createdb  --  Creates a new database from the command line.


createdb [ options ] dbname [ description ]


-h, --host host

Use this parameter to supply the hostname of the machine postmaster is running on.

-p, --port port

Use this parameter to provide the TCP/IP port or socket file postmaster is listening on.

-U, --username username

Use this parameter to specify the username to connect as.

-W, --password

Pass this parameter to indicate that createdb should prompt for a password.

-e, --echo

Use this parameter to echo all queries that createdb generates.

-q, --quiet

Pass this parameter to have createdb run in quiet mode. When in quiet mode, no responses will be displayed.

-D, --location datadir

Use this parameter to specify an alternate location for the database to be created in.

-T, --template template

Use this parameter to supply the name of the template database to build the new database's tables from.

-E, --encoding encoding

Use this parameter to specify the character encoding scheme for the new database.


Use this parameter to provide a unique name for the new database. If left unspecified, the new database's name will be set to your username.


This optional clause gives the user the ability to specify a an associated comment with the newly created database.

The options -h, -p, -U, -W, and -e are passed on literally to psql. The options -D, -T, and -E are converted into options for the create database SQL command. Refer to the Create Database reference section for further information.



This message is displayed if the database is created successfully.

createdb: Database creation failed.

This message is displayed if creation of the new database failed.

createdb: Comment creation failed. (Database was created.)

This message is displayed when creation of the database's description failed, though the database itself was created.


Use createdb to create a new database on the system. Its ownership will be set to the system account that executed the command. The createdb command is a script executable from that shell that is essentially a wrapper for the SQL CREATE DATABASE command. line


The following example will create the booktown database.

$ createdb booktown