CREATE DATABASE name [ WITH LOCATION = 'dbpath' ]
The name of a database to create.
An alternate location where to store the new database in the filesystem. See below for caveats.
Message returned if the command completes successfully.
You must have the special CREATEDB privilege to create databases. See CREATE USER.
This occurs if a database with the name specified already exists.
The database name and dbpath cannot contain single quotes. This is required so that the shell commands that create the database directory can execute safely.
The expansion of the specified dbpath (see below how) failed. Check the path you entered or make sure that the environment variable you are referencing does exist.
If you have an explicit transaction block in progress you cannot call CREATE DATABASE. You must finish the transaction first.
These are most likely related to insufficient permissions on the data directory, a full disk, or other file system problems. The user under which the database server is running, must have access to the location.
CREATE DATABASE creates a new Postgres database. The creator becomes the owner of the new database.
An alternate location can be specified in order to, for example, store the database on a different disk. The path must have been prepared with the initlocation command.
If the path contains a slash, the leading part is interpreted as an environment variable, which must be known to the server process. This way the database administrator can exercise control over at which locations databases can be created. (A customary choice is, e.g., 'PGDATA2'.) If the server is compiled with ALLOW_ABSOLUTE_DBPATHS (not so by default), absolute path names, as identified by a leading slash (e.g. '/usr/local/pgsql/data'), are allowed as well.
CREATE DATABASE is a Postgres language extension.
Use DROP DATABASE to remove a database.
The program createdb is a shell script wrapper around this command, provided for convenience.
There are security and data integrity issues involved with using alternate database locations specified with absolute path names, and by default only an environment variable known to the backend may be specified for an alternate location. See the Administrator's Guide for more information.
To create a new database:
olly=> create database lusiadas;
To create a new database in an alternate area ~/private_db:
$ mkdir private_db $ initlocation ~/private_db Creating Postgres database system directory /home/olly/private_db/base $ psql olly Welcome to psql, the PostgreSQL interactive terminal. Type: \copyright for distribution terms \h for help with SQL commands \? for help on internal slash commands \g or terminate with semicolon to execute query \q to quit olly=> CREATE DATABASE elsewhere WITH LOCATION = '/home/olly/private_db'; CREATE DATABASE
There is no CREATE DATABASE statement in SQL92. Databases are equivalent to catalogs whose creation is implementation-defined.
If you see anything in the documentation that is not correct, does not match your experience with the particular feature or requires further clarification, please use this form to report a documentation issue.