The instant database scratchpad: xata scratch
xata scratch gives you a disposable copy of your Postgres from the terminal. One command forks a branch with your real data, runs your query, and deletes it.
By:
Divyendu SinghPublished:
Reading time:
2 min readPreviously we have explored what workflows can we unlock, if database branches were easy, cost effective (1000 branches for $1) and fast (1-2 second boot time).
One workflow it opens up is “scratch pad for database”. A single command that allows your to run one-off experiments against production using an isolated instant database branch that is automatically deleted once the task is done.
TL;DR; (on an initialized project)
xata scratch -x "SELECT <heavy analytical query> FROM <a core high transaction database>" to isolate one off heavy analytical queries on copy of production data without competing on resources with production traffic.
OR
xata scratch -x "SELECT <...>" to check the performance of a query you want to optimize on realistic data
OR
xata scratch psql a single command to create a branch and drop into any binary like psql, pgcli or even a custom one, as long as it supports the standard Postgres environment variables.
OR
xata scratch <prompt your AI agent to use the scratch command when investigating a problem, validating a migration or testing a query>
OR
xata scratch <insert your use case>
Here you can see it in action:
Under the hood
Under the hood, xata scratch command doesn’t do anything fancy, it simply creates ephemeral branches by
- calls our create branch API which is fast by default
- we call it with sane parameters like scale to zero enabled
- wake up time is also around a second
- it injects known / common environment variables into the subprocess
- it calls either an inline query or a binary
- as the subprocess returns, it terminates the scratch / child branch
- profit, that’s all it needs to create a database scratchpad via ephemeral database branches
As you can see the command itself is straightforward. What makes it possible is an architecture where creating and deleting database branches is so fast and cheap that they can be treated as disposable resources.
More to come
Having access to instant and cost effective database branches opens up workflows which were previously unimaginable. We are exploring the frontier of developer experience we can provide with the end goal of saving costs (productivity, lower CI times) and increasing confidence (realistic data makes developing complicated features easier, think preview branches but with realistic data).
Try it out
You can try all this today by simply signing up and starting a new project on Xata. If you have any questions or interesting use-cases, please don’t hesitate to reach out.
Give every agentic workload its own Postgres branch
Create instant database clones with production-like data for every agent, workflow, and CI/CD pipeline.
Related Posts
Database branching for AI coding agents: a minimal, CLI-first setup that actually works
Learn how to enable database branching for coding agents like Claude Code and Amp Code using simple Xata CLI instructions in AGENTS.md. No complex skills required.
Every AI agent needs a database it can break
AI agents need two infrastructure layers: real-time streaming for fresh data and database branching for sandboxes. How to build both with Postgres.
Teaching Claude Code to use isolated database branches with Agent Skills
Learn how to set up the Xata Agent Skill in minutes. Enable Claude Code to access realistic data using isolated database branches for safer, faster debugging.
From DBA to DB Agents
Discover how a PostgreSQL DBA’s decade of expertise evolved into designing Xata’s AI-powered Postgres agent, automating monitoring and observability.