CREATE DATABASE
Creates a new database.
Synopsis
CREATE DATABASE <database_name> [s[WITH] <database_attribute>=<value> [ ... ]]
where
[OWNER=<database_owner>]
[TEMPLATE=<template>]
[ENCODING=<encoding>]
[TABLESPACE=<tablespace>]
[CONNECTION LIMIT=<connection_limit>]
Description
CREATE DATABASE
creates a new database. To create a database, you must be a superuser or have the special CREATEDB
privilege.
The creator becomes the owner of the new database by default. 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 themselves.
By default, the new database is created by cloning the standard system database template named template1
. You can specify a different template by including the WITH TEMPLATE=<template>
clause in the CREATE DATABASE
command. In particular, specifying WITH TEMPLATE=template0
creates a clean database containing only the standard objects predefined by HAWQ. This is useful if you wish to avoid copying any installation-local objects that may have been added to template1
.
Parameters
The name of a database to create.
Note: HAWQ reserves the database name hcatalog
for system use.
OWNER=
The name of the database user who will own the new database, or DEFAULT
to use the default owner (the user executing the command).
TEMPLATE=
The name of the template from which to create the new database, or ENCODING= Character set encoding to use in the new database. Specify a string constant (such as TABLESPACE= The name of the tablespace that will be associated with the new database, or CONNECTION LIMIT= The maximum number of concurrent connections possible. The default of -1 means there is no limitation. Only template databases may be specified in the The To create a new database using the default template: To create a database named To create a database named There is no DEFAULT
to use the default template (template1
).'SQL_ASCII'
), an integer encoding number, or DEFAULT
to use the default encoding.DEFAULT
to use the template database’s tablespace. This tablespace will be the default tablespace used for objects created in this database.Notes
CREATE DATABASE
cannot be executed inside a transaction block.WITH TEMPLATE=<template>
clause. When you specify template1
or template0
as the database template, no other sessions can be connected to the template database during the create operation. New connections to the template database are locked out until CREATE DATABASE
completes.CONNECTION LIMIT
is not enforced against superusers.Examples
CREATE DATABASE gpdb;
sales
owned by user salesapp
with a default tablespace of salesspace
:CREATE DATABASE sales OWNER=salesapp TABLESPACE=salesspace;
music
which supports the ISO-8859-1 character set:CREATE DATABASE music ENCODING='LATIN1';
Compatibility
CREATE DATABASE
statement in the SQL standard. Databases are equivalent to catalogs, whose creation is implementation-defined.See Also