MOO WebTech
Database Securitylessonadvanced

Data Control Language (DCL)

GRANT, REVOKE, roles, and schema-level permission management in PostgreSQL.

80 minL48

Overview

This lesson covers PostgreSQL's access control system. Students learn to create roles, grant and revoke privileges on databases, schemas, and tables, and implement a least-privilege model. Real-world scenarios are used to motivate the concepts.

Lesson Plan

TimeActivity
0–10 minIntro: why access control matters, PostgreSQL security model
10–30 minCREATE ROLE / CREATE USER, GRANT on database and schema
30–50 minGRANT on tables: SELECT, INSERT, UPDATE, DELETE
50–65 minREVOKE, role inheritance, and GRANT OPTION
65–75 minGuided demo: set up read-only analyst and read-write developer roles
75–80 minWrap-up

Key Concepts

  • CREATE ROLE name and CREATE USER name WITH PASSWORD '...'
  • GRANT privilege ON object TO role
  • REVOKE privilege ON object FROM role
  • Role inheritance: GRANT child_role TO parent_role
  • GRANT ALL vs individual privilege grants
  • Principle of least privilege: grant only what is needed

✏️Practice

Short in-class exercises:

  1. Create a readonly_user role and grant SELECT on all tables in a schema.
  2. Revoke INSERT privilege from a user on a specific table.
  3. Grant a role to another role and verify the effective permissions.