Skip to content

Upgrade PostgreSQL 18 to 19 ​

Compose defaults to PostgreSQL 18. Fresh installations can explicitly opt in to PostgreSQL 19. Existing installations can stay on PostgreSQL 18: this application release does not require a database major-version upgrade. If you update the Compose file while staying on 18, set POSTGRES_IMAGE=postgres:18-alpine in your existing .env before starting Compose. Do not replace .env with .env.example.

Changing the image tag does not upgrade a database. With the supported Compose volume mounted at /var/lib/postgresql, the official PostgreSQL 19 image refuses to start on a volume containing only the PostgreSQL 18 cluster. Changing the Compose project name or selecting a new volume can instead start an empty cluster. If an existing dashboard shows the first-run setup screen after an update, stop the application and check the database and volume. Do not complete setup or delete either volume.

Back up and restore with Compose ​

Rehearse this procedure before scheduling downtime. Keep the same application version on both sides of the database move so major-version migration and application changes can be verified separately. Run these commands from the existing Compose project directory, with its usual project name and .env. Examples assume the default database and role; adjust db_user and db_name to match the existing installation. If DATABASE_URL points at an external database, use the external database instructions below instead.

  1. Set POSTGRES_IMAGE=postgres:18-alpine in .env. Stop the backend and frontend, and stop any other clients that write to this database. Confirm the source version, database name and actual volume before taking the final backup.

    bash
    db_user=usage_dashboard
    db_name=usage_dashboard
    docker compose stop frontend backend
    docker compose exec -T db psql -X -v ON_ERROR_STOP=1 -U "$db_user" -d "$db_name" \
      -c 'SELECT current_database(), current_setting($$server_version$$);'
    db_container=$(docker compose ps -q db)
    docker inspect "$db_container" --format '{{range .Mounts}}{{println .Name .Destination}}{{end}}'

    Save the original .env (especially ENCRYPTION_KEY), Compose files, source volume name, and exact running application image tags or digests. In a protected backup directory with sufficient free space, make a new custom archive. Confirm standard_conforming_strings is on before dumping with PostgreSQL 18 tools (otherwise use a PostgreSQL 19 pg_dump client). Keep the archive private; it contains credentials and application data.

    bash
    docker compose exec -T db psql -X -U "$db_user" -d "$db_name" -c 'SHOW standard_conforming_strings;'
    umask 077
    docker compose exec -T db pg_dump -U "$db_user" -d "$db_name" -Fc > usage-dashboard-pg18.dump
    docker compose exec -T db pg_restore --list < usage-dashboard-pg18.dump
    sha256sum usage-dashboard-pg18.dump
    docker compose stop db

    Stop if any command fails. Keep the source volume intact. Never run docker compose down --volumes during this procedure.

  2. Create a new, unused volume name (check docker volume ls first). Use a persistent Compose override to select it explicitly, instead of reusing the source volume. Keep that override in every subsequent Compose command or incorporate it into the deployment configuration before re-enabling updates.

    bash
    docker volume create usage-dashboard-pg19-data

    Save this file as compose.pg19.yml:

    yaml
    services:
      db:
        image: postgres:19-alpine
    volumes:
      postgres-data:
        external: true
        name: usage-dashboard-pg19-data

    Leave database credentials and ENCRYPTION_KEY unchanged. Start only the new database. Verify the mounted volume, server version, and absence of tables before restoring. Do not start the backend until the restore succeeds.

    bash
    docker compose -f docker-compose.yml -f compose.pg19.yml up -d --wait db
    db_container=$(docker compose -f docker-compose.yml -f compose.pg19.yml ps -q db)
    docker inspect "$db_container" --format '{{range .Mounts}}{{println .Name .Destination}}{{end}}'
    docker compose -f docker-compose.yml -f compose.pg19.yml exec -T db \
      psql -X -v ON_ERROR_STOP=1 -U "$db_user" -d "$db_name" \
      -c 'SELECT current_database(), current_setting($$server_version$$);' -c '\dt'
    docker compose -f docker-compose.yml -f compose.pg19.yml exec -T db \
      pg_restore -U "$db_user" -d "$db_name" --no-owner --no-acl \
      --exit-on-error --single-transaction < usage-dashboard-pg18.dump
  3. Before allowing writes, compare the source and restored alembic_version, row counts (including provider_configs, usage_snapshots and usage_observations), sequence values, indexes, and constraints. Run ANALYZE on the target to rebuild planner statistics. Start the application with the same release as before. Keep public access blocked and set AUTO_POLL_ENABLED=false during verification. That flag stops provider auto-polls, not the separate data-source scheduler: block the backend's outbound access to enabled data-source endpoints until cutover. Check backend migration logs, /health, login, provider configurations and their history. Verify encrypted credentials work with the original key before reopening access. /health alone does not check the database.

    bash
    docker compose -f docker-compose.yml -f compose.pg19.yml up -d --wait
    docker compose -f docker-compose.yml -f compose.pg19.yml logs backend

Native Linux, external databases, and standalone containers ​

Keep the original PostgreSQL 18 cluster untouched and provision a separate PostgreSQL 19 cluster or fresh volume. Quiesce writers: on native Linux stop usage-dashboard-backend.service and do not run the migration unit; for standalone containers stop the frontend and backend. Take a custom-format pg_dump and restore with a PostgreSQL 19 pg_restore as above. Preserve the owner or supply the correct application role, and recreate required grants if using --no-owner --no-acl. Database dumps do not include cluster-wide roles or server configuration. Verify database identity, credentials, permissions and restored contents before repointing DATABASE_URL (or switching the PostgreSQL container/network alias). Run the usual native migration service or standalone startup only after the restore. For provider-managed PostgreSQL, follow the provider's supported procedure for upgrades, backups and recovery.

Roll back ​

If verification fails before accepting writes on PostgreSQL 19, stop the new application and database. For Compose, stop the stack using the PostgreSQL 19 override, then return to the original Compose files (no PostgreSQL 19 override), original volume/project name, POSTGRES_IMAGE=postgres:18-alpine, and the original application image tags and environment. Verify the expected old volume before starting. On native or standalone deployments, point the original application release at the untouched PostgreSQL 18 cluster instead. Check logs, login and history before reopening access. Leave the PostgreSQL 19 volume intact until recovery is confirmed.

If PostgreSQL 19 has already accepted writes, the PostgreSQL 18 copy is stale. Freeze writes again and plan reconciliation or recovery before switching back. Do not assume a PostgreSQL 19 dump can be loaded by PostgreSQL 18. Keep the source cluster and backup until the upgrade is accepted under your retention policy.

Self-hosted API usage dashboard.