CREATE DATABASE statement creates a new CockroachDB database.
The
CREATE DATABASE statement performs a schema change. For more information about how online schema changes work in CockroachDB, see Online Schema Changes.Required privileges
To create a database, the user must be a member of theadmin role or must have the CREATEDB parameter set.
Synopsis
Parameters
root user or other admin role) connections a gateway node can have open at one time, use the server.max_connections_per_gateway cluster setting. If a new non-superuser connection would exceed this limit, the error message "sorry, too many clients already" is returned, along with error code 53300. This setting may be useful until the CONNECTION LIMIT syntax is fully supported.
Example
Create a database
Create fails (name already in use)
CREATE DATABASE even though a new database wasn’t created.
Create a multi-region database
Suppose you start a cluster with region and zone localities specified at startup. For this example, let’s use a demo cluster, with the--demo-locality flag to simulate a multi-region cluster:
Create a multi-region database with a super region
To create a multi-region database and define a super region in the same statement, use theSUPER REGION clause:
ALTER DATABASE ... ALTER SUPER REGION ... SURVIVE.
To inspect the super region and whether it has an explicit survival goal, use SHOW SUPER REGIONS:
Create a multi-region database with a secondary region
You can add a secondary region to a multi-region database for failover purposes. If the primary region fails, the secondary region becomes the new primary region. To add a secondary region during database creation, use the following steps:-
Start a
cockroach democluster as described in the example Create a multi-region database. -
Issue a
CREATE DATABASEstatement like the following. It is the same as in the Create a multi-region database example, except that it adds aSECONDARY REGION {region}clause:
REGIONAL BY ROW tables, do not set a secondary region. A database has only one secondary region, and it applies to every partition, so every partition fails over to the same region, however far away. Instead, use Zone Config Extensions to define a failover region for each database region. This works like a secondary region, but you choose the failover region separately for each partition’s home region, for example us-east1 → us-central1 and europe-west1 → europe-west2. Failover regions require SURVIVE REGION FAILURE. For instructions, see Configure per-partition failover regions for REGIONAL BY ROW tables.

