Starting, stopping, and restarting instances

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.
If you are using a MySQL instance, you generally set your activation policy to ALWAYS to accept connection requests. If you are not using your instance, you can set its activation policy to NEVER to avoid instance charges.

Starting an instance

To start a stopped instance:

Console

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

    Go to the Cloud SQL Instances page

  2. Select an instance to start by clicking the instance name.
  3. Click the Start button, in the button bar at the top of the page.
  4. 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

Before using any of the request data below, 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://www.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://www.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://www.googleapis.com/sql/v1beta4/projects/project-id/operations/operation-id",
  "targetProject": "project-id"
}
To see how the underlying REST API request is constructed for this task, see the APIs Explorer on the instances:patch page.

Stopping 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

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

    Go to the Cloud SQL Instances page

  2. Select an instance to stop by clicking the instance name.
  3. Click the Stop button, in the button bar at the top of the page.
  4. 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

Before using any of the request data below, 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://www.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://www.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://www.googleapis.com/sql/v1beta4/projects/project-id/operations/operation-id",
  "targetProject": "project-id"
}
To see how the underlying REST API request is constructed for this task, see the APIs Explorer on the instances:patch page.

Restarting an instance

Restarting an instance drains the connections from the instance and stops it. Next, instances with an activation policy of Always restart and are ready to accept new connections.

To restart an instance:

Console

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

    Go to the Cloud SQL Instances page

  2. Select an instance to restart by clicking the instance name.
  3. Click the Restart button, in the button bar at the top of the page.
  4. In the Restart database instance dialog box, click Restart.

gcloud

Restart the instance:

gcloud sql instances restart [INSTANCE_NAME]

REST

Before using any of the request data below, 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://www.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://www.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://www.googleapis.com/sql/v1beta4/projects/project-id/operations/operation-id",
  "targetProject": "project-id"
}
To see how the underlying REST API request is constructed for this task, see the APIs Explorer on the instances:restart page.