PostgreSQL Source Code git master
Loading...
Searching...
No Matches
walreceiver.h File Reference
#include <netdb.h>
#include "access/xlog.h"
#include "access/xlogdefs.h"
#include "pgtime.h"
#include "port/atomics.h"
#include "replication/logicalproto.h"
#include "replication/walsender.h"
#include "storage/condition_variable.h"
#include "storage/spin.h"
#include "utils/tuplestore.h"
Include dependency graph for walreceiver.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  WalRcvData
 
struct  WalRcvStreamOptions
 
struct  WalRcvExecResult
 
struct  WalReceiverFunctionsType
 

Macros

#define MAXCONNINFO   1024
 
#define AllowCascadeReplication()   (EnableHotStandby && max_wal_senders > 0)
 
#define walrcv_connect(conninfo, replication, logical, must_use_password, appname, err)    WalReceiverFunctions->walrcv_connect(conninfo, replication, logical, must_use_password, appname, err)
 
#define walrcv_check_conninfo(conninfo, must_use_password)    WalReceiverFunctions->walrcv_check_conninfo(conninfo, must_use_password)
 
#define walrcv_get_conninfo(conn)    WalReceiverFunctions->walrcv_get_conninfo(conn)
 
#define walrcv_get_senderinfo(conn, sender_host, sender_port)    WalReceiverFunctions->walrcv_get_senderinfo(conn, sender_host, sender_port)
 
#define walrcv_identify_system(conn, primary_tli)    WalReceiverFunctions->walrcv_identify_system(conn, primary_tli)
 
#define walrcv_get_dbname_from_conninfo(conninfo)    WalReceiverFunctions->walrcv_get_dbname_from_conninfo(conninfo)
 
#define walrcv_server_version(conn)    WalReceiverFunctions->walrcv_server_version(conn)
 
#define walrcv_readtimelinehistoryfile(conn, tli, filename, content, size)    WalReceiverFunctions->walrcv_readtimelinehistoryfile(conn, tli, filename, content, size)
 
#define walrcv_startstreaming(conn, options)    WalReceiverFunctions->walrcv_startstreaming(conn, options)
 
#define walrcv_endstreaming(conn, next_tli)    WalReceiverFunctions->walrcv_endstreaming(conn, next_tli)
 
#define walrcv_receive(conn, buffer, wait_fd)    WalReceiverFunctions->walrcv_receive(conn, buffer, wait_fd)
 
#define walrcv_send(conn, buffer, nbytes)    WalReceiverFunctions->walrcv_send(conn, buffer, nbytes)
 
#define walrcv_create_slot(conn, slotname, temporary, two_phase, failover, snapshot_action, lsn)    WalReceiverFunctions->walrcv_create_slot(conn, slotname, temporary, two_phase, failover, snapshot_action, lsn)
 
#define walrcv_alter_slot(conn, slotname, failover, two_phase)    WalReceiverFunctions->walrcv_alter_slot(conn, slotname, failover, two_phase)
 
#define walrcv_get_backend_pid(conn)    WalReceiverFunctions->walrcv_get_backend_pid(conn)
 
#define walrcv_exec(conn, exec, nRetTypes, retTypes)    WalReceiverFunctions->walrcv_exec(conn, exec, nRetTypes, retTypes)
 
#define walrcv_disconnect(conn)    WalReceiverFunctions->walrcv_disconnect(conn)
 

Typedefs

typedef struct WalReceiverConn WalReceiverConn
 
typedef struct WalRcvExecResult WalRcvExecResult
 
typedef WalReceiverConn *(* walrcv_connect_fn) (const char *conninfo, bool replication, bool logical, bool must_use_password, const char *appname, char **err)
 
typedef void(* walrcv_check_conninfo_fn) (const char *conninfo, bool must_use_password)
 
typedef char *(* walrcv_get_conninfo_fn) (WalReceiverConn *conn)
 
typedef void(* walrcv_get_senderinfo_fn) (WalReceiverConn *conn, char **sender_host, int *sender_port)
 
typedef char *(* walrcv_identify_system_fn) (WalReceiverConn *conn, TimeLineID *primary_tli)
 
typedef char *(* walrcv_get_dbname_from_conninfo_fn) (const char *conninfo)
 
typedef int(* walrcv_server_version_fn) (WalReceiverConn *conn)
 
typedef void(* walrcv_readtimelinehistoryfile_fn) (WalReceiverConn *conn, TimeLineID tli, char **filename, char **content, int *size)
 
typedef bool(* walrcv_startstreaming_fn) (WalReceiverConn *conn, const WalRcvStreamOptions *options)
 
typedef void(* walrcv_endstreaming_fn) (WalReceiverConn *conn, TimeLineID *next_tli)
 
typedef int(* walrcv_receive_fn) (WalReceiverConn *conn, char **buffer, pgsocket *wait_fd)
 
typedef void(* walrcv_send_fn) (WalReceiverConn *conn, const char *buffer, int nbytes)
 
typedef char *(* walrcv_create_slot_fn) (WalReceiverConn *conn, const char *slotname, bool temporary, bool two_phase, bool failover, CRSSnapshotAction snapshot_action, XLogRecPtr *lsn)
 
typedef void(* walrcv_alter_slot_fn) (WalReceiverConn *conn, const char *slotname, const bool *failover, const bool *two_phase)
 
typedef pid_t(* walrcv_get_backend_pid_fn) (WalReceiverConn *conn)
 
typedef WalRcvExecResult *(* walrcv_exec_fn) (WalReceiverConn *conn, const char *query, const int nRetTypes, const Oid *retTypes)
 
typedef void(* walrcv_disconnect_fn) (WalReceiverConn *conn)
 
typedef struct WalReceiverFunctionsType WalReceiverFunctionsType
 

Enumerations

enum  WalRcvState {
  WALRCV_STOPPED , WALRCV_STARTING , WALRCV_CONNECTING , WALRCV_STREAMING ,
  WALRCV_WAITING , WALRCV_RESTARTING , WALRCV_STOPPING
}
 
enum  WalRcvExecStatus {
  WALRCV_ERROR , WALRCV_OK_COMMAND , WALRCV_OK_TUPLES , WALRCV_OK_COPY_IN ,
  WALRCV_OK_COPY_OUT , WALRCV_OK_COPY_BOTH
}
 

Functions

static void walrcv_clear_result (WalRcvExecResult *walres)
 
pg_noreturn void WalReceiverMain (const void *startup_data, size_t startup_data_len)
 
void WalRcvRequestApplyReply (void)
 
void ShutdownWalRcv (void)
 
bool WalRcvStreaming (void)
 
bool WalRcvRunning (void)
 
WalRcvState WalRcvGetState (void)
 
void RequestXLogStreaming (TimeLineID tli, XLogRecPtr recptr, const char *conninfo, const char *slotname, bool create_temp_slot)
 
XLogRecPtr GetWalRcvFlushRecPtr (XLogRecPtr *latestChunkStart, TimeLineID *receiveTLI)
 
XLogRecPtr GetWalRcvWriteRecPtr (void)
 
int GetReplicationApplyDelay (void)
 
int GetReplicationTransferLatency (void)
 

Variables

PGDLLIMPORT int wal_receiver_status_interval
 
PGDLLIMPORT int wal_receiver_timeout
 
PGDLLIMPORT bool hot_standby_feedback
 
