Re: Can Postgres Not Do This Safely ?!?

Поиск
Список
Период
Сортировка
От Jeff Davis
Тема Re: Can Postgres Not Do This Safely ?!?
Дата
Msg-id 1288396778.2410.14.camel@jdavis-ux.asterdata.local
обсуждение исходный текст
Ответ на Re: Can Postgres Not Do This Safely ?!?  (Andy Colson <andy@squeakycode.net>)
Ответы Re: Can Postgres Not Do This Safely ?!?  (bricklen <bricklen@gmail.com>)
Re: Can Postgres Not Do This Safely ?!?  (Merlin Moncure <mmoncure@gmail.com>)
Список pgsql-general
On Fri, 2010-10-29 at 16:57 -0500, Andy Colson wrote:
> begin
> insert into logged select * from events where processed = false;
> update events set processed = true where processed = false;
> commit;

There's a race condition there. The SELECT in the INSERT statement may
read 5 tuples, then a concurrent transaction inserts a 6th tuple, then
you do an update on all 6 tuples.

> begin
> select * from events where processed = false;
> ... do you processing on each, which would include inserting it...
> update events set processed = true where processed = false;
> commit;

Same problem here.

> Just make sure you do it all in the same transaction, so the update sees
> the exact same set as the select.

You need to use SERIALIZABLE isolation level for this to work. The
default is READ COMMITTED.

Or better yet, use Merlin's suggestion of PgQ. They've already worked
this out in a safe, efficient way. It's the basis for Londiste, a
replication system.

Regards,
    Jeff Davis


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

Предыдущее
От: Dale Seaburg
Дата:
Сообщение: Paradox to postgresql interface
Следующее
От: "Joshua D. Drake"
Дата:
Сообщение: Re: Paradox to postgresql interface