PostgreSQL Source Code git master
Loading...
Searching...
No Matches
libpqwalreceiver.c File Reference
#include "postgres.h"
#include <unistd.h>
#include <sys/time.h>
#include "common/connect.h"
#include "funcapi.h"
#include "libpq-fe.h"
#include "libpq/libpq-be-fe-helpers.h"
#include "mb/pg_wchar.h"
#include "miscadmin.h"
#include "pgstat.h"
#include "pqexpbuffer.h"
#include "replication/walreceiver.h"
#include "storage/latch.h"
#include "utils/builtins.h"
#include "utils/memutils.h"
#include "utils/pg_lsn.h"
#include "utils/tuplestore.h"
Include dependency graph for libpqwalreceiver.c:

Go to the source code of this file.

Data Structures

struct  WalReceiverConn
 

Macros

#define appendQuotedIdentifier(b, s)   appendQuotedString(b, s, '"')
 
#define appendQuotedLiteral(b, s)   appendQuotedString(b, s, '\'')
 

Functions

 PG_MODULE_MAGIC_EXT (.name="libpqwalreceiver",.version=PG_VERSION)
 
static WalReceiverConnlibpqrcv_connect (const char *conninfo, bool replication, bool logical, bool must_use_password, const char *appname, char **err)
 
static void libpqrcv_check_conninfo (const char *conninfo, bool must_use_password)
 
static charlibpqrcv_get_conninfo (WalReceiverConn *conn)
 
static void libpqrcv_get_senderinfo (WalReceiverConn *conn, char **sender_host, int *sender_port)
 
static charlibpqrcv_identify_system (WalReceiverConn *conn, TimeLineID *primary_tli)
 
static charlibpqrcv_get_dbname_from_conninfo (const char *connInfo)
 
static charlibpqrcv_get_option_from_conninfo (const char *connInfo, const char *keyword)
 
static int libpqrcv_server_version (WalReceiverConn *conn)
 
static void libpqrcv_readtimelinehistoryfile (WalReceiverConn *conn, TimeLineID tli, char **filename, char **content, int *len)
 
static bool libpqrcv_startstreaming (WalReceiverConn *conn, const WalRcvStreamOptions *options)
 
static void libpqrcv_endstreaming (WalReceiverConn *conn, TimeLineID *next_tli)
 
static int libpqrcv_receive (WalReceiverConn *conn, char **buffer, pgsocket *wait_fd)
 
static void libpqrcv_send (WalReceiverConn *conn, const char *buffer, int nbytes)
 
static charlibpqrcv_create_slot (WalReceiverConn *conn, const char *slotname, bool temporary, bool two_phase, bool failover, CRSSnapshotAction snapshot_action, XLogRecPtr *lsn)
 
static void libpqrcv_alter_slot (WalReceiverConn *conn, const char *slotname, const bool *failover, const bool *two_phase)
 
static pid_t libpqrcv_get_backend_pid (WalReceiverConn *conn)
 
static WalRcvExecResultlibpqrcv_exec (WalReceiverConn *conn, const char *query, const int nRetTypes, const Oid *retTypes)
 
static void libpqrcv_disconnect (WalReceiverConn *conn)
 
static charstringlist_to_identifierstr (List *strings)
 
void _PG_init (void)
 
static void appendQuotedString (StringInfo buf, const char *str, char quote)
 
static void libpqrcv_processTuples (PGresult *pgres, WalRcvExecResult *walres, const int nRetTypes, const Oid *retTypes)
 

Variables

static WalReceiverFunctionsType PQWalReceiverFunctions
 

Macro Definition Documentation

◆ appendQuotedIdentifier

#define appendQuotedIdentifier (   b,
 
)    appendQuotedString(b, s, '"')

Definition at line 548 of file libpqwalreceiver.c.

◆ appendQuotedLiteral

#define appendQuotedLiteral (   b,
 
)    appendQuotedString(b, s, '\'')

Definition at line 549 of file libpqwalreceiver.c.

Function Documentation

◆ _PG_init()

void _PG_init ( void  )

Definition at line 125 of file libpqwalreceiver.c.

126{
128 elog(ERROR, "libpqwalreceiver already loaded");
130}
#define ERROR
Definition elog.h:40
#define elog(elevel,...)
Definition elog.h:228
static WalReceiverFunctionsType PQWalReceiverFunctions
static int fb(int x)
WalReceiverFunctionsType * WalReceiverFunctions
Definition walreceiver.c:96

References elog, ERROR, fb(), PQWalReceiverFunctions, and WalReceiverFunctions.

◆ appendQuotedString()

static void appendQuotedString ( StringInfo  buf,
const char str,
char  quote 
)
static

Definition at line 534 of file libpqwalreceiver.c.

535{
537 while (*str)
538 {
539 char c = *str++;
540
541 if (c == quote)
544 }
546}
const char * str
static char buf[DEFAULT_XLOG_SEG_SIZE]
char * c
void appendStringInfoChar(StringInfo str, char ch)
Definition stringinfo.c:242

References appendStringInfoChar(), buf, and str.

◆ libpqrcv_alter_slot()

static void libpqrcv_alter_slot ( WalReceiverConn conn,
const char slotname,
const bool failover,
const bool two_phase 
)
static

Definition at line 1021 of file libpqwalreceiver.c.

1023{
1024 StringInfoData cmd;
1025 PGresult *res;
1026
1027 initStringInfo(&cmd);
1028 appendStringInfoString(&cmd, "ALTER_REPLICATION_SLOT ");
1029 appendQuotedIdentifier(&cmd, slotname);
1030 appendStringInfoString(&cmd, " ( ");
1031
1032 if (failover)
1033 appendStringInfo(&cmd, "FAILOVER %s",
1034 *failover ? "true" : "false");
1035
1036 if (failover && two_phase)
1037 appendStringInfoString(&cmd, ", ");
1038
1039 if (two_phase)
1040 appendStringInfo(&cmd, "TWO_PHASE %s",
1041 *two_phase ? "true" : "false");
1042
1043 appendStringInfoString(&cmd, " );");
1044
1045 res = libpqsrv_exec(conn->streamConn, cmd.data,
1047 pfree(cmd.data);
1048
1049 if (PQresultStatus(res) != PGRES_COMMAND_OK)
1050 ereport(ERROR,
1052 errmsg("could not alter replication slot \"%s\": %s",
1053 slotname, pchomp(PQerrorMessage(conn->streamConn)))));
1054
1055 PQclear(res);
1056}
int errcode(int sqlerrcode)
Definition elog.c:875
#define ereport(elevel,...)
Definition elog.h:152
#define ERRCODE_PROTOCOL_VIOLATION
Definition fe-connect.c:96
char * PQerrorMessage(const PGconn *conn)
static PGresult * libpqsrv_exec(PGconn *conn, const char *query, uint32 wait_event_info)
#define PQclear
#define PQresultStatus
@ PGRES_COMMAND_OK
Definition libpq-fe.h:131
#define appendQuotedIdentifier(b, s)
void pfree(void *pointer)
Definition mcxt.c:1619
char * pchomp(const char *in)
Definition mcxt.c:1938
static char * errmsg
static bool two_phase
static bool failover
PGconn * conn
Definition streamutil.c:52
void appendStringInfo(StringInfo str, const char *fmt,...)
Definition stringinfo.c:145
void appendStringInfoString(StringInfo str, const char *s)
Definition stringinfo.c:230
void initStringInfo(StringInfo str)
Definition stringinfo.c:97

