PostgreSQL Source Code  git master
standby.c File Reference
#include "postgres.h"
#include "access/transam.h"
#include "access/twophase.h"
#include "access/xact.h"
#include "access/xloginsert.h"
#include "access/xlogutils.h"
#include "miscadmin.h"
#include "pgstat.h"
#include "storage/bufmgr.h"
#include "storage/lmgr.h"
#include "storage/proc.h"
#include "storage/procarray.h"
#include "storage/sinvaladt.h"
#include "storage/standby.h"
#include "utils/hsearch.h"
#include "utils/memutils.h"
#include "utils/ps_status.h"
#include "utils/timeout.h"
#include "utils/timestamp.h"
Include dependency graph for standby.c:

Go to the source code of this file.

Data Structures

struct  RecoveryLockListsEntry
 

Macros

#define STANDBY_INITIAL_WAIT_US   1000
 

Typedefs

typedef struct RecoveryLockListsEntry RecoveryLockListsEntry
 

Functions

static void ResolveRecoveryConflictWithVirtualXIDs (VirtualTransactionId *waitlist, ProcSignalReason reason, uint32 wait_event_info, bool report_waiting)
 
static void SendRecoveryConflictWithBufferPin (ProcSignalReason reason)
 
static XLogRecPtr LogCurrentRunningXacts (RunningTransactions CurrRunningXacts)
 
static void LogAccessExclusiveLocks (int nlocks, xl_standby_lock *locks)
 
static const char * get_recovery_conflict_desc (ProcSignalReason reason)
 
void InitRecoveryTransactionEnvironment (void)
 
void ShutdownRecoveryTransactionEnvironment (void)
 
static TimestampTz GetStandbyLimitTime (void)
 
static bool WaitExceedsMaxStandbyDelay (uint32 wait_event_info)
 
void LogRecoveryConflict (ProcSignalReason reason, TimestampTz wait_start, TimestampTz now, VirtualTransactionId *wait_list, bool still_waiting)
 
void ResolveRecoveryConflictWithSnapshot (TransactionId latestRemovedXid, RelFileNode node)
 
void ResolveRecoveryConflictWithSnapshotFullXid (FullTransactionId latestRemovedFullXid, RelFileNode node)
 
void ResolveRecoveryConflictWithTablespace (Oid tsid)
 
void ResolveRecoveryConflictWithDatabase (Oid dbid)
 
void ResolveRecoveryConflictWithLock (LOCKTAG locktag, bool logging_conflict)
 
void ResolveRecoveryConflictWithBufferPin (void)
 
void CheckRecoveryConflictDeadlock (void)
 
void StandbyDeadLockHandler (void)
 
void StandbyTimeoutHandler (void)
 
void StandbyLockTimeoutHandler (void)
 
void StandbyAcquireAccessExclusiveLock (TransactionId xid, Oid dbOid, Oid relOid)
 
static void StandbyReleaseLockList (List *locks)
 
static void StandbyReleaseLocks (TransactionId xid)
 
void StandbyReleaseLockTree (TransactionId xid, int nsubxids, TransactionId *subxids)
 
void StandbyReleaseAllLocks (void)
 
void StandbyReleaseOldLocks (TransactionId oldxid)
 
void standby_redo (XLogReaderState *record)
 
XLogRecPtr LogStandbySnapshot (void)
 
void LogAccessExclusiveLock (Oid dbOid, Oid relOid)
 
void LogAccessExclusiveLockPrepare (void)
 
void LogStandbyInvalidations (int nmsgs, SharedInvalidationMessage *msgs, bool relcacheInitFileInval)
 

Variables

int vacuum_defer_cleanup_age
 
int max_standby_archive_delay = 30 * 1000
 
int max_standby_streaming_delay = 30 * 1000
 
bool log_recovery_conflict_waits = false
 
static HTABRecoveryLockLists
 
static volatile sig_atomic_t got_standby_deadlock_timeout = false
 
static volatile sig_atomic_t got_standby_lock_timeout = false
 
static int standbyWait_us = STANDBY_INITIAL_WAIT_US
 

Macro Definition Documentation

◆ STANDBY_INITIAL_WAIT_US

#define STANDBY_INITIAL_WAIT_US   1000

Definition at line 200 of file standby.c.

Referenced by ResolveRecoveryConflictWithVirtualXIDs().

Typedef Documentation

◆ RecoveryLockListsEntry

Function Documentation

◆ CheckRecoveryConflictDeadlock()

void CheckRecoveryConflictDeadlock ( void  )

Definition at line 862 of file standby.c.

References Assert, ereport, errcode(), errdetail(), errmsg(), ERROR, HoldingBufferPinThatDelaysRecovery(), and InRecovery.

Referenced by ProcSleep().

863 {
864  Assert(!InRecovery); /* do not call in Startup process */
865 
867  return;
868 
869  /*
870  * Error message should match ProcessInterrupts() but we avoid calling
871  * that because we aren't handling an interrupt at this point. Note that
872  * we only cancel the current transaction here, so if we are in a
873  * subtransaction and the pin is held by a parent, then the Startup
874  * process will continue to wait even though we have avoided deadlock.
875  */
876  ereport(ERROR,
877  (errcode(ERRCODE_T_R_DEADLOCK_DETECTED),
878  errmsg("canceling statement due to conflict with recovery"),
879  errdetail("User transaction caused buffer deadlock with recovery.")));
880 }
int errcode(int sqlerrcode)
Definition: elog.c:698
#define ERROR
Definition: elog.h:46
int errdetail(const char *fmt,...)
Definition: elog.c:1042
#define ereport(elevel,...)
Definition: elog.h:157
bool InRecovery
Definition: xlogutils.c:52
#define Assert(condition)
Definition: c.h:804
bool HoldingBufferPinThatDelaysRecovery(void)
Definition: bufmgr.c:4215
int errmsg(const char *fmt,...)
Definition: elog.c:909

◆ get_recovery_conflict_desc()

static const char * get_recovery_conflict_desc ( ProcSignalReason  reason)
static

Definition at line 1419 of file standby.c.

References _, PROCSIG_RECOVERY_CONFLICT_BUFFERPIN, PROCSIG_RECOVERY_CONFLICT_DATABASE, PROCSIG_RECOVERY_CONFLICT_LOCK, PROCSIG_RECOVERY_CONFLICT_SNAPSHOT, PROCSIG_RECOVERY_CONFLICT_STARTUP_DEADLOCK, and PROCSIG_RECOVERY_CONFLICT_TABLESPACE.

Referenced by LogRecoveryConflict().

1420 {
1421  const char *reasonDesc = _("unknown reason");
1422 
1423  switch (reason)
1424  {
1426  reasonDesc = _("recovery conflict on buffer pin");
1427  break;
1429  reasonDesc = _("recovery conflict on lock");
1430  break;
1432  reasonDesc = _("recovery conflict on tablespace");
1433  break;
1435  reasonDesc = _("recovery conflict on snapshot");
1436  break;
1438  reasonDesc = _("recovery conflict on buffer deadlock");
1439  break;
1441  reasonDesc = _("recovery conflict on database");
1442  break;
1443  default:
1444  break;
1445  }
1446 
1447  return reasonDesc;
1448 }
#define _(x)
Definition: elog.c:89

◆ GetStandbyLimitTime()

static TimestampTz GetStandbyLimitTime ( void  )
static

Definition at line 176 of file standby.c.

References GetXLogReceiptTime(), max_standby_archive_delay, max_standby_streaming_delay, and TimestampTzPlusMilliseconds.

Referenced by ResolveRecoveryConflictWithBufferPin(), ResolveRecoveryConflictWithLock(), and WaitExceedsMaxStandbyDelay().

177 {
178  TimestampTz rtime;
179  bool fromStream;
180 
181  /*
182  * The cutoff time is the last WAL data receipt time plus the appropriate
183  * delay variable. Delay of -1 means wait forever.
184  */
185  GetXLogReceiptTime(&rtime, &fromStream);
186  if (fromStream)
187  {
189  return 0; /* wait forever */
191  }
192  else
193  {
195  return 0; /* wait forever */
197  }
198 }
int max_standby_archive_delay
Definition: standby.c:40
int64 TimestampTz
Definition: timestamp.h:39
#define TimestampTzPlusMilliseconds(tz, ms)
Definition: timestamp.h:56
void GetXLogReceiptTime(TimestampTz *rtime, bool *fromStream)
Definition: xlog.c:6472
int max_standby_streaming_delay
Definition: standby.c:41

◆ InitRecoveryTransactionEnvironment()

void InitRecoveryTransactionEnvironment ( void  )

Definition at line 81 of file standby.c.

References VirtualTransactionId::backendId, HASHCTL::entrysize, GetNextLocalTransactionId(), HASH_BLOBS, hash_create(), HASH_ELEM, HASHCTL::keysize, VirtualTransactionId::localTransactionId, MyBackendId, SharedInvalBackendInit(), STANDBY_INITIALIZED, standbyState, and VirtualXactLockTableInsert().

Referenced by StartupXLOG().

