Before you can do anything, you must initialize a database storage
- area on disk. We call this a database
- cluster. (
SQL speaks of a catalog
- cluster instead.) A database cluster is a collection of databases
- that will be accessible through a single instance of a running
- database server. After initialization, a database cluster will
- contain one database named template1. As the
- name suggests, this will be used as a template for any subsequently
- created database; it should not be used for actual work.
+ area on disk. We call this a database cluster.
+ (
SQL speaks of a catalog cluster instead.) A
+ database cluster is a collection of databases that will be accessible
+ through a single instance of a running database server. After
+ initialization, a database cluster will contain one database named
+ template1. As the name suggests, this will be used
+ as a template for any subsequently created database; it should not be
+ used for actual work.
In file system terms, a database cluster will be a single directory
- under which all data will be stored. We call this the
- data directory or data
- area. It is completely up to you where you choose to
- store your data, there is no default, although locations such as
+ under which all data will be stored. We call this the data
+ directory or data area. It is
+ completely up to you where you choose to store your data, there is no
+ default, although locations such as
/usr/local/pgsql/data or
- /var/lib/pgsql/data are popular. To initialize
- a database cluster, use the command initdb,
- which is installed with
PostgreSQL. The
- desired file system location of your database system is indicated
- by the option, for example
+ /var/lib/pgsql/data are popular. To initialize a
+ database cluster, use the command initdb, which is
+ installed with
PostgreSQL. The desired
+ file system location of your database system is indicated by the
+ option, for example
> initdb -D /usr/local/pgsql/data
permissions from everyone but the
PostgreSQL user account.
+ However, while the directory contents are secure, the default
+ pg_hba.conf authentication of
+ trust allows any local user to become the
+ superuser and connect to the database. If you don't trust your local
+ users, we recommend you use the initdb option
+ or to assign a
+ password to the superuser and modify your
+ pg_hba.conf accordingly. (Another option:
+ Your operating system may support ident for
+ local connections.)
+
+
One surprise you might encounter while running initdb is