PostgreSQL Source Code git master
Loading...
Searching...
No Matches
walsender.h File Reference
#include "access/xlogdefs.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 PhysicalWakeupLogicalWalSnd (void)
 
XLogRecPtr GetStandbyFlushRecPtr (TimeLineID *tli)
 
void WalSndSignals (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 int wal_sender_shutdown_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.

58 { wake_wal_senders = true; } while (0)
PGDLLIMPORT bool wake_wal_senders
Definition walsender.c:155

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)
extern

Definition at line 2103 of file walsender.c.

2104{
2105 yyscan_t scanner;
2106 int parse_rc;
2107 Node *cmd_node;
2108 const char *cmdtag;
2110
2111 /* We save and re-use the cmd_context across calls */
2113
2114 /*
2115 * If WAL sender has been told that shutdown is getting close, switch its
2116 * status accordingly to handle the next replication commands correctly.
2117 */
2118 if (got_STOPPING)
2120
2121 /*
2122 * Throw error if in stopping mode. We need prevent commands that could
2123 * generate WAL while the shutdown checkpoint is being written. To be
2124 * safe, we just prohibit all new commands.
2125 */
2127 ereport(ERROR,
2129 errmsg("cannot execute new commands while WAL sender is in stopping mode")));
2130
2131 /*
2132 * CREATE_REPLICATION_SLOT ... LOGICAL exports a snapshot until the next
2133 * command arrives. Clean up the old stuff if there's anything.
2134 */
2136
2138
2139 /*
2140 * Prepare to parse and execute the command.
2141 *
2142 * Because replication command execution can involve beginning or ending
2143 * transactions, we need a working context that will survive that, so we
2144 * make it a child of TopMemoryContext. That in turn creates a hazard of
2145 * long-lived memory leaks if we lose track of the working context. We
2146 * deal with that by creating it only once per walsender, and resetting it
2147 * for each new command. (Normally this reset is a no-op, but if the
2148 * prior exec_replication_command call failed with an error, it won't be.)
2149 *
2150 * This is subtler than it looks. The transactions we manage can extend
2151 * across replication commands, indeed SnapBuildClearExportedSnapshot
2152 * might have just ended one. Because transaction exit will revert to the
2153 * memory context that was current at transaction start, we need to be
2154 * sure that that context is still valid. That motivates re-using the
2155 * same cmd_context rather than making a new one each time.
2156 */
2157 if (cmd_context == NULL)
2159 "Replication command context",
2161 else
2163
2165
2167
2168 /*
2169 * Is it a WalSender command?
2170 */
2172 {
2173 /* Nope; clean up and get out. */
2175
2178
2179 /* XXX this is a pretty random place to make this check */
2180 if (MyDatabaseId == InvalidOid)
2181 ereport(ERROR,
2183 errmsg("cannot execute SQL commands in WAL sender for physical replication")));
2184
2185 /* Tell the caller that this wasn't a WalSender command. */
2186 return false;
2187 }
2188
2189 /*
2190 * Looks like a WalSender command, so parse it.
2191 */
2193 if (parse_rc != 0)
2194 ereport(ERROR,
2196 errmsg_internal("replication command parser returned %d",
2197 parse_rc)));
2199
2200 /*
2201 * Report query to various monitoring facilities. For this purpose, we
2202 * report replication commands just like SQL commands.
2203 */
2205
2207
2208 /*
2209 * Log replication command if log_replication_commands is enabled. Even
2210 * when it's disabled, log the command with DEBUG1 level for backward
2211 * compatibility.
2212 */
2214 (errmsg("received replication command: %s", cmd_string)));
2215
2216 /*
2217 * Disallow replication commands in aborted transaction blocks.
2218 */
2220 ereport(ERROR,
2222 errmsg("current transaction is aborted, "
2223 "commands ignored until end of transaction block")));
2224
2226
2227 /*
2228 * Allocate buffers that will be used for each outgoing and incoming
2229 * message. We do this just once per command to reduce palloc overhead.
2230 */
2234
2235 switch (cmd_node->type)
2236 {
2238 cmdtag = "IDENTIFY_SYSTEM";
2242 break;
2243
2245 cmdtag = "READ_REPLICATION_SLOT";
2249 break;
2250
2251 case T_BaseBackupCmd:
2252 cmdtag = "BASE_BACKUP";
2257 break;
2258
2260 cmdtag = "CREATE_REPLICATION_SLOT";
2264 break;
2265
2267 cmdtag = "DROP_REPLICATION_SLOT";
2271 break;
2272
2274 cmdtag = "ALTER_REPLICATION_SLOT";
2278 break;
2279
2281 {
2283
2284 cmdtag = "START_REPLICATION";
2287
2288 if (cmd->kind == REPLICATION_KIND_PHYSICAL)
2289 StartReplication(cmd);
2290 else
2292
2293 /* dupe, but necessary per libpqrcv_endstreaming */
2295
2297 break;
2298 }
2299
2301 cmdtag = "TIMELINE_HISTORY";
2306 break;
2307
2308 case T_VariableShowStmt:
2309 {
2312
2313 cmdtag = "SHOW";
2315
2316 /* syscache access needs a transaction environment */
2318 GetPGVariable(n->name, dest);
2321 }
2322 break;
2323
2325 cmdtag = "UPLOAD_MANIFEST";
2330 break;
2331
2332 default:
2333 elog(ERROR, "unrecognized replication command node tag: %u",
2334 cmd_node->type);
2335 }
2336
2337 /*
2338 * Done. Revert to caller's memory context, and clean out the cmd_context
2339 * to recover memory right away.
2340 */
2343
2344 /*
2345 * We need not update ps display or pg_stat_activity, because PostgresMain
2346 * will reset those to "idle". But we must reset debug_query_string to
2347 * ensure it doesn't become a dangling pointer.
2348 */
2350
2351 return true;
2352}
void pgstat_report_activity(BackendState state, const char *cmd_str)
@ STATE_RUNNING
void SendBaseBackup(BaseBackupCmd *cmd, IncrementalBackupInfo *ib)
Definition basebackup.c:990
#define Assert(condition)
Definition c.h:1002
void * yyscan_t
Definition cubedata.h:65
DestReceiver * CreateDestReceiver(CommandDest dest)
Definition dest.c:113
void EndReplicationCommand(const char *commandTag)
Definition dest.c:217
@ DestRemoteSimple
Definition dest.h:91
int errcode(int sqlerrcode)
Definition elog.c:875
#define LOG
Definition elog.h:32
int int errmsg_internal(const char *fmt,...) pg_attribute_printf(1
#define DEBUG1
Definition elog.h:31
#define ERROR
Definition elog.h:40
#define elog(elevel,...)
Definition elog.h:228
#define ereport(elevel,...)
Definition elog.h:152
Oid MyDatabaseId
Definition globals.c:96
void GetPGVariable(const char *name, DestReceiver *dest)
Definition guc_funcs.c:410
void MemoryContextReset(MemoryContext context)
Definition mcxt.c:406
MemoryContext TopMemoryContext
Definition mcxt.c:167
MemoryContext CurrentMemoryContext
Definition mcxt.c:161
#define AllocSetContextCreate
Definition memutils.h:129
#define ALLOCSET_DEFAULT_SIZES
Definition memutils.h:160
#define CHECK_FOR_INTERRUPTS()
Definition miscadmin.h:125
static char * errmsg
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition palloc.h:138
const char * debug_query_string
Definition postgres.c:94
#define InvalidOid
static int fb(int x)
static void set_ps_display(const char *activity)
Definition ps_status.h:40
bool replication_scanner_is_replication_command(yyscan_t yyscanner)
void replication_scanner_finish(yyscan_t yyscanner)
void replication_scanner_init(const char *str, yyscan_t *yyscannerp)
@ REPLICATION_KIND_PHYSICAL
Definition replnodes.h:22
void SnapBuildClearExportedSnapshot(void)
Definition snapbuild.c:603
void initStringInfo(StringInfo str)
Definition stringinfo.c:97
Definition nodes.h:133
ReplicationKind kind
Definition replnodes.h:94
WalSndState state
static void AlterReplicationSlot(AlterReplicationSlotCmd *cmd)
Definition walsender.c:1488
static void SendTimeLineHistory(TimeLineHistoryCmd *cmd)
Definition walsender.c:611
WalSnd * MyWalSnd
Definition walsender.c:132
static void ReadReplicationSlot(ReadReplicationSlotCmd *cmd)
Definition walsender.c:511
static StringInfoData tmpbuf
Definition walsender.c:195
static void IdentifySystem(void)
Definition walsender.c:429
static StringInfoData reply_message
Definition walsender.c:194
void WalSndSetState(WalSndState state)
Definition walsender.c:4193
static StringInfoData output_message
Definition walsender.c:193
static void UploadManifest(void)
Definition walsender.c:718
static volatile sig_atomic_t got_STOPPING
Definition walsender.c:233
bool log_replication_commands
Definition walsender.c:150
static void CreateReplicationSlot(CreateReplicationSlotCmd *cmd)
Definition walsender.c:1265
static void StartLogicalReplication(StartReplicationCmd *cmd)
Definition walsender.c:1530
static IncrementalBackupInfo * uploaded_manifest
Definition walsender.c:172
static void DropReplicationSlot(DropReplicationSlotCmd *cmd)
Definition walsender.c:1479
static void StartReplication(StartReplicationCmd *cmd)
Definition walsender.c:860
static XLogReaderState * xlogreader
Definition walsender.c:162
@ WALSNDSTATE_STOPPING
int replication_yyparse(Node **replication_parse_result_p, yyscan_t yyscanner)
void PreventInTransactionBlock(bool isTopLevel, const char *stmtType)
Definition xact.c:3701
void StartTransactionCommand(void)
Definition xact.c:3112
bool IsAbortedTransactionBlockState(void)
Definition xact.c:409
void CommitTransactionCommand(void)
Definition xact.c:3210

References ALLOCSET_DEFAULT_SIZES, AllocSetContextCreate, AlterReplicationSlot(), Assert, CHECK_FOR_INTERRUPTS, CommitTransactionCommand(), CreateDestReceiver(), CreateReplicationSlot(), CurrentMemoryContext, DEBUG1, debug_query_string, DestRemoteSimple, DropReplicationSlot(), elog, EndReplicationCommand(), ereport, errcode(), errmsg, errmsg_internal(), ERROR, fb(), GetPGVariable(), got_STOPPING, IdentifySystem(), initStringInfo(), InvalidOid, IsAbortedTransactionBlockState(), StartReplicationCmd::kind, LOG, log_replication_commands, MemoryContextReset(), MemoryContextSwitchTo(), MyDatabaseId, MyWalSnd, VariableShowStmt::name, output_message, pgstat_report_activity(), PreventInTransactionBlock(), ReadReplicationSlot(), REPLICATION_KIND_PHYSICAL, 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, TopMemoryContext, uploaded_manifest, UploadManifest(), WalSndSetState(), WALSNDSTATE_STOPPING, and xlogreader.

Referenced by PostgresMain().

◆ GetStandbyFlushRecPtr()

XLogRecPtr GetStandbyFlushRecPtr ( TimeLineID tli)
extern

Definition at line 3896 of file walsender.c.

3897{
3899 TimeLineID replayTLI;
3903
3905
3906 /*
3907 * We can safely send what's already been replayed. Also, if walreceiver
3908 * is streaming WAL from the same timeline, we can send anything that it
3909 * has streamed, but hasn't been replayed yet.
3910 */
3911
3913 replayPtr = GetXLogReplayRecPtr(&replayTLI);
3914
3915 if (tli)
3916 *tli = replayTLI;
3917
3918 result = replayPtr;
3919 if (receiveTLI == replayTLI && receivePtr > replayPtr)
3921
3922 return result;
3923}
uint32 result
bool IsSyncingReplicationSlots(void)
Definition slotsync.c:1928
XLogRecPtr GetWalRcvFlushRecPtr(XLogRecPtr *latestChunkStart, TimeLineID *receiveTLI)
bool am_cascading_walsender
Definition walsender.c:136
uint64 XLogRecPtr
Definition xlogdefs.h:21
uint32 TimeLineID
Definition xlogdefs.h:63
static TimeLineID receiveTLI
XLogRecPtr GetXLogReplayRecPtr(TimeLineID *replayTLI)

References am_cascading_walsender, Assert, fb(), GetWalRcvFlushRecPtr(), GetXLogReplayRecPtr(), IsSyncingReplicationSlots(), receiveTLI, and result.

Referenced by IdentifySystem(), StartReplication(), update_local_synced_slot(), and XLogSendPhysical().

◆ HandleWalSndInitStopping()

void HandleWalSndInitStopping ( void  )
extern

Definition at line 3952 of file walsender.c.

3953{
3955
3956 /*
3957 * If replication has not yet started, die like with SIGTERM. If
3958 * replication is active, only set a flag and wake up the main loop. It
3959 * will send any outstanding WAL, wait for it to be replicated to the
3960 * standby, and then exit gracefully.
3961 */
3962 if (!replication_active)
3964 else
3965 got_STOPPING = true;
3966
3967 /* latch will be set by procsignal_sigusr1_handler */
3968}
int MyProcPid
Definition globals.c:49
bool am_walsender
Definition walsender.c:135
static volatile sig_atomic_t replication_active
Definition walsender.c:241
#define kill(pid, sig)
Definition win32_port.h:507

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

Referenced by procsignal_sigusr1_handler().

◆ InitWalSender()

void InitWalSender ( void  )
extern

Definition at line 330 of file walsender.c.

331{
333
334 /* Create a per-walsender data structure in shared memory */
336
337 /* need resource owner for e.g. basebackups */
339
340 /*
341 * Let postmaster know that we're a WAL sender. Once we've declared us as
342 * a WAL sender process, postmaster will let us outlive the bgwriter and
343 * kill us last in the shutdown sequence, so we get a chance to stream all
344 * remaining WAL at shutdown, including the shutdown checkpoint. Note that
345 * there's no going back, and we mustn't write any WAL records after this.
346 */
349
350 /*
351 * If the client didn't specify a database to connect to, show in PGPROC
352 * that our advertised xmin should affect vacuum horizons in all
353 * databases. This allows physical replication clients to send hot
354 * standby feedback that will delay vacuum cleanup in all databases.
355 */
357 {
363 }
364
365 /* Initialize empty timestamp buffer for lag tracking. */
367}
bool LWLockAcquire(LWLock *lock, LWLockMode mode)
Definition lwlock.c:1150
void LWLockRelease(LWLock *lock)
Definition lwlock.c:1767
@ LW_EXCLUSIVE
Definition lwlock.h:104
void * MemoryContextAllocZero(MemoryContext context, Size size)
Definition mcxt.c:1269
void SendPostmasterSignal(PMSignalReason reason)
Definition pmsignal.c:164
void MarkPostmasterChildWalSender(void)
Definition pmsignal.c:308
@ PMSIGNAL_ADVANCE_STATE_MACHINE
Definition pmsignal.h:44
#define PROC_AFFECTS_ALL_HORIZONS
Definition proc.h:66
void CreateAuxProcessResourceOwner(void)
Definition resowner.c:1006
PGPROC * MyProc
Definition proc.c:71
PROC_HDR * ProcGlobal
Definition proc.c:74
TransactionId xmin
Definition proc.h:242
uint8 statusFlags
Definition proc.h:210
int pgxactoff
Definition proc.h:207
uint8 * statusFlags
Definition proc.h:456
#define InvalidTransactionId
Definition transam.h:31
static void InitWalSenderSlot(void)
Definition walsender.c:3190
static LagTracker * lag_tracker
Definition walsender.c:279
bool RecoveryInProgress(void)
Definition xlog.c:6835

References am_cascading_walsender, Assert, CreateAuxProcessResourceOwner(), fb(), InitWalSenderSlot(), InvalidOid, InvalidTransactionId, lag_tracker, LW_EXCLUSIVE, LWLockAcquire(), LWLockRelease(), MarkPostmasterChildWalSender(), MemoryContextAllocZero(), MyDatabaseId, MyProc, PGPROC::pgxactoff, PMSIGNAL_ADVANCE_STATE_MACHINE, PROC_AFFECTS_ALL_HORIZONS, ProcGlobal, RecoveryInProgress(), SendPostmasterSignal(), PGPROC::statusFlags, PROC_HDR::statusFlags, TopMemoryContext, and PGPROC::xmin.

Referenced by PostgresMain().

◆ PhysicalWakeupLogicalWalSnd()

void PhysicalWakeupLogicalWalSnd ( void  )
extern

Definition at line 1839 of file walsender.c.

1840{
1842
1843 /*
1844 * If we are running in a standby, there is no need to wake up walsenders.
1845 * This is because we do not support syncing slots to cascading standbys,
1846 * so, there are no walsenders waiting for standbys to catch up.
1847 */
1848 if (RecoveryInProgress())
1849 return;
1850
1853}
#define NameStr(name)
Definition c.h:894
void ConditionVariableBroadcast(ConditionVariable *cv)
ReplicationSlot * MyReplicationSlot
Definition slot.c:158
bool SlotExistsInSyncStandbySlots(const char *slot_name)
Definition slot.c:3076
#define SlotIsPhysical(slot)
Definition slot.h:287
ReplicationSlotPersistentData data
Definition slot.h:213
ConditionVariable wal_confirm_rcv_cv
WalSndCtlData * WalSndCtl
Definition walsender.c:121

References Assert, ConditionVariableBroadcast(), ReplicationSlot::data, MyReplicationSlot, ReplicationSlotPersistentData::name, NameStr, RecoveryInProgress(), SlotExistsInSyncStandbySlots(), SlotIsPhysical, WalSndCtlData::wal_confirm_rcv_cv, and WalSndCtl.

Referenced by pg_physical_replication_slot_advance(), and PhysicalConfirmReceivedLocation().

◆ WalSndErrorCleanup()

void WalSndErrorCleanup ( void  )
extern

Definition at line 377 of file walsender.c.

378{
383
384 if (xlogreader != NULL && xlogreader->seg.ws_file >= 0)
386
387 if (MyReplicationSlot != NULL)
389
391
392 replication_active = false;
393
394 /*
395 * If there is a transaction in progress, it will clean up our
396 * ResourceOwner, but if a replication command set up a resource owner
397 * without a transaction, we've got to clean that up now.
398 */
401
403 proc_exit(0);
404
405 /* Revert back to startup state */
407}
void pgaio_error_cleanup(void)
Definition aio.c:1175
bool ConditionVariableCancelSleep(void)
void proc_exit(int code)
Definition ipc.c:105
void LWLockReleaseAll(void)
Definition lwlock.c:1866
void ReleaseAuxProcessResources(bool isCommit)
Definition resowner.c:1026
void ReplicationSlotRelease(void)
Definition slot.c:769
void ReplicationSlotCleanup(bool synced_only)
Definition slot.c:861
WALOpenSegment seg
Definition xlogreader.h:271
static void pgstat_report_wait_end(void)
Definition wait_event.h:83
static volatile sig_atomic_t got_SIGUSR2
Definition walsender.c:232
@ WALSNDSTATE_STARTUP
bool IsTransactionOrTransactionBlock(void)
Definition xact.c:5043
void wal_segment_close(XLogReaderState *state)
Definition xlogutils.c:855

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

Referenced by PostgresMain().

◆ WalSndInitStopping()

void WalSndInitStopping ( void  )
extern

Definition at line 4129 of file walsender.c.

4130{
4131 int i;
4132
4133 for (i = 0; i < max_wal_senders; i++)
4134 {
4136 pid_t pid;
4137
4138 SpinLockAcquire(&walsnd->mutex);
4139 pid = walsnd->pid;
4140 SpinLockRelease(&walsnd->mutex);
4141
4142 if (pid == 0)
4143 continue;
4144
4146 }
4147}
int i
Definition isn.c:77
#define INVALID_PROC_NUMBER
Definition procnumber.h:26
int SendProcSignal(pid_t pid, ProcSignalReason reason, ProcNumber procNumber)
Definition procsignal.c:296
@ PROCSIG_WALSND_INIT_STOPPING
Definition procsignal.h:35
static void SpinLockRelease(volatile slock_t *lock)
Definition spin.h:62
static void SpinLockAcquire(volatile slock_t *lock)
Definition spin.h:56
WalSnd walsnds[FLEXIBLE_ARRAY_MEMBER]
int max_wal_senders
Definition walsender.c:141

References fb(), i, INVALID_PROC_NUMBER, max_wal_senders, PROCSIG_WALSND_INIT_STOPPING, SendProcSignal(), SpinLockAcquire(), SpinLockRelease(), WalSndCtl, and WalSndCtlData::walsnds.

Referenced by ShutdownXLOG().

◆ WalSndRqstFileReload()

void WalSndRqstFileReload ( void  )
extern

Definition at line 3929 of file walsender.c.

3930{
3931 int i;
3932
3933 for (i = 0; i < max_wal_senders; i++)
3934 {
3936
3937 SpinLockAcquire(&walsnd->mutex);
3938 if (walsnd->pid == 0)
3939 {
3940 SpinLockRelease(&walsnd->mutex);
3941 continue;
3942 }
3943 walsnd->needreload = true;
3944 SpinLockRelease(&walsnd->mutex);
3945 }
3946}

References fb(), i, max_wal_senders, SpinLockAcquire(), SpinLockRelease(), WalSndCtl, and WalSndCtlData::walsnds.

Referenced by KeepFileRestoredFromArchive().

◆ WalSndSignals()

void WalSndSignals ( void  )
extern

Definition at line 3984 of file walsender.c.

3985{
3986 /* Set up signal handlers */
3988 pqsignal(SIGINT, StatementCancelHandler); /* query cancel */
3989 pqsignal(SIGTERM, die); /* request shutdown */
3990 /* SIGQUIT handler was already set up by InitPostmasterChild */
3991 InitializeTimeouts(); /* establishes SIGALRM handler */
3994 pqsignal(SIGUSR2, WalSndLastCycleHandler); /* request a last cycle and
3995 * shutdown */
3996
3997 /* Reset some signals that are accepted by postmaster but not here */
3999}
void SignalHandlerForConfigReload(SIGNAL_ARGS)
Definition interrupt.c:61
#define die(msg)
#define pqsignal
Definition port.h:548
#define PG_SIG_IGN
Definition port.h:552
#define PG_SIG_DFL
Definition port.h:551
void StatementCancelHandler(SIGNAL_ARGS)
Definition postgres.c:3155
void procsignal_sigusr1_handler(SIGNAL_ARGS)
Definition procsignal.c:696
void InitializeTimeouts(void)
Definition timeout.c:470
static void WalSndLastCycleHandler(SIGNAL_ARGS)
Definition walsender.c:3976
#define SIGCHLD
Definition win32_port.h:168
#define SIGHUP
Definition win32_port.h:158
#define SIGPIPE
Definition win32_port.h:163
#define SIGUSR1
Definition win32_port.h:170
#define SIGUSR2
Definition win32_port.h:171

References die, fb(), InitializeTimeouts(), PG_SIG_DFL, PG_SIG_IGN, pqsignal, procsignal_sigusr1_handler(), SIGCHLD, SIGHUP, SignalHandlerForConfigReload(), SIGPIPE, SIGUSR1, SIGUSR2, StatementCancelHandler(), and WalSndLastCycleHandler().

Referenced by PostgresMain().

◆ WalSndWaitStopping()

void WalSndWaitStopping ( void  )
extern

Definition at line 4155 of file walsender.c.

4156{
4157 for (;;)
4158 {
4159 int i;
4160 bool all_stopped = true;
4161
4162 for (i = 0; i < max_wal_senders; i++)
4163 {
4165
4166 SpinLockAcquire(&walsnd->mutex);
4167
4168 if (walsnd->pid == 0)
4169 {
4170 SpinLockRelease(&walsnd->mutex);
4171 continue;
4172 }
4173
4174 if (walsnd->state != WALSNDSTATE_STOPPING)
4175 {
4176 all_stopped = false;
4177 SpinLockRelease(&walsnd->mutex);
4178 break;
4179 }
4180 SpinLockRelease(&walsnd->mutex);
4181 }
4182
4183 /* safe to leave if confirmation is done for all WAL senders */
4184 if (all_stopped)
4185 return;
4186
4187 pg_usleep(10000L); /* wait for 10 msec */
4188 }
4189}
void pg_usleep(long microsec)
Definition signal.c:53

References fb(), i, max_wal_senders, pg_usleep(), SpinLockAcquire(), SpinLockRelease(), WalSndCtl, WalSndCtlData::walsnds, and WALSNDSTATE_STOPPING.

Referenced by ShutdownXLOG().

◆ WalSndWakeup()

void WalSndWakeup ( bool  physical,
bool  logical 
)
extern

Definition at line 4050 of file walsender.c.

4051{
4052 /*
4053 * Wake up all the walsenders waiting on WAL being flushed or replayed
4054 * respectively. Note that waiting walsender would have prepared to sleep
4055 * on the CV (i.e., added itself to the CV's waitlist) in WalSndWait()
4056 * before actually waiting.
4057 */
4058 if (physical)
4060
4061 if (logical)
4063}
ConditionVariable wal_replay_cv
ConditionVariable wal_flush_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{
67 {
68 wake_wal_senders = false;
69 if (max_wal_senders > 0)
70 WalSndWakeup(physical, logical);
71 }
72}
void WalSndWakeup(bool physical, bool logical)
Definition walsender.c:4050
PGDLLIMPORT int max_wal_senders
Definition walsender.c:141

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

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

◆ am_walsender

◆ log_replication_commands

PGDLLIMPORT bool log_replication_commands
extern

◆ max_wal_senders

◆ wake_wal_senders

PGDLLIMPORT bool wake_wal_senders
extern

Definition at line 155 of file walsender.c.

Referenced by WalSndWakeupProcessRequests().

◆ wal_sender_shutdown_timeout

PGDLLIMPORT int wal_sender_shutdown_timeout
extern

Definition at line 146 of file walsender.c.

Referenced by WalSndCheckShutdownTimeout(), and WalSndComputeSleeptime().

◆ wal_sender_timeout