Commit 98d6eb28 authored by Gabriel Mazetto's avatar Gabriel Mazetto

Update query to retreive database WAL position

The new query specify conditions to match primary and standy leaders
parent ed0fe440
...@@ -260,7 +260,15 @@ module Gitlab ...@@ -260,7 +260,15 @@ module Gitlab
# @return [String] # @return [String]
def self.get_write_location(ar_connection) def self.get_write_location(ar_connection)
row = ar_connection row = ar_connection
.select_all('SELECT CASE WHEN pg_is_in_recovery() = true THEN pg_last_wal_replay_lsn()::text ELSE pg_current_wal_insert_lsn()::text END AS location;') .select_all(<<~SQL)
SELECT CASE
WHEN pg_is_in_recovery() = true AND EXISTS (SELECT 1 FROM pg_stat_get_wal_senders())
THEN pg_last_wal_replay_lsn()::text
WHEN pg_is_in_recovery() = false
THEN pg_current_wal_insert_lsn()::text
ELSE NULL
END AS location;
SQL
.first .first
row['location'] if row row['location'] if row
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment