diff --git a/.unreleased/5655_decompression_workers.txt b/.unreleased/5655_decompression_workers.txt deleted file mode 100644 index 9a7d946ec0a..00000000000 --- a/.unreleased/5655_decompression_workers.txt +++ /dev/null @@ -1 +0,0 @@ -Implements: #5655 Improve the number of parallel workers for decompression \ No newline at end of file diff --git a/.unreleased/PR_5150 b/.unreleased/PR_5150 deleted file mode 100644 index 7a56f641af4..00000000000 --- a/.unreleased/PR_5150 +++ /dev/null @@ -1 +0,0 @@ -Implements: #5150 MERGE support on hypertables \ No newline at end of file diff --git a/.unreleased/PR_5586 b/.unreleased/PR_5586 deleted file mode 100644 index 4d9c263de73..00000000000 --- a/.unreleased/PR_5586 +++ /dev/null @@ -1 +0,0 @@ -Implements: #5586 Index scan support during UPDATE/DELETE \ No newline at end of file diff --git a/.unreleased/PR_5805 b/.unreleased/PR_5805 deleted file mode 100644 index a48ee63e57a..00000000000 --- a/.unreleased/PR_5805 +++ /dev/null @@ -1 +0,0 @@ -Implements: #5805 Make logrepl markers for (partial) decompressions diff --git a/.unreleased/PR_5839 b/.unreleased/PR_5839 deleted file mode 100644 index 31e5f8f8fe0..00000000000 --- a/.unreleased/PR_5839 +++ /dev/null @@ -1 +0,0 @@ -Implements: #5839 Support CAGG names in chunk_detailed_size diff --git a/.unreleased/PR_5852 b/.unreleased/PR_5852 deleted file mode 100644 index 2bb083c8b9b..00000000000 --- a/.unreleased/PR_5852 +++ /dev/null @@ -1 +0,0 @@ -Implements: #5852 Make set_chunk_time_interval CAGGs aware diff --git a/.unreleased/PR_5868 b/.unreleased/PR_5868 deleted file mode 100644 index 66964c04cfa..00000000000 --- a/.unreleased/PR_5868 +++ /dev/null @@ -1 +0,0 @@ -Implements: #5868 Allows ALTER TABLE ... REPLICA IDENTITY (FULL|INDEX) on materialized hypertables (continuoues aggregates) diff --git a/.unreleased/PR_5930 b/.unreleased/PR_5930 deleted file mode 100644 index 599e2c28976..00000000000 --- a/.unreleased/PR_5930 +++ /dev/null @@ -1,2 +0,0 @@ -Fixes: #5930 Add update tests with weird user names for jobs -Thanks: @mrksngl for discovering and reporting the issue diff --git a/.unreleased/PR_6036 b/.unreleased/PR_6036 deleted file mode 100644 index 313457f45fb..00000000000 --- a/.unreleased/PR_6036 +++ /dev/null @@ -1 +0,0 @@ -Implements: #6036 Add API function for updating OSM chunk ranges diff --git a/.unreleased/PR_6067 b/.unreleased/PR_6067 deleted file mode 100644 index 18229a13ed2..00000000000 --- a/.unreleased/PR_6067 +++ /dev/null @@ -1 +0,0 @@ -Implements: #6067 Adds drop_chunks hook for OSM diff --git a/.unreleased/PR_6081 b/.unreleased/PR_6081 deleted file mode 100644 index db672d882a5..00000000000 --- a/.unreleased/PR_6081 +++ /dev/null @@ -1,2 +0,0 @@ -Fixes: #6081 Improve compressed DML datatype handling - diff --git a/.unreleased/PR_6106 b/.unreleased/PR_6106 deleted file mode 100644 index 2f19ebe3ca1..00000000000 --- a/.unreleased/PR_6106 +++ /dev/null @@ -1 +0,0 @@ -Fixes: #6106 incorrect pointer usage in OSM hook callback diff --git a/.unreleased/bugfix_5562 b/.unreleased/bugfix_5562 deleted file mode 100644 index 3de323f9e1e..00000000000 --- a/.unreleased/bugfix_5562 +++ /dev/null @@ -1 +0,0 @@ -Fixes: #5562 Move trigger functions to _timescaledb_functions schema diff --git a/.unreleased/bugfix_5734 b/.unreleased/bugfix_5734 deleted file mode 100644 index 17415ae00b2..00000000000 --- a/.unreleased/bugfix_5734 +++ /dev/null @@ -1,5 +0,0 @@ -Implements: #5860 Rectifies interval calculation for Heirarchical CAggs - -Fixes: #5734 - -Thanks: @lukaskirner diff --git a/.unreleased/bugfix_5872 b/.unreleased/bugfix_5872 deleted file mode 100644 index 57742d0553a..00000000000 --- a/.unreleased/bugfix_5872 +++ /dev/null @@ -1 +0,0 @@ -Fixes: #5872 Fix duplicates on partially compressed chunk reads diff --git a/.unreleased/bugfix_5892 b/.unreleased/bugfix_5892 deleted file mode 100644 index 78ac805eede..00000000000 --- a/.unreleased/bugfix_5892 +++ /dev/null @@ -1,2 +0,0 @@ -Implements: #5894 Check unique indexes when enabling compression -Fixes: #5892 diff --git a/.unreleased/bugfix_5909 b/.unreleased/bugfix_5909 deleted file mode 100644 index b10042d6a2c..00000000000 --- a/.unreleased/bugfix_5909 +++ /dev/null @@ -1 +0,0 @@ -Implements: #5909 CREATE INDEX ONLY ON hypertable creates index on chunks diff --git a/.unreleased/bugfix_5918 b/.unreleased/bugfix_5918 deleted file mode 100644 index f33bd53bd4a..00000000000 --- a/.unreleased/bugfix_5918 +++ /dev/null @@ -1,3 +0,0 @@ -Fixes: #5918 Fix crash in COPY from program returning error - -Thanks: @alexanderlaw diff --git a/.unreleased/bugfix_5951 b/.unreleased/bugfix_5951 deleted file mode 100644 index f6b1216adf0..00000000000 --- a/.unreleased/bugfix_5951 +++ /dev/null @@ -1,4 +0,0 @@ -Implements: #5951 _timescaledb_internal.create_compressed_chunk doesn't account for existing uncompressed rows - -Fixes: #5946 - diff --git a/.unreleased/bugfix_5990 b/.unreleased/bugfix_5990 deleted file mode 100644 index 39513242393..00000000000 --- a/.unreleased/bugfix_5990 +++ /dev/null @@ -1 +0,0 @@ -Fixes: #5990 Place data in first/last function in correct mctx diff --git a/.unreleased/bugfix_5991 b/.unreleased/bugfix_5991 deleted file mode 100644 index 96dc1b67ec3..00000000000 --- a/.unreleased/bugfix_5991 +++ /dev/null @@ -1,2 +0,0 @@ -Fixes: #5991 Call eq_func correctly in time_bucket_gapfill -Thanks: @willsbit for reporting a crash in time_bucket_gapfill diff --git a/.unreleased/bugfix_6015 b/.unreleased/bugfix_6015 deleted file mode 100644 index d8d7f0aabb9..00000000000 --- a/.unreleased/bugfix_6015 +++ /dev/null @@ -1 +0,0 @@ -Fixes: #6015 Correct row count in EXPLAIN ANALYZE INSERT .. ON CONFLICT output diff --git a/.unreleased/bugfix_6024 b/.unreleased/bugfix_6024 deleted file mode 100644 index f331b36a67d..00000000000 --- a/.unreleased/bugfix_6024 +++ /dev/null @@ -1,3 +0,0 @@ -Fixes: #6035 UPDATE on compressed chunk crashes server - -Thanks: @alexanderlaw for reporting this issue on server crash diff --git a/.unreleased/bugfix_6037 b/.unreleased/bugfix_6037 deleted file mode 100644 index 86f413b8495..00000000000 --- a/.unreleased/bugfix_6037 +++ /dev/null @@ -1,3 +0,0 @@ -Fixes: #6045 Fix segfault in set_integer_now_func - -Thanks: @alexanderlaw for reporting this issue in set_integer_now_func diff --git a/.unreleased/bugfix_6044 b/.unreleased/bugfix_6044 deleted file mode 100644 index f9270ad46fb..00000000000 --- a/.unreleased/bugfix_6044 +++ /dev/null @@ -1 +0,0 @@ -Fixes: #6044 Server crash when using duplicate segmentby column diff --git a/.unreleased/bugfix_6053 b/.unreleased/bugfix_6053 deleted file mode 100644 index 09a8f4fad43..00000000000 --- a/.unreleased/bugfix_6053 +++ /dev/null @@ -1 +0,0 @@ -Fixes: #6053 Function approximate_row_count returns 0 for caggs diff --git a/.unreleased/bugfix_6084 b/.unreleased/bugfix_6084 deleted file mode 100644 index f9d422aa430..00000000000 --- a/.unreleased/bugfix_6084 +++ /dev/null @@ -1,2 +0,0 @@ -Fixes: #6084 Propagate parameter changes to decompress child nodes -Thanks: @ajcanterbury for reporting a problem with lateral joins on compressed chunks diff --git a/.unreleased/bugfix_chunk_create b/.unreleased/bugfix_chunk_create deleted file mode 100644 index 93aa83f3ccb..00000000000 --- a/.unreleased/bugfix_chunk_create +++ /dev/null @@ -1 +0,0 @@ -Fixes: #5788 Chunk_create must add existing table or fail diff --git a/.unreleased/feature_5137 b/.unreleased/feature_5137 deleted file mode 100644 index df1de9a8bfa..00000000000 --- a/.unreleased/feature_5137 +++ /dev/null @@ -1 +0,0 @@ -Implements: #5137 Insert into index during chunk compression diff --git a/.unreleased/feature_5515 b/.unreleased/feature_5515 deleted file mode 100644 index edd1611b2bb..00000000000 --- a/.unreleased/feature_5515 +++ /dev/null @@ -1 +0,0 @@ -Implements: #5515 Make hypertables support replica identity diff --git a/.unreleased/feature_5596 b/.unreleased/feature_5596 deleted file mode 100644 index 45aebe0c07b..00000000000 --- a/.unreleased/feature_5596 +++ /dev/null @@ -1 +0,0 @@ -Implements: #5596 Support for partial aggregations at chunk level diff --git a/.unreleased/feature_5599 b/.unreleased/feature_5599 deleted file mode 100644 index 74a113a0c9f..00000000000 --- a/.unreleased/feature_5599 +++ /dev/null @@ -1 +0,0 @@ -Implements: #5599 Enable ChunkAppend for partially compressed chunks \ No newline at end of file diff --git a/.unreleased/feature_5758 b/.unreleased/feature_5758 deleted file mode 100644 index c3e4b2dab00..00000000000 --- a/.unreleased/feature_5758 +++ /dev/null @@ -1 +0,0 @@ -Implements: #5758 Enable altering job schedule type through `alter_job` diff --git a/.unreleased/feature_5809 b/.unreleased/feature_5809 deleted file mode 100644 index 51a1b30a450..00000000000 --- a/.unreleased/feature_5809 +++ /dev/null @@ -1 +0,0 @@ -Implements: #5809 Relax invalidation threshold table-level lock to row-level when refreshing a Continuous Aggregate diff --git a/.unreleased/feature_5875 b/.unreleased/feature_5875 deleted file mode 100644 index df37b7deea2..00000000000 --- a/.unreleased/feature_5875 +++ /dev/null @@ -1 +0,0 @@ -Implements: #5875 Add job exit status and runtime to log diff --git a/CHANGELOG.md b/CHANGELOG.md index 61939ed7ec4..8368223b5ee 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,69 @@ `psql` with the `-X` flag to prevent any `.psqlrc` commands from accidentally triggering the load of a previous DB version.** +## 2.12.0 (2023-09-27) + +This release contains performance improvements for compressed hypertables +and continuous aggregates and bug fixes since the 2.11.2 release. +We recommend that you upgrade at the next available opportunity. + +This release moves all internal functions from the _timescaleb_internal +schema into the _timescaledb_functions schema. This separates code from +internal data objects and improves security by allowing more restrictive +permissions for the code schema. If you are calling any of those internal +functions you should adjust your code as soon as possible. This version +also includes a compatibility layer that allows calling them in the old +location but that layer will be removed in 2.14.0. + +**PostgreSQL 12 support removal announcement** +Following the deprecation announcement for PostgreSQL 12 in TimescaleDB 2.10, +PostgreSQL 12 is not supported starting with TimescaleDB 2.12. +Currently supported PostgreSQL major versions are 13, 14 and 15. +PostgreSQL 16 support will be added with a following TimescaleDB release. + +**Features** +* #5137 Insert into index during chunk compression +* #5150 MERGE support on hypertables +* #5515 Make hypertables support replica identity +* #5586 Index scan support during UPDATE/DELETE on compressed hypertables +* #5596 Support for partial aggregations at chunk level +* #5599 Enable ChunkAppend for partially compressed chunks +* #5655 Improve the number of parallel workers for decompression +* #5758 Enable altering job schedule type through `alter_job` +* #5805 Make logrepl markers for (partial) decompressions +* #5809 Relax invalidation threshold table-level lock to row-level when refreshing a Continuous Aggregate +* #5839 Support CAgg names in chunk_detailed_size +* #5852 Make set_chunk_time_interval CAggs aware +* #5868 Allow ALTER TABLE ... REPLICA IDENTITY (FULL|INDEX) on materialized hypertables (continuous aggregates) +* #5875 Add job exit status and runtime to log +* #5909 CREATE INDEX ONLY ON hypertable creates index on chunks + +**Bugfixes** +* #5860 Fix interval calculation for hierarchical CAggs +* #5894 Check unique indexes when enabling compression +* #5951 _timescaledb_internal.create_compressed_chunk doesn't account for existing uncompressed rows +* #5988 Move functions to _timescaledb_functions schema +* #5788 Chunk_create must add an existing table or fail +* #5872 Fix duplicates on partially compressed chunk reads +* #5918 Fix crash in COPY from program returning error +* #5990 Place data in first/last function in correct mctx +* #5991 Call eq_func correctly in time_bucket_gapfill +* #6015 Correct row count in EXPLAIN ANALYZE INSERT .. ON CONFLICT output +* #6035 Fix server crash on UPDATE of compressed chunk +* #6044 Fix server crash when using duplicate segmentby column +* #6045 Fix segfault in set_integer_now_func +* #6053 Fix approximate_row_count for CAggs +* #6081 Improve compressed DML datatype handling +* #6084 Propagate parameter changes to decompress child nodes +* #6102 Schedule compression policy more often + +**Thanks** +* @ajcanterbury for reporting a problem with lateral joins on compressed chunks +* @alexanderlaw for reporting multiple server crashes +* @lukaskirner for reporting a bug with monthly continuous aggregates +* @mrksngl for reporting a bug with unusual user names +* @willsbit for reporting a crash in time_bucket_gapfill + ## 2.11.2 (2023-08-09) This release contains bug fixes since the 2.11.1 release. @@ -72,7 +135,6 @@ This release includes these noteworthy features: * #5584 Reduce decompression during constraint checking * #5530 Optimize compressed chunk resorting * #5639 Support sending telemetry event reports -* #5150 MERGE support on hypertables **Bugfixes** * #5396 Fix SEGMENTBY columns predicates to be pushed down diff --git a/sql/CMakeLists.txt b/sql/CMakeLists.txt index d8000b74b38..fe5b64f4dae 100644 --- a/sql/CMakeLists.txt +++ b/sql/CMakeLists.txt @@ -37,11 +37,12 @@ set(MOD_FILES updates/2.10.2--2.10.3.sql updates/2.10.3--2.11.0.sql updates/2.11.0--2.11.1.sql - updates/2.11.1--2.11.2.sql) + updates/2.11.1--2.11.2.sql + updates/2.11.2--2.12.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.12.0--2.11.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. @@ -70,7 +71,8 @@ set(OLD_REV_FILES 2.10.3--2.10.2.sql 2.11.0--2.10.3.sql 2.11.1--2.11.0.sql - 2.11.2--2.11.1.sql) + 2.11.2--2.11.1.sql + 2.12.0--2.11.2.sql) set(MODULE_PATHNAME "$libdir/timescaledb-${PROJECT_VERSION_MOD}") set(LOADER_PATHNAME "$libdir/timescaledb") diff --git a/sql/updates/2.11.2--2.12.0.sql b/sql/updates/2.11.2--2.12.0.sql new file mode 100644 index 00000000000..ca1f10bfc9b --- /dev/null +++ b/sql/updates/2.11.2--2.12.0.sql @@ -0,0 +1,327 @@ +DROP FUNCTION IF EXISTS @extschema@.alter_job( + INTEGER, + INTERVAL, + INTERVAL, + INTEGER, + INTERVAL, + BOOL, + JSONB, + TIMESTAMPTZ, + BOOL, + REGPROC +); + +CREATE FUNCTION @extschema@.alter_job( + job_id INTEGER, + schedule_interval INTERVAL = NULL, + max_runtime INTERVAL = NULL, + max_retries INTEGER = NULL, + retry_period INTERVAL = NULL, + scheduled BOOL = NULL, + config JSONB = NULL, + next_start TIMESTAMPTZ = NULL, + if_exists BOOL = FALSE, + check_config REGPROC = NULL, + fixed_schedule BOOL = NULL, + initial_start TIMESTAMPTZ = NULL, + timezone TEXT DEFAULT NULL +) +RETURNS TABLE (job_id INTEGER, schedule_interval INTERVAL, max_runtime INTERVAL, max_retries INTEGER, retry_period INTERVAL, scheduled BOOL, config JSONB, +next_start TIMESTAMPTZ, check_config TEXT, fixed_schedule BOOL, initial_start TIMESTAMPTZ, timezone TEXT) +AS '@MODULE_PATHNAME@', 'ts_job_alter' +LANGUAGE C VOLATILE; + +-- when upgrading from old versions on PG13 this function might not be present +-- since there is no ALTER FUNCTION IF EXISTS we have to work around it with a DO block +DO $$ +DECLARE + foid regprocedure; + funcs text[] = '{ + drop_dist_ht_invalidation_trigger, + subtract_integer_from_now, + get_approx_row_count, + chunk_status, + create_chunk,create_chunk_table, + freeze_chunk,unfreeze_chunk,drop_chunk, + attach_osm_table_chunk + }'; +BEGIN + FOR foid IN + SELECT oid FROM pg_proc WHERE proname = ANY(funcs) AND pronamespace = '_timescaledb_internal'::regnamespace + LOOP + EXECUTE format('ALTER FUNCTION %s SET SCHEMA _timescaledb_functions', foid); + END LOOP; +END; +$$; + +DROP FUNCTION IF EXISTS _timescaledb_internal.get_time_type(integer); + +ALTER FUNCTION _timescaledb_internal.insert_blocker() SET SCHEMA _timescaledb_functions; +ALTER FUNCTION _timescaledb_internal.continuous_agg_invalidation_trigger() SET SCHEMA _timescaledb_functions; +ALTER FUNCTION _timescaledb_internal.get_create_command(name) SET SCHEMA _timescaledb_functions; + +ALTER FUNCTION _timescaledb_internal.to_unix_microseconds(timestamptz) SET SCHEMA _timescaledb_functions; +ALTER FUNCTION _timescaledb_internal.to_timestamp(bigint) SET SCHEMA _timescaledb_functions; +ALTER FUNCTION _timescaledb_internal.to_timestamp_without_timezone(bigint) SET SCHEMA _timescaledb_functions; +ALTER FUNCTION _timescaledb_internal.to_date(bigint) SET SCHEMA _timescaledb_functions; +ALTER FUNCTION _timescaledb_internal.to_interval(bigint) SET SCHEMA _timescaledb_functions; +ALTER FUNCTION _timescaledb_internal.interval_to_usec(interval) SET SCHEMA _timescaledb_functions; +ALTER FUNCTION _timescaledb_internal.time_to_internal(anyelement) SET SCHEMA _timescaledb_functions; + +ALTER FUNCTION _timescaledb_internal.set_dist_id(uuid) SET SCHEMA _timescaledb_functions; +ALTER FUNCTION _timescaledb_internal.set_peer_dist_id(uuid) SET SCHEMA _timescaledb_functions; +ALTER FUNCTION _timescaledb_internal.validate_as_data_node() SET SCHEMA _timescaledb_functions; +ALTER FUNCTION _timescaledb_internal.show_connection_cache() SET SCHEMA _timescaledb_functions; +ALTER FUNCTION _timescaledb_internal.ping_data_node(name, interval) SET SCHEMA _timescaledb_functions; +ALTER FUNCTION _timescaledb_internal.remote_txn_heal_data_node(oid) SET SCHEMA _timescaledb_functions; + +ALTER FUNCTION _timescaledb_internal.relation_size(regclass) SET SCHEMA _timescaledb_functions; +ALTER FUNCTION _timescaledb_internal.data_node_hypertable_info(name, name, name) SET SCHEMA _timescaledb_functions; +ALTER FUNCTION _timescaledb_internal.data_node_chunk_info(name, name, name) SET SCHEMA _timescaledb_functions; +ALTER FUNCTION _timescaledb_internal.hypertable_local_size(name, name) SET SCHEMA _timescaledb_functions; +ALTER FUNCTION _timescaledb_internal.hypertable_remote_size(name, name) SET SCHEMA _timescaledb_functions; +ALTER FUNCTION _timescaledb_internal.chunks_local_size(name, name) SET SCHEMA _timescaledb_functions; +ALTER FUNCTION _timescaledb_internal.chunks_remote_size(name, name) SET SCHEMA _timescaledb_functions; +ALTER FUNCTION _timescaledb_internal.range_value_to_pretty(bigint, regtype) SET SCHEMA _timescaledb_functions; +ALTER FUNCTION _timescaledb_internal.data_node_compressed_chunk_stats(name, name, name) SET SCHEMA _timescaledb_functions; +ALTER FUNCTION _timescaledb_internal.compressed_chunk_local_stats(name, name) SET SCHEMA _timescaledb_functions; +ALTER FUNCTION _timescaledb_internal.compressed_chunk_remote_stats(name, name) SET SCHEMA _timescaledb_functions; +ALTER FUNCTION _timescaledb_internal.indexes_local_size(name, name) SET SCHEMA _timescaledb_functions; +ALTER FUNCTION _timescaledb_internal.data_node_index_size(name, name, name) SET SCHEMA _timescaledb_functions; +ALTER FUNCTION _timescaledb_internal.indexes_remote_size(name, name, name) SET SCHEMA _timescaledb_functions; + +ALTER FUNCTION _timescaledb_internal.generate_uuid() SET SCHEMA _timescaledb_functions; +ALTER FUNCTION _timescaledb_internal.get_git_commit() SET SCHEMA _timescaledb_functions; +ALTER FUNCTION _timescaledb_internal.get_os_info() SET SCHEMA _timescaledb_functions; +ALTER FUNCTION _timescaledb_internal.tsl_loaded() SET SCHEMA _timescaledb_functions; + +ALTER FUNCTION _timescaledb_internal.calculate_chunk_interval(int, bigint, bigint) SET SCHEMA _timescaledb_functions; +ALTER FUNCTION _timescaledb_internal.chunks_in(record, integer[]) SET SCHEMA _timescaledb_functions; +ALTER FUNCTION _timescaledb_internal.chunk_id_from_relid(oid) SET SCHEMA _timescaledb_functions; +ALTER FUNCTION _timescaledb_internal.show_chunk(regclass) SET SCHEMA _timescaledb_functions; +ALTER FUNCTION _timescaledb_internal.set_chunk_default_data_node(regclass, name) SET SCHEMA _timescaledb_functions; +ALTER FUNCTION _timescaledb_internal.get_chunk_relstats(regclass) SET SCHEMA _timescaledb_functions; +ALTER FUNCTION _timescaledb_internal.get_chunk_colstats(regclass) SET SCHEMA _timescaledb_functions; + +UPDATE _timescaledb_catalog.hypertable SET chunk_sizing_func_schema = '_timescaledb_functions' WHERE chunk_sizing_func_schema = '_timescaledb_internal' AND chunk_sizing_func_name = 'calculate_chunk_interval'; + +DO $$ +DECLARE + foid regprocedure; + kind text; + funcs text[] = '{ + policy_compression_check,policy_compression_execute,policy_compression, + policy_job_error_retention_check,policy_job_error_retention, + policy_recompression, + policy_refresh_continuous_aggregate_check,policy_refresh_continuous_aggregate, + policy_reorder_check,policy_reorder,policy_retention_check,policy_retention, + + cagg_watermark, cagg_watermark_materialized, + cagg_migrate_plan_exists, cagg_migrate_pre_validation, cagg_migrate_create_plan, cagg_migrate_execute_create_new_cagg, + cagg_migrate_execute_disable_policies, cagg_migrate_execute_enable_policies, cagg_migrate_execute_copy_policies, + cagg_migrate_execute_refresh_new_cagg, cagg_migrate_execute_copy_data, cagg_migrate_execute_override_cagg, + cagg_migrate_execute_drop_old_cagg, cagg_migrate_execute_plan, + + finalize_agg, + + hypertable_invalidation_log_delete, invalidation_cagg_log_add_entry, invalidation_hyper_log_add_entry, + invalidation_process_cagg_log, invalidation_process_hypertable_log, materialization_invalidation_log_delete, + + alter_job_set_hypertable_id, + + create_compressed_chunk, get_compressed_chunk_index_for_recompression, recompress_chunk_segmentwise, + chunk_drop_replica, chunk_index_clone, chunk_index_replace, create_chunk_replica_table, drop_stale_chunks, + chunk_constraint_add_table_constraint, hypertable_constraint_add_table_fk_constraint, + health, wait_subscription_sync + }'; +BEGIN + FOR foid, kind IN + SELECT oid, + CASE + WHEN prokind = 'f' THEN 'FUNCTION' + WHEN prokind = 'a' THEN 'AGGREGATE' + ELSE 'PROCEDURE' + END + FROM pg_proc WHERE proname = ANY(funcs) AND pronamespace = '_timescaledb_internal'::regnamespace + LOOP + EXECUTE format('ALTER %s %s SET SCHEMA _timescaledb_functions', kind, foid); + END LOOP; +END; +$$; + +UPDATE _timescaledb_config.bgw_job SET proc_schema = '_timescaledb_functions' WHERE proc_schema = '_timescaledb_internal'; +UPDATE _timescaledb_config.bgw_job SET check_schema = '_timescaledb_functions' WHERE check_schema = '_timescaledb_internal'; + +ALTER FUNCTION _timescaledb_internal.start_background_workers() SET SCHEMA _timescaledb_functions; +ALTER FUNCTION _timescaledb_internal.stop_background_workers() SET SCHEMA _timescaledb_functions; +ALTER FUNCTION _timescaledb_internal.restart_background_workers() SET SCHEMA _timescaledb_functions; + +ALTER FUNCTION _timescaledb_internal.process_ddl_event() SET SCHEMA _timescaledb_functions; + +ALTER FUNCTION _timescaledb_internal.get_partition_for_key(val anyelement) SET SCHEMA _timescaledb_functions; +ALTER FUNCTION _timescaledb_internal.get_partition_hash(val anyelement) SET SCHEMA _timescaledb_functions; + +UPDATE _timescaledb_catalog.dimension SET partitioning_func_schema = '_timescaledb_functions' WHERE partitioning_func_schema = '_timescaledb_internal' AND partitioning_func IN ('get_partition_for_key','get_partition_hash'); + +ALTER FUNCTION _timescaledb_internal.finalize_agg_ffunc(internal,text,name,name,name[],bytea,anyelement) SET SCHEMA _timescaledb_functions; +ALTER FUNCTION _timescaledb_internal.finalize_agg_sfunc(internal,text,name,name,name[],bytea,anyelement) SET SCHEMA _timescaledb_functions; +ALTER FUNCTION _timescaledb_internal.partialize_agg(anyelement) SET SCHEMA _timescaledb_functions; + +-- Fix osm chunk ranges +UPDATE _timescaledb_catalog.dimension_slice ds + SET range_start = 9223372036854775806 +FROM _timescaledb_catalog.chunk_constraint cc +INNER JOIN _timescaledb_catalog.chunk c ON c.id = cc.chunk_id AND c.osm_chunk +WHERE cc.dimension_slice_id = ds.id AND ds.range_start <> 9223372036854775806; + +-- OSM support - table must be rebuilt to ensure consistent attribute numbers +-- we cannot just ALTER TABLE .. ADD COLUMN +ALTER TABLE _timescaledb_config.bgw_job + DROP CONSTRAINT bgw_job_hypertable_id_fkey; +ALTER TABLE _timescaledb_catalog.chunk + DROP CONSTRAINT chunk_hypertable_id_fkey; +ALTER TABLE _timescaledb_catalog.chunk_index + DROP CONSTRAINT chunk_index_hypertable_id_fkey; +ALTER TABLE _timescaledb_catalog.continuous_agg + DROP CONSTRAINT continuous_agg_mat_hypertable_id_fkey, + DROP CONSTRAINT continuous_agg_raw_hypertable_id_fkey; +ALTER TABLE _timescaledb_catalog.continuous_aggs_bucket_function + DROP CONSTRAINT continuous_aggs_bucket_function_mat_hypertable_id_fkey; +ALTER TABLE _timescaledb_catalog.continuous_aggs_invalidation_threshold + DROP CONSTRAINT continuous_aggs_invalidation_threshold_hypertable_id_fkey; +ALTER TABLE _timescaledb_catalog.dimension + DROP CONSTRAINT dimension_hypertable_id_fkey; +ALTER TABLE _timescaledb_catalog.hypertable + DROP CONSTRAINT hypertable_compressed_hypertable_id_fkey; +ALTER TABLE _timescaledb_catalog.hypertable_compression + DROP CONSTRAINT hypertable_compression_hypertable_id_fkey; +ALTER TABLE _timescaledb_catalog.hypertable_data_node + DROP CONSTRAINT hypertable_data_node_hypertable_id_fkey; +ALTER TABLE _timescaledb_catalog.tablespace + DROP CONSTRAINT tablespace_hypertable_id_fkey; + +DROP VIEW IF EXISTS timescaledb_information.hypertables; +DROP VIEW IF EXISTS timescaledb_information.job_stats; +DROP VIEW IF EXISTS timescaledb_information.jobs; +DROP VIEW IF EXISTS timescaledb_information.continuous_aggregates; +DROP VIEW IF EXISTS timescaledb_information.chunks; +DROP VIEW IF EXISTS timescaledb_information.dimensions; +DROP VIEW IF EXISTS timescaledb_information.compression_settings; +DROP VIEW IF EXISTS _timescaledb_internal.hypertable_chunk_local_size; +DROP VIEW IF EXISTS _timescaledb_internal.compressed_chunk_stats; +DROP VIEW IF EXISTS timescaledb_experimental.chunk_replication_status; +DROP VIEW IF EXISTS timescaledb_experimental.policies; + +-- recreate table +CREATE TABLE _timescaledb_catalog.hypertable_tmp AS SELECT * FROM _timescaledb_catalog.hypertable; +CREATE TABLE _timescaledb_catalog.tmp_hypertable_seq_value AS SELECT last_value, is_called FROM _timescaledb_catalog.hypertable_id_seq; + +ALTER EXTENSION timescaledb DROP TABLE _timescaledb_catalog.hypertable; +ALTER EXTENSION timescaledb DROP SEQUENCE _timescaledb_catalog.hypertable_id_seq; + +SET timescaledb.restoring = on; -- must disable the hooks otherwise we can't do anything without the table _timescaledb_catalog.hypertable + +DROP TABLE _timescaledb_catalog.hypertable; + +CREATE SEQUENCE _timescaledb_catalog.hypertable_id_seq MINVALUE 1; +SELECT setval('_timescaledb_catalog.hypertable_id_seq', last_value, is_called) FROM _timescaledb_catalog.tmp_hypertable_seq_value; +DROP TABLE _timescaledb_catalog.tmp_hypertable_seq_value; + +CREATE TABLE _timescaledb_catalog.hypertable ( + id INTEGER PRIMARY KEY NOT NULL DEFAULT nextval('_timescaledb_catalog.hypertable_id_seq'), + schema_name name NOT NULL, + table_name name NOT NULL, + associated_schema_name name NOT NULL, + associated_table_prefix name NOT NULL, + num_dimensions smallint NOT NULL, + chunk_sizing_func_schema name NOT NULL, + chunk_sizing_func_name name NOT NULL, + chunk_target_size bigint NOT NULL, -- size in bytes + compression_state smallint NOT NULL DEFAULT 0, + compressed_hypertable_id integer, + replication_factor smallint NULL, + status integer NOT NULL DEFAULT 0 +); + +SET timescaledb.restoring = off; + +INSERT INTO _timescaledb_catalog.hypertable ( + id, + schema_name, + table_name, + associated_schema_name, + associated_table_prefix, + num_dimensions, + chunk_sizing_func_schema, + chunk_sizing_func_name, + chunk_target_size, + compression_state, + compressed_hypertable_id, + replication_factor +) +SELECT + id, + schema_name, + table_name, + associated_schema_name, + associated_table_prefix, + num_dimensions, + chunk_sizing_func_schema, + chunk_sizing_func_name, + chunk_target_size, + compression_state, + compressed_hypertable_id, + replication_factor +FROM + _timescaledb_catalog.hypertable_tmp +ORDER BY id; + +UPDATE _timescaledb_catalog.hypertable h +SET status = 3 +WHERE EXISTS ( + SELECT FROM _timescaledb_catalog.chunk c WHERE c.osm_chunk AND c.hypertable_id = h.id +); + +ALTER SEQUENCE _timescaledb_catalog.hypertable_id_seq OWNED BY _timescaledb_catalog.hypertable.id; +SELECT pg_catalog.pg_extension_config_dump('_timescaledb_catalog.hypertable', 'WHERE id >= 1'); +SELECT pg_catalog.pg_extension_config_dump('_timescaledb_catalog.hypertable_id_seq', ''); + +GRANT SELECT ON _timescaledb_catalog.hypertable TO PUBLIC; +GRANT SELECT ON _timescaledb_catalog.hypertable_id_seq TO PUBLIC; + +DROP TABLE _timescaledb_catalog.hypertable_tmp; +-- now add any constraints +ALTER TABLE _timescaledb_catalog.hypertable + ADD CONSTRAINT hypertable_associated_schema_name_associated_table_prefix_key UNIQUE (associated_schema_name, associated_table_prefix), + ADD CONSTRAINT hypertable_table_name_schema_name_key UNIQUE (table_name, schema_name), + ADD CONSTRAINT hypertable_schema_name_check CHECK (schema_name != '_timescaledb_catalog'), + ADD CONSTRAINT hypertable_dim_compress_check CHECK (num_dimensions > 0 OR compression_state = 2), + ADD CONSTRAINT hypertable_chunk_target_size_check CHECK (chunk_target_size >= 0), + ADD CONSTRAINT hypertable_compress_check CHECK ( (compression_state = 0 OR compression_state = 1 ) OR (compression_state = 2 AND compressed_hypertable_id IS NULL)), + ADD CONSTRAINT hypertable_replication_factor_check CHECK (replication_factor > 0 OR replication_factor = -1), + ADD CONSTRAINT hypertable_compressed_hypertable_id_fkey FOREIGN KEY (compressed_hypertable_id) REFERENCES _timescaledb_catalog.hypertable (id); + +GRANT SELECT ON TABLE _timescaledb_catalog.hypertable TO PUBLIC; + +-- 3. reestablish constraints on other tables +ALTER TABLE _timescaledb_config.bgw_job + ADD CONSTRAINT bgw_job_hypertable_id_fkey FOREIGN KEY (hypertable_id) REFERENCES _timescaledb_catalog.hypertable(id) ON DELETE CASCADE; +ALTER TABLE _timescaledb_catalog.chunk + ADD CONSTRAINT chunk_hypertable_id_fkey FOREIGN KEY (hypertable_id) REFERENCES _timescaledb_catalog.hypertable(id); +ALTER TABLE _timescaledb_catalog.chunk_index + ADD CONSTRAINT chunk_index_hypertable_id_fkey FOREIGN KEY (hypertable_id) REFERENCES _timescaledb_catalog.hypertable(id) ON DELETE CASCADE; +ALTER TABLE _timescaledb_catalog.continuous_agg + ADD CONSTRAINT continuous_agg_mat_hypertable_id_fkey FOREIGN KEY (mat_hypertable_id) REFERENCES _timescaledb_catalog.hypertable(id) ON DELETE CASCADE, + ADD CONSTRAINT continuous_agg_raw_hypertable_id_fkey FOREIGN KEY (raw_hypertable_id) REFERENCES _timescaledb_catalog.hypertable(id) ON DELETE CASCADE; +ALTER TABLE _timescaledb_catalog.continuous_aggs_bucket_function + ADD CONSTRAINT continuous_aggs_bucket_function_mat_hypertable_id_fkey FOREIGN KEY (mat_hypertable_id) REFERENCES _timescaledb_catalog.hypertable(id) ON DELETE CASCADE; +ALTER TABLE _timescaledb_catalog.continuous_aggs_invalidation_threshold + ADD CONSTRAINT continuous_aggs_invalidation_threshold_hypertable_id_fkey FOREIGN KEY (hypertable_id) REFERENCES _timescaledb_catalog.hypertable(id) ON DELETE CASCADE; +ALTER TABLE _timescaledb_catalog.dimension + ADD CONSTRAINT dimension_hypertable_id_fkey FOREIGN KEY (hypertable_id) REFERENCES _timescaledb_catalog.hypertable(id) ON DELETE CASCADE; +ALTER TABLE _timescaledb_catalog.hypertable_compression + ADD CONSTRAINT hypertable_compression_hypertable_id_fkey FOREIGN KEY (hypertable_id) REFERENCES _timescaledb_catalog.hypertable(id) ON DELETE CASCADE; +ALTER TABLE _timescaledb_catalog.hypertable_data_node + ADD CONSTRAINT hypertable_data_node_hypertable_id_fkey FOREIGN KEY (hypertable_id) REFERENCES _timescaledb_catalog.hypertable(id); +ALTER TABLE _timescaledb_catalog.tablespace + ADD CONSTRAINT tablespace_hypertable_id_fkey FOREIGN KEY (hypertable_id) REFERENCES _timescaledb_catalog.hypertable(id) ON DELETE CASCADE; diff --git a/sql/updates/2.12.0--2.11.2.sql b/sql/updates/2.12.0--2.11.2.sql new file mode 100644 index 00000000000..0e4b8b779eb --- /dev/null +++ b/sql/updates/2.12.0--2.11.2.sql @@ -0,0 +1,439 @@ + +-- remove compatibility wrapper functions +-- this needs to happen before we move the actual functions back into _timescaledb_internal +DROP FUNCTION _timescaledb_internal.alter_job_set_hypertable_id(integer,regclass); +DROP FUNCTION _timescaledb_internal.attach_osm_table_chunk(regclass,regclass); +DROP FUNCTION _timescaledb_internal.cagg_migrate_plan_exists(integer); +DROP FUNCTION _timescaledb_internal.cagg_migrate_pre_validation(text,text,text); +DROP FUNCTION _timescaledb_internal.cagg_watermark(integer); +DROP FUNCTION _timescaledb_internal.cagg_watermark_materialized(integer); +DROP FUNCTION _timescaledb_internal.calculate_chunk_interval(integer,bigint,bigint); +DROP FUNCTION _timescaledb_internal.chunk_constraint_add_table_constraint(_timescaledb_catalog.chunk_constraint); +DROP FUNCTION _timescaledb_internal.chunk_drop_replica(regclass,name); +DROP FUNCTION _timescaledb_internal.chunk_id_from_relid(oid); +DROP FUNCTION _timescaledb_internal.chunk_index_clone(oid); +DROP FUNCTION _timescaledb_internal.chunk_index_replace(oid,oid); +DROP FUNCTION _timescaledb_internal.chunk_status(regclass); +DROP FUNCTION _timescaledb_internal.chunks_in(record,integer[]); +DROP FUNCTION _timescaledb_internal.chunks_local_size(name,name); +DROP FUNCTION _timescaledb_internal.chunks_remote_size(name,name); +DROP FUNCTION _timescaledb_internal.compressed_chunk_local_stats(name,name); +DROP FUNCTION _timescaledb_internal.compressed_chunk_remote_stats(name,name); +DROP FUNCTION _timescaledb_internal.continuous_agg_invalidation_trigger(); +DROP FUNCTION _timescaledb_internal.create_chunk(regclass,jsonb,name,name,regclass); +DROP FUNCTION _timescaledb_internal.create_chunk_replica_table(regclass,name); +DROP FUNCTION _timescaledb_internal.create_chunk_table(regclass,jsonb,name,name); +DROP FUNCTION _timescaledb_internal.create_compressed_chunk(regclass,regclass,bigint,bigint,bigint,bigint,bigint,bigint,bigint,bigint); +DROP FUNCTION _timescaledb_internal.data_node_chunk_info(name,name,name); +DROP FUNCTION _timescaledb_internal.data_node_compressed_chunk_stats(name,name,name); +DROP FUNCTION _timescaledb_internal.data_node_hypertable_info(name,name,name); +DROP FUNCTION _timescaledb_internal.data_node_index_size(name,name,name); +DROP FUNCTION _timescaledb_internal.drop_chunk(regclass); +DROP FUNCTION _timescaledb_internal.drop_dist_ht_invalidation_trigger(integer); +DROP FUNCTION _timescaledb_internal.drop_stale_chunks(name,integer[]); +DROP AGGREGATE _timescaledb_internal.finalize_agg(agg_name TEXT, inner_agg_collation_schema NAME, inner_agg_collation_name NAME, inner_agg_input_types NAME[][], inner_agg_serialized_state BYTEA, return_type_dummy_val anyelement); +DROP FUNCTION _timescaledb_internal.finalize_agg_ffunc(internal, text, name, name, name[][], bytea, anyelement); +DROP FUNCTION _timescaledb_internal.finalize_agg_sfunc(internal, text, name, name, name[][], bytea, anyelement); +DROP FUNCTION _timescaledb_internal.freeze_chunk(regclass); +DROP FUNCTION _timescaledb_internal.generate_uuid(); +DROP FUNCTION _timescaledb_internal.get_approx_row_count(regclass); +DROP FUNCTION _timescaledb_internal.get_chunk_colstats(regclass); +DROP FUNCTION _timescaledb_internal.get_chunk_relstats(regclass); +DROP FUNCTION _timescaledb_internal.get_compressed_chunk_index_for_recompression(regclass); +DROP FUNCTION _timescaledb_internal.get_create_command(name); +DROP FUNCTION _timescaledb_internal.get_git_commit(); +DROP FUNCTION _timescaledb_internal.get_os_info(); +DROP FUNCTION _timescaledb_internal.get_partition_for_key(anyelement); +DROP FUNCTION _timescaledb_internal.get_partition_hash(anyelement); +DROP FUNCTION _timescaledb_internal.health(); +DROP FUNCTION _timescaledb_internal.hypertable_constraint_add_table_fk_constraint(name,name,name,integer); +DROP FUNCTION _timescaledb_internal.hypertable_invalidation_log_delete(integer); +DROP FUNCTION _timescaledb_internal.hypertable_local_size(name,name); +DROP FUNCTION _timescaledb_internal.hypertable_remote_size(name,name); +DROP FUNCTION _timescaledb_internal.indexes_local_size(name,name); +DROP FUNCTION _timescaledb_internal.indexes_remote_size(name,name,name); +DROP FUNCTION _timescaledb_internal.insert_blocker(); +DROP FUNCTION _timescaledb_internal.interval_to_usec(interval); +DROP FUNCTION _timescaledb_internal.invalidation_cagg_log_add_entry(integer,bigint,bigint); +DROP FUNCTION _timescaledb_internal.invalidation_hyper_log_add_entry(integer,bigint,bigint); +DROP FUNCTION _timescaledb_internal.invalidation_process_cagg_log(integer,integer,regtype,bigint,bigint,integer[],bigint[],bigint[]); +DROP FUNCTION _timescaledb_internal.invalidation_process_cagg_log(integer,integer,regtype,bigint,bigint,integer[],bigint[],bigint[],text[]); +DROP FUNCTION _timescaledb_internal.invalidation_process_hypertable_log(integer,integer,regtype,integer[],bigint[],bigint[]); +DROP FUNCTION _timescaledb_internal.invalidation_process_hypertable_log(integer,integer,regtype,integer[],bigint[],bigint[],text[]); +DROP FUNCTION _timescaledb_internal.materialization_invalidation_log_delete(integer); +DROP FUNCTION _timescaledb_internal.partialize_agg(anyelement); +DROP FUNCTION _timescaledb_internal.ping_data_node(name,interval); +DROP FUNCTION _timescaledb_internal.policy_compression_check(jsonb); +DROP FUNCTION _timescaledb_internal.policy_job_error_retention(integer,jsonb); +DROP FUNCTION _timescaledb_internal.policy_job_error_retention_check(jsonb); +DROP FUNCTION _timescaledb_internal.policy_refresh_continuous_aggregate_check(jsonb); +DROP FUNCTION _timescaledb_internal.policy_reorder_check(jsonb); +DROP FUNCTION _timescaledb_internal.policy_retention_check(jsonb); +DROP FUNCTION _timescaledb_internal.process_ddl_event(); +DROP FUNCTION _timescaledb_internal.range_value_to_pretty(bigint,regtype); +DROP FUNCTION _timescaledb_internal.recompress_chunk_segmentwise(regclass,boolean); +DROP FUNCTION _timescaledb_internal.relation_size(regclass); +DROP FUNCTION _timescaledb_internal.remote_txn_heal_data_node(oid); +DROP FUNCTION _timescaledb_internal.set_chunk_default_data_node(regclass,name); +DROP FUNCTION _timescaledb_internal.set_dist_id(uuid); +DROP FUNCTION _timescaledb_internal.set_peer_dist_id(uuid); +DROP FUNCTION _timescaledb_internal.show_chunk(regclass); +DROP FUNCTION _timescaledb_internal.show_connection_cache(); +DROP FUNCTION _timescaledb_internal.start_background_workers(); +DROP FUNCTION _timescaledb_internal.stop_background_workers(); +DROP FUNCTION _timescaledb_internal.subtract_integer_from_now(regclass,bigint); +DROP FUNCTION _timescaledb_internal.time_to_internal(anyelement); +DROP FUNCTION _timescaledb_internal.to_date(bigint); +DROP FUNCTION _timescaledb_internal.to_interval(bigint); +DROP FUNCTION _timescaledb_internal.to_timestamp(bigint); +DROP FUNCTION _timescaledb_internal.to_timestamp_without_timezone(bigint); +DROP FUNCTION _timescaledb_internal.to_unix_microseconds(timestamp with time zone); +DROP FUNCTION _timescaledb_internal.tsl_loaded(); +DROP FUNCTION _timescaledb_internal.unfreeze_chunk(regclass); +DROP FUNCTION _timescaledb_internal.validate_as_data_node(); +DROP PROCEDURE _timescaledb_internal.cagg_migrate_create_plan(_timescaledb_catalog.continuous_agg,text,boolean,boolean); +DROP PROCEDURE _timescaledb_internal.cagg_migrate_execute_copy_data(_timescaledb_catalog.continuous_agg,_timescaledb_catalog.continuous_agg_migrate_plan_step); +DROP PROCEDURE _timescaledb_internal.cagg_migrate_execute_copy_policies(_timescaledb_catalog.continuous_agg,_timescaledb_catalog.continuous_agg_migrate_plan_step); +DROP PROCEDURE _timescaledb_internal.cagg_migrate_execute_create_new_cagg(_timescaledb_catalog.continuous_agg,_timescaledb_catalog.continuous_agg_migrate_plan_step); +DROP PROCEDURE _timescaledb_internal.cagg_migrate_execute_disable_policies(_timescaledb_catalog.continuous_agg,_timescaledb_catalog.continuous_agg_migrate_plan_step); +DROP PROCEDURE _timescaledb_internal.cagg_migrate_execute_drop_old_cagg(_timescaledb_catalog.continuous_agg,_timescaledb_catalog.continuous_agg_migrate_plan_step); +DROP PROCEDURE _timescaledb_internal.cagg_migrate_execute_enable_policies(_timescaledb_catalog.continuous_agg,_timescaledb_catalog.continuous_agg_migrate_plan_step); +DROP PROCEDURE _timescaledb_internal.cagg_migrate_execute_override_cagg(_timescaledb_catalog.continuous_agg,_timescaledb_catalog.continuous_agg_migrate_plan_step); +DROP PROCEDURE _timescaledb_internal.cagg_migrate_execute_plan(_timescaledb_catalog.continuous_agg); +DROP PROCEDURE _timescaledb_internal.cagg_migrate_execute_refresh_new_cagg(_timescaledb_catalog.continuous_agg,_timescaledb_catalog.continuous_agg_migrate_plan_step); +DROP PROCEDURE _timescaledb_internal.policy_compression(integer,jsonb); +DROP PROCEDURE _timescaledb_internal.policy_compression_execute(integer,integer,anyelement,integer,boolean,boolean); +DROP PROCEDURE _timescaledb_internal.policy_recompression(integer,jsonb); +DROP PROCEDURE _timescaledb_internal.policy_refresh_continuous_aggregate(integer,jsonb); +DROP PROCEDURE _timescaledb_internal.policy_reorder(integer,jsonb); +DROP PROCEDURE _timescaledb_internal.policy_retention(integer,jsonb); +DROP PROCEDURE _timescaledb_internal.wait_subscription_sync(name,name,integer,numeric); + +DROP FUNCTION IF EXISTS @extschema@.alter_job( + INTEGER, + INTERVAL, + INTERVAL, + INTEGER, + INTERVAL, + BOOL, + JSONB, + TIMESTAMPTZ, + BOOL, + REGPROC, + BOOL, + TIMESTAMPTZ, + TEXT +); + +CREATE FUNCTION @extschema@.alter_job( + job_id INTEGER, + schedule_interval INTERVAL = NULL, + max_runtime INTERVAL = NULL, + max_retries INTEGER = NULL, + retry_period INTERVAL = NULL, + scheduled BOOL = NULL, + config JSONB = NULL, + next_start TIMESTAMPTZ = NULL, + if_exists BOOL = FALSE, + check_config REGPROC = NULL +) +RETURNS TABLE (job_id INTEGER, schedule_interval INTERVAL, max_runtime INTERVAL, max_retries INTEGER, retry_period INTERVAL, scheduled BOOL, config JSONB, +next_start TIMESTAMPTZ, check_config TEXT) +AS '@MODULE_PATHNAME@', 'ts_job_alter' +LANGUAGE C VOLATILE; + +ALTER FUNCTION _timescaledb_functions.insert_blocker() SET SCHEMA _timescaledb_internal; +ALTER FUNCTION _timescaledb_functions.continuous_agg_invalidation_trigger() SET SCHEMA _timescaledb_internal; +ALTER FUNCTION _timescaledb_functions.drop_dist_ht_invalidation_trigger(integer) SET SCHEMA _timescaledb_internal; +ALTER FUNCTION _timescaledb_functions.get_create_command(name) SET SCHEMA _timescaledb_internal; + +ALTER FUNCTION _timescaledb_functions.to_unix_microseconds(timestamptz) SET SCHEMA _timescaledb_internal; +ALTER FUNCTION _timescaledb_functions.to_timestamp(bigint) SET SCHEMA _timescaledb_internal; +ALTER FUNCTION _timescaledb_functions.to_timestamp_without_timezone(bigint) SET SCHEMA _timescaledb_internal; +ALTER FUNCTION _timescaledb_functions.to_date(bigint) SET SCHEMA _timescaledb_internal; +ALTER FUNCTION _timescaledb_functions.to_interval(bigint) SET SCHEMA _timescaledb_internal; +ALTER FUNCTION _timescaledb_functions.interval_to_usec(interval) SET SCHEMA _timescaledb_internal; +ALTER FUNCTION _timescaledb_functions.time_to_internal(anyelement) SET SCHEMA _timescaledb_internal; +ALTER FUNCTION _timescaledb_functions.subtract_integer_from_now(regclass, bigint) SET SCHEMA _timescaledb_internal; + +ALTER FUNCTION _timescaledb_functions.set_dist_id(uuid) SET SCHEMA _timescaledb_internal; +ALTER FUNCTION _timescaledb_functions.set_peer_dist_id(uuid) SET SCHEMA _timescaledb_internal; +ALTER FUNCTION _timescaledb_functions.validate_as_data_node() SET SCHEMA _timescaledb_internal; +ALTER FUNCTION _timescaledb_functions.show_connection_cache() SET SCHEMA _timescaledb_internal; +ALTER FUNCTION _timescaledb_functions.ping_data_node(name, interval) SET SCHEMA _timescaledb_internal; +ALTER FUNCTION _timescaledb_functions.remote_txn_heal_data_node(oid) SET SCHEMA _timescaledb_internal; + +ALTER FUNCTION _timescaledb_functions.relation_size(regclass) SET SCHEMA _timescaledb_internal; +ALTER FUNCTION _timescaledb_functions.data_node_hypertable_info(name, name, name) SET SCHEMA _timescaledb_internal; +ALTER FUNCTION _timescaledb_functions.data_node_chunk_info(name, name, name) SET SCHEMA _timescaledb_internal; +ALTER FUNCTION _timescaledb_functions.hypertable_local_size(name, name) SET SCHEMA _timescaledb_internal; +ALTER FUNCTION _timescaledb_functions.hypertable_remote_size(name, name) SET SCHEMA _timescaledb_internal; +ALTER FUNCTION _timescaledb_functions.chunks_local_size(name, name) SET SCHEMA _timescaledb_internal; +ALTER FUNCTION _timescaledb_functions.chunks_remote_size(name, name) SET SCHEMA _timescaledb_internal; +ALTER FUNCTION _timescaledb_functions.range_value_to_pretty(bigint, regtype) SET SCHEMA _timescaledb_internal; +ALTER FUNCTION _timescaledb_functions.get_approx_row_count(regclass) SET SCHEMA _timescaledb_internal; +ALTER FUNCTION _timescaledb_functions.data_node_compressed_chunk_stats(name, name, name) SET SCHEMA _timescaledb_internal; +ALTER FUNCTION _timescaledb_functions.compressed_chunk_local_stats(name, name) SET SCHEMA _timescaledb_internal; +ALTER FUNCTION _timescaledb_functions.compressed_chunk_remote_stats(name, name) SET SCHEMA _timescaledb_internal; +ALTER FUNCTION _timescaledb_functions.indexes_local_size(name, name) SET SCHEMA _timescaledb_internal; +ALTER FUNCTION _timescaledb_functions.data_node_index_size(name, name, name) SET SCHEMA _timescaledb_internal; +ALTER FUNCTION _timescaledb_functions.indexes_remote_size(name, name, name) SET SCHEMA _timescaledb_internal; + +ALTER FUNCTION _timescaledb_functions.generate_uuid() SET SCHEMA _timescaledb_internal; +ALTER FUNCTION _timescaledb_functions.get_git_commit() SET SCHEMA _timescaledb_internal; +ALTER FUNCTION _timescaledb_functions.get_os_info() SET SCHEMA _timescaledb_internal; +ALTER FUNCTION _timescaledb_functions.tsl_loaded() SET SCHEMA _timescaledb_internal; + +ALTER FUNCTION _timescaledb_functions.calculate_chunk_interval(int, bigint, bigint) SET SCHEMA _timescaledb_internal; +ALTER FUNCTION _timescaledb_functions.chunk_status(regclass) SET SCHEMA _timescaledb_internal; +ALTER FUNCTION _timescaledb_functions.chunks_in(record, integer[]) SET SCHEMA _timescaledb_internal; +ALTER FUNCTION _timescaledb_functions.chunk_id_from_relid(oid) SET SCHEMA _timescaledb_internal; +ALTER FUNCTION _timescaledb_functions.show_chunk(regclass) SET SCHEMA _timescaledb_internal; +ALTER FUNCTION _timescaledb_functions.create_chunk(regclass, jsonb, name, name, regclass) SET SCHEMA _timescaledb_internal; +ALTER FUNCTION _timescaledb_functions.set_chunk_default_data_node(regclass, name) SET SCHEMA _timescaledb_internal; +ALTER FUNCTION _timescaledb_functions.get_chunk_relstats(regclass) SET SCHEMA _timescaledb_internal; +ALTER FUNCTION _timescaledb_functions.get_chunk_colstats(regclass) SET SCHEMA _timescaledb_internal; +ALTER FUNCTION _timescaledb_functions.create_chunk_table(regclass, jsonb, name, name) SET SCHEMA _timescaledb_internal; +ALTER FUNCTION _timescaledb_functions.freeze_chunk(regclass) SET SCHEMA _timescaledb_internal; +ALTER FUNCTION _timescaledb_functions.unfreeze_chunk(regclass) SET SCHEMA _timescaledb_internal; +ALTER FUNCTION _timescaledb_functions.drop_chunk(regclass) SET SCHEMA _timescaledb_internal; +ALTER FUNCTION _timescaledb_functions.attach_osm_table_chunk(regclass, regclass) SET SCHEMA _timescaledb_internal; + +UPDATE _timescaledb_catalog.hypertable SET chunk_sizing_func_schema = '_timescaledb_internal' WHERE chunk_sizing_func_schema = '_timescaledb_functions' AND chunk_sizing_func_name = 'calculate_chunk_interval'; + +ALTER FUNCTION _timescaledb_functions.policy_compression_check(jsonb) SET SCHEMA _timescaledb_internal; +ALTER PROCEDURE _timescaledb_functions.policy_compression_execute(integer,integer,anyelement,integer,boolean,boolean) SET SCHEMA _timescaledb_internal; +ALTER PROCEDURE _timescaledb_functions.policy_compression(integer,jsonb) SET SCHEMA _timescaledb_internal; +ALTER FUNCTION _timescaledb_functions.policy_job_error_retention_check(jsonb) SET SCHEMA _timescaledb_internal; +ALTER FUNCTION _timescaledb_functions.policy_job_error_retention(integer,jsonb) SET SCHEMA _timescaledb_internal; +ALTER PROCEDURE _timescaledb_functions.policy_recompression(integer,jsonb) SET SCHEMA _timescaledb_internal; +ALTER FUNCTION _timescaledb_functions.policy_refresh_continuous_aggregate_check(jsonb) SET SCHEMA _timescaledb_internal; +ALTER PROCEDURE _timescaledb_functions.policy_refresh_continuous_aggregate(integer,jsonb) SET SCHEMA _timescaledb_internal; +ALTER FUNCTION _timescaledb_functions.policy_reorder_check(jsonb) SET SCHEMA _timescaledb_internal; +ALTER PROCEDURE _timescaledb_functions.policy_reorder(integer,jsonb) SET SCHEMA _timescaledb_internal; +ALTER FUNCTION _timescaledb_functions.policy_retention_check(jsonb) SET SCHEMA _timescaledb_internal; +ALTER PROCEDURE _timescaledb_functions.policy_retention(integer,jsonb) SET SCHEMA _timescaledb_internal; + +UPDATE _timescaledb_config.bgw_job SET proc_schema = '_timescaledb_internal' WHERE proc_schema = '_timescaledb_functions'; +UPDATE _timescaledb_config.bgw_job SET check_schema = '_timescaledb_internal' WHERE check_schema = '_timescaledb_functions'; + +ALTER FUNCTION _timescaledb_functions.cagg_migrate_plan_exists(INTEGER) SET SCHEMA _timescaledb_internal; +ALTER FUNCTION _timescaledb_functions.cagg_migrate_pre_validation(TEXT, TEXT, TEXT) SET SCHEMA _timescaledb_internal; +ALTER PROCEDURE _timescaledb_functions.cagg_migrate_create_plan(_timescaledb_catalog.continuous_agg, TEXT, BOOLEAN, BOOLEAN) SET SCHEMA _timescaledb_internal; +ALTER PROCEDURE _timescaledb_functions.cagg_migrate_execute_create_new_cagg(_timescaledb_catalog.continuous_agg, _timescaledb_catalog.continuous_agg_migrate_plan_step) SET SCHEMA _timescaledb_internal; +ALTER PROCEDURE _timescaledb_functions.cagg_migrate_execute_disable_policies(_timescaledb_catalog.continuous_agg, _timescaledb_catalog.continuous_agg_migrate_plan_step) SET SCHEMA _timescaledb_internal; +ALTER PROCEDURE _timescaledb_functions.cagg_migrate_execute_enable_policies(_timescaledb_catalog.continuous_agg, _timescaledb_catalog.continuous_agg_migrate_plan_step) SET SCHEMA _timescaledb_internal; +ALTER PROCEDURE _timescaledb_functions.cagg_migrate_execute_copy_policies(_timescaledb_catalog.continuous_agg, _timescaledb_catalog.continuous_agg_migrate_plan_step) SET SCHEMA _timescaledb_internal; +ALTER PROCEDURE _timescaledb_functions.cagg_migrate_execute_refresh_new_cagg(_timescaledb_catalog.continuous_agg, _timescaledb_catalog.continuous_agg_migrate_plan_step) SET SCHEMA _timescaledb_internal; +ALTER PROCEDURE _timescaledb_functions.cagg_migrate_execute_copy_data(_timescaledb_catalog.continuous_agg, _timescaledb_catalog.continuous_agg_migrate_plan_step) SET SCHEMA _timescaledb_internal; +ALTER PROCEDURE _timescaledb_functions.cagg_migrate_execute_override_cagg(_timescaledb_catalog.continuous_agg, _timescaledb_catalog.continuous_agg_migrate_plan_step) SET SCHEMA _timescaledb_internal; +ALTER PROCEDURE _timescaledb_functions.cagg_migrate_execute_drop_old_cagg(_timescaledb_catalog.continuous_agg, _timescaledb_catalog.continuous_agg_migrate_plan_step) SET SCHEMA _timescaledb_internal; +ALTER PROCEDURE _timescaledb_functions.cagg_migrate_execute_plan(_timescaledb_catalog.continuous_agg) SET SCHEMA _timescaledb_internal; + +-- pre-update of previous version will have created an additional copy of restart_background_workers +-- since restart_background_workers was handled differently from other functions in previous versions +DROP FUNCTION _timescaledb_internal.restart_background_workers(); +ALTER FUNCTION _timescaledb_functions.start_background_workers() SET SCHEMA _timescaledb_internal; +ALTER FUNCTION _timescaledb_functions.stop_background_workers() SET SCHEMA _timescaledb_internal; +ALTER FUNCTION _timescaledb_functions.restart_background_workers() SET SCHEMA _timescaledb_internal; +ALTER FUNCTION _timescaledb_functions.alter_job_set_hypertable_id(integer,regclass) SET SCHEMA _timescaledb_internal; + +ALTER FUNCTION _timescaledb_functions.cagg_watermark(integer) SET SCHEMA _timescaledb_internal; +ALTER FUNCTION _timescaledb_functions.cagg_watermark_materialized(integer) SET SCHEMA _timescaledb_internal; +ALTER FUNCTION _timescaledb_functions.hypertable_invalidation_log_delete(integer) SET SCHEMA _timescaledb_internal; +ALTER FUNCTION _timescaledb_functions.invalidation_cagg_log_add_entry(integer,bigint,bigint) SET SCHEMA _timescaledb_internal; +ALTER FUNCTION _timescaledb_functions.invalidation_hyper_log_add_entry(integer,bigint,bigint) SET SCHEMA _timescaledb_internal; +ALTER FUNCTION _timescaledb_functions.invalidation_process_cagg_log(integer,integer,regtype,bigint,bigint,integer[],bigint[],bigint[]) SET SCHEMA _timescaledb_internal; +ALTER FUNCTION _timescaledb_functions.invalidation_process_cagg_log(integer,integer,regtype,bigint,bigint,integer[],bigint[],bigint[],text[]) SET SCHEMA _timescaledb_internal; +ALTER FUNCTION _timescaledb_functions.invalidation_process_hypertable_log(integer,integer,regtype,integer[],bigint[],bigint[]) SET SCHEMA _timescaledb_internal; +ALTER FUNCTION _timescaledb_functions.invalidation_process_hypertable_log(integer,integer,regtype,integer[],bigint[],bigint[],text[]) SET SCHEMA _timescaledb_internal; +ALTER FUNCTION _timescaledb_functions.materialization_invalidation_log_delete(integer) SET SCHEMA _timescaledb_internal; + +ALTER FUNCTION _timescaledb_functions.chunk_constraint_add_table_constraint(_timescaledb_catalog.chunk_constraint) SET SCHEMA _timescaledb_internal; +ALTER FUNCTION _timescaledb_functions.chunk_drop_replica(regclass,name) SET SCHEMA _timescaledb_internal; +ALTER FUNCTION _timescaledb_functions.chunk_index_clone(oid) SET SCHEMA _timescaledb_internal; +ALTER FUNCTION _timescaledb_functions.chunk_index_replace(oid,oid) SET SCHEMA _timescaledb_internal; +ALTER FUNCTION _timescaledb_functions.create_chunk_replica_table(regclass,name) SET SCHEMA _timescaledb_internal; +ALTER FUNCTION _timescaledb_functions.create_compressed_chunk(regclass,regclass,bigint,bigint,bigint,bigint,bigint,bigint,bigint,bigint) SET SCHEMA _timescaledb_internal; +ALTER FUNCTION _timescaledb_functions.drop_stale_chunks(name,integer[]) SET SCHEMA _timescaledb_internal; +ALTER FUNCTION _timescaledb_functions.get_compressed_chunk_index_for_recompression(regclass) SET SCHEMA _timescaledb_internal; +ALTER FUNCTION _timescaledb_functions.health() SET SCHEMA _timescaledb_internal; +ALTER FUNCTION _timescaledb_functions.hypertable_constraint_add_table_fk_constraint(name,name,name,integer) SET SCHEMA _timescaledb_internal; +ALTER FUNCTION _timescaledb_functions.process_ddl_event() SET SCHEMA _timescaledb_internal; +ALTER FUNCTION _timescaledb_functions.recompress_chunk_segmentwise(regclass,boolean) SET SCHEMA _timescaledb_internal; +ALTER PROCEDURE _timescaledb_functions.wait_subscription_sync(name,name,integer,numeric) SET SCHEMA _timescaledb_internal; + +ALTER FUNCTION _timescaledb_functions.get_partition_for_key(val anyelement) SET SCHEMA _timescaledb_internal; +ALTER FUNCTION _timescaledb_functions.get_partition_hash(val anyelement) SET SCHEMA _timescaledb_internal; + +UPDATE _timescaledb_catalog.dimension SET partitioning_func_schema = '_timescaledb_internal' WHERE partitioning_func_schema = '_timescaledb_functions' AND partitioning_func IN ('get_partition_for_key','get_partition_hash'); + +ALTER FUNCTION _timescaledb_functions.finalize_agg_ffunc(internal,text,name,name,name[],bytea,anyelement) SET SCHEMA _timescaledb_internal; +ALTER FUNCTION _timescaledb_functions.finalize_agg_sfunc(internal,text,name,name,name[],bytea,anyelement) SET SCHEMA _timescaledb_internal; +ALTER FUNCTION _timescaledb_functions.partialize_agg(anyelement) SET SCHEMA _timescaledb_internal; +ALTER AGGREGATE _timescaledb_functions.finalize_agg(text,name,name,name[][],bytea,anyelement) SET SCHEMA _timescaledb_internal; + +DROP FUNCTION _timescaledb_functions.hypertable_osm_range_update(regclass, anyelement, anyelement, boolean); + +-- recreate the _timescaledb_catalog.hypertable table as new field was added +-- 1. drop CONSTRAINTS from other tables referencing the existing one +ALTER TABLE _timescaledb_config.bgw_job + DROP CONSTRAINT bgw_job_hypertable_id_fkey; +ALTER TABLE _timescaledb_catalog.chunk + DROP CONSTRAINT chunk_hypertable_id_fkey; +ALTER TABLE _timescaledb_catalog.chunk_index + DROP CONSTRAINT chunk_index_hypertable_id_fkey; +ALTER TABLE _timescaledb_catalog.continuous_agg + DROP CONSTRAINT continuous_agg_mat_hypertable_id_fkey, + DROP CONSTRAINT continuous_agg_raw_hypertable_id_fkey; +ALTER TABLE _timescaledb_catalog.continuous_aggs_bucket_function + DROP CONSTRAINT continuous_aggs_bucket_function_mat_hypertable_id_fkey; +ALTER TABLE _timescaledb_catalog.continuous_aggs_invalidation_threshold + DROP CONSTRAINT continuous_aggs_invalidation_threshold_hypertable_id_fkey; +ALTER TABLE _timescaledb_catalog.dimension + DROP CONSTRAINT dimension_hypertable_id_fkey; +ALTER TABLE _timescaledb_catalog.hypertable + DROP CONSTRAINT hypertable_compressed_hypertable_id_fkey; +ALTER TABLE _timescaledb_catalog.hypertable_compression + DROP CONSTRAINT hypertable_compression_hypertable_id_fkey; +ALTER TABLE _timescaledb_catalog.hypertable_data_node + DROP CONSTRAINT hypertable_data_node_hypertable_id_fkey; +ALTER TABLE _timescaledb_catalog.tablespace + DROP CONSTRAINT tablespace_hypertable_id_fkey; + +-- drop dependent views +ALTER EXTENSION timescaledb DROP VIEW timescaledb_information.hypertables; +ALTER EXTENSION timescaledb DROP VIEW timescaledb_information.job_stats; +ALTER EXTENSION timescaledb DROP VIEW timescaledb_information.jobs; +ALTER EXTENSION timescaledb DROP VIEW timescaledb_information.continuous_aggregates; +ALTER EXTENSION timescaledb DROP VIEW timescaledb_information.chunks; +ALTER EXTENSION timescaledb DROP VIEW timescaledb_information.dimensions; +ALTER EXTENSION timescaledb DROP VIEW timescaledb_information.compression_settings; +ALTER EXTENSION timescaledb DROP VIEW _timescaledb_internal.hypertable_chunk_local_size; +ALTER EXTENSION timescaledb DROP VIEW _timescaledb_internal.compressed_chunk_stats; +ALTER EXTENSION timescaledb DROP VIEW timescaledb_experimental.chunk_replication_status; +ALTER EXTENSION timescaledb DROP VIEW timescaledb_experimental.policies; + +DROP VIEW timescaledb_information.hypertables; +DROP VIEW timescaledb_information.job_stats; +DROP VIEW timescaledb_information.jobs; +DROP VIEW timescaledb_information.continuous_aggregates; +DROP VIEW timescaledb_information.chunks; +DROP VIEW timescaledb_information.dimensions; +DROP VIEW timescaledb_information.compression_settings; +DROP VIEW _timescaledb_internal.hypertable_chunk_local_size; +DROP VIEW _timescaledb_internal.compressed_chunk_stats; +DROP VIEW timescaledb_experimental.chunk_replication_status; +DROP VIEW timescaledb_experimental.policies; + +-- recreate table +CREATE TABLE _timescaledb_catalog.hypertable_tmp AS SELECT * FROM _timescaledb_catalog.hypertable; +CREATE TABLE _timescaledb_catalog.tmp_hypertable_seq_value AS SELECT last_value, is_called FROM _timescaledb_catalog.hypertable_id_seq; + +ALTER EXTENSION timescaledb DROP TABLE _timescaledb_catalog.hypertable; +ALTER EXTENSION timescaledb DROP SEQUENCE _timescaledb_catalog.hypertable_id_seq; + +SET timescaledb.restoring = on; -- must disable the hooks otherwise we can't do anything without the table _timescaledb_catalog.hypertable + +DROP TABLE _timescaledb_catalog.hypertable; + +CREATE SEQUENCE _timescaledb_catalog.hypertable_id_seq MINVALUE 1; +SELECT setval('_timescaledb_catalog.hypertable_id_seq', last_value, is_called) FROM _timescaledb_catalog.tmp_hypertable_seq_value; +DROP TABLE _timescaledb_catalog.tmp_hypertable_seq_value; + +CREATE TABLE _timescaledb_catalog.hypertable ( + id INTEGER PRIMARY KEY NOT NULL DEFAULT nextval('_timescaledb_catalog.hypertable_id_seq'), + schema_name name NOT NULL, + table_name name NOT NULL, + associated_schema_name name NOT NULL, + associated_table_prefix name NOT NULL, + num_dimensions smallint NOT NULL, + chunk_sizing_func_schema name NOT NULL, + chunk_sizing_func_name name NOT NULL, + chunk_target_size bigint NOT NULL, -- size in bytes + compression_state smallint NOT NULL DEFAULT 0, + compressed_hypertable_id integer, + replication_factor smallint NULL +); + +SET timescaledb.restoring = off; + +INSERT INTO _timescaledb_catalog.hypertable ( + id, + schema_name, + table_name, + associated_schema_name, + associated_table_prefix, + num_dimensions, + chunk_sizing_func_schema, + chunk_sizing_func_name, + chunk_target_size, + compression_state, + compressed_hypertable_id, + replication_factor +) +SELECT + id, + schema_name, + table_name, + associated_schema_name, + associated_table_prefix, + num_dimensions, + chunk_sizing_func_schema, + chunk_sizing_func_name, + chunk_target_size, + compression_state, + compressed_hypertable_id, + replication_factor +FROM + _timescaledb_catalog.hypertable_tmp +ORDER BY id; + +ALTER SEQUENCE _timescaledb_catalog.hypertable_id_seq OWNED BY _timescaledb_catalog.hypertable.id; +SELECT pg_catalog.pg_extension_config_dump('_timescaledb_catalog.hypertable', 'WHERE id >= 1'); +SELECT pg_catalog.pg_extension_config_dump('_timescaledb_catalog.hypertable_id_seq', ''); + +GRANT SELECT ON _timescaledb_catalog.hypertable TO PUBLIC; +GRANT SELECT ON _timescaledb_catalog.hypertable_id_seq TO PUBLIC; + +DROP TABLE _timescaledb_catalog.hypertable_tmp; +-- now add any constraints +ALTER TABLE _timescaledb_catalog.hypertable + -- ADD CONSTRAINT hypertable_pkey PRIMARY KEY (id), + ADD CONSTRAINT hypertable_associated_schema_name_associated_table_prefix_key UNIQUE (associated_schema_name, associated_table_prefix), + ADD CONSTRAINT hypertable_table_name_schema_name_key UNIQUE (table_name, schema_name), + ADD CONSTRAINT hypertable_schema_name_check CHECK (schema_name != '_timescaledb_catalog'), + -- internal compressed hypertables have compression state = 2 + ADD CONSTRAINT hypertable_dim_compress_check CHECK (num_dimensions > 0 OR compression_state = 2), + ADD CONSTRAINT hypertable_chunk_target_size_check CHECK (chunk_target_size >= 0), + ADD CONSTRAINT hypertable_compress_check CHECK ( (compression_state = 0 OR compression_state = 1 ) OR (compression_state = 2 AND compressed_hypertable_id IS NULL)), + -- replication_factor NULL: regular hypertable + -- replication_factor > 0: distributed hypertable on access node + -- replication_factor -1: distributed hypertable on data node, which is part of a larger table + ADD CONSTRAINT hypertable_replication_factor_check CHECK (replication_factor > 0 OR replication_factor = -1), + ADD CONSTRAINT hypertable_compressed_hypertable_id_fkey FOREIGN KEY (compressed_hypertable_id) REFERENCES _timescaledb_catalog.hypertable (id); + +GRANT SELECT ON TABLE _timescaledb_catalog.hypertable TO PUBLIC; + +-- 3. reestablish constraints on other tables +ALTER TABLE _timescaledb_config.bgw_job + ADD CONSTRAINT bgw_job_hypertable_id_fkey FOREIGN KEY (hypertable_id) REFERENCES _timescaledb_catalog.hypertable(id) ON DELETE CASCADE; +ALTER TABLE _timescaledb_catalog.chunk + ADD CONSTRAINT chunk_hypertable_id_fkey FOREIGN KEY (hypertable_id) REFERENCES _timescaledb_catalog.hypertable(id); +ALTER TABLE _timescaledb_catalog.chunk_index + ADD CONSTRAINT chunk_index_hypertable_id_fkey FOREIGN KEY (hypertable_id) REFERENCES _timescaledb_catalog.hypertable(id) ON DELETE CASCADE; +ALTER TABLE _timescaledb_catalog.continuous_agg + ADD CONSTRAINT continuous_agg_mat_hypertable_id_fkey FOREIGN KEY (mat_hypertable_id) REFERENCES _timescaledb_catalog.hypertable(id) ON DELETE CASCADE, + ADD CONSTRAINT continuous_agg_raw_hypertable_id_fkey FOREIGN KEY (raw_hypertable_id) REFERENCES _timescaledb_catalog.hypertable(id) ON DELETE CASCADE; +ALTER TABLE _timescaledb_catalog.continuous_aggs_bucket_function + ADD CONSTRAINT continuous_aggs_bucket_function_mat_hypertable_id_fkey FOREIGN KEY (mat_hypertable_id) REFERENCES _timescaledb_catalog.hypertable(id) ON DELETE CASCADE; +ALTER TABLE _timescaledb_catalog.continuous_aggs_invalidation_threshold + ADD CONSTRAINT continuous_aggs_invalidation_threshold_hypertable_id_fkey FOREIGN KEY (hypertable_id) REFERENCES _timescaledb_catalog.hypertable(id) ON DELETE CASCADE; +ALTER TABLE _timescaledb_catalog.dimension + ADD CONSTRAINT dimension_hypertable_id_fkey FOREIGN KEY (hypertable_id) REFERENCES _timescaledb_catalog.hypertable(id) ON DELETE CASCADE; +ALTER TABLE _timescaledb_catalog.hypertable_compression + ADD CONSTRAINT hypertable_compression_hypertable_id_fkey FOREIGN KEY (hypertable_id) REFERENCES _timescaledb_catalog.hypertable(id) ON DELETE CASCADE; +ALTER TABLE _timescaledb_catalog.hypertable_data_node + ADD CONSTRAINT hypertable_data_node_hypertable_id_fkey FOREIGN KEY (hypertable_id) REFERENCES _timescaledb_catalog.hypertable(id); +ALTER TABLE _timescaledb_catalog.tablespace + ADD CONSTRAINT tablespace_hypertable_id_fkey FOREIGN KEY (hypertable_id) REFERENCES _timescaledb_catalog.hypertable(id) ON DELETE CASCADE; diff --git a/sql/updates/latest-dev.sql b/sql/updates/latest-dev.sql index ca1f10bfc9b..e69de29bb2d 100644 --- a/sql/updates/latest-dev.sql +++ b/sql/updates/latest-dev.sql @@ -1,327 +0,0 @@ -DROP FUNCTION IF EXISTS @extschema@.alter_job( - INTEGER, - INTERVAL, - INTERVAL, - INTEGER, - INTERVAL, - BOOL, - JSONB, - TIMESTAMPTZ, - BOOL, - REGPROC -); - -CREATE FUNCTION @extschema@.alter_job( - job_id INTEGER, - schedule_interval INTERVAL = NULL, - max_runtime INTERVAL = NULL, - max_retries INTEGER = NULL, - retry_period INTERVAL = NULL, - scheduled BOOL = NULL, - config JSONB = NULL, - next_start TIMESTAMPTZ = NULL, - if_exists BOOL = FALSE, - check_config REGPROC = NULL, - fixed_schedule BOOL = NULL, - initial_start TIMESTAMPTZ = NULL, - timezone TEXT DEFAULT NULL -) -RETURNS TABLE (job_id INTEGER, schedule_interval INTERVAL, max_runtime INTERVAL, max_retries INTEGER, retry_period INTERVAL, scheduled BOOL, config JSONB, -next_start TIMESTAMPTZ, check_config TEXT, fixed_schedule BOOL, initial_start TIMESTAMPTZ, timezone TEXT) -AS '@MODULE_PATHNAME@', 'ts_job_alter' -LANGUAGE C VOLATILE; - --- when upgrading from old versions on PG13 this function might not be present --- since there is no ALTER FUNCTION IF EXISTS we have to work around it with a DO block -DO $$ -DECLARE - foid regprocedure; - funcs text[] = '{ - drop_dist_ht_invalidation_trigger, - subtract_integer_from_now, - get_approx_row_count, - chunk_status, - create_chunk,create_chunk_table, - freeze_chunk,unfreeze_chunk,drop_chunk, - attach_osm_table_chunk - }'; -BEGIN - FOR foid IN - SELECT oid FROM pg_proc WHERE proname = ANY(funcs) AND pronamespace = '_timescaledb_internal'::regnamespace - LOOP - EXECUTE format('ALTER FUNCTION %s SET SCHEMA _timescaledb_functions', foid); - END LOOP; -END; -$$; - -DROP FUNCTION IF EXISTS _timescaledb_internal.get_time_type(integer); - -ALTER FUNCTION _timescaledb_internal.insert_blocker() SET SCHEMA _timescaledb_functions; -ALTER FUNCTION _timescaledb_internal.continuous_agg_invalidation_trigger() SET SCHEMA _timescaledb_functions; -ALTER FUNCTION _timescaledb_internal.get_create_command(name) SET SCHEMA _timescaledb_functions; - -ALTER FUNCTION _timescaledb_internal.to_unix_microseconds(timestamptz) SET SCHEMA _timescaledb_functions; -ALTER FUNCTION _timescaledb_internal.to_timestamp(bigint) SET SCHEMA _timescaledb_functions; -ALTER FUNCTION _timescaledb_internal.to_timestamp_without_timezone(bigint) SET SCHEMA _timescaledb_functions; -ALTER FUNCTION _timescaledb_internal.to_date(bigint) SET SCHEMA _timescaledb_functions; -ALTER FUNCTION _timescaledb_internal.to_interval(bigint) SET SCHEMA _timescaledb_functions; -ALTER FUNCTION _timescaledb_internal.interval_to_usec(interval) SET SCHEMA _timescaledb_functions; -ALTER FUNCTION _timescaledb_internal.time_to_internal(anyelement) SET SCHEMA _timescaledb_functions; - -ALTER FUNCTION _timescaledb_internal.set_dist_id(uuid) SET SCHEMA _timescaledb_functions; -ALTER FUNCTION _timescaledb_internal.set_peer_dist_id(uuid) SET SCHEMA _timescaledb_functions; -ALTER FUNCTION _timescaledb_internal.validate_as_data_node() SET SCHEMA _timescaledb_functions; -ALTER FUNCTION _timescaledb_internal.show_connection_cache() SET SCHEMA _timescaledb_functions; -ALTER FUNCTION _timescaledb_internal.ping_data_node(name, interval) SET SCHEMA _timescaledb_functions; -ALTER FUNCTION _timescaledb_internal.remote_txn_heal_data_node(oid) SET SCHEMA _timescaledb_functions; - -ALTER FUNCTION _timescaledb_internal.relation_size(regclass) SET SCHEMA _timescaledb_functions; -ALTER FUNCTION _timescaledb_internal.data_node_hypertable_info(name, name, name) SET SCHEMA _timescaledb_functions; -ALTER FUNCTION _timescaledb_internal.data_node_chunk_info(name, name, name) SET SCHEMA _timescaledb_functions; -ALTER FUNCTION _timescaledb_internal.hypertable_local_size(name, name) SET SCHEMA _timescaledb_functions; -ALTER FUNCTION _timescaledb_internal.hypertable_remote_size(name, name) SET SCHEMA _timescaledb_functions; -ALTER FUNCTION _timescaledb_internal.chunks_local_size(name, name) SET SCHEMA _timescaledb_functions; -ALTER FUNCTION _timescaledb_internal.chunks_remote_size(name, name) SET SCHEMA _timescaledb_functions; -ALTER FUNCTION _timescaledb_internal.range_value_to_pretty(bigint, regtype) SET SCHEMA _timescaledb_functions; -ALTER FUNCTION _timescaledb_internal.data_node_compressed_chunk_stats(name, name, name) SET SCHEMA _timescaledb_functions; -ALTER FUNCTION _timescaledb_internal.compressed_chunk_local_stats(name, name) SET SCHEMA _timescaledb_functions; -ALTER FUNCTION _timescaledb_internal.compressed_chunk_remote_stats(name, name) SET SCHEMA _timescaledb_functions; -ALTER FUNCTION _timescaledb_internal.indexes_local_size(name, name) SET SCHEMA _timescaledb_functions; -ALTER FUNCTION _timescaledb_internal.data_node_index_size(name, name, name) SET SCHEMA _timescaledb_functions; -ALTER FUNCTION _timescaledb_internal.indexes_remote_size(name, name, name) SET SCHEMA _timescaledb_functions; - -ALTER FUNCTION _timescaledb_internal.generate_uuid() SET SCHEMA _timescaledb_functions; -ALTER FUNCTION _timescaledb_internal.get_git_commit() SET SCHEMA _timescaledb_functions; -ALTER FUNCTION _timescaledb_internal.get_os_info() SET SCHEMA _timescaledb_functions; -ALTER FUNCTION _timescaledb_internal.tsl_loaded() SET SCHEMA _timescaledb_functions; - -ALTER FUNCTION _timescaledb_internal.calculate_chunk_interval(int, bigint, bigint) SET SCHEMA _timescaledb_functions; -ALTER FUNCTION _timescaledb_internal.chunks_in(record, integer[]) SET SCHEMA _timescaledb_functions; -ALTER FUNCTION _timescaledb_internal.chunk_id_from_relid(oid) SET SCHEMA _timescaledb_functions; -ALTER FUNCTION _timescaledb_internal.show_chunk(regclass) SET SCHEMA _timescaledb_functions; -ALTER FUNCTION _timescaledb_internal.set_chunk_default_data_node(regclass, name) SET SCHEMA _timescaledb_functions; -ALTER FUNCTION _timescaledb_internal.get_chunk_relstats(regclass) SET SCHEMA _timescaledb_functions; -ALTER FUNCTION _timescaledb_internal.get_chunk_colstats(regclass) SET SCHEMA _timescaledb_functions; - -UPDATE _timescaledb_catalog.hypertable SET chunk_sizing_func_schema = '_timescaledb_functions' WHERE chunk_sizing_func_schema = '_timescaledb_internal' AND chunk_sizing_func_name = 'calculate_chunk_interval'; - -DO $$ -DECLARE - foid regprocedure; - kind text; - funcs text[] = '{ - policy_compression_check,policy_compression_execute,policy_compression, - policy_job_error_retention_check,policy_job_error_retention, - policy_recompression, - policy_refresh_continuous_aggregate_check,policy_refresh_continuous_aggregate, - policy_reorder_check,policy_reorder,policy_retention_check,policy_retention, - - cagg_watermark, cagg_watermark_materialized, - cagg_migrate_plan_exists, cagg_migrate_pre_validation, cagg_migrate_create_plan, cagg_migrate_execute_create_new_cagg, - cagg_migrate_execute_disable_policies, cagg_migrate_execute_enable_policies, cagg_migrate_execute_copy_policies, - cagg_migrate_execute_refresh_new_cagg, cagg_migrate_execute_copy_data, cagg_migrate_execute_override_cagg, - cagg_migrate_execute_drop_old_cagg, cagg_migrate_execute_plan, - - finalize_agg, - - hypertable_invalidation_log_delete, invalidation_cagg_log_add_entry, invalidation_hyper_log_add_entry, - invalidation_process_cagg_log, invalidation_process_hypertable_log, materialization_invalidation_log_delete, - - alter_job_set_hypertable_id, - - create_compressed_chunk, get_compressed_chunk_index_for_recompression, recompress_chunk_segmentwise, - chunk_drop_replica, chunk_index_clone, chunk_index_replace, create_chunk_replica_table, drop_stale_chunks, - chunk_constraint_add_table_constraint, hypertable_constraint_add_table_fk_constraint, - health, wait_subscription_sync - }'; -BEGIN - FOR foid, kind IN - SELECT oid, - CASE - WHEN prokind = 'f' THEN 'FUNCTION' - WHEN prokind = 'a' THEN 'AGGREGATE' - ELSE 'PROCEDURE' - END - FROM pg_proc WHERE proname = ANY(funcs) AND pronamespace = '_timescaledb_internal'::regnamespace - LOOP - EXECUTE format('ALTER %s %s SET SCHEMA _timescaledb_functions', kind, foid); - END LOOP; -END; -$$; - -UPDATE _timescaledb_config.bgw_job SET proc_schema = '_timescaledb_functions' WHERE proc_schema = '_timescaledb_internal'; -UPDATE _timescaledb_config.bgw_job SET check_schema = '_timescaledb_functions' WHERE check_schema = '_timescaledb_internal'; - -ALTER FUNCTION _timescaledb_internal.start_background_workers() SET SCHEMA _timescaledb_functions; -ALTER FUNCTION _timescaledb_internal.stop_background_workers() SET SCHEMA _timescaledb_functions; -ALTER FUNCTION _timescaledb_internal.restart_background_workers() SET SCHEMA _timescaledb_functions; - -ALTER FUNCTION _timescaledb_internal.process_ddl_event() SET SCHEMA _timescaledb_functions; - -ALTER FUNCTION _timescaledb_internal.get_partition_for_key(val anyelement) SET SCHEMA _timescaledb_functions; -ALTER FUNCTION _timescaledb_internal.get_partition_hash(val anyelement) SET SCHEMA _timescaledb_functions; - -UPDATE _timescaledb_catalog.dimension SET partitioning_func_schema = '_timescaledb_functions' WHERE partitioning_func_schema = '_timescaledb_internal' AND partitioning_func IN ('get_partition_for_key','get_partition_hash'); - -ALTER FUNCTION _timescaledb_internal.finalize_agg_ffunc(internal,text,name,name,name[],bytea,anyelement) SET SCHEMA _timescaledb_functions; -ALTER FUNCTION _timescaledb_internal.finalize_agg_sfunc(internal,text,name,name,name[],bytea,anyelement) SET SCHEMA _timescaledb_functions; -ALTER FUNCTION _timescaledb_internal.partialize_agg(anyelement) SET SCHEMA _timescaledb_functions; - --- Fix osm chunk ranges -UPDATE _timescaledb_catalog.dimension_slice ds - SET range_start = 9223372036854775806 -FROM _timescaledb_catalog.chunk_constraint cc -INNER JOIN _timescaledb_catalog.chunk c ON c.id = cc.chunk_id AND c.osm_chunk -WHERE cc.dimension_slice_id = ds.id AND ds.range_start <> 9223372036854775806; - --- OSM support - table must be rebuilt to ensure consistent attribute numbers --- we cannot just ALTER TABLE .. ADD COLUMN -ALTER TABLE _timescaledb_config.bgw_job - DROP CONSTRAINT bgw_job_hypertable_id_fkey; -ALTER TABLE _timescaledb_catalog.chunk - DROP CONSTRAINT chunk_hypertable_id_fkey; -ALTER TABLE _timescaledb_catalog.chunk_index - DROP CONSTRAINT chunk_index_hypertable_id_fkey; -ALTER TABLE _timescaledb_catalog.continuous_agg - DROP CONSTRAINT continuous_agg_mat_hypertable_id_fkey, - DROP CONSTRAINT continuous_agg_raw_hypertable_id_fkey; -ALTER TABLE _timescaledb_catalog.continuous_aggs_bucket_function - DROP CONSTRAINT continuous_aggs_bucket_function_mat_hypertable_id_fkey; -ALTER TABLE _timescaledb_catalog.continuous_aggs_invalidation_threshold - DROP CONSTRAINT continuous_aggs_invalidation_threshold_hypertable_id_fkey; -ALTER TABLE _timescaledb_catalog.dimension - DROP CONSTRAINT dimension_hypertable_id_fkey; -ALTER TABLE _timescaledb_catalog.hypertable - DROP CONSTRAINT hypertable_compressed_hypertable_id_fkey; -ALTER TABLE _timescaledb_catalog.hypertable_compression - DROP CONSTRAINT hypertable_compression_hypertable_id_fkey; -ALTER TABLE _timescaledb_catalog.hypertable_data_node - DROP CONSTRAINT hypertable_data_node_hypertable_id_fkey; -ALTER TABLE _timescaledb_catalog.tablespace - DROP CONSTRAINT tablespace_hypertable_id_fkey; - -DROP VIEW IF EXISTS timescaledb_information.hypertables; -DROP VIEW IF EXISTS timescaledb_information.job_stats; -DROP VIEW IF EXISTS timescaledb_information.jobs; -DROP VIEW IF EXISTS timescaledb_information.continuous_aggregates; -DROP VIEW IF EXISTS timescaledb_information.chunks; -DROP VIEW IF EXISTS timescaledb_information.dimensions; -DROP VIEW IF EXISTS timescaledb_information.compression_settings; -DROP VIEW IF EXISTS _timescaledb_internal.hypertable_chunk_local_size; -DROP VIEW IF EXISTS _timescaledb_internal.compressed_chunk_stats; -DROP VIEW IF EXISTS timescaledb_experimental.chunk_replication_status; -DROP VIEW IF EXISTS timescaledb_experimental.policies; - --- recreate table -CREATE TABLE _timescaledb_catalog.hypertable_tmp AS SELECT * FROM _timescaledb_catalog.hypertable; -CREATE TABLE _timescaledb_catalog.tmp_hypertable_seq_value AS SELECT last_value, is_called FROM _timescaledb_catalog.hypertable_id_seq; - -ALTER EXTENSION timescaledb DROP TABLE _timescaledb_catalog.hypertable; -ALTER EXTENSION timescaledb DROP SEQUENCE _timescaledb_catalog.hypertable_id_seq; - -SET timescaledb.restoring = on; -- must disable the hooks otherwise we can't do anything without the table _timescaledb_catalog.hypertable - -DROP TABLE _timescaledb_catalog.hypertable; - -CREATE SEQUENCE _timescaledb_catalog.hypertable_id_seq MINVALUE 1; -SELECT setval('_timescaledb_catalog.hypertable_id_seq', last_value, is_called) FROM _timescaledb_catalog.tmp_hypertable_seq_value; -DROP TABLE _timescaledb_catalog.tmp_hypertable_seq_value; - -CREATE TABLE _timescaledb_catalog.hypertable ( - id INTEGER PRIMARY KEY NOT NULL DEFAULT nextval('_timescaledb_catalog.hypertable_id_seq'), - schema_name name NOT NULL, - table_name name NOT NULL, - associated_schema_name name NOT NULL, - associated_table_prefix name NOT NULL, - num_dimensions smallint NOT NULL, - chunk_sizing_func_schema name NOT NULL, - chunk_sizing_func_name name NOT NULL, - chunk_target_size bigint NOT NULL, -- size in bytes - compression_state smallint NOT NULL DEFAULT 0, - compressed_hypertable_id integer, - replication_factor smallint NULL, - status integer NOT NULL DEFAULT 0 -); - -SET timescaledb.restoring = off; - -INSERT INTO _timescaledb_catalog.hypertable ( - id, - schema_name, - table_name, - associated_schema_name, - associated_table_prefix, - num_dimensions, - chunk_sizing_func_schema, - chunk_sizing_func_name, - chunk_target_size, - compression_state, - compressed_hypertable_id, - replication_factor -) -SELECT - id, - schema_name, - table_name, - associated_schema_name, - associated_table_prefix, - num_dimensions, - chunk_sizing_func_schema, - chunk_sizing_func_name, - chunk_target_size, - compression_state, - compressed_hypertable_id, - replication_factor -FROM - _timescaledb_catalog.hypertable_tmp -ORDER BY id; - -UPDATE _timescaledb_catalog.hypertable h -SET status = 3 -WHERE EXISTS ( - SELECT FROM _timescaledb_catalog.chunk c WHERE c.osm_chunk AND c.hypertable_id = h.id -); - -ALTER SEQUENCE _timescaledb_catalog.hypertable_id_seq OWNED BY _timescaledb_catalog.hypertable.id; -SELECT pg_catalog.pg_extension_config_dump('_timescaledb_catalog.hypertable', 'WHERE id >= 1'); -SELECT pg_catalog.pg_extension_config_dump('_timescaledb_catalog.hypertable_id_seq', ''); - -GRANT SELECT ON _timescaledb_catalog.hypertable TO PUBLIC; -GRANT SELECT ON _timescaledb_catalog.hypertable_id_seq TO PUBLIC; - -DROP TABLE _timescaledb_catalog.hypertable_tmp; --- now add any constraints -ALTER TABLE _timescaledb_catalog.hypertable - ADD CONSTRAINT hypertable_associated_schema_name_associated_table_prefix_key UNIQUE (associated_schema_name, associated_table_prefix), - ADD CONSTRAINT hypertable_table_name_schema_name_key UNIQUE (table_name, schema_name), - ADD CONSTRAINT hypertable_schema_name_check CHECK (schema_name != '_timescaledb_catalog'), - ADD CONSTRAINT hypertable_dim_compress_check CHECK (num_dimensions > 0 OR compression_state = 2), - ADD CONSTRAINT hypertable_chunk_target_size_check CHECK (chunk_target_size >= 0), - ADD CONSTRAINT hypertable_compress_check CHECK ( (compression_state = 0 OR compression_state = 1 ) OR (compression_state = 2 AND compressed_hypertable_id IS NULL)), - ADD CONSTRAINT hypertable_replication_factor_check CHECK (replication_factor > 0 OR replication_factor = -1), - ADD CONSTRAINT hypertable_compressed_hypertable_id_fkey FOREIGN KEY (compressed_hypertable_id) REFERENCES _timescaledb_catalog.hypertable (id); - -GRANT SELECT ON TABLE _timescaledb_catalog.hypertable TO PUBLIC; - --- 3. reestablish constraints on other tables -ALTER TABLE _timescaledb_config.bgw_job - ADD CONSTRAINT bgw_job_hypertable_id_fkey FOREIGN KEY (hypertable_id) REFERENCES _timescaledb_catalog.hypertable(id) ON DELETE CASCADE; -ALTER TABLE _timescaledb_catalog.chunk - ADD CONSTRAINT chunk_hypertable_id_fkey FOREIGN KEY (hypertable_id) REFERENCES _timescaledb_catalog.hypertable(id); -ALTER TABLE _timescaledb_catalog.chunk_index - ADD CONSTRAINT chunk_index_hypertable_id_fkey FOREIGN KEY (hypertable_id) REFERENCES _timescaledb_catalog.hypertable(id) ON DELETE CASCADE; -ALTER TABLE _timescaledb_catalog.continuous_agg - ADD CONSTRAINT continuous_agg_mat_hypertable_id_fkey FOREIGN KEY (mat_hypertable_id) REFERENCES _timescaledb_catalog.hypertable(id) ON DELETE CASCADE, - ADD CONSTRAINT continuous_agg_raw_hypertable_id_fkey FOREIGN KEY (raw_hypertable_id) REFERENCES _timescaledb_catalog.hypertable(id) ON DELETE CASCADE; -ALTER TABLE _timescaledb_catalog.continuous_aggs_bucket_function - ADD CONSTRAINT continuous_aggs_bucket_function_mat_hypertable_id_fkey FOREIGN KEY (mat_hypertable_id) REFERENCES _timescaledb_catalog.hypertable(id) ON DELETE CASCADE; -ALTER TABLE _timescaledb_catalog.continuous_aggs_invalidation_threshold - ADD CONSTRAINT continuous_aggs_invalidation_threshold_hypertable_id_fkey FOREIGN KEY (hypertable_id) REFERENCES _timescaledb_catalog.hypertable(id) ON DELETE CASCADE; -ALTER TABLE _timescaledb_catalog.dimension - ADD CONSTRAINT dimension_hypertable_id_fkey FOREIGN KEY (hypertable_id) REFERENCES _timescaledb_catalog.hypertable(id) ON DELETE CASCADE; -ALTER TABLE _timescaledb_catalog.hypertable_compression - ADD CONSTRAINT hypertable_compression_hypertable_id_fkey FOREIGN KEY (hypertable_id) REFERENCES _timescaledb_catalog.hypertable(id) ON DELETE CASCADE; -ALTER TABLE _timescaledb_catalog.hypertable_data_node - ADD CONSTRAINT hypertable_data_node_hypertable_id_fkey FOREIGN KEY (hypertable_id) REFERENCES _timescaledb_catalog.hypertable(id); -ALTER TABLE _timescaledb_catalog.tablespace - ADD CONSTRAINT tablespace_hypertable_id_fkey FOREIGN KEY (hypertable_id) REFERENCES _timescaledb_catalog.hypertable(id) ON DELETE CASCADE; diff --git a/sql/updates/reverse-dev.sql b/sql/updates/reverse-dev.sql index 0e4b8b779eb..e69de29bb2d 100644 --- a/sql/updates/reverse-dev.sql +++ b/sql/updates/reverse-dev.sql @@ -1,439 +0,0 @@ - --- remove compatibility wrapper functions --- this needs to happen before we move the actual functions back into _timescaledb_internal -DROP FUNCTION _timescaledb_internal.alter_job_set_hypertable_id(integer,regclass); -DROP FUNCTION _timescaledb_internal.attach_osm_table_chunk(regclass,regclass); -DROP FUNCTION _timescaledb_internal.cagg_migrate_plan_exists(integer); -DROP FUNCTION _timescaledb_internal.cagg_migrate_pre_validation(text,text,text); -DROP FUNCTION _timescaledb_internal.cagg_watermark(integer); -DROP FUNCTION _timescaledb_internal.cagg_watermark_materialized(integer); -DROP FUNCTION _timescaledb_internal.calculate_chunk_interval(integer,bigint,bigint); -DROP FUNCTION _timescaledb_internal.chunk_constraint_add_table_constraint(_timescaledb_catalog.chunk_constraint); -DROP FUNCTION _timescaledb_internal.chunk_drop_replica(regclass,name); -DROP FUNCTION _timescaledb_internal.chunk_id_from_relid(oid); -DROP FUNCTION _timescaledb_internal.chunk_index_clone(oid); -DROP FUNCTION _timescaledb_internal.chunk_index_replace(oid,oid); -DROP FUNCTION _timescaledb_internal.chunk_status(regclass); -DROP FUNCTION _timescaledb_internal.chunks_in(record,integer[]); -DROP FUNCTION _timescaledb_internal.chunks_local_size(name,name); -DROP FUNCTION _timescaledb_internal.chunks_remote_size(name,name); -DROP FUNCTION _timescaledb_internal.compressed_chunk_local_stats(name,name); -DROP FUNCTION _timescaledb_internal.compressed_chunk_remote_stats(name,name); -DROP FUNCTION _timescaledb_internal.continuous_agg_invalidation_trigger(); -DROP FUNCTION _timescaledb_internal.create_chunk(regclass,jsonb,name,name,regclass); -DROP FUNCTION _timescaledb_internal.create_chunk_replica_table(regclass,name); -DROP FUNCTION _timescaledb_internal.create_chunk_table(regclass,jsonb,name,name); -DROP FUNCTION _timescaledb_internal.create_compressed_chunk(regclass,regclass,bigint,bigint,bigint,bigint,bigint,bigint,bigint,bigint); -DROP FUNCTION _timescaledb_internal.data_node_chunk_info(name,name,name); -DROP FUNCTION _timescaledb_internal.data_node_compressed_chunk_stats(name,name,name); -DROP FUNCTION _timescaledb_internal.data_node_hypertable_info(name,name,name); -DROP FUNCTION _timescaledb_internal.data_node_index_size(name,name,name); -DROP FUNCTION _timescaledb_internal.drop_chunk(regclass); -DROP FUNCTION _timescaledb_internal.drop_dist_ht_invalidation_trigger(integer); -DROP FUNCTION _timescaledb_internal.drop_stale_chunks(name,integer[]); -DROP AGGREGATE _timescaledb_internal.finalize_agg(agg_name TEXT, inner_agg_collation_schema NAME, inner_agg_collation_name NAME, inner_agg_input_types NAME[][], inner_agg_serialized_state BYTEA, return_type_dummy_val anyelement); -DROP FUNCTION _timescaledb_internal.finalize_agg_ffunc(internal, text, name, name, name[][], bytea, anyelement); -DROP FUNCTION _timescaledb_internal.finalize_agg_sfunc(internal, text, name, name, name[][], bytea, anyelement); -DROP FUNCTION _timescaledb_internal.freeze_chunk(regclass); -DROP FUNCTION _timescaledb_internal.generate_uuid(); -DROP FUNCTION _timescaledb_internal.get_approx_row_count(regclass); -DROP FUNCTION _timescaledb_internal.get_chunk_colstats(regclass); -DROP FUNCTION _timescaledb_internal.get_chunk_relstats(regclass); -DROP FUNCTION _timescaledb_internal.get_compressed_chunk_index_for_recompression(regclass); -DROP FUNCTION _timescaledb_internal.get_create_command(name); -DROP FUNCTION _timescaledb_internal.get_git_commit(); -DROP FUNCTION _timescaledb_internal.get_os_info(); -DROP FUNCTION _timescaledb_internal.get_partition_for_key(anyelement); -DROP FUNCTION _timescaledb_internal.get_partition_hash(anyelement); -DROP FUNCTION _timescaledb_internal.health(); -DROP FUNCTION _timescaledb_internal.hypertable_constraint_add_table_fk_constraint(name,name,name,integer); -DROP FUNCTION _timescaledb_internal.hypertable_invalidation_log_delete(integer); -DROP FUNCTION _timescaledb_internal.hypertable_local_size(name,name); -DROP FUNCTION _timescaledb_internal.hypertable_remote_size(name,name); -DROP FUNCTION _timescaledb_internal.indexes_local_size(name,name); -DROP FUNCTION _timescaledb_internal.indexes_remote_size(name,name,name); -DROP FUNCTION _timescaledb_internal.insert_blocker(); -DROP FUNCTION _timescaledb_internal.interval_to_usec(interval); -DROP FUNCTION _timescaledb_internal.invalidation_cagg_log_add_entry(integer,bigint,bigint); -DROP FUNCTION _timescaledb_internal.invalidation_hyper_log_add_entry(integer,bigint,bigint); -DROP FUNCTION _timescaledb_internal.invalidation_process_cagg_log(integer,integer,regtype,bigint,bigint,integer[],bigint[],bigint[]); -DROP FUNCTION _timescaledb_internal.invalidation_process_cagg_log(integer,integer,regtype,bigint,bigint,integer[],bigint[],bigint[],text[]); -DROP FUNCTION _timescaledb_internal.invalidation_process_hypertable_log(integer,integer,regtype,integer[],bigint[],bigint[]); -DROP FUNCTION _timescaledb_internal.invalidation_process_hypertable_log(integer,integer,regtype,integer[],bigint[],bigint[],text[]); -DROP FUNCTION _timescaledb_internal.materialization_invalidation_log_delete(integer); -DROP FUNCTION _timescaledb_internal.partialize_agg(anyelement); -DROP FUNCTION _timescaledb_internal.ping_data_node(name,interval); -DROP FUNCTION _timescaledb_internal.policy_compression_check(jsonb); -DROP FUNCTION _timescaledb_internal.policy_job_error_retention(integer,jsonb); -DROP FUNCTION _timescaledb_internal.policy_job_error_retention_check(jsonb); -DROP FUNCTION _timescaledb_internal.policy_refresh_continuous_aggregate_check(jsonb); -DROP FUNCTION _timescaledb_internal.policy_reorder_check(jsonb); -DROP FUNCTION _timescaledb_internal.policy_retention_check(jsonb); -DROP FUNCTION _timescaledb_internal.process_ddl_event(); -DROP FUNCTION _timescaledb_internal.range_value_to_pretty(bigint,regtype); -DROP FUNCTION _timescaledb_internal.recompress_chunk_segmentwise(regclass,boolean); -DROP FUNCTION _timescaledb_internal.relation_size(regclass); -DROP FUNCTION _timescaledb_internal.remote_txn_heal_data_node(oid); -DROP FUNCTION _timescaledb_internal.set_chunk_default_data_node(regclass,name); -DROP FUNCTION _timescaledb_internal.set_dist_id(uuid); -DROP FUNCTION _timescaledb_internal.set_peer_dist_id(uuid); -DROP FUNCTION _timescaledb_internal.show_chunk(regclass); -DROP FUNCTION _timescaledb_internal.show_connection_cache(); -DROP FUNCTION _timescaledb_internal.start_background_workers(); -DROP FUNCTION _timescaledb_internal.stop_background_workers(); -DROP FUNCTION _timescaledb_internal.subtract_integer_from_now(regclass,bigint); -DROP FUNCTION _timescaledb_internal.time_to_internal(anyelement); -DROP FUNCTION _timescaledb_internal.to_date(bigint); -DROP FUNCTION _timescaledb_internal.to_interval(bigint); -DROP FUNCTION _timescaledb_internal.to_timestamp(bigint); -DROP FUNCTION _timescaledb_internal.to_timestamp_without_timezone(bigint); -DROP FUNCTION _timescaledb_internal.to_unix_microseconds(timestamp with time zone); -DROP FUNCTION _timescaledb_internal.tsl_loaded(); -DROP FUNCTION _timescaledb_internal.unfreeze_chunk(regclass); -DROP FUNCTION _timescaledb_internal.validate_as_data_node(); -DROP PROCEDURE _timescaledb_internal.cagg_migrate_create_plan(_timescaledb_catalog.continuous_agg,text,boolean,boolean); -DROP PROCEDURE _timescaledb_internal.cagg_migrate_execute_copy_data(_timescaledb_catalog.continuous_agg,_timescaledb_catalog.continuous_agg_migrate_plan_step); -DROP PROCEDURE _timescaledb_internal.cagg_migrate_execute_copy_policies(_timescaledb_catalog.continuous_agg,_timescaledb_catalog.continuous_agg_migrate_plan_step); -DROP PROCEDURE _timescaledb_internal.cagg_migrate_execute_create_new_cagg(_timescaledb_catalog.continuous_agg,_timescaledb_catalog.continuous_agg_migrate_plan_step); -DROP PROCEDURE _timescaledb_internal.cagg_migrate_execute_disable_policies(_timescaledb_catalog.continuous_agg,_timescaledb_catalog.continuous_agg_migrate_plan_step); -DROP PROCEDURE _timescaledb_internal.cagg_migrate_execute_drop_old_cagg(_timescaledb_catalog.continuous_agg,_timescaledb_catalog.continuous_agg_migrate_plan_step); -DROP PROCEDURE _timescaledb_internal.cagg_migrate_execute_enable_policies(_timescaledb_catalog.continuous_agg,_timescaledb_catalog.continuous_agg_migrate_plan_step); -DROP PROCEDURE _timescaledb_internal.cagg_migrate_execute_override_cagg(_timescaledb_catalog.continuous_agg,_timescaledb_catalog.continuous_agg_migrate_plan_step); -DROP PROCEDURE _timescaledb_internal.cagg_migrate_execute_plan(_timescaledb_catalog.continuous_agg); -DROP PROCEDURE _timescaledb_internal.cagg_migrate_execute_refresh_new_cagg(_timescaledb_catalog.continuous_agg,_timescaledb_catalog.continuous_agg_migrate_plan_step); -DROP PROCEDURE _timescaledb_internal.policy_compression(integer,jsonb); -DROP PROCEDURE _timescaledb_internal.policy_compression_execute(integer,integer,anyelement,integer,boolean,boolean); -DROP PROCEDURE _timescaledb_internal.policy_recompression(integer,jsonb); -DROP PROCEDURE _timescaledb_internal.policy_refresh_continuous_aggregate(integer,jsonb); -DROP PROCEDURE _timescaledb_internal.policy_reorder(integer,jsonb); -DROP PROCEDURE _timescaledb_internal.policy_retention(integer,jsonb); -DROP PROCEDURE _timescaledb_internal.wait_subscription_sync(name,name,integer,numeric); - -DROP FUNCTION IF EXISTS @extschema@.alter_job( - INTEGER, - INTERVAL, - INTERVAL, - INTEGER, - INTERVAL, - BOOL, - JSONB, - TIMESTAMPTZ, - BOOL, - REGPROC, - BOOL, - TIMESTAMPTZ, - TEXT -); - -CREATE FUNCTION @extschema@.alter_job( - job_id INTEGER, - schedule_interval INTERVAL = NULL, - max_runtime INTERVAL = NULL, - max_retries INTEGER = NULL, - retry_period INTERVAL = NULL, - scheduled BOOL = NULL, - config JSONB = NULL, - next_start TIMESTAMPTZ = NULL, - if_exists BOOL = FALSE, - check_config REGPROC = NULL -) -RETURNS TABLE (job_id INTEGER, schedule_interval INTERVAL, max_runtime INTERVAL, max_retries INTEGER, retry_period INTERVAL, scheduled BOOL, config JSONB, -next_start TIMESTAMPTZ, check_config TEXT) -AS '@MODULE_PATHNAME@', 'ts_job_alter' -LANGUAGE C VOLATILE; - -ALTER FUNCTION _timescaledb_functions.insert_blocker() SET SCHEMA _timescaledb_internal; -ALTER FUNCTION _timescaledb_functions.continuous_agg_invalidation_trigger() SET SCHEMA _timescaledb_internal; -ALTER FUNCTION _timescaledb_functions.drop_dist_ht_invalidation_trigger(integer) SET SCHEMA _timescaledb_internal; -ALTER FUNCTION _timescaledb_functions.get_create_command(name) SET SCHEMA _timescaledb_internal; - -ALTER FUNCTION _timescaledb_functions.to_unix_microseconds(timestamptz) SET SCHEMA _timescaledb_internal; -ALTER FUNCTION _timescaledb_functions.to_timestamp(bigint) SET SCHEMA _timescaledb_internal; -ALTER FUNCTION _timescaledb_functions.to_timestamp_without_timezone(bigint) SET SCHEMA _timescaledb_internal; -ALTER FUNCTION _timescaledb_functions.to_date(bigint) SET SCHEMA _timescaledb_internal; -ALTER FUNCTION _timescaledb_functions.to_interval(bigint) SET SCHEMA _timescaledb_internal; -ALTER FUNCTION _timescaledb_functions.interval_to_usec(interval) SET SCHEMA _timescaledb_internal; -ALTER FUNCTION _timescaledb_functions.time_to_internal(anyelement) SET SCHEMA _timescaledb_internal; -ALTER FUNCTION _timescaledb_functions.subtract_integer_from_now(regclass, bigint) SET SCHEMA _timescaledb_internal; - -ALTER FUNCTION _timescaledb_functions.set_dist_id(uuid) SET SCHEMA _timescaledb_internal; -ALTER FUNCTION _timescaledb_functions.set_peer_dist_id(uuid) SET SCHEMA _timescaledb_internal; -ALTER FUNCTION _timescaledb_functions.validate_as_data_node() SET SCHEMA _timescaledb_internal; -ALTER FUNCTION _timescaledb_functions.show_connection_cache() SET SCHEMA _timescaledb_internal; -ALTER FUNCTION _timescaledb_functions.ping_data_node(name, interval) SET SCHEMA _timescaledb_internal; -ALTER FUNCTION _timescaledb_functions.remote_txn_heal_data_node(oid) SET SCHEMA _timescaledb_internal; - -ALTER FUNCTION _timescaledb_functions.relation_size(regclass) SET SCHEMA _timescaledb_internal; -ALTER FUNCTION _timescaledb_functions.data_node_hypertable_info(name, name, name) SET SCHEMA _timescaledb_internal; -ALTER FUNCTION _timescaledb_functions.data_node_chunk_info(name, name, name) SET SCHEMA _timescaledb_internal; -ALTER FUNCTION _timescaledb_functions.hypertable_local_size(name, name) SET SCHEMA _timescaledb_internal; -ALTER FUNCTION _timescaledb_functions.hypertable_remote_size(name, name) SET SCHEMA _timescaledb_internal; -ALTER FUNCTION _timescaledb_functions.chunks_local_size(name, name) SET SCHEMA _timescaledb_internal; -ALTER FUNCTION _timescaledb_functions.chunks_remote_size(name, name) SET SCHEMA _timescaledb_internal; -ALTER FUNCTION _timescaledb_functions.range_value_to_pretty(bigint, regtype) SET SCHEMA _timescaledb_internal; -ALTER FUNCTION _timescaledb_functions.get_approx_row_count(regclass) SET SCHEMA _timescaledb_internal; -ALTER FUNCTION _timescaledb_functions.data_node_compressed_chunk_stats(name, name, name) SET SCHEMA _timescaledb_internal; -ALTER FUNCTION _timescaledb_functions.compressed_chunk_local_stats(name, name) SET SCHEMA _timescaledb_internal; -ALTER FUNCTION _timescaledb_functions.compressed_chunk_remote_stats(name, name) SET SCHEMA _timescaledb_internal; -ALTER FUNCTION _timescaledb_functions.indexes_local_size(name, name) SET SCHEMA _timescaledb_internal; -ALTER FUNCTION _timescaledb_functions.data_node_index_size(name, name, name) SET SCHEMA _timescaledb_internal; -ALTER FUNCTION _timescaledb_functions.indexes_remote_size(name, name, name) SET SCHEMA _timescaledb_internal; - -ALTER FUNCTION _timescaledb_functions.generate_uuid() SET SCHEMA _timescaledb_internal; -ALTER FUNCTION _timescaledb_functions.get_git_commit() SET SCHEMA _timescaledb_internal; -ALTER FUNCTION _timescaledb_functions.get_os_info() SET SCHEMA _timescaledb_internal; -ALTER FUNCTION _timescaledb_functions.tsl_loaded() SET SCHEMA _timescaledb_internal; - -ALTER FUNCTION _timescaledb_functions.calculate_chunk_interval(int, bigint, bigint) SET SCHEMA _timescaledb_internal; -ALTER FUNCTION _timescaledb_functions.chunk_status(regclass) SET SCHEMA _timescaledb_internal; -ALTER FUNCTION _timescaledb_functions.chunks_in(record, integer[]) SET SCHEMA _timescaledb_internal; -ALTER FUNCTION _timescaledb_functions.chunk_id_from_relid(oid) SET SCHEMA _timescaledb_internal; -ALTER FUNCTION _timescaledb_functions.show_chunk(regclass) SET SCHEMA _timescaledb_internal; -ALTER FUNCTION _timescaledb_functions.create_chunk(regclass, jsonb, name, name, regclass) SET SCHEMA _timescaledb_internal; -ALTER FUNCTION _timescaledb_functions.set_chunk_default_data_node(regclass, name) SET SCHEMA _timescaledb_internal; -ALTER FUNCTION _timescaledb_functions.get_chunk_relstats(regclass) SET SCHEMA _timescaledb_internal; -ALTER FUNCTION _timescaledb_functions.get_chunk_colstats(regclass) SET SCHEMA _timescaledb_internal; -ALTER FUNCTION _timescaledb_functions.create_chunk_table(regclass, jsonb, name, name) SET SCHEMA _timescaledb_internal; -ALTER FUNCTION _timescaledb_functions.freeze_chunk(regclass) SET SCHEMA _timescaledb_internal; -ALTER FUNCTION _timescaledb_functions.unfreeze_chunk(regclass) SET SCHEMA _timescaledb_internal; -ALTER FUNCTION _timescaledb_functions.drop_chunk(regclass) SET SCHEMA _timescaledb_internal; -ALTER FUNCTION _timescaledb_functions.attach_osm_table_chunk(regclass, regclass) SET SCHEMA _timescaledb_internal; - -UPDATE _timescaledb_catalog.hypertable SET chunk_sizing_func_schema = '_timescaledb_internal' WHERE chunk_sizing_func_schema = '_timescaledb_functions' AND chunk_sizing_func_name = 'calculate_chunk_interval'; - -ALTER FUNCTION _timescaledb_functions.policy_compression_check(jsonb) SET SCHEMA _timescaledb_internal; -ALTER PROCEDURE _timescaledb_functions.policy_compression_execute(integer,integer,anyelement,integer,boolean,boolean) SET SCHEMA _timescaledb_internal; -ALTER PROCEDURE _timescaledb_functions.policy_compression(integer,jsonb) SET SCHEMA _timescaledb_internal; -ALTER FUNCTION _timescaledb_functions.policy_job_error_retention_check(jsonb) SET SCHEMA _timescaledb_internal; -ALTER FUNCTION _timescaledb_functions.policy_job_error_retention(integer,jsonb) SET SCHEMA _timescaledb_internal; -ALTER PROCEDURE _timescaledb_functions.policy_recompression(integer,jsonb) SET SCHEMA _timescaledb_internal; -ALTER FUNCTION _timescaledb_functions.policy_refresh_continuous_aggregate_check(jsonb) SET SCHEMA _timescaledb_internal; -ALTER PROCEDURE _timescaledb_functions.policy_refresh_continuous_aggregate(integer,jsonb) SET SCHEMA _timescaledb_internal; -ALTER FUNCTION _timescaledb_functions.policy_reorder_check(jsonb) SET SCHEMA _timescaledb_internal; -ALTER PROCEDURE _timescaledb_functions.policy_reorder(integer,jsonb) SET SCHEMA _timescaledb_internal; -ALTER FUNCTION _timescaledb_functions.policy_retention_check(jsonb) SET SCHEMA _timescaledb_internal; -ALTER PROCEDURE _timescaledb_functions.policy_retention(integer,jsonb) SET SCHEMA _timescaledb_internal; - -UPDATE _timescaledb_config.bgw_job SET proc_schema = '_timescaledb_internal' WHERE proc_schema = '_timescaledb_functions'; -UPDATE _timescaledb_config.bgw_job SET check_schema = '_timescaledb_internal' WHERE check_schema = '_timescaledb_functions'; - -ALTER FUNCTION _timescaledb_functions.cagg_migrate_plan_exists(INTEGER) SET SCHEMA _timescaledb_internal; -ALTER FUNCTION _timescaledb_functions.cagg_migrate_pre_validation(TEXT, TEXT, TEXT) SET SCHEMA _timescaledb_internal; -ALTER PROCEDURE _timescaledb_functions.cagg_migrate_create_plan(_timescaledb_catalog.continuous_agg, TEXT, BOOLEAN, BOOLEAN) SET SCHEMA _timescaledb_internal; -ALTER PROCEDURE _timescaledb_functions.cagg_migrate_execute_create_new_cagg(_timescaledb_catalog.continuous_agg, _timescaledb_catalog.continuous_agg_migrate_plan_step) SET SCHEMA _timescaledb_internal; -ALTER PROCEDURE _timescaledb_functions.cagg_migrate_execute_disable_policies(_timescaledb_catalog.continuous_agg, _timescaledb_catalog.continuous_agg_migrate_plan_step) SET SCHEMA _timescaledb_internal; -ALTER PROCEDURE _timescaledb_functions.cagg_migrate_execute_enable_policies(_timescaledb_catalog.continuous_agg, _timescaledb_catalog.continuous_agg_migrate_plan_step) SET SCHEMA _timescaledb_internal; -ALTER PROCEDURE _timescaledb_functions.cagg_migrate_execute_copy_policies(_timescaledb_catalog.continuous_agg, _timescaledb_catalog.continuous_agg_migrate_plan_step) SET SCHEMA _timescaledb_internal; -ALTER PROCEDURE _timescaledb_functions.cagg_migrate_execute_refresh_new_cagg(_timescaledb_catalog.continuous_agg, _timescaledb_catalog.continuous_agg_migrate_plan_step) SET SCHEMA _timescaledb_internal; -ALTER PROCEDURE _timescaledb_functions.cagg_migrate_execute_copy_data(_timescaledb_catalog.continuous_agg, _timescaledb_catalog.continuous_agg_migrate_plan_step) SET SCHEMA _timescaledb_internal; -ALTER PROCEDURE _timescaledb_functions.cagg_migrate_execute_override_cagg(_timescaledb_catalog.continuous_agg, _timescaledb_catalog.continuous_agg_migrate_plan_step) SET SCHEMA _timescaledb_internal; -ALTER PROCEDURE _timescaledb_functions.cagg_migrate_execute_drop_old_cagg(_timescaledb_catalog.continuous_agg, _timescaledb_catalog.continuous_agg_migrate_plan_step) SET SCHEMA _timescaledb_internal; -ALTER PROCEDURE _timescaledb_functions.cagg_migrate_execute_plan(_timescaledb_catalog.continuous_agg) SET SCHEMA _timescaledb_internal; - --- pre-update of previous version will have created an additional copy of restart_background_workers --- since restart_background_workers was handled differently from other functions in previous versions -DROP FUNCTION _timescaledb_internal.restart_background_workers(); -ALTER FUNCTION _timescaledb_functions.start_background_workers() SET SCHEMA _timescaledb_internal; -ALTER FUNCTION _timescaledb_functions.stop_background_workers() SET SCHEMA _timescaledb_internal; -ALTER FUNCTION _timescaledb_functions.restart_background_workers() SET SCHEMA _timescaledb_internal; -ALTER FUNCTION _timescaledb_functions.alter_job_set_hypertable_id(integer,regclass) SET SCHEMA _timescaledb_internal; - -ALTER FUNCTION _timescaledb_functions.cagg_watermark(integer) SET SCHEMA _timescaledb_internal; -ALTER FUNCTION _timescaledb_functions.cagg_watermark_materialized(integer) SET SCHEMA _timescaledb_internal; -ALTER FUNCTION _timescaledb_functions.hypertable_invalidation_log_delete(integer) SET SCHEMA _timescaledb_internal; -ALTER FUNCTION _timescaledb_functions.invalidation_cagg_log_add_entry(integer,bigint,bigint) SET SCHEMA _timescaledb_internal; -ALTER FUNCTION _timescaledb_functions.invalidation_hyper_log_add_entry(integer,bigint,bigint) SET SCHEMA _timescaledb_internal; -ALTER FUNCTION _timescaledb_functions.invalidation_process_cagg_log(integer,integer,regtype,bigint,bigint,integer[],bigint[],bigint[]) SET SCHEMA _timescaledb_internal; -ALTER FUNCTION _timescaledb_functions.invalidation_process_cagg_log(integer,integer,regtype,bigint,bigint,integer[],bigint[],bigint[],text[]) SET SCHEMA _timescaledb_internal; -ALTER FUNCTION _timescaledb_functions.invalidation_process_hypertable_log(integer,integer,regtype,integer[],bigint[],bigint[]) SET SCHEMA _timescaledb_internal; -ALTER FUNCTION _timescaledb_functions.invalidation_process_hypertable_log(integer,integer,regtype,integer[],bigint[],bigint[],text[]) SET SCHEMA _timescaledb_internal; -ALTER FUNCTION _timescaledb_functions.materialization_invalidation_log_delete(integer) SET SCHEMA _timescaledb_internal; - -ALTER FUNCTION _timescaledb_functions.chunk_constraint_add_table_constraint(_timescaledb_catalog.chunk_constraint) SET SCHEMA _timescaledb_internal; -ALTER FUNCTION _timescaledb_functions.chunk_drop_replica(regclass,name) SET SCHEMA _timescaledb_internal; -ALTER FUNCTION _timescaledb_functions.chunk_index_clone(oid) SET SCHEMA _timescaledb_internal; -ALTER FUNCTION _timescaledb_functions.chunk_index_replace(oid,oid) SET SCHEMA _timescaledb_internal; -ALTER FUNCTION _timescaledb_functions.create_chunk_replica_table(regclass,name) SET SCHEMA _timescaledb_internal; -ALTER FUNCTION _timescaledb_functions.create_compressed_chunk(regclass,regclass,bigint,bigint,bigint,bigint,bigint,bigint,bigint,bigint) SET SCHEMA _timescaledb_internal; -ALTER FUNCTION _timescaledb_functions.drop_stale_chunks(name,integer[]) SET SCHEMA _timescaledb_internal; -ALTER FUNCTION _timescaledb_functions.get_compressed_chunk_index_for_recompression(regclass) SET SCHEMA _timescaledb_internal; -ALTER FUNCTION _timescaledb_functions.health() SET SCHEMA _timescaledb_internal; -ALTER FUNCTION _timescaledb_functions.hypertable_constraint_add_table_fk_constraint(name,name,name,integer) SET SCHEMA _timescaledb_internal; -ALTER FUNCTION _timescaledb_functions.process_ddl_event() SET SCHEMA _timescaledb_internal; -ALTER FUNCTION _timescaledb_functions.recompress_chunk_segmentwise(regclass,boolean) SET SCHEMA _timescaledb_internal; -ALTER PROCEDURE _timescaledb_functions.wait_subscription_sync(name,name,integer,numeric) SET SCHEMA _timescaledb_internal; - -ALTER FUNCTION _timescaledb_functions.get_partition_for_key(val anyelement) SET SCHEMA _timescaledb_internal; -ALTER FUNCTION _timescaledb_functions.get_partition_hash(val anyelement) SET SCHEMA _timescaledb_internal; - -UPDATE _timescaledb_catalog.dimension SET partitioning_func_schema = '_timescaledb_internal' WHERE partitioning_func_schema = '_timescaledb_functions' AND partitioning_func IN ('get_partition_for_key','get_partition_hash'); - -ALTER FUNCTION _timescaledb_functions.finalize_agg_ffunc(internal,text,name,name,name[],bytea,anyelement) SET SCHEMA _timescaledb_internal; -ALTER FUNCTION _timescaledb_functions.finalize_agg_sfunc(internal,text,name,name,name[],bytea,anyelement) SET SCHEMA _timescaledb_internal; -ALTER FUNCTION _timescaledb_functions.partialize_agg(anyelement) SET SCHEMA _timescaledb_internal; -ALTER AGGREGATE _timescaledb_functions.finalize_agg(text,name,name,name[][],bytea,anyelement) SET SCHEMA _timescaledb_internal; - -DROP FUNCTION _timescaledb_functions.hypertable_osm_range_update(regclass, anyelement, anyelement, boolean); - --- recreate the _timescaledb_catalog.hypertable table as new field was added --- 1. drop CONSTRAINTS from other tables referencing the existing one -ALTER TABLE _timescaledb_config.bgw_job - DROP CONSTRAINT bgw_job_hypertable_id_fkey; -ALTER TABLE _timescaledb_catalog.chunk - DROP CONSTRAINT chunk_hypertable_id_fkey; -ALTER TABLE _timescaledb_catalog.chunk_index - DROP CONSTRAINT chunk_index_hypertable_id_fkey; -ALTER TABLE _timescaledb_catalog.continuous_agg - DROP CONSTRAINT continuous_agg_mat_hypertable_id_fkey, - DROP CONSTRAINT continuous_agg_raw_hypertable_id_fkey; -ALTER TABLE _timescaledb_catalog.continuous_aggs_bucket_function - DROP CONSTRAINT continuous_aggs_bucket_function_mat_hypertable_id_fkey; -ALTER TABLE _timescaledb_catalog.continuous_aggs_invalidation_threshold - DROP CONSTRAINT continuous_aggs_invalidation_threshold_hypertable_id_fkey; -ALTER TABLE _timescaledb_catalog.dimension - DROP CONSTRAINT dimension_hypertable_id_fkey; -ALTER TABLE _timescaledb_catalog.hypertable - DROP CONSTRAINT hypertable_compressed_hypertable_id_fkey; -ALTER TABLE _timescaledb_catalog.hypertable_compression - DROP CONSTRAINT hypertable_compression_hypertable_id_fkey; -ALTER TABLE _timescaledb_catalog.hypertable_data_node - DROP CONSTRAINT hypertable_data_node_hypertable_id_fkey; -ALTER TABLE _timescaledb_catalog.tablespace - DROP CONSTRAINT tablespace_hypertable_id_fkey; - --- drop dependent views -ALTER EXTENSION timescaledb DROP VIEW timescaledb_information.hypertables; -ALTER EXTENSION timescaledb DROP VIEW timescaledb_information.job_stats; -ALTER EXTENSION timescaledb DROP VIEW timescaledb_information.jobs; -ALTER EXTENSION timescaledb DROP VIEW timescaledb_information.continuous_aggregates; -ALTER EXTENSION timescaledb DROP VIEW timescaledb_information.chunks; -ALTER EXTENSION timescaledb DROP VIEW timescaledb_information.dimensions; -ALTER EXTENSION timescaledb DROP VIEW timescaledb_information.compression_settings; -ALTER EXTENSION timescaledb DROP VIEW _timescaledb_internal.hypertable_chunk_local_size; -ALTER EXTENSION timescaledb DROP VIEW _timescaledb_internal.compressed_chunk_stats; -ALTER EXTENSION timescaledb DROP VIEW timescaledb_experimental.chunk_replication_status; -ALTER EXTENSION timescaledb DROP VIEW timescaledb_experimental.policies; - -DROP VIEW timescaledb_information.hypertables; -DROP VIEW timescaledb_information.job_stats; -DROP VIEW timescaledb_information.jobs; -DROP VIEW timescaledb_information.continuous_aggregates; -DROP VIEW timescaledb_information.chunks; -DROP VIEW timescaledb_information.dimensions; -DROP VIEW timescaledb_information.compression_settings; -DROP VIEW _timescaledb_internal.hypertable_chunk_local_size; -DROP VIEW _timescaledb_internal.compressed_chunk_stats; -DROP VIEW timescaledb_experimental.chunk_replication_status; -DROP VIEW timescaledb_experimental.policies; - --- recreate table -CREATE TABLE _timescaledb_catalog.hypertable_tmp AS SELECT * FROM _timescaledb_catalog.hypertable; -CREATE TABLE _timescaledb_catalog.tmp_hypertable_seq_value AS SELECT last_value, is_called FROM _timescaledb_catalog.hypertable_id_seq; - -ALTER EXTENSION timescaledb DROP TABLE _timescaledb_catalog.hypertable; -ALTER EXTENSION timescaledb DROP SEQUENCE _timescaledb_catalog.hypertable_id_seq; - -SET timescaledb.restoring = on; -- must disable the hooks otherwise we can't do anything without the table _timescaledb_catalog.hypertable - -DROP TABLE _timescaledb_catalog.hypertable; - -CREATE SEQUENCE _timescaledb_catalog.hypertable_id_seq MINVALUE 1; -SELECT setval('_timescaledb_catalog.hypertable_id_seq', last_value, is_called) FROM _timescaledb_catalog.tmp_hypertable_seq_value; -DROP TABLE _timescaledb_catalog.tmp_hypertable_seq_value; - -CREATE TABLE _timescaledb_catalog.hypertable ( - id INTEGER PRIMARY KEY NOT NULL DEFAULT nextval('_timescaledb_catalog.hypertable_id_seq'), - schema_name name NOT NULL, - table_name name NOT NULL, - associated_schema_name name NOT NULL, - associated_table_prefix name NOT NULL, - num_dimensions smallint NOT NULL, - chunk_sizing_func_schema name NOT NULL, - chunk_sizing_func_name name NOT NULL, - chunk_target_size bigint NOT NULL, -- size in bytes - compression_state smallint NOT NULL DEFAULT 0, - compressed_hypertable_id integer, - replication_factor smallint NULL -); - -SET timescaledb.restoring = off; - -INSERT INTO _timescaledb_catalog.hypertable ( - id, - schema_name, - table_name, - associated_schema_name, - associated_table_prefix, - num_dimensions, - chunk_sizing_func_schema, - chunk_sizing_func_name, - chunk_target_size, - compression_state, - compressed_hypertable_id, - replication_factor -) -SELECT - id, - schema_name, - table_name, - associated_schema_name, - associated_table_prefix, - num_dimensions, - chunk_sizing_func_schema, - chunk_sizing_func_name, - chunk_target_size, - compression_state, - compressed_hypertable_id, - replication_factor -FROM - _timescaledb_catalog.hypertable_tmp -ORDER BY id; - -ALTER SEQUENCE _timescaledb_catalog.hypertable_id_seq OWNED BY _timescaledb_catalog.hypertable.id; -SELECT pg_catalog.pg_extension_config_dump('_timescaledb_catalog.hypertable', 'WHERE id >= 1'); -SELECT pg_catalog.pg_extension_config_dump('_timescaledb_catalog.hypertable_id_seq', ''); - -GRANT SELECT ON _timescaledb_catalog.hypertable TO PUBLIC; -GRANT SELECT ON _timescaledb_catalog.hypertable_id_seq TO PUBLIC; - -DROP TABLE _timescaledb_catalog.hypertable_tmp; --- now add any constraints -ALTER TABLE _timescaledb_catalog.hypertable - -- ADD CONSTRAINT hypertable_pkey PRIMARY KEY (id), - ADD CONSTRAINT hypertable_associated_schema_name_associated_table_prefix_key UNIQUE (associated_schema_name, associated_table_prefix), - ADD CONSTRAINT hypertable_table_name_schema_name_key UNIQUE (table_name, schema_name), - ADD CONSTRAINT hypertable_schema_name_check CHECK (schema_name != '_timescaledb_catalog'), - -- internal compressed hypertables have compression state = 2 - ADD CONSTRAINT hypertable_dim_compress_check CHECK (num_dimensions > 0 OR compression_state = 2), - ADD CONSTRAINT hypertable_chunk_target_size_check CHECK (chunk_target_size >= 0), - ADD CONSTRAINT hypertable_compress_check CHECK ( (compression_state = 0 OR compression_state = 1 ) OR (compression_state = 2 AND compressed_hypertable_id IS NULL)), - -- replication_factor NULL: regular hypertable - -- replication_factor > 0: distributed hypertable on access node - -- replication_factor -1: distributed hypertable on data node, which is part of a larger table - ADD CONSTRAINT hypertable_replication_factor_check CHECK (replication_factor > 0 OR replication_factor = -1), - ADD CONSTRAINT hypertable_compressed_hypertable_id_fkey FOREIGN KEY (compressed_hypertable_id) REFERENCES _timescaledb_catalog.hypertable (id); - -GRANT SELECT ON TABLE _timescaledb_catalog.hypertable TO PUBLIC; - --- 3. reestablish constraints on other tables -ALTER TABLE _timescaledb_config.bgw_job - ADD CONSTRAINT bgw_job_hypertable_id_fkey FOREIGN KEY (hypertable_id) REFERENCES _timescaledb_catalog.hypertable(id) ON DELETE CASCADE; -ALTER TABLE _timescaledb_catalog.chunk - ADD CONSTRAINT chunk_hypertable_id_fkey FOREIGN KEY (hypertable_id) REFERENCES _timescaledb_catalog.hypertable(id); -ALTER TABLE _timescaledb_catalog.chunk_index - ADD CONSTRAINT chunk_index_hypertable_id_fkey FOREIGN KEY (hypertable_id) REFERENCES _timescaledb_catalog.hypertable(id) ON DELETE CASCADE; -ALTER TABLE _timescaledb_catalog.continuous_agg - ADD CONSTRAINT continuous_agg_mat_hypertable_id_fkey FOREIGN KEY (mat_hypertable_id) REFERENCES _timescaledb_catalog.hypertable(id) ON DELETE CASCADE, - ADD CONSTRAINT continuous_agg_raw_hypertable_id_fkey FOREIGN KEY (raw_hypertable_id) REFERENCES _timescaledb_catalog.hypertable(id) ON DELETE CASCADE; -ALTER TABLE _timescaledb_catalog.continuous_aggs_bucket_function - ADD CONSTRAINT continuous_aggs_bucket_function_mat_hypertable_id_fkey FOREIGN KEY (mat_hypertable_id) REFERENCES _timescaledb_catalog.hypertable(id) ON DELETE CASCADE; -ALTER TABLE _timescaledb_catalog.continuous_aggs_invalidation_threshold - ADD CONSTRAINT continuous_aggs_invalidation_threshold_hypertable_id_fkey FOREIGN KEY (hypertable_id) REFERENCES _timescaledb_catalog.hypertable(id) ON DELETE CASCADE; -ALTER TABLE _timescaledb_catalog.dimension - ADD CONSTRAINT dimension_hypertable_id_fkey FOREIGN KEY (hypertable_id) REFERENCES _timescaledb_catalog.hypertable(id) ON DELETE CASCADE; -ALTER TABLE _timescaledb_catalog.hypertable_compression - ADD CONSTRAINT hypertable_compression_hypertable_id_fkey FOREIGN KEY (hypertable_id) REFERENCES _timescaledb_catalog.hypertable(id) ON DELETE CASCADE; -ALTER TABLE _timescaledb_catalog.hypertable_data_node - ADD CONSTRAINT hypertable_data_node_hypertable_id_fkey FOREIGN KEY (hypertable_id) REFERENCES _timescaledb_catalog.hypertable(id); -ALTER TABLE _timescaledb_catalog.tablespace - ADD CONSTRAINT tablespace_hypertable_id_fkey FOREIGN KEY (hypertable_id) REFERENCES _timescaledb_catalog.hypertable(id) ON DELETE CASCADE; diff --git a/version.config b/version.config index e0a2d64e926..1720f8b1670 100644 --- a/version.config +++ b/version.config @@ -1,3 +1,3 @@ -version = 2.12.0-dev +version = 2.12.0 update_from_version = 2.11.2 downgrade_to_version = 2.11.2