🐘 PostgreSQL
Beginner
How do you connect to PostgreSQL using psql?
Answer
psql is the interactive terminal client for PostgreSQL. Connect with: psql -h hostname -p 5432 -U username -d dbname. If running locally as the postgres user: psql (connects to the default database). Key psql meta-commands: \l (list databases), \c dbname (connect to database), \dt (list tables), \d tablename (describe table), \dn (list schemas), \df (list functions), \du (list users/roles), \q (quit), \? (help for meta-commands), \h SELECT (SQL command help). The connection string format: postgresql://user:password@host:5432/dbname.