From e0a21a060be290589e194f1a292e7dccb598e42c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Fabr=C3=ADzio=20de=20Royes=20Mello?=
 <fabriziomello@gmail.com>
Date: Mon, 27 May 2024 16:18:53 -0300
Subject: [PATCH] Release 2.15.1

This release contains bug fixes since the 2.15.0 release.
We recommend that you upgrade at the next available opportunity.

**Bugfixes**
* #6540 Segmentation fault when backfilling data with COPY into a compressed chunk
* #6858 Before update trigger not working correctly
* #6908 Fix gapfill with timezone behaviour around dst switches
* #6911 Fix dropped chunk metadata removal in update script
* #6940 Fix `pg_upgrade` failure by removing `regprocedure` from catalog table
* #6957 Fix segfault in UNION queries with ordering on compressed chunks

**Thanks**
* @DiAifU, @kiddhombre and @intermittentnrg for reporting issues with gapfill and daylight saving time
* @edgarzamora for reporting issue with update triggers
* @hongquan for reporting an issue with the update script
* @iliastsa and @SystemParadox for reporting an issue with COPY into a compressed chunk
---
 .unreleased/fix_6858                         |   2 -
 .unreleased/fix_6940                         |   1 -
 .unreleased/fix_compressed_copy_segfault     |   2 -
 .unreleased/pr_6908                          |   2 -
 .unreleased/pr_6911                          |   2 -
 .unreleased/pr_6957                          |   1 -
 .unreleased/template.release_notes_header.j2 |   2 +-
 CHANGELOG.md                                 | 103 ++++++++++++-------
 sql/CMakeLists.txt                           |   3 +-
 sql/updates/2.15.0--2.15.1.sql               |  49 +++++++++
 sql/updates/latest-dev.sql                   |  49 ---------
 version.config                               |   2 +-
 12 files changed, 118 insertions(+), 100 deletions(-)
 delete mode 100644 .unreleased/fix_6858
 delete mode 100644 .unreleased/fix_6940
 delete mode 100644 .unreleased/fix_compressed_copy_segfault
 delete mode 100644 .unreleased/pr_6908
 delete mode 100644 .unreleased/pr_6911
 delete mode 100644 .unreleased/pr_6957
 create mode 100644 sql/updates/2.15.0--2.15.1.sql

diff --git a/.unreleased/fix_6858 b/.unreleased/fix_6858
deleted file mode 100644
index df8794453..000000000
--- a/.unreleased/fix_6858
+++ /dev/null
@@ -1,2 +0,0 @@
-Fixes: #6858 Before update trigger not working correctly
-Thanks: @edgarzamora for reporting issue with update triggers
diff --git a/.unreleased/fix_6940 b/.unreleased/fix_6940
deleted file mode 100644
index 70f4bafe7..000000000
--- a/.unreleased/fix_6940
+++ /dev/null
@@ -1 +0,0 @@
-Fixes: #6940 Fix `pg_upgrade` failure by removing `regprocedure` from catalog table
diff --git a/.unreleased/fix_compressed_copy_segfault b/.unreleased/fix_compressed_copy_segfault
deleted file mode 100644
index 4146a20a6..000000000
--- a/.unreleased/fix_compressed_copy_segfault
+++ /dev/null
@@ -1,2 +0,0 @@
-Fixes: #6540 Segmentation fault when backfilling data with COPY into a compressed chunk
-Thanks: @iliastsa and @SystemParadox for reporting an issue with COPY into a compressed chunk
diff --git a/.unreleased/pr_6908 b/.unreleased/pr_6908
deleted file mode 100644
index 812eafc97..000000000
--- a/.unreleased/pr_6908
+++ /dev/null
@@ -1,2 +0,0 @@
-Fixes: #6908 Fix gapfill with timezone behaviour around dst switches
-Thanks: @DiAifU, @kiddhombre and @intermittentnrg for reporting issues with gapfill and daylight saving time
diff --git a/.unreleased/pr_6911 b/.unreleased/pr_6911
deleted file mode 100644
index 27cf97945..000000000
--- a/.unreleased/pr_6911
+++ /dev/null
@@ -1,2 +0,0 @@
-Fixes: #6911 Fix dropped chunk metadata removal in update script
-Thanks: @hongquan for reporting an issue with the update script
diff --git a/.unreleased/pr_6957 b/.unreleased/pr_6957
deleted file mode 100644
index b213f137e..000000000
--- a/.unreleased/pr_6957
+++ /dev/null
@@ -1 +0,0 @@
-Fixes: #6957 Fix segfault in UNION queries with ordering on compressed chunks
diff --git a/.unreleased/template.release_notes_header.j2 b/.unreleased/template.release_notes_header.j2
index f5d099f56..66ac22aa1 100644
--- a/.unreleased/template.release_notes_header.j2
+++ b/.unreleased/template.release_notes_header.j2
@@ -7,7 +7,7 @@
 ## {{ release_current }} ({{ release_date }})
 
 This release contains performance improvements and bug fixes since
