PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
xlogdesc.c
Go to the documentation of this file.
1 /*-------------------------------------------------------------------------
2  *
3  * xlogdesc.c
4  * rmgr descriptor routines for access/transam/xlog.c
5  *
6  * Portions Copyright (c) 1996-2017, PostgreSQL Global Development Group
7  * Portions Copyright (c) 1994, Regents of the University of California
8  *
9  *
10  * IDENTIFICATION
11  * src/backend/access/rmgrdesc/xlogdesc.c
12  *
13  *-------------------------------------------------------------------------
14  */
15 #include "postgres.h"
16 
17 #include "access/xlog.h"
18 #include "access/xlog_internal.h"
19 #include "catalog/pg_control.h"
20 #include "utils/guc.h"
21 #include "utils/timestamp.h"
22 
23 /*
24  * GUC support
25  */
27  {"minimal", WAL_LEVEL_MINIMAL, false},
28  {"replica", WAL_LEVEL_REPLICA, false},
29  {"archive", WAL_LEVEL_REPLICA, true}, /* deprecated */
30  {"hot_standby", WAL_LEVEL_REPLICA, true}, /* deprecated */
31  {"logical", WAL_LEVEL_LOGICAL, false},
32  {NULL, 0, false}
33 };
34 
35 void
37 {
38  char *rec = XLogRecGetData(record);
39  uint8 info = XLogRecGetInfo(record) & ~XLR_INFO_MASK;
40 
41  if (info == XLOG_CHECKPOINT_SHUTDOWN ||
42  info == XLOG_CHECKPOINT_ONLINE)
43  {
44  CheckPoint *checkpoint = (CheckPoint *) rec;
45 
46  appendStringInfo(buf, "redo %X/%X; "
47  "tli %u; prev tli %u; fpw %s; xid %u:%u; oid %u; multi %u; offset %u; "
48  "oldest xid %u in DB %u; oldest multi %u in DB %u; "
49  "oldest/newest commit timestamp xid: %u/%u; "
50  "oldest running xid %u; %s",
51  (uint32) (checkpoint->redo >> 32), (uint32) checkpoint->redo,
52  checkpoint->ThisTimeLineID,
53  checkpoint->PrevTimeLineID,
54  checkpoint->fullPageWrites ? "true" : "false",
55  checkpoint->nextXidEpoch, checkpoint->nextXid,
56  checkpoint->nextOid,
57  checkpoint->nextMulti,
58  checkpoint->nextMultiOffset,
59  checkpoint->oldestXid,
60  checkpoint->oldestXidDB,
61  checkpoint->oldestMulti,
62  checkpoint->oldestMultiDB,
63  checkpoint->oldestCommitTsXid,
64  checkpoint->newestCommitTsXid,
65  checkpoint->oldestActiveXid,
66  (info == XLOG_CHECKPOINT_SHUTDOWN) ? "shutdown" : "online");
67  }
68  else if (info == XLOG_NEXTOID)
69  {
70  Oid nextOid;
71 
72  memcpy(&nextOid, rec, sizeof(Oid));
73  appendStringInfo(buf, "%u", nextOid);
74  }
75  else if (info == XLOG_RESTORE_POINT)
76  {
77  xl_restore_point *xlrec = (xl_restore_point *) rec;
78 
79  appendStringInfoString(buf, xlrec->rp_name);
80  }
81  else if (info == XLOG_FPI || info == XLOG_FPI_FOR_HINT)
82  {
83  /* no further information to print */
84  }
85  else if (info == XLOG_BACKUP_END)
86  {
87  XLogRecPtr startpoint;
88 
89  memcpy(&startpoint, rec, sizeof(XLogRecPtr));
90  appendStringInfo(buf, "%X/%X",
91  (uint32) (startpoint >> 32), (uint32) startpoint);
92  }
93  else if (info == XLOG_PARAMETER_CHANGE)
94  {
95  xl_parameter_change xlrec;
96  const char *wal_level_str;
97  const struct config_enum_entry *entry;
98 
99  memcpy(&xlrec, rec, sizeof(xl_parameter_change));
100 
101  /* Find a string representation for wal_level */
102  wal_level_str = "?";
103  for (entry = wal_level_options; entry->name; entry++)
104  {
105  if (entry->val == xlrec.wal_level)
106  {
107  wal_level_str = entry->name;
108  break;
109  }
110  }
111 
112  appendStringInfo(buf, "max_connections=%d max_worker_processes=%d "
113  "max_prepared_xacts=%d max_locks_per_xact=%d "
114  "wal_level=%s wal_log_hints=%s "
115  "track_commit_timestamp=%s",
116  xlrec.MaxConnections,
117  xlrec.max_worker_processes,
118  xlrec.max_prepared_xacts,
119  xlrec.max_locks_per_xact,
120  wal_level_str,
121  xlrec.wal_log_hints ? "on" : "off",
122  xlrec.track_commit_timestamp ? "on" : "off");
123  }
124  else if (info == XLOG_FPW_CHANGE)
125  {
126  bool fpw;
127 
128  memcpy(&fpw, rec, sizeof(bool));
129  appendStringInfoString(buf, fpw ? "true" : "false");
130  }
131  else if (info == XLOG_END_OF_RECOVERY)
132  {
133  xl_end_of_recovery xlrec;
134 
135  memcpy(&xlrec, rec, sizeof(xl_end_of_recovery));
136  appendStringInfo(buf, "tli %u; prev tli %u; time %s",
137  xlrec.ThisTimeLineID, xlrec.PrevTimeLineID,
139  }
140 }
141 
142 const char *
144 {
145  const char *id = NULL;
146 
147  switch (info & ~XLR_INFO_MASK)
148  {
150  id = "CHECKPOINT_SHUTDOWN";
151  break;
153  id = "CHECKPOINT_ONLINE";
154  break;
155  case XLOG_NOOP:
156  id = "NOOP";
157  break;
158  case XLOG_NEXTOID:
159  id = "NEXTOID";
160  break;
161  case XLOG_SWITCH:
162  id = "SWITCH";
163  break;
164  case XLOG_BACKUP_END:
165  id = "BACKUP_END";
166  break;
168  id = "PARAMETER_CHANGE";
169  break;
170  case XLOG_RESTORE_POINT:
171  id = "RESTORE_POINT";
172  break;
173  case XLOG_FPW_CHANGE:
174  id = "FPW_CHANGE";
175  break;
177  id = "END_OF_RECOVERY";
178  break;
179  case XLOG_FPI:
180  id = "FPI";
181  break;
182  case XLOG_FPI_FOR_HINT:
183  id = "FPI_FOR_HINT";
184  break;
185  }
186 
187  return id;
188 }
static const char * wal_level_str(WalLevel wal_level)
#define XLOG_FPW_CHANGE
Definition: pg_control.h:74
#define XLOG_CHECKPOINT_ONLINE
Definition: pg_control.h:67
Definition: guc.h:164
TimeLineID PrevTimeLineID
void xlog_desc(StringInfo buf, XLogReaderState *record)
Definition: xlogdesc.c:36
TransactionId oldestActiveXid
Definition: pg_control.h:62
unsigned char uint8
Definition: c.h:266
MultiXactId oldestMulti
Definition: pg_control.h:48
TimeLineID PrevTimeLineID
Definition: pg_control.h:38
#define XLOG_RESTORE_POINT
Definition: pg_control.h:73
TransactionId oldestXid
Definition: pg_control.h:46
unsigned int Oid
Definition: postgres_ext.h:31
TransactionId nextXid
Definition: pg_control.h:42
#define XLOG_END_OF_RECOVERY
Definition: pg_control.h:75
MultiXactOffset nextMultiOffset
Definition: pg_control.h:45
#define XLOG_NEXTOID
Definition: pg_control.h:69
char rp_name[MAXFNAMELEN]
TransactionId oldestCommitTsXid
Definition: pg_control.h:51
#define XLogRecGetData(decoder)
Definition: xlogreader.h:220
void appendStringInfo(StringInfo str, const char *fmt,...)
Definition: stringinfo.c:78
#define XLOG_PARAMETER_CHANGE
Definition: pg_control.h:72
uint32 nextXidEpoch
Definition: pg_control.h:41
void appendStringInfoString(StringInfo str, const char *s)
Definition: stringinfo.c:157
static char * buf
Definition: pg_test_fsync.c:66
#define XLOG_CHECKPOINT_SHUTDOWN
Definition: pg_control.h:66
unsigned int uint32
Definition: c.h:268
#define XLOG_BACKUP_END
Definition: pg_control.h:71
#define XLogRecGetInfo(decoder)
Definition: xlogreader.h:216
int val
Definition: guc.h:167
TransactionId newestCommitTsXid
Definition: pg_control.h:53
#define XLOG_NOOP
Definition: pg_control.h:68
Oid oldestMultiDB
Definition: pg_control.h:49
Oid nextOid
Definition: pg_control.h:43
bool fullPageWrites
Definition: pg_control.h:40
TimestampTz end_time
#define NULL
Definition: c.h:229
uint64 XLogRecPtr
Definition: xlogdefs.h:21
#define XLR_INFO_MASK
Definition: xlogrecord.h:62
Oid oldestXidDB
Definition: pg_control.h:47
#define XLOG_FPI_FOR_HINT
Definition: pg_control.h:76
MultiXactId nextMulti
Definition: pg_control.h:44
#define XLOG_SWITCH
Definition: pg_control.h:70
const char * name
Definition: guc.h:166
const struct config_enum_entry wal_level_options[]
Definition: xlogdesc.c:26
const char * xlog_identify(uint8 info)
Definition: xlogdesc.c:143
TimeLineID ThisTimeLineID
#define XLOG_FPI
Definition: pg_control.h:77
TimeLineID ThisTimeLineID
Definition: pg_control.h:37
XLogRecPtr redo
Definition: pg_control.h:35
const char * timestamptz_to_str(TimestampTz t)
Definition: timestamp.c:1710