LinuxCommandLibrary

initdb

TLDR

Initialize PostgreSQL database cluster

$ initdb -D [/var/lib/postgresql/data]
copy
Initialize with specific encoding
$ initdb -D [/var/lib/postgresql/data] -E UTF8
copy
Initialize with specific locale
$ initdb -D [/var/lib/postgresql/data] --locale=[en_US.UTF-8]
copy
Initialize with authentication
$ initdb -D [/var/lib/postgresql/data] -A [scram-sha-256] -W
copy
Initialize with specific user
$ initdb -D [/var/lib/postgresql/data] -U [postgres]
copy

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.

SEE ALSO

pg_ctl(1), postgres(1), createdb(1)

Copied to clipboard