From: | Bertrand Drouvot <bertranddrouvot(dot)pg(at)gmail(dot)com> |
---|---|
To: | Nazir Bilal Yavuz <byavuz81(at)gmail(dot)com> |
Cc: | Michael Paquier <michael(at)paquier(dot)xyz>, Alvaro Herrera <alvherre(at)alvh(dot)no-ip(dot)org>, Kyotaro Horiguchi <horikyota(dot)ntt(at)gmail(dot)com>, pgsql-hackers(at)lists(dot)postgresql(dot)org |
Subject: | Re: per backend I/O statistics |
Date: | 2025-01-15 08:30:20 |
Message-ID: | Z4dyHHxGfGK7bGjd@ip-10-97-1-34.eu-west-3.compute.internal |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
Hi,
On Wed, Jan 15, 2025 at 11:03:54AM +0300, Nazir Bilal Yavuz wrote:
> Hi,
>
> On Thu, 19 Dec 2024 at 07:22, Michael Paquier <michael(at)paquier(dot)xyz> wrote:
> >
> > Fixed that, bumped the two version counters, and done.
>
> I encountered a problem while trying to add WAL stats to pg_stat_io
> and I wanted to hear your thoughts.
>
> Right now, pgstat_prep_backend_pending() is called in both
> pgstat_count_io_op() and pgstat_count_io_op_time() to create a local
> PgStat_BackendPending entry. In that process,
> pgstat_prep_pending_entry() -> MemoryContextAllocZero() is called. The
> problem is that MemoryContextAllocZero() can not be called in the
> critical sections.
>
> For example, here is what happens in the walsender backend:
>
> '''
> ... ->
> exec_replication_command() ->
> SendBaseBackup() ->
> ... ->
> XLogInsertRecord() ->
> START_CRIT_SECTION() /* Now we are in the critical section */ ->
> ... ->
> XLogWrite() ->
> pgstat_count_io_op_time() for the pg_pwrite() IO ->
> pgstat_prep_backend_pending() ->
> pgstat_prep_pending_entry() ->
> MemoryContextAllocZero() ->
> Failed at Assert("CritSectionCount == 0 || (context)->allowInCritSection")
> '''
>
> With this commit it may not be possible to count IOs in the critical
> sections. I think the problem happens only if the local
> PgStat_BackendPending entry is being created for the first time for
> this backend in the critical section.
Yeah, I encountered the exact same thing and mentioned it in [1] (see R1.).
In [1] I did propose to use a new PendingBackendWalStats variable to "bypass" the
pgstat_prep_backend_pending() usage.
Michael mentioned in [2] that is not really consistent with the rest (what I
agree with) and that "we should rethink a bit the way pending entries are
retrieved". I did not think about it yet but that might be the way to
go, thoughts?
[1]: https://www.postgresql.org/message-id/Z3zqc4o09dM/Ezyz%40ip-10-97-1-34.eu-west-3.compute.internal
[2]: https://www.postgresql.org/message-id/Z4dRlNuhSQ3hPPv2%40paquier.xyz
Regards,
--
Bertrand Drouvot
PostgreSQL Contributors Team
RDS Open Source Databases
Amazon Web Services: https://aws.amazon.com
From | Date | Subject | |
---|---|---|---|
Next Message | Bertrand Drouvot | 2025-01-15 08:38:33 | Re: Reorder shutdown sequence, to flush pgstats later |
Previous Message | Robins Tharakan | 2025-01-15 08:29:00 | Re: Several buildfarm animals fail tests because of shared memory error |