views:

49

answers:

3

Hi All,i have a main database with only setup data at the headquarter and several databases at different branches,i created a database link for each branch server.

In some case i would like to query all the valid links (as some links could be invalid due to connection problems or anything else),so my question is How to check if the database link is valid without getting in Connection timeout problems,Is there a SQL statement to let the oracle main server do that check and return only the valid database links?

Thanks in advance

Khaled

+2  A: 

I'm not sure you can create a query to check live db links. One thing you could do is create a table updated by a background process with the list of db links and for each of them a 'last time seen alive' timestamp

vc 74
That could be a solution also,thnx vc74
Khaled
+1  A: 

Any link could have a problem due to different categories of issues:

  • invalid link definition: wrong username, password (if used), service name

  • remote account locked

  • remote db configuration (e.g. sessions per user exceeded)

  • remote db or host unavailability

  • network connectivity

Given the changing nature of these failure modes there can't be a dictionary view (for example) that describes the state of the link. An asynchronous process that checks in the background will also stand a chance of being out-of-date. Probably the lightest-weight test you can do is issue a "select sysdate from dual@remote_db" before you need to use the link in your code

dpbradley
Thanks for ur answer,but the problem i face with this approach is waiting till i get the timeout exception.so if any of the database links is not available for any reason,i will have to wait till the server stops trying to connect !
Khaled
+1  A: 

You could write an OS level script that performs a tnsping, since db links usually depend on the tnsnames.ora anyway.

Stellios
Sounds like a good idea, but how to do it?
Khaled
For Windows... tnsping <tnsname> ... check the %errorlevel% value immediately after the tnsping. If it is 0 == OK, 1 == ERROR. For UNIX return code is $? (errorlevel equivalent).
Stellios
i will try this,thanx
Khaled