mirror of
https://github.com/timescale/timescaledb.git
synced 2025-05-14 17:43:34 +08:00
To increase schema security we do not want to mix our own internal objects with user objects. Since chunks are created in the _timescaledb_internal schema our internal functions should live in a different dedicated schema. This patch make the necessary adjustments for the following functions: - restart_background_workers() - stop_background_workers() - start_background_workers() - alter_job_set_hypertable_id(integer,regclass)
43 lines
1.6 KiB
PL/PgSQL
43 lines
1.6 KiB
PL/PgSQL
-- This file and its contents are licensed under the Apache License 2.0.
|
|
-- Please see the included NOTICE for copyright information and
|
|
-- LICENSE-APACHE for a copy of the license.
|
|
|
|
CREATE OR REPLACE FUNCTION @extschema@.timescaledb_pre_restore() RETURNS BOOL AS
|
|
$BODY$
|
|
DECLARE
|
|
db text;
|
|
BEGIN
|
|
SELECT current_database() INTO db;
|
|
EXECUTE format($$ALTER DATABASE %I SET timescaledb.restoring ='on'$$, db);
|
|
SET SESSION timescaledb.restoring = 'on';
|
|
PERFORM _timescaledb_functions.stop_background_workers();
|
|
--exported uuid may be included in the dump so backup the version
|
|
UPDATE _timescaledb_catalog.metadata SET key='exported_uuid_bak' WHERE key='exported_uuid';
|
|
RETURN true;
|
|
END
|
|
$BODY$
|
|
LANGUAGE PLPGSQL SET search_path TO pg_catalog, pg_temp;
|
|
|
|
|
|
CREATE OR REPLACE FUNCTION @extschema@.timescaledb_post_restore() RETURNS BOOL AS
|
|
$BODY$
|
|
DECLARE
|
|
db text;
|
|
BEGIN
|
|
SELECT current_database() INTO db;
|
|
EXECUTE format($$ALTER DATABASE %I RESET timescaledb.restoring $$, db);
|
|
-- we cannot use reset here because the reset_val might not be off
|
|
SET timescaledb.restoring TO off;
|
|
PERFORM _timescaledb_functions.restart_background_workers();
|
|
|
|
--try to restore the backed up uuid, if the restore did not set one
|
|
INSERT INTO _timescaledb_catalog.metadata
|
|
SELECT 'exported_uuid', value, include_in_telemetry FROM _timescaledb_catalog.metadata WHERE key='exported_uuid_bak'
|
|
ON CONFLICT DO NOTHING;
|
|
DELETE FROM _timescaledb_catalog.metadata WHERE key='exported_uuid_bak';
|
|
|
|
RETURN true;
|
|
END
|
|
$BODY$
|
|
LANGUAGE PLPGSQL SET search_path TO pg_catalog, pg_temp;
|