---
title: Efficiently manage database connection pools with Fluid compute
description: How to create high-performance database connection pools without leaking connections
url: /kb/guide/efficiently-manage-database-connection-pools-with-fluid-compute
canonical_url: "https://vercel.com/kb/guide/efficiently-manage-database-connection-pools-with-fluid-compute"
published: 2025-11-21
last_updated: 2026-06-17
authors: Anthony Shew
related:
  - /docs/fundamentals/what-is-compute
  - /docs/functions/functions-api-reference/vercel-functions-package
  - /docs/fluid-compute
  - /docs/frameworks/backend
install_vercel_plugin: npx plugins add vercel/vercel-plugin
---
<!-- docsgraph:related -->
## Related pages

> **For AI agents:** Follow these links to understand how this page connects to the rest of the Vercel ecosystem. For the full cross-link map (inbound, outbound, prerequisites, and semantic neighbors), see the .graph.md link below.

- [Connection Pooling with Vercel Functions](https://vercel.com/kb/guide/connection-pooling-with-functions?from=related) — Learn best practices for connecting to relational databases with Vercel Functions and Fluid compute
- [Functions](https://vercel.com/docs/functions?from=related) — Run server-side code on Vercel without managing a server.
- [Pricing](https://vercel.com/docs/functions/usage-and-pricing?from=related) — Learn about usage and pricing for fluid compute on Vercel.
- [How Vercel Services run on Fluid compute](https://vercel.com/kb/guide/vercel-services-fluid-compute?from=related) — The backends in a Vercel Services project run as Vercel Functions on Fluid compute by default. Learn how optimized concu
- [How to stop Vercel Functions from timing out](https://vercel.com/kb/guide/what-can-i-do-about-vercel-serverless-functions-timing-out?from=related) — Vercel Functions that time out usually trace back to a few causes. Learn how Fluid Compute fixes most of them and how to
- [Hosting your API on Vercel](https://vercel.com/kb/guide/hosting-backend-apis?from=related) — Learn how to build and scale performant APIs on Vercel.
- [How do I lower my Vercel Function execution time?](https://vercel.com/kb/guide/how-do-i-lower-my-serverless-function-execution-time?from=related) — Learn how to lower your Serverless Function execution time.

Full cross-link map for this page: [/kb/guide/efficiently-manage-database-connection-pools-with-fluid-compute.graph.md](/kb/guide/efficiently-manage-database-connection-pools-with-fluid-compute.graph.md)
<!-- /docsgraph:related -->


Establishing a database connection is expensive—requiring TCP handshakes, authentication, and resource allocation that can take 50-100ms or more. Without connection pooling, applications create and destroy connections for every request, wasting resources and overwhelming databases until they hit connection limits and crash under load.

Connection pooling maintains a ready pool of reusable connections, eliminating this overhead and enabling applications to scale efficiently under real-world traffic. Requests to your database become faster since your application can use an existing connection instead of creating a new one.

However, managing the behavior of database connection pools so that they both reuse connections and don’t leak can be difficult in serverless environments. On Vercel’s Fluid compute, connection pools are much easier to manage.

## What is Fluid compute?

Fluid compute offers a blend of serverless flexibility and server-like capabilities. Unlike traditional [serverless architectures](https://vercel.com/docs/fundamentals/what-is-compute#serverless), which can face issues such as cold starts and [limited functionalities](https://vercel.com/docs/fundamentals/what-is-compute#serverless-disadvantages), fluid compute provides a hybrid solution. It overcomes the limitations of both serverless and server-based approaches, delivering the advantages of both worlds,

Additionally, Fluid compute is billed using Active CPU pricing, meaning you only pay for the compute that you use. When your backend is waiting on I/O like database queries, AI model calls, and other external services.

## Connection pooling with Fluid compute

To pool connections with Fluid compute on Vercel, use the `attachDatabasePool` function from `@vercel/functions`:

```javascript
import { Pool } from "pg";
import { attachDatabasePool } from "@vercel/functions"

const pool = new Pool({
  connectionString: process.env.POSTGRES_URL,
});
attachDatabasePool(pool);

export default {
  async fetch() {
    const client = await pool.connect();
    try {
      const result = await client.query('SELECT NOW()');
      return Response.json(result.rows[0]);
    } finally {
      client.release();
    }
  },
};
```

`attachDatabasePool` will automatically manage pooling for [supported database clients](https://vercel.com/docs/functions/functions-api-reference/vercel-functions-package#attachdatabasepool), including PostgresQL (`pg`), MySQL2, MariaDB, MongoDB, Redis (`ioredis`), Cassandra (`cassandra-driver`), and more.

## Next steps

- [Learn more about](https://vercel.com/docs/functions/functions-api-reference/vercel-functions-package) `attachDatabasePool`
  
- [Learn more about Fluid compute](https://vercel.com/docs/fluid-compute)
  
- [Learn more about zero-config backends on Vercel](https://vercel.com/docs/frameworks/backend)