Critical: Postgres crashes, SSL EOF errors & connection resets using default internal URL
matiasmaquieira
PROOP

3 months ago

Hi,

I’m experiencing severe instability with my Postgres instance on Railway.

I am using the default internal connection URL provided by Railway:

postgresql://postgres:<password>@postgres.railway.internal:5432/railway

No parameters added — exactly as provided.

With this connection string, the backend starts failing continuously with:

  • 502 Bad Gateway – Application failed to respond

  • Prisma connection timeouts

  • Frontend failing to fetch API data

  • General DB connection failures

Postgres logs show ongoing crashes and connection resets:

Examples from the logs:

  • could not receive data from client: Connection reset by peer

  • could not accept SSL connection: EOF detected

  • Repeated database restarts and recovery cycles:

    • database system was not properly shut down; automatic recovery in progress

    • redo starts at…

    • invalid record length… expected at least 24, got 0

    • database system is ready to accept connections

These events happen repeatedly every few minutes.
It appears the Postgres server is crashing, restarting, and entering recovery loops.

This behavior began after removing the previously appended sslmode=require, but the issue persists even though this is an internal-only connection (postgres.railway.internal) which should not require SSL.

At this point, the database is unstable and causing production outages.

Thanks in advance for your help diagnosing this.

Solved$10 Bounty

Pinned Solution

devmuktary
HOBBY

3 months ago

Hi! Sorry you’re dealing with this, the issues you’re describing usually come down to two common causes on Railway:

white_check_mark emoji 1. Too many database connections

Railway Postgres has a relatively low connection limit. When your app exceeds it, you’ll see errors like:

• connection reset by peer

• Prisma timeouts

• 502 errors from your backend

• Postgres restarting or going into recovery

Prisma, in particular, opens multiple connections per instance. So if you have:

• multiple backend replicas

• a serverless frontend hitting your API frequently

• long-lived Prisma clients

…your database can get overwhelmed pretty quickly.

How to fix it

Use Prisma’s connection pooling by adding ?pgbouncer=true to your Postgres URL — even when using internal connections:

postgresql://postgres:<password>@postgres.railway.internal:5432/railway?pgbouncer=true

After updating your URL, redeploy your backend so Prisma reconnects using the pool.

This usually stabilizes the database immediately.

white_check_mark emoji 2. SSL mismatch after changing your connection string

You mentioned that the problems started after removing sslmode=require.

If your app or your Prisma client was previously set up expecting SSL, removing it can cause handshake failures like:

could not accept SSL connection: EOF detected

How to fix it

Explicitly disable SSL to avoid mismatched negotiation:

?sslmode=disable

Combined with pgbouncer:

postgresql://postgres:<password>@postgres.railway.internal:5432/railway?pgbouncer=true&sslmode=disable

Then regenerate Prisma:

npx prisma generate

And redeploy.

Additional things to check

arrows_counterclockwise emoji Restart your Postgres instance

Railway → Your Postgres Service → Restart

If it was stuck in a crash/recovery loop, this often clears it.

mag emoji Look for long-running queries or stuck migrations

Run:

railway psql

Then:

SELECT pid, query FROM pg_stat_activity;

Kill anything that’s stuck.

vertical_traffic_light emoji If the issue still persists

If even with pooling + sslmode=disable Postgres keeps restarting, it may point to:

• WAL/redo log corruption

• a partially applied migration

• the instance hitting memory limits

These can make Postgres crash repeatedly.

white_check_mark emoji The connection string that fixes 90% of these cases

Try this first:

postgresql://postgres:<password>@postgres.railway.internal:5432/railway?pgbouncer=true&sslmode=disable

Then redeploy your backend.

3 Replies

Railway
BOT

3 months ago


3 months ago

This thread has been marked as public for community involvement, as it does not contain any sensitive or personal information. Any further activity in this thread will be visible to everyone.

Status changed to Open ray-chen 3 months ago


devmuktary
HOBBY

3 months ago

Hi! Sorry you’re dealing with this, the issues you’re describing usually come down to two common causes on Railway:

white_check_mark emoji 1. Too many database connections

Railway Postgres has a relatively low connection limit. When your app exceeds it, you’ll see errors like:

• connection reset by peer

• Prisma timeouts

• 502 errors from your backend

• Postgres restarting or going into recovery

Prisma, in particular, opens multiple connections per instance. So if you have:

• multiple backend replicas

• a serverless frontend hitting your API frequently

• long-lived Prisma clients

…your database can get overwhelmed pretty quickly.

How to fix it

Use Prisma’s connection pooling by adding ?pgbouncer=true to your Postgres URL — even when using internal connections:

postgresql://postgres:<password>@postgres.railway.internal:5432/railway?pgbouncer=true

After updating your URL, redeploy your backend so Prisma reconnects using the pool.

This usually stabilizes the database immediately.

white_check_mark emoji 2. SSL mismatch after changing your connection string

You mentioned that the problems started after removing sslmode=require.

If your app or your Prisma client was previously set up expecting SSL, removing it can cause handshake failures like:

could not accept SSL connection: EOF detected

How to fix it

Explicitly disable SSL to avoid mismatched negotiation:

?sslmode=disable

Combined with pgbouncer:

postgresql://postgres:<password>@postgres.railway.internal:5432/railway?pgbouncer=true&sslmode=disable

Then regenerate Prisma:

npx prisma generate

And redeploy.

Additional things to check

arrows_counterclockwise emoji Restart your Postgres instance

Railway → Your Postgres Service → Restart

If it was stuck in a crash/recovery loop, this often clears it.

mag emoji Look for long-running queries or stuck migrations

Run:

railway psql

Then:

SELECT pid, query FROM pg_stat_activity;

Kill anything that’s stuck.

vertical_traffic_light emoji If the issue still persists

If even with pooling + sslmode=disable Postgres keeps restarting, it may point to:

• WAL/redo log corruption

• a partially applied migration

• the instance hitting memory limits

These can make Postgres crash repeatedly.

white_check_mark emoji The connection string that fixes 90% of these cases

Try this first:

postgresql://postgres:<password>@postgres.railway.internal:5432/railway?pgbouncer=true&sslmode=disable

Then redeploy your backend.


devmuktary

Hi! Sorry you’re dealing with this, the issues you’re describing usually come down to two common causes on Railway:1. Too many database connectionsRailway Postgres has a relatively low connection limit. When your app exceeds it, you’ll see errors like:• connection reset by peer• Prisma timeouts• 502 errors from your backend• Postgres restarting or going into recoveryPrisma, in particular, opens multiple connections per instance. So if you have:• multiple backend replicas• a serverless frontend hitting your API frequently• long-lived Prisma clients…your database can get overwhelmed pretty quickly.How to fix itUse Prisma’s connection pooling by adding ?pgbouncer=true to your Postgres URL — even when using internal connections:postgresql://postgres:<password>@postgres.railway.internal:5432/railway?pgbouncer=trueAfter updating your URL, redeploy your backend so Prisma reconnects using the pool.This usually stabilizes the database immediately.2. SSL mismatch after changing your connection stringYou mentioned that the problems started after removing sslmode=require.If your app or your Prisma client was previously set up expecting SSL, removing it can cause handshake failures like:could not accept SSL connection: EOF detectedHow to fix itExplicitly disable SSL to avoid mismatched negotiation:?sslmode=disableCombined with pgbouncer:postgresql://postgres:<password>@postgres.railway.internal:5432/railway?pgbouncer=true&sslmode=disableThen regenerate Prisma:npx prisma generateAnd redeploy.Additional things to checkRestart your Postgres instanceRailway → Your Postgres Service → RestartIf it was stuck in a crash/recovery loop, this often clears it.Look for long-running queries or stuck migrationsRun:railway psqlThen:SELECT pid, query FROM pg_stat_activity;Kill anything that’s stuck.If the issue still persistsIf even with pooling + sslmode=disable Postgres keeps restarting, it may point to:• WAL/redo log corruption• a partially applied migration• the instance hitting memory limitsThese can make Postgres crash repeatedly.The connection string that fixes 90% of these casesTry this first:postgresql://postgres:<password>@postgres.railway.internal:5432/railway?pgbouncer=true&sslmode=disableThen redeploy your backend.

matiasmaquieira
PROOP

3 months ago

It is working now. Thank you!


Status changed to Solved noahd 3 months ago


Loading...