Question

Asked on 2004-12-15 at 09:37:05ID: 25475572

lock table to avoid race condition?

by: jskubick125

Rating7.6Very Good

Does Oracle have any equivalent to MySQL's feature that allows a transaction to acquire a lock on one or more tables until the lock is either explicitly released or the connection associated with it dies?

I know it's a performance-killer if applied blindly to actively-used tables, which is why I planned to use it in conjunction with a semaphore table that would only be used by threads/transactions actually performing a specific maintenance operation to ensure that only one thread/transaction can be doing maintenance on the main table at any instant in time -- allowing other threads that don't bother to look at the semaphore table to get dirty reads in the meantime without delay or interruption (relying on oracle to release the lock and roll back the transaction if something caused the thread with the lock to die or lose its connection).

My problem is that I have a table with a nested table and date field that needs to enforce uniqueness between the nested table + date pair. Oracle can't attach unique constraints to nested tables, so I need to kludge it myself... with an application that's multithreaded AND likely to be running simultaneously on multiple machines (ie, a race condition eagerly waiting to happen). I kind of came up with a gruesome Rube Goldberg-esque way to achieve it by creating a semaphore table and doing an elaborate dance of inserting, committing, sleeping, and reading until it manages to insert the one and only record in the semaphore table before doing the maintenance on the main table and removing the record from the semaphore table... but even that's vulnerable to a thread dying outright before it deletes its record from the semaphore table (adding more second-guessing into the insert-sleep-select dance).

What I'd LIKE to do is have my Connection ask Oracle, "Please let me have exclusive access to the Semaphore table (allowing me to silently wait up to xx seconds for it to become available, then notifying me that I'm out of luck if it's still not available), but roll back everything I'm about to do in this transaction and release my hold if something causes an automatic transaction rollback".

  1. How to find database table lock and send alerts
    I want to check al the Experts, if there is a way to send alerts to a group of mail ids, say AAA if there is Database table lock, for more than 10 mins If so, where to put the query, like will it be a trigger or something else, and also there would be 100s of tables, if for each table, we need to set an alert I'm using Oracle 10g and 9i databases
  2. Hash join instead of nest loops
    Hi over Solaris We have recentrly copied (exp/imp) a database from Oracle vesion 9.2 to 11.1 We have performed the same statistcs and the data is the same. A certain query (with 5 table join) started working real slow. The explain plan shows that instead of Nested loops, the optimizer now chooses Hash join. The new server…
  3. moving max outside of the nest query
    I have the following and there is a nest query. I like to move where deptno= 10 outside to the main query, but still return the same result. How? Thanks! select * from emp where hiredate in (select max(hiredate) from emp where deptno= 10);
  4. SQL Join conditions and views
    I think I have a poorly written SQL view statement on my hands. When I use the view it selects every single table A-Z in the view when I only need lets say table C and D and because the view uses equi join it and it doesn't match up it sometimes ends up going into a cartesian join which ends up giving me the ORA-04030 out of memory error. I don't want to…
  5. Create a DB Link to access 1 table only
    I want to create a db link that will have access to only 1 remote table.

Solution

Sign up now to view this solution! It's quick, easy, and secure to subscribe. We will return you to this solution, unlocked, when you’re done.

About this Solution
View This Solution - Start Your 30 Day Free Trial
Zone
General
Tags
oracle table
Participating Experts
4
Solution Grade
A

Replies

 by:

Posted on 2004-12-15 at 10:19:22ID: 28331604

All comments and solutions are available to Premium Service Members only. Sign up to view the solution to this question. Already a member? Log in to view this solution.

 by: paquicuba

Posted on 2004-12-15 at 10:24:58ID: 28331605

All comments and solutions are available to Premium Service Members only. Sign up to view the solution to this question. Already a member? Log in to view this solution.

 by: ToddBarry

Posted on 2004-12-15 at 12:21:55ID: 28331606

All comments and solutions are available to Premium Service Members only. Sign up to view the solution to this question. Already a member? Log in to view this solution.

 by: galar71

Posted on 2004-12-16 at 09:15:14ID: 28331607

All comments and solutions are available to Premium Service Members only. Sign up to view the solution to this question. Already a member? Log in to view this solution.

 by: markgeer

Posted on 2004-12-16 at 17:20:50ID: 28331608

All comments and solutions are available to Premium Service Members only. Sign up to view the solution to this question. Already a member? Log in to view this solution.

Stay Connected

Oracle Around the Web

The latest Oracle news, tips, and tricks

Oracle Unveils Netra SPARC T3 Servers

New Carrier-Grade Blade and Rackmount Servers Deliver Better Performance, Density and Power Efficiency for the Communications Industry ...

read more

Oracle fixes 21 flaws in Java SE, Java for Business

Oracle is fixing 21 flaws in its Java SE and Java for Business products in its February critical patch update issued this week ...

read more

Obama’s Silicon Valley “Tech Supper”

Why was he there? Who wasn’t invited and why? What did they talk about? Why was he really there? These are the questions being debated ...

read more

Featured Oracle Experts

slightwv

slightwv has answered more than 2,000 Oracle questions and oversees database management within the U.S. Government. Slightwv

sdstuber

A regular presenter at the Collaborate conference, Oracle developer sdstuber is a top expert in PL/SQL and Oracle 9, 10 and 11. sdstuber

Testimonials

What users are saying about our experts

"The Oracle gurus provide answers, solutions and valuable workarounds"

User: schwertner

"Wow! Excellent, valuable explanation. Hats off to you"

User: aseshu70

"Solution worked fantastic and performs excellent! Thanks heaps"

User: klausbrandlhuber

Top Experts

  1. slightwv

    2,000

    0 points yesterday

    Profile

BrowseBecome an Expert