References appendQuotedIdentifier, appendStringInfo(), appendStringInfoString(), conn, StringInfoData::data, ereport, errcode(), ERRCODE_PROTOCOL_VIOLATION, errmsg, ERROR, failover, fb(), initStringInfo(), libpqsrv_exec(), pchomp(), pfree(), PGRES_COMMAND_OK, PQclear, PQerrorMessage(), PQresultStatus, and two_phase.

◆ libpqrcv_check_conninfo()

static void libpqrcv_check_conninfo ( const char conninfo,
bool  must_use_password 
)
static

Definition at line 296 of file libpqwalreceiver.c.

297{
299 PQconninfoOption *opt;
300 char *err = NULL;
301
302 opts = PQconninfoParse(conninfo, &err);
303 if (opts == NULL)
304 {
305 /* The error string is malloc'd, so we must free it explicitly */
306 char *errcopy = err ? pstrdup(err) : "out of memory";
307
308 PQfreemem(err);
311 errmsg("invalid connection string syntax: %s", errcopy)));
312 }
313
315 {
316 bool uses_password = false;
317
318 for (opt = opts; opt->keyword != NULL; ++opt)
319 {
320 /* Ignore connection options that are not present. */
321 if (opt->val == NULL)
322 continue;
323
324 if (strcmp(opt->keyword, "password") == 0 && opt->val[0] != '\0')
325 {
326 uses_password = true;
327 break;
328 }
329 }
330
331 if (!uses_password)
332 {
333 /* malloc'd, so we must free it explicitly */
335
338 errmsg("password is required"),
339 errdetail("Non-superusers must provide a password in the connection string.")));
340 }
341 }
342
344}
int errdetail(const char *fmt,...) pg_attribute_printf(1
void err(int eval, const char *fmt,...)
Definition err.c:43
void PQconninfoFree(PQconninfoOption *connOptions)
PQconninfoOption * PQconninfoParse(const char *conninfo, char **errmsg)
void PQfreemem(void *ptr)
Definition fe-exec.c:4068
char * pstrdup(const char *in)
Definition mcxt.c:1910
static AmcheckOptions opts
Definition pg_amcheck.c:112

References ereport, err(), errcode(), errdetail(), errmsg, ERROR, fb(), _PQconninfoOption::keyword, opts, PQconninfoFree(), PQconninfoParse(), PQfreemem(), pstrdup(), and _PQconninfoOption::val.

Referenced by libpqrcv_connect().

◆ libpqrcv_connect()

static WalReceiverConn * libpqrcv_connect ( const char conninfo,
bool  replication,
bool  logical,
bool  must_use_password,
const char appname,
char **  err 
)
static

Definition at line 148 of file libpqwalreceiver.c.

150{
152 const char *keys[6];
153 const char *vals[6];
154 int i = 0;
155 char *options_val = NULL;
156
157 /*
158 * Re-validate connection string. The validation already happened at DDL
159 * time, but the subscription owner may have changed. If we don't recheck
160 * with the correct must_use_password, it's possible that the connection
161 * will obtain the password from a different source, such as PGPASSFILE or
162 * PGPASSWORD.
163 */
165
166 /*
167 * We use the expand_dbname parameter to process the connection string (or
168 * URI), and pass some extra options.
169 */
170 keys[i] = "dbname";
171 vals[i] = conninfo;
172
173 /* We can not have logical without replication */
174 Assert(replication || !logical);
175
176 if (replication)
177 {
178 keys[++i] = "replication";
179 vals[i] = logical ? "database" : "true";
180
181 if (logical)
182 {
183 char *opt = NULL;
184
185 /* Tell the publisher to translate to our encoding */
186 keys[++i] = "client_encoding";
187 vals[i] = GetDatabaseEncodingName();
188
189 /*
190 * Force assorted GUC parameters to settings that ensure that the
191 * publisher will output data values in a form that is unambiguous
192 * to the subscriber. (We don't want to modify the subscriber's
193 * GUC settings, since that might surprise user-defined code
194 * running in the subscriber, such as triggers.) This should
195 * match what pg_dump does.
196 */
197 opt = libpqrcv_get_option_from_conninfo(conninfo, "options");
198 options_val = psprintf("%s -c datestyle=ISO -c intervalstyle=postgres -c extra_float_digits=3",
199 (opt == NULL) ? "" : opt);
200 keys[++i] = "options";
201 vals[i] = options_val;
202 if (opt != NULL)
203 pfree(opt);
204 }
205 else
206 {
207 /*
208 * The database name is ignored by the server in replication mode,
209 * but specify "replication" for .pgpass lookup.
210 */
211 keys[++i] = "dbname";
212 vals[i] = "replication";
213 }
214 }
215
216 keys[++i] = "fallback_application_name";
217 vals[i] = appname;
218
219 keys[++i] = NULL;
220 vals[i] = NULL;
221
222 Assert(i < lengthof(keys));
223
225 conn->streamConn =
227 /* expand_dbname = */ true);
229 "received message via replication");
232
233 if (options_val != NULL)
235
236 if (PQstatus(conn->streamConn) != CONNECTION_OK)
238
240 {
241 libpqsrv_disconnect(conn->streamConn);
242 pfree(conn);
243
246 errmsg("password is required"),
247 errdetail("Non-superuser cannot connect if the server does not request a password."),
248 errhint("Target server's authentication method must be changed, or set password_required=false in the subscription parameters.")));
249 }
250
251 /*
252 * Set always-secure search path for the cases where the connection is
253 * used to run SQL queries, so malicious users can't get control.
254 */
255 if (!replication || logical)
256 {
257 PGresult *res;
258
259 res = libpqsrv_exec(conn->streamConn,
263 {
264 PQclear(res);
265 *err = psprintf(_("could not clear search path: %s"),
266 pchomp(PQerrorMessage(conn->streamConn)));
267 goto bad_connection;
268 }
269 PQclear(res);
270 }
271
272 conn->logical = logical;
273
274 return conn;
275
276 /* error path, using libpq's error message */
278 *err = pchomp(PQerrorMessage(conn->streamConn));
279
280 /* error path, error already set */
282 libpqsrv_disconnect(conn->streamConn);
283 pfree(conn);
284 return NULL;
285}
#define Assert(condition)
Definition c.h:1002
#define lengthof(array)
Definition c.h:932
#define ALWAYS_SECURE_SEARCH_PATH_SQL
Definition connect.h:25
#define _(x)
Definition elog.c:96
int errhint(const char *fmt,...) pg_attribute_printf(1
int PQconnectionUsedPassword(const PGconn *conn)
ConnStatusType PQstatus(const PGconn *conn)
PQnoticeReceiver PQsetNoticeReceiver(PGconn *conn, PQnoticeReceiver proc, void *arg)
#define palloc0_object(type)
Definition fe_memutils.h:90
int i
Definition isn.c:77
static void libpqsrv_connect_complete(PGconn *conn, uint32 wait_event_info)
static void libpqsrv_notice_receiver(void *arg, const PGresult *res)
static void libpqsrv_disconnect(PGconn *conn)
static PGconn * libpqsrv_connect_params_start(const char *const *keywords, const char *const *values, int expand_dbname)
@ CONNECTION_OK
Definition libpq-fe.h:90
@ PGRES_TUPLES_OK
Definition libpq-fe.h:134
static void libpqrcv_check_conninfo(const char *conninfo, bool must_use_password)
static char * libpqrcv_get_option_from_conninfo(const char *connInfo, const char *keyword)
const char * GetDatabaseEncodingName(void)
Definition mbutils.c:1395
char * psprintf(const char *fmt,...)
Definition psprintf.c:43

References _, ALWAYS_SECURE_SEARCH_PATH_SQL, Assert, conn, CONNECTION_OK, ereport, err(), errcode(), errdetail(), errhint(), errmsg, ERROR, fb(), GetDatabaseEncodingName(), i, lengthof, libpqrcv_check_conninfo(), libpqrcv_get_option_from_conninfo(), libpqsrv_connect_complete(), libpqsrv_connect_params_start(), libpqsrv_disconnect(), libpqsrv_exec(), libpqsrv_notice_receiver(), palloc0_object, pchomp(), pfree(), PGRES_TUPLES_OK, PQclear, PQconnectionUsedPassword(), PQerrorMessage(), PQresultStatus, PQsetNoticeReceiver(), PQstatus(), and psprintf().

◆ libpqrcv_create_slot()

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

Definition at line 908 of file libpqwalreceiver.c.

911{
912 PGresult *res;
913 StringInfoData cmd;
914 char *snapshot;
916
917 use_new_options_syntax = (PQserverVersion(conn->streamConn) >= 150000);
918
919 initStringInfo(&cmd);
920
921 appendStringInfoString(&cmd, "CREATE_REPLICATION_SLOT ");
922 appendQuotedIdentifier(&cmd, slotname);
923
924 if (temporary)
925 appendStringInfoString(&cmd, " TEMPORARY");
926
927 if (conn->logical)
928 {
929 appendStringInfoString(&cmd, " LOGICAL pgoutput ");
931 appendStringInfoChar(&cmd, '(');
932 if (two_phase)
933 {
934 appendStringInfoString(&cmd, "TWO_PHASE");
936 appendStringInfoString(&cmd, ", ");
937 else
938 appendStringInfoChar(&cmd, ' ');
939 }
940
941 if (failover)
942 {
943 appendStringInfoString(&cmd, "FAILOVER");
945 appendStringInfoString(&cmd, ", ");
946 else
947 appendStringInfoChar(&cmd, ' ');
948 }
949
951 {
952 switch (snapshot_action)
953 {
955 appendStringInfoString(&cmd, "SNAPSHOT 'export'");
956 break;
958 appendStringInfoString(&cmd, "SNAPSHOT 'nothing'");
959 break;
960 case CRS_USE_SNAPSHOT:
961 appendStringInfoString(&cmd, "SNAPSHOT 'use'");
962 break;
963 }
964 }
965 else
966 {
967 switch (snapshot_action)
968 {
970 appendStringInfoString(&cmd, "EXPORT_SNAPSHOT");
971 break;
973 appendStringInfoString(&cmd, "NOEXPORT_SNAPSHOT");
974 break;
975 case CRS_USE_SNAPSHOT:
976 appendStringInfoString(&cmd, "USE_SNAPSHOT");
977 break;
978 }
979 }
980
982 appendStringInfoChar(&cmd, ')');
983 }
984 else
985 {
987 appendStringInfoString(&cmd, " PHYSICAL (RESERVE_WAL)");
988 else
989 appendStringInfoString(&cmd, " PHYSICAL RESERVE_WAL");
990 }
991
992 res = libpqsrv_exec(conn->streamConn,
993 cmd.data,
995 pfree(cmd.data);
996
1000 errmsg("could not create replication slot \"%s\": %s",
1001 slotname, pchomp(PQerrorMessage(conn->streamConn)))));
1002
1003 if (lsn)
1005 CStringGetDatum(PQgetvalue(res, 0, 1))));
1006
1007 if (!PQgetisnull(res, 0, 2))
1008 snapshot = pstrdup(PQgetvalue(res, 0, 2));
1009 else
1010 snapshot = NULL;
1011
1012 PQclear(res);
1013
1014 return snapshot;
1015}
int PQserverVersion(const PGconn *conn)
Datum DirectFunctionCall1Coll(PGFunction func, Oid collation, Datum arg1)
Definition fmgr.c:794
#define PQgetvalue
#define PQgetisnull
Datum pg_lsn_in(PG_FUNCTION_ARGS)
Definition pg_lsn.c:64
static XLogRecPtr DatumGetLSN(Datum X)
Definition pg_lsn.h:25
static Datum CStringGetDatum(const char *X)
Definition postgres.h:383
#define InvalidOid
@ CRS_USE_SNAPSHOT
Definition walsender.h:24
@ CRS_NOEXPORT_SNAPSHOT
Definition walsender.h:23
@ CRS_EXPORT_SNAPSHOT
Definition walsender.h:22

