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.
ERROR 1040 (08004): Too many connections Cloud SQLToo many connections Cloud SQLFATAL: sorry, too many clients already 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
- Limit pool size per instance (e.g. 2-5) and instances
- Use managed connection pooling or PgBouncer
- Increase
max_connectionsand instance size if justified
Detailed fix by platform
gcloud
gcloud sql instances patch INSTANCE --database-flags=max_connections=300
How to diagnose
- Count — Connections vs max?
- Source — Instances x pool?
- 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:
Similar errors
- 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
- Artifact Registry: Permission artifactregistry.repositories.uploadArtifacts denied Docker push: denied: Permission "artifactregistry.repositories.uploadArtifacts" denied on resource "projects/p/locations/l/repositories/r"
- 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
Most viewed in Google Cloud / Firebase
- Missing or insufficient permissions Firestore: FirebaseError: [code=permission-denied]: Missing or insufficient permissions
- Container failed to start Cloud Run: The user-provided container failed to start and listen on the port defined provided by the PORT=8080 environment variable
- Could not load the default credentials Google Cloud: Error: Could not load the default credentials. Browse to https://cloud.google.com/docs/authentication/getting-started
Other ways to find it
Where this error sits
Origin: Platform & cloud. Errors that are often confused with or caused by this one (click to open):
🧠 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.
Report a correction or suggest an improvement
Last updated 4 Nov 2026