99#define MULTIXACT_MEMBER_LOW_THRESHOLD UINT64CONST(2000000000)
100#define MULTIXACT_MEMBER_HIGH_THRESHOLD UINT64CONST(4000000000)
125#define MultiXactOffsetCtl (&MultiXactOffsetSlruDesc)
126#define MultiXactMemberCtl (&MultiXactMemberSlruDesc)
221#define NumMemberSlots (MaxBackends + max_prepared_xacts)
222#define NumVisibleSlots MaxBackends
299#define MAX_CACHE_ENTRIES 256
303#ifdef MULTIXACT_DEBUG
304#define debug_elog2(a,b) elog(a,b)
305#define debug_elog3(a,b,c) elog(a,b,c)
306#define debug_elog4(a,b,c,d) elog(a,b,c,d)
307#define debug_elog5(a,b,c,d,e) elog(a,b,c,d,e)
308#define debug_elog6(a,b,c,d,e,f) elog(a,b,c,d,e,f)
310#define debug_elog2(a,b)
311#define debug_elog3(a,b,c)
312#define debug_elog4(a,b,c,d)
313#define debug_elog5(a,b,c,d,e)
314#define debug_elog6(a,b,c,d,e,f)
460 for (
i = 0;
i < nmembers;
i++)
463 (members[
i].status == status))
487 for (
i = 0,
j = 0;
i < nmembers;
i++)
549 for (
i = 0;
i < nmembers;
i++)
564 for (
i = 0;
i < nmembers;
i++)
746 for (
i = 0;
i < nmembers;
i++)
751 elog(
ERROR,
"new multixact has more than one updating member: %s",
780 xlrec.nmembers = nmembers;
888 next_offset = offset + nmembers;
889 if (next_offset == 0)
904 for (
int i = 0;
i < nmembers;
i++, offset++)
988 elog(
ERROR,
"cannot assign MultiXactIds during recovery");
1040 errmsg(
"database is not accepting commands that assign new MultiXactIds to avoid wraparound data loss in database \"%s\"",
1042 errhint(
"Execute a database-wide VACUUM in that database.\n"
1043 "You might also need to commit or roll back old prepared transactions, or drop stale replication slots.")));
1047 errmsg(
"database is not accepting commands that assign new MultiXactIds to avoid wraparound data loss in database with OID %u",
1049 errhint(
"Execute a database-wide VACUUM in that database.\n"
1050 "You might also need to commit or roll back old prepared transactions, or drop stale replication slots.")));
1068 (
errmsg_plural(
"database \"%s\" must be vacuumed before %u more MultiXactId is used",
1069 "database \"%s\" must be vacuumed before %u more MultiXactIds are used",
1072 multiWrapLimit -
result),
1073 errdetail(
"Approximately %.2f%% of MultiXactIds are available for use.",
1075 errhint(
"Execute a database-wide VACUUM in that database.\n"
1076 "You might also need to commit or roll back old prepared transactions, or drop stale replication slots.")));
1079 (
errmsg_plural(
"database with OID %u must be vacuumed before %u more MultiXactId is used",
1080 "database with OID %u must be vacuumed before %u more MultiXactIds are used",
1083 multiWrapLimit -
result),
1084 errdetail(
"Approximately %.2f%% of MultiXactIds are available for use.",
1086 errhint(
"Execute a database-wide VACUUM in that database.\n"
1087 "You might also need to commit or roll back old prepared transactions, or drop stale replication slots.")));
1113 if (nextOffset + nmembers < nextOffset)
1116 errmsg(
"MultiXact members would wrap around")));
1117 *offset = nextOffset;
1245 errmsg(
"MultiXactId %u does no longer exist -- apparent wraparound",
1251 errmsg(
"MultiXactId %u has not been created yet -- apparent wraparound",
1276 errmsg(
"MultiXact %u has invalid offset", multi)));
1321 errmsg(
"MultiXact %u has invalid next offset", multi)));
1325 errmsg(
"MultiXact %u with offset (%" PRIu64 ") has zero members",
1330 errmsg(
"MultiXact %u has offset (%" PRIu64 ") greater than its next offset (%" PRIu64 ")",
1335 errmsg(
"MultiXact %u has too many members (%" PRIu64 ")",
1342 for (
int i = 0;
i < length;
i++, offset++)
1465 return entry->
multi;
1493 if (entry->
multi == multi)
1541 "MultiXact cache context",
1550 entry->
multi = multi;
1583 return "fornokeyupd";
1591 elog(
ERROR,
"unrecognized multixact status %d", status);
1611 for (
i = 1;
i < nmembers;
i++)
1786 .
name =
"multixact_offset",
1787 .Dir =
"pg_multixact/offsets",
1788 .long_segment_names =
false,
1801 .
name =
"multixact_member",
1802 .Dir =
"pg_multixact/members",
1803 .long_segment_names =
true,
2031 "MultiXact: checkpoint is nextMulti %u, nextOffset %" PRIu64 ", oldestMulti %u in DB %u",
2032 *nextMulti, *nextMultiOffset, *oldestMulti, *oldestMultiDB);
2068 nextMulti, nextMultiOffset);
2108 multiStopLimit = multiWrapLimit - 3000000;
2122 multiWarnLimit = multiWrapLimit - 100000000;
2151 (
errmsg_internal(
"MultiXactId wrap limit is %u, limited by database with OID %u",
2206 (
errmsg_plural(
"database \"%s\" must be vacuumed before %u more MultiXactId is used",
2207 "database \"%s\" must be vacuumed before %u more MultiXactIds are used",
2211 errdetail(
"Approximately %.2f%% of MultiXactIds are available for use.",
2213 errhint(
"To avoid MultiXactId assignment failures, execute a database-wide VACUUM in that database.\n"
2214 "You might also need to commit or roll back old prepared transactions, or drop stale replication slots.")));
2217 (
errmsg_plural(
"database with OID %u must be vacuumed before %u more MultiXactId is used",
2218 "database with OID %u must be vacuumed before %u more MultiXactIds are used",
2222 errdetail(
"Approximately %.2f%% of MultiXactIds are available for use.",
2224 errhint(
"To avoid MultiXactId assignment failures, execute a database-wide VACUUM in that database.\n"
2225 "You might also need to commit or roll back old prepared transactions, or drop stale replication slots.")));
2325 while (nmembers > 0)
2446 if (oldestMultiXactId == nextMXact)
2452 oldestOffset = nextOffset;
2478 (
errmsg(
"MultiXact member truncation is disabled because oldest checkpointed MultiXact %u does not exist on disk",
2479 oldestMultiXactId)));
2603 members = nextOffset - oldestOffset;
2726 (
errmsg(
"cannot truncate up to MultiXact %u because it does not exist on disk, skipping truncation",
2743 (
errmsg(
"cannot truncate up to MultiXact %u because it has invalid offset, skipping truncation",
2749 elog(
DEBUG1,
"performing multixact truncation: "
2750 "oldestMulti %u (offsets segment %" PRIx64 "), "
2751 "oldestOffset %" PRIu64 " (members segment %" PRIx64 ")",
2851 return errdetail(
"Could not access member of multixact %u at offset %" PRIu64 ".",
2854 return errdetail(
"Could not access multixact member at offset %" PRIu64 ".",
2902 xlrec.oldestMulti = oldestMulti;
2903 xlrec.oldestOffset = oldestOffset;
2957 for (
i = 0;
i <
xlrec->nmembers;
i++)
2972 elog(
DEBUG1,
"replaying multixact truncation: "
2973 "oldestMulti %u (offsets segment %" PRIx64 "), "
2974 "oldestOffset %" PRIu64 " (members segment %" PRIx64 ")",
2995 elog(
PANIC,
"multixact_redo: unknown op code %u", info);
static void pg_atomic_write_u64(volatile pg_atomic_uint64 *ptr, uint64 val)
int autovacuum_multixact_freeze_max_age
#define Assert(condition)
TransactionId MultiXactId
#define FLEXIBLE_ARRAY_MEMBER
#define MemSet(start, val, len)
memcpy(sums, checksumBaseOffsets, sizeof(checksumBaseOffsets))
int errcode(int sqlerrcode)
int errhint(const char *fmt,...) pg_attribute_printf(1
int errdetail(const char *fmt,...) pg_attribute_printf(1
int int errmsg_internal(const char *fmt,...) pg_attribute_printf(1
int int int errmsg_plural(const char *fmt_singular, const char *fmt_plural, unsigned long n,...) pg_attribute_printf(1
#define ereport(elevel,...)
#define palloc_array(type, count)
Datum difference(PG_FUNCTION_ARGS)
int multixact_offset_buffers
int multixact_member_buffers
#define dclist_container(type, membername, ptr)
static uint32 dclist_count(const dclist_head *head)
static void dclist_move_head(dclist_head *head, dlist_node *node)
static dlist_node * dclist_tail_node(dclist_head *head)
static void dclist_delete_from(dclist_head *head, dlist_node *node)
#define DCLIST_STATIC_INIT(name)
static void dclist_push_head(dclist_head *head, dlist_node *node)
static void dclist_init(dclist_head *head)
#define dclist_foreach(iter, lhead)
#define INJECTION_POINT_CACHED(name, arg)
#define INJECTION_POINT_LOAD(name)
char * get_database_name(Oid dbid)
bool LWLockAcquire(LWLock *lock, LWLockMode mode)
void LWLockRelease(LWLock *lock)
char * MemoryContextStrdup(MemoryContext context, const char *string)
void * MemoryContextAlloc(MemoryContext context, Size size)
MemoryContext TopTransactionContext
void pfree(void *pointer)
MemoryContext TopMemoryContext
#define AllocSetContextCreate
#define ALLOCSET_SMALL_SIZES
#define START_CRIT_SECTION()
#define END_CRIT_SECTION()
static MultiXactId PreviousMultiXactId(MultiXactId multi)
static SlruDesc MultiXactMemberSlruDesc
static bool MultiXactMemberPagePrecedes(int64 page1, int64 page2)
static MultiXactId GetNewMultiXactId(int nmembers, MultiXactOffset *offset)
static int mXactCacheGetById(MultiXactId multi, MultiXactMember **members)
MultiXactId MultiXactIdExpand(MultiXactId multi, TransactionId xid, MultiXactStatus status)
static void MultiXactShmemInit(void *arg)
static void ExtendMultiXactMember(MultiXactOffset offset, int nmembers)
void ReadMultiXactIdRange(MultiXactId *oldest, MultiXactId *next)
static MultiXactId * MyOldestVisibleMXactIdSlot(void)
bool MultiXactIdPrecedes(MultiXactId multi1, MultiXactId multi2)
char * mxstatus_to_string(MultiXactStatus status)
void multixact_redo(XLogReaderState *record)
static void PerformOffsetsTruncation(MultiXactId newOldestMulti)
void multixact_twophase_postcommit(FullTransactionId fxid, uint16 info, void *recdata, uint32 len)
#define debug_elog5(a, b, c, d, e)
static void MultiXactIdSetOldestVisible(void)
int multixactoffsetssyncfiletag(const FileTag *ftag, char *path)
static bool find_multixact_start(MultiXactId multi, MultiXactOffset *result)
void PostPrepare_MultiXact(FullTransactionId fxid)
void MultiXactSetNextMXact(MultiXactId nextMulti, MultiXactOffset nextMultiOffset)
#define MultiXactMemberCtl
static void WriteMTruncateXlogRec(Oid oldestMultiDB, MultiXactId endTruncOff, MultiXactOffset endTruncMemb)
static SlruDesc MultiXactOffsetSlruDesc
void AtPrepare_MultiXact(void)
bool MultiXactIdPrecedesOrEquals(MultiXactId multi1, MultiXactId multi2)
void MultiXactAdvanceOldest(MultiXactId oldestMulti, Oid oldestMultiDB)
static void mXactCachePut(MultiXactId multi, int nmembers, MultiXactMember *members)
void GetMultiXactInfo(uint32 *multixacts, MultiXactOffset *nextOffset, MultiXactId *oldestMultiXactId, MultiXactOffset *oldestOffset)
bool MultiXactIdIsRunning(MultiXactId multi, bool isLockOnly)
static void MultiXactShmemRequest(void *arg)
void MultiXactIdSetOldestMember(void)
#define MULTIXACT_MEMBER_LOW_THRESHOLD
static MemoryContext MXactContext
static MultiXactId * OldestVisibleMXactId
static int mxactMemberComparator(const void *arg1, const void *arg2)
static void ExtendMultiXactOffset(MultiXactId multi)
#define MultiXactOffsetCtl
void MultiXactGetCheckptMulti(bool is_shutdown, MultiXactId *nextMulti, MultiXactOffset *nextMultiOffset, MultiXactId *oldestMulti, Oid *oldestMultiDB)
static void RecordNewMultiXact(MultiXactId multi, MultiXactOffset offset, int nmembers, MultiXactMember *members)
int multixactmemberssyncfiletag(const FileTag *ftag, char *path)
#define MAX_CACHE_ENTRIES
static MultiXactId NextMultiXactId(MultiXactId multi)
MultiXactId GetOldestMultiXactId(void)
void CheckPointMultiXact(void)
static int MultiXactOffsetIoErrorDetail(const void *opaque_data)
static MultiXactId * PreparedXactOldestMemberMXactIdSlot(ProcNumber procno)
MultiXactId MultiXactIdCreateFromMembers(int nmembers, MultiXactMember *members)
static void MultiXactShmemAttach(void *arg)
static MultiXactId mXactCacheGetBySet(int nmembers, MultiXactMember *members)
static dclist_head MXactCache
#define debug_elog3(a, b, c)
char * mxid_to_string(MultiXactId multi, int nmembers, MultiXactMember *members)
#define debug_elog4(a, b, c, d)
void multixact_twophase_postabort(FullTransactionId fxid, uint16 info, void *recdata, uint32 len)
static void PerformMembersTruncation(MultiXactOffset newOldestOffset)
static bool MultiXactOffsetPagePrecedes(int64 page1, int64 page2)
static MultiXactId * MyOldestMemberMXactIdSlot(void)
int MultiXactMemberFreezeThreshold(void)
static void SetOldestOffset(void)
void MultiXactAdvanceNextMXact(MultiXactId minMulti, MultiXactOffset minMultiOffset)
static MultiXactId * OldestMemberMXactId
static MultiXactStateData * MultiXactState
MultiXactId ReadNextMultiXactId(void)
void BootStrapMultiXact(void)
#define debug_elog6(a, b, c, d, e, f)
void multixact_twophase_recover(FullTransactionId fxid, uint16 info, void *recdata, uint32 len)
static int MultiXactMemberIoErrorDetail(const void *opaque_data)
MultiXactId MultiXactIdCreate(TransactionId xid1, MultiXactStatus status1, TransactionId xid2, MultiXactStatus status2)
void TruncateMultiXact(MultiXactId newOldestMulti, Oid newOldestMultiDB)
bool check_multixact_offset_buffers(int *newval, void **extra, GucSource source)
bool check_multixact_member_buffers(int *newval, void **extra, GucSource source)
const ShmemCallbacks MultiXactShmemCallbacks
void AtEOXact_MultiXact(void)
#define MULTIXACT_MEMBER_HIGH_THRESHOLD
#define debug_elog2(a, b)
void StartupMultiXact(void)
void SetMultiXactIdLimit(MultiXactId oldest_datminmxid, Oid oldest_datoid)
int GetMultiXactIdMembers(MultiXactId multi, MultiXactMember **members, bool from_pgupgrade, bool isLockOnly)
#define MultiXactIdIsValid(multi)
#define XLOG_MULTIXACT_ZERO_MEM_PAGE
#define XLOG_MULTIXACT_ZERO_OFF_PAGE
@ MultiXactStatusForShare
@ MultiXactStatusForNoKeyUpdate
@ MultiXactStatusNoKeyUpdate
@ MultiXactStatusForUpdate
@ MultiXactStatusForKeyShare
#define ISUPDATE_from_mxstatus(status)
#define InvalidMultiXactId
#define XLOG_MULTIXACT_TRUNCATE_ID
#define SizeOfMultiXactCreate
#define SizeOfMultiXactTruncate
#define XLOG_MULTIXACT_CREATE_ID
static int64 MultiXactIdToOffsetSegment(MultiXactId multi)
static int64 MXOffsetToMemberSegment(MultiXactOffset offset)
#define MXACT_MEMBER_BITS_PER_XACT
static int MXOffsetToFlagsBitShift(MultiXactOffset32 offset)
#define MXACT_MEMBER_XACT_BITMASK
static int64 MXOffsetToMemberPage(MultiXactOffset32 offset)
#define MULTIXACT_OFFSETS_PER_PAGE
static int MXOffsetToMemberOffset(MultiXactOffset32 offset)
static int MultiXactIdToOffsetEntry(MultiXactId multi)
static int64 MultiXactIdToOffsetPage(MultiXactId multi)
#define MULTIXACT_MEMBERS_PER_PAGE
static int MXOffsetToFlagsOffset(MultiXactOffset32 offset)
#define ERRCODE_DATA_CORRUPTED
static rewind_source * source
static char buf[DEFAULT_XLOG_SEG_SIZE]
void SendPostmasterSignal(PMSignalReason reason)
@ PMSIGNAL_START_AUTOVAC_LAUNCHER
#define qsort(a, b, c, d)
#define FIRST_PREPARED_XACT_PROC_NUMBER
#define DELAY_CHKPT_START
bool TransactionIdIsInProgress(TransactionId xid)
Size add_size(Size s1, Size s2)
Size mul_size(Size s1, Size s2)
#define ShmemRequestStruct(...)
int SimpleLruReadPage_ReadOnly(SlruDesc *ctl, int64 pageno, const void *opaque_data)
void SimpleLruTruncate(SlruDesc *ctl, int64 cutoffPage)
void SimpleLruZeroAndWritePage(SlruDesc *ctl, int64 pageno)
int SimpleLruZeroPage(SlruDesc *ctl, int64 pageno)
bool SimpleLruDoesPhysicalPageExist(SlruDesc *ctl, int64 pageno)
void SimpleLruWriteAll(SlruDesc *ctl, bool allow_redirtied)
int SimpleLruReadPage(SlruDesc *ctl, int64 pageno, bool write_ok, const void *opaque_data)
bool check_slru_buffers(const char *name, int *newval)
int SlruSyncFileTag(SlruDesc *ctl, const FileTag *ftag, char *path)
#define SlruPagePrecedesUnitTests(ctl, per_page)
#define SimpleLruRequest(...)
static LWLock * SimpleLruGetBankLock(SlruDesc *ctl, int64 pageno)
void appendStringInfo(StringInfo str, const char *fmt,...)
void appendStringInfoChar(StringInfo str, char ch)
void initStringInfo(StringInfo str)
MultiXactId multiWrapLimit
MultiXactId multiStopLimit
MultiXactId multiWarnLimit
MultiXactId multiVacLimit
MultiXactOffset nextOffset
MultiXactId oldestMultiXactId
MultiXactId perBackendXactIds[FLEXIBLE_ARRAY_MEMBER]
MultiXactOffset oldestOffset
ShmemRequestCallback request_fn
MultiXactMember members[FLEXIBLE_ARRAY_MEMBER]
@ SYNC_HANDLER_MULTIXACT_MEMBER
@ SYNC_HANDLER_MULTIXACT_OFFSET
bool TransactionIdDidCommit(TransactionId transactionId)
#define TransactionIdEquals(id1, id2)
#define TransactionIdIsValid(xid)
static bool TransactionIdPrecedes(TransactionId id1, TransactionId id2)
ProcNumber TwoPhaseGetDummyProcNumber(FullTransactionId fxid, bool lock_held)
void RegisterTwoPhaseRecord(TwoPhaseRmgrId rmid, uint16 info, const void *data, uint32 len)
#define TWOPHASE_RM_MULTIXACT_ID
void AdvanceNextFullTransactionIdPastXid(TransactionId xid)
bool IsTransactionState(void)
bool TransactionIdIsCurrentTransactionId(TransactionId xid)
bool RecoveryInProgress(void)
void XLogFlush(XLogRecPtr record)
XLogRecPtr XLogSimpleInsertInt64(RmgrId rmid, uint8 info, int64 value)
XLogRecPtr XLogInsert(RmgrId rmid, uint8 info)
void XLogRegisterData(const void *data, uint32 len)
void XLogBeginInsert(void)
#define XLogRecGetInfo(decoder)
#define XLogRecGetData(decoder)
#define XLogRecGetXid(decoder)
#define XLogRecHasAnyBlockRefs(decoder)