I've been using PSQL for over 2 years now, this issue started occurring 3 Months ago. The database would stop responding after a day of runtime until the affected Node.js process is restarted. 4 Days ago this issue got much worse, unless the host OS was restarted the database stops responding within minutes or less of process runtime.
This issue occurs in only one Node.js process, I have about 4 other Node.js processes running perfectly fine, so it's most likely an issue with my code.
Highest statistics for the affected process:
10 Sessions (constantly stays at that number)
90000 Transactions Per Second (Transactions)
140 Tuples in (Updates)
8000000 Tuples out (Returned)
180000 Block I/O (Hits)
I have tried:
- Re-starting Postgres
- Re-installing Postgres
- using pg-pool (Runs into error: Connection timed out)
- using pg-promise (I'm not sure how to apply this module without spamming tasks or connections)
No Errors are emitted, and the connection becomes increasingly slow over several minutes until the pgAdmin Dashboard basically flatlines and no further response is received.
Code: Pool creation (initiated on startup):
const { Pool } = require('pg');
const auth = require('./auth.json');
const ch = require('./ClientHelper');
const pool = new Pool({
user: 'postgres',
host: 'localhost',
database: 'Ayako-v1.5',
password: auth.pSQLpw,
port: 5432,
});
pool.query('SELECT NOW() as now;', (err) => {
if (err) {
ch.logger("| Couldn't connect to DataBase", err.stack);
} else {
console.log('| Established Connection to DataBase');
}
});
pool.connect((err) => {
if (err) {
ch.logger('Error while logging into DataBase', err.stack);
}
});
pool.on('error', (err) => {
ch.logger('Unexpected error on idle pool client', err);
});
module.exports = pool;
Queries are executed via:
const query = async (query, arr, debug) => {
const pool = require('./DataBase');
if (debug === true) console.log(query, arr);
return pool.query(query, arr).catch((err) => {
console.log(query, arr);
module.exports.logger('Pool Query Error', err);
return null;
});
Queries arrive at the above query function but never receive a response. File Links:
https://github.com/Larsundso/Ayako-v1.5/blob/main/Files/BaseClient/DataBase.js
Versions PSQL - v14 | Node.js - v17.8.0 | Linux - Ubuntu 20.04.4 LTS