Re: Tracking row updates - race condition

From: Alex Adriaanse <alex(at)alexandcarmen(dot)com>
To: hf1122x(at)protecting(dot)net
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Tracking row updates - race condition
Date: 2005-03-29 05:03:42
Message-ID: 4248E1AE.8090404@alexandcarmen.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Thanks for the input everyone. I think Harald's approach will work
well, so I'm planning on doing what he suggested, with a few
modifications. I think I can still use a sequence-backed INTEGER rather
than TIMESTAMP, and have the trigger that sets the revision to NULL also
NOTIFY the daemon that will update the revision to
nextval('revision_sequence_name') of any updates, rather than running it
from a cron job every X minutes. The updates sent to the client would
also include rows with revision = NULL so that the client would not lag
behind, at the expense of sometimes having updates sent twice to the client.

Thanks again,

Alex

Harald Fuchs wrote:

>In article <423F09CF(dot)2030008(at)alexandcarmen(dot)com>,
>Alex Adriaanse <alex(at)alexandcarmen(dot)com> writes:
>
>
>>I think that would greatly decrease the chances of a race condition
>>occurring, but I don't think it'd solve it. What if 150 other
>>revisions occur between a row update and its corresponding commit?
>>
>>
>
>How about the following:
>
>* Use a TIMESTAMP rather than a SERIAL
>* Set this timestamp to NULL in your INSERT/UPDATE trigger
>* Use a cron job to set the timestamp to current_timestamp when it's NULL
>
>This way the client would lag behind somewhat, depending on the cron
>job frequency, but it should not miss a change.
>
>

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Christopher Browne 2005-03-29 05:57:39 Re: LWM 2004 Readers' Choice Nomination
Previous Message Yudie Pg 2005-03-29 04:37:42 Re: sub query constraint