In Microsoft MSSQL, SELECT @@TRANCOUNT method is available to get number of BEGIN TRANSACTION statements.

What is the equivalent command in PostgreSQL?


1 Answer 1


A_horse_with_no_name's comment had me curious, and it seems like PostgreSQL doesn't use transactions in the same way that you're used to in Microsoft SQL Server. Rather they use Save Points. This StackOverflow answer gives a little context about Save Points and how to track them (see the comments on the answer for additional details).

There typically can only be one transaction open at a time, but you can achieve nested transactions utilizing save points.

  • thanks for the answer. Is it true that it is not possible to keep track number of SavePoints based on dba.stackexchange.com/questions/75474/…? Correct me if I am wrong.
    – hunterex
    Jan 6, 2021 at 20:28
  • Is xact_commit same as SELECT @@TRANCOUNT? The postgresql.org/docs/11/monitoring-stats.html states that xact_commit returns number of transactions in this database that have been committed. I wonder if both methods are similar? Please advise!
    – hunterex
    Jan 6, 2021 at 20:31
  • @hunterex Unfortunately I'm not an expert on PostgreSQL but I believe that the StackOverflow question you linked is correct. And xact_commit is different because it tracks the total number of commits made in the database. @TRANCOUNT is the number of active transactions (which will inevitably return to 0 when the transaction either rollback or all of the active transactions get committed).
    – J.D.
    Jan 6, 2021 at 20:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.