Created
May 24, 2019 12:40
-
-
Save richardbasile/9741a0656c776418b5612086189d4e2e to your computer and use it in GitHub Desktop.
Find uncommitted transactions in PostgreSQL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
select * | |
from pg_stat_activity | |
where (state = 'idle in transaction') | |
and xact_start is not null ; |
This worked for me
select count(*)
from pg_locks
where pid = pg_backend_pid()
and locktype in ('transactionid')
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
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