82 {
84  HASHCTL hash_ctl;
85 
86  /*
87  * Initialize the hash table for tracking the list of locks held by each
88  * transaction.
89  */
90  hash_ctl.keysize = sizeof(TransactionId);
91  hash_ctl.entrysize = sizeof(RecoveryLockListsEntry);
92  RecoveryLockLists = hash_create("RecoveryLockLists",
93  64,
94  &hash_ctl,
96 
97  /*
98  * Initialize shared invalidation management for Startup process, being
99  * careful to register ourselves as a sendOnly process so we don't need to
100  * read messages, nor will we get signaled when the queue starts filling
101  * up.
102  */
104 
105  /*
106  * Lock a virtual transaction id for Startup process.
107  *
108  * We need to do GetNextLocalTransactionId() because
109  * SharedInvalBackendInit() leaves localTransactionId invalid and the lock
110  * manager doesn't like that at all.
111  *
112  * Note that we don't need to run XactLockTableInsert() because nobody
113  * needs to wait on xids. That sounds a little strange, but table locks
114  * are held by vxids and row level locks are held by xids. All queries
115  * hold AccessShareLocks so never block while we write or lock new rows.
116  */
117  vxid.backendId = MyBackendId;
120 
122 }
BackendId MyBackendId
Definition: globals.c:84
static HTAB * RecoveryLockLists
Definition: standby.c:44
#define HASH_ELEM
Definition: hsearch.h:95
uint32 TransactionId
Definition: c.h:587
void SharedInvalBackendInit(bool sendOnly)
Definition: sinvaladt.c:257
Size entrysize
Definition: hsearch.h:76
LocalTransactionId localTransactionId
Definition: lock.h:67
LocalTransactionId GetNextLocalTransactionId(void)
Definition: sinvaladt.c:766
void VirtualXactLockTableInsert(VirtualTransactionId vxid)
Definition: lock.c:4476
HotStandbyState standbyState
Definition: xlogutils.c:55
HTAB * hash_create(const char *tabname, long nelem, const HASHCTL *info, int flags)
Definition: dynahash.c:349
#define HASH_BLOBS
Definition: hsearch.h:97
Size keysize
Definition: hsearch.h:75
BackendId backendId
Definition: lock.h:66
struct RecoveryLockListsEntry RecoveryLockListsEntry

◆ LogAccessExclusiveLock()

void LogAccessExclusiveLock ( Oid  dbOid,
Oid  relOid 
)

Definition at line 1358 of file standby.c.

References xl_standby_lock::dbOid, GetCurrentTransactionId(), LogAccessExclusiveLocks(), MyXactFlags, xl_standby_lock::relOid, XACT_FLAGS_ACQUIREDACCESSEXCLUSIVELOCK, and xl_standby_lock::xid.

Referenced by LockAcquireExtended().

1359 {
1360  xl_standby_lock xlrec;
1361 
1362  xlrec.xid = GetCurrentTransactionId();
1363 
1364  xlrec.dbOid = dbOid;
1365  xlrec.relOid = relOid;
1366 
1367  LogAccessExclusiveLocks(1, &xlrec);
1369 }
static void LogAccessExclusiveLocks(int nlocks, xl_standby_lock *locks)
Definition: standby.c:1340
#define XACT_FLAGS_ACQUIREDACCESSEXCLUSIVELOCK
Definition: xact.h:108
TransactionId GetCurrentTransactionId(void)
Definition: xact.c:439
int MyXactFlags
Definition: xact.c:133
TransactionId xid
Definition: lockdefs.h:54

◆ LogAccessExclusiveLockPrepare()

void LogAccessExclusiveLockPrepare ( void  )

Definition at line 1375 of file standby.c.

References GetCurrentTransactionId().

Referenced by LockAcquireExtended().

1376 {
1377  /*
1378  * Ensure that a TransactionId has been assigned to this transaction, for
1379  * two reasons, both related to lock release on the standby. First, we
1380  * must assign an xid so that RecordTransactionCommit() and
1381  * RecordTransactionAbort() do not optimise away the transaction
1382  * completion record which recovery relies upon to release locks. It's a
1383  * hack, but for a corner case not worth adding code for into the main
1384  * commit path. Second, we must assign an xid before the lock is recorded
1385  * in shared memory, otherwise a concurrently executing
1386  * GetRunningTransactionLocks() might see a lock associated with an
1387  * InvalidTransactionId which we later assert cannot happen.
1388  */
1389  (void) GetCurrentTransactionId();
1390 }
TransactionId GetCurrentTransactionId(void)
Definition: xact.c:439

◆ LogAccessExclusiveLocks()

static void LogAccessExclusiveLocks ( int  nlocks,
xl_standby_lock locks 
)
static

Definition at line 1340 of file standby.c.

References xl_standby_locks::nlocks, offsetof, XLOG_MARK_UNIMPORTANT, XLOG_STANDBY_LOCK, XLogBeginInsert(), XLogInsert(), XLogRegisterData(), and XLogSetRecordFlags().

Referenced by LogAccessExclusiveLock(), and LogStandbySnapshot().

1341 {
1342  xl_standby_locks xlrec;
1343 
1344  xlrec.nlocks = nlocks;
1345 
1346  XLogBeginInsert();
1347  XLogRegisterData((char *) &xlrec, offsetof(xl_standby_locks, locks));
1348  XLogRegisterData((char *) locks, nlocks * sizeof(xl_standby_lock));
1350 
1351  (void) XLogInsert(RM_STANDBY_ID, XLOG_STANDBY_LOCK);
1352 }
#define XLOG_STANDBY_LOCK
Definition: standbydefs.h:34
void XLogSetRecordFlags(uint8 flags)
Definition: xloginsert.c:416
void XLogRegisterData(char *data, int len)
Definition: xloginsert.c:340
XLogRecPtr XLogInsert(RmgrId rmid, uint8 info)
Definition: xloginsert.c:434
#define XLOG_MARK_UNIMPORTANT
Definition: xlog.h:214
void XLogBeginInsert(void)
Definition: xloginsert.c:135
#define offsetof(type, field)
Definition: c.h:727

◆ LogCurrentRunningXacts()

static XLogRecPtr LogCurrentRunningXacts ( RunningTransactions  CurrRunningXacts)
static

Definition at line 1280 of file standby.c.

References DEBUG2, elog, xl_running_xacts::latestCompletedXid, RunningTransactionsData::latestCompletedXid, LSN_FORMAT_ARGS, MinSizeOfXactRunningXacts, xl_running_xacts::nextXid, RunningTransactionsData::nextXid, xl_running_xacts::oldestRunningXid, RunningTransactionsData::oldestRunningXid, xl_running_xacts::subxcnt, RunningTransactionsData::subxcnt, xl_running_xacts::subxid_overflow, RunningTransactionsData::subxid_overflow, trace_recovery(), xl_running_xacts::xcnt, RunningTransactionsData::xcnt, RunningTransactionsData::xids, XLOG_MARK_UNIMPORTANT, XLOG_RUNNING_XACTS, XLogBeginInsert(), XLogInsert(), XLogRegisterData(), XLogSetAsyncXactLSN(), and XLogSetRecordFlags().

Referenced by LogStandbySnapshot().

1281 {
1282  xl_running_xacts xlrec;
1283  XLogRecPtr recptr;
1284 
1285  xlrec.xcnt = CurrRunningXacts->xcnt;
1286  xlrec.subxcnt = CurrRunningXacts->subxcnt;
1287  xlrec.subxid_overflow = CurrRunningXacts->subxid_overflow;
1288  xlrec.nextXid = CurrRunningXacts->nextXid;
1289  xlrec.oldestRunningXid = CurrRunningXacts->oldestRunningXid;
1290  xlrec.latestCompletedXid = CurrRunningXacts->latestCompletedXid;
1291 
1292  /* Header */
1293  XLogBeginInsert();
1295  XLogRegisterData((char *) (&xlrec), MinSizeOfXactRunningXacts);
1296 
1297  /* array of TransactionIds */
1298  if (xlrec.xcnt > 0)
1299  XLogRegisterData((char *) CurrRunningXacts->xids,
1300  (xlrec.xcnt + xlrec.subxcnt) * sizeof(TransactionId));
1301 
1302  recptr = XLogInsert(RM_STANDBY_ID, XLOG_RUNNING_XACTS);
1303 
1304  if (CurrRunningXacts->subxid_overflow)
1306  "snapshot of %u running transactions overflowed (lsn %X/%X oldest xid %u latest complete %u next xid %u)",
1307  CurrRunningXacts->xcnt,
1308  LSN_FORMAT_ARGS(recptr),
1309  CurrRunningXacts->oldestRunningXid,
1310  CurrRunningXacts->latestCompletedXid,
1311  CurrRunningXacts->nextXid);
1312  else
1314  "snapshot of %u+%u running transaction ids (lsn %X/%X oldest xid %u latest complete %u next xid %u)",
1315  CurrRunningXacts->xcnt, CurrRunningXacts->subxcnt,
1316  LSN_FORMAT_ARGS(recptr),
1317  CurrRunningXacts->oldestRunningXid,
1318  CurrRunningXacts->latestCompletedXid,
1319  CurrRunningXacts->nextXid);
1320 
1321  /*
1322  * Ensure running_xacts information is synced to disk not too far in the
1323  * future. We don't want to stall anything though (i.e. use XLogFlush()),
1324  * so we let the wal writer do it during normal operation.
1325  * XLogSetAsyncXactLSN() conveniently will mark the LSN as to-be-synced
1326  * and nudge the WALWriter into action if sleeping. Check
1327  * XLogBackgroundFlush() for details why a record might not be flushed
1328  * without it.
1329  */
1330  XLogSetAsyncXactLSN(recptr);
1331 
1332  return recptr;
1333 }
TransactionId oldestRunningXid
Definition: standby.h:83
uint32 TransactionId
Definition: c.h:587
TransactionId * xids
Definition: standby.h:86
int trace_recovery(int trace_level)
Definition: elog.c:3597
TransactionId latestCompletedXid
Definition: standby.h:84
#define LSN_FORMAT_ARGS(lsn)
Definition: xlogdefs.h:43
TransactionId latestCompletedXid
Definition: standbydefs.h:54
#define DEBUG2
Definition: elog.h:24
void XLogSetRecordFlags(uint8 flags)
Definition: xloginsert.c:416
#define MinSizeOfXactRunningXacts
Definition: standby.h:62
void XLogRegisterData(char *data, int len)
Definition: xloginsert.c:340
XLogRecPtr XLogInsert(RmgrId rmid, uint8 info)
Definition: xloginsert.c:434
void XLogSetAsyncXactLSN(XLogRecPtr asyncXactLSN)
Definition: xlog.c:2728
uint64 XLogRecPtr
Definition: xlogdefs.h:21
#define XLOG_MARK_UNIMPORTANT
Definition: xlog.h:214
TransactionId nextXid
Definition: standbydefs.h:52
TransactionId nextXid
Definition: standby.h:82
#define elog(elevel,...)
Definition: elog.h:232
TransactionId oldestRunningXid
Definition: standbydefs.h:53
#define XLOG_RUNNING_XACTS
Definition: standbydefs.h:35
void XLogBeginInsert(void)
Definition: xloginsert.c:135

