I’ve spent hours wrestling with Docker, PostgreSQL, and Python. What I thought would be a simple setup turned into a frustration, false leads, and dead ends.
It all started when I tried to connect postgres container with jupyter notebook. I had set up the container, defined my root user and database, and even verified the password. But every single attempt in Python ended with:
I logged into the container manually with psql -U root -d mydb
Inside, I could connect without issue.
It worked inside, but not from the outside??
This give me so much confusion.
I tried with some of ChatGPT suggestions:
Recreating the container from scratch multiple times
(Thought that is about persisting volume).Resetting passwords with
ALTER USER ... WITH ENCRYPTED PASSWORD
.Editing
pg_hba.conf
to allow all authentication methods (trust, md5, scram-sha-256).
and so on.
Nothing worked. Each attempt brought new hope, only to crash with the same authentication error.
An Hour of Trial and Error... I gave up and think, may be running native postgres without using Docker may not have the same problem. But had I downloaded native version before?
...wait... or it is already running and using the same port!?
This will be much make sense since the error suggest that the connection have reached postgres but authentication just fail.
That's because the native postgres didnt use the same username and password!
I quickly open the shell to investigate what was actually listening on port 5432:
Suddenly, it clicked!! There are indeed two processes (PID 7416 and 7356) listening on the port 5432 and Python on my host machine was connecting to the wrong Postgres the whole time!!
I laughed, but mostly felt this incredible rush of relief. Hours of frustration condensed into a single, beautiful realization.
Top comments (0)