Header And Logo

PostgreSQL
| The world's most advanced open source database.

standby.h

Go to the documentation of this file.
00001 /*-------------------------------------------------------------------------
00002  *
00003  * standby.h
00004  *    Definitions for hot standby mode.
00005  *
00006  *
00007  * Portions Copyright (c) 1996-2013, PostgreSQL Global Development Group
00008  * Portions Copyright (c) 1994, Regents of the University of California
00009  *
00010  * src/include/storage/standby.h
00011  *
00012  *-------------------------------------------------------------------------
00013  */
00014 #ifndef STANDBY_H
00015 #define STANDBY_H
00016 
00017 #include "access/xlog.h"
00018 #include "storage/lock.h"
00019 #include "storage/procsignal.h"
00020 #include "storage/relfilenode.h"
00021 
00022 /* User-settable GUC parameters */
00023 extern int  vacuum_defer_cleanup_age;
00024 extern int  max_standby_archive_delay;
00025 extern int  max_standby_streaming_delay;
00026 
00027 extern void InitRecoveryTransactionEnvironment(void);
00028 extern void ShutdownRecoveryTransactionEnvironment(void);
00029 
00030 extern void ResolveRecoveryConflictWithSnapshot(TransactionId latestRemovedXid,
00031                                     RelFileNode node);
00032 extern void ResolveRecoveryConflictWithTablespace(Oid tsid);
00033 extern void ResolveRecoveryConflictWithDatabase(Oid dbid);
00034 
00035 extern void ResolveRecoveryConflictWithBufferPin(void);
00036 extern void CheckRecoveryConflictDeadlock(void);
00037 extern void StandbyDeadLockHandler(void);
00038 extern void StandbyTimeoutHandler(void);
00039 
00040 /*
00041  * Standby Rmgr (RM_STANDBY_ID)
00042  *
00043  * Standby recovery manager exists to perform actions that are required
00044  * to make hot standby work. That includes logging AccessExclusiveLocks taken
00045  * by transactions and running-xacts snapshots.
00046  */
00047 extern void StandbyAcquireAccessExclusiveLock(TransactionId xid, Oid dbOid, Oid relOid);
00048 extern void StandbyReleaseLockTree(TransactionId xid,
00049                        int nsubxids, TransactionId *subxids);
00050 extern void StandbyReleaseAllLocks(void);
00051 extern void StandbyReleaseOldLocks(int nxids, TransactionId *xids);
00052 
00053 /*
00054  * XLOG message types
00055  */
00056 #define XLOG_STANDBY_LOCK           0x00
00057 #define XLOG_RUNNING_XACTS          0x10
00058 
00059 typedef struct xl_standby_locks
00060 {
00061     int         nlocks;         /* number of entries in locks array */
00062     xl_standby_lock locks[1];   /* VARIABLE LENGTH ARRAY */
00063 } xl_standby_locks;
00064 
00065 /*
00066  * When we write running xact data to WAL, we use this structure.
00067  */
00068 typedef struct xl_running_xacts
00069 {
00070     int         xcnt;           /* # of xact ids in xids[] */
00071     int         subxcnt;            /* # of subxact ids in xids[] */
00072     bool        subxid_overflow;    /* snapshot overflowed, subxids missing */
00073     TransactionId nextXid;      /* copy of ShmemVariableCache->nextXid */
00074     TransactionId oldestRunningXid;     /* *not* oldestXmin */
00075     TransactionId latestCompletedXid;   /* so we can set xmax */
00076 
00077     TransactionId xids[1];      /* VARIABLE LENGTH ARRAY */
00078 } xl_running_xacts;
00079 
00080 #define MinSizeOfXactRunningXacts offsetof(xl_running_xacts, xids)
00081 
00082 
00083 /* Recovery handlers for the Standby Rmgr (RM_STANDBY_ID) */
00084 extern void standby_redo(XLogRecPtr lsn, XLogRecord *record);
00085 extern void standby_desc(StringInfo buf, uint8 xl_info, char *rec);
00086 
00087 /*
00088  * Declarations for GetRunningTransactionData(). Similar to Snapshots, but
00089  * not quite. This has nothing at all to do with visibility on this server,
00090  * so this is completely separate from snapmgr.c and snapmgr.h.
00091  * This data is important for creating the initial snapshot state on a
00092  * standby server. We need lots more information than a normal snapshot,
00093  * hence we use a specific data structure for our needs. This data
00094  * is written to WAL as a separate record immediately after each
00095  * checkpoint. That means that wherever we start a standby from we will
00096  * almost immediately see the data we need to begin executing queries.
00097  */
00098 
00099 typedef struct RunningTransactionsData
00100 {
00101     int         xcnt;           /* # of xact ids in xids[] */
00102     int         subxcnt;            /* # of subxact ids in xids[] */
00103     bool        subxid_overflow;    /* snapshot overflowed, subxids missing */
00104     TransactionId nextXid;      /* copy of ShmemVariableCache->nextXid */
00105     TransactionId oldestRunningXid;     /* *not* oldestXmin */
00106     TransactionId latestCompletedXid;   /* so we can set xmax */
00107 
00108     TransactionId *xids;        /* array of (sub)xids still running */
00109 } RunningTransactionsData;
00110 
00111 typedef RunningTransactionsData *RunningTransactions;
00112 
00113 extern void LogAccessExclusiveLock(Oid dbOid, Oid relOid);
00114 extern void LogAccessExclusiveLockPrepare(void);
00115 
00116 extern void LogStandbySnapshot(void);
00117 
00118 #endif   /* STANDBY_H */