Skip to main content

Connection Pooling

A connection pool is a storage of database connections that can be reused for future requests to the database. When a new connection is requested, it is retrieved from the pool if one is available. Once the connection is no longer needed, it is returned to the pool for reuse.

Connection pooling is important as it allows you to reuse existing connections instead of creating new ones, which can be an expensive operation.

The efficient management of database connections allows the database to process more queries without exhausting the available database connections, making your application more scalable.

Accelerate provides built-in connection pooling by default. By simply using Accelerate, you get the benefits of connection pooling without having to configure anything. However, you can also configure the connection pool to suit your needs.

info

For more information about connection pooling in Prisma, see the documentation here.

Default connection pool size

Accelerate has a default connection_limit set to 10.

Configuring the connection pool size

The connection pool size can be configured via the database connection string in your Platform project (not the Accelerate connection string in your Prisma schema) via the connection_limit parameter. For example, set a connection pool size of 10 like this: postgresql://USER:PASSWORD@HOST:PORT/DATABASE?connection_limit=10.

If nothing is configured, a default value will be used.

To change the size of the connection pool:

  1. Open the .
  2. Select the project in which you're using Accelerate. You might need to select a different workspace if you can't see your project.
  3. Select the environment where you want to configure Accelerate's connection pool size.
  4. Update the connection string by appending the connection_limit argument.

Update database connection string in Accelerate

Configuring the connection pool timeout

The connection pool timeout is the maximum number of seconds that a query will block while waiting for a connection from Accelerate's internal connection pool. This occurs if the number of concurrent requests exceeds the connection limit, resulting in queueing of additional requests until a free connection becomes available. An exception is thrown if a free connection does not become available within the pool timeout. The connection pool timeout can be disabled by setting the value to 0.

Similar to the connection pool size, you may also configure the connection pool timeout via the database connection string. To adjust this value, you may add the pool_timeout parameter to the database connection string.

For example:

postgresql://user:password@localhost:5432/db?connection_limit=10&pool_timeout=20
info

The default value for pool_timeout is 10 seconds.