Commands.app

psql

Connection

PostgreSQL interactive terminal

Options & Flags
Available options for this command
-h

Specify database server host

-p

Specify database server port

-U

Connect as specified database user

-d

Specify database name to connect to

-c

Execute a single command and exit

-f

Execute commands from a file

Examples
Common usage examples

Connect as postgres user

psql -U postgres

Connect to specific database on localhost

psql -h localhost -U myuser -d mydb

Execute single query and exit

psql -c 'SELECT version();'

Run SQL script on database

psql -f script.sql mydb
Notes
  • Use \q to quit psql
  • Use \? for help on psql commands
Related Commands
You might also find these useful