This page describes how to delete Cloud SQL instances.
Note the following when you plan to delete an instance:
- You cannot delete an instance that has any replicas. You must delete all replicas first.
- After you delete an instance, it might continue to appear in your project with an "unknown" size but with a "Being deleted" status. This is normal and the instance disappears completely after a brief period of time.
- It can take up to a week for the underlying resources related to an instance to be completely deleted, with the exception of read replicas, which are often deleted within a few minutes.
- The deleted instance name can be reused immediately to create a new instance.
- If deletion protection is enabled on an instance, you must disable it before deleting the instance.
- In case of contingencies, take a final backup to restore the deleted instance.
Required permissions
By default, only user or service accounts with the
Cloud SQL Admin
(roles/cloudsql.admin
)
or Owner
(roles/owner
) role have the permission to delete a
Cloud SQL instance (cloudsql.instances.delete
).
You can also define an IAM custom role
for the user or service account that includes the cloudsql.instances.delete
permission. This permission is
supported in
IAM custom roles.
Delete an instance
You can delete a Cloud SQL instance by using the Google Cloud console, gcloud CLI, or the API.
-
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 Delete.
- In the Delete instance dialog, complete the following actions:
- In the text field, enter the instance ID that appears.
If you want to take a final backup of the instance, leave the Take a final backup checkbox selected, expand the Retention options menu, and then, in the Retain for field, enter the number of days to retain the final backup. You can specify from 1 to 365 days.
If you want to delete the instance without taking a final backup, then clear the checkbox.
- In the Describe this backup text area, you can provide a description of the backup.
- Click Delete.
To delete an instance, use the gcloud sql instances delete
command:
gcloud sql instances deleteINSTANCE_NAME \ --project=PROJECT_ID
Make the following replacements:
- INSTANCE_NAME: the name of the instance
- PROJECT_ID: the ID or project number of the Google Cloud project that contains the instance that you want to delete
Before using any of the request data, make the following replacements:
- PROJECT_ID: the ID or project number of the Google Cloud project that contains the instance that you want to delete
- INSTANCE_NAME: the name of the instance
HTTP method and URL:
DELETE https://sqladmin.googleapis.com/v1/projects/PROJECT_ID /instances/INSTANCE_NAME
To send your request, expand one of these options:
curl (Linux, macOS, or Cloud Shell)
Execute the following command:
curl -X DELETE \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
"https://sqladmin.googleapis.com/v1/projects/PROJECT_ID /instances/INSTANCE_NAME "
PowerShell (Windows)
Execute the following command:
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }
Invoke-WebRequest `
-Method DELETE `
-Headers $headers `
-Uri "https://sqladmin.googleapis.com/v1/projects/PROJECT_ID /instances/INSTANCE_NAME " | Select-Object -Expand Content
You should receive a JSON response similar to the following:
{ "kind": "sql#operation", "targetLink": "https://sqladmin.googleapis.com/v1/projects/PROJECT_ID /instances/INSTANCE_NAME ", "status": "PENDING", "user": "user@example.com", "insertTime": "2020-01-15T00:10:22.078Z", "operationType": "DELETE", "name": "OPERATION_ID ", "targetId": "INSTANCE_NAME ", "selfLink": "https://sqladmin.googleapis.com/v1/projects/PROJECT_ID /operations/OPERATION_ID ", "targetProject": "PROJECT_ID " }
Before using any of the request data, make the following replacements:
- PROJECT_ID: the ID or project number of the Google Cloud project that contains the instance that you want to delete
- INSTANCE_NAME: the name of the instance
HTTP method and URL:
DELETE https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID /instances/INSTANCE_NAME
To send your request, expand one of these options:
curl (Linux, macOS, or Cloud Shell)
Execute the following command:
curl -X DELETE \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
"https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID /instances/INSTANCE_NAME "
PowerShell (Windows)
Execute the following command:
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }
Invoke-WebRequest `
-Method DELETE `
-Headers $headers `
-Uri "https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID /instances/INSTANCE_NAME " | Select-Object -Expand Content
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_NAME ", "status": "PENDING", "user": "user@example.com", "insertTime": "2020-01-15T00:10:22.078Z", "operationType": "DELETE", "name": "OPERATION_ID ", "targetId": "INSTANCE_NAME ", "selfLink": "https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID /operations/OPERATION_ID ", "targetProject": "PROJECT_ID " }
Restore a deleted instance
When you delete an instance, Cloud SQL deletes all resources for the instance, including on-demand backups and automated backups.
If you take a final backup as part of deleting an instance, then you can use this backup to recover the instance, either by creating an instance from the final backup or by restoring the final backup to an existing instance.
If you use a final backup to recover your instance, then your instance might have a different IP address from the original, deleted instance.
If you delete an instance accidentally without taking a final backup, then you can request to recover the instance by contacting Cloud Customer Care within 4 days from the time that the instance is deleted. If the instance can be recovered, then the instance configuration, including IP addresses used before the deletion, are restored. All backups available at the time of deletion are also recovered.