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

  1. Go to supabase.com and sign up for an account
  2. Click "New Project"
  3. Choose an organization (or create one)
  4. Fill in project details:
    • Name: Your project name
    • Database Password: Create a strong password (save this!)
    • Region: Choose closest to your users
  5. Click "Create new project"
  6. Wait for provisioning (usually 2-3 minutes)

Get Connection String

  1. In your Supabase project dashboard, go to "Settings" → "Database"
  2. Scroll down to "Connection string"
  3. Select "URI" tab (not "JDBC" or "Golang")
  4. Copy the connection string - it looks like: postgresql://postgres:[YOUR-PASSWORD]@db.xxx.supabase.co:5432/postgres
  5. Important: Replace [YOUR-PASSWORD] with the database password you set when creating the project
  6. Add ?sslmode=require at 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-password with your actual database password
  • The connection string should include ?sslmode=require for SSL
  • For production, use environment variables in your hosting platform
  • Never commit .env.local to 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:

  1. Go to "SQL Editor" in your Supabase dashboard
  2. Write and run SQL queries
  3. View results in the interface

Testing

  1. Restart your dev server: npm run dev
  2. Navigate to http://localhost:3000/sign-up
  3. Create a test account
  4. Verify the user was created:
    • Go to Supabase dashboard → "Table Editor"
    • Select the user table
    • You should see your test user
  5. 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