Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #ifndef XLOG_H
00012 #define XLOG_H
00013
00014 #include "access/rmgr.h"
00015 #include "access/xlogdefs.h"
00016 #include "datatype/timestamp.h"
00017 #include "lib/stringinfo.h"
00018 #include "storage/buf.h"
00019 #include "utils/pg_crc.h"
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041 typedef struct XLogRecord
00042 {
00043 uint32 xl_tot_len;
00044 TransactionId xl_xid;
00045 uint32 xl_len;
00046 uint8 xl_info;
00047 RmgrId xl_rmid;
00048
00049 XLogRecPtr xl_prev;
00050 pg_crc32 xl_crc;
00051
00052
00053
00054
00055
00056 } XLogRecord;
00057
00058 #define SizeOfXLogRecord MAXALIGN(sizeof(XLogRecord))
00059
00060 #define XLogRecGetData(record) ((char*) (record) + SizeOfXLogRecord)
00061
00062
00063
00064
00065 #define XLR_INFO_MASK 0x0F
00066
00067
00068
00069
00070
00071
00072 #define XLR_BKP_BLOCK_MASK 0x0F
00073 #define XLR_MAX_BKP_BLOCKS 4
00074 #define XLR_BKP_BLOCK(iblk) (0x08 >> (iblk))
00075
00076
00077 #define SYNC_METHOD_FSYNC 0
00078 #define SYNC_METHOD_FDATASYNC 1
00079 #define SYNC_METHOD_OPEN 2
00080 #define SYNC_METHOD_FSYNC_WRITETHROUGH 3
00081 #define SYNC_METHOD_OPEN_DSYNC 4
00082 extern int sync_method;
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114 typedef struct XLogRecData
00115 {
00116 char *data;
00117 uint32 len;
00118 Buffer buffer;
00119 bool buffer_std;
00120 struct XLogRecData *next;
00121 } XLogRecData;
00122
00123 extern PGDLLIMPORT TimeLineID ThisTimeLineID;
00124
00125
00126
00127
00128
00129
00130
00131
00132 extern bool InRecovery;
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155 typedef enum
00156 {
00157 STANDBY_DISABLED,
00158 STANDBY_INITIALIZED,
00159 STANDBY_SNAPSHOT_PENDING,
00160 STANDBY_SNAPSHOT_READY
00161 } HotStandbyState;
00162
00163 extern HotStandbyState standbyState;
00164
00165 #define InHotStandby (standbyState >= STANDBY_SNAPSHOT_PENDING)
00166
00167
00168
00169
00170
00171 typedef enum
00172 {
00173 RECOVERY_TARGET_UNSET,
00174 RECOVERY_TARGET_XID,
00175 RECOVERY_TARGET_TIME,
00176 RECOVERY_TARGET_NAME
00177 } RecoveryTargetType;
00178
00179 extern XLogRecPtr XactLastRecEnd;
00180
00181 extern bool reachedConsistency;
00182
00183
00184 extern int CheckPointSegments;
00185 extern int wal_keep_segments;
00186 extern int XLOGbuffers;
00187 extern int XLogArchiveTimeout;
00188 extern bool XLogArchiveMode;
00189 extern char *XLogArchiveCommand;
00190 extern bool EnableHotStandby;
00191 extern bool fullPageWrites;
00192 extern bool log_checkpoints;
00193
00194
00195 typedef enum WalLevel
00196 {
00197 WAL_LEVEL_MINIMAL = 0,
00198 WAL_LEVEL_ARCHIVE,
00199 WAL_LEVEL_HOT_STANDBY
00200 } WalLevel;
00201 extern int wal_level;
00202
00203 #define XLogArchivingActive() (XLogArchiveMode && wal_level >= WAL_LEVEL_ARCHIVE)
00204 #define XLogArchiveCommandSet() (XLogArchiveCommand[0] != '\0')
00205
00206
00207
00208
00209
00210 #define XLogIsNeeded() (wal_level >= WAL_LEVEL_ARCHIVE)
00211
00212
00213 #define XLogStandbyInfoActive() (wal_level >= WAL_LEVEL_HOT_STANDBY)
00214
00215 #ifdef WAL_DEBUG
00216 extern bool XLOG_DEBUG;
00217 #endif
00218
00219
00220
00221
00222
00223
00224
00225
00226 #define CHECKPOINT_IS_SHUTDOWN 0x0001
00227 #define CHECKPOINT_END_OF_RECOVERY 0x0002
00228
00229
00230 #define CHECKPOINT_IMMEDIATE 0x0004
00231 #define CHECKPOINT_FORCE 0x0008
00232
00233 #define CHECKPOINT_WAIT 0x0010
00234
00235 #define CHECKPOINT_CAUSE_XLOG 0x0020
00236 #define CHECKPOINT_CAUSE_TIME 0x0040
00237
00238
00239 typedef struct CheckpointStatsData
00240 {
00241 TimestampTz ckpt_start_t;
00242 TimestampTz ckpt_write_t;
00243 TimestampTz ckpt_sync_t;
00244 TimestampTz ckpt_sync_end_t;
00245 TimestampTz ckpt_end_t;
00246
00247 int ckpt_bufs_written;
00248
00249 int ckpt_segs_added;
00250 int ckpt_segs_removed;
00251 int ckpt_segs_recycled;
00252
00253 int ckpt_sync_rels;
00254 uint64 ckpt_longest_sync;
00255 uint64 ckpt_agg_sync_time;
00256
00257
00258
00259 } CheckpointStatsData;
00260
00261 extern CheckpointStatsData CheckpointStats;
00262
00263 extern XLogRecPtr XLogInsert(RmgrId rmid, uint8 info, XLogRecData *rdata);
00264 extern void XLogFlush(XLogRecPtr RecPtr);
00265 extern bool XLogBackgroundFlush(void);
00266 extern bool XLogNeedsFlush(XLogRecPtr RecPtr);
00267 extern int XLogFileInit(XLogSegNo segno, bool *use_existent, bool use_lock);
00268 extern int XLogFileOpen(XLogSegNo segno);
00269
00270 extern XLogRecPtr XLogSaveBufferForHint(Buffer buffer);
00271
00272 extern void CheckXLogRemoved(XLogSegNo segno, TimeLineID tli);
00273 extern void XLogSetAsyncXactLSN(XLogRecPtr record);
00274
00275 extern Buffer RestoreBackupBlock(XLogRecPtr lsn, XLogRecord *record,
00276 int block_index,
00277 bool get_cleanup_lock, bool keep_buffer);
00278
00279 extern void xlog_redo(XLogRecPtr lsn, XLogRecord *record);
00280 extern void xlog_desc(StringInfo buf, uint8 xl_info, char *rec);
00281
00282 extern void issue_xlog_fsync(int fd, XLogSegNo segno);
00283
00284 extern bool RecoveryInProgress(void);
00285 extern bool HotStandbyActive(void);
00286 extern bool XLogInsertAllowed(void);
00287 extern void GetXLogReceiptTime(TimestampTz *rtime, bool *fromStream);
00288 extern XLogRecPtr GetXLogReplayRecPtr(TimeLineID *replayTLI);
00289 extern XLogRecPtr GetXLogInsertRecPtr(void);
00290 extern XLogRecPtr GetXLogWriteRecPtr(void);
00291 extern bool RecoveryIsPaused(void);
00292 extern void SetRecoveryPause(bool recoveryPause);
00293 extern TimestampTz GetLatestXTime(void);
00294 extern TimestampTz GetCurrentChunkReplayStartTime(void);
00295 extern char *XLogFileNameP(TimeLineID tli, XLogSegNo segno);
00296
00297 extern void UpdateControlFile(void);
00298 extern uint64 GetSystemIdentifier(void);
00299 extern bool DataChecksumsEnabled(void);
00300 extern XLogRecPtr GetFakeLSNForUnloggedRel(void);
00301 extern Size XLOGShmemSize(void);
00302 extern void XLOGShmemInit(void);
00303 extern void BootStrapXLOG(void);
00304 extern void StartupXLOG(void);
00305 extern void ShutdownXLOG(int code, Datum arg);
00306 extern void InitXLOGAccess(void);
00307 extern void CreateCheckPoint(int flags);
00308 extern bool CreateRestartPoint(int flags);
00309 extern void XLogPutNextOid(Oid nextOid);
00310 extern XLogRecPtr XLogRestorePoint(const char *rpName);
00311 extern void UpdateFullPageWrites(void);
00312 extern XLogRecPtr GetRedoRecPtr(void);
00313 extern XLogRecPtr GetInsertRecPtr(void);
00314 extern XLogRecPtr GetFlushRecPtr(void);
00315 extern void GetNextXidAndEpoch(TransactionId *xid, uint32 *epoch);
00316
00317 extern bool CheckPromoteSignal(void);
00318 extern void WakeupRecovery(void);
00319 extern void SetWalWriterSleeping(bool sleeping);
00320
00321
00322
00323
00324 extern XLogRecPtr do_pg_start_backup(const char *backupidstr, bool fast,
00325 TimeLineID *starttli_p, char **labelfile);
00326 extern XLogRecPtr do_pg_stop_backup(char *labelfile, bool waitforarchive,
00327 TimeLineID *stoptli_p);
00328 extern void do_pg_abort_backup(void);
00329
00330
00331 #define BACKUP_LABEL_FILE "backup_label"
00332 #define BACKUP_LABEL_OLD "backup_label.old"
00333
00334 #endif