-
Notifications
You must be signed in to change notification settings - Fork 891
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add functions to enable/disable policies
- Loading branch information
1 parent
6f038ec
commit 6116ec6
Showing
8 changed files
with
495 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Implements: #6116 Add functions to enable/disable hypertable policies | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -128,4 +128,93 @@ CREATE OR REPLACE FUNCTION timescaledb_experimental.show_policies( | |
relation REGCLASS) | ||
RETURNS SETOF JSONB | ||
AS '@MODULE_PATHNAME@', 'ts_policies_show' | ||
LANGUAGE C VOLATILE; | ||
LANGUAGE C VOLATILE; | ||
|
||
CREATE OR REPLACE FUNCTION _timescaledb_functions.set_policy_scheduled(hypertable REGCLASS, policy_type TEXT, scheduled BOOL) | ||
RETURNS INTEGER | ||
AS $$ | ||
WITH affected_policies AS ( | ||
SELECT @[email protected]_job(j.id, scheduled => set_policy_scheduled.scheduled) | ||
FROM _timescaledb_config.bgw_job j | ||
JOIN _timescaledb_catalog.hypertable h ON h.id = j.hypertable_id | ||
WHERE j.proc_schema IN ('_timescaledb_internal', '_timescaledb_functions') | ||
AND j.proc_name = set_policy_scheduled.policy_type | ||
AND j.id >= 1000 | ||
AND scheduled <> set_policy_scheduled.scheduled | ||
AND format('%I.%I', h.schema_name, h.table_name) = set_policy_scheduled.hypertable::text | ||
) | ||
SELECT count(*) FROM affected_policies; | ||
$$ | ||
LANGUAGE SQL SET search_path TO pg_catalog, pg_temp; | ||
|
||
CREATE OR REPLACE FUNCTION _timescaledb_functions.set_all_policy_scheduled(hypertable REGCLASS, scheduled BOOL) | ||
RETURNS INTEGER | ||
AS $$ | ||
WITH affected_policies AS ( | ||
SELECT @[email protected]_job(j.id, scheduled => set_all_policy_scheduled.scheduled) | ||
FROM _timescaledb_config.bgw_job j | ||
JOIN _timescaledb_catalog.hypertable h ON h.id = j.hypertable_id | ||
WHERE j.proc_schema IN ('_timescaledb_internal', '_timescaledb_functions') | ||
AND j.id >= 1000 | ||
AND scheduled <> set_all_policy_scheduled.scheduled | ||
AND format('%I.%I', h.schema_name, h.table_name) = set_all_policy_scheduled.hypertable::text | ||
) | ||
SELECT count(*) FROM affected_policies; | ||
$$ | ||
LANGUAGE SQL SET search_path TO pg_catalog, pg_temp; | ||
|
||
CREATE OR REPLACE FUNCTION @[email protected]_all_policies(hypertable REGCLASS) | ||
RETURNS INTEGER | ||
AS $$ | ||
SELECT _timescaledb_functions.set_all_policy_scheduled(hypertable, false); | ||
$$ | ||
LANGUAGE SQL SET search_path TO pg_catalog, pg_temp; | ||
|
||
CREATE OR REPLACE FUNCTION @[email protected]_all_policies(hypertable REGCLASS) | ||
RETURNS INTEGER | ||
AS $$ | ||
SELECT _timescaledb_functions.set_all_policy_scheduled(hypertable, true); | ||
$$ | ||
LANGUAGE SQL SET search_path TO pg_catalog, pg_temp; | ||
|
||
CREATE OR REPLACE FUNCTION @[email protected]_compression_policy(hypertable REGCLASS) | ||
RETURNS INTEGER | ||
AS $$ | ||
SELECT _timescaledb_functions.set_policy_scheduled(hypertable, 'policy_compression', false); | ||
$$ | ||
LANGUAGE SQL SET search_path TO pg_catalog, pg_temp; | ||
|
||
CREATE OR REPLACE FUNCTION @[email protected]_compression_policy(hypertable REGCLASS) | ||
RETURNS INTEGER | ||
AS $$ | ||
SELECT _timescaledb_functions.set_policy_scheduled(hypertable, 'policy_compression', true); | ||
$$ | ||
LANGUAGE SQL SET search_path TO pg_catalog, pg_temp; | ||
|
||
CREATE OR REPLACE FUNCTION @[email protected]_reorder_policy(hypertable REGCLASS) | ||
RETURNS INTEGER | ||
AS $$ | ||
SELECT _timescaledb_functions.set_policy_scheduled(hypertable, 'policy_reorder', false); | ||
$$ | ||
LANGUAGE SQL SET search_path TO pg_catalog, pg_temp; | ||
|
||
CREATE OR REPLACE FUNCTION @[email protected]_reorder_policy(hypertable REGCLASS) | ||
RETURNS INTEGER | ||
AS $$ | ||
SELECT _timescaledb_functions.set_policy_scheduled(hypertable, 'policy_reorder', true); | ||
$$ | ||
LANGUAGE SQL SET search_path TO pg_catalog, pg_temp; | ||
|
||
CREATE OR REPLACE FUNCTION @[email protected]_retention_policy(hypertable REGCLASS) | ||
RETURNS INTEGER | ||
AS $$ | ||
SELECT _timescaledb_functions.set_policy_scheduled(hypertable, 'policy_retention', false); | ||
$$ | ||
LANGUAGE SQL SET search_path TO pg_catalog, pg_temp; | ||
|
||
CREATE OR REPLACE FUNCTION @[email protected]_retention_policy(hypertable REGCLASS) | ||
RETURNS INTEGER | ||
AS $$ | ||
SELECT _timescaledb_functions.set_policy_scheduled(hypertable, 'policy_retention', true); | ||
$$ | ||
LANGUAGE SQL SET search_path TO pg_catalog, pg_temp; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -179,3 +179,93 @@ DROP TABLE _timescaledb_internal.tmp_chunk_seq_value; | |
GRANT SELECT ON _timescaledb_catalog.chunk_id_seq TO PUBLIC; | ||
GRANT SELECT ON _timescaledb_catalog.chunk TO PUBLIC; | ||
-- end recreate _timescaledb_catalog.chunk table -- | ||
|
||
CREATE FUNCTION _timescaledb_functions.set_policy_scheduled(hypertable REGCLASS, policy_type TEXT, scheduled BOOL) | ||
RETURNS INTEGER | ||
AS $$ | ||
WITH affected_policies AS ( | ||
SELECT @[email protected]_job(j.id, scheduled => set_policy_scheduled.scheduled) | ||
FROM _timescaledb_config.bgw_job j | ||
JOIN _timescaledb_catalog.hypertable h ON h.id = j.hypertable_id | ||
WHERE j.proc_schema IN ('_timescaledb_internal', '_timescaledb_functions') | ||
AND j.proc_name = set_policy_scheduled.policy_type | ||
AND j.id >= 1000 | ||
AND scheduled <> set_policy_scheduled.scheduled | ||
AND format('%I.%I', h.schema_name, h.table_name) = set_policy_scheduled.hypertable::text | ||
) | ||
SELECT count(*) FROM affected_policies; | ||
$$ | ||
LANGUAGE SQL SET search_path TO pg_catalog, pg_temp; | ||
|
||
CREATE FUNCTION _timescaledb_functions.set_all_policy_scheduled(hypertable REGCLASS, scheduled BOOL) | ||
RETURNS INTEGER | ||
AS $$ | ||
WITH affected_policies AS ( | ||
SELECT @[email protected]_job(j.id, scheduled => set_all_policy_scheduled.scheduled) | ||
FROM _timescaledb_config.bgw_job j | ||
JOIN _timescaledb_catalog.hypertable h ON h.id = j.hypertable_id | ||
WHERE j.proc_schema IN ('_timescaledb_internal', '_timescaledb_functions') | ||
AND j.id >= 1000 | ||
AND scheduled <> set_all_policy_scheduled.scheduled | ||
AND format('%I.%I', h.schema_name, h.table_name) = set_all_policy_scheduled.hypertable::text | ||
) | ||
SELECT count(*) FROM affected_policies; | ||
$$ | ||
LANGUAGE SQL SET search_path TO pg_catalog, pg_temp; | ||
|
||
CREATE FUNCTION @[email protected]_all_policies(hypertable REGCLASS) | ||
RETURNS INTEGER | ||
AS $$ | ||
SELECT _timescaledb_functions.set_all_policy_scheduled(hypertable, false); | ||
$$ | ||
LANGUAGE SQL SET search_path TO pg_catalog, pg_temp; | ||
|
||
CREATE FUNCTION @[email protected]_all_policies(hypertable REGCLASS) | ||
RETURNS INTEGER | ||
AS $$ | ||
SELECT _timescaledb_functions.set_all_policy_scheduled(hypertable, true); | ||
$$ | ||
LANGUAGE SQL SET search_path TO pg_catalog, pg_temp; | ||
|
||
CREATE FUNCTION @[email protected]_compression_policy(hypertable REGCLASS) | ||
RETURNS INTEGER | ||
AS $$ | ||
SELECT _timescaledb_functions.set_policy_scheduled(hypertable, 'policy_compression', false); | ||
$$ | ||
LANGUAGE SQL SET search_path TO pg_catalog, pg_temp; | ||
|
||
CREATE FUNCTION @[email protected]_compression_policy(hypertable REGCLASS) | ||
RETURNS INTEGER | ||
AS $$ | ||
SELECT _timescaledb_functions.set_policy_scheduled(hypertable, 'policy_compression', true); | ||
$$ | ||
LANGUAGE SQL SET search_path TO pg_catalog, pg_temp; | ||
|
||
CREATE FUNCTION @[email protected]_reorder_policy(hypertable REGCLASS) | ||
RETURNS INTEGER | ||
AS $$ | ||
SELECT _timescaledb_functions.set_policy_scheduled(hypertable, 'policy_reorder', false); | ||
$$ | ||
LANGUAGE SQL SET search_path TO pg_catalog, pg_temp; | ||
|
||
CREATE FUNCTION @[email protected]_reorder_policy(hypertable REGCLASS) | ||
RETURNS INTEGER | ||
AS $$ | ||
SELECT _timescaledb_functions.set_policy_scheduled(hypertable, 'policy_reorder', true); | ||
$$ | ||
LANGUAGE SQL SET search_path TO pg_catalog, pg_temp; | ||
|
||
CREATE FUNCTION @[email protected]_retention_policy(hypertable REGCLASS) | ||
RETURNS INTEGER | ||
AS $$ | ||
SELECT _timescaledb_functions.set_policy_scheduled(hypertable, 'policy_retention', false); | ||
$$ | ||
LANGUAGE SQL SET search_path TO pg_catalog, pg_temp; | ||
|
||
CREATE FUNCTION @[email protected]_retention_policy(hypertable REGCLASS) | ||
RETURNS INTEGER | ||
AS $$ | ||
SELECT _timescaledb_functions.set_policy_scheduled(hypertable, 'policy_retention', true); | ||
$$ | ||
LANGUAGE SQL SET search_path TO pg_catalog, pg_temp; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -124,3 +124,14 @@ GRANT SELECT ON _timescaledb_catalog.chunk_id_seq TO PUBLIC; | |
GRANT SELECT ON _timescaledb_catalog.chunk TO PUBLIC; | ||
|
||
-- end recreate _timescaledb_catalog.chunk table -- | ||
|
||
DROP FUNCTION _timescaledb_functions.set_policy_scheduled(hypertable REGCLASS, policy_type TEXT, scheduled BOOL); | ||
DROP FUNCTION _timescaledb_functions.set_all_policy_scheduled(hypertable REGCLASS, scheduled BOOL); | ||
DROP FUNCTION @[email protected]_all_policies(hypertable REGCLASS); | ||
DROP FUNCTION @[email protected]_all_policies(hypertable REGCLASS); | ||
DROP FUNCTION @[email protected]_compression_policy(hypertable REGCLASS); | ||
DROP FUNCTION @[email protected]_compression_policy(hypertable REGCLASS); | ||
DROP FUNCTION @[email protected]_reorder_policy(hypertable REGCLASS); | ||
DROP FUNCTION @[email protected]_reorder_policy(hypertable REGCLASS); | ||
DROP FUNCTION @[email protected]_retention_policy(hypertable REGCLASS); | ||
DROP FUNCTION @[email protected]_retention_policy(hypertable REGCLASS); |
Oops, something went wrong.