PostgreSQL Source Code git master
Loading...
Searching...
No Matches
xlogdesc.c File Reference
#include "postgres.h"
#include "access/transam.h"
#include "access/xlog.h"
#include "access/xlog_internal.h"
#include "catalog/pg_control.h"
#include "utils/guc.h"
#include "utils/timestamp.h"
Include dependency graph for xlogdesc.c:

Go to the source code of this file.

Functions

static const charget_wal_level_string (int wal_level)
 
void xlog_desc (StringInfo buf, XLogReaderState *record)
 
const charxlog_identify (uint8 info)
 
void XLogRecGetBlockRefInfo (XLogReaderState *record, bool pretty, bool detailed_format, StringInfo buf, uint32 *fpi_len)
 

Variables

const struct config_enum_entry wal_level_options []
 

Function Documentation

◆ get_wal_level_string()

static const char * get_wal_level_string ( int  wal_level)
static

Definition at line 40 of file xlogdesc.c.

41{
42 const struct config_enum_entry *entry;
43 const char *wal_level_str = "?";
44
45 for (entry = wal_level_options; entry->name; entry++)
46 {
47 if (entry->val == wal_level)
48 {
49 wal_level_str = entry->name;
50 break;
51 }
52 }
53
54 return wal_level_str;
55}
static const char * wal_level_str(WalLevel wal_level)
Definition guc.h:174
const char * name
Definition guc.h:175
int val
Definition guc.h:176
int wal_level
Definition xlog.c:135
const struct config_enum_entry wal_level_options[]
Definition xlogdesc.c:27

References config_enum_entry::name, config_enum_entry::val, wal_level, wal_level_options, and wal_level_str().

Referenced by xlog_desc().

◆ xlog_desc()

void xlog_desc ( StringInfo  buf,
XLogReaderState record 
)

Definition at line 58 of file xlogdesc.c.

