This article covers the basics of installing and running PostgreSQL on Debian in Windows subsystem for Linux (WSL).
Updated June 15 2025 (to include running Postgres 18 on WSL, and connecting with the VS Code Postgres extension).
WSL makes for a great development environment if you're running Windows and want to use Linux locally. It's also a very convenient platform run to a local PostgreSQL server, and integrates nicely with dev tools like VS Code.
Which Linux distro?
You can choose from many Linux distributions to run on WSL (run wsl -l -o to see a list or import any distro using a TAR file). I like to use Debian as it's a popular, stable, general purpose distro with good support. You can install Debian to WSL directly from the Microsoft Store, and use Windows Terminal to log on to it.
Which Postgres version?
Ignore this step if you want want the default Postgres version that comes with your distro packages.
See the postgresql.org Apt/FAQ for guidance on how to install the latest released or development PostgreSQL version. For example, edit /etc/apt/sources.list.d/pgdg.list to point to the latest version 18 pre-release by adding this line:
deb http://apt.postgresql.org/pub/repos/apt/ bookworm-pgdg main 18
Install Postgres
The first thing to do is make sure you're up to date with the latest patches. On the Debian command line:
sudo apt update
sudo apt upgrade
sudo apt autoremove # to free up space if needed
If you're installing the latest released version (e.g., 17), install with:
sudo apt install postgresql postgresql-contrib
See Install PostgreSQL in the WSL docs for more details.
Installing a development release. E.g., postgresql-18
Alternatively, install a specific version like 18 with:
sudo apt install postgresql-18
Set a password for the postgres user with sudo passwd postgres and then start the service:
sudo passwd postgres
sudo service postgresql start
sudo systemctl enable postgresql # to start service automatically
Note: If you previously had an earlier version of PostgreSQL installed and the version you want isn't starting, you can explicitly initialize it. You can then run both versions (listening on different ports), or you can drop the older cluster if you don't need it. Example:
sudo pg_createcluster 18 main --start
pg_lsclusters
sudo pg_dropcluster 17 main --stop
sudo service postgresql start
Connecting to PostgreSQL
You can then enter the PostgreSQL shell with:
sudo -u postgres psql
..and from there run SQL commands, e.g. create PostgreSQL users with CREATE USER
Or run SQL commands directly, e.g.
sudo -i -u postgres psql < create_db.sql
sudo -i -u postgre psql -d mydb < create_schema.sql
# list databases
sudo -i postgres psql --list
Connecting with VS Code
VS Code has become a great way to connect to a Postgres instance since the PostgreSQL for Visual Studio Code extension was released in May 2025.
Create a new connection, use 127.0.0.1 as the "SERVER NAME" and check in "Advanced Connection Settings" to make sure 5432 is the listening port (unless you're using a different listening port - you can check in Debian with pg_lsclusters).
Connecting with pgAdmin
You can install pgAdmin on Windows and connect the GUI Admin/developer tool directly to your Postgres server running in WSL.
In pgAdmin, create a new server with the name of your choice, Host name/address: 127.0.0.1 and a valid PostgreSQL user/password.
Once I've done my local development it's very straightforward to export a database from WSL to a Postgres cloud service or other production destination.
Top comments (0)