LinuxCommandLibrary

pgcli

TLDR

Connect to database

$ pgcli [database]
copy
Connect with user and host
$ pgcli -h [hostname] -u [user] [database]
copy
Connect with URL
$ pgcli postgresql://[user]:[password]@[host]/[database]
copy
Connect via socket
$ pgcli -h /var/run/postgresql [database]
copy
Run single query
$ pgcli -c "[SELECT * FROM table]" [database]
copy
Execute file
$ pgcli [database] < [script.sql]
copy
List databases
$ pgcli --list
copy

SYNOPSIS

pgcli [-h host] [-p port] [-u user] [-c command] [options] [database]

DESCRIPTION

pgcli is an enhanced PostgreSQL client with auto-completion and syntax highlighting. It provides a more user-friendly experience than psql.
Auto-completion suggests table names, column names, SQL keywords, and function names as you type. Context-aware suggestions understand joins, subqueries, and complex expressions.
Syntax highlighting makes queries more readable. Errors in SQL are visible before execution.
Multi-line editing supports complex queries. History search finds previous commands. Output can be saved to files.
The interface responds to psql backslash commands (\d, \dt, \l, etc.) for compatibility. Additional commands are available for pgcli-specific features.
Configuration controls colors, key bindings, and behavior. The pgclirc file customizes the environment.

PARAMETERS

-h HOST, --host HOST

Database server host.
-p PORT, --port PORT
Database port.
-u USER, --user USER
Username.
-W, --password
Prompt for password.
-d DB, --dbname DB
Database name.
-c CMD
Execute command and exit.
--list
List databases.
--auto-vertical-output
Automatic vertical display for wide output.
--row-limit N
Limit displayed rows.
-l, --log-file FILE
Log to file.
--pgclirc FILE
Config file path.
--version
Show version.

CAVEATS

Requires Python. Some psql features not implemented. Large result sets may be slow to display.

HISTORY

pgcli was created by Amjith Ramanujam around 2014, inspired by mycli for MySQL. It brought modern CLI features to PostgreSQL, emphasizing usability improvements over the basic psql client.

SEE ALSO

psql(1), mycli(1), litecli(1), pg_dump(1)

Copied to clipboard