使用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

你可能感兴趣的:(使用dblink导致数据库连接数)