[20170210]关于dblink.txt

简介: [20170210]关于dblink.txt --昨天朋友要求建立的数据库关闭全部dblink.实际上很简单设置open_links,open_links_per_instance为0就ok了.

[20170210]关于dblink.txt

--昨天朋友要求建立的数据库关闭全部dblink.实际上很简单设置open_links,open_links_per_instance为0就ok了.

1.环境:
SCOTT@book> @ &r/ver1
PORT_STRING                    VERSION        BANNER
------------------------------ -------------- --------------------------------------------------------------------------------
x86_64/Linux 2.4.xx            11.2.0.4.0     Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production

SCOTT@book> show parameter link
NAME                    TYPE    VALUE
----------------------- ------- ------
open_links              integer 4
open_links_per_instance integer 4

create public database link "loopback"
connect to scott
identified by "book"
using '127.0.0.1/BOOK';
--//这样单台机器就可以模式dblink测试.

SCOTT@book> select sysdate from dual@loopback;
SYSDATE
-------------------
2017-02-10 08:50:38

SCOTT@book> alter system set open_links=0 scope=spfile;
System altered.

SCOTT@book> alter system set open_links_per_instance=0 scope=spfile;
System altered.

2.重启测试:
SCOTT@book> select sysdate from dual@loopback;
select sysdate from dual@loopback
                         *
ERROR at line 1:
ORA-02020: too many database links in use

--这样全部dblink都失效.

3.顺便做一些相关总结:

--//首先还原.
SCOTT@book> alter system reset open_links_per_instance;
System altered.

SCOTT@book> alter system reset open_links;
System altered.

--//重启数据库.
--//A.注意一点使用dblink会产生事务,会导致scn提升为2个数据库最高的scn.链接 http://blog.itpub.net/267265/viewspace-2123710/

SCOTT@book> @ &r/xid
XIDUSN_XIDSLOT_XIDSQN
------------------------------

no rows selected

SCOTT@book> select sysdate from dual@loopback;
SYSDATE
-------------------
2017-02-10 08:56:30

SCOTT@book> @ &r/xid
XIDUSN_XIDSLOT_XIDSQN
------------------------------
10.2.18166

C70                                                                        XIDUSN    XIDSLOT     XIDSQN     UBAFIL     UBABLK     UBASQN     UBAREC STATUS            USED_UBLK  USED_UREC XID              ADDR             START_DATE
---------------------------------------------------------------------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------------- ---------- ---------- ---------------- ---------------- -------------------
ALTER SYSTEM DUMP UNDO BLOCK '_SYSSMU10_1197734989$' XID 10 2 18166;           10          2      18166          0          0          0          0 ACTIVE                    1          1 0A000200F6460000 00000000818BF480 2017-02-10 08:56:30
ALTER SYSTEM DUMP UNDO HEADER '_SYSSMU10_1197734989$';
ALTER SYSTEM DUMP DATAFILE 0 BLOCK 0;

SCOTT@book> alter session close database link loopback;
ERROR:
ORA-02080: database link is in use

--//必须提交或者rollback才能关闭dblink.

SCOTT@book> select * from v$dblink;
DB_LINK                OWNER_ID LOG HET PROTOC OPEN_CURSORS IN_ UPD COMMIT_POINT_STRENGTH
-------------------- ---------- --- --- ------ ------------ --- --- ---------------------
LOOPBACK                     83 YES YES UNKN              0 YES NO                      1

SCOTT@book> rollback ;
Rollback complete.

SCOTT@book> select * from v$dblink;
DB_LINK                OWNER_ID LOG HET PROTOC OPEN_CURSORS IN_ UPD COMMIT_POINT_STRENGTH
-------------------- ---------- --- --- ------ ------------ --- --- ---------------------
LOOPBACK                     83 YES YES UNKN              0 NO  NO                      1

--//IN_TRANSACTION字段显示NO.

SCOTT@book> alter session close database link loopback;
Session altered.

SCOTT@book> select * from v$dblink;
no rows selected

--//还可以使用这个命令关闭exec DBMS_SESSION.CLOSE_DATABASE_LINK (<db link name>);必须先授权使用.
SYS@book> grant execute on DBMS_SESSION to scott;
Grant succeeded.

SCOTT@book> select sysdate from dual@loopback;
SYSDATE
-------------------
2017-02-10 09:03:33

