[FIX] server: db service, drop connection on drop

On database drop or rename, close the existing sql connections
This commit is contained in:
Denis Ledoux 2014-06-26 13:41:29 +02:00
parent 141e1b2615
commit 7e9dfa774e
1 changed files with 20 additions and 15 deletions

View File

@ -144,19 +144,11 @@ def exp_get_progress(id):
self_actions.pop(id)
raise Exception, e
def exp_drop(db_name):
if db_name not in exp_list(True):
return False
openerp.modules.registry.RegistryManager.delete(db_name)
openerp.sql_db.close_db(db_name)
db = openerp.sql_db.db_connect('postgres')
with closing(db.cursor()) as cr:
cr.autocommit(True) # avoid transaction block
def _drop_conn(cr, db_name):
# Try to terminate all other connections that might prevent
# dropping the database
try:
# PostgreSQL 9.2 renamed pg_stat_activity.procpid to pid:
# http://www.postgresql.org/docs/9.2/static/release-9-2.html#AEN110389
pid_col = 'pid' if cr._cnx.server_version >= 90200 else 'procpid'
@ -169,6 +161,18 @@ def exp_drop(db_name):
except Exception:
pass
def exp_drop(db_name):
if db_name not in exp_list(True):
return False
openerp.modules.registry.RegistryManager.delete(db_name)
openerp.sql_db.close_db(db_name)
db = openerp.sql_db.db_connect('postgres')
with closing(db.cursor()) as cr:
cr.autocommit(True) # avoid transaction block
_drop_conn(cr, db_name)
try:
cr.execute('DROP DATABASE "%s"' % db_name)
except Exception, e:
@ -274,6 +278,7 @@ def exp_rename(old_name, new_name):
db = openerp.sql_db.db_connect('postgres')
with closing(db.cursor()) as cr:
cr.autocommit(True) # avoid transaction block
_drop_conn(cr, old_name)
try:
cr.execute('ALTER DATABASE "%s" RENAME TO "%s"' % (old_name, new_name))
except Exception, e: