diff --git a/django/db/backends/postgresql_psycopg2/base.py b/django/db/backends/postgresql_psycopg2/base.py
index 67e2877..e1a3a53 100644
a
|
b
|
class DatabaseWrapper(BaseDatabaseWrapper):
|
193 | 193 | return self.connection.commit() |
194 | 194 | except Database.IntegrityError, e: |
195 | 195 | raise utils.IntegrityError, utils.IntegrityError(*tuple(e)), sys.exc_info()[2] |
| 196 | |
| 197 | def close(self): |
| 198 | if self.connection is None: |
| 199 | return |
| 200 | |
| 201 | try: |
| 202 | self.connection.close() |
| 203 | self.connection = None |
| 204 | |
| 205 | # in some cases psycopg2 can throw an exception on closing, some of |
| 206 | # these exceptions indicate that the connection has been closed, try to |
| 207 | # recognize those and mark the connection as closed. |
| 208 | # Taken from http://www.sqlalchemy.org/trac/browser/lib/sqlalchemy/dialects/postgresql/psycopg2.py |
| 209 | except psycopg2.OperationalError, e: |
| 210 | if 'closed the connection' in str(e) or 'connection not open' in str(e) or 'could not receive data from server' in str(e): |
| 211 | self.connection = None |
| 212 | else: |
| 213 | raise |
| 214 | except psycopg2.InterfaceError, e: |
| 215 | if 'connection already closed' in str(e) or 'cursor already closed' in str(e): |
| 216 | self.connection = None |
| 217 | else: |
| 218 | raise |
| 219 | except psycopg2.ProgrammingError, e: |
| 220 | if "losed the connection unexpectedly" in str(e): |
| 221 | self.connection = None |
| 222 | else: |
| 223 | raise |