The lock table is missing the unique index on className and key. This is wrong for at least two reasons.
1. We have a finder for lock that returns a Lock object by the className and the key but it doesn't have the unique flag in service.xml, so in case there were multiple rows in the database, this finder would blow up.
2. For PostgreSQL select for update doesn't seem to work under high concurrency situations, so it is possible to insert multiple rows into lock for the same className and key and so there is no way to use locking properly. By adding the unique index, there is an exception that can be caught and the lock acquisition can be retried.