数据库|TiDB-Server API的高效应用指南

一、API介绍

1.Status

显示TiDB 连接数、版本和git_hash 信息

tidb-server_ip:status_port/status

{
"connections": 0,
"version": "5.7.25-TiDB-v6.1.1",
"git_hash": "5263a0abda61f102122735049fd0dfadc7b7f822"
}

2.Status

显示tidb所有的监控指标信息

tidb-server_ip:status_port/metrics

# HELP br_raw_backup_region_seconds Backup region latency distributions.
# TYPE br_raw_backup_region_seconds histogram
br_raw_backup_region_seconds_bucket{le="0.05"} 0
br_raw_backup_region_seconds_bucket{le="0.1"} 0
br_raw_backup_region_seconds_bucket{le="0.2"} 0
br_raw_backup_region_seconds_bucket{le="0.4"} 0
br_raw_backup_region_seconds_bucket{le="0.8"} 0
br_raw_backup_region_seconds_bucket{le="1.6"} 0
br_raw_backup_region_seconds_bucket{le="3.2"} 0
br_raw_backup_region_seconds_bucket{le="6.4"} 0

3.StatsDump

获取指定表的统计信息

直接访问会返回表不存在,原因是他的语法为/stats/dump/{db}/{table}

[schema:1146]Table '{db}.{table}'doesn't exist

e.g:tidb-server_ip:status_port/stats/dump/tpcc/item

