Open Just-MP opened 5 months ago
Here the grafana charts before and after the debugging and granting
I will fix here key link for the solution: https://dba.stackexchange.com/a/259142 pg_read_all_stats are mandatory. Even though there is a words in PG docs https://www.postgresql.org/docs/current/predefined-roles.html that pg_monitor is a member "This role is a member of pg_read_all_settings, pg_read_all_stats and pg_stat_scan_tables", somehow it is not. user with pg_monitor cannot show states of the connections without a pg_read_all_stats.
Hey, @Just-MP !
I just went through the same problem and ended up here. I am using two database versions, 13.16 and 15.8 and this is what I think is the minimum set of commands to execute to allow the prometheus
scrapping user access to the stats.
As postgres
user, psql --dbname=postgres
and:
CREATE USER prometheus WITH NOSUPERUSER NOCREATEDB NOCREATEROLE;
GRANT pg_monitor to prometheus;
GRANT pg_read_all_stats to prometheus;
CREATE SCHEMA prometheus AUTHORIZATION prometheus;
ALTER USER prometheus SET SEARCH_PATH TO prometheus,pg_catalog;
I am unsure whether the last two commands are actually necessary. Would you be so kind as to confirm this, in case you know?
Thanks.
What did you do? I've created PostgreSQL user for monitoring as described in the readme
I've installed postgres_exporter and I've run it. Connected to prometheus without problems. Created postgres-exporter dashboard in the grafana without problems.
What did you expect to see? All metrics work as expected.
What did you see instead? Under which circumstances? In the grafana most of metrics worked succesfully However during of monitoring of our load testing there was always 1 connection active in Grafana monitoring in the "Connections by state (stacked)" chart. After checking pg_stat_activity under postgres superuser I've found that there are 480+ connections really, sometimes idle, sometimes active during the test. Environment
System information:
Linux 5.10.0-27-amd64 x86_64
postgres_exporter version:
exporter have been run from the "latest" docker container:
ExecStart=/usr/bin/docker run \ --net=host \ -e DATA_SOURCE_NAME="postgresql://postgres_metrics_exporter:my_pwd@127.0.0.1:my_pg_port/postgres?sslmode=disable" \ --name=postgres-exporter-container \ quay.io/prometheuscommunity/postgres-exporter:latest
PostgreSQL version:
15.6
Diving down the issue I've found that pg_monitor user rights are not enough to find any connection state from pg_stat_activity:
(note the NULL value in the state column of the output in all the rows except the two) but when granted pg_read_all_stats to the user, query to the pg_stat_activity worked as expected:
So, the citation from the manual
is wrong. I need both pg_monitor AND pg_read_all_stats roles to get states of the connections from grafana by postgres_exporter.
As well as I have need grants
for metrics to work, not the
citation from your docs. It will not get neither provide to prometheus info about connection states. Please fix the docs.