Windows Linux Subsystem and postgresql connection failed

Viewed 3086

There seems to be lots of questions likes this on stackoverflow, but none of them seemed to help me. I am runing Ubuntu on my windows linux subsystem and trying to install and use postgresql.

I installed in like this:

sudo apt-get install postgresql postgresql-contrib postgresql-client
pgadmin3

which worked fine:

near the bottom the install log says:

Creating new cluster 9.5/main ...
  config /etc/postgresql/9.5/main
  data   /var/lib/postgresql/9.5/main
  locale C
  socket /var/run/postgresql
  port   5433
update-alternatives: using /usr/share/postgresql/9.5/man/man1/postmaster.1.gz to provide /usr/share/man/man1/postmaster.1.gz (postmaster.1.gz) in auto mode
invoke-rc.d: could not determine current runlevel
Setting up postgresql (9.5+173) ...
Setting up postgresql-client (9.5+173) ...
Setting up postgresql-contrib-9.5 (9.5.8-0ubuntu0.16.04.1) ...
Setting up postgresql-contrib (9.5+173) ...
Processing triggers for systemd (229-4ubuntu16) ...
Processing triggers for ureadahead (0.100.0-19) ...

So the port is 5433. This is also the port listed in the postgresql.conf file.

When I type psql I get:

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.5433"?

When I do:

ps -df | grep postgres

I get a different port though (5432) and this is returned:

spotter     12     2  0 18:55 tty1     00:00:00 /usr/lib/postgresql/9.5/bin/psql -h 199.92.170.64 -d rtu_prod -Usv-read -p 5432
spotter   1835     2  0 20:21 tty1     00:00:00 grep --color=auto -a postgres
spotter   6134     2  0 20:51 tty1     00:00:00 grep --color=auto -a postgres
spotter   9348     2  0 22:06 tty1     00:00:00 grep --color=auto postgres

I think this might mean I have two versions of postgresql installed but I'm not sure.

Based on other posts I should enter /usr/lib/postgresql/9.5/bin/psql -h 199.92.170.64 -d rtu_prod -Usv-read -p 5432 to start it, but this asks for a password I have never heard of Password for user sv-read:

1 Answers

PostgreSQL works just fine with WSL. To fully run it, follow these steps:

Installation Steps:

  1. sudo apt update
  2. sudo apt install postgresql postgresql-contrib
  3. sudo service postgresql start
  4. sudo -i -u postgres
  5. psql

User setup from psql:

  1. CREATE USER <Your User name> WITH PASSWORD '<Your Password>';
  2. CREATE DATABASE <Your database> WITH OWNER <Your User name>;
  3. \password postgres
Related