{"id":42831,"library":"ha-pg","title":"ha-pg","description":"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.","status":"active","version":"0.0.9","language":"javascript","source_language":"en","source_url":"https://github.com/bitifet/node-postgres-ha","tags":["javascript","postgresql","high-availability","backend","database","postgres","postgre","rdbms","libpq"],"install":[{"cmd":"npm install ha-pg","lang":"bash","label":"npm"},{"cmd":"yarn add ha-pg","lang":"bash","label":"yarn"},{"cmd":"pnpm add ha-pg","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"peer dependency; ha-pg wraps node-postgres Pool and requires it at runtime","package":"pg","optional":false}],"imports":[{"note":"Use ha-pg instead of pg for enhanced Pool. The pg library's Pool is replaced by this wrapper.","wrong":"const { Pool } = require('pg');","symbol":"Pool","correct":"const { Pool } = require('ha-pg');"},{"note":"ESM import available. Type definitions are not bundled; may need @types/pg.","wrong":"import { Pool } from 'pg';","symbol":"Pool","correct":"import { Pool } from 'ha-pg';"},{"note":"Both patterns work, but destructuring is preferred.","wrong":"const Pool = require('ha-pg').Pool;","symbol":"Pool","correct":"const { Pool } = require('ha-pg');"}],"quickstart":{"code":"const { Pool } = require('ha-pg');\nconst pool = new Pool({\n  host: process.env.PGHOST ?? 'localhost',\n  database: process.env.PGDATABASE ?? 'mydb',\n  user: process.env.PGUSER ?? 'user',\n  password: process.env.PGPASSWORD ?? '',\n  port: process.env.PGPORT ?? 5432,\n  autoRecover: true,\n  client_timeout: 5000,\n});\n\n(async () => {\n  try {\n    const client = await pool.connect();\n    const res = await client.query('SELECT NOW()');\n    console.log(res.rows[0]);\n    client.release();\n  } catch (err) {\n    console.error(err);\n  } finally {\n    await pool.end();\n  }\n})();","lang":"javascript","description":"Create a high-availability Pool with autoRecover and client_timeout, run a query, then cleanly shut down."},"warnings":[{"fix":"npm install ha-pg pg","message":"Requires pg as a peer dependency; must install both ha-pg and pg.","severity":"gotcha","affected_versions":">=0.0.1"},{"fix":"Use original pg for Client operations.","message":"Only Pool is implemented; other node-postgres modules (Client, ClientBase) are not wrapped.","severity":"gotcha","affected_versions":">=0.0.1"},{"fix":"Set to 0 or omit if unintended termination is not desired.","message":"client_timeout option can forcibly end idle clients; use with caution as it may disrupt pending operations.","severity":"gotcha","affected_versions":">=0.0.6"},{"fix":"Disable autoCancel if not needed.","message":"autoCancel option sends cancel requests on reconnect; may have performance implications on high-latency connections.","severity":"gotcha","affected_versions":">=0.0.7"},{"fix":"Use async/await or .then() patterns.","message":"Only promises API has been tested; callback API may not be fully supported.","severity":"gotcha","affected_versions":">=0.0.1"}],"env_vars":null,"search_vec":"'0.0.9':46 'activ':47 'address':18 'auto':52 'auto-recoveri':51 'avail':6,78 'backend':79 'cancel':41,65 'client':23,31,56 'common':19 'connect':54 'current':44 'databas':80 'depend':73 'detect':29 'develop':48 'differenti':49 'disconnect':30 'end':61 'enhanc':14 'failur':26 'forc':59 'ha':2 'ha-pg':1 'hang':38 'high':5,77 'high-avail':4,76 'inabl':27 'includ':50 'issu':20 'javascript':74 'libpq':84 'like':21 'monitor':55 'network':25 'node':10,68 'node-postgr':9,67 'peer':72 'pg':3,12 'pool':15,60 'pool.end':37 'postgr':11,69,81,82 'postgresql':75 'queri':40,64 'rdbms':83 'reconnect':43 'recoveri':53 'refer':32 'releas':36 'remain':33 'remot':63 'requir':66 'resili':16 'timeout':57 'unreleas':22 'usabl':34 'version':45 'wrapper':7","created_at":"2026-06-05T16:56:52.904210+00:00","updated_at":"2026-06-05T16:56:52.904210+00:00","problems":[{"fix":"Ensure PostgreSQL is started and connection parameters are correct.","cause":"PostgreSQL server is not running or not accessible.","error":"Error: connect ECONNREFUSED 127.0.0.1:5432"},{"fix":"const { Pool } = require('ha-pg');","cause":"Using ha-pg but importing Pool from 'pg' instead of 'ha-pg'.","error":"TypeError: pool.end is not a function"},{"fix":"Ensure each client is released exactly once; use try/finally blocks.","cause":"Calling client.release() more than once.","error":"Error: Client has already been released"},{"fix":"Import Pool from 'ha-pg'.","cause":"Using pg's Pool instead of ha-pg's Pool which adds status().","error":"pool.status is not a function"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":"https://github.com/bitifet/node-postgres-ha#readme","github":"https://github.com/bitifet/node-postgres-ha","docs":null,"changelog":null,"pypi":null,"npm":"ha-pg","openapi_spec":null,"status_page":null,"smithery":null,"categories":["database","devops"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-05","next_check":"2026-09-03","install_tag":null}}