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?
Any user can query USER_DB_LINKS to determine which database links are available to that user. Only those with additional privileges can use the ALL_DB_LINKS or DBA_DB_LINKS view.
If application schema's password is not known to DBA. We can verify public database link using select * from dual@public_db_link; How private db links can be verified by a DBA if application schema's password is not known.
A database link is a pointer that defines a one-way communication path from an Oracle Database server to another database server. The link pointer is actually defined as an entry in a data dictionary table. To access the link, you must be connected to the local database that contains the data dictionary entry.
Use the ALTER DATABASE LINK statement to modify a fixed-user database link when the password of the connection or authentication user changes. Notes: You cannot use this statement to change the connection or authentication user associated with the database link. To change user , you must re-create the database link.
You can verify db link by executing:
select * from dual@my_db_link;
To can create function that verifies db link:
function is_link_active(
p_link_name varchar2
) return number is
v_query_link varchar2(100) := 'select count(*) alive from dual@'||p_link_name;
type db_link_cur is REF CURSOR;
cur db_link_cur;
v_status number;
begin
open cur FOR v_query_link;
loop
fetch cur INTO v_status;
exit when cur%notfound;
dbms_output.put_line('v_status='||v_status);
return v_status;
end loop;
close cur;
exception when others then
close cur;
return 0;
end is_link_active;
Lastly, you can create table my_db_links(id, name, status(0,1)) and update it:
update
my_db_links mdl
set
mdl.status = is_link_active(mdl.name);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With