CREATEDB(1)
π createdb(1) β create a new PostgreSQL database π
okay so bestie, this is the createdb(1) page from the PostgreSQL 15.19 Documentation, and itβs giving tiny-utility-big-main-character-energy. Weβre gonna get you comfy with it, no cap. β¨
π NAME π
createdb β create a new PostgreSQL database.
πΈ SYNOPSIS πΈ
createdb [connection-option...] [option...] [dbname [description]]
π¦ DESCRIPTION π¦
okay so createdb creates a new PostgreSQL database. Thatβs the whole assignment, and she ate. π
Normally, the database user who executes this command becomes the owner of the new database. But lowkey, a different owner can be specified via the -O option, if the executing user has appropriate privileges. iykyk.
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. Periodt. π
π OPTIONS π
createdb accepts the following command-line arguments:
dbnameβ sets the name of the database to be created. The name must be unique among all PostgreSQL databases in this cluster. The default is to create a database with the same name as the current system user.descriptionβ sets a comment to be associated with the newly created database.-D tablespace,--tablespace=tablespaceβ sets the default tablespace for the database. (This name is processed as a double-quoted identifier.)-e,--echoβ echoes the commands thatcreatedbgenerates and sends to the server.-E encoding,--encoding=encodingβ sets the character encoding scheme to be used in this database. The character sets supported by the PostgreSQL server are described in Section 24.3.1.-l locale,--locale=localeβ sets the locale to be used in this database. This is equivalent to specifying both--lc-collateand--lc-ctype.--lc-collate=localeβ sets theLC_COLLATEsetting to be used in this database.--lc-ctype=localeβ sets theLC_CTYPEsetting to be used in this database.--icu-locale=localeβ sets the ICU locale ID to be used in this database, if the ICU locale provider is selected.--locale-provider={libc|icu}β sets the locale provider for the databaseβs default collation.-O owner,--owner=ownerβ sets the database user who will own the new database. (This name is processed as a double-quoted identifier.)-S strategy,--strategy=strategyβ sets the database creation strategy. SeeCREATE DATABASE STRATEGYfor more details.-T template,--template=templateβ sets the template database from which to build this database. (This name is processed as a double-quoted identifier.)-V,--versionβ prints thecreatedbversion and exits.-?,--helpβ shows help aboutcreatedbcommand line arguments, and exits.
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.
π connection parameters, because we connect π
createdb also accepts the following command-line arguments for connection parameters:
-h host,--host=hostβ sets the host name of the machine on which the server is running. If the value begins with a slash, it is used as the directory for the Unix domain socket.-p port,--port=portβ sets the TCP port or the local Unix domain socket file extension on which the server is listening for connections.-U username,--username=usernameβ user name to connect as.-w,--no-passwordβ never issues a password prompt. If the server requires password authentication and a password is not available by other means such as a.pgpassfile, the connection attempt will fail. This option can be useful in batch jobs and scripts where no user is present to enter a password.-W,--passwordβ forcescreatedbto 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 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β sets the name of the database to connect to when creating the new database. If not specified, thepostgresdatabase will be used; if that does not exist (or if it is the name of the new database being created),template1will be used. This can be a connection string. If so, connection string parameters will override any conflicting command line options.
π ENVIRONMENT π
PGDATABASEβ if set, the name of the database to create, unless overridden on the command line.PGHOST,PGPORT,PGUSERβ default connection parameters.PGUSERalso determines the name of the database to create, if it is not specified on the command line or byPGDATABASE.PG_COLORβ specifies whether to use color in diagnostic messages. Possible values arealways,autoandnever.
This utility, like most other PostgreSQL utilities, also uses the environment variables supported by libpq (see Section 34.15).
π DIAGNOSTICS π
vibe check: 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))
π footer energy: PostgreSQL 15.19 Β· 2026 Β· createdb(1) β mwah, bestie ππ«Ά
π¦ where this page comes from
- opensuse-leap 16.0: postgresql15 15.19-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql15 15.19-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql15 15.19-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql15 15.19-160000.1.1 Β· PostgreSQL
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms