18 days ago
Hey, my PostgreSQL service is completely down since today.
The dashboard shows "We are unable to connect to the database via SSH"
and I can't restart or redeploy the service — nothing works.
My web app is also down because of this, gunicorn workers keep timing
out trying to reach postgres.railway.internal:5432.
Has anyone seen this before? Is there a way to force restart the
Postgres service from the CLI or API?
2 Replies
18 days ago
I'm having this problem too https://station.railway.com/questions/postgres-redeploy-appears-stuck-pg-boun-8530ee6c
Status changed to Awaiting User Response Railway • 18 days ago
18 days ago
Hey everyone, posting the full solution since I had multiple issues
stacking on top of each other. Hopefully this helps someone else.
Symptoms:
- Build failing on deploy
- Gunicorn WORKER TIMEOUT every 5 minutes
- "Unable to connect to database via SSH" in the dashboard
Root cause #1 - Python attestation (build failure)
mise 2026.6.11 introduced attestation verification for GitHub artifacts.
If your runtime.txt is pinned to an older Python version (e.g. 3.10.13),
the build will fail.
Fix: update runtime.txt to python-3.13.5
Root cause #2 - flask db upgrade hanging at startup
The Procfile runs flask db upgrade before gunicorn. If Postgres isn't
ready yet, it blocks indefinitely and the build times out.
Fix: replace the direct command with a retry script (migrate.sh):
#!/usr/bin/env bash
set -e
MAX_ATTEMPTS=5
DELAY=2
attempt=1
until flask db upgrade; do
if [ "$attempt" -ge "$MAX_ATTEMPTS" ]; then
echo "[migrate] Failed after $MAX_ATTEMPTS attempts."
exit 1fi
echo "[migrate] Attempt $attempt failed. Retrying in ${DELAY}s..."
sleep "$DELAY"
DELAY=$(( DELAY * 2 ))
attempt=$(( attempt + 1 ))
done
Then in your Procfile:
web: cd backend && bash migrate.sh && gunicorn app:app --bind 0.0.0.0:$PORT
Root cause #3 - gunicorn workers timing out
Even after the build, if Postgres is slow to respond, the app's seed/init
code blocks the worker past gunicorn's timeout (default 30s).
Fix: add connect_timeout to your SQLAlchemy engine options:
if database_url:
engine_options['connect_args'] = {'connect_timeout': 5}This makes connection failures fast (5s) instead of hanging forever.
All three fixes together got the app back online. Good luck!
Status changed to Awaiting Railway Response Railway • 18 days ago
Status changed to Solved lucascarv1804 • 18 days ago