Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

When I try to connect from a PostgreSQL client on the host system to the PostgreSQL server on a VirtualBox guest system, I get a "connection attempt failed" message.

The host system is Windows XP. I'm running VirtualBox 3.1.2. The guest system is Ubuntu 9.10 Karmic Koala with PostgreSQL 8.4.

I've forwarded port 5432 in VirtualBox as described in the manual and this post. When I run vboxmanage getextradata vmname enumerate, I get these entries (among others):

Key: VBoxInternal/Devices/e1000/0/LUN#0/Config/pgsql/GuestPort, Value: 5432
Key: VBoxInternal/Devices/e1000/0/LUN#0/Config/pgsql/HostPort, Value: 5432
Key: VBoxInternal/Devices/e1000/0/LUN#0/Config/pgsql/Protocol, Value: TCP

I configured PostgreSQL security in /etc/postgresql/8.4/main/pg_hba.conf with these entries:

# IPv4 local connections:
host    all         all         127.0.0.1/32          md5
host    all         all         192.168.1.0/24        md5
host    all         all         10.0.2.2/32        md5

Then I reloaded PostgreSQL with sudo /etc/init.d/postgresql-8.4 reload.

For diagnostic purposes only, I've disabled my Windows firewall and my Ubuntu firewall (sudo ufw disable).

Anybody know what steps I've missed?

share|improve this question

1 Answer 1

up vote 8 down vote accepted

OK, I found the missed step thanks to this post.

I had forgotten to set the listen_addresses setting in postgresql.conf. I'm using this value, but it could be more restricted:

listen_addresses = '*'

Just to clarify, when you connect to PostgreSQL from the host, use localhost as the server and 5432 as the port. VirtualBox will forward that port to the guest.

I also realized that some settings require you to restart PostgreSQL instead of just reloading it. The command is:

sudo /etc/init.d/postgresql-8.4 restart
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.