This guide shows you how to create a realistic staging environment in Xata by cloning your production database, optionally anonymizing sensitive data.Documentation Index
Fetch the complete documentation index at: https://xata.io/docs/llms.txt
Use this file to discover all available pages before exploring further.

1. Prerequisites
- A Xata account (sign up here)
- The Xata CLI installed:
- Access to your production PostgreSQL database
2. Create a Xata project and branch
In the Console, create a new project and then click the Create main branch button to create the PostgreSQL instance.
3. Configure the Xata CLI
Authenticate the CLI by running:xata init command in your application source directory, or in any directory/repository where you’d like to keep the configuration. It will create a .xata folder with several configuration files.
Follow the instructions from the prompt to select the project and branch that you created at the previous step. Leave the database name set to xata.
4. Get the connection string of your current provider
This step depends on your Postgres provider, but keep the following recommendations in mind:- If your provider offers a read-only endpoint, it is recommended to use that one in order to avoid extra load to your primary instance.
- If your provider offers a “pooler” or “pgbouncer” endpoint, avoid that one, because
xata cloneuses a long running transaction. - The Postgres connection string generally has the form
postgres://user:pass@host:5432/dbname.
5. Configure cloning
First, generate a configuration for the Xata clone process:CONN_STRING variable is set to the production connection string from the previous step.
.xata/clone.yaml. You can edit this file to further configure your anonymization process.
6. Start the clone
Now, run the clone command to snapshot your production database into Xata:- The clone process will copy data and apply your anonymization rules to the current (staging) branch.
7. Create a branch from the production clone
Now, list your branches to get the staging branch ID:staging branch ID from the list and create a new dev branch from staging:
Summary
- You now have a realistic, anonymized production clone in Xata.
- You can safely test schema migrations, new indexes, or any other database changes using instant Copy-on-Write branches.