1INITDB(1)                PostgreSQL 14.3 Documentation               INITDB(1)
2
3
4

NAME

6       initdb - create a new PostgreSQL database cluster
7

SYNOPSIS

9       initdb [option...] [--pgdata | -D] directory
10

DESCRIPTION

12       initdb creates a new PostgreSQL database cluster. A database cluster is
13       a collection of databases that are managed by a single server instance.
14
15       Creating a database cluster consists of creating the directories in
16       which the database data will live, generating the shared catalog tables
17       (tables that belong to the whole cluster rather than to any particular
18       database), and creating the template1 and postgres databases. When you
19       later create a new database, everything in the template1 database is
20       copied. (Therefore, anything installed in template1 is automatically
21       copied into each database created later.) The postgres database is a
22       default database meant for use by users, utilities and third party
23       applications.
24
25       Although initdb will attempt to create the specified data directory, it
26       might not have permission if the parent directory of the desired data
27       directory is root-owned. To initialize in such a setup, create an empty
28       data directory as root, then use chown to assign ownership of that
29       directory to the database user account, then su to become the database
30       user to run initdb.
31
32       initdb must be run as the user that will own the server process,
33       because the server needs to have access to the files and directories
34       that initdb creates. Since the server cannot be run as root, you must
35       not run initdb as root either. (It will in fact refuse to do so.)
36
37       For security reasons the new cluster created by initdb will only be
38       accessible by the cluster owner by default. The --allow-group-access
39       option allows any user in the same group as the cluster owner to read
40       files in the cluster. This is useful for performing backups as a
41       non-privileged user.
42
43       initdb initializes the database cluster's default locale and character
44       set encoding. The character set encoding, collation order (LC_COLLATE)
45       and character set classes (LC_CTYPE, e.g., upper, lower, digit) can be
46       set separately for a database when it is created.  initdb determines
47       those settings for the template1 database, which will serve as the
48       default for all other databases.
49
50       To alter the default collation order or character set classes, use the
51       --lc-collate and --lc-ctype options. Collation orders other than C or
52       POSIX also have a performance penalty. For these reasons it is
53       important to choose the right locale when running initdb.
54
55       The remaining locale categories can be changed later when the server is
56       started. You can also use --locale to set the default for all locale
57       categories, including collation order and character set classes. All
58       server locale values (lc_*) can be displayed via SHOW ALL. More details
59       can be found in Section 24.1.
60
61       To alter the default encoding, use the --encoding. More details can be
62       found in Section 24.3.
63

OPTIONS

