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 an 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 Console.

    Go to the Cloud SQL Instances page

  2. Create an 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 sql instances create [REGIONAL_INSTANCE_NAME] \
                         --availability-type=REGIONAL \
                         --database-version=[DATABASE_VERSION] \
                         --cpu=[NUMBER_CPUS] --memory=[MEMORY_SIZE]
    
    For a complete list of available parameters, see the gcloud sql instances create reference page.
  2. Configure the root user:
    gcloud sql users set-password root 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 login
    ACCESS_TOKEN="$(gcloud auth print-access-token)"
    curl --header "Authorization: Bearer ${ACCESS_TOKEN}" \
         --header 'Content-Type: application/json' \
         --data '{"name":"[INSTANCE_NAME]", "region":"[REGION]",
                  "databaseVersion": "[DATABASE_VERSION]",
                  "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

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:

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 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 sql instances patch [INSTANCE_NAME] --availability-type REGIONAL

For reference information, see gcloud sql instances patch.

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.

To learn more about failovers, see the Failover overview.

Console

  1. Go to the Cloud SQL Instances page in the Google Cloud 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 login
    ACCESS_TOKEN="$(gcloud auth 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:
    gcloud auth login
    ACCESS_TOKEN="$(gcloud auth print-access-token)"
    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.

Verifying an instance has high availability

To verify an instance has high availability:

Console

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

    Go to the Cloud SQL Instances page

  2. Click an instance name to open its Instance details page.
  3. Under Configuration, it shows Highly available (regional).

gcloud

gcloud sql instances describe [INSTANCE_NAME]
The output indicates availabilityType is REGIONAL.

cURL

gcloud auth login
ACCESS_TOKEN="$(gcloud auth print-access-token)"
curl --header "Authorization: Bearer ${ACCESS_TOKEN}" \
     -X GET \
     https://www.googleapis.com/sql/v1beta4/projects/[PROJECT-ID]/instances/[MASTER_INSTANCE_NAME]?fields=settings
The output indicates availabilityType is REGIONAL.

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 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.
  7. When you see the message box, click SAVE AND RESTART.

gcloud

For reference information, see gcloud sql instances patch.
gcloud 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.
gcloud auth login
ACCESS_TOKEN="$(gcloud auth print-access-token)"
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
Need help? Visit our support page.