使用dblink导致数据库连接数

        现有两个数据库,自己的数据库,别人的数据库

        近期一个功能上线之后,对方的开发人员经常过来抱怨说,他们的数据库连接数超了,导致

连不上,由于我们的新功能是通过dblink从我们数据库到他们数据库查数据,所以他们怀疑是我们数据库的连接没关,排查后发现代码里面有关闭连接,没问题。

后来查阅发现,数据库通过dblink查询,会打开一个session,即使是select也会,附上别人查阅的官方文档

 

Managing a Distributed Database


Closing Database Links


If you access a database link in a session, then the link remains open until you close the session. A link is open in the sense that a process is active on each of the remote databases accessed through the link. This situation has the following consequences:

  • If 20 users open sessions and access the same public link in a local database, then 20 database link connections are open.

  • If 20 users open sessions and each user accesses a private link, then 20 database link connections are open.

  • If one user starts a session and accesses 20 different links, then 20 database link connections are open.

After you close a session, the links that were active in the session are automatically closed. You may have occasion to close the link manually. For example, close links when:

  • The network connection established by a link is used infrequently in an application.

  • The user session must be terminated.

To close a link, issue the following statement, where linkname refers to the name of the link:

ALTER SESSION CLOSE DATABASE LINK linkname;

Note that this statement only closes the links that are active in your current session.  

解决:

    我们是通过was连接池取的连接,即使程序程序里面把连接close了,也只是把连接放回was的连接池,但是session还在,所以连接一只占着导致别人的数据库连接数超了。所以用dblink的时候,就算是select操作,也在后面加上con.commit或者con.rollback

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值