llong
Getting DBConnection.ConnectionError connection refused error
Environment:
-
Windows 10
-
Using WSL2 with Ubuntu Server via Windows Terminal to run setup
-
Database URL: ecto://postgres:postgres@localhost/chat_api_dev
-
Error: ** (DBConnection.ConnectionError) tcp connect (localhost:5432): connection refused - :econnrefused
(db_connection 2.2.2) lib/db_connection/connection.ex:87: DBConnection.Connection.connect/2
(connection 1.0.4) lib/connection.ex:622: Connection.enter_connect/5
(stdlib 3.13) proc_lib.erl:226: :proc_lib.init_p_do_apply/3
Last message: nil
State: Postgrex.Protocol
** (Mix) The database for ChatApi.Repo couldn’t be created: killed
I have validated that postgresql service is running in WSL2 by doing “sudo service postgresql status” which returns “13/main (port 5432): online”
I also run “netstat -an | grep 5432” which validates the port is listening
Also do “telnet localhost 5432” which connects fine
First Post!
rjk
When you netstat can you output the IP it binds to? (If that is also a localhost ip it does not allow access from outside the wsl2 vm but can be accessed from inside the vm)
Comparing WSL 2 and WSL 1 | Microsoft Docs You could try to access it on it’s own VM IP to see if that works.
If it is all working from inside WSL2 it could also be a firewall rule blocking going from outside to WSL2.








