PostgreSQL Source Code  git master
walsender.h File Reference
#include <signal.h>
Include dependency graph for walsender.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define WalSndWakeupRequest()    do { wake_wal_senders = true; } while (0)
 
#define WalSndWakeupProcessRequests()
 

Enumerations

enum  CRSSnapshotAction { CRS_EXPORT_SNAPSHOT , CRS_NOEXPORT_SNAPSHOT , CRS_USE_SNAPSHOT }
 

Functions

void InitWalSender (void)
 
bool exec_replication_command (const char *query_string)
 
void WalSndErrorCleanup (void)
 
void WalSndResourceCleanup (bool isCommit)
 
void WalSndSignals (void)
 
Size WalSndShmemSize (void)
 
void WalSndShmemInit (void)
 
void WalSndWakeup (void)
 
void WalSndInitStopping (void)
 
void WalSndWaitStopping (void)
 
void HandleWalSndInitStopping (void)
 
void WalSndRqstFileReload (void)
 

Variables

bool am_walsender
 
bool am_cascading_walsender
 
bool am_db_walsender
 
bool wake_wal_senders
 
int max_wal_senders
 
int wal_sender_timeout
 
bool log_replication_commands
 

Macro Definition Documentation

◆ WalSndWakeupProcessRequests

#define WalSndWakeupProcessRequests ( )
Value:
do \
{ \
{ \
wake_wal_senders = false; \
if (max_wal_senders > 0) \
WalSndWakeup(); \
} \
} while (0)
bool wake_wal_senders
Definition: walsender.c:130
int max_wal_senders
Definition: walsender.c:121

Definition at line 63 of file walsender.h.

◆ WalSndWakeupRequest

#define WalSndWakeupRequest ( )     do { wake_wal_senders = true; } while (0)

Definition at line 57 of file walsender.h.

Enumeration Type Documentation

◆ CRSSnapshotAction

Enumerator
CRS_EXPORT_SNAPSHOT 
CRS_NOEXPORT_SNAPSHOT 
CRS_USE_SNAPSHOT 

Definition at line 20 of file walsender.h.

