-
Notifications
You must be signed in to change notification settings - Fork 477
Add new section on read from standby feature #20502
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
peachdawnleach
merged 16 commits into
main
from
2025-10-01-doc-13854-add-read-from-standby
Oct 17, 2025
+206
−0
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
90bf4d9
Added new pages
peachdawnleach bd04a1e
Merge branch 'main' into 2025-10-01-doc-13854-add-read-from-standby
peachdawnleach 1e90a6f
Fixed broken links
peachdawnleach 468ff96
Merge branch '2025-10-01-doc-13854-add-read-from-standby' of github.c…
peachdawnleach 1690300
Lengthened summary
peachdawnleach fbe26de
Changes from review
peachdawnleach 1cc6642
Additional changes from review
peachdawnleach 435c041
Small wording changes
peachdawnleach ee4e585
Merge branch 'main' into 2025-10-01-doc-13854-add-read-from-standby
peachdawnleach 65577b3
Removed monitor replication lag
peachdawnleach d8d6164
Merge branch 'main' into 2025-10-01-doc-13854-add-read-from-standby
peachdawnleach fb8d313
Update read-from-standby.md
peachdawnleach b3e5b1d
Added links
peachdawnleach 712ab1f
Added see also links
peachdawnleach dfb424c
Added see also links
peachdawnleach dca6a6c
Merge branch 'main' into 2025-10-01-doc-13854-add-read-from-standby
peachdawnleach File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
--- | ||
title: Read from Standby | ||
summary: Direct read-only queries to your standby cluster instead of your primary cluster. | ||
toc: true | ||
docs_area: manage | ||
--- | ||
|
||
In addition to providing [failover]({% link {{ page.version.version }}/failover-replication.md %}) capabilities for [disaster recovery]({% link {{ page.version.version }}/disaster-recovery-overview.md %}), [**physical cluster replication (PCR)**]({% link {{ page.version.version }}/physical-cluster-replication-overview.md %}) allows you to direct read-only queries to your standby cluster. This process offloads traffic such as application reads, analytics queries, and ad-hoc reporting from the primary cluster. | ||
|
||
Use this page to understand how the _read from standby_ feature works and how to utilize it. | ||
|
||
## How the read from standby feature works | ||
|
||
PCR utilizes [cluster virtualization]({% link {{ page.version.version }}/cluster-virtualization-overview.md %}) to separate a cluster's control plane from its data plane. A cluster always has one control plane, called a _system virtual cluster (SystemVC)_, and at least one data plane, called an _App Virtual Cluster (AppVC)_. The standby cluster's SystemVC manages the PCR job and other cluster metadata, and is not used for application queries. All data tables, system tables, and cluster settings in the standby cluster's AppVC are identical to the primary cluster's AppVC. The standby cluster's AppVC itself remains offline during replication. | ||
|
||
When using read from standby, applications can read from the standby cluster, but they do not connect directly to the standby cluster's AppVC. Instead, PCR introduces a _reader virtual cluster (ReaderVC)_. The ReaderVC ensures a clean, isolated environment specifically for serving read queries without interfering with replication or system metadata. It reads continuously from the standby cluster's AppVC using internal pointers, providing access to the replicated data while keeping the AppVC offline. The ReaderVC itself only stores a small amount of metadata and no user data, so it is not expected to take up additional storage space. | ||
|
||
The standby cluster's ReaderVC has its own system tables and [cluster settings]({% link {{ page.version.version }}/cluster-settings.md %}). The ReaderVC replicates a subset of system tables, including **Users** and **Roles**, from the AppVC, so that existing primary users can authenticate using the same [users and roles]({% link {{ page.version.version }}/security-reference/authorization.md %}) as on the primary cluster's AppVC. Other system tables and cluster settings are set to defaults in the ReaderVC. For more information, consult [Physical Cluster Replication Technical Overview]({% link {{ page.version.version }}/physical-cluster-replication-technical-overview.md %}). | ||
|
||
In the event of failover, the ReaderVC's response depends on the type of failover. After failover to the latest timestamp, the ReaderVC continues pointing to the AppVC but stops receiving updates. After failover to a point-in-time timestamp, the ReaderVC is destroyed. | ||
|
||
## Use the read from standby feature | ||
### Before you begin | ||
|
||
Prior to setting up read from standby, ensure that: | ||
|
||
- You have already configured PCR between a _primary_ cluster and a _standby_ cluster. For information on configuring PCR, refer to [Set Up Physical Cluster Replication]({% link {{ page.version.version }}/set-up-physical-cluster-replication.md %}). | ||
- Your CockroachDB version is v24.3 or later. The `read from standby` option is not supported in earlier versions. | ||
|
||
### Start a PCR stream with read from standby | ||
|
||
To start a PCR stream that allows read access to the standby cluster, use the [`CREATE VIRTUAL CLUSTER ... REPLICATION`]({% link {{ page.version.version }}/create-virtual-cluster.md %}) statement with the `READ VIRTUAL CLUSTER` option: | ||
|
||
{% include_cached copy-clipboard.html %} | ||
~~~ sql | ||
CREATE VIRTUAL CLUSTER main FROM REPLICATION OF main ON 'postgresql://{connection string to primary}' WITH READ VIRTUAL CLUSTER; | ||
~~~ | ||
|
||
### Add read from standby to a PCR stream | ||
|
||
To add read from standby capabilities to an existing PCR stream, use the [`ALTER VIRTUAL CLUSTER`]({% link {{ page.version.version }}/alter-virtual-cluster.md %}) statement: | ||
|
||
{% include_cached copy-clipboard.html %} | ||
~~~ sql | ||
ALTER VIRTUAL CLUSTER main SET REPLICATION READ VIRTUAL CLUSTER; | ||
peachdawnleach marked this conversation as resolved.
Show resolved
Hide resolved
|
||
~~~ | ||
|
||
{{site.data.alerts.callout_info}} | ||
The standby cluster's AppVC must have a status of `replicating` before you can create your ReaderVC. Use the [`SHOW VIRTUAL CLUSTERS`]({% link {{ page.version.version }}/show-virtual-cluster.md %}) command to check the status of the AppVC. | ||
{{site.data.alerts.end}} | ||
|
||
### Check the status of your reader virtual cluster | ||
|
||
To confirm that your reader virtual cluster is active: | ||
|
||
{% include_cached copy-clipboard.html %} | ||
~~~ sql | ||
SHOW VIRTUAL CLUSTERS; | ||
~~~ | ||
|
||
The output shows a `standby-readonly` virtual cluster in addition to the systemVC and AppVC: | ||
|
||
~~~ | ||
id | name | data_state | service_mode | ||
-----+------------------+-------------+--------------- | ||
1 | system | ready | shared | ||
3 | standby | replicating | none | ||
4 | standby-readonly | ready | shared | ||
~~~ | ||
|
||
{{site.data.alerts.callout_info}} | ||
The ReaderVC cannot serve reads until after the PCR initial scan is complete. After completing the initial scan, wait until the ReaderVC's `service_mode` is `shared`, then wait about one minute before connecting to the ReaderVC. | ||
{{site.data.alerts.end}} | ||
|
||
### Run read-only queries on the standby cluster | ||
|
||
Once you have created a reader virtual cluster on the standby cluster, you can connect to it and run [read (`SELECT`) queries]({% link {{ page.version.version }}/selection-queries.md %}). For example: | ||
|
||
{% include_cached copy-clipboard.html %} | ||
~~~ sql | ||
SELECT COUNT(*) FROM customers; | ||
SELECT region, SUM(amount) FROM orders GROUP BY region; | ||
~~~ | ||
|
||
The results of queries on the standby cluster reflect the state of the primary cluster as of a historical time that approaches the [replicated time]({% link {{ page.version.version }}/show-virtual-cluster.md %}#show-replication-status). | ||
|
||
{{ site.data.alerts.callout_info }} | ||
Write operations are not permitted on the standby cluster. | ||
{{ site.data.alerts.end }} | ||
|
||
## See also | ||
- [Set Up Physical Cluster Replication]({% link {{ page.version.version }}/set-up-physical-cluster-replication.md %}) | ||
- [Fail Over from a Primary Cluster to a Standby Cluster]({% link {{ page.version.version }}/failover-replication.md %}) | ||
- [Physical Cluster Replication Technical Overview]({% link {{ page.version.version }}/physical-cluster-replication-technical-overview.md %}) | ||
- [`CREATE VIRTUAL CLUSTER`]({% link {{ page.version.version }}/create-virtual-cluster.md %}) | ||
- [`ALTER VIRTUAL CLUSTER`]({% link {{ page.version.version }}/alter-virtual-cluster.md %}) | ||
- [`SHOW VIRTUAL CLUSTER`]({% link {{ page.version.version }}/show-virtual-cluster.md %}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
--- | ||
title: Read from Standby | ||
summary: Direct read-only queries to your standby cluster instead of your primary cluster. | ||
toc: true | ||
docs_area: manage | ||
--- | ||
|
||
In addition to providing [failover]({% link {{ page.version.version }}/failover-replication.md %}) capabilities for [disaster recovery]({% link {{ page.version.version }}/disaster-recovery-overview.md %}), [**physical cluster replication (PCR)**]({% link {{ page.version.version }}/physical-cluster-replication-overview.md %}) allows you to direct read-only queries to your standby cluster. This process offloads traffic such as application reads, analytics queries, and ad-hoc reporting from the primary cluster. | ||
|
||
Use this page to understand how the _read from standby_ feature works and how to utilize it. | ||
|
||
## How the read from standby feature works | ||
|
||
PCR utilizes [cluster virtualization]({% link {{ page.version.version }}/cluster-virtualization-overview.md %}) to separate a cluster's control plane from its data plane. A cluster always has one control plane, called a _system virtual cluster (SystemVC)_, and at least one data plane, called an _App Virtual Cluster (AppVC)_. The standby cluster's SystemVC manages the PCR job and other cluster metadata, and is not used for application queries. All data tables, system tables, and cluster settings in the standby cluster's AppVC are identical to the primary cluster's AppVC. The standby cluster's AppVC itself remains offline during replication. | ||
|
||
When using read from standby, applications can read from the standby cluster, but they do not connect directly to the standby cluster's AppVC. Instead, PCR introduces a _reader virtual cluster (ReaderVC)_. The ReaderVC ensures a clean, isolated environment specifically for serving read queries without interfering with replication or system metadata. It reads continuously from the standby cluster's AppVC using internal pointers, providing access to the replicated data while keeping the AppVC offline. The ReaderVC itself only stores a small amount of metadata and no user data, so it is not expected to take up additional storage space. | ||
|
||
The standby cluster's ReaderVC has its own system tables and [cluster settings]({% link {{ page.version.version }}/cluster-settings.md %}). The ReaderVC replicates a subset of system tables, including **Users** and **Roles**, from the AppVC, so that existing primary users can authenticate using the same [users and roles]({% link {{ page.version.version }}/security-reference/authorization.md %}) as on the primary cluster's AppVC. Other system tables and cluster settings are set to defaults in the ReaderVC. For more information, consult [Physical Cluster Replication Technical Overview]({% link {{ page.version.version }}/physical-cluster-replication-technical-overview.md %}). | ||
|
||
In the event of failover, the ReaderVC is destroyed. | ||
|
||
## Use the read from standby feature | ||
### Before you begin | ||
|
||
Prior to setting up read from standby, ensure that: | ||
|
||
- You have already configured PCR between a _primary_ cluster and a _standby_ cluster. For information on configuring PCR, refer to [Set Up Physical Cluster Replication]({% link {{ page.version.version }}/set-up-physical-cluster-replication.md %}). | ||
- Your CockroachDB version is v24.3 or later. The `read from standby` option is not supported in earlier versions. | ||
|
||
### Start a PCR stream with read from standby | ||
|
||
To start a PCR stream that allows read access to the standby cluster, use the [`CREATE VIRTUAL CLUSTER ... REPLICATION`]({% link {{ page.version.version }}/create-virtual-cluster.md %}) statement with the `READ VIRTUAL CLUSTER` option: | ||
|
||
{% include_cached copy-clipboard.html %} | ||
~~~ sql | ||
CREATE VIRTUAL CLUSTER main FROM REPLICATION OF main ON 'postgresql://{connection string to primary}' WITH READ VIRTUAL CLUSTER; | ||
~~~ | ||
|
||
### Add read from standby to a PCR stream | ||
|
||
To add read from standby capabilities to an existing PCR stream, use the [`ALTER VIRTUAL CLUSTER`]({% link {{ page.version.version }}/alter-virtual-cluster.md %}) statement: | ||
|
||
{% include_cached copy-clipboard.html %} | ||
~~~ sql | ||
ALTER VIRTUAL CLUSTER main SET REPLICATION READ VIRTUAL CLUSTER; | ||
~~~ | ||
|
||
{{site.data.alerts.callout_info}} | ||
The standby cluster's AppVC must have a status of `replicating` before you can create your ReaderVC. Use the [`SHOW VIRTUAL CLUSTERS`]({% link {{ page.version.version }}/show-virtual-cluster.md %}) command to check the status of the AppVC. | ||
{{site.data.alerts.end}} | ||
|
||
### Check the status of your reader virtual cluster | ||
|
||
To confirm that your reader virtual cluster is active: | ||
peachdawnleach marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
{% include_cached copy-clipboard.html %} | ||
~~~ sql | ||
SHOW VIRTUAL CLUSTERS; | ||
~~~ | ||
|
||
The output shows a `standby-readonly` virtual cluster in addition to the systemVC and AppVC: | ||
|
||
~~~ | ||
id | name | data_state | service_mode | ||
-----+------------------+-------------+--------------- | ||
1 | system | ready | shared | ||
3 | standby | replicating | none | ||
4 | standby-readonly | ready | shared | ||
~~~ | ||
|
||
{{site.data.alerts.callout_info}} | ||
The ReaderVC cannot serve reads until after the PCR initial scan is complete. After completing the initial scan, wait until the ReaderVC's `service_mode` is `shared`, then wait about one minute before connecting to the ReaderVC. | ||
{{site.data.alerts.end}} | ||
|
||
### Run read-only queries on the standby cluster | ||
|
||
Once you have created a reader virtual cluster on the standby cluster, you can connect to it and run [read (`SELECT`) queries]({% link {{ page.version.version }}/selection-queries.md %}). For example: | ||
|
||
{% include_cached copy-clipboard.html %} | ||
~~~ sql | ||
SELECT COUNT(*) FROM customers; | ||
SELECT region, SUM(amount) FROM orders GROUP BY region; | ||
~~~ | ||
|
||
The results of queries on the standby cluster reflect the state of the primary cluster as of a historical time that approaches the [replicated time]({% link {{ page.version.version }}/show-virtual-cluster.md %}#show-replication-status). | ||
|
||
{{ site.data.alerts.callout_info }} | ||
Write operations are not permitted on the standby cluster. | ||
{{ site.data.alerts.end }} | ||
|
||
## See also | ||
- [Set Up Physical Cluster Replication]({% link {{ page.version.version }}/set-up-physical-cluster-replication.md %}) | ||
- [Fail Over from a Primary Cluster to a Standby Cluster]({% link {{ page.version.version }}/failover-replication.md %}) | ||
- [Physical Cluster Replication Technical Overview]({% link {{ page.version.version }}/physical-cluster-replication-technical-overview.md %}) | ||
- [`CREATE VIRTUAL CLUSTER`]({% link {{ page.version.version }}/create-virtual-cluster.md %}) | ||
- [`ALTER VIRTUAL CLUSTER`]({% link {{ page.version.version }}/alter-virtual-cluster.md %}) | ||
- [`SHOW VIRTUAL CLUSTER`]({% link {{ page.version.version }}/show-virtual-cluster.md %}) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.