Documentation
 
 
 

30.2. Creating a Database Cluster

Before you can do anything, you must initialize a database storage area on disk. We call this a database cluster. (SQL uses the term catalog cluster instead.) A database cluster is a collection of databases is accessible by a single instance of a running database server. After initialization, a database cluster will contain a database named template1. As the name suggests, this will be used as a template for subsequently created databases; it should not be used for actual work. (See Chapter 32 for information about creating databases.)

Note: The default database cluster is created and initialized automatically when you run our installers, and the following steps are only needed if you intend to perform this step manually.

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 a location such as /opt/EnterpriseDB/8.2.1.2/data is popular. To initialize a database cluster, use the command initdb, which is installed with EnterpriseDB. The desired file system location of your database system is indicated by the -D option, for example

$ initdb -D /opt/EnterpriseDB/8.2.1.2/data

Note that you must execute this command while logged into the EnterpriseDB user account, which is described in the previous section.

Tip: As an alternative to the -D option, you can set the environment variable PGDATA.

initdb will attempt to create the directory you specify if it does not already exist. It is likely that it will not have the permission to do so (if you followed our advice and created an unprivileged account). In that case you should create the directory yourself (as root) and change the owner to be the EnterpriseDB user. Here is how this might be done:

root# mkdir /opt/EnterpriseDB/8.2.1.2/data
root# chown enterprisedb /opt/EnterpriseDB/8.2.1.2/data
root# su enterprisedb
enterprisedb$ initdb -D /opt/EnterpriseDB/8.2.1.2/data

initdb will refuse to run if the data directory looks like it it has already been initialized.

Because the data directory contains all the data stored in the database, it is essential that it be secured from unauthorized access. initdb therefore revokes access permissions from everyone but the EnterpriseDB user.

However, while the directory contents are secure, the default client authentication setup allows any local user to connect to the database and even become the database superuser. If you do not trust other local users, we recommend you use one of initdb's -W, --pwprompt or --pwfile option to assign a password to the database superuser. After initdb, modify the pg_hba.conf file to use md5 or password instead of trust authentication before you start the server for the first time. (Other approaches include using ident authentication or file system permissions to restrict connections. See Chapter 33 for more information.)

initdb also initializes the default locale for the database cluster. Normally, it will just take the locale settings in the environment and apply them to the initialized database. It is possible to specify a different locale for the database; more information about that can be found in Section 34.1. The sort order used within a particular database cluster is set by initdb and cannot be changed later, short of dumping all data, rerunning initdb, and reloading the data. So it's important to make this choice correctly the first time.

 
 ©2004-2007 EnterpriseDB All Rights Reserved