Skip to content

Commit e627dad

Browse files
authored
Merge pull request #5 from NextDeveloperTeam/slot-name-fix
pg_stat_replication - fix `slot_name` using the `pid` value
2 parents 922fd63 + 2d626c6 commit e627dad

File tree

2 files changed

+15
-12
lines changed

2 files changed

+15
-12
lines changed

cmd/postgres_exporter/postgres_exporter.go

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -271,15 +271,15 @@ var builtinMetricMaps = map[string]intermediateMetricMap{
271271
},
272272
"pg_stat_replication": {
273273
map[string]ColumnMapping{
274-
"procpid": {DISCARD, "Process ID of a WAL sender process", nil, semver.MustParseRange("<9.2.0")},
275-
"pid": {DISCARD, "Process ID of a WAL sender process", nil, semver.MustParseRange(">=9.2.0")},
276-
"usesysid": {DISCARD, "OID of the user logged into this WAL sender process", nil, nil},
277-
"usename": {DISCARD, "Name of the user logged into this WAL sender process", nil, nil},
278-
"application_name": {LABEL, "Name of the application that is connected to this WAL sender", nil, nil},
279-
"client_addr": {LABEL, "IP address of the client connected to this WAL sender. If this field is null, it indicates that the client is connected via a Unix socket on the server machine.", nil, nil},
280-
"client_hostname": {DISCARD, "Host name of the connected client, as reported by a reverse DNS lookup of client_addr. This field will only be non-null for IP connections, and only when log_hostname is enabled.", nil, nil},
281-
"client_port": {DISCARD, "TCP port number that the client is using for communication with this WAL sender, or -1 if a Unix socket is used", nil, nil},
282-
"backend_start": {DISCARD, "with time zone Time when this process was started, i.e., when the client connected to this WAL sender", nil, nil},
274+
"procpid": {DISCARD, "Process ID of a WAL sender process", nil, semver.MustParseRange("<9.2.0")},
275+
"pid": {DISCARD, "Process ID of a WAL sender process", nil, semver.MustParseRange(">=9.2.0")},
276+
"usesysid": {DISCARD, "OID of the user logged into this WAL sender process", nil, nil},
277+
"usename": {DISCARD, "Name of the user logged into this WAL sender process", nil, nil},
278+
"application_name": {LABEL, "Name of the application that is connected to this WAL sender", nil, nil},
279+
"client_addr": {LABEL, "IP address of the client connected to this WAL sender. If this field is null, it indicates that the client is connected via a Unix socket on the server machine.", nil, nil},
280+
"client_hostname": {DISCARD, "Host name of the connected client, as reported by a reverse DNS lookup of client_addr. This field will only be non-null for IP connections, and only when log_hostname is enabled.", nil, nil},
281+
"client_port": {DISCARD, "TCP port number that the client is using for communication with this WAL sender, or -1 if a Unix socket is used", nil, nil},
282+
"backend_start": {DISCARD, "with time zone Time when this process was started, i.e., when the client connected to this WAL sender", nil, nil},
283283
"backend_xmin": {DISCARD, "The current backend's xmin horizon.", nil, nil},
284284
"state": {LABEL, "Current WAL sender state", nil, nil},
285285
"sent_location": {DISCARD, "Last transaction log position sent on this connection", nil, semver.MustParseRange("<10.0.0")},
@@ -391,11 +391,12 @@ var queryOverrides = map[string][]OverrideQuery{
391391
{
392392
semver.MustParseRange(">=10.0.0"),
393393
`
394-
SELECT *,
394+
SELECT stat.*, slots.slot_name,
395395
(case pg_is_in_recovery() when 't' then null else pg_current_wal_lsn() end) AS pg_current_wal_lsn,
396396
(case pg_is_in_recovery() when 't' then null else pg_wal_lsn_diff(pg_current_wal_lsn(), pg_lsn('0/0'))::float end) AS pg_current_wal_lsn_bytes,
397397
(case pg_is_in_recovery() when 't' then null else pg_wal_lsn_diff(pg_current_wal_lsn(), replay_lsn)::float end) AS pg_wal_lsn_diff
398-
FROM pg_stat_replication
398+
FROM pg_stat_replication stat
399+
JOIN pg_replication_slots slots on stat.pid = slots.active_pid
399400
`,
400401
},
401402
{

magefile.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
//go:build mage
12
// +build mage
3+
24
// Self-contained go-project magefile.
35

46
// nolint: deadcode
@@ -637,7 +639,7 @@ func Release() error {
637639
func makeBuilder(cmd string, platform Platform) func() error {
638640
f := func() error {
639641
// Depend on assets
640-
mg.Deps(Assets)
642+
//mg.Deps(Assets)
641643

642644
cmdSrc := fmt.Sprintf("./%s/%s", mustStr(filepath.Rel(curDir, cmdDir)), cmd)
643645

0 commit comments

Comments
 (0)