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

相关文章

MySQL 8 中的一个强大功能 JSON_TABLE示例详解

《MySQL8中的一个强大功能JSON_TABLE示例详解》JSON_TABLE是MySQL8中引入的一个强大功能,它允许用户将JSON数据转换为关系表格式,从而可以更方便地在SQL查询中处理J... 目录基本语法示例示例查询解释应用场景不适用场景1. ‌jsON 数据结构过于复杂或动态变化‌2. ‌性能要

postgresql使用UUID函数的方法

《postgresql使用UUID函数的方法》本文给大家介绍postgresql使用UUID函数的方法,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友参考下吧... 目录PostgreSQL有两种生成uuid的方法。可以先通过sql查看是否已安装扩展函数,和可以安装的扩展函数

MySQL字符串常用函数详解

《MySQL字符串常用函数详解》本文给大家介绍MySQL字符串常用函数,本文结合实例代码给大家介绍的非常详细,对大家学习或工作具有一定的参考借鉴价值,需要的朋友参考下吧... 目录mysql字符串常用函数一、获取二、大小写转换三、拼接四、截取五、比较、反转、替换六、去空白、填充MySQL字符串常用函数一、

如何使用Lombok进行spring 注入

《如何使用Lombok进行spring注入》本文介绍如何用Lombok简化Spring注入,推荐优先使用setter注入,通过注解自动生成getter/setter及构造器,减少冗余代码,提升开发效... Lombok为了开发环境简化代码,好处不用多说。spring 注入方式为2种,构造器注入和setter

MySQL中比较运算符的具体使用

《MySQL中比较运算符的具体使用》本文介绍了SQL中常用的符号类型和非符号类型运算符,符号类型运算符包括等于(=)、安全等于(=)、不等于(/!=)、大小比较(,=,,=)等,感兴趣的可以了解一下... 目录符号类型运算符1. 等于运算符=2. 安全等于运算符<=>3. 不等于运算符<>或!=4. 小于运

虚拟机Centos7安装MySQL数据库实践

《虚拟机Centos7安装MySQL数据库实践》用户分享在虚拟机安装MySQL的全过程及常见问题解决方案,包括处理GPG密钥、修改密码策略、配置远程访问权限及防火墙设置,最终通过关闭防火墙和停止Net... 目录安装mysql数据库下载wget命令下载MySQL安装包安装MySQL安装MySQL服务安装完成

使用zip4j实现Java中的ZIP文件加密压缩的操作方法

《使用zip4j实现Java中的ZIP文件加密压缩的操作方法》本文介绍如何通过Maven集成zip4j1.3.2库创建带密码保护的ZIP文件,涵盖依赖配置、代码示例及加密原理,确保数据安全性,感兴趣的... 目录1. zip4j库介绍和版本1.1 zip4j库概述1.2 zip4j的版本演变1.3 zip4

Python 字典 (Dictionary)使用详解

《Python字典(Dictionary)使用详解》字典是python中最重要,最常用的数据结构之一,它提供了高效的键值对存储和查找能力,:本文主要介绍Python字典(Dictionary)... 目录字典1.基本特性2.创建字典3.访问元素4.修改字典5.删除元素6.字典遍历7.字典的高级特性默认字典

MySQL进行数据库审计的详细步骤和示例代码

《MySQL进行数据库审计的详细步骤和示例代码》数据库审计通过触发器、内置功能及第三方工具记录和监控数据库活动,确保安全、完整与合规,Java代码实现自动化日志记录,整合分析系统提升监控效率,本文给大... 目录一、数据库审计的基本概念二、使用触发器进行数据库审计1. 创建审计表2. 创建触发器三、Java

MySQL逻辑删除与唯一索引冲突解决方案

《MySQL逻辑删除与唯一索引冲突解决方案》本文探讨MySQL逻辑删除与唯一索引冲突问题,提出四种解决方案:复合索引+时间戳、修改唯一字段、历史表、业务层校验,推荐方案1和方案3,适用于不同场景,感兴... 目录问题背景问题复现解决方案解决方案1.复合唯一索引 + 时间戳删除字段解决方案2:删除后修改唯一字