### Client Mode Installation Examples Source: https://github.com/taosdata/tdengine/blob/main/packaging/INSTALLATION_GUIDE.md Examples for installing TDengine in client mode. Note that client-only installation might not be fully supported in all versions. ```bash # Interactive installation of client ./install.sh -v client ``` ```bash # Silent installation of client ./install.sh -v client -s ``` ```bash # Custom path installation of client ./install.sh -v client -d /opt/tdengine-client ``` ```bash # Install client and disable FQDN interaction ./install.sh -v client -e no ``` -------------------------------- ### TDengine Installation Configuration File Example Source: https://github.com/taosdata/tdengine/blob/main/docs/zh/08-operation/20-inspect-tools/03-taosinstall.md An example configuration file for taosinstall, detailing environment setup, package paths, database credentials, and service configurations. ```config ######################################################## # # # Configuration # # # ######################################################## # 安装部署 TDengine TSDB 的环境信息,支持免密登录和 SSH 登录两种方式,当环境配置了免密登录后可不用配置 password 信息 [test_env] # 节点间通过 SSH 协议访问 firstep=192.168.0.1||fqdn=tdengine1||username=root||password=123456||port=22 secondep=192.168.0.2||fqdn=tdengine2||username=root||password=123456||port=22 dnode3=192.168.0.3||fqdn=tdengine3||username=root||username=123456||port=22 # 节点间配置免密登录,包括运行安装工具的当前节点也要配置免密!!! # firstep=192.168.0.1||fqdn=tdengine1||username=root||port=22 # secondep=192.168.0.2||fqdn=tdengine2||username=root||port=22 # dnode3=192.168.0.3||fqdn=tdengine3||username=root||port=22 # TDengine TSDB 安装包在本地所在全路径 [local_pack] package=/path_to_file/tdengine-tsdb-enterprise-3.3.x.x-Linux-x64.tar.gz md5 = 317f88bf13aa21706ae8c2d4f919d30f # oem 版本的版本名称,默认不使用 # [oem] # version=prodb # TDegine 的 Restful 连接信息 [database] username=root password=taosdata port=6030 rest_port=6041 # taosd 预配置文件, 该文件中配置会覆盖到所有 dnode 上对应配置文件 [taos_cfg] cfg_file=taos.cfg # taoskeeper的预配置文件, 该文件中配置会覆盖到所有 dnode 上对应配置文件 [taoskeeper_cfg] cfg_file=taoskeeper.toml # taosadapter 的预配置文件, 该文件中配置会覆盖到所有 dnode 上对应配置文件 [taosadapter_cfg] cfg_file=taosadapter.toml # taosx 的预配置文件, 该文件中配置会覆盖到所有 dnode 上对应配置文件 [taosx_cfg] cfg_file=taosx.toml # explorer 的预配置文件, 该文件中配置会覆盖到所有 dnode 上对应配置文件 [taosexplorer_cfg] cfg_file=explorer.toml # 监控用户 monitor 的配置信息 [monitor_user] username=monitor password=Taosmonitor_125# [td_services] taosd taos taosadapter taoskeeper taosx taos-explorer ``` -------------------------------- ### Server Mode Installation Examples Source: https://github.com/taosdata/tdengine/blob/main/packaging/INSTALLATION_GUIDE.md Examples for installing TDengine in server mode, including interactive, silent, and custom path installations. ```bash # Interactive installation (default server mode) ./install.sh ``` ```bash # Silent installation of server ./install.sh -s ``` ```bash # Custom path installation of server ./install.sh -d /opt/tdengine ``` ```bash # Silent mode + custom path installation of server ./install.sh -q /opt/tdengine ``` ```bash # Install server and disable FQDN interaction ./install.sh -e no ``` -------------------------------- ### Basic Installation Script Usage Source: https://github.com/taosdata/tdengine/blob/main/packaging/INSTALLATION_GUIDE.md Download, extract, and run the installation script. This is the most basic way to start the installation process. ```bash # Download and extract TDengine installation package # Enter the installation package directory ./install.sh ``` -------------------------------- ### Specify Installation Path Examples (Silent) Source: https://github.com/taosdata/tdengine/blob/main/packaging/INSTALLATION_GUIDE.md Examples demonstrating how to specify a custom installation path using the -q flag in silent installation modes. ```bash # Root user silent installation and specify path ./install.sh -q /opt/taos-install ``` ```bash # Regular user silent installation and specify path ./install.sh -q /home/user/taos-install ``` -------------------------------- ### Specify Installation Path Examples (Non-Silent) Source: https://github.com/taosdata/tdengine/blob/main/packaging/INSTALLATION_GUIDE.md Examples demonstrating how to specify a custom installation path using the -d flag in non-silent installation modes. ```bash # Root user specifies installation path ./install.sh -d /opt/taos-install ``` ```bash # Regular user specifies installation path ./install.sh -d /home/user/taos-install ``` -------------------------------- ### TDengine Setup for MQTT Subscription Example Source: https://github.com/taosdata/tdengine/blob/main/docs/en/06-advanced/01-subscription/03-mqtt.md These SQL statements set up the necessary database, supertable, topic, insert test data, and create a bnode for the MQTT subscription example. ```sql CREATE DATABASE db VGROUPS 1; CREATE TABLE db.meters (ts TIMESTAMP, f1 INT) TAGS (t1 INT); CREATE TOPIC topic_meters AS SELECT ts, tbname, f1, t1 FROM db.meters; INSERT INTO db.tb USING db.meters TAGS (1) VALUES (now, 1); CREATE BNODE ON DNODE 1; ``` -------------------------------- ### Start StatsD Source: https://github.com/taosdata/tdengine/blob/main/docs/en/assets/resources/_statsd.mdx Install StatsD dependencies and start the StatsD server with the modified configuration file. ```shell npm install node stats.js config.js & ``` -------------------------------- ### Quick Start Examples for compat-check Source: https://github.com/taosdata/tdengine/blob/main/test/tools/compat-check/README.md Demonstrates common command-line invocations for the compat-check tool, including cold upgrade, rolling upgrade, quick mode, and INFORMATION_SCHEMA checks. ```bash cd test/tools/compat-check # 冷升级(默认) python -m run.main -F /opt/td/3.3.8.0 -T /opt/td/3.4.0.8 # 滚动升级(热升级) python -m run.main -F /opt/td/3.3.8.0 -T /opt/td/3.4.0.8 -r # 快速模式(CI 冒烟测试) python -m run.main -F /opt/td/3.3.8.0 -T /opt/td/3.4.0.8 -r -q # 带 INFORMATION_SCHEMA 检查 python -m run.main -F /opt/td/3.3.8.0 -T /opt/td/3.4.0.8 -r -S ``` -------------------------------- ### TDengine Installation Directory Structure Example Source: https://github.com/taosdata/tdengine/blob/main/test/tools/compat-check/docs/User Manual.md Illustrates the expected directory layout for two different TDengine versions used for upgrade testing. ```text /opt/tdengine/ TDengine-enterprise-3.3.8.0/ ← from-dir taosd libtaos.so ... TDengine-enterprise-3.4.0.8/ ← to-dir taosd libtaos.so ... ``` -------------------------------- ### Example taosgen Startup Source: https://github.com/taosdata/tdengine/blob/main/docs/en/14-reference/02-tools/11-taosgen.md Start taosgen using command-line parameters to specify the host and configuration file. Ensure target TDengine clusters are running before execution. ```shell taosgen -h 127.0.0.1 -c config.yaml ``` -------------------------------- ### Start TDengine Server Source: https://github.com/taosdata/tdengine/blob/main/README.md Starts the TDengine server using systemd after installation. ```bash # Start the server after installation sudo systemctl start taosd ``` -------------------------------- ### Setup Python Environment and Run Subscriber Source: https://github.com/taosdata/tdengine/blob/main/docs/en/06-advanced/01-subscription/03-mqtt.md These shell commands set up a virtual environment, install the required `paho-mqtt` library, and run the Python subscriber script. ```shell python3 -m venv .test-env source .test-env/bin/activate pip3 install paho-mqtt==2.1.0 python3 ./sub.py ``` -------------------------------- ### Run TDengine Query Test Examples Source: https://github.com/taosdata/tdengine/blob/main/tools/lastqps-test/README.md Provides example commands to run the TDengine query test tool for different scenarios. Use these as a starting point for your performance testing. ```bash # Run table name IN query test (Mode 1) ./taos_query_a_simple 1 ``` ```bash # Run sub-table query test (Mode 2) ./taos_query_a_simple 2 ``` -------------------------------- ### EXPLAIN ANALYZE Example Source: https://github.com/taosdata/tdengine/blob/main/docs/zh/14-reference/03-taos-sql/28-explain.md Demonstrates how to use EXPLAIN ANALYZE to get runtime metrics for a query. This requires the actual execution of the target query. ```sql EXPLAIN ANALYZE SELECT * FROM meters WHERE ts > '2023-01-01'; ``` -------------------------------- ### Install Node.js Connector and Initialize Project Source: https://github.com/taosdata/tdengine/blob/main/docs/en/07-develop/01-connect.md Install the Node.js connector and initialize a new npm project. Execute nodejsChecker.js to verify the installation. ```bash npm init -y npm install @tdengine/websocket node nodejsChecker.js ``` -------------------------------- ### Install taosgen with Symbolic Link Source: https://github.com/taosdata/tdengine/blob/main/docs/en/14-reference/02-tools/11-taosgen.md Download the taosgen binary and create a symbolic link for convenient access in the system's executable directory. This example shows the process for Linux. ```shell tar zxvf taosgen-v0.8.6-linux-x64.tar.gz cd taosgen ln -sf `pwd`/taosgen /usr/bin/taosgen ``` -------------------------------- ### Install Node.js Dependencies Source: https://github.com/taosdata/tdengine/blob/main/docs/en/10-third-party/03-visual/02-perspective.md Install the necessary Node.js dependencies for the Perspective TDengine examples. This command should be run after cloning the repository and navigating to the node directory. ```bash npm install ``` -------------------------------- ### Install TDengine Client Source: https://github.com/taosdata/tdengine/blob/main/docs/en/10-third-party/03-visual/02-perspective.md Run the installation script to install the TDengine client locally. ```bash ./install.sh ``` -------------------------------- ### Build Docker Image with TDengine Client Dependencies Source: https://github.com/taosdata/tdengine/blob/main/packaging/docker/README.md Create a Dockerfile to build an image for a client application. This example installs necessary packages, downloads the TDengine client, and runs the installation script, preparing the image to connect to a TDengine service. ```dockerfile FROM ubuntu:20.04 RUN apt-get update && apt-get install -y wget ENV TDENGINE_VERSION=3.0.0.0 RUN wget -c https://www.taosdata.com/assets-download/3.0/TDengine-client-${TDENGINE_VERSION}-Linux-x64.tar.gz \ && tar xvf TDengine-client-${TDENGINE_VERSION}-Linux-x64.tar.gz \ && cd TDengine-client-${TDENGINE_VERSION} \ && ./install_client.sh \ && cd ../ \ && rm -rf TDengine-client-${TDENGINE_VERSION}-Linux-x64.tar.gz TDengine-client-${TDENGINE_VERSION} ``` -------------------------------- ### Query Result Example Source: https://github.com/taosdata/tdengine/blob/main/docs/en/05-basic/03-query.md Sample output from the time window query, showing partitioned table names, window start and end times, and the calculated average voltage. ```text tbname | _wstart | _wend | avg(voltage) | ====================================================================================== d2 | 2021-12-31 23:59:05.000 | 2022-01-01 00:00:05.000 | 253.000000000000000 | d2 | 2022-01-01 00:00:05.000 | 2022-01-01 00:01:05.000 | 244.166666666666657 | d2 | 2022-01-01 00:01:05.000 | 2022-01-01 00:02:05.000 | 241.833333333333343 | d2 | 2022-01-01 00:02:05.000 | 2022-01-01 00:03:05.000 | 243.166666666666657 | d2 | 2022-01-01 00:03:05.000 | 2022-01-01 00:04:05.000 | 240.833333333333343 | d2 | 2022-01-01 00:04:05.000 | 2022-01-01 00:05:05.000 | 244.800000000000011 | d26 | 2021-12-31 23:59:05.000 | 2022-01-01 00:00:05.000 | 253.000000000000000 | d26 | 2022-01-01 00:00:05.000 | 2022-01-01 00:01:05.000 | 244.166666666666657 | d26 | 2022-01-01 00:01:05.000 | 2022-01-01 00:02:05.000 | 241.833333333333343 | d26 | 2022-01-01 00:02:05.000 | 2022-01-01 00:03:05.000 | 243.166666666666657 | d26 | 2022-01-01 00:03:05.000 | 2022-01-01 00:04:05.000 | 240.833333333333343 | d26 | 2022-01-01 00:04:05.000 | 2022-01-01 00:05:05.000 | 244.800000000000011 | Query OK, 12 row(s) in set (0.021265s) ``` -------------------------------- ### Run TDgpt Installation Script Source: https://github.com/taosdata/tdengine/blob/main/docs/en/06-advanced/06-tdgpt/02-tutorial.md Navigate to the TDgpt installation directory and execute the install script. This script sets up TDgpt and its dependencies. ```bash cd tdengine-tdgpt-oss-{{VERSION}}-linux-x64 ./install.sh ``` -------------------------------- ### Download and Install Kafka Source: https://github.com/taosdata/tdengine/blob/main/docs/en/10-third-party/01-collection/11-kafka.md Installs Kafka by downloading the package, extracting it, and creating a symbolic link. Ensure Java 8 and Maven are installed. ```shell KAFKA_PKG="kafka_2.13-3.4.0" curl -O "https://archive.apache.org/dist/kafka/3.4.0/${KAFKA_PKG}.tgz" tar xzf "${KAFKA_PKG}.tgz" -C /opt/ ln -s "/opt/${KAFKA_PKG}" /opt/kafka ``` -------------------------------- ### Install TDengine from Package Source: https://github.com/taosdata/tdengine/blob/main/README.md Installs TDengine server from a downloaded tarball. Requires navigating into the extracted directory and running the install script. ```bash tar -xzf TDengine-server--Linux-x86_64.tar.gz cd TDengine-server- sudo ./install.sh ``` -------------------------------- ### Clone Perspective Examples Repository Source: https://github.com/taosdata/tdengine/blob/main/docs/en/10-third-party/03-visual/02-perspective.md Clone the repository to access the TDengine examples. Navigate into the Python examples directory. ```bash git clone https://github.com/ProspectiveCo/perspective-examples cd examples/tdengine/python ``` -------------------------------- ### Verify Boosttools Installation Source: https://github.com/taosdata/tdengine/blob/main/tools/boosttools/README.md After building and installing, verify the installation by running the help command and checking the dynamic library linkage. ```bash ./boosttools --help ``` ```bash ldd boosttools | grep taos ``` -------------------------------- ### Clone Perspective Examples Repository Source: https://github.com/taosdata/tdengine/blob/main/docs/en/10-third-party/03-visual/02-perspective.md Clone the perspective-examples repository to get started. This repository contains examples for integrating Perspective with various data sources, including TDengine. ```bash git clone https://github.com/ProspectiveCo/perspective-examples cd examples/tdengine/node ``` -------------------------------- ### Start TDgpt Service Source: https://github.com/taosdata/tdengine/blob/main/tools/tdgpt/README.md Starts the TDgpt service using systemctl. The service is installed but not automatically started. ```bash systemctl start taosanoded ``` -------------------------------- ### FastWriteExample Usage Examples Source: https://github.com/taosdata/tdengine/blob/main/docs/en/07-develop/15-high.md Provides example commands for running the FastWriteExample program in both simulated data writing mode and Kafka subscription writing mode. Adjust parameters as needed for your specific scenario. ```shell 1. Simulated data writing mode: java -jar highVolume.jar -r 5 -w 5 -b 10000 -c 100000 -s 1000000 -R 1000 2. Kafka subscription writing mode: java -jar highVolume.jar -r 5 -w 5 -b 10000 -c 100000 -s 1000000 -R 100 -K ``` -------------------------------- ### Substring Extraction Examples Source: https://github.com/taosdata/tdengine/blob/main/docs/zh/06-advanced/05-data-in/index.md Extracts a portion of a string based on start position and length. Negative start positions count from the end of the string. ```sql "012345678".sub_string(5) ``` ```sql "012345678".sub_string(5, 2) ``` ```sql "012345678".sub_string(-2) ``` -------------------------------- ### Start Kafka Services Source: https://github.com/taosdata/tdengine/blob/main/docs/en/10-third-party/01-collection/11-kafka.md Starts ZooKeeper, Kafka server, and Kafka Connect in distributed mode as background daemons. Ensure Kafka is installed and configured. ```shell zookeeper-server-start.sh -daemon $KAFKA_HOME/config/zookeeper.properties kafka-server-start.sh -daemon $KAFKA_HOME/config/server.properties connect-distributed.sh -daemon $KAFKA_HOME/config/connect-distributed.properties ``` -------------------------------- ### Quick Start: Cold Upgrade (Minimal) Source: https://github.com/taosdata/tdengine/blob/main/test/tools/compat-check/docs/User Manual.md Executes a basic cold upgrade test. Ensure you are in the `hot_update/` directory when running this command. ```bash python3 -m run.main \ --from-dir /opt/tdengine/TDengine-enterprise-3.3.8.0 \ --to-dir /opt/tdengine/TDengine-enterprise-3.4.0.8 ``` -------------------------------- ### Install TDengine Plugin in Docker Container Source: https://github.com/taosdata/tdengine/blob/main/docs/en/10-third-party/03-visual/01-grafana.md Start a Grafana Docker container and automatically install the TDengine plugin using the GF_INSTALL_PLUGINS environment variable. ```shell docker run -d \ -p 3000:3000 \ --name=grafana \ -e "GF_INSTALL_PLUGINS=https://downloads.tdengine.com/tdengine-tsdb-datasource/tdengine-datasource.zip;tdengine-datasource" \ grafana/grafana ``` -------------------------------- ### Example: Querying and Partitioning Data Source: https://github.com/taosdata/tdengine/blob/main/docs/en/05-basic/03-query.md This example demonstrates querying the supertable 'meters', partitioning the data by 'location', and calculating the average voltage for each location. ```sql SELECT location, avg(voltage) FROM meters PARTITION BY location; ``` -------------------------------- ### Example Query Result for State Window Source: https://github.com/taosdata/tdengine/blob/main/docs/en/05-basic/03-query.md This is an example output from a STATE_WINDOW query, showing table name, window start and end times, duration, and the calculated status. ```text tbname | _wstart | _wend | _wduration | status | =============================================================================================== d2 | 2022-01-01 00:00:00.000 | 2022-01-01 00:01:20.000 | 80000 | 0 | d2 | 2022-01-01 00:01:30.000 | 2022-01-01 00:01:30.000 | 0 | 1 | d2 | 2022-01-01 00:01:40.000 | 2022-01-01 00:01:40.000 | 0 | 0 | d2 | 2022-01-01 00:01:50.000 | 2022-01-01 00:01:50.000 | 0 | 1 | d2 | 2022-01-01 00:02:00.000 | 2022-01-01 00:02:20.000 | 20000 | 0 | d2 | 2022-01-01 00:02:30.000 | 2022-01-01 00:02:30.000 | 0 | 1 | d2 | 2022-01-01 00:02:40.000 | 2022-01-01 00:03:00.000 | 20000 | 0 | d2 | 2022-01-01 00:03:10.000 | 2022-01-01 00:03:10.000 | 0 | 1 | d2 | 2022-01-01 00:03:20.000 | 2022-01-01 00:03:40.000 | 20000 | 0 | d2 | 2022-01-01 00:03:50.000 | 2022-01-01 00:03:50.000 | 0 | 1 | d2 | 2022-01-01 00:04:00.000 | 2022-01-01 00:04:50.000 | 50000 | 0 | d26 | 2022-01-01 00:00:00.000 | 2022-01-01 00:01:20.000 | 80000 | 0 | d26 | 2022-01-01 00:01:30.000 | 2022-01-01 00:01:30.000 | 0 | 1 | d26 | 2022-01-01 00:01:40.000 | 2022-01-01 00:01:40.000 | 0 | 0 | d26 | 2022-01-01 00:01:50.000 | 2022-01-01 00:01:50.000 | 0 | 1 | d26 | 2022-01-01 00:02:00.000 | 2022-01-01 00:02:20.000 | 20000 | 0 | d26 | 2022-01-01 00:02:30.000 | 2022-01-01 00:02:30.000 | 0 | 1 | d26 | 2022-01-01 00:02:40.000 | 2022-01-01 00:03:00.000 | 20000 | 0 | d26 | 2022-01-01 00:03:10.000 | 2022-01-01 00:03:10.000 | 0 | 1 | d26 | 2022-01-01 00:03:20.000 | 2022-01-01 00:03:40.000 | 20000 | 0 | d26 | 2022-01-01 00:03:50.000 | 2022-01-01 00:03:50.000 | 0 | 1 | d26 | 2022-01-01 00:04:00.000 | 2022-01-01 00:04:50.000 | 50000 | 0 | Query OK, 22 row(s) in set (0.153403s) ``` -------------------------------- ### C# WebSocket TMQ Example Source: https://github.com/taosdata/tdengine/blob/main/docs/en/07-develop/07-tmq.md A full C# code example for subscribing to TMQ topics using WebSocket. This snippet covers the essential setup and message handling. ```csharp {{#include docs/examples/csharp/wssubscribe/Program.cs}} ``` -------------------------------- ### Query with Time Window and Partitioning Source: https://github.com/taosdata/tdengine/blob/main/docs/en/05-basic/03-query.md Example SQL query demonstrating partitioning by table name and then by a 1-minute time window with a 5-second offset. It also limits the results to the first 2 partitions. ```sql SELECT tbname, _wstart, _wend, avg(voltage) FROM meters WHERE ts >= "2022-01-01T00:00:00+08:00" AND ts < "2022-01-01T00:05:00+08:00" PARTITION BY tbname INTERVAL(1m, 5s) SLIMIT 2; ``` -------------------------------- ### Partition and Interval Query Example Source: https://github.com/taosdata/tdengine/blob/main/docs/en/14-reference/03-taos-sql/24-distinguished.md Demonstrates partitioning data by 'location' and then downsampling each partition every 10 minutes to find the maximum 'current' value. ```sql select _wstart, location, max(current) from meters partition by location interval(10m) ``` -------------------------------- ### C# Native TMQ Example Source: https://github.com/taosdata/tdengine/blob/main/docs/en/07-develop/07-tmq.md A full C# code example for subscribing to TMQ topics using a native connection. This snippet covers the essential setup and message handling. ```csharp {{#include docs/examples/csharp/subscribe/Program.cs}} ``` -------------------------------- ### Rust Get Connection from Pool Source: https://github.com/taosdata/tdengine/blob/main/docs/en/07-develop/01-connect.md Example of obtaining a connection object from a TDEngine connection pool in Rust. ```rust let taos = pool.get().await?; ``` -------------------------------- ### Configuration File Example Source: https://github.com/taosdata/tdengine/blob/main/docs/zh/08-operation/20-inspect-tools/01-taosprecheck.md An example configuration file for the taosprecheck tool. It demonstrates how to define test environments, system timezones, services, coredump settings, system variables, and pre-installation software lists. ```ini # 安装部署 TDengine TSDB 的环境信息,支持免密登录和 SSH 登录两种方式,当环境配置了免密登录后可不用配置 password 信息 [test_env] # 节点间通过 SSH 协议访问 firstep=192.168.0.1||fqdn=tdengine1||username=root||password=123456||port=22 secondep=192.168.0.2||fqdn=tdengine2||username=root||password=123456||port=22 dnode3=192.168.0.3||fqdn=tdengine3||username=root||username=123456||port=22 # 节点间配置免密登录 # firstep=192.168.0.1||fqdn=tdengine1||username=root||port=22 # secondep=192.168.0.2||fqdn=tdengine2||username=root||port=22 # dnode3=192.168.0.3||fqdn=tdengine3||username=root||port=22 # 系统时区,工具会按照下面配置修改系统时区 [timezone] tz=Asia/Shanghai # 系统服务状态,工具会按照下面配置关闭对应的系统服务 [services] firewall=inactive selinux=inactive # coredump 配置,工具会按照下面配置 coredump 的生成路径 [coredump] kernel.core_pattern=/data/taos/core/core-%%e-%%p # /etc/sysctl.conf 中系统参数,工具会按照下面配置修改系统参数值 [sys_vars:/etc/sysctl.conf] fs.nr_open=2147483584 fs.file-max=2147483584 net.ipv4.ip_local_port_range=10000 65534 # /etc/security/limits.conf 中系统参数,工具会按照下面配置修改系统参数值 [sys_vars:/etc/security/limits.conf] * soft nproc=65536 * soft nofile=2147483584 * soft stack=65536 * hard nproc=65536 * hard nofile=2147483584 * hard stack=65536 root soft nproc=65536 root soft nofile=2147483584 root soft stack=65536 root hard nproc=65536 root hard nofile=2147483584 root hard stack=65536 # 预安装软件列表 [app_list] screen tmux gdb fio iperf iperf3 sysstat net-tools jansson snappy ntp chrony tree wget ``` -------------------------------- ### State Window with Extend Option 1 Source: https://github.com/taosdata/tdengine/blob/main/docs/en/14-reference/03-taos-sql/24-distinguished.md This example shows STATE_WINDOW with extend set to 1. The window start time remains unchanged, and the end time is extended to just before the start of the next window. NULL values are handled. ```text taos> select _wstart, _wduration, _wend, count(*) from state_window_example state_window(status, 1); _wstart | _wduration | _wend | count(*) | ==================================================================================================== 2025-01-01 00:00:00.000 | 4999 | 2025-01-01 00:00:04.999 | 5 | 2025-01-01 00:00:05.000 | 1999 | 2025-01-01 00:00:06.999 | 2 | 2025-01-01 00:00:07.000 | 1000 | 2025-01-01 00:00:08.000 | 2 | ``` -------------------------------- ### Manage TDGPT Models Source: https://github.com/taosdata/tdengine/blob/main/tools/tdgpt/INSTALL.md Commands to start specific or all models managed by TDGPT. The installation directory needs to be specified or set. ```bash # Start specific model python /bin/taosanode_service.py model-start tdtsfm ``` ```bash # Start all models python /bin/taosanode_service.py model-start all ``` -------------------------------- ### Partition by Location Example Source: https://github.com/taosdata/tdengine/blob/main/docs/en/14-reference/03-taos-sql/24-distinguished.md Example of partitioning data by the 'location' tag and calculating the average voltage for each location. ```sql select location, avg(voltage) from meters partition by location ``` -------------------------------- ### Quick Start: Rolling Upgrade with System Info Check (Recommended for CI) Source: https://github.com/taosdata/tdengine/blob/main/test/tools/compat-check/docs/User Manual.md Runs a rolling upgrade test that also checks for differences in INFORMATION_SCHEMA. Recommended for Continuous Integration pipelines. Execute from the `hot_update/` directory. ```bash python3 -m run.main \ --from-dir /opt/tdengine/TDengine-enterprise-3.3.8.0 \ --to-dir /opt/tdengine/TDengine-enterprise-3.4.0.8 \ --rollupdate \ --check-sysinfo ``` -------------------------------- ### Prepare Data for MQTT Publishing Source: https://github.com/taosdata/tdengine/blob/main/docs/en/06-advanced/07-data-publisher/01-mqtt.md Create a database, super table, and topic, then insert sample data. This prepares the data structure and content for subsequent subscription and publishing. ```sql create database db vgroups 1; create table db.meters (ts timestamp, f1 int) tags(t1 int); create topic topic_meters as select ts, tbname, f1, t1 from db.meters; insert into db.tb using db.meters tags(1) values(now, 1); ``` -------------------------------- ### Consume Repeatedly (C) Source: https://github.com/taosdata/tdengine/blob/main/docs/en/07-develop/07-tmq.md C example for consuming messages, fetching topic assignments, seeking to the earliest offset, and starting a consumption loop. ```c {{#include docs/examples/c/tmq_demo.c:consume_repeatedly}} ``` -------------------------------- ### Environment Preparation for MQTT Subscription Source: https://github.com/taosdata/tdengine/blob/main/docs/zh/06-advanced/01-subscription/03-mqtt.md Prepare the TDengine environment by creating a database, a super table, a topic, and a Bnode. This setup is necessary before a client can subscribe to data. ```sql create database db vgroups 1; create table db.meters (ts timestamp, f1 int) tags(t1 int); create topic topic_meters as select ts, tbname, f1, t1 from db.meters; create bnode on dnode 1; ``` -------------------------------- ### Go TMQ Subscription Source: https://github.com/taosdata/tdengine/blob/main/docs/en/07-develop/07-tmq.md Example of subscribing to TMQ topics using Go. This snippet demonstrates the basic setup for a Go TMQ consumer. ```go func subscribe() { topics := []string{"topic1"} err := consumer.Subscribe(topics) if err != nil { log.Fatalf("Failed to subscribe to topics: %v", err) } for { records, err := consumer.Poll() if err != nil { log.Printf("Error polling messages: %v\n", err) continue } if len(records) > 0 { for _, block := range records { for _, record := range block { fmt.Printf("%+v\n", record) } } err = consumer.CommitSync() if err != nil { log.Printf("Failed to commit messages: %v\n", err) } } else { time.Sleep(100 * time.Millisecond) } } } func main() { subscribe() } ``` -------------------------------- ### C TMQ Subscription Example Source: https://github.com/taosdata/tdengine/blob/main/docs/en/07-develop/07-tmq.md A complete C example demonstrating subscription to TMQ topics. It includes creating a topic list, subscribing, and initiating the consume loop. ```c void subscribe_3() { char *topic_list[2]; tmq_consumer *consumer; topic_list[0] = "topic1"; topic_list[1] = "topic2"; consumer = tmq_consumer_create(NULL); if (tmq_subscribe(consumer, topic_list) < 0) { printf("Failed to subscribe to topics\n"); tmq_consumer_destroy(consumer); return; } printf("Successfully subscribed to topics\n"); basic_consume_loop(consumer); tmq_consumer_destroy(consumer); } ``` -------------------------------- ### Establish Native Connection in Java Source: https://github.com/taosdata/tdengine/blob/main/docs/en/07-develop/01-connect.md Connects to TDengine using the native JNI method in Java. This example shows the setup for a native connection. ```java public static void main(String[] args) { try { // Establish native connection Taos taos = Taos.open("taos://localhost:6030"); System.out.println("Successfully connected to TDengine via native connection!"); // Perform database operations here... // Close the connection taos.close(); System.out.println("Connection closed."); } catch (TaosException e) { System.err.println("Failed to connect to TDengine: " + e.getMessage()); e.printStackTrace(); } } ``` -------------------------------- ### Basic TDinsight.sh Configuration Example Source: https://github.com/taosdata/tdengine/blob/main/docs/en/14-reference/01-components/12-tdinsight.md Configures TDinsight.sh with specified TDengine database host, port, user, and password. ```shell ./TDinsight.sh -a http://tdengine:6041 -u root1 -p pass5ord ``` -------------------------------- ### Manage taosanoded Service with Systemd Source: https://github.com/taosdata/tdengine/blob/main/docs/en/06-advanced/06-tdgpt/03-management.md Use systemd commands to start, stop, and check the status of the `taosanoded` service, which is created upon anode installation. ```bash systemctl start taosanoded systemctl stop taosanoded systemctl status taosanoded ``` -------------------------------- ### String `sub_string` Function Examples Source: https://github.com/taosdata/tdengine/blob/main/docs/en/06-advanced/05-data-in/index.md The `sub_string` function extracts a portion of a string. It supports positive and negative start positions, and an optional length parameter. ```sql "012345678".sub_string(5) // "5678" ``` ```sql "012345678".sub_string(5, 2) // "56" ``` ```sql "012345678".sub_string(-2) // "78" ``` -------------------------------- ### Establish Native Connection in C# Source: https://github.com/taosdata/tdengine/blob/main/docs/en/07-develop/01-connect.md Connects to TDengine using the native connection method in C#. This example demonstrates the basic setup for a native connection. ```csharp using TDengine.Driver; using TDengine.Driver.Impl; public class Program { public static void Main(string[] args) { try { // Establish native connection using var client = DbDriver.Open(new ConnectionStringBuilder { Protocol = ProtocolType.Native, Host = "localhost", Port = 6030, Username = "root", Password = "taosdata" }); Console.WriteLine("Successfully connected to TDengine via native connection!"); // Perform database operations here... Console.WriteLine("Connection closed."); } catch (Exception e) { Console.Error.WriteLine($"Failed to connect to TDengine: {e.Message}"); e.StackTrace.ToList().ForEach(Console.Error.WriteLine); } } } ``` -------------------------------- ### PARTITION BY Clause Example Source: https://github.com/taosdata/tdengine/blob/main/docs/en/14-reference/03-taos-sql/20-select.md Demonstrates slicing data into partitions using the PARTITION BY clause. Positional syntax is supported, referencing columns by their order in the SELECT list. ```sql SELECT current FROM meters PARTITION BY 1; ``` -------------------------------- ### Create Database and Table (Go) Source: https://github.com/taosdata/tdengine/blob/main/docs/en/07-develop/02-sql.md Execute SQL commands to create a database and a supertable using Go. ```go db, err := sql.Open(taos.DriverName, "root:taosdata@tcp(127.0.0.1:6030)/power") if err != nil { panic(err) } defer db.Close() db.Exec("CREATE DATABASE IF NOT EXISTS power") db.Exec("USE power") db.Exec("CREATE STABLE IF NOT EXISTS meters (ts TIMESTAMP, current FLOAT, voltage INT, phase FLOAT) TAGS (groupId INT, location BINARY(24))") ``` -------------------------------- ### TAOS SQL WEEK Function Examples Source: https://github.com/taosdata/tdengine/blob/main/docs/en/14-reference/03-taos-sql/22-function.md Demonstrates the WEEK function with different modes to illustrate how the start of the week and return value range affect the output. ```sql taos> select week('2000-01-01',0); week('2000-01-01',0) | ======================== 0 | ``` ```sql taos> select week('2000-01-01',1); week('2000-01-01',1) | ======================== 0 | ``` ```sql taos> select week('2000-01-01',2); week('2000-01-01',2) | ======================== 52 | ``` ```sql taos> select week('2000-01-01',3); week('2000-01-01',3) | ======================== 52 | ``` -------------------------------- ### Install Moment Library Source: https://github.com/taosdata/tdengine/blob/main/docs/en/07-develop/09-udf.md Install the 'moment' library using pip before developing Python UDFs that require it. ```shell pip3 install moment ``` -------------------------------- ### Consume and Seek to Beginning (Java) Source: https://github.com/taosdata/tdengine/blob/main/docs/en/07-develop/07-tmq.md Demonstrates polling data, retrieving partition assignments, seeking to the beginning of partitions, and polling again in Java. ```java {{#include docs/examples/JDBC/JDBCDemo/src/main/java/com/taos/example/WsConsumerLoopFull.java:consumer_seek}} ``` -------------------------------- ### Subscribe to Topic Continuously Source: https://github.com/taosdata/tdengine/blob/main/docs/en/14-reference/02-tools/07-taos-cli.md Subscribe to a topic and receive messages continuously. Press Ctrl+C to stop the subscription. This example starts consuming from the earliest available offset. ```sql taos> subscribe topic_meters -g my_group -o earliest; ``` -------------------------------- ### Install Dependencies and Build Craft Source: https://github.com/taosdata/tdengine/blob/main/contrib/test/craft/help.txt Installs required development libraries and then builds the TDEngine craft component. Ensure you have the necessary permissions to install packages and run build commands. ```bash sudo apt-get install libuv1-dev liblz4-dev autoreconf -i ./configure --enable-example make ``` -------------------------------- ### Direct Python Invocation for TDengine Service Source: https://github.com/taosdata/tdengine/blob/main/tools/tdgpt/packaging/README.md Manually start the TDengine service or manage models by directly invoking Python scripts from the main installed virtual environment. ```bat C:\TDengine\taosanode\venvs\venv\Scripts\python.exe C:\TDengine\taosanode\bin\taosanode_service.py start C:\TDengine\taosanode\venvs\venv\Scripts\python.exe C:\TDengine\taosanode\bin\taosanode_service.py model-start all ``` -------------------------------- ### Example: Create a Power Topic with Filtering Source: https://github.com/taosdata/tdengine/blob/main/docs/en/06-advanced/01-subscription/01-topic.md An example of creating a query topic named 'power_topic' to subscribe to smart meter records where voltage exceeds 200, selecting specific columns. ```sql CREATE TOPIC power_topic AS SELECT ts, current, voltage FROM power.meters WHERE voltage > 200; ``` -------------------------------- ### Node.js Connection with Special Characters Source: https://github.com/taosdata/tdengine/blob/main/docs/en/27-train-faq/03-password.md The Node.js connector supports passwords with all valid characters starting from version 3.1.5. This example demonstrates setting the password using `WSConfig`. ```javascript const taos = require("@tdengine/websocket"); let dsn = 'ws://localhost:6041'; async function createConnect() { try { let conf = new taos.WSConfig(dsn); conf.setUser('user1'); conf.setPwd('Ab1!@#$%^&*()-_+=[]{}'); conf.setDb('test'); conn = await taos.sqlConnect(conf); console.log("Connected to " + dsn + " successfully."); return conn; } catch (err) { console.log("Connection failed with code: " + err.code + ", message: " + err.message); throw err; } } createConnect() ``` -------------------------------- ### Create Database Syntax Source: https://github.com/taosdata/tdengine/blob/main/docs/en/14-reference/03-taos-sql/02-database.md Use this syntax to create a new database. Optional parameters allow for fine-tuning storage and replication settings. ```sql CREATE DATABASE [IF NOT EXISTS] db_name [database_options] database_options: database_option ... database_option: { VGROUPS value | PRECISION {'ms' | 'us' | 'ns'} | REPLICA value | BUFFER value | PAGES value | PAGESIZE value | CACHEMODEL {'none' | 'last_row' | 'last_value' | 'both'} | CACHESIZE value | CACHESHARDBITS value | COMP {0 | 1 | 2} | DURATION value | MAXROWS value | MINROWS value | KEEP value | KEEP_TIME_OFFSET value | STT_TRIGGER value | SINGLE_STABLE {0 | 1} | TABLE_PREFIX value | TABLE_SUFFIX value | DNODES value | TSDB_PAGESIZE value | WAL_LEVEL {1 | 2} | WAL_FSYNC_PERIOD value | WAL_RETENTION_PERIOD value | WAL_RETENTION_SIZE value | SS_KEEPLOCAL value | SS_CHUNKPAGES value | SS_COMPACT value | COMPACT_INTERVAL value | COMPACT_TIME_RANGE value | COMPACT_TIME_OFFSET value } ``` -------------------------------- ### EXTERNAL_WINDOW Example Source: https://github.com/taosdata/tdengine/blob/main/docs/en/14-reference/03-taos-sql/20-select.md Illustrates the use of EXTERNAL_WINDOW for defining custom time-based windows using a subquery. The subquery must return timestamp columns for start and end times. ```sql SELECT * FROM d1.t1 EXTERNAL_WINDOW(ts, ts + 1m, 1m) PARTITION BY tag HAVING COUNT(*) > 1; ``` -------------------------------- ### Subscribe to Topic and Exit After N Messages Source: https://github.com/taosdata/tdengine/blob/main/docs/en/14-reference/02-tools/07-taos-cli.md Subscribe to a topic and automatically exit after receiving a specified number of messages. This example consumes 10 messages starting from the earliest offset. ```sql taos> subscribe topic_meters -g my_group -o earliest -n 10; ``` -------------------------------- ### Create Database with Basic Authentication Source: https://github.com/taosdata/tdengine/blob/main/docs/en/14-reference/05-connector/60-rest-api.md Example of creating a database using Basic Authentication with the REST API. ```shell curl -L -H "Authorization: Basic cm9vdDp0YW9zZGF0YQ==" -d "create database demo" 192.168.0.1:6041/rest/sql ``` -------------------------------- ### Session Window Query Results Source: https://github.com/taosdata/tdengine/blob/main/docs/en/05-basic/03-query.md Example output of a session window query, showing subtable name, window start and end times, window duration, and the count of records within each window. ```text tbname | _wstart | _wend | _wduration | count(*) | =============================================================================================== d2 | 2022-01-01 00:00:00.000 | 2022-01-01 00:09:50.000 | 590000 | 60 | d26 | 2022-01-01 00:00:00.000 | 2022-01-01 00:09:50.000 | 590000 | 60 | d52 | 2022-01-01 00:00:00.000 | 2022-01-01 00:09:50.000 | 590000 | 60 | d64 | 2022-01-01 00:00:00.000 | 2022-01-01 00:09:50.000 | 590000 | 60 | d76 | 2022-01-01 00:00:00.000 | 2022-01-01 00:09:50.000 | 590000 | 60 | d28 | 2022-01-01 00:00:00.000 | 2022-01-01 00:09:50.000 | 590000 | 60 | d4 | 2022-01-01 00:00:00.000 | 2022-01-01 00:09:50.000 | 590000 | 60 | d88 | 2022-01-01 00:00:00.000 | 2022-01-01 00:09:50.000 | 590000 | 60 | d77 | 2022-01-01 00:00:00.000 | 2022-01-01 00:09:50.000 | 590000 | 60 | d54 | 2022-01-01 00:00:00.000 | 2022-01-01 00:09:50.000 | 590000 | 60 | Query OK, 10 row(s) in set (0.043489s) ```