【问题标题】:How to start TimescaleDB compression job?如何启动 TimescaleDB 压缩作业?
【发布时间】:2020-10-24 10:14:25
【问题描述】:

我已将大量历史数据加载到 timescaledb 表中。

CREATE TABLE quotes (
    "time" timestamp NULL,
    symbol_id int4 NULL,
    "open" numeric(14,6) NULL,
    "close" numeric(14,6) NULL,
    high numeric(14,6) NULL,
    low numeric(14,6) NULL,
    volume int8 NULL,
    CONSTRAINT quotes_ts_pkey PRIMARY KEY (symbol_id, "time")
);

SELECT create_hypertable('quotes', 'time', 'symbol_id', 1, create_default_indexes => false);

ALTER TABLE quotes SET (
  timescaledb.compress,
  timescaledb.compress_segmentby = 'symbol_id'
);

SELECT add_compress_chunks_policy('quotes', INTERVAL '7 days');

之后我将数据插入到表中:

insert into quotes ("time", data_id, "open", "close", high, low, volume)
select "time", symbol_id, "open", "close", high, low, volume
from source_schema.quotes;

我看到哪些数据没有被压缩。

SELECT * FROM timescaledb_information.compressed_chunk_stats 
ORDER BY compression_status, hypertable_name, chunk_name;

我还可以选择包含旧数据的块,这些数据必须被压缩(这是我的期望)。

SELECT show_chunks('quotes', older_than => INTERVAL '7 days');

如果我尝试压缩块,效果很好:

SELECT compress_chunk('_timescaledb_internal._hyper_1_59_chunk');

但是如何根据指定的策略启动内部 timescaledb 作业以自动压缩块?

【问题讨论】:

    标签: postgresql timescaledb


    【解决方案1】:

    “SELECT add_compress_chunks_policy('quotes', INTERVAL '7 days');”应该为任何超过 7 天的块启动该自动化过程。 (也就是说,块的 end 必须 >= 7 天。)

    您还可以查看压缩数据或后台工作任务的信息视图:

    https://docs.timescale.com/latest/api#timescaledb_information-compressed_hypertable_stats https://docs.timescale.com/latest/api#timescaledb_information-compressed_chunk_stats https://docs.timescale.com/latest/api#timescaledb_information-policy_stats

    从您提供的信息中不确定为什么您没有看到压缩数据。在 slack.timescale.com 上的社区 slack 频道上帮助调试可能会更容易。干杯!

    【讨论】:

    • 谢谢,有帮助:SELECT * FROM timescaledb_information.policy_stats; SELECT alter_job_schedule(1000, next_start => '2020-07-03 17:34:00.0+00');
    • 查找 job_id 随 TSDB v2 更改。现在是 SELECT * FROM timescaledb_information.job_stats; docs.timescale.com/latest/release-notes/…
    • device_id , count , time 如果我添加超过 7 天的压缩策略,是否意味着我仍然可以在 7 天之前进行插入、删除、更新?
    猜你喜欢
    • 2023-03-06
    • 1970-01-01
    • 1970-01-01
    • 2013-06-12
    • 1970-01-01
    • 2022-04-11
    • 1970-01-01
    • 2014-10-30
    • 2013-09-15
    相关资源
    最近更新 更多