gitmyhub

pgcli

Python ★ 13k updated 18d ago

Postgres CLI with autocompletion and syntax highlighting

A smarter PostgreSQL command-line client with auto-complete for table and column names, syntax highlighting, and an optional safety prompt before running destructive queries.

PythonPostgreSQLsetup: easycomplexity 2/5

pgcli is a command-line tool for connecting to and querying a PostgreSQL database. PostgreSQL (often called Postgres) is a popular open-source database used by many web apps and services. pgcli replaces the built-in command-line tool that comes with Postgres, adding features that make it much nicer to use day to day.

The main thing pgcli adds is auto-completion: as you type a SQL query, it suggests keywords, table names, and column names from your actual database. If you type "SELECT * FROM" and press Tab, it will show you the tables available in that database. If you then start typing a WHERE clause, it will suggest column names for the table you already picked. This context-aware completion saves time and reduces typos.

It also highlights SQL syntax with colors, making it easier to read what you have typed. Results are formatted into clean tables in the terminal output. There is also a warning option that prompts you before running queries that could delete or overwrite data, which is useful if you work directly on production databases.

Installation is straightforward. On macOS you can install it with Homebrew in one command. On Linux many distributions package it directly, and it is also available via pip (the standard Python package installer) or tools like pipx and uvx. It can also be run inside a Docker container if you want to try it without installing anything on your machine.

Once installed, you connect by typing pgcli followed by your database name or a full connection URL. A configuration file is created automatically on first launch where you can adjust prompts, row limits, and other preferences. The project is open source and actively maintained, with instructions for contributors in the repository.

Where it fits