CREATE DATABASE

Synopsis

Use the CREATE DATABASE statement to create a database that functions as a grouping mechanism for database objects such as tables.

Syntax

  1. create_database ::= CREATE DATABASE name [ create_database_options ]
  2. create_database_options ::= [ WITH ] [ OWNER [ = ] user_name ]
  3. [ TEMPLATE [ = ] template ]
  4. [ ENCODING [ = ] encoding ]
  5. [ LC_COLLATE [ = ] lc_collate ]
  6. [ LC_CTYPE [ = ] lc_ctype ]
  7. [ TABLESPACE [ = ] tablespace_name ]
  8. [ ALLOW_CONNECTIONS [ = ] allowconn ]
  9. [ CONNECTION LIMIT [ = ] connlimit ]
  10. [ IS_TEMPLATE [ = ] istemplate ]
  11. [ COLOCATED [ = ] { 'true' | 'false' } ]

create_database

CREATE DATABASE - 图1

create_database_options

CREATE DATABASE - 图2

Semantics

create_database

CREATE DATABASE name

Specify the name of the database to be created. An error is raised if a YSQL database of the given name already exists.

create_database_options

[ WITH ] OWNER user_name

Specify the role name of the user who will own the new database. When not specified, the database creator is the owner.

TEMPLATE template

Specify the name of the template from which the new database is created.

ENCODING encoding

Specify the character set encoding to use in the new database.

LC_COLLATE lc_collate

Specify the collation order (LC_COLLATE).

LC_CTYPE lc_ctype

Specify the character classification (LC_CTYPE).

TABLESPACE tablespace_name

Specify the new tablespace that is associated with the database.

ALLOW_CONNECTIONS allowconn

Specify false to disallow connections to the database. Default is true, which allows connections to the database.

CONNECTION_LIMIT connlimit

Specify how many concurrent connections can be made to this database. Default of -1 allows unlimited concurrent connections.

IS_TEMPLATE istemplate

true — This database can be cloned by any user with CREATEDB privileges.Specify false to only superusers or the owner of the database can clone it.

COLOCATED

Specify true if all tables for this database should be colocated on a single tablet. See colocated tables architecture for details on when colocated tables are useful.Default value is false and every table in the database will have its own set of tablets.

Examples

Create a colocated database

  1. yugabyte=# CREATE DATABASE company WITH COLOCATED = true;

In this example, all tables in the database company will be colocated on a single tablet.

See also