Skip to content
Download all

You met psql in 5.1. Open it again as postgres.

On suta-linux-lab-1, as student:

suta-linux-lab-1 - as student
# Switch to the postgres user (type exit to come back)
sudo su - postgres

Now as postgres on suta-linux-lab-1:

suta-linux-lab-1 - as postgres
# Open an interactive psql session as the postgres role
psql

7.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.

psql - as postgres
-- Set a password for the postgres role (you type it twice; nothing shows on screen)
\password postgres
psql - as postgres
-- Create a login role for an application, with a password
CREATE ROLE appuser WITH LOGIN PASSWORD 'Change-Me-2026';
psql - as postgres
-- Create a database owned by that role
CREATE DATABASE appdb OWNER appuser;
  • Pick your own password instead of Change-Me-2026, and write it down. You need it in 7.2.
  • LOGIN lets the role connect. OWNER appuser makes appuser the owner of the new database.

Expected output for the last two:

CREATE ROLE
CREATE DATABASE

Check your work:

psql - as postgres
-- List roles
\du

Expected output:

List of roles
Role name | Attributes
-----------+------------------------------------------------------------
appuser |
postgres | Superuser, Create role, Create DB, Replication, Bypass RLS

Leave psql, then leave the postgres user:

psql - as postgres
-- Quit psql
\q
suta-linux-lab-1 - as postgres
# Return to the student user
exit

Was this page helpful?

Thanks. Glad it helped.

Thanks for telling us. Email the instructor what was missing, or ask in class.