Search code examples
node.jspostgresqlknex.js

Knex: Timeout acquiring a connection when running `knex migrate`


I'm running ./node_modules/.bin/knex migrate:latest --env local

Which results in the following error:

> knex migrate:latest --env local

Requiring external module ts-node/register
Using environment: local
TimeoutError: Knex: Timeout acquiring a connection. The pool is probably full. Are you missing a .transacting(trx) call?
at /Users/ashok/src/super-abs/alpha/server/node_modules/knex/lib/client.js:318:17
    at tryCatcher (/Users/ashok/src/super-abs/alpha/server/node_modules/bluebird/js/release/util.js:16:23)
    at /Users/ashok/src/super-abs/alpha/server/node_modules/bluebird/js/release/catch_filter.js:17:41
    at tryCatcher (/Users/ashok/src/super-abs/alpha/server/node_modules/bluebird/js/release/util.js:16:23)
    at Promise._settlePromiseFromHandler (/Users/ashok/src/super-abs/alpha/server/node_modules/bluebird/js/release/promise.js:547:31)
    at Promise._settlePromise (/Users/ashok/src/super-abs/alpha/server/node_modules/bluebird/js/release/promise.js:604:18)
    at Promise._settlePromise0 (/Users/ashok/src/super-abs/alpha/server/node_modules/bluebird/js/release/promise.js:649:10)
    at Promise._settlePromises (/Users/ashok/src/super-abs/alpha/server/node_modules/bluebird/js/release/promise.js:725:18)
    at _drainQueueStep (/Users/ashok/src/super-abs/alpha/server/node_modules/bluebird/js/release/async.js:93:12)
    at _drainQueue (/Users/ashok/src/super-abs/alpha/server/node_modules/bluebird/js/release/async.js:86:9)
    at Async._drainQueues (/Users/ashok/src/super-abs/alpha/server/node_modules/bluebird/js/release/async.js:102:5)
    at Immediate.Async.drainQueues [as _onImmediate] (/Users/ashok/src/super-abs/alpha/server/node_modules/bluebird/js/release/async.js:15:14)
    at processImmediate (internal/timers.js:456:21)

I've even tried deleting the database and re-running.

Are there connections I need to clear somehow? My app is not running.

Using the following

"knex": "0.19.0",

node -v: v14.0.0

psql (PostgreSQL) 11.7


Solution

  • Fixed this by simply downgrading to node version 13.11.0:

    sudo npm install -g n
    sudo n 13.11.0
    knex migrate:latest
    #  Requiring external module ts-node/register
    #  Using environment: local
    #  Batch 1 run: 63 migrations
    

    Yay.