Repository navigation
stream: docs and tutorial for xata clone stream #37
Changes from 5 commits
76fa2f7
1f0f2ff
3eedce6
c2cc027
533e3b7
8f5e73e
8c5d338
33eb733
2ccc958
cb77a57
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,7 +9,7 @@ The `clone` command helps you create a copy of your Xata database or clone an ex | |
|
|
||
| ### start | ||
|
|
||
| Snapshot performs a snapshot of the configured source Postgres database into the configured target. | ||
| Start performs a snapshot of the configured source Postgres database into the configured target. | ||
|
|
||
| ```bash | ||
| xata clone start [--source-url <url>] [--config <file>] [--log-level <level>] [--dump-file <file>] [--postgres-url <url>] [--profile] [--reset] [--tables <tables>] [--target <type>] [--target-url <url>] [--organization <id>] [--project <id>] [--branch <id>] [--filter-tables <tables>] [--validation-mode <mode>] [--role <role>] [-h|--help] | ||
|
|
@@ -35,7 +35,7 @@ xata clone start [--source-url <url>] [--config <file>] [--log-level <level>] [- | |
|
|
||
| ### config | ||
|
|
||
| Automatically configure the transforms for the clone command. | ||
| Automatically configure the transformations for the clone command. | ||
|
|
||
| ```bash | ||
| xata clone config [--source-url <url>] [--mode <mode>] [--validation-mode <mode>] [--organization <id>] [--project <id>] [--branch <id>] [-h|--help] | ||
|
|
@@ -49,6 +49,33 @@ xata clone config [--source-url <url>] [--mode <mode>] [--validation-mode <mode> | |
| - `--branch`: Branch ID (default: "") | ||
| - `-h, --help`: Print help information and exit | ||
|
|
||
| ### stream | ||
|
|
||
| Start a continuous data stream from the configured source to the configured target. | ||
|
|
||
| ```bash | ||
| xata clone stream --source-url <url> [--config <file>] [--log-level <level>] [--init] [--profile] [--replication-slot <name>] [--reset] [--snapshot-tables <tables>] [--source <type>] [--target <type>] [--target-url <url>] [--organization <id>] [--project <id>] [--branch <id>] [--filter-tables <tables>] [--validation-mode <mode>] [--role <role>] [-h|--help] | ||
| ``` | ||
|
|
||
| - `--source-url`: The source URL of the database to stream from (required) | ||
| - `--config`: .env or .yaml config file to use with pgstream if any | ||
| - `--log-level`: Log level for pgstream (trace|debug|info|warn|error|fatal|panic, default: info) | ||
| - `--init`: Whether to initialize pgstream before starting replication | ||
| - `--profile`: Whether to expose a /debug/pprof endpoint on localhost:6060 | ||
| - `--replication-slot`: Name of the postgres replication slot for pgstream to connect to | ||
|
divyenduz marked this conversation as resolved.
|
||
| - `--reset`: Whether to reset the target before snapshotting (only for postgres target) | ||
| - `--snapshot-tables`: List of tables to snapshot if initial snapshot is required, in the format `<schema>.<table>`. If not specified, the schema `public` will be assumed. Wildcards are supported | ||
| - `--source`: Source type. One of postgres, kafka | ||
| - `--target`: Target type. One of postgres, opensearch, elasticsearch, kafka | ||
| - `--target-url`: Target URL | ||
| - `--organization`: Organization ID | ||
| - `--project`: Project ID | ||
| - `--branch`: Branch ID | ||
| - `--filter-tables`: Tables to filter (default: _._) | ||
| - `--validation-mode`: Anonymization validation mode, strict implies that all tables and columns should be specified (strict|relaxed|prompt, default: prompt) | ||
| - `--role`: Postgres role to use for streaming | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we state this role, should have at least
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updated the docs to add a note (and added it to the CLI --help)
That's a good idea, but I think it should come from There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I haven't tested, but I would expect this to fail if the role doesn't work for replication. However, the snapshot would succeed.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe it should check that upfront and fail early? |
||
| - `-h, --help`: Print help information and exit | ||
|
|
||
| ## Global Flags | ||
|
|
||
| - `-h, --help` - Print help information and exit | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| --- | ||
| title: Stream Command | ||
| description: Commands for managing database streaming operations | ||
| --- | ||
|
divyenduz marked this conversation as resolved.
|
||
|
|
||
| The `stream` command helps you manage database streaming operations, including destroying pgstream setups. | ||
|
|
||
|
divyenduz marked this conversation as resolved.
|
||
| ## Subcommands | ||
|
|
||
| ### destroy | ||
|
|
||
| Destroy any pgstream setup, removing the replication slot and all the relevant tables/functions/triggers, along with the internal pgstream schema. | ||
|
gulcin marked this conversation as resolved.
|
||
|
|
||
| ```bash | ||
| xata stream destroy --source-url <url> [--config <file>] [--log-level <level>] [--postgres-url <url>] [--replication-slot <name>] [-h|--help] | ||
| ``` | ||
|
|
||
| - `--source-url`: The source URL of the database to clone (required) | ||
| - `--config`: .env or .yaml config file to use with pgstream if any | ||
| - `--log-level`: Log level for pgstream (trace|debug|info|warn|error|fatal|panic, default: info) | ||
| - `--postgres-url`: Source postgres URL where pgstream destroy will be run | ||
| - `--replication-slot`: Name of the postgres replication slot to be deleted by pgstream from the source url | ||
| - `-h, --help`: Print help information and exit | ||
|
|
||
| ## Global Flags | ||
|
|
||
| - `-h, --help` - Print help information and exit | ||
| - `--json` - Output in JSON format | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,156 @@ | ||
| --- | ||
| title: Set up streaming replication | ||
| description: Use Xata's streaming replication to keep your database continuously synchronized with real-time changes. | ||
|
divyenduz marked this conversation as resolved.
|
||
| --- | ||
|
|
||
| This guide shows you how to set up continuous streaming replication from your production PostgreSQL database to Xata, enabling real-time data synchronization with optional anonymization. | ||
|
|
||
|
divyenduz marked this conversation as resolved.
|
||
|  | ||
|
|
||
| ## 1. Prerequisites | ||
|
|
||
| - A Xata account ([sign up here](https://console.xata.io)) | ||
| - The [Xata CLI](/cli) installed: | ||
| ```bash | ||
| curl -fsSL https://xata.io/install.sh | bash | ||
| ``` | ||
| - A PostgreSQL database with: | ||
| - Logical replication enabled | ||
| - A dedicated replication slot (or permissions to create one) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How were we creating a slot if it does not exist? With
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we make it clear here, we get this covered basically so they don't need to go ahead an create a slot?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Made it so "- Role with permissions to create a replication slow ( |
||
| - Network connectivity from Xata to your database | ||
|
|
||
| ## 2. Enable logical replication on source database | ||
|
|
||
| First, ensure your source PostgreSQL database has logical replication enabled. You'll need to set these parameters: | ||
|
|
||
| ```sql | ||
| -- Check current settings | ||
| SHOW wal_level; | ||
| SHOW max_replication_slots; | ||
| SHOW max_wal_senders; | ||
| ``` | ||
|
|
||
| If not already configured, update your PostgreSQL configuration: | ||
|
|
||
| ```sql | ||
| ALTER SYSTEM SET wal_level = logical; | ||
| ALTER SYSTEM SET max_replication_slots = 10; | ||
| ALTER SYSTEM SET max_wal_senders = 10; | ||
| ``` | ||
|
|
||
| Restart your PostgreSQL instance for the changes to take effect. | ||
|
|
||
| ## 3. 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. | ||
|
|
||
| For streaming replication, consider using at least 1 replica to ensure high availability during continuous synchronization. Select an instance size that can handle your expected write throughput. | ||
|
|
||
| > **Note:** Streaming replication maintains a persistent connection to your source database. Ensure your network allows stable, long-lived connections between Xata and your PostgreSQL instance. | ||
|
|
||
| ## 4. Configure the Xata CLI | ||
|
|
||
| Authenticate the CLI by running: | ||
|
|
||
| ```sh | ||
| xata auth login | ||
| ``` | ||
|
|
||
| Initialize the project by running: | ||
|
|
||
| ```sh | ||
| xata init | ||
| ``` | ||
|
|
||
| ## 5. Configure streaming replication | ||
|
|
||
| Generate a configuration for the streaming process: | ||
|
|
||
| ```bash | ||
| xata clone config --source-url $CONN_STRING | ||
| ``` | ||
|
|
||
| Where `CONN_STRING` is your PostgreSQL connection string with replication permissions. | ||
|
|
||
| The configuration prompt will ask you to: | ||
|
|
||
| - Select tables to replicate | ||
| - Configure anonymization rules if needed | ||
|
eminano marked this conversation as resolved.
Outdated
|
||
| - Set up transformation pipelines | ||
|
|
||
| This creates a configuration file at `.xata/clone.yaml` that you can further customize. | ||
|
|
||
| ## 6. Initialize and start streaming | ||
|
|
||
| First, initialize the streaming setup with an optional initial snapshot: | ||
|
|
||
|
divyenduz marked this conversation as resolved.
Outdated
|
||
| ```bash | ||
| xata clone stream --source-url $CONN_STRING | ||
| ``` | ||
|
|
||
| This command will: | ||
|
|
||
| - Create an initial snapshot of your specified tables | ||
| - Set up the streaming pipeline | ||
| - Begin continuous replication | ||
|
|
||
| ## 7. Advanced configuration | ||
|
|
||
| ### Filtering specific tables | ||
|
|
||
| To stream only specific tables, use the `--filter-tables` flag: | ||
|
gulcin marked this conversation as resolved.
|
||
|
|
||
| ```bash | ||
| xata clone stream --source-url $CONN_STRING \ | ||
| --filter-tables "users.*,orders.*,products.*" | ||
| ``` | ||
|
|
||
| ### Custom transformations | ||
|
|
||
| Edit your `.xata/clone.yaml` file to add custom transformations: | ||
|
|
||
| ```yaml | ||
| transforms: | ||
| - table: users | ||
| columns: | ||
| - name: email | ||
| transformer: mask_email | ||
| - name: phone | ||
| transformer: redact | ||
| - table: orders | ||
| columns: | ||
| - name: credit_card | ||
| transformer: mask_credit_card | ||
| ``` | ||
|
|
||
| ### Running with Docker | ||
|
|
||
| For production deployments, consider running the streaming process in a containerized environment: | ||
|
|
||
| ```bash | ||
| docker run -d \ | ||
| --name xata-stream \ | ||
| --restart unless-stopped \ | ||
| -v $(pwd)/.xata:/config \ | ||
| xata/cli clone stream \ | ||
| --source-url $CONN_STRING | ||
| ``` | ||
|
|
||
| ## 10. Handling failures and recovery | ||
|
|
||
| If the streaming connection is interrupted, the replication slot ensures no data is lost. Simply restart the streaming command: | ||
|
|
||
|
divyenduz marked this conversation as resolved.
|
||
| ```bash | ||
| xata clone stream --source-url $CONN_STRING | ||
| ``` | ||
|
|
||
| The process will resume from where it left off, catching up with any changes that occurred during the downtime. | ||
|
divyenduz marked this conversation as resolved.
|
||
|
|
||
| ## Summary | ||
|
|
||
| - You now have real-time streaming replication from your PostgreSQL database to Xata | ||
|
divyenduz marked this conversation as resolved.
Outdated
|
||
| - Changes in your source database are automatically synchronized | ||
| - Your data can be anonymized in transit using configurable transformers | ||
| - The replication slot ensures no data loss during network interruptions | ||
|
|
||
| For more details on advanced streaming configurations and monitoring, see the [clone command documentation](/cli/clone). | ||
Uh oh!
There was an error while loading. Please reload this page.