CREATE DATABASE statement creates a new CockroachDB database.
Required privileges
To create a database, you must be a member of theadmin role or have the CREATEDB parameter set.
Syntax
Parameters
Create a new database only if a database of the same name does not already exist. If one does exist, do not return an error.
The name of the database to create, which must be unique and follow identifier rules.Avoid starting your database name with
cluster:. If your database name begins with this string, you must append &options=-ccluster=system to the URI connection string to connect to the cluster.The
ENCODING clause is accepted for PostgreSQL compatibility, but UTF-8 is the only supported encoding. The aliases UTF8 and UNICODE are also accepted. Values should be enclosed in single quotes and are case-insensitive.Example: CREATE DATABASE bank ENCODING = 'UTF-8'Supported for compatibility with PostgreSQL. A value of
-1 indicates no connection limit. Values other than -1 are currently not supported. By default, CONNECTION LIMIT = -1.Create a multi-region database with
region_name as the primary region.Allowed values include any region returned by SHOW REGIONS FROM CLUSTER.Create a multi-region database with
region_name_list as database regions.To set database regions at database creation, a primary region must be specified in the same CREATE DATABASE statement.Create a multi-region database with regional failure or zone failure survival goals.Options:
SURVIVE ZONE FAILURE(Default)SURVIVE REGION FAILURE(requires at least 3 database regions)
Examples
Create a database
Create a database with IF NOT EXISTS
CREATE DATABASE.
Create a multi-region database
First, check available regions:Create a multi-region database with secondary region
Add a secondary region for failover purposes:See also
- SHOW DATABASES
- SHOW CREATE DATABASE
- ALTER DATABASE
- SET DATABASE
- DROP DATABASE