I'm encountering a KnexTimeoutError when attempting to deploy my Node.js application's database changes using a series of npm scripts that utilize Knex migrations. My goal is to rollback all migrations, apply the latest migrations, and then seed the database, executed in a single npm command. The specific command I'm running is,
"deploy:fresh": "npm run knex:migrate:rollback:all && npm run knex:migrate:latest && npm run knex:seed:run"
I have been running this command quite a lot of times during development.
My stack,
- NestJS
- Objection.js ORM (with knex.js)
- PostgreSQL (on Supabase)
I know a similar alternative question (Knex: Timeout acquiring a connection. The pool is probably full. Are you missing a .transacting(trx) call?) exists, but it's too old and the versions suggested are too old for me now.
- "knex": "^3.1.0"
- "objection": "^3.1.4",
- "pg": "^8.11.3",
We would need to see your knex settings. In the connection object, there are (optional) settings for the connection pool.
You could try to up the max to something than the default, which is 10. But you should know that something in your script is likely a bit unhealthy if it eats up all those connections. This is more of a plaster than a remedy...
Btw, make sure that the connection to the db works in the first place so that is not the issue.