You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When run pg_dump and later pg_restore, the restoration process throws an error:
pg_restore: error: COPY failed for table "geodata_places": ERROR: type "earth" does not exist
LINE 1: ...ians($1))*sin(radians($2))),earth()*sin(radians($1)))::earth
^
QUERY: SELECT cube(cube(cube(earth()*cos(radians($1))*cos(radians($2))),earth()*cos(radians($1))*sin(radians($2))),earth()*sin(radians($1)))::earth
CONTEXT: SQL function "ll_to_earth" during inlining
COPY geodata_places, line 1: "3038999 Soldeu 1.66769 42.57688 AD 02 2017-11-06"
pg_restore: warning: errors ignored on restore: 1
Comparing that with our case, it seems pg_dumpall vs pg_dump is the culprit. In Cloudron only pg_dump is performed. Have to see what potential side-effects are to change that.
To add a bit more findings, so adding SET search_path TO "$user",public; (this may vary depending on your setup, it can be fetched in a working instance with SHOW search_path) in the top of the sqldump makes the restore work. I don't have a solution yet on how to make pg_dump do this automatically so one does not have to edit the file for restore.
Just want to add that SET search_path TO "$user",public; is only usable if we dump the database into plain text (sql script). In my case (binary format), it seems there is no way to restore the backup beside converting that binary format to plain text beforehand.
I think it is worth noting that there are two separate things that need to happen:
Schema needs to be re-created and
Data needs to be reloaded
Normally (1) happens via the migrations, which do correctly create the required extensions.
When you run the pg_dump command you have to the option to include only the data, only the schema, or both the schema and the data. The command in the docs exports the schema and the data together. We should maybe update the documentation to instead recommend:
I was able to get immich migrated from one Cloudnative PG cluster to another Cloudnative PG cluster. Here is the method I used:
Shut down Immich to stop writes to the DB
Run the following commands on the existing DB
ALTER EXTENSION cube SET SCHEMA pg_catalog;
ALTER EXTENSION earthdistance SET SCHEMA pg_catalog;
Create the new cluster using the bootstrap initdb method
spec:
instances: 3imageName: ghcr.io/bo0tzz/cnpgvecto.rs:14-v0.1.10 # CNPG compatible image with pgvecto.rs extension installedbootstrap:
initdb:
import:
type: microservicedatabases:
- immichsource:
externalCluster: postgres # name of cluster where existing immich data lives(...)externalClusters:
- name: postgresconnectionParameters:
host: postgres-ro.database.svc.cluster.localuser: postgresdbname: immichpassword:
name: cloudnative-pg-secretkey: password
For me, this created a database in the new cluster called app, owned by app. You could either update your immich HR to point at this new db with the new role, or update the db to fit the existing config (this is the choice I took)
To update the new cluster, perform the following psql commands on the new cluster:
ALTER DATABASE app RENAME TO immich; --or whatever your db name is
CREATE ROLE immich; --or whatever your role is
ALTER ROLE immich WITH LOGIN;
\c immich;
CREATE EXTENSION vectors; --add extension for v1.91.0 release
REASSIGN OWNED BY app TO immich;
Update Immich HR secrets/config to point at the new postgres cluster
For Cloudron we have decided to remove the search_path statement which newer pg_dump versions add to the sqldump. The line which gets added looks like SELECT pg_catalog.set_config('search_path', '', false); and if removed, pg_restore will pick up the default search_path from the main postgres config. This makes the restore work correctly, but given the CVE for this, this is only recommended in a trusted environment.
From our side no immich changes are required then.
So I think we should add a warning in "Backup and restore" section that pg_dump will produce an unusable backup without moving things into pg_catalog or manually editing and then we can close this issue.
For my install i need to use pg_dumpall -c -U postgres | gzip > "./dump.sql.gz" to backup and in new database, use gunzip < "/import/dump.sql.gz" | psql -U postgres -d immich to restore.
and i got same error
ERROR: type "earth" does not exist
LINE 1: ...ians($1))*sin(radians($2))),earth()*sin(radians($1)))::earth
^
QUERY: SELECT cube(cube(cube(earth()*cos(radians($1))*cos(radians($2))),earth()*cos(radians($1))*sin(radians($2))),earth()*sin(radians($1)))::earth
CONTEXT: SQL function "ll_to_earth" during inlining
COPY geodata_places, line 1: "3038999 Soldeu 1.66769 42.57688 AD 02 2017-11-06"
To verify that the change has been successfully applied, grep can be used:
grep "SELECT pg_catalog.set_config" dump.sql
I also tested removing the line altogether as above mentioned, It worked without issues but I was more conformable just leaving it there and adding those 2 schemas.
CREATE INDEX IF NOT EXISTS clip_index ON smart_search
USING vectors (embedding cosine_ops) WITH (options = $$
should be USING public.vectors instead. Although removing SELECT pg_catalog.set_config('search_path', '', false) makes the issue go away, it will be better if we can fix this somehow.
Same error. I am on Immich v1.91.4 and I followed the guide https://immich.app/docs/administration/backup-and-restore almost to the letter. (I had to to do docker-compose up --no-start instead of docker compose create, otherwise the network was not created.)
What procedure can be followed when access to the source database is lost?
The default recommended backup/restore path using pg_dumpall actually works fine (@nebulade)
This was not the case for me. I dumped with the suggested dumpall from version 1.93.3 and used the official restore procedure exactly. I have a very pure docker compose setup, all immich containers, nothing custom. I also restored to 1.93.3. However I still got the error during a restore:
ERROR: type "earth" does not exist
LINE 1: ...ians($1))*sin(radians($2))),earth()*sin(radians($1)))::earth
^
QUERY: SELECT cube(cube(cube(earth()*cos(radians($1))*cos(radians($2))),earth()*cos(radians($1))*sin(radians($2))),earth()*sin(radians($1)))::earth
CONTEXT: SQL function "ll_to_earth" during inlining
COPY geodata_places, line 1: "3038999 Soldeu 1.66769 42.57688 AD 02 2017-11-06"
I haven't found something broken in the restored instance though, should there have been some trouble?
Ran into this using Cloudnative-PG doing a v14 to v16 migration. My Postgres is not dedicated to Immich, I was able to list all databases minus Immich and they all cleanly migrated via Cloudnative-PG bootstrap "monolith" method.
Slightly different steps, but same theme overall:
Step 1 - Create Manual Cluster Database Dump of PG14
Activity
bo0tzz commentedon Dec 11, 2023
Cc @zackpollard
nebulade commentedon Dec 11, 2023
Came to report the same issue, as our Cloudron packaging tests hit this.
nebulade commentedon Dec 11, 2023
To add some more findings, looking at the postgresdump created from the database, it contains the following for earthdistance:
All other occurances of
earthdistanceextension functions are correctly prefixed withpublicit seems.alextran1502 commentedon Dec 11, 2023
@vnghia What Postgres version were you using when perform db_dump and pg_restore?
vnghia commentedon Dec 11, 2023
I'm using 16 but I think other versions are affected as well since
pg_dumpandpg_restoreare version-independent, at least for the SQL dump.alextran1502 commentedon Dec 11, 2023
References
nebulade commentedon Dec 11, 2023
This also happens on postgres 14
alextran1502 commentedon Dec 11, 2023
Does the following guide work?
https://immich.app/docs/administration/backup-and-restore
nebulade commentedon Dec 11, 2023
Comparing that with our case, it seems
pg_dumpallvspg_dumpis the culprit. In Cloudron onlypg_dumpis performed. Have to see what potential side-effects are to change that.ModestTG commentedon Dec 11, 2023
Reporting that streaming data out of Cloudnative PG and into a new cluster also runs into this same issue. Seems to fail on the
pg_restorefunction.My Cloudnative PG cluster config, trying to get data out of a PG14 database into a new cluster that has pgvecto.rs installed by default: https://github.com/ModestTG/jace-cluster/blob/main/kubernetes/apps/database/cloudnative-pg/cluster/cluster2.yaml
nebulade commentedon Dec 11, 2023
To add a bit more findings, so adding
SET search_path TO "$user",public;(this may vary depending on your setup, it can be fetched in a working instance withSHOW search_path) in the top of the sqldump makes the restore work. I don't have a solution yet on how to makepg_dumpdo this automatically so one does not have to edit the file for restore.This behavior to unset
search_pathis part of https://www.postgresql.org/docs/release/10.3/I guess the question is, why this
ll_to_earth()usesearth()without prefix, but I am really not a postgres extension expert :/vnghia commentedon Dec 11, 2023
Just want to add that
SET search_path TO "$user",public;is only usable if we dump the database into plain text (sql script). In my case (binary format), it seems there is no way to restore the backup beside converting that binary format to plain text beforehand.jrasm91 commentedon Dec 11, 2023
I think it is worth noting that there are two separate things that need to happen:
Normally (1) happens via the migrations, which do correctly create the required extensions.
When you run the pg_dump command you have to the option to include only the data, only the schema, or both the schema and the data. The command in the docs exports the schema and the data together. We should maybe update the documentation to instead recommend:
9 remaining items
ModestTG commentedon Dec 13, 2023
I was able to get immich migrated from one Cloudnative PG cluster to another Cloudnative PG cluster. Here is the method I used:
app, owned byapp. You could either update your immich HR to point at this new db with the new role, or update the db to fit the existing config (this is the choice I took)nebulade commentedon Dec 13, 2023
For Cloudron we have decided to remove the
search_pathstatement which newerpg_dumpversions add to the sqldump. The line which gets added looks likeSELECT pg_catalog.set_config('search_path', '', false);and if removed,pg_restorewill pick up the defaultsearch_pathfrom the main postgres config. This makes the restore work correctly, but given the CVE for this, this is only recommended in a trusted environment.From our side no immich changes are required then.
vnghia commentedon Dec 13, 2023
So I think we should add a warning in "Backup and restore" section that
pg_dumpwill produce an unusable backup without moving things intopg_catalogor manually editing and then we can close this issue.vnwnv commentedon Dec 21, 2023
I'm testing disaster recovery, and I met same problem when using
pg_dumpall,I'm using the postgres 15 from debian and immich v1.90.2
backup and restore like this
alextran1502 commentedon Dec 21, 2023
@wlmqpsc Please try to follow the guide here https://immich.app/docs/administration/backup-and-restore/
vnwnv commentedon Dec 21, 2023
OK. I tried this. @alextran1502
For my install i need to use
pg_dumpall -c -U postgres | gzip > "./dump.sql.gz"to backup and in new database, usegunzip < "/import/dump.sql.gz" | psql -U postgres -d immichto restore.and i got same error
vktr2b commentedon Dec 21, 2023
I've also encountered this issue but I've solved it by changing this line in my
dump.sqlso it uses both search_paths not just the default one.changed to
This
sedcommand sets search path to includes both thepublicschema and thepg_catalogschema, preventing the issue occurring when importingsed -i "s/SELECT pg_catalog.set_config('search_path', '', false);/SELECT pg_catalog.set_config('search_path', 'public, pg_catalog', true);/g" dump.sqlTo verify that the change has been successfully applied,
grepcan be used:grep "SELECT pg_catalog.set_config" dump.sqlI also tested removing the line altogether as above mentioned, It worked without issues but I was more conformable just leaving it there and adding those 2 schemas.
vnghia commentedon Dec 26, 2023
I got similar error while trying to restore the backup made with
1.91.1, these linesimmich/server/src/infra/migrations/1700714033632-AddFaceEmbeddingIndex.ts
Lines 8 to 9 in 1d0dbdf
and
immich/server/src/infra/migrations/1700713994428-AddCLIPEmbeddingIndex.ts
Lines 8 to 9 in 1d0dbdf
should be
USING public.vectorsinstead. Although removingSELECT pg_catalog.set_config('search_path', '', false)makes the issue go away, it will be better if we can fix this somehow./cc @jrasm91
erikvanoosten commentedon Dec 29, 2023
Same error. I am on Immich v1.91.4 and I followed the guide https://immich.app/docs/administration/backup-and-restore almost to the letter. (I had to to do
docker-compose up --no-startinstead ofdocker compose create, otherwise the network was not created.)What procedure can be followed when access to the source database is lost?
erikvanoosten commentedon Dec 29, 2023
With the sed command, suggested by #5630 (comment) this works:
Change
to:
Zakmaf commentedon Jan 16, 2024
Thank you so much @erikvanoosten, your solution worked for right away.
bjrne commentedon Feb 4, 2024
This was not the case for me. I dumped with the suggested
dumpallfrom version 1.93.3 and used the official restore procedure exactly. I have a very pure docker compose setup, all immich containers, nothing custom. I also restored to 1.93.3. However I still got the error during a restore:I haven't found something broken in the restored instance though, should there have been some trouble?
reefland commentedon Feb 9, 2024
Ran into this using Cloudnative-PG doing a v14 to v16 migration. My Postgres is not dedicated to Immich, I was able to list all databases minus Immich and they all cleanly migrated via Cloudnative-PG bootstrap "monolith" method.
Slightly different steps, but same theme overall:
Step 1 - Create Manual Cluster Database Dump of PG14
Step 2 - Use Script to Extract Immich Database from the dumpall file
https://nicolaiarocci.com/how-to-restore-a-single-postgres-database-from-a-pg_dumpall-dump/
Simple script:
Used as:
Step 3 - Fix Search Path:
sedstep in script aboveimmich.dumpSELECT pg_catalog.set_config(About line 8)Step 4 - Manually create Immich database and extensions as others documented.
Step 5 - Import Immich Dump File:
GPASSWORDis the password of theappuser/role.-his the host name, in this case IP address of new PG cluster load balancer-dpoints toimmichdatabase-Upoints to the user/role ofappThis imported cleanly with no SQL Errors.