Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit9a89546

Browse files
committed
Enhance pg_stat_wal_receiver view to display host and port of sender server.
Previously there was no way in the standby side to find out the host and portof the sender server that the walreceiver was currently connected to whenmultiple hosts and ports were specified in primary_conninfo. For that purpose,this patch adds sender_host and sender_port columns into pg_stat_wal_receiverview. They report the host and port that the active replication connectioncurrently uses.Bump catalog version.Author: Haribabu KommiReviewed-by: Michael Paquier and meDiscussion:https://postgr.es/m/CAJrrPGcV_aq8=cdqkFhVDJKEnDQ70yRTTdY9RODzMnXNrCz2Ow@mail.gmail.com
1 parent11002f8 commit9a89546

File tree

8 files changed

+94
-6
lines changed

8 files changed

+94
-6
lines changed

‎doc/src/sgml/monitoring.sgml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2031,6 +2031,25 @@ SELECT pid, wait_event_type, wait_event FROM pg_stat_activity WHERE wait_event i
20312031
<entry><type>text</type></entry>
20322032
<entry>Replication slot name used by this WAL receiver</entry>
20332033
</row>
2034+
<row>
2035+
<entry><structfield>sender_host</structfield></entry>
2036+
<entry><type>text</type></entry>
2037+
<entry>
2038+
Host of the <productname>PostgreSQL</productname> instance
2039+
this WAL receiver is connected to. This can be a host name,
2040+
an IP address, or a directory path if the connection is via
2041+
Unix socket. (The path case can be distinguished because it
2042+
will always be an absolute path, beginning with <literal>/</literal>.)
2043+
</entry>
2044+
</row>
2045+
<row>
2046+
<entry><structfield>sender_port</structfield></entry>
2047+
<entry><type>integer</type></entry>
2048+
<entry>
2049+
Port number of the <productname>PostgreSQL</productname> instance
2050+
this WAL receiver is connected to.
2051+
</entry>
2052+
</row>
20342053
<row>
20352054
<entry><structfield>conninfo</structfield></entry>
20362055
<entry><type>text</type></entry>

‎src/backend/catalog/system_views.sql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -752,6 +752,8 @@ CREATE VIEW pg_stat_wal_receiver AS
752752
s.latest_end_lsn,
753753
s.latest_end_time,
754754
s.slot_name,
755+
s.sender_host,
756+
s.sender_port,
755757
s.conninfo
756758
FROM pg_stat_get_wal_receiver() s
757759
WHEREs.pidIS NOT NULL;

‎src/backend/replication/libpqwalreceiver/libpqwalreceiver.c

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ static WalReceiverConn *libpqrcv_connect(const char *conninfo,
5353
char**err);
5454
staticvoidlibpqrcv_check_conninfo(constchar*conninfo);
5555
staticchar*libpqrcv_get_conninfo(WalReceiverConn*conn);
56+
staticvoidlibpqrcv_get_senderinfo(WalReceiverConn*conn,
57+
char**sender_host,int*sender_port);
5658
staticchar*libpqrcv_identify_system(WalReceiverConn*conn,
5759
TimeLineID*primary_tli,
5860
int*server_version);
@@ -82,6 +84,7 @@ static WalReceiverFunctionsType PQWalReceiverFunctions = {
8284
libpqrcv_connect,
8385
libpqrcv_check_conninfo,
8486
libpqrcv_get_conninfo,
87+
libpqrcv_get_senderinfo,
8588
libpqrcv_identify_system,
8689
libpqrcv_readtimelinehistoryfile,
8790
libpqrcv_startstreaming,
@@ -282,6 +285,29 @@ libpqrcv_get_conninfo(WalReceiverConn *conn)
282285
returnretval;
283286
}
284287

288+
/*
289+
* Provides information of sender this WAL receiver is connected to.
290+
*/
291+
staticvoid
292+
libpqrcv_get_senderinfo(WalReceiverConn*conn,char**sender_host,
293+
int*sender_port)
294+
{
295+
char*ret=NULL;
296+
297+
*sender_host=NULL;
298+
*sender_port=0;
299+
300+
Assert(conn->streamConn!=NULL);
301+
302+
ret=PQhost(conn->streamConn);
303+
if (ret&&strlen(ret)!=0)
304+
*sender_host=pstrdup(ret);
305+
306+
ret=PQport(conn->streamConn);
307+
if (ret&&strlen(ret)!=0)
308+
*sender_port=atoi(ret);
309+
}
310+
285311
/*
286312
* Check that primary's system identifier matches ours, and fetch the current
287313
* timeline ID of the primary.

‎src/backend/replication/walreceiver.c

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
#include"access/xlog_internal.h"
5353
#include"catalog/pg_authid.h"
5454
#include"catalog/pg_type.h"
55+
#include"common/ip.h"
5556
#include"funcapi.h"
5657
#include"libpq/pqformat.h"
5758
#include"libpq/pqsignal.h"
@@ -199,6 +200,8 @@ WalReceiverMain(void)
199200
TimestampTznow;
200201
boolping_sent;
201202
char*err;
203+
char*sender_host=NULL;
204+
intsender_port=0;
202205

203206
/*
204207
* WalRcv should be set up already (if we are a backend, we inherit this
@@ -308,19 +311,30 @@ WalReceiverMain(void)
308311

309312
/*
310313
* Save user-visible connection string. This clobbers the original
311-
* conninfo, for security.
314+
* conninfo, for security. Also save host and port of the sender server
315+
* this walreceiver is connected to.
312316
*/
313317
tmp_conninfo=walrcv_get_conninfo(wrconn);
318+
walrcv_get_senderinfo(wrconn,&sender_host,&sender_port);
314319
SpinLockAcquire(&walrcv->mutex);
315320
memset(walrcv->conninfo,0,MAXCONNINFO);
316321
if (tmp_conninfo)
317322
strlcpy((char*)walrcv->conninfo,tmp_conninfo,MAXCONNINFO);
323+
324+
memset(walrcv->sender_host,0,NI_MAXHOST);
325+
if (sender_host)
326+
strlcpy((char*)walrcv->sender_host,sender_host,NI_MAXHOST);
327+
328+
walrcv->sender_port=sender_port;
318329
walrcv->ready_to_display= true;
319330
SpinLockRelease(&walrcv->mutex);
320331

