PostgreSQL Source Code git master
standbydesc.c
Go to the documentation of this file.
1/*-------------------------------------------------------------------------
2 *
3 * standbydesc.c
4 * rmgr descriptor routines for storage/ipc/standby.c
5 *
6 * Portions Copyright (c) 1996-2025, PostgreSQL Global Development Group
7 * Portions Copyright (c) 1994, Regents of the University of California
8 *
9 *
10 * IDENTIFICATION
11 * src/backend/access/rmgrdesc/standbydesc.c
12 *
13 *-------------------------------------------------------------------------
14 */
15#include "postgres.h"
16
17#include "storage/standbydefs.h"
18
19static void
21{
22 int i;
23
24 appendStringInfo(buf, "nextXid %u latestCompletedXid %u oldestRunningXid %u",
25 xlrec->nextXid,
26 xlrec->latestCompletedXid,
27 xlrec->oldestRunningXid);
28 if (xlrec->xcnt > 0)
29 {
30 appendStringInfo(buf, "; %d xacts:", xlrec->xcnt);
31 for (i = 0; i < xlrec->xcnt; i++)
32 appendStringInfo(buf, " %u", xlrec->xids[i]);
33 }
34
35 if (xlrec->subxid_overflow)
36 appendStringInfoString(buf, "; subxid overflowed");
37
38 if (xlrec->subxcnt > 0)
39 {
40 appendStringInfo(buf, "; %d subxacts:", xlrec->subxcnt);
41 for (i = 0; i < xlrec->subxcnt; i++)
42 appendStringInfo(buf, " %u", xlrec->xids[xlrec->xcnt + i]);
43 }
44}
45
46void
48{
49 char *rec = XLogRecGetData(record);
50 uint8 info = XLogRecGetInfo(record) & ~XLR_INFO_MASK;
51
52 if (info == XLOG_STANDBY_LOCK)
53 {
54 xl_standby_locks *xlrec = (xl_standby_locks *) rec;
55 int i;
56
57 for (i = 0; i < xlrec->nlocks; i++)
58 appendStringInfo(buf, "xid %u db %u rel %u ",
59 xlrec->locks[i].xid, xlrec->locks[i].dbOid,
60 xlrec->locks[i].relOid);
61 }
62 else if (info == XLOG_RUNNING_XACTS)
63 {
64 xl_running_xacts *xlrec = (xl_running_xacts *) rec;
65
67 }
68 else if (info == XLOG_INVALIDATIONS)
69 {
70 xl_invalidations *xlrec = (xl_invalidations *) rec;
71
73 xlrec->dbId, xlrec->tsId,
75 }
76}
77
78const char *
80{
81 const char *id = NULL;
82
83 switch (info & ~XLR_INFO_MASK)
84 {
86 id = "LOCK";
87 break;
89 id = "RUNNING_XACTS";
90 break;
92 id = "INVALIDATIONS";
93 break;
94 }
95
96 return id;
97}
98
99/* also used by non-standby records having analogous invalidation fields */
100void
102 int nmsgs, SharedInvalidationMessage *msgs,
103 Oid dbId, Oid tsId,
104 bool relcacheInitFileInval)
105{
106 int i;
107
108 /* Do nothing if there are no invalidation messages */
109 if (nmsgs <= 0)
110 return;
111
112 if (relcacheInitFileInval)
113 appendStringInfo(buf, "; relcache init file inval dbid %u tsid %u",
114 dbId, tsId);
115
116 appendStringInfoString(buf, "; inval msgs:");
117 for (i = 0; i < nmsgs; i++)
118 {
119 SharedInvalidationMessage *msg = &msgs[i];
120
121 if (msg->id >= 0)
122 appendStringInfo(buf, " catcache %d", msg->id);
123 else if (msg->id == SHAREDINVALCATALOG_ID)
124 appendStringInfo(buf, " catalog %u", msg->cat.catId);
125 else if (msg->id == SHAREDINVALRELCACHE_ID)
126 appendStringInfo(buf, " relcache %u", msg->rc.relId);
127 /* not expected, but print something anyway */
128 else if (msg->id == SHAREDINVALSMGR_ID)
129 appendStringInfoString(buf, " smgr");
130 /* not expected, but print something anyway */
131 else if (msg->id == SHAREDINVALRELMAP_ID)
132 appendStringInfo(buf, " relmap db %u", msg->rm.dbId);
133 else if (msg->id == SHAREDINVALSNAPSHOT_ID)
134 appendStringInfo(buf, " snapshot %u", msg->sn.relId);
135 else
136 appendStringInfo(buf, " unrecognized id %d", msg->id);
137 }
138}
uint8_t uint8
Definition: c.h:486
int i
Definition: isn.c:72
static char * buf
Definition: pg_test_fsync.c:72
unsigned int Oid
Definition: postgres_ext.h:32
#define SHAREDINVALCATALOG_ID
Definition: sinval.h:67
#define SHAREDINVALSMGR_ID
Definition: sinval.h:85
#define SHAREDINVALSNAPSHOT_ID
Definition: sinval.h:104
#define SHAREDINVALRELCACHE_ID
Definition: sinval.h:76
#define SHAREDINVALRELMAP_ID
Definition: sinval.h:96
#define XLOG_INVALIDATIONS
Definition: standbydefs.h:36
#define XLOG_STANDBY_LOCK
Definition: standbydefs.h:34
#define XLOG_RUNNING_XACTS
Definition: standbydefs.h:35
void standby_desc(StringInfo buf, XLogReaderState *record)
Definition: standbydesc.c:47
const char * standby_identify(uint8 info)
Definition: standbydesc.c:79
void standby_desc_invalidations(StringInfo buf, int nmsgs, SharedInvalidationMessage *msgs, Oid dbId, Oid tsId, bool relcacheInitFileInval)
Definition: standbydesc.c:101
static void standby_desc_running_xacts(StringInfo buf, xl_running_xacts *xlrec)
Definition: standbydesc.c:20
void appendStringInfo(StringInfo str, const char *fmt,...)
Definition: stringinfo.c:145
void appendStringInfoString(StringInfo str, const char *s)
Definition: stringinfo.c:230
SharedInvalidationMessage msgs[FLEXIBLE_ARRAY_MEMBER]
Definition: standbydefs.h:69
bool relcacheInitFileInval
Definition: standbydefs.h:67
TransactionId latestCompletedXid
Definition: standbydefs.h:54
TransactionId oldestRunningXid
Definition: standbydefs.h:53
TransactionId xids[FLEXIBLE_ARRAY_MEMBER]
Definition: standbydefs.h:56
TransactionId nextXid
Definition: standbydefs.h:52
TransactionId xid
Definition: lockdefs.h:53
xl_standby_lock locks[FLEXIBLE_ARRAY_MEMBER]
Definition: standbydefs.h:41
SharedInvalRelcacheMsg rc
Definition: sinval.h:118
SharedInvalCatalogMsg cat
Definition: sinval.h:117
SharedInvalSnapshotMsg sn
Definition: sinval.h:121
SharedInvalRelmapMsg rm
Definition: sinval.h:120
#define XLogRecGetInfo(decoder)
Definition: xlogreader.h:410
#define XLogRecGetData(decoder)
Definition: xlogreader.h:415
#define XLR_INFO_MASK
Definition: xlogrecord.h:62