# GCP Cloud Spanner Instance Idle

> Flags Spanner instances with zero API requests, whose provisioned compute capacity bills every hour for no work.

Source: https://zop.dev/integrations/gcp/recommendations/gcp-cloud-spanner-instance-idle

---

## Compute capacity is the Spanner bill

Spanner prices compute by what you provision. Google's
[Spanner pricing](https://cloud.google.com/spanner/pricing) says it tracks an instance's compute
capacity in nodes or processing units over time and charges nodes times the hourly rate, which
varies by edition and region. Capacity can be smaller than one node (1,000 processing units), and
any capacity you provision is billed for at least an hour. Storage, backups and replication are
charged on top.

None of that depends on traffic. A proof-of-concept instance left behind after the project moved
on bills exactly what it billed at peak.

## Confirming the instance is unused

```bash
gcloud spanner instances list
```

For each candidate, chart `spanner.googleapis.com/api/request_count` over 30 days in Metrics
Explorer. The metric is a rate of Spanner API requests per second, reported per instance and
database, so a flat zero across every database means nothing is connecting.

## The rule's test

ZopNight reads the instance's API request metric by name and fires only when both the average and
the peak are zero across the data it holds for a 30-day lookback. The instance also has to have a
known monthly cost. The finding carries high severity, and its remedy is deleting the
instance.

## No request data, no finding

Spanner request activity only exists as a Cloud Monitoring series, so there is no fallback
signal. When that series is missing, the rule stays silent rather than treating silence as zero.
Any request at all in the window, even one, also clears the instance, as does an instance that
cannot be priced.

## Saving equals the monthly run-rate

```text
saving = current monthly instance cost
cost after deletion = 0
```

If the instance must stay for a future launch, reducing its compute capacity is the smaller win.

## Deleting an instance safely

1. Confirm with the owners that no service, job or failover plan depends on it.
2. Export databases worth keeping with the
   [Spanner to Cloud Storage Avro](https://cloud.google.com/dataflow/docs/guides/templates/provided/cloud-spanner-to-avro)
   Dataflow template.
3. Turn off deletion protection on any database that has it; Google blocks instance deletion
   until you do.
4. Delete the instance: `gcloud spanner instances delete INSTANCE_ID`.

**Warning**
Deleting a Spanner instance permanently removes it and all its databases. Google notes this cannot be undone.
