When Odoo can’t talk to PostgreSQL
You open Odoo in your browser and see a blank page or an error message that mentions the database. The Odoo server process may be running, but the web interface refuses to load. In the background, Odoo tries to connect to PostgreSQL, the database that stores all your company data, but the connection fails.
This failure affects everyone: users cannot log in, sales orders are stuck, inventory updates queue up, and reports won’t generate. The longer it lasts, the more data risks being inconsistent or lost.
Typical signs you’re facing this issue
- Browser error: “Database connection failed” or “Could not connect to PostgreSQL”
- Server log:
psycopg2.OperationalError,could not connect to server,no pg_hba.conf entry - Odoo service: Odoo process is running but logs show repeated connection attempts ending in failure
Why PostgreSQL connection fails in production
Most connection failures fall into three categories. Knowing which one you’re facing is the first step to fixing it.
1. PostgreSQL is not accepting connections
This happens when PostgreSQL is not running, is bound to the wrong network address, or is configured to reject all remote connections. Common causes:
- PostgreSQL service is stopped or crashed
- PostgreSQL is configured to listen only on
localhostand Odoo runs on a different server - Firewall or cloud security group blocks TCP port 5432
- PostgreSQL is set to
rejectall connections inpg_hba.conf
2. Odoo is misconfigured for the database
Odoo stores database connection details in its configuration file. If these details are wrong, Odoo cannot connect even if PostgreSQL is healthy. Common mistakes:
- Incorrect database name, user, or password in
odoo.conf - PostgreSQL user lacks permissions to access the database
- Odoo is configured to use a non-existent database
3. Database or user was deleted or altered
Sometimes the database or user that Odoo relies on no longer exists. This can happen after a migration, backup restore, or accidental deletion. Symptoms include:
- Error:
database "odoo_prod" does not exist - Error:
role "odoo" does not exist
Quick checks before diving deeper
Start with these three checks. They take less than two minutes and often reveal the root cause.
Check 1: Is PostgreSQL running?
On the server where PostgreSQL is installed, run:
systemctl status postgresql
What to look for: If the service is inactive (dead) or failed, restart it:
sudo systemctl restart postgresql
Success: Service status shows active (running).
Check 2: Can Odoo reach PostgreSQL?
From the Odoo server, test the connection to PostgreSQL using the psql command-line tool. Replace odoo_user and odoo_prod with your actual database user and name:
psql -h localhost -U odoo_user -d odoo_prod -c "SELECT 1;"
What to look for:
- If you see
Password:, enter the password and press Enter - If you see
could not connect to server, PostgreSQL is not accepting connections - If you see
permission denied, the user lacks permissions - If you see
SELECT 1, the connection works
Check 3: Are Odoo’s connection details correct?
Open the Odoo configuration file, usually at /etc/odoo/odoo.conf or in your Odoo installation directory. Look for the db_user, db_password, and db_name settings. Compare them to what you expect based on your PostgreSQL setup.
Tip: If you’re unsure, ask your Odoo administrator or check the Odoo implementation guide for standard defaults.
Step-by-step recovery guide
Use this checklist to recover the connection. Follow the steps in order and verify after each one.
Step 1: Restart PostgreSQL
If PostgreSQL crashed or was stopped, restart it:
sudo systemctl restart postgresql
Verify: Run systemctl status postgresql and look for active (running).
Step 2: Confirm PostgreSQL is listening on the network
Check if PostgreSQL accepts network connections:
sudo -u postgres psql -c "SHOW listen_addresses;"
What to look for:
localhostmeans it only accepts connections from the same server*means it accepts connections from any server- If only
localhostis shown and Odoo is on another server, update PostgreSQL configuration
Step 3: Update PostgreSQL to accept remote connections (if needed)
Edit PostgreSQL’s network configuration file, usually /etc/postgresql//main/postgresql.conf:
sudo nano /etc/postgresql/14/main/postgresql.conf
Find the line:
#listen_addresses = 'localhost'
Change it to:
listen_addresses = '*'
Save and close the file. Restart PostgreSQL:
sudo systemctl restart postgresql
Step 4: Update pg_hba.conf to allow the Odoo user
Edit the host-based authentication file, usually /etc/postgresql//main/pg_hba.conf:
sudo nano /etc/postgresql/14/main/pg_hba.conf
Add or update a line like this at the bottom of the file:
# TYPE DATABASE USER ADDRESS METHOD
host odoo_prod odoo_user 192.168.1.0/24 md5
Adjust: Replace 192.168.1.0/24 with the IP range of your Odoo server. Use 0.0.0.0/0 only if you fully trust your network.
Reload PostgreSQL to apply changes:
sudo systemctl reload postgresql
Step 5: Verify the Odoo user and database exist
Check if the database and user exist in PostgreSQL:
sudo -u postgres psql -c "\l" | grep odoo_prod
sudo -u postgres psql -c "\du" | grep odoo_user
If either is missing: Restore the database from backup or create it using the createdb command. For example:
sudo -u postgres createdb -O odoo_user odoo_prod
Step 6: Confirm Odoo configuration is correct
Open your Odoo configuration file and verify the connection details:
[options]
db_user = odoo_user
db_password = your_password
db_name = odoo_prod
Note: Never store plaintext passwords in configuration files. Use environment variables or Odoo’s secret management if available.
Step 7: Restart Odoo
Restart the Odoo service to pick up any configuration changes:
sudo systemctl restart odoo
Verify: Open Odoo in your browser. If it loads, the connection is restored.
What to do if Odoo still can’t connect
If you’ve followed all steps and Odoo still fails, the issue is likely deeper. Use this decision guide to narrow it down.
Decision guide
| Symptom | Likely cause | Next step |
|---|---|---|
no pg_hba.conf entry in logs |
PostgreSQL rejects the connection due to missing host rule | Update pg_hba.conf and reload PostgreSQL |
password authentication failed |
Wrong password or user in Odoo config | Update password in Odoo config or reset PostgreSQL user password |
database does not exist |
Database was deleted or never created | Restore from backup or create new database and reinstall Odoo |
connection refused |
PostgreSQL not running or port blocked by firewall | Check systemctl status postgresql and firewall rules |
role does not exist |
PostgreSQL user was deleted | Recreate user with createuser and grant permissions |
Advanced troubleshooting
If the issue persists, gather these logs for further analysis:
- PostgreSQL logs:
/var/log/postgresql/postgresql-14-main.log - Odoo logs:
/var/log/odoo/odoo-server.log - System logs:
journalctl -u postgresql -u odoo --no-pager -n 100
Tip: If you’re using a cloud provider, check security groups and network ACLs for port 5432.
Preventing connection failures in the future
Once the connection is restored, take these steps to reduce the risk of recurrence.
1. Monitor PostgreSQL service
Set up a simple health check script that runs every 5 minutes and alerts you if PostgreSQL stops:
#!/bin/bash
if ! systemctl is-active --quiet postgresql; then
echo "PostgreSQL is not running!" | mail -s "PostgreSQL Alert" [email protected]
fi
2. Use environment variables for credentials
Instead of storing passwords in odoo.conf, use environment variables or Odoo’s built-in secret management. This reduces the risk of accidental exposure during deployments or backups. For example:
export ODOO_DB_USER=odoo_user
export ODOO_DB_PASSWORD=your_password
export ODOO_DB_NAME=odoo_prod
3. Regularly back up PostgreSQL
Schedule automated backups of your PostgreSQL database to ensure you can restore quickly if the database is deleted or corrupted. Use pg_dump:
sudo -u postgres pg_dump odoo_prod > /backups/odoo_prod-$(date +%F).sql
Tip: Store backups offsite or in a separate volume to protect against disk failures.
4. Use a dedicated database user for Odoo
Create a dedicated PostgreSQL user for Odoo with limited permissions. This limits the damage if the password is compromised. For example:
sudo -u postgres createuser --pwprompt --createdb --no-superuser odoo_user
Grant minimal permissions: Only allow access to the Odoo database.
5. Document your setup
Create a simple runbook with these details:
- PostgreSQL version and installation path
- Database name, user, and password (stored securely)
- Odoo configuration file location
- Steps to restore the database
- Contact details for your Odoo partner or support team
Store this document in a shared location accessible to your operations team.
When to seek help
If you’ve tried the steps above and Odoo still can’t connect, it’s time to escalate. Use these triggers to decide when to seek help.
Escalate immediately if:
- The connection fails and you see
data directory "/var/lib/postgresql/14/main" does not existin logs - Restarting PostgreSQL fails with
FATAL: could not open file "postgresql.conf" - Odoo logs show repeated
OperationalError: server closed the connection unexpectedly - You suspect data corruption or accidental deletion of the database
Who to contact
If you’re using an Odoo implementation partner, contact them directly. Provide them with:
- PostgreSQL and Odoo logs (last 100 lines)
- Your Odoo configuration file (with sensitive details redacted)
- PostgreSQL version and installation path
If you’re running Odoo on a cloud platform, contact your cloud support team and reference your Odoo pricing tier for priority handling.
What not to do
- Do not delete or recreate the database unless you have a verified backup
- Do not change PostgreSQL configuration files without understanding the impact
- Do not restart Odoo repeatedly in quick succession; this can worsen the issue
Summary and next action
PostgreSQL connection failures in Odoo production are usually caused by one of three issues: PostgreSQL is not running or misconfigured, Odoo’s connection details are wrong, or the database or user is missing. Most of these issues can be resolved by checking three things: the PostgreSQL service status, the network configuration, and Odoo’s configuration file.
If you only take one action today, do this: Run systemctl status postgresql on your PostgreSQL server and verify the service is active. If it’s not, restart it and check the logs for errors. This single step resolves the majority of connection failures in production.
For ongoing reliability, document your setup, use environment variables for credentials, and schedule regular PostgreSQL backups. If the issue persists, escalate with clear logs and configuration details.
Practical Next Step
Check your database connection now
Discuss Your Odoo ScopeFAQ
What does the error 'no pg_hba.conf entry' mean and how do I fix it?
The error no pg_hba.conf entry means PostgreSQL is rejecting the connection because there is no rule in the pg_hba.conf file that allows the Odoo server’s IP address to connect to the database. To fix it, edit pg_hba.conf and add a line like host odoo_prod odoo_user 192.168.1.0/24 md5, then reload PostgreSQL with sudo systemctl reload postgresql. Replace the IP range with your Odoo server’s actual IP or subnet.
How do I check if PostgreSQL is listening on the network?
Run sudo -u postgres psql -c "SHOW listen_addresses;". If the result is localhost, PostgreSQL only accepts connections from the same server. If you need remote access, change listen_addresses to * in postgresql.conf and restart PostgreSQL.
What should I do if the Odoo database was deleted?
If the database was deleted, restore it from your latest backup using sudo -u postgres psql -f /backups/odoo_prod-2024-01-01.sql. If you don’t have a backup, you may need to recreate the database and reinstall Odoo modules. Always confirm with your team before proceeding, as this may result in data loss.
Can I use a different PostgreSQL version with Odoo?
Odoo supports PostgreSQL 10, 11, 12, 13, 14, and 15. Using an unsupported version can cause compatibility issues. Check the Odoo custom addons documentation for version-specific requirements. If upgrading PostgreSQL, test in a staging environment first to avoid downtime in production.
How do I reset the PostgreSQL password for the Odoo user?
To reset the password for the Odoo user, run sudo -u postgres psql -c "ALTER USER odoo_user WITH PASSWORD 'new_password';". Then update the password in your Odoo configuration file or environment variable and restart Odoo. Ensure the new password is stored securely and shared only with authorized personnel.