Why PostgreSQL Needs More Than Just "Open It"
Unlike a local SQLite file you double-click, PostgreSQL is a server process —
always running, always listening, always checking who's allowed in.
Every connection needs a destination and a role:
HOST — which machine runs the Postgres server
USER — which database role (account) you're authenticating as
DATABASE — which of the server's databases you want to land in
Omitted flags use environment variables or defaults. Explicit flags make your destination clear.
The psql Connection Flags
psql -h localhost -U student -d beer_db
-h host → the server's hostname or IP (default: PGHOST, or a local Unix socket when unset)
-U username → the role you want to connect as
-d database → which database to open (PGDATABASE overrides the role-name default)
Reading the Prompt
Once connected, the default prompt shows the database and session status:
postgres=# ← you are a superuser (# = superuser privilege)
mydb=> ← you are a regular user (> = normal role)
mydb=*# ← you're inside an open transaction (the * means "uncommitted")
The database name, the = sign, and the prompt character (#, >, !) are a live status bar.
You never need to guess where you are — the prompt tells you.
\conninfo: Your Session Receipt
After connecting, \conninfo prints connection details. This image displays a parameter/value table, including Database, Client User, Host, Server Port, and Superuser. Other versions may use a sentence:
You are connected to database "mydb" as user "student"
on host "localhost" (address "127.0.0.1") at port "5432".
It's the \conninfo answer to "wait, which database am I in?"
Did you know?
pg_isready can report that the server accepts connections even when the supplied role or database is invalid. It checks readiness; your successful psql login is a separate test. PostgreSQL documentation.
Key concepts
psql
The official PostgreSQL interactive terminal. Accepts SQL statements, returns results, and offers meta-commands (backslash commands like \dt, \l) for navigating the server without writing SQL.
Connection parameters
A connection selects a host, port, SQL role, and database. Flags override environment defaults; explicit choices make the destination reviewable.