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)
 

Enumerations

enum  CRSSnapshotAction { CRS_EXPORT_SNAPSHOT , CRS_NOEXPORT_SNAPSHOT , CRS_USE_SNAPSHOT }
 

Functions

void InitWalSender (void)
 
bool exec_replication_command (const char *cmd_string)
 
void WalSndErrorCleanup (void)
 
void WalSndResourceCleanup (bool isCommit)
 
void WalSndSignals (void)
 
Size WalSndShmemSize (void)
 
void WalSndShmemInit (void)
 
void WalSndWakeup (bool physical, bool logical)
 
void WalSndInitStopping (void)
 
void WalSndWaitStopping (void)
 
void HandleWalSndInitStopping (void)
 
void WalSndRqstFileReload (void)
 
static void WalSndWakeupProcessRequests (bool physical, bool logical)
 

Variables

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

Macro Definition Documentation

◆ 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 *  cmd_string)

Definition at line 1672 of file walsender.c.

1673 {
1674  int parse_rc;
1675  Node *cmd_node;
1676  const char *cmdtag;
1677  MemoryContext cmd_context;
1678  MemoryContext old_context;
1679 
1680  /*
1681  * If WAL sender has been told that shutdown is getting close, switch its
1682  * status accordingly to handle the next replication commands correctly.
1683  */
1684  if (got_STOPPING)
1686 
1687  /*
1688  * Throw error if in stopping mode. We need prevent commands that could
1689  * generate WAL while the shutdown checkpoint is being written. To be
1690  * safe, we just prohibit all new commands.
1691  */
1693  ereport(ERROR,
1694  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
1695  errmsg("cannot execute new commands while WAL sender is in stopping mode")));
1696 
1697  /*
1698  * CREATE_REPLICATION_SLOT ... LOGICAL exports a snapshot until the next
1699  * command arrives. Clean up the old stuff if there's anything.
1700  */
1702 
1704 
1705  /*
1706  * Prepare to parse and execute the command.
1707  */
1709  "Replication command context",
1711  old_context = MemoryContextSwitchTo(cmd_context);
1712 
1713  replication_scanner_init(cmd_string);
1714 
1715  /*
1716  * Is it a WalSender command?
1717  */
1719  {
1720  /* Nope; clean up and get out. */
1722 
1723  MemoryContextSwitchTo(old_context);
1724  MemoryContextDelete(cmd_context);
1725 
1726  /* XXX this is a pretty random place to make this check */
1727  if (MyDatabaseId == InvalidOid)
1728  ereport(ERROR,
1729  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1730  errmsg("cannot execute SQL commands in WAL sender for physical replication")));
1731 
1732  /* Tell the caller that this wasn't a WalSender command. */
1733  return false;
1734  }
1735 
1736  /*
1737  * Looks like a WalSender command, so parse it.
1738  */
1739  parse_rc = replication_yyparse();
1740  if (parse_rc != 0)
1741  ereport(ERROR,
1742  (errcode(ERRCODE_SYNTAX_ERROR),
1743  errmsg_internal("replication command parser returned %d",
1744  parse_rc)));
1746 
1747  cmd_node = replication_parse_result;
1748 
1749  /*
1750  * Report query to various monitoring facilities. For this purpose, we
1751  * report replication commands just like SQL commands.
1752  */
1753  debug_query_string = cmd_string;
1754 
1756 
1757  /*
1758  * Log replication command if log_replication_commands is enabled. Even
1759  * when it's disabled, log the command with DEBUG1 level for backward
1760  * compatibility.
1761  */
1763  (errmsg("received replication command: %s", cmd_string)));
1764 
1765  /*
1766  * Disallow replication commands in aborted transaction blocks.
1767  */
1769  ereport(ERROR,
1770  (errcode(ERRCODE_IN_FAILED_SQL_TRANSACTION),
1771  errmsg("current transaction is aborted, "
1772  "commands ignored until end of transaction block")));
1773 
1775 
1776  /*
1777  * Allocate buffers that will be used for each outgoing and incoming
1778  * message. We do this just once per command to reduce palloc overhead.
1779  */
1783 
1784  switch (cmd_node->type)
1785  {
1786  case T_IdentifySystemCmd:
1787  cmdtag = "IDENTIFY_SYSTEM";
1788  set_ps_display(cmdtag);
1789  IdentifySystem();
1790  EndReplicationCommand(cmdtag);
1791  break;
1792 
1793  case T_ReadReplicationSlotCmd:
1794  cmdtag = "READ_REPLICATION_SLOT";
1795  set_ps_display(cmdtag);
1797  EndReplicationCommand(cmdtag);
1798  break;
1799 
1800  case T_BaseBackupCmd:
1801  cmdtag = "BASE_BACKUP";
1802  set_ps_display(cmdtag);
1803  PreventInTransactionBlock(true, cmdtag);
1804  SendBaseBackup((BaseBackupCmd *) cmd_node);
1805  EndReplicationCommand(cmdtag);
1806  break;
1807 
1808  case T_CreateReplicationSlotCmd:
1809  cmdtag = "CREATE_REPLICATION_SLOT";
1810  set_ps_display(cmdtag);
1812  EndReplicationCommand(cmdtag);
1813  break;
1814 
1815  case T_DropReplicationSlotCmd:
1816  cmdtag = "DROP_REPLICATION_SLOT";
1817  set_ps_display(cmdtag);
1819  EndReplicationCommand(cmdtag);
1820  break;
1821 
1822  case T_StartReplicationCmd:
1823  {
1824  StartReplicationCmd *cmd = (StartReplicationCmd *) cmd_node;
1825 
1826  cmdtag = "START_REPLICATION";
1827  set_ps_display(cmdtag);
1828  PreventInTransactionBlock(true, cmdtag);
1829 
1830  if (cmd->kind == REPLICATION_KIND_PHYSICAL)
1831  StartReplication(cmd);
1832  else
1834 
1835  /* dupe, but necessary per libpqrcv_endstreaming */
1836  EndReplicationCommand(cmdtag);
1837 
1838  Assert(xlogreader != NULL);
1839  break;
1840  }
1841 
1842  case T_TimeLineHistoryCmd:
1843  cmdtag = "TIMELINE_HISTORY";
1844  set_ps_display(cmdtag);
1845  PreventInTransactionBlock(true, cmdtag);
1847  EndReplicationCommand(cmdtag);
1848  break;
1849 
1850  case T_VariableShowStmt:
1851  {
1853  VariableShowStmt *n = (VariableShowStmt *) cmd_node;
1854 
1855  cmdtag = "SHOW";
1856  set_ps_display(cmdtag);
1857 
1858  /* syscache access needs a transaction environment */
1860  GetPGVariable(n->name, dest);
1862  EndReplicationCommand(cmdtag);
1863  }
1864  break;
1865 
1866  default:
1867  elog(ERROR, "unrecognized replication command node tag: %u",
1868  cmd_node->type);
1869  }
1870 
1871  /* done */
1872  MemoryContextSwitchTo(old_context);
1873  MemoryContextDelete(cmd_context);
1874 
1875  /*
1876  * We need not update ps display or pg_stat_activity, because PostgresMain
1877  * will reset those to "idle". But we must reset debug_query_string to
1878  * ensure it doesn't become a dangling pointer.
1879  */
1880  debug_query_string = NULL;
1881 
1882  return true;
1883 }
void pgstat_report_activity(BackendState state, const char *cmd_str)
@ STATE_RUNNING
void SendBaseBackup(BaseBackupCmd *cmd)
Definition: basebackup.c:964
void EndReplicationCommand(const char *commandTag)
Definition: dest.c:201
DestReceiver * CreateDestReceiver(CommandDest dest)
Definition: dest.c:113
@ DestRemoteSimple
Definition: dest.h:91
int errmsg_internal(const char *fmt,...)
Definition: elog.c:1156
int errcode(int sqlerrcode)
Definition: elog.c:858
int errmsg(const char *fmt,...)
Definition: elog.c:1069
#define LOG
Definition: elog.h:31
#define DEBUG1
Definition: elog.h:30
#define ERROR
Definition: elog.h:39
#define ereport(elevel,...)
Definition: elog.h:149
Oid MyDatabaseId
Definition: globals.c:89
void GetPGVariable(const char *name, DestReceiver *dest)
Definition: guc_funcs.c:382
Assert(fmt[strlen(fmt) - 1] !='\n')
MemoryContext CurrentMemoryContext
Definition: mcxt.c:135
void MemoryContextDelete(MemoryContext context)
Definition: mcxt.c:403
#define AllocSetContextCreate
Definition: memutils.h:129
#define ALLOCSET_DEFAULT_SIZES
Definition: memutils.h:153
#define CHECK_FOR_INTERRUPTS()
Definition: miscadmin.h:121
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:138
const char * debug_query_string
Definition: postgres.c:85
#define InvalidOid
Definition: postgres_ext.h:36
static void set_ps_display(const char *activity)
Definition: ps_status.h:40
@ REPLICATION_KIND_PHYSICAL
Definition: replnodes.h:22
void SnapBuildClearExportedSnapshot(void)
Definition: snapbuild.c:730
void initStringInfo(StringInfo str)
Definition: stringinfo.c:59
Definition: nodes.h:129
NodeTag type
Definition: nodes.h:130
ReplicationKind kind
Definition: replnodes.h:82
WalSndState state
static void SendTimeLineHistory(TimeLineHistoryCmd *cmd)
Definition: walsender.c:577
WalSnd * MyWalSnd
Definition: walsender.c:113
static void ReadReplicationSlot(ReadReplicationSlotCmd *cmd)
Definition: walsender.c:478
static StringInfoData tmpbuf
Definition: walsender.c:160
static void IdentifySystem(void)
Definition: walsender.c:395
static StringInfoData reply_message
Definition: walsender.c:159
void WalSndSetState(WalSndState state)
Definition: walsender.c:3470
static StringInfoData output_message
Definition: walsender.c:158
static volatile sig_atomic_t got_STOPPING
Definition: walsender.c:188
bool log_replication_commands
Definition: walsender.c:126
static void CreateReplicationSlot(CreateReplicationSlotCmd *cmd)
Definition: walsender.c:1041
static void StartLogicalReplication(StartReplicationCmd *cmd)
Definition: walsender.c:1254
static void DropReplicationSlot(DropReplicationSlotCmd *cmd)
Definition: walsender.c:1244
static void StartReplication(StartReplicationCmd *cmd)
Definition: walsender.c:670
static XLogReaderState * xlogreader
Definition: walsender.c:138
PGDLLIMPORT Node * replication_parse_result
@ WALSNDSTATE_STOPPING
void replication_scanner_finish(void)
int replication_yyparse(void)
void replication_scanner_init(const char *str)
bool replication_scanner_is_replication_command(void)
void PreventInTransactionBlock(bool isTopLevel, const char *stmtType)
Definition: xact.c:3481
void StartTransactionCommand(void)
Definition: xact.c:2937
bool IsAbortedTransactionBlockState(void)
Definition: xact.c:398
void CommitTransactionCommand(void)
Definition: xact.c:3034

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, 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_scanner_is_replication_command(), replication_yyparse(), reply_message, SendBaseBackup(), SendTimeLineHistory(), set_ps_display(), SnapBuildClearExportedSnapshot(), StartLogicalReplication(), StartReplication(), StartTransactionCommand(), WalSnd::state, STATE_RUNNING, tmpbuf, Node::type, ReadReplicationSlotCmd::type, WalSndSetState(), WALSNDSTATE_STOPPING, and xlogreader.

