Issues Connecting to PostgreSQL in production

I am attempting to host my fullstack site with a PostgreSQL database. It’s running on node.js and rails. The connection to the database works fine in development. I am able to seed the database and create/update/delete data from the tables. However when I try to establish a connection in the production environment I get the following error log:

Caused by:
PG::ConnectionBad: connection to server at “::1”, port 5432 failed: Connection refused
Is the server running on that host and accepting TCP/IP connections?
connection to server at “127.0.0.1”, port 5432 failed: Connection refused
Is the server running on that host and accepting TCP/IP connections?

I have checked my environment variables and they all seem to match with the properties for my DB server.

Any advice would be much appreciated!

Hi there,

During development it is common to connect to localhost, but that won’t work when the database is on a server. It doesn’t looks like you’re using the database’s external (or internal) connection url to connect to it. This information can be found in the Connections section of the database service.

Let us know if you have any further questions.

Regards,
Mike


Render Support Engineer, MT (UTC-6)


I’ve added the environment variable to my database.yml file and still received the same error.

I currently have the host name set to local host in my url. Is it possible that this is what is causing the issue?

Hi there,

When connecting externally to any database hosted on a server, localhost should never be used, as localhost means the connection attempt is being made from within the same server (or on a local machine). Wherever the database is being hosted online, find the proper external connection string and hostname and then update the service to be pointing at those values.

Just to clarify, is this database hosted on Render or elsewhere?

Regards,
Mike


Render Support Engineer, MT (UTC-6)

The database is actually not being hosted by render. It is being run from postgreSQL on my local machine.

I have resolved the issue. Created a new db instance that is hosted via render.

Hi Anthony,

Glad to hear it! Thanks for letting us know.

Regards,
Mike


Render Support Engineer, MT (UTC-6)

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.