I am trying to connect my Flask application, deployed on render.com, to a PostgreSQL database. The database is already working with my development app, but I am encountering an error when trying to connect from the deployed app.
I am using the normal format for DATABASE_URL=‘postgres:{username}@{host}:{port}/{database_name}’
I have made the following changes to the pg_hba.conf and postgresql.conf files, and have restarted with postgresql with brew:
pg_hba.conf:
local all all md5
host all all 127.0.0.1/32 trust
host all all ::1/128 trust
host all all 0.0.0.0/0 trust
postgresql.conf:
listen_addresses = '*' # what IP address(es) to listen on;
# comma-separated list of addresses;
# defaults to 'localhost'; use '*' for all
# (change requires restart)
Despite these changes, I am still getting the following error when trying to connect:
Error connecting to database: (psycopg2.OperationalError) connection to server at "localhost" (::1), port 5432 failed:
Connection refused Is the server running on that host and accepting TCP/IP connections?
connection to server at "localhost" (127.0.0.1), port 5432 failed:
Connection refused Is the server running on that host and accepting TCP/IP connections?
(Background on this error at: https://sqlalche.me/e/20/e3q8)
Is there something else I need to configure or modify to successfully connect my Flask app to the PostgreSQL database on render.com?