initdb
TLDR
Initialize PostgreSQL database cluster
$ initdb -D [/var/lib/postgresql/data]
Initialize with specific encoding$ initdb -D [/var/lib/postgresql/data] -E UTF8
Initialize with specific locale$ initdb -D [/var/lib/postgresql/data] --locale=[en_US.UTF-8]
Initialize with authentication$ initdb -D [/var/lib/postgresql/data] -A [scram-sha-256] -W
Initialize with specific user$ initdb -D [/var/lib/postgresql/data] -U [postgres]
SYNOPSIS
initdb [options] -D directory
DESCRIPTION
initdb creates a new PostgreSQL database cluster. A cluster is a collection of databases managed by a single PostgreSQL server instance, stored in a data directory.
This command must be run before starting PostgreSQL for the first time. It creates the template databases, configuration files, and directory structure.
PARAMETERS
-D, --pgdata dir
Data directory location.-E, --encoding encoding
Default database encoding.--locale locale
Default locale.-U, --username user
Database superuser name.-W, --pwprompt
Prompt for superuser password.-A, --auth method
Authentication method.--auth-local method
Local connection auth method.--auth-host method
Host connection auth method.-k, --data-checksums
Enable data checksums.--wal-segsize size
WAL segment size.
CAVEATS
Must run as the PostgreSQL user. Directory must be empty or non-existent. Encoding and locale affect all databases. Data checksums cannot be changed later.
HISTORY
initdb is part of PostgreSQL, developed since 1996 by the PostgreSQL Global Development Group. It originated from the POSTGRES project at UC Berkeley.


