Heroku - error KnexTimeoutError: Knex: Timeout acquiring a connection. The pool is probably full. Are you missing a .transacting(trx) call?

Hi guys, I have a problem on Herku: :thinking:


What’s the problem? - Does it have to do with the fact that my Strapi on Heroku only has the Hobby Dyno Type? :roll_eyes:
Thanks in advance!

There have been a few times this question has come up:

Also from knex itself:

And Stack overflow:


Short answer is you may need to tweak your pool settings which can be found here: Configuration | Strapi Developer Documentation

If you have a moderately sized project, generally yes, because the hobby DB type has very very small resource limits (below what even PG themselves recommend)

@DMehaffy Thank you for the fast answer!
By the way, I have the database Heroku Postgres (Hobby Basic).

Should I rather upgrade my Strap dyno Type or my database, or both? :beer:
Many thanks!

@DMehaffy I just upgraded my Dyno Type to “Standard 1x”, but nothing happened, the problem is still there. Now it looks like I have to upgrade my Postgres database to “Standard 0”.

@DMehaffy My strapi is now set to Dyno Standard 1x and Postgres Database Standard-0. Unfortunately, the problem has not yet been resolved and must be something else. :thinking:

Do you have another idea?

@mingxi as I linked above, you will probably need to tune your Knex pool (tarn) settings. All of those various issues I linked should have some additional context.

I can’t give you a copy paste answer for the tuning as it varies project to project.

For anyone else that comes across this error while attempting to deploy to heroku, here is how I fixed it.

I added the line ssl: { rejectUnauthorized: false } to the database connection settings.

It looks like the official strapi documentation now includes this, but I was attempting to deploy a legacy application that did not have this config. Configuration | Strapi Developer Documentation

return {
  connections: {
    default: {
      settings: {
        client: 'postgres',
        host: env('DATABASE_HOST', '127.0.0.1'),
        port: env.int('DATABASE_PORT', 5432),
        database: env('DATABASE_NAME', 'strapi'),
        username: env('DATABASE_USERNAME', 'strapi'),
        password: env('DATABASE_PASSWORD', 'strapi'),
        schema: 'public',
        ssl: { rejectUnauthorized: false }, // this line is required
      },
    }
  }
}