PostgreSQL is the heart of every Odoo installation. Configuring the database correctly is crucial for the performance, security and stability of the entire ERP system. In this guide, we will show you how to professionally set up a PostgreSQL database for Odoo.
Why is PostgreSQL essential for Odoo?
Odoo uses PostgreSQL as its only database. It is a powerful, open-source relational database management system that offers advanced features, high performance and reliability. Without a properly configured PostgreSQL instance, Odoo simply will not work.
PostgreSQL gives Odoo support for complex queries, ACID transactions, multi-version concurrency control (MVCC) and a wide range of data types, including JSON, which Odoo uses extensively. These features make it an ideal choice for an ERP system that handles business data.
Installing PostgreSQL
Installation on Linux (Ubuntu/Debian)
Before configuring the database for Odoo, you need to install the PostgreSQL server. On Ubuntu- or Debian-based systems, the process is simple:
sudo apt update
sudo apt install postgresql postgresql-client -y
After installation, the PostgreSQL service starts automatically. You can check its status with the following command:
sudo systemctl status postgresql
Important: Make sure you install the right PostgreSQL version. Odoo 17 requires PostgreSQL 12 to 16, while Odoo 16 supports versions 10 to 15. We recommend installing PostgreSQL 14 or later for optimal performance.
Installation on Windows
On Windows, download the PostgreSQL installer from the official website. Once downloaded, run the installer and follow the wizard's instructions. During installation, remember the administrator password (postgres), as you will need it later.
If you are installing Odoo on Windows, see our guide: How to Install Odoo on Windows? A Step-by-Step Guide.
Creating a PostgreSQL User for Odoo
Odoo requires a dedicated PostgreSQL user with the appropriate permissions. For security reasons, you should not use the postgres superuser account for application connections.
Step 1: Switch to the postgres user
On Linux systems, switch to the postgres system user:
sudo su - postgres
Step 2: Create a new user
Create a new PostgreSQL user for Odoo. The username should match the name of the system user that will run Odoo:
createuser -d -R -S odoo
The parameters mean:
- -d: the user can create databases (required for Odoo to be able to create new databases through the web interface)
- -R: the user cannot create new roles
- -S: the user is not a superuser
Alternatively, you can create a user with a password using the psql interface:
psql
CREATE USER odoo WITH PASSWORD 'silne_haslo' CREATEDB;
\q
Step 3: Install the required PostgreSQL extensions
Odoo requires several PostgreSQL extensions for full functionality. Log in as postgres and enable the necessary extensions:
sudo su - postgres
psql
CREATE EXTENSION IF NOT EXISTS pg_trgm;
CREATE EXTENSION IF NOT EXISTS unaccent;
\q
The pg_trgm extension is required for full-text search in Odoo, and unaccent enables searching without regard to diacritical marks.
Configuring PostgreSQL for Optimal Odoo Performance
The default PostgreSQL configuration is not optimized for Odoo. To ensure the best performance, you need to adjust several parameters.
Editing the postgresql.conf file
The PostgreSQL configuration file is usually located at:
- Ubuntu/Debian:
/etc/postgresql/[wersja]/main/postgresql.conf - Windows:
C:\Program Files\PostgreSQL\[wersja]\data\postgresql.conf
Open the file as an administrator and adjust the following parameters:
shared_buffers = 512MB
effective_cache_size = 2GB
maintenance_work_mem = 128MB
work_mem = 16MB
max_connections = 100
wal_buffers = 16MB
checkpoint_completion_target = 0.9
random_page_cost = 2.0
These values are suitable for a server with 4GB of RAM. For larger servers, you can increase them proportionally. The shared_buffers parameter should be about 25% of available RAM, and effective_cache_size about 50-75%.
The random_page_cost parameter set to 2.0 is optimal for SSD drives. For traditional HDDs, keep the default value of 4.0.
Autovacuum configuration
Autovacuum is key to maintaining the performance of your Odoo database over time. Odoo generates a lot of transactions, so regular cleanup is essential:
autovacuum = on
autovacuum_max_workers = 3
autovacuum_naptime = 1min
autovacuum_vacuum_scale_factor = 0.05
autovacuum_analyze_scale_factor = 0.02
Restarting the PostgreSQL service
After making the changes, restart PostgreSQL:
sudo systemctl restart postgresql
Security Configuration
The pg_hba.conf file
The pg_hba.conf file controls who can connect to the database. It is located in the same directory as postgresql.conf.
For local Odoo installations, add the following line:
local all odoo md5
For remote connections (only in secure networks!):
host all odoo 192.168.1.0/24 md5
Replace the IP range with one that matches your network. For production environments, using SSL is recommended:
hostssl all odoo 192.168.1.0/24 md5
After the changes, reload the PostgreSQL configuration:
sudo systemctl reload postgresql
Creating a Database for Odoo
Odoo automatically creates a database during the first setup through the web interface. Important: To be able to create databases through the Odoo interface, you must set the admin_passwd parameter (master password) in the Odoo configuration file.
However, you can also create the database manually:
createdb -O odoo nazwa_bazy
The -O odoo parameter sets the odoo user as the database owner.
After creating the database, make sure the extensions are available:
psql -d nazwa_bazy -c "CREATE EXTENSION IF NOT EXISTS pg_trgm;"
psql -d nazwa_bazy -c "CREATE EXTENSION IF NOT EXISTS unaccent;"
Configuring the Odoo Connection to PostgreSQL
Once PostgreSQL is configured, you need to tell Odoo how to connect to the database. This is done through the Odoo configuration file (odoo.conf).
Add or modify the following parameters:
db_host = localhost
db_port = 5432
db_user = odoo
db_password = silne_haslo
db_name = False
db_maxconn = 64
admin_passwd = bardzo_silne_master_haslo
The db_name = False parameter allows Odoo to manage multiple databases. If you work with only one database, you can specify its name.
The db_maxconn parameter specifies the maximum number of database connections per Odoo process. A value of 64 is suitable for most installations. Make sure that max_connections in PostgreSQL is higher than db_maxconn × number of workers.
The admin_passwd parameter (master password) is required to manage databases through the Odoo web interface - creating, duplicating, deleting and backing up databases.
If you are installing Odoo on Ubuntu, check out our detailed guide: How to Install Odoo on Ubuntu? A Complete Step-by-Step Guide.
Testing the Connection
To test whether everything works correctly, start Odoo and check the logs. If the connection is correct, you should see messages about a successful database connection.
You can also test the connection manually:
psql -U odoo -h localhost -d postgres
If you can log in (and enter the password, if you set one), the configuration is correct.
Database Backup and Maintenance
Regular backups are crucial for the security of your business data. PostgreSQL offers the pg_dump tool:
pg_dump -U odoo -F c nazwa_bazy > backup.dump
The -F c parameter creates a backup in custom format, which is compressed and allows selective restoration.
Restoring from a backup:
pg_restore -U odoo -d nazwa_bazy -c backup.dump
The -c parameter cleans existing objects before restoring, which prevents conflicts.
Important: A database backup is only part of an Odoo backup. You must also back up the filestore directory, which contains attachments and files. By default, it is located in ~/.local/share/Odoo/filestore/nazwa_bazy (Linux) or in the Odoo data directory (Windows).
A full Odoo backup should include:
- The PostgreSQL database dump
- The filestore directory
- The odoo.conf configuration file
- Any custom modules
Consider automating backups using cron (Linux) or Task Scheduler (Windows). An example cron entry for a daily backup at 2:00 AM:
0 2 * * * pg_dump -U odoo -F c nazwa_bazy > /backup/odoo_$(date +\%Y\%m\%d).dump
Performance Monitoring and Optimization
Regularly monitoring PostgreSQL performance is crucial for keeping Odoo running optimally. You can use the pgBadger tool to analyze PostgreSQL logs and identify slow queries.
Enable slow query logging in postgresql.conf:
log_min_duration_statement = 1000 # log queries longer than 1 second
log_line_prefix = '%t [%p]: [%l-1] user=%u,db=%d,app=%a,client=%h '
log_checkpoints = on
log_connections = on
log_disconnections = on
log_lock_waits = on
Alternative: Installation with Docker
If you want to avoid configuring PostgreSQL manually, consider using Docker. Docker automatically configures PostgreSQL together with Odoo in isolated containers. See our guide: How to Install Odoo Using Docker?
FAQ - Frequently Asked Questions
Can I use a database other than PostgreSQL for Odoo?
No, Odoo requires PostgreSQL exclusively. The system was designed specifically to work with PostgreSQL and relies on features specific to this database, such as JSONB, arrays and advanced indexing. It does not support other database management systems such as MySQL, MariaDB or Microsoft SQL Server.
Which PostgreSQL version should I install for Odoo?
The recommended version depends on your Odoo version:
- Odoo 17: PostgreSQL 12, 13, 14, 15 or 16 (14 or later recommended)
- Odoo 16: PostgreSQL 10, 11, 12, 13, 14 or 15 (12 or later recommended)
- Odoo 15: PostgreSQL 10, 11, 12, 13 or 14
Always check the official Odoo documentation for current requirements. Avoid using PostgreSQL versions older than 12, as compatibility and performance issues may occur.
How can I reset the PostgreSQL user password for Odoo?
Log in as the postgres user and use the SQL command:
sudo su - postgres
psql
ALTER USER odoo WITH PASSWORD 'nowe_haslo';
\q
Then update the password in the Odoo configuration file (odoo.conf) in the db_password parameter and restart the Odoo service:
sudo systemctl restart odoo
Do I need PostgreSQL extensions for Odoo?
Yes, Odoo requires at least two PostgreSQL extensions:
- pg_trgm - essential for full-text search and for the performance of queries using the LIKE operator
- unaccent - enables searching without regard to diacritical marks (e.g. searching for "cafe" will also find "café")
Without these extensions, Odoo may not work properly or will be significantly slower.
Summary
Properly configuring a PostgreSQL database for Odoo is the foundation of a stable and efficient ERP system. By following this guide, you have created a secure database environment optimized for Odoo's needs. Remember to:
- Back up regularly (both the database and the filestore)
- Monitor performance and analyze slow queries
- Keep both PostgreSQL and Odoo updated to the latest compatible versions
- Apply security best practices, especially in production environments
- Set a master password for secure database management
Need help with your Odoo configuration?
Configuring PostgreSQL and Odoo can be challenging, especially for complex production environments. KK Innovations specializes in Odoo implementations and can help with the professional configuration, optimization and maintenance of your ERP system. Contact us to find out how we can support your business!