Script: Who’s using a database link?(找出谁在使用dblink)

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

时间: 2025-01-02 03:46:49

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

建立dblink(database link)

database linke是建立一个数据库到另一个数据库的路径的对象,通过database link可以允许查询远程表,我理解可以算作一种分布式数据库的用法. database link是单向连接,既然它是一种对象,那自然可以在xxx_objects表中查询到相关的信息.建立database link前需要明确几个事情: 1.确认从建立方的server可以访问远程数据库. 2.需要在建立方的tnsnames中配置远程数据库连接串. 3.只有在服务端配置的连接才能在dblink中使用,如果仅是在

Oracle创建Database Link

一菜单方式: 打开plsql,点击[File]-[New]-[Database link],打开如下图所示窗口 填好各项信息后,点击[Apply]即可完成Database Link的创建. 二SQL方式 -- Drop existing database link drop public database link dblink_name; -- Create database link create public database link dblink_name connect to SYS

IT忍者神龟之Database Link详解

-创建 CREATE public database link test_link CONNECT TO scott IDENTIFIED BY tiger using '(DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = 127.0.0.1)(PORT = 1521)) ) (CONNECT_DATA = (SERVICE_NAME = LEE) ) )'; --使用 select ename from [emai

ORACLE 11g 通过odbc建立连接到mysql库的database link

以前做过在oracle通过gateway建立到sqlserver的database link(详情参见:http://blog.csdn.net/mchdba/article/details/52719278),现在需要无缝访问mysql,所以也需要建立类似这样的连接通道. 1.分配mysql账号 先在mysql库上建立连接账号: GRANT SELECT ON test.* TO [email protected]'192.168.129.%' IDENTIFIED BY 'data_quer

Oracle Database Link 的创建和使用小见

假设:需要从数据库db_a通过db_link连接到db_b查询数据库b的部分相关信息 前提条件: 数据库a账户需要有创建dblink的权限,如果没有可以使用dba账户赋权限 grant CREATE PUBLIC DATABASE LINK to  username;grant DROP PUBLIC DATABASE LINK to usenrame; 数据库b账号需要有连接的权限,一般账户都有这个权限 以下是创建的语句: 基本语法: CREATE [SHARED][PUBLIC] datab

oracle database link使用说明

作用:将多个oracle数据库逻辑上看成一个数据库,也就是说在一个数据库中可以操作另一个数据库中的对象 简易语法: CREATE [PUBLIC] DATABASE LINK dblink CONNECT TO user IDENTIFIED BY password USING 'connect_string';  DROP [PUBLIC] DATABASE LINK dblink; 注意:你必须有CREATE DATABASE LINK或CREATE PUBLIC DATABASE LINK

database link远程链接数据库

--授权创建.删除dblink GRANT CREATE [PUBLIC] DATABASE LINK,DROP [PUBLIC] DATABASE LINK TO canco; --查看数据库GLOBAL_NAME(数据库名) SELECT * FROM GLOBAL_NAME; --查看有哪些dblink select owner,object_name from dba_objects where object_type='DATABASE LINK'; --删除dblink DROP [

create database link

如果本地的tnsnames.ora中未建立数据库连接,那么就是用1,否则就是用2 1:create database link geelyin96 connect to geelyin identified by geelyinpassword  using '(DESCRIPTION =  (ADDRESS_LIST =  (ADDRESS = (PROTOCOL = TCP)(HOST = 10.86.1.96)(PORT = 1521))  )  (CONNECT_DATA =  (SER

DATABASE LINK 的查看、创建与删除

1.查看dblink SELECT OWNER,OBJECT_NAME FROM DBA_OBJECTS WHERE OBJECT_TYPE='DATABASE LINK'; 或者 SELECT * FROM DBA_DB_LINKS; 2.创建dblink 前提: 创建dblink的用户有对应的数据库权限 create public database link 或者create database link 可以使用 grant create public database link,creat