21 {
CRSSnapshotAction
Definition: walsender.h:21
@ CRS_USE_SNAPSHOT
Definition: walsender.h:24
@ CRS_NOEXPORT_SNAPSHOT
Definition: walsender.h:23
@ CRS_EXPORT_SNAPSHOT
Definition: walsender.h:22

Function Documentation

◆ exec_replication_command()

bool exec_replication_command ( const char *  query_string)

Definition at line 1611 of file walsender.c.

1612 {
1613  int parse_rc;
1614  Node *cmd_node;
1615  const char *cmdtag;
1616  MemoryContext cmd_context;
1617  MemoryContext old_context;
1618 
1619  /*
1620  * If WAL sender has been told that shutdown is getting close, switch its
1621  * status accordingly to handle the next replication commands correctly.
1622  */
1623  if (got_STOPPING)
1625 
1626  /*
1627  * Throw error if in stopping mode. We need prevent commands that could
1628  * generate WAL while the shutdown checkpoint is being written. To be
1629  * safe, we just prohibit all new commands.
1630  */
1632  ereport(ERROR,
1633  (errmsg("cannot execute new commands while WAL sender is in stopping mode")));
1634 
1635  /*
1636  * CREATE_REPLICATION_SLOT ... LOGICAL exports a snapshot until the next
1637  * command arrives. Clean up the old stuff if there's anything.
1638  */
1640 
1642 
1643  /*
1644  * Parse the command.
1645  */
1647  "Replication command context",
1649  old_context = MemoryContextSwitchTo(cmd_context);
1650 
1651  replication_scanner_init(cmd_string);
1652  parse_rc = replication_yyparse();
1653  if (parse_rc != 0)
1654  ereport(ERROR,
1655  (errcode(ERRCODE_SYNTAX_ERROR),
1656  errmsg_internal("replication command parser returned %d",
1657  parse_rc)));
1659 
1660  cmd_node = replication_parse_result;
1661 
1662  /*
1663  * If it's a SQL command, just clean up our mess and return false; the
1664  * caller will take care of executing it.
1665  */
1666  if (IsA(cmd_node, SQLCmd))
1667  {
1668  if (MyDatabaseId == InvalidOid)
1669  ereport(ERROR,
1670  (errmsg("cannot execute SQL commands in WAL sender for physical replication")));
1671 
1672  MemoryContextSwitchTo(old_context);
1673  MemoryContextDelete(cmd_context);
1674 
1675  /* Tell the caller that this wasn't a WalSender command. */
1676  return false;
1677  }
1678 
1679  /*
1680  * Report query to various monitoring facilities. For this purpose, we
1681  * report replication commands just like SQL commands.
1682  */
1683  debug_query_string = cmd_string;
1684 
1686 
1687  /*
1688  * Log replication command if log_replication_commands is enabled. Even
1689  * when it's disabled, log the command with DEBUG1 level for backward
1690  * compatibility.
1691  */
1693  (errmsg("received replication command: %s", cmd_string)));
1694 
1695  /*
1696  * Disallow replication commands in aborted transaction blocks.
1697  */
1699  ereport(ERROR,
1700  (errcode(ERRCODE_IN_FAILED_SQL_TRANSACTION),
1701  errmsg("current transaction is aborted, "
1702  "commands ignored until end of transaction block")));
1703 
1705 
1706  /*
1707  * Allocate buffers that will be used for each outgoing and incoming
1708  * message. We do this just once per command to reduce palloc overhead.
1709  */
1713 
1714  switch (cmd_node->type)
1715  {
1716  case T_IdentifySystemCmd:
1717  cmdtag = "IDENTIFY_SYSTEM";
1718  set_ps_display(cmdtag);
1719  IdentifySystem();
1720  EndReplicationCommand(cmdtag);
1721  break;
1722 
1724  cmdtag = "READ_REPLICATION_SLOT";
1725  set_ps_display(cmdtag);
1727  EndReplicationCommand(cmdtag);
1728  break;
1729 
1730  case T_BaseBackupCmd:
1731  cmdtag = "BASE_BACKUP";
1732  set_ps_display(cmdtag);
1733  PreventInTransactionBlock(true, cmdtag);
1734  SendBaseBackup((BaseBackupCmd *) cmd_node);
1735  EndReplicationCommand(cmdtag);
1736  break;
1737 
1739  cmdtag = "CREATE_REPLICATION_SLOT";
1740  set_ps_display(cmdtag);
1742  EndReplicationCommand(cmdtag);
1743  break;
1744 
1746  cmdtag = "DROP_REPLICATION_SLOT";
1747  set_ps_display(cmdtag);
1749  EndReplicationCommand(cmdtag);
1750  break;
1751 
1752  case T_StartReplicationCmd:
1753  {
1754  StartReplicationCmd *cmd = (StartReplicationCmd *) cmd_node;
1755 
1756  cmdtag = "START_REPLICATION";
1757  set_ps_display(cmdtag);
1758  PreventInTransactionBlock(true, cmdtag);
1759 
1760  if (cmd->kind == REPLICATION_KIND_PHYSICAL)
1761  StartReplication(cmd);
1762  else
1764 
1765  /* dupe, but necessary per libpqrcv_endstreaming */
1766  EndReplicationCommand(cmdtag);
1767 
1768  Assert(xlogreader != NULL);
1769  break;
1770  }
1771 
1772  case T_TimeLineHistoryCmd:
1773  cmdtag = "TIMELINE_HISTORY";
1774  set_ps_display(cmdtag);
1775  PreventInTransactionBlock(true, cmdtag);
1777  EndReplicationCommand(cmdtag);
1778  break;
1779 
1780  case T_VariableShowStmt:
1781  {
1783  VariableShowStmt *n = (VariableShowStmt *) cmd_node;
1784 
1785  cmdtag = "SHOW";
1786  set_ps_display(cmdtag);
1787 
1788  /* syscache access needs a transaction environment */
1790  GetPGVariable(n->name, dest);
1792  EndReplicationCommand(cmdtag);
1793  }
1794  break;
1795 
1796  default:
1797  elog(ERROR, "unrecognized replication command node tag: %u",
1798  cmd_node->type);
1799  }
1800 
1801  /* done */
1802  MemoryContextSwitchTo(old_context);
1803  MemoryContextDelete(cmd_context);
1804 
1805  /*
1806  * We need not update ps display or pg_stat_activity, because PostgresMain
1807  * will reset those to "idle". But we must reset debug_query_string to
1808  * ensure it doesn't become a dangling pointer.
1809  */
1810  debug_query_string = NULL;
1811 
1812  return true;
1813 }
void pgstat_report_activity(BackendState state, const char *cmd_str)
@ STATE_RUNNING
void SendBaseBackup(BaseBackupCmd *cmd)
Definition: basebackup.c:866
void EndReplicationCommand(const char *commandTag)
Definition: dest.c:221
DestReceiver * CreateDestReceiver(CommandDest dest)
Definition: dest.c:113
@ DestRemoteSimple
Definition: dest.h:93
int errmsg_internal(const char *fmt,...)
Definition: elog.c:996
int errcode(int sqlerrcode)
Definition: elog.c:698
int errmsg(const char *fmt,...)
Definition: elog.c:909
#define LOG
Definition: elog.h:25
#define DEBUG1
Definition: elog.h:24
#define ERROR
Definition: elog.h:33
#define elog(elevel,...)
Definition: elog.h:218
#define ereport(elevel,...)
Definition: elog.h:143
Oid MyDatabaseId
Definition: globals.c:88
void GetPGVariable(const char *name, DestReceiver *dest)
Definition: guc.c:9351
Assert(fmt[strlen(fmt) - 1] !='\n')
MemoryContext CurrentMemoryContext
Definition: mcxt.c:42
void MemoryContextDelete(MemoryContext context)
Definition: mcxt.c:218
#define AllocSetContextCreate
Definition: memutils.h:173
#define ALLOCSET_DEFAULT_SIZES
Definition: memutils.h:195
#define CHECK_FOR_INTERRUPTS()
Definition: miscadmin.h:120
#define IsA(nodeptr, _type_)
Definition: nodes.h:589
@ T_IdentifySystemCmd
Definition: nodes.h:496
@ T_BaseBackupCmd
Definition: nodes.h:497
@ T_VariableShowStmt
Definition: nodes.h:359
@ T_ReadReplicationSlotCmd
Definition: nodes.h:500
@ T_DropReplicationSlotCmd
Definition: nodes.h:499
@ T_TimeLineHistoryCmd
Definition: nodes.h:502
@ T_StartReplicationCmd
Definition: nodes.h:501
@ T_CreateReplicationSlotCmd
Definition: nodes.h:498
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
const char * debug_query_string
Definition: postgres.c:90
#define InvalidOid
Definition: postgres_ext.h:36
void set_ps_display(const char *activity)
Definition: ps_status.c:349
@ REPLICATION_KIND_PHYSICAL
Definition: replnodes.h:22
void SnapBuildClearExportedSnapshot(void)
Definition: snapbuild.c:683
void initStringInfo(StringInfo str)
Definition: stringinfo.c:59
Definition: nodes.h:539
NodeTag type
Definition: nodes.h:540
ReplicationKind kind
Definition: replnodes.h:82
WalSndState state
static void SendTimeLineHistory(TimeLineHistoryCmd *cmd)
Definition: walsender.c:562
WalSnd * MyWalSnd
Definition: walsender.c:112
static void ReadReplicationSlot(ReadReplicationSlotCmd *cmd)
Definition: walsender.c:461
static StringInfoData tmpbuf
Definition: walsender.c:159
static void IdentifySystem(void)
Definition: walsender.c:377
static StringInfoData reply_message
Definition: walsender.c:158
void WalSndSetState(WalSndState state)
Definition: walsender.c:3338
static StringInfoData output_message
Definition: walsender.c:157
static volatile sig_atomic_t got_STOPPING
Definition: walsender.c:187
bool log_replication_commands
Definition: walsender.c:125
static void CreateReplicationSlot(CreateReplicationSlotCmd *cmd)
Definition: walsender.c:1030
static void StartLogicalReplication(StartReplicationCmd *cmd)
Definition: walsender.c:1240
static void DropReplicationSlot(DropReplicationSlotCmd *cmd)
Definition: walsender.c:1230
static void StartReplication(StartReplicationCmd *cmd)
Definition: walsender.c:668
static XLogReaderState * xlogreader
Definition: walsender.c:137
void replication_scanner_init(const char *query_string)
@ WALSNDSTATE_STOPPING
void replication_scanner_finish(void)
int replication_yyparse(void)
Node * replication_parse_result
void PreventInTransactionBlock(bool isTopLevel, const char *stmtType)
Definition: xact.c:3450
void StartTransactionCommand(void)
Definition: xact.c:2909
bool IsAbortedTransactionBlockState(void)
Definition: xact.c:393
void CommitTransactionCommand(void)
Definition: xact.c:3010

