Search code examples
postgresqlknex.js

How to time how long it took for Postgres to actually execute in query using Knex


How to time how long it took for Postgres to actually execute in query using Knex? Is there a way to do this?

Ideally, I'd like to see a breakdown of timings like: time to acquire socket from pool, time for PG to execute query, time to receive bytes.


Solution

  • Run your app with environment variable DEBUG=knex:* and it will print lots of info about how long certain things took.

    Also you can add event handlers to query events http://knexjs.org/#Interfaces-Events and do your own timers there. Those events can be also set globally like knex.on('query', ...).