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

Commit 4ad63c9

Browse files
committed
update readme, add new monitoring function
1 parent 4c8e831 commit 4ad63c9

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

README.md

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,31 @@ CREATE OR REPLACE FUNCTION monitoring.pgstattuple(IN relname text,
5555
FROM public.pgstattuple(relname)
5656
$$ LANGUAGE SQL VOLATILE SECURITY DEFINER;
5757

58+
CREATE OR REPLACE FUNCTION monitoring.pgstattuple_approx(IN relname text,
59+
OUT table_len BIGINT,
60+
OUT scanned_percent FLOAT8,
61+
OUT approx_tuple_count BIGINT,
62+
OUT approx_tuple_len BIGINT,
63+
OUT approx_tuple_percent FLOAT8,
64+
OUT dead_tuple_count BIGINT,
65+
OUT dead_tuple_len BIGINT,
66+
OUT dead_tuple_percent FLOAT8,
67+
OUT approx_free_space BIGINT,
68+
OUT approx_free_percent FLOAT8) AS $$
69+
SELECT
70+
table_len,
71+
scanned_percent,
72+
approx_tuple_count,
73+
approx_tuple_len,
74+
approx_tuple_percent,
75+
dead_tuple_count,
76+
dead_tuple_len,
77+
dead_tuple_percent,
78+
approx_free_space,
79+
approx_free_percent
80+
FROM public.pgstattuple_approx(relname)
81+
$$ LANGUAGE SQL VOLATILE SECURITY DEFINER;
82+
5883
CREATE ROLE monitoring WITH LOGIN PASSWORD 'mypassword'
5984
CONNECTION LIMIT 5 IN ROLE pg_monitor;
6085
ALTER ROLE monitoring SET search_path = monitoring, pg_catalog, public;
@@ -66,7 +91,7 @@ GRANT EXECUTE ON ALL FUNCTIONS IN SCHEMA monitoring TO monitoring;
6691

6792
Note that these statements must be run as a superuser (to create the SECURITY DEFINER function), but from here onwards you can use the `monitoring` user instead. The exporter will automatically use the helper methods if they exist in the `monitoring` schema, otherwise data will be fetched directly.
6893

69-
The default role `pg_monitor` was only added in PostgreSQL 10 (See more details [here](https://www.postgresql.org/docs/10/static/default-roles.html)). If you're running Postgres 9.6 or lower you need to create some other helper methods in the `monitoring` schema:
94+
The default role `pg_monitor` only has in PostgreSQL 10 or later (See more details [here](https://www.postgresql.org/docs/10/static/default-roles.html)). If you're running Postgres 9.6 or lower you need to create some other helper methods in the `monitoring` schema:
7095

7196
```sql
7297
CREATE OR REPLACE FUNCTION monitoring.pg_stat_activity() RETURNS SETOF pg_stat_activity AS $$

0 commit comments

Comments
 (0)