Goal: Prove that LOGIN, database CONNECT, table SELECT, and CREATEDB are separate permissions by testing both success and denial.
Connect explicitly as postgres for this administrative exercise; the default student role cannot create roles. Run \du to see every role on the server and their attributes. Find postgres and notice the "Superuser" flag in its attributes.
Create dev_user with LOGIN, NOSUPERUSER, NOCREATEDB, and NOCREATEROLE. LOGIN permits authentication; it does not grant access to every database or table. Expect CREATE ROLE.
Run \du dev_user. An empty attributes column means no special flags are displayed, not that LOGIN is absent. Also query pg_roles to verify LOGIN is t and the other three attributes are f. t/f are PostgreSQL boolean output, and the WHERE filter selects this role.
Revoke CONNECT on beer_db from PUBLIC, which represents all SQL roles. This removes the inherited public grant so the next test can fail predictably. Explicit grants to dataset owners and student are separate; the change lasts only in this lesson. Expect REVOKE.
Try \c beer_db dev_user. Expect permission denied for database "beer_db" and Previous connection kept. A failed interactive reconnect keeps your original postgres connection, so you can issue the next GRANT there.
In the retained postgres session, grant only CONNECT on beer_db to dev_user. Expect GRANT. This opens the database door; it does not grant SELECT on its tables.
Reconnect as dev_user after the CONNECT privilege has been granted. This time the connection should succeed.
Now that dev_user can connect to beer_db, check what that access actually includes. You can list table names with \dt because PostgreSQL exposes table metadata separately from table data, but reading rows still requires an explicit SELECT grant on the table itself.
While still connected as dev_user, try CREATE DATABASE test_db;. Expect permission denied to create database. This tests the NOCREATEDB attribute; successful CONNECT to an existing database does not confer database creation rights.