Self-service maintenance

Stay organized with collections Save and categorize content based on your preferences.

This page describes self-service maintenance, which lets you accept a maintenance update on your instance outside of the normal flow of scheduled maintenance.

Overview

Cloud SQL regularly releases software improvements, such as patches for known vulnerabilities, through new maintenance versions. While Cloud SQL schedules maintenance updates once every few months to ensure you have the latest maintenance version, you might want to use self-service maintenance if:

  • You need an update sooner than your next scheduled maintenance event.
  • You want to catch up to the latest maintenance version after skipping your most recent scheduled maintenance event.

You're not required to manually upgrade to the latest version. You can let Cloud SQL automatically upgrade your maintenance version during your next scheduled maintenance event.

Before you begin

Before you perform self-service maintenance, first check your current maintenance version. Then you can determine the target maintenance version you want to upgrade your instance to and upgrade your instance to that version.

Use the following method to see your current maintenance version:

gcloud

Before using the gcloud command below, make the following replacements:

  • INSTANCE_ID: The instance to query
gcloud sql instances describe INSTANCE_ID
  

The maintenance version is indicated beside the maintenanceVersion attribute.

REST v1

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

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

HTTP method and URL:

GET https://sqladmin.googleapis.com/v1/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_8_0"
}

Look for the maintenanceVersion item in the DatabaseInstance section of the response.

REST v1beta4

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

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

HTTP method and URL:

GET https://sqladmin.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_8_0"
}

Look for the maintenanceVersion item in the DatabaseInstance section of the response.

Determine the target maintenance version

Use the following method to view the maintenance versions you can select as your target. Note that you can't upgrade to a version earlier than the current maintenance version.

gcloud

Before using the gcloud command below, make the following replacements:

  • INSTANCE_ID: The instance to query
gcloud sql instances describe INSTANCE_ID
  

The list of available maintenance versions is indicated beside the availableMaintenanceVersions attribute.

REST v1

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

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

HTTP method and URL:

GET https://sqladmin.googleapis.com/v1/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_8_0"
}

Look for the availableMaintenanceVersions item in the DatabaseInstance section of the response.

REST v1beta4

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

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

HTTP method and URL:

GET https://sqladmin.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_8_0"
}

Look for the availableMaintenanceVersions item in the DatabaseInstance section of the response.

Upgrade to the target maintenance version

Use the following method to upgrade your instance to the target maintenance version.

gcloud

Before using the gcloud command below, make the following replacements:

  • INSTANCE_ID: The instance to query
  • MAINTENANCE_VERSION: the maintenance version to apply
gcloud sql instances patch INSTANCE_ID \
--maintenance-version=MAINTENANCE_VERSION
  

Terraform

To create an instance, use a Terraform resource.

resource "google_sql_database_instance" "mysql_ssm_instance_name" {
  name                = "mysql-ssm-instance-name"
  region              = "asia-northeast1"
  database_version    = "MYSQL_5_7"
  maintenance_version = "MYSQL_5_7_38.R20220809.02_00"
  settings {
    tier = "db-f1-micro"
  }
  deletion_protection = false # set to true to prevent destruction of the resource
}

Apply the changes

To apply your Terraform configuration in a Google Cloud project, complete the following steps:

  1. Launch Cloud Shell.
  2. Set the Google Cloud project where you want to apply the Terraform configuration:
    export GOOGLE_CLOUD_PROJECT=PROJECT_ID
    
  3. Create a directory and open a new file in that directory. The filename must have the .tf extension, for example main.tf:
    mkdir DIRECTORY && cd DIRECTORY && nano main.tf
    
  4. Copy the sample into main.tf.
  5. Review and modify the sample parameters to apply to your environment.
  6. Save your changes by pressing Ctrl-x and then y.
  7. Initialize Terraform:
    terraform init
  8. Review the configuration and verify that the resources that Terraform is going to create or update match your expectations:
    terraform plan

    Make corrections to the configuration as necessary.

  9. Apply the Terraform configuration by running the following command and entering yes at the prompt:
    terraform apply

    Wait until Terraform displays the "Apply complete!" message.

  10. Open your Google Cloud project to view the results. In the Google Cloud console, navigate to your resources in the UI to make sure that Terraform has created or updated them.

Delete the changes

To delete your changes, do the following:

  1. To disable deletion protection, in your Terraform configuration file set the deletion_protection argument to false.
    deletion_protection =  "false"
  2. Apply the updated Terraform configuration by running the following command and entering yes at the prompt:
    terraform apply
  1. Remove resources previously applied with your Terraform configuration by running the following command and entering yes at the prompt:

    terraform destroy

REST v1

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

  • project-id: The project ID
  • instance-id: The instance ID
  • maintenance-version: the maintenance version to use

HTTP method and URL:

POST https://sqladmin.googleapis.com/v1/projects/project-id/instances/instance-id

Request JSON body:

{
  "maintenanceVersion": "maintenance-version"
}

To send your request, expand one of these options:

You should receive a JSON response similar to the following:

{
  "kind": "sql#operation",
  "targetLink": "https://sqladmin.googleapis.com/v1/projects/project-id/instances/instance-id",
  "status": "PENDING",
  "user": "user@example.com",
  "insertTime": "2020-01-16T02:32:12.281Z",
  "startTime": "08:00",
  "endTime": "08:01",
  "operationType": UPDATE,
  "name": "operation-id",
  "targetId": "instance-id",
  "selfLink": "https://sqladmin.googleapis.com/v1/projects/project-id/operations/operation-id",
  "targetProject": "project-id"
}

REST v1beta4

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

  • project-id: The project ID
  • instance-id: The instance ID
  • maintenance-version: the maintenance version to use

HTTP method and URL:

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

Request JSON body:

{
  "maintenanceVersion": "maintenance-version"
}

To send your request, expand one of these options:

You should receive a JSON response similar to the following:

{
  "kind": "sql#operation",
  "targetLink": "https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id/instances/instance-id",
  "status": "PENDING",
  "user": "user@example.com",
  "insertTime": "2020-01-16T02:32:12.281Z",
  "startTime": "08:00",
  "endTime": "08:01",
  "operationType": UPDATE,
  "name": "operation-id",
  "targetId": "instance-id",
  "selfLink": "https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id/operations/operation-id",
  "targetProject": "project-id"
}