Skip to content

Commit cc3ac5a

Browse files
vigneshwaran-cCommitfest Bot
authored andcommitted
Add seq_sync_error_count to subscription statistics.
This commit introduces a new column seq_sync_error_count to subscription statistics. The new field tracks the number of errors encountered during sequence synchronization for each subscription.
1 parent b433bc0 commit cc3ac5a

File tree

11 files changed

+122
-60
lines changed

11 files changed

+122
-60
lines changed

doc/src/sgml/monitoring.sgml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2193,6 +2193,15 @@ description | Waiting for a newly initialized WAL file to reach durable storage
21932193
</para></entry>
21942194
</row>
21952195

2196+
<row>
2197+
<entry role="catalog_table_entry"><para role="column_definition">
2198+
<structfield>sequence_sync_error_count</structfield> <type>bigint</type>
2199+
</para>
2200+
<para>
2201+
Number of times an error occurred during the sequence synchronization
2202+
</para></entry>
2203+
</row>
2204+
21962205
<row>
21972206
<entry role="catalog_table_entry"><para role="column_definition">
21982207
<structfield>sync_error_count</structfield> <type>bigint</type>

src/backend/catalog/system_views.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1415,6 +1415,7 @@ CREATE VIEW pg_stat_subscription_stats AS
14151415
ss.subid,
14161416
s.subname,
14171417
ss.apply_error_count,
1418+
ss.seq_sync_error_count,
14181419
ss.sync_error_count,
14191420
ss.confl_insert_exists,
14201421
ss.confl_update_origin_differs,

src/backend/replication/logical/sequencesync.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -670,6 +670,9 @@ start_sequence_sync()
670670
* idle state.
671671
*/
672672
AbortOutOfAnyTransaction();
673+
pgstat_report_subscription_error(MySubscription->oid,
674+
WORKERTYPE_SEQUENCESYNC);
675+
673676
PG_RE_THROW();
674677
}
675678
}

src/backend/replication/logical/tablesync.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1530,7 +1530,8 @@ start_table_sync(XLogRecPtr *origin_startpos, char **slotname)
15301530
* idle state.
15311531
*/
15321532
AbortOutOfAnyTransaction();
1533-
pgstat_report_subscription_error(MySubscription->oid, false);
1533+
pgstat_report_subscription_error(MySubscription->oid,
1534+
WORKERTYPE_TABLESYNC);
15341535

15351536
PG_RE_THROW();
15361537
}

src/backend/replication/logical/worker.c

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5607,7 +5607,7 @@ start_apply(XLogRecPtr origin_startpos)
56075607
*/
56085608
AbortOutOfAnyTransaction();
56095609
pgstat_report_subscription_error(MySubscription->oid,
5610-
!am_tablesync_worker());
5610+
MyLogicalRepWorker->type);
56115611

56125612
PG_RE_THROW();
56135613
}
@@ -5954,15 +5954,12 @@ DisableSubscriptionAndExit(void)
59545954

59555955
RESUME_INTERRUPTS();
59565956

5957-
if (am_leader_apply_worker() || am_tablesync_worker())
5958-
{
5959-
/*
5960-
* Report the worker failed during either table synchronization or
5961-
* apply.
5962-
*/
5963-
pgstat_report_subscription_error(MyLogicalRepWorker->subid,
5964-
!am_tablesync_worker());
5965-
}
5957+
/*
5958+
* Report the worker failed during either sequence synchronization or
5959+
* table synchronization or apply.
5960+
*/
5961+
pgstat_report_subscription_error(MyLogicalRepWorker->subid,
5962+
MyLogicalRepWorker->type);
59665963

59675964
/* Disable the subscription */
59685965
StartTransactionCommand();

src/backend/utils/activity/pgstat_subscription.c

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,15 @@
1717

1818
#include "postgres.h"
1919

20+
#include "replication/worker_internal.h"
2021
#include "utils/pgstat_internal.h"
2122

2223

2324
/*
2425
* Report a subscription error.
2526
*/
2627
void
27-
pgstat_report_subscription_error(Oid subid, bool is_apply_error)
28+
pgstat_report_subscription_error(Oid subid, LogicalRepWorkerType wtype)
2829
{
2930
PgStat_EntryRef *entry_ref;
3031
PgStat_BackendSubEntry *pending;
@@ -33,10 +34,25 @@ pgstat_report_subscription_error(Oid subid, bool is_apply_error)
3334
InvalidOid, subid, NULL);
3435
pending = entry_ref->pending;
3536

36-
if (is_apply_error)
37-
pending->apply_error_count++;
38-
else
39-
pending->sync_error_count++;
37+
switch (wtype)
38+
{
39+
case WORKERTYPE_APPLY:
40+
pending->apply_error_count++;
41+
break;
42+
43+
case WORKERTYPE_SEQUENCESYNC:
44+
pending->seq_sync_error_count++;
45+
break;
46+
47+
case WORKERTYPE_TABLESYNC:
48+
pending->sync_error_count++;
49+
break;
50+
51+
default:
52+
/* Should never happen. */
53+
Assert(0);
54+
break;
55+
}
4056
}
4157

4258
/*
@@ -115,6 +131,7 @@ pgstat_subscription_flush_cb(PgStat_EntryRef *entry_ref, bool nowait)
115131

116132
#define SUB_ACC(fld) shsubent->stats.fld += localent->fld
117133
SUB_ACC(apply_error_count);
134+
SUB_ACC(seq_sync_error_count);
118135
SUB_ACC(sync_error_count);
119136
for (int i = 0; i < CONFLICT_NUM_TYPES; i++)
120137
SUB_ACC(conflict_count[i]);

src/backend/utils/adt/pgstatfuncs.c

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2203,7 +2203,7 @@ pg_stat_get_replication_slot(PG_FUNCTION_ARGS)
22032203
Datum
22042204
pg_stat_get_subscription_stats(PG_FUNCTION_ARGS)
22052205
{
2206-
#define PG_STAT_GET_SUBSCRIPTION_STATS_COLS 12
2206+
#define PG_STAT_GET_SUBSCRIPTION_STATS_COLS 13
22072207
Oid subid = PG_GETARG_OID(0);
22082208
TupleDesc tupdesc;
22092209
Datum values[PG_STAT_GET_SUBSCRIPTION_STATS_COLS] = {0};
@@ -2221,25 +2221,27 @@ pg_stat_get_subscription_stats(PG_FUNCTION_ARGS)
22212221
OIDOID, -1, 0);
22222222
TupleDescInitEntry(tupdesc, (AttrNumber) 2, "apply_error_count",
22232223
INT8OID, -1, 0);
2224-
TupleDescInitEntry(tupdesc, (AttrNumber) 3, "sync_error_count",
2224+
TupleDescInitEntry(tupdesc, (AttrNumber) 3, "seq_sync_error_count",
22252225
INT8OID, -1, 0);
2226-
TupleDescInitEntry(tupdesc, (AttrNumber) 4, "confl_insert_exists",
2226+
TupleDescInitEntry(tupdesc, (AttrNumber) 4, "sync_error_count",
22272227
INT8OID, -1, 0);
2228-
TupleDescInitEntry(tupdesc, (AttrNumber) 5, "confl_update_origin_differs",
2228+
TupleDescInitEntry(tupdesc, (AttrNumber) 5, "confl_insert_exists",
22292229
INT8OID, -1, 0);
2230-
TupleDescInitEntry(tupdesc, (AttrNumber) 6, "confl_update_exists",
2230+
TupleDescInitEntry(tupdesc, (AttrNumber) 6, "confl_update_origin_differs",
22312231
INT8OID, -1, 0);
2232-
TupleDescInitEntry(tupdesc, (AttrNumber) 7, "confl_update_deleted",
2232+
TupleDescInitEntry(tupdesc, (AttrNumber) 7, "confl_update_exists",
22332233
INT8OID, -1, 0);
2234-
TupleDescInitEntry(tupdesc, (AttrNumber) 8, "confl_update_missing",
2234+
TupleDescInitEntry(tupdesc, (AttrNumber) 8, "confl_update_deleted",
22352235
INT8OID, -1, 0);
2236-
TupleDescInitEntry(tupdesc, (AttrNumber) 9, "confl_delete_origin_differs",
2236+
TupleDescInitEntry(tupdesc, (AttrNumber) 9, "confl_update_missing",
22372237
INT8OID, -1, 0);
2238-
TupleDescInitEntry(tupdesc, (AttrNumber) 10, "confl_delete_missing",
2238+
TupleDescInitEntry(tupdesc, (AttrNumber) 10, "confl_delete_origin_differs",
22392239
INT8OID, -1, 0);
2240-
TupleDescInitEntry(tupdesc, (AttrNumber) 11, "confl_multiple_unique_conflicts",
2240+
TupleDescInitEntry(tupdesc, (AttrNumber) 11, "confl_delete_missing",
22412241
INT8OID, -1, 0);
2242-
TupleDescInitEntry(tupdesc, (AttrNumber) 12, "stats_reset",
2242+
TupleDescInitEntry(tupdesc, (AttrNumber) 12, "confl_multiple_unique_conflicts",
2243+
INT8OID, -1, 0);
2244+
TupleDescInitEntry(tupdesc, (AttrNumber) 13, "stats_reset",
22432245
TIMESTAMPTZOID, -1, 0);
22442246
BlessTupleDesc(tupdesc);
22452247

@@ -2256,6 +2258,9 @@ pg_stat_get_subscription_stats(PG_FUNCTION_ARGS)
22562258
/* apply_error_count */
22572259
values[i++] = Int64GetDatum(subentry->apply_error_count);
22582260

2261+
/* seq_sync_error_count */
2262+
values[i++] = Int64GetDatum(subentry->seq_sync_error_count);
2263+
22592264
/* sync_error_count */
22602265
values[i++] = Int64GetDatum(subentry->sync_error_count);
22612266

