Trouble connecting to Postgresql database in Vagrant guest box with Induction from host machine?

2.6k views Asked by At

I'm trying to connect to my PostgreSQL database which is inside of a guest machine (using Vagrant and VirtualBox).

I'm trying to connect to it with Induction, but I am getting an error saying:

Connection Error
Could not connect to server: Permission denied
Is the server running locally and accepting
connections on Unix domain socket "/var/pgsql_socket/.s.PGSQL.1234"

I have Vagrant doing a port forward to port 1234 on my host machine.

My settings for the Induction connection are:

Adapter: postgres
Host Name: 127.0.0.1
Username: vagrant
Password: [i don't have a password for the vagrant user for postgres so leaving empty]
Port: 1234
Database: development

The development database was created by Rails using rake db:create:all and I know that it works because I see it from the Rails db console.

In my postgresql.conf file, I have set listen_addresses to '*' to listen to external machines also.

What am I doing wrong?

EDIT (adding my pg_hba.conf):

# Database administrative login by Unix domain socket
local   all             postgres                                peer

# TYPE  DATABASE        USER            ADDRESS                 METHOD

# "local" is for Unix domain socket connections only
local   all             all                                     trust
# IPv4 local connections:
host    all             all             127.0.0.1/32            md5
# IPv6 local connections:
host    all             all             ::1/128                 md5

EDIT (this is the error that shows from the Induction app when trying to connect)

could not connect to server: Permission denied
Is the server running locally and accepting
connections on Unix domain socket "/var/pgsql_socket/.s.PGSQL.1234"
2

There are 2 answers

9
Pronix On

check file pg_hba.conf looks like require allow connection most easy and lesss secure set 'trust' (everyone can use your postgresql) http://www.postgresql.org/docs/9.2/static/auth-pg-hba-conf.html

0
Alpha Codemonkey On

I've seen that connection error when the PostgreSQL service is not running.

Check the status of the PostgreSQL service: sudo service postgresql status

Start the service: sudo service postgresql status