◆ libpqrcv_disconnect()

static void libpqrcv_disconnect ( WalReceiverConn conn)
static

Definition at line 779 of file libpqwalreceiver.c.

780{
781 libpqsrv_disconnect(conn->streamConn);
782 PQfreemem(conn->recvBuf);
783 pfree(conn);
784}

◆ libpqrcv_endstreaming()

static void libpqrcv_endstreaming ( WalReceiverConn conn,
TimeLineID next_tli 
)
static

Definition at line 658 of file libpqwalreceiver.c.

659{
660 PGresult *res;
661
662 /*
663 * Send copy-end message. As in libpqsrv_exec, this could theoretically
664 * block, but the risk seems small.
665 */
666 if (PQputCopyEnd(conn->streamConn, NULL) <= 0 ||
667 PQflush(conn->streamConn))
670 errmsg("could not send end-of-streaming message to primary: %s",
671 pchomp(PQerrorMessage(conn->streamConn)))));
672
673 *next_tli = 0;
674
675 /*
676 * After COPY is finished, we should receive a result set indicating the
677 * next timeline's ID, or just CommandComplete if the server was shut
678 * down.
679 *
680 * If we had not yet received CopyDone from the backend, PGRES_COPY_OUT is
681 * also possible in case we aborted the copy in mid-stream.
682 */
683 res = libpqsrv_get_result(conn->streamConn,
686 {
687 /*
688 * Read the next timeline's ID. The server also sends the timeline's
689 * starting point, but it is ignored.
690 */
691 if (PQnfields(res) < 2 || PQntuples(res) != 1)
694 errmsg("unexpected result set after end-of-streaming")));
695 *next_tli = pg_strtoint32(PQgetvalue(res, 0, 0));
696 PQclear(res);
697
698 /* the result set should be followed by CommandComplete */
699 res = libpqsrv_get_result(conn->streamConn,
701 }
702 else if (PQresultStatus(res) == PGRES_COPY_OUT)
703 {
704 PQclear(res);
705
706 /* End the copy */
707 if (PQendcopy(conn->streamConn))
710 errmsg("error while shutting down streaming COPY: %s",
711 pchomp(PQerrorMessage(conn->streamConn)))));
712
713 /* CommandComplete should follow */
714 res = libpqsrv_get_result(conn->streamConn,
716 }
717
721 errmsg("error reading result of streaming command: %s",
722 pchomp(PQerrorMessage(conn->streamConn)))));
723 PQclear(res);
724
725 /* Verify that there are no more results */
726 res = libpqsrv_get_result(conn->streamConn,
728 if (res != NULL)
731 errmsg("unexpected result after CommandComplete: %s",
732 pchomp(PQerrorMessage(conn->streamConn)))));
733}
int PQflush(PGconn *conn)
Definition fe-exec.c:4036
int PQendcopy(PGconn *conn)
Definition fe-exec.c:2966
int PQputCopyEnd(PGconn *conn, const char *errormsg)
Definition fe-exec.c:2766
static PGresult * libpqsrv_get_result(PGconn *conn, uint32 wait_event_info)
#define PQnfields
#define PQntuples
@ PGRES_COPY_OUT
Definition libpq-fe.h:137
int32 pg_strtoint32(const char *s)
Definition numutils.c:382

