1CREATEDB(1) PostgreSQL 9.2.24 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
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
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, --tablespace=tablespace
37 Specifies the default tablespace for the database. (This name is
38 processed as a double-quoted identifier.)
39
40 -e, --echo
41 Echo the commands that createdb generates and sends to the server.
42
43 -E encoding, --encoding=encoding
44 Specifies the character encoding scheme to be used in this
45 database. The character sets supported by the PostgreSQL server are
46 described in Section 22.3.1, “Supported Character Sets”, in the
47 documentation.
48
49 -l locale, --locale=locale
50 Specifies the locale to be used in this database. This is
51 equivalent to specifying both --lc-collate and --lc-ctype.
52
53 --lc-collate=locale
54 Specifies the LC_COLLATE setting to be used in this database.
55
56 --lc-ctype=locale
57 Specifies the LC_CTYPE setting to be used in this database.
58
59 -O owner, --owner=owner
60 Specifies the database user who will own the new database. (This
61 name is processed as a double-quoted identifier.)
62
63 -T template, --template=template
64 Specifies the template database from which to build this database.
65 (This name is processed as a double-quoted identifier.)
66
67 -V, --version
68 Print the createdb version and exit.
69
70 -?, --help
71 Show help about createdb command line arguments, and exit.
72
73 The options -D, -l, -E, -O, and -T correspond to options of the
74 underlying SQL command CREATE DATABASE (CREATE_DATABASE(7)); see there
75 for more information about them.
76
77 createdb also accepts the following command-line arguments for
78 connection parameters:
79
80 -h host, --host=host
81 Specifies the host name of the machine on which the server is
82 running. If the value begins with a slash, it is used as the
83 directory for the Unix domain socket.
84
85 -p port, --port=port
86 Specifies the TCP port or the local Unix domain socket file
87 extension on which the server is listening for connections.
88
89 -U username, --username=username
90 User name to connect as.
91
92 -w, --no-password
93 Never issue a password prompt. If the server requires password
94 authentication and a password is not available by other means such
95 as a .pgpass file, the connection attempt will fail. This option
96 can be useful in batch jobs and scripts where no user is present to
97 enter a password.
98
99 -W, --password
100 Force createdb to prompt for a password before connecting to a
101 database.
102
103 This option is never essential, since createdb will automatically
104 prompt for a password if the server demands password
105 authentication. However, createdb will waste a connection attempt
106 finding out that the server wants a password. In some cases it is
107 worth typing -W to avoid the extra connection attempt.
108
109 --maintenance-db=dbname
110 Specifies the name of the database to connect to when creating the
111 new database. If not specified, the postgres database will be used;
112 if that does not exist (or if it is the name of the new database
113 being created), template1 will be used.
114
116 PGDATABASE
117 If set, the name of the database to create, unless overridden on
118 the command line.
119
120 PGHOST, PGPORT, PGUSER
121 Default connection parameters. PGUSER also determines the name of
122 the database to create, if it is not specified on the command line
123 or by PGDATABASE.
124
125 This utility, like most other PostgreSQL utilities, also uses the
126 environment variables supported by libpq (see Section 31.14,
127 “Environment Variables”, in the documentation).
128
130 In case of difficulty, see CREATE DATABASE (CREATE_DATABASE(7)) and
131 psql(1) for discussions of potential problems and error messages. The
132 database server must be running at the targeted host. Also, any default
133 connection settings and environment variables used by the libpq
134 front-end library will apply.
135
137 To create the database demo using the default database server:
138
139 $ createdb demo
140
141 To create the database demo using the server on host eden, port 5000,
142 using the LATIN1 encoding scheme with a look at the underlying command:
143
144 $ createdb -p 5000 -h eden -E LATIN1 -e demo
145 CREATE DATABASE demo ENCODING 'LATIN1';
146
148 dropdb(1), CREATE DATABASE (CREATE_DATABASE(7))
149
150
151
152PostgreSQL 9.2.24 2017-11-06 CREATEDB(1)