Skip to content

Instantly share code, notes, and snippets.

View itsmeduncan's full-sized avatar

Duncan Grazier itsmeduncan

View GitHub Profile
@pguelpa
pguelpa / gist:5935df7e90a46d49f681
Created March 30, 2015 22:52
PostgreSQL Reaper
DO $$DECLARE row record;
BEGIN
FOR row IN SELECT pid, query FROM pg_stat_activity WHERE query_start < NOW() - interval '30 minutes' LOOP
RAISE NOTICE 'Killing query: %s', row.query;
PERFORM pg_cancel_backend(row.pid);
END LOOP;
END$$;