References ALLOCSET_DEFAULT_SIZES, AllocSetContextCreate, Assert(), CHECK_FOR_INTERRUPTS, CommitTransactionCommand(), CreateDestReceiver(), CreateReplicationSlot(), CurrentMemoryContext, DEBUG1, debug_query_string, generate_unaccent_rules::dest, DestRemoteSimple, DropReplicationSlot(), elog, EndReplicationCommand(), ereport, errcode(), errmsg(), errmsg_internal(), ERROR, GetPGVariable(), got_STOPPING, IdentifySystem(), initStringInfo(), InvalidOid, IsA, IsAbortedTransactionBlockState(), StartReplicationCmd::kind, LOG, log_replication_commands, MemoryContextDelete(), MemoryContextSwitchTo(), MyDatabaseId, MyWalSnd, VariableShowStmt::name, output_message, pgstat_report_activity(), PreventInTransactionBlock(), ReadReplicationSlot(), REPLICATION_KIND_PHYSICAL, replication_parse_result, replication_scanner_finish(), replication_scanner_init(), replication_yyparse(), reply_message, SendBaseBackup(), SendTimeLineHistory(), set_ps_display(), SnapBuildClearExportedSnapshot(), StartLogicalReplication(), StartReplication(), StartTransactionCommand(), WalSnd::state, STATE_RUNNING, T_BaseBackupCmd, T_CreateReplicationSlotCmd, T_DropReplicationSlotCmd, T_IdentifySystemCmd, T_ReadReplicationSlotCmd, T_StartReplicationCmd, T_TimeLineHistoryCmd, T_VariableShowStmt, tmpbuf, Node::type, ReadReplicationSlotCmd::type, WalSndSetState(), WALSNDSTATE_STOPPING, and xlogreader.

