Linux "createdb" Command Line Options and Examples
create a new PostgreSQL database

createdb creates a new PostgreSQL database. Normally, the database user who executes this command becomes the owner of the new database. However, a different owner can be specified via the -O option, if the executing user has appropriate privileges.


Usage:

createdb [connection-option...] [option...] [dbname [description]]




Command Line Options:

--tablespace
Specifies the default tablespace for the database. (This name is processed as a double-quoted identifier.)
createdb --tablespace ...
--echo
Echo the commands that createdb generates and sends to the server.
createdb --echo ...
--encoding
Specifies the character encoding scheme to be used in this database. The character sets supported by the PostgreSQL server aredescribed in Section 23.3.1.
createdb --encoding ...
--locale
Specifies the locale to be used in this database. This is equivalent to specifying both --lc-collate and --lc-ctype.
createdb --locale ...
--lc-collate
Specifies the LC_COLLATE setting to be used in this database.
createdb --lc-collate ...
--lc-ctype
Specifies the LC_CTYPE setting to be used in this database.
createdb --lc-ctype ...
--owner
Specifies the database user who will own the new database. (This name is processed as a double-quoted identifier.)
createdb --owner ...
--template
Specifies the template database from which to build this database. (This name is processed as a double-quoted identifier.)
createdb --template ...
--version
Print the createdb version and exit.
createdb --version ...
--help
Show help about createdb command line arguments, and exit.The options -D, -l, -E, -O, and -T correspond to options of the underlying SQL command CREATE DATABASE (CREATE_DATABASE(7)); seethere for more information about them.createdb also accepts the following command-line arguments for connection parameters:
createdb --help ...
--host
Specifies the host name of the machine on which the server is running. If the value begins with a slash, it is used as thedirectory for the Unix domain socket.
createdb --host ...
--port
Specifies the TCP port or the local Unix domain socket file extension on which the server is listening for connections.
createdb --port ...
--username
User name to connect as.
createdb --username ...
--no-password
Never issue a password prompt. If the server requires password authentication and a password is not available by other means suchas a .pgpass file, the connection attempt will fail. This option can be useful in batch jobs and scripts where no user is presentto enter a password.
createdb --no-password ...
--password
Force createdb to prompt for a password before connecting to a database.This option is never essential, since createdb will automatically prompt for a password if the server demands passwordauthentication. However, createdb will waste a connection attempt finding out that the server wants a password. In some cases itis worth typing -W to avoid the extra connection attempt.
createdb --password ...
--maintenance-db
Specifies the name of the database to connect to when creating the new database. If not specified, the postgres database will beused; if that does not exist (or if it is the name of the new database being created), template1 will be used.ENVIRONMENTPGDATABASEIf set, the name of the database to create, unless overridden on the command line.PGHOSTPGPORTPGUSERDefault connection parameters. PGUSER also determines the name of the database to create, if it is not specified on the commandline or by PGDATABASE.This utility, like most other PostgreSQL utilities, also uses the environment variables supported by libpq (see Section 33.14).DIAGNOSTICSIn case of difficulty, see CREATE DATABASE (CREATE_DATABASE(7)) and psql(1) for discussions of potential problems and error messages.The database server must be running at the targeted host. Also, any default connection settings and environment variables used by thelibpq front-end library will apply.EXAMPLESTo create the database demo using the default database server:$ createdb demoTo create the database demo using the server on host eden, port 5000, using the template0 template database, here is the command-linecommand and the underlying SQL command:$ createdb -p 5000 -h eden -T template0 -e demoCREATE DATABASE demo TEMPLATE template0;
createdb --maintenance-db ...