DEV Community

Kshitij Raj Sharma
Kshitij Raj Sharma

Posted on

Share Postgresql from Windows to WSL Linux

Hi , I am writting this short tutorial about how to share your current postgresql with postgis extension installed in your windows system with WSL. We will use networking share method.
For me , I needed to Install postgersql on my harddisk and I had it already before installing WSL and in need of sharing . I am documenting the steps you can take if you wanna download and install it in windows

  • Install and remember your postgresql and postgis version

I followed graphical installation method to install postgis postgresql bundle in my windows
Download the Installer :
https://www.enterprisedb.com/downloads/postgres-postgresql-downloads
Installing postgresql 15 in my case

  • Install Postgis extension from stack builder

You can follow this awesome tutorial in case you get lost

Once you have postgresql on your windows up and running , Now we need to access it from the WSL we have

  • Install postgresql client in your wsl
sudo apt install poststgresql-client
Enter fullscreen mode Exit fullscreen mode
  • Lets configure network mode in wslconfig

In your windows terminal (Inside Default profile : for eg : In my case C:\Users\mouse)

wsl nano .wslconfig
Enter fullscreen mode Exit fullscreen mode
[wsl2]
networkingMode=mirrored
Enter fullscreen mode Exit fullscreen mode
  • Check the connection
 psql -h localhost -p 5432 -U postgres -d postgres
Enter fullscreen mode Exit fullscreen mode
  • Restart WSL
wsl --shutdown
Enter fullscreen mode Exit fullscreen mode

Now you should be able to connect to your windows localhost from your WSL.

Top comments (0)