Re: regarding threads and transactions - problem 2

From: Martijn van Oosterhout <kleptog(at)svana(dot)org>
To: Surabhi Ahuja <surabhi(dot)ahuja(at)iiitb(dot)ac(dot)in>
Cc: pgsql-general(at)postgresql(dot)org, pingo(dot)bgm(at)gmail(dot)com
Subject: Re: regarding threads and transactions - problem 2
Date: 2005-08-26 08:10:40
Message-ID: 20050826081035.GB4848@svana.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Fri, Aug 26, 2005 at 01:28:51PM +0530, Surabhi Ahuja wrote:
> Dear All,
>
> This is in reference to a problem which I had put up sometime back.
> Please take some time to study it
>
> The piece of code that i am trying to execute is attached (itsa cpp file)
> The stored procedure (that the program calls) insert_patient is as follows:

Firstly, this has nothing to do with threads. Any programs executing
this in parallel would have the same problem.

> Please check the block in red. Why is it happening? insnt the call to the stored procedure considered one atomic operation?
> Please tell me what is going wrong?
>
> Cant I avoid such red blocks? and get messages like the ones obained from the other threads
> I can impose locks but would not that lower down the performance?
> Please suggest other solutions

Well, you guarentee atomicity by using locks. And yes, locks do
decrease performance overall. Since you don't take any locks the
procedure can execute in parallel with anything else.

Your options are:
1. Lock the table in the procedure
2. Change to using a system that doesn't require such a strange update
procedure.
3. Trap the error and retry.

Option 2 would be the best, though option 3 would be faster than
option 1.

Hope this helps,
--
Martijn van Oosterhout <kleptog(at)svana(dot)org> http://svana.org/kleptog/
> Patent. n. Genius is 5% inspiration and 95% perspiration. A patent is a
> tool for doing 5% of the work and then sitting around waiting for someone
> else to do the other 95% so you can sue them.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Richard Huxton 2005-08-26 08:20:03 Re: Altering built-in functions cast
Previous Message Surabhi Ahuja 2005-08-26 07:58:51 regarding threads and transactions - problem 2