Supabase Postgres
Last updated December 18, 2025
Overview
Supabase provides a fully managed PostgreSQL database with additional features like real-time subscriptions, storage, and auth. It works seamlessly with Drizzle ORM and is a great alternative to Neon.
Create Project
- Go to supabase.com and sign up for an account
- Click "New Project"
- Choose an organization (or create one)
- Fill in project details:
- Name: Your project name
- Database Password: Create a strong password (save this!)
- Region: Choose closest to your users
- Click "Create new project"
- Wait for provisioning (usually 2-3 minutes)
Get Connection String
- In your Supabase project dashboard, go to "Settings" → "Database"
- Scroll down to "Connection string"
- Select "URI" tab (not "JDBC" or "Golang")
- Copy the connection string - it looks like:
postgresql://postgres:[YOUR-PASSWORD]@db.xxx.supabase.co:5432/postgres - Important: Replace
[YOUR-PASSWORD]with the database password you set when creating the project - Add
?sslmode=requireat the end for SSL
Connection Pooling (Recommended for Serverless): Supabase provides connection pooling for better performance with serverless functions. In "Settings" → "Database", look for "Connection pooling" and use the "Transaction" mode connection string.
Environment Variables
Add this variable to your .env.local file:
# Supabase Postgres DATABASE_URL="postgresql://postgres:your-password@db.xxx.supabase.co:5432/postgres?sslmode=require"
Important:
- Replace
your-passwordwith your actual database password - The connection string should include
?sslmode=requirefor SSL - For production, use environment variables in your hosting platform
- Never commit
.env.localto git
Run Migrations
After setting DATABASE_URL, run the database migrations:
# Generate migrations from your schema npx drizzle-kit generate # Push migrations to your database npx drizzle-kit push
This will create all the required tables in your Supabase database.
Using Supabase SQL Editor: You can also run SQL directly in Supabase:
- Go to "SQL Editor" in your Supabase dashboard
- Write and run SQL queries
- View results in the interface
Testing
- Restart your dev server:
npm run dev - Navigate to
http://localhost:3000/sign-up - Create a test account
- Verify the user was created:
- Go to Supabase dashboard → "Table Editor"
- Select the
usertable - You should see your test user
- Sign in and verify sessions work correctly
Troubleshooting:
- If connection fails, verify the password in the connection string is correct
- Check that SSL mode is set to
require - Ensure your IP isn't blocked in "Settings" → "Database" → "Connection Pooling"
- For serverless, use the connection pooling URL instead