◆ LogRecoveryConflict()

void LogRecoveryConflict ( ProcSignalReason  reason,
TimestampTz  wait_start,
TimestampTz  now,
VirtualTransactionId wait_list,
bool  still_waiting 
)

Definition at line 249 of file standby.c.

References appendStringInfo(), Assert, VirtualTransactionId::backendId, BackendIdGetProc(), buf, StringInfoData::data, ereport, errdetail_log_plural(), errmsg(), get_recovery_conflict_desc(), initStringInfo(), LOG, pfree(), PGPROC::pid, TimestampDifference(), and VirtualTransactionIdIsValid.

Referenced by LockBufferForCleanup(), ProcSleep(), and ResolveRecoveryConflictWithVirtualXIDs().

252 {
253  long secs;
254  int usecs;
255  long msecs;
257  int nprocs = 0;
258 
259  /*
260  * There must be no conflicting processes when the recovery conflict has
261  * already been resolved.
262  */
263  Assert(still_waiting || wait_list == NULL);
264 
265  TimestampDifference(wait_start, now, &secs, &usecs);
266  msecs = secs * 1000 + usecs / 1000;
267  usecs = usecs % 1000;
268 
269  if (wait_list)
270  {
271  VirtualTransactionId *vxids;
272 
273  /* Construct a string of list of the conflicting processes */
274  vxids = wait_list;
275  while (VirtualTransactionIdIsValid(*vxids))
276  {
277  PGPROC *proc = BackendIdGetProc(vxids->backendId);
278 
279  /* proc can be NULL if the target backend is not active */
280  if (proc)
281  {
282  if (nprocs == 0)
283  {
284  initStringInfo(&buf);
285  appendStringInfo(&buf, "%d", proc->pid);
286  }
287  else
288  appendStringInfo(&buf, ", %d", proc->pid);
289 
290  nprocs++;
291  }
292 
293  vxids++;
294  }
295  }
296 
297  /*
298  * If wait_list is specified, report the list of PIDs of active
299  * conflicting backends in a detail message. Note that if all the backends
300  * in the list are not active, no detail message is logged.
301  */
302  if (still_waiting)
303  {
304  ereport(LOG,
305  errmsg("recovery still waiting after %ld.%03d ms: %s",
306  msecs, usecs, get_recovery_conflict_desc(reason)),
307  nprocs > 0 ? errdetail_log_plural("Conflicting process: %s.",
308  "Conflicting processes: %s.",
309  nprocs, buf.data) : 0);
310  }
311  else
312  {
313  ereport(LOG,
314  errmsg("recovery finished waiting after %ld.%03d ms: %s",
315  msecs, usecs, get_recovery_conflict_desc(reason)));
316  }
317 
318  if (nprocs > 0)
319  pfree(buf.data);
320 }
#define LOG
Definition: elog.h:26
void pfree(void *pointer)
Definition: mcxt.c:1169
void appendStringInfo(StringInfo str, const char *fmt,...)
Definition: stringinfo.c:91
static char * buf
Definition: pg_test_fsync.c:68
void initStringInfo(StringInfo str)
Definition: stringinfo.c:59
#define VirtualTransactionIdIsValid(vxid)
Definition: lock.h:72
int errdetail_log_plural(const char *fmt_singular, const char *fmt_plural, unsigned long n,...)
Definition: elog.c:1111
#define ereport(elevel,...)
Definition: elog.h:157
#define Assert(condition)
Definition: c.h:804
BackendId backendId
Definition: lock.h:66
int errmsg(const char *fmt,...)
Definition: elog.c:909
static const char * get_recovery_conflict_desc(ProcSignalReason reason)
Definition: standby.c:1419
void TimestampDifference(TimestampTz start_time, TimestampTz stop_time, long *secs, int *microsecs)
Definition: timestamp.c:1656
Definition: proc.h:121
int pid
Definition: proc.h:146
Datum now(PG_FUNCTION_ARGS)
Definition: timestamp.c:1544
PGPROC * BackendIdGetProc(int backendID)
Definition: sinvaladt.c:376

◆ LogStandbyInvalidations()

void LogStandbyInvalidations ( int  nmsgs,
SharedInvalidationMessage msgs,
bool  relcacheInitFileInval 
)

Definition at line 1397 of file standby.c.

References xl_invalidations::dbId, MinSizeOfInvalidations, MyDatabaseId, MyDatabaseTableSpace, xl_invalidations::nmsgs, xl_invalidations::relcacheInitFileInval, xl_invalidations::tsId, XLOG_INVALIDATIONS, XLogBeginInsert(), XLogInsert(), and XLogRegisterData().

Referenced by RecordTransactionCommit().

1399 {
1400  xl_invalidations xlrec;
1401 
1402  /* prepare record */
1403  memset(&xlrec, 0, sizeof(xlrec));
1404  xlrec.dbId = MyDatabaseId;
1405  xlrec.tsId = MyDatabaseTableSpace;
1406  xlrec.relcacheInitFileInval = relcacheInitFileInval;
1407  xlrec.nmsgs = nmsgs;
1408 
1409  /* perform insertion */
1410  XLogBeginInsert();
1411  XLogRegisterData((char *) (&xlrec), MinSizeOfInvalidations);
1412  XLogRegisterData((char *) msgs,
1413  nmsgs * sizeof(SharedInvalidationMessage));
1414  XLogInsert(RM_STANDBY_ID, XLOG_INVALIDATIONS);
1415 }
#define XLOG_INVALIDATIONS
Definition: standbydefs.h:36
Oid MyDatabaseTableSpace
Definition: globals.c:90
bool relcacheInitFileInval
Definition: standbydefs.h:67
#define MinSizeOfInvalidations
Definition: standbydefs.h:72
void XLogRegisterData(char *data, int len)
Definition: xloginsert.c:340
XLogRecPtr XLogInsert(RmgrId rmid, uint8 info)
Definition: xloginsert.c:434
Oid MyDatabaseId
Definition: globals.c:88
void XLogBeginInsert(void)
Definition: xloginsert.c:135

◆ LogStandbySnapshot()

XLogRecPtr LogStandbySnapshot ( void  )

Definition at line 1220 of file standby.c.

References Assert, GetRunningTransactionData(), GetRunningTransactionLocks(), RecoveryLockListsEntry::locks, LogAccessExclusiveLocks(), LogCurrentRunningXacts(), LWLockRelease(), pfree(), wal_level, WAL_LEVEL_LOGICAL, and XLogStandbyInfoActive.

Referenced by BackgroundWriterMain(), CreateCheckPoint(), ReplicationSlotReserveWal(), and SnapBuildWaitSnapshot().

1221 {
1222  XLogRecPtr recptr;
1223  RunningTransactions running;
1224  xl_standby_lock *locks;
1225  int nlocks;
1226 
1228 
1229  /*
1230  * Get details of any AccessExclusiveLocks being held at the moment.
1231  */
1232  locks = GetRunningTransactionLocks(&nlocks);
1233  if (nlocks > 0)
1234  LogAccessExclusiveLocks(nlocks, locks);
1235  pfree(locks);
1236 
1237  /*
1238  * Log details of all in-progress transactions. This should be the last
1239  * record we write, because standby will open up when it sees this.
1240  */
1241  running = GetRunningTransactionData();
1242 
1243  /*
1244  * GetRunningTransactionData() acquired ProcArrayLock, we must release it.
1245  * For Hot Standby this can be done before inserting the WAL record
1246  * because ProcArrayApplyRecoveryInfo() rechecks the commit status using
1247  * the clog. For logical decoding, though, the lock can't be released
1248  * early because the clog might be "in the future" from the POV of the
1249  * historic snapshot. This would allow for situations where we're waiting
1250  * for the end of a transaction listed in the xl_running_xacts record
1251  * which, according to the WAL, has committed before the xl_running_xacts
1252  * record. Fortunately this routine isn't executed frequently, and it's
1253  * only a shared lock.
1254  */
1256  LWLockRelease(ProcArrayLock);
1257 
1258  recptr = LogCurrentRunningXacts(running);
1259 
1260  /* Release lock if we kept it longer ... */
1262  LWLockRelease(ProcArrayLock);
1263 
1264  /* GetRunningTransactionData() acquired XidGenLock, we must release it */
1265  LWLockRelease(XidGenLock);
1266 
1267  return recptr;
1268 }
static void LogAccessExclusiveLocks(int nlocks, xl_standby_lock *locks)
Definition: standby.c:1340
int wal_level
Definition: xlog.c:108
xl_standby_lock * GetRunningTransactionLocks(int *nlocks)
Definition: lock.c:4018
void LWLockRelease(LWLock *lock)
Definition: lwlock.c:1803
void pfree(void *pointer)
Definition: mcxt.c:1169
static XLogRecPtr LogCurrentRunningXacts(RunningTransactions CurrRunningXacts)
Definition: standby.c:1280
#define XLogStandbyInfoActive()
Definition: xlog.h:180
uint64 XLogRecPtr
Definition: xlogdefs.h:21
#define Assert(condition)
Definition: c.h:804
RunningTransactions GetRunningTransactionData(void)
Definition: procarray.c:2707

