Your web application runs without a hitch in the Replit workspace. You press "Run", the API answers, the tables query cleanly, and the frontend renders mock data. Then you click "Deploy", watch the build succeed, open the live .replit.app URL, and get slammed with a 500 internal server error or a crash loop: ECONNREFUSED, ETIMEDOUT, relation "users" does not exist, or an abrupt SSL handshake failure.
At 365Finds, we see this exact breakdown trip up developers more than almost any other deployment issue on Replit. It feels like a platform bug. In reality, it is the direct consequence of Replit's strict operational boundary between interactive development and production.
Replit runs your live application in a separate container environment, on dynamic cloud IPs, with independent secrets, and—if you use Replit's managed PostgreSQL—against a completely separate production database instance. When a deployment fails to talk to your database, one of five specific boundaries has broken. Here is how to diagnose and fix each one.
1. The Missing Environment Variable: Workspace Secrets vs. Deployment Secrets
The most common reason a deployed Replit app cannot find its database is deceptively simple: your application does not have the connection string.
In Replit, the secrets you define inside the workspace (Tools > Secrets) are scoped exclusively to the development container. They do not automatically carry over to your production deployment. If your code expects process.env.DATABASE_URL or os.environ["DATABASE_URL"], that variable evaluates to undefined or an empty string in production, causing your ORM or database driver to attempt a fallback connection to localhost:5432—which immediately throws ECONNREFUSED.
The Fix
- Open your project in the Replit workspace.
- Click the Deployments tool in the left sidebar (or click your deployment status in the top bar).
- In your active deployment or deployment draft, open the Configuration or Settings pane.
- Locate the Deployment Secrets section.
- If you are using an external database (Supabase, Neon, AWS RDS, MongoDB Atlas, PlanetScale), verify that
DATABASE_URLis explicitly defined here with your production credentials. - Click Redeploy to build and spin up a new container with the updated environment variables.
365Finds Rule of Thumb: If you are using Replit's built-in PostgreSQL, do not manually paste a connection string into Deployment Secrets. Replit automatically provisions and injects the production
DATABASE_URLfor managed databases. Manually overriding it often binds production to a stalled dev database.
2. The Dual-Database Trap: Unapplied Migrations on the Production Database
When you spin up a managed PostgreSQL database inside Replit, Replit does not share that database with your deployed app. It creates a dual-database architecture:
- Development Database: An isolated development instance (often backed by Helium or a Neon development branch) connected to your workspace editor and Replit Agent.
- Production Database: A dedicated instance (backed by Neon) connected exclusively to your deployed application.
When you hit "Publish", your app connects to an authentic, fresh production database. If you built your schema in development using manual SQL scripts, ORM push commands (prisma db push, drizzle-kit push), or ad-hoc seeds, the production database starts completely empty. Your application boots, runs a SELECT * FROM users query during health checks or session initialization, and immediately crashes with:
error: relation "users" does not exist
The Fix
You must ensure database schema migrations execute against the production database before or during deployment startup:
- Using Replit's Automatic Schema Sync: Replit compares the development and production schemas during publishing. If it displays a prompt stating Detected potential conflicts, please review, do not skip it. Review the generated DDL and approve the column and table sync.
- Using Prisma: Update your deployment build or start command to run production migrations. In your
package.json:{ "scripts": { "build": "prisma generate && tsc", "start": "prisma migrate deploy && node dist/index.js" } }prisma migrate deployapplies pending migrations without prompting for interactive confirmation. - Using Drizzle ORM: Ensure your migration script runs as an entry point:
import { migrate } from "drizzle-orm/node-postgres/migrator"; import { db } from "./db"; // Run migrations prior to starting HTTP server await migrate(db, { migrationsFolder: "./drizzle" }); - Manual Verification via SQL Console: In the Replit workspace, open the Database tool, toggle the database dropdown from "Development" to "Production", and inspect your tables. If your production database has zero tables, your migrations failed to run.
3. Dynamic Egress IPs vs. External Database Firewalls
If your application connects to an external cloud database (such as MongoDB Atlas, Supabase, Amazon RDS, or a self-hosted VPS), it will work flawlessly from your local machine and even inside Replit's workspace, but fail with an ETIMEDOUT or Connection timed out error the moment it deploys.
Replit deployments run on Google Cloud Platform container infrastructure. Replit does not assign static outbound public IP addresses to deployment containers. Every time your deployment scales, restarts, or pushes a new build, its outbound (egress) IP address changes. If your database firewall is whitelisted only for your home office IP or a specific host, Replit's deployment traffic is discarded at the network edge.
The Fix
- Allow Anywhere Access (
0.0.0.0/0): In MongoDB Atlas Network Access, Supabase Network Restrictions, or AWS RDS Security Group inbound rules, allow access from0.0.0.0/0(all IPv4 addresses).- Is this safe? At 365Finds, we consider
0.0.0.0/0standard practice for serverless deployments only if you enforce strong, randomly generated credentials (passwords with 32+ characters) and mandatory SSL/TLS encryption.
- Is this safe? At 365Finds, we consider
- Static IP Outbound Proxy: If corporate security policies or compliance standards strictly forbid
0.0.0.0/0, you cannot connect directly from Replit. You must route outbound database traffic through a static egress proxy service (such as Fixie or Outbound Gateway), whitelist the proxy's static IP range in your database firewall, and set your deployment's HTTP/SOCKS proxy configuration in Deployment Secrets.
4. Missing or Broken SSL/TLS Negotiation
Modern managed database providers (including Replit PostgreSQL, Neon, Supabase, and AWS RDS) reject unencrypted plaintext connections over the public internet.
In development environments, database drivers frequently ignore SSL handshake requirements or fall back silently. When deployed to a production container with strict Node.js or Python runtime configurations, the driver rejects the connection:
error: no pg_hba.conf entry for host ..., user ..., database ..., no encryption
-- or --
Error: self-signed certificate in certificate chain
-- or --
SSL connection has been closed unexpectedly
The Fix
Verify that your database URL and ORM configuration explicitly require TLS.
1. Update the Connection String:
Append ?sslmode=require to your PostgreSQL connection string in Deployment Secrets:
postgresql://user:password@ep-sample-pooler.us-east-2.aws.neon.tech/neondb?sslmode=require
2. Configure Node.js pg / Knex / TypeORM:
If your driver fails verification against cloud provider intermediate certificates, explicitly configure SSL in your client initialization:
import { Pool } from 'pg';
const pool = new Pool({
connectionString: process.env.DATABASE_URL,
ssl: process.env.NODE_ENV === 'production'
? { rejectUnauthorized: false }
: false,
});
3. Configure Python (SQLAlchemy / psycopg2): Ensure your engine creation includes connect arguments:
import os
from sqlalchemy import create_engine
database_url = os.environ.get("DATABASE_URL")
if database_url and database_url.startswith("postgres://"):
database_url = database_url.replace("postgres://", "postgresql://", 1)
engine = create_engine(
database_url,
connect_args={"sslmode": "require"}
)
5. Autoscale Connection Exhaustion and Serverless Cold Starts
Replit Autoscale deployments scale down to zero when idle and spin up new instances rapidly under traffic spikes. Meanwhile, serverless databases like Replit's managed PostgreSQL (powered by Neon) automatically pause compute endpoints after periods of inactivity.
This creates two distinct failure modes:
- Cold Start Timeouts: When a request hits an idle Replit Autoscale app, both your application container and your database endpoint must wake up simultaneously. If your database connection timeout is configured to a rigid 3 or 5 seconds, the application throws a connection error before the database endpoint finishes resuming.
- Connection Starvation: If your app experiences a sudden surge in traffic, Replit spawns multiple autoscale instances. If each container initializes an ORM pool with 20 direct connections, a cluster of 5 containers attempts 100 simultaneous connections—instantly exceeding the connection limits of starter database tiers.
Diagnostic Matrix
| Symptom | Root Cause | Immediate Action |
|---|---|---|
ECONNREFUSED on port 5432 | DATABASE_URL missing in Deployment Secrets | Add DATABASE_URL under Deployments > Configuration > Deployment Secrets |
relation "..." does not exist | Production database is empty; migrations never ran | Execute prisma migrate deploy or review Replit publish schema sync |
ETIMEDOUT / Timeout acquiring connection | Dynamic IP blocked by external firewall or cold start | Whitelist 0.0.0.0/0 on external DB; raise connection timeout to 15s |
no pg_hba.conf entry ... no encryption | Cloud database enforces SSL, client connects via plaintext | Append ?sslmode=require to connection string |
too many connections / connection reset | Autoscale instances exhausting database connection limits | Switch to pooled connection string (port 6543 / PgBouncer) |
The Fix
- Use a Pooled Connection String: Never connect an Autoscale deployment directly to port 5432 of a serverless Postgres instance. Use the pooled connection string (typically port 6543 on Supabase, or the
-poolerhost on Neon/Replit Postgres). Connection poolers manage hundreds of transient application connections across a small set of persistent database connections. - Reduce ORM Pool Limits: Lower your client-side pool size. In production, configure your pool to allocate a maximum of 3 to 5 connections per container:
const pool = new Pool({ connectionString: process.env.DATABASE_URL, max: 5, idleTimeoutMillis: 30000, connectionTimeoutMillis: 15000, // Allow 15s for serverless wake-up });
The Recommended 365Finds Deployment Checklist
Before you hit "Republish" on Replit, run through this four-point check:
- Confirm whether your app connects to Replit's built-in PostgreSQL or an external provider. If built-in, do not manually override
DATABASE_URLin Deployment Secrets; let Replit manage it. - If using an external database, confirm
DATABASE_URLexists in Deployment Secrets, includes?sslmode=require, points to a connection pooler, and the database network access rule allows0.0.0.0/0. - Check the Publishing pane for pending schema migrations. Make sure your production database has tables before directing user traffic to it.
- Set client connection timeouts to at least 15,000 ms to survive serverless cold starts.
Follow these rules, and your Replit deployment will connect cleanly on the first build.