> ## Documentation Index
> Fetch the complete documentation index at: https://docs.domino.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Database Locking

> Database locks occur when queries or transactions conflict. Use the database-specific fix steps or Linux tools (ps, lsof, strace, fuser) to identify and resolve them.

Version/Environment (if relevant):
Applicable to all databases used within Domino deployments.

## Issue:

A database lock occurs when a query or transaction blocks or stalls due to a lock conflict. This may appear in code execution or log messages, for example:

Raw code

`sqlite3.OperationalError: database is locked`

## Root Cause:

Common causes of database locks include:

* Concurrent data access — multiple processes try to read and write the same data simultaneously, requiring the database to serialize access
* Long-running transactions — a transaction holds locks for an extended period, blocking other processes
* Resource contention — multiple processes compete for limited disk or memory resources
* Deadlocks — two or more processes each wait for the other to release a lock, creating a cycle that never resolves
* Hardware or software failures — locks persist beyond a failure even after the failure itself resolves

## Resolution:

MySQL

Error messages:

Raw code

`Deadlock found when trying to get lock
Lock wait timeout exceeded; try restarting transaction`

Fix steps:

1. Run `SHOW PROCESSLIST` to identify the process holding the lock.

Raw code

`SHOW PROCESSLIST;`

2. Terminate the blocking process using its process ID.

Raw code

`KILL <process_id>;`

3. If an open transaction is causing the lock, roll it back.

Raw code

`ROLLBACK;`

SQL Server

Error message:

Raw code

`Transaction (Process ID) was deadlocked on lock resources with another process
and was chosen as the victim of the deadlock. Restart the transaction.`

Fix steps:

1. Run `sp_who2` to identify the blocking process.

Raw code

`EXEC sp_who2;`

2. Terminate the blocking process using its process ID.

Raw code

`KILL <process_id>;`

3. If an open transaction is causing the lock, roll it back.

Raw code

`ROLLBACK;`

SQLite

Error message:

Raw code

`sqlite3.OperationalError: database is locked`

Fix steps:

1. Commit any open transaction.

Raw code

`conn.commit()`

2. Close the connection to release the lock.

Raw code

`conn.close()`

3. If multiple connections exist, close each one before reopening. Use the `sqlite3` module in Python to manage open connections.

Raw code

`# Example: close all connections before re-querying
for conn in open_connections:
conn.close()`

MongoDB

Error messages:

Raw code

`Error: couldn't execute operation: couldn't execute command.
CommandFailed: Transaction 12 is being rolled back - lock was not available`

Fix steps:

1. If a long-running operation holds the lock, wait for it to finish.
2. If the operation is stuck, terminate it using its operation ID.

Raw code

`db.killOp(<op_id>)`

3. As a last resort, restart the MongoDB server if a bug or system issue is causing the lock.

Linux tooling

Outside the database, use these Linux tools to identify signs of locking:

* ps — lists running processes and shows which processes hold locks
* lsof — lists all open files, including locked ones, and shows which process locks each file
* strace — traces system calls and signals for a process, helping identify the root cause of a lock
* fuser — shows which processes use a specific file or file system, including those holding locks

### Notes/Information:

* Design your schema and queries to minimize contention and reduce the need for locks.
* Experiment with different isolation levels to prevent transactions from conflicting with each other.
* Address locks promptly — persistent locks degrade database performance.

### References/Internal Records:

* Public KB Articles:
  * [Database Locking (KB-000001303)](https://support.domino.ai/support/s/article/Database-Locking-1718868034992)


## Related topics

- [Troubleshooting](/knowledge-base/troubleshooting-overview.md)
- [Persist data from Apps](/cloud/platform-capabilities/features/apps/persist-data-in-apps.md)
- [Vector databases](/cloud/platform-capabilities/core-concepts/data/data-source-connectors/vector-databases.md)
- [Connect to Oracle Database](/cloud/platform-capabilities/core-concepts/data/data-source-connectors/connect-to-oracle.md)