◆ ResolveRecoveryConflictWithBufferPin()

void ResolveRecoveryConflictWithBufferPin ( void  )

Definition at line 753 of file standby.c.

References Assert, DeadlockTimeout, EnableTimeoutParams::delay_ms, disable_all_timeouts(), enable_timeouts(), EnableTimeoutParams::fin_time, GetCurrentTimestamp(), GetStandbyLimitTime(), got_standby_deadlock_timeout, EnableTimeoutParams::id, InHotStandby, PG_WAIT_BUFFER_PIN, PROCSIG_RECOVERY_CONFLICT_BUFFERPIN, PROCSIG_RECOVERY_CONFLICT_STARTUP_DEADLOCK, ProcWaitForSignal(), SendRecoveryConflictWithBufferPin(), STANDBY_DEADLOCK_TIMEOUT, STANDBY_TIMEOUT, TMPARAM_AFTER, TMPARAM_AT, and EnableTimeoutParams::type.

Referenced by LockBufferForCleanup().

754 {
755  TimestampTz ltime;
756 
758 
759  ltime = GetStandbyLimitTime();
760 
761  if (GetCurrentTimestamp() >= ltime && ltime != 0)
762  {
763  /*
764  * We're already behind, so clear a path as quickly as possible.
765  */
767  }
768  else
769  {
770  /*
771  * Wake up at ltime, and check for deadlocks as well if we will be
772  * waiting longer than deadlock_timeout
773  */
774  EnableTimeoutParams timeouts[2];
775  int cnt = 0;
776 
777  if (ltime != 0)
778  {
779  timeouts[cnt].id = STANDBY_TIMEOUT;
780  timeouts[cnt].type = TMPARAM_AT;
781  timeouts[cnt].fin_time = ltime;
782  cnt++;
783  }
784 
786  timeouts[cnt].id = STANDBY_DEADLOCK_TIMEOUT;
787  timeouts[cnt].type = TMPARAM_AFTER;
788  timeouts[cnt].delay_ms = DeadlockTimeout;
789  cnt++;
790 
791  enable_timeouts(timeouts, cnt);
792  }
793 
794  /*
795  * Wait to be signaled by UnpinBuffer().
796  *
797  * We assume that only UnpinBuffer() and the timeout requests established
798  * above can wake us up here. WakeupRecovery() called by walreceiver or
799  * SIGHUP signal handler, etc cannot do that because it uses the different
800  * latch from that ProcWaitForSignal() waits on.
801  */
803 
805  {
806  /*
807  * Send out a request for hot-standby backends to check themselves for
808  * deadlocks.
809  *
810  * XXX The subsequent ResolveRecoveryConflictWithBufferPin() will wait
811  * to be signaled by UnpinBuffer() again and send a request for
812  * deadlocks check if deadlock_timeout happens. This causes the
813  * request to continue to be sent every deadlock_timeout until the
814  * buffer is unpinned or ltime is reached. This would increase the
815  * workload in the startup process and backends. In practice it may
816  * not be so harmful because the period that the buffer is kept pinned
817  * is basically no so long. But we should fix this?
818  */
821  }
822 
823  /*
824  * Clear any timeout requests established above. We assume here that the
825  * Startup process doesn't have any other timeouts than what this function
826  * uses. If that stops being true, we could cancel the timeouts
827  * individually, but that'd be slower.
828  */
829  disable_all_timeouts(false);
831 }
static volatile sig_atomic_t got_standby_deadlock_timeout
Definition: standby.c:47
static TimestampTz GetStandbyLimitTime(void)
Definition: standby.c:176
TimeoutId id
Definition: timeout.h:56
TimestampTz GetCurrentTimestamp(void)
Definition: timestamp.c:1580
int64 TimestampTz
Definition: timestamp.h:39
TimeoutType type
Definition: timeout.h:57
void enable_timeouts(const EnableTimeoutParams *timeouts, int count)
Definition: timeout.c:572
void disable_all_timeouts(bool keep_indicators)
Definition: timeout.c:687
#define InHotStandby
Definition: xlogutils.h:57
#define PG_WAIT_BUFFER_PIN
Definition: wait_event.h:20
static void SendRecoveryConflictWithBufferPin(ProcSignalReason reason)
Definition: standby.c:834
void ProcWaitForSignal(uint32 wait_event_info)
Definition: proc.c:1897
#define Assert(condition)
Definition: c.h:804
TimestampTz fin_time
Definition: timeout.h:59
int DeadlockTimeout
Definition: proc.c:60

◆ ResolveRecoveryConflictWithDatabase()

void ResolveRecoveryConflictWithDatabase ( Oid  dbid)

Definition at line 529 of file standby.c.

References CancelDBBackends(), CountDBBackends(), pg_usleep(), and PROCSIG_RECOVERY_CONFLICT_DATABASE.

Referenced by dbase_redo().

530 {
531  /*
532  * We don't do ResolveRecoveryConflictWithVirtualXIDs() here since that
533  * only waits for transactions and completely idle sessions would block
534  * us. This is rare enough that we do this as simply as possible: no wait,
535  * just force them off immediately.
536  *
537  * No locking is required here because we already acquired
538  * AccessExclusiveLock. Anybody trying to connect while we do this will
539  * block during InitPostgres() and then disconnect when they see the
540  * database has been removed.
541  */
542  while (CountDBBackends(dbid) > 0)
543  {
545 
546  /*
547  * Wait awhile for them to die so that we avoid flooding an
548  * unresponsive backend when system is heavily loaded.
549  */
550  pg_usleep(10000);
551  }
552 }
int CountDBBackends(Oid databaseid)
Definition: procarray.c:3531
void pg_usleep(long microsec)
Definition: signal.c:53
void CancelDBBackends(Oid databaseid, ProcSignalReason sigmode, bool conflictPending)
Definition: procarray.c:3592

◆ ResolveRecoveryConflictWithLock()

void ResolveRecoveryConflictWithLock ( LOCKTAG  locktag,
bool  logging_conflict 
)

Definition at line 583 of file standby.c.

References AccessExclusiveLock, Assert, cleanup(), DeadlockTimeout, EnableTimeoutParams::delay_ms, disable_all_timeouts(), enable_timeouts(), EnableTimeoutParams::fin_time, GetCurrentTimestamp(), GetLockConflicts(), GetStandbyLimitTime(), got_standby_deadlock_timeout, got_standby_lock_timeout, EnableTimeoutParams::id, InHotStandby, LOCKTAG::locktag_type, MyProc, now(), pg_atomic_read_u64(), pg_atomic_write_u64(), PG_WAIT_LOCK, PROCSIG_RECOVERY_CONFLICT_LOCK, PROCSIG_RECOVERY_CONFLICT_STARTUP_DEADLOCK, ProcWaitForSignal(), ResolveRecoveryConflictWithVirtualXIDs(), SignalVirtualTransaction(), STANDBY_DEADLOCK_TIMEOUT, STANDBY_LOCK_TIMEOUT, TMPARAM_AFTER, TMPARAM_AT, EnableTimeoutParams::type, VirtualTransactionIdIsValid, and PGPROC::waitStart.

Referenced by ProcSleep().

