DataGrip Cannot Connect to Local PostgreSQL Running in Docker Desktop for Windows with WSL2 Backend

Hello everyone! I think the title says it all.

I have Docker Desktop installed on windows 10. It uses WSL2 back-end. I have 3 databases running on docker. One Mongo, One Clickhouse, and one PostgreSQL. DataGrip can easily connect to the Clickhouse on localhost:8123, and also to the Mongo on localhost:27017 but for some reason it cannot connect to the PostgreSQL running on 5432.

The peculiar thing about this is that pgAdmin can connect to the PostgreSQL on localhost:5432.

Please bear in mind that DataGrip can easily connect to the two other containers in this docker-compose file.

For your info, this is my docker compose, which I use to run the three containers:

version: "3.9"
image: postgres:15.1-alpine
restart: on-failure
- "5432:5432"
- fpm_pg:/var/lib/postgresql/data
- POSTGRES_USER=postgres

image: "mongo:latest"
- "27017:27017"
- .env
restart: "no"

image: "clickhouse/clickhouse-server"
- "8123:8123"
- "9000:9000"
- "9004:9004"
- postgres
- .env
restart: "no"

driver: local

Has anyone encountered this?

I also cannot establish this connection from within "Goland", which was the first thing I tried.

I did read this: 

But it does not help.

Any help is appreciated.


Hi mostafa.zeinali ,

To better understand your incident, we need you to collect the logs from Help - Collect Logs and Diagnostic Data and upload it onto our FTP server:

Provide the upload id. We'll have a look and get back to you.


Upload id: 2023_01_15_6szwKj3xrvXH1XiMCce7WJ (file:


OK. I solved it. After reading the log file myself, I noticed that it's a socket exception which led me to believe that there's something wrong with the port 5432. I still maintain that because pgAdmin could connect to that DB, DataGrip should have been able to do the same, but let's go down the rabbit hole shall we?

I inspected the ports using:

netstat -an | findstr 5432

which showed me that even when the DB container is not running and even Docker itself is closed, something is listening on 5432.

I used

netstat -aon | findstr 5432

I found out that a PID:4846 is running on 5432. Going into TaskManager>Details, finding PID 4846 led me to find out that "Windows IP Helper service" is listening on this port. A quick search led me to this answer:

And I also remembered that for a previous project on an older version of docker in WSL2 which had a lot of problems forwarding ports, I had used port forwarding on this port. So, a quick:

netsh interface portproxy show all
netsh interface portproxy delete v4tov4 listenport=5432 listenaddress=
netsh interface portproxy delete v4tov4 listenport=5432 listenaddress=

solved the issue.

Now, I should again stress, that for some reason, pgAdmin didn't ahve any problem with the port forwarding and could connect to the DB with no problem, which led me to believe the port and connection should be fine. Hope this helps someone in the future. 




So, now that this is solved, my only feedback is, a better error message could have solved this for me 2 weeks ago. The original exception was "SocketException", but the error message did not contain anything about socket. You know the people using your IDEs are "developers"! You don't need to protect me from the scary stack trace!

BTW, this is the original error message:

DBMS: Case sensitivity: plain=mixed,
Driver: (ver. , JDBC)
Effective version: PostgreSQL (ver. 0.0)
The connection attempt failed.

Thanks for your feedback.

The error mentioned in your earlier message is usually shown in the UI:

DBMS: Case sensitivity: plain=mixed,
Driver: (ver. , JDBC)
Effective version: PostgreSQL (ver. 0.0)
The connection attempt failed.

If you're looking for a more detailed error message, incl the stack trace, you can look into idea.log in Help - Show Log in Files.

When you're getting the following exception after making a connection attempt:

2023-01-14 12:14:19,273 [ 58076] INFO - #c.i.d.d.DatabaseCredentialsAuthProvider - Connecting as: postgres
2023-01-14 12:14:40,425 [ 79228] WARN - #c.i.d.d.BaseDatabaseErrorHandler$IOErrorInfo - Connection reset Connection reset

It's clearly indicating a connectivity issue. We do also have a troubleshooting guide for such incidents:

But hey, glad you got it working.


Mostafa's solution helped me figure out why I could not connect to a database with Datagrip on Windows after I had already tried using the troubleshooting guide from here:

Maybe some parts of Mostafa's solution could be added to the troubleshooting guide? 

I could not connect to my database from Datagrip on Windows. It was working fine via JetBrains Gateway from a WSL PyCharm project. But it was not working from Datagrip running on Windows.

The parts that helped me find a solution (paraphrased) were:

If the connection is refused then there might be another process running on that port.

Shutdown the database and use netstat in Powershell to see if something else is running on the port (in my case 8123 for Clickhouse)

>> netstat -aon | findstr 8123

TCP               LISTENING       4952

Then go into TaskManager>Details to see if another process is using that port

My solution was to use a different port for the database (I was port-forwarding from remote to localhost).


I'm happy this helped someone :3


Please sign in to leave a comment.