Skip to content
Browse files

Improve monitoring PostgreSQL replication in pysysinfo.

  • Loading branch information...
1 parent bea45be commit 47cb465aac1bfcbad2786168fb3aea34288a6174 @aouyar committed
Showing with 32 additions and 3 deletions.
  1. +32 −3 pysysinfo/postgresql.py
View
35 pysysinfo/postgresql.py
@@ -242,9 +242,16 @@ def getXlogStatus(self):
inRecovery = self._simpleQuery("SELECT pg_is_in_recovery();")
cur = self._conn.cursor()
if inRecovery:
- cur.execute("""SELECT
- pg_last_xlog_receive_location(),
- pg_last_xlog_replay_location();""")
+ cols = ['pg_last_xlog_receive_location()',
+ 'pg_last_xlog_replay_location()',]
+ headers = ['xlog_receive_location',
+ 'xlog_replay_location',]
+ if self.checkVersion('9.1'):
+ cols.extend(['pg_last_xact_replay_timestamp()',
+ 'pg_is_xlog_replay_paused()',])
+ headers.extend(['xact_replay_timestamp',
+ 'xlog_replay_paused',])
+ cur.execute("""SELECT %s;""" % ','.join(cols))
headers = ('xlog_receive_location', 'xlog_replay_location')
else:
cur.execute("""SELECT
@@ -256,3 +263,25 @@ def getXlogStatus(self):
if inRecovery is not None:
info_dict['in_recovery'] = inRecovery
return info_dict
+
+ def getSlaveStatus(self):
+ """Returns status of replication slaves.
+
+ @return: Dictionary of status items.
+
+ """
+ info_dict = {}
+ if self.checkVersion('9.1'):
+ cols = ['procpid', 'usename', 'application_name',
+ 'client_addr', 'client_port', 'backend_start', 'state',
+ 'sent_location', 'write_location', 'flush_location',
+ 'replay_location', 'sync_priority', 'sync_state',]
+ cur = self._conn.cursor()
+ cur.execute("""SELECT %s FROM pg_stat_replication;"""
+ % ','.join(cols))
+ rows = cur.fetchall()
+ for row in rows:
+ info_dict[row[0]] = dict(zip(cols[1:], row[1:]))
+ else:
+ return None
+ return info_dict

0 comments on commit 47cb465

Please sign in to comment.
Something went wrong with that request. Please try again.