Coverage Report

Created: 2025-06-15 06:31

/src/postgres/src/include/access/xlog_internal.h
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * xlog_internal.h
3
 *
4
 * PostgreSQL write-ahead log internal declarations
5
 *
6
 * NOTE: this file is intended to contain declarations useful for
7
 * manipulating the XLOG files directly, but it is not supposed to be
8
 * needed by rmgr routines (redo support for individual record types).
9
 * So the XLogRecord typedef and associated stuff appear in xlogrecord.h.
10
 *
11
 * Note: This file must be includable in both frontend and backend contexts,
12
 * to allow stand-alone tools like pg_receivewal to deal with WAL files.
13
 *
14
 * Portions Copyright (c) 1996-2025, PostgreSQL Global Development Group
15
 * Portions Copyright (c) 1994, Regents of the University of California
16
 *
17
 * src/include/access/xlog_internal.h
18
 */
19
#ifndef XLOG_INTERNAL_H
20
#define XLOG_INTERNAL_H
21
22
#include "access/xlogdefs.h"
23
#include "access/xlogreader.h"
24
#include "datatype/timestamp.h"
25
#include "lib/stringinfo.h"
26
#include "pgtime.h"
27
#include "storage/block.h"
28
#include "storage/relfilelocator.h"
29
30
31
/*
32
 * Each page of XLOG file has a header like this:
33
 */
34
0
#define XLOG_PAGE_MAGIC 0xD118  /* can be used as WAL version indicator */
35
36
typedef struct XLogPageHeaderData
37
{
38
  uint16    xlp_magic;    /* magic value for correctness checks */
39
  uint16    xlp_info;   /* flag bits, see below */
40
  TimeLineID  xlp_tli;    /* TimeLineID of first record on page */
41
  XLogRecPtr  xlp_pageaddr; /* XLOG address of this page */
42
43
  /*
44
   * When there is not enough space on current page for whole record, we
45
   * continue on the next page.  xlp_rem_len is the number of bytes
46
   * remaining from a previous page; it tracks xl_tot_len in the initial
47
   * header.  Note that the continuation data isn't necessarily aligned.
48
   */
49
  uint32    xlp_rem_len;  /* total len of remaining data for record */
50
} XLogPageHeaderData;
51
52
0
#define SizeOfXLogShortPHD  MAXALIGN(sizeof(XLogPageHeaderData))
53
54
typedef XLogPageHeaderData *XLogPageHeader;
55
56
/*
57
 * When the XLP_LONG_HEADER flag is set, we store additional fields in the
58
 * page header.  (This is ordinarily done just in the first page of an
59
 * XLOG file.)  The additional fields serve to identify the file accurately.
60
 */
61
typedef struct XLogLongPageHeaderData
62
{
63
  XLogPageHeaderData std;   /* standard header fields */
64
  uint64    xlp_sysid;    /* system identifier from pg_control */
65
  uint32    xlp_seg_size; /* just as a cross-check */
66
  uint32    xlp_xlog_blcksz;  /* just as a cross-check */
67
} XLogLongPageHeaderData;
68
69
0
#define SizeOfXLogLongPHD MAXALIGN(sizeof(XLogLongPageHeaderData))
70
71
typedef XLogLongPageHeaderData *XLogLongPageHeader;
72
73
/* When record crosses page boundary, set this flag in new page's header */
74
0
#define XLP_FIRST_IS_CONTRECORD   0x0001
75
/* This flag indicates a "long" page header */
76
0
#define XLP_LONG_HEADER       0x0002
77
/* This flag indicates backup blocks starting in this page are optional */
78
0
#define XLP_BKP_REMOVABLE     0x0004
79
/* Replaces a missing contrecord; see CreateOverwriteContrecordRecord */
80
0
#define XLP_FIRST_IS_OVERWRITE_CONTRECORD 0x0008
81
/* All defined flag bits in xlp_info (used for validity checking of header) */
82
0
#define XLP_ALL_FLAGS       0x000F
83
84
#define XLogPageHeaderSize(hdr)   \
85
0
  (((hdr)->xlp_info & XLP_LONG_HEADER) ? SizeOfXLogLongPHD : SizeOfXLogShortPHD)
86
87
/* wal_segment_size can range from 1MB to 1GB */
88
0
#define WalSegMinSize 1024 * 1024
89
0
#define WalSegMaxSize 1024 * 1024 * 1024
90
/* default number of min and max wal segments */
91
#define DEFAULT_MIN_WAL_SEGS 5
92
#define DEFAULT_MAX_WAL_SEGS 64
93
94
/* check that the given size is a valid wal_segment_size */
95
0
#define IsPowerOf2(x) (x > 0 && ((x) & ((x)-1)) == 0)
96
#define IsValidWalSegSize(size) \
97
0
   (IsPowerOf2(size) && \
98
0
   ((size) >= WalSegMinSize && (size) <= WalSegMaxSize))
99
100
#define XLogSegmentsPerXLogId(wal_segsz_bytes)  \
101
0
  (UINT64CONST(0x100000000) / (wal_segsz_bytes))
102
103
#define XLogSegNoOffsetToRecPtr(segno, offset, wal_segsz_bytes, dest) \
104
0
    (dest) = (segno) * (wal_segsz_bytes) + (offset)
105
106
#define XLogSegmentOffset(xlogptr, wal_segsz_bytes) \
107
0
  ((xlogptr) & ((wal_segsz_bytes) - 1))
108
109
/*
110
 * Compute a segment number from an XLogRecPtr.
111
 *
112
 * For XLByteToSeg, do the computation at face value.  For XLByteToPrevSeg,
113
 * a boundary byte is taken to be in the previous segment.  This is suitable
114
 * for deciding which segment to write given a pointer to a record end,
115
 * for example.
116
 */
117
#define XLByteToSeg(xlrp, logSegNo, wal_segsz_bytes) \
118
0
  logSegNo = (xlrp) / (wal_segsz_bytes)
119
120
#define XLByteToPrevSeg(xlrp, logSegNo, wal_segsz_bytes) \
121
0
  logSegNo = ((xlrp) - 1) / (wal_segsz_bytes)
122
123
/*
124
 * Convert values of GUCs measured in megabytes to equiv. segment count.
125
 * Rounds down.
126
 */
127
#define XLogMBVarToSegs(mbvar, wal_segsz_bytes) \
128
0
  ((mbvar) / ((wal_segsz_bytes) / (1024 * 1024)))
129
130
/*
131
 * Is an XLogRecPtr within a particular XLOG segment?
132
 *
133
 * For XLByteInSeg, do the computation at face value.  For XLByteInPrevSeg,
134
 * a boundary byte is taken to be in the previous segment.
135
 */
136
#define XLByteInSeg(xlrp, logSegNo, wal_segsz_bytes) \
137
0
  (((xlrp) / (wal_segsz_bytes)) == (logSegNo))
138
139
#define XLByteInPrevSeg(xlrp, logSegNo, wal_segsz_bytes) \
140
0
  ((((xlrp) - 1) / (wal_segsz_bytes)) == (logSegNo))
141
142
/* Check if an XLogRecPtr value is in a plausible range */
143
#define XRecOffIsValid(xlrp) \
144
0
    ((xlrp) % XLOG_BLCKSZ >= SizeOfXLogShortPHD)
145
146
/*
147
 * The XLog directory and control file (relative to $PGDATA)
148
 */
149
0
#define XLOGDIR       "pg_wal"
150
0
#define XLOG_CONTROL_FILE "global/pg_control"
151
152
/*
153
 * These macros encapsulate knowledge about the exact layout of XLog file
154
 * names, timeline history file names, and archive-status file names.
155
 */
156
0
#define MAXFNAMELEN   64
157
158
/* Length of XLog file name */
159
0
#define XLOG_FNAME_LEN     24
160
161
/*
162
 * Generate a WAL segment file name.  Do not use this function in a helper
163
 * function allocating the result generated.
164
 */
165
static inline void
166
XLogFileName(char *fname, TimeLineID tli, XLogSegNo logSegNo, int wal_segsz_bytes)
167
0
{
168
0
  snprintf(fname, MAXFNAMELEN, "%08X%08X%08X", tli,
169
0
       (uint32) (logSegNo / XLogSegmentsPerXLogId(wal_segsz_bytes)),
170
0
       (uint32) (logSegNo % XLogSegmentsPerXLogId(wal_segsz_bytes)));
171
0
}
Unexecuted instantiation: xlogdesc.c:XLogFileName
Unexecuted instantiation: rmgr.c:XLogFileName
Unexecuted instantiation: timeline.c:XLogFileName
Unexecuted instantiation: xlog.c:XLogFileName
Unexecuted instantiation: xlogarchive.c:XLogFileName
Unexecuted instantiation: xlogbackup.c:XLogFileName
Unexecuted instantiation: xlogfuncs.c:XLogFileName
Unexecuted instantiation: xloginsert.c:XLogFileName
Unexecuted instantiation: xlogreader.c:XLogFileName
Unexecuted instantiation: xlogrecovery.c:XLogFileName
Unexecuted instantiation: xlogutils.c:XLogFileName
Unexecuted instantiation: checkpointer.c:XLogFileName
Unexecuted instantiation: pgarch.c:XLogFileName
Unexecuted instantiation: postmaster.c:XLogFileName
Unexecuted instantiation: walsummarizer.c:XLogFileName
Unexecuted instantiation: decode.c:XLogFileName
Unexecuted instantiation: logical.c:XLogFileName
Unexecuted instantiation: reorderbuffer.c:XLogFileName
Unexecuted instantiation: slotsync.c:XLogFileName
Unexecuted instantiation: slot.c:XLogFileName
Unexecuted instantiation: slotfuncs.c:XLogFileName
Unexecuted instantiation: walreceiver.c:XLogFileName
Unexecuted instantiation: walreceiverfuncs.c:XLogFileName
Unexecuted instantiation: walsender.c:XLogFileName
Unexecuted instantiation: basebackup.c:XLogFileName
Unexecuted instantiation: walsummary.c:XLogFileName
Unexecuted instantiation: genfile.c:XLogFileName
Unexecuted instantiation: guc_tables.c:XLogFileName
Unexecuted instantiation: pg_controldata.c:XLogFileName
Unexecuted instantiation: controldata_utils.c:XLogFileName
172
173
static inline void
174
XLogFileNameById(char *fname, TimeLineID tli, uint32 log, uint32 seg)
175
0
{
176
0
  snprintf(fname, MAXFNAMELEN, "%08X%08X%08X", tli, log, seg);
177
0
}
Unexecuted instantiation: xlogdesc.c:XLogFileNameById
Unexecuted instantiation: rmgr.c:XLogFileNameById
Unexecuted instantiation: timeline.c:XLogFileNameById
Unexecuted instantiation: xlog.c:XLogFileNameById
Unexecuted instantiation: xlogarchive.c:XLogFileNameById
Unexecuted instantiation: xlogbackup.c:XLogFileNameById
Unexecuted instantiation: xlogfuncs.c:XLogFileNameById
Unexecuted instantiation: xloginsert.c:XLogFileNameById
Unexecuted instantiation: xlogreader.c:XLogFileNameById
Unexecuted instantiation: xlogrecovery.c:XLogFileNameById
Unexecuted instantiation: xlogutils.c:XLogFileNameById
Unexecuted instantiation: checkpointer.c:XLogFileNameById
Unexecuted instantiation: pgarch.c:XLogFileNameById
Unexecuted instantiation: postmaster.c:XLogFileNameById
Unexecuted instantiation: walsummarizer.c:XLogFileNameById
Unexecuted instantiation: decode.c:XLogFileNameById
Unexecuted instantiation: logical.c:XLogFileNameById
Unexecuted instantiation: reorderbuffer.c:XLogFileNameById
Unexecuted instantiation: slotsync.c:XLogFileNameById
Unexecuted instantiation: slot.c:XLogFileNameById
Unexecuted instantiation: slotfuncs.c:XLogFileNameById
Unexecuted instantiation: walreceiver.c:XLogFileNameById
Unexecuted instantiation: walreceiverfuncs.c:XLogFileNameById
Unexecuted instantiation: walsender.c:XLogFileNameById
Unexecuted instantiation: basebackup.c:XLogFileNameById
Unexecuted instantiation: walsummary.c:XLogFileNameById
Unexecuted instantiation: genfile.c:XLogFileNameById
Unexecuted instantiation: guc_tables.c:XLogFileNameById
Unexecuted instantiation: pg_controldata.c:XLogFileNameById
Unexecuted instantiation: controldata_utils.c:XLogFileNameById
178
179
static inline bool
180
IsXLogFileName(const char *fname)
181
0
{
182
0
  return (strlen(fname) == XLOG_FNAME_LEN && \
183
0
      strspn(fname, "0123456789ABCDEF") == XLOG_FNAME_LEN);
184
0
}
Unexecuted instantiation: xlogdesc.c:IsXLogFileName
Unexecuted instantiation: rmgr.c:IsXLogFileName
Unexecuted instantiation: timeline.c:IsXLogFileName
Unexecuted instantiation: xlog.c:IsXLogFileName
Unexecuted instantiation: xlogarchive.c:IsXLogFileName
Unexecuted instantiation: xlogbackup.c:IsXLogFileName
Unexecuted instantiation: xlogfuncs.c:IsXLogFileName
Unexecuted instantiation: xloginsert.c:IsXLogFileName
Unexecuted instantiation: xlogreader.c:IsXLogFileName
Unexecuted instantiation: xlogrecovery.c:IsXLogFileName
Unexecuted instantiation: xlogutils.c:IsXLogFileName
Unexecuted instantiation: checkpointer.c:IsXLogFileName
Unexecuted instantiation: pgarch.c:IsXLogFileName
Unexecuted instantiation: postmaster.c:IsXLogFileName
Unexecuted instantiation: walsummarizer.c:IsXLogFileName
Unexecuted instantiation: decode.c:IsXLogFileName
Unexecuted instantiation: logical.c:IsXLogFileName
Unexecuted instantiation: reorderbuffer.c:IsXLogFileName
Unexecuted instantiation: slotsync.c:IsXLogFileName
Unexecuted instantiation: slot.c:IsXLogFileName
Unexecuted instantiation: slotfuncs.c:IsXLogFileName
Unexecuted instantiation: walreceiver.c:IsXLogFileName
Unexecuted instantiation: walreceiverfuncs.c:IsXLogFileName
Unexecuted instantiation: walsender.c:IsXLogFileName
Unexecuted instantiation: basebackup.c:IsXLogFileName
Unexecuted instantiation: walsummary.c:IsXLogFileName
Unexecuted instantiation: genfile.c:IsXLogFileName
Unexecuted instantiation: guc_tables.c:IsXLogFileName
Unexecuted instantiation: pg_controldata.c:IsXLogFileName
Unexecuted instantiation: controldata_utils.c:IsXLogFileName
185
186
/*
187
 * XLOG segment with .partial suffix.  Used by pg_receivewal and at end of
188
 * archive recovery, when we want to archive a WAL segment but it might not
189
 * be complete yet.
190
 */
