In order to find out what transactions are deadlocked in PostgreSQL, type the following command in psql or your favourite database management application:
SELECT pid, query, state, wait_event_type, wait_event
FROM pg_stat_activity;
If you know the pid(s) responsible for the deadlock, you can include it in the query as follows:
SELECT pid, query, state, wait_event_type, wait_event
FROM pg_stat_activity
WHERE pid IN (40, 500);