TimescaleDB 在第一次插入旧数据后压缩块

TimescaleDB compress chunks during after first insertion of older data

我有一个 TimescaleDB hypertable,它根据我的时间戳列每 1 个月的时间间隔分成几块。

TimescaleDB 是否使用相同的时间戳列来定义何时必须压缩块?

如果是这样,处理以下问题的最佳方法是什么:

我想从更早的时间开始填充此 table,比方说,2017 年。

当我启动我的软件进行这些插入时,在它插入第一行(带有 2017 年的时间戳)后,它将压缩 table,然后无法在同一块中进行下一次插入。

有办法避免吗?我可以暂时禁用所有块的压缩,然后在完成后重新启用它吗?

或者我可以通过某种方式强制插入,使 TimescaleDB 透明地进行解压缩、插入和重新压缩吗?

此外,我能否将压缩间隔的行为更改为基于插入行时而不是我的时间戳(这样即使我现在添加 2017 年的数据,它只会在一个月后压缩它今天)?

Does TimescaleDB use the same timestamp column to define when a chunk has to be compressed?

它将始终使用主键时间列。您可以指定时间间隔。
当主键有其他列时(时间除外,例如下面示例中的 device_id),您可以使用 segmentedby option: see this example from the docs

ALTER TABLE measurements SET (
  timescaledb.compress,
  timescaledb.compress_segmentby = 'device_id'
);

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

If so, how is the best method to handle the following issue: I want to populate this table starting from an older time, let's say, 2017. When I start my software to do these insertions, after it inserts the first row (with a timestamp from 2017) it will compress the table and then fail to do the next insertion in the same chunk. Is there a way to avoid that? can I momentarily disable compression for all chunks and then reenable it after I'm done?

您可以先创建超表(不压缩),然后插入您的历史数据,最后启用压缩(参见上面的示例代码)。
您还可以使用 Manual Compression:这样您就可以完全控制并决定压缩哪些块以及何时压缩它们

Or can I someway force the insertion making TimescaleDB do the decompression, insertion, and recompression after that transparently?

计划在 future versions

中修改压缩数据

另请注意,时间刻度将不允许更改压缩超表的架构(请参阅 docs 中的警告)

The current release of TimescaleDB supports the ability to query data in compressed chunks. However, it does not support inserts or updates into compressed chunks. We also block modifying the schema of hypertables with compressed chunks.