How to connect Datagrip on Ubuntu (WSL) inside Windows

I have installed Ubuntu ecosystem from Microsoft Store ().

After setting up the environment, I installed postgres, which looks ok:

eliya@DESKTOP-LDD0TT1:/mnt/c/Users/Eliya$ sudo -i -u postgres
[sudo] password for eliya:
postgres@DESKTOP-LDD0TT1:~$ psql
psql (10.12 (Ubuntu 10.12-0ubuntu0.18.04.1))
Type "help" for help.
postgres=#

Now, I have on my Windows Datagrip, and I can't figure out how can I connect to psql in my Ubuntu. First I tried to use localhost as my host, but it uses, of course, Windows psql service instead of ubuntu's.

How can I connect Datagrip to my virtual Ubuntu?

1 Answer

To connect to datagrip you need enable connection by TCP/IP to postgres database . To enable that open /etc/postgres/../postgresql.conf and change the line:#listen_addreses = "" to listen_addreses = "*" (remove #, and put * symbol) and save it. Then open pg_hba.conf (that is located in the same path that contains postgresql.conf) WITH sudo and the end of file add next lines to allow all connections (be careful):

host all all 0.0.0.0/0 md5
host all all ::/0 md5

Save it and restart the service: sudo service postgrestql restart. Finally, run netstat -t and copy the localaddress(not the foreign address), example: 172.17.125.13 BUT WITHOUT the port, because you will use the port of postgres database.

Finally use the IP copied in datagrip with the info of database such as username, password, port and database.

Be careful with the port of database that you use, because if you are running postgres on Windows the port 532 is busy and you get an error. If it ocurrs you need use another port, for example 5433 in WSL that you can modify in postgres.conf in the line mention the port 5432 by default.

Hope this can help you!!

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like