SCOTT@book> commit ;
Commit complete.

SCOTT@book> exec DBMS_SESSION.CLOSE_DATABASE_LINK ('loopback');
PL/SQL procedure successfully completed.

SCOTT@book> select * from v$dblink;
no rows selected

//B.如果要像了解那些会话打开了dblink,可以在sys用户执行:
column GTXID format a30
column waiting format a40
column ORIGIN format a30
column username format a12

Select /*+ ORDERED */
substr(s.ksusemnm,1,10)||'-'|| substr(s.ksusepid,1,10)      "ORIGIN",
g.K2GTITID_ORA "GTXID",
substr(s.indx,1,4)||'.'|| substr(s.ksuseser,1,5) "LSESSION" ,
s2.username,
   decode(bitand(ksuseidl,11),
         1,'ACTIVE',
               0, decode( bitand(ksuseflg,4096) , 0,'INACTIVE','CACHED'),
                     2,'SNIPED',
                           3,'SNIPED',
                                 'KILLED'
                                    )
    "S",
    w.event "WAITING",
    s2.client_info
    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;

--//在scott用户下执行:
SCOTT@book> select sysdate from dual@loopback;
SYSDATE
-------------------
2017-02-10 09:06:34

SCOTT@book> @ &r/spid
       SID    SERIAL# SPID       PID  P_SERIAL# C50
---------- ---------- ------ ------- ---------- --------------------------------------------------
       232          7 58424       21          4 alter system kill session '232,7' immediate;

--//sys用户执行:
SYS@book> @ &r/dblink
ORIGIN                         GTXID                          LSESSION            USERNAME     S        WAITING                                  CLIENT_INFO
------------------------------ ------------------------------ ------------------- ------------ -------- ---------------------------------------- --------------------
xxxxdg4-58423                  BOOK.e6127bf4.2.29.1643        232.7               SCOTT        INACTIVE SQL*Net message from client

目录
相关文章
|
SQL Oracle 关系型数据库
[20180511]PLSQL与fetchsize.txt
[20180511]PLSQL与fetchsize.txt --//测试看看PLSQL中cursor的fetchsize: 1.环境: SCOTT@book> @ ver1 PORT_STRING                    VERSION  ...
1171 0
|
Oracle 关系型数据库 OLAP
[20180224]expdp query 写法问题.txt
[20180224]expdp query 写法问题.txt --//如果使用expdp/impdp导入导出,如果参数复杂,最好的建议使用参数文件.避免各种问题.通过简单的例子说明问题.
1217 0
|
SQL 关系型数据库 Oracle
[20180211]current_schema与dblink.txt
[20180211]current_schema与dblink.txt --//有时候调优sql语句,经常在回话设在alter session set current_schema=scott,然后执行sql语句.
1121 0
|
关系型数据库 Oracle Linux
[20180211]dblink查询单个分区数据.txt
[20180211]dblink查询单个分区数据.txt 1.环境: SCOTT@book> @ &r/ver1 PORT_STRING                    VERSION        BANNER -------------------...
1129 0
|
Oracle 关系型数据库 Linux
[20171231]PLSQL使用绑定变量.txt
[20171231]PLSQL使用绑定变量.txt --//一些应用程序开发使用的绑定变量是:1,:2之列的语句,要调优这些语句必须写成如下: 1.环境: SCOTT@book> @ &r/ver1 PORT_STRING              ...
1205 0
|
网络协议 Oracle 关系型数据库
[20171110]toad 小技巧.txt
[20171110]toad 小技巧.txt --//前几天的事情,一大早要求查询记录操作异常,本来想使用logminer查询,我们redo文件太大,使用logminer分析很慢.
996 0
|
关系型数据库 Oracle Linux
[20170712]建立dblink的问题.txt
[20170712]建立dblink的问题.txt SYS@book> @ &r/ver1 PORT_STRING                    VERSION        BANNER ----------------------...
970 0
|
机器学习/深度学习 Oracle 关系型数据库
[20170622]传输表空间与dblink.txt
[20170622]传输表空间与dblink.txt --//测试看看使用dblink+传输表空间的情况.写的情况相对复杂一点,具体看测试: 1.环境: --//2个数据库版本一致.
961 0

热门文章

最新文章

下一篇
开通oss服务