Referenced by PostgresMain().

◆ HandleWalSndInitStopping()

void HandleWalSndInitStopping ( void  )

Definition at line 3224 of file walsender.c.

3225 {
3227 
3228  /*
3229  * If replication has not yet started, die like with SIGTERM. If
3230  * replication is active, only set a flag and wake up the main loop. It
3231  * will send any outstanding WAL, wait for it to be replicated to the
3232  * standby, and then exit gracefully.
3233  */
3234  if (!replication_active)
3235  kill(MyProcPid, SIGTERM);
3236  else
3237  got_STOPPING = true;
3238 }
int MyProcPid
Definition: globals.c:44
bool am_walsender
Definition: walsender.c:116
static volatile sig_atomic_t replication_active
Definition: walsender.c:196
#define kill(pid, sig)
Definition: win32_port.h:485

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 315 of file walsender.c.

316 {
320 
321  if (xlogreader != NULL && xlogreader->seg.ws_file >= 0)
323 
324  if (MyReplicationSlot != NULL)
326 
328 
329  replication_active = false;
330 
331  /*
332  * If there is a transaction in progress, it will clean up our
333  * ResourceOwner, but if a replication command set up a resource owner
334  * without a transaction, we've got to clean that up now.
335  */
337  WalSndResourceCleanup(false);
338 
339  if (got_STOPPING || got_SIGUSR2)
340  proc_exit(0);
341 
342  /* Revert back to startup state */
344 }
bool ConditionVariableCancelSleep(void)
void proc_exit(int code)
Definition: ipc.c:104
void LWLockReleaseAll(void)
Definition: lwlock.c:1903
void ReplicationSlotCleanup(void)
Definition: slot.c:605
ReplicationSlot * MyReplicationSlot
Definition: slot.c:99
void ReplicationSlotRelease(void)
Definition: slot.c:549
WALOpenSegment seg
Definition: xlogreader.h:272
static void pgstat_report_wait_end(void)
Definition: wait_event.h:104
static volatile sig_atomic_t got_SIGUSR2
Definition: walsender.c:187
void WalSndResourceCleanup(bool isCommit)
Definition: walsender.c:350
@ WALSNDSTATE_STARTUP
bool IsTransactionOrTransactionBlock(void)
Definition: xact.c:4834
void wal_segment_close(XLogReaderState *state)
Definition: xlogutils.c:844

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 3406 of file walsender.c.

