PostgreSQL Source Code git master
Loading...
Searching...
No Matches
snapmgr.h
Go to the documentation of this file.
1/*-------------------------------------------------------------------------
2 *
3 * snapmgr.h
4 * POSTGRES snapshot manager
5 *
6 * Portions Copyright (c) 1996-2026, PostgreSQL Global Development Group
7 * Portions Copyright (c) 1994, Regents of the University of California
8 *
9 * src/include/utils/snapmgr.h
10 *
11 *-------------------------------------------------------------------------
12 */
13#ifndef SNAPMGR_H
14#define SNAPMGR_H
15
16#include "access/transam.h"
17#include "utils/relcache.h"
18#include "utils/resowner.h"
19#include "utils/snapshot.h"
20
21
23
26
27/* Variables representing various special snapshot semantics */
31
32#define SnapshotSelf (&SnapshotSelfData)
33#define SnapshotAny (&SnapshotAnyData)
34
35/* Use get_toast_snapshot() for the TOAST snapshot */
36
37/*
38 * We don't provide a static SnapshotDirty variable because it would be
39 * non-reentrant. Instead, users of that snapshot type should declare a
40 * local variable of type SnapshotData, and initialize it with this macro.
41 */
42#define InitDirtySnapshot(snapshotdata) \
43 ((snapshotdata).snapshot_type = SNAPSHOT_DIRTY)
44
45/*
46 * Similarly, some initialization is required for a NonVacuumable snapshot.
47 * The caller must supply the visibility cutoff state to use (c.f.
48 * GlobalVisTestFor()).
49 */
50#define InitNonVacuumableSnapshot(snapshotdata, vistestp) \
51 ((snapshotdata).snapshot_type = SNAPSHOT_NON_VACUUMABLE, \
52 (snapshotdata).vistest = (vistestp))
53
54/*
55 * Is the snapshot implemented as an MVCC snapshot (i.e. it uses
56 * SNAPSHOT_MVCC)? If so, there will be at most one visible tuple in a chain
57 * of updated tuples, and each visible tuple will be seen exactly once.
58 */
59#define IsMVCCSnapshot(snapshot) \
60 ((snapshot)->snapshot_type == SNAPSHOT_MVCC)
61
62/*
63 * Special kind of MVCC snapshot, used during logical decoding. The visibility
64 * is checked from the perspective of an already committed transaction that is
65 * being decoded.
66 */
67#define IsHistoricMVCCSnapshot(snapshot) \
68 ((snapshot)->snapshot_type == SNAPSHOT_HISTORIC_MVCC)
69
70/*
71 * Is the snapshot either an MVCC snapshot or has equivalent visibility
72 * semantics (see IsMVCCSnapshot())?
73 */
74#define IsMVCCLikeSnapshot(snapshot) \
75 (IsMVCCSnapshot(snapshot) || IsHistoricMVCCSnapshot(snapshot))
76
78extern Snapshot GetLatestSnapshot(void);
79extern void SnapshotSetCommandId(CommandId curcid);
80
81extern Snapshot GetCatalogSnapshot(Oid relid);
83extern void InvalidateCatalogSnapshot(void);
85
86extern void PushActiveSnapshot(Snapshot snapshot);
87extern void PushActiveSnapshotWithLevel(Snapshot snapshot, int snap_level);
88extern void PushCopiedSnapshot(Snapshot snapshot);
89extern void UpdateActiveSnapshotCommandId(void);
90extern void PopActiveSnapshot(void);
91extern Snapshot GetActiveSnapshot(void);
92extern bool ActiveSnapshotSet(void);
93
94extern Snapshot RegisterSnapshot(Snapshot snapshot);
95extern void UnregisterSnapshot(Snapshot snapshot);
97extern void UnregisterSnapshotFromOwner(Snapshot snapshot, ResourceOwner owner);
98
99extern void AtSubCommit_Snapshot(int level);
100extern void AtSubAbort_Snapshot(int level);
101extern void AtEOXact_Snapshot(bool isCommit, bool resetXmin);
102
103extern void ImportSnapshot(const char *idstr);
104extern bool XactHasExportedSnapshots(void);
105extern void DeleteAllExportedSnapshotFiles(void);
107extern bool ThereAreNoPriorRegisteredSnapshots(void);
108extern bool HaveRegisteredOrActiveSnapshot(void);
109
110extern char *ExportSnapshot(Snapshot snapshot);
111
112/*
113 * These live in procarray.c because they're intimately linked to the
114 * procarray contents, but thematically they better fit into snapmgr.h.
115 */
122
123/*
124 * Utility functions for implementing visibility routines in table AMs.
125 */
126extern bool XidInMVCCSnapshot(TransactionId xid, Snapshot snapshot);
127
128/* Support for catalog timetravel for logical decoding */
129struct HTAB;
130extern struct HTAB *HistoricSnapshotGetTupleCids(void);
131extern void SetupHistoricSnapshot(Snapshot historic_snapshot, struct HTAB *tuplecids);
132extern void TeardownHistoricSnapshot(bool is_error);
133extern bool HistoricSnapshotActive(void);
134
135extern Size EstimateSnapshotSpace(Snapshot snapshot);
136extern void SerializeSnapshot(Snapshot snapshot, char *start_address);
138struct PGPROC;
139extern void RestoreTransactionSnapshot(Snapshot snapshot, struct PGPROC *source_pgproc);
140
141#endif /* SNAPMGR_H */
#define PGDLLIMPORT
Definition c.h:1423
uint32 CommandId
Definition c.h:752
uint32 TransactionId
Definition c.h:738
size_t Size
Definition c.h:691
static int progress
Definition pgbench.c:262
unsigned int Oid
static int fb(int x)
bool GlobalVisTestIsRemovableFullXid(GlobalVisState *state, FullTransactionId fxid)
Definition procarray.c:4229
void RestoreTransactionSnapshot(Snapshot snapshot, struct PGPROC *source_pgproc)
Definition snapmgr.c:1853
void UnregisterSnapshotFromOwner(Snapshot snapshot, ResourceOwner owner)
Definition snapmgr.c:879
struct HTAB * HistoricSnapshotGetTupleCids(void)
Definition snapmgr.c:1698
bool GlobalVisTestIsRemovableXid(GlobalVisState *state, TransactionId xid)
Definition procarray.c:4271
bool GlobalVisCheckRemovableFullXid(Relation rel, FullTransactionId fxid)
Definition procarray.c:4293
void AtSubAbort_Snapshot(int level)
Definition snapmgr.c:982
void SerializeSnapshot(Snapshot snapshot, char *start_address)
Definition snapmgr.c:1736
void AtEOXact_Snapshot(bool isCommit, bool resetXmin)
Definition snapmgr.c:1016
bool XidInMVCCSnapshot(TransactionId xid, Snapshot snapshot)
Definition snapmgr.c:1869
Snapshot GetTransactionSnapshot(void)
Definition snapmgr.c:272
Snapshot GetLatestSnapshot(void)
Definition snapmgr.c:354
void TeardownHistoricSnapshot(bool is_error)
Definition snapmgr.c:1685
Snapshot GetCatalogSnapshot(Oid relid)
Definition snapmgr.c:385
void UnregisterSnapshot(Snapshot snapshot)
Definition snapmgr.c:866
void PushActiveSnapshot(Snapshot snapshot)
Definition snapmgr.c:682
Snapshot RestoreSnapshot(char *start_address)
Definition snapmgr.c:1793
void AtSubCommit_Snapshot(int level)
Definition snapmgr.c:961
PGDLLIMPORT SnapshotData SnapshotToastData
Definition snapmgr.c:146
void UpdateActiveSnapshotCommandId(void)
Definition snapmgr.c:744
PGDLLIMPORT TransactionId TransactionXmin
Definition snapmgr.c:159
bool HistoricSnapshotActive(void)
Definition snapmgr.c:1692
void ImportSnapshot(const char *idstr)
Definition snapmgr.c:1387
bool ActiveSnapshotSet(void)
Definition snapmgr.c:812
PGDLLIMPORT SnapshotData SnapshotAnyData
Definition snapmgr.c:145
Snapshot RegisterSnapshot(Snapshot snapshot)
Definition snapmgr.c:824
bool XactHasExportedSnapshots(void)
Definition snapmgr.c:1574
void DeleteAllExportedSnapshotFiles(void)
Definition snapmgr.c:1587
bool GlobalVisCheckRemovableXid(Relation rel, TransactionId xid)
Definition procarray.c:4307
bool HaveRegisteredOrActiveSnapshot(void)
Definition snapmgr.c:1644
void InvalidateCatalogSnapshotConditionally(void)
Definition snapmgr.c:477
bool ThereAreNoPriorRegisteredSnapshots(void)
Definition snapmgr.c:1626
GlobalVisState * GlobalVisTestFor(Relation rel)
Definition procarray.c:4114
void SnapshotSetCommandId(CommandId curcid)
Definition snapmgr.c:490
void PopActiveSnapshot(void)
Definition snapmgr.c:775
void PushCopiedSnapshot(Snapshot snapshot)
Definition snapmgr.c:732
char * ExportSnapshot(Snapshot snapshot)
Definition snapmgr.c:1115
PGDLLIMPORT SnapshotData SnapshotSelfData
Definition snapmgr.c:144
Size EstimateSnapshotSpace(Snapshot snapshot)
Definition snapmgr.c:1712
void WaitForOlderSnapshots(TransactionId limitXmin, bool progress)
Definition indexcmds.c:436
void SetupHistoricSnapshot(Snapshot historic_snapshot, struct HTAB *tuplecids)
Definition snapmgr.c:1669
PGDLLIMPORT bool FirstSnapshotSet
Definition snapmgr.c:193
Snapshot RegisterSnapshotOnOwner(Snapshot snapshot, ResourceOwner owner)
Definition snapmgr.c:837
void InvalidateCatalogSnapshot(void)
Definition snapmgr.c:455
void PushActiveSnapshotWithLevel(Snapshot snapshot, int snap_level)
Definition snapmgr.c:696
Snapshot GetNonHistoricCatalogSnapshot(Oid relid)
Definition snapmgr.c:407
PGDLLIMPORT TransactionId RecentXmin
Definition snapmgr.c:160
Snapshot GetActiveSnapshot(void)
Definition snapmgr.c:800
Definition proc.h:176