How to Run pgAdmin 4 in WSL and Access from Windows


Stop installing heavy desktop apps for database management! If you're a developer rocking WSL (Windows Subsystem for Linux), there is a much smarter, lightweight, and "pro" way to handle your PostgreSQL databases.
Why clutter your Windows registry when you can run the pgAdmin 4 web interface cleanly inside Linux and access it directly from your favorite Windows browser? It feels native, saves resources, and makes you look like a total tech wizard. π§ββοΈβ¨
Ready to level up your workflow? Let's dive in! π
First things first. We don't need the bloat of the desktop client. We are going for the sleek, efficient web version.
Open your WSL terminal and run this command to fetch the official key. This ensures we're getting the genuine package. π
curl -fsS https://www.pgadmin.org/static/packages_pgadmin_org.pub | sudo gpg --dearmor -o /usr/share/keyrings/packages-pgadmin-org.gpgNow, tell your system where to find the pgAdmin goodies by copying and pasting this magic line:
sudo sh -c 'echo "deb [signed-by=/usr/share/keyrings/packages-pgadmin-org.gpg] https://ftp.postgresql.org/pub/pgadmin/pgadmin4/apt/$(lsb_release -cs) pgadmin4 main" > /etc/apt/sources.list.d/pgadmin4.list'Refresh your package list and install the pgadmin4-web package. Run:
sudo apt update
sudo apt install pgadmin4-webNow for the fun part! We need to set up a lightweight web server (Apache is used by default here) to serve the pgAdmin app. Think of it like setting up phpMyAdmin, but for Postgres. π
Run the built-in setup script:
sudo /usr/pgadmin4/bin/setup-web.shπ You'll need to answer a few quick prompts:
y (Yes) and hit Enter. β
Here is the magic of WSL 2. It automatically forwards ports to your Windows host. No complex networking configuration required! π
Boom! You are now inside the pgAdmin dashboard. But wait... where are your databases? π€
Unlike phpMyAdmin, pgAdmin doesn't just guess where your database server is. We need to introduce them properly.
Let's register your PostgreSQL server so pgAdmin can talk to it.
On the pgAdmin dashboard (left sidebar), Right-click on Servers π Register π Server...
A popup window will appear. Fill it out with these details:
Ubuntu DB or Localhost. (This is just a label for you). 127.0.0.1β οΈ Important: Use
127.0.0.1instead oflocalhost. Sometimes inside Linux containers/WSL, "localhost" tries to use a socket file which can cause permission headaches. The IP address forces a TCP connection. π§
5432 (Default) [postgresDBname]Note: By default, this is
postgres, but if you created a specific database, itβs often safer to connect directly to that.
root (Or your specific postgres username) Click Save. πΎ
If everything is correct, your server will appear, and you can browse your tables! π₯
Did you get a scary red error saying FATAL: Peer authentication failed for user 'sab'? π±
Don't panic! This just means PostgreSQL is being a bit too secure. It's configured to trust the operating system user identity rather than the password you just typed. We need to tell it to accept password logins.
sudo nano /etc/postgresql/16/main/pg_hba.conf(Note: Replace 16 with 14 or 15 if you are using an older version). local all all peer peer to md5 (or scram-sha-256):local all all scram-sha-256Also, ensure the IPv4 line says scram-sha-256 or md5:host all all 127.0.0.1/32 scram-sha-256 Ctrl+O then Enter to save, and Ctrl+X to exit. sudo service postgresql restart Now try clicking Save in pgAdmin again. It should work perfectly! π
Happy Coding! π»β¨

Step-by-step guide to installing Frappe 16 and ERPNext on Windows using WSL. Learn to set up Python 3.14, Node 24, and PostgreSQL for a next-gen dev environment.

Stop generating gibberish. Use these 15 insane prompts to create perfect text, consistent characters, and impossible macro shots. The ultimate guide for 2025

Shadows disappearing in your Threlte or Three.js scene? Itβs a frustum issue. Learn how to visualize the shadow box and fix clipping instantly with this guide.