191
static inline bool
192
IsPartialXLogFileName(const char *fname)
193
0
{
194
0
  return (strlen(fname) == XLOG_FNAME_LEN + strlen(".partial") &&
195
0
      strspn(fname, "0123456789ABCDEF") == XLOG_FNAME_LEN &&
196
0
      strcmp(fname + XLOG_FNAME_LEN, ".partial") == 0);
197
0
}
Unexecuted instantiation: xlogdesc.c:IsPartialXLogFileName
Unexecuted instantiation: rmgr.c:IsPartialXLogFileName
Unexecuted instantiation: timeline.c:IsPartialXLogFileName
Unexecuted instantiation: xlog.c:IsPartialXLogFileName
Unexecuted instantiation: xlogarchive.c:IsPartialXLogFileName
Unexecuted instantiation: xlogbackup.c:IsPartialXLogFileName
Unexecuted instantiation: xlogfuncs.c:IsPartialXLogFileName
Unexecuted instantiation: xloginsert.c:IsPartialXLogFileName
Unexecuted instantiation: xlogreader.c:IsPartialXLogFileName
Unexecuted instantiation: xlogrecovery.c:IsPartialXLogFileName
Unexecuted instantiation: xlogutils.c:IsPartialXLogFileName
Unexecuted instantiation: checkpointer.c:IsPartialXLogFileName
Unexecuted instantiation: pgarch.c:IsPartialXLogFileName
Unexecuted instantiation: postmaster.c:IsPartialXLogFileName
Unexecuted instantiation: walsummarizer.c:IsPartialXLogFileName
Unexecuted instantiation: decode.c:IsPartialXLogFileName
Unexecuted instantiation: logical.c:IsPartialXLogFileName
Unexecuted instantiation: reorderbuffer.c:IsPartialXLogFileName
Unexecuted instantiation: slotsync.c:IsPartialXLogFileName
Unexecuted instantiation: slot.c:IsPartialXLogFileName
Unexecuted instantiation: slotfuncs.c:IsPartialXLogFileName
Unexecuted instantiation: walreceiver.c:IsPartialXLogFileName
Unexecuted instantiation: walreceiverfuncs.c:IsPartialXLogFileName
Unexecuted instantiation: walsender.c:IsPartialXLogFileName
Unexecuted instantiation: basebackup.c:IsPartialXLogFileName
Unexecuted instantiation: walsummary.c:IsPartialXLogFileName
Unexecuted instantiation: genfile.c:IsPartialXLogFileName
Unexecuted instantiation: guc_tables.c:IsPartialXLogFileName
Unexecuted instantiation: pg_controldata.c:IsPartialXLogFileName
Unexecuted instantiation: controldata_utils.c:IsPartialXLogFileName
198
199
static inline void
200
XLogFromFileName(const char *fname, TimeLineID *tli, XLogSegNo *logSegNo, int wal_segsz_bytes)
201
0
{
202
0
  uint32    log;
203
0
  uint32    seg;
204
205
0
  sscanf(fname, "%08X%08X%08X", tli, &log, &seg);
206
0
  *logSegNo = (uint64) log * XLogSegmentsPerXLogId(wal_segsz_bytes) + seg;
207
0
}
Unexecuted instantiation: xlogdesc.c:XLogFromFileName
Unexecuted instantiation: rmgr.c:XLogFromFileName
Unexecuted instantiation: timeline.c:XLogFromFileName
Unexecuted instantiation: xlog.c:XLogFromFileName
Unexecuted instantiation: xlogarchive.c:XLogFromFileName
Unexecuted instantiation: xlogbackup.c:XLogFromFileName
Unexecuted instantiation: xlogfuncs.c:XLogFromFileName
Unexecuted instantiation: xloginsert.c:XLogFromFileName
Unexecuted instantiation: xlogreader.c:XLogFromFileName
Unexecuted instantiation: xlogrecovery.c:XLogFromFileName
Unexecuted instantiation: xlogutils.c:XLogFromFileName
Unexecuted instantiation: checkpointer.c:XLogFromFileName
Unexecuted instantiation: pgarch.c:XLogFromFileName
Unexecuted instantiation: postmaster.c:XLogFromFileName
Unexecuted instantiation: walsummarizer.c:XLogFromFileName
Unexecuted instantiation: decode.c:XLogFromFileName
Unexecuted instantiation: logical.c:XLogFromFileName
Unexecuted instantiation: reorderbuffer.c:XLogFromFileName
Unexecuted instantiation: slotsync.c:XLogFromFileName
Unexecuted instantiation: slot.c:XLogFromFileName
Unexecuted instantiation: slotfuncs.c:XLogFromFileName
Unexecuted instantiation: walreceiver.c:XLogFromFileName
Unexecuted instantiation: walreceiverfuncs.c:XLogFromFileName
Unexecuted instantiation: walsender.c:XLogFromFileName
Unexecuted instantiation: basebackup.c:XLogFromFileName
Unexecuted instantiation: walsummary.c:XLogFromFileName
Unexecuted instantiation: genfile.c:XLogFromFileName
Unexecuted instantiation: guc_tables.c:XLogFromFileName
Unexecuted instantiation: pg_controldata.c:XLogFromFileName
Unexecuted instantiation: controldata_utils.c:XLogFromFileName
208
209
static inline void
210
XLogFilePath(char *path, TimeLineID tli, XLogSegNo logSegNo, int wal_segsz_bytes)
211
0
{
212
0
  snprintf(path, MAXPGPATH, XLOGDIR "/%08X%08X%08X", tli,
213
0
       (uint32) (logSegNo / XLogSegmentsPerXLogId(wal_segsz_bytes)),
214
0
       (uint32) (logSegNo % XLogSegmentsPerXLogId(wal_segsz_bytes)));
215
0
}
Unexecuted instantiation: xlogdesc.c:XLogFilePath
Unexecuted instantiation: rmgr.c:XLogFilePath
Unexecuted instantiation: timeline.c:XLogFilePath
Unexecuted instantiation: xlog.c:XLogFilePath
Unexecuted instantiation: xlogarchive.c:XLogFilePath
Unexecuted instantiation: xlogbackup.c:XLogFilePath
Unexecuted instantiation: xlogfuncs.c:XLogFilePath
Unexecuted instantiation: xloginsert.c:XLogFilePath
Unexecuted instantiation: xlogreader.c:XLogFilePath
Unexecuted instantiation: xlogrecovery.c:XLogFilePath
Unexecuted instantiation: xlogutils.c:XLogFilePath
Unexecuted instantiation: checkpointer.c:XLogFilePath
Unexecuted instantiation: pgarch.c:XLogFilePath
Unexecuted instantiation: postmaster.c:XLogFilePath
Unexecuted instantiation: walsummarizer.c:XLogFilePath
Unexecuted instantiation: decode.c:XLogFilePath
Unexecuted instantiation: logical.c:XLogFilePath
Unexecuted instantiation: reorderbuffer.c:XLogFilePath
Unexecuted instantiation: slotsync.c:XLogFilePath
Unexecuted instantiation: slot.c:XLogFilePath
Unexecuted instantiation: slotfuncs.c:XLogFilePath
Unexecuted instantiation: walreceiver.c:XLogFilePath
Unexecuted instantiation: walreceiverfuncs.c:XLogFilePath
Unexecuted instantiation: walsender.c:XLogFilePath
Unexecuted instantiation: basebackup.c:XLogFilePath
Unexecuted instantiation: walsummary.c:XLogFilePath
Unexecuted instantiation: genfile.c:XLogFilePath
Unexecuted instantiation: guc_tables.c:XLogFilePath
Unexecuted instantiation: pg_controldata.c:XLogFilePath
Unexecuted instantiation: controldata_utils.c:XLogFilePath
216
217
static inline void
218
TLHistoryFileName(char *fname, TimeLineID tli)
219
0
{
220
0
  snprintf(fname, MAXFNAMELEN, "%08X.history", tli);
221
0
}
Unexecuted instantiation: xlogdesc.c:TLHistoryFileName
Unexecuted instantiation: rmgr.c:TLHistoryFileName
Unexecuted instantiation: timeline.c:TLHistoryFileName
Unexecuted instantiation: xlog.c:TLHistoryFileName
Unexecuted instantiation: xlogarchive.c:TLHistoryFileName
Unexecuted instantiation: xlogbackup.c:TLHistoryFileName
Unexecuted instantiation: xlogfuncs.c:TLHistoryFileName
Unexecuted instantiation: xloginsert.c:TLHistoryFileName
Unexecuted instantiation: xlogreader.c:TLHistoryFileName
Unexecuted instantiation: xlogrecovery.c:TLHistoryFileName
Unexecuted instantiation: xlogutils.c:TLHistoryFileName
Unexecuted instantiation: checkpointer.c:TLHistoryFileName
Unexecuted instantiation: pgarch.c:TLHistoryFileName
Unexecuted instantiation: postmaster.c:TLHistoryFileName
Unexecuted instantiation: walsummarizer.c:TLHistoryFileName
Unexecuted instantiation: decode.c:TLHistoryFileName
Unexecuted instantiation: logical.c:TLHistoryFileName
Unexecuted instantiation: reorderbuffer.c:TLHistoryFileName
Unexecuted instantiation: slotsync.c:TLHistoryFileName
Unexecuted instantiation: slot.c:TLHistoryFileName
Unexecuted instantiation: slotfuncs.c:TLHistoryFileName
Unexecuted instantiation: walreceiver.c:TLHistoryFileName
Unexecuted instantiation: walreceiverfuncs.c:TLHistoryFileName
Unexecuted instantiation: walsender.c:TLHistoryFileName
Unexecuted instantiation: basebackup.c:TLHistoryFileName
Unexecuted instantiation: walsummary.c:TLHistoryFileName
Unexecuted instantiation: genfile.c:TLHistoryFileName
Unexecuted instantiation: guc_tables.c:TLHistoryFileName
Unexecuted instantiation: pg_controldata.c:TLHistoryFileName
Unexecuted instantiation: controldata_utils.c:TLHistoryFileName
222
223
static inline bool
224
IsTLHistoryFileName(const char *fname)
225
0
{
226
0
  return (strlen(fname) == 8 + strlen(".history") &&
227
0
      strspn(fname, "0123456789ABCDEF") == 8 &&
228
0
      strcmp(fname + 8, ".history") == 0);
229
0
}
Unexecuted instantiation: xlogdesc.c:IsTLHistoryFileName
Unexecuted instantiation: rmgr.c:IsTLHistoryFileName
Unexecuted instantiation: timeline.c:IsTLHistoryFileName
Unexecuted instantiation: xlog.c:IsTLHistoryFileName
Unexecuted instantiation: xlogarchive.c:IsTLHistoryFileName
Unexecuted instantiation: xlogbackup.c:IsTLHistoryFileName
Unexecuted instantiation: xlogfuncs.c:IsTLHistoryFileName
Unexecuted instantiation: xloginsert.c:IsTLHistoryFileName
Unexecuted instantiation: xlogreader.c:IsTLHistoryFileName
Unexecuted instantiation: xlogrecovery.c:IsTLHistoryFileName
Unexecuted instantiation: xlogutils.c:IsTLHistoryFileName
Unexecuted instantiation: checkpointer.c:IsTLHistoryFileName
Unexecuted instantiation: pgarch.c:IsTLHistoryFileName
Unexecuted instantiation: postmaster.c:IsTLHistoryFileName
Unexecuted instantiation: walsummarizer.c:IsTLHistoryFileName
Unexecuted instantiation: decode.c:IsTLHistoryFileName
Unexecuted instantiation: logical.c:IsTLHistoryFileName
Unexecuted instantiation: reorderbuffer.c:IsTLHistoryFileName
Unexecuted instantiation: slotsync.c:IsTLHistoryFileName
Unexecuted instantiation: slot.c:IsTLHistoryFileName
Unexecuted instantiation: slotfuncs.c:IsTLHistoryFileName
Unexecuted instantiation: walreceiver.c:IsTLHistoryFileName
Unexecuted instantiation: walreceiverfuncs.c:IsTLHistoryFileName
Unexecuted instantiation: walsender.c:IsTLHistoryFileName
Unexecuted instantiation: basebackup.c:IsTLHistoryFileName
Unexecuted instantiation: walsummary.c:IsTLHistoryFileName
Unexecuted instantiation: genfile.c:IsTLHistoryFileName
Unexecuted instantiation: guc_tables.c:IsTLHistoryFileName
Unexecuted instantiation: pg_controldata.c:IsTLHistoryFileName
Unexecuted instantiation: controldata_utils.c:IsTLHistoryFileName
230
231
static inline void
232
TLHistoryFilePath(char *path, TimeLineID tli)
233
0
{
234
0
  snprintf(path, MAXPGPATH, XLOGDIR "/%08X.history", tli);
235
0
}
Unexecuted instantiation: xlogdesc.c:TLHistoryFilePath
Unexecuted instantiation: rmgr.c:TLHistoryFilePath
Unexecuted instantiation: timeline.c:TLHistoryFilePath
Unexecuted instantiation: xlog.c:TLHistoryFilePath
Unexecuted instantiation: xlogarchive.c:TLHistoryFilePath
Unexecuted instantiation: xlogbackup.c:TLHistoryFilePath
Unexecuted instantiation: xlogfuncs.c:TLHistoryFilePath
Unexecuted instantiation: xloginsert.c:TLHistoryFilePath
Unexecuted instantiation: xlogreader.c:TLHistoryFilePath
Unexecuted instantiation: xlogrecovery.c:TLHistoryFilePath
Unexecuted instantiation: xlogutils.c:TLHistoryFilePath
Unexecuted instantiation: checkpointer.c:TLHistoryFilePath
Unexecuted instantiation: pgarch.c:TLHistoryFilePath
Unexecuted instantiation: postmaster.c:TLHistoryFilePath
Unexecuted instantiation: walsummarizer.c:TLHistoryFilePath
Unexecuted instantiation: decode.c:TLHistoryFilePath
Unexecuted instantiation: logical.c:TLHistoryFilePath
Unexecuted instantiation: reorderbuffer.c:TLHistoryFilePath
Unexecuted instantiation: slotsync.c:TLHistoryFilePath
Unexecuted instantiation: slot.c:TLHistoryFilePath
Unexecuted instantiation: slotfuncs.c:TLHistoryFilePath
Unexecuted instantiation: walreceiver.c:TLHistoryFilePath
Unexecuted instantiation: walreceiverfuncs.c:TLHistoryFilePath
Unexecuted instantiation: walsender.c:TLHistoryFilePath
Unexecuted instantiation: basebackup.c:TLHistoryFilePath
Unexecuted instantiation: walsummary.c:TLHistoryFilePath
Unexecuted instantiation: genfile.c:TLHistoryFilePath
Unexecuted instantiation: guc_tables.c:TLHistoryFilePath
Unexecuted instantiation: pg_controldata.c:TLHistoryFilePath
Unexecuted instantiation: controldata_utils.c:TLHistoryFilePath
236
237
static inline void
238
StatusFilePath(char *path, const char *xlog, const char *suffix)
239
0
{
240
0
  snprintf(path, MAXPGPATH, XLOGDIR "/archive_status/%s%s", xlog, suffix);
241
0
}
Unexecuted instantiation: xlogdesc.c:StatusFilePath
Unexecuted instantiation: rmgr.c:StatusFilePath
Unexecuted instantiation: timeline.c:StatusFilePath
Unexecuted instantiation: xlog.c:StatusFilePath
Unexecuted instantiation: xlogarchive.c:StatusFilePath
Unexecuted instantiation: xlogbackup.c:StatusFilePath
Unexecuted instantiation: xlogfuncs.c:StatusFilePath
Unexecuted instantiation: xloginsert.c:StatusFilePath
Unexecuted instantiation: xlogreader.c:StatusFilePath
Unexecuted instantiation: xlogrecovery.c:StatusFilePath
Unexecuted instantiation: xlogutils.c:StatusFilePath
Unexecuted instantiation: checkpointer.c:StatusFilePath
Unexecuted instantiation: pgarch.c:StatusFilePath
Unexecuted instantiation: postmaster.c:StatusFilePath
Unexecuted instantiation: walsummarizer.c:StatusFilePath
Unexecuted instantiation: decode.c:StatusFilePath
Unexecuted instantiation: logical.c:StatusFilePath
Unexecuted instantiation: reorderbuffer.c:StatusFilePath
Unexecuted instantiation: slotsync.c:StatusFilePath
Unexecuted instantiation: slot.c:StatusFilePath
Unexecuted instantiation: slotfuncs.c:StatusFilePath
Unexecuted instantiation: walreceiver.c:StatusFilePath
Unexecuted instantiation: walreceiverfuncs.c:StatusFilePath
Unexecuted instantiation: walsender.c:StatusFilePath
Unexecuted instantiation: basebackup.c:StatusFilePath
Unexecuted instantiation: walsummary.c:StatusFilePath
Unexecuted instantiation: genfile.c:StatusFilePath
Unexecuted instantiation: guc_tables.c:StatusFilePath
Unexecuted instantiation: pg_controldata.c:StatusFilePath
Unexecuted instantiation: controldata_utils.c:StatusFilePath
242
243
static inline void
244
BackupHistoryFileName(char *fname, TimeLineID tli, XLogSegNo logSegNo, XLogRecPtr startpoint, int wal_segsz_bytes)
245
0
{
246
0
  snprintf(fname, MAXFNAMELEN, "%08X%08X%08X.%08X.backup", tli,
247
0
       (uint32) (logSegNo / XLogSegmentsPerXLogId(wal_segsz_bytes)),
248
0
       (uint32) (logSegNo % XLogSegmentsPerXLogId(wal_segsz_bytes)),
249
0
       (uint32) (XLogSegmentOffset(startpoint, wal_segsz_bytes)));
250
0
}
Unexecuted instantiation: xlogdesc.c:BackupHistoryFileName
Unexecuted instantiation: rmgr.c:BackupHistoryFileName
Unexecuted instantiation: timeline.c:BackupHistoryFileName
Unexecuted instantiation: xlog.c:BackupHistoryFileName
Unexecuted instantiation: xlogarchive.c:BackupHistoryFileName
Unexecuted instantiation: xlogbackup.c:BackupHistoryFileName
Unexecuted instantiation: xlogfuncs.c:BackupHistoryFileName
Unexecuted instantiation: xloginsert.c:BackupHistoryFileName
Unexecuted instantiation: xlogreader.c:BackupHistoryFileName
Unexecuted instantiation: xlogrecovery.c:BackupHistoryFileName
Unexecuted instantiation: xlogutils.c:BackupHistoryFileName
Unexecuted instantiation: checkpointer.c:BackupHistoryFileName
Unexecuted instantiation: pgarch.c:BackupHistoryFileName
Unexecuted instantiation: postmaster.c:BackupHistoryFileName
Unexecuted instantiation: walsummarizer.c:BackupHistoryFileName
Unexecuted instantiation: decode.c:BackupHistoryFileName
Unexecuted instantiation: logical.c:BackupHistoryFileName
Unexecuted instantiation: reorderbuffer.c:BackupHistoryFileName
Unexecuted instantiation: slotsync.c:BackupHistoryFileName
Unexecuted instantiation: slot.c:BackupHistoryFileName
Unexecuted instantiation: slotfuncs.c:BackupHistoryFileName
Unexecuted instantiation: walreceiver.c:BackupHistoryFileName
Unexecuted instantiation: walreceiverfuncs.c:BackupHistoryFileName
Unexecuted instantiation: walsender.c:BackupHistoryFileName
Unexecuted instantiation: basebackup.c:BackupHistoryFileName
Unexecuted instantiation: walsummary.c:BackupHistoryFileName
Unexecuted instantiation: genfile.c:BackupHistoryFileName
Unexecuted instantiation: guc_tables.c:BackupHistoryFileName
Unexecuted instantiation: pg_controldata.c:BackupHistoryFileName
Unexecuted instantiation: controldata_utils.c:BackupHistoryFileName
251
252
static inline bool
253
IsBackupHistoryFileName(const char *fname)
254
0
{
255
0
  return (strlen(fname) > XLOG_FNAME_LEN &&
256
0
      strspn(fname, "0123456789ABCDEF") == XLOG_FNAME_LEN &&
257
0
      strcmp(fname + strlen(fname) - strlen(".backup"), ".backup") == 0);
258
0
}
Unexecuted instantiation: xlogdesc.c:IsBackupHistoryFileName
Unexecuted instantiation: rmgr.c:IsBackupHistoryFileName
Unexecuted instantiation: timeline.c:IsBackupHistoryFileName
Unexecuted instantiation: xlog.c:IsBackupHistoryFileName
Unexecuted instantiation: xlogarchive.c:IsBackupHistoryFileName
Unexecuted instantiation: xlogbackup.c:IsBackupHistoryFileName
Unexecuted instantiation: xlogfuncs.c:IsBackupHistoryFileName
Unexecuted instantiation: xloginsert.c:IsBackupHistoryFileName
Unexecuted instantiation: xlogreader.c:IsBackupHistoryFileName
Unexecuted instantiation: xlogrecovery.c:IsBackupHistoryFileName
Unexecuted instantiation: xlogutils.c:IsBackupHistoryFileName
Unexecuted instantiation: checkpointer.c:IsBackupHistoryFileName
Unexecuted instantiation: pgarch.c:IsBackupHistoryFileName
Unexecuted instantiation: postmaster.c:IsBackupHistoryFileName
Unexecuted instantiation: walsummarizer.c:IsBackupHistoryFileName
Unexecuted instantiation: decode.c:IsBackupHistoryFileName
Unexecuted instantiation: logical.c:IsBackupHistoryFileName
Unexecuted instantiation: reorderbuffer.c:IsBackupHistoryFileName
Unexecuted instantiation: slotsync.c:IsBackupHistoryFileName
Unexecuted instantiation: slot.c:IsBackupHistoryFileName
Unexecuted instantiation: slotfuncs.c:IsBackupHistoryFileName
Unexecuted instantiation: walreceiver.c:IsBackupHistoryFileName
Unexecuted instantiation: walreceiverfuncs.c:IsBackupHistoryFileName
Unexecuted instantiation: walsender.c:IsBackupHistoryFileName
Unexecuted instantiation: basebackup.c:IsBackupHistoryFileName
Unexecuted instantiation: walsummary.c:IsBackupHistoryFileName
Unexecuted instantiation: genfile.c:IsBackupHistoryFileName
Unexecuted instantiation: guc_tables.c:IsBackupHistoryFileName
Unexecuted instantiation: pg_controldata.c:IsBackupHistoryFileName
Unexecuted instantiation: controldata_utils.c:IsBackupHistoryFileName
259
260
static inline void
261
BackupHistoryFilePath(char *path, TimeLineID tli, XLogSegNo logSegNo, XLogRecPtr startpoint, int wal_segsz_bytes)
262
0
{
263
0
  snprintf(path, MAXPGPATH, XLOGDIR "/%08X%08X%08X.%08X.backup", tli,
264
0
       (uint32) (logSegNo / XLogSegmentsPerXLogId(wal_segsz_bytes)),
265
0
       (uint32) (logSegNo % XLogSegmentsPerXLogId(wal_segsz_bytes)),
266
0
       (uint32) (XLogSegmentOffset((startpoint), wal_segsz_bytes)));
267
0
}
Unexecuted instantiation: xlogdesc.c:BackupHistoryFilePath
Unexecuted instantiation: rmgr.c:BackupHistoryFilePath
Unexecuted instantiation: timeline.c:BackupHistoryFilePath
Unexecuted instantiation: xlog.c:BackupHistoryFilePath
Unexecuted instantiation: xlogarchive.c:BackupHistoryFilePath
Unexecuted instantiation: xlogbackup.c:BackupHistoryFilePath
Unexecuted instantiation: xlogfuncs.c:BackupHistoryFilePath
Unexecuted instantiation: xloginsert.c:BackupHistoryFilePath
Unexecuted instantiation: xlogreader.c:BackupHistoryFilePath
Unexecuted instantiation: xlogrecovery.c:BackupHistoryFilePath
Unexecuted instantiation: xlogutils.c:BackupHistoryFilePath
Unexecuted instantiation: checkpointer.c:BackupHistoryFilePath
Unexecuted instantiation: pgarch.c:BackupHistoryFilePath
Unexecuted instantiation: postmaster.c:BackupHistoryFilePath
Unexecuted instantiation: walsummarizer.c:BackupHistoryFilePath
Unexecuted instantiation: decode.c:BackupHistoryFilePath
Unexecuted instantiation: logical.c:BackupHistoryFilePath
Unexecuted instantiation: reorderbuffer.c:BackupHistoryFilePath
Unexecuted instantiation: slotsync.c:BackupHistoryFilePath
Unexecuted instantiation: slot.c:BackupHistoryFilePath
Unexecuted instantiation: slotfuncs.c:BackupHistoryFilePath
Unexecuted instantiation: walreceiver.c:BackupHistoryFilePath
Unexecuted instantiation: walreceiverfuncs.c:BackupHistoryFilePath
Unexecuted instantiation: walsender.c:BackupHistoryFilePath
Unexecuted instantiation: basebackup.c:BackupHistoryFilePath
Unexecuted instantiation: walsummary.c:BackupHistoryFilePath
Unexecuted instantiation: genfile.c:BackupHistoryFilePath
Unexecuted instantiation: guc_tables.c:BackupHistoryFilePath
Unexecuted instantiation: pg_controldata.c:BackupHistoryFilePath
Unexecuted instantiation: controldata_utils.c:BackupHistoryFilePath
268
269
/*
270
 * Information logged when we detect a change in one of the parameters
271
 * important for Hot Standby.
272
 */
273
typedef struct xl_parameter_change
274
{
275
  int     MaxConnections;
276
  int     max_worker_processes;
277
  int     max_wal_senders;
278
  int     max_prepared_xacts;
279
  int     max_locks_per_xact;
280
  int     wal_level;
281
  bool    wal_log_hints;
282
  bool    track_commit_timestamp;
283
} xl_parameter_change;
284
285
/* logs restore point */
286
typedef struct xl_restore_point
287
{
288
  TimestampTz rp_time;
289
  char    rp_name[MAXFNAMELEN];
290
} xl_restore_point;
291
292
/* Overwrite of prior contrecord */
293
typedef struct xl_overwrite_contrecord
294
{
295
  XLogRecPtr  overwritten_lsn;
296
  TimestampTz overwrite_time;
297
} xl_overwrite_contrecord;
298
299
/* End of recovery mark, when we don't do an END_OF_RECOVERY checkpoint */
300
typedef struct xl_end_of_recovery
301
{
302
  TimestampTz end_time;
303
  TimeLineID  ThisTimeLineID; /* new TLI */
304
  TimeLineID  PrevTimeLineID; /* previous TLI we forked off from */
305
  int     wal_level;
306
} xl_end_of_recovery;
307
308
/*
309
 * The functions in xloginsert.c construct a chain of XLogRecData structs
310
 * to represent the final WAL record.
311
 */
312
typedef struct XLogRecData
313
{
314
  struct XLogRecData *next; /* next struct in chain, or NULL */
315
  const void *data;     /* start of rmgr data to include */
316
  uint32    len;      /* length of rmgr data to include */
317
} XLogRecData;
318
319
/*
320
 * Recovery target action.
321
 */
322
typedef enum
323
{
324
  RECOVERY_TARGET_ACTION_PAUSE,
325
  RECOVERY_TARGET_ACTION_PROMOTE,
326
  RECOVERY_TARGET_ACTION_SHUTDOWN,
327
}     RecoveryTargetAction;
328
329
struct LogicalDecodingContext;
330
struct XLogRecordBuffer;
331
332
/*
333
 * Method table for resource managers.
334
 *
335
 * This struct must be kept in sync with the PG_RMGR definition in
336
 * rmgr.c.
337
 *
338
 * rm_identify must return a name for the record based on xl_info (without
339
 * reference to the rmid). For example, XLOG_BTREE_VACUUM would be named
340
 * "VACUUM". rm_desc can then be called to obtain additional detail for the
341
 * record, if available (e.g. the last block).
342
 *
343
 * rm_mask takes as input a page modified by the resource manager and masks
344
 * out bits that shouldn't be flagged by wal_consistency_checking.
345
 *
346
 * RmgrTable[] is indexed by RmgrId values (see rmgrlist.h). If rm_name is
347
 * NULL, the corresponding RmgrTable entry is considered invalid.
348
 */
349
typedef struct RmgrData
350
{
351
  const char *rm_name;
352
  void    (*rm_redo) (XLogReaderState *record);
353
  void    (*rm_desc) (StringInfo buf, XLogReaderState *record);
354
  const char *(*rm_identify) (uint8 info);
355
  void    (*rm_startup) (void);
356
  void    (*rm_cleanup) (void);
357
  void    (*rm_mask) (char *pagedata, BlockNumber blkno);
358
  void    (*rm_decode) (struct LogicalDecodingContext *ctx,
359
                struct XLogRecordBuffer *buf);
360
} RmgrData;
361
362
extern PGDLLIMPORT RmgrData RmgrTable[];
363
extern void RmgrStartup(void);
364
extern void RmgrCleanup(void);
365
extern void RmgrNotFound(RmgrId rmid);
366
extern void RegisterCustomRmgr(RmgrId rmid, const RmgrData *rmgr);
367
368
#ifndef FRONTEND
369
static inline bool
370
RmgrIdExists(RmgrId rmid)
371
0
{
372
0
  return RmgrTable[rmid].rm_name != NULL;
373
0
}
Unexecuted instantiation: xlogdesc.c:RmgrIdExists
Unexecuted instantiation: rmgr.c:RmgrIdExists
Unexecuted instantiation: timeline.c:RmgrIdExists
Unexecuted instantiation: xlog.c:RmgrIdExists
Unexecuted instantiation: xlogarchive.c:RmgrIdExists
Unexecuted instantiation: xlogbackup.c:RmgrIdExists
Unexecuted instantiation: xlogfuncs.c:RmgrIdExists
Unexecuted instantiation: xloginsert.c:RmgrIdExists
Unexecuted instantiation: xlogreader.c:RmgrIdExists
Unexecuted instantiation: xlogrecovery.c:RmgrIdExists
Unexecuted instantiation: xlogutils.c:RmgrIdExists
Unexecuted instantiation: checkpointer.c:RmgrIdExists
Unexecuted instantiation: pgarch.c:RmgrIdExists
Unexecuted instantiation: postmaster.c:RmgrIdExists
Unexecuted instantiation: walsummarizer.c:RmgrIdExists
Unexecuted instantiation: decode.c:RmgrIdExists
Unexecuted instantiation: logical.c:RmgrIdExists
Unexecuted instantiation: reorderbuffer.c:RmgrIdExists
Unexecuted instantiation: slotsync.c:RmgrIdExists
Unexecuted instantiation: slot.c:RmgrIdExists
Unexecuted instantiation: slotfuncs.c:RmgrIdExists
Unexecuted instantiation: walreceiver.c:RmgrIdExists
Unexecuted instantiation: walreceiverfuncs.c:RmgrIdExists
Unexecuted instantiation: walsender.c:RmgrIdExists
Unexecuted instantiation: basebackup.c:RmgrIdExists
Unexecuted instantiation: walsummary.c:RmgrIdExists
Unexecuted instantiation: genfile.c:RmgrIdExists
Unexecuted instantiation: guc_tables.c:RmgrIdExists
Unexecuted instantiation: pg_controldata.c:RmgrIdExists
Unexecuted instantiation: controldata_utils.c:RmgrIdExists
374
375
static inline RmgrData
376
GetRmgr(RmgrId rmid)
377
0
{
378
0
  if (unlikely(!RmgrIdExists(rmid)))
379
0
    RmgrNotFound(rmid);
380
0
  return RmgrTable[rmid];
381
0
}
Unexecuted instantiation: xlogdesc.c:GetRmgr
Unexecuted instantiation: rmgr.c:GetRmgr
Unexecuted instantiation: timeline.c:GetRmgr
Unexecuted instantiation: xlog.c:GetRmgr
Unexecuted instantiation: xlogarchive.c:GetRmgr
Unexecuted instantiation: xlogbackup.c:GetRmgr
Unexecuted instantiation: xlogfuncs.c:GetRmgr
Unexecuted instantiation: xloginsert.c:GetRmgr
Unexecuted instantiation: xlogreader.c:GetRmgr
Unexecuted instantiation: xlogrecovery.c:GetRmgr
Unexecuted instantiation: xlogutils.c:GetRmgr
Unexecuted instantiation: checkpointer.c:GetRmgr
Unexecuted instantiation: pgarch.c:GetRmgr
Unexecuted instantiation: postmaster.c:GetRmgr
Unexecuted instantiation: walsummarizer.c:GetRmgr
Unexecuted instantiation: decode.c:GetRmgr
Unexecuted instantiation: logical.c:GetRmgr
Unexecuted instantiation: reorderbuffer.c:GetRmgr
Unexecuted instantiation: slotsync.c:GetRmgr
Unexecuted instantiation: slot.c:GetRmgr
Unexecuted instantiation: slotfuncs.c:GetRmgr
Unexecuted instantiation: walreceiver.c:GetRmgr
Unexecuted instantiation: walreceiverfuncs.c:GetRmgr
Unexecuted instantiation: walsender.c:GetRmgr
Unexecuted instantiation: basebackup.c:GetRmgr
Unexecuted instantiation: walsummary.c:GetRmgr
Unexecuted instantiation: genfile.c:GetRmgr
Unexecuted instantiation: guc_tables.c:GetRmgr
Unexecuted instantiation: pg_controldata.c:GetRmgr
Unexecuted instantiation: controldata_utils.c:GetRmgr
382
#endif
383
384
/*
385
 * Exported to support xlog switching from checkpointer
386
 */
387
extern pg_time_t GetLastSegSwitchData(XLogRecPtr *lastSwitchLSN);
388
extern XLogRecPtr RequestXLogSwitch(bool mark_unimportant);
389
390
extern void GetOldestRestartPoint(XLogRecPtr *oldrecptr, TimeLineID *oldtli);
391
392
extern void XLogRecGetBlockRefInfo(XLogReaderState *record, bool pretty,
393
                   bool detailed_format, StringInfo buf,
394
                   uint32 *fpi_len);
395
396
/*
397
 * Exported for the functions in timeline.c and xlogarchive.c.  Only valid
398
 * in the startup process.
399
 */
400
extern PGDLLIMPORT bool ArchiveRecoveryRequested;
401
extern PGDLLIMPORT bool InArchiveRecovery;
402
extern PGDLLIMPORT bool StandbyMode;
403
extern PGDLLIMPORT char *recoveryRestoreCommand;
404
405
#endif              /* XLOG_INTERNAL_H */