pgcli(1)
A command-line interface for PostgreSQL with auto-completion and syntax highlighting.
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
| Flag | What it does |
|---|---|
-h, --host HOST | PostgreSQL server host (default: localhost) |
-U, --username USER | PostgreSQL username (default: current system user) |
-p, --port PORT | PostgreSQL server port (default: 5432) |
-d, --database DBNAME | Database name to connect to |
-W, --password | Prompt for password before connecting |
-v, --version | Show pgcli version and exit |
-l, --list | List all available databases and exit |
--pgclirc FILE | Location of pgclirc config file |
-e, --execute QUERY | Execute query and exit (non-interactive mode) |
--no-auto-escape | Do not escape special characters in quoted identifiers |
Examples
Connect to the local 'mydb' database using current system user
pgcli mydbConnect to remote PostgreSQL server with custom host, user, and port
pgcli -h db.example.com -U admin -p 5433 productionConnect using a PostgreSQL connection URI
pgcli -d postgresql://user:pass@localhost:5432/mydbExecute a single query and exit without entering interactive mode
pgcli mydb -e "SELECT version();"List all available databases on the default PostgreSQL server
pgcli -lConnect to mydb and prompt for password before authenticating
pgcli -W mydbConnect using a custom configuration file location
pgcli --pgclirc ~/.config/pgclirc_prod mydb