◆ libpqrcv_exec()

static WalRcvExecResult * libpqrcv_exec ( WalReceiverConn conn,
const char query,
const int  nRetTypes,
const Oid retTypes 
)
static

Definition at line 1148 of file libpqwalreceiver.c.

1150{
1151 PGresult *pgres = NULL;
1153 char *diag_sqlstate;
1154
1155 if (MyDatabaseId == InvalidOid)
1156 ereport(ERROR,
1158 errmsg("the query interface requires a database connection")));
1159
1160 pgres = libpqsrv_exec(conn->streamConn,
1161 query,
1163
1164 switch (PQresultStatus(pgres))
1165 {
1166 case PGRES_TUPLES_OK:
1167 case PGRES_SINGLE_TUPLE:
1168 case PGRES_TUPLES_CHUNK:
1169 walres->status = WALRCV_OK_TUPLES;
1171 break;
1172
1173 case PGRES_COPY_IN:
1174 walres->status = WALRCV_OK_COPY_IN;
1175 break;
1176
1177 case PGRES_COPY_OUT:
1178 walres->status = WALRCV_OK_COPY_OUT;
1179 break;
1180
1181 case PGRES_COPY_BOTH:
1182 walres->status = WALRCV_OK_COPY_BOTH;
1183 break;
1184
1185 case PGRES_COMMAND_OK:
1186 walres->status = WALRCV_OK_COMMAND;
1187 break;
1188
1189 /* Empty query is considered error. */
1190 case PGRES_EMPTY_QUERY:
1191 walres->status = WALRCV_ERROR;
1192 walres->err = _("empty query");
1193 break;
1194
1197 walres->status = WALRCV_ERROR;
1198 walres->err = _("unexpected pipeline mode");
1199 break;
1200
1202 case PGRES_FATAL_ERROR:
1203 case PGRES_BAD_RESPONSE:
1204 walres->status = WALRCV_ERROR;
1205 walres->err = pchomp(PQerrorMessage(conn->streamConn));
1207 if (diag_sqlstate)
1208 walres->sqlstate = MAKE_SQLSTATE(diag_sqlstate[0],
1209 diag_sqlstate[1],
1210 diag_sqlstate[2],
1211 diag_sqlstate[3],
1212 diag_sqlstate[4]);
1213 break;
1214 }
1215
1216 PQclear(pgres);
1217
1218 return walres;
1219}
#define MAKE_SQLSTATE(ch1, ch2, ch3, ch4, ch5)
Definition elog.h:58
Oid MyDatabaseId
Definition globals.c:96
#define PQresultErrorField
@ PGRES_COPY_IN
Definition libpq-fe.h:138
@ PGRES_COPY_BOTH
Definition libpq-fe.h:143
@ PGRES_TUPLES_CHUNK
Definition libpq-fe.h:148
@ PGRES_FATAL_ERROR
Definition libpq-fe.h:142
@ PGRES_SINGLE_TUPLE
Definition libpq-fe.h:144
@ PGRES_EMPTY_QUERY
Definition libpq-fe.h:130
@ PGRES_PIPELINE_SYNC
Definition libpq-fe.h:145
@ PGRES_BAD_RESPONSE
Definition libpq-fe.h:139
@ PGRES_PIPELINE_ABORTED
Definition libpq-fe.h:146
@ PGRES_NONFATAL_ERROR
Definition libpq-fe.h:141
static void libpqrcv_processTuples(PGresult *pgres, WalRcvExecResult *walres, const int nRetTypes, const Oid *retTypes)
#define PG_DIAG_SQLSTATE
@ WALRCV_OK_COPY_IN
@ WALRCV_OK_COMMAND
@ WALRCV_ERROR
@ WALRCV_OK_TUPLES
@ WALRCV_OK_COPY_OUT
@ WALRCV_OK_COPY_BOTH

