PostgreSQL Source Code
git master
|
#include "postgres.h"
#include <unistd.h>
#include "access/htup_details.h"
#include "access/timeline.h"
#include "access/transam.h"
#include "access/xlog_internal.h"
#include "access/xlogarchive.h"
#include "access/xlogrecovery.h"
#include "catalog/pg_authid.h"
#include "funcapi.h"
#include "libpq/pqformat.h"
#include "libpq/pqsignal.h"
#include "miscadmin.h"
#include "pgstat.h"
#include "postmaster/auxprocess.h"
#include "postmaster/interrupt.h"
#include "replication/walreceiver.h"
#include "replication/walsender.h"
#include "storage/ipc.h"
#include "storage/proc.h"
#include "storage/procarray.h"
#include "storage/procsignal.h"
#include "utils/acl.h"
#include "utils/builtins.h"
#include "utils/guc.h"
#include "utils/pg_lsn.h"
#include "utils/ps_status.h"
#include "utils/timestamp.h"
Go to the source code of this file.
Macros | |
#define | NUM_WALRCV_WAKEUPS (WALRCV_WAKEUP_HSFEEDBACK + 1) |
Typedefs | |
typedef enum WalRcvWakeupReason | WalRcvWakeupReason |
Enumerations | |
enum | WalRcvWakeupReason { WALRCV_WAKEUP_TERMINATE , WALRCV_WAKEUP_PING , WALRCV_WAKEUP_REPLY , WALRCV_WAKEUP_HSFEEDBACK } |
Variables | |
int | wal_receiver_status_interval |
int | wal_receiver_timeout |
bool | hot_standby_feedback |
static WalReceiverConn * | wrconn = NULL |
WalReceiverFunctionsType * | WalReceiverFunctions = NULL |
static int | recvFile = -1 |
static TimeLineID | recvFileTLI = 0 |
static XLogSegNo | recvSegNo = 0 |
struct { | |
XLogRecPtr Write | |
XLogRecPtr Flush | |
} | LogstreamResult |
static TimestampTz | wakeup [NUM_WALRCV_WAKEUPS] |
static StringInfoData | reply_message |
#define NUM_WALRCV_WAKEUPS (WALRCV_WAKEUP_HSFEEDBACK + 1) |
Definition at line 123 of file walreceiver.c.
typedef enum WalRcvWakeupReason WalRcvWakeupReason |
enum WalRcvWakeupReason |
Enumerator | |
---|---|
WALRCV_WAKEUP_TERMINATE | |
WALRCV_WAKEUP_PING | |
WALRCV_WAKEUP_REPLY | |
WALRCV_WAKEUP_HSFEEDBACK |
Definition at line 117 of file walreceiver.c.
Datum pg_stat_get_wal_receiver | ( | PG_FUNCTION_ARGS | ) |
Definition at line 1402 of file walreceiver.c.
References WalRcvData::conninfo, CStringGetTextDatum, elog, ERROR, WalRcvData::flushedUpto, get_call_result_type(), GetUserId(), has_privs_of_role(), heap_form_tuple(), HeapTupleGetDatum(), Int32GetDatum(), WalRcvData::lastMsgReceiptTime, WalRcvData::lastMsgSendTime, WalRcvData::latestWalEnd, WalRcvData::latestWalEndTime, LSNGetDatum(), MAXCONNINFO, WalRcvData::mutex, NAMEDATALEN, TupleDescData::natts, palloc0(), pg_atomic_read_u64(), PG_RETURN_DATUM, PG_RETURN_NULL, WalRcvData::pid, WalRcvData::ready_to_display, WalRcvData::receivedTLI, WalRcvData::receiveStart, WalRcvData::receiveStartTLI, WalRcvData::sender_host, WalRcvData::sender_port, WalRcvData::slotname, SpinLockAcquire, SpinLockRelease, strlcpy(), TimestampTzGetDatum(), TYPEFUNC_COMPOSITE, values, WalRcv, WalRcvGetStateString(), WalRcvData::walRcvState, WalRcvData::writtenUpto, and XLogRecPtrIsInvalid.
void ProcessWalRcvInterrupts | ( | void | ) |
Definition at line 162 of file walreceiver.c.
References CHECK_FOR_INTERRUPTS, ereport, errcode(), errmsg(), FATAL, and ShutdownRequestPending.
Referenced by libpqrcv_connect(), libpqrcv_PQgetResult(), libpqrcv_processTuples(), WalRcvWaitForStartPosition(), and WalReceiverMain().
|
static |
Definition at line 1266 of file walreceiver.c.
References DEBUG2, elog, GetCurrentTimestamp(), GetReplicationApplyDelay(), GetReplicationTransferLatency(), WalRcvData::lastMsgReceiptTime, WalRcvData::lastMsgSendTime, WalRcvData::latestWalEnd, WalRcvData::latestWalEndTime, message_level_is_interesting(), WalRcvData::mutex, pfree(), pstrdup(), SpinLockAcquire, SpinLockRelease, timestamptz_to_str(), and WalRcv.
Referenced by XLogWalRcvProcessMsg().
|
static |
Definition at line 1318 of file walreceiver.c.
References hot_standby_feedback, now(), TIMESTAMP_INFINITY, TimestampTzPlusMilliseconds, TimestampTzPlusSeconds, wakeup, wal_receiver_status_interval, wal_receiver_timeout, WALRCV_WAKEUP_HSFEEDBACK, WALRCV_WAKEUP_PING, WALRCV_WAKEUP_REPLY, and WALRCV_WAKEUP_TERMINATE.
Referenced by WalReceiverMain(), XLogWalRcvSendHSFeedback(), and XLogWalRcvSendReply().
|
static |
Definition at line 802 of file walreceiver.c.
References arg, Assert, ConditionVariableBroadcast(), DatumGetPointer(), INVALID_PROC_NUMBER, WalRcvData::mutex, MyProcPid, WalRcvData::pid, WalRcvData::procno, WalRcvData::ready_to_display, SpinLockAcquire, SpinLockRelease, WakeupRecovery(), WalRcv, walrcv_disconnect, WALRCV_RESTARTING, WALRCV_STARTING, WALRCV_STOPPED, WALRCV_STOPPING, WALRCV_STREAMING, WALRCV_WAITING, WalRcvData::walRcvState, WalRcvData::walRcvStoppedCV, wrconn, and XLogWalRcvFlush().
Referenced by WalReceiverMain().
|
static |
Definition at line 746 of file walreceiver.c.
References ARCHIVE_MODE_ALWAYS, ereport, errcode(), errmsg(), errmsg_internal(), ERROR, existsTimeLineHistory(), len, LOG, MAXFNAMELEN, pfree(), TLHistoryFileName(), walrcv_readtimelinehistoryfile, wrconn, writeTimeLineHistoryFile(), XLogArchiveForceDone(), XLogArchiveMode, and XLogArchiveNotify().
Referenced by WalReceiverMain().
void WalRcvForceReply | ( | void | ) |
Definition at line 1359 of file walreceiver.c.
References WalRcvData::force_reply, GetPGProcByNumber, INVALID_PROC_NUMBER, WalRcvData::mutex, WalRcvData::procno, SetLatch(), SpinLockAcquire, SpinLockRelease, and WalRcv.
Referenced by ApplyWalRecord(), and WaitForWALToBecomeAvailable().
|
static |
Definition at line 1377 of file walreceiver.c.
References WALRCV_RESTARTING, WALRCV_STARTING, WALRCV_STOPPED, WALRCV_STOPPING, WALRCV_STREAMING, and WALRCV_WAITING.
Referenced by pg_stat_get_wal_receiver().
|
static |
Definition at line 666 of file walreceiver.c.
References Assert, elog, exit(), FATAL, InvalidXLogRecPtr, LSN_FORMAT_ARGS, WalRcvData::mutex, MyLatch, proc_exit(), ProcessWalRcvInterrupts(), WalRcvData::receiveStart, WalRcvData::receiveStartTLI, ResetLatch(), set_ps_display(), snprintf, SpinLockAcquire, SpinLockRelease, update_process_title, WaitLatch(), WakeupRecovery(), WalRcv, WALRCV_RESTARTING, WALRCV_STOPPING, WALRCV_STREAMING, WALRCV_WAITING, WalRcvData::walRcvState, WL_EXIT_ON_PM_DEATH, and WL_LATCH_SET.
Referenced by WalReceiverMain().
void WalReceiverMain | ( | char * | startup_data, |
size_t | startup_data_len | ||
) |
Definition at line 183 of file walreceiver.c.
References ARCHIVE_MODE_ALWAYS, Assert, AuxiliaryProcessMainCommon(), B_WAL_RECEIVER, buf, close, cluster_name, ConditionVariableBroadcast(), ConfigReloadPending, WalRcvData::conninfo, DEBUG1, elog, ereport, err(), errcode(), errcode_for_file_access(), errdetail(), errmsg(), ERROR, FATAL, WalRcvData::force_reply, GetCurrentTimestamp(), GetSystemIdentifier(), GetXLogReplayRecPtr(), i, initStringInfo(), WalRcvData::is_temp_slot, WalRcvData::lastMsgReceiptTime, WalRcvData::lastMsgSendTime, WalRcvData::latestWalEndTime, len, load_file(), LOG, LogstreamResult, LSN_FORMAT_ARGS, MAXCONNINFO, MAXFNAMELEN, Min, WalRcvData::mutex, MyBackendType, MyLatch, MyProcNumber, MyProcPid, NAMEDATALEN, now(), NUM_WALRCV_WAKEUPS, on_shmem_exit(), options, PANIC, pfree(), pg_atomic_write_u64(), pg_memory_barrier, PGC_SIGHUP, PGINVALID_SOCKET, WalRcvData::pid, PointerGetDatum(), pqsignal(), proc_exit(), ProcessConfigFile(), ProcessWalRcvInterrupts(), WalRcvData::procno, procsignal_sigusr1_handler(), WalRcvData::ready_to_display, WalRcvData::receiveStart, WalRcvData::receiveStartTLI, RecoveryInProgress(), recvFile, recvFileTLI, recvSegNo, reply_message, ResetLatch(), WalRcvData::sender_host, WalRcvData::sender_port, SIG_DFL, SIG_IGN, SIGALRM, SIGCHLD, SIGHUP, SignalHandlerForConfigReload(), SignalHandlerForShutdownRequest(), SIGPIPE, SIGUSR1, SIGUSR2, WalRcvData::slotname, snprintf, SpinLockAcquire, SpinLockRelease, strlcpy(), TIMESTAMP_INFINITY, TimestampDifferenceMilliseconds(), UINT64_FORMAT, UnBlockSig, WaitLatchOrSocket(), wakeup, wal_segment_size, WalRcv, walrcv_connect, 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(), WalRcvData::walRcvState, WalRcvData::walRcvStoppedCV, WalRcvWaitForStartPosition(), WalReceiverFunctions, WL_EXIT_ON_PM_DEATH, WL_LATCH_SET, WL_SOCKET_READABLE, WL_TIMEOUT, wrconn, WalRcvData::writtenUpto, XLogArchiveForceDone(), XLogArchiveMode, XLogArchiveNotify(), XLogFileName(), XLogWalRcvFlush(), XLogWalRcvProcessMsg(), XLogWalRcvSendHSFeedback(), and XLogWalRcvSendReply().
|
static |
Definition at line 1049 of file walreceiver.c.
References ARCHIVE_MODE_ALWAYS, Assert, close, ereport, errcode_for_file_access(), errmsg(), MAXFNAMELEN, PANIC, recvFile, recvFileTLI, recvSegNo, wal_segment_size, XLByteInSeg, XLogArchiveForceDone(), XLogArchiveMode, XLogArchiveNotify(), XLogFileName(), and XLogWalRcvFlush().
Referenced by XLogWalRcvWrite().
|
static |
Definition at line 994 of file walreceiver.c.
References AllowCascadeReplication, Assert, WalRcvData::flushedUpto, issue_xlog_fsync(), WalRcvData::latestChunkStart, LogstreamResult, LSN_FORMAT_ARGS, WalRcvData::mutex, WalRcvData::receivedTLI, recvFile, recvSegNo, set_ps_display(), snprintf, SpinLockAcquire, SpinLockRelease, update_process_title, WakeupRecovery(), WalRcv, WalSndWakeup(), XLogWalRcvSendHSFeedback(), and XLogWalRcvSendReply().
Referenced by WalRcvDie(), WalReceiverMain(), and XLogWalRcvClose().
|
static |
Definition at line 840 of file walreceiver.c.
References buf, ereport, errcode(), errmsg_internal(), ERROR, initReadOnlyStringInfo(), len, pq_getmsgbyte(), pq_getmsgint64(), ProcessWalSndrMessage(), type, XLogWalRcvSendReply(), and XLogWalRcvWrite().
Referenced by WalReceiverMain().
|
static |
Definition at line 1170 of file walreceiver.c.
References StringInfoData::data, DEBUG2, elog, EpochFromFullTransactionId, GetCurrentTimestamp(), GetReplicationHorizons(), hot_standby_feedback, HotStandbyActive(), InvalidTransactionId, StringInfoData::len, now(), pq_sendbyte(), pq_sendint32(), pq_sendint64(), ReadNextFullTransactionId(), reply_message, resetStringInfo(), TransactionIdIsValid, wakeup, wal_receiver_status_interval, walrcv_send, WALRCV_WAKEUP_HSFEEDBACK, WalRcvComputeNextWakeup(), wrconn, and XidFromFullTransactionId.
Referenced by WalReceiverMain(), and XLogWalRcvFlush().
Definition at line 1101 of file walreceiver.c.
References StringInfoData::data, DEBUG2, elog, GetCurrentTimestamp(), GetXLogReplayRecPtr(), StringInfoData::len, LogstreamResult, LSN_FORMAT_ARGS, now(), pq_sendbyte(), pq_sendint64(), reply_message, resetStringInfo(), wakeup, wal_receiver_status_interval, walrcv_send, WALRCV_WAKEUP_REPLY, WalRcvComputeNextWakeup(), and wrconn.
Referenced by WalReceiverMain(), XLogWalRcvFlush(), and XLogWalRcvProcessMsg().
|
static |
Definition at line 911 of file walreceiver.c.
References Assert, buf, ereport, errcode_for_file_access(), errmsg(), LogstreamResult, MAXFNAMELEN, PANIC, pg_atomic_write_u64(), pg_pwrite, recvFile, recvFileTLI, recvSegNo, wal_segment_size, WalRcv, WalRcvData::writtenUpto, XLByteInSeg, XLByteToSeg, XLogFileInit(), XLogFileName(), XLogSegmentOffset, and XLogWalRcvClose().
Referenced by XLogWalRcvProcessMsg().
XLogRecPtr Flush |
Definition at line 111 of file walreceiver.c.
Referenced by XLogWrite().
bool hot_standby_feedback |
Definition at line 89 of file walreceiver.c.
Referenced by slotsync_reread_config(), ValidateSlotSyncParams(), WalRcvComputeNextWakeup(), and XLogWalRcvSendHSFeedback().
struct { ... } LogstreamResult |
Referenced by WalReceiverMain(), XLogWalRcvFlush(), XLogWalRcvSendReply(), and XLogWalRcvWrite().
|
static |
Definition at line 100 of file walreceiver.c.
Referenced by WalReceiverMain(), XLogWalRcvClose(), XLogWalRcvFlush(), and XLogWalRcvWrite().
|
static |
Definition at line 101 of file walreceiver.c.
Referenced by WalReceiverMain(), XLogWalRcvClose(), and XLogWalRcvWrite().
|
static |
Definition at line 102 of file walreceiver.c.
Referenced by WalReceiverMain(), XLogWalRcvClose(), XLogWalRcvFlush(), and XLogWalRcvWrite().
|
static |
Definition at line 131 of file walreceiver.c.
Referenced by send_feedback(), WalReceiverMain(), XLogWalRcvSendHSFeedback(), and XLogWalRcvSendReply().
|
static |
Definition at line 129 of file walreceiver.c.
Referenced by LWLockUpdateVar(), LWLockWakeup(), WalRcvComputeNextWakeup(), WalReceiverMain(), XLogSetAsyncXactLSN(), XLogWalRcvSendHSFeedback(), and XLogWalRcvSendReply().
int wal_receiver_status_interval |
Definition at line 87 of file walreceiver.c.
Referenced by send_feedback(), WalRcvComputeNextWakeup(), XLogWalRcvSendHSFeedback(), and XLogWalRcvSendReply().
int wal_receiver_timeout |
Definition at line 88 of file walreceiver.c.
Referenced by logicalrep_worker_launch(), LogicalRepApplyLoop(), and WalRcvComputeNextWakeup().
WalReceiverFunctionsType* WalReceiverFunctions = NULL |
Definition at line 93 of file walreceiver.c.
Referenced by _PG_init(), and WalReceiverMain().
|
static |
Definition at line 92 of file walreceiver.c.
Referenced by AlterSubscription(), AlterSubscription_refresh(), check_publications(), check_publications_origin(), CreateSubscription(), DropSubscription(), fetch_table_list(), pg_sync_replication_slots(), ReplicationSlotDropAtPubNode(), ReplSlotSyncWorkerMain(), slotsync_failure_callback(), slotsync_worker_disconnect(), synchronize_slots(), SyncReplicationSlots(), validate_remote_info(), WalRcvDie(), WalRcvFetchTimeLineHistoryFiles(), WalReceiverMain(), XLogWalRcvSendHSFeedback(), and XLogWalRcvSendReply().
XLogRecPtr Write |
Definition at line 110 of file walreceiver.c.
Referenced by XLogWrite().