]> granicus.if.org Git - postgresql/commitdiff
Add walreceiver API to get remote server version
authorPeter Eisentraut <peter@eisentraut.org>
Fri, 15 Mar 2019 09:16:26 +0000 (10:16 +0100)
committerPeter Eisentraut <peter@eisentraut.org>
Fri, 15 Mar 2019 09:16:26 +0000 (10:16 +0100)
Add a separate walreceiver API function walrcv_server_version() to get
the version of the remote server, instead of doing it as part of
walrcv_identify_system().  This allows the server version to be
available even for uses that don't call IDENTIFY_SYSTEM, and it seems
cleaner anyway.

This is for an upcoming patch, not currently used.

Reviewed-by: Michael Paquier <michael@paquier.xyz>
Discussion: https://www.postgresql.org/message-id/20190115071359.GF1433@paquier.xyz

src/backend/replication/libpqwalreceiver/libpqwalreceiver.c
src/backend/replication/logical/worker.c
src/backend/replication/walreceiver.c
src/include/replication/walreceiver.h

index 7027737e67c2f31553b2f18110292b27ee20930d..7123d4169d9d66d0830a6b7ac1bb4f15e1f0311c 100644 (file)
@@ -56,8 +56,8 @@ static char *libpqrcv_get_conninfo(WalReceiverConn *conn);
 static void libpqrcv_get_senderinfo(WalReceiverConn *conn,
                                                char **sender_host, int *sender_port);
 static char *libpqrcv_identify_system(WalReceiverConn *conn,
-                                                TimeLineID *primary_tli,
-                                                int *server_version);
+                                                TimeLineID *primary_tli);
+static int libpqrcv_server_version(WalReceiverConn *conn);
 static void libpqrcv_readtimelinehistoryfile(WalReceiverConn *conn,
                                                                 TimeLineID tli, char **filename,
                                                                 char **content, int *len);
@@ -86,6 +86,7 @@ static WalReceiverFunctionsType PQWalReceiverFunctions = {
        libpqrcv_get_conninfo,
        libpqrcv_get_senderinfo,
        libpqrcv_identify_system,
+       libpqrcv_server_version,
        libpqrcv_readtimelinehistoryfile,
        libpqrcv_startstreaming,
        libpqrcv_endstreaming,
@@ -309,8 +310,7 @@ libpqrcv_get_senderinfo(WalReceiverConn *conn, char **sender_host,
  * timeline ID of the primary.
  */
 static char *
-libpqrcv_identify_system(WalReceiverConn *conn, TimeLineID *primary_tli,
-                                                int *server_version)
+libpqrcv_identify_system(WalReceiverConn *conn, TimeLineID *primary_tli)
 {
        PGresult   *res;
        char       *primary_sysid;
@@ -343,11 +343,18 @@ libpqrcv_identify_system(WalReceiverConn *conn, TimeLineID *primary_tli,
        *primary_tli = pg_strtoint32(PQgetvalue(res, 0, 1));
        PQclear(res);
 
-       *server_version = PQserverVersion(conn->streamConn);
-
        return primary_sysid;
 }
 
+/*
+ * Thin wrapper around libpq to obtain server version.
+ */
+static int
+libpqrcv_server_version(WalReceiverConn *conn)
+{
+       return PQserverVersion(conn->streamConn);
+}
+
 /*
  * Start streaming WAL data from given streaming options.
  *
index 07f4ec90553e004c4af1f5b16b0fe7de49295267..52a5090b6944d98622f0d8000793bde9c8951f4c 100644 (file)
@@ -1674,7 +1674,6 @@ ApplyWorkerMain(Datum main_arg)
                RepOriginId originid;
                TimeLineID      startpointTLI;
                char       *err;
-               int                     server_version;
 
                myslotname = MySubscription->slotname;
 
@@ -1708,8 +1707,7 @@ ApplyWorkerMain(Datum main_arg)
                 * We don't really use the output identify_system for anything but it
                 * does some initializations on the upstream so let's still call it.
                 */
-               (void) walrcv_identify_system(wrconn, &startpointTLI,
-                                                                         &server_version);
+               (void) walrcv_identify_system(wrconn, &startpointTLI);
 
        }
 
index 9eaaa8ff5057efbfdc2a2eaf85fa4febac2e4aff..d9959e568a8c06ff3c6827e87ccdafba56913532 100644 (file)
@@ -330,7 +330,6 @@ WalReceiverMain(void)
        {
                char       *primary_sysid;
                char            standby_sysid[32];
-               int                     server_version;
                WalRcvStreamOptions options;
 
                /*
@@ -338,8 +337,7 @@ WalReceiverMain(void)
                 * IDENTIFY_SYSTEM replication command.
                 */
                EnableWalRcvImmediateExit();
-               primary_sysid = walrcv_identify_system(wrconn, &primaryTLI,
-                                                                                          &server_version);
+               primary_sysid = walrcv_identify_system(wrconn, &primaryTLI);
 
                snprintf(standby_sysid, sizeof(standby_sysid), UINT64_FORMAT,
                                 GetSystemIdentifier());
index e04d725ff5894b01ae3ebf2ad346cdc47065f65c..33e89cae36f57f4b7ed2a9c8bc21c981c4cdd243 100644 (file)
@@ -209,8 +209,8 @@ typedef void (*walrcv_get_senderinfo_fn) (WalReceiverConn *conn,
                                                                                  char **sender_host,
                                                                                  int *sender_port);
 typedef char *(*walrcv_identify_system_fn) (WalReceiverConn *conn,
-                                                                                       TimeLineID *primary_tli,
-                                                                                       int *server_version);
+                                                                                       TimeLineID *primary_tli);
+typedef int (*walrcv_server_version_fn) (WalReceiverConn *conn);
 typedef void (*walrcv_readtimelinehistoryfile_fn) (WalReceiverConn *conn,
                                                                                                   TimeLineID tli,
                                                                                                   char **filename,
@@ -240,6 +240,7 @@ typedef struct WalReceiverFunctionsType
        walrcv_get_conninfo_fn walrcv_get_conninfo;
        walrcv_get_senderinfo_fn walrcv_get_senderinfo;
        walrcv_identify_system_fn walrcv_identify_system;
+       walrcv_server_version_fn walrcv_server_version;
        walrcv_readtimelinehistoryfile_fn walrcv_readtimelinehistoryfile;
        walrcv_startstreaming_fn walrcv_startstreaming;
        walrcv_endstreaming_fn walrcv_endstreaming;
@@ -260,8 +261,10 @@ extern PGDLLIMPORT WalReceiverFunctionsType *WalReceiverFunctions;
        WalReceiverFunctions->walrcv_get_conninfo(conn)
 #define walrcv_get_senderinfo(conn, sender_host, sender_port) \
        WalReceiverFunctions->walrcv_get_senderinfo(conn, sender_host, sender_port)
-#define walrcv_identify_system(conn, primary_tli, server_version) \
-       WalReceiverFunctions->walrcv_identify_system(conn, primary_tli, server_version)
+#define walrcv_identify_system(conn, primary_tli) \
+       WalReceiverFunctions->walrcv_identify_system(conn, primary_tli)
+#define walrcv_server_version(conn) \
+       WalReceiverFunctions->walrcv_server_version(conn)
 #define walrcv_readtimelinehistoryfile(conn, tli, filename, content, size) \
        WalReceiverFunctions->walrcv_readtimelinehistoryfile(conn, tli, filename, content, size)
 #define walrcv_startstreaming(conn, options) \