10 months ago
Issue Summary
Unable to connect to PostgreSQL database using internal network (postgres.railway.internal:5432) during application deployment and runtime. Public database URL works correctly, but internal connection consistently fails.
Error Details
Error Message:
Error: P1001: Can't reach database server at `postgres.railway.internal:5432`
Please make sure your database server is running at `postgres.railway.internal:5432`.
When it occurs:
- During build process when running
npx prisma migrate deploy - At application startup when attempting database operations
- Consistently fails with internal URL, works with public URL
Environment Information
Project Setup:
- Project Name: chaos-whisper
- Services:
- Next.js application (chaos-whisper)
- PostgreSQL database (Postgres)
- Both services are in the same Railway project
- Database service status: Active (green checkmark)
- Application deployment method: GitHub integration
Database Configuration:
- PostgreSQL service is running normally (verified via Railway dashboard)
- Database can be accessed via
DATABASE_PUBLIC_URL - Database cannot be accessed via
DATABASE_URL(internal) - Railway dashboard shows "You have no tables" because migrations fail
What I've Tried
- Verified Environment Variables:
- Confirmed
DATABASE_URLis set as variable reference:${{Postgres.DATABASE_URL}} - Double-checked connection string format
- Verified credentials match between public and internal URLs
- Confirmed
- Tested Connection Methods:
DATABASE_PUBLIC_URL: Works perfectlyDATABASE_URL(internal): Connection timeout- Database service health: Normal operation
- Deployment Strategy Changes:
- Moved database operations from build time to runtime
- Added connection retry logic
- Attempted different timing approaches
- Network Diagnostics:
- Confirmed both services are in same project
- No custom network isolation configured
- DNS resolution for
postgres.railway.internalappears to fail
Expected Behavior
The application should be able to connect to PostgreSQL using the internal network URL (postgres.railway.internal:5432) for:
- Database migrations during deployment
- Runtime database operations
- Better performance and security compared to public URL
Current Workaround
Using DATABASE_PUBLIC_URL as a temporary solution, but this is not ideal for production due to:
- Higher latency through public internet
- Security implications
- Not following Railway best practices
Request
Please investigate why the internal database connection is failing and help restore proper internal network connectivity between my Next.js application and PostgreSQL service.
Additional Information
Connection String Format (sanitized):
Internal (failing): postgresql://postgres:***@postgres.railway.internal:5432/railway
Public (working): postgresql://postgres:***@[public-host]:5432/railway
Application Stack:
- Next.js 15.3.5
- Prisma 6.11.1
- PostgreSQL (Railway managed)
Thank you for your assistance in resolving this internal networking issue.
2 Replies
10 months ago
Hey there! We've found the following might help you get unblocked faster:
- 🧵 Persistent Network Connection Failure
- 🧵 DB CONNECTION FAILURE
- 🧵 Unable to Connect to postgres.railway.internal (Connection Timed Out)
If you find the answer from one of these, please let us know by solving the thread!
Status changed to Solved vzheng56 • 10 months ago
Status changed to Awaiting Railway Response Railway • 10 months ago
Status changed to Solved vzheng56 • 10 months ago