psycopg2 的服务器连接状态值是什么意思?

what do psycopg2's server connection status values mean?

我试图在打开连接和关闭连接后输出连接状态。打开它时我得到 1 的输出,关闭它时得到 2 的输出,但是在 psycopg2 的文档中没有讨论这些值的含义。有谁知道不同的状态值是什么意思?

我正在使用 status 函数获取连接状态值。

这些是记录在案的状态常量,您可以在这里找到它们:http://initd.org/psycopg/docs/extensions.html#connection-status-constants

不过,这不会告诉您它的数字 representation/value。如果你像我一样打印每个常量,你应该得到这个:

from psycopg2 import extensions as ext

print(ext.STATUS_READY) #1
print(ext.STATUS_BEGIN) #2
print(ext.STATUS_IN_TRANSACTION) #2  (this is an alias for STATUS_BEGIN)
print(ext.STATUS_PREPARED) #5

另请注意,文档指出:"The status is undefined for closed connectons (sic)." http://initd.org/psycopg/docs/connection.html#connection.status