Difference between revisions of "/usr/share/doc/prometheus-postgres-exporter/README.Debian"

From wikieduonline
Jump to navigation Jump to search
(Created page with "<pre> To use the PostgreSQL exporter, you need to connect to the database with superuser (postgres) privileges, or with an user that has been granted enough permissions. The...")
 
 
(8 intermediate revisions by the same user not shown)
Line 1: Line 1:
<pre>
 
To use the PostgreSQL exporter, you need to connect to the database with
 
superuser (postgres) privileges, or with an user that has been granted enough
 
permissions.
 
  
The recommended way to do this, is to create a `prometheus` user with no
+
To use the PostgreSQL exporter, you need to connect to the database with
password, and then connect using UNIX domain sockets.
+
superuser (postgres) privileges, or with an user that has been granted enough
 
+
permissions.
To do that, set this connection string in
+
/etc/default/prometheus-postgres-exporter:
+
The recommended way to do this, is to create a `prometheus` user with no
 +
password, and then connect using UNIX domain sockets.
 +
 +
To do that, set this connection string in
 +
[[/etc/default/prometheus-postgres-exporter]]:
  
 
   DATA_SOURCE_NAME='user=prometheus host=/run/postgresql dbname=postgres'
 
   DATA_SOURCE_NAME='user=prometheus host=/run/postgresql dbname=postgres'
  
And use psql (sudo -u postgres psql) to execute these SQL commands to create
+
And use psql (sudo -u postgres psql) to execute these SQL commands to create
the user:
+
the user:
  
 
   CREATE USER prometheus;
 
   CREATE USER prometheus;
   ALTER USER prometheus SET SEARCH_PATH TO prometheus,pg_catalog;
+
   [[ALTER USER]] prometheus [[SET]] SEARCH_PATH TO prometheus,pg_catalog;
  
   CREATE SCHEMA prometheus AUTHORIZATION prometheus;
+
   [[PostgreSQL: CREATE SCHEMA|CREATE SCHEMA]] prometheus AUTHORIZATION prometheus;
  
 
   CREATE FUNCTION prometheus.f_select_pg_stat_activity()
 
   CREATE FUNCTION prometheus.f_select_pg_stat_activity()
Line 28: Line 28:
 
   $$;
 
   $$;
  
   CREATE FUNCTION prometheus.f_select_pg_stat_replication()
+
   [[CREATE FUNCTION]] prometheus.f_select_pg_stat_replication()
 
   RETURNS setof pg_catalog.pg_stat_replication
 
   RETURNS setof pg_catalog.pg_stat_replication
 
   LANGUAGE sql
 
   LANGUAGE sql
Line 36: Line 36:
 
   $$;
 
   $$;
  
   CREATE VIEW prometheus.pg_stat_replication
+
   [[CREATE VIEW]] prometheus.pg_stat_replication
 
   AS
 
   AS
 
     SELECT * FROM prometheus.f_select_pg_stat_replication();
 
     SELECT * FROM prometheus.f_select_pg_stat_replication();
Line 44: Line 44:
 
     SELECT * FROM prometheus.f_select_pg_stat_activity();
 
     SELECT * FROM prometheus.f_select_pg_stat_activity();
  
   GRANT SELECT ON prometheus.pg_stat_replication TO prometheus;
+
   [[GRANT SELECT ON]] prometheus.[[pg_stat_replication]] TO prometheus;
   GRANT SELECT ON prometheus.pg_stat_activity TO prometheus;
+
   GRANT SELECT ON prometheus.[[pg_stat_activity]] TO prometheus;
</pre>
+
 
 +
 
 +
== See also ==
 +
* {{exporter}}
 +
* {{Prometheus}}
 +
 
 +
[[Category:Prometheus]]
 +
[[Category:PostgreSQL]]

Latest revision as of 11:30, 8 February 2023

To use the PostgreSQL exporter, you need to connect to the database with
superuser (postgres) privileges, or with an user that has been granted enough
permissions.

The recommended way to do this, is to create a `prometheus` user with no
password, and then connect using UNIX domain sockets.

To do that, set this connection string in
/etc/default/prometheus-postgres-exporter:
 DATA_SOURCE_NAME='user=prometheus host=/run/postgresql dbname=postgres'
And use psql (sudo -u postgres psql) to execute these SQL commands to create
the user:
 CREATE USER prometheus;
 ALTER USER prometheus SET SEARCH_PATH TO prometheus,pg_catalog;
 CREATE SCHEMA prometheus AUTHORIZATION prometheus;
 CREATE FUNCTION prometheus.f_select_pg_stat_activity()
 RETURNS setof pg_catalog.pg_stat_activity
 LANGUAGE sql
 SECURITY DEFINER
 AS $$
   SELECT * from pg_catalog.pg_stat_activity;
 $$;
 CREATE FUNCTION prometheus.f_select_pg_stat_replication()
 RETURNS setof pg_catalog.pg_stat_replication
 LANGUAGE sql
 SECURITY DEFINER
 AS $$
   SELECT * from pg_catalog.pg_stat_replication;
 $$;
 CREATE VIEW prometheus.pg_stat_replication
 AS
   SELECT * FROM prometheus.f_select_pg_stat_replication();
 CREATE VIEW prometheus.pg_stat_activity
 AS
   SELECT * FROM prometheus.f_select_pg_stat_activity();
 GRANT SELECT ON prometheus.pg_stat_replication TO prometheus;
 GRANT SELECT ON prometheus.pg_stat_activity TO prometheus;


See also[edit]

Advertising: