public inbox for [email protected]
help / color / mirror / Atom feedFrom: Tom Lane <[email protected]>
To: Dominique Devienne <[email protected]>
Cc: [email protected]
Subject: Re: is pg_stat_activity "transactional"? How fast does it update?
Date: Tue, 10 Jun 2025 10:27:57 -0400
Message-ID: <[email protected]> (raw)
In-Reply-To: <CAFCRh-8WDkn2N+s43fofR4eKHcJC8fiotqWqSGkDQ4Sh4ZYwDg@mail.gmail.com>
References: <CAFCRh-8WDkn2N+s43fofR4eKHcJC8fiotqWqSGkDQ4Sh4ZYwDg@mail.gmail.com>
Dominique Devienne <[email protected]> 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().
regards, tom lane
view thread (4+ messages) latest in thread
reply
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: [email protected]
Cc: [email protected], [email protected], [email protected]
Subject: Re: is pg_stat_activity "transactional"? How fast does it update?
In-Reply-To: <[email protected]>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox