19 #ifndef XLOG_INTERNAL_H
20 #define XLOG_INTERNAL_H
34 #define XLOG_PAGE_MAGIC 0xD086
55 #define SizeOfXLogShortPHD MAXALIGN(sizeof(XLogPageHeaderData))
72 #define SizeOfXLogLongPHD MAXALIGN(sizeof(XLogLongPageHeaderData))
77 #define XLP_FIRST_IS_CONTRECORD 0x0001
79 #define XLP_LONG_HEADER 0x0002
81 #define XLP_BKP_REMOVABLE 0x0004
83 #define XLP_ALL_FLAGS 0x0007
85 #define XLogPageHeaderSize(hdr) \
86 (((hdr)->xlp_info & XLP_LONG_HEADER) ? SizeOfXLogLongPHD : SizeOfXLogShortPHD)
92 #define XLogSegSize ((uint32) XLOG_SEG_SIZE)
93 #define XLogSegmentsPerXLogId (UINT64CONST(0x100000000) / XLOG_SEG_SIZE)
95 #define XLogSegNoOffsetToRecPtr(segno, offset, dest) \
96 (dest) = (segno) * XLOG_SEG_SIZE + (offset)
106 #define XLByteToSeg(xlrp, logSegNo) \
107 logSegNo = (xlrp) / XLogSegSize
109 #define XLByteToPrevSeg(xlrp, logSegNo) \
110 logSegNo = ((xlrp) - 1) / XLogSegSize
118 #define XLByteInSeg(xlrp, logSegNo) \
119 (((xlrp) / XLogSegSize) == (logSegNo))
121 #define XLByteInPrevSeg(xlrp, logSegNo) \
122 ((((xlrp) - 1) / XLogSegSize) == (logSegNo))
125 #define XRecOffIsValid(xlrp) \
126 ((xlrp) % XLOG_BLCKSZ >= SizeOfXLogShortPHD)
131 #define XLOGDIR "pg_xlog"
132 #define XLOG_CONTROL_FILE "global/pg_control"
138 #define MAXFNAMELEN 64
141 #define XLOG_FNAME_LEN 24
143 #define XLogFileName(fname, tli, logSegNo) \
144 snprintf(fname, MAXFNAMELEN, "%08X%08X%08X", tli, \
145 (uint32) ((logSegNo) / XLogSegmentsPerXLogId), \
146 (uint32) ((logSegNo) % XLogSegmentsPerXLogId))
148 #define XLogFileNameById(fname, tli, log, seg) \
149 snprintf(fname, MAXFNAMELEN, "%08X%08X%08X", tli, log, seg)
151 #define IsXLogFileName(fname) \
152 (strlen(fname) == XLOG_FNAME_LEN && \
153 strspn(fname, "0123456789ABCDEF") == XLOG_FNAME_LEN)
160 #define IsPartialXLogFileName(fname) \
161 (strlen(fname) == XLOG_FNAME_LEN + strlen(".partial") && \
162 strspn(fname, "0123456789ABCDEF") == XLOG_FNAME_LEN && \
163 strcmp((fname) + XLOG_FNAME_LEN, ".partial") == 0)
165 #define XLogFromFileName(fname, tli, logSegNo) \
169 sscanf(fname, "%08X%08X%08X", tli, &log, &seg); \
170 *logSegNo = (uint64) log * XLogSegmentsPerXLogId + seg; \
173 #define XLogFilePath(path, tli, logSegNo) \
174 snprintf(path, MAXPGPATH, XLOGDIR "/%08X%08X%08X", tli, \
175 (uint32) ((logSegNo) / XLogSegmentsPerXLogId), \
176 (uint32) ((logSegNo) % XLogSegmentsPerXLogId))
178 #define TLHistoryFileName(fname, tli) \
179 snprintf(fname, MAXFNAMELEN, "%08X.history", tli)
181 #define IsTLHistoryFileName(fname) \
182 (strlen(fname) == 8 + strlen(".history") && \
183 strspn(fname, "0123456789ABCDEF") == 8 && \
184 strcmp((fname) + 8, ".history") == 0)
186 #define TLHistoryFilePath(path, tli) \
187 snprintf(path, MAXPGPATH, XLOGDIR "/%08X.history", tli)
189 #define StatusFilePath(path, xlog, suffix) \
190 snprintf(path, MAXPGPATH, XLOGDIR "/archive_status/%s%s", xlog, suffix)
192 #define BackupHistoryFileName(fname, tli, logSegNo, offset) \
193 snprintf(fname, MAXFNAMELEN, "%08X%08X%08X.%08X.backup", tli, \
194 (uint32) ((logSegNo) / XLogSegmentsPerXLogId), \
195 (uint32) ((logSegNo) % XLogSegmentsPerXLogId), offset)
197 #define IsBackupHistoryFileName(fname) \
198 (strlen(fname) > XLOG_FNAME_LEN && \
199 strspn(fname, "0123456789ABCDEF") == XLOG_FNAME_LEN && \
200 strcmp((fname) + strlen(fname) - strlen(".backup"), ".backup") == 0)
202 #define BackupHistoryFilePath(path, tli, logSegNo, offset) \
203 snprintf(path, MAXPGPATH, XLOGDIR "/%08X%08X%08X.%08X.backup", tli, \
204 (uint32) ((logSegNo) / XLogSegmentsPerXLogId), \
205 (uint32) ((logSegNo) % XLogSegmentsPerXLogId), offset)
276 const char *(*rm_identify) (
uint8 info);
304 const char *recovername, off_t expectedSize,
305 bool cleanupEnabled);
struct XLogLongPageHeaderData XLogLongPageHeaderData
void XLogArchiveCleanup(const char *xlog)
bool XLogArchiveIsReadyOrDone(const char *xlog)
XLogRecPtr RequestXLogSwitch(void)
void XLogArchiveNotifySeg(XLogSegNo segno)
struct xl_end_of_recovery xl_end_of_recovery
bool XLogArchiveCheckDone(const char *xlog)
TimeLineID PrevTimeLineID
struct xl_parameter_change xl_parameter_change
void ExecuteRecoveryCommand(char *command, char *commandName, bool failOnerror)
void(* rm_redo)(XLogReaderState *record)
XLogPageHeaderData * XLogPageHeader
void XLogArchiveNotify(const char *xlog)
XLogLongPageHeaderData * XLogLongPageHeader
char rp_name[MAXFNAMELEN]
char * recoveryRestoreCommand
void(* rm_desc)(StringInfo buf, XLogReaderState *record)
pg_time_t GetLastSegSwitchTime(void)
struct XLogRecData XLogRecData
bool ArchiveRecoveryRequested
bool XLogArchiveIsBusy(const char *xlog)
bool track_commit_timestamp
struct xl_restore_point xl_restore_point
void XLogArchiveForceDone(const char *xlog)
bool XLogArchiveIsReady(const char *xlog)
const RmgrData RmgrTable[]
struct XLogRecData * next
bool RestoreArchivedFile(char *path, const char *xlogfname, const char *recovername, off_t expectedSize, bool cleanupEnabled)
TimeLineID ThisTimeLineID
void GetOldestRestartPoint(XLogRecPtr *oldrecptr, TimeLineID *oldtli)
void KeepFileRestoredFromArchive(char *path, char *xlogfname)
struct XLogPageHeaderData XLogPageHeaderData