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.

Heroku

Build apps, not infrastructure.

Dealing with servers, hardware, and infrastructure can take up your valuable time. Discover the benefits of Heroku, the PaaS of choice for developers since 2007.

Visit Site

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay