I'm deploying to AWS Linux 2023 and my postgresql database in on aws RDS. I've installed psql and checked if db is accessible in my instance. I've also checked that the environmental variables are fetching exactly as expected in my settings.py. and I even ssh and applied the migrations myself. but I keep getting the following issue:
[stderr] raise dj_exc_value.with_traceback(traceback) from exc_value
[stderr] File "/home/ec2-user/.local/share/virtualenvs/app-UPB06Em1/lib/python3.13/site-packages/django/db/backends/base/base.py", line 279, in ensure_connection
[stderr] self.connect()
[stderr] ~~~~~~~~~~~~^^
[stderr] File "/home/ec2-user/.local/share/virtualenvs/app-UPB06Em1/lib/python3.13/site-packages/django/utils/asyncio.py", line 26, in inner
[stderr] return func(*args, **kwargs)
[stderr] File "/home/ec2-user/.local/share/virtualenvs/app-UPB06Em1/lib/python3.13/site-packages/django/db/backends/base/base.py", line 256, in connect
[stderr] self.connection = self.get_new_connection(conn_params)
[stderr] ~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^
[stderr] File "/home/ec2-user/.local/share/virtualenvs/app-UPB06Em1/lib/python3.13/site-packages/django/utils/asyncio.py", line 26, in inner
[stderr] return func(*args, **kwargs)
[stderr] File "/home/ec2-user/.local/share/virtualenvs/app-UPB06Em1/lib/python3.13/site-packages/django/db/backends/postgresql/base.py", line 332, in get_new_connection
[stderr] connection = self.Database.connect(**conn_params)
[stderr] File "/home/ec2-user/.local/share/virtualenvs/app-UPB06Em1/lib64/python3.13/site-packages/psycopg2/__init__.py", line 122, in connect
[stderr] conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
[stderr]django.db.utils.OperationalError: connection to server on socket "/var/run/postgresql/.s.PGSQL.5432" failed: No such file or directory
[stderr] Is the server running locally and accepting connections on that socket?
[stderr]
[stderr]2025-10-19 04:29:22,032 INFO Starting server at tcp:port=8000:interface=127.0.0.1
[stderr]2025-10-19 04:29:22,032 INFO HTTP/2 support not enabled (install the http2 and tls Twisted extras)
[stderr]2025-10-19 04:29:22,033 INFO Configuring endpoint tcp:port=8000:interface=127.0.0.1
[stderr]2025-10-19 04:29:22,033 INFO Listening on TCP address 127.0.0.1:8000
settings.py:
...
DATABASES = {
"default": {
"ENGINE": "django.db.backends.postgresql",
"NAME": DB_NAME,
"USER": DB_USER,
"PASSWORD": DB_PASSWORD,
"HOST": DB_HOST,
"PORT": DB_PORT,
}
}
...
any possible ideas why this issue is happening?
Edit: I'm using daphne to run the app and codedeploy to deploy the app. also note that the migration didn't get applied when code deploy run my start_app.sh
- python3.13
- pipenv
my start_app.sh:
cd /home/ec2-user/app
if [ ! -f /etc/ssl/private/privkey.pem ]; then
sudo mkdir -p /etc/ssl/private /etc/ssl/certs
sudo openssl req -x509 -nodes -days 365 \
-newkey rsa:2048 \
-keyout /etc/ssl/private/privkey.pem \
-out /etc/ssl/certs/fullchain.pem \
-subj "/C=US/ST=State/L=City/O=MyOrg/OU=MyDept/CN=localhost"
sudo chmod 600 /etc/ssl/private/privkey.pem
sudo chmod 644 /etc/ssl/certs/fullchain.pem
fi
python3.13 -m pipenv install --deploy --ignore-pipfile
python3.13 -m pipenv run python manage.py migrate
pkill -f daphne || true
python3.13 -m pipenv run daphne -b 127.0.0.1 -p 8000 core.asgi:application &
DAPHNE_PID=$!
# Check if the process is still running
sleep 10
if ! kill -0 "$DAPHNE_PID" 2>/dev/null; then
echo "Daphne failed to start — exiting."
exit 1
fi
sudo systemctl restart nginx