0

I'm trying to connect to a remote server from my local machine. Here's how my database.yml file looks like:

development:
  adapter: postgresql
  encoding: unicode
  database: db_name
  username: mac
  password: mac
  host: 178.XXX.XXX.XXX
  port: 5432
  pool: 10
  timeout: 5000

I edited pg_hba.conf to take my ip address:

local   all             all                                     trust
# IPv4 local connections:
host    all             all            35.XXX.XX.XX/32          trust

# IPv6 local connections:
host    all             all             ::1/128                 trust

Remote server is hosted on AWS with centos 6 AMI. Below inbound rules are added in it's security group. enter image description here

But I keep getting below error:

PG::ConnectionBad: could not connect to server: Connection refused
    Is the server running on host "<HOST NAME>" (178.XXX.XXX.XXX) and accepting
    TCP/IP connections on port 5432?

For logs checked /var/lib/pgsql/9.6/data/pg_log, however no logs are being created.

Running netstat -ntlp tells that server is listening on 5432 port enter image description here

Am I missing something or doing something wrong here? please help

cop
  • 93
  • 3
  • 10

1 Answers1

0

Check my answer from yesterday. There is a procedure how find a problem with connecting to the remote PostgreSQL database:

Remote PostgreSQL connection

The error you have posted is not related to Ruby on rails. It is standard problem with wrong PostgreSQL settings. First try psql which should show the same error as you posted

Write a comment if you will have a problem. I bet that the problem is because you forgot set listen_address"'*' in postgresql.conf because you don't mention this in the answer.

Bulva
  • 1,208
  • 14
  • 28
  • Hi Bulva, I added listen_address as well and followed your answer, but i still have the same connection error. – cop Apr 28 '18 at 06:19
  • So try restart PostgreSQL service and check the log in /var/logs/syslog or /var/logs/posgresql. Maybe did you try set pg_hba.conf like on the other answer? Maybe you made a mistake in your ip – Bulva Apr 28 '18 at 07:06
  • Hi, thanks a lot for your support, it was a firewall issue. I disabled the firewall and it worked. :) – cop Apr 28 '18 at 07:35
  • Ok. So don't forget you shouldn't disable firewall for all ports. It is better to open in/out port for posgresql – Bulva Apr 28 '18 at 07:36