Cloud SQL Auth Proxy Connection Pool Exhaustion: Diagnosing Intermittent Spikes
0 reputation · 30 Jun 2026, 09:25 UTC
0 reputation · 30 Jun 2026, 09:25 UTC
When Cloud SQL instances experience sudden spikes in connection count, the culprit is often the Auth Proxy’s connection‑pool behavior. Version 2.0.0 introduces a --max_connections flag that caps concurrent connections, but omitting it lets the proxy open a new connection per request. Coupled with a hard‑coded 60‑second idle timeout, this can leave orphaned server‑side sessions for up to 30 minutes, pushing the database to its max_connections limit.
Diagnosing these transient exhaustion events is complicated by the lack of a client‑side keep‑alive default. The proxy relies on application‑level keep‑alive, and when omitted, connections may silently drop while the server still counts them.
What instrumentation can reliably detect when idle connections linger on the Cloud SQL side but are closed by the proxy? Should we adjust the proxy’s idle timeout or the server’s wait_timeout to align? Is enabling TCP keep‑alive a viable solution to prevent silent drops?
34775 reputation · 30 Jun 2026, 13:27 UTC
Use Cloud Monitoring’s cloudsql.googleapis.com/instance/connection_count together with SHOW PROCESSLIST (MySQL) or pg_stat_activity (PostgreSQL) to see how many sessions the database actually sees. Compare that with the proxy’s log, which records every CONNECT and DISCONNECT. If the proxy shows a connection closed but the server still lists it, you have orphaned sessions caused by the 60‑second idle timeout. Fix the mismatch by:
--max_connections and --max_pool_size so the proxy re‑uses connections instead of opening a new one for each request.--idle_timeout (or the OS tcp_keepalive_time) with the database’s wait_timeout (MySQL) or idle_in_transaction_session_timeout (PostgreSQL).--keepalive-interval so the TCP layer keeps the socket alive and surfaces silent drops before the server timeout.# MySQL
SHOW PROCESSLIST;
# PostgreSQL
SELECT pid, state, query FROM pg_stat_activity;
cloudsql.googleapis.com/instance/connection_count metric for the instance and look for spikes that persist beyond the 60‑second window.--log_level=info, the log will contain lines like:
2026-10-12T06:00:00Z CONNECT 192.168.1.10:5432
2026-10-12T06:00:30Z DISCONNECT 192.168.1.10:5432
Compare timestamps with the server list to spot orphaned sessions.# In your instance flags
wait_timeout=300
interactive_timeout=300
For PostgreSQL:
# In your instance flags
idle_in_transaction_session_timeout=300000
Set the proxy idle timeout to the same value (e.g., --idle_timeout=300). If you cannot change the server flag, set the proxy idle timeout a bit lower to force early closure.cloud_sql_proxy --keepalive-interval=30s ...
Also set the host OS tcp_keepalive_time to 30s. This sends a keep‑alive packet every 30 seconds, keeping the TCP connection alive and allowing the server to notice a broken socket sooner.connection_count metric. It should now drop back to the baseline within the idle timeout window.To fine‑tune the recommendation, could you confirm which database engine you’re using (MySQL or PostgreSQL)? The exact server‑side timeout flag differs between them.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.