UNPKG

@clickup/pg-microsharding

Version:
42 lines 1.8 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getPhysicalReplicas = getPhysicalReplicas; const parseLsn_1 = require("./parseLsn"); const quote_1 = require("./quote"); const runSql_1 = require("./runSql"); /** * Returns detailed information about physical replicas of a DSN. Works for * vanilla PostgreSQL only: in Aurora, it returns an empty array. */ async function getPhysicalReplicas({ dsn, comment, }) { const replicas = await (0, runSql_1.runSql)(dsn, (0, quote_1.sql) ` SELECT pid, client_addr, usename, application_name, EXTRACT(EPOCH FROM replay_lag), EXTRACT(EPOCH FROM (now() - reply_time)), sent_lsn, replay_lsn FROM pg_stat_replication WHERE application_name = 'walreceiver' OR pid IN (SELECT active_pid FROM pg_replication_slots WHERE slot_type = 'physical') `, comment); return replicas.map(([pid, clientAddr, userName, applicationName, lagSec, feedbackAgoSec, masterLsn, replicaLsn,]) => ({ pid, clientAddr, userName, applicationName, // "If the standby server has entirely caught up with the sending server // and there is no more WAL activity, the most recently measured lag times // will continue to be displayed for a short time and then show NULL." lagSec: lagSec ? Math.round(parseFloat(lagSec)) : 0, feedbackAgoSec: feedbackAgoSec !== "" ? Math.round(parseFloat(feedbackAgoSec)) : null, masterLsn: (0, parseLsn_1.isLsn)(masterLsn) ? masterLsn : null, replicaLsn: (0, parseLsn_1.isLsn)(replicaLsn) ? replicaLsn : null, gap: (0, parseLsn_1.subtractLsn)(masterLsn, replicaLsn), })); } //# sourceMappingURL=getPhysicalReplicas.js.map