On Tue, Jun 10, 2025 at 4:27 PM Tom Lane <t...@sss.pgh.pa.us> wrote: > Dominique Devienne <ddevie...@gmail.com> writes: > > So when and how fast does pg_stat_activity update, in the face of a > > PQfinish? > > The shared state underlying pg_stat_activity is updated > immediately when something changes. However ... > > PQfinish is asynchronous: it sends a "goodbye" message and then > closes the connection without waiting for a response. So > depending on system load, the associated backend could still be > alive for some milliseconds. There might be other client > libraries that do that differently. > > Another thing that might be biting you is that a backend inspecting > pg_stat_activity() takes a snapshot of the view's contents and then > holds onto that snapshot until end of transaction. You can get > around that with pg_stat_clear_snapshot().
Many thanks Tom. Didn't know either of those facts. --DD