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. CockroachDB does not prevent you from defining secondary regions on databases with regional by row tables, but the interaction of these features is not supported. Therefore, Cockroach Labs recommends that you avoid defining secondary regions on databases that use regional by row table configurations.

