]> begriffs open source - ai-pg/blob - full-docs/man1/initdb.1
Convert HTML docs to more streamlined TXT
[ai-pg] / full-docs / man1 / initdb.1
1 '\" t
2 .\"     Title: initdb
3 .\"    Author: The PostgreSQL Global Development Group
4 .\" Generator: DocBook XSL Stylesheets vsnapshot <http://docbook.sf.net/>
5 .\"      Date: 2025
6 .\"    Manual: PostgreSQL 18.0 Documentation
7 .\"    Source: PostgreSQL 18.0
8 .\"  Language: English
9 .\"
10 .TH "INITDB" "1" "2025" "PostgreSQL 18.0" "PostgreSQL 18.0 Documentation"
11 .\" -----------------------------------------------------------------
12 .\" * Define some portability stuff
13 .\" -----------------------------------------------------------------
14 .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
15 .\" http://bugs.debian.org/507673
16 .\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html
17 .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
18 .ie \n(.g .ds Aq \(aq
19 .el       .ds Aq '
20 .\" -----------------------------------------------------------------
21 .\" * set default formatting
22 .\" -----------------------------------------------------------------
23 .\" disable hyphenation
24 .nh
25 .\" disable justification (adjust text to left margin only)
26 .ad l
27 .\" -----------------------------------------------------------------
28 .\" * MAIN CONTENT STARTS HERE *
29 .\" -----------------------------------------------------------------
30 .SH "NAME"
31 initdb \- create a new PostgreSQL database cluster
32 .SH "SYNOPSIS"
33 .HP \w'\fBinitdb\fR\ 'u
34 \fBinitdb\fR [\fIoption\fR...] [\fB\-\-pgdata\fR | \fB\-D\fR]\fI directory\fR
35 .SH "DESCRIPTION"
36 .PP
37 \fBinitdb\fR
38 creates a new
39 PostgreSQL
40 database cluster\&.
41 .PP
42 Creating a database cluster consists of creating the
43 directories
44 in which the cluster data will live, generating the shared catalog tables (tables that belong to the whole cluster rather than to any particular database), and creating the
45 postgres,
46 template1, and
47 template0
48 databases\&. The
49 postgres
50 database is a default database meant for use by users, utilities and third party applications\&.
51 template1
52 and
53 template0
54 are meant as source databases to be copied by later
55 \fBCREATE DATABASE\fR
56 commands\&.
57 template0
58 should never be modified, but you can add objects to
59 template1, which by default will be copied into databases created later\&. See
60 Section\ \&22.3
61 for more details\&.
62 .PP
63 Although
64 \fBinitdb\fR
65 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
66 \fBchown\fR
67 to assign ownership of that directory to the database user account, then
68 \fBsu\fR
69 to become the database user to run
70 \fBinitdb\fR\&.
71 .PP
72 \fBinitdb\fR
73 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
74 \fBinitdb\fR
75 creates\&. Since the server cannot be run as root, you must not run
76 \fBinitdb\fR
77 as root either\&. (It will in fact refuse to do so\&.)
78 .PP
79 For security reasons the new cluster created by
80 \fBinitdb\fR
81 will only be accessible by the cluster owner by default\&. The
82 \fB\-\-allow\-group\-access\fR
83 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\&.
84 .PP
85 \fBinitdb\fR
86 initializes the database cluster\*(Aqs default locale and character set encoding\&. These can also be set separately for each database when it is created\&.
87 \fBinitdb\fR
88 determines those settings for the template databases, which will serve as the default for all other databases\&.
89 .PP
90 By default,
91 \fBinitdb\fR
92 uses the locale provider
93 libc
94 (see
95 Section\ \&23.1.4)\&. The
96 libc
97 locale provider takes the locale settings from the environment, and determines the encoding from the locale settings\&.
98 .PP
99 To choose a different locale for the cluster, use the option
100 \fB\-\-locale\fR\&. There are also individual options
101 \fB\-\-lc\-*\fR
102 and
103 \fB\-\-icu\-locale\fR
104 (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\&.
105 .PP
106 Alternatively,
107 \fBinitdb\fR
108 can use the ICU library to provide locale services by specifying
109 \-\-locale\-provider=icu\&. The server must be built with ICU support\&. To choose the specific ICU locale ID to apply, use the option
110 \fB\-\-icu\-locale\fR\&. Note that for implementation reasons and to support legacy code,
111 \fBinitdb\fR
112 will still select and initialize libc locale settings when the ICU locale provider is used\&.
113 .PP
114 When
115 \fBinitdb\fR
116 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\&.
117 .PP
118 More details about locale settings can be found in
119 Section\ \&23.1\&.
120 .PP
121 To alter the default encoding, use the
122 \fB\-\-encoding\fR\&. More details can be found in
123 Section\ \&23.3\&.
124 .SH "OPTIONS"
125 .PP
126 .PP
127 \fB\-A \fR\fB\fIauthmethod\fR\fR
128 .br
129 \fB\-\-auth=\fR\fB\fIauthmethod\fR\fR
130 .RS 4
131 This option specifies the default authentication method for local users used in
132 pg_hba\&.conf
133 (host
134 and
135 local
136 lines)\&. See
137 Section\ \&20.1
138 for an overview of valid values\&.
139 .sp
140 \fBinitdb\fR
141 will prepopulate
142 pg_hba\&.conf
143 entries using the specified authentication method for non\-replication as well as replication connections\&.
144 .sp
145 Do not use
146 trust
147 unless you trust all local users on your system\&.
148 trust
149 is the default for ease of installation\&.
150 .RE
151 .PP
152 \fB\-\-auth\-host=\fR\fB\fIauthmethod\fR\fR
153 .RS 4
154 This option specifies the authentication method for local users via TCP/IP connections used in
155 pg_hba\&.conf
156 (host
157 lines)\&.
158 .RE
159 .PP
160 \fB\-\-auth\-local=\fR\fB\fIauthmethod\fR\fR
161 .RS 4
162 This option specifies the authentication method for local users via Unix\-domain socket connections used in
163 pg_hba\&.conf
164 (local
165 lines)\&.
166 .RE
167 .PP
168 \fB\-D \fR\fB\fIdirectory\fR\fR
169 .br
170 \fB\-\-pgdata=\fR\fB\fIdirectory\fR\fR
171 .RS 4
172 This option specifies the directory where the database cluster should be stored\&. This is the only information required by
173 \fBinitdb\fR, but you can avoid writing it by setting the
174 \fBPGDATA\fR
175 environment variable, which can be convenient since the database server (\fBpostgres\fR) can find the data directory later by the same variable\&.
176 .RE
177 .PP
178 \fB\-E \fR\fB\fIencoding\fR\fR
179 .br
180 \fB\-\-encoding=\fR\fB\fIencoding\fR\fR
181 .RS 4
182 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 character sets supported by the
183 PostgreSQL
184 server are described in
185 Section\ \&23.3.1\&.
186 .sp
187 By default, the template database encoding is derived from the locale\&. If
188 \fB\-\-no\-locale\fR
189 is specified (or equivalently, if the locale is
190 C
191 or
192 POSIX), then the default is
193 UTF8
194 for the ICU provider and
195 SQL_ASCII
196 for the
197 libc
198 provider\&.
199 .RE
200 .PP
201 \fB\-g\fR
202 .br
203 \fB\-\-allow\-group\-access\fR
204 .RS 4
205 Allows users in the same group as the cluster owner to read all cluster files created by
206 \fBinitdb\fR\&. This option is ignored on
207 Windows
208 as it does not support
209 POSIX\-style group permissions\&.
210 .RE
211 .PP
212 \fB\-\-icu\-locale=\fR\fB\fIlocale\fR\fR
213 .RS 4
214 Specifies the ICU locale when the ICU provider is used\&. Locale support is described in
215 Section\ \&23.1\&.
216 .RE
217 .PP
218 \fB\-\-icu\-rules=\fR\fB\fIrules\fR\fR
219 .RS 4
220 Specifies additional collation rules to customize the behavior of the default collation\&. This is supported for ICU only\&.
221 .RE
222 .PP
223 \fB\-k\fR
224 .br
225 \fB\-\-data\-checksums\fR
226 .RS 4
227 Use checksums on data pages to help detect corruption by the I/O system that would otherwise be silent\&. This is enabled by default; use
228 \fB\-\-no\-data\-checksums\fR
229 to disable checksums\&.
230 .sp
231 Enabling checksums might incur a small performance penalty\&. If set, checksums are calculated for all objects, in all databases\&. All checksum failures will be reported in the
232 pg_stat_database
233 view\&. See
234 Section\ \&28.2
235 for details\&.
236 .RE
237 .PP
238 \fB\-\-locale=\fR\fB\fIlocale\fR\fR
239 .RS 4
240 Sets the default locale for the database cluster\&. If this option is not specified, the locale is inherited from the environment that
241 \fBinitdb\fR
242 runs in\&. Locale support is described in
243 Section\ \&23.1\&.
244 .sp
245 If
246 \fB\-\-locale\-provider\fR
247 is
248 builtin,
249 \fB\-\-locale\fR
250 or
251 \fB\-\-builtin\-locale\fR
252 must be specified and set to
253 C,
254 C\&.UTF\-8
255 or
256 PG_UNICODE_FAST\&.
257 .RE
258 .PP
259 \fB\-\-lc\-collate=\fR\fB\fIlocale\fR\fR
260 .br
261 \fB\-\-lc\-ctype=\fR\fB\fIlocale\fR\fR
262 .br
263 \fB\-\-lc\-messages=\fR\fB\fIlocale\fR\fR
264 .br
265 \fB\-\-lc\-monetary=\fR\fB\fIlocale\fR\fR
266 .br
267 \fB\-\-lc\-numeric=\fR\fB\fIlocale\fR\fR
268 .br
269 \fB\-\-lc\-time=\fR\fB\fIlocale\fR\fR
270 .RS 4
271 Like
272 \fB\-\-locale\fR, but only sets the locale in the specified category\&.
273 .RE
274 .PP
275 \fB\-\-no\-locale\fR
276 .RS 4
277 Equivalent to
278 \fB\-\-locale=C\fR\&.
279 .RE
280 .PP
281 \fB\-\-builtin\-locale=\fR\fB\fIlocale\fR\fR
282 .RS 4
283 Specifies the locale name when the builtin provider is used\&. Locale support is described in
284 Section\ \&23.1\&.
285 .RE
286 .PP
287 \fB\-\-locale\-provider={\fR\fBbuiltin\fR\fB|\fR\fBlibc\fR\fB|\fR\fBicu\fR\fB}\fR
288 .RS 4
289 This option sets the locale provider for databases created in the new cluster\&. It can be overridden in the
290 \fBCREATE DATABASE\fR
291 command when new databases are subsequently created\&. The default is
292 libc
293 (see
294 Section\ \&23.1.4)\&.
295 .RE
296 .PP
297 \fB\-\-no\-data\-checksums\fR
298 .RS 4
299 Do not enable data checksums\&.
300 .RE
301 .PP
302 \fB\-\-pwfile=\fR\fB\fIfilename\fR\fR
303 .RS 4
304 Makes
305 \fBinitdb\fR
306 read the bootstrap superuser\*(Aqs password from a file\&. The first line of the file is taken as the password\&.
307 .RE
308 .PP
309 \fB\-T \fR\fB\fIconfig\fR\fR
310 .br
311 \fB\-\-text\-search\-config=\fR\fB\fIconfig\fR\fR
312 .RS 4
313 Sets the default text search configuration\&. See
314 default_text_search_config
315 for further information\&.
316 .RE
317 .PP
318 \fB\-U \fR\fB\fIusername\fR\fR
319 .br
320 \fB\-\-username=\fR\fB\fIusername\fR\fR
321 .RS 4
322 Sets the user name of the
323 bootstrap superuser\&. This defaults to the name of the operating\-system user running
324 \fBinitdb\fR\&.
325 .RE
326 .PP
327 \fB\-W\fR
328 .br
329 \fB\-\-pwprompt\fR
330 .RS 4
331 Makes
332 \fBinitdb\fR
333 prompt for a password to give the bootstrap superuser\&. If you don\*(Aqt plan on using password authentication, this is not important\&. Otherwise you won\*(Aqt be able to use password authentication until you have a password set up\&.
334 .RE
335 .PP
336 \fB\-X \fR\fB\fIdirectory\fR\fR
337 .br
338 \fB\-\-waldir=\fR\fB\fIdirectory\fR\fR
339 .RS 4
340 This option specifies the directory where the write\-ahead log should be stored\&.
341 .RE
342 .PP
343 \fB\-\-wal\-segsize=\fR\fB\fIsize\fR\fR
344 .RS 4
345 Set the
346 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\&.
347 .sp
348 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\&.
349 .RE
350 .PP
351 Other, less commonly used, options are also available:
352 .PP
353 \fB\-c \fR\fB\fIname\fR\fR\fB=\fR\fB\fIvalue\fR\fR
354 .br
355 \fB\-\-set \fR\fB\fIname\fR\fR\fB=\fR\fB\fIvalue\fR\fR
356 .RS 4
357 Forcibly set the server parameter
358 \fIname\fR
359 to
360 \fIvalue\fR
361 during
362 \fBinitdb\fR, and also install that setting in the generated
363 postgresql\&.conf
364 file, so that it will apply during future server runs\&. This option can be given more than once to set several parameters\&. It is primarily useful when the environment is such that the server will not start at all using the default parameters\&.
365 .RE
366 .PP
367 \fB\-d\fR
368 .br
369 \fB\-\-debug\fR
370 .RS 4
371 Print debugging output from the bootstrap backend and a few other messages of lesser interest for the general public\&. The bootstrap backend is the program
372 \fBinitdb\fR
373 uses to create the catalog tables\&. This option generates a tremendous amount of extremely boring output\&.
374 .RE
375 .PP
376 \fB\-\-discard\-caches\fR
377 .RS 4
378 Run the bootstrap backend with the
379 debug_discard_caches=1
380 option\&. This takes a very long time and is only of use for deep debugging\&.
381 .RE
382 .PP
383 \fB\-L \fR\fB\fIdirectory\fR\fR
384 .RS 4
385 Specifies where
386 \fBinitdb\fR
387 should 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\&.
388 .RE
389 .PP
390 \fB\-n\fR
391 .br
392 \fB\-\-no\-clean\fR
393 .RS 4
394 By default, when
395 \fBinitdb\fR
396 determines 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\&.
397 .RE
398 .PP
399 \fB\-N\fR
400 .br
401 \fB\-\-no\-sync\fR
402 .RS 4
403 By default,
404 \fBinitdb\fR
405 will wait for all files to be written safely to disk\&. This option causes
406 \fBinitdb\fR
407 to 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\&.
408 .RE
409 .PP
410 \fB\-\-no\-sync\-data\-files\fR
411 .RS 4
412 By default,
413 \fBinitdb\fR
414 safely writes all database files to disk\&. This option instructs
415 \fBinitdb\fR
416 to skip synchronizing all files in the individual database directories, the database directories themselves, and the tablespace directories, i\&.e\&., everything in the
417 base
418 subdirectory and any other tablespace directories\&. Other files, such as those in
419 pg_wal
420 and
421 pg_xact, will still be synchronized unless the
422 \fB\-\-no\-sync\fR
423 option is also specified\&.
424 .sp
425 Note that if
426 \fB\-\-no\-sync\-data\-files\fR
427 is used in conjunction with
428 \fB\-\-sync\-method=syncfs\fR, some or all of the aforementioned files and directories will be synchronized because
429 syncfs
430 processes entire file systems\&.
431 .sp
432 This option is primarily intended for internal use by tools that separately ensure the skipped files are synchronized to disk\&.
433 .RE
434 .PP
435 \fB\-\-no\-instructions\fR
436 .RS 4
437 By default,
438 \fBinitdb\fR
439 will 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 wrap
440 \fBinitdb\fR
441 in platform\-specific behavior, where those instructions are likely to be incorrect\&.
442 .RE
443 .PP
444 \fB\-s\fR
445 .br
446 \fB\-\-show\fR
447 .RS 4
448 Show internal settings and exit, without doing anything else\&. This can be used to debug the
449 initdb
450 installation\&.
451 .RE
452 .PP
453 \fB\-\-sync\-method=\fR\fB\fImethod\fR\fR
454 .RS 4
455 When set to
456 fsync, which is the default,
457 \fBinitdb\fR
458 will recursively open and synchronize all files in the data directory\&. The search for files will follow symbolic links for the WAL directory and each configured tablespace\&.
459 .sp
460 On Linux,
461 syncfs
462 may be used instead to ask the operating system to synchronize the whole file systems that contain the data directory, the WAL files, and each tablespace\&. See
463 recovery_init_sync_method
464 for information about the caveats to be aware of when using
465 syncfs\&.
466 .sp
467 This option has no effect when
468 \fB\-\-no\-sync\fR
469 is used\&.
470 .RE
471 .PP
472 \fB\-S\fR
473 .br
474 \fB\-\-sync\-only\fR
475 .RS 4
476 Safely write all database files to disk and exit\&. This does not perform any of the normal
477 initdb
478 operations\&. Generally, this option is useful for ensuring reliable recovery after changing
479 fsync
480 from
481 off
482 to
483 on\&.
484 .RE
485 .PP
486 Other options:
487 .PP
488 \fB\-V\fR
489 .br
490 \fB\-\-version\fR
491 .RS 4
492 Print the
493 initdb
494 version and exit\&.
495 .RE
496 .PP
497 \fB\-?\fR
498 .br
499 \fB\-\-help\fR
500 .RS 4
501 Show help about
502 initdb
503 command line arguments, and exit\&.
504 .RE
505 .SH "ENVIRONMENT"
506 .PP
507 \fBPGDATA\fR
508 .RS 4
509 Specifies the directory where the database cluster is to be stored; can be overridden using the
510 \fB\-D\fR
511 option\&.
512 .RE
513 .PP
514 \fBPG_COLOR\fR
515 .RS 4
516 Specifies whether to use color in diagnostic messages\&. Possible values are
517 always,
518 auto
519 and
520 never\&.
521 .RE
522 .PP
523 \fBTZ\fR
524 .RS 4
525 Specifies the default time zone of the created database cluster\&. The value should be a full time zone name (see
526 Section\ \&8.5.3)\&.
527 .RE
528 .SH "NOTES"
529 .PP
530 \fBinitdb\fR
531 can also be invoked via
532 \fBpg_ctl initdb\fR\&.
533 .SH "SEE ALSO"
534 \fBpg_ctl\fR(1), \fBpostgres\fR(1), Section\ \&20.1