References _, conn, ereport, errcode(), errmsg, ERROR, fb(), InvalidOid, libpqrcv_processTuples(), libpqsrv_exec(), MAKE_SQLSTATE, MyDatabaseId, palloc0_object, pchomp(), PG_DIAG_SQLSTATE, PGRES_BAD_RESPONSE, PGRES_COMMAND_OK, PGRES_COPY_BOTH, PGRES_COPY_IN, PGRES_COPY_OUT, PGRES_EMPTY_QUERY, PGRES_FATAL_ERROR, PGRES_NONFATAL_ERROR, PGRES_PIPELINE_ABORTED, PGRES_PIPELINE_SYNC, PGRES_SINGLE_TUPLE, PGRES_TUPLES_CHUNK, PGRES_TUPLES_OK, PQclear, PQerrorMessage(), PQresultErrorField, PQresultStatus, WALRCV_ERROR, WALRCV_OK_COMMAND, WALRCV_OK_COPY_BOTH, WALRCV_OK_COPY_IN, WALRCV_OK_COPY_OUT, and WALRCV_OK_TUPLES.

◆ libpqrcv_get_backend_pid()

static pid_t libpqrcv_get_backend_pid ( WalReceiverConn conn)
static

Definition at line 1062 of file libpqwalreceiver.c.

1063{
1064 return PQbackendPID(conn->streamConn);
1065}
int PQbackendPID(const PGconn *conn)

References conn, and PQbackendPID().

◆ libpqrcv_get_conninfo()

static char * libpqrcv_get_conninfo ( WalReceiverConn conn)
static

Definition at line 351 of file libpqwalreceiver.c.

352{
356 char *retval;
357
358 Assert(conn->streamConn != NULL);
359
361 conn_opts = PQconninfo(conn->streamConn);
362
363 if (conn_opts == NULL)
366 errmsg("could not parse connection string: %s",
367 _("out of memory"))));
368
369 /* build a clean connection string from pieces */
370 for (conn_opt = conn_opts; conn_opt->keyword != NULL; conn_opt++)
371 {
372 bool obfuscate;
373
374 /* Skip debug and empty options */
375 if (strchr(conn_opt->dispchar, 'D') ||
376 conn_opt->val == NULL ||
377 conn_opt->val[0] == '\0')
378 continue;
379
380 /* Obfuscate security-sensitive options */
381 obfuscate = strchr(conn_opt->dispchar, '*') != NULL;
382
383 appendPQExpBuffer(&buf, "%s%s=%s",
384 buf.len == 0 ? "" : " ",
385 conn_opt->keyword,
386 obfuscate ? "********" : conn_opt->val);
387 }
388
390
391 retval = PQExpBufferDataBroken(buf) ? NULL : pstrdup(buf.data);
393 return retval;
394}
PQconninfoOption * PQconninfo(PGconn *conn)
long val
Definition informix.c:689
void initPQExpBuffer(PQExpBuffer str)
Definition pqexpbuffer.c:90
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
void termPQExpBuffer(PQExpBuffer str)
#define PQExpBufferDataBroken(buf)
Definition pqexpbuffer.h:67

References _, appendPQExpBuffer(), Assert, buf, conn, ereport, errcode(), errmsg, ERROR, fb(), initPQExpBuffer(), PQconninfo(), PQconninfoFree(), PQExpBufferDataBroken, pstrdup(), and termPQExpBuffer().

◆ libpqrcv_get_dbname_from_conninfo()

static char * libpqrcv_get_dbname_from_conninfo ( const char connInfo)
static

Definition at line 475 of file libpqwalreceiver.c.

476{
478}

References fb(), and libpqrcv_get_option_from_conninfo().

◆ libpqrcv_get_option_from_conninfo()

static char * libpqrcv_get_option_from_conninfo ( const char connInfo,
const char keyword 
)
static

Definition at line 487 of file libpqwalreceiver.c.

488{
490 char *option = NULL;
491 char *err = NULL;
492
494 if (opts == NULL)
495 {
496 /* The error string is malloc'd, so we must free it explicitly */
497 char *errcopy = err ? pstrdup(err) : "out of memory";
498
499 PQfreemem(err);
502 errmsg("invalid connection string syntax: %s", errcopy)));
503 }
504
505 for (PQconninfoOption *opt = opts; opt->keyword != NULL; ++opt)
506 {
507 /*
508 * If the same option appears multiple times, then the last one will
509 * be returned
510 */
511 if (strcmp(opt->keyword, keyword) == 0 && opt->val &&
512 *opt->val)
513 {
514 if (option)
515 pfree(option);
516
517 option = pstrdup(opt->val);
518 }
519 }
520
522 return option;
523}

References ereport, err(), errcode(), errmsg, ERROR, fb(), opts, pfree(), PQconninfoFree(), PQconninfoParse(), PQfreemem(), and pstrdup().

Referenced by libpqrcv_connect(), and libpqrcv_get_dbname_from_conninfo().

◆ libpqrcv_get_senderinfo()

static void libpqrcv_get_senderinfo ( WalReceiverConn conn,
char **  sender_host,
int sender_port 
)
static

Definition at line 400 of file libpqwalreceiver.c.

402{
403 char *ret = NULL;
404
405 *sender_host = NULL;
406 *sender_port = 0;
407
408 Assert(conn->streamConn != NULL);
409
410 ret = PQhost(conn->streamConn);
411 if (ret && strlen(ret) != 0)
412 *sender_host = pstrdup(ret);
413
414 ret = PQport(conn->streamConn);
415 if (ret && strlen(ret) != 0)
416 *sender_port = atoi(ret);
417}
char * PQport(const PGconn *conn)
char * PQhost(const PGconn *conn)

References Assert, conn, fb(), PQhost(), PQport(), and pstrdup().

◆ libpqrcv_identify_system()

static char * libpqrcv_identify_system ( WalReceiverConn conn,
TimeLineID primary_tli 
)
static

Definition at line 424 of file libpqwalreceiver.c.

