Skip to content
-
Mind and Script Mind and Script Mind and Script

Deep Thoughts, Clean Thoughts

Mind and Script Mind and Script Mind and Script

Deep Thoughts, Clean Thoughts

  • Home
  • Life
    • Lifestyle
    • Mental Health
    • Personal Growth
    • Philosophy
    • Professional Growth
    • Psychology
  • Books
  • Writing
    • AI Writing
    • Technical Writing
  • Movies
  • Travel
    • Day Trips
    • Food
    • Itineraries
    • World
  • Technology
  • Home
  • Life
    • Lifestyle
    • Mental Health
    • Personal Growth
    • Philosophy
    • Professional Growth
    • Psychology
  • Books
  • Writing
    • AI Writing
    • Technical Writing
  • Movies
  • Travel
    • Day Trips
    • Food
    • Itineraries
    • World
  • Technology
Close

Search

Mind and Script Mind and Script Mind and Script

Deep Thoughts, Clean Thoughts

Mind and Script Mind and Script Mind and Script

Deep Thoughts, Clean Thoughts

  • Home
  • Life
    • Lifestyle
    • Mental Health
    • Personal Growth
    • Philosophy
    • Professional Growth
    • Psychology
  • Books
  • Writing
    • AI Writing
    • Technical Writing
  • Movies
  • Travel
    • Day Trips
    • Food
    • Itineraries
    • World
  • Technology
  • Home
  • Life
    • Lifestyle
    • Mental Health
    • Personal Growth
    • Philosophy
    • Professional Growth
    • Psychology
  • Books
  • Writing
    • AI Writing
    • Technical Writing
  • Movies
  • Travel
    • Day Trips
    • Food
    • Itineraries
    • World
  • Technology
Close

Search

Connect to PostgreSQL from WSL in Windows

Connect to PostgreSQL from WSL in Windows

August 13, 2025 3 Min Read
0

Welcome to this guide on setting up a development environment with PostgreSQL in the Windows Subsystem for Linux (WSL). This approach is highly recommended for developers as it combines the robust, Linux-native experience of PostgreSQL with the convenience of your Windows machine, allowing you to manage your database with powerful Windows-based tools like DBeaver or any GUI Tools of your choice.

Step 1: Install PgSQL in WSL

The first step is to get PgSQL up and running inside your WSL environment. This guide assumes you are using a Debian-based distribution like Ubuntu.

  • Open your WSL terminal (e.g., Ubuntu).
  • Update the package list to ensure you’re installing the latest version.
sudo apt update
  • Install PgSQL and its extensions using the following command.
sudo apt install postgresql postgresql-contrib

postgresql: The main server package.
postgresql-contrib: A package of useful utilities and extensions.

Step 2: Set a Password for the postgres User

By default, the postgres superuser has no password, which is a security risk and prevents external connections. You need to set one.

  • Switch to the postgres user to access the database administration tools.
sudo -i -u postgres
  • Access the PgSQL command-line prompt
psql
  • Set a new password for the postgres user. Replace your_new_password with a strong, secure password.
ALTER USER postgres WITH PASSWORD 'your_new_password';
  • Exit the psql prompt and return to your regular WSL user
==> \q
==> exit

Step 3: Allow External Connections from Windows

For your Windows applications (like DBeaver) to connect to the database in WSL, you must configure PgSQL to listen for external connections and update its authentication rules.

Configure postgresql.conf

  • Open the PgSQL configuration file. The path may vary slightly depending on your installed version.
    (example, sudo nano /etc/postgresql/14/main/postgresql.conf)
sudo nano /etc/postgresql/<version>/main/postgresql.conf
  • Change the listen_addresses line. Find the line that looks like
#listen_addresses = 'localhost',
  • Uncomment it by removing the #, and change the value to ‘*’ to accept connections from all IP addresses.
listen_addresses = '*'

Configure pg_hba.conf

  • Open the client authentication file.
sudo nano /etc/postgresql/<version>/main/pg_hba.conf
  • Add a new entry to allow connections from your Windows IP address.
  • Add the following line at the bottom of the file to allow all hosts to connect to all databases as the postgres user with password authentication.
host    all             postgres        0.0.0.0/0               md5
  • Save the changes and exit (Ctrl+X, then Y, then Enter).
  • Restart the PgSQL service to apply the new configurations.
sudo service postgresql restart

Step 4: Connect with DBeaver on Windows

Now that your server is configured to accept connections, you can set up DBeaver.

  • Find your WSL IP Address: Open a Command Prompt or PowerShell window on your Windows machine and run the following command to get the IP address of your WSL instance.
wsl hostname -I

Open DBeaver and create a new connection.
Go to Database -> New Database Connection.
Select PostgreSQL and click Next.
Enter the Connection Details.
Host: Use the IP address from the previous step.
Port: 5432 (default).
Database: Enter the name of your desired database (e.g., postgres or a new database you created).
Username: postgres
Password: The password you set in Step 2.
Click Test Connection… to confirm it works, and then click Finish.

You are now successfully connected to your PgSQL database in WSL from DBeaver on Windows. You can use DBeaver’s graphical interface to manage your databases, tables, and data. This powerful combination gives you the best of both worlds: a native Linux database server and the familiar, feature-rich tools of Windows. Happy coding!

💡 Mind and Script Weekly

Join other engineers and writers. No spam, just substance.

Disclaimer: This post may contain affiliate links. If you click and buy, we may receive a small commission at no extra cost to you. Read our full disclosure here.

Tags:

LinuxPostgreSQLWindowsWindows Sub-Sytems Linus
Author

Rajesh Mishra

I'm a developer who loves sharing insights, technical how-tos, and lessons learned from the world of code. While much of what I write may not be groundbreaking, I believe in documenting for future me—and for anyone else who might find it useful. Beyond tech, I also dive into life's experiences and moments, reflecting on personal growth and sharing stories that resonate. Whether you're here for practical tips or a fresh perspective on life, I hope you find something meaningful.

Follow Me
Other Articles
1D9nEjOHplSw1e0SM7eUOKA
Previous

7 Inventions That Changed the World in Unexpected Ways

1QqS8QLZyJoA7nqcAzrse5A
Next

Why Do We Rewatch Comfort Movies and Shows?

No Comment! Be the first one.

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Recent Posts

  • Hyderabad Traffic
  • 5 Best Books to Read After a Breakup
  • 5 Movies to Stream This Valentine’s Day If You’re Single
  • Self-Care: A Guide to Solo Valentine’s Day
  • Using GitHub Actions for Google Cloud Run

Recent Comments

  1. Sneha on Smartphones: Friend or Foe?

Important Links

  • Affiliate Disclosure
  • Privacy Policy
  • Terms of Use
© Copyright 2026 — Mind and Script. All rights reserved.