Postgres Drama
Written by Zackary Frazier, posted on 2024-09-15
- MISC
So I've been working with Spring Boot lately.
One thing I was playing around with was using Spring Boot Docker Compose package to spring up a docker container with Postgres installed, tied to JDBC, to host a database for a hobby for hobby project. This seemed like it should be easy enough. On YouTube I found about a dozen 10 minute videos on how to set this up so I was thinking, "this sounds easy peasy".
I kept getting this super weird error though.
FATAL: Password authentication failed for user "admin"
At first I though, "Okay, maybe a fat-fingered the password somewhere?". Then looking into it what I found is that the password should propagate automatically from the compose.yml file to allow spring boot to connect by default.
What gives?
I added pgadmin (a tool to connect to postgres) to my docker compose file, and after springing up the two containers manually, I found that I had no issues connecting to the database manually.
This was.... odd. I would think if there's an issue with the password being set in the docker container, I wouldn't be able to connect.
Even stranger, after restarting my computer and running the exact same project from IntelliJ the next day, suddenly it just mysteriously worked?
After scouring Reddit for answers, I found this post. I found a lot of confusing answers here. Some suggested editing the "pg_hba.conf" file - still no idea what that is. Others suggested deleting past volumes from the docker containers that have been sprung up in the past. I tried that, no dice.
I couldn't find a solution to the issue anywhere until I found a useful hint. I can't find the original Reddit post but someone had mentioned that they had 3 engineers look into this for a week before discovering the issue was they had a version of Postgres running on their machine, and the error message was drawn from Spring Boot's docker compose package trying to connect to it instead of to the version of Postgres hosted on the docker container sprung up by Spring Boot.
At first of course I thought, "I didn't install Postgres on my machine..." but then it clicked. I did install Postgres... but on WSL. I quickly pulled up the Windows linux terminal and typed in psql --version
and lo and behold there was a Postgres server running 💀.
This tracks too with how I saw the other day that the project was able to build without issues but then on other days it didn't build. On the days it did build, I didn't boot up WSL, so the Postgres server hadn't started. On the days it had built, I did open up WSL at some point, and thus the server was running.
I quickly nuked that installation of Postgres off the face of the Earth, and BOOM! Now my project was building with no problems 😎.