Skip to content

Commit bb26a64

Browse files
committed
Merge branch 'knutemann-master'
2 parents 01e4eb4 + 7e8fbdf commit bb26a64

File tree

2 files changed

+272
-163
lines changed

2 files changed

+272
-163
lines changed

README.md

+39
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,42 @@ for l in StringIO(x):
4141
```
4242
Adjust the value of the resultant prometheus value type appropriately. This helps build
4343
rich self-documenting metrics for the exporter.
44+
45+
46+
### Running as non-superuser
47+
48+
To be able to collect metrics from pg_stat_activity and pg_stat_replication as non-superuser you have to create functions and views to do so.
49+
50+
```sql
51+
CREATE USER postgres_exporter PASSWORD 'password';
52+
ALTER USER postgres_exporter SET SEARCH_PATH TO postgres_exporter,pg_catalog;
53+
54+
CREATE SCHEMA postgres_exporter AUTHORIZATION postgres_exporter;
55+
56+
CREATE FUNCTION postgres_exporter.f_select_pg_stat_activity()
57+
RETURNS setof pg_catalog.pg_stat_activity
58+
LANGUAGE sql
59+
SECURITY DEFINER
60+
AS $$
61+
SELECT * from pg_catalog.pg_stat_activity;
62+
$$;
63+
64+
CREATE FUNCTION postgres_exporter.f_select_pg_stat_replication()
65+
RETURNS setof pg_catalog.pg_stat_replication
66+
LANGUAGE sql
67+
SECURITY DEFINER
68+
AS $$
69+
SELECT * from pg_catalog.pg_stat_replication;
70+
$$;
71+
72+
CREATE VIEW postgres_exporter.pg_stat_replication
73+
AS
74+
SELECT * FROM postgres_exporter.f_select_pg_stat_replication();
75+
76+
CREATE VIEW postgres_exporter.pg_stat_activity
77+
AS
78+
SELECT * FROM postgres_exporter.f_select_pg_stat_activity();
79+
80+
GRANT SELECT ON postgres_exporter.pg_stat_replication TO postgres_exporter;
81+
GRANT SELECT ON postgres_exporter.pg_stat_activity TO postgres_exporter;
82+
```

0 commit comments

Comments
 (0)