INITDB(1)
π INITDB(1) π
the initdb glow-up: creating a brand-new PostgreSQL database cluster, bestie edition β¨
πΈ SYNOPSIS πΈ
initdb [option...] [--pgdata | -D] directory
π¦ DESCRIPTION π¦
okay so picture this: initdb creates a whole new PostgreSQL database cluster. and what even is a database cluster? it's literally just a collection of databases that get managed together by a single server instance. main character energy for your data, honestly π
creating a database cluster is a whole little ritual: you make the directories where the database data will live, generate the shared catalog tables (those are the tables that belong to the whole cluster rather than to any one particular database), and create the template1 and postgres databases. and here's the tea β when you later create a new database, everything in template1 gets copied. so like, anything you install in template1 is automatically copied into every database you create after that. iconic behavior, no notes. and postgres is a default database meant for use by users, utilities and third party applications π«Ά
so initdb will try to create the data directory you specify, but it might not have permission if the parent directory of your desired data directory is root-owned. annoying, i know. to initialize in that kind of setup, create an empty data directory as root, then use chown to give ownership of that directory to the database user account, then su to become the database user to run initdb. slay, you got this π
and listen β initdb must be run as the user that will own the server process, because the server needs access to all the files and directories that initdb creates. and since the server cannot be run as root, you must not run initdb as root either. (it will in fact refuse to do so, like it's literally not gonna let you π)
for security reasons, the new cluster created by initdb will only be accessible by the cluster owner by default. the --allow-group-access option lets any user in the same group as the cluster owner read files in the cluster. this is useful for performing backups as a non-privileged user β very demure, very mindful πΈ
initdb also initializes the database cluster's default locale and character set encoding. the character set encoding, collation order (LC_COLLATE) and character set classes (LC_CTYPE, e.g., upper, lower, digit) can all be set separately for a database when it is created. initdb determines those settings for the template1 database, which will serve as the default for all other databases.
to alter the default collation order or character set classes, use the --lc-collate and --lc-ctype options. quick heads up though: collation orders other than C or POSIX also have a performance penalty. so for these reasons it is important to choose the right locale when running initdb. choose wisely bestie π
the remaining locale categories can be changed later when the server is started. you can also use --locale to set the default for all locale categories, including collation order and character set classes. all server locale values (lc_*) can be displayed via SHOW ALL. more details 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 β¨
-A authmethod,--auth=authmethodβ this one specifies the default authentication method for local users, used inpg_hba.conf(bothhostandlocallines).initdbwill prepopulatepg_hba.confentries using the specified authentication method for non-replication as well as replication connections.
β οΈ do not usetrustunless you trust all local users on your system.trustis the default for ease of installation, but likeβ¦ be careful bestie π
--auth-host=authmethodβ specifies the authentication method for local users via TCP/IP connections, used inpg_hba.conf(hostlines).--auth-local=authmethodβ specifies the authentication method for local users via Unix-domain socket connections, used inpg_hba.conf(locallines).-D directory,--pgdata=directoryβ specifies the directory where the database cluster should be stored. this is the only infoinitdbactually requires, but you can avoid writing it by setting thePGDATAenvironment variable, which is lowkey 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 database. this will also be the default encoding of any database you create later, unless you override it there. the default is derived from the locale, orSQL_ASCIIif that does not work. the character sets supported by the PostgreSQL server are described in Section 23.3.1.-g,--allow-group-accessβ allows users in the same group as the cluster owner to read all cluster files created byinitdb. this option is ignored on Windows since it does not support POSIX-style group permissions.-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 thepg_stat_databaseview π--locale=localeβ sets the default locale for the database cluster. if this option is not specified, the locale is inherited from the environment thatinitdbruns in. locale support is described in Section 23.1.--lc-collate=locale,--lc-ctype=locale,--lc-messages=locale,--lc-monetary=locale,--lc-numeric=locale,--lc-time=localeβ like--locale, but only sets the locale in that specific category. one category at a time, very focused, very intentional π--no-localeβ equivalent to--locale=C.-N,--no-syncβ by default,initdbwill wait for all files to be written safely to disk. this option causesinitdbto return without waiting, which is faster but means 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.--pwfile=filenameβ makesinitdbread 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 normalinitdboperations.-T config,--text-search-config=configβ sets the default text search configuration. seedefault_text_search_configfor further information.-U username,--username=usernameβ selects the user name of the database superuser. this defaults to the name of the effective user runninginitdb. it is really not important what the superuser's name is, but one might choose to keep the customary namepostgres, even if the operating system user's name is different.-W,--pwpromptβ makesinitdbprompt 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β 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 β so like, commit to it fr fr.
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. efficiency icon behavior π₯
π§ 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 programinitdbuses to create the catalog tables. this option generates a tremendous amount of extremely boring output π΄-L directoryβ specifies whereinitdbshould 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, wheninitdbdetermines 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 the tidying-up and is thus useful for debugging.
π other options:
-V,--versionβ print theinitdbversion and exit.-?,--helpβ show help aboutinitdbcommand line arguments, and exit.
π 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. (aesthetic diagnostics, we love to see it π¨)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. cute shortcut, iykyk π«Ά
π SEE ALSO π
pg_ctl(1), postgres(1)
okurrr that's the whole page bestie, you're SO ready to spin up a cluster now π periodt. this slay of a manual page came to you from the PostgreSQL 13.23 documentation era, dated 2025 β go forth and initdb responsibly, mwah ππΈ
π¦ where this page comes from
- opensuse-leap 16.0: postgresql13-server 13.23-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql13-server 13.23-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql13-server 13.23-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql13-server 13.23-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