【问题标题】:Execute two queries at the same time on psql with node postgres使用节点 postgres 在 psql 上同时执行两个查询
【发布时间】:2022-01-14 05:34:45
【问题描述】:

例如,我有两个独立的查询:

const query = "SELECT PG_SLEEP(30);"
const query1 = "SELECT PG_SLEEP(30);"

console.time("Query")
await Promise.all([pgClient.query(query), pgClient.query(query1)]);
console.timeEnd("Query")

根据文档,这将被添加到一个队列中并一个接一个地执行,是否可以异步执行两个查询?所以注册时间应该是30左右而不是60...

更新: 其他方法是使用库的the pool feature 而不是实例化两个客户端

【问题讨论】:

    标签: node.js postgresql node-postgres


    【解决方案1】:

    为此,您必须打开两个数据库连接。那么两个查询同时运行就没有问题了。

    【讨论】:

    • 是的,这也有效,我认为有一种方法可以不使用这种方法
    • 不,这是唯一的办法。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-01-22
    • 1970-01-01
    • 2015-07-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多