Knex.js ↔︎ PostgreSQL: Are query-response events deduplicated across pooled connections?
27.5K reputation · 30 Aug 2020, 23:33 UTC
Goal
Implement a low‑noise alerting system that watches Knex’s query and query-response events to flag genuinely slow queries while avoiding duplicate notifications in concurrent workloads.
Constraints
Knex’s event system is global per instance, and each physical connection in the default pool emits a query-response event when it completes a query. In high‑concurrency scenarios, the same logical query may trigger multiple events, potentially inflating alert counts. The documentation does not state whether these events are deduplicated or if configuration options exist to suppress duplicates.
Unresolved Behavior
It remains unclear if the duplication of query-response events is inherent to Knex’s design or can be mitigated through pool or driver settings. Understanding this behavior is critical before deploying production alerting pipelines.
Specific Questions
- Does Knex emit one
query-responseevent per logical query when using the default connection pool, or are multiple events emitted for each physical connection that executes the query? - If duplicates occur, is there a documented mechanism—such as pool configuration, driver flags, or listener options—to deduplicate or suppress redundant events?
- Do different database drivers (e.g., PostgreSQL vs. MySQL) exhibit consistent event emission patterns, or does driver‑specific behavior influence duplicate alert generation?