473,408 Members | 1,876 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

Trouble with locking tables - reg.

Dear Group,
We are using Postgresql 7.3.4 on Redhat 8.0 with
Java 1.4.2. We are developing our applications in Java. We call stored
procedures from the java program. Order numbers are generated by many
departments in the Hospital. We manitain a single table from which to
select the order number. The way this works is that the order numbers
are released for reuse if the order has been completed. We wrote a
procedure in plpgsql with a transaction which locks the table for
concurrency problem. When more than one person tries to generate an
order number (by running the java program) still there arise the
concurrency problem.

We tried to check how the procedures with transaction that
locks the table works . what we did to check the procedure was as follows
we have one database server.
we took two computer systems. in both system we opened
one terminal (linux).
let the value of the order number be 50.
[1] in one system's terminal we started the transaction
using begin; lock table <table name>;
[2] in another system we run the procedure which fetch
the order number from the locked table ,display it -increment it - store
it in the table again using update statement (not like order number =
order number + 1) but like (x =order number +1), again we fetched the
value of the order number from the table and display it . the procedure
is as follows:

CREATE OR REPLACE FUNCTION CHECKING() RETURNS TEXT AS'
DECLARE
XVAL INTEGER;
BEGIN
BEGIN
LOCK TABLE CHECKING_LOCK;
SELECT INTO XVAL X FROM CHECKING_LOCK WHERE Y = TRUE;
RAISE NOTICE ''X BEF %'',XVAL;
XVAL := XVAL + 1;
UPDATE CHECKING_LOCK SET X = XVAL WHERE Y = TRUE;
SELECT INTO XVAL X FROM CHECKING_LOCK WHERE Y = TRUE;
RAISE NOTICE ''X AFT %'',XVAL;
END;
RETURN ''OK'';
END;
'LANGUAGE 'PLPGSQL';

Now this procedure waits for the other transaction to complete
[3] in the other system's terminal i update the field value -
increment it by 1 and entered end; to commit the transaction
[4] automatically the procedure runs and displays the result
As per transaction isolation level ( read committed being the
default isolation level) it should be 51 and 52.
as when the transaction in the terminal update it to 51 , the
transaction in the procedure which was waiting should fetch it as 51 and
increment it by 1 (52) and set the field value to 52 and when fetched
after update should return it the value as 52. this is what we want.
but what is the actual is ,
The final result the procedure displays is 50 before update and 50
after update.
when i verified in the database table it shows the field value as
51.
how to make it to our expectation.

Your immediate response in this regard is very much appreciate.
Thanking you,

Yours sincerely,

Shan.


---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to ma*******@postgresql.org

Nov 23 '05 #1
0 1166

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Steve McWilliams | last post by:
Hello, I am relatively new to MySql (4.0.14) but I have read through the relevent documentation and am still confused about how row level locking behaves with InnoDB tables. I created a...
9
by: john smile | last post by:
Hi All, I want to lock 2 tables on 2 servers using TABLOCKX hint. These tables function as semaphores in my application. It means when the tables are locked then other users will not be able to...
4
by: Sam | last post by:
Hello everyone, I have around 20 reports in an ASP web-application which connects to a SQL Server 2000 dB, executes stored procedures based on input parameters and returns the data in a nice...
8
by: arijitchatterjee123 | last post by:
Hi Group, I am facing a problem regarding locking. I have created a Stored Procedure in my Database. In this Stored Procedure Temprary Tables get created and after that values are inserted in...
3
by: Elias Farah | last post by:
Dear Access Peers, I am having a problem over a network, where the Database takes 5-Mins to load instead of the normal 5 seconds. It has only started to do this since I split the frontend &...
9
by: TD | last post by:
I am trying to add transactions to my code. The original code worked fine until I followed an example to setup transactions, now the code does strange things, but no error messages. Could...
2
by: Peter | last post by:
(I've tried this Q in the ms forums without response. See how it goes here.) Using A2003 but I guess this is not version-specific... If I want to implement row/record level locking on a split...
1
by: jimi_usenet | last post by:
Hi, Can anyone tell me if MySQL uses optimistic or pessimistic locking with InnoDB tables? And can this be modified in any way? When I use the search function on the mysql site, it only gives me...
7
dlite922
by: dlite922 | last post by:
I need to do some sort of Locking mechanism at interface level, instead of DB Level. I know how MySQL table locking works, but that won't work in my scenerio. Requirements: When someone is...
9
by: zmickle | last post by:
Experts and books all say that you can share an Access back end on a shared drive with the front end running on each host computer. I have a simple database that tracks student data and it is...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.