Immich upgrade fails and the pre-upgrade backup restore also fails

What app is this about, and its version: Immich 2.5.6~ynh1
What YunoHost version are you running: 12.1.39
What type of hardware are you using: Old laptop or computer

Describe your issue

Share relevant logs or error messages

https://paste.yunohost.org/raw/uhifatamen

Same problem here, it seems to be something related to nginx, here’s a log in english if that helps:
https://paste.yunohost.org/raw/uhevikiloq

1 Like

I finally instaled again and restored with the Immich backup system that works fine.

I have also trouble to restore a immich backup: https://paste.yunohost.org/raw/ejagigisaj

I come from the problem of different postgres cluster versions, here: Paperless doesn't start - #16 by jedie

Restore by immich web GUI doens’t work. It ends with:


Restoring Database

Error: /usr/lib/postgresql/17/bin/psql non-zero exit code (2)
ERROR:  current user cannot be dropped
ERROR:  cannot drop role postgres because it is required by the database system
ERROR:  role "immich" already exists
ERROR:  role "postgres" already exists
\connect: connection to server at "127.0.0.1", port 5433 failed: FATAL:  password authentication failed for user "immich"
connection to server at "127.0.0.1", port 5433 failed: FATAL:  password authentication failed for user "immich"

I tried now the /home/yunohost.app/immich/backups/restore_immich_db_backup.sh script…

EDIT: No success, the server doesn’t start and the logs are full of errors like:

[Nest] 71014  - 03/14/2026, 3:55:32 PM     LOG [Microservices:WebsocketRepository] Initialized websocket server
[Nest] 71014  - 03/14/2026, 3:55:32 PM     LOG [Microservices:DatabaseRepository] targetLists=1, current=1 for clip_index of 36803 rows
[Nest] 71014  - 03/14/2026, 3:55:32 PM     LOG [Microservices:DatabaseRepository] targetLists=256, current=256 for face_index of 186407 rows
[Nest] 71014  - 03/14/2026, 3:55:32 PM     LOG [Microservices:DatabaseRepository] Running migrations
Query failed : {
  durationMs: 1.393764999999803,
  error: PostgresError: constraint "album_asset_albumsId_fkey" for table "album_asset" does not exist
      at ErrorResponse (/var/www/immich/immich/app/node_modules/.pnpm/postgres@3.4.8/node_modules/postgres/cjs/src/connection.js:815:30)
      at handle (/var/www/immich/immich/app/node_modules/.pnpm/postgres@3.4.8/node_modules/postgres/cjs/src/connection.js:489:6)
      at Socket.data (/var/www/immich/immich/app/node_modules/.pnpm/postgres@3.4.8/node_modules/postgres/cjs/src/connection.js:324:9)
      at Socket.emit (node:events:508:28)
      at addChunk (node:internal/streams/readable:559:12)
      at readableAddChunkPushByteMode (node:internal/streams/readable:510:3)
      at Readable.push (node:internal/streams/readable:390:5)
      at TCP.onStreamRead (node:internal/stream_base_commons:189:23) {
    severity_local: 'ERROR',
    severity: 'ERROR',
    code: '42704',
    file: 'pg_constraint.c',
    line: '931',
    routine: 'get_relation_constraint_oid'
  },
  sql: 'ALTER TABLE "album_asset" RENAME CONSTRAINT "album_asset_albumsId_fkey" TO "album_asset_albumId_fkey";',
  params: []
}
[Nest] 71014  - 03/14/2026, 3:55:33 PM    WARN [Microservices:DatabaseRepository] Migration "1761755618862-FixColumnNames" failed
[Nest] 71014  - 03/14/2026, 3:55:33 PM   ERROR [Microservices:DatabaseRepository] Migrations failed: PostgresError: constraint "album_asset_albumsId_fkey" for table "album_asset" does not exist
PostgresError: constraint "album_asset_albumsId_fkey" for table "album_asset" does not exist
    at ErrorResponse (/var/www/immich/immich/app/node_modules/.pnpm/postgres@3.4.8/node_modules/postgres/cjs/src/connection.js:815:30)
    at handle (/var/www/immich/immich/app/node_modules/.pnpm/postgres@3.4.8/node_modules/postgres/cjs/src/connection.js:489:6)
    at Socket.data (/var/www/immich/immich/app/node_modules/.pnpm/postgres@3.4.8/node_modules/postgres/cjs/src/connection.js:324:9)
    at Socket.emit (node:events:508:28)
    at addChunk (node:internal/streams/readable:559:12)
    at readableAddChunkPushByteMode (node:internal/streams/readable:510:3)
    at Readable.push (node:internal/streams/readable:390:5)
    at TCP.onStreamRead (node:internal/stream_base_commons:189:23) {
  severity_local: 'ERROR',
  severity: 'ERROR',
  code: '42704',
  file: 'pg_constraint.c',
  line: '931',
  routine: 'get_relation_constraint_oid'
}
microservices worker error: PostgresError: constraint "album_asset_albumsId_fkey" for table "album_asset" does not exist, stack: PostgresError: constraint "album_asset_albumsId_fkey" for table "album_asset" does not exist
    at ErrorResponse (/var/www/immich/immich/app/node_modules/.pnpm/postgres@3.4.8/node_modules/postgres/cjs/src/connection.js:815:30)
    at handle (/var/www/immich/immich/app/node_modules/.pnpm/postgres@3.4.8/node_modules/postgres/cjs/src/connection.js:489:6)
    at Socket.data (/var/www/immich/immich/app/node_modules/.pnpm/postgres@3.4.8/node_modules/postgres/cjs/src/connection.js:324:9)
    at Socket.emit (node:events:508:28)
    at addChunk (node:internal/streams/readable:559:12)
    at readableAddChunkPushByteMode (node:internal/streams/readable:510:3)
    at Readable.push (node:internal/streams/readable:390:5)
    at TCP.onStreamRead (node:internal/stream_base_commons:189:23)
