4 createdb — create a new PostgreSQL database
8 createdb [connection-option...] [option...] [dbname [description]]
12 createdb creates a new PostgreSQL database.
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.
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.
24 createdb accepts the following command-line arguments:
27 Specifies the name of the database to be created. The name must
28 be unique among all PostgreSQL databases in this cluster. The
29 default is to create a database with the same name as the
33 Specifies a comment to be associated with the newly created
37 --tablespace=tablespace
38 Specifies the default tablespace for the database. (This name is
39 processed as a double-quoted identifier.)
43 Echo the commands that createdb generates and sends to the
48 Specifies the character encoding scheme to be used in this
49 database. The character sets supported by the PostgreSQL server
50 are described in Section 23.3.1.
54 Specifies the locale to be used in this database. This is
55 equivalent to specifying --lc-collate, --lc-ctype, and
56 --icu-locale to the same value. Some locales are only valid for
57 ICU and must be set with --icu-locale.
60 Specifies the LC_COLLATE setting to be used in this database.
63 Specifies the LC_CTYPE setting to be used in this database.
65 --builtin-locale=locale
66 Specifies the locale name when the builtin provider is used.
67 Locale support is described in Section 23.1.
70 Specifies the ICU locale ID to be used in this database, if the
71 ICU locale provider is selected.
74 Specifies additional collation rules to customize the behavior
75 of the default collation of this database. This is supported for
78 --locale-provider={builtin|libc|icu}
79 Specifies the locale provider for the database's default
84 Specifies the database user who will own the new database. (This
85 name is processed as a double-quoted identifier.)
89 Specifies the database creation strategy. See CREATE DATABASE
90 STRATEGY for more details.
94 Specifies the template database from which to build this
95 database. (This name is processed as a double-quoted
100 Print the createdb version and exit.
104 Show help about createdb command line arguments, and exit.
106 The options -D, -l, -E, -O, and -T correspond to options of the
107 underlying SQL command CREATE DATABASE; see there for more information
110 createdb also accepts the following command-line arguments for
111 connection parameters:
115 Specifies the host name of the machine on which the server is
116 running. If the value begins with a slash, it is used as the
117 directory for the Unix domain socket.
121 Specifies the TCP port or the local Unix domain socket file
122 extension on which the server is listening for connections.
126 User name to connect as.
130 Never issue a password prompt. If the server requires password
131 authentication and a password is not available by other means
132 such as a .pgpass file, the connection attempt will fail. This
133 option can be useful in batch jobs and scripts where no user is
134 present to enter a password.
138 Force createdb to prompt for a password before connecting to a
141 This option is never essential, since createdb will
142 automatically prompt for a password if the server demands
143 password authentication. However, createdb will waste a
144 connection attempt finding out that the server wants a password.
145 In some cases it is worth typing -W to avoid the extra
148 --maintenance-db=dbname
149 Specifies the name of the database to connect to when creating
150 the new database. If not specified, the postgres database will
151 be used; if that does not exist (or if it is the name of the new
152 database being created), template1 will be used. This can be a
153 connection string. If so, connection string parameters will
154 override any conflicting command line options.
159 If set, the name of the database to create, unless overridden on
165 Default connection parameters. PGUSER also determines the name
166 of the database to create, if it is not specified on the command
167 line or by PGDATABASE.
170 Specifies whether to use color in diagnostic messages. Possible
171 values are always, auto and never.
173 This utility, like most other PostgreSQL utilities, also uses the
174 environment variables supported by libpq (see Section 32.15).
178 In case of difficulty, see CREATE DATABASE and psql for discussions of
179 potential problems and error messages. The database server must be
180 running at the targeted host. Also, any default connection settings and
181 environment variables used by the libpq front-end library will apply.
185 To create the database demo using the default database server:
188 To create the database demo using the server on host eden, port 5000,
189 using the template0 template database, here is the command-line command
190 and the underlying SQL command:
191 $ createdb -p 5000 -h eden -T template0 -e demo
192 CREATE DATABASE demo TEMPLATE template0;
196 dropdb, CREATE DATABASE