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

相关文章

使用Docker构建Python Flask程序的详细教程

《使用Docker构建PythonFlask程序的详细教程》在当今的软件开发领域,容器化技术正变得越来越流行,而Docker无疑是其中的佼佼者,本文我们就来聊聊如何使用Docker构建一个简单的Py... 目录引言一、准备工作二、创建 Flask 应用程序三、创建 dockerfile四、构建 Docker

Python使用vllm处理多模态数据的预处理技巧

《Python使用vllm处理多模态数据的预处理技巧》本文深入探讨了在Python环境下使用vLLM处理多模态数据的预处理技巧,我们将从基础概念出发,详细讲解文本、图像、音频等多模态数据的预处理方法,... 目录1. 背景介绍1.1 目的和范围1.2 预期读者1.3 文档结构概述1.4 术语表1.4.1 核

Python使用pip工具实现包自动更新的多种方法

《Python使用pip工具实现包自动更新的多种方法》本文深入探讨了使用Python的pip工具实现包自动更新的各种方法和技术,我们将从基础概念开始,逐步介绍手动更新方法、自动化脚本编写、结合CI/C... 目录1. 背景介绍1.1 目的和范围1.2 预期读者1.3 文档结构概述1.4 术语表1.4.1 核

Conda与Python venv虚拟环境的区别与使用方法详解

《Conda与Pythonvenv虚拟环境的区别与使用方法详解》随着Python社区的成长,虚拟环境的概念和技术也在不断发展,:本文主要介绍Conda与Pythonvenv虚拟环境的区别与使用... 目录前言一、Conda 与 python venv 的核心区别1. Conda 的特点2. Python v

Spring Boot中WebSocket常用使用方法详解

《SpringBoot中WebSocket常用使用方法详解》本文从WebSocket的基础概念出发,详细介绍了SpringBoot集成WebSocket的步骤,并重点讲解了常用的使用方法,包括简单消... 目录一、WebSocket基础概念1.1 什么是WebSocket1.2 WebSocket与HTTP

C#中Guid类使用小结

《C#中Guid类使用小结》本文主要介绍了C#中Guid类用于生成和操作128位的唯一标识符,用于数据库主键及分布式系统,支持通过NewGuid、Parse等方法生成,感兴趣的可以了解一下... 目录前言一、什么是 Guid二、生成 Guid1. 使用 Guid.NewGuid() 方法2. 从字符串创建

Python使用python-can实现合并BLF文件

《Python使用python-can实现合并BLF文件》python-can库是Python生态中专注于CAN总线通信与数据处理的强大工具,本文将使用python-can为BLF文件合并提供高效灵活... 目录一、python-can 库:CAN 数据处理的利器二、BLF 文件合并核心代码解析1. 基础合

Python使用OpenCV实现获取视频时长的小工具

《Python使用OpenCV实现获取视频时长的小工具》在处理视频数据时,获取视频的时长是一项常见且基础的需求,本文将详细介绍如何使用Python和OpenCV获取视频时长,并对每一行代码进行深入解析... 目录一、代码实现二、代码解析1. 导入 OpenCV 库2. 定义获取视频时长的函数3. 打开视频文

MySQL 中的 CAST 函数详解及常见用法

《MySQL中的CAST函数详解及常见用法》CAST函数是MySQL中用于数据类型转换的重要函数,它允许你将一个值从一种数据类型转换为另一种数据类型,本文给大家介绍MySQL中的CAST... 目录mysql 中的 CAST 函数详解一、基本语法二、支持的数据类型三、常见用法示例1. 字符串转数字2. 数字

Mysql实现范围分区表(新增、删除、重组、查看)

《Mysql实现范围分区表(新增、删除、重组、查看)》MySQL分区表的四种类型(范围、哈希、列表、键值),主要介绍了范围分区的创建、查询、添加、删除及重组织操作,具有一定的参考价值,感兴趣的可以了解... 目录一、mysql分区表分类二、范围分区(Range Partitioning1、新建分区表:2、分