Re: [INTERFACES] locking on database updates

From: Rich Shepard <rshepard(at)appl-ecosys(dot)com>
To: Gary Stainburn <gary(dot)stainburn(at)ringways(dot)co(dot)uk>
Cc: "'Pgsql Interfaces'" <pgsql-interfaces(at)postgreSQL(dot)org>
Subject: Re: [INTERFACES] locking on database updates
Date: 1999-12-06 18:20:14
Message-ID: Pine.LNX.4.10.9912061016440.4887-100000@salmo.appl-ecosys.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-interfaces

On Mon, 6 Dec 1999, Gary Stainburn wrote:

> Pseudo Code
>
> Select & lock record
> increment number
> Update record
> Unlock record

What I learned from writing databases in Paradox/DOS is to change the
sequence so that steps 2 and 3 are switched. That is, wait until the record
is committed to be added, then grab the next number and assign it.

The advantage is that if the record is not added (user changed her mind or
had to go do something else right away), the ID table is untouched. Also,
assigning the unique number just before writing the record means that the ID
table is locked, incremented and unlocked very quickly. No one is slowed
down by this process.

HTH,

Rich

Dr. Richard B. Shepard, President

Applied Ecosystem Services, Inc. (TM)
Making environmentally-responsible mining happen. (SM)
--------------------------------
2404 SW 22nd Street | Troutdale, OR 97060-1247 | U.S.A.
+ 1 503-667-4517 (voice) | + 1 503-667-8863 (fax) | rshepard(at)appl-ecosys(dot)com

In response to

Browse pgsql-interfaces by date

  From Date Subject
Next Message Tom Lane 1999-12-07 01:14:21 Re: [INTERFACES] locking on database updates
Previous Message Gary Stainburn 1999-12-06 17:16:27 locking on database updates