Digital Dreamer
Writing /
Read on dev.to

Prisma db push or pull stuck?

Fix for Prisma connection stuck when working with Supabase. Switch from pooled connection to direct connection.

Prisma db push or pull stuck?

Fix for Prisma connection stuck

When working with Prisma and Supabase DB, I got an issue with the Prisma CLI getting stuck during prisma db push and prisma db pull. The issue often arises when using a Supabase connection string with the pooled connection (port 6543).

For example, running npx prisma db push took 9 minutes here and still failed.

The Fix

To resolve this, I needed to switch to a direct connection string using port 5432 instead.

text
# Old Pooled Connection
DATABASE_URL="postgresql://...@db.supabase.co:6543/db"
DIRECT_URL="postgresql://...@db.supabase.co:6543/db"

# New Direct Connection
DATABASE_URL="postgresql://...@db.supabase.co:6543/db"
DIRECT_URL="postgresql://...@db.supabase.co:5432/db"

What your Prisma Datasource initialiser should look like:

prisma
generator client {
  provider = "prisma-client-js"
}

datasource db {
  provider  = "postgresql"
  url       = env("DATABASE_URL")
  directUrl = env("DIRECT_URL")
}

Happy Hacking!

PS: For more details, check out the GitHub discussion.