When an Odoo operation keeps loading, record updates stop completing, or multiple users experience delays, a blocked database transaction may be responsible. The underlying issue can be difficult to identify because database locks, slow SQL queries, long-running transactions, and application-worker constraints can produce similar symptoms.
The key is to identify which transaction is waiting, which transaction is blocking it, and what the blocking operation is doing. Without that evidence, changing database settings or restarting services may fail to address the actual cause.
This guide explains how to diagnose blocked transactions, investigate the responsible SQL operations or Odoo workflows, trace potential problems in custom code, and verify the fix safely in a production environment.
Recognise the Symptoms of Odoo Database Locks
PostgreSQL uses database locks to coordinate concurrent transactions and maintain data consistency. Problems occur when a transaction holds a conflicting lock long enough to prevent other operations from progressing.
The following symptoms can indicate where to investigate, but none confirms a database-lock problem on its own.
| Observed symptom | Possible cause | What to investigate |
| An Odoo operation keeps loading | A query is waiting for a lock or executing slowly | Active database sessions and application logs |
| Several users experience delays simultaneously | Concurrent transactions may be competing for shared resources | Blocked sessions and active transactions |
| A record update takes too long | Another transaction may hold a conflicting lock | The affected operation and blocking transaction |
| An operation fails after waiting | A lock timeout, statement timeout, or another error may have occurred | Database errors and transaction logs |
| Performance deteriorates during bulk processing | Large transactions or expensive queries may contribute to contention | Transaction duration, query execution, and workload size |
Determine the scope of the problem. If one operation consistently causes delays, investigate its database queries and the Odoo workflow responsible. If unrelated operations become blocked simultaneously, look for a shared transaction or database resource that could explain the wider impact.
For example, a large update may hold locks on records that other transactions need to modify. Those transactions must wait until the conflicting locks are released or the transaction ends.
Important: A slow Odoo screen does not prove that database locking is responsible. Confirm whether a transaction is actually blocked before changing database settings or application code.
Understand Why Database Locks Occur
Odoo uses PostgreSQL transactions to manage database changes. When concurrent operations require conflicting locks, one transaction may have to wait for another to finish.
To diagnose the problem, identify which transaction is blocking other operations and why it is taking longer than expected.
Long-running transactions
Transactions that remain open longer than necessary can retain locks and delay other operations. Common causes include:
- Processing large numbers of records in one transaction.
- Running expensive database operations or custom code.
- Waiting for an external service while a transaction remains open.
- Performing multiple database operations before completing the transaction.
A long-running transaction is not automatically a problem. Check whether it is holding locks that other sessions need.
Concurrent updates
When multiple users, automated jobs, or custom workflows modify overlapping records, their operations may require conflicting locks. One transaction may then wait until the other releases its locks.
Check whether the delays coincide with simultaneous updates, bulk processing, or automated jobs.
Slow queries versus blocked queries
These problems can produce similar symptoms but require different investigations.
- Slow query: The database is executing an operation that takes longer than expected.
- Blocked query: The operation is waiting for another transaction to release a conflicting lock.
Both can occur together. Check database activity to determine whether the delay comes from query execution, lock contention, or both.
Custom code and transaction handling
Custom modules may increase lock contention when they perform unnecessary updates, process large record sets in one transaction, or keep transactions open during lengthy operations.
Inspect the relevant database activity and application code before attributing the problem to a customization.
Distinguish Database Locks from Other Performance Problems
Slow Odoo operations do not always indicate database-lock contention. Before changing PostgreSQL settings, determine whether the delay comes from a blocked transaction or another performance issue.
- Database lock contention: A transaction waits for another transaction to release a conflicting lock.
- Slow SQL queries: A query takes too long to execute. Investigate its execution time and query plan.
- Resource constraints: High CPU or memory usage can slow application and database operations.
- Application-worker constraints: Requests may wait when available workers are busy.
- Network or external-service delays: An operation may be waiting for another system to respond.
These problems can overlap. For example, a slow query may hold locks longer than necessary, causing other transactions to wait.
Start with the affected Odoo operation. Compare its timing with PostgreSQL activity and application logs. If a blocking relationship exists, investigate the transactions involved. Otherwise, examine query performance, worker availability, or infrastructure.
Do not change database settings until you have identified the likely cause.
Diagnose Blocked Transactions in PostgreSQL

