Still Getting ECONNREFUSED Connecting Backend to Postgres Plugin (Same Project, All Config Correct)

wrapped-up-gifting
PRO

10 days ago

  • Project name: Main Wrapped Up test

  • Backend service: gifting-ai-platform

  • Database plugin: Postgres (in the same project, status: Running)

  • DATABASE_URL: Set in backend service to the full connection string from the plugin’s Connect tab (tried both internal and proxy hostnames, port 5432, with and without ?ssl=true)

  • No other DB variables (like DB_HOST, DB_USER, etc.) are set.

  • Backend code uses: process.env.DATABASE_URL for the Sequelize connection.

  • Error Log: Unable to connect to the database: ConnectionRefusedError [SequelizeConnectionRefusedError]

    code: 'ECONNREFUSED'
    Both services appear in the same project sidebar (see attached screenshot).

  • Postgres plugin is running and shows as ready.

  • I have tried:

  • Restarting both backend and Postgres plugin

  • Removing and re-adding the Postgres plugin

  • Using both internal and proxy hostnames in the connection string

  • Waiting for the database to be fully ready

  • Confirming all environment variables and code are correct

  • Testing connection locally (works from my machine)

Request:

Could you please check for any internal networking issues, stuck containers, or misconfigurations in my project?

Is there anything else I should try to resolve this connection problem?

Thank you for your help!

$10 Bounty

13 Replies

Railway
BOT

10 days ago

Hey there! We've found the following might help you get unblocked faster:

If you find the answer from one of these, please let us know by solving the thread!


wrapped-up-gifting
PRO

10 days ago

these do not resolve my request - can i access pro help?


10 days ago

Heya, unfortunately we cannot offer application-level support due to volume. I've pushed this thread to our community bounty board for you.


Status changed to Awaiting User Response Railway 10 days ago


wrapped-up-gifting
PRO

10 days ago

Can i pay to be bumped up the application level support?


clashing
FREETop 1% Contributor

10 days ago

Can you provide the screenshot of the variables tab of your deployed service? I guess it's some variable issue


wrapped-up-gifting
PRO

9 days ago

Please find a screenshot of variables attached


wrapped-up-gifting

Please find a screenshot of variables attached

clashing
FREETop 1% Contributor

9 days ago

Please delete that one, as it contains the value for the variables too!! Not good to share that in public domain.

Also provide the screenshot of how you are initializing the server file, and using the variables in there.


wrapped-up-gifting
PRO

9 days ago

Thanks for the heads up - I deleted it. I am using a root directory and then there is a .env and .json file that have the build and start commands - let me know if we can chat directly, I would love to walk you through it!


clashing
FREETop 1% Contributor

9 days ago

That would be great. But I guess, we can resolve it here only


clashing
FREETop 1% Contributor

9 days ago

Sequelize expects postgres://, not postgresql://.

So, can you try by changing the variable? The databse URI should be: postgres://postgres:<your-password>@postgres.railway.internal:5432/railway

And if you have configured a shared variable for the database, then why are you using a hard-coded variable in the service deployment? After doing the concerned change in the shared variable of postgresql to postgres, use the same in the server deployment.

Click on the shared variables part, and then add that shared variable into the required service. (above screenshot is for reference)

I hope that would resolve the issue


wrapped-up-gifting
PRO

9 days ago

Thanks for the tip! Sadly it didn't with new error logs below - should perhaps all of my environment variables be under project setttings shared variable database or are the rest ok in server deployment?

You reached the start of the range → Jul 25, 2025, 11:01 PM

Starting Container

npm warn config production Use --omit=dev instead.

> gifting-ai-platform@1.0.0 start

> node index.js

=== AWS Credentials Debug ===

AWS_ACCESS_KEY_ID: SET

AWS_SECRET_ACCESS_KEY: SET

AWS_REGION: us-east-1

===========================

Starting Image Analysis Service...

Creating RekognitionService instance...

Initializing RekognitionService...

RekognitionService initialized successfully

RekognitionService created successfully

Static files served from: /

Initializing repository...

(node:15) NOTE: The AWS SDK for JavaScript (v2) is in maintenance mode.

SDK releases are limited to address critical bug fixes and security issues only.

Please migrate your code to use AWS SDK for JavaScript (v3).

For more information, check the blog post at https://a.co/cUPnyil

(Use node --trace-warnings ... to show where the warning was created)

Unable to connect to the database: ConnectionRefusedError [SequelizeConnectionRefusedError]

at Client._connectionCallback (/app/node_modules/sequelize/lib/dialects/postgres/connection-manager.js:133:24)

at Client._handleErrorWhileConnecting (/app/node_modules/pg/lib/client.js:336:19)

at Client._handleErrorEvent (/app/node_modules/pg/lib/client.js:346:19)

at Connection.emit (node:events:518:28)

at Connection.emit (node:domain:489:12)

at Socket.reportStreamError (/app/node_modules/pg/lib/connection.js:57:12)

at Socket.emit (node:events:518:28)

at Socket.emit (node:domain:489:12)

at emitErrorNT (node:internal/streams/destroy:169:8)

at emitErrorCloseNT (node:internal/streams/destroy:128:3) {

parent: AggregateError [ECONNREFUSED]:

at internalConnectMultiple (node:net:1122:18)

at afterConnectMultiple (node:net:1689:7) {

code: 'ECONNREFUSED',

[errors]: [ [Error], [Error] ]

},

original: AggregateError [ECONNREFUSED]:

at internalConnectMultiple (node:net:1122:18)

at afterConnectMultiple (node:net:1689:7) {

code: 'ECONNREFUSED',

[errors]: [ [Error], [Error] ]

}

}

Failed to connect to database. Exiting...

npm warn config production Use --omit=dev instead.

> gifting-ai-platform@1.0.0 start


wrapped-up-gifting
PRO

9 days ago

Editing code error to previous comment


clashing

Sequelize expects postgres://, not postgresql://.So, can you try by changing the variable? The databse URI should be: postgres://postgres:<your-password>@postgres.railway.internal:5432/railwayAnd if you have configured a shared variable for the database, then why are you using a hard-coded variable in the service deployment? After doing the concerned change in the shared variable of postgresql to postgres, use the same in the server deployment.Click on the shared variables part, and then add that shared variable into the required service. (above screenshot is for reference)I hope that would resolve the issue

wrapped-up-gifting
PRO

7 days ago

Hi mate - i responded to the comment chain but i realize not you! I moved over all environment variables and made the change you suggested and am still getting errors. Any other suggestions?