$linuxjunkies
>

pgcli(1)

A command-line interface for PostgreSQL with auto-completion and syntax highlighting.

UbuntuDebianFedoraArch

Synopsis

pgcli [OPTIONS] [DBNAME] [USERNAME] [HOSTNAME] [PORT]

Description

pgcli is an interactive terminal UI for PostgreSQL that provides a modern alternative to psql. It features intelligent auto-completion for table names, column names, SQL keywords, and database objects; syntax highlighting; and query history with better formatting.

Connect to a database using connection parameters as arguments, via a connection string with the -d flag, or through environment variables (PGDATABASE, PGUSER, PGHOST, PGPORT). Once connected, execute SQL queries interactively and explore your schema with built-in commands.

Common options

FlagWhat it does
-h, --host HOSTPostgreSQL server host (default: localhost)
-U, --username USERPostgreSQL username (default: current system user)
-p, --port PORTPostgreSQL server port (default: 5432)
-d, --database DBNAMEDatabase name to connect to
-W, --passwordPrompt for password before connecting
-v, --versionShow pgcli version and exit
-l, --listList all available databases and exit
--pgclirc FILELocation of pgclirc config file
-e, --execute QUERYExecute query and exit (non-interactive mode)
--no-auto-escapeDo not escape special characters in quoted identifiers

Examples

Connect to the local 'mydb' database using current system user

pgcli mydb

Connect to remote PostgreSQL server with custom host, user, and port

pgcli -h db.example.com -U admin -p 5433 production

Connect using a PostgreSQL connection URI

pgcli -d postgresql://user:pass@localhost:5432/mydb

Execute a single query and exit without entering interactive mode

pgcli mydb -e "SELECT version();"

List all available databases on the default PostgreSQL server

pgcli -l

Connect to mydb and prompt for password before authenticating

pgcli -W mydb

Connect using a custom configuration file location

pgcli --pgclirc ~/.config/pgclirc_prod mydb

Related commands