584 {
585  TimestampTz ltime;
587 
589 
590  ltime = GetStandbyLimitTime();
591  now = GetCurrentTimestamp();
592 
593  /*
594  * Update waitStart if first time through after the startup process
595  * started waiting for the lock. It should not be updated every time
596  * ResolveRecoveryConflictWithLock() is called during the wait.
597  *
598  * Use the current time obtained for comparison with ltime as waitStart
599  * (i.e., the time when this process started waiting for the lock). Since
600  * getting the current time newly can cause overhead, we reuse the
601  * already-obtained time to avoid that overhead.
602  *
603  * Note that waitStart is updated without holding the lock table's
604  * partition lock, to avoid the overhead by additional lock acquisition.
605  * This can cause "waitstart" in pg_locks to become NULL for a very short
606  * period of time after the wait started even though "granted" is false.
607  * This is OK in practice because we can assume that users are likely to
608  * look at "waitstart" when waiting for the lock for a long time.
609  */
610  if (pg_atomic_read_u64(&MyProc->waitStart) == 0)
612 
613  if (now >= ltime && ltime != 0)
614  {
615  /*
616  * We're already behind, so clear a path as quickly as possible.
617  */
618  VirtualTransactionId *backends;
619 
620  backends = GetLockConflicts(&locktag, AccessExclusiveLock, NULL);
621 
622  /*
623  * Prevent ResolveRecoveryConflictWithVirtualXIDs() from reporting
624  * "waiting" in PS display by disabling its argument report_waiting
625  * because the caller, WaitOnLock(), has already reported that.
626  */
629  PG_WAIT_LOCK | locktag.locktag_type,
630  false);
631  }
632  else
633  {
634  /*
635  * Wait (or wait again) until ltime, and check for deadlocks as well
636  * if we will be waiting longer than deadlock_timeout
637  */
638  EnableTimeoutParams timeouts[2];
639  int cnt = 0;
640 
641  if (ltime != 0)
642  {
643  got_standby_lock_timeout = false;
644  timeouts[cnt].id = STANDBY_LOCK_TIMEOUT;
645  timeouts[cnt].type = TMPARAM_AT;
646  timeouts[cnt].fin_time = ltime;
647  cnt++;
648  }
649 
651  timeouts[cnt].id = STANDBY_DEADLOCK_TIMEOUT;
652  timeouts[cnt].type = TMPARAM_AFTER;
653  timeouts[cnt].delay_ms = DeadlockTimeout;
654  cnt++;
655 
656  enable_timeouts(timeouts, cnt);
657  }
658 
659  /* Wait to be signaled by the release of the Relation Lock */
661 
662  /*
663  * Exit if ltime is reached. Then all the backends holding conflicting
664  * locks will be canceled in the next ResolveRecoveryConflictWithLock()
665  * call.
666  */
668  goto cleanup;
669 
671  {
672  VirtualTransactionId *backends;
673 
674  backends = GetLockConflicts(&locktag, AccessExclusiveLock, NULL);
675 
676  /* Quick exit if there's no work to be done */
677  if (!VirtualTransactionIdIsValid(*backends))
678  goto cleanup;
679 
680  /*
681  * Send signals to all the backends holding the conflicting locks, to
682  * ask them to check themselves for deadlocks.
683  */
684  while (VirtualTransactionIdIsValid(*backends))
685  {
686  SignalVirtualTransaction(*backends,
688  false);
689  backends++;
690  }
691 
692  /*
693  * Exit if the recovery conflict has not been logged yet even though
694  * logging is enabled, so that the caller can log that. Then
695  * RecoveryConflictWithLock() is called again and we will wait again
696  * for the lock to be released.
697  */
698  if (logging_conflict)
699  goto cleanup;
700 
701  /*
702  * Wait again here to be signaled by the release of the Relation Lock,
703  * to prevent the subsequent RecoveryConflictWithLock() from causing
704  * deadlock_timeout and sending a request for deadlocks check again.
705  * Otherwise the request continues to be sent every deadlock_timeout
706  * until the relation locks are released or ltime is reached.
707  */
710  }
711 
712 cleanup:
713 
714  /*
715  * Clear any timeout requests established above. We assume here that the
716  * Startup process doesn't have any other outstanding timeouts than those
717  * used by this function. If that stops being true, we could cancel the
718  * timeouts individually, but that'd be slower.
719  */
720  disable_all_timeouts(false);
721  got_standby_lock_timeout = false;
723 }
static volatile sig_atomic_t got_standby_deadlock_timeout
Definition: standby.c:47
static TimestampTz GetStandbyLimitTime(void)
Definition: standby.c:176
TimeoutId id
Definition: timeout.h:56
static void ResolveRecoveryConflictWithVirtualXIDs(VirtualTransactionId *waitlist, ProcSignalReason reason, uint32 wait_event_info, bool report_waiting)
Definition: standby.c:335
TimestampTz GetCurrentTimestamp(void)
Definition: timestamp.c:1580
PGPROC * MyProc
Definition: proc.c:68
int64 TimestampTz
Definition: timestamp.h:39
TimeoutType type
Definition: timeout.h:57
#define PG_WAIT_LOCK
Definition: wait_event.h:19
static void pg_atomic_write_u64(volatile pg_atomic_uint64 *ptr, uint64 val)
Definition: atomics.h:438
pid_t SignalVirtualTransaction(VirtualTransactionId vxid, ProcSignalReason sigmode, bool conflictPending)
Definition: procarray.c:3429
void enable_timeouts(const EnableTimeoutParams *timeouts, int count)
Definition: timeout.c:572
void disable_all_timeouts(bool keep_indicators)
Definition: timeout.c:687
#define InHotStandby
Definition: xlogutils.h:57
void ProcWaitForSignal(uint32 wait_event_info)
Definition: proc.c:1897
#define VirtualTransactionIdIsValid(vxid)
Definition: lock.h:72
static volatile sig_atomic_t got_standby_lock_timeout
Definition: standby.c:48
static void cleanup(void)
Definition: bootstrap.c:697
VirtualTransactionId * GetLockConflicts(const LOCKTAG *locktag, LOCKMODE lockmode, int *countp)
Definition: lock.c:2914
uint8 locktag_type
Definition: lock.h:173
#define Assert(condition)
Definition: c.h:804
TimestampTz fin_time
Definition: timeout.h:59
#define AccessExclusiveLock
Definition: lockdefs.h:45
static uint64 pg_atomic_read_u64(volatile pg_atomic_uint64 *ptr)
Definition: atomics.h:429
int DeadlockTimeout
Definition: proc.c:60
pg_atomic_uint64 waitStart
Definition: proc.h:184
Datum now(PG_FUNCTION_ARGS)
Definition: timestamp.c:1544

◆ ResolveRecoveryConflictWithSnapshot()

void ResolveRecoveryConflictWithSnapshot ( TransactionId  latestRemovedXid,
RelFileNode  node 
)

Definition at line 443 of file standby.c.

References RelFileNode::dbNode, GetConflictingVirtualXIDs(), PROCSIG_RECOVERY_CONFLICT_SNAPSHOT, ResolveRecoveryConflictWithVirtualXIDs(), TransactionIdIsValid, and WAIT_EVENT_RECOVERY_CONFLICT_SNAPSHOT.

Referenced by btree_xlog_delete(), gistRedoDeleteRecord(), hash_xlog_vacuum_one_page(), heap_xlog_freeze_page(), heap_xlog_prune(), heap_xlog_visible(), ResolveRecoveryConflictWithSnapshotFullXid(), and spgRedoVacuumRedirect().

444 {
445  VirtualTransactionId *backends;
446 
447  /*
448  * If we get passed InvalidTransactionId then we do nothing (no conflict).
449  *
450  * This can happen when replaying already-applied WAL records after a
451  * standby crash or restart, or when replaying an XLOG_HEAP2_VISIBLE
452  * record that marks as frozen a page which was already all-visible. It's
453  * also quite common with records generated during index deletion
454  * (original execution of the deletion can reason that a recovery conflict
455  * which is sufficient for the deletion operation must take place before
456  * replay of the deletion record itself).
457  */
458  if (!TransactionIdIsValid(latestRemovedXid))
459  return;
460 
461  backends = GetConflictingVirtualXIDs(latestRemovedXid,
462  node.dbNode);
463 
467  true);
468 }
static void ResolveRecoveryConflictWithVirtualXIDs(VirtualTransactionId *waitlist, ProcSignalReason reason, uint32 wait_event_info, bool report_waiting)
Definition: standby.c:335
VirtualTransactionId * GetConflictingVirtualXIDs(TransactionId limitXmin, Oid dbOid)
Definition: procarray.c:3349
#define TransactionIdIsValid(xid)
Definition: transam.h:41

◆ ResolveRecoveryConflictWithSnapshotFullXid()

void ResolveRecoveryConflictWithSnapshotFullXid ( FullTransactionId  latestRemovedFullXid,
RelFileNode  node 
)

Definition at line 475 of file standby.c.

References MaxTransactionId, ReadNextFullTransactionId(), ResolveRecoveryConflictWithSnapshot(), U64FromFullTransactionId, and XidFromFullTransactionId.

Referenced by btree_xlog_reuse_page(), and gistRedoPageReuse().

477 {
478  /*
479  * ResolveRecoveryConflictWithSnapshot operates on 32-bit TransactionIds,
480  * so truncate the logged FullTransactionId. If the logged value is very
481  * old, so that XID wrap-around already happened on it, there can't be any
482  * snapshots that still see it.
483  */
485  uint64 diff;
486 
487  diff = U64FromFullTransactionId(nextXid) -
488  U64FromFullTransactionId(latestRemovedFullXid);
489  if (diff < MaxTransactionId / 2)
490  {
491  TransactionId latestRemovedXid;
492 
493  latestRemovedXid = XidFromFullTransactionId(latestRemovedFullXid);
494  ResolveRecoveryConflictWithSnapshot(latestRemovedXid, node);
495  }
496 }
uint32 TransactionId
Definition: c.h:587
#define XidFromFullTransactionId(x)
Definition: transam.h:48
FullTransactionId ReadNextFullTransactionId(void)
Definition: varsup.c:261
#define MaxTransactionId
Definition: transam.h:35
#define U64FromFullTransactionId(x)
Definition: transam.h:49
void ResolveRecoveryConflictWithSnapshot(TransactionId latestRemovedXid, RelFileNode node)
Definition: standby.c:443

◆ ResolveRecoveryConflictWithTablespace()

void ResolveRecoveryConflictWithTablespace ( Oid  tsid)

Definition at line 499 of file standby.c.

References GetConflictingVirtualXIDs(), InvalidOid, InvalidTransactionId, PROCSIG_RECOVERY_CONFLICT_TABLESPACE, ResolveRecoveryConflictWithVirtualXIDs(), and WAIT_EVENT_RECOVERY_CONFLICT_TABLESPACE.

Referenced by tblspc_redo().

500 {
501  VirtualTransactionId *temp_file_users;
502 
503  /*
504  * Standby users may be currently using this tablespace for their
505  * temporary files. We only care about current users because
506  * temp_tablespace parameter will just ignore tablespaces that no longer
507  * exist.
508  *
509  * Ask everybody to cancel their queries immediately so we can ensure no
510  * temp files remain and we can remove the tablespace. Nuke the entire
511  * site from orbit, it's the only way to be sure.
512  *
513  * XXX: We could work out the pids of active backends using this
514  * tablespace by examining the temp filenames in the directory. We would
515  * then convert the pids into VirtualXIDs before attempting to cancel
516  * them.
517  *
518  * We don't wait for commit because drop tablespace is non-transactional.
519  */
521  InvalidOid);
525  true);
526 }
static void ResolveRecoveryConflictWithVirtualXIDs(VirtualTransactionId *waitlist, ProcSignalReason reason, uint32 wait_event_info, bool report_waiting)
Definition: standby.c:335
VirtualTransactionId * GetConflictingVirtualXIDs(TransactionId limitXmin, Oid dbOid)
Definition: procarray.c:3349
#define InvalidTransactionId
Definition: transam.h:31
#define InvalidOid
Definition: postgres_ext.h:36

◆ ResolveRecoveryConflictWithVirtualXIDs()

static void ResolveRecoveryConflictWithVirtualXIDs ( VirtualTransactionId waitlist,
ProcSignalReason  reason,
uint32  wait_event_info,
bool  report_waiting 
)
static

