I
Immich•5mo ago
molemanx

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
Immich
Immich•5mo ago
: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.
Mraedis
Mraedis•5mo ago
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
molemanx
molemanxOP•5mo ago
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
Mraedis
Mraedis•5mo ago
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?
molemanx
molemanxOP•5mo ago
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
Mraedis
Mraedis•5mo ago
Because your compose has
environment:
POSTGRES_PASSWORD: postgres
environment:
POSTGRES_PASSWORD: postgres
Which will just make the password 'postgres' regardless of what you do in the env
molemanx
molemanxOP•5mo ago
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
Mraedis
Mraedis•5mo ago
You need:
environment:
POSTGRES_PASSWORD: ${DB_PASSWORD}
POSTGRES_USER: ${DB_USERNAME}
POSTGRES_DB: ${DB_DATABASE_NAME}
environment:
POSTGRES_PASSWORD: ${DB_PASSWORD}
POSTGRES_USER: ${DB_USERNAME}
POSTGRES_DB: ${DB_DATABASE_NAME}
And just use the default env var names They are also used in the health check for instance Did yuo change thos as well?
molemanx
molemanxOP•5mo ago
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
Mraedis
Mraedis•5mo ago
Alright how are you wiping the DB?
molemanx
molemanxOP•5mo ago
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?
Mraedis
Mraedis•5mo ago
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?
molemanx
molemanxOP•5mo ago
That's correct, sorry!
Mraedis
Mraedis•5mo ago
Just checking, no need to worry
molemanx
molemanxOP•5mo ago
So in my case the files at $DOCKERDIR/immich/database
Mraedis
Mraedis•5mo ago
Just tried it now by creating a new stack and this works fine 🙃
molemanx
molemanxOP•5mo ago
Hm one second, will see if I can re-create again for good measure
Mraedis
Mraedis•5mo ago
I am using the default compose/env files (minus stack.env because portainer)
molemanx
molemanxOP•5mo ago
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
[Nest] 17 - 12/27/2024, 1:09:43 PM ERROR [ExceptionHandler] password authentication failed for user "postgres"
error: password authentication failed for user "postgres"
at Parser.parseErrorMessage (/usr/src/app/node_modules/pg-protocol/dist/parser.js:283:98)
at Parser.handlePacket (/usr/src/app/node_modules/pg-protocol/dist/parser.js:122:29)
at Parser.parse (/usr/src/app/node_modules/pg-protocol/dist/parser.js:35:38)
at Socket.<anonymous> (/usr/src/app/node_modules/pg-protocol/dist/index.js:11:42)
at Socket.emit (node:events:524:28)
at addChunk (node:internal/streams/readable:561:12)
at readableAddChunkPushByteMode (node:internal/streams/readable:512:3)
at Readable.push (node:internal/streams/readable:392:5)
at TCP.onStreamRead (node:internal/stream_base_commons:189:23)
microservices worker exited with code 1
Killing api process
[Nest] 17 - 12/27/2024, 1:09:43 PM ERROR [ExceptionHandler] password authentication failed for user "postgres"
error: password authentication failed for user "postgres"
at Parser.parseErrorMessage (/usr/src/app/node_modules/pg-protocol/dist/parser.js:283:98)
at Parser.handlePacket (/usr/src/app/node_modules/pg-protocol/dist/parser.js:122:29)
at Parser.parse (/usr/src/app/node_modules/pg-protocol/dist/parser.js:35:38)
at Socket.<anonymous> (/usr/src/app/node_modules/pg-protocol/dist/index.js:11:42)
at Socket.emit (node:events:524:28)
at addChunk (node:internal/streams/readable:561:12)
at readableAddChunkPushByteMode (node:internal/streams/readable:512:3)
at Readable.push (node:internal/streams/readable:392:5)
at TCP.onStreamRead (node:internal/stream_base_commons:189:23)
microservices worker exited with code 1
Killing api process
Mraedis
Mraedis•5mo ago
no that shouldn't make a difference for the database
molemanx
molemanxOP•5mo ago
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
Mraedis
Mraedis•5mo ago
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)
molemanx
molemanxOP•5mo ago
Maybe I can try that instead? It would at least change the password away from the default at that point
Mraedis
Mraedis•5mo ago
docker exec -it immich_postgres psql -U postgres
ALTER USER postgres WITH PASSWORD 'new_password';
docker exec -it immich_postgres psql -U postgres
ALTER USER postgres WITH PASSWORD 'new_password';
Should do it I think exit with \q if you're stuck 😛
molemanx
molemanxOP•5mo ago
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!
Zeus
Zeus•5mo ago
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 container
molemanx
molemanxOP•5mo ago
That looks to have worked, makes sense, so no need to go into the container itself and change the password, thank you!

Did you find this page helpful?