Re: [BUGS] BUG #10123: Weird entries in pg_stat_activity

From: Andres Freund <andres(at)anarazel(dot)de>
To: Fujii Masao <masao(dot)fujii(at)oss(dot)nttdata(dot)com>
Cc: Fujii Masao <masao(dot)fujii(at)gmail(dot)com>, maxim(dot)boguk(at)gmail(dot)com, pgsql-bugs(at)postgresql(dot)org
Subject: Re: [BUGS] BUG #10123: Weird entries in pg_stat_activity
Date: 2024-07-04 22:03:16
Message-ID: 20240704220316.srzqzkb7zgzh76xy@alap3.anarazel.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

Hi,

On 2024-07-04 14:54:01 +0900, Fujii Masao wrote:
> @@ -515,6 +515,17 @@ ProcessClientReadInterrupt(bool blocked)
> /* Check for general interrupts that arrived before/while reading */
> CHECK_FOR_INTERRUPTS();
>
> + /*
> + * Reset statement_timestamp() to 0 so that ProcessCatchupInterrupt()
> + * and ProcessNotifyInterrupt() will set pg_stat_activity.xact_start
> + * to NULL when they start new transaction. Otherwise, xact_start
> + * could be set to statement_timestamp() that may indicate the
> + * timestamp of the last query executed, while the backend's state
> + * remains "idle," leading to incorrect "idle" entries with non-NULL
> + * xact_start in pg_stat_activity.
> + */
> + ResetCurrentStatementStartTimestamp();
> +
> /* Process sinval catchup interrupts, if any */
> if (catchupInterruptPending)
> ProcessCatchupInterrupt();

This seems odd to me. ProcessClientReadInterrupt() can be called a lot, why do
we need to reset the statement start timestamp even if nothing is happening here?

> @@ -2598,6 +2609,8 @@ exec_describe_statement_message(const char *stmt_name)
> {
> CachedPlanSource *psrc;
>
> + pgstat_report_activity(STATE_RUNNING, NULL);
> +
> /*
> * Start up a transaction command. (Note that this will normally change
> * current memory context.) Nothing happens if we are already in one.
> @@ -2692,6 +2705,8 @@ exec_describe_portal_message(const char *portal_name)
> {
> Portal portal;
>
> + pgstat_report_activity(STATE_RUNNING, NULL);
> +
> /*
> * Start up a transaction command. (Note that this will normally change
> * current memory context.) Nothing happens if we are already in one.

Calls to pgstat_report_activity() aren't exactly free. This substantially
increases the number of calls to it for common workloads. There got to be a
more targeted way of dealing with this.

Greetings,

Andres Freund

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Tender Wang 2024-07-05 02:24:45 Re: BUG #18500: Detaching a partition with an index manually attached to the parent's index triggers Assert
Previous Message Laurenz Albe 2024-07-04 14:18:37 Re: BUG #18529: Can not install as Document