Sporadic issue - gunicorn trying to use non-existent database

I’m seeing a sporadic issue with my Django 4.2 app (ifbt.farm) hosted at Digital Ocean. The application connects to a Digital Ocean database cluster. I’ve never had an issue with GET requests, but sometimes when I try to POST an update to the database, I see a 500 error and the gunicorn log shows “connection to server at “localhost” (::1), port 5432 failed: Connection refused”. But Django should never try to connect to postgresql on localhost 5432 because I only have one database configured, and it’s on a different host and port.

DATABASES = {
  'default': {
    'ENGINE': 'django.db.backends.postgresql_psycopg2',
    'NAME': 'ifbt',
    'HOST': '[db-postgresql-sfo3-41894-do-user-14116213-0.b.db.ondigitalocean.com](https://db-postgresql-sfo3-41894-do-user-14116213-0.b.db.ondigitalocean.com)',
    'PORT': '25060',
    'USER': '*************',
    'PASSWORD': '**************',
  }
}

At one time, I did have postgresql installed on this node, but have disabled the local postgresql service and uninstalled/purged postgresql, postgresql-contrib, etc… I doubt if this is a Django issue, but just wondered if anyone else has run across anything like it.

Do you have a typo in the HOST value of your database settings? It looks like it is a markdown link. I’m not sure what psycopg2 does with that, but trying to connect to localhost if it can’t parse the host seems possible.

Thanks for the reply @massover – the host name in the settings was actually OK. I found my error. I had a couple places in my code where I was connecting using the psycopg2 driver directly and had hardcoded the host as localhost and the port as ‘’ (defaulting to 5432). Just a dumb mistake on my part.

The actual setting isn’t a markdown link, I think I must have copy/pasted from a DigitalOcean ticket which converted the url to markdown. Sorry for the confusion! Not my best today :frowning: