<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Jay Kamkru</title>
    <description>The latest articles on Forem by Jay Kamkru (@jaykape).</description>
    <link>https://forem.com/jaykape</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3471679%2F65c0d682-268b-40a9-a6e6-5b54b375b6c1.jpg</url>
      <title>Forem: Jay Kamkru</title>
      <link>https://forem.com/jaykape</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/jaykape"/>
    <language>en</language>
    <item>
      <title>The Long Hunt for a Dockerized PostgreSQL Connection</title>
      <dc:creator>Jay Kamkru</dc:creator>
      <pubDate>Sun, 31 Aug 2025 19:29:02 +0000</pubDate>
      <link>https://forem.com/jaykape/the-long-hunt-for-a-dockerized-postgresql-connection-kon</link>
      <guid>https://forem.com/jaykape/the-long-hunt-for-a-dockerized-postgresql-connection-kon</guid>
      <description>&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;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:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5ayh3rfaebdzbglmle59.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5ayh3rfaebdzbglmle59.png" alt="error" width="800" height="375"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I logged into the container manually with &lt;code&gt;psql -U root -d mydb&lt;/code&gt;&lt;br&gt;
Inside, I could connect without issue. &lt;/p&gt;

&lt;p&gt;It worked inside, but not from the outside??&lt;br&gt;
This give me so much confusion.&lt;/p&gt;

&lt;p&gt;I tried with some of ChatGPT suggestions:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Recreating the container from scratch multiple times&lt;br&gt;
(Thought that is about persisting volume).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Resetting passwords with &lt;code&gt;ALTER USER ... WITH ENCRYPTED PASSWORD&lt;/code&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Editing &lt;code&gt;pg_hba.conf&lt;/code&gt; to allow all authentication methods (trust, md5, scram-sha-256).&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;and so on.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Nothing worked.&lt;/strong&gt; Each attempt brought new hope, only to crash with the same authentication error.&lt;/p&gt;

&lt;p&gt;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? &lt;/p&gt;

&lt;p&gt;...wait... or it is already running and using the same port!?&lt;br&gt;
This will be much make sense since the error suggest that the connection have reached postgres but authentication just fail.&lt;br&gt;
That's because the native postgres didnt use the same username and password!&lt;/p&gt;

&lt;p&gt;I quickly open the shell to investigate what was actually listening on port 5432:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fw34ra8tj471qa3xerrfd.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fw34ra8tj471qa3xerrfd.png" alt="two processes on the same port" width="800" height="159"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;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!!&lt;/p&gt;

&lt;p&gt;I laughed, but mostly felt this incredible rush of relief. Hours of frustration condensed into a single, beautiful realization.&lt;/p&gt;

</description>
      <category>postgres</category>
      <category>docker</category>
    </item>
  </channel>
</rss>
