The catalog and backups
SQLite or PostgreSQL, moving between them, and backing up what cannot be made again.
Catalog database
The catalog is SQLite in WAL mode by default, /var/lib/pinax/pinax.db: a file the Pinax processes open themselves, with no database server to run, which suits one server running the web app and the watcher. It holds everything that cannot be made again (see What Pinax keeps), so back it up. PostgreSQL is the choice when IT would rather run the catalog as one of its databases, backed up, replicated, and monitored as the others are (The catalog database).
pinax db status names the catalog (never its password) and says whether it is up to date. Releases that change the catalog do it with migrations, applied when Pinax starts (Upgrading).
PostgreSQL
PostgreSQL 14 or later. Pinax needs one database and a role that owns it:
sudo -u postgres createuser --pwprompt pinaxsudo -u postgres createdb --owner pinax pinaxInstall Pinax with its PostgreSQL driver (step 2 of Install, with --extra postgres):
cd /opt/pinax && sudo env UV_PYTHON_INSTALL_DIR=/opt/pinax/.python uv sync --frozen --no-dev --extra postgresPoint Pinax at it in /etc/pinax/pinax.env, without the password, and with TLS when the database is on another host:
PINAX_DATABASE_URL=postgresql://pinax@db.example.org/pinax?sslmode=verify-fullPut the password in the pinax user's ~/.pgpass, which only that user may read (PostgreSQL's driver refuses it otherwise):
echo 'db.example.org:5432:pinax:pinax:THE-PASSWORD' | sudo -u pinax tee /var/lib/pinax/.pgpass >/dev/null && sudo chmod 0600 /var/lib/pinax/.pgpassThen pinax db upgrade (the shell function from step 3) creates the catalog (Pinax would also do it when it starts), and pinax db status should say up to date. Each Pinax process keeps up to PINAX_DATABASE_POOL_SIZE (10) connections open, and as many more at busy times; the web app, the watcher, and commands each have their own. Connections show as pinax in pg_stat_activity.
Moving a catalog from SQLite to PostgreSQL
pinax db copy copies every table of the catalog into an empty database, in one transaction, then sets PostgreSQL's id sequences past the copied rows and compares every table's count. Indexes and scans stay where they are. With the PostgreSQL database and role made, the driver installed, and the password in ~/.pgpass (above):
sudo systemctl stop pinax-web pinax-ingestpinax db copy postgresql://pinax@db.example.org/pinax?sslmode=verify-fullThen set PINAX_DATABASE_URL to the same URL in /etc/pinax/pinax.env and start the services again; keep pinax.db until PostgreSQL has been backed up. A catalog from 0.9.0 or earlier is upgraded first (pinax db upgrade), and the copy refuses a database that is not empty, or a source that is not up to date. The copy works the other way too, from PostgreSQL into a new SQLite file (--from names the source).
Backups
Catalog: back up
/var/lib/pinax/pinax.db, daily. It is the only part that cannot be made again: people, labs, memberships and site roles, folder ownership and its history, snapshot records, folder history for every scan, prices and free tiers, plans, tags, views, password hashes, API tokens' hashes, and the audit log. It is small. Copying the file while Pinax runs can catch it half-written, so use SQLite's online backup (thesqlite3package), which is safe at any time:sudo install -d -o pinax -g pinax -m 0750 /var/lib/pinax/backupsudo -u pinax sqlite3 /var/lib/pinax/pinax.db ".backup '/var/lib/pinax/backup/pinax-$(date +%F).db'"Then copy the backup off the server. To restore, stop
pinax-webandpinax-ingest, put the backup in place ofpinax.db, deletepinax.db-walandpinax.db-shm, and start them again. Keep the import files too.On PostgreSQL, the database's own backups apply, IT's or
pg_dump, which is safe while Pinax runs:sudo -u pinax pg_dump --format=custom --file=/var/lib/pinax/backup/pinax-$(date +%F).dump pinaxTo restore, stop
pinax-webandpinax-ingest, restore into an empty database withpg_restore --no-owner --role=pinax --dbname=pinax, and start them again.- Indexes: optional;
pinax rebuildmakes each again from its snapshot's scan, if that is kept. - Scans: keep those of snapshots that still have their index (Scans); the rest can be deleted.
- A catalog backup holds top-level folder names and people's names and emails; copies of indexes or scans hold every file and folder name and owner names. Protect them as you would the filesystem's own metadata.