Description
I am running a multi-agent workflow in n8n where I use a single Postgres database for both vector data and chat history. In this workflow I am also generating SQL using the same database.
Connection Setup
I created a Postgres account and successfully connected to it via n8n credentials. However, there isn’t an option to set connection pool configurations in the credentials settings.
Error Encountered
I sometimes receive the error:
sorry, too many clients already
This error resolves temporarily only when I restart the database.
Observations
It appears that n8n is opening a new database connection every time a step in the workflow accesses the Postgres DB. In a multi-agent workflow, this likely leads to exceeding the maximum allowed connections, as instead of reusing an existing connection from a pool, n8n creates a new one for each access.
Desired Outcome
Ideally, n8n should implement connection pooling so that each set of credentials uses and reuses a single connection pool across multiple workflow steps. I am seeking advice on how to manage or work around this behavior—whether through configuration changes, workflow isolation, or by using an external connection pooling tool such as PgBouncer.
Setup Information
- n8n version: 1.67.1
- Running n8n via: Local Docker version
- Operating system: Windows
See error image
Please share any workflow modifications or external solutions you have used to address this issue.