A production-grade PostgreSQL 16 setup purpose-built for MatrixHub:
- One command bootstrap:
make init - Idempotent schema init (entity, embedding_chunk, remote) on first boot
- Durable data via Docker volume, systemd auto-start on boot
- Optional PgBouncer connection pooling, Prometheus exporter
- Backup/restore automation (CLI + systemd nightly timer)
- Secure defaults with configurable
pg_hbaCIDR allow list
Compatibility: Mirrors the MatrixHub models/migrations you provided (columns, JSONB defaults, check constraints, indexes). No breaking changes.
# 1) Connect to your instance
ssh -i /path/to/your_key opc@<public-ip>
# 2) Install git & make and clone the repo
sudo dnf -y install git make
git clone https://github.com/agent-matrix/matrixhub-db.git
cd matrixhub-db
# 3) Configure secrets
cp .env.db.example .env.db
nano .env.db # set a strong POSTGRES_PASSWORD; adjust PG_ALLOW_CIDR
# 4) Bootstrap everything
make init
# 5) Verify
make verifypostgres://matrix:<PASSWORD>@<server-ip>:5432/matrixhub
- Installs Docker CE
- Opens firewall 5432/tcp (configurable via
PG_HOST_PORT) - Builds the custom Postgres image (schema/extension init)
- Runs the DB container with durable volume & healthcheck
- Installs and enables a systemd unit for auto-start
- Waits until the DB is healthy
Start a pooler on the same Docker network (port 6432 by default):
make pgbouncer-upApps connect to pgbouncer:6432 (inside the Docker network) or host:<PGBOUNCER_PORT> if you publish it.
Create a read-only monitoring role and run the exporter:
make exporter-upIt listens on host port 9187 by default.
- On-demand:
make backup-now - Nightly (02:30) with systemd timer:
make backup-install
Backups are stored in the ./backups/ directory.
- Passwords: Never commit
.env.db. pg_hba: RestrictPG_ALLOW_CIDRin.env.dbto your VCN subnets/VPN.- TLS: For client TLS, set
TLS_ENABLE=1in.env.db, create acertsdirectory withserver.crt/server.key, and re-runmake up. - Users: Prefer separate DB users per service (rw vs ro) with least privilege.
make systemd-remove
make clean # DANGER: This deletes the data volume