7. First connection and setup
You met psql in 5.1. Open it again as postgres.
On suta-linux-lab-1, as student:
# Switch to the postgres user (type exit to come back)sudo su - postgresNow as postgres on suta-linux-lab-1:
# Open an interactive psql session as the postgres rolepsql7.1 Set a password, create a role and a database
Section titled “7.1 Set a password, create a role and a database”Still in psql as postgres on suta-linux-lab-1.
-- Set a password for the postgres role (you type it twice; nothing shows on screen)\password postgres-- Create a login role for an application, with a passwordCREATE ROLE appuser WITH LOGIN PASSWORD 'Change-Me-2026';-- Create a database owned by that roleCREATE DATABASE appdb OWNER appuser;- Pick your own password instead of
Change-Me-2026, and write it down. You need it in 7.2. LOGINlets the role connect.OWNER appusermakes appuser the owner of the new database.
Expected output for the last two:
CREATE ROLECREATE DATABASECheck your work:
-- List roles\duExpected output:
List of roles Role name | Attributes-----------+------------------------------------------------------------ appuser | postgres | Superuser, Create role, Create DB, Replication, Bypass RLSLeave psql, then leave the postgres user:
-- Quit psql\q# Return to the student userexitWas this page helpful?
Thanks. Glad it helped.
Thanks for telling us. Email the instructor what was missing, or ask in class.