Why Odoo Database Performance Matters
Every Odoo operation — loading a form, running a report, processing an invoice — translates to PostgreSQL queries. A poorly optimized database is the #1 cause of slow Odoo instances. An AI operations agent can diagnose and fix database performance issues faster than most DBAs because it understands both PostgreSQL internals and Odoo's ORM query patterns.
What the Agent Analyzes
Slow Query Detection
The agent monitors PostgreSQL for queries exceeding a configurable threshold (default: 100ms):
-- The agent runs this to find slow queries
SELECT query, calls, mean_exec_time, total_exec_time
FROM pg_stat_statements
ORDER BY mean_exec_time DESC
LIMIT 20;For each slow query, the agent:
- Identifies which Odoo model and method generated it
- Checks if appropriate indexes exist
- Analyzes the query plan with
EXPLAIN ANALYZE - Recommends specific index creation or ORM optimization
Missing Index Detection
The agent identifies tables with sequential scans that should have indexes:
-- Find tables with high sequential scan ratios
SELECT schemaname, relname,
seq_scan, idx_scan,
CASE WHEN seq_scan + idx_scan > 0
THEN round(100.0 * seq_scan / (seq_scan + idx_scan), 1)
ELSE 0 END AS seq_scan_pct
FROM pg_stat_user_tables
WHERE seq_scan > 1000
ORDER BY seq_scan_pct DESC;Common missing indexes in Odoo installations:
sale_order(date_order, state)— Sales order list views filter by date and stateaccount_move_line(account_id, date)— Account reports filter by account and periodstock_move(state, product_id)— Inventory operations filter by state and productmail_message(res_id, model)— Chatter loads messages by recordir_attachment(res_model, res_id)— Attachment loading
PostgreSQL Configuration Tuning
The agent checks your PostgreSQL settings against Odoo best practices:
| Parameter | Default | Recommended for Odoo | Why |
|---|---|---|---|
| shared_buffers | 128MB | 25% of RAM (max 8GB) | More data cached in memory |
| effective_cache_size | 4GB | 75% of RAM | Better query plan decisions |
| work_mem | 4MB | 16-64MB | Faster sorts and joins |
| maintenance_work_mem | 64MB | 512MB-1GB | Faster VACUUM and index creation |
| random_page_cost | 4.0 | 1.1 (SSD) / 2.0 (HDD) | Accurate cost estimates for index scans |
| max_connections | 100 | workers × 2 + 20 | Match Odoo worker count |
| checkpoint_completion_target | 0.5 | 0.9 | Smoother write performance |
Table Bloat and Vacuum
The agent monitors dead tuple ratios and recommends vacuum schedules:
- Tables with dead tuple ratio > 20% need immediate VACUUM
- Large tables (mail_message, ir_attachment, account_move_line) need regular maintenance
- Autovacuum settings adjusted for Odoo's write patterns
Connection Management
- Active connection count vs max_connections limit
- Idle connections consuming resources
- Connection pooling recommendations (PgBouncer setup)
- Long-running transaction detection
Lock Contention
The agent identifies lock issues common in Odoo:
- Deadlocks from concurrent cron jobs
- Long-running transactions holding locks on busy tables
- Advisory lock usage by Odoo workers
- Row-level lock contention on sequence tables
Automated Optimization Actions
With appropriate permissions, the agent can:
- Create missing indexes (after human approval)
- Run VACUUM ANALYZE on bloated tables
- Update PostgreSQL configuration parameters
- Kill long-running idle transactions
- Generate maintenance scripts for scheduled execution
Monitoring Dashboard
The agent tracks these metrics over time:
- Query performance trends (average response time)
- Cache hit ratio (should be > 99%)
- Transaction rate (commits/sec, rollbacks/sec)
- Disk I/O patterns (reads vs writes)
- Connection utilization
- Bloat growth rate
Common Issues and Fixes
| Symptom | Root Cause | Agent Fix |
|---|---|---|
| List views load slowly | Missing index on filter columns | CREATE INDEX on relevant columns |
| Reports take minutes | Sequential scans on large tables | Create composite index, ANALYZE table |
| Random slowdowns | Autovacuum competing with queries | Tune autovacuum settings |
| Connection refused errors | max_connections too low | Increase max_connections, add connection pooling |
| Gradual performance decline | Table bloat, stale statistics | VACUUM FULL on affected tables, ANALYZE all |
Getting Started
DeployMonkey's AI agent includes database optimization diagnostics. It monitors your PostgreSQL performance, identifies slow queries, recommends indexes, and suggests configuration changes — all accessible through natural language in the control panel. Deploy Odoo on DeployMonkey to get AI-powered database optimization included in every plan.