PostgreSQL Source Code  git master
snapmgr.h
Go to the documentation of this file.
1 /*-------------------------------------------------------------------------
2  *
3  * snapmgr.h
4  * POSTGRES snapshot manager
5  *
6  * Portions Copyright (c) 1996-2017, 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 "fmgr.h"
17 #include "utils/relcache.h"
18 #include "utils/resowner.h"
19 #include "utils/snapshot.h"
20 
21 
22 /*
23  * The structure used to map times to TransactionId values for the "snapshot
24  * too old" feature must have a few entries at the tail to hold old values;
25  * otherwise the lookup will often fail and the expected early pruning or
26  * vacuum will not usually occur. It is best if this padding is for a number
27  * of minutes greater than a thread would normally be stalled, but it's OK if
28  * early vacuum opportunities are occasionally missed, so there's no need to
29  * use an extreme value or get too fancy. 10 minutes seems plenty.
30  */
31 #define OLD_SNAPSHOT_PADDING_ENTRIES 10
32 #define OLD_SNAPSHOT_TIME_MAP_ENTRIES (old_snapshot_threshold + OLD_SNAPSHOT_PADDING_ENTRIES)
33 
34 /*
35  * Common definition of relation properties that allow early pruning/vacuuming
36  * when old_snapshot_threshold >= 0.
37  */
38 #define RelationAllowsEarlyPruning(rel) \
39 ( \
40  RelationNeedsWAL(rel) \
41  && !IsCatalogRelation(rel) \
42  && !RelationIsAccessibleInLogicalDecoding(rel) \
43  && !RelationHasUnloggedIndex(rel) \
44 )
45 
46 #define EarlyPruningEnabled(rel) (old_snapshot_threshold >= 0 && RelationAllowsEarlyPruning(rel))
47 
48 /* GUC variables */
50 
51 
52 extern Size SnapMgrShmemSize(void);
53 extern void SnapMgrInit(void);
56 
57 extern bool FirstSnapshotSet;
58 
63 
64 extern Snapshot GetTransactionSnapshot(void);
65 extern Snapshot GetLatestSnapshot(void);
66 extern void SnapshotSetCommandId(CommandId curcid);
67 extern Snapshot GetOldestSnapshot(void);
68 
69 extern Snapshot GetCatalogSnapshot(Oid relid);
71 extern void InvalidateCatalogSnapshot(void);
73 
74 extern void PushActiveSnapshot(Snapshot snapshot);
75 extern void PushCopiedSnapshot(Snapshot snapshot);
76 extern void UpdateActiveSnapshotCommandId(void);
77 extern void PopActiveSnapshot(void);
78 extern Snapshot GetActiveSnapshot(void);
79 extern bool ActiveSnapshotSet(void);
80 
81 extern Snapshot RegisterSnapshot(Snapshot snapshot);
82 extern void UnregisterSnapshot(Snapshot snapshot);
84 extern void UnregisterSnapshotFromOwner(Snapshot snapshot, ResourceOwner owner);
85 
86 extern void AtSubCommit_Snapshot(int level);
87 extern void AtSubAbort_Snapshot(int level);
88 extern void AtEOXact_Snapshot(bool isCommit, bool resetXmin);
89 
90 extern void ImportSnapshot(const char *idstr);
91 extern bool XactHasExportedSnapshots(void);
92 extern void DeleteAllExportedSnapshotFiles(void);
93 extern bool ThereAreNoPriorRegisteredSnapshots(void);
95  Relation relation);
96 extern void MaintainOldSnapshotTimeMapping(TimestampTz whenTaken,
97  TransactionId xmin);
98 
99 extern char *ExportSnapshot(Snapshot snapshot);
100 
101 /* Support for catalog timetravel for logical decoding */
102 struct HTAB;
103 extern struct HTAB *HistoricSnapshotGetTupleCids(void);
104 extern void SetupHistoricSnapshot(Snapshot snapshot_now, struct HTAB *tuplecids);
105 extern void TeardownHistoricSnapshot(bool is_error);
106 extern bool HistoricSnapshotActive(void);
107 
108 extern Size EstimateSnapshotSpace(Snapshot snapshot);
109 extern void SerializeSnapshot(Snapshot snapshot, char *start_address);
110 extern Snapshot RestoreSnapshot(char *start_address);
111 extern void RestoreTransactionSnapshot(Snapshot snapshot, void *master_pgproc);
112 
113 #endif /* SNAPMGR_H */
uint32 CommandId
Definition: c.h:469
void AtSubCommit_Snapshot(int level)
Definition: snapmgr.c:1002
Snapshot GetLatestSnapshot(void)
Definition: snapmgr.c:379
TransactionId TransactionIdLimitedForOldSnapshots(TransactionId recentXmin, Relation relation)
Definition: snapmgr.c:1741
void AtSubAbort_Snapshot(int level)
Definition: snapmgr.c:1023
Snapshot RestoreSnapshot(char *start_address)
Definition: snapmgr.c:2127
uint32 TransactionId
Definition: c.h:455
struct HTAB * HistoricSnapshotGetTupleCids(void)
Definition: snapmgr.c:2030
int64 TimestampTz
Definition: timestamp.h:39
void TeardownHistoricSnapshot(bool is_error)
Definition: snapmgr.c:2017
bool XactHasExportedSnapshots(void)
Definition: snapmgr.c:1603
Snapshot GetActiveSnapshot(void)
Definition: snapmgr.c:839
Size EstimateSnapshotSpace(Snapshot snapshot)
Definition: snapmgr.c:2044
void PopActiveSnapshot(void)
Definition: snapmgr.c:812
unsigned int Oid
Definition: postgres_ext.h:31
Snapshot RegisterSnapshot(Snapshot snapshot)
Definition: snapmgr.c:863
#define PGDLLIMPORT
Definition: c.h:1060
char * ExportSnapshot(Snapshot snapshot)
Definition: snapmgr.c:1159
PGDLLIMPORT TransactionId RecentXmin
Definition: snapmgr.c:165
void RestoreTransactionSnapshot(Snapshot snapshot, void *master_pgproc)
Definition: snapmgr.c:2191
void SerializeSnapshot(Snapshot snapshot, char *start_address)
Definition: snapmgr.c:2068
Definition: dynahash.c:208
Snapshot GetOldestSnapshot(void)
Definition: snapmgr.c:411
void DeleteAllExportedSnapshotFiles(void)
Definition: snapmgr.c:1616
PGDLLIMPORT int old_snapshot_threshold
Definition: snapmgr.c:75
Size SnapMgrShmemSize(void)
Definition: snapmgr.c:251
void SetupHistoricSnapshot(Snapshot snapshot_now, struct HTAB *tuplecids)
Definition: snapmgr.c:2001
void PushActiveSnapshot(Snapshot snapshot)
Definition: snapmgr.c:733
void ImportSnapshot(const char *idstr)
Definition: snapmgr.c:1430
void MaintainOldSnapshotTimeMapping(TimestampTz whenTaken, TransactionId xmin)
Definition: snapmgr.c:1848
TimestampTz GetSnapshotCurrentTimestamp(void)
Definition: snapmgr.c:1686
void SnapshotSetCommandId(CommandId curcid)
Definition: snapmgr.c:544
bool ThereAreNoPriorRegisteredSnapshots(void)
Definition: snapmgr.c:1655
TimestampTz GetOldSnapshotThresholdTimestamp(void)
Definition: snapmgr.c:1711
bool HistoricSnapshotActive(void)
Definition: snapmgr.c:2024
bool FirstSnapshotSet
Definition: snapmgr.c:203
void AtEOXact_Snapshot(bool isCommit, bool resetXmin)
Definition: snapmgr.c:1059
bool ActiveSnapshotSet(void)
Definition: snapmgr.c:851
Snapshot GetTransactionSnapshot(void)
Definition: snapmgr.c:304
Snapshot GetCatalogSnapshot(Oid relid)
Definition: snapmgr.c:440
size_t Size
Definition: c.h:414
PGDLLIMPORT TransactionId RecentGlobalDataXmin
Definition: snapmgr.c:167
void InvalidateCatalogSnapshot(void)
Definition: snapmgr.c:510
PGDLLIMPORT TransactionId RecentGlobalXmin
Definition: snapmgr.c:166
Snapshot GetNonHistoricCatalogSnapshot(Oid relid)
Definition: snapmgr.c:462
Snapshot RegisterSnapshotOnOwner(Snapshot snapshot, ResourceOwner owner)
Definition: snapmgr.c:876
void UpdateActiveSnapshotCommandId(void)
Definition: snapmgr.c:781
void InvalidateCatalogSnapshotConditionally(void)
Definition: snapmgr.c:531
void UnregisterSnapshot(Snapshot snapshot)
Definition: snapmgr.c:905
void SnapMgrInit(void)
Definition: snapmgr.c:267
void UnregisterSnapshotFromOwner(Snapshot snapshot, ResourceOwner owner)
Definition: snapmgr.c:918
PGDLLIMPORT TransactionId TransactionXmin
Definition: snapmgr.c:164
void PushCopiedSnapshot(Snapshot snapshot)
Definition: snapmgr.c:769