[FIX] service: error database in use on duplicate database

When trying to duplicate a database, while
having opened connections to it, postgresql throws

```
OperationalError: source database "duplicate_test"
is being accessed by other users
DETAIL:  There is 1 other session using the database.
```

Connections must be dropped before trying duplication
using TEMPLATE to avoid this.
This commit is contained in:
Jos De Graeve 2015-03-18 18:20:25 +01:00 committed by Denis Ledoux
parent 534d5b8fe7
commit 7e7ecf36f1
1 changed files with 1 additions and 0 deletions

View File

@ -97,6 +97,7 @@ def exp_duplicate_database(db_original_name, 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_original_name)
cr.execute("""CREATE DATABASE "%s" ENCODING 'unicode' TEMPLATE "%s" """ % (db_name, db_original_name))
from_fs = openerp.tools.config.filestore(db_original_name)