AI-powered database client and MCP server for desktop and web, supporting Postgres, MySQL, MariaDB, SQL Server, ClickHouse and SQLite.
dbcli/pgcli
A Postgres command-line client with auto-completion and syntax highlighting, an alternative to the stock psql shell.
Open-source alternative to:psql
- Stars
- 13,422
- Forks
- 613
- Open issues
- 53
- Last commit
- 9 days ago
What is it?
pgcli is an interactive command-line client for PostgreSQL. It suggests SQL keywords, table names and column names as you type, and highlights syntax in the query prompt, which makes writing and exploring queries in a terminal faster than with the plain psql shell.
Completion is context-aware by default. After FROM it offers only table names, and after WHERE it offers column names. Results are pretty-printed as tables, and the tool supports common psql backslash commands alongside its own options. Connections can be made with a database name or a full postgresql:// URL, and it honors standard PG* environment variables and SSL settings.
The project is built on prompt_toolkit and Pygments and is installed as a Python package via pip, pipx or uvx, with Homebrew and Debian/Ubuntu packages also available. It can also be run in Docker or launched inside an IPython session through the ipython-sql magic.
Key features
- 01Auto-completes SQL keywords, tables and columns as you type.
- 02Context-sensitive completion, such as only tables after FROM.
- 03Syntax highlighting for queries in the terminal.
- 04Pretty-prints tabular query results.
- 05Supports common psql backslash commands and standard PG* environment variables.
- 06Configurable via a config file created at ~/.config/pgcli/config.
Use cases
- Writing and debugging SQL queries against a Postgres database from the terminal.
- Exploring an unfamiliar schema by browsing table and column names through completion.
- Connecting to Postgres over SSL or via DSN aliases in a daily workflow.
- Running pgcli inside IPython to keep query results in a Python session.
Quick start
- 1
Install pgcli with pip
pip install -U pgcli - 2
Connect to a database by name
pgcli [database_name]
Things to know
- Requires a local Postgres installation when installed via pip.
- Some Linux and macOS install paths depend on distribution or Homebrew packages.
In collections
Topics
FAQ
- What is pgcli?
- A Postgres command-line client with auto-completion and syntax highlighting, an alternative to the stock psql shell. pgcli is an interactive command-line client for PostgreSQL. It suggests SQL keywords, table names and column names as you type, and highlights syntax in the query prompt, which makes writing and exploring queries in a terminal faster than with the plain psql shell.
- Is pgcli free to use? What license does it have?
- pgcli is open source under the BSD-3-Clause license. Check the license terms before using it in commercial products.
- Is pgcli still maintained?
- Actively maintained. The last commit to pgcli was on Oct 15, 2026.
- What can I use pgcli for?
- Writing and debugging SQL queries against a Postgres database from the terminal. Exploring an unfamiliar schema by browsing table and column names through completion. Connecting to Postgres over SSL or via DSN aliases in a daily workflow. Running pgcli inside IPython to keep query results in a Python session.
- How do I install pgcli?
- Install pgcli with pip: pip install -U pgcli Connect to a database by name: pgcli [database_name]
- Where can I get pgcli?
- The source code and installation instructions are on GitHub: https://github.com/dbcli/pgcli
Summary generated by AI from the project's README. GitHub stats refresh daily.
Related projects
A keyboard-driven terminal UI for connecting to and querying many SQL databases, inspired by lazygit.
Free multi-platform desktop SQL client and database tool supporting 100+ databases via JDBC and ODBC drivers.
TypeScript ORM for Node.js that gives type-safe database access across PostgreSQL, MySQL, SQLite, MongoDB and other databases.
A free, local-first, AI-assisted database client and SQL workspace supporting 40+ databases across desktop, web, Docker and CLI.
Lightweight cross-platform database client for 100+ databases, with desktop, Docker, CLI, a built-in AI SQL assistant and an MCP server.