-the {{ release_previous }} release. We recommend that you upgrade at the next
+the {{ release_previous }} release. Best practice is to upgrade at the next
 available opportunity.
 
 In addition, it includes these noteworthy features:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 667927874..273ea7f6e 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -4,10 +4,35 @@
 `psql` with the `-X` flag to prevent any `.psqlrc` commands from
 accidentally triggering the load of a previous DB version.**
 
+## 2.15.1 (2024-05-28)
+
+This release contains bug fixes since the 2.15.0 release.
+Best practice is to upgrade at the next available opportunity.
+
+**Migrating from self-hosted TimescaleDB v2.14.x and earlier**
+
+After you run `ALTER EXTENSION`, you must run [this SQL script](https://github.com/timescale/timescaledb-extras/blob/master/utils/2.15.X-fix_hypertable_foreign_keys.sql). For more details, see the following pull request [#6797](https://github.com/timescale/timescaledb/pull/6797).
+
+If you are migrating from TimescaleDB v2.15.0, no changes are required.
+
+**Bugfixes**
+* #6540: Segmentation fault when you backfill data using COPY into a compressed chunk.
+* #6858: `BEFORE UPDATE` trigger not working correctly.
+* #6908: Fix `time_bucket_gapfill()` with timezone behaviour around daylight savings time (DST) switches.
+* #6911: Fix dropped chunk metadata removal in the update script.
+* #6940: Fix `pg_upgrade` failure by removing `regprocedure` from the catalog table.
+* #6957: Fix then `segfault` in UNION queries that contain ordering on compressed chunks.
+
+**Thanks**
+* @DiAifU, @kiddhombre and @intermittentnrg for reporting the issues with gapfill and daylight saving time.
+* @edgarzamora for reporting the issue with update triggers.
+* @hongquan for reporting the issue with the update script.
+* @iliastsa and @SystemParadox for reporting the issue with COPY into a compressed chunk.
+
 ## 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
+the 2.14.2 release. Best practice is to upgrade at the next
 available opportunity.
 
 In addition, it includes these noteworthy features:
@@ -23,50 +48,52 @@ In addition, it includes these noteworthy features:
 * 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).
+**Migrating from self-hosted TimescaleDB v2.14.x and earlier**
+
+After you run `ALTER EXTENSION`, you must run [this SQL script](https://github.com/timescale/timescaledb-extras/blob/master/utils/2.15.X-fix_hypertable_foreign_keys.sql). For more details, see the following pull request [#6797](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
+* #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
+* #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
+* @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
+* @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)
 
diff --git a/sql/CMakeLists.txt b/sql/CMakeLists.txt
index c7d308d40..a18fc99ed 100644
--- a/sql/CMakeLists.txt
+++ b/sql/CMakeLists.txt
@@ -37,7 +37,8 @@ set(MOD_FILES
     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.2--2.15.0.sql)
+    updates/2.14.2--2.15.0.sql
+    updates/2.15.0--2.15.1.sql)
 
 # The downgrade file to generate a downgrade script for the current version, as
 # specified in version.config
diff --git a/sql/updates/2.15.0--2.15.1.sql b/sql/updates/2.15.0--2.15.1.sql
new file mode 100644
index 000000000..8ea90a558
--- /dev/null
+++ b/sql/updates/2.15.0--2.15.1.sql
@@ -0,0 +1,49 @@
+CREATE TABLE _timescaledb_catalog._tmp_continuous_aggs_bucket_function AS
+    SELECT
+      mat_hypertable_id,
+      bucket_func::text AS bucket_func,
+      bucket_width,
+      bucket_origin,
+      bucket_offset,
+      bucket_timezone,
+      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 text 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,
+  CONSTRAINT continuous_aggs_bucket_function_func_check CHECK (pg_catalog.to_regprocedure(bucket_func) IS DISTINCT FROM 0)
+);
+
+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;
diff --git a/sql/updates/latest-dev.sql b/sql/updates/latest-dev.sql
index 8ea90a558..e69de29bb 100644
--- a/sql/updates/latest-dev.sql
+++ b/sql/updates/latest-dev.sql
@@ -1,49 +0,0 @@
-CREATE TABLE _timescaledb_catalog._tmp_continuous_aggs_bucket_function AS
-    SELECT
-      mat_hypertable_id,
-      bucket_func::text AS bucket_func,
-      bucket_width,
-      bucket_origin,
-      bucket_offset,
-      bucket_timezone,
-      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 text 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,
-  CONSTRAINT continuous_aggs_bucket_function_func_check CHECK (pg_catalog.to_regprocedure(bucket_func) IS DISTINCT FROM 0)
-);
-
-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;
diff --git a/version.config b/version.config
index f64f78a6a..5f055f657 100644
--- a/version.config
+++ b/version.config
@@ -1,3 +1,3 @@
 version = 2.16.0-dev
-update_from_version = 2.15.0
+update_from_version = 2.15.1
 downgrade_to_version = 2.15.0