Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mvdbeek/fc352f0f21a5eca14b8f7416f34e95e5 to your computer and use it in GitHub Desktop.
Save mvdbeek/fc352f0f21a5eca14b8f7416f34e95e5 to your computer and use it in GitHub Desktop.
delete first 100 user and history-item-less histories
BEGIN;
-- Clean up pgcleanup table
DELETE FROM cleanup_event_history_association WHERE cleanup_event_history_association.history_id IN (SELECT id FROM history WHERE history.user_id is null AND history.hid_counter = 1 ORDER BY history.update_time LIMIT 100);
-- Clean up audit table
DELETE FROM history_audit WHERE history_audit.history_id IN (select id from history where history.user_id is null and history.hid_counter = 1 ORDER BY history.update_time LIMIT 100);
-- Cleanup galaxy_session_to_history
DELETE FROM galaxy_session_to_history WHERE galaxy_session_to_history.session_id IN (SELECT galaxy_session.id FROM galaxy_session WHERE galaxy_session.current_history_id IN (SELECT history.id FROM history WHERE history.user_id is null AND history.hid_counter = 1 ORDER BY history.update_time LIMIT 100));
-- Clean up galaxy_session
DELETE FROM galaxy_session WHERE galaxy_session.current_history_id IN (select id from history where history.user_id is null AND history.hid_counter = 1 ORDER BY history.update_time LIMIT 100);
-- Now clean up actual history table (start with 100 histories)
DELETE FROM history where id in (select id from history where history.user_id is null and history.hid_counter = 1 ORDER BY history.update_time LIMIT 100);
ROLLBACK;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment