PostgreSQL Source Code  git master
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

void xlog_desc (StringInfo buf, XLogReaderState *record)
 
const char * xlog_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

◆ xlog_desc()

void xlog_desc ( StringInfo  buf,
XLogReaderState record 
)

Definition at line 37 of file xlogdesc.c.

38 {
39  char *rec = XLogRecGetData(record);
40  uint8 info = XLogRecGetInfo(record) & ~XLR_INFO_MASK;
41 
42  if (info == XLOG_CHECKPOINT_SHUTDOWN ||
43  info == XLOG_CHECKPOINT_ONLINE)
44  {
45  CheckPoint *checkpoint = (CheckPoint *) rec;
46 
47  appendStringInfo(buf, "redo %X/%X; "
48  "tli %u; prev tli %u; fpw %s; xid %u:%u; oid %u; multi %u; offset %u; "
49  "oldest xid %u in DB %u; oldest multi %u in DB %u; "
50  "oldest/newest commit timestamp xid: %u/%u; "
51  "oldest running xid %u; %s",
52  LSN_FORMAT_ARGS(checkpoint->redo),
53  checkpoint->ThisTimeLineID,
54  checkpoint->PrevTimeLineID,
55  checkpoint->fullPageWrites ? "true" : "false",
57  XidFromFullTransactionId(checkpoint->nextXid),
58  checkpoint->nextOid,
59  checkpoint->nextMulti,
60  checkpoint->nextMultiOffset,
61  checkpoint->oldestXid,
62  checkpoint->oldestXidDB,
63  checkpoint->oldestMulti,
64  checkpoint->oldestMultiDB,
65  checkpoint->oldestCommitTsXid,
66  checkpoint->newestCommitTsXid,
67  checkpoint->oldestActiveXid,
68  (info == XLOG_CHECKPOINT_SHUTDOWN) ? "shutdown" : "online");
69  }
70  else if (info == XLOG_NEXTOID)
71  {
72  Oid nextOid;
73 
74  memcpy(&nextOid, rec, sizeof(Oid));
75  appendStringInfo(buf, "%u", nextOid);
76  }
77  else if (info == XLOG_RESTORE_POINT)
78  {
79  xl_restore_point *xlrec = (xl_restore_point *) rec;
80 
82  }
83  else if (info == XLOG_FPI || info == XLOG_FPI_FOR_HINT)
84  {
85  /* no further information to print */
86  }
87  else if (info == XLOG_BACKUP_END)
88  {
89  XLogRecPtr startpoint;
90 
91  memcpy(&startpoint, rec, sizeof(XLogRecPtr));
92  appendStringInfo(buf, "%X/%X", LSN_FORMAT_ARGS(startpoint));
93  }
94  else if (info == XLOG_PARAMETER_CHANGE)
95  {
96  xl_parameter_change xlrec;
97  const char *wal_level_str;
98  const struct config_enum_entry *entry;
99 
100  memcpy(&xlrec, rec, sizeof(xl_parameter_change));
101 
102  /* Find a string representation for wal_level */
103  wal_level_str = "?";
104  for (entry = wal_level_options; entry->name; entry++)
105  {
106  if (entry->val == xlrec.wal_level)
107  {
108  wal_level_str = entry->name;
109  break;
110  }
111  }
112 
113  appendStringInfo(buf, "max_connections=%d max_worker_processes=%d "
114  "max_wal_senders=%d max_prepared_xacts=%d "
115  "max_locks_per_xact=%d wal_level=%s "
116  "wal_log_hints=%s track_commit_timestamp=%s",
117  xlrec.MaxConnections,
118  xlrec.max_worker_processes,
119  xlrec.max_wal_senders,
120  xlrec.max_prepared_xacts,
121  xlrec.max_locks_per_xact,
123  xlrec.wal_log_hints ? "on" : "off",
124  xlrec.track_commit_timestamp ? "on" : "off");
125  }
126  else if (info == XLOG_FPW_CHANGE)
127  {
128  bool fpw;
129 
130  memcpy(&fpw, rec, sizeof(bool));
131  appendStringInfoString(buf, fpw ? "true" : "false");
132  }
133  else if (info == XLOG_END_OF_RECOVERY)
134  {
135  xl_end_of_recovery xlrec;
136 
137  memcpy(&xlrec, rec, sizeof(xl_end_of_recovery));
138  appendStringInfo(buf, "tli %u; prev tli %u; time %s",
139  xlrec.ThisTimeLineID, xlrec.PrevTimeLineID,
141  }
142  else if (info == XLOG_OVERWRITE_CONTRECORD)
143  {
145 
146  memcpy(&xlrec, rec, sizeof(xl_overwrite_contrecord));
147  appendStringInfo(buf, "lsn %X/%X; time %s",
150  }
151  else if (info == XLOG_CHECKPOINT_REDO)
152  {
153  /* No details to write out */
154  }
155 }
const char * timestamptz_to_str(TimestampTz t)
Definition: timestamp.c:1853
static const char * wal_level_str(WalLevel wal_level)
unsigned char uint8
Definition: c.h:504
#define XLOG_RESTORE_POINT
Definition: pg_control.h:74
#define XLOG_FPW_CHANGE
Definition: pg_control.h:75
#define XLOG_CHECKPOINT_REDO
Definition: pg_control.h:81
#define XLOG_OVERWRITE_CONTRECORD
Definition: pg_control.h:80
#define XLOG_FPI
Definition: pg_control.h:78
#define XLOG_FPI_FOR_HINT
Definition: pg_control.h:77
#define XLOG_NEXTOID
Definition: pg_control.h:70
#define XLOG_CHECKPOINT_SHUTDOWN
Definition: pg_control.h:67
#define XLOG_BACKUP_END
Definition: pg_control.h:72
#define XLOG_PARAMETER_CHANGE
Definition: pg_control.h:73
#define XLOG_CHECKPOINT_ONLINE
Definition: pg_control.h:68
#define XLOG_END_OF_RECOVERY
Definition: pg_control.h:76
static char * buf
Definition: pg_test_fsync.c:73
unsigned int Oid
Definition: postgres_ext.h:31
void appendStringInfo(StringInfo str, const char *fmt,...)
Definition: stringinfo.c:97
void appendStringInfoString(StringInfo str, const char *s)
Definition: stringinfo.c:182
Oid oldestMultiDB
Definition: pg_control.h:50
MultiXactId oldestMulti
Definition: pg_control.h:49
MultiXactOffset nextMultiOffset
Definition: pg_control.h:46
TransactionId newestCommitTsXid
Definition: pg_control.h:54
TransactionId oldestXid
Definition: pg_control.h:47
TimeLineID PrevTimeLineID
Definition: pg_control.h:40
TimeLineID ThisTimeLineID
Definition: pg_control.h:39
Oid nextOid
Definition: pg_control.h:44
TransactionId oldestActiveXid
Definition: pg_control.h:63
bool fullPageWrites
Definition: pg_control.h:42
MultiXactId nextMulti
Definition: pg_control.h:45
FullTransactionId nextXid
Definition: pg_control.h:43
TransactionId oldestCommitTsXid
Definition: pg_control.h:52
XLogRecPtr redo
Definition: pg_control.h:37
Oid oldestXidDB
Definition: pg_control.h:48
Definition: guc.h:170
const char * name
Definition: guc.h:171
int val
Definition: guc.h:172
TimeLineID PrevTimeLineID
TimestampTz end_time
TimeLineID ThisTimeLineID
char rp_name[MAXFNAMELEN]
#define EpochFromFullTransactionId(x)
Definition: transam.h:47
#define XidFromFullTransactionId(x)
Definition: transam.h:48
#define LSN_FORMAT_ARGS(lsn)
Definition: xlogdefs.h:43
uint64 XLogRecPtr
Definition: xlogdefs.h:21
const struct config_enum_entry wal_level_options[]
Definition: xlogdesc.c:27
#define XLogRecGetInfo(decoder)
Definition: xlogreader.h:410
#define XLogRecGetData(decoder)
Definition: xlogreader.h:415
#define XLR_INFO_MASK
Definition: xlogrecord.h:62

References appendStringInfo(), appendStringInfoString(), buf, xl_end_of_recovery::end_time, EpochFromFullTransactionId, CheckPoint::fullPageWrites, LSN_FORMAT_ARGS, xl_parameter_change::max_locks_per_xact, xl_parameter_change::max_prepared_xacts, xl_parameter_change::max_wal_senders, xl_parameter_change::max_worker_processes, xl_parameter_change::MaxConnections, config_enum_entry::name, CheckPoint::newestCommitTsXid, CheckPoint::nextMulti, CheckPoint::nextMultiOffset, CheckPoint::nextOid, CheckPoint::nextXid, CheckPoint::oldestActiveXid, CheckPoint::oldestCommitTsXid, CheckPoint::oldestMulti, CheckPoint::oldestMultiDB, CheckPoint::oldestXid, CheckPoint::oldestXidDB, xl_overwrite_contrecord::overwrite_time, xl_overwrite_contrecord::overwritten_lsn, xl_end_of_recovery::PrevTimeLineID, CheckPoint::PrevTimeLineID, CheckPoint::redo, xl_restore_point::rp_name, xl_end_of_recovery::ThisTimeLineID, CheckPoint::ThisTimeLineID, timestamptz_to_str(), xl_parameter_change::track_commit_timestamp, config_enum_entry::val, xl_parameter_change::wal_level, wal_level_options, wal_level_str(), xl_parameter_change::wal_log_hints, XidFromFullTransactionId, 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_NEXTOID, XLOG_OVERWRITE_CONTRECORD, XLOG_PARAMETER_CHANGE, XLOG_RESTORE_POINT, XLogRecGetData, XLogRecGetInfo, and XLR_INFO_MASK.

◆ xlog_identify()

const char* xlog_identify ( uint8  info)

Definition at line 158 of file xlogdesc.c.

159 {
160  const char *id = NULL;
161 
162  switch (info & ~XLR_INFO_MASK)
163  {
165  id = "CHECKPOINT_SHUTDOWN";
166  break;
168  id = "CHECKPOINT_ONLINE";
169  break;
170  case XLOG_NOOP:
171  id = "NOOP";
172  break;
173  case XLOG_NEXTOID:
174  id = "NEXTOID";
175  break;
176  case XLOG_SWITCH:
177  id = "SWITCH";
178  break;
179  case XLOG_BACKUP_END:
180  id = "BACKUP_END";
181  break;
183  id = "PARAMETER_CHANGE";
184  break;
185  case XLOG_RESTORE_POINT:
186  id = "RESTORE_POINT";
187  break;
188  case XLOG_FPW_CHANGE:
189  id = "FPW_CHANGE";
190  break;
192  id = "END_OF_RECOVERY";
193  break;
195  id = "OVERWRITE_CONTRECORD";
196  break;
197  case XLOG_FPI:
198  id = "FPI";
199  break;
200  case XLOG_FPI_FOR_HINT:
201  id = "FPI_FOR_HINT";
202  break;
204  id = "CHECKPOINT_REDO";
205  break;
206  }
207 
208  return id;
209 }
#define XLOG_NOOP
Definition: pg_control.h:69
#define XLOG_SWITCH
Definition: pg_control.h:71

References 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_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 216 of file xlogdesc.c.

219 {
220  int block_id;
221 
222  Assert(record != NULL);
223 
224  if (detailed_format && pretty)
225  appendStringInfoChar(buf, '\n');
226 
227  for (block_id = 0; block_id <= XLogRecMaxBlockId(record); block_id++)
228  {
229  RelFileLocator rlocator;
230  ForkNumber forknum;
231  BlockNumber blk;
232 
233  if (!XLogRecGetBlockTagExtended(record, block_id,
234  &rlocator, &forknum, &blk, NULL))
235  continue;
236 
237  if (detailed_format)
238  {
239  /* Get block references in detailed format. */
240 
241  if (pretty)
242  appendStringInfoChar(buf, '\t');
243  else if (block_id > 0)
245 
247  "blkref #%d: rel %u/%u/%u fork %s blk %u",
248  block_id,
249  rlocator.spcOid, rlocator.dbOid, rlocator.relNumber,
250  forkNames[forknum],
251  blk);
252 
253  if (XLogRecHasBlockImage(record, block_id))
254  {
255  uint8 bimg_info = XLogRecGetBlock(record, block_id)->bimg_info;
256 
257  /* Calculate the amount of FPI data in the record. */
258  if (fpi_len)
259  *fpi_len += XLogRecGetBlock(record, block_id)->bimg_len;
260 
261  if (BKPIMAGE_COMPRESSED(bimg_info))
262  {
263  const char *method;
264 
265  if ((bimg_info & BKPIMAGE_COMPRESS_PGLZ) != 0)
266  method = "pglz";
267  else if ((bimg_info & BKPIMAGE_COMPRESS_LZ4) != 0)
268  method = "lz4";
269  else if ((bimg_info & BKPIMAGE_COMPRESS_ZSTD) != 0)
270  method = "zstd";
271  else
272  method = "unknown";
273 
275  " (FPW%s); hole: offset: %u, length: %u, "
276  "compression saved: %u, method: %s",
277  XLogRecBlockImageApply(record, block_id) ?
278  "" : " for WAL verification",
279  XLogRecGetBlock(record, block_id)->hole_offset,
280  XLogRecGetBlock(record, block_id)->hole_length,
281  BLCKSZ -
282  XLogRecGetBlock(record, block_id)->hole_length -
283  XLogRecGetBlock(record, block_id)->bimg_len,
284  method);
285  }
286  else
287  {
289  " (FPW%s); hole: offset: %u, length: %u",
290  XLogRecBlockImageApply(record, block_id) ?
291  "" : " for WAL verification",
292  XLogRecGetBlock(record, block_id)->hole_offset,
293  XLogRecGetBlock(record, block_id)->hole_length);
294  }
295  }
296 
297  if (pretty)
298  appendStringInfoChar(buf, '\n');
299  }
300  else
301  {
302  /* Get block references in short format. */
303 
304  if (forknum != MAIN_FORKNUM)
305  {
307  ", blkref #%d: rel %u/%u/%u fork %s blk %u",
308  block_id,
309  rlocator.spcOid, rlocator.dbOid, rlocator.relNumber,
310  forkNames[forknum],
311  blk);
312  }
313  else
314  {
316  ", blkref #%d: rel %u/%u/%u blk %u",
317  block_id,
318  rlocator.spcOid, rlocator.dbOid, rlocator.relNumber,
319  blk);
320  }
321 
322  if (XLogRecHasBlockImage(record, block_id))
323  {
324  /* Calculate the amount of FPI data in the record. */
325  if (fpi_len)
326  *fpi_len += XLogRecGetBlock(record, block_id)->bimg_len;
327 
328  if (XLogRecBlockImageApply(record, block_id))
329  appendStringInfoString(buf, " FPW");
330  else
331  appendStringInfoString(buf, " FPW for WAL verification");
332  }
333  }
334  }
335 
336  if (!detailed_format && pretty)
337  appendStringInfoChar(buf, '\n');
338 }
uint32 BlockNumber
Definition: block.h:31
#define Assert(condition)
Definition: c.h:858
const char *const forkNames[]
Definition: relpath.c:33
ForkNumber
Definition: relpath.h:48
@ MAIN_FORKNUM
Definition: relpath.h:50
void appendStringInfoChar(StringInfo str, char ch)
Definition: stringinfo.c:194
RelFileNumber relNumber
bool XLogRecGetBlockTagExtended(XLogReaderState *record, uint8 block_id, RelFileLocator *rlocator, ForkNumber *forknum, BlockNumber *blknum, Buffer *prefetch_buffer)
Definition: xlogreader.c:1997
#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, 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:73
@ WAL_LEVEL_LOGICAL
Definition: xlog.h:74
@ WAL_LEVEL_MINIMAL
Definition: xlog.h:72

Definition at line 1 of file xlogdesc.c.

Referenced by xlog_desc().