Using Immich with the Zalando Postgres Operator
The Problem
Immich has been a game changer for my family and has fully replaced Google Photos for over a year. The project has been going strong for a while with no signs of stopping and continues to push out updates full of new features! Something happened though on the update to v1.91, Immich was able to remove a dependency on a service called Typesense which they used for indexing and searching through content by using a new extension called vectors
inside of their existing PostgresQL database. You can read more about the reasoning here.
The result is that people who were using their own Postgres instance that wasn’t part of the Docker Compose or Helm Chart setup were out of luck with this upgrade and would have to figure out how to move forward. They recommended people switch to a new container image tensorchord/pgvecto-rs
as it is a drop in replacement on top of the normal Postgres image but with the extensions needed included. It’s impressive to see a project this big be able to switch something like their database backend and not cause their users any fuss. However I was using the Zalando Postgres Operator which has its own Postgres image called Spilo, so switching away was not so trivial for me.
Zalando is an enterprise-type business and as is customary, can move slowly sometimes. Someone created a feature request to get the vector
extension into Spilo back in July 2023. Then in January 2024 someone brought it up at the operator level and someone responded that support has already been baked into Spilo and that the default image for the operator will be updated in the next release. So it seemed like all the pieces were in place to use the vector
extension it was just a matter of time. I also couldn’t switch to tensorchord/pgvecto-rs
as there are some basic issues preventing high availability like stream replication not working.
I saw someone else mention in the comments of the release that they were also looking for ways forward with their Postgres instances and one person even went so far as to build his own custom container image which can be found here. This was way too much work for me to try and take on at the time so my Immich instance sat on v1.90.2 for a long time, hoping for someone to come along and provide a path forward. Finally I found some time to tackle the issue and I think my solution is worth sharing.
The Solution
This was actually very simple, if the vector
extension was already supported in the newest Spilo image ghcr.io/zalando/spilo-15:3.1-p1
then all I need to do is switch the one deployment over to the latest version. Like so!
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
apiVersion: acid.zalan.do/v1
kind: postgresql
metadata:
labels:
team: acid
name: acid-immich
namespace: immich
spec:
dockerImage: ghcr.io/zalando/spilo-15:3.1-p1
allowedSourceRanges: []
databases:
immich: immich
numberOfInstances: 2
postgresql:
version: '15'
Once I had ensured that my database was running as normal on the new image, I found that in v1.95.0 they introduced compatibility for the vector
extension as opposed to vectors
that is bundled with pgvecto-rs
by adding this environment variables:
1
DB_VECTOR_EXTENSION=pgvector
Then I just had to run the following commands against the database according to the migration documentation:
1
CREATE EXTENSION vector;
That’s it! My terabyte of photos were migrated in about 2 hours and I’m back to the latest version of Immich. Shout out to the team for this amazing project!