INITDB(1)
π NAME π
initdb β create a new PostgreSQL database cluster π
okay so this is the INITDB(1) page from the PostgreSQL 16.15 Documentation, and bestie, we're gonna get you fully caught up on what initdb does, no cap. β¨
πΈ SYNOPSIS πΈ
initdb [option...] [--pgdata | -D] directory
π¦ DESCRIPTION π¦
initdb creates a new PostgreSQL database cluster. That's the whole vibe. π«Ά
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. Iconic lineup, honestly:
postgresβ a default database meant for use by users, utilities and third party applications. she's the main character πtemplate1andtemplate0β meant as source databases to be copied by laterCREATE DATABASEcommands.
Lowkey important: template0 should never be modified β hands off, bestie π« β but you can add objects to template1, which by default will be copied into databases created later. See Section 23.3 for more details. iykyk.
So like, initdb will attempt to create the specified data directory, but it might not have permission if the parent directory of the desired data directory is root-owned π. To initialize in such a setup, do the little dance:
- create an empty data directory as root
- then use
chownto assign ownership of that directory to the database user account - then
suto become the database user to runinitdb
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. π it said no.)
For security reasons the new cluster created byinitdbwill only be accessible by the cluster owner by default. The--allow-group-accessoption 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. so everyone inherits the template's fit, basically π
By default, initdb uses the locale provider libc (see Section 24.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 π
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. π« fr fr, don't mix-and-match and then act surprised.
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. legacy code really said "i'm still here" π
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. π like, actually read the output, bestie.
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 menu of flags. no skipping, we're going through all of them π
- *
-A*authmethod,--auth=*authmethod*** β sets the default auth method for local users, the one that goes inpg_hba.conf(on thehostandlocal` lines). valid values are in Section 21.1, go look π
initdb will prepopulate the pg_hba.conf entries with whatever method you picked, for both non-replication and replication connections.
do not use trust unless you genuinely trust every local user on your system, fr. it's the default tho, purely for ease of installation π«Ά
--auth-host=authmethod β this one sets the auth method for local users coming in over 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*** β where the database cluster lives. this is literally the only infoinitdbrequires π but you can skip writing it by setting thePGDATAenvironment variable, which is lowkey convenient since the server (postgres`) can find the data directory later using that same variable. iconic teamwork. -Eencoding,--encoding=`encoding β picks the encoding for the template databases. this also becomes the default encoding for any database you create later, unless you override it at that point. the character sets the PostgreSQL server supports are in Section 24.3.1.
by default, the template database encoding is derived from the locale. if --no-locale is specified (or equivalently, if the locale is C or POSIX), then the default is UTF8 for the ICU provider and SQL_ASCII for the libc provider. slay.
-g,--allow-group-accessβ lets users in the same group as the cluster owner read all the cluster filesinitdbcreates. this option just gets ignored on Windows because Windows doesn't do POSIX-style group permissions π--icu-locale=locale β specifies the ICU locale when the ICU provider is in use. locale support is described in Section 24.1.--icu-rules=rules β extra collation rules to customize how the default collation behaves. ICU only, bestie.-k,--data-checksumsβ puts checksums on data pages so you can catch corruption from the I/O system that would otherwise be totally silent π but ngl, enabling checksums may cost you a noticeable performance penalty. if set, checksums get calculated for all objects, in all databases. all checksum failures get reported in thepg_stat_databaseview. details in Section 30.2.--locale=locale β sets the default locale for the database cluster. if you don't specify this, the locale is inherited from the environmentinitdbruns in. locale support is described in Section 24.1.--lc-collate=locale,--lc-ctype=locale,--lc-messages=locale,--lc-monetary=locale,--lc-numeric=locale,--lc-time=locale β same energy as--locale, but each one only sets the locale in its specified category β¨--no-localeβ equivalent to--locale=C. that's it, that's the whole thing.--locale-provider={libc|icu}β sets the locale provider for databases created in the new cluster. you can override it later in theCREATE DATABASEcommand when you create new databases. default islibc(see Section 24.1.4).-N,--no-syncβ by defaultinitdbwaits for all files to be safely written to disk. this option makes it return without waiting, which is faster, but means a later operating system crash can leave the data directory corrupt π generally this one's for testing β do not use it when you're making a production installation, okay?--no-instructionsβ by defaultinitdbwrites instructions for how to start the cluster at the end of its output. this option leaves those out. it's mainly for tools that wrapinitdbin platform-specific behavior, where those instructions would probably be wrong anyway.--pwfile=filename β makesinitdbread the bootstrap superuser's password from a file. the first line of the file is taken as the password π-S,--sync-onlyβ safely writes all the database files to disk and exits. it does none of the normalinitdboperations. generally useful for making sure recovery is reliable after flippingfsyncfrom off to on.- *
-T*config,--text-search-config=*config*** β sets the default text search configuration. seedefault_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 runninginitdb`. -W,--pwpromptβ makesinitdbprompt you for a password for the bootstrap superuser. if you're not planning on using password authentication, no big deal. otherwise you literally won't be able to use password authentication until you've got a password set up π-Xdirectory,--waldir=`directory β specifies the directory where the write-ahead log should be stored.--wal-segsize=size β sets the WAL segment size, in megabytes. that's 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). and heads up: this can only be set during initialization β it cannot be changed later.
it may be useful to tweak this 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. bumping the WAL file size reduces the number of WAL files. math is math β¨
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.conf` file so it applies during future server runs. you can give this option more than once to set several parameters. it's mainly useful when the environment is such that the server won't start at all with 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. warning: this option generates a tremendous amount of extremely boring output π--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. like, deep deep.-Ldirectory β specifies whereinitdbshould find its input files to initialize the database cluster. normally not necessary. you'll be told if you need to specify their location explicitly π«Ά-n,--no-cleanβ by default, wheninitdbfigures out 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 thus useful for debugging.
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 π¦
fun fact bestie: initdb can also be invoked via pg_ctl initdb π
π SEE ALSO π
pg_ctl(1), postgres(1), Section 21.1
and that's the whole page, you're so welcome π this lil gem is from PostgreSQL 16.15, dated 2026, and it's the INITDB(1) page β go forth and initialize your clusters, main character π«Άβ¨
π¦ where this page comes from
- opensuse-leap 16.0: postgresql16-server 16.15-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql16-server 16.15-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql16-server 16.15-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql16-server 16.15-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