Interview Prep/AWS/RDS, Aurora and DynamoDB

App logs show `FATAL: remaining connection slots are reserved for non-replication superuser connections` (or MySQL `ERROR 1040 (HY000): Too many connections`).

IntermediateTroubleshootingRDS, Aurora and DynamoDB
Answer

Likely causes → You have hit max_connections. Usually too many app replicas each open a large pool, or Lambda functions open a new connection per invocation, or connections leak.

Diagnose →

aws cloudwatch get-metric-statistics --namespace AWS/RDS --metric-name DatabaseConnections \
  --dimensions Name=DBInstanceIdentifier,Value=mydb --statistics Maximum --period 60 \
  --start-time $(date -u -d '-2 hour' +%FT%TZ) --end-time $(date -u +%FT%TZ)
psql -c "select usename, application_name, state, count(*) from pg_stat_activity group by 1,2,3 order by 4 desc;"

Fix →

  1. Shrink the pool per pod: total = replicas × pool size, which must stay under max_connections
  2. Put RDS Proxy (or PgBouncer) in front for Lambda and bursty clients
  3. Kill idle connections and set idle_in_transaction_session_timeout

Prevent → Budget connections per service, alarm at 80% of max, and use RDS Proxy for serverless callers.

aws All AWS questions Roadmap: AWS core services

More on RDS, Aurora and DynamoDB