Postgres errors when restoring
I am testing my backups and am seeing a new error. The restore itself seems to be working, but I'm unsure what is leading to this error.
Error message (appears twice as postgres is being restored):
Command used to backup:
docker exec -t immich_postgres pg_dumpall -c -U postgres > /path/to/database-backup/immich-database.sql
Command used to restore:
cat /path/to/database-backup/immich-database.sql | sed "s/SELECT pg_catalog.set_config('search_path', '', false);/SELECT pg_catalog.set_config('search_path', 'public, pg_catalog', true);/g" | docker exec -i immich_postgres psql --dbname=postgres --username=postgres
Relevant history:
- This installation has been up for a very long time - about two years.
- It went through the pgvector to pgvecto.rs breaking change, etc.
- I restored from a backup a few months back and re-initialized the db to use data checksums. There were no errors at the time. No changes have been made to the compose file since.20 Replies
:wave: Hey @emielregis,
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. :ballot_box_with_check: read applicable release notes.
3. :ballot_box_with_check: reviewed the FAQs for known issues.
4. :ballot_box_with_check: reviewed Github for known issues.
5. :ballot_box_with_check: tried accessing Immich via local ip (without a custom reverse proxy).
6. :ballot_box_with_check: uploaded the relevant information (see below).
7. :ballot_box_with_check: 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.Docker Compose file:
.env file:
What database are you on and what kind of mount / device is the database on?
Can you run these?
https://immich.app/docs/FAQ/#how-can-i-verify-the-integrity-of-my-database
I think I’ve seen this though
https://github.com/immich-app/immich/issues/11949
Postgres version is
docker.io/tensorchord/pgvecto-rs:pg14-v0.2.0
The database and backup both live in local btrfs filesystems.
There are no checksum errors.
Yeah, I saw this. There wasn't a resolution on the GitHub thread. Again, the restore seems to have worked, but I'm concerned there may be issues down the line that I may be missing at the moment.Successfully submitted, a tag has been added to inform contributors. :white_check_mark:
Mert suggested replacing
\r\r\n
with \n
but it did not get rid of the error message either. Here is the command I tried:
Note the additional pipe to sed: sed "s.\\r\\r\\n.\\n.g"
I think your sed is broken
if you use double quotes I think you would have to quadruple escape the backslash because both bash and sed will remove a layer
Sorry, my bad; I did catch that. I was aware that you have to use single quotes with sed if using
sed 's...g'
syntax. I did use a broken 'sed' the first time, and copied the wrong command from my bash history here. Sorry about the confusion.
Anyway, I used the command you suggested above and still got the error.
What’s the new error?
The same one, somehow.
Your sed is still broken then
I recommend removing the docker exec and work with the raw database output until it’s working
Do you mean map the folder containing the dump to the docker container, then execute
cat dump.sql | sed <stuff> | psql --dbname=postgres --username=postgres
?
I can try that.
Did not work. I tried this from within the container
Same error.
My bad. You probably meant to ask me to inspect the stream going to the docker exec command to figure out the correct sed
. I'll give it a try.It may be possible to edit the raw dump but I think this is risky
I am just testing my backups on a different Linux machine, so the real risk is minimal tbh. I think I'll edit the dump directly if needed.
It's clearly these two lines in the dump that's causing the issues. I'll continue investigating this tomorrow.
Oh, it’s a true carriage return not a backslash followed by an r
You probably need to remove one layer of backslashes from the single quote sed, then
It was indeed some shenanigans with carriage return and newline, though I'm not quite sure what exactly. Here is the command that worked.
Note the pipe to
dos2unix
I don’t see why you would need dos2unix if this was all on Linux
I’m concerned that may affect other rows
As it will affect much more than just the target
You're right, using dos2unix is probably not a great workaround to fix just two instances of rogue carriage returns. Hopefully this bug can be tracked down and the root cause can be fixed eventually.
The correct sed is
sed 's/\r\r$//g'
The restore command would be: