gooderp18绿色标准版
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

380 rindas
13KB

  1. /*
  2. * xlog.h
  3. *
  4. * PostgreSQL write-ahead log manager
  5. *
  6. * Portions Copyright (c) 1996-2019, PostgreSQL Global Development Group
  7. * Portions Copyright (c) 1994, Regents of the University of California
  8. *
  9. * src/include/access/xlog.h
  10. */
  11. #ifndef XLOG_H
  12. #define XLOG_H
  13. #include "access/rmgr.h"
  14. #include "access/xlogdefs.h"
  15. #include "access/xloginsert.h"
  16. #include "access/xlogreader.h"
  17. #include "datatype/timestamp.h"
  18. #include "lib/stringinfo.h"
  19. #include "nodes/pg_list.h"
  20. #include "storage/fd.h"
  21. /* Sync methods */
  22. #define SYNC_METHOD_FSYNC 0
  23. #define SYNC_METHOD_FDATASYNC 1
  24. #define SYNC_METHOD_OPEN 2 /* for O_SYNC */
  25. #define SYNC_METHOD_FSYNC_WRITETHROUGH 3
  26. #define SYNC_METHOD_OPEN_DSYNC 4 /* for O_DSYNC */
  27. extern int sync_method;
  28. extern PGDLLIMPORT TimeLineID ThisTimeLineID; /* current TLI */
  29. /*
  30. * Prior to 8.4, all activity during recovery was carried out by the startup
  31. * process. This local variable continues to be used in many parts of the
  32. * code to indicate actions taken by RecoveryManagers. Other processes that
  33. * potentially perform work during recovery should check RecoveryInProgress().
  34. * See XLogCtl notes in xlog.c.
  35. */
  36. extern bool InRecovery;
  37. /*
  38. * Like InRecovery, standbyState is only valid in the startup process.
  39. * In all other processes it will have the value STANDBY_DISABLED (so
  40. * InHotStandby will read as false).
  41. *
  42. * In DISABLED state, we're performing crash recovery or hot standby was
  43. * disabled in postgresql.conf.
  44. *
  45. * In INITIALIZED state, we've run InitRecoveryTransactionEnvironment, but
  46. * we haven't yet processed a RUNNING_XACTS or shutdown-checkpoint WAL record
  47. * to initialize our master-transaction tracking system.
  48. *
  49. * When the transaction tracking is initialized, we enter the SNAPSHOT_PENDING
  50. * state. The tracked information might still be incomplete, so we can't allow
  51. * connections yet, but redo functions must update the in-memory state when
  52. * appropriate.
  53. *
  54. * In SNAPSHOT_READY mode, we have full knowledge of transactions that are
  55. * (or were) running in the master at the current WAL location. Snapshots
  56. * can be taken, and read-only queries can be run.
  57. */
  58. typedef enum
  59. {
  60. STANDBY_DISABLED,
  61. STANDBY_INITIALIZED,
  62. STANDBY_SNAPSHOT_PENDING,
  63. STANDBY_SNAPSHOT_READY
  64. } HotStandbyState;
  65. extern HotStandbyState standbyState;
  66. #define InHotStandby (standbyState >= STANDBY_SNAPSHOT_PENDING)
  67. /*
  68. * Recovery target type.
  69. * Only set during a Point in Time recovery, not when in standby mode.
  70. */
  71. typedef enum
  72. {
  73. RECOVERY_TARGET_UNSET,
  74. RECOVERY_TARGET_XID,
  75. RECOVERY_TARGET_TIME,
  76. RECOVERY_TARGET_NAME,
  77. RECOVERY_TARGET_LSN,
  78. RECOVERY_TARGET_IMMEDIATE
  79. } RecoveryTargetType;
  80. /*
  81. * Recovery target TimeLine goal
  82. */
  83. typedef enum
  84. {
  85. RECOVERY_TARGET_TIMELINE_CONTROLFILE,
  86. RECOVERY_TARGET_TIMELINE_LATEST,
  87. RECOVERY_TARGET_TIMELINE_NUMERIC
  88. } RecoveryTargetTimeLineGoal;
  89. extern XLogRecPtr ProcLastRecPtr;
  90. extern XLogRecPtr XactLastRecEnd;
  91. extern PGDLLIMPORT XLogRecPtr XactLastCommitEnd;
  92. extern bool reachedConsistency;
  93. /* these variables are GUC parameters related to XLOG */
  94. extern int wal_segment_size;
  95. extern int min_wal_size_mb;
  96. extern int max_wal_size_mb;
  97. extern int wal_keep_segments;
  98. extern int XLOGbuffers;
  99. extern int XLogArchiveTimeout;
  100. extern int wal_retrieve_retry_interval;
  101. extern char *XLogArchiveCommand;
  102. extern bool EnableHotStandby;
  103. extern bool fullPageWrites;
  104. extern bool wal_log_hints;
  105. extern bool wal_compression;
  106. extern bool wal_init_zero;
  107. extern bool wal_recycle;
  108. extern bool *wal_consistency_checking;
  109. extern char *wal_consistency_checking_string;
  110. extern bool log_checkpoints;
  111. extern char *recoveryRestoreCommand;
  112. extern char *recoveryEndCommand;
  113. extern char *archiveCleanupCommand;
  114. extern bool recoveryTargetInclusive;
  115. extern int recoveryTargetAction;
  116. extern int recovery_min_apply_delay;
  117. extern char *PrimaryConnInfo;
  118. extern char *PrimarySlotName;
  119. /* indirectly set via GUC system */
  120. extern TransactionId recoveryTargetXid;
  121. extern char *recovery_target_time_string;
  122. extern const char *recoveryTargetName;
  123. extern XLogRecPtr recoveryTargetLSN;
  124. extern RecoveryTargetType recoveryTarget;
  125. extern char *PromoteTriggerFile;
  126. extern RecoveryTargetTimeLineGoal recoveryTargetTimeLineGoal;
  127. extern TimeLineID recoveryTargetTLIRequested;
  128. extern TimeLineID recoveryTargetTLI;
  129. extern int CheckPointSegments;
  130. /* option set locally in startup process only when signal files exist */
  131. extern bool StandbyModeRequested;
  132. extern bool StandbyMode;
  133. /* Archive modes */
  134. typedef enum ArchiveMode
  135. {
  136. ARCHIVE_MODE_OFF = 0, /* disabled */
  137. ARCHIVE_MODE_ON, /* enabled while server is running normally */
  138. ARCHIVE_MODE_ALWAYS /* enabled always (even during recovery) */
  139. } ArchiveMode;
  140. extern int XLogArchiveMode;
  141. /* WAL levels */
  142. typedef enum WalLevel
  143. {
  144. WAL_LEVEL_MINIMAL = 0,
  145. WAL_LEVEL_REPLICA,
  146. WAL_LEVEL_LOGICAL
  147. } WalLevel;
  148. /* Recovery states */
  149. typedef enum RecoveryState
  150. {
  151. RECOVERY_STATE_CRASH = 0, /* crash recovery */
  152. RECOVERY_STATE_ARCHIVE, /* archive recovery */
  153. RECOVERY_STATE_DONE /* currently in production */
  154. } RecoveryState;
  155. extern PGDLLIMPORT int wal_level;
  156. /* Is WAL archiving enabled (always or only while server is running normally)? */
  157. #define XLogArchivingActive() \
  158. (AssertMacro(XLogArchiveMode == ARCHIVE_MODE_OFF || wal_level >= WAL_LEVEL_REPLICA), XLogArchiveMode > ARCHIVE_MODE_OFF)
  159. /* Is WAL archiving enabled always (even during recovery)? */
  160. #define XLogArchivingAlways() \
  161. (AssertMacro(XLogArchiveMode == ARCHIVE_MODE_OFF || wal_level >= WAL_LEVEL_REPLICA), XLogArchiveMode == ARCHIVE_MODE_ALWAYS)
  162. #define XLogArchiveCommandSet() (XLogArchiveCommand[0] != '\0')
  163. /*
  164. * Is WAL-logging necessary for archival or log-shipping, or can we skip
  165. * WAL-logging if we fsync() the data before committing instead?
  166. */
  167. #define XLogIsNeeded() (wal_level >= WAL_LEVEL_REPLICA)
  168. /*
  169. * Is a full-page image needed for hint bit updates?
  170. *
  171. * Normally, we don't WAL-log hint bit updates, but if checksums are enabled,
  172. * we have to protect them against torn page writes. When you only set
  173. * individual bits on a page, it's still consistent no matter what combination
  174. * of the bits make it to disk, but the checksum wouldn't match. Also WAL-log
  175. * them if forced by wal_log_hints=on.
  176. */
  177. #define XLogHintBitIsNeeded() (DataChecksumsEnabled() || wal_log_hints)
  178. /* Do we need to WAL-log information required only for Hot Standby and logical replication? */
  179. #define XLogStandbyInfoActive() (wal_level >= WAL_LEVEL_REPLICA)
  180. /* Do we need to WAL-log information required only for logical replication? */
  181. #define XLogLogicalInfoActive() (wal_level >= WAL_LEVEL_LOGICAL)
  182. #ifdef WAL_DEBUG
  183. extern bool XLOG_DEBUG;
  184. #endif
  185. /*
  186. * OR-able request flag bits for checkpoints. The "cause" bits are used only
  187. * for logging purposes. Note: the flags must be defined so that it's
  188. * sensible to OR together request flags arising from different requestors.
  189. */
  190. /* These directly affect the behavior of CreateCheckPoint and subsidiaries */
  191. #define CHECKPOINT_IS_SHUTDOWN 0x0001 /* Checkpoint is for shutdown */
  192. #define CHECKPOINT_END_OF_RECOVERY 0x0002 /* Like shutdown checkpoint, but
  193. * issued at end of WAL recovery */
  194. #define CHECKPOINT_IMMEDIATE 0x0004 /* Do it without delays */
  195. #define CHECKPOINT_FORCE 0x0008 /* Force even if no activity */
  196. #define CHECKPOINT_FLUSH_ALL 0x0010 /* Flush all pages, including those
  197. * belonging to unlogged tables */
  198. /* These are important to RequestCheckpoint */
  199. #define CHECKPOINT_WAIT 0x0020 /* Wait for completion */
  200. #define CHECKPOINT_REQUESTED 0x0040 /* Checkpoint request has been made */
  201. /* These indicate the cause of a checkpoint request */
  202. #define CHECKPOINT_CAUSE_XLOG 0x0080 /* XLOG consumption */
  203. #define CHECKPOINT_CAUSE_TIME 0x0100 /* Elapsed time */
  204. /*
  205. * Flag bits for the record being inserted, set using XLogSetRecordFlags().
  206. */
  207. #define XLOG_INCLUDE_ORIGIN 0x01 /* include the replication origin */
  208. #define XLOG_MARK_UNIMPORTANT 0x02 /* record not important for durability */
  209. /* Checkpoint statistics */
  210. typedef struct CheckpointStatsData
  211. {
  212. TimestampTz ckpt_start_t; /* start of checkpoint */
  213. TimestampTz ckpt_write_t; /* start of flushing buffers */
  214. TimestampTz ckpt_sync_t; /* start of fsyncs */
  215. TimestampTz ckpt_sync_end_t; /* end of fsyncs */
  216. TimestampTz ckpt_end_t; /* end of checkpoint */
  217. int ckpt_bufs_written; /* # of buffers written */
  218. int ckpt_segs_added; /* # of new xlog segments created */
  219. int ckpt_segs_removed; /* # of xlog segments deleted */
  220. int ckpt_segs_recycled; /* # of xlog segments recycled */
  221. int ckpt_sync_rels; /* # of relations synced */
  222. uint64 ckpt_longest_sync; /* Longest sync for one relation */
  223. uint64 ckpt_agg_sync_time; /* The sum of all the individual sync
  224. * times, which is not necessarily the
  225. * same as the total elapsed time for the
  226. * entire sync phase. */
  227. } CheckpointStatsData;
  228. extern CheckpointStatsData CheckpointStats;
  229. struct XLogRecData;
  230. extern XLogRecPtr XLogInsertRecord(struct XLogRecData *rdata,
  231. XLogRecPtr fpw_lsn,
  232. uint8 flags);
  233. extern void XLogFlush(XLogRecPtr RecPtr);
  234. extern bool XLogBackgroundFlush(void);
  235. extern bool XLogNeedsFlush(XLogRecPtr RecPtr);
  236. extern int XLogFileInit(XLogSegNo segno, bool *use_existent, bool use_lock);
  237. extern int XLogFileOpen(XLogSegNo segno);
  238. extern void CheckXLogRemoved(XLogSegNo segno, TimeLineID tli);
  239. extern XLogSegNo XLogGetLastRemovedSegno(void);
  240. extern void XLogSetAsyncXactLSN(XLogRecPtr record);
  241. extern void XLogSetReplicationSlotMinimumLSN(XLogRecPtr lsn);
  242. extern void xlog_redo(XLogReaderState *record);
  243. extern void xlog_desc(StringInfo buf, XLogReaderState *record);
  244. extern const char *xlog_identify(uint8 info);
  245. extern void issue_xlog_fsync(int fd, XLogSegNo segno);
  246. extern bool RecoveryInProgress(void);
  247. extern RecoveryState GetRecoveryState(void);
  248. extern bool HotStandbyActive(void);
  249. extern bool HotStandbyActiveInReplay(void);
  250. extern bool XLogInsertAllowed(void);
  251. extern void GetXLogReceiptTime(TimestampTz *rtime, bool *fromStream);
  252. extern XLogRecPtr GetXLogReplayRecPtr(TimeLineID *replayTLI);
  253. extern XLogRecPtr GetXLogInsertRecPtr(void);
  254. extern XLogRecPtr GetXLogWriteRecPtr(void);
  255. extern bool RecoveryIsPaused(void);
  256. extern void SetRecoveryPause(bool recoveryPause);
  257. extern TimestampTz GetLatestXTime(void);
  258. extern TimestampTz GetCurrentChunkReplayStartTime(void);
  259. extern char *XLogFileNameP(TimeLineID tli, XLogSegNo segno);
  260. extern void UpdateControlFile(void);
  261. extern uint64 GetSystemIdentifier(void);
  262. extern char *GetMockAuthenticationNonce(void);
  263. extern bool DataChecksumsEnabled(void);
  264. extern XLogRecPtr GetFakeLSNForUnloggedRel(void);
  265. extern Size XLOGShmemSize(void);
  266. extern void XLOGShmemInit(void);
  267. extern void BootStrapXLOG(void);
  268. extern void LocalProcessControlFile(bool reset);
  269. extern void StartupXLOG(void);
  270. extern void ShutdownXLOG(int code, Datum arg);
  271. extern void InitXLOGAccess(void);
  272. extern void CreateCheckPoint(int flags);
  273. extern bool CreateRestartPoint(int flags);
  274. extern void XLogPutNextOid(Oid nextOid);
  275. extern XLogRecPtr XLogRestorePoint(const char *rpName);
  276. extern void UpdateFullPageWrites(void);
  277. extern void GetFullPageWriteInfo(XLogRecPtr *RedoRecPtr_p, bool *doPageWrites_p);
  278. extern XLogRecPtr GetRedoRecPtr(void);
  279. extern XLogRecPtr GetInsertRecPtr(void);
  280. extern XLogRecPtr GetFlushRecPtr(void);
  281. extern XLogRecPtr GetLastImportantRecPtr(void);
  282. extern void RemovePromoteSignalFiles(void);
  283. extern bool CheckPromoteSignal(void);
  284. extern void WakeupRecovery(void);
  285. extern void SetWalWriterSleeping(bool sleeping);
  286. extern void XLogRequestWalReceiverReply(void);
  287. extern void assign_max_wal_size(int newval, void *extra);
  288. extern void assign_checkpoint_completion_target(double newval, void *extra);
  289. /*
  290. * Routines to start, stop, and get status of a base backup.
  291. */
  292. /*
  293. * Session-level status of base backups
  294. *
  295. * This is used in parallel with the shared memory status to control parallel
  296. * execution of base backup functions for a given session, be it a backend
  297. * dedicated to replication or a normal backend connected to a database. The
  298. * update of the session-level status happens at the same time as the shared
  299. * memory counters to keep a consistent global and local state of the backups
  300. * running.
  301. */
  302. typedef enum SessionBackupState
  303. {
  304. SESSION_BACKUP_NONE,
  305. SESSION_BACKUP_EXCLUSIVE,
  306. SESSION_BACKUP_NON_EXCLUSIVE
  307. } SessionBackupState;
  308. extern XLogRecPtr do_pg_start_backup(const char *backupidstr, bool fast,
  309. TimeLineID *starttli_p, StringInfo labelfile,
  310. List **tablespaces, StringInfo tblspcmapfile, bool infotbssize,
  311. bool needtblspcmapfile);
  312. extern XLogRecPtr do_pg_stop_backup(char *labelfile, bool waitforarchive,
  313. TimeLineID *stoptli_p);
  314. extern void do_pg_abort_backup(int code, Datum arg);
  315. extern void register_persistent_abort_backup_handler(void);
  316. extern SessionBackupState get_backup_status(void);
  317. /* File path names (all relative to $PGDATA) */
  318. #define RECOVERY_SIGNAL_FILE "recovery.signal"
  319. #define STANDBY_SIGNAL_FILE "standby.signal"
  320. #define BACKUP_LABEL_FILE "backup_label"
  321. #define BACKUP_LABEL_OLD "backup_label.old"
  322. #define TABLESPACE_MAP "tablespace_map"
  323. #define TABLESPACE_MAP_OLD "tablespace_map.old"
  324. /* files to signal promotion to primary */
  325. #define PROMOTE_SIGNAL_FILE "promote"
  326. #define FALLBACK_PROMOTE_SIGNAL_FILE "fallback_promote"
  327. #endif /* XLOG_H */
上海开阖软件有限公司 沪ICP备12045867号-1