[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  ...
1162 0
|
机器学习/深度学习 Oracle 关系型数据库
[20180412]logminer使用问题(10g).txt
[20180412]logminer使用问题(10g).txt --//今天使用logminer下遇到一个问题,做一个记录: 1.环境: SYSTEM@xxx> @ &r/ver1 PORT_STRING                    VERSION...
1639 0
|
SQL 关系型数据库 Oracle
[20180211]current_schema与dblink.txt
[20180211]current_schema与dblink.txt --//有时候调优sql语句,经常在回话设在alter session set current_schema=scott,然后执行sql语句.
1117 0
[20171110]toad 小技巧.txt
[20171110]toad 小技巧.txt --//前几天的事情,一大早要求查询记录操作异常,本来想使用logminer查询,我们redo文件太大,使用logminer分析很慢.
991 0
|
SQL 关系型数据库 Oracle
[20170915]sql脚本这里的@表示什么.txt
[20170915]sql脚本这里的@表示什么.txt --//昨天看文章,链接https://mdinh.wordpress.com/2017/09/10/thoughts-on-rman-backup-strategy/ --//里面的sql语句在rman直接执行的,这个是12c的一个特性.
779 0
|
关系型数据库 Oracle Linux
[20170712]建立dblink的问题.txt
[20170712]建立dblink的问题.txt SYS@book> @ &r/ver1 PORT_STRING                    VERSION        BANNER ----------------------...
963 0
|
安全 测试技术 数据库
[20170607]10g dblink的密码.txt
[20170607]10g dblink的密码.txt --//10g下建立的dblink密码非常容易破解.只要能访问表sys.link$,做一个简单的测试来说明,实际上这个问题在11.
1121 0
|
SQL
[20170506]fetch sqlplus arraysize.txt
[20170506]fetch sqlplus arraysize.txt http://blog.itpub.net/267265/viewspace-2138042/ --//前一阵子写的,如果设置arrarsize=3,可以看到3条3条输出.
967 0
|
关系型数据库 Oracle
[20170410]11G ora_sql_txt是否有效.txt
[20170410]11G ora_sql_txt是否有效.txt --链接问的问题: http://www.itpub.net/thread-2086256-1-1.
1204 0
|
数据库 BI 关系型数据库
[20161214]如何确定dbid.txt
[20161214]如何确定dbid.txt --如何确定数据库的dbid,我曾经写过一篇blog,链接:http://blog.itpub.net/267265/viewspace-2125849/ --实际上还有1种非常武断的方法,直接使用strings...
827 0