PostgreSQL
Users & Roles Commands
PostgreSQL uses a role-based access control system. Learn to create users, assign roles, GRANT/REVOKE permissions, and set up read-only access for secure database management.
28 commands
Pro Tips
Use ALTER DEFAULT PRIVILEGES to auto-grant permissions on future tables, not just existing ones.
Create group roles (NOLOGIN) like 'readonly' or 'readwrite', then grant them to user roles for cleaner permission management.
Always GRANT USAGE ON SCHEMA before table-level grants, or users won't see the tables.
Common Mistakes
Cannot drop a user that owns objects. Use REASSIGN OWNED BY first, then DROP OWNED BY, then DROP USER.
Avoid granting SUPERUSER in production. Use specific privileges instead for least-privilege access.