[MERGE] Try to terminate psql connections before dropping database

bzr revid: odo@openerp.com-20120316160216-enjjiyw8t6457tqj
This commit is contained in:
Olivier Dony 2012-03-16 17:02:16 +01:00
commit 224dc24dac
1 changed files with 13 additions and 0 deletions

View File

@ -173,6 +173,8 @@ class db(netsvc.ExportService):
raise Exception, e
def exp_drop(self, db_name):
if not self.exp_db_exist(db_name):
return False
openerp.modules.registry.RegistryManager.delete(db_name)
sql_db.close_db(db_name)
@ -180,6 +182,17 @@ class db(netsvc.ExportService):
cr = db.cursor()
cr.autocommit(True) # avoid transaction block
try:
# Try to terminate all other connections that might prevent
# dropping the database
try:
cr.execute("""SELECT pg_terminate_backend(procpid)
FROM pg_stat_activity
WHERE datname = %s AND
procpid != pg_backend_pid()""",
(db_name,))
except Exception:
pass
try:
cr.execute('DROP DATABASE "%s"' % db_name)
except Exception, e: