Contents
CREATE DATABASE
An SQL command to create a database
CREATE DATABASE
is a DDL command to create a database.
CREATE DATABASE
has always been present in PostgreSQL.
Change history
- PostgreSQL 15
- PostgreSQL 13
LOCALE
option added, combining the existingLC_COLLATE
andLC_CTYPE
options (commit 06140c20)
- PostgreSQL 9.5
- PostgreSQL 9.0
- PostgreSQL 8.1
CONNECTION LIMIT
option added (commit d42cf5a4)
- PostgreSQL 8.0
TABLESPACE
option added to define the default tablespace for the database (commit 2467394e)LOCATION
option removed (commit 2467394e)
- PostgreSQL 7.3
OWNER
option added to enable specification of the database owner on database creation (commit a833c441)
- PostgreSQL 7.1
WITH TEMPLATE
option added to enable selection of a template database as an alternative to the default "template0
" (commit 2cf48ca0)
Examples
Basic usage example for CREATE DATABASE
:
postgres=# CREATE DATABASE foo; CREATE DATABASE postgres=# \l+ foo List of databases -[ RECORD 1 ]-----+------------ Name | foo Owner | postgres Encoding | UTF8 Collate | en_GB.UTF-8 Ctype | en_GB.UTF-8 Access privileges | Size | 7393 kB Tablespace | pg_default Description |
Creating a database with a different locale:
postgres=# CREATE DATABASE locale_test ENCODING latin1 LOCALE 'de_DE.iso88591' TEMPLATE template0; CREATE DATABASE postgres=# \l+ locale_test List of databases -[ RECORD 1 ]-----+--------------- Name | locale_test Owner | postgres Encoding | LATIN1 Collate | de_DE.iso88591 Ctype | de_DE.iso88591 Access privileges | Size | 7393 kB Tablespace | pg_default Description |
References
- PostgreSQL documentation: CREATE DATABASE
- PostgreSQL documentation: Creating a Database