My app can't reach its database
“ECONNREFUSED 127.0.0.1:5432”, “dial tcp [::1]:5432: connection refused”, “database is stopped”.
The app looks for the database on localhost
What you see
connect ECONNREFUSED 127.0.0.1:5432, dial tcp [::1]:5432: connect: connection refused, SQLSTATE[HY000] [2002] Connection refused.
Why
There's no database inside your app's container. The app falls back to localhost because it didn't get a database address: no database is linked, or the address it reads is empty or wrong.
Fix
1. Link a database in the project's Database tab (create one if you have none).
2. In Variables, delete any DATABASE_URL or DB_HOST you set yourself: they override the linked database's.
3. Redeploy.
DATABASE_URL holds something that isn't a URL
What you see
Your app logs that DATABASE_URL is set but the connection goes to localhost.
Why
The value is only a database name (like my_db) or a partial address. Drivers read a value without a host as "localhost".
Fix
Delete your DATABASE_URL in Variables. The linked database gives the full one, postgresql://user:password@host:5432/database. Redeploy.
The database is stopped
What you see
The deploy stops with “Your database … is stopped, so your app can't reach it”.
Why
You stopped it, or it was stopped because it grew past its plan's storage.
Fix
Start it from Databases. If it was stopped for storage, delete data or move to a plan with more storage first. Then deploy again.
It works locally but not here
What you see
Authentication fails, or the database name is wrong.
Why
The code uses your local credentials (root with no password, a fixed database name).
Fix
Read every connection setting from the variables: DB_HOST, DB_PORT, DB_DATABASE, DB_USERNAME, DB_PASSWORD, or just DATABASE_URL.
Moving from the old DockHosting platform?
Databases weren't moved automatically to the new platform. Create a new database here and import your data. See Import an existing database, or ask Support for help with your old data.
