PgAdmin on Windows 10 with Postgres when installed via Bash on Ubuntu on Windows

Viewed 18495

I would like to install Rails 5/Postgres within Bash On Ubuntu On Windows and also be able to access Postgres database via PgAdmin for Windows.

Am quiet happy to install all my rails dependencies through Bash on Ubuntu on Windows, but I am aware that I can't run any standard GUI tools from Bash and was wondering if it is possible to install Rails and PostGres on the Linux Subsystem and then query my databases using the Windows version of PgAdmin

I had a look at this tutorial how-to-install-ruby-on-rails-on-windows-10-with-postgresql but it seems that he installs Postgres into windows rather then the Linux Subsystem.

I was wondering if this is the only way to go about getting all these tools working nicely together.

Basically I want my Windows installed PgAdmin to communicate to my Bash On Ubuntu On Windows Postgres DB

7 Answers

Here's what I did to connect Postgres DB installed in WSL Ubuntu from Windows pgAdmin.

  1. Launch Ubuntu in Windows.
  2. Start postgres in Ubuntu terminal: sudo service postgresql start
  3. Download the latest pgAdmin and install in Windows.
  4. Launch pgAdmin, a new tab in browser opens; click on Add New Server link.
  5. In the popup Create - Server window in the browser:
    1. General tab: I set Name to localhost
    2. Connection tab: I set Host name/address to localhost, set Password to postgres, which is the default, click on Save password?
    3. I save the setting, leaving the rest of the fields as is
  6. That's it, I can see the DB created in Postgres immediately.

Browser screenshot on adding a server

posting in case someone had my issue

In my case I was getting Connection refused, I was able to resolve by changing listen_addresses property to '*' inside postgresql.conf file

To locate conf file on ubuntu

sudo -u postgres psql -c 'SHOW config_file'

once you find the file, you need to change listen_addresses like this

listen_addresses = '*'

Then restart postgres using

sudo service postgresql restart

you might need to change the permission of the file before you can edit it, don't forget to revert this change once done.

The answer provided by @kiatng helped me too. However, I was getting a socket not connected error when I was trying to access the data in my tables. Through another Google search, I found I needed to change localhost to 127.0.0.1 and then I was able to access the data. Just putting this here in case it helps someone else. I would have replied to kiatng's answer but I don't quite have enough 'reputation' yet to do so!

I had a similar issue with postgresql running on WSL2 - bash and wanting connect from pgadmin running on windows.

The following settings will get the job done (as it did for me)

in /etc/postgreql//main/postgresql.conf have

listen_addresses = '*'

And then in /etc/postgreql//main/pg_hba.conf have

# IPv4 local connections:
host    all             all             127.0.0.1/32            md5
host    all             all             172.0.0.0/8             md5

restart postgresql

sudo service postgresql restart

This allows both localhost access and WSL ip access.

In your pgadmin, in connection setting try out localhost as the host settings (usually works , if it does not, you can give the bash ip which is usually in 172 range)

In my case WSL2, localhost forwarding doesn't seem to work so the solutions mentioned were not working. I had to do a Network Reset, which worked for me.

Reference: WSL Issue on Github

If the above solutions are not working for you, try to do a Network Reset as shown in the image below, and then try the above answers.

enter image description here

First, run

sudo -u postgres psql -c 'SHOW config_file'

Open the resulting file, uncomment listen_addresses, and change to it this:

listen_addresses = '*'`

Then run

sudo service postgresql restart
Related