我正在使用节点包pg
对于 postgres (here https://github.com/brianc/node-postgres):
npm i pg
var pg = require('pg');
我正在查询一个不属于我的大型集群,在某些条件下可能会失败。失败可能是易于处理的错误响应或无休止的查询。
请注意,我无法在数据库端引入更改[配置或其他]。
有什么办法可以设置查询时间的超时时间吗?
我希望我的客户在设定的时间后放弃,并返回超时错误。
在文档中找不到类似的内容。
提前致谢!
您可以设置statement_timeout https://www.postgresql.org/docs/current/runtime-config-client.html#GUC-STATEMENT-TIMEOUT在客户端:
const { Client } = require('pg')
const client = new Client({
statement_timeout: 10000
})
或在泳池中:
const { Pool } = require('pg')
const pool = new Pool({
statement_timeout: 10000
})
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)