Goal: close a supplied PUBLIC exposure and verify creator-scoped read-only defaults.
The setup created separate analytics.customer_ltv data, deliberately granted PUBLIC schema and table access, and created Jane plus analyst membership. Baked beer data is unchanged. Connect as postgres to beer_db using -U for SQL role and -d for database; expect beer_db=#. PUBLIC means every role, not the schema named public.
Goal: read the table ACL rather than guessing what ALL means.
\dp analytics.customer_ltv is a psql display command. In grantee=privileges/grantor, an empty grantee before = means PUBLIC and /postgres names the grantor. Codes a/r/w/d/D/x/t/m mean INSERT/SELECT/UPDATE/DELETE/TRUNCATE/REFERENCES/TRIGGER/MAINTAIN. Expect a postgres owner entry and a PUBLIC entry. This lists table rights, not schema rights.
Goal: inspect the two privilege layers independently.
First inspect Jane’s effective schema USAGE and CREATE: both should be t. Then list PUBLIC table grants with information_schema.table_privileges: expect seven SQL-standard privilege rows. MAINTAIN is visible in the ACL but not a separate row in this view. role_table_grants is filtered to enabled grantors/grantees and is not a general PUBLIC exposure inventory. Schema ALL alone does not grant table SELECT or DML.
Goal: remove the schema gate while showing the table grant still exists.
Revoke schema ALL from PUBLIC, then compare Jane’s two privileges. Expect REVOKE, schema_usage = f, but table_select = t. Schema USAGE and table SELECT are independent requirements: revoking one does not erase the other. This deliberately intermediate state explains why the next revoke is still needed.
Goal: remove the separate PUBLIC table grant.
Revoke ALL on customer_ltv, then repeat the comparison. Expect both booleans f: the PUBLIC grant is gone from each layer. The owner still retains rights; revoking PUBLIC does not remove every role’s direct or inherited grants. No server reload is needed for these catalog changes.
Goal: give analyst the two keys required for reading.
Grant schema USAGE, then SELECT on all currently existing analytics tables. Expect two GRANT tags. USAGE lets the role resolve schema objects; SELECT permits their reads. Neither grants INSERT or schema CREATE. ALL TABLES IN SCHEMA covers existing tables only, which is why we configure defaults next.
Goal: define defaults for future tables created specifically by postgres.
FOR ROLE postgres names the object creator and IN SCHEMA analytics the location. Expect ALTER DEFAULT PRIVILEGES. It does not modify customer_ltv or apply automatically to tables another role creates. Because we are connected as postgres, the explicit FOR ROLE makes that scope visible rather than relying on an implicit default.
Goal: create a future table and inspect its automatic grant.
Create churn_risk as postgres and insert the one demonstration row (1, 0.50). Expect CREATE TABLE, INSERT 0 1, and analyst=r/postgres in \dp: r means SELECT. No table GRANT is run after creation; the ACL is evidence the configured default applied. The INSERT is just sample data to make the next read concrete.
Goal: prove inherited access works on the newly created row.
Exit with \q, then run the shell psql command as Jane to beer_db. Query churn_risk: expect customer_id 1 and risk_score 0.50, with no permission error. Jane’s access comes from analyst membership; the ACL names analyst rather than an individual Jane grant.
Goal: prove the same inherited permission still excludes writes.
Still as Jane, attempt an INSERT. Expect permission denied for table churn_risk; the existing demonstration row must remain the only row. This tests the configured table boundary, not a claim that every object in every schema is read-only.