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 "storage/checksum.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)
 
const charget_checksum_state_string (uint32 state)
 
void xlog2_desc (StringInfo buf, XLogReaderState *record)
 
void xlog_desc (StringInfo buf, XLogReaderState *record)
 
const charxlog_identify (uint8 info)
 
const charxlog2_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_checksum_state_string()

const char * get_checksum_state_string ( uint32  state)

Definition at line 59 of file xlogdesc.c.

60{
61 switch (state)
62 {
64 return "on";
66 return "inprogress-off";
68 return "inprogress-on";
70 return "off";
71 }
72
73 Assert(false);
74 return "?";
75}
#define Assert(condition)
Definition c.h:943
@ PG_DATA_CHECKSUM_VERSION
Definition checksum.h:29
@ PG_DATA_CHECKSUM_INPROGRESS_OFF
Definition checksum.h:30
@ PG_DATA_CHECKSUM_INPROGRESS_ON
Definition checksum.h:31
@ PG_DATA_CHECKSUM_OFF
Definition checksum.h:28

References Assert, PG_DATA_CHECKSUM_INPROGRESS_OFF, PG_DATA_CHECKSUM_INPROGRESS_ON, PG_DATA_CHECKSUM_OFF, and PG_DATA_CHECKSUM_VERSION.

Referenced by show_data_checksums(), xlog2_desc(), and xlog_desc().

◆ get_wal_level_string()

static const char * get_wal_level_string ( int  wal_level)
static

Definition at line 41 of file xlogdesc.c.

42{
43 const struct config_enum_entry *entry;
44 const char *wal_level_str = "?";
45
46 for (entry = wal_level_options; entry->name; entry++)
47 {
48 if (entry->val == wal_level)
49 {
50 wal_level_str = entry->name;
51 break;
52 }
53 }
54
55 return wal_level_str;
56}
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:138
const struct config_enum_entry wal_level_options[]
Definition xlogdesc.c:28

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

Referenced by xlog_desc().

◆ xlog2_desc()

void xlog2_desc ( StringInfo  buf,
XLogReaderState record 
)

Definition at line 78 of file xlogdesc.c.

79{
80 char *rec = XLogRecGetData(record);
81 uint8 info = XLogRecGetInfo(record) & ~XLR_INFO_MASK;
82
83 if (info == XLOG2_CHECKSUMS)
84 {
86
87 memcpy(&xlrec, rec, sizeof(xl_checksum_state));
89 }
90}
uint8_t uint8
Definition c.h:622
memcpy(sums, checksumBaseOffsets, sizeof(checksumBaseOffsets))
#define XLOG2_CHECKSUMS
Definition pg_control.h:90
static char buf[DEFAULT_XLOG_SEG_SIZE]
static int fb(int x)
void appendStringInfoString(StringInfo str, const char *s)
Definition stringinfo.c:230
const char * get_checksum_state_string(uint32 state)
Definition xlogdesc.c:59
#define XLogRecGetInfo(decoder)
Definition xlogreader.h:410
#define XLogRecGetData(decoder)
Definition xlogreader.h:415

References appendStringInfoString(), buf, fb(), get_checksum_state_string(), memcpy(), XLOG2_CHECKSUMS, XLogRecGetData, and XLogRecGetInfo.

◆ xlog2_identify()

const char * xlog2_identify ( uint8  info)

Definition at line 284 of file xlogdesc.c.

285{
286 const char *id = NULL;
287
288 switch (info & ~XLR_INFO_MASK)
289 {
290 case XLOG2_CHECKSUMS:
291 id = "CHECKSUMS";
292 break;
293 }
294
295 return id;
296}
#define XLR_INFO_MASK
Definition xlogrecord.h:62

References fb(), XLOG2_CHECKSUMS, and XLR_INFO_MASK.

◆ xlog_desc()

void xlog_desc ( StringInfo  buf,
XLogReaderState record 
)

Definition at line 93 of file xlogdesc.c.

