DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH PRINT BOOK
 

create_database(5)




CREATE DATABASE()         SQL Commands          CREATE DATABASE()


NAME

     CREATE DATABASE - create a new database


SYNOPSIS

     CREATE DATABASE name
         [ [ WITH ] [ OWNER [=] dbowner ]
                [ TEMPLATE [=] template ]
                [ ENCODING [=] encoding ]
                [ TABLESPACE [=] tablespace ]
                [ CONNECTION LIMIT [=] connlimit ] ]


DESCRIPTION

     CREATE DATABASE creates a new PostgreSQL database.

     To create a database, you must be a superuser  or  have  the
     special     CREATEDB    privilege.     See    CREATE    USER
     [create_user(5)].

     Normally, the creator becomes the owner of the new database.
     Superusers  can  create  databases  owned by other users, by
     using the OWNER clause. They can even create databases owned
     by  users  with  no  special privileges. Non-superusers with
     CREATEDB privilege can only create databases owned by  them-
     selves.

     By default, the new database will be created by cloning  the
     standard system database template1. A different template can
     be specified by writing TEMPLATE  name.  In  particular,  by
     writing TEMPLATE template0, you can create a virgin database
     containing only the standard objects predefined by your ver-
     sion  of  PostgreSQL.  This  is  useful if you wish to avoid
     copying any installation-local objects that  may  have  been
     added to template1.


PARAMETERS

     name The name of a database to create.

     dbowner
          The name of the database user  who  will  own  the  new
          database,  or  DEFAULT  to use the default (namely, the
          user executing the command).

     template
          The name of the template from which to create  the  new
          database,  or DEFAULT to use the default template (tem-
          plate1).

     encoding
          Character set encoding to  use  in  the  new  database.
          Specify  a  string  constant (e.g., 'SQL_ASCII'), or an


SQL - Language StatementLast change: 2008-01-03 1


CREATE DATABASE()         SQL Commands          CREATE DATABASE()

          integer encoding number, or DEFAULT to use the  default
          encoding  (namely,  the  encoding of the template data-
          base). The character sets supported by  the  PostgreSQL
          server are described in in the documentation.

     tablespace
          The name of the tablespace that will be associated with
          the  new  database,  or  DEFAULT  to  use  the template
          database's tablespace.  This  tablespace  will  be  the
          default  tablespace  used  for  objects created in this
          database. See CREATE TABLESPACE  [create_tablespace(5)]
          for more information.

     connlimit
          How many concurrent connections can  be  made  to  this
          database. -1 (the default) means no limit.

     Optional parameters can be written in any  order,  not  only
     the order illustrated above.


NOTES

     CREATE DATABASE cannot  be  executed  inside  a  transaction
     block.

     Errors along the line of  ``could  not  initialize  database
     directory''  are most likely related to insufficient permis-
     sions on the data directory, a full disk, or other file sys-
     tem problems.

     Use DROP DATABASE [drop_database(5)] to remove a database.

     The program createdb  [createdb(1)]  is  a  wrapper  program
     around this command, provided for convenience.

     Although it is possible to copy a database other  than  tem-
     plate1  by  specifying its name as the template, this is not
     (yet) intended as a general-purpose ``COPY DATABASE'' facil-
     ity.  The principal limitation is that no other sessions can
     be connected to the template  database  while  it  is  being
     copied.  CREATE  DATABASE  will fail if any other connection
     exists when it starts; otherwise,  new  connections  to  the
     template  database are locked out until CREATE DATABASE com-
     pletes.  See in the documentation for more information.

     The CONNECTION LIMIT option is only enforced  approximately;
     if  two  new sessions start at about the same time when just
     one connection ``slot'' remains for the database, it is pos-
     sible  that  both will fail. Also, the limit is not enforced
     against superusers.


EXAMPLES



SQL - Language StatementLast change: 2008-01-03 2


CREATE DATABASE()         SQL Commands          CREATE DATABASE()

     To create a new database:

     CREATE DATABASE lusiadas;

     To create a database sales owned by  user  salesapp  with  a
     default tablespace of salesspace:

     CREATE DATABASE sales OWNER salesapp TABLESPACE salesspace;

     To create a database music  which  supports  the  ISO-8859-1
     character set:

     CREATE DATABASE music ENCODING 'LATIN1';


COMPATIBILITY

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


SEE ALSO

     ALTER   DATABASE    [alter_database(5)],    DROP    DATABASE
     [drop_database(l)]


SQL - Language StatementLast change: 2008-01-03 3



Man(1) output converted with man2html