So i received a message from heroku saying it needs to carry out maintenance on my database and will be read only for a bit. However I go to check my site and the site isn't working for the pages that require data from the database, I go to check the logs and see this error message:
2022-05-20T09:57:55.246102 00:00 app[web.1]: sqlalchemy.exc.OperationalError: (psycopg2.OperationalError) connection to server at "eu-west-1.compute.amazonaws.com" (52.18.116.67), port 5432 failed: FATAL: password authentication failed for user "MYUSERNAME"
2022-05-20T09:57:55.246102 00:00 app[web.1]: connection to server at ".eu-west-1.compute.amazonaws.com" (52.18.116.67), port 5432 failed: FATAL: no pg_hba.conf entry for host "IP", user "MYUSERNAME", database "DATABASE", no encryption
I haven't touched or changed anything, so not sure what the problem is.
CodePudding user response:
This happen if you are not using the "dynamic" environment variable that Heroku manage for connecting to a PostgreSQL database
If you have just one, it's better to use DATABASE_URL as it always have up-to-date location and credentials
Heroku can change the url for various reasons, ex credentials rotation
If you are using sqlalchemy you might need a slight workaround:
os.environ.get('DATABASE_URL').replace('postgres://', 'postgresql://')