Enabling and disabling high availability on an instance

This page describes how to configure an 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 high availability, see Overview of the high availability Configuration.

The legacy configuration for high availability used a failover replica instance. The new configuration does not use a failover replica. Instead, it uses Google's regional persistent disks, which synchronously replicate data at the block-level between two zones in a region. If you have an existing MySQL instance that uses the legacy high availability, you can update your configuration to use the current version. For other procedures related the legacy high availability configuration, see Legacy configuration for high availability.

Creating a new instance configured for high availability

When you create an instance and configure it for high availability, Cloud SQL creates it 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 info page, select Show configuration options.
  4. Open Backups, recovery, and high availability.
  5. Select the High availability (regional) radio button.

gcloud

  1. Create the regional instance:
    gcloud sql instances create [REGIONAL_INSTANCE_NAME] \
                         --availability-type=REGIONAL \
                         --database-version=[DATABASE_VERSION] \
                         --tier=[MACHINE_TYPE] \
                         --enable-bin-log
    
    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 --host=% \
               --instance=[PRIMARY_INSTANCE_NAME]
               --password=[PASSWORD]
    

REST v1beta4

For the complete list of parameters for this request, see the instances:insert page.

Create the regional instance.

  1. Before using any of the request data below, make the following replacements:

    • project-id: The project ID
    • instance-name: The instance name
    • database-version: The database version enum string
    • region The GCP region
    • machine-type The machine type

    HTTP method and URL:

    POST https://www.googleapis.com/sql/v1beta4/projects/project-id/instances

    Request JSON body:

    {
      "name": "instance-name",
      "region": "region",
      "databaseVersion": "database-version",
       "settings": {
         "tier": "machine-type",
         "backupConfiguration": {
             "binaryLogEnabled": true,
             "enabled": true
          },
          "availabilityType": "REGIONAL"
       }
    }
    

    To send your request, expand one of these options:

    You should receive a JSON response similar to the following:

  2. When the instance finishes initializing, update the root password on the instance:

    Before using any of the request data below, make the following replacements:

    • project-id: The project ID
    • instance-id: The instance ID
    • password: The new root user password

    HTTP method and URL:

    PATCH https://www.googleapis.com/sql/v1beta4/projects/project-id/instances/instance-id/users?host=%25&name=root'

    Request JSON body:

    {
       "name": "root",
       "host": "%",
       "password": "password"}
    

    To send your request, expand one of these options:

    You should receive a successful status code (2xx) and an empty response.

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

  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.
  3. Click Edit.
  4. Open Backups, recovery, and high availability.
  5. Enable the Automate backups and Enable point-in-time recovery checkboxes.
  6. Select High availability (regional).
  7. Click Save.

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

gcloud

Update the instance to be regional:

gcloud sql instances patch [INSTANCE_NAME] --availability-type REGIONAL --enable-bin-log --backup-start-time=[HH:MM]

For reference information, see gcloud sql instances patch.

