Обсуждение: any way to check if a transaction is active?

Поиск
Список
Период
Сортировка

any way to check if a transaction is active?

От
Mario Weilguni
Дата:
I'm trying to find some method to detect wether a real transaction is in progress. With "real" I mean a transaction
explicitlystarted 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
towrite a extension function in C if this is necessary, but I've no 
clue where to start?

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

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

Best regards,
    Mario Weilguni

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

От
Richard Huxton
Дата:
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