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.