INITDB(1)

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

πŸ’– initdb(1) β€” create a new PostgreSQL database cluster πŸ’–

straight outta the PostgreSQL 15.19 Documentation, bestie: this is initdb(1), and it's literally the command that births a whole PostgreSQL database cluster πŸ‘‘

✨ NAME ✨

initdb β€” create a new PostgreSQL database cluster. that's it, that's the main character energy πŸ’…

πŸ¦‹ SYNOPSIS πŸ¦‹

initdb [option...] [--pgdata | -D] directory

okay so you give it options and a directory, and it does the cluster-creation thing. no cap 🫢

🌸 DESCRIPTION 🌸

initdb creates a new PostgreSQL database cluster. and bestie, a database cluster is a collection of databases that are managed by a single server instance. it's giving "one server, whole little database family" πŸ‘‘

Creating a database cluster consists of creating the directories in which the database data will live, generating the shared catalog tables (tables that belong to the whole cluster rather than to any particular database), and creating the postgres, template1, and template0 databases. the postgres database is a default database meant for use by users, utilities and third party applications. template1 and template0 are meant as source databases to be copied by later CREATE DATABASE commands. template0 should never be modified, but you can add objects to template1, which by default will be copied into databases created later. see Section 23.3 for more details πŸ“š

Although initdb will attempt to create the specified data directory, it might not have permission if the parent directory of the desired data directory is root-owned. to initialize in such a setup, create an empty data directory as root, then use chown to assign ownership of that directory to the database user account, then su to become the database user to run initdb. yes, bestie, the whole little permissions dance 🩰

initdb must be run as the user that will own the server process, because the server needs to have access to the files and directories that initdb creates. since the server cannot be run as root, you must not run initdb as root either. (it will in fact refuse to do so.) 🚫

🚨 serious vibe check: don't run initdb as root. it will literally refuse. the server can't run as root, so neither can this.

For security reasons the new cluster created by initdb will only be accessible by the cluster owner by default. the --allow-group-access option allows any user in the same group as the cluster owner to read files in the cluster. this is useful for performing backups as a non-privileged user 🫢

initdb initializes the database cluster's default locale and character set encoding. these can also be set separately for each database when it is created. initdb determines those settings for the template databases, which will serve as the default for all other databases. by default, initdb uses the locale provider libc, takes the locale settings from the environment, and determines the encoding from the locale settings. this is almost always sufficient, unless there are special requirements ✨

To choose a different locale for the cluster, use the option --locale. there are also individual options --lc-* (see below) to set values for the individual locale categories. note that inconsistent settings for different locale categories can give nonsensical results, so this should be used with care πŸ™ˆ

Alternatively, the ICU library can be used to provide locale services. (again, this only sets the default for subsequently created databases.) to select this option, specify --locale-provider=icu. to choose the specific ICU locale ID to apply, use the option --icu-locale. note that for implementation reasons and to support legacy code, initdb will still select and initialize libc locale settings when the ICU locale provider is used 🧚

When initdb runs, it will print out the locale settings it has chosen. if you have complex requirements or specified multiple options, it is advisable to check that the result matches what was intended πŸ‘€

More details about locale settings can be found in Section 24.1 πŸ“–

To alter the default encoding, use the --encoding. more details can be found in Section 24.3 πŸ”₯

πŸ’… OPTIONS πŸ’…

okay bestie, here's the whole options crew β€” every flag, every default, no skips, no cap πŸ’–

  • -A authmethod, --auth=authmethod β€” this option specifies the default authentication method for local users used in pg_hba.conf (host and local lines). see Section 21.1 for an overview of valid values. initdb will prepopulate pg_hba.conf entries using the specified authentication method for non-replication as well as replication connections.
🚨 do not use trust unless you trust all local users on your system. trust is the default for ease of installation. yes, the default is lowkey spicy, so pay attention.
  • --auth-host=authmethod β€” this option specifies the authentication method for local users via TCP/IP connections used in pg_hba.conf (host lines) 🌐
  • --auth-local=authmethod β€” this option specifies the authentication method for local users via Unix-domain socket connections used in pg_hba.conf (local lines) πŸ”Œ
  • -D directory, --pgdata=directory β€” this option specifies the directory where the database cluster should be stored. this is the only information required by initdb, but you can avoid writing it by setting the PGDATA environment variable, which can be convenient since the database server (postgres) can find the database directory later by the same variable πŸ“
  • -E encoding, --encoding=encoding β€” selects the encoding of the template databases. this will also be the default encoding of any database you create later, unless you override it then. the default is derived from the locale, if the libc locale provider is used, or UTF8 if the ICU locale provider is used. the character sets supported by the PostgreSQL server are described in Section 24.3.1 πŸ”€
  • -g, --allow-group-access β€” allows users in the same group as the cluster owner to read all cluster files created by initdb. this option is ignored on Windows as it does not support POSIX-style group permissions πŸͺŸ
  • --icu-locale=locale β€” specifies the ICU locale ID, if the ICU locale provider is used 🌍
  • -k, --data-checksums β€” use checksums on data pages to help detect corruption by the I/O system that would otherwise be silent. enabling checksums may incur a noticeable performance penalty. if set, checksums are calculated for all objects, in all databases. all checksum failures will be reported in the pg_stat_database view. see Section 30.2 for details πŸ”
  • --locale=locale β€” sets the default locale for the database cluster. if this option is not specified, the locale is inherited from the environment that initdb runs in. locale support is described in Section 24.1 🌸
  • --lc-collate=locale β€” like --locale, but only sets the locale in the specified category πŸŽ€
  • --lc-ctype=locale β€” like --locale, but only sets the locale in the specified category πŸŽ€
  • --lc-messages=locale β€” like --locale, but only sets the locale in the specified category πŸŽ€
  • --lc-monetary=locale β€” like --locale, but only sets the locale in the specified category πŸŽ€
  • --lc-numeric=locale β€” like --locale, but only sets the locale in the specified category πŸŽ€
  • --lc-time=locale β€” like --locale, but only sets the locale in the specified category πŸŽ€
  • --no-locale β€” equivalent to --locale=C 🫢
  • --locale-provider={libc|icu} β€” this option sets the locale provider for databases created in the new cluster. it can be overridden in the CREATE DATABASE command when new databases are subsequently created. the default is libc πŸ‘‘
  • -N, --no-sync β€” by default, initdb will wait for all files to be written safely to disk. this option causes initdb to return without waiting, which is faster, but means that a subsequent operating system crash can leave the data directory corrupt. generally, this option is useful for testing, but should not be used when creating a production installation.
