PostgreSQL Source Code git master
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
snapmgr.h
Go to the documentation of this file.
1/*-------------------------------------------------------------------------
2 *
3 * snapmgr.h
4 * POSTGRES snapshot manager
5 *
6 * Portions Copyright (c) 1996-2025, 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/* This macro encodes the knowledge of which snapshots are MVCC-safe */
55#define IsMVCCSnapshot(snapshot) \
56 ((snapshot)->snapshot_type == SNAPSHOT_MVCC || \
57 (snapshot)->snapshot_type == SNAPSHOT_HISTORIC_MVCC)
58
60extern Snapshot GetLatestSnapshot(void);
61extern void SnapshotSetCommandId(CommandId curcid);
62
63extern Snapshot GetCatalogSnapshot(Oid relid);
65extern void InvalidateCatalogSnapshot(void);
67
68extern void PushActiveSnapshot(Snapshot snapshot);
69extern void PushActiveSnapshotWithLevel(Snapshot snapshot, int snap_level);
70extern void PushCopiedSnapshot(Snapshot snapshot);
71extern void UpdateActiveSnapshotCommandId(void);
72extern void PopActiveSnapshot(void);
73extern Snapshot GetActiveSnapshot(void);
74extern bool ActiveSnapshotSet(void);
75
76extern Snapshot RegisterSnapshot(Snapshot snapshot);
77extern void UnregisterSnapshot(Snapshot snapshot);
79extern void UnregisterSnapshotFromOwner(Snapshot snapshot, ResourceOwner owner);
80
81extern void AtSubCommit_Snapshot(int level);
82extern void AtSubAbort_Snapshot(int level);
83extern void AtEOXact_Snapshot(bool isCommit, bool resetXmin);
84
85extern void ImportSnapshot(const char *idstr);
86extern bool XactHasExportedSnapshots(void);
87extern void DeleteAllExportedSnapshotFiles(void);
88extern void WaitForOlderSnapshots(TransactionId limitXmin, bool progress);
90extern bool HaveRegisteredOrActiveSnapshot(void);
91
92extern char *ExportSnapshot(Snapshot snapshot);
93
94/*
95 * These live in procarray.c because they're intimately linked to the
96 * procarray contents, but thematically they better fit into snapmgr.h.
97 */
104
105/*
106 * Utility functions for implementing visibility routines in table AMs.
107 */
108extern bool XidInMVCCSnapshot(TransactionId xid, Snapshot snapshot);
109
110/* Support for catalog timetravel for logical decoding */
111struct HTAB;
112extern struct HTAB *HistoricSnapshotGetTupleCids(void);
113extern void SetupHistoricSnapshot(Snapshot historic_snapshot, struct HTAB *tuplecids);
114extern void TeardownHistoricSnapshot(bool is_error);
115extern bool HistoricSnapshotActive(void);
116
117extern Size EstimateSnapshotSpace(Snapshot snapshot);
118extern void SerializeSnapshot(Snapshot snapshot, char *start_address);
119extern Snapshot RestoreSnapshot(char *start_address);
120extern void RestoreTransactionSnapshot(Snapshot snapshot, void *source_pgproc);
121
122#endif /* SNAPMGR_H */
#define PGDLLIMPORT
Definition: c.h:1291
uint32 CommandId
Definition: c.h:637
uint32 TransactionId
Definition: c.h:623
size_t Size
Definition: c.h:576
static int progress
Definition: pgbench.c:262
unsigned int Oid
Definition: postgres_ext.h:30
bool GlobalVisTestIsRemovableFullXid(GlobalVisState *state, FullTransactionId fxid)
Definition: procarray.c:4222
void UnregisterSnapshotFromOwner(Snapshot snapshot, ResourceOwner owner)
Definition: snapmgr.c:866
struct HTAB * HistoricSnapshotGetTupleCids(void)
Definition: snapmgr.c:1685
bool GlobalVisTestIsRemovableXid(GlobalVisState *state, TransactionId xid)
Definition: procarray.c:4264
bool GlobalVisCheckRemovableFullXid(Relation rel, FullTransactionId fxid)
Definition: procarray.c:4286
void AtSubAbort_Snapshot(int level)
Definition: snapmgr.c:969
void SerializeSnapshot(Snapshot snapshot, char *start_address)
Definition: snapmgr.c:1723
void AtEOXact_Snapshot(bool isCommit, bool resetXmin)
Definition: snapmgr.c:1003
bool XidInMVCCSnapshot(TransactionId xid, Snapshot snapshot)
Definition: snapmgr.c:1859
Snapshot GetTransactionSnapshot(void)
Definition: snapmgr.c:271
Snapshot GetLatestSnapshot(void)
Definition: snapmgr.c:342
void TeardownHistoricSnapshot(bool is_error)
Definition: snapmgr.c:1672
Snapshot GetCatalogSnapshot(Oid relid)
Definition: snapmgr.c:373
void UnregisterSnapshot(Snapshot snapshot)
Definition: snapmgr.c:853
void PushActiveSnapshot(Snapshot snapshot)
Definition: snapmgr.c:669
Snapshot RestoreSnapshot(char *start_address)
Definition: snapmgr.c:1780
void AtSubCommit_Snapshot(int level)
Definition: snapmgr.c:948
PGDLLIMPORT SnapshotData SnapshotToastData
Definition: snapmgr.c:145
void UpdateActiveSnapshotCommandId(void)
Definition: snapmgr.c:731
PGDLLIMPORT TransactionId TransactionXmin
Definition: snapmgr.c:158
bool HistoricSnapshotActive(void)
Definition: snapmgr.c:1679
void ImportSnapshot(const char *idstr)
Definition: snapmgr.c:1374
bool ActiveSnapshotSet(void)
Definition: snapmgr.c:799
PGDLLIMPORT SnapshotData SnapshotAnyData
Definition: snapmgr.c:144
Snapshot RegisterSnapshot(Snapshot snapshot)
Definition: snapmgr.c:811
bool XactHasExportedSnapshots(void)
Definition: snapmgr.c:1561
void DeleteAllExportedSnapshotFiles(void)
Definition: snapmgr.c:1574
bool GlobalVisCheckRemovableXid(Relation rel, TransactionId xid)
Definition: procarray.c:4300
bool HaveRegisteredOrActiveSnapshot(void)
Definition: snapmgr.c:1631
void InvalidateCatalogSnapshotConditionally(void)
Definition: snapmgr.c:464
bool ThereAreNoPriorRegisteredSnapshots(void)
Definition: snapmgr.c:1613
void RestoreTransactionSnapshot(Snapshot snapshot, void *source_pgproc)
Definition: snapmgr.c:1843
GlobalVisState * GlobalVisTestFor(Relation rel)
Definition: procarray.c:4107
void SnapshotSetCommandId(CommandId curcid)
Definition: snapmgr.c:477
void PopActiveSnapshot(void)
Definition: snapmgr.c:762
void PushCopiedSnapshot(Snapshot snapshot)
Definition: snapmgr.c:719
char * ExportSnapshot(Snapshot snapshot)
Definition: snapmgr.c:1102
PGDLLIMPORT SnapshotData SnapshotSelfData
Definition: snapmgr.c:143
Size EstimateSnapshotSpace(Snapshot snapshot)
Definition: snapmgr.c:1699
void WaitForOlderSnapshots(TransactionId limitXmin, bool progress)
Definition: indexcmds.c:435
void SetupHistoricSnapshot(Snapshot historic_snapshot, struct HTAB *tuplecids)
Definition: snapmgr.c:1656
PGDLLIMPORT bool FirstSnapshotSet
Definition: snapmgr.c:192
Snapshot RegisterSnapshotOnOwner(Snapshot snapshot, ResourceOwner owner)
Definition: snapmgr.c:824
void InvalidateCatalogSnapshot(void)
Definition: snapmgr.c:443
void PushActiveSnapshotWithLevel(Snapshot snapshot, int snap_level)
Definition: snapmgr.c:683
Snapshot GetNonHistoricCatalogSnapshot(Oid relid)
Definition: snapmgr.c:395
PGDLLIMPORT TransactionId RecentXmin
Definition: snapmgr.c:159
Snapshot GetActiveSnapshot(void)
Definition: snapmgr.c:787
Definition: dynahash.c:220
Definition: regguts.h:323