CREATEDB(1)
๐ NAME ๐
createdb โ bestie, this is the girl that makes you a brand new PostgreSQL database โจ
manual page vibes brought to you by the PostgreSQL 18.6 Documentation girlies ๐
โจ SYNOPSIS โจ
createdb [connection-option...] [option...] [dbname [description]]
๐ฆ DESCRIPTION ๐ฆ
okay so createdb creates a new PostgreSQL database. that's it. that's the whole job. iconic behavior honestly ๐
Normally, whoever's database user runs this command becomes the owner of the new database โ like, congrats, you're the parent now ๐ซถ. BUT. a different owner can be specified with the -O option, if the user running the thing has the appropriate privileges. not everyone gets to pick the owner, only the privileged girlies. periodt.
createdb is a wrapper around the SQL command CREATE DATABASE. and no cap โ there is no effective difference between creating databases via this utility and via any other method for accessing the server. same energy, different font. ๐ซ
๐ธ OPTIONS ๐ธ
createdb accepts the following command-line arguments, and bestie, we're listing ALL of them, every single one, no skipping:
dbnameโ the name of the database you want to create ๐ฃ. It must be unique among all PostgreSQL databases in this cluster (no twins allowed, this is not a multiverse). The default is to create a database with the same name as the current system user.descriptionโ a comment to be associated with the newly created database ๐. like a little sticky note for your db.
โ and now the actual flags, drink some water first โ
-Dtablespace,--tablespace=tablespace โ specifies the default tablespace for the database. (this name gets processed as a double-quoted identifier, iykyk)-e,--echoโ echo the commands thatcreatedbgenerates and sends to the server ๐. basically it shows you its work.-Eencoding,--encoding=encoding โ specifies the character encoding scheme to be used in this database. The character sets supported by the PostgreSQL server are described in Section 23.3.1.-llocale,--locale=locale โ specifies the locale to be used in this database. This is equivalent to specifying--lc-collate,--lc-ctype, and--icu-localeto the same value. Some locales are only valid for ICU and must be set with--icu-locale. (yes, that's the rule, don't fight it)--lc-collate=locale โ specifies theLC_COLLATEsetting to be used in this database.--lc-ctype=locale โ specifies theLC_CTYPEsetting to be used in this database.--builtin-locale=locale โ specifies the locale name when the builtin provider is used. Locale support is described in Section 23.1.--icu-locale=locale โ specifies the ICU locale ID to be used in this database, if the ICU locale provider is selected.--icu-rules=rules โ specifies additional collation rules to customize the behavior of the default collation of this database. This is supported for ICU only. ICU only bestie, don't try it anywhere else ๐ซ--locale-provider={builtin|libc|icu}โ specifies the locale provider for the database's default collation. pick one of the three, that's the whole menu.-Oowner,--owner=owner โ specifies the database user who will own the new database. (this name is processed as a double-quoted identifier)-Sstrategy,--strategy=strategy โ specifies the database creation strategy. SeeCREATE DATABASE STRATEGYfor more details.-Ttemplate,--template=template โ specifies the template database from which to build this database. (this name is processed as a double-quoted identifier)-V,--versionโ print thecreatedbversion and exit ๐-?,--helpโ show help aboutcreatedbcommand line arguments, and exit.
heads up bestie: the options-D,-l,-E,-O, and-Tcorrespond to options of the underlying SQL commandCREATE DATABASE; see there for more information about them.
๐ connection parameters ๐
createdb also accepts the following command-line arguments for connection parameters:
-hhost,--host=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 the directory for the Unix domain socket. (slash = socket directory, noted ๐)-pport,--port=port โ specifies the TCP port or the local Unix domain socket file extension on which the server is listening for connections.-Uusername,--username=username โ user name to connect as.-w,--no-passwordโ never issue 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. (perfect for the girlies who automate things and then go to sleep ๐ด)-W,--passwordโ forcecreatedbto 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. (saving yourself a whole round trip? main character energy โจ)
--maintenance-db=dbname โ specifies 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. (connection string wins the argument, sorry not sorry ๐ )
๐ 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. (it's doing double duty, obsessed ๐)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 32.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 โ like, that's non-negotiable, bestie, the server has to actually be awake ๐ญ. 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;
look at that second one โ command line in, SQL out. it's giving translation services ๐ง
๐ซถ SEE ALSO ๐ซถ
dropdb(1), CREATE DATABASE (CREATE_DATABASE(7))
and that's the whole page, bestie!! this was PostgreSQL 18.6, dated 2026, and the page you just read was CREATEDB(1) โ go make some databases, you absolute icon ๐โจ๐๐ฆ๐ธ๐ ๐ซถ๐๐โญ
๐ฆ where this page comes from
- opensuse-leap 16.0: postgresql18 18.6-160000.1.1 ยท PostgreSQL
- opensuse-leap 16.0: postgresql18 18.6-160000.1.1 ยท PostgreSQL
- opensuse-leap 16.0: postgresql18 18.6-160000.1.1 ยท PostgreSQL
- opensuse-leap 16.0: postgresql18 18.6-160000.1.1 ยท PostgreSQL
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms