postgresqlwindows-subsystem-for-linux

How to connect to windows postgres Database from WSL


I'm running Postgres 11 service on my Windows computer. How can I connect to this database from WSL?

When I try su - postgres:

postgres@LAPTOP-NQ52TKOG:~$ psql 
psql: could not connect to server: No such file or directory 
        Is the server running locally and accepting
        connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"

It's trying to connect to a Postgres in WSL. I don't want to run Ubuntu Postgres using: sudo /etc/init.d/postgresql start


Solution

  • Specify your host, port, and username explicitly For example:

    psql -h 127.0.0.1 -p 5432 -U postgres