425{
426 PGresult *res;
427 char *primary_sysid;
428
429 /*
430 * Get the system identifier and timeline ID as a DataRow message from the
431 * primary server.
432 */
433 res = libpqsrv_exec(conn->streamConn,
434 "IDENTIFY_SYSTEM",
439 errmsg("could not receive database system identifier and timeline ID from "
440 "the primary server: %s",
441 pchomp(PQerrorMessage(conn->streamConn)))));
442
443 /*
444 * IDENTIFY_SYSTEM returns 3 columns in 9.3 and earlier, and 4 columns in
445 * 9.4 and onwards.
446 */
447 if (PQnfields(res) < 3 || PQntuples(res) != 1)
450 errmsg("invalid response from primary server"),
451 errdetail("Could not identify system: got %d rows and %d fields, expected %d rows and %d or more fields.",
452 PQntuples(res), PQnfields(res), 1, 3)));
453 primary_sysid = pstrdup(PQgetvalue(res, 0, 0));
454 *primary_tli = pg_strtoint32(PQgetvalue(res, 0, 1));
455 PQclear(res);
456
457 return primary_sysid;
458}

References conn, ereport, errcode(), ERRCODE_PROTOCOL_VIOLATION, errdetail(), errmsg, ERROR, fb(), libpqsrv_exec(), pchomp(), pg_strtoint32(), PGRES_TUPLES_OK, PQclear, PQerrorMessage(), PQgetvalue, PQnfields, PQntuples, PQresultStatus, and pstrdup().

◆ libpqrcv_processTuples()

static void libpqrcv_processTuples ( PGresult pgres,
WalRcvExecResult walres,
const int  nRetTypes,
const Oid retTypes 
)
static

Definition at line 1071 of file libpqwalreceiver.c.

1073{
1074 int tupn;
1075 int coln;
1076 int nfields = PQnfields(pgres);
1077 HeapTuple tuple;
1078 AttInMetadata *attinmeta;
1079 MemoryContext rowcontext;
1080 MemoryContext oldcontext;
1081
1082 /* Make sure we got expected number of fields. */
1083 if (nfields != nRetTypes)
1084 ereport(ERROR,
1086 errmsg("invalid query response"),
1087 errdetail("Expected %d fields, got %d fields.",
1088 nRetTypes, nfields)));
1089
1090 walres->tuplestore = tuplestore_begin_heap(true, false, work_mem);
1091
1092 /* Create tuple descriptor corresponding to expected result. */
1094 for (coln = 0; coln < nRetTypes; coln++)
1095 TupleDescInitEntry(walres->tupledesc, (AttrNumber) coln + 1,
1096 PQfname(pgres, coln), retTypes[coln], -1, 0);
1097 TupleDescFinalize(walres->tupledesc);
1098 attinmeta = TupleDescGetAttInMetadata(walres->tupledesc);
1099
1100 /* No point in doing more here if there were no tuples returned. */
1101 if (PQntuples(pgres) == 0)
1102 return;
1103
1104 /* Create temporary context for local allocations. */
1106 "libpqrcv query result context",
1108
1109 /* Process returned rows. */
1110 for (tupn = 0; tupn < PQntuples(pgres); tupn++)
1111 {
1112 char *cstrs[MaxTupleAttributeNumber];
1113
1115
1116 /* Do the allocations in temporary context. */
1117 oldcontext = MemoryContextSwitchTo(rowcontext);
1118
1119 /*
1120 * Fill cstrs with null-terminated strings of column values.
1121 */
1122 for (coln = 0; coln < nfields; coln++)
1123 {
1124 if (PQgetisnull(pgres, tupn, coln))
1125 cstrs[coln] = NULL;
1126 else
1127 cstrs[coln] = PQgetvalue(pgres, tupn, coln);
1128 }
1129
1130 /* Convert row to a tuple, and add it to the tuplestore */
1131 tuple = BuildTupleFromCStrings(attinmeta, cstrs);
1132 tuplestore_puttuple(walres->tuplestore, tuple);
1133
1134 /* Clean up */
1135 MemoryContextSwitchTo(oldcontext);
1136 MemoryContextReset(rowcontext);
1137 }
1138
1139 MemoryContextDelete(rowcontext);
1140}
int16 AttrNumber
Definition attnum.h:21
HeapTuple BuildTupleFromCStrings(AttInMetadata *attinmeta, char **values)
AttInMetadata * TupleDescGetAttInMetadata(TupleDesc tupdesc)
int work_mem
Definition globals.c:133
#define MaxTupleAttributeNumber
#define PQfname
void MemoryContextReset(MemoryContext context)
Definition mcxt.c:406
MemoryContext CurrentMemoryContext
Definition mcxt.c:161
void MemoryContextDelete(MemoryContext context)
Definition mcxt.c:475
#define AllocSetContextCreate
Definition memutils.h:129
#define ALLOCSET_DEFAULT_SIZES
Definition memutils.h:160
#define CHECK_FOR_INTERRUPTS()
Definition miscadmin.h:125
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition palloc.h:138
TupleDesc CreateTemplateTupleDesc(int natts)
Definition tupdesc.c:165
void TupleDescFinalize(TupleDesc tupdesc)
Definition tupdesc.c:511
void TupleDescInitEntry(TupleDesc desc, AttrNumber attributeNumber, const char *attributeName, Oid oidtypeid, int32 typmod, int attdim)
Definition tupdesc.c:909
Tuplestorestate * tuplestore_begin_heap(bool randomAccess, bool interXact, int maxKBytes)
Definition tuplestore.c:331
void tuplestore_puttuple(Tuplestorestate *state, HeapTuple tuple)
Definition tuplestore.c:765

References ALLOCSET_DEFAULT_SIZES, AllocSetContextCreate, BuildTupleFromCStrings(), CHECK_FOR_INTERRUPTS, CreateTemplateTupleDesc(), CurrentMemoryContext, ereport, errcode(), ERRCODE_PROTOCOL_VIOLATION, errdetail(), errmsg, ERROR, fb(), MaxTupleAttributeNumber, MemoryContextDelete(), MemoryContextReset(), MemoryContextSwitchTo(), PQfname, PQgetisnull, PQgetvalue, PQnfields, PQntuples, TupleDescFinalize(), TupleDescGetAttInMetadata(), TupleDescInitEntry(), tuplestore_begin_heap(), tuplestore_puttuple(), and work_mem.

Referenced by libpqrcv_exec().

◆ libpqrcv_readtimelinehistoryfile()

static void libpqrcv_readtimelinehistoryfile ( WalReceiverConn conn,
TimeLineID  tli,
char **  filename,
char **  content,
int len 
)
static

Definition at line 739 of file libpqwalreceiver.c.

