1INITDB(1) PostgreSQL 12.6 Documentation INITDB(1)
2
3
4
6 initdb - create a new PostgreSQL database cluster
7
9 initdb [option...] [--pgdata | -D] directory
10
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 23.1.
60
61 To alter the default encoding, use the --encoding. More details can be
62 found in Section 23.3.
63
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 23.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.
113
114 --locale=locale
115 Sets the default locale for the database cluster. If this option is
116 not specified, the locale is inherited from the environment that
117 initdb runs in. Locale support is described in Section 23.1.
118
119 --lc-collate=locale
120 --lc-ctype=locale
121 --lc-messages=locale
122 --lc-monetary=locale
123 --lc-numeric=locale
124 --lc-time=locale
125 Like --locale, but only sets the locale in the specified category.
126
127 --no-locale
128 Equivalent to --locale=C.
129
130 -N
131 --no-sync
132 By default, initdb will wait for all files to be written safely to
133 disk. This option causes initdb to return without waiting, which is
134 faster, but means that a subsequent operating system crash can
135 leave the data directory corrupt. Generally, this option is useful
136 for testing, but should not be used when creating a production
137 installation.
138
139 --pwfile=filename
140 Makes initdb read the database superuser's password from a file.
141 The first line of the file is taken as the password.
142
143 -S
144 --sync-only
145 Safely write all database files to disk and exit. This does not
146 perform any of the normal initdb operations.
147
148 -T config
149 --text-search-config=config
150 Sets the default text search configuration. See
151 default_text_search_config for further information.
152
153 -U username
154 --username=username
155 Selects the user name of the database superuser. This defaults to
156 the name of the effective user running initdb. It is really not
157 important what the superuser's name is, but one might choose to
158 keep the customary name postgres, even if the operating system
159 user's name is different.
160
161 -W
162 --pwprompt
163 Makes initdb prompt for a password to give the database superuser.
164 If you don't plan on using password authentication, this is not
165 important. Otherwise you won't be able to use password
166 authentication until you have a password set up.
167
168 -X directory
169 --waldir=directory
170 This option specifies the directory where the write-ahead log
171 should be stored.
172
173 --wal-segsize=size
174 Set the WAL segment size, in megabytes. This is the size of each
175 individual file in the WAL log. The default size is 16 megabytes.
176 The value must be a power of 2 between 1 and 1024 (megabytes). This
177 option can only be set during initialization, and cannot be changed
178 later.
179
180 It may be useful to adjust this size to control the granularity of
181 WAL log shipping or archiving. Also, in databases with a high
182 volume of WAL, the sheer number of WAL files per directory can
183 become a performance and management problem. Increasing the WAL
184 file size will reduce the number of WAL files.
185
186 Other, less commonly used, options are also available:
187
188 -d
189 --debug
190 Print debugging output from the bootstrap backend and a few other
191 messages of lesser interest for the general public. The bootstrap
192 backend is the program initdb uses to create the catalog tables.
193 This option generates a tremendous amount of extremely boring
194 output.
195
196 -L directory
197 Specifies where initdb should find its input files to initialize
198 the database cluster. This is normally not necessary. You will be
199 told if you need to specify their location explicitly.
200
201 -n
202 --no-clean
203 By default, when initdb determines that an error prevented it from
204 completely creating the database cluster, it removes any files it
205 might have created before discovering that it cannot finish the
206 job. This option inhibits tidying-up and is thus useful for
207 debugging.
208
209 Other options:
210
211 -V
212 --version
213 Print the initdb version and exit.
214
215 -?
216 --help
217 Show help about initdb command line arguments, and exit.
218
220 PGDATA
221 Specifies the directory where the database cluster is to be stored;
222 can be overridden using the -D option.
223
224 PG_COLOR
225 Specifies whether to use color in diagnostic messages. Possible
226 values are always, auto and never.
227
228 TZ
229 Specifies the default time zone of the created database cluster.
230 The value should be a full time zone name (see Section 8.5.3).
231
232 This utility, like most other PostgreSQL utilities, also uses the
233 environment variables supported by libpq (see Section 33.14).
234
236 initdb can also be invoked via pg_ctl initdb.
237
239 pg_ctl(1), postgres(1)
240
241
242
243PostgreSQL 12.6 2021 INITDB(1)