πŸ’€ bestie, this is a "go fast and maybe regret it" flag. testing? cute. production? absolutely not.
  • --no-instructions β€” by default, initdb will write instructions for how to start the cluster at the end of its output. this option causes those instructions to be left out. this is primarily intended for use by tools that wrap initdb in platform-specific behavior, where those instructions are likely to be incorrect πŸ™ˆ
  • --pwfile=filename β€” makes initdb read the database superuser's password from a file. the first line of the file is taken as the password πŸ”
  • -S, --sync-only β€” safely write all database files to disk and exit. this does not perform any of the normal initdb operations. generally, this option is useful for ensuring reliable recovery after changing fsync from off to on πŸ’Ύ
  • -T config, --text-search-config=config β€” sets the default text search configuration. see default_text_search_config for further information πŸ”Ž
  • -U username, --username=username β€” selects the user name of the database superuser. this defaults to the name of the effective user running initdb. it is really not important what the superuser's name is, but one might choose to keep the customary name postgres, even if the operating system user's name is different πŸ‘€
  • -W, --pwprompt β€” makes initdb prompt for a password to give the database superuser. if you don't plan on using password authentication, this is not important. otherwise you won't be able to use password authentication until you have a password set up πŸ”‘
  • -X directory, --waldir=directory β€” this option specifies the directory where the write-ahead log should be stored πŸ“¦
  • --wal-segsize=size β€” set the WAL segment size, in megabytes. this is the size of each individual file in the WAL log. the default size is 16 megabytes. the value must be a power of 2 between 1 and 1024 (megabytes). this option can only be set during initialization, and cannot be changed later. it may be useful to adjust this size to control the granularity of WAL log shipping or archiving. also, in databases with a high volume of WAL, the sheer number of WAL files per directory can become a performance and management problem. increasing the WAL file size will reduce the number of WAL files πŸ”₯

πŸŽ€ Other, less commonly used, options are also available: πŸŽ€

  • -d, --debug β€” print debugging output from the bootstrap backend and a few other messages of lesser interest for the general public. the bootstrap backend is the program initdb uses to create the catalog tables. this option generates a tremendous amount of extremely boring output 😭
  • --discard-caches β€” run the bootstrap backend with the debug_discard_caches=1 option. this takes a very long time and is only of use for deep debugging 🐒
  • -L directory β€” specifies where initdb should find its input files to initialize the database cluster. this is normally not necessary. you will be told if you need to specify their location explicitly πŸ“‚
  • -n, --no-clean β€” by default, when initdb determines that an error prevented it from completely creating the database cluster, it removes any files it might have created before discovering that it cannot finish the job. this option inhibits tidying-up and is thus useful for debugging 🧹

⭐ Other options: ⭐

  • -V, --version β€” print the initdb version and exit 🏷️
  • -?, --help β€” show help about initdb command line arguments, and exit πŸ†˜

🌈 ENVIRONMENT 🌈

okay bestie, these are the env vars that initdb actually peeks at πŸ‘€ β€” three of them, no more, no less, and each one's got a whole personality:

✨ PGDATA

tells initdb where the database cluster should live πŸ“ β€” like, the actual directory it's gonna fill with files. but here's the tea: you can totally override it with the -D option if you'd rather say it to its face. so PGDATA is giving "suggestion" energy, not "final boss" energy πŸ’…

πŸŽ€ PG_COLOR

controls whether the diagnostic messages come out in color or not 🌸 the possible values are always, auto and never. literally a vibe check for your terminal output, no cap.

πŸ¦‹ TZ

sets the default time zone of the shiny new database cluster you just created ⏰ the value should be a full time zone name (see Section 8.5.3). don't be out here giving it a nickname when it wants the government name, iykyk 🫢


πŸ’€ NOTES πŸ’€

plot twist: you don't even have to call initdb directly if you don't want to πŸ”₯ initdb can also be invoked via pg_ctl initdb. same destination, different route, both iconic πŸ‘‘


πŸ‘‘ SEE ALSO πŸ‘‘

go read those if you're obsessed with context (and honestly? you should be πŸ’–)


and that's the whole page, bestie!! πŸŽ‰ this was PostgreSQL 15.19, dated 2026 β€” a whole era, an absolute icon, no notes 🌟 go make some databases, slay responsibly, and remember: your cluster is gonna be gorgeous βœ¨πŸ“πŸ’œ