1CREATEDB(1)              PostgreSQL 15.4 Documentation             CREATEDB(1)
2
3
4

NAME

6       createdb - create a new PostgreSQL database
7

SYNOPSIS

9       createdb [connection-option...] [option...] [dbname [description]]
10

DESCRIPTION

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

OPTIONS

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 both --lc-collate and --lc-ctype.
54
55       --lc-collate=locale
56           Specifies the LC_COLLATE setting to be used in this database.
57
58       --lc-ctype=locale
59           Specifies the LC_CTYPE setting to be used in this database.
60
61       --icu-locale=locale
62           Specifies the ICU locale ID to be used in this database, if the ICU
63           locale provider is selected.
64
65       --locale-provider={libc|icu}
66           Specifies the locale provider for the database's default collation.
67
68       -O owner
69       --owner=owner
70           Specifies the database user who will own the new database. (This
71           name is processed as a double-quoted identifier.)
72
73       -S template
74       --strategy=strategy
75           Specifies the database creation strategy. See CREATE DATABASE
76           STRATEGY for more details.
77
78       -T template
79       --template=template
80           Specifies the template database from which to build this database.
81           (This name is processed as a double-quoted identifier.)
82
83       -V
84       --version
85           Print the createdb version and exit.
86
87       -?
88       --help
89           Show help about createdb command line arguments, and exit.
90
91       The options -D, -l, -E, -O, and -T correspond to options of the
92       underlying SQL command CREATE DATABASE; see there for more information
93       about them.
94
95       createdb also accepts the following command-line arguments for
96       connection parameters:
97
98       -h host
99       --host=host
100           Specifies the host name of the machine on which the server is
101           running. If the value begins with a slash, it is used as the
102           directory for the Unix domain socket.
103
104       -p port
105       --port=port
106           Specifies the TCP port or the local Unix domain socket file
107           extension on which the server is listening for connections.
108
109       -U username
110       --username=username
111           User name to connect as.
112
113       -w
114       --no-password
115           Never issue a password prompt. If the server requires password
116           authentication and a password is not available by other means such
117           as a .pgpass file, the connection attempt will fail. This option
118           can be useful in batch jobs and scripts where no user is present to
119           enter a password.
120
121       -W
122       --password
123           Force createdb to prompt for a password before connecting to a
124           database.
125
126           This option is never essential, since createdb will automatically
127           prompt for a password if the server demands password
128           authentication. However, createdb will waste a connection attempt
129           finding out that the server wants a password. In some cases it is
130           worth typing -W to avoid the extra connection attempt.
131
132       --maintenance-db=dbname
133           Specifies the name of the database to connect to when creating the
134           new database. If not specified, the postgres database will be used;
135           if that does not exist (or if it is the name of the new database
136           being created), template1 will be used. This can be a connection
137           string. If so, connection string parameters will override any
138           conflicting command line options.
139

ENVIRONMENT

141       PGDATABASE
142           If set, the name of the database to create, unless overridden on
143           the command line.
144
145       PGHOST
146       PGPORT
147       PGUSER
148           Default connection parameters.  PGUSER also determines the name of
149           the database to create, if it is not specified on the command line
150           or by PGDATABASE.
151
152       PG_COLOR
153           Specifies whether to use color in diagnostic messages. Possible
154           values are always, auto and never.
155
156       This utility, like most other PostgreSQL utilities, also uses the
157       environment variables supported by libpq (see Section 34.15).
158

DIAGNOSTICS

160       In case of difficulty, see CREATE DATABASE (CREATE_DATABASE(7)) and
161       psql(1) for discussions of potential problems and error messages. The
162       database server must be running at the targeted host. Also, any default
163       connection settings and environment variables used by the libpq
164       front-end library will apply.
165

EXAMPLES

167       To create the database demo using the default database server:
168
169           $ createdb demo
170
171       To create the database demo using the server on host eden, port 5000,
172       using the template0 template database, here is the command-line command
173       and the underlying SQL command:
174
175           $ createdb -p 5000 -h eden -T template0 -e demo
176           CREATE DATABASE demo TEMPLATE template0;
177

SEE ALSO

179       dropdb(1), CREATE DATABASE (CREATE_DATABASE(7))
180
181
182
183PostgreSQL 15.4                      2023                          CREATEDB(1)
Impressum