Intermittent Database Connection Timeouts with n8n/Workers Template on Railway
financeiro-lgtm
PROOP

2 months ago

I am experiencing intermittent database connection timeouts between the Primary service and the Postgres database in my n8n/Workers setup on Railway.

This causes the n8n instance to become unavailable periodically.

The issue has been observed consistently in one of my deployments, while other companies using the same template are functioning normally.

I have reviewed the logs and identified multiple Database connection timed out errors.

Eventually, the database recovers, but the disruptions impact reliability.

Log Excerpt (from 2025-12-16 GMT-3):

  • Dec 16 2025 15:52:00 – Database connection timed out (multiple occurrences)

  • Dec 16 2025 15:52:23 – Database connection recovered

Additional Context:

  • I manage multiple deployments of this template, but only this specific instance is affected.

  • The issue occurs unpredictably and seems unrelated to load spikes or configuration changes.

  • I have not identified any misconfigurations or resource constraints specific to this deployment.

  1. Are there any known issues or incidents related to Postgres connectivity on Railway for this region/timeframe?

  2. Could I check the database instance health, network connectivity, or any resource limitations?

  3. Are there recommendations to improve connection stability for n8n on Railway?

Let me know if you need additional logs, project details, or access to the deployment for further debugging.

Thank you for your support!

Solved$30 Bounty

Pinned Solution

domehane
FREE

2 months ago

ok so add these env variables;

for your n8n primary service throw these in:

DB_POSTGRESDB_CONNECTION_TIMEOUT=60000

DB_POSTGRESDB_POOL_SIZE=10

DB_POSTGRESDB_MAX_POOL_SIZE=15

and on the postgres service add:

POSTGRES_MAX_WAL_SIZE=2GB

POSTGRES_CHECKPOINT_TIMEOUT=15min

POSTGRES_CHECKPOINT_COMPLETION_TARGET=0.9

then redeplot both services

11 Replies

financeiro-lgtm
PROOP

2 months ago

Log print

Attachments


uxuz
MODERATOR

2 months ago

Hey, Railway had an incident yesterday which could be the cause, if what you have experienced only started yesterday. If this is the case and you are still experiencing the issue now, then you would most likely want to redeploy your services to see if the issue still remains.


uxuz

Hey, Railway had an incident yesterday which could be the cause, if what you have experienced only started yesterday. If this is the case and you are still experiencing the issue now, then you would most likely want to redeploy your services to see if the issue still remains.

financeiro-lgtm
PROOP

2 months ago

This timeout issue has been happening since the services were created...
for almost 2 months now.

I just updated to the latest available versions of n8n and a patch for PostgreSQL 16 to 16.11.

I'll post any updates here.

Thanks.


financeiro-lgtm
PROOP

2 months ago

While I was writing my last response, it happened again lol.

I have no idea why this is happening.
It seems like something very specific to my project/deployment, as I can’t find any clues in the logs.

In the PostgreSQL logs, the only thing mentioned is checkpoint routines.
Some checkpoints are taking from 30s to 60s.

But the timestamps don’t match the timeouts.

n8n primary logs

2025-12-17T16:45:02.132013770Z [inf] Enqueued execution 5796 (job 5802)

2025-12-17T16:45:02.132021069Z [inf] Execution 5797 (job 5801) finished

2025-12-17T16:45:02.132026987Z [inf] Execution 5796 (job 5802) finished

2025-12-17T16:48:02.310980475Z [inf] Enqueued execution 5798 (job 5803)

2025-12-17T16:48:02.310988459Z [inf] Execution 5798 (job 5803) finished

2025-12-17T16:48:02.310994326Z [inf] Enqueued execution 5799 (job 5804)

2025-12-17T16:48:02.310999811Z [inf] Execution 5799 (job 5804) finished

2025-12-17T16:49:52.190239592Z [inf] Database connection timed out

2025-12-17T16:49:57.589638709Z [inf] Database connection timed out

2025-12-17T16:50:04.623691716Z [inf] Database connection timed out

2025-12-17T16:50:11.617088500Z [inf] Database connection timed out

2025-12-17T16:50:18.613441523Z [inf] Database connection timed out

2025-12-17T16:50:25.731960789Z [inf] Database connection timed out

2025-12-17T16:50:32.467696127Z [inf] Database connection timed out

2025-12-17T16:50:36.651494470Z [inf] timeout exceeded when trying to connect

2025-12-17T16:50:39.470113548Z [inf] Database connection timed out

2025-12-17T16:50:42.209308676Z [inf] Enqueued execution 5801 (job 5805)

2025-12-17T16:50:42.214611669Z [inf] Enqueued execution 5800 (job 5806)

2025-12-17T16:50:42.214625681Z [inf] Database connection recovered

2025-12-17T16:50:42.658914482Z [inf] Execution 5801 (job 5805) finished

2025-12-17T16:51:02.522095114Z [inf] Execution 5800 (job 5806) finished

2025-12-17T16:51:52.525290154Z [inf] Enqueued execution 5802 (job 5807)

2025-12-17T16:51:52.525301488Z [inf] Execution 5802 (job 5807) finished

