Database Migration Error with v1.136.0
I'm encountering a database migration error when upgrading to Immich v1.136.0. The server container continually restart due to a failed migration.
Error Details:
The migration "1752267649968-StandardizeNames" fails with:
PostgresError: relation "session" already exists sql: 'ALTER TABLE "sessions" RENAME TO "session"'
My Environment:
- Immich version: 1.136.0
- Deployment method: Docker Compose
- Database: PostgreSQL (
Steps I've Already Tried:
1. Examined both tables:
-
sessions appears to be the main sessions table with user data
- session was a simple key-value table with only 3 columns (key, data, expiry)
2. Backed up and dropped the session table manually in PostgreSQL
3. Restarted containers, but the migration still fails with the same error
My docker-compose configuration:
```yaml
services:
immich-server:
container_name: immich_server
image: ghcr.io/immich-app/immich-server:${IMMICH_VERSION:-release}
environment:
DB_HOSTNAME: immich_postgres
DB_PASSWORD: ${IMMICH_DB_PASSWORD}
DB_USERNAME: postgres
DB_DATABASE_NAME: immich
postgres: postgres
immich: immich
REDIS_HOSTNAME: immich_redis
volumes:
- ${IMMICH_UPLOAD_LOCATION}:/usr/src/app/upload
- /etc/localtime:/etc/localtime:ro
depends_on:
- immich-redis
- immich-database
restart: always
immich-database:
container_name: immich_postgres
image: ghcr.io/immich-app/postgres:14-vectorchord0.3.0-pgvectors0.2.0
environment:
DB_HOSTNAME: immich_postgres
POSTGRES_PASSWORD: ${IMMICH_DB_PASSWORD}
POSTGRES_USER: postgres
POSTGRES_DB: immich
POSTGRES_INITDB_ARGS: '--data-checksums'
DB_STORAGE_TYPE: 'HDD'
volumes:
- ${CONFIG_ROOT:-.}/immich/postgresql:/var/lib/postgresql/data
restart: always
profiles:
- immich24 Replies
:wave: Hey @cambelau,
Thanks for reaching out to us. Please carefully read this message and follow the recommended actions. This will help us be more effective in our support effort and leave more time for building Immich :immich:.
References
- Container Logs:
docker compose logs docs
- Container Status: docker ps -a docs
- Reverse Proxy: https://immich.app/docs/administration/reverse-proxy
- Code Formatting https://support.discord.com/hc/en-us/articles/210298617-Markdown-Text-101-Chat-Formatting-Bold-Italic-Underline#h_01GY0DAKGXDEHE263BCAYEGFJA
Checklist
I have...
1. :ballot_box_with_check: verified I'm on the latest release(note that mobile app releases may take some time).
2. :blue_square: read applicable release notes.
3. :blue_square: reviewed the FAQs for known issues.
4. :blue_square: reviewed Github for known issues.
5. :blue_square: tried accessing Immich via local ip (without a custom reverse proxy).
6. :blue_square: uploaded the relevant information (see below).
7. :blue_square: tried an incognito window, disabled extensions, cleared mobile app cache, logged out and back in, different browsers, etc. as applicable
(an item can be marked as "complete" by reacting with the appropriate number)
Information
In order to be able to effectively help you, we need you to provide clear information to show what the problem is. The exact details needed vary per case, but here is a list of things to consider:
- Your docker-compose.yml and .env files.
- Logs from all the containers and their status (see above).
- All the troubleshooting steps you've tried so far.
- Any recent changes you've made to Immich or your system.
- Details about your system (both software/OS and hardware).
- Details about your storage (filesystems, type of disks, output of commands like fdisk -l and df -h).
- The version of the Immich server, mobile app, and other relevant pieces.
- Any other information that you think might be relevant.
Please paste files and logs with proper code formatting, and especially avoid blurry screenshots.
Without the right information we can't work out what the problem is. Help us help you ;)
If this ticket can be closed you can use the /close command, and re-open it later if needed.
Successfully submitted, a tag has been added to inform contributors. :white_check_mark:Thanks to everyone who will take time to help me !
Hey @cambelau
Backed up and dropped the session table manually in PostgreSQLCould you share that backup or simply post
select * from session limit 3; ?Session table is not created, so i cannot query it.
The sessions table have those row (i replaced some field for safety)
From logs i can see that i have different errors at each restart :
PostgresError: relation "session" already exists
microservices worker error: PostgresError: relation "session" already exists, stack: PostgresError: relation "session" already exists
error: PostgresError: relation "user" already exists
PostgresError: relation "user" already exists
microservices worker error: PostgresError: relation "user" already exists, stack: PostgresError: relation "user" already exists
Both in the same migration job Migration "1752267649968-StandardizeNames"Interesting, so it complains about more than 1 table already existing...
1. Could you post your DB migration history and update history by querying the database:
2. Do you still have logs from the first upgrade attempt in
docker compose logs? Right after you changed to / pulled new version and did "compose up".
Would be nice to view them.
If they are already gone, then please post logs from one of restarts/attempts.
2.1. You can increase logging verbosity, it could be helpful, https://immich.app/docs/install/environment-variables/#general
3. Regarding session
Examined both tables: sessions appears to be the main sessions table with user data session was a simple key-value table with only 3 columns (key, data, expiry)So
session table existed at some point, then you dropped it, then on subsequent upgrade attempts:
>Session table is not created
right?I joined logs from the start and the restart, and the version-history (that looks good i think)
I dont have the first upgrade attempt sadly :/
Yes regarding session its what happened and the actual state of both table is this one :
I assume the
user table is not present either when you check it with \d user, right?
Would you like to dig deeper and enable verbose logging and DB query log? To understand how it encounters duplicate tables, this must be happening in a transaction because there are no traces in the database afterwards.
Below is step-by-step guide.
1. Enable extra logging
Use the attached file with extra log settings.
Add it as docker-compose.override.yml or compose.override.yaml depending on the main compose yml name.
Alternatively, incorporate its content/settings into your existing compose file.
2. Prepare
2.1. Stop and pull.
2.2 Show config.
2.3. Start DB and show tables.
3. Start Immich server
Wait for it to stop after failed migrations.
4. Grab info
4.1. Show tables once more.
4.2. Grab full verbose logs.
Post all 3 out-*.txt files.
PS. I've noticed there is profiles key in your compose, so the commands may need to be adjusted accordingly.Compose override with extra logging
Here are the 3 files :
Thanks a lot, I will have a look.
session_old - what's there, do you have an idea what is it, a copy of session?I backed up the sessions table one time before trying to delete it
Thank you for helping me
Could you
select * from ... limit 3 a few lines from session_old and from user? I'm wondering what process created them - the DB migration or smth else.
Two user(s) tables coexist currently:
Maybe you fixed session and now only user remains unfixed, can you do the same to user?session_old is empty
user is very strange its contains this
users contains my correct users
Yeah, strange. They both definitely do not belong to Immich database schema.
Could you also check their definitions?
Does Grafana ring a bell?
https://gist.github.com/magikid/06850c081f14dd5e5f4be4dc93d9b285#file-grafana-sql-L1073-L1078
Also Gitea overlaps pretty much with
out-tables1.txt https://github.com/go-gitea/gitea/tree/main/models/repo
- attachment, collaboration, pushmirror/push_mirror, language_stat, ...
Could it be that the same DB was used by
- Immich
- Grafana
- Gitea
?I have a Gitea stack deployed on the same machine but it use another container postgres and should not be related to the immich one
And no Grafana in the stack
I see.
user table is also from Gitea https://github.com/go-gitea/gitea/blob/84d31bc842be9ef74c4da7b6875f604afd286a51/models/user/user.go#L79-L152
session is quite similar too https://github.com/go-gitea/gitea/blob/84d31bc842be9ef74c4da7b6875f604afd286a51/models/auth/session.go#L17-L21So you mean my database is corrupted with some table of gitea ?
Kind of... infiltrated )
If you remove/rename
user it will allow Immich to proceed with renaming its own tablesHello @Sergey Katsubo, I had a little time to try it out, and sure enough, it was the user table that was causing the problem. Deleting it worked!
Thank you so much for your help !