---
title: Efficiently manage database connection pools with Fluid compute
description: How to create high-performance database connection pools without leaking connections
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
install_vercel_plugin: npx plugins add vercel/vercel-plugin
---

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)

## More Fluid compute guides

- [The Complete Guide to Vercel Daemons](/kb/guide/vercel-daemons): Run background workers with Vercel Daemons. Learn how to deploy container images, configure resources, handle shutdowns, and manage instances.
- [How to choose between Functions, containers, and Daemons on Vercel](/kb/guide/vercel-functions-containers-daemons): Choose Vercel Functions for HTTP requests, container images for custom runtimes, and Daemons for continuous background workers.
- [How to ship a FastAPI app on Vercel](/kb/guide/ship-a-fastapi-app-on-vercel): Deploy a FastAPI app to Vercel with zero configuration. Learn how the Python runtime, Vercel Functions, streaming, middleware, and cron jobs work together.