Thread: Doc: clarify possibility of ephemeral discrepancies between state and wait_event in pg_stat_activity

Hi,

This small doc change patch is following up on a past discussion about 
discrepancies between state and wait_event in pg_stat_activity:

https://www.postgresql.org/message-id/flat/ab1c0a7d-e789-5ef5-1180-42708ac6fe2d%40postgrespro.ru


As this kind of question is raised by PG users from time to time, the goal is to 
clarify that such discrepancies are to be expected. The attached patch reuses 
Robert Haas's eloquent wording from his response in the above thread. I've tried 
to keep it short and to the point, but it can be made more verbose if needed.


Best regards,

Alex Friedman
Attachment
I am not sure if the wait_event vs state relationship needs to
be documented specifically. I can think of another discrepancy
such as query_id = NULL and state = active, which occurs when
the query  is still being parsed and jumbled and a query_id is not yet
available. There are probably other ephemeral discrepancies
across all these fields.

Another common pattern is joining pg_stat_activity and pg_locks,
and that will have the same problem. Of course, these are different
views being joined, so maybe there isn't an expectation of 100%
accuracy, but worth calling this out as well.

If we do need to document anything, which I am not convinced we should,
it should be more generic.

-- 

Sami Imseih
Amazon Web Services (AWS)



On 26/02/2025 22:00, Sami Imseih wrote:
> If we do need to document anything, which I am not convinced we should,
> it should be more generic.

Thanks for the feedback, I've attached a v2 patch which has wording that's a bit 
more generic.

It's also worth noting that pg_locks already has a full paragraph explaining 
inconsistencies, so in my opinion it's worth it at least mentioning something 
similar here for pg_stat_activity.


Best regards,

Alex Friedman
Attachment