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.
这个资产会安全暂存
这个资产会先安全暂存。复制的指令会要求 Agent 读取暂存文件,并在激活脚本、MCP 配置或全局配置前先确认。
npx -y tokrepo@latest install 44395a8b-38c4-11f1-9bc6-00163e2b0d79 --target codex先暂存文件;激活前需要读取暂存 README 和安装计划。
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.
常见问题
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.
引用来源 (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
讨论
相关资产
mycli — MySQL CLI with Auto-Completion and Syntax Highlighting
mycli is a Python-based interactive CLI for MySQL/MariaDB/Percona with smart auto-completion, syntax highlighting, and result formatting — sister project to pgcli.
Commander.js — The Complete Solution for Node.js CLI Programs
A Node.js library for building command-line interfaces with support for commands, options, arguments, and auto-generated help.
Typer — Build Python CLIs from Type Hints
Typer turns Python functions into CLI commands using only type hints. It is built on Click but removes the boilerplate — write a function, and Typer auto-generates parsing, help text, and shell completions.
GitHub CLI (gh) — GitHub Official Command Line Tool
GitHub CLI brings GitHub to your terminal. Create PRs, manage issues, review code, run Actions, browse releases — without leaving the command line. Written in Go and the official cross-platform tool from GitHub.