Unable To Change Postgres Password
Hi there,
I have been trying to modify the base docker compose file found here so it doesn't rely on a .env file https://immich.app/docs/install/docker-compose/
This provides far more freedom for me to keep things exactly the same across all my docker compose files. I've finally had success with this, however strangely when you try to change the default 'postgres' password the whole thing fails and immich is unable to connect to postgres. I was hoping to work out why?
I've attached a modified immich yaml file (with traefik working in my own setup), the moment you attempt to change the environment variable 'POSTGRES_PASSWORD' immich is unable to connect to postgres. I'll attach exact errors below, thanks!
27 Replies
:wave: Hey @molemanx,
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. :blue_square: 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.Because you're either using a bad password (such as using $ improperly escaped), or you're changing it after you've booted up the initial container, at which point you cant change it like that through the env file
I've tried only letters and numbers as the documentation suggests, sadly it still fails. I've also destroyed the postgres database multiple times so it re-builds from scratch, but still no luck
Are you sure you're using "POSTGRES_PASSWORD" for this?
Because it's "DB_PASSWORD" to be clear
And are you changing the env file or the compose?
Using postgres_password as that's the environment variable, DB password is pulled in from the .env which I've stripped out of the docker compose file
Because your compose has
Which will just make the password 'postgres' regardless of what you do in the env
Yeah sorry I should have been clearer, that's the working docker compose file, my aim is to remove the .env file which I've managed to do other than this small hurdle
You need:
And just use the default env var names
They are also used in the health check for instance
Did yuo change thos as well?
Nope, those work fine because I saw they pull from the environment variables rather than the variables from the .env
I have also managed to get it working by starting the stack with the default varaibles listed in the docker compose file above, then bringing the stack down and at that point swapping the default password out. For some reason, that seems to work?
I'm not 100% convinced it's using the new password I placed into the compose file though
Alright how are you wiping the DB?
Destroying all the files at /var/lib/postgresql/data
I did wonder if that was correct, or if I should be connecting into the container and doing something else?
I'm assuming you're wiping the folder that is defined in the env var. not going into the container and killing the data there?
That's correct, sorry!
Just checking, no need to worry
So in my case the files at $DOCKERDIR/immich/database
Just tried it now by creating a new stack and this works fine 🙃
Hm one second, will see if I can re-create again for good measure
I am using the default compose/env files (minus stack.env because portainer)
The only files I have that I'm keeping are the ones mapped to the upload location, I don't think that should make a difference?
Back to failing sadly
no that shouldn't make a difference for the database
Just tried changing the password back to the default postgres after the above failed attempt, still no luck sadly. So weirdly, creating the container with 'postgres' as the password works, but creating it with a custom password fails, and switching it back to postgres still fails
So I really don't know what password it thinks it's grabbing 😅
Do you reckon the password actually changes away from postgres if I create the container, get it working, then switch the password away from default? That seems to work, but I don't know why, although I don't think I care if someone else agrees the password does actually change
No that shouldn't be possible
It creates it on startup, you'd have to go in the container and change the password with the postgres tools
(and then restart the container so it picks up the new password from env)
Maybe I can try that instead? It would at least change the password away from the default at that point
Should do it I think
exit with
\q
if you're stuck 😛Amazing thank you, whatever the cause of the issue is seems to be down to my setup in some way. I'll make that change in half hour or so, just going to get something to eat
I'll let you know if it works, thanks for your help!
you are wrong in your guess that these work without being set in the compose for immich-server
There are multiple variable scopes in a docker compose file, and for a variable to be visible inside the container it MUST be set with either
env_file:
or environment:
blocks
In order to avoid an env like you are trying, you need to set the POSTGRES_PASSWORD variable for the database container like you did, and the DB_PASSWORD variable in a similar way for the immich-server containerThat looks to have worked, makes sense, so no need to go into the container itself and change the password, thank you!