742{
743 PGresult *res;
744 char cmd[64];
745
746 Assert(!conn->logical);
747
748 /*
749 * Request the primary to send over the history file for given timeline.
750 */
751 snprintf(cmd, sizeof(cmd), "TIMELINE_HISTORY %u", tli);
752 res = libpqsrv_exec(conn->streamConn,
753 cmd,
758 errmsg("could not receive timeline history file from "
759 "the primary server: %s",
760 pchomp(PQerrorMessage(conn->streamConn)))));
761 if (PQnfields(res) != 2 || PQntuples(res) != 1)
764 errmsg("invalid response from primary server"),
765 errdetail("Expected 1 tuple with 2 fields, got %d tuples with %d fields.",
766 PQntuples(res), PQnfields(res))));
767 *filename = pstrdup(PQgetvalue(res, 0, 0));
768
769 *len = PQgetlength(res, 0, 1);
770 *content = palloc(*len);
771 memcpy(*content, PQgetvalue(res, 0, 1), *len);
772 PQclear(res);
773}
memcpy(sums, checksumBaseOffsets, sizeof(checksumBaseOffsets))
#define PQgetlength
void * palloc(Size size)
Definition mcxt.c:1390
const void size_t len
static char * filename
Definition pg_dumpall.c:120
#define snprintf
Definition port.h:261

◆ libpqrcv_receive()

static int libpqrcv_receive ( WalReceiverConn conn,
char **  buffer,
pgsocket wait_fd 
)
static

Definition at line 803 of file libpqwalreceiver.c.

805{
806 int rawlen;
807
808 PQfreemem(conn->recvBuf);
809 conn->recvBuf = NULL;
810
811 /* Try to receive a CopyData message */
812 rawlen = PQgetCopyData(conn->streamConn, &conn->recvBuf, 1);
813 if (rawlen == 0)
814 {
815 /* Try consuming some data. */
816 if (PQconsumeInput(conn->streamConn) == 0)
819 errmsg("could not receive data from WAL stream: %s",
820 pchomp(PQerrorMessage(conn->streamConn)))));
821
822 /* Now that we've consumed some input, try again */
823 rawlen = PQgetCopyData(conn->streamConn, &conn->recvBuf, 1);
824 if (rawlen == 0)
825 {
826 /* Tell caller to try again when our socket is ready. */
827 *wait_fd = PQsocket(conn->streamConn);
828 return 0;
829 }
830 }
831 if (rawlen == -1) /* end-of-streaming or error */
832 {
833 PGresult *res;
834
835 res = libpqsrv_get_result(conn->streamConn,
838 {
839 PQclear(res);
840
841 /* Verify that there are no more results. */
842 res = libpqsrv_get_result(conn->streamConn,
844 if (res != NULL)
845 {
846 PQclear(res);
847
848 /*
849 * If the other side closed the connection orderly (otherwise
850 * we'd seen an error, or PGRES_COPY_IN) don't report an error
851 * here, but let callers deal with it.
852 */
853 if (PQstatus(conn->streamConn) == CONNECTION_BAD)
854 return -1;
855
858 errmsg("unexpected result after CommandComplete: %s",
859 PQerrorMessage(conn->streamConn))));
860 }
861
862 return -1;
863 }
864 else if (PQresultStatus(res) == PGRES_COPY_IN)
865 {
866 PQclear(res);
867 return -1;
868 }
869 else
872 errmsg("could not receive data from WAL stream: %s",
873 pchomp(PQerrorMessage(conn->streamConn)))));
874 }
875 if (rawlen < -1)
878 errmsg("could not receive data from WAL stream: %s",
879 pchomp(PQerrorMessage(conn->streamConn)))));
880
881 /* Return received messages to caller */
882 *buffer = conn->recvBuf;
883 return rawlen;
884}
int PQsocket(const PGconn *conn)
int PQconsumeInput(PGconn *conn)
Definition fe-exec.c:2001
int PQgetCopyData(PGconn *conn, char **buffer, int async)
Definition fe-exec.c:2833
@ CONNECTION_BAD
Definition libpq-fe.h:91

◆ libpqrcv_send()

static void libpqrcv_send ( WalReceiverConn conn,
const char buffer,
int  nbytes 
)
static

Definition at line 892 of file libpqwalreceiver.c.

893{
894 if (PQputCopyData(conn->streamConn, buffer, nbytes) <= 0 ||
895 PQflush(conn->streamConn))
898 errmsg("could not send data to WAL stream: %s",
899 pchomp(PQerrorMessage(conn->streamConn)))));
900}
int PQputCopyData(PGconn *conn, const char *buffer, int nbytes)
Definition fe-exec.c:2712

◆ libpqrcv_server_version()

static int libpqrcv_server_version ( WalReceiverConn conn)
static

Definition at line 464 of file libpqwalreceiver.c.

465{
466 return PQserverVersion(conn->streamConn);
467}

References conn, and PQserverVersion().

◆ libpqrcv_startstreaming()

static bool libpqrcv_startstreaming ( WalReceiverConn conn,
const WalRcvStreamOptions options 
)
static

Definition at line 562 of file libpqwalreceiver.c.

564{
565 StringInfoData cmd;
566 PGresult *res;
567
568 Assert(options->logical == conn->logical);
569 Assert(options->slotname || !options->logical);
570
571 initStringInfo(&cmd);
572
573 /* Build the command. */
574 appendStringInfoString(&cmd, "START_REPLICATION");
575 if (options->slotname != NULL)
576 {
577 appendStringInfoString(&cmd, " SLOT ");
578 appendQuotedIdentifier(&cmd, options->slotname);
579 }
580
581 if (options->logical)
582 appendStringInfoString(&cmd, " LOGICAL");
583
584 appendStringInfo(&cmd, " %X/%08X", LSN_FORMAT_ARGS(options->startpoint));
585
586 /*
587 * Additional options are different depending on if we are doing logical
588 * or physical replication.
589 */
590 if (options->logical)
591 {
592 char *pubnames_str;
593 List *pubnames;
594
595 appendStringInfoString(&cmd, " (");
596
597 appendStringInfo(&cmd, "proto_version '%u'",
598 options->proto.logical.proto_version);
599
600 if (options->proto.logical.streaming_str)
601 {
602 appendStringInfoString(&cmd, ", streaming ");
603 appendQuotedLiteral(&cmd, options->proto.logical.streaming_str);
604 }
605
606 if (options->proto.logical.twophase &&
607 PQserverVersion(conn->streamConn) >= 150000)
608 appendStringInfoString(&cmd, ", two_phase 'on'");
609
610 if (options->proto.logical.origin &&
611 PQserverVersion(conn->streamConn) >= 160000)
612 {
613 appendStringInfoString(&cmd, ", origin ");
614 appendQuotedLiteral(&cmd, options->proto.logical.origin);
615 }
616
617 pubnames = options->proto.logical.publication_names;
619 appendStringInfoString(&cmd, ", publication_names ");
622
623 if (options->proto.logical.binary &&
624 PQserverVersion(conn->streamConn) >= 140000)
625 appendStringInfoString(&cmd, ", binary 'true'");
626
627 appendStringInfoChar(&cmd, ')');
628 }
629 else
630 appendStringInfo(&cmd, " TIMELINE %u",
631 options->proto.physical.startpointTLI);
632
633 /* Start streaming. */
634 res = libpqsrv_exec(conn->streamConn,
635 cmd.data,
637 pfree(cmd.data);
638
640 {
641 PQclear(res);
642 return false;
643 }
644 else if (PQresultStatus(res) != PGRES_COPY_BOTH)
647 errmsg("could not start WAL streaming: %s",
648 pchomp(PQerrorMessage(conn->streamConn)))));
649 PQclear(res);
650 return true;
651}
#define appendQuotedLiteral(b, s)
static char * stringlist_to_identifierstr(List *strings)
Definition pg_list.h:54
#define LSN_FORMAT_ARGS(lsn)
Definition xlogdefs.h:47

