Skip to content

Latest commit

 

History

History
111 lines (77 loc) · 4 KB

add-region.md

File metadata and controls

111 lines (77 loc) · 4 KB
title summary toc
ADD REGION
The ADD REGION statement adds a region to a multi-region database.
true

New in v21.1: The ALTER DATABASE .. ADD REGION statement adds a region to a multi-region database.

{{site.data.alerts.callout_info}} ADD REGION is a subcommand of ALTER DATABASE {{site.data.alerts.end}}

{{site.data.alerts.callout_danger}} In order to add a region with ADD REGION, you must first set a primary database region. For an example showing how to add a primary region, see Set the primary region. {{site.data.alerts.end}}

Synopsis

{% include {{ page.version.version }}/sql/generated/diagrams/alter_database_add_region.html %}

Parameters

| Parameter | Description | |-----------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------| | database_name | The database to which you are adding a region. | | region_name | The region being added to this database. Allowed values include any region present in SHOW REGIONS FROM CLUSTER. |

Required privileges

The user must be a member of the admin or owner roles, or have the CREATE privilege on the database.

Examples

Set the primary region

To add the first region, or to set an already-added region as the primary region, use the following statement:

{% include copy-clipboard.html %}

ALTER DATABASE foo PRIMARY REGION "us-east1";
ALTER DATABASE PRIMARY REGION

For more information, see Database regions.

Add a region to a database

To add another region to a database that already has at least one region, use a statement like the following:

{% include copy-clipboard.html %}

ALTER database foo ADD region "us-east1";
ALTER DATABASE ADD REGION

For more information, see Database regions.

{{site.data.alerts.callout_info}} Only regions that are defined at node startup time can be added to a multi-region database. For more information, see Cluster regions. {{site.data.alerts.end}}

View a database's regions

To view the regions associated with a multi-region database, use the following statement:

{% include copy-clipboard.html %}

SHOW REGIONS FROM DATABASE foo;
  database |  region  | primary |                     zones
-----------+----------+---------+------------------------------------------------
   foo     | us-east1 |  true   | {us-east1-b,us-east1-b,us-east1-b,us-east1-b}
(1 row)

For more information, see Database regions.

Drop a region from a database

To drop a region from a multi-region database, use the following statement:

{% include copy-clipboard.html %}

ALTER DATABASE foo DROP REGION "us-east1";
ALTER DATABASE DROP REGION

{{site.data.alerts.callout_danger}} You can only drop the primary region from a multi-region database if it's the last remaining region. After that, the database will no longer be a multi-region database. {{site.data.alerts.end}}

For more information, see Database regions.

See also