CREATEDB(1)
β¨ createdb β create a new PostgreSQL database β¨
Okay so like, the vibe check for this page: it's from the PostgreSQL 17.11 Documentation, and it's literally all about bringing a brand new database into the world. Slay.
πΈ NAME πΈ
createdb β create a new PostgreSQL database. Periodt.
β¨ SYNOPSIS β¨
createdb [connection-option...] [option...] [dbname [description]]
π DESCRIPTION π
Okay bestie, so createdb creates a new PostgreSQL database. That's the whole assignment. Main character energy.
Normally, the database user who executes this command becomes the owner of the new database. Cute, right? But wait β a different owner can be specified via the -O option, if the executing user has appropriate privileges. So like, you can hand off ownership, but only if you're allowed.
And here's the tea: 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. So don't come for me saying one is better β they're literally the same, iykyk.
π OPTIONS π
createdb accepts the following command-line arguments:
dbnameβ Specifies 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. So if you don't name it, it's gonna be your username. No cap.descriptionβ Specifies a comment to be associated with the newly created database. Like a little bio for your database. π-Dtablespace,--tablespace=tablespace β Specifies the default tablespace for the database. (This name is processed as a double-quoted identifier.) Don't forget the quotes situation.-e,--echoβ Echo the commands thatcreatedbgenerates and sends to the server. So you can see exactly what it's doing behind the scenes. Fr fr, this is the "show your work" option.-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. That's where you go for the full list, bestie.-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. So like, not every locale works everywhere β check yourself before you wreck yourself.--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. Builtin provider girlies know.--icu-locale=locale β Specifies the ICU locale ID to be used in this database, if the ICU locale provider is selected. ICU hive rise up.--icu-rules=rules β Specifies additional collation rules to customize the behavior of the default collation of this database. This is supported for ICU only. So if you're not on ICU, this option is not for you. Sorry not sorry.--locale-provider={builtin|libc|icu`} β Specifies the locale provider for the database's default collation. Pick your fighter: builtin, libc, or icu.-Oowner,--owner=owner β Specifies the database user who will own the new database. (This name is processed as a double-quoted identifier.) So you can be like "this database is owned by them" if you have the privileges.-Sstrategy,--strategy=strategy β Specifies the database creation strategy. SeeCREATE DATABASE STRATEGYfor more details. That's where the strategy tea is spilled.-Ttemplate,--template=template β Specifies the template database from which to build this database. (This name is processed as a double-quoted identifier.) Template database is like the blueprint, okay?-V,--versionβ Print thecreatedbversion and exit. Just a little flex.-?,--helpβ Show help aboutcreatedbcommand line arguments, and exit. The "help me help you" option.
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. So if you're confused, go read that page. I'm just the messenger.
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 means socket directory, got it.-pport,--port=port β Specifies the TCP port or the local Unix domain socket file extension on which the server is listening for connections. Port situation.-Uusername,--username=username β User name to connect as. Who am I today? Whatever you set here.-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. So like, don't ask, and also don't expect to get in if there's no password. β οΈ-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. So like, it's a convenience thing, not a need thing. π
--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. So it's like your base of operations. And connection strings win over CLI flags β no cap.
π 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. SoPGUSERis doing double duty. Multitasking icon.PG_COLORβ Specifies whether to use color in diagnostic messages. Possible values arealways,autoandnever. Color me pretty or don't.
This utility, like most other PostgreSQL utilities, also uses the environment variables supported by libpq (see Section 32.15). So if you know libpq, you know the vibes.
π©Ί 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. So like, check your server is up, check your settings, and if it's still broken, those pages are the ones.
π 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 that? -e shows you the SQL. Chef's kiss.
π SEE ALSO π
dropdb(1), CREATE DATABASE (CREATE_DATABASE(7))
And that's the whole thing bestie. This page is from PostgreSQL 17.11, dated 2026, and it's the CREATEDB(1) page. Now go create some databases and slay. πβ¨ππ¦πΈπ π«Άππ₯ππβππππ§π
π¦ where this page comes from
- opensuse-leap 16.0: postgresql17 17.11-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql17 17.11-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql17 17.11-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql17 17.11-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