1INITDB(1) PostgreSQL 9.2.24 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 22.1, “Locale Support”, in the documentation.
54
55 To alter the default encoding, use the --encoding. More details can be
56 found in Section 22.3, “Character Set Support”, in the documentation.
57
59 -A authmethod, --auth=authmethod
60 This option specifies the authentication method for local users
61 used in pg_hba.conf (host and local lines). Do not use trust unless
62 you trust all local users on your system. trust is the default for
63 ease of installation.
64
65 --auth-host=authmethod
66 This option specifies the authentication method for local users via
67 TCP/IP connections used in pg_hba.conf (host lines).
68
69 --auth-local=authmethod
70 This option specifies the authentication method for local users via
71 Unix-domain socket connections used in pg_hba.conf (local lines).
72
73 -D directory, --pgdata=directory
74 This option specifies the directory where the database cluster
75 should be stored. This is the only information required by initdb,
76 but you can avoid writing it by setting the PGDATA environment
77 variable, which can be convenient since the database server
78 (postgres) can find the database directory later by the same
79 variable.
80
81 -E encoding, --encoding=encoding
82 Selects the encoding of the template database. This will also be
83 the default encoding of any database you create later, unless you
84 override it there. The default is derived from the locale, or
85 SQL_ASCII if that does not work. The character sets supported by
86 the PostgreSQL server are described in Section 22.3.1, “Supported
87 Character Sets”, in the documentation.
88
89 --locale=locale
90 Sets the default locale for the database cluster. If this option is
91 not specified, the locale is inherited from the environment that
92 initdb runs in. Locale support is described in Section 22.1,
93 “Locale Support”, in the documentation.
94
95 --lc-collate=locale, --lc-ctype=locale, --lc-messages=locale,
96 --lc-monetary=locale, --lc-numeric=locale, --lc-time=locale
97 Like --locale, but only sets the locale in the specified category.
98
99 --no-locale
100 Equivalent to --locale=C.
101
102 --pwfile=filename
103 Makes initdb read the database superuser's password from a file.
104 The first line of the file is taken as the password.
105
106 -T CFG, --text-search-config=CFG
107 Sets the default text search configuration. See
108 default_text_search_config for further information.
109
110 -U username, --username=username
111 Selects the user name of the database superuser. This defaults to
112 the name of the effective user running initdb. It is really not
113 important what the superuser's name is, but one might choose to
114 keep the customary name postgres, even if the operating system
115 user's name is different.
116
117 -W, --pwprompt
118 Makes initdb prompt for a password to give the database superuser.
119 If you don't plan on using password authentication, this is not
120 important. Otherwise you won't be able to use password
121 authentication until you have a password set up.
122
123 -X directory, --xlogdir=directory
124 This option specifies the directory where the transaction log
125 should be stored.
126
127 Other, less commonly used, options are also available:
128
129 -d, --debug
130 Print debugging output from the bootstrap backend and a few other
131 messages of lesser interest for the general public. The bootstrap
132 backend is the program initdb uses to create the catalog tables.
133 This option generates a tremendous amount of extremely boring
134 output.
135
136 -L directory
137 Specifies where initdb should find its input files to initialize
138 the database cluster. This is normally not necessary. You will be
139 told if you need to specify their location explicitly.
140
141 -n, --noclean
142 By default, when initdb determines that an error prevented it from
143 completely creating the database cluster, it removes any files it
144 might have created before discovering that it cannot finish the
145 job. This option inhibits tidying-up and is thus useful for
146 debugging.
147
148 Other options:
149
150 -s, --show
151 Print the internal settings, then exit.
152
153 -V, --version
154 Print the initdb version and exit.
155
156 -?, --help
157 Show help about initdb command line arguments, and exit.
158
160 PGDATA
161 Specifies the directory where the database cluster is to be stored;
162 can be overridden using the -D option.
163
164 TZ
165 Specifies the time zone, using full time zone names, which the
166 created database cluster should use.
167
168 This utility, like most other PostgreSQL utilities, also uses the
169 environment variables supported by libpq (see Section 31.14,
170 “Environment Variables”, in the documentation).
171
173 initdb can also be invoked via pg_ctl initdb.
174
176 pg_ctl(1), postgres(1)
177
178
179
180PostgreSQL 9.2.24 2017-11-06 INITDB(1)