Skip to content

Commit

Permalink
Fix _timescaledb_functions.remove_dropped_chunk_metadata
Browse files Browse the repository at this point in the history
The removal function would only remove chunk_constraints that are
part of dimension constraints. This patch changes it to remove all
constraints of a chunk.
  • Loading branch information
svenklemm committed May 21, 2024
1 parent ec33c15 commit f9ccf1b
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .unreleased/pr_6911
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fixes: #6911 Fix dropped chunk metadata removal in update script
Thanks: @hongquan for reporting an issue with the update script
4 changes: 4 additions & 0 deletions sql/maintenance_utils.sql
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ BEGIN
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
Expand All @@ -149,6 +150,9 @@ BEGIN
USING _dimension_slice_remove
WHERE chunk_constraint.dimension_slice_id = _dimension_slice_remove.id;

DELETE FROM _timescaledb_catalog.chunk_constraint
WHERE chunk_constraint.chunk_id = _chunk_id;

DELETE FROM _timescaledb_internal.bgw_policy_chunk_stats
WHERE bgw_policy_chunk_stats.chunk_id = _chunk_id;

Expand Down
4 changes: 4 additions & 0 deletions sql/updates/2.14.2--2.15.0.sql
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ BEGIN
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
Expand All @@ -54,6 +55,9 @@ BEGIN
USING _dimension_slice_remove
WHERE chunk_constraint.dimension_slice_id = _dimension_slice_remove.id;

DELETE FROM _timescaledb_catalog.chunk_constraint
WHERE chunk_constraint.chunk_id = _chunk_id;

DELETE FROM _timescaledb_internal.bgw_policy_chunk_stats
WHERE bgw_policy_chunk_stats.chunk_id = _chunk_id;

Expand Down

0 comments on commit f9ccf1b

Please sign in to comment.