timescaledb/sql/updates/reverse-dev.sql
Erik Nordström e0f02c8c1a Add option to drop database when deleting data node
When deleting a data node, it is often convenient to be able to also
drop the database on the data node so that the node can be added again
using the same database name. However, dropping the database is
optional since it should be possible to delete a data node even if it
is no longer responding.

With the new functionality, a data node's database can be dropped as
follows:

```sql
SELECT delete_data_node('dn1', drop_database=>true);
```

Note that the default behavior is still to not drop the database in
order to be compatible with the old behavior. Enabling the option also
makes the function non-transactional, since dropping a database is not
transactional. Therefore, it is not possible to use this option in a
transaction block.

Closes #3876
2021-12-16 15:59:50 +01:00

79 lines
2.9 KiB
PL/PgSQL

DROP PROCEDURE IF EXISTS recompress_chunk;
DROP FUNCTION IF EXISTS _timescaledb_internal.chunk_status;
DROP FUNCTION IF EXISTS delete_data_node;
DO $$
DECLARE
caggs text[];
caggs_nr int;
BEGIN
SELECT array_agg(format('%I.%I', user_view_schema, user_view_name)) FROM _timescaledb_catalog.continuous_agg WHERE bucket_width < 0 INTO caggs;
SELECT array_length(caggs, 1) INTO caggs_nr;
IF caggs_nr > 0 THEN
RAISE EXCEPTION 'Downgrade is impossible since % continuous aggregates exist which use variable buckets: %', caggs_nr, caggs
USING HINT = 'Remove the corresponding continuous aggregates manually before downgrading';
END IF;
-- It's safe to drop the table.
-- ALTER EXTENSION is required to revert the effect of pg_extension_config_dump()
-- See "The list of tables configured to be dumped" test in test/sql/updates/post.catalog.sql
ALTER EXTENSION timescaledb DROP TABLE _timescaledb_catalog.continuous_aggs_bucket_function;
-- Actually drop the table.
-- ALTER EXTENSION only removes the table from the extension but doesn't drop it.
DROP TABLE IF EXISTS _timescaledb_catalog.continuous_aggs_bucket_function;
-- Drop overloaded versions of invalidation_process_hypertable_log() and invalidation_process_cagg_log()
-- with bucket_functions argument.
ALTER EXTENSION timescaledb DROP FUNCTION _timescaledb_internal.invalidation_process_hypertable_log(
mat_hypertable_id INTEGER,
raw_hypertable_id INTEGER,
dimtype REGTYPE,
mat_hypertable_ids INTEGER[],
bucket_widths BIGINT[],
max_bucket_widths BIGINT[],
bucket_functions TEXT[]
);
DROP FUNCTION IF EXISTS _timescaledb_internal.invalidation_process_hypertable_log(
mat_hypertable_id INTEGER,
raw_hypertable_id INTEGER,
dimtype REGTYPE,
mat_hypertable_ids INTEGER[],
bucket_widths BIGINT[],
max_bucket_widths BIGINT[],
bucket_functions TEXT[]
);
ALTER EXTENSION timescaledb DROP FUNCTION _timescaledb_internal.invalidation_process_cagg_log(
mat_hypertable_id INTEGER,
raw_hypertable_id INTEGER,
dimtype REGTYPE,
window_start BIGINT,
window_end BIGINT,
mat_hypertable_ids INTEGER[],
bucket_widths BIGINT[],
max_bucket_widths BIGINT[],
bucket_functions TEXT[],
OUT ret_window_start BIGINT,
OUT ret_window_end BIGINT
);
DROP FUNCTION IF EXISTS _timescaledb_internal.invalidation_process_cagg_log(
mat_hypertable_id INTEGER,
raw_hypertable_id INTEGER,
dimtype REGTYPE,
window_start BIGINT,
window_end BIGINT,
mat_hypertable_ids INTEGER[],
bucket_widths BIGINT[],
max_bucket_widths BIGINT[],
bucket_functions TEXT[],
OUT ret_window_start BIGINT,
OUT ret_window_end BIGINT
);
END
$$ LANGUAGE 'plpgsql';