Skip to Main Content
  • Questions
  • Is there a timeout for a query over database link?

Breadcrumb

Question and Answer

Connor McDonald

Thanks for the question, Ganesh.

Asked: February 22, 2019 - 9:01 pm UTC

Last updated: February 26, 2019 - 1:56 am UTC

Version: 12.1.0.2

Viewed 10K+ times! This question is

You Asked

Greetings -

I have written PL/sql code that gathers tablespace information among 100's of Databases on a regular basis that would assist in our Capacity Planning Program. This code is configured using dbms scheduler on a central server/db.

At a high level, this code connects to each db by dynamically creating db link, captures tablespace space information to insert into the local table and drops the link.

The idea is to if the link is working fine, get the data. If not capture the error and move to the next DB. Now, this code is working like a champ. But, today, I stumbled upon issue when one remote DB connection had "Library Cache contention" due to which entire program was hanging.

Is there a way one can have timeout functionality built for Database Link Connections that will close the link after say 30/60 sec which can be captured as exception to let the code move to the next DB..

thanks
Ganesh


and Connor said...

Take a look at this link

https://asktom.oracle.com/m/pls/asktom/asktom.search?tag=cancelling-long-running-queries

which discusses Resource Manager to put a cap on execution time for a statement.


Rating

  (3 ratings)

Is this answer out of date? If it is, please let us know via a Comment

Comments

Few Clarifications

Ganesh Sundaresan, February 23, 2019 - 2:53 pm UTC

Thanks for the feedback Connor.

I had looked into the post before too and wasn't sure if that implementation has to be done on each of the Target DB's to take effect?! If so, it would be an herculean task as it would require me to have a specific account created assign RM to that account for queries running longer than certain period of time. Will that RM method work on the Central DB where I am initiating DB Link from?

Meaning, I will have RM construct on my Central/Local DB. Run the code and if a remote DB takes more than 60sec, RM will stop that gracefully and I can capture that exception and move to the next DB?

Appreciate your thoughts.

thanks
Ganesh

Couple more updates

Ganesh Sundaresan, February 25, 2019 - 5:08 pm UTC

Greetings -

I tried implementing RM on the Central DB. I have set SWITCH_ELAPSED_TIME and SWITCH_GROUP to 100s and CANCEL_GROUP respectively. When I run query using dblink from sqlplus interface, it comes back applying RM with error : ORA-56735.

But, when I run the package where I have all those procedures that dynamically creates dblink, query and drop the link once the query is complete, I do see the select via dblink is hanging and RM seems not applying.

Wanted to update this fact and get your thoughts.

thanks
Ganesh

Got it working

Ganesh Sundaresan, February 25, 2019 - 8:03 pm UTC

Greetings -

I am able to get this working with RM construct on the Central DB for the specific user running the package. Earlier I had most of the procs defined with "PRAGMA AUTONOMOUS" that was causing RM not to fire properly.

Thanks for your inputs and providing direction to get to resolution.

Wish we had simpler solution of graceful termination of SQL Cursor when it runs beyond certain time. Something like

Open Cursor for <sql> for <time-interval>

Ganesh
Connor McDonald
February 26, 2019 - 1:56 am UTC

Hey, great work on getting it working. (Saved me from setting this up on a couple of databases here).

I love it when people take an AskTOM answer and the run with it, explore it, test it.

So many other people just come back with: "Hey I need the full code for me to cut and paste".

Made my day!

More to Explore

Performance

Get all the information about database performance in the Database Performance guide.