Re: any way to check if a transaction is active?

From: Richard Huxton <dev(at)archonet(dot)com>
To: Mario Weilguni <mweilguni(at)sime(dot)com>, pgsql-general(at)postgresql(dot)org
Subject: Re: any way to check if a transaction is active?
Date: 2002-08-08 14:22:53
Message-ID: 200208081522.53644.dev@archonet.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Thursday 08 Aug 2002 7:57 am, Mario Weilguni wrote:
> I'm trying to find some method to detect wether a real transaction is in
> progress. With "real" I mean a transaction explicitly started with "begin",
> not the auto-transactions postgres puts around single statements. Is there
> a function that can be used for this? It's ok for me to write a extension
> function in C if this is necessary, but I've no clue where to start?

Can't think of a good way to do this - you can query the states of the
backends using "ps" since Postgresql modifies the command-line displayed. If
you want to write some C I'd start looking at the code that does that.

Also, check the statistics analyser, although I can't think of anything that
says whether you're in a transaction.

> The reason why I need this is this one:
> * I use a database wrapper in PHP to stay compatible with Oracle
> * whenever I issue a rollback without any prior transaction, the apache
> error log will have a line NOTICE: ROLLBACK: no transaction in progress
> ROLLBACK

Is there not some way to flag whether you issue a BEGIN? If you don't know
whether you are in a transaction, how do you know what you are rolling back?

Another option would be to always issue a BEGIN at script startup and a COMMIT
or ROLLBACK at script end.

> This makes the error log unreadable, so I'm trying to get rid of this. Any
> idea how?

Or - just post-process the apache log with sed/awk/perl.

HTH

- Richard Huxton

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Richard Huxton 2002-08-08 14:24:17 Re: looking to speed up SELECT ... LEFT JOIN query
Previous Message Elielson Fontanezi 2002-08-08 13:57:22 RES: RES: [SQL] 3-tier