PostgreSQL Manager
Manages the shared PostgreSQL Docker container for local dev environments.
Architecture
postgres-manager/
├── docker-compose.yml # PostgreSQL 16 Alpine container
└── run.sh # lifecycle + db admin CLI
Joins the shared nginx-proxy_net network (created by proxy-manager) so app containers connect via hostname codai_postgres. Data is persisted in a named volume.
Commands
./run.sh start # start PostgreSQL container
./run.sh stop # stop container (data persists in volume)
./run.sh status # status + list databases
./run.sh wait # block until PostgreSQL is ready
./run.sh create-db <name> # CREATE DATABASE (idempotent)
./run.sh drop-db <name> # DROP DATABASE (interactive confirm)
./run.sh dump <src> <dest> # pg_dump src | psql dest
./run.sh list-dbs # list all non-template databases
./run.sh psql [<db>] # open psql interactive session
How to Execute Tasks
Start PostgreSQL for the first time
cd postgres-manager && ./run.sh start
On first run, Docker creates the volume and initializes codai_main.
Create a database for a new instance
./run.sh create-db codai_feature
Snapshot main database into a new instance
./run.sh dump codai_main codai_feature
Remove a worktree database
./run.sh drop-db codai_feature # prompts for confirmation
Open interactive psql
./run.sh psql # connects to codai_main
./run.sh psql codai_feature # connects to specific db
Startup Order
proxy-manager start— creates the shared Docker networkpostgres-manager start— joins the shared networkworktree-manager start <instance>
Configuration
| Variable | Default | Purpose |
|---|---|---|
POSTGRES_CONTAINER |
codai_postgres |
Container name |
POSTGRES_USER |
codai |
Database user |
POSTGRES_PASSWORD |
pgpass |
Database password |
POSTGRES_MAIN_DB |
codai_main |
Primary database name |
POSTGRES_PORT |
5433 |
Host port (maps to 5432) |
CODAI_NETWORK |
nginx-proxy_net |
Shared Docker network name |
App Connection
Backend containers connect to PostgreSQL at:
- Host:
codai_postgres(container name on shared network) - Port:
5432 - User:
codai/ Password:pgpass - DB:
codai_main(or instance-specific db)
Rules
- Never drop
POSTGRES_MAIN_DB— it is the source of truth for snapshots. drop-dbalways prompts for confirmation.- Database names are validated against
^[a-z][a-z0-9_]{0,62}$before any SQL or shell operation. stoppreserves data in the Docker volume. Usedocker compose down -vonly when you intentionally want to delete persisted data.- The container uses
restart: unless-stopped— it will resume after a Docker daemon restart. Run./run.sh stopwhen done. - The host port (
POSTGRES_PORT) is bound to127.0.0.1only. Set a non-defaultPOSTGRES_PASSWORDon shared machines. - Network is
external: true— proxy-manager must start first.
Related Plugins
proxy-manager— creates the shared Docker network (start first)mysql-manager— MySQL alternativeredis-manager— in-memory cache companionworktree-manager— app instances that consume PostgreSQL
