Goal: build a role hierarchy and prove inherited versus explicit access.
Think of group roles as key rings and object grants as keys. The ring’s name grants nothing by itself. Connect as postgres to database postgres: -U is the SQL role and -d the database. Expect postgres=#. This lab gives only dba_admin a schema privilege; analyst and app_writer remain labels without new object grants.
Goal: inspect the real starting identities.
Read the six non-built-in roles: postgres, student, and the four dataset owners. !~ means “does not match this regular expression”; ^pg_ excludes names beginning pg_. t/f mean true/false. Only postgres should have rolsuper = t. Roles are cluster-wide: owning one dataset does not imply they cannot access another through other grants.
Goal: create privilege containers without login capability.
Create analyst, app_writer, and dba_admin with NOLOGIN. Expect three CREATE ROLE tags. The role names suggest jobs, but do not grant SELECT, DML, or schema rights. A NOLOGIN role can hold privileges and own objects; it cannot authenticate directly.
Goal: add an analyst login to its group.
Create Jane with the lesson-only password and INHERIT, then grant analyst membership. Expect CREATE ROLE and GRANT ROLE. The grant names another role, not a table. The password is stored, but the current trust HBA baseline does not test it; LOGIN and authentication policy are separate.
Goal: add a service login without assuming its name confers write access.
Create Mike and grant app_writer membership. Expect both command tags. This group has no DML grant in this lesson, so membership does not yet make Mike a writer. His later permissions could also include direct grants, ownership, or PUBLIC access.
Goal: add the login used for the inheritance experiment.
Create Sara with INHERIT, then grant dba_admin membership. Expect both tags. In PostgreSQL 19, new memberships take their default inherit option from the member’s INHERIT attribute; the membership’s SET option controls whether SET ROLE is allowed. We grant the actual schema privilege later.
Goal: read the three new membership edges and their options.
pg_auth_members stores IDs; two joins to pg_roles turn member and group IDs into names. Filtering to our three logins excludes unrelated built-in memberships. Expect Jane→analyst, Mike→app_writer, Sara→dba_admin, each with inherit_option = t and set_option = t. These options belong to each membership, not every role relationship universally.
Goal: prove an inherited schema grant works without changing identity.
Exit psql with \q, connect as postgres to beer_db, grant schema CREATE to dba_admin, then reconnect as Sara. Run each shell psql command only after exiting the prior client. CREATE TABLE incident_log must succeed without SET ROLE. serial creates an automatically numbered integer plus a sequence. Sara owns this new table because she remained the effective role.
Goal: prove the analyst login does not inherit schema CREATE.
Reconnect as Jane and attempt CREATE TABLE analyst_scratch. Expect permission denied for schema public; this is the intended result. No scratch table should be stored. A failed standalone statement leaves psql usable. This verifies this specific schema privilege, not every possible operation in the cluster.
Goal: show membership without automatic use of its object privileges.
As postgres create Tom with NOINHERIT, then make the new dba_admin grant. Reconnect as Tom and attempt CREATE TABLE noinherit_test: expect the same schema permission error. This grant defaults to INHERIT FALSE and SET TRUE. Changing a role’s INHERIT attribute later does not rewrite existing membership options.
Goal: observe effective identity and ownership during an explicit role switch.
Still as Tom, read session_user and current_user, run SET ROLE dba_admin, and read them again. Expect Tom/Tom, then Tom/dba_admin. CREATE must now succeed; the catalog join must show table owner dba_admin. ::regclass resolves the table name to its catalog ID. After RESET ROLE, both identity columns must be Tom again. Switching roles is observable in SQL; durable audit logging requires separate configuration.