Deployn

Upgrade Immich from PostgreSQL 14 to 18 or 19 with VectorChord

Migrate Immich from PostgreSQL 14 to 18 or 19 with Docker Compose. Includes backup, restore, rollback, and measured idle resource usage.

Upgrade Immich from PostgreSQL 14 to 18 or 19 with VectorChord hero image
Contents
Tested with
Immich 3.4.2PostgreSQL 14.19, 18.3, and 19.0VectorChord 0.4.3, 1.1.1, and 1.5.0
Last checked on

If you run Immich with Docker Compose and want to upgrade from PostgreSQL 14 to 18 or 19, you need to migrate the database. Export your old database, create a PostgreSQL cluster, and restore the data there. Your photos and videos stay where they are.

I tested both paths on the same Hetzner server. I started with the default Compose file for Immich 3.4.2, which used PostgreSQL 14 and VectorChord 0.4.3. The test album contained 24 synthetic images, and Immich had already generated search embeddings for them.

Summary
  1. Back up the PostgreSQL database as a dump, along with the media directory, .env, and the Compose file.
  2. Choose PostgreSQL 18 with TensorChord VectorChord 1.1.1 or 19 with PGSTY VectorChord 1.5.0.
  3. Start PostgreSQL with an empty data directory, restore the dump, and verify Immich before allowing uploads again.

PostgreSQL 18 or 19 with VectorChord?

Path PostgreSQL VectorChord Database image
Starting point 14 0.4.3 from TensorChord Default image from Immich 3.4.2
A 18 1.1.1 from TensorChord Prebuilt TensorChord image
B 19 1.5.0 from the PGSTY fork Built from the official PostgreSQL image and the PGSTY package

Immich lists PostgreSQL 14 through 19 for use with an existing database and accepts VectorChord versions from 0.3 up to, but excluding, 2.0. TensorChord provides VectorChord 1.1.1 builds through PostgreSQL 18. Release 1.5.0 of the PGSTY fork supports PostgreSQL 15 through 19 on x86‑64 and ARM64. Both extensions are named vchord in PostgreSQL. Immich database documentation · TensorChord 1.1.1 · PGSTY 1.5.0

The Immich installation guide covers updating the Immich app itself. If your older instance still uses vectors from pgvecto.rs, migrate to vchord on your current PostgreSQL version first. Immich 3 dropped support for pgvecto.rs. The steps below start with a database that already uses vchord and vector. Immich documentation on migrating to VectorChord

1. Check your PostgreSQL version and extensions

Run the commands from your Immich installation directory. The examples use compose.yaml. If your file is named docker-compose.yml, use that filename when backing up, editing, and restoring the Compose file. The default configuration names the PostgreSQL service database. If .env sets DB_USERNAME or DB_DATABASE_NAME to values other than postgres and immich respectively, use your values in the commands.

Terminalbash
docker compose ps
docker compose exec -T database psql -U postgres -d immich \
  -c 'SHOW server_version;' \
  -c "SELECT extname, extversion FROM pg_extension
      WHERE extname IN ('vector', 'vchord', 'vectors') ORDER BY extname;"

Immich test album with 24 synthetic images on PostgreSQL 14

2. Prepare the database image before maintenance

Path A with PostgreSQL 18 and TensorChord

The image includes PostgreSQL, pgvector, and VectorChord. Pull it while Immich is still running. TensorChord image for PostgreSQL 18

Terminalbash
docker pull tensorchord/vchord-postgres:pg18-v1.1.1

Path B with PostgreSQL 19 and PGSTY

Create postgres19-image/Dockerfile. The build installs pgvector from the PostgreSQL package repository and checks the downloaded PGSTY package against the published SHA-256 checksum. dpkg --print-architecture selects the package for the image’s architecture. I tested the build on x86‑64. Official PostgreSQL image · PGSTY packages for PostgreSQL 19

postgres19-image/Dockerfiledockerfile
FROM postgres:19.0-trixie

RUN set -eux; \
    apt-get update; \
    apt-get install -y --no-install-recommends ca-certificates curl postgresql-19-pgvector; \
    cd /tmp; \
    package="postgresql-19-vchord_1.5.0-1_$(dpkg --print-architecture).deb"; \
    base=https://github.com/pgsty/vchord/releases/download/1.5.0; \
    curl -fsSLO "$base/$package"; \
    curl -fsSLO "$base/$package.sha256"; \
    sha256sum -c "$package.sha256"; \
    apt-get install -y --no-install-recommends "./$package"; \
    rm -f "$package" "$package.sha256"; \
    rm -rf /var/lib/apt/lists/*
Terminalbash
docker build -t immich-postgres:19.0-vchord1.5.0 postgres19-image

3. Stop Immich and back up PostgreSQL 14

Connect over SSH to the server still running Immich with PostgreSQL 14. Change into the directory containing the Compose file and .env. Run docker compose ps to check that you are in the right directory and the database service is running. The backup files will be written to this directory.

Wait for any active uploads to finish. The block first copies the configuration for rollback and restricts access to the backup of .env, which holds the database password. It then stops both Immich services so the library and its metadata stay consistent during the backup. PostgreSQL keeps running so pg_dump can export it.

The dump contains metadata such as albums and file references. The tar archive contains the photos and videos themselves. In the test they were in ./library. Use the path from your UPLOAD_LOCATION when creating the archive, and back up any external libraries separately. Immich backup and restore

Terminalbash
umask 077 &&
cp compose.yaml compose.pg14.yaml &&
cp .env .env.pg14 &&
chmod 600 .env.pg14 &&
docker compose stop immich-server immich-machine-learning &&
docker compose exec -T database pg_dump -U postgres -d immich -Fc \
  </dev/null > immich-pg14.dump &&
docker compose exec -T database pg_restore --list \
  < immich-pg14.dump > immich-pg14.list &&
tar -czf immich-library.tar.gz library

pg_restore --list checks that it can read the archive’s table of contents. The full restore in step 5 also checks whether tables and indexes can be created in the target database. Keep a copy of the dump, media archive, and configuration off the server. Make sure all commands completed successfully before stopping PostgreSQL 14.

Terminalbash
docker compose stop database

4. Point Compose to an empty data directory

Set DB_DATA_LOCATION=./postgres18 in .env for path A or DB_DATA_LOCATION=./postgres19 for path B. Use a new or empty directory. Keep the old directory referenced in .env.pg14 for rollback.

Change the image, startup command, and mount in the existing database service. Keep the existing environment variables POSTGRES_USER, POSTGRES_PASSWORD, and POSTGRES_DB.

compose.yaml · PostgreSQL 18yaml
services:
    database:
        image: tensorchord/vchord-postgres:pg18-v1.1.1
        command: ["postgres", "-c", "shared_preload_libraries=vchord"]
        volumes:
            - ${DB_DATA_LOCATION}:/var/lib/postgresql
compose.yaml · PostgreSQL 19yaml
services:
    database:
        image: immich-postgres:19.0-vchord1.5.0
        command: ["postgres", "-c", "shared_preload_libraries=vchord"]
        volumes:
            - ${DB_DATA_LOCATION}:/var/lib/postgresql

These images mount the parent directory /var/lib/postgresql. The container creates the actual data directory underneath it in a version-specific subdirectory. Data directory in the official PostgreSQL image · PostgreSQL documentation on major upgrades

5. Restore the dump and start Immich

Start only the database service. Repeat pg_isready until PostgreSQL accepts TCP connections. This checks the main process that starts after the empty cluster has been initialized.

Terminalbash
docker compose config --quiet &&
docker compose up -d database &&
docker compose exec -T database pg_isready -h 127.0.0.1 -U postgres -d immich </dev/null

Restore the dump once into the newly created database. The --exit-on-error flag stops the restore if a command fails. Check restore.log and use an empty target database if you need to retry.

Terminalbash
docker compose exec -T database pg_restore -U postgres -d immich \
  --exit-on-error --verbose < immich-pg14.dump > restore.log 2>&1 &&
docker compose exec -T database psql -U postgres -d immich \
  -v ON_ERROR_STOP=1 -c 'ANALYZE;' </dev/null

The restore creates vector and vchord using the target image’s default versions and rebuilds the saved indexes from their definitions. The index files from the old VectorChord version stay in the old cluster. PostgreSQL documentation on extensions in dumps · PostgreSQL documentation on pg_restore

Terminalbash
docker compose up -d
docker compose ps
docker compose logs --tail=60 immich-server

Run the SQL queries from step 1 again. Also compare the number of assets and search embeddings with the counts before migration. The query below uses the Immich 3.4.2 schema.

sql
SELECT (SELECT count(*) FROM asset) AS bilder,
       (SELECT count(*) FROM smart_search) AS embeddings;

Open an album you know, download an original, and try a search term that should return results from your library.

I restored the same PostgreSQL 14 dump into each target cluster separately. Both contained 24 assets and 24 search embeddings after the restore. On both, Immich displayed the test album, returned an original file that matched byte for byte, and returned five results for the semantic search “mountains at sunset.” The API request was limited to five results.

SQL output for PostgreSQL 14.19, 18.3, and 19.0 showing extension versions, 24 assets, and 24 embeddings

Test album after path A with PostgreSQL 18

Immich shows all 24 images in the test album after restoring to PostgreSQL 18

Test album after path B with PostgreSQL 19

The same Immich test album with 24 images after restoring to PostgreSQL 19

Idle resource usage on the Hetzner server

I measured idle usage on a Hetzner CPX32 with four vCPUs and 8 GB of RAM. I kept the Immich, Valkey, and machine learning service versions and the media library the same. For each database configuration, I took 15 samples after starting the stack, with no uploads or searches during sampling. I restarted the PostgreSQL 14 baseline after rolling back for its measurement. I paused for three seconds between samples.

Terminalbash
for sample in $(seq 1 15); do
  docker stats --no-stream --format '{{.Name}}\t{{.CPUPerc}}\t{{.MemUsage}}' \
    immich_postgres immich_server immich_machine_learning immich_redis
  if [ "$sample" -lt 15 ]; then sleep 3; fi
done
Database configuration Median PostgreSQL CPU Median PostgreSQL RAM Median RAM across all four containers
PostgreSQL 14.19 with VectorChord 0.4.3 0.04% 81.4 MiB 1,283.2 MiB
PostgreSQL 18.3 with TensorChord 1.1.1 0.03% 190.3 MiB 1,419.4 MiB
PostgreSQL 19.0 with PGSTY 1.5.0 0.01% 196.7 MiB 1,430.6 MiB

Median database CPU usage was close to zero for all three configurations. The two target images each used about 110 MiB more database RAM than the default Immich image in this test. The PostgreSQL versions, extensions, and image defaults varied, so the measurements cannot isolate VectorChord’s contribution. In the first measurement after importing and indexing the test images, the same PostgreSQL 14 container had a median of 616.5 MiB. Earlier activity had a substantial effect on the comparison.

The compressed database dump was 17.8 MiB. The pg_restore command took about ten seconds on each target version. The maintenance window also includes time for backup, cluster startup, ANALYZE, and verification in Immich. The size of your library and the time it takes to rebuild its indexes will affect how long your migration takes.

Roll back to PostgreSQL 14 if something goes wrong

As long as there have been no new uploads or changes since the migration, you can use the old PostgreSQL 14 directory and configuration to return to the state before maintenance. If the old PostgreSQL 14 data is gone, you’ll need the database and media backups.

Terminalbash
docker compose stop immich-server immich-machine-learning database &&
cp compose.pg14.yaml compose.yaml &&
cp .env.pg14 .env &&
docker compose up -d database &&
docker compose exec -T database pg_isready -h 127.0.0.1 -U postgres -d immich </dev/null

Repeat pg_isready until PostgreSQL accepts connections. Then start Immich.

Terminalbash
docker compose up -d

Check the PostgreSQL version again, sign in to Immich, and verify your library. In the lab, the original PostgreSQL 14 cluster restarted after both restores, and Immich responded to the API ping. Changes written to the new cluster won’t appear in the old database. If you’ve used Immich since switching, keep the new cluster and its data as well.