Database connection from Vercel to Supabase

Hi,
I deployed my Node.js project on Vercel, and my database is hosted on Supabase.
I set the environment variables (DB_HOST, DB_USER, DB_PASSWORD, DB_NAME), but my app shows a connection error.
DB_HOST=db.emtyjepwczgxglewnpzs.supabase.co
DB_PORT=5432
DB_USER=postgres
DB_PASSWORD=******
DB_NAME=postgres
The app connects fine on my local machine, but on Vercel I get this error:
javascript
Copy code
Error: getaddrinfo ENOTFOUND db.emtyjepwczgxglewnpzs.supabase.co
Could you please explain the correct way to connect a Vercel project to a Supabase database?
Should I adjust the connection string or use a specific Vercel configuration?
Thank you!

The ENOTFOUND error usually means your app can’t find the database host. Basically a DNS issue! Here are a few things to try:

Make sure your connection string is in the right format. You can grab it directly from your Supabase dashboard under Settings → Database. It should look like this:

postgresql://postgres:[YOUR-PASSWORD]@db.emtyjepwczgxglewnpzs.supabase.co:5432/postgres

Or instead of setting separate variables, try using a single DATABASE_URL with the full connection string:

DATABASE_URL=postgresql://postgres:your-password@db.emtyjepwczgxglewnpzs.supabase.co:5432/postgres

It’s cleaner and usually avoids issues with missing or mismatched parts of the string.

Let us know how you get on!

Hi @pawlean, this is not a DNS issue. Supabase no longer provides IPv4 support by default for their databases; they can only be accessed via IPv6:

https://supabase.com/docs/guides/troubleshooting/supabase–your-network-ipv4-and-ipv6-compatibility-cHe3BP

@urilyakubov In this case you have a DNS resolution issue because the DNS record of the database have only the AAAA record and not the A one, but this is intended to only accept IPv6 connections

The Vercel Functions does not support IPv6 connections to other hosts. The only solution is to purchase the IPv4 Add-On on Supabase or use a different database provider that still supports IPv4.