Skip to content

Commit 1f715f4

Browse files
bdrouvotAWSCommitfest Bot
authored andcommitted
Adding XID generation count per backend
This commit adds a new counter to record the number of XIDs generated per backend. It will help to detect if a backend is consuming XIDs at a high rate. Virtual transactions are not taken into account on purpose, we do want to track only the XID where there is a risk of wraparound.
1 parent 6ad7a20 commit 1f715f4

File tree

3 files changed

+8
-0
lines changed

3 files changed

+8
-0
lines changed

src/backend/access/transam/varsup.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "storage/pmsignal.h"
2525
#include "storage/proc.h"
2626
#include "utils/lsyscache.h"
27+
#include "utils/pgstat_internal.h"
2728
#include "utils/syscache.h"
2829

2930

@@ -257,6 +258,9 @@ GetNewTransactionId(bool isSubXact)
257258
/* LWLockRelease acts as barrier */
258259
MyProc->xid = xid;
259260
ProcGlobal->xids[MyProc->pgxactoff] = xid;
261+
PendingBackendStats.pending_xid_count++;
262+
backend_has_xactstats = true;
263+
pgstat_report_fixed = true;
260264
}
261265
else
262266
{

src/backend/utils/activity/pgstat_backend.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,9 +287,11 @@ pgstat_flush_backend_entry_xact(PgStat_EntryRef *entry_ref)
287287

288288
shbackendent->stats.xact_commit += PendingBackendStats.pending_xact_commit;
289289
shbackendent->stats.xact_rollback += PendingBackendStats.pending_xact_rollback;
290+
shbackendent->stats.xid_count += PendingBackendStats.pending_xid_count;
290291

291292
PendingBackendStats.pending_xact_commit = 0;
292293
PendingBackendStats.pending_xact_rollback = 0;
294+
PendingBackendStats.pending_xid_count = 0;
293295

294296
backend_has_xactstats = false;
295297
}

src/include/pgstat.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,7 @@ typedef struct PgStat_Backend
498498
PgStat_WalCounters wal_counters;
499499
PgStat_Counter xact_commit;
500500
PgStat_Counter xact_rollback;
501+
PgStat_Counter xid_count;
501502
} PgStat_Backend;
502503

503504
/* ---------
@@ -516,6 +517,7 @@ typedef struct PgStat_BackendPending
516517
*/
517518
PgStat_Counter pending_xact_commit;
518519
PgStat_Counter pending_xact_rollback;
520+
PgStat_Counter pending_xid_count;
519521
} PgStat_BackendPending;
520522

521523
/*

0 commit comments

Comments
 (0)