feat: add error handling for database connection pool to manage admin shutdown during backup windows

This commit is contained in:
Marco Pedone 2026-03-23 12:01:18 +01:00
parent 48768c0481
commit 70cc0e4536

View file

@ -26,6 +26,19 @@ const pool = new Pool({
user: env.POSTGRES_USER, user: env.POSTGRES_USER,
}); });
pool.on("error", (err) => {
const pgErr = err as { code?: string };
// "admin_shutdown" error sent during backups
const isAdminShutdown = pgErr.code === "57P01";
const hour = new Date().getHours();
// Consider it a backup window if it's between 00:00 and 02:00
const isBackupWindow = hour === 0 || hour === 1;
if (isAdminShutdown && isBackupWindow) return;
console.error("PG error:", err);
});
type Db = typeof db; type Db = typeof db;
type Trx = Transaction<PublicSchema>; type Trx = Transaction<PublicSchema>;