首页 > 解决方案 > 节点 postgres - (node:43028) UnhandledPromiseRejectionWarning: 错误: 抱歉,已经有太多客户端

问题描述

我正在尝试将数据添加到我的数据库中。数组中有多个条目

dataArryay.forEach((element) => {

    queryData(elementData)
}

该函数被多次调用

async function queryData(data) {

    const queryString = `INSERT............')`;

    const query = {
        text: queryString
    };

    const pool = await new pg.Pool({
        host: 'localhost',
        port: 'xxxx',
        user: 'xxxxxx',
        database: 'xxxxx',
        max: 100,
            idleTimeoutMillis: 50000,
            connectionTimeoutMillis: 3000,
        });
        await pool.connect();
        await pool.query(query)
        await pool.end()
    }

它进行了插入,但确实引发了太多的连接错误。我试过 .release() 和 .end()

查询我得到的连接时

max_conn = 500
used = 6
res_for_super = 3
res_for_normal = 491

我真的不知道这些人是什么,但他们似乎加起来有 500 人。

标签: postgresqldatabase-connectionnode-postgresconnection-pool

解决方案


推荐阅读