This error occurs when Prisma Accelerate encounters an unexpected server-side issue, often manifesting as a 502 Bad Gateway response. It typically indicates connectivity problems between Accelerate and your database, service availability issues, or transient infrastructure failures.
The P5006 error in Prisma Accelerate represents a catch-all for unexpected server-side errors that don't fall into more specific error categories. This error often appears with additional details like "UnknownTextError" and HTTP 502 Bad Gateway responses, indicating that Prisma Accelerate's infrastructure encountered an issue while processing your request. Unlike client-side errors (like invalid queries or connection strings), P5006 originates from Accelerate's backend services. This means the problem typically lies in the communication between Accelerate and your database, Accelerate's service availability, or temporary infrastructure issues in Prisma's cloud platform. The error is particularly common during database connection establishment or query execution, and can occur intermittently even when your code and configuration are correct. When your database is in sleep mode, behind a firewall, or experiencing high latency, Accelerate may timeout and throw this error rather than waiting indefinitely.
First, confirm your database is running and accessible. If using a serverless database, it may be in sleep mode:
Check database status:
- Log into your database provider's console (Neon, Supabase, PlanetScale, etc.)
- Verify the database instance is active and not paused
- If it's asleep, wake it by running a query through the provider's SQL editor
Test direct connection:
# Try connecting with psql or your database client
psql "postgresql://user:password@host:5432/database"If direct connection works but Accelerate fails, the issue is likely with Accelerate's network access to your database.
Ensure the connection string provided to Prisma Accelerate is correct:
Check your Prisma schema:
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}Verify the connection string format:
- Hostname is correct and accessible from the internet
- Port is correct (typically 5432 for PostgreSQL)
- Username and password are valid
- Database name exists
Test in Prisma Console:
- Go to your Accelerate project in Prisma Console
- Verify the connection string configured there matches your actual database
- Try updating it if credentials have changed
If your database is behind a firewall or in a VPC, you need to allow Prisma Accelerate's IP addresses:
Enable static IP for Accelerate:
- In Prisma Console, go to your Accelerate project settings
- Enable "Static IP" feature (may require a paid plan)
- Note the provided static IP addresses
Add IPs to database firewall:
For PostgreSQL on AWS RDS:
# Add security group rule allowing Accelerate IPsFor Supabase:
- Go to Database settings → Connection pooling
- Add Accelerate's static IPs to the allowed list
For PlanetScale/Neon:
- These are typically internet-accessible by default
- Ensure no IP allowlist is configured, or add Accelerate IPs
VPC considerations:
If your database is in a private VPC, you may need to:
- Expose the database to the internet with proper security groups
- Use a database proxy or connection pooler with public access
- Consider using Prisma Pulse for databases that must remain private
If using PgBouncer or another connection pooler, ensure compatibility:
For PgBouncer:
# Connection string should NOT include ?pgbouncer=true
# Accelerate handles its own connection pooling
DATABASE_URL="postgresql://user:password@host:5432/db"For Supabase:
Use the "Session" mode connection string, not "Transaction" mode:
# Use port 5432 (session mode), not 6543 (transaction mode)
postgresql://postgres:[PASSWORD]@db.[PROJECT].supabase.co:5432/postgresVerify pooler settings:
- Pool mode should be "session" not "transaction"
- Max connections should be adequate
- Idle timeout should be reasonable (60+ seconds)
P5006 errors can be intermittent. Add retry logic to handle temporary failures:
import { PrismaClient } from '@prisma/client'
const prisma = new PrismaClient()
async function queryWithRetry<T>(
fn: () => Promise<T>,
maxRetries = 3,
delayMs = 1000
): Promise<T> {
for (let i = 0; i < maxRetries; i++) {
try {
return await fn()
} catch (error: any) {
if (error.code === 'P5006' && i < maxRetries - 1) {
console.log(`P5006 error, retrying... (${i + 1}/${maxRetries})`)
await new Promise(resolve => setTimeout(resolve, delayMs * (i + 1)))
continue
}
throw error
}
}
throw new Error('Max retries exceeded')
}
// Usage
const users = await queryWithRetry(() =>
prisma.user.findMany()
)This handles temporary infrastructure hiccups gracefully.
Check if the issue is on Prisma's side:
Check Prisma status page:
Visit https://status.prisma.io to see if there are any ongoing incidents with Accelerate.
Review Accelerate logs:
- Go to Prisma Console → your Accelerate project
- Check the logs/metrics section for patterns
- Look for connection timeouts or gateway errors
Enable Prisma debug logging:
# Set environment variable
DEBUG="prisma:*" node your-app.jsOr in code:
const prisma = new PrismaClient({
log: ['query', 'error', 'warn'],
})This provides detailed information about what's happening before the error occurs.
If you've verified all configuration and the error continues:
Gather diagnostic information:
- Exact error message and stack trace
- Database provider and configuration
- When the error started occurring
- Frequency (constant vs. intermittent)
- Any recent changes to your setup
Submit a support ticket:
- For paid plans: Use Prisma Console support chat
- For community support: Post in Prisma GitHub Discussions or Discord
- Include your Accelerate project ID and error logs
Temporary workaround:
Consider temporarily bypassing Accelerate by using a direct database connection while the issue is resolved:
datasource db {
provider = "postgresql"
url = env("DIRECT_DATABASE_URL") // Direct connection
// url = env("DATABASE_URL") // Accelerate connection
}Database sleep mode and serverless databases: Serverless database providers like Neon and PlanetScale automatically pause databases after inactivity. When Prisma Accelerate tries to connect to a sleeping database, it may timeout before the database wakes up, resulting in P5006. Solutions include:
- Configure your database to stay active longer
- Use connection warming strategies (periodic health checks)
- Switch to a database plan that doesn't auto-pause
Accelerate vs. direct connection performance: P5006 can sometimes indicate that Accelerate adds too much latency for your use case. Accelerate routes requests through Prisma's infrastructure, which adds network hops. For databases in the same region as your application, a direct connection may be faster and more reliable.
VPC and private database considerations: Prisma Accelerate requires internet-accessible databases. If your security requirements mandate private databases, consider:
- Using Prisma Pulse instead (supports private databases via different architecture)
- Setting up a publicly accessible connection proxy
- Using SSH tunneling (not officially supported but possible)
Connection string caching: Prisma Accelerate caches your database connection string configuration. If you update credentials in your database provider, you must also update them in Prisma Console. Changes may take a few minutes to propagate.
Regional latency: If your database and Accelerate are in different geographic regions, network latency can cause timeouts. Check that your Accelerate region (configured in Console) is close to your database region.
Query response size limits: While P5006 is typically a connection error, it can also occur if your query result exceeds Accelerate's response size limit (5MB). For large datasets, use pagination or streaming APIs.
Production deployment tips:
- Always use environment variables for connection strings
- Set up monitoring/alerts for P5006 errors
- Keep Prisma Client and Accelerate SDK updated
- Test Accelerate connectivity during deployment verification
P1013: The provided database string is invalid
The provided database string is invalid
P1000: Authentication failed against database server
Authentication failed against database server
P1010: User was denied access on the database
How to fix "P1010: User was denied access on the database" in Prisma
P5008: Usage exceeded, upgrade your plan (Accelerate)
How to fix "Usage exceeded, upgrade your plan" in Prisma Accelerate
P3021: Foreign keys cannot be created on this database
How to fix 'P3021: Foreign keys cannot be created on this database' in Prisma