3407 {
3408  int i;
3409 
3410  for (i = 0; i < max_wal_senders; i++)
3411  {
3412  WalSnd *walsnd = &WalSndCtl->walsnds[i];
3413  pid_t pid;
3414 
3415  SpinLockAcquire(&walsnd->mutex);
3416  pid = walsnd->pid;
3417  SpinLockRelease(&walsnd->mutex);
3418 
3419  if (pid == 0)
3420  continue;
3421 
3423  }
3424 }
#define InvalidBackendId
Definition: backendid.h:23
int i
Definition: isn.c:73
int SendProcSignal(pid_t pid, ProcSignalReason reason, BackendId backendId)
Definition: procsignal.c:262
@ 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:122
WalSndCtlData * WalSndCtl
Definition: walsender.c:110

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 350 of file walsender.c.

351 {
352  ResourceOwner resowner;
353 
354  if (CurrentResourceOwner == NULL)
355  return;
356 
357  /*
358  * Deleting CurrentResourceOwner is not allowed, so we must save a pointer
359  * in a local variable and clear it first.
360  */
361  resowner = CurrentResourceOwner;
362  CurrentResourceOwner = NULL;
363 
364  /* Now we can release resources and delete it. */
365  ResourceOwnerRelease(resowner,
366  RESOURCE_RELEASE_BEFORE_LOCKS, isCommit, true);
367  ResourceOwnerRelease(resowner,
368  RESOURCE_RELEASE_LOCKS, isCommit, true);
369  ResourceOwnerRelease(resowner,
370  RESOURCE_RELEASE_AFTER_LOCKS, isCommit, true);
371  ResourceOwnerDelete(resowner);
372 }
ResourceOwner CurrentResourceOwner
Definition: resowner.c:147
void ResourceOwnerRelease(ResourceOwner owner, ResourceReleasePhase phase, bool isCommit, bool isTopLevel)
Definition: resowner.c:488
void ResourceOwnerDelete(ResourceOwner owner)
Definition: resowner.c:762
@ 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 3201 of file walsender.c.

