GRANT and REVOKE
Overview
GRANT assigns privileges; REVOKE removes a grant or membership. PostgreSQL privileges are additive across applicable roles and PUBLIC, so removing one grant may not eliminate effective access. Object ownership is distinct from an ordinary grant. Objective: inspect a small privilege matrix and model revocation safely.
First example
SELECT object,privilege FROM sec_grant WHERE role='reader' ORDER BY object,privilege;Observed SQLite result (rows in JSON):
[ [ "report", "SELECT" ]]How it works
Check database CONNECT, schema USAGE, object permissions and sequence or function permissions separately as applicable. SQLite has no native GRANT/REVOKE roles. Deleting a metadata row below illustrates removal only; no actual permissions change. The rollback restores the model.
Practical example
BEGIN;DELETE FROM sec_grant WHERE role='reader';SELECT COUNT(*) FROM sec_grant WHERE role='reader';ROLLBACK;Observed SQLite result (rows in JSON):
[ [ 0 ]]Practice and mistakes
Practice: list reader privileges before and after removal. Hint 1: filter by role. Hint 2: use a transaction and rollback. Check: report SELECT returns after rollback. Mistake: assuming REVOKE overrides a grant received through another role.
PostgreSQL 17 example — NOT RUN
SELECT table_schema,table_name,privilege_type FROM information_schema.role_table_grants WHERE grantee=current_user ORDER BY 1,2,3;Expected result, not executed: "Lists applicable view rows for current grantee; not a complete effective privilege audit."