CREATEDB(1) | PostgreSQL 16.3 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. 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
--icu-locale=locale
--icu-rules=rules
--locale-provider={libc|icu}
-O owner
--owner=owner
-S strategy
--strategy=strategy
-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; 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
PG_COLOR
This utility, like most other PostgreSQL utilities, also uses the environment variables supported by libpq (see Section 34.15).
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 template0 template database, here is the command-line command and the underlying SQL command:
$ createdb -p 5000 -h eden -T template0 -e demo CREATE DATABASE demo TEMPLATE template0;
SEE ALSO
dropdb(1), CREATE DATABASE (CREATE_DATABASE(7))
2024 | PostgreSQL 16.3 |