Gem

pgcli

pgcli is an interactive PostgreSQL shell with SQL completion and syntax highlighting.

Would you recommend pgcli?

No votes yet. Tried it? Be the first to say.

One vote per person. No account needed.

Overview

pgcli suggests database objects and SQL keywords as you type. Completion uses the statement context, so suggestions can include columns from a table you have already named. The client also supports connection aliases, configurable prompts and a row-count threshold prompt.

Instead of
Interactive psql sessions and desktop database browsers.
Reach for it when
Reach for it when exploring an unfamiliar PostgreSQL schema from a terminal.

Key features

  • Contextual SQL completion

    Suggests SQL keywords and database objects based on the statement being entered.

  • Query syntax highlighting

    Colours the SQL input as you type.

  • Named connection aliases

    Reads aliases defined in the client configuration.

  • Configurable result threshold

    Can prompt when results cross a configured row threshold.

  • Single connection mode

    Can use one database connection for querying and completion.

In depth

Install

The README uses Homebrew on macOS and also documents a Python package. Replace local_database with a database your local PostgreSQL connection can access.

bash
brew install pgcli
pgcli local_database

How it works

Start typing a query against a schema you know only partly. The client’s completion can suggest table names and then narrow column suggestions once there is enough context in the statement. Syntax highlighting and an editable prompt help when you are iterating on a query over several lines.

Connection aliases are handy when the same developer moves between several databases. A recognisable alias and prompt can make the current connection easier to spot. The client also exposes an option to use a single connection for sessions where the normal separate completion connection is inconvenient.

Good to know

  • The Python package for this release requires Python 3.10 or later.
  • The row threshold controls a client prompt. Query cost still depends on the SQL and the database.
  • The project targets interactive PostgreSQL work, including short investigations during development and support.

Repository README · v4.7.1 release · PyPI package metadata

Strengths and watch-outs

Strengths

  • Completion uses schema context
  • Runs entirely in a terminal
  • Easy to try on a local database

Watch out for

  • PostgreSQL-specific
  • Current Python package needs Python 3.10 or later
  • Completion can open a second connection by default

Try it in a few minutes

Terminal
brew install pgcli
pgcli local_database

Alternatives

psql

Ships with PostgreSQL and is widely used for scripted administration.

DBeaver

Offers a graphical schema browser and supports multiple database engines.

Related tools

Other tools that share topics with pgcli.

sqlite-utils

sqlite-utils.datasette.io
Gem

A Python library and CLI for building and querying SQLite databases from files or pipelines.

Instead of One-off CSV loaders and scratch database scripts.

llm (CLI)

llm.datasette.io
Gem

Use LLMs from the command line and pipe anything into them.

Instead of Copy-pasting terminal output into a chat window

Harlequin

harlequin.sh
Gem

A SQL IDE in your terminal for DuckDB, SQLite, Postgres, MySQL and more.

Instead of psql and the sqlite3 shell for exploring data, or opening a heavy GUI like DBeaver for a quick look