检查 Informix 中表是否被锁定

发布于 2024-10-08 06:44:12 字数 265 浏览 1 评论 0原文

我正在通过 ODBC 从 Informix DB 上的 sysmaster 表中读取已安装的 DB。我的问题是,当 DBA 进行数据库导入时,该表将被锁定,直到完成为止,这可能需要几个小时。我想在我的代码中处理这种情况,方法是在执行此操作时不尝试连接到该数据库。

有没有办法通过 SQL 查询读出表的状态,无论它是否被锁定?

编辑: 我在代码中捕获 ODBC 异常(-2146232009)来处理锁定的表,但我不太喜欢用异常来处理这个问题的想法。

I'm reading out installed DB's from the sysmaster table on an Informix DB via ODBC. My problem is that when the DBA are doing an DB Import that table is locked out until it's done and this can take hours. I want to handle this situation in my code by not trying to connect to that DB when this is being done.

Is there a way of reading out a table's status whether or not it's locked via an SQL query?

Edit:
I'm catching ODBC exception (-2146232009) in my code to handle the locked table, but I don't really like the idea of handle this with an exception.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

攒眉千度 2024-10-15 06:44:12

sysmaster:syslocks 表应包含您需要的信息。它实际上是一个视图,但如果它是一个表,则语句可能如下所示:

CREATE TABLE "informix".syslocks
(
    dbsname     CHAR(128),
    tabname     CHAR(128),
    rowidlk     INTEGER,
    keynum      SMALLINT,
    type        VARCHAR(4),
    owner       INTEGER,
    waiter      INTEGER
);

在一个非常空闲的系统上,我在 sysmaster 数据库中闲逛,我运行:

SELECT * FROM SysLocks;

并得到了输出:

sysmaster   sysdatabases    516 0   S   31
sysmaster   sysdatabases    516 0   S   32
sysmaster   sysdatabases    516 0   S   33  
sysmaster   sysdatabases    513 0   S   37

这应该为您提供所需的信息。您可能需要做一些实验以确保正确(找出 DB-Import 在其正在处理的数据库上设置或已经设置的锁)。

还有另一个视图,即 SysLockTab 视图,它包含更详细、更少面向用户的信息。您可以访问这些视图所构建的任何基础表。这些应该为您提供 SysLocks 视图中缺少的任何信息。

The sysmaster:syslocks table should contain the information you need. It is actually a view, but if it were a table, the statement might look like:

CREATE TABLE "informix".syslocks
(
    dbsname     CHAR(128),
    tabname     CHAR(128),
    rowidlk     INTEGER,
    keynum      SMALLINT,
    type        VARCHAR(4),
    owner       INTEGER,
    waiter      INTEGER
);

On a very idle system where I was poking around the sysmaster database, I ran:

SELECT * FROM SysLocks;

and got the output:

sysmaster   sysdatabases    516 0   S   31
sysmaster   sysdatabases    516 0   S   32
sysmaster   sysdatabases    516 0   S   33  
sysmaster   sysdatabases    513 0   S   37

This should give you the information you need. You'll probably need to do some experimentation to make sure you get it right (finding out exactly what locks DB-Import sets, or has set, on the database it is working on).

There is another view, the SysLockTab view, that contains more detailed, less user-oriented information. And there are whatever underlying tables that these views are built on that you could access instead. These should give you any information missing from the SysLocks view.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文