You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Nov 28, 2022. It is now read-only.
Copy file name to clipboardExpand all lines: README.md
+26-1Lines changed: 26 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -55,6 +55,31 @@ CREATE OR REPLACE FUNCTION monitoring.pgstattuple(IN relname text,
55
55
FROM public.pgstattuple(relname)
56
56
$$ LANGUAGE SQL VOLATILE SECURITY DEFINER;
57
57
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
+
58
83
CREATE ROLE monitoring WITH LOGIN PASSWORD 'mypassword'
59
84
CONNECTION LIMIT 5 IN ROLE pg_monitor;
60
85
ALTER ROLE monitoring SET search_path = monitoring, pg_catalog, public;
@@ -66,7 +91,7 @@ GRANT EXECUTE ON ALL FUNCTIONS IN SCHEMA monitoring TO monitoring;
66
91
67
92
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.
68
93
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:
70
95
71
96
```sql
72
97
CREATE OR REPLACEFUNCTIONmonitoring.pg_stat_activity() RETURNS SETOF pg_stat_activity AS $$
0 commit comments