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-2024, 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:1274
uint32 CommandId
Definition: c.h:620
uint32 TransactionId
Definition: c.h:606
size_t Size
Definition: c.h:559
static int progress
Definition: pgbench.c:261
unsigned int Oid
Definition: postgres_ext.h:31
bool GlobalVisTestIsRemovableFullXid(GlobalVisState *state, FullTransactionId fxid)
Definition: procarray.c:4222
void UnregisterSnapshotFromOwner(Snapshot snapshot, ResourceOwner owner)
Definition: snapmgr.c:807
struct HTAB * HistoricSnapshotGetTupleCids(void)
Definition: snapmgr.c:1626
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:910
void SerializeSnapshot(Snapshot snapshot, char *start_address)
Definition: snapmgr.c:1664
void AtEOXact_Snapshot(bool isCommit, bool resetXmin)
Definition: snapmgr.c:944
bool XidInMVCCSnapshot(TransactionId xid, Snapshot snapshot)
Definition: snapmgr.c:1800
Snapshot GetTransactionSnapshot(void)
Definition: snapmgr.c:212
Snapshot GetLatestSnapshot(void)
Definition: snapmgr.c:283
void TeardownHistoricSnapshot(bool is_error)
Definition: snapmgr.c:1613
Snapshot GetCatalogSnapshot(Oid relid)
Definition: snapmgr.c:314
void UnregisterSnapshot(Snapshot snapshot)
Definition: snapmgr.c:794
void PushActiveSnapshot(Snapshot snapshot)
Definition: snapmgr.c:610
Snapshot RestoreSnapshot(char *start_address)
Definition: snapmgr.c:1721
void AtSubCommit_Snapshot(int level)
Definition: snapmgr.c:889
PGDLLIMPORT SnapshotData SnapshotToastData
Definition: snapmgr.c:86
void UpdateActiveSnapshotCommandId(void)
Definition: snapmgr.c:672
PGDLLIMPORT TransactionId TransactionXmin
Definition: snapmgr.c:99
bool HistoricSnapshotActive(void)
Definition: snapmgr.c:1620
void ImportSnapshot(const char *idstr)
Definition: snapmgr.c:1315
bool ActiveSnapshotSet(void)
Definition: snapmgr.c:740
PGDLLIMPORT SnapshotData SnapshotAnyData
Definition: snapmgr.c:85
Snapshot RegisterSnapshot(Snapshot snapshot)
Definition: snapmgr.c:752
bool XactHasExportedSnapshots(void)
Definition: snapmgr.c:1502
void DeleteAllExportedSnapshotFiles(void)
Definition: snapmgr.c:1515
bool GlobalVisCheckRemovableXid(Relation rel, TransactionId xid)
Definition: procarray.c:4300
bool HaveRegisteredOrActiveSnapshot(void)
Definition: snapmgr.c:1572
void InvalidateCatalogSnapshotConditionally(void)
Definition: snapmgr.c:405
bool ThereAreNoPriorRegisteredSnapshots(void)
Definition: snapmgr.c:1554
void RestoreTransactionSnapshot(Snapshot snapshot, void *source_pgproc)
Definition: snapmgr.c:1784
GlobalVisState * GlobalVisTestFor(Relation rel)
Definition: procarray.c:4107
void SnapshotSetCommandId(CommandId curcid)
Definition: snapmgr.c:418
void PopActiveSnapshot(void)
Definition: snapmgr.c:703
void PushCopiedSnapshot(Snapshot snapshot)
Definition: snapmgr.c:660
char * ExportSnapshot(Snapshot snapshot)
Definition: snapmgr.c:1043
PGDLLIMPORT SnapshotData SnapshotSelfData
Definition: snapmgr.c:84
Size EstimateSnapshotSpace(Snapshot snapshot)
Definition: snapmgr.c:1640
void WaitForOlderSnapshots(TransactionId limitXmin, bool progress)
Definition: indexcmds.c:436
void SetupHistoricSnapshot(Snapshot historic_snapshot, struct HTAB *tuplecids)
Definition: snapmgr.c:1597
PGDLLIMPORT bool FirstSnapshotSet
Definition: snapmgr.c:133
Snapshot RegisterSnapshotOnOwner(Snapshot snapshot, ResourceOwner owner)
Definition: snapmgr.c:765
void InvalidateCatalogSnapshot(void)
Definition: snapmgr.c:384
void PushActiveSnapshotWithLevel(Snapshot snapshot, int snap_level)
Definition: snapmgr.c:624
Snapshot GetNonHistoricCatalogSnapshot(Oid relid)
Definition: snapmgr.c:336
PGDLLIMPORT TransactionId RecentXmin
Definition: snapmgr.c:100
Snapshot GetActiveSnapshot(void)
Definition: snapmgr.c:728
Definition: dynahash.c:220
Definition: regguts.h:323