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

System Information
  • Strapi v4.1.11:
  • Ubuntu:
  • PostgreSQL:
  • Node v14.19.2:
  • NPM v6.14.17:
  • Yarn Version:

I followed this guide for deploying my strapi backend on an AWS instance and when trying to run get this error:

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

I’ve tried all the tweaks I found online from changing the db inbound rules to allowing all traffic from my IP to adding different pool configurations to my database.js file. Nothing works.

Has anyone been able to find a workaround?

3 Likes

Try adding a large value to acquireConnectionTime to database config.
Example:

module.exports = ({ env }) => ({
connection: {
client: ‘postgres’,
connection: {
host: env(‘DATABASE_HOST’, ‘127.0.0.1’),
port: env.int(‘DATABASE_PORT’, 5432),
database: env(‘DATABASE_NAME’, ‘strapi’),
user: env(‘DATABASE_USERNAME’, ‘strapi’),
password: env(‘DATABASE_PASSWORD’, ‘strapi’),
schema: env(‘DATABASE_SCHEMA’, ‘public’), // Not required
ssl: env(‘DATABASE_SSL’, false)
},
acquireConnectionTimeout: 1000000,
pool: {
min: 0,
max: 1,
acquireTimeoutMillis: 300000,
createTimeoutMillis: 300000,
destroyTimeoutMillis: 300000,
idleTimeoutMillis: 30000,
reapIntervalMillis:1000,
createRetryIntervalMillis: 2000
},
debug: false,
},
});

Hi @jaredriver , were you able to find a solution?

Hey! I have the same problem @shrikant i try with different pool settings but no luck yet:(

@Drakenwolf
Here are the setting that I’m using on my M1 mac for development:

module.exports = ({ env }) => ({
  connection: {
    client: 'postgres',
    connection: {
      host: env('DATABASE_HOST', '127.0.0.1'),
      port: env.int('DATABASE_PORT', 5432),
      database: env('DATABASE_NAME', 'strapi'),
      user: env('DATABASE_USERNAME', 'strapi'),
      password: env('DATABASE_PASSWORD', 'strapi'),
      schema: env('DATABASE_SCHEMA', 'public'), // Not required
      ssl: env('DATABASE_SSL', false)
    },
    acquireConnectionTimeout: 1000000,
    pool: {
      min: 0,
      max: 4,
      acquireTimeoutMillis: 300000,
      createTimeoutMillis: 300000,
      destroyTimeoutMillis: 300000,
      idleTimeoutMillis: 30000,
      reapIntervalMillis:1000,
      createRetryIntervalMillis: 2000
    },
    debug: false,
  },
});

If these fail, try using a larger value for pool.max.
Observe the processor and RAM usage while you start Strapi. See if either of these max outs. You might want to consider using a larger database instance.

Hi, i tried this also with different pool setting but nothing. Do you have any other idea?

I ended up creating self hosting solution after encountering this issue… if anyone interested you can follow details at Strapi (Headless CMS), Google Cloud Run, and PostgreSQL | by Ganesh, Mohan | Jan, 2023 | Medium

Try to see the database log.
I had the same Knex problem, but the real problem was that my IP adress was not allowed in Postgres service on Microsoft azure.
So try to watch the database log while try to start Strapi service.
I hope this solution help you all.

2 Likes

You are absolutely right

Yup, I was working from home and didn’t update the IP on my PostgresDB