Expose PQbackendPID() through walreceiver API
authorPeter Eisentraut <peter@eisentraut.org>
Tue, 14 Jan 2020 13:05:25 +0000 (14:05 +0100)
committerPeter Eisentraut <peter@eisentraut.org>
Tue, 14 Jan 2020 13:40:41 +0000 (14:40 +0100)
This will be used by a subsequent patch.

Reviewed-by: Masahiko Sawada <masahiko.sawada@2ndquadrant.com>
Discussion: https://www.postgresql.org/message-id/CA%2Bfd4k4dM0iEPLxyVyme2RAFsn8SUgrNtBJOu81YqTY4V%2BnqZA%40mail.gmail.com

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

index 658af71fec915e911aec8e28f4bfad1ed22a0f2e..b731d3fd04e2cc986d9c486b6f632332a02f95ed 100644 (file)
@@ -74,6 +74,7 @@ static char *libpqrcv_create_slot(WalReceiverConn *conn,
                                                                  bool temporary,
                                                                  CRSSnapshotAction snapshot_action,
                                                                  XLogRecPtr *lsn);
+static pid_t libpqrcv_get_backend_pid(WalReceiverConn *conn);
 static WalRcvExecResult *libpqrcv_exec(WalReceiverConn *conn,
                                                                           const char *query,
                                                                           const int nRetTypes,
@@ -93,6 +94,7 @@ static WalReceiverFunctionsType PQWalReceiverFunctions = {
        libpqrcv_receive,
        libpqrcv_send,
        libpqrcv_create_slot,
+       libpqrcv_get_backend_pid,
        libpqrcv_exec,
        libpqrcv_disconnect
 };
@@ -858,6 +860,15 @@ libpqrcv_create_slot(WalReceiverConn *conn, const char *slotname,
        return snapshot;
 }
 
+/*
+ * Return PID of remote backend process.
+ */
+static pid_t
+libpqrcv_get_backend_pid(WalReceiverConn *conn)
+{
+       return PQbackendPID(conn->streamConn);
+}
+
 /*
  * Convert tuple query result to tuplestore.
  */
index a276237477628b19a012866297b1218e8a08c8df..172cfa28629c1ea7715ab18d2cb644f35068504c 100644 (file)
@@ -226,6 +226,7 @@ typedef char *(*walrcv_create_slot_fn) (WalReceiverConn *conn,
                                                                                const char *slotname, bool temporary,
                                                                                CRSSnapshotAction snapshot_action,
                                                                                XLogRecPtr *lsn);
+typedef pid_t (*walrcv_get_backend_pid_fn) (WalReceiverConn *conn);
 typedef WalRcvExecResult *(*walrcv_exec_fn) (WalReceiverConn *conn,
                                                                                         const char *query,
                                                                                         const int nRetTypes,
@@ -246,6 +247,7 @@ typedef struct WalReceiverFunctionsType
        walrcv_receive_fn walrcv_receive;
        walrcv_send_fn walrcv_send;
        walrcv_create_slot_fn walrcv_create_slot;
+       walrcv_get_backend_pid_fn walrcv_get_backend_pid;
        walrcv_exec_fn walrcv_exec;
        walrcv_disconnect_fn walrcv_disconnect;
 } WalReceiverFunctionsType;
@@ -276,6 +278,8 @@ extern PGDLLIMPORT WalReceiverFunctionsType *WalReceiverFunctions;
        WalReceiverFunctions->walrcv_send(conn, buffer, nbytes)
 #define walrcv_create_slot(conn, slotname, temporary, snapshot_action, lsn) \
        WalReceiverFunctions->walrcv_create_slot(conn, slotname, temporary, snapshot_action, lsn)
+#define walrcv_get_backend_pid(conn) \
+       WalReceiverFunctions->walrcv_get_backend_pid(conn)
 #define walrcv_exec(conn, exec, nRetTypes, retTypes) \
        WalReceiverFunctions->walrcv_exec(conn, exec, nRetTypes, retTypes)
 #define walrcv_disconnect(conn) \