1 /*-------------------------------------------------------------------------
4 * Exports from replication/walreceiverfuncs.c.
6 * Portions Copyright (c) 2010-2012, PostgreSQL Global Development Group
8 * src/include/replication/walreceiver.h
10 *-------------------------------------------------------------------------
12 #ifndef _WALRECEIVER_H
13 #define _WALRECEIVER_H
15 #include "access/xlog.h"
16 #include "access/xlogdefs.h"
17 #include "storage/spin.h"
20 extern bool am_walreceiver;
21 extern int wal_receiver_status_interval;
22 extern bool hot_standby_feedback;
25 * MAXCONNINFO: maximum size of a connection string.
27 * XXX: Should this move to pg_config_manual.h?
29 #define MAXCONNINFO 1024
31 /* Can we allow the standby to accept replication connection from another standby? */
32 #define AllowCascadeReplication() (EnableHotStandby && max_wal_senders > 0)
35 * Values for WalRcv->walRcvState.
39 WALRCV_STOPPED, /* stopped and mustn't start up again */
40 WALRCV_STARTING, /* launched, but the process hasn't
42 WALRCV_RUNNING, /* walreceiver is running */
43 WALRCV_STOPPING /* requested to stop, but still running */
46 /* Shared memory area for management of walreceiver process */
50 * PID of currently active walreceiver process, its current state and
51 * start time (actually, the time at which it was requested to be
55 WalRcvState walRcvState;
59 * receiveStart is the first byte position that will be received. When
60 * startup process starts the walreceiver, it sets receiveStart to the
61 * point where it wants the streaming to begin.
63 XLogRecPtr receiveStart;
66 * receivedUpto-1 is the last byte position that has already been
67 * received. At the first startup of walreceiver, receivedUpto is set to
68 * receiveStart. After that, walreceiver updates this whenever it flushes
69 * the received WAL to disk.
71 XLogRecPtr receivedUpto;
74 * latestChunkStart is the starting byte position of the current "batch"
75 * of received WAL. It's actually the same as the previous value of
76 * receivedUpto before the last flush to disk. Startup process can use
77 * this to detect whether it's keeping up or not.
79 XLogRecPtr latestChunkStart;
82 * Time of send and receive of any message received.
84 TimestampTz lastMsgSendTime;
85 TimestampTz lastMsgReceiptTime;
88 * connection string; is used for walreceiver to connect with the primary.
90 char conninfo[MAXCONNINFO];
92 slock_t mutex; /* locks shared variables shown above */
95 extern WalRcvData *WalRcv;
97 /* libpqwalreceiver hooks */
98 typedef bool (*walrcv_connect_type) (char *conninfo, XLogRecPtr startpoint);
99 extern PGDLLIMPORT walrcv_connect_type walrcv_connect;
101 typedef bool (*walrcv_receive_type) (int timeout, unsigned char *type,
102 char **buffer, int *len);
103 extern PGDLLIMPORT walrcv_receive_type walrcv_receive;
105 typedef void (*walrcv_send_type) (const char *buffer, int nbytes);
106 extern PGDLLIMPORT walrcv_send_type walrcv_send;
108 typedef void (*walrcv_disconnect_type) (void);
109 extern PGDLLIMPORT walrcv_disconnect_type walrcv_disconnect;
111 /* prototypes for functions in walreceiver.c */
112 extern void WalReceiverMain(void);
114 /* prototypes for functions in walreceiverfuncs.c */
115 extern Size WalRcvShmemSize(void);
116 extern void WalRcvShmemInit(void);
117 extern void ShutdownWalRcv(void);
118 extern bool WalRcvInProgress(void);
119 extern void RequestXLogStreaming(XLogRecPtr recptr, const char *conninfo);
120 extern XLogRecPtr GetWalRcvWriteRecPtr(XLogRecPtr *latestChunkStart);
121 extern int GetReplicationApplyDelay(void);
122 extern int GetReplicationTransferLatency(void);
124 #endif /* _WALRECEIVER_H */