1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
5 >CREATE DATABASE</TITLE
8 CONTENT="Modular DocBook HTML Stylesheet Version 1.7"><LINK
10 HREF="mailto:pgsql-docs@postgresql.org"><LINK
12 TITLE="PostgreSQL 7.4.1 Documentation"
13 HREF="index.html"><LINK
16 HREF="sql-commands.html"><LINK
18 TITLE="CREATE CONVERSION"
19 HREF="sql-createconversion.html"><LINK
22 HREF="sql-createdomain.html"><LINK
25 HREF="stylesheet.css"><META
27 CONTENT="2003-12-22T03:48:47"></HEAD
33 SUMMARY="Header navigation table"
43 >PostgreSQL 7.4.1 Documentation</TH
51 HREF="sql-createconversion.html"
60 HREF="sql-createconversion.html"
73 HREF="sql-createdomain.html"
81 HREF="sql-createdomain.html"
92 NAME="SQL-CREATEDATABASE"
102 >CREATE DATABASE -- create a new database</DIV
107 CLASS="REFSYNOPSISDIV"
115 >CREATE DATABASE <VAR
119 [ [ WITH ] [ OWNER [=] <VAR
154 > To create a database, you must be a superuser or have the special
160 HREF="sql-createuser.html"
167 > Normally, the creator becomes the owner of the new database.
168 Superusers can create databases owned by other users using the
172 > clause. They can even create databases owned by
173 users with no special privileges. Non-superusers with <TT
177 privilege can only create databases owned by themselves.
180 > An alternative location can be specified in order to,
181 for example, store the database on a different disk.
182 The path must have been prepared with the
184 HREF="app-initlocation.html"
194 > If the path name does not contain a slash, it is interpreted
195 as an environment variable name, which must be known to the
196 server process. This way the database administrator can
197 exercise control over locations in which databases can be created.
198 (A customary choice is, e.g., <TT
202 If the server is compiled with <TT
204 >ALLOW_ABSOLUTE_DBPATHS</TT
206 (not so by default), absolute path names, as identified by
210 >/usr/local/pgsql/data</TT
213 In either case, the final path name must be absolute and must not
214 contain any single quotes.
217 > By default, the new database will be created by cloning the standard
221 >. A different template can be
222 specified by writing <TT
232 >TEMPLATE template0</TT
233 >, you can create a virgin
234 database containing only the standard objects predefined by your
239 if you wish to avoid copying
240 any installation-local objects that may have been added to
247 > The optional encoding parameter allows selection of the database
248 encoding. When not specified, it defaults to the encoding used by
249 the selected template database.
271 > The name of a database to create.
281 > The name of the database user who will own the new database,
285 > to use the default (namely, the
286 user executing the command).
296 > An alternate file-system location in which to store the new database,
297 specified as a string literal;
301 > to use the default location.
311 > The name of the template from which to create the new database,
315 > to use the default template
329 > Character set encoding to use in the new database. Specify
330 a string constant (e.g., <TT
334 or an integer encoding number, or <TT
338 to use the default encoding.
344 > Optional parameters can be written in any order, not only the order
359 > cannot be executed inside a transaction
363 > Errors along the line of <SPAN
365 >"could not initialize database directory"</SPAN
367 are most likely related to insufficient permissions on the data
368 directory, a full disk, or other file system problems. When using an
369 alternate location, the user under
370 which the database server is running must have access to the location.
374 HREF="sql-dropdatabase.html"
378 > to remove a database.
382 HREF="app-createdb.html"
389 wrapper program around this command, provided for convenience.
392 > There are security issues involved with using alternate database
393 locations specified with absolute path names; this is why the feature
394 is not enabled by default. See <A
395 HREF="manage-ag-alternate-locs.html"
397 > for more information.
400 > Although it is possible to copy a database other than <TT
404 by specifying its name as the template, this is not (yet) intended as
405 a general-purpose <SPAN
412 We recommend that databases used as templates be treated as read-only.
414 HREF="manage-ag-templatedbs.html"
416 > for more information.
427 > To create a new database:
430 CLASS="PROGRAMLISTING"
431 >CREATE DATABASE lusiadas;</PRE
435 > To create a new database in an alternate area
439 >, execute the following from the
443 CLASS="PROGRAMLISTING"
445 initlocation ~/private_db</PRE
448 Then execute the following from within a
455 CLASS="PROGRAMLISTING"
456 >CREATE DATABASE elsewhere WITH LOCATION '/home/olly/private_db';</PRE
471 > statement in the SQL
472 standard. Databases are equivalent to catalogs, whose creation is
473 implementation-defined.
481 SUMMARY="Footer navigation table"
492 HREF="sql-createconversion.html"
510 HREF="sql-createdomain.html"
520 >CREATE CONVERSION</TD
526 HREF="sql-commands.html"