📡 You're offline — showing cached content
New version available!
Quick Access
Tutorials PostgreSQL Essentials Connecting with psql

Connecting with psql

5 min read
psql is PostgreSQL's interactive terminal for running SQL. Use \l to list databases, \c dbname to connect, \dt to list tables, and \d tablename to describe a table. It is the most efficient way to manage databases.

Connecting to PostgreSQL

psql -U postgres          -- connect as superuser
psql -U postgres -d mydb  -- connect to specific DB
\l                        -- list databases
\c mydb                   -- switch database
\dt                       -- list tables
\q                        -- quit

You can also connect with a connection string:

psql "postgresql://user:pass@localhost:5432/mydb"