3202 {
3203  int i;
3204 
3205  for (i = 0; i < max_wal_senders; i++)
3206  {
3207  WalSnd *walsnd = &WalSndCtl->walsnds[i];
3208 
3209  SpinLockAcquire(&walsnd->mutex);
3210  if (walsnd->pid == 0)
3211  {
3212  SpinLockRelease(&walsnd->mutex);
3213  continue;
3214  }
3215  walsnd->needreload = true;
3216  SpinLockRelease(&walsnd->mutex);
3217  }
3218 }
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 3289 of file walsender.c.

3290 {
3291  bool found;
3292  int i;
3293 
3294  WalSndCtl = (WalSndCtlData *)
3295  ShmemInitStruct("Wal Sender Ctl", WalSndShmemSize(), &found);
3296 
3297  if (!found)
3298  {
3299  /* First time through, so initialize */
3301 
3302  for (i = 0; i < NUM_SYNC_REP_WAIT_MODE; i++)
3304 
3305  for (i = 0; i < max_wal_senders; i++)
3306  {
3307  WalSnd *walsnd = &WalSndCtl->walsnds[i];
3308 
3309  SpinLockInit(&walsnd->mutex);
3310  }
3311 
3314  }
3315 }
#define MemSet(start, val, len)
Definition: c.h:1009
void ConditionVariableInit(ConditionVariable *cv)
static void dlist_init(dlist_head *head)
Definition: ilist.h:314
void * ShmemInitStruct(const char *name, Size size, bool *foundPtr)
Definition: shmem.c:396
#define SpinLockInit(lock)
Definition: spin.h:60
ConditionVariable wal_replay_cv
dlist_head SyncRepQueue[NUM_SYNC_REP_WAIT_MODE]
ConditionVariable wal_flush_cv
#define NUM_SYNC_REP_WAIT_MODE
Definition: syncrep.h:27
Size WalSndShmemSize(void)
Definition: walsender.c:3277

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

Referenced by CreateSharedMemoryAndSemaphores().

◆ WalSndShmemSize()

Size WalSndShmemSize ( void  )

Definition at line 3277 of file walsender.c.

3278 {
3279  Size size = 0;
3280 
3281  size = offsetof(WalSndCtlData, walsnds);
3282  size = add_size(size, mul_size(max_wal_senders, sizeof(WalSnd)));
3283 
3284  return size;
3285 }
size_t Size
Definition: c.h:594
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, and mul_size().

Referenced by CalculateShmemSize(), and WalSndShmemInit().

◆ WalSndSignals()

void WalSndSignals ( void  )

Definition at line 3258 of file walsender.c.

3259 {
3260  /* Set up signal handlers */
3262  pqsignal(SIGINT, StatementCancelHandler); /* query cancel */
3263  pqsignal(SIGTERM, die); /* request shutdown */
3264  /* SIGQUIT handler was already set up by InitPostmasterChild */
3265  InitializeTimeouts(); /* establishes SIGALRM handler */
3268  pqsignal(SIGUSR2, WalSndLastCycleHandler); /* request a last cycle and
3269  * shutdown */
3270 
3271  /* Reset some signals that are accepted by postmaster but not here */
3273 }
void SignalHandlerForConfigReload(SIGNAL_ARGS)
Definition: interrupt.c:61
#define die(msg)
Definition: pg_test_fsync.c:95
pqsigfunc pqsignal(int signo, pqsigfunc func)
void StatementCancelHandler(SIGNAL_ARGS)
Definition: postgres.c:3008
void procsignal_sigusr1_handler(SIGNAL_ARGS)
Definition: procsignal.c:639
void InitializeTimeouts(void)
Definition: timeout.c:474
static void WalSndLastCycleHandler(SIGNAL_ARGS)
Definition: walsender.c:3246
#define SIGCHLD
Definition: win32_port.h:178
#define SIGHUP
Definition: win32_port.h:168
#define SIG_DFL
Definition: win32_port.h:163
#define SIGPIPE
Definition: win32_port.h:173
#define SIGUSR1
Definition: win32_port.h:180
#define SIGUSR2
Definition: win32_port.h:181
#define SIG_IGN
Definition: win32_port.h:165

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 3432 of file walsender.c.

