Error code

PostgreSQL 40P01

POSTGRESQL40P01
Database Error Code· An error code returned by a database server such as PostgreSQL or MySQL.

What it means

deadlock_detected — two transactions are waiting on each other.

How to fix it

  1. Retry the rolled-back transaction after a short random delay.
  2. Ensure all transactions acquire locks on tables or rows in the same consistent order.
  3. Shorten transaction scope to hold locks for the minimum time necessary.

Not affiliated with PostgreSQL. Answer summarized from the manufacturer's manual linked above; consult that source for the authoritative procedure.