Postgres Connection Error - "sorry, too many clients already"

Description

I have a multi-agent workflow. I am using PGSQL for both vector DB and storing chat history as well. In my sample workflow, I am using the same PG DB to generate SQL.
In credential I have create a Postgres Account and I have been able to connect to it. But there is not parameter there where I can mention the connection pool configurations.

What is the error message (if any)?

It was running fine for few rounds, but I see the following error sometimes.
If I restart the DB, the error goes away for sometime.

When researching further, I feel that n8n is opening a new connection every time it is trying to access the DB.

In my opinion, in a multi-agent workflow where the same DB when accessed across different steps it is opening a new connection rather than utilising the same connection or use the connection from the connection pool.
Ideally it should create a connection pool for each item in credentials section and reutilise wherever possible.
NOTE: This is my assumption, and I may be wrong

Please share your workflow

This is the master workflow

This is the child workflow

Share the output returned by the last node

Information on your n8n setup

  • n8n version: 1.67.1
  • Running n8n via : Local Docker version
  • Operating system: Windows

It looks like your topic is missing some important information. Could you provide the following if applicable.

  • n8n version:
  • Database (default: SQLite):
  • n8n EXECUTIONS_PROCESS setting (default: own, main):
  • Running n8n via (Docker, npm, n8n cloud, desktop app):
  • Operating system:

EXECUTIONS_PROCESS settings: default
Database: PGSQL

Do you have a lot of executions on your n8n instance that are talking to this same postgres server?

Yes - It is a multi-agent workflow. So yes, based on the input request there may be multiple queries that may be used to query the chat-table.
The question here is that why the workflow is initiating multiple connections, it should first create a connection pool. The workflow should get the connections from the connection pool.