1CREATEDB(1) PostgreSQL 14.3 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 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 -O owner
62 --owner=owner
63 Specifies the database user who will own the new database. (This
64 name is processed as a double-quoted identifier.)
65
66 -T template
67 --template=template
68 Specifies the template database from which to build this database.
69 (This name is processed as a double-quoted identifier.)
70
71 -V
72 --version
73 Print the createdb version and exit.
74
75 -?
76 --help
77 Show help about createdb command line arguments, and exit.
78
79 The options -D, -l, -E, -O, and -T correspond to options of the
80 underlying SQL command CREATE DATABASE; see there for more information
81 about them.
82
83 createdb also accepts the following command-line arguments for
84 connection parameters:
85
86 -h host
87 --host=host
88 Specifies the host name of the machine on which the server is
89 running. If the value begins with a slash, it is used as the
90 directory for the Unix domain socket.
91
92 -p port
93 --port=port
94 Specifies the TCP port or the local Unix domain socket file
95 extension on which the server is listening for connections.
96
97 -U username
98 --username=username
99 User name to connect as.
100
101 -w
102 --no-password
103 Never issue a password prompt. If the server requires password
104 authentication and a password is not available by other means such
105 as a .pgpass file, the connection attempt will fail. This option
106 can be useful in batch jobs and scripts where no user is present to
107 enter a password.
108
109 -W
110 --password
111 Force createdb to prompt for a password before connecting to a
112 database.
113
114 This option is never essential, since createdb will automatically
115 prompt for a password if the server demands password
116 authentication. However, createdb will waste a connection attempt
117 finding out that the server wants a password. In some cases it is
118 worth typing -W to avoid the extra connection attempt.
119
120 --maintenance-db=dbname
121 Specifies the name of the database to connect to when creating the
122 new database. If not specified, the postgres database will be used;
123 if that does not exist (or if it is the name of the new database
124 being created), template1 will be used. This can be a connection
125 string. If so, connection string parameters will override any
126 conflicting command line options.
127
129 PGDATABASE
130 If set, the name of the database to create, unless overridden on
131 the command line.
132
133 PGHOST
134 PGPORT
135 PGUSER
136 Default connection parameters. PGUSER also determines the name of
137 the database to create, if it is not specified on the command line
138 or by PGDATABASE.
139
140 PG_COLOR
141 Specifies whether to use color in diagnostic messages. Possible
142 values are always, auto and never.
143
144 This utility, like most other PostgreSQL utilities, also uses the
145 environment variables supported by libpq (see Section 34.15).
146
148 In case of difficulty, see CREATE DATABASE (CREATE_DATABASE(7)) and
149 psql(1) for discussions of potential problems and error messages. The
150 database server must be running at the targeted host. Also, any default
151 connection settings and environment variables used by the libpq
152 front-end library will apply.
153
155 To create the database demo using the default database server:
156
157 $ createdb demo
158
159 To create the database demo using the server on host eden, port 5000,
160 using the template0 template database, here is the command-line command
161 and the underlying SQL command:
162
163 $ createdb -p 5000 -h eden -T template0 -e demo
164 CREATE DATABASE demo TEMPLATE template0;
165
167 dropdb(1), CREATE DATABASE (CREATE_DATABASE(7))
168
169
170
171PostgreSQL 14.3 2022 CREATEDB(1)