Skip to content

Instantly share code, notes, and snippets.

@richardbasile
Created May 24, 2019 12:40
Show Gist options
  • Save richardbasile/9741a0656c776418b5612086189d4e2e to your computer and use it in GitHub Desktop.
Save richardbasile/9741a0656c776418b5612086189d4e2e to your computer and use it in GitHub Desktop.
Find uncommitted transactions in PostgreSQL
select *
from pg_stat_activity
where (state = 'idle in transaction')
and xact_start is not null ;
@bebbo
Copy link

bebbo commented Dec 7, 2024

to find transactions:

SELECT pid, state, query
FROM pg_stat_activity
WHERE state = 'active';

to abort all transactions:

SELECT pg_terminate_backend(pid)
FROM pg_stat_activity
WHERE state = 'active';

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment