Can't connect to PostgreSQL on VirtualBox guest

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