Skip to content

Instantly share code, notes, and snippets.

@iledarn
Last active July 13, 2016 05:26
Show Gist options
  • Save iledarn/590f2e183d6bee49860f77da36732bfe to your computer and use it in GitHub Desktop.
Save iledarn/590f2e183d6bee49860f77da36732bfe to your computer and use it in GitHub Desktop.
Use instruction in the following order:
1. postgresql_9.4_install_bdr_extension.rst
2. prepare_databases_for_odoo.rst
3. prepare_odoo.rst
4. ir_attachment_force_storage_module.rst

Install ir_attachemnt_force storage module from https://github.com/it-projects-llc/misc-addons.git repository.

Attache repository directory to path in /etc/odoo/openerp-server.conf for both VMs.

cd /usr/local/src/
git clone https://github.com/it-projects-llc/misc-addons.git
cd misc-addons
git checkout 8.0

Edit /etc/odoo/openerp-server.conf

append to addons_path line (comma-separated): /usr/local/src/misc-addons

Stop your odoo:

service odoo stop

Remove postgresql-9.3 version:

apt-get purge postgresq-9.3

Add postgresql into ubuntu package lists and install postgresql-9.4

wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add -
echo 'deb http://apt.postgresql.org/pub/repos/apt/ trusty-pgdg main' >> /etc/apt/sources.list.d/pgdg.list
apt-get update
apt-get install -y postgresql-9.4
apt-get install -y postgresql-contrib-9.4

2ndQuadrant BDR packages for Debian/Ubuntu Apt Repository

wget --quiet -O - http://packages.2ndquadrant.com/bdr/apt/AA7A6805.asc | sudo apt-key add -
echo 'deb http://packages.2ndquadrant.com/bdr/apt/ trusty-2ndquadrant main' >> /etc/apt/sources.list.d/2ndquadrant.list
apt-get update
apt-get install -y postgresql-bdr-9.4-bdr-plugin

Add bdr configuration into your postgresql.conf (the lines below are commands you should envoke from terminal)

sed -i "s/listen_addresses = 'localhost'/listen_addresses = '\*'/" /etc/postgresql/9.4/main/postgresql.conf
sed -i "s/^#listen_addresses/listen_addresses/" /etc/postgresql/9.4/main/postgresql.conf
echo "shared_preload_libraries = 'bdr'" >> /etc/postgresql/9.4/main/postgresql.conf
echo "wal_level = 'logical'" >> /etc/postgresql/9.4/main/postgresql.conf
echo "track_commit_timestamp = on" >> /etc/postgresql/9.4/main/postgresql.conf
echo "max_wal_senders = 10" >> /etc/postgresql/9.4/main/postgresql.conf
echo "max_replication_slots = 10" >> /etc/postgresql/9.4/main/postgresql.conf
echo "max_worker_processes = 10" >> /etc/postgresql/9.4/main/postgresql.conf

Allow network connections to you postgresql server. Edit /etc/postgresql/9.4/main/pg_hba.conf. Find # TYPE DATABASE USER ADDRESS METHOD string at the end of the file. Delete all strings below that and put the following strings after

# "local" is for Unix domain socket connections only
local   all             all                                     trust
# IPv4 local connections:
host    all             all             127.0.0.1/32            trust
# IPv6 local connections:
host    all             all             ::1/128                 trust
# Allow replication connections from localhost, by a user with the
# replication privilege.
#local   replication     postgres                                trust
#host    replication     postgres        127.0.0.1/32            trust
#host    replication     postgres        ::1/128                 trust

host all all 0.0.0.0/0 trust
host replication all 0.0.0.0/0 trust

Restart postgresql server

service postgresql restart

Pay attention to comments that are the lines that begin with #

VM1:

su - postgres
createdb odoodb1
createuser -s odoo # may skip this part if you have odoo user already
psql -c "ALTER DATABASE odoodb1 OWNER TO odoo"
ip addr # NOTE IP OF VM1
psql odoodb1

CREATE EXTENSION IF NOT EXISTS btree_gist;
CREATE EXTENSION IF NOT EXISTS bdr;
SELECT bdr.bdr_group_create(local_node_name := 'node01',node_external_dsn := 'host=172.17.0.2 port=5432 dbname=odoodb1'); # use VM1 IP instead of 172.17.0.2

VM2:

su - postgres
ip addr # NOTE IP OF VM2
createuser -s odoo # may skip this part if you have odoo user already
createdb odoodb1 -U odoo
psql odoodb1

CREATE EXTENSION IF NOT EXISTS btree_gist;
CREATE EXTENSION IF NOT EXISTS bdr;
SELECT bdr.bdr_group_join( local_node_name := 'node02',  node_external_dsn := 'host=172.17.0.3 port=5432 dbname=odoodb1',  join_using_dsn := 'host=172.17.0.2 port=5432 dbname=odoodb1');
# use VM2 IP instead of 172.17.0.3 and VM1 IP instead of 172.17.0.2
SELECT bdr.bdr_node_join_wait_for_ready();

Edit /usr/lib/python2.7/dist-packages/openerp/addons/base/base.sql

put new line after 4: SET LOCAL default_sequenceam = 'bdr';

cut all lines from 181 to the end of the file and paste them in new file /usr/lib/python2.7/dist-packages/openerp/addons/base/base2.sql

Edit /usr/lib/python2.7/dist-packages/openerp/addons/base/base2.sql

comment with -- all lines that begin with 'select setval'

Edit /usr/lib/python2.7/dist-packages/openerp/modules/db.py

put before 56 two lines: import time
                         time.sleep(10)

# they should have the same indent as next line

copy lines from 45 to 'base_sql_file.close()'
paste them after two lines we added before

Edit first line of the pasted block
before: f = openerp.modules.get_module_resource('base', 'base.sql')
should be: f = openerp.modules.get_module_resource('base', 'base2.sql')

Edit /usr/lib/python2.7/dist-packages/openerp/models.py

create new line after 2722: cr.execute("SET LOCAL default_sequenceam = 'bdr'")

2800: cr.execute('CREATE TABLE "%s" ("%s" INTEGER NOT NULL, "%s" INTEGER NOT NULL, UNIQUE("%s","%s"))' % (m2m_tbl, col1, col2, col1, col2))

2800: 2799: cr.execute('CREATE TABLE "%s" ("%s" INTEGER NOT NULL, "%s" INTEGER NOT NULL, PRIMARY KEY("%s","%s"))' % (m2m_tbl, col1, col2, col1, col2))

Edit /usr/lib/python2.7/dist-packages/openerp/addons/base/ir/ir_sequence.py

138: sql = "CREATE SEQUENCE ir_sequence_%03d INCREMENT BY %%s START WITH %%s" % id

138: sql = "CREATE SEQUENCE ir_sequence_%03d START WITH %%s USING bdr" % id

139: cr.execute(sql, (number_increment, number_next))

139: cr.execute(sql, (number_next,))

106: 'implementation': 'standard',

106: 'implementation': 'no_gap',

Edit /usr/lib/python2.7/dist-packages/openerp/modules/registry.py

232: cr.execute("""CREATE SEQUENCE base_registry_signaling INCREMENT BY 1 START WITH 1""")

232: cr.execute("""CREATE SEQUENCE base_registry_signaling START WITH 1 USING bdr""")

234: cr.execute("""CREATE SEQUENCE base_cache_signaling INCREMENT BY 1 START WITH 1""")

234: cr.execute("""CREATE SEQUENCE base_cache_signaling START WITH 1 USING bdr""")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment