INITDB(1)

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

πŸ’… INITDB β€” the PostgreSQL 17.11 docs, bestie edition ✨

okay so this is initdb(1) from the PostgreSQL 17.11 documentation and honestly? she's the moment. she's where every single Postgres cluster is born. let's get into it 🫢


🌸 NAME 🌸

initdb β€” create a new PostgreSQL database cluster πŸ‘‘


✨ SYNOPSIS ✨

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

πŸ¦‹ DESCRIPTION πŸ¦‹

initdb creates a new PostgreSQL database cluster. that's it, that's the tweet. main character energy from the very first line πŸ’–

Creating a database cluster consists of creating the directories in which the cluster 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. so like, three little databases are born on day one πŸŽ€

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 β€” like, do not touch her, she is sacred β€” but you can add objects to template1, which by default will be copied into databases created later. see Section 22.3 for more details. iykyk ✨

⚠️ ngl this next part trips people up so read it twice. 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. that's the whole ritual, in order, no skipping steps πŸ™ˆ

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.) she said no πŸ’€ periodt.

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. very demure, very least-privilege 🧚

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. so the templates are basically the blueprint, everything downstream copies them 🌈

πŸ’œ locale stuff, aka the part where you have options πŸ’œ

By default, initdb uses the locale provider libc (see Section 23.1.4). The libc locale provider takes the locale settings from the environment, and determines the encoding from the locale settings. environment said what it said, libc listened πŸ“

