Tooling · Postgres

Local Postgres in one command

Every new project needs a database, and installing Postgres by hand on each machine gets old fast. PgQuick is a small Docker Compose setup that gives you PostgreSQL plus pgAdmin, wired together, with one command.

6 min read

  • postgres
  • docker
  • pgadmin
  • dev setup
github.com/waux-team/PgQuick

Why bother

A native Postgres install works until it doesn't: two projects want different major versions, a brew upgrade breaks the data directory, or a teammate's setup drifts from yours. Running the database in a container fixes all three. The version is pinned in a file, the data lives in a named volume, and everyone on the team starts from the same config.

PgQuick is that config, and nothing else. The whole repo is four files:

  • docker-compose.yaml — the Postgres and pgAdmin services
  • .env.example — credentials and the database name
  • .gitignore — keeps your real .env out of git
  • README.md — the two ways to start it

What you get

ServiceImageReach it at
Postgrespostgres:15-alpinelocalhost:5432
pgAdmindpage/pgadmin4:8http://localhost:8080

Both ports are bound to 127.0.0.1, so the database is reachable from your machine only, not from anyone else on the same Wi-Fi.

Quick start

You need Docker with the Compose plugin (Docker Desktop, OrbStack or Colima all work).

1. Clone the repo

bash
git clone https://github.com/waux-team/PgQuick.git
cd PgQuick

2. Create your .env

bash
cp .env.example .env

Then open .env and change the passwords and the database name:

bash
DATABASE_URL="postgres://admin:strong_password_here@localhost:5432/project_db_name?schema=public"

POSTGRES_USER=admin
POSTGRES_PASSWORD=strong_password_here
POSTGRES_DB=project_db_name
PGADMIN_EMAIL=admin@admin.com
PGADMIN_PASSWORD=strong_password_here

Keep DATABASE_URL in step with the three POSTGRES_* values. It isn't used by Compose; it's there so you can paste it straight into your app's own .env. The ?schema=public suffix is the form Prisma expects.

3. Start it

bash
docker compose up -d

4. Check it's healthy

bash
docker compose ps

postgres_db should show healthy. pgAdmin waits for that before it starts, so give it a few seconds on the first run.

Inside the compose file

The file is short, but a few lines are doing more than they look.

A real health check

yaml
healthcheck:
test: ["CMD-SHELL", "pg_isready -U $${POSTGRES_USER} -d $${POSTGRES_DB}"]
interval: 10s
timeout: 5s
retries: 5
start_period: 10s

pg_isready asks Postgres whether it is accepting connections. The doubled $$ stops Compose from substituting the variable itself, so the shell inside the container expands it instead. pgAdmin then uses that result:

yaml
depends_on:
db:
condition: service_healthy

Without the condition, Compose would only wait for the container to start, not for the database to be ready.

Guard rails

yaml
deploy:
resources:
limits:
memory: 1G
logging:
driver: json-file
options:
max-size: "10m"
max-file: "3"

The memory cap keeps a runaway query from eating your laptop. The log rotation keeps Docker's logs at 30 MB per service at most, instead of growing until the disk fills up.

Data that survives restarts

yaml
volumes:
postgres_data:
pgadmin_data:

Named volumes outlive the containers. docker compose down and up again, and your tables and saved pgAdmin servers are still there.

Connecting

From pgAdmin

Open http://localhost:8080 and sign in with PGADMIN_EMAIL and PGADMIN_PASSWORD. Then register a server:

  • Host: db
  • Port: 5432
  • Username / password: your POSTGRES_USER and POSTGRES_PASSWORD

Use db, not localhost. pgAdmin runs in its own container, where localhost means pgAdmin itself. Both services share the pg-network bridge, so the service name db (or the container name postgres_db) resolves to the database.

From your app

Your app runs on the host, so it uses localhost. Copy DATABASE_URL into the app's .env:

bash
DATABASE_URL="postgres://admin:strong_password_here@localhost:5432/project_db_name?schema=public"

From a terminal

No local psql needed. Use the one inside the container:

bash
docker exec -it postgres_db psql -U admin -d project_db_name

The manual way

If you only want the database and no pgAdmin, a single docker run does it:

bash
docker run -d \
--name my-postgres \
-e POSTGRES_USER=admin \
-e POSTGRES_PASSWORD=secret \
-e POSTGRES_DB=mydb \
-p 5432:5432 \
-v pgdata:/var/lib/postgresql/data \
postgres:16

Two differences from the Compose setup: this one runs Postgres 16 rather than 15, and -p 5432:5432 publishes the port on every network interface, not only on 127.0.0.1. Use -p 127.0.0.1:5432:5432 if you want the same local-only behaviour.

Stopping and resetting

bash
docker compose stop     # pause, keep everything
docker compose down # remove containers, keep data
docker compose down -v # remove containers AND wipe all data

down -v deletes both named volumes. Every table and every saved pgAdmin server is gone, with no undo. Dump anything you need first with pg_dump.

Common snags

  • Port 5432 is already in use. Another Postgres is running on the host. Stop it, or change the left side of the mapping to "127.0.0.1:5433:5432" and use port 5433 in DATABASE_URL.
  • Changed the password in .env but login still fails. Postgres only reads POSTGRES_PASSWORD the first time it creates the data directory. Change it with ALTER USER in psql, or reset with down -v.
  • pgAdmin keeps restarting. PGADMIN_EMAIL must be a valid email address; pgAdmin refuses to start with anything else.

That's the whole setup: clone, copy the env file, docker compose up -d. One database per project, the same version for everyone, and nothing installed on the host besides Docker.