PGDLLIMPORT WalRcvDataWalRcv
 
PGDLLIMPORT WalReceiverFunctionsTypeWalReceiverFunctions
 

Macro Definition Documentation

◆ AllowCascadeReplication

#define AllowCascadeReplication ( )    (EnableHotStandby && max_wal_senders > 0)

Definition at line 40 of file walreceiver.h.

◆ MAXCONNINFO

#define MAXCONNINFO   1024

Definition at line 37 of file walreceiver.h.

◆ walrcv_alter_slot

#define walrcv_alter_slot (   conn,
  slotname,
  failover,
  two_phase 
)     WalReceiverFunctions->walrcv_alter_slot(conn, slotname, failover, two_phase)

Definition at line 462 of file walreceiver.h.

473{
474 if (!walres)
475 return;
476
477 if (walres->err)
478 pfree(walres->err);
479
480 if (walres->tuplestore)
481 tuplestore_end(walres->tuplestore);
482
483 if (walres->tupledesc)
484 FreeTupleDesc(walres->tupledesc);
485
486 pfree(walres);
487}
488
489/* prototypes for functions in walreceiver.c */
490pg_noreturn extern void WalReceiverMain(const void *startup_data, size_t startup_data_len);
491extern void WalRcvRequestApplyReply(void);
492
493/* prototypes for functions in walreceiverfuncs.c */
494extern void ShutdownWalRcv(void);
495extern bool WalRcvStreaming(void);
496extern bool WalRcvRunning(void);
497extern WalRcvState WalRcvGetState(void);
499 const char *conninfo, const char *slotname,
500 bool create_temp_slot);
503extern int GetReplicationApplyDelay(void);
504extern int GetReplicationTransferLatency(void);
505
506#endif /* _WALRECEIVER_H */
#define pg_noreturn
Definition c.h:190
void pfree(void *pointer)
Definition mcxt.c:1616
static int fb(int x)
void FreeTupleDesc(TupleDesc tupdesc)
Definition tupdesc.c:560
void tuplestore_end(Tuplestorestate *state)
Definition tuplestore.c:493
XLogRecPtr GetWalRcvFlushRecPtr(XLogRecPtr *latestChunkStart, TimeLineID *receiveTLI)
bool WalRcvStreaming(void)
void RequestXLogStreaming(TimeLineID tli, XLogRecPtr recptr, const char *conninfo, const char *slotname, bool create_temp_slot)
pg_noreturn void WalReceiverMain(const void *startup_data, size_t startup_data_len)
XLogRecPtr GetWalRcvWriteRecPtr(void)
void ShutdownWalRcv(void)
WalRcvState WalRcvGetState(void)
bool WalRcvRunning(void)
WalRcvState
Definition walreceiver.h:46
int GetReplicationApplyDelay(void)
void WalRcvRequestApplyReply(void)
int GetReplicationTransferLatency(void)
uint64 XLogRecPtr
Definition xlogdefs.h:21
uint32 TimeLineID
Definition xlogdefs.h:63
static TimeLineID receiveTLI

◆ walrcv_check_conninfo

#define walrcv_check_conninfo (   conninfo,
  must_use_password 
)     WalReceiverFunctions->walrcv_check_conninfo(conninfo, must_use_password)

Definition at line 438 of file walreceiver.h.

◆ walrcv_connect

#define walrcv_connect (   conninfo,
  replication,
  logical,
  must_use_password,
  appname,
  err 
)     WalReceiverFunctions->walrcv_connect(conninfo, replication, logical, must_use_password, appname, err)

Definition at line 436 of file walreceiver.h.

◆ walrcv_create_slot

#define walrcv_create_slot (   conn,
  slotname,
  temporary,
  two_phase,
  failover,
  snapshot_action,
  lsn 
)     WalReceiverFunctions->walrcv_create_slot(conn, slotname, temporary, two_phase, failover, snapshot_action, lsn)

Definition at line 460 of file walreceiver.h.

◆ walrcv_disconnect

#define walrcv_disconnect (   conn)     WalReceiverFunctions->walrcv_disconnect(conn)

Definition at line 468 of file walreceiver.h.

◆ walrcv_endstreaming

#define walrcv_endstreaming (   conn,
  next_tli 
)     WalReceiverFunctions->walrcv_endstreaming(conn, next_tli)

Definition at line 454 of file walreceiver.h.

◆ walrcv_exec

#define walrcv_exec (   conn,
  exec,
  nRetTypes,
  retTypes 
)     WalReceiverFunctions->walrcv_exec(conn, exec, nRetTypes, retTypes)

Definition at line 466 of file walreceiver.h.

◆ walrcv_get_backend_pid

#define walrcv_get_backend_pid (   conn)     WalReceiverFunctions->walrcv_get_backend_pid(conn)

Definition at line 464 of file walreceiver.h.

◆ walrcv_get_conninfo

#define walrcv_get_conninfo (   conn)     WalReceiverFunctions->walrcv_get_conninfo(conn)

Definition at line 440 of file walreceiver.h.

◆ walrcv_get_dbname_from_conninfo

#define walrcv_get_dbname_from_conninfo (   conninfo)     WalReceiverFunctions->walrcv_get_dbname_from_conninfo(conninfo)

Definition at line 446 of file walreceiver.h.

◆ walrcv_get_senderinfo

#define walrcv_get_senderinfo (   conn,
  sender_host,
  sender_port 
)     WalReceiverFunctions->walrcv_get_senderinfo(conn, sender_host, sender_port)

Definition at line 442 of file walreceiver.h.

◆ walrcv_identify_system

#define walrcv_identify_system (   conn,
  primary_tli 
)     WalReceiverFunctions->walrcv_identify_system(conn, primary_tli)

Definition at line 444 of file walreceiver.h.

◆ walrcv_readtimelinehistoryfile

#define walrcv_readtimelinehistoryfile (   conn,
  tli,
  filename,
  content,
  size 
)     WalReceiverFunctions->walrcv_readtimelinehistoryfile(conn, tli, filename, content, size)

Definition at line 450 of file walreceiver.h.

◆ walrcv_receive

#define walrcv_receive (   conn,
  buffer,
  wait_fd 
)     WalReceiverFunctions->walrcv_receive(conn, buffer, wait_fd)

Definition at line 456 of file walreceiver.h.

◆ walrcv_send

#define walrcv_send (   conn,
  buffer,
  nbytes 
)     WalReceiverFunctions->walrcv_send(conn, buffer, nbytes)

Definition at line 458 of file walreceiver.h.

◆ walrcv_server_version

#define walrcv_server_version (   conn)     WalReceiverFunctions->walrcv_server_version(conn)

Definition at line 448 of file walreceiver.h.

◆ walrcv_startstreaming

#define walrcv_startstreaming (   conn,
  options 
)     WalReceiverFunctions->walrcv_startstreaming(conn, options)

Definition at line 452 of file walreceiver.h.

Typedef Documentation

◆ walrcv_alter_slot_fn

typedef void(* walrcv_alter_slot_fn) (WalReceiverConn *conn, const char *slotname, const bool *failover, const bool *two_phase)

Definition at line 380 of file walreceiver.h.

◆ walrcv_check_conninfo_fn

typedef void(* walrcv_check_conninfo_fn) (const char *conninfo, bool must_use_password)

Definition at line 255 of file walreceiver.h.

◆ walrcv_connect_fn

