Skip to content

Commit d929077

Browse files
Fixed grant on all tables to a separate view
1 parent 99cff13 commit d929077

File tree

3 files changed

+27
-4
lines changed

3 files changed

+27
-4
lines changed

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,17 @@ grant pg_monitor to postgres_ai_mon;
1919
grant select on pg_stat_statements to postgres_ai_mon;
2020
grant select on pg_stat_database to postgres_ai_mon;
2121
grant select on pg_stat_user_tables to postgres_ai_mon;
22+
23+
-- Create a public view for pg_statistic access for bloat metrics
24+
CREATE VIEW public.pg_statistic AS
25+
SELECT pg_statistic.stawidth,
26+
pg_statistic.stanullfrac,
27+
pg_statistic.starelid,
28+
pg_statistic.staattnum
29+
FROM pg_statistic;
30+
31+
GRANT SELECT ON public.pg_statistic TO pg_monitor;
32+
ALTER USER postgres_ai_mon set search_path = "$user", public, pg_catalog;
2233
```
2334

2435
**One command setup:**

config/pgwatch-prometheus/metrics.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2183,8 +2183,8 @@ presets:
21832183
pg_stat_activity_autovacuum: 5
21842184
pg_stat_activity_autovacuum_active: 5
21852185
pg_gin_index: 5
2186-
pg_table_bloat: 86400
2187-
pg_btree_bloat: 86400
2186+
pg_table_bloat: 60
2187+
pg_btree_bloat: 60
21882188
pg_invalid_indexes: 60
21892189
redundant_indexes: 60
21902190
unused_indexes: 60

config/target-db/init.sql

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,24 @@ INSERT INTO sample_data (name) VALUES
1919
CREATE USER monitor WITH PASSWORD 'monitor_pass';
2020
GRANT CONNECT ON DATABASE target_database TO monitor;
2121
GRANT USAGE ON SCHEMA public TO monitor;
22-
GRANT SELECT ON ALL TABLES IN SCHEMA public TO monitor;
23-
GRANT SELECT ON ALL SEQUENCES IN SCHEMA public TO monitor;
22+
23+
-- Create a public view for pg_statistic access
24+
CREATE VIEW public.pg_statistic AS
25+
SELECT pg_statistic.stawidth,
26+
pg_statistic.stanullfrac,
27+
pg_statistic.starelid,
28+
pg_statistic.staattnum
29+
FROM pg_statistic;
30+
31+
-- Grant specific access instead of all tables
32+
GRANT SELECT ON public.pg_statistic TO pg_monitor;
2433

2534
-- Grant access to monitoring views
2635
GRANT SELECT ON pg_stat_statements TO monitor;
2736
GRANT SELECT ON pg_stat_database TO monitor;
2837
GRANT SELECT ON pg_stat_user_tables TO monitor;
2938
-- Grant pg_monitor role to monitor user for enhanced monitoring capabilities
3039
GRANT pg_monitor TO monitor;
40+
41+
-- Set search path for the monitor user
42+
ALTER USER monitor SET search_path = "$user", public, pg_catalog;

0 commit comments

Comments
 (0)