UNPKG

@arturwojnar/hermes-postgresql

Version:

Production-Ready TypeScript Outbox Pattern for PostgreSQL

27 lines 905 B
import { swallow } from '@arturwojnar/hermes'; const killReplicationProcesses = async (sql, slotName) => { await swallow(async () => { const backendProcesses = await sql.unsafe(` SELECT pid FROM pg_stat_replication WHERE application_name = '${slotName}' AND state = 'streaming' `); for (const { pid } of backendProcesses) { await sql.unsafe(`SELECT pg_terminate_backend($1)`, [pid]); } }); await swallow(async () => { const idleProcesses = await sql.unsafe(` SELECT pid FROM pg_stat_activity WHERE application_name = '${slotName}' AND state = 'idle' `); for (const { pid } of idleProcesses) { await sql.unsafe(`SELECT pg_terminate_backend($1)`, [pid]); } }); }; export { killReplicationProcesses }; //# sourceMappingURL=killBackendReplicationProcesses.js.map