typedef WalReceiverConn *(* walrcv_connect_fn) (const char *conninfo, bool replication, bool logical, bool must_use_password, const char *appname, char **err)

Definition at line 243 of file walreceiver.h.

◆ walrcv_create_slot_fn

typedef char *(* walrcv_create_slot_fn) (WalReceiverConn *conn, const char *slotname, bool temporary, bool two_phase, bool failover, CRSSnapshotAction snapshot_action, XLogRecPtr *lsn)

Definition at line 366 of file walreceiver.h.

◆ walrcv_disconnect_fn

typedef void(* walrcv_disconnect_fn) (WalReceiverConn *conn)

Definition at line 411 of file walreceiver.h.

◆ walrcv_endstreaming_fn

typedef void(* walrcv_endstreaming_fn) (WalReceiverConn *conn, TimeLineID *next_tli)

Definition at line 331 of file walreceiver.h.

◆ walrcv_exec_fn

Definition at line 401 of file walreceiver.h.

◆ walrcv_get_backend_pid_fn

typedef pid_t(* walrcv_get_backend_pid_fn) (WalReceiverConn *conn)

Definition at line 391 of file walreceiver.h.

◆ walrcv_get_conninfo_fn

typedef char *(* walrcv_get_conninfo_fn) (WalReceiverConn *conn)

Definition at line 264 of file walreceiver.h.

◆ walrcv_get_dbname_from_conninfo_fn

typedef char *(* walrcv_get_dbname_from_conninfo_fn) (const char *conninfo)

Definition at line 292 of file walreceiver.h.

◆ walrcv_get_senderinfo_fn

typedef void(* walrcv_get_senderinfo_fn) (WalReceiverConn *conn, char **sender_host, int *sender_port)

Definition at line 273 of file walreceiver.h.

◆ walrcv_identify_system_fn

typedef char *(* walrcv_identify_system_fn) (WalReceiverConn *conn, TimeLineID *primary_tli)

Definition at line 284 of file walreceiver.h.

◆ walrcv_readtimelinehistoryfile_fn

typedef void(* walrcv_readtimelinehistoryfile_fn) (WalReceiverConn *conn, TimeLineID tli, char **filename, char **content, int *size)

Definition at line 308 of file walreceiver.h.

◆ walrcv_receive_fn

typedef int(* walrcv_receive_fn) (WalReceiverConn *conn, char **buffer, pgsocket *wait_fd)

Definition at line 342 of file walreceiver.h.

◆ walrcv_send_fn

typedef void(* walrcv_send_fn) (WalReceiverConn *conn, const char *buffer, int nbytes)

Definition at line 352 of file walreceiver.h.

◆ walrcv_server_version_fn

typedef int(* walrcv_server_version_fn) (WalReceiverConn *conn)

Definition at line 299 of file walreceiver.h.

◆ walrcv_startstreaming_fn

typedef bool(* walrcv_startstreaming_fn) (WalReceiverConn *conn, const WalRcvStreamOptions *options)

Definition at line 322 of file walreceiver.h.

◆ WalRcvExecResult

◆ WalReceiverConn

Definition at line 196 of file walreceiver.h.

◆ WalReceiverFunctionsType

Enumeration Type Documentation

◆ WalRcvExecStatus

Enumerator
WALRCV_ERROR 
WALRCV_OK_COMMAND 
WALRCV_OK_TUPLES 
WALRCV_OK_COPY_IN 
WALRCV_OK_COPY_OUT 
WALRCV_OK_COPY_BOTH 

Definition at line 203 of file walreceiver.h.

