Grant SELECT to postgres_exporter for certain tables
In gitlab-cookbooks/gitlab-exporters!198 (merged), we've added a query to have metrics for tracking the remaining capacity of int4 primary keys.
This effectively runs queries like the following:
SELECT 'events' as table_name, 'id' as column_name, max(id) as current_value, (select (2^(numeric_precision-1)-1) FROM information_schema.columns WHERE (table_name, column_name) = ('events', 'id')) as maximum_value FROM events
This has been added to postgres_exporter, which uses a dedicated postgres user postgres_exporter in production. Said user doesn't have any grants on GitLab-owned tables. Hence those queries fail momentarily, e.g. with the following:
INFO[0006] Error running query on database "127.0.0.1:5432": pg_integer_capacity pq: permission denied for table events source="postgres_exporter.go:1233"
Solutions
We grant read permissions to postgres_exporter, either on the entire public schema or on individual tables needed here.
There are a few variants for this:
ALTER GROUP gitlab ADD USER postgres_exporter;
-- or
GRANT SELECT ON events TO postgres_exporter; -- Same for other involved tables (6 overall)
Edited by Andreas Brandl