2月14日。
情人节的下午,别人都在订餐厅买花,我在这捣鼓数据库。
窗外是个适合约会的阴天,屋里只有风扇在转。
也挺好。
冷冰冰的机器,至少比人诚实。
你给它指令,它就执行,从不问为什么。
tar -zxvf TDengine-server-3.3.3.0-Linux-x64.tar.gz
第一步:像个原始人一样,下载那个包
去官网。
cd TDengine-server-3.3.3.0/
./install.sh
或者 whatever,找个信得过的镜像源。
3.3版本,不大,几十兆的东西。
去点击那个链接,注视着进度条慢慢地行进直至走完,内心不知因何缘故涌起一种满足之感,仿佛已然将数据装入脑海之中了。
我讨厌那种“下一步,下一步,完成”的安装包。
给它解压,借助tar或者unzip,瞧那些文件仿若流水那般哗啦啦地滚滚而出。
有人说这麻烦。
./start-all.sh
但我觉得,这才是“安装”该有的仪式感。
你得亲手触碰那些文件,才知道你把什么东西放进了你的电脑。
./start-all.sh
taosd has been started successfully
taosadapter has been started successfully
taos-explorer has been started successfully
taoskeeper has been started successfully
启动它!
让那个进程活过来!
终端,黑乎乎的窗口。
敲下那一行命令,就像念了一句咒语。
systemctl start 或者直接 ./taosd?
看你的习惯。
taos
Welcome to the TDengine Command Line Interface, Client Version:3.3.3.0
Copyright (c) 2023 by TDengine, all rights reserved.
********************************* Tab Completion *************************************
* The TDengine CLI supports tab completion for a variety of items, *
* including database names, table names, function names and keywords. *
* The full list of shortcut keys is as follows: *
* [ TAB ] ...... complete the current word *
* ...... if used on a blank line, display all supported commands *
* [ Ctrl + A ] ...... move cursor to the st[A]rt of the line *
* [ Ctrl + E ] ...... move cursor to the [E]nd of the line *
* [ Ctrl + W ] ...... move cursor to the middle of the line *
* [ Ctrl + L ] ...... clear the entire screen *
* [ Ctrl + K ] ...... clear the screen after the cursor *
* [ Ctrl + U ] ...... clear the screen before the cursor *
****************************************************************************************
Server is TDengine Community Edition, ver:3.3.3.0 and will never expire.
taos>
听到风扇猛地一转,或者看到那个光标在闪,没有报错。
成了。
一个被称作数据库“实例”且属于活的事物的东西,就这样在你的机器当中开始有了类似呼吸的状态 ,有了类似呼吸的状态 ,有了类似呼吸的状态。
进去看看?
那个叫 taos 的黑洞
新开一个窗口。
taos> CREATE DATABASE demo;
Create OK, 0 row(s) affected (1.124408s)
taos> USE demo;
Database changed.
taos> CREATE TABLE t (ts TIMESTAMP, speed INT);
Create OK, 0 row(s) affected (0.000997s)
taos> INSERT INTO t VALUES ('2019-07-15 00:00:00', 10);
Insert OK, 1 row(s) affected (0.000910s)
taos> INSERT INTO t VALUES ('2019-07-15 01:00:00', 20);
Insert OK, 1 row(s) affected (0.005860s)
taos> SELECT * FROM t;
ts | speed |
========================================
2019-07-15 00:00:00.000 | 10 |
2019-07-15 01:00:00.000 | 20 |
Query OK, 2 row(s) in set (0.005122s)
输入 taos。
回车。
那个熟悉的提示符出现了。
像个通向另一个世界的入口。
这个世界里没有情人节,只有 0 和 1。
然后,创造点什么吧
得给它点东西装进去。
总不能空着。
创建个数据库,嗯,就叫 test 吧,土的掉渣,但管用。
建一张表。
不,等等,听说这玩意挺牛,能建“超级表”?
试试。
用那个号称专为测试性能而生的工具 。
taosBenchmark -y
### 超级表?
名字挺唬人,到底是个啥?
说白了啊,就是个模板。
一张超级表底下能挂几万个结构一样但标签不同的子表 。
听起来是不是像搞批发的?
对,就是这意思。
我让工具帮我干点脏活累活。
终端里敲下那条命令,让它去折腾:
于test库之中,构建一张超级表,其名称不定,那就称作meters好了。
接着下面,去悬挂它一万张子表,其名字是从代码为“d0”按照顺序排列到代码为“d9999”。
每张子表里,给我塞 10,000 条记录 。
数据长啥样?
简单点。
时刻标记(ts),电流数值(current),电压幅度(voltage),以及相位情况(phase)。
时间起始于 “2017 - 07 - 14 10:40:00.000” ,它向前行进,走过时长为 10 秒的一段历程,最终抵达 09.999 这个节点而结束。
刚好十秒?
可能吧,我懒得算了。
反正每秒一千条,够密了。
每张子表还得有两个标签。
一个 groupid,从 1 到 10 循环着来。
给出一个 location,在其中写上 “北京.beijing”,或者写上 “上海.shanghai”,亦或是类似这样的内容。
命令敲下去。
回车。
然后盯着屏幕。
唰——
真的,就是那种感觉。
光标在闪,数字在跳。
一万乘以一万,那是多少来着?
taosBenchmark --help
对,一个亿。
一亿条数据,就这么哗哗地往硬盘里灌。
十几秒?
我泡了杯咖啡回来,还没喝,它就完事儿了。
说实话,挺震撼的。
虽然这机器不咋地,但这速度,还是让人有点头皮发麻 。
taosBenchmark -y
[10/12 13:53:31.737500] INFO: thread[2] has currently inserted rows: 6680000, peroid insert rate: 57478.902 rows/s
[10/12 13:54:01.626770] INFO: thread[7] has currently inserted rows: 8750000, peroid insert rate: 56196.588 rows/s
[10/12 13:54:01.636041] INFO: thread[0] has currently inserted rows: 8850000, peroid insert rate: 65632.458 rows/s
[10/12 13:54:01.644073] INFO: thread[3] has currently inserted rows: 8720000, peroid insert rate: 59466.463 rows/s
[10/12 13:54:01.714261] INFO: thread[6] has currently inserted rows: 9090000, peroid insert rate: 65726.141 rows/s
[10/12 13:54:01.741624] INFO: thread[5] has currently inserted rows: 9110000, peroid insert rate: 63152.297 rows/s
[10/12 13:54:01.781242] INFO: thread[4] has currently inserted rows: 9460000, peroid insert rate: 74258.246 rows/s
[10/12 13:54:01.783933] INFO: thread[2] has currently inserted rows: 8400000, peroid insert rate: 57245.557 rows/s
[10/12 13:54:01.839000] INFO: thread[1] has currently inserted rows: 8960000, peroid insert rate: 64533.210 rows/s
[10/12 13:54:31.692352] INFO: thread[0] has currently inserted rows: 10630000, peroid insert rate: 59222.784 rows/s
[10/12 13:54:31.738517] INFO: thread[7] has currently inserted rows: 10660000, peroid insert rate: 63429.862 rows/s
[10/12 13:54:31.749352] INFO: thread[6] has currently inserted rows: 11010000, peroid insert rate: 63925.420 rows/s
[10/12 13:54:31.804888] INFO: thread[3] has currently inserted rows: 10600000, peroid insert rate: 62334.218 rows/s
[10/12 13:54:31.836902] INFO: thread[2] has currently inserted rows: 10250000, peroid insert rate: 61557.914 rows/s
[10/12 13:54:31.946442] INFO: thread[5] has currently inserted rows: 11060000, peroid insert rate: 64558.848 rows/s
[10/12 13:54:32.007113] INFO: thread[4] has currently inserted rows: 11290000, peroid insert rate: 60543.903 rows/s
[10/12 13:54:32.014142] INFO: thread[1] has currently inserted rows: 10770000, peroid insert rate: 59983.430 rows/s
[10/12 13:54:55.829381] SUCC: thread[4] progressive mode, completed total inserted rows: 12500000, 68051.64 records/second
[10/12 13:54:58.067199] SUCC: thread[5] progressive mode, completed total inserted rows: 12500000, 67456.82 records/second
[10/12 13:54:58.491784] SUCC: thread[6] progressive mode, completed total inserted rows: 12500000, 67453.45 records/second
[10/12 13:55:00.483286] SUCC: thread[1] progressive mode, completed total inserted rows: 12500000, 65938.78 records/second
[10/12 13:55:01.719979] INFO: thread[0] has currently inserted rows: 12340000, peroid insert rate: 56948.746 rows/s
[10/12 13:55:01.839691] INFO: thread[3] has currently inserted rows: 12360000, peroid insert rate: 58598.302 rows/s
[10/12 13:55:01.858470] INFO: thread[7] has currently inserted rows: 12410000, peroid insert rate: 58100.930 rows/s
[10/12 13:55:01.984463] INFO: thread[2] has currently inserted rows: 12020000, peroid insert rate: 58710.362 rows/s
[10/12 13:55:02.896923] SUCC: thread[7] progressive mode, completed total inserted rows: 12500000, 65533.55 records/second
[10/12 13:55:03.323273] SUCC: thread[3] progressive mode, completed total inserted rows: 12500000, 65662.65 records/second
[10/12 13:55:03.563548] SUCC: thread[0] progressive mode, completed total inserted rows: 12500000, 65438.26 records/second
[10/12 13:55:03.564967] INFO: pthread_join 1 ...
[10/12 13:55:03.565000] INFO: pthread_join 2 ...
[10/12 13:55:04.986802] SUCC: thread[2] progressive mode, completed total inserted rows: 12500000, 65438.63 records/second
[10/12 13:55:04.987292] INFO: pthread_join 3 ...
[10/12 13:55:04.987317] INFO: pthread_join 4 ...
[10/12 13:55:04.987347] INFO: pthread_join 5 ...
[10/12 13:55:04.987361] INFO: pthread_join 6 ...
[10/12 13:55:04.987375] INFO: pthread_join 7 ...
[10/12 13:55:04.988953] SUCC: Spent 213.814175 (real 188.377236) seconds to insert rows: 100000000 with 8 thread(s) into test 467695.84 (real 530849.70) records/second
[10/12 13:55:04.988984] SUCC: insert delay, min: 16.7500ms, avg: 150.7018ms, p90: 240.1580ms, p95: 276.0430ms, p99: 359.5250ms, max: 716.8750ms
查查吧,别光顾着造
数据进去了,是骡子是马,得拉出来遛遛。
切回 taos 那个命令行界面。
先数数总共有多少条?
,选取,计数,,,从 测试下的仪表表中。 标点为分号。
100000000。
taos> show databases;
name |
=================================
information_schema |
performance_schema |
demo |
log |
test |
Query OK, 5 row(s) in set (0.018932s)
taos> use test;
Database changed.
嗯,一个没少。
算算平均值、最大最小值?
结果秒回。
那种感觉怎么说呢?
就像你对着空旷的山谷吼一声,立刻就有回声。
你知道它在那,而且比你想象的反应更快。
再具体点。
就想看看 “北京” 那个分站的数据有多少?
想要从名为test的数据库里的meters表中,统计出在位置等于“beijing.shijingshan”的那部分数据的数量,从而执行这样一条查询语句。
也是秒回。
这要是放在传统数据库里,没索引的话,早该全表扫描卡死了 。
### 聚合!
这才是数据库的灵魂
玩点花的。
taos> SELECT COUNT(*) FROM test.meters;
count(*) |
========================
100000000 |
Query OK, 1 row(s) in set (0.253498s)
我期冀查看名为“d1001”的这张表格,按照每10秒作为一个窗口的标准,电流的平均值以及电压的最大最小值究竟是多少呢?
结果出来了。
整整齐齐,时间窗口切得跟刀切西瓜似的。
那个 _wstart,伪列,告诉你每个窗口从哪开始 。
你瞧着这些数字,你脑海之中大概能够浮现出那物件,这十秒之内经历了啥。
电流高了,电压稳了,相位偏了... 有点意思。
查完累了。
得找个好看的界面。
taos> SELECT AVG(current), MAX(voltage), MIN(phase) FROM test.meters;
avg(current) | max(voltage) | min(phase) |
==================================================================
10.208735134506226 | 258 | 145.0000000 |
Query OK, 1 row(s) in set (4.253205s)
可视化?
终于不用看黑框了
装个工具吧。
Navicat,或者DBeaver,或者他们自家的那个什么IDE。
下个包,解压,双击打开。
填连接信息:
主机: localhost 或者你的 IP
端口: 那个熟悉的 6030?
还是别的?
taos> SELECT COUNT(*) FROM test.meters WHERE location = "California.SanFrancisco";
count(*) |
========================
10070000 |
Query OK, 1 row(s) in set (0.038677s)
用户: root
密码: 你设的那个,或者初始是 taosdata?
记住,第一次进去,密码大概率是错的或者空的。
文档里说得很清楚,有时候你得用命令行先改密码 。
执行对用户“root”的修改操作,将其密码设置为“你自己的密码”。
这步搞不定,可视化工具永远连不上。
点一下“测试连接”。
成功!
那种感觉,就像给一匹野马套上了缰绳。
舒服。
taos> SELECT AVG(current), MAX(voltage), MIN(phase) FROM test.meters WHERE groupId = 10;
avg(current) | max(voltage) | min(phase) |
==================================================================
10.208735134506226 | 258 | 145.0000000 |
Query OK, 1 row(s) in set (0.450205s)
写在最后
一个下午就这么过去了。
装了数据库,建了一亿条假数据,查了,看了,用了工具。
外面天黑了,不知道还有没有人记得今天是什么日子。
机器不知道,它只知道计算和存储。
但我替它记住了。
2026年2月14日,下午2点07分开始,我们用了一个多小时,在一个几寸大的屏幕上,创造了一个数据宇宙。
虽然这个宇宙,几分钟后就会被我一键删掉。
但在那十几秒的时间里,实现了写入一亿条的情况,而在达成这一情况之际进行的瞬间,由那种速度所引发的颅内高潮,这实际是真实存在的。
taos> SELECT _wstart, AVG(current), MAX(voltage), MIN(phase) FROM test.d1001 INTERVAL(10s);
_wstart | avg(current) | max(voltage) | min(phase) |
============================================================================================
2017-07-14 10:40:00.000 | 10.208735134506226 | 258 | 145.0000000 |
Query OK, 1 row(s) in set (0.025560s)

Comments NOTHING