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 pinax
sudo -u postgres createdb --owner pinax pinax

Install 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 postgres

Point 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-full

Put 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/.pgpass

Then 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-ingest
pinax db copy postgresql://pinax@db.example.org/pinax?sslmode=verify-full

Then 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