Re: Detecting uncommitted changes

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Thomas Kellerer <spam_eater(at)gmx(dot)net>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Detecting uncommitted changes
Date: 2011-12-27 19:22:54
Message-ID: 13168.1325013774@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Thomas Kellerer <spam_eater(at)gmx(dot)net> writes:
> Bill Moran wrote on 27.12.2011 19:37:
>>> is there a way I can detect if the current session has any uncommitted changes?

>> If I'm understanding you correctly, you could just make it check the
>> transaction status. If there's an active transaction, then there are
>> "uncommitted changes".

> Sounds like what I want, but how do I check the "transaction status" (I'm using JDBC)

More specifically, look to see if the current transaction has assigned
itself a transaction ID. I think the easiest place to see this is in
pg_locks --- it will be holding exclusive lock on a TransactionId object
if so.

There are various cases where you could get a false positive from this
type of test, eg if a subtransaction made some changes and then rolled
back, you'll have an XID even though there's not really anything to
commit. But it will never give a false negative.

regards, tom lane

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Jacques Lamothe 2011-12-27 19:31:43 Re: UNABLE TO CONNECT REMOTELY TO port 5436 - CRITICAL
Previous Message Raymond O'Donnell 2011-12-27 19:21:05 Re: UNABLE TO CONNECT REMOTELY TO port 5436 - CRITICAL