I run Postgres 12 service in Windows Subsystem for Linux 2 (WSL2).
In my /etc/postgresql/12/main/postgresql.conf
, I have:
listen_addresses = '*'
while my /etc/postgresql/12/main/pg_hba.conf
has this content:
local all postgres peer
local all all peer
host all all 0.0.0.0/0 md5
host all all ::0/0 md5
host all all 0.0.0.0/0 md5
host all all ::0/0 md5
host all all all md5
If I try to connect to this server from any other device then the local machine, it times out.
Does anyone have any idea why should this be?
-
That's a firewall. You are not planning to use that platform for anything serious where you would mind losing data, right?Laurenz Albe– Laurenz Albe2021年03月22日 06:18:06 +00:00Commented Mar 22, 2021 at 6:18
-
yep, just for home testingvlad– vlad2021年03月22日 16:45:05 +00:00Commented Mar 22, 2021 at 16:45
-
Good, because as far as I know it is not safe for databases.Laurenz Albe– Laurenz Albe2021年03月22日 17:10:11 +00:00Commented Mar 22, 2021 at 17:10
-
I additionally opened the port 5432 in windows firewall, but same resultvlad– vlad2021年03月22日 17:16:36 +00:00Commented Mar 22, 2021 at 17:16
-
1If the connection times out, that is a network problem and has nothing to do with the database.Laurenz Albe– Laurenz Albe2021年03月22日 17:21:50 +00:00Commented Mar 22, 2021 at 17:21
1 Answer 1
You need to forward Windows port to WSL2.
When using a WSL 1 distribution, if your computer was set up to be accessed by your LAN, then applications run in WSL could be accessed on your LAN as well.
This isn't the default case in WSL 2. WSL 2 has a virtualized ethernet adapter with its own unique IP address. Currently, to enable this workflow you will need to go through the same steps as you would for a regular virtual machine. (We are looking into ways to improve this experience.)
Here's an example PowerShell command to add a port proxy that listens on port 4000 on the host and connects it to port 4000 to the WSL 2 VM with IP address 192.168.101.100.
netsh interface portproxy add v4tov4 listenport=4000 listenaddress=0.0.0.0 connectport=4000 connectaddress=192.168.101.100
Reference : Comparing WSL 1 and WSL 2 : Accessing a WSL 2 distribution from your local area network (LAN) (Microsoft | Docs)
-
1Welcome to DBA.SE. Always consider adding the relevant information, as link only answers are normally deleted. Links tend to expire and then the answer becomes a non-answer. Thanks.John K. N.– John K. N.2021年07月02日 09:55:50 +00:00Commented Jul 2, 2021 at 9:55
-
Just in case someone else was looking for a current link to the same information: learn.microsoft.com/en-us/windows/wsl/…battery– battery2022年07月16日 03:56:44 +00:00Commented Jul 16, 2022 at 3:56