Another thing I learnt about PostgreSQL: notifications sent within a transaction will only be dispatch to listeners until and unless the transaction is committed. So inserting rows in one transaction, and notifying something which will consume those rows in another should not result in a deadlock.