When database locking is suspected, identify the transaction waiting for a lock and the transaction blocking it. PostgreSQL’s pg_stat_activity, pg_locks, and pg_blocking_pids() provide information that helps investigate current database activity.
Step 1: Identify blocked and blocking sessions
Use the following query to inspect current blocking relationships:
SELECT
blocked.pid AS blocked_pid,
blocked.application_name AS blocked_application,
blocked.wait_event_type,
blocked.wait_event,
now() – blocked.query_start AS blocked_query_duration,
blocked.query AS blocked_query,
blocker.pid AS blocking_pid,
blocker.application_name AS blocking_application,
now() – blocker.xact_start AS blocking_transaction_duration,
blocker.state AS blocking_session_state,
blocker.query AS blocking_query
FROM pg_stat_activity AS blocked
JOIN LATERAL unnest(
pg_blocking_pids(blocked.pid)
) AS blocking_pid(pid) ON true
JOIN pg_stat_activity AS blocker
ON blocker.pid = blocking_pid.pid
ORDER BY blocked.query_start;
The query returns sessions with identified blockers. Review the results to determine:
- Which session is waiting and which session is blocking it.
- How long the relevant query or transaction has been active.
- What SQL statement is associated with each session.
- Whether the blocking session is active or idle.
Note: This query examines current blocking relationships, not historical incidents. Test it in your PostgreSQL environment before using it operationally. SQL text may contain sensitive business information, so restrict access to diagnostic output.
Step 2: Investigate the blocking transaction
Examine the blocking session’s activity and transaction state. Look for large updates, expensive queries, bulk-processing operations, or an open transaction that retains locks while idle.
An idle session is not automatically responsible for a problem. Confirm its transaction state and blocking relationship before taking action.
Step 3: Correlate the database activity with Odoo
A PostgreSQL process ID or SQL statement may not identify the complete Odoo workflow responsible for the transaction.
Compare the incident timestamp with Odoo application logs. Look for the affected operation, timeout errors, bulk-processing jobs, recent code deployments, and custom methods associated with the affected records.
This helps connect the database-level blocking relationship to the application behaviour that initiated it.
Do not terminate a transaction or restart services simply because a session appears long-running. First establish what it is doing, which operations depend on it, and what business impact a corrective action could have.
Trace the Lock to an Odoo Operation
Identifying a blocking PostgreSQL session is only the first step. Next, determine which Odoo workflow initiated the transaction and why it is holding locks longer than necessary.
Inspect the relevant operation for:
- Bulk processing: Imports, reconciliations, or large updates that process many records in one transaction.
- Custom methods: Repeated database writes, inefficient loops, or expensive queries.
- External integrations: Remote requests that delay transaction completion.
- Recent changes: Deployments or modifications that coincide with the start of the problem.

Correlate PostgreSQL activity with Odoo logs and the affected workflow before attributing the issue to a specific cause.
Where a transaction remains open unnecessarily, a developer may need to optimise the database operations, redesign the processing workflow, or introduce appropriate batching. Changes must preserve transaction consistency and business correctness.
Do not assume that custom code or a recent deployment is responsible without supporting evidence. Confirm the cause before modifying the implementation.
Resolve the Underlying Cause Safely
The appropriate correction depends on what is causing the blocking transaction. Do not terminate database sessions or change configuration without understanding the operational consequences.
Optimise long-running transactions
Determine why the transaction has not completed. If it is performing legitimate business processing, interrupting it may cause errors or require recovery work. Investigate its purpose and application context before intervening.
Correct inefficient queries or custom code
Depending on the evidence, corrective actions may include:
- Removing unnecessary database writes.
- Improving expensive queries and evaluating indexing needs.
- Processing large workloads in suitable batches.
- Avoiding unnecessarily long transactions.
- Handling external-service delays without holding database transactions open unnecessarily.
Test code and database changes in a suitable non-production environment before deployment. If the issue involves custom workflows, transaction handling, or interactions between Odoo modules, review the wider Odoo ERP implementation services to understand how implementation and customisation decisions can affect system behaviour.
Terminate a session only when justified
Terminating a database session is an operational intervention, not a default solution. Confirm the session’s purpose, business impact, and recovery implications, and follow the appropriate production incident procedures.
Cancelling a query and terminating a session are different actions. Both can interrupt work, and rolling back a transaction may take additional time.
After an intervention, verify that the blocking condition has cleared and that affected business records and dependent operations remain consistent.
The objective is to correct the underlying cause, not merely remove the waiting request.
Verify the Correction and Prevent Recurrence
Clearing a blocked transaction does not necessarily resolve the underlying problem. Verify both PostgreSQL activity and the affected Odoo workflow before closing the incident.
Confirm the database is functioning normally
Check whether:
- The previously blocked operations complete successfully.
- The blocking relationship no longer appears.
- Similar transactions finish within an appropriate period.
- Comparable workloads trigger the same problem again.
Compare these results with the original incident rather than relying on one successful request.
Verify the affected Odoo workflow
Repeat the business operation that originally failed or became delayed. Confirm that records were updated correctly and dependent operations completed. For accounting, inventory, or other critical workflows, verify the resulting business data before considering the incident resolved.
Prevent recurrence
Choose preventive measures based on the confirmed cause:
- Long-running transactions: Review workload size, transaction duration, and batching.
- Inefficient SQL: Examine query execution and optimise where evidence supports it.
- Conflicting updates: Review transaction ordering and concurrent processing.
- Custom-code problems: Improve transaction handling and test under realistic workloads.
- External-service delays: Review timeouts and avoid unnecessarily long transactions.
- Insufficient monitoring: Improve visibility into relevant database activity and application errors.
There is no universal configuration change that prevents every database-lock problem. Prevention depends on the transaction patterns, workload, and implementation responsible for the incident.
Frequently Asked Questions
Odoo database locks occur when concurrent PostgreSQL transactions require conflicting locks. Long-running transactions, bulk processing, and simultaneous updates can cause operations to wait.
Use PostgreSQL’s pg_stat_activity view and pg_blocking_pids() function to identify blocked sessions and their blockers. Check Odoo logs to trace the issue to the affected business operation.
No, not without investigation. Identify the blocking transaction and assess its business impact first. Termination can interrupt legitimate processing or trigger a rollback.
Conclusion
Odoo database locks can delay business operations when transactions compete for conflicting database resources. Diagnose the blocking relationship, identify the responsible transaction, and trace it to the relevant Odoo workflow or database operation.
Use PostgreSQL activity and application logs to distinguish lock contention from slow queries or infrastructure problems. After applying a correction, verify that both database activity and the affected business workflow function correctly.
If the issue involves complex customisations or transaction handling, Odoo ERP implementation expertise may help identify the underlying cause and prevent recurrence.