{
"database_name": "tpcc",
"table_name": "item",
"columns": {
"i_data": {
"histogram": {
"ndv": 99072,
"buckets": [
{
"count": 390,
"lower_bound": "MDAxaHFvVW14YW9iUVAxSVRYWHlLMXc4TXJxwjA4RG1BaA==",
"upper_bound": "MEZWb0V6a2RiNmNuNFJoTmFZVkRqbHZ4b0hhUjN6WktuaFVFUkl6cHZlSUh1eGg=",
"repeats": 1,
"ndv": 0
},
......

4.StatsHistoryDump

获取指定表的历史统计信息

直接访问返回

[types:1292]Incorrect datetime value: '{snapshot}'

正确的语法为

/stats/dump/{db}/{table}/{yyyy-MM-dd HH:mm:ss}

/stats/dump/{db}/{table}/{yyyyMMddHHmmss}

e.g:tidb-server_ip:status_port/stats/dump/tpcc/item/2023-12-19 10:00:39

{
"database_name": "tpcc",
"table_name": "item",
"columns": {
"i_data": {
"histogram": {
"ndv": 99072,
"buckets": [
{
"count": 390,
"lower_bound": "MDAxaHFvVW14YW9iUVAxSVRYWHlLMXc4TXJxSjA4RG1BaA==",
"upper_bound": "MEZWb0V6a2RiNmNuNFJoTmFZVkRqbHZ4b0hhUjN6WktuaFVFUkl6cHZlSUh1eGg=",
"repeats": 1,
"ndv": 0
},
{
"count": 781,
"lower_bound": "MEZmRTV5VDdaZkNZMktTOTFCZ3FKTmhzZFdOTlZHNjhw",
"upper_bound": "MFVaTnc4UHdPOWlFMk8zbkdHZUdUbmZxcVNWVldqdFl5VE1lVmpXN2FWeG4=",
"repeats": 1,
"ndv": 0
},
......

5.PlanReplayerDump

保存和恢复集群现场信息

PLAN REPLAYER DUMP EXPLAIN [ANALYZE] sql-statement;

TiDB 根据 sql-statement 整理出以下集群现场信息:

TiDB 版本信息

TiDB 配置信息

TiDB Session 系统变量

TiDB 执行计划绑定信息(SQL Binding)

sql-statement 中所包含的表结构

sql-statement 中所包含表的统计信息

EXPLAIN [ANALYZE] sql-statement 的结果

PLAN REPLAYER 不会导出表中数据

tidb_last_plan_replayer_token 这个会话变量可以获取上一次 PLAN REPLAYER dump 执行的结果。(v6.5 以上版本有此变量)

MySQL [test]> plan replayer dump explain select * fromt1;
+-----------------------------------------------------------+
| File_token |
+-----------------------------------------------------------+
| replayer_xyUNbajB-Kx_rmD_Norcnw==_1702952402658503693.zip |
+-----------------------------------------------------------+
1row inset(0.06sec)

MySQL [test]> SELECT @@tidb_last_plan_replayer_token;
+-----------------------------------------------------------+
| @@tidb_last_plan_replayer_token |
+-----------------------------------------------------------+
| replayer_xyUNbajB-Kx_rmD_Norcnw==_1702952402658503693.zip |
+-----------------------------------------------------------+
1row inset(0.00sec)

ZIP 文件最多会在 TiDB 集群中保存一个小时,超时后 TiDB 会将其删除。

plan replayer dump explain 'tidbsqls.txt';

多条 SQL 语句可以写在文件中以 ; 进行分隔。

通过http下载文件

http://${tidb-server-ip}:${tidb-server-status-port}/plan_replayer/dump/${file_token}

将导出的文件导入的另一个集群,导入完毕后,该 TiDB 集群就载入了所需要的表结构、统计信息等其他影响构造 Plan 所需要的信息。

PLAN REPLAYER LOAD 'plan_replayer.zip';

6.Settings

tidb-server 的所有配置信息

tidb-server_ip:status_port/settings

7.BinlogRecover

恢复 Pump 后恢复 binlog 写入。

返回值:

超时,返回状态码:400,消息:timeout

如果正常返回,状态码:200

默认情况下,API 将在等待所有跳过的二进制日志事务提交后返回。如果此值大于 0,则表示需要等到它们提交完毕。

消息示例:false表示当前binlog不处于跳过状态,否则为跳过状态:表示当前处于跳过状态的事务数。

{
"Skipped": false,
"SkippedCommitterCounter": 0
}

8.Schema

获取集群所有databases的详细信息

tidb-server_ip:status_port/schema

[
{
"id": 1,
"db_name": {
"O": "test",
"L": "test"
},
"charset": "utf8mb4",
"collate": "utf8mb4_bin",
"state": 5,
"policy_ref_info": null
},
{
"id": 3,
"db_name": {
"O": "mysql",
"L": "mysql"
},
"charset": "utf8mb4",
"collate": "utf8mb4_bin",
"state": 5,
"policy_ref_info": null
},
......

tidb-server_ip:status_port/schema/{db}

查看指定database的详细信息,如该db下所有的table详细信息。

[
{
"id": 147,
"name": {
"O": "t2",
"L": "t2"
},
"charset": "utf8mb4",
"collate": "utf8mb4_bin",
"cols": [
{
"id": 1,
"name": {
"O": "id",
"L": "id"
},
"offset": 0,
"origin_default": null,
"origin_default_bit": null,
"default": null,
"default_bit": null,
"default_is_expr": false,
"generated_expr_string": "",
"generated_stored": false,
"dependences": null,
"type": {
"Tp": 3,
"Flag": 4099,
"Flen": 11,
"Decimal": 0,
"Charset": "binary",
"Collate": "binary",
"Elems": null,
"ElemsIsBinaryLit": null,
"Array": false
},
"state": 5,
"comment": "",
"hidden": false,
"change_state_info": null,
"version": 2
},
......

通过table_name 来获取table的详细信息

tidb-server_ip:status_port/schema/{db}/{table}

可以通过 tableID 获取 schema 信息(tableID 是 Table 在 TiDB 中的唯一标识符)

tidb-server_ip:status_port/schema?table_id={tableID}

{
"id": 147,
"name": {
"O": "t2",
"L": "t2"
},
"charset": "utf8mb4",
"collate": "utf8mb4_bin",
"cols": [
{
"id": 1,
"name": {
"O": "id",
"L": "id"
},

......

通过 tableID 获取db_info、table_info和tidb info schema version

tidb-server_ip:status_port/db-table/{tableID}

与上面的获取table的详细信息相比多了db_info和schema version信息。

{
"db_info": {
"id": 1,
"db_name": {
"O": "test",
"L": "test"
},
"charset": "utf8mb4",
"collate": "utf8mb4_bin",
"state": 5,
"policy_ref_info": null
},
......
......
"schema_version": 119
}

9.Schema Storage

获取集群所有table的信息

tidb-server_ip:status_port/schema_storage

[
{
"table_schema": "INFORMATION_SCHEMA",
"table_name": "CLIENT_ERRORS_SUMMARY_GLOBAL",
"table_rows": 0,
"avg_row_length": 0,
"data_length": 0,
"max_data_length": 0,
"index_length": 0,
"data_free": 0
},
......

也可以指定获取指定database或者table的信息

获取db下所有table的信息

tidb-server_ip:status_port/schema_storage/{db}

获取指定table的信息

tidb-server_ip:status_port/schema_storage/{db}/{table}

{ 
"table_schema": "test",
"table_name": "t1",
"table_rows": 4,
"avg_row_length": 8,
"data_length": 32,
"max_data_length": 0,
"index_length": 0,
"data_free": 0
}

10.DDL_History

获取所有 TiDB DDL 历史记录

tidb-server_ip:status_port/ddl/history

[
{
"id": 2,
"type": 1,
"schema_id": 1,
"table_id": 0,
"schema_name": "test",
"table_name": "",
"state": 6,
"warning": null,
"err": null,
"err_count": 0,
"row_count": 0,
"raw_args": null,
"schema_state": 5,
"snapshot_ver": 0,
"real_start_ts": 0,
"start_ts": 444336503938613250,
"dependency_id": 0,
"query": "CREATE DATABASE IF NOT EXISTS test",
"binlog": {
"SchemaVersion": 1,
"DBInfo": {
"id": 1,
"db_name": {
"O": "test",
"L": "test"
},
"charset": "utf8mb4",
"collate": "utf8mb4_bin",
"state": 5,
"policy_ref_info": null
},
"TableInfo": null,
"FinishedTS": 444336503965089800,
"MultipleTableInfos": null
},
"version": 1,
"reorg_meta": null,
"multi_schema_info": null,
"priority": 0,
"seq_num": 0,
"charset": "",
"collate": "",
"admin_operator": 0
},
......

11.DDL_Owner_Resign

辞去 ddl owner 的职务,让 tidb 开始新的 ddl owner 选举

curl -X POST http://{TiDBIP}:10080/ddl/owner/resign

注意:如果你请求的 TiDB 不是 ddl owner,则响应为This node is not a ddl owner, can't be resigned.

http://12.Info

tidb-server_ip:status_port/info

获取tidb-server的相关信息

{
"is_owner": true,
"max_procs": 4,
"gogc": 500,
"version": "5.7.25-TiDB-v7.1.0",
"git_hash": "635a4362235e8a3c0043542e62953e3c7bb2756",
"ddl_id": "39844a19-b9d7-4f39-b21a-9beb5ffec18",
"ip": "10.0.0.1",
"listening_port": 5000,
"status_port": 20080,
"lease": "45s",
"binlog_status": "On",
"start_timestamp": 1695089378,
"labels": {},
"server_id": 937142
}

13.InfoALL

tidb-server_ip:status_port/info/all

获取tidb集群所有tidb-server的信息

{
"servers_num": 1,
"owner_id": "9112417d-2609-404a-8a8b-c10b5cebfe2b",
"is_all_server_version_consistent": true,
"all_servers_info": {
"9112417d-2609-404a-8a8b-c10b5cebfe2b": {
"version": "5.7.25-TiDB-v6.5.2",
"git_hash": "29116c0256c52b224da2b34d712c1063d171c0ad",
"ddl_id": "9112417d-2609-404a-8a8b-c10b5cebfe2b",
"ip": "10.3.65.136",
"listening_port": 4900,
"status_port": 19080,
"lease": "45s",
"binlog_status": "On",
"start_timestamp": 1703554804,
"labels": {},
"server_id": 4042427
}
}
}

14.RegionsMeta

tidb-server_ip:status_port/regions/meta

获取所有region的元数据信息

[
{
"region_id": 10,
"leader": {
"id": 128,
"store_id": 2
},
"peers": [
{
"id": 11,
"store_id": 1
},
{
"id": 128,
"store_id": 2
},
{
"id": 178,
"store_id": 4
}
],
"region_epoch": {
"conf_ver": 5,
"version": 156
}
}
]

15.RegionHot

tidb-server_ip:status_port/regions/hot

获取热点region的表/索引信息

{
"read": [
{
"region_id": 180,
"region_metric": {
"flow_bytes": 38560,
"max_hot_degree": 2564,
"region_count": 0
},
"db_name": "mysql",
"table_name": "tidb_ddl_job",
"table_id": 281474976710654,
"index_name": "",
"index_id": 0
}
],
"write": []
}

16.Trace Viewer

tidb-server_ip:status_port/web/trace

以图形界面的方式显示执行sql的详细信息,参考 TRACE | PingCAP 文档中心 使用。

这个我实验无法显示出图形信息 https://asktug.com/t/topic/1014681,尝试了6.1、6.5、7.1环境都无法显示出来。

17.Debug

tidb-server_ip:status_port/debug/pprof/

tidb debug信息,例如heap、goroutine、trace等常用信息。

Types of profiles available:
Count Profile
12038allocs
0block
0cmdline
249goroutine
12038heap
85mutex
0profile
12threadcreate
0trace
full goroutine stack dump
Profile Descriptions:

allocs:A sampling of allpast memory allocations
block: Stack traces that led toblocking onsynchronization primitives
cmdline: The commandlineinvocation of the current program
goroutine: Stack traces of allcurrent goroutines
heap: A sampling of memory allocations of live objects. You can specify the gc GET parameter torun GC before taking the heap sample.
mutex: Stack traces of holders of contended mutexes
profile: CPU profile. You can specify the duration in the seconds GET parameter. After you getthe profilefile, use the gotool pprof commandtoinvestigate the profile.
threadcreate: Stack traces that led tothe creation of newOS threads
trace: A trace of execution of the current program. You can specify the duration in the seconds GET parameter. After you getthe trace file, use the gotool trace commandtoinvestigate the trace.

二、结尾

以上API在一些运维场景中仍然相当实用。通过在运维中灵活运用,可以使运维工作更加便捷,增强系统管理的灵活性。尤其是在运维开发的场景中熟练使用,有助于高效地进行开发工作。

作者:王思强| 数据库运维工程师

版权声明:本文由神州数码云基地团队整理撰写,若转载请注明出处。

公众号搜索神州数码云基地,了解更多技术干货!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mfbz.cn/a/584198.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

Ollama +Docker+OpenWebUI

1 Ollama 1.1 下载Ollama https://ollama.com/download 1.2 运行llama3 $ ollama run llama3 pulling manifest pulling 00e1317cbf74... 100% ▕███████████████████████████████████████████████████████████…

SD-WAN的核心竞争力有哪些?

随着企业网络需求的飞速增长,SD-WAN作为一种新兴网络连接方式,正迅速受到企业的青睐。SD-WAN不仅仅是连接手段,更是网络优化、安全防护和综合管理的集大成技术。在这篇文章中,我们将简要探讨SD-WAN的核心竞争力,以帮助…

Flink checkpoint 源码分析

序言 最近因为工作需要在阅读flink checkpoint处理机制,学习的过程中记录下来,并分享给大家。也算是学习并记录。 目前公司使用的flink版本为1.11。因此以下的分析都是基于1.11版本来的。 在分享前可以简单对flink checkpoint机制做一个大致的了解。 …

mysql-sql-练习题-4-标记

标记 连续登录2-7天用户建表排名找规律 最大连胜次数建表只输出连胜结果输出所有连续结果 连续登录2-7天用户 建表 create table continuous_login(user_id1 integer comment 用户id,date_login date comment 登陆日期 ) comment 用户登录表;insert into continuous_login val…

这是一个简单网站,后续还会更新

1、首页效果图 代码 <!DOCTYPE html> <html> <head> <meta charset"utf-8" /> <title>爱德照明网站首页</title> <style> /*外部样式*/ charset "utf-8"…

【计算机毕业设计】基于SSM++jsp的社区管理与服务系统【源码+lw+部署文档+讲解】

目录 摘 要 Abstract 第一章 绪论 第二章 系统关键技术 第三章 系统分析 3.1.1技术可行性 3.1.2经济可行性 3.1.3运行可行性 3.1.4法律可行性 3.4.1注册流程 3.4.2登录流程 3.4.3活动报名流程 第四章 系统设计 4.3.1登录模块顺序图 4.3.2添加信息模块顺序图 4.4.1 数据库E-…

使用STM32CubeMX对STM32F4进行串口配置

目录 1. 配置1.1 Pin脚1.2 RCC开启外部晶振1.3 时钟1.4 串口配置 2. 代码2.1 默认生成代码2.1 开启串口中断函数2.3 接收中断2.4 接收回调函数2.5 增加Printf 的使用 1. 配置 1.1 Pin脚 1.2 RCC开启外部晶振 1.3 时钟 外部使用8MHz晶振 开启内部16MHz晶振 使用锁相环 开启最高…

动手写一个简单的Android 表格控件支持固定列

Android 动手写一个简洁版表格控件 简介 源码已放到 gitee 作为在测绘地理信息行业中穿梭的打工人&#xff0c;遇到各种数据采集需求&#xff0c;既然有数据采集需求&#xff0c;那当然少不了数据展示功能&#xff0c;最常见的如表格方式展示。 当然&#xff0c;类似表格这些…

【消息队列】MQ介绍

MQ MQ&#xff08;MessageQueue&#xff09;&#xff0c;中文是消息队列&#xff0c;就是存放消息的队列&#xff0c;也是下面提到的事件驱动架构中的Broker 同步调用的优点&#xff1a; 时效性强&#xff0c;可以立即得到结果 同步调用的问题&#xff1a; 耦合度高性能和吞吐…

汽车信息安全入门总结(2)

目录 1.引入 2.汽车信息安全技术 3.密码学基础知识 4.小结 1.引入 上篇汽车信息安全入门总结(1)-CSDN博客主要讲述了汽车信息安全应该关注的点&#xff0c;以及相关法规和标准&#xff0c;限于篇幅&#xff0c;继续聊信息安全相关技术以及需要掌握的密码学基础知识。 2.汽…

Costas-Barker序列模糊函数仿真

文章目录 前言一、Costas 序列二、Barker 码三、Costas-Barker 序列模糊函数仿真1、MATLAB 核心代码2、仿真结果①、Costas-Barker 模糊函数图②、Costas-Barker 距离模糊函数图③、Costas-Barker 速度模糊函数图 四、资源自取 前言 Costas 码是一种用于载波同步的频率调制序列…

基于SpringBoot+Vue高校竞赛管理系统的设计与实现

项目介绍&#xff1a; 高校竞赛管理系统管理系统按照操作主体分为管理员和用户。管理员的功能包括字典管理、论坛管理、竞赛公告管理、获奖管理、老师管理、评审管理、评审分配管理、评审打分管理、赛事管理、赛事提交管理、赛事报名管理、用户管理、专家管理、管理员管理。用…

万兴PDF专家 PDFelement Pro v10.3.8 破姐版!

&#x1f9d1;‍&#x1f4bb;万兴PDF专家 PDFelement Pro v10.3.8 破姐版 (https://docs.qq.com/sheet/DRVVxTHJ3RXJFVHVr)

FreeRTOS软件定时器

说明本文章基于百问网RTOS教程文档 1.硬件定时器 什么是硬件定时器&#xff0c;由硬件电路构成的定时器。在学习STM32时我们都会学到定时器&#xff0c;这个就是硬件定时器。硬件定时器不单单可以定时&#xff0c;它还可以进行PWM输出等等。硬件定时器每隔一段固定的时间会进…

近几年视频取证、视频篡改检测技术发展现状及挑战

前言 本文主要搜集了视频取证各个子领域近几年的高影响因子/引用数的文章及其主要思想和做法&#xff0c;旨在分析目前视频篡改检测的发展现状与热点领域&#xff0c;文章中也融合了自己的一点看法和展望&#xff0c;欢迎感兴趣的同学和我多多沟通。 本文无论是文献搜集还是方…

基于Spring Boot的外卖点餐系统设计与实现

基于Spring Boot的外卖点餐系统设计与实现 开发语言&#xff1a;Java框架&#xff1a;springbootJDK版本&#xff1a;JDK1.8数据库工具&#xff1a;Navicat11开发软件&#xff1a;eclipse/myeclipse/idea 系统部分展示 网站首页界面图&#xff0c;通过进入网站可以查看首页、…

并查集应用-连通块中点的数量and食物链

文章目录 连通块中点的数量思路代码javaC 代码 食物链带扩展域的并查集代码带边权的并查集数组d的真正含义以及find()函数调用过程核心代码注意事项&#xff0c;即明白 d[i] 的含义 代码C Java 连通块中点的数量 给定一个包含 n 个点&#xff08;编号为 1∼n &#xff09;的无向…

Leetcode—860. 柠檬水找零【简单】

2024每日刷题&#xff08;122&#xff09; Leetcode—860. 柠檬水找零 实现代码 class Solution { public:bool lemonadeChange(vector<int>& bills) {int count5 0;int count10 0;for(int i 0; i < bills.size(); i) {if(bills[i] 5) {count5;} else if(bi…

【自然语言处理】Word2VecTranE的实现

作业一 Word2Vec&TranE的实现 1 任务目标 1.1 案例简介 Word2Vec是词嵌入的经典模型&#xff0c;它通过词之间的上下文信息来建模词的相似度。TransE是知识表示学习领域的经典模型&#xff0c;它借鉴了Word2Vec的思路&#xff0c;用“头实体关系尾实体”这一简单的训练目…

【matplot】【matlab】绘制简洁美观二维坐标系的一个例子

觉得下图不错美观大方&#xff0c;现仿制下图&#xff1a; import numpy as np import matplotlib.pyplot as pltdef sigmoid(x):return 1 / (1 np.exp(-x))def sigmoid_derivative(x):return sigmoid(x) * (1 - sigmoid(x))# 设置中文字体 plt.rcParams[font.family] [Tim…
最新文章