Cloud SQL: too many connections Google Cloud / Firebase Origin: Platform & cloud OSI layer 7 · Application Last updated 4 Nov 2026

Cloud SQL: FATAL: remaining connection slots are reserved / MySQL: ERROR 1040 (08004): Too many connections

The instance's maximum connections was reached, often because serverless instances each open their own connection pool.

Exact message you may see ERROR 1040 (08004): Too many connections Cloud SQLToo many connections Cloud SQLFATAL: sorry, too many clients already Cloud SQL
Seen on: Google Cloud SQL

Meaning

Cloud Run/Functions scale out and each instance opens connections. Set small pools (1-5 per instance), use connection pooling (PgBouncer / managed connection pooling), lower max-instances, and close idle connections. Raise max_connections flag only after sizing memory.

Common causes

  • Many serverless instances each with a pool
  • Pool max size too large
  • Connections never closed/leaked
  • Low max_connections on a small tier
  • Long-running transactions holding slots

⚡ Quick fix

  1. Limit pool size per instance (e.g. 2-5) and instances
  2. Use managed connection pooling or PgBouncer
  3. Increase max_connections and instance size if justified

Detailed fix by platform

gcloud

  1. gcloud sql instances patch INSTANCE --database-flags=max_connections=300

How to diagnose

  1. Count — Connections vs max?
  2. Source — Instances x pool?
  3. Leaks — Idle connections?

🔧 Still not fixed?

Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:

Where this error sits

Origin: Platform & cloud. Errors that are often confused with or caused by this one (click to open):

API has not been used in project before or it is disabled — Google Cloud: 403 SERVICE_DISABLED — Cloud Resource Manager API has not been used in project 123456 before or it is disabled. Enable it by visiting (Google Cloud / Firebase)API has not been used…Artifact Registry: Permission artifactregistry.repositories.uploadArtifacts denied — Docker push: denied: Permission "artifactregistry.repositories.uploadArtifacts" denied on resource "projects/p/locations/l/repositories/r" (Google Cloud / Firebase)Artifact Registry: Pe…BigQuery: Access Denied: Project: User does not have bigquery.jobs.create permission — BigQuery: Access Denied: Project my-project: User does not have bigquery.jobs.create permission in project my-project (Google Cloud / Firebase)BigQuery: Access Deni…BigQuery: Not found: Dataset was not found in location — BigQuery: Not found: Dataset my-project:analytics was not found in location EU (Google Cloud / Firebase)BigQuery: Not found: …Cloud Run 503: The request failed because the instance had an error — Cloud Run: 503 Service Unavailable — The request was aborted because there was no available instance (Google Cloud / Firebase)Cloud Run 503: The re…Cloud SQL: failed to connect to instance — Cloud SQL: failed to connect to `host=PROJECT:REGION:INSTANCE user=app database=db`: dial error (timeout) / Cloud SQL Auth Proxy: failed to connect to instance (Google Cloud / Firebase)Cloud SQL: failed to …Error 403: API has not been used in project (Terraform) — Terraform: Error: Error creating Network: googleapi: Error 403: Compute Engine API has not been used in project 123 before or it is disabled (Terraform)Error 403: API has no…Google provider: could not find default credentials — Terraform: Error: Attempted to load application default credentials since neither `credentials` nor `access_token` was set in the provider block. No credentials loaded (Terraform)Google provider: coul…Cloud SQL…

Explore the map of this error Full error map →

🧠 Still stuck? Analyze your error

Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.

💬 What worked for others

No tips yet — did something else fix this for you?

Share what worked for you

Tips are checked by an editor before they appear. Links are removed.