← PostgreSQL learning path
PostgreSQL · Module 9 of 10

Security and roles

Control access with roles, privileges and row-level security.

📖 Key ideas

  1. Roles act as users or groups: CREATE ROLE app LOGIN PASSWORD ...
  2. GRANT SELECT, INSERT ON orders TO app;
  3. Least privilege: apps should not use the superuser.
  4. Row-Level Security (RLS) restricts rows per user.
  5. 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