table of contents
CREATEDB(1) | PostgreSQL 9.2.24 Documentation | CREATEDB(1) |
NAME¶
createdb - create a new PostgreSQL database
SYNOPSIS¶
createdb [connection-option...] [option...] [dbname [description]]
DESCRIPTION¶
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.
createdb is a wrapper around the SQL command CREATE DATABASE (CREATE_DATABASE(7)). There is no effective difference between creating databases via this utility and via other methods for accessing the server.
OPTIONS¶
createdb accepts the following command-line arguments:
dbname
description
-D tablespace, --tablespace=tablespace
-e, --echo
-E encoding, --encoding=encoding
-l locale, --locale=locale
--lc-collate=locale
--lc-ctype=locale
-O owner, --owner=owner
-T template, --template=template
-V, --version
-?, --help
The options -D, -l, -E, -O, and -T correspond to options of the underlying SQL command CREATE DATABASE (CREATE_DATABASE(7)); see there for more information about them.
createdb also accepts the following command-line arguments for connection parameters:
-h host, --host=host
-p port, --port=port
-U username, --username=username
-w, --no-password
-W, --password
This option is never essential, since createdb will automatically prompt for a password if the server demands password authentication. However, createdb will waste a connection attempt finding out that the server wants a password. In some cases it is worth typing -W to avoid the extra connection attempt.
--maintenance-db=dbname
ENVIRONMENT¶
PGDATABASE
PGHOST, PGPORT, PGUSER
This utility, like most other PostgreSQL utilities, also uses the environment variables supported by libpq (see Section 31.14, “Environment Variables”, in the documentation).
DIAGNOSTICS¶
In 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 the libpq front-end library will apply.
EXAMPLES¶
To create the database demo using the default database server:
$ createdb demo
To create the database demo using the server on host eden, port 5000, using the LATIN1 encoding scheme with a look at the underlying command:
$ createdb -p 5000 -h eden -E LATIN1 -e demo CREATE DATABASE demo ENCODING 'LATIN1';
SEE ALSO¶
dropdb(1), CREATE DATABASE (CREATE_DATABASE(7))
2017-11-06 | PostgreSQL 9.2.24 |