Wener Notes

TimeScale

约 2 分钟阅读
bash
# 基于 postgres 上游构建的镜像
# https://github.com/timescale/timescaledb-docker
# timescale/timescaledb-postgis 包含 postgis 扩展
docker run --rm -it \
  -p 5432:5432 \
  -v $PWD/data:/var/lib/postgresql/data \
  -e POSTGRES_DB=timescale \
  -e POSTGRES_USER=timescale \
  -e POSTGRES_PASSWORD=timescale \
  --name timescaledb timescale/timescaledb:latest-pg12

# http://localhost:9201/metrics
# -log-level 默认 debug
# -async-acks 在写入到数据库之前响应 - 可能丢但 metric 场景下一般不影响
docker run --rm -it --link timescaledb:db \
  -p 9201:9201 \
  --name ts-prometheus timescale/timescale-prometheus \
  -async-acks \
  -db-host=db -db-name=timescale -db-port=5432 -db-user=timescale -db-password=timescale

prometheus --config.file=prometheus.yml

prometheus.yml

yaml
global:
  scrape_interval: 15s

scrape_configs:
  - job_name: 'prometheus'
    static_configs:
      - targets: ['localhost:9090']

  - job_name: 'node'
    static_configs:
      - targets: ['localhost:9100']

  - job_name: 'tsdb-prom'
    static_configs:
      - targets: ['localhost:9201']

remote_write:
  - url: 'http://localhost:9201/write'
remote_read:
  - url: 'http://localhost:9201/read'

Notes

  • create_hypertable
    • chunk_time_interval=7d
    • partitioning_column
    • number_partitions - 基于 partitioning_column 的 hash 分片
    • associated_schema_name=_timescaledb_internal
    • associated_table_prefix=_hyper
    • replication_factor=timescaledb.hypertable_replication_factor_default
    • docs.timescale.com/api/latest/hypertable/create_hypertable
sql
SELECT create_hypertable('samples', 'ts', chunk_time_interval => INTERVAL '7 day');

select chunks_detailed_size('samples');
select * from timescaledb_information.chunks;

Direct Columnstore Insert

sql
SET timescaledb.enable_direct_compress_insert = true;
SET timescaledb.enable_direct_compress_copy = true;

关联信息

反向链接、本文链接的其他页面和外部资料。

反向链接

  • Database Awesome
    笔记 · timescale

    | name | stand for | · | Relational DBMS | 关系型数据库 | · | Key-value stores | KV 存储 | · | Document stores | 文档存储 | · | Time Series DBMS | 时序数据库 |

References

GitHub6 条
其他外链9 条
最近更新commit 0fa4c28Edit

On this page