使用完 Oracle 中的数据库基础链接后是否应该删除/关闭它们?
我有一个 SQL 脚本,它使用“创建数据库链接”连接到另一个数据库,并复制一些数据。
使用完该数据库基础链接后是否应该删除或关闭它? (假设我可能不再需要它)。
最好的做法是什么?
我在我的团队中听到了一些相互矛盾的答案。
如果我应该关闭它,如何确保在调用时链接关闭:(
drop database link somelink;
我收到错误,抱怨我打开了连接,这很奇怪,因为我没有执行任何异步操作/作业)。
I have an SQL script that connects to another database using "create database link", and copies some data.
Should this database base link be dropped or closed after I am done using it?
(Say, assuming that I probably won't be needing it again).
What's the best practice?
I am hearing some conflicting answers on my team.
If I should be closing it, how do I ensure that the link gets closed when I call:
drop database link somelink;
(I get errors complaining that I have connections open, which is odd because I'm not performing any asynchronous operations/jobs).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
从最佳实践的角度来看,我对在脚本中动态创建数据库链接非常谨慎。数据库链接应该像任何其他对象一样——它们应该被创建一次并被多次引用。如果这确实是一次性事件,您在另一个数据库停用之前从该数据库中提取数据,则创建和删除链接是有意义的。对于其他任何事情,我会创建链接并让它保留给下一个可能需要它的人,除非有迫切需要删除它(即,您从安全组获得了例外,可以在短时间内创建链接的时间)。
您可以使用该命令关闭数据库链接
,这可能是在使用完数据库链接后和删除它之前做的一件好事。这应该可以消除您在删除链接时遇到的错误。
From a best practices standpoint, I would be very wary about creating database links dynamically in a script. Database links should be just like any other object-- they should be created once and referenced multiple times. If this is truly a one-time event where you are extracting data from another database before it is decommissioned, creating and dropping the link would make sense. For anything else, I would create the link and let it remain for the next person that may need it unless there is a compelling need to drop it (i.e. you're getting an exception from the security group to create the link for a short period of time).
You can close a database link with the command
which is probably a nice thing to do when you're done with it and before you drop it. That should eliminate the errors you're getting when you drop the link.