baptisteArno / typebot.io

💬 Typebot is a powerful chatbot builder that you can self-host.
https://typebot.io
Other
7.17k stars 1.96k forks source link

Too many database connections opened: FATAL: sorry, too many clients already #1602

Closed eltonciatto closed 3 months ago

eltonciatto commented 3 months ago

When making many changes to the large flow, Prisma has problems saving this data to the database, so it returns the error: Could not fetch typebot - Invalid prisma.typebot.findFirst() invocation: Too many database connections opened: FATAL : sorry, too many clients already.

Suggestions for Possible solutions: To make database connection management scalable, you can adopt several strategies, including using a connection proxy, implementing an efficient connection pool, and continually monitoring and tuning database resources. Here are some detailed approaches to do this:

Use a Connection Proxy like PgBouncer PgBouncer is a popular tool for managing PostgreSQL database connections efficiently. It acts as an intermediary between the application and the database, managing the connection pool.

Reuse of Connections with Prisma Using Prisma, ensure you reuse the Prisma client rather than creating a new instance with each request. Create the Prisma client once and reuse it throughout the application.

Note: I am facing these problems on self-hosting, however, some users reported to me that they face this same error using Typebot.io. WhatsApp Image 2024-06-21 at 01 17 03

baptisteArno commented 3 months ago

It's up to you how you maintain and scale your database. This issue is not related to Typebot. 🙏