Initializing a new Odoo database
To be able to create a new database, your user must be a PostgreSQL superuser. The ./odoo.py setup_pg
does that for you; otherwise use the following command to create a PostgreSQL superuser for the current Unix user with:
$ sudo createuser --superuser $(whoami)
To create a new database we use the command createdb
. Let's create a v8dev
database:
$ createdb v8dev
To initialize this database with the Odoo data schema we should run Odoo on the empty database by using the -d
option:
$ ~/odoo-dev/odoo/odoo.py -d v8dev
This will take a couple of minutes to initialize a v8dev
database, and will end with an INFO log message Modules loaded. Then the server will be ready to listen to client requests.
By default, this method will initialize the database with demonstration data, which often is useful on development databases. To initialize a database without demonstration data, add to the command the option: --without-demo-data=all
.
Open http://<server-name>:8069
in your browser to be presented with the login screen. If you don't know your server name, type the hostname
command at the terminal to find it, or the ifconfig
command to find the IP address.
If you are hosting Odoo in a virtual machine you might need to do some network configuration to be able to use it as a server. The simplest solution is to change the VM network type from NAT to Bridged. With this, instead of sharing the host IP address, the guest VM will have its own IP address. It's also possible to use NAT, but that requires you to configure port forwarding, so your system knows that some ports, such as 8069, should be handled by the VM. In case you're having trouble, hopefully these details can help you find help in the documentation for your chosen virtualization software.
The default administrator account is admin
with password admin
. Upon login you are presented with the Settings menu, displaying the installed modules. Remove the Installed filter and you will be able to see and install any of the official modules.
Whenever you want to stop the Odoo server instance and return to the command line, press Ctrl + C. At the bash prompt, pressing the Up arrow key will bring you the previous shell command, so it's a quick way to start Odoo again with the same options. You will see the Ctrl + C followed by Up arrow and Enter is a frequently used combination to restart the Odoo server during development.
Managing your databases
We've seen how to create and initialize new Odoo databases from the command line. There are more commands worth knowing for managing databases.
You already know how to use the createdb
command to create empty databases, but it can also create a new database by copying an existing one, by using a --template
option.
Make sure your Odoo instance is stopped and you have no other connection open on the v8dev
database created above, and run:
$ createdb --template=v8dev v8test
In fact, every time we create a database, a template is used. If none is specified, a predefined one called template1
is used.
To list the existing databases in your system use the PostgreSQL utility psql
utility with the -l
option:
$ psql -l
Running it we should see listed the two databases we created so far: v8dev
and v8test
. The list will also display the encoding used in each database. The default is UTF8, which is the encoding needed for Odoo databases.
To remove a database you no longer need (or want to recreate), use the dropdb
command:
$ dropdb v8test
Now you know the basics to work with several databases. To learn more on PostgresSQL, the official documentation can be found at http://www.postgresql.org/docs/
Note
WARNING: The drop database will irrevocably destroy your data. Be careful when using it and always keep backups of your important databases before using it.