Script to hard delete OLD records

The following script hard deletes records from the records_lb table with state=OLD and related entries in the indexers table.

SET SEARCH_PATH = '{tenantId}_mod_source_record_storage'; BEGIN; DELETE FROM marc_indexers WHERE EXISTS( SELECT 1 FROM records_lb WHERE records_lb.id = marc_indexers.marc_id AND records_lb.state = 'OLD' ); DELETE FROM records_lb WHERE state = 'OLD'; COMMIT;