Enabling and disabling high availability on an instance

This page describes how to configure a PostgreSQL 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 PostgreSQL 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 a PostgreSQL instance.
  3. On the Instance ID page, select Show configuration options.
  4. Open Auto backups and high availability.
  5. Select the High availability (regional) checkbox.

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:
    gcloud auth application-default login
    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 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 master instance name to open its Instance details 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.
    gcloud auth application-default login
    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.

Disabling high availability on an instance

Before you perform this procedure, make sure there are no operations currently running on the instance.

To disable 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. Select the instance you want to disable high availability on.
  3. On the Instance details page, click EDIT.
  4. Open Auto backups.
  5. Under Availability click Single zone.
  6. Click Save. This edit requires a restart of the instance. When you see the message box, click SAVE AND RESTART

gcloud

For reference information, see gcloud sql instances patch.
gcloud beta sql instances patch [INSTANCE_NAME] --availability-type ZONAL

cURL

The following request uses the instances:patch method to change the availability type on the instance to ZONAL.
curl --header "Authorization: Bearer ${ACCESS_TOKEN}" \
     --header 'Content-Type: application/json' \
     --data '{"settings": {"availabilityType":"ZONAL"}}' \
     -X PATCH \
     https://www.googleapis.com/sql/v1beta4/projects/[PROJECT-ID]/instances/[INSTANCE_NAME]

What's next

Was this page helpful? Let us know how we did:

Send feedback about...

Cloud SQL for PostgreSQL