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