Skip to content
AI GatewayAI Gateway Manual

Upgrade

Upgrade AI Gateway to a newer version using install.sh upgrade, including database backup, rollback, and post-upgrade verification.

Upgrades are handled by the same installer script that performed the initial installation. Each version gets its own directory; the upgrade downloads and extracts the new package, copies secrets from the current .env, runs migrations, and switches current to the new version directory when the service reports healthy.

  • Run from aig/current. The script rejects execution from any other version directory.
  • The installation must be running (the bundled PostgreSQL must accept connections) so the installer can take a database backup before switching.
  • If you use an external PostgreSQL, back it up with your own tools first and then pass --no-backup (see External PostgreSQL).
  • Log in to harbor.chequer.io as the user that runs the installer (see Registry login). When the upgrade is done, log out as the same user with docker logout harbor.chequer.io (sudo docker logout harbor.chequer.io if you logged in with sudo).

From aig/current, run:

Terminal window
cd aig/current
./install.sh upgrade 2026.11.15

The script performs these steps in order:

  1. Validate inputs. Confirms the target version sorts higher than the installed version and that the required tools are available.
  2. Extract the new package. Downloads package.tar.gz from https://dl.querypie.com/releases/ai-gateway/<version>/ (or uses --package) into aig/<version>/. If .env does not yet exist in that directory, copies the current .env into it, updates VERSION, and appends any keys that the new env.template adds.
  3. Verify datastores. Checks that COMPOSE_PROFILES is consistent with DATABASE_URL and REDIS_URL in the new .env.
  4. Pull images. Pulls the images for the new version from harbor.chequer.io. A pull failure aborts before any running service changes (see Image pull failure).
  5. Back up the database. Dumps the bundled PostgreSQL to aig/<current_version>/backups/aig-<current_version>-<timestamp>.dump using pg_dump -Fc. Skipped when --no-backup is passed. Rejected with an error when DATABASE_URL is set without --no-backup.
  6. Start the new version. Runs docker compose up -d --remove-orphans from the new version directory, so migrate runs against the new schema first. Waits for /readyz to respond (up to 300 seconds).
  7. Switch current. Points aig/current at the new version directory.
  8. Print next steps. Logs the base URL and bootstrap token location.

If the host cannot reach dl.querypie.com, download the package on another machine and copy it to the host, then pass --package:

Terminal window
./install.sh upgrade 2026.11.15 --package /tmp/package-2026.11.15.tar.gz

The path may be absolute or relative to the directory from which you invoke the script (not aig/current).

When DATABASE_URL is set in .env, the installer cannot reach the external database to take a dump. Back up the external database with your own tools, then pass --no-backup:

Terminal window
./install.sh upgrade 2026.11.15 --no-backup

Running upgrade without --no-backup when DATABASE_URL is set is rejected:

[aig] ERROR: DATABASE_URL points to a PostgreSQL this script cannot back up; back it up with your own tools, then run './install.sh upgrade 2026.11.15 --no-backup'

If any step fails, the script exits immediately (the script runs with set -euo pipefail). The previous version continues running because current is not switched until after /readyz responds. The partially created aig/<version>/ directory is left in place; running the same upgrade command again reuses it and keeps the .env already copied into it.

If the database backup step fails (for example because PostgreSQL is not running or disk space is insufficient), the script aborts before touching the running service:

[aig] ERROR: database backup failed; start the installation first or pass --no-backup

The previous version directory and its .env remain on disk after an upgrade. To roll back, run every command from the previous version directory. That directory holds both the Compose file to start and the backups/ dump the upgrade created.

Terminal window
cd aig/2026.11.01
docker compose stop server web
docker compose exec -T postgres dropdb -U ai_gateway ai_gateway
docker compose exec -T postgres createdb -U ai_gateway ai_gateway
docker compose exec -T postgres pg_restore -U ai_gateway -d ai_gateway \
< backups/aig-2026.11.01-<timestamp>.dump
docker compose up -d --remove-orphans
ln -sfn 2026.11.01 ../current

The dropdb/createdb pair matters: a failed upgrade may have left partial schema changes in the shared aig_pgdata volume, and restoring into a non-empty database fails. If you use an external PostgreSQL, skip those three database commands and instead restore the backup you took before the upgrade using your own tools.

Note: encrypted values in the database (IdP client secrets, provider API keys) are readable only with the DB_FIELD_ENCRYPTION_KEY from the .env that was in use when they were written. If you rolled forward and new encrypted values were written with the new .env, rolling back to the previous .env makes those new values unreadable. Roll back as soon as possible after detecting a problem, before any new configuration is saved.

After a successful upgrade, verify the new version is running:

Terminal window
cd aig
# Confirm current points to the new version directory.
readlink current
cd current
# Confirm the service reports healthy. If you changed AIG_HTTP_PORT from its
# default of 80, append it: http://127.0.0.1:8080/readyz
curl -sf http://127.0.0.1/readyz && echo "ok"
# Confirm the VERSION in .env matches the upgraded version.
grep ^VERSION .env

In the browser, the last line of the Account menu at the top right shows the same version. Reload the page if it still shows the previous one.

The installer also prints the base URL; confirm the gateway is reachable through the load balancer:

Terminal window
curl -sI https://aig.example.com/api/auth/capabilities

Expect HTTP/2 200 and the header X-Content-Type-Options: nosniff.