gc.sql (2174B)
1 -- 2 -- This file is part of TALER 3 -- Copyright (C) 2026 Taler Systems SA 4 -- 5 -- TALER is free software; you can redistribute it and/or modify it under the 6 -- terms of the GNU General Public License as published by the Free Software 7 -- Foundation; either version 3, or (at your option) any later version. 8 -- 9 -- TALER is distributed in the hope that it will be useful, but WITHOUT ANY 10 -- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 11 -- A PARTICULAR PURPOSE. See the GNU General Public License for more details. 12 -- 13 -- You should have received a copy of the GNU General Public License along with 14 -- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> 15 -- 16 17 DROP PROCEDURE IF EXISTS merchant_do_gc; 18 CREATE PROCEDURE merchant_do_gc(in_now INT8) 19 LANGUAGE plpgsql 20 AS $$ 21 DECLARE 22 rec RECORD; 23 s TEXT; 24 BEGIN 25 -- Per-instance GC: loop over all instances and run the 26 -- per-instance GC helpers + targeted DELETEs in each schema. 27 FOR rec IN SELECT merchant_serial FROM merchant.merchant_instances 28 LOOP 29 s := 'merchant_instance_' || rec.merchant_serial::TEXT; 30 BEGIN 31 EXECUTE format('SET LOCAL search_path TO %I, merchant', s); 32 EXECUTE format('CALL %I.merchant_statistic_amount_gc()', s); 33 EXECUTE format('CALL %I.merchant_statistic_bucket_gc()', s); 34 EXECUTE format('CALL %I.merchant_statistic_counter_gc()', s); 35 EXECUTE format('DELETE FROM %I.merchant_unclaim_signatures' 36 ' WHERE expiration_time < $1', s) USING in_now; 37 EXCEPTION 38 WHEN undefined_table THEN 39 NULL; 40 WHEN undefined_function THEN 41 NULL; 42 END; 43 COMMIT; 44 END LOOP; 45 DELETE FROM merchant.tan_challenges 46 WHERE expiration_date < $1; 47 -- Restore the global search_path so subsequent statements on this 48 -- session don't leak into the last visited instance schema. 49 SET LOCAL search_path TO merchant; 50 END $$; 51 COMMENT ON PROCEDURE merchant_do_gc 52 IS 'Calls per-instance garbage collection subroutines across every instance.' 53 ' For each' 54 ' instance runs merchant_statistic_*_gc and DELETEs expired tan_challenges' 55 ' / merchant_unclaim_signatures.'; 56 57 COMMIT;