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 ;
@Mahmoud-Elbahnasawy
Copy link

i tested it but it does behave as expected
in sql server there is a variable called @@trancount that is able to specify the number of open transaction (uncommitted)
but i can't find a way in postgres to give me the same behavior
Any way thank you

@Mahmoud-Elbahnasawy
Copy link

This worked for me
select count(*)
from pg_locks
where pid = pg_backend_pid()
and locktype in ('transactionid')

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