00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef XLOG_INTERNAL_H
00020 #define XLOG_INTERNAL_H
00021
00022 #include "access/xlogdefs.h"
00023 #include "datatype/timestamp.h"
00024 #include "lib/stringinfo.h"
00025 #include "pgtime.h"
00026 #include "storage/block.h"
00027 #include "storage/relfilenode.h"
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044 typedef struct BkpBlock
00045 {
00046 RelFileNode node;
00047 ForkNumber fork;
00048 BlockNumber block;
00049 uint16 hole_offset;
00050 uint16 hole_length;
00051
00052
00053 } BkpBlock;
00054
00055
00056
00057
00058 #define XLOG_PAGE_MAGIC 0xD075
00059
00060 typedef struct XLogPageHeaderData
00061 {
00062 uint16 xlp_magic;
00063 uint16 xlp_info;
00064 TimeLineID xlp_tli;
00065 XLogRecPtr xlp_pageaddr;
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076 uint32 xlp_rem_len;
00077 } XLogPageHeaderData;
00078
00079 #define SizeOfXLogShortPHD MAXALIGN(sizeof(XLogPageHeaderData))
00080
00081 typedef XLogPageHeaderData *XLogPageHeader;
00082
00083
00084
00085
00086
00087
00088 typedef struct XLogLongPageHeaderData
00089 {
00090 XLogPageHeaderData std;
00091 uint64 xlp_sysid;
00092 uint32 xlp_seg_size;
00093 uint32 xlp_xlog_blcksz;
00094 } XLogLongPageHeaderData;
00095
00096 #define SizeOfXLogLongPHD MAXALIGN(sizeof(XLogLongPageHeaderData))
00097
00098 typedef XLogLongPageHeaderData *XLogLongPageHeader;
00099
00100
00101 #define XLP_FIRST_IS_CONTRECORD 0x0001
00102
00103 #define XLP_LONG_HEADER 0x0002
00104
00105 #define XLP_BKP_REMOVABLE 0x0004
00106
00107 #define XLP_ALL_FLAGS 0x0007
00108
00109 #define XLogPageHeaderSize(hdr) \
00110 (((hdr)->xlp_info & XLP_LONG_HEADER) ? SizeOfXLogLongPHD : SizeOfXLogShortPHD)
00111
00112
00113
00114
00115
00116 #define XLogSegSize ((uint32) XLOG_SEG_SIZE)
00117 #define XLogSegmentsPerXLogId (UINT64CONST(0x100000000) / XLOG_SEG_SIZE)
00118
00119 #define XLogSegNoOffsetToRecPtr(segno, offset, dest) \
00120 (dest) = (segno) * XLOG_SEG_SIZE + (offset)
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130 #define XLByteToSeg(xlrp, logSegNo) \
00131 logSegNo = (xlrp) / XLogSegSize
00132
00133 #define XLByteToPrevSeg(xlrp, logSegNo) \
00134 logSegNo = ((xlrp) - 1) / XLogSegSize
00135
00136
00137
00138
00139
00140
00141
00142 #define XLByteInSeg(xlrp, logSegNo) \
00143 (((xlrp) / XLogSegSize) == (logSegNo))
00144
00145 #define XLByteInPrevSeg(xlrp, logSegNo) \
00146 ((((xlrp) - 1) / XLogSegSize) == (logSegNo))
00147
00148
00149 #define XRecOffIsValid(xlrp) \
00150 ((xlrp) % XLOG_BLCKSZ >= SizeOfXLogShortPHD)
00151
00152
00153
00154
00155 #define XLOGDIR "pg_xlog"
00156 #define XLOG_CONTROL_FILE "global/pg_control"
00157
00158
00159
00160
00161
00162 #define MAXFNAMELEN 64
00163
00164 #define XLogFileName(fname, tli, logSegNo) \
00165 snprintf(fname, MAXFNAMELEN, "%08X%08X%08X", tli, \
00166 (uint32) ((logSegNo) / XLogSegmentsPerXLogId), \
00167 (uint32) ((logSegNo) % XLogSegmentsPerXLogId))
00168
00169 #define XLogFromFileName(fname, tli, logSegNo) \
00170 do { \
00171 uint32 log; \
00172 uint32 seg; \
00173 sscanf(fname, "%08X%08X%08X", tli, &log, &seg); \
00174 *logSegNo = (uint64) log * XLogSegmentsPerXLogId + seg; \
00175 } while (0)
00176
00177 #define XLogFilePath(path, tli, logSegNo) \
00178 snprintf(path, MAXPGPATH, XLOGDIR "/%08X%08X%08X", tli, \
00179 (uint32) ((logSegNo) / XLogSegmentsPerXLogId), \
00180 (uint32) ((logSegNo) % XLogSegmentsPerXLogId))
00181
00182 #define TLHistoryFileName(fname, tli) \
00183 snprintf(fname, MAXFNAMELEN, "%08X.history", tli)
00184
00185 #define TLHistoryFilePath(path, tli) \
00186 snprintf(path, MAXPGPATH, XLOGDIR "/%08X.history", tli)
00187
00188 #define StatusFilePath(path, xlog, suffix) \
00189 snprintf(path, MAXPGPATH, XLOGDIR "/archive_status/%s%s", xlog, suffix)
00190
00191 #define BackupHistoryFileName(fname, tli, logSegNo, offset) \
00192 snprintf(fname, MAXFNAMELEN, "%08X%08X%08X.%08X.backup", tli, \
00193 (uint32) ((logSegNo) / XLogSegmentsPerXLogId), \
00194 (uint32) ((logSegNo) % XLogSegmentsPerXLogId), offset)
00195
00196 #define BackupHistoryFilePath(path, tli, logSegNo, offset) \
00197 snprintf(path, MAXPGPATH, XLOGDIR "/%08X%08X%08X.%08X.backup", tli, \
00198 (uint32) ((logSegNo) / XLogSegmentsPerXLogId), \
00199 (uint32) ((logSegNo) % XLogSegmentsPerXLogId), offset)
00200
00201
00202
00203
00204
00205 typedef struct xl_parameter_change
00206 {
00207 int MaxConnections;
00208 int max_prepared_xacts;
00209 int max_locks_per_xact;
00210 int wal_level;
00211 } xl_parameter_change;
00212
00213
00214 typedef struct xl_restore_point
00215 {
00216 TimestampTz rp_time;
00217 char rp_name[MAXFNAMELEN];
00218 } xl_restore_point;
00219
00220
00221 typedef struct xl_end_of_recovery
00222 {
00223 TimestampTz end_time;
00224 TimeLineID ThisTimeLineID;
00225 TimeLineID PrevTimeLineID;
00226 } xl_end_of_recovery;
00227
00228
00229
00230
00231
00232 struct XLogRecord;
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242 typedef struct RmgrData
00243 {
00244 const char *rm_name;
00245 void (*rm_redo) (XLogRecPtr lsn, struct XLogRecord *rptr);
00246 void (*rm_desc) (StringInfo buf, uint8 xl_info, char *rec);
00247 void (*rm_startup) (void);
00248 void (*rm_cleanup) (void);
00249 bool (*rm_safe_restartpoint) (void);
00250 } RmgrData;
00251
00252 extern const RmgrData RmgrTable[];
00253
00254
00255
00256
00257 extern pg_time_t GetLastSegSwitchTime(void);
00258 extern XLogRecPtr RequestXLogSwitch(void);
00259
00260 extern void GetOldestRestartPoint(XLogRecPtr *oldrecptr, TimeLineID *oldtli);
00261
00262
00263
00264
00265
00266 extern bool ArchiveRecoveryRequested;
00267 extern bool InArchiveRecovery;
00268 extern bool StandbyMode;
00269 extern char *recoveryRestoreCommand;
00270
00271
00272
00273
00274 extern bool RestoreArchivedFile(char *path, const char *xlogfname,
00275 const char *recovername, off_t expectedSize,
00276 bool cleanupEnabled);
00277 extern void ExecuteRecoveryCommand(char *command, char *commandName,
00278 bool failOnerror);
00279 extern void KeepFileRestoredFromArchive(char *path, char *xlogfname);
00280 extern void XLogArchiveNotify(const char *xlog);
00281 extern void XLogArchiveNotifySeg(XLogSegNo segno);
00282 extern void XLogArchiveForceDone(const char *xlog);
00283 extern bool XLogArchiveCheckDone(const char *xlog);
00284 extern bool XLogArchiveIsBusy(const char *xlog);
00285 extern void XLogArchiveCleanup(const char *xlog);
00286
00287 #endif