2
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"?

The following error is what I get when I open up my site on heroku. I'm not sure what is going on, but my settings are as follows...

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'NAME': os.environ.get('DB_NAME'),
    }
}

pushing to heroku master works fine but just when opening up my app heroku open I get that error and I am not sure how to fix it.

I have also django_heroku.settings(locals()) at the end of my settings.py file and my DB_NAME is a config var of the name of the database on my Heroku app.

Michael Torres
  • 512
  • 3
  • 21
  • 1
    Well, as usual, you could start by following the [documentation](https://devcenter.heroku.com/articles/django-app-configuration). –  Dec 01 '20 at 23:37
  • What makes you think I have not? – Michael Torres Dec 02 '20 at 00:19
  • Under heroku addons you can add a Postgres. Check out https://pypi.org/project/dj-database-url/ you can add your datbase like so `DATABASES['default'] = dj_database_url.config(default='postgres://...'}` I would suggest a db dumb (https://stackoverflow.com/questions/11546151/how-to-make-db-dumpfile-in-django) to migrate all the data. – hansTheFranz Dec 02 '20 at 00:35
  • 1
    @MichaelTorres Because you're missing DATABASE_URL in your settings, which is explained in the documentation I linked. Not so strange I assumed you didn't read it now, is it? –  Dec 02 '20 at 00:38
  • @Melvyn Had that in my settings before and looked at docs many times and also researched on other sites. I know exactly what you are referring to and decided to get the name of the database on heroku and add that as a config var which is what I am doing and I have added the `django_heroku.settings(locals())` at the bottom of my settings. I haved updated my post to include this. – Michael Torres Dec 02 '20 at 18:26
  • @hansTheFranz It didn't work. I tried that before. Should have mentioned it in my post. – Michael Torres Dec 02 '20 at 18:26
  • The name is not the problem but the host, evident by the connection being tried to a local socket, instead of an IP/hostname. So in order to debug, get the actual settings: `heroku run /bin/sh -c 'echo "from django.conf import settings; print(settings.DATABASES);" |python3 manage.py shell'` –  Dec 02 '20 at 20:09
  • Have you managed to solve this? I'm having a similar issue. – MeL Jun 21 '22 at 00:10

0 Answers0