惯性思维总是 令我们离大师们 有着一定的距离,这种差距 在知识广袤的领域尤其明显。
Oracle领域被称为Oracle的世界,当之无愧;一丁点的想当然就让我们偏离于事实。
以dblink的表现为例,我一直认为dblink的远程连接session仅在操作(select,dml)发生时短期存在,在操作完成后依据一定条件保留或退出。
而事实并非如此,随便使用一个远程查询语句如下:
SQL> select * from help@LZ; –LZ 为dblink名
在远程数据库端观察session,可以发现:
select sid,username,machine,program,module from v$session where module=’ORACLE.EXE’
| SID | USERNAME | MACHINE | PROGRAM | MODULE | |
| 1 | 526 | SYSTEM | WIN_DESK1 | ORACLE.EXE | ORACLE.EXE |
且该远程会话一直保留直到原会话退出为止,无论是成功退出还是程序失败。
若希望在原会话中关掉已打开的远程会话,则需要使用一下命令:
Alter session close database link DBLINKNAME;
这里要注意,需要先执行commit后以上关闭远程session SQL方会成功,即便是Select操作也是如此;
若没有执行commit,会出现:
ORA-02080: 数据库链接正在使用中
© 2009, www.oracledatabase12g.com. 版权所有.文章允许转载,但必须以链接方式注明源地址,否则追究法律责任.
相关文章 | Related posts:




How To Remove a Dead Connection to the Target Database Through DBlink After a Network Connection Failure
Applies to:
Oracle Net Services – Version: 8.1.7 to 9.2
Information in this document applies to any platform.
Goal
This document describe how you can remove a dead connection to the remote database through dblink after a network connection failure with the remote database server.
Solution
1. Please set (ENABLE=BROKEN) in the connect string for the target database in the tnsnames.ora file at the origin or source database ORACLE_HOME\network\admin or TNS_ADMIN directory.
E.g.>)(PORT = <
>))
TEST.WORLD =
(DESCRIPTION =
(ENABLE=BROKEN)
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = <
)
(CONNECT_DATA =
(SERVICE_NAME = DISCARD.WORLD)
) )
2. Please create the dblink using this connect string.
3. Please set the OS tcp/ip keepalive parameter in the local databse to a desired low value (e.g. 5 minutes).
Please note that in the case of a database link, the target destination of the link constitutes the server side of the connection. So it is not possible to use the DCD to close the database link from the origin database server in case of a network failure.