standby.h 3.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /*-------------------------------------------------------------------------
  2. *
  3. * standby.h
  4. * Definitions for hot standby mode.
  5. *
  6. *
  7. * Portions Copyright (c) 1996-2022, PostgreSQL Global Development Group
  8. * Portions Copyright (c) 1994, Regents of the University of California
  9. *
  10. * src/include/storage/standby.h
  11. *
  12. *-------------------------------------------------------------------------
  13. */
  14. #ifndef STANDBY_H
  15. #define STANDBY_H
  16. #include "datatype/timestamp.h"
  17. #include "storage/lock.h"
  18. #include "storage/procsignal.h"
  19. #include "storage/relfilenode.h"
  20. #include "storage/standbydefs.h"
  21. /* User-settable GUC parameters */
  22. extern PGDLLIMPORT int vacuum_defer_cleanup_age;
  23. extern PGDLLIMPORT int max_standby_archive_delay;
  24. extern PGDLLIMPORT int max_standby_streaming_delay;
  25. extern PGDLLIMPORT bool log_recovery_conflict_waits;
  26. extern void InitRecoveryTransactionEnvironment(void);
  27. extern void ShutdownRecoveryTransactionEnvironment(void);
  28. extern void ResolveRecoveryConflictWithSnapshot(TransactionId latestRemovedXid,
  29. RelFileNode node);
  30. extern void ResolveRecoveryConflictWithSnapshotFullXid(FullTransactionId latestRemovedFullXid,
  31. RelFileNode node);
  32. extern void ResolveRecoveryConflictWithTablespace(Oid tsid);
  33. extern void ResolveRecoveryConflictWithDatabase(Oid dbid);
  34. extern void ResolveRecoveryConflictWithLock(LOCKTAG locktag, bool logging_conflict);
  35. extern void ResolveRecoveryConflictWithBufferPin(void);
  36. extern void CheckRecoveryConflictDeadlock(void);
  37. extern void StandbyDeadLockHandler(void);
  38. extern void StandbyTimeoutHandler(void);
  39. extern void StandbyLockTimeoutHandler(void);
  40. extern void LogRecoveryConflict(ProcSignalReason reason, TimestampTz wait_start,
  41. TimestampTz cur_ts, VirtualTransactionId *wait_list,
  42. bool still_waiting);
  43. /*
  44. * Standby Rmgr (RM_STANDBY_ID)
  45. *
  46. * Standby recovery manager exists to perform actions that are required
  47. * to make hot standby work. That includes logging AccessExclusiveLocks taken
  48. * by transactions and running-xacts snapshots.
  49. */
  50. extern void StandbyAcquireAccessExclusiveLock(TransactionId xid, Oid dbOid, Oid relOid);
  51. extern void StandbyReleaseLockTree(TransactionId xid,
  52. int nsubxids, TransactionId *subxids);
  53. extern void StandbyReleaseAllLocks(void);
  54. extern void StandbyReleaseOldLocks(TransactionId oldxid);
  55. #define MinSizeOfXactRunningXacts offsetof(xl_running_xacts, xids)
  56. /*
  57. * Declarations for GetRunningTransactionData(). Similar to Snapshots, but
  58. * not quite. This has nothing at all to do with visibility on this server,
  59. * so this is completely separate from snapmgr.c and snapmgr.h.
  60. * This data is important for creating the initial snapshot state on a
  61. * standby server. We need lots more information than a normal snapshot,
  62. * hence we use a specific data structure for our needs. This data
  63. * is written to WAL as a separate record immediately after each
  64. * checkpoint. That means that wherever we start a standby from we will
  65. * almost immediately see the data we need to begin executing queries.
  66. */
  67. typedef struct RunningTransactionsData
  68. {
  69. int xcnt; /* # of xact ids in xids[] */
  70. int subxcnt; /* # of subxact ids in xids[] */
  71. bool subxid_overflow; /* snapshot overflowed, subxids missing */
  72. TransactionId nextXid; /* xid from ShmemVariableCache->nextXid */
  73. TransactionId oldestRunningXid; /* *not* oldestXmin */
  74. TransactionId latestCompletedXid; /* so we can set xmax */
  75. TransactionId *xids; /* array of (sub)xids still running */
  76. } RunningTransactionsData;
  77. typedef RunningTransactionsData *RunningTransactions;
  78. extern void LogAccessExclusiveLock(Oid dbOid, Oid relOid);
  79. extern void LogAccessExclusiveLockPrepare(void);
  80. extern XLogRecPtr LogStandbySnapshot(void);
  81. extern void LogStandbyInvalidations(int nmsgs, SharedInvalidationMessage *msgs,
  82. bool relcacheInitFileInval);
  83. #endif /* STANDBY_H */