Learning center

Writes from Cloud Run fail: is the Cloud SQL disk full?

Read the instance's disk utilization and its automatic storage increase settings before blaming the latest revision. A disk that is nearly full with automatic increases off, or held at their limit, makes writes fail, and Cloud SQL then stops the instance.

How a full disk shows up#

A full disk does not announce itself as a connection problem at first. PostgreSQL's documentation says a filled data disk does not corrupt data but can prevent useful activity, and that a full disk under the write-ahead log can make the server panic and shut down. PostgreSQL's error code for the condition is SQLSTATE 53100 (disk_full), and the driver reports it as a query error on a connection that otherwise works. Disk full failure · PostgreSQL error codes

Which requests fail follows from which statements need space. Inserts, updates and anything that writes the log fail; a query that reads existing rows and fits in memory may still return. Writes failing while reads succeed therefore points at the disk. PostgreSQL does not promise that reads keep working, and queries that spill to temporary files need space too, so treat the pattern as a lead to check, not a test.

The second phase is a full outage. When an instance is nearly out of storage, Cloud SQL stops it to prevent the loss of information, and the console shows a banner suggesting more storage and automatic increases. If the instance runs out of space entirely, it goes offline and existing connections drop. From that point every connection fails, at stage 1 or stage 4 of the hub's stage table, and the guide to a stopped or suspended instance applies too. Stop an instance · --storage-auto-increase

Check 1: how full is the disk, and can it grow?#

Read the storage settings and the out-of-disk report:

gcloud sql instances describe INSTANCE --project PROJECT \
  --format='yaml(state, settings.dataDiskSizeGb, settings.storageAutoResize, settings.storageAutoResizeLimit, outOfDiskReport)'
FieldMeaning
settings.storageAutoResizeWhether automatic storage increases are on. The default is true
settings.storageAutoResizeLimitThe size, in GB, the disk may grow to. 0 means no limit
settings.dataDiskSizeGbThe current provisioned size
outOfDiskReport.sqlOutOfDiskStateNORMAL, or SOFT_SHUTDOWN when the data disk is almost used up and the instance was shut down to prevent data corruption

Instance resource

With automatic increases on, Cloud SQL checks available storage every 30 seconds and adds capacity when it falls below a threshold. For SSD and HDD storage the threshold is MIN(5 + provisioned GB / 25, 25) GB, rounded down, and each increase adds that same amount. Increases stop at the limit, and for Hyperdisk Balanced, increases that come too often within four hours can be throttled, so an instance can run out of space with the setting on and the size below the limit. Automatic storage increases

Automatic increases are recorded as System Event audit entries with the method cloudsql.instances.automaticStorageIncrease, which Cloud SQL always writes, so an empty result for the hours before the errors means the disk did not grow. Cloud SQL system events

Then read the metrics over the incident window in Metrics Explorer, resource type Cloud SQL Database:

MetricWhat it shows
database/disk/utilizationThe fraction of the disk quota in use
database/disk/bytes_used and database/disk/quotaBytes used and the maximum data disk size
database/disk/bytes_used_by_data_typeUsage split into data, WAL, temporary data and other types

All are sampled every 60 seconds and can take up to 165 seconds to appear. Cloud SQL metrics · Disk usage by data type

Disk utilizationAutomatic increaseReading
Near 1.0Off, or the size equals the limitStorage. The disk cannot grow, and writes fail until someone adds space
Near 1.0On, below the limitGrowth outran the increases. Find the data type that grew: WAL, temporary data or tables
Well below 1.0AnyNot storage. Read the error's stage again

Check 2: does the growth line up with the deploy?#

A full disk is a shared condition: every revision's writes fail. The deploy matters only if the new revision is what filled it. Compare the slope of database/disk/bytes_used_by_data_type before and after the revision took traffic. A new revision that writes far more rows, keeps a long transaction open so that WAL accumulates, or runs queries that spill to temporary files changes the slope at the moment its instances start. A slope that was steady for days and simply reached the ceiling has nothing to do with the deploy. Find when the revision started serving

A worked fixture: same error rate, two databases#

The fixture is illustrative. orders-db has 100 GB of SSD storage. orders-api-00018 took all traffic at 10:02:00 UTC; at 10:20 order creation starts failing while order lookups keep working.

Database A. The description:

outOfDiskReport:
  sqlOutOfDiskState: NORMAL
settings:
  dataDiskSizeGb: '100'
  storageAutoResize: true
  storageAutoResizeLimit: '100'
state: RUNNABLE

Automatic increases are on, but the limit equals the current size, so the disk cannot grow. The SSD threshold for 100 GB is MIN(5 + 100/25, 25) = 9 GB; below 9 GB free, Cloud SQL would have added storage if the limit allowed it. database/disk/utilization rose from 0.89 at 09:00 to 0.998 at 10:19, under 0.2 GB free on 100 GB. The INSERT errors carry SQLSTATE 53100, from both orders-api-00018 and a fresh orders-api-00017 instance started through its tag. The deploy did not cause this. Raising the size or the limit is a change to the instance that someone with that authority must make, and soon: an instance this close to full can be stopped.

Database B. Same symptom, different readings. storageAutoResizeLimit is 0 and utilization is 0.64. The failing writes return SQLSTATE 53300 (too_many_connections) on new connections, not 53100, and only order creation opens a new connection per request in orders-api-00018. The disk is not involved; this is a connection budget problem the new revision introduced.

Where the checks mislead#

database/disk/bytes_used does not include the space the file system keeps for its own metadata, which on large disks is 1% to 3% of the total. Utilization can read a little lower than the space PostgreSQL can actually use, and automatic increases can start before the metric reaches the threshold. Considerations for large disks

A disk can cause trouble before it is full. PostgreSQL's documentation warns that some file systems perform badly when they are almost full, so slow writes in the last few percent are not proof of a code change. Look for 53100 in the PostgreSQL log, cloudsql.googleapis.com/postgres.log, before reading latency. Disk full failure · View Cloud SQL logs

Automatic increases are permanent; the provisioned size does not shrink by itself. A limit set to cap that cost is one reason a disk cannot grow during an incident. It is a setting someone chose, so read who set it in the Admin Activity audit log before changing it. Automatic storage increases · Cloud SQL audit logging

Questions#

What happens when a Cloud SQL instance runs out of storage?

When it is nearly out of storage, Cloud SQL stops it to prevent the loss of information. If it runs out entirely, it goes offline and drops existing connections. Before that, statements that need new space can fail with SQLSTATE 53100 (disk_full).

Why did automatic storage increase not prevent a full disk?

The setting may be off, the increase limit may equal the current size, or growth may have outrun the increases. Cloud SQL checks every 30 seconds and adds a fixed amount each time, and on Hyperdisk Balanced frequent increases within four hours can be throttled.

Which metric shows Cloud SQL disk usage?

database/disk/utilization gives the fraction of the disk quota in use. database/disk/bytes_used_by_data_type shows whether data, WAL or temporary files are growing.

One month of free code review.

New organizations get one calendar month of hosted code review for private and public GitHub repositories. No card or cloud connection required. Eligibility and fair-use terms.

Start free with GitHub

Related reading