microservices worker exited with code 1
Killing api process

Just reinstall and restore the immich db backup either from immich gui either with script provided

1 Like

currently the installation doesn’t work: https://paste.yunohost.org/raw/efoxobojoq

I tried a older version with:

yunohost app install https://github.com/YunoHost-Apps/immich_ynh/tree/444c6c4fb729038f54c72a567008079e31cc83fd -f

But also doesn’t work because of: ERROR: database "immich" already exists See: https://paste.yunohost.org/raw/dacebohomo

Now i try:

yunohost app install https://github.com/YunoHost-Apps/immich_ynh/tree/444c6c4fb729038f54c72a567008079e31cc83fd -f --no-remove-on-failure

and then:

yunohost app upgrade immich -F -b -c -u https://github.com/YunoHost-Apps/immich_ynh/tree/444c6c4fb729038f54c72a567008079e31cc83fd

The update looks okay:

...
Warnung: Skipping the creation of a backup prior to the upgrade.
Info: Updating sources...
Info: Updating system_user...
Info: Updating install_dir...
Info: Updating data_dir...
Info: Updating permissions...
Info: Updating ports...
Info: Updating apt...
Info: Updating nodejs...
Info: Updating database...
Info: [+...................] > Checking hardware requirements...
Info: [#++.................] > Stopping immich's systemd service...
Info: [###+................] > Ensuring downward compatibility...
Info: [####++..............] > Upgrading source files...
Info: '/var/www/immich/immich' wasn't deleted because it doesn't exist.
Info: '/var/www/immich/.cache' wasn't deleted because it doesn't exist.
Info: '/var/www/immich/.config' wasn't deleted because it doesn't exist.
Info: [######+.............] > Installing additionnal packages (if needed)...
Info: [#######++...........] > Updating a PostgreSQL database...
Info: [#########+..........] > Temporary adding additional swap (if needed)...
Info: [##########++........] > Making install...
Info: '/var/www/immich/vips' wasn't deleted because it doesn't exist.
Info: Building libheif for HEIC support...
Info: Building libvips with HEIC support...
Info: Cleaning up libvips build directory...
Info: Building immich server...
Info: Building immich openapi & web interface...
Info: Building immich cli...
Info: Building immich plugins...
Info: Building immich machine learning...
Info: Adding geonames capabilities...
Info: Cleaning up immich source directory...
Info: [############+.......] > Remove temporary swap if added...
Info: [#############++.....] > Updating immich's configuration files...
Info: [###############+....] > Upgrading system configurations related to immich...
Info: The service fail2ban has correctly executed the action reload-or-restart.
Info: [################++..] > Starting immich's systemd service...
Info: The service immich-machine-learning has correctly executed the action start.
Info: The service immich-server has correctly executed the action start.
Info: [####################] > Upgrade of immich completed
...

And now i try a restore with:

root@YunoHost:/home/yunohost.app/immich/backups# bash restore_immich_db_backup.sh 

DB restore was not successfully. So i tried to upgrade to “master” with:

yunohost app upgrade immich -F -b -c -u https://github.com/YunoHost-Apps/immich_ynh/tree/master

But doesn’t work: https://paste.yunohost.org/raw/uxanuhasin

So next try, after deinstall:

yunohost app install https://github.com/YunoHost-Apps/immich_ynh/tree/master -f --no-remove-on-failure

The systemd services can’t start:

==> /var/log/immich/immich-server.log <==
(node:74937) ExperimentalWarning: WASI is an experimental feature and might change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
/var/www/immich/immich/app/node_modules/.pnpm/postgres@3.4.8/node_modules/postgres/cjs/src/connection.js:817
      errored(Errors.postgres(parseError(x)))
                     ^

PostgresError: password authentication failed for user "immich"
    at ErrorResponse (/var/www/immich/immich/app/node_modules/.pnpm/postgres@3.4.8/node_modules/postgres/cjs/src/connection.js:817:22)
    at handle (/var/www/immich/immich/app/node_modules/.pnpm/postgres@3.4.8/node_modules/postgres/cjs/src/connection.js:489:6)
    at Socket.data (/var/www/immich/immich/app/node_modules/.pnpm/postgres@3.4.8/node_modules/postgres/cjs/src/connection.js:324:9)
    at Socket.emit (node:events:508:28)
    at addChunk (node:internal/streams/readable:559:12)
    at readableAddChunkPushByteMode (node:internal/streams/readable:510:3)
    at Readable.push (node:internal/streams/readable:390:5)
    at TCP.onStreamRead (node:internal/stream_base_commons:189:23) {
  severity_local: 'FATAL',
  severity: 'FATAL',
  code: '28P01',
  file: 'auth.c',
  line: '329',
  routine: 'auth_failed'
}

Node.js v24.12.0

Then i tried to install the last pre-postgres-17 version, think it’s: GitHub - YunoHost-Apps/immich_ynh at 444c6c4fb729038f54c72a567008079e31cc83fd · GitHub

so i ran:

yunohost app install https://github.com/YunoHost-Apps/immich_ynh/tree/444c6c4fb729038f54c72a567008079e31cc83fd -f --no-remove-on-failure

but it ends in:

...
Info: DEBUG - ++ cat /etc/yunohost/psql
Info: DEBUG - + sudo --login --user=postgres PGUSER=postgres PGPASSWORD=********** psql --cluster=16/main '' '--command=CREATE DATABASE immich;'
Info: WARNING - ERROR:  database "immich" already exists
Info: DEBUG - + ynh_exit_properly
Error: The installation of immich failed, but was not cleaned up as requested by --no-remove-on-failure.

So i tried to upgrade with:

yunohost app upgrade immich -F -b -c -u https://github.com/YunoHost-Apps/immich_ynh/tree/444c6c4fb729038f54c72a567008079e31cc83fd

The in worked.

Trying to restore a backup in maintenance results in error:

Error: /usr/lib/postgresql/16/bin/psql non-zero exit code (2)
ERROR:  current user cannot be dropped
ERROR:  cannot drop role postgres because it is required by the database system
ERROR:  role "immich" already exists
ERROR:  role "postgres" already exists
\connect: connection to server at "127.0.0.1", port 5432 failed: FATAL:  password authentication failed for user "immich"
connection to server at "127.0.0.1", port 5432 failed: FATAL:  password authentication failed for user "immich"

After exit the maintenance mode, the services is broken in a endless retry mode, because of this error:

==> /var/log/postgresql/postgresql-16-main.log <==
2026-03-14 22:20:45.270 UTC [122819] immich@immich FATAL:  password authentication failed for user "immich"
2026-03-14 22:20:45.270 UTC [122819] immich@immich DETAIL:  Connection matched file "/etc/postgresql/16/main/pg_hba.conf" line 125: "host    all             all             127.0.0.1/32            scram-sha-256"

==> /var/log/immich/immich-server.log <==
/var/www/immich/immich/app/node_modules/.pnpm/postgres@3.4.8/node_modules/postgres/cjs/src/connection.js:817
      errored(Errors.postgres(parseError(x)))
                     ^

PostgresError: password authentication failed for user "immich"
    at ErrorResponse (/var/www/immich/immich/app/node_modules/.pnpm/postgres@3.4.8/node_modules/postgres/cjs/src/connection.js:817:22)
    at handle (/var/www/immich/immich/app/node_modules/.pnpm/postgres@3.4.8/node_modules/postgres/cjs/src/connection.js:489:6)
    at Socket.data (/var/www/immich/immich/app/node_modules/.pnpm/postgres@3.4.8/node_modules/postgres/cjs/src/connection.js:324:9)
    at Socket.emit (node:events:508:28)
    at addChunk (node:internal/streams/readable:563:12)
    at readableAddChunkPushByteMode (node:internal/streams/readable:514:3)
    at Readable.push (node:internal/streams/readable:394:5)
    at TCP.onStreamRead (node:internal/stream_base_commons:189:23) {
  severity_local: 'FATAL',
  severity: 'FATAL',
  code: '28P01',
  file: 'auth.c',
  line: '331',
  routine: 'auth_failed'
}

Node.js v24.14.0

Try to use the restore script results in:

root@YunoHost:/home/yunohost.app/immich/backups# bash restore_immich_db_backup.sh 
1) immich-db-backup-20260301T020000-v2.2.3-pg16.13.sql.gz                  6) immich-db-backup-20260306T020000-v2.2.3-pg16.13.sql.gz                11) immich-db-backup-20260311T020000-v2.2.3-pg16.13.sql.gz
2) immich-db-backup-20260302T020000-v2.2.3-pg16.13.sql.gz                  7) immich-db-backup-20260307T020000-v2.2.3-pg16.13.sql.gz                12) immich-db-backup-20260312T020000-v2.2.3-pg16.13.sql.gz
3) immich-db-backup-20260303T020000-v2.2.3-pg16.13.sql.gz                  8) immich-db-backup-20260308T020000-v2.2.3-pg16.13.sql.gz                13) immich-db-backup-20260313T020000-v2.2.3-pg16.13.sql.gz
4) immich-db-backup-20260304T020000-v2.2.3-pg16.13.sql.gz                  9) immich-db-backup-20260309T020000-v2.2.3-pg16.13.sql.gz                14) immich-db-backup-20260314T020000-v2.2.3-pg16.13.sql.gz
5) immich-db-backup-20260305T020000-v2.2.3-pg16.13.sql.gz                 10) immich-db-backup-20260310T020000-v2.2.3-pg16.13.sql.gz                15) restore-point-immich-db-backup-20260314T221912-v2.5.6-pg16.13.sql.gz
Select backup file to restore, or 0 to exit:14

