A core utility for creating a database

createdb is a core utility for creating a database and is essentially a wrapper around the CREATE DATABASE SQL command.

createdb was added in PostgreSQL 7.0.


As of PostgreSQL 14, createdb does not accept the -d option for providing a conninfo string; connection parameters must be provided individually or via environment variables

If the default postgres database does not exist, provide the name of a database to connect to with --maintenance-db.

Since PostgreSQL 8.3, createdb no longer emits any output on successful creation of a database.

Source code

The createdb source code is located at src/bin/scripts/createdb.c.

Change history


Basic usage example for createdb:

$ createdb -h localhost -p 5432 -U postgres testdb

Creating a database from template0:

$ createdb -h localhost -p 5432 -U postgres --template=template0 testdb 

Attempting to create a database which already exists:

$ createdb -h localhost -p 5432 -U postgres postgres
createdb: error: database creation failed: ERROR:  database "postgres" already exists


Core utility

See also