CREATEDB(1)
π createdb β create a new PostgreSQL database β¨
okay so bestie, this is the createdb page from the PostgreSQL 16.15 docs β literally the glow-up guide for making a whole new database. let's get into it π«Ά
πΈ SYNOPSIS
createdb [connection-option...] [option...] [dbname [description]]
like, connection options first, then regular options, then the db name and an optional lil description. slay.
β¨ DESCRIPTION β¨
createdb creates a new PostgreSQL database. that's it, that's the vibe π
normally the database user who runs this command becomes the owner of the new database β main character energy, you get what you made. but you can hand ownership to someone else with the -O option, if you have the appropriate privileges. no cap, only if.
so here's the thing: createdb is literally just a wrapper around the SQL command CREATE DATABASE. there is no effective difference between creating databases with this utility and creating them through any other method of accessing the server. same result, different outfit π
π OPTIONS π
createdb accepts the following command-line arguments:
dbnameβ the name of the database you wanna create. it has to be unique among all the PostgreSQL databases in this cluster (no dupe names bestie π). the default is to create a database with the same name as the current system user β cute and automatic.descriptionβ a comment to be associated with the shiny new database. like a lil bio for your db π¦- *
-D*tablespace,--tablespace=tablespace β specifies the default tablespace for the database. heads up: this name is processed as a double-quoted identifier. -e,--echoβ echo the commands thatcreatedbgenerates and sends to the server. very "show your work" of it β¨- *
-E*encoding,--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 24.3.1. go check there, iykyk. - *
-l*locale,--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β not me warning you twice π - *
--lc-collate=locale* β specifies theLC_COLLATEsetting to be used in this database. - *
--lc-ctype=locale* β specifies theLC_CTYPEsetting to be used in this database. - *
--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, bestie. --locale-provider={libc|icu`} β specifies the locale provider for the database's default collation.- *
-O*owner,--owner=owner β specifies the database user who will own the new database. (and yeah, this name is processed as a double-quoted identifier too.) - *
-S*strategy,--strategy=strategy β specifies the database creation strategy. seeCREATE DATABASE STRATEGYfor more details π - *
-T*template,--template=template β specifies the template database from which to build this database. (double-quoted identifier, you know the drill.) -V,--versionβ print thecreatedbversion and exit. quick lil flex.-?,--helpβ show help aboutcreatedbcommand line arguments, and exit. icon behavior.
ngl, the options-D,-l,-E,-O, and-Tcorrespond to options of the underlying SQL commandCREATE DATABASEβ see there for more info about them. bestie, that manpage is the source of truth π
π connection parameter arguments π
createdb also accepts the following command-line arguments for connection parameters β the "how do i even reach the server" section:
- *
-h*host,--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. sneaky but iconic. - *
-p*port,--port=port β specifies 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. hi, it's me. -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. very "nobody's home" energy π-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. lowkey efficient π
- *
--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. messy but that's the rules π
π¦ 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. multitasking queen πPG_COLORβ specifies whether to use color in diagnostic messages. possible values arealways,autoandnever. aesthetic error messages, obsessed π
this utility, like most other PostgreSQL utilities, also uses the environment variables supported by libpq (see Section 34.15). fr fr.
π DIAGNOSTICS π
if things go sideways, 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, it literally has to be up, bestie. 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 β both, because we're thorough like that:
$ createdb -p 5000 -h eden -T template0 -e demo
CREATE DATABASE demo TEMPLATE template0;
ate. no crumbs. β¨
π§ SEE ALSO π§
dropdb(1), CREATE DATABASE (CREATE_DATABASE(7)) β the break-up page and the origin story, respectively π
and that's the whole page, bestie! this lil masterpiece is from the PostgreSQL16.15documentation, dated2026, and it's thecreatedbpage, periodt. go make some databases, you icon π«Άπ β¨
π¦ where this page comes from
- opensuse-leap 16.0: postgresql16 16.15-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql16 16.15-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql16 16.15-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql16 16.15-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