You select "immich-db-backup-20260314T020000-v2.2.3-pg16.13.sql.gz".

To proceed we are going to:
 1) stop immich
 2) drop the curent database
 3) restore the databse with the selected backup
 4) restart immich

Are you sure you want to continue restoring? [y/N] y
[+...................] Stopping immich...
[#+..................] Droping current immich db...
ERROR:  database "immich" does not exist

I just tweak the script and deactivate myynh_drop_psql_db and myynh_create_psql_db then the SQL dump restore starts…

After restore the server can’t start because of this errors:

==> /var/log/postgresql/postgresql-16-main.log <==
2026-03-14 22:46:28.895 UTC [127432] immich@immich ERROR:  constraint "album_asset_albumsId_fkey" for table "album_asset" does not exist
2026-03-14 22:46:28.895 UTC [127432] immich@immich STATEMENT:  ALTER TABLE "album_asset" RENAME CONSTRAINT "album_asset_albumsId_fkey" TO "album_asset_albumId_fkey";

==> /var/log/immich/immich-server.log <==
Query failed : {
  durationMs: 1.162200999999186,
  error: PostgresError: constraint "album_asset_albumsId_fkey" for table "album_asset" does not exist
      at ErrorResponse (/var/www/immich/immich/app/node_modules/.pnpm/postgres@3.4.8/node_modules/postgres/cjs/src/connection.js:815:30)
      at handle (/var/www/immich/immich/app/node_modules/.pnpm/postgres@3.4.8/node_modules/postgres/cjs/src/connection.js:489:6)
      at Socket.data (/var/www/immich/immich/app/node_modules/.pnpm/postgres@3.4.8/node_modules/postgres/cjs/src/connection.js:324:9)
      at Socket.emit (node:events:508:28)
      at addChunk (node:internal/streams/readable:563:12)
      at readableAddChunkPushByteMode (node:internal/streams/readable:514:3)
      at Readable.push (node:internal/streams/readable:394:5)
      at TCP.onStreamRead (node:internal/stream_base_commons:189:23) {
    severity_local: 'ERROR',
    severity: 'ERROR',
    code: '42704',
    file: 'pg_constraint.c',
    line: '889',
    routine: 'get_relation_constraint_oid'
  },
  sql: 'ALTER TABLE "album_asset" RENAME CONSTRAINT "album_asset_albumsId_fkey" TO "album_asset_albumId_fkey";',
  params: []
}
[Nest] 127386  - 03/14/2026, 10:46:28 PM    WARN [Microservices:DatabaseRepository] Migration "1761755618862-FixColumnNames" failed
[Nest] 127386  - 03/14/2026, 10:46:28 PM   ERROR [Microservices:DatabaseRepository] Migrations failed: PostgresError: constraint "album_asset_albumsId_fkey" for table "album_asset" does not exist
PostgresError: constraint "album_asset_albumsId_fkey" for table "album_asset" does not exist
    at ErrorResponse (/var/www/immich/immich/app/node_modules/.pnpm/postgres@3.4.8/node_modules/postgres/cjs/src/connection.js:815:30)
    at handle (/var/www/immich/immich/app/node_modules/.pnpm/postgres@3.4.8/node_modules/postgres/cjs/src/connection.js:489:6)
    at Socket.data (/var/www/immich/immich/app/node_modules/.pnpm/postgres@3.4.8/node_modules/postgres/cjs/src/connection.js:324:9)
    at Socket.emit (node:events:508:28)
    at addChunk (node:internal/streams/readable:563:12)
    at readableAddChunkPushByteMode (node:internal/streams/readable:514:3)
    at Readable.push (node:internal/streams/readable:394:5)
    at TCP.onStreamRead (node:internal/stream_base_commons:189:23) {
  severity_local: 'ERROR',
  severity: 'ERROR',
  code: '42704',
  file: 'pg_constraint.c',
  line: '889',
  routine: 'get_relation_constraint_oid'
}
microservices worker error: PostgresError: constraint "album_asset_albumsId_fkey" for table "album_asset" does not exist, stack: PostgresError: constraint "album_asset_albumsId_fkey" for table "album_asset" does not exist
    at ErrorResponse (/var/www/immich/immich/app/node_modules/.pnpm/postgres@3.4.8/node_modules/postgres/cjs/src/connection.js:815:30)
    at handle (/var/www/immich/immich/app/node_modules/.pnpm/postgres@3.4.8/node_modules/postgres/cjs/src/connection.js:489:6)
    at Socket.data (/var/www/immich/immich/app/node_modules/.pnpm/postgres@3.4.8/node_modules/postgres/cjs/src/connection.js:324:9)
    at Socket.emit (node:events:508:28)
    at addChunk (node:internal/streams/readable:563:12)
    at readableAddChunkPushByteMode (node:internal/streams/readable:514:3)
    at Readable.push (node:internal/streams/readable:394:5)
    at TCP.onStreamRead (node:internal/stream_base_commons:189:23)
microservices worker exited with code 1
Killing api process

Seems it’s this: v2.3.1 Update fail-loop, no booting & usable anymore · Issue #24037 · immich-app/immich · GitHub and discussion here: v2.3.1 Update fail-loop, no booting & usable anymore · immich-app/immich · Discussion #24042 · GitHub So migrations are missing?!?

I had this problem, and this solution worked for me.

Specifically, I removed the app from via Yunohost panel (leaving the data), then re-installed the app from the app catalog.

After that, I ssh into the server, entered the “/home/yunohost.app/immich/backups” directory as root, and executed “bash restore_immich_db_backup.sh”, chose the latest backup from the list, and after a minute or so, everything was back and working as of the latest DB backup,

I didn’t need to install any alternate versions or anything like that. It just worked.

Your situation is quite complex, and I am not sure to be able to help you more than what’s ca be read in the immich discussion you linked.
You certainly have to tweak you db backup to apply migrations manually :frowning:

I believe usually Yunohost is “against” Docker, but in my case after spending a lot of time doing backups and restores, I decided to migrate Immich to its original Docker instance, which is not too easy but certainly it’s doable, I really think the job done in immich_ynh is amazing, but I prefer this config instead, feels safer to upgrade/backup/restore in my opinion.

Your choice
Now immich is prebuit in yunohost so it make it safer and faster to install by avoiding all the heavy compilation on your server and the amount of resources required.

2 Likes