Database Errors
Troubleshoot PostgreSQL and database-related issues in OEC.sh. This guide covers connection problems, performance issues, migrations, and data recovery.
Connection Refused
Symptom
Odoo cannot connect to PostgreSQL with "connection refused" or "could not connect to server" errors.
Common Causes and Solutions
PostgreSQL Container Not Running
Symptom: Database container is stopped or crashed.
Solution:
- Check container status: Environment → Overview (look for database status)
- Restart the environment: Environment → ⋮ menu → Restart
- If issue persists, check server resources
Incorrect Connection Parameters
Symptom: "password authentication failed" or "role does not exist" error.
Solution:
- Verify database credentials in Environment → Settings → Environment Variables
- Ensure
DB_HOST,DB_PORT,DB_USER,DB_PASSWORD, andDB_NAMEare correct - Check that the database user has proper permissions
OEC.sh automatically configures database connections. If you're seeing connection errors after a fresh deployment, try restarting the environment first.
Network Issues
Symptom: Connection times out or intermittently fails.
Solution:
- Check server network status
- Verify firewall rules allow internal communication
- For cross-server setups, ensure proper network connectivity
Performance Issues
Symptom
Database queries are slow, Odoo is unresponsive, or you see "lock wait timeout" errors.
Common Causes and Solutions
High Memory Usage
Symptom: PostgreSQL consuming excessive memory, causing slowdowns.
Solution:
- Check database memory usage: Server → Metrics
- Enable PgBouncer connection pooling (Pro/Agency plans)
- Increase RAM allocation for the environment
Monitor PostgreSQL memory in real-time:
- Go to Server → Metrics
- Look for "PostgreSQL Memory" graph
- If consistently above 80%, scale up resources
Missing Indexes
Symptom: Specific queries are very slow.
Solution:
- Access terminal: Environment → Terminal
- Analyze slow queries using
EXPLAIN ANALYZE - Add indexes for frequently queried columns
-- Example: Add index for partner name searches
CREATE INDEX idx_res_partner_name ON res_partner(name);Long-Running Transactions
Symptom: "lock wait timeout exceeded" or transactions stuck.
Solution:
- Identify blocked transactions via terminal
- Kill long-running queries if necessary
- Review application code for transaction issues
-- Find blocked queries
SELECT pid, now() - pg_stat_activity.query_start AS duration, query, state
FROM pg_stat_activity
WHERE (now() - pg_stat_activity.query_start) > interval '5 minutes';
-- Terminate a stuck query (use with caution)
SELECT pg_terminate_backend(pid);Only terminate queries if you understand the impact. Killing active transactions can leave data in an inconsistent state.
Migration Failures
Symptom
Odoo module upgrades fail during database migration.
Common Causes and Solutions
Schema Conflicts
Symptom: "relation already exists" or "column already exists" error.
Solution:
- Check if a previous migration partially completed
- Review the migration script for issues
- Manually fix the schema if needed (use terminal access)
Data Type Mismatch
Symptom: "cannot cast" or "invalid input syntax" error.
Solution:
- Identify the problematic column/data
- Clean or transform data before migration
- Update migration script to handle edge cases
Backup First
Always create a backup before attempting fixes: Environment → Backups → Create Backup
Access Terminal
Go to Environment → Terminal for direct database access
Check Current State
-- Check table structure
\d table_name
-- Check data causing issues
SELECT * FROM table_name WHERE column_name IS NOT NULL LIMIT 10;Apply Fix
Fix data or schema as needed, then retry the migration
Odoo Version Upgrade Issues
Symptom: Major version upgrade fails (e.g., 16.0 to 17.0).
Solution:
- Use the Clone with Sanitization feature to create a test copy
- Run the upgrade on the clone first
- Review and fix any module compatibility issues
- Upgrade the production environment after successful testing
Major Odoo version upgrades often require module updates. Check that all your custom and third-party modules support the target version.
Database Corruption
Symptom
Data appears corrupted, queries return unexpected results, or PostgreSQL reports corruption errors.
Common Causes and Solutions
Disk Full During Write
Symptom: Corruption after disk space ran out.
Solution:
- Free up disk space immediately
- Stop all services
- Run PostgreSQL recovery or restore from backup
Hardware Failure
Symptom: Sudden corruption without obvious cause.
Solution:
- Restore from the most recent backup
- Consider migrating to a different server
- Contact support for assistance
Recovery Steps
Stop the Environment
Prevent further writes that could worsen corruption.
Assess Damage
If you have terminal access:
-- Check for corruption
SELECT pg_catalog.pg_database_size(datname) FROM pg_database;Attempt Recovery
PostgreSQL has built-in recovery mechanisms:
pg_resetwal -f /var/lib/postgresql/data # Last resort, may lose dataRestore from Backup
If recovery fails, restore from your most recent backup:
- Go to Environment → Backups
- Select a backup before the corruption
- Click Restore
Important: Regular backups are your best protection against data loss. OEC.sh automatically backs up to your configured storage providers.
Read Replica Issues
Available on Pro and Agency plans for Odoo 18.0+
Replica Lag
Symptom: Read replica shows outdated data.
Solution:
- Check replica status: Environment → Database → Replica Health
- Monitor lag metrics (bytes and seconds behind primary)
- If lag persists, consider rebuilding the replica
Replica Offline
Symptom: Replica shows "offline" or "error" status.
Solution:
- Check the replica error message in the dashboard
- Verify network connectivity between primary and replica
- Rebuild replica if needed: Environment → Database → Rebuild Replica
Prevention Tips
- Enable Automated Backups - Configure daily backups to multiple storage providers
- Monitor Disk Usage - Set up alerts before running out of space
- Use Connection Pooling - Enable PgBouncer for better resource management
- Test Upgrades - Always test major changes on a clone first
- Review Queries - Optimize slow queries before they cause problems
Still Having Issues?
If the above solutions don't resolve your problem:
-
Collect Information:
- Environment ID
- Error messages from logs
- Recent changes made
- Database version and size
-
Contact Support: Email support@oec.sh