321332
if (tmp_conninfo)
322333
pfree(tmp_conninfo);
323334

335+
if (sender_host)
336+
pfree(sender_host);
337+
324338
first_stream= true;
325339
for (;;)
326340
{
@@ -1402,6 +1416,8 @@ pg_stat_get_wal_receiver(PG_FUNCTION_ARGS)
14021416
TimestampTzlast_receipt_time;
14031417
XLogRecPtrlatest_end_lsn;
14041418
TimestampTzlatest_end_time;
1419+
charsender_host[NI_MAXHOST];
1420+
intsender_port=0;
14051421
charslotname[NAMEDATALEN];
14061422
charconninfo[MAXCONNINFO];
14071423

@@ -1419,6 +1435,8 @@ pg_stat_get_wal_receiver(PG_FUNCTION_ARGS)
14191435
latest_end_lsn=WalRcv->latestWalEnd;
14201436
latest_end_time=WalRcv->latestWalEndTime;
14211437
strlcpy(slotname, (char*)WalRcv->slotname,sizeof(slotname));
1438+
strlcpy(sender_host, (char*)WalRcv->sender_host,sizeof(sender_host));
1439+
sender_port=WalRcv->sender_port;
14221440
strlcpy(conninfo, (char*)WalRcv->conninfo,sizeof(conninfo));
14231441
SpinLockRelease(&WalRcv->mutex);
14241442

@@ -1482,10 +1500,18 @@ pg_stat_get_wal_receiver(PG_FUNCTION_ARGS)
14821500
nulls[10]= true;
14831501
else
14841502
values[10]=CStringGetTextDatum(slotname);
1485-
if (*conninfo=='\0')
1503+
if (*sender_host=='\0')
14861504
nulls[11]= true;
14871505
else
1488-
values[11]=CStringGetTextDatum(conninfo);
1506+
values[11]=CStringGetTextDatum(sender_host);
1507+
if (sender_port==0)
1508+
nulls[12]= true;
1509+
else
1510+
values[12]=Int32GetDatum(sender_port);
1511+
if (*conninfo=='\0')
1512+
nulls[13]= true;
1513+
else
1514+
values[13]=CStringGetTextDatum(conninfo);
14891515
}
14901516

14911517
/* Returns the record as Datum */

‎src/include/catalog/catversion.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,6 @@
5353
*/
5454

5555
/*yyyymmddN */
56-
#defineCATALOG_VERSION_NO201803291
56+
#defineCATALOG_VERSION_NO201803311
5757

5858
#endif

‎src/include/catalog/pg_proc.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2919,7 +2919,7 @@ DATA(insert OID = 3318 ( pg_stat_get_progress_info PGNSP PGUID 12 1 100 0 0
29192919
DESCR("statistics: information about progress of backends running maintenance command");
29202920
DATA(insert OID = 3099 ( pg_stat_get_wal_sendersPGNSP PGUID 12 1 10 0 0 f f f f t s r 0 0 2249 "" "{23,25,3220,3220,3220,3220,1186,1186,1186,23,25}" "{o,o,o,o,o,o,o,o,o,o,o}" "{pid,state,sent_lsn,write_lsn,flush_lsn,replay_lsn,write_lag,flush_lag,replay_lag,sync_priority,sync_state}" _null_ _null_ pg_stat_get_wal_senders _null_ _null_ _null_ ));
29212921
DESCR("statistics: information about currently active replication");
2922-
DATA(insert OID = 3317 ( pg_stat_get_wal_receiverPGNSP PGUID 12 1 0 0 0 f f f f f s r 0 0 2249 "" "{23,25,3220,23,3220,23,1184,1184,3220,1184,25,25}" "{o,o,o,o,o,o,o,o,o,o,o,o}" "{pid,status,receive_start_lsn,receive_start_tli,received_lsn,received_tli,last_msg_send_time,last_msg_receipt_time,latest_end_lsn,latest_end_time,slot_name,conninfo}" _null_ _null_ pg_stat_get_wal_receiver _null_ _null_ _null_ ));
2922+
DATA(insert OID = 3317 ( pg_stat_get_wal_receiverPGNSP PGUID 12 1 0 0 0 f f f f f s r 0 0 2249 "" "{23,25,3220,23,3220,23,1184,1184,3220,1184,25,25,23,25}" "{o,o,o,o,o,o,o,o,o,o,o,o,o,o}" "{pid,status,receive_start_lsn,receive_start_tli,received_lsn,received_tli,last_msg_send_time,last_msg_receipt_time,latest_end_lsn,latest_end_time,slot_name,sender_host,sender_port,conninfo}" _null_ _null_ pg_stat_get_wal_receiver _null_ _null_ _null_ ));
29232923
DESCR("statistics: information about WAL receiver");
29242924
DATA(insert OID = 6118 ( pg_stat_get_subscriptionPGNSP PGUID 12 1 0 0 0 f f f f f s r 1 0 2249 "26" "{26,26,26,23,3220,1184,1184,3220,1184}" "{i,o,o,o,o,o,o,o,o}" "{subid,subid,relid,pid,received_lsn,last_msg_send_time,last_msg_receipt_time,latest_end_lsn,latest_end_time}" _null_ _null_ pg_stat_get_subscription _null_ _null_ _null_ ));
29252925
DESCR("statistics: information about subscription");

‎src/include/replication/walreceiver.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,13 @@ typedef struct
108108
*/
109109
charconninfo[MAXCONNINFO];
110110

111+
/*
112+
* Host name (this can be a host name, an IP address, or a directory
113+
* path) and port number of the active replication connection.
114+
*/
115+
charsender_host[NI_MAXHOST];
116+
intsender_port;
117+
111118
/*
112119
* replication slot name; is also used for walreceiver to connect with the
113120
* primary
@@ -197,6 +204,9 @@ typedef WalReceiverConn *(*walrcv_connect_fn) (const char *conninfo, bool logica
197204
char**err);
198205
typedefvoid (*walrcv_check_conninfo_fn) (constchar*conninfo);
199206
typedefchar*(*walrcv_get_conninfo_fn) (WalReceiverConn*conn);
207+
typedefvoid (*walrcv_get_senderinfo_fn) (WalReceiverConn*conn,
208+
char**sender_host,
209+
int*sender_port);
200210
typedefchar*(*walrcv_identify_system_fn) (WalReceiverConn*conn,
201211
TimeLineID*primary_tli,
202212
int*server_version);
@@ -227,6 +237,7 @@ typedef struct WalReceiverFunctionsType
227237
walrcv_connect_fnwalrcv_connect;
228238
walrcv_check_conninfo_fnwalrcv_check_conninfo;
229239
walrcv_get_conninfo_fnwalrcv_get_conninfo;
240+
walrcv_get_senderinfo_fnwalrcv_get_senderinfo;
230241
walrcv_identify_system_fnwalrcv_identify_system;
231242
walrcv_readtimelinehistoryfile_fnwalrcv_readtimelinehistoryfile;
232243
walrcv_startstreaming_fnwalrcv_startstreaming;
@@ -246,6 +257,8 @@ extern PGDLLIMPORT WalReceiverFunctionsType *WalReceiverFunctions;
246257
WalReceiverFunctions->walrcv_check_conninfo(conninfo)
247258
#definewalrcv_get_conninfo(conn) \
248259
WalReceiverFunctions->walrcv_get_conninfo(conn)
260+
#definewalrcv_get_senderinfo(conn,sender_host,sender_port) \
261+
WalReceiverFunctions->walrcv_get_senderinfo(conn, sender_host, sender_port)
249262
#definewalrcv_identify_system(conn,primary_tli,server_version) \
250263
WalReceiverFunctions->walrcv_identify_system(conn, primary_tli, server_version)
251264
#definewalrcv_readtimelinehistoryfile(conn,tli,filename,content,size) \

‎src/test/regress/expected/rules.out

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1972,8 +1972,10 @@ pg_stat_wal_receiver| SELECT s.pid,
19721972
s.latest_end_lsn,
19731973
s.latest_end_time,
19741974
s.slot_name,
1975+
s.sender_host,
1976+
s.sender_port,
19751977
s.conninfo
1976-
FROM pg_stat_get_wal_receiver() s(pid, status, receive_start_lsn, receive_start_tli, received_lsn, received_tli, last_msg_send_time, last_msg_receipt_time, latest_end_lsn, latest_end_time, slot_name, conninfo)
1978+
FROM pg_stat_get_wal_receiver() s(pid, status, receive_start_lsn, receive_start_tli, received_lsn, received_tli, last_msg_send_time, last_msg_receipt_time, latest_end_lsn, latest_end_time, slot_name,sender_host, sender_port,conninfo)
19771979
WHERE (s.pid IS NOT NULL);
19781980
pg_stat_xact_all_tables| SELECT c.oid AS relid,
19791981
n.nspname AS schemaname,

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp