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

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       | 

Categories

DDL, SQL command

See also

createdb, ALTER DATABASE, DROP DATABASE