ankane / distribute_reads

Scale database reads to replicas in Rails

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

DistributeReads.replication_lag throws an error on Aurora PG 11.9

kknd113 opened this issue · comments

I ran into this issue when running DistributeReads.replication_lag
Is there a way to work around this?

> DistributeReads.replication_lag
ActiveRecord::StatementInvalid: PG::FeatureNotSupported: ERROR:  Function pg_last_xlog_receive_location() is currently not supported for Aurora
: SELECT CASE WHEN NOT pg_is_in_recovery() OR pg_last_wal_receive_lsn() = pg_last_wal_replay_lsn() THEN 0 ELSE EXTRACT (EPOCH FROM NOW() - pg_last_xact_replay_timestamp()) END AS lag
from /opt/rubies/ruby-2.6.5/lib/ruby/gems/2.6.0/ruby/2.6.0/gems/activerecord-5.0.7.2/lib/active_record/connection_adapters/postgresql_adapter.rb:600:in `async_exec'
Caused by PG::FeatureNotSupported: ERROR:  Function pg_last_xlog_receive_location() is currently not supported for Aurora

Hey @kknd113, as far as I know, there's not a way to query replication lag on Aurora Postgres.

Added by @rezigned in #47 🎉

Unfortunately, there doesn't seem to be a way to get the lag for the specific replica that's querying, so it takes the max of all replicas.