Skip to content

Commit e5194d6

Browse files
phumpalmajormoses
authored andcommitted
Fixes replication check compatibility in PG 10
1 parent d34e294 commit e5194d6

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ This project adheres to [Semantic Versioning](http://semver.org/).
44
This CHANGELOG follows the format listed [here](https://github.com/sensu-plugins/community/blob/master/HOW_WE_CHANGELOG.md).
55

66
## [Unreleased]
7+
### Fixed
8+
- check-postgres-replication.rb: maintains backwards compatibility with <= 9.6 and adds compatibility for >= 10
79

810
## [1.4.2] - 2017-09-27
911
### Fixed

bin/check-postgres-replication.rb

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,13 @@ def run
117117
sslmode: ssl_mode,
118118
connect_timeout: config[:timeout])
119119

120-
master = conn_master.exec('SELECT pg_current_xlog_location()').getvalue(0, 0)
120+
begin
121+
# PostgreSQL 10
122+
master = conn_master.exec('SELECT pg_current_wal_lsn()').getvalue(0, 0)
123+
rescue
124+
# PostgreSQL <= 9.6
125+
master = conn_master.exec('SELECT pg_current_xlog_location()').getvalue(0, 0)
126+
end
121127
m_segbytes = conn_master.exec('SHOW wal_segment_size').getvalue(0, 0).sub(/\D+/, '').to_i << 20
122128
conn_master.close
123129

@@ -130,7 +136,13 @@ def run
130136
sslmode: ssl_mode,
131137
connect_timeout: config[:timeout])
132138

133-
slave = conn_slave.exec('SELECT pg_last_xlog_receive_location()').getvalue(0, 0)
139+
begin
140+
# PostgreSQL 10
141+
slave = conn_slave.exec('SELECT pg_last_wal_replay_lsn()').getvalue(0, 0)
142+
rescue
143+
# PostgreSQL <= 9.6
144+
slave = conn_slave.exec('SELECT pg_last_xlog_receive_location()').getvalue(0, 0)
145+
end
134146
conn_slave.close
135147

136148
# Computing lag

0 commit comments

Comments
 (0)