diff options
author | Mark Wong <mark@2ndQuadrant.com> | 2019-09-13 13:39:59 +0000 |
---|---|---|
committer | Mark Wong <mark@2ndQuadrant.com> | 2019-09-13 13:39:59 +0000 |
commit | 35e83cfd2b82a2ab39d8838628e0df218cdd5f24 (patch) | |
tree | d4dfc610ed9025c7a17ba9906cac412f931229d4 | |
parent | c7c423eb6000bae5a1965beb1221e1b5747bcaa4 (diff) |
Update replication query for v10 changes
-rw-r--r-- | machine/m_linux.c | 4 | ||||
-rw-r--r-- | pg.c | 21 |
2 files changed, 22 insertions, 3 deletions
diff --git a/machine/m_linux.c b/machine/m_linux.c index 626c80e..8949fa8 100644 --- a/machine/m_linux.c +++ b/machine/m_linux.c @@ -165,7 +165,7 @@ char fmt_header_io[] = " PID RCHAR WCHAR SYSCR SYSCW READS WRITES CWRITES COMMAND"; char fmt_header_replication[] = -" PID USERNAME APPLICATION CLIENT STATE PRIMARY SENT WRITE FLUSH REPLAY SLAG WLAG FLAG RLAG"; +" PID USERNAME APPLICATION CLIENT STATE PRIMARY SENT WRITE FLUSH REPLAY SLAG WLAG FLAG RLAG"; /* these are names given to allowed sorting orders -- first is default */ static char *ordernames[] = @@ -988,7 +988,7 @@ format_next_replication(caddr_t handle) struct top_proc *p = &pgtable[proc_index++]; snprintf(fmt, sizeof(fmt), - "%5d %-8.8s %-11.11s %15s %-9.9s %10s %10s %10s %10s %10s %5s %5s %5s %5s", + "%5d %-8.8s %-11.11s %15s %-9.9s %-10.10s %-10.10s %-10.10s %-10.10s %-10.10s %5s %5s %5s %5s", p->pid, p->usename, p->application_name, @@ -41,6 +41,21 @@ #define REPLICATION \ "SELECT pid, usename, application_name, client_addr, state,\n" \ + " pg_current_wal_insert_lsn() AS primary,\n" \ + " sent_lsn, write_lsn, flush_lsn,\n" \ + " replay_lsn, \n" \ + " pg_wal_lsn_diff(pg_current_wal_insert_lsn(),\n" \ + " sent_lsn) as sent_lag,\n" \ + " pg_wal_lsn_diff(pg_current_wal_insert_lsn(),\n" \ + " write_lsn) as write_lag,\n" \ + " pg_wal_lsn_diff(pg_current_wal_insert_lsn(),\n" \ + " flush_lsn) as flush_lag,\n" \ + " pg_wal_lsn_diff(pg_current_wal_insert_lsn(),\n" \ + " replay_lsn) as replay_lag\n" \ + " FROM pg_stat_replication;" + +#define REPLICATION_9_6 \ + "SELECT pid, usename, application_name, client_addr, state,\n" \ " pg_current_xlog_insert_location() AS primary,\n" \ " sent_location, write_location, flush_location,\n" \ " replay_location, \n" \ @@ -160,7 +175,11 @@ pg_replication(PGconn *pgconn) PQexec(pgconn, "BEGIN;"); PQexec(pgconn, "SET statement_timeout = '2s';"); - pgresult = PQexec(pgconn, REPLICATION); + if (pg_version(pgconn) >= 1000) { + pgresult = PQexec(pgconn, REPLICATION); + } else { + pgresult = PQexec(pgconn, REPLICATION_9_6); + } PQexec(pgconn, "ROLLBACK;"); return pgresult; } |