psycopg2或PostgreSQL的sqlalchemy中获

psycopg2或PostgreSQL的sqlalchemy中获

本文介绍了是否有可能发布“ VACUUM ANALYZE< tablename>”消息。从psycopg2或PostgreSQL的sqlalchemy中获取?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗯,这个问题几乎可以概括一下。我的数据库活动非常密集,我想以编程方式发出真空分析。但是,我收到一条错误消息,指出无法在事务中执行查询。还有其他方法吗?

Well, the question pretty much summarises it. My db activity is very update intensive, and I want to programmatically issue a Vacuum Analyze. However I get an error that says that the query cannot be executed within a transaction. Is there some other way to do it?

推荐答案

这是Python DB-API中的一个缺陷:它会为您。它不应该那样做;是否以及何时开始交易应由程序员决定。这样的低级,核心API不应让开发人员烦恼,而应该做一些事情,例如在背后进行交易。我们是大男孩-谢谢,我们可以自己开始交易。

This is a flaw in the Python DB-API: it starts a transaction for you. It shouldn't do that; whether and when to start a transaction should be up to the programmer. Low-level, core APIs like this shouldn't babysit the developer and do things like starting transactions behind our backs. We're big boys--we can start transactions ourself, thanks.

使用psycopg2,您可以使用API​​扩展名禁用这种不幸的行为:run connection.autocommit = True 。不幸的是,由于没有标准的API,因此您必须依靠非标准的扩展来发出必须在事务之外执行的命令。

With psycopg2, you can disable this unfortunate behavior with an API extension: run connection.autocommit = True. There's no standard API for this, unfortunately, so you have to depend on nonstandard extensions to issue commands that must be executed outside of a transaction.

没有一种语言能克服这些缺陷,这是Python的其中之一。我也曾经被这个东西咬过。

No language is without its warts, and this is one of Python's. I've been bitten by this before too.

这篇关于是否有可能发布“ VACUUM ANALYZE< tablename>”消息。从psycopg2或PostgreSQL的sqlalchemy中获取?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-26 08:57