CREATEDB(1)

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

CREATEDB(1) πŸ’–βœ¨

okay so bestie, let me tell you about createdb β€” it's literally the main character of database creation in PostgreSQL 14.24 and it's giving icon behavior πŸ‘‘


✨ NAME ✨

createdb β€” create a new PostgreSQL database, no cap πŸ’…


🌸 SYNOPSIS 🌸

createdb [connection-option...] [option...] [dbname [description]]

πŸ¦‹ DESCRIPTION πŸ¦‹

okay so createdb creates a new PostgreSQL database. periodt. πŸ’–

Normally, the database user who executes this command becomes the owner of the new database. that's just how it is, bestie. but highkey, a different owner can be specified via the -O option β€” only if the executing user has appropriate privileges though. 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. fr fr, it's the same vibe either way ✨


πŸŽ€ 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 (no duplicates allowed bestie πŸ’€). the default is to create a database with the same name as the current system user. slay πŸ’…
  • description β€” specifies a comment to be associated with the newly created database. cute little annotation, love that for you πŸŽ€
  • -D tablespace, --tablespace=tablespace β€” specifies the default tablespace for the database. (this name is processed as a double-quoted identifier.) noted πŸ“
  • -e, --echo β€” echo the commands that createdb generates and sends to the server. so you can see exactly what's going down πŸ‘€
  • -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. very important energy πŸ’–
  • -l locale, --locale=locale β€” specifies the locale to be used in this database. this is equivalent to specifying both --lc-collate and --lc-ctype. two-for-one, we love efficiency ✨
  • --lc-collate=locale β€” specifies the LC_COLLATE setting to be used in this database. collation vibes πŸ¦‹
  • --lc-ctype=locale β€” specifies the LC_CTYPE setting to be used in this database. character type vibes 🌸
  • -O owner, --owner=owner β€” specifies the database user who will own the new database. (this name is processed as a double-quoted identifier.) main character owner energy πŸ‘‘
  • -T template, --template=template β€” specifies the template database from which to build this database. (this name is processed as a double-quoted identifier.) building from a template, iconic πŸŽ€
  • -V, --version β€” print the createdb version and exit. just the version, nothing else, bye πŸ‘‹
  • -?, --help β€” show help about createdb command line arguments, and exit. when you need a little guidance bestie 🫢

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. iykyk πŸ”₯

createdb also accepts the following command-line arguments for connection parameters:

  • -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. socket energy πŸ”Œ
  • -p port, --port=port β€” specifies the TCP port or the local Unix domain socket file extension on which the server is listening for connections. port vibes ✨
  • -U username, --username=username β€” user name to connect as. who are you today bestie? πŸ’…
  • -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. no password, no problem (unless there's a problem) 😭
  • -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. efficiency icon πŸ’…
  • --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. flexible and iconic 🌈

🌈 ENVIRONMENT 🌈

  • PGDATABASE β€” if set, the name of the database to create, unless overridden on the command line. environment variable doing its thing ✨
  • 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. triple threat energy πŸ’–
  • PG_COLOR β€” specifies whether to use color in diagnostic messages. possible values are always, auto and never. color vibes 🌈

This utility, like most other PostgreSQL utilities, also uses the environment variables supported by libpq (see Section 34.15). libpq bestie 🫢


πŸ’€ 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. no cap, gotta have the server running bestie 😭


πŸ“ 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, ate and left no crumbs πŸ’…πŸ”₯


πŸ‘‘ SEE ALSO πŸ‘‘

dropdb(1), CREATE DATABASE (CREATE_DATABASE(7))


okay bestie, that's the whole thing! createdb is literally iconic and now you know everything about it. go forth and create databases, slay, and remember: no cap, this utility is a wrapper around CREATE DATABASE and it's giving convenience πŸ’–βœ¨

PostgreSQL 14.24 β€” 2026 β€” CREATEDB(1) forever bestie πŸŽ€πŸ¦‹πŸŒΈπŸ’…πŸ‘‘

πŸ“¦ where this page comes from