203#define SNAPSHOT_EXPORT_DIR "pg_snapshots"
226 .
name =
"snapshot reference",
307 "cannot take query snapshot during a parallel operation");
362 "cannot update SecondarySnapshot during a parallel operation");
569 errmsg(
"could not import the requested snapshot"),
570 errdetail(
"The source transaction is not running anymore.")));
575 errmsg(
"could not import the requested snapshot"),
576 errdetail(
"The source process with PID %d is not running anymore.",
628 newsnap->snapXactCompletionCount = 0;
631 if (snapshot->
xcnt > 0)
764 elog(
ERROR,
"cannot modify commandid in active snapshot during a parallel operation");
852 if (
snap->regd_count == 1)
868 if (snapshot ==
NULL)
881 if (snapshot ==
NULL)
1062 &
esnap->snapshot->ph_node);
1077 elog(
WARNING,
"registered snapshots seem to remain after cleanup");
1081 elog(
WARNING,
"snapshot %p still active", active);
1156 errmsg(
"cannot export a snapshot from a subtransaction")));
1184 esnap->snapshot = snapshot;
1221 for (
i = 0;
i < snapshot->
xcnt;
i++)
1275 errmsg(
"could not rename file \"%s\" to \"%s\": %m",
1413 errmsg(
"SET TRANSACTION SNAPSHOT must be called before any query")));
1422 errmsg(
"a snapshot-importing transaction must have isolation level SERIALIZABLE or REPEATABLE READ")));
1431 errmsg(
"invalid snapshot identifier: \"%s\"",
idstr)));
1446 errmsg(
"snapshot \"%s\" does not exist",
idstr)));
1450 errmsg(
"could not open file \"%s\" for reading: %m",
1456 elog(
ERROR,
"could not stat file \"%s\": %m", path);
1461 elog(
ERROR,
"could not read file \"%s\": %m", path);
1470 memset(&snapshot, 0,
sizeof(snapshot));
1490 errmsg(
"invalid snapshot data in file \"%s\"", path)));
1493 for (
i = 0;
i < xcnt;
i++)
1506 errmsg(
"invalid snapshot data in file \"%s\"", path)));
1509 for (
i = 0;
i < xcnt;
i++)
1531 errmsg(
"invalid snapshot data in file \"%s\"", path)));
1544 errmsg(
"a serializable transaction cannot import a snapshot from a non-serializable transaction")));
1548 errmsg(
"a non-read-only serializable transaction cannot import a snapshot from a read-only transaction")));
1563 errmsg(
"cannot import a snapshot from a different database")));
1611 errmsg(
"could not remove file \"%s\": %m",
buf)));
1764 if (snapshot->
xcnt > 0)
#define Assert(condition)
#define OidIsValid(objectId)
int errcode_for_file_access(void)
int errdetail(const char *fmt,...)
int errcode(int sqlerrcode)
int errmsg(const char *fmt,...)
#define ereport(elevel,...)
struct dirent * ReadDirExtended(DIR *dir, const char *dirname, int elevel)
DIR * AllocateDir(const char *dirname)
FILE * AllocateFile(const char *name, const char *mode)
#define palloc_object(type)
#define PG_RETURN_TEXT_P(x)
#define INJECTION_POINT(name, arg)
List * lappend(List *list, void *datum)
#define VirtualTransactionIdIsValid(vxid)
void * MemoryContextAlloc(MemoryContext context, Size size)
MemoryContext TopTransactionContext
char * pstrdup(const char *in)
void pfree(void *pointer)
void pairingheap_remove(pairingheap *heap, pairingheap_node *node)
void pairingheap_add(pairingheap *heap, pairingheap_node *node)
pairingheap_node * pairingheap_first(pairingheap *heap)
#define pairingheap_is_empty(h)
#define pairingheap_is_singular(h)
#define pairingheap_container(type, membername, ptr)
#define pairingheap_const_container(type, membername, ptr)
#define pairingheap_reset(h)
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
static bool pg_lfind32(uint32 key, const uint32 *base, uint32 nelem)
static int list_length(const List *l)
static char buf[DEFAULT_XLOG_SEG_SIZE]
static Datum PointerGetDatum(const void *X)
static Pointer DatumGetPointer(Datum X)
void SetSerializableTransactionSnapshot(Snapshot snapshot, VirtualTransactionId *sourcevxid, int sourcepid)
Snapshot GetSerializableTransactionSnapshot(Snapshot snapshot)
int GetMaxSnapshotSubxidCount(void)
Snapshot GetSnapshotData(Snapshot snapshot)
int GetMaxSnapshotXidCount(void)
bool ProcArrayInstallRestoredXmin(TransactionId xmin, PGPROC *proc)
bool ProcArrayInstallImportedXmin(TransactionId xmin, VirtualTransactionId *sourcevxid)
ResourceOwner CurrentResourceOwner
void ResourceOwnerForget(ResourceOwner owner, Datum value, const ResourceOwnerDesc *kind)
void ResourceOwnerRemember(ResourceOwner owner, Datum value, const ResourceOwnerDesc *kind)
void ResourceOwnerEnlarge(ResourceOwner owner)
#define RELEASE_PRIO_SNAPSHOT_REFS
@ RESOURCE_RELEASE_AFTER_LOCKS
Size add_size(Size s1, Size s2)
Size mul_size(Size s1, Size s2)
static Snapshot HistoricSnapshot
static Snapshot FirstXactSnapshot
static SnapshotData CatalogSnapshotData
void UnregisterSnapshotFromOwner(Snapshot snapshot, ResourceOwner owner)
static void SetTransactionSnapshot(Snapshot sourcesnap, VirtualTransactionId *sourcevxid, int sourcepid, PGPROC *sourceproc)
void AtSubAbort_Snapshot(int level)
void SerializeSnapshot(Snapshot snapshot, char *start_address)
SnapshotData SnapshotSelfData
void AtEOXact_Snapshot(bool isCommit, bool resetXmin)
static Snapshot CurrentSnapshot
static Snapshot SecondarySnapshot
bool XidInMVCCSnapshot(TransactionId xid, Snapshot snapshot)
static List * exportedSnapshots
static pairingheap RegisteredSnapshots
static void UnregisterSnapshotNoOwner(Snapshot snapshot)
Snapshot GetTransactionSnapshot(void)
Snapshot GetLatestSnapshot(void)
void TeardownHistoricSnapshot(bool is_error)
Snapshot GetCatalogSnapshot(Oid relid)
void UnregisterSnapshot(Snapshot snapshot)
void PushActiveSnapshot(Snapshot snapshot)
static Snapshot CopySnapshot(Snapshot snapshot)
Snapshot RestoreSnapshot(char *start_address)
void AtSubCommit_Snapshot(int level)
static void ResourceOwnerRememberSnapshot(ResourceOwner owner, Snapshot snap)
void UpdateActiveSnapshotCommandId(void)
static void SnapshotResetXmin(void)
void RestoreTransactionSnapshot(Snapshot snapshot, PGPROC *source_pgproc)
static int parseIntFromText(const char *prefix, char **s, const char *filename)
static SnapshotData SecondarySnapshotData
static int xmin_cmp(const pairingheap_node *a, const pairingheap_node *b, void *arg)
TransactionId TransactionXmin
SnapshotData SnapshotAnyData
bool HistoricSnapshotActive(void)
void ImportSnapshot(const char *idstr)
bool ActiveSnapshotSet(void)
Snapshot RegisterSnapshot(Snapshot snapshot)
bool XactHasExportedSnapshots(void)
static const ResourceOwnerDesc snapshot_resowner_desc
void DeleteAllExportedSnapshotFiles(void)
static void parseVxidFromText(const char *prefix, char **s, const char *filename, VirtualTransactionId *vxid)
static void FreeSnapshot(Snapshot snapshot)
#define SNAPSHOT_EXPORT_DIR
bool HaveRegisteredOrActiveSnapshot(void)
void InvalidateCatalogSnapshotConditionally(void)
static SnapshotData CurrentSnapshotData
SnapshotData SnapshotToastData
static void ResourceOwnerForgetSnapshot(ResourceOwner owner, Snapshot snap)
bool ThereAreNoPriorRegisteredSnapshots(void)
void SnapshotSetCommandId(CommandId curcid)
void PopActiveSnapshot(void)
void PushCopiedSnapshot(Snapshot snapshot)
char * ExportSnapshot(Snapshot snapshot)
Size EstimateSnapshotSpace(Snapshot snapshot)
static ActiveSnapshotElt * ActiveSnapshot
void SetupHistoricSnapshot(Snapshot historic_snapshot, HTAB *tuplecids)
static HTAB * tuplecid_data
Snapshot RegisterSnapshotOnOwner(Snapshot snapshot, ResourceOwner owner)
static TransactionId parseXidFromText(const char *prefix, char **s, const char *filename)
HTAB * HistoricSnapshotGetTupleCids(void)
void InvalidateCatalogSnapshot(void)
void PushActiveSnapshotWithLevel(Snapshot snapshot, int snap_level)
Snapshot GetNonHistoricCatalogSnapshot(Oid relid)
static Snapshot CatalogSnapshot
Snapshot GetActiveSnapshot(void)
Datum pg_export_snapshot(PG_FUNCTION_ARGS)
static void ResOwnerReleaseSnapshot(Datum res)
struct SnapshotData * Snapshot
void appendStringInfo(StringInfo str, const char *fmt,...)
void appendStringInfoString(StringInfo str, const char *s)
void initStringInfo(StringInfo str)
struct ActiveSnapshotElt * as_next
uint64 snapXactCompletionCount
SnapshotType snapshot_type
LocalTransactionId localTransactionId
TransactionId SubTransGetTopmostTransaction(TransactionId xid)
bool RelationHasSysCache(Oid relid)
bool RelationInvalidatesSnapshotsOnly(Oid relid)
static bool TransactionIdFollows(TransactionId id1, TransactionId id2)
#define InvalidTransactionId
static bool TransactionIdFollowsOrEquals(TransactionId id1, TransactionId id2)
#define FirstNormalTransactionId
#define TransactionIdIsValid(xid)
#define TransactionIdIsNormal(xid)
static bool TransactionIdPrecedes(TransactionId id1, TransactionId id2)
text * cstring_to_text(const char *s)
int GetCurrentTransactionNestLevel(void)
TransactionId GetTopTransactionIdIfAny(void)
bool IsSubTransaction(void)
bool IsInParallelMode(void)
int xactGetCommittedChildren(TransactionId **ptr)
CommandId GetCurrentCommandId(bool used)
#define XACT_SERIALIZABLE
#define IsolationUsesXactSnapshot()
#define IsolationIsSerializable()