- Notifications
You must be signed in to change notification settings - Fork 0
Postgres
You might consider a managed Postgres for your application.
This page shows how to self-host it as a service.
The database in SuperStack isn’t bundled inside the main app/ stack. Instead, it lives in its own directory — db/ — and is started separately.
By isolating the database layer, you gain several benefits:
- Avoid data corruption
- Run multiple app stacks safely
- Upgrade and experiment freely
- Cleaner separation of concerns
In short — keep your data persistent and your app stacks disposable. The db/ project handles the durable data, while each app/ project can come and go freely.
From the root of the repository, create a db directory:
mkdir dbCreate a Compose file:
db/compose.yaml
name: myapp-dbservices: postgres: image: postgresvolumes: - postgres_data:/var/lib/postgresql/data:rwenvironment: POSTGRES_USER: ${POSTGRES_USER:?}POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:?}POSTGRES_DB: ${POSTGRES_DB:?}healthcheck: test: ["CMD", "pg_isready", "-U", "${POSTGRES_USER}", "-d", "app"]interval: 0.5stimeout: 3sretries: 10volumes: postgres_data:Optionally, increase healtcheck intervals in development:
db/compose.override.yaml
services: postgres: # Set faster healthcheck intervals for the development serverhealthcheck: interval: 0.5stimeout: 1sretries: 10Add an environment file:
db/.env
POSTGRES_USER=admin POSTGRES_PASSWORD=pass POSTGRES_DB=appFrom the db/ directory:
docker compose up -dIn your app, connect to the db network in services that need it:
app/compose.yaml
services: # Add db_default network to services that need db accesspostgrest: networks: - default - myapp-db_defaultnetworks: myapp-db_default: external: trueSee also:
- Configure Psql – Customize psql for interacting with Postgres
- Convenience Script – Add a convenience script for interacing with PG
- Postgres Extensions – Add Extensions
- Postgres Migrations – Add a simple migrations system
- PostgREST – Add a REST API to Postgres