REST v1beta4

  1. Check the primary instance to see if automatic backups and binary logs are enabled. These are required for high availability instances.

    Before using any of the request data below, make the following replacements:

    • project-id: The project ID
    • instance-id: The instance ID

    HTTP method and URL:

    GET https://www.googleapis.com/sql/v1beta4/projects/project-id/instances/instance-id

    To send your request, expand one of these options:

    You should receive a JSON response similar to the following:

    {
      "kind": "sql#instance",
      "state": "RUNNABLE",
      "databaseVersion": "MYSQL_5_7",
      "settings": {
        "authorizedGaeApplications": [],
        "tier": "db-f1-micro",
        "kind": "sql#settings",
        "pricingPlan": "PER_USE",
        "replicationType": "SYNCHRONOUS",
        "activationPolicy": "ALWAYS",
        "ipConfiguration": {
          "authorizedNetworks": [],
          "ipv4Enabled": true
        },
        "locationPreference": {
          "zone": "asia-east1-a",
          "kind": "sql#locationPreference"
        },
        "dataDiskType": "PD_SSD",
        "backupConfiguration": {
          "startTime": "08:00",
          "kind": "sql#backupConfiguration",
          "enabled": true,
          "binaryLogEnabled": true
        },
        "settingsVersion": "13",
        "storageAutoResizeLimit": "0",
        "storageAutoResize": true,
        "dataDiskSizeGb": "10"
      },
      "etag": "etag-id",
      "ipAddresses": [
        {
          "type": "PRIMARY",
          "ipAddress": "10.0.0.1"
        }
      ],
      "serverCaCert": {
        "kind": "sql#sslCert",
        "certSerialNumber": "0",
        "cert": "certificate-id",
        "commonName": "C=US,O=Google\\, Inc,CN=Google Cloud SQL Server CA,dnQualifier=dn-qualifier-id",
        "sha1Fingerprint": "sha-id",
        "instance": "instance-id",
        "createTime": "2019-06-28T22:46:35.052Z",
        "expirationTime": "2029-06-25T22:47:35.052Z"
      },
      "instanceType": "CLOUD_SQL_INSTANCE",
      "project": "project-id",
      "serviceAccountEmailAddress": "service-acct-id@gcp-sa-cloud-sql.iam.gserviceaccount.com",
      "backendType": "SECOND_GEN",
      "selfLink": "https://www.googleapis.com/sql/v1beta4/projects/project-id/instances/instance-id",
      "connectionName": "project-id:region:instance-id",
      "name": "instance-id",
      "region": "asia-east1",
      "gceZone": "asia-east1-a"
    }
    

    The output contains a section similar to the following:

      "backupConfiguration": {
        "kind": "sql#backupConfiguration",
        "startTime": "12:00",
        "enabled": true,
        "binaryLogEnabled": true
        }
      
  2. If either enabled or binaryLogEnabled are false, use the instances:patch method to enable them both. To enable backups, set enabled to true and startTime to a value which is the start of the backup window. To enable binary logging, set binaryLogEnabled to true.

    Before using any of the request data below, make the following replacements:

    • project-id: The project ID
    • instance-id: The instance ID (primary or replica)
    • start-time The time in the format "HH:MM"
    • enabled: Set to true for a primary instance. Set to false for a replica instance

    HTTP method and URL:

    PATCH https://www.googleapis.com/sql/v1beta4/projects/project-id/instances/instance-id

    Request JSON body:

    {
      "settings":
      {
        "backupConfiguration":
        {
          "startTime": "start-time",
          "enabled": enabled,
          "binaryLogEnabled": true
        }
      }
    }
    

    To send your request, expand one of these options:

    You should receive a JSON response similar to the following:

  3. Update the instance to be a regional instance:

    Before using any of the request data below, make the following replacements:

    • project-id: The project ID
    • instance-name: The instance name

    HTTP method and URL:

    PATCH https://www.googleapis.com/sql/v1beta4/projects/project-id/instances/instance-name

    Request JSON body:

    {
      "settings": {"availabilityType": "REGIONAL" }
    }
    

    To send your request, expand one of these options:

    You should receive a successful status code (2xx) and an empty response.

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 primary instance name to open its Instance details page.
  3. Click Failover in the button bar.

gcloud

Initiate the failover:

gcloud sql instances failover [PRIMARY_INSTANCE_NAME]

REST v1beta4

  1. Describe the primary instance to get the value of the settingsVersion field.

    Before using any of the request data below, make the following replacements:

    • project-id: The project ID
    • instance-id: The instance ID

    HTTP method and URL:

    GET https://www.googleapis.com/sql/v1beta4/projects/project-id/instances/instance-id

    To send your request, expand one of these options:

    You should receive a JSON response similar to the following:

    {
      "kind": "sql#instance",
      "state": "RUNNABLE",
      "databaseVersion": "MYSQL_5_7",
      "settings": {
        "authorizedGaeApplications": [],
        "tier": "db-f1-micro",
        "kind": "sql#settings",
        "pricingPlan": "PER_USE",
        "replicationType": "SYNCHRONOUS",
        "activationPolicy": "ALWAYS",
        "ipConfiguration": {
          "authorizedNetworks": [],
          "ipv4Enabled": true
        },
        "locationPreference": {
          "zone": "asia-east1-a",
          "kind": "sql#locationPreference"
        },
        "dataDiskType": "PD_SSD",
        "backupConfiguration": {
          "startTime": "08:00",
          "kind": "sql#backupConfiguration",
          "enabled": true,
          "binaryLogEnabled": true
        },
        "settingsVersion": "13",
        "storageAutoResizeLimit": "0",
        "storageAutoResize": true,
        "dataDiskSizeGb": "10"
      },
      "etag": "etag-id",
      "ipAddresses": [
        {
          "type": "PRIMARY",
          "ipAddress": "10.0.0.1"
        }
      ],
      "serverCaCert": {
        "kind": "sql#sslCert",
        "certSerialNumber": "0",
        "cert": "certificate-id",
        "commonName": "C=US,O=Google\\, Inc,CN=Google Cloud SQL Server CA,dnQualifier=dn-qualifier-id",
        "sha1Fingerprint": "sha-id",
        "instance": "instance-id",
        "createTime": "2019-06-28T22:46:35.052Z",
        "expirationTime": "2029-06-25T22:47:35.052Z"
      },
      "instanceType": "CLOUD_SQL_INSTANCE",
      "project": "project-id",
      "serviceAccountEmailAddress": "service-acct-id@gcp-sa-cloud-sql.iam.gserviceaccount.com",
      "backendType": "SECOND_GEN",
      "selfLink": "https://www.googleapis.com/sql/v1beta4/projects/project-id/instances/instance-id",
      "connectionName": "project-id:region:instance-id",
      "name": "instance-id",
      "region": "asia-east1",
      "gceZone": "asia-east1-a"
    }
    
  2. Initiate the failover:

    Before using any of the request data below, make the following replacements:

    • project-id: The project ID
    • instance-name: The instance name
    • settings-version: The settingsVersion from instanceInfo

    HTTP method and URL:

    POST https://www.googleapis.com/sql/v1beta4/projects/project-id/instances/instance-name/failover

    Request JSON body:

    {
      "failoverContext":
         {
            "settingsVersion":"settings-version"
         }
    }
    

    To send your request, expand one of these options:

    You should receive a JSON response similar to the following:

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.