Definition at line 335 of file standby.c.

References Assert, CancelVirtualTransaction(), DeadlockTimeout, get_ps_display(), GetCurrentTimestamp(), log_recovery_conflict_waits, LogRecoveryConflict(), now(), palloc(), pfree(), pg_usleep(), set_ps_display(), STANDBY_INITIAL_WAIT_US, standbyWait_us, TimestampDifferenceExceeds(), update_process_title, VirtualTransactionIdIsValid, VirtualXactLock(), and WaitExceedsMaxStandbyDelay().

Referenced by ResolveRecoveryConflictWithLock(), ResolveRecoveryConflictWithSnapshot(), and ResolveRecoveryConflictWithTablespace().

338 {
339  TimestampTz waitStart = 0;
340  char *new_status = NULL;
341  bool logged_recovery_conflict = false;
342 
343  /* Fast exit, to avoid a kernel call if there's no work to be done. */
344  if (!VirtualTransactionIdIsValid(*waitlist))
345  return;
346 
347  /* Set the wait start timestamp for reporting */
348  if (report_waiting && (log_recovery_conflict_waits || update_process_title))
349  waitStart = GetCurrentTimestamp();
350 
351  while (VirtualTransactionIdIsValid(*waitlist))
352  {
353  /* reset standbyWait_us for each xact we wait for */
355 
356  /* wait until the virtual xid is gone */
357  while (!VirtualXactLock(*waitlist, false))
358  {
359  /* Is it time to kill it? */
360  if (WaitExceedsMaxStandbyDelay(wait_event_info))
361  {
362  pid_t pid;
363 
364  /*
365  * Now find out who to throw out of the balloon.
366  */
368  pid = CancelVirtualTransaction(*waitlist, reason);
369 
370  /*
371  * Wait a little bit for it to die so that we avoid flooding
372  * an unresponsive backend when system is heavily loaded.
373  */
374  if (pid != 0)
375  pg_usleep(5000L);
376  }
377 
378  if (waitStart != 0 && (!logged_recovery_conflict || new_status == NULL))
379  {
380  TimestampTz now = 0;
381  bool maybe_log_conflict;
382  bool maybe_update_title;
383 
384  maybe_log_conflict = (log_recovery_conflict_waits && !logged_recovery_conflict);
385  maybe_update_title = (update_process_title && new_status == NULL);
386 
387  /* Get the current timestamp if not report yet */
388  if (maybe_log_conflict || maybe_update_title)
389  now = GetCurrentTimestamp();
390 
391  /*
392  * Report via ps if we have been waiting for more than 500
393  * msec (should that be configurable?)
394  */
395  if (maybe_update_title &&
396  TimestampDifferenceExceeds(waitStart, now, 500))
397  {
398  const char *old_status;
399  int len;
400 
401  old_status = get_ps_display(&len);
402  new_status = (char *) palloc(len + 8 + 1);
403  memcpy(new_status, old_status, len);
404  strcpy(new_status + len, " waiting");
405  set_ps_display(new_status);
406  new_status[len] = '\0'; /* truncate off " waiting" */
407  }
408 
409  /*
410  * Emit the log message if the startup process is waiting
411  * longer than deadlock_timeout for recovery conflict.
412  */
413  if (maybe_log_conflict &&
415  {
416  LogRecoveryConflict(reason, waitStart, now, waitlist, true);
417  logged_recovery_conflict = true;
418  }
419  }
420  }
421 
422  /* The virtual transaction is gone now, wait for the next one */
423  waitlist++;
424  }
425 
426  /*
427  * Emit the log message if recovery conflict was resolved but the startup
428  * process waited longer than deadlock_timeout for it.
429  */
430  if (logged_recovery_conflict)
431  LogRecoveryConflict(reason, waitStart, GetCurrentTimestamp(),
432  NULL, false);
433 
434  /* Reset ps display if we changed it */
435  if (new_status)
436  {
437  set_ps_display(new_status);
438  pfree(new_status);
439  }
440 }
static bool WaitExceedsMaxStandbyDelay(uint32 wait_event_info)
Definition: standby.c:209
pid_t CancelVirtualTransaction(VirtualTransactionId vxid, ProcSignalReason sigmode)
Definition: procarray.c:3423
bool update_process_title
Definition: ps_status.c:36
TimestampTz GetCurrentTimestamp(void)
Definition: timestamp.c:1580
int64 TimestampTz
Definition: timestamp.h:39
static int standbyWait_us
Definition: standby.c:201
void LogRecoveryConflict(ProcSignalReason reason, TimestampTz wait_start, TimestampTz now, VirtualTransactionId *wait_list, bool still_waiting)
Definition: standby.c:249
bool TimestampDifferenceExceeds(TimestampTz start_time, TimestampTz stop_time, int msec)
Definition: timestamp.c:1711
bool VirtualXactLock(VirtualTransactionId vxid, bool wait)
Definition: lock.c:4599
void set_ps_display(const char *activity)
Definition: ps_status.c:349
void pg_usleep(long microsec)
Definition: signal.c:53
void pfree(void *pointer)
Definition: mcxt.c:1169
#define STANDBY_INITIAL_WAIT_US
Definition: standby.c:200
const char * get_ps_display(int *displen)
Definition: ps_status.c:430
bool log_recovery_conflict_waits
Definition: standby.c:42
#define VirtualTransactionIdIsValid(vxid)
Definition: lock.h:72
#define Assert(condition)
Definition: c.h:804
void * palloc(Size size)
Definition: mcxt.c:1062
int DeadlockTimeout
Definition: proc.c:60
Datum now(PG_FUNCTION_ARGS)
Definition: timestamp.c:1544

◆ SendRecoveryConflictWithBufferPin()

static void SendRecoveryConflictWithBufferPin ( ProcSignalReason  reason)
static

Definition at line 834 of file standby.c.

References Assert, CancelDBBackends(), InvalidOid, PROCSIG_RECOVERY_CONFLICT_BUFFERPIN, and PROCSIG_RECOVERY_CONFLICT_STARTUP_DEADLOCK.

Referenced by ResolveRecoveryConflictWithBufferPin(), and StandbyTimeoutHandler().

835 {
838 
839  /*
840  * We send signal to all backends to ask them if they are holding the
841  * buffer pin which is delaying the Startup process. We must not set the
842  * conflict flag yet, since most backends will be innocent. Let the
843  * SIGUSR1 handling in each backend decide their own fate.
844  */
845  CancelDBBackends(InvalidOid, reason, false);
846 }
void CancelDBBackends(Oid databaseid, ProcSignalReason sigmode, bool conflictPending)
Definition: procarray.c:3592
#define InvalidOid
Definition: postgres_ext.h:36
#define Assert(condition)
Definition: c.h:804

◆ ShutdownRecoveryTransactionEnvironment()

void ShutdownRecoveryTransactionEnvironment ( void  )

Definition at line 138 of file standby.c.

References ExpireAllKnownAssignedTransactionIds(), hash_destroy(), StandbyReleaseAllLocks(), and VirtualXactLockTableCleanup().

Referenced by StartupProcExit(), and StartupXLOG().

139 {
140  /*
141  * Do nothing if RecoveryLockLists is NULL because which means that
142  * transaction tracking has not been yet initialized or has been already
143  * shutdowned. This prevents transaction tracking from being shutdowned
144  * unexpectedly more than once.
145  */
146  if (RecoveryLockLists == NULL)
147  return;
148 
149  /* Mark all tracked in-progress transactions as finished. */
151 
152  /* Release all locks the tracked transactions were holding */
154 
155  /* Destroy the hash table of locks. */
157  RecoveryLockLists = NULL;
158 
159  /* Cleanup our VirtualTransaction */
161 }
void hash_destroy(HTAB *hashp)
Definition: dynahash.c:862
void VirtualXactLockTableCleanup(void)
Definition: lock.c:4499
static HTAB * RecoveryLockLists
Definition: standby.c:44
void ExpireAllKnownAssignedTransactionIds(void)
Definition: procarray.c:4450
void StandbyReleaseAllLocks(void)
Definition: standby.c:1049

◆ standby_redo()

void standby_redo ( XLogReaderState record)

Definition at line 1103 of file standby.c.

References Assert, xl_invalidations::dbId, xl_standby_lock::dbOid, elog, i, xl_running_xacts::latestCompletedXid, RunningTransactionsData::latestCompletedXid, xl_standby_locks::locks, xl_invalidations::msgs, xl_running_xacts::nextXid, RunningTransactionsData::nextXid, xl_standby_locks::nlocks, xl_invalidations::nmsgs, xl_running_xacts::oldestRunningXid, RunningTransactionsData::oldestRunningXid, PANIC, ProcArrayApplyRecoveryInfo(), ProcessCommittedInvalidationMessages(), xl_invalidations::relcacheInitFileInval, xl_standby_lock::relOid, STANDBY_DISABLED, StandbyAcquireAccessExclusiveLock(), standbyState, xl_running_xacts::subxcnt, RunningTransactionsData::subxcnt, xl_running_xacts::subxid_overflow, RunningTransactionsData::subxid_overflow, xl_invalidations::tsId, xl_running_xacts::xcnt, RunningTransactionsData::xcnt, xl_standby_lock::xid, xl_running_xacts::xids, RunningTransactionsData::xids, XLOG_INVALIDATIONS, XLOG_RUNNING_XACTS, XLOG_STANDBY_LOCK, XLogRecGetData, XLogRecGetInfo, XLogRecHasAnyBlockRefs, and XLR_INFO_MASK.

1104 {
1105  uint8 info = XLogRecGetInfo(record) & ~XLR_INFO_MASK;
1106 
1107  /* Backup blocks are not used in standby records */
1108  Assert(!XLogRecHasAnyBlockRefs(record));
1109 
1110  /* Do nothing if we're not in hot standby mode */
1112  return;
1113 
1114  if (info == XLOG_STANDBY_LOCK)
1115  {
1116  xl_standby_locks *xlrec = (xl_standby_locks *) XLogRecGetData(record);
1117  int i;
1118 
1119  for (i = 0; i < xlrec->nlocks; i++)
1121  xlrec->locks[i].dbOid,
1122  xlrec->locks[i].relOid);
1123  }
1124  else if (info == XLOG_RUNNING_XACTS)
1125  {
1126  xl_running_xacts *xlrec = (xl_running_xacts *) XLogRecGetData(record);
1127  RunningTransactionsData running;
1128 
1129  running.xcnt = xlrec->xcnt;
1130  running.subxcnt = xlrec->subxcnt;
1131  running.subxid_overflow = xlrec->subxid_overflow;
1132  running.nextXid = xlrec->nextXid;
1133  running.latestCompletedXid = xlrec->latestCompletedXid;
1134  running.oldestRunningXid = xlrec->oldestRunningXid;
1135  running.xids = xlrec->xids;
1136 
1137  ProcArrayApplyRecoveryInfo(&running);
1138  }
1139  else if (info == XLOG_INVALIDATIONS)
1140  {
1141  xl_invalidations *xlrec = (xl_invalidations *) XLogRecGetData(record);
1142 
1144  xlrec->nmsgs,
1145  xlrec->relcacheInitFileInval,
1146  xlrec->dbId,
1147  xlrec->tsId);
1148  }
1149  else
1150  elog(PANIC, "standby_redo: unknown op code %u", info);
1151 }
void ProcArrayApplyRecoveryInfo(RunningTransactions running)
Definition: procarray.c:1034
TransactionId oldestRunningXid
Definition: standby.h:83
#define XLOG_INVALIDATIONS
Definition: standbydefs.h:36
unsigned char uint8
Definition: c.h:439
#define XLOG_STANDBY_LOCK
Definition: standbydefs.h:34
TransactionId * xids
Definition: standby.h:86
#define PANIC
Definition: elog.h:50
TransactionId latestCompletedXid
Definition: standby.h:84
TransactionId xids[FLEXIBLE_ARRAY_MEMBER]
Definition: standbydefs.h:56
#define XLogRecGetData(decoder)
Definition: xlogreader.h:320
TransactionId latestCompletedXid
Definition: standbydefs.h:54
bool relcacheInitFileInval
Definition: standbydefs.h:67
HotStandbyState standbyState
Definition: xlogutils.c:55
#define XLogRecGetInfo(decoder)
Definition: xlogreader.h:315
TransactionId xid
Definition: lockdefs.h:54
void ProcessCommittedInvalidationMessages(SharedInvalidationMessage *msgs, int nmsgs, bool RelcacheInitFileInval, Oid dbid, Oid tsid)
Definition: inval.c:962
#define Assert(condition)
Definition: c.h:804
#define XLR_INFO_MASK
Definition: xlogrecord.h:62
SharedInvalidationMessage msgs[FLEXIBLE_ARRAY_MEMBER]
Definition: standbydefs.h:69
TransactionId nextXid
Definition: standbydefs.h:52
xl_standby_lock locks[FLEXIBLE_ARRAY_MEMBER]
Definition: standbydefs.h:41
TransactionId nextXid
Definition: standby.h:82
void StandbyAcquireAccessExclusiveLock(TransactionId xid, Oid dbOid, Oid relOid)
Definition: standby.c:948
#define elog(elevel,...)
Definition: elog.h:232
int i
TransactionId oldestRunningXid
Definition: standbydefs.h:53
#define XLOG_RUNNING_XACTS
Definition: standbydefs.h:35
#define XLogRecHasAnyBlockRefs(decoder)
Definition: xlogreader.h:322

