1INITDB(1) PostgreSQL 10.7 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 initdb initializes the database cluster's default locale and character
38 set encoding. The character set encoding, collation order (LC_COLLATE)
39 and character set classes (LC_CTYPE, e.g. upper, lower, digit) can be
40 set separately for a database when it is created. initdb determines
41 those settings for the template1 database, which will serve as the
42 default for all other databases.
43
44 To alter the default collation order or character set classes, use the
45 --lc-collate and --lc-ctype options. Collation orders other than C or
46 POSIX also have a performance penalty. For these reasons it is
47 important to choose the right locale when running initdb.
48
49 The remaining locale categories can be changed later when the server is
50 started. You can also use --locale to set the default for all locale
51 categories, including collation order and character set classes. All
52 server locale values (lc_*) can be displayed via SHOW ALL. More details
53 can be found in Section 23.1.
54
55 To alter the default encoding, use the --encoding. More details can be
56 found in Section 23.3.
57
59 -A authmethod
60 --auth=authmethod
61 This option specifies the default authentication method for local
62 users used in pg_hba.conf (host and local lines). initdb will
63 prepopulate pg_hba.conf entries using the specified authentication
64 method for non-replication as well as replication connections.
65
66 Do not use trust unless you trust all local users on your system.
67 trust is the default for ease of installation.
68
69 --auth-host=authmethod
70 This option specifies the authentication method for local users via
71 TCP/IP connections used in pg_hba.conf (host lines).
72
73 --auth-local=authmethod
74 This option specifies the authentication method for local users via
75 Unix-domain socket connections used in pg_hba.conf (local lines).
76
77 -D directory
78 --pgdata=directory
79 This option specifies the directory where the database cluster
80 should be stored. This is the only information required by initdb,
81 but you can avoid writing it by setting the PGDATA environment
82 variable, which can be convenient since the database server
83 (postgres) can find the database directory later by the same
84 variable.
85
86 -E encoding
87 --encoding=encoding
88 Selects the encoding of the template database. This will also be
89 the default encoding of any database you create later, unless you
90 override it there. The default is derived from the locale, or
91 SQL_ASCII if that does not work. The character sets supported by
92 the PostgreSQL server are described in Section 23.3.1.
93
94 -k
95 --data-checksums
96 Use checksums on data pages to help detect corruption by the I/O
97 system that would otherwise be silent. Enabling checksums may incur
98 a noticeable performance penalty. This option can only be set
99 during initialization, and cannot be changed later. If set,
100 checksums are calculated for all objects, in all databases.
101
102 --locale=locale
103 Sets the default locale for the database cluster. If this option is
104 not specified, the locale is inherited from the environment that
105 initdb runs in. Locale support is described in Section 23.1.
106
107 --lc-collate=locale
108 --lc-ctype=locale
109 --lc-messages=locale
110 --lc-monetary=locale
111 --lc-numeric=locale
112 --lc-time=locale
113 Like --locale, but only sets the locale in the specified category.
114
115 --no-locale
116 Equivalent to --locale=C.
117
118 -N
119 --no-sync
120 By default, initdb will wait for all files to be written safely to
121 disk. This option causes initdb to return without waiting, which is
122 faster, but means that a subsequent operating system crash can
123 leave the data directory corrupt. Generally, this option is useful
124 for testing, but should not be used when creating a production
125 installation.
126
127 --pwfile=filename
128 Makes initdb read the database superuser's password from a file.
129 The first line of the file is taken as the password.
130
131 -S
132 --sync-only
133 Safely write all database files to disk and exit. This does not
134 perform any of the normal initdb operations.
135
136 -T config
137 --text-search-config=config
138 Sets the default text search configuration. See
139 default_text_search_config for further information.
140
141 -U username
142 --username=username
143 Selects the user name of the database superuser. This defaults to
144 the name of the effective user running initdb. It is really not
145 important what the superuser's name is, but one might choose to
146 keep the customary name postgres, even if the operating system
147 user's name is different.
148
149 -W
150 --pwprompt
151 Makes initdb prompt for a password to give the database superuser.
152 If you don't plan on using password authentication, this is not
153 important. Otherwise you won't be able to use password
154 authentication until you have a password set up.
155
156 -X directory
157 --waldir=directory
158 This option specifies the directory where the write-ahead log
159 should be stored.
160
161 Other, less commonly used, options are also available:
162
163 -d
164 --debug
165 Print debugging output from the bootstrap backend and a few other
166 messages of lesser interest for the general public. The bootstrap
167 backend is the program initdb uses to create the catalog tables.
168 This option generates a tremendous amount of extremely boring
169 output.
170
171 -L directory
172 Specifies where initdb should find its input files to initialize
173 the database cluster. This is normally not necessary. You will be
174 told if you need to specify their location explicitly.
175
176 -n
177 --no-clean
178 By default, when initdb determines that an error prevented it from
179 completely creating the database cluster, it removes any files it
180 might have created before discovering that it cannot finish the
181 job. This option inhibits tidying-up and is thus useful for
182 debugging.
183
184 Other options:
185
186 -s
187 --show
188 Print the internal settings, then exit.
189
190 -V
191 --version
192 Print the initdb version and exit.
193
194 -?
195 --help
196 Show help about initdb command line arguments, and exit.
197
199 PGDATA
200 Specifies the directory where the database cluster is to be stored;
201 can be overridden using the -D option.
202
203 TZ
204 Specifies the default time zone of the created database cluster.
205 The value should be a full time zone name (see Section 8.5.3).
206
207 This utility, like most other PostgreSQL utilities, also uses the
208 environment variables supported by libpq (see Section 33.14).
209
211 initdb can also be invoked via pg_ctl initdb.
212
214 pg_ctl(1), postgres(1)
215
216
217
218PostgreSQL 10.7 2019 INITDB(1)