Alexander Pikeev
Alexander Pikeev

Reputation: 41

Connecting to PostgreSQL on WSL

How to connect to PostgreSQL server running in WSL from pgAdmin running in Windows? If you specify localhost and port 5432, the error appears:

could not connect to server: Connection refused (0x0000274D / 10061)
Is the server running on host "localhost" (:: 1) and accepting
TCP / IP connections on port 5432?
could not connect to server: Connection refused (0x0000274D / 10061)
Is the server running on host "localhost" (127.0.0.1) and accepting
TCP / IP connections on port 5432?

Upvotes: 4

Views: 7345

Answers (2)

Larry
Larry

Reputation: 187

In addition to the previous answer, you may also need to change the postgresql.conf file to allow sql to listen on non-local port.

For that you need to edit postgresql.conf and change listen_addresses = 'localhost' to listen_addresses = '*'

Then restart postgresql on wsl with sudo service postgresql restart

Upvotes: 5

user19655590
user19655590

Reputation: 51

i got the same issue with a Ubuntu WSL2 and here is how i solved it :

  • in wsl get your local ip address (ip addr and look for the adress in eth0 section after inet.). for me it was 172.18.117.222/20.
  • in the pg_hba.conf add a mask line in the IPv4 section to allow connection through the local IP address : host all all 172.18.117.222/20 md5
  • restart the postgresql server.
  • connect in PgAdmin using 172.18.117.222 instead of localhost.

Upvotes: 5

Related Questions