Oracle中如何检查数据库链接是否有效?
我有一个主数据库,仅在总部设置数据,在不同的分支机构有几个数据库。我为每个分支机构服务器创建了一个数据库链接。
在某些情况下,我想查询所有有效链接(因为某些链接可能由于连接问题或其他原因而无效),所以我的问题是如何检查数据库链接是否有效而不会出现连接超时问题。是否有 SQL 语句让 oracle 主服务器执行该检查并仅返回有效的数据库链接?
I have a main database with only setup data at the headquarter and several databases at different branches.I created a database link for each branch server.
In some case I would like to query all the valid links (as some links could be invalid due to connection problems or anything else),so my question is How to check if the database link is valid without getting in Connection timeout problems. Is there a SQL statement to let the oracle main server do that check and return only the valid database links?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
我不知道您是否设法完成此操作,但我想做类似的事情并检查哪些数据库链接处于活动状态。我在另一个论坛上发现了这个
,它只显示活动的数据库链接。同样,只有当您有权访问
v$dblink
时,此操作才有效。I don't know if you managed to get this done, but I wanted to do something like this and check which database links are active. I found this on another forum
which shows only active dblinks. Again, this will work only if you have permission to access
v$dblink
.您可以通过执行以下命令来验证数据库链接:
可以创建验证数据库链接的函数:
最后,您可以创建表 my_db_links(id, name, status(0,1)) 并更新它:
You can verify db link by executing:
To can create function that verifies db link:
Lastly, you can create table my_db_links(id, name, status(0,1)) and update it:
我不确定您是否可以创建查询来检查实时数据库链接。
您可以做的一件事是创建一个由后台进程更新的表,其中包含数据库链接列表,并为每个链接提供“上次活着的时间”时间戳
I'm not sure you can create a query to check live db links.
One thing you could do is create a table updated by a background process with the list of db links and for each of them a 'last time seen alive' timestamp
由于不同类别的问题,任何链接都可能出现问题:
链接定义无效:错误
用户名、密码(如果使用)、服务
name
远程帐户已锁定
远程数据库配置(例如超出每个用户的会话数)
远程数据库或主机不可用< /p>
考虑到这些故障模式不断变化的性质,不可能有一个字典视图(例如)来描述链接的状态。在后台检查的异步进程也有可能过时。您可以做的最轻量级的测试可能是在需要使用代码中的链接之前发出“select sysdate from Dual@remote_db”
Any link could have a problem due to different categories of issues:
invalid link definition: wrong
username, password (if used), service
name
remote account locked
remote db configuration (e.g. sessions per user exceeded)
remote db or host unavailability
Given the changing nature of these failure modes there can't be a dictionary view (for example) that describes the state of the link. An asynchronous process that checks in the background will also stand a chance of being out-of-date. Probably the lightest-weight test you can do is issue a "select sysdate from dual@remote_db" before you need to use the link in your code
您可以使用
WITH FUNCTION
并进行简单的检查:结果您将收到
OK
或错误消息。You could use
WITH FUNCTION
and do simple check:As result you will get
OK
or error message.您可以编写一个执行 tnsping 的操作系统级别脚本,因为无论如何数据库链接通常都依赖于 tnsnames.ora。
You could write an OS level script that performs a tnsping, since db links usually depend on the tnsnames.ora anyway.