7
Creating a cluster
Tool
initdb
Notes
a new database cluster cannot belong to the OS superuser
PGDATA is a convenient variable that represents the cluster directory
configuration files are created in the PGDATA directory
enabling checksum calculation for data pages is a good idea
After installing the server, you need to create a database cluster. The initdb
tool does that for you.
For security reasons, the directory in which the cluster is initialized cannot
belong to the OS superuser. Usually, the cluster ownership is assigned to
the postgres user.
The cluster owner can define the PGDATA environment variable pointing to
the cluster directory. This variable is used by some server tools when they
need to find out the location of the cluster. Such tools include initdb, as well
as pg_ctl, the main server management tool, which we will discuss in a bit.
During cluster initialization, initdb creates configuration files in the PGDATA
directory. We will talk more about configuration files in another topic.
initdb has many keys that affect its operation. One important key is -k or
--data-checksums. It enables or disables calculating checksums for data
pages. The checksum check is performed when accessing any data page in
the cluster. This slightly reduces performance, but allows you to quickly
detect data corruption.