Unable to connect external postgresql database to Heroku

  heroku, heroku-postgres, plotly-dash, postgresql, python

I’m trying to deploy a Dash app onto Heroku that is connected to an external PostgreSQL database. I’ve tried to use the heroku-postgres addon but I don’t quite understand how that works, and I think it also won’t have enough space for the data I need. I currently have an external PostgreSQL database I’m using and I’ve gone through the steps to attach/detach/config:add the new DATABASE_URL.

Every time I deploy I run into this error (more of the error code in the image):

Error fetching data from PostgreSQL table could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?

enter image description here

I’ve set up my Config Vars such that the DATABASE_URL is postgres://user:[email protected]_ip:port/database_name

and in my code I’m connecting to the database via a .env file that looks like this:

# Development settings

Also, I saw somewhere that this might be useful to check ps -ef | grep postgres and the output of that shows the correct database connection, but the output of pg_lsclusters shows nothing.

Please let me know if I can provide any more info. Thank you in advance!

Source: Python Questions