◆ StandbyAcquireAccessExclusiveLock()

void StandbyAcquireAccessExclusiveLock ( TransactionId  xid,
Oid  dbOid,
Oid  relOid 
)

Definition at line 948 of file standby.c.

References AccessExclusiveLock, Assert, xl_standby_lock::dbOid, DEBUG4, elog, HASH_ENTER, hash_search(), lappend(), LockAcquire(), RecoveryLockListsEntry::locks, NIL, OidIsValid, palloc(), xl_standby_lock::relOid, SET_LOCKTAG_RELATION, trace_recovery(), TransactionIdDidAbort(), TransactionIdDidCommit(), TransactionIdIsValid, xl_standby_lock::xid, and RecoveryLockListsEntry::xid.

Referenced by lock_twophase_standby_recover(), and standby_redo().

949 {
950  RecoveryLockListsEntry *entry;
951  xl_standby_lock *newlock;
952  LOCKTAG locktag;
953  bool found;
954 
955  /* Already processed? */
956  if (!TransactionIdIsValid(xid) ||
957  TransactionIdDidCommit(xid) ||
959  return;
960 
962  "adding recovery lock: db %u rel %u", dbOid, relOid);
963 
964  /* dbOid is InvalidOid when we are locking a shared relation. */
965  Assert(OidIsValid(relOid));
966 
967  /* Create a new list for this xid, if we don't have one already. */
968  entry = hash_search(RecoveryLockLists, &xid, HASH_ENTER, &found);
969  if (!found)
970  {
971  entry->xid = xid;
972  entry->locks = NIL;
973  }
974 
975  newlock = palloc(sizeof(xl_standby_lock));
976  newlock->xid = xid;
977  newlock->dbOid = dbOid;
978  newlock->relOid = relOid;
979  entry->locks = lappend(entry->locks, newlock);
980 
981  SET_LOCKTAG_RELATION(locktag, newlock->dbOid, newlock->relOid);
982 
983  (void) LockAcquire(&locktag, AccessExclusiveLock, true, false);
984 }
#define NIL
Definition: pg_list.h:65
LockAcquireResult LockAcquire(const LOCKTAG *locktag, LOCKMODE lockmode, bool sessionLock, bool dontWait)
Definition: lock.c:747
static HTAB * RecoveryLockLists
Definition: standby.c:44
Definition: lock.h:167
void * hash_search(HTAB *hashp, const void *keyPtr, HASHACTION action, bool *foundPtr)
Definition: dynahash.c:954
bool TransactionIdDidCommit(TransactionId transactionId)
Definition: transam.c:125
#define DEBUG4
Definition: elog.h:22
#define OidIsValid(objectId)
Definition: c.h:710
TransactionId xid
Definition: standby.c:64
int trace_recovery(int trace_level)
Definition: elog.c:3597
#define SET_LOCKTAG_RELATION(locktag, dboid, reloid)
Definition: lock.h:184
bool TransactionIdDidAbort(TransactionId transactionId)
Definition: transam.c:181
List * lappend(List *list, void *datum)
Definition: list.c:336
TransactionId xid
Definition: lockdefs.h:54
#define Assert(condition)
Definition: c.h:804
#define AccessExclusiveLock
Definition: lockdefs.h:45
void * palloc(Size size)
Definition: mcxt.c:1062
#define elog(elevel,...)
Definition: elog.h:232
#define TransactionIdIsValid(xid)
Definition: transam.h:41

◆ StandbyDeadLockHandler()

void StandbyDeadLockHandler ( void  )

Definition at line 893 of file standby.c.

References got_standby_deadlock_timeout.

Referenced by StartupProcessMain().

894 {
896 }
static volatile sig_atomic_t got_standby_deadlock_timeout
Definition: standby.c:47

◆ StandbyLockTimeoutHandler()

void StandbyLockTimeoutHandler ( void  )

Definition at line 916 of file standby.c.

References got_standby_lock_timeout.

Referenced by StartupProcessMain().

917 {
919 }
static volatile sig_atomic_t got_standby_lock_timeout
Definition: standby.c:48

◆ StandbyReleaseAllLocks()

void StandbyReleaseAllLocks ( void  )

Definition at line 1049 of file standby.c.

References DEBUG2, elog, HASH_REMOVE, hash_search(), hash_seq_init(), hash_seq_search(), RecoveryLockListsEntry::locks, StandbyReleaseLockList(), status(), and trace_recovery().

Referenced by ShutdownRecoveryTransactionEnvironment(), and StandbyReleaseLocks().

1050 {
1052  RecoveryLockListsEntry *entry;
1053 
1054  elog(trace_recovery(DEBUG2), "release all standby locks");
1055 
1056  hash_seq_init(&status, RecoveryLockLists);
1057  while ((entry = hash_seq_search(&status)))
1058  {
1059  StandbyReleaseLockList(entry->locks);
1060  hash_search(RecoveryLockLists, entry, HASH_REMOVE, NULL);
1061  }
1062 }
static void StandbyReleaseLockList(List *locks)
Definition: standby.c:987
static HTAB * RecoveryLockLists
Definition: standby.c:44
void * hash_search(HTAB *hashp, const void *keyPtr, HASHACTION action, bool *foundPtr)
Definition: dynahash.c:954
int trace_recovery(int trace_level)
Definition: elog.c:3597
#define DEBUG2
Definition: elog.h:24
void * hash_seq_search(HASH_SEQ_STATUS *status)
Definition: dynahash.c:1436
void hash_seq_init(HASH_SEQ_STATUS *status, HTAB *hashp)
Definition: dynahash.c:1426
#define elog(elevel,...)
Definition: elog.h:232
static void static void status(const char *fmt,...) pg_attribute_printf(1
Definition: pg_regress.c:229

◆ StandbyReleaseLockList()

static void StandbyReleaseLockList ( List locks)
static

Definition at line 987 of file standby.c.

References AccessExclusiveLock, Assert, xl_standby_lock::dbOid, DEBUG4, elog, linitial, list_delete_first(), LockRelease(), LOG, pfree(), xl_standby_lock::relOid, SET_LOCKTAG_RELATION, trace_recovery(), and xl_standby_lock::xid.

Referenced by StandbyReleaseAllLocks(), StandbyReleaseLocks(), and StandbyReleaseOldLocks().

988 {
989  while (locks)
990  {
991  xl_standby_lock *lock = (xl_standby_lock *) linitial(locks);
992  LOCKTAG locktag;
993 
995  "releasing recovery lock: xid %u db %u rel %u",
996  lock->xid, lock->dbOid, lock->relOid);
997  SET_LOCKTAG_RELATION(locktag, lock->dbOid, lock->relOid);
998  if (!LockRelease(&locktag, AccessExclusiveLock, true))
999  {
1000  elog(LOG,
1001  "RecoveryLockLists contains entry for lock no longer recorded by lock manager: xid %u database %u relation %u",
1002  lock->xid, lock->dbOid, lock->relOid);
1003  Assert(false);
1004  }
1005  pfree(lock);
1006  locks = list_delete_first(locks);
1007  }
1008 }
Definition: lock.h:167
#define LOG
Definition: elog.h:26
#define DEBUG4
Definition: elog.h:22
int trace_recovery(int trace_level)
Definition: elog.c:3597
void pfree(void *pointer)
Definition: mcxt.c:1169
#define linitial(l)
Definition: pg_list.h:174
#define SET_LOCKTAG_RELATION(locktag, dboid, reloid)
Definition: lock.h:184
TransactionId xid
Definition: lockdefs.h:54
#define Assert(condition)
Definition: c.h:804
#define AccessExclusiveLock
Definition: lockdefs.h:45
#define elog(elevel,...)
Definition: elog.h:232
bool LockRelease(const LOCKTAG *locktag, LOCKMODE lockmode, bool sessionLock)
Definition: lock.c:1975
List * list_delete_first(List *list)
Definition: list.c:875

◆ StandbyReleaseLocks()

static void StandbyReleaseLocks ( TransactionId  xid)
static

Definition at line 1011 of file standby.c.

References HASH_FIND, HASH_REMOVE, hash_search(), RecoveryLockListsEntry::locks, StandbyReleaseAllLocks(), StandbyReleaseLockList(), and TransactionIdIsValid.

Referenced by StandbyReleaseLockTree().

1012 {
1013  RecoveryLockListsEntry *entry;
1014 
1015  if (TransactionIdIsValid(xid))
1016  {
1017  if ((entry = hash_search(RecoveryLockLists, &xid, HASH_FIND, NULL)))
1018  {
1019  StandbyReleaseLockList(entry->locks);
1020  hash_search(RecoveryLockLists, entry, HASH_REMOVE, NULL);
1021  }
1022  }
1023  else
1025 }
static void StandbyReleaseLockList(List *locks)
Definition: standby.c:987
static HTAB * RecoveryLockLists
Definition: standby.c:44
void * hash_search(HTAB *hashp, const void *keyPtr, HASHACTION action, bool *foundPtr)
Definition: dynahash.c:954
void StandbyReleaseAllLocks(void)
Definition: standby.c:1049
#define TransactionIdIsValid(xid)
Definition: transam.h:41

◆ StandbyReleaseLockTree()

void StandbyReleaseLockTree ( TransactionId  xid,
int  nsubxids,
TransactionId subxids 
)

Definition at line 1035 of file standby.c.

References i, and StandbyReleaseLocks().

Referenced by RecoverPreparedTransactions(), xact_redo_abort(), and xact_redo_commit().

1036 {
1037  int i;
1038 
1039  StandbyReleaseLocks(xid);
1040 
1041  for (i = 0; i < nsubxids; i++)
1042  StandbyReleaseLocks(subxids[i]);
1043 }
static void StandbyReleaseLocks(TransactionId xid)
Definition: standby.c:1011
int i

◆ StandbyReleaseOldLocks()

void StandbyReleaseOldLocks ( TransactionId  oldxid)

Definition at line 1070 of file standby.c.

References Assert, HASH_REMOVE, hash_search(), hash_seq_init(), hash_seq_search(), RecoveryLockListsEntry::locks, StandbyReleaseLockList(), StandbyTransactionIdIsPrepared(), status(), TransactionIdIsValid, TransactionIdPrecedes(), and RecoveryLockListsEntry::xid.

Referenced by ProcArrayApplyRecoveryInfo().

1071 {
1073  RecoveryLockListsEntry *entry;
1074 
1075  hash_seq_init(&status, RecoveryLockLists);
1076  while ((entry = hash_seq_search(&status)))
1077  {
1078  Assert(TransactionIdIsValid(entry->xid));
1079 
1080  /* Skip if prepared transaction. */
1081  if (StandbyTransactionIdIsPrepared(entry->xid))
1082  continue;
1083 
1084  /* Skip if >= oldxid. */
1085  if (!TransactionIdPrecedes(entry->xid, oldxid))
1086  continue;
1087 
1088  /* Remove all locks and hash table entry. */
1089  StandbyReleaseLockList(entry->locks);
1090  hash_search(RecoveryLockLists, entry, HASH_REMOVE, NULL);
1091  }
1092 }
static void StandbyReleaseLockList(List *locks)
Definition: standby.c:987
static HTAB * RecoveryLockLists
Definition: standby.c:44
void * hash_search(HTAB *hashp, const void *keyPtr, HASHACTION action, bool *foundPtr)
Definition: dynahash.c:954
TransactionId xid
Definition: standby.c:64
bool StandbyTransactionIdIsPrepared(TransactionId xid)
Definition: twophase.c:1438
bool TransactionIdPrecedes(TransactionId id1, TransactionId id2)
Definition: transam.c:300
#define Assert(condition)
Definition: c.h:804
void * hash_seq_search(HASH_SEQ_STATUS *status)
Definition: dynahash.c:1436
void hash_seq_init(HASH_SEQ_STATUS *status, HTAB *hashp)
Definition: dynahash.c:1426
#define TransactionIdIsValid(xid)
Definition: transam.h:41
static void static void status(const char *fmt,...) pg_attribute_printf(1
Definition: pg_regress.c:229

◆ StandbyTimeoutHandler()

void StandbyTimeoutHandler ( void  )

Definition at line 904 of file standby.c.

References disable_timeout(), PROCSIG_RECOVERY_CONFLICT_BUFFERPIN, SendRecoveryConflictWithBufferPin(), and STANDBY_DEADLOCK_TIMEOUT.

Referenced by StartupProcessMain().

905 {
906  /* forget any pending STANDBY_DEADLOCK_TIMEOUT request */
908 
910 }
static void SendRecoveryConflictWithBufferPin(ProcSignalReason reason)
Definition: standby.c:834
void disable_timeout(TimeoutId id, bool keep_indicator)
Definition: timeout.c:621

◆ WaitExceedsMaxStandbyDelay()

static bool WaitExceedsMaxStandbyDelay ( uint32  wait_event_info)
static

Definition at line 209 of file standby.c.

References CHECK_FOR_INTERRUPTS, GetCurrentTimestamp(), GetStandbyLimitTime(), pg_usleep(), pgstat_report_wait_end(), pgstat_report_wait_start(), and standbyWait_us.

Referenced by ResolveRecoveryConflictWithVirtualXIDs().

210 {
211  TimestampTz ltime;
212 
214 
215  /* Are we past the limit time? */
216  ltime = GetStandbyLimitTime();
217  if (ltime && GetCurrentTimestamp() >= ltime)
218  return true;
219 
220  /*
221  * Sleep a bit (this is essential to avoid busy-waiting).
222  */
223  pgstat_report_wait_start(wait_event_info);
226 
227  /*
228  * Progressively increase the sleep times, but not to more than 1s, since
229  * pg_usleep isn't interruptible on some platforms.
230  */
231  standbyWait_us *= 2;
232  if (standbyWait_us > 1000000)
233  standbyWait_us = 1000000;
234 
235  return false;
236 }
static TimestampTz GetStandbyLimitTime(void)
Definition: standby.c:176
static void pgstat_report_wait_end(void)
Definition: wait_event.h:274
TimestampTz GetCurrentTimestamp(void)
Definition: timestamp.c:1580
int64 TimestampTz
Definition: timestamp.h:39
static int standbyWait_us
Definition: standby.c:201
void pg_usleep(long microsec)
Definition: signal.c:53
static void pgstat_report_wait_start(uint32 wait_event_info)
Definition: wait_event.h:258
#define CHECK_FOR_INTERRUPTS()
Definition: miscadmin.h:120

Variable Documentation

◆ got_standby_deadlock_timeout

volatile sig_atomic_t got_standby_deadlock_timeout = false
static

◆ got_standby_lock_timeout

volatile sig_atomic_t got_standby_lock_timeout = false
static

Definition at line 48 of file standby.c.

Referenced by ResolveRecoveryConflictWithLock(), and StandbyLockTimeoutHandler().

◆ log_recovery_conflict_waits

bool log_recovery_conflict_waits = false

◆ max_standby_archive_delay

int max_standby_archive_delay = 30 * 1000

Definition at line 40 of file standby.c.

Referenced by GetStandbyLimitTime().

◆ max_standby_streaming_delay

int max_standby_streaming_delay = 30 * 1000

Definition at line 41 of file standby.c.

Referenced by GetStandbyLimitTime().

◆ RecoveryLockLists

HTAB* RecoveryLockLists
static

Definition at line 44 of file standby.c.

◆ standbyWait_us

int standbyWait_us = STANDBY_INITIAL_WAIT_US
static

◆ vacuum_defer_cleanup_age

int vacuum_defer_cleanup_age

Definition at line 39 of file standby.c.

Referenced by ComputeXidHorizons(), and GetSnapshotData().