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.
Manage maintenance on a read replica cluster
You perform self-service maintenance at the instance level. You maintain each instance in a read replica cluster. Before you perform maintenance on the Cloud SQL primary instance, perform self-service maintenance on all read replicas of the instance.
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": "SQLSERVER_2019_STANDARD" }
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": "SQLSERVER_2019_STANDARD" }
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": "SQLSERVER_2019_STANDARD" }
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": "SQLSERVER_2019_STANDARD" }
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.
Apply the changes
To apply your Terraform configuration in a Google Cloud project, complete the steps in the following sections.
Prepare Cloud Shell
- Launch Cloud Shell.
-
Set the default Google Cloud project where you want to apply your Terraform configurations.
You only need to run this command once per project, and you can run it in any directory.
export GOOGLE_CLOUD_PROJECT=PROJECT_ID
Environment variables are overridden if you set explicit values in the Terraform configuration file.
Prepare the directory
Each Terraform configuration file must have its own directory (also called a root module).
-
In Cloud Shell, create a directory and a new
file within that directory. The filename must have the
.tf
extension—for examplemain.tf
. In this tutorial, the file is referred to asmain.tf
.mkdir DIRECTORY && cd DIRECTORY && touch main.tf
-
If you are following a tutorial, you can copy the sample code in each section or step.
Copy the sample code into the newly created
main.tf
.Optionally, copy the code from GitHub. This is recommended when the Terraform snippet is part of an end-to-end solution.
- Review and modify the sample parameters to apply to your environment.
- Save your changes.
-
Initialize Terraform. You only need to do this once per directory.
terraform init
Optionally, to use the latest Google provider version, include the
-upgrade
option:terraform init -upgrade
Apply the changes
-
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.
-
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.
- 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:
- To disable deletion protection, in your Terraform configuration file set the
deletion_protection
argument tofalse
.deletion_protection = "false"
- Apply the updated Terraform configuration by running the following command and
entering
yes
at the prompt:terraform apply
-
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:
PATCH 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:
PATCH 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" }