【问题标题】:What is the correct way how to use database PG POOL如何使用数据库PG POOL的正确方法是什么
【发布时间】:2020-01-28 08:39:16
【问题描述】:

我正在使用节点Postgress,我想使用connection pooling。我有这样的简单存储库:

初始化

    const pool = new Pool({
        connectionString: process.env.DATABASE_URL,
    })

    await pool.connect()

示例 SELECT 代码..

export default (
    {
        pgPool,
    }: Object
) => {
    return { 
        getExampleData: async (uid: string) => {
            const result = await pgPool.query('SELECT data FROM public.results_table WHERE uid = $1::text;', [uid])
            return result.rows
        },
    }
}

我的问题是,在压力下(很多请求)我收到以下错误:

错误:剩余的连接槽被保留用于非复制 超级用户连接

我不确定我是否正确使用了池。

【问题讨论】:

  • “很多请求”是多少?我们使用 pgpool、haproxy、PHP。 Apache 并且有很多客户端并且没有遇到任何问题。但是,我们已将所有内容调整为拥有大约 2000 个同时客户端。两台服务器,一台主机,一台从机和 8 个内核,配备 16GB 内存和 2TB 硬盘,使用 NFS。
  • 20/s :-D 正在测试数据库,有 25 个连接插槽,1GB 内存...

标签: node.js postgresql connection-pooling


【解决方案1】:

我们 pgpool.conf 的一部分:

# - Pool size -

num_init_children = 100
                                   # Number of pools
                                   # (change requires restart)
max_pool = 3
                                   # (change requires restart)

# - Life time -

child_life_time = 120
                                   # Pool exits after being idle for this many seconds
child_max_connections = 0
                                   # Pool exits after receiving that many connections
                                   # 0 means no exit
connection_life_time = 90
                                   # Connection to backend closes after being idle for this many seconds
                                   # 0 means no close
client_idle_limit = 0
                                   # Client is disconnected after being idle for that many seconds
                                   # (even inside an explicit transactions!)
                                   # 0 means no disconnection

以下问题/答案也应该对您有所帮助:

Heroku “psql: FATAL: remaining connection slots are reserved for non-replication superuser connections”

相信这会有所帮助。

【讨论】:

    猜你喜欢
    • 2018-01-25
    • 2021-07-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-05-28
    • 1970-01-01
    • 1970-01-01
    • 2020-05-15
    相关资源
    最近更新 更多