Skip to content

Instantly share code, notes, and snippets.

@sumitsahoo
Created February 7, 2025 05:30
Show Gist options
  • Save sumitsahoo/1871855c6bdcb76d6765c165e41db55a to your computer and use it in GitHub Desktop.
Save sumitsahoo/1871855c6bdcb76d6765c165e41db55a to your computer and use it in GitHub Desktop.
Kill a db transaction in PostgreSQL
-- Find in progress transactions
SELECT *
FROM pg_stat_activity
WHERE state = 'idle in transaction'
AND pid <> pg_backend_pid()
AND query LIKE '%<table_name>%';
-- Kill process
SELECT pg_terminate_backend(<pid>);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment