Private networking: service cannot reach Postgres at postgres.railway.internal:5432 (works only via DATABASE_PUBLIC_URL)
eutieldenia-hub
HOBBYOP

9 days ago

Hi Railway team,

I’m having an issue with private networking between two services in the same project.

  • Project:Test para DANIA

  • Services involved:

    • Primary – n8n (Docker image n8nio/n8n)

    • Postgres – managed PostgreSQL from Railway

What I’m trying to do

I want my Primary (n8n) service to connect to the Postgres service using the internal hostpostgres.railway.internal:5432 over private networking.

What works

If I configure n8n to connect via the public proxy URL (DATABASE_PUBLIC_URL), everything works fine.

Current working DB config in Primary:

DB_TYPE=postgresdb
DB_POSTGRESDB_HOST=trolley.proxy.rlwy.net
DB_POSTGRESDB_PORT=15544
DB_POSTGRESDB_DATABASE=railway
DB_POSTGRESDB_USER=postgres
DB_POSTGRESDB_PASSWORD=BtGTaq1IfnnRO1gI_cnH09VENkw60p9y
DB_POSTGRESDB_SSL=true
DB_POSTGRESDB_SSL_REJECT_UNAUTHORIZED=false
DB_POSTGRESDB_CONNECTION_TIMEOUT=60000

With this configuration, n8n starts correctly and can use the database without any issues.

What doesn’t work (private networking)

When I switch to the internal connection, using the variables derived from DATABASE_URL:

DB_TYPE=postgresdb

DB_POSTGRESDB_HOST=postgres.railway.internal
DB_POSTGRESDB_PORT=5432
DB_POSTGRESDB_DATABASE=railway
DB_POSTGRESDB_USER=postgres
DB_POSTGRESDB_PASSWORD=BtGTaq1IfnnRO1gI_cnH09VENkw60p9y

DB_POSTGRESDB_CONNECTION_TIMEOUT=60000

(with no DB_POSTGRESDB_CONNECTION_STRING and no SSL variables)

and with Private Networking enabled on both services:

  • Postgres → Settings → Networking: Private networking ON

  • Primary → Settings → Networking: Private networking ON

  • ENABLE_ALPINE_PRIVATE_NETWORKING=true on Primary (from your template)

…then the n8n container fails to connect to Postgres and eventually times out.

Error logs from Primary (n8n)

When using postgres.railway.internal:5432 I consistently get:

There was an error initializing DB
Could not establish database connection within the configured timeout of 60,000 ms. Please ensure the database is configured correctly and the server is reachable. You can increase the timeout by setting the 'DB_POSTGRESDB_CONNECTION_TIMEOUT' environment variable.
Error: Could not establish database connection within the configured timeout of 60,000 ms.
    at DbConnection.init (...)
    at Start.init (...)
    at CommandRegistry.execute (...)
    at /usr/local/lib/node_modules/n8n/bin/n8n:63:2
Connection terminated due to connection timeout
Last session crashed
Initializing n8n process

Earlier, when I was experimenting with configs and before cleaning up the vars, I also saw:

There was an error initializing DB
connect ECONNREFUSED ::1:5432

But now, with only the internal host/port config above, the error is the timeout, not ECONNREFUSED.

Logs from Postgres service

At the same time, the Postgres logs show the database starting fine and listening on port 5432:

2025-11-26 16:54:04.643 UTC [3] LOG:  starting PostgreSQL 16.11 ...
2025-11-26 16:54:04.643 UTC [3] LOG:  listening on IPv4 address "0.0.0.0", port 5432
2025-11-26 16:54:04.643 UTC [3] LOG:  listening on IPv6 address "::", port 5432
2025-11-26 16:54:05.199 UTC [3] LOG:  database system is ready to accept connections

I don’t see any incoming connection attempts or authentication errors in the Postgres logs when n8n is trying to connect via the internal host, which suggests the packets never reach the DB service.

Summary

  • Private networking is enabled on both services.

  • Postgres is healthy and listening on 0.0.0.0:5432.

  • n8n can connect successfully when using the public proxy host/port with SSL.

  • When using the private host postgres.railway.internal:5432 from the Primary service, the connection times out.

  • It looks like the private networking / internal DNS between Primary and Postgres in this project is not working as expected.

Could you please:

  1. Check that private networking is correctly configured for this project and that Primary can resolve and reach postgres.railway.internal on port 5432?

  2. Confirm if there is any known issue with private networking for this stack (n8n + Postgres) or with Alpine networking in your environment?

I’m happy to provide the exact project ID, service IDs, or run any additional tests you need.

Thanks a lot in advance for your help!

$10 Bounty

10 Replies

Railway
BOT

9 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!


starphoneswebtech
PRO

9 days ago

Hello,

You are sharing your database credentials, I hope you are aware of that, if so please reset your db.

also can you verify two things:

  1. Ensure that n8n and Postgres are running in the same environment; internal DNS won’t work otherwise.

  2. Test the Postgres connection directly using railway run psql.

If the schema is broken there, restore or reset the database. If it isn’t, then it’s likely just a networking mismatch, and disabling SSL internally should resolve it.


eutieldenia-hub
HOBBYOP

9 days ago

Hi, thanks for the guidance.

First, I’ve rotated the Postgres credentials, so the values I shared earlier are no longer valid.

Per your suggestions I’ve checked the following:

  1. Same environment

Using the Railway CLI I linked the project:

railway link
# workspace: enrique utiel denia's Projects
# project: Test para DANIA
# environment: production
# service: Postgres

Both services (Primary – n8n and Postgres) are in the same project and in the same environment (production). They appear on the same canvas and share the same environment selector.

  1. Testing Postgres connection with railway run psql

From PowerShell on my machine:

railway run psql "$DATABASE_URL"

This uses the internal DATABASE_URL (the one that points to postgres.railway.internal:5432).

The result is:

psql: error: no se pudo traducir el nombre «postgres.railway.internal» a una dirección: Name or service not known

So even inside railway run the hostname postgres.railway.internal cannot be resolved.

For clarity:

  • When I configure n8n to use the public proxy URL (DATABASE_PUBLIC_URL) with SSL, everything works fine and n8n can use the database.

  • When I configure n8n to use the internal host:

DB_TYPE=postgresdb
DB_POSTGRESDB_HOST=postgres.railway.internal
DB_POSTGRESDB_PORT=5432
DB_POSTGRESDB_DATABASE=railway
DB_POSTGRESDB_USER=postgres
DB_POSTGRESDB_PASSWORD=<************>
DB_POSTGRESDB_CONNECTION_TIMEOUT=60000
# SSL disabled for the internal connection as suggested

n8n cannot connect and times out, and the railway run psql "$DATABASE_URL" command fails with the “Name or service not known” error above.

Given this, it looks like the issue is not with SSL or the schema, but with internal DNS / private networking for postgres.railway.internal in this environment.

Could you please check why postgres.railway.internal is not resolvable from the production environment of the Test para DANIA project, and whether there is any misconfiguration on private networking for this project?

I’m happy to run any additional commands you need and share the output.

Thanks again for your help!


shmbrg
PRO

5 days ago

Is there any update on this issue? It seems like I'm facing the exact same issue.


shmbrg

Is there any update on this issue? It seems like I'm facing the exact same issue.

eutieldenia-hub
HOBBYOP

5 days ago

No, I haven't found information on how to solve the problem, but I haven't received any help. The only solution at the moment is to work with public networking.


eutieldenia-hub

No, I haven't found information on how to solve the problem, but I haven't received any help. The only solution at the moment is to work with public networking.

shmbrg
PRO

5 days ago

Thanks for the hint. I was able to set all connections (including workers) to public, so now my workflows execute again. This is really odd, as I haven't changed anything to the configuration.

While debugging, I've also deployed a complete fresh infrastructure project from the template "N8N (w/ workers)" and ran into the same private endpoint connection issues. This seems to be a bigger problem.


shmbrg
PRO

4 days ago


Update: This is my current project. First the private connection of the Primary and the Worker instances to Postgres wouldn't work. I fixed this using the public endpoints. Today also the private connection to Redis stopped working. The fix is again using a public connection.

Is there an issue with private connections?

Attachments


shmbrg

Update: This is my current project. First the private connection of the Primary and the Worker instances to Postgres wouldn't work. I fixed this using the public endpoints. Today also the private connection to Redis stopped working. The fix is again using a public connection.Is there an issue with private connections?

eutieldenia-hub
HOBBYOP

4 days ago

Good morning. It seems that's the case, and I'm not the only one with this problem. Let's see if Railway can tell us what's going on...


shmbrg

Update: This is my current project. First the private connection of the Primary and the Worker instances to Postgres wouldn't work. I fixed this using the public endpoints. Today also the private connection to Redis stopped working. The fix is again using a public connection.Is there an issue with private connections?

starphoneswebtech
PRO

3 days ago

Private connection with redis works when you add ?family=0


dmenisdev
FREE

17 hours ago

New to Railway I deployed a PostgreSQL using the Railway template and I had a private network url. I came back to it the next day and in the setting I see "failed to get private networks". It is very worrying that this sudden happens and even more so that I see that this was reported days ago.


Loading...