PostgreSQL tuning

Discussing PostgreSQL tuning is beyond the scope of this book. You may want to check out the books PostgreSQL 9 Admin Cookbook or PostgreSQL 9.0 High Performance, both from Packt Publishing, for an in-depth coverage of these topics.

The default configuration of PostgreSQL is generally very conservative and is meant to prevent the database server from hogging all the system resources. On production servers, you can safely increase some parameters in the postgresql.conf file to get better performance. Here are some settings for PostgreSQL 9.6 you can use to get started:

max_connections = 80 
shared_buffers = 256MB 
effective_cache_size = 768MB 
work_mem = 3276kB 
maintenance_work_mem = 64MB 
min_wal_size = 2GB
max_wal_size = 4GB
checkpoint_completion_target = 0.9 wal_buffers = 7864kB default_statistics_target = 100

You will need to restart PostgreSQL after modifying these settings.

The pgtune utility can help in finding more suitable configuration. An online version is available at http://pgtune.leopard.in.ua/:

Connect to the website and fill in the form:

  • DB Version: Use the database version you have installed (by default 9.6 in Debian Stretch)
  • OS Type: Linux
  • DB Type: Choose Online transaction processing system, as Odoo instances are heavy users of transactions
  • Total Memory (RAM): Put the amount of RAM you want to allocate to PostgreSQL; this will be almost all of it if you are using a dedicated server (see later)
  • Number of Connections: The max number of simultaneous queries your database server will accept

If your instance is heavily loaded, you will benefit from separating the database server and the Odoo server onto two different hosts. Don't use two virtual machines running on the same physical server if you are getting down to this; use two physical servers with a high speed network connection between both. In that case, you will need to ensure that the pg_hba.conf file on the database server host allows password authenticated connections on the database from the Odoo server, and that the postgresql.conf file lets the PostgreSQL server listen in on the network interface connecting both servers.