Fix possible crash in pg_dump with identity sequences.
[pgsql.git] / src / include / access / multixact.h
blob7ffd256c744d38c92201cef8ea734a81f5f4fe04
1 /*
2 * multixact.h
4 * PostgreSQL multi-transaction-log manager
6 * Portions Copyright (c) 1996-2024, PostgreSQL Global Development Group
7 * Portions Copyright (c) 1994, Regents of the University of California
9 * src/include/access/multixact.h
11 #ifndef MULTIXACT_H
12 #define MULTIXACT_H
14 #include "access/xlogreader.h"
15 #include "lib/stringinfo.h"
16 #include "storage/sync.h"
20 * The first two MultiXactId values are reserved to store the truncation Xid
21 * and epoch of the first segment, so we start assigning multixact values from
22 * 2.
24 #define InvalidMultiXactId ((MultiXactId) 0)
25 #define FirstMultiXactId ((MultiXactId) 1)
26 #define MaxMultiXactId ((MultiXactId) 0xFFFFFFFF)
28 #define MultiXactIdIsValid(multi) ((multi) != InvalidMultiXactId)
30 #define MaxMultiXactOffset ((MultiXactOffset) 0xFFFFFFFF)
33 * Possible multixact lock modes ("status"). The first four modes are for
34 * tuple locks (FOR KEY SHARE, FOR SHARE, FOR NO KEY UPDATE, FOR UPDATE); the
35 * next two are used for update and delete modes.
37 typedef enum
39 MultiXactStatusForKeyShare = 0x00,
40 MultiXactStatusForShare = 0x01,
41 MultiXactStatusForNoKeyUpdate = 0x02,
42 MultiXactStatusForUpdate = 0x03,
43 /* an update that doesn't touch "key" columns */
44 MultiXactStatusNoKeyUpdate = 0x04,
45 /* other updates, and delete */
46 MultiXactStatusUpdate = 0x05,
47 } MultiXactStatus;
49 #define MaxMultiXactStatus MultiXactStatusUpdate
51 /* does a status value correspond to a tuple update? */
52 #define ISUPDATE_from_mxstatus(status) \
53 ((status) > MultiXactStatusForUpdate)
56 typedef struct MultiXactMember
58 TransactionId xid;
59 MultiXactStatus status;
60 } MultiXactMember;
63 /* ----------------
64 * multixact-related XLOG entries
65 * ----------------
68 #define XLOG_MULTIXACT_ZERO_OFF_PAGE 0x00
69 #define XLOG_MULTIXACT_ZERO_MEM_PAGE 0x10
70 #define XLOG_MULTIXACT_CREATE_ID 0x20
71 #define XLOG_MULTIXACT_TRUNCATE_ID 0x30
73 typedef struct xl_multixact_create
75 MultiXactId mid; /* new MultiXact's ID */
76 MultiXactOffset moff; /* its starting offset in members file */
77 int32 nmembers; /* number of member XIDs */
78 MultiXactMember members[FLEXIBLE_ARRAY_MEMBER];
79 } xl_multixact_create;
81 #define SizeOfMultiXactCreate (offsetof(xl_multixact_create, members))
83 typedef struct xl_multixact_truncate
85 Oid oldestMultiDB;
87 /* to-be-truncated range of multixact offsets */
88 MultiXactId startTruncOff; /* just for completeness' sake */
89 MultiXactId endTruncOff;
91 /* to-be-truncated range of multixact members */
92 MultiXactOffset startTruncMemb;
93 MultiXactOffset endTruncMemb;
94 } xl_multixact_truncate;
96 #define SizeOfMultiXactTruncate (sizeof(xl_multixact_truncate))
99 extern MultiXactId MultiXactIdCreate(TransactionId xid1,
100 MultiXactStatus status1, TransactionId xid2,
101 MultiXactStatus status2);
102 extern MultiXactId MultiXactIdExpand(MultiXactId multi, TransactionId xid,
103 MultiXactStatus status);
104 extern MultiXactId MultiXactIdCreateFromMembers(int nmembers,
105 MultiXactMember *members);
107 extern MultiXactId ReadNextMultiXactId(void);
108 extern void ReadMultiXactIdRange(MultiXactId *oldest, MultiXactId *next);
109 extern bool MultiXactIdIsRunning(MultiXactId multi, bool isLockOnly);
110 extern void MultiXactIdSetOldestMember(void);
111 extern int GetMultiXactIdMembers(MultiXactId multi, MultiXactMember **members,
112 bool from_pgupgrade, bool isLockOnly);
113 extern bool MultiXactIdPrecedes(MultiXactId multi1, MultiXactId multi2);
114 extern bool MultiXactIdPrecedesOrEquals(MultiXactId multi1,
115 MultiXactId multi2);
117 extern int multixactoffsetssyncfiletag(const FileTag *ftag, char *path);
118 extern int multixactmemberssyncfiletag(const FileTag *ftag, char *path);
120 extern void AtEOXact_MultiXact(void);
121 extern void AtPrepare_MultiXact(void);
122 extern void PostPrepare_MultiXact(TransactionId xid);
124 extern Size MultiXactShmemSize(void);
125 extern void MultiXactShmemInit(void);
126 extern void BootStrapMultiXact(void);
127 extern void StartupMultiXact(void);
128 extern void TrimMultiXact(void);
129 extern void SetMultiXactIdLimit(MultiXactId oldest_datminmxid,
130 Oid oldest_datoid,
131 bool is_startup);
132 extern void MultiXactGetCheckptMulti(bool is_shutdown,
133 MultiXactId *nextMulti,
134 MultiXactOffset *nextMultiOffset,
135 MultiXactId *oldestMulti,
136 Oid *oldestMultiDB);
137 extern void CheckPointMultiXact(void);
138 extern MultiXactId GetOldestMultiXactId(void);
139 extern void TruncateMultiXact(MultiXactId newOldestMulti,
140 Oid newOldestMultiDB);
141 extern void MultiXactSetNextMXact(MultiXactId nextMulti,
142 MultiXactOffset nextMultiOffset);
143 extern void MultiXactAdvanceNextMXact(MultiXactId minMulti,
144 MultiXactOffset minMultiOffset);
145 extern void MultiXactAdvanceOldest(MultiXactId oldestMulti, Oid oldestMultiDB);
146 extern int MultiXactMemberFreezeThreshold(void);
148 extern void multixact_twophase_recover(TransactionId xid, uint16 info,
149 void *recdata, uint32 len);
150 extern void multixact_twophase_postcommit(TransactionId xid, uint16 info,
151 void *recdata, uint32 len);
152 extern void multixact_twophase_postabort(TransactionId xid, uint16 info,
153 void *recdata, uint32 len);
155 extern void multixact_redo(XLogReaderState *record);
156 extern void multixact_desc(StringInfo buf, XLogReaderState *record);
157 extern const char *multixact_identify(uint8 info);
158 extern char *mxid_to_string(MultiXactId multi, int nmembers,
159 MultiXactMember *members);
161 #endif /* MULTIXACT_H */