Your supabase connection string looked correct when the AI pasted it into the project. Locally it answers. In production, the first query fails: ENOTFOUND, tenant or user not found, password authentication failed, too many connections, or a serverless function that hangs until timeout.
There is not one Supabase string. Several valid strings exist, differing by host, port, username, IP version and pooling behavior. A migration string can be wrong for Vercel, and a backend string can be dangerous in a browser.
supabase connection string is a runtime decision, not a single secret
Frontend application: you normally do not need a Postgres connection string. Browser code should use the Data API or client libraries with the project URL, API key and Row Level Security. Putting the database password into frontend JavaScript is a leak.
Serverless or edge function: use the shared pooler in transaction mode. Serverless platforms create many short-lived execution environments. Transaction pooling exists for that shape. It uses port 6543 and is IPv4-reachable on every plan.
Persistent backend on IPv4: use the shared pooler in session mode on port 5432. This fits long-running servers, containers, GUIs and BI tools without IPv6. Session mode keeps session state and supports prepared statements.
Persistent backend on IPv6, or with the IPv4 add-on: use the direct connection on port 5432. Direct is also right for migrations, pg_dump, backup, restore and replication. Without the paid IPv4 add-on, the direct endpoint is IPv6.
High-load paid application: the dedicated pooler uses transaction mode on port 6543 and runs close to the database. It is not a universal upgrade.
Read the string before you paste it
A direct connection looks like this:
postgresql://postgres:[YOUR-DATABASE-PASSWORD]@db.[PROJECT-REF].supabase.co:5432/postgres
A shared pooler string looks like this:
postgresql://postgres.[PROJECT-REF]:[YOUR-DATABASE-PASSWORD]@[POOLER-HOST]:5432/postgres
postgresql://postgres.[PROJECT-REF]:[YOUR-DATABASE-PASSWORD]@[POOLER-HOST]:6543/postgres
Direct connections and the dedicated pooler use postgres. Shared pooler connections use postgres.[PROJECT-REF]; a custom role becomes [ROLE].[PROJECT-REF]. Without the project reference, the pooler cannot route the tenant.
Copy host and username together from the Connect dialog. The pooler host contains a cluster index you cannot reliably derive from the region. On the shared pooler, 5432 is session mode and 6543 is transaction mode. On the direct database host, 5432 is direct Postgres and 6543 is the dedicated pooler when it exists.
The production click path
- Write down where this connection runs. Browser, serverless, persistent server, migration job, GUI and worker are different answers.
- Open the Supabase Dashboard and click Connect. Copy the exact string for that runtime; never reconstruct or copy the pooler host from another project.
- Replace the password placeholder correctly. Percent-encode reserved characters such as
&,#,?or spaces. A password reset breaks old deployments until their secret is updated. - Store it as a server-side secret. Never put it in frontend code, public repositories, screenshots, issue reports or AI prompts.
- Set SSL deliberately. Use
sslmode=requireat minimum; for verification, configure the downloaded root certificate withsslmode=verify-fullandsslrootcertor the driver equivalent. - Match prepared statements to the mode. The shared transaction pooler does not support them: Postgres.js/Drizzle
prepare: false, Prismapgbouncer=true, asyncpgstatement_cache_size=0, JDBCprepareThreshold=0. - Cap the application-side pool in serverless. Create the client once at module scope and start with pool size 1; large per-instance pools multiply with warm instances.
- Use direct or session mode for migrations and dumps. Migration tools,
pg_dump, backup and restore workflows need stable Postgres-native sessions. - Test the exact production shape. Test from the same network or runtime, then test the deployed app; local success only proves your laptop combination works.
What the common errors usually mean
ENOTFOUND often means the direct IPv6 endpoint was copied into an IPv4-only environment. Use shared session mode or enable the IPv4 add-on when direct is genuinely required.
tenant or user not found usually means wrong pooler host, missing .[PROJECT-REF], or host and username copied from different places.
password authentication failed means the password is wrong, stale, or broken by missing percent-encoding. Fix the stored secret once and redeploy.
too many connections often means application-side pooling is fighting serverless scaling. Reduce the local pool first.
Session settings, temporary tables, LISTEN/NOTIFY, advisory locks, holdable cursors and query pipelining do not survive transaction pooling. Keep them inside one transaction or use session/direct mode.
How this interacts with AI-generated code
Ask the AI which runtime each file is. A route handler, edge function, migration script, browser component and worker are not interchangeable. The fix is often architectural: browser code moves back to the Data API with supabase rls, server code gets the right pooler, and migration jobs get direct or session mode.
After a restore or password reset, the old string is not harmless. Keep the supabase backup recovery checklist next to this audit, and use the supabase migrations path for schema repair.
Minimum production checklist
- No Postgres connection string is shipped to browser code.
- Frontend access uses the Data API or client libraries with RLS enabled and policies tested.
- Serverless uses the shared transaction pooler on port 6543 unless there is a documented reason not to.
- Persistent IPv4-only backends use the shared session pooler on port 5432 or a deliberate IPv4 add-on setup.
- Migrations, dumps and restore tooling use direct or session mode.
- The pooler host and username were copied together from the Connect dialog.
- The database password is percent-encoded and stored only as a server-side secret.
- SSL is required; prepared statements are disabled for the shared transaction pooler; the application-side pool is capped.
- Edge functions follow the supabase edge functions production triage.
- The deployment still passes the wider lovable deploy production checklist.
The right connection string matches host, port, username, IP version and pooling behavior to the runtime. Choose in that order, and most production database errors become boring configuration mistakes.
FAQ
Is it safe to put a Supabase connection string in frontend code?
No. A Postgres connection string contains the database password and must never ship to the browser. Frontend code should use the Supabase Data API or client libraries with Row Level Security and the correct API key. Keep the connection string in server-side environment variables only.
Which Supabase connection string should serverless use?
Serverless and edge functions normally use the shared pooler in transaction mode on port 6543. Create the client once at module scope, set the application-side pool size to 1, turn off prepared statements for the shared pooler, and require SSL.
Why does the direct Supabase connection fail on an IPv4-only network?
Direct database connections are IPv6 by default. On an IPv4-only network, use the shared pooler in session mode on port 5432, or enable the paid IPv4 add-on when you truly need the direct endpoint or dedicated pooler.