LinuxCommandLibrary

psql

TLDR

Connect to database

$ psql -d [database]
copy
Connect to remote server
$ psql -h [host] -U [user] -d [database]
copy
Execute SQL command
$ psql -c "SELECT * FROM [table]" [database]
copy
Execute SQL file
$ psql -f [script.sql] [database]
copy
List databases
$ psql -l
copy
Interactive mode
$ psql [database]
copy

SYNOPSIS

psql [options] [dbname]

DESCRIPTION

psql is PostgreSQL interactive terminal. Database client.
The tool executes SQL queries. Manages PostgreSQL databases.
psql queries PostgreSQL.

PARAMETERS

DBNAME

Database name.
-h HOST
Server hostname.
-p PORT
Port number.
-U USER
Username.
-d DBNAME
Database name.
-c COMMAND
Execute command.
-f FILE
Execute file.
-l
List databases.

CAVEATS

PostgreSQL specific. Requires server connection.

HISTORY

psql is the official PostgreSQL command-line client.

SEE ALSO

pg_dump(1), createdb(1), mysql(1)

Copied to clipboard