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

6 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

6 months ago

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 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:@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.

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:@postgres.railway.internal:5432/railway?pgbouncer=true&sslmode=disable

Then regenerate Prisma:

npx prisma generate

And redeploy.

Additional things to check

🔄 Restart your Postgres instance

Railway → Your Postgres Service → Restart

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

🔍 Look for long-running queries or stuck migrations

Run:

railway psql

Then:

SELECT pid, query FROM pg_stat_activity;

Kill anything that’s stuck.

🚦 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.

The connection string that fixes 90% of these cases

Try this first:

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

Then redeploy your backend.

3 Replies

Railway
BOT

6 months 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!


6 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 6 months ago


devmuktary
HOBBY

6 months ago

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 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:@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.

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:@postgres.railway.internal:5432/railway?pgbouncer=true&sslmode=disable

Then regenerate Prisma:

npx prisma generate

And redeploy.

Additional things to check

🔄 Restart your Postgres instance

Railway → Your Postgres Service → Restart

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

🔍 Look for long-running queries or stuck migrations

Run:

railway psql

Then:

SELECT pid, query FROM pg_stat_activity;

Kill anything that’s stuck.

🚦 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.

The connection string that fixes 90% of these cases

Try this first:

postgresql://postgres:@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 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. 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 🔄 Restart your Postgres instance Railway → Your Postgres Service → Restart If it was stuck in a crash/recovery loop, this often clears it. 🔍 Look for long-running queries or stuck migrations Run: railway psql Then: SELECT pid, query FROM pg\_stat\_activity; Kill anything that’s stuck. 🚦 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. 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.

matiasmaquieira
PROOP

6 months ago

It is working now. Thank you!


Status changed to Solved noahd 6 months ago


Welcome!

Sign in to your Railway account to join the conversation.

Loading...