1CREATE DATABASE()                SQL Commands                CREATE DATABASE()
2
3
4

NAME

6       CREATE DATABASE - create a new database
7
8

SYNOPSIS

10       CREATE DATABASE name
11           [ [ WITH ] [ OWNER [=] dbowner ]
12                  [ TEMPLATE [=] template ]
13                  [ ENCODING [=] encoding ]
14                  [ TABLESPACE [=] tablespace ]
15                  [ CONNECTION LIMIT [=] connlimit ] ]
16
17

DESCRIPTION

19       CREATE DATABASE creates a new PostgreSQL database.
20
21       To  create a database, you must be a superuser or have the special CRE‐
22       ATEDB privilege.  See CREATE USER [create_user(7)].
23
24       Normally, the creator becomes the owner of  the  new  database.   Supe‐
25       rusers  can  create  databases owned by other users, by using the OWNER
26       clause. They can even create databases owned by users with  no  special
27       privileges.  Non-superusers  with  CREATEDB  privilege  can only create
28       databases owned by themselves.
29
30       By default, the new database will be created by  cloning  the  standard
31       system  database  template1.  A  different template can be specified by
32       writing TEMPLATE name. In particular, by  writing  TEMPLATE  template0,
33       you  can  create a virgin database containing only the standard objects
34       predefined by your version of PostgreSQL. This is useful if you wish to
35       avoid  copying  any installation-local objects that may have been added
36       to template1.
37

PARAMETERS

39       name   The name of a database to create.
40
41       dbowner
42              The name of the database user who will own the new database,  or
43              DEFAULT  to use the default (namely, the user executing the com‐
44              mand).
45
46       template
47              The name of the template from which to create the new  database,
48              or DEFAULT to use the default template (template1).
49
50       encoding
51              Character  set  encoding  to  use in the new database. Specify a
52              string constant (e.g., 'SQL_ASCII'), or an integer encoding num‐
53              ber,  or DEFAULT to use the default encoding (namely, the encod‐
54              ing of the template database). The character sets  supported  by
55              the PostgreSQL server are described in in the documentation.
56
57       tablespace
58              The  name of the tablespace that will be associated with the new
59              database, or DEFAULT to use the template database's  tablespace.
60              This  tablespace will be the default tablespace used for objects
61              created  in  this  database.   See   CREATE   TABLESPACE   [cre‐
62              ate_tablespace(7)] for more information.
63
64       connlimit
65              How many concurrent connections can be made to this database. -1
66              (the default) means no limit.
67
68       Optional parameters can be written in any order,  not  only  the  order
69       illustrated above.
70

NOTES

72       CREATE DATABASE cannot be executed inside a transaction block.
73
74       Errors  along  the  line of ``could not initialize database directory''
75       are most likely related to insufficient permissions on the data  direc‐
76       tory, a full disk, or other file system problems.
77
78       Use DROP DATABASE [drop_database(7)] to remove a database.
79
80       The  program  createdb  [createdb(1)]  is a wrapper program around this
81       command, provided for convenience.
82
83       Although it is possible to copy a  database  other  than  template1  by
84       specifying  its  name  as the template, this is not (yet) intended as a
85       general-purpose ``COPY DATABASE'' facility.  The  principal  limitation
86       is  that  no  other  sessions can be connected to the template database
87       while it is being copied. CREATE DATABASE will fail if any  other  con‐
88       nection  exists  when it starts; otherwise, new connections to the tem‐
89       plate database are locked out until CREATE DATABASE completes.  See  in
90       the documentation for more information.
91
92       The  CONNECTION LIMIT option is only enforced approximately; if two new
93       sessions start at about the same time when just one connection ``slot''
94       remains for the database, it is possible that both will fail. Also, the
95       limit is not enforced against superusers.
96

EXAMPLES

98       To create a new database:
99
100       CREATE DATABASE lusiadas;
101
102
103       To create a database sales  owned  by  user  salesapp  with  a  default
104       tablespace of salesspace:
105
106       CREATE DATABASE sales OWNER salesapp TABLESPACE salesspace;
107
108
109       To create a database music which supports the ISO-8859-1 character set:
110
111       CREATE DATABASE music ENCODING 'LATIN1';
112
113

COMPATIBILITY

115       There  is  no  CREATE DATABASE statement in the SQL standard. Databases
116       are equivalent to catalogs, whose creation is implementation-defined.
117

SEE ALSO

119       ALTER DATABASE [alter_database(7)], DROP DATABASE [drop_database(l)]
120
121
122
123SQL - Language Statements         2008-06-08                 CREATE DATABASE()
Impressum