CREATEDB(UNIX)

NAME
createdb — create a database

SYNOPSIS
createdb [-a system] [-h host] [-p port] [-D location] [dbname]

DESCRIPTION
createdb creates a new database. The person who executes this command becomes the database administrator, or DBA, for this database and is the only person, other than the Postgres super-user, who can destroy it.

Createdb is a shell script that invokes psql. Hence, a postmaster process must be running on the database server host before createdb is executed. In addition, the PGOPTION and PGREALM environment variables will be passed on to psql and processed as described in psql(1).

The optional argument dbname specifies the name of the database to be created. The name must be unique among all Postgres databases. dbname defaults to the value of the USER environment variable.

createdb understands the following command-line options:

-a system
    Specifies an authentication system system (see pgintro(1)) to use in connecting to the postmaster process. The default is site-specific.

-D dbpath
    Specifies the alternate database location for this database.

-h host
    Specifies the hostname of the machine on which the postmaster is running. Defaults to the name of the local host, or the value of the PGHOST environment variable (if set).

-p port
    Specifies the Internet TCP port on which the postmaster is listening for connections. Defaults to 5432, or the value of the PGPORT environment variable (if set).

EXAMPLES
# create 5432 demo database
createdb demo
# create the demo database using the postmaster on host eden,
# port using the Kerberos authentication system.
createdb -a kerberos -p 5432 -h eden demo

FILES

$PGDATA/base/dbname
    The location of the files corresponding to the database dbname.

SEE ALSO
createdb(l), destroydb(1), initdb(1), psql(1), postmaster(1).

DIAGNOSTICS

Error: Failed to connect to backend (host=xxx, port=xxx)
    Createdb could not attach to the postmaster process on the specified host and port. If you see this message, ensure that the postmaster is running on the proper host and that you have specified the proper port. If your site uses an authentication system, ensure that you have obtained the required authentication credentials.

user “username” is not in “pg_user”
    You do not have a valid entry in the relation “pg_user” and cannot do anything with Postgres at all; contact your Postgres site administrator.

user “username” is not allowed to create/destroy databases
    You do not have permission to create new databases; contact your Postgres site administrator.

dbname already exists
    The database already exists.

database creation failed on dbname
    An internal error occurred in psql or the backend server. Ensure that your Postgres site administrator has properly installed Postgres and initialized the site with initdb.