---
title: "A Postgres database for every Vercel and Netlify preview | Xata"
description: "Connect each preview deployment to its own Postgres branch with production-shaped data. The branch is created with the preview and deleted when it goes away."
source: "https://xata.io/solutions/preview"
---

# A database for every preview deployment

Each Vercel or Netlify preview connects to its own Postgres branch with production-shaped data. When the preview goes away, so does the branch.

[Read the docs](/docs/automations/vercel-github-app)[Get started](https://console.xata.io/signup)

### Copy-on-write

Each preview branch starts from production-shaped data without copying it.

### Its own DATABASE_URL

Every preview deployment connects to its own Postgres.

### Gone with the preview

The branch is deleted when the pull request closes.

The problem

## A preview is only as real as the data behind it

Reviewers judge a change by what they see in the preview. If the data behind it is shared or fake, they are judging the wrong thing. Seed data never has the shape, the volume or the edge cases of the rows your users actually create.

### Migrations break other previews

A schema change in one preview breaks every other preview on the same database.

### Test records leak

Data created while reviewing one change shows up in the next review.

### Nobody knows the schema

Staging drifts, and nobody can say which schema it is on today.

How it works

## One branch per preview, created and deleted for you

1. 01

   ### Pull request opens

   A developer or a coding agent opens a pull request.

2. 02

   ### A database branch is created

   The Xata GitHub App creates a branch from your root branch, named after the Git branch. It copies no data, so it is ready in about three seconds.

3. 03

   ### The preview builds against the branch

   Vercel and Netlify expose the Git branch name at build time. A short build step turns it into that branch’s connection string and passes it to the app as DATABASE_URL.

4. 04

   ### The branch is deleted on close

   When the pull request merges or closes, the GitHub App deletes the branch.

Under the hood

### How copy-on-write branching works

Xata separates Postgres compute from copy-on-write storage.

[See the architecture](/postgres-branching#storage-architecture)

Set it up

## Two ways to set it up

Automatic

### GitHub App + Vercel or Netlify

- GitHub
- Vercel
- Netlify

1. 01Install the Xata GitHub App and link the repo
2. 02Add one build step that sets DATABASE_URL
3. 03Every preview gets its own branch

Or run it from any CI

- [Vercel guide](/docs/automations/vercel-github-app)
- [Netlify guide](/docs/quickstarts/netlify)
- [GitHub App](/docs/automations/github-app)

Agent-driven

### Let your coding agent do it

- Claude Code
- Cursor
- Codex

1. 01The agent creates a branch
2. 02It runs the migration and seeds the data it needs
3. 03It opens the pull request, so the preview builds on a migrated database

Try it

- [Xata for coding agents](/docs/ai-agents/overview)
- [Agent guides](/docs/ai-agents/claude-code)

Coding agents

## Your agent can run the whole workflow

Connect the Xata MCP server or install the CLI, and your coding agent can create branches, apply migrations and read schema without touching production.

- Claude Code
- Cursor
- Codex
- VS Code (Copilot)
- Windsurf
- Cline
- OpenCode
- Zed

### [Xata for coding agents](/docs/ai-agents/overview)

[CLI, MCP and agent skills in one place.](/docs/ai-agents/overview)

[Read the guide](/docs/ai-agents/overview)

### [MCP server](/docs/platform/mcp)

[Setup for every supported client.](/docs/platform/mcp)

[Connect MCP](/docs/platform/mcp)

Keep it cheap and safe

## Forgotten previews cost nothing, real data stays private

### [Forgotten previews cost nothing to keep](/scale-to-zero)

[Turn on scale to zero for child branches and a preview nobody opens releases its compute until the next connection.](/scale-to-zero)

[Learn more](/scale-to-zero)

### [Real data you are allowed to use](/postgres-data-masking)

[If production holds personal data, copy it into Xata with masking rules applied and branch previews from the masked copy.](/postgres-data-masking)

[Learn more](/postgres-data-masking)

## More branching workflows

### [One branch per pull request](/solutions/pull-request)

[Test every migration before it merges.](/solutions/pull-request)

[Learn more](/solutions/pull-request)

### [One branch per CI/CD](/solutions/ci-cd)

[A clean database for every test run.](/solutions/ci-cd)

[Learn more](/solutions/ci-cd)

### [Database Branching](/postgres-branching)

[How Xata branches Postgres.](/postgres-branching)

[Learn more](/postgres-branching)

## Give every preview its own database

Production-shaped data behind every Vercel and Netlify preview, deleted when the preview goes away.

[Get started](https://console.xata.io/signup)[Talk to an engineer](https://cal.com/team/xata/xata-sales)