◆ PG_MODULE_MAGIC_EXT()

PG_MODULE_MAGIC_EXT ( name = "libpqwalreceiver",
version = PG_VERSION 
)

◆ stringlist_to_identifierstr()

static char * stringlist_to_identifierstr ( List strings)
static

Definition at line 1230 of file libpqwalreceiver.c.

1231{
1232 ListCell *lc;
1233 StringInfoData res;
1234 bool first = true;
1235
1236 initStringInfo(&res);
1237
1238 foreach(lc, strings)
1239 {
1240 char *val = strVal(lfirst(lc));
1241
1242 if (first)
1243 first = false;
1244 else
1245 appendStringInfoChar(&res, ',');
1247 }
1248
1249 return res.data;
1250}
#define lfirst(lc)
Definition pg_list.h:172
#define strVal(v)
Definition value.h:82

References appendQuotedIdentifier, appendStringInfoChar(), StringInfoData::data, fb(), initStringInfo(), lfirst, strVal, and val.

Variable Documentation

◆ PQWalReceiverFunctions

WalReceiverFunctionsType PQWalReceiverFunctions
static
Initial value:
= {
.walrcv_connect = libpqrcv_connect,
.walrcv_check_conninfo = libpqrcv_check_conninfo,
.walrcv_get_conninfo = libpqrcv_get_conninfo,
.walrcv_get_senderinfo = libpqrcv_get_senderinfo,
.walrcv_identify_system = libpqrcv_identify_system,
.walrcv_server_version = libpqrcv_server_version,
.walrcv_readtimelinehistoryfile = libpqrcv_readtimelinehistoryfile,
.walrcv_startstreaming = libpqrcv_startstreaming,
.walrcv_endstreaming = libpqrcv_endstreaming,
.walrcv_receive = libpqrcv_receive,
.walrcv_send = libpqrcv_send,
.walrcv_create_slot = libpqrcv_create_slot,
.walrcv_alter_slot = libpqrcv_alter_slot,
.walrcv_get_dbname_from_conninfo = libpqrcv_get_dbname_from_conninfo,
.walrcv_get_backend_pid = libpqrcv_get_backend_pid,
.walrcv_exec = libpqrcv_exec,
.walrcv_disconnect = libpqrcv_disconnect
}
static WalReceiverConn * libpqrcv_connect(const char *conninfo, bool replication, bool logical, bool must_use_password, const char *appname, char **err)
static void libpqrcv_readtimelinehistoryfile(WalReceiverConn *conn, TimeLineID tli, char **filename, char **content, int *len)
static pid_t libpqrcv_get_backend_pid(WalReceiverConn *conn)
static void libpqrcv_send(WalReceiverConn *conn, const char *buffer, int nbytes)
static void libpqrcv_disconnect(WalReceiverConn *conn)
static char * libpqrcv_identify_system(WalReceiverConn *conn, TimeLineID *primary_tli)
static char * libpqrcv_create_slot(WalReceiverConn *conn, const char *slotname, bool temporary, bool two_phase, bool failover, CRSSnapshotAction snapshot_action, XLogRecPtr *lsn)
static WalRcvExecResult * libpqrcv_exec(WalReceiverConn *conn, const char *query, const int nRetTypes, const Oid *retTypes)
static void libpqrcv_endstreaming(WalReceiverConn *conn, TimeLineID *next_tli)
static void libpqrcv_get_senderinfo(WalReceiverConn *conn, char **sender_host, int *sender_port)
static int libpqrcv_server_version(WalReceiverConn *conn)
static bool libpqrcv_startstreaming(WalReceiverConn *conn, const WalRcvStreamOptions *options)
static int libpqrcv_receive(WalReceiverConn *conn, char **buffer, pgsocket *wait_fd)
static void libpqrcv_alter_slot(WalReceiverConn *conn, const char *slotname, const bool *failover, const bool *two_phase)
static char * libpqrcv_get_conninfo(WalReceiverConn *conn)
static char * libpqrcv_get_dbname_from_conninfo(const char *connInfo)

Definition at line 98 of file libpqwalreceiver.c.

98 {
99 .walrcv_connect = libpqrcv_connect,
100 .walrcv_check_conninfo = libpqrcv_check_conninfo,
101 .walrcv_get_conninfo = libpqrcv_get_conninfo,
102 .walrcv_get_senderinfo = libpqrcv_get_senderinfo,
103 .walrcv_identify_system = libpqrcv_identify_system,
104 .walrcv_server_version = libpqrcv_server_version,
105 .walrcv_readtimelinehistoryfile = libpqrcv_readtimelinehistoryfile,
106 .walrcv_startstreaming = libpqrcv_startstreaming,
107 .walrcv_endstreaming = libpqrcv_endstreaming,
108 .walrcv_receive = libpqrcv_receive,
109 .walrcv_send = libpqrcv_send,
110 .walrcv_create_slot = libpqrcv_create_slot,
111 .walrcv_alter_slot = libpqrcv_alter_slot,
112 .walrcv_get_dbname_from_conninfo = libpqrcv_get_dbname_from_conninfo,
113 .walrcv_get_backend_pid = libpqrcv_get_backend_pid,
114 .walrcv_exec = libpqrcv_exec,
115 .walrcv_disconnect = libpqrcv_disconnect
116};

Referenced by _PG_init().