Node-Postgres for High Availability
Node-Postgres for High Availability
ha-pg is an npm package that provides a high-availability wrapper for node-postgres, designed to enhance the resilience of applications using PostgreSQL. It addresses common issues encountered with node-postgres, particularly those related to network instability and client management within connection pools. The package aims to mitigate problems such as clients not being released after network issues, difficulty in detecting network disconnections or high latency, and pools failing to resolve pending client requests. The package primarily enhances the `Pool` class from node-postgres. Key features include emitting an error event when the `connect()` method fails and introducing an "allErrors" event type that consolidates error events from both the pool and its clients. It also implements a `recover()` method to free clients in an ended state and an optional `autoRecover` setting that automatically calls `recover()` and retries client acquisition upon failure. Additionally, ha-pg provides a `serverIsReachable()` method to check network connectivity to the database server. ha-pg is intended for developers seeking to improve the robustness of their Node.js applications that interact with PostgreSQL, especially in environments where network reliability or client pool management presents challenges. It offers a solution for issues like queries lasting indefinitely due to pending queues when no connection timeout is defined, and client references remaining usable after being released to the pool. The package currently has no external dependencies or dependents listed on npm.