Referenced by PostgresMain().

◆ HandleWalSndInitStopping()

void HandleWalSndInitStopping ( void  )

Definition at line 3132 of file walsender.c.

3133 {
3135 
3136  /*
3137  * If replication has not yet started, die like with SIGTERM. If
3138  * replication is active, only set a flag and wake up the main loop. It
3139  * will send any outstanding WAL, wait for it to be replicated to the
3140  * standby, and then exit gracefully.
3141  */
3142  if (!replication_active)
3143  kill(MyProcPid, SIGTERM);
3144  else
3145  got_STOPPING = true;
3146 }
int MyProcPid
Definition: globals.c:43
bool am_walsender
Definition: walsender.c:115
static volatile sig_atomic_t replication_active
Definition: walsender.c:195
#define kill(pid, sig)
Definition: win32_port.h:464

References am_walsender, Assert(), got_STOPPING, kill, MyProcPid, and replication_active.

Referenced by procsignal_sigusr1_handler().

◆ InitWalSender()

void InitWalSender ( void  )

Referenced by PostgresMain().

◆ WalSndErrorCleanup()

void WalSndErrorCleanup ( void  )

Definition at line 297 of file walsender.c.

298 {
302 
303  if (xlogreader != NULL && xlogreader->seg.ws_file >= 0)
305 
306  if (MyReplicationSlot != NULL)
308 
310 
311  replication_active = false;
312 
313  /*
314  * If there is a transaction in progress, it will clean up our
315  * ResourceOwner, but if a replication command set up a resource owner
316  * without a transaction, we've got to clean that up now.
317  */
319  WalSndResourceCleanup(false);
320 
321  if (got_STOPPING || got_SIGUSR2)
322  proc_exit(0);
323 
324  /* Revert back to startup state */
326 }
void ConditionVariableCancelSleep(void)
void proc_exit(int code)
Definition: ipc.c:104
void LWLockReleaseAll(void)
Definition: lwlock.c:1902
void ReplicationSlotCleanup(void)
Definition: slot.c:525
ReplicationSlot * MyReplicationSlot
Definition: slot.c:96
void ReplicationSlotRelease(void)
Definition: slot.c:469
WALOpenSegment seg
Definition: xlogreader.h:225
static void pgstat_report_wait_end(void)
Definition: wait_event.h:278
static volatile sig_atomic_t got_SIGUSR2
Definition: walsender.c:186
void WalSndResourceCleanup(bool isCommit)
Definition: walsender.c:332
@ WALSNDSTATE_STARTUP
bool IsTransactionOrTransactionBlock(void)
Definition: xact.c:4772
void wal_segment_close(XLogReaderState *state)
Definition: xlogutils.c:833