204{
205 WALRCV_ERROR, /* There was error when executing the query. */
206 WALRCV_OK_COMMAND, /* Query executed utility or replication
207 * command. */
208 WALRCV_OK_TUPLES, /* Query returned tuples. */
209 WALRCV_OK_COPY_IN, /* Query started COPY FROM. */
210 WALRCV_OK_COPY_OUT, /* Query started COPY TO. */
211 WALRCV_OK_COPY_BOTH, /* Query started COPY BOTH replication
212 * protocol. */
WalRcvExecStatus
@ WALRCV_OK_COPY_IN
@ WALRCV_OK_COMMAND
@ WALRCV_ERROR
@ WALRCV_OK_TUPLES
@ WALRCV_OK_COPY_OUT
@ WALRCV_OK_COPY_BOTH

◆ WalRcvState

Enumerator
WALRCV_STOPPED 
WALRCV_STARTING 
WALRCV_CONNECTING 
WALRCV_STREAMING 
WALRCV_WAITING 
WALRCV_RESTARTING 
WALRCV_STOPPING 

Definition at line 45 of file walreceiver.h.

46{
47 WALRCV_STOPPED, /* stopped and mustn't start up again */
48 WALRCV_STARTING, /* launched, but the process hasn't
49 * initialized yet */
50 WALRCV_CONNECTING, /* connecting to upstream server */
51 WALRCV_STREAMING, /* walreceiver is streaming */
52 WALRCV_WAITING, /* stopped streaming, waiting for orders */
53 WALRCV_RESTARTING, /* asked to restart streaming */
54 WALRCV_STOPPING, /* requested to stop, but still running */
@ WALRCV_STARTING
Definition walreceiver.h:48
@ WALRCV_STOPPED
Definition walreceiver.h:47
@ WALRCV_CONNECTING
Definition walreceiver.h:50
@ WALRCV_RESTARTING
Definition walreceiver.h:53
@ WALRCV_STREAMING
Definition walreceiver.h:51
@ WALRCV_WAITING
Definition walreceiver.h:52
@ WALRCV_STOPPING
Definition walreceiver.h:54

Function Documentation

◆ GetReplicationApplyDelay()

int GetReplicationApplyDelay ( void  )
extern

Definition at line 381 of file walreceiverfuncs.c.

382{
387
388 SpinLockAcquire(&walrcv->mutex);
389 receivePtr = walrcv->flushedUpto;
390 SpinLockRelease(&walrcv->mutex);
391
393
394 if (receivePtr == replayPtr)
395 return 0;
396
398
399 if (chunkReplayStartTime == 0)
400 return -1;
401
404}
long TimestampDifferenceMilliseconds(TimestampTz start_time, TimestampTz stop_time)
Definition timestamp.c:1751
TimestampTz GetCurrentTimestamp(void)
Definition timestamp.c:1639
int64 TimestampTz
Definition timestamp.h:39
static void SpinLockRelease(volatile slock_t *lock)
Definition spin.h:62
static void SpinLockAcquire(volatile slock_t *lock)
Definition spin.h:56
WalRcvData * WalRcv
TimestampTz GetCurrentChunkReplayStartTime(void)
XLogRecPtr GetXLogReplayRecPtr(TimeLineID *replayTLI)

References fb(), GetCurrentChunkReplayStartTime(), GetCurrentTimestamp(), GetXLogReplayRecPtr(), SpinLockAcquire(), SpinLockRelease(), TimestampDifferenceMilliseconds(), and WalRcv.

Referenced by ProcessWalSndrMessage().

◆ GetReplicationTransferLatency()

int GetReplicationTransferLatency ( void  )
extern

Definition at line 411 of file walreceiverfuncs.c.

412{
414 TimestampTz lastMsgSendTime;
415 TimestampTz lastMsgReceiptTime;
416
417 SpinLockAcquire(&walrcv->mutex);
418 lastMsgSendTime = walrcv->lastMsgSendTime;
419 lastMsgReceiptTime = walrcv->lastMsgReceiptTime;
420 SpinLockRelease(&walrcv->mutex);
421
422 return TimestampDifferenceMilliseconds(lastMsgSendTime,
423 lastMsgReceiptTime);
424}

References fb(), SpinLockAcquire(), SpinLockRelease(), TimestampDifferenceMilliseconds(), and WalRcv.

Referenced by ProcessWalSndrMessage().

◆ GetWalRcvFlushRecPtr()

XLogRecPtr GetWalRcvFlushRecPtr ( XLogRecPtr latestChunkStart,
TimeLineID receiveTLI 
)
extern

Definition at line 348 of file walreceiverfuncs.c.

349{
352
353 SpinLockAcquire(&walrcv->mutex);
354 recptr = walrcv->flushedUpto;
355 if (latestChunkStart)
356 *latestChunkStart = walrcv->latestChunkStart;
357 if (receiveTLI)
358 *receiveTLI = walrcv->receivedTLI;
359 SpinLockRelease(&walrcv->mutex);
360
361 return recptr;
362}

References fb(), receiveTLI, SpinLockAcquire(), SpinLockRelease(), and WalRcv.

Referenced by CreateRestartPoint(), GetCurrentLSNForWaitType(), GetLatestLSN(), GetStandbyFlushRecPtr(), pg_last_wal_receive_lsn(), and WaitForWALToBecomeAvailable().

◆ GetWalRcvWriteRecPtr()

XLogRecPtr GetWalRcvWriteRecPtr ( void  )
extern

Definition at line 369 of file walreceiverfuncs.c.

370{
372
373 return pg_atomic_read_u64(&walrcv->writtenUpto);
374}
static uint64 pg_atomic_read_u64(volatile pg_atomic_uint64 *ptr)
Definition atomics.h:467

References fb(), pg_atomic_read_u64(), and WalRcv.

Referenced by GetCurrentLSNForWaitType().

◆ RequestXLogStreaming()

void RequestXLogStreaming ( TimeLineID  tli,
XLogRecPtr  recptr,
const char conninfo,
const char slotname,
bool  create_temp_slot 
)
extern

Definition at line 261 of file walreceiverfuncs.c.

263{
265 bool launch = false;
266 pg_time_t now = (pg_time_t) time(NULL);
268
269 /*
270 * We always start at the beginning of the segment. That prevents a broken
271 * segment (i.e., with no records in the first half of a segment) from
272 * being created by XLOG streaming, which might cause trouble later on if
273 * the segment is e.g archived.
274 */
277
278 SpinLockAcquire(&walrcv->mutex);
279
280 /* It better be stopped if we try to restart it */
281 Assert(walrcv->walRcvState == WALRCV_STOPPED ||
282 walrcv->walRcvState == WALRCV_WAITING);
283
284 if (conninfo != NULL)
285 strlcpy(walrcv->conninfo, conninfo, MAXCONNINFO);
286 else
287 walrcv->conninfo[0] = '\0';
288
289 /*
290 * Use configured replication slot if present, and ignore the value of
291 * create_temp_slot as the slot name should be persistent. Otherwise, use
292 * create_temp_slot to determine whether this WAL receiver should create a
293 * temporary slot by itself and use it, or not.
294 */
295 if (slotname != NULL && slotname[0] != '\0')
296 {
297 strlcpy(walrcv->slotname, slotname, NAMEDATALEN);
298 walrcv->is_temp_slot = false;
299 }
300 else
301 {
302 walrcv->slotname[0] = '\0';
303 walrcv->is_temp_slot = create_temp_slot;
304 }
305
306 if (walrcv->walRcvState == WALRCV_STOPPED)
307 {
308 launch = true;
309 walrcv->walRcvState = WALRCV_STARTING;
310 }
311 else
312 walrcv->walRcvState = WALRCV_RESTARTING;
313 walrcv->startTime = now;
314
315 /*
316 * If this is the first startup of walreceiver (on this timeline),
317 * initialize flushedUpto and latestChunkStart to the starting point.
318 */
319 if (!XLogRecPtrIsValid(walrcv->receiveStart) || walrcv->receivedTLI != tli)
320 {
321 walrcv->flushedUpto = recptr;
322 walrcv->receivedTLI = tli;
323 walrcv->latestChunkStart = recptr;
324 pg_atomic_write_u64(&walrcv->writtenUpto, recptr);
325 }
326 walrcv->receiveStart = recptr;
327 walrcv->receiveStartTLI = tli;
328
329 walrcv_proc = walrcv->procno;
330
331 SpinLockRelease(&walrcv->mutex);
332
333 if (launch)
337}
static void pg_atomic_write_u64(volatile pg_atomic_uint64 *ptr, uint64 val)
Definition atomics.h:485
Datum now(PG_FUNCTION_ARGS)
Definition timestamp.c:1603
#define Assert(condition)
Definition c.h:943
void SetLatch(Latch *latch)
Definition latch.c:290
#define NAMEDATALEN
int64 pg_time_t
Definition pgtime.h:23
void SendPostmasterSignal(PMSignalReason reason)
Definition pmsignal.c:164
@ PMSIGNAL_START_WALRECEIVER
Definition pmsignal.h:43
size_t strlcpy(char *dst, const char *src, size_t siz)
Definition strlcpy.c:45
#define GetPGProcByNumber(n)
Definition proc.h:504
#define INVALID_PROC_NUMBER
Definition procnumber.h:26
int ProcNumber
Definition procnumber.h:24
#define MAXCONNINFO
Definition walreceiver.h:37
int wal_segment_size
Definition xlog.c:150
#define XLogSegmentOffset(xlogptr, wal_segsz_bytes)
#define XLogRecPtrIsValid(r)
Definition xlogdefs.h:29

References Assert, fb(), GetPGProcByNumber, INVALID_PROC_NUMBER, MAXCONNINFO, NAMEDATALEN, now(), pg_atomic_write_u64(), PMSIGNAL_START_WALRECEIVER, SendPostmasterSignal(), SetLatch(), SpinLockAcquire(), SpinLockRelease(), strlcpy(), wal_segment_size, WalRcv, WALRCV_RESTARTING, WALRCV_STARTING, WALRCV_STOPPED, WALRCV_WAITING, XLogRecPtrIsValid, and XLogSegmentOffset.

Referenced by WaitForWALToBecomeAvailable().

◆ ShutdownWalRcv()

void ShutdownWalRcv ( void  )
extern

Definition at line 193 of file walreceiverfuncs.c.

194{
196 pid_t walrcvpid = 0;
197 bool stopped = false;
198
199 /*
200 * Request walreceiver to stop. Walreceiver will switch to WALRCV_STOPPED
201 * mode once it's finished, and will also request postmaster to not
202 * restart itself.
203 */
204 SpinLockAcquire(&walrcv->mutex);
205 switch (walrcv->walRcvState)
206 {
207 case WALRCV_STOPPED:
208 break;
209 case WALRCV_STARTING:
210 walrcv->walRcvState = WALRCV_STOPPED;
211 stopped = true;
212 break;
213
215 case WALRCV_STREAMING:
216 case WALRCV_WAITING:
218 walrcv->walRcvState = WALRCV_STOPPING;
220 case WALRCV_STOPPING:
221 walrcvpid = walrcv->pid;
222 break;
223 }
224 SpinLockRelease(&walrcv->mutex);
225
226 /* Unnecessary but consistent. */
227 if (stopped)
228 ConditionVariableBroadcast(&walrcv->walRcvStoppedCV);
229
230 /*
231 * Signal walreceiver process if it was still running.
232 */
233 if (walrcvpid != 0)
235
236 /*
237 * Wait for walreceiver to acknowledge its death by setting state to
238 * WALRCV_STOPPED.
239 */
240 ConditionVariablePrepareToSleep(&walrcv->walRcvStoppedCV);
241 while (WalRcvRunning())
242 ConditionVariableSleep(&walrcv->walRcvStoppedCV,
245}
#define pg_fallthrough
Definition c.h:161
bool ConditionVariableCancelSleep(void)
void ConditionVariableBroadcast(ConditionVariable *cv)
void ConditionVariablePrepareToSleep(ConditionVariable *cv)
void ConditionVariableSleep(ConditionVariable *cv, uint32 wait_event_info)
bool WalRcvRunning(void)
#define kill(pid, sig)
Definition win32_port.h:490

References ConditionVariableBroadcast(), ConditionVariableCancelSleep(), ConditionVariablePrepareToSleep(), ConditionVariableSleep(), fb(), kill, pg_fallthrough, SpinLockAcquire(), SpinLockRelease(), WalRcv, WALRCV_CONNECTING, WALRCV_RESTARTING, WALRCV_STARTING, WALRCV_STOPPED, WALRCV_STOPPING, WALRCV_STREAMING, WALRCV_WAITING, and WalRcvRunning().

Referenced by XLogShutdownWalRcv().

◆ walrcv_clear_result()

static void walrcv_clear_result ( WalRcvExecResult walres)
inlinestatic

◆ WalRcvGetState()

WalRcvState WalRcvGetState ( void  )
extern

Definition at line 124 of file walreceiverfuncs.c.

125{
128
129 SpinLockAcquire(&walrcv->mutex);
130 state = walrcv->walRcvState;
131 SpinLockRelease(&walrcv->mutex);
132
133 return state;
134}

References fb(), SpinLockAcquire(), SpinLockRelease(), and WalRcv.

Referenced by WaitForWALToBecomeAvailable().

◆ WalRcvRequestApplyReply()

void WalRcvRequestApplyReply ( void  )
extern

Definition at line 1393 of file walreceiver.c.

1394{
1395 ProcNumber procno;
1396
1398 /* fetching the proc number is probably atomic, but don't rely on it */
1400 procno = WalRcv->procno;
1402 if (procno != INVALID_PROC_NUMBER)
1403 SetLatch(&GetPGProcByNumber(procno)->procLatch);
1404}
ProcNumber procno
Definition walreceiver.h:68
sig_atomic_t apply_reply_requested
slock_t mutex

References WalRcvData::apply_reply_requested, GetPGProcByNumber, INVALID_PROC_NUMBER, WalRcvData::mutex, WalRcvData::procno, SetLatch(), SpinLockAcquire(), SpinLockRelease(), and WalRcv.

Referenced by ApplyWalRecord(), and WaitForWALToBecomeAvailable().

◆ WalRcvRunning()

bool WalRcvRunning ( void  )
extern

Definition at line 76 of file walreceiverfuncs.c.

77{
80 pg_time_t startTime;
81
82 SpinLockAcquire(&walrcv->mutex);
83
84 state = walrcv->walRcvState;
85 startTime = walrcv->startTime;
86
87 SpinLockRelease(&walrcv->mutex);
88
89 /*
90 * If it has taken too long for walreceiver to start up, give up. Setting
91 * the state to STOPPED ensures that if walreceiver later does start up
92 * after all, it will see that it's not supposed to be running and die
93 * without doing anything.
94 */
96 {
97 pg_time_t now = (pg_time_t) time(NULL);
98
99 if ((now - startTime) > WALRCV_STARTUP_TIMEOUT)
100 {
101 bool stopped = false;
102
103 SpinLockAcquire(&walrcv->mutex);
104 if (walrcv->walRcvState == WALRCV_STARTING)
105 {
106 state = walrcv->walRcvState = WALRCV_STOPPED;
107 stopped = true;
108 }
109 SpinLockRelease(&walrcv->mutex);
110
111 if (stopped)
112 ConditionVariableBroadcast(&walrcv->walRcvStoppedCV);
113 }
114 }
115
116 if (state != WALRCV_STOPPED)
117 return true;
118 else
119 return false;
120}
#define WALRCV_STARTUP_TIMEOUT

References ConditionVariableBroadcast(), fb(), now(), SpinLockAcquire(), SpinLockRelease(), WalRcv, WALRCV_STARTING, WALRCV_STARTUP_TIMEOUT, and WALRCV_STOPPED.

Referenced by ShutdownWalRcv(), and StartupRequestWalReceiverRestart().

◆ WalRcvStreaming()

bool WalRcvStreaming ( void  )
extern

Definition at line 141 of file walreceiverfuncs.c.

142{
145 pg_time_t startTime;
146
147 SpinLockAcquire(&walrcv->mutex);
148
149 state = walrcv->walRcvState;
150 startTime = walrcv->startTime;
151
152 SpinLockRelease(&walrcv->mutex);
153
154 /*
155 * If it has taken too long for walreceiver to start up, give up. Setting
156 * the state to STOPPED ensures that if walreceiver later does start up
157 * after all, it will see that it's not supposed to be running and die
158 * without doing anything.
159 */
160 if (state == WALRCV_STARTING)
161 {
162 pg_time_t now = (pg_time_t) time(NULL);
163
164 if ((now - startTime) > WALRCV_STARTUP_TIMEOUT)
165 {
166 bool stopped = false;
167
168 SpinLockAcquire(&walrcv->mutex);
169 if (walrcv->walRcvState == WALRCV_STARTING)
170 {
171 state = walrcv->walRcvState = WALRCV_STOPPED;
172 stopped = true;
173 }
174 SpinLockRelease(&walrcv->mutex);
175
176 if (stopped)
177 ConditionVariableBroadcast(&walrcv->walRcvStoppedCV);
178 }
179 }
180
183 return true;
184 else
185 return false;
186}

References ConditionVariableBroadcast(), fb(), now(), SpinLockAcquire(), SpinLockRelease(), WalRcv, WALRCV_CONNECTING, WALRCV_RESTARTING, WALRCV_STARTING, WALRCV_STARTUP_TIMEOUT, WALRCV_STOPPED, and WALRCV_STREAMING.

Referenced by FinishWalRecovery(), and WaitForWALToBecomeAvailable().

◆ WalReceiverMain()

pg_noreturn void WalReceiverMain ( const void startup_data,
size_t  startup_data_len 
)
extern

Definition at line 154 of file walreceiver.c.

155{
156 char conninfo[MAXCONNINFO];
157 char *tmp_conninfo;
158 char slotname[NAMEDATALEN];
159 bool is_temp_slot;
160 XLogRecPtr startpoint;
161 TimeLineID startpointTLI;
163 bool first_stream;
166 char *err;
167 char *sender_host = NULL;
168 int sender_port = 0;
169 char *appname;
170
172
174
175 /*
176 * WalRcv should be set up already (if we are a backend, we inherit this
177 * by fork() or EXEC_BACKEND mechanism from the postmaster).
178 */
179 walrcv = WalRcv;
180 Assert(walrcv != NULL);
181
182 /*
183 * Mark walreceiver as running in shared memory.
184 *
185 * Do this as early as possible, so that if we fail later on, we'll set
186 * state to STOPPED. If we die before this, the startup process will keep
187 * waiting for us to start up, until it times out.
188 */
189 SpinLockAcquire(&walrcv->mutex);
190 Assert(walrcv->pid == 0);
191 switch (walrcv->walRcvState)
192 {
193 case WALRCV_STOPPING:
194 /* If we've already been requested to stop, don't start up. */
195 walrcv->walRcvState = WALRCV_STOPPED;
197
198 case WALRCV_STOPPED:
199 SpinLockRelease(&walrcv->mutex);
200 ConditionVariableBroadcast(&walrcv->walRcvStoppedCV);
201 proc_exit(1);
202 break;
203
204 case WALRCV_STARTING:
205 /* The usual case */
206 break;
207
209 case WALRCV_WAITING:
210 case WALRCV_STREAMING:
212 default:
213 /* Shouldn't happen */
214 SpinLockRelease(&walrcv->mutex);
215 elog(PANIC, "walreceiver still running according to shared memory state");
216 }
217 /* Advertise our PID so that the startup process can kill us */
218 walrcv->pid = MyProcPid;
219 walrcv->walRcvState = WALRCV_CONNECTING;
220
221 /* Fetch information required to start streaming */
222 walrcv->ready_to_display = false;
223 strlcpy(conninfo, walrcv->conninfo, MAXCONNINFO);
224 strlcpy(slotname, walrcv->slotname, NAMEDATALEN);
225 is_temp_slot = walrcv->is_temp_slot;
226 startpoint = walrcv->receiveStart;
227 startpointTLI = walrcv->receiveStartTLI;
228
229 /*
230 * At most one of is_temp_slot and slotname can be set; otherwise,
231 * RequestXLogStreaming messed up.
232 */
233 Assert(!is_temp_slot || (slotname[0] == '\0'));
234
235 /* Initialise to a sanish value */
237 walrcv->lastMsgSendTime =
238 walrcv->lastMsgReceiptTime = walrcv->latestWalEndTime = now;
239
240 /* Report our proc number so that others can wake us up */
241 walrcv->procno = MyProcNumber;
242
243 SpinLockRelease(&walrcv->mutex);
244
245 /* Arrange to clean up at walreceiver exit */
246 on_shmem_exit(WalRcvDie, PointerGetDatum(&startpointTLI));
247
248 /* Properly accept or ignore signals the postmaster might send us */
249 pqsignal(SIGHUP, SignalHandlerForConfigReload); /* set flag to read config
250 * file */
252 pqsignal(SIGTERM, die); /* request shutdown */
253 /* SIGQUIT handler was already set up by InitPostmasterChild */
258
259 /* Reset some signals that are accepted by postmaster but not here */
261
262 /* Load the libpq-specific functions */
263 load_file("libpqwalreceiver", false);
265 elog(ERROR, "libpqwalreceiver didn't initialize correctly");
266
267 /* Unblock signals (they were blocked when the postmaster forked us) */
269
270 /* Establish the connection to the primary for XLOG streaming */
271 appname = cluster_name[0] ? cluster_name : "walreceiver";
272 wrconn = walrcv_connect(conninfo, true, false, false, appname, &err);
273 if (!wrconn)
276 errmsg("streaming replication receiver \"%s\" could not connect to the primary server: %s",
277 appname, err)));
278
279 /*
280 * Save user-visible connection string. This clobbers the original
281 * conninfo, for security. Also save host and port of the sender server
282 * this walreceiver is connected to.
283 */
285 walrcv_get_senderinfo(wrconn, &sender_host, &sender_port);
286 SpinLockAcquire(&walrcv->mutex);
287 memset(walrcv->conninfo, 0, MAXCONNINFO);
288 if (tmp_conninfo)
290
291 memset(walrcv->sender_host, 0, NI_MAXHOST);
292 if (sender_host)
293 strlcpy(walrcv->sender_host, sender_host, NI_MAXHOST);
294
295 walrcv->sender_port = sender_port;
296 walrcv->ready_to_display = true;
297 SpinLockRelease(&walrcv->mutex);
298
299 if (tmp_conninfo)
301
302 if (sender_host)
303 pfree(sender_host);
304
305 first_stream = true;
306 for (;;)
307 {
308 char *primary_sysid;
309 char standby_sysid[32];
311
312 /*
313 * Check that we're connected to a valid server using the
314 * IDENTIFY_SYSTEM replication command.
315 */
317
321 {
324 errmsg("database system identifier differs between the primary and standby"),
325 errdetail("The primary's identifier is %s, the standby's identifier is %s.",
327 }
328
329 /*
330 * Confirm that the current timeline of the primary is the same or
331 * ahead of ours.
332 */
333 if (primaryTLI < startpointTLI)
336 errmsg("highest timeline %u of the primary is behind recovery timeline %u",
337 primaryTLI, startpointTLI)));
338
339 /*
340 * Get any missing history files. We do this always, even when we're
341 * not interested in that timeline, so that if we're promoted to
342 * become the primary later on, we don't select the same timeline that
343 * was already used in the current primary. This isn't bullet-proof -
344 * you'll need some external software to manage your cluster if you
345 * need to ensure that a unique timeline id is chosen in every case,
346 * but let's avoid the confusion of timeline id collisions where we
347 * can.
348 */
350
351 /*
352 * Create temporary replication slot if requested, and update slot
353 * name in shared memory. (Note the slot name cannot already be set
354 * in this case.)
355 */
356 if (is_temp_slot)
357 {
358 snprintf(slotname, sizeof(slotname),
359 "pg_walreceiver_%lld",
360 (long long int) walrcv_get_backend_pid(wrconn));
361
362 walrcv_create_slot(wrconn, slotname, true, false, false, 0, NULL);
363
364 SpinLockAcquire(&walrcv->mutex);
365 strlcpy(walrcv->slotname, slotname, NAMEDATALEN);
366 SpinLockRelease(&walrcv->mutex);
367 }
368
369 /*
370 * Start streaming.
371 *
372 * We'll try to start at the requested starting point and timeline,
373 * even if it's different from the server's latest timeline. In case
374 * we've already reached the end of the old timeline, the server will
375 * finish the streaming immediately, and we will go back to await
376 * orders from the startup process. If recovery_target_timeline is
377 * 'latest', the startup process will scan pg_wal and find the new
378 * history file, bump recovery target timeline, and ask us to restart
379 * on the new timeline.
380 */
381 options.logical = false;
382 options.startpoint = startpoint;
383 options.slotname = slotname[0] != '\0' ? slotname : NULL;
384 options.proto.physical.startpointTLI = startpointTLI;
386 {
387 if (first_stream)
388 ereport(LOG,
389 errmsg("started streaming WAL from primary at %X/%08X on timeline %u",
390 LSN_FORMAT_ARGS(startpoint), startpointTLI));
391 else
392 ereport(LOG,
393 errmsg("restarted WAL streaming at %X/%08X on timeline %u",
394 LSN_FORMAT_ARGS(startpoint), startpointTLI));
395 first_stream = false;
396
397 /*
398 * Switch to STREAMING after a successful connection if current
399 * state is CONNECTING. This switch happens after an initial
400 * startup, or after a restart as determined by
401 * WalRcvWaitForStartPosition().
402 */
403 SpinLockAcquire(&walrcv->mutex);
404 if (walrcv->walRcvState == WALRCV_CONNECTING)
405 walrcv->walRcvState = WALRCV_STREAMING;
406 SpinLockRelease(&walrcv->mutex);
407
408 /* Initialize LogstreamResult and buffers for processing messages */
411
412 /* Initialize nap wakeup times. */
414 for (int i = 0; i < NUM_WALRCV_WAKEUPS; ++i)
416
417 /* Send initial reply/feedback messages. */
418 XLogWalRcvSendReply(true, false, false);
420
421 /* Loop until end-of-streaming or error */
422 for (;;)
423 {
424 char *buf;
425 int len;
426 bool endofwal = false;
428 int rc;
430 long nap;
431
432 /*
433 * Exit walreceiver if we're not in recovery. This should not
434 * happen, but cross-check the status here.
435 */
436 if (!RecoveryInProgress())
439 errmsg("cannot continue WAL streaming, recovery has already ended")));
440
441 /* Process any requests or signals received recently */
443
445 {
446 ConfigReloadPending = false;
448 /* recompute wakeup times */
450 for (int i = 0; i < NUM_WALRCV_WAKEUPS; ++i)
453 }
454
455 /* See if we can read data immediately */
457 if (len != 0)
458 {
459 /*
460 * Process the received data, and any subsequent data we
461 * can read without blocking.
462 */
463 for (;;)
464 {
465 if (len > 0)
466 {
467 /*
468 * Something was received from primary, so adjust
469 * the ping and terminate wakeup times.
470 */
473 now);
475 XLogWalRcvProcessMsg(buf[0], &buf[1], len - 1,
476 startpointTLI);
477 }
478 else if (len == 0)
479 break;
480 else if (len < 0)
481 {
482 ereport(LOG,
483 (errmsg("replication terminated by primary server"),
484 errdetail("End of WAL reached on timeline %u at %X/%08X.",
485 startpointTLI,
487 endofwal = true;
488 break;
489 }
491 }
492
493 /* Let the primary know that we received some data. */
494 XLogWalRcvSendReply(false, false, false);
495
496 /*
497 * If we've written some records, flush them to disk and
498 * let the startup process and primary server know about
499 * them.
500 */
501 XLogWalRcvFlush(false, startpointTLI);
502 }
503
504 /* Check if we need to exit the streaming loop. */
505 if (endofwal)
506 break;
507
508 /* Find the soonest wakeup time, to limit our nap. */
510 for (int i = 0; i < NUM_WALRCV_WAKEUPS; ++i)
512
513 /* Calculate the nap time, clamping as necessary. */
516
517 /*
518 * Ideally we would reuse a WaitEventSet object repeatedly
519 * here to avoid the overheads of WaitLatchOrSocket on epoll
520 * systems, but we can't be sure that libpq (or any other
521 * walreceiver implementation) has the same socket (even if
522 * the fd is the same number, it may have been closed and
523 * reopened since the last time). In future, if there is a
524 * function for removing sockets from WaitEventSet, then we
525 * could add and remove just the socket each time, potentially
526 * avoiding some system calls.
527 */
532 wait_fd,
533 nap,
535 if (rc & WL_LATCH_SET)
536 {
539
540 if (walrcv->apply_reply_requested)
541 {
542 /*
543 * The recovery process has asked us to send apply
544 * feedback now. Make sure the flag is really set to
545 * false in shared memory before sending the reply, so
546 * we don't miss a new request for a reply.
547 */
548 walrcv->apply_reply_requested = false;
550 XLogWalRcvSendReply(false, false, true);
551 }
552 }
553 if (rc & WL_TIMEOUT)
554 {
555 /*
556 * We didn't receive anything new. If we haven't heard
557 * anything from the server for more than
558 * wal_receiver_timeout / 2, ping the server. Also, if
559 * it's been longer than wal_receiver_status_interval
560 * since the last update we sent, send a status update to
561 * the primary anyway, to report any progress in applying
562 * WAL.
563 */
564 bool requestReply = false;
565
566 /*
567 * Report pending statistics to the cumulative stats
568 * system. This location is useful for the report as it
569 * is not within a tight loop in the WAL receiver, to
570 * avoid bloating pgstats with requests, while also making
571 * sure that the reports happen each time a status update
572 * is sent.
573 */
574 pgstat_report_wal(false);
575
576 /*
577 * Check if time since last receive from primary has
578 * reached the configured limit.
579 */
584 errmsg("terminating walreceiver due to timeout")));
585
586 /*
587 * If we didn't receive anything new for half of receiver
588 * replication timeout, then ping the server.
589 */
591 {
592 requestReply = true;
594 }
595
598 }
599 }
600
601 /*
602 * The backend finished streaming. Exit streaming COPY-mode from
603 * our side, too.
604 */
606
607 /*
608 * If the server had switched to a new timeline that we didn't
609 * know about when we began streaming, fetch its timeline history
610 * file now.
611 */
613 }
614 else
615 ereport(LOG,
616 (errmsg("primary server contains no more WAL on requested timeline %u",
617 startpointTLI)));
618
619 /*
620 * End of WAL reached on the requested timeline. Close the last
621 * segment, and await for new orders from the startup process.
622 */
623 if (recvFile >= 0)
624 {
626
627 XLogWalRcvFlush(false, startpointTLI);
629 if (close(recvFile) != 0)
632 errmsg("could not close WAL segment %s: %m",
633 xlogfname)));
634
635 /*
636 * Create .done file forcibly to prevent the streamed segment from
637 * being archived later.
638 */
641 else
643 }
644 recvFile = -1;
645
646 elog(DEBUG1, "walreceiver ended streaming and awaits new instructions");
647 WalRcvWaitForStartPosition(&startpoint, &startpointTLI);
648 }
649 /* not reached */
650}
#define pg_memory_barrier()
Definition atomics.h:141
void AuxiliaryProcessMainCommon(void)
Definition auxprocess.c:41
sigset_t UnBlockSig
Definition pqsignal.c:22
#define Min(x, y)
Definition c.h:1091
#define UINT64_FORMAT
Definition c.h:635
#define TIMESTAMP_INFINITY
Definition timestamp.h:151
void load_file(const char *filename, bool restricted)
Definition dfmgr.c:149
int errcode_for_file_access(void)
Definition elog.c:898
int errcode(int sqlerrcode)
Definition elog.c:875
#define LOG
Definition elog.h:32
int errdetail(const char *fmt,...) pg_attribute_printf(1
#define FATAL
Definition elog.h:42
#define PANIC
Definition elog.h:44
#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
void err(int eval, const char *fmt,...)
Definition err.c:43
int MyProcPid
Definition globals.c:49
ProcNumber MyProcNumber
Definition globals.c:92
struct Latch * MyLatch
Definition globals.c:65
void ProcessConfigFile(GucContext context)
Definition guc-file.l:120
@ PGC_SIGHUP
Definition guc.h:75
char * cluster_name
Definition guc_tables.c:582
#define close(a)
Definition win32.h:12
volatile sig_atomic_t ConfigReloadPending
Definition interrupt.c:27
void SignalHandlerForConfigReload(SIGNAL_ARGS)
Definition interrupt.c:61
void on_shmem_exit(pg_on_exit_callback function, Datum arg)
Definition ipc.c:372
void proc_exit(int code)
Definition ipc.c:105
int i
Definition isn.c:77
int WaitLatchOrSocket(Latch *latch, int wakeEvents, pgsocket sock, long timeout, uint32 wait_event_info)
Definition latch.c:223
void ResetLatch(Latch *latch)
Definition latch.c:374
#define CHECK_FOR_INTERRUPTS()
Definition miscadmin.h:125
static char * errmsg
const void size_t len
static char buf[DEFAULT_XLOG_SEG_SIZE]
#define die(msg)
void pgstat_report_wal(bool force)
Definition pgstat_wal.c:46
#define pqsignal
Definition port.h:547
#define PG_SIG_IGN
Definition port.h:551
int pgsocket
Definition port.h:29
#define snprintf
Definition port.h:260
#define PGINVALID_SOCKET
Definition port.h:31
#define PG_SIG_DFL
Definition port.h:550
#define PointerGetDatum(X)
Definition postgres.h:354
void procsignal_sigusr1_handler(SIGNAL_ARGS)
Definition procsignal.c:688
void initStringInfo(StringInfo str)
Definition stringinfo.c:97
#define WL_SOCKET_READABLE
#define WL_TIMEOUT
#define WL_EXIT_ON_PM_DEATH
#define WL_LATCH_SET
#define NUM_WALRCV_WAKEUPS
static WalReceiverConn * wrconn
Definition walreceiver.c:95
static TimestampTz wakeup[NUM_WALRCV_WAKEUPS]
static StringInfoData reply_message
static int recvFile
static void WalRcvFetchTimeLineHistoryFiles(TimeLineID first, TimeLineID last)
static void XLogWalRcvFlush(bool dying, TimeLineID tli)
static TimeLineID recvFileTLI
WalReceiverFunctionsType * WalReceiverFunctions
Definition walreceiver.c:96
static void XLogWalRcvSendReply(bool force, bool requestReply, bool checkApply)
static XLogSegNo recvSegNo
static void XLogWalRcvSendHSFeedback(bool immed)
@ WALRCV_WAKEUP_TERMINATE
@ WALRCV_WAKEUP_PING
static void WalRcvWaitForStartPosition(XLogRecPtr *startpoint, TimeLineID *startpointTLI)
static void XLogWalRcvProcessMsg(unsigned char type, char *buf, Size len, TimeLineID tli)
static void WalRcvComputeNextWakeup(WalRcvWakeupReason reason, TimestampTz now)
static void WalRcvDie(int code, Datum arg)
static struct @19 LogstreamResult
#define walrcv_startstreaming(conn, options)
#define walrcv_connect(conninfo, replication, logical, must_use_password, appname, err)
#define walrcv_get_senderinfo(conn, sender_host, sender_port)
#define walrcv_create_slot(conn, slotname, temporary, two_phase, failover, snapshot_action, lsn)
#define walrcv_get_conninfo(conn)
#define walrcv_endstreaming(conn, next_tli)
#define walrcv_identify_system(conn, primary_tli)
#define walrcv_get_backend_pid(conn)
#define walrcv_receive(conn, buffer, wait_fd)
#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 SIGALRM
Definition win32_port.h:164
#define SIGUSR2
Definition win32_port.h:171
uint64 GetSystemIdentifier(void)
Definition xlog.c:4647
bool RecoveryInProgress(void)
Definition xlog.c:6830
int XLogArchiveMode
Definition xlog.c:126
@ ARCHIVE_MODE_ALWAYS
Definition xlog.h:69
#define MAXFNAMELEN
static void XLogFileName(char *fname, TimeLineID tli, XLogSegNo logSegNo, int wal_segsz_bytes)
void XLogArchiveForceDone(const char *xlog)
void XLogArchiveNotify(const char *xlog)
#define LSN_FORMAT_ARGS(lsn)
Definition xlogdefs.h:47

References ARCHIVE_MODE_ALWAYS, Assert, AuxiliaryProcessMainCommon(), buf, CHECK_FOR_INTERRUPTS, close, cluster_name, ConditionVariableBroadcast(), ConfigReloadPending, DEBUG1, die, elog, ereport, err(), errcode(), errcode_for_file_access(), errdetail(), errmsg, ERROR, FATAL, fb(), GetCurrentTimestamp(), GetSystemIdentifier(), GetXLogReplayRecPtr(), i, initStringInfo(), len, load_file(), LOG, LogstreamResult, LSN_FORMAT_ARGS, MAXCONNINFO, MAXFNAMELEN, Min, MyLatch, MyProcNumber, MyProcPid, NAMEDATALEN, now(), NUM_WALRCV_WAKEUPS, on_shmem_exit(), PANIC, pfree(), pg_fallthrough, pg_memory_barrier, PG_SIG_DFL, PG_SIG_IGN, PGC_SIGHUP, PGINVALID_SOCKET, pgstat_report_wal(), PointerGetDatum, pqsignal, proc_exit(), ProcessConfigFile(), procsignal_sigusr1_handler(), RecoveryInProgress(), recvFile, recvFileTLI, recvSegNo, reply_message, ResetLatch(), SIGALRM, SIGCHLD, SIGHUP, SignalHandlerForConfigReload(), SIGPIPE, SIGUSR1, SIGUSR2, snprintf, SpinLockAcquire(), SpinLockRelease(), strlcpy(), TIMESTAMP_INFINITY, TimestampDifferenceMilliseconds(), UINT64_FORMAT, UnBlockSig, WaitLatchOrSocket(), wakeup, wal_segment_size, WalRcv, walrcv_connect, WALRCV_CONNECTING, walrcv_create_slot, walrcv_endstreaming, walrcv_get_backend_pid, walrcv_get_conninfo, walrcv_get_senderinfo, walrcv_identify_system, walrcv_receive, WALRCV_RESTARTING, WALRCV_STARTING, walrcv_startstreaming, WALRCV_STOPPED, WALRCV_STOPPING, WALRCV_STREAMING, WALRCV_WAITING, WALRCV_WAKEUP_PING, WALRCV_WAKEUP_TERMINATE, WalRcvComputeNextWakeup(), WalRcvDie(), WalRcvFetchTimeLineHistoryFiles(), WalRcvWaitForStartPosition(), WalReceiverFunctions, WL_EXIT_ON_PM_DEATH, WL_LATCH_SET, WL_SOCKET_READABLE, WL_TIMEOUT, wrconn, XLogArchiveForceDone(), XLogArchiveMode, XLogArchiveNotify(), XLogFileName(), XLogWalRcvFlush(), XLogWalRcvProcessMsg(), XLogWalRcvSendHSFeedback(), and XLogWalRcvSendReply().

Variable Documentation

◆ hot_standby_feedback

PGDLLIMPORT bool hot_standby_feedback
extern

◆ wal_receiver_status_interval

PGDLLIMPORT int wal_receiver_status_interval
extern

◆ wal_receiver_timeout

PGDLLIMPORT int wal_receiver_timeout
extern

◆ WalRcv

◆ WalReceiverFunctions

PGDLLIMPORT WalReceiverFunctionsType* WalReceiverFunctions
extern

Definition at line 96 of file walreceiver.c.

Referenced by _PG_init(), and WalReceiverMain().