Currently viewing the human version
Switch to AI version

Why pgcli Exists (And When It Breaks)

pgcli auto-completion in action

So you've heard pgcli makes psql bearable, but what does that actually mean? Let's be specific about where PostgreSQL's default client falls apart and where pgcli actually delivers.

psql's tab completion is garbage. Type SELECT * FROM u and it suggests every command in your PATH instead of your user table. pgcli actually shows you table names like a sane person would expect.

Tab Completion That Actually Works

When you type SELECT * FROM and hit tab, pgcli shows your tables. When you type WHERE user_id = it shows columns from the users table. This is how completion should work, and somehow PostgreSQL's psql still hasn't figured this out after decades.

The catch? Schema indexing takes forever on databases with 500+ tables. First startup can take 30 seconds while it reads your entire schema. After that it's fast, until your database schema changes and it has to rebuild everything.

Auto-completion gets confused with complex JOINs and subqueries. Type something like SELECT u.name FROM users u JOIN orders o ON u.id = o.user_id WHERE and completion just gives up. Falls back to suggesting every column in your database.

Tables You Can Actually Read

psql output looks like ASCII vomit. pgcli formats results in actual tables with borders and proper alignment. No more counting spaces to figure out which value belongs to which column. It uses tabulate for table formatting and click for CLI styling.

The downside? Memory usage grows with result set size. Query returning 50k rows? pgcli eats 200MB of RAM formatting tables. psql just streams the output and uses 5MB. This is a known limitation of Python-based CLI tools vs native C programs.

Schema Awareness (Until It's Not)

Database Connection Diagram

pgcli connects to your database and reads system catalogs to know about tables, columns, functions. Works great for development where you're constantly forgetting column names. The approach is similar to what SQL completion tools like DataGrip use.

Breaks on production databases where connection pooling interferes with schema queries. Also chokes on massive schemas - try using it on a database with 2000+ tables and watch it freeze for minutes.

Reality check: pgcli has 12k GitHub stars because it solves psql's most annoying problems. Just don't expect it to handle enterprise-scale databases gracefully. For comparison, mycli and litecli face similar scaling issues.

What's New in v4.3.0

The March 2025 release brought some improvements worth knowing about:

  • Better Python 3.12+ compatibility - fewer dependency conflicts during installation
  • Improved psycopg 3.x support - the newer PostgreSQL adapter, though psycopg2 still works fine
  • Smarter schema caching - reduces startup time by 20-30% on databases with complex schemas
  • Memory optimizations - still uses more than psql, but won't balloon as aggressively on large result sets

Still no fix for the fundamental scaling issues - 1000+ table schemas will still make it crawl. But for typical development databases (50-200 tables), it's noticeably snappier than previous versions.

pgcli vs Reality Check on PostgreSQL Tools

Feature

pgcli

psql

DBeaver

pgAdmin

Interface Type

Terminal (actual useful)

Terminal (spartan)

GUI (bloated)

Web (why?)

Auto-completion

✅ Works like you'd expect

❌ Suggests random garbage

✅ Good until IntelliJ spoils you

❌ Basic textarea bullshit

Syntax Highlighting

✅ Colors that make sense

❌ Welcome to 1985

✅ Full IDE experience

❌ Syntax highlighting is hard apparently

Table Formatting

✅ Actually readable

❌ ASCII art from hell

✅ Pretty but slow as shit

✅ Takes 5 seconds to render 10 rows

Installation

pip install pgcli (pray to Python gods)

Ships with PostgreSQL

Download 500MB installer

Download then debug for 2 hours

Memory Usage

Low (until big schemas)

Minimal (5MB)

Medium (200MB minimum)

High (eats all your RAM)

Startup Time

Fast (slow on first schema load)

Instant

Medium (forever on Windows)

Slow (loading dashboard queries)

Large Schemas

❌ Chokes on 1000+ tables

✅ Doesn't give a fuck

✅ Handles everything

❌ Crashes with "memory exceeded"

Production Use

❌ Interactive only

✅ Scripts don't break

❌ GUI on servers? Really?

❌ Web interface on prod? No.

SSH Tunneling

Manual (copy your psql setup)

Manual (works everywhere)

✅ Built-in (when it works)

✅ Built-in (breaks randomly)

When It Breaks

Python dependency hell

Never (it's C)

Java runtime bullshit

Everything (it's JavaScript)

Best For

Development queries

Production scripts

Multiple databases

Postgresql administration (masochists)

Installation: Pray to the Python Gods

Python Logo

Ready to try pgcli after seeing what it can do? Here's the reality of getting it running on your machine.

pgcli installation usually works fine until it doesn't. When it breaks, you'll spend 2 hours fighting Python dependencies and libpq-dev hell. The issues are similar to other psycopg2-based tools, but pgcli v4.3.0 (March 2025) has improved compatibility with Python 3.12+.

The Easy Way (That Sometimes Works)

Copy this and hope for the best:

pip install pgcli

Works great until you hit Python 3.12 compatibility issues or the dreaded psycopg2 dependency hell. If it installs cleanly, you're lucky. If not, welcome to dependency nightmare land.

macOS users: Skip pip, use Homebrew instead:

brew install pgcli

Homebrew handles the libpq dependency and PostgreSQL client libraries. Way less likely to break than pip on macOS. Still takes forever to compile everything from source, similar to other PostgreSQL tools.

Ubuntu/Debian: System packages save you from compilation hell:

sudo apt-get install pgcli

Usually works but often gives you an ancient version. Check pgcli --version - if it's older than 3.x, you're missing features. The Debian package tracker shows current versions.

When pip install Fails (Spoiler: It Will)

Error: psycopg2 build fails
This is the big one. You need PostgreSQL development headers:

## Ubuntu/Debian
sudo apt-get install python3-dev libpq-dev

## macOS with Homebrew
brew install postgresql

## Then try again
pip install pgcli

Error: ERROR: No matching distribution found for python-dev
Windows WSL issues. You need the Windows PostgreSQL binaries in your PATH. Download PostgreSQL for Windows, add C:\Program Files\PostgreSQL\15\bin to PATH.

Error: ImportError: No module named '_ctypes'
Your Python is fucked. Reinstall Python or use pyenv. This usually happens with system Python on CentOS/RHEL.

Error: ModuleNotFoundError: No module named 'setuptools_scm'
Missing build tools. Install with pip install setuptools-scm wheel then retry. This started showing up more with Python 3.12+.

Error: Failed building wheel for psycopg2
Classic. Either install psycopg2-binary instead (pip install psycopg2-binary pgcli) or fix your build environment. The binary version works fine for development but some security-conscious environments block it.

Nuclear Option: Docker

Docker Logo

When all else fails, use Docker to avoid the dependency hell:

docker run --rm -it dpage/pgcli pgcli postgresql://user:pass@host/db

Slower startup but guaranteed to work. Good for CI environments where you can't fight with system dependencies. Similar to other Docker-based database tools.

Configuration (The Part That Actually Works)

First run creates ~/.config/pgcli/config. Most important settings:

## Make it less chatty
less_chatty = True

## Vi mode if you're not a savage
vi = True

## Don't log sensitive queries
log_file = 

## Multi-line mode is actually useful
multi_line = True

Config rarely breaks. It's the only reliable part of pgcli.

Connection Reality Check

pgcli uses the same connection logic as psql. Your existing PostgreSQL environment variables work:

export PGHOST=localhost
export PGDATABASE=myapp
export PGUSER=dev
pgcli  # connects automatically

Production gotcha: Don't use pgcli for production automation. It's slower than psql and does extra queries for schema awareness. Use psql for scripts that matter.

Questions You Actually Have

Q

Why doesn't pgcli just work like psql?

A

Because psql's tab completion is garbage and its output looks like ASCII vomit. pgcli shows table names when you type FROM instead of suggesting every binary in your PATH. The trade-off is slower startup and higher memory usage.

Q

Does pgcli break on large databases?

A

Yeah. Schema indexing chokes on 1000+ tables and can take minutes to load. Memory usage grows with result set size

  • query 50k rows and watch it eat 200MB of RAM. psql handles this fine because it just streams output.
Q

Can I use pgcli for production scripts?

A

Don't. pgcli is slower than psql and does extra schema queries on startup. Use psql for automation, cron jobs, and anything that matters. pgcli is for interactive development where you want nice formatting and completion.

Q

Why does installation keep failing?

A

Python dependency hell. You need libpq-dev, python3-dev, and the right psycopg2 version. macOS users should use Homebrew. Windows users need PostgreSQL binaries in PATH. When all else fails, use Docker.

Q

How do I fix "psycopg2 build failed"?

A

Install PostgreSQL development headers:

## Ubuntu/Debian
sudo apt-get install python3-dev libpq-dev

## macOS
brew install postgresql

Then pip install pgcli again. This error means your system can't compile the PostgreSQL adapter.

Q

Why is pgcli slow on first startup?

A

It's reading your entire database schema to build completion indexes. Takes 30 seconds on databases with 500+ tables. After that it's fast until your schema changes. You can disable this with --no-refresher but then completion sucks.

Q

Does pgcli work with connection pooling?

A

Not great. Connection poolers interfere with schema queries. pgcli expects direct database access to read system catalogs. Works fine with application-level pooling but struggles with pgbouncer in transaction mode.

Q

Can I connect to multiple databases?

A

One database per pgcli session, just like psql. Want multiple connections? Open multiple terminals. There's no tabbed interface or connection manager

  • it's a command-line tool, not a GUI.
Q

Why does completion stop working?

A

Complex queries confuse the parser. Type something like SELECT u.name FROM (SELECT * FROM users WHERE created_at > '2024-01-01') u and completion gives up. Falls back to suggesting every column in your database.

Q

Should I use pgcli for everything?

A

Fuck no. Use pgcli for development queries where you want nice formatting and completion. Use psql for scripts, production automation, and large result sets. Use a GUI tool for schema browsing and complex data exploration.

Related Tools & Recommendations

howto
Recommended

How to Migrate PostgreSQL 15 to 16 Without Destroying Your Weekend

integrates with PostgreSQL

PostgreSQL
/howto/migrate-postgresql-15-to-16-production/migrate-postgresql-15-to-16-production
66%
alternatives
Recommended

Why I Finally Dumped Cassandra After 5 Years of 3AM Hell

integrates with MongoDB

MongoDB
/alternatives/mongodb-postgresql-cassandra/cassandra-operational-nightmare
66%
compare
Recommended

MongoDB vs PostgreSQL vs MySQL: Which One Won't Ruin Your Weekend

integrates with postgresql

postgresql
/compare/mongodb/postgresql/mysql/performance-benchmarks-2025
66%
tool
Recommended

DBeaver Performance Optimization - Stop Waiting 30 Seconds for Your Database to Load

Real-world fixes for the most annoying DBeaver performance issues - from startup time that makes you question life choices to memory leaks that crash your lapto

DBeaver Community
/tool/dbeaver/performance-optimization
60%
tool
Recommended

DBeaver Community - If You Work With Databases and Don't Want to Pay for DataGrip

Java-based database client that connects to basically anything with a JDBC driver - from MySQL to MongoDB to whatever the hell Oracle is calling their stuff thi

DBeaver Community
/tool/dbeaver/overview
60%
tool
Recommended

DataGrip - Database IDE That Doesn't Completely Suck

Cross-platform database tool that actually works with multiple databases from one interface

DataGrip
/tool/datagrip/overview
60%
news
Popular choice

Anthropic Raises $13B at $183B Valuation: AI Bubble Peak or Actual Revenue?

Another AI funding round that makes no sense - $183 billion for a chatbot company that burns through investor money faster than AWS bills in a misconfigured k8s

/news/2025-09-02/anthropic-funding-surge
60%
tool
Recommended

MyCLI - Terminal MySQL Client with Auto-completion and Syntax Highlighting

Finally, a MySQL client that works with you instead of against you.

MyCLI
/tool/mycli/overview
59%
tool
Recommended

LiteCLI - SQLite CLI That Doesn't Suck

similar to LiteCLI

LiteCLI
/tool/litecli/overview
59%
news
Popular choice

Docker Desktop Hit by Critical Container Escape Vulnerability

CVE-2025-9074 exposes host systems to complete compromise through API misconfiguration

Technology News Aggregation
/news/2025-08-25/docker-cve-2025-9074
57%
tool
Popular choice

Yarn Package Manager - npm's Faster Cousin

Explore Yarn Package Manager's origins, its advantages over npm, and the practical realities of using features like Plug'n'Play. Understand common issues and be

Yarn
/tool/yarn/overview
55%
tool
Recommended

pgAdmin - The GUI You Get With PostgreSQL

It's what you use when you don't want to remember psql commands

pgAdmin
/tool/pgadmin/overview
54%
alternatives
Popular choice

PostgreSQL Alternatives: Escape Your Production Nightmare

When the "World's Most Advanced Open Source Database" Becomes Your Worst Enemy

PostgreSQL
/alternatives/postgresql/pain-point-solutions
52%
tool
Popular choice

AWS RDS Blue/Green Deployments - Zero-Downtime Database Updates

Explore Amazon RDS Blue/Green Deployments for zero-downtime database updates. Learn how it works, deployment steps, and answers to common FAQs about switchover

AWS RDS Blue/Green Deployments
/tool/aws-rds-blue-green-deployments/overview
47%
tool
Recommended

Python 3.13 Production Deployment - What Actually Breaks

Python 3.13 will probably break something in your production environment. Here's how to minimize the damage.

Python 3.13
/tool/python-3.13/production-deployment
45%
howto
Recommended

Python 3.13 Finally Lets You Ditch the GIL - Here's How to Install It

Fair Warning: This is Experimental as Hell and Your Favorite Packages Probably Don't Work Yet

Python 3.13
/howto/setup-python-free-threaded-mode/setup-guide
45%
troubleshoot
Recommended

Python Performance Disasters - What Actually Works When Everything's On Fire

Your Code is Slow, Users Are Pissed, and You're Getting Paged at 3AM

Python
/troubleshoot/python-performance-optimization/performance-bottlenecks-diagnosis
45%
tool
Recommended

psycopg2 - The PostgreSQL Adapter Everyone Actually Uses

The PostgreSQL adapter that actually works. Been around forever, boring as hell, does the job.

psycopg2
/tool/psycopg2/overview
45%
news
Popular choice

Three Stories That Pissed Me Off Today

Explore the latest tech news: You.com's funding surge, Tesla's robotaxi advancements, and the surprising quiet launch of Instagram's iPad app. Get your daily te

OpenAI/ChatGPT
/news/2025-09-05/tech-news-roundup
40%
tool
Popular choice

Aider - Terminal AI That Actually Works

Explore Aider, the terminal-based AI coding assistant. Learn what it does, how to install it, and get answers to common questions about API keys and costs.

Aider
/tool/aider/overview
40%

Recommendations combine user behavior, content similarity, research intelligence, and SEO optimization