How can I access Postgresql hosted on Vagrant as a guest on Windows?

I am trying to connect to Postgresql using the PGAdmin III client on Windows 8.1. Postgresql is installed on a local copy of Vagrant (Ubuntu 14.04) on my Windows computer. It works and works on Vagrant:

LISTEN

tcp        0      0 127.0.0.1:5432          0.0.0.0:*               LISTEN      814/postgres

TESTED USER / PASS / LOCAL CONNECTION

I can access Postgresql locally in Vagrant via SSH on Windows:

vagrant@precise32:/etc/postgresql/9.1/main$ psql -h localhost testdb myuser
Password for user myuser:
psql (9.1.15)
SSL connection (<removed)
Type "help" for help.

testdb=> \quit

pg_hba.conf

I added this to my pg_hba.conf file:

# IPv4 local connections:
host    all             all             127.0.0.1/32            md5
host    all             all             <my IP>                 md5

VAGRANT CONFIG

My Vagrant configuration is configured to send to address 5432:

# Create a forwarded port mapping which allows access to a specific port
# within the machine from a port on the host machine. In the example below,
# accessing "localhost:8080" will access port 80 on the guest machine.
config.vm.network "forwarded_port", guest: 5432, host: 15432

postgresql.conf

And my postgresql.conf file is configured to listen on all IP addresses:

#listen_addresses = '*'    # what IP address(es) to listen on;

PGADMIN ERROR

, , PGAdmin , , , , - ?:

An error has occurred:

Error connecting to the server: server closed the connection unexpectedly
This probably means the server terminated abnormally before or while processing the request.

PGADMIN

Host: localhost
Port: 15432
Service: <blank>
Maintenance DB: postgres
Username: Myuser (verified)
Password: ****** (verified)
Store password:
Colour: <blank>
Group: Servers
+4
3

, pg_hba.conf, ip 10.0.2.2/24 .

0

Vagrant IP ( ), :

config.vm.network :forwarded_port, host: 15432, guest: 5432
config.vm.network :private_network, ip: "192.168.111.222"

PGAdmin Windows 192.168.111.222, 5432.

, , ..: P

0

I had the same problem on linux and I think this can happen on Windows too. In my postgresql.conf, the port variable was defined in two places. The first value is 5432 and the second value is 5435.

By running telnet vm_ip 5435, I was able to connect to a server running vm.

In my case, my vm worked with the public_network parameter, so I have an external ip. In this case, you do not need to forward the port as soon as you get access to vm, for example, with the address 192.168.60.15:5435.

0
source

All Articles