← PostgreSQL learning pathPostgreSQL · Module 9 of 10
Security and roles
Control access with roles, privileges and row-level security.
📖 Key ideas
- Roles act as users or groups: CREATE ROLE app LOGIN PASSWORD ...
- GRANT SELECT, INSERT ON orders TO app;
- Least privilege: apps should not use the superuser.
- Row-Level Security (RLS) restricts rows per user.
- Use parameterised queries to prevent SQL injection; enforce SSL connections.
💡 Real-life example: RLS is a hostel warden who lets each student open only their own room.
RoleUser or group in Postgres
GRANTGives privileges
RLSRow-Level Security
SuperuserRole with all powers