Registry / database / ha-pg
library0.0.9jsnpmunverified

High-Availability wrapper over node-postgres (pg) that enhances Pool resilience by addressing common issues like unreleased clients after network failures, inability to detect disconnections, client references remaining usable after release, pool.end() hanging, and query cancellation after reconnection. Current version 0.0.9, actively developed. Differentiators include auto-recovery, connection monitoring, client timeout for forced pool end, and remote query cancellation. Requires node-postgres as a peer dependency.

npm install ha-pg
INSTALL
IMPORT
SIG · HA-PG
H
ha-pg
databasejavascriptv0.0.9
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Pool
✓ const { Pool } = require('ha-pg');
✗ const { Pool } = require('pg');
Use ha-pg instead of pg for enhanced Pool. The pg library's Pool is replaced by this wrapper.
Pool
✓ import { Pool } from 'ha-pg';
✗ import { Pool } from 'pg';
ESM import available. Type definitions are not bundled; may need @types/pg.
Pool
✓ const { Pool } = require('ha-pg');
✗ const Pool = require('ha-pg').Pool;
Both patterns work, but destructuring is preferred.

Create a high-availability Pool with autoRecover and client_timeout, run a query, then cleanly shut down.

const { Pool } = require('ha-pg'); const pool = new Pool({ host: process.env.PGHOST ?? 'localhost', database: process.env.PGDATABASE ?? 'mydb', user: process.env.PGUSER ?? 'user', password: process.env.PGPASSWORD ?? '', port: process.env.PGPORT ?? 5432, autoRecover: true, client_timeout: 5000, }); (async () => { try { const client = await pool.connect(); const res = await client.query('SELECT NOW()'); console.log(res.rows[0]); client.release(); } catch (err) { console.error(err); } finally { await pool.end(); } })();
Debug
Known issues
gotchaRequires pg as a peer dependency; must install both ha-pg and pg.
fix
npm install ha-pg pg
affects: >=0.0.1
gotchaOnly Pool is implemented; other node-postgres modules (Client, ClientBase) are not wrapped.
fix
Use original pg for Client operations.
affects: >=0.0.1
gotchaclient_timeout option can forcibly end idle clients; use with caution as it may disrupt pending operations.
fix
Set to 0 or omit if unintended termination is not desired.
affects: >=0.0.6
gotchaautoCancel option sends cancel requests on reconnect; may have performance implications on high-latency connections.
fix
Disable autoCancel if not needed.
affects: >=0.0.7
gotchaOnly promises API has been tested; callback API may not be fully supported.
fix
Use async/await or .then() patterns.
affects: >=0.0.1
Errors
Common errors & fixes
Error: connect ECONNREFUSED 127.0.0.1:5432
PostgreSQL server is not running or not accessible.
fix
Ensure PostgreSQL is started and connection parameters are correct.
TypeError: pool.end is not a function
Using ha-pg but importing Pool from 'pg' instead of 'ha-pg'.
fix
const { Pool } = require('ha-pg');
Error: Client has already been released
Calling client.release() more than once.
fix
Ensure each client is released exactly once; use try/finally blocks.
pool.status is not a function
Using pg's Pool instead of ha-pg's Pool which adds status().
fix
Import Pool from 'ha-pg'.
Upgrade
Version history
0.0.9latest on npm
Audit
Dependencies
pgrequiredpeer dependency; ha-pg wraps node-postgres Pool and requires it at runtime
Agent activity
19 hits · last 30 days
node
18
Resources
packageha-pg ↗
ha-pg — npm install ha-pg · libregistry