Cookbook recipe

Sessions being killed or abandoned — connection health alert

Applies to PostgreSQL 13–17 Last reviewed Nov 2025 Grounded in source
Estimated investigation4 min

Scenario

PostgreSQL 14+ reports session lifecycle counters in pg_stat_database — rising sessions_killed or sessions_abandoned values indicate connection health problems worth investigating. Diagnose it Requires PostgreSQL 14+ (sessions_* columns added in PG14): SELECT datname, sessions, sessions_abandoned, -- client…

Investigation Path

PostgreSQL 14+ reports session lifecycle counters in pg_stat_database — rising sessions_killed or sessions_abandoned values indicate connection health problems worth investigating.

Diagnose it

Requires PostgreSQL 14+ (sessions_* columns added in PG14):

SELECT datname,
       sessions,
       sessions_abandoned,   -- client disconnected without clean exit
       sessions_fatal,       -- server error caused session to end
       sessions_killed,      -- terminated by pg_terminate_backend or timeout
       xact_commit,
       xact_rollback
FROM pg_stat_database
WHERE datname NOT IN ('template0', 'template1')
ORDER BY sessions_killed + sessions_abandoned DESC;

Why it happens

sessions_killed counts connections ended by pg_terminate_backend(),
idle_in_transaction_session_timeout, or authentication_timeout.
sessions_abandoned counts connections where the client disconnected without
sending a proper termination (network failure, process crash, or an abrupt container restart).
sessions_fatal indicates the server itself encountered an error that forced the
session to end — these are the most serious and worth checking the PostgreSQL log for.

This is a Pro lesson

Get every Learning Pathway and cookbook recipe — grounded in PostgreSQL source code, with diagnostics, fixes, and prevention for each topic.

Continue this lesson to learn:

  • How to fix it
  • Prevent it next time
  • Related & next steps
  • All 36 Learning Pathway lessons
  • 170+ cookbook recipes
  • Source-grounded diagnostics & fixes

Secure checkout Cancel anytime Source-grounded

Career Impact

This scenario builds production judgment and operational confidence under pressure.

Open Career Dashboard →

Keep going

Related & next steps

Was this helpful?

← All cookbook recipes