CREATE ROLE and CREATE USER are the same statement — CREATE USER just adds LOGIN. Group your privileges onto roles that cannot log in, grant those roles to the people and services that can, and use \du and \drg to see the result. If you are on PostgreSQL 16 or later, INHERIT is now a property of each grant, not of the role, and changing the role attribute no longer changes grants that already exist. That last point breaks a lot of copied-from-2019 scripts.
Table of Contents
CREATE ROLE vs CREATE USER
hwroles=# CREATE ROLE hw_r_plain;
CREATE ROLE
hwroles=# CREATE USER hw_u_plain;
CREATE ROLE
Both echo CREATE ROLE, because there is only one object type. The catalog shows the one difference:
hwroles=# SELECT rolname, rolcanlogin, rolinherit, rolcreatedb, rolsuper
hwroles-# FROM pg_roles WHERE rolname LIKE 'hw\_%\_plain' ORDER BY 1;
rolname | rolcanlogin | rolinherit | rolcreatedb | rolsuper
------------+-------------+------------+-------------+----------
hw_r_plain | f | t | f | f
hw_u_plain | t | t | f | f
And that difference is the whole story:
$ psql -U hw_r_plain -d hwroles
psql: error: connection to server ... failed:
FATAL: role "hw_r_plain" is not permitted to log in
$ psql -U hw_u_plain -d hwroles -c 'SELECT current_user'
hw_u_plain
Use CREATE ROLE for groups, CREATE USER for things that connect. Set passwords with \password rolename in psql rather than CREATE ROLE ... PASSWORD 'literal': the literal form ends up in ~/.psql_history, and if log_statement is on it ends up in the server log in cleartext too.
Inheritance, and the role that has a privilege but cannot use it
Two login roles, both members of the same group, one created NOINHERIT:
CREATE ROLE hw_analysts;
GRANT SELECT ON public.ledger TO hw_analysts;
CREATE ROLE hw_alice LOGIN; -- INHERIT is the default
CREATE ROLE hw_bob LOGIN NOINHERIT;
GRANT hw_analysts TO hw_alice;
GRANT hw_analysts TO hw_bob;
-- alice
hwroles=> SELECT count(*) FROM public.ledger;
count
-------
2
-- bob: identical membership
hwroles=> SELECT count(*) FROM public.ledger;
ERROR: permission denied for table ledger
Bob is not missing the privilege; he is not using it. SET ROLE switches him into the group for the rest of the session:
hwroles=> SET ROLE hw_analysts;
SET
hwroles=> SELECT current_user, session_user;
current_user | session_user
--------------+--------------
hw_analysts | hw_bob
hwroles=> SELECT count(*) FROM public.ledger;
count
-------
2
session_user stays as the role that authenticated, which is what audit logging and pg_stat_activity report. RESET ROLE switches back. NOINHERIT plus SET ROLE is the right shape for an administrative account: the elevated privilege is a deliberate act you can see in the logs, not something every stray statement runs with. Run on PostgreSQL 16 or later, user-roles-management-guide.sh replays this page’s role and grant statements against a temporary cluster of its own and removes it on exit; on older servers it skips the grant-option checks.
The PostgreSQL 16 change: INHERIT belongs to the grant now
\du no longer carries a “Member of” column. Memberships moved to \drg, which shows two things that did not exist before 16 — an Options column and a Grantor:
hwroles=# \drg
List of role grants
Role name | Member of | Options | Grantor
-------------+------------------+--------------+----------
hw_alice | hw_analysts | INHERIT, SET | postgres
hw_bob | hw_analysts | SET | postgres
Alice’s membership carries INHERIT; Bob’s does not. The options were fixed at GRANT time from each role’s rolinherit attribute, and they are frozen there. Here is the trap that catches scripts written before 16 — flipping the attribute does nothing to the grant:
hwroles=# ALTER ROLE hw_bob INHERIT;
ALTER ROLE
hwroles=# SELECT rolname, rolinherit FROM pg_roles WHERE rolname='hw_bob';
rolname | rolinherit
---------+------------
hw_bob | t
hwroles=# \drg hw_bob
Role name | Member of | Options | Grantor
-----------+-------------+---------+----------
hw_bob | hw_analysts | SET | postgres
-- as bob, still:
hwroles=> SELECT count(*) FROM public.ledger;
ERROR: permission denied for table ledger
The role says it inherits. The grant says it does not. The grant wins. Re-issue it with the option spelled out and the privilege appears:
hwroles=# GRANT hw_analysts TO hw_bob WITH INHERIT TRUE;
GRANT ROLE
hwroles=# \drg hw_bob
Role name | Member of | Options | Grantor
-----------+-------------+--------------+----------
hw_bob | hw_analysts | INHERIT, SET | postgres
The flip side is a combination that was impossible before 16: inherit the privileges but never be able to become the role. Useful when you want an application to read what the group can read, without letting it assume the group’s identity and create objects owned by it:
hwroles=# GRANT hw_analysts TO hw_carol WITH INHERIT TRUE, SET FALSE;
GRANT ROLE
hwroles=> SELECT count(*) FROM public.ledger;
count
-------
2
hwroles=> SET ROLE hw_analysts;
ERROR: permission denied to set role "hw_analysts"
WITH ADMIN OPTION: delegate membership, not role creation
A team lead who is merely a member of a group cannot add anyone to it:
hwroles=> GRANT hw_analysts TO hw_newhire;
ERROR: permission denied to grant role "hw_analysts"
DETAIL: Only roles with the ADMIN option on role "hw_analysts" may grant this role.
Give them the admin option and they can — and the Grantor column records who did it:
hwroles=# GRANT hw_analysts TO hw_lead WITH ADMIN OPTION;
-- now, as hw_lead
hwroles=> GRANT hw_analysts TO hw_newhire;
GRANT ROLE
hwroles=# \drg hw_newhire
Role name | Member of | Options | Grantor
------------+-------------+--------------+---------
hw_newhire | hw_analysts | INHERIT, SET | hw_lead
This is the privilege you want for delegating onboarding, and it is much narrower than CREATEROLE — the lead still cannot mint roles at all:
hwroles=> CREATE ROLE hw_sneaky LOGIN SUPERUSER;
ERROR: permission denied to create role
DETAIL: Only roles with the CREATEROLE attribute may create roles.
Dropping a role that owns things
hwroles=# DROP ROLE hw_alice;
ERROR: role "hw_alice" cannot be dropped because some objects depend on it
DETAIL: owner of table ledger
The order is: REASSIGN OWNED BY hw_alice TO some_other_role; then DROP OWNED BY hw_alice; (which removes the remaining privileges granted to her) then DROP ROLE hw_alice;. Both of the first two are per-database, so on a cluster with several databases you run them in each one. pg_shdepend tells you where the dependencies are.
A layout that holds up
One nologin role per capability (app_read, app_write, app_migrate), not per team — teams change, capabilities don’t. Grant the capability roles to login roles. Pair every grant with ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT SELECT ON TABLES TO app_read; so tomorrow’s tables are covered; a plain GRANT SELECT ON ALL TABLES only covers the tables that exist right now, which is the single most common reason a permission “randomly stops working” after a deployment. And where a role’s job is genuinely “read everything”, the built-in predefined roles like pg_read_all_data beat maintaining your own.
Verified 2026-08-10 on PostgreSQL 17.10 (Homebrew), aarch64-apple-darwin25.6.0. Every statement, every error message and both \du and \drg outputs above were executed on a throwaway cluster and pasted unedited. The claims about which release introduced the grant-level INHERIT/SET options are attributed to PostgreSQL 16 from the GRANT documentation; I have only 17.10 here, so I could not run the pre-16 comparison.