2010-01-15 10:19:10 +01:00
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
*
|
|
|
|
* walreceiver.h
|
|
|
|
* Exports from replication/walreceiverfuncs.c.
|
|
|
|
*
|
2011-01-01 19:18:15 +01:00
|
|
|
* Portions Copyright (c) 2010-2011, PostgreSQL Global Development Group
|
2010-01-15 10:19:10 +01:00
|
|
|
*
|
2010-09-20 22:08:53 +02:00
|
|
|
* src/include/replication/walreceiver.h
|
2010-01-15 10:19:10 +01:00
|
|
|
*
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
#ifndef _WALRECEIVER_H
|
|
|
|
#define _WALRECEIVER_H
|
|
|
|
|
2011-09-04 02:46:19 +02:00
|
|
|
#include "access/xlog.h"
|
2010-01-20 10:16:24 +01:00
|
|
|
#include "access/xlogdefs.h"
|
2010-01-15 10:19:10 +01:00
|
|
|
#include "storage/spin.h"
|
2010-06-04 00:17:32 +02:00
|
|
|
#include "pgtime.h"
|
2010-01-15 10:19:10 +01:00
|
|
|
|
2010-02-19 11:51:04 +01:00
|
|
|
extern bool am_walreceiver;
|
2011-04-10 17:42:00 +02:00
|
|
|
extern int wal_receiver_status_interval;
|
2011-02-16 20:29:37 +01:00
|
|
|
extern bool hot_standby_feedback;
|
2010-02-19 11:51:04 +01:00
|
|
|
|
2010-01-15 10:19:10 +01:00
|
|
|
/*
|
|
|
|
* MAXCONNINFO: maximum size of a connection string.
|
|
|
|
*
|
|
|
|
* XXX: Should this move to pg_config_manual.h?
|
|
|
|
*/
|
|
|
|
#define MAXCONNINFO 1024
|
|
|
|
|
2011-09-04 02:46:19 +02:00
|
|
|
/* Can we allow the standby to accept replication connection from another standby? */
|
|
|
|
#define AllowCascadeReplication() (EnableHotStandby && max_wal_senders > 0)
|
|
|
|
|
2010-01-15 10:19:10 +01:00
|
|
|
/*
|
|
|
|
* Values for WalRcv->walRcvState.
|
|
|
|
*/
|
|
|
|
typedef enum
|
|
|
|
{
|
2010-02-26 03:01:40 +01:00
|
|
|
WALRCV_STOPPED, /* stopped and mustn't start up again */
|
|
|
|
WALRCV_STARTING, /* launched, but the process hasn't
|
|
|
|
* initialized yet */
|
|
|
|
WALRCV_RUNNING, /* walreceiver is running */
|
|
|
|
WALRCV_STOPPING /* requested to stop, but still running */
|
2010-01-15 10:19:10 +01:00
|
|
|
} WalRcvState;
|
|
|
|
|
|
|
|
/* Shared memory area for management of walreceiver process */
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
/*
|
2010-07-03 22:43:58 +02:00
|
|
|
* PID of currently active walreceiver process, its current state and
|
2010-07-06 21:19:02 +02:00
|
|
|
* start time (actually, the time at which it was requested to be
|
|
|
|
* started).
|
2010-01-15 10:19:10 +01:00
|
|
|
*/
|
2010-02-26 03:01:40 +01:00
|
|
|
pid_t pid;
|
2010-01-15 10:19:10 +01:00
|
|
|
WalRcvState walRcvState;
|
2010-02-26 03:01:40 +01:00
|
|
|
pg_time_t startTime;
|
2010-01-15 10:19:10 +01:00
|
|
|
|
2011-03-01 19:46:57 +01:00
|
|
|
/*
|
2011-04-10 17:42:00 +02:00
|
|
|
* receiveStart is the first byte position that will be received. When
|
|
|
|
* startup process starts the walreceiver, it sets receiveStart to the
|
|
|
|
* point where it wants the streaming to begin.
|
2011-03-01 19:46:57 +01:00
|
|
|
*/
|
|
|
|
XLogRecPtr receiveStart;
|
|
|
|
|
2010-01-15 10:19:10 +01:00
|
|
|
/*
|
2010-07-03 22:43:58 +02:00
|
|
|
* receivedUpto-1 is the last byte position that has already been
|
2011-04-10 17:42:00 +02:00
|
|
|
* received. At the first startup of walreceiver, receivedUpto is set to
|
|
|
|
* receiveStart. After that, walreceiver updates this whenever it flushes
|
|
|
|
* the received WAL to disk.
|
2010-01-15 10:19:10 +01:00
|
|
|
*/
|
|
|
|
XLogRecPtr receivedUpto;
|
|
|
|
|
2010-07-03 22:43:58 +02:00
|
|
|
/*
|
|
|
|
* latestChunkStart is the starting byte position of the current "batch"
|
|
|
|
* of received WAL. It's actually the same as the previous value of
|
2010-07-06 21:19:02 +02:00
|
|
|
* receivedUpto before the last flush to disk. Startup process can use
|
2010-07-03 22:43:58 +02:00
|
|
|
* this to detect whether it's keeping up or not.
|
|
|
|
*/
|
|
|
|
XLogRecPtr latestChunkStart;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* connection string; is used for walreceiver to connect with the primary.
|
|
|
|
*/
|
|
|
|
char conninfo[MAXCONNINFO];
|
|
|
|
|
2010-02-26 03:01:40 +01:00
|
|
|
slock_t mutex; /* locks shared variables shown above */
|
2010-01-15 10:19:10 +01:00
|
|
|
} WalRcvData;
|
|
|
|
|
2010-01-20 19:54:27 +01:00
|
|
|
extern WalRcvData *WalRcv;
|
2010-01-15 10:19:10 +01:00
|
|
|
|
2010-01-20 10:16:24 +01:00
|
|
|
/* libpqwalreceiver hooks */
|
|
|
|
typedef bool (*walrcv_connect_type) (char *conninfo, XLogRecPtr startpoint);
|
|
|
|
extern PGDLLIMPORT walrcv_connect_type walrcv_connect;
|
|
|
|
|
2010-02-03 10:47:19 +01:00
|
|
|
typedef bool (*walrcv_receive_type) (int timeout, unsigned char *type,
|
2010-02-26 03:01:40 +01:00
|
|
|
char **buffer, int *len);
|
2010-01-20 10:16:24 +01:00
|
|
|
extern PGDLLIMPORT walrcv_receive_type walrcv_receive;
|
|
|
|
|
2010-12-11 15:27:37 +01:00
|
|
|
typedef void (*walrcv_send_type) (const char *buffer, int nbytes);
|
|
|
|
extern PGDLLIMPORT walrcv_send_type walrcv_send;
|
|
|
|
|
2010-01-20 10:16:24 +01:00
|
|
|
typedef void (*walrcv_disconnect_type) (void);
|
|
|
|
extern PGDLLIMPORT walrcv_disconnect_type walrcv_disconnect;
|
|
|
|
|
2010-09-13 12:14:25 +02:00
|
|
|
/* prototypes for functions in walreceiver.c */
|
2010-01-20 10:16:24 +01:00
|
|
|
extern void WalReceiverMain(void);
|
2010-09-13 12:14:25 +02:00
|
|
|
|
|
|
|
/* prototypes for functions in walreceiverfuncs.c */
|
2010-01-15 10:19:10 +01:00
|
|
|
extern Size WalRcvShmemSize(void);
|
|
|
|
extern void WalRcvShmemInit(void);
|
Make standby server continuously retry restoring the next WAL segment with
restore_command, if the connection to the primary server is lost. This
ensures that the standby can recover automatically, if the connection is
lost for a long time and standby falls behind so much that the required
WAL segments have been archived and deleted in the master.
This also makes standby_mode useful without streaming replication; the
server will keep retrying restore_command every few seconds until the
trigger file is found. That's the same basic functionality pg_standby
offers, but without the bells and whistles.
To implement that, refactor the ReadRecord/FetchRecord functions. The
FetchRecord() function introduced in the original streaming replication
patch is removed, and all the retry logic is now in a new function called
XLogReadPage(). XLogReadPage() is now responsible for executing
restore_command, launching walreceiver, and waiting for new WAL to arrive
from primary, as required.
This also changes the life cycle of walreceiver. When launched, it now only
tries to connect to the master once, and exits if the connection fails, or
is lost during streaming for any reason. The startup process detects the
death, and re-launches walreceiver if necessary.
2010-01-27 16:27:51 +01:00
|
|
|
extern void ShutdownWalRcv(void);
|
2010-01-15 10:19:10 +01:00
|
|
|
extern bool WalRcvInProgress(void);
|
|
|
|
extern void RequestXLogStreaming(XLogRecPtr recptr, const char *conninfo);
|
2010-07-03 22:43:58 +02:00
|
|
|
extern XLogRecPtr GetWalRcvWriteRecPtr(XLogRecPtr *latestChunkStart);
|
2010-01-15 10:19:10 +01:00
|
|
|
|
|
|
|
#endif /* _WALRECEIVER_H */
|