[PR #20538] fix: avoid unnecessary writes to system metadata repository #16596

Closed
opened 2026-02-05 16:07:47 +03:00 by OVERLORD · 0 comments
Owner

Original Pull Request: https://github.com/immich-app/immich/pull/20538

State: closed
Merged: Yes


When running the server in a secondary, read-only role against a PostgreSQL read-only replica, the bootstrap process currently attempts to unconditionally write the media location to the metadata repository. This leads to the following error:

PostgresError: cannot execute INSERT in a read-only transaction

This PR updates the bootstrap logic to avoid unnecessary writes by writing MediaLocation only if it is missing or has changed compared to the current runtime-detected value.

This change make the bootstrap process safe to run in read-only environments.

How Has This Been Tested?

  • Tested the change inside a docker container
  • Compiled the changed file

Checklist:

  • I have performed a self-review of my own code
  • I have made corresponding changes to the documentation if applicable
  • I have no unrelated changes in the PR.
  • I have confirmed that any new dependencies are strictly necessary.
  • I have written tests for new code (if applicable)
  • I have followed naming conventions/patterns in the surrounding code
  • All code in src/services/ uses repositories implementations for database calls, filesystem operations, etc.
  • All code in src/repositories/ is pretty basic/simple and does not have any immich specific logic (that belongs in src/services/)
**Original Pull Request:** https://github.com/immich-app/immich/pull/20538 **State:** closed **Merged:** Yes --- When running the server in a secondary, read-only role against a PostgreSQL read-only replica, the bootstrap process currently attempts to unconditionally write the media location to the metadata repository. This leads to the following error: ``` PostgresError: cannot execute INSERT in a read-only transaction ``` This PR updates the bootstrap logic to avoid unnecessary writes by writing MediaLocation only if it is missing or has changed compared to the current runtime-detected value. This change make the bootstrap process safe to run in read-only environments. ## How Has This Been Tested? - [x] Tested the change inside a docker container - [x] Compiled the changed file ## Checklist: - [x] I have performed a self-review of my own code - [ ] I have made corresponding changes to the documentation if applicable - [x] I have no unrelated changes in the PR. - [x] I have confirmed that any new dependencies are strictly necessary. - [ ] I have written tests for new code (if applicable) - [x] I have followed naming conventions/patterns in the surrounding code - [x] All code in `src/services/` uses repositories implementations for database calls, filesystem operations, etc. - [ ] All code in `src/repositories/` is pretty basic/simple and does not have any immich specific logic (that belongs in `src/services/`)
OVERLORD added the pull-request label 2026-02-05 16:07:47 +03:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: immich-app/immich#16596