【发布时间】:2018-03-28 07:45:44
【问题描述】:
我使用 node.js 和 PostgreSQL 作为我的数据库。我使用下面的代码来连接我的数据库。
const pool = new pg.Pool(config);
pool.connect((err) => {
if (err) {
console.log(err);
return;
}
console.log('connected to database', config.database);
});
这是配置代码:
const crypto = require('crypto').randomBytes(256).toString('hex');
module.exports = {
host:'192.168.87.8',
user: 'fjavadpour',
database: 'fj_correspondence',
password: 'Fariba321',
port: 5432,
max: 200,
secret:crypto,
idleTimeoutMillis: 72000000
};
但是我的数据库连接会在空闲大约一小时后崩溃并停止。 我该如何解决?
【问题讨论】:
-
您的主机在哪里?是否在同一个网络内?
-
@AnshulVerma 是的!我一开始可以连接到主机,但是大约一个小时后我没有联系数据库时它崩溃并出现 ECONNRESET 错误
标签: node.js postgresql server timeout