0

I have a Ruby on Rails application running on nginx server (application server is on Red Hat OS). The database is installed on another server (same OS: Red Hat). From console of the application server, I'm able to connect to the database using same db credentials as in application. But the ruby application is not able to make a connection. It is throwing error

The error log /var/log/nginx/error.log has below error message

stderr: 
PG::ConnectionBad (could not connect to server: Permission denied
      Is the server running on host "10.178.61.135" and accepting
      TCP/IP connections on port 5432?
):

Also, to mention I'm able to run the rake db:migrate successfully

The database.yml file looks like below:

production:
  adapter: postgresql
  encoding: unicode
  database: applicationdatabase
  host: 10.178.61.135
  pool: 30
  port: 5432
  timeout: 10000
  username: dbuser
  password: dbpassword

On Database server the connection config /var/lib/pgsql/11/data/pg_hba.conf:

# Allow replication connections from localhost, by a user with the replication privilege.
local   replication     all                                     peer
host    replication     all             127.0.0.1/32            ident
host    replication     all             ::1/128                 ident
host       all          all             0.0.0.0/0               md5 

Database privilege

 List of databases
    Name             |    Owner    | Encoding |   Collate   |    Ctype    |      Access privileges
---------------------+-------------+----------+-------------+-------------+-----------------------------
 applicationdatabase | dbuser      | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =Tc/dbuser            +
                     |             |          |             |             | dbuser=CTc/dbuser

Other configs and versions

# Web app Server
nginx/1.10.1
Phusion passenger 5.0.29
Ruby 2.1.9
Rails 4.1.5
pg 0.17.1
RHEL 7.7

# DB Server
PostgreSQL 11.3
RHEL 7.7
3
  • Worth to mention, I read stackoverflow.com/questions/38466190/… and the postgresql conf is as suggested in the post. Commented Jan 13, 2020 at 15:54
  • As suggested on stackoverflow.com/questions/19828385/…; I tried removing the PID file and rebooting the machines, but no luck Commented Jan 13, 2020 at 15:55
  • can try your pg_hba.conf local all all trust host all all 127.0.0.1/32 md5 and host all all ::1/128 md5 Commented Jan 13, 2020 at 17:00

1 Answer 1

0

If 'psql' on the app server can connect but your application itself cannot, it sounds like something on the app server machine, like selinux or apparmor, which controls which users or apps can use the network.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.