Every once in awhile it is useful to find out which sessions are using a database link in an Oracle database. It’s one of those things that you may not need very often, but when you do need it, it is usually rather important.

Yong Huang includes this script on his website, and notes that Mark further attributed authorship in Metalink Forum thread 524821.994. but this note is no longer available.

Here’s the script, complete with comments.

— for 9I and below

-- 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,10
) "Status",
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

— for 10g and above

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,
10)
"Status",
SUBSTR (s2.event, 1, 10) "WAITING"
FROM x$k2gte g,
x$ktcxb t,
x$ksuse s,
v$session s2
WHERE g.K2GTDXCB = t.ktcxbxba
AND g.K2GTDSES = t.ktcxbses
AND s.addr = g.K2GTDSES
AND s2.sid = s.indx;

If you want to close a link, issue the following statement, where linkname refers to the name of the link:

sql> commit or rollback;
SQL> alter session close database link linkname;
Session altered.

references Jared‘s article

Script: Who’s using a database link?(找出谁在使用dblink)的更多相关文章

  1. Oracle创建Database Link

    一菜单方式: 打开plsql,点击[File]-[New]-[Database link],打开如下图所示窗口 填好各项信息后,点击[Apply]即可完成Database Link的创建. 二SQL方 ...

  2. 建立dblink(database link)

    版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/bisal/article/details/26730993 database linke是建立一个数 ...

  3. Oracle数据库如何创建DATABASE LINK?

    Oracle数据库如何创建DATABASE LINK? 2011-08-09 14:54 taowei20061122 CSDN博客  http://blog.csdn.net/taowei20061 ...

  4. oracle 创建database Link

    当两台不同的数据库服务器想要共享一部分数据的时候,可以通过创建database Link的方式实现. 创建全局database links ,则必须使用systm或sys用户,在database前加p ...

  5. database link远程链接数据库

    --授权创建.删除dblink GRANT CREATE [PUBLIC] DATABASE LINK,DROP [PUBLIC] DATABASE LINK TO canco; --查看数据库GLO ...

  6. database link

    create database link lims_qumas_supplyconnect to QPROCESSDEV identified by qprocessdevusing '(DESCRI ...

  7. Oracle11g密码区分大小写导致database link无法连接

    http://f.dataguru.cn/thread-128013-1-1.html Oracle11g的密码默认是区分大小写的,该特性通过初始化参数sec_case_sensitive_logon ...

  8. DATABASE LINK 的查看、创建与删除

    1.查看dblink SELECT OWNER,OBJECT_NAME FROM DBA_OBJECTS WHERE OBJECT_TYPE='DATABASE LINK'; 或者 SELECT * ...

  9. oracle Database Link

    1 Database Link 的创建: 有两个数据库服务器A/B, 其中A的IP地址为172.20.36.245, 服务器B为本机.服务器B上的数据库实例名为ORCL,在本机上的服务监听配置上有服务 ...

随机推荐

  1. 【转】 Android快速开发系列 10个常用工具类 -- 不错

    原文网址:http://blog.csdn.net/lmj623565791/article/details/38965311 转载请标明出处:http://blog.csdn.net/lmj6235 ...

  2. 利用dhtmlxGrid做的表格排序的功能。

    dhtmlxGrid支持tree和grid. grid之间.grid内部进行拖拽, 如在grid内部进行拖拽,可以增加一行:在grid之间拖拽,第一个grid的记录删除,第二个grid增加一行记录.

  3. java中Pattern.compile函数的相关解释

    Pattern.compile函数:Pattern Pattern.compile(String regex, int flag) flag的取值范围如下: Pattern.CANON_EQ,当且仅当 ...

  4. Delphi TcxTreeList 怎么设置分组

    Delphi 的TcxTreeList控件设置按种类分组,操作如下: 1. 在TcxTreeList控件中双击,打开 Bands 属性,在这里面建需要分的组,在Captions->Text 输入 ...

  5. handlebars模板库的资源

    web 开发中,js 解析JSON 是经常的事情.非常繁琐.handlebars 使用了模版,只要你定义一个模版,提供一个json对象,handlebars 就能吧json对象放到你定的模版中,非常方 ...

  6. bzoj 1069 [SCOI2007]最大土地面积(旋转卡壳)

    1069: [SCOI2007]最大土地面积 Time Limit: 1 Sec  Memory Limit: 162 MBSubmit: 2277  Solved: 853[Submit][Stat ...

  7. Bzoj 1657: [Usaco2006 Mar]Mooo 奶牛的歌声 单调栈

    1657: [Usaco2006 Mar]Mooo 奶牛的歌声 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 631  Solved: 445[Submi ...

  8. [LeetCode] 73. Set Matrix Zeroes 解题思路

    Given a m x n matrix, if an element is 0, set its entire row and column to 0. Do it in place. Follow ...

  9. pathmunge /etc/profile

    pathmunge () { case ":${PATH}:" in *:"$1":*) ;; *) if [ "$2" = "a ...

  10. Morris Traversal 二叉树遍历。

    那天做了个SWAP NODE的题,要求constant space,不得不Morris Traversal. 稍微研究了一下,真正意义上的O(1)space对二叉树进行遍历.好像是1979年的算法. ...