Problem while handling server restart with postgresql 8.4.12
(original reporter: abdelrahman) I have a system where I am upgrading my postgresql from version 8.4.3 to 8.4.12 while my sqlachamy version is 0.6.4 which i also update to version 0.7.8. I had a problem that the sqlachamy was not able to handle the server restart anymore where any requests from my session if the restart fails with:
(InterfaceError) connection already closed None None
I had a debugged the problem for a bit and it seems that the exception msg raised by the postgresql server when its shutdown is changes from 8.4.3 to 8.4.12, where in 8.4.3 it was
OperationalError('terminating connection due to administrator command\nserver closed the connection unexpectedly\n\tThis probably means the server terminated abnormally\n\tbefore or while processing the request.\n',)
while the msg in 8.4.12 is
OperationalError('terminating connection due to administrator command\nFATAL: terminating connection due to administrator command\n',)
in the psycopg2.py in both the latest stable version and the development version of sqlalchamy, the method check if the connection is lost is:
def is_disconnect(self, e, connection, cursor):
if isinstance(e, self.dbapi.OperationalError):
# these error messages from libpq: interfaces/libpq/fe-misc.c.
# TODO: these are sent through gettext in libpq and we can't
# check within other locales - consider using connection.closed
return 'closed the connection' in str(e) or \
'connection not open' in str(e) or \
'could not receive data from server' in str(e)
elif isinstance(e, self.dbapi.InterfaceError):
# psycopg2 client errors, psycopg2/conenction.h, psycopg2/cursor.h
return 'connection already closed' in str(e) or \
'cursor already closed' in str(e)
elif isinstance(e, self.dbapi.ProgrammingError):
# not sure where this path is originally from, it may
# be obsolete. It really says "losed", not "closed".
return "losed the connection unexpectedly" in str(e)
else:
return False
Notice that when the OperationalError is raised(which is the one raised on server shutdown), the exception message is parsed to match of the expected error msgs which does not match in postgresql 8.4.12
Comments (5)
-
repo owner -
Account Deleted (original author: abdelrahman) yes i tested the fix and it seems to fix the problem. Thank you for the quick response
-
repo owner OK will try to get that into 0.7.9
-
repo owner - changed status to resolved
-
repo owner - removed milestone
Removing milestone: 0.7.9 (automated comment)
- Log in to comment
can you confirm this patch fixes please: