File tree Expand file tree Collapse file tree 1 file changed +8
-0
lines changed Expand file tree Collapse file tree 1 file changed +8
-0
lines changed Original file line number Diff line number Diff line change @@ -221,6 +221,10 @@ def get_replication_delays(conn):
221
221
sql = ("SELECT client_addr, "
222
222
"pg_xlog_location_diff(pg_current_xlog_location(), replay_location) AS bytes_diff "
223
223
"FROM public.pg_stat_repl" )
224
+ if is_in_recovery (conn ):
225
+ # pg_current_xlog_location cannot be called in a replica
226
+ # use pg_last_xlog_receive_location for monitoring cascade replication
227
+ sql = sql .replace ("pg_current_xlog_location" , "pg_last_xlog_receive_location" )
224
228
if conn .server_version >= 100000 : # PostgreSQL 10 and higher
225
229
sql = sql .replace ('_xlog' , '_wal' )
226
230
sql = sql .replace ('_location' , '_lsn' )
@@ -273,3 +277,7 @@ def get_wal_receiver_status(conn):
273
277
host = CONNINFO_HOST_RE .search (conn_info ).groupdict ().get ('host' , 'UNKNOWN' )
274
278
host_replication_status .append ((host , status ))
275
279
return host_replication_status
280
+
281
+
282
+ def is_in_recovery (conn ):
283
+ return query (conn , "SELECT pg_is_in_recovery()" )[0 ][0 ]
You can’t perform that action at this time.
0 commit comments