1CREATEDB(1)              PostgreSQL 10.7 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
19       (CREATE_DATABASE(7)). There is no effective difference between creating
20       databases via this utility and via other methods for accessing the
21       server.
22

OPTIONS

24       createdb accepts the following command-line arguments:
25
26       dbname
27           Specifies the name of the database to be created. The name must be
28           unique among all PostgreSQL databases in this cluster. The default
29           is to create a database with the same name as the current system
30           user.
31
32       description
33           Specifies a comment to be associated with the newly created
34           database.
35
36       -D tablespace
37       --tablespace=tablespace
38           Specifies the default tablespace for the database. (This name is
39           processed as a double-quoted identifier.)
40
41       -e
42       --echo
43           Echo the commands that createdb generates and sends to the server.
44
45       -E encoding
46       --encoding=encoding
47           Specifies the character encoding scheme to be used in this
48           database. The character sets supported by the PostgreSQL server are
49           described in Section 23.3.1.
50
51       -l locale
52       --locale=locale
53           Specifies the locale to be used in this database. This is
54           equivalent to specifying both --lc-collate and --lc-ctype.
55
56       --lc-collate=locale
57           Specifies the LC_COLLATE setting to be used in this database.
58
59       --lc-ctype=locale
60           Specifies the LC_CTYPE setting to be used in this database.
61
62       -O owner
63       --owner=owner
64           Specifies the database user who will own the new database. (This
65           name is processed as a double-quoted identifier.)
66
67       -T template
68       --template=template
69           Specifies the template database from which to build this database.
70           (This name is processed as a double-quoted identifier.)
71
72       -V
73       --version
74           Print the createdb version and exit.
75
76       -?
77       --help
78           Show help about createdb command line arguments, and exit.
79
80       The options -D, -l, -E, -O, and -T correspond to options of the
81       underlying SQL command CREATE DATABASE (CREATE_DATABASE(7)); see there
82       for more information about them.
83
84       createdb also accepts the following command-line arguments for
85       connection parameters:
86
87       -h host
88       --host=host
89           Specifies the host name of the machine on which the server is
90           running. If the value begins with a slash, it is used as the
91           directory for the Unix domain socket.
92
93       -p port
94       --port=port
95           Specifies the TCP port or the local Unix domain socket file
96           extension on which the server is listening for connections.
97
98       -U username
99       --username=username
100           User name to connect as.
101
102       -w
103       --no-password
104           Never issue a password prompt. If the server requires password
105           authentication and a password is not available by other means such
106           as a .pgpass file, the connection attempt will fail. This option
107           can be useful in batch jobs and scripts where no user is present to
108           enter a password.
109
110       -W
111       --password
112           Force createdb to prompt for a password before connecting to a
113           database.
114
115           This option is never essential, since createdb will automatically
116           prompt for a password if the server demands password
117           authentication. However, createdb will waste a connection attempt
118           finding out that the server wants a password. In some cases it is
119           worth typing -W to avoid the extra connection attempt.
120
121       --maintenance-db=dbname
122           Specifies the name of the database to connect to when creating the
123           new database. If not specified, the postgres database will be used;
124           if that does not exist (or if it is the name of the new database
125           being created), template1 will be used.
126

ENVIRONMENT

128       PGDATABASE
129           If set, the name of the database to create, unless overridden on
130           the command line.
131
132       PGHOST
133       PGPORT
134       PGUSER
135           Default connection parameters.  PGUSER also determines the name of
136           the database to create, if it is not specified on the command line
137           or by PGDATABASE.
138
139       This utility, like most other PostgreSQL utilities, also uses the
140       environment variables supported by libpq (see Section 33.14).
141

DIAGNOSTICS

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

EXAMPLES

150       To create the database demo using the default database server:
151
152           $ createdb demo
153
154       To create the database demo using the server on host eden, port 5000,
155       using the template0 template database, here is the command-line command
156       and the underlying SQL command:
157
158           $ createdb -p 5000 -h eden -T template0 -e demo
159           CREATE DATABASE demo TEMPLATE template0;
160

SEE ALSO

162       dropdb(1), CREATE DATABASE (CREATE_DATABASE(7))
163
164
165
166PostgreSQL 10.7                      2019                          CREATEDB(1)
Impressum