Re: Hard problem with concurrency

Поиск
Список
Период
Сортировка
От Christopher Kings-Lynne
Тема Re: Hard problem with concurrency
Дата
Msg-id 024a01c2d642$7aae8b00$6500a8c0@fhp.internal
обсуждение исходный текст
Ответ на Hard problem with concurrency  ("Christopher Kings-Lynne" <chriskl@familyhealth.com.au>)
Ответы Re: Hard problem with concurrency  (Bruce Momjian <pgman@candle.pha.pa.us>)
Список pgsql-hackers
> If you don't have a primary key already, create a unique index on the
> combination you want to be unique. Then:
>
> . Try to insert the record
> . If you get a duplicate key error
>   then do update instead
>
> No possibilities of duplicate records due to race conditions. If two
people
> try to insert/update at the same time you'll only get one of the two
results,
> but that's the downside of the general approach you've taken. It's a tad
> inefficient if the usual case is updates, but certainly not less efficient
> than doing table locks.

The idea was to stop our postgres logs being spammed up with unique
constraint violation warnings....in which case your solution above is
identical to our current one.  Update and if it fails, insert, except since
the row is likely to already be there - our current way will be a bit more
efficient.

Chris



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

Предыдущее
От: Greg Stark
Дата:
Сообщение: Re: Hard problem with concurrency
Следующее
От: Ryan Bradetich
Дата:
Сообщение: Questions about indexes?