To choose a different locale for the cluster, use the option --locale. There are also individual options --lc-* and --icu-locale (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. like, mix and match at your own risk bestie 😭

Alternatively, initdb can use the ICU library to provide locale services by specifying --locale-provider=icu. The server must be built with ICU support. 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. she's doing both at once and honestly? iconic multitasking πŸ‘‘

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. vibe check your output, fr fr, it tells you what it picked β€” read it πŸ‘€

More details about locale settings can be found in Section 23.1. πŸ“š

To alter the default encoding, use the --encoding. More details can be found in Section 23.3. ✨

✨ OPTIONS ✨

okay bestie, buckle up, this is the part where we go through literally every flag πŸ’…

  • -A authmethod, --auth=authmethod β€” sets the default authentication method for local users, the one that goes into pg_hba.conf (the host and local lines, iykyk). Section 20.1 has the whole rundown of valid values. initdb will prepopulate those pg_hba.conf entries using whatever method you picked β€” for non-replication and replication connections, both. 🫢
⚠️ Do not use trust unless you genuinely trust all local users on your system. It's the default purely for ease of installation, not because it's a vibe.
  • --auth-host=authmethod β€” this one sets the auth method for local users coming in via TCP/IP connections, i.e. the host lines in pg_hba.conf. 🌐
  • --auth-local=authmethod β€” and this one's for local users over Unix-domain socket connections, i.e. the local lines in pg_hba.conf. πŸ”Œ
  • -D directory, --pgdata=directory β€” tells it where the database cluster should live. Fun fact: this is the only info initdb actually requires. But you can dodge writing it out by setting the PGDATA environment variable instead, which is lowkey convenient because the database server (postgres) can find the data directory later using that same variable. πŸŽ€
  • -E encoding, --encoding=encoding β€” picks the encoding of the template databases. This also becomes the default encoding of every database you create later, unless you override it at that point. The character sets the PostgreSQL server supports are catalogued in Section 23.3.1. πŸ“ By default the template database encoding is derived from the locale. But if --no-locale is specified (or equivalently, the locale is C or POSIX), then the default is UTF8 for the ICU provider and SQL_ASCII for the libc provider. slay, very specific.
  • -g, --allow-group-access β€” lets users in the same group as the cluster owner read all the cluster files initdb creates. This option is ignored on Windows, because Windows doesn't do POSIX-style group permissions. sorry bestie πŸ’€
  • --icu-locale=locale β€” specifies the ICU locale when the ICU provider is in use. Locale support lives in Section 23.1. 🌍
  • --icu-rules=rules β€” specifies extra collation rules to customize how the default collation behaves. ICU only, no cap. ✨
  • -k, --data-checksums β€” puts checksums on data pages so you can catch corruption caused by the I/O system that would otherwise be completely silent. Heads up: enabling checksums may incur a noticeable performance penalty. If set, checksums get calculated for all objects, in all databases. All checksum failures get reported in the pg_stat_database view. Section 28.2 has the details. πŸ”
  • --locale=locale β€” sets the default locale for the database cluster. If you don't specify this option, the locale gets inherited from the environment that initdb runs in. Locale support is described in Section 23.1. 🌸 If --locale-provider is builtin, then --locale or --builtin-locale must be specified and set to C or C.UTF-8.
  • --lc-collate=locale, --lc-ctype=locale, --lc-messages=locale, --lc-monetary=locale, --lc-numeric=locale, --lc-time=locale β€” same energy as --locale, except each one only sets the locale in its specific category. one lil category each, iconic behavior πŸ’…
  • --no-locale β€” literally equivalent to --locale=C. that's it, that's the whole option.
  • --builtin-locale=locale β€” specifies the locale name when the builtin provider is used. Locale support is described in Section 23.1. 🧚
  • --locale-provider={builtin|libc|icu} β€” sets the locale provider for databases created in the new cluster. You can override it later in the CREATE DATABASE command whenever you create new databases afterward. The default is libc (see Section 23.1.4). πŸ‘‘
  • --pwfile=filename β€” makes initdb read the bootstrap superuser's password from a file. The first line of the file is taken as the password. first line only, don't get cute. πŸ“„
  • -T config, --text-search-config=config β€” sets the default text search configuration. See default_text_search_config for more info. πŸ”Ž
  • -U username, --username=username β€” sets the user name of the bootstrap superuser. Defaults to the name of the operating-system user running initdb. 🫑
  • -W, --pwprompt β€” makes initdb prompt you for a password to give the bootstrap superuser. If you're not planning on using password authentication, this one isn't important. Otherwise: you won't be able to use password authentication until you've got a password set up. πŸ”
  • -X directory, --waldir=directory β€” specifies where the write-ahead log should be stored. πŸ“‚
  • --wal-segsize=size β€” sets the WAL segment size in megabytes. This is the size of each individual file in the WAL log. Default is 16 megabytes. The value must be a power of 2 between 1 and 1024 (megabytes). This option can only be set during initialization β€” it cannot be changed later. periodt. 🚫 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 πŸ¦‹

  • -c name=value, --set name=value β€” forcibly sets the server parameter name to value during initdb, and also installs that setting in the generated postgresql.conf file so it applies during future server runs. You can give this option more than once to set several parameters. It's primarily useful when the environment is such that the server won't start at all using the default parameters. πŸ› οΈ
  • -d, --debug β€” prints debugging output from the bootstrap backend plus a few other messages of lesser interest to 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. like, so much. πŸ’€
  • --discard-caches β€” runs 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'll 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 it can't finish the job. This option inhibits the tidying-up, which is useful for debugging. 🧹❌
  • -N, --no-sync β€” by default initdb waits for all files to be written safely to disk. This option makes initdb return without waiting, which is faster, but it means a subsequent operating system crash can leave the data directory corrupt. Generally this one's useful for testing, but should not be used when creating a production installation. ⚠️
  • --no-instructions β€” by default initdb writes instructions for how to start the cluster at the end of its output. This option leaves those instructions out. It's primarily intended for tools that wrap initdb in platform-specific behavior, where those instructions are likely to be incorrect. 🀐
  • -s, --show β€” shows internal settings and exits, without doing anything else. Can be used to debug the initdb installation. πŸ”§
  • --sync-method=method β€” when set to fsync, which is the default, initdb recursively opens and synchronizes all files in the data directory. The search for files will follow symbolic links for the WAL directory and each configured tablespace. πŸŒ€ On Linux, syncfs may be used instead to ask the operating system to synchronize the whole file systems that contain the data directory, the WAL files, and each tablespace. See recovery_init_sync_method for info about the caveats to be aware of when using syncfs. This option has no effect when --no-sync is used.
  • -S, --sync-only β€” safely writes all database files to disk and exits. This does not perform any of the normal initdb operations. Generally it's useful for ensuring reliable recovery after changing fsync from off to on. πŸ’Ύ

⭐ Other options ⭐

  • -V, --version β€” prints the initdb version and exits. 🏷️
  • -?, --help β€” shows help about initdb command line arguments, and exits. πŸ†˜

🌈 ENVIRONMENT 🌈

  • PGDATA β€” specifies the directory where the database cluster is to be stored; can be overridden using the -D option. πŸ“
  • PG_COLOR β€” specifies whether to use color in diagnostic messages. Possible values are always, auto and never. 🎨
  • TZ β€” specifies the default time zone of the created database cluster. The value should be a full time zone name (see Section 8.5.3). 🌏

πŸ’œ NOTES πŸ’œ

initdb can also be invoked via pg_ctl initdb. two ways to do the thing, we love options 🫢


πŸŽ€ SEE ALSO πŸŽ€

pg_ctl(1), postgres(1), Section 20.1


and that's the whole page bestie!! this was PostgreSQL 17.11, dated 2026, filed under INITDB(1) β€” go forth and initialize that cluster, you're gonna slay πŸ’–βœ¨πŸ‘‘