PostgreSQL 17.12Lab-verified · 2026-11-30

PostgreSQL 0LP01: role is a member of role

The GRANT would make a loop in role membership, because the target role is already a member of the granted role.

PostgreSQL 17.12
0LP01: role "app_write" is a member of role "app_read"

Jump to a cause

  1. 01Granting a role back in the reverse direction
  2. 02An indirect cycle through several roles

Lab-verifiedReproduced and fixed on PostgreSQL 17.12 · 2026-11-30 · container image postgres:17

SQLSTATE 0LP01 (invalid_grant_operation) appears on GRANT role TO role when the grant would create a cycle. The message role "A" is a member of role "B" says that A already belongs to B, directly or through other roles, so B cannot also become a member of A.

We reproduced a direct reverse grant and an indirect cycle through three roles on PostgreSQL 17. In both, the existing membership already did what was needed.

01Granting a role back in the reverse direction

app_read was already granted to app_write (writers can read). GRANT app_write TO app_read would close the loop, so PostgreSQL refused it.

Setup
Setuprun as postgres
CREATE ROLE app_read;
CREATE ROLE app_write;
GRANT app_read TO app_write;
OUTPUT
CREATE ROLE
CREATE ROLE
GRANT ROLE
Setuprun as lab_a
CREATE TABLE orders (id int PRIMARY KEY, amount int);
INSERT INTO orders VALUES (1, 12000);
GRANT USAGE ON SCHEMA lab_a TO app_read;
GRANT SELECT ON orders TO app_read;
GRANT INSERT ON orders TO app_write;
OUTPUT
CREATE TABLE
INSERT 0 1
GRANT
GRANT
GRANT
Reproducerun as postgres
GRANT app_write TO app_read;
✕ ERROR
ERROR:  0LP01: role "app_write" is a member of role "app_read"
Check the causerun as postgres
SELECT r.rolname AS role, m.rolname AS member
FROM pg_auth_members a
JOIN pg_roles r ON r.oid = a.roleid
JOIN pg_roles m ON m.oid = a.member
WHERE r.rolname LIKE 'app\_%';
OUTPUT
   role   |  member
----------+-----------
 app_read | app_write
(1 row)

pg_auth_members shows role app_read with member app_write.

Fixrun as postgres
GRANT app_write TO lab_b;
OUTPUT
GRANT ROLE

Keep one direction. Granting app_write to the user lab_b was enough: lab_b could INSERT into lab_a.orders (from app_write) and SELECT it (from app_read through app_write).

After the fixrun as lab_b
INSERT INTO lab_a.orders VALUES (2, 8000);
SELECT * FROM lab_a.orders ORDER BY id;
✓ SUCCESS
INSERT 0 1
 id | amount
----+--------
  1 |  12000
  2 |   8000
(2 rows)

02An indirect cycle through several roles

The chain was sales_read → sales_write → sales_admin. GRANT sales_admin TO sales_read failed with role "sales_admin" is a member of role "sales_read": sales_admin is already in sales_read through sales_write, even though no direct grant exists.

Setup
Setuprun as postgres
CREATE ROLE sales_read;
CREATE ROLE sales_write;
CREATE ROLE sales_admin;
GRANT sales_read TO sales_write;
GRANT sales_write TO sales_admin;
OUTPUT
CREATE ROLE
CREATE ROLE
CREATE ROLE
GRANT ROLE
GRANT ROLE
Setuprun as lab_a
CREATE TABLE sales (id int PRIMARY KEY, amount int);
INSERT INTO sales VALUES (1, 5000);
GRANT USAGE ON SCHEMA lab_a TO sales_read;
GRANT SELECT ON sales TO sales_read;
OUTPUT
CREATE TABLE
INSERT 0 1
GRANT
GRANT
Reproducerun as postgres
GRANT sales_admin TO sales_read;
✕ ERROR
ERROR:  0LP01: role "sales_admin" is a member of role "sales_read"
Check the causerun as postgres
SELECT pg_has_role('sales_admin', 'sales_read', 'MEMBER') AS admin_has_read,
       pg_has_role('sales_read', 'sales_admin', 'MEMBER') AS read_has_admin;
OUTPUT
 admin_has_read | read_has_admin
----------------+----------------
 t              | f
(1 row)

pg_has_role('sales_admin', 'sales_read', 'MEMBER') is t and the reverse is f.

Fixrun as postgres
GRANT sales_admin TO lab_b;
OUTPUT
GRANT ROLE

No reverse grant was needed. After GRANT sales_admin TO lab_b, lab_b could read lab_a.sales, a privilege given only to sales_read.

After the fixrun as lab_b
SELECT * FROM lab_a.sales;
✓ SUCCESS
 id | amount
----+--------
  1 |   5000
(1 row)

FAQ

What does "role A is a member of role B" mean on GRANT?

A is already inside B, directly or through other roles. Our GRANT tried to put B inside A, which would make a loop, so it failed with 0LP01.

How do I check role membership, including indirect?

pg_has_role('member_role', 'group_role', 'MEMBER') counts indirect membership. Direct grants are in pg_auth_members.

How do I give a user both read and write roles?

Grant the higher role to the user. In our test GRANT app_write TO lab_b gave both INSERT and SELECT, because app_write already contained app_read.

How we verify

Each scenario starts from fresh database users. A script runs the setup, confirms the exact error code, applies the fix and runs the statement again. The output shown is what the database printed, saved by the script.

lab_a and lab_b are ordinary roles created for the test, each owning a schema of the same name; postgres is the superuser. PostgreSQL 17.12