REST v1beta4

Before using any of the request data below, make the following replacements:

  • project-id: The project ID
  • instance-id: The instance ID

HTTP method and URL:

GET https://www.googleapis.com/sql/v1beta4/projects/project-id/instances/instance-id

To send your request, expand one of these options:

You should receive a JSON response similar to the following:

{
  "kind": "sql#instance",
  "state": "RUNNABLE",
  "databaseVersion": "MYSQL_5_7",
  "settings": {
    "authorizedGaeApplications": [],
    "tier": "db-f1-micro",
    "kind": "sql#settings",
    "pricingPlan": "PER_USE",
    "replicationType": "SYNCHRONOUS",
    "activationPolicy": "ALWAYS",
    "ipConfiguration": {
      "authorizedNetworks": [],
      "ipv4Enabled": true
    },
    "locationPreference": {
      "zone": "asia-east1-a",
      "kind": "sql#locationPreference"
    },
    "dataDiskType": "PD_SSD",
    "backupConfiguration": {
      "startTime": "08:00",
      "kind": "sql#backupConfiguration",
      "enabled": true,
      "binaryLogEnabled": true
    },
    "settingsVersion": "13",
    "storageAutoResizeLimit": "0",
    "storageAutoResize": true,
    "dataDiskSizeGb": "10"
  },
  "etag": "etag-id",
  "ipAddresses": [
    {
      "type": "PRIMARY",
      "ipAddress": "10.0.0.1"
    }
  ],
  "serverCaCert": {
    "kind": "sql#sslCert",
    "certSerialNumber": "0",
    "cert": "certificate-id",
    "commonName": "C=US,O=Google\\, Inc,CN=Google Cloud SQL Server CA,dnQualifier=dn-qualifier-id",
    "sha1Fingerprint": "sha-id",
    "instance": "instance-id",
    "createTime": "2019-06-28T22:46:35.052Z",
    "expirationTime": "2029-06-25T22:47:35.052Z"
  },
  "instanceType": "CLOUD_SQL_INSTANCE",
  "project": "project-id",
  "serviceAccountEmailAddress": "service-acct-id@gcp-sa-cloud-sql.iam.gserviceaccount.com",
  "backendType": "SECOND_GEN",
  "selfLink": "https://www.googleapis.com/sql/v1beta4/projects/project-id/instances/instance-id",
  "connectionName": "project-id:region:instance-id",
  "name": "instance-id",
  "region": "asia-east1",
  "gceZone": "asia-east1-a"
}

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

REST v1beta4

The following request uses the instances:patch method to change the availability type on the instance to ZONAL.

Before using any of the request data below, make the following replacements:

  • project-id: The project ID
  • instance-name: The instance name

HTTP method and URL:

PATCH https://www.googleapis.com/sql/v1beta4/projects/project-id/instances/instance-name

Request JSON body:

{
  "settings": {"availabilityType": "ZONAL" }
}

To send your request, expand one of these options:

You should receive a successful status code (2xx) and an empty response.

Updating an instance from legacy to current high availability

To update your instance from the legacy to the new high-availability configuration, do the following:

  1. Delete the failover replica on the MySQL instances you want to update. See Legacy configuration: Disabling high availability on an instance.
  2. Configure the instance to use the current version of high availability. See Configuring an existing instance for high availability.

Troubleshooting

Click the links in the table for details:

For this problem... The issue might be... Try this...
Can't find metrics for manual failover. Only automatic failovers go into the metrics. N/A
CPU and RAM are near 100% usage Instance machine size is too small for the load. Upgrade the instance machine size.

Can't find metrics for manual failover

You performed a manual failover and can't find a corresponding entry in Metrics Explorer in the automatic failover metrics.

The issue might be

Only automatic failovers go into the metrics. Manually initiated failovers do not.

Things to try

N/A


CPU and RAM are near 100% usage

Cloud SQL instance resources (CPU and RAM) are near 100% usage, causing the high availability instance to go down.

The issue might be

The instance machine size is too small for the load.

Things to try

Edit the instance to upgrade to a larger machine size to get more CPUs and memory.

What's next