Configuring an Instance for High Availability

This page describes how to configure a Cloud SQL instance for high availability.

You can configure an instance for high availability when you create the instance, or you can enable high availability on an existing instance.

For more information about the high availability configuration, see Overview of the High Availability Configuration.

Creating a new instance configured for high availability

When you create a Cloud SQL instance, and you configure it for high availability, Cloud SQL creates the instance as a regional instance.

To create an instance configured for high availability:

Console

  1. Go to the Cloud SQL Instances page in the Google Cloud Platform Console.

    Go to the Cloud SQL Instances page

  2. Create the instance, selecting the High availability (regional) checkbox under the Enable auto backups and high availability configuration option section.

gcloud

  1. Create the regional instance:
    gcloud beta sql instances create [REGIONAL_INSTANCE_NAME] \
                                     --availability-type=REGIONAL \
                                     --database-version=POSTGRES_9_6 \
                                     --cpu=[NUMBER_CPUS] --memory=[MEMORY_SIZE]
    
  2. Configure the root user:
    gcloud sql users set-password postgres no-host \
                          --instance=[REGIONAL_INSTANCE_NAME] --password=[PASSWORD]
    
For a complete list of available parameters, see the gcloud beta sql instances create reference page.

cURL

  1. Create the regional instance:
    ACCESS_TOKEN="$(gcloud auth application-default print-access-token)"
    curl --header "Authorization: Bearer ${ACCESS_TOKEN}" \
         --header 'Content-Type: application/json' \
         --data '{"name":"[INSTANCE_NAME]", "region":"[REGION]",
                  "databaseVersion":"POSTGRES_9_6",
                  "settings": {
                      "tier":"[MACHINE_TYPE]",
                      "availabilityType":"REGIONAL"}}' \
         -X POST \
         https://www.googleapis.com/sql/v1beta4/projects/[PROJECT-ID]/instances
    
    For the complete list of parameters for this request, see the instances:insert page.
  2. When the instance finishes initializing, update the password for the postgres user:
    curl --header "Authorization: Bearer ${ACCESS_TOKEN}" \
         --header 'Content-Type: application/json' \
         --data '{"name": "postgres", "host": "nohost", "password": "[PASSWORD]"}' \
         'https://www.googleapis.com/sql/v1beta4/projects/[PROJECT-ID]/instances/[INSTANCE_NAME]/users?name=postgres'
    

For more details about creating an instance, see Creating Instances.

Configuring an existing instance for high availability

Console

Configuring an existing instance for high availability causes a few minutes of downtime while the instance is reconfigured.

To configure an existing instance for high availability:

  1. Go to the Cloud SQL Instances page in the Google Cloud Platform Console.

    Go to the Cloud SQL Instances page

  2. Click the instance name to open its Overview page and click Edit in the button bar.
  3. Under the Enable auto backups and high availability configuration option section, select the High availability (regional) checkbox.
  4. Click Save.

    You are returned to the instance page for the master while the instance is updated.

gcloud

Update the instance to be regional:

gcloud beta sql instances patch [INSTANCE_NAME] --availability-type REGIONAL

cURL

Configuring an existing instance for high availability causes a few minutes of downtime while the instance is reconfigured.

Update the instance to be a regional instance:

curl --header "Authorization: Bearer ${ACCESS_TOKEN}" \
     --header 'Content-Type: application/json' \
     --data '{"settings": {"availabilityType":"REGIONAL"}}' \
     -X PATCH \
     https://www.googleapis.com/sql/v1beta4/projects/[PROJECT-ID]/instances/[INSTANCE_NAME]

Initiating failover

Testing failover is optional, but is recommended so that you can see how your application responds in the event of a failover.

Console

  1. Go to the Cloud SQL Instances page in the Google Cloud Platform Console.

    Go to the Cloud SQL Instances page

  2. Click the instance name to open its Overview page.
  3. Click Failover in the button bar.

gcloud

Initiate the failover:

gcloud sql instances failover [MASTER_INSTANCE_NAME]

cURL

  1. Describe the master instance to get the value of the `settingsVersion` field.
    ACCESS_TOKEN="$(gcloud auth application-default print-access-token)"
    curl --header "Authorization: Bearer ${ACCESS_TOKEN}" \
         -X GET \
         https://www.googleapis.com/sql/v1beta4/projects/[PROJECT-ID]/instances/[MASTER_INSTANCE_NAME]
    
  2. Initiate the failover:
    curl --header "Authorization: Bearer ${ACCESS_TOKEN}" \
         --header 'Content-Type: application/json' \
         --data '{"failoverContext":{"settingsVersion":"[SETTINGS_VERSION]"}}' \
              -X POST \
         https://www.googleapis.com/sql/v1beta4/projects/[PROJECT-ID]/instances/[MASTER_INSTANCE_NAME]/failover
              

The instance fails over and is not available to serve data for a few minutes.

What's next

Send feedback about...

Cloud SQL for PostgreSQL