[英]Segfault on 2nd connection with pyodbc to mirrored MS SQL Server
I'm facing an issue with a Python script that connects to a mirrored MS SQL server DB. 我遇到了与镜像MS SQL Server DB连接的Python脚本问题。 It's throwing a segmentation fault when I try connecting to the DB for the second time. 当我第二次尝试连接到数据库时,它将引发分段错误。 Both the app server and the DB instances are running on Google Compute Engine. 应用服务器和数据库实例均在Google Compute Engine上运行。
Here's some code replicating the issue: 这是一些复制该问题的代码:
import pyodbc
params = {
'autocommit': True,
'uid': 'myuser',
'tds_version': '8.0',
'DRIVER': '{mssql}',
'pwd': 'mypassword',
'server': 'sql-server-01',
'database': 'mydb',
'port': 1433,
}
c1 = pyodbc.connect(**params)
c2 = pyodbc.connect(**params)
The first connection (c1) succeeds, but the second connection (c2) fails immediately with segfault. 第一个连接(c1)成功,但是第二个连接(c2)立即因段错误而失败。 "mydb" is mirrored to a second server (sql-server-02). “ mydb”镜像到第二台服务器(sql-server-02)。 Using a non-mirrored DB, or disabling mirroring for this DB, makes it go away. 使用非镜像数据库或禁用该数据库的镜像会使它消失。
We have tried upgrading several libs, and that didn't fix the issue. 我们已经尝试升级几个库,但是并没有解决问题。 Versions: 版本:
To add here, Java code performing the same steps works fine. 要在此处添加,执行相同步骤的Java代码可以正常工作。
Any ideas? 有任何想法吗?
The MSODBC driver has a lot of known issues, especially with multithreading. MSODBC驱动程序有很多已知问题,尤其是在多线程方面。 It sounds like you're running into this. 听起来您好像遇到了这种情况。 I ran into it with Django's runserver; 我在Django的runserver中遇到了这个问题; it would only work (and still with bugs in SQLRowCount) with the --nothreading
option for Django's runserver. 只有使用Django的runserver的--nothreading
选项,它才能正常工作(并且仍然存在SQLRowCount中的错误)。
Fortunately, Microsoft is now assembling a team to make a better performing, reliable driver (thank you, MS!). 幸运的是,Microsoft现在正在组建一个团队,以提供性能更好,更可靠的驱动程序(谢谢您,MS!)。 In the meantime, I use FreeTDS 0.95 (which supports up to TDS version 7.3, a la SQL Server 2008), which has treated me very well. 同时,我使用的是FreeTDS 0.95(它支持TDS 7.3版,即SQL Server 2008),这对我来说非常好。 Give that a try? 试试看吗? Good luck. 祝好运。
It is a known issue in certain versions of MS ODBC + unixODBC. 在某些版本的MS ODBC + unixODBC中,这是一个已知问题。 By upgrading to unixODBC-2.3.2 and the latest MS ODBC driver, solves the issue on some distributions of linux, eg ubuntu and debian. 通过升级到unixODBC-2.3.2和最新的MS ODBC驱动程序,解决了某些Linux发行版上的问题,例如ubuntu和debian。 You can follow the steps for upgrade here: https://blog.afoolishmanifesto.com/posts/install-and-configure-the-ms-odbc-driver-on-debian/ it solved the double connection issue - can open multiple connections without segfaulting. 您可以在此处按照升级步骤进行操作: https : //blog.afoolishmanifesto.com/posts/install-and-configure-the-ms-odbc-driver-on-debian/它解决了双重连接问题-可以打开多个连接没有segfaulting。
The same upgrade / steps did not work for me on RedHat 7.1 though - you still get a segfault on opening a connection twice in same session. 尽管在RedHat 7.1上,相同的升级步骤对我不起作用-在同一会话中两次打开连接仍会遇到段错误。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.