Files
nexus/wiki/concepts/时序数据库.md
2026-04-22 04:03:04 +08:00

58 lines
2.5 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
---
title: "时序数据库"
type: concept
aliases: [Time Series Database, TSDB, 时序数据, 时间序列数据库]
tags: [database, monitoring, time-series, storage]
date: 2025-11-11
---
# 时序数据库
## Overview
时序数据库Time Series DatabaseTSDB是一种专门为带时间戳的数据点序列设计的数据库类型适用于监控指标、传感器数据、金融行情等场景。与传统关系型数据库相比TSDB 针对高写入吞吐、时间范围查询、聚合分析做了专门优化,是现代可观测性系统的核心基础设施。
## Core Properties
- **时间戳主键**:每条记录以时间戳为核心标识
- **高写入吞吐**:支持每秒百万级数据点写入
- **时间范围查询**:高效的范围扫描和聚合
- **数据降采样**自动压缩历史数据high-resolution → low-resolution
- **保留策略**按时间自动过期旧数据Retention Policy
## Key Operations
| 操作 | 说明 | 示例 |
|------|------|------|
| 插入 | 写入带时间戳的数据点 | `metric{labels} value timestamp` |
| 查询 | 时间范围检索 | `WHERE time > t1 AND time < t2` |
| 聚合 | 按时间窗口聚合 | `rate(metric[5m])``avg_over_time(metric[1h])` |
| 降采样 | 降低历史数据精度 | 1s → 1m → 1h → 1d |
| 内插 | 估算缺失数据点 | 线性内插、Previous Forward Fill |
## Data Model
```
Metric Name: node_cpu_seconds_total
Labels: {cpu="0", host="server1", mode="user"}
Data Points: (timestamp=1700000000, value=1234.56), (timestamp=1700000015, value=1235.10), ...
```
## Leading TSDB Solutions
| 产品 | 特点 | 适用场景 |
|------|------|----------|
| [[Prometheus]] TSDB | 单实例设计,简约高效 | 单节点/小规模监控 |
| [[VictoriaMetrics]] | PromQL 兼容,长期存储 | 中小型集群 |
| InfluxDB | Telegraf 生态丰富 | IoT/传感器 |
| TimescaleDB | PostgreSQL 扩展 | 需要 SQL 的场景 |
| QuestDB | 高性能SQL 接口 | 金融高频数据 |
| Thanos | Prometheus 长期存储 | 多租户/大规模 |
| Grafana Mimir | Grafana 官方后端 | 企业级监控 |
## Related Entities
- [[Prometheus]] — 核心 TSDB 实现
- [[VictoriaMetrics]] — Prometheus 兼容替代方案
## Related Concepts
- [[Exporter]] — TSDB 的数据来源
- [[PromQL]] — TSDB 查询语言
- [[Prometheus告警规则]] — 基于 TSDB 数据的告警
- [[System Monitoring]] — 上游应用领域
- [[Centralized Logging]] — 互补的可观测性数据(日志/追踪)