Check the Number of Replicas for Each Region in TiDB

Note:
This topic has been translated from a Chinese forum by GPT and might contain errors.

Original topic: 查看tidb每个 region有几个副本

| username: TiDBer_FMWXa7ja

[TiDB Usage Environment] Production Environment / Testing / PoC
[TiDB Version]
[Reproduction Path] I deployed three KV storage nodes. To save disk space in the testing environment, I set max-replicas to 1.
[Encountered Problem: Problem Phenomenon and Impact] I want to check how many replicas each region actually has to verify if my setting of max-replicas to 1 has taken effect.
[Resource Configuration]
[Attachment: Screenshot/Log/Monitoring]

| username: Kongdom | Original post link

Setting max-replicas to 1 means there is only one replica. For example, my test cluster is set to 1.

| username: tidb菜鸟一只 | Original post link

To check the number of replicas for each Region in TiDB, you can use TiDB’s official tool, TiDB Lightning, which provides the check_region_replica.py script to check the number of replicas for each Region.

The specific steps are as follows:

  1. Run the following command in the command line to install TiDB Lightning:
curl https://raw.githubusercontent.com/pingcap/tidb-lightning/master/scripts/run_lightning.sh | bash -s -- --tidb-server <TiDB address> --binlog <binlog address> --deploy-mode=standalone --no-start
  1. After installation, switch to the bin directory of TiDB Lightning:
cd lightning-bin
  1. Run the check_region_replica.py script:
./check_region_replica.py --pd "http://<PD address>"

Here, <PD address> refers to the address of the PD Server, which needs to be replaced with the actual address.

After executing the above commands, the script will output detailed information such as the ID of each Region, the number of replicas, and the TiKV nodes where the replicas are located.

| username: TiDBer_FMWXa7ja | Original post link

Okay, thank you.

| username: 考试没答案 | Original post link

tiup ctl:v6.5.0 tidb table -d test -t history_wti_alarm_utc regions --host 192.168.2.21

| username: TiDBer_FMWXa7ja | Original post link

Thank you.

| username: 裤衩儿飞上天 | Original post link

For example, all Regions with a replica count not equal to 3:

region --jq=".regions[] | {id: .id, peer_stores: [.peers[].store_id] | select(length != 3)}"
| username: system | Original post link

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.