P
Prisma4d ago
dolary

Is there any way to close existing connections?

Like the title says. I've hit the limit and because app is deployed trough vercel I can't close these connections anywhere through vercel or prisma.io. Is there any way I could close these zombie connections?
4 Replies
Prisma AI Help
You've gone full bot mode! Let me fetch that AI answer for you ASAP. In serverless environments like Vercel, zombie database connections can accumulate because each deployment or function invocation may create new connections, and old containers/functions may linger for minutes or even hours, holding connections open. Unfortunately, there is no way to programmatically close these connections from within your Vercel deployment or Prisma itself, because once the serverless function is frozen or terminated, your code cannot run cleanup logic like $disconnect()—the environment is simply paused or destroyed by the platform, not your application code. This is a limitation of serverless platforms, not Prisma specifically Prisma, Next.js, Heroku PostgreSQL database running into connection limits in production, Other serverless considerations. Workarounds: - Connection Pooler: Use an external connection pooler like PgBouncer or Prisma Accelerate. This helps mitigate the impact of many open connections by pooling them at the database level Deploy to Vercel: Connection pooling. - Manual Cleanup: You can manually kill idle connections directly in your database (e.g., using SQL scripts in your database console). For PostgreSQL, you can run a script to terminate idle connections, such as:
SELECT pg_terminate_backend(pid)
FROM pg_stat_activity
WHERE state = 'idle' AND datname = 'your_db_name';

SELECT pg_terminate_backend(pid)
FROM pg_stat_activity
WHERE state = 'idle' AND datname = 'your_db_name';

Or use more advanced scripts as shared in community discussions Node-API/LibraryEngine: $disconnect does not free up memory / kill engine. - Database Settings: Configure your database to automatically close idle connections after a certain period. There is no way to trigger this cleanup from Vercel or Prisma directly once the function is frozen. Using a connection pooler is the most robust solution.
dolary
dolaryOP3d ago
I cannot terminate connections by PID because I don't know what are the resources in the pg_stat_activity. It looks like I don't have access to these informations
Prisma AI Help
🤔 Alright, thanks for letting us know that there's still some help needed. A team member will reply to you shortly. In the meantime, please let us know any additional info, questions, or which parts of the answer may need clarification.
Nurul
Nurul3d ago
Hey! Does using $disconnect also not work for you?

Did you find this page helpful?