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.
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.
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?