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

2024-01-09 19:12

本文主要是介绍Script: Who’s using a database link?(找出谁在使用dblink),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

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

Every once in a while 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 author ship 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, 35) "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

DBMS_SESSION.CLOSE_DATABASE_LINK

The CLOSE_DATABASE_LINK procedure is used to close an open but inactive database link in the session. The header for the program is,

PROCEDURE DBMS_SESSION.CLOSE_DATABASE_LINK

   (dblink IN VARCHAR2);

Parameter

Description

dblink

Specifies the name of the database link.

Notes

Use of database links establishes a proxy session for the local user on the remote database, and this is a relatively expensive process. This is why Oracle keeps database links open rather than closing them immediately upon completion of the remote operation. Therefore, the CLOSE_DATABASE_LINK procedure probably should not be routinely called, especially for database links that are likely to be referenced again in the current session.

This procedure is equivalent to SQL "ALTER SESSION CLOSE DATABASE LINK <name>".

Exceptions

The CLOSE_DATABASE_LINK procedure does not raise any package exceptions. It can raise the following Oracle exceptions when the referenced database link cannot be closed:

ORA-02080  Database link is in use.

ORA-02081  Database link is not open.

Restrictions

  • All cursors using the database link must be closed, and any transactions that reference the link (for UPDATE or SELECT purposes) must be ended (with COMMIT or ROLLBACK). 
     
  • The program does not assert a purity level with the RESTRICT_REFERENCES pragma.

Example

To close a database link named LOOPBACK, specify the following:

BEGIN

   DBMS_SESSION.CLOSE_DATABASE_LINK('LOOPBACK');

END;

这篇关于Script: Who’s using a database link?(找出谁在使用dblink)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/588137

相关文章

Rust中的注释使用解读

《Rust中的注释使用解读》本文介绍了Rust中的行注释、块注释和文档注释的使用方法,通过示例展示了如何在实际代码中应用这些注释,以提高代码的可读性和可维护性... 目录Rust 中的注释使用指南1. 行注释示例:行注释2. 块注释示例:块注释3. 文档注释示例:文档注释4. 综合示例总结Rust 中的注释

MySQL安装时initializing database失败的问题解决

《MySQL安装时initializingdatabase失败的问题解决》本文主要介绍了MySQL安装时initializingdatabase失败的问题解决,文中通过图文介绍的非常详细,对大家的学... 目录问题页面:解决方法:问题页面:解决方法:1.勾选红框中的选项:2.将下图红框中全部改为英

Linux使用cut进行文本提取的操作方法

《Linux使用cut进行文本提取的操作方法》Linux中的cut命令是一个命令行实用程序,用于从文件或标准输入中提取文本行的部分,本文给大家介绍了Linux使用cut进行文本提取的操作方法,文中有详... 目录简介基础语法常用选项范围选择示例用法-f:字段选择-d:分隔符-c:字符选择-b:字节选择--c

使用Go语言开发一个命令行文件管理工具

《使用Go语言开发一个命令行文件管理工具》这篇文章主要为大家详细介绍了如何使用Go语言开发一款命令行文件管理工具,支持批量重命名,删除,创建,移动文件,需要的小伙伴可以了解下... 目录一、工具功能一览二、核心代码解析1. 主程序结构2. 批量重命名3. 批量删除4. 创建文件/目录5. 批量移动三、如何安

springboot的调度服务与异步服务使用详解

《springboot的调度服务与异步服务使用详解》本文主要介绍了Java的ScheduledExecutorService接口和SpringBoot中如何使用调度线程池,包括核心参数、创建方式、自定... 目录1.调度服务1.1.JDK之ScheduledExecutorService1.2.spring

Java使用Tesseract-OCR实战教程

《Java使用Tesseract-OCR实战教程》本文介绍了如何在Java中使用Tesseract-OCR进行文本提取,包括Tesseract-OCR的安装、中文训练库的配置、依赖库的引入以及具体的代... 目录Java使用Tesseract-OCRTesseract-OCR安装配置中文训练库引入依赖代码实

MySQL 中的服务器配置和状态详解(MySQL Server Configuration and Status)

《MySQL中的服务器配置和状态详解(MySQLServerConfigurationandStatus)》MySQL服务器配置和状态设置包括服务器选项、系统变量和状态变量三个方面,可以通过... 目录mysql 之服务器配置和状态1 MySQL 架构和性能优化1.1 服务器配置和状态1.1.1 服务器选项

Python使用Pandas对比两列数据取最大值的五种方法

《Python使用Pandas对比两列数据取最大值的五种方法》本文主要介绍使用Pandas对比两列数据取最大值的五种方法,包括使用max方法、apply方法结合lambda函数、函数、clip方法、w... 目录引言一、使用max方法二、使用apply方法结合lambda函数三、使用np.maximum函数

MySQL8.0设置redo缓存大小的实现

《MySQL8.0设置redo缓存大小的实现》本文主要在MySQL8.0.30及之后版本中使用innodb_redo_log_capacity参数在线更改redo缓存文件大小,下面就来介绍一下,具有一... mysql 8.0.30及之后版本可以使用innodb_redo_log_capacity参数来更改

Qt 中集成mqtt协议的使用方法

《Qt中集成mqtt协议的使用方法》文章介绍了如何在工程中引入qmqtt库,并通过声明一个单例类来暴露订阅到的主题数据,本文通过实例代码给大家介绍的非常详细,感兴趣的朋友一起看看吧... 目录一,引入qmqtt 库二,使用一,引入qmqtt 库我是将整个头文件/源文件都添加到了工程中进行编译,这样 跨平台