References ConditionVariableCancelSleep(), got_SIGUSR2, got_STOPPING, IsTransactionOrTransactionBlock(), LWLockReleaseAll(), MyReplicationSlot, pgstat_report_wait_end(), proc_exit(), replication_active, ReplicationSlotCleanup(), ReplicationSlotRelease(), XLogReaderState::seg, wal_segment_close(), WalSndResourceCleanup(), WalSndSetState(), WALSNDSTATE_STARTUP, WALOpenSegment::ws_file, and xlogreader.

Referenced by PostgresMain().

◆ WalSndInitStopping()

void WalSndInitStopping ( void  )

Definition at line 3274 of file walsender.c.

3275 {
3276  int i;
3277 
3278  for (i = 0; i < max_wal_senders; i++)
3279  {
3280  WalSnd *walsnd = &WalSndCtl->walsnds[i];
3281  pid_t pid;
3282 
3283  SpinLockAcquire(&walsnd->mutex);
3284  pid = walsnd->pid;
3285  SpinLockRelease(&walsnd->mutex);
3286 
3287  if (pid == 0)
3288  continue;
3289 
3291  }
3292 }
#define InvalidBackendId
Definition: backendid.h:23
int i
Definition: isn.c:73
int SendProcSignal(pid_t pid, ProcSignalReason reason, BackendId backendId)
Definition: procsignal.c:261
@ PROCSIG_WALSND_INIT_STOPPING
Definition: procsignal.h:35
#define SpinLockRelease(lock)
Definition: spin.h:64
#define SpinLockAcquire(lock)
Definition: spin.h:62
WalSnd walsnds[FLEXIBLE_ARRAY_MEMBER]
slock_t mutex
int max_wal_senders
Definition: walsender.c:121
WalSndCtlData * WalSndCtl
Definition: walsender.c:109

References i, InvalidBackendId, max_wal_senders, WalSnd::mutex, WalSnd::pid, PROCSIG_WALSND_INIT_STOPPING, SendProcSignal(), SpinLockAcquire, SpinLockRelease, WalSndCtl, and WalSndCtlData::walsnds.

Referenced by ShutdownXLOG().

◆ WalSndResourceCleanup()

void WalSndResourceCleanup ( bool  isCommit)

Definition at line 332 of file walsender.c.

333 {
334  ResourceOwner resowner;
335 
336  if (CurrentResourceOwner == NULL)
337  return;
338 
339  /*
340  * Deleting CurrentResourceOwner is not allowed, so we must save a pointer
341  * in a local variable and clear it first.
342  */
343  resowner = CurrentResourceOwner;
344  CurrentResourceOwner = NULL;
345 
346  /* Now we can release resources and delete it. */
347  ResourceOwnerRelease(resowner,
348  RESOURCE_RELEASE_BEFORE_LOCKS, isCommit, true);
349  ResourceOwnerRelease(resowner,
350  RESOURCE_RELEASE_LOCKS, isCommit, true);
351  ResourceOwnerRelease(resowner,
352  RESOURCE_RELEASE_AFTER_LOCKS, isCommit, true);
353  ResourceOwnerDelete(resowner);
354 }
ResourceOwner CurrentResourceOwner
Definition: resowner.c:146
void ResourceOwnerRelease(ResourceOwner owner, ResourceReleasePhase phase, bool isCommit, bool isTopLevel)
Definition: resowner.c:486
void ResourceOwnerDelete(ResourceOwner owner)
Definition: resowner.c:737
@ RESOURCE_RELEASE_LOCKS
Definition: resowner.h:49
@ RESOURCE_RELEASE_BEFORE_LOCKS
Definition: resowner.h:48
@ RESOURCE_RELEASE_AFTER_LOCKS
Definition: resowner.h:50

References CurrentResourceOwner, RESOURCE_RELEASE_AFTER_LOCKS, RESOURCE_RELEASE_BEFORE_LOCKS, RESOURCE_RELEASE_LOCKS, ResourceOwnerDelete(), and ResourceOwnerRelease().

Referenced by perform_base_backup(), and WalSndErrorCleanup().

◆ WalSndRqstFileReload()

void WalSndRqstFileReload ( void  )

