summaryrefslogtreecommitdiff
path: root/openerpcommand
diff options
context:
space:
mode:
authorVo Minh Thu <vmt@openerp.com>2013-02-19 16:16:13 +0100
committerVo Minh Thu <vmt@openerp.com>2013-02-19 16:16:13 +0100
commit1f269d0d93e684945f37cbe60ed53bc9fad41eb2 (patch)
tree0a58dfa4bd30ac34abba01fdf6e92e40cf67f156 /openerpcommand
parenteafdbbd60110980cf230ff795519d627b02c958b (diff)
[FIX] oe drop: correctly call netsvc.init_logger(), and use pid instead of procpid under postgres 9.2.
bzr revid: vmt@openerp.com-20130219151613-k0pvlemire9kvrok
Diffstat (limited to 'openerpcommand')
-rw-r--r--openerpcommand/drop.py13
1 files changed, 9 insertions, 4 deletions
diff --git a/openerpcommand/drop.py b/openerpcommand/drop.py
index aee8c2859f9..b64442716de 100644
--- a/openerpcommand/drop.py
+++ b/openerpcommand/drop.py
@@ -9,6 +9,7 @@ import common
# openerp/service/web_services.py).
def drop_database(database_name):
import openerp
+ openerp.netsvc.init_logger()
db = openerp.sql_db.db_connect('template1')
cr = db.cursor()
cr.autocommit(True) # avoid transaction block
@@ -16,17 +17,21 @@ def drop_database(database_name):
# TODO option for doing this.
# Try to terminate all other connections that might prevent
# dropping the database
+
+ # 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'
try:
- cr.execute("""SELECT pg_terminate_backend(procpid)
+ cr.execute("""SELECT pg_terminate_backend(%(pid_col)s)
FROM pg_stat_activity
- WHERE datname = %s AND
- procpid != pg_backend_pid()""",
+ WHERE datname = %%s AND
+ %(pid_col)s != pg_backend_pid()""" % {'pid_col': pid_col},
(database_name,))
except Exception:
pass
try:
- cr.execute('DROP DATABASE "%s"' % database_name)
+ cr.execute('DROP DATABASE "%s"' % database_name, log_exceptions=False)
except Exception, e:
print "Can't drop %s" % (database_name,)
finally: