From 275bab232ccb179a974c8882899c381c2ab4b30c Mon Sep 17 00:00:00 2001 From: Jan Nidzwetzki Date: Thu, 21 Sep 2023 11:43:53 +0200 Subject: [PATCH] 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. --- scripts/docker-build.sh | 2 +- test/sql/updates/setup.policies.sql | 21 +++- tsl/src/bgw_policy/compression_api.c | 23 ++++- tsl/test/expected/bgw_custom.out | 8 +- tsl/test/expected/bgw_db_scheduler_fixed.out | 8 +- tsl/test/expected/bgw_policy.out | 10 +- tsl/test/expected/cagg_migrate.out | 28 ++--- tsl/test/expected/cagg_policy.out | 8 +- tsl/test/expected/compression_bgw.out | 6 +- tsl/test/expected/compression_policy.out | 103 +++++++++++++++++++ tsl/test/sql/CMakeLists.txt | 1 + tsl/test/sql/compression_policy.sql | 79 ++++++++++++++ 12 files changed, 255 insertions(+), 42 deletions(-) create mode 100644 tsl/test/expected/compression_policy.out create mode 100644 tsl/test/sql/compression_policy.sql diff --git a/scripts/docker-build.sh b/scripts/docker-build.sh index 49a116da3c0..08eb1d914c7 100755 --- a/scripts/docker-build.sh +++ b/scripts/docker-build.sh @@ -80,7 +80,7 @@ build_timescaledb() cd /build/debug \ && git config --global --add safe.directory /src \ && cmake -DGENERATE_DOWNGRADE_SCRIPT=${GENERATE_DOWNGRADE_SCRIPT} -DENABLE_DEBUG_UTILS=off -DUSE_OPENSSL=${USE_OPENSSL} -DCMAKE_BUILD_TYPE=${BUILD_TYPE} /src \ - && make && make install \ + && make -j 4 && make install \ && echo \"shared_preload_libraries = 'timescaledb'\" >> /usr/local/share/postgresql/postgresql.conf.sample \ && echo \"timescaledb.telemetry_level=off\" >> /usr/local/share/postgresql/postgresql.conf.sample \ && cd / && rm -rf /build" diff --git a/test/sql/updates/setup.policies.sql b/test/sql/updates/setup.policies.sql index d63a3eac657..e6bb50a0e48 100644 --- a/test/sql/updates/setup.policies.sql +++ b/test/sql/updates/setup.policies.sql @@ -20,21 +20,32 @@ SELECT DO LANGUAGE PLPGSQL $$ DECLARE - ts_version TEXT; + ts_major TEXT; + ts_minor TEXT; BEGIN - SELECT extversion INTO ts_version FROM pg_extension WHERE extname = 'timescaledb'; + SELECT + (string_to_array(extversion,'.'))[1] INTO ts_major + FROM pg_extension WHERE extname = 'timescaledb'; + + SELECT + (string_to_array(extversion,'.'))[2] INTO ts_minor + FROM pg_extension WHERE extname = 'timescaledb'; PERFORM add_reorder_policy('policy_test_timestamptz','policy_test_timestamptz_time_idx'); -- some policy API functions got renamed for 2.0 so we need to make - -- sure to use the right name for the version - IF ts_version < '2.0.0' THEN + -- sure to use the right name for the version. The schedule_interval + -- parameter of add_compression_policy was introduced in 2.8.0 + IF ts_major < 2 THEN PERFORM add_drop_chunks_policy('policy_test_timestamptz','60d'::interval); PERFORM add_compress_chunks_policy('policy_test_timestamptz','10d'::interval); - ELSE + ELSIF ts_major <= 2 AND ts_minor < 8 THEN PERFORM add_retention_policy('policy_test_timestamptz','60d'::interval); PERFORM add_compression_policy('policy_test_timestamptz','10d'::interval); + ELSE + PERFORM add_retention_policy('policy_test_timestamptz','60d'::interval); + PERFORM add_compression_policy('policy_test_timestamptz','10d'::interval, schedule_interval => '3 days 12:00:00'::interval); END IF; END $$; diff --git a/tsl/src/bgw_policy/compression_api.c b/tsl/src/bgw_policy/compression_api.c index 0dd3c06a956..2bbd86c1bb7 100644 --- a/tsl/src/bgw_policy/compression_api.c +++ b/tsl/src/bgw_policy/compression_api.c @@ -34,6 +34,11 @@ #define DEFAULT_RETRY_PERIOD \ DatumGetIntervalP(DirectFunctionCall3(interval_in, CStringGetDatum("1 hour"), InvalidOid, -1)) +/* Default max schedule period for the compression policy is 12 hours. The actual schedule period + * will be chunk_interval/2 if the chunk_interval is < 12 hours. */ +#define DEFAULT_MAX_SCHEDULE_PERIOD \ + DatumGetIntervalP(DirectFunctionCall3(interval_in, CStringGetDatum("12 hours"), InvalidOid, -1)) + static Hypertable *validate_compress_chunks_hypertable(Cache *hcache, Oid user_htoid, bool *is_cagg); @@ -248,8 +253,22 @@ policy_compression_add_internal(Oid user_rel_oid, Datum compress_after_datum, if (dim && IS_TIMESTAMP_TYPE(ts_dimension_get_partition_type(dim)) && !user_defined_schedule_interval) { - default_schedule_interval = DatumGetIntervalP( - ts_internal_to_interval_value(dim->fd.interval_length / 2, INTERVALOID)); + int64 hypertable_schedule_interval = dim->fd.interval_length / 2; + int64 max_schedule_interval = + ts_interval_value_to_internal(IntervalPGetDatum(DEFAULT_MAX_SCHEDULE_PERIOD), + INTERVALOID); + + /* On hypertables with a small chunk_time_interval, schedule the compression job more often + * than DEFAULT_MAX_SCHEDULE_PERIOD */ + if (max_schedule_interval > hypertable_schedule_interval) + { + default_schedule_interval = DatumGetIntervalP( + ts_internal_to_interval_value(hypertable_schedule_interval, INTERVALOID)); + } + else + { + default_schedule_interval = DEFAULT_MAX_SCHEDULE_PERIOD; + } } /* insert a new job into jobs table */ diff --git a/tsl/test/expected/bgw_custom.out b/tsl/test/expected/bgw_custom.out index aa04b999d69..fcb7d13e0b3 100644 --- a/tsl/test/expected/bgw_custom.out +++ b/tsl/test/expected/bgw_custom.out @@ -476,7 +476,7 @@ order by id; select t.schedule_interval FROM alter_job(:job_id_4, next_start=> now() ) t; schedule_interval ------------------- - @ 7 days 12 hours + @ 12 hours (1 row) SELECT wait_for_job_to_run(:job_id_4, 2); @@ -917,9 +917,9 @@ ALTER TABLE sensor_data SET (timescaledb.compress, timescaledb.compress_orderby SELECT add_compression_policy('sensor_data', INTERVAL '1' minute) AS compressjob_id \gset -- set recompress to true SELECT alter_job(id,config:=jsonb_set(config,'{recompress}', 'true')) FROM _timescaledb_config.bgw_job WHERE id = :compressjob_id; - alter_job ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- - (1014,"@ 3 days 12 hours","@ 0",-1,"@ 1 hour",t,"{""recompress"": true, ""hypertable_id"": 4, ""compress_after"": ""@ 1 min""}",-infinity,_timescaledb_functions.policy_compression_check,f,,) + alter_job +----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- + (1014,"@ 12 hours","@ 0",-1,"@ 1 hour",t,"{""recompress"": true, ""hypertable_id"": 4, ""compress_after"": ""@ 1 min""}",-infinity,_timescaledb_functions.policy_compression_check,f,,) (1 row) -- create new chunks diff --git a/tsl/test/expected/bgw_db_scheduler_fixed.out b/tsl/test/expected/bgw_db_scheduler_fixed.out index 0fe9dcccaa1..d92dbfead1c 100644 --- a/tsl/test/expected/bgw_db_scheduler_fixed.out +++ b/tsl/test/expected/bgw_db_scheduler_fixed.out @@ -1696,7 +1696,7 @@ select * from _timescaledb_config.bgw_job; id | application_name | schedule_interval | max_runtime | max_retries | retry_period | proc_schema | proc_name | owner | scheduled | fixed_schedule | initial_start | hypertable_id | config | check_schema | check_name | timezone ------+--------------------------------------------+-------------------+-------------+-------------+--------------+------------------------+-------------------------------------+------------+-----------+----------------+----------------------------------+---------------+--------------------------------------------------------------------------------+------------------------+-------------------------------------------+--------------- 1026 | Retention Policy [1026] | @ 1 day | @ 5 mins | -1 | @ 5 mins | _timescaledb_functions | policy_retention | super_user | t | t | Fri Dec 31 16:00:00 1999 PST | 1 | {"drop_after": "@ 2 years", "hypertable_id": 1} | _timescaledb_functions | policy_retention_check | Europe/Berlin - 1027 | Compression Policy [1027] | @ 15 days | @ 0 | -1 | @ 1 hour | _timescaledb_functions | policy_compression | super_user | t | t | Fri Dec 31 16:00:00 1999 PST | 1 | {"hypertable_id": 1, "compress_after": "@ 1 year"} | _timescaledb_functions | policy_compression_check | Europe/Berlin + 1027 | Compression Policy [1027] | @ 12 hours | @ 0 | -1 | @ 1 hour | _timescaledb_functions | policy_compression | super_user | t | t | Fri Dec 31 16:00:00 1999 PST | 1 | {"hypertable_id": 1, "compress_after": "@ 1 year"} | _timescaledb_functions | policy_compression_check | Europe/Berlin 1028 | Refresh Continuous Aggregate Policy [1028] | @ 21 days | @ 0 | -1 | @ 21 days | _timescaledb_functions | policy_refresh_continuous_aggregate | super_user | t | t | Fri Dec 31 16:00:00.005 1999 PST | 2 | {"end_offset": "@ 2 mons", "start_offset": "@ 1 year", "mat_hypertable_id": 2} | _timescaledb_functions | policy_refresh_continuous_aggregate_check | Europe/Athens (3 rows) @@ -1711,7 +1711,7 @@ SELECT * from _timescaledb_internal.bgw_job_stat; job_id | last_start | last_finish | next_start | last_successful_finish | last_run_success | total_runs | total_duration | total_duration_failures | total_successes | total_failures | total_crashes | consecutive_failures | consecutive_crashes | flags --------+----------------------------------+----------------------------------+----------------------------------+----------------------------------+------------------+------------+----------------+-------------------------+-----------------+----------------+---------------+----------------------+---------------------+------- 1026 | Fri Dec 31 16:00:00 1999 PST | Fri Dec 31 16:00:00 1999 PST | Sat Jan 01 16:00:00 2000 PST | Fri Dec 31 16:00:00 1999 PST | t | 1 | @ 0 | @ 0 | 1 | 0 | 0 | 0 | 0 | 0 - 1027 | Fri Dec 31 16:00:00 1999 PST | Fri Dec 31 16:00:00 1999 PST | Sat Jan 15 16:00:00 2000 PST | Fri Dec 31 16:00:00 1999 PST | t | 1 | @ 0 | @ 0 | 1 | 0 | 0 | 0 | 0 | 0 + 1027 | Fri Dec 31 16:00:00 1999 PST | Fri Dec 31 16:00:00 1999 PST | Sat Jan 01 04:00:00 2000 PST | Fri Dec 31 16:00:00 1999 PST | t | 1 | @ 0 | @ 0 | 1 | 0 | 0 | 0 | 0 | 0 1028 | Fri Dec 31 16:00:00.005 1999 PST | Fri Dec 31 16:00:00.005 1999 PST | Fri Jan 21 16:00:00.005 2000 PST | Fri Dec 31 16:00:00.005 1999 PST | t | 1 | @ 0 | @ 0 | 1 | 0 | 0 | 0 | 0 | 0 (3 rows) @@ -1780,7 +1780,7 @@ select * from _timescaledb_config.bgw_job order by id; id | application_name | schedule_interval | max_runtime | max_retries | retry_period | proc_schema | proc_name | owner | scheduled | fixed_schedule | initial_start | hypertable_id | config | check_schema | check_name | timezone ------+--------------------------------------------+-------------------+-------------+-------------+--------------+------------------------+-------------------------------------+------------+-----------+----------------+----------------------------------+---------------+--------------------------------------------------------------------------------+------------------------+-------------------------------------------+--------------- 1026 | Retention Policy [1026] | @ 1 day | @ 5 mins | -1 | @ 5 mins | _timescaledb_functions | policy_retention | super_user | t | t | Fri Dec 31 16:00:00 1999 PST | 1 | {"drop_after": "@ 2 years", "hypertable_id": 1} | _timescaledb_functions | policy_retention_check | Europe/Berlin - 1027 | Compression Policy [1027] | @ 15 days | @ 0 | -1 | @ 1 hour | _timescaledb_functions | policy_compression | super_user | t | t | Fri Dec 31 16:00:00 1999 PST | 1 | {"hypertable_id": 1, "compress_after": "@ 1 year"} | _timescaledb_functions | policy_compression_check | Europe/Berlin + 1027 | Compression Policy [1027] | @ 12 hours | @ 0 | -1 | @ 1 hour | _timescaledb_functions | policy_compression | super_user | t | t | Fri Dec 31 16:00:00 1999 PST | 1 | {"hypertable_id": 1, "compress_after": "@ 1 year"} | _timescaledb_functions | policy_compression_check | Europe/Berlin 1028 | Refresh Continuous Aggregate Policy [1028] | @ 21 days | @ 0 | -1 | @ 21 days | _timescaledb_functions | policy_refresh_continuous_aggregate | super_user | t | t | Fri Dec 31 16:00:00.005 1999 PST | 2 | {"end_offset": "@ 2 mons", "start_offset": "@ 1 year", "mat_hypertable_id": 2} | _timescaledb_functions | policy_refresh_continuous_aggregate_check | Europe/Athens 1029 | User-Defined Action [1029] | @ 7 mons | @ 0 | -1 | @ 5 mins | public | job_test_fixed | super_user | t | t | Fri Dec 31 16:00:00.01 1999 PST | | | | | 1030 | User-Defined Action [1030] | @ 7 mons | @ 0 | -1 | @ 5 mins | public | job_test_fixed | super_user | t | t | Fri Dec 31 16:00:00.01 1999 PST | | | | | Europe/Athens @@ -1798,7 +1798,7 @@ ORDER BY job_id; job_id | last_start | last_finish | next_start | last_successful_finish --------+------------------------------+------------------------------+------------------------------+------------------------------ 1026 | Fri Dec 31 16:00:00 1999 PST | Fri Dec 31 16:00:00 1999 PST | Sat Jan 01 16:00:00 2000 PST | Fri Dec 31 16:00:00 1999 PST - 1027 | Fri Dec 31 16:00:00 1999 PST | Fri Dec 31 16:00:00 1999 PST | Sat Jan 15 16:00:00 2000 PST | Fri Dec 31 16:00:00 1999 PST + 1027 | Fri Dec 31 16:00:00 1999 PST | Fri Dec 31 16:00:00 1999 PST | Sat Jan 01 04:00:00 2000 PST | Fri Dec 31 16:00:00 1999 PST 1028 | Fri Dec 31 16:00:00 1999 PST | Fri Dec 31 16:00:00 1999 PST | Fri Jan 21 16:00:00 2000 PST | Fri Dec 31 16:00:00 1999 PST 1029 | Fri Dec 31 16:00:00 1999 PST | Fri Dec 31 16:00:00 1999 PST | Mon Jul 31 16:00:00 2000 PDT | Fri Dec 31 16:00:00 1999 PST 1030 | Fri Dec 31 16:00:00 1999 PST | Fri Dec 31 16:00:00 1999 PST | Mon Jul 31 16:00:00 2000 PDT | Fri Dec 31 16:00:00 1999 PST diff --git a/tsl/test/expected/bgw_policy.out b/tsl/test/expected/bgw_policy.out index cd84d710a16..48536a5289f 100644 --- a/tsl/test/expected/bgw_policy.out +++ b/tsl/test/expected/bgw_policy.out @@ -714,11 +714,11 @@ select create_hypertable('test_missing_schedint_integer', 'time', chunk_time_int alter table test_missing_schedint_integer set (timescaledb.compress); select add_compression_policy('test_missing_schedint_integer', BIGINT '600000') as compression_id_integer \gset select * from _timescaledb_config.bgw_job where id in (:retenion_id_missing_schedint, :compression_id_missing_schedint, :compression_id_integer); - id | application_name | schedule_interval | max_runtime | max_retries | retry_period | proc_schema | proc_name | owner | scheduled | fixed_schedule | initial_start | hypertable_id | config | check_schema | check_name | timezone -------+---------------------------+--------------------+-------------+-------------+--------------+------------------------+--------------------+---------------------+-----------+----------------+---------------+---------------+-----------------------------------------------------+------------------------+--------------------------+---------- - 1008 | Retention Policy [1008] | @ 1 day | @ 5 mins | -1 | @ 5 mins | _timescaledb_functions | policy_retention | default_perm_user_2 | t | f | | 8 | {"drop_after": "@ 14 days", "hypertable_id": 8} | _timescaledb_functions | policy_retention_check | - 1009 | Compression Policy [1009] | @ 15 days 12 hours | @ 0 | -1 | @ 1 hour | _timescaledb_functions | policy_compression | default_perm_user_2 | t | f | | 8 | {"hypertable_id": 8, "compress_after": "@ 60 days"} | _timescaledb_functions | policy_compression_check | - 1010 | Compression Policy [1010] | @ 1 day | @ 0 | -1 | @ 1 hour | _timescaledb_functions | policy_compression | default_perm_user_2 | t | f | | 10 | {"hypertable_id": 10, "compress_after": 600000} | _timescaledb_functions | policy_compression_check | + id | application_name | schedule_interval | max_runtime | max_retries | retry_period | proc_schema | proc_name | owner | scheduled | fixed_schedule | initial_start | hypertable_id | config | check_schema | check_name | timezone +------+---------------------------+-------------------+-------------+-------------+--------------+------------------------+--------------------+---------------------+-----------+----------------+---------------+---------------+-----------------------------------------------------+------------------------+--------------------------+---------- + 1008 | Retention Policy [1008] | @ 1 day | @ 5 mins | -1 | @ 5 mins | _timescaledb_functions | policy_retention | default_perm_user_2 | t | f | | 8 | {"drop_after": "@ 14 days", "hypertable_id": 8} | _timescaledb_functions | policy_retention_check | + 1009 | Compression Policy [1009] | @ 12 hours | @ 0 | -1 | @ 1 hour | _timescaledb_functions | policy_compression | default_perm_user_2 | t | f | | 8 | {"hypertable_id": 8, "compress_after": "@ 60 days"} | _timescaledb_functions | policy_compression_check | + 1010 | Compression Policy [1010] | @ 1 day | @ 0 | -1 | @ 1 hour | _timescaledb_functions | policy_compression | default_perm_user_2 | t | f | | 10 | {"hypertable_id": 10, "compress_after": 600000} | _timescaledb_functions | policy_compression_check | (3 rows) -- test policy check functions with NULL args diff --git a/tsl/test/expected/cagg_migrate.out b/tsl/test/expected/cagg_migrate.out index 5ad01fafcb6..25219dbf1c3 100644 --- a/tsl/test/expected/cagg_migrate.out +++ b/tsl/test/expected/cagg_migrate.out @@ -959,7 +959,7 @@ AND hypertable_name = :'MAT_TABLE_NAME' AND job_id >= 1000; job_id | application_name | schedule_interval | max_runtime | max_retries | retry_period | proc_schema | proc_name | owner | scheduled | fixed_schedule | config | next_start | initial_start | hypertable_schema | hypertable_name | check_schema | check_name --------+--------------------------------------------+-------------------+-------------+-------------+--------------+------------------------+-------------------------------------+--------------------+-----------+----------------+---------------------------------------------------------------------------------+------------+---------------+-----------------------+-----------------------------+------------------------+------------------------------------------- - 1014 | Compression Policy [1014] | @ 35 days | @ 0 | -1 | @ 1 hour | _timescaledb_functions | policy_compression | cluster_super_user | t | f | {"hypertable_id": 16, "compress_after": "@ 45 days"} | | | _timescaledb_internal | _materialized_hypertable_16 | _timescaledb_functions | policy_compression_check + 1014 | Compression Policy [1014] | @ 12 hours | @ 0 | -1 | @ 1 hour | _timescaledb_functions | policy_compression | cluster_super_user | t | f | {"hypertable_id": 16, "compress_after": "@ 45 days"} | | | _timescaledb_internal | _materialized_hypertable_16 | _timescaledb_functions | policy_compression_check 1013 | Refresh Continuous Aggregate Policy [1013] | @ 1 hour | @ 0 | -1 | @ 1 hour | _timescaledb_functions | policy_refresh_continuous_aggregate | cluster_super_user | t | f | {"end_offset": "@ 1 day", "start_offset": "@ 30 days", "mat_hypertable_id": 16} | | | _timescaledb_internal | _materialized_hypertable_16 | _timescaledb_functions | policy_refresh_continuous_aggregate_check 1012 | Retention Policy [1012] | @ 1 day | @ 5 mins | -1 | @ 5 mins | _timescaledb_functions | policy_retention | cluster_super_user | t | f | {"drop_after": "@ 30 days", "hypertable_id": 16} | | | _timescaledb_internal | _materialized_hypertable_16 | _timescaledb_functions | policy_retention_check (3 rows) @@ -1020,7 +1020,7 @@ AND hypertable_name = :'NEW_MAT_TABLE_NAME' AND job_id >= 1000; job_id | application_name | schedule_interval | max_runtime | max_retries | retry_period | proc_schema | proc_name | owner | scheduled | fixed_schedule | config | next_start | initial_start | hypertable_schema | hypertable_name | check_schema | check_name --------+--------------------------------------------+-------------------+-------------+-------------+--------------+------------------------+-------------------------------------+--------------------+-----------+----------------+---------------------------------------------------------------------------------+------------+---------------+-----------------------+-----------------------------+------------------------+------------------------------------------- - 1017 | Compression Policy [1017] | @ 35 days | @ 0 | -1 | @ 1 hour | _timescaledb_functions | policy_compression | cluster_super_user | t | f | {"hypertable_id": 19, "compress_after": "@ 45 days"} | | | _timescaledb_internal | _materialized_hypertable_19 | _timescaledb_functions | policy_compression_check + 1017 | Compression Policy [1017] | @ 12 hours | @ 0 | -1 | @ 1 hour | _timescaledb_functions | policy_compression | cluster_super_user | t | f | {"hypertable_id": 19, "compress_after": "@ 45 days"} | | | _timescaledb_internal | _materialized_hypertable_19 | _timescaledb_functions | policy_compression_check 1016 | Refresh Continuous Aggregate Policy [1016] | @ 1 hour | @ 0 | -1 | @ 1 hour | _timescaledb_functions | policy_refresh_continuous_aggregate | cluster_super_user | t | f | {"end_offset": "@ 1 day", "start_offset": "@ 30 days", "mat_hypertable_id": 19} | | | _timescaledb_internal | _materialized_hypertable_19 | _timescaledb_functions | policy_refresh_continuous_aggregate_check 1015 | Retention Policy [1015] | @ 1 day | @ 5 mins | -1 | @ 5 mins | _timescaledb_functions | policy_retention | cluster_super_user | t | f | {"drop_after": "@ 30 days", "hypertable_id": 19} | | | _timescaledb_internal | _materialized_hypertable_19 | _timescaledb_functions | policy_retention_check (3 rows) @@ -1099,7 +1099,7 @@ SELECT * FROM cagg_jobs WHERE schema = 'public' AND name = 'conditions_summary_d --------+--------------------------+------+--------------------------------------------+-------------------+-------------+-------------+--------------+------------------------+-------------------------------------+--------------------+-----------+----------------+---------------+---------------+---------------------------------------------------------------------------------+------------------------+-------------------------------------------+---------- public | conditions_summary_daily | 1012 | Retention Policy [1012] | @ 1 day | @ 5 mins | -1 | @ 5 mins | _timescaledb_functions | policy_retention | cluster_super_user | t | f | | 16 | {"drop_after": "@ 30 days", "hypertable_id": 16} | _timescaledb_functions | policy_retention_check | public | conditions_summary_daily | 1013 | Refresh Continuous Aggregate Policy [1013] | @ 1 hour | @ 0 | -1 | @ 1 hour | _timescaledb_functions | policy_refresh_continuous_aggregate | cluster_super_user | t | f | | 16 | {"end_offset": "@ 1 day", "start_offset": "@ 30 days", "mat_hypertable_id": 16} | _timescaledb_functions | policy_refresh_continuous_aggregate_check | - public | conditions_summary_daily | 1014 | Compression Policy [1014] | @ 35 days | @ 0 | -1 | @ 1 hour | _timescaledb_functions | policy_compression | cluster_super_user | t | f | | 16 | {"hypertable_id": 16, "compress_after": "@ 45 days"} | _timescaledb_functions | policy_compression_check | + public | conditions_summary_daily | 1014 | Compression Policy [1014] | @ 12 hours | @ 0 | -1 | @ 1 hour | _timescaledb_functions | policy_compression | cluster_super_user | t | f | | 16 | {"hypertable_id": 16, "compress_after": "@ 45 days"} | _timescaledb_functions | policy_compression_check | (3 rows) CALL cagg_migrate('conditions_summary_daily', override => TRUE); @@ -1173,7 +1173,7 @@ SELECT * FROM cagg_jobs WHERE schema = 'public' AND name = 'conditions_summary_d --------+--------------------------+------+--------------------------------------------+-------------------+-------------+-------------+--------------+------------------------+-------------------------------------+--------------------+-----------+----------------+---------------+---------------+---------------------------------------------------------------------------------+------------------------+-------------------------------------------+---------- public | conditions_summary_daily | 1018 | Retention Policy [1018] | @ 1 day | @ 5 mins | -1 | @ 5 mins | _timescaledb_functions | policy_retention | cluster_super_user | t | f | | 21 | {"drop_after": "@ 30 days", "hypertable_id": 21} | _timescaledb_functions | policy_retention_check | public | conditions_summary_daily | 1019 | Refresh Continuous Aggregate Policy [1019] | @ 1 hour | @ 0 | -1 | @ 1 hour | _timescaledb_functions | policy_refresh_continuous_aggregate | cluster_super_user | t | f | | 21 | {"end_offset": "@ 1 day", "start_offset": "@ 30 days", "mat_hypertable_id": 21} | _timescaledb_functions | policy_refresh_continuous_aggregate_check | - public | conditions_summary_daily | 1020 | Compression Policy [1020] | @ 35 days | @ 0 | -1 | @ 1 hour | _timescaledb_functions | policy_compression | cluster_super_user | t | f | | 21 | {"hypertable_id": 21, "compress_after": "@ 45 days"} | _timescaledb_functions | policy_compression_check | + public | conditions_summary_daily | 1020 | Compression Policy [1020] | @ 12 hours | @ 0 | -1 | @ 1 hour | _timescaledb_functions | policy_compression | cluster_super_user | t | f | | 21 | {"hypertable_id": 21, "compress_after": "@ 45 days"} | _timescaledb_functions | policy_compression_check | (3 rows) -- should return the old cagg jobs @@ -1182,7 +1182,7 @@ SELECT * FROM cagg_jobs WHERE schema = 'public' AND name = 'conditions_summary_d --------+------------------------------+------+--------------------------------------------+-------------------+-------------+-------------+--------------+------------------------+-------------------------------------+--------------------+-----------+----------------+---------------+---------------+---------------------------------------------------------------------------------+------------------------+-------------------------------------------+---------- public | conditions_summary_daily_old | 1012 | Retention Policy [1012] | @ 1 day | @ 5 mins | -1 | @ 5 mins | _timescaledb_functions | policy_retention | cluster_super_user | t | f | | 16 | {"drop_after": "@ 30 days", "hypertable_id": 16} | _timescaledb_functions | policy_retention_check | public | conditions_summary_daily_old | 1013 | Refresh Continuous Aggregate Policy [1013] | @ 1 hour | @ 0 | -1 | @ 1 hour | _timescaledb_functions | policy_refresh_continuous_aggregate | cluster_super_user | t | f | | 16 | {"end_offset": "@ 1 day", "start_offset": "@ 30 days", "mat_hypertable_id": 16} | _timescaledb_functions | policy_refresh_continuous_aggregate_check | - public | conditions_summary_daily_old | 1014 | Compression Policy [1014] | @ 35 days | @ 0 | -1 | @ 1 hour | _timescaledb_functions | policy_compression | cluster_super_user | t | f | | 16 | {"hypertable_id": 16, "compress_after": "@ 45 days"} | _timescaledb_functions | policy_compression_check | + public | conditions_summary_daily_old | 1014 | Compression Policy [1014] | @ 12 hours | @ 0 | -1 | @ 1 hour | _timescaledb_functions | policy_compression | cluster_super_user | t | f | | 16 | {"hypertable_id": 16, "compress_after": "@ 45 days"} | _timescaledb_functions | policy_compression_check | (3 rows) -- should return no rows because the cagg was overwritten @@ -1203,7 +1203,7 @@ SELECT * FROM cagg_jobs WHERE schema = 'public' AND name = 'conditions_summary_d --------+--------------------------+------+--------------------------------------------+-------------------+-------------+-------------+--------------+------------------------+-------------------------------------+--------------------+-----------+----------------+---------------+---------------+---------------------------------------------------------------------------------+------------------------+-------------------------------------------+---------- public | conditions_summary_daily | 1012 | Retention Policy [1012] | @ 1 day | @ 5 mins | -1 | @ 5 mins | _timescaledb_functions | policy_retention | cluster_super_user | t | f | | 16 | {"drop_after": "@ 30 days", "hypertable_id": 16} | _timescaledb_functions | policy_retention_check | public | conditions_summary_daily | 1013 | Refresh Continuous Aggregate Policy [1013] | @ 1 hour | @ 0 | -1 | @ 1 hour | _timescaledb_functions | policy_refresh_continuous_aggregate | cluster_super_user | t | f | | 16 | {"end_offset": "@ 1 day", "start_offset": "@ 30 days", "mat_hypertable_id": 16} | _timescaledb_functions | policy_refresh_continuous_aggregate_check | - public | conditions_summary_daily | 1014 | Compression Policy [1014] | @ 35 days | @ 0 | -1 | @ 1 hour | _timescaledb_functions | policy_compression | cluster_super_user | t | f | | 16 | {"hypertable_id": 16, "compress_after": "@ 45 days"} | _timescaledb_functions | policy_compression_check | + public | conditions_summary_daily | 1014 | Compression Policy [1014] | @ 12 hours | @ 0 | -1 | @ 1 hour | _timescaledb_functions | policy_compression | cluster_super_user | t | f | | 16 | {"hypertable_id": 16, "compress_after": "@ 45 days"} | _timescaledb_functions | policy_compression_check | (3 rows) CALL cagg_migrate('conditions_summary_daily', override => TRUE, drop_old => TRUE); @@ -1255,7 +1255,7 @@ SELECT * FROM cagg_jobs WHERE schema = 'public' AND name = 'conditions_summary_d --------+--------------------------+------+--------------------------------------------+-------------------+-------------+-------------+--------------+------------------------+-------------------------------------+--------------------+-----------+----------------+---------------+---------------+---------------------------------------------------------------------------------+------------------------+-------------------------------------------+---------- public | conditions_summary_daily | 1021 | Retention Policy [1021] | @ 1 day | @ 5 mins | -1 | @ 5 mins | _timescaledb_functions | policy_retention | cluster_super_user | t | f | | 23 | {"drop_after": "@ 30 days", "hypertable_id": 23} | _timescaledb_functions | policy_retention_check | public | conditions_summary_daily | 1022 | Refresh Continuous Aggregate Policy [1022] | @ 1 hour | @ 0 | -1 | @ 1 hour | _timescaledb_functions | policy_refresh_continuous_aggregate | cluster_super_user | t | f | | 23 | {"end_offset": "@ 1 day", "start_offset": "@ 30 days", "mat_hypertable_id": 23} | _timescaledb_functions | policy_refresh_continuous_aggregate_check | - public | conditions_summary_daily | 1023 | Compression Policy [1023] | @ 35 days | @ 0 | -1 | @ 1 hour | _timescaledb_functions | policy_compression | cluster_super_user | t | f | | 23 | {"hypertable_id": 23, "compress_after": "@ 45 days"} | _timescaledb_functions | policy_compression_check | + public | conditions_summary_daily | 1023 | Compression Policy [1023] | @ 12 hours | @ 0 | -1 | @ 1 hour | _timescaledb_functions | policy_compression | cluster_super_user | t | f | | 23 | {"hypertable_id": 23, "compress_after": "@ 45 days"} | _timescaledb_functions | policy_compression_check | (3 rows) -- should return no rows because the old cagg was removed @@ -1638,7 +1638,7 @@ AND hypertable_name = :'MAT_TABLE_NAME' AND job_id >= 1000; job_id | application_name | schedule_interval | max_runtime | max_retries | retry_period | proc_schema | proc_name | owner | scheduled | fixed_schedule | config | next_start | initial_start | hypertable_schema | hypertable_name | check_schema | check_name --------+--------------------------------------------+-------------------+-------------+-------------+--------------+------------------------+-------------------------------------+--------------------+-----------+----------------+---------------------------------------------------------------------------------+------------+---------------+-----------------------+-----------------------------+------------------------+------------------------------------------- - 1026 | Compression Policy [1026] | @ 35 days | @ 0 | -1 | @ 1 hour | _timescaledb_functions | policy_compression | cluster_super_user | t | f | {"hypertable_id": 29, "compress_after": "@ 45 days"} | | | _timescaledb_internal | _materialized_hypertable_29 | _timescaledb_functions | policy_compression_check + 1026 | Compression Policy [1026] | @ 12 hours | @ 0 | -1 | @ 1 hour | _timescaledb_functions | policy_compression | cluster_super_user | t | f | {"hypertable_id": 29, "compress_after": "@ 45 days"} | | | _timescaledb_internal | _materialized_hypertable_29 | _timescaledb_functions | policy_compression_check 1025 | Refresh Continuous Aggregate Policy [1025] | @ 1 hour | @ 0 | -1 | @ 1 hour | _timescaledb_functions | policy_refresh_continuous_aggregate | cluster_super_user | t | f | {"end_offset": "@ 1 day", "start_offset": "@ 30 days", "mat_hypertable_id": 29} | | | _timescaledb_internal | _materialized_hypertable_29 | _timescaledb_functions | policy_refresh_continuous_aggregate_check 1024 | Retention Policy [1024] | @ 1 day | @ 5 mins | -1 | @ 5 mins | _timescaledb_functions | policy_retention | cluster_super_user | t | f | {"drop_after": "@ 30 days", "hypertable_id": 29} | | | _timescaledb_internal | _materialized_hypertable_29 | _timescaledb_functions | policy_retention_check (3 rows) @@ -1699,7 +1699,7 @@ AND hypertable_name = :'NEW_MAT_TABLE_NAME' AND job_id >= 1000; job_id | application_name | schedule_interval | max_runtime | max_retries | retry_period | proc_schema | proc_name | owner | scheduled | fixed_schedule | config | next_start | initial_start | hypertable_schema | hypertable_name | check_schema | check_name --------+--------------------------------------------+-------------------+-------------+-------------+--------------+------------------------+-------------------------------------+--------------------+-----------+----------------+---------------------------------------------------------------------------------+------------+---------------+-----------------------+-----------------------------+------------------------+------------------------------------------- - 1029 | Compression Policy [1029] | @ 35 days | @ 0 | -1 | @ 1 hour | _timescaledb_functions | policy_compression | cluster_super_user | t | f | {"hypertable_id": 32, "compress_after": "@ 45 days"} | | | _timescaledb_internal | _materialized_hypertable_32 | _timescaledb_functions | policy_compression_check + 1029 | Compression Policy [1029] | @ 12 hours | @ 0 | -1 | @ 1 hour | _timescaledb_functions | policy_compression | cluster_super_user | t | f | {"hypertable_id": 32, "compress_after": "@ 45 days"} | | | _timescaledb_internal | _materialized_hypertable_32 | _timescaledb_functions | policy_compression_check 1028 | Refresh Continuous Aggregate Policy [1028] | @ 1 hour | @ 0 | -1 | @ 1 hour | _timescaledb_functions | policy_refresh_continuous_aggregate | cluster_super_user | t | f | {"end_offset": "@ 1 day", "start_offset": "@ 30 days", "mat_hypertable_id": 32} | | | _timescaledb_internal | _materialized_hypertable_32 | _timescaledb_functions | policy_refresh_continuous_aggregate_check 1027 | Retention Policy [1027] | @ 1 day | @ 5 mins | -1 | @ 5 mins | _timescaledb_functions | policy_retention | cluster_super_user | t | f | {"drop_after": "@ 30 days", "hypertable_id": 32} | | | _timescaledb_internal | _materialized_hypertable_32 | _timescaledb_functions | policy_retention_check (3 rows) @@ -1778,7 +1778,7 @@ SELECT * FROM cagg_jobs WHERE schema = 'public' AND name = 'conditions_summary_d --------+--------------------------+------+--------------------------------------------+-------------------+-------------+-------------+--------------+------------------------+-------------------------------------+--------------------+-----------+----------------+---------------+---------------+---------------------------------------------------------------------------------+------------------------+-------------------------------------------+---------- public | conditions_summary_daily | 1024 | Retention Policy [1024] | @ 1 day | @ 5 mins | -1 | @ 5 mins | _timescaledb_functions | policy_retention | cluster_super_user | t | f | | 29 | {"drop_after": "@ 30 days", "hypertable_id": 29} | _timescaledb_functions | policy_retention_check | public | conditions_summary_daily | 1025 | Refresh Continuous Aggregate Policy [1025] | @ 1 hour | @ 0 | -1 | @ 1 hour | _timescaledb_functions | policy_refresh_continuous_aggregate | cluster_super_user | t | f | | 29 | {"end_offset": "@ 1 day", "start_offset": "@ 30 days", "mat_hypertable_id": 29} | _timescaledb_functions | policy_refresh_continuous_aggregate_check | - public | conditions_summary_daily | 1026 | Compression Policy [1026] | @ 35 days | @ 0 | -1 | @ 1 hour | _timescaledb_functions | policy_compression | cluster_super_user | t | f | | 29 | {"hypertable_id": 29, "compress_after": "@ 45 days"} | _timescaledb_functions | policy_compression_check | + public | conditions_summary_daily | 1026 | Compression Policy [1026] | @ 12 hours | @ 0 | -1 | @ 1 hour | _timescaledb_functions | policy_compression | cluster_super_user | t | f | | 29 | {"hypertable_id": 29, "compress_after": "@ 45 days"} | _timescaledb_functions | policy_compression_check | (3 rows) CALL cagg_migrate('conditions_summary_daily', override => TRUE); @@ -1852,7 +1852,7 @@ SELECT * FROM cagg_jobs WHERE schema = 'public' AND name = 'conditions_summary_d --------+--------------------------+------+--------------------------------------------+-------------------+-------------+-------------+--------------+------------------------+-------------------------------------+--------------------+-----------+----------------+---------------+---------------+---------------------------------------------------------------------------------+------------------------+-------------------------------------------+---------- public | conditions_summary_daily | 1030 | Retention Policy [1030] | @ 1 day | @ 5 mins | -1 | @ 5 mins | _timescaledb_functions | policy_retention | cluster_super_user | t | f | | 34 | {"drop_after": "@ 30 days", "hypertable_id": 34} | _timescaledb_functions | policy_retention_check | public | conditions_summary_daily | 1031 | Refresh Continuous Aggregate Policy [1031] | @ 1 hour | @ 0 | -1 | @ 1 hour | _timescaledb_functions | policy_refresh_continuous_aggregate | cluster_super_user | t | f | | 34 | {"end_offset": "@ 1 day", "start_offset": "@ 30 days", "mat_hypertable_id": 34} | _timescaledb_functions | policy_refresh_continuous_aggregate_check | - public | conditions_summary_daily | 1032 | Compression Policy [1032] | @ 35 days | @ 0 | -1 | @ 1 hour | _timescaledb_functions | policy_compression | cluster_super_user | t | f | | 34 | {"hypertable_id": 34, "compress_after": "@ 45 days"} | _timescaledb_functions | policy_compression_check | + public | conditions_summary_daily | 1032 | Compression Policy [1032] | @ 12 hours | @ 0 | -1 | @ 1 hour | _timescaledb_functions | policy_compression | cluster_super_user | t | f | | 34 | {"hypertable_id": 34, "compress_after": "@ 45 days"} | _timescaledb_functions | policy_compression_check | (3 rows) -- should return the old cagg jobs @@ -1861,7 +1861,7 @@ SELECT * FROM cagg_jobs WHERE schema = 'public' AND name = 'conditions_summary_d --------+------------------------------+------+--------------------------------------------+-------------------+-------------+-------------+--------------+------------------------+-------------------------------------+--------------------+-----------+----------------+---------------+---------------+---------------------------------------------------------------------------------+------------------------+-------------------------------------------+---------- public | conditions_summary_daily_old | 1024 | Retention Policy [1024] | @ 1 day | @ 5 mins | -1 | @ 5 mins | _timescaledb_functions | policy_retention | cluster_super_user | t | f | | 29 | {"drop_after": "@ 30 days", "hypertable_id": 29} | _timescaledb_functions | policy_retention_check | public | conditions_summary_daily_old | 1025 | Refresh Continuous Aggregate Policy [1025] | @ 1 hour | @ 0 | -1 | @ 1 hour | _timescaledb_functions | policy_refresh_continuous_aggregate | cluster_super_user | t | f | | 29 | {"end_offset": "@ 1 day", "start_offset": "@ 30 days", "mat_hypertable_id": 29} | _timescaledb_functions | policy_refresh_continuous_aggregate_check | - public | conditions_summary_daily_old | 1026 | Compression Policy [1026] | @ 35 days | @ 0 | -1 | @ 1 hour | _timescaledb_functions | policy_compression | cluster_super_user | t | f | | 29 | {"hypertable_id": 29, "compress_after": "@ 45 days"} | _timescaledb_functions | policy_compression_check | + public | conditions_summary_daily_old | 1026 | Compression Policy [1026] | @ 12 hours | @ 0 | -1 | @ 1 hour | _timescaledb_functions | policy_compression | cluster_super_user | t | f | | 29 | {"hypertable_id": 29, "compress_after": "@ 45 days"} | _timescaledb_functions | policy_compression_check | (3 rows) -- should return no rows because the cagg was overwritten @@ -1882,7 +1882,7 @@ SELECT * FROM cagg_jobs WHERE schema = 'public' AND name = 'conditions_summary_d --------+--------------------------+------+--------------------------------------------+-------------------+-------------+-------------+--------------+------------------------+-------------------------------------+--------------------+-----------+----------------+---------------+---------------+---------------------------------------------------------------------------------+------------------------+-------------------------------------------+---------- public | conditions_summary_daily | 1024 | Retention Policy [1024] | @ 1 day | @ 5 mins | -1 | @ 5 mins | _timescaledb_functions | policy_retention | cluster_super_user | t | f | | 29 | {"drop_after": "@ 30 days", "hypertable_id": 29} | _timescaledb_functions | policy_retention_check | public | conditions_summary_daily | 1025 | Refresh Continuous Aggregate Policy [1025] | @ 1 hour | @ 0 | -1 | @ 1 hour | _timescaledb_functions | policy_refresh_continuous_aggregate | cluster_super_user | t | f | | 29 | {"end_offset": "@ 1 day", "start_offset": "@ 30 days", "mat_hypertable_id": 29} | _timescaledb_functions | policy_refresh_continuous_aggregate_check | - public | conditions_summary_daily | 1026 | Compression Policy [1026] | @ 35 days | @ 0 | -1 | @ 1 hour | _timescaledb_functions | policy_compression | cluster_super_user | t | f | | 29 | {"hypertable_id": 29, "compress_after": "@ 45 days"} | _timescaledb_functions | policy_compression_check | + public | conditions_summary_daily | 1026 | Compression Policy [1026] | @ 12 hours | @ 0 | -1 | @ 1 hour | _timescaledb_functions | policy_compression | cluster_super_user | t | f | | 29 | {"hypertable_id": 29, "compress_after": "@ 45 days"} | _timescaledb_functions | policy_compression_check | (3 rows) CALL cagg_migrate('conditions_summary_daily', override => TRUE, drop_old => TRUE); @@ -1934,7 +1934,7 @@ SELECT * FROM cagg_jobs WHERE schema = 'public' AND name = 'conditions_summary_d --------+--------------------------+------+--------------------------------------------+-------------------+-------------+-------------+--------------+------------------------+-------------------------------------+--------------------+-----------+----------------+---------------+---------------+---------------------------------------------------------------------------------+------------------------+-------------------------------------------+---------- public | conditions_summary_daily | 1033 | Retention Policy [1033] | @ 1 day | @ 5 mins | -1 | @ 5 mins | _timescaledb_functions | policy_retention | cluster_super_user | t | f | | 36 | {"drop_after": "@ 30 days", "hypertable_id": 36} | _timescaledb_functions | policy_retention_check | public | conditions_summary_daily | 1034 | Refresh Continuous Aggregate Policy [1034] | @ 1 hour | @ 0 | -1 | @ 1 hour | _timescaledb_functions | policy_refresh_continuous_aggregate | cluster_super_user | t | f | | 36 | {"end_offset": "@ 1 day", "start_offset": "@ 30 days", "mat_hypertable_id": 36} | _timescaledb_functions | policy_refresh_continuous_aggregate_check | - public | conditions_summary_daily | 1035 | Compression Policy [1035] | @ 35 days | @ 0 | -1 | @ 1 hour | _timescaledb_functions | policy_compression | cluster_super_user | t | f | | 36 | {"hypertable_id": 36, "compress_after": "@ 45 days"} | _timescaledb_functions | policy_compression_check | + public | conditions_summary_daily | 1035 | Compression Policy [1035] | @ 12 hours | @ 0 | -1 | @ 1 hour | _timescaledb_functions | policy_compression | cluster_super_user | t | f | | 36 | {"hypertable_id": 36, "compress_after": "@ 45 days"} | _timescaledb_functions | policy_compression_check | (3 rows) -- should return no rows because the old cagg was removed diff --git a/tsl/test/expected/cagg_policy.out b/tsl/test/expected/cagg_policy.out index 4f1df2807d5..c509b5b9881 100644 --- a/tsl/test/expected/cagg_policy.out +++ b/tsl/test/expected/cagg_policy.out @@ -439,7 +439,7 @@ SELECT timescaledb_experimental.add_policies('max_mat_view_date', refresh_start_ SELECT timescaledb_experimental.show_policies('max_mat_view_date'); show_policies -------------------------------------------------------------------------------------------------------------------------------------------------------------- - {"policy_name": "policy_compression", "compress_after": "@ 20 days", "compress_interval": "@ 35 days"} + {"policy_name": "policy_compression", "compress_after": "@ 20 days", "compress_interval": "@ 12 hours"} {"policy_name": "policy_refresh_continuous_aggregate", "refresh_interval": "@ 1 hour", "refresh_end_offset": "@ 1 day", "refresh_start_offset": "@ 15 days"} {"drop_after": "@ 25 days", "policy_name": "policy_retention", "retention_interval": "@ 1 day"} (3 rows) @@ -454,7 +454,7 @@ SELECT timescaledb_experimental.alter_policies('max_mat_view_date', refresh_star SELECT timescaledb_experimental.show_policies('max_mat_view_date'); show_policies -------------------------------------------------------------------------------------------------------------------------------------------------------------- - {"policy_name": "policy_compression", "compress_after": "@ 26 days", "compress_interval": "@ 35 days"} + {"policy_name": "policy_compression", "compress_after": "@ 26 days", "compress_interval": "@ 12 hours"} {"policy_name": "policy_refresh_continuous_aggregate", "refresh_interval": "@ 1 hour", "refresh_end_offset": "@ 1 day", "refresh_start_offset": "@ 16 days"} {"drop_after": "@ 40 days", "policy_name": "policy_retention", "retention_interval": "@ 1 day"} (3 rows) @@ -503,7 +503,7 @@ ERROR: refresh and compression policies overlap SELECT timescaledb_experimental.show_policies('max_mat_view_date'); show_policies -------------------------------------------------------------------------------------------------------------------------------------------------------- - {"policy_name": "policy_compression", "compress_after": "@ 20 days", "compress_interval": "@ 35 days"} + {"policy_name": "policy_compression", "compress_after": "@ 20 days", "compress_interval": "@ 12 hours"} {"policy_name": "policy_refresh_continuous_aggregate", "refresh_interval": "@ 1 hour", "refresh_end_offset": null, "refresh_start_offset": "@ 5 days"} {"drop_after": "@ 25 days", "policy_name": "policy_retention", "retention_interval": "@ 1 day"} (3 rows) @@ -514,7 +514,7 @@ ERROR: refresh and retention policies overlap SELECT timescaledb_experimental.show_policies('max_mat_view_date'); show_policies -------------------------------------------------------------------------------------------------------------------------------------------------------- - {"policy_name": "policy_compression", "compress_after": "@ 20 days", "compress_interval": "@ 35 days"} + {"policy_name": "policy_compression", "compress_after": "@ 20 days", "compress_interval": "@ 12 hours"} {"policy_name": "policy_refresh_continuous_aggregate", "refresh_interval": "@ 1 hour", "refresh_end_offset": null, "refresh_start_offset": "@ 5 days"} {"drop_after": "@ 25 days", "policy_name": "policy_retention", "retention_interval": "@ 1 day"} (3 rows) diff --git a/tsl/test/expected/compression_bgw.out b/tsl/test/expected/compression_bgw.out index b1da1884ac1..09febc592b6 100644 --- a/tsl/test/expected/compression_bgw.out +++ b/tsl/test/expected/compression_bgw.out @@ -34,9 +34,9 @@ select generate_series('2018-12-01 00:00'::timestamp, '2018-12-31 00:00'::timest select add_compression_policy('conditions', '60d'::interval) AS compressjob_id \gset select * from _timescaledb_config.bgw_job where id = :compressjob_id; - id | application_name | schedule_interval | max_runtime | max_retries | retry_period | proc_schema | proc_name | owner | scheduled | fixed_schedule | initial_start | hypertable_id | config | check_schema | check_name | timezone -------+---------------------------+--------------------+-------------+-------------+--------------+------------------------+--------------------+-------------------+-----------+----------------+---------------+---------------+-----------------------------------------------------+------------------------+--------------------------+---------- - 1000 | Compression Policy [1000] | @ 15 days 12 hours | @ 0 | -1 | @ 1 hour | _timescaledb_functions | policy_compression | default_perm_user | t | f | | 1 | {"hypertable_id": 1, "compress_after": "@ 60 days"} | _timescaledb_functions | policy_compression_check | + id | application_name | schedule_interval | max_runtime | max_retries | retry_period | proc_schema | proc_name | owner | scheduled | fixed_schedule | initial_start | hypertable_id | config | check_schema | check_name | timezone +------+---------------------------+-------------------+-------------+-------------+--------------+------------------------+--------------------+-------------------+-----------+----------------+---------------+---------------+-----------------------------------------------------+------------------------+--------------------------+---------- + 1000 | Compression Policy [1000] | @ 12 hours | @ 0 | -1 | @ 1 hour | _timescaledb_functions | policy_compression | default_perm_user | t | f | | 1 | {"hypertable_id": 1, "compress_after": "@ 60 days"} | _timescaledb_functions | policy_compression_check | (1 row) select * from alter_job(:compressjob_id, schedule_interval=>'1s'); diff --git a/tsl/test/expected/compression_policy.out b/tsl/test/expected/compression_policy.out new file mode 100644 index 00000000000..c444c96e146 --- /dev/null +++ b/tsl/test/expected/compression_policy.out @@ -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) + diff --git a/tsl/test/sql/CMakeLists.txt b/tsl/test/sql/CMakeLists.txt index dddf593c48e..b6e8f6aa354 100644 --- a/tsl/test/sql/CMakeLists.txt +++ b/tsl/test/sql/CMakeLists.txt @@ -18,6 +18,7 @@ set(TEST_FILES compression_bgw.sql compression_conflicts.sql compression_insert.sql + compression_policy.sql compression_qualpushdown.sql exp_cagg_monthly.sql exp_cagg_next_gen.sql diff --git a/tsl/test/sql/compression_policy.sql b/tsl/test/sql/compression_policy.sql new file mode 100644 index 00000000000..0723fb32f2d --- /dev/null +++ b/tsl/test/sql/compression_policy.sql @@ -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;