22.2. Creating a Database
In order to create a database, the PostgreSQL server must be up and running (see Section 18.3 ).
Databases are created with the SQL command CREATE DATABASE :
follows the usual rules for
identifiers. The current role automatically
becomes the owner of the new database. It is the privilege of the
owner of a database to remove it later (which also removes all
the objects in it, even if they have a different owner).
The creation of databases is a restricted operation. See Section 21.2 for how to grant permission.
Since you need to be connected to the database server in order to
question remains how the
database at any given
site can be created. The first database is always created by the
command when the data storage area is
database is called
create the first
database you can connect to
A second database,
is also created during database cluster initialization. Whenever a
new database is created within the
is essentially cloned.
This means that any changes you make in
propagated to all subsequently created databases. Because of this,
avoid creating objects in
unless you want them
propagated to every newly created database. More details
does no magic. It connects to the
database and issues the
exactly as described above.
reference page contains the invocation
details. Note that
without any arguments will create
a database with the current user name.
Chapter 20 contains information about how to restrict who can connect to a given database.
Sometimes you want to create a database for someone else, and have them become the owner of the new database, so they can configure and manage it themselves. To achieve that, use one of the following commands:
from the SQL environment, or:
from the shell. Only the superuser is allowed to create a database for someone else (that is, for a role you are not a member of).