timescaledb/sql/restoring.sql
David Kohn 35a1e357d8 Add functions for turning restoring on/off and setting license key
These functions improve usability and take all the proper steps to
set restoring on/off (and stop/start background workers in the process)
and to set the license key via a function rather than a guc modification.
2019-04-18 11:59:31 -04:00

32 lines
942 B
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 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_internal.stop_background_workers();
RETURN true;
END
$BODY$
LANGUAGE PLPGSQL;
CREATE OR REPLACE FUNCTION timescaledb_post_restore() RETURNS BOOL AS
$BODY$
DECLARE
db text;
BEGIN
SELECT current_database() INTO db;
EXECUTE format($$ALTER DATABASE %I SET timescaledb.restoring ='off'$$, db);
SET SESSION timescaledb.restoring='off';
PERFORM _timescaledb_internal.start_background_workers();
RETURN true;
END
$BODY$
LANGUAGE PLPGSQL;