From 2d0ed64017a2cf18d33a19b733186a37006a4499 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabr=C3=ADzio=20de=20Royes=20Mello?= Date: Mon, 6 May 2024 11:52:12 -0300 Subject: [PATCH] Release 2.15.0 This release contains performance improvements and bug fixes since the 2.14.2 release. We recommend that you upgrade at the next available opportunity. In addition, it includes these noteworthy features: * Support `time_bucket` with `origin` and/or `offset` on Continuous Aggregate * Compression improvements: - Improve expression pushdown - Add minmax sparse indexes when compressing columns with btree indexes - Make compression use the defaults functions - Vectorize filters in WHERE clause that contain text equality operators and LIKE expressions **Deprecation warning** * Starting on this release will not be possible to create Continuous Aggregate using `time_bucket_ng` anymore and it will be completely removed on the upcoming releases. * Recommend users to [migrate their old Continuous Aggregate format to the new one](https://docs.timescale.com/use-timescale/latest/continuous-aggregates/migrate/) because it support will be completely removed in next releases prevent them to migrate. * This is the last release supporting PostgreSQL 13. **For on-premise users and this release only**, you will need to run [this SQL script](https://github.com/timescale/timescaledb-extras/blob/master/utils/2.15.X-fix_hypertable_foreign_keys.sql) after running `ALTER EXTENSION`. More details can be found in the pull request [#6786](https://github.com/timescale/timescaledb/pull/6797). **Features** * #6382 Support for time_bucket with origin and offset in CAggs * #6696 Improve defaults for compression segment_by and order_by * #6705 Add sparse minmax indexes for compressed columns that have uncompressed btree indexes * #6754 Allow DROP CONSTRAINT on compressed hypertables * #6767 Add metadata table `_timestaledb_internal.bgw_job_stat_history` for tracking job execution history * #6798 Prevent usage of deprecated time_bucket_ng in CAgg definition * #6810 Add telemetry for access methods * #6811 Remove no longer relevant timescaledb.allow_install_without_preload GUC * #6837 Add migration path for CAggs using time_bucket_ng * #6865 Update the watermark when truncating a CAgg **Bugfixes** * #6617 Fix error in show_chunks * #6621 Remove metadata when dropping chunks * #6677 Fix snapshot usage in CAgg invalidation scanner * #6698 Define meaning of 0 retries for jobs as no retries * #6717 Fix handling of compressed tables with primary or unique index in COPY path * #6726 Fix constify cagg_watermark using window function when querying a CAgg * #6729 Fix NULL start value handling in CAgg refresh * #6732 Fix CAgg migration with custom timezone / date format settings * #6752 Remove custom autovacuum setting from compressed chunks * #6770 Fix plantime chunk exclusion for OSM chunk * #6789 Fix deletes with subqueries and compression * #6796 Fix a crash involving a view on a hypertable * #6797 Fix foreign key constraint handling on compressed hypertables * #6816 Fix handling of chunks with no contraints * #6820 Fix a crash when the ts_hypertable_insert_blocker was called directly * #6849 Use non-orderby compressed metadata in compressed DML * #6867 Clean up compression settings when deleting compressed cagg * #6869 Fix compressed DML with constraints of form value OP column * #6870 Fix bool expression pushdown for queries on compressed chunks **Thanks** * @brasic for reporting a crash when the ts_hypertable_insert_blocker was called directly * @bvanelli for reporting an issue with the jobs retry count * @djzurawsk For reporting error when dropping chunks * @Dzuzepppe for reporting an issue with DELETEs using subquery on compressed chunk working incorrectly. * @hongquan For reporting a 'timestamp out of range' error during CAgg migrations * @kevcenteno for reporting an issue with the show_chunks API showing incorrect output when 'created_before/created_after' was used with time-partitioned columns. * @mahipv For starting working on the job history PR * @rovo89 For reporting constify cagg_watermark not working using window function when querying a CAgg --- .unreleased/RELEASE_NOTES_HEADER.md.j2 | 24 +- .unreleased/auto_sparse_indexes | 1 - .unreleased/bugfix_6677 | 1 - .unreleased/bugfix_6717 | 1 - .unreleased/bugfix_6729 | 1 - .unreleased/bugfix_6732 | 2 - .unreleased/bugfix_6752 | 1 - .unreleased/bugfix_6789 | 2 - .unreleased/bugfix_6796 | 1 - .unreleased/feature_6382 | 1 - .unreleased/feature_6837 | 1 - .unreleased/feature_6865 | 1 - .unreleased/fix_6617 | 2 - .unreleased/fix_6816 | 1 - .unreleased/fix_6820 | 2 - .unreleased/pr_6621 | 2 - .unreleased/pr_6696 | 1 - .unreleased/pr_6698 | 2 - .unreleased/pr_6726 | 2 - .unreleased/pr_6754 | 1 - .unreleased/pr_6767 | 2 - .unreleased/pr_6770 | 1 - .unreleased/pr_6797 | 1 - .unreleased/pr_6798 | 1 - .unreleased/pr_6810 | 1 - .unreleased/pr_6811 | 1 - .unreleased/pr_6849 | 1 - .unreleased/pr_6867 | 1 - .unreleased/pr_6869 | 1 - .unreleased/pr_6870 | 1 - .unreleased/template.release_notes_header.j2 | 2 +- CHANGELOG.md | 64 +++ sql/CMakeLists.txt | 8 +- sql/updates/2.14.2--2.15.0.sql | 440 +++++++++++++++++++ sql/updates/2.15.0--2.14.2.sql | 290 ++++++++++++ sql/updates/latest-dev.sql | 440 ------------------- sql/updates/reverse-dev.sql | 290 ------------ version.config | 2 +- 38 files changed, 811 insertions(+), 786 deletions(-) delete mode 100644 .unreleased/auto_sparse_indexes delete mode 100644 .unreleased/bugfix_6677 delete mode 100644 .unreleased/bugfix_6717 delete mode 100644 .unreleased/bugfix_6729 delete mode 100644 .unreleased/bugfix_6732 delete mode 100644 .unreleased/bugfix_6752 delete mode 100644 .unreleased/bugfix_6789 delete mode 100644 .unreleased/bugfix_6796 delete mode 100644 .unreleased/feature_6382 delete mode 100644 .unreleased/feature_6837 delete mode 100644 .unreleased/feature_6865 delete mode 100644 .unreleased/fix_6617 delete mode 100644 .unreleased/fix_6816 delete mode 100644 .unreleased/fix_6820 delete mode 100644 .unreleased/pr_6621 delete mode 100644 .unreleased/pr_6696 delete mode 100644 .unreleased/pr_6698 delete mode 100644 .unreleased/pr_6726 delete mode 100644 .unreleased/pr_6754 delete mode 100644 .unreleased/pr_6767 delete mode 100644 .unreleased/pr_6770 delete mode 100644 .unreleased/pr_6797 delete mode 100644 .unreleased/pr_6798 delete mode 100644 .unreleased/pr_6810 delete mode 100644 .unreleased/pr_6811 delete mode 100644 .unreleased/pr_6849 delete mode 100644 .unreleased/pr_6867 delete mode 100644 .unreleased/pr_6869 delete mode 100644 .unreleased/pr_6870 create mode 100644 sql/updates/2.14.2--2.15.0.sql create mode 100644 sql/updates/2.15.0--2.14.2.sql diff --git a/.unreleased/RELEASE_NOTES_HEADER.md.j2 b/.unreleased/RELEASE_NOTES_HEADER.md.j2 index de92e7da72b..f5d099f5626 100644 --- a/.unreleased/RELEASE_NOTES_HEADER.md.j2 +++ b/.unreleased/RELEASE_NOTES_HEADER.md.j2 @@ -1,20 +1,16 @@ +{# + # Variables: + # release_current = the release version that has being builded + # release_previous = previous release version + # release_date = date of the release in format YYYY-MM-DD + #} ## {{ release_current }} ({{ release_date }}) -This release contains performance improvements and bug fixes since +This release contains performance improvements and bug fixes since the {{ release_previous }} release. We recommend that you upgrade at the next available opportunity. In addition, it includes these noteworthy features: -* Support `time_bucket` with `origin` and/or `offset` on Continuous Aggregate -* Compression improvements: - - Improve expression pushdown - - Add minmax sparse indexes when compressing columns with btree indexes - - Make compression use the defaults functions - - Vectorize filters in WHERE clause that contain text equality operators and LIKE expressions - -**Deprecation warning** -* Starting on this release will not be possible to create Continuous Aggregate using `time_bucket_ng` anymore and it will be completely removed on the upcoming releases. -* Recommend users to [migrate their old Continuous Aggregate format to the new one](https://docs.timescale.com/use-timescale/latest/continuous-aggregates/migrate/) because it support will be completely removed in next releases prevent them to migrate. -* This is the last release supporting PostgreSQL 13. - -**For on-premise users and this release only**, you will need to run [this SQL script](https://github.com/timescale/timescaledb-extras/blob/master/utils/2.15.X-fix_hypertable_foreign_keys.sql) after running `ALTER EXTENSION`. More details can be found in the pull request [#6786](https://github.com/timescale/timescaledb/pull/6797). +* feature 1 +* feature 2 +* feature N diff --git a/.unreleased/auto_sparse_indexes b/.unreleased/auto_sparse_indexes deleted file mode 100644 index 99b09327245..00000000000 --- a/.unreleased/auto_sparse_indexes +++ /dev/null @@ -1 +0,0 @@ -Implements: #6705 Add sparse minmax indexes for compressed columns that have uncompressed btree indexes diff --git a/.unreleased/bugfix_6677 b/.unreleased/bugfix_6677 deleted file mode 100644 index 40691dcb919..00000000000 --- a/.unreleased/bugfix_6677 +++ /dev/null @@ -1 +0,0 @@ -Fixes: #6677 Fix snapshot usage in CAgg invalidation scanner diff --git a/.unreleased/bugfix_6717 b/.unreleased/bugfix_6717 deleted file mode 100644 index f73dd7ce82b..00000000000 --- a/.unreleased/bugfix_6717 +++ /dev/null @@ -1 +0,0 @@ -Fixes: #6717 Fix handling of compressed tables with primary or unique index in COPY path diff --git a/.unreleased/bugfix_6729 b/.unreleased/bugfix_6729 deleted file mode 100644 index e1ded6ebfea..00000000000 --- a/.unreleased/bugfix_6729 +++ /dev/null @@ -1 +0,0 @@ -Fixes: #6729 Fix NULL start value handling in CAgg refresh diff --git a/.unreleased/bugfix_6732 b/.unreleased/bugfix_6732 deleted file mode 100644 index ca0c78cc910..00000000000 --- a/.unreleased/bugfix_6732 +++ /dev/null @@ -1,2 +0,0 @@ -Fixes: #6732 Fix CAgg migration with custom timezone / date format settings -Thanks: @hongquan For reporting a 'timestamp out of range' error during CAgg migrations diff --git a/.unreleased/bugfix_6752 b/.unreleased/bugfix_6752 deleted file mode 100644 index a17b3cc0629..00000000000 --- a/.unreleased/bugfix_6752 +++ /dev/null @@ -1 +0,0 @@ -Fixes: #6752 Remove custom autovacuum setting from compressed chunks diff --git a/.unreleased/bugfix_6789 b/.unreleased/bugfix_6789 deleted file mode 100644 index b4afe6dfef9..00000000000 --- a/.unreleased/bugfix_6789 +++ /dev/null @@ -1,2 +0,0 @@ -Fixes: #6789 Fix deletes with subqueries and compression -Thanks: @Dzuzepppe for reporting an issue with DELETEs using subquery on compressed chunk working incorrectly. diff --git a/.unreleased/bugfix_6796 b/.unreleased/bugfix_6796 deleted file mode 100644 index d9e4b2b7831..00000000000 --- a/.unreleased/bugfix_6796 +++ /dev/null @@ -1 +0,0 @@ -Fixes: #6796 Fix a crash involving a view on a hypertable diff --git a/.unreleased/feature_6382 b/.unreleased/feature_6382 deleted file mode 100644 index 4b1e499f10b..00000000000 --- a/.unreleased/feature_6382 +++ /dev/null @@ -1 +0,0 @@ -Implements: #6382 Support for time_bucket with origin and offset in CAggs diff --git a/.unreleased/feature_6837 b/.unreleased/feature_6837 deleted file mode 100644 index acb9aa3e0d2..00000000000 --- a/.unreleased/feature_6837 +++ /dev/null @@ -1 +0,0 @@ -Implements: #6837 Add migration path for CAggs using time_bucket_ng diff --git a/.unreleased/feature_6865 b/.unreleased/feature_6865 deleted file mode 100644 index 8584a15f928..00000000000 --- a/.unreleased/feature_6865 +++ /dev/null @@ -1 +0,0 @@ -Implements: #6865 Update the watermark when truncating a CAgg diff --git a/.unreleased/fix_6617 b/.unreleased/fix_6617 deleted file mode 100644 index e50f239eaff..00000000000 --- a/.unreleased/fix_6617 +++ /dev/null @@ -1,2 +0,0 @@ -Fixes: #6617 Fix error in show_chunks -Thanks: @kevcenteno for reporting an issue with the show_chunks API showing incorrect output when 'created_before/created_after' was used with time-partitioned columns. diff --git a/.unreleased/fix_6816 b/.unreleased/fix_6816 deleted file mode 100644 index 62f27cfae06..00000000000 --- a/.unreleased/fix_6816 +++ /dev/null @@ -1 +0,0 @@ -Fixes: #6816 Fix handling of chunks with no contraints diff --git a/.unreleased/fix_6820 b/.unreleased/fix_6820 deleted file mode 100644 index 47ed02ad198..00000000000 --- a/.unreleased/fix_6820 +++ /dev/null @@ -1,2 +0,0 @@ -Fixes: #6820 Fix a crash when the ts_hypertable_insert_blocker was called directly -Thanks: @brasic for reporting a crash when the ts_hypertable_insert_blocker was called directly diff --git a/.unreleased/pr_6621 b/.unreleased/pr_6621 deleted file mode 100644 index bc20f80487a..00000000000 --- a/.unreleased/pr_6621 +++ /dev/null @@ -1,2 +0,0 @@ -Fixes: #6621 Remove metadata when dropping chunks -Thanks: @djzurawsk For reporting error when dropping chunks diff --git a/.unreleased/pr_6696 b/.unreleased/pr_6696 deleted file mode 100644 index c52ca5f2d35..00000000000 --- a/.unreleased/pr_6696 +++ /dev/null @@ -1 +0,0 @@ -Implements: #6696 Improve defaults for compression segment_by and order_by diff --git a/.unreleased/pr_6698 b/.unreleased/pr_6698 deleted file mode 100644 index 7ab28df25a6..00000000000 --- a/.unreleased/pr_6698 +++ /dev/null @@ -1,2 +0,0 @@ -Fixes: #6698 Define meaning of 0 retries for jobs as no retries -Thanks: @bvanelli for reporting an issue with the jobs retry count diff --git a/.unreleased/pr_6726 b/.unreleased/pr_6726 deleted file mode 100644 index 0ef9596ccc5..00000000000 --- a/.unreleased/pr_6726 +++ /dev/null @@ -1,2 +0,0 @@ -Fixes: #6726 Fix constify cagg_watermark using window function when querying a CAgg -Thanks: @rovo89 For reporting constify cagg_watermark not working using window function when querying a CAgg diff --git a/.unreleased/pr_6754 b/.unreleased/pr_6754 deleted file mode 100644 index b1d7d156988..00000000000 --- a/.unreleased/pr_6754 +++ /dev/null @@ -1 +0,0 @@ -Implements: #6754 Allow DROP CONSTRAINT on compressed hypertables diff --git a/.unreleased/pr_6767 b/.unreleased/pr_6767 deleted file mode 100644 index 9f7adbffc78..00000000000 --- a/.unreleased/pr_6767 +++ /dev/null @@ -1,2 +0,0 @@ -Implements: #6767 Add metadata table `_timestaledb_internal.bgw_job_stat_history` for tracking job execution history -Thanks: @mahipv For starting working on the job history PR diff --git a/.unreleased/pr_6770 b/.unreleased/pr_6770 deleted file mode 100644 index e77daff2d71..00000000000 --- a/.unreleased/pr_6770 +++ /dev/null @@ -1 +0,0 @@ -Fixes: #6770 Fix plantime chunk exclusion for OSM chunk diff --git a/.unreleased/pr_6797 b/.unreleased/pr_6797 deleted file mode 100644 index 849d80b16af..00000000000 --- a/.unreleased/pr_6797 +++ /dev/null @@ -1 +0,0 @@ -Fixes: #6797 Fix foreign key constraint handling on compressed hypertables diff --git a/.unreleased/pr_6798 b/.unreleased/pr_6798 deleted file mode 100644 index 1324d70a648..00000000000 --- a/.unreleased/pr_6798 +++ /dev/null @@ -1 +0,0 @@ -Implements: #6798 Prevent usage of deprecated time_bucket_ng in CAgg definition diff --git a/.unreleased/pr_6810 b/.unreleased/pr_6810 deleted file mode 100644 index 821d29c97fa..00000000000 --- a/.unreleased/pr_6810 +++ /dev/null @@ -1 +0,0 @@ -Implements: #6810 Add telemetry for access methods diff --git a/.unreleased/pr_6811 b/.unreleased/pr_6811 deleted file mode 100644 index bfd242b7365..00000000000 --- a/.unreleased/pr_6811 +++ /dev/null @@ -1 +0,0 @@ -Implements: #6811 Remove no longer relevant timescaledb.allow_install_without_preload GUC diff --git a/.unreleased/pr_6849 b/.unreleased/pr_6849 deleted file mode 100644 index 78ad70209d9..00000000000 --- a/.unreleased/pr_6849 +++ /dev/null @@ -1 +0,0 @@ -Fixes: #6849 Use non-orderby compressed metadata in compressed DML diff --git a/.unreleased/pr_6867 b/.unreleased/pr_6867 deleted file mode 100644 index 03690e0920d..00000000000 --- a/.unreleased/pr_6867 +++ /dev/null @@ -1 +0,0 @@ -Fixes: #6867 Clean up compression settings when deleting compressed cagg diff --git a/.unreleased/pr_6869 b/.unreleased/pr_6869 deleted file mode 100644 index 20a0af6c1ef..00000000000 --- a/.unreleased/pr_6869 +++ /dev/null @@ -1 +0,0 @@ -Fixes: #6869 Fix compressed DML with constraints of form value OP column diff --git a/.unreleased/pr_6870 b/.unreleased/pr_6870 deleted file mode 100644 index 21395dd862e..00000000000 --- a/.unreleased/pr_6870 +++ /dev/null @@ -1 +0,0 @@ -Fixes: #6870 Fix bool expression pushdown for queries on compressed chunks diff --git a/.unreleased/template.release_notes_header.j2 b/.unreleased/template.release_notes_header.j2 index 6576647d6ae..f5d099f5626 100644 --- a/.unreleased/template.release_notes_header.j2 +++ b/.unreleased/template.release_notes_header.j2 @@ -6,7 +6,7 @@ #} ## {{ release_current }} ({{ release_date }}) -This release contains performance improvements and bug fixes since +This release contains performance improvements and bug fixes since the {{ release_previous }} release. We recommend that you upgrade at the next available opportunity. diff --git a/CHANGELOG.md b/CHANGELOG.md index 225af5b6ddb..66792787420 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,70 @@ `psql` with the `-X` flag to prevent any `.psqlrc` commands from accidentally triggering the load of a previous DB version.** +## 2.15.0 (2024-05-08) + +This release contains performance improvements and bug fixes since +the 2.14.2 release. We recommend that you upgrade at the next +available opportunity. + +In addition, it includes these noteworthy features: +* Support `time_bucket` with `origin` and/or `offset` on Continuous Aggregate +* Compression improvements: + - Improve expression pushdown + - Add minmax sparse indexes when compressing columns with btree indexes + - Improve compression setting defaults + - Vectorize filters in WHERE clause that contain text equality operators and LIKE expressions + +**Deprecation warning** +* Starting on this release will not be possible to create Continuous Aggregate using `time_bucket_ng` anymore and it will be completely removed on the upcoming releases. +* Recommend users to [migrate their old Continuous Aggregate format to the new one](https://docs.timescale.com/use-timescale/latest/continuous-aggregates/migrate/) because it support will be completely removed in next releases prevent them to migrate. +* This is the last release supporting PostgreSQL 13. + +**For on-premise users and this release only**, you will need to run [this SQL script](https://github.com/timescale/timescaledb-extras/blob/master/utils/2.15.X-fix_hypertable_foreign_keys.sql) after running `ALTER EXTENSION`. More details can be found in the pull request [#6786](https://github.com/timescale/timescaledb/pull/6797). + +**Features** +* #6382 Support for time_bucket with origin and offset in CAggs +* #6696 Improve defaults for compression segment_by and order_by +* #6705 Add sparse minmax indexes for compressed columns that have uncompressed btree indexes +* #6754 Allow DROP CONSTRAINT on compressed hypertables +* #6767 Add metadata table `_timestaledb_internal.bgw_job_stat_history` for tracking job execution history +* #6798 Prevent usage of deprecated time_bucket_ng in CAgg definition +* #6810 Add telemetry for access methods +* #6811 Remove no longer relevant timescaledb.allow_install_without_preload GUC +* #6837 Add migration path for CAggs using time_bucket_ng +* #6865 Update the watermark when truncating a CAgg + +**Bugfixes** +* #6617 Fix error in show_chunks +* #6621 Remove metadata when dropping chunks +* #6677 Fix snapshot usage in CAgg invalidation scanner +* #6698 Define meaning of 0 retries for jobs as no retries +* #6717 Fix handling of compressed tables with primary or unique index in COPY path +* #6726 Fix constify cagg_watermark using window function when querying a CAgg +* #6729 Fix NULL start value handling in CAgg refresh +* #6732 Fix CAgg migration with custom timezone / date format settings +* #6752 Remove custom autovacuum setting from compressed chunks +* #6770 Fix plantime chunk exclusion for OSM chunk +* #6789 Fix deletes with subqueries and compression +* #6796 Fix a crash involving a view on a hypertable +* #6797 Fix foreign key constraint handling on compressed hypertables +* #6816 Fix handling of chunks with no contraints +* #6820 Fix a crash when the ts_hypertable_insert_blocker was called directly +* #6849 Use non-orderby compressed metadata in compressed DML +* #6867 Clean up compression settings when deleting compressed cagg +* #6869 Fix compressed DML with constraints of form value OP column +* #6870 Fix bool expression pushdown for queries on compressed chunks + +**Thanks** +* @brasic for reporting a crash when the ts_hypertable_insert_blocker was called directly +* @bvanelli for reporting an issue with the jobs retry count +* @djzurawsk For reporting error when dropping chunks +* @Dzuzepppe for reporting an issue with DELETEs using subquery on compressed chunk working incorrectly. +* @hongquan For reporting a 'timestamp out of range' error during CAgg migrations +* @kevcenteno for reporting an issue with the show_chunks API showing incorrect output when 'created_before/created_after' was used with time-partitioned columns. +* @mahipv For starting working on the job history PR +* @rovo89 For reporting constify cagg_watermark not working using window function when querying a CAgg + ## 2.14.2 (2024-02-20) This release contains bug fixes since the 2.14.1 release. diff --git a/sql/CMakeLists.txt b/sql/CMakeLists.txt index fe64458e905..d7423d706d1 100644 --- a/sql/CMakeLists.txt +++ b/sql/CMakeLists.txt @@ -45,11 +45,12 @@ set(MOD_FILES updates/2.13.0--2.13.1.sql updates/2.13.1--2.14.0.sql updates/2.14.0--2.14.1.sql - updates/2.14.1--2.14.2.sql) + updates/2.14.1--2.14.2.sql + updates/2.14.2--2.15.0.sql) # The downgrade file to generate a downgrade script for the current version, as # specified in version.config -set(CURRENT_REV_FILE reverse-dev.sql) +set(CURRENT_REV_FILE 2.15.0--2.14.2.sql) # Files for generating old downgrade scripts. This should only include files for # downgrade from one version to its previous version since we do not support # skipping versions when downgrading. @@ -86,7 +87,8 @@ set(OLD_REV_FILES 2.13.1--2.13.0.sql 2.14.0--2.13.1.sql 2.14.1--2.14.0.sql - 2.14.2--2.14.1.sql) + 2.14.2--2.14.1.sql + 2.15.0--2.14.2.sql) set(MODULE_PATHNAME "$libdir/timescaledb-${PROJECT_VERSION_MOD}") set(LOADER_PATHNAME "$libdir/timescaledb") diff --git a/sql/updates/2.14.2--2.15.0.sql b/sql/updates/2.14.2--2.15.0.sql new file mode 100644 index 00000000000..209a466b410 --- /dev/null +++ b/sql/updates/2.14.2--2.15.0.sql @@ -0,0 +1,440 @@ +-- Remove multi-node CAGG support +DROP FUNCTION IF EXISTS _timescaledb_internal.invalidation_cagg_log_add_entry(integer,bigint,bigint); +DROP FUNCTION IF EXISTS _timescaledb_internal.invalidation_hyper_log_add_entry(integer,bigint,bigint); +DROP FUNCTION IF EXISTS _timescaledb_internal.materialization_invalidation_log_delete(integer); +DROP FUNCTION IF EXISTS _timescaledb_internal.invalidation_process_cagg_log(integer,integer,regtype,bigint,bigint,integer[],bigint[],bigint[]); +DROP FUNCTION IF EXISTS _timescaledb_internal.invalidation_process_cagg_log(integer,integer,regtype,bigint,bigint,integer[],bigint[],bigint[],text[]); +DROP FUNCTION IF EXISTS _timescaledb_internal.invalidation_process_hypertable_log(integer,integer,regtype,integer[],bigint[],bigint[]); +DROP FUNCTION IF EXISTS _timescaledb_internal.invalidation_process_hypertable_log(integer,integer,regtype,integer[],bigint[],bigint[],text[]); +DROP FUNCTION IF EXISTS _timescaledb_internal.hypertable_invalidation_log_delete(integer); + +DROP FUNCTION IF EXISTS _timescaledb_functions.invalidation_cagg_log_add_entry(integer,bigint,bigint); +DROP FUNCTION IF EXISTS _timescaledb_functions.invalidation_hyper_log_add_entry(integer,bigint,bigint); +DROP FUNCTION IF EXISTS _timescaledb_functions.materialization_invalidation_log_delete(integer); +DROP FUNCTION IF EXISTS _timescaledb_functions.invalidation_process_cagg_log(integer,integer,regtype,bigint,bigint,integer[],bigint[],bigint[]); +DROP FUNCTION IF EXISTS _timescaledb_functions.invalidation_process_cagg_log(integer,integer,regtype,bigint,bigint,integer[],bigint[],bigint[],text[]); +DROP FUNCTION IF EXISTS _timescaledb_functions.invalidation_process_hypertable_log(integer,integer,regtype,integer[],bigint[],bigint[]); +DROP FUNCTION IF EXISTS _timescaledb_functions.invalidation_process_hypertable_log(integer,integer,regtype,integer[],bigint[],bigint[],text[]); +DROP FUNCTION IF EXISTS _timescaledb_functions.hypertable_invalidation_log_delete(integer); + +-- Remove chunk metadata when marked as dropped +CREATE FUNCTION _timescaledb_functions.remove_dropped_chunk_metadata(_hypertable_id INTEGER) +RETURNS INTEGER LANGUAGE plpgsql AS $$ +DECLARE + _chunk_id INTEGER; + _removed INTEGER := 0; +BEGIN + FOR _chunk_id IN + SELECT id FROM _timescaledb_catalog.chunk + WHERE hypertable_id = _hypertable_id + AND dropped IS TRUE + AND NOT EXISTS ( + SELECT FROM information_schema.tables + WHERE tables.table_schema = chunk.schema_name + AND tables.table_name = chunk.table_name + ) + AND NOT EXISTS ( + SELECT FROM _timescaledb_catalog.hypertable + JOIN _timescaledb_catalog.continuous_agg ON continuous_agg.raw_hypertable_id = hypertable.id + WHERE hypertable.id = chunk.hypertable_id + -- for the old caggs format we need to keep chunk metadata for dropped chunks + AND continuous_agg.finalized IS FALSE + ) + LOOP + _removed := _removed + 1; + RAISE INFO 'Removing metadata of chunk % from hypertable %', _chunk_id, _hypertable_id; + WITH _dimension_slice_remove AS ( + DELETE FROM _timescaledb_catalog.dimension_slice + USING _timescaledb_catalog.chunk_constraint + WHERE dimension_slice.id = chunk_constraint.dimension_slice_id + AND chunk_constraint.chunk_id = _chunk_id + RETURNING _timescaledb_catalog.dimension_slice.id + ) + DELETE FROM _timescaledb_catalog.chunk_constraint + USING _dimension_slice_remove + WHERE chunk_constraint.dimension_slice_id = _dimension_slice_remove.id; + + DELETE FROM _timescaledb_internal.bgw_policy_chunk_stats + WHERE bgw_policy_chunk_stats.chunk_id = _chunk_id; + + DELETE FROM _timescaledb_catalog.chunk_index + WHERE chunk_index.chunk_id = _chunk_id; + + DELETE FROM _timescaledb_catalog.compression_chunk_size + WHERE compression_chunk_size.chunk_id = _chunk_id + OR compression_chunk_size.compressed_chunk_id = _chunk_id; + + DELETE FROM _timescaledb_catalog.chunk + WHERE chunk.id = _chunk_id + OR chunk.compressed_chunk_id = _chunk_id; + END LOOP; + + RETURN _removed; +END; +$$ SET search_path TO pg_catalog, pg_temp; + +SELECT _timescaledb_functions.remove_dropped_chunk_metadata(id) AS chunks_metadata_removed +FROM _timescaledb_catalog.hypertable; + +-- +-- Rebuild the catalog table `_timescaledb_catalog.continuous_aggs_bucket_function` +-- + +CREATE OR REPLACE FUNCTION _timescaledb_functions.cagg_get_bucket_function( + mat_hypertable_id INTEGER +) RETURNS regprocedure AS '@MODULE_PATHNAME@', 'ts_continuous_agg_get_bucket_function' LANGUAGE C STRICT VOLATILE; + +-- Since we need now the regclass of the used bucket function, we have to recover it +-- by parsing the view query by calling 'cagg_get_bucket_function'. +CREATE TABLE _timescaledb_catalog._tmp_continuous_aggs_bucket_function AS + SELECT + mat_hypertable_id, + _timescaledb_functions.cagg_get_bucket_function(mat_hypertable_id), + bucket_width, + origin, + NULL::text AS bucket_offset, + timezone, + false AS bucket_fixed_width + FROM + _timescaledb_catalog.continuous_aggs_bucket_function + ORDER BY + mat_hypertable_id; + +ALTER EXTENSION timescaledb + DROP TABLE _timescaledb_catalog.continuous_aggs_bucket_function; + +DROP TABLE _timescaledb_catalog.continuous_aggs_bucket_function; + +CREATE TABLE _timescaledb_catalog.continuous_aggs_bucket_function ( + mat_hypertable_id integer NOT NULL, + -- The bucket function + bucket_func regprocedure NOT NULL, + -- `bucket_width` argument of the function, e.g. "1 month" + bucket_width text NOT NULL, + -- optional `origin` argument of the function provided by the user + bucket_origin text, + -- optional `offset` argument of the function provided by the user + bucket_offset text, + -- optional `timezone` argument of the function provided by the user + bucket_timezone text, + -- fixed or variable sized bucket + bucket_fixed_width bool NOT NULL, + -- table constraints + CONSTRAINT continuous_aggs_bucket_function_pkey PRIMARY KEY (mat_hypertable_id), + CONSTRAINT continuous_aggs_bucket_function_mat_hypertable_id_fkey FOREIGN KEY (mat_hypertable_id) REFERENCES _timescaledb_catalog.hypertable (id) ON DELETE CASCADE +); + +INSERT INTO _timescaledb_catalog.continuous_aggs_bucket_function + SELECT * FROM _timescaledb_catalog._tmp_continuous_aggs_bucket_function; + +DROP TABLE _timescaledb_catalog._tmp_continuous_aggs_bucket_function; + +SELECT pg_catalog.pg_extension_config_dump('_timescaledb_catalog.continuous_aggs_bucket_function', ''); + +GRANT SELECT ON TABLE _timescaledb_catalog.continuous_aggs_bucket_function TO PUBLIC; + +ANALYZE _timescaledb_catalog.continuous_aggs_bucket_function; + +ALTER EXTENSION timescaledb DROP FUNCTION _timescaledb_functions.cagg_get_bucket_function(INTEGER); +DROP FUNCTION IF EXISTS _timescaledb_functions.cagg_get_bucket_function(INTEGER); + +-- +-- End rebuild the catalog table `_timescaledb_catalog.continuous_aggs_bucket_function` +-- + +-- Convert _timescaledb_catalog.continuous_aggs_bucket_function.bucket_origin to TimestampTZ +UPDATE _timescaledb_catalog.continuous_aggs_bucket_function + SET bucket_origin = bucket_origin::timestamp::timestamptz::text + WHERE length(bucket_origin) > 1; + +-- Historically, we have used empty strings for undefined bucket_origin and timezone +-- attributes. This is now replaced by proper NULL values. We use TRIM() to ensure we handle empty string well. +UPDATE _timescaledb_catalog.continuous_aggs_bucket_function SET bucket_origin = NULL WHERE TRIM(bucket_origin) = ''; +UPDATE _timescaledb_catalog.continuous_aggs_bucket_function SET bucket_timezone = NULL WHERE TRIM(bucket_timezone) = ''; + +-- So far, there were no difference between 0 and -1 retries. Since now on, 0 means no retries. Updating the retry +-- count of existing jobs to -1 to keep the current semantics. +UPDATE _timescaledb_config.bgw_job SET max_retries = -1 WHERE max_retries = 0; + +DROP FUNCTION IF EXISTS _timescaledb_functions.get_chunk_relstats; +DROP FUNCTION IF EXISTS _timescaledb_functions.get_chunk_colstats; +DROP FUNCTION IF EXISTS _timescaledb_internal.get_chunk_relstats; +DROP FUNCTION IF EXISTS _timescaledb_internal.get_chunk_colstats; + +-- In older TSDB versions, we disabled autovacuum for compressed chunks +-- to keep the statistics. However, this restriction was removed in +-- #5118 but no migration was performed to remove the custom +-- autovacuum setting for existing chunks. +DO $$ +DECLARE + chunk regclass; +BEGIN + FOR chunk IN + SELECT pg_catalog.format('%I.%I', schema_name, table_name)::regclass + FROM _timescaledb_catalog.chunk c + JOIN pg_catalog.pg_class AS pc ON (pc.oid=format('%I.%I', schema_name, table_name)::regclass) + CROSS JOIN unnest(reloptions) AS u(option) + WHERE + dropped = false + AND osm_chunk = false + AND option LIKE 'autovacuum_enabled%' + LOOP + EXECUTE pg_catalog.format('ALTER TABLE %s RESET (autovacuum_enabled);', chunk::text); + END LOOP; +END +$$; + +-- +-- Rebuild the catalog table `_timescaledb_catalog.continuous_agg` +-- + +-- (1) Create missing entries in _timescaledb_catalog.continuous_aggs_bucket_function +CREATE OR REPLACE FUNCTION _timescaledb_functions.cagg_get_bucket_function( + mat_hypertable_id INTEGER +) RETURNS regprocedure AS '@MODULE_PATHNAME@', 'ts_continuous_agg_get_bucket_function' LANGUAGE C STRICT VOLATILE; + +-- Make sure function points to the new version of TSDB +CREATE OR REPLACE FUNCTION _timescaledb_functions.to_interval(unixtime_us BIGINT) RETURNS INTERVAL + AS '@MODULE_PATHNAME@', 'ts_pg_unix_microseconds_to_interval' LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE; + +-- We need to create entries in continuous_aggs_bucket_function for all CAggs that were treated so far +-- as fixed indicated by a bucket_width != -1 +INSERT INTO _timescaledb_catalog.continuous_aggs_bucket_function + SELECT + mat_hypertable_id, + _timescaledb_functions.cagg_get_bucket_function(mat_hypertable_id), + -- Intervals needs to be converted into the proper interval format + -- Function name could be prefixed with 'public.'. Therefore LIKE instead of starts_with is used + CASE WHEN _timescaledb_functions.cagg_get_bucket_function(mat_hypertable_id)::text LIKE '%time_bucket(interval,%' THEN + _timescaledb_functions.to_interval(bucket_width)::text + ELSE + bucket_width::text + END, + NULL, -- bucket_origin + NULL, -- bucket_offset + NULL, -- bucket_timezone + true -- bucket_fixed_width + FROM _timescaledb_catalog.continuous_agg WHERE bucket_width != -1; + +ALTER EXTENSION timescaledb DROP FUNCTION _timescaledb_functions.cagg_get_bucket_function(INTEGER); +DROP FUNCTION IF EXISTS _timescaledb_functions.cagg_get_bucket_function(INTEGER); + +-- (2) Rebuild catalog table +DROP VIEW IF EXISTS timescaledb_experimental.policies; +DROP VIEW IF EXISTS timescaledb_information.hypertables; +DROP VIEW IF EXISTS timescaledb_information.continuous_aggregates; + +DROP PROCEDURE IF EXISTS @extschema@.cagg_migrate (REGCLASS, BOOLEAN, BOOLEAN); +DROP FUNCTION IF EXISTS _timescaledb_internal.cagg_migrate_pre_validation (TEXT, TEXT, TEXT); +DROP FUNCTION IF EXISTS _timescaledb_functions.cagg_migrate_pre_validation (TEXT, TEXT, TEXT); +DROP PROCEDURE IF EXISTS _timescaledb_internal.cagg_migrate_create_plan (_timescaledb_catalog.continuous_agg, TEXT, BOOLEAN, BOOLEAN); +DROP PROCEDURE IF EXISTS _timescaledb_functions.cagg_migrate_create_plan (_timescaledb_catalog.continuous_agg, TEXT, BOOLEAN, BOOLEAN); + +DROP FUNCTION IF EXISTS _timescaledb_functions.cagg_migrate_plan_exists (INTEGER); +DROP PROCEDURE IF EXISTS _timescaledb_internal.cagg_migrate_execute_plan (_timescaledb_catalog.continuous_agg); +DROP PROCEDURE IF EXISTS _timescaledb_functions.cagg_migrate_execute_plan (_timescaledb_catalog.continuous_agg); +DROP PROCEDURE IF EXISTS _timescaledb_internal.cagg_migrate_execute_create_new_cagg (_timescaledb_catalog.continuous_agg, _timescaledb_catalog.continuous_agg_migrate_plan_step); +DROP PROCEDURE IF EXISTS _timescaledb_functions.cagg_migrate_execute_create_new_cagg (_timescaledb_catalog.continuous_agg, _timescaledb_catalog.continuous_agg_migrate_plan_step); +DROP PROCEDURE IF EXISTS _timescaledb_internal.cagg_migrate_execute_disable_policies (_timescaledb_catalog.continuous_agg, _timescaledb_catalog.continuous_agg_migrate_plan_step); +DROP PROCEDURE IF EXISTS _timescaledb_functions.cagg_migrate_execute_disable_policies (_timescaledb_catalog.continuous_agg, _timescaledb_catalog.continuous_agg_migrate_plan_step); +DROP PROCEDURE IF EXISTS _timescaledb_internal.cagg_migrate_execute_enable_policies (_timescaledb_catalog.continuous_agg, _timescaledb_catalog.continuous_agg_migrate_plan_step); +DROP PROCEDURE IF EXISTS _timescaledb_functions.cagg_migrate_execute_enable_policies (_timescaledb_catalog.continuous_agg, _timescaledb_catalog.continuous_agg_migrate_plan_step); +DROP PROCEDURE IF EXISTS _timescaledb_internal.cagg_migrate_execute_copy_policies (_timescaledb_catalog.continuous_agg, _timescaledb_catalog.continuous_agg_migrate_plan_step); +DROP PROCEDURE IF EXISTS _timescaledb_functions.cagg_migrate_execute_copy_policies (_timescaledb_catalog.continuous_agg, _timescaledb_catalog.continuous_agg_migrate_plan_step); +DROP PROCEDURE IF EXISTS _timescaledb_internal.cagg_migrate_execute_refresh_new_cagg (_timescaledb_catalog.continuous_agg, _timescaledb_catalog.continuous_agg_migrate_plan_step); +DROP PROCEDURE IF EXISTS _timescaledb_functions.cagg_migrate_execute_refresh_new_cagg (_timescaledb_catalog.continuous_agg, _timescaledb_catalog.continuous_agg_migrate_plan_step); +DROP PROCEDURE IF EXISTS _timescaledb_internal.cagg_migrate_execute_copy_data (_timescaledb_catalog.continuous_agg, _timescaledb_catalog.continuous_agg_migrate_plan_step); +DROP PROCEDURE IF EXISTS _timescaledb_functions.cagg_migrate_execute_copy_data (_timescaledb_catalog.continuous_agg, _timescaledb_catalog.continuous_agg_migrate_plan_step); +DROP PROCEDURE IF EXISTS _timescaledb_internal.cagg_migrate_execute_override_cagg (_timescaledb_catalog.continuous_agg, _timescaledb_catalog.continuous_agg_migrate_plan_step); +DROP PROCEDURE IF EXISTS _timescaledb_functions.cagg_migrate_execute_override_cagg (_timescaledb_catalog.continuous_agg, _timescaledb_catalog.continuous_agg_migrate_plan_step); +DROP PROCEDURE IF EXISTS _timescaledb_internal.cagg_migrate_execute_drop_old_cagg (_timescaledb_catalog.continuous_agg, _timescaledb_catalog.continuous_agg_migrate_plan_step); +DROP PROCEDURE IF EXISTS _timescaledb_functions.cagg_migrate_execute_drop_old_cagg (_timescaledb_catalog.continuous_agg, _timescaledb_catalog.continuous_agg_migrate_plan_step); + +ALTER TABLE _timescaledb_catalog.continuous_aggs_materialization_invalidation_log + DROP CONSTRAINT continuous_aggs_materialization_invalid_materialization_id_fkey; + +ALTER TABLE _timescaledb_catalog.continuous_aggs_watermark + DROP CONSTRAINT continuous_aggs_watermark_mat_hypertable_id_fkey; + +ALTER EXTENSION timescaledb + DROP TABLE _timescaledb_catalog.continuous_agg; + +CREATE TABLE _timescaledb_catalog._tmp_continuous_agg AS + SELECT + mat_hypertable_id, + raw_hypertable_id, + parent_mat_hypertable_id, + user_view_schema, + user_view_name, + partial_view_schema, + partial_view_name, + direct_view_schema, + direct_view_name, + materialized_only, + finalized + FROM + _timescaledb_catalog.continuous_agg + ORDER BY + mat_hypertable_id; + +DROP TABLE _timescaledb_catalog.continuous_agg; + +CREATE TABLE _timescaledb_catalog.continuous_agg ( + mat_hypertable_id integer NOT NULL, + raw_hypertable_id integer NOT NULL, + parent_mat_hypertable_id integer, + user_view_schema name NOT NULL, + user_view_name name NOT NULL, + partial_view_schema name NOT NULL, + partial_view_name name NOT NULL, + direct_view_schema name NOT NULL, + direct_view_name name NOT NULL, + materialized_only bool NOT NULL DEFAULT FALSE, + finalized bool NOT NULL DEFAULT TRUE, + -- table constraints + CONSTRAINT continuous_agg_pkey PRIMARY KEY (mat_hypertable_id), + CONSTRAINT continuous_agg_partial_view_schema_partial_view_name_key UNIQUE (partial_view_schema, partial_view_name), + CONSTRAINT continuous_agg_user_view_schema_user_view_name_key UNIQUE (user_view_schema, user_view_name), + CONSTRAINT continuous_agg_mat_hypertable_id_fkey + FOREIGN KEY (mat_hypertable_id) REFERENCES _timescaledb_catalog.hypertable (id) ON DELETE CASCADE, + CONSTRAINT continuous_agg_raw_hypertable_id_fkey + FOREIGN KEY (raw_hypertable_id) REFERENCES _timescaledb_catalog.hypertable (id) ON DELETE CASCADE, + CONSTRAINT continuous_agg_parent_mat_hypertable_id_fkey + FOREIGN KEY (parent_mat_hypertable_id) + REFERENCES _timescaledb_catalog.continuous_agg (mat_hypertable_id) ON DELETE CASCADE +); + +INSERT INTO _timescaledb_catalog.continuous_agg +SELECT * FROM _timescaledb_catalog._tmp_continuous_agg; +DROP TABLE _timescaledb_catalog._tmp_continuous_agg; + +CREATE INDEX continuous_agg_raw_hypertable_id_idx ON _timescaledb_catalog.continuous_agg (raw_hypertable_id); + +SELECT pg_catalog.pg_extension_config_dump('_timescaledb_catalog.continuous_agg', ''); + +GRANT SELECT ON TABLE _timescaledb_catalog.continuous_agg TO PUBLIC; + +ALTER TABLE _timescaledb_catalog.continuous_aggs_materialization_invalidation_log + ADD CONSTRAINT continuous_aggs_materialization_invalid_materialization_id_fkey + FOREIGN KEY (materialization_id) + REFERENCES _timescaledb_catalog.continuous_agg(mat_hypertable_id) ON DELETE CASCADE; + +ALTER TABLE _timescaledb_catalog.continuous_aggs_watermark + ADD CONSTRAINT continuous_aggs_watermark_mat_hypertable_id_fkey + FOREIGN KEY (mat_hypertable_id) + REFERENCES _timescaledb_catalog.continuous_agg (mat_hypertable_id) ON DELETE CASCADE; + +ANALYZE _timescaledb_catalog.continuous_agg; + +-- +-- END Rebuild the catalog table `_timescaledb_catalog.continuous_agg` +-- + +-- +-- START bgw_job_stat_history +-- +DROP VIEW IF EXISTS timescaledb_information.job_errors; + +CREATE SEQUENCE _timescaledb_internal.bgw_job_stat_history_id_seq MINVALUE 1; + +CREATE TABLE _timescaledb_internal.bgw_job_stat_history ( + id INTEGER NOT NULL DEFAULT nextval('_timescaledb_internal.bgw_job_stat_history_id_seq'), + job_id INTEGER NOT NULL, + pid INTEGER, + execution_start TIMESTAMPTZ NOT NULL DEFAULT NOW(), + execution_finish TIMESTAMPTZ, + succeeded boolean NOT NULL DEFAULT FALSE, + data jsonb, + -- table constraints + CONSTRAINT bgw_job_stat_history_pkey PRIMARY KEY (id) +); + +ALTER SEQUENCE _timescaledb_internal.bgw_job_stat_history_id_seq OWNED BY _timescaledb_internal.bgw_job_stat_history.id; + +CREATE INDEX bgw_job_stat_history_job_id_idx ON _timescaledb_internal.bgw_job_stat_history (job_id); + +REVOKE ALL ON _timescaledb_internal.bgw_job_stat_history FROM PUBLIC; + +INSERT INTO _timescaledb_internal.bgw_job_stat_history (job_id, pid, execution_start, execution_finish, data) +SELECT + job_errors.job_id, + job_errors.pid, + job_errors.start_time, + job_errors.finish_time, + jsonb_build_object('job', to_jsonb(bgw_job.*)) || jsonb_build_object('error_data', job_errors.error_data) +FROM + _timescaledb_internal.job_errors + LEFT JOIN _timescaledb_config.bgw_job ON bgw_job.id = job_errors.job_id +ORDER BY + job_errors.job_id, job_errors.start_time; + +ALTER EXTENSION timescaledb + DROP TABLE _timescaledb_internal.job_errors; + +DROP TABLE _timescaledb_internal.job_errors; + +UPDATE _timescaledb_config.bgw_job SET scheduled = false WHERE id = 2; +INSERT INTO _timescaledb_config.bgw_job ( + id, + application_name, + schedule_interval, + max_runtime, + max_retries, + retry_period, + proc_schema, + proc_name, + owner, + scheduled, + config, + check_schema, + check_name, + fixed_schedule, + initial_start +) +VALUES +( + 3, + 'Job History Log Retention Policy [3]', + INTERVAL '1 month', + INTERVAL '1 hour', + -1, + INTERVAL '1h', + '_timescaledb_functions', + 'policy_job_stat_history_retention', + pg_catalog.quote_ident(current_role)::regrole, + true, + '{"drop_after":"1 month"}', + '_timescaledb_functions', + 'policy_job_stat_history_retention_check', + true, + '2000-01-01 00:00:00+00'::timestamptz +) ON CONFLICT (id) DO NOTHING; + +DROP FUNCTION IF EXISTS _timescaledb_internal.policy_job_error_retention(job_id integer,config jsonb); +DROP FUNCTION IF EXISTS _timescaledb_internal.policy_job_error_retention_check(config jsonb); +DROP FUNCTION IF EXISTS _timescaledb_functions.policy_job_error_retention(job_id integer,config jsonb); +DROP FUNCTION IF EXISTS _timescaledb_functions.policy_job_error_retention_check(config jsonb); + +-- +-- END bgw_job_stat_history +-- + +-- Migrate existing CAggs using time_bucket_ng to time_bucket +CREATE PROCEDURE _timescaledb_functions.cagg_migrate_to_time_bucket(cagg REGCLASS) + AS '@MODULE_PATHNAME@', 'ts_continuous_agg_migrate_to_time_bucket' LANGUAGE C; + +DO $$ +DECLARE + cagg_name regclass; +BEGIN + FOR cagg_name IN + SELECT pg_catalog.format('%I.%I', user_view_schema, user_view_name)::regclass + FROM _timescaledb_catalog.continuous_agg cagg + JOIN _timescaledb_catalog.continuous_aggs_bucket_function AS bf ON (cagg.mat_hypertable_id = bf.mat_hypertable_id) + WHERE + bf.bucket_func::text LIKE '%time_bucket_ng%' + LOOP + CALL _timescaledb_functions.cagg_migrate_to_time_bucket(cagg_name); + END LOOP; +END +$$; diff --git a/sql/updates/2.15.0--2.14.2.sql b/sql/updates/2.15.0--2.14.2.sql new file mode 100644 index 00000000000..8f3c13af7a6 --- /dev/null +++ b/sql/updates/2.15.0--2.14.2.sql @@ -0,0 +1,290 @@ +DROP FUNCTION IF EXISTS _timescaledb_functions.remove_dropped_chunk_metadata(INTEGER); + + +-- +-- Rebuild the catalog table `_timescaledb_catalog.continuous_agg` +-- +DROP VIEW IF EXISTS timescaledb_experimental.policies; +DROP VIEW IF EXISTS timescaledb_information.hypertables; +DROP VIEW IF EXISTS timescaledb_information.continuous_aggregates; + +DROP PROCEDURE IF EXISTS @extschema@.cagg_migrate (REGCLASS, BOOLEAN, BOOLEAN); +DROP FUNCTION IF EXISTS _timescaledb_internal.cagg_migrate_pre_validation (TEXT, TEXT, TEXT); +DROP FUNCTION IF EXISTS _timescaledb_functions.cagg_migrate_pre_validation (TEXT, TEXT, TEXT); +DROP PROCEDURE IF EXISTS _timescaledb_internal.cagg_migrate_create_plan (_timescaledb_catalog.continuous_agg, TEXT, BOOLEAN, BOOLEAN); +DROP PROCEDURE IF EXISTS _timescaledb_functions.cagg_migrate_create_plan (_timescaledb_catalog.continuous_agg, TEXT, BOOLEAN, BOOLEAN); + +DROP FUNCTION IF EXISTS _timescaledb_functions.cagg_migrate_plan_exists (INTEGER); +DROP PROCEDURE IF EXISTS _timescaledb_internal.cagg_migrate_execute_plan (_timescaledb_catalog.continuous_agg); +DROP PROCEDURE IF EXISTS _timescaledb_functions.cagg_migrate_execute_plan (_timescaledb_catalog.continuous_agg); +DROP PROCEDURE IF EXISTS _timescaledb_internal.cagg_migrate_execute_create_new_cagg (_timescaledb_catalog.continuous_agg, _timescaledb_catalog.continuous_agg_migrate_plan_step); +DROP PROCEDURE IF EXISTS _timescaledb_functions.cagg_migrate_execute_create_new_cagg (_timescaledb_catalog.continuous_agg, _timescaledb_catalog.continuous_agg_migrate_plan_step); +DROP PROCEDURE IF EXISTS _timescaledb_internal.cagg_migrate_execute_disable_policies (_timescaledb_catalog.continuous_agg, _timescaledb_catalog.continuous_agg_migrate_plan_step); +DROP PROCEDURE IF EXISTS _timescaledb_functions.cagg_migrate_execute_disable_policies (_timescaledb_catalog.continuous_agg, _timescaledb_catalog.continuous_agg_migrate_plan_step); +DROP PROCEDURE IF EXISTS _timescaledb_internal.cagg_migrate_execute_enable_policies (_timescaledb_catalog.continuous_agg, _timescaledb_catalog.continuous_agg_migrate_plan_step); +DROP PROCEDURE IF EXISTS _timescaledb_functions.cagg_migrate_execute_enable_policies (_timescaledb_catalog.continuous_agg, _timescaledb_catalog.continuous_agg_migrate_plan_step); +DROP PROCEDURE IF EXISTS _timescaledb_internal.cagg_migrate_execute_copy_policies (_timescaledb_catalog.continuous_agg, _timescaledb_catalog.continuous_agg_migrate_plan_step); +DROP PROCEDURE IF EXISTS _timescaledb_functions.cagg_migrate_execute_copy_policies (_timescaledb_catalog.continuous_agg, _timescaledb_catalog.continuous_agg_migrate_plan_step); +DROP PROCEDURE IF EXISTS _timescaledb_internal.cagg_migrate_execute_refresh_new_cagg (_timescaledb_catalog.continuous_agg, _timescaledb_catalog.continuous_agg_migrate_plan_step); +DROP PROCEDURE IF EXISTS _timescaledb_functions.cagg_migrate_execute_refresh_new_cagg (_timescaledb_catalog.continuous_agg, _timescaledb_catalog.continuous_agg_migrate_plan_step); +DROP PROCEDURE IF EXISTS _timescaledb_internal.cagg_migrate_execute_copy_data (_timescaledb_catalog.continuous_agg, _timescaledb_catalog.continuous_agg_migrate_plan_step); +DROP PROCEDURE IF EXISTS _timescaledb_functions.cagg_migrate_execute_copy_data (_timescaledb_catalog.continuous_agg, _timescaledb_catalog.continuous_agg_migrate_plan_step); +DROP PROCEDURE IF EXISTS _timescaledb_internal.cagg_migrate_execute_override_cagg (_timescaledb_catalog.continuous_agg, _timescaledb_catalog.continuous_agg_migrate_plan_step); +DROP PROCEDURE IF EXISTS _timescaledb_functions.cagg_migrate_execute_override_cagg (_timescaledb_catalog.continuous_agg, _timescaledb_catalog.continuous_agg_migrate_plan_step); +DROP PROCEDURE IF EXISTS _timescaledb_internal.cagg_migrate_execute_drop_old_cagg (_timescaledb_catalog.continuous_agg, _timescaledb_catalog.continuous_agg_migrate_plan_step); +DROP PROCEDURE IF EXISTS _timescaledb_functions.cagg_migrate_execute_drop_old_cagg (_timescaledb_catalog.continuous_agg, _timescaledb_catalog.continuous_agg_migrate_plan_step); + +ALTER TABLE _timescaledb_catalog.continuous_aggs_materialization_invalidation_log + DROP CONSTRAINT continuous_aggs_materialization_invalid_materialization_id_fkey; + +ALTER TABLE _timescaledb_catalog.continuous_aggs_watermark + DROP CONSTRAINT continuous_aggs_watermark_mat_hypertable_id_fkey; + +ALTER EXTENSION timescaledb + DROP TABLE _timescaledb_catalog.continuous_agg; + +CREATE TABLE _timescaledb_catalog._tmp_continuous_agg AS + SELECT + mat_hypertable_id, + raw_hypertable_id, + parent_mat_hypertable_id, + user_view_schema, + user_view_name, + partial_view_schema, + partial_view_name, + -1::bigint as bucket_width, -- -1 means variable width. Will be modified soon if not variable. + direct_view_schema, + direct_view_name, + materialized_only, + finalized + FROM + _timescaledb_catalog.continuous_agg + ORDER BY + mat_hypertable_id; + +-- Migrate CAggs with fixed bucket on interval back +WITH fixed_buckets AS ( + SELECT * FROM _timescaledb_catalog.continuous_aggs_bucket_function WHERE bucket_fixed_width = true AND bucket_func::text LIKE '%time_bucket(interval%' +) +UPDATE _timescaledb_catalog._tmp_continuous_agg cagg + SET bucket_width = _timescaledb_functions.interval_to_usec(fb.bucket_width::interval) + FROM fixed_buckets fb + WHERE cagg.mat_hypertable_id = fb.mat_hypertable_id; + +-- Migrate CAggs with fixed bucket on integer back +WITH fixed_buckets AS ( + SELECT * FROM _timescaledb_catalog.continuous_aggs_bucket_function WHERE bucket_fixed_width = true AND bucket_func::text NOT LIKE '%time_bucket(interval%' +) +UPDATE _timescaledb_catalog._tmp_continuous_agg cagg + SET bucket_width = fb.bucket_width::bigint + FROM fixed_buckets fb + WHERE cagg.mat_hypertable_id = fb.mat_hypertable_id; + +DELETE FROM _timescaledb_catalog.continuous_aggs_bucket_function WHERE bucket_fixed_width = true; + +DROP TABLE _timescaledb_catalog.continuous_agg; + +CREATE TABLE _timescaledb_catalog.continuous_agg ( + mat_hypertable_id integer NOT NULL, + raw_hypertable_id integer NOT NULL, + parent_mat_hypertable_id integer, + user_view_schema name NOT NULL, + user_view_name name NOT NULL, + partial_view_schema name NOT NULL, + partial_view_name name NOT NULL, + bucket_width bigint NOT NULL, + direct_view_schema name NOT NULL, + direct_view_name name NOT NULL, + materialized_only bool NOT NULL DEFAULT FALSE, + finalized bool NOT NULL DEFAULT TRUE, + -- table constraints + CONSTRAINT continuous_agg_pkey PRIMARY KEY (mat_hypertable_id), + CONSTRAINT continuous_agg_partial_view_schema_partial_view_name_key UNIQUE (partial_view_schema, partial_view_name), + CONSTRAINT continuous_agg_user_view_schema_user_view_name_key UNIQUE (user_view_schema, user_view_name), + CONSTRAINT continuous_agg_mat_hypertable_id_fkey + FOREIGN KEY (mat_hypertable_id) REFERENCES _timescaledb_catalog.hypertable (id) ON DELETE CASCADE, + CONSTRAINT continuous_agg_raw_hypertable_id_fkey + FOREIGN KEY (raw_hypertable_id) REFERENCES _timescaledb_catalog.hypertable (id) ON DELETE CASCADE, + CONSTRAINT continuous_agg_parent_mat_hypertable_id_fkey + FOREIGN KEY (parent_mat_hypertable_id) + REFERENCES _timescaledb_catalog.continuous_agg (mat_hypertable_id) ON DELETE CASCADE +); + +INSERT INTO _timescaledb_catalog.continuous_agg +SELECT * FROM _timescaledb_catalog._tmp_continuous_agg; +DROP TABLE _timescaledb_catalog._tmp_continuous_agg; + +CREATE INDEX continuous_agg_raw_hypertable_id_idx ON _timescaledb_catalog.continuous_agg (raw_hypertable_id); + +SELECT pg_catalog.pg_extension_config_dump('_timescaledb_catalog.continuous_agg', ''); + +GRANT SELECT ON TABLE _timescaledb_catalog.continuous_agg TO PUBLIC; + +ALTER TABLE _timescaledb_catalog.continuous_aggs_materialization_invalidation_log + ADD CONSTRAINT continuous_aggs_materialization_invalid_materialization_id_fkey + FOREIGN KEY (materialization_id) + REFERENCES _timescaledb_catalog.continuous_agg(mat_hypertable_id) ON DELETE CASCADE; + +ALTER TABLE _timescaledb_catalog.continuous_aggs_watermark + ADD CONSTRAINT continuous_aggs_watermark_mat_hypertable_id_fkey + FOREIGN KEY (mat_hypertable_id) + REFERENCES _timescaledb_catalog.continuous_agg (mat_hypertable_id) ON DELETE CASCADE; + +ANALYZE _timescaledb_catalog.continuous_agg; + +-- +-- END Rebuild the catalog table `_timescaledb_catalog.continuous_agg` +-- + +-- +-- Rebuild the catalog table `_timescaledb_catalog.continuous_aggs_bucket_function` +-- +UPDATE _timescaledb_catalog.continuous_aggs_bucket_function SET bucket_origin = '' WHERE bucket_origin IS NULL; +UPDATE _timescaledb_catalog.continuous_aggs_bucket_function SET bucket_timezone = '' WHERE bucket_timezone IS NULL; + +CREATE TABLE _timescaledb_catalog._tmp_continuous_aggs_bucket_function AS + SELECT + mat_hypertable_id, + CASE WHEN bucket_func::text like 'timescaledb_experimental%' THEN true ELSE false END, + split_part(bucket_func::regproc::text, '.', 2), + bucket_width, + bucket_origin, + bucket_timezone + FROM + _timescaledb_catalog.continuous_aggs_bucket_function + ORDER BY + mat_hypertable_id; + +ALTER EXTENSION timescaledb + DROP TABLE _timescaledb_catalog.continuous_aggs_bucket_function; + +DROP TABLE _timescaledb_catalog.continuous_aggs_bucket_function; + +CREATE TABLE _timescaledb_catalog.continuous_aggs_bucket_function ( + mat_hypertable_id integer NOT NULL, + -- The schema of the function. Equals TRUE for "timescaledb_experimental", FALSE otherwise. + experimental bool NOT NULL, + -- Name of the bucketing function, e.g. "time_bucket" or "time_bucket_ng" + name text NOT NULL, + -- `bucket_width` argument of the function, e.g. "1 month" + bucket_width text NOT NULL, + -- `origin` argument of the function provided by the user + origin text NOT NULL, + -- `timezone` argument of the function provided by the user + timezone text NOT NULL, + -- table constraints + CONSTRAINT continuous_aggs_bucket_function_pkey PRIMARY KEY (mat_hypertable_id), + CONSTRAINT continuous_aggs_bucket_function_mat_hypertable_id_fkey FOREIGN KEY (mat_hypertable_id) REFERENCES _timescaledb_catalog.hypertable (id) ON DELETE CASCADE +); + +INSERT INTO _timescaledb_catalog.continuous_aggs_bucket_function + SELECT * FROM _timescaledb_catalog._tmp_continuous_aggs_bucket_function; + +DROP TABLE _timescaledb_catalog._tmp_continuous_aggs_bucket_function; + +SELECT pg_catalog.pg_extension_config_dump('_timescaledb_catalog.continuous_aggs_bucket_function', ''); + +GRANT SELECT ON TABLE _timescaledb_catalog.continuous_aggs_bucket_function TO PUBLIC; + +ANALYZE _timescaledb_catalog.continuous_aggs_bucket_function; + +-- +-- End rebuild the catalog table `_timescaledb_catalog.continuous_aggs_bucket_function` +-- + +-- Convert _timescaledb_catalog.continuous_aggs_bucket_function.origin back to Timestamp +UPDATE _timescaledb_catalog.continuous_aggs_bucket_function + SET origin = origin::timestamptz::timestamp::text + WHERE length(origin) > 1; + +-- only create stub +CREATE FUNCTION _timescaledb_functions.get_chunk_relstats(relid REGCLASS) +RETURNS TABLE(chunk_id INTEGER, hypertable_id INTEGER, num_pages INTEGER, num_tuples REAL, num_allvisible INTEGER) +AS $$BEGIN END$$ LANGUAGE plpgsql SET search_path = pg_catalog, pg_temp; + +CREATE FUNCTION _timescaledb_functions.get_chunk_colstats(relid REGCLASS) +RETURNS TABLE(chunk_id INTEGER, hypertable_id INTEGER, att_num INTEGER, nullfrac REAL, width INTEGER, distinctval REAL, slotkind INTEGER[], slotopstrings CSTRING[], slotcollations OID[], slot1numbers FLOAT4[], slot2numbers FLOAT4[], slot3numbers FLOAT4[], slot4numbers FLOAT4[], slot5numbers FLOAT4[], slotvaluetypetrings CSTRING[], slot1values CSTRING[], slot2values CSTRING[], slot3values CSTRING[], slot4values CSTRING[], slot5values CSTRING[]) +AS $$BEGIN END$$ LANGUAGE plpgsql SET search_path = pg_catalog, pg_temp; + +-- +-- START bgw_job_stat_history +-- +DROP VIEW IF EXISTS timescaledb_information.job_errors; + +ALTER EXTENSION timescaledb + DROP VIEW timescaledb_information.job_history; + +DROP VIEW IF EXISTS timescaledb_information.job_history; + +CREATE TABLE _timescaledb_internal.job_errors ( + job_id integer not null, + pid integer, + start_time timestamptz, + finish_time timestamptz, + error_data jsonb +); + +INSERT INTO _timescaledb_internal.job_errors (job_id, pid, start_time, finish_time, error_data) +SELECT + job_id, + pid, + execution_start, + execution_finish, + data->'error_data' +FROM + _timescaledb_internal.bgw_job_stat_history +WHERE + succeeded IS FALSE +ORDER BY + job_id, execution_start; + +ALTER EXTENSION timescaledb + DROP TABLE _timescaledb_internal.bgw_job_stat_history; + +DROP TABLE IF EXISTS _timescaledb_internal.bgw_job_stat_history; + +REVOKE ALL ON _timescaledb_internal.job_errors FROM PUBLIC; + +DROP FUNCTION IF EXISTS _timescaledb_internal.policy_job_stat_history_retention(job_id integer,config jsonb); +DROP FUNCTION IF EXISTS _timescaledb_internal.policy_job_stat_history_retention_check(config jsonb); +DROP FUNCTION IF EXISTS _timescaledb_functions.policy_job_stat_history_retention(job_id integer,config jsonb); +DROP FUNCTION IF EXISTS _timescaledb_functions.policy_job_stat_history_retention_check(config jsonb); + +CREATE OR REPLACE FUNCTION _timescaledb_functions.policy_job_error_retention(job_id integer, config JSONB) RETURNS integer +LANGUAGE PLPGSQL AS +$BODY$ +DECLARE + drop_after INTERVAL; + numrows INTEGER; +BEGIN + SELECT config->>'drop_after' INTO STRICT drop_after; + WITH deleted AS + (DELETE + FROM _timescaledb_internal.job_errors + WHERE finish_time < (now() - drop_after) RETURNING *) + SELECT count(*) + FROM deleted INTO numrows; + RETURN numrows; +END; +$BODY$ SET search_path TO pg_catalog, pg_temp; + +CREATE OR REPLACE FUNCTION _timescaledb_functions.policy_job_error_retention_check(config JSONB) RETURNS VOID +LANGUAGE PLPGSQL AS +$BODY$ +DECLARE + drop_after interval; +BEGIN + IF config IS NULL THEN + RAISE EXCEPTION 'config cannot be NULL, and must contain drop_after'; + END IF; + SELECT config->>'drop_after' INTO STRICT drop_after; + IF drop_after IS NULL THEN + RAISE EXCEPTION 'drop_after interval not provided'; + END IF ; +END; +$BODY$ SET search_path TO pg_catalog, pg_temp; + +UPDATE _timescaledb_config.bgw_job SET scheduled = true WHERE id = 2; +DELETE FROM _timescaledb_config.bgw_job WHERE id = 3; + +DROP PROCEDURE IF EXISTS _timescaledb_functions.cagg_migrate_to_time_bucket(cagg REGCLASS); diff --git a/sql/updates/latest-dev.sql b/sql/updates/latest-dev.sql index 209a466b410..e69de29bb2d 100644 --- a/sql/updates/latest-dev.sql +++ b/sql/updates/latest-dev.sql @@ -1,440 +0,0 @@ --- Remove multi-node CAGG support -DROP FUNCTION IF EXISTS _timescaledb_internal.invalidation_cagg_log_add_entry(integer,bigint,bigint); -DROP FUNCTION IF EXISTS _timescaledb_internal.invalidation_hyper_log_add_entry(integer,bigint,bigint); -DROP FUNCTION IF EXISTS _timescaledb_internal.materialization_invalidation_log_delete(integer); -DROP FUNCTION IF EXISTS _timescaledb_internal.invalidation_process_cagg_log(integer,integer,regtype,bigint,bigint,integer[],bigint[],bigint[]); -DROP FUNCTION IF EXISTS _timescaledb_internal.invalidation_process_cagg_log(integer,integer,regtype,bigint,bigint,integer[],bigint[],bigint[],text[]); -DROP FUNCTION IF EXISTS _timescaledb_internal.invalidation_process_hypertable_log(integer,integer,regtype,integer[],bigint[],bigint[]); -DROP FUNCTION IF EXISTS _timescaledb_internal.invalidation_process_hypertable_log(integer,integer,regtype,integer[],bigint[],bigint[],text[]); -DROP FUNCTION IF EXISTS _timescaledb_internal.hypertable_invalidation_log_delete(integer); - -DROP FUNCTION IF EXISTS _timescaledb_functions.invalidation_cagg_log_add_entry(integer,bigint,bigint); -DROP FUNCTION IF EXISTS _timescaledb_functions.invalidation_hyper_log_add_entry(integer,bigint,bigint); -DROP FUNCTION IF EXISTS _timescaledb_functions.materialization_invalidation_log_delete(integer); -DROP FUNCTION IF EXISTS _timescaledb_functions.invalidation_process_cagg_log(integer,integer,regtype,bigint,bigint,integer[],bigint[],bigint[]); -DROP FUNCTION IF EXISTS _timescaledb_functions.invalidation_process_cagg_log(integer,integer,regtype,bigint,bigint,integer[],bigint[],bigint[],text[]); -DROP FUNCTION IF EXISTS _timescaledb_functions.invalidation_process_hypertable_log(integer,integer,regtype,integer[],bigint[],bigint[]); -DROP FUNCTION IF EXISTS _timescaledb_functions.invalidation_process_hypertable_log(integer,integer,regtype,integer[],bigint[],bigint[],text[]); -DROP FUNCTION IF EXISTS _timescaledb_functions.hypertable_invalidation_log_delete(integer); - --- Remove chunk metadata when marked as dropped -CREATE FUNCTION _timescaledb_functions.remove_dropped_chunk_metadata(_hypertable_id INTEGER) -RETURNS INTEGER LANGUAGE plpgsql AS $$ -DECLARE - _chunk_id INTEGER; - _removed INTEGER := 0; -BEGIN - FOR _chunk_id IN - SELECT id FROM _timescaledb_catalog.chunk - WHERE hypertable_id = _hypertable_id - AND dropped IS TRUE - AND NOT EXISTS ( - SELECT FROM information_schema.tables - WHERE tables.table_schema = chunk.schema_name - AND tables.table_name = chunk.table_name - ) - AND NOT EXISTS ( - SELECT FROM _timescaledb_catalog.hypertable - JOIN _timescaledb_catalog.continuous_agg ON continuous_agg.raw_hypertable_id = hypertable.id - WHERE hypertable.id = chunk.hypertable_id - -- for the old caggs format we need to keep chunk metadata for dropped chunks - AND continuous_agg.finalized IS FALSE - ) - LOOP - _removed := _removed + 1; - RAISE INFO 'Removing metadata of chunk % from hypertable %', _chunk_id, _hypertable_id; - WITH _dimension_slice_remove AS ( - DELETE FROM _timescaledb_catalog.dimension_slice - USING _timescaledb_catalog.chunk_constraint - WHERE dimension_slice.id = chunk_constraint.dimension_slice_id - AND chunk_constraint.chunk_id = _chunk_id - RETURNING _timescaledb_catalog.dimension_slice.id - ) - DELETE FROM _timescaledb_catalog.chunk_constraint - USING _dimension_slice_remove - WHERE chunk_constraint.dimension_slice_id = _dimension_slice_remove.id; - - DELETE FROM _timescaledb_internal.bgw_policy_chunk_stats - WHERE bgw_policy_chunk_stats.chunk_id = _chunk_id; - - DELETE FROM _timescaledb_catalog.chunk_index - WHERE chunk_index.chunk_id = _chunk_id; - - DELETE FROM _timescaledb_catalog.compression_chunk_size - WHERE compression_chunk_size.chunk_id = _chunk_id - OR compression_chunk_size.compressed_chunk_id = _chunk_id; - - DELETE FROM _timescaledb_catalog.chunk - WHERE chunk.id = _chunk_id - OR chunk.compressed_chunk_id = _chunk_id; - END LOOP; - - RETURN _removed; -END; -$$ SET search_path TO pg_catalog, pg_temp; - -SELECT _timescaledb_functions.remove_dropped_chunk_metadata(id) AS chunks_metadata_removed -FROM _timescaledb_catalog.hypertable; - --- --- Rebuild the catalog table `_timescaledb_catalog.continuous_aggs_bucket_function` --- - -CREATE OR REPLACE FUNCTION _timescaledb_functions.cagg_get_bucket_function( - mat_hypertable_id INTEGER -) RETURNS regprocedure AS '@MODULE_PATHNAME@', 'ts_continuous_agg_get_bucket_function' LANGUAGE C STRICT VOLATILE; - --- Since we need now the regclass of the used bucket function, we have to recover it --- by parsing the view query by calling 'cagg_get_bucket_function'. -CREATE TABLE _timescaledb_catalog._tmp_continuous_aggs_bucket_function AS - SELECT - mat_hypertable_id, - _timescaledb_functions.cagg_get_bucket_function(mat_hypertable_id), - bucket_width, - origin, - NULL::text AS bucket_offset, - timezone, - false AS bucket_fixed_width - FROM - _timescaledb_catalog.continuous_aggs_bucket_function - ORDER BY - mat_hypertable_id; - -ALTER EXTENSION timescaledb - DROP TABLE _timescaledb_catalog.continuous_aggs_bucket_function; - -DROP TABLE _timescaledb_catalog.continuous_aggs_bucket_function; - -CREATE TABLE _timescaledb_catalog.continuous_aggs_bucket_function ( - mat_hypertable_id integer NOT NULL, - -- The bucket function - bucket_func regprocedure NOT NULL, - -- `bucket_width` argument of the function, e.g. "1 month" - bucket_width text NOT NULL, - -- optional `origin` argument of the function provided by the user - bucket_origin text, - -- optional `offset` argument of the function provided by the user - bucket_offset text, - -- optional `timezone` argument of the function provided by the user - bucket_timezone text, - -- fixed or variable sized bucket - bucket_fixed_width bool NOT NULL, - -- table constraints - CONSTRAINT continuous_aggs_bucket_function_pkey PRIMARY KEY (mat_hypertable_id), - CONSTRAINT continuous_aggs_bucket_function_mat_hypertable_id_fkey FOREIGN KEY (mat_hypertable_id) REFERENCES _timescaledb_catalog.hypertable (id) ON DELETE CASCADE -); - -INSERT INTO _timescaledb_catalog.continuous_aggs_bucket_function - SELECT * FROM _timescaledb_catalog._tmp_continuous_aggs_bucket_function; - -DROP TABLE _timescaledb_catalog._tmp_continuous_aggs_bucket_function; - -SELECT pg_catalog.pg_extension_config_dump('_timescaledb_catalog.continuous_aggs_bucket_function', ''); - -GRANT SELECT ON TABLE _timescaledb_catalog.continuous_aggs_bucket_function TO PUBLIC; - -ANALYZE _timescaledb_catalog.continuous_aggs_bucket_function; - -ALTER EXTENSION timescaledb DROP FUNCTION _timescaledb_functions.cagg_get_bucket_function(INTEGER); -DROP FUNCTION IF EXISTS _timescaledb_functions.cagg_get_bucket_function(INTEGER); - --- --- End rebuild the catalog table `_timescaledb_catalog.continuous_aggs_bucket_function` --- - --- Convert _timescaledb_catalog.continuous_aggs_bucket_function.bucket_origin to TimestampTZ -UPDATE _timescaledb_catalog.continuous_aggs_bucket_function - SET bucket_origin = bucket_origin::timestamp::timestamptz::text - WHERE length(bucket_origin) > 1; - --- Historically, we have used empty strings for undefined bucket_origin and timezone --- attributes. This is now replaced by proper NULL values. We use TRIM() to ensure we handle empty string well. -UPDATE _timescaledb_catalog.continuous_aggs_bucket_function SET bucket_origin = NULL WHERE TRIM(bucket_origin) = ''; -UPDATE _timescaledb_catalog.continuous_aggs_bucket_function SET bucket_timezone = NULL WHERE TRIM(bucket_timezone) = ''; - --- So far, there were no difference between 0 and -1 retries. Since now on, 0 means no retries. Updating the retry --- count of existing jobs to -1 to keep the current semantics. -UPDATE _timescaledb_config.bgw_job SET max_retries = -1 WHERE max_retries = 0; - -DROP FUNCTION IF EXISTS _timescaledb_functions.get_chunk_relstats; -DROP FUNCTION IF EXISTS _timescaledb_functions.get_chunk_colstats; -DROP FUNCTION IF EXISTS _timescaledb_internal.get_chunk_relstats; -DROP FUNCTION IF EXISTS _timescaledb_internal.get_chunk_colstats; - --- In older TSDB versions, we disabled autovacuum for compressed chunks --- to keep the statistics. However, this restriction was removed in --- #5118 but no migration was performed to remove the custom --- autovacuum setting for existing chunks. -DO $$ -DECLARE - chunk regclass; -BEGIN - FOR chunk IN - SELECT pg_catalog.format('%I.%I', schema_name, table_name)::regclass - FROM _timescaledb_catalog.chunk c - JOIN pg_catalog.pg_class AS pc ON (pc.oid=format('%I.%I', schema_name, table_name)::regclass) - CROSS JOIN unnest(reloptions) AS u(option) - WHERE - dropped = false - AND osm_chunk = false - AND option LIKE 'autovacuum_enabled%' - LOOP - EXECUTE pg_catalog.format('ALTER TABLE %s RESET (autovacuum_enabled);', chunk::text); - END LOOP; -END -$$; - --- --- Rebuild the catalog table `_timescaledb_catalog.continuous_agg` --- - --- (1) Create missing entries in _timescaledb_catalog.continuous_aggs_bucket_function -CREATE OR REPLACE FUNCTION _timescaledb_functions.cagg_get_bucket_function( - mat_hypertable_id INTEGER -) RETURNS regprocedure AS '@MODULE_PATHNAME@', 'ts_continuous_agg_get_bucket_function' LANGUAGE C STRICT VOLATILE; - --- Make sure function points to the new version of TSDB -CREATE OR REPLACE FUNCTION _timescaledb_functions.to_interval(unixtime_us BIGINT) RETURNS INTERVAL - AS '@MODULE_PATHNAME@', 'ts_pg_unix_microseconds_to_interval' LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE; - --- We need to create entries in continuous_aggs_bucket_function for all CAggs that were treated so far --- as fixed indicated by a bucket_width != -1 -INSERT INTO _timescaledb_catalog.continuous_aggs_bucket_function - SELECT - mat_hypertable_id, - _timescaledb_functions.cagg_get_bucket_function(mat_hypertable_id), - -- Intervals needs to be converted into the proper interval format - -- Function name could be prefixed with 'public.'. Therefore LIKE instead of starts_with is used - CASE WHEN _timescaledb_functions.cagg_get_bucket_function(mat_hypertable_id)::text LIKE '%time_bucket(interval,%' THEN - _timescaledb_functions.to_interval(bucket_width)::text - ELSE - bucket_width::text - END, - NULL, -- bucket_origin - NULL, -- bucket_offset - NULL, -- bucket_timezone - true -- bucket_fixed_width - FROM _timescaledb_catalog.continuous_agg WHERE bucket_width != -1; - -ALTER EXTENSION timescaledb DROP FUNCTION _timescaledb_functions.cagg_get_bucket_function(INTEGER); -DROP FUNCTION IF EXISTS _timescaledb_functions.cagg_get_bucket_function(INTEGER); - --- (2) Rebuild catalog table -DROP VIEW IF EXISTS timescaledb_experimental.policies; -DROP VIEW IF EXISTS timescaledb_information.hypertables; -DROP VIEW IF EXISTS timescaledb_information.continuous_aggregates; - -DROP PROCEDURE IF EXISTS @extschema@.cagg_migrate (REGCLASS, BOOLEAN, BOOLEAN); -DROP FUNCTION IF EXISTS _timescaledb_internal.cagg_migrate_pre_validation (TEXT, TEXT, TEXT); -DROP FUNCTION IF EXISTS _timescaledb_functions.cagg_migrate_pre_validation (TEXT, TEXT, TEXT); -DROP PROCEDURE IF EXISTS _timescaledb_internal.cagg_migrate_create_plan (_timescaledb_catalog.continuous_agg, TEXT, BOOLEAN, BOOLEAN); -DROP PROCEDURE IF EXISTS _timescaledb_functions.cagg_migrate_create_plan (_timescaledb_catalog.continuous_agg, TEXT, BOOLEAN, BOOLEAN); - -DROP FUNCTION IF EXISTS _timescaledb_functions.cagg_migrate_plan_exists (INTEGER); -DROP PROCEDURE IF EXISTS _timescaledb_internal.cagg_migrate_execute_plan (_timescaledb_catalog.continuous_agg); -DROP PROCEDURE IF EXISTS _timescaledb_functions.cagg_migrate_execute_plan (_timescaledb_catalog.continuous_agg); -DROP PROCEDURE IF EXISTS _timescaledb_internal.cagg_migrate_execute_create_new_cagg (_timescaledb_catalog.continuous_agg, _timescaledb_catalog.continuous_agg_migrate_plan_step); -DROP PROCEDURE IF EXISTS _timescaledb_functions.cagg_migrate_execute_create_new_cagg (_timescaledb_catalog.continuous_agg, _timescaledb_catalog.continuous_agg_migrate_plan_step); -DROP PROCEDURE IF EXISTS _timescaledb_internal.cagg_migrate_execute_disable_policies (_timescaledb_catalog.continuous_agg, _timescaledb_catalog.continuous_agg_migrate_plan_step); -DROP PROCEDURE IF EXISTS _timescaledb_functions.cagg_migrate_execute_disable_policies (_timescaledb_catalog.continuous_agg, _timescaledb_catalog.continuous_agg_migrate_plan_step); -DROP PROCEDURE IF EXISTS _timescaledb_internal.cagg_migrate_execute_enable_policies (_timescaledb_catalog.continuous_agg, _timescaledb_catalog.continuous_agg_migrate_plan_step); -DROP PROCEDURE IF EXISTS _timescaledb_functions.cagg_migrate_execute_enable_policies (_timescaledb_catalog.continuous_agg, _timescaledb_catalog.continuous_agg_migrate_plan_step); -DROP PROCEDURE IF EXISTS _timescaledb_internal.cagg_migrate_execute_copy_policies (_timescaledb_catalog.continuous_agg, _timescaledb_catalog.continuous_agg_migrate_plan_step); -DROP PROCEDURE IF EXISTS _timescaledb_functions.cagg_migrate_execute_copy_policies (_timescaledb_catalog.continuous_agg, _timescaledb_catalog.continuous_agg_migrate_plan_step); -DROP PROCEDURE IF EXISTS _timescaledb_internal.cagg_migrate_execute_refresh_new_cagg (_timescaledb_catalog.continuous_agg, _timescaledb_catalog.continuous_agg_migrate_plan_step); -DROP PROCEDURE IF EXISTS _timescaledb_functions.cagg_migrate_execute_refresh_new_cagg (_timescaledb_catalog.continuous_agg, _timescaledb_catalog.continuous_agg_migrate_plan_step); -DROP PROCEDURE IF EXISTS _timescaledb_internal.cagg_migrate_execute_copy_data (_timescaledb_catalog.continuous_agg, _timescaledb_catalog.continuous_agg_migrate_plan_step); -DROP PROCEDURE IF EXISTS _timescaledb_functions.cagg_migrate_execute_copy_data (_timescaledb_catalog.continuous_agg, _timescaledb_catalog.continuous_agg_migrate_plan_step); -DROP PROCEDURE IF EXISTS _timescaledb_internal.cagg_migrate_execute_override_cagg (_timescaledb_catalog.continuous_agg, _timescaledb_catalog.continuous_agg_migrate_plan_step); -DROP PROCEDURE IF EXISTS _timescaledb_functions.cagg_migrate_execute_override_cagg (_timescaledb_catalog.continuous_agg, _timescaledb_catalog.continuous_agg_migrate_plan_step); -DROP PROCEDURE IF EXISTS _timescaledb_internal.cagg_migrate_execute_drop_old_cagg (_timescaledb_catalog.continuous_agg, _timescaledb_catalog.continuous_agg_migrate_plan_step); -DROP PROCEDURE IF EXISTS _timescaledb_functions.cagg_migrate_execute_drop_old_cagg (_timescaledb_catalog.continuous_agg, _timescaledb_catalog.continuous_agg_migrate_plan_step); - -ALTER TABLE _timescaledb_catalog.continuous_aggs_materialization_invalidation_log - DROP CONSTRAINT continuous_aggs_materialization_invalid_materialization_id_fkey; - -ALTER TABLE _timescaledb_catalog.continuous_aggs_watermark - DROP CONSTRAINT continuous_aggs_watermark_mat_hypertable_id_fkey; - -ALTER EXTENSION timescaledb - DROP TABLE _timescaledb_catalog.continuous_agg; - -CREATE TABLE _timescaledb_catalog._tmp_continuous_agg AS - SELECT - mat_hypertable_id, - raw_hypertable_id, - parent_mat_hypertable_id, - user_view_schema, - user_view_name, - partial_view_schema, - partial_view_name, - direct_view_schema, - direct_view_name, - materialized_only, - finalized - FROM - _timescaledb_catalog.continuous_agg - ORDER BY - mat_hypertable_id; - -DROP TABLE _timescaledb_catalog.continuous_agg; - -CREATE TABLE _timescaledb_catalog.continuous_agg ( - mat_hypertable_id integer NOT NULL, - raw_hypertable_id integer NOT NULL, - parent_mat_hypertable_id integer, - user_view_schema name NOT NULL, - user_view_name name NOT NULL, - partial_view_schema name NOT NULL, - partial_view_name name NOT NULL, - direct_view_schema name NOT NULL, - direct_view_name name NOT NULL, - materialized_only bool NOT NULL DEFAULT FALSE, - finalized bool NOT NULL DEFAULT TRUE, - -- table constraints - CONSTRAINT continuous_agg_pkey PRIMARY KEY (mat_hypertable_id), - CONSTRAINT continuous_agg_partial_view_schema_partial_view_name_key UNIQUE (partial_view_schema, partial_view_name), - CONSTRAINT continuous_agg_user_view_schema_user_view_name_key UNIQUE (user_view_schema, user_view_name), - CONSTRAINT continuous_agg_mat_hypertable_id_fkey - FOREIGN KEY (mat_hypertable_id) REFERENCES _timescaledb_catalog.hypertable (id) ON DELETE CASCADE, - CONSTRAINT continuous_agg_raw_hypertable_id_fkey - FOREIGN KEY (raw_hypertable_id) REFERENCES _timescaledb_catalog.hypertable (id) ON DELETE CASCADE, - CONSTRAINT continuous_agg_parent_mat_hypertable_id_fkey - FOREIGN KEY (parent_mat_hypertable_id) - REFERENCES _timescaledb_catalog.continuous_agg (mat_hypertable_id) ON DELETE CASCADE -); - -INSERT INTO _timescaledb_catalog.continuous_agg -SELECT * FROM _timescaledb_catalog._tmp_continuous_agg; -DROP TABLE _timescaledb_catalog._tmp_continuous_agg; - -CREATE INDEX continuous_agg_raw_hypertable_id_idx ON _timescaledb_catalog.continuous_agg (raw_hypertable_id); - -SELECT pg_catalog.pg_extension_config_dump('_timescaledb_catalog.continuous_agg', ''); - -GRANT SELECT ON TABLE _timescaledb_catalog.continuous_agg TO PUBLIC; - -ALTER TABLE _timescaledb_catalog.continuous_aggs_materialization_invalidation_log - ADD CONSTRAINT continuous_aggs_materialization_invalid_materialization_id_fkey - FOREIGN KEY (materialization_id) - REFERENCES _timescaledb_catalog.continuous_agg(mat_hypertable_id) ON DELETE CASCADE; - -ALTER TABLE _timescaledb_catalog.continuous_aggs_watermark - ADD CONSTRAINT continuous_aggs_watermark_mat_hypertable_id_fkey - FOREIGN KEY (mat_hypertable_id) - REFERENCES _timescaledb_catalog.continuous_agg (mat_hypertable_id) ON DELETE CASCADE; - -ANALYZE _timescaledb_catalog.continuous_agg; - --- --- END Rebuild the catalog table `_timescaledb_catalog.continuous_agg` --- - --- --- START bgw_job_stat_history --- -DROP VIEW IF EXISTS timescaledb_information.job_errors; - -CREATE SEQUENCE _timescaledb_internal.bgw_job_stat_history_id_seq MINVALUE 1; - -CREATE TABLE _timescaledb_internal.bgw_job_stat_history ( - id INTEGER NOT NULL DEFAULT nextval('_timescaledb_internal.bgw_job_stat_history_id_seq'), - job_id INTEGER NOT NULL, - pid INTEGER, - execution_start TIMESTAMPTZ NOT NULL DEFAULT NOW(), - execution_finish TIMESTAMPTZ, - succeeded boolean NOT NULL DEFAULT FALSE, - data jsonb, - -- table constraints - CONSTRAINT bgw_job_stat_history_pkey PRIMARY KEY (id) -); - -ALTER SEQUENCE _timescaledb_internal.bgw_job_stat_history_id_seq OWNED BY _timescaledb_internal.bgw_job_stat_history.id; - -CREATE INDEX bgw_job_stat_history_job_id_idx ON _timescaledb_internal.bgw_job_stat_history (job_id); - -REVOKE ALL ON _timescaledb_internal.bgw_job_stat_history FROM PUBLIC; - -INSERT INTO _timescaledb_internal.bgw_job_stat_history (job_id, pid, execution_start, execution_finish, data) -SELECT - job_errors.job_id, - job_errors.pid, - job_errors.start_time, - job_errors.finish_time, - jsonb_build_object('job', to_jsonb(bgw_job.*)) || jsonb_build_object('error_data', job_errors.error_data) -FROM - _timescaledb_internal.job_errors - LEFT JOIN _timescaledb_config.bgw_job ON bgw_job.id = job_errors.job_id -ORDER BY - job_errors.job_id, job_errors.start_time; - -ALTER EXTENSION timescaledb - DROP TABLE _timescaledb_internal.job_errors; - -DROP TABLE _timescaledb_internal.job_errors; - -UPDATE _timescaledb_config.bgw_job SET scheduled = false WHERE id = 2; -INSERT INTO _timescaledb_config.bgw_job ( - id, - application_name, - schedule_interval, - max_runtime, - max_retries, - retry_period, - proc_schema, - proc_name, - owner, - scheduled, - config, - check_schema, - check_name, - fixed_schedule, - initial_start -) -VALUES -( - 3, - 'Job History Log Retention Policy [3]', - INTERVAL '1 month', - INTERVAL '1 hour', - -1, - INTERVAL '1h', - '_timescaledb_functions', - 'policy_job_stat_history_retention', - pg_catalog.quote_ident(current_role)::regrole, - true, - '{"drop_after":"1 month"}', - '_timescaledb_functions', - 'policy_job_stat_history_retention_check', - true, - '2000-01-01 00:00:00+00'::timestamptz -) ON CONFLICT (id) DO NOTHING; - -DROP FUNCTION IF EXISTS _timescaledb_internal.policy_job_error_retention(job_id integer,config jsonb); -DROP FUNCTION IF EXISTS _timescaledb_internal.policy_job_error_retention_check(config jsonb); -DROP FUNCTION IF EXISTS _timescaledb_functions.policy_job_error_retention(job_id integer,config jsonb); -DROP FUNCTION IF EXISTS _timescaledb_functions.policy_job_error_retention_check(config jsonb); - --- --- END bgw_job_stat_history --- - --- Migrate existing CAggs using time_bucket_ng to time_bucket -CREATE PROCEDURE _timescaledb_functions.cagg_migrate_to_time_bucket(cagg REGCLASS) - AS '@MODULE_PATHNAME@', 'ts_continuous_agg_migrate_to_time_bucket' LANGUAGE C; - -DO $$ -DECLARE - cagg_name regclass; -BEGIN - FOR cagg_name IN - SELECT pg_catalog.format('%I.%I', user_view_schema, user_view_name)::regclass - FROM _timescaledb_catalog.continuous_agg cagg - JOIN _timescaledb_catalog.continuous_aggs_bucket_function AS bf ON (cagg.mat_hypertable_id = bf.mat_hypertable_id) - WHERE - bf.bucket_func::text LIKE '%time_bucket_ng%' - LOOP - CALL _timescaledb_functions.cagg_migrate_to_time_bucket(cagg_name); - END LOOP; -END -$$; diff --git a/sql/updates/reverse-dev.sql b/sql/updates/reverse-dev.sql index 8f3c13af7a6..e69de29bb2d 100644 --- a/sql/updates/reverse-dev.sql +++ b/sql/updates/reverse-dev.sql @@ -1,290 +0,0 @@ -DROP FUNCTION IF EXISTS _timescaledb_functions.remove_dropped_chunk_metadata(INTEGER); - - --- --- Rebuild the catalog table `_timescaledb_catalog.continuous_agg` --- -DROP VIEW IF EXISTS timescaledb_experimental.policies; -DROP VIEW IF EXISTS timescaledb_information.hypertables; -DROP VIEW IF EXISTS timescaledb_information.continuous_aggregates; - -DROP PROCEDURE IF EXISTS @extschema@.cagg_migrate (REGCLASS, BOOLEAN, BOOLEAN); -DROP FUNCTION IF EXISTS _timescaledb_internal.cagg_migrate_pre_validation (TEXT, TEXT, TEXT); -DROP FUNCTION IF EXISTS _timescaledb_functions.cagg_migrate_pre_validation (TEXT, TEXT, TEXT); -DROP PROCEDURE IF EXISTS _timescaledb_internal.cagg_migrate_create_plan (_timescaledb_catalog.continuous_agg, TEXT, BOOLEAN, BOOLEAN); -DROP PROCEDURE IF EXISTS _timescaledb_functions.cagg_migrate_create_plan (_timescaledb_catalog.continuous_agg, TEXT, BOOLEAN, BOOLEAN); - -DROP FUNCTION IF EXISTS _timescaledb_functions.cagg_migrate_plan_exists (INTEGER); -DROP PROCEDURE IF EXISTS _timescaledb_internal.cagg_migrate_execute_plan (_timescaledb_catalog.continuous_agg); -DROP PROCEDURE IF EXISTS _timescaledb_functions.cagg_migrate_execute_plan (_timescaledb_catalog.continuous_agg); -DROP PROCEDURE IF EXISTS _timescaledb_internal.cagg_migrate_execute_create_new_cagg (_timescaledb_catalog.continuous_agg, _timescaledb_catalog.continuous_agg_migrate_plan_step); -DROP PROCEDURE IF EXISTS _timescaledb_functions.cagg_migrate_execute_create_new_cagg (_timescaledb_catalog.continuous_agg, _timescaledb_catalog.continuous_agg_migrate_plan_step); -DROP PROCEDURE IF EXISTS _timescaledb_internal.cagg_migrate_execute_disable_policies (_timescaledb_catalog.continuous_agg, _timescaledb_catalog.continuous_agg_migrate_plan_step); -DROP PROCEDURE IF EXISTS _timescaledb_functions.cagg_migrate_execute_disable_policies (_timescaledb_catalog.continuous_agg, _timescaledb_catalog.continuous_agg_migrate_plan_step); -DROP PROCEDURE IF EXISTS _timescaledb_internal.cagg_migrate_execute_enable_policies (_timescaledb_catalog.continuous_agg, _timescaledb_catalog.continuous_agg_migrate_plan_step); -DROP PROCEDURE IF EXISTS _timescaledb_functions.cagg_migrate_execute_enable_policies (_timescaledb_catalog.continuous_agg, _timescaledb_catalog.continuous_agg_migrate_plan_step); -DROP PROCEDURE IF EXISTS _timescaledb_internal.cagg_migrate_execute_copy_policies (_timescaledb_catalog.continuous_agg, _timescaledb_catalog.continuous_agg_migrate_plan_step); -DROP PROCEDURE IF EXISTS _timescaledb_functions.cagg_migrate_execute_copy_policies (_timescaledb_catalog.continuous_agg, _timescaledb_catalog.continuous_agg_migrate_plan_step); -DROP PROCEDURE IF EXISTS _timescaledb_internal.cagg_migrate_execute_refresh_new_cagg (_timescaledb_catalog.continuous_agg, _timescaledb_catalog.continuous_agg_migrate_plan_step); -DROP PROCEDURE IF EXISTS _timescaledb_functions.cagg_migrate_execute_refresh_new_cagg (_timescaledb_catalog.continuous_agg, _timescaledb_catalog.continuous_agg_migrate_plan_step); -DROP PROCEDURE IF EXISTS _timescaledb_internal.cagg_migrate_execute_copy_data (_timescaledb_catalog.continuous_agg, _timescaledb_catalog.continuous_agg_migrate_plan_step); -DROP PROCEDURE IF EXISTS _timescaledb_functions.cagg_migrate_execute_copy_data (_timescaledb_catalog.continuous_agg, _timescaledb_catalog.continuous_agg_migrate_plan_step); -DROP PROCEDURE IF EXISTS _timescaledb_internal.cagg_migrate_execute_override_cagg (_timescaledb_catalog.continuous_agg, _timescaledb_catalog.continuous_agg_migrate_plan_step); -DROP PROCEDURE IF EXISTS _timescaledb_functions.cagg_migrate_execute_override_cagg (_timescaledb_catalog.continuous_agg, _timescaledb_catalog.continuous_agg_migrate_plan_step); -DROP PROCEDURE IF EXISTS _timescaledb_internal.cagg_migrate_execute_drop_old_cagg (_timescaledb_catalog.continuous_agg, _timescaledb_catalog.continuous_agg_migrate_plan_step); -DROP PROCEDURE IF EXISTS _timescaledb_functions.cagg_migrate_execute_drop_old_cagg (_timescaledb_catalog.continuous_agg, _timescaledb_catalog.continuous_agg_migrate_plan_step); - -ALTER TABLE _timescaledb_catalog.continuous_aggs_materialization_invalidation_log - DROP CONSTRAINT continuous_aggs_materialization_invalid_materialization_id_fkey; - -ALTER TABLE _timescaledb_catalog.continuous_aggs_watermark - DROP CONSTRAINT continuous_aggs_watermark_mat_hypertable_id_fkey; - -ALTER EXTENSION timescaledb - DROP TABLE _timescaledb_catalog.continuous_agg; - -CREATE TABLE _timescaledb_catalog._tmp_continuous_agg AS - SELECT - mat_hypertable_id, - raw_hypertable_id, - parent_mat_hypertable_id, - user_view_schema, - user_view_name, - partial_view_schema, - partial_view_name, - -1::bigint as bucket_width, -- -1 means variable width. Will be modified soon if not variable. - direct_view_schema, - direct_view_name, - materialized_only, - finalized - FROM - _timescaledb_catalog.continuous_agg - ORDER BY - mat_hypertable_id; - --- Migrate CAggs with fixed bucket on interval back -WITH fixed_buckets AS ( - SELECT * FROM _timescaledb_catalog.continuous_aggs_bucket_function WHERE bucket_fixed_width = true AND bucket_func::text LIKE '%time_bucket(interval%' -) -UPDATE _timescaledb_catalog._tmp_continuous_agg cagg - SET bucket_width = _timescaledb_functions.interval_to_usec(fb.bucket_width::interval) - FROM fixed_buckets fb - WHERE cagg.mat_hypertable_id = fb.mat_hypertable_id; - --- Migrate CAggs with fixed bucket on integer back -WITH fixed_buckets AS ( - SELECT * FROM _timescaledb_catalog.continuous_aggs_bucket_function WHERE bucket_fixed_width = true AND bucket_func::text NOT LIKE '%time_bucket(interval%' -) -UPDATE _timescaledb_catalog._tmp_continuous_agg cagg - SET bucket_width = fb.bucket_width::bigint - FROM fixed_buckets fb - WHERE cagg.mat_hypertable_id = fb.mat_hypertable_id; - -DELETE FROM _timescaledb_catalog.continuous_aggs_bucket_function WHERE bucket_fixed_width = true; - -DROP TABLE _timescaledb_catalog.continuous_agg; - -CREATE TABLE _timescaledb_catalog.continuous_agg ( - mat_hypertable_id integer NOT NULL, - raw_hypertable_id integer NOT NULL, - parent_mat_hypertable_id integer, - user_view_schema name NOT NULL, - user_view_name name NOT NULL, - partial_view_schema name NOT NULL, - partial_view_name name NOT NULL, - bucket_width bigint NOT NULL, - direct_view_schema name NOT NULL, - direct_view_name name NOT NULL, - materialized_only bool NOT NULL DEFAULT FALSE, - finalized bool NOT NULL DEFAULT TRUE, - -- table constraints - CONSTRAINT continuous_agg_pkey PRIMARY KEY (mat_hypertable_id), - CONSTRAINT continuous_agg_partial_view_schema_partial_view_name_key UNIQUE (partial_view_schema, partial_view_name), - CONSTRAINT continuous_agg_user_view_schema_user_view_name_key UNIQUE (user_view_schema, user_view_name), - CONSTRAINT continuous_agg_mat_hypertable_id_fkey - FOREIGN KEY (mat_hypertable_id) REFERENCES _timescaledb_catalog.hypertable (id) ON DELETE CASCADE, - CONSTRAINT continuous_agg_raw_hypertable_id_fkey - FOREIGN KEY (raw_hypertable_id) REFERENCES _timescaledb_catalog.hypertable (id) ON DELETE CASCADE, - CONSTRAINT continuous_agg_parent_mat_hypertable_id_fkey - FOREIGN KEY (parent_mat_hypertable_id) - REFERENCES _timescaledb_catalog.continuous_agg (mat_hypertable_id) ON DELETE CASCADE -); - -INSERT INTO _timescaledb_catalog.continuous_agg -SELECT * FROM _timescaledb_catalog._tmp_continuous_agg; -DROP TABLE _timescaledb_catalog._tmp_continuous_agg; - -CREATE INDEX continuous_agg_raw_hypertable_id_idx ON _timescaledb_catalog.continuous_agg (raw_hypertable_id); - -SELECT pg_catalog.pg_extension_config_dump('_timescaledb_catalog.continuous_agg', ''); - -GRANT SELECT ON TABLE _timescaledb_catalog.continuous_agg TO PUBLIC; - -ALTER TABLE _timescaledb_catalog.continuous_aggs_materialization_invalidation_log - ADD CONSTRAINT continuous_aggs_materialization_invalid_materialization_id_fkey - FOREIGN KEY (materialization_id) - REFERENCES _timescaledb_catalog.continuous_agg(mat_hypertable_id) ON DELETE CASCADE; - -ALTER TABLE _timescaledb_catalog.continuous_aggs_watermark - ADD CONSTRAINT continuous_aggs_watermark_mat_hypertable_id_fkey - FOREIGN KEY (mat_hypertable_id) - REFERENCES _timescaledb_catalog.continuous_agg (mat_hypertable_id) ON DELETE CASCADE; - -ANALYZE _timescaledb_catalog.continuous_agg; - --- --- END Rebuild the catalog table `_timescaledb_catalog.continuous_agg` --- - --- --- Rebuild the catalog table `_timescaledb_catalog.continuous_aggs_bucket_function` --- -UPDATE _timescaledb_catalog.continuous_aggs_bucket_function SET bucket_origin = '' WHERE bucket_origin IS NULL; -UPDATE _timescaledb_catalog.continuous_aggs_bucket_function SET bucket_timezone = '' WHERE bucket_timezone IS NULL; - -CREATE TABLE _timescaledb_catalog._tmp_continuous_aggs_bucket_function AS - SELECT - mat_hypertable_id, - CASE WHEN bucket_func::text like 'timescaledb_experimental%' THEN true ELSE false END, - split_part(bucket_func::regproc::text, '.', 2), - bucket_width, - bucket_origin, - bucket_timezone - FROM - _timescaledb_catalog.continuous_aggs_bucket_function - ORDER BY - mat_hypertable_id; - -ALTER EXTENSION timescaledb - DROP TABLE _timescaledb_catalog.continuous_aggs_bucket_function; - -DROP TABLE _timescaledb_catalog.continuous_aggs_bucket_function; - -CREATE TABLE _timescaledb_catalog.continuous_aggs_bucket_function ( - mat_hypertable_id integer NOT NULL, - -- The schema of the function. Equals TRUE for "timescaledb_experimental", FALSE otherwise. - experimental bool NOT NULL, - -- Name of the bucketing function, e.g. "time_bucket" or "time_bucket_ng" - name text NOT NULL, - -- `bucket_width` argument of the function, e.g. "1 month" - bucket_width text NOT NULL, - -- `origin` argument of the function provided by the user - origin text NOT NULL, - -- `timezone` argument of the function provided by the user - timezone text NOT NULL, - -- table constraints - CONSTRAINT continuous_aggs_bucket_function_pkey PRIMARY KEY (mat_hypertable_id), - CONSTRAINT continuous_aggs_bucket_function_mat_hypertable_id_fkey FOREIGN KEY (mat_hypertable_id) REFERENCES _timescaledb_catalog.hypertable (id) ON DELETE CASCADE -); - -INSERT INTO _timescaledb_catalog.continuous_aggs_bucket_function - SELECT * FROM _timescaledb_catalog._tmp_continuous_aggs_bucket_function; - -DROP TABLE _timescaledb_catalog._tmp_continuous_aggs_bucket_function; - -SELECT pg_catalog.pg_extension_config_dump('_timescaledb_catalog.continuous_aggs_bucket_function', ''); - -GRANT SELECT ON TABLE _timescaledb_catalog.continuous_aggs_bucket_function TO PUBLIC; - -ANALYZE _timescaledb_catalog.continuous_aggs_bucket_function; - --- --- End rebuild the catalog table `_timescaledb_catalog.continuous_aggs_bucket_function` --- - --- Convert _timescaledb_catalog.continuous_aggs_bucket_function.origin back to Timestamp -UPDATE _timescaledb_catalog.continuous_aggs_bucket_function - SET origin = origin::timestamptz::timestamp::text - WHERE length(origin) > 1; - --- only create stub -CREATE FUNCTION _timescaledb_functions.get_chunk_relstats(relid REGCLASS) -RETURNS TABLE(chunk_id INTEGER, hypertable_id INTEGER, num_pages INTEGER, num_tuples REAL, num_allvisible INTEGER) -AS $$BEGIN END$$ LANGUAGE plpgsql SET search_path = pg_catalog, pg_temp; - -CREATE FUNCTION _timescaledb_functions.get_chunk_colstats(relid REGCLASS) -RETURNS TABLE(chunk_id INTEGER, hypertable_id INTEGER, att_num INTEGER, nullfrac REAL, width INTEGER, distinctval REAL, slotkind INTEGER[], slotopstrings CSTRING[], slotcollations OID[], slot1numbers FLOAT4[], slot2numbers FLOAT4[], slot3numbers FLOAT4[], slot4numbers FLOAT4[], slot5numbers FLOAT4[], slotvaluetypetrings CSTRING[], slot1values CSTRING[], slot2values CSTRING[], slot3values CSTRING[], slot4values CSTRING[], slot5values CSTRING[]) -AS $$BEGIN END$$ LANGUAGE plpgsql SET search_path = pg_catalog, pg_temp; - --- --- START bgw_job_stat_history --- -DROP VIEW IF EXISTS timescaledb_information.job_errors; - -ALTER EXTENSION timescaledb - DROP VIEW timescaledb_information.job_history; - -DROP VIEW IF EXISTS timescaledb_information.job_history; - -CREATE TABLE _timescaledb_internal.job_errors ( - job_id integer not null, - pid integer, - start_time timestamptz, - finish_time timestamptz, - error_data jsonb -); - -INSERT INTO _timescaledb_internal.job_errors (job_id, pid, start_time, finish_time, error_data) -SELECT - job_id, - pid, - execution_start, - execution_finish, - data->'error_data' -FROM - _timescaledb_internal.bgw_job_stat_history -WHERE - succeeded IS FALSE -ORDER BY - job_id, execution_start; - -ALTER EXTENSION timescaledb - DROP TABLE _timescaledb_internal.bgw_job_stat_history; - -DROP TABLE IF EXISTS _timescaledb_internal.bgw_job_stat_history; - -REVOKE ALL ON _timescaledb_internal.job_errors FROM PUBLIC; - -DROP FUNCTION IF EXISTS _timescaledb_internal.policy_job_stat_history_retention(job_id integer,config jsonb); -DROP FUNCTION IF EXISTS _timescaledb_internal.policy_job_stat_history_retention_check(config jsonb); -DROP FUNCTION IF EXISTS _timescaledb_functions.policy_job_stat_history_retention(job_id integer,config jsonb); -DROP FUNCTION IF EXISTS _timescaledb_functions.policy_job_stat_history_retention_check(config jsonb); - -CREATE OR REPLACE FUNCTION _timescaledb_functions.policy_job_error_retention(job_id integer, config JSONB) RETURNS integer -LANGUAGE PLPGSQL AS -$BODY$ -DECLARE - drop_after INTERVAL; - numrows INTEGER; -BEGIN - SELECT config->>'drop_after' INTO STRICT drop_after; - WITH deleted AS - (DELETE - FROM _timescaledb_internal.job_errors - WHERE finish_time < (now() - drop_after) RETURNING *) - SELECT count(*) - FROM deleted INTO numrows; - RETURN numrows; -END; -$BODY$ SET search_path TO pg_catalog, pg_temp; - -CREATE OR REPLACE FUNCTION _timescaledb_functions.policy_job_error_retention_check(config JSONB) RETURNS VOID -LANGUAGE PLPGSQL AS -$BODY$ -DECLARE - drop_after interval; -BEGIN - IF config IS NULL THEN - RAISE EXCEPTION 'config cannot be NULL, and must contain drop_after'; - END IF; - SELECT config->>'drop_after' INTO STRICT drop_after; - IF drop_after IS NULL THEN - RAISE EXCEPTION 'drop_after interval not provided'; - END IF ; -END; -$BODY$ SET search_path TO pg_catalog, pg_temp; - -UPDATE _timescaledb_config.bgw_job SET scheduled = true WHERE id = 2; -DELETE FROM _timescaledb_config.bgw_job WHERE id = 3; - -DROP PROCEDURE IF EXISTS _timescaledb_functions.cagg_migrate_to_time_bucket(cagg REGCLASS); diff --git a/version.config b/version.config index 2467f7f9151..b8cd6ca5842 100644 --- a/version.config +++ b/version.config @@ -1,3 +1,3 @@ -version = 2.15.0-dev +version = 2.15.0 update_from_version = 2.14.2 downgrade_to_version = 2.14.2