CREATEDB(1)

πŸ“¦ version 16.15, in opensuse-leap 16.0

πŸ’… 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 that createdb generates 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-locale to 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 the LC_COLLATE setting to be used in this database.
  • *--lc-ctype=locale* β€” specifies the LC_CTYPE setting 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. see CREATE DATABASE STRATEGY for 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 the createdb version and exit. quick lil flex.
  • -?, --help β€” show help about createdb command line arguments, and exit. icon behavior.
ngl, the options -D, -l, -E, -O, and -T correspond to options of the underlying SQL command CREATE 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 .pgpass file, 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 β€” force createdb to 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, the postgres database will be used; if that does not exist (or if it is the name of the new database being created), template1 will 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. PGUSER also determines the name of the database to create, if it is not specified on the command line or by PGDATABASE. multitasking queen πŸ‘‘
  • PG_COLOR β€” specifies whether to use color in diagnostic messages. possible values are always, auto and never. 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 PostgreSQL 16.15 documentation, dated 2026, and it's the createdb page, periodt. go make some databases, you icon πŸ«ΆπŸ’…βœ¨
πŸ“¦ where this page comes from