Definition at line 3109 of file walsender.c.

3110 {
3111  int i;
3112 
3113  for (i = 0; i < max_wal_senders; i++)
3114  {
3115  WalSnd *walsnd = &WalSndCtl->walsnds[i];
3116 
3117  SpinLockAcquire(&walsnd->mutex);
3118  if (walsnd->pid == 0)
3119  {
3120  SpinLockRelease(&walsnd->mutex);
3121  continue;
3122  }
3123  walsnd->needreload = true;
3124  SpinLockRelease(&walsnd->mutex);
3125  }
3126 }
bool needreload

References i, max_wal_senders, WalSnd::mutex, WalSnd::needreload, WalSnd::pid, SpinLockAcquire, SpinLockRelease, WalSndCtl, and WalSndCtlData::walsnds.

Referenced by KeepFileRestoredFromArchive().

◆ WalSndShmemInit()

void WalSndShmemInit ( void  )

Definition at line 3197 of file walsender.c.

3198 {
3199  bool found;
3200  int i;
3201 
3202  WalSndCtl = (WalSndCtlData *)
3203  ShmemInitStruct("Wal Sender Ctl", WalSndShmemSize(), &found);
3204 
3205  if (!found)
3206  {
3207  /* First time through, so initialize */
3209 
3210  for (i = 0; i < NUM_SYNC_REP_WAIT_MODE; i++)
3212 
3213  for (i = 0; i < max_wal_senders; i++)
3214  {
3215  WalSnd *walsnd = &WalSndCtl->walsnds[i];
3216 
3217  SpinLockInit(&walsnd->mutex);
3218  }
3219  }
3220 }
#define MemSet(start, val, len)
Definition: c.h:1008
void * ShmemInitStruct(const char *name, Size size, bool *foundPtr)
Definition: shmem.c:396
void SHMQueueInit(SHM_QUEUE *queue)
Definition: shmqueue.c:36
#define SpinLockInit(lock)
Definition: spin.h:60
SHM_QUEUE SyncRepQueue[NUM_SYNC_REP_WAIT_MODE]
#define NUM_SYNC_REP_WAIT_MODE
Definition: syncrep.h:28
Size WalSndShmemSize(void)
Definition: walsender.c:3185

References i, max_wal_senders, MemSet, WalSnd::mutex, NUM_SYNC_REP_WAIT_MODE, ShmemInitStruct(), SHMQueueInit(), SpinLockInit, WalSndCtlData::SyncRepQueue, WalSndCtl, WalSndCtlData::walsnds, and WalSndShmemSize().

Referenced by CreateSharedMemoryAndSemaphores().

◆ WalSndShmemSize()

Size WalSndShmemSize ( void  )

Definition at line 3185 of file walsender.c.

3186 {
3187  Size size = 0;
3188 
3189  size = offsetof(WalSndCtlData, walsnds);
3190  size = add_size(size, mul_size(max_wal_senders, sizeof(WalSnd)));
3191 
3192  return size;
3193 }
#define offsetof(type, field)
Definition: c.h:727
size_t Size
Definition: c.h:540
Size add_size(Size s1, Size s2)
Definition: shmem.c:502
Size mul_size(Size s1, Size s2)
Definition: shmem.c:519

References add_size(), max_wal_senders, mul_size(), and offsetof.

Referenced by CalculateShmemSize(), and WalSndShmemInit().

◆ WalSndSignals()

void WalSndSignals ( void  )

Definition at line 3166 of file walsender.c.

3167 {
3168  /* Set up signal handlers */
3170  pqsignal(SIGINT, StatementCancelHandler); /* query cancel */
3171  pqsignal(SIGTERM, die); /* request shutdown */
3172  /* SIGQUIT handler was already set up by InitPostmasterChild */
3173  InitializeTimeouts(); /* establishes SIGALRM handler */
3176  pqsignal(SIGUSR2, WalSndLastCycleHandler); /* request a last cycle and
3177  * shutdown */
3178 
3179  /* Reset some signals that are accepted by postmaster but not here */
3181 }
void SignalHandlerForConfigReload(SIGNAL_ARGS)
Definition: interrupt.c:56
#define die(msg)
Definition: pg_test_fsync.c:98
void StatementCancelHandler(SIGNAL_ARGS)
Definition: postgres.c:2950
void procsignal_sigusr1_handler(SIGNAL_ARGS)
Definition: procsignal.c:642
pqsigfunc pqsignal(int signum, pqsigfunc handler)
Definition: signal.c:170
void InitializeTimeouts(void)
Definition: timeout.c:461
static void WalSndLastCycleHandler(SIGNAL_ARGS)
Definition: walsender.c:3154
#define SIGCHLD
Definition: win32_port.h:177
#define SIGHUP
Definition: win32_port.h:167
#define SIG_DFL
Definition: win32_port.h:162
#define SIGPIPE
Definition: win32_port.h:172
#define SIGUSR1
Definition: win32_port.h:179
#define SIGUSR2
Definition: win32_port.h:180
#define SIG_IGN
Definition: win32_port.h:164

