Odoo Help


This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.


How to script the creation of a new database?

Ian Beardslee
on 8/5/13, 12:20 AM 6,088 views

We are trying to improve our development process and part of that is ensuring that people create a new database and install our modules in their dev environment as part of their test process before they commit their changes to our git repo.

Using ..

/usr/bin/openerp-server -c /etc/openerp/openerp-server.conf --init=our_module --stop-after-init -d test_database

.. I can script the installation of our modules in a new database that as been created through the web interface, but how can that new test_database be created from the command line?

We must update our modules to a duplicate of our existing database .. which leads to a 2nd related question .. is there a way to duplicate an existing database from the command line?

Marwan Yassin
On 2/6/16, 5:01 AM

For Odoo 9, and most likely with every Odoo version higher than 6.1

pip install oerplib 

Then create a python script : create_db.py


import sys #import sys if you want command line args

import oerplib

oerp = oerplib.OERP(server='localhost', protocol='xmlrpc', port=8069)

oerp.db.create_database('SUPER_ADMIN_PWD', "DB_NAME", False, 'en_US', "DB_PASS")

You can replace DB_NAME and DB_PASS with sys.argv[n] and pass the value from command line or script

Em Sciara
On 11/17/15, 12:23 PM

On Odoo 9.0 (and I guess also 8.0), if test_database does not exist, the exact command you wrote will create it automatically through the -d flag...

As far as I can tell this does not work in 8.0: Odoo will fail startup with an OperationalError.

Atte Isopuro
on 2/3/16, 7:53 AM
Laura Jarvenpaa
On 8/5/13, 3:22 AM

stackoverflow.com/questions/876522/creating-a-copy-of-a-database-in-postgres (can't post links so removed the http part)

From there duplicating db from command line:

createdb -O ownername -T originaldb newdb

Haven't tested this one but would assume that it works because it has been voted as a good answer.

Hmm that is a valid workaround. I was actually trying to work out how to do it via OpenERP. Ultimate goal is to have a single script that runs on the OpenERP server that drops some test databases, creates one 'empty' OpenERP database to install our module and a duplicate of an existing database and updates our modules. Running it via OpenERP (running 'openerp-server' as the 'openerp' user) gets around the idea of having to provide additional credentials to do something on the DB server.

Ian Beardslee
on 8/5/13, 5:56 PM
Royal Administrator
On 10/8/14, 4:49 PM

# thanks to https://pythonhosted.org/OERPLib/

I have been able to create a database using oerplib from https://pythonhosted.org/OERPLib/, one of the two client libraries I have found "out there", the other being openerplib from https://pypi.python.org/pypi/openerp-client-lib.

Using oerplib:

# pip install oerplib

# python
>>> import oerplib
>>> jconn = oerplib.rpc.ConnectorJSONRPC('localhost', port=8069)
>>> jconn.proxy.web.database.get_list()
>>> jconn.proxy.web.database.create(fields=[{'name': 'super_admin_pwd', 'value': 'master-secret'}, {'name': 'db_name', 'value': 'my-new-database'}, {'name': 'create_admin_pwd', 'value': 'secret'}, {'name': 'create_confirm_pwd', 'value': 'secret'}, {'name': 'db_lang', 'value': 'en_US'}])

There are more concise mechanisms also, without all the 'name', 'value', etc.
This mechanism as written has indeed create a database for me.

God speed on your database creation automation journey,

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

2 follower(s)


Asked: 8/5/13, 12:20 AM
Seen: 6088 times
Last updated: 2/6/16, 5:01 AM