4 * PostgreSQL transaction log manager
6 * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
7 * Portions Copyright (c) 1994, Regents of the University of California
9 * $PostgreSQL: pgsql/src/include/access/xlog.h,v 1.62 2005/06/02 05:55:29 tgl Exp $
14 #include "access/rmgr.h"
15 #include "access/transam.h"
16 #include "access/xlogdefs.h"
17 #include "storage/buf.h"
18 #include "utils/pg_crc.h"
22 * The overall layout of an XLOG record is:
23 * Fixed-size header (XLogRecord struct)
31 * where there can be zero to three backup blocks (as signaled by xl_info flag
32 * bits). XLogRecord structs always start on MAXALIGN boundaries in the WAL
33 * files, and we round up SizeOfXLogRecord so that the rmgr data is also
34 * guaranteed to begin on a MAXALIGN boundary. However, no padding is added
35 * to align BkpBlock structs or backup block data.
37 * NOTE: xl_len counts only the rmgr data, not the XLogRecord header,
38 * and also not any backup blocks. xl_tot_len counts everything. Neither
39 * length field is rounded up to an alignment boundary.
41 typedef struct XLogRecord
43 pg_crc32 xl_crc; /* CRC for this record */
44 XLogRecPtr xl_prev; /* ptr to previous record in log */
45 TransactionId xl_xid; /* xact id */
46 uint32 xl_tot_len; /* total len of entire record */
47 uint32 xl_len; /* total len of rmgr data */
48 uint8 xl_info; /* flag bits, see below */
49 RmgrId xl_rmid; /* resource manager for this record */
51 /* Depending on MAXALIGN, there are either 2 or 6 wasted bytes here */
53 /* ACTUAL LOG DATA FOLLOWS AT END OF STRUCT */
57 #define SizeOfXLogRecord MAXALIGN(sizeof(XLogRecord))
59 #define XLogRecGetData(record) ((char*) (record) + SizeOfXLogRecord)
62 * XLOG uses only low 4 bits of xl_info. High 4 bits may be used by rmgr.
64 #define XLR_INFO_MASK 0x0F
67 * If we backed up any disk blocks with the XLOG record, we use flag bits in
68 * xl_info to signal it. We support backup of up to 3 disk blocks per XLOG
69 * record. (Could support 4 if we cared to dedicate all the xl_info bits for
70 * this purpose; currently bit 0 of xl_info is unused and available.)
72 #define XLR_BKP_BLOCK_MASK 0x0E /* all info bits used for bkp
74 #define XLR_MAX_BKP_BLOCKS 3
75 #define XLR_SET_BKP_BLOCK(iblk) (0x08 >> (iblk))
76 #define XLR_BKP_BLOCK_1 XLR_SET_BKP_BLOCK(0) /* 0x08 */
77 #define XLR_BKP_BLOCK_2 XLR_SET_BKP_BLOCK(1) /* 0x04 */
78 #define XLR_BKP_BLOCK_3 XLR_SET_BKP_BLOCK(2) /* 0x02 */
81 * Sometimes we log records which are out of transaction control.
82 * Rmgr may "or" XLOG_NO_TRAN into info passed to XLogInsert to indicate this.
84 #define XLOG_NO_TRAN XLR_INFO_MASK
87 #define SYNC_METHOD_FSYNC 0
88 #define SYNC_METHOD_FDATASYNC 1
89 #define SYNC_METHOD_OPEN 2 /* for O_SYNC and O_DSYNC */
90 #define SYNC_METHOD_FSYNC_WRITETHROUGH 3
91 extern int sync_method;
94 * List of these structs is used to pass data to XLogInsert().
96 * If buffer is valid then XLOG will check if buffer must be backed up
97 * (ie, whether this is first change of that page since last checkpoint).
98 * If so, the whole page contents are attached to the XLOG record, and XLOG
99 * sets XLR_BKP_BLOCK_X bit in xl_info. Note that the buffer must be pinned
100 * and locked while this is going on, so that it won't change under us.
101 * NB: when this happens, we do not bother to insert the associated data into
102 * the XLOG record, since we assume it's present in the buffer. Therefore,
103 * rmgr redo routines MUST pay attention to XLR_BKP_BLOCK_X to know what
104 * is actually stored in the XLOG record.
106 typedef struct XLogRecData
108 Buffer buffer; /* buffer associated with this data */
111 struct XLogRecData *next;
114 extern TimeLineID ThisTimeLineID; /* current TLI */
115 extern bool InRecovery;
116 extern XLogRecPtr MyLastRecPtr;
117 extern bool MyXactMadeXLogEntry;
118 extern bool MyXactMadeTempRelUpdate;
119 extern XLogRecPtr ProcLastRecEnd;
121 /* these variables are GUC parameters related to XLOG */
122 extern int CheckPointSegments;
123 extern int XLOGbuffers;
124 extern char *XLogArchiveCommand;
125 extern char *XLOG_sync_method;
126 extern const char XLOG_sync_method_default[];
128 #define XLogArchivingActive() (XLogArchiveCommand[0] != '\0')
131 extern bool XLOG_DEBUG;
134 extern XLogRecPtr XLogInsert(RmgrId rmid, uint8 info, XLogRecData *rdata);
135 extern void XLogFlush(XLogRecPtr RecPtr);
137 extern void xlog_redo(XLogRecPtr lsn, XLogRecord *record);
138 extern void xlog_undo(XLogRecPtr lsn, XLogRecord *record);
139 extern void xlog_desc(char *buf, uint8 xl_info, char *rec);
141 extern void UpdateControlFile(void);
142 extern int XLOGShmemSize(void);
143 extern void XLOGShmemInit(void);
144 extern void XLOGPathInit(void);
145 extern void BootStrapXLOG(void);
146 extern void StartupXLOG(void);
147 extern void ShutdownXLOG(int code, Datum arg);
148 extern void InitXLOGAccess(void);
149 extern void CreateCheckPoint(bool shutdown, bool force);
150 extern void XLogPutNextOid(Oid nextOid);
151 extern void XLogPutNextMultiXactId(MultiXactId multi);
152 extern XLogRecPtr GetRedoRecPtr(void);