Re: PostgreSQL 8.4.8 bringing my website down every evening

Поиск
Список
Период
Сортировка
От Alban Hertroys
Тема Re: PostgreSQL 8.4.8 bringing my website down every evening
Дата
Msg-id 7572A704-FF98-4271-B7FE-6C0B4CFFE15C@solfertje.student.utwente.nl
обсуждение исходный текст
Ответ на Re: PostgreSQL 8.4.8 bringing my website down every evening  (Alexander Farber <alexander.farber@gmail.com>)
Ответы Re: PostgreSQL 8.4.8 bringing my website down every evening
Список 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'san 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
objectinstead. 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!



В списке pgsql-general по дате отправления:

Предыдущее
От: Gavin Flower
Дата:
Сообщение: Re: unique across two tables
Следующее
От: Dave Coventry
Дата:
Сообщение: Postgres errors in Drupal install.