Skip to content

pg - PostgreSQL Lord of the Ring

pg Lord of the ring logo

One tool to rule them all - A unified interface for PostgreSQL client tools

Say goodbye to remembering different syntaxes for each PostgreSQL tool! pg provides one consistent command-line interface for psql, pg_dump, pg_restore, createdb, and more.

Quick Example

# Each tool has different syntax 😕
psql -d myapp -h server -U user
pg_dump -d myapp -h server -U user -f dump.sql
createdb myapp -h server -U user
# One consistent interface 🎉
pg query -s production
pg dump db -s production myapp -f dump.sql # or pg export db -s production myapp -f dump.sql
pg create db -s production myapp

Key Features

  • 🎯 Unified syntax for all PostgreSQL tools
  • 🔌 Service file support - the elegant way to connect
  • 📦 Zero dependencies - pure bash
  • 🛠️ Full compatibility - all original features preserved
  • 🚨 Clear distinction between logical dumps and physical backups

Common Commands

What you want to do Command
Connect to database pg query -s production mydb
Export database pg dump db -s production myapp backup.sql
Import database pg dump import -s production myapp backup.sql
Create database pg create db -s production newapp
Run maintenance pg maintain vacuum -s production mydb
Check server status pg info ready -s production

Next Steps

Why Service Files?

The examples above use -s production which refers to entries in ~/.pg_service.conf:

[production]
host=prod-db.company.com
port=5432
user=app_user
dbname=myapp
sslmode=require

This approach is:

  • Secure - No passwords on command line
  • Maintainable - Change connection details in one place
  • Clean - Simple, readable commands
  • Professional - How experienced PostgreSQL DBAs connect

Ready to simplify your PostgreSQL workflow? Let's get started!