The error occurs because Django is trying to connect to the local PostgreSQL socket (/var/run/postgresql/.s.PGSQL.5432), which means it's looking for the database as if it were on the same machine. This usually happens when the database host is set as localhost or the database host environment variable is missing or not properly loaded.
Check the DB_HOST value inside your Django settings during server startup. Log or print this value to verify.
Make sure your environment variables (DB_NAME, DB_USER, DB_PASSWORD, DB_HOST, DB_PORT) are exported before running Daphne/server on your deployment (e.g., inside your start_app.sh).
Example:
export DB_NAME=yourdbname
export DB_USER=yourdbuser
export DB_PASSWORD=yourdbpassword
export DB_HOST=your-rds-endpoint.amazonaws.com
export DB_PORT=5432
Confirm that your settings.py is reading these variables via os.environ.get.
After updating, redeploy. If it still fails, log/print the values to debug.
The HOST value must match the RDS endpoint, not localhost or blank.
Your Django app defaults to connecting to the local database because it doesn't find the correct database host.
Set and export your environment variables with the correct database endpoint before starting your app to fix the issue.