473,378 Members | 1,390 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,378 software developers and data experts.

table locking.. FK tables locking on insert

I have several tables with common FKs.. the problem occurs when
performing a large number of inserts on any of the tables at the same
time. The first to start inserting seems to get a lock on the
referenced FK tables and doesn't release them until its done, forcing
the other apps to just wait... and wait..since they also seem to want a
lock for their FK tables..... something just doesnt seem right here :(

when I remove the FKs, everything goes fine.. but I need my foreign
keys.. really I do.

What does postgres do here? or is the problem in the jdbc driver.. or
maybe the server? (using Jboss 3.2.1, hibernate and 7.3.2 postgres)..

any ideas?
---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faqs/FAQ.html

Nov 12 '05 #1
4 3089

On Tue, 28 Oct 2003, Ati Rosselet wrote:
I have several tables with common FKs.. the problem occurs when
performing a large number of inserts on any of the tables at the same
time. The first to start inserting seems to get a lock on the
referenced FK tables and doesn't release them until its done, forcing
the other apps to just wait... and wait..since they also seem to want a
lock for their FK tables..... something just doesnt seem right here :(

when I remove the FKs, everything goes fine.. but I need my foreign
keys.. really I do.

What does postgres do here? or is the problem in the jdbc driver.. or
maybe the server? (using Jboss 3.2.1, hibernate and 7.3.2 postgres)..

any ideas?


A lock is grabbed on the associated pk row (so that some other transaction
can't delete it). Unfortunately that lock conflicts with other fk
modifications attempting to grab the lock. Two possible solutions involve
read locks or dirty reads. Neither of these is trivial, one will get
implemented eventually, but there's no concrete timetable.

For more details, you may want to look up info in the archives.

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

Nov 12 '05 #2
Stephan Szabo wrote:
On Tue, 28 Oct 2003, Ati Rosselet wrote:
I have several tables with common FKs.. the problem occurs when
performing a large number of inserts on any of the tables at the same
time. The first to start inserting seems to get a lock on the
referenced FK tables and doesn't release them until its done, forcing
the other apps to just wait... and wait..since they also seem to want a
lock for their FK tables..... something just doesnt seem right here :(

when I remove the FKs, everything goes fine.. but I need my foreign
keys.. really I do.

What does postgres do here? or is the problem in the jdbc driver.. or
maybe the server? (using Jboss 3.2.1, hibernate and 7.3.2 postgres)..

any ideas?


A lock is grabbed on the associated pk row (so that some other transaction
can't delete it). Unfortunately that lock conflicts with other fk
modifications attempting to grab the lock. Two possible solutions involve
read locks or dirty reads. Neither of these is trivial, one will get
implemented eventually, but there's no concrete timetable.

For more details, you may want to look up info in the archives.


This problem is fixed for v7.4 and backpatched into v7.3.4. There will
be a 7.3.5 release shortly that fixes a possible foreign key violation
related to deferred checking due to this change. So you might want to
wait for 7.3.5.
Jan

--
#================================================= =====================#
# It's easier to get forgiveness for being wrong than for being right. #
# Let's break this rule - forgive me. #
#================================================= = Ja******@Yahoo.com #
---------------------------(end of broadcast)---------------------------
TIP 9: the planner will ignore your desire to choose an index scan if your
joining column's datatypes do not match

Nov 12 '05 #3

On Mon, 3 Nov 2003, Jan Wieck wrote:
Stephan Szabo wrote:
On Tue, 28 Oct 2003, Ati Rosselet wrote:
I have several tables with common FKs.. the problem occurs when
performing a large number of inserts on any of the tables at the same
time. The first to start inserting seems to get a lock on the
referenced FK tables and doesn't release them until its done, forcing
the other apps to just wait... and wait..since they also seem to want a
lock for their FK tables..... something just doesnt seem right here :(

when I remove the FKs, everything goes fine.. but I need my foreign
keys.. really I do.

What does postgres do here? or is the problem in the jdbc driver.. or
maybe the server? (using Jboss 3.2.1, hibernate and 7.3.2 postgres)..

any ideas?


A lock is grabbed on the associated pk row (so that some other transaction
can't delete it). Unfortunately that lock conflicts with other fk
modifications attempting to grab the lock. Two possible solutions involve
read locks or dirty reads. Neither of these is trivial, one will get
implemented eventually, but there's no concrete timetable.

For more details, you may want to look up info in the archives.


This problem is fixed for v7.4 and backpatched into v7.3.4. There will


Are you sure, Jan? His problem seems to be related to inserts which AFAIK
still run the for update queries that might lock against other inserting
transactions as opposed to the update problems that I think that patch
fixed.

---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faqs/FAQ.html

Nov 12 '05 #4
Stephan Szabo wrote:
On Mon, 3 Nov 2003, Jan Wieck wrote:
Stephan Szabo wrote:
> On Tue, 28 Oct 2003, Ati Rosselet wrote:
>
>> I have several tables with common FKs.. the problem occurs when
>> performing a large number of inserts on any of the tables at the same
>> time. The first to start inserting seems to get a lock on the
>> referenced FK tables and doesn't release them until its done, forcing
>> the other apps to just wait... and wait..since they also seem to want a
>> lock for their FK tables..... something just doesnt seem right here :(
>>
>> when I remove the FKs, everything goes fine.. but I need my foreign
>> keys.. really I do.
>>
>> What does postgres do here? or is the problem in the jdbc driver.. or
>> maybe the server? (using Jboss 3.2.1, hibernate and 7.3.2 postgres)..
>>
>> any ideas?
>
> A lock is grabbed on the associated pk row (so that some other transaction
> can't delete it). Unfortunately that lock conflicts with other fk
> modifications attempting to grab the lock. Two possible solutions involve
> read locks or dirty reads. Neither of these is trivial, one will get
> implemented eventually, but there's no concrete timetable.
>
> For more details, you may want to look up info in the archives.


This problem is fixed for v7.4 and backpatched into v7.3.4. There will


Are you sure, Jan? His problem seems to be related to inserts which AFAIK
still run the for update queries that might lock against other inserting
transactions as opposed to the update problems that I think that patch
fixed.


Hmmm ... er ... you're right. His only option currently is deferring the
check then. I think we really need read locks someday.
Jan

--
#================================================= =====================#
# It's easier to get forgiveness for being wrong than for being right. #
# Let's break this rule - forgive me. #
#================================================= = Ja******@Yahoo.com #
---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster

Nov 12 '05 #5

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

Similar topics

0
by: Jacob Nielsen | last post by:
Hi, I've got two tables that control my menu on my site (which is coded in ASP). The first table (cam_menu) contains info about the sort order of the menu and the second about my content. To...
3
by: Albretch | last post by:
I am trying to insert some textual data belonging to an HTML page into a table column with 'TEXT' as data type mysql's maual _/manual.html#String_types tell you, you may insert up to (2^16 - 1),...
3
by: mahajan.sanjeev | last post by:
Hi All, I am using a SQLTransaction to insert records into a table. At one time, there are 5000 or more records to be inserted one by one. It takes some 20-25 mins for the entire process to run....
22
by: EMW | last post by:
Hi, I managed to create a SQL server database and a table in it. The table is empty and that brings me to my next chalenge: How can I get the info in the table in the dataset to go in an empty...
5
by: Gavin Scott | last post by:
Hi, I'm having a performance problem with a large database table we use with postgres 7.3.4. The table is: db=> \d log Table "public.log" Column | Type | Modifiers...
2
by: invinfo | last post by:
I don't recall exactly what options I selected in September when I installed the beta v5.0.4 on my development machine, But, as I started to develop and then backup data, I noticed that my tables...
22
by: RayPower | last post by:
I'm having problem with using DAO recordset to append record into a table and subsequent code to update other tables in a transaction. The MDB is Access 2000 with the latest service pack of JET 4....
0
by: shakahshakah | last post by:
Just started investigating InnoDB after having used MyISAM tables in the 4.0.12 version, almost immediately ran into a locking issue with INSERTs, DELETEs, and transactions. Given the following...
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.