ALTER ROLE username WITH SUPERUSER;, run as an existing superuser. You almost certainly want one of the predefined roles instead. Superuser is not “admin” — it is “skip every permission check”, and it includes the ability to run arbitrary shell commands as the operating-system account PostgreSQL runs under. Three of the four requests that lead people here are solved by GRANT pg_read_all_data, GRANT pg_monitor, or GRANT pg_maintain, none of which give away the server.
Table of Contents
The case people reach for superuser to fix
A reporting or BI account needs to read every table, including tables that do not exist yet. Granting SELECT per table doesn’t hold, because tomorrow’s migration adds a table the grant doesn’t cover — so somebody makes it a superuser. Here is the failure:
hwtables=> SELECT count(*) FROM public.orders;
ERROR: permission denied for table orders
hwtables=> SELECT count(*) FROM app.sessions;
ERROR: permission denied for schema app
One statement fixes it, and it is not ALTER ROLE ... SUPERUSER:
hwtables=# GRANT pg_read_all_data TO hw_reporter;
GRANT ROLE
hwtables=> SELECT count(*) FROM public.orders;
count
-------
5000
hwtables=> SELECT count(*) FROM app.sessions;
count
-------
2000
It covers every schema, and it covers tables created after the grant — which is the whole reason per-table grants failed:
-- created as postgres, after the grant above
hwtables=> SELECT count(*) FROM public.invoices_new;
count
-------
3
And it stays read-only. The role still cannot write, cannot change server settings, and is not a superuser:
hwtables=> INSERT INTO public.invoices_new VALUES (4);
ERROR: permission denied for table invoices_new
hwtables=> SELECT current_setting('is_superuser');
off
hwtables=> ALTER SYSTEM SET work_mem='64MB';
ERROR: permission denied to set parameter "work_mem"
hwtables=> COPY (SELECT 1) TO PROGRAM 'cat';
ERROR: permission denied to COPY to or from an external program
DETAIL: Only roles with privileges of the "pg_execute_server_program" role may COPY to or from
an external program.
The other three, and what each is actually for
pg_monitor is the one for a metrics exporter or an on-call dashboard. Without it, a non-superuser sees pg_stat_activity rows for other roles but the query column is blank — which is why your monitoring shows connections and no queries. Same view, same moment, before and after the grant:
-- without pg_monitor
usename | state | query
-------------+--------+-----------------------------------------------
hw_reporter | active | SELECT usename, state, left(query,45) AS quer
(1 row)
-- after GRANT pg_monitor TO hw_reporter;
usename | state | query
-------------+--------+-----------------------------------------------
hw_reporter | active | SELECT usename, state, left(query,45) AS quer
postgres | active | SELECT pg_sleep(8), 'nightly_billing_rollup';
(2 rows)
More on reading that view in viewing active queries.
pg_maintain is the one for a cron job that vacuums or reindexes tables it does not own. This is worth seeing, because the failure without it is a warning, not an error — the job exits 0 and quietly does nothing:
hwtables=> VACUUM ANALYZE public.orders;
WARNING: permission denied to vacuum "orders", skipping it
VACUUM
hwtables=# GRANT pg_maintain TO hw_maint;
hwtables=> VACUUM ANALYZE public.orders;
VACUUM
hwtables=> REINDEX TABLE public.orders;
REINDEX
And it grants maintenance without granting data access, which is exactly the split you want for an automated job:
hwtables=> SELECT * FROM public.orders LIMIT 1;
ERROR: permission denied for table orders
pg_write_all_data completes the set — INSERT, UPDATE, DELETE on every table — and is the right grant for a restore or ETL account. It does not include SELECT; grant both if the job needs to read what it writes.
All fifteen predefined roles on this server:
SELECT rolname FROM pg_roles WHERE rolname LIKE 'pg\_%' ORDER BY 1;
pg_checkpoint pg_read_all_data pg_signal_backend
pg_create_subscription pg_read_all_settings pg_stat_scan_tables
pg_database_owner pg_read_all_stats pg_use_reserved_connections
pg_execute_server_program pg_read_server_files pg_write_all_data
pg_maintain pg_monitor pg_write_server_files
They arrived across several releases — pg_monitor in 10, pg_read_all_data and pg_write_all_data in 14, pg_maintain in 17. I only have 17.10 to test against, so treat those introduction versions as cited from the predefined roles documentation rather than measured; check SELECT rolname FROM pg_roles WHERE rolname LIKE 'pg\_%' on your own server, which is the only answer that matters.
If you still need superuser, this is the command
hwtables=# ALTER ROLE hw_su WITH SUPERUSER;
ALTER ROLE
hwtables=# SELECT rolname, rolsuper FROM pg_roles WHERE rolname='hw_su';
rolname | rolsuper
---------+----------
hw_su | t
ALTER USER is the same statement — USER and ROLE are synonyms here, not two separate methods. To reverse it: ALTER ROLE hw_su WITH NOSUPERUSER;. Only an existing superuser can run either. how-to-grant-superuser-privileges.sh promotes a role the way the ALTER ROLE example above does, then runs the COPY ... TO PROGRAM test and the row-level-security comparison below, all against a cluster it starts on port 55613 that holds none of your roles.
What you just handed over
Superuser includes pg_execute_server_program, which means shell access as the account the server runs as. Not a metaphor:
hwtables=# COPY (SELECT 1) TO PROGRAM 'id -un > /tmp/whoami.txt';
COPY 1
$ cat /tmp/whoami.txt
[user]
On a packaged Linux install that would print postgres — an account that owns the data directory, so anyone with superuser on the database can read, alter or delete the files of every database on the host, and read ~/.pgpass and any credentials the server user can reach. A compromised superuser login is a compromised host, not a compromised database.
Superuser also ignores row-level security, and it ignores it whether or not the role has BYPASSRLS — note rolbypassrls is f for this role. Same table, same policy, two roles:
-- hw_reporter (pg_read_all_data, not superuser): policy applies
tenant | secret
--------+--------------
a | alpha-secret
(1 row)
-- hw_su (superuser): policy bypassed
tenant | secret
--------+--------------
a | alpha-secret
b | beta-secret
(2 rows)
That is the strongest argument for the predefined roles: pg_read_all_data reads every table your policies allow, and superuser reads every table.
A checklist worth keeping
Audit who has it — SELECT rolname FROM pg_roles WHERE rolsuper; — and expect the list to be shorter than the number of people who think they need it. Give superuser roles NOLOGIN and reach them with SET ROLE from a normal account, so the powerful identity is never the one holding a password. Never point an application connection string at one. And if the request was “let this account create databases” or “let it create roles”, the attributes CREATEDB and CREATEROLE exist for precisely that, without the rest.
Verified 2026-08-10 on PostgreSQL 17.10 (Homebrew), aarch64-apple-darwin25.6.0. Every command and every error message above was executed on a throwaway cluster and pasted unedited except for one substitution: the account name returned by the COPY ... TO PROGRAM result is shown as [user] rather than the real login name. The point of that block — that the command runs as the database server’s OS user — is unaffected. Everything else is verbatim, including the COPY ... TO PROGRAM result and the RLS comparison. The only unmeasured claims on this page are the release numbers in which each predefined role was introduced, flagged above.