michaelpq/pg_bulkload — pull request #1 by tvondra (2012-09-17 19:48:24+00:00)
Title: Unlocking of indexes locked in _bt_mergebuild in AccessExclusiveLock

When running pg_bulkload inside a transaction, it seems the indexes are not properly releases and are kept locked in AccessExclusiveLock mode till the end of the transaction (which may be quite a long time). This causes a lot of deadlocks in our case because of autovacuum (partly because we need to do an explicit LOCK at the end of the transaction).

I've found this lock is acquired in _bt_mergebuild and never releases - adding an UnlockRelation to IndexSpoolEnd seems to do the trick (no dangling locks since then), but I'm not sure this is really the right place so maybe this might cause corruption although I haven't seen anything like that.