src/include/catalog/pg_proc.dat

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5704,9 +5704,9 @@
57045704
{ oid => '6231', descr => 'statistics: information about subscription stats',
57055705
proname => 'pg_stat_get_subscription_stats', provolatile => 's',
57065706
proparallel => 'r', prorettype => 'record', proargtypes => 'oid',
5707-
proallargtypes => '{oid,oid,int8,int8,int8,int8,int8,int8,int8,int8,int8,int8,timestamptz}',
5708-
proargmodes => '{i,o,o,o,o,o,o,o,o,o,o,o,o}',
5709-
proargnames => '{subid,subid,apply_error_count,sync_error_count,confl_insert_exists,confl_update_origin_differs,confl_update_exists,confl_update_deleted,confl_update_missing,confl_delete_origin_differs,confl_delete_missing,confl_multiple_unique_conflicts,stats_reset}',
5707+
proallargtypes => '{oid,oid,int8,int8,int8,int8,int8,int8,int8,int8,int8,int8,int8,timestamptz}',
5708+
proargmodes => '{i,o,o,o,o,o,o,o,o,o,o,o,o,o}',
5709+
proargnames => '{subid,subid,apply_error_count,seq_sync_error_count,sync_error_count,confl_insert_exists,confl_update_origin_differs,confl_update_exists,confl_update_deleted,confl_update_missing,confl_delete_origin_differs,confl_delete_missing,confl_multiple_unique_conflicts,stats_reset}',
57105710
prosrc => 'pg_stat_get_subscription_stats' },
57115711
{ oid => '6118', descr => 'statistics: information about subscription',
57125712
proname => 'pg_stat_get_subscription', prorows => '10', proisstrict => 'f',

src/include/pgstat.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "portability/instr_time.h"
1717
#include "postmaster/pgarch.h" /* for MAX_XFN_CHARS */
1818
#include "replication/conflict.h"
19+
#include "replication/worker_internal.h"
1920
#include "utils/backend_progress.h" /* for backward compatibility */ /* IWYU pragma: export */
2021
#include "utils/backend_status.h" /* for backward compatibility */ /* IWYU pragma: export */
2122
#include "utils/pgstat_kind.h"
@@ -108,6 +109,7 @@ typedef struct PgStat_FunctionCallUsage
108109
typedef struct PgStat_BackendSubEntry
109110
{
110111
PgStat_Counter apply_error_count;
112+
PgStat_Counter seq_sync_error_count;
111113
PgStat_Counter sync_error_count;
112114
PgStat_Counter conflict_count[CONFLICT_NUM_TYPES];
113115
} PgStat_BackendSubEntry;
@@ -416,6 +418,7 @@ typedef struct PgStat_SLRUStats
416418
typedef struct PgStat_StatSubEntry
417419
{
418420
PgStat_Counter apply_error_count;
421+
PgStat_Counter seq_sync_error_count;
419422
PgStat_Counter sync_error_count;
420423
PgStat_Counter conflict_count[CONFLICT_NUM_TYPES];
421424
TimestampTz stat_reset_timestamp;
@@ -769,7 +772,8 @@ extern PgStat_SLRUStats *pgstat_fetch_slru(void);
769772
* Functions in pgstat_subscription.c
770773
*/
771774

772-
extern void pgstat_report_subscription_error(Oid subid, bool is_apply_error);
775+
extern void pgstat_report_subscription_error(Oid subid,
776+
LogicalRepWorkerType wtype);
773777
extern void pgstat_report_subscription_conflict(Oid subid, ConflictType type);
774778
extern void pgstat_create_subscription(Oid subid);
775779
extern void pgstat_drop_subscription(Oid subid);

src/test/regress/expected/rules.out

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2191,6 +2191,7 @@ pg_stat_subscription| SELECT su.oid AS subid,
21912191
pg_stat_subscription_stats| SELECT ss.subid,
21922192
s.subname,
21932193
ss.apply_error_count,
2194+
ss.seq_sync_error_count,
21942195
ss.sync_error_count,
21952196
ss.confl_insert_exists,
21962197
ss.confl_update_origin_differs,
@@ -2202,7 +2203,7 @@ pg_stat_subscription_stats| SELECT ss.subid,
22022203
ss.confl_multiple_unique_conflicts,
22032204
ss.stats_reset
22042205
FROM pg_subscription s,
2205-
LATERAL pg_stat_get_subscription_stats(s.oid) ss(subid, apply_error_count, sync_error_count, confl_insert_exists, confl_update_origin_differs, confl_update_exists, confl_update_deleted, confl_update_missing, confl_delete_origin_differs, confl_delete_missing, confl_multiple_unique_conflicts, stats_reset);
2206+
LATERAL pg_stat_get_subscription_stats(s.oid) ss(subid, apply_error_count, seq_sync_error_count, sync_error_count, confl_insert_exists, confl_update_origin_differs, confl_update_exists, confl_update_deleted, confl_update_missing, confl_delete_origin_differs, confl_delete_missing, confl_multiple_unique_conflicts, stats_reset);
22062207
pg_stat_sys_indexes| SELECT relid,
22072208
indexrelid,
22082209
schemaname,

0 commit comments

Comments
 (0)