94{
95 char *rec = XLogRecGetData(record);
96 uint8 info = XLogRecGetInfo(record) & ~XLR_INFO_MASK;
97
98 if (info == XLOG_CHECKPOINT_SHUTDOWN ||
100 {
102
103 appendStringInfo(buf, "redo %X/%08X; "
104 "tli %u; prev tli %u; fpw %s; wal_level %s; logical decoding %s; xid %u:%u; oid %u; multi %u; offset %" PRIu64 "; "
105 "oldest xid %u in DB %u; oldest multi %u in DB %u; "
106 "oldest/newest commit timestamp xid: %u/%u; "
107 "oldest running xid %u; "
108 "checksums %s; %s",
110 checkpoint->ThisTimeLineID,
111 checkpoint->PrevTimeLineID,
112 checkpoint->fullPageWrites ? "true" : "false",
114 checkpoint->logicalDecodingEnabled ? "true" : "false",
117 checkpoint->nextOid,
118 checkpoint->nextMulti,
119 checkpoint->nextMultiOffset,
120 checkpoint->oldestXid,
121 checkpoint->oldestXidDB,
122 checkpoint->oldestMulti,
123 checkpoint->oldestMultiDB,
124 checkpoint->oldestCommitTsXid,
125 checkpoint->newestCommitTsXid,
126 checkpoint->oldestActiveXid,
127 get_checksum_state_string(checkpoint->dataChecksumState),
128 (info == XLOG_CHECKPOINT_SHUTDOWN) ? "shutdown" : "online");
129 }
130 else if (info == XLOG_NEXTOID)
131 {
132 Oid nextOid;
133
134 memcpy(&nextOid, rec, sizeof(Oid));
135 appendStringInfo(buf, "%u", nextOid);
136 }
137 else if (info == XLOG_RESTORE_POINT)
138 {
140
142 }
143 else if (info == XLOG_FPI || info == XLOG_FPI_FOR_HINT)
144 {
145 /* no further information to print */
146 }
147 else if (info == XLOG_BACKUP_END)
148 {
149 XLogRecPtr startpoint;
150
151 memcpy(&startpoint, rec, sizeof(XLogRecPtr));
152 appendStringInfo(buf, "%X/%08X", LSN_FORMAT_ARGS(startpoint));
153 }
154 else if (info == XLOG_PARAMETER_CHANGE)
155 {
157 const char *wal_level_str;
158
159 memcpy(&xlrec, rec, sizeof(xl_parameter_change));
161
162 appendStringInfo(buf, "max_connections=%d max_worker_processes=%d "
163 "max_wal_senders=%d max_prepared_xacts=%d "
164 "max_locks_per_xact=%d wal_level=%s "
165 "wal_log_hints=%s track_commit_timestamp=%s",
166 xlrec.MaxConnections,
167 xlrec.max_worker_processes,
168 xlrec.max_wal_senders,
169 xlrec.max_prepared_xacts,
170 xlrec.max_locks_per_xact,
172 xlrec.wal_log_hints ? "on" : "off",
173 xlrec.track_commit_timestamp ? "on" : "off");
174 }
175 else if (info == XLOG_FPW_CHANGE)
176 {
177 bool fpw;
178
179 memcpy(&fpw, rec, sizeof(bool));
180 appendStringInfoString(buf, fpw ? "true" : "false");
181 }
182 else if (info == XLOG_END_OF_RECOVERY)
183 {
185
186 memcpy(&xlrec, rec, sizeof(xl_end_of_recovery));
187 appendStringInfo(buf, "tli %u; prev tli %u; time %s; wal_level %s",
188 xlrec.ThisTimeLineID, xlrec.PrevTimeLineID,
189 timestamptz_to_str(xlrec.end_time),
190 get_wal_level_string(xlrec.wal_level));
191 }
192 else if (info == XLOG_OVERWRITE_CONTRECORD)
193 {
195
196 memcpy(&xlrec, rec, sizeof(xl_overwrite_contrecord));
197 appendStringInfo(buf, "lsn %X/%08X; time %s",
198 LSN_FORMAT_ARGS(xlrec.overwritten_lsn),
199 timestamptz_to_str(xlrec.overwrite_time));
200 }
201 else if (info == XLOG_CHECKPOINT_REDO)
202 {
204
205 memcpy(&xlrec, rec, sizeof(xl_checkpoint_redo));
206 appendStringInfo(buf, "wal_level %s; checksums %s",
207 get_wal_level_string(xlrec.wal_level),
208 get_checksum_state_string(xlrec.data_checksum_version));
209 }
211 {
212 bool enabled;
213
214 memcpy(&enabled, rec, sizeof(bool));
215 appendStringInfoString(buf, enabled ? "true" : "false");
216 }
217 else if (info == XLOG_ASSIGN_LSN)
218 {
219 /* no further information to print */
220 }
221}
const char * timestamptz_to_str(TimestampTz t)
Definition timestamp.c:1856
bool track_commit_timestamp
Definition commit_ts.c:121
#define XLOG_RESTORE_POINT
Definition pg_control.h:79
#define XLOG_FPW_CHANGE
Definition pg_control.h:80
#define XLOG_CHECKPOINT_REDO
Definition pg_control.h:86
#define XLOG_OVERWRITE_CONTRECORD
Definition pg_control.h:85
#define XLOG_ASSIGN_LSN
Definition pg_control.h:84
#define XLOG_FPI
Definition pg_control.h:83
#define XLOG_FPI_FOR_HINT
Definition pg_control.h:82
#define XLOG_NEXTOID
Definition pg_control.h:75
#define XLOG_CHECKPOINT_SHUTDOWN
Definition pg_control.h:72
#define XLOG_BACKUP_END
Definition pg_control.h:77
#define XLOG_PARAMETER_CHANGE
Definition pg_control.h:78
#define XLOG_LOGICAL_DECODING_STATUS_CHANGE
Definition pg_control.h:87
#define XLOG_CHECKPOINT_ONLINE
Definition pg_control.h:73
#define XLOG_END_OF_RECOVERY
Definition pg_control.h:81
unsigned int Oid
void appendStringInfo(StringInfo str, const char *fmt,...)
Definition stringinfo.c:145
#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:41

References appendStringInfo(), appendStringInfoString(), buf, EpochFromFullTransactionId, fb(), get_checksum_state_string(), get_wal_level_string(), LSN_FORMAT_ARGS, memcpy(), timestamptz_to_str(), 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 224 of file xlogdesc.c.

225{
226 const char *id = NULL;
227
228 switch (info & ~XLR_INFO_MASK)
229 {
231 id = "CHECKPOINT_SHUTDOWN";
232 break;
234 id = "CHECKPOINT_ONLINE";
235 break;
236 case XLOG_NOOP:
237 id = "NOOP";
238 break;
239 case XLOG_NEXTOID:
240 id = "NEXTOID";
241 break;
242 case XLOG_SWITCH:
243 id = "SWITCH";
244 break;
245 case XLOG_BACKUP_END:
246 id = "BACKUP_END";
247 break;
249 id = "PARAMETER_CHANGE";
250 break;
252 id = "RESTORE_POINT";
253 break;
254 case XLOG_FPW_CHANGE:
255 id = "FPW_CHANGE";
256 break;
258 id = "END_OF_RECOVERY";
259 break;
261 id = "OVERWRITE_CONTRECORD";
262 break;
263 case XLOG_FPI:
264 id = "FPI";
265 break;
267 id = "FPI_FOR_HINT";
268 break;
270 id = "CHECKPOINT_REDO";
271 break;
273 id = "LOGICAL_DECODING_STATUS_CHANGE";
274 break;
275 case XLOG_ASSIGN_LSN:
276 id = "ASSIGN_LSN";
277 break;
278 }
279
280 return id;
281}
#define XLOG_NOOP
Definition pg_control.h:74
#define XLOG_SWITCH
Definition pg_control.h:76

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 303 of file xlogdesc.c.

306{
307 int block_id;
308
309 Assert(record != NULL);
310
311 if (detailed_format && pretty)
313
314 for (block_id = 0; block_id <= XLogRecMaxBlockId(record); block_id++)
315 {
316 RelFileLocator rlocator;
317 ForkNumber forknum;
319
321 &rlocator, &forknum, &blk, NULL))
322 continue;
323
324 if (detailed_format)
325 {
326 /* Get block references in detailed format. */
327
328 if (pretty)
330 else if (block_id > 0)
332
334 "blkref #%d: rel %u/%u/%u fork %s blk %u",
335 block_id,
336 rlocator.spcOid, rlocator.dbOid, rlocator.relNumber,
337 forkNames[forknum],
338 blk);
339
340 if (XLogRecHasBlockImage(record, block_id))
341 {
342 uint8 bimg_info = XLogRecGetBlock(record, block_id)->bimg_info;
343
344 /* Calculate the amount of FPI data in the record. */
345 if (fpi_len)
346 *fpi_len += XLogRecGetBlock(record, block_id)->bimg_len;
347
348 if (BKPIMAGE_COMPRESSED(bimg_info))
349 {
350 const char *method;
351
352 if ((bimg_info & BKPIMAGE_COMPRESS_PGLZ) != 0)
353 method = "pglz";
354 else if ((bimg_info & BKPIMAGE_COMPRESS_LZ4) != 0)
355 method = "lz4";
356 else if ((bimg_info & BKPIMAGE_COMPRESS_ZSTD) != 0)
357 method = "zstd";
358 else
359 method = "unknown";
360
362 " (FPW%s); hole: offset: %u, length: %u, "
363 "compression saved: %u, method: %s",
365 "" : " for WAL verification",
366 XLogRecGetBlock(record, block_id)->hole_offset,
367 XLogRecGetBlock(record, block_id)->hole_length,
368 BLCKSZ -
369 XLogRecGetBlock(record, block_id)->hole_length -
370 XLogRecGetBlock(record, block_id)->bimg_len,
371 method);
372 }
373 else
374 {
376 " (FPW%s); hole: offset: %u, length: %u",
378 "" : " for WAL verification",
379 XLogRecGetBlock(record, block_id)->hole_offset,
380 XLogRecGetBlock(record, block_id)->hole_length);
381 }
382 }
383
384 if (pretty)
386 }
387 else
388 {
389 /* Get block references in short format. */
390
391 if (forknum != MAIN_FORKNUM)
392 {
394 ", blkref #%d: rel %u/%u/%u fork %s blk %u",
395 block_id,
396 rlocator.spcOid, rlocator.dbOid, rlocator.relNumber,
397 forkNames[forknum],
398 blk);
399 }
400 else
401 {
403 ", blkref #%d: rel %u/%u/%u blk %u",
404 block_id,
405 rlocator.spcOid, rlocator.dbOid, rlocator.relNumber,
406 blk);
407 }
408
409 if (XLogRecHasBlockImage(record, block_id))
410 {
411 /* Calculate the amount of FPI data in the record. */
412 if (fpi_len)
413 *fpi_len += XLogRecGetBlock(record, block_id)->bimg_len;
414
415 if (XLogRecBlockImageApply(record, block_id))
417 else
418 appendStringInfoString(buf, " FPW for WAL verification");
419 }
420 }
421 }
422
423 if (!detailed_format && pretty)
425}
uint32 BlockNumber
Definition block.h:31
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:425
#define XLogRecGetBlock(decoder, i)
Definition xlogreader.h:419
#define XLogRecMaxBlockId(decoder)
Definition xlogreader.h:418
#define XLogRecHasBlockImage(decoder, block_id)
Definition xlogreader.h:423
#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:77
@ WAL_LEVEL_LOGICAL
Definition xlog.h:78
@ WAL_LEVEL_MINIMAL
Definition xlog.h:76

Definition at line 28 of file xlogdesc.c.

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

Referenced by get_wal_level_string().