Runbook: TimescaleDB Slow / Down
Symptoms
POST /v1/eventslatency elevated (p99 > 500 ms) or returning 500.GET /readyzon ingest showschecks.postgres: "error".- DB connection pool exhausted — log lines:
ingest.unhandled_errorwithPrismaClientKnownRequestError. - Hypertable chunk creation lagging.
Observe
Metrics: Grafana — http://localhost:3001 (see on-call.md)
Grafana: http://localhost:3001 (see on-call.md)Key panels:
- p50 / p99 Latency — sustained elevation points to DB saturation, not transient spikes.
- Error Rate (5xx) — correlate with DB error logs.
Logs:
docker compose -f docker-compose.infra.yml logs -f postgresbun run docker:app:logs # ingest logs for DB error messagesConnect directly:
docker compose -f docker-compose.infra.yml exec postgres \ psql -U postgres -d ai_agents_observabilityDiagnose
-
Blocking queries?
SELECT pid, wait_event_type, wait_event, query, now() - query_start AS ageFROM pg_stat_activityWHERE state != 'idle'ORDER BY age DESC; -
Lock contention?
SELECT * FROM pg_locks l JOIN pg_stat_activity a ON l.pid = a.pidWHERE NOT l.granted; -
Hypertable chunk maintenance? — TimescaleDB background jobs (compression, retention) can spike I/O. Check
timescaledb_information.job_stats. -
Disk full? — Check volume usage. Retention policy should keep the
eventshypertable bounded. -
OOM? —
docker stats— if Postgres is hitting its memory limit, it may crash + restart.
Mitigate
- Kill a blocking query:
SELECT pg_terminate_backend(<pid>); - Restart Postgres (last resort — will briefly interrupt all services):
docker compose -f docker-compose.infra.yml restart postgres - Ingest events are idempotent (
ON CONFLICT DO NOTHING) — hook CLIs will re-deliver on retry. - If the volume is full, increase storage or run the retention sweep manually.
Escalate
If the DB volume is corrupted or data loss is suspected, escalate immediately to the team lead. See on-call.md.