PostgreSQL Create Database

  • Database is used to store everything like tables, views, stored procedures, ….
  • We can create database in PostgreSQL using ‘CREATE DATABASE db_name’ or ‘createdb’.
  • By default, the new database will be created by cloning the standard system database template1.

Syntax 1:

CREATE DATABASE name
[ [ WITH ] [ OWNER [=] user_name ]
[ TEMPLATE [=] template ]
[ ENCODING [=] encoding ]
[ LC_COLLATE [=] lc_collate ]
[ LC_CTYPE [=] lc_ctype ]
[ TABLESPACE [=] tablespace ]
[ CONNECTION LIMIT [=] connlimit ] ]

Examples:
To create a new database:

CREATE DATABASE k2info;

PostgreSQL Create Database

To create a database pinfo which supports the ISO-8859-1 character set:>

CREATE DATABASE pinfo ENCODING ‘LATIN1’ TEMPLATE template0;

Syntax 2:

createdb [option…] [dbname] [description]

Examples:

createdb k2info2;

Powered by k2schools