The site returns errors after a deploy
Checkout fails right after a rolling release
Troubleshooting, Medium
8 instances run behind a load balancer. A rolling deploy finished at 10:00. At 10:10 you are on call: errors are 25% (was 0.1%). You know:
- The errors began at 10:02. They are HTTP 500 on POST /checkout only (25% of requests). Other pages use a replica and work.
- Every instance logs FATAL: remaining connection slots are reserved for non-replication superuser connections.
- The release raised the database pool from 10 to 30 connections per instance. The database allows 200 in total. Other services use about 40.
List your first 15 minutes in order, with reason and command. Then name the cause, the proof, and how you prevent a repeat.
Examples
git diff v1.41..v1.42 --stat, or the release notesSELECT usename, count(*) FROM pg_stat_activity GROUP BY usename; on the primary, next to SHOW max_connections;Constraints
- 8 instances. The rolling deploy finished at 10:00 and the errors started at 10:02.
- Only POST /checkout fails (HTTP 500). It is about 25% of requests and customers cannot pay.
- The database allows 200 connections. Other services use about 40. The new release raised the pool size per instance.
- You can roll back the release and read the database. Do not restart the database.
Your answer must contain
- Who you tell, and the first step that protects customers, then the rest of the first 15 minutes in order with a reason each
- The commands or dashboards you use
- The cause, tied to the facts above, and how you confirm it
- How you stop it coming back
A strong answer covers A strong answer rolls back before it digs, confirms recovery with a metric, ties 8 x 30 plus 40 connections to the limit of 200, and adds a pool limit, a pooler and a canary.
Hints
Try the problem first. Open one hint at a time.
Hint 1 a nudge
Customers cannot pay, and the errors began two minutes after the release. What is the quickest safe step before you know the cause?
Hint 2 the approach
Read the log line. The database has no free slots. Add up what the instances now ask for and what other services use, and compare it with the limit.
Hint 3 the key step
After the rollback, confirm recovery with the error rate and the connection count. Then fix the pool size and add checks so a release cannot take all the slots again.
Walkthrough
Full walkthrough brute force to best
First minutes, in order
The first minutes, in order. 0 to 2 minutes: tell the incident channel that you are on call, the impact (25 percent of requests, checkout only) and the time line. 2 to 5 minutes: roll back to the previous release, for example with kubectl rollout undo deployment/web or your deploy tool. Mitigate before you diagnose, because a rollback is quick and safe and the release is already the likely cause. 5 to 8 minutes: confirm recovery with the error rate, the checkout success rate and the database connection count. Do not call it done until they stay normal for several minutes.
Narrow down the cause
8 to 15 minutes: find the cause while users are safe. The log says the database has no free slots. Add up the demand: 8 instances x 30 connections is 240, more than the 200 allowed, and other services hold about 40. Even the old pool used 8 x 10 + 40 = 120. Only checkout fails because it needs the primary database for a write, while other pages read from a replica.
Cause and fix
Cause: the release raised the pool from 10 to 30 connections per instance. Eight instances now want 240 connections, but the database allows 200 and other services already hold about 40. New connections are refused, so every request that needs the primary database fails with HTTP 500. Fix after the incident: set the pool so that instances times pool plus other services stays under about 80 percent of the maximum, put a pooler such as PgBouncer in front of the database, and write a short review with the time line and an owner for each action. A smaller pool set by config is also acceptable if it is faster than a rollback, but only after the impact has stopped.
Read the evidence
Read the evidence in order. The error log names the connection slots. The count of connections by user shows web_app 160, billing 25 and reports 15, which is 200 of 200. The CPU and memory dashboard shows about 30 percent CPU and no restarts, so the instances are healthy. After the rollback the pools return to 10 per instance, the connection total falls to about 120, and the error rate goes back to 0.1 percent.
Commands
kubectl rollout undo deployment/web
kubectl rollout status deployment/web
SELECT usename, count(*) FROM pg_stat_activity GROUP BY usename;
SHOW max_connections;
git diff v1.41..v1.42 --statConfirm and prevent
Prevention: alert at 80 percent of connection use. Check the pool setting against the connection budget before every release. Roll out one instance first and watch connections. Keep a connection budget for each service.
Common mistakes
- Reading code or the whole log before any mitigation. Customers keep failing meanwhile.
- Restarting instances at random. Each restart opens more connections.
- Raising the connection limit as the only fix, with no memory check and no pool limit.
- Declaring the incident over with no metric that shows recovery.