CREATE DATABASE

Creates a new database.

Synopsis

CREATE DATABASE <database_name> [s[WITH] <database_attribute>=<value> [ ... ]]

where <database_attribute> is:

    [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

<database_name>
The name of a database to create.

Note: HAWQ reserves the database name hcatalog for system use.

OWNER=<database_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=<template>
The name of the template from which to create the new database, or DEFAULT to use the default template (template1).

ENCODING=<encoding>
Character set encoding to use in the new database. Specify a string constant (such as 'SQL_ASCII'), an integer encoding number, or DEFAULT to use the default encoding.

TABLESPACE=<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.

CONNECTION LIMIT=<connection_limit>
The maximum number of concurrent connections possible. The default of -1 means there is no limitation.

Notes

CREATE DATABASE cannot be executed inside a transaction block.

Only template databases may be specified in the 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.

The CONNECTION LIMIT is not enforced against superusers.

Examples

To create a new database using the default template:

CREATE DATABASE gpdb;

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

CREATE DATABASE sales OWNER=salesapp TABLESPACE=salesspace;

To create a database named 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

DROP DATABASE