PostgreSQL CREATE DATABASE Keyword
The PostgreSQL CREATE DATABASE keyword is used to create a new PostgreSQL database.
Syntax
The syntax of using CREATE DATABASE statement in PostgreSQL is given below:
CREATE DATABASE DatabaseName;
Please note that to create any database, appropriate privilege is required. Along with this, the database name should be unique within the RDBMS. After creating the database, the following command can be used to see the list of databases available in RDBMS.
\l OR SELECT datname FROM pg_database;
Example: create a database
To create a database with name testDB, the following statement can be used:
CREATE DATABASE testDB;
After creating the database, the following commands can be used to see the list of databases available in RDBMS.
\l Result: Name | Owner | Encoding | Collate | Ctype | Access privileges -------------+----------+----------+------------+------------+----------------------------- SQLExample1 | postgres | UTF8 | en_US.utf8 | en_US.utf8 | =Tc/postgres + | | | | | postgres=CTc/postgres SQLExample2 | postgres | UTF8 | en_US.utf8 | en_US.utf8 | =Tc/postgres + | | | | | postgres=CTc/postgres SQLExample3 | postgres | UTF8 | en_US.utf8 | en_US.utf8 | =Tc/postgres + | | | | | postgres=CTc/postgres SQLExample4 | postgres | UTF8 | en_US.utf8 | en_US.utf8 | =Tc/postgres + | | | | | postgres=CTc/postgres SQLExample5 | postgres | UTF8 | en_US.utf8 | en_US.utf8 | =Tc/postgres + | | | | | postgres=CTc/postgres SQLExample6 | postgres | UTF8 | en_US.utf8 | en_US.utf8 | =Tc/postgres + | | | | | postgres=CTc/postgres SQLExample7 | postgres | UTF8 | en_US.utf8 | en_US.utf8 | =Tc/postgres + | | | | | postgres=CTc/postgres SQLExample8 | postgres | UTF8 | en_US.utf8 | en_US.utf8 | =Tc/postgres + | | | | | postgres=CTc/postgres testDB | postgres | UTF8 | en_US.utf8 | en_US.utf8 | =Tc/postgres + | | | | | postgres=CTc/postgres (9 rows) SELECT datname FROM pg_database; Result: datname ------------- SQLExample1 SQLExample2 SQLExample3 SQLExample4 SQLExample5 SQLExample6 SQLExample7 SQLExample8 testDB (9 rows)
❮ PostgreSQL Keywords