3433 {
3434  for (;;)
3435  {
3436  int i;
3437  bool all_stopped = true;
3438 
3439  for (i = 0; i < max_wal_senders; i++)
3440  {
3441  WalSnd *walsnd = &WalSndCtl->walsnds[i];
3442 
3443  SpinLockAcquire(&walsnd->mutex);
3444 
3445  if (walsnd->pid == 0)
3446  {
3447  SpinLockRelease(&walsnd->mutex);
3448  continue;
3449  }
3450 
3451  if (walsnd->state != WALSNDSTATE_STOPPING)
3452  {
3453  all_stopped = false;
3454  SpinLockRelease(&walsnd->mutex);
3455  break;
3456  }
3457  SpinLockRelease(&walsnd->mutex);
3458  }
3459 
3460  /* safe to leave if confirmation is done for all WAL senders */
3461  if (all_stopped)
3462  return;
3463 
3464  pg_usleep(10000L); /* wait for 10 msec */
3465  }
3466 }
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 ( bool  physical,
bool  logical 
)

Definition at line 3333 of file walsender.c.

3334 {
3335  /*
3336  * Wake up all the walsenders waiting on WAL being flushed or replayed
3337  * respectively. Note that waiting walsender would have prepared to sleep
3338  * on the CV (i.e., added itself to the CV's waitlist) in WalSndWait()
3339  * before actually waiting.
3340  */
3341  if (physical)
3343 
3344  if (logical)
3346 }
void ConditionVariableBroadcast(ConditionVariable *cv)

References ConditionVariableBroadcast(), WalSndCtlData::wal_flush_cv, WalSndCtlData::wal_replay_cv, and WalSndCtl.

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

◆ WalSndWakeupProcessRequests()

static void WalSndWakeupProcessRequests ( bool  physical,
bool  logical 
)
inlinestatic

Definition at line 64 of file walsender.h.

65 {
66  if (wake_wal_senders)
67  {
68  wake_wal_senders = false;
69  if (max_wal_senders > 0)
70  WalSndWakeup(physical, logical);
71  }
72 }
PGDLLIMPORT bool wake_wal_senders
Definition: walsender.c:131
void WalSndWakeup(bool physical, bool logical)
Definition: walsender.c:3333
PGDLLIMPORT int max_wal_senders
Definition: walsender.c:122

References max_wal_senders, wake_wal_senders, and WalSndWakeup().

Referenced by XLogBackgroundFlush(), and XLogFlush().

Variable Documentation

◆ am_cascading_walsender

◆ am_db_walsender

PGDLLIMPORT bool am_db_walsender
extern

Definition at line 119 of file walsender.c.

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

◆ am_walsender

◆ log_replication_commands

PGDLLIMPORT bool log_replication_commands
extern

Definition at line 126 of file walsender.c.

Referenced by exec_replication_command().

◆ max_wal_senders

◆ wake_wal_senders

PGDLLIMPORT bool wake_wal_senders
extern

Definition at line 131 of file walsender.c.

Referenced by WalSndWakeupProcessRequests().

◆ wal_sender_timeout