Skip to main content

Database

The PDM keeps everything except file contents in one Postgres 16 database: documents, folders, branches, drafts and versions, revisions, references, jobs, runs and the audit log.

Set it up​

CREATE ROLE pdm LOGIN PASSWORD 'choose-one';
CREATE DATABASE pdm OWNER pdm;

Then set DB_HOST, DB_PORT, DB_USER, DB_PASSWORD and DB_NAME. That's all: the API creates its tables on its first start and runs new migrations on every start after an update. There's no separate migration step.

The repository's docker-compose.yml starts a Postgres for development on port 5002 (yarn db:up). It's fine to copy, but it isn't a production setup.

Backups​

The database and the file store belong together. The database says which files exist and the store holds them, so back up both at the same time, database first:

pg_dump --format=custom --file=pdm-$(date +%F).dump pdm
rsync -a /srv/classcad-pdm/packages/api/storage/ /backup/pdm-storage/

Files are never changed in place, only added and removed, so copying the store while the PDM runs is safe. At worst the copy has a file the dump doesn't know about yet.

To restore: stop the API and workers, restore the dump (pg_restore --clean --dbname=pdm pdm-….dump), put the files back, start again.