PostgreSQL Source Code git master
walsender_private.h
Go to the documentation of this file.
1/*-------------------------------------------------------------------------
2 *
3 * walsender_private.h
4 * Private definitions from replication/walsender.c.
5 *
6 * Portions Copyright (c) 2010-2025, PostgreSQL Global Development Group
7 *
8 * src/include/replication/walsender_private.h
9 *
10 *-------------------------------------------------------------------------
11 */
12#ifndef _WALSENDER_PRIVATE_H
13#define _WALSENDER_PRIVATE_H
14
15#include "access/xlog.h"
16#include "lib/ilist.h"
17#include "nodes/nodes.h"
18#include "nodes/replnodes.h"
19#include "replication/syncrep.h"
21#include "storage/shmem.h"
22#include "storage/spin.h"
23
24typedef enum WalSndState
25{
32
33/*
34 * Each walsender has a WalSnd struct in shared memory.
35 *
36 * This struct is protected by its 'mutex' spinlock field, except that some
37 * members are only written by the walsender process itself, and thus that
38 * process is free to read those members without holding spinlock. pid and
39 * needreload always require the spinlock to be held for all accesses.
40 */
41typedef struct WalSnd
42{
43 pid_t pid; /* this walsender's PID, or 0 if not active */
44
45 WalSndState state; /* this walsender's state */
46 XLogRecPtr sentPtr; /* WAL has been sent up to this point */
47 bool needreload; /* does currently-open file need to be
48 * reloaded? */
49
50 /*
51 * The xlog locations that have been written, flushed, and applied by
52 * standby-side. These may be invalid if the standby-side has not offered
53 * values yet.
54 */
58
59 /* Measured lag times, or -1 for unknown/none. */
63
64 /*
65 * The priority order of the standby managed by this WALSender, as listed
66 * in synchronous_standby_names, or 0 if not-listed.
67 */
69
70 /* Protects shared variables in this structure. */
71 slock_t mutex;
72
73 /*
74 * Timestamp of the last message received from standby.
75 */
77
80
82
83/* There is one WalSndCtl struct for the whole database cluster */
84typedef struct
85{
86 /*
87 * Synchronous replication queue with one queue per request type.
88 * Protected by SyncRepLock.
89 */
91
92 /*
93 * Current location of the head of the queue. All waiters should have a
94 * waitLSN that follows this value. Protected by SyncRepLock.
95 */
97
98 /*
99 * Status of data related to the synchronous standbys. Waiting backends
100 * can't reload the config file safely, so checkpointer updates this value
101 * as needed. Protected by SyncRepLock.
102 */
104
105 /* used as a registry of physical / logical walsenders to wake */
108
109 /*
110 * Used by physical walsenders holding slots specified in
111 * synchronized_standby_slots to wake up logical walsenders holding
112 * logical failover slots when a walreceiver confirms the receipt of LSN.
113 */
115
118
119/* Flags for WalSndCtlData->sync_standbys_status */
120
121/*
122 * Is the synchronous standby data initialized from the GUC? This is set the
123 * first time synchronous_standby_names is processed by the checkpointer.
124 */
125#define SYNC_STANDBY_INIT (1 << 0)
126
127/*
128 * Is the synchronous standby data defined? This is set when
129 * synchronous_standby_names has some data, after being processed by the
130 * checkpointer.
131 */
132#define SYNC_STANDBY_DEFINED (1 << 1)
133
135
136
137extern void WalSndSetState(WalSndState state);
138
139/*
140 * Internal functions for parsing the replication grammar, in repl_gram.y and
141 * repl_scanner.l
142 */
143union YYSTYPE;
144#ifndef YY_TYPEDEF_YY_SCANNER_T
145#define YY_TYPEDEF_YY_SCANNER_T
146typedef void *yyscan_t;
147#endif
148extern int replication_yyparse(Node **replication_parse_result_p, yyscan_t yyscanner);
149extern int replication_yylex(union YYSTYPE *yylval_param, yyscan_t yyscanner);
150pg_noreturn extern void replication_yyerror(Node **replication_parse_result_p, yyscan_t yyscanner, const char *message);
151extern void replication_scanner_init(const char *str, yyscan_t *yyscannerp);
152extern void replication_scanner_finish(yyscan_t yyscanner);
154
155#endif /* _WALSENDER_PRIVATE_H */
#define PGDLLIMPORT
Definition: c.h:1291
#define pg_noreturn
Definition: c.h:165
#define FLEXIBLE_ARRAY_MEMBER
Definition: c.h:434
uint8 bits8
Definition: c.h:509
void * yyscan_t
Definition: cubedata.h:67
int64 TimestampTz
Definition: timestamp.h:39
int64 TimeOffset
Definition: timestamp.h:40
const char * str
#define yyscan_t
Definition: pgbench.h:23
int YYSTYPE
Definition: psqlscanslash.l:39
ReplicationKind
Definition: replnodes.h:21
Definition: nodes.h:135
ConditionVariable wal_confirm_rcv_cv
ConditionVariable wal_replay_cv
ConditionVariable wal_flush_cv
TimeOffset writeLag
slock_t mutex
XLogRecPtr flush
XLogRecPtr sentPtr
TimeOffset flushLag
WalSndState state
ReplicationKind kind
XLogRecPtr write
TimeOffset applyLag
int sync_standby_priority
bool needreload
TimestampTz replyTime
XLogRecPtr apply
Definition: regguts.h:323
#define NUM_SYNC_REP_WAIT_MODE
Definition: syncrep.h:27
pg_noreturn void replication_yyerror(Node **replication_parse_result_p, yyscan_t yyscanner, const char *message)
Definition: repl_scanner.l:260
WalSndState
@ WALSNDSTATE_STREAMING
@ WALSNDSTATE_BACKUP
@ WALSNDSTATE_CATCHUP
@ WALSNDSTATE_STARTUP
@ WALSNDSTATE_STOPPING
bool replication_scanner_is_replication_command(yyscan_t yyscanner)
Definition: repl_scanner.l:299
int replication_yyparse(Node **replication_parse_result_p, yyscan_t yyscanner)
void WalSndSetState(WalSndState state)
Definition: walsender.c:3838
PGDLLIMPORT WalSndCtlData * WalSndCtl
Definition: walsender.c:114
struct WalSnd WalSnd
void replication_scanner_finish(yyscan_t yyscanner)
Definition: repl_scanner.l:284
PGDLLIMPORT WalSnd * MyWalSnd
Definition: walsender.c:117
void replication_scanner_init(const char *str, yyscan_t *yyscannerp)
Definition: repl_scanner.l:268
int replication_yylex(union YYSTYPE *yylval_param, yyscan_t yyscanner)
uint64 XLogRecPtr
Definition: xlogdefs.h:21