Upgrade a self-hosted database
Nomatron is in early access. Some advanced workflows may not be covered in the public docs.
Nomatron stores its data in PostgreSQL. When a production server starts a new version, that start applies the database changes for the version. Take a backup before every upgrade. If startup fails, restore that backup. Do not keep retrying against a database you cannot restore.
Which upgrades are supported
Supported: one step from an initialized production database, created by an earlier Nomatron release, to a newer release. You do not apply database changes by hand.
Read the release notes for every release you pass through. A new version can start cleanly and still change operator-visible behavior.
Not supported:
- A downgrade to an older binary. Columns added by a newer version are left in place.
- Two different Nomatron versions running against the same database.
nomatron database initas the upgrade step. It refuses an initialized database.- A production server attached to a database that was created in dev mode. Startup refuses that database.
- A jump the release notes tell you not to take.
Stop every Nomatron process before the new version starts. The backup comes first so a failed start can be restored.
Order of operations
Do these in order for every install method.
- Back up PostgreSQL and confirm the dump file is not empty.
- Stop or drain every Nomatron server. Leave PostgreSQL running.
- Start one process on the new version. That start applies the database changes. Wait until it is healthy.
- Verify.
- Start the other servers, if you have more than one.
If step 3 fails, stop. Do not start a second process. Restore the dump, then start the previous version.
Backup and restore
Use pg_dump and pg_restore from the same PostgreSQL major version as the server. The published trial Compose stack uses Postgres 16. Do not print the database URL in shell history if you can avoid it. The URL is NOMATRON_DB_URL when that variable is set, otherwise database.connection_string in the server HCL file.
Custom-format dump:
pg_dump --format=custom --file=nomatron-backup.dump --dbname="$NOMATRON_DB_URL"Restore, with Nomatron stopped. --clean drops existing objects in this database and reloads the dump. Run it only against the database you just backed up.
pg_restore --clean --if-exists --exit-on-error --dbname="$NOMATRON_DB_URL" nomatron-backup.dumpA failed upgrade is not rolled back by Nomatron. Restore the dump. Do not guess which statements were committed.
Trial Compose package
With the stack running. Custom-format archives need a real file, not a pipe:
docker compose exec -T postgres pg_dump -U nomatron -d nomatron --format=custom --file=/tmp/nomatron-backup.dump
docker compose cp postgres:/tmp/nomatron-backup.dump ./nomatron-backup.dumpStop only the Nomatron container. Postgres keeps running.
docker compose stop nomatronSet NOMATRON_VERSION in .env to the new published tag, then start the new container:
docker compose up -d nomatronThe image is ghcr.io/nomatronio/nomatron-releases/nomatron at that tag. The container command is server, which applies the database changes.
Verify:
docker compose ps
docker compose exec nomatron /usr/local/bin/nomatron healthRestore the trial database:
docker compose stop nomatron
docker compose cp ./nomatron-backup.dump postgres:/tmp/nomatron-backup.dump
docker compose exec -T postgres pg_restore -U nomatron -d nomatron --clean --if-exists --exit-on-error /tmp/nomatron-backup.dumpSet NOMATRON_VERSION back to the previous tag and start again with docker compose up -d nomatron.
docker compose down -v deletes the Postgres volume. That is not a backup, and it is not a restore.
Binary install
Stop the nomatron server process. Leave PostgreSQL running. Take the pg_dump above. Replace the binary with the newer release. Start one server with the same config file the old process used:
nomatron server --config /etc/nomatron/config.hclStartup applies the database changes, then serves traffic. In another shell:
nomatron healthIf health does not succeed, stop the process and pg_restore as above, then start the previous binary.
Do not run nomatron database init again on this database.
Nomad
If you run the Nomatron binary or container as your own Nomad job, use the same order: dump PostgreSQL from outside the allocation, drain every Nomatron allocation, submit the new image or binary, and wait until one allocation is healthy (nomatron health) before allowing the others. Do not run two versions together.
What a healthy upgrade looks like
The new process stays up. nomatron health succeeds. You can sign in. If you run more than one server, start the rest only after that.
A dev-mode database cannot be opened by a production server. Use a dedicated Postgres instance for production.