Sha256: 07d67907ddecf6a13af2b53167d2ae01014f5f53c34d27c3af2872ce4c68af2f

Contents?: true

Size: 756 Bytes

Versions: 1

Compression:

Stored size: 756 Bytes

Contents

module PgHero
  module Methods
    module Replica
      def replica?
        unless defined?(@replica)
          @replica = select_all("SELECT setting FROM pg_settings WHERE name = 'hot_standby'").first["setting"] == "on"
        end
        @replica
      end

      # http://www.postgresql.org/message-id/CADKbJJWz9M0swPT3oqe8f9+tfD4-F54uE6Xtkh4nERpVsQnjnw@mail.gmail.com
      def replication_lag
        select_all(<<-SQL
          SELECT
            CASE
              WHEN pg_last_xlog_receive_location() = pg_last_xlog_replay_location() THEN 0
              ELSE EXTRACT (EPOCH FROM NOW() - pg_last_xact_replay_timestamp())
            END
          AS replication_lag
        SQL
        ).first["replication_lag"].to_f
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
pghero-1.6.4 lib/pghero/methods/replica.rb