INITDB(1)
π
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. Althoughinitdbwill 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 usechownto assign ownership of that directory to the database user account, thensuto become the database user to runinitdb. 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 intopg_hba.conf(thehostandlocallines, iykyk). Section 20.1 has the whole rundown of valid values.initdbwill prepopulate thosepg_hba.confentries 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. thehostlines inpg_hba.conf. π--auth-local=authmethodβ and this one's for local users over Unix-domain socket connections, i.e. thelocallines inpg_hba.conf. π-D directory,--pgdata=directoryβ tells it where the database cluster should live. Fun fact: this is the only infoinitdbactually requires. But you can dodge writing it out by setting thePGDATAenvironment 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-localeis specified (or equivalently, the locale isCorPOSIX), then the default isUTF8for the ICU provider andSQL_ASCIIfor the libc provider. slay, very specific.-g,--allow-group-accessβ lets users in the same group as the cluster owner read all the cluster filesinitdbcreates. 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 thepg_stat_databaseview. 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 thatinitdbruns in. Locale support is described in Section 23.1. πΈ If--locale-providerisbuiltin, then--localeor--builtin-localemust be specified and set toCorC.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 theCREATE DATABASEcommand whenever you create new databases afterward. The default islibc(see Section 23.1.4). π--pwfile=filenameβ makesinitdbread 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. Seedefault_text_search_configfor more info. π-U username,--username=usernameβ sets the user name of the bootstrap superuser. Defaults to the name of the operating-system user runninginitdb. π«‘-W,--pwpromptβ makesinitdbprompt 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 duringinitdb, and also installs that setting in the generatedpostgresql.conffile 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 programinitdbuses 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 thedebug_discard_caches=1option. This takes a very long time and is only of use for deep debugging. π-L directoryβ specifies whereinitdbshould 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, wheninitdbdetermines 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 defaultinitdbwaits for all files to be written safely to disk. This option makesinitdbreturn 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 defaultinitdbwrites 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 wrapinitdbin 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 theinitdbinstallation. π§--sync-method=methodβ when set tofsync, which is the default,initdbrecursively 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,syncfsmay 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. Seerecovery_init_sync_methodfor info about the caveats to be aware of when usingsyncfs. This option has no effect when--no-syncis used.-S,--sync-onlyβ safely writes all database files to disk and exits. This does not perform any of the normalinitdboperations. Generally it's useful for ensuring reliable recovery after changingfsyncfrom off to on. πΎ
β Other options β
-V,--versionβ prints theinitdbversion and exits. π·οΈ-?,--helpβ shows help aboutinitdbcommand line arguments, and exits. π
π ENVIRONMENT π
PGDATAβ specifies the directory where the database cluster is to be stored; can be overridden using the-Doption. πPG_COLORβ specifies whether to use color in diagnostic messages. Possible values arealways,autoandnever. π¨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 πβ¨π
π¦ where this page comes from
- opensuse-leap 16.0: postgresql17-server 17.11-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql17-server 17.11-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql17-server 17.11-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql17-server 17.11-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