#QueryFailedError: relation "migrations" already exists

1 messages · Page 1 of 1 (latest)

ruby trout
#

I want to migrate from docker to k8s (on TrueNas via Truecharts). I took a backup as described in the docs. But after restoring I got an error while starting the immich pod. Any Idea?

green thistle
#

The immich server initializes the db on its first startup, so you have to first start the db, restore your backup and then start the other containers.

#

Otherwise, the backup will conflict with the newly initialized objects in the db.

ruby trout
#

I'm pretty sure I done this that way. But I will do it again 🙂

loud brook
ruby trout
#

I could not use pg_dumpall because of k8s. So I just dumped only the immich database. But this should work as well, right?

loud brook
#

that's ok

#

for the restore make sure you specify the target database --dbname=immich

ruby trout
#

Yes.

ruby trout
#

Will I break anything, when I only restore the database, but not the images (i will do this later)?

loud brook
#

it shouldn't break anything

ruby trout
#

nice thx

loud brook
#

I mean, don't delete the backup lol

#

but it should be fine

ruby trout
#

Does not work. Same error again 😦

loud brook
#

please send over the exact commands you are running

ruby trout
#

postgres@red bolt-cnpg-main-1:~/data$ gunzip < immich.sql.gz | sed "s/SELECT pg_catalog.set_config('search_path', '', false);/SELECT pg_catalog.set_config('search_path', 'public, pg_catalog', true);/g" | psql --username=postgres --dbname immich

#

for backup

docker exec -t immich_postgres pg_dump --clean --if-exists --username=postgres immich | gzip > "immich.sql.gz"

loud brook
#

Ok, let's start over, reset everything and before you run the gunzip you should shell into the database using psql immich and run \d+

ruby trout
#

sure.. just a sec

loud brook
#

let me know what that shows

ruby trout
loud brook
#

and to be safe can you do \l+

ruby trout
loud brook
#

Ok. now try the gunzip

#

then show me those \d+ and \l+ commands again

ruby trout
loud brook
#

That looks fine. At this point you should be able to start up Immich

ruby trout
#

nope 😄

loud brook
#

If you restart Immich one more time, does it still log that error?

#

and/or does Immich actually work?

#

I don't think migrations is not the first table to be created, so I wonder if there's a first run script that is trying to create it for some reason

#

actually it looks like it's a crash loop isn't it

ruby trout
#

No Endpoint, so no service & no webgui

#

Yes. k8s restarts the pod every n seconds

loud brook
#

I think it might be a permissions issue.. let's try doing a re restore but use the command: psql --dbname=immich --username=immich

#

This might be because you are not using pg_dumpall

ruby trout
#

ok. lets do it again 😄

loud brook
#

Sorry! Tricky situation. The restore commands are based on pg_dumpall which contains more permissions

#

pg_dump is just rows and tables I think

ruby trout
#

Yes used pg_dumpall before. It works, but is more tricky because I need to reset the password. But I ended up with the exact same error

#

But lets do it again 🙂

loud brook
#

surprised pg_dumpall had the same error.. hmm. I hope this helps

ruby trout
#

Could this happend because my old immich version was not up2date but the newone is?

loud brook
#

How much not up to date? It could yes

ruby trout
#

Can I check this in my db dump?

#

Because my old docker instance is offline

ruby trout
loud brook
#

It’s not obviously stored in the DB. can you check the DB dump for any lines containing the word OWNER?

#

Also are any errors printed when you do the restore? Can you post the output of the restore command from the first way of doing it as username=postgres

ruby trout
#

This looks wrong, right? This should be owned by user immich

#

because docker uses the postgres user, but truecharts uses an extra user?

loud brook
#

Docker does not use the Postgres user, it uses an Immich user

#

Either way, your previous backup is quite odd

#

I recommend doing the restore, like it worked before, then run all those lines but change it to immich

ruby trout
loud brook
#

Actually, a few of those should stay as Postgres.. give me a few minutes to check which ones

ruby trout
#

ok

loud brook
#

Are you using this DB for anything else?

ruby trout
#

no

loud brook
#

Then it should be fine to own all them to immich

ruby trout
#

uhhh, new error

lets restart postgres...

loud brook
#

Bottom of this page

ruby trout
#

Problems with k8s... it takes some time..

#

YES! Thank you so much! ❤️

loud brook
#

Great! Really weird issue. Not sure how that happened

#

Please keep a record of the tables you owned to immich. In case there is an issue down the line you will know what to change back

green thistle
loud brook
#

I think this is the only thing that would conflict if we changed the owner

#

I'm honestly surprised that ALTER DEFAULT seemed to not work - baffles me (though it wasn't run in this case)

green thistle
#

Yeah, I have no clue why that doesn’t work. I’d be interested to see if 0.2.1 behaves any differently here

#

We could update the default to that if so

loud brook
#

Wait, I think I'm dumb. Schemas in postgres are a subset of databases, right?

#

For example if I do \dn+ in the postgres database I only see the public schema, but in the immich DB I see the vectors schema

#

So maybe we can just to alter owner...... I actually have two instances of Immich in my database so I will do some testing

#

I just did ALTER SCHEMA vectors OWNER TO... and ALTER TABLE pg_vector_index_stat OWNER TO... and both Immich instances are running fine

#

If we alter the schema owner first, the table owner will inherit, yes?

ruby trout
#

I have nearly no knowledge about pg :/ So I can't help you there