mirror of
https://github.com/postgres/postgres.git
synced 2026-03-08 00:01:15 -05: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:
parent
cd4e8caaa0
commit
e0b0142959
3 changed files with 51 additions and 2 deletions
|
|
@ -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);
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
|||
|
|
@ -37,6 +37,40 @@ SELECT obj_description(s.oid, 'pg_subscription') FROM pg_subscription s;
|
|||
test subscription
|
||||
(1 row)
|
||||
|
||||
-- Check if the subscription stats are created and stats_reset is updated
|
||||
-- by pg_stat_reset_subscription_stats().
|
||||
SELECT subname, stats_reset IS NULL stats_reset_is_null FROM pg_stat_subscription_stats WHERE subname = 'regress_testsub';
|
||||
subname | stats_reset_is_null
|
||||
-----------------+---------------------
|
||||
regress_testsub | t
|
||||
(1 row)
|
||||
|
||||
SELECT pg_stat_reset_subscription_stats(oid) FROM pg_subscription WHERE subname = 'regress_testsub';
|
||||
pg_stat_reset_subscription_stats
|
||||
----------------------------------
|
||||
|
||||
(1 row)
|
||||
|
||||
SELECT subname, stats_reset IS NULL stats_reset_is_null FROM pg_stat_subscription_stats WHERE subname = 'regress_testsub';
|
||||
subname | stats_reset_is_null
|
||||
-----------------+---------------------
|
||||
regress_testsub | f
|
||||
(1 row)
|
||||
|
||||
-- Reset the stats again and check if the new reset_stats is updated.
|
||||
SELECT stats_reset as prev_stats_reset FROM pg_stat_subscription_stats WHERE subname = 'regress_testsub' \gset
|
||||
SELECT pg_stat_reset_subscription_stats(oid) FROM pg_subscription WHERE subname = 'regress_testsub';
|
||||
pg_stat_reset_subscription_stats
|
||||
----------------------------------
|
||||
|
||||
(1 row)
|
||||
|
||||
SELECT :'prev_stats_reset' < stats_reset FROM pg_stat_subscription_stats WHERE subname = 'regress_testsub';
|
||||
?column?
|
||||
----------
|
||||
t
|
||||
(1 row)
|
||||
|
||||
-- fail - name already exists
|
||||
CREATE SUBSCRIPTION regress_testsub CONNECTION 'dbname=regress_doesnotexist' PUBLICATION testpub WITH (connect = false);
|
||||
ERROR: subscription "regress_testsub" already exists
|
||||
|
|
|
|||
|
|
@ -30,6 +30,17 @@ CREATE SUBSCRIPTION regress_testsub CONNECTION 'dbname=regress_doesnotexist' PUB
|
|||
COMMENT ON SUBSCRIPTION regress_testsub IS 'test subscription';
|
||||
SELECT obj_description(s.oid, 'pg_subscription') FROM pg_subscription s;
|
||||
|
||||
-- Check if the subscription stats are created and stats_reset is updated
|
||||
-- by pg_stat_reset_subscription_stats().
|
||||
SELECT subname, stats_reset IS NULL stats_reset_is_null FROM pg_stat_subscription_stats WHERE subname = 'regress_testsub';
|
||||
SELECT pg_stat_reset_subscription_stats(oid) FROM pg_subscription WHERE subname = 'regress_testsub';
|
||||
SELECT subname, stats_reset IS NULL stats_reset_is_null FROM pg_stat_subscription_stats WHERE subname = 'regress_testsub';
|
||||
|
||||
-- Reset the stats again and check if the new reset_stats is updated.
|
||||
SELECT stats_reset as prev_stats_reset FROM pg_stat_subscription_stats WHERE subname = 'regress_testsub' \gset
|
||||
SELECT pg_stat_reset_subscription_stats(oid) FROM pg_subscription WHERE subname = 'regress_testsub';
|
||||
SELECT :'prev_stats_reset' < stats_reset FROM pg_stat_subscription_stats WHERE subname = 'regress_testsub';
|
||||
|
||||
-- fail - name already exists
|
||||
CREATE SUBSCRIPTION regress_testsub CONNECTION 'dbname=regress_doesnotexist' PUBLICATION testpub WITH (connect = false);
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue