Troubleshooting¶
Common issues and solutions when using pg.
Connection Issues¶
Service Not Found¶
Solution: Check your~/.pg_service.conf file exists and contains the service: Connection Refused¶
Solutions:- Check PostgreSQL is running:
pg info ready -s production - Verify host/port in service file
- Check firewall settings
- Check pg_hba configuration
Comprehensive Connection Troubleshooting
For a complete visual guide to diagnosing PostgreSQL connection issues, see Can't Connect to PostgreSQL?
Authentication Failed¶
Solutions:- Set up or check
.pgpassfile for passwords - Use certificate authentication
- Check username in service file
Command Issues¶
Unknown Command¶
Solution: Usepg help to see available commands. Mixed Connection Methods¶
or Solution: Use only one connection method at a time:Argument Order¶
Commands fail silently or with unexpected errors.
Solution: Put connection options before tool options:
# ❌ Wrong order
pg dump db dump.sql -s production
# ✅ Correct order
pg dump db -s production dump.sql
Flag Conflicts¶
Problem: Using-c for commands when -c is reserved for connection strings. Solution: Use long form flags that conflict:
# ❌ Conflicts with connection string flag
pg query -s production -c "select version();"
# ✅ Use long form
pg query -s production --command "select version();"
Debugging¶
Enable Debug Logging¶
Test Commands Without Execution¶
pg dump db -s production --pg-dry-run -f dump.sql
# Ouput: Would execute: pg_dump -d 'service=production' -f dump.sql
Common Gotchas¶
File Permissions¶
If pg won't run:
PostgreSQL Tools Missing¶
Solution: Install PostgreSQL client tools:Service File Location¶
Service file not found on some systems.
Solution: Check these locations:
~/.pg_service.conf(user-specific)/etc/postgresql-common/pg_service.conf(system-wide on Debian/Ubuntu)
Getting Help¶
pg help- Show all commandspg <command> --help- Show command-specific helppg <command> <subcommand> --help- Show tool-specific helppg <command> --pg-verbose- Debug connection issuespg <command> --pg-dry-run- See what would be executed
Still having issues? Check the PostgreSQL documentation for underlying tool problems.