]> granicus.if.org Git - postgresql/blob - src/include/access/xlog.h
Invent WAL timelines, as per recent discussion, to make point-in-time
[postgresql] / src / include / access / xlog.h
1 /*
2  * xlog.h
3  *
4  * PostgreSQL transaction log manager
5  *
6  * Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
7  * Portions Copyright (c) 1994, Regents of the University of California
8  *
9  * $PostgreSQL: pgsql/src/include/access/xlog.h,v 1.54 2004/07/21 22:31:25 tgl Exp $
10  */
11 #ifndef XLOG_H
12 #define XLOG_H
13
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"
19
20
21 /*
22  * Header for each record in XLOG
23  *
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
27  * really:
28  *
29  * SizeOfXLogRecord + xl_len + n_backup_blocks * (sizeof(BkpBlock) + BLCKSZ)
30  *
31  * rounded up to a MAXALIGN boundary (so that all xlog records start on
32  * MAXALIGN boundaries).
33  */
34 typedef struct XLogRecord
35 {
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 */
43
44         /* ACTUAL LOG DATA FOLLOWS AT END OF STRUCT */
45
46 } XLogRecord;
47
48 #define SizeOfXLogRecord        MAXALIGN(sizeof(XLogRecord))
49 #define MAXLOGRECSZ                     65535           /* the most that'll fit in xl_len */
50
51 #define XLogRecGetData(record)  ((char*) (record) + SizeOfXLogRecord)
52
53 /*
54  * XLOG uses only low 4 bits of xl_info.  High 4 bits may be used by rmgr.
55  */
56 #define XLR_INFO_MASK                   0x0F
57
58 /*
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.)
63  */
64 #define XLR_BKP_BLOCK_MASK              0x0E    /* all info bits used for bkp
65                                                                                  * blocks */
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 */
71
72 /*
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.
75  */
76 #define XLOG_NO_TRAN                    XLR_INFO_MASK
77
78 /*
79  * List of these structs is used to pass data to XLogInsert().
80  *
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.
90  */
91 typedef struct XLogRecData
92 {
93         Buffer          buffer;                 /* buffer associated with this data */
94         char       *data;
95         uint32          len;
96         struct XLogRecData *next;
97 } XLogRecData;
98
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;
105
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[];
112
113 #define XLogArchivingActive()   (XLogArchiveCommand[0] != '\0')
114
115 #ifdef WAL_DEBUG
116 extern bool     XLOG_DEBUG;
117 #endif
118
119 extern XLogRecPtr XLogInsert(RmgrId rmid, uint8 info, XLogRecData *rdata);
120 extern void XLogFlush(XLogRecPtr RecPtr);
121
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);
125
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);
137
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 ...
140  */
141 extern XLogRecPtr GetUndoRecPtr(void);
142
143 #endif   /* XLOG_H */