This is the multi-page printable view of this section. .
Quick Start
Get pgcli up and running in minutes.
Installation
Install pgcli with a single command:
This script will:
- Download the latest pgcli binary for your platform
- Install it to
/usr/local/bin(or~/.local/binif no sudo) - Add pgcli to your PATH
Initialize Configuration
This creates ~/.pgcli/pg.yaml with sensible defaults including:
- A default instance named
default - Data directory at
~/pg/default - Auto-assigned ports starting from 35432
The --backup-dir flag is optional but recommended for production: it puts
backup data and logs on a separate path from instance data, so a data-disk
failure does not cascade into backup loss.
Start Instance
The output shows the connection URL, admin password, and backup status.
Connect to Your Database
Basic Operations
Multi-Instance
Multiple Config Files (Isolation)
For isolated testing environments or one config per project on the same host,
generate a separate config file per environment with a distinct --namespace
and disjoint port ranges.
| Parameter | Default | Meaning |
|---|---|---|
--namespace |
default |
Container name prefix: pgcli-pg-<namespace>-<instance> |
--base-dir |
~/.pgcli |
Base directory for all data paths |
--backup-dir |
(under --base-dir) |
Separate base directory for backup data/log |
--pg-start-port |
35432 |
First PG host port; instances get sequential ports |
--pg-ssh-port |
42201 |
First SSH host port; sequential from here |
Planning tips:
- Always pass an explicit
--namespaceto avoid container name clashes. - Port ranges must not overlap between configs on one host.
- The namespace is baked into container names at creation time. Changing it later requires
pg destroyand re-init.
Interactive psql Session
Inside the interactive psql shell you get:
- SQL queries with history and tab completion
- psql meta-commands (
\dt,\du,\l, etc.) \qto quit
Container Shell
The shell runs as root inside the container, giving full access to:
- PostgreSQL data directory (
/var/lib/postgresql/data) - Configuration files
- Log files (
/var/log/postgresql/) - All system tools and utilities
Next Steps
- Learn about backup and restore
- Set up replication for high availability
- Explore extensions management
- Configure auto-start on boot for production deployments
- Understand administration