]> begriffs open source - ai-pg/blob - full-docs/txt/app-createdb.txt
Convert HTML docs to more streamlined TXT
[ai-pg] / full-docs / txt / app-createdb.txt
1
2 createdb
3
4    createdb — create a new PostgreSQL database
5
6 Synopsis
7
8    createdb [connection-option...] [option...] [dbname [description]]
9
10 Description
11
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
22 Options
23
24    createdb accepts the following command-line arguments:
25
26    dbname
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
30           current system 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
44           server.
45
46    -E encoding
47           --encoding=encoding
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.
51
52    -l locale
53           --locale=locale
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.
58
59    --lc-collate=locale
60           Specifies the LC_COLLATE setting to be used in this database.
61
62    --lc-ctype=locale
63           Specifies the LC_CTYPE setting to be used in this database.
64
65    --builtin-locale=locale
66           Specifies the locale name when the builtin provider is used.
67           Locale support is described in Section 23.1.
68
69    --icu-locale=locale
70           Specifies the ICU locale ID to be used in this database, if the
71           ICU locale provider is selected.
72
73    --icu-rules=rules
74           Specifies additional collation rules to customize the behavior
75           of the default collation of this database. This is supported for
76           ICU only.
77
78    --locale-provider={builtin|libc|icu}
79           Specifies the locale provider for the database's default
80           collation.
81
82    -O owner
83           --owner=owner
84           Specifies the database user who will own the new database. (This
85           name is processed as a double-quoted identifier.)
86
87    -S strategy
88           --strategy=strategy
89           Specifies the database creation strategy. See CREATE DATABASE
90           STRATEGY for more details.
91
92    -T template
93           --template=template
94           Specifies the template database from which to build this
95           database. (This name is processed as a double-quoted
96           identifier.)
97
98    -V
99           --version
100           Print the createdb version and exit.
101
102    -?
103           --help
104           Show help about createdb command line arguments, and exit.
105
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
108    about them.
109
110    createdb also accepts the following command-line arguments for
111    connection parameters:
112
113    -h host
114           --host=host
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.
118
119    -p port
120           --port=port
121           Specifies the TCP port or the local Unix domain socket file
122           extension on which the server is listening for connections.
123
124    -U username
125           --username=username
126           User name to connect as.
127
128    -w
129           --no-password
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.
135
136    -W
137           --password
138           Force createdb to prompt for a password before connecting to a
139           database.
140
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
146           connection attempt.
147
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.
155
156 Environment
157
158    PGDATABASE
159           If set, the name of the database to create, unless overridden on
160           the command line.
161
162    PGHOST
163           PGPORT
164           PGUSER
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.
168
169    PG_COLOR
170           Specifies whether to use color in diagnostic messages. Possible
171           values are always, auto and never.
172
173    This utility, like most other PostgreSQL utilities, also uses the
174    environment variables supported by libpq (see Section 32.15).
175
176 Diagnostics
177
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.
182
183 Examples
184
185    To create the database demo using the default database server:
186 $ createdb demo
187
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;
193
194 See Also
195
196    dropdb, CREATE DATABASE