3

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:

6
  • 2
    psql -h /tmp ? psql -h localhost? Commented Sep 20, 2017 at 2:53
  • first one returned psql: could not connect to server: No such file or directory Is the server running locally and accepting connections on Unix domain socket "/tmp/.s.PGSQL.5432"? Interesting its a different socket. The second one returned: psql: FATAL: could not load pg_hba.conf I may have two versions of posgresql installed then... Commented Sep 20, 2017 at 2:59
  • 1
    TBH I don't know if PostgreSQL even works on the Windows Linux subsystem. We don't have a buildfarm member to test it at the moment as nobody has cared. It depends on just how compatible it truly is. Why don't you just use the native Windows PostgreSQL instead? Commented Sep 20, 2017 at 3:27
  • It works in WSL, I want to use in WSL to learn how to use without a GUI. I connected to a colleagues database with psql -h 199.xx.xxx.64 -d rtk_prcd -U sv-read -p 5432 and I got in fine, so I don't know whats going on. Commented Sep 20, 2017 at 14:00
  • @CraigRinger adding '-h localhost' to commands made it work for me. 'psql', 'createdb db_name' etc. gave me the error. 'psql -h localhost', 'createdb db_name -h localhost' both worked. Commented Jul 5, 2018 at 19:30

1 Answer 1

5

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.