Skip to content

Fix dump/restore when chunk skipping is enabled #8211

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .unreleased/pr_8211
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixes: #8211 Fix dump/restore when chunk skipping is enabled
4 changes: 1 addition & 3 deletions scripts/test_update_from_version.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ FROM_VERSION=${FROM_VERSION:-$(grep '^previous_version ' version.config | awk '{
TO_VERSION=${TO_VERSION:-$(grep '^version ' version.config | awk '{ print $3 }')}

TEST_REPAIR=${TEST_REPAIR:-false}
TEST_VERSION=${TEST_VERSION:-v8}
TEST_VERSION=${TEST_VERSION:-v9}

OUTPUT_DIR=${OUTPUT_DIR:-update_test/${FROM_VERSION}_to_${TO_VERSION}}
PGDATA="${OUTPUT_DIR}/data"
Expand Down Expand Up @@ -135,5 +135,3 @@ if [ -f "${OUTPUT_DIR}/baseline_vs_updated.diff" ] || [ -f "${OUTPUT_DIR}/baseli
echo "Update test for ${FROM_VERSION} -> ${TO_VERSION} failed"
exit 1
fi


10 changes: 7 additions & 3 deletions scripts/test_updates.sh
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,19 @@ if [ -n "${VERSIONS}" ]; then
for version in ${VERSIONS}; do
ts_minor_version=$(echo "${version}" | awk -F. '{print $2}')

TEST_VERSION=v8

if [ "${ts_minor_version}" -ge 10 ]; then
TEST_REPAIR=true
else
TEST_REPAIR=false
fi


if [ "${ts_minor_version}" -ge 16 ]; then
TEST_VERSION=v9
else
TEST_VERSION=v8
fi

export TEST_VERSION TEST_REPAIR

FROM_VERSION=${version} "${SCRIPT_DIR}/test_update_from_version.sh"
Expand All @@ -115,4 +120,3 @@ else
fi

exit $FAIL_COUNT

2 changes: 1 addition & 1 deletion sql/pre_install/tables.sql
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ SELECT pg_catalog.pg_extension_config_dump('_timescaledb_catalog.chunk_index', '
CREATE TABLE _timescaledb_catalog.chunk_column_stats (
id serial NOT NULL,
hypertable_id integer NOT NULL,
chunk_id integer NOT NULL,
chunk_id integer NULL,
column_name name NOT NULL,
range_start bigint NOT NULL,
range_end bigint NOT NULL,
Expand Down
8 changes: 7 additions & 1 deletion sql/updates/latest-dev.sql
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,10 @@ AS $$
BEGIN
-- empty body
END;
$$ LANGUAGE PLPGSQL;
$$ LANGUAGE PLPGSQL;

-- Make chunk_id use NULL to mark special entries instead of 0
-- (Invalid chunk) since that doesn't work with the FK constraint on
-- chunk_id.
ALTER TABLE _timescaledb_catalog.chunk_column_stats ALTER COLUMN chunk_id DROP NOT NULL;
UPDATE _timescaledb_catalog.chunk_column_stats SET chunk_id = NULL WHERE chunk_id = 0;
9 changes: 9 additions & 0 deletions sql/updates/reverse-dev.sql
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,12 @@ BEGIN
-- empty body
END;
$$ LANGUAGE PLPGSQL;

-- Add back the chunk_column_stats NOT NULL constraint. But first
-- delete all entries with with NULL since they will no longer be
-- allowed. Note that it is not possible to revert chunk_id back to 0
-- because it will violate the FK constraint. Removing the entries
-- effectively means that collecting column stats for those columns
-- will be disabled. It can be enabled again after downgrade.
DELETE FROM _timescaledb_catalog.chunk_column_stats WHERE chunk_id IS NULL;
ALTER TABLE _timescaledb_catalog.chunk_column_stats ALTER COLUMN chunk_id SET NOT NULL;
Loading
Loading