Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed using pg_current_wal_lsn if pg_is_in_recovery is true #65

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions internal/collector/postgres_replication_slots.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,16 @@ import (

const (
// Query for Postgres version 9.6 and older.
postgresReplicationSlotQuery96 = "SELECT database, slot_name, slot_type, active, pg_current_xlog_location() - restart_lsn AS since_restart_bytes FROM pg_replication_slots"
postgresReplicationSlotQuery96 = "SELECT database, slot_name, slot_type, active, " +
"CASE WHEN pg_is_in_recovery() THEN pg_xlog_location_diff(pg_current_xlog_location(), restart_lsn) " +
"ELSE pg_xlog_location_diff(pg_current_xlog_location(), restart_lsn) END AS since_restart_bytes " +
"FROM pg_replication_slots"

// Query for Postgres versions from 10 and newer.
postgresReplicationSlotQueryLatest = "SELECT database, slot_name, slot_type, active, pg_current_wal_lsn() - restart_lsn AS since_restart_bytes FROM pg_replication_slots"
postgresReplicationSlotQueryLatest = "SELECT database, slot_name, slot_type, active, " +
"CASE WHEN pg_is_in_recovery() THEN pg_wal_lsn_diff(pg_last_wal_receive_lsn(), restart_lsn) " +
"ELSE pg_wal_lsn_diff(pg_current_wal_lsn(), restart_lsn) END AS since_restart_bytes " +
"FROM pg_replication_slots"
)

type postgresReplicationSlotCollector struct {
Expand Down
Loading