59{
60 char *rec = XLogRecGetData(record);
61 uint8 info = XLogRecGetInfo(record) & ~XLR_INFO_MASK;
62
63 if (info == XLOG_CHECKPOINT_SHUTDOWN ||
65 {
67
68 appendStringInfo(buf, "redo %X/%08X; "
69 "tli %u; prev tli %u; fpw %s; wal_level %s; logical decoding %s; xid %u:%u; oid %u; multi %u; offset %" PRIu64 "; "
70 "oldest xid %u in DB %u; oldest multi %u in DB %u; "
71 "oldest/newest commit timestamp xid: %u/%u; "
72 "oldest running xid %u; %s",
74 checkpoint->ThisTimeLineID,
75 checkpoint->PrevTimeLineID,
76 checkpoint->fullPageWrites ? "true" : "false",
78 checkpoint->logicalDecodingEnabled ? "true" : "false",
81 checkpoint->nextOid,
82 checkpoint->nextMulti,
83 checkpoint->nextMultiOffset,
84 checkpoint->oldestXid,
85 checkpoint->oldestXidDB,
86 checkpoint->oldestMulti,
87 checkpoint->oldestMultiDB,
88 checkpoint->oldestCommitTsXid,
89 checkpoint->newestCommitTsXid,
90 checkpoint->oldestActiveXid,
91 (info == XLOG_CHECKPOINT_SHUTDOWN) ? "shutdown" : "online");
92 }
93 else if (info == XLOG_NEXTOID)
94 {
95 Oid nextOid;
96
97 memcpy(&nextOid, rec, sizeof(Oid));
98 appendStringInfo(buf, "%u", nextOid);
99 }
100 else if (info == XLOG_RESTORE_POINT)
101 {
103
105 }
106 else if (info == XLOG_FPI || info == XLOG_FPI_FOR_HINT)
107 {
108 /* no further information to print */
109 }
110 else if (info == XLOG_BACKUP_END)
111 {
112 XLogRecPtr startpoint;
113
114 memcpy(&startpoint, rec, sizeof(XLogRecPtr));
115 appendStringInfo(buf, "%X/%08X", LSN_FORMAT_ARGS(startpoint));
116 }
117 else if (info == XLOG_PARAMETER_CHANGE)
118 {
120 const char *wal_level_str;
121
122 memcpy(&xlrec, rec, sizeof(xl_parameter_change));
124
125 appendStringInfo(buf, "max_connections=%d max_worker_processes=%d "
126 "max_wal_senders=%d max_prepared_xacts=%d "
127 "max_locks_per_xact=%d wal_level=%s "
128 "wal_log_hints=%s track_commit_timestamp=%s",
129 xlrec.MaxConnections,
130 xlrec.max_worker_processes,
131 xlrec.max_wal_senders,
132 xlrec.max_prepared_xacts,
133 xlrec.max_locks_per_xact,
135 xlrec.wal_log_hints ? "on" : "off",
136 xlrec.track_commit_timestamp ? "on" : "off");
137 }
138 else if (info == XLOG_FPW_CHANGE)
139 {
140 bool fpw;
141
142 memcpy(&fpw, rec, sizeof(bool));
143 appendStringInfoString(buf, fpw ? "true" : "false");
144 }
145 else if (info == XLOG_END_OF_RECOVERY)
146 {
148
149 memcpy(&xlrec, rec, sizeof(xl_end_of_recovery));
150 appendStringInfo(buf, "tli %u; prev tli %u; time %s; wal_level %s",
151 xlrec.ThisTimeLineID, xlrec.PrevTimeLineID,
152 timestamptz_to_str(xlrec.end_time),
153 get_wal_level_string(xlrec.wal_level));
154 }
155 else if (info == XLOG_OVERWRITE_CONTRECORD)
156 {
158
159 memcpy(&xlrec, rec, sizeof(xl_overwrite_contrecord));
160 appendStringInfo(buf, "lsn %X/%08X; time %s",
161 LSN_FORMAT_ARGS(xlrec.overwritten_lsn),
162 timestamptz_to_str(xlrec.overwrite_time));
163 }
164 else if (info == XLOG_CHECKPOINT_REDO)
165 {
166 int wal_level;
167
168 memcpy(&wal_level, rec, sizeof(int));
170 }
172 {
173 bool enabled;
174
175 memcpy(&enabled, rec, sizeof(bool));
176 appendStringInfoString(buf, enabled ? "true" : "false");
177 }
178 else if (info == XLOG_ASSIGN_LSN)
179 {
180 /* no further information to print */
181 }
182}
const char * timestamptz_to_str(TimestampTz t)
Definition timestamp.c:1853
uint8_t uint8
Definition c.h:616
bool track_commit_timestamp
Definition commit_ts.c:109
#define XLOG_RESTORE_POINT
Definition pg_control.h:76
#define XLOG_FPW_CHANGE
Definition pg_control.h:77
#define XLOG_CHECKPOINT_REDO
Definition pg_control.h:83
#define XLOG_OVERWRITE_CONTRECORD
Definition pg_control.h:82
#define XLOG_ASSIGN_LSN
Definition pg_control.h:81
#define XLOG_FPI
Definition pg_control.h:80
#define XLOG_FPI_FOR_HINT
Definition pg_control.h:79
#define XLOG_NEXTOID
Definition pg_control.h:72
#define XLOG_CHECKPOINT_SHUTDOWN
Definition pg_control.h:69
#define XLOG_BACKUP_END
Definition pg_control.h:74
#define XLOG_PARAMETER_CHANGE
Definition pg_control.h:75
#define XLOG_LOGICAL_DECODING_STATUS_CHANGE
Definition pg_control.h:84
#define XLOG_CHECKPOINT_ONLINE
Definition pg_control.h:70
#define XLOG_END_OF_RECOVERY
Definition pg_control.h:78
static char buf[DEFAULT_XLOG_SEG_SIZE]
unsigned int Oid
static int fb(int x)
void appendStringInfo(StringInfo str, const char *fmt,...)
Definition stringinfo.c:145
void appendStringInfoString(StringInfo str, const char *s)
Definition stringinfo.c:230
#define EpochFromFullTransactionId(x)
Definition transam.h:47
#define XidFromFullTransactionId(x)
Definition transam.h:48
#define LSN_FORMAT_ARGS(lsn)
Definition xlogdefs.h:47
uint64 XLogRecPtr
Definition xlogdefs.h:21
static const char * get_wal_level_string(int wal_level)
Definition xlogdesc.c:40
#define XLogRecGetInfo(decoder)
Definition xlogreader.h:409
#define XLogRecGetData(decoder)
Definition xlogreader.h:414

References appendStringInfo(), appendStringInfoString(), buf, EpochFromFullTransactionId, fb(), get_wal_level_string(), LSN_FORMAT_ARGS, timestamptz_to_str(), wal_level, wal_level_str(), XidFromFullTransactionId, XLOG_ASSIGN_LSN, XLOG_BACKUP_END, XLOG_CHECKPOINT_ONLINE, XLOG_CHECKPOINT_REDO, XLOG_CHECKPOINT_SHUTDOWN, XLOG_END_OF_RECOVERY, XLOG_FPI, XLOG_FPI_FOR_HINT, XLOG_FPW_CHANGE, XLOG_LOGICAL_DECODING_STATUS_CHANGE, XLOG_NEXTOID, XLOG_OVERWRITE_CONTRECORD, XLOG_PARAMETER_CHANGE, XLOG_RESTORE_POINT, XLogRecGetData, and XLogRecGetInfo.

◆ xlog_identify()

const char * xlog_identify ( uint8  info)

Definition at line 185 of file xlogdesc.c.

186{
187 const char *id = NULL;
188
189 switch (info & ~XLR_INFO_MASK)
190 {
192 id = "CHECKPOINT_SHUTDOWN";
193 break;
195 id = "CHECKPOINT_ONLINE";
196 break;
197 case XLOG_NOOP:
198 id = "NOOP";
199 break;
200 case XLOG_NEXTOID:
201 id = "NEXTOID";
202 break;
203 case XLOG_SWITCH:
204 id = "SWITCH";
205 break;
206 case XLOG_BACKUP_END:
207 id = "BACKUP_END";
208 break;
210 id = "PARAMETER_CHANGE";
211 break;
213 id = "RESTORE_POINT";
214 break;
215 case XLOG_FPW_CHANGE:
216 id = "FPW_CHANGE";
217 break;
219 id = "END_OF_RECOVERY";
220 break;
222 id = "OVERWRITE_CONTRECORD";
223 break;
224 case XLOG_FPI:
225 id = "FPI";
226 break;
228 id = "FPI_FOR_HINT";
229 break;
231 id = "CHECKPOINT_REDO";
232 break;
234 id = "LOGICAL_DECODING_STATUS_CHANGE";
235 break;
236 case XLOG_ASSIGN_LSN:
237 id = "ASSIGN_LSN";
238 break;
239 }
240
241 return id;
242}
#define XLOG_NOOP
Definition pg_control.h:71
#define XLOG_SWITCH
Definition pg_control.h:73
#define XLR_INFO_MASK
Definition xlogrecord.h:62

References fb(), XLOG_ASSIGN_LSN, XLOG_BACKUP_END, XLOG_CHECKPOINT_ONLINE, XLOG_CHECKPOINT_REDO, XLOG_CHECKPOINT_SHUTDOWN, XLOG_END_OF_RECOVERY, XLOG_FPI, XLOG_FPI_FOR_HINT, XLOG_FPW_CHANGE, XLOG_LOGICAL_DECODING_STATUS_CHANGE, XLOG_NEXTOID, XLOG_NOOP, XLOG_OVERWRITE_CONTRECORD, XLOG_PARAMETER_CHANGE, XLOG_RESTORE_POINT, XLOG_SWITCH, and XLR_INFO_MASK.

◆ XLogRecGetBlockRefInfo()

void XLogRecGetBlockRefInfo ( XLogReaderState record,
bool  pretty,
bool  detailed_format,
StringInfo  buf,
uint32 fpi_len 
)

Definition at line 249 of file xlogdesc.c.

252{
253 int block_id;
254
255 Assert(record != NULL);
256
257 if (detailed_format && pretty)
259
260 for (block_id = 0; block_id <= XLogRecMaxBlockId(record); block_id++)
261 {
262 RelFileLocator rlocator;
263 ForkNumber forknum;
265
267 &rlocator, &forknum, &blk, NULL))
268 continue;
269
270 if (detailed_format)
271 {
272 /* Get block references in detailed format. */
273
274 if (pretty)
276 else if (block_id > 0)
278
280 "blkref #%d: rel %u/%u/%u fork %s blk %u",
281 block_id,
282 rlocator.spcOid, rlocator.dbOid, rlocator.relNumber,
283 forkNames[forknum],
284 blk);
285
286 if (XLogRecHasBlockImage(record, block_id))
287 {
288 uint8 bimg_info = XLogRecGetBlock(record, block_id)->bimg_info;
289
290 /* Calculate the amount of FPI data in the record. */
291 if (fpi_len)
292 *fpi_len += XLogRecGetBlock(record, block_id)->bimg_len;
293
294 if (BKPIMAGE_COMPRESSED(bimg_info))
295 {
296 const char *method;
297
298 if ((bimg_info & BKPIMAGE_COMPRESS_PGLZ) != 0)
299 method = "pglz";
300 else if ((bimg_info & BKPIMAGE_COMPRESS_LZ4) != 0)
301 method = "lz4";
302 else if ((bimg_info & BKPIMAGE_COMPRESS_ZSTD) != 0)
303 method = "zstd";
304 else
305 method = "unknown";
306
308 " (FPW%s); hole: offset: %u, length: %u, "
309 "compression saved: %u, method: %s",
311 "" : " for WAL verification",
312 XLogRecGetBlock(record, block_id)->hole_offset,
313 XLogRecGetBlock(record, block_id)->hole_length,
314 BLCKSZ -
315 XLogRecGetBlock(record, block_id)->hole_length -
316 XLogRecGetBlock(record, block_id)->bimg_len,
317 method);
318 }
319 else
320 {
322 " (FPW%s); hole: offset: %u, length: %u",
324 "" : " for WAL verification",
325 XLogRecGetBlock(record, block_id)->hole_offset,
326 XLogRecGetBlock(record, block_id)->hole_length);
327 }
328 }
329
330 if (pretty)
332 }
333 else
334 {
335 /* Get block references in short format. */
336
337 if (forknum != MAIN_FORKNUM)
338 {
340 ", blkref #%d: rel %u/%u/%u fork %s blk %u",
341 block_id,
342 rlocator.spcOid, rlocator.dbOid, rlocator.relNumber,
343 forkNames[forknum],
344 blk);
345 }
346 else
347 {
349 ", blkref #%d: rel %u/%u/%u blk %u",
350 block_id,
351 rlocator.spcOid, rlocator.dbOid, rlocator.relNumber,
352 blk);
353 }
354
355 if (XLogRecHasBlockImage(record, block_id))
356 {
357 /* Calculate the amount of FPI data in the record. */
358 if (fpi_len)
359 *fpi_len += XLogRecGetBlock(record, block_id)->bimg_len;
360
361 if (XLogRecBlockImageApply(record, block_id))
363 else
364 appendStringInfoString(buf, " FPW for WAL verification");
365 }
366 }
367 }
368
369 if (!detailed_format && pretty)
371}
uint32 BlockNumber
Definition block.h:31
#define Assert(condition)
Definition c.h:945
const char *const forkNames[]
Definition relpath.c:33
ForkNumber
Definition relpath.h:56
@ MAIN_FORKNUM
Definition relpath.h:58
void appendStringInfoChar(StringInfo str, char ch)
Definition stringinfo.c:242
RelFileNumber relNumber
bool XLogRecGetBlockTagExtended(XLogReaderState *record, uint8 block_id, RelFileLocator *rlocator, ForkNumber *forknum, BlockNumber *blknum, Buffer *prefetch_buffer)
#define XLogRecBlockImageApply(decoder, block_id)
Definition xlogreader.h:424
#define XLogRecGetBlock(decoder, i)
Definition xlogreader.h:418
#define XLogRecMaxBlockId(decoder)
Definition xlogreader.h:417
#define XLogRecHasBlockImage(decoder, block_id)
Definition xlogreader.h:422
#define BKPIMAGE_COMPRESS_ZSTD
Definition xlogrecord.h:162
#define BKPIMAGE_COMPRESS_LZ4
Definition xlogrecord.h:161
#define BKPIMAGE_COMPRESSED(info)
Definition xlogrecord.h:164
#define BKPIMAGE_COMPRESS_PGLZ
Definition xlogrecord.h:160

References appendStringInfo(), appendStringInfoChar(), appendStringInfoString(), Assert, BKPIMAGE_COMPRESS_LZ4, BKPIMAGE_COMPRESS_PGLZ, BKPIMAGE_COMPRESS_ZSTD, BKPIMAGE_COMPRESSED, buf, RelFileLocator::dbOid, fb(), forkNames, MAIN_FORKNUM, RelFileLocator::relNumber, RelFileLocator::spcOid, XLogRecBlockImageApply, XLogRecGetBlock, XLogRecGetBlockTagExtended(), XLogRecHasBlockImage, and XLogRecMaxBlockId.

Referenced by GetWALRecordInfo(), and XLogDumpDisplayRecord().

Variable Documentation

◆ wal_level_options

const struct config_enum_entry wal_level_options[]
Initial value:
= {
{"minimal", WAL_LEVEL_MINIMAL, false},
{"replica", WAL_LEVEL_REPLICA, false},
{"archive", WAL_LEVEL_REPLICA, true},
{"hot_standby", WAL_LEVEL_REPLICA, true},
{"logical", WAL_LEVEL_LOGICAL, false},
{NULL, 0, false}
}
@ WAL_LEVEL_REPLICA
Definition xlog.h:76
@ WAL_LEVEL_LOGICAL
Definition xlog.h:77
@ WAL_LEVEL_MINIMAL
Definition xlog.h:75

Definition at line 27 of file xlogdesc.c.

27 {
28 {"minimal", WAL_LEVEL_MINIMAL, false},
29 {"replica", WAL_LEVEL_REPLICA, false},
30 {"archive", WAL_LEVEL_REPLICA, true}, /* deprecated */
31 {"hot_standby", WAL_LEVEL_REPLICA, true}, /* deprecated */
32 {"logical", WAL_LEVEL_LOGICAL, false},
33 {NULL, 0, false}
34};

Referenced by get_wal_level_string().