-
Notifications
You must be signed in to change notification settings - Fork 893
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Schedule compression policy more often
By default, the compression policy is scheduled for every chunk_time_interval / 2 in the current implementation, equal to three days and twelve hours with our default settings. This schedule interval was sufficient for previous versions of TimescaleDB. However, with the introduction of features like mutable compression and ON CONFLICT .. DO UPDATE queries, regular DML operations decompress data. To ensure that modified data is compressed earlier, this patch reduces the schedule interval of the compression policy to run at least every 12 hours.
- Loading branch information
1 parent
8c41757
commit 0d7f95b
Showing
4 changed files
with
204 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
-- This file and its contents are licensed under the Timescale License. | ||
-- Please see the included NOTICE for copyright information and | ||
-- LICENSE-TIMESCALE for a copy of the license. | ||
---- | ||
-- Chunk interval 1 month - compression schedule interval should be 12 hours | ||
---- | ||
CREATE TABLE sensor_data_1month( | ||
time timestamptz not null, | ||
sensor_id integer not null | ||
); | ||
SELECT FROM create_hypertable('sensor_data_1month', 'time', chunk_time_interval => INTERVAL '1 month'); | ||
-- | ||
(1 row) | ||
|
||
ALTER TABLE sensor_data_1month SET (timescaledb.compress); | ||
-- Add a compression policy and check the schedule interval | ||
SELECT add_compression_policy('sensor_data_1month','7 days'::INTERVAL) as compression_job \gset | ||
SELECT schedule_interval from timescaledb_information.jobs where job_id = :compression_job; | ||
schedule_interval | ||
------------------- | ||
@ 12 hours | ||
(1 row) | ||
|
||
---- | ||
-- Chunk interval 1 week - compression schedule interval should be 12 hours | ||
---- | ||
CREATE TABLE sensor_data_1week( | ||
time timestamptz not null, | ||
sensor_id integer not null | ||
); | ||
SELECT FROM create_hypertable('sensor_data_1week', 'time', chunk_time_interval => INTERVAL '1 week'); | ||
-- | ||
(1 row) | ||
|
||
ALTER TABLE sensor_data_1week SET (timescaledb.compress); | ||
-- Add a compression policy and check the schedule interval | ||
SELECT add_compression_policy('sensor_data_1week','7 days'::INTERVAL) as compression_job \gset | ||
SELECT schedule_interval from timescaledb_information.jobs where job_id = :compression_job; | ||
schedule_interval | ||
------------------- | ||
@ 12 hours | ||
(1 row) | ||
|
||
---- | ||
-- Chunk interval 1 day - compression schedule interval should be 12 hours | ||
---- | ||
CREATE TABLE sensor_data_1day( | ||
time timestamptz not null, | ||
sensor_id integer not null | ||
); | ||
SELECT FROM create_hypertable('sensor_data_1day', 'time', chunk_time_interval => INTERVAL '1 day'); | ||
-- | ||
(1 row) | ||
|
||
ALTER TABLE sensor_data_1day SET (timescaledb.compress); | ||
-- Add a compression policy and check the schedule interval | ||
SELECT add_compression_policy('sensor_data_1day','7 days'::INTERVAL) as compression_job \gset | ||
SELECT schedule_interval from timescaledb_information.jobs where job_id = :compression_job; | ||
schedule_interval | ||
------------------- | ||
@ 12 hours | ||
(1 row) | ||
|
||
---- | ||
-- Chunk interval 1 hour - compression schedule interval should be 30 minutes | ||
---- | ||
CREATE TABLE sensor_data_1hour( | ||
time timestamptz not null, | ||
sensor_id integer not null | ||
); | ||
SELECT FROM create_hypertable('sensor_data_1hour', 'time', chunk_time_interval => INTERVAL '1 hour'); | ||
-- | ||
(1 row) | ||
|
||
ALTER TABLE sensor_data_1hour SET (timescaledb.compress); | ||
-- Add a compression policy and check the schedule interval | ||
SELECT add_compression_policy('sensor_data_1hour','7 days'::INTERVAL) as compression_job \gset | ||
SELECT schedule_interval from timescaledb_information.jobs where job_id = :compression_job; | ||
schedule_interval | ||
------------------- | ||
@ 30 mins | ||
(1 row) | ||
|
||
---- | ||
-- Chunk interval 1 hour - compression schedule is set to a custom value | ||
---- | ||
CREATE TABLE sensor_data_1hour_custom( | ||
time timestamptz not null, | ||
sensor_id integer not null | ||
); | ||
SELECT FROM create_hypertable('sensor_data_1hour_custom', 'time', chunk_time_interval => INTERVAL '1 hour'); | ||
-- | ||
(1 row) | ||
|
||
ALTER TABLE sensor_data_1hour_custom SET (timescaledb.compress); | ||
-- Add a compression policy and check the schedule interval | ||
SELECT add_compression_policy('sensor_data_1hour_custom','7 days'::INTERVAL, schedule_interval => '7 days') as compression_job \gset | ||
SELECT schedule_interval from timescaledb_information.jobs where job_id = :compression_job; | ||
schedule_interval | ||
------------------- | ||
@ 7 days | ||
(1 row) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
-- This file and its contents are licensed under the Timescale License. | ||
-- Please see the included NOTICE for copyright information and | ||
-- LICENSE-TIMESCALE for a copy of the license. | ||
|
||
---- | ||
-- Chunk interval 1 month - compression schedule interval should be 12 hours | ||
---- | ||
CREATE TABLE sensor_data_1month( | ||
time timestamptz not null, | ||
sensor_id integer not null | ||
); | ||
|
||
SELECT FROM create_hypertable('sensor_data_1month', 'time', chunk_time_interval => INTERVAL '1 month'); | ||
ALTER TABLE sensor_data_1month SET (timescaledb.compress); | ||
|
||
-- Add a compression policy and check the schedule interval | ||
SELECT add_compression_policy('sensor_data_1month','7 days'::INTERVAL) as compression_job \gset | ||
SELECT schedule_interval from timescaledb_information.jobs where job_id = :compression_job; | ||
|
||
---- | ||
-- Chunk interval 1 week - compression schedule interval should be 12 hours | ||
---- | ||
CREATE TABLE sensor_data_1week( | ||
time timestamptz not null, | ||
sensor_id integer not null | ||
); | ||
|
||
SELECT FROM create_hypertable('sensor_data_1week', 'time', chunk_time_interval => INTERVAL '1 week'); | ||
ALTER TABLE sensor_data_1week SET (timescaledb.compress); | ||
|
||
-- Add a compression policy and check the schedule interval | ||
SELECT add_compression_policy('sensor_data_1week','7 days'::INTERVAL) as compression_job \gset | ||
SELECT schedule_interval from timescaledb_information.jobs where job_id = :compression_job; | ||
|
||
---- | ||
-- Chunk interval 1 day - compression schedule interval should be 12 hours | ||
---- | ||
CREATE TABLE sensor_data_1day( | ||
time timestamptz not null, | ||
sensor_id integer not null | ||
); | ||
|
||
SELECT FROM create_hypertable('sensor_data_1day', 'time', chunk_time_interval => INTERVAL '1 day'); | ||
ALTER TABLE sensor_data_1day SET (timescaledb.compress); | ||
|
||
-- Add a compression policy and check the schedule interval | ||
SELECT add_compression_policy('sensor_data_1day','7 days'::INTERVAL) as compression_job \gset | ||
SELECT schedule_interval from timescaledb_information.jobs where job_id = :compression_job; | ||
|
||
|
||
---- | ||
-- Chunk interval 1 hour - compression schedule interval should be 30 minutes | ||
---- | ||
CREATE TABLE sensor_data_1hour( | ||
time timestamptz not null, | ||
sensor_id integer not null | ||
); | ||
|
||
SELECT FROM create_hypertable('sensor_data_1hour', 'time', chunk_time_interval => INTERVAL '1 hour'); | ||
ALTER TABLE sensor_data_1hour SET (timescaledb.compress); | ||
|
||
-- Add a compression policy and check the schedule interval | ||
SELECT add_compression_policy('sensor_data_1hour','7 days'::INTERVAL) as compression_job \gset | ||
SELECT schedule_interval from timescaledb_information.jobs where job_id = :compression_job; | ||
|
||
---- | ||
-- Chunk interval 1 hour - compression schedule is set to a custom value | ||
---- | ||
CREATE TABLE sensor_data_1hour_custom( | ||
time timestamptz not null, | ||
sensor_id integer not null | ||
); | ||
|
||
SELECT FROM create_hypertable('sensor_data_1hour_custom', 'time', chunk_time_interval => INTERVAL '1 hour'); | ||
ALTER TABLE sensor_data_1hour_custom SET (timescaledb.compress); | ||
|
||
-- Add a compression policy and check the schedule interval | ||
SELECT add_compression_policy('sensor_data_1hour_custom','7 days'::INTERVAL, schedule_interval => '7 days') as compression_job \gset | ||
SELECT schedule_interval from timescaledb_information.jobs where job_id = :compression_job; |