4 * PostgreSQL transaction log manager
6 * Portions Copyright (c) 1996-2003, 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.54 2004/07/21 22:31:25 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 * Header for each record in XLOG
24 * NOTE: xl_len counts only the rmgr data, not the XLogRecord header,
25 * and also not any backup blocks appended to the record (which are signaled
26 * by xl_info flag bits). The total space needed for an XLOG record is
29 * SizeOfXLogRecord + xl_len + n_backup_blocks * (sizeof(BkpBlock) + BLCKSZ)
31 * rounded up to a MAXALIGN boundary (so that all xlog records start on
32 * MAXALIGN boundaries).
34 typedef struct XLogRecord
36 crc64 xl_crc; /* CRC for this record */
37 XLogRecPtr xl_prev; /* ptr to previous record in log */
38 XLogRecPtr xl_xact_prev; /* ptr to previous record of this xact */
39 TransactionId xl_xid; /* xact id */
40 uint16 xl_len; /* total len of rmgr data */
41 uint8 xl_info; /* flag bits, see below */
42 RmgrId xl_rmid; /* resource manager for this record */
44 /* ACTUAL LOG DATA FOLLOWS AT END OF STRUCT */
48 #define SizeOfXLogRecord MAXALIGN(sizeof(XLogRecord))
49 #define MAXLOGRECSZ 65535 /* the most that'll fit in xl_len */
51 #define XLogRecGetData(record) ((char*) (record) + SizeOfXLogRecord)
54 * XLOG uses only low 4 bits of xl_info. High 4 bits may be used by rmgr.
56 #define XLR_INFO_MASK 0x0F
59 * If we backed up any disk blocks with the XLOG record, we use flag bits in
60 * xl_info to signal it. We support backup of up to 3 disk blocks per XLOG
61 * record. (Could support 4 if we cared to dedicate all the xl_info bits for
62 * this purpose; currently bit 0 of xl_info is unused and available.)
64 #define XLR_BKP_BLOCK_MASK 0x0E /* all info bits used for bkp
66 #define XLR_MAX_BKP_BLOCKS 3
67 #define XLR_SET_BKP_BLOCK(iblk) (0x08 >> (iblk))
68 #define XLR_BKP_BLOCK_1 XLR_SET_BKP_BLOCK(0) /* 0x08 */
69 #define XLR_BKP_BLOCK_2 XLR_SET_BKP_BLOCK(1) /* 0x04 */
70 #define XLR_BKP_BLOCK_3 XLR_SET_BKP_BLOCK(2) /* 0x02 */
73 * Sometimes we log records which are out of transaction control.
74 * Rmgr may "or" XLOG_NO_TRAN into info passed to XLogInsert to indicate this.
76 #define XLOG_NO_TRAN XLR_INFO_MASK
79 * List of these structs is used to pass data to XLogInsert().
81 * If buffer is valid then XLOG will check if buffer must be backed up
82 * (ie, whether this is first change of that page since last checkpoint).
83 * If so, the whole page contents are attached to the XLOG record, and XLOG
84 * sets XLR_BKP_BLOCK_X bit in xl_info. Note that the buffer must be pinned
85 * and locked while this is going on, so that it won't change under us.
86 * NB: when this happens, we do not bother to insert the associated data into
87 * the XLOG record, since we assume it's present in the buffer. Therefore,
88 * rmgr redo routines MUST pay attention to XLR_BKP_BLOCK_X to know what
89 * is actually stored in the XLOG record.
91 typedef struct XLogRecData
93 Buffer buffer; /* buffer associated with this data */
96 struct XLogRecData *next;
99 extern TimeLineID ThisTimeLineID; /* current TLI */
100 extern bool InRecovery;
101 extern XLogRecPtr MyLastRecPtr;
102 extern bool MyXactMadeXLogEntry;
103 extern bool MyXactMadeTempRelUpdate;
104 extern XLogRecPtr ProcLastRecEnd;
106 /* these variables are GUC parameters related to XLOG */
107 extern int CheckPointSegments;
108 extern int XLOGbuffers;
109 extern char *XLogArchiveCommand;
110 extern char *XLOG_sync_method;
111 extern const char XLOG_sync_method_default[];
113 #define XLogArchivingActive() (XLogArchiveCommand[0] != '\0')
116 extern bool XLOG_DEBUG;
119 extern XLogRecPtr XLogInsert(RmgrId rmid, uint8 info, XLogRecData *rdata);
120 extern void XLogFlush(XLogRecPtr RecPtr);
122 extern void xlog_redo(XLogRecPtr lsn, XLogRecord *record);
123 extern void xlog_undo(XLogRecPtr lsn, XLogRecord *record);
124 extern void xlog_desc(char *buf, uint8 xl_info, char *rec);
126 extern void UpdateControlFile(void);
127 extern int XLOGShmemSize(void);
128 extern void XLOGShmemInit(void);
129 extern void XLOGPathInit(void);
130 extern void BootStrapXLOG(void);
131 extern void StartupXLOG(void);
132 extern void ShutdownXLOG(int code, Datum arg);
133 extern void InitXLOGAccess(void);
134 extern void CreateCheckPoint(bool shutdown, bool force);
135 extern void XLogPutNextOid(Oid nextOid);
136 extern XLogRecPtr GetRedoRecPtr(void);
138 /* in storage/ipc/sinval.c, but don't want to declare in sinval.h because
139 * we'd have to include xlog.h into that ...
141 extern XLogRecPtr GetUndoRecPtr(void);