Postgres log:

2025-12-17 16:35:11.559 UTC [2] LOG: database system is ready to accept connections

2025-12-17 16:40:11.627 UTC [23] LOG: checkpoint starting: time

2025-12-17 16:40:50.680 UTC [23] LOG: checkpoint complete: wrote 9 buffers (0.1%); 0 WAL file(s) added, 0 removed, 0 recycled; write=0.893 s, sync=0.017 s, total=39.054 s; sync files=4, longest=0.017 s, average=0.005 s; distance=1 kB, estimate=41 kB; lsn=0/3F0DE210, redo lsn=0/3F0DE1D8

2025-12-17 16:45:11.779 UTC [23] LOG: checkpoint starting: time

2025-12-17 16:46:09.721 UTC [23] LOG: checkpoint complete: wrote 575 buffers (3.5%); 0 WAL file(s) added, 0 removed, 0 recycled; write=57.504 s, sync=0.357 s, total=57.942 s; sync files=20, longest=0.309 s, average=0.018 s; distance=4293 kB, estimate=4293 kB; lsn=0/3F5124E8, redo lsn=0/3F50F680

2025-12-17 16:50:11.819 UTC [23] LOG: checkpoint starting: time

2025-12-17 16:50:48.727 UTC [23] LOG: checkpoint complete: wrote 62 buffers (0.4%); 0 WAL file(s) added, 0 removed, 0 recycled; write=5.599 s, sync=0.114 s, total=36.909 s; sync files=23, longest=0.114 s, average=0.005 s; distance=186 kB, estimate=3882 kB; lsn=0/3F56CD70, redo lsn=0/3F53E128

2025-12-17 16:55:11.827 UTC [23] LOG: checkpoint starting: time

2025-12-17 16:55:19.889 UTC [23] LOG: checkpoint complete: wrote 80 buffers (0.5%); 0 WAL file(s) added, 0 removed, 0 recycled; write=7.972 s, sync=0.022 s, total=8.062 s; sync files=20, longest=0.016 s, average=0.002 s; distance=612 kB, estimate=3555 kB; lsn=0/3F5D74C0, redo lsn=0/3F5D7488


domehane
FREE

2 months ago

what are your database env variables set to on the n8n primary service? specifically looking for DB_POSTGRESDB_CONNECTION_TIMEOUT, DB_POSTGRESDB_POOL_SIZE, and DB_POSTGRESDB_MAX_POOL_SIZE ; are these even set or just using defaults?


domehane

what are your database env variables set to on the n8n primary service? specifically looking for DB_POSTGRESDB_CONNECTION_TIMEOUT, DB_POSTGRESDB_POOL_SIZE, and DB_POSTGRESDB_MAX_POOL_SIZE ; are these even set or just using defaults?

financeiro-lgtm
PROOP

2 months ago

Thank you for your help.
All variables across all services are set to their defaults; I've never needed to change them.
Do you have any suggestions?


domehane
FREE

2 months ago

ok so add these env variables;

for your n8n primary service throw these in:

DB_POSTGRESDB_CONNECTION_TIMEOUT=60000

DB_POSTGRESDB_POOL_SIZE=10

DB_POSTGRESDB_MAX_POOL_SIZE=15

and on the postgres service add:

POSTGRES_MAX_WAL_SIZE=2GB

POSTGRES_CHECKPOINT_TIMEOUT=15min

POSTGRES_CHECKPOINT_COMPLETION_TARGET=0.9

then redeplot both services


domehane

ok so add these env variables;for your n8n primary service throw these in:DB_POSTGRESDB_CONNECTION_TIMEOUT=60000DB_POSTGRESDB_POOL_SIZE=10DB_POSTGRESDB_MAX_POOL_SIZE=15and on the postgres service add:POSTGRES_MAX_WAL_SIZE=2GBPOSTGRES_CHECKPOINT_TIMEOUT=15minPOSTGRES_CHECKPOINT_COMPLETION_TARGET=0.9then redeplot both services

financeiro-lgtm
PROOP

2 months ago

All set! I'll keep an eye on the logs and the system behavior. If anything comes up, I'll update you here. Thanks a lot!


domehane
FREE

2 months ago

okay let me know the result


financeiro-lgtm
PROOP

2 months ago

Looking good so far, no timeouts yet.
I'll keep watching it.
If we make it through today without issues, we can call it fixed!
Normally we'd have seen something by now – I'm really putting it through some heavy load tests

Thanks


domehane

ok so add these env variables;for your n8n primary service throw these in:DB_POSTGRESDB_CONNECTION_TIMEOUT=60000DB_POSTGRESDB_POOL_SIZE=10DB_POSTGRESDB_MAX_POOL_SIZE=15and on the postgres service add:POSTGRES_MAX_WAL_SIZE=2GBPOSTGRES_CHECKPOINT_TIMEOUT=15minPOSTGRES_CHECKPOINT_COMPLETION_TARGET=0.9then redeplot both services

financeiro-lgtm
PROOP

2 months ago

Fixed!

Thanks!


Status changed to Solved brody about 2 months ago


Loading...