Start using PostgreSQL
Switch PostgreSQL databases
Reconnect psql to another database and verify that the new connection uses the intended role.
A connection enters one database. There is no USE database that quietly changes context inside a session, the way MySQL does it. To move from postgres to notes_app, reconnect:
\connect notes_app
You are now connected to database "notes_app" as user "flavio".
\c is the short form of \connect, and you will see it in most documentation and tutorials.
You can also choose a role while switching:
\connect notes_app notes_app
The first argument is the database, the second is the role. This is how you test what your application role can actually see and do, without leaving your admin session behind for good.
It is a new connection, not a setting
Run \conninfo after switching. PostgreSQL opened a new connection; it did not change a database setting inside the old one.
That distinction has practical consequences. Session state does not travel across \connect. Anything you configured with SET, any open transaction, any temporary table: gone, because the session it lived in is gone. If you SET search_path and then switch databases, set it again.
When the switch fails
Point \connect at a database that does not exist and you get:
connection to server ... failed: FATAL: database "notes_ap" does not exist
Previous connection kept
Read the last line. psql keeps your previous connection alive, so you are still connected to the old database. People miss that line, assume the switch happened, and run their next statements against the wrong database. After any failed \connect, run \conninfo before typing anything else.
The other failure you will meet once you lock down permissions in the next module:
FATAL: permission denied for database "notes_app"
DETAIL: User does not have CONNECT privilege.
That one is not a typo. The database exists, but the role you chose is not allowed in. It means your grants are working; connect as a role that holds CONNECT on that database instead.
Make the habit boring: switch, then verify with \conninfo, then work.
Lesson completed