This page describes how to start an instance, stop an instance, and restart an instance that is running.
Activation policy
When you start, stop, or restart an instance, you need to set an activation policy to use. The activation policy indicates if the instance is activated to accept connection requests.
Activation policy options are:
ALWAYS- The instance is always up and running.NEVER- The instance is not restarted.
ALWAYS. If you
are not using your instance, you can set its activation policy to
NEVER to avoid instance charges.
Start an instance
To start a stopped instance:
Console
-
In the Google Cloud console, go to the Cloud SQL Instances page.
- To open the Overview page of an instance, click the instance name.
- Click Start.
- In the Start database instance? dialog box, click
Start.
The activation policy of the instance is set to Always and the instance is started.
gcloud
Use ALWAYS for the activation policy:
gcloud sql instances patch INSTANCE_NAME \ --activation-policy=always
REST v1
Before using any of the request data, make the following replacements:
- project-id: The project ID
- instance-id: The instance ID
- activation-policy: The activation policy is ALWAYS or NEVER
HTTP method and URL:
PATCH https://sqladmin.googleapis.com/v1/projects/project-id/instances/instance-id
Request JSON body:
{
"settings": {
"activationPolicy": "activation-policy"
}
}
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-20T21:30:35.667Z",
"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
- activation-policy: The activation policy is ALWAYS or NEVER
HTTP method and URL:
PATCH https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id/instances/instance-id
Request JSON body:
{
"settings": {
"activationPolicy": "activation-policy"
}
}
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-20T21:30:35.667Z",
"operationType": "UPDATE",
"name": "operation-id",
"targetId": "instance-id",
"selfLink": "https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id/operations/operation-id",
"targetProject": "project-id"
}
Start and move a stopped instance to a different zone
To move a stopped instance to a different zone in the same region, you must start
the instance and change its zone in the same request. If you attempt to change
the zone without setting the activation policy to ALWAYS, then you can't move
the instance, and the request fails.
To start a stopped instance and move it to a different zone, do the following:
gcloud
To start a stopped instance and change its primary zone, specify both the
--zone and --activation-policy=ALWAYS flags:
gcloud sql instances patch INSTANCE_NAME \ --zone=PRIMARY_ZONE \ --activation-policy=ALWAYS
For a high availability (HA) instance, you can also specify the optional
--secondary-zone flag:
gcloud sql instances patch INSTANCE_NAME \ --zone=PRIMARY_ZONE \ --secondary-zone=SECONDARY_ZONE \ --activation-policy=ALWAYS
Replace the following:
- INSTANCE_NAME: the name of the instance.
- PRIMARY_ZONE: the primary zone where you want to move and start the instance. The zone must be in the same region as the instance.
- SECONDARY_ZONE: Optional: the secondary zone for the instance. The zone must be in the same region as the instance and be different from the primary zone.
REST v1
To start a stopped instance and change its zone, specify both
locationPreference and settings.activationPolicy in the
request body of the
instances.patch
method:
PATCH https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/instances/INSTANCE_NAME { "settings": { "activationPolicy": "ALWAYS", "locationPreference": { "zone": "PRIMARY_ZONE" } } }
For a high availability (HA) instance, you can also specify the optional
secondaryZone field in locationPreference:
PATCH https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/instances/INSTANCE_NAME { "settings": { "activationPolicy": "ALWAYS", "locationPreference": { "zone": "PRIMARY_ZONE", "secondaryZone": "SECONDARY_ZONE" } } }
Replace the following:
- PROJECT_ID: the ID of the Google Cloud project.
- INSTANCE_NAME: the name of the instance.
- PRIMARY_ZONE: the primary zone where you want to move and start the instance. The zone must be in the same region as the instance.
- SECONDARY_ZONE: Optional: the secondary zone for the instance. The zone must be in the same region as the instance and be different from the primary zone.
REST v1beta4
To start a stopped instance and change its zone, specify both
locationPreference and settings.activationPolicy in the
request body of the
instances.patch
method:
PATCH https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID/instances/INSTANCE_NAME { "settings": { "activationPolicy": "ALWAYS", "locationPreference": { "zone": "PRIMARY_ZONE" } } }
For a high availability (HA) instance, you can also specify the optional
secondaryZone field in locationPreference:
PATCH https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID/instances/INSTANCE_NAME { "settings": { "activationPolicy": "ALWAYS", "locationPreference": { "zone": "PRIMARY_ZONE", "secondaryZone": "SECONDARY_ZONE" } } }
Replace the following:
- PROJECT_ID: the ID of the Google Cloud project.
- INSTANCE_NAME: the name of the instance.
- PRIMARY_ZONE: the primary zone where you want to move and start the instance. The zone must be in the same region as the instance.
- SECONDARY_ZONE: Optional: the secondary zone for the instance. The zone must be in the same region as the instance and be different from the primary zone.
Stop an instance
You can manually stop an instance when needed. When you stop an instance, it remains stopped, and does not respond to application connections, until you start it again.
Stopping an instance suspends instance charges. The instance data is unaffected, and charges for storage and IP addresses continue to apply.
To stop an instance:
Console
-
In the Google Cloud console, go to the Cloud SQL Instances page.
- To open the Overview page of an instance, click the instance name.
- Click Stop.
- In the Stop database instance? dialog box, click
Stop.
The activation policy of the instance is set to
Off(Never) and the instance is stopped.
gcloud
gcloud sql instances patch INSTANCE_NAME \ --activation-policy=never
REST v1
Before using any of the request data, make the following replacements:
- project-id: The project ID
- instance-id: The instance ID
- activation-policy: The activation policy is NEVER
HTTP method and URL:
PATCH https://sqladmin.googleapis.com/v1/projects/project-id/instances/instance-id
Request JSON body:
{
"settings": {
"activationPolicy": "activation-policy"
}
}
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-20T21:30:35.667Z",
"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
- activation-policy: The activation policy is NEVER
HTTP method and URL:
PATCH https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id/instances/instance-id
Request JSON body:
{
"settings": {
"activationPolicy": "activation-policy"
}
}
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-20T21:30:35.667Z",
"operationType": "UPDATE",
"name": "operation-id",
"targetId": "instance-id",
"selfLink": "https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id/operations/operation-id",
"targetProject": "project-id"
}
Restart an instance
Restarting an instance drains the connections from the instance and stops it. Next, the instance restarts and is ready to accept new connections.
Restarting an instance doesn't change the public or private IP addresses of the instance.
To restart an instance:
Console
-
In the Google Cloud console, go to the Cloud SQL Instances page.
- To open the Overview page of an instance, click the instance name.
- Click Restart.
- In the Restart database instance? dialog box, click Restart.
gcloud
Restart the instance:
gcloud sql instances restart INSTANCE_NAME
REST v1
Before using any of the request data, make the following replacements:
- project-id: The project ID
- instance-id: The instance ID
- activation-policy: The activation policy is ALWAYS or NEVER
HTTP method and URL:
POST https://sqladmin.googleapis.com/v1/projects/project-id/instances/instance-id/restart
Request JSON body:
{
"settings": {
"activationPolicy": "activation-policy"
}
}
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-20T21:30:35.667Z",
"operationType": "RESTART",
"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
- activation-policy: The activation policy is ALWAYS or NEVER
HTTP method and URL:
POST https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id/instances/instance-id/restart
Request JSON body:
{
"settings": {
"activationPolicy": "activation-policy"
}
}
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-20T21:30:35.667Z",
"operationType": "RESTART",
"name": "operation-id",
"targetId": "instance-id",
"selfLink": "https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id/operations/operation-id",
"targetProject": "project-id"
}