簡體   English   中英

多次 select 查詢后,Express 服務器的 Postgres 數據庫查詢超時

[英]Postgres database queries from express server time out after multiple select queries

我正在運行一個節點(快速)rest API,一個 postgres 數據庫和一個索引器,它在同一台服務器上填充數據庫。

出於某種原因,當我從 rest api 對數據庫進行大量查詢時,在一定數量的查詢之后,以下所有查詢都開始超時。 似乎沒有任何鎖,我需要重新啟動我的 docker 容器以使數據庫再次返回。

我在我的 rest api 中添加了一些日志,以查看似乎超時的地方:

        console.log("get here1")
        pool.query(totalQuery, [], (error, results) => {
                console.log("get here2");
                if (error) {
                        console.error(error)
                        res.status(404).json(error)
                }

                const total_markets = results.rows[0] ? results.rows[0].total_markets : 0;

                pool.query(query, values, (error, results) => {
                        console.log("get here3");
                  if (error) {
                          console.error(error)
                          res.status(404).json(error)
                  }

                  res.status(200).json({count: total_markets, data: results.rows})
          })
        });

服務器日志如下:

get here2
get here3
get here
get here2
get here3
get here
get here
get here
get here

我真的不確定是什么導致我的查詢超時,但似乎整個數據庫都無法訪問。

當我附加到 docker 容器並使用psql查詢數據庫時,查詢工作正常。

原來這是一個 node.js(pg 更具體的問題)

我在池配置中添加了超時屬性:

const pool = new Pool({
  connectionString: process.env.CONNECTION_STRING ? process.env.CONNECTION_STRING : connectionString,
  ssl: production,
  max : 5,
  connectionTimeoutMillis : 5000,
  idleTimeoutMillis : 30000
});```

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM