---
title: "Drizzle"
description: "Connect Drizzle ORM to your PostgreSQL database through PgBeam for connection pooling, caching, and global routing."
canonical: "https://pgbeam.com/docs/drizzle"
last-updated: "2026-09-14T19:37:21.000Z"
---

# Drizzle

> Connect Drizzle ORM to your PostgreSQL database through PgBeam for connection pooling, caching, and global routing.

URL: https://pgbeam.com/docs/drizzle

Connect your Drizzle ORM application to PgBeam by updating the connection string. No changes to your schema definitions, table declarations, or queries are required.

## Setup

## Update your environment

## Configure the database client

## Run a test query

If this returns results, Drizzle is connected through PgBeam.

## Connection pool sizing

PgBeam handles upstream connection pooling, so the `pg` pool on your application side should be small. A pool size of 3-5 per application instance is typically sufficient.

Deployment type

Recommended `max` pool size

Single server

5-10

Multiple replicas/pods

3-5 per instance

Serverless (Lambda)

1-2

With PgBeam in transaction pool mode, each Drizzle connection only holds an
upstream connection for the duration of a transaction. This means a small
local pool can handle high concurrency.

## Drizzle Kit migrations

Run Drizzle Kit migrations directly against your origin database, not through
PgBeam. Migrations may use session features that behave differently through a
connection pool.

The same applies to `drizzle-kit push` for development:

## Caching with Drizzle

## Query builder queries (recommended)

For standard Drizzle query builder queries (`db.select()`, `db.query`, etc.), PgBeam automatically tracks the generated SQL shapes. Enable caching for these through Cache Rules in the dashboard, with no code changes needed.

## Raw queries with annotations

Use Drizzle's `sql` template for fine-grained cache control:

## Read replicas with Drizzle

Route read queries to replicas using the `/* @pgbeam:replica */` annotation:

Standard query builder calls always go to the primary database. To use replica routing, use raw SQL with the annotation.

See Read Replicas for details on replica setup.

## Debugging

Enable PgBeam debug output to verify caching and routing:

## Common issues

Issue

Cause

Fix

"Too many connections" errors

`pg` pool too large

Set `max: 5` in Pool config

Migrations fail through PgBeam

Session features not available

Run migrations against origin directly

Stale data after writes

Cache returning old results

Use `noCache` annotation or adjust TTL

## Further reading

Connection Pooling: Pool modes and sizing guidance

Caching: TTL, SWR, cache rules, and SQL annotations

Read Replicas: Replica setup and routing