Re: Fix locking issue with fixed-size stats template in injection_points

From: wenhui qiu <qiuwenhuifx(at)gmail(dot)com>
To: Chao Li <li(dot)evan(dot)chao(at)gmail(dot)com>
Cc: Michael Paquier <michael(at)paquier(dot)xyz>, Postgres hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Fix locking issue with fixed-size stats template in injection_points
Date: 2025-09-29 07:54:39
Message-ID: CAGjGUAKX-q+TKi8eFEG3Nvc2g0GZsXQgZ=P07oy67XOYK0hbiQ@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

HI
This patch looks good to me.

The issue is clear: unlike other fixed-size stats kinds (archiver,
bgwriter, checkpointer), the injection_points stats can be updated
concurrently by multiple backends. Without synchronization, this can lead
to inconsistent changecount state and assertion failures in
pgstat_begin_changecount_write(), as shown in your reproduction.

Thanks

On Mon, Sep 29, 2025 at 3:29 PM Chao Li <li(dot)evan(dot)chao(at)gmail(dot)com> wrote:

>
>
> On Sep 29, 2025, at 14:27, Michael Paquier <michael(at)paquier(dot)xyz> wrote:
>
> On Mon, Sep 29, 2025 at 09:46:05AM +0800, Chao Li wrote:
>
> I saw pg_state_begin_changecount_write() is called multiple places,
> as you mention, for example bgwriter.
>
>
> I've mentioned that in my first email, and put in details:
> - pgstat_report_bgwriter() is called once, by the bgwriter.
> - pgstat_report_checkpointer() is called three time, all by the
> checkpointer.
> - pgstat_report_archiver() is called twice, all by pgarch.c.
>
> So all of them don't have a problem, two calls cannot happen
> concurrently.
> --
> Michael
>
>
> Thanks for the clarification. Then the patch looks good to me.
>
> Best regards,
> --
> Chao Li (Evan)
> HighGo Software Co., Ltd.
> https://www.highgo.com/
>
>
>
>
>

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Michael Paquier 2025-09-29 08:01:37 Re: Fix locking issue with fixed-size stats template in injection_points
Previous Message jian he 2025-09-29 07:42:39 Re: bug, ALTER TABLE call ATPostAlterTypeCleanup twice for the same relation