snapmgr.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /*-------------------------------------------------------------------------
  2. *
  3. * snapmgr.h
  4. * POSTGRES snapshot manager
  5. *
  6. * Portions Copyright (c) 1996-2016, 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. #include "fmgr.h"
  16. #include "utils/relcache.h"
  17. #include "utils/resowner.h"
  18. #include "utils/snapshot.h"
  19. /*
  20. * The structure used to map times to TransactionId values for the "snapshot
  21. * too old" feature must have a few entries at the tail to hold old values;
  22. * otherwise the lookup will often fail and the expected early pruning or
  23. * vacuum will not usually occur. It is best if this padding is for a number
  24. * of minutes greater than a thread would normally be stalled, but it's OK if
  25. * early vacuum opportunities are occasionally missed, so there's no need to
  26. * use an extreme value or get too fancy. 10 minutes seems plenty.
  27. */
  28. #define OLD_SNAPSHOT_PADDING_ENTRIES 10
  29. #define OLD_SNAPSHOT_TIME_MAP_ENTRIES (old_snapshot_threshold + OLD_SNAPSHOT_PADDING_ENTRIES)
  30. /*
  31. * Common definition of relation properties that allow early pruning/vacuuming
  32. * when old_snapshot_threshold >= 0.
  33. */
  34. #define RelationAllowsEarlyPruning(rel) \
  35. ( \
  36. RelationNeedsWAL(rel) \
  37. && !IsCatalogRelation(rel) \
  38. && !RelationIsAccessibleInLogicalDecoding(rel) \
  39. && !RelationHasUnloggedIndex(rel) \
  40. )
  41. #define EarlyPruningEnabled(rel) (old_snapshot_threshold >= 0 && RelationAllowsEarlyPruning(rel))
  42. /* GUC variables */
  43. extern PGDLLIMPORT int old_snapshot_threshold;
  44. extern Size SnapMgrShmemSize(void);
  45. extern void SnapMgrInit(void);
  46. extern int64 GetSnapshotCurrentTimestamp(void);
  47. extern int64 GetOldSnapshotThresholdTimestamp(void);
  48. extern bool FirstSnapshotSet;
  49. extern TransactionId TransactionXmin;
  50. extern TransactionId RecentXmin;
  51. extern TransactionId RecentGlobalXmin;
  52. extern TransactionId RecentGlobalDataXmin;
  53. extern Snapshot GetTransactionSnapshot(void);
  54. extern Snapshot GetLatestSnapshot(void);
  55. extern void SnapshotSetCommandId(CommandId curcid);
  56. extern Snapshot GetOldestSnapshot(void);
  57. extern Snapshot GetCatalogSnapshot(Oid relid);
  58. extern Snapshot GetNonHistoricCatalogSnapshot(Oid relid);
  59. extern void InvalidateCatalogSnapshot(void);
  60. extern void InvalidateCatalogSnapshotConditionally(void);
  61. extern void PushActiveSnapshot(Snapshot snapshot);
  62. extern void PushCopiedSnapshot(Snapshot snapshot);
  63. extern void UpdateActiveSnapshotCommandId(void);
  64. extern void PopActiveSnapshot(void);
  65. extern Snapshot GetActiveSnapshot(void);
  66. extern bool ActiveSnapshotSet(void);
  67. extern Snapshot RegisterSnapshot(Snapshot snapshot);
  68. extern void UnregisterSnapshot(Snapshot snapshot);
  69. extern Snapshot RegisterSnapshotOnOwner(Snapshot snapshot, ResourceOwner owner);
  70. extern void UnregisterSnapshotFromOwner(Snapshot snapshot, ResourceOwner owner);
  71. extern void AtSubCommit_Snapshot(int level);
  72. extern void AtSubAbort_Snapshot(int level);
  73. extern void AtEOXact_Snapshot(bool isCommit);
  74. extern Datum pg_export_snapshot(PG_FUNCTION_ARGS);
  75. extern void ImportSnapshot(const char *idstr);
  76. extern bool XactHasExportedSnapshots(void);
  77. extern void DeleteAllExportedSnapshotFiles(void);
  78. extern bool ThereAreNoPriorRegisteredSnapshots(void);
  79. extern TransactionId TransactionIdLimitedForOldSnapshots(TransactionId recentXmin,
  80. Relation relation);
  81. extern void MaintainOldSnapshotTimeMapping(int64 whenTaken, TransactionId xmin);
  82. extern char *ExportSnapshot(Snapshot snapshot);
  83. /* Support for catalog timetravel for logical decoding */
  84. struct HTAB;
  85. extern struct HTAB *HistoricSnapshotGetTupleCids(void);
  86. extern void SetupHistoricSnapshot(Snapshot snapshot_now, struct HTAB *tuplecids);
  87. extern void TeardownHistoricSnapshot(bool is_error);
  88. extern bool HistoricSnapshotActive(void);
  89. extern Size EstimateSnapshotSpace(Snapshot snapshot);
  90. extern void SerializeSnapshot(Snapshot snapshot, char *start_address);
  91. extern Snapshot RestoreSnapshot(char *start_address);
  92. extern void RestoreTransactionSnapshot(Snapshot snapshot, void *master_pgproc);
  93. #endif /* SNAPMGR_H */