Re: Issue with pg_stat_subscription_stats - Mailing list pgsql-hackers

From Andres Freund
Subject Re: Issue with pg_stat_subscription_stats
Date
Msg-id 20220705215245.dnj3ugvqvxfc4z4l@awork3.anarazel.de
Whole thread Raw
In response to Re: Issue with pg_stat_subscription_stats  (Masahiko Sawada <sawada.mshk@gmail.com>)
Responses Re: Issue with pg_stat_subscription_stats
Re: Issue with pg_stat_subscription_stats
List pgsql-hackers
Hi,

On 2022-07-04 11:01:01 +0900, Masahiko Sawada wrote:
> I've attached the patch, fix_drop_subscriptions_stats.patch, to fix it.

LGTM. Unless somebody sees a reason not to, I'm planning to commit that to 15
and HEAD.


> I've also attached another PoC patch,
> poc_create_subscription_stats.patch, to create the stats entry when
> creating the subscription, which address the issue reported in this
> thread; the pg_stat_reset_subscription_stats() doesn't update the
> stats_reset if no error is reported yet.

It'd be good for this to include a test.


> diff --git a/src/backend/utils/activity/pgstat_subscription.c b/src/backend/utils/activity/pgstat_subscription.c
> index e1072bd5ba..ef318b7422 100644
> --- a/src/backend/utils/activity/pgstat_subscription.c
> +++ b/src/backend/utils/activity/pgstat_subscription.c
> @@ -47,8 +47,20 @@ pgstat_report_subscription_error(Oid subid, bool is_apply_error)
>  void
>  pgstat_create_subscription(Oid subid)
>  {
> +    PgStat_EntryRef *entry_ref;
> +    PgStatShared_Subscription *shstatent;
> +
>      pgstat_create_transactional(PGSTAT_KIND_SUBSCRIPTION,
>                                  InvalidOid, subid);
> +
> +    entry_ref = pgstat_get_entry_ref_locked(PGSTAT_KIND_SUBSCRIPTION,
> +                                            InvalidOid, subid,
> +                                            false);
> +    shstatent = (PgStatShared_Subscription *) entry_ref->shared_stats;
> +
> +    memset(&shstatent->stats, 0, sizeof(shstatent->stats));
> +
> +    pgstat_unlock_entry(entry_ref);
>  }
>  
>  /*

I think most of this could just be pgstat_reset_entry().

Greetings,

Andres Freund



pgsql-hackers by date:

Previous
From: Andrew Dunstan
Date:
Subject: Re: [UNVERIFIED SENDER] Re: pg_upgrade can result in early wraparound on databases with high transaction load
Next
From: Noah Misch
Date:
Subject: Re: First draft of the PG 15 release notes