GCP

RESOURCE_EXHAUSTED - Resource Exhausted: Quota or Capacity Limit Reached

RESOURCE_EXHAUSTED hits when you've maxed out quotas (project or regional limits), hit a temporary capacity stockout in that zone, or exhausted disk space. This can be client-side (you've used all your quota) or server-side (GCP temporarily lacks capacity). Most common in Compute Engine when you've hit VM instance quotas, disk quotas, or regional capacity limits, but also appears in Cloud SQL instance and storage quotas, GKE cluster and node quotas, and BigQuery query and storage quotas. Regional stockouts are transient—try different zones or retry later. Quota exhaustion is persistent until you free resources or request increases.

#Common Causes

  • Project Quota Reached: You've exceeded the maximum allowed quota for a resource type (e.g., VM instances, disks, Cloud SQL instances, GKE clusters). Quotas are enforced per project and per region. This is persistent—you must free quota or request an increase.
  • Regional Capacity Unavailable (Stockout): GCP doesn't have physical resources available in that zone or region temporarily. This is transient—try a different zone or region, or retry later.
  • Disk Space Exhausted: The storage system is out of space. For Compute Engine, this affects disk creation and snapshots. For Cloud SQL, this affects database storage. This is persistent—you must free up space or increase capacity.
  • API Rate Limit Exceeded: You've exceeded the rate limit or quota for API requests. Rate limits are enforced per API and per project. This is transient—wait and retry with rate limiting.

Solutions

  1. 1Step 1: Diagnose - Check quota usage to see which quota is exhausted: gcloud compute project-info describe --project PROJECT_ID --format="table(quotas.metric,quotas.limit,quotas.usage)"
  2. 2Step 2: Diagnose - Check specific quota (e.g., VM instances): gcloud compute project-info describe --project PROJECT_ID --format="get(quotas[metric=INSTANCES].limit,quotas[metric=INSTANCES].usage)"
  3. 3Step 3: Fix - Free quota by deleting unused resources: gcloud compute instances list --filter="status:TERMINATED" --format="value(name,zone)" | while read name zone; do gcloud compute instances delete $name --zone $zone --quiet; done
  4. 4Step 4: Fix - If quota is fine, try a different zone or region (for stockout issues): gcloud compute zones list Then retry creation in a different zone.
  5. 5Step 5: Fix - For disk space exhaustion, delete unused disks or snapshots: gcloud compute disks list --filter="status:UNATTACHED"
  6. 6Step 6: Fix - Request quota increase via Cloud Console: IAM & Admin > Quotas (note: requires approval, not immediate).

</>Code Examples

Quota Diagnosis and Resource Cleanup
1# This script helps diagnose and fix RESOURCE_EXHAUSTED errors
2
3PROJECT_ID="my-project"
4
5# Step 1: Check all quota usage
6echo "Checking quota usage..."
7gcloud compute project-info describe \
8  --project $PROJECT_ID \
9  --format="table(quotas.metric,quotas.limit,quotas.usage)"
10
11# Step 2: Check specific quota (example: VM instances)
12echo "Checking VM instances quota..."
13gcloud compute project-info describe \
14  --project $PROJECT_ID \
15  --format="get(quotas[metric=INSTANCES].limit,quotas[metric=INSTANCES].usage)" | \
16  jq -r '.quotas[] | select(.metric == "INSTANCES") | "Limit: \(.limit), Usage: \(.usage)"'
17
18# Step 3: List and delete unused resources to free quota
19echo "Checking for terminated instances..."
20TERMINATED_INSTANCES=$(gcloud compute instances list \
21  --filter="status:TERMINATED" \
22  --format="value(name,zone)" \
23  --project $PROJECT_ID)
24
25if [ ! -z "$TERMINATED_INSTANCES" ]; then
26  echo "Found terminated instances. Deleting to free quota..."
27  echo "$TERMINATED_INSTANCES" | while read name zone; do
28    echo "Deleting instance $name in zone $zone..."
29    gcloud compute instances delete $name --zone $zone --quiet --project $PROJECT_ID
30  done
31else
32  echo "No terminated instances found"
33fi
34
35# Step 4: Check disk usage
36echo "Checking disk usage..."
37gcloud compute disks list \
38  --format="table(name,sizeGb,status)" \
39  --project $PROJECT_ID
40
41# Step 5: List unattached disks (can be deleted to free quota)
42echo "Checking for unattached disks..."
43UNATTACHED_DISKS=$(gcloud compute disks list \
44  --filter="status:UNATTACHED" \
45  --format="value(name,zone)" \
46  --project $PROJECT_ID)
47
48if [ ! -z "$UNATTACHED_DISKS" ]; then
49  echo "Found unattached disks:"
50  echo "$UNATTACHED_DISKS"
51  # Uncomment to delete unattached disks:
52  # echo "$UNATTACHED_DISKS" | while read name zone; do
53  #   gcloud compute disks delete $name --zone $zone --quiet --project $PROJECT_ID
54  # done
55fi
56
57# Step 6: If quota is fine, try different zones (for stockout)
58echo "Listing available zones..."
59gcloud compute zones list --format="table(name,status)"

Related Errors

Provider Information

This error code is specific to GCP services. For more information, refer to the official GCP documentation.

RESOURCE_EXHAUSTED - Resource Exhausted: Quota or Capacity Limit Reached | GCP Error Reference | Error Code Reference