Created
October 6, 2016 17:15
-
-
Save dotmaik1/2bb55b244d95cade34d163069d0fff06 to your computer and use it in GitHub Desktop.
who_dblink.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| --The following script can be used to see open DB link sessions (on both databases). | |
| -- who is querying via dblink? | |
| -- Courtesy of Tom Kyte, via Mark Bobak | |
| -- this script can be used at both ends of the database link | |
| -- to match up which session on the remote database started | |
| -- the local transaction | |
| -- the GTXID will match for those sessions | |
| -- just run the script on both databases | |
| Select /*+ ORDERED */ | |
| substr(s.ksusemnm,1,10)||'-'|| substr(s.ksusepid,1,10) "ORIGIN", | |
| substr(g.K2GTITID_ORA,1,35) "GTXID", | |
| substr(s.indx,1,4)||'.'|| substr(s.ksuseser,1,5) "LSESSION" , | |
| s2.username, | |
| substr( | |
| decode(bitand(ksuseidl,11), | |
| 1,'ACTIVE', | |
| 0, decode( bitand(ksuseflg,4096) , 0,'INACTIVE','CACHED'), | |
| 2,'SNIPED', | |
| 3,'SNIPED', | |
| 'KILLED' | |
| ),1,1 | |
| ) "S", | |
| substr(w.event,1,10) "WAITING" | |
| from x$k2gte g, x$ktcxb t, x$ksuse s, v$session_wait w, v$session s2 | |
| where g.K2GTDXCB =t.ktcxbxba | |
| and g.K2GTDSES=t.ktcxbses | |
| and s.addr=g.K2GTDSES | |
| and w.sid=s.indx | |
| and s2.sid = w.sid; | |
| --Get DDLs of all db links | |
| Set long 1000 | |
| set pages 500 | |
| set lines 200 | |
| SELECT DBMS_METADATA.GET_DDL('DB_LINK',db.db_link,db.owner) from dba_db_links db; | |
| --DB links information | |
| SET LINES 200 | |
| SET PAGES 500 | |
| COL OWNER FORMAT a15 | |
| COL USERNAME FORMAT A25 HEADING "USER" | |
| COL DB_LINK FORMAT A50 | |
| COL HOST FORMAT A50 HEADING "SERVICE" | |
| SELECT * FROM DBA_DB_LINKS | |
| / |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment