PostgreSQL Source Code git master
Loading...
Searching...
No Matches
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-2026, 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 appendStringInfo(buf, "; dbid: %u", xlrec->dbid);
46}
47
48void
50{
51 char *rec = XLogRecGetData(record);
52 uint8 info = XLogRecGetInfo(record) & ~XLR_INFO_MASK;
53
54 if (info == XLOG_STANDBY_LOCK)
55 {
57 int i;
58
59 for (i = 0; i < xlrec->nlocks; i++)
60 appendStringInfo(buf, "xid %u db %u rel %u ",
61 xlrec->locks[i].xid, xlrec->locks[i].dbOid,
62 xlrec->locks[i].relOid);
63 }
64 else if (info == XLOG_RUNNING_XACTS)
65 {
67
69 }
70 else if (info == XLOG_INVALIDATIONS)
71 {
73
75 xlrec->dbId, xlrec->tsId,
76 xlrec->relcacheInitFileInval);
77 }
78}
79
80const char *
82{
83 const char *id = NULL;
84
85 switch (info & ~XLR_INFO_MASK)
86 {
88 id = "LOCK";
89 break;
91 id = "RUNNING_XACTS";
92 break;
94 id = "INVALIDATIONS";
95 break;
96 }
97
98 return id;
99}
100
101/* also used by non-standby records having analogous invalidation fields */
102void
104 int nmsgs, SharedInvalidationMessage *msgs,
105 Oid dbId, Oid tsId,
106 bool relcacheInitFileInval)
107{
108 int i;
109
110 /* Do nothing if there are no invalidation messages */
111 if (nmsgs <= 0)
112 return;
113
114 if (relcacheInitFileInval)
115 appendStringInfo(buf, "; relcache init file inval dbid %u tsid %u",
116 dbId, tsId);
117
118 appendStringInfoString(buf, "; inval msgs:");
119 for (i = 0; i < nmsgs; i++)
120 {
121 SharedInvalidationMessage *msg = &msgs[i];
122
123 if (msg->id >= 0)
124 appendStringInfo(buf, " catcache %d", msg->id);
125 else if (msg->id == SHAREDINVALCATALOG_ID)
126 appendStringInfo(buf, " catalog %u", msg->cat.catId);
127 else if (msg->id == SHAREDINVALRELCACHE_ID)
128 appendStringInfo(buf, " relcache %u", msg->rc.relId);
129 /* not expected, but print something anyway */
130 else if (msg->id == SHAREDINVALSMGR_ID)
131 appendStringInfoString(buf, " smgr");
132 /* not expected, but print something anyway */
133 else if (msg->id == SHAREDINVALRELMAP_ID)
134 appendStringInfo(buf, " relmap db %u", msg->rm.dbId);
135 else if (msg->id == SHAREDINVALSNAPSHOT_ID)
136 appendStringInfo(buf, " snapshot %u", msg->sn.relId);
137 else if (msg->id == SHAREDINVALRELSYNC_ID)
138 appendStringInfo(buf, " relsync %u", msg->rs.relid);
139 else
140 appendStringInfo(buf, " unrecognized id %d", msg->id);
141 }
142}
uint8_t uint8
Definition c.h:622
int i
Definition isn.c:77
static char buf[DEFAULT_XLOG_SEG_SIZE]
unsigned int Oid
static int fb(int x)
#define SHAREDINVALCATALOG_ID
Definition sinval.h:68
#define SHAREDINVALRELSYNC_ID
Definition sinval.h:114
#define SHAREDINVALSMGR_ID
Definition sinval.h:86
#define SHAREDINVALSNAPSHOT_ID
Definition sinval.h:105
#define SHAREDINVALRELCACHE_ID
Definition sinval.h:77
#define SHAREDINVALRELMAP_ID
Definition sinval.h:97
#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:49
const char * standby_identify(uint8 info)
Definition standbydesc.c:81
void standby_desc_invalidations(StringInfo buf, int nmsgs, SharedInvalidationMessage *msgs, Oid dbId, Oid tsId, bool relcacheInitFileInval)
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
SharedInvalRelcacheMsg rc
Definition sinval.h:129
SharedInvalCatalogMsg cat
Definition sinval.h:128
SharedInvalRelSyncMsg rs
Definition sinval.h:133
SharedInvalSnapshotMsg sn
Definition sinval.h:132
SharedInvalRelmapMsg rm
Definition sinval.h:131
#define XLogRecGetInfo(decoder)
Definition xlogreader.h:410
#define XLogRecGetData(decoder)
Definition xlogreader.h:415
#define XLR_INFO_MASK
Definition xlogrecord.h:62