Problem confirmation

You may have a file lock in your NextCloud database if you see a 423 Locked error in your Nextcloud Client activity log

Furthermore, you may see the Nextcloud synchronisation status icon that overlays synchronised folders and files may be orange, denoting a problem.

To resolve, follow these steps:

Stop Nextcloud services

Close your desktop Nextcloud client(s).

Stop your Nextcloud server process.
If running Nextcloud in Docker then stop the container. At the shell prompt this will something like docker stop nextcloud, or perhaps use Portainer instead.
Else, stop your web server with systemctl stop httpd or systemctl stop nginx.

Backup the locked database

Using a tool like WinSCP, backup your Nextcloud database by right-clicking the SQLite database file and duplicating it, naming it something you will remember.

In a docker container, you will find the Nextcloud SQLite database file at /yourdockervolume/data/nextcloud01.db
In a regular install on a Debian-derived system,  you might find it at: /var/www/html/nextcloud/data/nextcloud01.db
RedHat-derived systems often locate html at:
/var/www/nextcloud/data/nextcloud01.db
Omitting the html.

Then, still using WinSCP, copy the Nextcloud SQLite database file to a temporary location on your desktop computer.

Clear the database locks

Using free database management tool DBeaver, open the local copy of the Nextcloud SQLite database file by doing Database menu | New database connection.

Choose SQLite in the database type selector box, and specify the path to your Nextcloud SQLite database file when prompted. When accepted, a SQLite node will appear in the DB Navigator pane on the left hand side.

Right-click the Nextcloud database node in the DB Navigator pane and select SQL Editor. A SQL Tab will appear to the right. In the SQL pane, paste the following SQL code snippet:

DELETE FROM oc_file_locks WHERE 1;

Run the SQL code by clicking the orange arrow symbol at the left of the code window. The code will run and remove locks from the database.

Disconnect the Nextcloud SQLite database file by right-clicking the SQLite node in DB Navigator and select Disconnect DB.

Move the fixed database back

Using WinSCP, delete the original database on your Nextcloud server (remembering to have made a backup). Then, copy the fixed database back to the original location on your Nextcloud server.

On your server console, reapply appropriate file ownership to the fixed database file. The easiest way to accomplish this to reapply permissions to the entire Nextcloud folder. If you're running Nextcloud in a container, run:
chown www-data -R /path/to/nextcloud/docker/volume
Or if running natively (on a Debian-derived system):
chown www-data -R /var/www/html/nextcloud/

Restart services and recover

Restart your Nextcloud service by restarting your container or webserver. Observe logs to confirm it restarts without error.

Restart your desktop Nextcloud Client(s). If the lock does not appear to clear then edit and resave affected files to trigger a resync, or copy affected files to a new filename and delete the original. The new or changed file should synchronise correctly without locking.

If the orange file synchronisation badge persists in Explorer after the fix, restart the Nextcloud Client to clear it.

After a day or two, remember to remove your backup of the broken Nextcloud database from your server.