Closed
Description
What did you do?
- check out main as of d273f97
- make build
- configure env vars for my PG instance
- start the exporter
What did you expect to see?
Loading the web endpoint hosted by the exporter should display postgres stats.
What did you see instead? Under which circumstances?
When hitting the web endpoint, the exporter throws an error:
ts=2023-03-12T19:18:30.626Z caller=collector.go:194 level=error msg="collector failed" name=replication_slot duration_seconds=0.241972666 err="sql: Scan error on column index 3, name \"active\": converting driver.Value type bool (\"true\") to a int64: invalid syntax"
Environment
-
macOS 13.2.1 / 22D68
-
go version go1.19.5 darwin/arm64
-
System information:
Darwin 22.3.0 arm64
- postgres_exporter version:
postgres_exporter, version 0.12.0-rc.0 (branch: master, revision: d273f97b729614b93267cc7ebf7cd4646aebe1d4)
build user: andre@boom
build date: 20230312-19:46:47
go version: go1.19.5
platform: darwin/arm64
- postgres_exporter flags:
none (all config via env vars)
- PostgreSQL version:
server is 13.7.0
- Logs:
ts=2023-03-12T19:18:30.626Z caller=collector.go:194 level=error msg="collector failed" name=replication_slot duration_seconds=0.241972666 err="sql: Scan error on column index 3, name \"active\": converting driver.Value type bool (\"true\") to a int64: invalid syntax"
- Possible fix:
With the following change, things appear to work as I expect:
diff --git a/collector/replication_slots.go b/collector/replication_slots.go
index ed37441..a9cad77 100644
--- a/collector/replication_slots.go
+++ b/collector/replication_slots.go
@@ -69,7 +69,7 @@ func (PGReplicationSlotCollector) Update(ctx context.Context, db *sql.DB, ch cha
var slot_name string
var wal_lsn int64
var flush_lsn int64
- var is_active int64
+ var is_active bool
if err := rows.Scan(&slot_name, &wal_lsn, &flush_lsn, &is_active); err != nil {
return err
}
@@ -78,7 +78,7 @@ func (PGReplicationSlotCollector) Update(ctx context.Context, db *sql.DB, ch cha
pgReplicationSlot["current_wal_lsn"],
prometheus.GaugeValue, float64(wal_lsn), slot_name,
)
- if is_active == 1 {
+ if is_active {
ch <- prometheus.MustNewConstMetric(
pgReplicationSlot["confirmed_flush_lsn"],
prometheus.GaugeValue, float64(flush_lsn), slot_name,
Replication stats seems to be a recently added feature of the exporter, added in #747
I can confirm that the type of the active
column in pg_replication_slots
is indeed boolean:
> \d+ pg_replication_slots
View "pg_catalog.pg_replication_slots"
Column | Type | Collation | Nullable | Default | Storage | Description
---------------------+---------+-----------+----------+---------+----------+-------------
slot_name | name | | | | plain |
plugin | name | | | | plain |
slot_type | text | | | | extended |
datoid | oid | | | | plain |
database | name | | | | plain |
temporary | boolean | | | | plain |
active | boolean | | | | plain |
active_pid | integer | | | | plain |
xmin | xid | | | | plain |
catalog_xmin | xid | | | | plain |
restart_lsn | pg_lsn | | | | plain |
confirmed_flush_lsn | pg_lsn | | | | plain |
wal_status | text | | | | extended |
safe_wal_size | bigint | | | | plain |
View definition:
SELECT l.slot_name,
l.plugin,
l.slot_type,
l.datoid,
d.datname AS database,
l.temporary,
l.active,
l.active_pid,
l.xmin,
l.catalog_xmin,
l.restart_lsn,
l.confirmed_flush_lsn,
l.wal_status,
l.safe_wal_size
FROM pg_get_replication_slots() l(slot_name, plugin, slot_type, datoid, temporary, active, active_pid, xmin, catalog_xmin, restart_lsn, confirmed_flush_lsn, wal_status, safe_wal_size)
LEFT JOIN pg_database d ON l.datoid = d.oid;
This is the first time I've used postgres_exporter so I'm not super confident that I haven't overlooked something important...
Thanks :)
Metadata
Metadata
Assignees
Labels
No labels