pgcli — PostgreSQL CLI with Auto-Completion and Syntax Highlighting
pgcli is a modern `psql` replacement in Python with intelligent auto-completion for tables/columns/functions, syntax highlighting, multi-line editing, and output formatting.
What it is
pgcli is a Python-based interactive command-line interface for PostgreSQL that serves as a modern replacement for psql. It adds intelligent auto-completion for table names, column names, SQL keywords, and functions, plus syntax highlighting, multi-line editing, and formatted output.
The tool targets database administrators, backend developers, and data engineers who work with PostgreSQL from the terminal and want a more productive CLI experience.
How it saves time or tokens
pgcli eliminates the constant context-switching of checking table schemas before writing queries. Auto-completion surfaces column names as you type, reducing typos and the need to run \d table_name repeatedly. Syntax highlighting catches errors visually before execution.
How to use
- Install pgcli:
pip install pgcliorbrew install pgcli. - Connect to your database:
pgcli -h localhost -U postgres -d mydb. - Start typing SQL -- auto-completion and highlighting activate automatically.
Example
# Install
pip install pgcli
# Connect to a local database
pgcli -h localhost -U postgres -d mydb
# Inside pgcli, auto-completion works as you type:
# SELECT u -> suggests: users, updates, uuid_generate_v4()
# SELECT * FROM users WHERE -> suggests column names: id, name, email
# Useful pgcli-specific commands:
# \f - toggle formatted output
# \x - expanded display
# \dt - list tables
# F2 - toggle multi-line mode
Related on TokRepo
- AI Tools for Database -- database tools and utilities for developers
- Automation Tools -- tools that speed up repetitive development tasks
Common pitfalls
- pgcli's auto-completion queries the database schema on startup. For databases with thousands of tables, this can cause a slow initial connection. Use
--no-auto-completefor large schemas. - pgcli stores command history in
~/.config/pgcli/history. Be careful with sensitive queries in shared environments. - Some psql backslash commands behave slightly differently in pgcli. Check
\?inside pgcli for the exact supported set.
Frequently Asked Questions
pgcli adds smart auto-completion, syntax highlighting, and multi-line editing on top of psql's functionality. psql is the official PostgreSQL client with complete feature coverage. pgcli is a drop-in replacement for interactive use but defers to psql for scripting.
Yes. pgcli passes connection parameters through to the underlying psycopg library, which supports SSL. Use the same SSL flags or connection strings you would use with psql.
Yes. pgcli supports all standard PostgreSQL connection methods: host/port/user flags, connection URIs, and .pgpass files. It works with local, remote, and cloud-hosted PostgreSQL instances.
Yes. pgcli connects to any PostgreSQL-compatible database, including Amazon RDS, Aurora, Google Cloud SQL, Azure Database for PostgreSQL, and Supabase.
pgcli is a read/write client just like psql. It does not add any safety layer. Use the same caution you would with psql -- avoid running unreviewed queries on production databases.
Citations (3)
- pgcli GitHub— pgcli is a Python-based PostgreSQL CLI with auto-completion
- pgcli Official Site— Smart completion for tables, columns, and functions
- dbcli Project— Part of the dbcli family of database CLIs
Related on TokRepo
Discussion
Related Assets
HumHub — Open-Source Enterprise Social Network
A flexible, open-source social networking platform built on Yii2 for creating private communities, intranets, and collaboration spaces within organizations.
Dolibarr — Open-Source ERP & CRM for Business Management
A modular open-source ERP and CRM application written in PHP for managing contacts, invoices, orders, inventory, accounting, and more from a single web interface.
PrestaShop — Open-Source PHP E-Commerce Platform
A widely adopted open-source e-commerce platform written in PHP with a rich module marketplace, multi-language support, and a strong European user base.