{"id":34519643,"url":"https://github.com/wentaojin/tidba","last_synced_at":"2025-12-26T10:01:32.132Z","repository":{"id":56013285,"uuid":"316191234","full_name":"wentaojin/tidba","owner":"wentaojin","description":"TiDB 数据库 DBA 常用工具集","archived":false,"fork":false,"pushed_at":"2025-12-25T14:47:11.000Z","size":148298,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-12-25T15:47:35.936Z","etag":null,"topics":["pd","region","tidb","tikv"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/wentaojin.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2020-11-26T10:08:20.000Z","updated_at":"2025-12-25T14:46:28.000Z","dependencies_parsed_at":"2025-12-24T05:04:38.700Z","dependency_job_id":null,"html_url":"https://github.com/wentaojin/tidba","commit_stats":null,"previous_names":[],"tags_count":21,"template":false,"template_full_name":null,"purl":"pkg:github/wentaojin/tidba","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wentaojin%2Ftidba","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wentaojin%2Ftidba/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wentaojin%2Ftidba/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wentaojin%2Ftidba/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/wentaojin","download_url":"https://codeload.github.com/wentaojin/tidba/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wentaojin%2Ftidba/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28052416,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-12-26T02:00:06.189Z","response_time":55,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["pd","region","tidb","tikv"],"created_at":"2025-12-24T04:36:56.734Z","updated_at":"2025-12-26T10:01:32.117Z","avatar_url":"https://github.com/wentaojin.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# TiDBA\n\nTiDB 数据库 DBA 运维工具集（交互式 / 非交互式 CLI），涵盖数据库自动化巡检、故障应急诊断、批量写入热点打散、参数变量对比、交互式 CLI SQL 语句执行（Select、Use、Explain、Show）等常见运维命令集。\n\n**NOTES:**\n1. 使用时必须跟 TiUP 中控机所在用户环境 Shell 保持一致，即沿用 TiUP 部分元数据信息\n2. 使用前必须执行 meta create 命令创建集群访问所需元数据，clusterName 需要与 TiUP 集群名保持一致\n   ```\n    {                                     \n    \"clusterName\": \"\",                   \n    \"dbUser\": \"\",                        \n    \"dbPassword\": \"\",                    \n    \"dbHost\": \"\",                        \n    \"dbPort\": 0,                         \n    \"dbCharset\": \"utf8mb4\",              \n    \"connParams\": \"\",                    \n    \"comment\": \"\"                        \n    }   \n   ```\n3. 交互式命令行 CLI 可通过 login / logout 命令进行集群切换操作（默认以交互式 CLI 模式运行）\n    ```\n    login 前 CLI 显示状态\n    tidba »»» login -c tidb-jwt00\n\n    login 后 CLI 显示状态\n    tidba[tidb-jwt00] »»» \n    ```\n---\n\n### Inspect 命令\n\ninspect 命令功能集：\n- inspect create 数据巡检参数配置创建\n- inspect query  数据库巡检参数配置查询\n- inspect update 数据库巡检参数配置修改\n- inspect delete 数据库巡检参数配置删除\n- inspect start 数据库巡检启动\n  \n```\n示例：\n非交互式命令\n$ ./tidba inspect {subCommand} -c {clusterName}\n\n交互式命令\ntidba[tidb-jwt00] »»» inspect {subCommand}\n```\n### Split 命令\n\n每种打散方式资源消耗以及场景可能情况不同，子命令分为基于实际数据表打散（key、range）、基于采样基础表打散(estimate、sampling)\n\nsplit 命令功能集：\n- split range 基于数据库表已有数据，自动生成数据以及索引打散语句\n- split key 基于数据库表已有 region key，自动生成数据以及索引打散语句\n- split estimate 采样指定数据库表某些字段 columns 所在数据，自动 ONLY 生成索引打散语句\n- split sampling 采样指定数据表某个索引名 index 所在字段数据，自动 ONLY 生成索引打散语句\n\n```\n示例：\n非交互式命令\n基于已有数据，根据 range 生成打散\n$ ./tidba split range -c {clusterName} --database {dbName} --tables {table1,table2} --daemon\n\n基于已有数据，根据 key 生成打散\n$ ./tidba split key -c {clusterName} --database {dbName} --tables {table1,table2} --daemon\n\n基于基础采样表某个或某几个字段数据，根据 distinct 生成打散\n$ ./tidba split estimate -c {clusterName} --database {dbName} --tables {tableName} --columns {column1,column2} --new-db {newDbName} --new-table {newTableName} --new-index {newIndexName} --estimate-size {estimateSize} --daemon\n\n基于基础采样表某个索引名 index 所在字段数据，根据 distinct 生成打散\n--resource server 数据量大的情况下,资源耗用主要在于机器资源且相对折中\n--resource database 数据量大的情况下,资源耗用主要位于数据库\n$ ./tidba split sampling  -c {clusterName} --database {dbName} --tables {tableName} --index {indexName} --new-db {newDbName} --new-table {newTableName} --new-index {newIndexName} --estimate-row {estimateRows} --resource server --daemon\n\n交互式命令(除 --daemon 以及 tidba 字样之外其他保持一致)\ntidba[tidb-jwt00] »»» split {subCommand} ...flags\n```\n### Region 命令\n\nregion 命令功能集：\n- region hotspot 查找集群数据库热点 region（支持数据库、store 实例、数据表、数据索引级别）\n- region replica 查找 down store 宕机不可用，集群内所有 down 副本数大于或等于正常副本数（多数派副本 DOWN）的 所有 region 信息\n- region leader  查找集群表数据 region leader 或者索引 region leader 分布\n- region query  查找集群指定 region id 信息，包含数据库、表、索引、decode key 值\n\n```\n示例：\n非交互式命令\n\n查找集群数据库热点 region 信息\n$ ./tidba region hotspot -c {clusterName} --database {dbName} [--stores {tikv1:servicePort1,tikv1:servicePort2}] [--tables {tableName}] [--indexes {indexName1,indexName2}] --type {write/read/all} --top 10\n\n查看数据以及索引 region leader 分布\n$ ./tidba region leader -c {clusterName} --database {dbName} [--stores {tikv1:servicePort1,tikv1:servicePort2}] --tables {tableName} [--indexes {indexName1,indexName2}]\n\n当 down tikv 宕机不可用，查找集群内所有 down-peer 副本数大于或等于正常副本数（多数派副本 DOWN）的所有 region 信息【忽略已被删除但未 GC 的 Region 信息】\n假设三副本集群，存在 kv 节点 1,2,28,30，若 down store 1,28 宕机不可用，查找指定 down kv 节点地址集群内所有 Down 副本数大于或等于正常副本数（多数派副本 DOWN）的所有 region 信息\n$ ./tidba region replica -c {clusterName} [--stores {tikv1:servicePort1,tikv2:servicePort2}] --region-type {all/data/index} --daemon\n\n-- 查找指定的 region 信息\n$ ./tidba region query -c {clusterName} --region-ids {region1,region2,region3} \n\n交互式命令(除 --daemon 以及 tidba 字样之外其他保持一致)\ntidba[tidb-jwt00] »»» split {subCommand} ...flags\n```\n### TOPSQL 命令\n\ntopsql 命令功能集（默认取近 30 min 且不显示 sql 文本）：\n- topsql elapsed 基于时间窗口内 sql 执行总耗时排序\n- topsql plans 基于时间窗口内产生多个执行计划的 sql 排序\n- topsql execs 基于时间窗口内 sql 执行次数排序，显示获取每类 sql 解析、编译、执行的平均时间\n- topsql cpu 基于时间窗口内 tidb / tikv 组件或者实例集群 cpu 维度排序\n- topsql diag 基于时间窗口 elapsed、plans、execs、cpu 维度，影响集群性能的 SQL TOP 5\n- topsql memory 基于时间窗口内 sql 执行内存使用排序以及影响 plan cache sql 执行次数排序\n\n```\n示例：\n非交互命令\n$ ./tidba topsql elapsed -c {clusterName} [--nearly 30 / --start {startTime} --end {endTime} ] --top 10 [--enable-sql] [--enable-history]\n\n$ ./tidba topsql plans -c {clusterName} [--nearly 30 / --start {startTime} --end {endTime} ] --top 10 [--enable-sql] [--enable-history]\n\n$ ./tidba topsql execs -c {clusterName} [--nearly 30 / --start {startTime} --end {endTime} ] --top 10 [--enable-sql] [--enable-history]\n\n$ ./tidba topsql cpu -c {clusterName} --component {tidb/tikv} [--instances {instAddr:statusPort}] [--nearly 30 / --start {startTime} --end {endTime} ] --top 10 [--enable-sql] [--enable-history]\n\n$ ./tidba topsql diag -c {clusterName} [--nearly 30 / --start {startTime} --end {endTime} ] [--top 10] [--enable-sql] [--enable-history]\n\n$ ./tidba topsql memory -c {clusterName} [--nearly 30 / --start {startTime} --end {endTime} ] [--top 10] [--enable-sql] [--enable-history]\n\n交互式命令(除 tidba 字样之外其他保持一致)\ntidba[tidb-jwt00] »»» topsql {subCommand} ...flags\n```\n\n### RUNAWAY 命令\n\nrunaway 基于 SQL Digest 自动进行集群级别 SQL 限流 / SQL 拦截 KILL，以避免同类 SQL 影响集群整体性能\n- runaway create 基于 sql digest 创建集群级别 SQL 限流\n- runaway query 查询集群当前 runaway watcher 信息\n- runaway delete 基于指定的 runaway watch id 删除 runaway watch\n\n```\n示例：\n非交互命令\n$ ./tidba runaway create -c {clusterName} [--resource-group {resourceGroupName}] [--ru-per-sec {ru}] [--priority {priority}] [--sql-digest {sqlDigest} / --sql-text {sqlText}] [--action {kill/switch}]\n\n$ ./tidba runaway query -c {clusterName}\n\n$ ./tidba runaway delete -c {clusterName} --watch-ids {watchID1,watchID2}\n\n\n交互式命令(除 tidba 字样之外其他保持一致)\ntidba[tidb-jwt00] »»» runaway {subCommand} ...flags\n```\n\n### KILL 命令\n\nkill 命令功能集合：\n- kill sql 基于 sql digest 间歇性或持续性 kill session\n- kill user 基于 username  间歇性或持续性 kill 对应 user 所有 session\n\n```\n示例：\n非交互命令\n$ ./tidba kill sql -c {clusterName} --sql-digests {sqlDigest1,sqlDigest2} [--duration 30] [--interval 500] [--concurrency 5]\n\n$ ./tidba kill user -c {clusterName} --users {username1,username2} [--duration 30] [--interval 500]  [--concurrency 5]\n\n交互式命令(除 tidba 字样之外其他保持一致)\ntidba[tidb-jwt00] »»» kill {subCommand} ...flags\n```\n### SQL 命令\n\nsql 命令功能集合:\n- sql display 基于 sql digest 显示 sql 执行详情，涵盖执行计划、执行信息等\n- sql bind 基于 sql digest 进行执行计划创建、删除、查询等\n  \n```\n示例：\n非交互命令\n$ ./tidba sql display -c {clusterName} --sql-digest {sqlDigest1} [--nearly 30 / --start {startTime} --end {endTime} ] [--enable-sql] [--enable-history]\n\n$ ./tidba sql bind create -c {clusterName} --sql-digest {sqlDigest1} [--schema {schemaName}] [--nearly 30 / --start {startTime} --end {endTime} ] [--enable-sql] [--enable-history]\n\n$ ./tidba sql bind query -c {clusterName}\n\n$ ./tidba sql bind delete -c {clusterName} --sql-digest {sqlDigest1} [--schema {schemaName}] [--nearly 30 / --start {startTime} --end {endTime} ] [--enable-sql] [--enable-history]\n\n交互式命令(除 tidba 字样之外其他保持一致)\ntidba[tidb-jwt00] »»» sql {subCommand} ...flags\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwentaojin%2Ftidba","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwentaojin%2Ftidba","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwentaojin%2Ftidba/lists"}