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.

Imagine monitoring actually built for developers

Billboard image

Join Vercel, CrowdStrike, and thousands of other teams that trust Checkly to streamline monitor creation and configuration with Monitoring as Code.

Start Monitoring

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Immerse yourself in a wealth of knowledge with this piece, supported by the inclusive DEV Community—every developer, no matter where they are in their journey, is invited to contribute to our collective wisdom.

A simple “thank you” goes a long way—express your gratitude below in the comments!

Gathering insights enriches our journey on DEV and fortifies our community ties. Did you find this article valuable? Taking a moment to thank the author can have a significant impact.

Okay