Книга: Fedora™ Unleashed, 2008 edition
Initializing the Data Directory in PostgreSQL
Initializing the Data Directory in PostgreSQL
After the RPMs are installed, you need to initialize the data directory. To do so, you must first create the data directory and you must be the root user. The following example assumes that the data directory is /usr/local/pgsql/data
.
Create the /usr/local/pgsql/data
directory (using mkdir
) and change the ownerships of the directory (using chown
and chgrp
) so it is owned by the user postgres
. Then use su
and, as the user postgres
, issue the following commands:
# mkdir /usr/local/pgsql
# chown postgres /usr/local/pgsql
# chgrp postgres /usr/local/pgsql
# su - postgres
-bash-2.05b$ initdb -D /usr/local/pgsql/data
The files belonging to this database system will be owned by user "postgres".
This user must also own the server process.
The database cluster will be initialized with locale en_US.UTF-8.
This locale setting will prevent the use of indexes for pattern matching
operations. If that is a concern, rerun initdb with the collation order
set to "C". For more information see the Administrator's Guide.
creating directory /usr/local/pgsql/data... ok
creating directory /usr/local/pgsql/data/base... ok
creating directory /usr/local/pgsql/data/global... ok
creating directory /usr/local/pgsql/data/pg_xlog... ok
creating directory /usr/local/pgsql/data/pg_clog... ok
creating template1 database in /usr/local/pgsql/data/base/1... ok
creating configuration files... ok initializing pg_shadow... ok
enabling unlimited row size for system tables... ok
initializing pg_depend... ok
creating system views... ok
loading pg_description... ok
creating conversions... ok
setting privileges on built-in objects... ok
vacuuming database template1... ok
copying template1 to template0... ok
Success. You can now start the database server using:
/usr/bin/postmaster -D /usr/local/pgsql/data
or
/usr/bin/pg_ctl -D /usr/local/pgsql/data -l logfile start
This initializes the database and sets the permissions on the data directory to their correct values.
CAUTION
The initdb
program sets the permissions on the data directory to 700
. You should not change these permissions to anything else to avoid creating a security hole.
You can start the postmaster
program with the following command (make sure that you are still the user postgres
):
$ postmaster -D /usr/local/pgsql/data &
If you have decided to use a directory other than /usr/local/pgsql/data
as the data directory, you should replace the directory in the postmaster
command line with what ever directory you are using.
TIP
By default, Fedora makes the PostgreSQL data directory /var/lib/pgsql/data
. This isn't a very good place to store the data, however, because most people do not have the necessary space in the /var
partition for any kind of serious data storage. Note that if you do change the data directory to something else (such as /usr/local/pgsql/data
, as in the examples in this section), you need to edit the PostgreSQL startup file (named postgres
) located in /etc/rc.d/init.d
to reflect the change.
- Creating Database Users in PostgreSQL
- Deleting Database Users in PostgreSQL
- Creating a File System
- Информация заголовочной страницы (Database header)
- Database dialect
- Безопасность внешних таблиц. Параметр EXTERNAL FILE DIRECTORY
- 4.4.4 The Dispatcher
- DATABASE CACHE SIZE
- ТМР DIRECTORY
- EXTERNAL FUNCTION DIRECTORY
- About the author
- Chapter 7. The state machine