INITDB(1)
π 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 inpg_hba.conf(hostandlocallines). see Section 21.1 for an overview of valid values.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. 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 inpg_hba.conf(hostlines) π--auth-local=authmethodβ this option specifies the authentication method for local users via Unix-domain socket connections used inpg_hba.conf(locallines) π-D directory,--pgdata=directoryβ this option specifies the directory where the database cluster should be stored. this is the only information required byinitdb, but you can avoid writing it by setting thePGDATAenvironment 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 thelibclocale provider is used, orUTF8if 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 byinitdb. 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 thepg_stat_databaseview. 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 thatinitdbruns 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 theCREATE DATABASEcommand when new databases are subsequently created. the default islibcπ-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 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,initdbwill 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 wrapinitdbin platform-specific behavior, where those instructions are likely to be incorrect π--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. generally, this option is useful for ensuring reliable recovery after changingfsyncfrom off to on πΎ-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β 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 programinitdbuses to create the catalog tables. this option generates a tremendous amount of extremely boring output π--discard-cachesβ run 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 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 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 π
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 π
pg_ctl(1)postgres(1)- Section 21.1
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 β¨ππ
π¦ where this page comes from
- opensuse-leap 16.0: postgresql15-server 15.19-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql15-server 15.19-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql15-server 15.19-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql15-server 15.19-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