1
0
mirror of https://github.com/postgres/postgres.git synced 2026-01-05 23:38:41 +03:00

Create subscription stats entry at CREATE SUBSCRIPTION time

Previously, the subscription stats entry was created when the first
stats, i.e., an error on apply worker or tablesync worker,  were
reported. Therefore, the stats_reset field was not updated by
pg_stat_reset_subscription_stats() if the stats entry was not
populated yet, which was different behavior than other statistics.

This change creates the subscription stats entry and initializes it at
CREATE SUBSCRIPTION time.

Reviewed-by: Andres Freund <andres@anarazel.de>
Reviewed-by: Amit Kapila <amit.kapila16@gmail.com>
Author: Masahiko Sawada <sawada.mshk@gmail.com>
Discussion: https://postgr.es/m/CAAKRu_Zqd-e5imT_3-ZiQv1cfsWuy16OJTiUaCvqpq4V7GVdSg@mail.gmail.com
This commit is contained in:
Andres Freund
2022-10-06 16:45:20 -07:00
parent cd4e8caaa0
commit e0b0142959
3 changed files with 51 additions and 2 deletions

View File

@@ -41,14 +41,18 @@ pgstat_report_subscription_error(Oid subid, bool is_apply_error)
/*
* Report creating the subscription.
*
* Ensures that stats are dropped if transaction rolls back.
*/
void
pgstat_create_subscription(Oid subid)
{
/* Ensures that stats are dropped if transaction rolls back */
pgstat_create_transactional(PGSTAT_KIND_SUBSCRIPTION,
InvalidOid, subid);
/* Create and initialize the subscription stats entry */
pgstat_get_entry_ref(PGSTAT_KIND_SUBSCRIPTION, InvalidOid, subid,
true, NULL);
pgstat_reset_entry(PGSTAT_KIND_SUBSCRIPTION, InvalidOid, subid, 0);
}
/*