65       -A authmethod
66       --auth=authmethod
67           This option specifies the default authentication method for local
68           users used in pg_hba.conf (host and local lines).  initdb will
69           prepopulate pg_hba.conf entries using the specified authentication
70           method for non-replication as well as replication connections.
71
72           Do not use trust unless you trust all local users on your system.
73           trust is the default for ease of installation.
74
75       --auth-host=authmethod
76           This option specifies the authentication method for local users via
77           TCP/IP connections used in pg_hba.conf (host lines).
78
79       --auth-local=authmethod
80           This option specifies the authentication method for local users via
81           Unix-domain socket connections used in pg_hba.conf (local lines).
82
83       -D directory
84       --pgdata=directory
85           This option specifies the directory where the database cluster
86           should be stored. This is the only information required by initdb,
87           but you can avoid writing it by setting the PGDATA environment
88           variable, which can be convenient since the database server
89           (postgres) can find the database directory later by the same
90           variable.
91
92       -E encoding
93       --encoding=encoding
94           Selects the encoding of the template database. This will also be
95           the default encoding of any database you create later, unless you
96           override it there. The default is derived from the locale, or
97           SQL_ASCII if that does not work. The character sets supported by
98           the PostgreSQL server are described in Section 24.3.1.
99
100       -g
101       --allow-group-access
102           Allows users in the same group as the cluster owner to read all
103           cluster files created by initdb. This option is ignored on Windows
104           as it does not support POSIX-style group permissions.
105
106       -k
107       --data-checksums
108           Use checksums on data pages to help detect corruption by the I/O
109           system that would otherwise be silent. Enabling checksums may incur
110           a noticeable performance penalty. If set, checksums are calculated
111           for all objects, in all databases. All checksum failures will be
112           reported in the pg_stat_database view. See Section 30.2 for
113           details.
114
115       --locale=locale
116           Sets the default locale for the database cluster. If this option is
117           not specified, the locale is inherited from the environment that
118           initdb runs in. Locale support is described in Section 24.1.
119
120       --lc-collate=locale
121       --lc-ctype=locale
122       --lc-messages=locale
123       --lc-monetary=locale
124       --lc-numeric=locale
125       --lc-time=locale
126           Like --locale, but only sets the locale in the specified category.
127
128       --no-locale
129           Equivalent to --locale=C.
130
131       -N
132       --no-sync
133           By default, initdb will wait for all files to be written safely to
134           disk. This option causes initdb to return without waiting, which is
135           faster, but means that a subsequent operating system crash can
136           leave the data directory corrupt. Generally, this option is useful
137           for testing, but should not be used when creating a production
138           installation.
139
140       --no-instructions
141           By default, initdb will write instructions for how to start the
142           cluster at the end of its output. This option causes those
143           instructions to be left out. This is primarily intended for use by
144           tools that wrap initdb in platform-specific behavior, where those
145           instructions are likely to be incorrect.
146
147       --pwfile=filename
148           Makes initdb read the database superuser's password from a file.
149           The first line of the file is taken as the password.
150
151       -S
152       --sync-only
153           Safely write all database files to disk and exit. This does not
154           perform any of the normal initdb operations.
155
156       -T config
157       --text-search-config=config
158           Sets the default text search configuration. See
159           default_text_search_config for further information.
160
161       -U username
162       --username=username
163           Selects the user name of the database superuser. This defaults to
164           the name of the effective user running initdb. It is really not
165           important what the superuser's name is, but one might choose to
166           keep the customary name postgres, even if the operating system
167           user's name is different.
168
169       -W
170       --pwprompt
171           Makes initdb prompt for a password to give the database superuser.
172           If you don't plan on using password authentication, this is not
173           important. Otherwise you won't be able to use password
174           authentication until you have a password set up.
175
176       -X directory
177       --waldir=directory
178           This option specifies the directory where the write-ahead log
179           should be stored.
180
181       --wal-segsize=size
182           Set the WAL segment size, in megabytes. This is the size of each
183           individual file in the WAL log. The default size is 16 megabytes.
184           The value must be a power of 2 between 1 and 1024 (megabytes). This
185           option can only be set during initialization, and cannot be changed
186           later.
187
188           It may be useful to adjust this size to control the granularity of
189           WAL log shipping or archiving. Also, in databases with a high
190           volume of WAL, the sheer number of WAL files per directory can
191           become a performance and management problem. Increasing the WAL
192           file size will reduce the number of WAL files.
193
194       Other, less commonly used, options are also available:
195
196       -d
197       --debug
198           Print debugging output from the bootstrap backend and a few other
199           messages of lesser interest for the general public. The bootstrap
200           backend is the program initdb uses to create the catalog tables.
201           This option generates a tremendous amount of extremely boring
202           output.
203
204       --discard-caches
205           Run the bootstrap backend with the debug_discard_caches=1 option.
206           This takes a very long time and is only of use for deep debugging.
207
208       -L directory
209           Specifies where initdb should find its input files to initialize
210           the database cluster. This is normally not necessary. You will be
211           told if you need to specify their location explicitly.
212
213       -n
214       --no-clean
215           By default, when initdb determines that an error prevented it from
216           completely creating the database cluster, it removes any files it
217           might have created before discovering that it cannot finish the
218           job. This option inhibits tidying-up and is thus useful for
219           debugging.
220
221       Other options:
222
223       -V
224       --version
225           Print the initdb version and exit.
226
227       -?
228       --help
229           Show help about initdb command line arguments, and exit.
230

ENVIRONMENT

232       PGDATA
233           Specifies the directory where the database cluster is to be stored;
234           can be overridden using the -D option.
235
236       PG_COLOR
237           Specifies whether to use color in diagnostic messages. Possible
238           values are always, auto and never.
239
240       TZ
241           Specifies the default time zone of the created database cluster.
242           The value should be a full time zone name (see Section 8.5.3).
243
244       This utility, like most other PostgreSQL utilities, also uses the
245       environment variables supported by libpq (see Section 34.15).
246

NOTES

248       initdb can also be invoked via pg_ctl initdb.
249

SEE ALSO

251       pg_ctl(1), postgres(1)
252
253
254
255PostgreSQL 14.3                      2022                            INITDB(1)
Impressum