Skip to content
This repository was archived by the owner on Nov 28, 2022. It is now read-only.

Commit fab005d

Browse files
committed
Add function to check permission for pgstattuple
1 parent 26388a5 commit fab005d

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

gauges/deadtuples.go

+12
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ func (g *Gauges) DeadTuples() *prometheus.GaugeVec {
2323
log.Warn("postgresql_dead_tuples_pct disabled because pgstattuple extension is not installed")
2424
return gauge
2525
}
26+
if !g.hasPermissionToExecutePgStatTuple() {
27+
log.Warn("postgresql_dead_tuples_pct disabled because user doesn't have permission to use pgstattuple functions")
28+
return gauge
29+
}
2630

2731
const relationsQuery = `
2832
SELECT relname FROM pg_stat_user_tables ORDER BY n_tup_ins + n_tup_upd desc LIMIT 20
@@ -49,3 +53,11 @@ func (g *Gauges) DeadTuples() *prometheus.GaugeVec {
4953

5054
return gauge
5155
}
56+
57+
func (g *Gauges) hasPermissionToExecutePgStatTuple() bool {
58+
if _, err := g.db.Exec("SELECT 1 FROM pgstattuple('pg_class')"); err != nil {
59+
log.WithError(err).Error("failed to execute pgstattuple function")
60+
return false
61+
}
62+
return true
63+
}

0 commit comments

Comments
 (0)