Re: per backend WAL statistics

From: Bertrand Drouvot <bertranddrouvot(dot)pg(at)gmail(dot)com>
To: Michael Paquier <michael(at)paquier(dot)xyz>
Cc: pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Re: per backend WAL statistics
Date: 2025-01-08 11:11:59
Message-ID: Z35dfx9oc2u+F5VX@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 08, 2025 at 03:21:26PM +0900, Michael Paquier wrote:
> On Tue, Jan 07, 2025 at 08:48:51AM +0000, Bertrand Drouvot wrote:
> > Now that commit 9aea73fc61 added backend-level statistics to pgstats (and
> > per backend IO statistics), we can more easily add per backend statistics.
> >
> > Please find attached a patch to implement $SUBJECT.
>
> I've looked at v1-0002 and v1-0001.

Thanks for looking at it!

> +static void
> +pgstat_flush_io_entry(PgStat_EntryRef *entry_ref, bool nowait, bool need_lock)
> {
> - PgStatShared_Backend *shbackendioent;
> - PgStat_BackendPendingIO *pendingent;
> + PgStatShared_Backend *shbackendent;
> + PgStat_BackendPending *pendingent;
> PgStat_BktypeIO *bktype_shstats;
> + PgStat_BackendPendingIO *pending_io;
>
> - if (!pgstat_lock_entry(entry_ref, nowait))
> - return false;
> + if (need_lock && !pgstat_lock_entry(entry_ref, nowait))
> + return;
>
> The addition of need_lock at this level leads to a result that seems a
> bit confusing, where pgstat_backend_flush_cb() passes "false" because
> it locks the entry by itself as an effect of v1-0003 with the new area
> for WAL. Wouldn't it be cleaner to do an extra pgstat_[un]lock_entry
> dance in pgstat_backend_flush_io() instead? Another approach I can
> think of that would be slightly cleaner to me is to pass a bits32 to a
> single routine that would control if WAL stats, I/O stats or both
> should be flushed, keeping pgstat_flush_backend() as name with an
> extra argument to decide which parts of the stats should be flushed.

Yeah, that's more elegant as it also means that the main callback will not change
(should we add even more stats in the future). Done that way in v2 attached.

> -PgStat_BackendPendingIO *
> +PgStat_BackendPending *
>
> This rename makes sense.
>
> #define PG_STAT_GET_WAL_COLS 9
> TupleDesc tupdesc;
> Datum values[PG_STAT_GET_WAL_COLS] = {0};
> bool nulls[PG_STAT_GET_WAL_COLS] = {0};
>
> It feels unnatural to have a PG_STAT_GET_WAL_COLS while it would not
> only relate to this function anymore.

Has been renamed to PG_STAT_WAL_COLS in the attached.

Regards,

--
Bertrand Drouvot
PostgreSQL Contributors Team
RDS Open Source Databases
Amazon Web Services: https://aws.amazon.com

Attachment Content-Type Size
v2-0001-Extract-logic-filling-pg_stat_get_wal-s-tuple-int.patch text/x-diff 3.9 KB
v2-0002-PGSTAT_KIND_BACKEND-code-refactoring.patch text/x-diff 9.8 KB
v2-0003-per-backend-WAL-statistics.patch text/x-diff 22.6 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Nazir Bilal Yavuz 2025-01-08 11:26:37 Re: Adding NetBSD and OpenBSD to Postgres CI
Previous Message vignesh C 2025-01-08 11:03:07 Re: Conflict detection for update_deleted in logical replication