References die, InitializeTimeouts(), pqsignal(), procsignal_sigusr1_handler(), SIG_DFL, SIG_IGN, SIGCHLD, SIGHUP, SignalHandlerForConfigReload(), SIGPIPE, SIGUSR1, SIGUSR2, StatementCancelHandler(), and WalSndLastCycleHandler().

Referenced by PostgresMain().

◆ WalSndWaitStopping()

void WalSndWaitStopping ( void  )

Definition at line 3300 of file walsender.c.

3301 {
3302  for (;;)
3303  {
3304  int i;
3305  bool all_stopped = true;
3306 
3307  for (i = 0; i < max_wal_senders; i++)
3308  {
3309  WalSnd *walsnd = &WalSndCtl->walsnds[i];
3310 
3311  SpinLockAcquire(&walsnd->mutex);
3312 
3313  if (walsnd->pid == 0)
3314  {
3315  SpinLockRelease(&walsnd->mutex);
3316  continue;
3317  }
3318 
3319  if (walsnd->state != WALSNDSTATE_STOPPING)
3320  {
3321  all_stopped = false;
3322  SpinLockRelease(&walsnd->mutex);
3323  break;
3324  }
3325  SpinLockRelease(&walsnd->mutex);
3326  }
3327 
3328  /* safe to leave if confirmation is done for all WAL senders */
3329  if (all_stopped)
3330  return;
3331 
3332  pg_usleep(10000L); /* wait for 10 msec */
3333  }
3334 }
void pg_usleep(long microsec)
Definition: signal.c:53

References i, max_wal_senders, WalSnd::mutex, pg_usleep(), WalSnd::pid, SpinLockAcquire, SpinLockRelease, WalSnd::state, WalSndCtl, WalSndCtlData::walsnds, and WALSNDSTATE_STOPPING.

Referenced by ShutdownXLOG().

◆ WalSndWakeup()

void WalSndWakeup ( void  )

Definition at line 3229 of file walsender.c.

3230 {
3231  int i;
3232 
3233  for (i = 0; i < max_wal_senders; i++)
3234  {
3235  Latch *latch;
3236  WalSnd *walsnd = &WalSndCtl->walsnds[i];
3237 
3238  /*
3239  * Get latch pointer with spinlock held, for the unlikely case that
3240  * pointer reads aren't atomic (as they're 8 bytes).
3241  */
3242  SpinLockAcquire(&walsnd->mutex);
3243  latch = walsnd->latch;
3244  SpinLockRelease(&walsnd->mutex);
3245 
3246  if (latch != NULL)
3247  SetLatch(latch);
3248  }
3249 }
void SetLatch(Latch *latch)
Definition: latch.c:567
Definition: latch.h:111
Latch * latch

References i, WalSnd::latch, max_wal_senders, WalSnd::mutex, SetLatch(), SpinLockAcquire, SpinLockRelease, WalSndCtl, and WalSndCtlData::walsnds.

Referenced by KeepFileRestoredFromArchive(), StartupXLOG(), and XLogWalRcvFlush().

Variable Documentation

◆ am_cascading_walsender

◆ am_db_walsender

bool am_db_walsender
extern

Definition at line 118 of file walsender.c.

Referenced by check_db(), ClientAuthentication(), InitPostgres(), and ProcessStartupPacket().

◆ am_walsender

◆ log_replication_commands

bool log_replication_commands
extern

Definition at line 125 of file walsender.c.

Referenced by exec_replication_command().

◆ max_wal_senders

◆ wake_wal_senders

bool wake_wal_senders
extern

Definition at line 130 of file walsender.c.

◆ wal_sender_timeout

int wal_sender_timeout
extern