简体   繁体   English

查询阻止时如何捕获此警告消息?

[英]How do I capture this warning message when the query is blocking?

When I do a query with isql I get the following message and the query blocks. 当我使用isql进行查询时,我得到以下消息和查询块。

The transaction log in database foo is almost full. 数据库foo中的事务日志几乎已满。 Your transaction is being suspended until space is made available in the log. 您的事务将暂停,直到日志中的空间可用。

When I do the same from Python: 当我从Python做同样的事情时:

cursor.execute(sql)

The query blocks, but I would like see this message. 查询阻止,但我想看到此消息。

I tried: 我试过了:

Sybase.set_debug(sys.stderr)
connection.debug = 1

I'm using: 我正在使用:

  • python-sybase-0.40pre1 蟒蛇,SYBASE,0.40pre1
  • Adaptive Server Enterprise/15.5/EBF 18164 Adaptive Server Enterprise / 15.5 / EBF 18164

EDIT: The question is, "How do I capture this warning message in the python program?" 编辑:问题是,“如何在python程序中捕获此警告消息?”

Good question and I'm not sure I can completely answer it. 好问题,我不确定我能否完全回答。 Here are some ideas. 这是一些想法。

Sybase.py uses logging. Sybase.py使用日志记录。 Make sure you are using it. 确保您使用它。 To "bump" the logging out I would do this: 要“阻止”退出,我会这样做:

import logging
logging.basicConfig(level = logging.INFO,
                    format = "%(asctime)s %(levelname)s [%(filename)s] (%(name)s) %(message)s",
                    datefmt = "%H:%M:%S", stream = sys.stdout)
log = logging.getLogger('sybase')
log.setLevel(logging.DEBUG)

And apparently (why is beyond me??) to get this working in Sybase.py you need to set a global DEBUG=True (see line 38) 显然(为什么超出我?)要在Sybase.py中使用它,你需要设置一个全局DEBUG=True (见第38行)

But then if we look at def execute we can see (as you point out) that it's blocking. 但是如果我们看看def execute我们可以看到(正如你指出的那样)它是阻塞的。 We'll that sort of answers your question. 我们会回答你的问题。 You aren't going to get anything back as it's blocking it. 你不会得到任何回报,因为它阻止了它。 So how do you fix this - write a non-blocking excute method;) There is some hints in examples/timeout.py. 那么你如何解决这个问题 - 编写一个非阻塞的执行方法;)examples / timeout.py中有一些提示。 Apparently someone else has run up on this but hasn't really fixed it. 显然其他人已经对此表示不满,但还没有真正修复它。

I know this didn't probably help but I spent 15 minutes looking - I should at least tell you what I found.. You would think that execute would give you some result -- Wait what is the value of result in line 707?? 我知道这可能没有帮助,但我花了15分钟看 - 我至少应该告诉你我发现了什么..你会认为execute会给你一些result - 等一下707的结果值是什么?

                while 1:
                    status, result = self._cmd.ct_results()
                    if status != CS_SUCCEED:
                        break

If status != CS_SUCCEED (which I'm assuming in your case is True) can you simply see what "result" is equal to? 如果status!= CS_SUCCEED(我假设你的情况是True),你能看到“结果”等于什么? I wonder if they just failed raise the result as an exception? 我想知道他们是否只是将结果作为例外提出?

原因很明显,事务日志已满,你可以在sybase MDA表monSysStatement中查看blocikng查询。这里你可以检查sql语句,它取高Io,时间,行数影响等。

Your query may be large which is overflowing the transaction log (eg you are inserting large binary files). 您的查询可能很大,这会溢出事务日志(例如,您正在插入大型二进制文件)。 Or you may not be truncating your transaction logs often enough if that's an option. 或者,如果这是一个选项,您可能不会经常截断您的事务日志。

During runtime you will want to have an except statement that catches the exception Error. 在运行时期间,您将需要一个捕获异常错误的except语句。

See the Sybase Python documentation . 请参见Sybase Python文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM