1CREATEDB(1) PostgreSQL 16.1 Documentation CREATEDB(1)
2
3
4
6 createdb - create a new PostgreSQL database
7
9 createdb [connection-option...] [option...] [dbname [description]]
10
12 createdb creates a new PostgreSQL database.
13
14 Normally, the database user who executes this command becomes the owner
15 of the new database. However, a different owner can be specified via
16 the -O option, if the executing user has appropriate privileges.
17
18 createdb is a wrapper around the SQL command CREATE DATABASE. There is
19 no effective difference between creating databases via this utility and
20 via other methods for accessing the server.
21
23 createdb accepts the following command-line arguments:
24
25 dbname
26 Specifies the name of the database to be created. The name must be
27 unique among all PostgreSQL databases in this cluster. The default
28 is to create a database with the same name as the current system
29 user.
30
31 description
32 Specifies a comment to be associated with the newly created
33 database.
34
35 -D tablespace
36 --tablespace=tablespace
37 Specifies the default tablespace for the database. (This name is
38 processed as a double-quoted identifier.)
39
40 -e
41 --echo
42 Echo the commands that createdb generates and sends to the server.
43
44 -E encoding
45 --encoding=encoding
46 Specifies the character encoding scheme to be used in this
47 database. The character sets supported by the PostgreSQL server are
48 described in Section 24.3.1.
49
50 -l locale
51 --locale=locale
52 Specifies the locale to be used in this database. This is
53 equivalent to specifying --lc-collate, --lc-ctype, and --icu-locale
54 to the same value. Some locales are only valid for ICU and must be
55 set with --icu-locale.
56
57 --lc-collate=locale
58 Specifies the LC_COLLATE setting to be used in this database.
59
60 --lc-ctype=locale
61 Specifies the LC_CTYPE setting to be used in this database.
62
63 --icu-locale=locale
64 Specifies the ICU locale ID to be used in this database, if the ICU
65 locale provider is selected.
66
67 --icu-rules=rules
68 Specifies additional collation rules to customize the behavior of
69 the default collation of this database. This is supported for ICU
70 only.
71
72 --locale-provider={libc|icu}
73 Specifies the locale provider for the database's default collation.
74
75 -O owner
76 --owner=owner
77 Specifies the database user who will own the new database. (This
78 name is processed as a double-quoted identifier.)
79
80 -S template
81 --strategy=strategy
82 Specifies the database creation strategy. See CREATE DATABASE
83 STRATEGY for more details.
84
85 -T template
86 --template=template
87 Specifies the template database from which to build this database.
88 (This name is processed as a double-quoted identifier.)
89
90 -V
91 --version
92 Print the createdb version and exit.
93
94 -?
95 --help
96 Show help about createdb command line arguments, and exit.
97
98 The options -D, -l, -E, -O, and -T correspond to options of the
99 underlying SQL command CREATE DATABASE; see there for more information
100 about them.
101
102 createdb also accepts the following command-line arguments for
103 connection parameters:
104
105 -h host
106 --host=host
107 Specifies the host name of the machine on which the server is
108 running. If the value begins with a slash, it is used as the
109 directory for the Unix domain socket.
110
111 -p port
112 --port=port
113 Specifies the TCP port or the local Unix domain socket file
114 extension on which the server is listening for connections.
115
116 -U username
117 --username=username
118 User name to connect as.
119
120 -w
121 --no-password
122 Never issue a password prompt. If the server requires password
123 authentication and a password is not available by other means such
124 as a .pgpass file, the connection attempt will fail. This option
125 can be useful in batch jobs and scripts where no user is present to
126 enter a password.
127
128 -W
129 --password
130 Force createdb to prompt for a password before connecting to a
131 database.
132
133 This option is never essential, since createdb will automatically
134 prompt for a password if the server demands password
135 authentication. However, createdb will waste a connection attempt
136 finding out that the server wants a password. In some cases it is
137 worth typing -W to avoid the extra connection attempt.
138
139 --maintenance-db=dbname
140 Specifies the name of the database to connect to when creating the
141 new database. If not specified, the postgres database will be used;
142 if that does not exist (or if it is the name of the new database
143 being created), template1 will be used. This can be a connection
144 string. If so, connection string parameters will override any
145 conflicting command line options.
146
148 PGDATABASE
149 If set, the name of the database to create, unless overridden on
150 the command line.
151
152 PGHOST
153 PGPORT
154 PGUSER
155 Default connection parameters. PGUSER also determines the name of
156 the database to create, if it is not specified on the command line
157 or by PGDATABASE.
158
159 PG_COLOR
160 Specifies whether to use color in diagnostic messages. Possible
161 values are always, auto and never.
162
163 This utility, like most other PostgreSQL utilities, also uses the
164 environment variables supported by libpq (see Section 34.15).
165
167 In case of difficulty, see CREATE DATABASE (CREATE_DATABASE(7)) and
168 psql(1) for discussions of potential problems and error messages. The
169 database server must be running at the targeted host. Also, any default
170 connection settings and environment variables used by the libpq
171 front-end library will apply.
172
174 To create the database demo using the default database server:
175
176 $ createdb demo
177
178 To create the database demo using the server on host eden, port 5000,
179 using the template0 template database, here is the command-line command
180 and the underlying SQL command:
181
182 $ createdb -p 5000 -h eden -T template0 -e demo
183 CREATE DATABASE demo TEMPLATE template0;
184
186 dropdb(1), CREATE DATABASE (CREATE_DATABASE(7))
187
188
189
190PostgreSQL 16.1 2023 CREATEDB(1)