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):
221221 sql = ("SELECT client_addr, "
222222 "pg_xlog_location_diff(pg_current_xlog_location(), replay_location) AS bytes_diff "
223223 "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" )
224228 if conn .server_version >= 100000 : # PostgreSQL 10 and higher
225229 sql = sql .replace ('_xlog' , '_wal' )
226230 sql = sql .replace ('_location' , '_lsn' )
@@ -273,3 +277,7 @@ def get_wal_receiver_status(conn):
273277 host = CONNINFO_HOST_RE .search (conn_info ).groupdict ().get ('host' , 'UNKNOWN' )
274278 host_replication_status .append ((host , status ))
275279 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