From: | Alban Hertroys <dalroi(at)solfertje(dot)student(dot)utwente(dot)nl> |
---|---|
To: | Alexander Farber <alexander(dot)farber(at)gmail(dot)com> |
Cc: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: PostgreSQL 8.4.8 bringing my website down every evening |
Date: | 2011-06-25 11:22:58 |
Message-ID: | 7572A704-FF98-4271-B7FE-6C0B4CFFE15C@solfertje.student.utwente.nl |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
On 23 Jun 2011, at 19:48, Alexander Farber wrote:
> Sorry for the late reply - but I still haven't found a solution,
> for example I have a PHP script with 5 consecutive SELECT
> statements (source code + problem described again under:
>
> http://stackoverflow.com/questions/6458246/php-and-pgbouncer-in-transaction-mode-current-transaction-is-aborted
>
> ) and if I add $db->beginTransaction(); $db->commit();
> around each $db->prepare("select ..."); execute();
> then my script will fail very often with
>
> SQLSTATE[25P02]: In failed sql transaction: 7 ERROR: current
> transaction is aborted, commands ignored until end of transaction
> block
You almost got it right, but you added too many beginTransaction/commit pairs.
You only need a beginTransaction after you set up your database connection in your function, and a commit at the very end. You're supposed to put related queries in one transaction so that they either all commit, or none of them do if there's an error in one of the statements.
As another possible improvement, I'd probably not create a new connection in every function call, but use a global $db object instead. Creating DB-connections is relatively expensive, so you don't want to do that more often than strictly necessary. In that case you could probably use beginTransaction at the start of your script and commit at the end.
But that all depends on your requirements, of course.
Alban Hertroys
--
If you can't see the forest for the trees,
cut the trees and you'll see there is no forest.
!DSPAM:737,4e05c52212095034320330!
From | Date | Subject | |
---|---|---|---|
Next Message | Rob Sargent | 2011-06-25 15:34:36 | Re: glitch installing xml support in 9.1.beta2 |
Previous Message | Guillaume Lelarge | 2011-06-25 07:10:34 | Re: glitch installing xml support in 9.1.beta2 |