Re: Fixes a clip bug in pg_stat_get_backend_activity()

From: Michael Paquier <michael(at)paquier(dot)xyz>
To: Chao Li <li(dot)evan(dot)chao(at)gmail(dot)com>
Cc: Postgres hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Fixes a clip bug in pg_stat_get_backend_activity()
Date: 2025-12-26 05:59:33
Message-ID: aU4kRTw293ucEBVh@paquier.xyz
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Fri, Dec 26, 2025 at 11:54:38AM +0800, Chao Li wrote:
> This is an eyeball caught bug:
> ```
> clipped_activity = pgstat_clip_activity(activity);
> ret = cstring_to_text(activity); <== bug here: should use clipped_activity
> pfree(clipped_activity);
>
> PG_RETURN_TEXT_P(ret);
> ```
> clipped result is stored in clipped_activity, but it's not used.

Ohh.... Oops. Nice catch.

> This should be an edge case bug. It would only be triggered by using
> multi-byte characters in SQL and the SQL statement length
> exceeds track_activity_query_size, and a multi-byte character just across
> the boundary and gets truncated in the middle.

Yep, that seems wrong since 54b6cd589ac2, meaning a backpatch all the
way down. pg_stat_get_backend_activity() is a less popular solution
than pg_stat_activity, so this would unlikely be hit, still wrong it
is.
--
Michael

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message zengman 2025-12-26 06:28:53 Re: Regression with large XML data input
Previous Message Michael Paquier 2025-12-26 05:45:13 Re: Sequence Access Methods, round two