Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have a postgresql server inside a virtualbox created by vagrant.

I have also set up a portforwarding from 5432 inside the box to 15432 on the host system via the Vagrant file.

When connecting via psql

$ psql dbname username -h 127.0.0.1 -p 15432

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

Both, server and client are running Ubuntu 12.04 (postgresql-9.1, Version: 9.1+129ubuntu1)

Connecting inside the VM it self to port 5432 works fine.

The port forwarding it self does not seem to go completely wrong, because when I try to another port, I get "connection refused")

share|improve this question
1  
what does 'ifconfig -a' on the host return? you should have a second (virtual) network adapter for the VBox NAT like '192.168.56.x'. if you replace 127.0.0.1 in your command with the VBox NAT IP address, does it work correctly? when connecting to a vbox nat, its just like connecting to a publicly forwarded port on a gateway router. hosts outside the NAT network use the public IP to connect to it. –  Frank Thomas Dec 6 '12 at 15:37
    
@FrankThomas I have only the normal eth0, lo, wlan0 interfaces. Connecting to SSH and HTTP via forwarded ports and 127.0.0.1 works fine. –  Alex Dec 6 '12 at 16:46

1 Answer 1

Did you configure Postgres to listen on the public interface? By default, it listens only on the loopback adapter

If you're using the Postgres cookbook, you need to set the attribute:

set['postgresql']['config']['listen_addresses'] = '*'

This corresponds to the listen_addresses parameter in postgresql.conf

And likely open up pg_hba to the network that Postgres thinks your connection is coming in on:

Again, the Chef attribute:

set['postgresql']['pg_hba'] = [
    {:type => 'local', :db => 'all', :user => 'all', :addr => nil, :method => 'trust'},
    {:type => 'host', :db => 'all', :user => 'all', :addr => '127.0.0.1/32', :method => 'trust'},
    {:type => 'host', :db => 'all', :user => 'all', :addr => '10.0.0.0/16', :method => 'trust'}
]
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.