41 .
name =
"libpqwalreceiver",
57 bool replication,
bool logical,
59 const char *appname,
char **
err);
64 char **sender_host,
int *sender_port);
73 char **content,
int *
len);
128 elog(
ERROR,
"libpqwalreceiver already loaded");
174 Assert(replication || !logical);
178 keys[++
i] =
"replication";
179 vals[
i] = logical ?
"database" :
"true";
186 keys[++
i] =
"client_encoding";
198 options_val =
psprintf(
"%s -c datestyle=ISO -c intervalstyle=postgres -c extra_float_digits=3",
199 (opt ==
NULL) ?
"" : opt);
200 keys[++
i] =
"options";
211 keys[++
i] =
"dbname";
212 vals[
i] =
"replication";
216 keys[++
i] =
"fallback_application_name";
243 errmsg(
"password is required"),
244 errdetail(
"Non-superuser cannot connect if the server does not request a password."),
245 errhint(
"Target server's authentication method must be changed, or set password_required=false in the subscription parameters.")));
249 "received message via replication");
255 if (!replication || logical)
272 conn->logical = logical;
338 errmsg(
"password is required"),
339 errdetail(
"Non-superusers must provide a password in the connection string.")));
366 errmsg(
"could not parse connection string: %s",
367 _(
"out of memory"))));
384 buf.len == 0 ?
"" :
" ",
411 if (ret &&
strlen(ret) != 0)
415 if (ret &&
strlen(ret) != 0)
416 *sender_port =
atoi(ret);
439 errmsg(
"could not receive database system identifier and timeline ID from "
440 "the primary server: %s",
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.",
511 if (
strcmp(opt->keyword, keyword) == 0 && opt->val &&
571 options->proto.logical.proto_version);
573 if (
options->proto.logical.streaming_str)
575 options->proto.logical.streaming_str);
577 if (
options->proto.logical.twophase &&
581 if (
options->proto.logical.origin &&
584 options->proto.logical.origin);
591 errmsg(
"could not start WAL streaming: %s",
598 errmsg(
"could not start WAL streaming: %s",
604 if (
options->proto.logical.binary &&
612 options->proto.physical.startpointTLI);
628 errmsg(
"could not start WAL streaming: %s",
651 errmsg(
"could not send end-of-streaming message to primary: %s",
675 errmsg(
"unexpected result set after end-of-streaming")));
691 errmsg(
"error while shutting down streaming COPY: %s",
702 errmsg(
"error reading result of streaming command: %s",
712 errmsg(
"unexpected result after CommandComplete: %s",
722 char **content,
int *
len)
732 snprintf(cmd,
sizeof(cmd),
"TIMELINE_HISTORY %u", tli);
739 errmsg(
"could not receive timeline history file from "
740 "the primary server: %s",
745 errmsg(
"invalid response from primary server"),
746 errdetail(
"Expected 1 tuple with 2 fields, got %d tuples with %d fields.",
800 errmsg(
"could not receive data from WAL stream: %s",
839 errmsg(
"unexpected result after CommandComplete: %s",
853 errmsg(
"could not receive data from WAL stream: %s",
859 errmsg(
"could not receive data from WAL stream: %s",
863 *buffer =
conn->recvBuf;
879 errmsg(
"could not send data to WAL stream: %s",
980 errmsg(
"could not create replication slot \"%s\": %s",
1031 errmsg(
"could not alter replication slot \"%s\": %s",
1065 errmsg(
"invalid query response"),
1066 errdetail(
"Expected %d fields, got %d fields.",
1084 "libpqrcv query result context",
1136 errmsg(
"the query interface requires a database connection")));
1170 walres->err =
_(
"empty query");
1176 walres->err =
_(
"unexpected pipeline mode");
#define Assert(condition)
#define ALWAYS_SECURE_SEARCH_PATH_SQL
int errdetail(const char *fmt,...)
int errhint(const char *fmt,...)
int errcode(int sqlerrcode)
int errmsg(const char *fmt,...)
#define MAKE_SQLSTATE(ch1, ch2, ch3, ch4, ch5)
#define ereport(elevel,...)
void err(int eval, const char *fmt,...)
HeapTuple BuildTupleFromCStrings(AttInMetadata *attinmeta, char **values)
AttInMetadata * TupleDescGetAttInMetadata(TupleDesc tupdesc)
int PQserverVersion(const PGconn *conn)
char * PQport(const PGconn *conn)
char * PQhost(const PGconn *conn)
int PQconnectionUsedPassword(const PGconn *conn)
PQconninfoOption * PQconninfo(PGconn *conn)
void PQconninfoFree(PQconninfoOption *connOptions)
PQconninfoOption * PQconninfoParse(const char *conninfo, char **errmsg)
ConnStatusType PQstatus(const PGconn *conn)
PQnoticeReceiver PQsetNoticeReceiver(PGconn *conn, PQnoticeReceiver proc, void *arg)
int PQbackendPID(const PGconn *conn)
char * PQerrorMessage(const PGconn *conn)
int PQsocket(const PGconn *conn)
int PQflush(PGconn *conn)
void PQfreemem(void *ptr)
int PQendcopy(PGconn *conn)
int PQputCopyEnd(PGconn *conn, const char *errormsg)
int PQputCopyData(PGconn *conn, const char *buffer, int nbytes)
int PQconsumeInput(PGconn *conn)
char * PQescapeLiteral(PGconn *conn, const char *str, size_t len)
char * PQescapeIdentifier(PGconn *conn, const char *str, size_t len)
int PQgetCopyData(PGconn *conn, char **buffer, int async)
#define palloc0_object(type)
Datum DirectFunctionCall1Coll(PGFunction func, Oid collation, Datum arg1)
#define PG_MODULE_MAGIC_EXT(...)
#define MaxTupleAttributeNumber
static PGresult * libpqsrv_exec(PGconn *conn, const char *query, uint32 wait_event_info)
static PGconn * libpqsrv_connect_params(const char *const *keywords, const char *const *values, int expand_dbname, uint32 wait_event_info)
static PGresult * libpqsrv_get_result(PGconn *conn, uint32 wait_event_info)
static void libpqsrv_notice_receiver(void *arg, const PGresult *res)
static void libpqsrv_disconnect(PGconn *conn)
#define PQresultErrorField
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 char * stringlist_to_identifierstr(PGconn *conn, List *strings)
static void libpqrcv_check_conninfo(const char *conninfo, bool must_use_password)
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 WalReceiverFunctionsType PQWalReceiverFunctions
static char * libpqrcv_get_option_from_conninfo(const char *connInfo, const char *keyword)
static char * libpqrcv_get_conninfo(WalReceiverConn *conn)
static void libpqrcv_processTuples(PGresult *pgres, WalRcvExecResult *walres, const int nRetTypes, const Oid *retTypes)
static char * libpqrcv_get_dbname_from_conninfo(const char *connInfo)
const char * GetDatabaseEncodingName(void)
void MemoryContextReset(MemoryContext context)
char * pstrdup(const char *in)
void pfree(void *pointer)
char * pchomp(const char *in)
MemoryContext CurrentMemoryContext
void MemoryContextDelete(MemoryContext context)
#define AllocSetContextCreate
#define ALLOCSET_DEFAULT_SIZES
#define CHECK_FOR_INTERRUPTS()
int32 pg_strtoint32(const char *s)
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
static AmcheckOptions opts
Datum pg_lsn_in(PG_FUNCTION_ARGS)
static XLogRecPtr DatumGetLSN(Datum X)
static char buf[DEFAULT_XLOG_SEG_SIZE]
static Datum CStringGetDatum(const char *X)
void initPQExpBuffer(PQExpBuffer str)
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
void termPQExpBuffer(PQExpBuffer str)
#define PQExpBufferDataBroken(buf)
char * psprintf(const char *fmt,...)
const char * quote_identifier(const char *ident)
void appendStringInfo(StringInfo str, const char *fmt,...)
void appendStringInfoString(StringInfo str, const char *s)
void appendStringInfoChar(StringInfo str, char ch)
void initStringInfo(StringInfo str)
walrcv_connect_fn walrcv_connect
TupleDesc CreateTemplateTupleDesc(int natts)
void TupleDescInitEntry(TupleDesc desc, AttrNumber attributeNumber, const char *attributeName, Oid oidtypeid, int32 typmod, int attdim)
Tuplestorestate * tuplestore_begin_heap(bool randomAccess, bool interXact, int maxKBytes)
void tuplestore_puttuple(Tuplestorestate *state, HeapTuple tuple)
WalReceiverFunctionsType * WalReceiverFunctions
#define LSN_FORMAT_ARGS(lsn)