diff --git a/.circleci/config.yml b/.circleci/config.yml
deleted file mode 100644
index 6f98693addd5cba9a40f6ab9335054951a78b2ee..0000000000000000000000000000000000000000
--- a/.circleci/config.yml
+++ /dev/null
@@ -1,13 +0,0 @@
-# Use the latest 2.1 version of CircleCI pipeline process engine. See: https://circleci.com/docs/2.0/configuration-reference
-version: 2.1
-# Use a package of configuration called an orb.
-orbs:
- # Declare a dependency on the welcome-orb
- welcome: circleci/welcome-orb@0.4.1
-# Orchestrate or schedule a set of jobs
-workflows:
- # Name the workflow "welcome"
- welcome:
- # Run the welcome/run job in its own container
- jobs:
- - welcome/run
diff --git a/.drone.yml b/.drone.yml
deleted file mode 100644
index f4ab3c92519ed218820e07c7fa8ed645f93d94d4..0000000000000000000000000000000000000000
--- a/.drone.yml
+++ /dev/null
@@ -1,264 +0,0 @@
----
-kind: pipeline
-name: test_arm64_bionic
-
-platform:
- os: linux
- arch: arm64
-steps:
-- name: build
- image: arm64v8/ubuntu:bionic
- commands:
- - apt-get update
- - apt-get install -y cmake git build-essential wget
- - wget https://dl.google.com/go/go1.16.9.linux-arm64.tar.gz
- - tar -C /usr/local -xzf go1.16.9.linux-arm64.tar.gz
- - export PATH=$PATH:/usr/local/go/bin
- - git submodule update --init --recursive
- - mkdir debug
- - cd debug
- - cmake .. -DCPUTYPE=aarch64 > /dev/null
- - make -j4
- trigger:
- event:
- - pull_request
- when:
- branch:
- - develop
- - master
- - 2.0
----
-kind: pipeline
-name: test_arm64_focal
-
-platform:
- os: linux
- arch: arm64
-
-steps:
-- name: build
- image: arm64v8/ubuntu:focal
- commands:
- - echo 'debconf debconf/frontend select Noninteractive' | debconf-set-selections
- - apt-get update
- - apt-get install -y -qq git cmake build-essential wget
- - wget https://dl.google.com/go/go1.16.9.linux-arm64.tar.gz
- - tar -C /usr/local -xzf go1.16.9.linux-arm64.tar.gz
- - export PATH=$PATH:/usr/local/go/bin
- - git submodule update --init --recursive
- - mkdir debug
- - cd debug
- - cmake .. -DCPUTYPE=aarch64 > /dev/null
- - make -j4
- trigger:
- event:
- - pull_request
- when:
- branch:
- - develop
- - master
- - 2.0
----
-kind: pipeline
-name: test_arm64_centos7
-
-platform:
- os: linux
- arch: arm64
-
-steps:
-- name: build
- image: arm64v8/centos:7
- commands:
- - yum install -y epel-release
- - yum install -y gcc gcc-c++ make cmake3 wget git
- - wget https://dl.google.com/go/go1.16.9.linux-arm64.tar.gz
- - tar -C /usr/local -xzf go1.16.9.linux-arm64.tar.gz
- - export PATH=$PATH:/usr/local/go/bin
- - ln -s /usr/bin/cmake3 /usr/bin/cmake
- - go version
- - git submodule update --init --recursive
- - mkdir debug
- - cd debug
- - cmake3 .. -DCPUTYPE=aarch64 > /dev/null
- - make -j4
- trigger:
- event:
- - pull_request
- when:
- branch:
- - develop
- - master
- - 2.0
----
-kind: pipeline
-name: test_arm64_centos8
-
-platform:
- os: linux
- arch: arm64
-
-steps:
-- name: build
- image: arm64v8/centos:8
- commands:
- - dnf install -y gcc gcc-c++ make cmake epel-release git libarchive golang
- - git submodule update --init --recursive
- - mkdir debug
- - cd debug
- - cmake .. -DCPUTYPE=aarch64 > /dev/null
- - make -j4
- trigger:
- event:
- - pull_request
- when:
- branch:
- - develop
- - master
- - 2.0
----
-kind: pipeline
-name: test_arm_bionic
-
-platform:
- os: linux
- arch: arm
-
-steps:
-- name: build
- image: arm32v7/ubuntu:bionic
- commands:
- - apt-get update
- - apt-get install -y cmake build-essential golang-go git
- - git submodule update --init --recursive
- - mkdir debug
- - cd debug
- - cmake .. -DCPUTYPE=aarch32 > /dev/null
- - make -j4
- trigger:
- event:
- - pull_request
- when:
- branch:
- - develop
- - master
- - 2.0
----
-kind: pipeline
-name: build_trusty
-
-platform:
- os: linux
- arch: amd64
-
-steps:
-- name: build
- image: ubuntu:trusty
- commands:
- - apt-get update
- - apt-get install -y gcc cmake3 build-essential git binutils-2.26 wget
- - wget https://dl.google.com/go/go1.16.9.linux-amd64.tar.gz
- - tar -C /usr/local -xzf go1.16.9.linux-amd64.tar.gz
- - export PATH=$PATH:/usr/local/go/bin
- - git submodule update --init --recursive
- - mkdir debug
- - cd debug
- - cmake ..
- - make -j4
- trigger:
- event:
- - pull_request
- when:
- branch:
- - develop
- - master
- - 2.0
----
-kind: pipeline
-name: build_xenial
-
-platform:
- os: linux
- arch: amd64
-
-steps:
-- name: build
- image: ubuntu:xenial
- commands:
- - apt-get update
- - apt-get install -y gcc cmake build-essential git wget
- - wget https://dl.google.com/go/go1.16.9.linux-amd64.tar.gz
- - tar -C /usr/local -xzf go1.16.9.linux-amd64.tar.gz
- - export PATH=$PATH:/usr/local/go/bin
- - git submodule update --init --recursive
- - mkdir debug
- - cd debug
- - cmake ..
- - make -j4
- trigger:
- event:
- - pull_request
- when:
- branch:
- - develop
- - master
- - 2.0
----
-kind: pipeline
-name: build_bionic
-platform:
- os: linux
- arch: amd64
-
-steps:
-- name: build
- image: ubuntu:bionic
- commands:
- - apt-get update
- - apt-get install -y gcc cmake build-essential git wget
- - wget https://dl.google.com/go/go1.16.9.linux-amd64.tar.gz
- - tar -C /usr/local -xzf go1.16.9.linux-amd64.tar.gz
- - export PATH=$PATH:/usr/local/go/bin
- - git submodule update --init --recursive
- - mkdir debug
- - cd debug
- - cmake ..
- - make -j4
- trigger:
- event:
- - pull_request
- when:
- branch:
- - develop
- - master
- - 2.0
----
-kind: pipeline
-name: build_centos7
-platform:
- os: linux
- arch: amd64
-
-steps:
-- name: build
- image: ansible/centos7-ansible
- commands:
- - yum install -y epel-release
- - yum install -y gcc gcc-c++ make cmake3 wget git
- - wget https://dl.google.com/go/go1.16.9.linux-amd64.tar.gz
- - tar -C /usr/local -xzf go1.16.9.linux-amd64.tar.gz
- - export PATH=$PATH:/usr/local/go/bin
- - ln -s /usr/bin/cmake3 /usr/bin/cmake
- - git submodule update --init --recursive
- - mkdir debug
- - cd debug
- - cmake3 ..
- - make -j4
- trigger:
- event:
- - pull_request
- when:
- branch:
- - develop
- - master
- - 2.0
\ No newline at end of file
diff --git a/.gitmodules b/.gitmodules
index 9c09b908ad94723e60c3945681c4068e786481d7..7a63174d3f6ae59abd733dce60189b462b8c76f8 100644
--- a/.gitmodules
+++ b/.gitmodules
@@ -20,3 +20,9 @@
[submodule "examples/rust"]
path = examples/rust
url = https://github.com/songtianyi/tdengine-rust-bindings.git
+[submodule "src/connector/php-tdengine"]
+ path = src/connector/php-tdengine
+ url = https://github.com/Yurunsoft/php-tdengine.git
+[submodule "src/connector/php-tdengine-restful-connector"]
+ path = src/connector/php-tdengine-restful-connector
+ url = https://github.com/Yurunsoft/tdengine-restful-connector.git
diff --git a/Jenkinsfile b/Jenkinsfile
index 15640f81393f5544cf16d75fa72da062dbbda8b0..0f0a09f2be366eab9488e281f7d65ce9d7592e24 100644
--- a/Jenkinsfile
+++ b/Jenkinsfile
@@ -116,7 +116,7 @@ def pre_test(){
make > /dev/null
make install > /dev/null
cd ${WKC}/tests
- pip3 install ${WKC}/src/connector/python/
+ pip3 install taospy
'''
return 1
}
diff --git a/Jenkinsfile2 b/Jenkinsfile2
index d93ed9df5b70ce791c444005316bc279ef82666f..8cffa8e06d0643f0a0654ea99f6d89fa6994ee5b 100644
--- a/Jenkinsfile2
+++ b/Jenkinsfile2
@@ -21,21 +21,25 @@ def sync_source() {
if (env.CHANGE_TARGET == 'master') {
sh '''
cd ${WKC}
+ git clean -fxd
git checkout master
'''
} else if (env.CHANGE_TARGET == '2.0') {
sh '''
cd ${WKC}
+ git clean -fxd
git checkout 2.0
'''
} else if (env.CHANGE_TARGET == '2.4') {
sh '''
cd ${WKC}
+ git clean -fxd
git checkout 2.4
'''
} else {
sh '''
cd ${WKC}
+ git clean -fxd
git checkout develop
'''
}
@@ -83,6 +87,16 @@ def sync_source() {
cd ${WKC}
git fetch origin +refs/pull/${CHANGE_ID}/merge
git checkout -qf FETCH_HEAD
+
+ if [ ! -d src/connector/python/.github ]; then
+ rm -rf src/connector/python/* || :
+ rm -rf src/connector/python/.* || :
+ git clone --depth 1 https://github.com/taosdata/taos-connector-python src/connector/python || echo "failed to clone python connector"
+ else
+ cd src/connector/python || echo "src/connector/python not exist"
+ git pull || :
+ cd ${WKC}
+ fi
'''
} else if (env.CHANGE_URL =~ /\/TDinternal\//) {
sh '''
@@ -90,6 +104,16 @@ def sync_source() {
cd ${WK}
git fetch origin +refs/pull/${CHANGE_ID}/merge
git checkout -qf FETCH_HEAD
+
+ if [ ! -d community/src/connector/python/.github ]; then
+ rm -rf community/src/connector/python/* || :
+ rm -rf community/src/connector/python/.* || :
+ git clone --depth 1 https://github.com/taosdata/taos-connector-python community/src/connector/python || echo "failed to clone python connector"
+ else
+ cd community/src/connector/python || echo "community/src/connector/python not exist"
+ git pull || :
+ cd ${WK}
+ fi
'''
} else {
sh '''
@@ -251,20 +275,6 @@ pipeline {
}
}
parallel {
- stage ('build worker08_arm32') {
- agent {label " worker08_arm32"}
- steps {
- timeout(time: 20, unit: 'MINUTES') {
- pre_test()
- script {
- sh '''
- echo "worker08_arm32 build done"
- date
- '''
- }
- }
- }
- }
stage ('build worker07_arm64') {
agent {label " worker07_arm64 "}
steps {
diff --git a/cmake/define.inc b/cmake/define.inc
index a15a0725ebcc04683cee3559e69cf667a060fc7d..9e3d4a0dfa05d1bdbc783da68d470c3a57f57d7b 100755
--- a/cmake/define.inc
+++ b/cmake/define.inc
@@ -287,9 +287,17 @@ IF (TD_LINUX)
SET(COMMON_FLAGS "${COMMON_FLAGS} -pipe -Wshadow")
ENDIF ()
+MESSAGE(STATUS "CMAKE_CXX_COMPILER_ID: " ${CMAKE_CXX_COMPILER_ID})
+IF ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
+ EXECUTE_PROCESS( COMMAND ${CMAKE_CXX_COMPILER} --version OUTPUT_VARIABLE clang_full_version_string )
+ string (REGEX REPLACE ".*clang version ([0-9]+\\.[0-9]+).*" "\\1" CLANG_VERSION_STRING ${clang_full_version_string})
+ IF (CLANG_VERSION_STRING GREATER_EQUAL 13.0)
+ SET(COMMON_FLAGS "${COMMON_FLAGS} -Wno-unused-but-set-variable")
+ ENDIF ()
+ENDIF ()
+
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/inc)
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/os/inc)
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/util/inc)
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/common/inc)
-MESSAGE(STATUS "CMAKE_CXX_COMPILER_ID: " ${CMAKE_CXX_COMPILER_ID})
diff --git a/cmake/input.inc b/cmake/input.inc
index 9d411e382b4a9b07de238cc1caaa246dcbda57bc..6eb7e44e0af007240c803dd5cf50c69de47f4fc8 100755
--- a/cmake/input.inc
+++ b/cmake/input.inc
@@ -53,11 +53,6 @@ IF (${MEM_CHECK} MATCHES "true")
MESSAGE(STATUS "build with memory check")
ENDIF ()
-IF (${MQTT} MATCHES "false")
- SET(TD_MQTT FALSE)
- MESSAGE(STATUS "build without mqtt module")
-ENDIF ()
-
IF (${RANDOM_FILE_FAIL} MATCHES "true")
SET(TD_RANDOM_FILE_FAIL TRUE)
MESSAGE(STATUS "build with random-file-fail enabled")
@@ -104,4 +99,4 @@ ELSE()
MESSAGE(STATUS "build with TSZ enabled")
ADD_DEFINITIONS(-DTD_TSZ)
set(VAR_TSZ "TSZ" CACHE INTERNAL "global variant tsz" )
-ENDIF()
\ No newline at end of file
+ENDIF()
diff --git a/cmake/install.inc b/cmake/install.inc
index 8124929746f42462fd29865814cc2d661a3019f9..6da298ef3e039fc1274acc4e43d7c7ae63356876 100755
--- a/cmake/install.inc
+++ b/cmake/install.inc
@@ -20,7 +20,7 @@ ELSEIF (TD_WINDOWS)
INSTALL(FILES ${EXECUTABLE_OUTPUT_PATH}/taos.exe DESTINATION .)
IF (TD_MVN_INSTALLED)
- INSTALL(FILES ${LIBRARY_OUTPUT_PATH}/taos-jdbcdriver-2.0.37-dist.jar DESTINATION connector/jdbc)
+ INSTALL(FILES ${LIBRARY_OUTPUT_PATH}/taos-jdbcdriver-2.0.38-dist.jar DESTINATION connector/jdbc)
ENDIF ()
ELSEIF (TD_DARWIN)
SET(TD_MAKE_INSTALL_SH "${TD_COMMUNITY_DIR}/packaging/tools/make_install.sh")
diff --git a/docs-cn/01-intro/01-intro.md b/docs-cn/01-intro/01-intro.md
index d6b0968e47dd71bdfa648072b198641d74caa8b3..f1e70a1af72ff0c61cd5007cdd62205e369ffc58 100644
--- a/docs-cn/01-intro/01-intro.md
+++ b/docs-cn/01-intro/01-intro.md
@@ -1,10 +1,9 @@
---
sidebar_label: 产品简介
+title: 产品简介
toc_max_heading_level: 2
---
-# 产品简介
-
## TDengine 简介
TDengine 是一款高性能、分布式、支持 SQL 的时序数据库。而且除时序数据库功能外,它还提供缓存、数据订阅、流式计算等功能,最大程度减少研发和运维的复杂度,且核心代码,包括集群功能全部开源(开源协议,AGPL v3.0)。与其他时序数据数据库相比,TDengine 有以下特点:
@@ -25,15 +24,16 @@ TDengine 是一款高性能、分布式、支持 SQL 的时序数据库。而且
- **互动 Console**: 通过命令行 console,不用编程,执行 SQL 语句就能做即席查询、各种数据库的操作、管理以及集群的维护.
-采用 TDengine,可将典型的物联网、车联网、工业互联网大数据平台的总拥有成本大幅降低。但需要指出的是,因充分利用了物联网时序数据的特点,它无法用来处理网络爬虫、微博、微信、电商、ERP、CRM 等通用型数据。
+采用 TDengine,可将典型的物联网、车联网、工业互联网大数据平台的总拥有成本大幅降低。表现在几个方面,1:由于其超强性能,它能将系统需要的计算资源和存储资源大幅降低;2:因为采用SQL接口,能与众多第三放软件无缝集成,学习迁移成本大幅下降;3:因为其All In One的特性,系统复杂度降低,能降研发成本;4:因为运维维护简单,运营维护成本能大幅降低。
+在整个时序大数据平台中,TDengine在其中扮演的角色如下:

图 1. TDengine技术生态图
## TDengine 总体适用场景
-作为一个 IoT 大数据平台,TDengine 的典型适用场景是在 IoT 范畴,而且用户有一定的数据量。本文后续的介绍主要针对这个范畴里面的系统。范畴之外的系统,比如 CRM,ERP 等,不在本文讨论范围内。
+作为一个高性能、分布式、支持 SQL 的时序数据库,TDengine 的典型适用场景包括但不限于 IoT、工业互联网、车联网、IT运维、能源、金融证券等领域。需要指出的是,TDengine是针对时序数据场景设计的专用数据库和专用大数据处理工具,因充分利用了时序大数据的特点,它无法用来处理网络爬虫、微博、微信、电商、ERP、CRM 等通用型数据。本文对适用场景做更多详细的分析。
### 数据源特点和需求
diff --git a/docs-cn/02-concept/02-concept.md b/docs-cn/02-concept/02-concept.md
index ccaa1b51e0410c2a2e02513f5ce6e4a2c6e00325..b1638e838d9b2da35018b4d24640b98d5e476e47 100644
--- a/docs-cn/02-concept/02-concept.md
+++ b/docs-cn/02-concept/02-concept.md
@@ -1,24 +1,111 @@
-# 基本概念
+---
+title: 数据模型和基本概念
+---
## 物联网典型场景
-在典型的物联网、车联网、运维监测场景中,往往有多种不同类型的数据采集设备,采集一个到多个不同的物理量。而同一种采集设备类型,往往又有多个具体的采集设备分布在不同的地点。大数据处理系统就是要将各种采集的数据汇总,然后进行计算和分析。对于同一类设备,其采集的数据类似如下的表格:
-
-| Device ID | Time Stamp | Value 1 | Value 2 | Value 3 | Tag 1 | Tag 2 |
-| :-------: | :-----------: | :-----: | :-----: | :-----: | :---: | :---: |
-| D1001 | 1538548685000 | 10.3 | 219 | 0.31 | Red | Tesla |
-| D1002 | 1538548684000 | 10.2 | 220 | 0.23 | Blue | BMW |
-| D1003 | 1538548686500 | 11.5 | 221 | 0.35 | Black | Honda |
-| D1004 | 1538548685500 | 13.4 | 223 | 0.29 | Red | Volvo |
-| D1001 | 1538548695000 | 12.6 | 218 | 0.33 | Red | Tesla |
-| D1004 | 1538548696600 | 11.8 | 221 | 0.28 | Black | Honda |
-
-
-每一条记录都有设备 ID,时间戳,采集的物理量,还有与每个设备相关的静态标签。每个设备是受外界的触发,或按照设定的周期采集数据。采集的数据点是时序的,是一个数据流。
-
-**数据特征**
-
-除时序特征外,仔细研究发现,物联网、车联网、运维监测类数据还具有很多其他明显的特征。
+在典型的物联网、车联网、运维监测场景中,往往有多种不同类型的数据采集设备或采集点,采集一个到多个不同的物理量。而同一种采集设备类型,往往又有多个具体的采集设备分布在不同的地点。采集的物理量都带有时间标签,而且数据量随时间不断增长,但每个数据采集设备或采集点还有自身的静态属性。对于同一类设备,其采集的数据以及静态属性都是很规则的。以智能电表为例,假设每个智能电表采集电流、电压、相位三个量,其采集的数据类似如下的表格:
+
+
+
+ 设备ID |
+ 时间戳 |
+ 采集量 |
+ 标签 |
+
+
+Device ID |
+Time Stamp |
+current |
+voltage |
+phase |
+location |
+groupId |
+
+
+
+
+d1001 |
+1538548685000 |
+10.3 |
+219 |
+0.31 |
+Beijing.Chaoyang |
+2 |
+
+
+d1002 |
+1538548684000 |
+10.2 |
+220 |
+0.23 |
+Beijing.Chaoyang |
+3 |
+
+
+d1003 |
+1538548686500 |
+11.5 |
+221 |
+0.35 |
+Beijing.Haidian |
+3 |
+
+
+d1004 |
+1538548685500 |
+13.4 |
+223 |
+0.29 |
+Beijing.Haidian |
+2 |
+
+
+d1001 |
+1538548695000 |
+12.6 |
+218 |
+0.33 |
+Beijing.Chaoyang |
+2 |
+
+
+d1004 |
+1538548696600 |
+11.8 |
+221 |
+0.28 |
+Beijing.Haidian |
+2 |
+
+
+d1002 |
+1538548696650 |
+10.3 |
+218 |
+0.25 |
+Beijing.Chaoyang |
+3 |
+
+
+d1001 |
+1538548696800 |
+12.3 |
+221 |
+0.31 |
+Beijing.Chaoyang |
+2 |
+
+
+
+
+ 表 1:智能电表数据示例
+
+每一条记录都有设备 ID,时间戳,采集的物理量(如上图中的电流、电压、相位),还有与每个设备相关的静态标签(如上述表 1 中的位置 location 和分组 groupId)。每个设备是受外界的触发,或按照设定的周期采集数据。采集的数据点是时序的,是一个数据流。
+
+## 数据特征
+
+除时序特征外,仔细研究发现,物联网、车联网、运维监测类数据及其应用还具有很多其他明显的特征。
1. 数据是结构化的;
2. 数据极少有更新或删除操作;
@@ -28,41 +115,62 @@
6. 用户关注的是一段时间的趋势,而不是某一特点时间点的值;
7. 数据是有保留期限的;
8. 数据的查询分析一定是基于时间段和地理区域的;
-9. 除存储查询外,还往往需要各种统计和实时计算操作;
+9. 系统需要各种实时计算和统计操作,包括降采样、插值等特种操作;
10. 数据量巨大,一天采集的数据就可以超过 100 亿条。
充分利用上述特征,TDengine 采取了一特殊的优化的存储和计算设计来处理时序数据,能将系统处理能力显著提高。
-## 数据采集点
+## 采集量(Metric)
+
+采集量是指传感器、设备或其他类型采集点采集的物理量,比如电流、电压、温度、压力、GPS位置等,是随时间变化的,数据类型可以是整型、浮点型、布尔型,也可是字符串。随着时间的推移,存储的采集量的数据量越来越大。
+
+## 标签(Label/Tag)
+
+标签是指传感器、设备或其他类型采集点的静态属性,不是随时间变化的,比如设备型号、颜色、设备的所在地等,数据类型可以是任何类型。虽然是静态的,但TDengine容许用户修改、删除或增加标签值。与采集量不一样的是,随时间的推移,存储的标签的数据量不会有什么变化。
+
+## 数据采集点(Data Colletion Point)
+
+数据采集点是指按照预设时间周期或受事件触发采集物理量的硬件或软件。一个数据采集点可以采集一个或多个物理量,**但这些物理量都是同一时刻采集的,具有相同的时间戳**。对于复杂的设备,往往有多个数据采集点,每个采集点采集的周期都可能不一样,而且完全独立,不同步。比如对于一台汽车,有数据采集点专门采集GPS位置,有数据采集点专门采集发动机状态,有数据采集点专门采集车内的环境,这样一台汽车就有三个数据采集点。
+
+## 关系型数据库模型
+
+因为采集的数据一般是结构化数据,同时为降低学习门槛,TDengine 采用传统的关系型数据库模型管理数据。用户需要先创建库,然后创建表,之后才能插入或查询数据。TDengine 采用的是结构化存储,而不是 NoSQL 的 key-value 存储。
+
+与通用数据库相比,TDengine通过一个数据采集点一张表,来大幅提高单个数据采集点的插入和查询速度。同时TDengine引入了超级表的概念,让每个表都带有标签,解决多个数据采集点之间的聚合分析问题。
-持续按照预设频率生成数据的软件或硬件设备称为数据采集点。TDengine中推荐一个数据采集点生成的数据存储在对应的一个或若干个表中。采集点产生的数据通常是包括时间戳、测量值、标签等必要信息构成的元组。
+## 一个数据采集点一张表
-## 采集量
+为充分利用其数据的时序性和其他数据特点,TDengine 要求**对每个数据采集点单独建表**(比如有一千万个智能电表,就需创建一千万张表,上述表格中的 d1001,d1002,d1003,d1004 都需单独建表),用来存储这个采集点所采集的时序数据。这种设计有几大优点:
-数据采集点生成的具有时间、测量值、标签的元组信息。除了时间戳、标签信息以外的测量值称为采集量。
+1. 由于不同采集设备产生数据的过程完全独立,每个设备的数据源是唯一的,一张表也就只有一个写入者,这样就可采用无锁方式来写,写入速度就能大幅提升。
+2. 对于一个数据采集点而言,其产生的数据是按照时间排序的,因此写的操作可用追加的方式实现,进一步大幅提高数据写入速度。
+3. 一个数据采集点的数据是以块为单位连续存储的。如果读取一个时间段的数据,它能大幅减少随机读取操作,成数量级的提升读取和查询速度。
+4. 一个数据块内部,采用列式存储,对于不同数据类型,采用不同压缩算法,而且由于一个数据采集点的采集量的变化是缓慢的,压缩率更高。
-## 标签
+如果采用传统的方式,将多个设备的数据写入一张表,由于网络延时不可控,不同设备的数据到达服务器的时序是无法保证的,写入操作是要有锁保护的,而且一个设备的数据是难以保证连续存储在一起的。**采用一个数据采集点一张表的方式,能最大程度的保证单个数据采集点的插入和查询的性能是最优的。**
-表的结构化描述信息,以一维数组形式存在。标签模式需要在创建超级表的时候指定,后续可动态调整。只有基于超级表创建的子表才具有标签。标签信息的内容首次创建子表的时候指定,并可按需调整。可以看到,TDengine中标签信息是表级别,而不是记录级别。
+TDengine 建议用数据采集点的名字(如上表中的 D1001)来做表名。每个数据采集点可能同时采集多个物理量(如上表中的 curent,voltage,phase),每个物理量对应一张表中的一列,数据类型可以是整型、浮点型、字符串等。除此之外,表的第一列必须是时间戳,即数据类型为 timestamp。对采集的数据,TDengine 将自动按照时间戳建立索引,但对采集的物理量不建任何索引。数据用列式存储方式保存。
-## 数据库
+对于复杂的设备,比如汽车,它有多个数据采集点,那么就需要为一台汽车建立多张表。
- TDengine中数据库与普通数据库管理系统中的数据库语义和行为相同,但是结合应用需求增加了若干配置参数用以控制其行为。
+## 超级表:同一类型数据采集点的集合
-## 超级表
+由于一个数据采集点一张表,导致表的数量巨增,难以管理,而且应用经常需要做采集点之间的聚合操作,聚合的操作也变得复杂起来。为解决这个问题,TDengine 引入超级表(Super Table,简称为 STable)的概念。
-超级表(Super Table, STable)是TDengine中一个重要的概念。超级表是面向相同数据模式的数据表,提供(数据+标签)模式管理和查询处理的逻辑抽象。通常将基于超级表创建的表称为该超级表的子表,并在系统内部建立逻辑关联。超级表与(基于其创建的)子表的关系体现在以下几个方面:
+超级表是指某一特定类型的数据采集点的集合。同一类型的数据采集点,其表的结构是完全一样的,但每个表(数据采集点)的静态属性(标签)是不一样的。描述一个超级表(某一特定类型的数据采集点的集合),除需要定义采集量的表结构之外,还需要定义其标签的 schema,标签的数据类型可以是整数、浮点数、字符串,标签可以有多个,可以事后增加、删除或修改。如果整个系统有 N 个不同类型的数据采集点,就需要建立 N 个超级表。
-超级表的子表共享其数据模式和标签模式。因此,不能通过子表调整数据或标签的模式。对于超级表的数据模式修改立即对所有的子表生效。
+在 TDengine 的设计里,**表用来代表一个具体的数据采集点,超级表用来代表一组相同类型的数据采集点集合**。当为某个具体数据采集点创建表时,用户使用超级表的定义做模板,同时指定该具体采集点(表)的标签值。与传统的关系型数据库相比,表(一个数据采集点)是带有静态标签的,而且这些标签可以事后增加、删除、修改。超级表与与基于超级表建立的子表之间的关系表现在:
-超级表自身不能存储任何数据或标签信息。因此,不能向一个超级表写入数据,只能将数据写入子表中。
+1. 一张超级表包含有多张子表,这些子表具有相同的采集量 schema,但带有不同的标签值。
+2. 不能通过子表调整数据或标签的模式,对于超级表的数据模式修改立即对所有的子表生效。
+3. 超级表只定义一个模板,自身不存储任何数据或标签信息。因此,不能向一个超级表写入数据,只能将数据写入子表中。
-针对超级表的查询,将所有子表中的数据视为一个整体数据集进行处理。但是可以直接发起针对某个或若干个子表的查询,此时查询请求将该子表视为一个普通的表进行处理。
+针对超级表的查询,TDengine将把所有子表中的数据视为一个整体数据集进行处理,会先把满足标签过滤条件的表从超级表中找出来,然后再扫描这些表的时序数据,进行聚合操作,这样需要扫描的数据集会大幅减少,从而显著提高查询的性能。本质上,TDengine通过对超级表查询的支持,实现了多个同类数据采集点的高效聚合。
-## 表
+## FQDN & End Point
-一系列二维数组的集合,用来代表和储存数据对象之间的关系,由纵向的列和横向的行组成。TDengine中的表与普通数据库中的表没有差别。
+FQDN (fully qualified domain name, 完全限定域名)是 Internet 上特定计算机或主机的完整域名。FQDN由两部分组成:主机名和域名。例如,假设邮件服务器的FQDN可能是mail.tdengine.com。主机名是mail,主机位于域名tdengine.com中。DNS(Domain Name System),负责将FQDN翻译成IP,是互联网应用的寻址方式。对于没有DNS的系统,可以通过配置hosts文件来解决。
-但是,对于通过超级表创建的子表,还具有额外的标签数据信息。不能针对某个子表调整数据模式。每个子表具有与其关联的标签数据,并可按需调整内容。但是模式调整必须要通过超级表模式调整来完成。
+TDengine集群的每个节点是由End Point来唯一标识的,End Point是由 FQDN 外加 Port 组成,比如 h1.tdengine.com:6030。这样当IP发生变化的时候,我们依然可以使用 FQDN 来动态找到节点,不需要更改集群的任何配置。而且采用 FQDN,便于内网和外网对同一个集群的统一访问。
-使用TDengine存储和管理物联网数据的时候,推荐使用一个子表存储一个数据采集点生成的数据,而使用超级表用来代表一组相同类型的数据采集点的集合。
+TDengine 不建议采用直接的IP地址访问集群,不利于管理。不了解 FQDN 概念,请看博文[《一篇文章说清楚 TDengine 的 FQDN》](https://www.taosdata.com/blog/2020/09/11/1824.html)。
diff --git a/docs-cn/03-get-started/03-get-started.md b/docs-cn/03-get-started/03-get-started.md
index a5b872d0ec7f8dedb34aa09ec4442aaf15dbf030..6776455c9dc3ab68d291488b7b3b0353967f0ac1 100644
--- a/docs-cn/03-get-started/03-get-started.md
+++ b/docs-cn/03-get-started/03-get-started.md
@@ -1,7 +1,21 @@
-# 立即开始
+---
+title: 立即开始
+description: "从 Docker,安装包或使用 apt-get 快速安装 TDengine, 通过命令行程序TAOS CLI和工具 taosdemo 快速体验 TDengine 功能"
+---
-## 从 Docker 快速开始
+import Tabs from "@theme/Tabs";
+import TabItem from "@theme/TabItem";
+import PkgInstall from "./\_pkg_install.mdx";
+import AptGetInstall from "./\_apt_get_install.mdx";
+
+## 安装
+
+TDengine 完整的软件包包括服务端(taosd)、用于与第三方系统对接并提供RESTful接口的taosAdapter、应用驱动(taosc)、命令行程序 (CLI,taos) 和一些工具软件,目前 2.X 版服务端taosd、taosAdapter 仅在 Linux 系统上安装和运行,后续将支持 Windows、macOS 等系统。应用驱动 taosc 与 TDengine CLI 可以在 Windows 或 Linux 上安装和运行。TDengine 除 RESTful接口外,还提供一些列编程语言的连接器。2.4 之前的版本中,无 taosAdapter,RESTfule 接口均由 taosd 内置的 http 服务提供。
+TDengine 支持 X64/ARM64/MIPS64/Alpha64 硬件平台,后续将支持 ARM32、RISC-V 等 CPU 架构。
+
+
+
如果已经安装了 docker, 只需执行下面的命令。
```shell
@@ -22,46 +36,32 @@ docker exec -it bash
然后就可以执行相关的 Linux 命令操作和访问 TDengine
-详细操作方法请参照 [通过 Docker 快速体验 TDengine](/train-fqa/docker)。
+详细操作方法请参照 [通过 Docker 快速体验 TDengine](/train-faq/docker)。
:::info
从 2.4.0.10 开始,除 taosd 以外,Docker 镜像还包含:taos、taosAdapter、taosdump、taosBenchmark、TDinsight 安装脚本和示例代码。启动 Docker 容器时,将同时启动 taosAdapter 和 taosd,实现对 RESTful 的支持。
:::
-:::note
-暂时不建议生产环境采用 Docker 来部署 TDengine 的客户端或服务端,但在开发环境下或初次尝试时,使用 Docker 方式部署是十分方便的。特别是,利用 Docker,可以方便地在 macOS 和 Windows 环境下尝试 TDengine。
-
-:::
-
-## 安装
+
+
+
+
+
+
+
+
-import Tabs from "@theme/Tabs";
-import TabItem from "@theme/TabItem";
-import PkgInstall from "./\_pkg_install.mdx";
-import AptGetInstall from "./\_apt_get_install.mdx";
-import SrcInstall from "./\_src_install.mdx";
+如果您希望对 TDengine 贡献代码或对内部实现感兴趣,请参考我们的 [TDengine GitHub 主页](https://github.com/taosdata/TDengine) 下载源码构建和安装.
-TDengine 包括服务端、客户端和周边生态工具软件,目前 2.0 版服务端仅在 Linux 系统上安装和运行,后续将支持 Windows、macOS 等系统。客户端可以在 Windows 或 Linux 上安装和运行。在任何操作系统上的应用都可以使用 RESTful 接口连接服务端程序 taosd,其中 2.4 之后版本默认使用单独运行的独立组件 taosAdapter 提供 http 服务和更多数据写入方式。taosAdapter 需要手动启动。
-之前版本 TDengine 服务端,以及所有服务端 lite 版,均使用内置 http 服务。
+下载其他组件、最新 Beta 版及之前版本的安装包,请点击[这里](https://www.taosdata.com/cn/all-downloads/)。
-TDengine 支持 X64/ARM64/MIPS64/Alpha64 硬件平台,后续将支持 ARM32、RISC-V 等 CPU 架构。
-
-
-
-
-
-
-
-
-
-
-
+
## 启动
-使用 `systemctl` 命令来启动 TDengine 的服务进程。
+安装后,请使用 `systemctl` 命令来启动 TDengine 的服务进程。
```bash
systemctl start taosd
@@ -79,7 +79,7 @@ systemctl status taosd
- systemctl 命令需要 _root_ 权限来运行,如果您非 _root_ 用户,请在命令前添加 sudo 。
- 为更好的获得产品反馈,改善产品,TDengine 会采集基本的使用信息,但您可以修改系统配置文件 taos.cfg 里的配置参数 telemetryReporting,将其设为 0,就可将其关闭。
-- TDengine 采用 FQDN(一般就是 hostname)作为节点的 ID,为保证正常运行,需要给运行 taosd 的服务器配置好 hostname,在客户端应用运行的机器配置好 DNS 服务或 hosts 文件,保证 FQDN 能够解析。
+- TDengine 采用 FQDN(一般就是 hostname)作为节点的 ID,为保证正常运行,需要给运行 taosd 的服务器配置好 FQDN,在 TDengine CLI 或应用运行的机器配置好 DNS 服务或 hosts 文件,保证 FQDN 能够解析。
- `systemctl stop taosd` 指令在执行后并不会马上停止 TDengine 服务,而是会等待系统中必要的落盘工作正常完成。在数据量很大的情况下,这可能会消耗较长时间。
TDengine 支持在使用 [`systemd`](https://en.wikipedia.org/wiki/Systemd) 做进程服务管理的 Linux 系统上安装,用 `which systemctl` 命令来检测系统中是否存在 `systemd` 包:
@@ -92,23 +92,23 @@ which systemctl
:::note
-## 进入命令行
+## TDengine 命令行 (CLI)
-执行 TDengine 客户端程序,您只要在 Linux 终端执行 `taos` 即可。
+为便于检查 TDengine 的状态,执行各种即席(Ad Hoc)查询,TDengine 提供一命令行应用程序(以下简称为 TDengine CLI) taos。要进入 TDengine 命令行,您只要在安装有 TDengine 的 Linux 终端执行 `taos` 即可。
```bash
taos
```
-如果连接服务成功,将会打印出欢迎消息和版本信息。如果失败,则会打印错误消息出来(请参考 [FAQ](/train-fqa/faq) 来解决终端连接服务端失败的问题)。客户端的提示符号如下:
+如果连接服务成功,将会打印出欢迎消息和版本信息。如果失败,则会打印错误消息出来(请参考 [FAQ](/train-faq/faq) 来解决终端连接服务端失败的问题)。 TDengine CLI 的提示符号如下:
```cmd
taos>
```
-在 TDengine 客户端中,用户可以通过 SQL 命令来创建/删除数据库、表等,并进行插入查询操作。在终端中运行的 SQL 语句需要以分号结束来运行。示例:
+在 TDengine CLI中,用户可以通过 SQL 命令来创建/删除数据库、表等,并进行插入查询操作。在终端中运行的 SQL 语句需要以分号结束来运行。示例:
-```mysql
+```sql
create database demo;
use demo;
create table t (ts timestamp, speed int);
@@ -122,45 +122,11 @@ select * from t;
Query OK, 2 row(s) in set (0.003128s)
```
-除执行 SQL 语句外,系统管理员还可以从 TDengine 客户端进行检查系统运行状态、添加删除用户账号等操作。
-
-## 命令行参数
-
-您可通过配置命令行参数来改变 TDengine 客户端的行为。以下为常用的几个命令行参数:
-
-- -c, --config-dir: 指定配置文件目录,默认为 `/etc/taos`
-- -h, --host: 指定服务的 FQDN 地址或 IP 地址,默认为连接本地服务
-- -s, --commands: 在不进入终端的情况下运行 TDengine 命令
-- -u, --user: 连接 TDengine 服务端的用户名,缺省为 root
-- -p, --password: 连接 TDengine 服务端的密码,缺省为 taosdata
-- -?, --help: 打印出所有命令行参数
-
-示例:
-
-```bash
-taos -h h1.taos.com -s "use db; show tables;"
-```
-
-## 运行 SQL 命令脚本
-
-TDengine 终端可以通过 `source` 命令来运行 SQL 命令脚本。
-
-```mysql
-taos> source ;
-```
-
-## taos shell 小技巧
-
-- 可以使用上下光标键查看历史输入的指令
-- 修改用户密码:在 shell 中使用 `alter user` 命令,缺省密码为 taosdata
-- ctrl+c 中止正在进行中的查询
-- 执行 `RESET QUERY CACHE` 可清除本地缓存的表 schema
-- 批量执行 SQL 语句。可以将一系列的 shell 命令(以英文 ; 结尾,每个 SQL 语句为一行)按行存放在文件里,在 shell 里执行命令 `source ` 自动执行该文件里所有的 SQL 语句
-- 输入 q 回车,退出 taos shell
+除执行 SQL 语句外,系统管理员还可以从 TDengine CLI 进行检查系统运行状态、添加删除用户账号等操作。TAOS CLI 连同应用驱动也可以独立安装在 Linux 或 windows 机器上运行,更多细节请参考 [这里](../reference/taos-shell/)
## 使用 taosBenchmark 体验写入速度
-启动 TDengine 的服务,在 Linux 终端执行 `taosBenchmark` (曾命名为 taosdemo):
+启动 TDengine 的服务,在 Linux 终端执行 `taosBenchmark` (曾命名为 `taosdemo`):
```bash
taosBenchmark
@@ -170,42 +136,38 @@ taosBenchmark
这条命令很快完成 1 亿条记录的插入。具体时间取决于硬件性能,即使在一台普通的 PC 服务器往往也仅需十几秒。
-## taosBenchmark 详细功能列表
-
-taosBenchmark 命令本身带有很多选项,配置表的数目、记录条数等等,请执行 `taosBenchmark --help` 详细列出。您可以设置不同参数进行体验。
-
-taosBenchmark 详细使用方法请参照 [如何使用 taosBenchmark 对 TDengine 进行性能测试](https://www.taosdata.com/2021/10/09/3111.html)。
+taosBenchmark 命令本身带有很多选项,配置表的数目、记录条数等等,您可以设置不同参数进行体验,请执行 `taosBenchmark --help` 详细列出。taosBenchmark 详细使用方法请参照 [如何使用 taosBenchmark 对 TDengine 进行性能测试](https://www.taosdata.com/2021/10/09/3111.html)。
-## 使用 taos shell 体验查询速度
+## 使用 TDengine CLI 体验查询速度
-在 TDengine 客户端输入查询命令,体验查询速度。
+使用上述 taosBenchmark 插入数据后,可以在 TDengine CLI 输入查询命令,体验查询速度。
查询超级表下记录总条数:
-```mysql
+```sql
taos> select count(*) from test.meters;
```
查询 1 亿条记录的平均值、最大值、最小值等:
-```mysql
+```sql
taos> select avg(current), max(voltage), min(phase) from test.meters;
```
查询 location="beijing" 的记录总条数:
-```mysql
+```sql
taos> select count(*) from test.meters where location="beijing";
```
查询 groupId=10 的所有记录的平均值、最大值、最小值等:
-```mysql
+```sql
taos> select avg(current), max(voltage), min(phase) from test.meters where groupId=10;
```
对表 d10 按 10s 进行平均值、最大值和最小值聚合统计:
-```mysql
+```sql
taos> select avg(current), max(voltage), min(phase) from test.d10 interval(10s);
```
diff --git a/docs-cn/03-get-started/_apt_get_install.mdx b/docs-cn/03-get-started/_apt_get_install.mdx
index 8161d8e805c94e4fdc60a63f7cefc452eb833f5a..b1bc4a13517bbfdc9eda86a58b89aee8e41fa470 100644
--- a/docs-cn/03-get-started/_apt_get_install.mdx
+++ b/docs-cn/03-get-started/_apt_get_install.mdx
@@ -1,4 +1,4 @@
-如果,可以使用 apt-get 工具从官方仓库安装。
+可以使用 apt-get 工具从官方仓库安装。
**安装包仓库**
diff --git a/docs-cn/03-get-started/_pkg_install.mdx b/docs-cn/03-get-started/_pkg_install.mdx
index c3d1d97fe318422207f8aadbe60f3ec27dae6e08..13047f99805172cf37958f18a0c94c5b3201745b 100644
--- a/docs-cn/03-get-started/_pkg_install.mdx
+++ b/docs-cn/03-get-started/_pkg_install.mdx
@@ -1,5 +1,3 @@
-import PkgList from "./_pkg_list.mdx";
-
TDengine 的安装非常简单,从下载到安装成功仅仅只要几秒钟。
为方便使用,从 2.4.0.10 开始,标准的服务端安装包包含了 taos、taosd、taosAdapter、taosdump、taosBenchmark、TDinsight 安装脚本和示例代码;如果您只需要用到服务端程序和客户端连接的 C/C++ 语言支持,也可以仅下载 lite 版本的安装包。
@@ -8,6 +6,51 @@ TDengine 的安装非常简单,从下载到安装成功仅仅只要几秒钟
发布版本包括稳定版和 Beta 版,Beta 版含有更多新功能。正式上线或测试建议安装稳定版。您可以根据需要选择下载:
-
+
+
+具体的安装方法,请参见[安装包的安装和卸载](/operation/pkg-install)。
+
+下载其他组件、最新 Beta 版及之前版本的安装包,请点击[这里](https://www.taosdata.com/all-downloads)
-具体的安装方法,请参见 [安装包的安装和卸载](/operation/pkg-install) 以及 [视频教程](https://www.taosdata.com/blog/2020/11/11/1941.html)。
+请点击[这里](https://github.com/taosdata/TDengine/releases) 查看 Release Notes。
diff --git a/docs-cn/03-get-started/_pkg_list.mdx b/docs-cn/03-get-started/_pkg_list.mdx
deleted file mode 100644
index 1ed8a107170302c37ac66d2e0087cb14122cf5cb..0000000000000000000000000000000000000000
--- a/docs-cn/03-get-started/_pkg_list.mdx
+++ /dev/null
@@ -1,48 +0,0 @@
-**最新安装包**
-
-
-
-**所有下载**
-
-https://www.taosdata.com/all-downloads
diff --git a/docs-cn/03-get-started/_src_install.mdx b/docs-cn/03-get-started/_src_install.mdx
deleted file mode 100644
index 2004d73fe0d7a4c4aaf50fa42e996841c8c08275..0000000000000000000000000000000000000000
--- a/docs-cn/03-get-started/_src_install.mdx
+++ /dev/null
@@ -1,3 +0,0 @@
-如果您希望对 TDengine 贡献代码或对内部实现感兴趣,请参考我们的 [TDengine GitHub 主页](https://github.com/taosdata/TDengine) 下载源码构建和安装.
-
-下载其他组件、最新 Beta 版及之前版本的安装包,请点击[这里](https://www.taosdata.com/cn/all-downloads/)。
diff --git a/docs-cn/04-connect/04-connect.mdx b/docs-cn/04-connect/04-connect.mdx
deleted file mode 100644
index 6c664f2a7516814802fdeae2579586d3320bfead..0000000000000000000000000000000000000000
--- a/docs-cn/04-connect/04-connect.mdx
+++ /dev/null
@@ -1,91 +0,0 @@
----
-sidebar_label: 建立连接
-sidebar_position: 4
----
-
-# 建立连接
-
-import Tabs from "@theme/Tabs";
-import TabItem from "@theme/TabItem";
-import ConnRest from "./_connect_restful.mdx";
-import ConnJava from "./_connect_java.mdx";
-import ConnGo from "./_connect_go.mdx";
-import ConnRust from "./_connect_rust.mdx";
-import ConnNode from "./_connect_node.mdx";
-import ConnJavaNative from "./_connect_java_native.mdx";
-import ConnPythonNative from "./_connect_python_native.mdx";
-import ConnGoNative from "./_connect_go_native.mdx";
-import ConnRustNative from "./_connect_rust_native.mdx";
-import ConnNodeNative from "./_connect_node_native.mdx";
-import ConnCSNative from "./_connect_cs_native.mdx";
-import ConnC from "./_connect_c.mdx";
-
-## 连接器介绍
-
-TDengine 提供了丰富的应用程序开发接口,其中包括 C/C++、Java、Python、Go、Node.js、C# 、RESTful 等,便于用户快速开发应用。
-
-
-
-(图:连接器工作原理)
-
-TDengine 提供了 RESTful 接口,应用程序无需安装任何依赖,只需发送 HTTP 请求就可以连接到 TDengine。同时也提供了各语言的连接器,使用驱动程序 (taosc) 连接 TDengine。通过驱动程序可以使用 TDengine 更丰富的功能。
-
-## 前提条件
-
-在执行这一步之前,请确保有一个正在运行的,且可以访问到的 TDengine。以下所有示例代码,都假设 TDengine 安装在本机,且 fqdn(默认 localhost) 和 serverPort(默认 6030) 都使用默认配置。
-
-## 建立连接
-
-### RESTful
-
-如果你安装的是 TDengine 2.4 之后的版本,使用 RESTful 方式连接时还需启动 taosAdaper。
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-### 本地驱动
-
-在没有安装 TDengine 服务端软件的系统上使用本地驱动连接 TDengine, 需要提前[安装客户端驱动程序](/reference/connector/#安装客户端驱动)。
-:::note
-需要单独安装客户端时,为避免客户端驱动和服务端不兼容,请尽量使用一致的版本。
-
-:::
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/docs-cn/04-connect/_connect_cs_native.mdx b/docs-cn/04-connect/_connect_cs_native.mdx
deleted file mode 100644
index 19dc4bb52b8d033d49882d9be6e7a9c76e8fe61f..0000000000000000000000000000000000000000
--- a/docs-cn/04-connect/_connect_cs_native.mdx
+++ /dev/null
@@ -1,9 +0,0 @@
-首先添加 [TDengine.Connector](https://www.nuget.org/packages/TDengine.Connector/) 的引用:
-
-```bash
-dotnet add package TDengine.Connector
-```
-
-```csharp
-{{#include docs-examples/csharp/ConnectExample.cs}}
-```
diff --git a/docs-cn/04-connect/_connect_go.mdx b/docs-cn/04-connect/_connect_go.mdx
deleted file mode 100644
index 17d7eb98ba3fa7483edd54978771e03cc051ff53..0000000000000000000000000000000000000000
--- a/docs-cn/04-connect/_connect_go.mdx
+++ /dev/null
@@ -1,11 +0,0 @@
-```go-mod title=go.mod
-module goexample
-
-go 1.17
-
-require github.com/taosdata/driver-go/v2 develop
-```
-
-```go
-{{#include docs-examples/go/connect/restexample/main.go}}
-```
diff --git a/docs-cn/04-connect/_connect_go_native.mdx b/docs-cn/04-connect/_connect_go_native.mdx
deleted file mode 100644
index 44d31f4b8bfde337c5ef31337fc3ccf25149adb1..0000000000000000000000000000000000000000
--- a/docs-cn/04-connect/_connect_go_native.mdx
+++ /dev/null
@@ -1,16 +0,0 @@
-:::note
-driver-go 使用 cgo 封装了 taosc 的 API。cgo 需要使用 gcc 编译 C 的源码。因此需要确保你的系统上有 gcc。
-
-:::
-
-```go-mod title=go.mod
-module goexample
-
-go 1.17
-
-require github.com/taosdata/driver-go/v2 develop
-```
-
-```go
-{{#include docs-examples/go/connect/cgoexample/main.go}}
-```
diff --git a/docs-cn/04-connect/_connect_java.mdx b/docs-cn/04-connect/_connect_java.mdx
deleted file mode 100644
index 4282e57215a896656c5ca2a51df45f3bef1cdd5a..0000000000000000000000000000000000000000
--- a/docs-cn/04-connect/_connect_java.mdx
+++ /dev/null
@@ -1,11 +0,0 @@
-```xml title=pom.xml
-
- com.taosdata.jdbc
- taos-jdbcdriver
- 2.0.37
-
-```
-
-```java
-{{#include docs-examples/java/src/main/java/com/taos/example/RESTConnectExample.java}}
-```
diff --git a/docs-cn/04-connect/_connect_java_native.mdx b/docs-cn/04-connect/_connect_java_native.mdx
deleted file mode 100644
index 9d75df6684ace21d1e7c5995d07d578b8d3803d2..0000000000000000000000000000000000000000
--- a/docs-cn/04-connect/_connect_java_native.mdx
+++ /dev/null
@@ -1,11 +0,0 @@
-```xml title=pom.xml
-
- com.taosdata.jdbc
- taos-jdbcdriver
- 2.0.37
-
-```
-
-```java
-{{#include docs-examples/java/src/main/java/com/taos/example/JNIConnectExample.java}}
-```
diff --git a/docs-cn/04-connect/_connect_node_native.mdx b/docs-cn/04-connect/_connect_node_native.mdx
deleted file mode 100644
index 4ffeedd8d9fdc600f8f4b5ab1db41b2139a75039..0000000000000000000000000000000000000000
--- a/docs-cn/04-connect/_connect_node_native.mdx
+++ /dev/null
@@ -1,9 +0,0 @@
-首先需要安装 node.js 的连接器 `td2.0-connector`:
-
-```bash
-npm install td2.0-connector
-```
-
-```js
-{{#include docs-examples/node/nativeexample/connect.js}}
-```
diff --git a/docs-cn/04-connect/_connect_python_native.mdx b/docs-cn/04-connect/_connect_python_native.mdx
deleted file mode 100644
index 1a258988835c383285f16ff9eb0b64518941f7b0..0000000000000000000000000000000000000000
--- a/docs-cn/04-connect/_connect_python_native.mdx
+++ /dev/null
@@ -1,9 +0,0 @@
-推荐使用 `python >= 3.4`。首先需要安装 python 连接器 `taospy`。执行以下命令即可:
-
-```
-pip3 install taospy
-```
-
-```python
-{{#include docs-examples/python/connect_exmaple.py}}
-```
diff --git a/docs-cn/04-connect/_connect_restful.mdx b/docs-cn/04-connect/_connect_restful.mdx
deleted file mode 100644
index d68903aa3979f5098e83a029bae42d5f8363fa93..0000000000000000000000000000000000000000
--- a/docs-cn/04-connect/_connect_restful.mdx
+++ /dev/null
@@ -1,22 +0,0 @@
-下面用 curl 工具来演示访问 RESTful 接口。在命令行执行下面的命令:
-
-```bash
-curl http://localhost:6041/rest/sql -u root:taosdata -d "select server_version()"
-```
-
-- `-u` 用于指定访问数据库的用户名和密码。
-- `-d` 用于指定发送要执行的 SQL 语句。它会被放入 POST 请求的 Body 中。
-
-如果正常,会返回一个 JSON 字符串,里面包含了服务端的版本。例如:
-
-```json
-{
- "status": "succ",
- "head": ["server_version()"],
- "column_meta": [["server_version()", 8, 7]],
- "data": [["2.4.0.0"]],
- "rows": 1
-}
-```
-
-了解更多:[RESTful API](/reference/restful-api)。
diff --git a/docs-cn/04-connect/_connect_rust.mdx b/docs-cn/04-connect/_connect_rust.mdx
deleted file mode 100644
index b167278a55f9b3dca97367e0b391fef28a00d6ec..0000000000000000000000000000000000000000
--- a/docs-cn/04-connect/_connect_rust.mdx
+++ /dev/null
@@ -1,8 +0,0 @@
-```toml title=Cargo.toml
-[dependencies]
-libtaos = { version = "*", features = ["rest"] }
-```
-
-```rust
-{{#include docs-examples/rust/restexample/examples/connect.rs}}
-```
diff --git a/docs-cn/04-connect/_connect_rust_native.mdx b/docs-cn/04-connect/_connect_rust_native.mdx
deleted file mode 100644
index 0ee07c295eb457322d32caaa4cb027593ac5966d..0000000000000000000000000000000000000000
--- a/docs-cn/04-connect/_connect_rust_native.mdx
+++ /dev/null
@@ -1,8 +0,0 @@
-```toml title=Cargo.toml
-[dependencies]
-libtaos = { version = "0.4.2"}
-```
-
-```rust
-{{#include docs-examples/rust/nativeexample/examples/connect.rs}}
-```
diff --git a/docs-cn/04-connect/_category_.yml b/docs-cn/04-develop/01-connect/_category_.yml
similarity index 100%
rename from docs-cn/04-connect/_category_.yml
rename to docs-cn/04-develop/01-connect/_category_.yml
diff --git a/docs-cn/04-connect/_connect_c.mdx b/docs-cn/04-develop/01-connect/_connect_c.mdx
similarity index 66%
rename from docs-cn/04-connect/_connect_c.mdx
rename to docs-cn/04-develop/01-connect/_connect_c.mdx
index 4d6f1cfe1b06ef9baeb7da2bb2559880ada99fbf..9cd8669561195b49e8428ed490ad97bb5653ae6a 100644
--- a/docs-cn/04-connect/_connect_c.mdx
+++ b/docs-cn/04-develop/01-connect/_connect_c.mdx
@@ -1,3 +1,3 @@
-```c
+```c title="原生连接"
{{#include docs-examples/c/connect_example.c}}
```
diff --git a/docs-cn/04-develop/01-connect/_connect_cs.mdx b/docs-cn/04-develop/01-connect/_connect_cs.mdx
new file mode 100644
index 0000000000000000000000000000000000000000..204173dd329f6f214a9ea44c2f360be2cdbfdab8
--- /dev/null
+++ b/docs-cn/04-develop/01-connect/_connect_cs.mdx
@@ -0,0 +1,7 @@
+```csharp title="原生连接"
+{{#include docs-examples/csharp/ConnectExample.cs}}
+```
+:::info
+C# 连接器目前只支持原生连接。
+
+:::
\ No newline at end of file
diff --git a/docs-cn/04-develop/01-connect/_connect_go.mdx b/docs-cn/04-develop/01-connect/_connect_go.mdx
new file mode 100644
index 0000000000000000000000000000000000000000..4e4f189672f2fda4b807fe628d4455a41ac4cb69
--- /dev/null
+++ b/docs-cn/04-develop/01-connect/_connect_go.mdx
@@ -0,0 +1,15 @@
+#### 使用数据库访问统一接口
+```go title="原生连接"
+{{#include docs-examples/go/connect/cgoexample/main.go}}
+```
+```go title="REST 连接"
+{{#include docs-examples/go/connect/restexample/main.go}}
+```
+#### 使用高级封装
+也可以使用 driver-go 的 af 包建立连接。这个模块封装了 TDengine 的高级功能, 如:参数绑定、订阅等。
+
+```go title="使用 af 包建立原生连接"
+{{#include docs-examples/go/connect/afconn/main.go}}
+```
+
+
diff --git a/docs-cn/04-develop/01-connect/_connect_java.mdx b/docs-cn/04-develop/01-connect/_connect_java.mdx
new file mode 100644
index 0000000000000000000000000000000000000000..cd6d7c4cab9a84abb22895c704debd260884081f
--- /dev/null
+++ b/docs-cn/04-develop/01-connect/_connect_java.mdx
@@ -0,0 +1,11 @@
+```java title="原生连接"
+{{#include docs-examples/java/src/main/java/com/taos/example/JNIConnectExample.java}}
+```
+```java title="REST 连接"
+{{#include docs-examples/java/src/main/java/com/taos/example/RESTConnectExample.java:main}}
+```
+使用REST 连接时,如果查询数据量比较大,还可开启批量拉取功能。
+```java title="开启批量拉取功能" {4}
+{{#include docs-examples/java/src/main/java/com/taos/example/WSConnectExample.java:main}}
+```
+更多连接参数配置,参考[Java 连接器](/reference/connector/java)
\ No newline at end of file
diff --git a/docs-cn/04-develop/01-connect/_connect_node.mdx b/docs-cn/04-develop/01-connect/_connect_node.mdx
new file mode 100644
index 0000000000000000000000000000000000000000..8a259888f87d4d441c58b9a8a9008b19273c1a58
--- /dev/null
+++ b/docs-cn/04-develop/01-connect/_connect_node.mdx
@@ -0,0 +1,6 @@
+```js title="原生连接"
+{{#include docs-examples/node/nativeexample/connect.js}}
+```
+```js title="REST 连接"
+{{#include docs-examples/node/restexample/connect.js}}
+```
\ No newline at end of file
diff --git a/docs-cn/04-develop/01-connect/_connect_python.mdx b/docs-cn/04-develop/01-connect/_connect_python.mdx
new file mode 100644
index 0000000000000000000000000000000000000000..331ec0f693601baeb28ede7b0278e67f1471c187
--- /dev/null
+++ b/docs-cn/04-develop/01-connect/_connect_python.mdx
@@ -0,0 +1,3 @@
+```python title="原生连接"
+{{#include docs-examples/python/connect_exmaple.py}}
+```
\ No newline at end of file
diff --git a/docs-cn/04-develop/01-connect/_connect_r.mdx b/docs-cn/04-develop/01-connect/_connect_r.mdx
new file mode 100644
index 0000000000000000000000000000000000000000..a69a57f66be3672d61cb0f84f43aba123cfbd5aa
--- /dev/null
+++ b/docs-cn/04-develop/01-connect/_connect_r.mdx
@@ -0,0 +1,3 @@
+```r title="原生连接"
+{{#include docs-examples/R/connect_native.r:demo}}
+```
\ No newline at end of file
diff --git a/docs-cn/04-develop/01-connect/_connect_rust.mdx b/docs-cn/04-develop/01-connect/_connect_rust.mdx
new file mode 100644
index 0000000000000000000000000000000000000000..b051108452d16f207ce10b128f5de2e5f507200f
--- /dev/null
+++ b/docs-cn/04-develop/01-connect/_connect_rust.mdx
@@ -0,0 +1,7 @@
+```rust title="原生连接/REST 连接"
+{{#include docs-examples/rust/nativeexample/examples/connect.rs}}
+```
+:::note
+对于 Rust 连接器, 连接方式的不同只体现在使用的特性不同。如果启用了 "rest" 特性,那么只有 RESTful 的实现会被编译进来。
+
+:::
diff --git a/docs-cn/04-develop/01-connect/index.md b/docs-cn/04-develop/01-connect/index.md
new file mode 100644
index 0000000000000000000000000000000000000000..144b08433d511b06a95344e819a907a95779e0d2
--- /dev/null
+++ b/docs-cn/04-develop/01-connect/index.md
@@ -0,0 +1,239 @@
+---
+title: 建立连接
+description: "本节介绍如何使用连接器建立与 TDengine 的连接,给出连接器安装、连接的简单说明。"
+---
+
+import Tabs from "@theme/Tabs";
+import TabItem from "@theme/TabItem";
+import ConnJava from "./_connect_java.mdx";
+import ConnGo from "./_connect_go.mdx";
+import ConnRust from "./_connect_rust.mdx";
+import ConnNode from "./_connect_node.mdx";
+import ConnPythonNative from "./_connect_python.mdx";
+import ConnCSNative from "./_connect_cs.mdx";
+import ConnC from "./_connect_c.mdx";
+import ConnR from "./_connect_r.mdx";
+import InstallOnWindows from "../../14-reference/03-connector/_linux_install.mdx";
+import InstallOnLinux from "../../14-reference/03-connector/_windows_install.mdx";
+import VerifyLinux from "../../14-reference/03-connector/_verify_linux.mdx";
+import VerifyWindows from "../../14-reference/03-connector/_verify_windows.mdx";
+
+TDengine 提供 REST API,容许在任何平台的任何应用程序通过它访问 TDengine 运行实例,详细介绍请看 [REST API](/reference/rest-api/)。除 REST API 之外,TDengine 还提供多种编程语言的连接器方便用户开发应用程序,其中包括 C/C++、Java、Python、Go、Node.js、C# 等。 本节介绍如何使用连接器建立与 TDengine 的连接,给出连接器安装、连接的简单说明。关于各连接器的详细功能说明,请查看[连接器](https://docs.taosdata.com/reference/connector/)
+
+## 连接器建立连接的方式
+
+连接器建立连接的方式,TDengine 提供两种:
+
+1. 通过 taosAdapter 组件提供的 REST API 建立与 taosd 的连接,这种连接方式下文中简称"REST 连接“
+2. 通过客户端驱动程序 taosc 直接与服务端程序 taosd 建立连接,这种连接方式下文中简称“原生连接”。
+
+无论使用何种方式建立连接,连接器都提供了相同或相似的 API 操作数据库,都可以执行 SQL 语句,只是初始化连接的方式稍有不同,用户在使用上不会感到什么差别。
+
+关键不同点在于:
+
+1. 使用 REST 连接,用户无需安装客户端驱动程序 taosc,具有跨平台易用的优势,但性能要下降 30%左右。
+2. 使用原生连接可以体验 TDengine 的全部功能,如[参数绑定接口](/reference/connector/cpp#参数绑定-api)、[订阅](reference/connector/cpp#数据订阅接口)等等。
+
+## 安装客户端驱动 taosc
+
+如果选择原生连接,而且应用程序不在 TDengine 同一台服务器上运行,你需要先安装客户端驱动,否则可以跳过此一步。为避免客户端驱动和服务端不兼容,请使用一致的版本。
+
+### 安装步骤
+
+
+
+
+
+
+
+
+
+
+### 安装验证
+
+以上安装和配置完成后,并确认 TDengine 服务已经正常启动运行,此时可以执行安装包里带有的 TDengine 命令行程序 taos 进行登录。
+
+
+
+
+
+
+
+
+
+
+## 安装连接器
+
+
+
+
+如果使用 maven 管理项目,只需在 pom.xml 中加入以下依赖。
+
+```xml
+
+ com.taosdata.jdbc
+ taos-jdbcdriver
+ 2.0.38
+
+```
+
+
+
+
+使用 `pip` 从 PyPI 安装:
+
+```
+pip install taospy
+```
+
+从 Git URL 安装:
+
+```
+pip install git+https://github.com/taosdata/taos-connector-python.git
+```
+
+
+
+
+编辑 `go.mod` 添加 `driver-go` 依赖即可。
+
+```go-mod title=go.mod
+module goexample
+
+go 1.17
+
+require github.com/taosdata/driver-go/v2 develop
+```
+
+:::note
+driver-go 使用 cgo 封装了 taosc 的 API。cgo 需要使用 gcc 编译 C 的源码。因此需要确保你的系统上有 gcc。
+
+:::
+
+
+
+
+编辑 `Cargo.toml` 添加 `libtaos` 依赖即可。
+
+```toml title=Cargo.toml
+[dependencies]
+libtaos = { version = "0.4.2"}
+```
+
+:::info
+Rust 连接器通过不同的特性区分不同的连接方式。如果要建立 REST 连接,需要开启 `rest` 特性:
+
+```toml
+libtaos = { version = "*", features = ["rest"] }
+```
+
+:::
+
+
+
+
+Node.js 连接器通过不同的包提供不同的连接方式。
+
+1. 安装 Node.js 原生连接器
+
+```
+npm i td2.0-connector
+```
+
+:::note
+推荐 Node 版本大于等于 `node-v12.8.0` 小于 `node-v13.0.0`
+
+::: 2. 安装 Node.js REST 连接器
+
+```
+npm i td2.0-rest-connector
+```
+
+
+
+
+编辑项目配置文件中添加 [TDengine.Connector](https://www.nuget.org/packages/TDengine.Connector/) 的引用即可:
+
+```xml title=csharp.csproj {12}
+
+
+
+ Exe
+ net6.0
+ enable
+ enable
+ TDengineExample.AsyncQueryExample
+
+
+
+
+
+
+
+```
+
+也可通过 dotnet 命令添加:
+
+```
+dotnet add package TDengine.Connector
+```
+
+:::note
+以下示例代码,均基于 dotnet6.0,如果使用其它版本,可能需要做适当调整。
+
+:::
+
+
+
+
+1. 下载 [taos-jdbcdriver-version-dist.jar](https://repo1.maven.org/maven2/com/taosdata/jdbc/taos-jdbcdriver/2.0.38/)。
+2. 安装 R 的依赖包`RJDBC`:
+
+```R
+install.packages("RJDBC")
+```
+
+
+
+
+如果已经安装了 TDengine 服务端软件或 TDengine 客户端驱动 taosc, 那么已经安装了 C 连接器,无需额外操作。
+
+
+
+
+
+## 建立连接
+
+在执行这一步之前,请确保有一个正在运行的,且可以访问到的 TDengine,而且服务端的 FQDN 配置正确。以下示例代码,都假设 TDengine 安装在本机,且 FQDN(默认 localhost) 和 serverPort(默认 6030) 都使用默认配置。
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+:::tip
+如果建立连接失败,大部分情况下是 FQDN 或防火墙的配置不正确,详细的排查方法请看[《常见问题及反馈》](https://docs.taosdata.com/train-faq/faq)中的“遇到错误 Unable to establish connection, 我怎么办?”
+
+:::
diff --git a/docs-cn/05-model/_category_.yml b/docs-cn/04-develop/02-model/_category_.yml
similarity index 95%
rename from docs-cn/05-model/_category_.yml
rename to docs-cn/04-develop/02-model/_category_.yml
index c61397aa9b77ad3c29bdd4aed021d1e2c556c4a1..e5dae7c27cf17ff737aa8301bc79aad468c28791 100644
--- a/docs-cn/05-model/_category_.yml
+++ b/docs-cn/04-develop/02-model/_category_.yml
@@ -1 +1,2 @@
label: 数据建模
+
diff --git a/docs-cn/05-model/05-model.mdx b/docs-cn/04-develop/02-model/index.mdx
similarity index 69%
rename from docs-cn/05-model/05-model.mdx
rename to docs-cn/04-develop/02-model/index.mdx
index f7f0b51350be62ea2faf8992ba9fc93bd1092979..7cf03cee37a5ac681181b0982e98e48d139ddb83 100644
--- a/docs-cn/05-model/05-model.mdx
+++ b/docs-cn/04-develop/02-model/index.mdx
@@ -1,18 +1,21 @@
-# TDengine 数据建模
+---
+slug: /model
+title: TDengine 数据建模
+---
-TDengine 采用关系型数据模型,需要建库、建表。因此对于一个具体的应用场景,需要考虑库、超级表和普通表的设计。本节不讨论细致的语法规则,只介绍概念。
+TDengine 采用类关系型数据模型,需要建库、建表。因此对于一个具体的应用场景,需要考虑库、超级表和普通表的设计。本节不讨论细致的语法规则,只介绍概念。
关于数据建模请参考[视频教程](https://www.taosdata.com/blog/2020/11/11/1945.html)。
## 创建库
-不同类型的数据采集点往往具有不同的数据特征,包括数据采集频率的高低,数据保留时间的长短,副本的数目,数据块的大小,是否允许更新数据等等。为了在各种场景下 TDengine 都能最大效率的工作,TDengine 建议将不同数据特征的表创建在不同的库里,因为每个库可以配置不同的存储策略。创建一个库时,除 SQL 标准的选项外,应用还可以指定保留时长、副本数、内存块个数、时间精度、文件块里最大最小记录条数、是否压缩、一个数据文件覆盖的天数等多种参数。比如:
+不同类型的数据采集点往往具有不同的数据特征,包括数据采集频率的高低,数据保留时间的长短,副本的数目,数据块的大小,是否允许更新数据等等。为了在各种场景下 TDengine 都能最大效率的工作,TDengine 建议将不同数据特征的表创建在不同的库里,因为每个库可以配置不同的存储策略。创建一个库时,除 SQL 标准的选项外,还可以指定保留时长、副本数、内存块个数、时间精度、文件块里最大最小记录条数、是否压缩、一个数据文件覆盖的天数等多种参数。比如:
```sql
CREATE DATABASE power KEEP 365 DAYS 10 BLOCKS 6 UPDATE 1;
```
-上述语句将创建一个名为 power 的库,这个库的数据将保留 365 天(超过 365 天将被自动删除),每 10 天一个数据文件,内存块数为 6,允许更新数据。详细的语法及参数请见 [数据库管理](/reference/taos-sql/database) 章节。
+上述语句将创建一个名为 power 的库,这个库的数据将保留 365 天(超过 365 天将被自动删除),每 10 天一个数据文件,内存块数为 6,允许更新数据。详细的语法及参数请见 [数据库管理](/taos-sql/database) 章节。
创建库之后,需要使用 SQL 命令 `USE` 将当前库切换过来,例如:
@@ -24,7 +27,7 @@ USE power;
:::note
-- 任何一张表或超级表是属于一个库的,在创建表之前,必须先创建库。
+- 任何一张表或超级表必须属于某个库,在创建表之前,必须先创建库。
- 处于两个不同库的表是不能进行 JOIN 操作的。
- 创建并插入记录、查询历史记录的时候,均需要指定时间戳。
@@ -42,11 +45,11 @@ CREATE STABLE meters (ts timestamp, current float, voltage int, phase float) TAG
这一指令中的 STABLE 关键字,在 2.0.15 之前的版本中需写作 TABLE 。
:::
-与创建普通表一样,创建表时,需要提供表名(示例中为 meters),表结构 Schema,即数据列的定义。第一列必须为时间戳(示例中为 ts),其他列为采集的物理量(示例中为 current, voltage, phase),数据类型可以为整型、浮点型、字符串等。除此之外,还需要提供标签的 schema (示例中为 location, groupId),标签的数据类型可以为整型、浮点型、字符串等。采集点的静态属性往往可以作为标签,比如采集点的地理位置、设备型号、设备组 ID、管理员 ID 等等。标签的 schema 可以事后增加、删除、修改。具体定义以及细节请见 [TAOS SQL 的超级表管理](/reference/taos-sql/stable) 章节。
+与创建普通表一样,创建超级表时,需要提供表名(示例中为 meters),表结构 Schema,即数据列的定义。第一列必须为时间戳(示例中为 ts),其他列为采集的物理量(示例中为 current, voltage, phase),数据类型可以为整型、浮点型、字符串等。除此之外,还需要提供标签的 schema (示例中为 location, groupId),标签的数据类型可以为整型、浮点型、字符串等。采集点的静态属性往往可以作为标签,比如采集点的地理位置、设备型号、设备组 ID、管理员 ID 等等。标签的 schema 可以事后增加、删除、修改。具体定义以及细节请见 [TAOS SQL 的超级表管理](/taos-sql/stable) 章节。
-每一种类型的数据采集点需要建立一个超级表,因此一个物联网系统,往往会有多个超级表。对于电网,我们就需要对智能电表、变压器、母线、开关等都建立一个超级表。在物联网中,一个设备就可能有多个数据采集点(比如一台风力发电的风机,有的采集点采集电流、电压等电参数,有的采集点采集温度、湿度、风向等环境参数),这个时候,对这一类型的设备,需要建立多张超级表。一张超级表里包含的采集物理量必须是同时采集的(时间戳是一致的)。
+每一种类型的数据采集点需要建立一个超级表,因此一个物联网系统,往往会有多个超级表。对于电网,我们就需要对智能电表、变压器、母线、开关等都建立一个超级表。在物联网中,一个设备就可能有多个数据采集点(比如一台风力发电的风机,有的采集点采集电流、电压等电参数,有的采集点采集温度、湿度、风向等环境参数),这个时候,对这一类型的设备,需要建立多张超级表。
-一张超级表最多容许 1024 列,如果一个采集点采集的物理量个数超过 1024,需要建多张超级表来处理。一个系统可以有多个 DB,一个 DB 里可以有一到多个超级表。(从 2.1.7.0 版本开始,列数限制由 1024 列放宽到了 4096 列。)
+一张超级表最多容许 4096 列 (在 2.1.7.0 版本之前,列数限制为 1024 列),如果一个采集点采集的物理量个数超过 4096,需要建多张超级表来处理。一个系统可以有多个 DB,一个 DB 里可以有一到多个超级表。
## 创建表
@@ -56,10 +59,10 @@ TDengine 对每个数据采集点需要独立建表。与标准的关系型数
CREATE TABLE d1001 USING meters TAGS ("Beijing.Chaoyang", 2);
```
-其中 d1001 是表名,meters 是超级表的表名,后面紧跟标签 Location 的具体标签值 ”Beijing.Chaoyang",标签 groupId 的具体标签值 2。虽然在创建表时,需要指定标签值,但可以事后修改。详细细则请见 [TAOS SQL 的表管理](/reference/taos-sql/table) 章节。
+其中 d1001 是表名,meters 是超级表的表名,后面紧跟标签 Location 的具体标签值 ”Beijing.Chaoyang",标签 groupId 的具体标签值 2。虽然在创建表时,需要指定标签值,但可以事后修改。详细细则请见 [TAOS SQL 的表管理](/taos-sql/table) 章节。
:::warning
-目前 TDengine 没有从技术层面限制使用一个 database (dbA)的超级表作为模板建立另一个 database (dbB)的子表,后续会禁止这种用法,不建议使用这种方法建表。
+目前 TDengine 没有从技术层面限制使用一个 database (db1) 的超级表作为模板建立另一个 database (db2) 的子表,后续会禁止这种用法,不建议使用这种方法建表。
:::
@@ -67,7 +70,7 @@ TDengine 建议将数据采集点的全局唯一 ID 作为表名(比如设备序
### 自动建表
-在某些特殊场景中,用户在写数据时并不确定某个数据采集点的表是否存在,此时可在写入数据时使用自动建表语法来创建不存在的表,若该表已存在则不会建立新表。比如:
+在某些特殊场景中,用户在写数据时并不确定某个数据采集点的表是否存在,此时可在写入数据时使用自动建表语法来创建不存在的表,若该表已存在则不会建立新表且后面的 USING 语句被忽略。比如:
```sql
INSERT INTO d1001 USING meters TAGS ("Beijng.Chaoyang", 2) VALUES (now, 10.2, 219, 0.32);
@@ -75,7 +78,7 @@ INSERT INTO d1001 USING meters TAGS ("Beijng.Chaoyang", 2) VALUES (now, 10.2, 21
上述 SQL 语句将记录`(now, 10.2, 219, 0.32)`插入表 d1001。如果表 d1001 还未创建,则使用超级表 meters 做模板自动创建,同时打上标签值 `"Beijing.Chaoyang", 2`。
-关于自动建表的详细语法请参见 [插入记录时自动建表](reference/taos-sql/insert#插入记录时自动建表) 章节。
+关于自动建表的详细语法请参见 [插入记录时自动建表](/taos-sql/insert#插入记录时自动建表) 章节。
## 多列模型 vs 单列模型
diff --git a/docs-cn/04-develop/03-insert-data/01-sql-writing.mdx b/docs-cn/04-develop/03-insert-data/01-sql-writing.mdx
new file mode 100644
index 0000000000000000000000000000000000000000..7a4ab3eb72f6bf41e863ba26aa7ef97b503349d8
--- /dev/null
+++ b/docs-cn/04-develop/03-insert-data/01-sql-writing.mdx
@@ -0,0 +1,129 @@
+---
+title: SQL 写入
+---
+
+import Tabs from "@theme/Tabs";
+import TabItem from "@theme/TabItem";
+import JavaSQL from "./_java_sql.mdx";
+import JavaStmt from "./_java_stmt.mdx";
+import PySQL from "./_py_sql.mdx";
+import PyStmt from "./_py_stmt.mdx";
+import GoSQL from "./_go_sql.mdx";
+import GoStmt from "./_go_stmt.mdx";
+import RustSQL from "./_rust_sql.mdx";
+import RustStmt from "./_rust_stmt.mdx";
+import NodeSQL from "./_js_sql.mdx";
+import NodeStmt from "./_js_stmt.mdx";
+import CsSQL from "./_cs_sql.mdx";
+import CsStmt from "./_cs_stmt.mdx";
+import CSQL from "./_c_sql.mdx";
+import CStmt from "./_c_stmt.mdx";
+
+## SQL 写入简介
+
+应用通过连接器执行 INSERT 语句来插入数据,用户还可以通过 TAOS Shell,手动输入 INSERT 语句插入数据。
+
+### 一次写入一条
+下面这条 INSERT 就将一条记录写入到表 d1001 中:
+
+```sql
+INSERT INTO d1001 VALUES (1538548685000, 10.3, 219, 0.31);
+```
+
+### 一次写入多条
+
+TDengine 支持一次写入多条记录,比如下面这条命令就将两条记录写入到表 d1001 中:
+
+```sql
+INSERT INTO d1001 VALUES (1538548684000, 10.2, 220, 0.23) (1538548696650, 10.3, 218, 0.25);
+```
+
+### 一次写入多表
+
+TDengine 也支持一次向多个表写入数据,比如下面这条命令就向 d1001 写入两条记录,向 d1002 写入一条记录:
+
+```sql
+INSERT INTO d1001 VALUES (1538548685000, 10.3, 219, 0.31) (1538548695000, 12.6, 218, 0.33) d1002 VALUES (1538548696800, 12.3, 221, 0.31);
+```
+
+详细的 SQL INSERT 语法规则参考 [TAOS SQL 的数据写入](/taos-sql/insert)。
+
+:::info
+
+- 要提高写入效率,需要批量写入。一批写入的记录条数越多,插入效率就越高。但一条记录不能超过 16K,一条 SQL 语句总长度不能超过 1M 。
+- TDengine 支持多线程同时写入,要进一步提高写入速度,一个客户端需要打开 20 个以上的线程同时写。但线程数达到一定数量后,无法再提高,甚至还会下降,因为线程频繁切换,带来额外开销。
+
+:::
+
+:::warning
+
+- 对同一张表,如果新插入记录的时间戳已经存在,默认情形下(UPDATE=0)新记录将被直接抛弃,也就是说,在一张表里,时间戳必须是唯一的。如果应用自动生成记录,很有可能生成的时间戳是一样的,这样,成功插入的记录条数会小于应用插入的记录条数。如果在创建数据库时使用了 UPDATE 1 选项,插入相同时间戳的新记录将覆盖原有记录。
+- 写入的数据的时间戳必须大于当前时间减去配置参数 keep 的时间。如果 keep 配置为 3650 天,那么无法写入比 3650 天还早的数据。写入数据的时间戳也不能大于当前时间加配置参数 days。如果 days 为 2,那么无法写入比当前时间还晚 2 天的数据。
+
+:::
+
+## 示例程序
+
+### 普通 SQL 写入
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+:::note
+
+1. 无论 RESTful 方式建立连接还是本地驱动方式建立连接,以上示例代码都能正常工作。
+2. 唯一需要注意的是:由于 RESTful 接口无状态, 不能使用 `use db` 语句来切换数据库, 所以在上面示例中使用了`dbName.tbName`指定表名。
+
+:::
+
+### 参数绑定写入
+
+TDengine 也提供了支持参数绑定的 Prepare API,与 MySQL 类似,这些 API 目前也仅支持用问号 `?` 来代表待绑定的参数。从 2.1.1.0 和 2.1.2.0 版本开始,TDengine 大幅改进了参数绑定接口对数据写入(INSERT)场景的支持。这样在通过参数绑定接口写入数据时,就避免了 SQL 语法解析的资源消耗,从而在绝大多数情况下显著提升写入性能。
+
+需要注意的是,只有使用原生连接的连接器,才能使用参数绑定功能。
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/docs-cn/04-develop/03-insert-data/02-influxdb-line.mdx b/docs-cn/04-develop/03-insert-data/02-influxdb-line.mdx
new file mode 100644
index 0000000000000000000000000000000000000000..dedd7f0e70834e21257bda78dd184f5ddc520160
--- /dev/null
+++ b/docs-cn/04-develop/03-insert-data/02-influxdb-line.mdx
@@ -0,0 +1,70 @@
+---
+sidebar_label: InfluxDB 行协议
+title: InfluxDB 行协议
+---
+
+import Tabs from "@theme/Tabs";
+import TabItem from "@theme/TabItem";
+import JavaLine from "./_java_line.mdx";
+import PyLine from "./_py_line.mdx";
+import GoLine from "./_go_line.mdx";
+import RustLine from "./_rust_line.mdx";
+import NodeLine from "./_js_line.mdx";
+import CsLine from "./_cs_line.mdx";
+import CLine from "./_c_line.mdx";
+
+## 协议介绍
+
+InfluxDB Line 协议采用一行字符串来表示一行数据。分为四部分:
+
+```
+measurement,tag_set field_set timestamp
+```
+
+- measurement 将作为超级表名。它与 tag_set 之间使用一个英文逗号来分隔。
+- tag_set 将作为标签数据,其格式形如 `=,=`,也即可以使用英文逗号来分隔多个标签数据。它与 field_set 之间使用一个半角空格来分隔。
+- field_set 将作为普通列数据,其格式形如 `=,=`,同样是使用英文逗号来分隔多个普通列的数据。它与 timestamp 之间使用一个半角空格来分隔。
+- timestamp 即本行数据对应的主键时间戳。
+
+例如:
+
+```
+meters,location=Beijing.Haidian,groupid=2 current=13.4,voltage=223,phase=0.29 1648432611249500
+```
+
+:::note
+
+- tag_set 中的所有的数据自动转化为 nchar 数据类型;
+- field_set 中的每个数据项都需要对自身的数据类型进行描述, 比如 1.2f32 代表 float 类型的数值 1.2, 如果不带类型后缀会被当作 double 处理;
+- timestamp 支持多种时间精度。写入数据的时候需要用参数指定时间精度,支持从小时到纳秒的 6 种时间精度。
+
+:::
+
+要了解更多可参考:[InfluxDB Line 协议官方文档](https://docs.influxdata.com/influxdb/v2.0/reference/syntax/line-protocol/) 和 [TDengine 无模式写入参考指南](/reference/schemaless/#无模式写入行协议)
+
+
+## 示例代码
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/docs-cn/04-develop/03-insert-data/03-opentsdb-telnet.mdx b/docs-cn/04-develop/03-insert-data/03-opentsdb-telnet.mdx
new file mode 100644
index 0000000000000000000000000000000000000000..7efb3e1cf967e6d135e7999b4f0dc191b93a884b
--- /dev/null
+++ b/docs-cn/04-develop/03-insert-data/03-opentsdb-telnet.mdx
@@ -0,0 +1,84 @@
+---
+sidebar_label: OpentsDB 行协议
+title: OpentsDB 行协议
+---
+
+import Tabs from "@theme/Tabs";
+import TabItem from "@theme/TabItem";
+import JavaTelnet from "./_java_opts_telnet.mdx";
+import PyTelnet from "./_py_opts_telnet.mdx";
+import GoTelnet from "./_go_opts_telnet.mdx";
+import RustTelnet from "./_rust_opts_telnet.mdx";
+import NodeTelnet from "./_js_opts_telnet.mdx";
+import CsTelnet from "./_cs_opts_telnet.mdx";
+import CTelnet from "./_c_opts_telnet.mdx";
+
+## 协议介绍
+
+OpentsDB 行协议同样采用一行字符串来表示一行数据。OpentsDB 采用的是单列模型,因此一行只能包含一个普通数据列。标签列依然可以有多个。分为四部分,具体格式约定如下:
+
+```txt
+ =[ =]
+```
+
+- metric 将作为超级表名。
+- timestamp 本行数据对应的时间戳。根据时间戳的长度自动识别时间精度。支持秒和毫秒两种时间精度
+- value 度量值,必须为一个数值。对应的列名也是 “value”。
+- 最后一部分是标签集, 用空格分隔不同标签, 所有标签自动转化为 nchar 数据类型;
+
+例如:
+
+```txt
+meters.current 1648432611250 11.3 location=Beijing.Haidian groupid=3
+```
+
+参考[OpenTSDB Telnet API文档](http://opentsdb.net/docs/build/html/api_telnet/put.html)。
+
+## 示例代码
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+以上示例代码会自动创建 2 个超级表, 每个超级表有 4 条数据。
+
+```cmd
+taos> use test;
+Database changed.
+
+taos> show stables;
+ name | created_time | columns | tags | tables |
+============================================================================================
+ meters.current | 2022-03-30 17:04:10.877 | 2 | 2 | 2 |
+ meters.voltage | 2022-03-30 17:04:10.882 | 2 | 2 | 2 |
+Query OK, 2 row(s) in set (0.002544s)
+
+taos> select tbname, * from `meters.current`;
+ tbname | ts | value | groupid | location |
+==================================================================================================================================
+ t_0e7bcfa21a02331c06764f275... | 2022-03-28 09:56:51.249 | 10.800000000 | 3 | Beijing.Haidian |
+ t_0e7bcfa21a02331c06764f275... | 2022-03-28 09:56:51.250 | 11.300000000 | 3 | Beijing.Haidian |
+ t_7e7b26dd860280242c6492a16... | 2022-03-28 09:56:51.249 | 10.300000000 | 2 | Beijing.Chaoyang |
+ t_7e7b26dd860280242c6492a16... | 2022-03-28 09:56:51.250 | 12.600000000 | 2 | Beijing.Chaoyang |
+Query OK, 4 row(s) in set (0.005399s)
+```
diff --git a/docs-cn/04-develop/03-insert-data/04-opentsdb-json.mdx b/docs-cn/04-develop/03-insert-data/04-opentsdb-json.mdx
new file mode 100644
index 0000000000000000000000000000000000000000..0767dba0c12cca24c0bcb55c6b95a0392772cafa
--- /dev/null
+++ b/docs-cn/04-develop/03-insert-data/04-opentsdb-json.mdx
@@ -0,0 +1,99 @@
+---
+sidebar_label: OpentsDB JSON 格式协议
+title: OpentsDB JSON 格式协议
+---
+
+import Tabs from "@theme/Tabs";
+import TabItem from "@theme/TabItem";
+import JavaJson from "./_java_opts_json.mdx";
+import PyJson from "./_py_opts_json.mdx";
+import GoJson from "./_go_opts_json.mdx";
+import RustJson from "./_rust_opts_json.mdx";
+import NodeJson from "./_js_opts_json.mdx";
+import CsJson from "./_cs_opts_json.mdx";
+import CJson from "./_c_opts_json.mdx";
+
+## 协议介绍
+
+OpentsDB JSON 格式协议采用一个 JSON 字符串表示一行或多行数据。例如:
+
+```json
+[
+ {
+ "metric": "sys.cpu.nice",
+ "timestamp": 1346846400,
+ "value": 18,
+ "tags": {
+ "host": "web01",
+ "dc": "lga"
+ }
+ },
+ {
+ "metric": "sys.cpu.nice",
+ "timestamp": 1346846400,
+ "value": 9,
+ "tags": {
+ "host": "web02",
+ "dc": "lga"
+ }
+ }
+]
+```
+
+与 OpentsDB 行协议类似, metric 将作为超级表名, timestamp 表示时间戳,value 表示度量值, tags 表示标签集。
+
+
+参考[OpenTSDB HTTP API文档](http://opentsdb.net/docs/build/html/api_http/put.html)。
+
+:::note
+- 对于 JSON 格式协议,TDengine 并不会自动把所有标签转成 nchar 类型, 字符串将将转为 nchar 类型, 数值将同样转换为 double 类型。
+- TDengine 只接收 JSON **数组格式**的字符串,即使一行数据也需要转换成数组形式。
+
+:::
+
+## 示例代码
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+以上示例代码会自动创建 2 个超级表, 每个超级表有 2 条数据。
+
+```cmd
+taos> use test;
+Database changed.
+
+taos> show stables;
+ name | created_time | columns | tags | tables |
+============================================================================================
+ meters.current | 2022-03-29 16:05:25.193 | 2 | 2 | 1 |
+ meters.voltage | 2022-03-29 16:05:25.200 | 2 | 2 | 1 |
+Query OK, 2 row(s) in set (0.001954s)
+
+taos> select * from `meters.current`;
+ ts | value | groupid | location |
+===================================================================================================================
+ 2022-03-28 09:56:51.249 | 10.300000000 | 2.000000000 | Beijing.Chaoyang |
+ 2022-03-28 09:56:51.250 | 12.600000000 | 2.000000000 | Beijing.Chaoyang |
+Query OK, 2 row(s) in set (0.004076s)
+```
diff --git a/docs-cn/04-develop/03-insert-data/_c_line.mdx b/docs-cn/04-develop/03-insert-data/_c_line.mdx
new file mode 100644
index 0000000000000000000000000000000000000000..5ef2e9af774c54e9f090357286f83d2280c2ab11
--- /dev/null
+++ b/docs-cn/04-develop/03-insert-data/_c_line.mdx
@@ -0,0 +1,3 @@
+```c
+{{#include docs-examples/c/line_example.c:main}}
+```
\ No newline at end of file
diff --git a/docs-cn/04-develop/03-insert-data/_c_opts_json.mdx b/docs-cn/04-develop/03-insert-data/_c_opts_json.mdx
new file mode 100644
index 0000000000000000000000000000000000000000..22ad2e0122797248a372734aac0f3a16a1356530
--- /dev/null
+++ b/docs-cn/04-develop/03-insert-data/_c_opts_json.mdx
@@ -0,0 +1,3 @@
+```c
+{{#include docs-examples/c/json_protocol_example.c:main}}
+```
\ No newline at end of file
diff --git a/docs-cn/04-develop/03-insert-data/_c_opts_telnet.mdx b/docs-cn/04-develop/03-insert-data/_c_opts_telnet.mdx
new file mode 100644
index 0000000000000000000000000000000000000000..508d7bc98a149f49766bcd0a474ffe226cbe30bb
--- /dev/null
+++ b/docs-cn/04-develop/03-insert-data/_c_opts_telnet.mdx
@@ -0,0 +1,3 @@
+```c
+{{#include docs-examples/c/telnet_line_example.c:main}}
+```
\ No newline at end of file
diff --git a/docs-cn/04-develop/03-insert-data/_c_sql.mdx b/docs-cn/04-develop/03-insert-data/_c_sql.mdx
new file mode 100644
index 0000000000000000000000000000000000000000..f4153fd2c427677a338d0c377663d0335f2672f0
--- /dev/null
+++ b/docs-cn/04-develop/03-insert-data/_c_sql.mdx
@@ -0,0 +1,3 @@
+```c
+{{#include docs-examples/c/insert_example.c}}
+```
\ No newline at end of file
diff --git a/docs-cn/04-develop/03-insert-data/_c_stmt.mdx b/docs-cn/04-develop/03-insert-data/_c_stmt.mdx
new file mode 100644
index 0000000000000000000000000000000000000000..01ac067519a2bd224e313fd70169722ba5f20413
--- /dev/null
+++ b/docs-cn/04-develop/03-insert-data/_c_stmt.mdx
@@ -0,0 +1,6 @@
+```c title=一次绑定一行
+{{#include docs-examples/c/stmt_example.c}}
+```
+```c title=一次绑定多行 72:117
+{{#include docs-examples/c/multi_bind_example.c}}
+```
\ No newline at end of file
diff --git a/docs-cn/04-develop/03-insert-data/_category_.yml b/docs-cn/04-develop/03-insert-data/_category_.yml
new file mode 100644
index 0000000000000000000000000000000000000000..1255095431329864a351b41b639ceb7d1cb40531
--- /dev/null
+++ b/docs-cn/04-develop/03-insert-data/_category_.yml
@@ -0,0 +1,5 @@
+label: 写入数据
+link:
+ type: generated-index
+ slug: /insert-data/
+ description: "TDengine 支持多种写入协议,包括 SQL,InfluxDB Line 协议, OpentsDB Telnet 协议,OpentsDB JSON 格式协议。数据可以单条插入,也可以批量插入,可以插入一个数据采集点的数据,也可以同时插入多个数据采集点的数据。同时,TDengine 支持多线程插入,支持时间乱序数据插入,也支持历史数据插入。InfluxDB Line 协议、OpentsDB Telnet 协议和 OpentsDB JSON 格式协议是 TDengine 支持的三种无模式写入协议。使用无模式方式写入无需提前创建超级表和子表,并且引擎能自适用数据对表结构做调整。"
diff --git a/docs-cn/04-develop/03-insert-data/_cs_line.mdx b/docs-cn/04-develop/03-insert-data/_cs_line.mdx
new file mode 100644
index 0000000000000000000000000000000000000000..9c275ee3d7c7a1e52fbb34dbae922004543ee3ce
--- /dev/null
+++ b/docs-cn/04-develop/03-insert-data/_cs_line.mdx
@@ -0,0 +1,3 @@
+```csharp
+{{#include docs-examples/csharp/InfluxDBLineExample.cs}}
+```
diff --git a/docs-cn/04-develop/03-insert-data/_cs_opts_json.mdx b/docs-cn/04-develop/03-insert-data/_cs_opts_json.mdx
new file mode 100644
index 0000000000000000000000000000000000000000..3d538b8506b298241faecd8098f89571359135c9
--- /dev/null
+++ b/docs-cn/04-develop/03-insert-data/_cs_opts_json.mdx
@@ -0,0 +1,3 @@
+```csharp
+{{#include docs-examples/csharp/OptsJsonExample.cs}}
+```
diff --git a/docs-cn/04-develop/03-insert-data/_cs_opts_telnet.mdx b/docs-cn/04-develop/03-insert-data/_cs_opts_telnet.mdx
new file mode 100644
index 0000000000000000000000000000000000000000..c53bf3d7233115351e5af03b7d9e6318aa4a0da6
--- /dev/null
+++ b/docs-cn/04-develop/03-insert-data/_cs_opts_telnet.mdx
@@ -0,0 +1,3 @@
+```csharp
+{{#include docs-examples/csharp/OptsTelnetExample.cs}}
+```
diff --git a/docs-cn/04-develop/03-insert-data/_cs_sql.mdx b/docs-cn/04-develop/03-insert-data/_cs_sql.mdx
new file mode 100644
index 0000000000000000000000000000000000000000..c7688bfbe77a1135424d829fe9b29fbb1bc93ae2
--- /dev/null
+++ b/docs-cn/04-develop/03-insert-data/_cs_sql.mdx
@@ -0,0 +1,3 @@
+```csharp
+{{#include docs-examples/csharp/SQLInsertExample.cs}}
+```
diff --git a/docs-cn/04-develop/03-insert-data/_cs_stmt.mdx b/docs-cn/04-develop/03-insert-data/_cs_stmt.mdx
new file mode 100644
index 0000000000000000000000000000000000000000..97c3b910ffeb9e0c88fc143a02014115e819c147
--- /dev/null
+++ b/docs-cn/04-develop/03-insert-data/_cs_stmt.mdx
@@ -0,0 +1,3 @@
+```csharp
+{{#include docs-examples/csharp/StmtInsertExample.cs}}
+```
diff --git a/docs-cn/04-develop/03-insert-data/_go_line.mdx b/docs-cn/04-develop/03-insert-data/_go_line.mdx
new file mode 100644
index 0000000000000000000000000000000000000000..cd225945b70e28bef2ca7fdaf0d9be0ad7ffc18c
--- /dev/null
+++ b/docs-cn/04-develop/03-insert-data/_go_line.mdx
@@ -0,0 +1,3 @@
+```go
+{{#include docs-examples/go/insert/line/main.go}}
+```
diff --git a/docs-cn/04-develop/03-insert-data/_go_opts_json.mdx b/docs-cn/04-develop/03-insert-data/_go_opts_json.mdx
new file mode 100644
index 0000000000000000000000000000000000000000..0c0d3e5b6330e046988cdd02234285ec67e92f01
--- /dev/null
+++ b/docs-cn/04-develop/03-insert-data/_go_opts_json.mdx
@@ -0,0 +1,3 @@
+```go
+{{#include docs-examples/go/insert/json/main.go}}
+```
diff --git a/docs-cn/04-develop/03-insert-data/_go_opts_telnet.mdx b/docs-cn/04-develop/03-insert-data/_go_opts_telnet.mdx
new file mode 100644
index 0000000000000000000000000000000000000000..d5ca40cc146e62412476289853e8e2739e0e9e4b
--- /dev/null
+++ b/docs-cn/04-develop/03-insert-data/_go_opts_telnet.mdx
@@ -0,0 +1,3 @@
+```go
+{{#include docs-examples/go/insert/telnet/main.go}}
+```
diff --git a/docs-cn/04-develop/03-insert-data/_go_sql.mdx b/docs-cn/04-develop/03-insert-data/_go_sql.mdx
new file mode 100644
index 0000000000000000000000000000000000000000..613a65add1741eb763a4b24e65d180d05f7d670f
--- /dev/null
+++ b/docs-cn/04-develop/03-insert-data/_go_sql.mdx
@@ -0,0 +1,3 @@
+```go
+{{#include docs-examples/go/insert/sql/main.go}}
+```
diff --git a/docs-cn/04-develop/03-insert-data/_go_stmt.mdx b/docs-cn/04-develop/03-insert-data/_go_stmt.mdx
new file mode 100644
index 0000000000000000000000000000000000000000..7bb6792d6df5b250850bd0a0021ecceba994aa09
--- /dev/null
+++ b/docs-cn/04-develop/03-insert-data/_go_stmt.mdx
@@ -0,0 +1,8 @@
+```go
+{{#include docs-examples/go/insert/stmt/main.go}}
+```
+
+:::tip
+driver-go 的模块 `github.com/taosdata/driver-go/v2/wrapper` 是 C 接口的底层封装。使用这个模块也可以实现参数绑定写入。
+
+:::
diff --git a/docs-cn/04-develop/03-insert-data/_java_line.mdx b/docs-cn/04-develop/03-insert-data/_java_line.mdx
new file mode 100644
index 0000000000000000000000000000000000000000..2e59a5d4701b2a2ab04ec5711845dc5c80067a1e
--- /dev/null
+++ b/docs-cn/04-develop/03-insert-data/_java_line.mdx
@@ -0,0 +1,3 @@
+```java
+{{#include docs-examples/java/src/main/java/com/taos/example/LineProtocolExample.java}}
+```
diff --git a/docs-cn/04-develop/03-insert-data/_java_opts_json.mdx b/docs-cn/04-develop/03-insert-data/_java_opts_json.mdx
new file mode 100644
index 0000000000000000000000000000000000000000..826a1a07d9405cb193849f9d21e5444f68517914
--- /dev/null
+++ b/docs-cn/04-develop/03-insert-data/_java_opts_json.mdx
@@ -0,0 +1,3 @@
+```java
+{{#include docs-examples/java/src/main/java/com/taos/example/JSONProtocolExample.java}}
+```
diff --git a/docs-cn/04-develop/03-insert-data/_java_opts_telnet.mdx b/docs-cn/04-develop/03-insert-data/_java_opts_telnet.mdx
new file mode 100644
index 0000000000000000000000000000000000000000..954dcc1a482a150dea0b190e1e0593adbfbde796
--- /dev/null
+++ b/docs-cn/04-develop/03-insert-data/_java_opts_telnet.mdx
@@ -0,0 +1,3 @@
+```java
+{{#include docs-examples/java/src/main/java/com/taos/example/TelnetLineProtocolExample.java}}
+```
diff --git a/docs-cn/04-develop/03-insert-data/_java_sql.mdx b/docs-cn/04-develop/03-insert-data/_java_sql.mdx
new file mode 100644
index 0000000000000000000000000000000000000000..a863378defe43b1f22c1f98087a34f053a7d6619
--- /dev/null
+++ b/docs-cn/04-develop/03-insert-data/_java_sql.mdx
@@ -0,0 +1,3 @@
+```java
+{{#include docs-examples/java/src/main/java/com/taos/example/RestInsertExample.java:insert}}
+```
\ No newline at end of file
diff --git a/docs-cn/04-develop/03-insert-data/_java_stmt.mdx b/docs-cn/04-develop/03-insert-data/_java_stmt.mdx
new file mode 100644
index 0000000000000000000000000000000000000000..54443e535fa84bdf8dc9161ed4ad00f50b26266c
--- /dev/null
+++ b/docs-cn/04-develop/03-insert-data/_java_stmt.mdx
@@ -0,0 +1,3 @@
+```java
+{{#include docs-examples/java/src/main/java/com/taos/example/StmtInsertExample.java}}
+```
diff --git a/docs-cn/04-develop/03-insert-data/_js_line.mdx b/docs-cn/04-develop/03-insert-data/_js_line.mdx
new file mode 100644
index 0000000000000000000000000000000000000000..172c9bc17b8cff8b2620720b235a9c8e69bd4197
--- /dev/null
+++ b/docs-cn/04-develop/03-insert-data/_js_line.mdx
@@ -0,0 +1,3 @@
+```js
+{{#include docs-examples/node/nativeexample/influxdb_line_example.js}}
+```
diff --git a/docs-cn/04-develop/03-insert-data/_js_opts_json.mdx b/docs-cn/04-develop/03-insert-data/_js_opts_json.mdx
new file mode 100644
index 0000000000000000000000000000000000000000..20ac9ec91e8dc6675828b16d7da0acb09afd3b5f
--- /dev/null
+++ b/docs-cn/04-develop/03-insert-data/_js_opts_json.mdx
@@ -0,0 +1,3 @@
+```js
+{{#include docs-examples/node/nativeexample/opentsdb_json_example.js}}
+```
diff --git a/docs-cn/04-develop/03-insert-data/_js_opts_telnet.mdx b/docs-cn/04-develop/03-insert-data/_js_opts_telnet.mdx
new file mode 100644
index 0000000000000000000000000000000000000000..c3c8c40bd642f4f443de88e3db006ad50724d514
--- /dev/null
+++ b/docs-cn/04-develop/03-insert-data/_js_opts_telnet.mdx
@@ -0,0 +1,3 @@
+```js
+{{#include docs-examples/node/nativeexample/opentsdb_telnet_example.js}}
+```
diff --git a/docs-cn/04-develop/03-insert-data/_js_sql.mdx b/docs-cn/04-develop/03-insert-data/_js_sql.mdx
new file mode 100644
index 0000000000000000000000000000000000000000..f5e17c76892a57a94192a95451b508b1c176c984
--- /dev/null
+++ b/docs-cn/04-develop/03-insert-data/_js_sql.mdx
@@ -0,0 +1,3 @@
+```js
+{{#include docs-examples/node/nativeexample/insert_example.js}}
+```
diff --git a/docs-cn/04-develop/03-insert-data/_js_stmt.mdx b/docs-cn/04-develop/03-insert-data/_js_stmt.mdx
new file mode 100644
index 0000000000000000000000000000000000000000..17a6c9785c7dc1e3c3fa6a59982913f1f139f9c2
--- /dev/null
+++ b/docs-cn/04-develop/03-insert-data/_js_stmt.mdx
@@ -0,0 +1,12 @@
+```js title=一次绑定一行
+{{#include docs-examples/node/nativeexample/param_bind_example.js}}
+```
+
+```js title=一次绑定多行
+{{#include docs-examples/node/nativeexample/multi_bind_example.js:insertData}}
+```
+
+:::info
+一次绑定一行效率不如一次绑定多行,但支持非 INSERT 语句。一次绑定多行效率更高,但仅支持 INSERT 语句。
+
+:::
diff --git a/docs-cn/04-develop/03-insert-data/_py_line.mdx b/docs-cn/04-develop/03-insert-data/_py_line.mdx
new file mode 100644
index 0000000000000000000000000000000000000000..d3bb1ebb3403b53fa43bfc9d5d1a0de9764d7583
--- /dev/null
+++ b/docs-cn/04-develop/03-insert-data/_py_line.mdx
@@ -0,0 +1,3 @@
+```py
+{{#include docs-examples/python/line_protocol_example.py}}
+```
diff --git a/docs-cn/04-develop/03-insert-data/_py_opts_json.mdx b/docs-cn/04-develop/03-insert-data/_py_opts_json.mdx
new file mode 100644
index 0000000000000000000000000000000000000000..cfbfe13ccfdb4f3f34b77300812863fdf70d0f59
--- /dev/null
+++ b/docs-cn/04-develop/03-insert-data/_py_opts_json.mdx
@@ -0,0 +1,3 @@
+```py
+{{#include docs-examples/python/json_protocol_example.py}}
+```
diff --git a/docs-cn/04-develop/03-insert-data/_py_opts_telnet.mdx b/docs-cn/04-develop/03-insert-data/_py_opts_telnet.mdx
new file mode 100644
index 0000000000000000000000000000000000000000..14bc65a7a3da815abadf7f25c8deffeac666c8d7
--- /dev/null
+++ b/docs-cn/04-develop/03-insert-data/_py_opts_telnet.mdx
@@ -0,0 +1,3 @@
+```py
+{{#include docs-examples/python/telnet_line_protocol_example.py}}
+```
diff --git a/docs-cn/04-develop/03-insert-data/_py_sql.mdx b/docs-cn/04-develop/03-insert-data/_py_sql.mdx
new file mode 100644
index 0000000000000000000000000000000000000000..c0e15b8ec115b9244d50a47c9eafec04bcfdd70c
--- /dev/null
+++ b/docs-cn/04-develop/03-insert-data/_py_sql.mdx
@@ -0,0 +1,3 @@
+```py
+{{#include docs-examples/python/native_insert_example.py}}
+```
diff --git a/docs-cn/04-develop/03-insert-data/_py_stmt.mdx b/docs-cn/04-develop/03-insert-data/_py_stmt.mdx
new file mode 100644
index 0000000000000000000000000000000000000000..8241ea86bc64ac64d842dc0a6cddc0eae0399503
--- /dev/null
+++ b/docs-cn/04-develop/03-insert-data/_py_stmt.mdx
@@ -0,0 +1,12 @@
+```py title=一次绑定一行
+{{#include docs-examples/python/bind_param_example.py}}
+```
+
+```py title=一次绑定多行
+{{#include docs-examples/python/multi_bind_example.py:bind_batch}}
+```
+
+:::info
+一次绑定一行效率不如一次绑定多行,但支持非 INSERT 语句。一次绑定多行效率更高,但仅支持 INSERT 语句。
+
+:::
\ No newline at end of file
diff --git a/docs-cn/04-develop/03-insert-data/_rust_line.mdx b/docs-cn/04-develop/03-insert-data/_rust_line.mdx
new file mode 100644
index 0000000000000000000000000000000000000000..696ddb7b854751b8dee01047066f97f74212933f
--- /dev/null
+++ b/docs-cn/04-develop/03-insert-data/_rust_line.mdx
@@ -0,0 +1,3 @@
+```rust
+{{#include docs-examples/rust/schemalessexample/examples/influxdb_line_example.rs}}
+```
diff --git a/docs-cn/04-develop/03-insert-data/_rust_opts_json.mdx b/docs-cn/04-develop/03-insert-data/_rust_opts_json.mdx
new file mode 100644
index 0000000000000000000000000000000000000000..97d9052dacd1894cc7548a59951ecfaad9caee87
--- /dev/null
+++ b/docs-cn/04-develop/03-insert-data/_rust_opts_json.mdx
@@ -0,0 +1,3 @@
+```rust
+{{#include docs-examples/rust/schemalessexample/examples/opentsdb_json_example.rs}}
+```
diff --git a/docs-cn/04-develop/03-insert-data/_rust_opts_telnet.mdx b/docs-cn/04-develop/03-insert-data/_rust_opts_telnet.mdx
new file mode 100644
index 0000000000000000000000000000000000000000..14021f43d8aff30c35dc30c5d278d4e51f375024
--- /dev/null
+++ b/docs-cn/04-develop/03-insert-data/_rust_opts_telnet.mdx
@@ -0,0 +1,3 @@
+```rust
+{{#include docs-examples/rust/schemalessexample/examples/opentsdb_telnet_example.rs}}
+```
diff --git a/docs-cn/04-develop/03-insert-data/_rust_sql.mdx b/docs-cn/04-develop/03-insert-data/_rust_sql.mdx
new file mode 100644
index 0000000000000000000000000000000000000000..8e8013e4ad734efcc262ea2f750b82210a538e49
--- /dev/null
+++ b/docs-cn/04-develop/03-insert-data/_rust_sql.mdx
@@ -0,0 +1,3 @@
+```rust
+{{#include docs-examples/rust/restexample/examples/insert_example.rs}}
+```
diff --git a/docs-cn/04-develop/03-insert-data/_rust_stmt.mdx b/docs-cn/04-develop/03-insert-data/_rust_stmt.mdx
new file mode 100644
index 0000000000000000000000000000000000000000..590a7a0e717426ed0235331c49dfc578bc55b2f7
--- /dev/null
+++ b/docs-cn/04-develop/03-insert-data/_rust_stmt.mdx
@@ -0,0 +1,3 @@
+```rust
+{{#include docs-examples/rust/nativeexample/examples/stmt_example.rs}}
+```
diff --git a/docs-cn/04-develop/04-query-data/_c.mdx b/docs-cn/04-develop/04-query-data/_c.mdx
new file mode 100644
index 0000000000000000000000000000000000000000..76c9067e2f6af19465cf7c52c3e9b48bb868547d
--- /dev/null
+++ b/docs-cn/04-develop/04-query-data/_c.mdx
@@ -0,0 +1,3 @@
+```c
+{{#include docs-examples/c/query_example.c}}
+```
\ No newline at end of file
diff --git a/docs-cn/04-develop/04-query-data/_c_async.mdx b/docs-cn/04-develop/04-query-data/_c_async.mdx
new file mode 100644
index 0000000000000000000000000000000000000000..09f3d3b3ff6d6644f837642ef41db459ba7c5753
--- /dev/null
+++ b/docs-cn/04-develop/04-query-data/_c_async.mdx
@@ -0,0 +1,3 @@
+```c
+{{#include docs-examples/c/async_query_example.c:demo}}
+```
\ No newline at end of file
diff --git a/docs-cn/07-query-data/_category_.yml b/docs-cn/04-develop/04-query-data/_category_.yml
similarity index 100%
rename from docs-cn/07-query-data/_category_.yml
rename to docs-cn/04-develop/04-query-data/_category_.yml
diff --git a/docs-cn/04-develop/04-query-data/_cs.mdx b/docs-cn/04-develop/04-query-data/_cs.mdx
new file mode 100644
index 0000000000000000000000000000000000000000..2ab52feb564eff0fe251bc9900ea2539171e5dba
--- /dev/null
+++ b/docs-cn/04-develop/04-query-data/_cs.mdx
@@ -0,0 +1,3 @@
+```csharp
+{{#include docs-examples/csharp/QueryExample.cs}}
+```
diff --git a/docs-cn/04-develop/04-query-data/_cs_async.mdx b/docs-cn/04-develop/04-query-data/_cs_async.mdx
new file mode 100644
index 0000000000000000000000000000000000000000..f868994b303e62016b5e2f9304275135855c6ae5
--- /dev/null
+++ b/docs-cn/04-develop/04-query-data/_cs_async.mdx
@@ -0,0 +1,3 @@
+```csharp
+{{#include docs-examples/csharp/AsyncQueryExample.cs}}
+```
diff --git a/docs-cn/04-develop/04-query-data/_go.mdx b/docs-cn/04-develop/04-query-data/_go.mdx
new file mode 100644
index 0000000000000000000000000000000000000000..417c12315c06517e2f3de850ac9a379b7714b519
--- /dev/null
+++ b/docs-cn/04-develop/04-query-data/_go.mdx
@@ -0,0 +1,3 @@
+```go
+{{#include docs-examples/go/query/sync/main.go}}
+```
diff --git a/docs-cn/04-develop/04-query-data/_go_async.mdx b/docs-cn/04-develop/04-query-data/_go_async.mdx
new file mode 100644
index 0000000000000000000000000000000000000000..72fff411b980a0dcbdcaf4274722c63e0351db6f
--- /dev/null
+++ b/docs-cn/04-develop/04-query-data/_go_async.mdx
@@ -0,0 +1,3 @@
+```go
+{{#include docs-examples/go/query/async/main.go}}
+```
diff --git a/docs-cn/04-develop/04-query-data/_java.mdx b/docs-cn/04-develop/04-query-data/_java.mdx
new file mode 100644
index 0000000000000000000000000000000000000000..519b9266144486231caf3ee593e973d438941ee4
--- /dev/null
+++ b/docs-cn/04-develop/04-query-data/_java.mdx
@@ -0,0 +1,3 @@
+```java
+{{#include docs-examples/java/src/main/java/com/taos/example/RestQueryExample.java}}
+```
diff --git a/docs-cn/04-develop/04-query-data/_js.mdx b/docs-cn/04-develop/04-query-data/_js.mdx
new file mode 100644
index 0000000000000000000000000000000000000000..c5e4c4f3fc20d3940a2bc6e13e6a5dea8a15ff13
--- /dev/null
+++ b/docs-cn/04-develop/04-query-data/_js.mdx
@@ -0,0 +1,3 @@
+```js
+{{#include docs-examples/node/nativeexample/query_example.js}}
+```
diff --git a/docs-cn/04-develop/04-query-data/_js_async.mdx b/docs-cn/04-develop/04-query-data/_js_async.mdx
new file mode 100644
index 0000000000000000000000000000000000000000..c65d54ed12f6c4bbeb333e0de0ba9ca4638bff84
--- /dev/null
+++ b/docs-cn/04-develop/04-query-data/_js_async.mdx
@@ -0,0 +1,3 @@
+```js
+{{#include docs-examples/node/nativeexample/async_query_example.js}}
+```
diff --git a/docs-cn/04-develop/04-query-data/_py.mdx b/docs-cn/04-develop/04-query-data/_py.mdx
new file mode 100644
index 0000000000000000000000000000000000000000..6a1bacdd3ef91e9484c1d87d6a22de8b128e2144
--- /dev/null
+++ b/docs-cn/04-develop/04-query-data/_py.mdx
@@ -0,0 +1,11 @@
+通过迭代逐行获取查询结果。
+
+```py
+{{#include docs-examples/python/query_example.py:iter}}
+```
+
+一次获取所有查询结果,并把每一行转化为一个字典返回。
+
+```py
+{{#include docs-examples/python/query_example.py:fetch_all}}
+```
diff --git a/docs-cn/04-develop/04-query-data/_py_async.mdx b/docs-cn/04-develop/04-query-data/_py_async.mdx
new file mode 100644
index 0000000000000000000000000000000000000000..2399a50df645804788036e17bf223c53482d4eaf
--- /dev/null
+++ b/docs-cn/04-develop/04-query-data/_py_async.mdx
@@ -0,0 +1,8 @@
+```py
+{{#include docs-examples/python/async_query_example.py}}
+```
+
+:::note
+这个示例程序,目前在 Windows 系统上还无法运行
+
+:::
diff --git a/docs-cn/04-develop/04-query-data/_rust.mdx b/docs-cn/04-develop/04-query-data/_rust.mdx
new file mode 100644
index 0000000000000000000000000000000000000000..742d70fd025ff44b573eedf78441c9d73defad45
--- /dev/null
+++ b/docs-cn/04-develop/04-query-data/_rust.mdx
@@ -0,0 +1,3 @@
+```rust
+{{#include docs-examples/rust/restexample/examples/query_example.rs}}
+```
diff --git a/docs-cn/07-query-data/07-query-data.mdx b/docs-cn/04-develop/04-query-data/index.mdx
similarity index 59%
rename from docs-cn/07-query-data/07-query-data.mdx
rename to docs-cn/04-develop/04-query-data/index.mdx
index f253b13b0d0b86b9e23a1c419e490fb85b081f85..829280fba5b1e5a956b79699df39f9bb2c1cb177 100644
--- a/docs-cn/07-query-data/07-query-data.mdx
+++ b/docs-cn/04-develop/04-query-data/index.mdx
@@ -1,11 +1,26 @@
-# 查询数据
+---
+slug: /query-data
+title: 查询数据
+description: "主要查询功能,通过连接器执行同步查询和异步查询"
+---
import Tabs from "@theme/Tabs";
import TabItem from "@theme/TabItem";
+import JavaQuery from "./_java.mdx";
+import PyQuery from "./_py.mdx";
+import GoQuery from "./_go.mdx";
+import RustQuery from "./_rust.mdx";
+import NodeQuery from "./_js.mdx";
+import CsQuery from "./_cs.mdx";
+import CQuery from "./_c.mdx";
+import PyAsync from "./_py_async.mdx";
+import NodeAsync from "./_js_async.mdx";
+import CsAsync from "./_cs_async.mdx";
+import CAsync from "./_c_async.mdx";
## 主要查询功能
-TDengine 采用 SQL 作为查询语言。应用程序可以通过 C/C++, Java, Go, C#, Python, Node.js 连接器发送 SQL 语句,用户可以通过 TDengine 提供的命令行(Command Line Interface, CLI)工具 TAOS Shell 手动执行 SQL 即席查询(Ad-Hoc Query)。TDengine 支持如下查询功能:
+TDengine 采用 SQL 作为查询语言。应用程序可以通过 REST API 或连接器发送 SQL 语句,用户还可以通过 TDengine 命令行工具 taos 手动执行 SQL 即席查询(Ad-Hoc Query)。TDengine 支持如下查询功能:
- 单列、多列数据查询
- 标签和数值的多种过滤条件:>, <, =, <\>, like 等
@@ -14,9 +29,9 @@ TDengine 采用 SQL 作为查询语言。应用程序可以通过 C/C++, Java, G
- 时间戳对齐的连接查询(Join Query: 隐式连接)操作
- 多种聚合/计算函数: count, max, min, avg, sum, twa, stddev, leastsquares, top, bottom, first, last, percentile, apercentile, last_row, spread, diff 等
-例如:在 TAOS Shell 中,从表 d1001 中查询出 voltage > 215 的记录,按时间降序排列,仅仅输出 2 条。
+例如:在命令行工具 taos 中,从表 d1001 中查询出 voltage > 215 的记录,按时间降序排列,仅仅输出 2 条。
-```mysql
+```sql
taos> select * from d1001 where voltage > 215 order by ts desc limit 2;
ts | current | voltage | phase |
======================================================================================
@@ -27,13 +42,15 @@ Query OK, 2 row(s) in set (0.001100s)
为满足物联网场景的需求,TDengine 支持几个特殊的函数,比如 twa(时间加权平均),spread (最大值与最小值的差),last_row(最后一条记录)等,更多与物联网场景相关的函数将添加进来。TDengine 还支持连续查询。
-具体的查询语法请看 [TAOS SQL 的数据查询](https://www.taosdata.com/cn/documentation/taos-sql#select) 章节。
+具体的查询语法请看 [TAOS SQL 的数据查询](/taos-sql/select) 章节。
## 多表聚合查询
物联网场景中,往往同一个类型的数据采集点有多个。TDengine 采用超级表(STable)的概念来描述某一个类型的数据采集点,一张普通的表来描述一个具体的数据采集点。同时 TDengine 使用标签来描述数据采集点的静态属性,一个具体的数据采集点有具体的标签值。通过指定标签的过滤条件,TDengine 提供了一高效的方法将超级表(某一类型的数据采集点)所属的子表进行聚合查询。对普通表的聚合函数以及绝大部分操作都适用于超级表,语法完全一样。
-**示例 1**:在 TAOS Shell,查找北京所有智能电表采集的电压平均值,并按照 location 分组
+### 示例一
+
+在 TAOS Shell,查找北京所有智能电表采集的电压平均值,并按照 location 分组。
```
taos> SELECT AVG(voltage) FROM meters GROUP BY location;
@@ -44,7 +61,9 @@ taos> SELECT AVG(voltage) FROM meters GROUP BY location;
Query OK, 2 row(s) in set (0.002136s)
```
-**示例 2**:在 TAOS shell, 查找 groupId 为 2 的所有智能电表过去 24 小时的记录条数,电流的最大值
+### 示例二
+
+在 TAOS shell, 查找 groupId 为 2 的所有智能电表过去 24 小时的记录条数,电流的最大值。
```
taos> SELECT count(*), max(current) FROM meters where groupId = 2 and ts > now - 24h;
@@ -54,7 +73,7 @@ taos> SELECT count(*), max(current) FROM meters where groupId = 2 and ts > now -
Query OK, 1 row(s) in set (0.002136s)
```
-TDengine 仅容许对属于同一个超级表的表之间进行聚合查询,不同超级表之间的聚合查询不支持。在 [TAOS SQL 的数据查询](https://www.taosdata.com/cn/documentation/taos-sql#select) 一章,查询类操作都会注明是否支持超级表。
+TDengine 仅容许对属于同一个超级表的表之间进行聚合查询,不同超级表之间的聚合查询不支持。在 [TAOS SQL 的数据查询](/taos-sql/select) 一章,查询类操作都会注明是否支持超级表。
## 降采样查询、插值
@@ -97,31 +116,63 @@ taos> SELECT SUM(current) FROM meters INTERVAL(1s, 500a);
Query OK, 5 row(s) in set (0.001521s)
```
-物联网场景里,每个数据采集点采集数据的时间是难同步的,但很多分析算法(比如 FFT)需要把采集的数据严格按照时间等间隔的对齐,在很多系统里,需要应用自己写程序来处理,但使用 TDengine 的降采样操作就轻松解决。如果一个时间间隔里,没有采集的数据,TDengine 还提供插值计算的功能。
+物联网场景里,每个数据采集点采集数据的时间是难同步的,但很多分析算法(比如 FFT)需要把采集的数据严格按照时间等间隔的对齐,在很多系统里,需要应用自己写程序来处理,但使用 TDengine 的降采样操作就轻松解决。
-语法规则细节请见 [TAOS SQL 的时间维度聚合](https://www.taosdata.com/cn/documentation/taos-sql#aggregation) 章节。
+如果一个时间间隔里,没有采集的数据,TDengine 还提供插值计算的功能。
-## 示例代码
+语法规则细节请见 [TAOS SQL 的按时间窗口切分聚合](/taos-sql/interval) 章节。
-### 同步查询
+## 示例代码
-
-
-
-
-
-
-
-
+### 查询数据
+
+在 [SQL 写入](/develop/insert-data/sql-writing) 一章,我们创建了 power 数据库,并向 meters 表写入了一些数据,以下示例代码展示如何查询这个表的数据。
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+:::note
+
+1. 无论是使用 REST 连接还是原生连接的连接器,以上示例代码都能正常工作。
+2. 唯一需要注意的是:由于 RESTful 接口无状态, 不能使用 `use db` 语句来切换数据库。
+
+:::
+
### 异步查询
-
-
-
-
-
-
-
+除同步查询 API 之外,TDengine 还提供性能更高的异步调用 API 处理数据插入、查询操作。在软硬件环境相同的情况下,异步 API 处理数据插入的速度比同步 API 快 2-4 倍。异步 API 采用非阻塞式的调用方式,在系统真正完成某个具体数据库操作前,立即返回。调用的线程可以去处理其他工作,从而可以提升整个应用的性能。异步 API 在网络延迟严重的情况下,优点尤为突出。
+
+需要注意的是,只有使用原生连接的连接器,才能使用异步查询功能。
+
+
+
+
+
+
+
+
+
+
+
diff --git a/docs-cn/08-advance-feature/01-continuous-query.mdx b/docs-cn/04-develop/05-continuous-query.mdx
similarity index 86%
rename from docs-cn/08-advance-feature/01-continuous-query.mdx
rename to docs-cn/04-develop/05-continuous-query.mdx
index 2764bd408440bcb22cbb4136dbc8ea9753c7b7bc..2fd1b3cc755188f513fe511541a84efa3558d3ea 100644
--- a/docs-cn/08-advance-feature/01-continuous-query.mdx
+++ b/docs-cn/04-develop/05-continuous-query.mdx
@@ -1,12 +1,9 @@
---
sidebar_label: 连续查询
+description: "连续查询是一个按照预设频率自动执行的查询功能,提供按照时间窗口的聚合查询能力,是一种简化的时间驱动流式计算。"
+title: "连续查询(Continuous Query)"
---
-# 连续查询(Continuous Query)
-
-import Tabs from "@theme/Tabs";
-import TabItem from "@theme/TabItem";
-
连续查询是 TDengine 定期自动执行的查询,采用滑动窗口的方式进行计算,是一种简化的时间驱动的流式计算。针对库中的表或超级表,TDengine 可提供定期自动执行的连续查询,用户可让 TDengine 推送查询的结果,也可以将结果再写回到 TDengine 中。每次执行的查询是一个时间窗口,时间窗口随着时间流动向前滑动。在定义连续查询的时候需要指定时间窗口(time window, 参数 interval)大小和每次前向增量时间(forward sliding times, 参数 sliding)。
TDengine 的连续查询采用时间驱动模式,可以直接使用 TAOS SQL 进行定义,不需要额外的操作。使用连续查询,可以方便快捷地按照时间窗口生成结果,从而对原始采集数据进行降采样(down sampling)。用户通过 TAOS SQL 定义连续查询以后,TDengine 自动在最后的一个完整的时间周期末端拉起查询,并将计算获得的结果推送给用户或者写回 TDengine。
@@ -15,7 +12,21 @@ TDengine 提供的连续查询与普通流计算中的时间窗口计算具有
- 不同于流计算的实时反馈计算结果,连续查询只在时间窗口关闭以后才开始计算。例如时间周期是 1 天,那么当天的结果只会在 23:59:59 以后才会生成。
- 如果有历史记录写入到已经计算完成的时间区间,连续查询并不会重新进行计算,也不会重新将结果推送给用户。对于写回 TDengine 的模式,也不会更新已经存在的计算结果。
-- 使用连续查询推送结果的模式,服务端并不缓存客户端计算状态,也不提供 Exactly-Once 的语意保证。如果用户的应用端崩溃,再次拉起的连续查询将只会从再次拉起的时间开始重新计算最近的一个完整的时间窗口。如果使用写回模式,TDengine 可确保数据写回的有效性和连续性。
+- 使用连续查询推送结果的模式,服务端并不缓存客户端计算状态,也不提供 Exactly-Once 的语义保证。如果用户的应用端崩溃,再次拉起的连续查询将只会从再次拉起的时间开始重新计算最近的一个完整的时间窗口。如果使用写回模式,TDengine 可确保数据写回的有效性和连续性。
+
+## 连续查询语法
+
+```sql
+[CREATE TABLE AS] SELECT select_expr [, select_expr ...]
+ FROM {tb_name_list}
+ [WHERE where_condition]
+ [INTERVAL(interval_val [, interval_offset]) [SLIDING sliding_val]]
+
+```
+
+INTERVAL: 连续查询作用的时间窗口
+
+SLIDING: 连续查询的时间窗口向前滑动的时间间隔
## 使用连续查询
@@ -28,7 +39,7 @@ create table D1002 using meters tags ("Beijing.Haidian", 2);
...
```
-我们已经知道,可以通过下面这条 SQL 语句以一分钟为时间窗口、30 秒为前向增量统计这些电表的平均电压。
+可以通过下面这条 SQL 语句以一分钟为时间窗口、30 秒为前向增量统计这些电表的平均电压。
```sql
select avg(voltage) from meters interval(1m) sliding(30s);
@@ -48,7 +59,7 @@ create table avg_vol as select avg(voltage) from meters interval(1m) sliding(30s
会自动创建一个名为 `avg_vol` 的新表,然后每隔 30 秒,TDengine 会增量执行 `as` 后面的 SQL 语句,并将查询结果写入这个表中,用户程序后续只要从 `avg_vol` 中查询数据即可。例如:
-```mysql
+```sql
taos> select * from avg_vol;
ts | avg_voltage_ |
===================================================
@@ -62,7 +73,7 @@ taos> select * from avg_vol;
此外,TDengine 还支持用户指定连续查询的起止时间。如果不输入开始时间,连续查询将从第一条原始数据所在的时间窗口开始;如果没有输入结束时间,连续查询将永久运行;如果用户指定了结束时间,连续查询在系统时间达到指定的时间以后停止运行。比如使用下面的 SQL 创建的连续查询将运行一小时,之后会自动停止。
-```mysql
+```sql
create table avg_vol as select avg(voltage) from meters where ts > now and ts <= now + 1h interval(1m) sliding(30s);
```
@@ -71,16 +82,3 @@ create table avg_vol as select avg(voltage) from meters where ts > now and ts <=
## 管理连续查询
用户可在控制台中通过 `show streams` 命令来查看系统中全部运行的连续查询,并可以通过 `kill stream` 命令杀掉对应的连续查询。后续版本会提供更细粒度和便捷的连续查询管理命令。
-
-## 示例代码
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/docs-cn/08-advance-feature/02-subscribe.mdx b/docs-cn/04-develop/06-subscribe.mdx
similarity index 73%
rename from docs-cn/08-advance-feature/02-subscribe.mdx
rename to docs-cn/04-develop/06-subscribe.mdx
index 96123d1a66ddbbc660760fba71ae56267ccab573..d33a60d8de0a4552fa531d5e390c0faae22057fa 100644
--- a/docs-cn/08-advance-feature/02-subscribe.mdx
+++ b/docs-cn/04-develop/06-subscribe.mdx
@@ -1,15 +1,24 @@
---
-sidebar_position: 2
-sidebar_label: 订阅
+sidebar_label: 数据订阅
+description: "轻量级的数据订阅与推送服务。连续写入到 TDengine 中的时序数据能够被自动推送到订阅客户端。"
+title: 数据订阅
---
-# 数据订阅(Publisher/Subscriber)
+import Tabs from "@theme/Tabs";
+import TabItem from "@theme/TabItem";
+import Java from "./_sub_java.mdx";
+import Python from "./_sub_python.mdx";
+import Go from "./_sub_go.mdx";
+import Rust from "./_sub_rust.mdx";
+import Node from "./_sub_node.mdx";
+import CSharp from "./_sub_cs.mdx";
+import CDemo from "./_sub_c.mdx";
-基于数据天然的时间序列特性,TDengine 的数据写入(insert)与消息系统的数据发布(pub)逻辑上一致,均可视为系统中插入一条带时间戳的新记录。同时,TDengine 在内部严格按照数据时间序列单调递增的方式保存数据。本质上来说,TDengine 中里每一张表均可视为一个标准的消息队列。
+基于数据天然的时间序列特性,TDengine 的数据写入(insert)与消息系统的数据发布(pub)逻辑上一致,均可视为系统中插入一条带时间戳的新记录。同时,TDengine 在内部严格按照数据时间序列单调递增的方式保存数据。本质上来说,TDengine 中每一张表均可视为一个标准的消息队列。
TDengine 内嵌支持轻量级的消息订阅与推送服务。使用系统提供的 API,用户可使用普通查询语句订阅数据库中的一张或多张表。订阅的逻辑和操作状态的维护均是由客户端完成,客户端定时轮询服务器是否有新的记录到达,有新的记录到达就会将结果反馈到客户。
-TDengine 的订阅与推送服务的状态是客户端维持,TDengine 服务器并不维持。因此如果应用重启,从哪个时间点开始获取最新数据,由应用决定。
+TDengine 的订阅与推送服务的状态是由客户端维持,TDengine 服务端并不维持。因此如果应用重启,从哪个时间点开始获取最新数据,由应用决定。
TDengine 的 API 中,与订阅相关的主要有以下三个:
@@ -19,7 +28,7 @@ taos_consume
taos_unsubscribe
```
-这些 API 的文档请见 [C/C++ Connector](https://www.taosdata.com/cn/documentation/connector#c-cpp),下面仍以智能电表场景为例介绍一下它们的具体用法(超级表和子表结构请参考上一节“连续查询”),完整的示例代码可以在 [这里](https://github.com/taosdata/TDengine/blob/master/examples/c/subscribe.c) 找到。
+这些 API 的文档请见 [C/C++ Connector](/reference/connector/cpp),下面仍以智能电表场景为例介绍一下它们的具体用法(超级表和子表结构请参考上一节“连续查询”),完整的示例代码可以在 [这里](https://github.com/taosdata/TDengine/blob/master/examples/c/subscribe.c) 找到。
如果我们希望当某个电表的电流超过一定限制(比如 10A)后能得到通知并进行一些处理, 有两种方法:一是分别对每张子表进行查询,每次查询后记录最后一条数据的时间戳,后续只查询这个时间戳之后的数据:
@@ -161,28 +170,26 @@ $ taos
这时,因为电流超过了 10A,您应该可以看到示例程序将它输出到了屏幕上。您可以继续插入一些数据观察示例程序的输出。
-## Java 使用数据订阅功能
+## 示例程序
-订阅功能也提供了 Java 开发接口,相关说明请见 [Java Connector](https://www.taosdata.com/cn/documentation/connector/java#subscribe)。需要注意的是,目前 Java 接口没有提供异步订阅模式,但用户程序可以通过创建 `TimerTask` 等方式达到同样的效果。
-
-下面以一个示例程序介绍其具体使用方法。它所完成的功能与前面介绍的 C 语言示例基本相同,也是订阅数据库中所有电流超过 10A 的记录。
+下面以一个示例程序介绍其具体使用方法。示例程序的目的是订阅数据库中所有电流超过 10A 的记录。
### 准备数据
-```sql
-# 创建 power 库
+```
+# create database "power"
taos> create database power;
-# 切换库
+# use "power" as the database in following operations
taos> use power;
-# 创建超级表
+# create super table "meters"
taos> create table meters(ts timestamp, current float, voltage int, phase int) tags(location binary(64), groupId int);
-# 创建表
+# create tabes using the schema defined by super table "meters"
taos> create table d1001 using meters tags ("Beijing.Chaoyang", 2);
taos> create table d1002 using meters tags ("Beijing.Haidian", 2);
-# 插入测试数据
+# insert some rows
taos> insert into d1001 values("2020-08-15 12:00:00.000", 12, 220, 1),("2020-08-15 12:10:00.000", 12.3, 220, 2),("2020-08-15 12:20:00.000", 12.2, 220, 1);
taos> insert into d1002 values("2020-08-15 12:00:00.000", 9.9, 220, 1),("2020-08-15 12:10:00.000", 10.3, 220, 1),("2020-08-15 12:20:00.000", 11.2, 220, 1);
-# 从超级表 meters 查询电流大于 10A 的记录
+# filter out the rows in which current is bigger than 10A
taos> select * from meters where current > 10;
ts | current | voltage | phase | location | groupid |
===========================================================================================================
@@ -193,64 +200,37 @@ taos> select * from meters where current > 10;
2020-08-15 12:20:00.000 | 12.20000 | 220 | 1 | Beijing.Chaoyang | 2 |
Query OK, 5 row(s) in set (0.004896s)
```
-
-### 示例程序
-
-```java
-public class SubscribeDemo {
- private static final String topic = "topic-meter-current-bg-10";
- private static final String sql = "select * from meters where current > 10";
-
- public static void main(String[] args) {
- Connection connection = null;
- TSDBSubscribe subscribe = null;
-
- try {
- Class.forName("com.taosdata.jdbc.TSDBDriver");
- Properties properties = new Properties();
- properties.setProperty(TSDBDriver.PROPERTY_KEY_CHARSET, "UTF-8");
- properties.setProperty(TSDBDriver.PROPERTY_KEY_TIME_ZONE, "UTC-8");
- String jdbcUrl = "jdbc:TAOS://127.0.0.1:6030/power?user=root&password=taosdata";
- connection = DriverManager.getConnection(jdbcUrl, properties);
- subscribe = ((TSDBConnection) connection).subscribe(topic, sql, true); // 创建订阅
- int count = 0;
- while (count < 10) {
- TimeUnit.SECONDS.sleep(1); // 等待1秒,避免频繁调用 consume,给服务端造成压力
- TSDBResultSet resultSet = subscribe.consume(); // 消费数据
- if (resultSet == null) {
- continue;
- }
- ResultSetMetaData metaData = resultSet.getMetaData();
- while (resultSet.next()) {
- int columnCount = metaData.getColumnCount();
- for (int i = 1; i <= columnCount; i++) {
- System.out.print(metaData.getColumnLabel(i) + ": " + resultSet.getString(i) + "\t");
- }
- System.out.println();
- count++;
- }
- }
- } catch (Exception e) {
- e.printStackTrace();
- } finally {
- try {
- if (null != subscribe)
- subscribe.close(true); // 关闭订阅
- if (connection != null)
- connection.close();
- } catch (SQLException throwables) {
- throwables.printStackTrace();
- }
- }
- }
-}
-```
-
-运行示例程序,首先,它会消费符合查询条件的所有历史数据:
+### 示例代码
+
+
+
+
+
+ {/*
+
+
+
+
+
+
+
+
+
+
+
+
+
+ */}
+
+
+
+
+
+### 运行示例程序
+
+示例程序会先消费符合查询条件的所有历史数据:
```bash
-# java -jar subscribe.jar
-
ts: 1597464000000 current: 12.0 voltage: 220 phase: 1 location: Beijing.Chaoyang groupid : 2
ts: 1597464600000 current: 12.3 voltage: 220 phase: 2 location: Beijing.Chaoyang groupid : 2
ts: 1597465200000 current: 12.2 voltage: 220 phase: 1 location: Beijing.Chaoyang groupid : 2
@@ -260,14 +240,14 @@ ts: 1597465200000 current: 11.2 voltage: 220 phase: 1 location: Beijing.Haidian
接着,使用 taos 客户端向表中新增一条数据:
-```sql
+```
# taos
taos> use power;
-taos> insert into d1001 values("2020-08-15 12:40:00.000", 12.4, 220, 1);
+taos> insert into d1001 values(now, 12.4, 220, 1);
```
因为这条数据的电流大于 10A,示例程序会将其消费:
```
-ts: 1597466400000 current: 12.4 voltage: 220 phase: 1 location: Beijing.Chaoyang groupid: 2
+ts: 1651146662805 current: 12.4 voltage: 220 phase: 1 location: Beijing.Chaoyang groupid: 2
```
diff --git a/docs-cn/08-advance-feature/03-cache.md b/docs-cn/04-develop/07-cache.md
similarity index 93%
rename from docs-cn/08-advance-feature/03-cache.md
rename to docs-cn/04-develop/07-cache.md
index 7f100a9b50ebbab6fe1225c584ed18142176701c..fd31335310d62d792e5173e38a9aa778ee6c6c60 100644
--- a/docs-cn/08-advance-feature/03-cache.md
+++ b/docs-cn/04-develop/07-cache.md
@@ -1,9 +1,9 @@
---
sidebar_label: 缓存
+title: 缓存
+description: "提供写驱动的缓存管理机制,将每个表最近写入的一条记录持续保存在缓存中,可以提供高性能的最近状态查询。"
---
-# 缓存(Cache)
-
TDengine 采用时间驱动缓存管理策略(First-In-First-Out,FIFO),又称为写驱动的缓存管理机制。这种策略有别于读驱动的数据缓存模式(Least-Recent-Used,LRU),直接将最近写入的数据保存在系统的缓存中。当缓存达到临界值的时候,将最早的数据批量写入磁盘。一般意义上来说,对于物联网数据的使用,用户最为关心最近产生的数据,即当前状态。TDengine 充分利用了这一特性,将最近到达的(当前状态)数据保存在缓存中。
TDengine 通过查询函数向用户提供毫秒级的数据获取能力。直接将最近到达的数据保存在缓存中,可以更加快速地响应用户针对最近一条或一批数据的查询分析,整体上提供更快的数据库查询响应能力。从这个意义上来说,可通过设置合适的配置参数将 TDengine 作为数据缓存来使用,而不需要再部署额外的缓存系统,可有效地简化系统架构,降低运维的成本。需要注意的是,TDengine 重启以后系统的缓存将被清空,之前缓存的数据均会被批量写入磁盘,缓存的数据将不会像专门的 key-value 缓存系统再将之前缓存的数据重新加载到缓存中。
@@ -14,7 +14,7 @@ TDengine 将内存池按块划分进行管理,数据在内存块里是以行
你可以通过函数 last_row() 快速获取一张表或一张超级表的最后一条记录,这样很便于在大屏显示各设备的实时状态或采集值。例如:
-```mysql
+```sql
select last_row(voltage) from meters where location='Beijing.Chaoyang';
```
diff --git a/docs-cn/04-develop/08-udf.md b/docs-cn/04-develop/08-udf.md
new file mode 100644
index 0000000000000000000000000000000000000000..09681650db32200e60c0fdb787d3e455dd339d85
--- /dev/null
+++ b/docs-cn/04-develop/08-udf.md
@@ -0,0 +1,208 @@
+---
+sidebar_label: 用户定义函数
+title: UDF(用户定义函数)
+description: "支持用户编码的聚合函数和标量函数,在查询中嵌入并使用用户定义函数,拓展查询的能力和功能。"
+---
+
+在有些应用场景中,应用逻辑需要的查询无法直接使用系统内置的函数来表示。利用 UDF 功能,TDengine 可以插入用户编写的处理代码并在查询中使用它们,就能够很方便地解决特殊应用场景中的使用需求。 UDF 通常以数据表中的一列数据做为输入,同时支持以嵌套子查询的结果作为输入。
+
+从 2.2.0.0 版本开始,TDengine 支持通过 C/C++ 语言进行 UDF 定义。接下来结合示例讲解 UDF 的使用方法。
+
+用户可以通过 UDF 实现两类函数: 标量函数 和 聚合函数。
+
+## 用 C/C++ 语言来定义 UDF
+
+### 标量函数
+
+用户可以按照下列函数模板定义自己的标量计算函数
+
+ `void udfNormalFunc(char* data, short itype, short ibytes, int numOfRows, long long* ts, char* dataOutput, char* interBuf, char* tsOutput, int* numOfOutput, short otype, short obytes, SUdfInit* buf)`
+
+ 其中 udfNormalFunc 是函数名的占位符,以上述模板实现的函数对行数据块进行标量计算,其参数项是固定的,用于按照约束完成与引擎之间的数据交换。
+
+- udfNormalFunc 中各参数的具体含义是:
+ - data:输入数据。
+ - itype:输入数据的类型。这里采用的是短整型表示法,与各种数据类型对应的值可以参见 [column_meta 中的列类型说明](/reference/rest-api/)。例如 4 用于表示 INT 型。
+ - iBytes:输入数据中每个值会占用的字节数。
+ - numOfRows:输入数据的总行数。
+ - ts:主键时间戳在输入中的列数据(只读)。
+ - dataOutput:输出数据的缓冲区,缓冲区大小为用户指定的输出类型大小 \* numOfRows。
+ - interBuf:中间计算结果的缓冲区,大小为用户在创建 UDF 时指定的 BUFSIZE 大小。通常用于计算中间结果与最终结果不一致时使用,由引擎负责分配与释放。
+ - tsOutput:主键时间戳在输出时的列数据,如果非空可用于输出结果对应的时间戳。
+ - numOfOutput:输出结果的个数(行数)。
+ - oType:输出数据的类型。取值含义与 itype 参数一致。
+ - oBytes:输出数据中每个值占用的字节数。
+ - buf:用于在 UDF 与引擎间的状态控制信息传递块。
+
+ [add_one.c](https://github.com/taosdata/TDengine/blob/develop/tests/script/sh/add_one.c) 是结构最简单的 UDF 实现,也即上面定义的 udfNormalFunc 函数的一个具体实现。其功能为:对传入的一个数据列(可能因 WHERE 子句进行了筛选)中的每一项,都输出 +1 之后的值,并且要求输入的列数据类型为 INT。
+
+### 聚合函数
+
+用户可以按照如下函数模板定义自己的聚合函数。
+
+`void abs_max_merge(char* data, int32_t numOfRows, char* dataOutput, int32_t* numOfOutput, SUdfInit* buf)`
+
+其中 udfMergeFunc 是函数名的占位符,以上述模板实现的函数用于对计算中间结果进行聚合,只有针对超级表的聚合查询才需要调用该函数。其中各参数的具体含义是:
+
+ - data:udfNormalFunc 的输出数据数组,如果使用了 interBuf 那么 data 就是 interBuf 的数组。
+ - numOfRows:data 中数据的行数。
+ - dataOutput:输出数据的缓冲区,大小等于一条最终结果的大小。如果此时输出还不是最终结果,可以选择输出到 interBuf 中即 data 中。
+ - numOfOutput:输出结果的个数(行数)。
+ - buf:用于在 UDF 与引擎间的状态控制信息传递块。
+
+[abs_max.c](https://github.com/taosdata/TDengine/blob/develop/tests/script/sh/abs_max.c) 实现的是一个聚合函数,功能是对一组数据按绝对值取最大值。
+
+其计算过程为:与所在查询语句相关的数据会被分为多个行数据块,对每个行数据块调用 udfNormalFunc(在本例的实现代码中,实际函数名是 `abs_max`)来生成每个子表的中间结果,再将子表的中间结果调用 udfMergeFunc(本例中,其实际的函数名是 `abs_max_merge`)进行聚合,生成超级表的最终聚合结果或中间结果。聚合查询最后还会通过 udfFinalizeFunc(本例中,其实际的函数名是 `abs_max_finalize`)再把超级表的中间结果处理为最终结果,最终结果只能含 0 或 1 条结果数据。
+
+其他典型场景,如协方差的计算,也可通过定义聚合 UDF 的方式实现。
+
+### 最终计算
+
+用户可以按下面的函数模板实现自己的函数对计算结果进行最终计算,通常用于有 interBuf 使用的场景。
+
+`void abs_max_finalize(char* dataOutput, char* interBuf, int* numOfOutput, SUdfInit* buf)`
+
+其中 udfFinalizeFunc 是函数名的占位符 ,其中各参数的具体含义是:
+ - dataOutput:输出数据的缓冲区。
+ - interBuf:中间结算结果缓冲区,可作为输入。
+ - numOfOutput:输出数据的个数,对聚合函数来说只能是 0 或者 1。
+ - buf:用于在 UDF 与引擎间的状态控制信息传递块。
+
+## UDF 实现方式的规则总结
+
+三类 UDF 函数: udfNormalFunc、udfMergeFunc、udfFinalizeFunc ,其函数名约定使用相同的前缀,此前缀即 udfNormalFunc 的实际函数名,也即 udfNormalFunc 函数不需要在实际函数名后添加后缀;而udfMergeFunc 的函数名要加上后缀 `_merge`、udfFinalizeFunc 的函数名要加上后缀 `_finalize`,这是 UDF 实现规则的一部分,系统会按照这些函数名后缀来调用相应功能。
+
+根据 UDF 函数类型的不同,用户所要实现的功能函数也不同:
+
+- 标量函数:UDF 中需实现 udfNormalFunc。
+- 聚合函数:UDF 中需实现 udfNormalFunc、udfMergeFunc(对超级表查询)、udfFinalizeFunc。
+
+:::note
+如果对应的函数不需要具体的功能,也需要实现一个空函数。
+
+:::
+
+## 编译 UDF
+
+用户定义函数的 C 语言源代码无法直接被 TDengine 系统使用,而是需要先编译为 动态链接库,之后才能载入 TDengine 系统。
+
+例如,按照上一章节描述的规则准备好了用户定义函数的源代码 add_one.c,以 Linux 为例可以执行如下指令编译得到动态链接库文件:
+
+```bash
+gcc -g -O0 -fPIC -shared add_one.c -o add_one.so
+```
+
+这样就准备好了动态链接库 add_one.so 文件,可以供后文创建 UDF 时使用了。为了保证可靠的系统运行,编译器 GCC 推荐使用 7.5 及以上版本。
+
+## 在系统中管理和使用 UDF
+
+### 创建 UDF
+
+用户可以通过 SQL 指令在系统中加载客户端所在主机上的 UDF 函数库(不能通过 RESTful 接口或 HTTP 管理界面来进行这一过程)。一旦创建成功,则当前 TDengine 集群的所有用户都可以在 SQL 指令中使用这些函数。UDF 存储在系统的 MNode 节点上,因此即使重启 TDengine 系统,已经创建的 UDF 也仍然可用。
+
+在创建 UDF 时,需要区分标量函数和聚合函数。如果创建时声明了错误的函数类别,则可能导致通过 SQL 指令调用函数时出错。此外, UDF 支持输入与输出类型不一致,用户需要保证输入数据类型与 UDF 程序匹配,UDF 输出数据类型与 OUTPUTTYPE 匹配。
+
+- 创建标量函数
+```sql
+CREATE FUNCTION ids(X) AS ids(Y) OUTPUTTYPE typename(Z) [ BUFSIZE B ];
+```
+
+ - ids(X):标量函数未来在 SQL 指令中被调用时的函数名,必须与函数实现中 udfNormalFunc 的实际名称一致;
+ - ids(Y):包含 UDF 函数实现的动态链接库的库文件绝对路径(指的是库文件在当前客户端所在主机上的保存路径,通常是指向一个 .so 文件),这个路径需要用英文单引号或英文双引号括起来;
+ - typename(Z):此函数计算结果的数据类型,与上文中 udfNormalFunc 的 itype 参数不同,这里不是使用数字表示法,而是直接写类型名称即可;
+ - B:中间计算结果的缓冲区大小,单位是字节,最小 0,最大 512,如果不使用可以不设置。
+
+ 例如,如下语句可以把 add_one.so 创建为系统中可用的 UDF:
+
+ ```sql
+ CREATE FUNCTION add_one AS "/home/taos/udf_example/add_one.so" OUTPUTTYPE INT;
+ ```
+
+- 创建聚合函数:
+```sql
+CREATE AGGREGATE FUNCTION ids(X) AS ids(Y) OUTPUTTYPE typename(Z) [ BUFSIZE B ];
+```
+
+ - ids(X):聚合函数未来在 SQL 指令中被调用时的函数名,必须与函数实现中 udfNormalFunc 的实际名称一致;
+ - ids(Y):包含 UDF 函数实现的动态链接库的库文件绝对路径(指的是库文件在当前客户端所在主机上的保存路径,通常是指向一个 .so 文件),这个路径需要用英文单引号或英文双引号括起来;
+ - typename(Z):此函数计算结果的数据类型,与上文中 udfNormalFunc 的 itype 参数不同,这里不是使用数字表示法,而是直接写类型名称即可;
+ - B:中间计算结果的缓冲区大小,单位是字节,最小 0,最大 512,如果不使用可以不设置。
+
+ 关于中间计算结果的使用,可以参考示例程序[demo.c](https://github.com/taosdata/TDengine/blob/develop/tests/script/sh/demo.c)
+
+ 例如,如下语句可以把 demo.so 创建为系统中可用的 UDF:
+
+ ```sql
+ CREATE AGGREGATE FUNCTION demo AS "/home/taos/udf_example/demo.so" OUTPUTTYPE DOUBLE bufsize 14;
+ ```
+
+### 管理 UDF
+
+- 删除指定名称的用户定义函数:
+```
+DROP FUNCTION ids(X);
+```
+
+- ids(X):此参数的含义与 CREATE 指令中的 ids(X) 参数一致,也即要删除的函数的名字,例如
+```sql
+DROP FUNCTION add_one;
+```
+- 显示系统中当前可用的所有 UDF:
+```sql
+SHOW FUNCTIONS;
+```
+
+### 调用 UDF
+
+在 SQL 指令中,可以直接以在系统中创建 UDF 时赋予的函数名来调用用户定义函数。例如:
+```sql
+SELECT X(c) FROM table/stable;
+```
+
+表示对名为 c 的数据列调用名为 X 的用户定义函数。SQL 指令中用户定义函数可以配合 WHERE 等查询特性来使用。
+
+## UDF 的一些使用限制
+
+在当前版本下,使用 UDF 存在如下这些限制:
+
+1. 在创建和调用 UDF 时,服务端和客户端都只支持 Linux 操作系统;
+2. UDF 不能与系统内建的 SQL 函数混合使用,暂不支持在一条 SQL 语句中使用多个不同名的 UDF ;
+3. UDF 只支持以单个数据列作为输入;
+4. UDF 只要创建成功,就会被持久化存储到 MNode 节点中;
+5. 无法通过 RESTful 接口来创建 UDF;
+6. UDF 在 SQL 中定义的函数名,必须与 .so 库文件实现中的接口函数名前缀保持一致,也即必须是 udfNormalFunc 的名称,而且不可与 TDengine 中已有的内建 SQL 函数重名。
+
+## 示例代码
+
+### 标量函数示例 [add_one](https://github.com/taosdata/TDengine/blob/develop/tests/script/sh/add_one.c)
+
+
+add_one.c
+
+```c
+{{#include tests/script/sh/add_one.c}}
+```
+
+
+
+### 向量函数示例 [abs_max](https://github.com/taosdata/TDengine/blob/develop/tests/script/sh/abs_max.c)
+
+
+abs_max.c
+
+```c
+{{#include tests/script/sh/abs_max.c}}
+```
+
+
+
+### 使用中间计算结果示例 [demo](https://github.com/taosdata/TDengine/blob/develop/tests/script/sh/demo.c)
+
+
+demo.c
+
+```c
+{{#include tests/script/sh/demo.c}}
+```
+
+
diff --git a/docs-cn/04-develop/_category_.yml b/docs-cn/04-develop/_category_.yml
new file mode 100644
index 0000000000000000000000000000000000000000..509a9405c42939a4819b87669a4c5b244bd29a8b
--- /dev/null
+++ b/docs-cn/04-develop/_category_.yml
@@ -0,0 +1 @@
+label: 开发指南
\ No newline at end of file
diff --git a/docs-cn/04-develop/_sub_c.mdx b/docs-cn/04-develop/_sub_c.mdx
new file mode 100644
index 0000000000000000000000000000000000000000..95fef0042d0a277f9136e6e6f8c15558487232f9
--- /dev/null
+++ b/docs-cn/04-develop/_sub_c.mdx
@@ -0,0 +1,3 @@
+```c
+{{#include docs-examples/c/subscribe_demo.c}}
+```
\ No newline at end of file
diff --git a/docs-cn/04-develop/_sub_cs.mdx b/docs-cn/04-develop/_sub_cs.mdx
new file mode 100644
index 0000000000000000000000000000000000000000..80934aa4d014a076896dce7f41e520f06ffd735d
--- /dev/null
+++ b/docs-cn/04-develop/_sub_cs.mdx
@@ -0,0 +1,3 @@
+```csharp
+{{#include docs-examples/csharp/SubscribeDemo.cs}}
+```
\ No newline at end of file
diff --git a/docs-cn/04-develop/_sub_go.mdx b/docs-cn/04-develop/_sub_go.mdx
new file mode 100644
index 0000000000000000000000000000000000000000..cd908fc12c3a35f49ca108ee56c3951c5388a95f
--- /dev/null
+++ b/docs-cn/04-develop/_sub_go.mdx
@@ -0,0 +1,3 @@
+```go
+{{#include docs-examples/go/sub/main.go}}
+```
\ No newline at end of file
diff --git a/docs-cn/04-develop/_sub_java.mdx b/docs-cn/04-develop/_sub_java.mdx
new file mode 100644
index 0000000000000000000000000000000000000000..1ee0cb1a21e35f6760f8680e2ba6dedee92201cd
--- /dev/null
+++ b/docs-cn/04-develop/_sub_java.mdx
@@ -0,0 +1,7 @@
+```java
+{{#include docs-examples/java/src/main/java/com/taos/example/SubscribeDemo.java}}
+```
+:::note
+目前 Java 接口没有提供异步订阅模式,但用户程序可以通过创建 `TimerTask` 等方式达到同样的效果。
+
+:::
\ No newline at end of file
diff --git a/docs-cn/04-develop/_sub_node.mdx b/docs-cn/04-develop/_sub_node.mdx
new file mode 100644
index 0000000000000000000000000000000000000000..c93ad627ce9a77ca71a014b41d571089e6c1727b
--- /dev/null
+++ b/docs-cn/04-develop/_sub_node.mdx
@@ -0,0 +1,3 @@
+```js
+{{#include docs-examples/node/nativeexample/subscribe_demo.js}}
+```
\ No newline at end of file
diff --git a/docs-cn/04-develop/_sub_python.mdx b/docs-cn/04-develop/_sub_python.mdx
new file mode 100644
index 0000000000000000000000000000000000000000..b817deeba6e283a3ba16fee0d580d3823c999536
--- /dev/null
+++ b/docs-cn/04-develop/_sub_python.mdx
@@ -0,0 +1,3 @@
+```py
+{{#include docs-examples/python/subscribe_demo.py}}
+```
\ No newline at end of file
diff --git a/docs-cn/04-develop/_sub_rust.mdx b/docs-cn/04-develop/_sub_rust.mdx
new file mode 100644
index 0000000000000000000000000000000000000000..4750cf7a3b871db48c9e5a26b22ab4b8a03f11be
--- /dev/null
+++ b/docs-cn/04-develop/_sub_rust.mdx
@@ -0,0 +1,3 @@
+```rs
+{{#include docs-examples/rust/nativeexample/examples/subscribe_demo.rs}}
+```
\ No newline at end of file
diff --git a/docs-cn/06-insert-data/01-sql-writing.mdx b/docs-cn/06-insert-data/01-sql-writing.mdx
deleted file mode 100644
index 6e5605c75cf13b33406ca5457fdc7b537e8b2be6..0000000000000000000000000000000000000000
--- a/docs-cn/06-insert-data/01-sql-writing.mdx
+++ /dev/null
@@ -1,65 +0,0 @@
-# SQL 写入
-
-import Tabs from "@theme/Tabs";
-import TabItem from "@theme/TabItem";
-
-## SQL 写入
-
-应用通过 C/C++, Java, Go, C#, Python, Node.js 连接器执行 SQL insert 语句来插入数据,用户还可以通过 TAOS Shell,手动输入 SQL insert 语句插入数据。比如下面这条 insert 就将一条记录写入到表 d1001 中:
-
-```mysql
-INSERT INTO d1001 VALUES (1538548685000, 10.3, 219, 0.31);
-```
-
-TDengine 支持一次写入多条记录,比如下面这条命令就将两条记录写入到表 d1001 中:
-
-```mysql
-INSERT INTO d1001 VALUES (1538548684000, 10.2, 220, 0.23) (1538548696650, 10.3, 218, 0.25);
-```
-
-TDengine 也支持一次向多个表写入数据,比如下面这条命令就向 d1001 写入两条记录,向 d1002 写入一条记录:
-
-```mysql
-INSERT INTO d1001 VALUES (1538548685000, 10.3, 219, 0.31) (1538548695000, 12.6, 218, 0.33) d1002 VALUES (1538548696800, 12.3, 221, 0.31);
-```
-
-详细的 SQL INSERT 语法规则请见 [TAOS SQL 的数据写入](https://www.taosdata.com/cn/documentation/taos-sql#insert) 章节。
-
-:::tip
-
-- 要提高写入效率,需要批量写入。一批写入的记录条数越多,插入效率就越高。但一条记录不能超过 16K,一条 SQL 语句总长度不能超过 1M 。
-- TDengine 支持多线程同时写入,要进一步提高写入速度,一个客户端需要打开 20 个以上的线程同时写。但线程数达到一定数量后,无法再提高,甚至还会下降,因为线程频繁切换,带来额外开销。
-- 对同一张表,如果新插入记录的时间戳已经存在,默认情形下(UPDATE=0)新记录将被直接抛弃,也就是说,在一张表里,时间戳必须是唯一的。如果应用自动生成记录,很有可能生成的时间戳是一样的,这样,成功插入的记录条数会小于应用插入的记录条数。如果在创建数据库时使用了 UPDATE 1 选项,插入相同时间戳的新记录将覆盖原有记录。
-- 写入的数据的时间戳必须大于当前时间减去配置参数 keep 的时间。如果 keep 配置为 3650 天,那么无法写入比 3650 天还早的数据。写入数据的时间戳也不能大于当前时间加配置参数 days。如果 days 为 2,那么无法写入比当前时间还晚 2 天的数据。
-
-:::
-
-## 示例程序
-
-### 普通 SQL 写入
-
-
-
-
-
-
-
-
-
-
-
-### 动态绑定写入
-
-(补充介绍)
-
-### 示例代码
-
-
-
-
-
-
-
-
-
-
diff --git a/docs-cn/06-insert-data/02-influxdb-line.mdx b/docs-cn/06-insert-data/02-influxdb-line.mdx
deleted file mode 100644
index 9076b5bad488f1dfb40f25542ad7505b5a5c85b9..0000000000000000000000000000000000000000
--- a/docs-cn/06-insert-data/02-influxdb-line.mdx
+++ /dev/null
@@ -1,7 +0,0 @@
----
-sidebar_label: InfluxDB Line 协议
----
-
-# InfluxDB Line 协议
-
-## 示例代码
diff --git a/docs-cn/06-insert-data/03-opentsdb-telnet.mdx b/docs-cn/06-insert-data/03-opentsdb-telnet.mdx
deleted file mode 100644
index 0bb8b33c8e98c1e20653a4b2af6e565d9b6e1d6d..0000000000000000000000000000000000000000
--- a/docs-cn/06-insert-data/03-opentsdb-telnet.mdx
+++ /dev/null
@@ -1,7 +0,0 @@
----
-sidebar_label: OpentsDB Telnet 协议
----
-
-# OpentsDB Telnet 协议
-
-## 示例代码
\ No newline at end of file
diff --git a/docs-cn/06-insert-data/04-opentsdb-json.mdx b/docs-cn/06-insert-data/04-opentsdb-json.mdx
deleted file mode 100644
index 99c62d56cd504bc6b6a1f1c3a0179eebdc24d553..0000000000000000000000000000000000000000
--- a/docs-cn/06-insert-data/04-opentsdb-json.mdx
+++ /dev/null
@@ -1,7 +0,0 @@
----
-sidebar_label: OpentsDB JSON 格式协议
----
-
-# OpentsDB JSON 格式协议
-
-## 示例代码
diff --git a/docs-cn/06-insert-data/_category_.yml b/docs-cn/06-insert-data/_category_.yml
deleted file mode 100644
index 1b37afd70abc99638dd86b02ada3e02f61d1c526..0000000000000000000000000000000000000000
--- a/docs-cn/06-insert-data/_category_.yml
+++ /dev/null
@@ -1,15 +0,0 @@
-label: 写入数据
-link:
- type: generated-index
- description: "TDengine 支持多种接口写入数据,包括 SQL,Prometheus,Telegraf,collectd,StatsD,EMQ MQTT Broker,HiveMQ Broker,CSV 文件等,后续还将提供 Kafka,OPC 等接口。数据可以单条插入,也可以批量插入,可以插入一个数据采集点的数据,也可以同时插入多个数据采集点的数据。支持多线程插入,支持时间乱序数据插入,也支持历史数据插入。"
- keywords:
- [
- SQL,
- Prometheus,
- Telegraf,
- collectd,
- StatsD,
- EMQ MQTT Broker,
- HiveMQ Broker,
- CSV,
- ]
diff --git a/docs-cn/08-advance-feature/04-udf.md b/docs-cn/08-advance-feature/04-udf.md
deleted file mode 100644
index 2cc88d8963e9eb57e908ed3f062fe287301b1d30..0000000000000000000000000000000000000000
--- a/docs-cn/08-advance-feature/04-udf.md
+++ /dev/null
@@ -1,412 +0,0 @@
----
-sidebar_label: UDF
----
-
-# UDF(用户定义函数)
-
-在有些应用场景中,应用逻辑需要的查询无法直接使用系统内置的函数来表示。利用 UDF 功能,TDengine 可以插入用户编写的处理代码并在查询中使用它们,就能够很方便地解决特殊应用场景中的使用需求。 UDF 通常以数据表中的一列数据做为输入,同时支持以嵌套子查询的结果作为输入。
-
-从 2.2.0.0 版本开始,TDengine 支持通过 C/C++ 语言进行 UDF 定义。接下来结合示例讲解 UDF 的使用方法。
-
-## 用 C/C++ 语言来定义 UDF
-
-TDengine 提供 3 个 UDF 的源代码示例,分别为:
-
-- [add_one.c](#add_one.c)
-- [abs_max.c](#abs_max.c)
-- [demo.c](#demo.c)
-
-### 标量函数
-
-[add_one.c](https://github.com/taosdata/TDengine/blob/develop/tests/script/sh/add_one.c) 是结构最简单的 UDF 实现。其功能为:对传入的一个数据列(可能因 WHERE 子句进行了筛选)中的每一项,都输出 +1 之后的值,并且要求输入的列数据类型为 INT。
-
-这一具体的处理逻辑在函数 `void add_one(char* data, short itype, short ibytes, int numOfRows, long long* ts, char* dataOutput, char* interBuf, char* tsOutput, int* numOfOutput, short otype, short obytes, SUdfInit* buf)` 中定义。这类用于实现 UDF 的基础计算逻辑的函数,我们称为 udfNormalFunc,也就是对行数据块的标量计算函数。需要注意的是,udfNormalFunc 的参数项是固定的,用于按照约束完成与引擎之间的数据交换。
-
-- udfNormalFunc 中各参数的具体含义是:
- - data:输入数据。
- - itype:输入数据的类型。这里采用的是短整型表示法,与各种数据类型对应的值可以参见 [column_meta 中的列类型说明](https://www.taosdata.com/cn/documentation/connector#column_meta)。例如 4 用于表示 INT 型。
- - iBytes:输入数据中每个值会占用的字节数。
- - numOfRows:输入数据的总行数。
- - ts:主键时间戳在输入中的列数据(只读)。
- - dataOutput:输出数据的缓冲区,缓冲区大小为用户指定的输出类型大小 \* numOfRows。
- - interBuf:中间计算结果的缓冲区,大小为用户在创建 UDF 时指定的 BUFSIZE 大小。通常用于计算中间结果与最终结果不一致时使用,由引擎负责分配与释放。
- - tsOutput:主键时间戳在输出时的列数据,如果非空可用于输出结果对应的时间戳。
- - numOfOutput:输出结果的个数(行数)。
- - oType:输出数据的类型。取值含义与 itype 参数一致。
- - oBytes:输出数据中每个值占用的字节数。
- - buf:用于在 UDF 与引擎间的状态控制信息传递块。
-
-### 聚合函数
-
-[abs_max.c](https://github.com/taosdata/TDengine/blob/develop/tests/script/sh/abs_max.c) 实现的是一个聚合函数,功能是对一组数据按绝对值取最大值。
-
-其计算过程为:与所在查询语句相关的数据会被分为多个行数据块,对每个行数据块调用 udfNormalFunc(在本例的实现代码中,实际函数名是 `abs_max`)来生成每个子表的中间结果,再将子表的中间结果调用 udfMergeFunc(本例中,其实际的函数名是 `abs_max_merge`)进行聚合,生成超级表的最终聚合结果或中间结果。聚合查询最后还会通过 udfFinalizeFunc(本例中,其实际的函数名是 `abs_max_finalize`)再把超级表的中间结果处理为最终结果,最终结果只能含 0 或 1 条结果数据。
-
-值得注意的是,udfNormalFunc、udfMergeFunc、udfFinalizeFunc 之间,函数名约定使用相同的前缀,此前缀即 udfNormalFunc 的实际函数名。udfMergeFunc 的函数名后缀 `_merge`、udfFinalizeFunc 的函数名后缀 `_finalize`,是 UDF 实现规则的一部分,系统会按照这些函数名后缀来调用相应功能。
-
-- udfMergeFunc 用于对计算中间结果进行聚合,只有针对超级表的聚合查询才需要调用该函数。本例中 udfMergeFunc 对应的实现函数为 `void abs_max_merge(char* data, int32_t numOfRows, char* dataOutput, int32_t* numOfOutput, SUdfInit* buf)`,其中各参数的具体含义是:
-
- - data:udfNormalFunc 的输出数据数组,如果使用了 interBuf 那么 data 就是 interBuf 的数组。
- - numOfRows:data 中数据的行数。
- - dataOutput:输出数据的缓冲区,大小等于一条最终结果的大小。如果此时输出还不是最终结果,可以选择输出到 interBuf 中即 data 中。
- - numOfOutput:输出结果的个数(行数)。
- - buf:用于在 UDF 与引擎间的状态控制信息传递块。
-
-- udfFinalizeFunc 用于对计算结果进行最终计算,通常用于有 interBuf 使用的场景。本例中 udfFinalizeFunc 对应的实现函数为 `void abs_max_finalize(char* dataOutput, char* interBuf, int* numOfOutput, SUdfInit* buf)`,其中各参数的具体含义是:
- - dataOutput:输出数据的缓冲区。
- - interBuf:中间结算结果缓冲区,可作为输入。
- - numOfOutput:输出数据的个数,对聚合函数来说只能是 0 或者 1。
- - buf:用于在 UDF 与引擎间的状态控制信息传递块。
-
-其他典型场景,如协方差的计算,即可通过定义聚合 UDF 的方式实现。
-
-### 其他 UDF 函数
-
-用户 UDF 程序除了需要实现上面几个函数外,还有两个用于初始化和释放 UDF 与引擎间的状态控制信息传递块的函数。具体来说,也即对应 udfInitFunc 和 udfDestroyFunc。其函数名命名规则同样是采取以 udfNormalFunc 的实际函数名为前缀,以 `_init` 和 `_destroy` 为后缀。系统会在初始化和资源释放时调用对应名称的函数。
-
-- udfInitFunc 用于初始化状态控制信息传递块。上例中 udfInitFunc 对应的实现函数为 `int abs_max_init(SUdfInit* buf)`,其中各参数的具体含义是:
-
- - buf:用于在 UDF 与引擎间的状态控制信息传递块。
-
-- udfDestroyFunc 用于释放状态控制信息传递块。上例中 udfDestroyFunc 对应的实现函数为 `void abs_max_destroy(SUdfInit* buf)`,其中各参数的具体含义是:
- - buf:用于在 UDF 与引擎间的状态控制信息传递块。
-
-目前该功能暂时没有实际意义,待后续扩展使用。
-
-### UDF 实现方式的规则总结
-
-根据 UDF 函数类型的不同,用户所要实现的功能函数也不同:
-
-- 标量函数:UDF 中需实现 udfNormalFunc。
-- 聚合函数:UDF 中需实现 udfNormalFunc、udfMergeFunc(对超级表查询)、udfFinalizeFunc。
-
-需要注意的是,如果对应的函数不需要具体的功能,也需要实现一个空函数。
-
-## 编译 UDF
-
-用户定义函数的 C 语言源代码无法直接被 TDengine 系统使用,而是需要先编译为 .so 链接库,之后才能载入 TDengine 系统。
-
-例如,按照上一章节描述的规则准备好了用户定义函数的源代码 add_one.c,那么可以执行如下指令编译得到动态链接库文件:
-
-```bash
-gcc -g -O0 -fPIC -shared add_one.c -o add_one.so
-```
-
-这样就准备好了动态链接库 add_one.so 文件,可以供后文创建 UDF 时使用了。为了保证可靠的系统运行,编译器 GCC 推荐使用 7.5 及以上版本。
-
-## 在系统中管理和使用 UDF
-
-### 创建 UDF
-
-用户可以通过 SQL 指令在系统中加载客户端所在主机上的 UDF 函数库(不能通过 RESTful 接口或 HTTP 管理界面来进行这一过程)。一旦创建成功,则当前 TDengine 集群的所有用户都可以在 SQL 指令中使用这些函数。UDF 存储在系统的 MNode 节点上,因此即使重启 TDengine 系统,已经创建的 UDF 也仍然可用。
-
-在创建 UDF 时,需要区分标量函数和聚合函数。如果创建时声明了错误的函数类别,则可能导致通过 SQL 指令调用函数时出错。此外, UDF 支持输入与输出类型不一致,用户需要保证输入数据类型与 UDF 程序匹配,UDF 输出数据类型与 OUTPUTTYPE 匹配。
-
-- 创建标量函数:`CREATE FUNCTION ids(X) AS ids(Y) OUTPUTTYPE typename(Z) [ BUFSIZE B ];`
-
- - ids(X):标量函数未来在 SQL 指令中被调用时的函数名,必须与函数实现中 udfNormalFunc 的实际名称一致;
- - ids(Y):包含 UDF 函数实现的动态链接库的库文件绝对路径(指的是库文件在当前客户端所在主机上的保存路径,通常是指向一个 .so 文件),这个路径需要用英文单引号或英文双引号括起来;
- - typename(Z):此函数计算结果的数据类型,与上文中 udfNormalFunc 的 itype 参数不同,这里不是使用数字表示法,而是直接写类型名称即可;
- - B:中间计算结果的缓冲区大小,单位是字节,最小 0,最大 512,如果不使用可以不设置。
-
- 例如,如下语句可以把 add_one.so 创建为系统中可用的 UDF:
-
- ```sql
- CREATE FUNCTION add_one AS "/home/taos/udf_example/add_one.so" OUTPUTTYPE INT;
- ```
-
-- 创建聚合函数:`CREATE AGGREGATE FUNCTION ids(X) AS ids(Y) OUTPUTTYPE typename(Z) [ BUFSIZE B ];`
-
- - ids(X):聚合函数未来在 SQL 指令中被调用时的函数名,必须与函数实现中 udfNormalFunc 的实际名称一致;
- - ids(Y):包含 UDF 函数实现的动态链接库的库文件绝对路径(指的是库文件在当前客户端所在主机上的保存路径,通常是指向一个 .so 文件),这个路径需要用英文单引号或英文双引号括起来;
- - typename(Z):此函数计算结果的数据类型,与上文中 udfNormalFunc 的 itype 参数不同,这里不是使用数字表示法,而是直接写类型名称即可;
- - B:中间计算结果的缓冲区大小,单位是字节,最小 0,最大 512,如果不使用可以不设置。
-
- 关于中间计算结果的使用,可以参考示例程序[demo.c](https://github.com/taosdata/TDengine/blob/develop/tests/script/sh/demo.c)
-
- 例如,如下语句可以把 demo.so 创建为系统中可用的 UDF:
-
- ```sql
- CREATE AGGREGATE FUNCTION demo AS "/home/taos/udf_example/demo.so" OUTPUTTYPE DOUBLE bufsize 14;
- ```
-
-### 管理 UDF
-
-- 删除指定名称的用户定义函数:`DROP FUNCTION ids(X);`
- - ids(X):此参数的含义与 CREATE 指令中的 ids(X) 参数一致,也即要删除的函数的名字,例如 `DROP FUNCTION add_one;`。
-- 显示系统中当前可用的所有 UDF:`SHOW FUNCTIONS;`
-
-### 调用 UDF
-
-在 SQL 指令中,可以直接以在系统中创建 UDF 时赋予的函数名来调用用户定义函数。例如:
-
-```sql
-SELECT X(c) FROM table/stable;
-```
-
-表示对名为 c 的数据列调用名为 X 的用户定义函数。SQL 指令中用户定义函数可以配合 WHERE 等查询特性来使用。
-
-## UDF 的一些使用限制
-
-在当前版本下,使用 UDF 存在如下这些限制:
-
-1. 在创建和调用 UDF 时,服务端和客户端都只支持 Linux 操作系统;
-2. UDF 不能与系统内建的 SQL 函数混合使用,暂不支持在一条 SQL 语句中使用多个不同名的 UDF ;
-3. UDF 只支持以单个数据列作为输入;
-4. UDF 只要创建成功,就会被持久化存储到 MNode 节点中;
-5. 无法通过 RESTful 接口来创建 UDF;
-6. UDF 在 SQL 中定义的函数名,必须与 .so 库文件实现中的接口函数名前缀保持一致,也即必须是 udfNormalFunc 的名称,而且不可与 TDengine 中已有的内建 SQL 函数重名。
-
-## 代码附件
-
-### [add_one.c](https://github.com/taosdata/TDengine/blob/develop/tests/script/sh/add_one.c)
-
-```c
-#include
-#include
-#include
-
-typedef struct SUdfInit{
- int maybe_null; /* 1 if function can return NULL */
- int decimals; /* for real functions */
- long long length; /* For string functions */
- char *ptr; /* free pointer for function data */
- int const_item; /* 0 if result is independent of arguments */
-} SUdfInit;
-
-void add_one(char* data, short itype, short ibytes, int numOfRows, long long* ts, char* dataOutput, char* interBUf, char* tsOutput,
- int* numOfOutput, short otype, short obytes, SUdfInit* buf) {
- int i;
- int r = 0;
- // printf("add_one input data:%p, type:%d, rows:%d, ts:%p,%lld, dataoutput:%p, tsOutput:%p, numOfOutput:%p, buf:%p\n", data, itype, numOfRows, ts, *ts, dataOutput, tsOutput, numOfOutput, buf);
- if (itype == 4) {
- for(i=0;i
-#include
-#include
-#include
-
-typedef struct SUdfInit{
- int maybe_null; /* 1 if function can return NULL */
- int decimals; /* for real functions */
- int64_t length; /* For string functions */
- char *ptr; /* free pointer for function data */
- int const_item; /* 0 if result is independent of arguments */
-} SUdfInit;
-
-
-#define TSDB_DATA_INT_NULL 0x80000000L
-#define TSDB_DATA_BIGINT_NULL 0x8000000000000000L
-
-void abs_max(char* data, short itype, short ibytes, int numOfRows, int64_t* ts, char* dataOutput, char* interBuf, char* tsOutput,
- int* numOfOutput, short otype, short obytes, SUdfInit* buf) {
- int i;
- int64_t r = 0;
- // printf("abs_max input data:%p, type:%d, rows:%d, ts:%p, %" PRId64 ", dataoutput:%p, tsOutput:%p, numOfOutput:%p, buf:%p\n", data, itype, numOfRows, ts, *ts, dataOutput, tsOutput, numOfOutput, buf);
- if (itype == 5) {
- r=*(int64_t *)dataOutput;
- *numOfOutput=0;
-
- for(i=0;i r) {
- r = v;
- }
- }
-
- *(int64_t *)dataOutput=r;
-
- // printf("abs_max out, dataoutput:%" PRId64", numOfOutput:%d\n", *(int64_t *)dataOutput, *numOfOutput);
- }else {
- *numOfOutput=0;
- }
-}
-
-
-
-void abs_max_finalize(char* dataOutput, char* interBuf, int* numOfOutput, SUdfInit* buf) {
- int i;
- //int64_t r = 0;
- // printf("abs_max_finalize dataoutput:%p:%d, numOfOutput:%d, buf:%p\n", dataOutput, *dataOutput, *numOfOutput, buf);
- // *numOfOutput=1;
- // printf("abs_max finalize, dataoutput:%" PRId64", numOfOutput:%d\n", *(int64_t *)dataOutput, *numOfOutput);
-}
-
-void abs_max_merge(char* data, int32_t numOfRows, char* dataOutput, int32_t* numOfOutput, SUdfInit* buf) {
- int64_t r = 0;
-
- if (numOfRows > 0) {
- r = *((int64_t *)data);
- }
- // printf("abs_max_merge numOfRows:%d, dataoutput:%p, buf:%p\n", numOfRows, dataOutput, buf);
- for (int i = 1; i < numOfRows; ++i) {
- // printf("abs_max_merge %d - %" PRId64"\n", i, *((int64_t *)data + i));
- if (*((int64_t*)data + i) > r) {
- r= *((int64_t*)data + i);
- }
- }
-
- *(int64_t*)dataOutput=r;
- if (numOfRows > 0) {
- *numOfOutput=1;
- } else {
- *numOfOutput=0;
- }
-
- // printf("abs_max_merge, dataoutput:%" PRId64", numOfOutput:%d\n", *(int64_t *)dataOutput, *numOfOutput);
-}
-
-
-int abs_max_init(SUdfInit* buf) {
- // printf("abs_max init\n");
- return 0;
-}
-
-
-void abs_max_destroy(SUdfInit* buf) {
- // printf("abs_max destroy\n");
-}
-```
-
-### [demo.c](https://github.com/taosdata/TDengine/blob/develop/tests/script/sh/demo.c)
-
-```c
-#include
-#include
-#include
-
-typedef struct SUdfInit{
- int maybe_null; /* 1 if function can return NULL */
- int decimals; /* for real functions */
- long long length; /* For string functions */
- char *ptr; /* free pointer for function data */
- int const_item; /* 0 if result is independent of arguments */
-} SUdfInit;
-
-typedef struct SDemo{
- double sum;
- int num;
- short otype;
-}SDemo;
-
-#define FLOAT_NULL 0x7FF00000 // it is an NAN
-#define DOUBLE_NULL 0x7FFFFF0000000000L // it is an NAN
-
-
-void demo(char* data, short itype, short ibytes, int numOfRows, long long* ts, char* dataOutput, char* interBuf, char* tsOutput,
- int* numOfOutput, short otype, short obytes, SUdfInit* buf) {
- int i;
- double r = 0;
- SDemo *p = (SDemo *)interBuf;
- SDemo *q = (SDemo *)dataOutput;
- printf("demo input data:%p, type:%d, rows:%d, ts:%p,%lld, dataoutput:%p, interBUf:%p, tsOutput:%p, numOfOutput:%p, buf:%p\n", data, itype, numOfRows, ts, *ts, dataOutput, interBuf, tsOutput, numOfOutput, buf);
-
- for(i=0;isum += r*r;
- }
-
- p->otype = otype;
- p->num += numOfRows;
-
- q->sum = p->sum;
- q->num = p->num;
- q->otype = p->otype;
-
- *numOfOutput=1;
-
- printf("demo out, sum:%f, num:%d, numOfOutput:%d\n", p->sum, p->num, *numOfOutput);
-}
-
-
-void demo_merge(char* data, int32_t numOfRows, char* dataOutput, int32_t* numOfOutput, SUdfInit* buf) {
- int i;
- SDemo *p = (SDemo *)data;
- SDemo res = {0};
- printf("demo_merge input data:%p, rows:%d, dataoutput:%p, numOfOutput:%p, buf:%p\n", data, numOfRows, dataOutput, numOfOutput, buf);
-
- for(i=0;isum * p->sum;
- res.num += p->num;
- p++;
- }
-
- p->sum = res.sum;
- p->num = res.num;
-
- *numOfOutput=1;
-
- printf("demo out, sum:%f, num:%d, numOfOutput:%d\n", p->sum, p->num, *numOfOutput);
-}
-
-
-
-void demo_finalize(char* dataOutput, char* interBuf, int* numOfOutput, SUdfInit* buf) {
- SDemo *p = (SDemo *)interBuf;
- printf("demo_finalize interbuf:%p, numOfOutput:%p, buf:%p, sum:%f, num:%d\n", interBuf, numOfOutput, buf, p->sum, p->num);
- if (p->otype == 6) {
- if (p->num != 30000) {
- *(unsigned int *)dataOutput = FLOAT_NULL;
- } else {
- *(float *)dataOutput = (float)(p->sum / p->num);
- }
- printf("finalize values:%f\n", *(float *)dataOutput);
- } else if (p->otype == 7) {
- if (p->num != 30000) {
- *(unsigned long long *)dataOutput = DOUBLE_NULL;
- } else {
- *(double *)dataOutput = (double)(p->sum / p->num);
- }
- printf("finalize values:%f\n", *(double *)dataOutput);
- }
-
- *numOfOutput=1;
-
- printf("demo finalize, numOfOutput:%d\n", *numOfOutput);
-}
-
-
-int demo_init(SUdfInit* buf) {
- printf("demo init\n");
- return 0;
-}
-
-
-void demo_destroy(SUdfInit* buf) {
- printf("demo destroy\n");
-}
-```
diff --git a/docs-cn/08-advance-feature/08-advance-feature.md b/docs-cn/08-advance-feature/08-advance-feature.md
deleted file mode 100644
index 4de393203389c0df473d471c3d934aa640d06b49..0000000000000000000000000000000000000000
--- a/docs-cn/08-advance-feature/08-advance-feature.md
+++ /dev/null
@@ -1,19 +0,0 @@
-# 高级功能
-
-本章介绍以下TDengine中的高级功能。
-
-## 连续查询
-
-连续查询是一个按照预设频率自动执行的查询功能,提供按照时间窗口的聚合查询能力,是一种简化的时间驱动流式计算。
-
-## 订阅
-
-轻量级的数据订阅与推送服务。连续写入到TDengine中时序数据均能够推动到订阅客户端。
-
-## 缓存
-
-提供写驱动的缓存管理机制,将每个表最近的一条写入记录数据持续保存在缓存中,可以提供给高性能的最近状态查询。
-
-## 用户定义函数
-
-支持用户编码的聚合函数和标量函数,在查询中嵌入并使用用户定义函数,拓展查询的能力和功能。
diff --git a/docs-cn/08-advance-feature/_05-stream.md b/docs-cn/08-advance-feature/_05-stream.md
deleted file mode 100644
index 30a9dbdf6888c2981e076c950350bfe1c6769f15..0000000000000000000000000000000000000000
--- a/docs-cn/08-advance-feature/_05-stream.md
+++ /dev/null
@@ -1,5 +0,0 @@
----
-sidebar_label: 流计算
----
-
-# 流计算
diff --git a/docs-cn/08-advance-feature/_category_.yml b/docs-cn/08-advance-feature/_category_.yml
deleted file mode 100644
index 29235a943efebff0bd732fad8654f138c2b24bc9..0000000000000000000000000000000000000000
--- a/docs-cn/08-advance-feature/_category_.yml
+++ /dev/null
@@ -1 +0,0 @@
-label: 高级功能
\ No newline at end of file
diff --git a/docs-cn/09-third-party/02-prometheus.md b/docs-cn/09-third-party/02-prometheus.md
deleted file mode 100644
index 605fe817fe2dde219dea2448f8c8e45fa8a50183..0000000000000000000000000000000000000000
--- a/docs-cn/09-third-party/02-prometheus.md
+++ /dev/null
@@ -1,34 +0,0 @@
----
-sidebar_label: Prometheus
----
-
-# Prometheus 写入
-
-remote_read 和 remote_write 是 Prometheus 数据读写分离的集群方案。
-只需要将 remote_read 和 remote_write url 指向 taosAdapter 对应的 url 同时设置 Basic 验证即可使用。
-
-- remote_read url : `http://host_to_taosAdapter:port(default 6041)/prometheus/v1/remote_read/:db`
-- remote_write url : `http://host_to_taosAdapter:port(default 6041)/prometheus/v1/remote_write/:db`
-
-Basic 验证:
-
-- username: TDengine 连接用户名
-- password: TDengine 连接密码
-
-示例 prometheus.yml 如下:
-
-```yaml
-remote_write:
- - url: "http://localhost:6041/prometheus/v1/remote_write/prometheus_data"
- basic_auth:
- username: root
- password: taosdata
-
-remote_read:
- - url: "http://localhost:6041/prometheus/v1/remote_read/prometheus_data"
- basic_auth:
- username: root
- password: taosdata
- remote_timeout: 10s
- read_recent: true
-```
diff --git a/docs-cn/09-third-party/03-telegraf.md b/docs-cn/09-third-party/03-telegraf.md
deleted file mode 100644
index 191193b426995fb7e3036605f52ddef963da0d55..0000000000000000000000000000000000000000
--- a/docs-cn/09-third-party/03-telegraf.md
+++ /dev/null
@@ -1,32 +0,0 @@
----
-sidebar_label: Telegraf
----
-
-# Telegraf 写入
-
-安装 Telegraf 请参考[官方文档](https://portal.influxdata.com/downloads/)。
-
-TDengine 新版本(2.3.0.0+)包含一个 taosAdapter 独立程序,负责接收包括 Telegraf 的多种应用的数据写入。
-
-配置方法,在 /etc/telegraf/telegraf.conf 增加如下文字,其中 database name 请填写希望在 TDengine 保存 Telegraf 数据的数据库名,TDengine server/cluster host、username 和 password 填写 TDengine 实际值:
-
-```
-[[outputs.http]]
- url = "http://:6041/influxdb/v1/write?db="
- method = "POST"
- timeout = "5s"
- username = ""
- password = ""
- data_format = "influx"
- influx_max_line_bytes = 250
-```
-
-然后重启 telegraf:
-
-```
-sudo systemctl start telegraf
-```
-
-即可在 TDengine 中查询 metrics 数据库中 Telegraf 写入的数据。
-
-taosAdapter 相关配置参数请参考 taosadapter --help 命令输出以及相关文档。
diff --git a/docs-cn/09-third-party/05-collectd.md b/docs-cn/09-third-party/05-collectd.md
deleted file mode 100644
index c94dd8cb977c0a01d67839467b04e414e33eaf3d..0000000000000000000000000000000000000000
--- a/docs-cn/09-third-party/05-collectd.md
+++ /dev/null
@@ -1,26 +0,0 @@
----
-sidebar_label: collectd
----
-
-# collectd 写入
-
-安装 collectd,请参考[官方文档](https://collectd.org/download.shtml)。
-
-TDengine 新版本(2.3.0.0+)包含一个 taosAdapter 独立程序,负责接收包括 collectd 的多种应用的数据写入。
-
-在 /etc/collectd/collectd.conf 文件中增加如下内容,其中 host 和 port 请填写 TDengine 和 taosAdapter 配置的实际值:
-
-```
-LoadPlugin network
-
- Server "" ""
-
-```
-
-重启 collectd
-
-```
-sudo systemctl start collectd
-```
-
-taosAdapter 相关配置参数请参考 taosadapter --help 命令输出以及相关文档。
diff --git a/docs-cn/09-third-party/06-statsd.md b/docs-cn/09-third-party/06-statsd.md
deleted file mode 100644
index b1bf4b06e4a52258df0a2aa3ed5a0a4c7872abb5..0000000000000000000000000000000000000000
--- a/docs-cn/09-third-party/06-statsd.md
+++ /dev/null
@@ -1,31 +0,0 @@
----
-sidebar_label: StatsD
----
-
-# StatsD 直接写入
-
-安装 StatsD
-请参考[官方文档](https://github.com/statsd/statsd)。
-
-TDengine 新版本(2.3.0.0+)包含一个 taosAdapter 独立程序,负责接收包括 StatsD 的多种应用的数据写入。
-
-在 config.js 文件中增加如下内容后启动 StatsD,其中 host 和 port 请填写 TDengine 和 taosAdapter 配置的实际值:
-
-```
-backends 部分添加 "./backends/repeater"
-repeater 部分添加 { host:'', port: }
-```
-
-示例配置文件:
-
-```
-{
-port: 8125
-, backends: ["./backends/repeater"]
-, repeater: [{ host: '127.0.0.1', port: 6044}]
-}
-```
-
-taosAdapter 相关配置参数请参考 taosadapter --help 命令输出以及相关文档。
-
-icinga2 可以收集监控和性能数据并写入 OpenTSDB,taosAdapter 可以支持接收 icinga2 的数据并写入到 TDengine 中。
diff --git a/docs-cn/09-third-party/07-icinga2.md b/docs-cn/09-third-party/07-icinga2.md
deleted file mode 100644
index d83e4fcd309ba2ce54bb0a8a8754bdd2ca19968d..0000000000000000000000000000000000000000
--- a/docs-cn/09-third-party/07-icinga2.md
+++ /dev/null
@@ -1,18 +0,0 @@
----
-sidebar_label: icinga2
----
-
-# icinga2 写入
-
-- 参考链接 `https://icinga.com/docs/icinga-2/latest/doc/14-features/#opentsdb-writer` 使能 opentsdb-writer
-- 使能 taosAdapter 配置项 opentsdb_telnet.enable
-- 修改配置文件 /etc/icinga2/features-enabled/opentsdb.conf
-
-```
-object OpenTsdbWriter "opentsdb" {
- host = "host to taosAdapter"
- port = 6048
-}
-```
-
-taosAdapter 相关配置参数请参考 taosadapter --help 命令输出以及相关文档。
\ No newline at end of file
diff --git a/docs-cn/09-third-party/08-tcollector.md b/docs-cn/09-third-party/08-tcollector.md
deleted file mode 100644
index 70ae0762ee3e1d39876569d4169b26afe1038a34..0000000000000000000000000000000000000000
--- a/docs-cn/09-third-party/08-tcollector.md
+++ /dev/null
@@ -1,12 +0,0 @@
----
-sidebar_label: TCollector
----
-
-# TCollector 写入
-
-TCollector 是一个在客户侧收集本地收集器并发送数据到 OpenTSDB 的进程,taosAdaapter 可以支持接收 TCollector 的数据并写入到 TDengine 中。
-
-使能 taosAdapter 配置项 opentsdb_telnet.enable
-修改 TCollector 配置文件,修改 OpenTSDB 宿主机地址为 taosAdapter 被部署的地址,并修改端口号为 taosAdapter 使用的端口(默认 6049)。
-
-taosAdapter 相关配置参数请参考 taosadapter --help 命令输出以及相关文档。
diff --git a/docs-cn/09-third-party/09-third-party.md b/docs-cn/09-third-party/09-third-party.md
deleted file mode 100644
index 6c57defe891c056f42da0607e1a6791fa2ff2e21..0000000000000000000000000000000000000000
--- a/docs-cn/09-third-party/09-third-party.md
+++ /dev/null
@@ -1,3 +0,0 @@
-# 第三方工具
-
-TDengine 通过对标准 SQL 命令、常用数据库连接器标准(例如 JDBC)、ORM 以及其他流行时序数据库写入协议(例如 InfluxDB Line Protocol、OpenTSDB JSON、OpenTSDB Telnet 等)的支持可以使 TDengine 非常容易和第三方工具共同使用。
diff --git a/docs-cn/09-third-party/_category_.yml b/docs-cn/09-third-party/_category_.yml
deleted file mode 100644
index 95aee1e75b1165dcb963a376a86cc58b3917e054..0000000000000000000000000000000000000000
--- a/docs-cn/09-third-party/_category_.yml
+++ /dev/null
@@ -1 +0,0 @@
-label: 第三方工具
diff --git a/docs-cn/10-cluster/01-deploy.md b/docs-cn/10-cluster/01-deploy.md
new file mode 100644
index 0000000000000000000000000000000000000000..cee140c0ec13bc9c8052a599a2147acc1aa15a8d
--- /dev/null
+++ b/docs-cn/10-cluster/01-deploy.md
@@ -0,0 +1,138 @@
+---
+title: 集群部署
+---
+
+## 准备工作
+
+### 第零步
+
+规划集群所有物理节点的 FQDN,将规划好的 FQDN 分别添加到每个物理节点的 /etc/hosts;修改每个物理节点的 /etc/hosts,将所有集群物理节点的 IP 与 FQDN 的对应添加好。【如部署了 DNS,请联系网络管理员在 DNS 上做好相关配置】
+
+### 第一步
+
+如果搭建集群的物理节点中,存有之前的测试数据、装过 1.X 的版本,或者装过其他版本的 TDengine,请先将其删除,并清空所有数据(如果需要保留原有数据,请联系涛思交付团队进行旧版本升级、数据迁移),具体步骤请参考博客[《TDengine 多种安装包的安装和卸载》](https://www.taosdata.com/blog/2019/08/09/566.html)。
+
+:::note
+因为 FQDN 的信息会写进文件,如果之前没有配置或者更改 FQDN,且启动了 TDengine。请一定在确保数据无用或者备份的前提下,清理一下之前的数据(rm -rf /var/lib/taos/\*);
+:::
+
+:::note
+客户端所在服务器也需要配置,确保它可以正确解析每个节点的 FQDN 配置,不管是通过 DNS 服务,还是修改 hosts 文件。
+:::
+
+### 第二步
+
+建议关闭所有物理节点的防火墙,至少保证端口:6030 - 6042 的 TCP 和 UDP 端口都是开放的。强烈建议先关闭防火墙,集群搭建完毕之后,再来配置端口;
+
+### 第三步
+
+在所有物理节点安装 TDengine,且版本必须是一致的,但不要启动 taosd。安装时,提示输入是否要加入一个已经存在的 TDengine 集群时,第一个物理节点直接回车创建新集群,后续物理节点则输入该集群任何一个在线的物理节点的 FQDN:端口号(默认 6030);
+
+### 第四步
+
+检查所有数据节点,以及应用程序所在物理节点的网络设置:
+
+每个物理节点上执行命令 `hostname -f`,查看和确认所有节点的 hostname 是不相同的(应用驱动所在节点无需做此项检查);
+
+每个物理节点上执行 ping host,其中 host 是其他物理节点的 hostname,看能否 ping 通其它物理节点;如果不能 ping 通,需要检查网络设置,或 /etc/hosts 文件(Windows 系统默认路径为 C:\Windows\system32\drivers\etc\hosts),或 DNS 的配置。如果无法 ping 通,是无法组成集群的;
+
+从应用运行的物理节点,ping taosd 运行的数据节点,如果无法 ping 通,应用是无法连接 taosd 的,请检查应用所在物理节点的 DNS 设置或 hosts 文件;
+
+每个数据节点的 End Point 就是输出的 hostname 外加端口号,比如 h1.taosdata.com:6030。
+
+### 第五步
+
+修改 TDengine 的配置文件(所有节点的文件 /etc/taos/taos.cfg 都需要修改)。假设准备启动的第一个数据节点 End Point 为 h1.taosdata.com:6030,其与集群配置相关参数如下:
+
+```c
+// firstEp 是每个数据节点首次启动后连接的第一个数据节点
+firstEp h1.taosdata.com:6030
+
+// 必须配置为本数据节点的 FQDN,如果本机只有一个 hostname,可注释掉本项
+fqdn h1.taosdata.com
+
+// 配置本数据节点的端口号,缺省是 6030
+serverPort 6030
+
+// 副本数为偶数的时候,需要配置,请参考《Arbitrator 的使用》的部分
+arbitrator ha.taosdata.com:6042
+```
+
+一定要修改的参数是 firstEp 和 fqdn。在每个数据节点,firstEp 需全部配置成一样,但 fqdn 一定要配置成其所在数据节点的值。其他参数可不做任何修改,除非你很清楚为什么要修改。
+
+加入到集群中的数据节点 dnode,涉及集群相关的下表 9 项参数必须完全相同,否则不能成功加入到集群中。
+
+| **#** | **配置参数名称** | **含义** |
+| ----- | ------------------ | ------------------------------------------- |
+| 1 | numOfMnodes | 系统中管理节点个数 |
+| 2 | mnodeEqualVnodeNum | 一个 mnode 等同于 vnode 消耗的个数 |
+| 3 | offlineThreshold | dnode 离线阈值,超过该时间将导致 Dnode 离线 |
+| 4 | statusInterval | dnode 向 mnode 报告状态时长 |
+| 5 | arbitrator | 系统中裁决器的 End Point |
+| 6 | timezone | 时区 |
+| 7 | balance | 是否启动负载均衡 |
+| 8 | maxTablesPerVnode | 每个 vnode 中能够创建的最大表个数 |
+| 9 | maxVgroupsPerDb | 每个 DB 中能够使用的最大 vgroup 个数 |
+
+:::note
+在 2.0.19.0 及更早的版本中,除以上 9 项参数外,dnode 加入集群时,还会要求 locale 和 charset 参数的取值也一致。
+
+:::
+
+## 启动集群
+
+### 启动第一个数据节点
+
+按照《立即开始》里的步骤,启动第一个数据节点,例如 h1.taosdata.com,然后执行 taos,启动 taos shell,从 shell 里执行命令“SHOW DNODES”,如下所示:
+
+```
+Welcome to the TDengine shell from Linux, Client Version:2.0.0.0
+
+
+Copyright (c) 2017 by TAOS Data, Inc. All rights reserved.
+
+taos> show dnodes;
+ id | end_point | vnodes | cores | status | role | create_time |
+=====================================================================================
+ 1 | h1.taos.com:6030 | 0 | 2 | ready | any | 2020-07-31 03:49:29.202 |
+Query OK, 1 row(s) in set (0.006385s)
+
+taos>
+```
+
+上述命令里,可以看到刚启动的数据节点的 End Point 是:h1.taos.com:6030,就是这个新集群的 firstEp。
+
+### 启动后续数据节点
+
+将后续的数据节点添加到现有集群,具体有以下几步:
+
+按照《立即开始》一章的方法在每个物理节点启动 taosd;(注意:每个物理节点都需要在 taos.cfg 文件中将 firstEp 参数配置为新集群首个节点的 End Point——在本例中是 h1.taos.com:6030)
+
+在第一个数据节点,使用 CLI 程序 taos,登录进 TDengine 系统,执行命令:
+
+```sql
+CREATE DNODE "h2.taos.com:6030";
+```
+
+将新数据节点的 End Point(准备工作中第四步获知的)添加进集群的 EP 列表。“fqdn:port”需要用双引号引起来,否则出错。请注意将示例的“h2.taos.com:6030” 替换为这个新数据节点的 End Point。
+
+然后执行命令
+
+```sql
+SHOW DNODES;
+```
+
+查看新节点是否被成功加入。如果该被加入的数据节点处于离线状态,请做两个检查:
+
+查看该数据节点的 taosd 是否正常工作,如果没有正常运行,需要先检查为什么?
+查看该数据节点 taosd 日志文件 taosdlog.0 里前面几行日志(一般在 /var/log/taos 目录),看日志里输出的该数据节点 fqdn 以及端口号是否为刚添加的 End Point。如果不一致,需要将正确的 End Point 添加进去。
+按照上述步骤可以源源不断的将新的数据节点加入到集群。
+
+:::tip
+
+任何已经加入集群在线的数据节点,都可以作为后续待加入节点的 firstEp。
+firstEp 这个参数仅仅在该数据节点首次加入集群时有作用,加入集群后,该数据节点会保存最新的 mnode 的 End Point 列表,不再依赖这个参数。
+接下来,配置文件中的 firstEp 参数就主要在客户端连接的时候使用了,例如 taos shell 如果不加参数,会默认连接由 firstEp 指定的节点。
+两个没有配置 firstEp 参数的数据节点 dnode 启动后,会独立运行起来。这个时候,无法将其中一个数据节点加入到另外一个数据节点,形成集群。无法将两个独立的集群合并成为新的集群。
+
+:::
diff --git a/docs-cn/10-cluster/01-prerequisites.md b/docs-cn/10-cluster/01-prerequisites.md
deleted file mode 100644
index 8f88126c931357005fe010c6beb2a6da27f71d88..0000000000000000000000000000000000000000
--- a/docs-cn/10-cluster/01-prerequisites.md
+++ /dev/null
@@ -1,74 +0,0 @@
-# 准备工作
-## 第零步
-
-规划集群所有物理节点的 FQDN,将规划好的 FQDN 分别添加到每个物理节点的/etc/hostname;修改每个物理节点的/etc/hosts,将所有集群物理节点的 IP 与 FQDN 的对应添加好。【如部署了 DNS,请联系网络管理员在 DNS 上做好相关配置】
-
-## 第一步
-
-如果搭建集群的物理节点中,存有之前的测试数据、装过 1.X 的版本,或者装过其他版本的 TDengine,请先将其删除,并清空所有数据(如果需要保留原有数据,请联系涛思交付团队进行旧版本升级、数据迁移),具体步骤请参考博客《TDengine 多种安装包的安装和卸载》。
-
-:::note
-因为 FQDN 的信息会写进文件,如果之前没有配置或者更改 FQDN,且启动了 TDengine。请一定在确保数据无用或者备份的前提下,清理一下之前的数据(rm -rf /var/lib/taos/*);
-:::
-
-:::note
-客户端也需要配置,确保它可以正确解析每个节点的 FQDN 配置,不管是通过 DNS 服务,还是修改 hosts 文件。
-:::
-
-
-## 第二步
-
-建议关闭所有物理节点的防火墙,至少保证端口:6030 - 6042 的 TCP 和 UDP 端口都是开放的。强烈建议先关闭防火墙,集群搭建完毕之后,再来配置端口;
-
-## 第三步
-
-在所有物理节点安装 TDengine,且版本必须是一致的,但不要启动 taosd。安装时,提示输入是否要加入一个已经存在的 TDengine 集群时,第一个物理节点直接回车创建新集群,后续物理节点则输入该集群任何一个在线的物理节点的 FQDN:端口号(默认 6030);
-
-## 第四步
-
-检查所有数据节点,以及应用程序所在物理节点的网络设置:
-
-每个物理节点上执行命令hostname -f,查看和确认所有节点的 hostname 是不相同的(应用驱动所在节点无需做此项检查);
-
-每个物理节点上执行ping host,其中 host 是其他物理节点的 hostname,看能否 ping 通其它物理节点;如果不能 ping 通,需要检查网络设置,或/etc/hosts 文件(Windows 系统默认路径为 C:\Windows\system32\drivers\etc\hosts),或 DNS 的配置。如果无法 ping 通,是无法组成集群的;
-
-从应用运行的物理节点,ping taosd 运行的数据节点,如果无法 ping 通,应用是无法连接 taosd 的,请检查应用所在物理节点的 DNS 设置或 hosts 文件;
-
-每个数据节点的 End Point 就是输出的 hostname 外加端口号,比如h1.taosdata.com:6030。
-
-## 第五步
-
-修改 TDengine 的配置文件(所有节点的文件/etc/taos/taos.cfg 都需要修改)。假设准备启动的第一个数据节点 End Point 为 h1.taosdata.com:6030,其与集群配置相关参数如下:
-
-```
-// firstEp 是每个数据节点首次启动后连接的第一个数据节点
-firstEp h1.taosdata.com:6030
-
-// 必须配置为本数据节点的FQDN,如果本机只有一个hostname, 可注释掉本项
-fqdn h1.taosdata.com
-
-// 配置本数据节点的端口号,缺省是6030
-serverPort 6030
-
-// 副本数为偶数的时候,需要配置,请参考《Arbitrator的使用》的部分
-arbitrator ha.taosdata.com:6042
-```
-一定要修改的参数是 firstEp 和 fqdn。在每个数据节点,firstEp 需全部配置成一样,但 fqdn 一定要配置成其所在数据节点的值。其他参数可不做任何修改,除非你很清楚为什么要修改。
-
-加入到集群中的数据节点 dnode,涉及集群相关的下表 9 项参数必须完全相同,否则不能成功加入到集群中。
-
-| **#** | **配置参数名称** | **含义** |
-| ----- | ------------------ | ------------------------------------------- |
-| 1 | numOfMnodes | 系统中管理节点个数 |
-| 2 | mnodeEqualVnodeNum | 一个 mnode 等同于 vnode 消耗的个数 |
-| 3 | offlineThreshold | dnode 离线阈值,超过该时间将导致 Dnode 离线 |
-| 4 | statusInterval | dnode 向 mnode 报告状态时长 |
-| 5 | arbitrator | 系统中裁决器的 End Point |
-| 6 | timezone | 时区 |
-| 7 | balance | 是否启动负载均衡 |
-| 8 | maxTablesPerVnode | 每个 vnode 中能够创建的最大表个数 |
-| 9 | maxVgroupsPerDb | 每个 DB 中能够使用的最大 vgroup 个数 |
-
-:::note
-在 2.0.19.0 及更早的版本中,除以上 9 项参数外,dnode 加入集群时,还会要求 locale 和 charset 参数的取值也一致。
-:::
diff --git a/docs-cn/10-cluster/02-cluster-mgmt.md b/docs-cn/10-cluster/02-cluster-mgmt.md
index f00a68aad76b02f8e380479a89f05a6e19223c3f..6ab8ec091b898e8f441d75ef898dc0ff06fce6be 100644
--- a/docs-cn/10-cluster/02-cluster-mgmt.md
+++ b/docs-cn/10-cluster/02-cluster-mgmt.md
@@ -1,117 +1,216 @@
-# 集群部署
-## 启动第一个数据节点
-按照《立即开始》里的指示,启动第一个数据节点,例如 h1.taosdata.com,然后执行 taos, 启动 taos shell,从 shell 里执行命令"show dnodes;",如下所示:
-```
+---
+title: 数据节点管理
+---
-Welcome to the TDengine shell from Linux, Client Version:2.0.0.0
+上面已经介绍如何从零开始搭建集群。集群组建完成后,可以随时查看集群中当前的数据节点的状态,还可以添加新的数据节点进行扩容,删除数据节点,甚至手动进行数据节点之间的负载均衡操作。
+:::note
-Copyright (c) 2017 by TAOS Data, Inc. All rights reserved.
+以下所有执行命令的操作需要先登陆进 TDengine 系统,必要时请使用 root 权限。
-taos> show dnodes;
- id | end_point | vnodes | cores | status | role | create_time |
-=====================================================================================
- 1 | h1.taos.com:6030 | 0 | 2 | ready | any | 2020-07-31 03:49:29.202 |
-Query OK, 1 row(s) in set (0.006385s)
+:::
+
+## 查看数据节点
+
+启动 TDengine CLI 程序 taos,然后执行:
+
+```sql
+SHOW DNODES;
+```
+
+它将列出集群中所有的 dnode,每个 dnode 的 ID,end_point(fqdn:port),状态(ready,offline 等),vnode 数目,还未使用的 vnode 数目等信息。在添加或删除一个数据节点后,可以使用该命令查看。
+
+输出如下(具体内容仅供参考,取决于实际的集群配置)
-taos>
```
-上述命令里,可以看到这个刚启动的这个数据节点的 End Point 是:h1.taos.com:6030,就是这个新集群的 firstEp。
+taos> show dnodes;
+ id | end_point | vnodes | cores | status | role | create_time | offline reason |
+======================================================================================================================================
+ 1 | localhost:6030 | 9 | 8 | ready | any | 2022-04-15 08:27:09.359 | |
+Query OK, 1 row(s) in set (0.008298s)
+```
-## 启动后续数据节点
-将后续的数据节点添加到现有集群,具体有以下几步:
+## 查看虚拟节点组
-按照《立即开始》一章的方法在每个物理节点启动 taosd;(注意:每个物理节点都需要在 taos.cfg 文件中将 firstEp 参数配置为新集群首个节点的 End Point——在本例中是 h1.taos.com:6030)
+为充分利用多核技术,并提供 scalability,数据需要分片处理。因此 TDengine 会将一个 DB 的数据切分成多份,存放在多个 vnode 里。这些 vnode 可能分布在多个数据节点 dnode 里,这样就实现了水平扩展。一个 vnode 仅仅属于一个 DB,但一个 DB 可以有多个 vnode。vnode 所在的数据节点是 mnode 根据当前系统资源的情况,自动进行分配的,无需任何人工干预。
-在第一个数据节点,使用 CLI 程序 taos,登录进 TDengine 系统,执行命令:
+启动 CLI 程序 taos,然后执行:
-```mysql
-CREATE DNODE "h2.taos.com:6030";
+```sql
+USE SOME_DATABASE;
+SHOW VGROUPS;
```
-将新数据节点的 End Point (准备工作中第四步获知的) 添加进集群的 EP 列表。"fqdn:port"需要用双引号引起来,否则出错。请注意将示例的“h2.taos.com:6030" 替换为这个新数据节点的 End Point。
-然后执行命令
-```mysql
-SHOW DNODES;
+输出如下(具体内容仅供参考,取决于实际的集群配置)
+
+```
+taos> show dnodes;
+ id | end_point | vnodes | cores | status | role | create_time | offline reason |
+======================================================================================================================================
+ 1 | localhost:6030 | 9 | 8 | ready | any | 2022-04-15 08:27:09.359 | |
+Query OK, 1 row(s) in set (0.008298s)
+
+taos> use db;
+Database changed.
+
+taos> show vgroups;
+ vgId | tables | status | onlines | v1_dnode | v1_status | compacting |
+==========================================================================================
+ 14 | 38000 | ready | 1 | 1 | master | 0 |
+ 15 | 38000 | ready | 1 | 1 | master | 0 |
+ 16 | 38000 | ready | 1 | 1 | master | 0 |
+ 17 | 38000 | ready | 1 | 1 | master | 0 |
+ 18 | 37001 | ready | 1 | 1 | master | 0 |
+ 19 | 37000 | ready | 1 | 1 | master | 0 |
+ 20 | 37000 | ready | 1 | 1 | master | 0 |
+ 21 | 37000 | ready | 1 | 1 | master | 0 |
+Query OK, 8 row(s) in set (0.001154s)
```
-查看新节点是否被成功加入。如果该被加入的数据节点处于离线状态,请做两个检查:
-查看该数据节点的 taosd 是否正常工作,如果没有正常运行,需要先检查为什么
-查看该数据节点 taosd 日志文件 taosdlog.0 里前面几行日志(一般在/var/log/taos 目录),看日志里输出的该数据节点 fqdn 以及端口号是否为刚添加的 End Point。如果不一致,需要将正确的 End Point 添加进去。
-按照上述步骤可以源源不断的将新的数据节点加入到集群。
+## 添加数据节点
-:::tip
+启动 CLI 程序 taos,然后执行:
-任何已经加入集群在线的数据节点,都可以作为后续待加入节点的 firstEp。
-firstEp 这个参数仅仅在该数据节点首次加入集群时有作用,加入集群后,该数据节点会保存最新的 mnode 的 End Point 列表,不再依赖这个参数。
-接下来,配置文件中的 firstEp 参数就主要在客户端连接的时候使用了,例如 taos shell 如果不加参数,会默认连接由 firstEp 指定的节点。
-两个没有配置 firstEp 参数的数据节点 dnode 启动后,会独立运行起来。这个时候,无法将其中一个数据节点加入到另外一个数据节点,形成集群。无法将两个独立的集群合并成为新的集群。
+```sql
+CREATE DNODE "fqdn:port";
+```
-:::
+将新数据节点的 End Point 添加进集群的 EP 列表。“fqdn:port“需要用双引号引起来,否则出错。一个数据节点对外服务的 fqdn 和 port 可以通过配置文件 taos.cfg 进行配置,缺省是自动获取。【强烈不建议用自动获取方式来配置 FQDN,可能导致生成的数据节点的 End Point 不是所期望的】
-## 数据节点管理
-上面已经介绍如何从零开始搭建集群。集群组建完后,还可以随时添加新的数据节点进行扩容,或删除数据节点,并检查集群当前状态。
+示例如下:
+```
+taos> create dnode "localhost:7030";
+Query OK, 0 of 0 row(s) in database (0.008203s)
-提示:
+taos> show dnodes;
+ id | end_point | vnodes | cores | status | role | create_time | offline reason |
+======================================================================================================================================
+ 1 | localhost:6030 | 9 | 8 | ready | any | 2022-04-15 08:27:09.359 | |
+ 2 | localhost:7030 | 0 | 0 | offline | any | 2022-04-19 08:11:42.158 | status not received |
+Query OK, 2 row(s) in set (0.001017s)
+```
-以下所有执行命令的操作需要先登陆进 TDengine 系统,必要时请使用 root 权限。
-添加数据节点
-执行 CLI 程序 taos,执行:
+在上面的示例中可以看到新创建的 dnode 的状态为 offline,待该 dnode 被启动并连接上配置文件中指定的 firstEp后再次查看,得到如下结果(示例)
-```mysql
-CREATE DNODE "fqdn:port";
```
-将新数据节点的 End Point 添加进集群的 EP 列表。"fqdn:port"需要用双引号引起来,否则出错。一个数据节点对外服务的 fqdn 和 port 可以通过配置文件 taos.cfg 进行配置,缺省是自动获取。【强烈不建议用自动获取方式来配置 FQDN,可能导致生成的数据节点的 End Point 不是所期望的】
+taos> show dnodes;
+ id | end_point | vnodes | cores | status | role | create_time | offline reason |
+======================================================================================================================================
+ 1 | localhost:6030 | 3 | 8 | ready | any | 2022-04-15 08:27:09.359 | |
+ 2 | localhost:7030 | 6 | 8 | ready | any | 2022-04-19 08:14:59.165 | |
+Query OK, 2 row(s) in set (0.001316s)
+```
+从中可以看到两个 dnode 状态都为 ready
+
## 删除数据节点
-执行 CLI 程序 taos,执行:
-```mysql
-DROP DNODE "fqdn:port | dnodeID";
+启动 CLI 程序 taos,然后执行:
+
+```sql
+DROP DNODE "fqdn:port";
+```
+或者
+```sql
+DROP DNODE dnodeId;
+```
+
+通过 “fqdn:port” 或 dnodeID 来指定一个具体的节点都是可以的。其中 fqdn 是被删除的节点的 FQDN,port 是其对外服务器的端口号;dnodeID 可以通过 SHOW DNODES 获得。
+
+示例如下:
+```
+taos> show dnodes;
+ id | end_point | vnodes | cores | status | role | create_time | offline reason |
+======================================================================================================================================
+ 1 | localhost:6030 | 9 | 8 | ready | any | 2022-04-15 08:27:09.359 | |
+ 2 | localhost:7030 | 0 | 0 | offline | any | 2022-04-19 08:11:42.158 | status not received |
+Query OK, 2 row(s) in set (0.001017s)
+
+taos> drop dnode 2;
+Query OK, 0 of 0 row(s) in database (0.000518s)
+
+taos> show dnodes;
+ id | end_point | vnodes | cores | status | role | create_time | offline reason |
+======================================================================================================================================
+ 1 | localhost:6030 | 9 | 8 | ready | any | 2022-04-15 08:27:09.359 | |
+Query OK, 1 row(s) in set (0.001137s)
```
-通过"fqdn:port"或"dnodeID"来指定一个具体的节点都是可以的。其中 fqdn 是被删除的节点的 FQDN,port 是其对外服务器的端口号;dnodeID 可以通过 SHOW DNODES 获得。
+
+上面的示例中,初次执行 `show dnodes` 列出了两个 dnode, 执行 `drop dnode 2` 删除其中 ID 为 2 的 dnode 之后再次执行 `show dnodes`,可以看到只剩下 ID 为 1 的 dnode 。
:::warning
-一个数据节点一旦被 drop 之后,不能重新加入集群。需要将此节点重新部署(清空数据文件夹)。集群在完成 drop dnode 操作之前,会将该 dnode 的数据迁移走。
-请注意 drop dnode 和 停止 taosd 进程是两个不同的概念,不要混淆:因为删除 dnode 之前要执行迁移数据的操作,因此被删除的 dnode 必须保持在线状态。待删除操作结束之后,才能停止 taosd 进程。
+数据节点一旦被 drop 之后,不能重新加入集群。需要将此节点重新部署(清空数据文件夹)。集群在完成 `drop dnode` 操作之前,会将该 dnode 的数据迁移走。
+请注意 `drop dnode` 和 停止 taosd 进程是两个不同的概念,不要混淆:因为删除 dnode 之前要执行迁移数据的操作,因此被删除的 dnode 必须保持在线状态。待删除操作结束之后,才能停止 taosd 进程。
一个数据节点被 drop 之后,其他节点都会感知到这个 dnodeID 的删除操作,任何集群中的节点都不会再接收此 dnodeID 的请求。
dnodeID 是集群自动分配的,不得人工指定。它在生成时是递增的,不会重复。
:::
## 手动迁移数据节点
+
手动将某个 vnode 迁移到指定的 dnode。
-执行 CLI 程序 taos,执行:
+启动 CLI 程序 taos,然后执行:
-```mysql
+```sql
ALTER DNODE BALANCE "VNODE:-DNODE:";
```
+
其中:source-dnodeId 是源 dnodeId,也就是待迁移的 vnode 所在的 dnodeID;vgId 可以通过 SHOW VGROUPS 获得,列表的第一列;dest-dnodeId 是目标 dnodeId。
-:::warning
+首先执行 `show vgroups` 查看 vgroup 的分布情况
+```
+taos> show vgroups;
+ vgId | tables | status | onlines | v1_dnode | v1_status | compacting |
+==========================================================================================
+ 14 | 38000 | ready | 1 | 3 | master | 0 |
+ 15 | 38000 | ready | 1 | 3 | master | 0 |
+ 16 | 38000 | ready | 1 | 3 | master | 0 |
+ 17 | 38000 | ready | 1 | 3 | master | 0 |
+ 18 | 37001 | ready | 1 | 3 | master | 0 |
+ 19 | 37000 | ready | 1 | 1 | master | 0 |
+ 20 | 37000 | ready | 1 | 1 | master | 0 |
+ 21 | 37000 | ready | 1 | 1 | master | 0 |
+Query OK, 8 row(s) in set (0.001314s)
+```
-只有在集群的自动负载均衡选项关闭时(balance 设置为 0),才允许手动迁移。
-只有处于正常工作状态的 vnode 才能被迁移:master/slave,当处于 offline/unsynced/syncing 状态时,是不能迁移的。
-迁移前,务必核实目标 dnode 的资源足够:CPU、内存、硬盘。
+从中可以看到在 dnode 3 中有5个 vgroup,而 dnode 1 有 3 个 vgroup,假定我们想将其中 vgId 为18 的 vgroup 从 dnode 3 迁移到 dnode 1
-:::
+```
+taos> alter dnode 3 balance "vnode:18-dnode:1";
-## 查看数据节点
-执行 CLI 程序 taos,执行:
+DB error: Balance already enabled (0.00755
+```
-```mysql
-SHOW DNODES;
+上面的结果表明目前所在数据库已经启动了 balance 选项,所以无法进行手动迁移。
+
+停止整个集群,将两个 dnode 的配置文件中的 balance 都设置为 0 (默认为1)之后,重新启动集群,再次执行 ` alter dnode` 和 `show vgroups` 命令如下
+```
+taos> alter dnode 3 balance "vnode:18-dnode:1";
+Query OK, 0 row(s) in set (0.000575s)
+
+taos> show vgroups;
+ vgId | tables | status | onlines | v1_dnode | v1_status | v2_dnode | v2_status | compacting |
+=================================================================================================================
+ 14 | 38000 | ready | 1 | 3 | master | 0 | NULL | 0 |
+ 15 | 38000 | ready | 1 | 3 | master | 0 | NULL | 0 |
+ 16 | 38000 | ready | 1 | 3 | master | 0 | NULL | 0 |
+ 17 | 38000 | ready | 1 | 3 | master | 0 | NULL | 0 |
+ 18 | 37001 | ready | 2 | 1 | slave | 3 | master | 0 |
+ 19 | 37000 | ready | 1 | 1 | master | 0 | NULL | 0 |
+ 20 | 37000 | ready | 1 | 1 | master | 0 | NULL | 0 |
+ 21 | 37000 | ready | 1 | 1 | master | 0 | NULL | 0 |
+Query OK, 8 row(s) in set (0.001242s)
```
-它将列出集群中所有的 dnode,每个 dnode 的 ID,end_point(fqdn:port),状态(ready, offline 等),vnode 数目,还未使用的 vnode 数目等信息。在添加或删除一个数据节点后,可以使用该命令查看。
-## 查看虚拟节点组
-为充分利用多核技术,并提供 scalability,数据需要分片处理。因此 TDengine 会将一个 DB 的数据切分成多份,存放在多个 vnode 里。这些 vnode 可能分布在多个数据节点 dnode 里,这样就实现了水平扩展。一个 vnode 仅仅属于一个 DB,但一个 DB 可以有多个 vnode。vnode 的是 mnode 根据当前系统资源的情况,自动进行分配的,无需任何人工干预。
+从上面的输出可以看到 vgId 为 18 的 vnode 被从 dnode 3 迁移到了 dnode 1。
-执行 CLI 程序 taos,执行:
+:::warning
+
+只有在集群的自动负载均衡选项关闭时(balance 设置为 0),才允许手动迁移。
+只有处于正常工作状态的 vnode 才能被迁移:master/slave;当处于 offline/unsynced/syncing 状态时,是不能迁移的。
+迁移前,务必核实目标 dnode 的资源足够:CPU、内存、硬盘。
+
+:::
- ```mysql
-USE SOME_DATABASE;
-SHOW VGROUPS;
- ```
diff --git a/docs-cn/10-cluster/03-ha-and-lb.md b/docs-cn/10-cluster/03-ha-and-lb.md
index b9a15a5efc68d4e4f59c131454163067c309685e..3d15feb11c47fe821fa4689de2665a65ea17cbe9 100644
--- a/docs-cn/10-cluster/03-ha-and-lb.md
+++ b/docs-cn/10-cluster/03-ha-and-lb.md
@@ -1,36 +1,44 @@
-# 高可用与负载均衡
-## vnode 的高可用性
+---
+title: 高可用与负载均衡
+---
+
+## Vnode 的高可用性
+
TDengine 通过多副本的机制来提供系统的高可用性,包括 vnode 和 mnode 的高可用性。
-vnode 的副本数是与 DB 关联的,一个集群里可以有多个 DB,根据运营的需求,每个 DB 可以配置不同的副本数。创建数据库时,通过参数 replica 指定副本数(缺省为 1)。如果副本数为 1,系统的可靠性无法保证,只要数据所在的节点宕机,就将无法提供服务。集群的节点数必须大于等于副本数,否则创建表时将返回错误"more dnodes are needed"。比如下面的命令将创建副本数为 3 的数据库 demo:
+vnode 的副本数是与 DB 关联的,一个集群里可以有多个 DB,根据运营的需求,每个 DB 可以配置不同的副本数。创建数据库时,通过参数 replica 指定副本数(缺省为 1)。如果副本数为 1,系统的可靠性无法保证,只要数据所在的节点宕机,就将无法提供服务。集群的节点数必须大于等于副本数,否则创建表时将返回错误“more dnodes are needed”。比如下面的命令将创建副本数为 3 的数据库 demo:
-```mysql
+```sql
CREATE DATABASE demo replica 3;
```
-一个 DB 里的数据会被切片分到多个 vnode group,vnode group 里的 vnode 数目就是 DB 的副本数,同一个 vnode group 里各 vnode 的数据是完全一致的。为保证高可用性,vnode group 里的 vnode 一定要分布在不同的数据节点 dnode 里(实际部署时,需要在不同的物理机上),只要一个 vgroup 里超过半数的 vnode 处于工作状态,这个 vgroup 就能正常的对外服务。
+
+一个 DB 里的数据会被切片分到多个 vnode group,vnode group 里的 vnode 数目就是 DB 的副本数,同一个 vnode group 里各 vnode 的数据是完全一致的。为保证高可用性,vnode group 里的 vnode 一定要分布在不同的数据节点 dnode 里(实际部署时,需要在不同的物理机上),只要一个 vnode group 里超过半数的 vnode 处于工作状态,这个 vnode group 就能正常的对外服务。
一个数据节点 dnode 里可能有多个 DB 的数据,因此一个 dnode 离线时,可能会影响到多个 DB。如果一个 vnode group 里的一半或一半以上的 vnode 不工作,那么该 vnode group 就无法对外服务,无法插入或读取数据,这样会影响到它所属的 DB 的一部分表的读写操作。
因为 vnode 的引入,无法简单地给出结论:“集群中过半数据节点 dnode 工作,集群就应该工作”。但是对于简单的情形,很好下结论。比如副本数为 3,只有三个 dnode,那如果仅有一个节点不工作,整个集群还是可以正常工作的,但如果有两个数据节点不工作,那整个集群就无法正常工作了。
## Mnode 的高可用性
-TDengine 集群是由 mnode (taosd 的一个模块,管理节点) 负责管理的,为保证 mnode 的高可用,可以配置多个 mnode 副本,副本数由系统配置参数 numOfMnodes 决定,有效范围为 1-3。为保证元数据的强一致性,mnode 副本之间是通过同步的方式进行数据复制的。
+
+TDengine 集群是由 mnode(taosd 的一个模块,管理节点)负责管理的,为保证 mnode 的高可用,可以配置多个 mnode 副本,副本数由系统配置参数 numOfMnodes 决定,有效范围为 1-3。为保证元数据的强一致性,mnode 副本之间是通过同步的方式进行数据复制的。
一个集群有多个数据节点 dnode,但一个 dnode 至多运行一个 mnode 实例。多个 dnode 情况下,哪个 dnode 可以作为 mnode 呢?这是完全由系统根据整个系统资源情况,自动指定的。用户可通过 CLI 程序 taos,在 TDengine 的 console 里,执行如下命令:
-```mysql
+```sql
SHOW MNODES;
```
-来查看 mnode 列表,该列表将列出 mnode 所处的 dnode 的 End Point 和角色(master, slave, unsynced 或 offline)。当集群中第一个数据节点启动时,该数据节点一定会运行一个 mnode 实例,否则该数据节点 dnode 无法正常工作,因为一个系统是必须有至少一个 mnode 的。如果 numOfMnodes 配置为 2,启动第二个 dnode 时,该 dnode 也将运行一个 mnode 实例。
+
+来查看 mnode 列表,该列表将列出 mnode 所处的 dnode 的 End Point 和角色(master,slave,unsynced 或 offline)。当集群中第一个数据节点启动时,该数据节点一定会运行一个 mnode 实例,否则该数据节点 dnode 无法正常工作,因为一个系统是必须有至少一个 mnode 的。如果 numOfMnodes 配置为 2,启动第二个 dnode 时,该 dnode 也将运行一个 mnode 实例。
为保证 mnode 服务的高可用性,numOfMnodes 必须设置为 2 或更大。因为 mnode 保存的元数据必须是强一致的,如果 numOfMnodes 大于 2,复制参数 quorum 自动设为 2,也就是说,至少要保证有两个副本写入数据成功,才通知客户端应用写入成功。
-:::note
-一个 TDengine 高可用系统,无论是 vnode 还是 mnode, 都必须配置多个副本。
+:::note
+一个 TDengine 高可用系统,无论是 vnode 还是 mnode,都必须配置多个副本。
:::
## 负载均衡
+
有三种情况,将触发负载均衡,而且都无需人工干预。
当一个新数据节点添加进集群时,系统将自动触发负载均衡,一些节点上的数据将被自动转移到新数据节点上,无需任何人工干预。
@@ -38,24 +46,26 @@ SHOW MNODES;
如果一个数据节点过热(数据量过大),系统将自动进行负载均衡,将该数据节点的一些 vnode 自动挪到其他节点。
当上述三种情况发生时,系统将启动各个数据节点的负载计算,从而决定如何挪动。
-:::tip
-负载均衡由参数 balance 控制,它决定是否启动自动负载均衡, 0 表示禁用, 1 表示启用自动负载均衡。**
+:::tip
+负载均衡由参数 balance 控制,它决定是否启动自动负载均衡,0 表示禁用,1 表示启用自动负载均衡。
:::
## 数据节点离线处理
+
如果一个数据节点离线,TDengine 集群将自动检测到。有如下两种情况:
-该数据节点离线超过一定时间(taos.cfg 里配置参数 offlineThreshold 控制时长),系统将自动把该数据节点删除,产生系统报警信息,触发负载均衡流程。如果该被删除的数据节点重新上线时,它将无法加入集群,需要系统管理员重新将其添加进集群才会开始工作。
+该数据节点离线超过一定时间(taos.cfg 里配置参数 offlineThreshold 控制时长),系统将自动把该数据节点删除,产生系统报警信息,触发负载均衡流程。如果该被删除的数据节点重新上线时,它将无法加入集群,需要系统管理员重新将其添加进集群才会开始工作。
离线后,在 offlineThreshold 的时长内重新上线,系统将自动启动数据恢复流程,等数据完全恢复后,该节点将开始正常工作。
-:::note
-如果一个虚拟节点组(包括 mnode 组)里所归属的每个数据节点都处于离线或 unsynced 状态,必须等该虚拟节点组里的所有数据节点都上线、都能交换状态信息后,才能选出 Master,该虚拟节点组才能对外提供服务。比如整个集群有 3 个数据节点,副本数为 3,如果 3 个数据节点都宕机,然后 2 个数据节点重启,是无法工作的,只有等 3 个数据节点都重启成功,才能对外服务。
+:::note
+如果一个虚拟节点组(包括 mnode 组)里所归属的每个数据节点都处于离线或 unsynced 状态,必须等该虚拟节点组里的所有数据节点都上线、都能交换状态信息后,才能选出 Master,该虚拟节点组才能对外提供服务。比如整个集群有 3 个数据节点,副本数为 3,如果 3 个数据节点都宕机,然后 2 个数据节点重启,是无法工作的,只有等 3 个数据节点都重启成功,才能对外服务。
:::
## Arbitrator 的使用
+
如果副本数为偶数,当一个 vnode group 里一半或超过一半的 vnode 不工作时,是无法从中选出 master 的。同理,一半或超过一半的 mnode 不工作时,是无法选出 mnode 的 master 的,因为存在“split brain”问题。
为解决这个问题,TDengine 引入了 Arbitrator 的概念。Arbitrator 模拟一个 vnode 或 mnode 在工作,但只简单的负责网络连接,不处理任何数据插入或访问。只要包含 Arbitrator 在内,超过半数的 vnode 或 mnode 工作,那么该 vnode group 或 mnode 组就可以正常的提供数据插入或查询服务。比如对于副本数为 2 的情形,如果一个节点 A 离线,但另外一个节点 B 正常,而且能连接到 Arbitrator,那么节点 B 就能正常工作。
@@ -69,9 +79,9 @@ Arbitrator 的执行程序名为 tarbitrator。该程序对系统资源几乎没
修改每个 taosd 实例的配置文件,在 taos.cfg 里将参数 arbitrator 设置为 tarbitrator 程序所对应的 End Point。(如果该参数配置了,当副本数为偶数时,系统将自动连接配置的 Arbitrator。如果副本数为奇数,即使配置了 Arbitrator,系统也不会去建立连接。)
-在配置文件中配置了的 Arbitrator,会出现在 SHOW DNODES; 指令的返回结果中,对应的 role 列的值会是“arb”。
+在配置文件中配置了的 Arbitrator,会出现在 SHOW DNODES 指令的返回结果中,对应的 role 列的值会是“arb”。
查看集群 Arbitrator 的状态【2.0.14.0 以后支持】
-```mysql
+```sql
SHOW DNODES;
```
diff --git a/docs-cn/10-cluster/_category_.yml b/docs-cn/10-cluster/_category_.yml
index 356872bc73715fb8cb8d307d7fe2bfe6def86c27..df953cb6dd297c91f1e6d1e2d30690afab293982 100644
--- a/docs-cn/10-cluster/_category_.yml
+++ b/docs-cn/10-cluster/_category_.yml
@@ -1,6 +1,7 @@
label: 集群管理
link:
type: generated-index
+ slug: /cluster/
description: "TDengine支持以集群方式部署,以提升系统的处理能力和高可用性。TDengine集群支持任意数据的多副本从而提升高可用性,并自动实现负载均衡。同时TDengine集群具有很好的横向扩展能力以处理更多的数据采集点和更大的数据量。"
keywords:
[
diff --git a/docs-cn/11-operation/09-status.md b/docs-cn/11-operation/09-status.md
deleted file mode 100644
index 7137be1d16b154a78f579b053d09a7d7c8b2fdda..0000000000000000000000000000000000000000
--- a/docs-cn/11-operation/09-status.md
+++ /dev/null
@@ -1,39 +0,0 @@
-# 系统连接、任务查询管理
-
-系统管理员可以从 CLI 查询系统的连接、正在进行的查询、流式计算,并且可以关闭连接、停止正在进行的查询和流式计算。CLI 里 SQL 语法如下:
-
-```mysql
-SHOW CONNECTIONS;
-```
-
-显示数据库的连接,其中一列显示 ip:port, 为连接的 IP 地址和端口号。
-
-```mysql
-KILL CONNECTION ;
-```
-
-强制关闭数据库连接,其中的 connection-id 是 SHOW CONNECTIONS 中显示的第一列的数字。
-
-```mysql
-SHOW QUERIES;
-```
-
-显示数据查询,其中第一列显示的以冒号隔开的两个数字为 query-id,为发起该 query 应用连接的 connection-id 和查询次数。
-
-```mysql
-KILL QUERY ;
-```
-
-强制关闭数据查询,其中 query-id 是 SHOW QUERIES 中显示的 connection-id:query-no 字串,如“105:2”,拷贝粘贴即可。
-
-```mysql
-SHOW STREAMS;
-```
-
-显示流式计算,其中第一列显示的以冒号隔开的两个数字为 stream-id, 为启动该 stream 应用连接的 connection-id 和发起 stream 的次数。
-
-```mysql
-KILL STREAM ;
-```
-
-强制关闭流式计算,其中的中 stream-id 是 SHOW STREAMS 中显示的 connection-id:stream-no 字串,如 103:2,拷贝粘贴即可。
diff --git a/docs-cn/11-operation/_category_.yml b/docs-cn/11-operation/_category_.yml
deleted file mode 100644
index 73e81280876190b72a1c05b454c4873f1889091f..0000000000000000000000000000000000000000
--- a/docs-cn/11-operation/_category_.yml
+++ /dev/null
@@ -1,3 +0,0 @@
-label: 运维指南
-link:
- type: generated-index
\ No newline at end of file
diff --git a/docs-cn/14-reference/01-taos-sql/01-data-type.md b/docs-cn/12-taos-sql/01-data-type.md
similarity index 90%
rename from docs-cn/14-reference/01-taos-sql/01-data-type.md
rename to docs-cn/12-taos-sql/01-data-type.md
index 107e73de5b6903d7aeaa6d6c8a68fb9f5941b7e9..7e63e1c9507f3b12f37fdb42a9c347bd92aafb75 100644
--- a/docs-cn/14-reference/01-taos-sql/01-data-type.md
+++ b/docs-cn/12-taos-sql/01-data-type.md
@@ -1,18 +1,17 @@
---
sidebar_label: 支持的数据类型
+title: 支持的数据类型
---
-# 支持的数据类型
-
使用 TDengine,最重要的是时间戳。创建并插入记录、查询历史记录的时候,均需要指定时间戳。时间戳有如下规则:
- 时间格式为 `YYYY-MM-DD HH:mm:ss.MS`,默认时间分辨率为毫秒。比如:`2017-08-12 18:25:58.128`
- 内部函数 now 是客户端的当前时间
- 插入记录时,如果时间戳为 now,插入数据时使用提交这条记录的客户端的当前时间
-- Epoch Time:时间戳也可以是一个长整数,表示从格林威治时间 1970-01-01 00:00:00.000 (UTC/GMT) 开始的毫秒数(相应地,如果所在 Database 的时间精度设置为“微秒”,则长整型格式的时间戳含义也就对应于从格林威治时间 1970-01-01 00:00:00.000 (UTC/GMT) 开始的微秒数;纳秒精度的逻辑也是类似的。)
-- 时间可以加减,比如 now-2h,表明查询时刻向前推 2 个小时(最近 2 小时)。数字后面的时间单位可以是 b(纳秒)、u(微秒)、a(毫秒)、s(秒)、m(分)、h(小时)、d(天)、w(周)。 比如 `select * from t1 where ts > now-2w and ts <= now-1w`,表示查询两周前整整一周的数据。在指定降采样操作(down sampling)的时间窗口(interval)时,时间单位还可以使用 n(自然月) 和 y(自然年)。
+- Epoch Time:时间戳也可以是一个长整数,表示从格林威治时间 1970-01-01 00:00:00.000 (UTC/GMT) 开始的毫秒数(相应地,如果所在 Database 的时间精度设置为“微秒”,则长整型格式的时间戳含义也就对应于从格林威治时间 1970-01-01 00:00:00.000 (UTC/GMT) 开始的微秒数;纳秒精度逻辑类似。)
+- 时间可以加减,比如 now-2h,表明查询时刻向前推 2 个小时(最近 2 小时)。数字后面的时间单位可以是 b(纳秒)、u(微秒)、a(毫秒)、s(秒)、m(分)、h(小时)、d(天)、w(周)。 比如 `select * from t1 where ts > now-2w and ts <= now-1w`,表示查询两周前整整一周的数据。在指定降采样操作(down sampling)的时间窗口(interval)时,时间单位还可以使用 n (自然月) 和 y (自然年)。
-TDengine 缺省的时间戳是毫秒精度,但通过在 `CREATE DATABASE` 时传递的 PRECISION 参数就可以支持微秒和纳秒。(从 2.1.5.0 版本开始支持纳秒精度)
+TDengine 缺省的时间戳精度是毫秒,但通过在 `CREATE DATABASE` 时传递的 PRECISION 参数也可以支持微秒和纳秒。(从 2.1.5.0 版本开始支持纳秒精度)
```
CREATE DATABASE db_name PRECISION 'ns';
@@ -24,15 +23,15 @@ CREATE DATABASE db_name PRECISION 'ns';
| --- | :-------: | --------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| 1 | TIMESTAMP | 8 | 时间戳。缺省精度毫秒,可支持微秒和纳秒。从格林威治时间 1970-01-01 00:00:00.000 (UTC/GMT) 开始,计时不能早于该时间。(从 2.0.18.0 版本开始,已经去除了这一时间范围限制)(从 2.1.5.0 版本开始支持纳秒精度) |
| 2 | INT | 4 | 整型,范围 [-2^31+1, 2^31-1], -2^31 用作 NULL |
-| 3 | BIGINT | 8 | 长整型,范围 [-2^63+1, 2^63-1], -2^63 用于 NULL |
+| 3 | BIGINT | 8 | 长整型,范围 [-2^63+1, 2^63-1], -2^63 用作 NULL |
| 4 | FLOAT | 4 | 浮点型,有效位数 6-7,范围 [-3.4E38, 3.4E38] |
| 5 | DOUBLE | 8 | 双精度浮点型,有效位数 15-16,范围 [-1.7E308, 1.7E308] |
| 6 | BINARY | 自定义 | 记录单字节字符串,建议只用于处理 ASCII 可见字符,中文等多字节字符需使用 nchar。理论上,最长可以有 16374 字节。binary 仅支持字符串输入,字符串两端需使用单引号引用。使用时须指定大小,如 binary(20) 定义了最长为 20 个单字节字符的字符串,每个字符占 1 byte 的存储空间,总共固定占用 20 bytes 的空间,此时如果用户字符串超出 20 字节将会报错。对于字符串内的单引号,可以用转义字符反斜线加单引号来表示,即 `\’`。 |
-| 7 | SMALLINT | 2 | 短整型, 范围 [-32767, 32767], -32768 用于 NULL |
-| 8 | TINYINT | 1 | 单字节整型,范围 [-127, 127], -128 用于 NULL |
+| 7 | SMALLINT | 2 | 短整型, 范围 [-32767, 32767], -32768 用作 NULL |
+| 8 | TINYINT | 1 | 单字节整型,范围 [-127, 127], -128 用作 NULL |
| 9 | BOOL | 1 | 布尔型,{true, false} |
| 10 | NCHAR | 自定义 | 记录包含多字节字符在内的字符串,如中文字符。每个 nchar 字符占用 4 bytes 的存储空间。字符串两端使用单引号引用,字符串内的单引号需用转义字符 `\’`。nchar 使用时须指定字符串大小,类型为 nchar(10) 的列表示此列的字符串最多存储 10 个 nchar 字符,会固定占用 40 bytes 的空间。如果用户字符串长度超出声明长度,将会报错。 |
-| 11 | JSON | | json 数据类型, 只有 tag 类型可以是 json 格式 |
+| 11 | JSON | | json 数据类型, 只有 tag 可以是 json 格式 |
@@ -42,7 +41,7 @@ TDengine 对 SQL 语句中的英文字符不区分大小写,自动转化为小
:::
:::note
-虽然 Binary 类型在底层存储上支持字节型的二进制字符,但不同编程语言对二进制数据的处理方式并不保证一致,因此建议在 Binary 类型中只存储 ASCII 可见字符,而避免存储不可见字符。多字节的数据,例如中文字符,则需要使用 nchar 类型进行保存。如果强行使用 Binary 类型保存中文字符,虽然有时也能正常读写,但并不带有字符集信息,很容易出现数据乱码甚至数据损坏等情况。
+虽然 BINARY 类型在底层存储上支持字节型的二进制字符,但不同编程语言对二进制数据的处理方式并不保证一致,因此建议在 BINARY 类型中只存储 ASCII 可见字符,而避免存储不可见字符。多字节的数据,例如中文字符,则需要使用 NCHAR 类型进行保存。如果强行使用 BINARY 类型保存中文字符,虽然有时也能正常读写,但并不带有字符集信息,很容易出现数据乱码甚至数据损坏等情况。
:::
diff --git a/docs-cn/14-reference/01-taos-sql/02-database.md b/docs-cn/12-taos-sql/02-database.md
similarity index 89%
rename from docs-cn/14-reference/01-taos-sql/02-database.md
rename to docs-cn/12-taos-sql/02-database.md
index 1fe934e87796313b647222a000635d113ef391bb..5240efa26fc98aaa0ffe83abbb3e44a23dbf338c 100644
--- a/docs-cn/14-reference/01-taos-sql/02-database.md
+++ b/docs-cn/12-taos-sql/02-database.md
@@ -1,34 +1,24 @@
---
sidebar_label: 数据库管理
+title: 数据库管理
---
-# 数据库管理
-
## 创建数据库
```
CREATE DATABASE [IF NOT EXISTS] db_name [KEEP keep] [DAYS days] [UPDATE 1];
```
-:::info 说明
-
+:::info
1. KEEP 是该数据库的数据保留多长天数,缺省是 3650 天(10 年),数据库会自动删除超过时限的数据;
-
2. UPDATE 标志数据库支持更新相同时间戳数据;(从 2.1.7.0 版本开始此参数支持设为 2,表示允许部分列更新,也即更新数据行时未被设置的列会保留原值。)(从 2.0.8.0 版本开始支持此参数。注意此参数不能通过 `ALTER DATABASE` 指令进行修改。)
-
1. UPDATE 设为 0 时,表示不允许更新数据,后发送的相同时间戳的数据会被直接丢弃;
-
2. UPDATE 设为 1 时,表示更新全部列数据,即如果更新一个数据行,其中某些列没有提供取值,那么这些列会被设为 NULL;
-
3. UPDATE 设为 2 时,表示支持更新部分列数据,即如果更新一个数据行,其中某些列没有提供取值,那么这些列会保持原有数据行中的对应值;
-
- 4. 更多关于 UPDATE 参数的用法,请参考[FAQ](https://www.taosdata.com/cn/documentation/faq)。
-
+ 4. 更多关于 UPDATE 参数的用法,请参考[FAQ](/train-faq/faq)。
3. 数据库名最大长度为 33;
-
4. 一条 SQL 语句的最大长度为 65480 个字符;
-
-5. 数据库还有更多与存储相关的配置参数,请参见 [服务端配置](https://www.taosdata.com/cn/documentation/administrator#config) 章节。
+5. 数据库还有更多与数据库相关的配置参数,如 cache, blocks, days, keep, minRows, maxRows, wal, fsync, update, cacheLast, replica, quorum, maxVgroupsPerDb, ctime, comp, prec, 具体细节请参见 [配置参数](/reference/config/) 章节。
:::
@@ -44,7 +34,7 @@ SHOW VARIABLES;
USE db_name;
```
-使用/切换数据库(在 RESTful 连接方式下无效)。
+使用/切换数据库(在 REST 连接方式下无效)。
## 删除数据库
diff --git a/docs-cn/14-reference/01-taos-sql/03-table.md b/docs-cn/12-taos-sql/03-table.md
similarity index 94%
rename from docs-cn/14-reference/01-taos-sql/03-table.md
rename to docs-cn/12-taos-sql/03-table.md
index 81834bacd47e04249b72aa4f28d31a73b4c74e75..330734f9bc46ffb09fc338997f37c0e05560a2d5 100644
--- a/docs-cn/14-reference/01-taos-sql/03-table.md
+++ b/docs-cn/12-taos-sql/03-table.md
@@ -1,4 +1,6 @@
-# 表管理
+---
+title: 表管理
+---
## 创建数据表
@@ -74,13 +76,6 @@ SHOW CREATE TABLE tb_name;
常用于数据库迁移。对一个已经存在的数据表,返回其创建语句;在另一个集群中执行该语句,就能得到一个结构完全相同的数据表。
-## 在线修改显示字符宽度
-
-```
-SET MAX_BINARY_DISPLAY_WIDTH ;
-```
-
-如显示的内容后面以...结尾时,表示该内容已被截断,可通过本命令修改显示字符宽度以显示完整的内容。
## 获取表的结构信息
@@ -120,3 +115,9 @@ ALTER TABLE tb_name MODIFY COLUMN field_name data_type(length);
如果数据列的类型是可变长格式(BINARY 或 NCHAR),那么可以使用此指令修改其宽度(只能改大,不能改小)。(2.1.3.0 版本新增)
如果表是通过超级表创建,更改表结构的操作只能对超级表进行。同时针对超级表的结构更改对所有通过该结构创建的表生效。对于不是通过超级表创建的表,可以直接修改表结构。
+ ### 修改子表标签值
+
+```
+ALTER TABLE tb_name SET TAG tag_name=new_tag_value;
+```
+如果表是通过超级表创建,可以使用此指令修改其标签值
diff --git a/docs-cn/14-reference/01-taos-sql/04-stable.md b/docs-cn/12-taos-sql/04-stable.md
similarity index 79%
rename from docs-cn/14-reference/01-taos-sql/04-stable.md
rename to docs-cn/12-taos-sql/04-stable.md
index 8ac8e669f36fc0dd7066006e5b1e4d4ca7d15cc2..52ec7fa6983abc63bcb839f28f8d9a56d6863cb8 100644
--- a/docs-cn/14-reference/01-taos-sql/04-stable.md
+++ b/docs-cn/12-taos-sql/04-stable.md
@@ -1,10 +1,13 @@
---
sidebar_label: 超级表管理
+title: 超级表 STable 管理
---
-# 超级表 STable 管理
+:::note
-注意:在 2.0.15.0 及以后的版本中,开始支持 STABLE 保留字。也即,在本节后文的指令说明中,CREATE、DROP、ALTER 三个指令在老版本中保留字需写作 TABLE 而不是 STABLE。
+在 2.0.15.0 及以后的版本中开始支持 STABLE 保留字。也即,在本节后文的指令说明中,CREATE、DROP、ALTER 三个指令在 2.0.15.0 之前的版本中 STABLE 保留字需写作 TABLE。
+
+:::
## 创建超级表
@@ -18,7 +21,7 @@ CREATE STABLE [IF NOT EXISTS] stb_name (timestamp_field_name TIMESTAMP, field1_n
1. TAGS 列的数据类型不能是 timestamp 类型;(从 2.1.3.0 版本开始,TAGS 列中支持使用 timestamp 类型,但需注意在 TAGS 中的 timestamp 列写入数据时需要提供给定值,而暂不支持四则运算,例如 `NOW + 10s` 这类表达式)
2. TAGS 列名不能与其他列名相同;
-3. TAGS 列名不能为预留关键字(参见:[参数限制与保留关键字](https://www.taosdata.com/cn/documentation/administrator#keywords) 章节);
+3. TAGS 列名不能为预留关键字(参见:[参数限制与保留关键字](/taos-sql/keywords/) 章节);
4. TAGS 最多允许 128 个,至少 1 个,总长度不超过 16 KB。
:::
@@ -109,11 +112,7 @@ ALTER STABLE stb_name MODIFY TAG tag_name data_type(length);
如果标签的类型是可变长格式(BINARY 或 NCHAR),那么可以使用此指令修改其宽度(只能改大,不能改小)。(2.1.3.0 版本新增)
-### 修改子表标签值
-
-```
-ALTER TABLE tb_name SET TAG tag_name=new_tag_value;
-```
-
-说明:除了更新标签的值的操作是针对子表进行,其他所有的标签操作(添加标签、删除标签等)均只能作用于 STable,不能对单个子表操作。对 STable 添加标签以后,依托于该 STable 建立的所有表将自动增加了一个标签,所有新增标签的默认值都是 NULL。
+:::note
+除了更新标签的值的操作是针对子表进行,其他所有的标签操作(添加标签、删除标签等)均只能作用于 STable,不能对单个子表操作。对 STable 添加标签以后,依托于该 STable 建立的所有表将自动增加了一个标签,所有新增标签的默认值都是 NULL。
+:::
\ No newline at end of file
diff --git a/docs-cn/14-reference/01-taos-sql/05-insert.md b/docs-cn/12-taos-sql/05-insert.md
similarity index 99%
rename from docs-cn/14-reference/01-taos-sql/05-insert.md
rename to docs-cn/12-taos-sql/05-insert.md
index d0c0c28dba3f5f64ff066f6a313e8307488c13b5..e542e442b78c9033ae37196f4913a7c67fb19d8b 100644
--- a/docs-cn/14-reference/01-taos-sql/05-insert.md
+++ b/docs-cn/12-taos-sql/05-insert.md
@@ -1,9 +1,8 @@
---
sidebar_label: 数据写入
+title: 数据写入
---
-# 数据写入
-
## 写入语法
```
diff --git a/docs-cn/14-reference/01-taos-sql/06-select.md b/docs-cn/12-taos-sql/06-select.md
similarity index 81%
rename from docs-cn/14-reference/01-taos-sql/06-select.md
rename to docs-cn/12-taos-sql/06-select.md
index dab208f0860ab4eed435d097205e1a803350dcde..6f0a0735135738c9502632387022cc94e9495375 100644
--- a/docs-cn/14-reference/01-taos-sql/06-select.md
+++ b/docs-cn/12-taos-sql/06-select.md
@@ -1,9 +1,8 @@
---
sidebar_label: 数据查询
+title: 数据查询
---
-# 数据查询
-
## 查询语法
```
@@ -222,42 +221,43 @@ Query OK, 1 row(s) in set (0.000081s)
## \_block_dist 函数
-用于获得指定的(超级)表的数据块分布信息
+**功能说明**: 用于获得指定的(超级)表的数据块分布信息
```txt title="语法"
SELECT _block_dist() FROM { tb_name | stb_name }
```
-返回结果类型:字符串。
+**返回结果类型**:字符串。
-适用数据类型:不能输入任何参数。
+**适用数据类型**:不能输入任何参数。
-嵌套子查询支持:不支持子查询或嵌套查询。
+**嵌套子查询支持**:不支持子查询或嵌套查询。
-返回 FROM 子句中输入的表或超级表的数据块分布情况。不支持查询条件。
+**返回结果**:
-返回的结果是该表或超级表的数据块所包含的行数的数据分布直方图。
+- 返回 FROM 子句中输入的表或超级表的数据块分布情况。不支持查询条件。
+- 返回的结果是该表或超级表的数据块所包含的行数的数据分布直方图。
```txt title="返回结果"
summary:
5th=[392], 10th=[392], 20th=[392], 30th=[392], 40th=[792], 50th=[792] 60th=[792], 70th=[792], 80th=[792], 90th=[792], 95th=[792], 99th=[792] Min=[392(Rows)] Max=[800(Rows)] Avg=[666(Rows)] Stddev=[2.17] Rows=[2000], Blocks=[3], Size=[5.440(Kb)] Comp=[0.23] RowsInMem=[0] SeekHeaderTime=[1(us)]
```
-上述信息的说明如下:
+**上述信息的说明如下**:
-1. 查询的(超级)表所包含的存储在文件中的数据块(data block)中所包含的数据行的数量分布直方图信息:5%, 10%, 20%, 30%, 40%, 50%, 60%, 70%, 80%, 90%, 95%, 99% 的数值;
-2. 所有数据块中,包含行数最少的数据块所包含的行数量, 其中的 Min 指标 392 行。
-3. 所有数据块中,包含行数最多的数据块所包含的行数量, 其中的 Max 指标 800 行。
-4. 所有数据块行数的算数平均值 666 行(其中的 Avg 项)。
-5. 所有数据块中行数分布的均方差为 2.17 ( stddev )。
-6. 数据块包含的行的总数为 2000 行(Rows)。
-7. 数据块总数是 3 个数据块 (Blocks)。
-8. 数据块占用磁盘空间大小 5.44 Kb (size)。
-9. 压缩后的数据块的大小除以原始数据的所获得的压缩比例: 23%(Comp),及压缩后的数据规模是原始数据规模的 23%。
-10. 内存中存在的数据行数是 0,表示内存中没有数据缓存。
-11. 获取数据块信息的过程中读取头文件的时间开销 1 微秒(SeekHeaderTime)。
+- 查询的(超级)表所包含的存储在文件中的数据块(data block)中所包含的数据行的数量分布直方图信息:5%, 10%, 20%, 30%, 40%, 50%, 60%, 70%, 80%, 90%, 95%, 99% 的数值;
+- 所有数据块中,包含行数最少的数据块所包含的行数量, 其中的 Min 指标 392 行。
+- 所有数据块中,包含行数最多的数据块所包含的行数量, 其中的 Max 指标 800 行。
+- 所有数据块行数的算数平均值 666 行(其中的 Avg 项)。
+- 所有数据块中行数分布的均方差为 2.17 ( stddev )。
+- 数据块包含的行的总数为 2000 行(Rows)。
+- 数据块总数是 3 个数据块 (Blocks)。
+- 数据块占用磁盘空间大小 5.44 Kb (size)。
+- 压缩后的数据块的大小除以原始数据的所获得的压缩比例: 23%(Comp),及压缩后的数据规模是原始数据规模的 23%。
+- 内存中存在的数据行数是 0,表示内存中没有数据缓存。
+- 获取数据块信息的过程中读取头文件的时间开销 1 微秒(SeekHeaderTime)。
-支持版本:指定计算算法的功能从 2.1.0.x 版本开始,2.1.0.0 之前的版本不支持指定使用算法的功能。
+**支持版本**:指定计算算法的功能从 2.1.0.x 版本开始,2.1.0.0 之前的版本不支持指定使用算法的功能。
## TAOS SQL 中特殊关键词
@@ -323,18 +323,20 @@ Query OK, 1 row(s) in set (0.001091s)
| like | match a wildcard string | **`binary`** **`nchar`** |
| match/nmatch | filter regex | **`binary`** **`nchar`** |
-1. <\> 算子也可以写为 != ,请注意,这个算子不能用于数据表第一列的 timestamp 字段。
-2. like 算子使用通配符字符串进行匹配检查。
+**使用说明**:
+
+- <\> 算子也可以写为 != ,请注意,这个算子不能用于数据表第一列的 timestamp 字段。
+- like 算子使用通配符字符串进行匹配检查。
- 在通配符字符串中:'%'(百分号)匹配 0 到任意个字符;'\_'(下划线)匹配单个任意 ASCII 字符。
- 如果希望匹配字符串中原本就带有的 \_(下划线)字符,那么可以在通配符字符串中写作 `\_`,也即加一个反斜线来进行转义。(从 2.2.0.0 版本开始支持)
- 通配符字符串最长不能超过 20 字节。(从 2.1.6.1 版本开始,通配符字符串的长度放宽到了 100 字节,并可以通过 taos.cfg 中的 maxWildCardsLength 参数来配置这一长度限制。但不建议使用太长的通配符字符串,将有可能严重影响 LIKE 操作的执行性能。)
-3. 同时进行多个字段的范围过滤,需要使用关键词 AND 来连接不同的查询条件,暂不支持 OR 连接的不同列之间的查询过滤条件。
+- 同时进行多个字段的范围过滤,需要使用关键词 AND 来连接不同的查询条件,暂不支持 OR 连接的不同列之间的查询过滤条件。
- 从 2.3.0.0 版本开始,已支持完整的同一列和/或不同列间的 AND/OR 运算。
-4. 针对单一字段的过滤,如果是时间过滤条件,则一条语句中只支持设定一个;但针对其他的(普通)列或标签列,则可以使用 `OR` 关键字进行组合条件的查询过滤。例如: `((value > 20 AND value < 30) OR (value < 12))`。
+- 针对单一字段的过滤,如果是时间过滤条件,则一条语句中只支持设定一个;但针对其他的(普通)列或标签列,则可以使用 `OR` 关键字进行组合条件的查询过滤。例如: `((value > 20 AND value < 30) OR (value < 12))`。
- 从 2.3.0.0 版本开始,允许使用多个时间过滤条件,但首列时间戳的过滤运算结果只能包含一个区间。
-5. 从 2.0.17.0 版本开始,条件过滤开始支持 BETWEEN AND 语法,例如 `WHERE col2 BETWEEN 1.5 AND 3.25` 表示查询条件为“1.5 ≤ col2 ≤ 3.25”。
-6. 从 2.1.4.0 版本开始,条件过滤开始支持 IN 算子,例如 `WHERE city IN ('Beijing', 'Shanghai')`。说明:BOOL 类型写作 `{true, false}` 或 `{0, 1}` 均可,但不能写作 0、1 之外的整数;FLOAT 和 DOUBLE 类型会受到浮点数精度影响,集合内的值在精度范围内认为和数据行的值完全相等才能匹配成功;TIMESTAMP 类型支持非主键的列。
-7. 从 2.3.0.0 版本开始,条件过滤开始支持正则表达式,关键字 match/nmatch,不区分大小写。
+- 从 2.0.17.0 版本开始,条件过滤开始支持 BETWEEN AND 语法,例如 `WHERE col2 BETWEEN 1.5 AND 3.25` 表示查询条件为“1.5 ≤ col2 ≤ 3.25”。
+- 从 2.1.4.0 版本开始,条件过滤开始支持 IN 算子,例如 `WHERE city IN ('Beijing', 'Shanghai')`。说明:BOOL 类型写作 `{true, false}` 或 `{0, 1}` 均可,但不能写作 0、1 之外的整数;FLOAT 和 DOUBLE 类型会受到浮点数精度影响,集合内的值在精度范围内认为和数据行的值完全相等才能匹配成功;TIMESTAMP 类型支持非主键的列。
+- 从 2.3.0.0 版本开始,条件过滤开始支持正则表达式,关键字 match/nmatch,不区分大小写。
## 正则表达式过滤
@@ -376,14 +378,18 @@ WHERE t1.ts = t2.ts AND t1.deviceid = t2.deviceid AND t1.status=0;
类似地,也可以对多个子查询的查询结果进行 JOIN 操作。
-注意,JOIN 操作存在如下限制要求:
+:::note
+
+JOIN语句存在如下限制要求:
-1. 参与一条语句中 JOIN 操作的表/超级表最多可以有 10 个。
-2. 在包含 JOIN 操作的查询语句中不支持 FILL。
-3. 暂不支持参与 JOIN 操作的表之间聚合后的四则运算。
-4. 不支持只对其中一部分表做 GROUP BY。
-5. JOIN 查询的不同表的过滤条件之间不能为 OR。
-6. JOIN 查询要求连接条件不能是普通列,只能针对标签和主时间字段列(第一列)。
+- 参与一条语句中 JOIN 操作的表/超级表最多可以有 10 个。
+- 在包含 JOIN 操作的查询语句中不支持 FILL。
+- 暂不支持参与 JOIN 操作的表之间聚合后的四则运算。
+- 不支持只对其中一部分表做 GROUP BY。
+- JOIN 查询的不同表的过滤条件之间不能为 OR。
+- JOIN 查询要求连接条件不能是普通列,只能针对标签和主时间字段列(第一列)。
+
+:::
## 嵌套查询
@@ -397,17 +403,17 @@ SELECT ... FROM (SELECT ... FROM ...) ...;
:::info
-1. 目前仅支持一层嵌套,也即不能在子查询中再嵌入子查询。
-2. 内层查询的返回结果将作为“虚拟表”供外层查询使用,此虚拟表可以使用 AS 语法做重命名,以便于外层查询中方便引用。
-3. 目前不能在“连续查询”功能中使用子查询。
-4. 在内层和外层查询中,都支持普通的表间/超级表间 JOIN。内层查询的计算结果也可以再参与数据子表的 JOIN 操作。
-5. 目前内层查询、外层查询均不支持 UNION 操作。
-6. 内层查询支持的功能特性与非嵌套的查询语句能力是一致的。
+- 目前仅支持一层嵌套,也即不能在子查询中再嵌入子查询。
+- 内层查询的返回结果将作为“虚拟表”供外层查询使用,此虚拟表可以使用 AS 语法做重命名,以便于外层查询中方便引用。
+- 目前不能在“连续查询”功能中使用子查询。
+- 在内层和外层查询中,都支持普通的表间/超级表间 JOIN。内层查询的计算结果也可以再参与数据子表的 JOIN 操作。
+- 目前内层查询、外层查询均不支持 UNION 操作。
+- 内层查询支持的功能特性与非嵌套的查询语句能力是一致的。
- 内层查询的 ORDER BY 子句一般没有意义,建议避免这样的写法以免无谓的资源消耗。
-7. 与非嵌套的查询语句相比,外层查询所能支持的功能特性存在如下限制:
+- 与非嵌套的查询语句相比,外层查询所能支持的功能特性存在如下限制:
- 计算函数部分:
- _. 如果内层查询的结果数据未提供时间戳,那么计算过程依赖时间戳的函数在外层会无法正常工作。例如:TOP, BOTTOM, FIRST, LAST, DIFF。
- _. 计算过程需要两遍扫描的函数,在外层查询中无法正常工作。例如:此类函数包括:STDDEV, PERCENTILE。
+ - 如果内层查询的结果数据未提供时间戳,那么计算过程依赖时间戳的函数在外层会无法正常工作。例如:TOP, BOTTOM, FIRST, LAST, DIFF。
+ - 计算过程需要两遍扫描的函数,在外层查询中无法正常工作。例如:此类函数包括:STDDEV, PERCENTILE。
- 外层查询中不支持 IN 算子,但在内层中可以使用。
- 外层查询不支持 GROUP BY。
diff --git a/docs-cn/14-reference/01-taos-sql/07-function.md b/docs-cn/12-taos-sql/07-function.md
similarity index 52%
rename from docs-cn/14-reference/01-taos-sql/07-function.md
rename to docs-cn/12-taos-sql/07-function.md
index 38671a08ff11d812896fad51b647abb4e4261dd7..de993020740abe39a177f8107f0388dcc439a17e 100644
--- a/docs-cn/14-reference/01-taos-sql/07-function.md
+++ b/docs-cn/12-taos-sql/07-function.md
@@ -1,9 +1,8 @@
---
sidebar_label: SQL 函数
+title: SQL 函数
---
-# SQL 函数
-
## 聚合函数
TDengine 支持针对数据的聚合查询。提供支持的聚合和选择函数如下:
@@ -14,20 +13,21 @@ TDengine 支持针对数据的聚合查询。提供支持的聚合和选择函
SELECT COUNT([*|field_name]) FROM tb_name [WHERE clause];
```
-- **功能说明**:统计表/超级表中记录行数或某列的非空值个数。
-- **返回数据类型**:长整型 INT64。
-- **应用字段**:应用全部字段。
-- **适用于**:表、超级表。
+**功能说明**:统计表/超级表中记录行数或某列的非空值个数。
+
+**返回数据类型**:长整型 INT64。
+
+**应用字段**:应用全部字段。
-:::info
+**适用于**:表、超级表。
+
+**使用说明**:
- 可以使用星号(\*)来替代具体的字段,使用星号(\*)返回全部记录数量。
- 针对同一表的(不包含 NULL 值)字段查询结果均相同。
- 如果统计对象是具体的列,则返回该列中非 NULL 值的记录数量。
-:::
-
-示例:
+**示例**:
```
taos> SELECT COUNT(*), COUNT(voltage) FROM meters;
@@ -49,12 +49,15 @@ Query OK, 1 row(s) in set (0.001075s)
SELECT AVG(field_name) FROM tb_name [WHERE clause];
```
-- **功能说明**:统计表/超级表中某列的平均值。
-- **返回数据类型**:双精度浮点数 Double。
-- **应用字段**:不能应用在 timestamp、binary、nchar、bool 字段。
-- **适用于**:表、超级表。
+**功能说明**:统计表/超级表中某列的平均值。
-示例:
+**返回数据类型**:双精度浮点数 Double。
+
+**应用字段**:不能应用在 timestamp、binary、nchar、bool 字段。
+
+**适用于**:表、超级表。
+
+**示例**:
```
taos> SELECT AVG(current), AVG(voltage), AVG(phase) FROM meters;
@@ -76,12 +79,17 @@ Query OK, 1 row(s) in set (0.000943s)
SELECT TWA(field_name) FROM tb_name WHERE clause;
```
-- **功能说明**:时间加权平均函数。统计表中某列在一段时间内的时间加权平均。
-- **返回数据类型**:双精度浮点数 Double。
-- **应用字段**:不能应用在 timestamp、binary、nchar、bool 类型字段。
-- **适用于**:表、(超级表。
+**功能说明**:时间加权平均函数。统计表中某列在一段时间内的时间加权平均。
+
+**返回数据类型**:双精度浮点数 Double。
+
+**应用字段**:不能应用在 timestamp、binary、nchar、bool 类型字段。
+
+**适用于**:表、超级表。
+
+**使用说明**:
-说明:从 2.1.3.0 版本开始,TWA 函数可以在由 GROUP BY 划分出单独时间线的情况下用于超级表(也即 GROUP BY tbname)。
+- 从 2.1.3.0 版本开始,TWA 函数可以在由 GROUP BY 划分出单独时间线的情况下用于超级表(也即 GROUP BY tbname)。
### IRATE
@@ -95,9 +103,11 @@ SELECT IRATE(field_name) FROM tb_name WHERE clause;
**应用字段**:不能应用在 timestamp、binary、nchar、bool 类型字段。
-适用于:**表、(超级表)**。
+**适用于**:表、超级表。
+
+**使用说明**:
-说明:(从 2.1.3.0 版本开始新增此函数)IRATE 可以在由 GROUP BY 划分出单独时间线的情况下用于超级表(也即 GROUP BY tbname)。
+- 从 2.1.3.0 版本开始此函数可用,IRATE 可以在由 GROUP BY 划分出单独时间线的情况下用于超级表(也即 GROUP BY tbname)。
### SUM
@@ -113,7 +123,7 @@ SELECT SUM(field_name) FROM tb_name [WHERE clause];
**适用于**:表、超级表。
-示例:
+**示例**:
```
taos> SELECT SUM(current), SUM(voltage), SUM(phase) FROM meters;
@@ -141,9 +151,9 @@ SELECT STDDEV(field_name) FROM tb_name [WHERE clause];
**应用字段**:不能应用在 timestamp、binary、nchar、bool 类型字段。
-**适用于**:表。(从 2.0.15.1 版本开始,本函数也支持**超级表**)
+**适用于**:表、超级表(从 2.0.15.1 版本开始)
-示例:
+**示例**:
```
taos> SELECT STDDEV(current) FROM d1001;
@@ -159,12 +169,15 @@ Query OK, 1 row(s) in set (0.000915s)
SELECT LEASTSQUARES(field_name, start_val, step_val) FROM tb_name [WHERE clause];
```
-- **功能说明**:统计表中某列的值是主键(时间戳)的拟合直线方程。start_val 是自变量初始值,step_val 是自变量的步长值。
-- **返回数据类型**:字符串表达式(斜率, 截距)。
-- **应用字段**:不能应用在 timestamp、binary、nchar、bool 类型字段。
-- **适用于**:表。
+**功能说明**:统计表中某列的值是主键(时间戳)的拟合直线方程。start_val 是自变量初始值,step_val 是自变量的步长值。
+
+**返回数据类型**:字符串表达式(斜率, 截距)。
+
+**应用字段**:不能应用在 timestamp、binary、nchar、bool 类型字段。
+
+**适用于**:表。
-示例:
+**示例**:
```
taos> SELECT LEASTSQUARES(current, 1, 1) FROM d1001;
@@ -179,13 +192,18 @@ Query OK, 1 row(s) in set (0.000921s)
```
SELECT MODE(field_name) FROM tb_name [WHERE clause];
```
-- **功能说明**:返回出现频率最高的值,若存在多个频率相同的最高值,输出空。不能匹配标签、时间戳输出。
-- **返回数据类型**:同应用的字段。
-- **应用字段**:适合于除时间主列外的任何类型字段。
-- **说明**:由于返回数据量未知,考虑到内存因素,为了函数可以正常返回结果,建议不重复的数据量在10万级别,否则会报错。
-- **支持的版本**:2.6开始的版本。
-示例:
+**功能说明**:返回出现频率最高的值,若存在多个频率相同的最高值,输出空。不能匹配标签、时间戳输出。
+
+**返回数据类型**:同应用的字段。
+
+**应用字段**:适合于除时间主列外的任何类型字段。
+
+**使用说明**:由于返回数据量未知,考虑到内存因素,为了函数可以正常返回结果,建议不重复的数据量在 10 万级别,否则会报错。
+
+**支持的版本**:2.6.0.0 及以后的版本。
+
+**示例**:
```
taos> select voltage from d002;
@@ -202,20 +220,25 @@ taos> select mode(voltage) from d002;
========================
1 |
Query OK, 1 row(s) in set (0.019393s)
-```
+```
### HYPERLOGLOG
+
```
SELECT HYPERLOGLOG(field_name) FROM { tb_name | stb_name } [WHERE clause];
```
-- **功能说明**:
- - 采用hyperloglog算法,返回某列的基数。该算法在数据量很大的情况下,可以明显降低内存的占用,但是求出来的基数是个估算值,标准误差(标准误差是多次实验,每次的平均数的标准差,不是与真实结果的误差)为0.81%。
- - 在数据量较少的时候该算法不是很准确,可以使用select count(data) from (select unique(col) as data from table) 的方法。
-- **返回结果类型**:整形。
-- **应用字段**:适合于任何类型字段。
-- **支持的版本**:2.6开始的版本。
-示例:
+**功能说明**:
+ - 采用 hyperloglog 算法,返回某列的基数。该算法在数据量很大的情况下,可以明显降低内存的占用,但是求出来的基数是个估算值,标准误差(标准误差是多次实验,每次的平均数的标准差,不是与真实结果的误差)为 0.81%。
+ - 在数据量较少的时候该算法不是很准确,可以使用 select count(data) from (select unique(col) as data from table) 的方法。
+
+**返回结果类型**:整形。
+
+**应用字段**:适合于任何类型字段。
+
+**支持的版本**:2.6.0.0 及以后的版本。
+
+**示例**:
```
taos> select dbig from shll;
@@ -236,7 +259,7 @@ taos> select hyperloglog(dbig) from shll;
========================
4 |
Query OK, 1 row(s) in set (0.008388s)
- ```
+```
## 选择函数
@@ -256,7 +279,7 @@ SELECT MIN(field_name) FROM {tb_name | stb_name} [WHERE clause];
**适用于**:表、超级表。
-示例:
+**示例**:
```
taos> SELECT MIN(current), MIN(voltage) FROM meters;
@@ -286,7 +309,7 @@ SELECT MAX(field_name) FROM { tb_name | stb_name } [WHERE clause];
**适用于**:表、超级表。
-示例:
+**示例**:
```
taos> SELECT MAX(current), MAX(voltage) FROM meters;
@@ -316,15 +339,13 @@ SELECT FIRST(field_name) FROM { tb_name | stb_name } [WHERE clause];
**适用于**:表、超级表。
-说明:
-
-1)如果要返回各个列的首个(时间戳最小)非 NULL 值,可以使用 FIRST(\*);
-
-2)如果结果集中的某列全部为 NULL 值,则该列的返回结果也是 NULL;
+**使用说明**:
-3)如果结果集中所有列全部为 NULL 值,则不返回结果。
+- 如果要返回各个列的首个(时间戳最小)非 NULL 值,可以使用 FIRST(\*);
+- 如果结果集中的某列全部为 NULL 值,则该列的返回结果也是 NULL;
+- 如果结果集中所有列全部为 NULL 值,则不返回结果。
-示例:
+**示例**:
```
taos> SELECT FIRST(*) FROM meters;
@@ -354,15 +375,14 @@ SELECT LAST(field_name) FROM { tb_name | stb_name } [WHERE clause];
**适用于**:表、超级表。
-说明:
+**使用说明**:
-1)如果要返回各个列的最后(时间戳最大)一个非 NULL 值,可以使用 LAST(\*);
+- 如果要返回各个列的最后(时间戳最大)一个非 NULL 值,可以使用 LAST(\*);
+- 如果结果集中的某列全部为 NULL 值,则该列的返回结果也是 NULL;如果结果集中所有列全部为 NULL 值,则不返回结果。
+- 在用于超级表时,时间戳完全一样且同为最大的数据行可能有多个,那么会从中随机返回一条,而并不保证多次运行所挑选的数据行必然一致。
-2)如果结果集中的某列全部为 NULL 值,则该列的返回结果也是 NULL;如果结果集中所有列全部为 NULL 值,则不返回结果。
-3)在用于超级表时,时间戳完全一样且同为最大的数据行可能有多个,那么会从中随机返回一条,而并不保证多次运行所挑选的数据行必然一致。
-
-示例:
+**示例**:
```
taos> SELECT LAST(*) FROM meters;
@@ -392,15 +412,13 @@ SELECT TOP(field_name, K) FROM { tb_name | stb_name } [WHERE clause];
**适用于**:表、超级表。
-说明:
-
-1)*k*值取值范围 1≤*k*≤100;
-
-2)系统同时返回该记录关联的时间戳列;
+**使用说明**:
-3)限制:TOP 函数不支持 FILL 子句。
+- *k*值取值范围 1≤*k*≤100;
+- 系统同时返回该记录关联的时间戳列;
+- 限制:TOP 函数不支持 FILL 子句。
-示例:
+**示例**:
```
taos> SELECT TOP(current, 3) FROM meters;
@@ -433,15 +451,13 @@ SELECT BOTTOM(field_name, K) FROM { tb_name | stb_name } [WHERE clause];
**适用于**:表、超级表。
-说明:
+**使用说明**:
-1)*k*值取值范围 1≤*k*≤100;
+- *k*值取值范围 1≤*k*≤100;
+- 系统同时返回该记录关联的时间戳列;
+- 限制:BOTTOM 函数不支持 FILL 子句。
-2)系统同时返回该记录关联的时间戳列;
-
-3)限制:BOTTOM 函数不支持 FILL 子句。
-
-示例:
+**示例**:
```
taos> SELECT BOTTOM(voltage, 2) FROM meters;
@@ -473,9 +489,9 @@ SELECT PERCENTILE(field_name, P) FROM { tb_name } [WHERE clause];
**适用于**:表。
-说明:*P*值取值范围 0≤*P*≤100,为 0 的时候等同于 MIN,为 100 的时候等同于 MAX。
+**使用说明**:*P*值取值范围 0≤*P*≤100,为 0 的时候等同于 MIN,为 100 的时候等同于 MAX。
-示例:
+**示例**:
```
taos> SELECT PERCENTILE(current, 20) FROM d1001;
@@ -500,9 +516,14 @@ FROM { tb_name | stb_name } [WHERE clause]
**适用于**:表、超级表。
-说明:
**P**值有效取值范围 0≤P≤100,为 0 的时候等同于 MIN,为 100 的时候等同于 MAX;
**algo_type**的有效输入:**default** 和 **t-digest**。 用于指定计算近似分位数的算法。可不提供第三个参数的输入,此时将使用 default 的算法进行计算,即 apercentile(column_name, 50, "default") 与 apercentile(column_name, 50) 等价。当使用“t-digest”参数的时候,将使用 t-digest 方式采样计算近似分位数。但该参数指定计算算法的功能从 2.2.0.x 版本开始支持,2.2.0.0 之前的版本不支持指定使用算法的功能。
+**使用说明**
+
+- **P**值有效取值范围 0≤P≤100,为 0 的时候等同于 MIN,为 100 的时候等同于 MAX;
+- **algo_type**的有效输入:**default** 和 **t-digest**
+- 用于指定计算近似分位数的算法。可不提供第三个参数的输入,此时将使用 default 的算法进行计算,即 apercentile(column_name, 50, "default") 与 apercentile(column_name, 50) 等价。
+- 当使用“t-digest”参数的时候,将使用 t-digest 方式采样计算近似分位数。但该参数指定计算算法的功能从 2.2.0.x 版本开始支持,2.2.0.0 之前的版本不支持指定使用算法的功能。
-嵌套子查询支持:适用于内层查询和外层查询。
+**嵌套子查询支持**:适用于内层查询和外层查询。
```
taos> SELECT APERCENTILE(current, 20) FROM d1001;
@@ -538,16 +559,12 @@ SELECT LAST_ROW(field_name) FROM { tb_name | stb_name };
**适用于**:表、超级表。
-限制:LAST_ROW() 不能与 INTERVAL 一起使用。
+**使用说明**:
-说明:在用于超级表时,时间戳完全一样且同为最大的数据行可能有多个,那么会从中随机返回一条,而并不保证多次运行所挑选的数据行必然一致。
+- 在用于超级表时,时间戳完全一样且同为最大的数据行可能有多个,那么会从中随机返回一条,而并不保证多次运行所挑选的数据行必然一致。
+- 不能与 INTERVAL 一起使用。
-{" "}
-
-{" "}
-
-
-示例:
+**示例**:
```
taos> SELECT LAST_ROW(current) FROM meters;
@@ -575,53 +592,49 @@ SELECT INTERP(field_name) FROM { tb_name | stb_name } [WHERE where_condition] [
**应用字段**:数值型字段。
-适用于:**表、超级表、嵌套查询**。
-
-说明:
-1)INTERP 用于在指定时间断面获取指定列的记录值,如果该时间断面不存在符合条件的行数据,那么会根据 FILL 参数的设定进行插值。
-
-2)INTERP 的输入数据为指定列的数据,可以通过条件语句(where 子句)来对原始列数据进行过滤,如果没有指定过滤条件则输入为全部数据。
-
-3)INTERP 的输出时间范围根据 RANGE(timestamp1,timestamp2)字段来指定,需满足 timestamp1<=timestamp2。其中 timestamp1(必选值)为输出时间范围的起始值,即如果 timestamp1 时刻符合插值条件则 timestamp1 为输出的第一条记录,timestamp2(必选值)为输出时间范围的结束值,即输出的最后一条记录的 timestamp 不能大于 timestamp2。如果没有指定 RANGE,那么满足过滤条件的输入数据中第一条记录的 timestamp 即为 timestamp1,最后一条记录的 timestamp 即为 timestamp2,同样也满足 timestamp1 <= timestamp2。
-
-4)INTERP 根据 EVERY 字段来确定输出时间范围内的结果条数,即从 timestamp1 开始每隔固定长度的时间(EVERY 值)进行插值。如果没有指定 EVERY,则默认窗口大小为无穷大,即从 timestamp1 开始只有一个窗口。
+**适用于**:表、超级表、嵌套查询。
-5)INTERP 根据 FILL 字段来决定在每个符合输出条件的时刻如何进行插值,如果没有 FILL 字段则默认不插值,即输出为原始记录值或不输出(原始记录不存在)。
-6)INTERP 只能在一个时间序列内进行插值,因此当作用于超级表时必须跟 group by tbname 一起使用,当作用嵌套查询外层时内层子查询不能含 GROUP BY 信息。
+**使用说明**
-7)INTERP 的插值结果不受 ORDER BY timestamp 的影响,ORDER BY timestamp 只影响输出结果的排序。
+- INTERP 用于在指定时间断面获取指定列的记录值,如果该时间断面不存在符合条件的行数据,那么会根据 FILL 参数的设定进行插值。
+- INTERP 的输入数据为指定列的数据,可以通过条件语句(where 子句)来对原始列数据进行过滤,如果没有指定过滤条件则输入为全部数据。
+- INTERP 的输出时间范围根据 RANGE(timestamp1,timestamp2)字段来指定,需满足 timestamp1<=timestamp2。其中 timestamp1(必选值)为输出时间范围的起始值,即如果 timestamp1 时刻符合插值条件则 timestamp1 为输出的第一条记录,timestamp2(必选值)为输出时间范围的结束值,即输出的最后一条记录的 timestamp 不能大于 timestamp2。如果没有指定 RANGE,那么满足过滤条件的输入数据中第一条记录的 timestamp 即为 timestamp1,最后一条记录的 timestamp 即为 timestamp2,同样也满足 timestamp1 <= timestamp2。
+- INTERP 根据 EVERY 字段来确定输出时间范围内的结果条数,即从 timestamp1 开始每隔固定长度的时间(EVERY 值)进行插值。如果没有指定 EVERY,则默认窗口大小为无穷大,即从 timestamp1 开始只有一个窗口。
+- INTERP 根据 FILL 字段来决定在每个符合输出条件的时刻如何进行插值,如果没有 FILL 字段则默认不插值,即输出为原始记录值或不输出(原始记录不存在)。
+- INTERP 只能在一个时间序列内进行插值,因此当作用于超级表时必须跟 group by tbname 一起使用,当作用嵌套查询外层时内层子查询不能含 GROUP BY 信息。
+- INTERP 的插值结果不受 ORDER BY timestamp 的影响,ORDER BY timestamp 只影响输出结果的排序。
-SQL 示例:
+**SQL示例(基于文档中广泛使用的电表 schema )**:
- 1) 单点线性插值
+- 单点线性插值
```
- taos> SELECT INTERP(*) FROM t1 RANGE('2017-7-14 18:40:00','2017-7-14 18:40:00') FILL(LINEAR);
+ taos> SELECT INTERP(current) FROM t1 RANGE('2017-7-14 18:40:00','2017-7-14 18:40:00') FILL(LINEAR);
```
- 2) 在2017-07-14 18:00:00到2017-07-14 19:00:00间每隔5秒钟进行取值(不插值)
+- 在2017-07-14 18:00:00到2017-07-14 19:00:00间每隔5秒钟进行取值(不插值)
```
- taos> SELECT INTERP(*) FROM t1 RANGE('2017-7-14 18:00:00','2017-7-14 19:00:00') EVERY(5s);
+ taos> SELECT INTERP(current) FROM t1 RANGE('2017-7-14 18:00:00','2017-7-14 19:00:00') EVERY(5s);
```
- 3) 在2017-07-14 18:00:00到2017-07-14 19:00:00间每隔5秒钟进行线性插值
+- 在2017-07-14 18:00:00到2017-07-14 19:00:00间每隔5秒钟进行线性插值
```
- taos> SELECT INTERP(*) FROM t1 RANGE('2017-7-14 18:00:00','2017-7-14 19:00:00') EVERY(5s) FILL(LINEAR);
+ taos> SELECT INTERP(current) FROM t1 RANGE('2017-7-14 18:00:00','2017-7-14 19:00:00') EVERY(5s) FILL(LINEAR);
```
-4.在所有时间范围内每隔 5 秒钟进行向后插值
+- 在所有时间范围内每隔 5 秒钟进行向后插值
```
- taos> SELECT INTERP(*) FROM t1 EVERY(5s) FILL(NEXT);
+ taos> SELECT INTERP(current) FROM t1 EVERY(5s) FILL(NEXT);
```
-5.根据 2017-07-14 17:00:00 到 2017-07-14 20:00:00 间的数据进行从 2017-07-14 18:00:00 到 2017-07-14 19:00:00 间每隔 5 秒钟进行线性插值
+- 根据 2017-07-14 17:00:00 到 2017-07-14 20:00:00 间的数据进行从 2017-07-14 18:00:00 到 2017-07-14 19:00:00 间每隔 5 秒钟进行线性插值
```
- taos> SELECT INTERP(*) FROM t1 where ts >= '2017-07-14 17:00:00' and ts <= '2017-07-14 20:00:00' RANGE('2017-7-14 18:00:00','2017-7-14 19:00:00') EVERY(5s) FILL(LINEAR);
+ taos> SELECT INTERP(current) FROM t1 where ts >= '2017-07-14 17:00:00' and ts <= '2017-07-14 20:00:00' RANGE('2017-7-14 18:00:00','2017-7-14 19:00:00') EVERY(5s) FILL(LINEAR);
```
### INTERP [2.3.1 之前的版本]
@@ -638,8 +651,14 @@ SELECT INTERP(field_name) FROM { tb_name | stb_name } WHERE ts='timestamp' [FILL
**适用于**:表、超级表。
-说明:(从 2.0.15.0 版本开始新增此函数)
1)INTERP 必须指定时间断面,如果该时间断面不存在直接对应的数据,那么会根据 FILL 参数的设定进行插值。此外,条件语句里面可附带筛选条件,例如标签、tbname。
2)INTERP 查询要求查询的时间区间必须位于数据集合(表)的所有记录的时间范围之内。如果给定的时间戳位于时间范围之外,即使有插值指令,仍然不返回结果。
3)单个 INTERP 函数查询只能够针对一个时间点进行查询,如果需要返回等时间间隔的断面数据,可以通过 INTERP 配合 EVERY 的方式来进行查询处理(而不是使用 INTERVAL),其含义是每隔固定长度的时间进行插值。
- 示例:
+**使用说明**:
+
+- 从 2.0.15.0 及以后版本可用
+- INTERP 必须指定时间断面,如果该时间断面不存在直接对应的数据,那么会根据 FILL 参数的设定进行插值。此外,条件语句里面可附带筛选条件,例如标签、tbname。
+- INTERP 查询要求查询的时间区间必须位于数据集合(表)的所有记录的时间范围之内。如果给定的时间戳位于时间范围之外,即使有插值指令,仍然不返回结果。
+- 单个 INTERP 函数查询只能够针对一个时间点进行查询,如果需要返回等时间间隔的断面数据,可以通过 INTERP 配合 EVERY 的方式来进行查询处理(而不是使用 INTERVAL),其含义是每隔固定长度的时间进行插值
+
+**示例**:
```
taos> SELECT INTERP(*) FROM meters WHERE ts='2017-7-14 18:40:00.004';
@@ -674,20 +693,23 @@ SELECT INTERP(field_name) FROM { tb_name | stb_name } WHERE ts='timestamp' [FILL
```
### TAIL
+
```
SELECT TAIL(field_name, k, offset_val) FROM {tb_name | stb_name} [WHERE clause];
```
-**功能说明**:返回跳过最后 offset_value个,然后取连续 k 个记录,不忽略 NULL 值。offset_val 可以不输入。此时返回最后的 k 个记录。当有 offset_val 输入的情况下,该函数功能等效于order by ts desc LIMIT k OFFSET offset_val。
-**参数范围**:k: [1,100] offset_val: [0,100]。
+**功能说明**:返回跳过最后 offset_value 个,然后取连续 k 个记录,不忽略 NULL 值。offset_val 可以不输入。此时返回最后的 k 个记录。当有 offset_val 输入的情况下,该函数功能等效于 `order by ts desc LIMIT k OFFSET offset_val`。
+
+**参数范围**:k: [1,100] offset_val: [0,100]。
**返回结果数据类型**:同应用的字段。
**应用字段**:适合于除时间主列外的任何类型字段。
-**支持版本**:2.6 开始的版本。
+**支持版本**:2.6.0.0 及之后的版本。
+
+**示例**:
-示例:
```
taos> select ts,dbig from tail2;
ts | dbig |
@@ -709,22 +731,26 @@ Query OK, 2 row(s) in set (0.002307s)
```
### UNIQUE
+
```
SELECT UNIQUE(field_name) FROM {tb_name | stb_name} [WHERE clause];
```
+
**功能说明**:返回该列的数值首次出现的值。该函数功能与 distinct 相似,但是可以匹配标签和时间戳信息。可以针对除时间列以外的字段进行查询,可以匹配标签和时间戳,其中的标签和时间戳是第一次出现时刻的标签和时间戳。
**返回结果数据类型**:同应用的字段。
**应用字段**:适合于除时间类型以外的字段。
-**支持版本**:2.6 开始的版本。
+**支持版本**:2.6.0.0 及之后的版本。
+
+**使用说明**:
+
+- 该函数可以应用在普通表和超级表上。不能和窗口操作一起使用,例如 interval/state_window/session_window 。
+- 由于返回数据量未知,考虑到内存因素,为了函数可以正常返回结果,建议不重复的数据量在 10 万级别,否则会报错。
+
+**示例**:
-**说明**:
- - 该函数可以应用在普通表和超级表上。不能和窗口操作一起使用,例如 interval/state_window/session_window 。
- - 由于返回数据量未知,考虑到内存因素,为了函数可以正常返回结果,建议不重复的数据量在10万级别,否则会报错。
-
-示例:
```
taos> select ts,voltage from unique1;
ts | voltage |
@@ -752,29 +778,36 @@ Query OK, 5 row(s) in set (0.108458s)
## 计算函数
-- **DIFF**
- ```mysql
- SELECT {DIFF(field_name, ignore_negative) | DIFF(field_name)} FROM tb_name [WHERE clause];
- ```
- 功能说明:统计表中某列的值与前一行对应值的差。 ignore_negative 取值为 0|1 , 可以不填,默认值为 0. 不忽略负值。ignore_negative为1时表示忽略负数。
+### DIFF
- 返回结果数据类型:同应用字段。
+ ```sql
+ SELECT {DIFF(field_name, ignore_negative) | DIFF(field_name)} FROM tb_name [WHERE clause];
+ ```
- 应用字段:不能应用在timestamp、binary、nchar、bool类型字段。
+**功能说明**:统计表中某列的值与前一行对应值的差。 ignore_negative 取值为 0|1 , 可以不填,默认值为 0. 不忽略负值。ignore_negative 为 1 时表示忽略负数。
- 适用于:**表、(超级表)**。
+**返回结果数据类型**:同应用字段。
- 说明:输出结果行数是范围内总行数减一,第一行没有结果输出。从 2.1.3.0 版本开始,DIFF 函数可以在由 GROUP BY 划分出单独时间线的情况下用于超级表(也即 GROUP BY tbname)。从2.6.0开始,DIFF函数支持ignore_negative参数
+**应用字段**:不能应用在 timestamp、binary、nchar、bool 类型字段。
- 示例:
- ```mysql
- taos> SELECT DIFF(current) FROM d1001;
- ts | diff(current) |
- =================================================
- 2018-10-03 14:38:15.000 | 2.30000 |
- 2018-10-03 14:38:16.800 | -0.30000 |
- Query OK, 2 row(s) in set (0.001162s)
- ```
+**适用于**:表、超级表。
+
+**使用说明**:
+
+- 输出结果行数是范围内总行数减一,第一行没有结果输出。
+- 从 2.1.3.0 版本开始,DIFF 函数可以在由 GROUP BY 划分出单独时间线的情况下用于超级表(也即 GROUP BY tbname)。
+- 从 2.6.0 开始,DIFF 函数支持 ignore_negative 参数
+
+**示例**:
+
+ ```sql
+ taos> SELECT DIFF(current) FROM d1001;
+ ts | diff(current) |
+ =================================================
+ 2018-10-03 14:38:15.000 | 2.30000 |
+ 2018-10-03 14:38:16.800 | -0.30000 |
+ Query OK, 2 row(s) in set (0.001162s)
+ ```
### DERIVATIVE
@@ -788,11 +821,14 @@ SELECT DERIVATIVE(field_name, time_interval, ignore_negative) FROM tb_name [WHER
**应用字段**:不能应用在 timestamp、binary、nchar、bool 类型字段。
-适用于:**表、(超级表)**。
+**适用于**:表、超级表
+
+**使用说明**:
-说明:(从 2.1.3.0 版本开始新增此函数)输出结果行数是范围内总行数减一,第一行没有结果输出。DERIVATIVE 函数可以在由 GROUP BY 划分出单独时间线的情况下用于超级表(也即 GROUP BY tbname)。
+- 从 2.1.3.0 及以后版本可用;输出结果行数是范围内总行数减一,第一行没有结果输出。
+- DERIVATIVE 函数可以在由 GROUP BY 划分出单独时间线的情况下用于超级表(也即 GROUP BY tbname)。
-示例:
+**示例**:
```
taos> select derivative(current, 10m, 0) from t1;
@@ -820,9 +856,9 @@ SELECT SPREAD(field_name) FROM { tb_name | stb_name } [WHERE clause];
**适用于**:表、超级表。
-说明:可用于 TIMESTAMP 字段,此时表示记录的时间覆盖范围。
+**使用说明**:可用于 TIMESTAMP 字段,此时表示记录的时间覆盖范围。
-示例:
+**示例**:
```
taos> SELECT SPREAD(voltage) FROM meters;
@@ -846,16 +882,18 @@ SELECT CEIL(field_name) FROM { tb_name | stb_name } [WHERE clause];
**功能说明**:获得指定列的向上取整数的结果。
-返回结果类型:与指定列的原始数据类型一致。例如,如果指定列的原始数据类型为 Float,那么返回的数据类型也为 Float;如果指定列的原始数据类型为 Double,那么返回的数据类型也为 Double。
+**返回结果类型**:与指定列的原始数据类型一致。例如,如果指定列的原始数据类型为 Float,那么返回的数据类型也为 Float;如果指定列的原始数据类型为 Double,那么返回的数据类型也为 Double。
+
+**适用数据类型**:不能应用在 timestamp、binary、nchar、bool 类型字段上;在超级表查询中使用时,不能应用在 tag 列,无论 tag 列的类型是什么类型。
-适用数据类型:不能应用在 timestamp、binary、nchar、bool 类型字段上;在超级表查询中使用时,不能应用在 tag 列,无论 tag 列的类型是什么类型。
+**适用于**: 普通表、超级表。
-嵌套子查询支持:适用于内层查询和外层查询。
+**嵌套子查询支持**:适用于内层查询和外层查询。
-说明:
-支持 +、-、\*、/ 运算,如 ceil(col1) + ceil(col2)。
-只能与普通列,选择(Selection)、投影(Projection)函数一起使用,不能与聚合(Aggregation)函数一起使用。
-该函数可以应用在普通表和超级表上。
+**使用说明**:
+
+- 支持 +、-、\*、/ 运算,如 ceil(col1) + ceil(col2)。
+- 只能与普通列,选择(Selection)、投影(Projection)函数一起使用,不能与聚合(Aggregation)函数一起使用。
### FLOOR
@@ -875,380 +913,470 @@ SELECT ROUND(field_name) FROM { tb_name | stb_name } [WHERE clause];
**功能说明**:获得指定列的四舍五入的结果。
其他使用说明参见 CEIL 函数描述。
-- **ASIN**
- ```mysql
- SELECT ASIN(field_name) FROM { tb_name | stb_name } [WHERE clause]
+### CSUM
+
+ ```sql
+ SELECT CSUM(field_name) FROM { tb_name | stb_name } [WHERE clause]
```
- 功能说明:获得指定列的反正弦结果
- 返回结果类型:DOUBLE。如果输入值为NULL,输出值也为NULL
+ **功能说明**:累加和(Cumulative sum),输出行与输入行数相同。
+
+ **返回结果类型**: 输入列如果是整数类型返回值为长整型 (int64_t),浮点数返回值为双精度浮点数(Double)。无符号整数类型返回值为无符号长整型(uint64_t)。 返回结果中同时带有每行记录对应的时间戳。
- 适用数据类型:不能应用在 timestamp、binary、nchar、bool 类型字段上;在超级表查询中使用时,不能应用在 tag 列
+ **适用数据类型**:不能应用在 timestamp、binary、nchar、bool 类型字段上;在超级表查询中使用时,不能应用在标签之上。
- 嵌套子查询支持:适用于内层查询和外层查询。
+ **嵌套子查询支持**: 适用于内层查询和外层查询。
- 使用说明:
+ **使用说明**:
+
+ - 不支持 +、-、*、/ 运算,如 csum(col1) + csum(col2)。
+ - 只能与聚合(Aggregation)函数一起使用。 该函数可以应用在普通表和超级表上。
+ - 使用在超级表上的时候,需要搭配 Group by tbname使用,将结果强制规约到单个时间线。
- 只能与普通列,选择(Selection)、投影(Projection)函数一起使用,不能与聚合(Aggregation)函数一起使用。
+**支持版本**: 从2.3.0.x开始支持
- 该函数可以应用在普通表和超级表上。
+### MAVG
-- **ACOS**
- ```mysql
- SELECT ACOS(field_name) FROM { tb_name | stb_name } [WHERE clause]
+ ```sql
+ SELECT MAVG(field_name, K) FROM { tb_name | stb_name } [WHERE clause]
```
- 功能说明:获得指定列的反余弦结果
- 返回结果类型:DOUBLE。如果输入值为NULL,输出值也为NULL
+ **功能说明**: 计算连续 k 个值的移动平均数(moving average)。如果输入行数小于 k,则无结果输出。参数 k 的合法输入范围是 1≤ k ≤ 1000。
+
+ **返回结果类型**: 返回双精度浮点数类型。
- 适用数据类型:不能应用在 timestamp、binary、nchar、bool 类型字段上;在超级表查询中使用时,不能应用在 tag 列
+ **适用数据类型**: 不能应用在 timestamp、binary、nchar、bool 类型上;在超级表查询中使用时,不能应用在标签之上。
- 嵌套子查询支持:适用于内层查询和外层查询。
+ **嵌套子查询支持**: 适用于内层查询和外层查询。
- 使用说明:
+ **使用说明**:
+
+ - 不支持 +、-、*、/ 运算,如 mavg(col1, k1) + mavg(col2, k1);
+ - 只能与普通列,选择(Selection)、投影(Projection)函数一起使用,不能与聚合(Aggregation)函数一起使用;
+ - 该函数可以应用在普通表和超级表上;使用在超级表上的时候,需要搭配 Group by tbname使用,将结果强制规约到单个时间线。
- 只能与普通列,选择(Selection)、投影(Projection)函数一起使用,不能与聚合(Aggregation)函数一起使用。
+**支持版本**: 从2.3.0.x开始支持
- 该函数可以应用在普通表和超级表上。
+### SAMPLE
-- **ATAN**
- ```mysql
- SELECT ATAN(field_name) FROM { tb_name | stb_name } [WHERE clause]
+ ```sql
+ SELECT SAMPLE(field_name, K) FROM { tb_name | stb_name } [WHERE clause]
```
- 功能说明:获得指定列的反正切结果
- 返回结果类型:DOUBLE。如果输入值为NULL,输出值也为NULL
+ **功能说明**: 获取数据的 k 个采样值。参数 k 的合法输入范围是 1≤ k ≤ 1000。
- 适用数据类型:不能应用在 timestamp、binary、nchar、bool 类型字段上;在超级表查询中使用时,不能应用在 tag 列
+ **返回结果类型**: 同原始数据类型, 返回结果中带有该行记录的时间戳。
- 嵌套子查询支持:适用于内层查询和外层查询。
+ **适用数据类型**: 在超级表查询中使用时,不能应用在标签之上。
- 使用说明:
+ **嵌套子查询支持**: 适用于内层查询和外层查询。
- 只能与普通列,选择(Selection)、投影(Projection)函数一起使用,不能与聚合(Aggregation)函数一起使用。
+ **使用说明**:
+
+ - 不能参与表达式计算;该函数可以应用在普通表和超级表上;
+ - 使用在超级表上的时候,需要搭配 Group by tbname 使用,将结果强制规约到单个时间线。
- 该函数可以应用在普通表和超级表上。
+**支持版本**: 从2.3.0.x开始支持
- 版本2.6.0.x后支持
+### ASIN
-- **SIN**
- ```mysql
- SELECT SIN(field_name) FROM { tb_name | stb_name } [WHERE clause]
- ```
- 功能说明:获得指定列的正弦结果
+ ```sql
+ SELECT ASIN(field_name) FROM { tb_name | stb_name } [WHERE clause]
+ ```
- 返回结果类型:DOUBLE。如果输入值为NULL,输出值也为NULL
+**功能说明**:获得指定列的反正弦结果
- 适用数据类型:不能应用在 timestamp、binary、nchar、bool 类型字段上;在超级表查询中使用时,不能应用在 tag 列
+**返回结果类型**:DOUBLE。如果输入值为 NULL,输出值也为 NULL
- 嵌套子查询支持:适用于内层查询和外层查询。
+**适用数据类型**:不能应用在 timestamp、binary、nchar、bool 类型字段上;在超级表查询中使用时,不能应用在 tag 列
- 使用说明:
+**嵌套子查询支持**:适用于内层查询和外层查询。
- 只能与普通列,选择(Selection)、投影(Projection)函数一起使用,不能与聚合(Aggregation)函数一起使用。
+**使用说明**:
- 该函数可以应用在普通表和超级表上。
+- 只能与普通列,选择(Selection)、投影(Projection)函数一起使用,不能与聚合(Aggregation)函数一起使用。
+- 该函数可以应用在普通表和超级表上。
+- 版本2.6.0.x后支持
- 版本2.6.0.x后支持
+### ACOS
-- **COS**
- ```mysql
- SELECT COS(field_name) FROM { tb_name | stb_name } [WHERE clause]
- ```
- 功能说明:获得指定列的余弦结果
+ ```sql
+ SELECT ACOS(field_name) FROM { tb_name | stb_name } [WHERE clause]
+ ```
- 返回结果类型:DOUBLE。如果输入值为NULL,输出值也为NULL
+**功能说明**:获得指定列的反余弦结果
- 适用数据类型:不能应用在 timestamp、binary、nchar、bool 类型字段上;在超级表查询中使用时,不能应用在 tag 列
+**返回结果类型**:DOUBLE。如果输入值为 NULL,输出值也为 NULL
- 嵌套子查询支持:适用于内层查询和外层查询。
+**适用数据类型**:不能应用在 timestamp、binary、nchar、bool 类型字段上;在超级表查询中使用时,不能应用在 tag 列
- 使用说明:
+**嵌套子查询支持**:适用于内层查询和外层查询。
- 只能与普通列,选择(Selection)、投影(Projection)函数一起使用,不能与聚合(Aggregation)函数一起使用。
+**使用说明**:
- 该函数可以应用在普通表和超级表上。
+- 只能与普通列,选择(Selection)、投影(Projection)函数一起使用,不能与聚合(Aggregation)函数一起使用。
+- 该函数可以应用在普通表和超级表上。
+- 版本2.6.0.x后支持
- 版本2.6.0.x后支持
+### ATAN
-- **TAN**
- ```mysql
- SELECT TAN(field_name) FROM { tb_name | stb_name } [WHERE clause]
- ```
- 功能说明:获得指定列的正切结果
+ ```sql
+ SELECT ATAN(field_name) FROM { tb_name | stb_name } [WHERE clause]
+ ```
- 返回结果类型:DOUBLE。如果输入值为NULL,输出值也为NULL
+**功能说明**:获得指定列的反正切结果
- 适用数据类型:不能应用在 timestamp、binary、nchar、bool 类型字段上;在超级表查询中使用时,不能应用在 tag 列
+**返回结果类型**:DOUBLE。如果输入值为 NULL,输出值也为 NULL
- 嵌套子查询支持:适用于内层查询和外层查询。
+**适用数据类型**:不能应用在 timestamp、binary、nchar、bool 类型字段上;在超级表查询中使用时,不能应用在 tag 列
- 使用说明:
+**嵌套子查询支持**:适用于内层查询和外层查询。
- 只能与普通列,选择(Selection)、投影(Projection)函数一起使用,不能与聚合(Aggregation)函数一起使用。
+**使用说明**:
- 该函数可以应用在普通表和超级表上。
+- 只能与普通列,选择(Selection)、投影(Projection)函数一起使用,不能与聚合(Aggregation)函数一起使用。
+- 该函数可以应用在普通表和超级表上。
+- 版本2.6.0.x后支持
- 版本2.6.0.x后支持
+### SIN
-- **POW**
- ```mysql
- SELECT POW(field_name, power) FROM { tb_name | stb_name } [WHERE clause]
- ```
- 功能说明:获得指定列的指数为power的幂
+ ```sql
+ SELECT SIN(field_name) FROM { tb_name | stb_name } [WHERE clause]
+ ```
- 返回结果类型:DOUBLE。如果输入值为NULL,输出值也为NULL
+**功能说明**:获得指定列的正弦结果
- 适用数据类型:不能应用在 timestamp、binary、nchar、bool 类型字段上;在超级表查询中使用时,不能应用在 tag 列
+**返回结果类型**:DOUBLE。如果输入值为 NULL,输出值也为 NULL
- 嵌套子查询支持:适用于内层查询和外层查询。
+**适用数据类型**:不能应用在 timestamp、binary、nchar、bool 类型字段上;在超级表查询中使用时,不能应用在 tag 列
- 使用说明:
+**嵌套子查询支持**:适用于内层查询和外层查询。
- 只能与普通列,选择(Selection)、投影(Projection)函数一起使用,不能与聚合(Aggregation)函数一起使用。
+**使用说明**:
- 该函数可以应用在普通表和超级表上。
+- 只能与普通列,选择(Selection)、投影(Projection)函数一起使用,不能与聚合(Aggregation)函数一起使用。
+- 该函数可以应用在普通表和超级表上。
+- 版本2.6.0.x后支持
- 版本2.6.0.x后支持
+### COS
-- **LOG**
- ```mysql
- SELECT LOG(field_name, base) FROM { tb_name | stb_name } [WHERE clause]
- ```
- 功能说明:获得指定列对于底数base的对数
+ ```sql
+ SELECT COS(field_name) FROM { tb_name | stb_name } [WHERE clause]
+ ```
- 返回结果类型:DOUBLE。如果输入值为NULL,输出值也为NULL
+**功能说明**:获得指定列的余弦结果
- 适用数据类型:不能应用在 timestamp、binary、nchar、bool 类型字段上;在超级表查询中使用时,不能应用在 tag 列
+**返回结果类型**:DOUBLE。如果输入值为 NULL,输出值也为 NULL
- 嵌套子查询支持:适用于内层查询和外层查询。
+**适用数据类型**:不能应用在 timestamp、binary、nchar、bool 类型字段上;在超级表查询中使用时,不能应用在 tag 列
- 使用说明:
+**嵌套子查询支持**:适用于内层查询和外层查询。
- 只能与普通列,选择(Selection)、投影(Projection)函数一起使用,不能与聚合(Aggregation)函数一起使用。
+**使用说明**:
- 该函数可以应用在普通表和超级表上。
+- 只能与普通列,选择(Selection)、投影(Projection)函数一起使用,不能与聚合(Aggregation)函数一起使用。
+- 该函数可以应用在普通表和超级表上。
+- 版本2.6.0.x后支持
- 版本2.6.0.x后支持
+### TAN
-- **ABS**
- ```mysql
- SELECT ABS(field_name) FROM { tb_name | stb_name } [WHERE clause]
- ```
- 功能说明:获得指定列的绝对值
+ ```sql
+ SELECT TAN(field_name) FROM { tb_name | stb_name } [WHERE clause]
+ ```
- 返回结果类型:如果输入值为整数,输出值是UBIGINT类型。如果输入值是FLOAT/DOUBLE数据类型,输出值是DOUBLE数据类型。
+**功能说明**:获得指定列的正切结果
- 适用数据类型:不能应用在 timestamp、binary、nchar、bool 类型字段上;在超级表查询中使用时,不能应用在 tag 列
+**返回结果类型**:DOUBLE。如果输入值为 NULL,输出值也为 NULL
- 嵌套子查询支持:适用于内层查询和外层查询。
+**适用数据类型**:不能应用在 timestamp、binary、nchar、bool 类型字段上;在超级表查询中使用时,不能应用在 tag 列
- 使用说明:
+**嵌套子查询支持**:适用于内层查询和外层查询。
- 只能与普通列,选择(Selection)、投影(Projection)函数一起使用,不能与聚合(Aggregation)函数一起使用。
+**使用说明**:
- 该函数可以应用在普通表和超级表上。
+- 只能与普通列,选择(Selection)、投影(Projection)函数一起使用,不能与聚合(Aggregation)函数一起使用。
+- 该函数可以应用在普通表和超级表上。
+- 版本2.6.0.x后支持
- 版本2.6.0.x后支持
+### POW
-- **SQRT**
- ```mysql
- SELECT SQRT(field_name) FROM { tb_name | stb_name } [WHERE clause]
- ```
- 功能说明:获得指定列的平方根
+ ```sql
+ SELECT POW(field_name, power) FROM { tb_name | stb_name } [WHERE clause]
+ ```
- 返回结果类型:DOUBLE。如果输入值为NULL,输出值也为NULL
+**功能说明**:获得指定列的指数为 power 的幂
- 适用数据类型:不能应用在 timestamp、binary、nchar、bool 类型字段上;在超级表查询中使用时,不能应用在 tag 列
+**返回结果类型**:DOUBLE。如果输入值为 NULL,输出值也为 NULL
- 嵌套子查询支持:适用于内层查询和外层查询。
+**适用数据类型**:不能应用在 timestamp、binary、nchar、bool 类型字段上;在超级表查询中使用时,不能应用在 tag 列
- 使用说明:
+**嵌套子查询支持**:适用于内层查询和外层查询。
- 只能与普通列,选择(Selection)、投影(Projection)函数一起使用,不能与聚合(Aggregation)函数一起使用。
+**使用说明**:
- 该函数可以应用在普通表和超级表上。
+- 只能与普通列,选择(Selection)、投影(Projection)函数一起使用,不能与聚合(Aggregation)函数一起使用。
+- 该函数可以应用在普通表和超级表上。
+- 版本2.6.0.x后支持
- 版本2.6.0.x后支持
+### LOG
-- **CAST**
- ```mysql
- SELECT CAST(expression AS type_name) FROM { tb_name | stb_name } [WHERE clause]
- ```
- 功能说明:数据类型转换函数,输入参数expression支持普通列、常量、标量函数及它们之间的四则运算,不支持tag列,只适用于select子句中。
+ ```sql
+ SELECT LOG(field_name, base) FROM { tb_name | stb_name } [WHERE clause]
+ ```
+
+**功能说明**:获得指定列对于底数 base 的对数
+
+**返回结果类型**:DOUBLE。如果输入值为 NULL,输出值也为 NULL
+
+**适用数据类型**:不能应用在 timestamp、binary、nchar、bool 类型字段上;在超级表查询中使用时,不能应用在 tag 列
+
+**嵌套子查询支持**:适用于内层查询和外层查询。
+
+**使用说明**:
- 返回结果类型:CAST中指定的类型(type_name)。
+- 只能与普通列,选择(Selection)、投影(Projection)函数一起使用,不能与聚合(Aggregation)函数一起使用。
+- 该函数可以应用在普通表和超级表上。
+- 版本2.6.0.x后支持
- 适用数据类型:输入参数expression的类型可以是除JSON外目前所有类型字段(BOOL/TINYINT/SMALLINT/INT/BIGINT/FLOAT/DOUBLE/BINARY(M)/TIMESTAMP/NCHAR(M)/TINYINT UNSIGNED/SMALLINT UNSIGNED/INT UNSIGNED/BIGINT UNSIGNED); 输出目标类型只支持BIGINT/BINARY(N)/TIMESTAMP/NCHAR(N)/BIGINT UNSIGNED。
+### ABS
- 说明:
+ ```sql
+ SELECT ABS(field_name) FROM { tb_name | stb_name } [WHERE clause]
+ ```
- 对于不能支持的类型转换会直接报错。
+**功能说明**:获得指定列的绝对值
- 如果输入值为NULL则输出值也为NULL。
+**返回结果类型**:如果输入值为整数,输出值是 UBIGINT 类型。如果输入值是 FLOAT/DOUBLE 数据类型,输出值是 DOUBLE 数据类型。
- 对于类型支持但某些值无法正确转换的情况对应的转换后的值以转换函数输出为准。目前可能遇到的几种情况:
+**适用数据类型**:不能应用在 timestamp、binary、nchar、bool 类型字段上;在超级表查询中使用时,不能应用在 tag 列
+
+**嵌套子查询支持**:适用于内层查询和外层查询。
+
+**使用说明**:
+
+- 只能与普通列,选择(Selection)、投影(Projection)函数一起使用,不能与聚合(Aggregation)函数一起使用。
+- 该函数可以应用在普通表和超级表上。
+- 版本2.6.0.x后支持
+
+### SQRT
+
+ ```sql
+ SELECT SQRT(field_name) FROM { tb_name | stb_name } [WHERE clause]
+ ```
+
+**功能说明**:获得指定列的平方根
+
+**返回结果类型**:DOUBLE。如果输入值为 NULL,输出值也为 NULL
+
+**适用数据类型**:不能应用在 timestamp、binary、nchar、bool 类型字段上;在超级表查询中使用时,不能应用在 tag 列
+
+**嵌套子查询支持**:适用于内层查询和外层查询。
+
+**使用说明**:
+
+- 只能与普通列,选择(Selection)、投影(Projection)函数一起使用,不能与聚合(Aggregation)函数一起使用。
+- 该函数可以应用在普通表和超级表上。
+- 版本2.6.0.x后支持
+
+### CAST
+
+ ```sql
+ SELECT CAST(expression AS type_name) FROM { tb_name | stb_name } [WHERE clause]
+ ```
+
+**功能说明**:数据类型转换函数,输入参数 expression 支持普通列、常量、标量函数及它们之间的四则运算,不支持 tag 列,只适用于 select 子句中。
+
+**返回结果类型**:CAST 中指定的类型(type_name)。
+
+**适用数据类型**:
+
+- 输入参数 expression 的类型可以是除 JSON 外目前所有类型字段(BOOL/TINYINT/SMALLINT/INT/BIGINT/FLOAT/DOUBLE/BINARY(M)/TIMESTAMP/NCHAR(M)/TINYINT UNSIGNED/SMALLINT UNSIGNED/INT UNSIGNED/BIGINT UNSIGNED);
+- 输出目标类型只支持 BIGINT/BINARY(N)/TIMESTAMP/NCHAR(N)/BIGINT UNSIGNED。
+
+**使用说明**:
+
+- 对于不能支持的类型转换会直接报错。
+- 如果输入值为NULL则输出值也为NULL。
+- 对于类型支持但某些值无法正确转换的情况对应的转换后的值以转换函数输出为准。目前可能遇到的几种情况:
1)BINARY/NCHAR转BIGINT/BIGINT UNSIGNED时可能出现的无效字符情况,例如"a"可能转为0。
2)有符号数或TIMESTAMP转BIGINT UNSIGNED可能遇到的溢出问题。
3)BIGINT UNSIGNED转BIGINT可能遇到的溢出问题。
4)FLOAT/DOUBLE转BIGINT/BIGINT UNSIGNED可能遇到的溢出问题。
- 版本2.6.0.x后支持
+- 版本2.6.0.x后支持
-- **CONCAT**
- ```mysql
- SELECT CONCAT(str1|column1, str2|column2, ...) FROM { tb_name | stb_name } [WHERE clause]
- ```
- 功能说明:字符串连接函数。
+### CONCAT
- 返回结果类型:同输入参数类型,BINARY或者NCHAR。
+ ```sql
+ SELECT CONCAT(str1|column1, str2|column2, ...) FROM { tb_name | stb_name } [WHERE clause]
+ ```
- 适用数据类型:输入参数或者全部是BINARY格式的字符串或者列,或者全部是NCHAR格式的字符串或者列。不能应用在TAG列。
+**功能说明**:字符串连接函数。
- 说明:
-
- 如果输入值为NULL,输出值为NULL。
- 该函数最小参数个数为2个,最大参数个数为8个。
- 该函数可以应用在普通表和超级表上。
- 该函数适用于内层查询和外层查询。
- 版本2.6.0.x后支持
-
-- **CONCAT_WS**
- ```
- SELECT CONCAT_WS(separator, str1|column1, str2|column2, ...) FROM { tb_name | stb_name } [WHERE clause]
- ```
- 功能说明:带分隔符的字符串连接函数。
+**返回结果类型**:同输入参数类型,BINARY 或者 NCHAR。
- 返回结果类型:同输入参数类型,BINARY或者NCHAR。
+**适用数据类型**:输入参数或者全部是 BINARY 格式的字符串或者列,或者全部是 NCHAR 格式的字符串或者列。不能应用在 TAG 列。
- 适用数据类型:输入参数或者全部是BINARY格式的字符串或者列,或者全部是NCHAR格式的字符串或者列。不能应用在TAG列。
+**使用说明**:
- 说明:
-
- 如果separator值为NULL,输出值为NULL。如果separator值不为NULL,其他输入为NULL,输出为空串
- 该函数最小参数个数为3个,最大参数个数为9个。
- 该函数可以应用在普通表和超级表上。
- 该函数适用于内层查询和外层查询。
- 版本2.6.0.x后支持
+- 如果输入值为NULL,输出值为NULL。
+- 该函数最小参数个数为2个,最大参数个数为8个。
+- 该函数可以应用在普通表和超级表上。
+- 该函数适用于内层查询和外层查询。
+- 版本2.6.0.x后支持
-- **LENGTH**
- ```
- SELECT LENGTH(str|column) FROM { tb_name | stb_name } [WHERE clause]
- ```
- 功能说明:以字节计数的字符串长度。
+### CONCAT_WS
- 返回结果类型:INT。
+ ```
+ SELECT CONCAT_WS(separator, str1|column1, str2|column2, ...) FROM { tb_name | stb_name } [WHERE clause]
+ ```
- 适用数据类型:输入参数是BINARY类型或者NCHAR类型的字符串或者列。不能应用在TAG列。
+**功能说明**:带分隔符的字符串连接函数。
- 说明:
+**返回结果类型**:同输入参数类型,BINARY 或者 NCHAR。
- 如果输入值为NULL,输出值为NULL。
- 该函数可以应用在普通表和超级表上。
- 该函数适用于内层查询和外层查询。
- 版本2.6.0.x后支持
+**适用数据类型**:输入参数或者全部是 BINARY 格式的字符串或者列,或者全部是 NCHAR 格式的字符串或者列。不能应用在 TAG 列。
-- **CHAR_LENGTH**
- ```
- SELECT CHAR_LENGTH(str|column) FROM { tb_name | stb_name } [WHERE clause]
- ```
- 功能说明:以字符计数的字符串长度。
+**使用说明**:
- 返回结果类型:INT。
+- 如果separator值为NULL,输出值为NULL。如果separator值不为NULL,其他输入为NULL,输出为空串
+- 该函数最小参数个数为3个,最大参数个数为9个。
+- 该函数可以应用在普通表和超级表上。
+- 该函数适用于内层查询和外层查询。
+- 版本2.6.0.x后支持
- 适用数据类型:输入参数是BINARY类型或者NCHAR类型的字符串或者列。不能应用在TAG列。
+### LENGTH
- 说明:
-
- 如果输入值为NULL,输出值为NULL。
- 该函数可以应用在普通表和超级表上。
- 该函数适用于内层查询和外层查询。
- 版本2.6.0.x后支持
+ ```
+ SELECT LENGTH(str|column) FROM { tb_name | stb_name } [WHERE clause]
+ ```
-- **LOWER**
- ```
- SELECT LOWER(str|column) FROM { tb_name | stb_name } [WHERE clause]
- ```
- 功能说明:将字符串参数值转换为全小写字母。
+**功能说明**:以字节计数的字符串长度。
- 返回结果类型:同输入类型。
+**返回结果类型**:INT。
- 适用数据类型:输入参数是BINARY类型或者NCHAR类型的字符串或者列。不能应用在TAG列。
+**适用数据类型**:输入参数是 BINARY 类型或者 NCHAR 类型的字符串或者列。不能应用在 TAG 列。
- 说明:
-
- 如果输入值为NULL,输出值为NULL。
- 该函数可以应用在普通表和超级表上。
- 该函数适用于内层查询和外层查询。
- 版本2.6.0.x后支持
+**使用说明**
-- **UPPER**
- ```
- SELECT UPPER(str|column) FROM { tb_name | stb_name } [WHERE clause]
- ```
- 功能说明:将字符串参数值转换为全大写字母。
+- 如果输入值为NULL,输出值为NULL。
+- 该函数可以应用在普通表和超级表上。
+- 函数适用于内层查询和外层查询。
+- 版本2.6.0.x后支持
- 返回结果类型:同输入类型。
+### CHAR_LENGTH
- 适用数据类型:输入参数是BINARY类型或者NCHAR类型的字符串或者列。不能应用在TAG列。
+ ```
+ SELECT CHAR_LENGTH(str|column) FROM { tb_name | stb_name } [WHERE clause]
+ ```
- 说明:
-
- 如果输入值为NULL,输出值为NULL。
- 该函数可以应用在普通表和超级表上。
- 该函数适用于内层查询和外层查询。
- 版本2.6.0.x后支持
+**功能说明**:以字符计数的字符串长度。
-- **LTRIM**
- ```
- SELECT LTRIM(str|column) FROM { tb_name | stb_name } [WHERE clause]
- ```
- 功能说明:返回清除左边空格后的字符串。
+**返回结果类型**:INT。
- 返回结果类型:同输入类型。
+**适用数据类型**:输入参数是 BINARY 类型或者 NCHAR 类型的字符串或者列。不能应用在 TAG 列。
- 适用数据类型:输入参数是BINARY类型或者NCHAR类型的字符串或者列。不能应用在TAG列。
+**使用说明**
- 说明:
-
- 如果输入值为NULL,输出值为NULL。
- 该函数可以应用在普通表和超级表上。
- 该函数适用于内层查询和外层查询。
- 版本2.6.0.x后支持
+- 如果输入值为NULL,输出值为NULL。
+- 该函数可以应用在普通表和超级表上。
+- 该函数适用于内层查询和外层查询。
+- 版本2.6.0.x后支持
-- **RTRIM**
- ```
- SELECT RTRIM(str|column) FROM { tb_name | stb_name } [WHERE clause]
- ```
- 功能说明:返回清除右边空格后的字符串。
+### LOWER
- 返回结果类型:同输入类型。
+ ```
+ SELECT LOWER(str|column) FROM { tb_name | stb_name } [WHERE clause]
+ ```
- 适用数据类型:输入参数是BINARY类型或者NCHAR类型的字符串或者列。不能应用在TAG列。
+**功能说明**:将字符串参数值转换为全小写字母。
- 说明:
-
- 如果输入值为NULL,输出值为NULL。
- 该函数可以应用在普通表和超级表上。
- 该函数适用于内层查询和外层查询。
- 版本2.6.0.x后支持
+**返回结果类型**:同输入类型。
-- **SUBSTR**
- ```
- SELECT SUBSTR(str,pos[,len]) FROM { tb_name | stb_name } [WHERE clause]
- ```
- 功能说明:从源字符串str中的指定位置pos开始取一个长度为len的子串并返回。
+**适用数据类型**:输入参数是 BINARY 类型或者 NCHAR 类型的字符串或者列。不能应用在 TAG 列。
+
+**使用说明**:
+
+- 如果输入值为NULL,输出值为NULL。
+- 该函数可以应用在普通表和超级表上。
+- 该函数适用于内层查询和外层查询。
+- 版本2.6.0.x后支持
+
+### UPPER
+
+ ```
+ SELECT UPPER(str|column) FROM { tb_name | stb_name } [WHERE clause]
+ ```
+
+**功能说明**:将字符串参数值转换为全大写字母。
+
+**返回结果类型**:同输入类型。
+
+**适用数据类型**:输入参数是 BINARY 类型或者 NCHAR 类型的字符串或者列。不能应用在 TAG 列。
+
+**使用说明**:
+
+- 如果输入值为NULL,输出值为NULL。
+- 该函数可以应用在普通表和超级表上。
+- 该函数适用于内层查询和外层查询。
+- 版本2.6.0.x后支持
+
+### LTRIM
+
+ ```
+ SELECT LTRIM(str|column) FROM { tb_name | stb_name } [WHERE clause]
+ ```
+
+**功能说明**:返回清除左边空格后的字符串。
- 返回结果类型:同输入类型。
+**返回结果类型**:同输入类型。
- 适用数据类型:输入参数是BINARY类型或者NCHAR类型的字符串或者列。不能应用在TAG列。
+**适用数据类型**:输入参数是 BINARY 类型或者 NCHAR 类型的字符串或者列。不能应用在 TAG 列。
- 说明:
-
- 如果输入值为NULL,输出值为NULL。
- 输入参数pos可以为正数,也可以为负数。如果pos是正数,表示从开始往后抽取子串。如果pos为负数,表示从结尾往前抽取字符串。如果输入参数len被忽略,返回的子串包含从pos开始的整个字串。
- 该函数可以应用在普通表和超级表上。
- 该函数适用于内层查询和外层查询。
- 版本2.6.0.x后支持
+**使用说明**:
+
+- 如果输入值为NULL,输出值为NULL。
+- 该函数可以应用在普通表和超级表上。
+- 该函数适用于内层查询和外层查询。
+- 版本2.6.0.x后支持
+
+### RTRIM
+
+ ```
+ SELECT RTRIM(str|column) FROM { tb_name | stb_name } [WHERE clause]
+ ```
+
+**功能说明**:返回清除右边空格后的字符串。
+
+**返回结果类型**:同输入类型。
+
+**适用数据类型**:输入参数是 BINARY 类型或者 NCHAR 类型的字符串或者列。不能应用在 TAG 列。
+
+**使用说明**:
+
+- 如果输入值为NULL,输出值为NULL。
+- 该函数可以应用在普通表和超级表上。
+- 该函数适用于内层查询和外层查询。
+- 版本2.6.0.x后支持
+
+### SUBSTR
+
+ ```
+ SELECT SUBSTR(str,pos[,len]) FROM { tb_name | stb_name } [WHERE clause]
+ ```
+
+**功能说明**:从源字符串 str 中的指定位置 pos 开始取一个长度为 len 的子串并返回。
+
+**返回结果类型**:同输入类型。
+
+**适用数据类型**:输入参数是 BINARY 类型或者 NCHAR 类型的字符串或者列。不能应用在 TAG 列。
+
+**使用说明**:
+
+- 如果输入值为NULL,输出值为NULL。
+- 输入参数pos可以为正数,也可以为负数。如果pos是正数,表示开始位置从字符串开头正数计算。如果pos为负数,表示开始位置从字符串结尾倒数计算。如果输入参数len被忽略,返回的子串包含从pos开始的整个字串。
+- 该函数可以应用在普通表和超级表上。
+- 该函数适用于内层查询和外层查询。
+- 版本2.6.0.x后支持
### 四则运算
@@ -1264,11 +1392,10 @@ SELECT field_name [+|-|*|/|%][Value|field_name] FROM { tb_name | stb_name } [WH
**适用于**:表、超级表。
-说明:
+**使用说明**:
-1)支持两列或多列之间进行计算,可使用括号控制计算优先级;
-
-2)NULL 字段不参与计算,如果参与计算的某行中包含 NULL,该行的计算结果为 NULL。
+- 支持两列或多列之间进行计算,可使用括号控制计算优先级;
+- NULL 字段不参与计算,如果参与计算的某行中包含 NULL,该行的计算结果为 NULL。
```
taos> SELECT current + voltage * phase FROM d1001;
@@ -1281,12 +1408,15 @@ Query OK, 3 row(s) in set (0.001046s)
```
### STATECOUNT
+
```
SELECT STATECOUNT(field_name, oper, val) FROM { tb_name | stb_name } [WHERE clause];
```
-**功能说明**:返回满足某个条件的连续记录的个数,结果作为新的一列追加在每行后面。条件根据参数计算,如果条件为true则加1,条件为false则重置为-1,如果数据为NULL,跳过该条数据。
+
+**功能说明**:返回满足某个条件的连续记录的个数,结果作为新的一列追加在每行后面。条件根据参数计算,如果条件为 true 则加 1,条件为 false 则重置为-1,如果数据为 NULL,跳过该条数据。
**参数范围**:
+
- oper : LT (小于)、GT(大于)、LE(小于等于)、GE(大于等于)、NE(不等于)、EQ(等于),不区分大小写。
- val : 数值型
@@ -1298,13 +1428,13 @@ SELECT STATECOUNT(field_name, oper, val) FROM { tb_name | stb_name } [WHERE clau
**支持的版本**:2.6 开始的版本。
-**说明**:
+**使用说明**:
- 该函数可以应用在普通表上,在由 GROUP BY 划分出单独时间线的情况下用于超级表(也即 GROUP BY tbname)
+- 不能和窗口操作一起使用,例如 interval/state_window/session_window。
-- 不能和窗口操作一起使用,例如interval/state_window/session_window。
+**示例**:
-示例:
```
taos> select ts,dbig from statef2;
ts | dbig |
@@ -1330,15 +1460,18 @@ Query OK, 6 row(s) in set (0.002791s)
```
### STATEDURATION
+
```
SELECT stateDuration(field_name, oper, val, unit) FROM { tb_name | stb_name } [WHERE clause];
```
-**功能说明**:返回满足某个条件的连续记录的时间长度,结果作为新的一列追加在每行后面。条件根据参数计算,如果条件为true则加上两个记录之间的时间长度(第一个满足条件的记录时间长度记为0),条件为false则重置为-1,如果数据为NULL,跳过该条数据。
+
+**功能说明**:返回满足某个条件的连续记录的时间长度,结果作为新的一列追加在每行后面。条件根据参数计算,如果条件为 true 则加上两个记录之间的时间长度(第一个满足条件的记录时间长度记为 0),条件为 false 则重置为-1,如果数据为 NULL,跳过该条数据。
**参数范围**:
+
- oper : LT (小于)、GT(大于)、LE(小于等于)、GE(大于等于)、NE(不等于)、EQ(等于),不区分大小写。
- val : 数值型
-- unit : 时间长度的单位,范围[1s、1m、1h ],不足一个单位舍去。默认为1s。
+- unit : 时间长度的单位,范围[1s、1m、1h ],不足一个单位舍去。默认为 1s。
**返回结果类型**:整形。
@@ -1348,13 +1481,13 @@ SELECT stateDuration(field_name, oper, val, unit) FROM { tb_name | stb_name } [W
**支持的版本**:2.6 开始的版本。
-**说明**:
+**使用说明**:
- 该函数可以应用在普通表上,在由 GROUP BY 划分出单独时间线的情况下用于超级表(也即 GROUP BY tbname)
+- 不能和窗口操作一起使用,例如 interval/state_window/session_window。
-- 不能和窗口操作一起使用,例如interval/state_window/session_window。
+**示例**:
-示例:
```
taos> select ts,dbig from statef2;
ts | dbig |
@@ -1379,12 +1512,13 @@ ts | dbig | stateduration(dbig,gt,2) |
Query OK, 6 row(s) in set (0.002613s)
```
-### 时间函数
+## 时间函数
-从 2.6.0.0 版本开始,TDengine查询引擎支持以下时间相关函数:
+从 2.6.0.0 版本开始,TDengine 查询引擎支持以下时间相关函数:
### NOW
-```mysql
+
+```sql
SELECT NOW() FROM { tb_name | stb_name } [WHERE clause];
SELECT select_expr FROM { tb_name | stb_name } WHERE ts_col cond_operatior NOW();
INSERT INTO tb_name VALUES (NOW(), ...);
@@ -1394,17 +1528,19 @@ INSERT INTO tb_name VALUES (NOW(), ...);
**返回结果数据类型**:TIMESTAMP 时间戳类型。
-**应用字段**:在 WHERE 或 INSERT 语句中使用时只能作用于TIMESTAMP类型的字段。
+**应用字段**:在 WHERE 或 INSERT 语句中使用时只能作用于 TIMESTAMP 类型的字段。
**适用于**:表、超级表。
-**说明**:
- 1)支持时间加减操作,如NOW() + 1s, 支持的时间单位如下:
- b(纳秒)、u(微秒)、a(毫秒)、s(秒)、m(分)、h(小时)、d(天)、w(周)。
- 2)返回的时间戳精度与当前 DATABASE 设置的时间精度一致。
+**使用说明**:
-示例:
-```mysql
+- 支持时间加减操作,如 NOW() + 1s, 支持的时间单位如下:
+ b(纳秒)、u(微秒)、a(毫秒)、s(秒)、m(分)、h(小时)、d(天)、w(周)。
+- 返回的时间戳精度与当前 DATABASE 设置的时间精度一致。
+
+**示例**:
+
+```sql
taos> SELECT NOW() FROM meters;
now() |
==========================
@@ -1427,12 +1563,14 @@ taos> INSERT INTO d1001 VALUES (NOW(), 10.2, 219, 0.32);
Query OK, 1 of 1 row(s) in database (0.002210s)
```
-## TODAY
-```mysql
+### TODAY
+
+```sql
SELECT TODAY() FROM { tb_name | stb_name } [WHERE clause];
SELECT select_expr FROM { tb_name | stb_name } WHERE ts_col cond_operatior TODAY()];
INSERT INTO tb_name VALUES (TODAY(), ...);
```
+
**功能说明**:返回客户端当日零时的系统时间。
**返回结果数据类型**:TIMESTAMP 时间戳类型。
@@ -1441,13 +1579,15 @@ INSERT INTO tb_name VALUES (TODAY(), ...);
**适用于**:表、超级表。
-**说明**:
- 1)支持时间加减操作,如TODAY() + 1s, 支持的时间单位如下:
- b(纳秒),u(微秒),a(毫秒),s(秒),m(分),h(小时),d(天),w(周)。
- 2)返回的时间戳精度与当前 DATABASE 设置的时间精度一致。
+**使用说明**:
+
+- 支持时间加减操作,如 TODAY() + 1s, 支持的时间单位如下:
+ b(纳秒),u(微秒),a(毫秒),s(秒),m(分),h(小时),d(天),w(周)。
+- 返回的时间戳精度与当前 DATABASE 设置的时间精度一致。
+
+**示例**:
-示例:
-```mysql
+```sql
taos> SELECT TODAY() FROM meters;
today() |
==========================
@@ -1470,10 +1610,12 @@ taos> INSERT INTO d1001 VALUES (TODAY(), 10.2, 219, 0.32);
Query OK, 1 of 1 row(s) in database (0.002210s)
```
-## TIMEZONE
-```mysql
+### TIMEZONE
+
+```sql
SELECT TIMEZONE() FROM { tb_name | stb_name } [WHERE clause];
```
+
**功能说明**:返回客户端当前时区信息。
**返回结果数据类型**:BINARY 类型。
@@ -1482,8 +1624,9 @@ SELECT TIMEZONE() FROM { tb_name | stb_name } [WHERE clause];
**适用于**:表、超级表。
-示例:
-```mysql
+**示例**:
+
+```sql
taos> SELECT TIMEZONE() FROM meters;
timezone() |
=================================
@@ -1491,10 +1634,12 @@ taos> SELECT TIMEZONE() FROM meters;
Query OK, 1 row(s) in set (0.002093s)
```
-## TO_ISO8601
-```mysql
+### TO_ISO8601
+
+```sql
SELECT TO_ISO8601(ts_val | ts_col) FROM { tb_name | stb_name } [WHERE clause];
```
+
**功能说明**:将 UNIX 时间戳转换成为 ISO8601 标准的日期时间格式,并附加客户端时区信息。
**返回结果数据类型**:BINARY 类型。
@@ -1503,10 +1648,14 @@ SELECT TO_ISO8601(ts_val | ts_col) FROM { tb_name | stb_name } [WHERE clause];
**适用于**:表、超级表。
-**说明**:如果输入是 UNIX 时间戳常量,返回格式精度由时间戳的位数决定,如果输入是 TIMSTAMP 类型的列,返回格式的时间戳精度与当前 DATABASE 设置的时间精度一致。
+**使用说明**:
+
+- 如果输入是 UNIX 时间戳常量,返回格式精度由时间戳的位数决定;
+- 如果输入是 TIMSTAMP 类型的列,返回格式的时间戳精度与当前 DATABASE 设置的时间精度一致。
-示例:
-```mysql
+**示例**:
+
+```sql
taos> SELECT TO_ISO8601(1643738400) FROM meters;
to_iso8601(1643738400) |
==============================
@@ -1520,24 +1669,28 @@ taos> SELECT TO_ISO8601(ts) FROM meters;
2022-02-02T02:00:00+0800 |
```
-## TO_UNIXTIMESTAMP
-```mysql
+### TO_UNIXTIMESTAMP
+
+```sql
SELECT TO_UNIXTIMESTAMP(datetime_string | ts_col) FROM { tb_name | stb_name } [WHERE clause];
```
+
**功能说明**:将日期时间格式的字符串转换成为 UNIX 时间戳。
-**返回结果数据类型**:长整型INT64。
+**返回结果数据类型**:长整型 INT64。
**应用字段**:字符串常量或是 BINARY/NCHAR 类型的列。
**适用于**:表、超级表。
-说明:
-1)输入的日期时间字符串须符合 ISO8601/RFC3339 标准,无法转换的字符串格式将返回0。
-2)返回的时间戳精度与当前 DATABASE 设置的时间精度一致。
+**使用说明**:
-示例:
-```mysql
+- 输入的日期时间字符串须符合 ISO8601/RFC3339 标准,无法转换的字符串格式将返回 0。
+- 返回的时间戳精度与当前 DATABASE 设置的时间精度一致。
+
+**示例**:
+
+```sql
taos> SELECT TO_UNIXTIMESTAMP("2022-02-02T02:00:00.000Z") FROM meters;
to_unixtimestamp("2022-02-02T02:00:00.000Z") |
==============================================
@@ -1551,10 +1704,12 @@ taos> SELECT TO_UNIXTIMESTAMP(col_binary) FROM meters;
1643767200000 |
```
-## TIMETRUNCATE
-```mysql
+### TIMETRUNCATE
+
+```sql
SELECT TIMETRUNCATE(ts_val | datetime_string | ts_col, time_unit) FROM { tb_name | stb_name } [WHERE clause];
```
+
**功能说明**:将时间戳按照指定时间单位 time_unit 进行截断。
**返回结果数据类型**:TIMESTAMP 时间戳类型。
@@ -1563,13 +1718,14 @@ SELECT TIMETRUNCATE(ts_val | datetime_string | ts_col, time_unit) FROM { tb_name
**适用于**:表、超级表。
-说明:
-1)支持的时间单位 time_unit 如下:
- 1u(微秒),1a(毫秒),1s(秒),1m(分),1h(小时),1d(天)。
-2)返回的时间戳精度与当前 DATABASE 设置的时间精度一致。
+**使用说明**:
+- 支持的时间单位 time_unit 如下:
+ 1u(微秒),1a(毫秒),1s(秒),1m(分),1h(小时),1d(天)。
+- 返回的时间戳精度与当前 DATABASE 设置的时间精度一致。
+
+**示例**:
-示例:
-```mysql
+```sql
taos> SELECT TIMETRUNCATE(1643738522000, 1h) FROM meters;
timetruncate(1643738522000, 1h) |
===================================
@@ -1591,25 +1747,28 @@ taos> SELECT TIMETRUNCATE(ts, 1h) FROM meters;
Query OK, 3 row(s) in set (0.003903s)
```
-## TIMEDIFF
-```mysql
+### TIMEDIFF
+
+```sql
SELECT TIMEDIFF(ts_val1 | datetime_string1 | ts_col1, ts_val2 | datetime_string2 | ts_col2 [, time_unit]) FROM { tb_name | stb_name } [WHERE clause];
```
+
**功能说明**:计算两个时间戳之间的差值,并近似到时间单位 time_unit 指定的精度。
-**返回结果数据类型**:长整型INT64。
+**返回结果数据类型**:长整型 INT64。
**应用字段**:UNIX 时间戳,日期时间格式的字符串,或者 TIMESTAMP 类型的列。
**适用于**:表、超级表。
-说明:
-1)支持的时间单位 time_unit 如下:
- 1u(微秒),1a(毫秒),1s(秒),1m(分),1h(小时),1d(天)。
-2)如果时间单位 time_unit 未指定, 返回的时间差值精度与当前 DATABASE 设置的时间精度一致。
+**使用说明**:
+- 支持的时间单位 time_unit 如下:
+ 1u(微秒),1a(毫秒),1s(秒),1m(分),1h(小时),1d(天)。
+- 如果时间单位 time_unit 未指定, 返回的时间差值精度与当前 DATABASE 设置的时间精度一致。
+
+**示例**:
-示例:
-```mysql
+```sql
taos> SELECT TIMEDIFF(1643738400000, 1643742000000) FROM meters;
timediff(1643738400000, 1643742000000) |
=========================================
diff --git a/docs-cn/14-reference/01-taos-sql/08-interval.md b/docs-cn/12-taos-sql/08-interval.md
similarity index 94%
rename from docs-cn/14-reference/01-taos-sql/08-interval.md
rename to docs-cn/12-taos-sql/08-interval.md
index 362ca1bef6ffa2b1e01d739907da5ebff726a500..d62e11b0dbd0ba49ceedb3807e05361f060969b3 100644
--- a/docs-cn/14-reference/01-taos-sql/08-interval.md
+++ b/docs-cn/12-taos-sql/08-interval.md
@@ -1,8 +1,8 @@
---
sidebar_label: 按窗口切分聚合
+title: 按窗口切分聚合
---
-# 按窗口切分聚合
TDengine 支持按时间段窗口切分方式进行聚合结果查询,比如温度传感器每秒采集一次数据,但需查询每隔 10 分钟的温度平均值。这种场景下可以使用窗口子句来获得需要的查询结果。
窗口子句用于针对查询的数据集合进行按照窗口切分成为查询子集并进行聚合,窗口包含时间窗口(time window)、状态窗口(status window)、会话窗口(session window)三种窗口。其中时间窗口又可划分为滑动时间窗口和翻转时间窗口。
@@ -16,13 +16,13 @@ INTERVAL 子句用于产生相等时间周期的窗口,SLIDING 用以指定窗
INTERVAL 和 SLIDING 子句需要配合聚合和选择函数来使用。以下 SQL 语句非法:
```
-SELECT * FROM temp_table INTERVAL(1S)
+SELECT * FROM temp_tb_1 INTERVAL(1m);
```
SLIDING 的向前滑动的时间不能超过一个窗口的时间范围。以下语句非法:
```
-SELECT COUNT(*) FROM temp_table INTERVAL(1D) SLIDING(2D)
+SELECT COUNT(*) FROM temp_tb_1 INTERVAL(1m) SLIDING(2m);
```
当 SLIDING 与 INTERVAL 取值相等的时候,滑动窗口即为翻转窗口。
@@ -38,7 +38,7 @@ _ 从 2.1.5.0 版本开始,INTERVAL 语句允许的最短时间间隔调整为
使用 STATE_WINDOW 来确定状态窗口划分的列。例如:
```
-SELECT COUNT(*), FIRST(ts), status FROM temp_tb_1 STATE_WINDOW(status)
+SELECT COUNT(*), FIRST(ts), status FROM temp_tb_1 STATE_WINDOW(status);
```
## 会话窗口
@@ -51,7 +51,7 @@ SELECT COUNT(*), FIRST(ts), status FROM temp_tb_1 STATE_WINDOW(status)
```
-SELECT COUNT(*), FIRST(ts) FROM temp_tb_1 SESSION(ts, tol_val)
+SELECT COUNT(*), FIRST(ts) FROM temp_tb_1 SESSION(ts, tol_val);
```
这种类型的查询语法如下:
@@ -72,7 +72,7 @@ SELECT function_list FROM stb_name
```
- 在聚合查询中,function_list 位置允许使用聚合和选择函数,并要求每个函数仅输出单个结果(例如:COUNT、AVG、SUM、STDDEV、LEASTSQUARES、PERCENTILE、MIN、MAX、FIRST、LAST),而不能使用具有多行输出结果的函数(例如:DIFF 以及四则运算)。
-- 此外也 LAST_ROW 查询也不能与窗口聚合同时出现。
+- 此外 LAST_ROW 查询也不能与窗口聚合同时出现。
- 标量函数(如:CEIL/FLOOR 等)也不能使用在窗口聚合查询中。
-
@@ -93,7 +93,7 @@ SELECT function_list FROM stb_name
:::
-时间聚合也常被用于连续查询场景,可以参考文档 [连续查询(Continuous Query)](https://www.taosdata.com/cn/documentation/advanced-features#continuous-query)。
+时间聚合也常被用于连续查询场景,可以参考文档 [连续查询(Continuous Query)](/develop/continuous-query)。
## 示例
diff --git a/docs-cn/14-reference/01-taos-sql/09-limit.md b/docs-cn/12-taos-sql/09-limit.md
similarity index 64%
rename from docs-cn/14-reference/01-taos-sql/09-limit.md
rename to docs-cn/12-taos-sql/09-limit.md
index c4e7c6b2f03f3a3f469d32f713bf15bba32f54bc..3c86a3862174377e6a00d046fb69627c773fe76e 100644
--- a/docs-cn/14-reference/01-taos-sql/09-limit.md
+++ b/docs-cn/12-taos-sql/09-limit.md
@@ -1,17 +1,17 @@
---
sidebar_label: 边界限制
+title: 边界限制
---
-# 边界限制
-
## 一般限制
- 数据库名最大长度为 32。
-- 表名最大长度为 192,每行数据最大长度 16k 个字符, 从 2.1.7.0 版本开始,每行数据最大长度 48k 个字符(注意:数据行内每个 BINARY/NCHAR 类型的列还会额外占用 2 个字节的存储位置)。
-- 列名最大长度为 64,最多允许 1024 列,最少需要 2 列,第一列必须是时间戳。(从 2.1.7.0 版本开始,改为最多允许 4096 列)
-- 标签名最大长度为 64,最多允许 128 个,可以 1 个,一个表中标签值的总长度不超过 16k 个字符。
+- 表名最大长度为 192,不包括数据库名前缀和分隔符
+- 每行数据最大长度 16k 个字符, 从 2.1.7.0 版本开始,每行数据最大长度 48k 个字符(注意:数据行内每个 BINARY/NCHAR 类型的列还会额外占用 2 个字节的存储位置)。
+- 列名最大长度为 64,最多允许 4096 列,最少需要 2 列,第一列必须是时间戳。注:从 2.1.7.0 版本(不含)以前最多允许 4096 列
+- 标签名最大长度为 64,最多允许 128 个,至少要有 1 个标签,一个表中标签值的总长度不超过 16k 个字符。
- SQL 语句最大长度 1048576 个字符,也可通过客户端配置参数 maxSQLLength 修改,取值范围 65480 ~ 1048576。
-- SELECT 语句的查询结果,最多允许返回 1024 列(语句中的函数调用可能也会占用一些列空间),超限时需要显式指定较少的返回数据列,以避免语句执行报错。(从 2.1.7.0 版本开始,改为最多允许 4096 列)
+- SELECT 语句的查询结果,最多允许返回 4096 列(语句中的函数调用可能也会占用一些列空间),超限时需要显式指定较少的返回数据列,以避免语句执行报错。注: 2.1.7.0 版本(不含)之前为最多允许 1024 列
- 库的数目,超级表的数目、表的数目,系统不做限制,仅受系统资源限制。
## GROUP BY 的限制
@@ -35,17 +35,20 @@ IS NOT NULL 支持所有类型的列。不为空的表达式为 <\>"",仅对
## 表(列)名合法性说明
-TDengine 中的表(列)名命名规则如下:
+### TDengine 中的表(列)名命名规则如下:
只能由字母、数字、下划线构成,数字不能在首位,长度不能超过 192 字节,不区分大小写。这里表名称不包括数据库名的前缀和分隔符。
-转移后表(列)名规则:
-为了兼容支持更多形式的表(列)名,TDengine 引入新的转义符 "`"。可用让表名与关键词不冲突,同时不受限于上述表名称合法性约束检查,转义符不计入表名称的长度。
+### 转义后表(列)名规则:
+为了兼容支持更多形式的表(列)名,TDengine 引入新的转义符 "`",可以避免表名与关键词的冲突,同时不受限于上述表名合法性约束检查,转义符不计入表名的长度。
转义后的表(列)名同样受到长度限制要求,且长度计算的时候不计算转义符。使用转义字符以后,不再对转义字符中的内容进行大小写统一。
例如:
\`aBc\` 和 \`abc\` 是不同的表(列)名,但是 abc 和 aBc 是相同的表(列)名。
-需要注意的是转义字符中的内容必须是可打印字符。
+:::note
+转义字符中的内容必须是可打印字符。
+
+:::
-支持版本
+### 支持版本
支持转义符的功能从 2.3.0.1 版本开始。
\ No newline at end of file
diff --git a/docs-cn/14-reference/01-taos-sql/10-json.md b/docs-cn/12-taos-sql/10-json.md
similarity index 98%
rename from docs-cn/14-reference/01-taos-sql/10-json.md
rename to docs-cn/12-taos-sql/10-json.md
index 6a06bd30ea9eec9eb8e1471d60f74416f6e45e96..4a4a8cca732ac433ba5ada1ec3805ebfa663edb3 100644
--- a/docs-cn/14-reference/01-taos-sql/10-json.md
+++ b/docs-cn/12-taos-sql/10-json.md
@@ -1,8 +1,8 @@
---
sidebar_label: JSON 类型使用说明
+title: JSON 类型使用说明
---
-# JSON 类型使用说明
## 语法说明
diff --git a/docs-cn/14-reference/01-taos-sql/11-escape.md b/docs-cn/12-taos-sql/11-escape.md
similarity index 73%
rename from docs-cn/14-reference/01-taos-sql/11-escape.md
rename to docs-cn/12-taos-sql/11-escape.md
index be27dd4e7b6dd59264d8740f47d4baaf4182a678..756e5c81591e7414827fdc65e228cfafc96214ad 100644
--- a/docs-cn/14-reference/01-taos-sql/11-escape.md
+++ b/docs-cn/12-taos-sql/11-escape.md
@@ -1,4 +1,6 @@
-# 转义字符说明
+---
+title: 转义字符说明
+---
## 转义字符表
@@ -25,4 +27,4 @@
2. 反引号``标识符: 保持原样,不转义
2. 数据里有转义字符
1. 遇到上面定义的转义字符会转义(%和\_见下面说明),如果没有匹配的转义字符会忽略掉转义符\。
- 2. 对于%和*,因为在 like 里这两个字符是通配符,所以在模式匹配 like 里用`\%`%和`\_`表示字符里本身的%和*,如果在 like 模式匹配上下文之外使用`\%`或`\_`,则它们的计算结果为字符串`\%`和`\_`,而不是%和\_。
+ 2. 对于%和\_,因为在 like 里这两个字符是通配符,所以在模式匹配 like 里用`\%`%和`\_`表示字符里本身的%和\_,如果在 like 模式匹配上下文之外使用`\%`或`\_`,则它们的计算结果为字符串`\%`和`\_`,而不是%和\_。
diff --git a/docs-cn/14-reference/06-keywords/_category_.yml b/docs-cn/12-taos-sql/12-keywords/_category_.yml
similarity index 100%
rename from docs-cn/14-reference/06-keywords/_category_.yml
rename to docs-cn/12-taos-sql/12-keywords/_category_.yml
diff --git a/docs-cn/14-reference/06-keywords/06-keywords.md b/docs-cn/12-taos-sql/12-keywords/index.md
similarity index 99%
rename from docs-cn/14-reference/06-keywords/06-keywords.md
rename to docs-cn/12-taos-sql/12-keywords/index.md
index e43d09e8123b46b51c04c2359d1f43e17d569c4c..608d4e080967cfd97072706cf0963ae669960be6 100644
--- a/docs-cn/14-reference/06-keywords/06-keywords.md
+++ b/docs-cn/12-taos-sql/12-keywords/index.md
@@ -1,7 +1,7 @@
---
sidebar_label: 参数限制与保留关键字
+title: TDengine 参数限制与保留关键字
---
-# TDengine 参数限制与保留关键字
## 名称命名规则
diff --git a/docs-cn/14-reference/01-taos-sql/_category_.yml b/docs-cn/12-taos-sql/_category_.yml
similarity index 100%
rename from docs-cn/14-reference/01-taos-sql/_category_.yml
rename to docs-cn/12-taos-sql/_category_.yml
diff --git a/docs-cn/14-reference/01-taos-sql/01-taos-sql.md b/docs-cn/12-taos-sql/index.md
similarity index 84%
rename from docs-cn/14-reference/01-taos-sql/01-taos-sql.md
rename to docs-cn/12-taos-sql/index.md
index 2c8d11288e55fd007b62b0a5fecc7dc7f2dc2737..bc5c2efd67b5dca554ba7e7a0012477af2e373ab 100644
--- a/docs-cn/14-reference/01-taos-sql/01-taos-sql.md
+++ b/docs-cn/12-taos-sql/index.md
@@ -1,8 +1,10 @@
-# TAOS SQL
+---
+title: TAOS SQL
+---
本文档说明 TAOS SQL 支持的语法规则、主要查询功能、支持的 SQL 查询函数,以及常用技巧等内容。阅读本文档需要读者具有基本的 SQL 语言的基础。
-TAOS SQL 是用户对 TDengine 进行数据写入和查询的主要工具。TAOS SQL 为了便于用户快速上手,在一定程度上提供类似于标准 SQL 类似的风格和模式。严格意义上,TAOS SQL 并不是也不试图提供 SQL 标准的语法。此外,由于 TDengine 针对的时序性结构化数据不提供删除功能,因此在 TAO SQL 中不提供数据删除的相关功能。
+TAOS SQL 是用户对 TDengine 进行数据写入和查询的主要工具。TAOS SQL 为了便于用户快速上手,在一定程度上提供与标准 SQL 类似的风格和模式。严格意义上,TAOS SQL 并不是也不试图提供标准的 SQL 语法。此外,由于 TDengine 针对的时序性结构化数据不提供删除功能,因此在 TAO SQL 中不提供数据删除的相关功能。
TAOS SQL 不支持关键字的缩写,例如 DESCRIBE 不能缩写为 DESC。
diff --git a/docs-cn/11-operation/01-pkg-install.md b/docs-cn/13-operation/01-pkg-install.md
similarity index 71%
rename from docs-cn/11-operation/01-pkg-install.md
rename to docs-cn/13-operation/01-pkg-install.md
index 257e9bb351bd18071dad7a7f149937c74e45c0ed..92b04a42ec9b3a80187d4482f465190288038f8d 100644
--- a/docs-cn/11-operation/01-pkg-install.md
+++ b/docs-cn/13-operation/01-pkg-install.md
@@ -1,13 +1,20 @@
-# 安装、卸载、启动和停止
+---
+title: 安装和卸载
+description: 安装、卸载、启动、停止和升级
+---
-TDengine 开源版本提供 deb 和 rpm 格式安装包,用户可以根据自己的运行环境选择合适的安装包。其中 deb 支持 Debian/Ubuntu 等系统,rpm 支持 CentOS/RHEL/SUSE 等系统。同时我们也为企业用户提供 tar.gz 格式安装包。
+import Tabs from "@theme/Tabs";
+import TabItem from "@theme/TabItem";
-## deb 包的安装和卸载
+TDengine 开源版本提供 deb 和 rpm 格式安装包,用户可以根据自己的运行环境选择合适的安装包。其中 deb 支持 Debian/Ubuntu 及衍生系统,rpm 支持 CentOS/RHEL/SUSE 及衍生系统。同时我们也为企业用户提供 tar.gz 格式安装包。
-### 安装 deb
+## 安装
-1、从官网下载获得 deb 安装包,比如 TDengine-server-2.0.0.0-Linux-x64.deb;
-2、进入到 TDengine-server-2.0.0.0-Linux-x64.deb 安装包所在目录,执行如下的安装命令:
+
+
+
+1、从官网下载获得 deb 安装包,例如 TDengine-server-2.4.0.7-Linux-x64.deb;
+2、进入到 TDengine-server-2.4.0.7-Linux-x64.deb 安装包所在目录,执行如下的安装命令:
```
$ sudo dpkg -i TDengine-server-2.4.0.7-Linux-x64.deb
@@ -18,7 +25,7 @@ Unpacking tdengine (2.4.0.7) over (2.4.0.7) ...
Setting up tdengine (2.4.0.7) ...
Start to install TDengine...
-System hostname is: shuduo-1804
+System hostname is: ubuntu-1804
Enter FQDN:port (like h1.taosdata.com:6030) of an existing TDengine cluster node to join
OR leave it blank to build one:
@@ -28,33 +35,18 @@ Created symlink /etc/systemd/system/multi-user.target.wants/taosd.service → /e
To configure TDengine : edit /etc/taos/taos.cfg
To start TDengine : sudo systemctl start taosd
-To access TDengine : taos -h shuduo-1804 to login into TDengine server
+To access TDengine : taos -h ubuntu-1804 to login into TDengine server
TDengine is installed successfully!
```
-注:当安装第一个节点时,出现 Enter FQDN:提示的时候,不需要输入任何内容。只有当安装第二个或以后更多的节点时,才需要输入已有集群中任何一个可用节点的 FQDN,支持该新节点加入集群。当然也可以不输入,而是在新节点启动前,配置到新节点的配置文件中。
-
-后续两种安装包也是同样的操作。
+
-### 卸载 deb
+
-卸载命令如下:
-
-```
-$ sudo dpkg -r tdengine
-(Reading database ... 137504 files and directories currently installed.)
-Removing tdengine (2.4.0.7) ...
-TDengine is removed successfully!
-```
-
-## rpm 包的安装和卸载
-
-### 安装 rpm
-
-1、从官网下载获得 rpm 安装包,比如 TDengine-server-2.0.0.0-Linux-x64.rpm;
-2、进入到 TDengine-server-2.0.0.0-Linux-x64.rpm 安装包所在目录,执行如下的安装命令:
+1、从官网下载获得 rpm 安装包,例如 TDengine-server-2.4.0.7-Linux-x64.rpm;
+2、进入到 TDengine-server-2.4.0.7-Linux-x64.rpm 安装包所在目录,执行如下的安装命令:
```
$ sudo rpm -ivh TDengine-server-2.4.0.7-Linux-x64.rpm
@@ -80,20 +72,11 @@ To access TDengine : taos -h centos7 to login into TDengine server
TDengine is installed successfully!
```
-### 卸载 rpm
-
-卸载命令如下:
-
-```
-$ sudo rpm -e tdengine
-TDengine is removed successfully!
-```
-
-## tar.gz 格式安装包的安装和卸载
+
-### 安装 tar.gz 安装包
+
-1、从官网下载获得 tar.gz 安装包,比如 TDengine-server-2.4.0.7-Linux-x64.tar.gz;
+1、从官网下载获得 tar.gz 安装包,例如 TDengine-server-2.4.0.7-Linux-x64.tar.gz;
2、进入到 TDengine-server-2.4.0.7-Linux-x64.tar.gz 安装包所在目录,先解压文件后,进入子目录,执行其中的 install.sh 安装脚本:
```
@@ -133,16 +116,55 @@ Nginx for TDengine is updated successfully!
To configure TDengine : edit /etc/taos/taos.cfg
To configure Taos Adapter (if has) : edit /etc/taos/taosadapter.toml
To start TDengine : sudo systemctl start taosd
-To access TDengine : use taos -h shuduo-1804 in shell OR from http://127.0.0.1:6060
+To access TDengine : use taos -h ubuntu-1804 in shell OR from http://127.0.0.1:6060
TDengine is updated successfully!
Install taoskeeper as a standalone service
taoskeeper is installed, enable it by `systemctl enable taoskeeper`
```
-说明:install.sh 安装脚本在执行过程中,会通过命令行交互界面询问一些配置信息。如果希望采取无交互安装方式,那么可以用 -e no 参数来执行 install.sh 脚本。运行 `./install.sh -h` 指令可以查看所有参数的详细说明信息。
+:::info
+install.sh 安装脚本在执行过程中,会通过命令行交互界面询问一些配置信息。如果希望采取无交互安装方式,那么可以用 -e no 参数来执行 install.sh 脚本。运行 `./install.sh -h` 指令可以查看所有参数的详细说明信息。
-### tar.gz 安装后的卸载
+:::
+
+
+
+
+:::note
+当安装第一个节点时,出现 Enter FQDN:提示的时候,不需要输入任何内容。只有当安装第二个或以后更多的节点时,才需要输入已有集群中任何一个可用节点的 FQDN,支持该新节点加入集群。当然也可以不输入,而是在新节点启动前,配置到新节点的配置文件中。
+
+:::
+
+## 卸载
+
+
+
+
+卸载命令如下:
+
+```
+$ sudo dpkg -r tdengine
+(Reading database ... 137504 files and directories currently installed.)
+Removing tdengine (2.4.0.7) ...
+TDengine is removed successfully!
+
+```
+
+
+
+
+
+卸载命令如下:
+
+```
+$ sudo rpm -e tdengine
+TDengine is removed successfully!
+```
+
+
+
+
卸载命令如下:
@@ -154,6 +176,30 @@ TDengine is removed successfully!
taosKeeper is removed successfully!
```
+
+
+
+:::info
+- TDengine 提供了多种安装包,但最好不要在一个系统上同时使用 tar.gz 安装包和 deb 或 rpm 安装包。否则会相互影响,导致在使用时出现问题。
+
+- 对于 deb 包安装后,如果安装目录被手工误删了部分,出现卸载、或重新安装不能成功。此时,需要清除 TDengine 包的安装信息,执行如下命令:
+
+ ```
+ $ sudo rm -f /var/lib/dpkg/info/tdengine*
+ ```
+
+然后再重新进行安装就可以了。
+
+- 对于 rpm 包安装后,如果安装目录被手工误删了部分,出现卸载、或重新安装不能成功。此时,需要清除 TDengine 包的安装信息,执行如下命令:
+
+ ```
+ $ sudo rpm -e --noscripts tdengine
+ ```
+
+然后再重新进行安装就可以了。
+
+:::
+
## 安装目录说明
TDengine 成功安装后,主安装目录是 /usr/local/taos,目录内容如下:
@@ -188,7 +234,7 @@ lrwxrwxrwx 1 root root 13 Feb 22 09:34 log -> /var/log/taos/
如果是更新安装,当缺省配置文件( /etc/taos/taos.cfg )存在时,仍然使用已有的配置文件,安装包中携带的配置文件修改为 taos.cfg.orig 保存在 /usr/local/taos/cfg/ 目录,可以作为设置配置参数的参考样例;如果不存在配置文件,就使用安装包中自带的配置文件。
-## TDengine 的启动、停止、卸载
+## 启动和停止
TDengine 使用 Linux 系统的 systemd/systemctl/service 来管理系统的启动和、停止、重启操作。TDengine 的服务进程是 taosd,默认情况下 TDengine 在系统启动后将自动启动。DBA 可以通过 systemd/systemctl/service 手动操作停止、启动、重新启动服务。
@@ -206,40 +252,32 @@ TDengine 使用 Linux 系统的 systemd/systemctl/service 来管理系统的启
如果服务进程处于活动状态,则 status 指令会显示如下的相关信息:
-```
-......
-
-Active: active (running)
-
-......
-```
+ ```
+ Active: active (running)
+ ```
如果后台服务进程处于停止状态,则 status 指令会显示如下的相关信息:
-```
-......
-
-Active: inactive (dead)
-
-......
-```
-
-## 注意事项
-
-- TDengine 提供了多种安装包,但最好不要在一个系统上同时使用 tar.gz 安装包和 deb 或 rpm 安装包。否则会相互影响,导致在使用时出现问题。
-
-- 对于 deb 包安装后,如果安装目录被手工误删了部分,出现卸载、或重新安装不能成功。此时,需要清除 TDengine 包的安装信息,执行如下命令:
+ ```
+ Active: inactive (dead)
+ ```
-```
-$ sudo rm -f /var/lib/dpkg/info/tdengine*
-```
+## 升级
+升级分为两个层面:升级安装包 和 升级运行中的实例。
-然后再重新进行安装就可以了。
+升级安装包请遵循前述安装和卸载的步骤先卸载旧版本再安装新版本。
-- 对于 rpm 包安装后,如果安装目录被手工误删了部分,出现卸载、或重新安装不能成功。此时,需要清除 TDengine 包的安装信息,执行如下命令:
+升级运行中的实例则要复杂得多,首先请注意版本号,TDengine 的版本号目前分为四段,如 2.4.0.14 和 2.4.0.16,只有前三段版本号一致(即只有第四段版本号不同)才能把一个运行中的实例进行升级。升级步骤如下:
+- 停止数据写入
+- 确保所有数据落盘,即写入时序数据库
+- 停止 TDengine 集群
+- 卸载旧版本并安装新版本
+- 重新启动 TDengine 集群
+- 进行简单的查询操作确认旧数据没有丢失
+- 进行简单的写入操作确认 TDengine 集群可用
+- 重新恢复业务数据的写入
-```
-$ sudo rpm -e --noscripts tdengine
-```
+:::warning
+TDengine 不保证低版本能够兼容高版本的数据,所以任何时候都不推荐降级
-然后再重新进行安装就可以了。
+:::
\ No newline at end of file
diff --git a/docs-cn/11-operation/02-planning.mdx b/docs-cn/13-operation/02-planning.mdx
similarity index 90%
rename from docs-cn/11-operation/02-planning.mdx
rename to docs-cn/13-operation/02-planning.mdx
index 1e62c54ff04f4204be996cf2c92b51f6fdf59d91..954ba7ca00ebdcb10cfcad515292d96127106ff3 100644
--- a/docs-cn/11-operation/02-planning.mdx
+++ b/docs-cn/13-operation/02-planning.mdx
@@ -1,9 +1,8 @@
---
sidebar_label: 容量规划
+title: 容量规划
---
-# 容量规划
-
使用 TDengine 来搭建一个物联网大数据平台,计算资源、存储资源需要根据业务场景进行规划。下面分别讨论系统运行所需要的内存、CPU 以及硬盘空间。
## 内存需求
@@ -11,10 +10,10 @@ sidebar_label: 容量规划
每个 Database 可以创建固定数目的 vgroup,默认与 CPU 核数相同,可通过 maxVgroupsPerDb 配置;vgroup 中的每个副本会是一个 vnode;每个 vnode 会占用固定大小的内存(大小与数据库的配置参数 blocks 和 cache 有关);每个 Table 会占用与标签总长度有关的内存;此外,系统会有一些固定的内存开销。因此,每个 DB 需要的系统内存可通过如下公式计算:
```
-Database Memory Size = maxVgroupsPerDb * (blocks * cache + 10MB) + numOfTables * (tagSizePerTable + 0.5KB)
+Database Memory Size = maxVgroupsPerDb * replica * (blocks * cache + 10MB) + numOfTables * (tagSizePerTable + 0.5KB)
```
-示例:假设是 4 核机器,cache 是缺省大小 16M, blocks 是缺省值 6,并且一个 DB 中有 10 万张表,标签总长度是 256 字节,则这个 DB 总的内存需求为:4 \* (16 \* 6 + 10) + 100000 \* (0.25 + 0.5) / 1000 = 499M。
+示例:假设 maxVgroupPerDB 是缺省值 64,cache 是缺省大小 16M, blocks 是缺省值 6,并且一个 DB 中有 10 万张表,单副本,标签总长度是 256 字节,则这个 DB 总的内存需求为:64 \* 1 \* (16 \* 6 + 10) + 100000 \* (0.25 + 0.5) / 1000 = 6792M。
在实际的系统运维中,我们通常会更关心 TDengine 服务进程(taosd)会占用的内存量。
@@ -30,7 +29,7 @@ taosd 内存总量 = vnode 内存 + mnode 内存 + 查询内存
注意:以上内存估算方法,主要讲解了系统的“必须内存需求”,而不是“内存总数上限”。在实际运行的生产环境中,由于操作系统缓存、资源管理调度等方面的原因,内存规划应当在估算结果的基础上保留一定冗余,以维持系统状态和系统性能的稳定性。并且,生产环境通常会配置系统资源的监控工具,以便及时发现硬件资源的紧缺情况。
-最后,如果内存充裕,可以考虑加大 Blocks 的配置,这样更多数据将保存在内存里,提高查询速度。
+最后,如果内存充裕,可以考虑加大 Blocks 的配置,这样更多数据将保存在内存里,提高写入和查询速度。
### 客户端内存需求
@@ -79,4 +78,4 @@ Raw DataSize = numOfTables * rowSizePerTable * rowsPerTable
因为 TDengine 具有很好的水平扩展能力,根据总量,再根据单个物理机或虚拟机的资源,就可以轻松决定需要购置多少台物理机或虚拟机了。
-**立即计算 CPU、内存、存储,请参见:[资源估算方法](https://www.taosdata.com/config/config.html)。**
\ No newline at end of file
+**立即计算 CPU、内存、存储,请参见:[资源估算方法](https://www.taosdata.com/config/config.html)。**
diff --git a/docs-cn/11-operation/03-tolerance.md b/docs-cn/13-operation/03-tolerance.md
similarity index 98%
rename from docs-cn/11-operation/03-tolerance.md
rename to docs-cn/13-operation/03-tolerance.md
index bd293f1609d1fd7bfd5ef22171ed13ff0e822a25..054e5c4cee07f7066038a6bfc5c4b25306b033ce 100644
--- a/docs-cn/11-operation/03-tolerance.md
+++ b/docs-cn/13-operation/03-tolerance.md
@@ -1,4 +1,6 @@
-# 容错和灾备
+---
+title: 容错和灾备
+---
## 容错
diff --git a/docs-cn/11-operation/06-admin.md b/docs-cn/13-operation/06-admin.md
similarity index 96%
rename from docs-cn/11-operation/06-admin.md
rename to docs-cn/13-operation/06-admin.md
index 9829cc2db0dea629af0d7accc705123da06d5545..7934d31eafb774fb45e1902bee29e8b518d152d6 100644
--- a/docs-cn/11-operation/06-admin.md
+++ b/docs-cn/13-operation/06-admin.md
@@ -1,4 +1,6 @@
-# 用户管理
+---
+title: 用户管理
+---
系统管理员可以在 CLI 界面里添加、删除用户,也可以修改密码。CLI 里 SQL 语法如下:
@@ -28,7 +30,7 @@ ALTER USER PRIVILEGE ;
说明:系统内共有 super/write/read 三种权限级别,但目前不允许通过 alter 指令把 super 权限赋予用户。
-```mysql
+```sql
SHOW USERS;
```
diff --git a/docs-cn/11-operation/07-import.md b/docs-cn/13-operation/07-import.md
similarity index 95%
rename from docs-cn/11-operation/07-import.md
rename to docs-cn/13-operation/07-import.md
index 0d7517c4389badbe72bf226c8365ccf8995f69a3..7dee05720d4c3446181e8e0d81a5c27e35300ba8 100644
--- a/docs-cn/11-operation/07-import.md
+++ b/docs-cn/13-operation/07-import.md
@@ -1,4 +1,6 @@
-# 数据导入
+---
+title: 数据导入
+---
TDengine 提供多种方便的数据导入功能,一种按脚本文件导入,一种按数据文件导入,一种是 taosdump 工具导入本身导出的文件。
@@ -10,7 +12,7 @@ TDengine 的 shell 支持 source filename 命令,用于批量运行文件中
TDengine 也支持在 shell 对已存在的表从 CSV 文件中进行数据导入。CSV 文件只属于一张表且 CSV 文件中的数据格式需与要导入表的结构相同,在导入的时候,其语法如下:
-```mysql
+```sql
insert into tb1 file 'path/data.csv';
```
@@ -21,7 +23,7 @@ insert into tb1 file 'path/data.csv';
例如,现在存在一个子表 d1001, 其表结构如下:
-```mysql
+```sql
taos> DESCRIBE d1001
Field | Type | Length | Note |
=================================================================================
@@ -49,11 +51,11 @@ taos> DESCRIBE d1001
那么可以用如下命令导入数据:
-```mysql
+```sql
taos> insert into d1001 file '~/data.csv';
Query OK, 9 row(s) affected (0.004763s)
```
## taosdump 工具导入
-TDengine 提供了方便的数据库导入导出工具 taosdump。用户可以将 taosdump 从一个系统导出的数据,导入到其他系统中。具体使用方法,请参见:[TDengine 数据备份工具: taosdump](https://www.taosdata.com/docs/cn/v2.0/tools/taosdump)。
+TDengine 提供了方便的数据库导入导出工具 taosdump。用户可以将 taosdump 从一个系统导出的数据,导入到其他系统中。具体使用方法,请参见:[TDengine 数据备份工具: taosdump](/reference/taosdump)。
diff --git a/docs-cn/11-operation/08-export.md b/docs-cn/13-operation/08-export.md
similarity index 71%
rename from docs-cn/11-operation/08-export.md
rename to docs-cn/13-operation/08-export.md
index a2ac4f4c45003d35ca33d2531734072268ff2365..042ecc7ba29f976d50bbca1e3155bd03b2ae7ccc 100644
--- a/docs-cn/11-operation/08-export.md
+++ b/docs-cn/13-operation/08-export.md
@@ -1,4 +1,6 @@
-# 数据导出
+---
+title: 数据导出
+---
为方便数据导出,TDengine 提供了两种导出方式,分别是按表导出和用 taosdump 导出。
@@ -6,7 +8,7 @@
如果用户需要导出一个表或一个 STable 中的数据,可在 taos shell 中运行:
-```mysql
+```sql
select * from >> data.csv;
```
@@ -14,6 +16,5 @@ select * from >> data.csv;
## 用 taosdump 导出数据
-利用 taosdump,用户可以根据需要选择导出所有数据库、一个数据库或者数据库中的一张表,所有数据或一时间段的数据,甚至仅仅表的定义。
-
-具体使用方法,请参见博客:[TDengine DUMP 工具使用指南](https://www.taosdata.com/blog/2020/03/09/1334.html)。
\ No newline at end of file
+利用 taosdump,用户可以根据需要选择导出所有数据库、一个数据库或者数据库中的一张表,所有数据或一时间段的数据,甚至仅仅表的定义。具体使用方法,请参见:
+[TDengine 数据备份工具: taosdump](/reference/taosdump)。
diff --git a/docs-cn/13-operation/09-status.md b/docs-cn/13-operation/09-status.md
new file mode 100644
index 0000000000000000000000000000000000000000..e7ae78bace91f6dab06591340965ba04efdd5edb
--- /dev/null
+++ b/docs-cn/13-operation/09-status.md
@@ -0,0 +1,53 @@
+---
+title: 系统连接、任务查询管理
+---
+
+系统管理员可以从 CLI 查询系统的连接、正在进行的查询、流式计算,并且可以关闭连接、停止正在进行的查询和流式计算。
+
+## 显示数据库的连接
+
+```sql
+SHOW CONNECTIONS;
+```
+
+其结果中的一列显示 ip:port, 为连接的 IP 地址和端口号。
+
+## 强制关闭数据库连接
+
+```sql
+KILL CONNECTION ;
+```
+
+其中的 connection-id 是 SHOW CONNECTIONS 中显示的第一列的数字。
+
+## 显示数据查询
+
+```sql
+SHOW QUERIES;
+```
+
+其中第一列显示的以冒号隔开的两个数字为 query-id,为发起该 query 应用连接的 connection-id 和查询次数。
+
+## 强制关闭数据查询
+
+```sql
+KILL QUERY ;
+```
+
+其中 query-id 是 SHOW QUERIES 中显示的 connection-id:query-no 字串,如“105:2”,拷贝粘贴即可。
+
+## 显示连续查询
+
+```sql
+SHOW STREAMS;
+```
+
+其中第一列显示的以冒号隔开的两个数字为 stream-id, 为启动该 stream 应用连接的 connection-id 和发起 stream 的次数。
+
+## 强制关闭连续查询
+
+```sql
+KILL STREAM ;
+```
+
+其中的 stream-id 是 SHOW STREAMS 中显示的 connection-id:stream-no 字串,如 103:2,拷贝粘贴即可。
diff --git a/docs-cn/11-operation/10-monitor.md b/docs-cn/13-operation/10-monitor.md
similarity index 94%
rename from docs-cn/11-operation/10-monitor.md
rename to docs-cn/13-operation/10-monitor.md
index 367d1dd54ef5d53b43542600c55b8337e721c013..e30be775fb5c337b2a621bea92d3af31a2cb5cc0 100644
--- a/docs-cn/11-operation/10-monitor.md
+++ b/docs-cn/13-operation/10-monitor.md
@@ -1,4 +1,6 @@
-# 系统监控
+---
+title: 系统监控
+---
TDengine 启动后,会自动创建一个监测数据库 log,并自动将服务器的 CPU、内存、硬盘空间、带宽、请求数、磁盘读写速度、慢查询等信息定时写入该数据库。TDengine 还将重要的系统操作(比如登录、创建、删除数据库等)日志以及各种错误报警信息记录下来存放在 log 库里。系统管理员可以从 CLI 直接查看这个数据库,也可以在 WEB 通过图形化界面查看这些监测信息。
@@ -49,4 +51,4 @@ chmod +x TDinsight.sh
运行程序并重启 Grafana 服务,打开面板:`http://localhost:3000/d/tdinsight`。
-更多使用场景和限制请参考[TDinsight](https://github.com/taosdata/grafanaplugin/blob/master/dashboards/TDinsight.md) 文档。
+更多使用场景和限制请参考[TDinsight](/reference/tdinsight/) 文档。
diff --git a/docs-cn/11-operation/11-optimize.md b/docs-cn/13-operation/11-optimize.md
similarity index 83%
rename from docs-cn/11-operation/11-optimize.md
rename to docs-cn/13-operation/11-optimize.md
index b06df1d32a80362e4ea28e92d1c12b6b58b83896..57411dbbb0705ae4c9c4568bb09909918bcee6a3 100644
--- a/docs-cn/11-operation/11-optimize.md
+++ b/docs-cn/13-operation/11-optimize.md
@@ -1,8 +1,10 @@
-# 性能优化
+---
+title: 性能优化
+---
-因数据行 [update](https://www.taosdata.com/cn/documentation/faq#update)、表删除、数据过期等原因,TDengine 的磁盘存储文件有可能出现数据碎片,影响查询操作的性能表现。从 2.1.3.0 版本开始,新增 SQL 指令 COMPACT 来启动碎片重整过程:
+因数据行 [update](/train-faq/faq/#update)、表删除、数据过期等原因,TDengine 的磁盘存储文件有可能出现数据碎片,影响查询操作的性能表现。从 2.1.3.0 版本开始,新增 SQL 指令 COMPACT 来启动碎片重整过程:
-```mysql
+```sql
COMPACT VNODES IN (vg_id1, vg_id2, ...)
```
@@ -10,20 +12,19 @@ COMPACT 命令对指定的一个或多个 VGroup 启动碎片重整,系统会
需要注意的是,碎片重整操作会大幅消耗磁盘 I/O。因此在重整进行期间,有可能会影响节点的写入和查询性能,甚至在极端情况下导致短时间的阻写。
-
## 存储参数优化
不同应用场景的数据往往具有不同的数据特征,比如保留天数、副本数、采集频次、记录大小、采集点的数量、压缩等都可完全不同。为获得在存储上的最高效率,TDengine 提供如下存储相关的系统配置参数(既可以作为 create database 指令的参数,也可以写在 taos.cfg 配置文件中用来设定创建新数据库时所采用的默认值):
| # | 配置参数名称 | 单位 | 含义 | **取值范围** | **缺省值** |
| --- | ------------ | ---- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------- | ---------- |
-| 1 | days | 天 | 一个数据文件存储数据的时间跨度 | | 10 |
-| 2 | keep | 天 | (可通过 alter database 修改)数据库中数据保留的天数。 | 3650 |
-| 3 | cache | MB | 内存块的大小 | | 16 |
-| 4 | blocks | | (可通过 alter database 修改)每个 VNODE(TSDB)中有多少个 cache 大小的内存块。因此一个 VNODE 使用的内存大小粗略为(cache \* blocks)。 | | 6 |
+| 1 | days | 天 | 一个数据文件存储数据的时间跨度 | 1-3650 | 10 |
+| 2 | keep | 天 | (可通过 alter database 修改)数据库中数据保留的天数。 |1-36500 |3650 |
+| 3 | cache | MB | 内存块的大小 | 1-128 | 16 |
+| 4 | blocks | | (可通过 alter database 修改)每个 VNODE(TSDB)中有多少个 cache 大小的内存块。因此一个 VNODE 使用的内存大小粗略为(cache \* blocks)。 | 3-10000 | 6 |
| 5 | quorum | | (可通过 alter database 修改)多副本环境下指令执行的确认数要求 | 1-2 | 1 |
-| 6 | minRows | | 文件块中记录的最小条数 | | 100 |
-| 7 | maxRows | | 文件块中记录的最大条数 | | 4096 |
+| 6 | minRows | | 文件块中记录的最小条数 | 10-1000 | 100 |
+| 7 | maxRows | | 文件块中记录的最大条数 | 200-10000 | 4096 |
| 8 | comp | | (可通过 alter database 修改)文件压缩标志位 | 0:关闭,1:一阶段压缩,2:两阶段压缩 | 2 |
| 9 | walLevel | | (作为 database 的参数时名为 wal;在 taos.cfg 中作为参数时需要写作 walLevel)WAL 级别 | 1:写 wal,但不执行 fsync;2:写 wal, 而且执行 fsync | 1 |
| 10 | fsync | 毫秒 | 当 wal 设置为 2 时,执行 fsync 的周期。设置为 0,表示每次写入,立即执行 fsync。 | | 3000 |
@@ -34,7 +35,7 @@ COMPACT 命令对指定的一个或多个 VGroup 启动碎片重整,系统会
对于一个应用场景,可能有多种数据特征的数据并存,最佳的设计是将具有相同数据特征的表放在一个库里,这样一个应用有多个库,而每个库可以配置不同的存储参数,从而保证系统有最优的性能。TDengine 允许应用在创建库时指定上述存储参数,如果指定,该参数就将覆盖对应的系统配置参数。举例,有下述 SQL:
-```mysql
+```sql
CREATE DATABASE demo DAYS 10 CACHE 32 BLOCKS 8 REPLICA 3 UPDATE 1;
```
@@ -42,27 +43,27 @@ COMPACT 命令对指定的一个或多个 VGroup 启动碎片重整,系统会
一个数据库创建成功后,仅部分参数可以修改并实时生效,其余参数不能修改:
-| **参数名** | **能否修改** | **范围** | **修改语法示例** |
-| ----------- | ------------ | ------------------------------------------ | -------------------------------------- |
-| name | | | |
-| create time | | | |
-| ntables | | | |
-| vgroups | | | |
-| replica | **YES** | 在线 dnode 数目为 1:1-1;2:1-2;>=3:1-3 | ALTER DATABASE REPLICA _n_ |
-| quorum | **YES** | 1-2 | ALTER DATABASE QUORUM _n_ |
-| days | | | |
-| keep | **YES** | days-365000 | ALTER DATABASE KEEP _n_ |
-| cache | | | |
-| blocks | **YES** | 3-1000 | ALTER DATABASE BLOCKS _n_ |
-| minrows | | | |
-| maxrows | | | |
-| wal | | | |
-| fsync | | | |
-| comp | **YES** | 0-2 | ALTER DATABASE COMP _n_ |
-| precision | | | |
-| status | | | |
-| update | | | |
-| cachelast | **YES** | 0 \| 1 \| 2 \| 3 | ALTER DATABASE CACHELAST _n_ |
+| **参数名** | **能否修改** | **范围** | **修改语法示例** |
+| ----------- | ------------ | ---------------------------------------------------------- | -------------------------------------- |
+| name | | | |
+| create time | | | |
+| ntables | | | |
+| vgroups | | | |
+| replica | **YES** | 在线 dnode 数目为:
1:1-1;
2:1-2;
\>=3:1-3 | ALTER DATABASE REPLICA _n_ |
+| quorum | **YES** | 1-2 | ALTER DATABASE QUORUM _n_ |
+| days | | | |
+| keep | **YES** | days-365000 | ALTER DATABASE KEEP _n_ |
+| cache | | | |
+| blocks | **YES** | 3-1000 | ALTER DATABASE BLOCKS _n_ |
+| minrows | | | |
+| maxrows | | | |
+| wal | | | |
+| fsync | | | |
+| comp | **YES** | 0-2 | ALTER DATABASE COMP _n_ |
+| precision | | | |
+| status | | | |
+| update | | | |
+| cachelast | **YES** | 0 \| 1 \| 2 \| 3 | ALTER DATABASE CACHELAST _n_ |
**说明:**在 2.1.3.0 版本之前,通过 ALTER DATABASE 语句修改这些参数后,需要重启服务器才能生效。
@@ -83,7 +84,7 @@ TDengine 集群中加入一个新的 dnode 时,涉及集群相关的一些参
为方便调试,可通过 SQL 语句临时调整每个 dnode 的日志配置,系统重启后会失效:
-```mysql
+```sql
ALTER DNODE
```
@@ -97,4 +98,3 @@ ALTER DNODE
```
alter dnode 1 debugFlag 135;
```
-
diff --git a/docs-cn/11-operation/17-diagnose.md b/docs-cn/13-operation/17-diagnose.md
similarity index 92%
rename from docs-cn/11-operation/17-diagnose.md
rename to docs-cn/13-operation/17-diagnose.md
index 666fe6e655cab27962d156d97bf14086feaa32b5..e2a2ef035a33a295b206c77ec08edf8f7842671f 100644
--- a/docs-cn/11-operation/17-diagnose.md
+++ b/docs-cn/13-operation/17-diagnose.md
@@ -1,4 +1,6 @@
-# 诊断及其他
+---
+title: 诊断及其他
+---
## 网络连接诊断
@@ -9,8 +11,11 @@
诊断步骤:
1. 如拟诊断的端口范围与服务器 taosd 实例的端口范围相同,须先停掉 taosd 实例
-2. 服务端命令行输入:`taos -n server -P ` 以服务端身份启动对端口 port 为基准端口的监听
-3. 客户端命令行输入:`taos -n client -h -P ` 以客户端身份启动对指定的服务器、指定的端口发送测试包
+2. 服务端命令行输入:`taos -n server -P -l ` 以服务端身份启动对端口 port 为基准端口的监听
+3. 客户端命令行输入:`taos -n client -h -P -l ` 以客户端身份启动对指定的服务器、指定的端口发送测试包
+
+-l : 测试网络包的大小(单位:字节)。最小值是 11、最大值是 64000,默认值为 1000。
+注:两端命令行中指定的测试包长度必须一致,否则测试显示失败。
服务端运行正常的话会输出以下信息:
@@ -94,7 +99,7 @@ taos -n sync -P 6042 -h
-h:所要连接的服务端的 FQDN 或 ip 地址。如果不设置这一项,会使用本机 taos.cfg 文件中 FQDN 参数的设置作为默认值。
-P:所连接服务端的网络端口。默认值为 6030。
-N:诊断过程中使用的网络包总数。最小值是 1、最大值是 10000,默认值为 100。
--l:单个网络包的大小(单位:字节)。最小值是 1024、最大值是 1024 _ 1024 _ 1024,默认值为 1000。
+-l:单个网络包的大小(单位:字节)。最小值是 1024、最大值是 1024 `*` 1024 `*` 1024,默认值为 1024。
-S:网络封包的类型。可以是 TCP 或 UDP,默认值为 TCP。
## FQDN 解析速度诊断
diff --git a/docs-cn/13-operation/_category_.yml b/docs-cn/13-operation/_category_.yml
new file mode 100644
index 0000000000000000000000000000000000000000..930e441defdc80215ce5d90375a9cbd2d4bad947
--- /dev/null
+++ b/docs-cn/13-operation/_category_.yml
@@ -0,0 +1,4 @@
+label: 运维指南
+link:
+ slug: /operation/
+ type: generated-index
diff --git a/docs-cn/13-tdinternal/03-taosd.md b/docs-cn/13-tdinternal/03-taosd.md
deleted file mode 100644
index 874fa230290016b88fbc905233745a1052ca5a18..0000000000000000000000000000000000000000
--- a/docs-cn/13-tdinternal/03-taosd.md
+++ /dev/null
@@ -1,121 +0,0 @@
----
-sidebar_label: taosd 的设计
----
-
-# taosd的设计
-
-逻辑上,TDengine系统包含dnode, taosc和App,dnode是服务器侧执行代码taosd的一个运行实例,因此taosd是TDengine的核心,本文对taosd的设计做一简单的介绍,模块内的实现细节请见其他文档。
-
-## 系统模块图
-
-taosd包含rpc, dnode, vnode, tsdb, query, cq, sync, wal, mnode, http, monitor等模块,具体如下图:
-
-
-
-taosd的启动入口是dnode模块,dnode然后启动其他模块,包括可选配置的http, monitor模块。taosc或dnode之间交互的消息都是通过rpc模块进行,dnode模块根据接收到的消息类型,将消息分发到vnode或mnode的消息队列,或由dnode模块自己消费。dnode的工作线程(worker)消费消息队列里的消息,交给mnode或vnode进行处理。下面对各个模块做简要说明。
-
-## RPC模块
-
-该模块负责taosd与taosc, 以及其他数据节点之间的通讯。TDengine没有采取标准的HTTP或gRPC等第三方工具,而是实现了自己的通讯模块RPC。
-
-考虑到物联网场景下,数据写入的包一般不大,因此除支持TCP连接之外,RPC还支持UDP连接。当数据包小于15K时,RPC将采用UDP方式进行连接,否则将采用TCP连接。对于查询类的消息,RPC不管包的大小,总是采取TCP连接。对于UDP连接,RPC实现了自己的超时、重传、顺序检查等机制,以保证数据可靠传输。
-
-RPC模块还提供数据压缩功能,如果数据包的字节数超过系统配置参数compressMsgSize, RPC在传输中将自动压缩数据,以节省带宽。
-
-为保证数据的安全和数据的integrity, RPC模块采用MD5做数字签名,对数据的真实性和完整性进行认证。
-
-## DNODE模块
-
-该模块是整个taosd的入口,它具体负责如下任务:
-
-- 系统的初始化,包括
- - 从文件taos.cfg读取系统配置参数,从文件dnodeCfg.json读取数据节点的配置参数;
- - 启动RPC模块,并建立起与taosc通讯的server连接,与其他数据节点通讯的server连接;
- - 启动并初始化dnode的内部管理, 该模块将扫描该数据节点已有的vnode,并打开它们;
- - 初始化可配置的模块,如mnode, http, monitor等。
-- 数据节点的管理,包括
- - 定时的向mnode发送status消息,报告自己的状态;
- - 根据mnode的指示,创建、改变、删除vnode;
- - 根据mnode的指示,修改自己的配置参数;
-- 消息的分发、消费,包括
- - 为每一个vnode和mnode的创建并维护一个读队列、一个写队列;
- - 将从taosc或其他数据节点来的消息,根据消息类型,将其直接分发到不同的消息队列,或由自己的管理模块直接消费;
- - 维护一个读的线程池,消费读队列的消息,交给vnode或mnode处理。为支持高并发,一个读线程(Worker)可以消费多个队列的消息,一个读队列可以由多个worker消费;
- - 维护一个写的线程池,消费写队列的消息,交给vnode或mnode处理。为保证写操作的序列化,一个写队列只能由一个写线程负责,但一个写线程可以负责多个写队列。
-
-taosd的消息消费由dnode通过读写线程池进行控制,是系统的中枢。该模块内的结构体图如下:
-
-
-
-## VNODE模块
-
-vnode是一独立的数据存储查询逻辑单元,但因为一个vnode只能容许一个DB,因此vnode内部没有account, DB, user等概念。为实现更好的模块化、封装以及未来的扩展,它有很多子模块,包括负责存储的TSDB,负责查询的Query, 负责数据复制的sync,负责数据库日志的的wal, 负责连续查询的cq(continuous query), 负责事件触发的流计算的event等模块,这些子模块只与vnode模块发生关系,与其他模块没有任何调用关系。模块图如下:
-
-
-
-vnode模块向下,与dnodeVRead,dnodeVWrite发生互动,向上,与子模块发生互动。它主要的功能有:
-
-- 协调各个子模块的互动。各个子模块之间都不直接调用,都需要通过vnode模块进行;
-- 对于来自taosc或mnode的写操作,vnode模块将其分解为写日志(wal), 转发(sync), 本地存储(tsdb)子模块的操作;
-- 对于查询操作,分发到query模块进行。
-
-一个数据节点里有多个vnode, 因此vnode模块是有多个运行实例的。每个运行实例是完全独立的。
-
-vnode与其子模块是通过API直接调用,而不是通过消息队列传递。而且各个子模块只与vnode模块有交互,不与dnode, rpc等模块发生任何直接关联。
-
-## MNODE模块
-
-mnode是整个系统的大脑,负责整个系统的资源调度,负责meta data的管理与存储。
-
-一个运行的系统里,只有一个mnode,但它有多个副本(由系统配置参数numOfMnodes控制)。这些副本分布在不同的dnode里,目的是保证系统的高可靠运行。副本之间的数据复制是采用同步而非异步的方式,以确保数据的一致性,确保数据不会丢失。这些副本会自动选举一个Master,其他副本是slave。所有数据更新类的操作,都只能在master上进行,而查询类的可以在slave节点上进行。代码实现上,同步模块与vnode共享,但mnode被分配一个特殊的vgroup ID: 1,而且quorum大于1。整个集群系统是由多个dnode组成的,运行的mnode的副本数不可能超过dnode的个数,但不会超过配置的副本数。如果某个mnode副本宕机一段时间,只要超过半数的mnode副本仍在运行,运行的mnode会自动根据整个系统的资源情况,在其他dnode里再启动一个mnode, 以保证运行的副本数。
-
-各个dnode通过信息交换,保存有mnode各个副本的End Point列表,并向其中的master节点定时(间隔由系统配置参数statusInterval控制)发送status消息,消息体里包含该dnode的CPU、内存、剩余存储空间、vnode个数,以及各个vnode的状态(存储空间、原始数据大小、记录条数、角色等)。这样mnode就了解整个系统的资源情况,如果用户创建新的表,就可以决定需要在哪个dnode创建;如果增加或删除dnode, 或者监测到某dnode数据过热、或离线太长,就可以决定需要挪动那些vnode,以实现负载均衡。
-
-mnode里还负责account, user, DB, stable, table, vgroup, dnode的创建、删除与更新。mnode不仅把这些entity的meta data保存在内存,还做持久化存储。但为节省内存,各个表的标签值不保存在mnode(保存在vnode),而且子表不维护自己的schema, 而是与stable共享。为减小mnode的查询压力,taosc会缓存table、stable的schema。对于查询类的操作,各个slave mnode也可以提供,以减轻master压力。
-
-## TSDB模块
-
-TSDB模块是VNODE中的负责快速高并发地存储和读取属于该VNODE的表的元数据及采集的时序数据的引擎。除此之外,TSDB还提供了表结构的修改、表标签值的修改等功能。TSDB提供API供VNODE和Query等模块调用。TSDB中存储了两类数据,1:元数据信息;2:时序数据
-
-### 元数据信息
-
-TSDB中存储的元数据包含属于其所在的VNODE中表的类型,schema的定义等。对于超级表和超级表下的子表而言,又包含了tag的schema定义以及子表的tag值等。对于元数据信息而言,TSDB就相当于一个全内存的KV型数据库,属于该VNODE的表对象全部在内存中,方便快速查询表的信息。除此之外,TSDB还对其中的子表,按照tag的第一列取值做了全内存的索引,大大加快了对于标签的过滤查询。TSDB中的元数据的最新状态在落盘时,会以追加(append-only)的形式,写入到meta文件中。meta文件只进行追加操作,即便是元数据的删除,也会以一条记录的形式写入到文件末尾。TSDB也提供了对于元数据的修改操作,如表schema的修改,tag schema的修改以及tag值的修改等。
-
-### 时序数据
-
-每个TSDB在创建时,都会事先分配一定量的内存缓冲区,且内存缓冲区的大小可配可修改。表采集的时序数据,在写入TSDB时,首先以追加的方式写入到分配的内存缓冲区中,同时建立基于时间戳的内存索引,方便快速查询。当内存缓冲区的数据积累到一定的程度时(达到内存缓冲区总大小的1/3),则会触发落盘操作,将缓冲区中的数据持久化到硬盘文件上。时序数据在内存缓冲区中是以行(row)的形式存储的。
-
-而时序数据在写入到TSDB的数据文件时,是以列(column)的形式存储的。TSDB中的数据文件包含多个数据文件组,每个数据文件组中又包含.head、.data和.last三个文件,如(v2f1801.head、v2f1801.data、v2f1801.last)数据文件组。TSDB中的数据文件组是按照时间跨度进行分片的,默认是10天一个文件组,且可通过配置文件及建库选项进行配置。分片的数据文件组又按照编号递增排列,方便快速定位某一时间段的时序数据,高效定位数据文件组。时序数据在TSDB的数据文件中是以块的形式进行列式存储的,每个块中只包含一张表的数据,且数据在一个块中是按照时间顺序递增排列的。在一个数据文件组中,.head文件负责存储数据块的索引及统计信息,如每个块的位置,压缩算法,时间戳范围等。存储在.head文件中一张表的索引信息是按照数据块中存储的数据的时间递增排列的,方便进行折半查找等工作。.head和.last文件是存储真实数据块的文件,若数据块中的数据累计到一定程度,则会写入.data文件中,否则,会写入.last文件中,等待下次落盘时合并数据写入.data文件中,从而大大减少文件中块的个数,避免数据的过度碎片化。
-
-## Query模块
-
-该模块负责整体系统的查询处理。客户端调用该该模块进行SQL语法解析,并将查询或写入请求发送到vnode,同时负责针对超级表的查询进行二阶段的聚合操作。在Vnode端,该模块调用TSDB模块读取系统中存储的数据进行查询处理。Query模块还定义了系统能够支持的全部查询函数,查询函数的实现机制与查询框架无耦合,可以在不修改查询流程的情况下动态增加查询函数。详细的设计请参见《TDengine 2.0查询模块设计》。
-
-## SYNC模块
-
-该模块实现数据的多副本复制,包括vnode与mnode的数据复制,支持异步和同步两种复制方式,以满足meta data与时序数据不同复制的需求。因为它为mnode与vnode共享,系统为mnode副本预留了一个特殊的vgroup ID:1。因此vnode group的ID是从2开始的。
-
-每个vnode/mnode模块实例会有一对应的sync模块实例,他们是一一对应的。详细设计请见[TDengine 2.0 数据复制模块设计](https://www.taosdata.com/cn/documentation/architecture/replica/)
-
-## WAL模块
-
-该模块负责将新插入的数据写入write ahead log(WAL), 为vnode, mnode共享。以保证服务器crash或其他故障,能从WAL中恢复数据。
-
-每个vnode/mnode模块实例会有一对应的wal模块实例,是完全一一对应的。WAL的落盘操作由两个参数walLevel, fsync控制。看具体场景,如果要100%保证数据不会丢失,需要将walLevel配置为2,fsync设置为0,每条数据插入请求,都会实时落盘后,才会给应用确认
-
-## HTTP模块
-
-该模块负责处理系统对外的RESTful接口,可以通过配置,由dnode启动或停止。
-
-该模块将接收到的RESTful请求,做了各种合法性检查后,将其变成标准的SQL语句,通过taosc的异步接口,将请求发往整个系统中的任一dnode。收到处理后的结果后,再翻译成HTTP协议,返回给应用。
-
-如果HTTP模块启动,就意味着启动了一个taosc的实例。任一一个dnode都可以启动该模块,以实现对RESTful请求的分布式处理。
-
-## Monitor模块
-
-该模块负责检测一个dnode的运行状态,可以通过配置,由dnode启动或停止。原则上,每个dnode都应该启动一个monitor实例。
-
-Monitor采集TDengine里的关键操作,比如创建、删除、更新账号、表、库等,而且周期性的收集CPU、内存、网络等资源的使用情况(采集周期由系统配置参数monitorInterval控制)。获得这些数据后,monitor模块将采集的数据写入系统的日志库(DB名字由系统配置参数monitorDbName控制)。
-
-Monitor模块使用taosc来将采集的数据写入系统,因此每个monitor实例,都有一个taosc运行实例。
-
diff --git a/docs-cn/13-tdinternal/_category_.yml b/docs-cn/13-tdinternal/_category_.yml
deleted file mode 100644
index e654a7f3d212869be00d819f16dcdb7197244da2..0000000000000000000000000000000000000000
--- a/docs-cn/13-tdinternal/_category_.yml
+++ /dev/null
@@ -1,3 +0,0 @@
-label: 技术内幕
-link:
- type: generated-index
\ No newline at end of file
diff --git a/docs-cn/14-reference/01-taos-sql/12-errorcode.md b/docs-cn/14-reference/01-taos-sql/12-errorcode.md
deleted file mode 100644
index 2013e1e640d10bbd09572ca1d9c4ba12a38620d8..0000000000000000000000000000000000000000
--- a/docs-cn/14-reference/01-taos-sql/12-errorcode.md
+++ /dev/null
@@ -1,176 +0,0 @@
----
-sidebar_label: 错误码
----
-
-# 错误码以及对应的十进制码
-
-| 状态码 | 模 | 错误码(十六进制) | 错误描述 | 错误码(十进制) |
-| :-------------------------------------- | :-: | :----------------: | :------------------------------------------- | :--------------- |
-| TSDB_CODE_RPC_ACTION_IN_PROGRESS | 0 | 0x0001 | "Action in progress" | -2147483647 |
-| TSDB_CODE_RPC_AUTH_REQUIRED | 0 | 0x0002 | "Authentication required" | -2147483646 |
-| TSDB_CODE_RPC_AUTH_FAILURE | 0 | 0x0003 | "Authentication failure" | -2147483645 |
-| TSDB_CODE_RPC_REDIRECT | 0 | 0x0004 | "Redirect" | -2147483644 |
-| TSDB_CODE_RPC_NOT_READY | 0 | 0x0005 | "System not ready" | -2147483643 |
-| TSDB_CODE_RPC_ALREADY_PROCESSED | 0 | 0x0006 | "Message already processed" | -2147483642 |
-| TSDB_CODE_RPC_LAST_SESSION_NOT_FINISHED | 0 | 0x0007 | "Last session not finished" | -2147483641 |
-| TSDB_CODE_RPC_MISMATCHED_LINK_ID | 0 | 0x0008 | "Mismatched meter id" | -2147483640 |
-| TSDB_CODE_RPC_TOO_SLOW | 0 | 0x0009 | "Processing of request timed out" | -2147483639 |
-| TSDB_CODE_RPC_MAX_SESSIONS | 0 | 0x000A | "Number of sessions reached limit" | -2147483638 |
-| TSDB_CODE_RPC_NETWORK_UNAVAIL | 0 | 0x000B | "Unable to establish connection" | -2147483637 |
-| TSDB_CODE_RPC_APP_ERROR | 0 | 0x000C | "Unexpected generic error in RPC" | -2147483636 |
-| TSDB_CODE_RPC_UNEXPECTED_RESPONSE | 0 | 0x000D | "Unexpected response" | -2147483635 |
-| TSDB_CODE_RPC_INVALID_VALUE | 0 | 0x000E | "Invalid value" | -2147483634 |
-| TSDB_CODE_RPC_INVALID_TRAN_ID | 0 | 0x000F | "Invalid transaction id" | -2147483633 |
-| TSDB_CODE_RPC_INVALID_SESSION_ID | 0 | 0x0010 | "Invalid session id" | -2147483632 |
-| TSDB_CODE_RPC_INVALID_MSG_TYPE | 0 | 0x0011 | "Invalid message type" | -2147483631 |
-| TSDB_CODE_RPC_INVALID_RESPONSE_TYPE | 0 | 0x0012 | "Invalid response type" | -2147483630 |
-| TSDB_CODE_RPC_INVALID_TIME_STAMP | 0 | 0x0013 | "Invalid timestamp" | -2147483629 |
-| TSDB_CODE_COM_OPS_NOT_SUPPORT | 0 | 0x0100 | "Operation not supported" | -2147483392 |
-| TSDB_CODE_COM_MEMORY_CORRUPTED | 0 | 0x0101 | "Memory corrupted" | -2147483391 |
-| TSDB_CODE_COM_OUT_OF_MEMORY | 0 | 0x0102 | "Out of memory" | -2147483390 |
-| TSDB_CODE_COM_INVALID_CFG_MSG | 0 | 0x0103 | "Invalid config message" | -2147483389 |
-| TSDB_CODE_COM_FILE_CORRUPTED | 0 | 0x0104 | "Data file corrupted" | -2147483388 |
-| TSDB_CODE_TSC_INVALID_OPERATION | 0 | 0x0200 | "Invalid SQL statement" | -2147483136 |
-| TSDB_CODE_TSC_INVALID_QHANDLE | 0 | 0x0201 | "Invalid qhandle" | -2147483135 |
-| TSDB_CODE_TSC_INVALID_TIME_STAMP | 0 | 0x0202 | "Invalid combination of client/service time" | -2147483134 |
-| TSDB_CODE_TSC_INVALID_VALUE | 0 | 0x0203 | "Invalid value in client" | -2147483133 |
-| TSDB_CODE_TSC_INVALID_VERSION | 0 | 0x0204 | "Invalid client version" | -2147483132 |
-| TSDB_CODE_TSC_INVALID_IE | 0 | 0x0205 | "Invalid client ie" | -2147483131 |
-| TSDB_CODE_TSC_INVALID_FQDN | 0 | 0x0206 | "Invalid host name" | -2147483130 |
-| TSDB_CODE_TSC_INVALID_USER_LENGTH | 0 | 0x0207 | "Invalid user name" | -2147483129 |
-| TSDB_CODE_TSC_INVALID_PASS_LENGTH | 0 | 0x0208 | "Invalid password" | -2147483128 |
-| TSDB_CODE_TSC_INVALID_DB_LENGTH | 0 | 0x0209 | "Database name too long" | -2147483127 |
-| TSDB_CODE_TSC_INVALID_TABLE_ID_LENGTH | 0 | 0x020A | "Table name too long" | -2147483126 |
-| TSDB_CODE_TSC_INVALID_CONNECTION | 0 | 0x020B | "Invalid connection" | -2147483125 |
-| TSDB_CODE_TSC_OUT_OF_MEMORY | 0 | 0x020C | "System out of memory" | -2147483124 |
-| TSDB_CODE_TSC_NO_DISKSPACE | 0 | 0x020D | "System out of disk space" | -2147483123 |
-| TSDB_CODE_TSC_QUERY_CACHE_ERASED | 0 | 0x020E | "Query cache erased" | -2147483122 |
-| TSDB_CODE_TSC_QUERY_CANCELLED | 0 | 0x020F | "Query terminated" | -2147483121 |
-| TSDB_CODE_TSC_SORTED_RES_TOO_MANY | 0 | 0x0210 | "Result set too large to be sorted" | -2147483120 |
-| TSDB_CODE_TSC_APP_ERROR | 0 | 0x0211 | "Application error" | -2147483119 |
-| TSDB_CODE_TSC_ACTION_IN_PROGRESS | 0 | 0x0212 | "Action in progress" | -2147483118 |
-| TSDB_CODE_TSC_DISCONNECTED | 0 | 0x0213 | "Disconnected from service" | -2147483117 |
-| TSDB_CODE_TSC_NO_WRITE_AUTH | 0 | 0x0214 | "No write permission" | -2147483116 |
-| TSDB_CODE_MND_MSG_NOT_PROCESSED | 0 | 0x0300 | "Message not processed" | -2147482880 |
-| TSDB_CODE_MND_ACTION_IN_PROGRESS | 0 | 0x0301 | "Message is progressing" | -2147482879 |
-| TSDB_CODE_MND_ACTION_NEED_REPROCESSED | 0 | 0x0302 | "Messag need to be reprocessed" | -2147482878 |
-| TSDB_CODE_MND_NO_RIGHTS | 0 | 0x0303 | "Insufficient privilege for operation" | -2147482877 |
-| TSDB_CODE_MND_APP_ERROR | 0 | 0x0304 | "Unexpected generic error in mnode" | -2147482876 |
-| TSDB_CODE_MND_INVALID_CONNECTION | 0 | 0x0305 | "Invalid message connection" | -2147482875 |
-| TSDB_CODE_MND_INVALID_MSG_VERSION | 0 | 0x0306 | "Incompatible protocol version" | -2147482874 |
-| TSDB_CODE_MND_INVALID_MSG_LEN | 0 | 0x0307 | "Invalid message length" | -2147482873 |
-| TSDB_CODE_MND_INVALID_MSG_TYPE | 0 | 0x0308 | "Invalid message type" | -2147482872 |
-| TSDB_CODE_MND_TOO_MANY_SHELL_CONNS | 0 | 0x0309 | "Too many connections" | -2147482871 |
-| TSDB_CODE_MND_OUT_OF_MEMORY | 0 | 0x030A | "Out of memory in mnode" | -2147482870 |
-| TSDB_CODE_MND_INVALID_SHOWOBJ | 0 | 0x030B | "Data expired" | -2147482869 |
-| TSDB_CODE_MND_INVALID_QUERY_ID | 0 | 0x030C | "Invalid query id" | -2147482868 |
-| TSDB_CODE_MND_INVALID_STREAM_ID | 0 | 0x030D | "Invalid stream id" | -2147482867 |
-| TSDB_CODE_MND_INVALID_CONN_ID | 0 | 0x030E | "Invalid connection id" | -2147482866 |
-| TSDB_CODE_MND_SDB_OBJ_ALREADY_THERE | 0 | 0x0320 | "Object already there" | -2147482848 |
-| TSDB_CODE_MND_SDB_ERROR | 0 | 0x0321 | "Unexpected generic error in sdb" | -2147482847 |
-| TSDB_CODE_MND_SDB_INVALID_TABLE_TYPE | 0 | 0x0322 | "Invalid table type" | -2147482846 |
-| TSDB_CODE_MND_SDB_OBJ_NOT_THERE | 0 | 0x0323 | "Object not there" | -2147482845 |
-| TSDB_CODE_MND_SDB_INVAID_META_ROW | 0 | 0x0324 | "Invalid meta row" | -2147482844 |
-| TSDB_CODE_MND_SDB_INVAID_KEY_TYPE | 0 | 0x0325 | "Invalid key type" | -2147482843 |
-| TSDB_CODE_MND_DNODE_ALREADY_EXIST | 0 | 0x0330 | "DNode already exists" | -2147482832 |
-| TSDB_CODE_MND_DNODE_NOT_EXIST | 0 | 0x0331 | "DNode does not exist" | -2147482831 |
-| TSDB_CODE_MND_VGROUP_NOT_EXIST | 0 | 0x0332 | "VGroup does not exist" | -2147482830 |
-| TSDB_CODE_MND_NO_REMOVE_MASTER | 0 | 0x0333 | "Master DNode cannot be removed" | -2147482829 |
-| TSDB_CODE_MND_NO_ENOUGH_DNODES | 0 | 0x0334 | "Out of DNodes" | -2147482828 |
-| TSDB_CODE_MND_CLUSTER_CFG_INCONSISTENT | 0 | 0x0335 | "Cluster cfg inconsistent" | -2147482827 |
-| TSDB_CODE_MND_INVALID_DNODE_CFG_OPTION | 0 | 0x0336 | "Invalid dnode cfg option" | -2147482826 |
-| TSDB_CODE_MND_BALANCE_ENABLED | 0 | 0x0337 | "Balance already enabled" | -2147482825 |
-| TSDB_CODE_MND_VGROUP_NOT_IN_DNODE | 0 | 0x0338 | "Vgroup not in dnode" | -2147482824 |
-| TSDB_CODE_MND_VGROUP_ALREADY_IN_DNODE | 0 | 0x0339 | "Vgroup already in dnode" | -2147482823 |
-| TSDB_CODE_MND_DNODE_NOT_FREE | 0 | 0x033A | "Dnode not avaliable" | -2147482822 |
-| TSDB_CODE_MND_INVALID_CLUSTER_ID | 0 | 0x033B | "Cluster id not match" | -2147482821 |
-| TSDB_CODE_MND_NOT_READY | 0 | 0x033C | "Cluster not ready" | -2147482820 |
-| TSDB_CODE_MND_ACCT_ALREADY_EXIST | 0 | 0x0340 | "Account already exists" | -2147482816 |
-| TSDB_CODE_MND_INVALID_ACCT | 0 | 0x0341 | "Invalid account" | -2147482815 |
-| TSDB_CODE_MND_INVALID_ACCT_OPTION | 0 | 0x0342 | "Invalid account options" | -2147482814 |
-| TSDB_CODE_MND_USER_ALREADY_EXIST | 0 | 0x0350 | "User already exists" | -2147482800 |
-| TSDB_CODE_MND_INVALID_USER | 0 | 0x0351 | "Invalid user" | -2147482799 |
-| TSDB_CODE_MND_INVALID_USER_FORMAT | 0 | 0x0352 | "Invalid user format" | -2147482798 |
-| TSDB_CODE_MND_INVALID_PASS_FORMAT | 0 | 0x0353 | "Invalid password format" | -2147482797 |
-| TSDB_CODE_MND_NO_USER_FROM_CONN | 0 | 0x0354 | "Can not get user from conn" | -2147482796 |
-| TSDB_CODE_MND_TOO_MANY_USERS | 0 | 0x0355 | "Too many users" | -2147482795 |
-| TSDB_CODE_MND_TABLE_ALREADY_EXIST | 0 | 0x0360 | "Table already exists" | -2147482784 |
-| TSDB_CODE_MND_INVALID_TABLE_ID | 0 | 0x0361 | "Table name too long" | -2147482783 |
-| TSDB_CODE_MND_INVALID_TABLE_NAME | 0 | 0x0362 | "Table does not exist" | -2147482782 |
-| TSDB_CODE_MND_INVALID_TABLE_TYPE | 0 | 0x0363 | "Invalid table type in tsdb" | -2147482781 |
-| TSDB_CODE_MND_TOO_MANY_TAGS | 0 | 0x0364 | "Too many tags" | -2147482780 |
-| TSDB_CODE_MND_TOO_MANY_TIMESERIES | 0 | 0x0366 | "Too many time series" | -2147482778 |
-| TSDB_CODE_MND_NOT_SUPER_TABLE | 0 | 0x0367 | "Not super table" | -2147482777 |
-| TSDB_CODE_MND_COL_NAME_TOO_LONG | 0 | 0x0368 | "Tag name too long" | -2147482776 |
-| TSDB_CODE_MND_TAG_ALREAY_EXIST | 0 | 0x0369 | "Tag already exists" | -2147482775 |
-| TSDB_CODE_MND_TAG_NOT_EXIST | 0 | 0x036A | "Tag does not exist" | -2147482774 |
-| TSDB_CODE_MND_FIELD_ALREAY_EXIST | 0 | 0x036B | "Field already exists" | -2147482773 |
-| TSDB_CODE_MND_FIELD_NOT_EXIST | 0 | 0x036C | "Field does not exist" | -2147482772 |
-| TSDB_CODE_MND_INVALID_STABLE_NAME | 0 | 0x036D | "Super table does not exist" | -2147482771 |
-| TSDB_CODE_MND_DB_NOT_SELECTED | 0 | 0x0380 | "Database not specified or available" | -2147482752 |
-| TSDB_CODE_MND_DB_ALREADY_EXIST | 0 | 0x0381 | "Database already exists" | -2147482751 |
-| TSDB_CODE_MND_INVALID_DB_OPTION | 0 | 0x0382 | "Invalid database options" | -2147482750 |
-| TSDB_CODE_MND_INVALID_DB | 0 | 0x0383 | "Invalid database name" | -2147482749 |
-| TSDB_CODE_MND_MONITOR_DB_FORBIDDEN | 0 | 0x0384 | "Cannot delete monitor database" | -2147482748 |
-| TSDB_CODE_MND_TOO_MANY_DATABASES | 0 | 0x0385 | "Too many databases for account" | -2147482747 |
-| TSDB_CODE_MND_DB_IN_DROPPING | 0 | 0x0386 | "Database not available" | -2147482746 |
-| TSDB_CODE_DND_MSG_NOT_PROCESSED | 0 | 0x0400 | "Message not processed" | -2147482624 |
-| TSDB_CODE_DND_OUT_OF_MEMORY | 0 | 0x0401 | "Dnode out of memory" | -2147482623 |
-| TSDB_CODE_DND_NO_WRITE_ACCESS | 0 | 0x0402 | "No permission for disk files in dnode" | -2147482622 |
-| TSDB_CODE_DND_INVALID_MSG_LEN | 0 | 0x0403 | "Invalid message length" | -2147482621 |
-| TSDB_CODE_VND_ACTION_IN_PROGRESS | 0 | 0x0500 | "Action in progress" | -2147482368 |
-| TSDB_CODE_VND_MSG_NOT_PROCESSED | 0 | 0x0501 | "Message not processed" | -2147482367 |
-| TSDB_CODE_VND_ACTION_NEED_REPROCESSED | 0 | 0x0502 | "Action need to be reprocessed" | -2147482366 |
-| TSDB_CODE_VND_INVALID_VGROUP_ID | 0 | 0x0503 | "Invalid Vgroup ID" | -2147482365 |
-| TSDB_CODE_VND_INIT_FAILED | 0 | 0x0504 | "Vnode initialization failed" | -2147482364 |
-| TSDB_CODE_VND_NO_DISKSPACE | 0 | 0x0505 | "System out of disk space" | -2147482363 |
-| TSDB_CODE_VND_NO_DISK_PERMISSIONS | 0 | 0x0506 | "No write permission for disk files" | -2147482362 |
-| TSDB_CODE_VND_NO_SUCH_FILE_OR_DIR | 0 | 0x0507 | "Missing data file" | -2147482361 |
-| TSDB_CODE_VND_OUT_OF_MEMORY | 0 | 0x0508 | "Out of memory" | -2147482360 |
-| TSDB_CODE_VND_APP_ERROR | 0 | 0x0509 | "Unexpected generic error in vnode" | -2147482359 |
-| TSDB_CODE_VND_INVALID_STATUS | 0 | 0x0510 | "Database not ready" | -2147482352 |
-| TSDB_CODE_VND_NOT_SYNCED | 0 | 0x0511 | "Database suspended" | -2147482351 |
-| TSDB_CODE_VND_NO_WRITE_AUTH | 0 | 0x0512 | "Write operation denied" | -2147482350 |
-| TSDB_CODE_TDB_INVALID_TABLE_ID | 0 | 0x0600 | "Invalid table ID" | -2147482112 |
-| TSDB_CODE_TDB_INVALID_TABLE_TYPE | 0 | 0x0601 | "Invalid table type" | -2147482111 |
-| TSDB_CODE_TDB_IVD_TB_SCHEMA_VERSION | 0 | 0x0602 | "Invalid table schema version" | -2147482110 |
-| TSDB_CODE_TDB_TABLE_ALREADY_EXIST | 0 | 0x0603 | "Table already exists" | -2147482109 |
-| TSDB_CODE_TDB_INVALID_CONFIG | 0 | 0x0604 | "Invalid configuration" | -2147482108 |
-| TSDB_CODE_TDB_INIT_FAILED | 0 | 0x0605 | "Tsdb init failed" | -2147482107 |
-| TSDB_CODE_TDB_NO_DISKSPACE | 0 | 0x0606 | "No diskspace for tsdb" | -2147482106 |
-| TSDB_CODE_TDB_NO_DISK_PERMISSIONS | 0 | 0x0607 | "No permission for disk files" | -2147482105 |
-| TSDB_CODE_TDB_FILE_CORRUPTED | 0 | 0x0608 | "Data file(s) corrupted" | -2147482104 |
-| TSDB_CODE_TDB_OUT_OF_MEMORY | 0 | 0x0609 | "Out of memory" | -2147482103 |
-| TSDB_CODE_TDB_TAG_VER_OUT_OF_DATE | 0 | 0x060A | "Tag too old" | -2147482102 |
-| TSDB_CODE_TDB_TIMESTAMP_OUT_OF_RANGE | 0 | 0x060B | "Timestamp data out of range" | -2147482101 |
-| TSDB_CODE_TDB_SUBMIT_MSG_MSSED_UP | 0 | 0x060C | "Submit message is messed up" | -2147482100 |
-| TSDB_CODE_TDB_INVALID_ACTION | 0 | 0x060D | "Invalid operation" | -2147482099 |
-| TSDB_CODE_TDB_INVALID_CREATE_TB_MSG | 0 | 0x060E | "Invalid creation of table" | -2147482098 |
-| TSDB_CODE_TDB_NO_TABLE_DATA_IN_MEM | 0 | 0x060F | "No table data in memory skiplist" | -2147482097 |
-| TSDB_CODE_TDB_FILE_ALREADY_EXISTS | 0 | 0x0610 | "File already exists" | -2147482096 |
-| TSDB_CODE_TDB_TABLE_RECONFIGURE | 0 | 0x0611 | "Need to reconfigure table" | -2147482095 |
-| TSDB_CODE_TDB_IVD_CREATE_TABLE_INFO | 0 | 0x0612 | "Invalid information to create table" | -2147482094 |
-| TSDB_CODE_QRY_INVALID_QHANDLE | 0 | 0x0700 | "Invalid handle" | -2147481856 |
-| TSDB_CODE_QRY_INVALID_MSG | 0 | 0x0701 | "Invalid message" | -2147481855 |
-| TSDB_CODE_QRY_NO_DISKSPACE | 0 | 0x0702 | "No diskspace for query" | -2147481854 |
-| TSDB_CODE_QRY_OUT_OF_MEMORY | 0 | 0x0703 | "System out of memory" | -2147481853 |
-| TSDB_CODE_QRY_APP_ERROR | 0 | 0x0704 | "Unexpected generic error in query" | -2147481852 |
-| TSDB_CODE_QRY_DUP_JOIN_KEY | 0 | 0x0705 | "Duplicated join key" | -2147481851 |
-| TSDB_CODE_QRY_EXCEED_TAGS_LIMIT | 0 | 0x0706 | "Tag conditon too many" | -2147481850 |
-| TSDB_CODE_QRY_NOT_READY | 0 | 0x0707 | "Query not ready" | -2147481849 |
-| TSDB_CODE_QRY_HAS_RSP | 0 | 0x0708 | "Query should response" | -2147481848 |
-| TSDB_CODE_GRANT_EXPIRED | 0 | 0x0800 | "License expired" | -2147481600 |
-| TSDB_CODE_GRANT_DNODE_LIMITED | 0 | 0x0801 | "DNode creation limited by licence" | -2147481599 |
-| TSDB_CODE_GRANT_ACCT_LIMITED | 0 | 0x0802 | "Account creation limited by license" | -2147481598 |
-| TSDB_CODE_GRANT_TIMESERIES_LIMITED | 0 | 0x0803 | "Table creation limited by license" | -2147481597 |
-| TSDB_CODE_GRANT_DB_LIMITED | 0 | 0x0804 | "DB creation limited by license" | -2147481596 |
-| TSDB_CODE_GRANT_USER_LIMITED | 0 | 0x0805 | "User creation limited by license" | -2147481595 |
-| TSDB_CODE_GRANT_CONN_LIMITED | 0 | 0x0806 | "Conn creation limited by license" | -2147481594 |
-| TSDB_CODE_GRANT_STREAM_LIMITED | 0 | 0x0807 | "Stream creation limited by license" | -2147481593 |
-| TSDB_CODE_GRANT_SPEED_LIMITED | 0 | 0x0808 | "Write speed limited by license" | -2147481592 |
-| TSDB_CODE_GRANT_STORAGE_LIMITED | 0 | 0x0809 | "Storage capacity limited by license" | -2147481591 |
-| TSDB_CODE_GRANT_QUERYTIME_LIMITED | 0 | 0x080A | "Query time limited by license" | -2147481590 |
-| TSDB_CODE_GRANT_CPU_LIMITED | 0 | 0x080B | "CPU cores limited by license" | -2147481589 |
-| TSDB_CODE_SYN_INVALID_CONFIG | 0 | 0x0900 | "Invalid Sync Configuration" | -2147481344 |
-| TSDB_CODE_SYN_NOT_ENABLED | 0 | 0x0901 | "Sync module not enabled" | -2147481343 |
-| TSDB_CODE_WAL_APP_ERROR | 0 | 0x1000 | "Unexpected generic error in wal" | -2147479552 |
diff --git a/docs-cn/14-reference/02-restful-api/02-restful-api.mdx b/docs-cn/14-reference/02-rest-api/02-rest-api.mdx
similarity index 92%
rename from docs-cn/14-reference/02-restful-api/02-restful-api.mdx
rename to docs-cn/14-reference/02-rest-api/02-rest-api.mdx
index 6173c3215ac5a5dccc1caa206f89b77d101a6e70..42f93fce0d325eb5c42392bcffb678b113612961 100644
--- a/docs-cn/14-reference/02-restful-api/02-restful-api.mdx
+++ b/docs-cn/14-reference/02-rest-api/02-rest-api.mdx
@@ -1,6 +1,8 @@
-# RESTful API
+---
+title: REST API
+---
-为支持各种不同类型平台的开发,TDengine 提供符合 REST 设计标准的 API,即 RESTful API。为最大程度降低学习成本,不同于其他数据库 RESTful API 的设计方法,TDengine 直接通过 HTTP POST 请求 BODY 中包含的 SQL 语句来操作数据库,仅需要一个 URL。RESTful 连接器的使用参见[视频教程](https://www.taosdata.com/blog/2020/11/11/1965.html)。
+为支持各种不同类型平台的开发,TDengine 提供符合 REST 设计标准的 API,即 REST API。为最大程度降低学习成本,不同于其他数据库 REST API 的设计方法,TDengine 直接通过 HTTP POST 请求 BODY 中包含的 SQL 语句来操作数据库,仅需要一个 URL。REST 连接器的使用参见[视频教程](https://www.taosdata.com/blog/2020/11/11/1965.html)。
注意:与原生连接器的一个区别是,RESTful 接口是无状态的,因此 `USE db_name` 指令没有效果,所有对表名、超级表名的引用都需要指定数据库名前缀。(从 2.2.0.0 版本开始,支持在 RESTful url 中指定 db_name,这时如果 SQL 语句中没有指定数据库名前缀的话,会使用 url 中指定的这个 db_name。从 2.4.0.0 版本开始,RESTful 默认由 taosAdapter 提供,要求必须在 url 中指定 db_name。)
@@ -70,9 +72,7 @@ h1.taosdata.com:6041/rest/sql
}
```
-## RESTful 连接器的使用
-
-### HTTP 请求格式
+## HTTP 请求格式
```
http://:/rest/sql/[db_name]
@@ -292,7 +292,7 @@ HTTP 请求 URL 采用 `sqlutc` 时,返回结果集的时间戳将采用 UTC
## 重要配置项
-下面仅列出一些与 RESTful 接口有关的配置参数,其他系统参数请看配置文件里的说明。(注意:配置修改后,需要重启 taosd 服务才能生效)
+下面仅列出一些与 RESTful 接口有关的配置参数,其他系统参数请看配置文件里的说明。
- 对外提供 RESTful 服务的端口号,默认绑定到 6041(实际取值是 serverPort + 11,因此可以通过修改 serverPort 参数的设置来修改)。
- httpMaxThreads: 启动的线程数量,默认为 2(2.0.17.0 版本开始,默认值改为 CPU 核数的一半向下取整)。
@@ -300,3 +300,8 @@ HTTP 请求 URL 采用 `sqlutc` 时,返回结果集的时间戳将采用 UTC
- httpEnableCompress: 是否支持压缩,默认不支持,目前 TDengine 仅支持 gzip 压缩格式。
- httpDebugFlag: 日志开关,默认 131。131:仅错误和报警信息,135:调试信息,143:非常详细的调试信息,默认 131。
- httpDbNameMandatory: 是否必须在 RESTful url 中指定默认的数据库名。默认为 0,即关闭此检查。如果设置为 1,那么每个 RESTful url 中都必须设置一个默认数据库名,否则无论此时执行的 SQL 语句是否需要指定数据库,都会返回一个执行错误,拒绝执行此 SQL 语句。
+
+:::note
+如果使用 taosd 提供的 REST API, 那么以上配置需要写在 taosd 的配置文件 taos.cfg 中。如果使用 taosAdaper 提供的 REST API, 那么需要参考 taosAdaper [对应的配置方法](/reference/taosadapter/)。
+
+:::
diff --git a/docs-cn/14-reference/02-rest-api/_category_.yml b/docs-cn/14-reference/02-rest-api/_category_.yml
new file mode 100644
index 0000000000000000000000000000000000000000..57a20d8458e937f60c41806be4392ebb2d13e0f7
--- /dev/null
+++ b/docs-cn/14-reference/02-rest-api/_category_.yml
@@ -0,0 +1 @@
+label: REST API
diff --git a/docs-cn/14-reference/02-restful-api/_category_.yml b/docs-cn/14-reference/02-restful-api/_category_.yml
deleted file mode 100644
index 736836846eef118e51ab802811151e26646684e9..0000000000000000000000000000000000000000
--- a/docs-cn/14-reference/02-restful-api/_category_.yml
+++ /dev/null
@@ -1 +0,0 @@
-label: RESTful API
diff --git a/docs-cn/14-reference/03-connector/03-connector.mdx b/docs-cn/14-reference/03-connector/03-connector.mdx
index 2036a591ff1f6f579dfec4e2e014573900d3c21d..c0e714f148a7821e070be38a5484484fdd747e9a 100644
--- a/docs-cn/14-reference/03-connector/03-connector.mdx
+++ b/docs-cn/14-reference/03-connector/03-connector.mdx
@@ -1,55 +1,78 @@
-# 连接器
+---
+title: 连接器
+---
-TDengine 提供了丰富的应用程序开发接口,其中包括 C/C++、Java、Python、Go、Node.js、C# 、RESTful 等,便于用户快速开发应用。
+TDengine 提供了丰富的应用程序开发接口,为了便于用户快速开发自己的应用,TDengine 支持了多种编程语言的连接器,其中官方连接器包括支持 C/C++、Java、Python、Go、Node.js、C# 和 Rust 的连接器。这些连接器支持使用原生接口(taosc)和 REST 接口(部分语言暂不支持)连接 TDengine 集群。社区开发者也贡献了多个非官方连接器,例如 ADO.NET 连接器、Lua 连接器和 PHP 连接器。
-
+
-## 支持的系统
+## 支持的平台
-目前 TDengine 的连接器可支持的平台广泛,包括:X64/X86/ARM64/ARM32/MIPS/Alpha 等硬件平台,以及 Linux/Win64/Win32 等开发环境。对照矩阵如下:
+目前 TDengine 的原生接口连接器可支持的平台包括:X64/X86/ARM64/ARM32/MIPS/Alpha 等硬件平台,以及 Linux/Win64/Win32 等开发环境。对照矩阵如下:
-| **CPU** | **OS** | **JDBC** | **Python** | **Go** | **Node.js** | **C#** | **Rust** | **RESTful** |
-| -------------- | --------- | -------- | ---------- | ------ | ----------- | ------ | -------- | ----------- |
-| **X86 64bit** | **Linux** | ● | ● | ● | ● | ● | ● | ● |
-| **X86 64bit** | **Win64** | ● | ● | ● | ● | ● | ● | ● |
-| **X86 64bit** | **Win32** | ● | ● | ● | ● | ○ | ○ | ● |
-| **X86 32bit** | **Win32** | ○ | ○ | ○ | ○ | ○ | ○ | ● |
-| **ARM64** | **Linux** | ● | ● | ● | ● | ○ | ○ | ● |
-| **ARM32** | **Linux** | ● | ● | ● | ● | ○ | ○ | ● |
-| **MIPS 龙芯** | **Linux** | ○ | ○ | ○ | ○ | ○ | ○ | ○ |
-| **Alpha 申威** | **Linux** | ○ | ○ | -- | -- | -- | -- | ○ |
-| **X86 海光** | **Linux** | ○ | ○ | ○ | -- | -- | -- | ○ |
+| **CPU** | **OS** | **JDBC** | **Python** | **Go** | **Node.js** | **C#** | **Rust** | C/C++ |
+| -------------- | --------- | -------- | ---------- | ------ | ----------- | ------ | -------- | ----- |
+| **X86 64bit** | **Linux** | ● | ● | ● | ● | ● | ● | ● |
+| **X86 64bit** | **Win64** | ● | ● | ● | ● | ● | ● | ● |
+| **X86 64bit** | **Win32** | ● | ● | ● | ● | ○ | ○ | ● |
+| **X86 32bit** | **Win32** | ○ | ○ | ○ | ○ | ○ | ○ | ● |
+| **ARM64** | **Linux** | ● | ● | ● | ● | ○ | ○ | ● |
+| **ARM32** | **Linux** | ● | ● | ● | ● | ○ | ○ | ● |
+| **MIPS 龙芯** | **Linux** | ○ | ○ | ○ | ○ | ○ | ○ | ○ |
+| **Alpha 申威** | **Linux** | ○ | ○ | -- | -- | -- | -- | ○ |
+| **X86 海光** | **Linux** | ○ | ○ | ○ | -- | -- | -- | ○ |
其中 ● 表示官方测试验证通过,○ 表示非官方测试验证通过,-- 表示未经验证。
-## 特性矩阵
+使用 REST 连接由于不依赖客户端驱动可以支持更广泛的操作系统。
-连接器对 TDengine 特性的支持对照矩阵如下[1]:
+## 版本支持
-| **Feature** | **Java** | **Python** | **Go** | **C#** | **Node.js** | **Rust** |
-| ------------------ | --------- | ---------- | -------- | -------- | ----------- | -------- |
-| **连接管理** | 支持 | 支持 | 支持 | 支持 | 支持 | 支持 |
-| **同步查询** | 支持 | 支持 | 支持 | 支持 | 支持 | 支持 |
-| **异步查询** | 不支持[2] | 支持 | 支持 | 支持 | 支持 | 暂不支持 |
-| **参数绑定** | 支持 | 支持 | 支持 | 支持 | 支持 | 支持 |
-| **获取系统信息** | 暂不支持 | 支持 | 暂不支持 | 暂不支持 | 支持 | 暂不支持 |
-| **错误信息** | 支持 | 支持 | 支持 | 支持 | 支持 | 支持 |
-| **订阅功能** | 支持 | 支持 | 支持 | 支持 | 支持 | 暂不支持 |
-| **Schemaless** | 支持 | 支持 | 支持 | 支持 | 支持 | 支持 |
-| **RESTful 连接** | 支持 | 支持 | 支持 | 暂不支持 | 支持 | 支持 |
-| **批量拉取(WS)** | 支持 | 暂不支持 | 暂不支持 | 暂不支持 | 暂不支持 | 暂不支持 |
+TDengine 版本更新往往会增加新的功能特性,列表中的连接器版本为连接器最佳适配版本。
-备注:
+| **TDengine 版本** | **Java** | **Python** | **Go** | **C#** | **Node.js** | **Rust** |
+| --------------------- | -------- | ---------- | ------------ | ------------- | --------------- | -------- |
+| **2.4.0.14 及以上** | 2.0.38 | 当前版本 | develop 分支 | 1.0.2 - 1.0.6 | 2.0.10 - 2.0.12 | 当前版本 |
+| **2.4.0.6 及以上** | 2.0.37 | 当前版本 | develop 分支 | 1.0.2 - 1.0.6 | 2.0.10 - 2.0.12 | 当前版本 |
+| **2.4.0.4 - 2.4.0.5** | 2.0.37 | 当前版本 | develop 分支 | 1.0.2 - 1.0.6 | 2.0.10 - 2.0.12 | 当前版本 |
+| **2.2.x.x ** | 2.0.36 | 当前版本 | master 分支 | n/a | 2.0.7 - 2.0.9 | 当前版本 |
+| **2.0.x.x ** | 2.0.34 | 当前版本 | master 分支 | n/a | 2.0.1 - 2.0.6 | 当前版本 |
-[1]: 由于不同语言数据库框架规范不同,并不意味着所有 C/C++ 接口都需要对应支持。
+## 功能特性
-[2]: JDBC 标准为同步查询。
+连接器对 TDengine 功能特性的支持对照如下:
+
+### 使用原生接口(taosc)
+
+| **功能特性** | **Java** | **Python** | **Go** | **C#** | **Node.js** | **Rust** |
+| -------------- | -------- | ---------- | ------ | ------ | ----------- | -------- |
+| **连接管理** | 支持 | 支持 | 支持 | 支持 | 支持 | 支持 |
+| **普通查询** | 支持 | 支持 | 支持 | 支持 | 支持 | 支持 |
+| **连续查询** | 支持 | 支持 | 支持 | 支持 | 支持 | 支持 |
+| **参数绑定** | 支持 | 支持 | 支持 | 支持 | 支持 | 支持 |
+| **订阅功能** | 支持 | 支持 | 支持 | 支持 | 支持 | 暂不支持 |
+| **Schemaless** | 支持 | 支持 | 支持 | 支持 | 支持 | 支持 |
+| **DataFrame** | 不支持 | 支持 | 不支持 | 不支持 | 不支持 | 不支持 |
+
+:::info
+由于不同编程语言数据库框架规范不同,并不意味着所有 C/C++ 接口都需要对应封装支持。
+:::
+
+### 使用 REST 接口
+
+| **功能特性** | **Java** | **Python** | **Go** | **C#(暂不支持)** | **Node.js** | **Rust** |
+| ------------------------------ | -------- | ---------- | -------- | ------------------ | ----------- | -------- |
+| **连接管理** | 支持 | 支持 | 支持 | N/A | 支持 | 支持 |
+| **普通查询** | 支持 | 支持 | 支持 | N/A | 支持 | 支持 |
+| **连续查询** | 支持 | 支持 | 支持 | N/A | 支持 | 支持 |
+| **参数绑定** | 不支持 | 不支持 | 不支持 | N/A | 不支持 | 不支持 |
+| **订阅功能** | 不支持 | 不支持 | 不支持 | N/A | 不支持 | 不支持 |
+| **Schemaless** | 暂不支持 | 暂不支持 | 暂不支持 | N/A | 暂不支持 | 暂不支持 |
+| **批量拉取(基于 WebSocket)** | 支持 | 暂不支持 | 暂不支持 | N/A | 暂不支持 | 暂不支持 |
+| **DataFrame** | 不支持 | 支持 | 不支持 | N/A | 不支持 | 不支持 |
:::warning
-- 在没有安装 TDengine 服务端软件的系统中使用连接器(除 RESTful 外)访问 TDengine 数据库,需要安装相应版本的客户端安装包来使应用驱动(Linux 系统中文件名为 libtaos.so,Windows 系统中为 taos.dll)被安装在系统中,否则会产生无法找到相应库文件的错误。
-- 所有执行 SQL 语句的 API,例如 C/C++ Connector 中的 `tao_query`、`taos_query_a`、`taos_subscribe` 等,以及其它语言中与它们对应的 API,每次都只能执行一条 SQL 语句,如果实际参数中包含了多条语句,它们的行为是未定义的。
-- 升级 TDengine 到 2.0.8.0 版本的用户,必须更新 JDBC。连接 TDengine 必须升级 taos-jdbcdriver 到 2.0.12 及以上。详细的版本依赖关系请参见 [taos-jdbcdriver 文档](https://www.taosdata.com/cn/documentation/connector/java#version)。
- 无论选用何种编程语言的连接器,2.0 及以上版本的 TDengine 推荐数据库应用的每个线程都建立一个独立的连接,或基于线程建立连接池,以避免连接内的“USE statement”状态量在线程之间相互干扰(但连接的查询和写入操作都是线程安全的)。
:::
@@ -58,13 +81,13 @@ import Tabs from "@theme/Tabs";
import TabItem from "@theme/TabItem";
import InstallOnWindows from "./_linux_install.mdx";
import InstallOnLinux from "./_windows_install.mdx";
-import VarifyWindows from "./_varify_linux.mdx";
-import VarifyLinux from "./_varify_windows.mdx";
+import VerifyWindows from "./_verify_windows.mdx";
+import VerifyLinux from "./_verify_linux.mdx";
## 安装客户端驱动
:::info
-只有在没有安装 TDengine 服务端软件的系统上使用非 RESTFful 连接器才需要安装客户端驱动。
+只有在没有安装 TDengine 服务端软件的系统上使用原生接口连接器才需要安装客户端驱动。
:::
@@ -81,13 +104,14 @@ import VarifyLinux from "./_varify_windows.mdx";
### 安装验证
-以上安装和配置完成后,并确认 TDengine 服务已经正常启动运行,此时可以执行 taos 客户端进行登录。
+以上安装和配置完成后,并确认 TDengine 服务已经正常启动运行,此时可以执行 TDengine CLI 工具进行登录。
-
+
-
+
+
diff --git a/docs-cn/14-reference/03-connector/_linux_install.mdx b/docs-cn/14-reference/03-connector/_linux_install.mdx
index 21dacdfdb8f64364bb7aae0567a424bc98e2ef96..be363395cb6340a00ea0e51a0facc57a0340b301 100644
--- a/docs-cn/14-reference/03-connector/_linux_install.mdx
+++ b/docs-cn/14-reference/03-connector/_linux_install.mdx
@@ -4,24 +4,23 @@
- ARM32 硬件环境:TDengine-client-2.x.x.x-Linux-aarch32.tar.gz
2. 解压缩软件包
- 将软件包放置在当前用户可读写的任意目录下,然后执行下面的命令:`tar -xzvf TDengine-client-xxxxxxxxx.tar.gz`
- 其中 xxxxxxxxx 需要替换为实际版本的字符串。
+ 将软件包放置在当前用户可读写的任意目录下,然后执行下面的命令:`tar -xzvf TDengine-client-VERSION.tar.gz`
+ 其中 VERSION 需要替换为实际版本的字符串。
3. 执行安装脚本
解压软件包之后,会在解压目录下看到以下文件(目录):
- - _ install_client.sh_:安装脚本,用于应用驱动程序
- - _ taos.tar.gz_:应用驱动安装包
- - _ driver_:TDengine 应用驱动 driver
- - _connector_: 各种编程语言连接器(go/nodejs/python/JDBC)
- - _examples_: 各种编程语言的示例程序(c/C#/go/JDBC/MATLAB/python/R)
+ - _ install_client.sh_:安装脚本,用于应用驱动程序
+ - _ taos.tar.gz_:应用驱动安装包
+ - _ driver_:TDengine 应用驱动 driver
+ - _examples_: 各种编程语言的示例程序(c/C#/go/JDBC/MATLAB/python/R)
运行 install_client.sh 进行安装。
4. 配置 taos.cfg
- 编辑 taos.cfg 文件(默认路径/etc/taos/taos.cfg),将 firstEP 修改为 TDengine 服务器的 End Point,例如:`h1.taos.com:6030`
+ 编辑 taos.cfg 文件(默认路径/etc/taos/taos.cfg),将 firstEP 修改为 TDengine 服务器的 End Point,例如:`h1.tdengine.com:6030`
:::tip
-1. 如本机没有部署 TDengine 服务,仅安装了应用驱动,则 taos.cfg 中仅需配置 firstEP,无需配置 FQDN。
-2. 为防止与服务器端连接时出现“unable to resolve FQDN”错误,建议确认客户端的 hosts 文件已经配置正确的 FQDN 值。
+1. 如本机没有部署 TDengine 服务,仅安装了应用驱动,则 taos.cfg 中仅需配置 firstEP,无需在本机配置 FQDN。
+2. 为防止与服务器端连接时出现“Unable to resolve FQDN”错误,建议确认本机的 hosts 文件已经配置了服务器正确的 FQDN 值,或配置好了 DNS 服务。
:::
diff --git a/docs-cn/14-reference/03-connector/_preparition.mdx b/docs-cn/14-reference/03-connector/_preparition.mdx
new file mode 100644
index 0000000000000000000000000000000000000000..87538ebfd8c60507aec90ee86e427d85979dbc4a
--- /dev/null
+++ b/docs-cn/14-reference/03-connector/_preparition.mdx
@@ -0,0 +1,10 @@
+- 已安装客户端驱动(使用原生连接必须安装,使用 REST 连接无需安装)
+
+:::info
+
+由于 TDengine 的客户端驱动使用 C 语言编写,使用原生连接时需要加载系统对应安装在本地的客户端驱动共享库文件,通常包含在 TDengine 安装包。TDengine Linux 服务端安装包附带了 TDengine 客户端,也可以单独安装 [Linux 客户端](/get-started/) 。在 Windows 环境开发时需要安装 TDengine 对应的 [Windows 客户端](https://www.taosdata.com/cn/all-downloads/#TDengine-Windows-Client) 。
+
+- libtaos.so: 在 Linux 系统中成功安装 TDengine 后,依赖的 Linux 版客户端驱动 libtaos.so 文件会被自动拷贝至 /usr/lib/libtaos.so,该目录包含在 Linux 自动扫描路径上,无需单独指定。
+- taos.dll: 在 Windows 系统中安装完客户端之后,依赖的 Windows 版客户端驱动 taos.dll 文件会自动拷贝到系统默认搜索路径 C:/Windows/System32 下,同样无需要单独指定。
+
+:::
diff --git a/docs-cn/14-reference/03-connector/_varify_linux.mdx b/docs-cn/14-reference/03-connector/_verify_linux.mdx
similarity index 87%
rename from docs-cn/14-reference/03-connector/_varify_linux.mdx
rename to docs-cn/14-reference/03-connector/_verify_linux.mdx
index 8c355560d7750cac8eea9c6f72f7b24a398ac274..84839f8e94fe68a709238b608ddd487afaaa97b1 100644
--- a/docs-cn/14-reference/03-connector/_varify_linux.mdx
+++ b/docs-cn/14-reference/03-connector/_verify_linux.mdx
@@ -1,14 +1,14 @@
-在 Linux shell 下直接执行 taos,应该就能正常连接到 TDegine 服务,进入到 taos shell 界面,示例如下:
-
-```mysql
-$ taos
-Welcome to the TDengine shell from Linux, Client Version:2.0.5.0
-Copyright (c) 2017 by TAOS Data, Inc. All rights reserved.
-taos> show databases;
-name | created_time | ntables | vgroups | replica | quorum | days | keep1,keep2,keep(D) | cache(MB)| blocks | minrows | maxrows | wallevel | fsync | comp | precision | status |
-=========================================================================================================================================================================================================================
-test | 2020-10-14 10:35:48.617 | 10 | 1 | 1 | 1 | 2 | 3650,3650,3650 | 16| 6 | 100 | 4096 | 1 | 3000 | 2 | ms | ready |
-log | 2020-10-12 09:08:21.651 | 4 | 1 | 1 | 1 | 10 | 30,30,30 | 1| 3 | 100 | 4096 | 1 | 3000 | 2 | us | ready |
-Query OK, 2 row(s) in set (0.001198s)
-taos>
-```
+在 Linux shell 下直接执行 `taos` 连接到 TDegine 服务,进入到 TDengine CLI 界面,示例如下:
+
+```text
+$ taos
+Welcome to the TDengine shell from Linux, Client Version:2.0.5.0
+Copyright (c) 2017 by TAOS Data, Inc. All rights reserved.
+taos> show databases;
+name | created_time | ntables | vgroups | replica | quorum | days | keep1,keep2,keep(D) | cache(MB)| blocks | minrows | maxrows | wallevel | fsync | comp | precision | status |
+=========================================================================================================================================================================================================================
+test | 2020-10-14 10:35:48.617 | 10 | 1 | 1 | 1 | 2 | 3650,3650,3650 | 16| 6 | 100 | 4096 | 1 | 3000 | 2 | ms | ready |
+log | 2020-10-12 09:08:21.651 | 4 | 1 | 1 | 1 | 10 | 30,30,30 | 1| 3 | 100 | 4096 | 1 | 3000 | 2 | us | ready |
+Query OK, 2 row(s) in set (0.001198s)
+taos>
+```
diff --git a/docs-cn/14-reference/03-connector/_varify_windows.mdx b/docs-cn/14-reference/03-connector/_verify_windows.mdx
similarity index 86%
rename from docs-cn/14-reference/03-connector/_varify_windows.mdx
rename to docs-cn/14-reference/03-connector/_verify_windows.mdx
index 9383ed2b23e70c5321c52dc67e5686e5afe23c4c..19ac71ec310ea18eb8dacde6dfa34f3bcd57f560 100644
--- a/docs-cn/14-reference/03-connector/_varify_windows.mdx
+++ b/docs-cn/14-reference/03-connector/_verify_windows.mdx
@@ -1,14 +1,14 @@
-在 cmd 下进入到 c:\TDengine 目录下直接执行 taos.exe,应该就能正常链接到 tdegine 服务,进入到 taos shell 界面,示例如下:
-
-```mysql
- C:\TDengine>taos
- Welcome to the TDengine shell from Linux, Client Version:2.0.5.0
- Copyright (c) 2017 by TAOS Data, Inc. All rights reserved.
- taos> show databases;
- name | created_time | ntables | vgroups | replica | quorum | days | keep1,keep2,keep(D) | cache(MB) | blocks | minrows | maxrows | wallevel | fsync | comp | precision | status |
- ===================================================================================================================================================================================================================================================================
- test | 2020-10-14 10:35:48.617 | 10 | 1 | 1 | 1 | 2 | 3650,3650,3650 | 16 | 6 | 100 | 4096 | 1 | 3000 | 2 | ms | ready |
- log | 2020-10-12 09:08:21.651 | 4 | 1 | 1 | 1 | 10 | 30,30,30 | 1 | 3 | 100 | 4096 | 1 | 3000 | 2 | us | ready |
- Query OK, 2 row(s) in set (0.045000s)
- taos>
-```
\ No newline at end of file
+在 cmd 下进入到 C:\TDengine 目录下直接执行 `taos.exe`,连接到 TDengine 服务,进入到 TDengine CLI 界面,示例如下:
+
+```text
+ C:\TDengine>taos
+ Welcome to the TDengine shell from Linux, Client Version:2.0.5.0
+ Copyright (c) 2017 by TAOS Data, Inc. All rights reserved.
+ taos> show databases;
+ name | created_time | ntables | vgroups | replica | quorum | days | keep1,keep2,keep(D) | cache(MB) | blocks | minrows | maxrows | wallevel | fsync | comp | precision | status |
+ ===================================================================================================================================================================================================================================================================
+ test | 2020-10-14 10:35:48.617 | 10 | 1 | 1 | 1 | 2 | 3650,3650,3650 | 16 | 6 | 100 | 4096 | 1 | 3000 | 2 | ms | ready |
+ log | 2020-10-12 09:08:21.651 | 4 | 1 | 1 | 1 | 10 | 30,30,30 | 1 | 3 | 100 | 4096 | 1 | 3000 | 2 | us | ready |
+ Query OK, 2 row(s) in set (0.045000s)
+ taos>
+```
diff --git a/docs-cn/14-reference/03-connector/_windows_install.mdx b/docs-cn/14-reference/03-connector/_windows_install.mdx
index 67b04607172d5cd6e00b44d21b60c2c1a28d738a..ac7d5bfc0a9bdcfba7fa66258a4fdf097f1629b5 100644
--- a/docs-cn/14-reference/03-connector/_windows_install.mdx
+++ b/docs-cn/14-reference/03-connector/_windows_install.mdx
@@ -6,7 +6,7 @@
默认安装路径为:C:\TDengine,其中包括以下文件(目录):
- - _taos.exe_:taos shell 命令行程序
+ - _taos.exe_:TDengine CLI 命令行程序
- _cfg_ : 配置文件目录
- _driver_: 应用驱动动态链接库
- _examples_: 示例程序 bash/C/C#/go/JDBC/Python/Node.js
@@ -16,11 +16,11 @@
4. 配置 taos.cfg
- 编辑 taos.cfg 文件(默认路径 C:\TDengine\cfg\taos.cfg),将 firstEP 修改为 TDengine 服务器的 End Point,例如:`h1.taos.com:6030`。
+ 编辑 taos.cfg 文件(默认路径 C:\TDengine\cfg\taos.cfg),将 firstEP 修改为 TDengine 服务器的 End Point,例如:`h1.tdengine.com:6030`。
:::tip
-1. 如利用 FQDN 连接服务器,必须确认本机网络环境 DNS 已配置好,或在 hosts 文件中添加 FQDN 寻址记录,如编辑 C:\Windows\system32\drivers\etc\hosts,添加如下的记录:`192.168.1.99 h1.taos.com`
+1. 如利用 FQDN 连接服务器,必须确认本机网络环境 DNS 已配置好,或在 hosts 文件中添加 FQDN 寻址记录, 如编辑 C:\Windows\system32\drivers\etc\hosts,添加类似如下的记录:`192.168.1.99 h1.taos.com`
2. 卸载:运行 unins000.exe 可卸载 TDengine 应用驱动。
:::
diff --git a/docs-cn/14-reference/03-connector/cpp.mdx b/docs-cn/14-reference/03-connector/cpp.mdx
index a10fe7ef4c9e61e1207cc324b53423702a3afbe7..29aebaed3d8ca852950508ba751b8c86689724ca 100644
--- a/docs-cn/14-reference/03-connector/cpp.mdx
+++ b/docs-cn/14-reference/03-connector/cpp.mdx
@@ -1,44 +1,134 @@
---
sidebar_position: 1
+sidebar_label: C/C++
+title: C/C++ Connector
---
-# C/C++ Connector
+C/C++ 开发人员可以使用 TDengine 的客户端驱动,即 C/C++连接器 (以下都用 TDengine 客户端驱动表示),开发自己的应用来连接 TDengine 集群完成数据存储、查询以及其他功能。TDengine 客户端驱动的 API 类似于 MySQL 的 C API。应用程序使用时,需要包含 TDengine 头文件 _taos.h_,里面列出了提供的 API 的函数原型;应用程序还要链接到所在平台上对应的动态库。
-**C/C++连接器支持的系统有**:
-
-| **CPU 类型** | x64(64bit) | | | ARM64 | ARM32 |
-| ------------ | ------------ | -------- | -------- | -------- | -------- |
-| **OS 类型** | Linux | Win64 | Win32 | Linux | Linux |
-| **支持与否** | **支持** | **支持** | **支持** | **支持** | **支持** |
+```c
+#include
+```
-C/C++的 API 类似于 MySQL 的 C API。应用程序使用时,需要包含 TDengine 头文件 _taos.h_,里面列出了提供的 API 的函数原型。安装后,taos.h 位于:
+TDengine 服务端或客户端安装后,`taos.h` 位于:
- Linux:`/usr/local/taos/include`
- Windows:`C:\TDengine\include`
-```C
-#include
+TDengine 客户端驱动的动态库位于:
+
+- Linux: `/usr/local/taos/driver/libtaos.so`
+- Windows: `C:\TDengine\taos.dll`
+
+## 支持的平台
+
+请参考[支持的平台列表](/reference/connector#支持的平台)
+
+## 支持的版本
+
+TDengine 客户端驱动的版本号与 TDengine 服务端的版本号是一一对应的强对应关系,建议使用与 TDengine 服务端完全相同的客户端驱动。虽然低版本的客户端驱动在前三段版本号一致(即仅第四段版本号不同)的情况下也能够与高版本的服务端相兼容,但这并非推荐用法。强烈不建议使用高版本的客户端驱动访问低版本的服务端。
+
+## 安装步骤
+
+TDengine 客户端驱动的安装请参考 [安装指南](/reference/connector#安装步骤)
+
+## 建立连接
+
+使用客户端驱动访问 TDengine 集群的基本过程为:建立连接、查询和写入、关闭连接、清除资源。
+
+下面为建立连接的示例代码,其中省略了查询和写入部分,展示了如何建立连接、关闭连接以及清除资源。
+
+```c
+ TAOS *taos = taos_connect("localhost:6030", "root", "taosdata", NULL, 0);
+ if (taos == NULL) {
+ printf("failed to connect to server, reason:%s\n", "null taos" /*taos_errstr(taos)*/);
+ exit(1);
+ }
+
+ /* put your code here for read and write */
+
+ taos_close(taos);
+ taos_cleanup();
```
-注意:
+在上面的示例代码中, `taos_connect` 建立到客户端程序所在主机的 6030 端口的连接,`taos_close`关闭当前连接,`taos_cleanup`清除客户端驱动所申请和使用的资源。
+
+:::note
-- 在编译时需要链接 TDengine 动态库。Linux 为 _libtaos.so_ ,安装后,位于 _/usr/local/taos/driver_。Windows 为 taos.dll,安装后位于 _C:\TDengine_。
- 如未特别说明,当 API 的返回值是整数时,_0_ 代表成功,其它是代表失败原因的错误码,当返回值是指针时, _NULL_ 表示失败。
-- 在 taoserror.h 中有所有的错误码,以及对应的原因描述。
+- 所有的错误码以及对应的原因描述在 taoserror.h 文件中。
+
+:::
+
+## 示例程序
+
+本节展示了使用客户端驱动访问 TDengine 集群的常见访问方式的示例代码。
+
+### 同步查询示例
+
+
+同步查询
+
+```c
+{{#include examples/c/demo.c}}
+```
+
+
+
+### 异步查询示例
+
+
+异步查询
+
+```c
+{{#include examples/c/asyncdemo.c}}
+```
+
+
-### 示例程序
+### 参数绑定示例
-使用 C/C++连接器的示例代码请参见 https://github.com/taosdata/TDengine/tree/develop/examples/c 。
+
+参数绑定
-示例程序源码也可以在安装目录下的 examples/c 路径下找到:
+```c
+{{#include examples/c/prepare.c}}
+```
+
+
+
+### 无模式写入示例
+
+
+无模式写入
-**apitest.c、asyncdemo.c、demo.c、prepare.c、stream.c、subscribe.c**
+```c
+{{#include examples/c/schemaless.c}}
+```
+
+
-该目录下有 makefile,在 Linux 环境下,直接执行 make 就可以编译得到执行文件。
+### 订阅和消费示例
-在一台机器上启动 TDengine 服务,执行这些示例程序,按照提示输入 TDengine 服务的 FQDN,就可以正常运行,并打印出信息。
+
+订阅和消费
-**提示:**在 ARM 环境下编译时,请将 makefile 中的-msse4.2 打开,这个选项只有在 x64/x86 硬件平台上才能支持。
+```c
+{{#include examples/c/subscribe.c}}
+```
+
+
+
+:::info
+更多示例代码及下载请见 [github](https://github.com/taosdata/TDengine/tree/develop/examples/c)
+也可以在安装目录下的 examples/c 路径下找到。 该目录下有 makefile,在 Linux 环境下,直接执行 make 就可以编译得到执行文件。
+**提示:**在 ARM 环境下编译时,请将 makefile 中的 `-msse4.2` 去掉,这个选项只有在 x64/x86 硬件平台上才能支持。
+
+:::
+
+## API 参考
+
+以下分别介绍 TDengine 客户端驱动的基础 API、同步 API、异步 API、订阅 API 和无模式写入 API。
### 基础 API
@@ -46,7 +136,7 @@ C/C++的 API 类似于 MySQL 的 C API。应用程序使用时,需要包含 TD
- `void taos_init()`
- 初始化运行环境。如果应用没有主动调用该 API,那么应用在调用`taos_connect`时将自动调用,故应用程序一般无需手动调用该 API。
+ 初始化运行环境。如果应用没有主动调用该 API,那么应用在调用 `taos_connect()` 时将自动调用,故应用程序一般无需手动调用该 API。
- `void taos_cleanup()`
@@ -72,7 +162,10 @@ C/C++的 API 类似于 MySQL 的 C API。应用程序使用时,需要包含 TD
返回值为空表示失败。应用程序需要保存返回的参数,以便后续 API 调用。
- **提示:** 同一进程可以根据不同的 host/port 连接多个 taosd 集群
+ :::info
+ 同一进程可以根据不同的 host/port 连接多个 TDengine 集群
+
+ :::
- `char *taos_get_server_info(TAOS *taos)`
@@ -80,19 +173,19 @@ C/C++的 API 类似于 MySQL 的 C API。应用程序使用时,需要包含 TD
- `int taos_select_db(TAOS *taos, const char *db)`
- 将当前的缺省数据库设置为`db`。
+ 将当前的缺省数据库设置为 `db`。
- `void taos_close(TAOS *taos)`
- 关闭连接,其中`taos`是`taos_connect`函数返回的指针。
+ 关闭连接,其中`taos`是 `taos_connect()` 函数返回的指针。
### 同步查询 API
-传统的数据库操作 API,都属于同步操作。应用调用 API 后,一直处于阻塞状态,直到服务器返回结果。TDengine 支持如下 API:
+传统的数据库操作 API,都属于同步操作。应用调用 API 后,一直处于阻塞状态,直到服务端返回结果。
- `TAOS_RES* taos_query(TAOS *taos, const char *sql)`
- 该 API 用来执行 SQL 语句,可以是 DQL、DML 或 DDL 语句。 其中的`taos`参数是通过`taos_connect`获得的指针。不能通过返回值是否是 NULL 来判断执行结果是否失败,而是需要用`taos_errno`函数解析结果集中的错误代码来进行判断。
+ 该 API 用来执行 SQL 语句,可以是 DQL、DML 或 DDL 语句。 其中的 `taos` 参数是通过 `taos_connect()` 获得的指针。不能通过返回值是否是 `NULL` 来判断执行结果是否失败,而是需要用 `taos_errno()` 函数解析结果集中的错误代码来进行判断。
- `int taos_result_precision(TAOS_RES *res)`
@@ -112,7 +205,7 @@ C/C++的 API 类似于 MySQL 的 C API。应用程序使用时,需要包含 TD
- `int* taos_fetch_lengths(TAOS_RES *res)`
- 获取结果集中每个字段的长度。 返回值是一个数组,其长度为结果集的列数。
+ 获取结果集中每个字段的长度。返回值是一个数组,其长度为结果集的列数。
- `int taos_affected_rows(TAOS_RES *res)`
@@ -120,13 +213,13 @@ C/C++的 API 类似于 MySQL 的 C API。应用程序使用时,需要包含 TD
- `TAOS_FIELD *taos_fetch_fields(TAOS_RES *res)`
- 获取查询结果集每列数据的属性(列的名称、列的数据类型、列的长度),与 taos_num_fileds 配合使用,可用来解析`taos_fetch_row`返回的一个元组(一行)的数据。 `TAOS_FIELD` 的结构如下:
+ 获取查询结果集每列数据的属性(列的名称、列的数据类型、列的长度),与 `taos_num_fileds()` 配合使用,可用来解析 `taos_fetch_row()` 返回的一个元组(一行)的数据。 `TAOS_FIELD` 的结构如下:
```c
typedef struct taosField {
- char name[65]; // 列名
- uint8_t type; // 数据类型
- int16_t bytes; // 长度,单位是字节
+ char name[65]; // column name
+ uint8_t type; // data type
+ int16_t bytes; // length, in bytes
} TAOS_FIELD;
```
@@ -136,7 +229,7 @@ typedef struct taosField {
- `void taos_free_result(TAOS_RES *res)`
- 释放查询结果集以及相关的资源。查询完成后,务必调用该 API 释放资源,否则可能导致应用内存泄露。但也需注意,释放资源后,如果再调用`taos_consume`等获取查询结果的函数,将导致应用 Crash。
+ 释放查询结果集以及相关的资源。查询完成后,务必调用该 API 释放资源,否则可能导致应用内存泄露。但也需注意,释放资源后,如果再调用 `taos_consume()` 等获取查询结果的函数,将导致应用崩溃。
- `char *taos_errstr(TAOS_RES *res)`
@@ -146,7 +239,10 @@ typedef struct taosField {
获取最近一次 API 调用失败的原因,返回值为错误代码。
-**注意**:2.0 及以上版本 TDengine 推荐数据库应用的每个线程都建立一个独立的连接,或基于线程建立连接池。而不推荐在应用中将该连接 (TAOS\*) 结构体传递到不同的线程共享使用。基于 TAOS 结构体发出的查询、写入等操作具有多线程安全性,但 “USE statement” 等状态量有可能在线程之间相互干扰。此外,C 语言的连接器可以按照需求动态建立面向数据库的新连接(该过程对用户不可见),同时建议只有在程序最后退出的时候才调用 taos_close 关闭连接。
+:::note
+2.0 及以上版本 TDengine 推荐数据库应用的每个线程都建立一个独立的连接,或基于线程建立连接池。而不推荐在应用中将该连接 (TAOS\*) 结构体传递到不同的线程共享使用。基于 TAOS 结构体发出的查询、写入等操作具有多线程安全性,但 “USE statement” 等状态量有可能在线程之间相互干扰。此外,C 语言的连接器可以按照需求动态建立面向数据库的新连接(该过程对用户不可见),同时建议只有在程序最后退出的时候才调用 `taos_close()` 关闭连接。
+
+:::
### 异步查询 API
@@ -160,40 +256,37 @@ typedef struct taosField {
异步执行 SQL 语句。
- - taos:调用 taos_connect 返回的数据库连接
+ - taos:调用 `taos_connect()` 返回的数据库连接
- sql:需要执行的 SQL 语句
- - fp:用户定义的回调函数,其第三个参数`code`用于指示操作是否成功,`0`表示成功,负数表示失败(调用`taos_errstr`获取失败原因)。应用在定义回调函数的时候,主要处理第二个参数`TAOS_RES *`,该参数是查询返回的结果集
+ - fp:用户定义的回调函数,其第三个参数 `code` 用于指示操作是否成功,`0` 表示成功,负数表示失败(调用 `taos_errstr()` 可获取失败原因)。应用在定义回调函数的时候,主要处理第二个参数 `TAOS_RES *`,该参数是查询返回的结果集
- param:应用提供一个用于回调的参数
- `void taos_fetch_rows_a(TAOS_RES *res, void (*fp)(void *param, TAOS_RES *, int numOfRows), void *param);`
- 批量获取异步查询的结果集,只能与`taos_query_a`配合使用。其中:
+ 批量获取异步查询的结果集,只能与 `taos_query_a()` 配合使用。其中:
- - res:`taos_query_a`回调时返回的结果集
- - fp:回调函数。其参数`param`是用户可定义的传递给回调函数的参数结构体;`numOfRows`是获取到的数据的行数(不是整个查询结果集的函数)。 在回调函数中,应用可以通过调用`taos_fetch_row`前向迭代获取批量记录中每一行记录。读完一块内的所有记录后,应用需要在回调函数中继续调用`taos_fetch_rows_a`获取下一批记录进行处理,直到返回的记录数(numOfRows)为零(结果返回完成)或记录数为负值(查询出错)。
+ - res:`taos_query_a()` 回调时返回的结果集
+ - fp:回调函数。其参数 `param` 是用户可定义的传递给回调函数的参数结构体;`numOfRows` 是获取到的数据的行数(不是整个查询结果集的函数)。 在回调函数中,应用可以通过调用 `taos_fetch_row()` 前向迭代获取批量记录中每一行记录。读完一块内的所有记录后,应用需要在回调函数中继续调用 `taos_fetch_rows_a()` 获取下一批记录进行处理,直到返回的记录数 `numOfRows` 为零(结果返回完成)或记录数为负值(查询出错)。
TDengine 的异步 API 均采用非阻塞调用模式。应用程序可以用多线程同时打开多张表,并可以同时对每张打开的表进行查询或者插入操作。需要指出的是,**客户端应用必须确保对同一张表的操作完全串行化**,即对同一个表的插入或查询操作未完成时(未返回时),不能够执行第二个插入或查询操作。
-
### 参数绑定 API
-除了直接调用 `taos_query` 进行查询,TDengine 也提供了支持参数绑定的 Prepare API,与 MySQL 一样,这些 API 目前也仅支持用问号 `?` 来代表待绑定的参数。文档中有时也会把此功能称为“原生接口写入”。
+除了直接调用 `taos_query()` 进行查询,TDengine 也提供了支持参数绑定的 Prepare API,风格与 MySQL 类似,目前也仅支持用问号 `?` 来代表待绑定的参数。
从 2.1.1.0 和 2.1.2.0 版本开始,TDengine 大幅改进了参数绑定接口对数据写入(INSERT)场景的支持。这样在通过参数绑定接口写入数据时,就避免了 SQL 语法解析的资源消耗,从而在绝大多数情况下显著提升写入性能。此时的典型操作步骤如下:
-1. 调用 `taos_stmt_init` 创建参数绑定对象;
-2. 调用 `taos_stmt_prepare` 解析 INSERT 语句;
-3. 如果 INSERT 语句中预留了表名但没有预留 TAGS,那么调用 `taos_stmt_set_tbname` 来设置表名;
-4. 如果 INSERT 语句中既预留了表名又预留了 TAGS(例如 INSERT 语句采取的是自动建表的方式),那么调用 `taos_stmt_set_tbname_tags` 来设置表名和 TAGS 的值;
-5. 调用 `taos_stmt_bind_param_batch` 以多列的方式设置 VALUES 的值,或者调用 `taos_stmt_bind_param` 以单行的方式设置 VALUES 的值;
-6. 调用 `taos_stmt_add_batch` 把当前绑定的参数加入批处理;
+1. 调用 `taos_stmt_init()` 创建参数绑定对象;
+2. 调用 `taos_stmt_prepare()` 解析 INSERT 语句;
+3. 如果 INSERT 语句中预留了表名但没有预留 TAGS,那么调用 `taos_stmt_set_tbname()` 来设置表名;
+4. 如果 INSERT 语句中既预留了表名又预留了 TAGS(例如 INSERT 语句采取的是自动建表的方式),那么调用 `taos_stmt_set_tbname_tags()` 来设置表名和 TAGS 的值;
+5. 调用 `taos_stmt_bind_param_batch()` 以多列的方式设置 VALUES 的值,或者调用 `taos_stmt_bind_param()` 以单行的方式设置 VALUES 的值;
+6. 调用 `taos_stmt_add_batch()` 把当前绑定的参数加入批处理;
7. 可以重复第 3 ~ 6 步,为批处理加入更多的数据行;
-8. 调用 `taos_stmt_execute` 执行已经准备好的批处理指令;
-9. 执行完毕,调用 `taos_stmt_close` 释放所有资源。
+8. 调用 `taos_stmt_execute()` 执行已经准备好的批处理指令;
+9. 执行完毕,调用 `taos_stmt_close()` 释放所有资源。
-说明:如果 `taos_stmt_execute` 执行成功,假如不需要改变 SQL 语句的话,那么是可以复用 `taos_stmt_prepare` 的解析结果,直接进行第 3 ~ 6 步绑定新数据的。但如果执行出错,那么并不建议继续在当前的环境上下文下继续工作,而是建议释放资源,然后从 `taos_stmt_init` 步骤重新开始。
-
-除 C/C++ 语言外,TDengine 的 Java 语言 JNI Connector 也提供参数绑定接口支持,具体请另外参见:[参数绑定接口的 Java 用法](https://www.taosdata.com/cn/documentation/connector/java#stmt-java)。
+说明:如果 `taos_stmt_execute()` 执行成功,假如不需要改变 SQL 语句的话,那么是可以复用 `taos_stmt_prepare()` 的解析结果,直接进行第 3 ~ 6 步绑定新数据的。但如果执行出错,那么并不建议继续在当前的环境上下文下继续工作,而是建议释放资源,然后从 `taos_stmt_init()` 步骤重新开始。
接口相关的具体函数如下(也可以参考 [prepare.c](https://github.com/taosdata/TDengine/blob/develop/examples/c/prepare.c) 文件中使用对应函数的方式):
@@ -207,50 +300,50 @@ TDengine 的异步 API 均采用非阻塞调用模式。应用程序可以用多
- `int taos_stmt_bind_param(TAOS_STMT *stmt, TAOS_BIND *bind)`
- 不如 `taos_stmt_bind_param_batch` 效率高,但可以支持非 INSERT 类型的 SQL 语句。
- 进行参数绑定,bind 指向一个数组(代表所要绑定的一行数据),需保证此数组中的元素数量和顺序与 SQL 语句中的参数完全一致。TAOS_BIND 的使用方法与 MySQL 中的 MYSQL_BIND 一致,具体定义如下:
-
-```c
-typedef struct TAOS_BIND {
- int buffer_type;
- void * buffer;
- unsigned long buffer_length; // 未实际使用
- unsigned long *length;
- int * is_null;
- int is_unsigned; // 未实际使用
- int * error; // 未实际使用
-} TAOS_BIND;
-```
+ 不如 `taos_stmt_bind_param_batch()` 效率高,但可以支持非 INSERT 类型的 SQL 语句。
+ 进行参数绑定,bind 指向一个数组(代表所要绑定的一行数据),需保证此数组中的元素数量和顺序与 SQL 语句中的参数完全一致。TAOS_BIND 的使用方法与 MySQL 中的 MYSQL_BIND 类似,具体定义如下:
+
+ ```c
+ typedef struct TAOS_BIND {
+ int buffer_type;
+ void * buffer;
+ uintptr_t buffer_length; // not in use
+ uintptr_t * length;
+ int * is_null;
+ int is_unsigned; // not in use
+ int * error; // not in use
+ } TAOS_BIND;
+ ```
- `int taos_stmt_set_tbname(TAOS_STMT* stmt, const char* name)`
- (2.1.1.0 版本新增,仅支持用于替换 INSERT 语句中的参数值)
+ (2.1.1.0 版本新增,仅支持用于替换 INSERT 语句中的参数值)
当 SQL 语句中的表名使用了 `?` 占位时,可以使用此函数绑定一个具体的表名。
- `int taos_stmt_set_tbname_tags(TAOS_STMT* stmt, const char* name, TAOS_BIND* tags)`
- (2.1.2.0 版本新增,仅支持用于替换 INSERT 语句中的参数值)
- 当 SQL 语句中的表名和 TAGS 都使用了 `?` 占位时,可以使用此函数绑定具体的表名和具体的 TAGS 取值。最典型的使用场景是使用了自动建表功能的 INSERT 语句(目前版本不支持指定具体的 TAGS 列)。tags 参数中的列数量需要与 SQL 语句中要求的 TAGS 数量完全一致。
+ (2.1.2.0 版本新增,仅支持用于替换 INSERT 语句中的参数值)
+ 当 SQL 语句中的表名和 TAGS 都使用了 `?` 占位时,可以使用此函数绑定具体的表名和具体的 TAGS 取值。最典型的使用场景是使用了自动建表功能的 INSERT 语句(目前版本不支持指定具体的 TAGS 列)。TAGS 参数中的列数量需要与 SQL 语句中要求的 TAGS 数量完全一致。
- `int taos_stmt_bind_param_batch(TAOS_STMT* stmt, TAOS_MULTI_BIND* bind)`
- (2.1.1.0 版本新增,仅支持用于替换 INSERT 语句中的参数值)
+ (2.1.1.0 版本新增,仅支持用于替换 INSERT 语句中的参数值)
以多列的方式传递待绑定的数据,需要保证这里传递的数据列的顺序、列的数量与 SQL 语句中的 VALUES 参数完全一致。TAOS_MULTI_BIND 的具体定义如下:
-```c
-typedef struct TAOS_MULTI_BIND {
- int buffer_type;
- void * buffer;
- uintptr_t buffer_length;
- int32_t * length;
- char * is_null;
- int num; // 列的个数,即 buffer 中的参数个数
-} TAOS_MULTI_BIND;
-```
+ ```c
+ typedef struct TAOS_MULTI_BIND {
+ int buffer_type;
+ void * buffer;
+ uintptr_t buffer_length;
+ uintptr_t * length;
+ char * is_null;
+ int num; // the number of columns
+ } TAOS_MULTI_BIND;
+ ```
- `int taos_stmt_add_batch(TAOS_STMT *stmt)`
- 将当前绑定的参数加入批处理中,调用此函数后,可以再次调用 `taos_stmt_bind_param` 或 `taos_stmt_bind_param_batch` 绑定新的参数。需要注意,此函数仅支持 INSERT/IMPORT 语句,如果是 SELECT 等其他 SQL 语句,将返回错误。
+ 将当前绑定的参数加入批处理中,调用此函数后,可以再次调用 `taos_stmt_bind_param()` 或 `taos_stmt_bind_param_batch()` 绑定新的参数。需要注意,此函数仅支持 INSERT/IMPORT 语句,如果是 SELECT 等其他 SQL 语句,将返回错误。
- `int taos_stmt_execute(TAOS_STMT *stmt)`
@@ -258,7 +351,7 @@ typedef struct TAOS_MULTI_BIND {
- `TAOS_RES* taos_stmt_use_result(TAOS_STMT *stmt)`
- 获取语句的结果集。结果集的使用方式与非参数化调用时一致,使用完成后,应对此结果集调用 `taos_free_result` 以释放资源。
+ 获取语句的结果集。结果集的使用方式与非参数化调用时一致,使用完成后,应对此结果集调用 `taos_free_result()` 以释放资源。
- `int taos_stmt_close(TAOS_STMT *stmt)`
@@ -266,107 +359,54 @@ typedef struct TAOS_MULTI_BIND {
- `char * taos_stmt_errstr(TAOS_STMT *stmt)`
- (2.1.3.0 版本新增)
- 用于在其他 stmt API 返回错误(返回错误码或空指针)时获取错误信息。
+ (2.1.3.0 版本新增)
+ 用于在其他 STMT API 返回错误(返回错误码或空指针)时获取错误信息。
-
-### Schemaless 方式写入接口
+### 无模式写入 API
-除了使用 SQL 方式或者使用参数绑定 API 写入数据外,还可以使用 Schemaless 的方式完成写入。Schemaless 可以免于预先创建超级表/数据子表的数据结构,而是可以直接写入数据,TDengine 系统会根据写入的数据内容自动创建和维护所需要的表结构。Schemaless 的使用方式详见 [Schemaless 写入](https://www.taosdata.com/cn/documentation/insert#schemaless) 章节,这里介绍与之配套使用的 C/C++ API。
+除了使用 SQL 方式或者使用参数绑定 API 写入数据外,还可以使用 Schemaless 的方式完成写入。Schemaless 可以免于预先创建超级表/数据子表的数据结构,而是可以直接写入数据,TDengine 系统会根据写入的数据内容自动创建和维护所需要的表结构。Schemaless 的使用方式详见 [Schemaless 写入](/reference/schemaless/) 章节,这里介绍与之配套使用的 C/C++ API。
- `TAOS_RES* taos_schemaless_insert(TAOS* taos, const char* lines[], int numLines, int protocol, int precision)`
- **功能说明**
- 该接口将行协议的文本数据写入到 TDengine 中。
-
- **参数说明**
- taos: 数据库连接,通过 taos_connect 函数建立的数据库连接。
- lines:文本数据。满足解析格式要求的无模式文本字符串。
- numLines:文本数据的行数,不能为 0 。
- protocol: 行协议类型,用于标识文本数据格式。
- precision:文本数据中的时间戳精度字符串。
-
- **返回值**
- TAOS_RES 结构体,应用可以通过使用 taos_errstr 获得错误信息,也可以使用 taos_errno 获得错误码。
- 在某些情况下,返回的 TAOS_RES 为 NULL,此时仍然可以调用 taos_errno 来安全地获得错误码信息。
- 返回的 TAOS_RES 需要调用方来负责释放,否则会出现内存泄漏。
-
- **说明**
- 协议类型是枚举类型,包含以下三种格式:
- TSDB_SML_LINE_PROTOCOL:InfluxDB 行协议(Line Protocol)
- TSDB_SML_TELNET_PROTOCOL: OpenTSDB 文本行协议
- TSDB_SML_JSON_PROTOCOL: OpenTSDB Json 协议格式
-
- 时间戳分辨率的定义,定义在 taos.h 文件中,具体内容如下:
- TSDB_SML_TIMESTAMP_NOT_CONFIGURED = 0,
- TSDB_SML_TIMESTAMP_HOURS,
- TSDB_SML_TIMESTAMP_MINUTES,
- TSDB_SML_TIMESTAMP_SECONDS,
- TSDB_SML_TIMESTAMP_MILLI_SECONDS,
- TSDB_SML_TIMESTAMP_MICRO_SECONDS,
- TSDB_SML_TIMESTAMP_NANO_SECONDS
-
- 需要注意的是,时间戳分辨率参数只在协议类型为 SML_LINE_PROTOCOL 的时候生效。
- 对于 OpenTSDB 的文本协议,时间戳的解析遵循其官方解析规则 — 按照时间戳包含的字符的数量来确认时间精度。
-
- **支持版本**
- 该功能接口从 2.3.0.0 版本开始支持。
-
-```c
-#include
-#include
-#include
-
-int main() {
- const char* host = "127.0.0.1";
- const char* user = "root";
- const char* passwd = "taosdata";
-
- // connect to server
- TAOS* taos = taos_connect(host, user, passwd, "test", 0);
+ **功能说明**
+ 该接口将行协议的文本数据写入到 TDengine 中。
- // prepare the line string
- char* lines1[] = {
- "stg,t1=3i64,t2=4f64,t3=\"t3\" c1=3i64,c3=L\"passit\",c2=false,c4=4f64 1626006833639000000",
- "stg,t1=4i64,t3=\"t4\",t2=5f64,t4=5f64 c1=3i64,c3=L\"passitagin\",c2=true,c4=5f64,c5=5f64 1626006833641000000"
- };
+ **参数说明**
+ taos: 数据库连接,通过 `taos_connect()` 函数建立的数据库连接。
+ lines:文本数据。满足解析格式要求的无模式文本字符串。
+ numLines:文本数据的行数,不能为 0 。
+ protocol: 行协议类型,用于标识文本数据格式。
+ precision:文本数据中的时间戳精度字符串。
- // schema-less insert
- TAOS_RES* res = taos_schemaless_insert(taos, lines1, 2, TSDB_SML_LINE_PROTOCOL, TSDB_SML_TIMESTAMP_NANO_SECONDS);
- if (taos_errno(res) != 0) {
- printf("failed to insert schema-less data, reason: %s\n", taos_errstr(res));
- }
-
- taos_free_result(res);
-
- // close the connection
- taos_close(taos);
- return (code);
-}
-```
+ **返回值**
+ TAOS_RES 结构体,应用可以通过使用 `taos_errstr()` 获得错误信息,也可以使用 `taos_errno()` 获得错误码。
+ 在某些情况下,返回的 TAOS_RES 为 `NULL`,此时仍然可以调用 `taos_errno()` 来安全地获得错误码信息。
+ 返回的 TAOS_RES 需要调用方来负责释放,否则会出现内存泄漏。
-### 连续查询接口
+ **说明**
+ 协议类型是枚举类型,包含以下三种格式:
-TDengine 提供时间驱动的实时流式计算 API。可以每隔一指定的时间段,对一张或多张数据库的表(数据流)进行各种实时聚合计算操作。操作简单,仅有打开、关闭流的 API。具体如下:
+ - TSDB_SML_LINE_PROTOCOL:InfluxDB 行协议(Line Protocol)
+ - TSDB_SML_TELNET_PROTOCOL: OpenTSDB Telnet 文本行协议
+ - TSDB_SML_JSON_PROTOCOL: OpenTSDB Json 协议格式
-- `TAOS_STREAM *taos_open_stream(TAOS *taos, const char *sql, void (*fp)(void *param, TAOS_RES *, TAOS_ROW row), int64_t stime, void *param, void (*callback)(void *))`
+ 时间戳分辨率的定义,定义在 taos.h 文件中,具体内容如下:
- 该 API 用来创建数据流,其中:
+ - TSDB_SML_TIMESTAMP_NOT_CONFIGURED = 0,
+ - TSDB_SML_TIMESTAMP_HOURS,
+ - TSDB_SML_TIMESTAMP_MINUTES,
+ - TSDB_SML_TIMESTAMP_SECONDS,
+ - TSDB_SML_TIMESTAMP_MILLI_SECONDS,
+ - TSDB_SML_TIMESTAMP_MICRO_SECONDS,
+ - TSDB_SML_TIMESTAMP_NANO_SECONDS
- - taos:已经建立好的数据库连接。
- - sql:SQL 查询语句(仅能使用查询语句)。
- - fp:用户定义的回调函数指针,每次流式计算完成后,TDengine 将查询的结果(TAOS_ROW)、查询状态(TAOS_RES)、用户定义参数(PARAM)传递给回调函数,在回调函数内,用户可以使用 taos_num_fields 获取结果集列数,taos_fetch_fields 获取结果集每列数据的类型。
- - stime:是流式计算开始的时间。如果是“64 位整数最小值”,表示从现在开始;如果不为“64 位整数最小值”,表示从指定的时间开始计算(UTC 时间从 1970/1/1 算起的毫秒数)。
- - param:是应用提供的用于回调的一个参数,回调时,提供给应用。
- - callback: 第二个回调函数,会在连续查询自动停止时被调用。
+ 需要注意的是,时间戳分辨率参数只在协议类型为 `SML_LINE_PROTOCOL` 的时候生效。
+ 对于 OpenTSDB 的文本协议,时间戳的解析遵循其官方解析规则 — 按照时间戳包含的字符的数量来确认时间精度。
- 返回值为 NULL,表示创建失败;返回值不为空,表示成功。
+ **支持版本**
+ 该功能接口从 2.3.0.0 版本开始支持。
-- `void taos_close_stream (TAOS_STREAM *tstr)`
-
- 关闭数据流,其中提供的参数是 taos_open_stream 的返回值。用户停止流式计算的时候,务必关闭该数据流。
-
-### 数据订阅接口
+### 订阅和消费 API
订阅 API 目前支持订阅一张或多张表,并通过定期轮询的方式不断获取写入表中的最新数据。
@@ -380,7 +420,7 @@ TDengine 提供时间驱动的实时流式计算 API。可以每隔一指定的
- sql:订阅的查询语句,此语句只能是 `select` 语句,只应查询原始数据,只能按时间正序查询数据
- fp:收到查询结果时的回调函数(稍后介绍函数原型),只在异步调用时使用,同步调用时此参数应该传 `NULL`
- param:调用回调函数时的附加参数,系统 API 将其原样传递到回调函数,不进行任何处理
- - interval:轮询周期,单位为毫秒。异步调用时,将根据此参数周期性的调用回调函数,为避免对系统性能造成影响,不建议将此参数设置的过小;同步调用时,如两次调用`taos_consume`的间隔小于此周期,API 将会阻塞,直到时间间隔超过此周期。
+ - interval:轮询周期,单位为毫秒。异步调用时,将根据此参数周期性的调用回调函数,为避免对系统性能造成影响,不建议将此参数设置的过小;同步调用时,如两次调用 `taos_consume()` 的间隔小于此周期,API 将会阻塞,直到时间间隔超过此周期。
- `typedef void (*TAOS_SUBSCRIBE_CALLBACK)(TAOS_SUB* tsub, TAOS_RES *res, void* param, int code)`
@@ -388,17 +428,23 @@ TDengine 提供时间驱动的实时流式计算 API。可以每隔一指定的
- tsub:订阅对象
- res:查询结果集,注意结果集中可能没有记录
- - param:调用 `taos_subscribe`时客户程序提供的附加参数
+ - param:调用 `taos_subscribe()` 时客户程序提供的附加参数
- code:错误码
- **注意**:在这个回调函数里不可以做耗时过长的处理,尤其是对于返回的结果集中数据较多的情况,否则有可能导致客户端阻塞等异常状态。如果必须进行复杂计算,则建议在另外的线程中进行处理。
+ :::note
+ 在这个回调函数里不可以做耗时过长的处理,尤其是对于返回的结果集中数据较多的情况,否则有可能导致客户端阻塞等异常状态。如果必须进行复杂计算,则建议在另外的线程中进行处理。
+
+ :::
- `TAOS_RES *taos_consume(TAOS_SUB *tsub)`
- 同步模式下,该函数用来获取订阅的结果。 用户应用程序将其置于一个循环之中。 如两次调用`taos_consume`的间隔小于订阅的轮询周期,API 将会阻塞,直到时间间隔超过此周期。 如果数据库有新记录到达,该 API 将返回该最新的记录,否则返回一个没有记录的空结果集。 如果返回值为 `NULL`,说明系统出错。 异步模式下,用户程序不应调用此 API。
+ 同步模式下,该函数用来获取订阅的结果。 用户应用程序将其置于一个循环之中。 如两次调用 `taos_consume()` 的间隔小于订阅的轮询周期,API 将会阻塞,直到时间间隔超过此周期。如果数据库有新记录到达,该 API 将返回该最新的记录,否则返回一个没有记录的空结果集。 如果返回值为 `NULL`,说明系统出错。 异步模式下,用户程序不应调用此 API。
+
+ :::note
+ 在调用 `taos_consume()` 之后,用户应用应确保尽快调用 `taos_fetch_row()` 或 `taos_fetch_block()` 来处理订阅结果,否则服务端会持续缓存查询结果数据等待客户端读取,极端情况下会导致服务端内存消耗殆尽,影响服务稳定性。
- **注意**:在调用 `taos_consume()` 之后,用户应用应确保尽快调用 `taos_fetch_row()` 或 `taos_fetch_block()` 来处理订阅结果,否则服务端会持续缓存查询结果数据等待客户端读取,极端情况下会导致服务端内存消耗殆尽,影响服务稳定性。
+ :::
- `void taos_unsubscribe(TAOS_SUB *tsub, int keepProgress)`
- 取消订阅。 如参数 `keepProgress` 不为 0,API 会保留订阅的进度信息,后续调用 `taos_subscribe` 时可以基于此进度继续;否则将删除进度信息,后续只能重新开始读取数据。
+ 取消订阅。 如参数 `keepProgress` 不为 0,API 会保留订阅的进度信息,后续调用 `taos_subscribe()` 时可以基于此进度继续;否则将删除进度信息,后续只能重新开始读取数据。
diff --git a/docs-cn/14-reference/03-connector/cshapr.mdx b/docs-cn/14-reference/03-connector/cshapr.mdx
deleted file mode 100644
index 9ce6d024dce8dcf1d9010f158d20effd4c054739..0000000000000000000000000000000000000000
--- a/docs-cn/14-reference/03-connector/cshapr.mdx
+++ /dev/null
@@ -1,81 +0,0 @@
----
-sidebar_position: 7
-sidebar_label: C#
----
-
-# C# 连接器
-
-- C# 连接器支持的系统有:Linux 64/Windows x64/Windows x86
-
-- C# 连接器现在也支持从[Nuget 下载引用](https://www.nuget.org/packages/TDengine.Connector/)
-
-- 在 Windows 系统上,C# 应用程序可以使用 TDengine 的原生 C 接口来执行所有数据库操作,后续版本将提供 ORM(Dapper)框架驱动。
-
-## 安装准备
-
-- 应用驱动安装请参考[安装连接器驱动步骤](https://www.taosdata.com/cn/documentation/connector#driver)。
-- 接口文件 TDengineDrivercs.cs 和参考程序示例 TDengineTest.cs 均位于 Windows 客户端 install_directory/examples/C#目录下。
-- 安装[.NET SDK](https://dotnet.microsoft.com/download)
-
-## 示例程序
-
-示例程序源码位于
-
-- {client_install_directory}/examples/C#
-- [C# example source code on GitHub](https://github.com/taosdata/TDengine/tree/develop/examples/C%23)
-
-:::note
-TDengineTest.cs C# 示例源程序,包含了数据库连接参数,以及如何执行数据插入、查询等操作。
-
-:::
-
-## 安装验证
-
-需要先安装 .NET SDK
-
-```cmd
-cd {client_install_directory}/examples/C#/C#Checker
-//运行测试
-dotnet run -- -h . // 此步骤会先build,然后再运行。
-```
-
-## C# 连接器的使用
-
-在 Windows 系统上,C# 应用程序可以使用 TDengine 的 C# 连接器接口来执行所有数据库的操作。使用的具体步骤如下所示:
-
-- 创建一个 C# project(需要 .NET SDK).
-
- ```cmd
- mkdir test
- cd test
- dotnet new console
- ```
-
-- 通过 Nuget 引用 TDengineDriver 包
-
- ```cmd
- dotnet add package TDengine.Connector
- ```
-
-- 在项目中需要用到 TDengineConnector 的地方引用 TDengineDriver namespace。
-
- ```cs
- using TDengineDriver;
- ```
-
-- 用户可以参考[TDengineTest.cs](https://github.com/taosdata/TDengine/tree/develop/examples/C%2523/TDengineTest)来定义数据库连接参数,以及如何执行数据插入、查询等操作。
-
-:::note
-
-- TDengine V2.0.3.0 之后同时支持 32 位和 64 位 Windows 系统,所以 C# 项目在生成 .exe 文件时,“解决方案”/“项目”的“平台”请选择对应的 x86 或 x64。
-- 此接口目前已经在 Visual Studio 2015/2017 中验证过,其它 Visual Studio 版本尚待验证。
-- 此连接器需要用到 taos.dll 文件,所以在未安装客户端时需要在执行应用程序前,拷贝 Windows{client_install_directory}/driver 目录中的 taos.dll 文件到项目最后生成 .exe 可执行文件所在的文件夹。之后运行 exe 文件,即可访问 TDengine 数据库并做插入、查询等操作。
-
-:::
-
-## 第三方驱动
-
-Maikebing.Data.Taos 是一个 TDengine 的 ADO.NET 提供器,支持 Linux,Windows。该开发包由热心贡献者`麦壳饼@@maikebing`提供,具体请参考:
-
-- 接口下载:https://github.com/maikebing/Maikebing.EntityFrameworkCore.Taos
-- 用法说明:https://www.taosdata.com/blog/2020/11/02/1901.html
diff --git a/docs-cn/14-reference/03-connector/csharp.mdx b/docs-cn/14-reference/03-connector/csharp.mdx
new file mode 100644
index 0000000000000000000000000000000000000000..bbefaacb459153ab5116d557fdf1940d487b4bd3
--- /dev/null
+++ b/docs-cn/14-reference/03-connector/csharp.mdx
@@ -0,0 +1,189 @@
+---
+toc_max_heading_level: 4
+sidebar_position: 7
+sidebar_label: C#
+title: C# Connector
+---
+
+import Tabs from '@theme/Tabs';
+import TabItem from '@theme/TabItem';
+
+import Preparition from "./_preparition.mdx"
+import CSInsert from "../../04-develop/03-insert-data/_cs_sql.mdx"
+import CSInfluxLine from "../../04-develop/03-insert-data/_cs_line.mdx"
+import CSOpenTSDBTelnet from "../../04-develop/03-insert-data/_cs_opts_telnet.mdx"
+import CSOpenTSDBJson from "../../04-develop/03-insert-data/_cs_opts_json.mdx"
+import CSQuery from "../../04-develop/04-query-data/_cs.mdx"
+import CSAsyncQuery from "../../04-develop/04-query-data/_cs_async.mdx"
+
+`TDengine.Connector` 是 TDengine 提供的 C# 语言连接器。C# 开发人员可以通过它开发存取 TDengine 集群数据的 C# 应用软件。
+
+`TDengine.Connector` 连接器支持通过 TDengine 客户端驱动(taosc)建立与 TDengine 运行实例的连接,提供数据写入、查询、订阅、schemaless 数据写入、参数绑定接口数据写入等功能 `TDengine.Connector` 目前暂未提供 REST 连接方式,用户可以参考 [RESTful APIs](https://docs.taosdata.com//reference/restful-api/) 文档自行编写。
+
+本文介绍如何在 Linux 或 Windows 环境中安装 `TDengine.Connector`,并通过 `TDengine.Connector` 连接 TDengine 集群,进行数据写入、查询等基本操作。
+
+`TDengine.Connector` 的源码托管在 [GitHub](https://github.com/taosdata/taos-connector-dotnet)。
+
+## 支持的平台
+
+支持的平台和 TDengine 客户端驱动支持的平台一致。
+
+## 版本支持
+
+请参考[版本支持列表](/reference/connector#版本支持)
+
+## 支持的功能特性
+
+1. 连接管理
+2. 普通查询
+3. 连续查询
+4. 参数绑定
+5. 订阅功能
+6. Schemaless
+
+## 安装步骤
+
+### 安装前准备
+
+* 安装 [.NET SDK](https://dotnet.microsoft.com/download)
+* [Nuget 客户端](https://docs.microsoft.com/en-us/nuget/install-nuget-client-tools) (可选安装)
+* 安装 TDengine 客户端驱动,具体步骤请参考[安装客户端驱动](/reference/connector#安装客户端驱动)
+
+### 使用 dotnet CLI 安装
+
+
+
+
+可以在当前 .NET 项目的路径下,通过 dotnet 命令引用 Nuget 中发布的 `TDengine.Connector` 到当前项目。
+
+``` bash
+dotnet add package TDengine.Connector
+```
+
+
+
+
+可以下载 TDengine 的源码,直接引用最新版本的 TDengine.Connector 库
+
+```bash
+git clone https://github.com/taosdata/TDengine.git
+cd TDengine/src/connector/C#/src/
+cp -r TDengineDriver/ myProject
+
+cd myProject
+dotnet add TDengineDriver/TDengineDriver.csproj
+```
+
+
+
+## 建立连接
+
+``` C#
+using TDengineDriver;
+
+namespace TDengineExample
+{
+
+ internal class EstablishConnection
+ {
+ static void Main(String[] args)
+ {
+ string host = "localhost";
+ short port = 6030;
+ string username = "root";
+ string password = "taosdata";
+ string dbname = "";
+
+ var conn = TDengine.Connect(host, username, password, dbname, port);
+ if (conn == IntPtr.Zero)
+ {
+ Console.WriteLine("Connect to TDengine failed");
+ }
+ else
+ {
+ Console.WriteLine("Connect to TDengine success");
+ }
+ TDengine.Close(conn);
+ TDengine.Cleanup();
+ }
+ }
+}
+
+```
+
+## 使用示例
+
+### 写入数据
+
+#### SQL 写入
+
+
+
+#### InfluxDB 行协议写入
+
+
+
+#### OpenTSDB Telnet 行协议写入
+
+
+
+#### OpenTSDB JSON 行协议写入
+
+
+
+### 查询数据
+
+#### 同步查询
+
+
+
+#### 异步查询
+
+
+
+### 更多示例程序
+
+|示例程序 | 示例程序描述 |
+|--------------------------------------------------------------------------------------------------------------------|--------------------------------------------|
+| [C#checker](https://github.com/taosdata/TDengine/tree/develop/examples/C%23/C%23checker) | 使用 TDengine.Connector 可以通过 help 命令中提供的参数,测试C# Driver的同步写入和查询 |
+| [TDengineTest](https://github.com/taosdata/TDengine/tree/develop/examples/C%23/TDengineTest) | 使用 TDengine.Connector 实现的简单写入和查询的示例 |
+| [insertCn](https://github.com/taosdata/TDengine/tree/develop/examples/C%23/insertCn) | 使用 TDengine.Connector 实现的写入和查询中文字符的示例 |
+| [jsonTag](https://github.com/taosdata/TDengine/tree/develop/examples/C%23/jsonTag) | 使用 TDengine.Connector 实现的写入和查询 json tag 类型数据的示例 |
+| [stmt](https://github.com/taosdata/TDengine/tree/develop/examples/C%23/stmt) | 使用 TDengine.Connector 实现的参数绑定的示例 |
+| [schemaless](https://github.com/taosdata/TDengine/tree/develop/examples/C%23/schemaless) | 使用 TDengine.Connector 实现的使用 schemaless 写入的示例 |
+| [benchmark](https://github.com/taosdata/TDengine/tree/develop/examples/C%23/taosdemo) | 使用 TDengine.Connector 实现的简易 Benchmark |
+| [async query](https://github.com/taosdata/taos-connector-dotnet/blob/develop/examples/QueryAsyncSample.cs) | 使用 TDengine.Connector 实现的异步查询的示例 |
+| [subscribe](https://github.com/taosdata/taos-connector-dotnet/blob/develop/examples/SubscribeSample.cs) | 使用 TDengine.Connector 实现的订阅数据的示例 |
+
+## 重要更新记录
+
+| TDengine.Connector | 说明 |
+|--------------------|--------------------------------|
+| 1.0.6 | 修复 schemaless 在 1.0.4 和 1.0.5 中失效 bug。 |
+| 1.0.5 | 修复 Windows 同步查询中文报错 bug。 |
+| 1.0.4 | 新增异步查询,订阅等功能。修复绑定参数 bug。 |
+| 1.0.3 | 新增参数绑定、schemaless、 json tag等功能。 |
+| 1.0.2 | 新增连接管理、同步查询、错误信息等功能。 |
+
+## 其他说明
+
+### 第三方驱动
+
+`Maikebing.Data.Taos` 是一个 TDengine 的 ADO.NET 连接器,支持 Linux,Windows 平台。该连接器由社区贡献者`麦壳饼@@maikebing` 提供,具体请参考:
+
+* 接口下载:
+* 用法说明:
+
+## 常见问题
+
+1. "Unable to establish connection","Unable to resolve FQDN"
+
+ 一般是因为 FQDN 配置不正确。可以参考[如何彻底搞懂 TDengine 的 FQDN](https://www.taosdata.com/blog/2021/07/29/2741.html)解决。
+
+2. Unhandled exception. System.DllNotFoundException: Unable to load DLL 'taos' or one of its dependencies: 找不到指定的模块。
+
+ 一般是因为程序没有找到依赖的客户端驱动。解决方法为:Windows 下可以将 `C:\TDengine\driver\taos.dll` 拷贝到 `C:\Windows\System32\ ` 目录下,Linux 下建立如下软链接 `ln -s /usr/local/taos/driver/libtaos.so.x.x.x.x /usr/lib/libtaos.so` 即可。
+
+## API 参考
+
+[API 参考](https://docs.taosdata.com/api/connector-csharp/html/860d2ac1-dd52-39c9-e460-0829c4e5a40b.htm)
diff --git a/docs-cn/14-reference/03-connector/go.mdx b/docs-cn/14-reference/03-connector/go.mdx
index 888f4ae139c8246553ee863668ca11d6683f7068..2c73443a1c919ee41899baba5cb1e1aecc4b5552 100644
--- a/docs-cn/14-reference/03-connector/go.mdx
+++ b/docs-cn/14-reference/03-connector/go.mdx
@@ -1,138 +1,222 @@
---
+toc_max_heading_level: 4
sidebar_position: 4
+sidebar_label: Go
+title: TDengine Go Connector
---
-# Go Connector
+import Tabs from '@theme/Tabs';
+import TabItem from '@theme/TabItem';
-## 安装准备
+import Preparition from "./_preparition.mdx"
+import GoInsert from "../../04-develop/03-insert-data/_go_sql.mdx"
+import GoInfluxLine from "../../04-develop/03-insert-data/_go_line.mdx"
+import GoOpenTSDBTelnet from "../../04-develop/03-insert-data/_go_opts_telnet.mdx"
+import GoOpenTSDBJson from "../../04-develop/03-insert-data/_go_opts_json.mdx"
+import GoQuery from "../../04-develop/04-query-data/_go.mdx"
-Go 连接器支持的系统有:
+`driver-go` 是 TDengine 的官方 Go 语言连接器,实现了 Go 语言[ database/sql ](https://golang.org/pkg/database/sql/) 包的接口。Go 开发人员可以通过它开发存取 TDengine 集群数据的应用软件。
-| **CPU 类型** | x64(64bit) | | | aarch64 | aarch32 |
-| ------------ | ------------ | -------- | -------- | -------- | ---------- |
-| **OS 类型** | Linux | Win64 | Win32 | Linux | Linux |
-| **支持与否** | **支持** | **支持** | **支持** | **支持** | **开发中** |
+`driver-go` 提供两种形式的连接器。一种是**原生连接器**,它通过 TDengine 客户端驱动程序(taosc)原生连接 TDengine 运行实例,支持数据写入、查询、订阅、schemaless 接口和参数绑定接口等功能。另外一种是 **REST 连接器**,它通过 taosAdapter 提供的 REST 接口连接 TDengine 运行实例。REST 连接实现的功能特性集合和原生连接有少量不同。
-安装前准备:已安装好 TDengine 应用驱动,参考[安装连接器驱动步骤](/reference/connector)。
+本文介绍如何安装 `driver-go`,并通过 `driver-go` 连接 TDengine 集群、进行数据查询、数据写入等基本操作。
-## 示例程序
+`driver-go` 的源码托管在 [GitHub](https://github.com/taosdata/driver-go)。
-使用 Go 连接器的示例代码请参考 `https://github.com/taosdata/TDengine/tree/develop/examples/go` 以及[视频教程](https://www.taosdata.com/blog/2020/11/11/1951.html)。
+## 支持的平台
-示例程序源码也位于安装目录下的 examples/go/taosdemo.go 文件中。
+原生连接器支持的平台和 TDengine 客户端驱动支持的平台一致。
+REST 连接器支持所有能运行 Go 的平台。
-:::tip
-建议 Go 版本是 1.13 及以上,并开启模块支持:
-:::
+## 版本支持
-```sh
-go env -w GO111MODULE=on
-go env -w GOPROXY=https://goproxy.io,direct
-```
+请参考[版本支持列表](/reference/connector#版本支持)
-在 taosdemo.go 所在目录下进行编译和执行:
+## 支持的功能特性
-```sh
-go mod init taosdemo
-go get github.com/taosdata/driver-go/taosSql
-# use win branch in Windows platform.
-#go get github.com/taosdata/driver-go/taosSql@win
-go build
-./taosdemo -h fqdn -p serverPort
-```
+### 原生连接器
-## Go 连接器的使用
+“原生连接”指连接器通过 TDengine 客户端驱动(taosc)直接与 TDengine 运行实例建立的连接。支持的功能特性有:
-TDengine 提供了 GO 驱动程序包`taosSql`。`taosSql` 实现了 GO 语言的内置接口 `database/sql/driver`。用户只需按如下方式引入包就可以在应用程序中访问 TDengine。
+* 普通查询
+* 连续查询
+* 订阅
+* schemaless 接口
+* 参数绑定接口
-```go
-import (
- "database/sql"
- _ "github.com/taosdata/driver-go/v2/taosSql"
-)
-```
+### REST 连接器
-:::tip
-下划线与双引号之间必须有一个空格。
+"REST 连接"指连接器通过 taosAdapter 组件提供的 REST API 与 TDengine 运行实例建立的连接。支持的功能特性有:
-:::
+* 普通查询
+* 连续查询
-`taosSql` 的 v2 版本进行了重构,分离出内置数据库操作接口 `database/sql/driver` 到目录 `taosSql`;订阅、 stmt 等其他功能放到目录 `af`。
+## 安装步骤
-## 常用 API
+### 安装前准备
+
+* 安装 Go 开发环境(Go 1.14 及以上,GCC 4.8.5 及以上)
+* 如果使用原生连接器,请安装 TDengine 客户端驱动,具体步骤请参考[安装客户端驱动](/reference/connector#安装客户端驱动)
+
+配置好环境变量,检查命令:
+
+* ```go env```
+* ```gcc -v```
+
+### 使用 go get 安装
+
+`go get -u github.com/taosdata/driver-go/v2@develop`
+
+### 使用 go mod 管理
-- `sql.Open(DRIVER_NAME string, dataSourceName string) *DB`
+1. 使用 `go mod` 命令初始化项目:
- 该 API 用来打开 DB,返回一个类型为\*DB 的对象,一般情况下,DRIVER_NAME 设置为字符串 `taosSql`,dataSourceName 设置为字符串 `user:password@/tcp(host:port)/dbname`,如果客户想要用多个 goroutine 并发访问 TDengine, 那么需要在各个 goroutine 中分别创建一个 sql.Open 对象并用之访问 TDengine。
+ ```text
+ go mod init taos-demo
+ ```
- **注意**: 该 API 成功创建的时候,并没有做权限等检查,只有在真正执行 Query 或者 Exec 的时候才能真正的去创建连接,并同时检查 user/password/host/port 是不是合法。另外,由于整个驱动程序大部分实现都下沉到 taosSql 所依赖的 libtaos 动态库中。所以,sql.Open 本身特别轻量。
+2. 引入 taosSql :
-- `func (db *DB) Exec(query string, args ...interface{}) (Result, error)`
+ ```go
+ import (
+ "database/sql"
+ _ "github.com/taosdata/driver-go/v2/taosSql"
+ )
+ ```
+
+3. 使用 `go mod tidy` 更新依赖包:
+
+ ```text
+ go mod tidy
+ ```
+
+4. 使用 `go run taos-demo` 运行程序或使用 `go build` 命令编译出二进制文件。
-sql.Open 内置的方法,用来执行非查询相关 SQL
+ ```text
+ go run taos-demo
+ go build
+ ```
-- `func (db *DB) Query(query string, args ...interface{}) (*Rows, error)`
+## 建立连接
-sql.Open 内置的方法,用来执行查询语句
+### 数据源名称(DSN)
-- `func (db *DB) Prepare(query string) (*Stmt, error)`
+数据源名称具有通用格式,例如 [PEAR DB](http://pear.php.net/manual/en/package.database.db.intro-dsn.php),但没有类型前缀(方括号表示可选):
- sql.Open 内置的方法,Prepare creates a prepared statement for later queries or executions.
+``` text
+[username[:password]@][protocol[(address)]]/[dbname][?param1=value1&...¶mN=valueN]
+```
+
+完整形式的 DSN:
+
+```text
+username:password@protocol(address)/dbname?param=value
+```
+### 使用连接器进行连接
-- `func (s *Stmt) Exec(args ...interface{}) (Result, error)`
+
+
+
+_taosSql_ 通过 cgo 实现了 Go 的 `database/sql/driver` 接口。只需要引入驱动就可以使用 [`database/sql`](https://golang.org/pkg/database/sql/) 的接口。
+
+使用 `taosSql` 作为 `driverName` 并且使用一个正确的 [DSN](#DSN) 作为 `dataSourceName`,DSN 支持的参数:
+
+* configPath 指定 taos.cfg 目录
+
+示例:
+
+```go
+package main
- sql.Open 内置的方法,executes a prepared statement with the given arguments and returns a Result summarizing the effect of the statement.
+import (
+ "database/sql"
+ "fmt"
-- `func (s *Stmt) Query(args ...interface{}) (*Rows, error)`
+ _ "github.com/taosdata/driver-go/v2/taosSql"
+)
- sql.Open 内置的方法,Query executes a prepared query statement with the given arguments and returns the query results as a \*Rows.
+func main() {
+ var taosUri = "root:taosdata/tcp(localhost:6030)/"
+ taos, err := sql.Open("taosSql", taosUri)
+ if err != nil {
+ fmt.Println("failed to connect TDengine, err:", err)
+ return
+ }
+}
+```
-- `func (s *Stmt) Close() error`
+
+
- sql.Open 内置的方法,Close closes the statement.
+_taosRestful_ 通过 `http client` 实现了 Go 的 `database/sql/driver` 接口。只需要引入驱动就可以使用[`database/sql`](https://golang.org/pkg/database/sql/)的接口。
-## 其他代码示例
+使用 `taosRestful` 作为 `driverName` 并且使用一个正确的 [DSN](#DSN) 作为 `dataSourceName`,DSN 支持的参数:
-[Consume Messages from Kafka](https://github.com/taosdata/go-demo-kafka) 是一个通过 Go 语言实现消费 Kafka 队列写入 TDengine 的示例程序,也可以作为通过 Go 连接 TDengine 的写法参考。
+* `disableCompression` 是否接受压缩数据,默认为 true 不接受压缩数据,如果传输数据使用 gzip 压缩设置为 false。
+* `readBufferSize` 读取数据的缓存区大小默认为 4K(4096),当查询结果数据量多时可以适当调大该值。
-## Go RESTful 的使用
+示例:
-### 引入
+```go
+package main
-```go restful
import (
- "database/sql"
- _ "github.com/taosdata/driver-go/v2/taosRestful"
+ "database/sql"
+ "fmt"
+
+ _ "github.com/taosdata/driver-go/v2/taosRestful"
)
+
+func main() {
+ var taosUri = "root:taosdata/http(localhost:6041)/"
+ taos, err := sql.Open("taosRestful", taosUri)
+ if err != nil {
+ fmt.Println("failed to connect TDengine, err:", err)
+ return
+ }
+}
```
+
+
+
+## 使用示例
+
+### 写入数据
+
+#### SQL 写入
-`go.mod ` 的文件 require 块使用 github.com/taosdata/driver-go/v2 develop 之后执行 `go mod tidy `
+
-`sql.Open `的 driverName 为 `taosRestful`
+#### InfluxDB 行协议写入
-### DSN
+
-格式为:
+#### OpenTSDB Telnet 行协议写入
-数据库用户名:数据库密码@连接方式(域名或 ip:端口)/[数据库][?参数]
+
-样例:
+#### OpenTSDB JSON 行协议写入
-`root:taosdata@http(localhost:6041)/test?readBufferSize=52428800`
+
-参数:
+### 查询数据
-`disableCompression` 是否接受压缩数据,默认为 true 不接受压缩数据,如果传输数据使用 gzip 压缩设置为 false。
+
-`readBufferSize` 读取数据的缓存区大小默认为 4K(4096),当查询结果数据量多时可以适当调大该值。
+### 更多示例程序
-### 使用限制
+* [示例程序](https://github.com/taosdata/TDengine/tree/develop/examples/go)
+* [视频教程](https://www.taosdata.com/blog/2020/11/11/1951.html)。
-由于 RESTful 接口无状态所以 `use db` 语法不会生效,需要将 db 名称放到 SQL 语句中,如:`create table if not exists tb1 (ts timestamp, a int)`改为`create table if not exists test.tb1 (ts timestamp, a int)`否则将报错`[0x217] Database not specified or available`。
+## 使用限制
-也可以将 db 名称放到 DSN 中,将 `root:taosdata@http(localhost:6041)/` 改为 `root:taosdata@http(localhost:6041)/test`,此方法在 TDengine 2.4.0.5 版本的 taosAdapter 开始支持。当指定的 db 不存在时执行 `create database` 语句不会报错,而执行针对该 db 的其他查询或写入操作会报错。完整示例如下:
+由于 REST 接口无状态所以 `use db` 语法不会生效,需要将 db 名称放到 SQL 语句中,如:`create table if not exists tb1 (ts timestamp, a int)`改为`create table if not exists test.tb1 (ts timestamp, a int)`否则将报错`[0x217] Database not specified or available`。
-```go restful demo
+也可以将 db 名称放到 DSN 中,将 `root:taosdata@http(localhost:6041)/` 改为 `root:taosdata@http(localhost:6041)/test`,此方法在 TDengine 2.4.0.5 版本的 taosAdapter 开始支持。当指定的 db 不存在时执行 `create database` 语句不会报错,而执行针对该 db 的其他查询或写入操作会报错。
+
+完整示例如下:
+
+```go
package main
import (
@@ -180,32 +264,148 @@ func main() {
}
```
-### 常见问题
+## 常见问题
-- 无法找到包`github.com/taosdata/driver-go/v2/taosRestful`
+1. 无法找到包 `github.com/taosdata/driver-go/v2/taosRestful`
将 `go.mod` 中 require 块对`github.com/taosdata/driver-go/v2`的引用改为`github.com/taosdata/driver-go/v2 develop`,之后执行 `go mod tidy`。
-- stmt 相关接口崩溃
+2. database/sql 中 stmt(参数绑定)相关接口崩溃
- RESTful 不支持 stmt 相关接口,建议使用`db.Exec`和`db.Query`。
+ REST 不支持参数绑定相关接口,建议使用`db.Exec`和`db.Query`。
-- 使用 `use db` 语句后执行其他语句报错 `[0x217] Database not specified or available`
+3. 使用 `use db` 语句后执行其他语句报错 `[0x217] Database not specified or available`
- 在 RESTful 接口中 SQL 语句的执行无上下文关联,使用 `use db` 语句不会生效,解决办法见上方使用限制章节。
+ 在 REST 接口中 SQL 语句的执行无上下文关联,使用 `use db` 语句不会生效,解决办法见上方使用限制章节。
-- 使用 taosSql 不报错使用 taosRestful 报错 `[0x217] Database not specified or available`
+4. 使用 taosSql 不报错使用 taosRestful 报错 `[0x217] Database not specified or available`
- 因为 RESTful 接口无状态,使用 `use db` 语句不会生效,解决办法见上方使用限制章节。
+ 因为 REST 接口无状态,使用 `use db` 语句不会生效,解决办法见上方使用限制章节。
-- 升级 `github.com/taosdata/driver-go/v2/taosRestful`
+5. 升级 `github.com/taosdata/driver-go/v2/taosRestful`
将 `go.mod` 文件中对 `github.com/taosdata/driver-go/v2` 的引用改为 `github.com/taosdata/driver-go/v2 develop`,之后执行 `go mod tidy`。
-- readBufferSize 参数调大后无明显效果
+6. `readBufferSize` 参数调大后无明显效果
+
+ `readBufferSize` 调大后会减少获取结果时 `syscall` 的调用。如果查询结果的数据量不大,修改该参数不会带来明显提升,如果该参数修改过大,瓶颈会在解析 JSON 数据。如果需要优化查询速度,需要根据实际情况调整该值来达到查询效果最优。
+
+7. `disableCompression` 参数设置为 `false` 时查询效率降低
+
+ 当 `disableCompression` 参数设置为 `false` 时查询结果会使用 `gzip` 压缩后传输,拿到数据后要先进行 `gzip` 解压。
+
+8. `go get` 命令无法获取包,或者获取包超时
+
+ 设置 Go 代理 `go env -w GOPROXY=https://goproxy.cn,direct`。
+
+## 常用 API
+
+### database/sql API
+
+* `sql.Open(DRIVER_NAME string, dataSourceName string) *DB`
+
+ 该 API 用来打开 DB,返回一个类型为 \*DB 的对象。
+
+:::info
+该 API 成功创建的时候,并没有做权限等检查,只有在真正执行 Query 或者 Exec 的时候才能真正的去创建连接,并同时检查 user/password/host/port 是不是合法。
+:::
+
+* `func (db *DB) Exec(query string, args ...interface{}) (Result, error)`
+
+ `sql.Open` 内置的方法,用来执行非查询相关 SQL。
+
+* `func (db *DB) Query(query string, args ...interface{}) (*Rows, error)`
+
+ `sql.Open` 内置的方法,用来执行查询语句。
+
+### 高级功能(af)API
+
+`af` 包封装了连接管理、订阅、schemaless、参数绑定等 TDengine 高级功能。
+
+#### 连接管理
+
+* `af.Open(host, user, pass, db string, port int) (*Connector, error)`
+
+ 该 API 通过 cgo 创建与 taosd 的连接。
+
+* `func (conn *Connector) Close() error`
+
+ 关闭与 taosd 的连接。
+
+#### 订阅
+
+* `func (conn *Connector) Subscribe(restart bool, topic string, sql string, interval time.Duration) (Subscriber, error)`
+
+ 订阅数据。
+
+* `func (s *taosSubscriber) Consume() (driver.Rows, error)`
+
+ 消费订阅数据,返回 `database/sql/driver` 包的 `Rows` 结构。
+
+* `func (s *taosSubscriber) Unsubscribe(keepProgress bool)`
+
+ 取消订阅数据。
+
+#### schemaless
+
+* `func (conn *Connector) InfluxDBInsertLines(lines []string, precision string) error`
+
+ 写入 influxDB 行协议。
+
+* `func (conn *Connector) OpenTSDBInsertTelnetLines(lines []string) error`
+
+ 写入 OpenTDSB telnet 协议数据。
+
+* `func (conn *Connector) OpenTSDBInsertJsonPayload(payload string) error`
+
+ 写入 OpenTSDB JSON 协议数据。
+
+#### 参数绑定
+
+* `func (conn *Connector) StmtExecute(sql string, params *param.Param) (res driver.Result, err error)`
+
+ 参数绑定单行插入。
+
+* `func (conn *Connector) StmtQuery(sql string, params *param.Param) (rows driver.Rows, err error)`
+
+ 参数绑定查询,返回 `database/sql/driver` 包的 `Rows` 结构。
+
+* `func (conn *Connector) InsertStmt() *insertstmt.InsertStmt`
+
+ 初始化参数。
+
+* `func (stmt *InsertStmt) Prepare(sql string) error`
+
+ 参数绑定预处理 SQL 语句。
+
+* `func (stmt *InsertStmt) SetTableName(name string) error`
+
+ 参数绑定设置表名。
+
+* `func (stmt *InsertStmt) SetSubTableName(name string) error`
+
+ 参数绑定设置子表名。
+
+* `func (stmt *InsertStmt) BindParam(params []*param.Param, bindType *param.ColumnType) error`
+
+ 参数绑定多行数据。
+
+* `func (stmt *InsertStmt) AddBatch() error`
+
+ 添加到参数绑定批处理。
+
+* `func (stmt *InsertStmt) Execute() error`
+
+ 执行参数绑定。
+
+* `func (stmt *InsertStmt) GetAffectedRows() int`
+
+ 获取参数绑定插入受影响行数。
+
+* `func (stmt *InsertStmt) Close() error`
- readBufferSize 调大后会减少获取结果时 syscall 的调用。如果查询结果的数据量不大,修改该参数不会带来明显提升,如果该参数修改过大,瓶颈会在解析 JSON 数据。如果需要优化查询速度,需要根据实际情况调整该值来达到查询效果最优。
+ 结束参数绑定。
-- disableCompression 参数设置为 false 时查询效率降低
+## API 参考
- 当 disableCompression 参数设置为 false 时查询结果会 gzip 压缩后传输,拿到数据后要先进行 gzip 解压。
+全部 API 见 [driver-go 文档](https://pkg.go.dev/github.com/taosdata/driver-go/v2)
diff --git a/docs-cn/14-reference/03-connector/java.mdx b/docs-cn/14-reference/03-connector/java.mdx
index 95c04171e1141f587f9fcb5d790548ef412af7c6..293deb4fe6bc47e149e64bb738569f29744734e9 100644
--- a/docs-cn/14-reference/03-connector/java.mdx
+++ b/docs-cn/14-reference/03-connector/java.mdx
@@ -1,81 +1,41 @@
---
+toc_max_heading_level: 4
sidebar_position: 2
+sidebar_label: Java
+title: TDengine Java Connector
+description: TDengine Java 连接器基于标准 JDBC API 实现, 并提供原生连接与 REST连接两种连接器。
---
-# Java Connector
+import Tabs from '@theme/Tabs';
+import TabItem from '@theme/TabItem';
-## 总体介绍
+`taos-jdbcdriver` 是 TDengine 的官方 Java 语言连接器,Java 开发人员可以通过它开发存取 TDengine 数据库的应用软件。`taos-jdbcdriver` 实现了 JDBC driver 标准的接口,并提供两种形式的连接器。一种是通过 TDengine 客户端驱动程序(taosc)原生连接 TDengine 实例,支持数据写入、查询、订阅、schemaless 接口和参数绑定接口等功能,一种是通过 taosAdapter 提供的 REST 接口连接 TDengine 实例(2.0.18 及更高版本)。REST 连接实现的功能集合和原生连接有少量不同。
-`taos-jdbcdriver` 的实现包括 2 种形式: JDBC-JNI 和 JDBC-RESTful(taos-jdbcdriver-2.0.18 开始支持 JDBC-RESTful)。 JDBC-JNI 通过调用客户端 libtaos.so(或 taos.dll )的本地方法实现, JDBC-RESTful 则在内部封装了 RESTful 接口实现。
+
-
+上图显示了两种 Java 应用使用连接器访问 TDengine 的两种方式:
-上图显示了 3 种 Java 应用使用连接器访问 TDengine 的方式:
+- JDBC 原生连接:Java 应用在物理节点 1(pnode1)上使用 TSDBDriver 直接调用客户端驱动(libtaos.so 或 taos.dll)的 API 将写入和查询请求发送到位于物理节点 2(pnode2)上的 taosd 实例。
+- JDBC REST 连接:Java 应用通过 RestfulDriver 将 SQL 封装成一个 REST 请求,发送给物理节点 2 的 REST 服务器(taosAdapter),通过 REST 服务器请求 taosd 并返回结果。
-- JDBC-JNI:Java 应用在物理节点 1(pnode1)上使用 JDBC-JNI 的 API ,直接调用客户端 API(libtaos.so 或 taos.dll)将写入和查询请求发送到位于物理节点 2(pnode2)上的 taosd 实例。
-- RESTful:应用将 SQL 发送给位于物理节点 2(pnode2)上的 RESTful 连接器,再调用客户端 API(libtaos.so)。
-- JDBC-RESTful:Java 应用通过 JDBC-RESTful 的 API ,将 SQL 封装成一个 RESTful 请求,发送给物理节点 2 的 RESTful 连接器。
+使用 REST 连接器,不依赖 TDengine 客户端驱动,可以跨平台,更加方便灵活,但性能比原生连接器低约 30%。
-TDengine 的 JDBC 驱动实现尽可能与关系型数据库驱动保持一致,但 TDengine 与关系对象型数据库的使用场景和技术特征存在差异,导致 `taos-jdbcdriver` 与传统的 JDBC driver 也存在一定差异。在使用时需要注意以下几点:
+:::info
+TDengine 的 JDBC 驱动实现尽可能与关系型数据库驱动保持一致,但 TDengine 与关系对象型数据库的使用场景和技术特征存在差异,所以`taos-jdbcdriver` 与传统的 JDBC driver 也存在一定差异。在使用时需要注意以下几点:
- TDengine 目前不支持针对单条数据记录的删除操作。
- 目前不支持事务操作。
-### JDBC-JNI 和 JDBC-RESTful 的对比
-
-
-
- 对比项 |
- JDBC-JNI |
- JDBC-RESTful |
-
-
- 支持的操作系统 |
- linux、windows |
- 全平台 |
-
-
- 是否需要安装 client |
- 需要 |
- 不需要 |
-
-
- server 升级后是否需要升级 client |
- 需要 |
- 不需要 |
-
-
- 写入性能 |
- JDBC-RESTful 是 JDBC-JNI 的 50%~90% |
-
-
- 查询性能 |
- JDBC-RESTful 与 JDBC-JNI 没有差别 |
-
-
-
-注意:
-
-- 与 JNI 方式不同,RESTful 接口是无状态的。在使用 JDBC-RESTful 时,需要在 sql 中指定表、超级表的数据库名称。例如:
+:::
-```sql
-INSERT INTO test.t1 USING test.weather (ts, temperature) TAGS('beijing') VALUES(now, 24.6);
-```
+## 支持的平台
-- 从 taos-jdbcdriver-2.0.36 和 TDengine 2.2.0.0 版本开始,如果在 url 中指定了 dbname,那么,JDBC-RESTful 会默认使用/rest/sql/dbname 作为 resful 请求的 url,在 sql 中不需要指定 dbname。例如:url 为 jdbc:TAOS-RS://127.0.0.1:6041/test,那么,可以执行 sql:insert into t1 using weather(ts, temperatrue) tags('beijing') values(now, 24.6);
+原生连接器支持的平台和 TDengine 客户端驱动支持的平台一致。
+REST 连接器支持所有能运行 Java 的平台。
## 版本支持
-| taos-jdbcdriver 版本 | TDengine 2.0.x.x 版本 | TDengine 2.2.x.x 版本 | TDengine 2.4.x.x 版本 | JDK 版本 |
-| -------------------- | --------------------- | --------------------- | --------------------- | -------- |
-| 2.0.37 | X | X | 2.4.0.6 以上 | 1.8.x |
-| 2.0.36 | X | 2.2.2.11 以上 | 2.4.0.0 - 2.4.0.5 | 1.8.x |
-| 2.0.35 | X | 2.2.2.11 以上 | 2.3.0.0 - 2.4.0.5 | 1.8.x |
-| 2.0.33 - 2.0.34 | 2.0.3.0 以上 | 2.2.0.0 以上 | 2.4.0.0 - 2.4.0.5 | 1.8.x |
-| 2.0.31 - 2.0.32 | 2.1.3.0 - 2.1.7.7 | X | X | 1.8.x |
-| 2.0.22 - 2.0.30 | 2.0.18.0 - 2.1.2.1 | X | X | 1.8.x |
-| 2.0.12 - 2.0.21 | 2.0.8.0 - 2.0.17.4 | X | X | 1.8.x |
-| 2.0.4 - 2.0.11 | 2.0.0.0 - 2.0.7.3 | X | X | 1.8.x |
+请参考[版本支持列表](/reference/connector#版本支持)
## TDengine DataType 和 Java DataType
@@ -95,26 +55,21 @@ TDengine 目前支持时间戳、数字、字符、布尔类型,与 Java 对
| NCHAR | java.lang.String | java.lang.String |
| JSON | - | java.lang.String |
-注意:JSON 类型仅在 tag 中支持。
+**注意**:JSON 类型仅在 tag 中支持。
-## 安装 Java Connector
+## 安装步骤
### 安装前准备
使用 Java Connector 连接数据库前,需要具备以下条件:
-1. Linux 或 Windows 操作系统
-2. Java 1.8 以上运行时环境
-3. TDengine-client(使用 JDBC-JNI 时必须,使用 JDBC-RESTful 时非必须)
-
-**注意**:由于 TDengine 的应用驱动是使用 C 语言开发的,使用 taos-jdbcdriver 驱动包时需要依赖系统对应的本地函数库。
-
-- libtaos.so 在 Linux 系统中成功安装 TDengine 后,依赖的本地函数库 libtaos.so 文件会被自动拷贝至 /usr/lib/libtaos.so,该目录包含在 Linux 自动扫描路径上,无需单独指定。
-- taos.dll 在 Windows 系统中安装完客户端之后,驱动包依赖的 taos.dll 文件会自动拷贝到系统默认搜索路径 C:/Windows/System32 下,同样无需要单独指定。
+- 已安装 Java 1.8 或以上版本运行时环境和 Maven 3.6 或以上版本
+- 已安装 TDengine 客户端驱动(使用原生连接必须安装,使用 REST 连接无需安装),具体步骤请参考[安装客户端驱动](/reference/connector#安装客户端驱动)
-**注意**:在 Windows 环境开发时需要安装 TDengine 对应的 [windows 客户端](https://www.taosdata.com/cn/all-downloads/#TDengine-Windows-Client),Linux 服务器安装完 TDengine 之后默认已安装 client,也可以单独安装 [Linux 客户端](https://www.taosdata.com/cn/getting-started/#快速上手) 连接远程 TDengine Server。
+### 安装连接器
-### 通过 maven 获取 JDBC driver
+
+
目前 taos-jdbcdriver 已经发布到 [Sonatype Repository](https://search.maven.org/artifact/com.taosdata.jdbc/taos-jdbcdriver) 仓库,且各大仓库都已同步。
@@ -122,51 +77,41 @@ TDengine 目前支持时间戳、数字、字符、布尔类型,与 Java 对
- [mvnrepository](https://mvnrepository.com/artifact/com.taosdata.jdbc/taos-jdbcdriver)
- [maven.aliyun](https://maven.aliyun.com/mvn/search)
-maven 项目中,在 pom.xml 中添加以下依赖:
+Maven 项目中,在 pom.xml 中添加以下依赖:
```xml-dtd
com.taosdata.jdbc
taos-jdbcdriver
- 2.0.18
+ 2.0.**
```
-### 通过源码编译获取 JDBC driver
+
+
-可以通过下载 TDengine 的源码,自己编译最新版本的 java connector
+可以通过下载 TDengine 的源码,自己编译最新版本的 Java connector
```shell
git clone https://github.com/taosdata/TDengine.git
cd TDengine/src/connector/jdbc
-mvn clean package -Dmaven.test.skip=true
+mvn clean install -Dmaven.test.skip=true
```
-编译后,在 target 目录下会产生 taos-jdbcdriver-2.0.XX-dist.jar 的 jar 包。
+编译后,在 target 目录下会产生 taos-jdbcdriver-2.0.XX-dist.jar 的 jar 包,并自动将编译的 jar 文件放在本地的 Maven 仓库中。
-## Java 连接器的使用
+
+
-### 获取连接
+## 建立连接
-#### 指定 URL 获取连接
-
-通过指定 URL 获取连接,如下所示:
-
-```java
-Class.forName("com.taosdata.jdbc.rs.RestfulDriver");
-String jdbcUrl = "jdbc:TAOS-RS://taosdemo.com:6041/test?user=root&password=taosdata";
-Connection conn = DriverManager.getConnection(jdbcUrl);
-```
-
-以上示例,使用 **JDBC-RESTful** 的 driver,建立了到 hostname 为 taosdemo.com,端口为 6041,数据库名为 test 的连接。这个 URL 中指定用户名(user)为 root,密码(password)为 taosdata。
-
-使用 JDBC-RESTful 接口,不需要依赖本地函数库。与 JDBC-JNI 相比,仅需要:
+TDengine 的 JDBC URL 规范格式为:
+`jdbc:[TAOS|TAOS-RS]://[host_name]:[port]/[database_name]?[user={user}|&password={password}|&charset={charset}|&cfgdir={config_dir}|&locale={locale}|&timezone={timezone}]`
-1. driverClass 指定为“com.taosdata.jdbc.rs.RestfulDriver”;
-2. jdbcUrl 以“jdbc:TAOS-RS://”开头;
-3. 使用 6041 作为连接端口。
+对于建立连接,原生连接器与 REST 连接器有细微不同。
-如果希望获得更好的写入和查询性能,Java 应用可以使用 **JDBC-JNI** 的 driver,如下所示:
+
+
```java
Class.forName("com.taosdata.jdbc.TSDBDriver");
@@ -174,16 +119,9 @@ String jdbcUrl = "jdbc:TAOS://taosdemo.com:6030/test?user=root&password=taosdata
Connection conn = DriverManager.getConnection(jdbcUrl);
```
-以上示例,使用了 JDBC-JNI 的 driver,建立了到 hostname 为 taosdemo.com,端口为 6030(TDengine 的默认端口),数据库名为 test 的连接。这个 URL 中指定用户名(user)为 root,密码(password)为 taosdata。
-
-**注意**:使用 JDBC-JNI 的 driver,taos-jdbcdriver 驱动包时需要依赖系统对应的本地函数库(Linux 下是 libtaos.so;Windows 下是 taos.dll)。
+以上示例,使用了 JDBC 原生连接的 TSDBDriver,建立了到 hostname 为 taosdemo.com,端口为 6030(TDengine 的默认端口),数据库名为 test 的连接。这个 URL 中指定用户名(user)为 root,密码(password)为 taosdata。
-> 在 Windows 环境开发时需要安装 TDengine 对应的 [windows 客户端](https://www.taosdata.com/cn/all-downloads/#TDengine-Windows-Client),Linux 服务器安装完 TDengine 之后默认已安装 client,也可以单独安装 [Linux 客户端](https://www.taosdata.com/cn/getting-started/#%E5%AE%A2%E6%88%B7%E7%AB%AF) 连接远程 TDengine Server。
-
-JDBC-JNI 的使用请参见[视频教程](https://www.taosdata.com/blog/2020/11/11/1955.html)。
-
-TDengine 的 JDBC URL 规范格式为:
-`jdbc:[TAOS|TAOS-RS]://[host_name]:[port]/[database_name]?[user={user}|&password={password}|&charset={charset}|&cfgdir={config_dir}|&locale={locale}|&timezone={timezone}]`
+**注意**:使用 JDBC 原生连接,taos-jdbcdriver 需要依赖客户端驱动(Linux 下是 libtaos.so;Windows 下是 taos.dll)。
url 中的配置参数如下:
@@ -193,46 +131,14 @@ url 中的配置参数如下:
- charset:客户端使用的字符集,默认值为系统字符集。
- locale:客户端语言环境,默认值系统当前 locale。
- timezone:客户端使用的时区,默认值为系统当前时区。
-- batchfetch: 仅在使用 JDBC-JNI 时生效。true:在执行查询时批量拉取结果集;false:逐行拉取结果集。默认值为:false。
-- timestampFormat: 仅在使用 JDBC-RESTful 时生效. 'TIMESTAMP':结果集中 timestamp 类型的字段为一个 long 值; 'UTC':结果集中 timestamp 类型的字段为一个 UTC 时间格式的字符串; 'STRING':结果集中 timestamp 类型的字段为一个本地时间格式的字符串。默认值为'STRING'。
-- batchErrorIgnore:true:在执行 Statement 的 executeBatch 时,如果中间有一条 sql 执行失败,继续执行下面的 sq 了。false:不再执行失败 sql 后的任何语句。默认值为:false。
+- batchfetch: true:在执行查询时批量拉取结果集;false:逐行拉取结果集。默认值为:false。开启批量拉取同时获取一批数据在查询数据量较大时批量拉取可以有效的提升查询性能。
+- batchErrorIgnore:true:在执行 Statement 的 executeBatch 时,如果中间有一条 SQL 执行失败将继续执行下面的 SQL。false:不再执行失败 SQL 后的任何语句。默认值为:false。
-#### 指定 URL 和 Properties 获取连接
+JDBC 原生连接的使用请参见[视频教程](https://www.taosdata.com/blog/2020/11/11/1955.html)。
-除了通过指定的 URL 获取连接,还可以使用 Properties 指定建立连接时的参数,如下所示:
+**使用 TDengine 客户端驱动配置文件建立连接 **
-```java
-public Connection getConn() throws Exception{
- Class.forName("com.taosdata.jdbc.TSDBDriver");
- // Class.forName("com.taosdata.jdbc.rs.RestfulDriver");
- String jdbcUrl = "jdbc:TAOS://taosdemo.com:6030/test?user=root&password=taosdata";
- // String jdbcUrl = "jdbc:TAOS-RS://taosdemo.com:6041/test?user=root&password=taosdata";
- Properties connProps = new Properties();
- connProps.setProperty(TSDBDriver.PROPERTY_KEY_CHARSET, "UTF-8");
- connProps.setProperty(TSDBDriver.PROPERTY_KEY_LOCALE, "en_US.UTF-8");
- connProps.setProperty(TSDBDriver.PROPERTY_KEY_TIME_ZONE, "UTC-8");
- Connection conn = DriverManager.getConnection(jdbcUrl, connProps);
- return conn;
-}
-```
-
-以上示例,建立一个到 hostname 为 taosdemo.com,端口为 6030,数据库名为 test 的连接。注释为使用 JDBC-RESTful 时的方法。这个连接在 url 中指定了用户名(user)为 root,密码(password)为 taosdata,并在 connProps 中指定了使用的字符集、语言环境、时区等信息。
-
-properties 中的配置参数如下:
-
-- TSDBDriver.PROPERTY_KEY_USER:登录 TDengine 用户名,默认值 'root'。
-- TSDBDriver.PROPERTY_KEY_PASSWORD:用户登录密码,默认值 'taosdata'。
-- TSDBDriver.PROPERTY_KEY_CONFIG_DIR:客户端配置文件目录路径,Linux OS 上默认值 `/etc/taos`,Windows OS 上默认值 `C:/TDengine/cfg`。
-- TSDBDriver.PROPERTY_KEY_CHARSET:客户端使用的字符集,默认值为系统字符集。
-- TSDBDriver.PROPERTY_KEY_LOCALE:客户端语言环境,默认值系统当前 locale。
-- TSDBDriver.PROPERTY_KEY_TIME_ZONE:客户端使用的时区,默认值为系统当前时区。
-- TSDBDriver.PROPERTY_KEY_BATCH_LOAD: 仅在使用 JDBC-JNI 时生效。true:在执行查询时批量拉取结果集;false:逐行拉取结果集。默认值为:false。
-- TSDBDriver.PROPERTY_KEY_TIMESTAMP_FORMAT: 仅在使用 JDBC-RESTful 时生效. 'TIMESTAMP':结果集中 timestamp 类型的字段为一个 long 值; 'UTC':结果集中 timestamp 类型的字段为一个 UTC 时间格式的字符串; 'STRING':结果集中 timestamp 类型的字段为一个本地时间格式的字符串。默认值为'STRING'。
-- TSDBDriver.PROPERTY_KEY_BATCH_ERROR_IGNORE:true:在执行 Statement 的 executeBatch 时,如果中间有一条 sql 执行失败,继续执行下面的 sq 了。false:不再执行失败 sql 后的任何语句。默认值为:false。
-
-#### 使用客户端配置文件建立连接
-
-当使用 JDBC-JNI 连接 TDengine 集群时,可以使用客户端配置文件,在客户端配置文件中指定集群的 firstEp、secondEp 参数。如下所示:
+当使用 JDBC 原生连接连接 TDengine 集群时,可以使用 TDengine 客户端驱动配置文件,在配置文件中指定集群的 firstEp、secondEp 等参数。如下所示:
1. 在 Java 应用中不指定 hostname 和 port
@@ -251,7 +157,7 @@ public Connection getConn() throws Exception{
2. 在配置文件中指定 firstEp 和 secondEp
-```
+```shell
# first fully qualified domain name (FQDN) for TDengine system
firstEp cluster_node1:6030
@@ -269,19 +175,107 @@ secondEp cluster_node2:6030
TDengine 中,只要保证 firstEp 和 secondEp 中一个节点有效,就可以正常建立到集群的连接。
-> 注意:这里的配置文件指的是调用 JDBC Connector 的应用程序所在机器上的配置文件,Linux OS 上默认值 /etc/taos/taos.cfg ,Windows OS 上默认值 C://TDengine/cfg/taos.cfg。
+> **注意**:这里的配置文件指的是调用 JDBC Connector 的应用程序所在机器上的配置文件,Linux OS 上默认值 /etc/taos/taos.cfg ,Windows OS 上默认值 C://TDengine/cfg/taos.cfg。
-#### 配置参数的优先级
+
+
-通过以上 3 种方式获取连接,如果配置参数在 url、Properties、客户端配置文件中有重复,则参数的`优先级由高到低`分别如下:
+```java
+Class.forName("com.taosdata.jdbc.rs.RestfulDriver");
+String jdbcUrl = "jdbc:TAOS-RS://taosdemo.com:6041/test?user=root&password=taosdata";
+Connection conn = DriverManager.getConnection(jdbcUrl);
+```
+
+以上示例,使用了 JDBC REST 连接的 RestfulDriver,建立了到 hostname 为 taosdemo.com,端口为 6041,数据库名为 test 的连接。这个 URL 中指定用户名(user)为 root,密码(password)为 taosdata。
+
+使用 JDBC REST 连接,不需要依赖客户端驱动。与 JDBC 原生连接相比,仅需要:
+
+1. driverClass 指定为“com.taosdata.jdbc.rs.RestfulDriver”;
+2. jdbcUrl 以“jdbc:TAOS-RS://”开头;
+3. 使用 6041 作为连接端口。
+
+url 中的配置参数如下:
+
+- user:登录 TDengine 用户名,默认值 'root'。
+- password:用户登录密码,默认值 'taosdata'。
+- batchfetch: true:在执行查询时批量拉取结果集;false:逐行拉取结果集。默认值为:false。逐行拉取结果集使用 HTTP 方式进行数据传输。从 taos-jdbcdriver-2.0.38 和 TDengine 2.4.0.12 版本开始,JDBC REST 连接增加批量拉取数据功能。taos-jdbcdriver 与 TDengine 之间通过 WebSocket 连接进行数据传输。相较于 HTTP,WebSocket 可以使 JDBC REST 连接支持大数据量查询,并提升查询性能。
+- batchErrorIgnore:true:在执行 Statement 的 executeBatch 时,如果中间有一条 SQL 执行失败,继续执行下面的 SQL 了。false:不再执行失败 SQL 后的任何语句。默认值为:false。
+
+**注意**:部分配置项(比如:locale、timezone)在 REST 连接中不生效。
+
+:::note
+
+- 与原生连接方式不同,REST 接口是无状态的。在使用 JDBC REST 连接时,需要在 SQL 中指定表、超级表的数据库名称。例如:
+
+```sql
+INSERT INTO test.t1 USING test.weather (ts, temperature) TAGS('beijing') VALUES(now, 24.6);
+```
+
+- 从 taos-jdbcdriver-2.0.36 和 TDengine 2.2.0.0 版本开始,如果在 url 中指定了 dbname,那么,JDBC REST 连接会默认使用/rest/sql/dbname 作为 resful 请求的 url,在 SQL 中不需要指定 dbname。例如:url 为 jdbc:TAOS-RS://127.0.0.1:6041/test,那么,可以执行 sql:insert into t1 using weather(ts, temperatrue) tags('beijing') values(now, 24.6);
+
+:::
+
+
+
+
+### 指定 URL 和 Properties 获取连接
+
+除了通过指定的 URL 获取连接,还可以使用 Properties 指定建立连接时的参数。
+
+**注意**:
+
+- 应用中设置的 client parameter 为进程级别的,即如果要更新 client 的参数,需要重启应用。这是因为 client parameter 是全局参数,仅在应用程序的第一次设置生效。
+- 以下示例代码基于 taos-jdbcdriver-2.0.36。
+
+```java
+public Connection getConn() throws Exception{
+ Class.forName("com.taosdata.jdbc.TSDBDriver");
+ String jdbcUrl = "jdbc:TAOS://taosdemo.com:6030/test?user=root&password=taosdata";
+ Properties connProps = new Properties();
+ connProps.setProperty(TSDBDriver.PROPERTY_KEY_CHARSET, "UTF-8");
+ connProps.setProperty(TSDBDriver.PROPERTY_KEY_LOCALE, "en_US.UTF-8");
+ connProps.setProperty(TSDBDriver.PROPERTY_KEY_TIME_ZONE, "UTC-8");
+ connProps.setProperty("debugFlag", "135");
+ connProps.setProperty("maxSQLLength", "1048576");
+ Connection conn = DriverManager.getConnection(jdbcUrl, connProps);
+ return conn;
+}
+
+public Connection getRestConn() throws Exception{
+ Class.forName("com.taosdata.jdbc.rs.RestfulDriver");
+ String jdbcUrl = "jdbc:TAOS-RS://taosdemo.com:6041/test?user=root&password=taosdata";
+ Properties connProps = new Properties();
+ connProps.setProperty(TSDBDriver.PROPERTY_KEY_BATCH_LOAD, "true");
+ Connection conn = DriverManager.getConnection(jdbcUrl, connProps);
+ return conn;
+}
+```
+
+以上示例,建立一个到 hostname 为 taosdemo.com,端口为 6030/6041,数据库名为 test 的连接。这个连接在 url 中指定了用户名(user)为 root,密码(password)为 taosdata,并在 connProps 中指定了使用的字符集、语言环境、时区、是否开启批量拉取等信息。
+
+properties 中的配置参数如下:
+
+- TSDBDriver.PROPERTY_KEY_USER:登录 TDengine 用户名,默认值 'root'。
+- TSDBDriver.PROPERTY_KEY_PASSWORD:用户登录密码,默认值 'taosdata'。
+- TSDBDriver.PROPERTY_KEY_BATCH_LOAD: true:在执行查询时批量拉取结果集;false:逐行拉取结果集。默认值为:false。
+- TSDBDriver.PROPERTY_KEY_BATCH_ERROR_IGNORE:true:在执行 Statement 的 executeBatch 时,如果中间有一条 SQL 执行失败,继续执行下面的 sq 了。false:不再执行失败 SQL 后的任何语句。默认值为:false。
+- TSDBDriver.PROPERTY_KEY_CONFIG_DIR:仅在使用 JDBC 原生连接时生效。客户端配置文件目录路径,Linux OS 上默认值 `/etc/taos`,Windows OS 上默认值 `C:/TDengine/cfg`。
+- TSDBDriver.PROPERTY_KEY_CHARSET:仅在使用 JDBC 原生连接时生效。 客户端使用的字符集,默认值为系统字符集。
+- TSDBDriver.PROPERTY_KEY_LOCALE:仅在使用 JDBC 原生连接时生效。 客户端语言环境,默认值系统当前 locale。
+- TSDBDriver.PROPERTY_KEY_TIME_ZONE:仅在使用 JDBC 原生连接时生效。 客户端使用的时区,默认值为系统当前时区。
+- 此外对 JDBC 原生连接,通过指定 URL 和 Properties 还可以指定其他参数,比如日志级别、SQL 长度等。更多详细配置请参考[客户端配置](/reference/config/#仅客户端适用)。
+
+### 配置参数的优先级
+
+通过前面三种方式获取连接,如果配置参数在 url、Properties、客户端配置文件中有重复,则参数的`优先级由高到低`分别如下:
1. JDBC URL 参数,如上所述,可以在 JDBC URL 的参数中指定。
2. Properties connProps
-3. 客户端配置文件 taos.cfg
+3. 使用原生连接时,TDengine 客户端驱动的配置文件 taos.cfg
例如:在 url 中指定了 password 为 taosdata,在 Properties 中指定了 password 为 taosdemo,那么,JDBC 会使用 url 中的 password 建立连接。
-> 更多详细配置请参考[客户端配置](https://www.taosdata.com/cn/documentation/administrator/#client)
+## 使用示例
### 创建数据库和表
@@ -298,7 +292,7 @@ stmt.executeUpdate("use db");
stmt.executeUpdate("create table if not exists tb (ts timestamp, temperature int, humidity float)");
```
-> 注意:如果不使用 `use db` 指定数据库,则后续对表的操作都需要增加数据库名称作为前缀,如 db.tb。
+> **注意**:如果不使用 `use db` 指定数据库,则后续对表的操作都需要增加数据库名称作为前缀,如 db.tb。
### 插入数据
@@ -350,25 +344,24 @@ try (Statement statement = connection.createStatement()) {
}
```
-JDBC 连接器可能报错的错误码包括 3 种:JDBC driver 本身的报错(错误码在 0x2301 到 0x2350 之间),JNI 方法的报错(错误码在 0x2351 到 0x2400 之间),TDengine 其他功能模块的报错。
+JDBC 连接器可能报错的错误码包括 3 种:JDBC driver 本身的报错(错误码在 0x2301 到 0x2350 之间),原生连接方法的报错(错误码在 0x2351 到 0x2400 之间),TDengine 其他功能模块的报错。
具体的错误码请参考:
- https://github.com/taosdata/TDengine/blob/develop/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBErrorNumbers.java
- https://github.com/taosdata/TDengine/blob/develop/src/inc/taoserror.h
-### 通过参数绑定写入数据
+### 通过参数绑定写入数据
+
+从 2.1.2.0 版本开始,TDengine 的 JDBC 原生连接实现大幅改进了参数绑定方式对数据写入(INSERT)场景的支持。采用这种方式写入数据时,能避免 SQL 语法解析的资源消耗,从而在很多情况下显著提升写入性能。
-从 2.1.2.0 版本开始,TDengine 的 JDBC-JNI 实现大幅改进了参数绑定方式对数据写入(INSERT)场景的支持。采用这种方式写入数据时,能避免 SQL 语法解析的资源消耗,从而在很多情况下显著提升写入性能。
-注意:
+**注意**:
-- JDBC-RESTful 实现并不提供参数绑定这种使用方式
+- JDBC REST 连接目前不支持参数绑定
- 以下示例代码基于 taos-jdbcdriver-2.0.36
- binary 类型数据需要调用 setString 方法,nchar 类型数据需要调用 setNString 方法
- setString 和 setNString 都要求用户在 size 参数里声明表定义中对应列的列宽
-示例代码:
-
```java
public class ParameterBindingDemo {
@@ -626,70 +619,49 @@ public void setString(int columnIndex, ArrayList list, int size) throws
public void setNString(int columnIndex, ArrayList list, int size) throws SQLException
```
-### 设置客户端参数
+### 无模式写入
-从 TDengine-2.3.5.0 版本开始,jdbc driver 支持在应用的第一次连接中,设置 TDengine 的客户端参数。Driver 支持 JDBC-JNI 方式中,通过 jdbcUrl 和 properties 两种方式设置 client parameter。
-注意:
+从 2.2.0.0 版本开始,TDengine 增加了对无模式写入功能。无模式写入兼容 InfluxDB 的 行协议(Line Protocol)、OpenTSDB 的 telnet 行协议和 OpenTSDB 的 JSON 格式协议。详情请参见[无模式写入](/reference/schemaless/)。
-- JDBC-RESTful 不支持设置 client parameter 的功能。
-- 应用中设置的 client parameter 为进程级别的,即如果要更新 client 的参数,需要重启应用。这是因为 client parameter 是全局参数,仅在应用程序的第一次设置生效。
-- 以下示例代码基于 taos-jdbcdriver-2.0.36。
+**注意**:
-示例代码:
+- JDBC REST 连接目前不支持无模式写入
+- 以下示例代码基于 taos-jdbcdriver-2.0.36
```java
-public class ClientParameterSetting {
+public class SchemalessInsertTest {
private static final String host = "127.0.0.1";
+ private static final String lineDemo = "st,t1=3i64,t2=4f64,t3=\"t3\" c1=3i64,c3=L\"passit\",c2=false,c4=4f64 1626006833639000000";
+ private static final String telnetDemo = "stb0_0 1626006833 4 host=host0 interface=eth0";
+ private static final String jsonDemo = "{\"metric\": \"meter_current\",\"timestamp\": 1346846400,\"value\": 10.3, \"tags\": {\"groupid\": 2, \"location\": \"Beijing\", \"id\": \"d1001\"}}";
public static void main(String[] args) throws SQLException {
- setParameterInJdbcUrl();
-
- setParameterInProperties();
- }
-
- private static void setParameterInJdbcUrl() throws SQLException {
- String jdbcUrl = "jdbc:TAOS://" + host + ":6030/?debugFlag=135&asyncLog=0";
-
- Connection connection = DriverManager.getConnection(jdbcUrl, "root", "taosdata");
-
- printDatabase(connection);
-
- connection.close();
- }
-
- private static void setParameterInProperties() throws SQLException {
- String jdbcUrl = "jdbc:TAOS://" + host + ":6030/";
- Properties properties = new Properties();
- properties.setProperty("user", "root");
- properties.setProperty("password", "taosdata");
- properties.setProperty("debugFlag", "135");
- properties.setProperty("asyncLog", "0");
- properties.setProperty("maxSQLLength", "1048576");
-
- try (Connection conn = DriverManager.getConnection(jdbcUrl, properties)) {
- printDatabase(conn);
+ final String url = "jdbc:TAOS://" + host + ":6030/?user=root&password=taosdata";
+ try (Connection connection = DriverManager.getConnection(url)) {
+ init(connection);
+
+ SchemalessWriter writer = new SchemalessWriter(connection);
+ writer.write(lineDemo, SchemalessProtocolType.LINE, SchemalessTimestampType.NANO_SECONDS);
+ writer.write(telnetDemo, SchemalessProtocolType.TELNET, SchemalessTimestampType.MILLI_SECONDS);
+ writer.write(jsonDemo, SchemalessProtocolType.JSON, SchemalessTimestampType.NOT_CONFIGURED);
}
}
- private static void printDatabase(Connection connection) throws SQLException {
+ private static void init(Connection connection) throws SQLException {
try (Statement stmt = connection.createStatement()) {
- ResultSet rs = stmt.executeQuery("show databases");
-
- ResultSetMetaData meta = rs.getMetaData();
- while (rs.next()) {
- for (int i = 1; i <= meta.getColumnCount(); i++) {
- System.out.print(meta.getColumnLabel(i) + ": " + rs.getString(i) + "\t");
- }
- System.out.println();
- }
+ stmt.executeUpdate("drop database if exists test_schemaless");
+ stmt.executeUpdate("create database if not exists test_schemaless");
+ stmt.executeUpdate("use test_schemaless");
}
}
}
```
-## 订阅
+### 订阅
-### 创建
+TDengine Java 连接器支持订阅功能,应用 API 如下:
+
+#### 创建订阅
```java
TSDBSubscribe sub = ((TSDBConnection)conn).subscribe("topic", "select * from meters", false);
@@ -703,7 +675,7 @@ TSDBSubscribe sub = ((TSDBConnection)conn).subscribe("topic", "select * from met
如上面的例子将使用 SQL 语句 `select * from meters` 创建一个名为 `topic` 的订阅,如果这个订阅已经存在,将继续之前的查询进度,而不是从头开始消费所有的数据。
-### 消费数据
+#### 订阅消费数据
```java
int total = 0;
@@ -721,7 +693,7 @@ while(true) {
`consume` 方法返回一个结果集,其中包含从上次 `consume` 到目前为止的所有新数据。请务必按需选择合理的调用 `consume` 的频率(如例子中的 `Thread.sleep(1000)`),否则会给服务端造成不必要的压力。
-### 关闭订阅
+#### 关闭订阅
```java
sub.close(true);
@@ -729,7 +701,7 @@ sub.close(true);
`close` 方法关闭一个订阅。如果其参数为 `true` 表示保留订阅进度信息,后续可以创建同名订阅继续消费数据;如为 `false` 则不保留订阅进度。
-## 关闭资源
+### 关闭资源
```java
resultSet.close();
@@ -739,9 +711,9 @@ conn.close();
> `注意务必要将 connection 进行关闭`,否则会出现连接泄露。
-## 与连接池使用
+### 与连接池使用
-### HikariCP
+#### HikariCP
使用示例如下:
@@ -775,7 +747,7 @@ conn.close();
> 通过 HikariDataSource.getConnection() 获取连接后,使用完成后需要调用 close() 方法,实际上它并不会关闭连接,只是放回连接池中。
> 更多 HikariCP 使用问题请查看[官方说明](https://github.com/brettwooldridge/HikariCP)。
-### Druid
+#### Druid
使用示例如下:
@@ -820,33 +792,48 @@ server_status()|
Query OK, 1 row(s) in set (0.000141s)
```
-## 在框架中使用
+### 更多示例程序
-- Spring JdbcTemplate 中使用 taos-jdbcdriver,可参考 [SpringJdbcTemplate](https://github.com/taosdata/TDengine/tree/develop/examples/JDBC/SpringJdbcTemplate)
-- Springboot + Mybatis 中使用,可参考 [springbootdemo](https://github.com/taosdata/TDengine/tree/develop/examples/JDBC/springbootdemo)
+示例程序源码位于 `TDengine/examples/JDBC` 下:
-## 示例程序
+- JDBCDemo:JDBC 示例源程序。
+- JDBCConnectorChecker:JDBC 安装校验源程序及 jar 包。
+- connectionPools:HikariCP, Druid, dbcp, c3p0 等连接池中使用 taos-jdbcdriver。
+- SpringJdbcTemplate:Spring JdbcTemplate 中使用 taos-jdbcdriver。
+- mybatisplus-demo:Springboot + Mybatis 中使用 taos-jdbcdriver。
-示例程序源码位于 TDengine/test/examples/JDBC 下:
+请参考:[JDBC example](https://github.com/taosdata/TDengine/tree/develop/examples/JDBC)
-- JDBCDemo:JDBC 示例源程序
-- JDBCConnectorChecker:JDBC 安装校验源程序及 jar 包
-- Springbootdemo:springboot 示例源程序
-- SpringJdbcTemplate:SpringJDBC 模板
+## 重要更新记录
-请参考:[JDBC example](https://github.com/taosdata/TDengine/tree/develop/examples/JDBC)
+| taos-jdbcdriver 版本 | 主要变化 |
+| :------------------: | :----------------------------: |
+| 2.0.38 | JDBC REST 连接增加批量拉取功能 |
+| 2.0.37 | 增加对 json tag 支持 |
+| 2.0.36 | 增加对 schemaless 写入支持 |
## 常见问题
-- 使用 Statement 的 addBatch 和 executeBatch 来执行“批量写入/更行”,为什么没有带来性能上的提升?
- **原因**:TDengine 的 JDBC 实现中,通过 addBatch 方法提交的 sql 语句,会按照添加的顺序,依次执行,这种方式没有减少与服务端的交互次数,不会带来性能上的提升。
+1. 使用 Statement 的 `addBatch` 和 `executeBatch` 来执行“批量写入/更行”,为什么没有带来性能上的提升?
+
+ **原因**:TDengine 的 JDBC 实现中,通过 `addBatch` 方法提交的 SQL 语句,会按照添加的顺序,依次执行,这种方式没有减少与服务端的交互次数,不会带来性能上的提升。
+
**解决方法**:1. 在一条 insert 语句中拼接多个 values 值;2. 使用多线程的方式并发插入;3. 使用参数绑定的写入方式
-- java.lang.UnsatisfiedLinkError: no taos in java.library.path
+
+2. java.lang.UnsatisfiedLinkError: no taos in java.library.path
+
**原因**:程序没有找到依赖的本地函数库 taos。
+
**解决方法**:Windows 下可以将 C:\TDengine\driver\taos.dll 拷贝到 C:\Windows\System32\ 目录下,Linux 下将建立如下软链 `ln -s /usr/local/taos/driver/libtaos.so.x.x.x.x /usr/lib/libtaos.so` 即可。
-- java.lang.UnsatisfiedLinkError: taos.dll Can't load AMD 64 bit on a IA 32-bit platform
+3. java.lang.UnsatisfiedLinkError: taos.dll Can't load AMD 64 bit on a IA 32-bit platform
+
**原因**:目前 TDengine 只支持 64 位 JDK。
+
**解决方法**:重新安装 64 位 JDK。
-- 其它问题请参考 [Issues](https://github.com/taosdata/TDengine/issues)
+4. 其它问题请参考 [FAQ](/train-faq/faq)
+
+## API 参考
+
+[taos-jdbcdriver doc](https://docs.taosdata.com/api/taos-jdbcdriver)
diff --git a/docs-cn/14-reference/03-connector/node.mdx b/docs-cn/14-reference/03-connector/node.mdx
index 0a34aacbcff9c499ee28665ef12337e42408a87b..c95e0dfaed8ec9ca0e10b6393bce42f1cadc08b7 100644
--- a/docs-cn/14-reference/03-connector/node.mdx
+++ b/docs-cn/14-reference/03-connector/node.mdx
@@ -1,50 +1,76 @@
---
-sidebar_position: 5
+toc_max_heading_level: 4
+sidebar_position: 6
+sidebar_label: Node.js
+title: TDengine Node.js Connector
---
-# Node.js Connector
+import Tabs from "@theme/Tabs";
+import TabItem from "@theme/TabItem";
-Node.js 连接器支持的系统有:
+import Preparition from "./_preparition.mdx";
+import NodeInsert from "../../04-develop/03-insert-data/_js_sql.mdx";
+import NodeInfluxLine from "../../04-develop/03-insert-data/_js_line.mdx";
+import NodeOpenTSDBTelnet from "../../04-develop/03-insert-data/_js_opts_telnet.mdx";
+import NodeOpenTSDBJson from "../../04-develop/03-insert-data/_js_opts_json.mdx";
+import NodeQuery from "../../04-develop/04-query-data/_js.mdx";
+import NodeAsyncQuery from "../../04-develop/04-query-data/_js_async.mdx";
-| **CPU 类型** | x64(64bit) | | | aarch64 | aarch32 |
-| ------------ | ------------ | -------- | -------- | -------- | -------- |
-| **OS 类型** | Linux | Win64 | Win32 | Linux | Linux |
-| **支持与否** | **支持** | **支持** | **支持** | **支持** | **支持** |
+`td2.0-connector` 是 TDengine 的官方 Node.js 语言连接器。Node.js 开发人员可以通过它开发可以存取 TDengine 集群数据的应用软件。
-Node.js 连接器的使用参见[视频教程](https://www.taosdata.com/blog/2020/11/11/1957.html)。
+`td2.0-connector` 支持两种形式的连接器。一种是**原生连接器**,它通过 TDengine 客户端驱动程序(taosc)连接 TDengine 运行实例,支持数据写入、查询、订阅、schemaless 接口和参数绑定接口等功能。另外一种是 **REST 连接器**,它通过 taosAdapter 提供的 REST 接口连接 TDengine 的运行实例。REST 连接器可以在任何平台运行,但性能略为下降,接口实现的功能特性集合和原生接口有少量不同。
-### 安装准备
+`td2.0-connector` 的源码托管在 [GitHub](https://github.com/taosdata/taos-connector-node)。
-- 应用驱动安装请参考[安装连接器驱动步骤](https://www.taosdata.com/cn/documentation/connector#driver)。
+## 支持的平台
-### 安装 Node.js 连接器
+原生连接器支持的平台和 TDengine 客户端驱动支持的平台一致。
+REST 连接器支持所有能运行 Node.js 的平台。
-用户可以通过[npm](https://www.npmjs.com/)来进行安装,也可以通过源代码*src/connector/nodejs/* 来进行安装。具体安装步骤如下:
+## 版本支持
-首先,通过[npm](https://www.npmjs.com/)安装 node.js 连接器。
+请参考[版本支持列表](/reference/connector#版本支持)
-```bash
-npm install td2.0-connector
-```
+## 支持的功能特性
+
+### 原生连接器
+
+1. 连接管理
+2. 普通查询
+3. 连续查询
+4. 参数绑定
+5. 订阅功能
+6. Schemaless
+
+### REST 连接器
-我们建议用户使用 npm 安装 node.js 连接器。如果您没有安装 npm,可以将*src/connector/nodejs/*拷贝到您的 nodejs 项目目录下。
+1. 连接管理
+2. 普通查询
+3. 连续查询
-我们使用[node-gyp](https://github.com/nodejs/node-gyp)和 TDengine 服务端进行交互。安装 node.js 连接器之前,还需要根据具体操作系统来安装下文提到的一些依赖工具。
+## 安装步骤
-### Linux
+### 安装前准备
+
+- 安装 Node.js 开发环境
+- 如果使用 REST 连接器,跳过此步。但如果使用原生连接器,请安装 TDengine 客户端驱动,具体步骤请参考[安装客户端驱动](/reference/connector#安装客户端驱动)。我们使用 [node-gyp](https://github.com/nodejs/node-gyp) 和 TDengine 实例进行交互,还需要根据具体操作系统来安装下文提到的一些依赖工具。
+
+
+
- `python` (建议`v2.7` , `v3.x.x` 目前还不支持)
-- `node` 2.0.6 支持 v12.x 和 v10.x,2.0.5 及更早版本支持 v10.x 版本,其他版本可能存在包兼容性的问题。
+- `td2.0-connector` 2.0.6 支持 Node.js LTS v10.9.0 或更高版本, Node.js LTS v12.8.0 或更高版本;2.0.5 及更早版本支持 Node.js LTS v10.x 版本。其他版本可能存在包兼容性的问题
- `make`
-- c 语言编译器比如[GCC](https://gcc.gnu.org)
+- C 语言编译器,[GCC](https://gcc.gnu.org) v4.8.5 或更高版本
-### Windows
+
+
-#### 安装方法 1
+- 安装方法 1
-使用微软的[windows-build-tools](https://github.com/felixrieseberg/windows-build-tools)在`cmd` 命令行界面执行`npm install --global --production windows-build-tools` 即可安装所有的必备工具。
+使用微软的[ windows-build-tools ](https://github.com/felixrieseberg/windows-build-tools)在`cmd` 命令行界面执行`npm install --global --production windows-build-tools` 即可安装所有的必备工具。
-#### 安装方法 2
+- 安装方法 2
手动安装以下工具:
@@ -52,26 +78,41 @@ npm install td2.0-connector
- 安装 [Python](https://www.python.org/downloads/) 2.7(`v3.x.x` 暂不支持) 并执行 `npm config set python python2.7`
- 进入`cmd`命令行界面,`npm config set msvs_version 2017`
-如果以上步骤不能成功执行,可以参考微软的 node.js 用户手册[Microsoft's Node.js Guidelines for Windows](https://github.com/Microsoft/nodejs-guidelines/blob/master/windows-environment.md#compiling-native-addon-modules)。
+参考微软的 Node.js 用户手册[ Microsoft's Node.js Guidelines for Windows](https://github.com/Microsoft/nodejs-guidelines/blob/master/windows-environment.md#compiling-native-addon-modules)。
如果在 Windows 10 ARM 上使用 ARM64 Node.js,还需添加 "Visual C++ compilers and libraries for ARM64" 和 "Visual C++ ATL for ARM64"。
-### 示例程序
+
+
+
+### 使用 npm 安装
+
+
+
-示例程序源码位于 install_directory/examples/nodejs,有:
+```bash
+npm install td2.0-connector
+```
-Node-example.js node.js 示例源程序
-Node-example-raw.js
+
+
+
+```bash
+npm i td2.0-rest-connector
+```
+
+
+
### 安装验证
-在安装好 TDengine 客户端后,使用 nodejsChecker.js 程序能够验证当前环境是否支持 nodejs 方式访问 Tdengine。
+在安装好 TDengine 客户端后,使用 nodejsChecker.js 程序能够验证当前环境是否支持 Node.js 方式访问 TDengine。
验证方法:
-1. 新建安装验证目录,例如:`~/tdengine-test`,拷贝 github 上 nodejsChecker.js 源程序。下载地址:(https://github.com/taosdata/TDengine/tree/develop/examples/nodejs/nodejsChecker.js)。
+- 新建安装验证目录,例如:`~/tdengine-test`,下载 GitHub 上 [nodejsChecker.js 源代码](https://github.com/taosdata/TDengine/tree/develop/examples/nodejs/nodejsChecker.js)到本地。
-2. 在命令行中执行以下命令:
+- 在命令行中执行以下命令。
```bash
npm init -y
@@ -79,121 +120,140 @@ npm install td2.0-connector
node nodejsChecker.js host=localhost
```
-3. 执行以上步骤后,在命令行会输出 nodejs 连接 Tdengine 实例,并执行简答插入和查询的结果。
+- 执行以上步骤后,在命令行会输出 nodejsChecker.js 连接 TDengine 实例,并执行简单插入和查询的结果。
-### Node.js 连接器的使用
+## 建立连接
-以下是 Node.js 连接器的一些基本使用方法,详细的使用方法可参考[TDengine Node.js connector](https://github.com/taosdata/TDengine/tree/develop/src/connector/nodejs)。
+请选择使用一种连接器。
-#### 建立连接
+
+
-使用 node.js 连接器时,必须先`require td2.0-connector`,然后使用 `taos.connect` 函数建立到服务端的连接。例如如下代码:
+安装并引用 `td2.0-connector` 包。
```javascript
+//A cursor also needs to be initialized in order to interact with TDengine from Node.js.
const taos = require("td2.0-connector");
var conn = taos.connect({
- host: "taosdemo.com",
+ host: "127.0.0.1",
user: "root",
password: "taosdata",
config: "/etc/taos",
- port: 6030,
+ port: 0,
});
var cursor = conn.cursor(); // Initializing a new cursor
-```
-建立了一个到 hostname 为 taosdemo.com,端口为 6030(Tdengine 的默认端口号)的连接。连接指定了用户名(root)和密码(taosdata)。taos.connect 函数必须提供的参数是`host`,其它参数在没有提供的情况下会使用如下的默认值。taos.connect 返回了`cursor` 对象,使用 cursor 来执行 sql 语句。
+//Close a connection
+conn.close();
+```
-#### 执行 SQL 和插入数据
+
+
-对于 DDL 语句(例如 create database、create table、use 等),可以使用 cursor 的 execute 方法。代码如下:
+安装并引用 `td2.0-rest-connector` 包。
-```js
-cursor.execute("create database if not exists test;");
+```javascript
+//A cursor also needs to be initialized in order to interact with TDengine from Node.js.
+import { options, connect } from "td2.0-rest-connector";
+options.path = "/rest/sqlt";
+// set host
+options.host = "localhost";
+// set other options like user/passwd
+
+let conn = connect(options);
+let cursor = conn.cursor();
```
-以上代码创建了一个名称为 test 的数据库。对于 DDL 语句,一般没有返回值,cursor 的 execute 返回值为 0。
+
+
-对于 Insert 语句,代码如下:
+## 使用示例
-```js
-var affectRows = cursor.execute(
- "insert into test.weather values(now, 22.3, 34);"
-);
-```
+### 写入数据
-execute 方法的返回值为该语句影响的行数,上面的 sql 向 test 库的 weather 表中,插入了一条数据,则返回值 affectRows 为 1。
+#### SQL 写入
-TDengine 目前还不支持 delete 语句。但从 2.0.8.0 版本开始,可以通过 `CREATE DATABASE` 时指定的 UPDATE 参数来启用对数据行的 update。
+
-#### 查询
+#### InfluxDB 行协议写入
-可通过 `cursor.query` 函数来查询数据库。
+
-```javascript
-var query = cursor.query("show databases;");
-```
+#### OpenTSDB Telnet 行协议写入
-查询的结果可以通过 `query.execute()` 函数获取并打印出来。
+
-```javascript
-var promise = query.execute();
-promise.then(function (result) {
- result.pretty();
-});
-```
+#### OpenTSDB JSON 行协议写入
-格式化查询语句还可以使用`query`的`bind`方法。如下面的示例:`query`会自动将提供的数值填入查询语句的`?`里。
+
-```javascript
-var query = cursor
- .query("select * from meterinfo.meters where ts <= ? and areaid = ?;")
- .bind(new Date(), 5);
-query.execute().then(function (result) {
- result.pretty();
-});
-```
+### 查询数据
-如果在`query`语句里提供第二个参数并设为`true`也可以立即获取查询结果。如下:
+#### 同步查询
-```javascript
-var promise = cursor.query(
- "select * from meterinfo.meters where v1 = 30;",
- true
-);
-promise.then(function (result) {
- result.pretty();
-});
-```
+
-#### 关闭连接
+#### 异步查询
-在完成插入、查询等操作后,要关闭连接。代码如下:
+
-```js
-conn.close();
-```
+## 更多示例程序
-#### 异步函数
+| 示例程序 | 示例程序描述 |
+| ------------------------------------------------------------------------------------------------------------------------------------------ | -------------------------------------- |
+| [connection](https://github.com/taosdata/taos-connector-node/tree/develop/nodejs/examples/cursorClose.js) | 建立连接的示例。 |
+| [stmtBindBatch](https://github.com/taosdata/taos-connector-node/tree/develop/nodejs/examples/stmtBindParamBatchSample.js) | 绑定多行参数插入的示例。 |
+| [stmtBind](https://github.com/taosdata/taos-connector-node/tree/develop/nodejs/examples/stmtBindParamSample.js) | 一行一行绑定参数插入的示例。 |
+| [stmtBindSingleParamBatch](https://github.com/taosdata/taos-connector-node/tree/develop/nodejs/examples/stmtBindSingleParamBatchSample.js) | 按列绑定参数插入的示例。 |
+| [stmtUseResult](https://github.com/taosdata/taos-connector-node/tree/develop/nodejs/examples/stmtUseResultSample.js) | 绑定参数查询的示例。 |
+| [json tag](https://github.com/taosdata/taos-connector-node/tree/develop/nodejs/examples/testJsonTag.js) | Json tag 的使用示例。 |
+| [Nanosecond](https://github.com/taosdata/taos-connector-node/tree/develop/nodejs/examples/testNanoseconds.js) | 时间戳为纳秒精度的使用的示例。 |
+| [Microsecond](https://github.com/taosdata/taos-connector-node/tree/develop/nodejs/examples/testMicroseconds.js) | 时间戳为微秒精度的使用的示例。 |
+| [schemless insert](https://github.com/taosdata/taos-connector-node/tree/develop/nodejs/examples/testSchemalessInsert.js) | schemless 插入的示例。 |
+| [subscribe](https://github.com/taosdata/taos-connector-node/tree/develop/nodejs/examples/testSubscribe.js) | 订阅的使用示例。 |
+| [asyncQuery](https://github.com/taosdata/taos-connector-node/tree/develop/nodejs/examples/tset.js) | 异步查询的使用示例。 |
+| [REST](https://github.com/taosdata/taos-connector-node/blob/develop/typescript-rest/example/example.ts) | 使用 REST 连接的 TypeScript 使用示例。 |
-异步查询数据库的操作和上面类似,只需要在`cursor.execute`, `TaosQuery.execute`等函数后面加上`_a`。
+## 使用限制
-```javascript
-var promise1 = cursor
- .query("select count(*), avg(v1), avg(v2) from meter1;")
- .execute_a();
-var promise2 = cursor
- .query("select count(*), avg(v1), avg(v2) from meter2;")
- .execute_a();
-promise1.then(function (result) {
- result.pretty();
-});
-promise2.then(function (result) {
- result.pretty();
-});
-```
+Node.js 连接器 >= v2.0.6 目前支持 node 的版本为:支持 >=v12.8.0 <= v12.9.1 || >=v10.20.0 <= v10.9.0 ;2.0.5 及更早版本支持 v10.x 版本,其他版本可能存在包兼容性的问题。
+
+## 其他说明
+
+Node.js 连接器的使用参见[视频教程](https://www.taosdata.com/blog/2020/11/11/1957.html)。
+
+## 常见问题
+
+1. 使用 REST 连接需要启动 taosadapter。
+
+ ```bash
+ sudo systemctl start taosadapter
+ ```
+
+2. Node.js 版本
+
+ 连接器 >v2.0.6 目前兼容的 Node.js 版本为:>=v10.20.0 <= v10.9.0 || >=v12.8.0 <= v12.9.1
+
+3. "Unable to establish connection","Unable to resolve FQDN"
+
+ 一般都是因为配置 FQDN 不正确。 可以参考[如何彻底搞懂 TDengine 的 FQDN](https://www.taosdata.com/blog/2021/07/29/2741.html) 。
+
+## 重要更新记录
+
+### 原生接口连接器
+
+| td2.0-connector 版本 | 说明 |
+| -------------------- | ---------------------------------------------------------------- |
+| 2.0.12 | 修复 cursor.close() 报错的 bug。 |
+| 2.0.11 | 支持绑定参数、json tag、schemaless 接口等功能。 |
+| 2.0.10 | 支持连接管理,普通查询、连续查询、获取系统信息、订阅功能等功能。 |
+
+### REST 接口连接器
-### 示例
+| td2.0-rest-connector 版本 | 说明 |
+| ------------------------- | ---------------------------------------------------------------- |
+| 1.0.3 | 支持连接管理、普通查询、获取系统信息、错误信息、连续查询等功能。 |
-[node-example.js](https://github.com/taosdata/tests/tree/master/examples/nodejs/node-example.js)提供了一个使用 NodeJS 连接器建表,插入天气数据并查询插入的数据的代码示例。
+## API 参考
-[node-example-raw.js](https://github.com/taosdata/tests/tree/master/examples/nodejs/node-example-raw.js)同样是一个使用 NodeJS 连接器建表,插入天气数据并查询插入的数据的代码示例,但和上面不同的是,该示例只使用`cursor`。
+[API 参考](https://docs.taosdata.com/api/td2.0-connector/)
diff --git a/docs-cn/14-reference/03-connector/python.mdx b/docs-cn/14-reference/03-connector/python.mdx
index dd260e499d466537d60dac7b09938443a66a33f7..abe569ed2683b84eb7cf586a15efec25237ddaf3 100644
--- a/docs-cn/14-reference/03-connector/python.mdx
+++ b/docs-cn/14-reference/03-connector/python.mdx
@@ -1,355 +1,353 @@
---
sidebar_position: 3
+sidebar_label: Python
+title: Python Connector
+description: "taospy 是 TDengine 的官方 Python 连接器。taospy 提供了丰富的 API, 使得 Python 应用可以很方便地使用 TDengine。tasopy 对 TDengine 的原生接口和 REST 接口都进行了封装, 分别对应 tasopy 的两个子模块:tasos 和 taosrest。除了对原生接口和 REST 接口的封装,taospy 还提供了符合 Python 数据访问规范(PEP 249)的编程接口。这使得 taospy 和很多第三方工具集成变得简单,比如 SQLAlchemy 和 pandas"
---
-# Python Connector
+import Tabs from "@theme/Tabs";
+import TabItem from "@theme/TabItem";
-Python 连接器的使用参见[视频教程](https://www.taosdata.com/blog/2020/11/11/1963.html)
+`taospy` 是 TDengine 的官方 Python 连接器。`taospy` 提供了丰富的 API, 使得 Python 应用可以很方便地使用 TDengine。`tasopy` 对 TDengine 的[原生接口](/reference/connector/cpp)和 [REST 接口](/reference/rest-api)都进行了封装, 分别对应 `tasopy` 包的 `taos` 模块 和 `taosrest` 模块。
+除了对原生接口和 REST 接口的封装,`taospy` 还提供了符合 [Python 数据访问规范(PEP 249)](https://peps.python.org/pep-0249/) 的编程接口。这使得 `taospy` 和很多第三方工具集成变得简单,比如 [SQLAlchemy](https://www.sqlalchemy.org/) 和 [pandas](https://pandas.pydata.org/)。
-- **安装**:参见下面具体步骤
-- **示例程序**:位于 install_directory/examples/python
+使用客户端驱动提供的原生接口直接与服务端建立的连接的方式下文中称为“原生连接”;使用 taosAdapter 提供的 REST 接口与服务端建立的连接的方式下文中称为“REST 连接”。
-### 安装
+Python 连接器的源码托管在 [GitHub](https://github.com/taosdata/taos-connector-python)。
-Python 连接器支持的系统有:Linux 64/Windows x64
+## 支持的平台
-安装前准备:
+- 原生连接[支持的平台](/reference/connector/#支持的平台)和 TDengine 客户端支持的平台一致。
+- REST 连接支持所有能运行 Python 的平台。
-- 已安装好 TDengine 应用驱动,请参考[安装连接器驱动步骤](https://www.taosdata.com/cn/documentation/connector#driver)
-- 已安装 python 2.7 or >= 3.4
-- 已安装 pip
+## 版本选择
-### Python 连接器安装
+无论使用什么版本的 TDengine 都建议使用最新版本的 `tasopy`。
-Python 连接器可以通过 `pip` 从 PyPI 下载安装。注意 TDengine Python 连接器的包名为 `taospy` 而不是 `taos`(这是一个与 TDengine 无关的另一个程序)。但为保持向后兼容性,仍然使用 `import taos` 导入。
+## 支持的功能
-```bash
-pip install taospy
-```
+- 原生连接支持 TDeingine 的所有核心功能, 包括: 连接管理、查询(包括写入)、参数绑定、订阅、无模式写入(Schemaless)。
+- REST 连接目前仅支持查询功能。
-如果不使用系统默认的 `python` 和 `pip`,则需要指定 `pip` 的版本或路径:
+## 安装
-```bash
-pip2 install taospy
-pip3 install taospy
-```
+### 准备
-Python 命令行依赖 taos 动态库 `libtaos.so` 或 `taos.dll`, 对于 Windows 客户端,安装 TDengine windows 客户端后,如果不能正常 `import taos`,可以将 `C:\TDengine\driver\taos.dll` 拷贝到 `C:\windows\system32` 目录后重新尝试。
+1. 安装 Python。建议使用 Python >= 3.6。如果系统上还没有 Python 可参考 [Python BeginnersGuide](https://wiki.python.org/moin/BeginnersGuide/Download) 安装。
+2. 安装 [pip](https://pypi.org/project/pip/)。大部分情况下 Python 的安装包都自带了 pip 工具, 如果没有请参考 [pip docuemntation](https://pip.pypa.io/en/stable/installation/) 安装。
+3. 如果使用原生连接,还需[安装客户端驱动](../#安装客户端驱动)。客户端软件包含了 TDengine 客户端动态链接库(libtaos.so 或 taos.dll) 和 TDengine CLI。
-对于无法联网用户,可以将 TDengine 客户端中的 `connector/python` 路径(Linux 下其安装路径为 `/usr/local/taos/connector/python/`,Windows 下默认安装路径为 `C:\TDengine\connector\python`)添加到 `PYTHONPATH` 环境变量中使用。
+### 使用 pip 安装
-### 示例程序
+#### 卸载旧版本
-示例程序源码位于 `/examples/python`,有:
+如果以前安装过旧版本的 Python 连接器, 请提前卸载。
-- **read_example.py** Python 示例源程序
+```
+pip3 uninstall taos taospy
+```
-用户可以参考`read_example.py`这个程序来设计用户自己的写入、查询程序。
+:::note
+较早的 TDengine 客户端软件包含了 Python 连接器。如果从客户端软件的安装目录安装了 Python 连接器,那么对应的 Python 包名是 `taos`。 所以上述卸载命令包含了 `taos`, 不存在也没关系。
-在安装了对应的应用驱动后,通过`import taos`引入 taos 类。主要步骤如下:
+:::
-- 通过 taos.connect 获取 TaosConnection 对象,这个对象可以一个程序只申请一个,在多线程中共享。
+#### 安装 `tasopy`
-- 通过 TaosConnection 对象的 `.cursor()` 方法获取一个新的游标对象,这个游标对象必须保证每个线程独享。
+
+
-- 通过游标对象的 execute()方法,执行写入或查询的 SQL 语句。
+安装最新版本
-- 如果执行的是写入语句,execute 返回的是成功写入的行数信息 affected rows。
+```
+pip3 install taospy
+```
-- 如果执行的是查询语句,则 execute 执行成功后,需要通过 fetchall 方法去拉取结果集。 具体方法可以参考示例代码。
+也可以指定某个特定版本安装。
-### 安装验证
+```
+pip3 install taospy==2.3.0
+```
-运行如下指令:
+
+
-```bash
-cd {install_directory}/examples/python/PYTHONConnectorChecker/`
-python3 PythonChecker.py -host
+```
+pip3 install git+https://github.com/taosdata/taos-connector-python.git
```
-验证通过将打印出成功信息。
+
+
-### Python 连接器的使用
+### 安装验证
-#### PEP-249 兼容 API
+
+
-您可以像其他数据库一样,使用类似 [PEP-249](https://www.python.org/dev/peps/pep-0249/) 数据库 API 规范风格的 API:
+对于原生连接,需要验证客户端驱动和 Python 连接器本身是否都正确安装。如果能成功导入 `taos` 模块,则说明已经正确安装了客户端驱动和 Python 连接器。可在 Python 交互式 Shell 中输入:
```python
import taos
+```
+
+
+
-conn = taos.connect()
-cursor = conn.cursor()
+对于 REST 连接,只需验证是否能成功导入 `taosrest` 模块。可在 Python 交互式 Shell 中输入:
-cursor.execute("show databases")
-results = cursor.fetchall()
-for row in results:
- print(row)
+```python
+import taosrest
```
-##### 代码示例
+
+
-1. 导入 TDengine 客户端模块
+:::tip
+如果系统上有多个版本的 Python,则可能有多个 `pip` 命令。要确保使用的 `pip` 命令路径是正确的。上面我们用 `pip3` 命令安装,排除了使用 Python 2.x 版本对应的 `pip` 的可能性。但是如果系统上有多个 Python 3.x 版本,仍需检查安装路径是否正确。最简单的验证方式是,在命令再次输入 `pip3 install taospy`, 就会打印出 `taospy` 的具体安装位置,比如在 Windows 上:
- ```python
- import taos
- ```
+```
+C:\> pip3 install taospy
+Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple
+Requirement already satisfied: taospy in c:\users\username\appdata\local\programs\python\python310\lib\site-packages (2.3.0)
+```
-2. 获取连接并获取游标对象
+:::
- ```python
- conn = taos.connect(host="127.0.0.1", user="root", password="taosdata", config="/etc/taos")
- c1 = conn.cursor()
- ```
+## 建立连接
- _host_ 是 TDengine 服务端所在 IP, _config_ 为客户端配置文件所在目录。
+### 连通性测试
-3. 写入数据
+在用连接器建立连接之前,建议先测试本地 TDengine CLI 到 TDengine 集群的连通性。
- ```python
- import datetime
+
+
- # 创建数据库
- c1.execute('create database db')
- c1.execute('use db')
- # 建表
- c1.execute('create table tb (ts timestamp, temperature int, humidity float)')
- # 插入数据
- start_time = datetime.datetime(2019, 11, 1)
- affected_rows = c1.execute('insert into tb values (\'%s\', 0, 0.0)' %start_time)
- # 批量插入数据
- time_interval = datetime.timedelta(seconds=60)
- sqlcmd = ['insert into tb values']
- for irow in range(1,11):
- start_time += time_interval
- sqlcmd.append('(\'%s\', %d, %f)' %(start_time, irow, irow*1.2))
- affected_rows = c1.execute(' '.join(sqlcmd))
- ```
+请确保 TDengine 集群已经启动, 且集群中机器的 FQDN (如果启动的是单机版,FQDN 默认为 hostname)在本机能够解析, 可用 ping 命令进行测试:
-4. 查询数据
+```
+ping
+```
- ```python
- c1.execute('select * from tb')
- # 拉取查询结果
- data = c1.fetchall()
- # 返回的结果是一个列表,每一行构成列表的一个元素
- numOfRows = c1.rowcount
- numOfCols = len(c1.description)
- for irow in range(numOfRows):
- print("Row%d: ts=%s, temperature=%d, humidity=%f" %(irow, data[irow][0], data[irow][1], data[irow][2]))
+然后测试用 TDengine CLI 能否正常连接集群:
- # 直接使用cursor 循环拉取查询结果
- c1.execute('select * from tb')
- for data in c1:
- print("ts=%s, temperature=%d, humidity=%f" %(data[0], data[1], data[2]))
- ```
+```
+taos -h -p
+```
-#### Query API
+上面的 FQDN 可以为集群中任意一个 dnode 的 FQDN, PORT 为这个 dnode 对应的 serverPort。
-从 v2.1.0 版本开始, 我们提供另外一种方法:`connection.query` 来操作数据库。
+
+
-```python
-import taos
+对于 REST 连接, 除了确保集群已经启动,还要确保 taosAdapter 组件已经启动。可以使用如下 curl 命令测试:
+
+```
+curl -u root:taosdata http://:/rest/sql -d "select server_version()"
+```
-conn = taos.connect()
-conn.execute("create database if not exists pytest")
+上面的 FQDN 为运行 taosAdapter 的机器的 FQDN, PORT 为 taosAdapter 配置的监听端口, 默认为 6041。
+如果测试成功,会输出服务器版本信息,比如:
-result = conn.query("show databases")
-num_of_fields = result.field_count
-for field in result.fields:
- print(field)
-for row in result:
- print(row)
-conn.execute("drop database pytest")
+```json
+{
+ "status": "succ",
+ "head": ["server_version()"],
+ "column_meta": [["server_version()", 8, 8]],
+ "data": [["2.4.0.16"]],
+ "rows": 1
+}
```
-`query` 方法会返回一个 `TaosResult` 对象,并提供了以下属性或方法:
+
+
-属性:
+### 使用连接器建立连接
-- `fields`: `TaosFields` 集合类,提供返回数据的列信息。
-- `field_count`: 返回数据的列数.
-- `affected_rows`: 插入数据的行数.
-- `row_count`: 查询数据结果数.
-- `precision`: 当前数据库的时间精度.
+以下示例代码假设 TDengine 安装在本机, 且 FQDN 和 serverPort 都使用了默认配置。
-方法:
+
+
-- `fetch_all()`: 类似于 `cursor.fetchall()` 返回同样的集合数据
-- `fetch_all_into_dict()`: v2.1.1 新添加的 API,将上面的数据转换成字典类型返回
-- `blocks_iter()` `rows_iter()`: 根据底层 API 提供的两种不同迭代器。
-- `fetch_rows_a`: 异步 API
-- `errno`: 错误码
-- `errstr`: 错误信息
-- `close`: 关闭结果对象,一般不需要直接调用
+```python
+{{#include docs-examples/python/connect_native_reference.py}}
+```
-#### 订阅 API
+`connect` 函数的所有参数都是可选的关键字参数。下面是连接参数的具体说明:
-1. 创建一个同步订阅队列:
+- `host` : 要连接的节点的 FQDN。 没有默认值。如果不同提供此参数,则会连接客户端配置文件中的 firstEP。
+- `user` :TDengine 用户名。 默认值是 root。
+- `password` : TDengine 用户密码。 默认值是 taosdata。
+- `port` : 要连接的数据节点的起始端口,即 serverPort 配置。默认值是 6030。只有在提供了 host 参数的时候,这个参数才生效。
+- `config` : 客户端配置文件路径。 在 Windows 系统上默认是 `C:\TDengine\cfg`。 在 Linux 系统上默认是 `/etc/taos/`。
+- `timezone` : 查询结果中 TIMESTAMP 类型的数据,转换为 python 的 datetime 对象时使用的时区。默认为本地时区。
- ```python
- # 创建一个主题为 'test' 消费周期为1000毫秒的订阅
- # 第一个参数为 True 表示重新开始订阅,如为 False 且之前创建过主题为 'test' 的订阅,
- # 则表示继续消费此订阅的数据,而不是重新开始消费所有数据
- sub = conn.subscribe(True, "test", "select * from tb;", 1000)
- ```
+:::warning
+`config` 和 `timezone` 都是进程级别的配置。建议一个进程建立的所有连接都使用相同的参数值。否则可能产生无法预知的错误。
+:::
-2. 消费订阅的数据
+:::tip
+`connect` 函数返回 `taos.TaosConnection` 实例。 在客户端多线程的场景下,推荐每个线程申请一个独立的连接实例,而不建议多线程共享一个连接。
- ```python
- data = sub.consume()
- for d in data:
- print(d)
- ```
+:::
-3. 取消订阅
+
+
- ```python
- sub.close()
- ```
+```python
+{{#include docs-examples/python/connect_rest_examples.py:connect}}
+```
-4. 关闭连接
+`connect` 函数的所有参数都是可选的关键字参数。下面是连接参数的具体说明:
- ```python
- conn.close()
- ```
+- `host`: 要连接的主机。默认是 localhost。
+- `user`: TDenigne 用户名。默认是 root。
+- `password`: TDeingine 用户密码。默认是 taosdata。
+- `port`: taosAdapter REST 服务监听端口。默认是 6041.
+- `timeout`: HTTP 请求超时时间。单位为秒。默认为 `socket._GLOBAL_DEFAULT_TIMEOUT`。 一般无需配置。
-#### JSON 类型
+:::note
-从 `taospy` `v2.2.0` 开始,Python 连接器开始支持 JSON 数据类型的标签(TDengine 版本要求 Beta 版 2.3.5+, 稳定版 2.4.0+)。
+:::
-创建一个使用 JSON 类型标签的超级表及其子表:
+
+
-```python
-# encoding:UTF-8
-import taos
+## 示例程序
-conn = taos.connect()
-conn.execute("create database if not exists py_test_json_type")
-conn.execute("use py_test_json_type")
+### 基本使用
-conn.execute("create stable s1 (ts timestamp, v1 int) tags (info json)")
-conn.execute("create table s1_1 using s1 tags ('{\"k1\": \"v1\"}')")
-```
+
+
-查询子表标签及表名:
+##### TaosConnection 类的使用
-```python
-tags = conn.query("select info, tbname from s1").fetch_all_into_dict()
-tags
+`TaosConnection` 类既包含对 PEP249 Connection 接口的实现(如:`cursor`方法和 `close` 方法),也包含很多扩展功能(如: `execute`、 `query`、`schemaless_insert` 和 `subscribe` 方法。
+
+```python title="execute 方法"
+{{#include docs-examples/python/connection_usage_native_reference.py:insert}}
```
-`tags` 内容为:
+```python title="query 方法"
+{{#include docs-examples/python/connection_usage_native_reference.py:query}}
+```
-```python
-[{'info': '{"k1":"v1"}', 'tbname': 's1_1'}]
+:::tip
+查询结果只能获取一次。比如上面的示例中 `featch_all` 和 `fetch_all_into_dict` 只能用一个。重复获取得到的结果为空列表。
+:::
+
+##### TaosResult 类的使用
+
+上面 `TaosConnection` 类的使用示例中,我们已经展示了两种获取查询结果的方法: `featch_all` 和 `fetch_all_into_dict`。除此之外 `TaosResult` 还提供了按行迭代(`rows_iter`)或按数据块迭代(`blocks_iter`)结果集的方法。在查询数据量较大的场景,使用这两个方法会更高效。
+
+```python title="blocks_iter 方法"
+{{#include docs-examples/python/result_set_examples.py}}
```
+##### TaosCursor 类的使用
-获取 JSON 中某值:
+`TaosConnection` 类和 `TaosResult` 类已经实现了原生接口的所有功能。如果你对 PEP249 规范中的接口比较熟悉也可以使用 `TaosCursor` 类提供的方法。
-```python
-k1 = conn.query("select info->'k1' as k1 from s1").fetch_all_into_dict()
-"""
->>> k1
-[{'k1': '"v1"'}]
-"""
+```python title="TaosCursor 的使用"
+{{#include docs-examples/python/cursor_usage_native_reference.py}}
```
-更多 JSON 类型的操作方式请参考 [JSON 类型使用说明](https://www.taosdata.com/cn/documentation/taos-sql)。
+:::note
+TaosCursor 类使用原生连接进行写入、查询操作。在客户端多线程的场景下,这个游标实例必须保持线程独享,不能跨线程共享使用,否则会导致返回结果出现错误。
-#### 关于纳秒 (nanosecond) 在 Python 连接器中的说明
+:::
-由于目前 Python 对 nanosecond 支持的不完善(参见链接 1. 2. ),目前的实现方式是在 nanosecond 精度时返回整数,而不是 ms 和 us 返回的 datetime 类型,应用开发者需要自行处理,建议使用 pandas 的 to_datetime()。未来如果 Python 正式完整支持了纳秒,涛思数据可能会修改相关接口。
+
+
-1. https://stackoverflow.com/questions/10611328/parsing-datetime-strings-containing-nanoseconds
-2. https://www.python.org/dev/peps/pep-0564/
+##### TaosRestCursor 类的使用
-#### 帮助信息
+`TaosRestCursor` 类是对 PEP249 Cursor 接口的实现。
-用户可通过 python 的帮助信息直接查看模块的使用信息,或者参考 tests/examples/python 中的示例程序。以下为部分常用类和方法:
+```python title="TaosRestCursor 的使用"
+{{#include docs-examples/python/connect_rest_examples.py:basic}}
+```
+- `cursor.execute` : 用来执行任意 SQL 语句。
+- `cursor.rowcount`: 对于写入操作返回写入成功记录数。对于查询操作,返回结果集行数。
+- `cursor.description` : 返回字段的描述信息。关于描述信息的具体格式请参考[TaosRestCursor](https://docs.taosdata.com/api/taospy/taosrest/cursor.html)。
-- _TaosConnection_ 类
+##### RestClient 类的使用
- 参考 python 中 help(taos.TaosConnection)。
- 这个类对应客户端和 TDengine 建立的一个连接。在客户端多线程的场景下,推荐每个线程申请一个独立的连接实例,而不建议多线程共享一个连接。
+`RestClient` 类是对于 [REST API](/reference/rest-api) 的直接封装。它只包含一个 `sql()` 方法用于执行任意 SQL 语句, 并返回执行结果。
-- _TaosCursor_ 类
+```python title="RestClient 的使用"
+{{#include docs-examples/python/rest_client_example.py}}
+```
- 参考 python 中 help(taos.TaosCursor)。
- 这个类对应客户端进行的写入、查询操作。在客户端多线程的场景下,这个游标实例必须保持线程独享,不能跨线程共享使用,否则会导致返回结果出现错误。
+对于 `sql()` 方法更详细的介绍, 请参考 [RestClient](https://docs.taosdata.com/api/taospy/taosrest/restclient.html)。
-- _connect_ 方法
- 用于生成 taos.TaosConnection 的实例。
-## RESTful Connector
+
+
-为支持各种不同类型平台的开发,TDengine 提供符合 REST 设计标准的 API,即 RESTful API。为最大程度降低学习成本,不同于其他数据库 RESTful API 的设计方法,TDengine 直接通过 HTTP POST 请求 BODY 中包含的 SQL 语句来操作数据库,仅需要一个 URL。RESTful 连接器的使用参见[视频教程](https://www.taosdata.com/blog/2020/11/11/1965.html)。
+### 与 pandas 一起使用
-注意:与原生连接器的一个区别是,RESTful 接口是无状态的,因此 `USE db_name` 指令没有效果,所有对表名、超级表名的引用都需要指定数据库名前缀。(从 2.2.0.0 版本开始,支持在 RESTful url 中指定 db_name,这时如果 SQL 语句中没有指定数据库名前缀的话,会使用 url 中指定的这个 db_name。从 2.4.0.0 版本开始,RESTful 默认有 taosAdapter 提供,要求必须在 url 中指定 db_name。)
+
+
-### 安装
+```python
+{{#include docs-examples/python/conn_native_pandas.py}}
+```
-RESTful 接口不依赖于任何 TDengine 的库,因此客户端不需要安装任何 TDengine 的库,只要客户端的开发语言支持 HTTP 协议即可。
+
+
-### 验证
+```python
+{{#include docs-examples/python/conn_rest_pandas.py}}
+```
-在已经安装 TDengine 服务器端的情况下,可以按照如下方式进行验证。
+
+
-下面以 Ubuntu 环境中使用 curl 工具(确认已经安装)来验证 RESTful 接口的正常。
+### 其它示例程序
-下面示例是列出所有的数据库,请把 h1.taosdata.com 和 6041(缺省值)替换为实际运行的 TDengine 服务 fqdn 和端口号:
+| 示例程序链接 | 示例程序内容 |
+| ------------------------------------------------------------------------------------------------------------- | ----------------------- |
+| [bind_multi.py](https://github.com/taosdata/taos-connector-python/blob/main/examples/bind-multi.py) | 参数绑定, 一次绑定多行 |
+| [bind_row.py](https://github.com/taosdata/taos-connector-python/blob/main/examples/bind-row.py) | 参数绑定,一次绑定一行 |
+| [insert_lines.py](https://github.com/taosdata/taos-connector-python/blob/main/examples/insert-lines.py) | InfluxDB 行协议写入 |
+| [json_tag.py](https://github.com/taosdata/taos-connector-python/blob/main/examples/json-tag.py) | 使用 JSON 类型的标签 |
+| [subscribe-async.py](https://github.com/taosdata/taos-connector-python/blob/main/examples/subscribe-async.py) | 异步订阅 |
+| [subscribe-sync.py](https://github.com/taosdata/taos-connector-python/blob/main/examples/subscribe-sync.py) | 同步订阅 |
-```html
-curl -H 'Authorization: Basic cm9vdDp0YW9zZGF0YQ==' -d 'show databases;'
-h1.taosdata.com:6041/rest/sql
-```
+## 其它说明
-返回值结果如下表示验证通过:
+### 异常处理
-```json
-{
- "status": "succ",
- "head": [
- "name",
- "created_time",
- "ntables",
- "vgroups",
- "replica",
- "quorum",
- "days",
- "keep1,keep2,keep(D)",
- "cache(MB)",
- "blocks",
- "minrows",
- "maxrows",
- "wallevel",
- "fsync",
- "comp",
- "precision",
- "status"
- ],
- "data": [
- [
- "log",
- "2020-09-02 17:23:00.039",
- 4,
- 1,
- 1,
- 1,
- 10,
- "30,30,30",
- 1,
- 3,
- 100,
- 4096,
- 1,
- 3000,
- 2,
- "us",
- "ready"
- ]
- ],
- "rows": 1
-}
+所有数据库操作如果出现异常,都会直接抛出来。由应用程序负责异常处理。比如:
+
+```python
+{{#include docs-examples/python/handle_exception.py}}
```
+
+### 关于纳秒 (nanosecond)
+
+由于目前 Python 对 nanosecond 支持的不完善(见下面的链接),目前的实现方式是在 nanosecond 精度时返回整数,而不是 ms 和 us 返回的 datetime 类型,应用开发者需要自行处理,建议使用 pandas 的 to_datetime()。未来如果 Python 正式完整支持了纳秒,Python 连接器可能会修改相关接口。
+
+1. https://stackoverflow.com/questions/10611328/parsing-datetime-strings-containing-nanoseconds
+2. https://www.python.org/dev/peps/pep-0564/
+
+
+## 常见问题
+
+欢迎[提问或报告问题](https://github.com/taosdata/taos-connector-python/issues)。
+
+## 重要更新
+
+| 连接器版本 | 重要更新 | 发布日期 |
+| ---------- | --------------------------------------------------------------------------------- | ---------- |
+| 2.3.1 | 1. support TDengine REST API
2. remove support for Python version below 3.6 | 2022-04-28 |
+| 2.2.5 | support timezone option when connect | 2022-04-13 |
+| 2.2.2 | support sqlalchemy dialect plugin | 2022-03-28 |
+
+
+[**Release Notes**](https://github.com/taosdata/taos-connector-python/releases)
+
+## API 参考
+
+- [taos](https://docs.taosdata.com/api/taospy/taos/)
+- [taosrest](https://docs.taosdata.com/api/taospy/taosrest)
diff --git a/docs-cn/14-reference/03-connector/rust.mdx b/docs-cn/14-reference/03-connector/rust.mdx
index 4928e1f0795651bac4fdf96f5f692aa11c82e996..2f7f466ca2ea8e97bb2c8f6b622916c4cf59180a 100644
--- a/docs-cn/14-reference/03-connector/rust.mdx
+++ b/docs-cn/14-reference/03-connector/rust.mdx
@@ -1,110 +1,388 @@
-# Rust Connector
+---
+toc_max_heading_level: 4
+sidebar_position: 5
+sidebar_label: Rust
+title: TDengine Rust Connector
+---
- 
+import Tabs from '@theme/Tabs';
+import TabItem from '@theme/TabItem';
-> Rust 连接器仍然在快速开发中,版本 API 变动在所难免,在 1.0 之前无法保证其向后兼容,请使用时注意版本及对应的文档。
+import Preparition from "./_preparition.mdx"
+import RustInsert from "../../04-develop/03-insert-data/_rust_sql.mdx"
+import RustInfluxLine from "../../04-develop/03-insert-data/_rust_line.mdx"
+import RustOpenTSDBTelnet from "../../04-develop/03-insert-data/_rust_opts_telnet.mdx"
+import RustOpenTSDBJson from "../../04-develop/03-insert-data/_rust_opts_json.mdx"
+import RustQuery from "../../04-develop/04-query-data/_rust.mdx"
-感谢 [@songtianyi](https://github.com/songtianyi) 对 [libtdengine](https://github.com/songtianyi/tdengine-rust-bindings) 的贡献,使 Rust 社区能够使用 Rust 连接[TDengine]. [libtaos-rs] 项目旨在为 Rust 开发者提供官方支持,使用 taosc 接口及 HTTP 接口构建兼容 API 以便于用户切换接口方式。
+[](https://crates.io/crates/libtaos)  [](https://docs.rs/libtaos)
-## 依赖
+`libtaos` 是 TDengine 的官方 Rust 语言连接器。Rust 开发人员可以通过它开发存取 TDengine 数据库的应用软件。
-- [Rust](https://www.rust-lang.org/learn/get-started)
+`libtaos` 提供两种形式的连接器。一种是**原生连接器**,它通过 TDengine 客户端驱动程序(taosc)连接 TDengine 运行实例。另外一种是 **REST 连接器**,它通过 taosAdapter 的 REST 接口连接 TDengine 运行实例。你可以通过不同的 “特性(即 Cargo 关键字 features)” 来指定使用哪种连接器。REST 连接器可以在任何平台运行,但原生连接器依赖 TDengine 客户端能运行的平台。
-默认情况下,[libtaos-rs] 使用 C 接口连接数据库,所以您需要:
+`libtaos` 的源码托管在 [GitHub](https://github.com/taosdata/libtaos-rs)。
-- [TDengine 客户端](https://www.taosdata.com/cn/getting-started/#%E9%80%9A%E8%BF%87%E5%AE%89%E8%A3%85%E5%8C%85%E5%AE%89%E8%A3%85)
-- `clang`: `bindgen` 使用 `libclangAST` 来生成对应的 Rust 绑定。
+## 支持的平台
-## 特性列表
+原生连接器支持的平台和 TDengine 客户端驱动支持的平台一致。
+REST 连接器支持所有能运行 Rust 的平台。
-- [x] C 接口的 Rust 绑定
-- [x] 使用 `rest` feature 来启用 RESTful API.
-- [x] [r2d2] 连接池支持(feature `r2d2`)
-- [ ] 迭代器接口
-- [ ] 流式计算接口
-- [ ] 订阅支持
+## 版本支持
-## 构建和测试
+请参考[版本支持列表](/reference/connector#版本支持)
-```sh
-cargo build
-cargo test
-```
+Rust 连接器仍然在快速开发中,1.0 之前无法保证其向后兼容。建议使用 2.4 版本以上的 TDengine,以避免已知问题。
+
+## 安装
-测试使用默认用户名密码和本地连接。您可以根据具体情况设置环境变量:
+### 安装前准备
+* 安装 Rust 开发工具链
+* 如果使用原生连接器,请安装 TDengine 客户端驱动,具体步骤请参考[安装客户端驱动](/reference/connector#安装客户端驱动)
-- `TEST_TAOS_IP`
-- `TEST_TAOS_PORT`
-- `TEST_TAOS_USER`
-- `TEST_TAOS_PASS`
-- `TEST_TAOS_DB`
+### 添加 libtaos 依赖
-## 使用
+根据选择的连接器,按照如下说明在 [Rust](https://rust-lang.org) 项目中添加 [libtaos][libtaos] 依赖:
-使用默认的 taosc 连接方式,可以在 `Cargo.toml` 中直接添加 `libtaos` 依赖:
+
+
+
+在 `Cargo.toml` 文件中添加 [libtaos][libtaos]:
```toml
[dependencies]
-libtaos = "v0.3.8"
+# use default feature
+libtaos = "*"
```
-添加 feature `r2d2` 来启动连接池:
+
+
+
+在 `Cargo.toml` 文件中添加 [libtaos][libtaos],并启用 `rest` 特性。
```toml
[dependencies]
-libtaos = { version = "*", features = ["r2d2"] }
+# use rest feature
+libtaos = { version = "*", features = ["rest"]}
```
-对于 RESTful 接口,可使用 `rest` 特性来替代 taosc,免去安装 TDengine 客户端。
+
+
+
+
+### 使用连接池
+
+请在 `Cargo.toml` 中启用 `r2d2` 特性。
```toml
[dependencies]
-libtaos = { version = "*", features = ["rest"] }
+# with taosc
+libtaos = { version = "*", features = ["r2d2"] }
+# or rest
+libtaos = { version = "*", features = ["rest", "r2d2"] }
+```
+
+## 建立连接
+
+[TaosCfgBuilder] 为使用者提供构造器形式的 API,以便于后续创建连接或使用连接池。
+
+```rust
+let cfg: TaosCfg = TaosCfgBuilder::default()
+ .ip("127.0.0.1")
+ .user("root")
+ .pass("taosdata")
+ .db("log") // do not set if not require a default database.
+ .port(6030u16)
+ .build()
+ .expect("TaosCfg builder error");
+}
```
-本项目中提供一个 [示例程序](https://github.com/taosdata/libtaos-rs/blob/main/examples/demo.rs) 如下:
+现在您可以使用该对象创建连接:
```rust
+let conn = cfg.connect()?;
+```
+
+连接对象可以创建多个:
+
+```rust
+let conn = cfg.connect()?;
+let conn2 = cfg.connect()?;
+```
+
+可以在应用中使用连接池:
+
+```rust
+let pool = r2d2::Pool::builder()
+ .max_size(10000) // max connections
+ .build(cfg)?;
+
// ...
-#[tokio::main]
-async fn main() -> Result<(), Error> {
- init();
- let taos = taos_connect()?;
-
- assert_eq!(
- taos.query("drop database if exists demo").await.is_ok(),
- true
- );
- assert_eq!(taos.query("create database demo").await.is_ok(), true);
- assert_eq!(taos.query("use demo").await.is_ok(), true);
- assert_eq!(
- taos.query("create table m1 (ts timestamp, speed int)")
- .await
- .is_ok(),
- true
- );
-
- for i in 0..10i32 {
- assert_eq!(
- taos.query(format!("insert into m1 values (now+{}s, {})", i, i).as_str())
- .await
- .is_ok(),
- true
- );
- }
- let rows = taos.query("select * from m1").await?;
+// Use pool to get connection
+let conn = pool.get()?;
+```
- println!("{}", rows.column_meta.into_iter().map(|col| col.name).join(","));
+之后您可以对数据库进行相关操作:
+
+```rust
+async fn demo() -> Result<(), Error> {
+ // get connection ...
+
+ // create database
+ conn.exec("create database if not exists demo").await?;
+ // change database context
+ conn.exec("use demo").await?;
+ // create table
+ conn.exec("create table if not exists tb1 (ts timestamp, v int)").await?;
+ // insert
+ conn.exec("insert into tb1 values(now, 1)").await?;
+ // query
+ let rows = conn.query("select * from tb1").await?;
for row in rows.rows {
println!("{}", row.into_iter().join(","));
}
- Ok(())
}
```
-您可以在 [bailongma-rs] - 一个 Rust 编写的 Prometheus 远程存储 API 适配器 - 看到如何在具体应用中使用 Rust 连接器。
+## 使用示例
+
+### 写入数据
+
+#### SQL 写入
+
+
+
+#### InfluxDB 行协议写入
+
+
+
+#### OpenTSDB Telnet 行协议写入
+
+
+
+#### OpenTSDB JSON 行协议写入
+
+
+
+### 查询数据
+
+
+
+### 更多示例程序
+
+| 程序路径 | 程序说明 |
+| -------------- | ----------------------------------------------------------------------------- |
+| [demo.rs] | 基本API 使用示例 |
+| [bailongma-rs] | 使用 TDengine 作为存储后端的 Prometheus 远程存储 API 适配器,使用 r2d2 连接池 |
+
+## API 参考
+
+### 连接构造器 API
+
+[Builder Pattern](https://doc.rust-lang.org/1.0.0/style/ownership/builders.html) 构造器模式是 Rust 处理复杂数据类型或可选配置类型的解决方案。[libtaos] 实现中,使用连接构造器 [TaosCfgBuilder] 作为 TDengine Rust 连接器的入口。[TaosCfgBuilder] 提供对服务器、端口、数据库、用户名和密码等的可选配置。
+
+使用 `default()` 方法可以构建一个默认参数的 [TaosCfg],用于后续连接数据库或建立连接池。
+
+```rust
+let cfg = TaosCfgBuilder::default().build()?;
+```
+
+使用构造器模式,用户可按需设置:
+
+```rust
+let cfg = TaosCfgBuilder::default()
+ .ip("127.0.0.1")
+ .user("root")
+ .pass("taosdata")
+ .db("log")
+ .port(6030u16)
+ .build()?;
+```
+
+使用 [TaosCfg] 对象创建 TDengine 连接:
+
+```rust
+let conn: Taos = cfg.connect();
+```
+
+### 连接池
+
+在复杂应用中,建议启用连接池。[libtaos] 的连接池使用 [r2d2] 实现。
+
+如下,可以生成一个默认参数的连接池。
+
+```rust
+let pool = r2d2::Pool::new(cfg)?;
+```
+
+同样可以使用连接池的构造器,对连接池参数进行设置:
+
+```rust
+ use std::time::Duration;
+ let pool = r2d2::Pool::builder()
+ .max_size(5000) // max connections
+ .max_lifetime(Some(Duration::from_minutes(100))) // lifetime of each connection
+ .min_idle(Some(1000)) // minimal idle connections
+ .connection_timeout(Duration::from_minutes(2))
+ .build(cfg);
+```
+
+在应用代码中,使用 `pool.get()?` 来获取一个连接对象 [Taos]。
+
+```rust
+let taos = pool.get()?;
+```
+
+### 连接
+
+[Taos] 结构体是 [libtaos] 中的连接管理者,主要提供了两个 API:
+
+1. `exec`: 执行某个非查询类 SQL 语句,例如 `CREATE`,`ALTER`,`INSERT` 等。
+
+ ```rust
+ taos.exec().await?;
+ ```
+
+2. `query`:执行查询语句,返回 [TaosQueryData] 对象。
+
+ ```rust
+ let q = taos.query("select * from log.logs").await?;
+ ```
+
+ [TaosQueryData] 对象存储了查询结果数据和返回的列的基本信息(列名,类型,长度):
+
+ 列信息使用 [ColumnMeta] 存储:
+
+ ```rust
+ let cols = &q.column_meta;
+ for col in cols {
+ println!("name: {}, type: {:?}, bytes: {}", col.name, col.type_, col.bytes);
+ }
+ ```
+
+ 逐行获取数据:
+
+ ```rust
+ for (i, row) in q.rows.iter().enumerate() {
+ for (j, cell) in row.iter().enumerate() {
+ println!("cell({}, {}) data: {}", i, j, cell);
+ }
+ }
+ ```
+
+需要注意的是,需要使用 Rust 异步函数和异步运行时。
+
+[Taos] 提供部分 SQL 的 Rust 方法化以减少 `format!` 代码块的频率:
+
+- `.describe(table: &str)`: 执行 `DESCRIBE` 并返回一个 Rust 数据结构。
+- `.create_database(database: &str)`: 执行 `CREATE DATABASE` 语句。
+- `.use_database(database: &str)`: 执行 `USE` 语句。
+
+除此之外,该结构也是 [参数绑定](#参数绑定接口) 和 [行协议接口](#行协议接口) 的入口,使用方法请参考具体的 API 说明。
+
+### 参数绑定接口
+
+与 C 接口类似,Rust 提供参数绑定接口。首先,通过 [Taos] 对象创建一个 SQL 语句的参数绑定对象 [Stmt]:
+
+```rust
+let mut stmt: Stmt = taos.stmt("insert into ? values(?,?)")?;
+```
+
+参数绑定对象提供了一组接口用于实现参数绑定:
+
+##### `.set_tbname(tbname: impl ToCString)`
+
+用于绑定表名。
+
+##### `.set_tbname_tags(tbname: impl ToCString, tags: impl IntoParams)`
+
+当 SQL 语句使用超级表时,用于绑定子表表名和标签值:
+
+```rust
+let mut stmt = taos.stmt("insert into ? using stb0 tags(?) values(?,?)")?;
+// tags can be created with any supported type, here is an example using JSON
+let v = Field::Json(serde_json::from_str("{\"tag1\":\"一二三四五六七八九十\"}").unwrap());
+stmt.set_tbname_tags("tb0", [&tag])?;
+```
+
+##### `.bind(params: impl IntoParams)`
+
+用于绑定值类型。使用 [Field] 结构体构建需要的类型并绑定:
+
+```rust
+let ts = Field::Timestamp(Timestamp::now());
+let value = Field::Float(0.0);
+stmt.bind(vec![ts, value].iter())?;
+```
+
+##### `.execute()`
+
+执行 SQL。[Stmt] 对象可以复用,在执行后可以重新绑定并执行。
+
+```rust
+stmt.execute()?;
+
+// next bind cycle.
+//stmt.set_tbname()?;
+//stmt.bind()?;
+//stmt.execute()?;
+```
+
+### 行协议接口
+
+行协议接口支持多种模式和不同精度,需要引入 schemaless 模块中的常量以进行设置:
+
+```rust
+use libtaos::*;
+use libtaos::schemaless::*;
+```
+
+- InfluxDB 行协议
+
+ ```rust
+ let lines = [
+ "st,t1=abc,t2=def,t3=anything c1=3i64,c3=L\"pass\",c2=false 1626006833639000000"
+ "st,t1=abc,t2=def,t3=anything c1=3i64,c3=L\"abc\",c4=4f64 1626006833639000000"
+ ];
+ taos.schemaless_insert(&lines, TSDB_SML_LINE_PROTOCOL, TSDB_SML_TIMESTAMP_NANOSECONDS)?;
+ ```
+
+- OpenTSDB Telnet 协议
+
+ ```rust
+ let lines = ["sys.if.bytes.out 1479496100 1.3E3 host=web01 interface=eth0"];
+ taos.schemaless_insert(&lines, TSDB_SML_LINE_PROTOCOL, TSDB_SML_TIMESTAMP_SECONDS)?;
+ ```
+
+- OpenTSDB JSON 协议
+
+ ```rust
+ let lines = [r#"
+ {
+ "metric": "st",
+ "timestamp": 1626006833,
+ "value": 10,
+ "tags": {
+ "t1": true,
+ "t2": false,
+ "t3": 10,
+ "t4": "123_abc_.!@#$%^&*:;,./?|+-=()[]{}<>"
+ }
+ }"#];
+ taos.schemaless_insert(&lines, TSDB_SML_LINE_PROTOCOL, TSDB_SML_TIMESTAMP_SECONDS)?;
+ ```
+
+其他相关结构体 API 使用说明请移步 Rust 文档托管网页:。
-[libtaos-rs]: https://github.com/taosdata/libtaos-rs
+[libtaos]: https://github.com/taosdata/libtaos-rs
[tdengine]: https://github.com/taosdata/TDengine
[bailongma-rs]: https://github.com/taosdata/bailongma-rs
[r2d2]: https://crates.io/crates/r2d2
+[demo.rs]: https://github.com/taosdata/libtaos-rs/blob/main/examples/demo.rs
+[TaosCfgBuilder]: https://docs.rs/libtaos/latest/libtaos/struct.TaosCfgBuilder.html
+[TaosCfg]: https://docs.rs/libtaos/latest/libtaos/struct.TaosCfg.html
+[Taos]: https://docs.rs/libtaos/latest/libtaos/struct.Taos.html
+[TaosQueryData]: https://docs.rs/libtaos/latest/libtaos/field/struct.TaosQueryData.html
+[Field]: https://docs.rs/libtaos/latest/libtaos/field/enum.Field.html
+[Stmt]: https://docs.rs/libtaos/latest/libtaos/stmt/struct.Stmt.html
diff --git a/docs-cn/14-reference/03-connector/tdengine-jdbc-connector.png b/docs-cn/14-reference/03-connector/tdengine-jdbc-connector.png
new file mode 100644
index 0000000000000000000000000000000000000000..1cb8401ea30b01d8db652ed4ea70ecc511de7461
Binary files /dev/null and b/docs-cn/14-reference/03-connector/tdengine-jdbc-connector.png differ
diff --git a/docs-cn/14-reference/04-taosadapter.md b/docs-cn/14-reference/04-taosadapter.md
new file mode 100644
index 0000000000000000000000000000000000000000..158d4ab008c3b3eca28cd469c38f451b22678518
--- /dev/null
+++ b/docs-cn/14-reference/04-taosadapter.md
@@ -0,0 +1,338 @@
+---
+title: "taosAdapter"
+description: "taosAdapter 是一个 TDengine 的配套工具,是 TDengine 集群和应用程序之间的桥梁和适配器。它提供了一种易于使用和高效的方式来直接从数据收集代理软件(如 Telegraf、StatsD、collectd 等)摄取数据。它还提供了 InfluxDB/OpenTSDB 兼容的数据摄取接口,允许 InfluxDB/OpenTSDB 应用程序无缝移植到 TDengine"
+sidebar_label: "taosAdapter"
+---
+
+import Prometheus from "./_prometheus.mdx"
+import CollectD from "./_collectd.mdx"
+import StatsD from "./_statsd.mdx"
+import Icinga2 from "./_icinga2.mdx"
+import Tcollector from "./_tcollector.mdx"
+
+taosAdapter 是一个 TDengine 的配套工具,是 TDengine 集群和应用程序之间的桥梁和适配器。它提供了一种易于使用和高效的方式来直接从数据收集代理软件(如 Telegraf、StatsD、collectd 等)摄取数据。它还提供了 InfluxDB/OpenTSDB 兼容的数据摄取接口,允许 InfluxDB/OpenTSDB 应用程序无缝移植到 TDengine。
+
+taosAdapter 提供以下功能:
+
+- RESTful 接口
+- 兼容 InfluxDB v1 写接口
+- 兼容 OpenTSDB JSON 和 telnet 格式写入
+- 无缝连接到 Telegraf
+- 无缝连接到 collectd
+- 无缝连接到 StatsD
+- 支持 Prometheus remote_read 和 remote_write
+
+## taosAdapter 架构图
+
+
+
+## taosAdapter 部署方法
+
+### 安装 taosAdapter
+
+taosAdapter 从 TDengine v2.4.0.0 版本开始成为 TDengine 服务端软件 的一部分,如果您使用 TDengine server 您不需要任何额外的步骤来安装 taosAdapter。您可以从[涛思数据官方网站](https://taosdata.com/cn/all-downloads/)下载 TDengine server(taosAdapter 包含在 v2.4.0.0 及以上版本)安装包。如果需要将 taosAdapter 分离部署在 TDengine server 之外的服务器上,则应该在该服务器上安装完整的 TDengine 来安装 taosAdapter。如果您需要使用源代码编译生成 taosAdapter,您可以参考[构建 taosAdapter](https://github.com/taosdata/taosadapter/blob/develop/BUILD-CN.md)文档。
+
+### start/stop taosAdapter
+
+在 Linux 系统上 taosAdapter 服务默认由 systemd 管理。使用命令 `systemctl start taosadapter` 可以启动 taosAdapter 服务。使用命令 `systemctl stop taosadapter` 可以停止 taosAdapter 服务。
+
+### 移除 taosAdapter
+
+使用命令 rmtaos 可以移除包括 taosAdapter 在内的 TDengine server 软件。
+
+### 升级 taosAdapter
+
+taosAdapter 和 TDengine server 需要使用相同版本。请通过升级 TDengine server 来升级 taosAdapter。
+与 taosd 分离部署的 taosAdapter 必须通过升级其所在服务器的 TDengine server 才能得到升级。
+
+## taosAdapter 参数列表
+
+taosAdapter 支持通过命令行参数、环境变量和配置文件来进行配置。默认配置文件是 /etc/taos/taosadapter.toml。
+
+命令行参数优先于环境变量优先于配置文件,命令行用法是 arg=val,如 taosadapter -p=30000 --debug=true,详细列表如下:
+
+```shell
+Usage of taosAdapter:
+ --collectd.db string collectd db name. Env "TAOS_ADAPTER_COLLECTD_DB" (default "collectd")
+ --collectd.enable enable collectd. Env "TAOS_ADAPTER_COLLECTD_ENABLE" (default true)
+ --collectd.password string collectd password. Env "TAOS_ADAPTER_COLLECTD_PASSWORD" (default "taosdata")
+ --collectd.port int collectd server port. Env "TAOS_ADAPTER_COLLECTD_PORT" (default 6045)
+ --collectd.user string collectd user. Env "TAOS_ADAPTER_COLLECTD_USER" (default "root")
+ --collectd.worker int collectd write worker. Env "TAOS_ADAPTER_COLLECTD_WORKER" (default 10)
+ -c, --config string config path default /etc/taos/taosadapter.toml
+ --cors.allowAllOrigins cors allow all origins. Env "TAOS_ADAPTER_CORS_ALLOW_ALL_ORIGINS" (default true)
+ --cors.allowCredentials cors allow credentials. Env "TAOS_ADAPTER_CORS_ALLOW_Credentials"
+ --cors.allowHeaders stringArray cors allow HEADERS. Env "TAOS_ADAPTER_ALLOW_HEADERS"
+ --cors.allowOrigins stringArray cors allow origins. Env "TAOS_ADAPTER_ALLOW_ORIGINS"
+ --cors.allowWebSockets cors allow WebSockets. Env "TAOS_ADAPTER_CORS_ALLOW_WebSockets"
+ --cors.exposeHeaders stringArray cors expose headers. Env "TAOS_ADAPTER_Expose_Headers"
+ --debug enable debug mode. Env "TAOS_ADAPTER_DEBUG"
+ --help Print this help message and exit
+ --influxdb.enable enable influxdb. Env "TAOS_ADAPTER_INFLUXDB_ENABLE" (default true)
+ --log.path string log path. Env "TAOS_ADAPTER_LOG_PATH" (default "/var/log/taos")
+ --log.rotationCount uint log rotation count. Env "TAOS_ADAPTER_LOG_ROTATION_COUNT" (default 30)
+ --log.rotationSize string log rotation size(KB MB GB), must be a positive integer. Env "TAOS_ADAPTER_LOG_ROTATION_SIZE" (default "1GB")
+ --log.rotationTime duration log rotation time. Env "TAOS_ADAPTER_LOG_ROTATION_TIME" (default 24h0m0s)
+ --logLevel string log level (panic fatal error warn warning info debug trace). Env "TAOS_ADAPTER_LOG_LEVEL" (default "info")
+ --monitor.collectDuration duration Set monitor duration. Env "TAOS_MONITOR_COLLECT_DURATION" (default 3s)
+ --monitor.identity string The identity of the current instance, or 'hostname:port' if it is empty. Env "TAOS_MONITOR_IDENTITY"
+ --monitor.incgroup Whether running in cgroup. Env "TAOS_MONITOR_INCGROUP"
+ --monitor.password string TDengine password. Env "TAOS_MONITOR_PASSWORD" (default "taosdata")
+ --monitor.pauseAllMemoryThreshold float Memory percentage threshold for pause all. Env "TAOS_MONITOR_PAUSE_ALL_MEMORY_THRESHOLD" (default 80)
+ --monitor.pauseQueryMemoryThreshold float Memory percentage threshold for pause query. Env "TAOS_MONITOR_PAUSE_QUERY_MEMORY_THRESHOLD" (default 70)
+ --monitor.user string TDengine user. Env "TAOS_MONITOR_USER" (default "root")
+ --monitor.writeInterval duration Set write to TDengine interval. Env "TAOS_MONITOR_WRITE_INTERVAL" (default 30s)
+ --monitor.writeToTD Whether write metrics to TDengine. Env "TAOS_MONITOR_WRITE_TO_TD" (default true)
+ --node_exporter.caCertFile string node_exporter ca cert file path. Env "TAOS_ADAPTER_NODE_EXPORTER_CA_CERT_FILE"
+ --node_exporter.certFile string node_exporter cert file path. Env "TAOS_ADAPTER_NODE_EXPORTER_CERT_FILE"
+ --node_exporter.db string node_exporter db name. Env "TAOS_ADAPTER_NODE_EXPORTER_DB" (default "node_exporter")
+ --node_exporter.enable enable node_exporter. Env "TAOS_ADAPTER_NODE_EXPORTER_ENABLE"
+ --node_exporter.gatherDuration duration node_exporter gather duration. Env "TAOS_ADAPTER_NODE_EXPORTER_GATHER_DURATION" (default 5s)
+ --node_exporter.httpBearerTokenString string node_exporter http bearer token. Env "TAOS_ADAPTER_NODE_EXPORTER_HTTP_BEARER_TOKEN_STRING"
+ --node_exporter.httpPassword string node_exporter http password. Env "TAOS_ADAPTER_NODE_EXPORTER_HTTP_PASSWORD"
+ --node_exporter.httpUsername string node_exporter http username. Env "TAOS_ADAPTER_NODE_EXPORTER_HTTP_USERNAME"
+ --node_exporter.insecureSkipVerify node_exporter skip ssl check. Env "TAOS_ADAPTER_NODE_EXPORTER_INSECURE_SKIP_VERIFY" (default true)
+ --node_exporter.keyFile string node_exporter cert key file path. Env "TAOS_ADAPTER_NODE_EXPORTER_KEY_FILE"
+ --node_exporter.password string node_exporter password. Env "TAOS_ADAPTER_NODE_EXPORTER_PASSWORD" (default "taosdata")
+ --node_exporter.responseTimeout duration node_exporter response timeout. Env "TAOS_ADAPTER_NODE_EXPORTER_RESPONSE_TIMEOUT" (default 5s)
+ --node_exporter.urls strings node_exporter urls. Env "TAOS_ADAPTER_NODE_EXPORTER_URLS" (default [http://localhost:9100])
+ --node_exporter.user string node_exporter user. Env "TAOS_ADAPTER_NODE_EXPORTER_USER" (default "root")
+ --opentsdb.enable enable opentsdb. Env "TAOS_ADAPTER_OPENTSDB_ENABLE" (default true)
+ --opentsdb_telnet.dbs strings opentsdb_telnet db names. Env "TAOS_ADAPTER_OPENTSDB_TELNET_DBS" (default [opentsdb_telnet,collectd_tsdb,icinga2_tsdb,tcollector_tsdb])
+ --opentsdb_telnet.enable enable opentsdb telnet,warning: without auth info(default false). Env "TAOS_ADAPTER_OPENTSDB_TELNET_ENABLE"
+ --opentsdb_telnet.maxTCPConnections int max tcp connections. Env "TAOS_ADAPTER_OPENTSDB_TELNET_MAX_TCP_CONNECTIONS" (default 250)
+ --opentsdb_telnet.password string opentsdb_telnet password. Env "TAOS_ADAPTER_OPENTSDB_TELNET_PASSWORD" (default "taosdata")
+ --opentsdb_telnet.ports ints opentsdb telnet tcp port. Env "TAOS_ADAPTER_OPENTSDB_TELNET_PORTS" (default [6046,6047,6048,6049])
+ --opentsdb_telnet.tcpKeepAlive enable tcp keep alive. Env "TAOS_ADAPTER_OPENTSDB_TELNET_TCP_KEEP_ALIVE"
+ --opentsdb_telnet.user string opentsdb_telnet user. Env "TAOS_ADAPTER_OPENTSDB_TELNET_USER" (default "root")
+ --pool.idleTimeout duration Set idle connection timeout. Env "TAOS_ADAPTER_POOL_IDLE_TIMEOUT" (default 1h0m0s)
+ --pool.maxConnect int max connections to taosd. Env "TAOS_ADAPTER_POOL_MAX_CONNECT" (default 4000)
+ --pool.maxIdle int max idle connections to taosd. Env "TAOS_ADAPTER_POOL_MAX_IDLE" (default 4000)
+ -P, --port int http port. Env "TAOS_ADAPTER_PORT" (default 6041)
+ --prometheus.enable enable prometheus. Env "TAOS_ADAPTER_PROMETHEUS_ENABLE" (default true)
+ --restfulRowLimit int restful returns the maximum number of rows (-1 means no limit). Env "TAOS_ADAPTER_RESTFUL_ROW_LIMIT" (default -1)
+ --ssl.certFile string ssl cert file path. Env "TAOS_ADAPTER_SSL_CERT_FILE"
+ --ssl.enable enable ssl. Env "TAOS_ADAPTER_SSL_ENABLE"
+ --ssl.keyFile string ssl key file path. Env "TAOS_ADAPTER_SSL_KEY_FILE"
+ --statsd.allowPendingMessages int statsd allow pending messages. Env "TAOS_ADAPTER_STATSD_ALLOW_PENDING_MESSAGES" (default 50000)
+ --statsd.db string statsd db name. Env "TAOS_ADAPTER_STATSD_DB" (default "statsd")
+ --statsd.deleteCounters statsd delete counter cache after gather. Env "TAOS_ADAPTER_STATSD_DELETE_COUNTERS" (default true)
+ --statsd.deleteGauges statsd delete gauge cache after gather. Env "TAOS_ADAPTER_STATSD_DELETE_GAUGES" (default true)
+ --statsd.deleteSets statsd delete set cache after gather. Env "TAOS_ADAPTER_STATSD_DELETE_SETS" (default true)
+ --statsd.deleteTimings statsd delete timing cache after gather. Env "TAOS_ADAPTER_STATSD_DELETE_TIMINGS" (default true)
+ --statsd.enable enable statsd. Env "TAOS_ADAPTER_STATSD_ENABLE" (default true)
+ --statsd.gatherInterval duration statsd gather interval. Env "TAOS_ADAPTER_STATSD_GATHER_INTERVAL" (default 5s)
+ --statsd.maxTCPConnections int statsd max tcp connections. Env "TAOS_ADAPTER_STATSD_MAX_TCP_CONNECTIONS" (default 250)
+ --statsd.password string statsd password. Env "TAOS_ADAPTER_STATSD_PASSWORD" (default "taosdata")
+ --statsd.port int statsd server port. Env "TAOS_ADAPTER_STATSD_PORT" (default 6044)
+ --statsd.protocol string statsd protocol [tcp or udp]. Env "TAOS_ADAPTER_STATSD_PROTOCOL" (default "udp")
+ --statsd.tcpKeepAlive enable tcp keep alive. Env "TAOS_ADAPTER_STATSD_TCP_KEEP_ALIVE"
+ --statsd.user string statsd user. Env "TAOS_ADAPTER_STATSD_USER" (default "root")
+ --statsd.worker int statsd write worker. Env "TAOS_ADAPTER_STATSD_WORKER" (default 10)
+ --taosConfigDir string load taos client config path. Env "TAOS_ADAPTER_TAOS_CONFIG_FILE"
+ --version Print the version and exit
+```
+
+备注:
+使用浏览器进行接口调用请根据实际情况设置如下跨源资源共享(CORS)参数:
+
+```text
+AllowAllOrigins
+AllowOrigins
+AllowHeaders
+ExposeHeaders
+AllowCredentials
+AllowWebSockets
+```
+
+如果不通过浏览器进行接口调用无需关心这几项配置。
+
+关于 CORS 协议细节请参考:[https://www.w3.org/wiki/CORS_Enabled](https://www.w3.org/wiki/CORS_Enabled) 或 [https://developer.mozilla.org/zh-CN/docs/Web/HTTP/CORS](https://developer.mozilla.org/zh-CN/docs/Web/HTTP/CORS)。
+
+示例配置文件参见 [example/config/taosadapter.toml](https://github.com/taosdata/taosadapter/blob/develop/example/config/taosadapter.toml)。
+
+## 功能列表
+
+- 与 RESTful 接口兼容
+ [https://www.taosdata.com/cn/documentation/connector#restful](https://www.taosdata.com/cn/documentation/connector#restful)
+- 兼容 InfluxDB v1 写接口
+ [https://docs.influxdata.com/influxdb/v2.0/reference/api/influxdb-1x/write/](https://docs.influxdata.com/influxdb/v2.0/reference/api/influxdb-1x/write/)
+- 兼容 OpenTSDB JSON 和 telnet 格式写入
+ -
+ -
+- 与 collectd 无缝连接
+ collectd 是一个系统统计收集守护程序,请访问 [https://collectd.org/](https://collectd.org/) 了解更多信息。
+- Seamless connection with StatsD
+ StatsD 是一个简单而强大的统计信息汇总的守护程序。请访问 [https://github.com/statsd/statsd](https://github.com/statsd/statsd) 了解更多信息。
+- 与 icinga2 的无缝连接
+ icinga2 是一个收集检查结果指标和性能数据的软件。请访问 [https://icinga.com/docs/icinga-2/latest/doc/14-features/#opentsdb-writer](https://icinga.com/docs/icinga-2/latest/doc/14-features/#opentsdb-writer) 了解更多信息。
+- 与 tcollector 无缝连接
+ TCollector 是一个客户端进程,从本地收集器收集数据,并将数据推送到 OpenTSDB。请访问 [http://opentsdb.net/docs/build/html/user_guide/utilities/tcollector.html](http://opentsdb.net/docs/build/html/user_guide/utilities/tcollector.html) 了解更多信息。
+- 无缝连接 node_exporter
+ node_export 是一个机器指标的导出器。请访问 [https://github.com/prometheus/node_exporter](https://github.com/prometheus/node_exporter) 了解更多信息。
+- 支持 Prometheus remote_read 和 remote_write
+ remote_read 和 remote_write 是 Prometheus 数据读写分离的集群方案。请访问[https://prometheus.io/blog/2019/10/10/remote-read-meets-streaming/#remote-apis](https://prometheus.io/blog/2019/10/10/remote-read-meets-streaming/#remote-apis) 了解更多信息。
+
+## 接口
+
+### TDengine RESTful 接口
+
+您可以使用任何支持 http 协议的客户端通过访问 RESTful 接口地址 `http://:6041/` 来写入数据到 TDengine 或从 TDengine 中查询数据。细节请参考[官方文档](/reference/connector#restful)。支持如下 EndPoint :
+
+```text
+/rest/sql
+/rest/sqlt
+/rest/sqlutc
+```
+
+### InfluxDB
+
+您可以使用任何支持 http 协议的客户端访问 Restful 接口地址 `http://:6041/` 来写入 InfluxDB 兼容格式的数据到 TDengine。EndPoint 如下:
+
+```text
+/influxdb/v1/write
+```
+
+支持 InfluxDB 查询参数如下:
+
+- `db` 指定 TDengine 使用的数据库名
+- `precision` TDengine 使用的时间精度
+- `u` TDengine 用户名
+- `p` TDengine 密码
+
+注意: 目前不支持 InfluxDB 的 token 验证方式只支持 Basic 验证和查询参数验证。
+
+### OpenTSDB
+
+您可以使用任何支持 http 协议的客户端访问 Restful 接口地址 `http://:6041/` 来写入 OpenTSDB 兼容格式的数据到 TDengine。EndPoint 如下:
+
+```text
+/opentsdb/v1/put/json/:db
+/opentsdb/v1/put/telnet/:db
+```
+
+### collectd
+
+
+
+### StatsD
+
+
+
+### icinga2 OpenTSDB writer
+
+
+
+### TCollector
+
+
+
+### node_exporter
+
+Prometheus 使用的由\*NIX 内核暴露的硬件和操作系统指标的输出器
+
+- 启用 taosAdapter 的配置 node_exporter.enable
+- 设置 node_exporter 的相关配置
+- 重新启动 taosAdapter
+
+### prometheus
+
+
+
+## 内存使用优化方法
+
+taosAdapter 将监测自身运行过程中内存使用率并通过两个阈值进行调节。有效值范围为 -1 到 100 的整数,单位为系统物理内存的百分比。
+
+- pauseQueryMemoryThreshold
+- pauseAllMemoryThreshold
+
+当超过 pauseQueryMemoryThreshold 阈值时时停止处理查询请求。
+
+http 返回内容:
+
+- code 503
+- body "query memory exceeds threshold"
+
+当超过 pauseAllMemoryThreshold 阈值时停止处理所有写入和查询请求。
+
+http 返回内容:
+
+- code 503
+- body "memory exceeds threshold"
+
+当内存回落到阈值之下时恢复对应功能。
+
+状态检查接口 `http://:6041/-/ping`
+
+- 正常返回 `code 200`
+- 无参数 如果内存超过 pauseAllMemoryThreshold 将返回 `code 503`
+- 请求参数 `action=query` 如果内存超过 pauseQueryMemoryThreshold 或 pauseAllMemoryThreshold 将返回 `code 503`
+
+对应配置参数
+
+```text
+ monitor.collectDuration 监测间隔 环境变量 "TAOS_MONITOR_COLLECT_DURATION" (默认值 3s)
+ monitor.incgroup 是否是cgroup中运行(容器中运行设置为 true) 环境变量 "TAOS_MONITOR_INCGROUP"
+ monitor.pauseAllMemoryThreshold 不再进行插入和查询的内存阈值 环境变量 "TAOS_MONITOR_PAUSE_ALL_MEMORY_THRESHOLD" (默认值 80)
+ monitor.pauseQueryMemoryThreshold 不再进行查询的内存阈值 环境变量 "TAOS_MONITOR_PAUSE_QUERY_MEMORY_THRESHOLD" (默认值 70)
+```
+
+您可以根据具体项目应用场景和运营策略进行相应调整,并建议使用运营监控软件及时进行系统内存状态监控。负载均衡器也可以通过这个接口检查 taosAdapter 运行状态。
+
+## taosAdapter 监控指标
+
+taosAdapter 采集 http 相关指标、cpu 百分比和内存百分比。
+
+### http 接口
+
+提供符合 [OpenMetrics](https://github.com/OpenObservability/OpenMetrics/blob/main/specification/OpenMetrics.md) 接口:
+
+```text
+http://:6041/metrics
+```
+
+### 写入 TDengine
+
+taosAdapter 支持将 http 监控、cpu 百分比和内存百分比写入 TDengine。
+
+有关配置参数
+
+| **配置项** | **描述** | **默认值** |
+| ----------------------- | --------------------------------------------------------- | ---------- |
+| monitor.collectDuration | cpu 和内存采集间隔 | 3s |
+| monitor.identity | 当前 taosadapter 的标识符如果不设置将使用 'hostname:port' | |
+| monitor.incgroup | 是否是 cgroup 中运行(容器中运行设置为 true) | false |
+| monitor.writeToTD | 是否写入到 TDengine | true |
+| monitor.user | TDengine 连接用户名 | root |
+| monitor.password | TDengine 连接密码 | taosdata |
+| monitor.writeInterval | 写入 TDengine 间隔 | 30s |
+
+## 结果返回条数限制
+
+taosAdapter 通过参数 `restfulRowLimit` 来控制结果的返回条数,-1 代表无限制,默认无限制。
+
+该参数控制以下接口返回
+
+- `http://:6041/rest/sql`
+- `http://:6041/rest/sqlt`
+- `http://:6041/rest/sqlutc`
+- `http://:6041/prometheus/v1/remote_read/:db`
+
+## 故障解决
+
+您可以通过命令 `systemctl status taosadapter` 来检查 taosAdapter 运行状态。
+
+您也可以通过设置 --logLevel 参数或者环境变量 TAOS_ADAPTER_LOG_LEVEL 来调节 taosAdapter 日志输出详细程度。有效值包括: panic、fatal、error、warn、warning、info、debug 以及 trace。
+
+## 如何从旧版本 TDengine 迁移到 taosAdapter
+
+在 TDengine server 2.2.x.x 或更早期版本中,taosd 进程包含一个内嵌的 http 服务。如前面所述,taosAdapter 是一个使用 systemd 管理的独立软件,拥有自己的进程。并且两者有一些配置参数和行为是不同的,请见下表:
+
+| **#** | **embedded httpd** | **taosAdapter** | **comment** |
+| ----- | ------------------- | ------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------ |
+| 1 | httpEnableRecordSql | --logLevel=debug | |
+| 2 | httpMaxThreads | n/a | taosAdapter 自动管理线程池,无需此参数 |
+| 3 | telegrafUseFieldNum | 请参考 taosAdapter telegraf 配置方法 | |
+| 4 | restfulRowLimit | restfulRowLimit | 内嵌 httpd 默认输出 10240 行数据,最大允许值为 102400。taosAdapter 也提供 restfulRowLimit 但是默认不做限制。您可以根据实际场景需求进行配置 |
+| 5 | httpDebugFlag | 不适用 | httpdDebugFlag 对 taosAdapter 不起作用 |
+| 6 | httpDBNameMandatory | 不适用 | taosAdapter 要求 URL 中必须指定数据库名 |
diff --git a/docs-cn/14-reference/05-taosbenchmark.md b/docs-cn/14-reference/05-taosbenchmark.md
new file mode 100644
index 0000000000000000000000000000000000000000..c8668dedc5527f667dedf5fee9b54872047f0a51
--- /dev/null
+++ b/docs-cn/14-reference/05-taosbenchmark.md
@@ -0,0 +1,431 @@
+---
+title: taosBenchmark
+sidebar_label: taosBenchmark
+toc_max_heading_level: 4
+---
+
+## 简介
+
+taosBenchmark (曾用名 taosdemo ) 是一个用于测试 TDengine 产品性能的工具。taosBenchmark 可以测试 TDengine 的插入、查询和订阅等功能的性能,它可以模拟由大量设备产生的大量数据,还可以灵活地控制数据库、超级表、标签列的数量和类型、数据列的数量和类型、子表的数量、每张子表的数据量、插入数据的时间间隔、taosBenchmark 的工作线程数量、是否以及如何插入乱序数据等。为了兼容过往用户的使用习惯,安装包提供 了 taosdemo 作为 taosBenchmark 的软链接。
+
+## 安装
+
+taosBenchmark 有两种安装方式:
+
+- 安装 TDengine 官方安装包的同时会自动安装 taosBenchmark, 详情请参考[ TDengine 安装](/operation/pkg-install)。
+
+- 单独编译 taos-tools 并安装, 详情请参考 [taos-tools](https://github.com/taosdata/taos-tools) 仓库。
+
+## 运行
+
+### 配置和运行方式
+
+taosBenchmark 支持两种配置方式:[命令行参数](#命令行参数详解) 和 [JSON 配置文件](#配置文件参数详解)。这两种方式是互斥的,在使用配置文件时只能使用一个命令行参数 `-f ` 指定配置文件。在使用命令行参数运行 taosBenchmark 并控制其行为时则不能使用 `-f` 参数而要用其它参数来进行配置。除此之外,taosBenchmark 还提供了一种特殊的运行方式,即无参数运行。
+
+taosBenchmark 支持对 TDengine 做完备的性能测试,其所支持的 TDengine 功能分为三大类:写入、查询和订阅。这三种功能之间是互斥的,每次运行 taosBenchmark 只能选择其中之一。值得注意的是,所要测试的功能类型在使用命令行配置方式时是不可配置的,命令行配置方式只能测试写入性能。若要测试 TDegnine 的查询和订阅性能,必须使用配置文件的方式,通过配置文件中的参数 `filetype` 指定所要测试的功能类型。
+
+**在运行 taosBenchmark 之前要确保 TDengine 集群已经在正确运行。**
+
+### 无命令行参数运行
+
+执行下列命令即可快速体验 taosBenchmark 对 TDengine 进行基于默认配置的写入性能测试。
+
+```bash
+taosBenchmark
+```
+
+在无参数运行时,taosBenchmark 默认连接 `/etc/taos` 下指定的 TDengine 集群,并在 TDengine 中创建一个名为 test 的数据库,test 数据库下创建名为 meters 的一张超级表,超级表下创建 10000 张表,每张表中写入 10000 条记录。注意,如果已有 test 数据库,这个命令会先删除该数据库后建立一个全新的 test 数据库。
+
+### 使用命令行配置参数运行
+
+在使用命令行参数运行 taosBenchmark 并控制其行为时,`-f ` 参数不能使用。所有配置参数都必须通过命令行指定。以下是使用命令行方式测试 taosBenchmark 写入性能的一个示例。
+
+```bash
+taosBenchmark -I stmt -n 200 -t 100
+```
+
+上面的命令 `taosBenchmark` 将创建一个名为`test`的数据库,在其中建立一张超级表`meters`,在该超级表中建立 100 张子表并使用参数绑定的方式为每张子表插入 200 条记录。
+
+### 使用配置文件运行
+
+taosBenchmark 安装包中提供了配置文件的示例,位于 `/examples/taosbenchmark-json` 下
+
+使用如下命令行即可运行 taosBenchmark 并通过配置文件控制其行为。
+
+```bash
+taosBenchmark -f
+```
+
+**下面是几个配置文件的示例:**
+
+#### 插入场景 JSON 配置文件示例
+
+
+insert.json
+
+```json
+{{#include /taos-tools/example/insert.json}}
+```
+
+
+
+#### 查询场景 JSON 配置文件示例
+
+
+query.json
+
+```json
+{{#include /taos-tools/example/query.json}}
+```
+
+
+
+#### 订阅场景 JSON 配置文件示例
+
+
+subscribe.json
+
+```json
+{{#include /taos-tools/example/subscribe.json}}
+```
+
+
+
+## 命令行参数详解
+
+- **-f/--file ** :
+ 要使用的 JSON 配置文件,由该文件指定所有参数,本参数与命令行其他参数不能同时使用。没有默认值。
+
+- **-c/--config-dir ** :
+ TDengine 集群配置文件所在的目录,默认路径是 /etc/taos 。
+
+- **-h/--host ** :
+ 指定要连接的 TDengine 服务端的 FQDN,默认值为 localhost 。
+
+- **-P/--port ** :
+ 要连接的 TDengine 服务器的端口号,默认值为 6030 。
+
+- **-I/--interface ** :
+ 插入模式,可选项有 taosc, rest, stmt, sml, sml-rest, 分别对应普通写入、restful 接口写入、参数绑定接口写入、schemaless 接口写入、restful schemaless 接口写入 (由 taosAdapter 提供)。默认值为 taosc。
+
+- **-u/--user ** :
+ 用于连接 TDengine 服务端的用户名,默认为 root 。
+
+- **-p/--password ** :
+ 用于连接 TDengine 服务端的密码,默认值为 taosdata。
+
+- **-o/--output ** :
+ 结果输出文件的路径,默认值为 ./output.txt。
+
+- **-T/--thread ** :
+ 插入数据的线程数量,默认为 8 。
+
+- **-B/--interlace-rows ** :
+ 启用交错插入模式并同时指定向每个子表每次插入的数据行数。交错插入模式是指依次向每张子表插入由本参数所指定的行数并重复这个过程,直到所有子表的数据都插入完成。默认值为 0, 即向一张子表完成数据插入后才会向下一张子表进行数据插入。
+
+- **-i/--insert-interval ** :
+ 指定交错插入模式的插入间隔,单位为 ms,默认值为 0。 只有当 `-B/--interlace-rows` 大于 0 时才起作用。意味着数据插入线程在为每个子表插入隔行扫描记录后,会等待该值指定的时间间隔后再进行下一轮写入。
+
+- **-r/--rec-per-req ** :
+ 每次向 TDegnine 请求写入的数据行数,默认值为 30000 。
+
+- **-t/--tables ** :
+ 指定子表的数量,默认为 10000 。
+
+- **-S/--timestampstep ** :
+ 每个子表中插入数据的时间戳步长,单位是 ms,默认值是 1。
+
+- **-n/--records ** :
+ 每个子表插入的记录数,默认值为 10000 。
+
+- **-d/--database ** :
+ 所使用的数据库的名称,默认值为 test 。
+
+- **-b/--data-type ** :
+ 超级表的数据列的类型。如果不使用则默认为有三个数据列,其类型分别为 FLOAT, INT, FLOAT 。
+
+- **-l/--columns ** :
+ 超级表的数据列的总数量。如果同时设置了该参数和 `-b/--data-type`,则最后的结果列数为两者取大。如果本参数指定的数量大于 `-b/--data-type` 指定的列数,则未指定的列类型默认为 INT, 例如: `-l 5 -b float,double`, 那么最后的列为 `FLOAT,DOUBLE,INT,INT,INT`。如果 columns 指定的数量小于或等于 `-b/--data-type` 指定的列数,则结果为 `-b/--data-type` 指定的列和类型,例如: `-l 3 -b float,double,float,bigint`,那么最后的列为 `FLOAT,DOUBLE,FLOAT,BIGINT` 。
+
+- **-A/--tag-type ** :
+ 超级表的标签列类型。nchar 和 binary 类型可以同时设置长度,例如:
+
+```
+taosBenchmark -A INT,DOUBLE,NCHAR,BINARY(16)
+```
+
+如果没有设置标签类型,默认是两个标签,其类型分别为 INT 和 BINARY(16)。
+注意:在有的 shell 比如 bash 命令里面 “()” 需要转义,则上述指令应为:
+
+```
+taosBenchmark -A INT,DOUBLE,NCHAR,BINARY\(16\)
+```
+
+- **-w/--binwidth **:
+ nchar 和 binary 类型的默认长度,默认值为 64。
+
+- **-m/--table-prefix ** :
+ 子表名称的前缀,默认值为 "d"。
+
+- **-E/--escape-character** :
+ 开关参数,指定在超级表和子表名称中是否使用转义字符。默认值为不使用。
+
+- **-C/--chinese** :
+ 开关参数,指定 nchar 和 binary 是否使用 Unicode 中文字符。默认值为不使用。
+
+- **-N/--normal-table** :
+ 开关参数,指定只创建普通表,不创建超级表。默认值为 false。仅当插入模式为 taosc, stmt, rest 模式下可以使用。
+
+- **-M/--random** :
+ 开关参数,插入数据为生成的随机值。默认值为 false。若配置此参数,则随机生成要插入的数据。对于数值类型的 标签列/数据列,其值为该类型取值范围内的随机值。对于 NCHAR 和 BINARY 类型的 标签列/数据列,其值为指定长度范围内的随机字符串。
+
+- **-x/--aggr-func** :
+ 开关参数,指示插入后查询聚合函数。默认值为 false。
+
+- **-y/--answer-yes** :
+ 开关参数,要求用户在提示后确认才能继续。默认值为 false 。
+
+- **-O/--disorder ** :
+ 指定乱序数据的百分比概率,其值域为 [0,50]。默认为 0,即没有乱序数据。
+
+- **-R/--disorder-range ** :
+ 指定乱序数据的时间戳回退范围。所生成的乱序时间戳为非乱序情况下应该使用的时间戳减去这个范围内的一个随机值。仅在 `-O/--disorder` 指定的乱序数据百分比大于 0 时有效。
+
+- **-F/--prepare_rand ** :
+ 生成的随机数据中唯一值的数量。若为 1 则表示所有数据都相同。默认值为 10000 。
+
+- **-a/--replica ** :
+ 创建数据库时指定其副本数,默认值为 1 。
+
+- **-V/--version** :
+ 显示版本信息并退出。不能与其它参数混用。
+
+- **-?/--help** :
+ 显示帮助信息并退出。不能与其它参数混用。
+
+## 配置文件参数详解
+
+### 通用配置参数
+
+本节所列参数适用于所有功能模式。
+
+- **filetype** : 要测试的功能,可选值为 `insert`, `query` 和 `subscribe`。分别对应插入、查询和订阅功能。每个配置文件中只能指定其中之一。
+- **cfgdir** : TDengine 集群配置文件所在的目录,默认路径是 /etc/taos 。
+
+- **host** : 指定要连接的 TDengine 服务端的 FQDN,默认值为 localhost。
+
+- **port** : 要连接的 TDengine 服务器的端口号,默认值为 6030。
+
+- **user** : 用于连接 TDengine 服务端的用户名,默认为 root。
+
+- **password** : 用于连接 TDengine 服务端的密码,默认值为 taosdata。
+
+### 插入场景配置参数
+
+插入场景下 `filetype` 必须设置为 `insert`,该参数及其它通用参数详见[通用配置参数](#通用配置参数)
+
+#### 数据库相关配置参数
+
+创建数据库时的相关参数在 json 配置文件中的 `dbinfo` 中配置,具体参数如下。这些参数与 TDengine 中 `create database` 时所指定的数据库参数相对应。
+
+- **name** : 数据库名。
+
+- **drop** : 插入前是否删除数据库,默认为 true。
+
+- **replica** : 创建数据库时指定的副本数。
+
+- **days** : 单个数据文件中存储数据的时间跨度,默认值为 10。
+
+- **cache** : 缓存块的大小,单位是 MB,默认值是 16。
+
+- **blocks** : 每个 vnode 中缓存块的数量,默认为 6。
+
+- **precision** : 数据库时间精度,默认值为 "ms"。
+
+- **keep** : 保留数据的天数,默认值为 3650。
+
+- **minRows** : 文件块中的最小记录数,默认值为 100。
+
+- **maxRows** : 文件块中的最大记录数,默认值为 4096。
+
+- **comp** : 文件压缩标志,默认值为 2。
+
+- **walLevel** : WAL 级别,默认为 1。
+
+- **cacheLast** : 是否允许将每个表的最后一条记录保留在内存中,默认值为 0,可选值为 0,1,2,3。
+
+- **quorum** : 多副本模式下的写确认数量,默认值为 1。
+
+- **fsync** : 当 wal 设置为 2 时,fsync 的间隔时间,单位为 ms,默认值为 3000。
+
+- **update** : 是否支持数据更新,默认值为 0, 可选值为 0, 1, 2。
+
+#### 超级表相关配置参数
+
+创建超级表时的相关参数在 json 配置文件中的 `super_tables` 中配置,具体参数如下表。
+
+- **name**: 超级表名,必须配置,没有默认值。
+- **child_table_exists** : 子表是否已经存在,默认值为 "no",可选值为 "yes" 或 "no"。
+
+- **child_table_count** : 子表的数量,默认值为 10。
+
+- **child_table_prefix** : 子表名称的前缀,必选配置项,没有默认值。
+
+- **escape_character** : 超级表和子表名称中是否包含转义字符,默认值为 "no",可选值为 "yes" 或 "no"。
+
+- **auto_create_table** : 仅当 insert_mode 为 taosc, rest, stmt 并且 childtable_exists 为 "no" 时生效,该参数为 "yes" 表示 taosBenchmark 在插入数据时会自动创建不存在的表;为 "no" 则表示先提前建好所有表再进行插入。
+
+- **batch_create_tbl_num** : 创建子表时每批次的建表数量,默认为 10。注:实际的批数不一定与该值相同,当执行的 SQL 语句大于支持的最大长度时,会自动截断再执行,继续创建。
+
+- **data_source** : 数据的来源,默认为 taosBenchmark 随机产生,可以配置为 "rand" 和 "sample"。为 "sample" 时使用 sample_file 参数指定的文件内的数据。
+
+- **insert_mode** : 插入模式,可选项有 taosc, rest, stmt, sml, sml-rest, 分别对应普通写入、restful 接口写入、参数绑定接口写入、schemaless 接口写入、restful schemaless 接口写入 (由 taosAdapter 提供)。默认值为 taosc 。
+
+- **non_stop_mode** : 指定是否持续写入,若为 "yes" 则 insert_rows 失效,直到 Ctrl + C 停止程序,写入才会停止。默认值为 "no",即写入指定数量的记录后停止。注:即使在持续写入模式下 insert_rows 失效,但其也必须被配置为一个非零正整数。
+
+- **line_protocol** : 使用行协议插入数据,仅当 insert_mode 为 sml 或 sml-rest 时生效,可选项为 line, telnet, json。
+
+- **tcp_transfer** : telnet 模式下的通信协议,仅当 insert_mode 为 sml-rest 并且 line_protocol 为 telnet 时生效。如果不配置,则默认为 http 协议。
+
+- **insert_rows** : 每个子表插入的记录数,默认为 0 。
+
+- **childtable_offset** : 仅当 childtable_exists 为 yes 时生效,指定从超级表获取子表列表时的偏移量,即从第几个子表开始。
+
+- **childtable_limit** : 仅当 childtable_exists 为 yes 时生效,指定从超级表获取子表列表的上限。
+
+- **interlace_rows** : 启用交错插入模式并同时指定向每个子表每次插入的数据行数。交错插入模式是指依次向每张子表插入由本参数所指定的行数并重复这个过程,直到所有子表的数据都插入完成。默认值为 0, 即向一张子表完成数据插入后才会向下一张子表进行数据插入。
+
+- **insert_interval** : 指定交错插入模式的插入间隔,单位为 ms,默认值为 0。 只有当 `-B/--interlace-rows` 大于 0 时才起作用。意味着数据插入线程在为每个子表插入隔行扫描记录后,会等待该值指定的时间间隔后再进行下一轮写入。
+
+- **partial_col_num** : 若该值为正数 n 时, 则仅向前 n 列写入,仅当 insert_mode 为 taosc 和 rest 时生效,如果 n 为 0 则是向全部列写入。
+
+- **disorder_ratio** : 指定乱序数据的百分比概率,其值域为 [0,50]。默认为 0,即没有乱序数据。
+
+- **disorder_range** : 指定乱序数据的时间戳回退范围。所生成的乱序时间戳为非乱序情况下应该使用的时间戳减去这个范围内的一个随机值。仅在 `-O/--disorder` 指定的乱序数据百分比大于 0 时有效。
+
+- **timestamp_step** : 每个子表中插入数据的时间戳步长,单位与数据库的 `precision` 一致,默认值是 1。
+
+- **start_timestamp** : 每个子表的时间戳起始值,默认值是 now。
+
+- **sample_format** : 样本数据文件的类型,现在只支持 "csv" 。
+
+- **sample_file** : 指定 csv 格式的文件作为数据源,仅当 data_source 为 sample 时生效。若 csv 文件内的数据行数小于等于 prepared_rand,那么会循环读取 csv 文件数据直到与 prepared_rand 相同;否则则会只读取 prepared_rand 个数的行的数据。也即最终生成的数据行数为二者取小。
+
+- **use_sample_ts** : 仅当 data_source 为 sample 时生效,表示 sample_file 指定的 csv 文件内是否包含第一列时间戳,默认为 no。 若设置为 yes, 则使用 csv 文件第一列作为时间戳,由于同一子表时间戳不能重复,生成的数据量取决于 csv 文件内的数据行数相同,此时 insert_rows 失效。
+
+- **tags_file** : 仅当 insert_mode 为 taosc, rest 的模式下生效。 最终的 tag 的数值与 childtable_count 有关,如果 csv 文件内的 tag 数据行小于给定的子表数量,那么会循环读取 csv 文件数据直到生成 childtable_count 指定的子表数量;否则则只会读取 childtable_count 行 tag 数据。也即最终生成的子表数量为二者取小。
+
+#### 标签列与数据列配置参数
+
+指定超级表标签列与数据列的配置参数分别在 `super_tables` 中的 `columns` 和 `tag` 中。
+
+- **type** : 指定列类型,可选值请参考 TDengine 支持的数据类型。
+ 注:JSON 数据类型比较特殊,只能用于标签,当使用 JSON 类型作为 tag 时有且只能有这一个标签,此时 count 和 len 代表的意义分别是 JSON tag 内的 key-value pair 的个数和每个 KV pair 的 value 的值的长度,value 默认为 string。
+
+- **len** : 指定该数据类型的长度,对 NCHAR,BINARY 和 JSON 数据类型有效。如果对其他数据类型配置了该参数,若为 0 , 则代表该列始终都是以 null 值写入;如果不为 0 则被忽略。
+
+- **count** : 指定该类型列连续出现的数量,例如 "count": 4096 即可生成 4096 个指定类型的列。
+
+- **name** : 列的名字,若与 count 同时使用,比如 "name":"current", "count":3, 则 3 个列的名字分别为 current, current_2. current_3。
+
+- **min** : 数据类型的 列/标签 的最小值。
+
+- **max** : 数据类型的 列/标签 的最大值。
+
+- **values** : nchar/binary 列/标签的值域,将从值中随机选择。
+
+#### 插入行为配置参数
+
+- **thread_count** : 插入数据的线程数量,默认为 8。
+
+- **connection_pool_size** : 预先建立的与 TDengine 服务端之间的连接的数量。若不配置,则与所指定的线程数相同。
+
+- **result_file** : 结果输出文件的路径,默认值为 ./output.txt。
+
+- **confirm_parameter_prompt** : 开关参数,要求用户在提示后确认才能继续。默认值为 false 。
+
+- **interlace_rows** : 启用交错插入模式并同时指定向每个子表每次插入的数据行数。交错插入模式是指依次向每张子表插入由本参数所指定的行数并重复这个过程,直到所有子表的数据都插入完成。默认值为 0, 即向一张子表完成数据插入后才会向下一张子表进行数据插入。
+ 在 `super_tables` 中也可以配置该参数,若配置则以 `super_tables` 中的配置为高优先级,覆盖全局设置。
+
+- **insert_interval** :
+ 指定交错插入模式的插入间隔,单位为 ms,默认值为 0。 只有当 `-B/--interlace-rows` 大于 0 时才起作用。意味着数据插入线程在为每个子表插入隔行扫描记录后,会等待该值指定的时间间隔后再进行下一轮写入。
+ 在 `super_tables` 中也可以配置该参数,若配置则以 `super_tables` 中的配置为高优先级,覆盖全局设置。
+
+- **num_of_records_per_req** :
+ 每次向 TDegnine 请求写入的数据行数,默认值为 30000 。当其设置过大时,TDegnine 客户端驱动会返回相应的错误信息,此时需要调低这个参数的设置以满足写入要求。
+
+- **prepare_rand** : 生成的随机数据中唯一值的数量。若为 1 则表示所有数据都相同。默认值为 10000 。
+
+### 查询场景配置参数
+
+查询场景下 `filetype` 必须设置为 `qeury`,该参数及其它通用参数详见[通用配置参数](#通用配置参数)
+
+#### 执行指定查询语句的配置参数
+
+查询子表或者普通表的配置参数在 `specified_table_query` 中设置。
+
+- **query_interval** : 查询时间间隔,单位是秒,默认值为 0。
+
+- **threads** : 执行查询 SQL 的线程数,默认值为 1。
+
+- **sqls**:
+ - **sql**: 执行的 SQL 命令,必填。
+ - **result**: 保存查询结果的文件,未指定则不保存。
+
+#### 查询超级表的配置参数
+
+查询超级表的配置参数在 `super_table_query` 中设置。
+
+- **stblname** : 指定要查询的超级表的名称,必填。
+
+- **query_interval** : 查询时间间隔,单位是秒,默认值为 0。
+
+- **threads** : 执行查询 SQL 的线程数,默认值为 1。
+
+- **sqls** :
+ - **sql** : 执行的 SQL 命令,必填;对于超级表的查询 SQL,在 SQL 命令中保留 "xxxx",程序会自动将其替换为超级表的所有子表名。
+ 替换为超级表中所有的子表名。
+ - **result** : 保存查询结果的文件,未指定则不保存。
+
+### 订阅场景配置参数
+
+订阅场景下 `filetype` 必须设置为 `subscribe`,该参数及其它通用参数详见[通用配置参数](#通用配置参数)
+
+#### 执行指定订阅语句的配置参数
+
+订阅子表或者普通表的配置参数在 `specified_table_query` 中设置。
+
+- **threads** : 执行 SQL 的线程数,默认为 1。
+
+- **interva** : 执行订阅的时间间隔,单位为秒,默认为 0。
+
+- **restart** : "yes" 表示开始新的订阅,"no" 表示继续之前的订阅,默认值为 "no"。
+
+- **keepProgress** : "yes" 表示保留订阅进度,"no" 表示不保留,默认值为 "no"。
+
+- **resubAfterConsume** : "yes" 表示取消之前的订阅然后再次订阅, "no" 表示继续之前的订阅,默认值为 "no"。
+
+- **sqls** :
+ - **sql** : 执行的 SQL 命令,必填。
+ - **result** : 保存查询结果的文件,未指定则不保存。
+
+#### 订阅超级表的配置参数
+
+订阅超级表的配置参数在 `super_table_query` 中设置。
+
+- **stblname** : 要订阅的超级表名称,必填。
+
+- **threads** : 执行 SQL 的线程数,默认为 1。
+
+- **interva** : 执行订阅的时间间隔,单位为秒,默认为 0。
+
+- **restart** : "yes" 表示开始新的订阅,"no" 表示继续之前的订阅,默认值为 "no"。
+
+- **keepProgress** : "yes" 表示保留订阅进度,"no" 表示不保留,默认值为 "no"。
+
+- **resubAfterConsume** : "yes" 表示取消之前的订阅然后再次订阅, "no" 表示继续之前的订阅,默认值为 "no"。
+
+- **sqls** :
+ - **sql** : 执行的 SQL 命令,必填;对于超级表的查询 SQL,在 SQL 命令中保留 "xxxx",程序会自动将其替换为超级表的所有子表名。
+ 替换为超级表中所有的子表名。
+ - **result** : 保存查询结果的文件,未指定则不保存。
diff --git a/docs-cn/14-reference/06-taosdump.md b/docs-cn/14-reference/06-taosdump.md
new file mode 100644
index 0000000000000000000000000000000000000000..ede5d236a975b8c892545105b5537c2eea84d081
--- /dev/null
+++ b/docs-cn/14-reference/06-taosdump.md
@@ -0,0 +1,118 @@
+---
+title: taosdump
+---
+
+## 简介
+
+taosdump 是一个支持从运行中的 TDengine 集群备份数据并将备份的数据恢复
+到相同或另一个运行中的 TDengine 集群中的工具应用程序。
+
+taosdump 可以用数据库、超级表或普通表作为逻辑数据单元进行备份,也可以对数据库、超级
+表和普通表中指定时间段内的数据记录进行备份。使用时可以指定数据备份的目录路径,如果
+不指定位置,taosdump 默认会将数据备份到当前目录。
+
+如果指定的位置已经有数据文件,taosdump 会提示用户并立即退出,避免数据被覆盖。这意味着同一路径只能被用于一次备份。
+如果看到相关提示,请小心操作。
+
+taosdump 是一个逻辑备份工具,它不应被用于备份任何原始数据、环境设置、
+硬件信息、服务端配置或集群的拓扑结构。taosdump 使用
+[ Apache AVRO ](https://avro.apache.org/)作为数据文件格式来存储备份数据。
+
+## 安装
+
+taosdump 有两种安装方式:
+
+- 安装 taosTools 官方安装包, 请从[所有下载链接](https://www.taosdata.com/all-downloads)页面找到 taosTools 并下载安装。
+
+- 单独编译 taos-tools 并安装, 详情请参考 [taos-tools](https://github.com/taosdata/taos-tools) 仓库。
+
+## 常用使用场景
+
+### taosdump 备份数据
+
+1. 备份所有数据库:指定 `-A` 或 `--all-databases` 参数;
+2. 备份多个指定数据库:使用 `-D db1,db2,...` 参数;
+3. 备份指定数据库中的某些超级表或普通表:使用 `dbname stbname1 stbname2 tbname1 tbname2 ...` 参数,注意这种输入序列第一个参数为数据库名称,且只支持一个数据库,第二个和之后的参数为该数据库中的超级表或普通表名称,中间以空格分隔;
+4. 备份系统 log 库:TDengine 集群通常会包含一个系统数据库,名为 `log`,这个数据库内的数据为 TDengine 自我运行的数据,taosdump 默认不会对 log 库进行备份。如果有特定需求对 log 库进行备份,可以使用 `-a` 或 `--allow-sys` 命令行参数。
+5. “宽容”模式备份:taosdump 1.4.1 之后的版本提供 `-n` 参数和 `-L` 参数,用于备份数据时不使用转义字符和“宽容”模式,可以在表名、列名、标签名没使用转义字符的情况下减少备份数据时间和备份数据占用空间。如果不确定符合使用 `-n` 和 `-L` 条件时请使用默认参数进行“严格”模式进行备份。转义字符的说明请参考[官方文档](/taos-sql/escape)。
+
+:::tip
+- taosdump 1.4.1 之后的版本提供 `-I` 参数,用于解析 avro 文件 schema 和数据,如果指定 `-s` 参数将只解析 schema。
+- taosdump 1.4.2 之后的备份使用 `-B` 参数指定的批次数,默认值为 16384,如果在某些环境下由于网络速度或磁盘性能不足导致 "Error actual dump .. batch .." 可以通过 `-B` 参数挑战为更小的值进行尝试。
+
+:::
+
+### taosdump 恢复数据
+
+恢复指定路径下的数据文件:使用 `-i` 参数加上数据文件所在路径。如前面提及,不应该使用同一个目录备份不同数据集合,也不应该在同一路径多次备份同一数据集,否则备份数据会造成覆盖或多次备份。
+
+:::tip
+taosdump 内部使用 TDengine stmt binding API 进行恢复数据的写入,为提高数据恢复性能,目前使用 16384 为一次写入批次。如果备份数据中有比较多列数据,可能会导致产生 "WAL size exceeds limit" 错误,此时可以通过使用 `-B` 参数调整为一个更小的值进行尝试。
+
+:::
+
+## 详细命令行参数列表
+
+以下为 taosdump 详细命令行参数列表:
+
+```
+Usage: taosdump [OPTION...] dbname [tbname ...]
+ or: taosdump [OPTION...] --databases db1,db2,...
+ or: taosdump [OPTION...] --all-databases
+ or: taosdump [OPTION...] -i inpath
+ or: taosdump [OPTION...] -o outpath
+
+ -h, --host=HOST Server host dumping data from. Default is
+ localhost.
+ -p, --password User password to connect to server. Default is
+ taosdata.
+ -P, --port=PORT Port to connect
+ -u, --user=USER User name used to connect to server. Default is
+ root.
+ -c, --config-dir=CONFIG_DIR Configure directory. Default is /etc/taos
+ -i, --inpath=INPATH Input file path.
+ -o, --outpath=OUTPATH Output file path.
+ -r, --resultFile=RESULTFILE DumpOut/In Result file path and name.
+ -a, --allow-sys Allow to dump system database
+ -A, --all-databases Dump all databases.
+ -D, --databases=DATABASES Dump inputted databases. Use comma to separate
+ databases' name.
+ -N, --without-property Dump database without its properties.
+ -s, --schemaonly Only dump tables' schema.
+ -y, --answer-yes Input yes for prompt. It will skip data file
+ checking!
+ -d, --avro-codec=snappy Choose an avro codec among null, deflate, snappy,
+ and lzma.
+ -S, --start-time=START_TIME Start time to dump. Either epoch or
+ ISO8601/RFC3339 format is acceptable. ISO8601
+ format example: 2017-10-01T00:00:00.000+0800 or
+ 2017-10-0100:00:00:000+0800 or '2017-10-01
+ 00:00:00.000+0800'
+ -E, --end-time=END_TIME End time to dump. Either epoch or ISO8601/RFC3339
+ format is acceptable. ISO8601 format example:
+ 2017-10-01T00:00:00.000+0800 or
+ 2017-10-0100:00:00.000+0800 or '2017-10-01
+ 00:00:00.000+0800'
+ -B, --data-batch=DATA_BATCH Number of data per query/insert statement when
+ backup/restore. Default value is 16384. If you see
+ 'error actual dump .. batch ..' when backup or if
+ you see 'WAL size exceeds limit' error when
+ restore, please adjust the value to a smaller one
+ and try. The workable value is related to the
+ length of the row and type of table schema.
+ -I, --inspect inspect avro file content and print on screen
+ -L, --loose-mode Using loose mode if the table name and column name
+ use letter and number only. Default is NOT.
+ -n, --no-escape No escape char '`'. Default is using it.
+ -T, --thread-num=THREAD_NUM Number of thread for dump in file. Default is
+ 5.
+ -g, --debug Print debug info.
+ -?, --help Give this help list
+ --usage Give a short usage message
+ -V, --version Print program version
+
+Mandatory or optional arguments to long options are also mandatory or optional
+for any corresponding short options.
+
+Report bugs to .
+```
diff --git a/docs-cn/14-reference/07-tdinsight/assets/15146-tdengine-monitor-dashboard.json b/docs-cn/14-reference/07-tdinsight/assets/15146-tdengine-monitor-dashboard.json
new file mode 100644
index 0000000000000000000000000000000000000000..f651983528ca824b4e6b14586aac5a5bfb4ecab8
--- /dev/null
+++ b/docs-cn/14-reference/07-tdinsight/assets/15146-tdengine-monitor-dashboard.json
@@ -0,0 +1,3191 @@
+{
+ "__inputs": [
+ {
+ "name": "DS_TDENGINE",
+ "label": "TDengine",
+ "description": "",
+ "type": "datasource",
+ "pluginId": "tdengine-datasource",
+ "pluginName": "TDengine"
+ }
+ ],
+ "__requires": [
+ {
+ "type": "panel",
+ "id": "gauge",
+ "name": "Gauge",
+ "version": ""
+ },
+ {
+ "type": "grafana",
+ "id": "grafana",
+ "name": "Grafana",
+ "version": "7.5.10"
+ },
+ {
+ "type": "panel",
+ "id": "graph",
+ "name": "Graph",
+ "version": ""
+ },
+ {
+ "type": "panel",
+ "id": "piechart",
+ "name": "Pie chart v2",
+ "version": ""
+ },
+ {
+ "type": "panel",
+ "id": "stat",
+ "name": "Stat",
+ "version": ""
+ },
+ {
+ "type": "panel",
+ "id": "table",
+ "name": "Table",
+ "version": ""
+ },
+ {
+ "type": "datasource",
+ "id": "tdengine-datasource",
+ "name": "TDengine",
+ "version": "3.1.0"
+ },
+ {
+ "type": "panel",
+ "id": "text",
+ "name": "Text",
+ "version": ""
+ }
+ ],
+ "annotations": {
+ "list": [
+ {
+ "builtIn": 1,
+ "datasource": "-- Grafana --",
+ "enable": true,
+ "hide": true,
+ "iconColor": "rgba(0, 211, 255, 1)",
+ "name": "Annotations & Alerts",
+ "type": "dashboard"
+ }
+ ]
+ },
+ "description": "TDengine nodes metrics.",
+ "editable": true,
+ "gnetId": 15146,
+ "graphTooltip": 0,
+ "id": null,
+ "iteration": 1635263227798,
+ "links": [],
+ "panels": [
+ {
+ "collapsed": false,
+ "datasource": null,
+ "gridPos": {
+ "h": 1,
+ "w": 24,
+ "x": 0,
+ "y": 0
+ },
+ "id": 57,
+ "panels": [],
+ "title": "Cluster Status",
+ "type": "row"
+ },
+ {
+ "datasource": null,
+ "fieldConfig": {
+ "defaults": {},
+ "overrides": []
+ },
+ "gridPos": {
+ "h": 3,
+ "w": 24,
+ "x": 0,
+ "y": 1
+ },
+ "id": 32,
+ "options": {
+ "content": "TDengine Cluster Dashboard
>\n",
+ "mode": "markdown"
+ },
+ "pluginVersion": "7.5.10",
+ "repeatDirection": "h",
+ "targets": [
+ {
+ "alias": "mnodes",
+ "formatType": "Time series",
+ "queryType": "SQL",
+ "refId": "A",
+ "sql": "show mnodes",
+ "target": "select metric",
+ "timeshift": {
+ "period": null
+ },
+ "type": "timeserie"
+ }
+ ],
+ "timeFrom": null,
+ "timeShift": null,
+ "title": "-- OVERVIEW --",
+ "transformations": [
+ {
+ "id": "calculateField",
+ "options": {
+ "binary": {
+ "left": "Time",
+ "operator": "+",
+ "reducer": "sum",
+ "right": ""
+ },
+ "mode": "binary",
+ "reduce": {
+ "reducer": "sum"
+ }
+ }
+ }
+ ],
+ "type": "text"
+ },
+ {
+ "datasource": "${DS_TDENGINE}",
+ "fieldConfig": {
+ "defaults": {
+ "color": {
+ "mode": "thresholds"
+ },
+ "mappings": [],
+ "thresholds": {
+ "mode": "absolute",
+ "steps": [
+ {
+ "color": "green",
+ "value": null
+ },
+ {
+ "color": "red",
+ "value": 80
+ }
+ ]
+ }
+ },
+ "overrides": []
+ },
+ "gridPos": {
+ "h": 3,
+ "w": 8,
+ "x": 0,
+ "y": 4
+ },
+ "id": 28,
+ "options": {
+ "colorMode": "value",
+ "graphMode": "area",
+ "justifyMode": "auto",
+ "orientation": "auto",
+ "reduceOptions": {
+ "calcs": ["lastNotNull"],
+ "fields": "",
+ "values": true
+ },
+ "text": {},
+ "textMode": "auto"
+ },
+ "pluginVersion": "7.5.10",
+ "repeatDirection": "h",
+ "targets": [
+ {
+ "alias": "dnodes",
+ "formatType": "Time series",
+ "queryType": "SQL",
+ "refId": "A",
+ "sql": "show mnodes",
+ "target": "select metric",
+ "timeshift": {
+ "period": null
+ },
+ "type": "timeserie"
+ }
+ ],
+ "timeFrom": null,
+ "timeShift": null,
+ "title": "Master MNode",
+ "transformations": [
+ {
+ "id": "filterByValue",
+ "options": {
+ "filters": [
+ {
+ "config": {
+ "id": "regex",
+ "options": {
+ "value": "master"
+ }
+ },
+ "fieldName": "role"
+ }
+ ],
+ "match": "all",
+ "type": "include"
+ }
+ },
+ {
+ "id": "filterFieldsByName",
+ "options": {
+ "include": {
+ "names": ["dnodes"]
+ }
+ }
+ }
+ ],
+ "type": "stat"
+ },
+ {
+ "datasource": "${DS_TDENGINE}",
+ "fieldConfig": {
+ "defaults": {
+ "color": {
+ "mode": "thresholds"
+ },
+ "mappings": [],
+ "thresholds": {
+ "mode": "absolute",
+ "steps": [
+ {
+ "color": "green",
+ "value": null
+ }
+ ]
+ }
+ },
+ "overrides": []
+ },
+ "gridPos": {
+ "h": 3,
+ "w": 7,
+ "x": 8,
+ "y": 4
+ },
+ "id": 70,
+ "options": {
+ "colorMode": "value",
+ "graphMode": "area",
+ "justifyMode": "auto",
+ "orientation": "auto",
+ "reduceOptions": {
+ "calcs": ["lastNotNull"],
+ "fields": "/^Time$/",
+ "values": true
+ },
+ "text": {},
+ "textMode": "auto"
+ },
+ "pluginVersion": "7.5.10",
+ "repeatDirection": "h",
+ "targets": [
+ {
+ "alias": "dnodes",
+ "formatType": "Time series",
+ "queryType": "SQL",
+ "refId": "A",
+ "sql": "show mnodes",
+ "target": "select metric",
+ "timeshift": {
+ "period": null
+ },
+ "type": "timeserie"
+ }
+ ],
+ "timeFrom": null,
+ "timeShift": null,
+ "title": "Master MNode Create Time",
+ "transformations": [
+ {
+ "id": "filterByValue",
+ "options": {
+ "filters": [
+ {
+ "config": {
+ "id": "regex",
+ "options": {
+ "value": "master"
+ }
+ },
+ "fieldName": "role"
+ }
+ ],
+ "match": "all",
+ "type": "include"
+ }
+ },
+ {
+ "id": "filterFieldsByName",
+ "options": {
+ "include": {
+ "names": ["Time"]
+ }
+ }
+ },
+ {
+ "id": "calculateField",
+ "options": {
+ "mode": "reduceRow",
+ "reduce": {
+ "reducer": "min"
+ }
+ }
+ }
+ ],
+ "type": "stat"
+ },
+ {
+ "datasource": "${DS_TDENGINE}",
+ "fieldConfig": {
+ "defaults": {
+ "color": {
+ "mode": "thresholds"
+ },
+ "custom": {
+ "align": null,
+ "filterable": false
+ },
+ "mappings": [],
+ "thresholds": {
+ "mode": "absolute",
+ "steps": [
+ {
+ "color": "green",
+ "value": null
+ },
+ {
+ "color": "red",
+ "value": 80
+ }
+ ]
+ }
+ },
+ "overrides": []
+ },
+ "gridPos": {
+ "h": 9,
+ "w": 9,
+ "x": 15,
+ "y": 4
+ },
+ "id": 29,
+ "options": {
+ "showHeader": true
+ },
+ "pluginVersion": "7.5.10",
+ "repeatDirection": "h",
+ "targets": [
+ {
+ "alias": "dnodes",
+ "formatType": "Time series",
+ "queryType": "SQL",
+ "refId": "A",
+ "sql": "show variables",
+ "target": "select metric",
+ "timeshift": {
+ "period": null
+ },
+ "type": "timeserie"
+ }
+ ],
+ "timeFrom": null,
+ "timeShift": null,
+ "title": "Variables",
+ "transformations": [
+ {
+ "id": "filterFieldsByName",
+ "options": {
+ "include": {
+ "names": ["value", "name"]
+ }
+ }
+ },
+ {
+ "id": "filterByValue",
+ "options": {
+ "filters": [
+ {
+ "config": {
+ "id": "regex",
+ "options": {
+ "value": ".*"
+ }
+ },
+ "fieldName": "name"
+ }
+ ],
+ "match": "all",
+ "type": "include"
+ }
+ }
+ ],
+ "type": "table"
+ },
+ {
+ "datasource": "${DS_TDENGINE}",
+ "fieldConfig": {
+ "defaults": {
+ "color": {
+ "mode": "thresholds"
+ },
+ "mappings": [],
+ "thresholds": {
+ "mode": "absolute",
+ "steps": [
+ {
+ "color": "green",
+ "value": null
+ },
+ {
+ "color": "red",
+ "value": 80
+ }
+ ]
+ }
+ },
+ "overrides": []
+ },
+ "gridPos": {
+ "h": 3,
+ "w": 2,
+ "x": 0,
+ "y": 7
+ },
+ "id": 33,
+ "options": {
+ "colorMode": "value",
+ "graphMode": "area",
+ "justifyMode": "auto",
+ "orientation": "auto",
+ "reduceOptions": {
+ "calcs": ["lastNotNull"],
+ "fields": "/.*/",
+ "values": true
+ },
+ "text": {},
+ "textMode": "auto"
+ },
+ "pluginVersion": "7.5.10",
+ "repeatDirection": "h",
+ "targets": [
+ {
+ "alias": "dnodes",
+ "formatType": "Table",
+ "queryType": "SQL",
+ "refId": "A",
+ "sql": "select server_version()",
+ "target": "select metric",
+ "timeshift": {
+ "period": null
+ },
+ "type": "timeserie"
+ }
+ ],
+ "timeFrom": null,
+ "timeShift": null,
+ "title": "Server Version",
+ "transformations": [],
+ "type": "stat"
+ },
+ {
+ "datasource": "${DS_TDENGINE}",
+ "fieldConfig": {
+ "defaults": {
+ "color": {
+ "mode": "thresholds"
+ },
+ "mappings": [],
+ "thresholds": {
+ "mode": "absolute",
+ "steps": [
+ {
+ "color": "green",
+ "value": null
+ },
+ {
+ "color": "red",
+ "value": 80
+ }
+ ]
+ }
+ },
+ "overrides": []
+ },
+ "gridPos": {
+ "h": 3,
+ "w": 3,
+ "x": 2,
+ "y": 7
+ },
+ "id": 27,
+ "options": {
+ "colorMode": "value",
+ "graphMode": "area",
+ "justifyMode": "auto",
+ "orientation": "auto",
+ "reduceOptions": {
+ "calcs": ["lastNotNull"],
+ "fields": "",
+ "values": true
+ },
+ "text": {},
+ "textMode": "auto"
+ },
+ "pluginVersion": "7.5.10",
+ "repeatDirection": "h",
+ "targets": [
+ {
+ "alias": "dnodes",
+ "formatType": "Time series",
+ "queryType": "SQL",
+ "refId": "A",
+ "sql": "show mnodes",
+ "target": "select metric",
+ "timeshift": {
+ "period": null
+ },
+ "type": "timeserie"
+ }
+ ],
+ "timeFrom": null,
+ "timeShift": null,
+ "title": "Number of MNodes",
+ "transformations": [
+ {
+ "id": "filterByValue",
+ "options": {
+ "filters": [
+ {
+ "config": {
+ "id": "greater",
+ "options": {
+ "value": 0
+ }
+ },
+ "fieldName": "id"
+ }
+ ],
+ "match": "any",
+ "type": "include"
+ }
+ },
+ {
+ "id": "reduce",
+ "options": {
+ "includeTimeField": false,
+ "mode": "reduceFields",
+ "reducers": ["count"]
+ }
+ },
+ {
+ "id": "filterFieldsByName",
+ "options": {
+ "include": {
+ "names": ["id"]
+ }
+ }
+ }
+ ],
+ "type": "stat"
+ },
+ {
+ "datasource": "${DS_TDENGINE}",
+ "fieldConfig": {
+ "defaults": {
+ "color": {
+ "mode": "thresholds"
+ },
+ "mappings": [],
+ "thresholds": {
+ "mode": "absolute",
+ "steps": [
+ {
+ "color": "green",
+ "value": null
+ }
+ ]
+ }
+ },
+ "overrides": []
+ },
+ "gridPos": {
+ "h": 3,
+ "w": 2,
+ "x": 5,
+ "y": 7
+ },
+ "id": 41,
+ "options": {
+ "colorMode": "value",
+ "graphMode": "none",
+ "justifyMode": "auto",
+ "orientation": "horizontal",
+ "reduceOptions": {
+ "calcs": ["last"],
+ "fields": "",
+ "values": false
+ },
+ "text": {},
+ "textMode": "value"
+ },
+ "pluginVersion": "7.5.10",
+ "targets": [
+ {
+ "formatType": "Time series",
+ "queryType": "SQL",
+ "refId": "A",
+ "sql": "show dnodes",
+ "target": "select metric",
+ "type": "timeserie"
+ }
+ ],
+ "timeFrom": null,
+ "timeShift": null,
+ "title": "Total Dnodes",
+ "transformations": [
+ {
+ "id": "reduce",
+ "options": {
+ "includeTimeField": false,
+ "mode": "reduceFields",
+ "reducers": ["count"]
+ }
+ },
+ {
+ "id": "filterFieldsByName",
+ "options": {
+ "include": {
+ "names": ["id"]
+ }
+ }
+ }
+ ],
+ "type": "stat"
+ },
+ {
+ "datasource": "${DS_TDENGINE}",
+ "fieldConfig": {
+ "defaults": {
+ "color": {
+ "mode": "thresholds"
+ },
+ "mappings": [],
+ "thresholds": {
+ "mode": "absolute",
+ "steps": [
+ {
+ "color": "green",
+ "value": null
+ },
+ {
+ "color": "red",
+ "value": 1
+ }
+ ]
+ }
+ },
+ "overrides": []
+ },
+ "gridPos": {
+ "h": 3,
+ "w": 2,
+ "x": 7,
+ "y": 7
+ },
+ "id": 31,
+ "options": {
+ "colorMode": "value",
+ "graphMode": "none",
+ "justifyMode": "auto",
+ "orientation": "horizontal",
+ "reduceOptions": {
+ "calcs": ["last"],
+ "fields": "",
+ "values": false
+ },
+ "text": {},
+ "textMode": "value"
+ },
+ "pluginVersion": "7.5.10",
+ "targets": [
+ {
+ "formatType": "Time series",
+ "queryType": "SQL",
+ "refId": "A",
+ "sql": "show dnodes",
+ "target": "select metric",
+ "type": "timeserie"
+ }
+ ],
+ "timeFrom": null,
+ "timeShift": null,
+ "title": "Offline Dnodes",
+ "transformations": [
+ {
+ "id": "filterByValue",
+ "options": {
+ "filters": [
+ {
+ "config": {
+ "id": "regex",
+ "options": {
+ "value": "ready"
+ }
+ },
+ "fieldName": "status"
+ }
+ ],
+ "match": "all",
+ "type": "exclude"
+ }
+ },
+ {
+ "id": "reduce",
+ "options": {
+ "includeTimeField": false,
+ "mode": "reduceFields",
+ "reducers": ["count"]
+ }
+ },
+ {
+ "id": "filterFieldsByName",
+ "options": {
+ "include": {
+ "names": ["id"]
+ }
+ }
+ }
+ ],
+ "type": "stat"
+ },
+ {
+ "datasource": "${DS_TDENGINE}",
+ "fieldConfig": {
+ "defaults": {
+ "color": {
+ "mode": "thresholds"
+ },
+ "mappings": [],
+ "thresholds": {
+ "mode": "absolute",
+ "steps": [
+ {
+ "color": "green",
+ "value": null
+ },
+ {
+ "color": "red",
+ "value": 80
+ }
+ ]
+ }
+ },
+ "overrides": []
+ },
+ "gridPos": {
+ "h": 3,
+ "w": 3,
+ "x": 9,
+ "y": 7
+ },
+ "id": 65,
+ "options": {
+ "colorMode": "value",
+ "graphMode": "area",
+ "justifyMode": "auto",
+ "orientation": "auto",
+ "reduceOptions": {
+ "calcs": ["lastNotNull"],
+ "fields": "",
+ "values": true
+ },
+ "text": {},
+ "textMode": "auto"
+ },
+ "pluginVersion": "7.5.10",
+ "repeatDirection": "h",
+ "targets": [
+ {
+ "alias": "dnodes",
+ "formatType": "Time series",
+ "queryType": "SQL",
+ "refId": "A",
+ "sql": "show databases;",
+ "target": "select metric",
+ "timeshift": {
+ "period": null
+ },
+ "type": "timeserie"
+ }
+ ],
+ "timeFrom": null,
+ "timeShift": null,
+ "title": "Number of Databases",
+ "transformations": [
+ {
+ "id": "reduce",
+ "options": {
+ "includeTimeField": false,
+ "mode": "reduceFields",
+ "reducers": ["count"]
+ }
+ },
+ {
+ "id": "filterFieldsByName",
+ "options": {
+ "include": {
+ "names": ["name"]
+ }
+ }
+ }
+ ],
+ "type": "stat"
+ },
+ {
+ "datasource": "${DS_TDENGINE}",
+ "fieldConfig": {
+ "defaults": {
+ "color": {
+ "mode": "thresholds"
+ },
+ "mappings": [],
+ "thresholds": {
+ "mode": "absolute",
+ "steps": [
+ {
+ "color": "green",
+ "value": null
+ },
+ {
+ "color": "red",
+ "value": 80
+ }
+ ]
+ }
+ },
+ "overrides": []
+ },
+ "gridPos": {
+ "h": 3,
+ "w": 3,
+ "x": 12,
+ "y": 7
+ },
+ "id": 69,
+ "options": {
+ "colorMode": "value",
+ "graphMode": "area",
+ "justifyMode": "auto",
+ "orientation": "auto",
+ "reduceOptions": {
+ "calcs": ["lastNotNull"],
+ "fields": "",
+ "values": true
+ },
+ "text": {},
+ "textMode": "auto"
+ },
+ "pluginVersion": "7.5.10",
+ "repeatDirection": "h",
+ "targets": [
+ {
+ "alias": "dnodes",
+ "formatType": "Time series",
+ "queryType": "SQL",
+ "refId": "A",
+ "sql": "show databases;",
+ "target": "select metric",
+ "timeshift": {
+ "period": null
+ },
+ "type": "timeserie"
+ }
+ ],
+ "timeFrom": null,
+ "timeShift": null,
+ "title": "Total Number of Vgroups",
+ "transformations": [
+ {
+ "id": "filterFieldsByName",
+ "options": {
+ "include": {
+ "names": ["vgroups"]
+ }
+ }
+ },
+ {
+ "id": "reduce",
+ "options": {
+ "includeTimeField": false,
+ "mode": "reduceFields",
+ "reducers": ["sum"]
+ }
+ }
+ ],
+ "type": "stat"
+ },
+ {
+ "datasource": "${DS_TDENGINE}",
+ "fieldConfig": {
+ "defaults": {
+ "color": {
+ "mode": "thresholds"
+ },
+ "custom": {
+ "align": "center",
+ "displayMode": "auto",
+ "filterable": true
+ },
+ "mappings": [],
+ "thresholds": {
+ "mode": "absolute",
+ "steps": [
+ {
+ "color": "green",
+ "value": null
+ }
+ ]
+ }
+ },
+ "overrides": [
+ {
+ "matcher": {
+ "id": "byName",
+ "options": "role"
+ },
+ "properties": [
+ {
+ "id": "mappings",
+ "value": [
+ {
+ "from": "",
+ "id": 1,
+ "text": "",
+ "to": "",
+ "type": 2,
+ "value": ""
+ }
+ ]
+ }
+ ]
+ }
+ ]
+ },
+ "gridPos": {
+ "h": 3,
+ "w": 9,
+ "x": 0,
+ "y": 10
+ },
+ "id": 67,
+ "options": {
+ "showHeader": true
+ },
+ "pluginVersion": "7.5.10",
+ "targets": [
+ {
+ "formatType": "Table",
+ "queryType": "SQL",
+ "refId": "A",
+ "sql": "show dnodes",
+ "target": "select metric",
+ "type": "timeserie"
+ }
+ ],
+ "timeFrom": null,
+ "timeShift": null,
+ "title": "Number of DNodes for each Role",
+ "transformations": [
+ {
+ "id": "groupBy",
+ "options": {
+ "fields": {
+ "end_point": {
+ "aggregations": ["count"],
+ "operation": "aggregate"
+ },
+ "role": {
+ "aggregations": [],
+ "operation": "groupby"
+ }
+ }
+ }
+ },
+ {
+ "id": "filterFieldsByName",
+ "options": {}
+ },
+ {
+ "id": "organize",
+ "options": {
+ "excludeByName": {},
+ "indexByName": {},
+ "renameByName": {
+ "end_point (count)": "Number of DNodes",
+ "role": "Dnode Role"
+ }
+ }
+ }
+ ],
+ "type": "table"
+ },
+ {
+ "datasource": "${DS_TDENGINE}",
+ "fieldConfig": {
+ "defaults": {
+ "color": {
+ "mode": "thresholds"
+ },
+ "mappings": [],
+ "thresholds": {
+ "mode": "absolute",
+ "steps": [
+ {
+ "color": "green",
+ "value": null
+ },
+ {
+ "color": "red",
+ "value": 80
+ }
+ ]
+ }
+ },
+ "overrides": []
+ },
+ "gridPos": {
+ "h": 3,
+ "w": 3,
+ "x": 9,
+ "y": 10
+ },
+ "id": 55,
+ "options": {
+ "colorMode": "value",
+ "graphMode": "area",
+ "justifyMode": "auto",
+ "orientation": "auto",
+ "reduceOptions": {
+ "calcs": ["lastNotNull"],
+ "fields": "",
+ "values": true
+ },
+ "text": {},
+ "textMode": "auto"
+ },
+ "pluginVersion": "7.5.10",
+ "repeatDirection": "h",
+ "targets": [
+ {
+ "alias": "dnodes",
+ "formatType": "Time series",
+ "queryType": "SQL",
+ "refId": "A",
+ "sql": "show connections",
+ "target": "select metric",
+ "timeshift": {
+ "period": null
+ },
+ "type": "timeserie"
+ }
+ ],
+ "timeFrom": null,
+ "timeShift": null,
+ "title": "Number of Connections",
+ "transformations": [
+ {
+ "id": "reduce",
+ "options": {
+ "includeTimeField": false,
+ "mode": "reduceFields",
+ "reducers": ["count"]
+ }
+ },
+ {
+ "id": "filterFieldsByName",
+ "options": {
+ "include": {
+ "names": ["connId"]
+ }
+ }
+ }
+ ],
+ "type": "stat"
+ },
+ {
+ "datasource": "${DS_TDENGINE}",
+ "fieldConfig": {
+ "defaults": {
+ "color": {
+ "mode": "thresholds"
+ },
+ "mappings": [],
+ "thresholds": {
+ "mode": "absolute",
+ "steps": [
+ {
+ "color": "green",
+ "value": null
+ }
+ ]
+ }
+ },
+ "overrides": []
+ },
+ "gridPos": {
+ "h": 3,
+ "w": 3,
+ "x": 12,
+ "y": 10
+ },
+ "id": 68,
+ "options": {
+ "colorMode": "value",
+ "graphMode": "area",
+ "justifyMode": "auto",
+ "orientation": "auto",
+ "reduceOptions": {
+ "calcs": ["lastNotNull"],
+ "fields": "",
+ "values": true
+ },
+ "text": {},
+ "textMode": "auto"
+ },
+ "pluginVersion": "7.5.10",
+ "repeatDirection": "h",
+ "targets": [
+ {
+ "alias": "dnodes",
+ "formatType": "Time series",
+ "queryType": "SQL",
+ "refId": "A",
+ "sql": "show databases;",
+ "target": "select metric",
+ "timeshift": {
+ "period": null
+ },
+ "type": "timeserie"
+ }
+ ],
+ "timeFrom": null,
+ "timeShift": null,
+ "title": "Total Number of Tables",
+ "transformations": [
+ {
+ "id": "filterFieldsByName",
+ "options": {
+ "include": {
+ "names": ["ntables"]
+ }
+ }
+ },
+ {
+ "id": "reduce",
+ "options": {
+ "includeTimeField": false,
+ "mode": "reduceFields",
+ "reducers": ["sum"]
+ }
+ }
+ ],
+ "type": "stat"
+ },
+ {
+ "collapsed": false,
+ "datasource": null,
+ "gridPos": {
+ "h": 1,
+ "w": 24,
+ "x": 0,
+ "y": 13
+ },
+ "id": 24,
+ "panels": [],
+ "title": "Dnodes Status",
+ "type": "row"
+ },
+ {
+ "datasource": "${DS_TDENGINE}",
+ "fieldConfig": {
+ "defaults": {
+ "color": {
+ "mode": "thresholds"
+ },
+ "custom": {
+ "align": "center",
+ "displayMode": "auto",
+ "filterable": true
+ },
+ "mappings": [],
+ "thresholds": {
+ "mode": "absolute",
+ "steps": [
+ {
+ "color": "green",
+ "value": null
+ },
+ {
+ "color": "red",
+ "value": 80
+ }
+ ]
+ }
+ },
+ "overrides": [
+ {
+ "matcher": {
+ "id": "byName",
+ "options": "status"
+ },
+ "properties": [
+ {
+ "id": "custom.width",
+ "value": 86
+ }
+ ]
+ },
+ {
+ "matcher": {
+ "id": "byName",
+ "options": "vnodes"
+ },
+ "properties": [
+ {
+ "id": "custom.width",
+ "value": 77
+ }
+ ]
+ },
+ {
+ "matcher": {
+ "id": "byName",
+ "options": "role"
+ },
+ "properties": [
+ {
+ "id": "custom.width",
+ "value": 84
+ }
+ ]
+ },
+ {
+ "matcher": {
+ "id": "byName",
+ "options": "cores"
+ },
+ "properties": [
+ {
+ "id": "custom.width",
+ "value": 75
+ }
+ ]
+ },
+ {
+ "matcher": {
+ "id": "byName",
+ "options": "end_point"
+ },
+ "properties": [
+ {
+ "id": "custom.width",
+ "value": 205
+ }
+ ]
+ },
+ {
+ "matcher": {
+ "id": "byName",
+ "options": "id"
+ },
+ "properties": [
+ {
+ "id": "custom.width",
+ "value": 78
+ }
+ ]
+ }
+ ]
+ },
+ "gridPos": {
+ "h": 5,
+ "w": 16,
+ "x": 0,
+ "y": 14
+ },
+ "id": 36,
+ "options": {
+ "showHeader": true,
+ "sortBy": []
+ },
+ "pluginVersion": "7.5.10",
+ "targets": [
+ {
+ "formatType": "Table",
+ "queryType": "SQL",
+ "refId": "A",
+ "sql": "show dnodes",
+ "target": "select metric",
+ "type": "timeserie"
+ }
+ ],
+ "timeFrom": null,
+ "timeShift": null,
+ "title": "DNodes Status",
+ "type": "table"
+ },
+ {
+ "datasource": "${DS_TDENGINE}",
+ "fieldConfig": {
+ "defaults": {
+ "color": {
+ "mode": "palette-classic"
+ },
+ "mappings": [],
+ "thresholds": {
+ "mode": "absolute",
+ "steps": [
+ {
+ "color": "green",
+ "value": null
+ },
+ {
+ "color": "red",
+ "value": 80
+ }
+ ]
+ }
+ },
+ "overrides": []
+ },
+ "gridPos": {
+ "h": 5,
+ "w": 8,
+ "x": 16,
+ "y": 14
+ },
+ "id": 40,
+ "options": {
+ "displayLabels": [],
+ "legend": {
+ "displayMode": "table",
+ "placement": "right",
+ "values": ["value"]
+ },
+ "pieType": "pie",
+ "reduceOptions": {
+ "calcs": ["lastNotNull"],
+ "fields": "/.*/",
+ "values": false
+ },
+ "text": {
+ "titleSize": 6
+ }
+ },
+ "pluginVersion": "7.5.10",
+ "targets": [
+ {
+ "formatType": "Table",
+ "queryType": "SQL",
+ "refId": "A",
+ "sql": "show dnodes",
+ "target": "select metric",
+ "type": "timeserie"
+ }
+ ],
+ "title": "Offline Reasons",
+ "transformations": [
+ {
+ "id": "filterByValue",
+ "options": {
+ "filters": [
+ {
+ "config": {
+ "id": "regex",
+ "options": {
+ "value": "ready"
+ }
+ },
+ "fieldName": "status"
+ }
+ ],
+ "match": "all",
+ "type": "exclude"
+ }
+ },
+ {
+ "id": "filterFieldsByName",
+ "options": {
+ "include": {
+ "names": ["offline reason", "end_point"]
+ }
+ }
+ },
+ {
+ "id": "groupBy",
+ "options": {
+ "fields": {
+ "Time": {
+ "aggregations": ["count"],
+ "operation": "aggregate"
+ },
+ "end_point": {
+ "aggregations": ["count"],
+ "operation": "aggregate"
+ },
+ "offline reason": {
+ "aggregations": [],
+ "operation": "groupby"
+ }
+ }
+ }
+ }
+ ],
+ "type": "piechart"
+ },
+ {
+ "collapsed": false,
+ "datasource": null,
+ "gridPos": {
+ "h": 1,
+ "w": 24,
+ "x": 0,
+ "y": 19
+ },
+ "id": 22,
+ "panels": [],
+ "title": "Mnodes Status",
+ "type": "row"
+ },
+ {
+ "datasource": "${DS_TDENGINE}",
+ "fieldConfig": {
+ "defaults": {
+ "color": {
+ "mode": "thresholds"
+ },
+ "custom": {
+ "align": "center",
+ "filterable": false
+ },
+ "mappings": [],
+ "thresholds": {
+ "mode": "absolute",
+ "steps": [
+ {
+ "color": "green",
+ "value": null
+ },
+ {
+ "color": "red",
+ "value": 80
+ }
+ ]
+ }
+ },
+ "overrides": []
+ },
+ "gridPos": {
+ "h": 5,
+ "w": 24,
+ "x": 0,
+ "y": 20
+ },
+ "id": 38,
+ "options": {
+ "showHeader": true
+ },
+ "pluginVersion": "7.5.10",
+ "targets": [
+ {
+ "formatType": "Table",
+ "queryType": "SQL",
+ "refId": "A",
+ "sql": "show mnodes;",
+ "target": "select metric",
+ "type": "timeserie"
+ }
+ ],
+ "title": "Mnodes Status",
+ "type": "table"
+ },
+ {
+ "collapsed": false,
+ "datasource": null,
+ "gridPos": {
+ "h": 1,
+ "w": 24,
+ "x": 0,
+ "y": 25
+ },
+ "id": 20,
+ "panels": [],
+ "repeat": "fqdn",
+ "title": "节点资源占用 [ $fqdn ]",
+ "type": "row"
+ },
+ {
+ "datasource": "${DS_TDENGINE}",
+ "description": "",
+ "fieldConfig": {
+ "defaults": {
+ "color": {
+ "mode": "continuous-GrYlRd"
+ },
+ "mappings": [],
+ "min": 0,
+ "thresholds": {
+ "mode": "absolute",
+ "steps": [
+ {
+ "color": "green",
+ "value": null
+ }
+ ]
+ },
+ "unit": "decmbytes"
+ },
+ "overrides": []
+ },
+ "gridPos": {
+ "h": 6,
+ "w": 5,
+ "x": 0,
+ "y": 26
+ },
+ "id": 66,
+ "options": {
+ "orientation": "auto",
+ "reduceOptions": {
+ "calcs": ["mean"],
+ "fields": "/^taosd$/",
+ "values": false
+ },
+ "showThresholdLabels": true,
+ "showThresholdMarkers": true,
+ "text": {}
+ },
+ "pluginVersion": "7.5.10",
+ "targets": [
+ {
+ "alias": "memory",
+ "formatType": "Time series",
+ "queryType": "SQL",
+ "refId": "A",
+ "sql": "select last(mem_taosd) as taosd, last(mem_total) as total from log.dn where fqdn = '$fqdn' and ts >= now -5m and ts < now",
+ "target": "select metric",
+ "type": "timeserie"
+ }
+ ],
+ "timeFrom": null,
+ "timeShift": null,
+ "title": "Current Memory Usage of taosd",
+ "type": "gauge"
+ },
+ {
+ "datasource": "${DS_TDENGINE}",
+ "description": "taosd max memery last 10 minutes",
+ "fieldConfig": {
+ "defaults": {
+ "color": {
+ "mode": "continuous-GrYlRd"
+ },
+ "mappings": [],
+ "min": 0,
+ "thresholds": {
+ "mode": "absolute",
+ "steps": [
+ {
+ "color": "green",
+ "value": null
+ },
+ {
+ "color": "#EAB839",
+ "value": 0.5
+ },
+ {
+ "color": "red",
+ "value": 0.8
+ }
+ ]
+ },
+ "unit": "percentunit"
+ },
+ "overrides": [
+ {
+ "matcher": {
+ "id": "byName",
+ "options": "last(cpu_taosd)"
+ },
+ "properties": [
+ {
+ "id": "thresholds",
+ "value": {
+ "mode": "absolute",
+ "steps": [
+ {
+ "color": "green",
+ "value": null
+ },
+ {
+ "color": "red",
+ "value": 80
+ }
+ ]
+ }
+ }
+ ]
+ }
+ ]
+ },
+ "gridPos": {
+ "h": 6,
+ "w": 5,
+ "x": 5,
+ "y": 26
+ },
+ "id": 45,
+ "options": {
+ "orientation": "auto",
+ "reduceOptions": {
+ "calcs": ["mean"],
+ "fields": "/^last\\(cpu_taosd\\)$/",
+ "values": false
+ },
+ "showThresholdLabels": true,
+ "showThresholdMarkers": true,
+ "text": {}
+ },
+ "pluginVersion": "7.5.10",
+ "targets": [
+ {
+ "alias": "mem_taosd",
+ "formatType": "Time series",
+ "queryType": "SQL",
+ "refId": "A",
+ "sql": "select last(cpu_taosd) from log.dn where fqdn = '$fqdn'",
+ "target": "select metric",
+ "type": "timeserie"
+ }
+ ],
+ "timeFrom": null,
+ "timeShift": null,
+ "title": "Current CPU Usage of taosd",
+ "type": "gauge"
+ },
+ {
+ "datasource": "${DS_TDENGINE}",
+ "description": "avg band speed last one minute",
+ "fieldConfig": {
+ "defaults": {
+ "color": {
+ "mode": "thresholds"
+ },
+ "mappings": [],
+ "max": 8192,
+ "min": 0,
+ "thresholds": {
+ "mode": "absolute",
+ "steps": [
+ {
+ "color": "green",
+ "value": null
+ },
+ {
+ "color": "#EAB839",
+ "value": 4916
+ },
+ {
+ "color": "red",
+ "value": 6554
+ }
+ ]
+ },
+ "unit": "Kbits"
+ },
+ "overrides": []
+ },
+ "gridPos": {
+ "h": 6,
+ "w": 4,
+ "x": 10,
+ "y": 26
+ },
+ "id": 14,
+ "options": {
+ "orientation": "auto",
+ "reduceOptions": {
+ "calcs": ["last"],
+ "fields": "",
+ "values": false
+ },
+ "showThresholdLabels": false,
+ "showThresholdMarkers": true,
+ "text": {}
+ },
+ "pluginVersion": "7.5.10",
+ "targets": [
+ {
+ "alias": "band_speed",
+ "formatType": "Time series",
+ "queryType": "SQL",
+ "refId": "A",
+ "sql": "select avg(band_speed) from log.dn where fqdn='$fqdn' and ts >= now-5m and ts < now interval(1m)",
+ "target": "select metric",
+ "type": "timeserie"
+ }
+ ],
+ "timeFrom": null,
+ "timeShift": null,
+ "title": "band speed",
+ "type": "gauge"
+ },
+ {
+ "datasource": "${DS_TDENGINE}",
+ "description": "io read/write rate",
+ "fieldConfig": {
+ "defaults": {
+ "color": {
+ "mode": "thresholds"
+ },
+ "mappings": [],
+ "max": 8192,
+ "min": 0,
+ "thresholds": {
+ "mode": "absolute",
+ "steps": [
+ {
+ "color": "green",
+ "value": null
+ },
+ {
+ "color": "#EAB839",
+ "value": 4916
+ },
+ {
+ "color": "red",
+ "value": 6554
+ }
+ ]
+ },
+ "unit": "Kbits"
+ },
+ "overrides": []
+ },
+ "gridPos": {
+ "h": 6,
+ "w": 5,
+ "x": 14,
+ "y": 26
+ },
+ "id": 48,
+ "options": {
+ "orientation": "auto",
+ "reduceOptions": {
+ "calcs": ["last"],
+ "fields": "",
+ "values": false
+ },
+ "showThresholdLabels": false,
+ "showThresholdMarkers": true,
+ "text": {}
+ },
+ "pluginVersion": "7.5.10",
+ "targets": [
+ {
+ "alias": "",
+ "formatType": "Time series",
+ "queryType": "SQL",
+ "refId": "A",
+ "sql": "select last(io_read) as io_read, last(io_write) as io_write from log.dn where fqdn='$fqdn' and ts >= now-1h and ts < now interval(1m)",
+ "target": "select metric",
+ "type": "timeserie"
+ }
+ ],
+ "timeFrom": null,
+ "timeShift": null,
+ "title": "IO Rate",
+ "type": "gauge"
+ },
+ {
+ "datasource": "${DS_TDENGINE}",
+ "description": "",
+ "fieldConfig": {
+ "defaults": {
+ "color": {
+ "mode": "thresholds"
+ },
+ "mappings": [],
+ "max": 1,
+ "min": 0,
+ "thresholds": {
+ "mode": "percentage",
+ "steps": [
+ {
+ "color": "green",
+ "value": null
+ },
+ {
+ "color": "#EAB839",
+ "value": 75
+ },
+ {
+ "color": "red",
+ "value": 80
+ },
+ {
+ "color": "dark-red",
+ "value": 95
+ }
+ ]
+ },
+ "unit": "percentunit"
+ },
+ "overrides": []
+ },
+ "gridPos": {
+ "h": 6,
+ "w": 5,
+ "x": 19,
+ "y": 26
+ },
+ "id": 51,
+ "options": {
+ "orientation": "auto",
+ "reduceOptions": {
+ "calcs": ["last"],
+ "fields": "/^disk_used_percent$/",
+ "values": false
+ },
+ "showThresholdLabels": true,
+ "showThresholdMarkers": true,
+ "text": {}
+ },
+ "pluginVersion": "7.5.10",
+ "targets": [
+ {
+ "alias": "disk_used",
+ "formatType": "Time series",
+ "queryType": "SQL",
+ "refId": "A",
+ "sql": "select last(disk_used) as used from log.dn where fqdn = '$fqdn' and ts >= $from and ts < $to interval(1m)",
+ "target": "select metric",
+ "timeshift": {
+ "period": null
+ },
+ "type": "timeserie"
+ },
+ {
+ "alias": "disk_total",
+ "formatType": "Time series",
+ "hide": false,
+ "queryType": "SQL",
+ "refId": "B",
+ "sql": "select last(disk_total) as total from log.dn where fqdn = '$fqdn' and ts >= $from and ts < $to interval(1m)",
+ "target": "select metric",
+ "type": "timeserie"
+ },
+ {
+ "alias": "disk_used_percent",
+ "expression": "A/B",
+ "formatType": "Time series",
+ "hide": false,
+ "queryType": "Arithmetic",
+ "refId": "C",
+ "target": "select metric",
+ "type": "timeserie"
+ }
+ ],
+ "timeFrom": null,
+ "timeShift": null,
+ "title": "Disk Used",
+ "transformations": [
+ {
+ "id": "reduce",
+ "options": {
+ "includeTimeField": false,
+ "mode": "reduceFields",
+ "reducers": ["lastNotNull"]
+ }
+ }
+ ],
+ "type": "gauge"
+ },
+ {
+ "datasource": "${DS_TDENGINE}",
+ "description": "taosd max memery last 10 minutes",
+ "fieldConfig": {
+ "defaults": {
+ "color": {
+ "mode": "continuous-GrYlRd"
+ },
+ "mappings": [],
+ "min": 0,
+ "thresholds": {
+ "mode": "absolute",
+ "steps": [
+ {
+ "color": "green",
+ "value": null
+ }
+ ]
+ },
+ "unit": "decmbytes"
+ },
+ "overrides": []
+ },
+ "gridPos": {
+ "h": 6,
+ "w": 5,
+ "x": 0,
+ "y": 32
+ },
+ "id": 12,
+ "options": {
+ "orientation": "auto",
+ "reduceOptions": {
+ "calcs": ["mean"],
+ "fields": "/^taosd$/",
+ "values": false
+ },
+ "showThresholdLabels": true,
+ "showThresholdMarkers": true,
+ "text": {}
+ },
+ "pluginVersion": "7.5.10",
+ "targets": [
+ {
+ "alias": "memory",
+ "formatType": "Time series",
+ "queryType": "SQL",
+ "refId": "A",
+ "sql": "select max(mem_taosd) as taosd, max(mem_total) as total from log.dn where fqdn = '$fqdn' and ts >= now -5m and ts < now",
+ "target": "select metric",
+ "type": "timeserie"
+ }
+ ],
+ "timeFrom": null,
+ "timeShift": null,
+ "title": "Max Memory Usage of taosd in Last 5 minute",
+ "type": "gauge"
+ },
+ {
+ "datasource": "${DS_TDENGINE}",
+ "description": "taosd max memery last 10 minutes",
+ "fieldConfig": {
+ "defaults": {
+ "color": {
+ "mode": "continuous-GrYlRd"
+ },
+ "mappings": [],
+ "max": 1,
+ "min": 0,
+ "thresholds": {
+ "mode": "absolute",
+ "steps": [
+ {
+ "color": "green",
+ "value": null
+ },
+ {
+ "color": "#EAB839",
+ "value": 0.5
+ },
+ {
+ "color": "red",
+ "value": 0.8
+ }
+ ]
+ },
+ "unit": "percentunit"
+ },
+ "overrides": []
+ },
+ "gridPos": {
+ "h": 6,
+ "w": 5,
+ "x": 5,
+ "y": 32
+ },
+ "id": 43,
+ "options": {
+ "orientation": "auto",
+ "reduceOptions": {
+ "calcs": ["mean"],
+ "fields": "",
+ "values": false
+ },
+ "showThresholdLabels": true,
+ "showThresholdMarkers": true,
+ "text": {}
+ },
+ "pluginVersion": "7.5.10",
+ "targets": [
+ {
+ "alias": "mem_taosd",
+ "formatType": "Time series",
+ "queryType": "SQL",
+ "refId": "A",
+ "sql": "select max(cpu_taosd) from log.dn where fqdn = '$fqdn' and ts >= now -5m and ts < now",
+ "target": "select metric",
+ "type": "timeserie"
+ }
+ ],
+ "timeFrom": null,
+ "timeShift": null,
+ "title": "Max CPU Usage of taosd in Last 5 minute",
+ "type": "gauge"
+ },
+ {
+ "datasource": "${DS_TDENGINE}",
+ "description": "avg band speed last one minute",
+ "fieldConfig": {
+ "defaults": {
+ "color": {
+ "mode": "thresholds"
+ },
+ "mappings": [],
+ "max": 8192,
+ "min": 0,
+ "thresholds": {
+ "mode": "absolute",
+ "steps": [
+ {
+ "color": "green",
+ "value": null
+ },
+ {
+ "color": "#EAB839",
+ "value": 4916
+ },
+ {
+ "color": "red",
+ "value": 6554
+ }
+ ]
+ },
+ "unit": "Kbits"
+ },
+ "overrides": []
+ },
+ "gridPos": {
+ "h": 6,
+ "w": 4,
+ "x": 10,
+ "y": 32
+ },
+ "id": 50,
+ "options": {
+ "orientation": "auto",
+ "reduceOptions": {
+ "calcs": ["last"],
+ "fields": "",
+ "values": false
+ },
+ "showThresholdLabels": false,
+ "showThresholdMarkers": true,
+ "text": {}
+ },
+ "pluginVersion": "7.5.10",
+ "targets": [
+ {
+ "alias": "band_speed",
+ "formatType": "Time series",
+ "queryType": "SQL",
+ "refId": "A",
+ "sql": "select max(band_speed) from log.dn where fqdn = '$fqdn' and ts >= now-1h",
+ "target": "select metric",
+ "type": "timeserie"
+ }
+ ],
+ "timeFrom": null,
+ "timeShift": null,
+ "title": "Max band speed in last hour",
+ "type": "gauge"
+ },
+ {
+ "datasource": "${DS_TDENGINE}",
+ "description": "io read/write rate",
+ "fieldConfig": {
+ "defaults": {
+ "color": {
+ "mode": "thresholds"
+ },
+ "mappings": [],
+ "max": 8192,
+ "min": 0,
+ "thresholds": {
+ "mode": "absolute",
+ "steps": [
+ {
+ "color": "green",
+ "value": null
+ },
+ {
+ "color": "#EAB839",
+ "value": 4916
+ },
+ {
+ "color": "red",
+ "value": 6554
+ }
+ ]
+ },
+ "unit": "Kbits"
+ },
+ "overrides": []
+ },
+ "gridPos": {
+ "h": 6,
+ "w": 5,
+ "x": 14,
+ "y": 32
+ },
+ "id": 49,
+ "options": {
+ "orientation": "auto",
+ "reduceOptions": {
+ "calcs": ["last"],
+ "fields": "",
+ "values": false
+ },
+ "showThresholdLabels": false,
+ "showThresholdMarkers": true,
+ "text": {}
+ },
+ "pluginVersion": "7.5.10",
+ "targets": [
+ {
+ "alias": "",
+ "formatType": "Time series",
+ "queryType": "SQL",
+ "refId": "A",
+ "sql": "select max(io_read) as io_read, max(io_write) as io_write from log.dn where fqdn = '$fqdn'",
+ "target": "select metric",
+ "type": "timeserie"
+ }
+ ],
+ "timeFrom": null,
+ "timeShift": null,
+ "title": "Max IO Rate in last hour",
+ "type": "gauge"
+ },
+ {
+ "datasource": "${DS_TDENGINE}",
+ "description": "io read/write rate",
+ "fieldConfig": {
+ "defaults": {
+ "color": {
+ "mode": "thresholds"
+ },
+ "mappings": [],
+ "max": 8192,
+ "min": 0,
+ "thresholds": {
+ "mode": "absolute",
+ "steps": [
+ {
+ "color": "green",
+ "value": null
+ },
+ {
+ "color": "#EAB839",
+ "value": 4916
+ },
+ {
+ "color": "red",
+ "value": 6554
+ }
+ ]
+ },
+ "unit": "cpm"
+ },
+ "overrides": []
+ },
+ "gridPos": {
+ "h": 6,
+ "w": 5,
+ "x": 19,
+ "y": 32
+ },
+ "id": 52,
+ "options": {
+ "orientation": "auto",
+ "reduceOptions": {
+ "calcs": ["last"],
+ "fields": "",
+ "values": false
+ },
+ "showThresholdLabels": false,
+ "showThresholdMarkers": true,
+ "text": {}
+ },
+ "pluginVersion": "7.5.10",
+ "targets": [
+ {
+ "alias": "req-http",
+ "formatType": "Time series",
+ "queryType": "SQL",
+ "refId": "A",
+ "sql": "select sum(req_http) as req_http from log.dn where fqdn = '$fqdn' and ts >= now - 1h interval(1m)",
+ "target": "select metric",
+ "type": "timeserie"
+ },
+ {
+ "alias": "req-inserts",
+ "formatType": "Time series",
+ "hide": false,
+ "queryType": "SQL",
+ "refId": "B",
+ "sql": "select sum(req_insert) as req_insert from log.dn where fqdn = '$fqdn' and ts >= now - 1h interval(1m)",
+ "target": "select metric",
+ "type": "timeserie"
+ },
+ {
+ "alias": "req-selects",
+ "formatType": "Time series",
+ "hide": false,
+ "queryType": "SQL",
+ "refId": "C",
+ "sql": "select sum(req_select) as req_select from log.dn where fqdn = '$fqdn' and ts >= now - 1h interval(1m)",
+ "target": "select metric",
+ "type": "timeserie"
+ }
+ ],
+ "timeFrom": null,
+ "timeShift": null,
+ "title": "Requests in last Minute",
+ "type": "gauge"
+ },
+ {
+ "aliasColors": {},
+ "bars": false,
+ "cacheTimeout": null,
+ "dashLength": 10,
+ "dashes": false,
+ "datasource": "${DS_TDENGINE}",
+ "description": "monitor system cpu",
+ "fieldConfig": {
+ "defaults": {
+ "links": []
+ },
+ "overrides": []
+ },
+ "fill": 1,
+ "fillGradient": 0,
+ "gridPos": {
+ "h": 11,
+ "w": 12,
+ "x": 0,
+ "y": 38
+ },
+ "hiddenSeries": false,
+ "hideTimeOverride": true,
+ "id": 2,
+ "legend": {
+ "avg": false,
+ "current": false,
+ "max": false,
+ "min": false,
+ "show": true,
+ "total": false,
+ "values": false
+ },
+ "lines": true,
+ "linewidth": 1,
+ "links": [],
+ "nullPointMode": "null",
+ "options": {
+ "alertThreshold": true
+ },
+ "percentage": false,
+ "pluginVersion": "7.5.10",
+ "pointradius": 2,
+ "points": false,
+ "renderer": "flot",
+ "seriesOverrides": [],
+ "spaceLength": 10,
+ "stack": false,
+ "steppedLine": false,
+ "targets": [
+ {
+ "alias": "cpu_system",
+ "formatType": "Time series",
+ "hide": false,
+ "queryType": "SQL",
+ "refId": "A",
+ "sql": "select avg(cpu_system) from log.dn where fqdn='$fqdn' and ts >= now-1h and ts < now interval(30s)",
+ "target": "select metric",
+ "type": "timeserie"
+ },
+ {
+ "alias": "cpu_taosd",
+ "formatType": "Time series",
+ "hide": false,
+ "queryType": "SQL",
+ "refId": "B",
+ "sql": "select avg(cpu_taosd) from log.dn where fqdn='$fqdn' and ts >= now-1h and ts < now interval(30s)",
+ "target": "select metric",
+ "type": "timeserie"
+ }
+ ],
+ "thresholds": [],
+ "timeFrom": "1h",
+ "timeRegions": [],
+ "timeShift": "30s",
+ "title": "CPU 资源占用情况",
+ "tooltip": {
+ "shared": true,
+ "sort": 0,
+ "value_type": "individual"
+ },
+ "type": "graph",
+ "xaxis": {
+ "buckets": null,
+ "mode": "time",
+ "name": null,
+ "show": true,
+ "values": []
+ },
+ "yaxes": [
+ {
+ "decimals": null,
+ "format": "percent",
+ "label": "使用占比",
+ "logBase": 1,
+ "max": null,
+ "min": null,
+ "show": true
+ },
+ {
+ "format": "short",
+ "label": null,
+ "logBase": 1,
+ "max": null,
+ "min": null,
+ "show": false
+ }
+ ],
+ "yaxis": {
+ "align": false,
+ "alignLevel": null
+ }
+ },
+ {
+ "aliasColors": {},
+ "bars": false,
+ "cacheTimeout": null,
+ "dashLength": 10,
+ "dashes": false,
+ "datasource": "${DS_TDENGINE}",
+ "description": "monitor system cpu",
+ "fieldConfig": {
+ "defaults": {
+ "links": []
+ },
+ "overrides": []
+ },
+ "fill": 1,
+ "fillGradient": 0,
+ "gridPos": {
+ "h": 11,
+ "w": 12,
+ "x": 12,
+ "y": 38
+ },
+ "hiddenSeries": false,
+ "hideTimeOverride": true,
+ "id": 42,
+ "legend": {
+ "avg": false,
+ "current": false,
+ "max": false,
+ "min": false,
+ "show": true,
+ "total": false,
+ "values": false
+ },
+ "lines": true,
+ "linewidth": 1,
+ "links": [],
+ "nullPointMode": "null",
+ "options": {
+ "alertThreshold": true
+ },
+ "percentage": false,
+ "pluginVersion": "7.5.10",
+ "pointradius": 2,
+ "points": false,
+ "renderer": "flot",
+ "seriesOverrides": [],
+ "spaceLength": 10,
+ "stack": false,
+ "steppedLine": false,
+ "targets": [
+ {
+ "alias": "system",
+ "formatType": "Time series",
+ "hide": false,
+ "queryType": "SQL",
+ "refId": "A",
+ "sql": "select avg(mem_system) from log.dn where fqdn = '$fqdn' and ts >= now-1h and ts < now interval(30s)",
+ "target": "select metric",
+ "type": "timeserie"
+ },
+ {
+ "alias": "taosd",
+ "formatType": "Time series",
+ "hide": false,
+ "queryType": "SQL",
+ "refId": "B",
+ "sql": "select avg(mem_taosd) from log.dn where fqdn = '$fqdn' and ts >= now-1h and ts < now interval(30s)",
+ "target": "select metric",
+ "type": "timeserie"
+ },
+ {
+ "alias": "total",
+ "formatType": "Time series",
+ "hide": false,
+ "queryType": "SQL",
+ "refId": "C",
+ "sql": "select avg(mem_total) from log.dn where fqdn = '$fqdn' and ts >= now-1h and ts < now interval(30s)",
+ "target": "select metric",
+ "type": "timeserie"
+ }
+ ],
+ "thresholds": [],
+ "timeFrom": "1h",
+ "timeRegions": [],
+ "timeShift": "30s",
+ "title": "内存资源占用情况",
+ "tooltip": {
+ "shared": true,
+ "sort": 0,
+ "value_type": "individual"
+ },
+ "type": "graph",
+ "xaxis": {
+ "buckets": null,
+ "mode": "time",
+ "name": null,
+ "show": true,
+ "values": []
+ },
+ "yaxes": [
+ {
+ "decimals": null,
+ "format": "decmbytes",
+ "label": "使用占比",
+ "logBase": 1,
+ "max": null,
+ "min": null,
+ "show": true
+ },
+ {
+ "format": "short",
+ "label": null,
+ "logBase": 1,
+ "max": null,
+ "min": null,
+ "show": false
+ }
+ ],
+ "yaxis": {
+ "align": false,
+ "alignLevel": null
+ }
+ },
+ {
+ "aliasColors": {},
+ "bars": false,
+ "dashLength": 10,
+ "dashes": false,
+ "datasource": "${DS_TDENGINE}",
+ "fieldConfig": {
+ "defaults": {},
+ "overrides": []
+ },
+ "fill": 1,
+ "fillGradient": 0,
+ "gridPos": {
+ "h": 9,
+ "w": 12,
+ "x": 0,
+ "y": 49
+ },
+ "hiddenSeries": false,
+ "id": 54,
+ "legend": {
+ "alignAsTable": false,
+ "avg": false,
+ "current": true,
+ "max": false,
+ "min": false,
+ "rightSide": false,
+ "show": true,
+ "total": false,
+ "values": true
+ },
+ "lines": true,
+ "linewidth": 1,
+ "nullPointMode": "null",
+ "options": {
+ "alertThreshold": true
+ },
+ "percentage": false,
+ "pluginVersion": "7.5.10",
+ "pointradius": 2,
+ "points": false,
+ "renderer": "flot",
+ "seriesOverrides": [
+ {
+ "alias": "percent",
+ "yaxis": 2
+ }
+ ],
+ "spaceLength": 10,
+ "stack": false,
+ "steppedLine": false,
+ "targets": [
+ {
+ "alias": "disk_used",
+ "formatType": "Time series",
+ "hide": false,
+ "queryType": "SQL",
+ "refId": "A",
+ "sql": "select avg(disk_used) from log.dn where fqdn = '$fqdn' and ts >= $from and ts < $to interval(30s)",
+ "target": "select metric",
+ "timeshift": {
+ "period": null
+ },
+ "type": "timeserie"
+ },
+ {
+ "alias": "disk_total",
+ "formatType": "Time series",
+ "hide": false,
+ "queryType": "SQL",
+ "refId": "B",
+ "sql": "select avg(disk_total) from log.dn where fqdn = '$fqdn' and ts >= $from and ts < $to interval(30s)",
+ "target": "select metric",
+ "timeshift": {
+ "period": null
+ },
+ "type": "timeserie"
+ },
+ {
+ "alias": "percent",
+ "formatType": "Time series",
+ "hide": false,
+ "queryType": "SQL",
+ "refId": "D",
+ "sql": "select avg(disk_used)/avg(disk_total) * 100 from log.dn where fqdn = '$fqdn' and ts >= $from and ts < $to interval(30s)",
+ "target": "select metric",
+ "timeshift": {
+ "period": null
+ },
+ "type": "timeserie"
+ }
+ ],
+ "thresholds": [],
+ "timeFrom": null,
+ "timeRegions": [],
+ "timeShift": null,
+ "title": "Disk Used Percent",
+ "tooltip": {
+ "shared": false,
+ "sort": 0,
+ "value_type": "individual"
+ },
+ "type": "graph",
+ "xaxis": {
+ "buckets": null,
+ "mode": "time",
+ "name": null,
+ "show": true,
+ "values": []
+ },
+ "yaxes": [
+ {
+ "format": "gbytes",
+ "label": null,
+ "logBase": 1,
+ "max": null,
+ "min": null,
+ "show": true
+ },
+ {
+ "format": "percent",
+ "label": "Disk Used",
+ "logBase": 1,
+ "max": null,
+ "min": null,
+ "show": true
+ }
+ ],
+ "yaxis": {
+ "align": false,
+ "alignLevel": null
+ }
+ },
+ {
+ "aliasColors": {},
+ "bars": false,
+ "dashLength": 10,
+ "dashes": false,
+ "datasource": "${DS_TDENGINE}",
+ "fieldConfig": {
+ "defaults": {},
+ "overrides": []
+ },
+ "fill": 1,
+ "fillGradient": 0,
+ "gridPos": {
+ "h": 9,
+ "w": 12,
+ "x": 12,
+ "y": 49
+ },
+ "hiddenSeries": false,
+ "id": 64,
+ "legend": {
+ "alignAsTable": false,
+ "avg": false,
+ "current": true,
+ "max": false,
+ "min": false,
+ "rightSide": false,
+ "show": true,
+ "total": false,
+ "values": true
+ },
+ "lines": true,
+ "linewidth": 1,
+ "nullPointMode": "null",
+ "options": {
+ "alertThreshold": true
+ },
+ "percentage": false,
+ "pluginVersion": "7.5.10",
+ "pointradius": 2,
+ "points": false,
+ "renderer": "flot",
+ "seriesOverrides": [],
+ "spaceLength": 10,
+ "stack": false,
+ "steppedLine": false,
+ "targets": [
+ {
+ "alias": "disk_used",
+ "formatType": "Time series",
+ "hide": false,
+ "queryType": "SQL",
+ "refId": "A",
+ "sql": "select derivative(value, 1m, 0) from (select avg(disk_used) as value from log.dn where fqdn = '$fqdn' and ts >= $from and ts < $to interval(1m))",
+ "target": "select metric",
+ "timeshift": {
+ "period": null
+ },
+ "type": "timeserie"
+ }
+ ],
+ "thresholds": [],
+ "timeFrom": null,
+ "timeRegions": [],
+ "timeShift": null,
+ "title": "Disk Used Increasing Rate per Minute",
+ "tooltip": {
+ "shared": false,
+ "sort": 0,
+ "value_type": "individual"
+ },
+ "type": "graph",
+ "xaxis": {
+ "buckets": null,
+ "mode": "time",
+ "name": null,
+ "show": true,
+ "values": []
+ },
+ "yaxes": [
+ {
+ "format": "percentunit",
+ "label": null,
+ "logBase": 1,
+ "max": null,
+ "min": null,
+ "show": true
+ },
+ {
+ "format": "percentunit",
+ "label": "Disk Used",
+ "logBase": 1,
+ "max": null,
+ "min": null,
+ "show": true
+ }
+ ],
+ "yaxis": {
+ "align": false,
+ "alignLevel": null
+ }
+ },
+ {
+ "aliasColors": {},
+ "bars": false,
+ "cacheTimeout": null,
+ "dashLength": 10,
+ "dashes": false,
+ "datasource": "${DS_TDENGINE}",
+ "description": "total select request per minute last hour",
+ "fieldConfig": {
+ "defaults": {
+ "unit": "cpm"
+ },
+ "overrides": []
+ },
+ "fill": 1,
+ "fillGradient": 0,
+ "gridPos": {
+ "h": 9,
+ "w": 12,
+ "x": 0,
+ "y": 58
+ },
+ "hiddenSeries": false,
+ "id": 8,
+ "interval": null,
+ "legend": {
+ "avg": false,
+ "current": false,
+ "max": false,
+ "min": false,
+ "show": true,
+ "total": false,
+ "values": false
+ },
+ "lines": true,
+ "linewidth": 1,
+ "links": [],
+ "maxDataPoints": 100,
+ "nullPointMode": "null",
+ "options": {
+ "alertThreshold": true
+ },
+ "percentage": false,
+ "pluginVersion": "7.5.10",
+ "pointradius": 2,
+ "points": false,
+ "renderer": "flot",
+ "seriesOverrides": [],
+ "spaceLength": 10,
+ "stack": false,
+ "steppedLine": false,
+ "targets": [
+ {
+ "alias": "req_select",
+ "formatType": "Time series",
+ "queryType": "SQL",
+ "refId": "A",
+ "sql": "select sum(req_select) from log.dn where fqdn = '$fqdn' and ts >= $from and ts < $to interval(1m)",
+ "target": "select metric",
+ "timeshift": {
+ "period": null
+ },
+ "type": "timeserie"
+ },
+ {
+ "alias": "req_insert",
+ "formatType": "Time series",
+ "hide": false,
+ "queryType": "SQL",
+ "refId": "B",
+ "sql": "select sum(req_insert) from log.dn where fqdn = '$fqdn' and ts >= $from and ts < $to interval(1m)",
+ "target": "select metric",
+ "type": "timeserie"
+ },
+ {
+ "alias": "req_http",
+ "formatType": "Time series",
+ "hide": false,
+ "queryType": "SQL",
+ "refId": "C",
+ "sql": "select sum(req_http) from log.dn where fqdn = '$fqdn' and ts >= $from and ts < $to interval(1m)",
+ "target": "select metric",
+ "type": "timeserie"
+ }
+ ],
+ "thresholds": [],
+ "timeFrom": null,
+ "timeRegions": [],
+ "timeShift": null,
+ "title": "Requets Count per Minutes $fqdn",
+ "tooltip": {
+ "shared": true,
+ "sort": 0,
+ "value_type": "individual"
+ },
+ "type": "graph",
+ "xaxis": {
+ "buckets": null,
+ "mode": "time",
+ "name": null,
+ "show": true,
+ "values": []
+ },
+ "yaxes": [
+ {
+ "format": "cpm",
+ "label": null,
+ "logBase": 1,
+ "max": null,
+ "min": "0",
+ "show": true
+ },
+ {
+ "format": "short",
+ "label": null,
+ "logBase": 1,
+ "max": null,
+ "min": null,
+ "show": true
+ }
+ ],
+ "yaxis": {
+ "align": false,
+ "alignLevel": null
+ }
+ },
+ {
+ "aliasColors": {},
+ "bars": false,
+ "cacheTimeout": null,
+ "dashLength": 10,
+ "dashes": false,
+ "datasource": "${DS_TDENGINE}",
+ "description": "io",
+ "fieldConfig": {
+ "defaults": {
+ "links": [],
+ "unit": "Kbits"
+ },
+ "overrides": []
+ },
+ "fill": 1,
+ "fillGradient": 0,
+ "gridPos": {
+ "h": 9,
+ "w": 12,
+ "x": 12,
+ "y": 58
+ },
+ "hiddenSeries": false,
+ "hideTimeOverride": true,
+ "id": 47,
+ "legend": {
+ "avg": false,
+ "current": false,
+ "max": false,
+ "min": false,
+ "show": true,
+ "total": false,
+ "values": false
+ },
+ "lines": true,
+ "linewidth": 1,
+ "links": [],
+ "nullPointMode": "null",
+ "options": {
+ "alertThreshold": true
+ },
+ "percentage": false,
+ "pluginVersion": "7.5.10",
+ "pointradius": 2,
+ "points": false,
+ "renderer": "flot",
+ "seriesOverrides": [],
+ "spaceLength": 10,
+ "stack": false,
+ "steppedLine": false,
+ "targets": [
+ {
+ "alias": "io-read",
+ "formatType": "Time series",
+ "hide": false,
+ "queryType": "SQL",
+ "refId": "A",
+ "sql": "select avg(io_read) from log.dn where fqdn = '$fqdn' and ts >= now-1h and ts < now interval(1m)",
+ "target": "select metric",
+ "type": "timeserie"
+ },
+ {
+ "alias": "io-write",
+ "formatType": "Time series",
+ "hide": false,
+ "queryType": "SQL",
+ "refId": "B",
+ "sql": "select avg(io_write) from log.dn where fqdn = '$fqdn' and ts >= now-1h and ts < now interval(1m)",
+ "target": "select metric",
+ "type": "timeserie"
+ },
+ {
+ "alias": "io-read-last-hour",
+ "formatType": "Time series",
+ "hide": false,
+ "queryType": "SQL",
+ "refId": "C",
+ "sql": "select avg(io_read) from log.dn where fqdn = '$fqdn' and ts >= now-2h and ts < now - 1h interval(1m)",
+ "target": "select metric",
+ "timeshift": {
+ "period": 1,
+ "unit": "hours"
+ },
+ "type": "timeserie"
+ },
+ {
+ "alias": "io-write-last-hour",
+ "formatType": "Time series",
+ "hide": false,
+ "queryType": "SQL",
+ "refId": "D",
+ "sql": "select avg(io_write) from log.dn where fqdn = '$fqdn' and ts >= now-1h and ts < now interval(1m)",
+ "target": "select metric",
+ "timeshift": {
+ "period": 1,
+ "unit": "hours"
+ },
+ "type": "timeserie"
+ }
+ ],
+ "thresholds": [],
+ "timeFrom": "1h",
+ "timeRegions": [],
+ "timeShift": "30s",
+ "title": "IO",
+ "tooltip": {
+ "shared": true,
+ "sort": 0,
+ "value_type": "individual"
+ },
+ "type": "graph",
+ "xaxis": {
+ "buckets": null,
+ "mode": "time",
+ "name": null,
+ "show": true,
+ "values": []
+ },
+ "yaxes": [
+ {
+ "decimals": null,
+ "format": "Kbits",
+ "label": "IO Rate",
+ "logBase": 1,
+ "max": null,
+ "min": null,
+ "show": true
+ },
+ {
+ "format": "short",
+ "label": null,
+ "logBase": 1,
+ "max": null,
+ "min": null,
+ "show": false
+ }
+ ],
+ "yaxis": {
+ "align": false,
+ "alignLevel": null
+ }
+ },
+ {
+ "collapsed": false,
+ "datasource": null,
+ "gridPos": {
+ "h": 1,
+ "w": 24,
+ "x": 0,
+ "y": 67
+ },
+ "id": 63,
+ "panels": [],
+ "title": "Login History",
+ "type": "row"
+ },
+ {
+ "aliasColors": {},
+ "bars": false,
+ "dashLength": 10,
+ "dashes": false,
+ "datasource": "${DS_TDENGINE}",
+ "fieldConfig": {
+ "defaults": {
+ "displayName": "Logins Per Minute",
+ "unit": "cpm"
+ },
+ "overrides": []
+ },
+ "fill": 1,
+ "fillGradient": 0,
+ "gridPos": {
+ "h": 8,
+ "w": 12,
+ "x": 0,
+ "y": 68
+ },
+ "hiddenSeries": false,
+ "id": 61,
+ "legend": {
+ "avg": false,
+ "current": false,
+ "max": false,
+ "min": false,
+ "show": true,
+ "total": false,
+ "values": false
+ },
+ "lines": true,
+ "linewidth": 1,
+ "nullPointMode": "null",
+ "options": {
+ "alertThreshold": true
+ },
+ "percentage": false,
+ "pluginVersion": "7.5.10",
+ "pointradius": 2,
+ "points": false,
+ "renderer": "flot",
+ "seriesOverrides": [
+ {
+ "alias": "logins",
+ "nullPointMode": "null as zero"
+ }
+ ],
+ "spaceLength": 10,
+ "stack": false,
+ "steppedLine": false,
+ "targets": [
+ {
+ "alias": "logins",
+ "formatType": "Time series",
+ "queryType": "SQL",
+ "refId": "A",
+ "sql": "select count(*) from log.log where ts >= $from and ts < $to interval (1m)",
+ "target": "select metric",
+ "type": "timeserie"
+ }
+ ],
+ "thresholds": [],
+ "timeFrom": null,
+ "timeRegions": [],
+ "timeShift": null,
+ "title": "Login Counts per Minute",
+ "tooltip": {
+ "shared": true,
+ "sort": 0,
+ "value_type": "individual"
+ },
+ "type": "graph",
+ "xaxis": {
+ "buckets": null,
+ "mode": "time",
+ "name": null,
+ "show": true,
+ "values": []
+ },
+ "yaxes": [
+ {
+ "format": "cpm",
+ "label": null,
+ "logBase": 1,
+ "max": null,
+ "min": null,
+ "show": true
+ },
+ {
+ "format": "short",
+ "label": null,
+ "logBase": 1,
+ "max": null,
+ "min": null,
+ "show": true
+ }
+ ],
+ "yaxis": {
+ "align": false,
+ "alignLevel": null
+ }
+ }
+ ],
+ "refresh": "1m",
+ "schemaVersion": 27,
+ "style": "dark",
+ "tags": ["TDengine", "multiple"],
+ "templating": {
+ "list": [
+ {
+ "current": {
+ "selected": false,
+ "text": "TDengine",
+ "value": "TDengine"
+ },
+ "description": "TDengine Data Source Selector",
+ "error": null,
+ "hide": 0,
+ "includeAll": false,
+ "label": "Datasource",
+ "multi": false,
+ "name": "ds",
+ "options": [],
+ "query": "tdengine-datasource",
+ "queryValue": "",
+ "refresh": 1,
+ "regex": "",
+ "skipUrlSync": false,
+ "type": "datasource"
+ },
+ {
+ "allValue": null,
+ "current": {},
+ "datasource": "${DS_TDENGINE}",
+ "definition": "select fqdn from log.dn",
+ "description": "TDengine Nodes FQDN (Hostname)",
+ "error": null,
+ "hide": 0,
+ "includeAll": false,
+ "label": null,
+ "multi": false,
+ "name": "fqdn",
+ "options": [],
+ "query": "select fqdn from log.dn",
+ "refresh": 1,
+ "regex": "",
+ "skipUrlSync": false,
+ "sort": 0,
+ "tagValuesQuery": "",
+ "tags": [],
+ "tagsQuery": "",
+ "type": "query",
+ "useTags": false
+ }
+ ]
+ },
+ "time": {
+ "from": "now-1h",
+ "to": "now"
+ },
+ "timepicker": {
+ "refresh_intervals": ["5s", "10s", "30s", "1m", "5m", "15m", "30m", "1h", "2h", "1d"]
+ },
+ "timezone": "",
+ "title": "Multiple TDengines Monitoring",
+ "uid": "tdengine-multiple",
+ "version": 4
+}
diff --git a/docs-cn/14-reference/07-tdinsight/assets/15155-tdengine-alert-demo.json b/docs-cn/14-reference/07-tdinsight/assets/15155-tdengine-alert-demo.json
new file mode 100644
index 0000000000000000000000000000000000000000..ab98354aaeae8c4dc945aae085d12fec50b530d1
--- /dev/null
+++ b/docs-cn/14-reference/07-tdinsight/assets/15155-tdengine-alert-demo.json
@@ -0,0 +1,212 @@
+{
+ "__inputs": [
+ {
+ "name": "DS_TDENGINE",
+ "label": "TDengine",
+ "description": "",
+ "type": "datasource",
+ "pluginId": "tdengine-datasource",
+ "pluginName": "TDengine"
+ }
+ ],
+ "__requires": [
+ {
+ "type": "grafana",
+ "id": "grafana",
+ "name": "Grafana",
+ "version": "7.5.10"
+ },
+ {
+ "type": "panel",
+ "id": "graph",
+ "name": "Graph",
+ "version": ""
+ },
+ {
+ "type": "datasource",
+ "id": "tdengine-datasource",
+ "name": "TDengine",
+ "version": "3.1.0"
+ }
+ ],
+ "annotations": {
+ "list": [
+ {
+ "builtIn": 1,
+ "datasource": "-- Grafana --",
+ "enable": true,
+ "hide": true,
+ "iconColor": "rgba(0, 211, 255, 1)",
+ "name": "Annotations & Alerts",
+ "type": "dashboard"
+ }
+ ]
+ },
+ "description": "",
+ "editable": true,
+ "gnetId": null,
+ "graphTooltip": 0,
+ "id": null,
+ "links": [],
+ "panels": [
+ {
+ "alert": {
+ "alertRuleTags": {},
+ "conditions": [
+ {
+ "evaluator": {
+ "params": [5],
+ "type": "gt"
+ },
+ "operator": {
+ "type": "and"
+ },
+ "query": {
+ "params": ["A", "10s", "now"]
+ },
+ "reducer": {
+ "params": [],
+ "type": "avg"
+ },
+ "type": "query"
+ }
+ ],
+ "executionErrorState": "alerting",
+ "for": "5m",
+ "frequency": "10s",
+ "handler": 1,
+ "message": "This is a alert demo!",
+ "name": "cpu load average alert",
+ "noDataState": "no_data",
+ "notifications": [
+ {
+ "uid": "4sKm9jd7k"
+ },
+ {
+ "uid": "QyczKkFnk"
+ }
+ ]
+ },
+ "aliasColors": {},
+ "bars": false,
+ "dashLength": 10,
+ "dashes": false,
+ "datasource": "${DS_TDENGINE}",
+ "decimals": null,
+ "fieldConfig": {
+ "defaults": {},
+ "overrides": []
+ },
+ "fill": 1,
+ "fillGradient": 0,
+ "gridPos": {
+ "h": 9,
+ "w": 12,
+ "x": 0,
+ "y": 0
+ },
+ "hiddenSeries": false,
+ "id": 2,
+ "legend": {
+ "avg": true,
+ "current": true,
+ "hideEmpty": false,
+ "max": true,
+ "min": true,
+ "show": true,
+ "total": false,
+ "values": true
+ },
+ "lines": true,
+ "linewidth": 1,
+ "nullPointMode": "null",
+ "options": {
+ "alertThreshold": true
+ },
+ "percentage": false,
+ "pluginVersion": "7.5.10",
+ "pointradius": 2,
+ "points": false,
+ "renderer": "flot",
+ "seriesOverrides": [],
+ "spaceLength": 10,
+ "stack": false,
+ "steppedLine": false,
+ "targets": [
+ {
+ "alias": "system",
+ "formatType": "Time series",
+ "queryType": "SQL",
+ "refId": "A",
+ "sql": "select avg(cpu_system) as system from log.dn where ts >= now-1h and ts < now interval(30s)",
+ "target": "select metric",
+ "type": "timeserie"
+ }
+ ],
+ "thresholds": [
+ {
+ "colorMode": "critical",
+ "fill": true,
+ "line": true,
+ "op": "gt",
+ "value": 5,
+ "visible": true
+ }
+ ],
+ "timeFrom": null,
+ "timeRegions": [],
+ "timeShift": null,
+ "title": "CPU Load Average",
+ "tooltip": {
+ "shared": true,
+ "sort": 0,
+ "value_type": "individual"
+ },
+ "type": "graph",
+ "xaxis": {
+ "buckets": null,
+ "mode": "time",
+ "name": null,
+ "show": true,
+ "values": []
+ },
+ "yaxes": [
+ {
+ "format": "percent",
+ "label": "Percent",
+ "logBase": 1,
+ "max": null,
+ "min": null,
+ "show": true
+ },
+ {
+ "format": "short",
+ "label": "",
+ "logBase": 1,
+ "max": null,
+ "min": null,
+ "show": false
+ }
+ ],
+ "yaxis": {
+ "align": false,
+ "alignLevel": null
+ }
+ }
+ ],
+ "schemaVersion": 27,
+ "style": "dark",
+ "tags": ["TDengine"],
+ "templating": {
+ "list": []
+ },
+ "time": {
+ "from": "now-1h",
+ "to": "now"
+ },
+ "timepicker": {},
+ "timezone": "",
+ "title": "TDengine Alert Demo",
+ "uid": "aLN9ujOnk",
+ "version": 15
+}
diff --git a/docs-cn/14-reference/07-tdinsight/assets/TDinsight-1-cluster-status.png b/docs-cn/14-reference/07-tdinsight/assets/TDinsight-1-cluster-status.png
new file mode 100644
index 0000000000000000000000000000000000000000..4708f836feb21980f2db7fed4a55f799b23a6ec1
Binary files /dev/null and b/docs-cn/14-reference/07-tdinsight/assets/TDinsight-1-cluster-status.png differ
diff --git a/docs-cn/14-reference/07-tdinsight/assets/TDinsight-2-dnodes.png b/docs-cn/14-reference/07-tdinsight/assets/TDinsight-2-dnodes.png
new file mode 100644
index 0000000000000000000000000000000000000000..f2684e6eed70e8f56697eae42b495d6bd62815e8
Binary files /dev/null and b/docs-cn/14-reference/07-tdinsight/assets/TDinsight-2-dnodes.png differ
diff --git a/docs-cn/14-reference/07-tdinsight/assets/TDinsight-3-mnodes.png b/docs-cn/14-reference/07-tdinsight/assets/TDinsight-3-mnodes.png
new file mode 100644
index 0000000000000000000000000000000000000000..74686691e4106b8646c3deee1e0ce73b2f53f1ea
Binary files /dev/null and b/docs-cn/14-reference/07-tdinsight/assets/TDinsight-3-mnodes.png differ
diff --git a/docs-cn/14-reference/07-tdinsight/assets/TDinsight-4-requests.png b/docs-cn/14-reference/07-tdinsight/assets/TDinsight-4-requests.png
new file mode 100644
index 0000000000000000000000000000000000000000..27964215567f9f961c0aeaf1b863188437008fb7
Binary files /dev/null and b/docs-cn/14-reference/07-tdinsight/assets/TDinsight-4-requests.png differ
diff --git a/docs-cn/14-reference/07-tdinsight/assets/TDinsight-5-database.png b/docs-cn/14-reference/07-tdinsight/assets/TDinsight-5-database.png
new file mode 100644
index 0000000000000000000000000000000000000000..b0d3abbf21ec4d4bd7bfb95fcc03a5f936b22665
Binary files /dev/null and b/docs-cn/14-reference/07-tdinsight/assets/TDinsight-5-database.png differ
diff --git a/docs-cn/14-reference/07-tdinsight/assets/TDinsight-6-dnode-usage.png b/docs-cn/14-reference/07-tdinsight/assets/TDinsight-6-dnode-usage.png
new file mode 100644
index 0000000000000000000000000000000000000000..2b54cbeb83bcff12f20461a4f57f882e2073f231
Binary files /dev/null and b/docs-cn/14-reference/07-tdinsight/assets/TDinsight-6-dnode-usage.png differ
diff --git a/docs-cn/14-reference/07-tdinsight/assets/TDinsight-7-login-history.png b/docs-cn/14-reference/07-tdinsight/assets/TDinsight-7-login-history.png
new file mode 100644
index 0000000000000000000000000000000000000000..eb3848657f13900c856ac595c20766465157e9c4
Binary files /dev/null and b/docs-cn/14-reference/07-tdinsight/assets/TDinsight-7-login-history.png differ
diff --git a/docs-cn/14-reference/07-tdinsight/assets/TDinsight-8-taosadaper.png b/docs-cn/14-reference/07-tdinsight/assets/TDinsight-8-taosadaper.png
new file mode 100644
index 0000000000000000000000000000000000000000..d94b2e02ac9855bb3d2f77d8902e068839db364f
Binary files /dev/null and b/docs-cn/14-reference/07-tdinsight/assets/TDinsight-8-taosadaper.png differ
diff --git a/docs-cn/14-reference/07-tdinsight/assets/TDinsight-full.png b/docs-cn/14-reference/07-tdinsight/assets/TDinsight-full.png
new file mode 100644
index 0000000000000000000000000000000000000000..654df2934597ce600a1dc2dcd0cab7e29de7076d
Binary files /dev/null and b/docs-cn/14-reference/07-tdinsight/assets/TDinsight-full.png differ
diff --git a/docs-cn/14-reference/07-tdinsight/assets/alert-manager-status.png b/docs-cn/14-reference/07-tdinsight/assets/alert-manager-status.png
new file mode 100644
index 0000000000000000000000000000000000000000..e3afa22c0326d70567ec4529c83101c746daac87
Binary files /dev/null and b/docs-cn/14-reference/07-tdinsight/assets/alert-manager-status.png differ
diff --git a/docs-cn/14-reference/07-tdinsight/assets/alert-notification-channel.png b/docs-cn/14-reference/07-tdinsight/assets/alert-notification-channel.png
new file mode 100644
index 0000000000000000000000000000000000000000..198bf37141c86a66cdd91b47a331bcdeb83daaf8
Binary files /dev/null and b/docs-cn/14-reference/07-tdinsight/assets/alert-notification-channel.png differ
diff --git a/docs-cn/14-reference/07-tdinsight/assets/alert-query-demo.png b/docs-cn/14-reference/07-tdinsight/assets/alert-query-demo.png
new file mode 100644
index 0000000000000000000000000000000000000000..ace3aa3c2f8f14fabdac54bc25ae2d9449445b69
Binary files /dev/null and b/docs-cn/14-reference/07-tdinsight/assets/alert-query-demo.png differ
diff --git a/docs-cn/14-reference/07-tdinsight/assets/alert-rule-condition-notifications.png b/docs-cn/14-reference/07-tdinsight/assets/alert-rule-condition-notifications.png
new file mode 100644
index 0000000000000000000000000000000000000000..7082e49f6beb8690c36f98a3f4ff2befdb8fd014
Binary files /dev/null and b/docs-cn/14-reference/07-tdinsight/assets/alert-rule-condition-notifications.png differ
diff --git a/docs-cn/14-reference/07-tdinsight/assets/alert-rule-test.png b/docs-cn/14-reference/07-tdinsight/assets/alert-rule-test.png
new file mode 100644
index 0000000000000000000000000000000000000000..ffd4911b53854c42dbf0ff11838cb604fa694138
Binary files /dev/null and b/docs-cn/14-reference/07-tdinsight/assets/alert-rule-test.png differ
diff --git a/docs-cn/14-reference/07-tdinsight/assets/howto-add-datasource-button.png b/docs-cn/14-reference/07-tdinsight/assets/howto-add-datasource-button.png
new file mode 100644
index 0000000000000000000000000000000000000000..802c7366f921301bd7fbc62458e56b2d1eaf195c
Binary files /dev/null and b/docs-cn/14-reference/07-tdinsight/assets/howto-add-datasource-button.png differ
diff --git a/docs-cn/14-reference/07-tdinsight/assets/howto-add-datasource-tdengine.png b/docs-cn/14-reference/07-tdinsight/assets/howto-add-datasource-tdengine.png
new file mode 100644
index 0000000000000000000000000000000000000000..019ec921b6f808671f4f864ddf3380159d4a0dcc
Binary files /dev/null and b/docs-cn/14-reference/07-tdinsight/assets/howto-add-datasource-tdengine.png differ
diff --git a/docs-cn/14-reference/07-tdinsight/assets/howto-add-datasource-test.png b/docs-cn/14-reference/07-tdinsight/assets/howto-add-datasource-test.png
new file mode 100644
index 0000000000000000000000000000000000000000..3963abb4ea8ae0e6f5557466f7a5b746c2d2ea3c
Binary files /dev/null and b/docs-cn/14-reference/07-tdinsight/assets/howto-add-datasource-test.png differ
diff --git a/docs-cn/14-reference/07-tdinsight/assets/howto-add-datasource.png b/docs-cn/14-reference/07-tdinsight/assets/howto-add-datasource.png
new file mode 100644
index 0000000000000000000000000000000000000000..837100464b35a5cafac474723aef603f91945ebc
Binary files /dev/null and b/docs-cn/14-reference/07-tdinsight/assets/howto-add-datasource.png differ
diff --git a/docs-cn/14-reference/07-tdinsight/assets/howto-dashboard-display.png b/docs-cn/14-reference/07-tdinsight/assets/howto-dashboard-display.png
new file mode 100644
index 0000000000000000000000000000000000000000..98223df25499effac343ff5723544a3c289f18fa
Binary files /dev/null and b/docs-cn/14-reference/07-tdinsight/assets/howto-dashboard-display.png differ
diff --git a/docs-cn/14-reference/07-tdinsight/assets/howto-dashboard-import-options.png b/docs-cn/14-reference/07-tdinsight/assets/howto-dashboard-import-options.png
new file mode 100644
index 0000000000000000000000000000000000000000..07aba348f02b4fb8ef68e79664920c119b842d4c
Binary files /dev/null and b/docs-cn/14-reference/07-tdinsight/assets/howto-dashboard-import-options.png differ
diff --git a/docs-cn/14-reference/07-tdinsight/assets/howto-import-dashboard.png b/docs-cn/14-reference/07-tdinsight/assets/howto-import-dashboard.png
new file mode 100644
index 0000000000000000000000000000000000000000..7e28939ead8bf3b6e2b4330e4f9b59c2e39b5c1c
Binary files /dev/null and b/docs-cn/14-reference/07-tdinsight/assets/howto-import-dashboard.png differ
diff --git a/docs-cn/14-reference/07-tdinsight/assets/import-dashboard-15167.png b/docs-cn/14-reference/07-tdinsight/assets/import-dashboard-15167.png
new file mode 100644
index 0000000000000000000000000000000000000000..981f640b14d18aa6f0682768d8405a232df500f6
Binary files /dev/null and b/docs-cn/14-reference/07-tdinsight/assets/import-dashboard-15167.png differ
diff --git a/docs-cn/14-reference/07-tdinsight/assets/import-dashboard-for-tdengine.png b/docs-cn/14-reference/07-tdinsight/assets/import-dashboard-for-tdengine.png
new file mode 100644
index 0000000000000000000000000000000000000000..94ef4fa5fe63e535118a81707b413c028ce01f70
Binary files /dev/null and b/docs-cn/14-reference/07-tdinsight/assets/import-dashboard-for-tdengine.png differ
diff --git a/docs-cn/14-reference/07-tdinsight/assets/import-via-grafana-dot-com.png b/docs-cn/14-reference/07-tdinsight/assets/import-via-grafana-dot-com.png
new file mode 100644
index 0000000000000000000000000000000000000000..670cacc377c2801fa9437c3c132c5c7fbc361b0f
Binary files /dev/null and b/docs-cn/14-reference/07-tdinsight/assets/import-via-grafana-dot-com.png differ
diff --git a/docs-cn/14-reference/07-tdinsight/assets/import_dashboard.png b/docs-cn/14-reference/07-tdinsight/assets/import_dashboard.png
new file mode 100644
index 0000000000000000000000000000000000000000..d74cd36c96ee0fd24ddc6feae2da07824816f745
Binary files /dev/null and b/docs-cn/14-reference/07-tdinsight/assets/import_dashboard.png differ
diff --git a/docs-cn/14-reference/07-tdinsight/assets/tdengine-grafana-7.x.json b/docs-cn/14-reference/07-tdinsight/assets/tdengine-grafana-7.x.json
new file mode 100644
index 0000000000000000000000000000000000000000..b4254c428b28a0084e54b5e3c509dd2e0ec651b9
--- /dev/null
+++ b/docs-cn/14-reference/07-tdinsight/assets/tdengine-grafana-7.x.json
@@ -0,0 +1,3358 @@
+{
+ "annotations": {
+ "list": [
+ {
+ "builtIn": 1,
+ "datasource": "-- Grafana --",
+ "enable": true,
+ "hide": true,
+ "iconColor": "rgba(0, 211, 255, 1)",
+ "name": "Annotations & Alerts",
+ "type": "dashboard"
+ }
+ ]
+ },
+ "description": "TDengine nodes metrics.",
+ "editable": true,
+ "gnetId": null,
+ "graphTooltip": 0,
+ "id": 3,
+ "iteration": 1634275785625,
+ "links": [],
+ "panels": [
+ {
+ "collapsed": false,
+ "datasource": null,
+ "gridPos": {
+ "h": 1,
+ "w": 24,
+ "x": 0,
+ "y": 0
+ },
+ "id": 57,
+ "panels": [],
+ "title": "Cluster Status",
+ "type": "row"
+ },
+ {
+ "datasource": null,
+ "fieldConfig": {
+ "defaults": {},
+ "overrides": []
+ },
+ "gridPos": {
+ "h": 3,
+ "w": 24,
+ "x": 0,
+ "y": 1
+ },
+ "id": 32,
+ "options": {
+ "content": "TDengine Cluster Dashboard
>\n",
+ "mode": "markdown"
+ },
+ "pluginVersion": "7.5.10",
+ "repeatDirection": "h",
+ "targets": [
+ {
+ "alias": "mnodes",
+ "formatType": "Time series",
+ "queryType": "SQL",
+ "refId": "A",
+ "sql": "show mnodes",
+ "target": "select metric",
+ "timeshift": {
+ "period": null
+ },
+ "type": "timeserie"
+ }
+ ],
+ "timeFrom": null,
+ "timeShift": null,
+ "title": "-- OVERVIEW --",
+ "transformations": [
+ {
+ "id": "calculateField",
+ "options": {
+ "binary": {
+ "left": "Time",
+ "operator": "+",
+ "reducer": "sum",
+ "right": ""
+ },
+ "mode": "binary",
+ "reduce": {
+ "reducer": "sum"
+ }
+ }
+ }
+ ],
+ "type": "text"
+ },
+ {
+ "datasource": "${ds}",
+ "fieldConfig": {
+ "defaults": {
+ "color": {
+ "mode": "thresholds"
+ },
+ "mappings": [],
+ "thresholds": {
+ "mode": "absolute",
+ "steps": [
+ {
+ "color": "green",
+ "value": null
+ },
+ {
+ "color": "red",
+ "value": 80
+ }
+ ]
+ }
+ },
+ "overrides": []
+ },
+ "gridPos": {
+ "h": 3,
+ "w": 8,
+ "x": 0,
+ "y": 4
+ },
+ "id": 28,
+ "options": {
+ "colorMode": "value",
+ "graphMode": "area",
+ "justifyMode": "auto",
+ "orientation": "auto",
+ "reduceOptions": {
+ "calcs": [
+ "lastNotNull"
+ ],
+ "fields": "",
+ "values": true
+ },
+ "text": {},
+ "textMode": "auto"
+ },
+ "pluginVersion": "7.5.10",
+ "repeatDirection": "h",
+ "targets": [
+ {
+ "alias": "dnodes",
+ "formatType": "Time series",
+ "queryType": "SQL",
+ "refId": "A",
+ "sql": "show mnodes",
+ "target": "select metric",
+ "timeshift": {
+ "period": null
+ },
+ "type": "timeserie"
+ }
+ ],
+ "timeFrom": null,
+ "timeShift": null,
+ "title": "Master MNode",
+ "transformations": [
+ {
+ "id": "filterByValue",
+ "options": {
+ "filters": [
+ {
+ "config": {
+ "id": "regex",
+ "options": {
+ "value": "master"
+ }
+ },
+ "fieldName": "role"
+ }
+ ],
+ "match": "all",
+ "type": "include"
+ }
+ },
+ {
+ "id": "filterFieldsByName",
+ "options": {
+ "include": {
+ "names": [
+ "dnodes"
+ ]
+ }
+ }
+ }
+ ],
+ "type": "stat"
+ },
+ {
+ "datasource": "${ds}",
+ "fieldConfig": {
+ "defaults": {
+ "color": {
+ "mode": "thresholds"
+ },
+ "mappings": [],
+ "thresholds": {
+ "mode": "absolute",
+ "steps": [
+ {
+ "color": "green",
+ "value": null
+ }
+ ]
+ }
+ },
+ "overrides": []
+ },
+ "gridPos": {
+ "h": 3,
+ "w": 7,
+ "x": 8,
+ "y": 4
+ },
+ "id": 70,
+ "options": {
+ "colorMode": "value",
+ "graphMode": "area",
+ "justifyMode": "auto",
+ "orientation": "auto",
+ "reduceOptions": {
+ "calcs": [
+ "lastNotNull"
+ ],
+ "fields": "/^Time$/",
+ "values": true
+ },
+ "text": {},
+ "textMode": "auto"
+ },
+ "pluginVersion": "7.5.10",
+ "repeatDirection": "h",
+ "targets": [
+ {
+ "alias": "dnodes",
+ "formatType": "Time series",
+ "queryType": "SQL",
+ "refId": "A",
+ "sql": "show mnodes",
+ "target": "select metric",
+ "timeshift": {
+ "period": null
+ },
+ "type": "timeserie"
+ }
+ ],
+ "timeFrom": null,
+ "timeShift": null,
+ "title": "Master MNode Create Time",
+ "transformations": [
+ {
+ "id": "filterByValue",
+ "options": {
+ "filters": [
+ {
+ "config": {
+ "id": "regex",
+ "options": {
+ "value": "master"
+ }
+ },
+ "fieldName": "role"
+ }
+ ],
+ "match": "all",
+ "type": "include"
+ }
+ },
+ {
+ "id": "filterFieldsByName",
+ "options": {
+ "include": {
+ "names": [
+ "Time"
+ ]
+ }
+ }
+ },
+ {
+ "id": "calculateField",
+ "options": {
+ "mode": "reduceRow",
+ "reduce": {
+ "reducer": "min"
+ }
+ }
+ }
+ ],
+ "type": "stat"
+ },
+ {
+ "datasource": "${ds}",
+ "fieldConfig": {
+ "defaults": {
+ "color": {
+ "mode": "thresholds"
+ },
+ "custom": {
+ "align": null,
+ "filterable": false
+ },
+ "mappings": [],
+ "thresholds": {
+ "mode": "absolute",
+ "steps": [
+ {
+ "color": "green",
+ "value": null
+ },
+ {
+ "color": "red",
+ "value": 80
+ }
+ ]
+ }
+ },
+ "overrides": []
+ },
+ "gridPos": {
+ "h": 9,
+ "w": 9,
+ "x": 15,
+ "y": 4
+ },
+ "id": 29,
+ "options": {
+ "showHeader": true
+ },
+ "pluginVersion": "7.5.10",
+ "repeatDirection": "h",
+ "targets": [
+ {
+ "alias": "dnodes",
+ "formatType": "Time series",
+ "queryType": "SQL",
+ "refId": "A",
+ "sql": "show variables",
+ "target": "select metric",
+ "timeshift": {
+ "period": null
+ },
+ "type": "timeserie"
+ }
+ ],
+ "timeFrom": null,
+ "timeShift": null,
+ "title": "Variables",
+ "transformations": [
+ {
+ "id": "filterFieldsByName",
+ "options": {
+ "include": {
+ "names": [
+ "value",
+ "name"
+ ]
+ }
+ }
+ },
+ {
+ "id": "filterByValue",
+ "options": {
+ "filters": [
+ {
+ "config": {
+ "id": "regex",
+ "options": {
+ "value": ".*"
+ }
+ },
+ "fieldName": "name"
+ }
+ ],
+ "match": "all",
+ "type": "include"
+ }
+ }
+ ],
+ "type": "table"
+ },
+ {
+ "datasource": "${ds}",
+ "fieldConfig": {
+ "defaults": {
+ "color": {
+ "mode": "thresholds"
+ },
+ "mappings": [],
+ "thresholds": {
+ "mode": "absolute",
+ "steps": [
+ {
+ "color": "green",
+ "value": null
+ },
+ {
+ "color": "red",
+ "value": 80
+ }
+ ]
+ }
+ },
+ "overrides": []
+ },
+ "gridPos": {
+ "h": 3,
+ "w": 2,
+ "x": 0,
+ "y": 7
+ },
+ "id": 33,
+ "options": {
+ "colorMode": "value",
+ "graphMode": "area",
+ "justifyMode": "auto",
+ "orientation": "auto",
+ "reduceOptions": {
+ "calcs": [
+ "lastNotNull"
+ ],
+ "fields": "/.*/",
+ "values": true
+ },
+ "text": {},
+ "textMode": "auto"
+ },
+ "pluginVersion": "7.5.10",
+ "repeatDirection": "h",
+ "targets": [
+ {
+ "alias": "dnodes",
+ "formatType": "Table",
+ "queryType": "SQL",
+ "refId": "A",
+ "sql": "select server_version()",
+ "target": "select metric",
+ "timeshift": {
+ "period": null
+ },
+ "type": "timeserie"
+ }
+ ],
+ "timeFrom": null,
+ "timeShift": null,
+ "title": "Server Version",
+ "transformations": [],
+ "type": "stat"
+ },
+ {
+ "datasource": "${ds}",
+ "fieldConfig": {
+ "defaults": {
+ "color": {
+ "mode": "thresholds"
+ },
+ "mappings": [],
+ "thresholds": {
+ "mode": "absolute",
+ "steps": [
+ {
+ "color": "green",
+ "value": null
+ },
+ {
+ "color": "red",
+ "value": 80
+ }
+ ]
+ }
+ },
+ "overrides": []
+ },
+ "gridPos": {
+ "h": 3,
+ "w": 3,
+ "x": 2,
+ "y": 7
+ },
+ "id": 27,
+ "options": {
+ "colorMode": "value",
+ "graphMode": "area",
+ "justifyMode": "auto",
+ "orientation": "auto",
+ "reduceOptions": {
+ "calcs": [
+ "lastNotNull"
+ ],
+ "fields": "",
+ "values": true
+ },
+ "text": {},
+ "textMode": "auto"
+ },
+ "pluginVersion": "7.5.10",
+ "repeatDirection": "h",
+ "targets": [
+ {
+ "alias": "dnodes",
+ "formatType": "Time series",
+ "queryType": "SQL",
+ "refId": "A",
+ "sql": "show mnodes",
+ "target": "select metric",
+ "timeshift": {
+ "period": null
+ },
+ "type": "timeserie"
+ }
+ ],
+ "timeFrom": null,
+ "timeShift": null,
+ "title": "Number of MNodes",
+ "transformations": [
+ {
+ "id": "filterByValue",
+ "options": {
+ "filters": [
+ {
+ "config": {
+ "id": "greater",
+ "options": {
+ "value": 0
+ }
+ },
+ "fieldName": "id"
+ }
+ ],
+ "match": "any",
+ "type": "include"
+ }
+ },
+ {
+ "id": "reduce",
+ "options": {
+ "includeTimeField": false,
+ "mode": "reduceFields",
+ "reducers": [
+ "count"
+ ]
+ }
+ },
+ {
+ "id": "filterFieldsByName",
+ "options": {
+ "include": {
+ "names": [
+ "id"
+ ]
+ }
+ }
+ }
+ ],
+ "type": "stat"
+ },
+ {
+ "datasource": "${ds}",
+ "fieldConfig": {
+ "defaults": {
+ "color": {
+ "mode": "thresholds"
+ },
+ "mappings": [],
+ "thresholds": {
+ "mode": "absolute",
+ "steps": [
+ {
+ "color": "green",
+ "value": null
+ }
+ ]
+ }
+ },
+ "overrides": []
+ },
+ "gridPos": {
+ "h": 3,
+ "w": 2,
+ "x": 5,
+ "y": 7
+ },
+ "id": 41,
+ "options": {
+ "colorMode": "value",
+ "graphMode": "none",
+ "justifyMode": "auto",
+ "orientation": "horizontal",
+ "reduceOptions": {
+ "calcs": [
+ "last"
+ ],
+ "fields": "",
+ "values": false
+ },
+ "text": {},
+ "textMode": "value"
+ },
+ "pluginVersion": "7.5.10",
+ "targets": [
+ {
+ "formatType": "Time series",
+ "queryType": "SQL",
+ "refId": "A",
+ "sql": "show dnodes",
+ "target": "select metric",
+ "type": "timeserie"
+ }
+ ],
+ "timeFrom": null,
+ "timeShift": null,
+ "title": "Total Dnodes",
+ "transformations": [
+ {
+ "id": "reduce",
+ "options": {
+ "includeTimeField": false,
+ "mode": "reduceFields",
+ "reducers": [
+ "count"
+ ]
+ }
+ },
+ {
+ "id": "filterFieldsByName",
+ "options": {
+ "include": {
+ "names": [
+ "id"
+ ]
+ }
+ }
+ }
+ ],
+ "type": "stat"
+ },
+ {
+ "datasource": "${ds}",
+ "fieldConfig": {
+ "defaults": {
+ "color": {
+ "mode": "thresholds"
+ },
+ "mappings": [],
+ "thresholds": {
+ "mode": "absolute",
+ "steps": [
+ {
+ "color": "green",
+ "value": null
+ },
+ {
+ "color": "red",
+ "value": 1
+ }
+ ]
+ }
+ },
+ "overrides": []
+ },
+ "gridPos": {
+ "h": 3,
+ "w": 2,
+ "x": 7,
+ "y": 7
+ },
+ "id": 31,
+ "options": {
+ "colorMode": "value",
+ "graphMode": "none",
+ "justifyMode": "auto",
+ "orientation": "horizontal",
+ "reduceOptions": {
+ "calcs": [
+ "last"
+ ],
+ "fields": "",
+ "values": false
+ },
+ "text": {},
+ "textMode": "value"
+ },
+ "pluginVersion": "7.5.10",
+ "targets": [
+ {
+ "formatType": "Time series",
+ "queryType": "SQL",
+ "refId": "A",
+ "sql": "show dnodes",
+ "target": "select metric",
+ "type": "timeserie"
+ }
+ ],
+ "timeFrom": null,
+ "timeShift": null,
+ "title": "Offline Dnodes",
+ "transformations": [
+ {
+ "id": "filterByValue",
+ "options": {
+ "filters": [
+ {
+ "config": {
+ "id": "regex",
+ "options": {
+ "value": "ready"
+ }
+ },
+ "fieldName": "status"
+ }
+ ],
+ "match": "all",
+ "type": "exclude"
+ }
+ },
+ {
+ "id": "reduce",
+ "options": {
+ "includeTimeField": false,
+ "mode": "reduceFields",
+ "reducers": [
+ "count"
+ ]
+ }
+ },
+ {
+ "id": "filterFieldsByName",
+ "options": {
+ "include": {
+ "names": [
+ "id"
+ ]
+ }
+ }
+ }
+ ],
+ "type": "stat"
+ },
+ {
+ "datasource": "${ds}",
+ "fieldConfig": {
+ "defaults": {
+ "color": {
+ "mode": "thresholds"
+ },
+ "mappings": [],
+ "thresholds": {
+ "mode": "absolute",
+ "steps": [
+ {
+ "color": "green",
+ "value": null
+ },
+ {
+ "color": "red",
+ "value": 80
+ }
+ ]
+ }
+ },
+ "overrides": []
+ },
+ "gridPos": {
+ "h": 3,
+ "w": 3,
+ "x": 9,
+ "y": 7
+ },
+ "id": 65,
+ "options": {
+ "colorMode": "value",
+ "graphMode": "area",
+ "justifyMode": "auto",
+ "orientation": "auto",
+ "reduceOptions": {
+ "calcs": [
+ "lastNotNull"
+ ],
+ "fields": "",
+ "values": true
+ },
+ "text": {},
+ "textMode": "auto"
+ },
+ "pluginVersion": "7.5.10",
+ "repeatDirection": "h",
+ "targets": [
+ {
+ "alias": "dnodes",
+ "formatType": "Time series",
+ "queryType": "SQL",
+ "refId": "A",
+ "sql": "show databases;",
+ "target": "select metric",
+ "timeshift": {
+ "period": null
+ },
+ "type": "timeserie"
+ }
+ ],
+ "timeFrom": null,
+ "timeShift": null,
+ "title": "Number of Databases",
+ "transformations": [
+ {
+ "id": "reduce",
+ "options": {
+ "includeTimeField": false,
+ "mode": "reduceFields",
+ "reducers": [
+ "count"
+ ]
+ }
+ },
+ {
+ "id": "filterFieldsByName",
+ "options": {
+ "include": {
+ "names": [
+ "name"
+ ]
+ }
+ }
+ }
+ ],
+ "type": "stat"
+ },
+ {
+ "datasource": "${ds}",
+ "fieldConfig": {
+ "defaults": {
+ "color": {
+ "mode": "thresholds"
+ },
+ "mappings": [],
+ "thresholds": {
+ "mode": "absolute",
+ "steps": [
+ {
+ "color": "green",
+ "value": null
+ },
+ {
+ "color": "red",
+ "value": 80
+ }
+ ]
+ }
+ },
+ "overrides": []
+ },
+ "gridPos": {
+ "h": 3,
+ "w": 3,
+ "x": 12,
+ "y": 7
+ },
+ "id": 69,
+ "options": {
+ "colorMode": "value",
+ "graphMode": "area",
+ "justifyMode": "auto",
+ "orientation": "auto",
+ "reduceOptions": {
+ "calcs": [
+ "lastNotNull"
+ ],
+ "fields": "",
+ "values": true
+ },
+ "text": {},
+ "textMode": "auto"
+ },
+ "pluginVersion": "7.5.10",
+ "repeatDirection": "h",
+ "targets": [
+ {
+ "alias": "dnodes",
+ "formatType": "Time series",
+ "queryType": "SQL",
+ "refId": "A",
+ "sql": "show databases;",
+ "target": "select metric",
+ "timeshift": {
+ "period": null
+ },
+ "type": "timeserie"
+ }
+ ],
+ "timeFrom": null,
+ "timeShift": null,
+ "title": "Total Number of Vgroups",
+ "transformations": [
+ {
+ "id": "filterFieldsByName",
+ "options": {
+ "include": {
+ "names": [
+ "vgroups"
+ ]
+ }
+ }
+ },
+ {
+ "id": "reduce",
+ "options": {
+ "includeTimeField": false,
+ "mode": "reduceFields",
+ "reducers": [
+ "sum"
+ ]
+ }
+ }
+ ],
+ "type": "stat"
+ },
+ {
+ "datasource": "${ds}",
+ "fieldConfig": {
+ "defaults": {
+ "color": {
+ "mode": "thresholds"
+ },
+ "custom": {
+ "align": "center",
+ "displayMode": "auto",
+ "filterable": true
+ },
+ "mappings": [],
+ "thresholds": {
+ "mode": "absolute",
+ "steps": [
+ {
+ "color": "green",
+ "value": null
+ }
+ ]
+ }
+ },
+ "overrides": [
+ {
+ "matcher": {
+ "id": "byName",
+ "options": "role"
+ },
+ "properties": [
+ {
+ "id": "mappings",
+ "value": [
+ {
+ "from": "",
+ "id": 1,
+ "text": "",
+ "to": "",
+ "type": 2,
+ "value": ""
+ }
+ ]
+ }
+ ]
+ }
+ ]
+ },
+ "gridPos": {
+ "h": 3,
+ "w": 9,
+ "x": 0,
+ "y": 10
+ },
+ "id": 67,
+ "options": {
+ "showHeader": true
+ },
+ "pluginVersion": "7.5.10",
+ "targets": [
+ {
+ "formatType": "Table",
+ "queryType": "SQL",
+ "refId": "A",
+ "sql": "show dnodes",
+ "target": "select metric",
+ "type": "timeserie"
+ }
+ ],
+ "timeFrom": null,
+ "timeShift": null,
+ "title": "Number of DNodes for each Role",
+ "transformations": [
+ {
+ "id": "groupBy",
+ "options": {
+ "fields": {
+ "end_point": {
+ "aggregations": [
+ "count"
+ ],
+ "operation": "aggregate"
+ },
+ "role": {
+ "aggregations": [],
+ "operation": "groupby"
+ }
+ }
+ }
+ },
+ {
+ "id": "filterFieldsByName",
+ "options": {}
+ },
+ {
+ "id": "organize",
+ "options": {
+ "excludeByName": {},
+ "indexByName": {},
+ "renameByName": {
+ "end_point (count)": "Number of DNodes",
+ "role": "Dnode Role"
+ }
+ }
+ }
+ ],
+ "type": "table"
+ },
+ {
+ "datasource": "${ds}",
+ "fieldConfig": {
+ "defaults": {
+ "color": {
+ "mode": "thresholds"
+ },
+ "mappings": [],
+ "thresholds": {
+ "mode": "absolute",
+ "steps": [
+ {
+ "color": "green",
+ "value": null
+ },
+ {
+ "color": "red",
+ "value": 80
+ }
+ ]
+ }
+ },
+ "overrides": []
+ },
+ "gridPos": {
+ "h": 3,
+ "w": 3,
+ "x": 9,
+ "y": 10
+ },
+ "id": 55,
+ "options": {
+ "colorMode": "value",
+ "graphMode": "area",
+ "justifyMode": "auto",
+ "orientation": "auto",
+ "reduceOptions": {
+ "calcs": [
+ "lastNotNull"
+ ],
+ "fields": "",
+ "values": true
+ },
+ "text": {},
+ "textMode": "auto"
+ },
+ "pluginVersion": "7.5.10",
+ "repeatDirection": "h",
+ "targets": [
+ {
+ "alias": "dnodes",
+ "formatType": "Time series",
+ "queryType": "SQL",
+ "refId": "A",
+ "sql": "show connections",
+ "target": "select metric",
+ "timeshift": {
+ "period": null
+ },
+ "type": "timeserie"
+ }
+ ],
+ "timeFrom": null,
+ "timeShift": null,
+ "title": "Number of Connections",
+ "transformations": [
+ {
+ "id": "reduce",
+ "options": {
+ "includeTimeField": false,
+ "mode": "reduceFields",
+ "reducers": [
+ "count"
+ ]
+ }
+ },
+ {
+ "id": "filterFieldsByName",
+ "options": {
+ "include": {
+ "names": [
+ "connId"
+ ]
+ }
+ }
+ }
+ ],
+ "type": "stat"
+ },
+ {
+ "datasource": "${ds}",
+ "fieldConfig": {
+ "defaults": {
+ "color": {
+ "mode": "thresholds"
+ },
+ "mappings": [],
+ "thresholds": {
+ "mode": "absolute",
+ "steps": [
+ {
+ "color": "green",
+ "value": null
+ }
+ ]
+ }
+ },
+ "overrides": []
+ },
+ "gridPos": {
+ "h": 3,
+ "w": 3,
+ "x": 12,
+ "y": 10
+ },
+ "id": 68,
+ "options": {
+ "colorMode": "value",
+ "graphMode": "area",
+ "justifyMode": "auto",
+ "orientation": "auto",
+ "reduceOptions": {
+ "calcs": [
+ "lastNotNull"
+ ],
+ "fields": "",
+ "values": true
+ },
+ "text": {},
+ "textMode": "auto"
+ },
+ "pluginVersion": "7.5.10",
+ "repeatDirection": "h",
+ "targets": [
+ {
+ "alias": "dnodes",
+ "formatType": "Time series",
+ "queryType": "SQL",
+ "refId": "A",
+ "sql": "show databases;",
+ "target": "select metric",
+ "timeshift": {
+ "period": null
+ },
+ "type": "timeserie"
+ }
+ ],
+ "timeFrom": null,
+ "timeShift": null,
+ "title": "Total Number of Tables",
+ "transformations": [
+ {
+ "id": "filterFieldsByName",
+ "options": {
+ "include": {
+ "names": [
+ "ntables"
+ ]
+ }
+ }
+ },
+ {
+ "id": "reduce",
+ "options": {
+ "includeTimeField": false,
+ "mode": "reduceFields",
+ "reducers": [
+ "sum"
+ ]
+ }
+ }
+ ],
+ "type": "stat"
+ },
+ {
+ "collapsed": false,
+ "datasource": null,
+ "gridPos": {
+ "h": 1,
+ "w": 24,
+ "x": 0,
+ "y": 13
+ },
+ "id": 24,
+ "panels": [],
+ "title": "Dnodes Status",
+ "type": "row"
+ },
+ {
+ "datasource": "${ds}",
+ "fieldConfig": {
+ "defaults": {
+ "color": {
+ "mode": "thresholds"
+ },
+ "custom": {
+ "align": "center",
+ "displayMode": "auto",
+ "filterable": true
+ },
+ "mappings": [],
+ "thresholds": {
+ "mode": "absolute",
+ "steps": [
+ {
+ "color": "green",
+ "value": null
+ },
+ {
+ "color": "red",
+ "value": 80
+ }
+ ]
+ }
+ },
+ "overrides": [
+ {
+ "matcher": {
+ "id": "byName",
+ "options": "status"
+ },
+ "properties": [
+ {
+ "id": "custom.width",
+ "value": null
+ }
+ ]
+ },
+ {
+ "matcher": {
+ "id": "byName",
+ "options": "vnodes"
+ },
+ "properties": [
+ {
+ "id": "custom.width",
+ "value": null
+ }
+ ]
+ }
+ ]
+ },
+ "gridPos": {
+ "h": 5,
+ "w": 16,
+ "x": 0,
+ "y": 14
+ },
+ "id": 36,
+ "options": {
+ "showHeader": true,
+ "sortBy": []
+ },
+ "pluginVersion": "7.5.10",
+ "targets": [
+ {
+ "formatType": "Table",
+ "queryType": "SQL",
+ "refId": "A",
+ "sql": "show dnodes",
+ "target": "select metric",
+ "type": "timeserie"
+ }
+ ],
+ "timeFrom": null,
+ "timeShift": null,
+ "title": "DNodes Status",
+ "type": "table"
+ },
+ {
+ "datasource": "${ds}",
+ "fieldConfig": {
+ "defaults": {
+ "color": {
+ "mode": "palette-classic"
+ },
+ "mappings": [],
+ "thresholds": {
+ "mode": "absolute",
+ "steps": [
+ {
+ "color": "green",
+ "value": null
+ },
+ {
+ "color": "red",
+ "value": 80
+ }
+ ]
+ }
+ },
+ "overrides": []
+ },
+ "gridPos": {
+ "h": 5,
+ "w": 8,
+ "x": 16,
+ "y": 14
+ },
+ "id": 40,
+ "options": {
+ "displayLabels": [],
+ "legend": {
+ "displayMode": "table",
+ "placement": "right",
+ "values": [
+ "value"
+ ]
+ },
+ "pieType": "pie",
+ "reduceOptions": {
+ "calcs": [
+ "lastNotNull"
+ ],
+ "fields": "/.*/",
+ "values": false
+ },
+ "text": {
+ "titleSize": 6
+ }
+ },
+ "pluginVersion": "7.5.10",
+ "targets": [
+ {
+ "formatType": "Table",
+ "queryType": "SQL",
+ "refId": "A",
+ "sql": "show dnodes",
+ "target": "select metric",
+ "type": "timeserie"
+ }
+ ],
+ "title": "Offline Reasons",
+ "transformations": [
+ {
+ "id": "filterByValue",
+ "options": {
+ "filters": [
+ {
+ "config": {
+ "id": "regex",
+ "options": {
+ "value": "ready"
+ }
+ },
+ "fieldName": "status"
+ }
+ ],
+ "match": "all",
+ "type": "exclude"
+ }
+ },
+ {
+ "id": "filterFieldsByName",
+ "options": {
+ "include": {
+ "names": [
+ "offline reason",
+ "end_point"
+ ]
+ }
+ }
+ },
+ {
+ "id": "groupBy",
+ "options": {
+ "fields": {
+ "Time": {
+ "aggregations": [
+ "count"
+ ],
+ "operation": "aggregate"
+ },
+ "end_point": {
+ "aggregations": [
+ "count"
+ ],
+ "operation": "aggregate"
+ },
+ "offline reason": {
+ "aggregations": [],
+ "operation": "groupby"
+ }
+ }
+ }
+ }
+ ],
+ "type": "piechart"
+ },
+ {
+ "collapsed": false,
+ "datasource": null,
+ "gridPos": {
+ "h": 1,
+ "w": 24,
+ "x": 0,
+ "y": 19
+ },
+ "id": 22,
+ "panels": [],
+ "title": "Mnodes Status",
+ "type": "row"
+ },
+ {
+ "datasource": "${ds}",
+ "fieldConfig": {
+ "defaults": {
+ "color": {
+ "mode": "thresholds"
+ },
+ "custom": {
+ "align": "center",
+ "filterable": false
+ },
+ "mappings": [],
+ "thresholds": {
+ "mode": "absolute",
+ "steps": [
+ {
+ "color": "green",
+ "value": null
+ },
+ {
+ "color": "red",
+ "value": 80
+ }
+ ]
+ }
+ },
+ "overrides": []
+ },
+ "gridPos": {
+ "h": 5,
+ "w": 24,
+ "x": 0,
+ "y": 20
+ },
+ "id": 38,
+ "options": {
+ "showHeader": true
+ },
+ "pluginVersion": "7.5.10",
+ "targets": [
+ {
+ "formatType": "Table",
+ "queryType": "SQL",
+ "refId": "A",
+ "sql": "show mnodes;",
+ "target": "select metric",
+ "type": "timeserie"
+ }
+ ],
+ "title": "Mnodes Status",
+ "type": "table"
+ },
+ {
+ "collapsed": false,
+ "datasource": null,
+ "gridPos": {
+ "h": 1,
+ "w": 24,
+ "x": 0,
+ "y": 25
+ },
+ "id": 20,
+ "panels": [],
+ "repeat": "fqdn",
+ "scopedVars": {
+ "fqdn": {
+ "selected": true,
+ "text": "huolinhe-TM1701:6030",
+ "value": "huolinhe-TM1701:6030"
+ }
+ },
+ "title": "节点资源占用 [ $fqdn ]",
+ "type": "row"
+ },
+ {
+ "datasource": "${ds}",
+ "description": "",
+ "fieldConfig": {
+ "defaults": {
+ "color": {
+ "mode": "continuous-GrYlRd"
+ },
+ "mappings": [],
+ "min": 0,
+ "thresholds": {
+ "mode": "absolute",
+ "steps": [
+ {
+ "color": "green",
+ "value": null
+ }
+ ]
+ },
+ "unit": "decmbytes"
+ },
+ "overrides": []
+ },
+ "gridPos": {
+ "h": 6,
+ "w": 5,
+ "x": 0,
+ "y": 26
+ },
+ "id": 66,
+ "options": {
+ "orientation": "auto",
+ "reduceOptions": {
+ "calcs": [
+ "mean"
+ ],
+ "fields": "/^taosd$/",
+ "values": false
+ },
+ "showThresholdLabels": true,
+ "showThresholdMarkers": true,
+ "text": {}
+ },
+ "pluginVersion": "7.5.10",
+ "scopedVars": {
+ "fqdn": {
+ "selected": true,
+ "text": "huolinhe-TM1701:6030",
+ "value": "huolinhe-TM1701:6030"
+ }
+ },
+ "targets": [
+ {
+ "alias": "memory",
+ "formatType": "Time series",
+ "queryType": "SQL",
+ "refId": "A",
+ "sql": "select last(mem_taosd) as taosd, last(mem_total) as total from log.dn where fqdn = '$fqdn' and ts >= now -5m and ts < now",
+ "target": "select metric",
+ "type": "timeserie"
+ }
+ ],
+ "timeFrom": null,
+ "timeShift": null,
+ "title": "Current Memory Usage of taosd",
+ "type": "gauge"
+ },
+ {
+ "datasource": "${ds}",
+ "description": "taosd max memery last 10 minutes",
+ "fieldConfig": {
+ "defaults": {
+ "color": {
+ "mode": "continuous-GrYlRd"
+ },
+ "mappings": [],
+ "min": 0,
+ "thresholds": {
+ "mode": "absolute",
+ "steps": [
+ {
+ "color": "green",
+ "value": null
+ },
+ {
+ "color": "#EAB839",
+ "value": 0.5
+ },
+ {
+ "color": "red",
+ "value": 0.8
+ }
+ ]
+ },
+ "unit": "percentunit"
+ },
+ "overrides": [
+ {
+ "matcher": {
+ "id": "byName",
+ "options": "last(cpu_taosd)"
+ },
+ "properties": [
+ {
+ "id": "thresholds",
+ "value": {
+ "mode": "absolute",
+ "steps": [
+ {
+ "color": "green",
+ "value": null
+ },
+ {
+ "color": "red",
+ "value": 80
+ }
+ ]
+ }
+ }
+ ]
+ }
+ ]
+ },
+ "gridPos": {
+ "h": 6,
+ "w": 5,
+ "x": 5,
+ "y": 26
+ },
+ "id": 45,
+ "options": {
+ "orientation": "auto",
+ "reduceOptions": {
+ "calcs": [
+ "mean"
+ ],
+ "fields": "/^last\\(cpu_taosd\\)$/",
+ "values": false
+ },
+ "showThresholdLabels": true,
+ "showThresholdMarkers": true,
+ "text": {}
+ },
+ "pluginVersion": "7.5.10",
+ "scopedVars": {
+ "fqdn": {
+ "selected": true,
+ "text": "huolinhe-TM1701:6030",
+ "value": "huolinhe-TM1701:6030"
+ }
+ },
+ "targets": [
+ {
+ "alias": "mem_taosd",
+ "formatType": "Time series",
+ "queryType": "SQL",
+ "refId": "A",
+ "sql": "select last(cpu_taosd) from log.dn where fqdn = '$fqdn'",
+ "target": "select metric",
+ "type": "timeserie"
+ }
+ ],
+ "timeFrom": null,
+ "timeShift": null,
+ "title": "Current CPU Usage of taosd",
+ "type": "gauge"
+ },
+ {
+ "datasource": "${ds}",
+ "description": "avg band speed last one minute",
+ "fieldConfig": {
+ "defaults": {
+ "color": {
+ "mode": "thresholds"
+ },
+ "mappings": [],
+ "max": 8192,
+ "min": 0,
+ "thresholds": {
+ "mode": "absolute",
+ "steps": [
+ {
+ "color": "green",
+ "value": null
+ },
+ {
+ "color": "#EAB839",
+ "value": 4916
+ },
+ {
+ "color": "red",
+ "value": 6554
+ }
+ ]
+ },
+ "unit": "Kbits"
+ },
+ "overrides": []
+ },
+ "gridPos": {
+ "h": 6,
+ "w": 4,
+ "x": 10,
+ "y": 26
+ },
+ "id": 14,
+ "options": {
+ "orientation": "auto",
+ "reduceOptions": {
+ "calcs": [
+ "last"
+ ],
+ "fields": "",
+ "values": false
+ },
+ "showThresholdLabels": false,
+ "showThresholdMarkers": true,
+ "text": {}
+ },
+ "pluginVersion": "7.5.10",
+ "scopedVars": {
+ "fqdn": {
+ "selected": true,
+ "text": "huolinhe-TM1701:6030",
+ "value": "huolinhe-TM1701:6030"
+ }
+ },
+ "targets": [
+ {
+ "alias": "band_speed",
+ "formatType": "Time series",
+ "queryType": "SQL",
+ "refId": "A",
+ "sql": "select avg(band_speed) from log.dn where fqdn='$fqdn' and ts >= now-5m and ts < now interval(1m)",
+ "target": "select metric",
+ "type": "timeserie"
+ }
+ ],
+ "timeFrom": null,
+ "timeShift": null,
+ "title": "band speed",
+ "type": "gauge"
+ },
+ {
+ "datasource": "${ds}",
+ "description": "io read/write rate",
+ "fieldConfig": {
+ "defaults": {
+ "color": {
+ "mode": "thresholds"
+ },
+ "mappings": [],
+ "max": 8192,
+ "min": 0,
+ "thresholds": {
+ "mode": "absolute",
+ "steps": [
+ {
+ "color": "green",
+ "value": null
+ },
+ {
+ "color": "#EAB839",
+ "value": 4916
+ },
+ {
+ "color": "red",
+ "value": 6554
+ }
+ ]
+ },
+ "unit": "Kbits"
+ },
+ "overrides": []
+ },
+ "gridPos": {
+ "h": 6,
+ "w": 5,
+ "x": 14,
+ "y": 26
+ },
+ "id": 48,
+ "options": {
+ "orientation": "auto",
+ "reduceOptions": {
+ "calcs": [
+ "last"
+ ],
+ "fields": "",
+ "values": false
+ },
+ "showThresholdLabels": false,
+ "showThresholdMarkers": true,
+ "text": {}
+ },
+ "pluginVersion": "7.5.10",
+ "scopedVars": {
+ "fqdn": {
+ "selected": true,
+ "text": "huolinhe-TM1701:6030",
+ "value": "huolinhe-TM1701:6030"
+ }
+ },
+ "targets": [
+ {
+ "alias": "",
+ "formatType": "Time series",
+ "queryType": "SQL",
+ "refId": "A",
+ "sql": "select last(io_read) as io_read, last(io_write) as io_write from log.dn where fqdn='$fqdn' and ts >= now-1h and ts < now interval(1m)",
+ "target": "select metric",
+ "type": "timeserie"
+ }
+ ],
+ "timeFrom": null,
+ "timeShift": null,
+ "title": "IO Rate",
+ "type": "gauge"
+ },
+ {
+ "datasource": "${ds}",
+ "description": "",
+ "fieldConfig": {
+ "defaults": {
+ "color": {
+ "mode": "thresholds"
+ },
+ "mappings": [],
+ "max": 1,
+ "min": 0,
+ "thresholds": {
+ "mode": "percentage",
+ "steps": [
+ {
+ "color": "green",
+ "value": null
+ },
+ {
+ "color": "#EAB839",
+ "value": 75
+ },
+ {
+ "color": "red",
+ "value": 80
+ },
+ {
+ "color": "dark-red",
+ "value": 95
+ }
+ ]
+ },
+ "unit": "percentunit"
+ },
+ "overrides": []
+ },
+ "gridPos": {
+ "h": 6,
+ "w": 5,
+ "x": 19,
+ "y": 26
+ },
+ "id": 51,
+ "options": {
+ "orientation": "auto",
+ "reduceOptions": {
+ "calcs": [
+ "last"
+ ],
+ "fields": "/^disk_used_percent$/",
+ "values": false
+ },
+ "showThresholdLabels": true,
+ "showThresholdMarkers": true,
+ "text": {}
+ },
+ "pluginVersion": "7.5.10",
+ "scopedVars": {
+ "fqdn": {
+ "selected": true,
+ "text": "huolinhe-TM1701:6030",
+ "value": "huolinhe-TM1701:6030"
+ }
+ },
+ "targets": [
+ {
+ "alias": "disk_used",
+ "formatType": "Time series",
+ "queryType": "SQL",
+ "refId": "A",
+ "sql": "select last(disk_used) as used from log.dn where fqdn = '$fqdn' and ts >= $from and ts < $to interval(1m)",
+ "target": "select metric",
+ "timeshift": {
+ "period": null
+ },
+ "type": "timeserie"
+ },
+ {
+ "alias": "disk_total",
+ "formatType": "Time series",
+ "hide": false,
+ "queryType": "SQL",
+ "refId": "B",
+ "sql": "select last(disk_total) as total from log.dn where fqdn = '$fqdn' and ts >= $from and ts < $to interval(1m)",
+ "target": "select metric",
+ "type": "timeserie"
+ },
+ {
+ "alias": "disk_used_percent",
+ "expression": "A/B",
+ "formatType": "Time series",
+ "hide": false,
+ "queryType": "Arithmetic",
+ "refId": "C",
+ "target": "select metric",
+ "type": "timeserie"
+ }
+ ],
+ "timeFrom": null,
+ "timeShift": null,
+ "title": "Disk Used",
+ "transformations": [
+ {
+ "id": "reduce",
+ "options": {
+ "includeTimeField": false,
+ "mode": "reduceFields",
+ "reducers": [
+ "lastNotNull"
+ ]
+ }
+ }
+ ],
+ "type": "gauge"
+ },
+ {
+ "datasource": "${ds}",
+ "description": "taosd max memery last 10 minutes",
+ "fieldConfig": {
+ "defaults": {
+ "color": {
+ "mode": "continuous-GrYlRd"
+ },
+ "mappings": [],
+ "min": 0,
+ "thresholds": {
+ "mode": "absolute",
+ "steps": [
+ {
+ "color": "green",
+ "value": null
+ }
+ ]
+ },
+ "unit": "decmbytes"
+ },
+ "overrides": []
+ },
+ "gridPos": {
+ "h": 6,
+ "w": 5,
+ "x": 0,
+ "y": 32
+ },
+ "id": 12,
+ "options": {
+ "orientation": "auto",
+ "reduceOptions": {
+ "calcs": [
+ "mean"
+ ],
+ "fields": "/^taosd$/",
+ "values": false
+ },
+ "showThresholdLabels": true,
+ "showThresholdMarkers": true,
+ "text": {}
+ },
+ "pluginVersion": "7.5.10",
+ "scopedVars": {
+ "fqdn": {
+ "selected": true,
+ "text": "huolinhe-TM1701:6030",
+ "value": "huolinhe-TM1701:6030"
+ }
+ },
+ "targets": [
+ {
+ "alias": "memory",
+ "formatType": "Time series",
+ "queryType": "SQL",
+ "refId": "A",
+ "sql": "select max(mem_taosd) as taosd, max(mem_total) as total from log.dn where fqdn = '$fqdn' and ts >= now -5m and ts < now",
+ "target": "select metric",
+ "type": "timeserie"
+ }
+ ],
+ "timeFrom": null,
+ "timeShift": null,
+ "title": "Max Memory Usage of taosd in Last 5 minute",
+ "type": "gauge"
+ },
+ {
+ "datasource": "${ds}",
+ "description": "taosd max memery last 10 minutes",
+ "fieldConfig": {
+ "defaults": {
+ "color": {
+ "mode": "continuous-GrYlRd"
+ },
+ "mappings": [],
+ "max": 1,
+ "min": 0,
+ "thresholds": {
+ "mode": "absolute",
+ "steps": [
+ {
+ "color": "green",
+ "value": null
+ },
+ {
+ "color": "#EAB839",
+ "value": 0.5
+ },
+ {
+ "color": "red",
+ "value": 0.8
+ }
+ ]
+ },
+ "unit": "percentunit"
+ },
+ "overrides": []
+ },
+ "gridPos": {
+ "h": 6,
+ "w": 5,
+ "x": 5,
+ "y": 32
+ },
+ "id": 43,
+ "options": {
+ "orientation": "auto",
+ "reduceOptions": {
+ "calcs": [
+ "mean"
+ ],
+ "fields": "",
+ "values": false
+ },
+ "showThresholdLabels": true,
+ "showThresholdMarkers": true,
+ "text": {}
+ },
+ "pluginVersion": "7.5.10",
+ "scopedVars": {
+ "fqdn": {
+ "selected": true,
+ "text": "huolinhe-TM1701:6030",
+ "value": "huolinhe-TM1701:6030"
+ }
+ },
+ "targets": [
+ {
+ "alias": "mem_taosd",
+ "formatType": "Time series",
+ "queryType": "SQL",
+ "refId": "A",
+ "sql": "select max(cpu_taosd) from log.dn where fqdn = '$fqdn' and ts >= now -5m and ts < now",
+ "target": "select metric",
+ "type": "timeserie"
+ }
+ ],
+ "timeFrom": null,
+ "timeShift": null,
+ "title": "Max CPU Usage of taosd in Last 5 minute",
+ "type": "gauge"
+ },
+ {
+ "datasource": "${ds}",
+ "description": "avg band speed last one minute",
+ "fieldConfig": {
+ "defaults": {
+ "color": {
+ "mode": "thresholds"
+ },
+ "mappings": [],
+ "max": 8192,
+ "min": 0,
+ "thresholds": {
+ "mode": "absolute",
+ "steps": [
+ {
+ "color": "green",
+ "value": null
+ },
+ {
+ "color": "#EAB839",
+ "value": 4916
+ },
+ {
+ "color": "red",
+ "value": 6554
+ }
+ ]
+ },
+ "unit": "Kbits"
+ },
+ "overrides": []
+ },
+ "gridPos": {
+ "h": 6,
+ "w": 4,
+ "x": 10,
+ "y": 32
+ },
+ "id": 50,
+ "options": {
+ "orientation": "auto",
+ "reduceOptions": {
+ "calcs": [
+ "last"
+ ],
+ "fields": "",
+ "values": false
+ },
+ "showThresholdLabels": false,
+ "showThresholdMarkers": true,
+ "text": {}
+ },
+ "pluginVersion": "7.5.10",
+ "scopedVars": {
+ "fqdn": {
+ "selected": true,
+ "text": "huolinhe-TM1701:6030",
+ "value": "huolinhe-TM1701:6030"
+ }
+ },
+ "targets": [
+ {
+ "alias": "band_speed",
+ "formatType": "Time series",
+ "queryType": "SQL",
+ "refId": "A",
+ "sql": "select max(band_speed) from log.dn where fqdn = '$fqdn' and ts >= now-1h",
+ "target": "select metric",
+ "type": "timeserie"
+ }
+ ],
+ "timeFrom": null,
+ "timeShift": null,
+ "title": "Max band speed in last hour",
+ "type": "gauge"
+ },
+ {
+ "datasource": "${ds}",
+ "description": "io read/write rate",
+ "fieldConfig": {
+ "defaults": {
+ "color": {
+ "mode": "thresholds"
+ },
+ "mappings": [],
+ "max": 8192,
+ "min": 0,
+ "thresholds": {
+ "mode": "absolute",
+ "steps": [
+ {
+ "color": "green",
+ "value": null
+ },
+ {
+ "color": "#EAB839",
+ "value": 4916
+ },
+ {
+ "color": "red",
+ "value": 6554
+ }
+ ]
+ },
+ "unit": "Kbits"
+ },
+ "overrides": []
+ },
+ "gridPos": {
+ "h": 6,
+ "w": 5,
+ "x": 14,
+ "y": 32
+ },
+ "id": 49,
+ "options": {
+ "orientation": "auto",
+ "reduceOptions": {
+ "calcs": [
+ "last"
+ ],
+ "fields": "",
+ "values": false
+ },
+ "showThresholdLabels": false,
+ "showThresholdMarkers": true,
+ "text": {}
+ },
+ "pluginVersion": "7.5.10",
+ "scopedVars": {
+ "fqdn": {
+ "selected": true,
+ "text": "huolinhe-TM1701:6030",
+ "value": "huolinhe-TM1701:6030"
+ }
+ },
+ "targets": [
+ {
+ "alias": "",
+ "formatType": "Time series",
+ "queryType": "SQL",
+ "refId": "A",
+ "sql": "select max(io_read) as io_read, max(io_write) as io_write from log.dn where fqdn = '$fqdn'",
+ "target": "select metric",
+ "type": "timeserie"
+ }
+ ],
+ "timeFrom": null,
+ "timeShift": null,
+ "title": "Max IO Rate in last hour",
+ "type": "gauge"
+ },
+ {
+ "datasource": "${ds}",
+ "description": "io read/write rate",
+ "fieldConfig": {
+ "defaults": {
+ "color": {
+ "mode": "thresholds"
+ },
+ "mappings": [],
+ "max": 8192,
+ "min": 0,
+ "thresholds": {
+ "mode": "absolute",
+ "steps": [
+ {
+ "color": "green",
+ "value": null
+ },
+ {
+ "color": "#EAB839",
+ "value": 4916
+ },
+ {
+ "color": "red",
+ "value": 6554
+ }
+ ]
+ },
+ "unit": "cpm"
+ },
+ "overrides": []
+ },
+ "gridPos": {
+ "h": 6,
+ "w": 5,
+ "x": 19,
+ "y": 32
+ },
+ "id": 52,
+ "options": {
+ "orientation": "auto",
+ "reduceOptions": {
+ "calcs": [
+ "last"
+ ],
+ "fields": "",
+ "values": false
+ },
+ "showThresholdLabels": false,
+ "showThresholdMarkers": true,
+ "text": {}
+ },
+ "pluginVersion": "7.5.10",
+ "scopedVars": {
+ "fqdn": {
+ "selected": true,
+ "text": "huolinhe-TM1701:6030",
+ "value": "huolinhe-TM1701:6030"
+ }
+ },
+ "targets": [
+ {
+ "alias": "req-http",
+ "formatType": "Time series",
+ "queryType": "SQL",
+ "refId": "A",
+ "sql": "select sum(req_http) as req_http from log.dn where fqdn = '$fqdn' and ts >= now - 1h interval(1m)",
+ "target": "select metric",
+ "type": "timeserie"
+ },
+ {
+ "alias": "req-inserts",
+ "formatType": "Time series",
+ "hide": false,
+ "queryType": "SQL",
+ "refId": "B",
+ "sql": "select sum(req_insert) as req_insert from log.dn where fqdn = '$fqdn' and ts >= now - 1h interval(1m)",
+ "target": "select metric",
+ "type": "timeserie"
+ },
+ {
+ "alias": "req-selects",
+ "formatType": "Time series",
+ "hide": false,
+ "queryType": "SQL",
+ "refId": "C",
+ "sql": "select sum(req_select) as req_select from log.dn where fqdn = '$fqdn' and ts >= now - 1h interval(1m)",
+ "target": "select metric",
+ "type": "timeserie"
+ }
+ ],
+ "timeFrom": null,
+ "timeShift": null,
+ "title": "Requests in last Minute",
+ "type": "gauge"
+ },
+ {
+ "aliasColors": {},
+ "bars": false,
+ "cacheTimeout": null,
+ "dashLength": 10,
+ "dashes": false,
+ "datasource": "${ds}",
+ "description": "monitor system cpu",
+ "fieldConfig": {
+ "defaults": {
+ "links": []
+ },
+ "overrides": []
+ },
+ "fill": 1,
+ "fillGradient": 0,
+ "gridPos": {
+ "h": 11,
+ "w": 12,
+ "x": 0,
+ "y": 38
+ },
+ "hiddenSeries": false,
+ "hideTimeOverride": true,
+ "id": 2,
+ "legend": {
+ "avg": false,
+ "current": false,
+ "max": false,
+ "min": false,
+ "show": true,
+ "total": false,
+ "values": false
+ },
+ "lines": true,
+ "linewidth": 1,
+ "links": [],
+ "nullPointMode": "null",
+ "options": {
+ "alertThreshold": true
+ },
+ "percentage": false,
+ "pluginVersion": "7.5.10",
+ "pointradius": 2,
+ "points": false,
+ "renderer": "flot",
+ "scopedVars": {
+ "fqdn": {
+ "selected": true,
+ "text": "huolinhe-TM1701:6030",
+ "value": "huolinhe-TM1701:6030"
+ }
+ },
+ "seriesOverrides": [],
+ "spaceLength": 10,
+ "stack": false,
+ "steppedLine": false,
+ "targets": [
+ {
+ "alias": "cpu_system",
+ "formatType": "Time series",
+ "hide": false,
+ "queryType": "SQL",
+ "refId": "A",
+ "sql": "select avg(cpu_system) from log.dn where fqdn='$fqdn' and ts >= now-1h and ts < now interval(30s)",
+ "target": "select metric",
+ "type": "timeserie"
+ },
+ {
+ "alias": "cpu_taosd",
+ "formatType": "Time series",
+ "hide": false,
+ "queryType": "SQL",
+ "refId": "B",
+ "sql": "select avg(cpu_taosd) from log.dn where fqdn='$fqdn' and ts >= now-1h and ts < now interval(30s)",
+ "target": "select metric",
+ "type": "timeserie"
+ }
+ ],
+ "thresholds": [],
+ "timeFrom": "1h",
+ "timeRegions": [],
+ "timeShift": "30s",
+ "title": "CPU 资源占用情况",
+ "tooltip": {
+ "shared": true,
+ "sort": 0,
+ "value_type": "individual"
+ },
+ "type": "graph",
+ "xaxis": {
+ "buckets": null,
+ "mode": "time",
+ "name": null,
+ "show": true,
+ "values": []
+ },
+ "yaxes": [
+ {
+ "$$hashKey": "object:58",
+ "decimals": null,
+ "format": "percent",
+ "label": "使用占比",
+ "logBase": 1,
+ "max": null,
+ "min": null,
+ "show": true
+ },
+ {
+ "$$hashKey": "object:59",
+ "format": "short",
+ "label": null,
+ "logBase": 1,
+ "max": null,
+ "min": null,
+ "show": false
+ }
+ ],
+ "yaxis": {
+ "align": false,
+ "alignLevel": null
+ }
+ },
+ {
+ "aliasColors": {},
+ "bars": false,
+ "cacheTimeout": null,
+ "dashLength": 10,
+ "dashes": false,
+ "datasource": "${ds}",
+ "description": "monitor system cpu",
+ "fieldConfig": {
+ "defaults": {
+ "links": []
+ },
+ "overrides": []
+ },
+ "fill": 1,
+ "fillGradient": 0,
+ "gridPos": {
+ "h": 11,
+ "w": 12,
+ "x": 12,
+ "y": 38
+ },
+ "hiddenSeries": false,
+ "hideTimeOverride": true,
+ "id": 42,
+ "legend": {
+ "avg": false,
+ "current": false,
+ "max": false,
+ "min": false,
+ "show": true,
+ "total": false,
+ "values": false
+ },
+ "lines": true,
+ "linewidth": 1,
+ "links": [],
+ "nullPointMode": "null",
+ "options": {
+ "alertThreshold": true
+ },
+ "percentage": false,
+ "pluginVersion": "7.5.10",
+ "pointradius": 2,
+ "points": false,
+ "renderer": "flot",
+ "scopedVars": {
+ "fqdn": {
+ "selected": true,
+ "text": "huolinhe-TM1701:6030",
+ "value": "huolinhe-TM1701:6030"
+ }
+ },
+ "seriesOverrides": [],
+ "spaceLength": 10,
+ "stack": false,
+ "steppedLine": false,
+ "targets": [
+ {
+ "alias": "system",
+ "formatType": "Time series",
+ "hide": false,
+ "queryType": "SQL",
+ "refId": "A",
+ "sql": "select avg(mem_system) from log.dn where fqdn = '$fqdn' and ts >= now-1h and ts < now interval(30s)",
+ "target": "select metric",
+ "type": "timeserie"
+ },
+ {
+ "alias": "taosd",
+ "formatType": "Time series",
+ "hide": false,
+ "queryType": "SQL",
+ "refId": "B",
+ "sql": "select avg(mem_taosd) from log.dn where fqdn = '$fqdn' and ts >= now-1h and ts < now interval(30s)",
+ "target": "select metric",
+ "type": "timeserie"
+ },
+ {
+ "alias": "total",
+ "formatType": "Time series",
+ "hide": false,
+ "queryType": "SQL",
+ "refId": "C",
+ "sql": "select avg(mem_total) from log.dn where fqdn = '$fqdn' and ts >= now-1h and ts < now interval(30s)",
+ "target": "select metric",
+ "type": "timeserie"
+ }
+ ],
+ "thresholds": [],
+ "timeFrom": "1h",
+ "timeRegions": [],
+ "timeShift": "30s",
+ "title": "内存资源占用情况",
+ "tooltip": {
+ "shared": true,
+ "sort": 0,
+ "value_type": "individual"
+ },
+ "type": "graph",
+ "xaxis": {
+ "buckets": null,
+ "mode": "time",
+ "name": null,
+ "show": true,
+ "values": []
+ },
+ "yaxes": [
+ {
+ "$$hashKey": "object:58",
+ "decimals": null,
+ "format": "decmbytes",
+ "label": "使用占比",
+ "logBase": 1,
+ "max": null,
+ "min": null,
+ "show": true
+ },
+ {
+ "$$hashKey": "object:59",
+ "format": "short",
+ "label": null,
+ "logBase": 1,
+ "max": null,
+ "min": null,
+ "show": false
+ }
+ ],
+ "yaxis": {
+ "align": false,
+ "alignLevel": null
+ }
+ },
+ {
+ "aliasColors": {},
+ "bars": false,
+ "dashLength": 10,
+ "dashes": false,
+ "datasource": "${ds}",
+ "fieldConfig": {
+ "defaults": {
+ "unit": "percent"
+ },
+ "overrides": []
+ },
+ "fill": 1,
+ "fillGradient": 0,
+ "gridPos": {
+ "h": 9,
+ "w": 12,
+ "x": 0,
+ "y": 49
+ },
+ "hiddenSeries": false,
+ "id": 54,
+ "legend": {
+ "alignAsTable": false,
+ "avg": false,
+ "current": true,
+ "max": false,
+ "min": false,
+ "rightSide": false,
+ "show": true,
+ "total": false,
+ "values": true
+ },
+ "lines": true,
+ "linewidth": 1,
+ "nullPointMode": "null",
+ "options": {
+ "alertThreshold": true
+ },
+ "percentage": false,
+ "pluginVersion": "7.5.10",
+ "pointradius": 2,
+ "points": false,
+ "renderer": "flot",
+ "scopedVars": {
+ "fqdn": {
+ "selected": true,
+ "text": "huolinhe-TM1701:6030",
+ "value": "huolinhe-TM1701:6030"
+ }
+ },
+ "seriesOverrides": [
+ {
+ "$$hashKey": "object:249",
+ "alias": "disk_used",
+ "hiddenSeries": true
+ },
+ {
+ "$$hashKey": "object:256",
+ "alias": "disk_total",
+ "hiddenSeries": true
+ }
+ ],
+ "spaceLength": 10,
+ "stack": false,
+ "steppedLine": false,
+ "targets": [
+ {
+ "alias": "disk_used",
+ "formatType": "Time series",
+ "hide": false,
+ "queryType": "SQL",
+ "refId": "A",
+ "sql": "select avg(disk_used) from log.dn where fqdn = '$fqdn' and ts >= $from and ts < $to interval(30s)",
+ "target": "select metric",
+ "timeshift": {
+ "period": null
+ },
+ "type": "timeserie"
+ },
+ {
+ "alias": "disk_total",
+ "formatType": "Time series",
+ "hide": false,
+ "queryType": "SQL",
+ "refId": "B",
+ "sql": "select avg(disk_total) from log.dn where fqdn = '$fqdn' and ts >= $from and ts < $to interval(30s)",
+ "target": "select metric",
+ "timeshift": {
+ "period": null
+ },
+ "type": "timeserie"
+ },
+ {
+ "alias": "percent",
+ "expression": "A/B * 100",
+ "formatType": "Time series",
+ "hide": false,
+ "queryType": "Arithmetic",
+ "refId": "C",
+ "target": "select metric",
+ "type": "timeserie"
+ }
+ ],
+ "thresholds": [],
+ "timeFrom": null,
+ "timeRegions": [],
+ "timeShift": null,
+ "title": "Disk Used Percent",
+ "tooltip": {
+ "shared": false,
+ "sort": 0,
+ "value_type": "individual"
+ },
+ "type": "graph",
+ "xaxis": {
+ "buckets": null,
+ "mode": "time",
+ "name": null,
+ "show": true,
+ "values": []
+ },
+ "yaxes": [
+ {
+ "$$hashKey": "object:456",
+ "format": "percent",
+ "label": null,
+ "logBase": 1,
+ "max": "100",
+ "min": "0",
+ "show": true
+ },
+ {
+ "$$hashKey": "object:457",
+ "format": "percentunit",
+ "label": "Disk Used",
+ "logBase": 1,
+ "max": null,
+ "min": null,
+ "show": false
+ }
+ ],
+ "yaxis": {
+ "align": false,
+ "alignLevel": null
+ }
+ },
+ {
+ "aliasColors": {},
+ "bars": false,
+ "dashLength": 10,
+ "dashes": false,
+ "datasource": "${ds}",
+ "fieldConfig": {
+ "defaults": {},
+ "overrides": []
+ },
+ "fill": 1,
+ "fillGradient": 0,
+ "gridPos": {
+ "h": 9,
+ "w": 12,
+ "x": 12,
+ "y": 49
+ },
+ "hiddenSeries": false,
+ "id": 64,
+ "legend": {
+ "alignAsTable": false,
+ "avg": false,
+ "current": true,
+ "max": false,
+ "min": false,
+ "rightSide": false,
+ "show": true,
+ "total": false,
+ "values": true
+ },
+ "lines": true,
+ "linewidth": 1,
+ "nullPointMode": "null",
+ "options": {
+ "alertThreshold": true
+ },
+ "percentage": false,
+ "pluginVersion": "7.5.10",
+ "pointradius": 2,
+ "points": false,
+ "renderer": "flot",
+ "scopedVars": {
+ "fqdn": {
+ "selected": true,
+ "text": "huolinhe-TM1701:6030",
+ "value": "huolinhe-TM1701:6030"
+ }
+ },
+ "seriesOverrides": [
+ {
+ "$$hashKey": "object:834",
+ "alias": "percent",
+ "yaxis": 2
+ }
+ ],
+ "spaceLength": 10,
+ "stack": false,
+ "steppedLine": false,
+ "targets": [
+ {
+ "alias": "disk_used",
+ "formatType": "Time series",
+ "hide": false,
+ "queryType": "SQL",
+ "refId": "A",
+ "sql": "select avg(disk_used) from log.dn where fqdn = '$fqdn' and ts >= $from and ts < $to interval(30s)",
+ "target": "select metric",
+ "timeshift": {
+ "period": null
+ },
+ "type": "timeserie"
+ },
+ {
+ "alias": "disk_total",
+ "formatType": "Time series",
+ "hide": false,
+ "queryType": "SQL",
+ "refId": "B",
+ "sql": "select avg(disk_total) from log.dn where fqdn = '$fqdn' and ts >= $from and ts < $to interval(30s)",
+ "target": "select metric",
+ "timeshift": {
+ "period": null
+ },
+ "type": "timeserie"
+ },
+ {
+ "alias": "percent",
+ "expression": "A/B",
+ "formatType": "Time series",
+ "hide": false,
+ "queryType": "Arithmetic",
+ "refId": "C",
+ "target": "select metric",
+ "type": "timeserie"
+ }
+ ],
+ "thresholds": [],
+ "timeFrom": null,
+ "timeRegions": [],
+ "timeShift": null,
+ "title": "Disk Used",
+ "tooltip": {
+ "shared": false,
+ "sort": 0,
+ "value_type": "individual"
+ },
+ "type": "graph",
+ "xaxis": {
+ "buckets": null,
+ "mode": "time",
+ "name": null,
+ "show": true,
+ "values": []
+ },
+ "yaxes": [
+ {
+ "$$hashKey": "object:456",
+ "format": "decgbytes",
+ "label": null,
+ "logBase": 1,
+ "max": null,
+ "min": null,
+ "show": true
+ },
+ {
+ "$$hashKey": "object:457",
+ "format": "percentunit",
+ "label": "Disk Used",
+ "logBase": 1,
+ "max": null,
+ "min": null,
+ "show": true
+ }
+ ],
+ "yaxis": {
+ "align": false,
+ "alignLevel": null
+ }
+ },
+ {
+ "aliasColors": {},
+ "bars": false,
+ "cacheTimeout": null,
+ "dashLength": 10,
+ "dashes": false,
+ "datasource": "${ds}",
+ "description": "total select request per minute last hour",
+ "fieldConfig": {
+ "defaults": {
+ "unit": "cpm"
+ },
+ "overrides": []
+ },
+ "fill": 1,
+ "fillGradient": 0,
+ "gridPos": {
+ "h": 9,
+ "w": 12,
+ "x": 0,
+ "y": 58
+ },
+ "hiddenSeries": false,
+ "id": 8,
+ "interval": null,
+ "legend": {
+ "avg": false,
+ "current": false,
+ "max": false,
+ "min": false,
+ "show": true,
+ "total": false,
+ "values": false
+ },
+ "lines": true,
+ "linewidth": 1,
+ "links": [],
+ "maxDataPoints": 100,
+ "nullPointMode": "null",
+ "options": {
+ "alertThreshold": true
+ },
+ "percentage": false,
+ "pluginVersion": "7.5.10",
+ "pointradius": 2,
+ "points": false,
+ "renderer": "flot",
+ "scopedVars": {
+ "fqdn": {
+ "selected": true,
+ "text": "huolinhe-TM1701:6030",
+ "value": "huolinhe-TM1701:6030"
+ }
+ },
+ "seriesOverrides": [],
+ "spaceLength": 10,
+ "stack": false,
+ "steppedLine": false,
+ "targets": [
+ {
+ "alias": "req_select",
+ "formatType": "Time series",
+ "queryType": "SQL",
+ "refId": "A",
+ "sql": "select sum(req_select) from log.dn where fqdn = '$fqdn' and ts >= $from and ts < $to interval(1m)",
+ "target": "select metric",
+ "timeshift": {
+ "period": null
+ },
+ "type": "timeserie"
+ },
+ {
+ "alias": "req_insert",
+ "formatType": "Time series",
+ "hide": false,
+ "queryType": "SQL",
+ "refId": "B",
+ "sql": "select sum(req_insert) from log.dn where fqdn = '$fqdn' and ts >= $from and ts < $to interval(1m)",
+ "target": "select metric",
+ "type": "timeserie"
+ },
+ {
+ "alias": "req_http",
+ "formatType": "Time series",
+ "hide": false,
+ "queryType": "SQL",
+ "refId": "C",
+ "sql": "select sum(req_http) from log.dn where fqdn = '$fqdn' and ts >= $from and ts < $to interval(1m)",
+ "target": "select metric",
+ "type": "timeserie"
+ }
+ ],
+ "thresholds": [],
+ "timeFrom": null,
+ "timeRegions": [],
+ "timeShift": null,
+ "title": "Requets Count per Minutes $fqdn",
+ "tooltip": {
+ "shared": true,
+ "sort": 0,
+ "value_type": "individual"
+ },
+ "type": "graph",
+ "xaxis": {
+ "buckets": null,
+ "mode": "time",
+ "name": null,
+ "show": true,
+ "values": []
+ },
+ "yaxes": [
+ {
+ "$$hashKey": "object:127",
+ "format": "cpm",
+ "label": null,
+ "logBase": 1,
+ "max": null,
+ "min": "0",
+ "show": true
+ },
+ {
+ "$$hashKey": "object:128",
+ "format": "short",
+ "label": null,
+ "logBase": 1,
+ "max": null,
+ "min": null,
+ "show": true
+ }
+ ],
+ "yaxis": {
+ "align": false,
+ "alignLevel": null
+ }
+ },
+ {
+ "aliasColors": {},
+ "bars": false,
+ "cacheTimeout": null,
+ "dashLength": 10,
+ "dashes": false,
+ "datasource": "${ds}",
+ "description": "io",
+ "fieldConfig": {
+ "defaults": {
+ "links": [],
+ "unit": "Kbits"
+ },
+ "overrides": []
+ },
+ "fill": 1,
+ "fillGradient": 0,
+ "gridPos": {
+ "h": 9,
+ "w": 12,
+ "x": 12,
+ "y": 58
+ },
+ "hiddenSeries": false,
+ "hideTimeOverride": true,
+ "id": 47,
+ "legend": {
+ "avg": false,
+ "current": false,
+ "max": false,
+ "min": false,
+ "show": true,
+ "total": false,
+ "values": false
+ },
+ "lines": true,
+ "linewidth": 1,
+ "links": [],
+ "nullPointMode": "null",
+ "options": {
+ "alertThreshold": true
+ },
+ "percentage": false,
+ "pluginVersion": "7.5.10",
+ "pointradius": 2,
+ "points": false,
+ "renderer": "flot",
+ "scopedVars": {
+ "fqdn": {
+ "selected": true,
+ "text": "huolinhe-TM1701:6030",
+ "value": "huolinhe-TM1701:6030"
+ }
+ },
+ "seriesOverrides": [],
+ "spaceLength": 10,
+ "stack": false,
+ "steppedLine": false,
+ "targets": [
+ {
+ "alias": "io-read",
+ "formatType": "Time series",
+ "hide": false,
+ "queryType": "SQL",
+ "refId": "A",
+ "sql": "select avg(io_read) from log.dn where fqdn = '$fqdn' and ts >= now-1h and ts < now interval(1m)",
+ "target": "select metric",
+ "type": "timeserie"
+ },
+ {
+ "alias": "io-write",
+ "formatType": "Time series",
+ "hide": false,
+ "queryType": "SQL",
+ "refId": "B",
+ "sql": "select avg(io_write) from log.dn where fqdn = '$fqdn' and ts >= now-1h and ts < now interval(1m)",
+ "target": "select metric",
+ "type": "timeserie"
+ },
+ {
+ "alias": "io-read-last-hour",
+ "formatType": "Time series",
+ "hide": false,
+ "queryType": "SQL",
+ "refId": "C",
+ "sql": "select avg(io_read) from log.dn where fqdn = '$fqdn' and ts >= now-2h and ts < now - 1h interval(1m)",
+ "target": "select metric",
+ "timeshift": {
+ "period": 1,
+ "unit": "hours"
+ },
+ "type": "timeserie"
+ },
+ {
+ "alias": "io-write-last-hour",
+ "formatType": "Time series",
+ "hide": false,
+ "queryType": "SQL",
+ "refId": "D",
+ "sql": "select avg(io_write) from log.dn where fqdn = '$fqdn' and ts >= now-1h and ts < now interval(1m)",
+ "target": "select metric",
+ "timeshift": {
+ "period": 1,
+ "unit": "hours"
+ },
+ "type": "timeserie"
+ }
+ ],
+ "thresholds": [],
+ "timeFrom": "1h",
+ "timeRegions": [],
+ "timeShift": "30s",
+ "title": "IO",
+ "tooltip": {
+ "shared": true,
+ "sort": 0,
+ "value_type": "individual"
+ },
+ "type": "graph",
+ "xaxis": {
+ "buckets": null,
+ "mode": "time",
+ "name": null,
+ "show": true,
+ "values": []
+ },
+ "yaxes": [
+ {
+ "$$hashKey": "object:58",
+ "decimals": null,
+ "format": "Kbits",
+ "label": "使用占比",
+ "logBase": 1,
+ "max": null,
+ "min": null,
+ "show": true
+ },
+ {
+ "$$hashKey": "object:59",
+ "format": "short",
+ "label": null,
+ "logBase": 1,
+ "max": null,
+ "min": null,
+ "show": false
+ }
+ ],
+ "yaxis": {
+ "align": false,
+ "alignLevel": null
+ }
+ },
+ {
+ "collapsed": false,
+ "datasource": null,
+ "gridPos": {
+ "h": 1,
+ "w": 24,
+ "x": 0,
+ "y": 67
+ },
+ "id": 63,
+ "panels": [],
+ "title": "Login History",
+ "type": "row"
+ },
+ {
+ "aliasColors": {},
+ "bars": false,
+ "dashLength": 10,
+ "dashes": false,
+ "datasource": "${ds}",
+ "fieldConfig": {
+ "defaults": {
+ "displayName": "Logins Per Minute",
+ "unit": "cpm"
+ },
+ "overrides": []
+ },
+ "fill": 1,
+ "fillGradient": 0,
+ "gridPos": {
+ "h": 8,
+ "w": 12,
+ "x": 0,
+ "y": 68
+ },
+ "hiddenSeries": false,
+ "id": 61,
+ "legend": {
+ "avg": false,
+ "current": false,
+ "max": false,
+ "min": false,
+ "show": true,
+ "total": false,
+ "values": false
+ },
+ "lines": true,
+ "linewidth": 1,
+ "nullPointMode": "null",
+ "options": {
+ "alertThreshold": true
+ },
+ "percentage": false,
+ "pluginVersion": "7.5.10",
+ "pointradius": 2,
+ "points": false,
+ "renderer": "flot",
+ "seriesOverrides": [
+ {
+ "$$hashKey": "object:756",
+ "alias": "logins",
+ "nullPointMode": "null as zero"
+ }
+ ],
+ "spaceLength": 10,
+ "stack": false,
+ "steppedLine": false,
+ "targets": [
+ {
+ "alias": "logins",
+ "formatType": "Time series",
+ "queryType": "SQL",
+ "refId": "A",
+ "sql": "select count(*) from log.log where ts >= $from and ts < $to interval (1m)",
+ "target": "select metric",
+ "type": "timeserie"
+ }
+ ],
+ "thresholds": [],
+ "timeFrom": null,
+ "timeRegions": [],
+ "timeShift": null,
+ "title": "Login Counts per Minute",
+ "tooltip": {
+ "shared": true,
+ "sort": 0,
+ "value_type": "individual"
+ },
+ "type": "graph",
+ "xaxis": {
+ "buckets": null,
+ "mode": "time",
+ "name": null,
+ "show": true,
+ "values": []
+ },
+ "yaxes": [
+ {
+ "$$hashKey": "object:585",
+ "format": "cpm",
+ "label": null,
+ "logBase": 1,
+ "max": null,
+ "min": null,
+ "show": true
+ },
+ {
+ "$$hashKey": "object:586",
+ "format": "short",
+ "label": null,
+ "logBase": 1,
+ "max": null,
+ "min": null,
+ "show": true
+ }
+ ],
+ "yaxis": {
+ "align": false,
+ "alignLevel": null
+ }
+ }
+ ],
+ "refresh": "1m",
+ "schemaVersion": 27,
+ "style": "dark",
+ "tags": [
+ "TDengine"
+ ],
+ "templating": {
+ "list": [
+ {
+ "current": {
+ "selected": true,
+ "text": "TDengine",
+ "value": "TDengine"
+ },
+ "description": "TDengine Data Source Selector",
+ "error": null,
+ "hide": 0,
+ "includeAll": false,
+ "label": "Datasource",
+ "multi": false,
+ "name": "ds",
+ "options": [],
+ "query": "tdengine-datasource",
+ "queryValue": "",
+ "refresh": 1,
+ "regex": "",
+ "skipUrlSync": false,
+ "type": "datasource"
+ },
+ {
+ "allValue": null,
+ "current": {
+ "selected": false,
+ "text": "huolinhe-TM1701:6030",
+ "value": "huolinhe-TM1701:6030"
+ },
+ "datasource": "${ds}",
+ "definition": "select fqdn from log.dn",
+ "description": "TDengine Nodes FQDN (Hostname)",
+ "error": null,
+ "hide": 0,
+ "includeAll": false,
+ "label": null,
+ "multi": false,
+ "name": "fqdn",
+ "options": [],
+ "query": "select fqdn from log.dn",
+ "refresh": 1,
+ "regex": "",
+ "skipUrlSync": false,
+ "sort": 0,
+ "tagValuesQuery": "",
+ "tags": [],
+ "tagsQuery": "",
+ "type": "query",
+ "useTags": false
+ }
+ ]
+ },
+ "time": {
+ "from": "now-1h",
+ "to": "now"
+ },
+ "timepicker": {
+ "refresh_intervals": [
+ "5s",
+ "10s",
+ "30s",
+ "1m",
+ "5m",
+ "15m",
+ "30m",
+ "1h",
+ "2h",
+ "1d"
+ ]
+ },
+ "timezone": "",
+ "title": "TDengine",
+ "uid": "tdengine",
+ "version": 8
+}
\ No newline at end of file
diff --git a/docs-cn/14-reference/07-tdinsight/assets/tdengine-grafana.json b/docs-cn/14-reference/07-tdinsight/assets/tdengine-grafana.json
new file mode 100644
index 0000000000000000000000000000000000000000..7696cfce3fcca3dd5f9278c91d3df2c1b32b9c97
--- /dev/null
+++ b/docs-cn/14-reference/07-tdinsight/assets/tdengine-grafana.json
@@ -0,0 +1,627 @@
+{
+ "annotations": {
+ "list": [
+ {
+ "builtIn": 1,
+ "datasource": "-- Grafana --",
+ "enable": true,
+ "hide": true,
+ "iconColor": "rgba(0, 211, 255, 1)",
+ "name": "Annotations & Alerts",
+ "type": "dashboard"
+ }
+ ]
+ },
+ "editable": true,
+ "gnetId": null,
+ "graphTooltip": 0,
+ "id": 3,
+ "links": [],
+ "panels": [
+ {
+ "cacheTimeout": null,
+ "colorBackground": false,
+ "colorValue": true,
+ "colors": ["#299c46", "rgba(237, 129, 40, 0.89)", "#d44a3a"],
+ "datasource": "TDengine",
+ "description": "total select request per minute last hour",
+ "format": "none",
+ "gauge": {
+ "maxValue": 100,
+ "minValue": 0,
+ "show": false,
+ "thresholdLabels": false,
+ "thresholdMarkers": true
+ },
+ "gridPos": {
+ "h": 6,
+ "w": 12,
+ "x": 0,
+ "y": 0
+ },
+ "id": 8,
+ "interval": null,
+ "links": [],
+ "mappingType": 1,
+ "mappingTypes": [
+ {
+ "name": "value to text",
+ "value": 1
+ },
+ {
+ "name": "range to text",
+ "value": 2
+ }
+ ],
+ "maxDataPoints": 100,
+ "nullPointMode": "connected",
+ "nullText": null,
+ "options": {},
+ "postfix": "次数/min",
+ "postfixFontSize": "20%",
+ "prefix": "",
+ "prefixFontSize": "50%",
+ "rangeMaps": [
+ {
+ "from": "null",
+ "text": "N/A",
+ "to": "null"
+ }
+ ],
+ "sparkline": {
+ "fillColor": "rgba(31, 118, 189, 0.18)",
+ "full": true,
+ "lineColor": "rgb(31, 120, 193)",
+ "show": true,
+ "ymax": null,
+ "ymin": null
+ },
+ "tableColumn": "",
+ "targets": [
+ {
+ "alias": "req_select",
+ "refId": "A",
+ "sql": "select sum(req_select) from log.dn where ts >= now-1h and ts < now interval(1m)",
+ "target": "select metric",
+ "type": "timeserie"
+ }
+ ],
+ "thresholds": "120,240",
+ "timeFrom": null,
+ "timeShift": null,
+ "title": "req select",
+ "type": "singlestat",
+ "valueFontSize": "150%",
+ "valueMaps": [
+ {
+ "op": "=",
+ "text": "N/A",
+ "value": "null"
+ }
+ ],
+ "valueName": "total"
+ },
+ {
+ "cacheTimeout": null,
+ "colorBackground": false,
+ "colorValue": true,
+ "colors": ["#299c46", "rgba(237, 129, 40, 0.89)", "#d44a3a"],
+ "datasource": "TDengine",
+ "description": "total insert request per minute for last hour",
+ "format": "none",
+ "gauge": {
+ "maxValue": 100,
+ "minValue": 0,
+ "show": false,
+ "thresholdLabels": false,
+ "thresholdMarkers": true
+ },
+ "gridPos": {
+ "h": 6,
+ "w": 12,
+ "x": 12,
+ "y": 0
+ },
+ "id": 6,
+ "interval": null,
+ "links": [],
+ "mappingType": 1,
+ "mappingTypes": [
+ {
+ "name": "value to text",
+ "value": 1
+ },
+ {
+ "name": "range to text",
+ "value": 2
+ }
+ ],
+ "maxDataPoints": 100,
+ "nullPointMode": "connected",
+ "nullText": null,
+ "options": {},
+ "postfix": "次数/min",
+ "postfixFontSize": "20%",
+ "prefix": "",
+ "prefixFontSize": "50%",
+ "rangeMaps": [
+ {
+ "from": "null",
+ "text": "N/A",
+ "to": "null"
+ }
+ ],
+ "sparkline": {
+ "fillColor": "rgba(31, 118, 189, 0.18)",
+ "full": false,
+ "lineColor": "rgb(31, 120, 193)",
+ "show": true,
+ "ymax": null,
+ "ymin": null
+ },
+ "tableColumn": "",
+ "targets": [
+ {
+ "alias": "req_insert",
+ "refId": "A",
+ "sql": "select sum(req_insert) from log.dn where ts >= now-1h and ts < now interval(1m)",
+ "target": "select metric",
+ "type": "timeserie"
+ }
+ ],
+ "thresholds": "110,240",
+ "timeFrom": null,
+ "timeShift": null,
+ "title": "req insert",
+ "type": "singlestat",
+ "valueFontSize": "150%",
+ "valueMaps": [
+ {
+ "op": "=",
+ "text": "N/A",
+ "value": "null"
+ }
+ ],
+ "valueName": "total"
+ },
+ {
+ "datasource": "TDengine",
+ "description": "taosd max memery last 10 minutes",
+ "gridPos": {
+ "h": 6,
+ "w": 8,
+ "x": 0,
+ "y": 6
+ },
+ "id": 12,
+ "options": {
+ "fieldOptions": {
+ "calcs": ["mean"],
+ "defaults": {
+ "mappings": [],
+ "max": 4096,
+ "min": 0,
+ "thresholds": [
+ {
+ "color": "green",
+ "value": null
+ },
+ {
+ "color": "red",
+ "value": 80
+ },
+ {
+ "color": "#EAB839",
+ "value": 2048
+ }
+ ],
+ "unit": "decmbytes"
+ },
+ "thresholds": [
+ {
+ "index": 0,
+ "color": "green",
+ "value": null
+ },
+ {
+ "index": 1,
+ "color": "red",
+ "value": 80
+ },
+ {
+ "index": 2,
+ "color": "#EAB839",
+ "value": 2048
+ }
+ ],
+ "override": {},
+ "values": false
+ },
+ "orientation": "auto",
+ "showThresholdLabels": true,
+ "showThresholdMarkers": true
+ },
+ "pluginVersion": "6.4.3",
+ "targets": [
+ {
+ "alias": "mem_taosd",
+ "refId": "A",
+ "sql": "select max(mem_taosd) from log.dn where ts >= now -10m and ts < now",
+ "target": "select metric",
+ "type": "timeserie"
+ }
+ ],
+ "timeFrom": null,
+ "timeShift": null,
+ "title": "taosd memery",
+ "type": "gauge"
+ },
+ {
+ "datasource": "TDengine",
+ "description": "max System Memory last 1 hour",
+ "gridPos": {
+ "h": 6,
+ "w": 8,
+ "x": 8,
+ "y": 6
+ },
+ "id": 10,
+ "options": {
+ "fieldOptions": {
+ "calcs": ["last"],
+ "mappings": [],
+ "defaults": {
+ "mappings": [],
+ "max": 4,
+ "min": 0,
+ "thresholds": [
+ {
+ "color": "green",
+ "value": null
+ },
+ {
+ "color": "semi-dark-orange",
+ "value": 60
+ },
+ {
+ "color": "dark-red",
+ "value": 80
+ }
+ ],
+ "title": "",
+ "unit": "decmbytes"
+ },
+ "thresholds": [
+ {
+ "index": 0,
+ "color": "green",
+ "value": null
+ },
+ {
+ "index": 1,
+ "color": "semi-dark-orange",
+ "value": 60
+ },
+ {
+ "index": 2,
+ "color": "dark-red",
+ "value": 80
+ }
+ ],
+ "override": {},
+ "values": false
+ },
+ "orientation": "auto",
+ "showThresholdLabels": true,
+ "showThresholdMarkers": true
+ },
+ "pluginVersion": "6.4.3",
+ "targets": [
+ {
+ "alias": "mem_system",
+ "refId": "A",
+ "sql": "select max(mem_system) from log.dn where ts >= now -10h and ts < now",
+ "target": "select metric",
+ "type": "timeserie"
+ }
+ ],
+ "timeFrom": null,
+ "timeShift": null,
+ "title": "system memory",
+ "type": "gauge"
+ },
+ {
+ "datasource": "TDengine",
+ "description": "avg band speed last one minute",
+ "gridPos": {
+ "h": 6,
+ "w": 8,
+ "x": 16,
+ "y": 6
+ },
+ "id": 14,
+ "options": {
+ "fieldOptions": {
+ "calcs": ["last"],
+ "defaults": {
+ "mappings": [],
+ "max": 8192,
+ "min": 0,
+ "thresholds": [
+ {
+ "color": "green",
+ "value": null
+ },
+ {
+ "color": "#EAB839",
+ "value": 4916
+ },
+ {
+ "color": "red",
+ "value": 6554
+ }
+ ],
+ "unit": "Kbits"
+ },
+ "mappings": [],
+ "thresholds": [
+ {
+ "index": 0,
+ "color": "green",
+ "value": null
+ },
+ {
+ "index": 1,
+ "color": "#EAB839",
+ "value": 4916
+ },
+ {
+ "index": 2,
+ "color": "red",
+ "value": 6554
+ }
+ ],
+ "override": {},
+ "values": false
+ },
+ "orientation": "auto",
+ "showThresholdLabels": false,
+ "showThresholdMarkers": true
+ },
+ "pluginVersion": "6.4.3",
+ "targets": [
+ {
+ "alias": "band_speed",
+ "refId": "A",
+ "sql": "select avg(band_speed) from log.dn where ts >= now-1h and ts < now interval(1m)",
+ "target": "select metric",
+ "type": "timeserie"
+ }
+ ],
+ "timeFrom": null,
+ "timeShift": null,
+ "title": "band speed",
+ "type": "gauge"
+ },
+ {
+ "aliasColors": {},
+ "bars": false,
+ "cacheTimeout": null,
+ "dashLength": 10,
+ "dashes": false,
+ "datasource": "TDengine",
+ "description": "monitor system cpu",
+ "fill": 1,
+ "fillGradient": 0,
+ "gridPos": {
+ "h": 11,
+ "w": 12,
+ "x": 0,
+ "y": 12
+ },
+ "hideTimeOverride": true,
+ "id": 2,
+ "legend": {
+ "avg": false,
+ "current": false,
+ "max": false,
+ "min": false,
+ "show": true,
+ "total": false,
+ "values": false
+ },
+ "lines": true,
+ "linewidth": 1,
+ "links": [],
+ "nullPointMode": "null",
+ "options": {
+ "dataLinks": []
+ },
+ "percentage": false,
+ "pluginVersion": "6.4.3",
+ "pointradius": 2,
+ "points": false,
+ "renderer": "flot",
+ "seriesOverrides": [],
+ "spaceLength": 10,
+ "stack": false,
+ "steppedLine": false,
+ "targets": [
+ {
+ "alias": "cpu_system11",
+ "hide": false,
+ "refId": "A",
+ "sql": "select avg(cpu_system) from log.dn where ts >= now-1h and ts < now interval(1s)",
+ "target": "select metric",
+ "type": "timeserie"
+ },
+ {
+ "alias": "cpu_taosd",
+ "hide": false,
+ "refId": "B",
+ "sql": "select avg(cpu_taosd) from log.dn where ts >= now-1h and ts < now interval(1s)",
+ "target": "select metric",
+ "type": "timeserie"
+ }
+ ],
+ "thresholds": [],
+ "timeFrom": "1h",
+ "timeRegions": [],
+ "timeShift": "30s",
+ "title": "cpu_system",
+ "tooltip": {
+ "shared": true,
+ "sort": 0,
+ "value_type": "individual"
+ },
+ "type": "graph",
+ "xaxis": {
+ "buckets": null,
+ "mode": "time",
+ "name": null,
+ "show": true,
+ "values": []
+ },
+ "yaxes": [
+ {
+ "decimals": null,
+ "format": "percent",
+ "label": "使用占比",
+ "logBase": 1,
+ "max": null,
+ "min": null,
+ "show": true
+ },
+ {
+ "format": "short",
+ "label": null,
+ "logBase": 1,
+ "max": null,
+ "min": null,
+ "show": false
+ }
+ ],
+ "yaxis": {
+ "align": false,
+ "alignLevel": null
+ }
+ },
+ {
+ "aliasColors": {},
+ "bars": false,
+ "dashLength": 10,
+ "dashes": false,
+ "datasource": "TDengine",
+ "fill": 1,
+ "fillGradient": 0,
+ "gridPos": {
+ "h": 11,
+ "w": 12,
+ "x": 12,
+ "y": 12
+ },
+ "id": 18,
+ "legend": {
+ "avg": false,
+ "current": false,
+ "max": false,
+ "min": false,
+ "show": true,
+ "total": false,
+ "values": false
+ },
+ "lines": true,
+ "linewidth": 1,
+ "nullPointMode": "null",
+ "options": {
+ "dataLinks": []
+ },
+ "percentage": false,
+ "pointradius": 2,
+ "points": false,
+ "renderer": "flot",
+ "seriesOverrides": [],
+ "spaceLength": 10,
+ "stack": false,
+ "steppedLine": false,
+ "targets": [
+ {
+ "alias": "",
+ "refId": "A",
+ "sql": "select avg(disk_used) disk_used from log.dn where ts >= $from and ts < $to interval(1s) group by fqdn",
+ "target": "select metric",
+ "type": "timeserie"
+ }
+ ],
+ "thresholds": [],
+ "timeFrom": null,
+ "timeRegions": [],
+ "timeShift": null,
+ "title": "avg_disk_used",
+ "tooltip": {
+ "shared": true,
+ "sort": 0,
+ "value_type": "individual"
+ },
+ "type": "graph",
+ "xaxis": {
+ "buckets": null,
+ "mode": "time",
+ "name": null,
+ "show": true,
+ "values": []
+ },
+ "yaxes": [
+ {
+ "format": "decgbytes",
+ "label": "",
+ "logBase": 1,
+ "max": null,
+ "min": null,
+ "show": true
+ },
+ {
+ "format": "short",
+ "label": null,
+ "logBase": 1,
+ "max": null,
+ "min": null,
+ "show": true
+ }
+ ],
+ "yaxis": {
+ "align": false,
+ "alignLevel": null
+ }
+ }
+ ],
+ "refresh": "5s",
+ "schemaVersion": 20,
+ "style": "dark",
+ "tags": [],
+ "templating": {
+ "list": []
+ },
+ "time": {
+ "from": "now-1h",
+ "to": "now"
+ },
+ "timepicker": {
+ "refresh_intervals": [
+ "5s",
+ "10s",
+ "30s",
+ "1m",
+ "5m",
+ "15m",
+ "30m",
+ "1h",
+ "2h",
+ "1d"
+ ]
+ },
+ "timezone": "",
+ "title": "TDengine",
+ "uid": "FE-vpe0Wk",
+ "version": 1
+}
diff --git a/docs-cn/14-reference/07-tdinsight/assets/tdengine_dashboard.png b/docs-cn/14-reference/07-tdinsight/assets/tdengine_dashboard.png
new file mode 100644
index 0000000000000000000000000000000000000000..0101e7430cb2ef673818de8bd3af53d0d082ad3f
Binary files /dev/null and b/docs-cn/14-reference/07-tdinsight/assets/tdengine_dashboard.png differ
diff --git a/docs-cn/14-reference/07-tdinsight/index.md b/docs-cn/14-reference/07-tdinsight/index.md
new file mode 100644
index 0000000000000000000000000000000000000000..553ae48b285f39a1fb29ebe946cb9b949adf9664
--- /dev/null
+++ b/docs-cn/14-reference/07-tdinsight/index.md
@@ -0,0 +1,427 @@
+---
+title: TDinsight - 基于Grafana的TDengine零依赖监控解决方案
+sidebar_label: TDinsight
+---
+
+TDinsight 是使用 [TDengine] 原生监控数据库和 [Grafana] 对 TDengine 进行监控的解决方案。
+
+TDengine 启动后,会自动创建一个监测数据库 log,并自动将服务器的 CPU、内存、硬盘空间、带宽、请求数、磁盘读写速度、慢查询等信息定时写入该数据库,并对重要的系统操作(比如登录、创建、删除数据库等)以及各种错误报警信息进行记录。通过 [Grafana] 和 [TDengine 数据源插件](https://github.com/taosdata/grafanaplugin/releases),TDinsight 将集群状态、节点信息、插入及查询请求、资源使用情况等进行可视化展示,同时还支持 vnode、dnode、mnode 节点状态异常告警,为开发者实时监控 TDengine 集群运行状态提供了便利。本文将指导用户安装 Grafana 服务器并通过 `TDinsight.sh` 安装脚本自动安装 TDengine 数据源插件及部署 TDinsight 可视化面板。
+
+## 系统要求
+
+要部署 TDinsight,需要一个单节点的 TDengine 服务器或一个多节点的 [TDengine] 集群,以及一个[Grafana]服务器。此仪表盘需要 TDengine 2.3.3.0 及以上,并启用 `log` 数据库(`monitor = 1`)。
+
+## 安装 Grafana
+
+我们建议在此处使用最新的[Grafana] 7 或 8 版本。您可以在任何[支持的操作系统](https://grafana.com/docs/grafana/latest/installation/requirements/#supported-operating-systems)中,按照 [Grafana 官方文档安装说明](https://grafana.com/docs/grafana/latest/installation/) 安装 [Grafana]。
+
+### 在 Debian 或 Ubuntu 上安装 Grafana
+
+对于 Debian 或 Ubuntu 操作系统,建议使用 Grafana 镜像仓库。使用如下命令从零开始安装:
+
+```bash
+sudo apt-get install -y apt-transport-https
+sudo apt-get install -y software-properties-common wget
+wget -q -O - https://packages.grafana.com/gpg.key |\
+ sudo apt-key add -
+echo "deb https://packages.grafana.com/oss/deb stable main" |\
+ sudo tee -a /etc/apt/sources.list.d/grafana.list
+sudo apt-get update
+sudo apt-get install grafana
+```
+
+### 在 CentOS / RHEL 上安装 Grafana
+
+您可以从官方 YUM 镜像仓库安装。
+
+```bash
+sudo tee /etc/yum.repos.d/grafana.repo << EOF
+[grafana]
+name=grafana
+baseurl=https://packages.grafana.com/oss/rpm
+repo_gpgcheck=1
+enabled=1
+gpgcheck=1
+gpgkey=https://packages.grafana.com/gpg.key
+sslverify=1
+sslcacert=/etc/pki/tls/certs/ca-bundle.crt
+EOF
+sudo yum install grafana
+```
+
+或者用 RPM 安装:
+
+```bash
+wget https://dl.grafana.com/oss/release/grafana-7.5.11-1.x86_64.rpm
+sudo yum install grafana-7.5.11-1.x86_64.rpm
+# or
+sudo yum install \
+ https://dl.grafana.com/oss/release/grafana-7.5.11-1.x86_64.rpm
+```
+
+## 自动部署 TDinsight
+
+我们提供了一个自动化安装脚本 [`TDinsight.sh`](https://github.com/taosdata/grafanaplugin/releases/latest/download/TDinsight.sh) 脚本以便用户快速进行安装配置。
+
+您可以通过 `wget` 或其他工具下载该脚本:
+
+```bash
+wget https://github.com/taosdata/grafanaplugin/releases/latest/download/TDinsight.sh
+chmod +x TDinsight.sh
+```
+
+这个脚本会自动下载最新的[Grafana TDengine 数据源插件](https://github.com/taosdata/grafanaplugin/releases/latest) 和 [TDinsight 仪表盘](https://grafana.com/grafana/dashboards/15167) ,将命令行选项中的可配置参数转为 [Grafana Provisioning](https://grafana.com/docs/grafana/latest/administration/provisioning/) 配置文件,以进行自动化部署及更新等操作。利用该脚本提供的告警设置选项,你还可以获得内置的阿里云短信告警通知支持。
+
+假设您在同一台主机上使用 TDengine 和 Grafana 的默认服务。运行 `./TDinsight.sh` 并打开 Grafana 浏览器窗口就可以看到 TDinsight 仪表盘了。
+
+下面是 TDinsight.sh 的用法说明:
+
+```bash
+Usage:
+ ./TDinsight.sh
+ ./TDinsight.sh -h|--help
+ ./TDinsight.sh -n -a -u -p
+
+Install and configure TDinsight dashboard in Grafana on ubuntu 18.04/20.04 system.
+
+-h, -help, --help Display help
+
+-V, -verbose, --verbose Run script in verbose mode. Will print out each step of execution.
+
+-v, --plugin-version TDengine datasource plugin version, [default: latest]
+
+-P, --grafana-provisioning-dir Grafana provisioning directory, [default: /etc/grafana/provisioning/]
+-G, --grafana-plugins-dir Grafana plugins directory, [default: /var/lib/grafana/plugins]
+-O, --grafana-org-id Grafana orgnization id. [default: 1]
+
+-n, --tdengine-ds-name TDengine datasource name, no space. [default: TDengine]
+-a, --tdengine-api TDengine REST API endpoint. [default: http://127.0.0.1:6041]
+-u, --tdengine-user TDengine user name. [default: root]
+-p, --tdengine-password TDengine password. [default: taosdata]
+
+-i, --tdinsight-uid Replace with a non-space ascii code as the dashboard id. [default: tdinsight]
+-t, --tdinsight-title Dashboard title. [default: TDinsight]
+-e, --tdinsight-editable If the provisioning dashboard could be editable. [default: false]
+
+-E, --external-notifier Apply external notifier uid to TDinsight dashboard.
+
+Aliyun SMS as Notifier:
+-s, --sms-enabled To enable tdengine-datasource plugin builtin aliyun sms webhook.
+-N, --sms-notifier-name Provisioning notifier name.[default: TDinsight Builtin SMS]
+-U, --sms-notifier-uid Provisioning notifier uid, use lowercase notifier name by default.
+-D, --sms-notifier-is-default Set notifier as default.
+-I, --sms-access-key-id Aliyun sms access key id
+-K, --sms-access-key-secret Aliyun sms access key secret
+-S, --sms-sign-name Sign name
+-C, --sms-template-code Template code
+-T, --sms-template-param Template param, a escaped json string like '{"alarm_level":"%s","time":"%s","name":"%s","content":"%s"}'
+-B, --sms-phone-numbers Comma-separated numbers list, eg "189xxxxxxxx,132xxxxxxxx"
+-L, --sms-listen-addr [default: 127.0.0.1:9100]
+```
+
+大多数命令行选项都可以通过环境变量获得同样的效果。
+
+| 短选项 | 长选项 | 环境变量 | 说明 |
+| ------ | -------------------------- | ---------------------------- | --------------------------------------------------------------------------- |
+| -v | --plugin-version | TDENGINE_PLUGIN_VERSION | TDengine 数据源插件版本,默认使用最新版。 |
+| -P | --grafana-provisioning-dir | GF_PROVISIONING_DIR | Grafana 配置目录,默认为`/etc/grafana/provisioning/` |
+| -G | --grafana-plugins-dir | GF_PLUGINS_DIR | Grafana 插件目录,默认为`/var/lib/grafana/plugins`。 |
+| -O | --grafana-org-id | GF_ORG_ID | Grafana 组织 ID,默认为 1。 |
+| -n | --tdengine-ds-name | TDENGINE_DS_NAME | TDengine 数据源名称,默认为 TDengine。 |
+| -a | --tdengine-api | TDENGINE_API | TDengine REST API 端点。默认为`http://127.0.0.1:6041`。 |
+| -u | --tdengine-user | TDENGINE_USER | TDengine 用户名。 [默认值:root] |
+| -p | --tdengine-密码 | TDENGINE_PASSWORD | TDengine 密码。 [默认:taosdata] |
+| -i | --tdinsight-uid | TDINSIGHT_DASHBOARD_UID | TDinsight 仪表盘`uid`。 [默认值:tdinsight] |
+| -t | --tdinsight-title | TDINSIGHT_DASHBOARD_TITLE | TDinsight 仪表盘标题。 [默认:TDinsight] |
+| -e | --tdinsight-可编辑 | TDINSIGHT_DASHBOARD_EDITABLE | 如果配置仪表盘可以编辑。 [默认值:false] |
+| -E | --external-notifier | EXTERNAL_NOTIFIER | 将外部通知程序 uid 应用于 TDinsight 仪表盘。 |
+| -s | --sms-enabled | SMS_ENABLED | 启用阿里云短信 webhook 内置的 tdengine-datasource 插件。 |
+| -N | --sms-notifier-name | SMS_NOTIFIER_NAME | 供应通知程序名称。[默认:`TDinsight Builtin SMS`] |
+| -U | --sms-notifier-uid | SMS_NOTIFIER_UID | "Notification Channel" `uid`,默认使用程序名称的小写,其他字符用 “-” 代替。 |
+| -D | --sms-notifier-is-default | SMS_NOTIFIER_IS_DEFAULT | 将内置短信通知设置为默认值。 |
+| -I | --sms-access-key-id | SMS_ACCESS_KEY_ID | 阿里云短信访问密钥 id |
+| -K | --sms-access-key-secret | SMS_ACCESS_KEY_SECRET | 阿里云短信访问秘钥 |
+| -S | --sms-sign-name | SMS_SIGN_NAME | 签名 |
+| -C | --sms-template-code | SMS_TEMPLATE_CODE | 模板代码 |
+| -T | --sms-template-param | SMS_TEMPLATE_PARAM | 模板参数的 JSON 模板 |
+| -B | --sms-phone-numbers | SMS_PHONE_NUMBERS | 逗号分隔的手机号列表,例如`"189xxxxxxxx,132xxxxxxxx"` |
+| -L | --sms-listen-addr | SMS_LISTEN_ADDR | 内置 sms webhook 监听地址,默认为`127.0.0.1:9100` |
+
+假设您在主机 `tdengine` 上启动 TDengine 数据库,HTTP API 端口为 `6041`,用户为 `root1`,密码为 `pass5ord`。执行脚本:
+
+```bash
+sudo ./TDinsight.sh -a http://tdengine:6041 -u root1 -p pass5ord
+```
+
+我们提供了一个“-E”选项,用于从命令行配置 TDinsight 使用现有的通知通道(Notification Channel)。假设你的 Grafana 用户和密码是 `admin:admin`,使用以下命令获取已有的通知通道的`uid`:
+
+```bash
+curl --no-progress-meter -u admin:admin http://localhost:3000/api/alert-notifications | jq
+```
+
+使用上面获取的 `uid` 值作为 `-E` 输入。
+
+```bash
+sudo ./TDinsight.sh -a http://tdengine:6041 -u root1 -p pass5ord -E existing-notifier
+```
+
+如果你想使用[阿里云短信](https://www.aliyun.com/product/sms)服务作为通知渠道,你应该使用`-s`标志启用并添加以下参数:
+
+- `-N`:Notification Channel 名,默认为`TDinsight Builtin SMS`。
+- `-U`:Channel uid,默认是 `name` 的小写,任何其他字符都替换为 - ,对于默认的 `-N`,其 uid 为 `tdinsight-builtin-sms`。
+- `-I`:阿里云短信访问密钥 id。
+- `-K`:阿里云短信访问秘钥。
+- `-S`:阿里云短信签名。
+- `-C`:阿里云短信模板 ID。
+- `-T`:阿里云短信模板参数,为 JSON 格式模板,示例如下 `'{"alarm_level":"%s","time":"%s","name":"%s","content":"%s "}'`。有四个参数:告警级别、时间、名称和告警内容。
+- `-B`:电话号码列表,以逗号`,`分隔。
+
+如果要监控多个 TDengine 集群,则需要设置多个 TDinsight 仪表盘。设置非默认 TDinsight 需要进行一些更改: `-n` `-i` `-t` 选项需要更改为非默认名称,如果使用 内置短信告警功能,`-N` 和 `-L` 也应该改变。
+
+```bash
+sudo ./TDengine.sh -n TDengine-Env1 -a http://another:6041 -u root -p taosdata -i tdinsight-env1 -t 'TDinsight Env1'
+# 如果使用内置短信通知
+sudo ./TDengine.sh -n TDengine-Env1 -a http://another:6041 -u root -p taosdata -i tdinsight-env1 -t 'TDinsight Env1' \
+ -s -N 'Env1 SMS' -I xx -K xx -S xx -C SMS_XX -T '' -B 00000000000 -L 127.0.0.01:10611
+```
+
+请注意,配置数据源、通知 Channel 和仪表盘在前端是不可更改的。您应该再次通过此脚本更新配置或手动更改 `/etc/grafana/provisioning` 目录(这是 Grafana 的默认目录,根据需要使用`-P`选项更改)中的配置文件。
+
+特别地,当您使用 Grafana Cloud 或其他组织时,`-O` 可用于设置组织 ID。 `-G` 可指定 Grafana 插件安装目录。 `-e` 参数将仪表盘设置为可编辑。
+
+## 手动设置 TDinsight
+
+### 安装 TDengine 数据源插件
+
+从 GitHub 安装 TDengine 最新版数据源插件。
+
+```bash
+get_latest_release() {
+ curl --silent "https://api.github.com/repos/taosdata/grafanaplugin/releases/latest" |
+ grep '"tag_name":' |
+ sed -E 's/.*"v([^"]+)".*/\1/'
+}
+TDENGINE_PLUGIN_VERSION=$(get_latest_release)
+sudo grafana-cli \
+ --pluginUrl https://github.com/taosdata/grafanaplugin/releases/download/v$TDENGINE_PLUGIN_VERSION/tdengine-datasource-$TDENGINE_PLUGIN_VERSION.zip \
+ plugins install tdengine-datasource
+```
+
+### 配置 Grafana
+
+将以下设置添加到配置文件 `/etc/grafana/grafana.ini`,以启用未签名插件。
+
+```ini
+[plugins]
+allow_loading_unsigned_plugins = tdengine-datasource
+```
+
+### 启动 Grafana 服务
+
+```bash
+sudo systemctl start grafana-server
+sudo systemctl enable grafana-server
+```
+
+### 登录到 Grafana
+
+在 Web 浏览器中打开默认的 Grafana 网址:`http://localhost:3000`。
+默认用户名/密码都是 `admin`。Grafana 会要求在首次登录后更改密码。
+
+### 添加 TDengine 数据源
+
+指向 **Configurations** -> **Data Sources** 菜单,然后点击 **Add data source** 按钮。
+
+
+
+搜索并选择**TDengine**。
+
+
+
+配置 TDengine 数据源。
+
+
+
+保存并测试,正常情况下会报告 'TDengine Data source is working'。
+
+
+
+### 导入仪表盘
+
+指向 **+** / **Create** - **import**(或 `/dashboard/import` url)。
+
+
+
+在 **Import via grafana.com** 位置键入仪表盘 ID `15167` 并 **Load**。
+
+
+
+导入完成后,TDinsight 的完整页面视图如下所示。
+
+
+
+## TDinsight 仪表盘详细信息
+
+TDinsight 仪表盘旨在提供 TDengine 相关资源使用情况[dnodes, mdodes, vnodes](https://www.taosdata.com/cn/documentation/architecture#cluster)或数据库的使用情况和状态。
+
+指标详情如下:
+
+### 集群状态
+
+
+
+这部分包括集群当前信息和状态,告警信息也在此处(从左到右,从上到下)。
+
+- **First EP**:当前 TDengine 集群中的`firstEp`设置。
+- **Version**:TDengine 服务器版本(master mnode)。
+- **Master Uptime**: 当前 Master MNode 被选举为 Master 后经过的时间。
+- **Expire Time** - 企业版过期时间。
+- **Used Measuring Points** - 企业版已使用的测点数。
+- **Databases** - 数据库个数。
+- **Connections** - 当前连接个数。
+- **DNodes/MNodes/VGroups/VNodes**:每种资源的总数和存活数。
+- **DNodes/MNodes/VGroups/VNodes Alive Percent**:每种资源的存活数/总数的比例,启用告警规则,并在资源存活率(1 分钟内平均健康资源比例)不足 100%时触发。
+- **Messuring Points Used**:启用告警规则的测点数用量(社区版无数据,默认情况下是健康的)。
+- **Grants Expire Time**:启用告警规则的企业版过期时间(社区版无数据,默认情况是健康的)。
+- **Error Rate**:启用警报的集群总合错误率(每秒平均错误数)。
+- **Variables**:`show variables` 表格展示。
+
+### DNodes 状态
+
+
+
+- **DNodes Status**:`show dnodes` 的简单表格视图。
+- **DNodes Lifetime**:从创建 dnode 开始经过的时间。
+- **DNodes Number**:DNodes 数量变化。
+- **Offline Reason**:如果有任何 dnode 状态为离线,则以饼图形式展示离线原因。
+
+### MNode 概述
+
+
+
+1. **MNodes Status**:`show mnodes` 的简单表格视图。
+2. **MNodes Number**:类似于`DNodes Number`,MNodes 数量变化。
+
+### 请求
+
+
+
+1. **Requests Rate(Inserts per Second)**:平均每秒插入次数。
+2. **Requests (Selects)**:查询请求数及变化率(count of second)。
+3. **Requests (HTTP)**:HTTP 请求数和请求速率(count of second)。
+
+### 数据库
+
+
+
+数据库使用情况,对变量 `$database` 的每个值即每个数据库进行重复多行展示。
+
+1. **STables**:超级表数量。
+2. **Total Tables**:所有表数量。
+3. **Sub Tables**:所有超级表子表的数量。
+4. **Tables**:所有普通表数量随时间变化图。
+5. **Tables Number Foreach VGroups**:每个 VGroups 包含的表数量。
+
+### DNode 资源使用情况
+
+
+
+数据节点资源使用情况展示,对变量 `$fqdn` 即每个数据节点进行重复多行展示。包括:
+
+1. **Uptime**:从创建 dnode 开始经过的时间。
+2. **Has MNodes?**:当前 dnode 是否为 mnode。
+3. **CPU Cores**:CPU 核数。
+4. **VNodes Number**:当前 dnode 的 VNodes 数量。
+5. **VNodes Masters**:处于 master 角色的 vnode 数量。
+6. **Current CPU Usage of taosd**:taosd 进程的 CPU 使用率。
+7. **Current Memory Usage of taosd**:taosd 进程的内存使用情况。
+8. **Disk Used**:taosd 数据目录的总磁盘使用百分比。
+9. **CPU Usage**:进程和系统 CPU 使用率。
+10. **RAM Usage**:RAM 使用指标时间序列视图。
+11. **Disk Used**:多级存储下每个级别使用的磁盘(默认为 level0 级)。
+12. **Disk Increasing Rate per Minute**:每分钟磁盘用量增加或减少的百分比。
+13. **Disk IO**:磁盘 IO 速率。
+14. **Net IO**:网络 IO,除本机网络之外的总合网络 IO 速率。
+
+### 登录历史
+
+
+
+目前只报告每分钟登录次数。
+
+### TaosAdapter
+
+
+
+包含 taosAdapter 请求统计和状态详情。包括:
+
+1. **http_request**: 包含总请求数,请求失败数以及正在处理的请求数
+2. **top 3 request endpoint**: 按终端分组,请求排名前三的数据
+3. **Memory Used**: taosAdapter 内存使用情况
+4. **latency_quantile(ms)**: (1, 2, 5, 9, 99)阶段的分位数
+5. **top 3 failed request endpoint**: 按终端分组,请求失败排名前三的数据
+6. **CPU Used**: taosAdapter cpu 使用情况
+
+## 升级
+
+通过 `TDinsight.sh` 脚本安装的 TDinsight,可以通过重新运行该脚本就可以升级到最新的 Grafana 插件和 TDinsight Dashboard。
+
+手动安装的情况下,可按照上述步骤自行安装新的 Grafana 插件和 Dashboard。
+
+## 卸载
+
+通过 `TDinsight.sh` 脚本安装的 TDinsight,可以使用命令行 `TDinsight.sh -R` 清理相关资源。
+
+手动安装时,要完全卸载 TDinsight,需要清理以下内容:
+
+1. Grafana 中的 TDinsight Dashboard。
+2. Grafana 中的 Data Source 数据源。
+3. 从插件安装目录删除 `tdengine-datasource` 插件。
+
+## 整合的 Docker 示例
+
+```bash
+git clone --depth 1 https://github.com/taosdata/grafanaplugin.git
+cd grafanaplugin
+```
+
+根据需要在 `docker-compose.yml` 文件中修改:
+
+```yaml
+version: "3.7"
+
+services:
+ grafana:
+ image: grafana/grafana:7.5.10
+ volumes:
+ - ./dist:/var/lib/grafana/plugins/tdengine-datasource
+ - ./grafana/grafana.ini:/etc/grafana/grafana.ini
+ - ./grafana/provisioning/:/etc/grafana/provisioning/
+ - grafana-data:/var/lib/grafana
+ environment:
+ TDENGINE_API: ${TDENGINE_API}
+ TDENGINE_USER: ${TDENGINE_USER}
+ TDENGINE_PASS: ${TDENGINE_PASS}
+ SMS_ACCESS_KEY_ID: ${SMS_ACCESS_KEY_ID}
+ SMS_ACCESS_KEY_SECRET: ${SMS_ACCESS_KEY_SECRET}
+ SMS_SIGN_NAME: ${SMS_SIGN_NAME}
+ SMS_TEMPLATE_CODE: ${SMS_TEMPLATE_CODE}
+ SMS_TEMPLATE_PARAM: "${SMS_TEMPLATE_PARAM}"
+ SMS_PHONE_NUMBERS: $SMS_PHONE_NUMBERS
+ SMS_LISTEN_ADDR: ${SMS_LISTEN_ADDR}
+ ports:
+ - 3000:3000
+volumes:
+ grafana-data:
+```
+
+替换`docker-compose.yml`中的环境变量或保存环境变量到`.env`文件,然后用`docker-compose up`启动 Grafana。`docker-compose` 工具的具体用法参见 [Docker Compose Reference](https://docs.docker.com/compose/)
+
+```bash
+docker-compose up -d
+```
+
+TDinsight 已经通过 Provisioning 部署完毕,请到 http://localhost:3000/d/tdinsight/ 查看仪表盘。
+
+[grafana]: https://grafana.com
+[tdengine]: https://www.taosdata.com
diff --git a/docs-cn/14-reference/08-server-config/_category_.yml b/docs-cn/14-reference/08-server-config/_category_.yml
deleted file mode 100644
index e05fbeb578ceb525ae80f3d50c3e018df13bfa56..0000000000000000000000000000000000000000
--- a/docs-cn/14-reference/08-server-config/_category_.yml
+++ /dev/null
@@ -1 +0,0 @@
-label: 服务端配置
\ No newline at end of file
diff --git a/docs-cn/14-reference/08-taos-shell.md b/docs-cn/14-reference/08-taos-shell.md
new file mode 100644
index 0000000000000000000000000000000000000000..c9167fcf2643954981925fb5ef67a60cbad97a6d
--- /dev/null
+++ b/docs-cn/14-reference/08-taos-shell.md
@@ -0,0 +1,85 @@
+---
+title: TDengine 命令行(CLI)
+sidebar_label: TDengine CLI
+description: TDengine CLI 的使用说明和技巧
+---
+
+TDengine 命令行程序(以下简称 TDengine CLI)是用户操作 TDengine 实例并与之交互的最简洁最常用的方式。
+
+## 安装
+
+如果在 TDengine 服务器端执行,无需任何安装,已经自动安装好。如果要在非 TDengine 服务器端运行,需要安装 TDengine 客户端驱动,具体安装,请参考 [连接器](/reference/connector/)。
+
+## 执行
+
+要进入 TDengine CLI,您只要在 Linux 终端或Windos 终端执行 `taos` 即可。
+
+```bash
+taos
+```
+如果连接服务成功,将会打印出欢迎消息和版本信息。如果失败,则会打印错误消息出来(请参考 [FAQ](/train-faq/faq) 来解决终端连接服务端失败的问题)。TDengine CLI 的提示符号如下:
+
+```cmd
+taos>
+```
+进入CLI后,你可执行各种SQL语句,包括插入、查询以及各种管理命令。
+
+## 执行 SQL 脚本
+
+在 TDengine CLI 里可以通过 `source` 命令来运行 SQL 命令脚本。
+
+```sql
+taos> source ;
+```
+
+## 在线修改显示字符宽度
+
+可以在 TDengine CLI 里使用如下命令调整字符显示宽度
+
+```sql
+taos> SET MAX_BINARY_DISPLAY_WIDTH ;
+```
+
+如显示的内容后面以...结尾时,表示该内容已被截断,可通过本命令修改显示字符宽度以显示完整的内容。
+
+## 命令行参数
+
+您可通过配置命令行参数来改变 TDengine CLI 的行为。以下为常用的几个命令行参数:
+
+- -h, --host=HOST: 要连接的 TDengine 服务端所在服务器的 FQDN, 默认为连接本地服务
+- -P, --port=PORT: 指定服务端所用端口号
+- -u, --user=USER: 连接时使用的用户名
+- -p, --password=PASSWORD: 连接服务端时使用的密码
+- -?, --help: 打印出所有命令行参数
+
+还有更多其他参数:
+
+- -c, --config-dir: 指定配置文件目录,默认为 `/etc/taos`,该目录下的配置文件默认名称为 taos.cfg
+- -C, --dump-config: 打印 -c 指定的目录中 taos.cfg 的配置参数
+- -d, --database=DATABASE: 指定连接到服务端时使用的数据库
+- -D, --directory=DIRECTORY: 导入指定路径中的 SQL 脚本文件
+- -f, --file=FILE: 以非交互模式执行 SQL 脚本文件
+- -k, --check=CHECK: 指定要检查的表
+- -l, --pktlen=PKTLEN: 网络测试时使用的测试包大小
+- -n, --netrole=NETROLE: 网络连接测试时的测试范围,默认为 startup, 可选值为 client, server, rpc, startup, sync, speed, fqdn
+- -r, --raw-time: 将时间输出出 uint64_t
+- -s, --commands=COMMAND: 以非交互模式执行的 SQL 命令
+- -S, --pkttype=PKTTYPE: 指定网络测试所用的包类型,默认为 TCP。只有 netrole 为 speed 时既可以指定为 TCP 也可以指定为 UDP
+- -T, --thread=THREADNUM: 以多线程模式导入数据时的线程数
+- -s, --commands: 在不进入终端的情况下运行 TDengine 命令
+- -z, --timezone=TIMEZONE: 指定时区,默认为本地
+- -V, --version: 打印出当前版本号
+
+示例:
+
+```bash
+taos -h h1.taos.com -s "use db; show tables;"
+```
+## TDengine CLI 小技巧
+
+- 可以使用上下光标键查看历史输入的指令
+- 修改用户密码:在 shell 中使用 `alter user` 命令,缺省密码为 taosdata
+- ctrl+c 中止正在进行中的查询
+- 执行 `RESET QUERY CACHE` 可清除本地缓存的表 schema
+- 批量执行 SQL 语句。可以将一系列的 shell 命令(以英文 ; 结尾,每个 SQL 语句为一行)按行存放在文件里,在 shell 里执行命令 `source ` 自动执行该文件里所有的 SQL 语句
+- 输入 q 回车,退出 taos shell
diff --git a/docs-cn/14-reference/09-client-config/09-client-config.md b/docs-cn/14-reference/09-client-config/09-client-config.md
deleted file mode 100644
index 15ca79b029d8194c5af0c43ab579aac8727b06d4..0000000000000000000000000000000000000000
--- a/docs-cn/14-reference/09-client-config/09-client-config.md
+++ /dev/null
@@ -1,105 +0,0 @@
-# 客户端及应用驱动配置
-
-TDengine 系统的前台交互客户端应用程序为 taos,以及应用驱动,它与 taosd 共享同一个配置文件 taos.cfg。运行 taos 时,使用参数-c 指定配置文件目录,如 taos -c /home/cfg,表示使用/home/cfg/目录下的 taos.cfg 配置文件中的参数,缺省目录是/etc/taos。更多 taos 的使用方法请见帮助信息 `taos --help`。本节主要说明 taos 客户端应用在配置文件 taos.cfg 文件中使用到的参数。
-
-**2.0.10.0 之后版本支持命令行以下参数显示当前客户端参数的配置**
-
-```bash
-taos -C 或 taos --dump-config
-```
-
-客户端及应用驱动配置参数列表及解释
-
-- firstEp: taos 启动时,主动连接的集群中第一个 taosd 实例的 end point, 缺省值为 localhost:6030。
-
-- secondEp: taos 启动时,如果 firstEp 连不上,将尝试连接 secondEp。
-
-- locale:系统区位信息及编码格式。
-
- 默认值:系统中动态获取,如果自动获取失败,需要用户在配置文件设置或通过 API 设置。
-
- TDengine 为存储中文、日文、韩文等非 ASCII 编码的宽字符,提供一种专门的字段类型 nchar。写入 nchar 字段的数据将统一采用 UCS4-LE 格式进行编码并发送到服务器。需要注意的是,编码正确性是客户端来保证。因此,如果用户想要正常使用 nchar 字段来存储诸如中文、日文、韩文等非 ASCII 字符,需要正确设置客户端的编码格式。
-
- 客户端的输入的字符均采用操作系统当前默认的编码格式,在 Linux 系统上多为 UTF-8,部分中文系统编码则可能是 GB18030 或 GBK 等。在 docker 环境中默认的编码是 POSIX。在中文版 Windows 系统中,编码则是 CP936。客户端需要确保正确设置自己所使用的字符集,即客户端运行的操作系统当前编码字符集,才能保证 nchar 中的数据正确转换为 UCS4-LE 编码格式。
-
- 在 Linux 中 locale 的命名规则为: <语言>\_<地区>.<字符集编码> 如:zh_CN.UTF-8,zh 代表中文,CN 代表大陆地区,UTF-8 表示字符集。字符集编码为客户端正确解析本地字符串提供编码转换的说明。Linux 系统与 Mac OSX 系统可以通过设置 locale 来确定系统的字符编码,由于 Windows 使用的 locale 中不是 POSIX 标准的 locale 格式,因此在 Windows 下需要采用另一个配置参数 charset 来指定字符编码。在 Linux 系统中也可以使用 charset 来指定字符编码。
-
-- charset:字符集编码。
-
- 默认值:系统中动态获取,如果自动获取失败,需要用户在配置文件设置或通过 API 设置。
-
- 如果配置文件中不设置 charset,在 Linux 系统中,taos 在启动时候,自动读取系统当前的 locale 信息,并从 locale 信息中解析提取 charset 编码格式。如果自动读取 locale 信息失败,则尝试读取 charset 配置,如果读取 charset 配置也失败,则中断启动过程。
-
- 在 Linux 系统中,locale 信息包含了字符编码信息,因此正确设置了 Linux 系统 locale 以后可以不用再单独设置 charset。例如:
-
- ```
- locale zh_CN.UTF-8
- ```
-
- 在 Windows 系统中,无法从 locale 获取系统当前编码。如果无法从配置文件中读取字符串编码信息,taos 默认设置为字符编码为 CP936。其等效在配置文件中添加如下配置:
-
- ```
- charset CP936
- ```
-
- 如果需要调整字符编码,请查阅当前操作系统使用的编码,并在配置文件中正确设置。
-
- 在 Linux 系统中,如果用户同时设置了 locale 和字符集编码 charset,并且 locale 和 charset 的不一致,后设置的值将覆盖前面设置的值。
-
- ```
- locale zh_CN.UTF-8
- charset GBK
- ```
-
- 则 charset 的有效值是 GBK。
-
- ```
- charset GBK
- locale zh_CN.UTF-8
- ```
-
- charset 的有效值是 UTF-8。
-
- 日志的配置参数,与 server 的配置参数完全一样。
-
-- timezone
-
- 默认值:动态获取当前客户端运行系统所在的时区。
-
- 为应对多时区的数据写入和查询问题,TDengine 采用 Unix 时间戳(Unix Timestamp)来记录和存储时间戳。Unix 时间戳的特点决定了任一时刻不论在任何时区,产生的时间戳均一致。需要注意的是,Unix 时间戳是在客户端完成转换和记录。为了确保客户端其他形式的时间转换为正确的 Unix 时间戳,需要设置正确的时区。
-
- 在 Linux 系统中,客户端会自动读取系统设置的时区信息。用户也可以采用多种方式在配置文件设置时区。例如:
-
- ```
- timezone UTC-8
- timezone GMT-8
- timezone Asia/Shanghai
- ```
-
- 均是合法的设置东八区时区的格式。但需注意,Windows 下并不支持 `timezone Asia/Shanghai` 这样的写法,而必须写成 `timezone UTC-8`。
-
- 时区的设置对于查询和写入 SQL 语句中非 Unix 时间戳的内容(时间戳字符串、关键词 now 的解析)产生影响。例如:
-
- ```sql
- SELECT count(*) FROM table_name WHERE TS<'2019-04-11 12:01:08';
- ```
-
- 在东八区,SQL 语句等效于
-
- ```sql
- SELECT count(*) FROM table_name WHERE TS<1554955268000;
- ```
-
- 在 UTC 时区,SQL 语句等效于
-
- ```sql
- SELECT count(*) FROM table_name WHERE TS<1554984068000;
- ```
-
- 为了避免使用字符串时间格式带来的不确定性,也可以直接使用 Unix 时间戳。此外,还可以在 SQL 语句中使用带有时区的时间戳字符串,例如:RFC3339 格式的时间戳字符串,2013-04-12T15:52:01.123+08:00 或者 ISO-8601 格式时间戳字符串 2013-04-12T15:52:01.123+0800。上述两个字符串转化为 Unix 时间戳不受系统所在时区的影响。
-
- 启动 taos 时,也可以从命令行指定一个 taosd 实例的 end point,否则就从 taos.cfg 读取。
-
-- maxBinaryDisplayWidth
-
- Shell 中 binary 和 nchar 字段的显示宽度上限,超过此限制的部分将被隐藏。默认值:30。可在 taos shell 中通过命令 set max_binary_display_width nn 动态修改此选项。
diff --git a/docs-cn/14-reference/09-client-config/_category_.yml b/docs-cn/14-reference/09-client-config/_category_.yml
deleted file mode 100644
index ad6e70b96dd031cc3d2607565f91d554e19addeb..0000000000000000000000000000000000000000
--- a/docs-cn/14-reference/09-client-config/_category_.yml
+++ /dev/null
@@ -1 +0,0 @@
-label: 客户端配置
diff --git a/docs-cn/14-reference/05-support-platform/_category_.yml b/docs-cn/14-reference/09-support-platform/_category_.yml
similarity index 100%
rename from docs-cn/14-reference/05-support-platform/_category_.yml
rename to docs-cn/14-reference/09-support-platform/_category_.yml
diff --git a/docs-cn/14-reference/05-support-platform/05-support-platform.md b/docs-cn/14-reference/09-support-platform/index.md
similarity index 99%
rename from docs-cn/14-reference/05-support-platform/05-support-platform.md
rename to docs-cn/14-reference/09-support-platform/index.md
index 35fb659b08c6fb9426d76cbb0d854e39a82f226d..11374e4deb44de4a08ce5c239cd6166014e7ee1d 100644
--- a/docs-cn/14-reference/05-support-platform/05-support-platform.md
+++ b/docs-cn/14-reference/09-support-platform/index.md
@@ -1,4 +1,6 @@
-# 支持平台列表
+---
+title: 支持平台列表
+---
## TDengine 服务端支持的平台列表
diff --git a/docs-cn/14-reference/07-docker/_category_.yml b/docs-cn/14-reference/11-docker/_category_.yml
similarity index 100%
rename from docs-cn/14-reference/07-docker/_category_.yml
rename to docs-cn/14-reference/11-docker/_category_.yml
diff --git a/docs-cn/14-reference/07-docker/07-docker.md b/docs-cn/14-reference/11-docker/index.md
similarity index 99%
rename from docs-cn/14-reference/07-docker/07-docker.md
rename to docs-cn/14-reference/11-docker/index.md
index 3efcd0bace13c0b391f06a312e0affb7991610bd..6960db08b271b628d5c3c451865e4a7187b1712f 100644
--- a/docs-cn/14-reference/07-docker/07-docker.md
+++ b/docs-cn/14-reference/11-docker/index.md
@@ -1,4 +1,6 @@
-# 用 Docker 部署 TDengine
+---
+title: 用 Docker 部署 TDengine
+---
本章主要介绍如何在容器中启动 TDengine 服务并访问它。
注意:可以在 docker run 命令行中或者 docker-compose 文件中使用环境变量来控制容器中服务的行为。
diff --git a/docs-cn/14-reference/12-config/_category_.yml b/docs-cn/14-reference/12-config/_category_.yml
new file mode 100644
index 0000000000000000000000000000000000000000..8d3cfcc8d0d8966bf1354f9ece83faea105f9c7a
--- /dev/null
+++ b/docs-cn/14-reference/12-config/_category_.yml
@@ -0,0 +1 @@
+label: 配置参数
\ No newline at end of file
diff --git a/docs-cn/14-reference/08-server-config/08-server-config.md b/docs-cn/14-reference/12-config/index.md
similarity index 86%
rename from docs-cn/14-reference/08-server-config/08-server-config.md
rename to docs-cn/14-reference/12-config/index.md
index 844aa21c4378e892e1379e28b5501f8eaceb4750..0f7ba121c7e22c738772eef4178aab6e53adb6fd 100644
--- a/docs-cn/14-reference/08-server-config/08-server-config.md
+++ b/docs-cn/14-reference/12-config/index.md
@@ -1,4 +1,9 @@
-# 服务端配置
+---
+title: 配置参数
+description: "TDengine 客户端和服务配置列表"
+---
+
+## 为服务端指定配置文件
TDengine 系统后台服务由 taosd 提供,可以在配置文件 taos.cfg 里修改配置参数,以满足不同场景的需求。配置文件的缺省位置在/etc/taos 目录,可以通过 taosd 命令行执行参数 -c 指定配置文件目录。比如,指定配置文件位于`/home/user` 这个目录:
@@ -12,28 +17,56 @@ taosd -c /home/user
taosd -C
```
-下面仅仅列出一些重要的配置参数,更多的参数请看配置文件里的说明。而且这些参数的缺省配置都是可以工作的,一般无需设置。
+## 为客户端指定配置文件
+
+TDengine 系统的前台交互客户端应用程序为 taos,以及应用驱动,它可以与 taosd 共享同一个配置文件 taos.cfg,也可以使用单独指定配置文件。运行 taos 时,使用参数-c 指定配置文件目录,如 taos -c /home/cfg,表示使用/home/cfg/目录下的 taos.cfg 配置文件中的参数,缺省目录是/etc/taos。更多 taos 的使用方法请见帮助信息 `taos --help`。
+
+**2.0.10.0 之后版本支持命令行以下参数显示当前客户端参数的配置**
+
+```bash
+taos -C
+```
+
+```bash
+taos --dump-config
+```
+
+# 配置参数详细列表
+
+:::note
+本节内容覆盖产品的配置参数,适用于服务端的参数按其对产品行为的影响进行分类,这其中有部分参数也同时适用于客户端;但有少量参数仅适用于客户端,这部分参数进行了单独归类。
+
+:::
+
:::note
配置文件参数修改后,需要重启*taosd*服务,或客户端应用才能生效。
:::
-## 首要参数
+## 连接相关
-### firstEP
+### firstEp
| 属性 | 说明 |
| -------- | ----------------------------------------------------- |
| 适用范围 | 服务端和客户端均适用 |
-| 含义 | taosd 启动时,主动连接的集群中首个 dnode 的 end point |
+| 含义 | taosd 或者 taos 启动时,主动连接的集群中首个 dnode 的 end point |
| 缺省值 | localhost:6030 |
+### secondEp
+
+| 属性 | 说明 |
+| -------- | ---------------------------------------------------------------------------- |
+| 适用范围 | 服务端和客户端均适用 |
+| 含义 | taosd 或者 taos 启动时,如果 firstEp 连接不上,尝试连接集群中第二个 dnode 的 end point |
+| 缺省值 | 无 |
+
### fqdn
| 属性 | 说明 |
| -------- | ----------------------------------------------------------------- |
-| 适用范围 | 服务端和客户端均适用 |
+| 适用范围 | 仅服务端适用 |
| 含义 | 数据节点的 FQDN。如果习惯 IP 地址访问,可设置为该节点的 IP 地址。 |
| 缺省值 | 缺省为操作系统配置的第一个 hostname。 |
| 补充说明 | 这个参数值的长度需要控制在 96 个字符以内。 |
@@ -42,10 +75,10 @@ taosd -C
| 属性 | 说明 |
| -------- | ------------------------------------------------------------------------------------------------------------------- |
-| 适用范围 | 服务端和客户端均适用 |
+| 适用范围 | 仅服务端适用 |
| 含义 | taosd 启动后,对外服务的端口号 |
| 缺省值 | 6030 |
-| 补充说明 | RESTful 服务使用的端口号是在此基础上+11,即默认值为 6041(注意 2.4 及后续版本使用 taosAdapter 提供 RESTful 接口)。 |
+| 补充说明 | RESTful 服务在2.4.0.0之前(不含)由taosd提供,默认端口为 6041; 在2.4.0.0 及后续版本由 taosAdapter,默认端口为6041 |
:::note
对于端口,TDengine 会使用从 serverPort 起 13 个连续的 TCP 和 UDP 端口号,请务必在防火墙打开。因此如果是缺省配置,需要打开从 6030 到 6042 共 13 个端口,而且必须 TCP 和 UDP 都打开。(详细的端口情况请参见下表)
@@ -55,7 +88,7 @@ taosd -C
| TCP | 6030 | 客户端与服务端之间通讯。 | 由配置文件设置 serverPort 决定。 |
| TCP | 6035 | 多节点集群的节点间通讯。 | 随 serverPort 端口变化。 |
| TCP | 6040 | 多节点集群的节点间数据同步。 | 随 serverPort 端口变化。 |
-| TCP | 6041 | 客户端与服务端之间的 RESTful 通讯。 | 随 serverPort 端口变化。注意 taosAdapter 配置或有不同,请参考相应[文档](https://www.taosdata.com/cn/documentation/tools/adapter)。 |
+| TCP | 6041 | 客户端与服务端之间的 RESTful 通讯。 | 随 serverPort 端口变化。注意 taosAdapter 配置或有不同,请参考相应[文档](/reference/taosadapter/)。 |
| TCP | 6042 | Arbitrator 的服务端口。 | 随 Arbitrator 启动参数设置变化。 |
| TCP | 6043 | TaosKeeper 监控服务端口。 | 随 TaosKeeper 启动参数设置变化。 |
| TCP | 6044 | 支持 StatsD 的数据接入端口。 | 随 taosAdapter 启动参数设置变化(2.3.0.1+以上版本)。 |
@@ -64,32 +97,36 @@ taosd -C
| UDP | 6030-6034 | 客户端与服务端之间通讯。 | 随 serverPort 端口变化。 |
| UDP | 6035-6039 | 多节点集群的节点间通讯。 | 随 serverPort 端口变化。
+### maxShellConns
-### logDir
-
-| 属性 | 说明 |
-| -------- | -------------------------------------------------- |
-| 适用范围 | 服务端和客户端均适用 |
-| 含义 | 日志文件目录,客户端和服务器的运行日志将写入该目录 |
-| 缺省值 | /var/log/taos |
+| 属性 | 说明 |
+| -------- | ----------------------- |
+| 适用范围 | 仅服务端适用 |
+| 含义 | 一个 dnode 容许的连接数 |
+| 取值范围 | 10-50000000 |
+| 缺省值 | 5000 |
-### dataDir
+### maxConnections
-| 属性 | 说明 |
-| -------- | ------------------------------------------ |
-| 适用范围 | 仅服务端适用 |
-| 含义 | 数据文件目录,所有的数据文件都将写入该目录 |
-| 缺省值 | /var/lib/taos |
+| 属性 | 说明 |
+| -------- | ------------------------------------------------------------------------------- |
+| 适用范围 | 仅服务端适用 |
+| 含义 | 一个数据库连接所容许的 dnode 连接数 |
+| 取值范围 | 1-100000 |
+| 缺省值 | 5000 |
+| 补充说明 | 实际测试下来,如果默认没有配,选 50 个 worker thread 会产生 Network unavailable |
-### arbitrator
+### rpcForceTcp
-| 属性 | 说明 |
-| -------- | ------------------------ |
-| 适用范围 | 仅服务端适用 |
-| 含义 | 系统中裁决器的 end point |
-| 缺省值 | 空 |
+| 属性 | 说明 |
+| -------- | --------------------------------------------------- |
+| 适用范围 | 服务端和客户端均适用 |
+| 含义 | 强制使用 TCP 传输 |
+| 取值范围 | 0: 不开启 1: 开启 |
+| 缺省值 | 0 |
+| 补充说明 | 在网络比较差的环境中,建议开启。
2.0 版本新增。 |
-## 开关类
+## 监控相关
### monitor
@@ -100,51 +137,56 @@ taosd -C
| 取值范围 | 0:关闭监控服务, 1:激活监控服务。 |
| 缺省值 | 0 |
-### vnodeBak
+### monitorInterval
+
+| 属性 | 说明 |
+| -------- | -------------------------------------------- |
+| 适用范围 | 仅服务端适用 |
+| 含义 | 监控数据库记录系统参数(CPU/内存)的时间间隔 |
+| 单位 | 秒 |
+| 取值范围 | 1-600 |
+| 缺省值 | 30 |
-| 属性 | 说明 |
-| -------- | -------------------------------- |
-| 适用范围 | 仅服务端适用 |
-| 含义 | 删除 vnode 时是否备份 vnode 目录 |
-| 取值范围 | 0:否,1:是 |
-| 缺省值 | 1 |
-### elemetryRePorting
+### telemetryReporting
| 属性 | 说明 |
| -------- | ---------------------------------------- |
| 适用范围 | 仅服务端适用 |
| 含义 | 是否允许 TDengine 采集和上报基本使用信息 |
-| 取值范围 | 0:不允许
1:允许 |
+| 取值范围 | 0:不允许 1:允许 |
| 缺省值 | 1 |
-### balance
+## 查询相关
-| 属性 | 说明 |
-| -------- | ---------------- |
-| 适用范围 | 仅服务端适用 |
-| 含义 | 是否启动负载均衡 |
-| 取值范围 | 0,1 |
-| 缺省值 | 1 |
+### queryBufferSize
-### stream
+| 属性 | 说明 |
+| -------- | ------------------------------------------------------------------------------------------------------------------- |
+| 适用范围 | 仅服务端适用 |
+| 含义 | 为所有并发查询占用保留的内存大小。 |
+| 单位 | MB |
+| 缺省值 | 无 |
+| 补充说明 | 计算规则可以根据实际应用可能的最大并发数和表的数字相乘,再乘 170 。
(2.0.15 以前的版本中,此参数的单位是字节) |
-| 属性 | 说明 |
-| -------- | ------------------------------ |
-| 适用范围 | 仅服务端适用 |
-| 含义 | 是否启用连续查询(流计算功能) |
-| 取值范围 | 0:不允许
1:允许 |
-| 缺省值 | 1 |
+### ratioOfQueryCores
-### enableCoreFile
+| 属性 | 说明 |
+| -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --- |
+| 适用范围 | 仅服务端适用 |
+| 含义 | 设置查询线程的最大数量。 |
+| 缺省值 | 1 |
+| 补充说明 | 最小值 0 表示只有 1 个查询线程
最大值 2 表示最大建立 2 倍 CPU 核数的查询线程。
默认为 1,表示最大和 CPU 核数相等的查询线程。
该值可以为小数,即 0.5 表示最大建立 CPU 核数一半的查询线程。 |
-| 属性 | 说明 |
-| -------- | ------------------------------------------------------------------------------------------------------------------------------------------ |
-| 适用范围 | 服务端和客户端均适用 |
-| 含义 | 是否开启服务 crash 时生成 core 文件 |
-| 取值范围 | 0:否,1:是 |
-| 缺省值 | 1 |
-| 补充说明 | 不同的启动方式,生成 core 文件的目录如下:1、systemctl start taosd 启动:生成的 core 在根目录下
2、手动启动,就在 taosd 执行目录下。 |
+### maxNumOfDistinctRes
+
+| 属性 | 说明 |
+| -------- | -------------------------------- |
+| 适用范围 | 仅服务端适用 |
+| 含义 | 允许返回的 distinct 结果最大行数 |
+| 取值范围 | 默认值为 10 万,最大值 1 亿 |
+| 缺省值 | 10 万 |
+| 补充说明 | 2.3 版本新增。 | |
## 区域相关
@@ -156,6 +198,41 @@ taosd -C
| 含义 | 时区 |
| 缺省值 | 从系统中动态获取当前的时区设置 |
+:::info
+为应对多时区的数据写入和查询问题,TDengine 采用 Unix 时间戳(Unix Timestamp)来记录和存储时间戳。Unix 时间戳的特点决定了任一时刻不论在任何时区,产生的时间戳均一致。需要注意的是,Unix 时间戳是在客户端完成转换和记录。为了确保客户端其他形式的时间转换为正确的 Unix 时间戳,需要设置正确的时区。
+
+ 在 Linux 系统中,客户端会自动读取系统设置的时区信息。用户也可以采用多种方式在配置文件设置时区。例如:
+
+ ```
+ timezone UTC-8
+ timezone GMT-8
+ timezone Asia/Shanghai
+ ```
+
+ 均是合法的设置东八区时区的格式。但需注意,Windows 下并不支持 `timezone Asia/Shanghai` 这样的写法,而必须写成 `timezone UTC-8`。
+
+ 时区的设置对于查询和写入 SQL 语句中非 Unix 时间戳的内容(时间戳字符串、关键词 now 的解析)产生影响。例如:
+
+ ```sql
+ SELECT count(*) FROM table_name WHERE TS<'2019-04-11 12:01:08';
+ ```
+
+ 在东八区,SQL 语句等效于
+
+ ```sql
+ SELECT count(*) FROM table_name WHERE TS<1554955268000;
+ ```
+
+ 在 UTC 时区,SQL 语句等效于
+
+ ```sql
+ SELECT count(*) FROM table_name WHERE TS<1554984068000;
+ ```
+
+ 为了避免使用字符串时间格式带来的不确定性,也可以直接使用 Unix 时间戳。此外,还可以在 SQL 语句中使用带有时区的时间戳字符串,例如:RFC3339 格式的时间戳字符串,2013-04-12T15:52:01.123+08:00 或者 ISO-8601 格式时间戳字符串 2013-04-12T15:52:01.123+0800。上述两个字符串转化为 Unix 时间戳不受系统所在时区的影响。
+
+:::
+
### locale
| 属性 | 说明 |
@@ -164,6 +241,15 @@ taosd -C
| 含义 | 系统区位信息及编码格式 |
| 缺省值 | 系统中动态获取,如果自动获取失败,需要用户在配置文件设置或通过 API 设置 |
+:::info
+ TDengine 为存储中文、日文、韩文等非 ASCII 编码的宽字符,提供一种专门的字段类型 nchar。写入 nchar 字段的数据将统一采用 UCS4-LE 格式进行编码并发送到服务器。需要注意的是,编码正确性是客户端来保证。因此,如果用户想要正常使用 nchar 字段来存储诸如中文、日文、韩文等非 ASCII 字符,需要正确设置客户端的编码格式。
+
+ 客户端的输入的字符均采用操作系统当前默认的编码格式,在 Linux 系统上多为 UTF-8,部分中文系统编码则可能是 GB18030 或 GBK 等。在 docker 环境中默认的编码是 POSIX。在中文版 Windows 系统中,编码则是 CP936。客户端需要确保正确设置自己所使用的字符集,即客户端运行的操作系统当前编码字符集,才能保证 nchar 中的数据正确转换为 UCS4-LE 编码格式。
+
+ 在 Linux 中 locale 的命名规则为: <语言>\_<地区>.<字符集编码> 如:zh_CN.UTF-8,zh 代表中文,CN 代表大陆地区,UTF-8 表示字符集。字符集编码为客户端正确解析本地字符串提供编码转换的说明。Linux 系统与 Mac OSX 系统可以通过设置 locale 来确定系统的字符编码,由于 Windows 使用的 locale 中不是 POSIX 标准的 locale 格式,因此在 Windows 下需要采用另一个配置参数 charset 来指定字符编码。在 Linux 系统中也可以使用 charset 来指定字符编码。
+
+:::
+
### charset
| 属性 | 说明 |
@@ -172,8 +258,51 @@ taosd -C
| 含义 | 字符集编码 |
| 缺省值 | 系统中动态获取,如果自动获取失败,需要用户在配置文件设置或通过 API 设置 |
+:::info
+如果配置文件中不设置 charset,在 Linux 系统中,taos 在启动时候,自动读取系统当前的 locale 信息,并从 locale 信息中解析提取 charset 编码格式。如果自动读取 locale 信息失败,则尝试读取 charset 配置,如果读取 charset 配置也失败,则中断启动过程。
+
+ 在 Linux 系统中,locale 信息包含了字符编码信息,因此正确设置了 Linux 系统 locale 以后可以不用再单独设置 charset。例如:
+
+ ```
+ locale zh_CN.UTF-8
+ ```
+
+ 在 Windows 系统中,无法从 locale 获取系统当前编码。如果无法从配置文件中读取字符串编码信息,taos 默认设置为字符编码为 CP936。其等效在配置文件中添加如下配置:
+
+ ```
+ charset CP936
+ ```
+
+ 如果需要调整字符编码,请查阅当前操作系统使用的编码,并在配置文件中正确设置。
+
+ 在 Linux 系统中,如果用户同时设置了 locale 和字符集编码 charset,并且 locale 和 charset 的不一致,后设置的值将覆盖前面设置的值。
+
+ ```
+ locale zh_CN.UTF-8
+ charset GBK
+ ```
+
+ 则 charset 的有效值是 GBK。
+
+ ```
+ charset GBK
+ locale zh_CN.UTF-8
+ ```
+
+ charset 的有效值是 UTF-8。
+
+:::
+
## 存储相关
+### dataDir
+
+| 属性 | 说明 |
+| -------- | ------------------------------------------ |
+| 适用范围 | 仅服务端适用 |
+| 含义 | 数据文件目录,所有的数据文件都将写入该目录 |
+| 缺省值 | /var/lib/taos |
+
### cache
| 属性 | 说明 |
@@ -264,16 +393,6 @@ taosd -C
| 缺省值 | 0 |
| 补充说明 | 2.1.2.0 版本之前、2.0.20.7 版本之前在 taos.cfg 文件中不支持此参数。
-
-### minimalLogDirGB
-
-| 属性 | 说明 |
-| -------- | -------------------------------------------- |
-| 适用范围 | 服务端和客户端均适用 |
-| 含义 | 当日志文件夹的磁盘大小小于该值时,停止写日志 |
-| 单位 | GB |
-| 缺省值 | 0.1 |
-
### minimalTmpDirGB
| 属性 | 说明 |
@@ -281,7 +400,7 @@ taosd -C
| 适用范围 | 服务端和客户端均适用 |
| 含义 | 当日志文件夹的磁盘大小小于该值时,停止写临时文件 |
| 单位 | GB |
-| 缺省值 | 0.1 |
+| 缺省值 | 1.0 |
### minimalDataDirGB
@@ -290,10 +409,27 @@ taosd -C
| 适用范围 | 仅服务端适用 |
| 含义 | 当日志文件夹的磁盘大小小于该值时,停止写时序数据 |
| 单位 | GB |
-| 缺省值 | 0.1 |
+| 缺省值 | 2.0 |
+
+### vnodeBak
+
+| 属性 | 说明 |
+| -------- | -------------------------------- |
+| 适用范围 | 仅服务端适用 |
+| 含义 | 删除 vnode 时是否备份 vnode 目录 |
+| 取值范围 | 0:否,1:是 |
+| 缺省值 | 1 |
## 集群相关
+### numOfMnodes
+
+| 属性 | 说明 |
+| -------- | ------------------ |
+| 适用范围 | 仅服务端适用 |
+| 含义 | 系统中管理节点个数 |
+| 缺省值 | 3 |
+
### replica
| 属性 | 说明 |
@@ -320,6 +456,32 @@ taosd -C
| 含义 | dnode 的可选角色 |
| 取值范围 | 0:any(既可作为 mnode,也可分配 vnode)
1:mgmt(只能作为 mnode,不能分配 vnode)
2:dnode(不能作为 mnode,只能分配 vnode) |
| 缺省值 | 0 |
+### balance
+
+| 属性 | 说明 |
+| -------- | ---------------- |
+| 适用范围 | 仅服务端适用 |
+| 含义 | 是否启动负载均衡 |
+| 取值范围 | 0,1 |
+| 缺省值 | 1 |
+
+### balanceInterval
+
+| 属性 | 说明 |
+| -------- | ------------------------------------------------ |
+| 适用范围 | 仅服务端适用 |
+| 含义 | 管理节点在正常运行状态下,检查负载均衡的时间间隔 |
+| 单位 | 秒 |
+| 取值范围 | 1-30000 |
+| 缺省值 | 300 |
+
+### arbitrator
+
+| 属性 | 说明 |
+| -------- | ------------------------ |
+| 适用范围 | 仅服务端适用 |
+| 含义 | 系统中裁决器的 end point,其格式如firstEp |
+| 缺省值 | 空 |
## 时间相关
@@ -373,28 +535,7 @@ taosd -C
| 取值范围 | 1-8640000 |
| 缺省值 | 7200 |
-### minSlidingTime
-
-| 属性 | 说明 |
-| -------- | ----------------------------------- |
-| 适用范围 | 仅服务端适用 |
-| 含义 | 最小滑动窗口时长 |
-| 单位 | 毫秒 |
-| 取值范围 | 10-1000000 |
-| 缺省值 | 10 |
-| 补充说明 | 支持 us 补值后,这个值就是 1us 了。 |
-
-### minIntervalTime
-
-| 属性 | 说明 |
-| -------- | -------------- |
-| 适用范围 | 仅服务端适用 |
-| 含义 | 时间窗口最小值 |
-| 单位 | 毫秒 |
-| 取值范围 | 1-1000000 |
-| 缺省值 | 10 |
-
-### maxTmerCtrl
+### maxTmrCtrl
| 属性 | 说明 |
| -------- | -------------------- |
@@ -404,16 +545,6 @@ taosd -C
| 取值范围 | 8-2048 |
| 缺省值 | 512 |
-### monitorInterval
-
-| 属性 | 说明 |
-| -------- | -------------------------------------------- |
-| 适用范围 | 仅服务端适用 |
-| 含义 | 监控数据库记录系统参数(CPU/内存)的时间间隔 |
-| 单位 | 秒 |
-| 取值范围 | 1-600 |
-| 缺省值 | 30 |
-
### offlineThreshold
| 属性 | 说明 |
@@ -424,47 +555,8 @@ taosd -C
| 取值范围 | 5-7200000 |
| 缺省值 | 86400\*10(10 天) |
-### maxStreamCompDelay
-
-| 属性 | 说明 |
-| -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
-| 适用范围 | 仅服务端适用 |
-| 含义 | 连续查询启动最大延迟 |
-| 单位 | 毫秒 |
-| 取值范围 | 10-1000000000 |
-| 缺省值 | 20000 |
-| 补充说明 | 为避免多个 stream 同时执行占用太多系统资源,程序中对 stream 的执行时间人为增加了一些随机的延时。
maxFirstStreamCompDelay 是 stream 第一次执行前最少要等待的时间。
streamCompDelayRatio 是延迟时间的计算系数,它乘以查询的 interval 后为延迟时间基准。
maxStreamCompDelay 是延迟时间基准的上限。
实际延迟时间为一个不超过延迟时间基准的随机值。
stream 某次计算失败后需要重试,retryStreamCompDelay 是重试的等待时间基准。
实际重试等待时间为不超过等待时间基准的随机值。 |
-
-### maxFirstStreamCompDelay
-
-| 属性 | 说明 |
-| -------- | -------------------------- |
-| 适用范围 | 仅服务端适用 |
-| 含义 | 第一次连续查询启动最大延迟 |
-| 单位 | 毫秒 |
-| 取值范围 | 10-1000000000 |
-| 缺省值 | 10000 |
-
-### retryStreamCompDelay
-
-| 属性 | 说明 |
-| -------- | -------------------- |
-| 适用范围 | 仅服务端适用 |
-| 含义 | 连续查询重试等待间隔 |
-| 单位 | 毫秒 |
-| 取值范围 | 10-1000000000 |
-| 缺省值 | 10 |
-
-### streamCompDelayRatio
-
-| 属性 | 说明 |
-| -------- | -------------------------- |
-| 适用范围 | 仅服务端适用 |
-| 含义 | 连续查询的延迟时间计算系数 |
-| 取值范围 | 0.1-0.9 |
-| 缺省值 | 0.1 |
-## 数量相关
+## 性能调优
### numOfThreadsPerCore
@@ -484,14 +576,6 @@ taosd -C
| 缺省值 | 1 |
| 补充说明 | 该值可以为小数,即 0.5 表示最大建立 CPU 核数一半的查询线程。 |
-### numOfMnodes
-
-| 属性 | 说明 |
-| -------- | ------------------ |
-| 适用范围 | 仅服务端适用 |
-| 含义 | 系统中管理节点个数 |
-| 缺省值 | 3 |
-
### maxVgroupsPerDb
| 属性 | 说明 |
@@ -509,41 +593,47 @@ taosd -C
| 含义 | 每个 vnode 中能够创建的最大表个数 |
| 缺省值 | 1000000 |
-### maxNumOfOrderedRes
+### minTablesPerVnode
-| 属性 | 说明 |
-| -------- | -------------------------------------- |
-| 适用范围 | 服务端和客户端均适用 |
-| 含义 | 支持超级表时间排序允许的最多记录数限制 |
-| 缺省值 | 10 万 |
+| 属性 | 说明 |
+| -------- | --------------------------------- |
+| 适用范围 | 仅服务端适用 |
+| 含义 | 每个 vnode 中必须创建表的最小数量 |
+| 缺省值 | 1000 |
-### maxShellConns
+### tableIncStepPerVnode
-| 属性 | 说明 |
-| -------- | ----------------------- |
-| 适用范围 | 仅服务端适用 |
-| 含义 | 一个 dnode 容许的连接数 |
-| 取值范围 | 10-50000000 |
-| 缺省值 | 5000 |
+| 属性 | 说明 |
+| -------- | ----------------------------------- |
+| 适用范围 | 仅服务端适用 |
+| 含义 | 每个 vnode 中超过最小表数,i.e. minTablesPerVnode, 后递增步长 |
+| 缺省值 | 1000 |
-### maxConnections
+### maxNumOfOrderedRes
+
+| 属性 | 说明 |
+| -------- | -------------------------------------- |
+| 适用范围 | 服务端和客户端均适用 |
+| 含义 | 支持超级表时间排序允许的最多记录数限制 |
+| 缺省值 | 10 万 |
-| 属性 | 说明 |
-| -------- | ------------------------------------------------------------------------------- |
-| 适用范围 | 仅服务端适用 |
-| 含义 | 一个数据库连接所容许的 dnode 连接数 |
-| 取值范围 | 1-100000 |
-| 缺省值 | 5000 |
-| 补充说明 | 实际测试下来,如果默认没有配,选 50 个 worker thread 会产生 Network unavailable |
### mnodeEqualVnodeNum
| 属性 | 说明 |
| -------- | ---------------------------------- |
| 适用范围 | 仅服务端适用 |
-| 含义 | 一个 mnode 等同于 vnode 消耗的个数 |
+| 含义 | 将一个 mnode 等同于 vnode 消耗的个数 |
| 缺省值 | 4 |
+### numOfCommitThreads
+
+| 属性 | 说明 |
+| -------- | ---------------------- |
+| 适用范围 | 仅服务端适用 |
+| 含义 | 设置写入线程的最大数量 |
+| 缺省值 | |
+
## 压缩相关
### comp
@@ -555,6 +645,14 @@ taosd -C
| 取值范围 | 0:关闭,1:一阶段压缩,2:两阶段压缩 |
| 缺省值 | 2 |
+### tsdbMetaCompactRatio
+
+| 属性 | 说明 |
+| -------- | -------------------------------------------------------------- |
+| 含义 | tsdb meta 文件中冗余数据超过多少阈值,开启 meta 文件的压缩功能 |
+| 取值范围 | 0:不开启,[1-100]:冗余数据比例 |
+| 缺省值 | 0 |
+
### compressMsgSize
| 属性 | 说明 |
@@ -606,8 +704,90 @@ taosd -C
| 缺省值 | 0.0000000000000001 |
| 补充说明 | 小于此值的浮点数尾数部分将被截取 |
+## 连续查询相关
+
+### stream
+
+| 属性 | 说明 |
+| -------- | ------------------------------ |
+| 适用范围 | 仅服务端适用 |
+| 含义 | 是否启用连续查询(流计算功能) |
+| 取值范围 | 0:不允许
1:允许 |
+| 缺省值 | 1 |
+
+### minSlidingTime
+
+| 属性 | 说明 |
+| -------- | ----------------------------------- |
+| 适用范围 | 仅服务端适用 |
+| 含义 | 最小滑动窗口时长 |
+| 单位 | 毫秒 |
+| 取值范围 | 10-1000000 |
+| 缺省值 | 10 |
+| 补充说明 | 支持 us 补值后,这个值就是 1us 了。 |
+
+### minIntervalTime
+
+| 属性 | 说明 |
+| -------- | -------------- |
+| 适用范围 | 仅服务端适用 |
+| 含义 | 时间窗口最小值 |
+| 单位 | 毫秒 |
+| 取值范围 | 1-1000000 |
+| 缺省值 | 10 |
+
+### maxStreamCompDelay
+
+| 属性 | 说明 |
+| -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
+| 适用范围 | 仅服务端适用 |
+| 含义 | 连续查询启动最大延迟 |
+| 单位 | 毫秒 |
+| 取值范围 | 10-1000000000 |
+| 缺省值 | 20000 |
+
+### maxFirstStreamCompDelay
+
+| 属性 | 说明 |
+| -------- | -------------------------- |
+| 适用范围 | 仅服务端适用 |
+| 含义 | 第一次连续查询启动最大延迟 |
+| 单位 | 毫秒 |
+| 取值范围 | 10-1000000000 |
+| 缺省值 | 10000 |
+
+### retryStreamCompDelay
+
+| 属性 | 说明 |
+| -------- | -------------------- |
+| 适用范围 | 仅服务端适用 |
+| 含义 | 连续查询重试等待间隔 |
+| 单位 | 毫秒 |
+| 取值范围 | 10-1000000000 |
+| 缺省值 | 10 |
+
+### streamCompDelayRatio
+
+| 属性 | 说明 |
+| -------- | -------------------------- |
+| 适用范围 | 仅服务端适用 |
+| 含义 | 连续查询的延迟时间计算系数,实际延迟时间为本参数乘以计算时间窗口 |
+| 取值范围 | 0.1-0.9 |
+| 缺省值 | 0.1 |
+
+:::info
+为避免多个 stream 同时执行占用太多系统资源,程序中对 stream 的执行时间人为增加了一些随机的延时。
maxFirstStreamCompDelay 是 stream 第一次执行前最少要等待的时间。
streamCompDelayRatio 是延迟时间的计算系数,它乘以查询的 interval 后为延迟时间基准。
maxStreamCompDelay 是延迟时间基准的上限。
实际延迟时间为一个不超过延迟时间基准的随机值。
stream 某次计算失败后需要重试,retryStreamCompDelay 是重试的等待时间基准。
实际重试等待时间为不超过等待时间基准的随机值。
+
+:::
+
## HTTP 相关
+:::note
+HTTP服务在2.4.0.0(不含)以前的版本中由taosd提供,在2.4.0.0以后(含)由taosAdapter提供。
+本节的配置参数仅在2.4.0.0(不含)以前的版本中生效。如果您使用的是2.4.0.0(含)及以后的版本请参考[文档](/reference/taosadapter/)。
+
+:::
+
### http
| 属性 | 说明 |
@@ -622,7 +802,7 @@ taosd -C
| 属性 | 说明 |
| -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------- |
| 适用范围 | 仅服务端适用 |
-| 含义 | 内部使用,记录通过 RESTFul 接口,产生的 SQL 调用。taosAdapter 配置或有不同,请参考相应[文档](https://www.taosdata.com/cn/documentation/tools/adapter)。 |
+| 含义 | 记录通过 RESTFul 接口,产生的 SQL 调用。 |
| 缺省值 | 0 |
| 补充说明 | 生成的文件(httpnote.0/httpnote.1),与服务端日志所在目录相同。 |
@@ -631,7 +811,7 @@ taosd -C
| 属性 | 说明 |
| -------- | --------------------------------------------------------------------------------------------------------------------------- |
| 适用范围 | 仅服务端适用 |
-| 含义 | RESTFul 接口的线程数。taosAdapter 配置或有不同,请参考相应[文档](https://www.taosdata.com/cn/documentation/tools/adapter)。 |
+| 含义 | RESTFul 接口的线程数。taosAdapter 配置或有不同,请参考相应[文档](/reference/taosadapter/)。 |
| 缺省值 | 2 |
### restfulRowLimit
@@ -639,7 +819,7 @@ taosd -C
| 属性 | 说明 |
| -------- | ------------------------------------------------------------------------------------------------------------------------------------- |
| 适用范围 | 仅服务端适用 |
-| 含义 | RESTFul 接口单次返回的记录条数。taosAdapter 配置或有不同,请参考相应[文档](https://www.taosdata.com/cn/documentation/tools/adapter)。 |
+| 含义 | RESTFul 接口单次返回的记录条数。taosAdapter 配置或有不同,请参考相应[文档](/reference/taosadapter/)。 |
| 缺省值 | 10240 |
| 补充说明 | 最大 10,000,000 |
@@ -655,6 +835,24 @@ taosd -C
## 日志相关
+### logDir
+
+| 属性 | 说明 |
+| -------- | -------------------------------------------------- |
+| 适用范围 | 服务端和客户端均适用 |
+| 含义 | 日志文件目录,客户端和服务器的运行日志将写入该目录 |
+| 缺省值 | /var/log/taos |
+
+### minimalLogDirGB
+
+| 属性 | 说明 |
+| -------- | -------------------------------------------- |
+| 适用范围 | 服务端和客户端均适用 |
+| 含义 | 当日志文件夹的磁盘大小小于该值时,停止写日志 |
+| 单位 | GB |
+| 缺省值 | 1.0 |
+
+
### numOfLogLines
| 属性 | 说明 |
@@ -853,138 +1051,6 @@ taosd -C
| 取值范围 | 同上 |
| 缺省值 | |
-## 内部配置
-
-### secondEP
-
-| 属性 | 说明 |
-| -------- | ---------------------------------------------------------------------------- |
-| 适用范围 | 服务端和客户端均适用 |
-| 含义 | taosd 启动时,如果 firstEp 连接不上,尝试连接集群中第二个 dnode 的 end point |
-| 缺省值 | 无 |
-
-### scriptDir
-
-| 属性 | 说明 |
-| -------- | ------------ |
-| 适用范围 | 仅服务端适用 |
-| 含义 | |
-| 缺省值 | |
-
-### balanceInterval
-
-| 属性 | 说明 |
-| -------- | ------------------------------------------------ |
-| 适用范围 | 仅服务端适用 |
-| 含义 | 管理节点在正常运行状态下,检查负载均衡的时间间隔 |
-| 单位 | 秒 |
-| 取值范围 | 1-30000 |
-| 缺省值 | 300 |
-
-### minTablesPerVnode
-
-| 属性 | 说明 |
-| -------- | --------------------------------- |
-| 适用范围 | 仅服务端适用 |
-| 含义 | 每个 vnode 中必须创建的最小表个数 |
-| 缺省值 | 1000 |
-
-### tableIncStepPerVnode
-
-| 属性 | 说明 |
-| -------- | ----------------------------------- |
-| 适用范围 | 仅服务端适用 |
-| 含义 | 每个 vnode 中超过最小表数后递增步长 |
-| 缺省值 | 1000 |
-
-### mqttHostName
-
-| 属性 | 说明 |
-| -------- | -------------------------------------------- |
-| 适用范围 | 仅服务端适用 |
-| 含义 | mqtt uri |
-| 缺省值 | |
-| 补充说明 | mqtt://username:password@hostname:1883/taos/ |
-
-### mqttPort
-
-| 属性 | 说明 |
-| -------- | ---------------- |
-| 适用范围 | 仅服务端适用 |
-| 含义 | mqtt client name |
-| 缺省值 | |
-| 补充说明 | 1883 |
-
-### mqttTopic
-
-| 属性 | 说明 |
-| -------- | ------------ |
-| 适用范围 | 仅服务端适用 |
-| 含义 | |
-| 缺省值 | |
-| 补充说明 | /test |
-
-### mqtt
-
-| 属性 | 说明 |
-| -------- | --------------------------------------- |
-| 适用范围 | 仅服务端适用 |
-| 含义 | 服务器内部的 mqtt 服务开关。 |
-| 取值范围 | 0:关闭 mqtt 服务, 1:激活 mqtt 服务。 |
-| 缺省值 | 0 |
-
-### telegrafUseFieldNum
-
-| 属性 | 说明 |
-| -------- | ---- |
-| 适用范围 | |
-| 含义 | |
-| 缺省值 | |
-
-### gitinfo
-
-| 属性 | 说明 |
-| -------- | -------------------- |
-| 适用范围 | 服务端和客户端均适用 |
-| 含义 | |
-| 取值范围 | 1 |
-| 缺省值 | |
-
-### gitinfoofInternal
-
-| 属性 | 说明 |
-| -------- | -------------------- |
-| 适用范围 | 服务端和客户端均适用 |
-| 含义 | |
-| 取值范围 | 2 |
-| 缺省值 | |
-
-### Buildinfo
-
-| 属性 | 说明 |
-| -------- | -------------------- |
-| 适用范围 | 服务端和客户端均适用 |
-| 含义 | |
-| 取值范围 | 3 |
-| 缺省值 | |
-
-### version
-
-| 属性 | 说明 |
-| -------- | -------------------- |
-| 适用范围 | 服务端和客户端均适用 |
-| 含义 | |
-| 取值范围 | 4 |
-| 缺省值 | |
-
-### numOfCommitThreads
-
-| 属性 | 说明 |
-| -------- | ---------------------- |
-| 适用范围 | 仅服务端适用 |
-| 含义 | 设置写入线程的最大数量 |
-| 缺省值 | |
-
## 仅客户端适用
### maxSQLLength
@@ -1013,7 +1079,11 @@ taosd -C
| 含义 | Taos shell 中 binary 和 nchar 字段的显示宽度上限,超过此限制的部分将被隐藏 |
| 取值范围 | 5 - |
| 缺省值 | 30 |
-| 补充说明 | 实际上限按以下规则计算:如果字段值的长度大于 maxBinaryDisplayWidth,则显示上限为 **字段名长度** 和 **maxBinaryDisplayWidth** 的较大者。
否则,上限为 **字段名长度** 和 **字段值长度** 的较大者。
可在 shell 中通过命令 set max_binary_display_width nn 动态修改此选项 |
+
+:::info
+实际上限按以下规则计算:如果字段值的长度大于 maxBinaryDisplayWidth,则显示上限为 **字段名长度** 和 **maxBinaryDisplayWidth** 的较大者。
否则,上限为 **字段名长度** 和 **字段值长度** 的较大者。
可在 shell 中通过命令 set max_binary_display_width nn 动态修改此选项
+
+:::
### maxWildCardsLength
@@ -1025,14 +1095,6 @@ taosd -C
| 缺省值 | 100 |
| 补充说明 | 2.1.6.1 版本新增。 |
-### tsdbMetaCompactRatio
-
-| 属性 | 说明 |
-| -------- | -------------------------------------------------------------- |
-| 含义 | tsdb meta 文件中冗余数据超过多少阈值,开启 meta 文件的压缩功能 |
-| 取值范围 | 0:不开启,[1-100]:冗余数据比例 |
-| 缺省值 | 0 |
-
### clientMerge
| 属性 | 说明 |
@@ -1053,42 +1115,12 @@ taosd -C
## 其他
-### queryBufferSize
-
-| 属性 | 说明 |
-| -------- | ------------------------------------------------------------------------------------------------------------------- |
-| 适用范围 | 仅服务端适用 |
-| 含义 | 为所有并发查询占用保留的内存大小。 |
-| 单位 | MB |
-| 缺省值 | |
-| 补充说明 | 计算规则可以根据实际应用可能的最大并发数和表的数字相乘,再乘 170 。
(2.0.15 以前的版本中,此参数的单位是字节) |
-
-### ratioOfQueryCores
-
-| 属性 | 说明 |
-| -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --- |
-| 适用范围 | 仅服务端适用 |
-| 含义 | 设置查询线程的最大数量。 |
-| 缺省值 | |
-| 补充说明 | 最小值 0 表示只有 1 个查询线程
最大值 2 表示最大建立 2 倍 CPU 核数的查询线程。
默认为 1,表示最大和 CPU 核数相等的查询线程。
该值可以为小数,即 0.5 表示最大建立 CPU 核数一半的查询线程。 | |
-
-### rpcForceTcp
-
-| 属性 | 说明 |
-| -------- | --------------------------------------------------- |
-| 适用范围 | 服务端和客户端均适用 |
-| 含义 | 强制使用 TCP 传输 |
-| 取值范围 | 0: 不开启 1: 开启 |
-| 缺省值 | 0 |
-| 补充说明 | 在网络比较差的环境中,建议开启。
2.0 版本新增。 |
-
-### maxNumOfDistinctRes
-
-| 属性 | 说明 |
-| -------- | -------------------------------- |
-| 适用范围 | 仅服务端适用 |
-| 含义 | 允许返回的 distinct 结果最大行数 |
-| 取值范围 | 默认值为 10 万,最大值 1 亿 |
-| 缺省值 | 10 万 |
-| 补充说明 | 2.3 版本新增。 |
+### enableCoreFile
+| 属性 | 说明 |
+| -------- | ------------------------------------------------------------------------------------------------------------------------------------------ |
+| 适用范围 | 服务端和客户端均适用 |
+| 含义 | 是否开启服务 crash 时生成 core 文件 |
+| 取值范围 | 0:否,1:是 |
+| 缺省值 | 1 |
+| 补充说明 | 不同的启动方式,生成 core 文件的目录如下:1、systemctl start taosd 启动:生成的 core 在根目录下
2、手动启动,就在 taosd 执行目录下。 |
\ No newline at end of file
diff --git a/docs-cn/17-train-fqa/04-direcotry.md b/docs-cn/14-reference/12-directory.md
similarity index 69%
rename from docs-cn/17-train-fqa/04-direcotry.md
rename to docs-cn/14-reference/12-directory.md
index c2746de1c1dd98f9ffa715680d4a1048cd3e8c02..df2a6536ee1faf9ef9a041a453ecd3d3375483f6 100644
--- a/docs-cn/17-train-fqa/04-direcotry.md
+++ b/docs-cn/14-reference/12-directory.md
@@ -1,11 +1,12 @@
-# 文件目录结构
+---
+title: 文件目录结构
+---
安装 TDengine 后,默认会在操作系统中生成下列目录或文件:
| 目录/文件 | 说明 |
| ------------------------- | -------------------------------------------------------------------- |
| /usr/local/taos/bin | TDengine 可执行文件目录。其中的执行文件都会软链接到/usr/bin 目录下。 |
-| /usr/local/taos/connector | TDengine 各种连接器目录。 |
| /usr/local/taos/driver | TDengine 动态链接库目录。会软链接到/usr/lib 目录下。 |
| /usr/local/taos/examples | TDengine 各种语言应用示例目录。 |
| /usr/local/taos/include | TDengine 对外提供的 C 语言接口的头文件。 |
@@ -21,7 +22,13 @@ TDengine 的所有可执行文件默认存放在 _/usr/local/taos/bin_ 目录下
- _taos_:TDengine Shell 可执行文件
- _taosdump_:数据导入导出工具
- _taosBenchmark_:TDengine 测试工具
-- remove.sh:卸载 TDengine 的脚本,请谨慎执行,链接到/usr/bin 目录下的**rmtaos**命令。会删除 TDengine 的安装目录/usr/local/taos,但会保留/etc/taos、/var/lib/taos、/var/log/taos。
+- _remove.sh_:卸载 TDengine 的脚本,请谨慎执行,链接到/usr/bin 目录下的**rmtaos**命令。会删除 TDengine 的安装目录/usr/local/taos,但会保留/etc/taos、/var/lib/taos、/var/log/taos
+- _taosadapter_: 提供 RESTful 服务和接受其他多种软件写入请求的服务端可执行文件
+- _tarbitrator_: 提供双节点集群部署的仲裁功能
+- _run_taosd_and_taosadapter.sh_:同时启动 taosd 和 taosAdapter 的脚本
+- _TDinsight.sh_:用于下载 TDinsight 并安装的脚本
+- _set_core.sh_:用于方便调试设置系统生成 core dump 文件的脚本
+- _taosd-dump-cfg.gdb_:用于方便调试 taosd 的 gdb 执行脚本。
:::note
2.4.0.0 版本之后的 taosBenchmark 和 taosdump 需要安装独立安装包 taosTools。
diff --git a/docs-cn/14-reference/13-schemaless/13-schemaless.md b/docs-cn/14-reference/13-schemaless/13-schemaless.md
index 9e74d5ac4d040fbb84650e2e65350b36716dee5e..7b34b97ce06626bda91919f31e4691125df0defa 100644
--- a/docs-cn/14-reference/13-schemaless/13-schemaless.md
+++ b/docs-cn/14-reference/13-schemaless/13-schemaless.md
@@ -1,4 +1,6 @@
-# Schemaless 写入
+---
+title: Schemaless 写入
+---
## 前言
@@ -6,7 +8,6 @@
从 2.2.0.0 版本开始,提供调用 Schemaless 写入方式,可以免于预先创建超级表/子表的步骤,随着数据写入接口能够自动创建与数据对应的存储结构。并且在必要时,Schemaless
将自动增加必要的数据列,保证用户写入的数据可以被正确存储。
-
无模式写入方式建立的超级表及其对应的子表与通过 SQL 直接建立的超级表和子表完全没有区别,你也可以通过,SQL 语句直接向其中写入数据。需要注意的是,通过无模式写入方式建立的表,其表名是基于标签值按照固定的映射规则生成,所以无法明确地进行表意,缺乏可读性。
## 无模式写入行协议
@@ -68,7 +69,7 @@ st,t1=3,t2=4,t3=t3 c1=3i64,c3="passit",c2=false,c4=4f64 1626006833639000000
"measurement,tag_key1=tag_value1,tag_key2=tag_value2"
```
-需要注意的是,这里的 tag*key1, tag_key2 并不是用户输入的标签的原始顺序,而是使用了标签名称按照字符串升序排列后的结果。所以,tag_key1 并不是在行协议中输入的第一个标签。
+需要注意的是,这里的 tag_key1, tag_key2 并不是用户输入的标签的原始顺序,而是使用了标签名称按照字符串升序排列后的结果。所以,tag_key1 并不是在行协议中输入的第一个标签。
排列完成以后计算该字符串的 MD5 散列值 "md5_val"。然后将计算的结果与字符串组合生成表名:“t_md5_val”。其中的 “t*” 是固定的前缀,每个通过该映射关系自动生成的表都具有该前缀。
2. 如果解析行协议获得的超级表不存在,则会创建这个超级表。
@@ -80,9 +81,10 @@ st,t1=3,t2=4,t3=t3 c1=3i64,c3="passit",c2=false,c4=4f64 1626006833639000000
7. 如果指定的数据子表已经存在,而且本次指定的标签列取值跟已保存的值不一样,那么最新的数据行中的值会覆盖旧的标签列取值。
8. 整个处理过程中遇到的错误会中断写入过程,并返回错误代码。
-:::Tip
+:::tip
无模式所有的处理逻辑,仍会遵循 TDengine 对数据结构的底层限制,例如每行数据的总长度不能超过
-16k 字节。这方面的具体限制约束请参见 [TAOS SQL 边界限制](https://www.taosdata.com/cn/documentation/taos-sql#limitation)
+16k 字节。这方面的具体限制约束请参见 [TAOS SQL 边界限制](/taos-sql/limit)
+
:::
## 时间分辨率识别
@@ -161,4 +163,4 @@ TDengine 提供数据写入的幂等性保证,即您可以反复调用 API 进
如果是无模式写入过程中的数据本身错误,应用会得到 TSDB_CODE_TSC_LINE_SYNTAX_ERROR
错误信息,该错误信息表明错误发生在写入文本中。其他的错误码与原系统一致,可以通过
-taos_errstr 获取具体的错误原因。
\ No newline at end of file
+taos_errstr 获取具体的错误原因。
diff --git a/docs-cn/14-reference/_category_.yml b/docs-cn/14-reference/_category_.yml
index 9381de6f82b806cb79e17e983c984de1c761fb18..f8031c35755f5912110136e8fdf3b176ddf5d6b0 100644
--- a/docs-cn/14-reference/_category_.yml
+++ b/docs-cn/14-reference/_category_.yml
@@ -1,3 +1,4 @@
label: 参考指南
link:
+ slug: /reference/
type: generated-index
\ No newline at end of file
diff --git a/docs-cn/14-reference/_collectd.mdx b/docs-cn/14-reference/_collectd.mdx
new file mode 100644
index 0000000000000000000000000000000000000000..1853769bf926a081a80cdf72b8e822e58cefb1e9
--- /dev/null
+++ b/docs-cn/14-reference/_collectd.mdx
@@ -0,0 +1,85 @@
+### 配置 taosAdapter
+
+配置 taosAdapter 接收 collectd 数据的方法:
+
+- 在 taosAdapter 配置文件(默认位置为 /etc/taos/taosadapter.toml)中使能配置项
+
+```
+...
+[opentsdb_telnet]
+enable = true
+maxTCPConnections = 250
+tcpKeepAlive = false
+dbs = ["opentsdb_telnet", "collectd", "icinga2", "tcollector"]
+ports = [6046, 6047, 6048, 6049]
+user = "root"
+password = "taosdata"
+...
+```
+
+其中 taosAdapter 默认写入的数据库名称为 `collectd`,也可以修改 taosAdapter 配置文件 dbs 项来指定不同的名称。user 和 password 填写实际 TDengine 配置的值。修改过配置文件 taosAdapter 需重新启动。
+
+- 也可以使用 taosAdapter 命令行参数或设置环境变量启动的方式,使能 taosAdapter 接收 collectd 数据功能,具体细节请参考 [taosAdapter 的使用手册](/reference/taosadapter)
+
+### 配置 collectd
+#
+collectd 使用插件机制可以以多种形式将采集到的监控数据写入到不同的数据存储软件。TDengine 支持直接采集插件和 write_tsdb 插件。
+
+#### 配置接收直接采集插件数据
+
+修改 collectd 配置文件(默认位置 /etc/collectd/collectd.conf)相关配置项。
+
+```text
+LoadPlugin network
+
+ Server "" ""
+
+```
+
+其中 填写运行 taosAdapter 的服务器域名或 IP 地址。 填写 taosAdapter 用于接收 collectd 数据的端口(默认为 6045)。
+
+实例如下:
+
+```text
+LoadPlugin network
+
+ Server "127.0.0.1" "6045"
+
+```
+
+#### 配置 write_tsdb 插件数据
+
+修改 collectd 配置文件(默认位置 /etc/collectd/collectd.conf)相关配置项。
+
+```text
+LoadPlugin write_tsdb
+
+
+ Host ""
+ Port ""
+ ...
+
+
+```
+
+其中 填写运行 taosAdapter 的服务器域名或 IP 地址。 填写 taosAdapter 用于接收 collectd write_tsdb 插件的数据(默认为 6047)。
+
+```text
+LoadPlugin write_tsdb
+
+
+ Host "127.0.0.1"
+ Port "6047"
+ HostTags "status=production"
+ StoreRates false
+ AlwaysAppendDS false
+
+
+```
+
+然后重启 collectd:
+
+```
+systemctl restart collectd
+```
+
diff --git a/docs-cn/14-reference/_icinga2.mdx b/docs-cn/14-reference/_icinga2.mdx
new file mode 100644
index 0000000000000000000000000000000000000000..0ed5023f953a6d879cc553def3aa0eaa9098afd5
--- /dev/null
+++ b/docs-cn/14-reference/_icinga2.mdx
@@ -0,0 +1,44 @@
+### 配置 taosAdapter
+
+配置 taosAdapter 接收 icinga2 数据的方法:
+
+- 在 taosAdapter 配置文件(默认位置 /etc/taos/taosadapter.toml)中使能配置项
+
+```
+...
+[opentsdb_telnet]
+enable = true
+maxTCPConnections = 250
+tcpKeepAlive = false
+dbs = ["opentsdb_telnet", "collectd", "icinga2", "tcollector"]
+ports = [6046, 6047, 6048, 6049]
+user = "root"
+password = "taosdata"
+...
+```
+
+其中 taosAdapter 默认写入的数据库名称为 `icinga2`,也可以修改 taosAdapter 配置文件 dbs 项来指定不同的名称。user 和 password 填写实际 TDengine 配置的值。修改过 taosAdapter 需重新启动。
+
+- 也可以使用 taosAdapter 命令行参数或设置环境变量启动的方式,使能 taosAdapter 接收 icinga2 数据功能,具体细节请参考 [taosAdapter 的使用手册](/reference/taosadapter)
+
+### 配置 icinga2
+
+- 使能 icinga2 的 opentsdb-writer(参考链接 https://icinga.com/docs/icinga-2/latest/doc/14-features/#opentsdb-writer)
+- 修改配置文件 `/etc/icinga2/features-enabled/opentsdb.conf` 填写 为运行 taosAdapter 的服务器的域名或 IP 地址, 填写 taosAdapter 支持接收 icinga2 数据的相应端口(默认为 6048)
+
+```
+object OpenTsdbWriter "opentsdb" {
+ host = ""
+ port =
+}
+```
+
+实例文件:
+
+```
+object OpenTsdbWriter "opentsdb" {
+ host = "127.0.0.1"
+ port = 6048
+}
+```
+
diff --git a/docs-cn/14-reference/_prometheus.mdx b/docs-cn/14-reference/_prometheus.mdx
new file mode 100644
index 0000000000000000000000000000000000000000..be73d95cbc001727ee1ea60759f37e0a836643c2
--- /dev/null
+++ b/docs-cn/14-reference/_prometheus.mdx
@@ -0,0 +1,31 @@
+配置 Prometheus 是通过编辑 Prometheus 配置文件 prometheus.yml (默认位置 /etc/prometheus/prometheus.yml)完成的。
+
+### 配置第三方数据库地址
+
+将其中的 remote_read url 和 remote_write url 指向运行 taosAdapter 服务的服务器域名或 IP 地址,REST 服务端口(taosAdapter 默认使用 6041),以及希望写入 TDengine 的数据库名称,并确保相应的 URL 形式如下:
+
+- remote_read url : `http://:/prometheus/v1/remote_read/`
+- remote_write url : `http://:/prometheus/v1/remote_write/`
+
+### 配置 Basic 验证
+
+- username:
+- password:
+
+### prometheus.yml 文件中 remote_write 和 remote_read 相关部分配置示例
+
+```yaml
+remote_write:
+ - url: "http://localhost:6041/prometheus/v1/remote_write/prometheus_data"
+ basic_auth:
+ username: root
+ password: taosdata
+
+remote_read:
+ - url: "http://localhost:6041/prometheus/v1/remote_read/prometheus_data"
+ basic_auth:
+ username: root
+ password: taosdata
+ remote_timeout: 10s
+ read_recent: true
+```
diff --git a/docs-cn/14-reference/_statsd.mdx b/docs-cn/14-reference/_statsd.mdx
new file mode 100644
index 0000000000000000000000000000000000000000..b225c44267d7ae32e3845972f683f664e11e9cae
--- /dev/null
+++ b/docs-cn/14-reference/_statsd.mdx
@@ -0,0 +1,55 @@
+### 配置 taosAdapter
+
+配置 taosAdapter 接收 StatsD 数据的方法:
+
+- 在 taosAdapter 配置文件(默认位置 /etc/taos/taosadapter.toml)中使能配置项
+
+```
+...
+[statsd]
+enable = true
+port = 6044
+db = "statsd"
+user = "root"
+password = "taosdata"
+worker = 10
+gatherInterval = "5s"
+protocol = "udp"
+maxTCPConnections = 250
+tcpKeepAlive = false
+allowPendingMessages = 50000
+deleteCounters = true
+deleteGauges = true
+deleteSets = true
+deleteTimings = true
+...
+```
+
+其中 taosAdapter 默认写入的数据库名称为 `statsd`,也可以修改 taosAdapter 配置文件 db 项来指定不同的名称。user 和 password 填写实际 TDengine 配置的值。修改过配置文件 taosAdapter 需重新启动。
+
+- 也可以使用 taosAdapter 命令行参数或设置环境变量启动的方式,使能 taosAdapter 接收 StatsD 数据功能,具体细节请参考 [taosAdapter 的使用手册](/reference/taosadapter)
+
+### 配置 StatsD
+
+使用 StatsD 需要下载其[源代码](https://github.com/statsd/statsd)。其配置文件请参考其源代码下载到本地的根目录下的示例文件 `exampleConfig.js` 进行修改。其中 填写运行 taosAdapter 的服务器域名或 IP 地址,请填写 taosAdapter 接收 StatsD 数据的端口(默认为 6044)。
+
+```
+backends 部分添加 "./backends/repeater"
+repeater 部分添加 { host:'', port: }
+```
+
+示例配置文件:
+
+```
+{
+port: 8125
+, backends: ["./backends/repeater"]
+, repeater: [{ host: '127.0.0.1', port: 6044}]
+}
+```
+
+增加如下内容后启动 StatsD(假设配置文件修改为 config.js)。
+
+```
+node stats.js config.js &
+```
diff --git a/docs-cn/14-reference/_tcollector.mdx b/docs-cn/14-reference/_tcollector.mdx
new file mode 100644
index 0000000000000000000000000000000000000000..8e51975b512d658e27a53b469d981e1c85a871dc
--- /dev/null
+++ b/docs-cn/14-reference/_tcollector.mdx
@@ -0,0 +1,82 @@
+
+### 配置 taosAdapter
+
+配置 taosAdapter 接收 TCollector 数据的方法:
+
+- 在 taosAdapter 配置文件(默认位置 /etc/taos/taosadapter.toml)中使能配置项
+
+```
+...
+[opentsdb_telnet]
+enable = true
+maxTCPConnections = 250
+tcpKeepAlive = false
+dbs = ["opentsdb_telnet", "collectd", "icinga2", "tcollector"]
+ports = [6046, 6047, 6048, 6049]
+user = "root"
+password = "taosdata"
+...
+```
+
+其中 taosAdapter 默认写入的数据库名称为 `tcollector`,也可以修改 taosAdapter 配置文件 dbs 项来指定不同的名称。user 和 password 填写实际 TDengine 配置的值。修改过配置文件 taosAdapter 需重新启动。
+
+- 也可以使用 taosAdapter 命令行参数或设置环境变量启动的方式,使能 taosAdapter 接收 tcollector 数据功能,具体细节请参考 [taosAdapter 的使用手册](/reference/taosadapter)
+
+### 配置 TCollector
+
+使用 TCollector 需下载其[源代码](https://github.com/OpenTSDB/tcollector)。其配置项在其源代码中。注意:TCollector 各个版本区别较大,这里仅以当前 master 分支最新代码 (git commit: 37ae920) 为例。
+
+修改 `collectors/etc/config.py` 和 `tcollector.py` 两个文件中相应内容。将原指向 OpenTSDB 宿主机的地址修改为 taosAdapter 被部署的服务器域名或 IP 地址,修改端口为 taosAdapter 支持 TCollector 使用的相应端口(默认为 6049)。
+
+示例为源代码修改内容的 git diff 输出:
+
+```
+index e7e7a1c..ec3e23c 100644
+--- a/collectors/etc/config.py
++++ b/collectors/etc/config.py
+@@ -59,13 +59,13 @@ def get_defaults():
+ 'http_password': False,
+ 'reconnectinterval': 0,
+ 'http_username': False,
+- 'port': 4242,
++ 'port': 6049,
+ 'pidfile': '/var/run/tcollector.pid',
+ 'http': False,
+ 'http_api_path': "api/put",
+ 'tags': [],
+ 'remove_inactive_collectors': False,
+- 'host': '',
++ 'host': '127.0.0.1',
+ 'logfile': '/var/log/tcollector.log',
+ 'cdir': default_cdir,
+ 'ssl': False,
+diff --git a/tcollector.py b/tcollector.py
+index 21f9b23..4c71ba2 100755
+--- a/tcollector.py
++++ b/tcollector.py
+@@ -64,7 +64,7 @@ ALIVE = True
+ # exceptions, something is not right and tcollector will shutdown.
+ # Hopefully some kind of supervising daemon will then restart it.
+ MAX_UNCAUGHT_EXCEPTIONS = 100
+-DEFAULT_PORT = 4242
++DEFAULT_PORT = 6049
+ MAX_REASONABLE_TIMESTAMP = 2209212000 # Good until Tue 3 Jan 14:00:00 GMT 2040
+ # How long to wait for datapoints before assuming
+ # a collector is dead and restarting it
+@@ -943,13 +943,13 @@ def parse_cmdline(argv):
+ 'http_password': False,
+ 'reconnectinterval': 0,
+ 'http_username': False,
+- 'port': 4242,
++ 'port': 6049,
+ 'pidfile': '/var/run/tcollector.pid',
+ 'http': False,
+ 'http_api_path': "api/put",
+ 'tags': [],
+ 'remove_inactive_collectors': False,
+- 'host': '',
++ 'host': '127.0.0.1',
+ 'logfile': '/var/log/tcollector.log',
+ 'cdir': default_cdir,
+ 'ssl': False,
+```
diff --git a/docs-cn/14-reference/_telegraf.mdx b/docs-cn/14-reference/_telegraf.mdx
new file mode 100644
index 0000000000000000000000000000000000000000..bae46d66062ad7d5bfc2487900c02bd7a19ce4f6
--- /dev/null
+++ b/docs-cn/14-reference/_telegraf.mdx
@@ -0,0 +1,27 @@
+
+在 Telegraf 配置文件(默认位置 /etc/telegraf/telegraf.conf) 增加 outputs.http 输出模块配置:
+
+```
+[[outputs.http]]
+ url = "http://:/influxdb/v1/write?db="
+ ...
+ username = ""
+ password = ""
+ ...
+```
+
+其中 请填写运行 taosAdapter 服务的服务器域名或 IP 地址, 请填写 REST 服务的端口(默认为 6041), 和 请填写当前运行的 TDengine 实际配置, 请填写希望在 TDengine 保存 Telegraf 数据的数据库名。
+
+示例如下:
+
+```
+[[outputs.http]]
+ url = "http://127.0.0.1:6041/influxdb/v1/write?db=telegraf"
+ method = "POST"
+ timeout = "5s"
+ username = "root"
+ password = "taosdata"
+ data_format = "influx"
+ influx_max_line_bytes = 250
+```
+
diff --git a/docs-cn/14-reference/taosAdapter-architecture.png b/docs-cn/14-reference/taosAdapter-architecture.png
new file mode 100644
index 0000000000000000000000000000000000000000..08a9018553aae6f86b42d127b372d0cecfa9bdf8
Binary files /dev/null and b/docs-cn/14-reference/taosAdapter-architecture.png differ
diff --git a/docs-cn/16-iot-bigdata/_category_.yml b/docs-cn/16-iot-bigdata/_category_.yml
deleted file mode 100644
index 400c7656a3749cfd5ced4b8921f683c4a0054459..0000000000000000000000000000000000000000
--- a/docs-cn/16-iot-bigdata/_category_.yml
+++ /dev/null
@@ -1,3 +0,0 @@
-label: 物联网大数据
-link:
- type: generated-index
\ No newline at end of file
diff --git a/docs-cn/17-train-fqa/01-faq.md b/docs-cn/17-train-fqa/01-faq.md
deleted file mode 100644
index 27ba469415211f05639b0f70a13cffa67ac8bd51..0000000000000000000000000000000000000000
--- a/docs-cn/17-train-fqa/01-faq.md
+++ /dev/null
@@ -1,222 +0,0 @@
-# 常见问题及反馈
-
-## 问题反馈
-
-如果 FAQ 中的信息不能够帮到您,需要 TDengine 技术团队的技术支持与协助,请将以下两个目录中内容打包:
-
-1. /var/log/taos (如果没有修改过默认路径)
-2. /etc/taos
-
-附上必要的问题描述,包括使用的 TDengine 版本信息、平台环境信息、发生该问题的执行操作、出现问题的表征及大概的时间,在 [GitHub](https://github.com/taosdata/TDengine) 提交 issue。
-
-为了保证有足够的 debug 信息,如果问题能够重复,请修改/etc/taos/taos.cfg 文件,最后面添加一行“debugFlag 135"(不带引号本身),然后重启 taosd, 重复问题,然后再递交。也可以通过如下 SQL 语句,临时设置 taosd 的日志级别。
-
-```
- alter dnode debugFlag 135;
-```
-
-但系统正常运行时,请一定将 debugFlag 设置为 131,否则会产生大量的日志信息,降低系统效率。
-
-## 常见问题列表
-
-**1. TDengine2.0 之前的版本升级到 2.0 及以上的版本应该注意什么?☆☆☆**
-
-2.0 版在之前版本的基础上,进行了完全的重构,配置文件和数据文件是不兼容的。在升级之前务必进行如下操作:
-
-1. 删除配置文件,执行 `sudo rm -rf /etc/taos/taos.cfg`
-2. 删除日志文件,执行 `sudo rm -rf /var/log/taos/`
-3. 确保数据已经不再需要的前提下,删除数据文件,执行 `sudo rm -rf /var/lib/taos/`
-4. 安装最新稳定版本的 TDengine
-5. 如果需要迁移数据或者数据文件损坏,请联系涛思数据官方技术支持团队,进行协助解决
-
-**2. Windows 平台下 JDBCDriver 找不到动态链接库,怎么办?**
-
-请看为此问题撰写的[技术博客](https://www.taosdata.com/blog/2019/12/03/950.html)。
-
-**3. 创建数据表时提示 more dnodes are needed**
-
-请看为此问题撰写的[技术博客](https://www.taosdata.com/blog/2019/12/03/965.html)。
-
-**4. 如何让 TDengine crash 时生成 core 文件?**
-
-请看为此问题撰写的[技术博客](https://www.taosdata.com/blog/2019/12/06/974.html)。
-
-**5. 遇到错误“Unable to establish connection”, 我怎么办?**
-
-客户端遇到连接故障,请按照下面的步骤进行检查:
-
-1. 检查网络环境
-
- - 云服务器:检查云服务器的安全组是否打开 TCP/UDP 端口 6030-6042 的访问权限
- - 本地虚拟机:检查网络能否 ping 通,尽量避免使用`localhost` 作为 hostname
- - 公司服务器:如果为 NAT 网络环境,请务必检查服务器能否将消息返回值客户端
-
-2. 确保客户端与服务端版本号是完全一致的,开源社区版和企业版也不能混用
-
-3. 在服务器,执行 `systemctl status taosd` 检查*taosd*运行状态。如果没有运行,启动*taosd*
-
-4. 确认客户端连接时指定了正确的服务器 FQDN (Fully Qualified Domain Name —— 可在服务器上执行 Linux 命令 hostname -f 获得),FQDN 配置参考:[一篇文章说清楚 TDengine 的 FQDN](https://www.taosdata.com/blog/2020/09/11/1824.html)。
-
-5. ping 服务器 FQDN,如果没有反应,请检查你的网络,DNS 设置,或客户端所在计算机的系统 hosts 文件。如果部署的是 TDengine 集群,客户端需要能 ping 通所有集群节点的 FQDN。
-
-6. 检查防火墙设置(Ubuntu 使用 ufw status,CentOS 使用 firewall-cmd --list-port),确认 TCP/UDP 端口 6030-6042 是打开的
-
-7. 对于 Linux 上的 JDBC(ODBC, Python, Go 等接口类似)连接, 确保*libtaos.so*在目录*/usr/local/taos/driver*里, 并且*/usr/local/taos/driver*在系统库函数搜索路径*LD_LIBRARY_PATH*里
-
-8. 对于 Windows 上的 JDBC, ODBC, Python, Go 等连接,确保*C:\TDengine\driver\taos.dll*在你的系统库函数搜索目录里 (建议*taos.dll*放在目录 _C:\Windows\System32_)
-
-9. 如果仍不能排除连接故障
-
- - Linux 系统请使用命令行工具 nc 来分别判断指定端口的 TCP 和 UDP 连接是否通畅
- 检查 UDP 端口连接是否工作:`nc -vuz {hostIP} {port} `
- 检查服务器侧 TCP 端口连接是否工作:`nc -l {port}`
- 检查客户端侧 TCP 端口连接是否工作:`nc {hostIP} {port}`
-
- - Windows 系统请使用 PowerShell 命令 Net-TestConnection -ComputerName {fqdn} -Port {port} 检测服务段端口是否访问
-
-10. 也可以使用 taos 程序内嵌的网络连通检测功能,来验证服务器和客户端之间指定的端口连接是否通畅(包括 TCP 和 UDP):[TDengine 内嵌网络检测工具使用指南](https://www.taosdata.com/blog/2020/09/08/1816.html)。
-
-**6. 遇到错误“Unexpected generic error in RPC”或者“Unable to resolve FQDN”,我怎么办?**
-
-产生这个错误,是由于客户端或数据节点无法解析 FQDN(Fully Qualified Domain Name)导致。对于 TAOS Shell 或客户端应用,请做如下检查:
-
-1. 请检查连接的服务器的 FQDN 是否正确,FQDN 配置参考:[一篇文章说清楚 TDengine 的 FQDN](https://www.taosdata.com/blog/2020/09/11/1824.html)
-2. 如果网络配置有 DNS server,请检查是否正常工作
-3. 如果网络没有配置 DNS server,请检查客户端所在机器的 hosts 文件,查看该 FQDN 是否配置,并是否有正确的 IP 地址
-4. 如果网络配置 OK,从客户端所在机器,你需要能 Ping 该连接的 FQDN,否则客户端是无法连接服务器的
-5. 如果服务器曾经使用过 TDengine,且更改过 hostname,建议检查 data 目录的 dnodeEps.json 是否符合当前配置的 EP,路径默认为/var/lib/taos/dnode。正常情况下,建议更换新的数据目录或者备份后删除以前的数据目录,这样可以避免该问题。
-6. 检查/etc/hosts 和/etc/hostname 是否是预配置的 FQDN
-
-**7. 虽然语法正确,为什么我还是得到 "Invalid SQL" 错误**
-
-如果你确认语法正确,2.0 之前版本,请检查 SQL 语句长度是否超过 64K。如果超过,也会返回这个错误。
-
-**8. 是否支持 validation queries?**
-
-TDengine 还没有一组专用的 validation queries。然而建议你使用系统监测的数据库”log"来做。
-
-
-
-**9. 我可以删除或更新一条记录吗?**
-
-TDengine 目前尚不支持删除功能,未来根据用户需求可能会支持。
-
-从 2.0.8.0 开始,TDengine 支持更新已经写入数据的功能。使用更新功能需要在创建数据库时使用 UPDATE 1 参数,之后可以使用 INSERT INTO 命令更新已经写入的相同时间戳数据。UPDATE 参数不支持 ALTER DATABASE 命令修改。没有使用 UPDATE 1 参数创建的数据库,写入相同时间戳的数据不会修改之前的数据,也不会报错。
-
-另需注意,在 UPDATE 设置为 0 时,后发送的相同时间戳的数据会被直接丢弃,但并不会报错,而且仍然会被计入 affected rows (所以不能利用 INSERT 指令的返回信息进行时间戳查重)。这样设计的主要原因是,TDengine 把写入的数据看做一个数据流,无论时间戳是否出现冲突,TDengine 都认为产生数据的原始设备真实地产生了这样的数据。UPDATE 参数只是控制这样的流数据在进行持久化时要怎样处理——UPDATE 为 0 时,表示先写入的数据覆盖后写入的数据;而 UPDATE 为 1 时,表示后写入的数据覆盖先写入的数据。这种覆盖关系如何选择,取决于对数据的后续使用和统计中,希望以先还是后生成的数据为准。
-
-此外,从 2.1.7.0 版本开始,支持将 UPDATE 参数设为 2,表示“支持部分列更新”。也即,当 UPDATE 设为 1 时,如果更新一个数据行,其中某些列没有提供取值,那么这些列会被设为 NULL;而当 UPDATE 设为 2 时,如果更新一个数据行,其中某些列没有提供取值,那么这些列会保持原有数据行中的对应值。
-
-**10. 我怎么创建超过 1024 列的表?**
-
-使用 2.0 及其以上版本,默认支持 1024 列;2.0 之前的版本,TDengine 最大允许创建 250 列的表。但是如果确实超过限值,建议按照数据特性,逻辑地将这个宽表分解成几个小表。(从 2.1.7.0 版本开始,表的最大列数增加到了 4096 列。)
-
-**11. 最有效的写入数据的方法是什么?**
-
-批量插入。每条写入语句可以一张表同时插入多条记录,也可以同时插入多张表的多条记录。
-
-**12. Windows 系统下插入的 nchar 类数据中的汉字被解析成了乱码如何解决?**
-
-Windows 下插入 nchar 类的数据中如果有中文,请先确认系统的地区设置成了中国(在 Control Panel 里可以设置),这时 cmd 中的`taos`客户端应该已经可以正常工作了;如果是在 IDE 里开发 Java 应用,比如 Eclipse, Intellij,请确认 IDE 里的文件编码为 GBK(这是 Java 默认的编码类型),然后在生成 Connection 时,初始化客户端的配置,具体语句如下:
-
-```JAVA
-Class.forName("com.taosdata.jdbc.TSDBDriver");
-Properties properties = new Properties();
-properties.setProperty(TSDBDriver.LOCALE_KEY, "UTF-8");
-Connection = DriverManager.getConnection(url, properties);
-```
-
-**13.JDBC 报错: the excuted SQL is not a DML or a DDL?**
-
-请更新至最新的 JDBC 驱动
-
-```xml
-
- com.taosdata.jdbc
- taos-jdbcdriver
- 2.0.27
-
-```
-
-**14. taos connect failed, reason: invalid timestamp**
-
-常见原因是服务器和客户端时间没有校准,可以通过和时间服务器同步的方式(Linux 下使用 ntpdate 命令,Windows 在系统时间设置中选择自动同步)校准。
-
-**15. 表名显示不全**
-
-由于 taos shell 在终端中显示宽度有限,有可能比较长的表名显示不全,如果按照显示的不全的表名进行相关操作会发生 Table does not exist 错误。解决方法可以是通过修改 taos.cfg 文件中的设置项 maxBinaryDisplayWidth, 或者直接输入命令 set max_binary_display_width 100。或者在命令结尾使用 \G 参数来调整结果的显示方式。
-
-**16. 如何进行数据迁移?**
-
-TDengine 是根据 hostname 唯一标志一台机器的,在数据文件从机器 A 移动机器 B 时,注意如下两件事:
-
-- 2.0.0.0 至 2.0.6.x 的版本,重新配置机器 B 的 hostname 为机器 A 的 hostname。
-- 2.0.7.0 及以后的版本,到/var/lib/taos/dnode 下,修复 dnodeEps.json 的 dnodeId 对应的 FQDN,重启。确保机器内所有机器的此文件是完全相同的。
-- 1.x 和 2.x 版本的存储结构不兼容,需要使用迁移工具或者自己开发应用导出导入数据。
-
-**17. 如何在命令行程序 taos 中临时调整日志级别**
-
-为了调试方便,从 2.0.16 版本开始,命令行程序 taos 新增了与日志记录相关的两条指令:
-
-```mysql
-ALTER LOCAL flag_name flag_value;
-```
-
-其含义是,在当前的命令行程序下,修改一个特定模块的日志记录级别(只对当前命令行程序有效,如果 taos 命令行程序重启,则需要重新设置):
-
-- flag_name 的取值可以是:debugFlag,cDebugFlag,tmrDebugFlag,uDebugFlag,rpcDebugFlag
-- flag_value 的取值可以是:131(输出错误和警告日志),135( 输出错误、警告和调试日志),143( 输出错误、警告、调试和跟踪日志)
-
-```mysql
-ALTER LOCAL RESETLOG;
-```
-
-其含义是,清空本机所有由客户端生成的日志文件。
-
-
-
-**18. 时间戳的时区信息是怎样处理的?**
-
-TDengine 中时间戳的时区总是由客户端进行处理,而与服务端无关。具体来说,客户端会对 SQL 语句中的时间戳进行时区转换,转为 UTC 时区(即 Unix 时间戳——Unix Timestamp)再交由服务端进行写入和查询;在读取数据时,服务端也是采用 UTC 时区提供原始数据,客户端收到后再根据本地设置,把时间戳转换为本地系统所要求的时区进行显示。
-
-客户端在处理时间戳字符串时,会采取如下逻辑:
-
-1. 在未做特殊设置的情况下,客户端默认使用所在操作系统的时区设置。
-2. 如果在 taos.cfg 中设置了 timezone 参数,则客户端会以这个配置文件中的设置为准。
-3. 如果在 C/C++/Java/Python 等各种编程语言的 Connector Driver 中,在建立数据库连接时显式指定了 timezone,那么会以这个指定的时区设置为准。例如 Java Connector 的 JDBC URL 中就有 timezone 参数。
-4. 在书写 SQL 语句时,也可以直接使用 Unix 时间戳(例如 `1554984068000`)或带有时区的时间戳字符串,也即以 RFC 3339 格式(例如 `2013-04-12T15:52:01.123+08:00`)或 ISO-8601 格式(例如 `2013-04-12T15:52:01.123+0800`)来书写时间戳,此时这些时间戳的取值将不再受其他时区设置的影响。
-
-
-
-**19. TDengine 都会用到哪些网络端口?**
-
-在 TDengine 2.0 版本中,会用到以下这些网络端口(以默认端口 6030 为前提进行说明,如果修改了配置文件中的设置,那么这里列举的端口都会出现变化),管理员可以参考这里的信息调整防火墙设置:
-
-| 协议 | 默认端口 | 用途说明 | 修改方法 |
-| :--- | :-------- | :---------------------------------- | :--------------------------------------------------------------------------------------------------------------------------------- |
-| TCP | 6030 | 客户端与服务端之间通讯。 | 由配置文件设置 serverPort 决定。 |
-| TCP | 6035 | 多节点集群的节点间通讯。 | 随 serverPort 端口变化。 |
-| TCP | 6040 | 多节点集群的节点间数据同步。 | 随 serverPort 端口变化。 |
-| TCP | 6041 | 客户端与服务端之间的 RESTful 通讯。 | 随 serverPort 端口变化。注意 taosAdapter 配置或有不同,请参考相应[文档](https://www.taosdata.com/cn/documentation/tools/adapter)。 |
-| TCP | 6042 | Arbitrator 的服务端口。 | 随 Arbitrator 启动参数设置变化。 |
-| TCP | 6043 | TaosKeeper 监控服务端口。 | 随 TaosKeeper 启动参数设置变化。 |
-| TCP | 6044 | 支持 StatsD 的数据接入端口。 | 随 taosAdapter 启动参数设置变化(2.3.0.1+以上版本)。 |
-| TCP | 6045 | 支持 collectd 数据接入端口。 | 随 taosAdapter 启动参数设置变化(2.3.0.1+以上版本)。 |
-| TCP | 6060 | 企业版内 Monitor 服务的网络端口。 | |
-| UDP | 6030-6034 | 客户端与服务端之间通讯。 | 随 serverPort 端口变化。 |
-| UDP | 6035-6039 | 多节点集群的节点间通讯。 | 随 serverPort 端口变化。 |
-
-**20. go 语言编写组件编译失败怎样解决?**
-
-新版本 TDengine 2.3.0.0 包含一个使用 go 语言开发的 taosAdapter 独立组件,需要单独运行,取代之前 taosd 内置的 httpd ,提供包含原 httpd 功能以及支持多种其他软件(Prometheus、Telegraf、collectd、StatsD 等)的数据接入功能。
-使用最新 develop 分支代码编译需要先 `git submodule update --init --recursive` 下载 taosAdapter 仓库代码后再编译。
-
-目前编译方式默认自动编译 taosAdapter。go 语言版本要求 1.14 以上,如果发生 go 编译错误,往往是国内访问 go mod 问题,可以通过设置 go 环境变量来解决:
-
-```sh
-go env -w GO111MODULE=on
-go env -w GOPROXY=https://goproxy.cn,direct
-```
-
-如果希望继续使用之前的内置 httpd,可以关闭 taosAdapter 编译,使用
-`cmake .. -DBUILD_HTTP=true` 使用原来内置的 httpd。
diff --git a/docs-cn/09-third-party/01-grafana.mdx b/docs-cn/20-third-party/01-grafana.mdx
similarity index 86%
rename from docs-cn/09-third-party/01-grafana.mdx
rename to docs-cn/20-third-party/01-grafana.mdx
index c34c617010daf92225f5e086355ec5d822c39d51..569cd750475447c9c6d107949c99b9405867916e 100644
--- a/docs-cn/09-third-party/01-grafana.mdx
+++ b/docs-cn/20-third-party/01-grafana.mdx
@@ -1,10 +1,9 @@
---
sidebar_label: Grafana
+title: Grafana
---
-# Grafana
-
-TDengine 能够与开源数据可视化系统 [Grafana](https://www.grafana.com/) 快速集成搭建数据监测报警系统,整个过程无需任何代码开发,TDengine 中数据表中内容可以在仪表盘(DashBoard)上进行可视化展现。关于 TDengine 插件的使用您可以在[GitHub](https://github.com/taosdata/grafanaplugin/blob/master/README.md)中了解更多。
+TDengine 能够与开源数据可视化系统 [Grafana](https://www.grafana.com/) 快速集成搭建数据监测报警系统,整个过程无需任何代码开发,TDengine 中数据表的内容可以在仪表盘(DashBoard)上进行可视化展现。关于 TDengine 插件的使用您可以在[GitHub](https://github.com/taosdata/grafanaplugin/blob/master/README.md)中了解更多。
## 安装 Grafana
@@ -12,20 +11,20 @@ TDengine 能够与开源数据可视化系统 [Grafana](https://www.grafana.com/
## 配置 Grafana
-TDengine 的 Grafana 插件托管在 GitHub,可从 下载,当前最新版本为 3.1.3。
+TDengine 的 Grafana 插件托管在 GitHub,可从 下载,当前最新版本为 3.1.4。
推荐使用 [`grafana-cli` 命令行工具](https://grafana.com/docs/grafana/latest/administration/cli/) 进行插件安装。
```bash
sudo -u grafana grafana-cli \
- --pluginUrl https://github.com/taosdata/grafanaplugin/releases/download/v3.1.3/tdengine-datasource-3.1.3.zip \
+ --pluginUrl https://github.com/taosdata/grafanaplugin/releases/download/v3.1.4/tdengine-datasource-3.1.4.zip \
plugins install tdengine-datasource
```
或者下载到本地并解压到 Grafana 插件目录。
```bash
-GF_VERSION=3.1.3
+GF_VERSION=3.1.4
wget https://github.com/taosdata/grafanaplugin/releases/download/v$GF_VERSION/tdengine-datasource-$GF_VERSION.zip
```
@@ -45,7 +44,7 @@ allow_loading_unsigned_plugins = tdengine-datasource
在 Docker 环境下,可以使用如下的环境变量设置自动安装并设置 TDengine 插件:
```bash
-GF_INSTALL_PLUGINS=https://github.com/taosdata/grafanaplugin/releases/download/v3.1.3/tdengine-datasource-3.1.3.zip;tdengine-datasource
+GF_INSTALL_PLUGINS=https://github.com/taosdata/grafanaplugin/releases/download/v3.1.4/tdengine-datasource-3.1.4.zip;tdengine-datasource
GF_PLUGINS_ALLOW_LOADING_UNSIGNED_PLUGINS=tdengine-datasource
```
@@ -65,7 +64,7 @@ GF_PLUGINS_ALLOW_LOADING_UNSIGNED_PLUGINS=tdengine-datasource

-- Host: TDengine 集群的中任意一台服务器的 IP 地址与 TDengine RESTful 接口的端口号(6041),默认 http://localhost:6041。注意:从 2.4 版本开始 RESTful 服务默认使用独立组件 taosAdapter 提供,请参考相关文档配置部署。
+- Host: TDengine 集群中提供 REST 服务 (在 2.4 之前由 taosd 提供, 从 2.4 开始由 taosAdapter 提供)的组件所在服务器的 IP 地址与 TDengine REST 服务的端口号(6041),默认 http://localhost:6041。
- User:TDengine 用户名。
- Password:TDengine 用户密码。
@@ -93,4 +92,4 @@ GF_PLUGINS_ALLOW_LOADING_UNSIGNED_PLUGINS=tdengine-datasource
### 导入 Dashboard
-在 2.3.3.0 及以上版本,您可以导入 TDinsight Dashboard (Grafana Dashboard ID: [15167](https://grafana.com/grafana/dashboards/15167)) 作为 TDengine 集群的监控可视化工具。安装和使用说明请见 [TDinsight 用户手册](https://www.taosdata.com/cn/documentation/tools/insight)。
+在 2.3.3.0 及以上版本,您可以导入 TDinsight Dashboard (Grafana Dashboard ID: [15167](https://grafana.com/grafana/dashboards/15167)) 作为 TDengine 集群的监控可视化工具。安装和使用说明请见 [TDinsight 用户手册](/reference/tdinsight/)。
diff --git a/docs-cn/20-third-party/02-prometheus.md b/docs-cn/20-third-party/02-prometheus.md
new file mode 100644
index 0000000000000000000000000000000000000000..0fe534b8df263064e5269e1732b69893efd7a79a
--- /dev/null
+++ b/docs-cn/20-third-party/02-prometheus.md
@@ -0,0 +1,89 @@
+---
+sidebar_label: Prometheus
+title: Prometheus
+---
+
+import Prometheus from "../14-reference/_prometheus.mdx"
+
+Prometheus 是一款流行的开源监控告警系统。Prometheus 于2016年加入了 Cloud Native Computing Foundation (云原生云计算基金会,简称 CNCF),成为继 Kubernetes 之后的第二个托管项目,该项目拥有非常活跃的开发人员和用户社区。
+
+Prometheus 提供了 `remote_write` 和 `remote_read` 接口来利用其它数据库产品作为它的存储引擎。为了让 Prometheus 生态圈的用户能够利用 TDengine 的高效写入和查询,TDengine 也提供了对这两个接口的支持。
+
+通过适当的配置, Prometheus 的数据可以通过 `remote_write` 接口存储到 TDengine 中,也可以通过 `remote_read` 接口来查询存储在 TDengine 中的数据,充分利用 TDengine 对时序数据的高效存储查询性能和集群处理能力。
+
+## 前置条件
+
+要将 Prometheus 数据写入 TDengine 需要以下几方面的准备工作。
+- TDengine 集群已经部署并正常运行
+- taosAdapter 已经安装并正常运行。具体细节请参考 [taosAdapter 的使用手册](/reference/taosadapter)
+- Prometheus 已经安装。安装 Prometheus 请参考[官方文档](https://prometheus.io/docs/prometheus/latest/installation/)
+
+## 配置步骤
+
+
+## 验证方法
+
+重启 Prometheus 后可参考以下示例验证从 Prometheus 向 TDengine 写入数据并能够正确读出。
+
+### 使用 TDengine CLI 查询写入数据
+```
+taos> show databases;
+ name | created_time | ntables | vgroups | replica | quorum | days | keep | cache(MB) | blocks | minrows | maxrows | wallevel | fsync | comp | cachelast | precision | update | status |
+====================================================================================================================================================================================================================================================================================
+ test | 2022-04-12 08:07:58.756 | 1 | 1 | 1 | 1 | 10 | 3650 | 16 | 6 | 100 | 4096 | 1 | 3000 | 2 | 0 | ms | 0 | ready |
+ log | 2022-04-20 07:19:50.260 | 2 | 1 | 1 | 1 | 10 | 3650 | 16 | 6 | 100 | 4096 | 1 | 3000 | 2 | 0 | ms | 0 | ready |
+ prometheus_data | 2022-04-20 07:21:09.202 | 158 | 1 | 1 | 1 | 10 | 3650 | 16 | 6 | 100 | 4096 | 1 | 3000 | 2 | 0 | ns | 2 | ready |
+ db | 2022-04-15 06:37:08.512 | 1 | 1 | 1 | 1 | 10 | 3650 | 16 | 6 | 100 | 4096 | 1 | 3000 | 2 | 0 | ms | 0 | ready |
+Query OK, 4 row(s) in set (0.000585s)
+
+taos> use prometheus_data;
+Database changed.
+
+taos> show stables;
+ name | created_time | columns | tags | tables |
+============================================================================================
+ metrics | 2022-04-20 07:21:09.209 | 2 | 1 | 1389 |
+Query OK, 1 row(s) in set (0.000487s)
+
+taos> select * from metrics limit 10;
+ ts | value | labels |
+=============================================================================================
+ 2022-04-20 07:21:09.193000000 | 0.000024996 | {"__name__":"go_gc_duration... |
+ 2022-04-20 07:21:14.193000000 | 0.000024996 | {"__name__":"go_gc_duration... |
+ 2022-04-20 07:21:19.193000000 | 0.000024996 | {"__name__":"go_gc_duration... |
+ 2022-04-20 07:21:24.193000000 | 0.000024996 | {"__name__":"go_gc_duration... |
+ 2022-04-20 07:21:29.193000000 | 0.000024996 | {"__name__":"go_gc_duration... |
+ 2022-04-20 07:21:09.193000000 | 0.000054249 | {"__name__":"go_gc_duration... |
+ 2022-04-20 07:21:14.193000000 | 0.000054249 | {"__name__":"go_gc_duration... |
+ 2022-04-20 07:21:19.193000000 | 0.000054249 | {"__name__":"go_gc_duration... |
+ 2022-04-20 07:21:24.193000000 | 0.000054249 | {"__name__":"go_gc_duration... |
+ 2022-04-20 07:21:29.193000000 | 0.000054249 | {"__name__":"go_gc_duration... |
+Query OK, 10 row(s) in set (0.011146s)
+```
+
+### 使用 promql-cli 通过 remote_read 从 TDengine 读取数据
+
+安装 promql-cli
+
+```
+ go install github.com/nalbury/promql-cli@latest
+```
+
+在 TDengine 和 taosAdapter 服务运行状态对 Prometheus 数据进行查询
+
+```
+ubuntu@shuduo-1804 ~ $ promql-cli --host "http://127.0.0.1:9090" "sum(up) by (job)"
+JOB VALUE TIMESTAMP
+prometheus 1 2022-04-20T08:05:26Z
+node 1 2022-04-20T08:05:26Z
+```
+
+暂停 taosAdapter 服务后对 Prometheus 数据进行查询
+
+```
+ubuntu@shuduo-1804 ~ $ sudo systemctl stop taosadapter.service
+ubuntu@shuduo-1804 ~ $ promql-cli --host "http://127.0.0.1:9090" "sum(up) by (job)"
+VALUE TIMESTAMP
+
+```
+
diff --git a/docs-cn/20-third-party/03-telegraf.md b/docs-cn/20-third-party/03-telegraf.md
new file mode 100644
index 0000000000000000000000000000000000000000..88a69211c0592940d7f75d34c03bcc0593cd74d6
--- /dev/null
+++ b/docs-cn/20-third-party/03-telegraf.md
@@ -0,0 +1,67 @@
+---
+sidebar_label: Telegraf
+title: Telegraf 写入
+---
+
+import Telegraf from "../14-reference/_telegraf.mdx"
+
+Telegraf 是一款十分流行的指标采集开源软件。在数据采集和平台监控系统中,Telegraf 可以采集多种组件的运行信息,而不需要自己手写脚本定时采集,降低数据获取的难度。
+
+只需要将 Telegraf 的输出配置增加指向 taosAdapter 对应的 url 并修改若干配置项即可将 Telegraf 的数据写入到 TDengine 中。将 Telegraf 的数据存在到 TDengine 中可以充分利用 TDengine 对时序数据的高效存储查询性能和集群处理能力。
+
+## 前置条件
+
+要将 Telegraf 数据写入 TDengine 需要以下几方面的准备工作。
+- TDengine 集群已经部署并正常运行
+- taosAdapter 已经安装并正常运行。具体细节请参考 [taosAdapter 的使用手册](/reference/taosadapter)
+- Telegraf 已经安装。安装 Telegraf 请参考[官方文档](https://docs.influxdata.com/telegraf/v1.22/install/)
+
+## 配置步骤
+
+
+## 验证方法
+
+重启 Telegraf 服务:
+
+```
+sudo systemctl restart telegraf
+```
+
+使用 TDengine CLI 验证从 Telegraf 向 TDengine 写入数据并能够正确读出:
+
+```
+taos> show databases;
+ name | created_time | ntables | vgroups | replica | quorum | days | keep | cache(MB) | blocks | minrows | maxrows | wallevel | fsync | comp | cachelast | precision | update | status |
+====================================================================================================================================================================================================================================================================================
+ telegraf | 2022-04-20 08:47:53.488 | 22 | 1 | 1 | 1 | 10 | 3650 | 16 | 6 | 100 | 4096 | 1 | 3000 | 2 | 0 | ns | 2 | ready |
+ log | 2022-04-20 07:19:50.260 | 9 | 1 | 1 | 1 | 10 | 3650 | 16 | 6 | 100 | 4096 | 1 | 3000 | 2 | 0 | ms | 0 | ready |
+Query OK, 2 row(s) in set (0.002401s)
+
+taos> use telegraf;
+Database changed.
+
+taos> show stables;
+ name | created_time | columns | tags | tables |
+============================================================================================
+ swap | 2022-04-20 08:47:53.532 | 7 | 1 | 1 |
+ cpu | 2022-04-20 08:48:03.488 | 11 | 2 | 5 |
+ system | 2022-04-20 08:47:53.512 | 8 | 1 | 1 |
+ diskio | 2022-04-20 08:47:53.550 | 12 | 2 | 15 |
+ kernel | 2022-04-20 08:47:53.503 | 6 | 1 | 1 |
+ mem | 2022-04-20 08:47:53.521 | 35 | 1 | 1 |
+ processes | 2022-04-20 08:47:53.555 | 12 | 1 | 1 |
+ disk | 2022-04-20 08:47:53.541 | 8 | 5 | 2 |
+Query OK, 8 row(s) in set (0.000521s)
+
+taos> select * from telegraf.system limit 10;
+ ts | load1 | load5 | load15 | n_cpus | n_users | uptime | uptime_format | host
+|
+=============================================================================================================================================================================================================================================
+ 2022-04-20 08:47:50.000000000 | 0.000000000 | 0.050000000 | 0.070000000 | 4 | 1 | 5533 | 1:32 | shuduo-1804
+|
+ 2022-04-20 08:48:00.000000000 | 0.000000000 | 0.050000000 | 0.070000000 | 4 | 1 | 5543 | 1:32 | shuduo-1804
+|
+ 2022-04-20 08:48:10.000000000 | 0.000000000 | 0.040000000 | 0.070000000 | 4 | 1 | 5553 | 1:32 | shuduo-1804
+|
+Query OK, 3 row(s) in set (0.013269s)
+```
diff --git a/docs-cn/20-third-party/05-collectd.md b/docs-cn/20-third-party/05-collectd.md
new file mode 100644
index 0000000000000000000000000000000000000000..04892fd42e92e962fcccadf626f67c432e78d286
--- /dev/null
+++ b/docs-cn/20-third-party/05-collectd.md
@@ -0,0 +1,73 @@
+---
+sidebar_label: collectd
+title: collectd 写入
+---
+
+import CollectD from "../14-reference/_collectd.mdx"
+
+collectd 是一个用来收集系统性能的守护进程。collectd 提供各种存储方式来存储不同值的机制。它会在系统运行和存储信息时周期性的统计系统的相关统计信息。利用这些信息有助于查找当前系统性能瓶颈和预测系统未来的负载等。
+
+只需要将 collectd 的配置指向运行 taosAdapter 的服务器域名(或 IP 地址)和相应端口即可将 collectd 采集的数据写入到 TDengine,可以充分利用 TDengine 对时序数据的高效存储查询性能和集群处理能力。
+
+## 前置条件
+
+要将 collectd 数据写入 TDengine,需要几方面的准备工作。
+- TDengine 集群已经部署并正常运行
+- taosAdapter 已经安装并正常运行,具体细节请参考[ taosAdapter 的使用手册](/reference/taosadapter)
+- collectd 已经安装。安装 collectd 请参考[官方文档](https://collectd.org/download.shtml)
+
+## 配置步骤
+
+
+## 验证方法
+
+重启 collectd
+
+```
+sudo systemctl restart collectd
+```
+
+使用 TDengine CLI 验证从 collectd 向 TDengine 写入数据并能够正确读出:
+
+```
+taos> show databases;
+ name | created_time | ntables | vgroups | replica | quorum | days | keep | cache(MB) | blocks | minrows | maxrows | wallevel | fsync | comp | cachelast | precision | update | status |
+====================================================================================================================================================================================================================================================================================
+ collectd | 2022-04-20 09:27:45.460 | 95 | 1 | 1 | 1 | 10 | 3650 | 16 | 6 | 100 | 4096 | 1 | 3000 | 2 | 0 | ns | 2 | ready |
+ log | 2022-04-20 07:19:50.260 | 11 | 1 | 1 | 1 | 10 | 3650 | 16 | 6 | 100 | 4096 | 1 | 3000 | 2 | 0 | ms | 0 | ready |
+Query OK, 2 row(s) in set (0.003266s)
+
+taos> use collectd;
+Database changed.
+
+taos> show stables;
+ name | created_time | columns | tags | tables |
+============================================================================================
+ load_1 | 2022-04-20 09:27:45.492 | 2 | 2 | 1 |
+ memory_value | 2022-04-20 09:27:45.463 | 2 | 3 | 6 |
+ df_value | 2022-04-20 09:27:45.463 | 2 | 4 | 25 |
+ load_2 | 2022-04-20 09:27:45.501 | 2 | 2 | 1 |
+ load_0 | 2022-04-20 09:27:45.485 | 2 | 2 | 1 |
+ interface_1 | 2022-04-20 09:27:45.488 | 2 | 3 | 12 |
+ irq_value | 2022-04-20 09:27:45.476 | 2 | 3 | 31 |
+ interface_0 | 2022-04-20 09:27:45.480 | 2 | 3 | 12 |
+ entropy_value | 2022-04-20 09:27:45.473 | 2 | 2 | 1 |
+ swap_value | 2022-04-20 09:27:45.477 | 2 | 3 | 5 |
+Query OK, 10 row(s) in set (0.002236s)
+
+taos> select * from collectd.memory_value limit 10;
+ ts | value | host | type_instance | type |
+=========================================================================================================================================================
+ 2022-04-20 09:27:45.459653462 | 54689792.000000000 | shuduo-1804 | buffered | memory |
+ 2022-04-20 09:27:55.453168283 | 57212928.000000000 | shuduo-1804 | buffered | memory |
+ 2022-04-20 09:28:05.453004291 | 57942016.000000000 | shuduo-1804 | buffered | memory |
+ 2022-04-20 09:27:45.459653462 | 6381330432.000000000 | shuduo-1804 | free | memory |
+ 2022-04-20 09:27:55.453168283 | 6357643264.000000000 | shuduo-1804 | free | memory |
+ 2022-04-20 09:28:05.453004291 | 6349987840.000000000 | shuduo-1804 | free | memory |
+ 2022-04-20 09:27:45.459653462 | 107040768.000000000 | shuduo-1804 | slab_recl | memory |
+ 2022-04-20 09:27:55.453168283 | 107536384.000000000 | shuduo-1804 | slab_recl | memory |
+ 2022-04-20 09:28:05.453004291 | 107634688.000000000 | shuduo-1804 | slab_recl | memory |
+ 2022-04-20 09:27:45.459653462 | 309137408.000000000 | shuduo-1804 | used | memory |
+Query OK, 10 row(s) in set (0.010348s)
+```
+
diff --git a/docs-cn/20-third-party/06-statsd.md b/docs-cn/20-third-party/06-statsd.md
new file mode 100644
index 0000000000000000000000000000000000000000..bcbd6c42ae5dd1c83be428797544d254e11a0238
--- /dev/null
+++ b/docs-cn/20-third-party/06-statsd.md
@@ -0,0 +1,68 @@
+---
+sidebar_label: StatsD
+title: StatsD 直接写入
+---
+
+import StatsD from "../14-reference/_statsd.mdx"
+
+StatsD 是汇总和总结应用指标的一个简单的守护进程,近些年来发展迅速,已经变成了一个用于收集应用性能指标的统一的协议。
+
+只需要在 StatsD 的配置文件中填写运行 taosAdapter 的服务器域名(或 IP 地址)和相应端口即可将 StatsD 的数据写入到 TDengine 中,可以充分利用 TDengine 对时序数据的高效存储查询性能和集群处理能力。
+
+## 前置条件
+
+要将 StatsD 数据写入 TDengine 需要以下几方面的准备工作。
+- TDengine 集群已经部署并正常运行
+- taosAdapter 已经安装并正常运行。具体细节请参考 [taosAdapter 的使用手册](/reference/taosadapter)
+- StatsD 已经安装。安装 StatsD 请参考[官方文档](https://github.com/statsd/statsd)
+
+## 配置步骤
+
+
+## 验证方法
+
+运行 StatsD:
+
+```
+$ node stats.js config.js &
+[1] 8546
+$ 20 Apr 09:54:41 - [8546] reading config file: exampleConfig.js
+20 Apr 09:54:41 - server is up INFO
+```
+
+使用 nc 写入测试数据:
+
+```
+$ echo "foo:1|c" | nc -u -w0 127.0.0.1 8125
+```
+
+使用 TDengine CLI 验证从 StatsD 向 TDengine 写入数据并能够正确读出:
+
+```
+Welcome to the TDengine shell from Linux, Client Version:2.4.0.0
+Copyright (c) 2020 by TAOS Data, Inc. All rights reserved.
+
+taos> show databases;
+ name | created_time | ntables | vgroups | replica | quorum | days | keep | cache(MB) | blocks | minrows | maxrows | wallevel | fsync | comp | cachelast | precision | update | status |
+====================================================================================================================================================================================================================================================================================
+ log | 2022-04-20 07:19:50.260 | 11 | 1 | 1 | 1 | 10 | 3650 | 16 | 6 | 100 | 4096 | 1 | 3000 | 2 | 0 | ms | 0 | ready |
+ statsd | 2022-04-20 09:54:51.220 | 1 | 1 | 1 | 1 | 10 | 3650 | 16 | 6 | 100 | 4096 | 1 | 3000 | 2 | 0 | ns | 2 | ready |
+Query OK, 2 row(s) in set (0.003142s)
+
+taos> use statsd;
+Database changed.
+
+taos> show stables;
+ name | created_time | columns | tags | tables |
+============================================================================================
+ foo | 2022-04-20 09:54:51.234 | 2 | 1 | 1 |
+Query OK, 1 row(s) in set (0.002161s)
+
+taos> select * from foo;
+ ts | value | metric_type |
+=======================================================================================
+ 2022-04-20 09:54:51.219614235 | 1 | counter |
+Query OK, 1 row(s) in set (0.004179s)
+
+taos>
+```
diff --git a/docs-cn/20-third-party/07-icinga2.md b/docs-cn/20-third-party/07-icinga2.md
new file mode 100644
index 0000000000000000000000000000000000000000..ed1f1404a730eca5f51e2ff9bbcd54949018f8ea
--- /dev/null
+++ b/docs-cn/20-third-party/07-icinga2.md
@@ -0,0 +1,74 @@
+---
+sidebar_label: icinga2
+title: icinga2 写入
+---
+
+import Icinga2 from "../14-reference/_icinga2.mdx"
+
+icinga2 是一款开源主机、网络监控软件,最初由 Nagios 网络监控应用发展而来。目前,icinga2 遵从 GNU GPL v2 许可协议发行。
+
+只需要将 icinga2 的配置修改指向 taosAdapter 对应的服务器和相应端口即可将 icinga2 采集的数据存在到 TDengine 中,可以充分利用 TDengine 对时序数据的高效存储查询性能和集群处理能力。
+
+## 前置条件
+
+要将 icinga2 数据写入 TDengine 需要以下几方面的准备工作。
+- TDengine 集群已经部署并正常运行
+- taosAdapter 已经安装并正常运行。具体细节请参考[ taosAdapter 的使用手册](/reference/taosadapter)
+- icinga2 已经安装。安装 icinga2 请参考[官方文档](https://icinga.com/docs/icinga-2/latest/doc/02-installation/)
+
+## 配置步骤
+
+
+## 验证方法
+
+重启 taosAdapter:
+```
+sudo systemctl restart taosadapter
+```
+
+重启 icinga2:
+
+```
+sudo systemctl restart icinga2
+```
+
+等待 10 秒左右后,使用 TDengine CLI 查询 TDengine 验证是否创建相应数据库并写入数据:
+
+```
+taos> show databases;
+ name | created_time | ntables | vgroups | replica | quorum | days | keep | cache(MB) | blocks | minrows | maxrows | wallevel | fsync | comp | cachelast | precision | update | status |
+====================================================================================================================================================================================================================================================================================
+ log | 2022-04-20 07:19:50.260 | 11 | 1 | 1 | 1 | 10 | 3650 | 16 | 6 | 100 | 4096 | 1 | 3000 | 2 | 0 | ms | 0 | ready |
+ icinga2 | 2022-04-20 12:11:39.697 | 13 | 1 | 1 | 1 | 10 | 3650 | 16 | 6 | 100 | 4096 | 1 | 3000 | 2 | 0 | ns | 2 | ready |
+Query OK, 2 row(s) in set (0.001867s)
+
+taos> use icinga2;
+Database changed.
+
+taos> show stables;
+ name | created_time | columns | tags | tables |
+============================================================================================
+ icinga.service.users.state_... | 2022-04-20 12:11:39.726 | 2 | 1 | 1 |
+ icinga.service.users.acknow... | 2022-04-20 12:11:39.756 | 2 | 1 | 1 |
+ icinga.service.procs.downti... | 2022-04-20 12:11:44.541 | 2 | 1 | 1 |
+ icinga.service.users.users | 2022-04-20 12:11:39.770 | 2 | 1 | 1 |
+ icinga.service.procs.procs_min | 2022-04-20 12:11:44.599 | 2 | 1 | 1 |
+ icinga.service.users.users_min | 2022-04-20 12:11:39.809 | 2 | 1 | 1 |
+ icinga.check.max_check_atte... | 2022-04-20 12:11:39.847 | 2 | 3 | 2 |
+ icinga.service.procs.state_... | 2022-04-20 12:11:44.522 | 2 | 1 | 1 |
+ icinga.service.procs.procs_... | 2022-04-20 12:11:44.576 | 2 | 1 | 1 |
+ icinga.service.users.users_... | 2022-04-20 12:11:39.796 | 2 | 1 | 1 |
+ icinga.check.latency | 2022-04-20 12:11:39.869 | 2 | 3 | 2 |
+ icinga.service.procs.procs_... | 2022-04-20 12:11:44.588 | 2 | 1 | 1 |
+ icinga.service.users.downti... | 2022-04-20 12:11:39.746 | 2 | 1 | 1 |
+ icinga.service.users.users_... | 2022-04-20 12:11:39.783 | 2 | 1 | 1 |
+ icinga.service.users.reachable | 2022-04-20 12:11:39.736 | 2 | 1 | 1 |
+ icinga.service.procs.procs | 2022-04-20 12:11:44.565 | 2 | 1 | 1 |
+ icinga.service.procs.acknow... | 2022-04-20 12:11:44.554 | 2 | 1 | 1 |
+ icinga.service.procs.state | 2022-04-20 12:11:44.509 | 2 | 1 | 1 |
+ icinga.service.procs.reachable | 2022-04-20 12:11:44.532 | 2 | 1 | 1 |
+ icinga.check.current_attempt | 2022-04-20 12:11:39.825 | 2 | 3 | 2 |
+ icinga.check.execution_time | 2022-04-20 12:11:39.898 | 2 | 3 | 2 |
+ icinga.service.users.state | 2022-04-20 12:11:39.704 | 2 | 1 | 1 |
+Query OK, 22 row(s) in set (0.002317s)
+```
diff --git a/docs-cn/20-third-party/08-tcollector.md b/docs-cn/20-third-party/08-tcollector.md
new file mode 100644
index 0000000000000000000000000000000000000000..5fbf001fa093f978dfdcd0f3f344a131d56ed9f9
--- /dev/null
+++ b/docs-cn/20-third-party/08-tcollector.md
@@ -0,0 +1,67 @@
+---
+sidebar_label: TCollector
+title: TCollector 写入
+---
+
+import Tcollector from "../14-reference/_tcollector.mdx"
+
+TCollector 是 openTSDB 的一部分,它用来采集客户端日志发送给数据库。
+
+只需要将 TCollector 的配置修改指向运行 taosAdapter 的服务器域名(或 IP 地址)和相应端口即可将 TCollector 采集的数据存在到 TDengine 中,可以充分利用 TDengine 对时序数据的高效存储查询性能和集群处理能力。
+
+## 前置条件
+
+要将 TCollector 数据写入 TDengine 需要以下几方面的准备工作。
+- TDengine 集群已经部署并正常运行
+- taosAdapter 已经安装并正常运行。具体细节请参考 [taosAdapter 的使用手册](/reference/taosadapter)
+- TCollector 已经安装。安装 TCollector 请参考[官方文档](http://opentsdb.net/docs/build/html/user_guide/utilities/tcollector.html#installation-of-tcollector)
+
+## 配置步骤
+
+
+## 验证方法
+
+重启 taosAdapter:
+
+```
+sudo systemctl restart taosadapter
+```
+
+手动执行 `sudo ./tcollector.py`
+
+等待数秒后使用 TDengine CLI 查询 TDengine 是否创建相应数据库并写入数据。
+
+```
+taos> show databases;
+ name | created_time | ntables | vgroups | replica | quorum | days | keep | cache(MB) | blocks | minrows | maxrows | wallevel | fsync | comp | cachelast | precision | update | status |
+====================================================================================================================================================================================================================================================================================
+ tcollector | 2022-04-20 12:44:49.604 | 88 | 1 | 1 | 1 | 10 | 3650 | 16 | 6 | 100 | 4096 | 1 | 3000 | 2 | 0 | ns | 2 | ready |
+ log | 2022-04-20 07:19:50.260 | 11 | 1 | 1 | 1 | 10 | 3650 | 16 | 6 | 100 | 4096 | 1 | 3000 | 2 | 0 | ms | 0 | ready |
+Query OK, 2 row(s) in set (0.002679s)
+
+taos> use tcollector;
+Database changed.
+
+taos> show stables;
+ name | created_time | columns | tags | tables |
+============================================================================================
+ proc.meminfo.hugepages_rsvd | 2022-04-20 12:44:53.945 | 2 | 1 | 1 |
+ proc.meminfo.directmap1g | 2022-04-20 12:44:54.110 | 2 | 1 | 1 |
+ proc.meminfo.vmallocchunk | 2022-04-20 12:44:53.724 | 2 | 1 | 1 |
+ proc.meminfo.hugepagesize | 2022-04-20 12:44:54.004 | 2 | 1 | 1 |
+ tcollector.reader.lines_dro... | 2022-04-20 12:44:49.675 | 2 | 1 | 1 |
+ proc.meminfo.sunreclaim | 2022-04-20 12:44:53.437 | 2 | 1 | 1 |
+ proc.stat.ctxt | 2022-04-20 12:44:55.363 | 2 | 1 | 1 |
+ proc.meminfo.swaptotal | 2022-04-20 12:44:53.158 | 2 | 1 | 1 |
+ proc.uptime.total | 2022-04-20 12:44:52.813 | 2 | 1 | 1 |
+ tcollector.collector.lines_... | 2022-04-20 12:44:49.895 | 2 | 2 | 51 |
+ proc.meminfo.vmallocused | 2022-04-20 12:44:53.704 | 2 | 1 | 1 |
+ proc.meminfo.memavailable | 2022-04-20 12:44:52.939 | 2 | 1 | 1 |
+ sys.numa.foreign_allocs | 2022-04-20 12:44:57.929 | 2 | 2 | 1 |
+ proc.meminfo.committed_as | 2022-04-20 12:44:53.639 | 2 | 1 | 1 |
+ proc.vmstat.pswpin | 2022-04-20 12:44:54.177 | 2 | 1 | 1 |
+ proc.meminfo.cmafree | 2022-04-20 12:44:53.865 | 2 | 1 | 1 |
+ proc.meminfo.mapped | 2022-04-20 12:44:53.349 | 2 | 1 | 1 |
+ proc.vmstat.pgmajfault | 2022-04-20 12:44:54.251 | 2 | 1 | 1 |
+...
+```
diff --git a/docs-cn/09-third-party/09-emq-broder.md b/docs-cn/20-third-party/09-emq-broder.md
similarity index 96%
rename from docs-cn/09-third-party/09-emq-broder.md
rename to docs-cn/20-third-party/09-emq-broder.md
index 0d2bd4d2f996247119bca736d295b7faf5d55e23..a661943088e2b478ff9940b6679a47c1bbb039ed 100644
--- a/docs-cn/09-third-party/09-emq-broder.md
+++ b/docs-cn/20-third-party/09-emq-broder.md
@@ -1,7 +1,6 @@
---
sidebar_label: EMQ Broker
+title: EMQ Broker 写入
---
-# EMQ Broker 写入
-
MQTT 是流行的物联网数据传输协议,[EMQ](https://github.com/emqx/emqx)是一开源的 MQTT Broker 软件,无需任何代码,只需要在 EMQ Dashboard 里使用“规则”做简单配置,即可将 MQTT 的数据直接写入 TDengine。EMQ X 支持通过 发送到 Web 服务的方式保存数据到 TDEngine,也在企业版上提供原生的 TDEngine 驱动实现直接保存。详细使用方法请参考 [EMQ 官方文档](https://docs.emqx.io/broker/latest/cn/rule/rule-example.html#%E4%BF%9D%E5%AD%98%E6%95%B0%E6%8D%AE%E5%88%B0-tdengine)。
diff --git a/docs-cn/09-third-party/10-hive-mq-broker.md b/docs-cn/20-third-party/10-hive-mq-broker.md
similarity index 95%
rename from docs-cn/09-third-party/10-hive-mq-broker.md
rename to docs-cn/20-third-party/10-hive-mq-broker.md
index 81657da1009c286ece906116abf33428868c1971..f75ed793d6272ae27f92676e2096ef455f638aa6 100644
--- a/docs-cn/09-third-party/10-hive-mq-broker.md
+++ b/docs-cn/20-third-party/10-hive-mq-broker.md
@@ -1,7 +1,6 @@
---
sidebar_label: HiveMQ Broker
+title: HiveMQ Broker 写入
---
-# HiveMQ Broker 写入
-
[HiveMQ](https://www.hivemq.com/) 是一个提供免费个人版和企业版的 MQTT 代理,主要用于企业和新兴的机器到机器 M2M 通讯和内部传输,满足可伸缩性、易管理和安全特性。HiveMQ 提供了开源的插件开发包。可以通过 HiveMQ extension - TDengine 保存数据到 TDengine。详细使用方法请参考 [HiveMQ extension - TDengine 说明文档](https://github.com/huskar-t/hivemq-tdengine-extension/blob/b62a26ecc164a310104df57691691b237e091c89/README.md)。
diff --git a/docs-cn/20-third-party/_category_.yml b/docs-cn/20-third-party/_category_.yml
new file mode 100644
index 0000000000000000000000000000000000000000..cf9d95e5f9e0941f64159ffa17619839fdafbf05
--- /dev/null
+++ b/docs-cn/20-third-party/_category_.yml
@@ -0,0 +1,6 @@
+label: 第三方工具
+link:
+ type: generated-index
+ slug: /third-party/
+ description: TDengine 通过对标准 SQL 命令、常用数据库连接器标准(例如 JDBC)、ORM 以及其他流行时序数据库写入协议(例如 InfluxDB Line Protocol、OpenTSDB JSON、OpenTSDB Telnet 等)的支持可以使 TDengine 非常容易和第三方工具共同使用。
+
diff --git a/docs-cn/20-third-party/_deploytaosadapter.mdx b/docs-cn/20-third-party/_deploytaosadapter.mdx
new file mode 100644
index 0000000000000000000000000000000000000000..ec40744c9a4620801e59aadd49996a0b6381f1bc
--- /dev/null
+++ b/docs-cn/20-third-party/_deploytaosadapter.mdx
@@ -0,0 +1,18 @@
+### 部署taosAdapter
+
+taosAdapter 可以和 TDengine 部署在同一个系统中,也可以分离部署。
+
+启动 taosAdapter:
+
+```
+systemctl start taosadapter
+```
+
+检查 taosAdapter 的运行状态:
+
+```
+systemctl status taosadapter
+```
+
+taosAdapter 详细的配置参数和使用请参考 `taosadapter --help` 命令输出以及 [参考文档](/reference/taosadapter) 。
+
diff --git a/docs-cn/13-tdinternal/01-arch.md b/docs-cn/21-tdinternal/01-arch.md
similarity index 55%
rename from docs-cn/13-tdinternal/01-arch.md
rename to docs-cn/21-tdinternal/01-arch.md
index f276a8e86ba52aa63a49b0c8f3022a3acb7f39ba..84f6d239dd9fb347a4850966d391cb0b629a7944 100644
--- a/docs-cn/13-tdinternal/01-arch.md
+++ b/docs-cn/21-tdinternal/01-arch.md
@@ -1,155 +1,8 @@
---
-sidebar_label: 数据模型和整体架构
+sidebar_label: 整体架构
+title: 整体架构
---
-# 数据模型和整体架构
-
-## 数据模型
-
-### 物联网典型场景
-
-在典型的物联网、车联网、运维监测场景中,往往有多种不同类型的数据采集设备,采集一个到多个不同的物理量。而同一种采集设备类型,往往又有多个具体的采集设备分布在不同的地点。大数据处理系统就是要将各种采集的数据汇总,然后进行计算和分析。对于同一类设备,其采集的数据都是很规则的。以智能电表为例,假设每个智能电表采集电流、电压、相位三个量,其采集的数据类似如下的表格:
-
-
-
- 设备ID |
- 时间戳 |
- 采集量 |
- 标签 |
-
-
-Device ID |
-Time Stamp |
-current |
-voltage |
-phase |
-location |
-groupId |
-
-
-
-
-d1001 |
-1538548685000 |
-10.3 |
-219 |
-0.31 |
-Beijing.Chaoyang |
-2 |
-
-
-d1002 |
-1538548684000 |
-10.2 |
-220 |
-0.23 |
-Beijing.Chaoyang |
-3 |
-
-
-d1003 |
-1538548686500 |
-11.5 |
-221 |
-0.35 |
-Beijing.Haidian |
-3 |
-
-
-d1004 |
-1538548685500 |
-13.4 |
-223 |
-0.29 |
-Beijing.Haidian |
-2 |
-
-
-d1001 |
-1538548695000 |
-12.6 |
-218 |
-0.33 |
-Beijing.Chaoyang |
-2 |
-
-
-d1004 |
-1538548696600 |
-11.8 |
-221 |
-0.28 |
-Beijing.Haidian |
-2 |
-
-
-d1002 |
-1538548696650 |
-10.3 |
-218 |
-0.25 |
-Beijing.Chaoyang |
-3 |
-
-
-d1001 |
-1538548696800 |
-12.3 |
-221 |
-0.31 |
-Beijing.Chaoyang |
-2 |
-
-
-
-
- 表 1:智能电表数据示例
-
-每一条记录都有设备 ID,时间戳,采集的物理量(如上图中的电流、电压、相位),还有与每个设备相关的静态标签(如上述表 1 中的位置 Location 和分组 groupId)。每个设备是受外界的触发,或按照设定的周期采集数据。采集的数据点是时序的,是一个数据流。
-
-### 数据特征
-
-除时序特征外,仔细研究发现,物联网、车联网、运维监测类数据还具有很多其他明显的特征:
-
-1. 数据高度结构化;
-2. 数据极少有更新或删除操作;
-3. 无需传统数据库的事务处理;
-4. 相对互联网应用,写多读少;
-5. 流量平稳,根据设备数量和采集频次,可以预测出来;
-6. 用户关注的是一段时间的趋势,而不是某一特定时间点的值;
-7. 数据有保留期限;
-8. 数据的查询分析一定是基于时间段和空间区域;
-9. 除存储、查询操作外,还需要各种统计和实时计算操作;
-10. 数据量巨大,一天可能采集的数据就可以超过 100 亿条。
-
-充分利用上述特征,TDengine 采取了经特殊优化的存储和计算设计来处理时序数据,它将系统处理能力显著提高,同时大幅降低了系统运维的复杂度。
-
-### 关系型数据库模型
-
-因为采集的数据一般是结构化数据,同时为降低学习门槛,TDengine 采用传统的关系型数据库模型管理数据。因此用户需要先创建库,然后创建表,之后才能插入或查询数据。TDengine 采用的是结构化存储,而不是 NoSQL 的 key-value 存储。
-
-### 一个数据采集点一张表
-
-为充分利用其数据的时序性和其他数据特点,TDengine 要求**对每个数据采集点单独建表**(比如有一千万个智能电表,就需创建一千万张表,上述表格中的 d1001, d1002, d1003, d1004 都需单独建表),用来存储这个采集点所采集的时序数据。这种设计有几大优点:
-
-1. 能保证一个采集点的数据在存储介质上是以块为单位连续存储的。如果读取一个时间段的数据,它能大幅减少随机读取操作,成数量级的提升读取和查询速度。
-2. 由于不同采集设备产生数据的过程完全独立,每个设备的数据源是唯一的,一张表也就只有一个写入者,这样就可采用无锁方式来写,写入速度就能大幅提升。
-3. 对于一个数据采集点而言,其产生的数据是时序的,因此写的操作可用追加的方式实现,进一步大幅提高数据写入速度。
-
-如果采用传统的方式,将多个设备的数据写入一张表,由于网络延时不可控,不同设备的数据到达服务器的时序是无法保证的,写入操作是要有锁保护的,而且一个设备的数据是难以保证连续存储在一起的。**采用一个数据采集点一张表的方式,能最大程度的保证单个数据采集点的插入和查询的性能是最优的。**
-
-TDengine 建议用数据采集点的名字(如上表中的 D1001)来做表名。每个数据采集点可能同时采集多个物理量(如上表中的 curent, voltage, phase),每个物理量对应一张表中的一列,数据类型可以是整型、浮点型、字符串等。除此之外,表的第一列必须是时间戳,即数据类型为 timestamp。对采集的数据,TDengine 将自动按照时间戳建立索引,但对采集的物理量不建任何索引。数据用列式存储方式保存。
-
-### 超级表:同一类型数据采集点的集合
-
-由于一个数据采集点一张表,导致表的数量巨增,难以管理,而且应用经常需要做采集点之间的聚合操作,聚合的操作也变得复杂起来。为解决这个问题,TDengine 引入超级表(Super Table,简称为 STable)的概念。
-
-超级表是指某一特定类型的数据采集点的集合。同一类型的数据采集点,其表的结构是完全一样的,但每个表(数据采集点)的静态属性(标签)是不一样的。描述一个超级表(某一特定类型的数据采集点的集合),除需要定义采集量的表结构之外,还需要定义其标签的 schema,标签的数据类型可以是整数、浮点数、字符串,标签可以有多个,可以事后增加、删除或修改。如果整个系统有 N 个不同类型的数据采集点,就需要建立 N 个超级表。
-
-在 TDengine 的设计里,**表用来代表一个具体的数据采集点,超级表用来代表一组相同类型的数据采集点集合**。当为某个具体数据采集点创建表时,用户使用超级表的定义做模板,同时指定该具体采集点(表)的标签值。与传统的关系型数据库相比,表(一个数据采集点)是带有静态标签的,而且这些标签可以事后增加、删除、修改。**一张超级表包含有多张表,这些表具有相同的时序数据 schema,但带有不同的标签值**。
-
-当对多个具有相同数据类型的数据采集点进行聚合操作时,TDengine 会先把满足标签过滤条件的表从超级表中找出来,然后再扫描这些表的时序数据,进行聚合操作,这样需要扫描的数据集会大幅减少,从而显著提高聚合计算的性能。
-
## 集群与基本逻辑单元
TDengine 的设计是基于单个硬件、软件系统不可靠,基于任何单台计算机都无法提供足够计算能力和存储能力处理海量数据的假设进行设计的。因此 TDengine 从研发的第一天起,就按照分布式高可靠架构进行设计,是支持水平扩展的,这样任何单台或多台服务器发生硬件故障或软件错误都不影响系统的可用性和可靠性。同时,通过节点虚拟化并辅以自动化负载均衡技术,TDengine 能最高效率地利用异构集群中的计算和存储资源降低硬件投资。
@@ -162,25 +15,25 @@ TDengine 分布式架构的逻辑结构图如下:
图 1 TDengine架构示意图
-一个完整的 TDengine 系统是运行在一到多个物理节点上的,逻辑上,它包含数据节点(dnode)、TDengine 应用驱动(taosc)以及应用(app)。系统中存在一到多个数据节点,这些数据节点组成一个集群(cluster)。应用通过 taosc 的 API 与 TDengine 集群进行互动。下面对每个逻辑单元进行简要介绍。
+一个完整的 TDengine 系统是运行在一到多个物理节点上的,逻辑上,它包含数据节点(dnode)、TDengine 应用驱动(taosc)以及应用(app)。系统中存在一到多个数据节点,这些数据节点组成一个集群(cluster)。应用通过 taosc 的 API 与 TDengine 集群进行互动。下面对每个逻辑单元进行简要介绍。
-**物理节点(pnode):** pnode 是一独立运行、拥有自己的计算、存储和网络能力的计算机,可以是安装有 OS 的物理机、虚拟机或 Docker 容器。物理节点由其配置的 FQDN (Fully Qualified Domain Name)来标识。TDengine 完全依赖 FQDN 来进行网络通讯,如果不了解 FQDN,请看博文[《一篇文章说清楚 TDengine 的 FQDN》](https://www.taosdata.com/blog/2020/09/11/1824.html)。
+**物理节点(pnode):** pnode 是一独立运行、拥有自己的计算、存储和网络能力的计算机,可以是安装有 OS 的物理机、虚拟机或 Docker 容器。物理节点由其配置的 FQDN(Fully Qualified Domain Name)来标识。TDengine 完全依赖 FQDN 来进行网络通讯,如果不了解 FQDN,请看博文[《一篇文章说清楚 TDengine 的 FQDN》](https://www.taosdata.com/blog/2020/09/11/1824.html)。
-**数据节点(dnode):** dnode 是 TDengine 服务器侧执行代码 taosd 在物理节点上的一个运行实例,一个工作的系统必须有至少一个数据节点。dnode 包含零到多个逻辑的虚拟节点(vnode),零或者至多一个逻辑的管理节点(mnode)。dnode 在系统中的唯一标识由实例的 End Point (EP)决定。EP 是 dnode 所在物理节点的 FQDN (Fully Qualified Domain Name)和系统所配置的网络端口号(Port)的组合。通过配置不同的端口,一个物理节点(一台物理机、虚拟机或容器)可以运行多个实例,或有多个数据节点。
+**数据节点(dnode):** dnode 是 TDengine 服务器侧执行代码 taosd 在物理节点上的一个运行实例,一个工作的系统必须有至少一个数据节点。dnode 包含零到多个逻辑的虚拟节点(vnode),零或者至多一个逻辑的管理节点(mnode)。dnode 在系统中的唯一标识由实例的 End Point(EP)决定。EP 是 dnode 所在物理节点的 FQDN(Fully Qualified Domain Name)和系统所配置的网络端口号(Port)的组合。通过配置不同的端口,一个物理节点(一台物理机、虚拟机或容器)可以运行多个实例,或有多个数据节点。
-**虚拟节点(vnode):** 为更好的支持数据分片、负载均衡,防止数据过热或倾斜,数据节点被虚拟化成多个虚拟节点(vnode,图中 V2, V3, V4 等)。每个 vnode 都是一个相对独立的工作单元,是时序数据存储的基本单元,具有独立的运行线程、内存空间与持久化存储的路径。一个 vnode 包含一定数量的表(数据采集点)。当创建一张新表时,系统会检查是否需要创建新的 vnode。一个数据节点上能创建的 vnode 的数量取决于该数据节点所在物理节点的硬件资源。一个 vnode 只属于一个 DB,但一个 DB 可以有多个 vnode。一个 vnode 除存储的时序数据外,也保存有所包含的表的 schema、标签值等。一个虚拟节点由所属的数据节点的 EP,以及所属的 VGroup ID 在系统内唯一标识,由管理节点创建并管理。
+**虚拟节点(vnode):** 为更好的支持数据分片、负载均衡,防止数据过热或倾斜,数据节点被虚拟化成多个虚拟节点(vnode,图中 V2,V3,V4 等)。每个 vnode 都是一个相对独立的工作单元,是时序数据存储的基本单元,具有独立的运行线程、内存空间与持久化存储的路径。一个 vnode 包含一定数量的表(数据采集点)。当创建一张新表时,系统会检查是否需要创建新的 vnode。一个数据节点上能创建的 vnode 的数量取决于该数据节点所在物理节点的硬件资源。一个 vnode 只属于一个 DB,但一个 DB 可以有多个 vnode。一个 vnode 除存储的时序数据外,也保存有所包含的表的 schema、标签值等。一个虚拟节点由所属的数据节点的 EP,以及所属的 VGroup ID 在系统内唯一标识,由管理节点创建并管理。
-**管理节点(mnode):** 一个虚拟的逻辑单元,负责所有数据节点运行状态的监控和维护,以及节点之间的负载均衡(图中 M)。同时,管理节点也负责元数据(包括用户、数据库、表、静态标签等)的存储和管理,因此也称为 Meta Node。TDengine 集群中可配置多个(开源版最多不超过 3 个) mnode,它们自动构建成为一个虚拟管理节点组(图中 M0, M1, M2)。mnode 间采用 master/slave 的机制进行管理,而且采取强一致方式进行数据同步, 任何数据更新操作只能在 Master 上进行。mnode 集群的创建由系统自动完成,无需人工干预。每个 dnode 上至多有一个 mnode,由所属的数据节点的 EP 来唯一标识。每个 dnode 通过内部消息交互自动获取整个集群中所有 mnode 所在的 dnode 的 EP。
+**管理节点(mnode):** 一个虚拟的逻辑单元,负责所有数据节点运行状态的监控和维护,以及节点之间的负载均衡(图中 M)。同时,管理节点也负责元数据(包括用户、数据库、表、静态标签等)的存储和管理,因此也称为 Meta Node。TDengine 集群中可配置多个(开源版最多不超过 3 个)mnode,它们自动构建成为一个虚拟管理节点组(图中 M0,M1,M2)。mnode 间采用 master/slave 的机制进行管理,而且采取强一致方式进行数据同步,任何数据更新操作只能在 Master 上进行。mnode 集群的创建由系统自动完成,无需人工干预。每个 dnode 上至多有一个 mnode,由所属的数据节点的 EP 来唯一标识。每个 dnode 通过内部消息交互自动获取整个集群中所有 mnode 所在的 dnode 的 EP。
-**虚拟节点组(VGroup):** 不同数据节点上的 vnode 可以组成一个虚拟节点组(vnode group)来保证系统的高可靠。虚拟节点组内采取 master/slave 的方式进行管理。写操作只能在 master vnode 上进行,系统采用异步复制的方式将数据同步到 slave vnode,这样确保了一份数据在多个物理节点上有拷贝。一个 vgroup 里虚拟节点个数就是数据的副本数。如果一个 DB 的副本数为 N,系统必须有至少 N 数据节点。副本数在创建 DB 时通过参数 replica 可以指定,缺省为 1。使用 TDengine 的多副本特性,可以不再需要昂贵的磁盘阵列等存储设备,就可以获得同样的数据高可靠性。虚拟节点组由管理节点创建、管理,并且由管理节点分配一个系统唯一的 ID,VGroup ID。如果两个虚拟节点的 vnode group ID 相同,说明他们属于同一个组,数据互为备份。虚拟节点组里虚拟节点的个数是可以动态改变的,容许只有一个,也就是没有数据复制。VGroup ID 是永远不变的,即使一个虚拟节点组被删除,它的 ID 也不会被收回重复利用。
+**虚拟节点组(VGroup):** 不同数据节点上的 vnode 可以组成一个虚拟节点组(vgroup)来保证系统的高可靠。虚拟节点组内采取 master/slave 的方式进行管理。写操作只能在 master vnode 上进行,系统采用异步复制的方式将数据同步到 slave vnode,这样确保了一份数据在多个物理节点上有拷贝。一个 vgroup 里虚拟节点个数就是数据的副本数。如果一个 DB 的副本数为 N,系统必须有至少 N 数据节点。副本数在创建 DB 时通过参数 replica 可以指定,缺省为 1。使用 TDengine 的多副本特性,可以不再需要昂贵的磁盘阵列等存储设备,就可以获得同样的数据高可靠性。虚拟节点组由管理节点创建、管理,并且由管理节点分配一个系统唯一的 ID,VGroup ID。如果两个虚拟节点的 VGroup ID 相同,说明他们属于同一个组,数据互为备份。虚拟节点组里虚拟节点的个数是可以动态改变的,容许只有一个,也就是没有数据复制。VGroup ID 是永远不变的,即使一个虚拟节点组被删除,它的 ID 也不会被收回重复利用。
-**TAOSC:** taosc 是 TDengine 给应用提供的驱动程序(driver),负责处理应用与集群的接口交互,提供 C/C++ 语言原生接口,内嵌于 JDBC、C#、Python、Go、Node.js 语言连接库里。应用都是通过 taosc 而不是直接连接集群中的数据节点与整个集群进行交互的。这个模块负责获取并缓存元数据;将插入、查询等请求转发到正确的数据节点;在把结果返回给应用时,还需要负责最后一级的聚合、排序、过滤等操作。对于 JDBC、C/C++、C#、Python、Go、Node.js 接口而言,这个模块是在应用所处的物理节点上运行。同时,为支持全分布式的 RESTful 接口,taosc 在 TDengine 集群的每个 dnode 上都有一运行实例。
+**Taosc** taosc 是 TDengine 给应用提供的驱动程序(driver),负责处理应用与集群的接口交互,提供 C/C++ 语言原生接口,内嵌于 JDBC、C#、Python、Go、Node.js 语言连接库里。应用都是通过 taosc 而不是直接连接集群中的数据节点与整个集群进行交互的。这个模块负责获取并缓存元数据;将插入、查询等请求转发到正确的数据节点;在把结果返回给应用时,还需要负责最后一级的聚合、排序、过滤等操作。对于 JDBC、C/C++、C#、Python、Go、Node.js 接口而言,这个模块是在应用所处的物理节点上运行。同时,为支持全分布式的 RESTful 接口,taosc 在 TDengine 集群的每个 dnode 上都有一运行实例。
### 节点之间的通讯
**通讯方式:**TDengine 系统的各个数据节点之间,以及应用驱动与各数据节点之间的通讯是通过 TCP/UDP 进行的。因为考虑到物联网场景,数据写入的包一般不大,因此 TDengine 除采用 TCP 做传输之外,还采用 UDP 方式,因为 UDP 更加高效,而且不受连接数的限制。TDengine 实现了自己的超时、重传、确认等机制,以确保 UDP 的可靠传输。对于数据量不到 15K 的数据包,采取 UDP 的方式进行传输,超过 15K 的,或者是查询类的操作,自动采取 TCP 的方式进行传输。同时,TDengine 根据配置和数据包,会自动对数据进行压缩/解压缩,数字签名/认证等处理。对于数据节点之间的数据复制,只采用 TCP 方式进行数据传输。
-**FQDN 配置:**一个数据节点有一个或多个 FQDN,可以在系统配置文件 taos.cfg 通过参数"fqdn"进行指定,如果没有指定,系统将自动获取计算机的 hostname 作为其 FQDN。如果节点没有配置 FQDN,可以直接将该节点的配置参数 fqdn 设置为它的 IP 地址。但不建议使用 IP,因为 IP 地址可变,一旦变化,将让集群无法正常工作。一个数据节点的 EP(End Point) 由 FQDN + Port 组成。采用 FQDN,需要保证 DNS 服务正常工作,或者在节点以及应用所在的节点配置好 hosts 文件。另外,这个参数值的长度需要控制在 96 个字符以内。
+**FQDN 配置:**一个数据节点有一个或多个 FQDN,可以在系统配置文件 taos.cfg 通过参数“fqdn”进行指定,如果没有指定,系统将自动获取计算机的 hostname 作为其 FQDN。如果节点没有配置 FQDN,可以直接将该节点的配置参数 fqdn 设置为它的 IP 地址。但不建议使用 IP,因为 IP 地址可变,一旦变化,将让集群无法正常工作。一个数据节点的 EP(End Point)由 FQDN + Port 组成。采用 FQDN,需要保证 DNS 服务正常工作,或者在节点以及应用所在的节点配置好 hosts 文件。另外,这个参数值的长度需要控制在 96 个字符以内。
**端口配置:**一个数据节点对外的端口由 TDengine 的系统配置参数 serverPort 决定,对集群内部通讯的端口是 serverPort+5。为支持多线程高效的处理 UDP 数据,每个对内和对外的 UDP 连接,都需要占用 5 个连续的端口。
@@ -188,9 +41,9 @@ TDengine 分布式架构的逻辑结构图如下:
- 集群数据节点对外提供 RESTful 服务占用一个 TCP 端口,是 serverPort+11。
- 集群内数据节点与 Arbitrator 节点之间通讯占用一个 TCP 端口,是 serverPort+12。
-因此一个数据节点总的端口范围为 serverPort 到 serverPort+12,总共 13 个 TCP/UDP 端口。使用时,需要确保防火墙将这些端口打开。每个数据节点可以配置不同的 serverPort。(详细的端口情况请参见 [TDengine 2.0 端口说明](https://www.taosdata.com/cn/documentation/faq#port))
+因此一个数据节点总的端口范围为 serverPort 到 serverPort+12,总共 13 个 TCP/UDP 端口。使用时,需要确保防火墙将这些端口打开。每个数据节点可以配置不同的 serverPort。详细的端口情况请参见 [TDengine 2.0 端口说明](/train-faq/faq#port)
-**集群对外连接:**TDengine 集群可以容纳单个、多个甚至几千个数据节点。应用只需要向集群中任何一个数据节点发起连接即可,连接需要提供的网络参数是一数据节点的 End Point(FQDN 加配置的端口号)。通过命令行 CLI 启动应用 taos 时,可以通过选项-h 来指定数据节点的 FQDN, -P 来指定其配置的端口号,如果端口不配置,将采用 TDengine 的系统配置参数 serverPort。
+**集群对外连接:**TDengine 集群可以容纳单个、多个甚至几千个数据节点。应用只需要向集群中任何一个数据节点发起连接即可,连接需要提供的网络参数是一数据节点的 End Point(FQDN 加配置的端口号)。通过命令行 CLI 启动应用 taos 时,可以通过选项-h 来指定数据节点的 FQDN,-P 来指定其配置的端口号,如果端口不配置,将采用 TDengine 的系统配置参数 serverPort。
**集群内部通讯:**各个数据节点之间通过 TCP/UDP 进行连接。一个数据节点启动时,将获取 mnode 所在的 dnode 的 EP 信息,然后与系统中的 mnode 建立起连接,交换信息。获取 mnode 的 EP 信息有三步:
@@ -200,11 +53,11 @@ TDengine 分布式架构的逻辑结构图如下:
获取 mnode EP 列表后,数据节点发起连接,如果连接成功,则成功加入进工作的集群,如果不成功,则尝试 mnode EP 列表中的下一个。如果都尝试了,但连接都仍然失败,则休眠几秒后,再进行尝试。
-**MNODE 的选择:**TDengine 逻辑上有管理节点,但没有单独的执行代码,服务器侧只有一套执行代码 taosd。那么哪个数据节点会是管理节点呢?这是系统自动决定的,无需任何人工干预。原则如下:一个数据节点启动时,会检查自己的 End Point, 并与获取的 mnode EP List 进行比对,如果在其中,该数据节点认为自己应该启动 mnode 模块,成为 mnode。如果自己的 EP 不在 mnode EP List 里,则不启动 mnode 模块。在系统的运行过程中,由于负载均衡、宕机等原因,mnode 有可能迁移至新的 dnode,但一切都是透明的,无需人工干预,配置参数的修改,是 mnode 自己根据资源做出的决定。
+**Mnode 的选择:**TDengine 逻辑上有管理节点,但没有单独的执行代码,服务器侧只有一套执行代码 taosd。那么哪个数据节点会是管理节点呢?这是系统自动决定的,无需任何人工干预。原则如下:一个数据节点启动时,会检查自己的 End Point,并与获取的 mnode EP List 进行比对,如果在其中,该数据节点认为自己应该启动 mnode 模块,成为 mnode。如果自己的 EP 不在 mnode EP List 里,则不启动 mnode 模块。在系统的运行过程中,由于负载均衡、宕机等原因,mnode 有可能迁移至新的 dnode,但一切都是透明的,无需人工干预,配置参数的修改,是 mnode 自己根据资源做出的决定。
-**新数据节点的加入:**系统有了一个数据节点后,就已经成为一个工作的系统。添加新的节点进集群时,有两个步骤,第一步:使用 TDengine CLI 连接到现有工作的数据节点,然后用命令"create dnode"将新的数据节点的 End Point 添加进去; 第二步:在新的数据节点的系统配置参数文件 taos.cfg 里,将 firstEp, secondEp 参数设置为现有集群中任意两个数据节点的 EP 即可。具体添加的详细步骤请见详细的用户手册。这样就把集群一步一步的建立起来。
+**新数据节点的加入:**系统有了一个数据节点后,就已经成为一个工作的系统。添加新的节点进集群时,有两个步骤,第一步:使用 TDengine CLI 连接到现有工作的数据节点,然后用命令“CREATE DNODE”将新的数据节点的 End Point 添加进去;第二步:在新的数据节点的系统配置参数文件 taos.cfg 里,将 firstEp,secondEp 参数设置为现有集群中任意两个数据节点的 EP 即可。具体添加的详细步骤请见详细的用户手册。这样就把集群一步一步的建立起来。
-**重定向:**无论是 dnode 还是 taosc,最先都是要发起与 mnode 的连接,但 mnode 是系统自动创建并维护的,因此对于用户来说,并不知道哪个 dnode 在运行 mnode。TDengine 只要求向系统中任何一个工作的 dnode 发起连接即可。因为任何一个正在运行的 dnode,都维护有目前运行的 mnode EP List。当收到一个来自新启动的 dnode 或 taosc 的连接请求,如果自己不是 mnode,则将 mnode EP List 回复给对方,taosc 或新启动的 dnode 收到这个 list, 就重新尝试建立连接。当 mnode EP List 发生改变,通过节点之间的消息交互,各个数据节点就很快获取最新列表,并通知 taosc。
+**重定向:**无论是 dnode 还是 taosc,最先都是要发起与 mnode 的连接,但 mnode 是系统自动创建并维护的,因此对于用户来说,并不知道哪个 dnode 在运行 mnode。TDengine 只要求向系统中任何一个工作的 dnode 发起连接即可。因为任何一个正在运行的 dnode,都维护有目前运行的 mnode EP List。当收到一个来自新启动的 dnode 或 taosc 的连接请求,如果自己不是 mnode,则将 mnode EP List 回复给对方,taosc 或新启动的 dnode 收到这个 list,就重新尝试建立连接。当 mnode EP List 发生改变,通过节点之间的消息交互,各个数据节点就很快获取最新列表,并通知 taosc。
### 一个典型的消息流程
@@ -216,14 +69,14 @@ TDengine 分布式架构的逻辑结构图如下:
1. 应用通过 JDBC 或其他 API 接口发起插入数据的请求。
2. taosc 会检查缓存,看是否保存有该表的 meta data。如果有,直接到第 4 步。如果没有,taosc 将向 mnode 发出 get meta-data 请求。
-3. mnode 将该表的 meta-data 返回给 taosc。Meta-data 包含有该表的 schema, 而且还有该表所属的 vgroup 信息(vnode ID 以及所在的 dnode 的 End Point,如果副本数为 N,就有 N 组 End Point)。如果 taosc 迟迟得不到 mnode 回应,而且存在多个 mnode, taosc 将向下一个 mnode 发出请求。
+3. mnode 将该表的 meta-data 返回给 taosc。Meta-data 包含有该表的 schema,而且还有该表所属的 vgroup 信息(vnode ID 以及所在的 dnode 的 End Point,如果副本数为 N,就有 N 组 End Point)。如果 taosc 迟迟得不到 mnode 回应,而且存在多个 mnode,taosc 将向下一个 mnode 发出请求。
4. taosc 向 master vnode 发起插入请求。
5. vnode 插入数据后,给 taosc 一个应答,表示插入成功。如果 taosc 迟迟得不到 vnode 的回应,taosc 会认为该节点已经离线。这种情况下,如果被插入的数据库有多个副本,taosc 将向 vgroup 里下一个 vnode 发出插入请求。
6. taosc 通知 APP,写入成功。
对于第二和第三步,taosc 启动时,并不知道 mnode 的 End Point,因此会直接向配置的集群对外服务的 End Point 发起请求。如果接收到该请求的 dnode 并没有配置 mnode,该 dnode 会在回复的消息中告知 mnode EP 列表,这样 taosc 会重新向新的 mnode 的 EP 发出获取 meta-data 的请求。
-对于第四和第五步,没有缓存的情况下,taosc 无法知道虚拟节点组里谁是 master,就假设第一个 vnodeID 就是 master,向它发出请求。如果接收到请求的 vnode 并不是 master,它会在回复中告知谁是 master,这样 taosc 就向建议的 master vnode 发出请求。一旦得到插入成功的回复,taosc 会缓存 master 节点的信息。
+对于第四和第五步,没有缓存的情况下,taosc 无法知道虚拟节点组里谁是 master,就假设第一个 vnodeID 就是 master,向它发出请求。如果接收到请求的 vnode 并不是 master,它会在回复中告知谁是 master,这样 taosc 就向建议的 master vnode 发出请求。一旦得到插入成功的回复,taosc 会缓存 master 节点的信息。
上述是插入数据的流程,查询、计算的流程也完全一致。taosc 把这些复杂的流程全部封装屏蔽了,对于应用来说无感知也无需任何特别处理。
@@ -246,27 +99,27 @@ TDengine 存储的数据包括采集的时序数据以及库、表相关的元
### 数据分片
-对于海量的数据管理,为实现水平扩展,一般都需要采取分片(Sharding)分区(Partitioning)策略。TDengine 是通过 vnode 来实现数据分片的,通过一个时间段一个数据文件来实现时序数据分区的。
+对于海量的数据管理,为实现水平扩展,一般都需要采取分片(Sharding)分区(Partitioning)策略。TDengine 是通过 vnode 来实现数据分片的,通过一个时间段一个数据文件来实现时序数据分区的。
-vnode(虚拟数据节点)负责为采集的时序数据提供写入、查询和计算功能。为便于负载均衡、数据恢复、支持异构环境,TDengine 将一个数据节点根据其计算和存储资源切分为多个 vnode。这些 vnode 的管理是 TDengine 自动完成的,对应用完全透明。
+vnode(虚拟数据节点)负责为采集的时序数据提供写入、查询和计算功能。为便于负载均衡、数据恢复、支持异构环境,TDengine 将一个数据节点根据其计算和存储资源切分为多个 vnode。这些 vnode 的管理是 TDengine 自动完成的,对应用完全透明。
-对于单独一个数据采集点,无论其数据量多大,一个 vnode(或 vnode group, 如果副本数大于 1)有足够的计算资源和存储资源来处理(如果每秒生成一条 16 字节的记录,一年产生的原始数据不到 0.5G),因此 TDengine 将一张表(一个数据采集点)的所有数据都存放在一个 vnode 里,而不会让同一个采集点的数据分布到两个或多个 dnode 上。而且一个 vnode 可存储多个数据采集点(表)的数据,一个 vnode 可容纳的表的数目的上限为一百万。设计上,一个 vnode 里所有的表都属于同一个 DB。一个数据节点上,除非特殊配置,一个 DB 拥有的 vnode 数目不会超过系统核的数目。
+对于单独一个数据采集点,无论其数据量多大,一个 vnode(或 vgroup,如果副本数大于 1)有足够的计算资源和存储资源来处理(如果每秒生成一条 16 字节的记录,一年产生的原始数据不到 0.5G),因此 TDengine 将一张表(一个数据采集点)的所有数据都存放在一个 vnode 里,而不会让同一个采集点的数据分布到两个或多个 dnode 上。而且一个 vnode 可存储多个数据采集点(表)的数据,一个 vnode 可容纳的表的数目的上限为一百万。设计上,一个 vnode 里所有的表都属于同一个 DB。一个数据节点上,除非特殊配置,一个 DB 拥有的 vnode 数目不会超过系统核的数目。
-创建 DB 时,系统并不会马上分配资源。但当创建一张表时,系统将看是否有已经分配的 vnode, 且该 vnode 是否有空余的表空间,如果有,立即在该有空位的 vnode 创建表。如果没有,系统将从集群中,根据当前的负载情况,在一个 dnode 上创建一新的 vnode, 然后创建表。如果 DB 有多个副本,系统不是只创建一个 vnode,而是一个 vgroup (虚拟数据节点组)。系统对 vnode 的数目没有任何限制,仅仅受限于物理节点本身的计算和存储资源。
+创建 DB 时,系统并不会马上分配资源。但当创建一张表时,系统将看是否有已经分配的 vnode,且该 vnode 是否有空余的表空间,如果有,立即在该有空位的 vnode 创建表。如果没有,系统将从集群中,根据当前的负载情况,在一个 dnode 上创建一新的 vnode,然后创建表。如果 DB 有多个副本,系统不是只创建一个 vnode,而是一个 vgroup(虚拟数据节点组)。系统对 vnode 的数目没有任何限制,仅仅受限于物理节点本身的计算和存储资源。
-每张表的 meta data(包含 schema, 标签等)也存放于 vnode 里,而不是集中存放于 mnode,实际上这是对 Meta 数据的分片,这样便于高效并行的进行标签过滤操作。
+每张表的 meta data(包含 schema,标签等)也存放于 vnode 里,而不是集中存放于 mnode,实际上这是对 Meta 数据的分片,这样便于高效并行的进行标签过滤操作。
### 数据分区
-TDengine 除 vnode 分片之外,还对时序数据按照时间段进行分区。每个数据文件只包含一个时间段的时序数据,时间段的长度由 DB 的配置参数 days 决定。这种按时间段分区的方法还便于高效实现数据的保留策略,只要数据文件超过规定的天数(系统配置参数 keep),将被自动删除。而且不同的时间段可以存放于不同的路径和存储介质,以便于大数据的冷热管理,实现多级存储。
+TDengine 除 vnode 分片之外,还对时序数据按照时间段进行分区。每个数据文件只包含一个时间段的时序数据,时间段的长度由 DB 的配置参数 days 决定。这种按时间段分区的方法还便于高效实现数据的保留策略,只要数据文件超过规定的天数(系统配置参数 keep),将被自动删除。而且不同的时间段可以存放于不同的路径和存储介质,以便于大数据的冷热管理,实现多级存储。
总的来说,**TDengine 是通过 vnode 以及时间两个维度,对大数据进行切分**,便于并行高效的管理,实现水平扩展。
### 负载均衡
-每个 dnode 都定时向 mnode(虚拟管理节点)报告其状态(包括硬盘空间、内存大小、CPU、网络、虚拟节点个数等),因此 mnode 了解整个集群的状态。基于整体状态,当 mnode 发现某个 dnode 负载过重,它会将 dnode 上的一个或多个 vnode 挪到其他 dnode。在挪动过程中,对外服务继续进行,数据插入、查询和计算操作都不受影响。
+每个 dnode 都定时向 mnode(虚拟管理节点)报告其状态(包括硬盘空间、内存大小、CPU、网络、虚拟节点个数等),因此 mnode 了解整个集群的状态。基于整体状态,当 mnode 发现某个 dnode 负载过重,它会将 dnode 上的一个或多个 vnode 挪到其他 dnode。在挪动过程中,对外服务继续进行,数据插入、查询和计算操作都不受影响。
-如果 mnode 一段时间没有收到 dnode 的状态报告,mnode 会认为这个 dnode 已经离线。如果离线时间超过一定时长(时长由配置参数 offlineThreshold 决定),该 dnode 将被 mnode 强制剔除出集群。该 dnode 上的 vnodes 如果副本数大于 1,系统将自动在其他 dnode 上创建新的副本,以保证数据的副本数。如果该 dnode 上还有 mnode, 而且 mnode 的副本数大于 1,系统也将自动在其他 dnode 上创建新的 mnode, 以保证 mnode 的副本数。
+如果 mnode 一段时间没有收到 dnode 的状态报告,mnode 会认为这个 dnode 已经离线。如果离线时间超过一定时长(时长由配置参数 offlineThreshold 决定),该 dnode 将被 mnode 强制剔除出集群。该 dnode 上的 vnodes 如果副本数大于 1,系统将自动在其他 dnode 上创建新的副本,以保证数据的副本数。如果该 dnode 上还有 mnode,而且 mnode 的副本数大于 1,系统也将自动在其他 dnode 上创建新的 mnode,以保证 mnode 的副本数。
当新的数据节点被添加进集群,因为新的计算和存储被添加进来,系统也将自动启动负载均衡流程。
@@ -288,9 +141,9 @@ Master Vnode 遵循下面的写入流程:
1. master vnode 收到应用的数据插入请求,验证 OK,进入下一步;
2. 如果系统配置参数 walLevel 大于 0,vnode 将把该请求的原始数据包写入数据库日志文件 WAL。如果 walLevel 设置为 2,而且 fsync 设置为 0,TDengine 还将 WAL 数据立即落盘,以保证即使宕机,也能从数据库日志文件中恢复数据,避免数据的丢失;
-3. 如果有多个副本,vnode 将把数据包转发给同一虚拟节点组内的 slave vnodes, 该转发包带有数据的版本号(version);
+3. 如果有多个副本,vnode 将把数据包转发给同一虚拟节点组内的 slave vnodes,该转发包带有数据的版本号(version);
4. 写入内存,并将记录加入到 skip list;
-5. master vnode 返回确认信息给应用,表示写入成功。
+5. master vnode 返回确认信息给应用,表示写入成功;
6. 如果第 2、3、4 步中任何一步失败,将直接返回错误给应用。
### Slave Vnode 写入流程
@@ -309,16 +162,16 @@ Master Vnode 遵循下面的写入流程:
### 主从选择
-Vnode 会保持一个数据版本号(version),对内存数据进行持久化存储时,对该版本号也进行持久化存储。每个数据更新操作,无论是采集的时序数据还是元数据,这个版本号将增加 1。
+Vnode 会保持一个数据版本号(version),对内存数据进行持久化存储时,对该版本号也进行持久化存储。每个数据更新操作,无论是采集的时序数据还是元数据,这个版本号将增加 1。
-一个 vnode 启动时,角色(master、slave) 是不定的,数据是处于未同步状态,它需要与虚拟节点组内其他节点建立 TCP 连接,并互相交换 status,其中包括 version 和自己的角色。通过 status 的交换,系统进入选主流程,规则如下:
+一个 vnode 启动时,角色(master、slave)是不定的,数据是处于未同步状态,它需要与虚拟节点组内其他节点建立 TCP 连接,并互相交换 status,其中包括 version 和自己的角色。通过 status 的交换,系统进入选主流程,规则如下:
1. 如果只有一个副本,该副本永远就是 master
2. 所有副本都在线时,版本最高的被选为 master
3. 在线的虚拟节点数过半,而且有虚拟节点是 slave 的话,该虚拟节点自动成为 master
4. 对于 2 和 3,如果多个虚拟节点满足成为 master 的要求,那么虚拟节点组的节点列表里,最前面的选为 master
-更多的关于数据复制的流程,请见[TDengine 2.0 数据复制模块设计](https://www.taosdata.com/cn/documentation/architecture/replica/)。
+更多的关于数据复制的流程,请见[《TDengine 2.0 数据复制模块设计》](/tdinternal/replica/)。
### 同步复制
@@ -344,11 +197,11 @@ TDengine 采用数据驱动的方式让缓存中的数据写入硬盘进行持
对于采集的数据,一般有保留时长,这个时长由系统配置参数 keep 决定。超过这个设置天数的数据文件,将被系统自动删除,释放存储空间。
-给定 days 与 keep 两个参数,一个典型工作状态的 vnode 中总的数据文件数为:`向上取整(keep/days)+1`个。总的数据文件个数不宜过大,也不宜过小。10 到 100 以内合适。基于这个原则,可以设置合理的 days。目前的版本,参数 keep 可以修改,但对于参数 days,一旦设置后,不可修改。
+给定 days 与 keep 两个参数,一个典型工作状态的 vnode 中总的数据文件数为:向上取整 `(keep/days)+1` 个。总的数据文件个数不宜过大,也不宜过小。10 到 100 以内合适。基于这个原则,可以设置合理的 days。目前的版本,参数 keep 可以修改,但对于参数 days,一旦设置后,不可修改。
在每个数据文件里,一张表的数据是一块一块存储的。一张表可以有一到多个数据文件块。在一个文件块里,数据是列式存储的,占用的是一片连续的存储空间,这样大大提高读取速度。文件块的大小由系统参数 maxRows (每块最大记录条数)决定,缺省值为 4096。这个值不宜过大,也不宜过小。过大,定位具体时间段的数据的搜索时间会变长,影响读取速度;过小,数据块的索引太大,压缩效率偏低,也影响读取速度。
-每个数据文件(.data 结尾)都有一个对应的索引文件(.head 结尾),该索引文件对每张表都有一数据块的摘要信息,记录了每个数据块在数据文件中的偏移量,数据的起止时间等信息,以帮助系统迅速定位需要查找的数据。每个数据文件还有一对应的 last 文件(.last 结尾),该文件是为防止落盘时数据块碎片化而设计的。如果一张表落盘的记录条数没有达到系统配置参数 minRows(每块最小记录条数),将被先存储到 last 文件,等下次落盘时,新落盘的记录将与 last 文件的记录进行合并,再写入数据文件。
+每个数据文件(.data 结尾)都有一个对应的索引文件(.head 结尾),该索引文件对每张表都有一数据块的摘要信息,记录了每个数据块在数据文件中的偏移量,数据的起止时间等信息,以帮助系统迅速定位需要查找的数据。每个数据文件还有一对应的 last 文件(.last 结尾),该文件是为防止落盘时数据块碎片化而设计的。如果一张表落盘的记录条数没有达到系统配置参数 minRows(每块最小记录条数),将被先存储到 last 文件,等下次落盘时,新落盘的记录将与 last 文件的记录进行合并,再写入数据文件。
数据写入磁盘时,根据系统配置参数 comp 决定是否压缩数据。TDengine 提供了三种压缩选项:无压缩、一阶段压缩和两阶段压缩,分别对应 comp 值为 0、1 和 2 的情况。一阶段压缩根据数据的类型进行了相应的压缩,压缩算法包括 delta-delta 编码、simple 8B 方法、zig-zag 编码、LZ4 等算法。二阶段压缩在一阶段压缩的基础上又用通用压缩算法进行了压缩,压缩率更高。
@@ -376,7 +229,7 @@ dataDir [path]
需要说明的是,数据在不同级别的存储介质上的移动,是由系统自动完成的,用户无需干预。
- primary: 是否为主挂载点,0(否)或 1(是),省略默认为 1。
-在配置中,只允许一个主挂载点的存在(level=0, primary=1),例如采用如下的配置方式:
+在配置中,只允许一个主挂载点的存在(level=0,primary=1),例如采用如下的配置方式:
```
dataDir /mnt/data1 0 1
@@ -387,19 +240,21 @@ dataDir /mnt/data5 2 0
dataDir /mnt/data6 2 0
```
-注意:
+:::note
1. 多级存储不允许跨级配置,合法的配置方案有:仅 0 级,仅 0 级+ 1 级,以及 0 级+ 1 级+ 2 级。而不允许只配置 level=0 和 level=2,而不配置 level=1。
2. 禁止手动移除使用中的挂载盘,挂载盘目前不支持非本地的网络盘。
3. 多级存储目前不支持删除已经挂载的硬盘的功能。
+:::
+
## 数据查询
TDengine 提供了多种多样针对表和超级表的查询处理功能,除了常规的聚合查询之外,还提供针对时序数据的窗口查询、统计聚合等功能。TDengine 的查询处理需要客户端、vnode、mnode 节点协同完成。
### 单表查询
-SQL 语句的解析和校验工作在客户端完成。解析 SQL 语句并生成抽象语法树(Abstract Syntax Tree, AST),然后对其进行校验和检查。以及向管理节点(mnode)请求查询中指定表的元数据信息(table metadata)。
+SQL 语句的解析和校验工作在客户端完成。解析 SQL 语句并生成抽象语法树(Abstract Syntax Tree,AST),然后对其进行校验和检查。以及向管理节点(mnode)请求查询中指定表的元数据信息(table metadata)。
根据元数据信息中的 End Point 信息,将查询请求序列化后发送到该表所在的数据节点(dnode)。dnode 接收到查询请求后,识别出该查询请求指向的虚拟节点(vnode),将消息转发到 vnode 的查询执行队列。vnode 的查询执行线程建立基础的查询执行环境,并立即返回该查询请求,同时开始执行该查询。
@@ -423,7 +278,7 @@ SELECT COUNT(*) FROM d1001 INTERVAL(1h);
SELECT COUNT(*) FROM d1001 WHERE ts >= '2017-7-14 00:00:00' AND ts < '2017-7-14 23:59:59' INTERVAL(1h) FILL(PREV);
```
-针对 d1001 设备采集数据统计每小时记录数,如果某一个小时不存在数据,则返回之前一个小时的统计数据。TDengine 提供前向插值(prev)、线性插值(linear)、NULL 值填充(NULL)、特定值填充(value)。
+针对 d1001 设备采集数据统计每小时记录数,如果某一个小时不存在数据,则返回之前一个小时的统计数据。TDengine 提供前向插值(prev)、线性插值(linear)、空值填充(NULL)、特定值填充(value)。
### 多表聚合查询
@@ -434,7 +289,7 @@ TDengine 对每个数据采集点单独建表,但在实际应用中经常需
图 5 多表聚合查询原理图
1. 应用将一个查询条件发往系统;
-2. taosc 将超级表的名字发往 meta node(管理节点);
+2. taosc 将超级表的名字发往 meta node(管理节点);
3. 管理节点将超级表所拥有的 vnode 列表发回 taosc;
4. taosc 将计算的请求连同标签过滤条件发往这些 vnode 对应的多个数据节点;
5. 每个 vnode 先在内存里查找出自己节点里符合标签过滤条件的表的集合,然后扫描存储的时序数据,完成相应的聚合计算,将结果返回给 taosc;
diff --git a/docs-cn/13-tdinternal/02-replica.md b/docs-cn/21-tdinternal/02-replica.md
similarity index 99%
rename from docs-cn/13-tdinternal/02-replica.md
rename to docs-cn/21-tdinternal/02-replica.md
index 037ce0682ade1677da00287dd5f30696c3eaf17b..6a384b982d22956dd514d8df05dc827ca6f8b729 100644
--- a/docs-cn/13-tdinternal/02-replica.md
+++ b/docs-cn/21-tdinternal/02-replica.md
@@ -1,9 +1,8 @@
---
sidebar_label: 数据复制模块设计
+title: 数据复制模块设计
---
-# 数据复制模块设计
-
## 数据复制概述
数据复制(Replication)是指同一份数据在多个物理地点保存。它的目的是防止数据丢失,提高系统的高可用性(High Availability),而且通过应用访问多个副本,提升数据查询性能。
@@ -14,7 +13,7 @@ TDengine面向的是物联网场景,需要支持数据的实时复制,来最
数据复制是与数据存储(写入、读取)密切相关的,但两者又是相对独立,可以完全脱耦的。在TDengine系统中,有两种不同类型的数据,一种是时序数据,由TSDB模块负责;一种是元数据(Meta Data), 由MNODE负责。这两种性质不同的数据都需要同步功能。数据复制模块通过不同的实例启动配置参数,为这两种类型数据都提供同步功能。
-在阅读本文之前,请先阅读《[TDengine 2.0 整体架构](https://www.taosdata.com/cn/documentation/architecture/)》,了解TDengine的集群设计和基本概念
+在阅读本文之前,请先阅读《[TDengine 2.0 整体架构](/tdinternal/arch/)》,了解TDengine的集群设计和基本概念
特别注明:本文中提到数据更新操作包括数据的增加、删除与修改。
diff --git a/docs-cn/21-tdinternal/03-taosd.md b/docs-cn/21-tdinternal/03-taosd.md
new file mode 100644
index 0000000000000000000000000000000000000000..f0f50e03e277524fc37f44a2207b43e87898937e
--- /dev/null
+++ b/docs-cn/21-tdinternal/03-taosd.md
@@ -0,0 +1,121 @@
+---
+sidebar_label: taosd 的设计
+title: taosd的设计
+---
+
+
+逻辑上,TDengine 系统包含 dnode,taosc 和 App,dnode 是服务器侧执行代码 taosd 的一个运行实例,因此 taosd 是 TDengine 的核心,本文对 taosd 的设计做一简单的介绍,模块内的实现细节请见其他文档。
+
+## 系统模块图
+
+taosd 包含 rpc,dnode,vnode,tsdb,query,cq,sync,wal,mnode,http,monitor 等模块,具体如下图:
+
+
+
+taosd 的启动入口是 dnode 模块,dnode 然后启动其他模块,包括可选配置的 http,monitor 模块。taosc 或 dnode 之间交互的消息都是通过 rpc 模块进行,dnode 模块根据接收到的消息类型,将消息分发到 vnode 或 mnode 的消息队列,或由 dnode 模块自己消费。dnode 的工作线程(worker)消费消息队列里的消息,交给 mnode 或 vnode 进行处理。下面对各个模块做简要说明。
+
+## RPC模块
+
+该模块负责 taosd 与 taosc,以及其他数据节点之间的通讯。TDengine 没有采取标准的 HTTP 或 gRPC 等第三方工具,而是实现了自己的通讯模块 RPC。
+
+考虑到物联网场景下,数据写入的包一般不大,因此除支持 TCP 连接之外,RPC 还支持 UDP 连接。当数据包小于 15K 时,RPC 将采用 UDP 方式进行连接,否则将采用 TCP 连接。对于查询类的消息,RPC 不管包的大小,总是采取 TCP 连接。对于 UDP 连接,RPC 实现了自己的超时、重传、顺序检查等机制,以保证数据可靠传输。
+
+RPC 模块还提供数据压缩功能,如果数据包的字节数超过系统配置参数 compressMsgSize,RPC 在传输中将自动压缩数据,以节省带宽。
+
+为保证数据的安全和数据的 integrity,RPC 模块采用 MD5 做数字签名,对数据的真实性和完整性进行认证。
+
+## DNODE模块
+
+该模块是整个 taosd 的入口,它具体负责如下任务:
+
+- 系统的初始化,包括
+ - 从文件 taos.cfg 读取系统配置参数,从文件 dnodeCfg.json 读取数据节点的配置参数;
+ - 启动 RPC 模块,并建立起与 taosc 通讯的 server 连接,与其他数据节点通讯的 server 连接;
+ - 启动并初始化 dnode 的内部管理,该模块将扫描该数据节点已有的 vnode ,并打开它们;
+ - 初始化可配置的模块,如 mnode,http,monitor 等。
+- 数据节点的管理,包括
+ - 定时的向 mnode 发送 status 消息,报告自己的状态;
+ - 根据 mnode 的指示,创建、改变、删除 vnode;
+ - 根据 mnode 的指示,修改自己的配置参数;
+- 消息的分发、消费,包括
+ - 为每一个 vnode 和 mnode 的创建并维护一个读队列、一个写队列;
+ - 将从 taosc 或其他数据节点来的消息,根据消息类型,将其直接分发到不同的消息队列,或由自己的管理模块直接消费;
+ - 维护一个读的线程池,消费读队列的消息,交给 vnode 或 mnode 处理。为支持高并发,一个读线程(worker)可以消费多个队列的消息,一个读队列可以由多个 worker 消费;
+ - 维护一个写的线程池,消费写队列的消息,交给 vnode 或 mnode 处理。为保证写操作的序列化,一个写队列只能由一个写线程负责,但一个写线程可以负责多个写队列。
+
+taosd 的消息消费由 dnode 通过读写线程池进行控制,是系统的中枢。该模块内的结构体图如下:
+
+
+
+## VNODE模块
+
+vnode 是一独立的数据存储查询逻辑单元,但因为一个 vnode 只能容许一个 DB ,因此 vnode 内部没有 account,DB,user 等概念。为实现更好的模块化、封装以及未来的扩展,它有很多子模块,包括负责存储的 TSDB,负责查询的 query,负责数据复制的 sync,负责数据库日志的的 wal,负责连续查询的 cq(continuous query),负责事件触发的流计算的 event 等模块,这些子模块只与 vnode 模块发生关系,与其他模块没有任何调用关系。模块图如下:
+
+
+
+vnode 模块向下,与 dnodeVRead,dnodeVWrite 发生互动,向上,与子模块发生互动。它主要的功能有:
+
+- 协调各个子模块的互动。各个子模块之间都不直接调用,都需要通过 vnode 模块进行;
+- 对于来自 taosc 或 mnode 的写操作,vnode 模块将其分解为写日志(wal),转发(sync),本地存储(TSDB)子模块的操作;
+- 对于查询操作,分发到 query 模块进行。
+
+一个数据节点里有多个 vnode,因此 vnode 模块是有多个运行实例的。每个运行实例是完全独立的。
+
+vnode 与其子模块是通过 API 直接调用,而不是通过消息队列传递。而且各个子模块只与 vnode 模块有交互,不与 dnode,rpc 等模块发生任何直接关联。
+
+## MNODE模块
+
+mnode 是整个系统的大脑,负责整个系统的资源调度,负责 meta data 的管理与存储。
+
+一个运行的系统里,只有一个 mnode,但它有多个副本(由系统配置参数 numOfMnodes 控制)。这些副本分布在不同的 dnode 里,目的是保证系统的高可靠运行。副本之间的数据复制是采用同步而非异步的方式,以确保数据的一致性,确保数据不会丢失。这些副本会自动选举一个 Master,其他副本是 slave。所有数据更新类的操作,都只能在 master 上进行,而查询类的可以在 slave 节点上进行。代码实现上,同步模块与 vnode 共享,但 mnode 被分配一个特殊的 vgroup ID: 1,而且 quorum 大于1。整个集群系统是由多个 dnode 组成的,运行的 mnode 的副本数不可能超过 dnode 的个数,但不会超过配置的副本数。如果某个 mnode 副本宕机一段时间,只要超过半数的 mnode 副本仍在运行,运行的 mnode 会自动根据整个系统的资源情况,在其他 dnode 里再启动一个 mnode,以保证运行的副本数。
+
+各个 dnode 通过信息交换,保存有 mnode 各个副本的 End Point 列表,并向其中的 master 节点定时(间隔由系统配置参数 statusInterval 控制)发送 status 消息,消息体里包含该 dnode 的 CPU、内存、剩余存储空间、vnode 个数,以及各个 vnode 的状态(存储空间、原始数据大小、记录条数、角色等)。这样 mnode 就了解整个系统的资源情况,如果用户创建新的表,就可以决定需要在哪个 dnode 创建;如果增加或删除 dnode,或者监测到某 dnode 数据过热、或离线太长,就可以决定需要挪动那些 vnode,以实现负载均衡。
+
+mnode 里还负责 account,user,DB,stable,table,vgroup,dnode 的创建、删除与更新。mnode 不仅把这些 entity 的 meta data 保存在内存,还做持久化存储。但为节省内存,各个表的标签值不保存在 mnode(保存在 vnode),而且子表不维护自己的 schema,而是与 stable 共享。为减小 mnode 的查询压力,taosc 会缓存 table、stable 的 schema。对于查询类的操作,各个 slave mnode 也可以提供,以减轻 master 压力。
+
+## TSDB模块
+
+TSDB 模块是 vnode 中的负责快速高并发地存储和读取属于该 vnode 的表的元数据及采集的时序数据的引擎。除此之外,TSDB 还提供了表结构的修改、表标签值的修改等功能。TSDB 提供 API 供 vnode 和 query 等模块调用。TSDB 中存储了两类数据,1:元数据信息;2:时序数据
+
+### 元数据信息
+
+TSDB 中存储的元数据包含属于其所在的 vnode 中表的类型,schema 的定义等。对于超级表和超级表下的子表而言,又包含了 tag 的 schema 定义以及子表的 tag 值等。对于元数据信息而言,TSDB 就相当于一个全内存的KV型数据库,属于该 vnode 的表对象全部在内存中,方便快速查询表的信息。除此之外,TSDB 还对其中的子表,按照 tag 的第一列取值做了全内存的索引,大大加快了对于标签的过滤查询。TSDB 中的元数据的最新状态在落盘时,会以追加(append-only)的形式,写入到 meta 文件中。meta 文件只进行追加操作,即便是元数据的删除,也会以一条记录的形式写入到文件末尾。TSDB 也提供了对于元数据的修改操作,如表 schema 的修改,tag schema 的修改以及 tag 值的修改等。
+
+### 时序数据
+
+每个 TSDB 在创建时,都会事先分配一定量的内存缓冲区,且内存缓冲区的大小可配可修改。表采集的时序数据,在写入 TSDB 时,首先以追加的方式写入到分配的内存缓冲区中,同时建立基于时间戳的内存索引,方便快速查询。当内存缓冲区的数据积累到一定的程度时(达到内存缓冲区总大小的 1/3),则会触发落盘操作,将缓冲区中的数据持久化到硬盘文件上。时序数据在内存缓冲区中是以行(row)的形式存储的。
+
+而时序数据在写入到 TSDB 的数据文件时,是以列(column)的形式存储的。TSDB 中的数据文件包含多个数据文件组,每个数据文件组中又包含 .head、.data 和 .last 三个文件,如(v2f1801.head、v2f1801.data、v2f1801.last)数据文件组。TSDB 中的数据文件组是按照时间跨度进行分片的,默认是 10 天一个文件组,且可通过配置文件及建库选项进行配置。分片的数据文件组又按照编号递增排列,方便快速定位某一时间段的时序数据,高效定位数据文件组。时序数据在 TSDB 的数据文件中是以块的形式进行列式存储的,每个块中只包含一张表的数据,且数据在一个块中是按照时间顺序递增排列的。在一个数据文件组中,.head 文件负责存储数据块的索引及统计信息,如每个块的位置,压缩算法,时间戳范围等。存储在 .head 文件中一张表的索引信息是按照数据块中存储的数据的时间递增排列的,方便进行折半查找等工作。.head 和 .last文件是存储真实数据块的文件,若数据块中的数据累计到一定程度,则会写入 .data 文件中,否则,会写入 .last 文件中,等待下次落盘时合并数据写入 .data 文件中,从而大大减少文件中块的个数,避免数据的过度碎片化。
+
+## Query模块
+
+该模块负责整体系统的查询处理。客户端调用该该模块进行 SQL 语法解析,并将查询或写入请求发送到 vnode ,同时负责针对超级表的查询进行二阶段的聚合操作。在 vnode 端,该模块调用 TSDB 模块读取系统中存储的数据进行查询处理。query 模块还定义了系统能够支持的全部查询函数,查询函数的实现机制与查询框架无耦合,可以在不修改查询流程的情况下动态增加查询函数。详细的设计请参见《TDengine 2.0 查询模块设计》。
+
+## SYNC模块
+
+该模块实现数据的多副本复制,包括vnode与mnode的数据复制,支持异步和同步两种复制方式,以满足meta data与时序数据不同复制的需求。因为它为mnode与vnode共享,系统为mnode副本预留了一个特殊的vgroup ID:1。因此vnode group的ID是从2开始的。
+
+每个vnode/mnode模块实例会有一对应的sync模块实例,他们是一一对应的。详细设计请见[TDengine 2.0 数据复制模块设计](/tdinternal/replica/)
+
+## WAL模块
+
+该模块负责将新插入的数据写入 write ahead log(WAL),为vnode,mnode共享。以保证服务器 crash 或其他故障,能从 WAL 中恢复数据。
+
+每个 vnode/mnode 模块实例会有一对应的 wal 模块实例,是完全一一对应的。WAL 的落盘操作由两个参数 walLevel,fsync 控制。看具体场景,如果要 100% 保证数据不会丢失,需要将 walLevel 配置为 2,fsync 设置为 0,每条数据插入请求,都会实时落盘后,才会给应用确认
+
+## HTTP模块
+
+该模块负责处理系统对外的 RESTful 接口,可以通过配置,由 dnode 启动或停止 。(仅 2.2 及之前的版本中存在)
+
+该模块将接收到的 RESTful 请求,做了各种合法性检查后,将其变成标准的 SQL 语句,通过 taosc 的异步接口,将请求发往整个系统中的任一 dnode 。收到处理后的结果后,再翻译成 HTTP 协议,返回给应用。
+
+如果HTTP模块启动,就意味着启动了一个taosc的实例。任一一个dnode都可以启动该模块,以实现对RESTful请求的分布式处理。
+
+## Monitor模块
+
+该模块负责检测一个 dnode 的运行状态,可以通过配置,由 dnode 启动或停止。原则上,每个 dnode 都应该启动一个 monitor 实例。
+
+Monitor 采集 TDengine 里的关键操作,比如创建、删除、更新账号、表、库等,而且周期性的收集 CPU、内存、网络等资源的使用情况(采集周期由系统配置参数 monitorInterval 控制)。获得这些数据后,monitor 模块将采集的数据写入系统的日志库(DB 名字由系统配置参数 monitorDbName 控制)。
+
+Monitor 模块使用 taosc 来将采集的数据写入系统,因此每个 monitor 实例,都有一个 taosc 运行实例。
+
diff --git a/docs-cn/13-tdinternal/12-tsz-compress.md b/docs-cn/21-tdinternal/12-tsz-compress.md
similarity index 98%
rename from docs-cn/13-tdinternal/12-tsz-compress.md
rename to docs-cn/21-tdinternal/12-tsz-compress.md
index 5072b474195fa648f5f8e29a6954e8ef6fe35e06..baf5df15db3b44edc9e0bd6909e46fa84b676a0b 100644
--- a/docs-cn/13-tdinternal/12-tsz-compress.md
+++ b/docs-cn/21-tdinternal/12-tsz-compress.md
@@ -1,4 +1,6 @@
-# TSZ 压缩算法
+---
+title: TSZ 压缩算法
+---
TSZ 压缩算法是 TDengine 为浮点数据类型提供更加丰富的压缩功能,可以实现浮点数的有损至无损全状态压缩,相比原来在 TDengine 中原有压缩算法,TSZ 压缩算法压缩选项更丰富,压缩率更高,即使切到无损状态下对浮点数压缩,压缩率也会比原来的压缩算法高一倍。
diff --git a/docs-cn/16-iot-bigdata/iot-bigdata.md b/docs-cn/21-tdinternal/30-iot-big-data.md
similarity index 61%
rename from docs-cn/16-iot-bigdata/iot-bigdata.md
rename to docs-cn/21-tdinternal/30-iot-big-data.md
index 5687dd3fda161c426108dba298b73fc4db949c28..a234713f883056e3d1a0dcbfe8e2e47a82865f81 100644
--- a/docs-cn/16-iot-bigdata/iot-bigdata.md
+++ b/docs-cn/21-tdinternal/30-iot-big-data.md
@@ -1,5 +1,7 @@
-# 物联网大数据
-
+---
+title: 物联网大数据
+description: "物联网、工业互联网大数据的特点;物联网大数据平台应具备的功能和特点;通用大数据架构为什么不适合处理物联网数据;物联网、车联网、工业互联网大数据平台,为什么推荐使用 TDengine"
+---
- [物联网、工业互联网大数据的特点](https://www.taosdata.com/blog/2019/07/09/105.html)
- [物联网大数据平台应具备的功能和特点](https://www.taosdata.com/blog/2019/07/29/542.html)
diff --git a/docs-cn/21-tdinternal/_category_.yml b/docs-cn/21-tdinternal/_category_.yml
new file mode 100644
index 0000000000000000000000000000000000000000..73c78f68a520fefecc145daaa24fe7e28c7c78e2
--- /dev/null
+++ b/docs-cn/21-tdinternal/_category_.yml
@@ -0,0 +1,4 @@
+label: 技术内幕
+link:
+ slug: /tdinternal/
+ type: generated-index
\ No newline at end of file
diff --git a/docs-cn/15-application/01-telegraf.md b/docs-cn/25-application/01-telegraf.md
similarity index 98%
rename from docs-cn/15-application/01-telegraf.md
rename to docs-cn/25-application/01-telegraf.md
index a23240debebbbf4a9da023f904562f04276f5b12..87f74fa67fbdbc3e4c5631b9cd393c4a78d3e25e 100644
--- a/docs-cn/15-application/01-telegraf.md
+++ b/docs-cn/25-application/01-telegraf.md
@@ -1,9 +1,8 @@
---
sidebar_label: TDengine + Telegraf + Grafana
+title: 使用 TDengine + Telegraf + Grafana 快速搭建 IT 运维展示系统
---
-# 使用 TDengine + Telegraf + Grafana 快速搭建 IT 运维展示系统
-
## 背景介绍
TDengine 是涛思数据专为物联网、车联网、工业互联网、IT 运维等设计和优化的大数据平台。自从 2019 年 7 月开源以来,凭借创新的数据建模设计、快捷的安装方式、易用的编程接口和强大的数据写入查询性能博得了大量时序数据开发者的青睐。
diff --git a/docs-cn/15-application/02-collectd.md b/docs-cn/25-application/02-collectd.md
similarity index 92%
rename from docs-cn/15-application/02-collectd.md
rename to docs-cn/25-application/02-collectd.md
index 10f8eff8b7ade5a66357fb095a600fa453f53731..da055632837e74f4d863148843f1001cc3aa3e8b 100644
--- a/docs-cn/15-application/02-collectd.md
+++ b/docs-cn/25-application/02-collectd.md
@@ -1,9 +1,8 @@
---
sidebar_label: TDengine + collectd/StatsD + Grafana
+title: 使用 TDengine + collectd/StatsD + Grafana 快速搭建 IT 运维监控系统
---
-# 使用 TDengine + collectd/StatsD + Grafana 快速搭建 IT 运维监控系统
-
## 背景介绍
TDengine 是涛思数据专为物联网、车联网、工业互联网、IT 运维等设计和优化的大数据平台。自从 2019 年 7 月开源以来,凭借创新的数据建模设计、快捷的安装方式、易用的编程接口和强大的数据写入查询性能博得了大量时序数据开发者的青睐。
@@ -37,7 +36,7 @@ IT 运维监测数据通常都是对时间特性比较敏感的数据,例如
### 安装 TDengine
-从涛思数据官网[下载](http://taosdata.com/cn/all-downloads/)页面下载最新 TDengine-server 2.3.0.0 或以上版本安装。
+从涛思数据官网[下载](http://taosdata.com/cn/all-downloads/)页面下载最新 TDengine-server 2.3.0.0 或以上版本安装。
## 数据链路设置
@@ -53,7 +52,7 @@ IT 运维监测数据通常都是对时间特性比较敏感的数据,例如
### 配置 collectd
-在 /etc/collectd/collectd.conf 文件中增加如下内容,其中 host 和 port 请填写 TDengine 和 taosAdapter 配置的实际值:
+在 `/etc/collectd/collectd.conf` 文件中增加如下内容,其中 host 和 port 请填写 TDengine 和 taosAdapter 配置的实际值:
```
LoadPlugin network
@@ -66,7 +65,7 @@ sudo systemctl start collectd
### 配置 StatsD
-在 config.js 文件中增加如下内容后启动 StatsD,其中 host 和 port 请填写 TDengine 和 taosAdapter 配置的实际值:
+在 `config.js` 文件中增加如下内容后启动 StatsD,其中 host 和 port 请填写 TDengine 和 taosAdapter 配置的实际值:
```
backends 部分添加 "./backends/repeater"
diff --git a/docs-cn/15-application/03-immigrate.md b/docs-cn/25-application/03-immigrate.md
similarity index 97%
rename from docs-cn/15-application/03-immigrate.md
rename to docs-cn/25-application/03-immigrate.md
index 1e3087c06f40ae393ad55f71b534ca0cf424cb74..9b2c04e96ecf5f7f43abc2a3e2c6fbce03840d9c 100644
--- a/docs-cn/15-application/03-immigrate.md
+++ b/docs-cn/25-application/03-immigrate.md
@@ -1,9 +1,8 @@
---
sidebar_label: OpenTSDB 迁移到 TDengine
+title: OpenTSDB 应用迁移到 TDengine 的最佳实践
---
-# OpenTSDB 应用迁移到 TDengine 的最佳实践
-
作为一个分布式、可伸缩、基于 HBase 的分布式时序数据库系统,得益于其先发优势,OpenTSDB 被 DevOps 领域的人员引入并广泛地应用在了运维监控领域。但最近几年,随着云计算、微服务、容器化等新技术快速落地发展,企业级服务种类变得越来越多,架构也越来越复杂,应用运行基础环境日益多样化,给系统和运行监控带来的压力也越来越大。从这一现状出发,使用 OpenTSDB 作为 DevOps 的监控后端存储,越来越受困于其性能问题以及迟缓的功能升级,以及由此而衍生出来的应用部署成本上升和运行效率降低等问题,这些问题随着系统规模的扩大日益严重。
在这一背景下,为满足高速增长的物联网大数据市场和技术需求,在吸取众多传统关系型数据库、NoSQL 数据库、流计算引擎、消息队列等软件的优点之后,涛思数据自主开发出创新型大数据处理产品 TDengine。在时序大数据处理上,TDengine 有着自己独特的优势。就 OpenTSDB 当前遇到的问题来说,TDengine 能够有效解决。
@@ -48,7 +47,7 @@ sidebar_label: OpenTSDB 迁移到 TDengine
用户可以根据需求弹性部署 taosAdapter 实例,结合场景的需要,快速提升数据写入的吞吐量,为不同应用场景下的数据写入提供保障。
-通过 taosAdapter,用户可以将 collectd 和 StatsD 收集的数据直接推送到 TDengine ,实现应用场景的无缝迁移,非常的轻松便捷。taosAdapter 还支持 Telegraf、Icinga、TCollector 、node_exporter 的数据接入,使用详情参考[taosAdapter](https://www.taosdata.com/cn/documentation/tools/adapter)。
+通过 taosAdapter,用户可以将 collectd 和 StatsD 收集的数据直接推送到 TDengine ,实现应用场景的无缝迁移,非常的轻松便捷。taosAdapter 还支持 Telegraf、Icinga、TCollector 、node_exporter 的数据接入,使用详情参考[taosAdapter](/reference/taosadapter/)。
如果使用 collectd,修改其默认位置 `/etc/collectd/collectd.conf` 的配置文件为指向 taosAdapter 部署的节点 IP 地址和端口。假设 taosAdapter 的 IP 地址为 192.168.1.130,端口为 6046,配置如下:
@@ -66,7 +65,7 @@ LoadPlugin write_tsdb
- **调整看板(Dashborad)系统**
-在数据能够正常写入 TDengine 后,可以调整适配 Grafana 将写入 TDengine 的数据可视化呈现出来。获取和使用 TDengine 提供的 Grafana 插件请参考[与其他工具的连接](https://www.taosdata.com/cn/documentation/connections#grafana)。
+在数据能够正常写入 TDengine 后,可以调整适配 Grafana 将写入 TDengine 的数据可视化呈现出来。获取和使用 TDengine 提供的 Grafana 插件请参考[与其他工具的连接](/third-party/grafana)。
TDengine 提供了默认的两套 Dashboard 模板,用户只需要将 Grafana 目录下的模板导入到 Grafana 中即可激活使用。
@@ -361,7 +360,7 @@ WHERE ts>=1510560000 AND ts<=1515000009
### 计算资源估算
-由于物联网数据的特殊性,数据产生的频率固定以后,TDengine 写入的过程对于(计算和存储)资源消耗都保持一个相对固定的量。《[TDengine 的运营与维护](https://www.taosdata.com/cn/documentation/administrator)》上的描述,该系统中每秒 22000 个写入,消耗 CPU 不到 1 个核。
+由于物联网数据的特殊性,数据产生的频率固定以后,TDengine 写入的过程对于(计算和存储)资源消耗都保持一个相对固定的量。《[TDengine 运维指南](/operation/)》上的描述,该系统中每秒 22000 个写入,消耗 CPU 不到 1 个核。
在针对查询所需要消耗的 CPU 资源的估算上,假设应用要求数据库提供的 QPS 为 10000,每次查询消耗的 CPU 时间约 1 ms,那么每个核每秒提供的查询为 1000 QPS,满足 10000 QPS 的查询请求,至少需要 10 个核。为了让系统整体上 CPU 负载小于 50%,整个集群需要 10 个核的两倍,即 20 个核。
@@ -385,11 +384,11 @@ TDengine 提供了丰富的帮助文档说明集群安装、部署的诸多方
为确保系统能够正常获取运行的必要信息。请在服务端正确设置以下关键参数:
-FQDN、firstEp、secondEP、dataDir、logDir、tmpDir、serverPort。各参数的具体含义及设置的要求,可参见文档《[TDengine 集群安装、管理](https://www.taosdata.com/cn/documentation/cluster)》
+FQDN、firstEp、secondEP、dataDir、logDir、tmpDir、serverPort。各参数的具体含义及设置的要求,可参见文档《[TDengine 集群安装、管理](/cluster/)》
按照相同的步骤,在需要运行的节点上设置参数,并启动 taosd 服务,然后添加 Dnode 到集群中。
-最后启动 taos,执行命令 show dnodes,如果能看到所有的加入集群的节点,那么集群顺利搭建完成。具体的操作流程及注意事项,请参阅文档《[TDengine 集群安装、管理](https://www.taosdata.com/cn/documentation/cluster)》
+最后启动 taos,执行命令 show dnodes,如果能看到所有的加入集群的节点,那么集群顺利搭建完成。具体的操作流程及注意事项,请参阅文档《[TDengine 集群安装、管理](/cluster/)》
## 附录 4: 超级表名称
@@ -397,5 +396,5 @@ FQDN、firstEp、secondEP、dataDir、logDir、tmpDir、serverPort。各参数
## 附录 5:参考文章
-1. [使用 TDengine + collectd/StatsD + Grafana 快速搭建 IT 运维监控系统](https://www.taosdata.com/cn/documentation20/devops/collectd)
-2. [通过 collectd 将采集数据直接写入 TDengine](https://www.taosdata.com/cn/documentation20/insert#collectd)
+1. [使用 TDengine + collectd/StatsD + Grafana 快速搭建 IT 运维监控系统](/application/collectd/)
+2. [通过 collectd 将采集数据直接写入 TDengine](/third-party/collectd/)
diff --git a/docs-cn/15-application/_category_.yml b/docs-cn/25-application/_category_.yml
similarity index 69%
rename from docs-cn/15-application/_category_.yml
rename to docs-cn/25-application/_category_.yml
index 725833f45110361f27e6fcb7015b4e2413fda7bb..141c9269b50a2155391543ecea1dfe5c918e113c 100644
--- a/docs-cn/15-application/_category_.yml
+++ b/docs-cn/25-application/_category_.yml
@@ -1,3 +1,4 @@
label: 应用实践
link:
+ slug: /application/
type: generated-index
diff --git a/docs-cn/27-train-faq/01-faq.md b/docs-cn/27-train-faq/01-faq.md
new file mode 100644
index 0000000000000000000000000000000000000000..fac12cb44eaff68ec74d3019e537aecb0291410f
--- /dev/null
+++ b/docs-cn/27-train-faq/01-faq.md
@@ -0,0 +1,224 @@
+---
+title: 常见问题及反馈
+---
+
+## 问题反馈
+
+如果 FAQ 中的信息不能够帮到您,需要 TDengine 技术团队的技术支持与协助,请将以下两个目录中内容打包:
+
+1. /var/log/taos (如果没有修改过默认路径)
+2. /etc/taos
+
+附上必要的问题描述,包括使用的 TDengine 版本信息、平台环境信息、发生该问题的执行操作、出现问题的表征及大概的时间,在 [GitHub](https://github.com/taosdata/TDengine) 提交 issue。
+
+为了保证有足够的 debug 信息,如果问题能够重复,请修改/etc/taos/taos.cfg 文件,最后面添加一行“debugFlag 135"(不带引号本身),然后重启 taosd, 重复问题,然后再递交。也可以通过如下 SQL 语句,临时设置 taosd 的日志级别。
+
+```
+ alter dnode debugFlag 135;
+```
+
+但系统正常运行时,请一定将 debugFlag 设置为 131,否则会产生大量的日志信息,降低系统效率。
+
+## 常见问题列表
+
+**1. TDengine2.0 之前的版本升级到 2.0 及以上的版本应该注意什么?☆☆☆**
+
+ 2.0 版在之前版本的基础上,进行了完全的重构,配置文件和数据文件是不兼容的。在升级之前务必进行如下操作:
+
+ 1. 删除配置文件,执行 `sudo rm -rf /etc/taos/taos.cfg`
+ 2. 删除日志文件,执行 `sudo rm -rf /var/log/taos/`
+ 3. 确保数据已经不再需要的前提下,删除数据文件,执行 `sudo rm -rf /var/lib/taos/`
+ 4. 安装最新稳定版本的 TDengine
+ 5. 如果需要迁移数据或者数据文件损坏,请联系涛思数据官方技术支持团队,进行协助解决
+
+**2. Windows 平台下 JDBCDriver 找不到动态链接库,怎么办?**
+
+ 请看为此问题撰写的[技术博客](https://www.taosdata.com/blog/2019/12/03/950.html)。
+
+**3. 创建数据表时提示 more dnodes are needed**
+
+ 请看为此问题撰写的[技术博客](https://www.taosdata.com/blog/2019/12/03/965.html)。
+
+**4. 如何让 TDengine crash 时生成 core 文件?**
+
+ 请看为此问题撰写的[技术博客](https://www.taosdata.com/blog/2019/12/06/974.html)。
+
+**5. 遇到错误“Unable to establish connection”, 我怎么办?**
+
+ 客户端遇到连接故障,请按照下面的步骤进行检查:
+
+ 1. 检查网络环境
+
+ - 云服务器:检查云服务器的安全组是否打开 TCP/UDP 端口 6030-6042 的访问权限
+ - 本地虚拟机:检查网络能否 ping 通,尽量避免使用`localhost` 作为 hostname
+ - 公司服务器:如果为 NAT 网络环境,请务必检查服务器能否将消息返回值客户端
+
+ 2. 确保客户端与服务端版本号是完全一致的,开源社区版和企业版也不能混用
+
+ 3. 在服务器,执行 `systemctl status taosd` 检查*taosd*运行状态。如果没有运行,启动*taosd*
+
+ 4. 确认客户端连接时指定了正确的服务器 FQDN (Fully Qualified Domain Name —— 可在服务器上执行 Linux 命令 hostname -f 获得),FQDN 配置参考:[一篇文章说清楚 TDengine 的 FQDN](https://www.taosdata.com/blog/2020/09/11/1824.html)。
+
+ 5. ping 服务器 FQDN,如果没有反应,请检查你的网络,DNS 设置,或客户端所在计算机的系统 hosts 文件。如果部署的是 TDengine 集群,客户端需要能 ping 通所有集群节点的 FQDN。
+
+ 6. 检查防火墙设置(Ubuntu 使用 ufw status,CentOS 使用 firewall-cmd --list-port),确认 TCP/UDP 端口 6030-6042 是打开的
+
+ 7. 对于 Linux 上的 JDBC(ODBC, Python, Go 等接口类似)连接, 确保*libtaos.so*在目录*/usr/local/taos/driver*里, 并且*/usr/local/taos/driver*在系统库函数搜索路径*LD_LIBRARY_PATH*里
+
+ 8. 对于 Windows 上的 JDBC, ODBC, Python, Go 等连接,确保*C:\TDengine\driver\taos.dll*在你的系统库函数搜索目录里 (建议*taos.dll*放在目录 _C:\Windows\System32_)
+
+ 9. 如果仍不能排除连接故障
+
+ - Linux 系统请使用命令行工具 nc 来分别判断指定端口的 TCP 和 UDP 连接是否通畅
+ 检查 UDP 端口连接是否工作:`nc -vuz {hostIP} {port} `
+ 检查服务器侧 TCP 端口连接是否工作:`nc -l {port}`
+ 检查客户端侧 TCP 端口连接是否工作:`nc {hostIP} {port}`
+
+ - Windows 系统请使用 PowerShell 命令 Net-TestConnection -ComputerName {fqdn} -Port {port} 检测服务段端口是否访问
+
+ 10. 也可以使用 taos 程序内嵌的网络连通检测功能,来验证服务器和客户端之间指定的端口连接是否通畅(包括 TCP 和 UDP):[TDengine 内嵌网络检测工具使用指南](https://www.taosdata.com/blog/2020/09/08/1816.html)。
+
+**6. 遇到错误“Unexpected generic error in RPC”或者“Unable to resolve FQDN”,我怎么办?**
+
+ 产生这个错误,是由于客户端或数据节点无法解析 FQDN(Fully Qualified Domain Name)导致。对于 TAOS Shell 或客户端应用,请做如下检查:
+
+ 1. 请检查连接的服务器的 FQDN 是否正确,FQDN 配置参考:[一篇文章说清楚 TDengine 的 FQDN](https://www.taosdata.com/blog/2020/09/11/1824.html)
+ 2. 如果网络配置有 DNS server,请检查是否正常工作
+ 3. 如果网络没有配置 DNS server,请检查客户端所在机器的 hosts 文件,查看该 FQDN 是否配置,并是否有正确的 IP 地址
+ 4. 如果网络配置 OK,从客户端所在机器,你需要能 Ping 该连接的 FQDN,否则客户端是无法连接服务器的
+ 5. 如果服务器曾经使用过 TDengine,且更改过 hostname,建议检查 data 目录的 dnodeEps.json 是否符合当前配置的 EP,路径默认为/var/lib/taos/dnode。正常情况下,建议更换新的数据目录或者备份后删除以前的数据目录,这样可以避免该问题。
+ 6. 检查/etc/hosts 和/etc/hostname 是否是预配置的 FQDN
+
+**7. 虽然语法正确,为什么我还是得到 "Invalid SQL" 错误**
+
+ 如果你确认语法正确,2.0 之前版本,请检查 SQL 语句长度是否超过 64K。如果超过,也会返回这个错误。
+
+**8. 是否支持 validation queries?**
+
+ TDengine 还没有一组专用的 validation queries。然而建议你使用系统监测的数据库”log"来做。
+
+
+
+**9. 我可以删除或更新一条记录吗?**
+
+ TDengine 目前尚不支持删除功能,未来根据用户需求可能会支持。
+
+ 从 2.0.8.0 开始,TDengine 支持更新已经写入数据的功能。使用更新功能需要在创建数据库时使用 UPDATE 1 参数,之后可以使用 INSERT INTO 命令更新已经写入的相同时间戳数据。UPDATE 参数不支持 ALTER DATABASE 命令修改。没有使用 UPDATE 1 参数创建的数据库,写入相同时间戳的数据不会修改之前的数据,也不会报错。
+
+ 另需注意,在 UPDATE 设置为 0 时,后发送的相同时间戳的数据会被直接丢弃,但并不会报错,而且仍然会被计入 affected rows (所以不能利用 INSERT 指令的返回信息进行时间戳查重)。这样设计的主要原因是,TDengine 把写入的数据看做一个数据流,无论时间戳是否出现冲突,TDengine 都认为产生数据的原始设备真实地产生了这样的数据。UPDATE 参数只是控制这样的流数据在进行持久化时要怎样处理——UPDATE 为 0 时,表示先写入的数据覆盖后写入的数据;而 UPDATE 为 1 时,表示后写入的数据覆盖先写入的数据。这种覆盖关系如何选择,取决于对数据的后续使用和统计中,希望以先还是后生成的数据为准。
+
+ 此外,从 2.1.7.0 版本开始,支持将 UPDATE 参数设为 2,表示“支持部分列更新”。也即,当 UPDATE 设为 1 时,如果更新一个数据行,其中某些列没有提供取值,那么这些列会被设为 NULL;而当 UPDATE 设为 2 时,如果更新一个数据行,其中某些列没有提供取值,那么这些列会保持原有数据行中的对应值。
+
+**10. 我怎么创建超过 1024 列的表?**
+
+ 使用 2.0 及其以上版本,默认支持 1024 列;2.0 之前的版本,TDengine 最大允许创建 250 列的表。但是如果确实超过限值,建议按照数据特性,逻辑地将这个宽表分解成几个小表。(从 2.1.7.0 版本开始,表的最大列数增加到了 4096 列。)
+
+**11. 最有效的写入数据的方法是什么?**
+
+ 批量插入。每条写入语句可以一张表同时插入多条记录,也可以同时插入多张表的多条记录。
+
+**12. Windows 系统下插入的 nchar 类数据中的汉字被解析成了乱码如何解决?**
+
+ Windows 下插入 nchar 类的数据中如果有中文,请先确认系统的地区设置成了中国(在 Control Panel 里可以设置),这时 cmd 中的`taos`客户端应该已经可以正常工作了;如果是在 IDE 里开发 Java 应用,比如 Eclipse, Intellij,请确认 IDE 里的文件编码为 GBK(这是 Java 默认的编码类型),然后在生成 Connection 时,初始化客户端的配置,具体语句如下:
+
+ ```JAVA
+ Class.forName("com.taosdata.jdbc.TSDBDriver");
+ Properties properties = new Properties();
+ properties.setProperty(TSDBDriver.LOCALE_KEY, "UTF-8");
+ Connection = DriverManager.getConnection(url, properties);
+ ```
+
+**13.JDBC 报错: the excuted SQL is not a DML or a DDL?**
+
+ 请更新至最新的 JDBC 驱动
+
+ ```xml
+
+ com.taosdata.jdbc
+ taos-jdbcdriver
+ 2.0.27
+
+ ```
+
+**14. taos connect failed, reason: invalid timestamp**
+
+ 常见原因是服务器和客户端时间没有校准,可以通过和时间服务器同步的方式(Linux 下使用 ntpdate 命令,Windows 在系统时间设置中选择自动同步)校准。
+
+**15. 表名显示不全**
+
+ 由于 taos shell 在终端中显示宽度有限,有可能比较长的表名显示不全,如果按照显示的不全的表名进行相关操作会发生 Table does not exist 错误。解决方法可以是通过修改 taos.cfg 文件中的设置项 maxBinaryDisplayWidth, 或者直接输入命令 set max_binary_display_width 100。或者在命令结尾使用 \G 参数来调整结果的显示方式。
+
+**16. 如何进行数据迁移?**
+
+ TDengine 是根据 hostname 唯一标志一台机器的,在数据文件从机器 A 移动机器 B 时,注意如下两件事:
+
+ - 2.0.0.0 至 2.0.6.x 的版本,重新配置机器 B 的 hostname 为机器 A 的 hostname。
+ - 2.0.7.0 及以后的版本,到/var/lib/taos/dnode 下,修复 dnodeEps.json 的 dnodeId 对应的 FQDN,重启。确保机器内所有机器的此文件是完全相同的。
+ - 1.x 和 2.x 版本的存储结构不兼容,需要使用迁移工具或者自己开发应用导出导入数据。
+
+**17. 如何在命令行程序 taos 中临时调整日志级别**
+
+ 为了调试方便,从 2.0.16 版本开始,命令行程序 taos 新增了与日志记录相关的两条指令:
+
+ ```sql
+ ALTER LOCAL flag_name flag_value;
+ ```
+
+ 其含义是,在当前的命令行程序下,修改一个特定模块的日志记录级别(只对当前命令行程序有效,如果 taos 命令行程序重启,则需要重新设置):
+
+ - flag_name 的取值可以是:debugFlag,cDebugFlag,tmrDebugFlag,uDebugFlag,rpcDebugFlag
+ - flag_value 的取值可以是:131(输出错误和警告日志),135( 输出错误、警告和调试日志),143( 输出错误、警告、调试和跟踪日志)
+
+ ```sql
+ ALTER LOCAL RESETLOG;
+ ```
+
+ 其含义是,清空本机所有由客户端生成的日志文件。
+
+
+
+**18. 时间戳的时区信息是怎样处理的?**
+
+ TDengine 中时间戳的时区总是由客户端进行处理,而与服务端无关。具体来说,客户端会对 SQL 语句中的时间戳进行时区转换,转为 UTC 时区(即 Unix 时间戳——Unix Timestamp)再交由服务端进行写入和查询;在读取数据时,服务端也是采用 UTC 时区提供原始数据,客户端收到后再根据本地设置,把时间戳转换为本地系统所要求的时区进行显示。
+
+ 客户端在处理时间戳字符串时,会采取如下逻辑:
+
+ 1. 在未做特殊设置的情况下,客户端默认使用所在操作系统的时区设置。
+ 2. 如果在 taos.cfg 中设置了 timezone 参数,则客户端会以这个配置文件中的设置为准。
+ 3. 如果在 C/C++/Java/Python 等各种编程语言的 Connector Driver 中,在建立数据库连接时显式指定了 timezone,那么会以这个指定的时区设置为准。例如 Java Connector 的 JDBC URL 中就有 timezone 参数。
+ 4. 在书写 SQL 语句时,也可以直接使用 Unix 时间戳(例如 `1554984068000`)或带有时区的时间戳字符串,也即以 RFC 3339 格式(例如 `2013-04-12T15:52:01.123+08:00`)或 ISO-8601 格式(例如 `2013-04-12T15:52:01.123+0800`)来书写时间戳,此时这些时间戳的取值将不再受其他时区设置的影响。
+
+
+
+**19. TDengine 都会用到哪些网络端口?**
+
+ 在 TDengine 2.0 版本中,会用到以下这些网络端口(以默认端口 6030 为前提进行说明,如果修改了配置文件中的设置,那么这里列举的端口都会出现变化),管理员可以参考这里的信息调整防火墙设置:
+
+| 协议 | 默认端口 | 用途说明 | 修改方法 |
+| :--- | :-------- | :---------------------------------- | :--------------------------------------------------------------------------------------------------------------------------------- |
+| TCP | 6030 | 客户端与服务端之间通讯。 | 由配置文件设置 serverPort 决定。 |
+| TCP | 6035 | 多节点集群的节点间通讯。 | 随 serverPort 端口变化。 |
+| TCP | 6040 | 多节点集群的节点间数据同步。 | 随 serverPort 端口变化。 |
+| TCP | 6041 | 客户端与服务端之间的 RESTful 通讯。 | 随 serverPort 端口变化。注意 taosAdapter 配置或有不同,请参考相应[文档](/reference/taosadapter/)。 |
+| TCP | 6042 | Arbitrator 的服务端口。 | 随 Arbitrator 启动参数设置变化。 |
+| TCP | 6043 | TaosKeeper 监控服务端口。 | 随 TaosKeeper 启动参数设置变化。 |
+| TCP | 6044 | 支持 StatsD 的数据接入端口。 | 随 taosAdapter 启动参数设置变化(2.3.0.1+以上版本)。 |
+| TCP | 6045 | 支持 collectd 数据接入端口。 | 随 taosAdapter 启动参数设置变化(2.3.0.1+以上版本)。 |
+| TCP | 6060 | 企业版内 Monitor 服务的网络端口。 | |
+| UDP | 6030-6034 | 客户端与服务端之间通讯。 | 随 serverPort 端口变化。 |
+| UDP | 6035-6039 | 多节点集群的节点间通讯。 | 随 serverPort 端口变化。 |
+
+**20. go 语言编写组件编译失败怎样解决?**
+
+ 新版本 TDengine 2.3.0.0 包含一个使用 go 语言开发的 taosAdapter 独立组件,需要单独运行,取代之前 taosd 内置的 httpd ,提供包含原 httpd 功能以及支持多种其他软件(Prometheus、Telegraf、collectd、StatsD 等)的数据接入功能。
+ 使用最新 develop 分支代码编译需要先 `git submodule update --init --recursive` 下载 taosAdapter 仓库代码后再编译。
+
+ 目前编译方式默认自动编译 taosAdapter。go 语言版本要求 1.14 以上,如果发生 go 编译错误,往往是国内访问 go mod 问题,可以通过设置 go 环境变量来解决:
+
+ ```sh
+ go env -w GO111MODULE=on
+ go env -w GOPROXY=https://goproxy.cn,direct
+ ```
+
+ 如果希望继续使用之前的内置 httpd,可以关闭 taosAdapter 编译,使用
+ `cmake .. -DBUILD_HTTP=true` 使用原来内置的 httpd。
diff --git a/docs-cn/17-train-fqa/02-video.mdx b/docs-cn/27-train-faq/02-video.mdx
similarity index 97%
rename from docs-cn/17-train-fqa/02-video.mdx
rename to docs-cn/27-train-faq/02-video.mdx
index 767b154fd34f3898a269bb505999a9de2bf11799..b644412332fe817ea7fdc2c9ddc176ecc9858c56 100644
--- a/docs-cn/17-train-fqa/02-video.mdx
+++ b/docs-cn/27-train-faq/02-video.mdx
@@ -1,6 +1,6 @@
-# 视频教程
-
-##
+---
+title: 视频教程
+---
## 技术公开课
diff --git a/docs-cn/17-train-fqa/03-docker.md b/docs-cn/27-train-faq/03-docker.md
similarity index 96%
rename from docs-cn/17-train-fqa/03-docker.md
rename to docs-cn/27-train-faq/03-docker.md
index 54b94c9abae50d5a6581ed4bce321bc5d5e761f3..a86b72a39e94c4db7d3b229fba2260df36ef2a88 100644
--- a/docs-cn/17-train-fqa/03-docker.md
+++ b/docs-cn/27-train-faq/03-docker.md
@@ -1,4 +1,6 @@
-# 通过 Docker 快速体验 TDengine
+---
+title: 通过 Docker 快速体验 TDengine
+---
虽然并不推荐在生产环境中通过 Docker 来部署 TDengine 服务,但 Docker 工具能够很好地屏蔽底层操作系统的环境差异,很适合在开发测试或初次体验时用于安装运行 TDengine 的工具集。特别是,借助 Docker,能够比较方便地在 macOS 和 Windows 系统上尝试 TDengine,而无需安装虚拟机或额外租用 Linux 服务器。另外,从 2.0.14.0 版本开始,TDengine 提供的镜像已经可以同时支持 X86-64、X86、arm64、arm32 平台,像 NAS、树莓派、嵌入式开发板之类可以运行 docker 的非主流计算机也可以基于本文档轻松体验 TDengine。
@@ -24,7 +26,7 @@ $ docker run -d -p 6030-6049:6030-6049 -p 6030-6049:6030-6049/udp tdengine/tdeng
526aa188da767ae94b244226a2b2eec2b5f17dd8eff592893d9ec0cd0f3a1ccd
```
-这条命令,启动一个运行了 TDengine server 的 docker 容器,并且将容器的 6030 到 6049 端口映射到宿主机的 6030 到 6049 端口上。如果宿主机已经运行了 TDengine server 并占用了相同端口,需要映射容器的端口到不同的未使用端口段。(详情参见 [TDengine 2.0 端口说明](https://www.taosdata.com/cn/documentation/faq#port))。为了支持 TDengine 客户端操作 TDengine server 服务, TCP 和 UDP 端口都需要打开。
+这条命令,启动一个运行了 TDengine server 的 docker 容器,并且将容器的 6030 到 6049 端口映射到宿主机的 6030 到 6049 端口上。如果宿主机已经运行了 TDengine server 并占用了相同端口,需要映射容器的端口到不同的未使用端口段。(详情参见 [TDengine 2.0 端口说明](/train-faq/faq#port)。为了支持 TDengine 客户端操作 TDengine server 服务, TCP 和 UDP 端口都需要打开。
- **docker run**:通过 Docker 运行一个容器
- **-d**:让容器在后台运行
@@ -88,7 +90,7 @@ taos>
TDengine 终端成功连接服务端,打印出了欢迎消息和版本信息。如果失败,会有错误信息打印出来。
-在 TDengine 终端中,可以通过 SQL 命令来创建/删除数据库、表、超级表等,并可以进行插入和查询操作。具体可以参考 [TAOS SQL 说明文档](https://www.taosdata.com/cn/documentation/taos-sql)。
+在 TDengine 终端中,可以通过 SQL 命令来创建/删除数据库、表、超级表等,并可以进行插入和查询操作。具体可以参考 [TAOS SQL 说明文档](/taos-sql/)。
### 在宿主机访问 Docker 容器中的 TDengine server
@@ -115,15 +117,15 @@ curl -u root:taosdata -d 'show databases' 127.0.0.1:6041/rest/sql
{"status":"succ","head":["name","created_time","ntables","vgroups","replica","quorum","days","keep0,keep1,keep(D)","cache(MB)","blocks","minrows","maxrows","wallevel","fsync","comp","cachelast","precision","update","status"],"column_meta":[["name",8,32],["created_time",9,8],["ntables",4,4],["vgroups",4,4],["replica",3,2],["quorum",3,2],["days",3,2],["keep0,keep1,keep(D)",8,24],["cache(MB)",4,4],["blocks",4,4],["minrows",4,4],["maxrows",4,4],["wallevel",2,1],["fsync",4,4],["comp",2,1],["cachelast",2,1],["precision",8,3],["update",2,1],["status",8,10]],"data":[["test","2021-08-18 06:01:11.021",10000,4,1,1,10,"3650,3650,3650",16,6,100,4096,1,3000,2,0,"ms",0,"ready"],["log","2021-08-18 05:51:51.065",4,1,1,1,10,"30,30,30",1,3,100,4096,1,3000,2,0,"us",0,"ready"]],"rows":2}
```
-这条命令,通过 RESTful 接口访问 TDengine server,这时连接的是本机的 6041 端口,可见连接成功。
+这条命令,通过 REST API 访问 TDengine server,这时连接的是本机的 6041 端口,可见连接成功。
-TDengine RESTful 接口详情请参考[官方文档](https://www.taosdata.com/cn/documentation/connector#restful)。
+TDengine REST API 详情请参考[官方文档](/reference/rest-api/)。
### 使用 Docker 容器运行 TDengine server 和 taosAdapter
在 TDegnine 2.4.0.0 之后版本的 Docker 容器,开始提供一个独立运行的组件 taosAdapter,代替之前版本 TDengine 中 taosd 进程中内置的 http server。taosAdapter 支持通过 RESTful 接口对 TDengine server 的数据写入和查询能力,并提供和 InfluxDB/OpenTSDB 兼容的数据摄取接口,允许 InfluxDB/OpenTSDB 应用程序无缝移植到 TDengine。在新版本 Docker 镜像中,默认启用了 taosAdapter,也可以使用 docker run 命令中设置 TAOS_DISABLE_ADAPTER=true 来禁用 taosAdapter;也可以在 docker run 命令中单独使用 taosAdapter,而不运行 taosd 。
-注意:如果容器中运行 taosAdapter,需要根据需要映射其他端口,具体端口默认配置和修改方法请参考[taosAdapter 文档](https://github.com/taosdata/taosadapter/blob/develop/README-CN.md)。
+注意:如果容器中运行 taosAdapter,需要根据需要映射其他端口,具体端口默认配置和修改方法请参考[taosAdapter 文档](/reference/taosadapter/)。
使用 docker 运行 TDengine 2.4.0.4 版本镜像(taosd + taosAdapter):
diff --git a/docs-cn/17-train-fqa/_category_.yml b/docs-cn/27-train-faq/_category_.yml
similarity index 74%
rename from docs-cn/17-train-fqa/_category_.yml
rename to docs-cn/27-train-faq/_category_.yml
index 27e8b47b49ee57d059b3088e583bf2c6a9d4df99..034d5894b9aea00e43caf4df21cb39487d8baf7b 100644
--- a/docs-cn/17-train-fqa/_category_.yml
+++ b/docs-cn/27-train-faq/_category_.yml
@@ -1,3 +1,4 @@
label: FAQ、教程及其它
link:
+ slug: /train-faq/
type: generated-index
diff --git a/docs-examples/.gitignore b/docs-examples/.gitignore
new file mode 100644
index 0000000000000000000000000000000000000000..7ed6d403bf5f64c0cb230265b4dffee609dea93b
--- /dev/null
+++ b/docs-examples/.gitignore
@@ -0,0 +1,3 @@
+.vscode
+*.lock
+.idea
\ No newline at end of file
diff --git a/docs-examples/.gitignre b/docs-examples/.gitignre
new file mode 100644
index 0000000000000000000000000000000000000000..0853156c65c2c6c1b693290e74c3ee630bcaac19
--- /dev/null
+++ b/docs-examples/.gitignre
@@ -0,0 +1,2 @@
+.vscode
+*.lock
\ No newline at end of file
diff --git a/docs-examples/R/connect_native.r b/docs-examples/R/connect_native.r
new file mode 100644
index 0000000000000000000000000000000000000000..18c142872be5efaa7167c10a25f62bcb9fbf5a52
--- /dev/null
+++ b/docs-examples/R/connect_native.r
@@ -0,0 +1,16 @@
+if (! "RJDBC" %in% installed.packages()[, "Package"]) {
+ install.packages('RJDBC', repos='http://cran.us.r-project.org')
+}
+
+# ANCHOR: demo
+library("DBI")
+library("rJava")
+library("RJDBC")
+
+args<- commandArgs(trailingOnly = TRUE)
+driver_path = args[1] # path to jdbc-driver for example: "/root/taos-jdbcdriver-2.0.37-dist.jar"
+driver = JDBC("com.taosdata.jdbc.TSDBDriver", driver_path)
+conn = dbConnect(driver, "jdbc:TAOS://127.0.0.1:6030/?user=root&password=taosdata")
+dbGetQuery(conn, "SELECT server_version()")
+dbDisconnect(conn)
+# ANCHOR_END: demo
\ No newline at end of file
diff --git a/docs-examples/R/connect_rest.r b/docs-examples/R/connect_rest.r
new file mode 100644
index 0000000000000000000000000000000000000000..5ceec572fc26575dfc597983eeac3233bc4488ab
--- /dev/null
+++ b/docs-examples/R/connect_rest.r
@@ -0,0 +1,12 @@
+if (! "RJDBC" %in% installed.packages()[, "Package"]) {
+ install.packages('RJDBC', repos='http://cran.us.r-project.org')
+}
+
+library("DBI")
+library("rJava")
+library("RJDBC")
+driver_path = "/home/debug/build/lib/taos-jdbcdriver-2.0.38-dist.jar"
+driver = JDBC("com.taosdata.jdbc.rs.RestfulDriver", driver_path)
+conn = dbConnect(driver, "jdbc:TAOS-RS://localhost:6041?user=root&password=taosdata")
+dbGetQuery(conn, "SELECT server_version()")
+dbDisconnect(conn)
\ No newline at end of file
diff --git a/docs-examples/c/.gitignore b/docs-examples/c/.gitignore
new file mode 100644
index 0000000000000000000000000000000000000000..afe974314989a1e3aa4eee703738a9a960c18577
--- /dev/null
+++ b/docs-examples/c/.gitignore
@@ -0,0 +1,3 @@
+*
+!*.c
+!.gitignore
diff --git a/docs-examples/c/async_query_example.c b/docs-examples/c/async_query_example.c
new file mode 100644
index 0000000000000000000000000000000000000000..77002891bb4c03f7c7e32b329678e8a124f12a99
--- /dev/null
+++ b/docs-examples/c/async_query_example.c
@@ -0,0 +1,195 @@
+// compile with:
+// gcc -o async_query_example async_query_example.c -ltaos
+
+#include
+#include
+#include
+#include
+#include
+#include
+
+typedef int16_t VarDataLenT;
+
+#define TSDB_NCHAR_SIZE sizeof(int32_t)
+#define VARSTR_HEADER_SIZE sizeof(VarDataLenT)
+
+#define GET_FLOAT_VAL(x) (*(float *)(x))
+#define GET_DOUBLE_VAL(x) (*(double *)(x))
+
+#define varDataLen(v) ((VarDataLenT *)(v))[0]
+
+int printRow(char *str, TAOS_ROW row, TAOS_FIELD *fields, int numFields) {
+ int len = 0;
+ char split = ' ';
+
+ for (int i = 0; i < numFields; ++i) {
+ if (i > 0) {
+ str[len++] = split;
+ }
+
+ if (row[i] == NULL) {
+ len += sprintf(str + len, "%s", "NULL");
+ continue;
+ }
+
+ switch (fields[i].type) {
+ case TSDB_DATA_TYPE_TINYINT:
+ len += sprintf(str + len, "%d", *((int8_t *)row[i]));
+ break;
+
+ case TSDB_DATA_TYPE_UTINYINT:
+ len += sprintf(str + len, "%u", *((uint8_t *)row[i]));
+ break;
+
+ case TSDB_DATA_TYPE_SMALLINT:
+ len += sprintf(str + len, "%d", *((int16_t *)row[i]));
+ break;
+
+ case TSDB_DATA_TYPE_USMALLINT:
+ len += sprintf(str + len, "%u", *((uint16_t *)row[i]));
+ break;
+
+ case TSDB_DATA_TYPE_INT:
+ len += sprintf(str + len, "%d", *((int32_t *)row[i]));
+ break;
+
+ case TSDB_DATA_TYPE_UINT:
+ len += sprintf(str + len, "%u", *((uint32_t *)row[i]));
+ break;
+
+ case TSDB_DATA_TYPE_BIGINT:
+ len += sprintf(str + len, "%" PRId64, *((int64_t *)row[i]));
+ break;
+
+ case TSDB_DATA_TYPE_UBIGINT:
+ len += sprintf(str + len, "%" PRIu64, *((uint64_t *)row[i]));
+ break;
+
+ case TSDB_DATA_TYPE_FLOAT: {
+ float fv = 0;
+ fv = GET_FLOAT_VAL(row[i]);
+ len += sprintf(str + len, "%f", fv);
+ } break;
+
+ case TSDB_DATA_TYPE_DOUBLE: {
+ double dv = 0;
+ dv = GET_DOUBLE_VAL(row[i]);
+ len += sprintf(str + len, "%lf", dv);
+ } break;
+
+ case TSDB_DATA_TYPE_BINARY:
+ case TSDB_DATA_TYPE_NCHAR: {
+ int32_t charLen = varDataLen((char *)row[i] - VARSTR_HEADER_SIZE);
+ memcpy(str + len, row[i], charLen);
+ len += charLen;
+ } break;
+
+ case TSDB_DATA_TYPE_TIMESTAMP:
+ len += sprintf(str + len, "%" PRId64, *((int64_t *)row[i]));
+ break;
+
+ case TSDB_DATA_TYPE_BOOL:
+ len += sprintf(str + len, "%d", *((int8_t *)row[i]));
+ default:
+ break;
+ }
+ }
+
+ return len;
+}
+
+void printHeader(TAOS_RES *res) {
+ int numFields = taos_num_fields(res);
+ TAOS_FIELD *fields = taos_fetch_fields(res);
+ char header[256] = {0};
+ int len = 0;
+ for (int i = 0; i < numFields; ++i) {
+ len += sprintf(header + len, "%s ", fields[i].name);
+ }
+ puts(header);
+}
+
+// ANCHOR: demo
+
+/**
+ * @brief call back function of taos_fetch_row_a
+ *
+ * @param param : the third parameter you passed to taos_fetch_row_a
+ * @param res : pointer of TAOS_RES
+ * @param numOfRow : number of rows fetched in this batch. will be 0 if there is no more data.
+ * @return void*
+ */
+void *fetch_row_callback(void *param, TAOS_RES *res, int numOfRow) {
+ printf("numOfRow = %d \n", numOfRow);
+ int numFields = taos_num_fields(res);
+ TAOS_FIELD *fields = taos_fetch_fields(res);
+ TAOS *_taos = (TAOS *)param;
+ if (numOfRow > 0) {
+ for (int i = 0; i < numOfRow; ++i) {
+ TAOS_ROW row = taos_fetch_row(res);
+ char temp[256] = {0};
+ printRow(temp, row, fields, numFields);
+ puts(temp);
+ }
+ taos_fetch_rows_a(res, fetch_row_callback, _taos);
+ } else {
+ printf("no more data, close the connection.\n");
+ taos_free_result(res);
+ taos_close(_taos);
+ taos_cleanup();
+ }
+}
+
+/**
+ * @brief callback function of taos_query_a
+ *
+ * @param param: the fourth parameter you passed to taos_query_a
+ * @param res : the result set
+ * @param code : status code
+ * @return void*
+ */
+void *select_callback(void *param, TAOS_RES *res, int code) {
+ printf("query callback ...\n");
+ TAOS *_taos = (TAOS *)param;
+ if (code == 0 && res) {
+ printHeader(res);
+ taos_fetch_rows_a(res, fetch_row_callback, _taos);
+ } else {
+ printf("failed to exeuce taos_query. error: %s\n", taos_errstr(res));
+ taos_free_result(res);
+ taos_close(_taos);
+ taos_cleanup();
+ exit(EXIT_FAILURE);
+ }
+}
+
+int main() {
+ TAOS *taos = taos_connect("localhost", "root", "taosdata", "power", 6030);
+ if (taos == NULL) {
+ puts("failed to connect to server");
+ exit(EXIT_FAILURE);
+ }
+ // param one is the connection returned by taos_connect.
+ // param two is the SQL to execute.
+ // param three is the callback function.
+ // param four can be any pointer. It will be passed to your callback function as the first parameter. we use taos
+ // here, because we want to close it after getting data.
+ taos_query_a(taos, "SELECT * FROM meters", select_callback, taos);
+ sleep(1);
+}
+
+// output:
+// query callback ...
+// ts current voltage phase location groupid
+// numOfRow = 8
+// 1538548685000 10.300000 219 0.310000 beijing.chaoyang 2
+// 1538548695000 12.600000 218 0.330000 beijing.chaoyang 2
+// 1538548696800 12.300000 221 0.310000 beijing.chaoyang 2
+// 1538548696650 10.300000 218 0.250000 beijing.chaoyang 3
+// 1538548685500 11.800000 221 0.280000 beijing.haidian 2
+// 1538548696600 13.400000 223 0.290000 beijing.haidian 2
+// 1538548685000 10.800000 223 0.290000 beijing.haidian 3
+// 1538548686500 11.500000 221 0.350000 beijing.haidian 3
+// numOfRow = 0
+// no more data, close the connection.
+// ANCHOR_END: demo
\ No newline at end of file
diff --git a/docs-examples/c/connect_example b/docs-examples/c/connect_example
deleted file mode 100644
index 1d9451cbf6724d51dbbc9baeba97d779461b2a5d..0000000000000000000000000000000000000000
Binary files a/docs-examples/c/connect_example and /dev/null differ
diff --git a/docs-examples/c/connect_example.c b/docs-examples/c/connect_example.c
index a64bc43361a05ba91b8637a15c7379fc3a2aef12..ff0891e08267840fd5141d1b4271109d832c1c51 100644
--- a/docs-examples/c/connect_example.c
+++ b/docs-examples/c/connect_example.c
@@ -1,13 +1,24 @@
// compile with
-// gcc connect_example.c -o connect_example -I /usr/local/taos/include -L /usr/local/taos/driver -ltaos
+// gcc connect_example.c -o connect_example -ltaos
#include
+#include
#include "taos.h"
-#include "taoserror.h"
int main() {
- // if don't want to connect to a default db, set it to NULL.
+ const char *host = "localhost";
+ const char *user = "root";
+ const char *passwd = "taosdata";
+ // if don't want to connect to a default db, set it to NULL or ""
const char *db = NULL;
- TAOS *taos = taos_connect("localhost", "root", "taosdata", db, 6030);
- printf("Connected\n");
- taos_close(taos);
+ uint16_t port = 0; // 0 means use the default port
+ TAOS *taos = taos_connect(host, user, passwd, db, port);
+ if (taos == NULL) {
+ int errono = taos_errno(NULL);
+ char *msg = taos_errstr(NULL);
+ printf("%d, %s\n", errono, msg);
+ } else {
+ printf("connected\n");
+ taos_close(taos);
+ }
+ taos_cleanup();
}
diff --git a/docs-examples/c/error_handle_example.c b/docs-examples/c/error_handle_example.c
new file mode 100644
index 0000000000000000000000000000000000000000..36bb7f12f77a46230add5af82b68e6fb86ddfe77
--- /dev/null
+++ b/docs-examples/c/error_handle_example.c
@@ -0,0 +1,24 @@
+// compile with
+// gcc error_handle_example.c -o error_handle_example -ltaos
+#include
+#include
+#include "taos.h"
+
+int main() {
+ const char *host = "localhost";
+ const char *user = "root";
+ const char *passwd = "taosdata";
+ // if don't want to connect to a default db, set it to NULL or ""
+ const char *db = "notexist";
+ uint16_t port = 0; // 0 means use the default port
+ TAOS *taos = taos_connect(host, user, passwd, db, port);
+ if (taos == NULL) {
+ int errono = taos_errno(NULL);
+ char *msg = taos_errstr(NULL);
+ printf("%d, %s\n", errono, msg);
+ } else {
+ printf("connected\n");
+ taos_close(taos);
+ }
+ taos_cleanup();
+}
diff --git a/docs-examples/c/insert_example.c b/docs-examples/c/insert_example.c
new file mode 100644
index 0000000000000000000000000000000000000000..ca12be9314efbda707dbd05449c746794c209743
--- /dev/null
+++ b/docs-examples/c/insert_example.c
@@ -0,0 +1,51 @@
+// compile with
+// gcc -o insert_example insert_example.c -ltaos
+#include
+#include
+#include "taos.h"
+
+
+/**
+ * @brief execute sql and print affected rows.
+ *
+ * @param taos
+ * @param sql
+ */
+void executeSQL(TAOS *taos, const char *sql) {
+ TAOS_RES *res = taos_query(taos, sql);
+ int code = taos_errno(res);
+ if (code != 0) {
+ printf("Error code: %d; Message: %s\n", code, taos_errstr(res));
+ taos_free_result(res);
+ taos_close(taos);
+ exit(EXIT_FAILURE);
+ }
+ int affectedRows = taos_affected_rows(res);
+ printf("affected rows %d\n", affectedRows);
+ taos_free_result(res);
+}
+
+
+
+int main() {
+ TAOS *taos = taos_connect("localhost", "root", "taosdata", NULL, 6030);
+ if (taos == NULL) {
+ printf("failed to connect to server\n");
+ exit(EXIT_FAILURE);
+ }
+ executeSQL(taos, "CREATE DATABASE power");
+ executeSQL(taos, "USE power");
+ executeSQL(taos, "CREATE STABLE meters (ts TIMESTAMP, current FLOAT, voltage INT, phase FLOAT) TAGS (location BINARY(64), groupId INT)");
+ executeSQL(taos, "INSERT INTO d1001 USING meters TAGS(Beijing.Chaoyang, 2) VALUES ('2018-10-03 14:38:05.000', 10.30000, 219, 0.31000) ('2018-10-03 14:38:15.000', 12.60000, 218, 0.33000) ('2018-10-03 14:38:16.800', 12.30000, 221, 0.31000)"
+ "d1002 USING meters TAGS(Beijing.Chaoyang, 3) VALUES ('2018-10-03 14:38:16.650', 10.30000, 218, 0.25000)"
+ "d1003 USING meters TAGS(Beijing.Haidian, 2) VALUES ('2018-10-03 14:38:05.500', 11.80000, 221, 0.28000) ('2018-10-03 14:38:16.600', 13.40000, 223, 0.29000)"
+ "d1004 USING meters TAGS(Beijing.Haidian, 3) VALUES ('2018-10-03 14:38:05.000', 10.80000, 223, 0.29000) ('2018-10-03 14:38:06.500', 11.50000, 221, 0.35000)");
+ taos_close(taos);
+ taos_cleanup();
+}
+
+// output:
+// affected rows 0
+// affected rows 0
+// affected rows 0
+// affected rows 8
\ No newline at end of file
diff --git a/docs-examples/c/json_protocol_example.c b/docs-examples/c/json_protocol_example.c
new file mode 100644
index 0000000000000000000000000000000000000000..182fd201308facc80c76f36cfa57580784d70413
--- /dev/null
+++ b/docs-examples/c/json_protocol_example.c
@@ -0,0 +1,52 @@
+// compile with
+// gcc -o json_protocol_example json_protocol_example.c -ltaos
+#include
+#include
+#include
+#include "taos.h"
+
+void executeSQL(TAOS *taos, const char *sql) {
+ TAOS_RES *res = taos_query(taos, sql);
+ int code = taos_errno(res);
+ if (code != 0) {
+ printf("%s\n", taos_errstr(res));
+ taos_free_result(res);
+ taos_close(taos);
+ exit(EXIT_FAILURE);
+ }
+ taos_free_result(res);
+}
+
+// ANCHOR: main
+int main() {
+ TAOS *taos = taos_connect("localhost", "root", "taosdata", "", 6030);
+ if (taos == NULL) {
+ printf("failed to connect to server\n");
+ exit(EXIT_FAILURE);
+ }
+ executeSQL(taos, "DROP DATABASE IF EXISTS test");
+ executeSQL(taos, "CREATE DATABASE test");
+ executeSQL(taos, "USE test");
+ char *line =
+ "[{\"metric\": \"meters.current\", \"timestamp\": 1648432611249, \"value\": 10.3, \"tags\": {\"location\": "
+ "\"Beijing.Chaoyang\", \"groupid\": 2}},{\"metric\": \"meters.voltage\", \"timestamp\": 1648432611249, "
+ "\"value\": 219, \"tags\": {\"location\": \"Beijing.Haidian\", \"groupid\": 1}},{\"metric\": \"meters.current\", "
+ "\"timestamp\": 1648432611250, \"value\": 12.6, \"tags\": {\"location\": \"Beijing.Chaoyang\", \"groupid\": "
+ "2}},{\"metric\": \"meters.voltage\", \"timestamp\": 1648432611250, \"value\": 221, \"tags\": {\"location\": "
+ "\"Beijing.Haidian\", \"groupid\": 1}}]";
+
+ char *lines[] = {line};
+ TAOS_RES *res = taos_schemaless_insert(taos, lines, 1, TSDB_SML_JSON_PROTOCOL, TSDB_SML_TIMESTAMP_NOT_CONFIGURED);
+ if (taos_errno(res) != 0) {
+ printf("failed to insert schema-less data, reason: %s\n", taos_errstr(res));
+ } else {
+ int affectedRow = taos_affected_rows(res);
+ printf("successfully inserted %d rows\n", affectedRow);
+ }
+ taos_free_result(res);
+ taos_close(taos);
+ taos_cleanup();
+}
+// output:
+// successfully inserted 4 rows
+// ANCHOR_END: main
diff --git a/docs-examples/c/line_example.c b/docs-examples/c/line_example.c
new file mode 100644
index 0000000000000000000000000000000000000000..8dd4b1a5075369625645959da0476b76b9fbf290
--- /dev/null
+++ b/docs-examples/c/line_example.c
@@ -0,0 +1,47 @@
+// compile with
+// gcc -o line_example line_example.c -ltaos
+#include
+#include
+#include
+#include "taos.h"
+
+void executeSQL(TAOS *taos, const char *sql) {
+ TAOS_RES *res = taos_query(taos, sql);
+ int code = taos_errno(res);
+ if (code != 0) {
+ printf("%s\n", taos_errstr(res));
+ taos_free_result(res);
+ taos_close(taos);
+ exit(EXIT_FAILURE);
+ }
+ taos_free_result(res);
+}
+
+// ANCHOR: main
+int main() {
+ TAOS *taos = taos_connect("localhost", "root", "taosdata", "", 0);
+ if (taos == NULL) {
+ printf("failed to connect to server\n");
+ exit(EXIT_FAILURE);
+ }
+ executeSQL(taos, "DROP DATABASE IF EXISTS test");
+ executeSQL(taos, "CREATE DATABASE test");
+ executeSQL(taos, "USE test");
+ char *lines[] = {"meters,location=Beijing.Haidian,groupid=2 current=11.8,voltage=221,phase=0.28 1648432611249",
+ "meters,location=Beijing.Haidian,groupid=2 current=13.4,voltage=223,phase=0.29 1648432611250",
+ "meters,location=Beijing.Haidian,groupid=3 current=10.8,voltage=223,phase=0.29 1648432611249",
+ "meters,location=Beijing.Haidian,groupid=3 current=11.3,voltage=221,phase=0.35 1648432611250"};
+ TAOS_RES *res = taos_schemaless_insert(taos, lines, 4, TSDB_SML_LINE_PROTOCOL, TSDB_SML_TIMESTAMP_MILLI_SECONDS);
+ if (taos_errno(res) != 0) {
+ printf("failed to insert schema-less data, reason: %s\n", taos_errstr(res));
+ } else {
+ int affectedRows = taos_affected_rows(res);
+ printf("successfully inserted %d rows\n", affectedRows);
+ }
+ taos_free_result(res);
+ taos_close(taos);
+ taos_cleanup();
+}
+// output:
+// successfully inserted 4 rows
+// ANCHOR_END: main
\ No newline at end of file
diff --git a/docs-examples/c/multi_bind_example.c b/docs-examples/c/multi_bind_example.c
new file mode 100644
index 0000000000000000000000000000000000000000..fe11df9caad3e216fbd0b1ff2f40a54fe3ba86e5
--- /dev/null
+++ b/docs-examples/c/multi_bind_example.c
@@ -0,0 +1,147 @@
+// compile with
+// gcc -o multi_bind_example multi_bind_example.c -ltaos
+#include
+#include
+#include
+#include "taos.h"
+
+/**
+ * @brief execute sql only and ignore result set
+ *
+ * @param taos
+ * @param sql
+ */
+void executeSQL(TAOS *taos, const char *sql) {
+ TAOS_RES *res = taos_query(taos, sql);
+ int code = taos_errno(res);
+ if (code != 0) {
+ printf("%s\n", taos_errstr(res));
+ taos_free_result(res);
+ taos_close(taos);
+ exit(EXIT_FAILURE);
+ }
+ taos_free_result(res);
+}
+
+/**
+ * @brief exit program when error occur.
+ *
+ * @param stmt
+ * @param code
+ * @param msg
+ */
+void checkErrorCode(TAOS_STMT *stmt, int code, const char *msg) {
+ if (code != 0) {
+ printf("%s. error: %s\n", msg, taos_stmt_errstr(stmt));
+ taos_stmt_close(stmt);
+ exit(EXIT_FAILURE);
+ }
+}
+
+/**
+ * @brief insert data using stmt API
+ *
+ * @param taos
+ */
+void insertData(TAOS *taos) {
+ // init
+ TAOS_STMT *stmt = taos_stmt_init(taos);
+ // prepare
+ const char *sql = "INSERT INTO ? USING meters TAGS(?, ?) values(?, ?, ?, ?)";
+ int code = taos_stmt_prepare(stmt, sql, 0);
+ checkErrorCode(stmt, code, "failed to execute taos_stmt_prepare");
+ // bind table name and tags
+ TAOS_BIND tags[2];
+ char *location = "Beijing.Chaoyang";
+ int groupId = 2;
+ tags[0].buffer_type = TSDB_DATA_TYPE_BINARY;
+ tags[0].buffer_length = strlen(location);
+ tags[0].length = &tags[0].buffer_length;
+ tags[0].buffer = location;
+ tags[0].is_null = NULL;
+
+ tags[1].buffer_type = TSDB_DATA_TYPE_INT;
+ tags[1].buffer_length = sizeof(int);
+ tags[1].length = &tags[1].buffer_length;
+ tags[1].buffer = &groupId;
+ tags[1].is_null = NULL;
+
+ code = taos_stmt_set_tbname_tags(stmt, "d1001", tags);
+ checkErrorCode(stmt, code, "failed to execute taos_stmt_set_tbname_tags");
+
+ // highlight-start
+ // insert two rows with multi binds
+ TAOS_MULTI_BIND params[4];
+ // values to bind
+ int64_t ts[] = {1648432611249, 1648432611749};
+ float current[] = {10.3, 12.6};
+ int voltage[] = {219, 218};
+ float phase[] = {0.31, 0.33};
+ // is_null array
+ char is_null[2] = {0};
+ // length array
+ int32_t int64Len[2] = {sizeof(int64_t)};
+ int32_t floatLen[2] = {sizeof(float)};
+ int32_t intLen[2] = {sizeof(int)};
+
+ params[0].buffer_type = TSDB_DATA_TYPE_TIMESTAMP;
+ params[0].buffer_length = sizeof(int64_t);
+ params[0].buffer = ts;
+ params[0].length = int64Len;
+ params[0].is_null = is_null;
+ params[0].num = 2;
+
+ params[1].buffer_type = TSDB_DATA_TYPE_FLOAT;
+ params[1].buffer_length = sizeof(float);
+ params[1].buffer = current;
+ params[1].length = floatLen;
+ params[1].is_null = is_null;
+ params[1].num = 2;
+
+ params[2].buffer_type = TSDB_DATA_TYPE_INT;
+ params[2].buffer_length = sizeof(int);
+ params[2].buffer = voltage;
+ params[2].length = intLen;
+ params[2].is_null = is_null;
+ params[2].num = 2;
+
+ params[3].buffer_type = TSDB_DATA_TYPE_FLOAT;
+ params[3].buffer_length = sizeof(float);
+ params[3].buffer = phase;
+ params[3].length = floatLen;
+ params[3].is_null = is_null;
+ params[3].num = 2;
+
+ code = taos_stmt_bind_param_batch(stmt, params); // bind batch
+ checkErrorCode(stmt, code, "failed to execute taos_stmt_bind_param_batch");
+ code = taos_stmt_add_batch(stmt); // add batch
+ checkErrorCode(stmt, code, "failed to execute taos_stmt_add_batch");
+ // highlight-end
+ // execute
+ code = taos_stmt_execute(stmt);
+ checkErrorCode(stmt, code, "failed to execute taos_stmt_execute");
+ int affectedRows = taos_stmt_affected_rows(stmt);
+ printf("successfully inserted %d rows\n", affectedRows);
+ // close
+ taos_stmt_close(stmt);
+}
+
+int main() {
+ TAOS *taos = taos_connect("localhost", "root", "taosdata", NULL, 6030);
+ if (taos == NULL) {
+ printf("failed to connect to server\n");
+ exit(EXIT_FAILURE);
+ }
+ executeSQL(taos, "DROP DATABASE IF EXISTS power");
+ executeSQL(taos, "CREATE DATABASE power");
+ executeSQL(taos, "USE power");
+ executeSQL(taos,
+ "CREATE STABLE meters (ts TIMESTAMP, current FLOAT, voltage INT, phase FLOAT) TAGS (location BINARY(64), "
+ "groupId INT)");
+ insertData(taos);
+ taos_close(taos);
+ taos_cleanup();
+}
+
+// output:
+// successfully inserted 2 rows
\ No newline at end of file
diff --git a/docs-examples/c/query_example.c b/docs-examples/c/query_example.c
new file mode 100644
index 0000000000000000000000000000000000000000..4314ac4fe2f5b5251af2462bf0b20ebeed7cac5e
--- /dev/null
+++ b/docs-examples/c/query_example.c
@@ -0,0 +1,143 @@
+// compile with:
+// gcc -o query_example query_example.c -ltaos
+#include
+#include
+#include
+#include
+#include
+
+typedef int16_t VarDataLenT;
+
+#define TSDB_NCHAR_SIZE sizeof(int32_t)
+#define VARSTR_HEADER_SIZE sizeof(VarDataLenT)
+
+#define GET_FLOAT_VAL(x) (*(float *)(x))
+#define GET_DOUBLE_VAL(x) (*(double *)(x))
+
+#define varDataLen(v) ((VarDataLenT *)(v))[0]
+
+int printRow(char *str, TAOS_ROW row, TAOS_FIELD *fields, int numFields) {
+ int len = 0;
+ char split = ' ';
+
+ for (int i = 0; i < numFields; ++i) {
+ if (i > 0) {
+ str[len++] = split;
+ }
+
+ if (row[i] == NULL) {
+ len += sprintf(str + len, "%s", "NULL");
+ continue;
+ }
+
+ switch (fields[i].type) {
+ case TSDB_DATA_TYPE_TINYINT:
+ len += sprintf(str + len, "%d", *((int8_t *)row[i]));
+ break;
+
+ case TSDB_DATA_TYPE_UTINYINT:
+ len += sprintf(str + len, "%u", *((uint8_t *)row[i]));
+ break;
+
+ case TSDB_DATA_TYPE_SMALLINT:
+ len += sprintf(str + len, "%d", *((int16_t *)row[i]));
+ break;
+
+ case TSDB_DATA_TYPE_USMALLINT:
+ len += sprintf(str + len, "%u", *((uint16_t *)row[i]));
+ break;
+
+ case TSDB_DATA_TYPE_INT:
+ len += sprintf(str + len, "%d", *((int32_t *)row[i]));
+ break;
+
+ case TSDB_DATA_TYPE_UINT:
+ len += sprintf(str + len, "%u", *((uint32_t *)row[i]));
+ break;
+
+ case TSDB_DATA_TYPE_BIGINT:
+ len += sprintf(str + len, "%" PRId64, *((int64_t *)row[i]));
+ break;
+
+ case TSDB_DATA_TYPE_UBIGINT:
+ len += sprintf(str + len, "%" PRIu64, *((uint64_t *)row[i]));
+ break;
+
+ case TSDB_DATA_TYPE_FLOAT: {
+ float fv = 0;
+ fv = GET_FLOAT_VAL(row[i]);
+ len += sprintf(str + len, "%f", fv);
+ } break;
+
+ case TSDB_DATA_TYPE_DOUBLE: {
+ double dv = 0;
+ dv = GET_DOUBLE_VAL(row[i]);
+ len += sprintf(str + len, "%lf", dv);
+ } break;
+
+ case TSDB_DATA_TYPE_BINARY:
+ case TSDB_DATA_TYPE_NCHAR: {
+ int32_t charLen = varDataLen((char *)row[i] - VARSTR_HEADER_SIZE);
+ memcpy(str + len, row[i], charLen);
+ len += charLen;
+ } break;
+
+ case TSDB_DATA_TYPE_TIMESTAMP:
+ len += sprintf(str + len, "%" PRId64, *((int64_t *)row[i]));
+ break;
+
+ case TSDB_DATA_TYPE_BOOL:
+ len += sprintf(str + len, "%d", *((int8_t *)row[i]));
+ default:
+ break;
+ }
+ }
+
+ return len;
+}
+
+/**
+ * @brief print column name and values of each row
+ *
+ * @param res
+ * @return int
+ */
+static int printResult(TAOS_RES *res) {
+ int numFields = taos_num_fields(res);
+ TAOS_FIELD *fields = taos_fetch_fields(res);
+ char header[256] = {0};
+ int len = 0;
+ for (int i = 0; i < numFields; ++i) {
+ len += sprintf(header + len, "%s ", fields[i].name);
+ }
+ puts(header);
+
+ TAOS_ROW row = NULL;
+ while ((row = taos_fetch_row(res))) {
+ char temp[256] = {0};
+ printRow(temp, row, fields, numFields);
+ puts(temp);
+ }
+}
+
+int main() {
+ TAOS *taos = taos_connect("localhost", "root", "taosdata", "power", 6030);
+ if (taos == NULL) {
+ puts("failed to connect to server");
+ exit(EXIT_FAILURE);
+ }
+ TAOS_RES *res = taos_query(taos, "SELECT * FROM meters LIMIT 2");
+ if (taos_errno(res) != 0) {
+ printf("failed to exeuce taos_query. error: %s\n", taos_errstr(res));
+ exit(EXIT_FAILURE);
+ }
+ printResult(res);
+ taos_free_result(res);
+ taos_close(taos);
+ taos_cleanup();
+}
+
+// output:
+// ts current voltage phase location groupid
+// 1648432611249 10.300000 219 0.310000 Beijing.Chaoyang 2
+// 1648432611749 12.600000 218 0.330000 Beijing.Chaoyang 2
\ No newline at end of file
diff --git a/docs-examples/c/stmt_example.c b/docs-examples/c/stmt_example.c
new file mode 100644
index 0000000000000000000000000000000000000000..fab1506f953ef68050e4318406fa2ba1a0202929
--- /dev/null
+++ b/docs-examples/c/stmt_example.c
@@ -0,0 +1,141 @@
+// compile with
+// gcc -o stmt_example stmt_example.c -ltaos
+#include
+#include
+#include
+#include "taos.h"
+
+/**
+ * @brief execute sql only.
+ *
+ * @param taos
+ * @param sql
+ */
+void executeSQL(TAOS *taos, const char *sql) {
+ TAOS_RES *res = taos_query(taos, sql);
+ int code = taos_errno(res);
+ if (code != 0) {
+ printf("%s\n", taos_errstr(res));
+ taos_free_result(res);
+ taos_close(taos);
+ exit(EXIT_FAILURE);
+ }
+ taos_free_result(res);
+}
+
+/**
+ * @brief check return status and exit program when error occur.
+ *
+ * @param stmt
+ * @param code
+ * @param msg
+ */
+void checkErrorCode(TAOS_STMT *stmt, int code, const char* msg) {
+ if (code != 0) {
+ printf("%s. error: %s\n", msg, taos_stmt_errstr(stmt));
+ taos_stmt_close(stmt);
+ exit(EXIT_FAILURE);
+ }
+}
+
+typedef struct {
+ int64_t ts;
+ float current;
+ int voltage;
+ float phase;
+} Row;
+
+/**
+ * @brief insert data using stmt API
+ *
+ * @param taos
+ */
+void insertData(TAOS *taos) {
+ // init
+ TAOS_STMT *stmt = taos_stmt_init(taos);
+ // prepare
+ const char *sql = "INSERT INTO ? USING meters TAGS(?, ?) VALUES(?, ?, ?, ?)";
+ int code = taos_stmt_prepare(stmt, sql, 0);
+ checkErrorCode(stmt, code, "failed to execute taos_stmt_prepare");
+ // bind table name and tags
+ TAOS_BIND tags[2];
+ char* location = "Beijing.Chaoyang";
+ int groupId = 2;
+ tags[0].buffer_type = TSDB_DATA_TYPE_BINARY;
+ tags[0].buffer_length = strlen(location);
+ tags[0].length = &tags[0].buffer_length;
+ tags[0].buffer = location;
+ tags[0].is_null = NULL;
+
+ tags[1].buffer_type = TSDB_DATA_TYPE_INT;
+ tags[1].buffer_length = sizeof(int);
+ tags[1].length = &tags[1].buffer_length;
+ tags[1].buffer = &groupId;
+ tags[1].is_null = NULL;
+
+ code = taos_stmt_set_tbname_tags(stmt, "d1001", tags);
+ checkErrorCode(stmt, code, "failed to execute taos_stmt_set_tbname_tags");
+
+ // insert two rows
+ Row rows[2] = {
+ {1648432611249, 10.3, 219, 0.31},
+ {1648432611749, 12.6, 218, 0.33},
+ };
+
+ TAOS_BIND values[4];
+ values[0].buffer_type = TSDB_DATA_TYPE_TIMESTAMP;
+ values[0].buffer_length = sizeof(int64_t);
+ values[0].length = &values[0].buffer_length;
+ values[0].is_null = NULL;
+
+ values[1].buffer_type = TSDB_DATA_TYPE_FLOAT;
+ values[1].buffer_length = sizeof(float);
+ values[1].length = &values[1].buffer_length;
+ values[1].is_null = NULL;
+
+ values[2].buffer_type = TSDB_DATA_TYPE_INT;
+ values[2].buffer_length = sizeof(int);
+ values[2].length = &values[2].buffer_length;
+ values[2].is_null = NULL;
+
+ values[3].buffer_type = TSDB_DATA_TYPE_FLOAT;
+ values[3].buffer_length = sizeof(float);
+ values[3].length = &values[3].buffer_length;
+ values[3].is_null = NULL;
+
+ for (int i = 0; i < 2; ++i) {
+ values[0].buffer = &rows[i].ts;
+ values[1].buffer = &rows[i].current;
+ values[2].buffer = &rows[i].voltage;
+ values[3].buffer = &rows[i].phase;
+ code = taos_stmt_bind_param(stmt, values); // bind param
+ checkErrorCode(stmt, code, "failed to execute taos_stmt_bind_param");
+ code = taos_stmt_add_batch(stmt); // add batch
+ checkErrorCode(stmt, code, "failed to execute taos_stmt_add_batch");
+ }
+ // execute
+ code = taos_stmt_execute(stmt);
+ checkErrorCode(stmt, code, "failed to execute taos_stmt_execute");
+ int affectedRows = taos_stmt_affected_rows(stmt);
+ printf("successfully inserted %d rows\n", affectedRows);
+ // close
+ taos_stmt_close(stmt);
+}
+
+int main() {
+ TAOS *taos = taos_connect("localhost", "root", "taosdata", NULL, 6030);
+ if (taos == NULL) {
+ printf("failed to connect to server\n");
+ exit(EXIT_FAILURE);
+ }
+ executeSQL(taos, "CREATE DATABASE power");
+ executeSQL(taos, "USE power");
+ executeSQL(taos, "CREATE STABLE meters (ts TIMESTAMP, current FLOAT, voltage INT, phase FLOAT) TAGS (location BINARY(64), groupId INT)");
+ insertData(taos);
+ taos_close(taos);
+ taos_cleanup();
+}
+
+
+// output:
+// successfully inserted 2 rows
\ No newline at end of file
diff --git a/docs-examples/c/subscribe_demo.c b/docs-examples/c/subscribe_demo.c
new file mode 100644
index 0000000000000000000000000000000000000000..3c6c4176f7b4914b9a50184906f220d0e8a1a248
--- /dev/null
+++ b/docs-examples/c/subscribe_demo.c
@@ -0,0 +1,63 @@
+// compile with:
+// gcc -o subscribe_demo subscribe_demo.c -ltaos
+
+#include
+#include
+#include
+#include
+
+int nTotalRows;
+
+/**
+ * @brief callback function of subscription.
+ *
+ * @param tsub
+ * @param res
+ * @param param. the additional parameter passed to taos_subscribe
+ * @param code. error code
+ */
+void subscribe_callback(TAOS_SUB* tsub, TAOS_RES* res, void* param, int code) {
+ if (code != 0) {
+ printf("error: %d\n", code);
+ exit(EXIT_FAILURE);
+ }
+
+ TAOS_ROW row = NULL;
+ int num_fields = taos_num_fields(res);
+ TAOS_FIELD* fields = taos_fetch_fields(res);
+ int nRows = 0;
+
+ while ((row = taos_fetch_row(res))) {
+ char buf[4096] = {0};
+ taos_print_row(buf, row, fields, num_fields);
+ puts(buf);
+ nRows++;
+ }
+
+ nTotalRows += nRows;
+ printf("%d rows consumed.\n", nRows);
+}
+
+int main() {
+ TAOS* taos = taos_connect("localhost", "root", "taosdata", NULL, 6030);
+ if (taos == NULL) {
+ printf("failed to connect to server\n");
+ exit(EXIT_FAILURE);
+ }
+
+ int restart = 1; // if the topic already exists, where to subscribe from the begine.
+ const char* topic = "topic-meter-current-bg-10";
+ const char* sql = "select * from power.meters where current > 10";
+ void* param = NULL; // additional parameter.
+ int interval = 2000; // consumption interval in microseconds.
+ TAOS_SUB* tsub = taos_subscribe(taos, restart, topic, sql, subscribe_callback, NULL, interval);
+
+ getchar(); // press Enter to stop
+
+ printf("total rows consumed: %d\n", nTotalRows);
+ int keep = 0; // weather to keep subscribe process
+ taos_unsubscribe(tsub, keep);
+
+ taos_close(taos);
+ taos_cleanup();
+}
\ No newline at end of file
diff --git a/docs-examples/c/telnet_line_example.c b/docs-examples/c/telnet_line_example.c
new file mode 100644
index 0000000000000000000000000000000000000000..913d433f6aec07b3bce115d45536ffa4b45a0481
--- /dev/null
+++ b/docs-examples/c/telnet_line_example.c
@@ -0,0 +1,54 @@
+// compile with
+// gcc -o telnet_line_example telnet_line_example.c -ltaos
+#include
+#include
+#include
+#include "taos.h"
+
+void executeSQL(TAOS *taos, const char *sql) {
+ TAOS_RES *res = taos_query(taos, sql);
+ int code = taos_errno(res);
+ if (code != 0) {
+ printf("%s\n", taos_errstr(res));
+ taos_free_result(res);
+ taos_close(taos);
+ exit(EXIT_FAILURE);
+ }
+ taos_free_result(res);
+}
+
+// ANCHOR: main
+int main() {
+ TAOS *taos = taos_connect("localhost", "root", "taosdata", "", 6030);
+ if (taos == NULL) {
+ printf("failed to connect to server\n");
+ exit(EXIT_FAILURE);
+ }
+ executeSQL(taos, "DROP DATABASE IF EXISTS test");
+ executeSQL(taos, "CREATE DATABASE test");
+ executeSQL(taos, "USE test");
+ char *lines[] = {
+ "meters.current 1648432611249 10.3 location=Beijing.Chaoyang groupid=2",
+ "meters.current 1648432611250 12.6 location=Beijing.Chaoyang groupid=2",
+ "meters.current 1648432611249 10.8 location=Beijing.Haidian groupid=3",
+ "meters.current 1648432611250 11.3 location=Beijing.Haidian groupid=3",
+ "meters.voltage 1648432611249 219 location=Beijing.Chaoyang groupid=2",
+ "meters.voltage 1648432611250 218 location=Beijing.Chaoyang groupid=2",
+ "meters.voltage 1648432611249 221 location=Beijing.Haidian groupid=3",
+ "meters.voltage 1648432611250 217 location=Beijing.Haidian groupid=3",
+ };
+ TAOS_RES *res = taos_schemaless_insert(taos, lines, 8, TSDB_SML_TELNET_PROTOCOL, TSDB_SML_TIMESTAMP_NOT_CONFIGURED);
+ if (taos_errno(res) != 0) {
+ printf("failed to insert schema-less data, reason: %s\n", taos_errstr(res));
+ } else {
+ int affectedRow = taos_affected_rows(res);
+ printf("successfully inserted %d rows\n", affectedRow);
+ }
+
+ taos_free_result(res);
+ taos_close(taos);
+ taos_cleanup();
+}
+// output:
+// successfully inserted 8 rows
+// ANCHOR_END: main
diff --git a/src/connector/C#/examples/lib/Utils.cs b/docs-examples/csharp/AsyncQueryExample.cs
similarity index 53%
rename from src/connector/C#/examples/lib/Utils.cs
rename to docs-examples/csharp/AsyncQueryExample.cs
index a2fb25c70162a49ac8f1bb24f451cac413f72733..fe30d21efe82e8d1dc414bd4723227ca93bc944f 100644
--- a/src/connector/C#/examples/lib/Utils.cs
+++ b/docs-examples/csharp/AsyncQueryExample.cs
@@ -1,110 +1,69 @@
-using System;
using TDengineDriver;
using System.Runtime.InteropServices;
-using System.Text;
-using System.Collections.Generic;
-namespace Sample.UtilsTools
+
+namespace TDengineExample
{
- public class UtilsTools
+ public class AsyncQueryExample
{
-
- static string ip = "127.0.0.1";
- static string user = "root";
- static string password = "taosdata";
- static string db = "";
- static short port = 0;
- static string globalDbName = "csharp_example_db";
- //get a TDengine connection
- public static IntPtr TDConnection()
- {
- TDengine.Options((int)TDengineInitOption.TSDB_OPTION_CONFIGDIR, GetConfigPath());
- TDengine.Options((int)TDengineInitOption.TSDB_OPTION_SHELL_ACTIVITY_TIMER, "60");
- TDengine.Init();
-
- IntPtr conn = TDengine.Connect(ip, user, password, db, port);
- UtilsTools.ExecuteUpdate(conn, $"drop database if exists {globalDbName}");
- UtilsTools.ExecuteUpdate(conn, $"create database if not exists {globalDbName} keep 3650");
- UtilsTools.ExecuteUpdate(conn, $"use {globalDbName}");
- return conn;
- }
- //get taos.cfg file based on different os
- public static string GetConfigPath()
+ static void Main()
{
- string configDir = "";
- if (OperatingSystem.IsOSPlatform("Windows"))
- {
- configDir = "C:/TDengine/cfg";
- }
- else if (OperatingSystem.IsOSPlatform("Linux"))
- {
- configDir = "/etc/taos";
- }
- else if (OperatingSystem.IsOSPlatform("macOS"))
- {
- configDir = "/usr/local/etc/taos";
- }
- return configDir;
- }
-
- public static IntPtr ExecuteQuery(IntPtr conn, String sql)
- {
- IntPtr res = TDengine.Query(conn, sql);
- if (!IsValidResult(res))
- {
- Console.Write(sql.ToString() + " failure, ");
- ExitProgram();
- }
- else
- {
- Console.WriteLine(sql.ToString() + " success");
- }
- return res;
+ IntPtr conn = GetConnection();
+ QueryAsyncCallback queryAsyncCallback = new QueryAsyncCallback(QueryCallback);
+ TDengine.QueryAsync(conn, "select * from meters", queryAsyncCallback, IntPtr.Zero);
+ Thread.Sleep(2000);
+ TDengine.Close(conn);
+ TDengine.Cleanup();
}
- public static IntPtr ExecuteErrorQuery(IntPtr conn, String sql)
+ static void QueryCallback(IntPtr param, IntPtr taosRes, int code)
{
- IntPtr res = TDengine.Query(conn, sql);
- if (!IsValidResult(res))
+ if (code == 0 && taosRes != IntPtr.Zero)
{
- Console.Write(sql.ToString() + " failure, ");
- ExitProgram();
+ FetchRowAsyncCallback fetchRowAsyncCallback = new FetchRowAsyncCallback(FetchRowCallback);
+ TDengine.FetchRowAsync(taosRes, fetchRowAsyncCallback, param);
}
else
{
- Console.WriteLine(sql.ToString() + " success");
-
+ Console.WriteLine($"async query data failed, failed code {code}");
}
- return res;
}
- public static void ExecuteUpdate(IntPtr conn, String sql)
+ static void FetchRowCallback(IntPtr param, IntPtr taosRes, int numOfRows)
{
- IntPtr res = TDengine.Query(conn, sql);
- if (!IsValidResult(res))
+ if (numOfRows > 0)
{
- Console.Write(sql.ToString() + " failure, ");
- ExitProgram();
+ Console.WriteLine($"{numOfRows} rows async retrieved");
+ DisplayRes(taosRes);
+ TDengine.FetchRowAsync(taosRes, FetchRowCallback, param);
}
else
{
- Console.WriteLine(sql.ToString() + " success");
+ if (numOfRows == 0)
+ {
+ Console.WriteLine("async retrieve complete.");
+ }
+ else
+ {
+ Console.WriteLine($"FetchRowAsync callback error, error code {numOfRows}");
+ }
+ TDengine.FreeResult(taosRes);
}
- TDengine.FreeResult(res);
}
public static void DisplayRes(IntPtr res)
{
if (!IsValidResult(res))
{
- ExitProgram();
+ TDengine.Cleanup();
+ System.Environment.Exit(1);
}
- List metaList = GetResField(res);
+ List metaList = TDengine.FetchFields(res);
int fieldCount = metaList.Count;
// metaList.ForEach((item) => { Console.Write("{0} ({1}) \t|\t", item.name, item.size); });
- List