I found the root cause of the bug I reported at:
http://archives.postgresql.org/pgsql-bugs/2006-10/msg00211.php
What happens is this:
* Out of memory condition causes an ERROR
* ERROR triggers an AbortTransaction()
* AbortTransaction() calls RecordTransactionAbort()
* RecordTransactionAbort calls smgrGetPendingDeletes()
* smgrGetPendingDeletes() calls palloc()
* palloc() fails, resulting in ERROR, causing infinite recursion
* elog.c detects infinite recursion, and elevates it to PANIC
I'm not sure how easy this is to fix, but I asked on IRC and got some
agreement that this is a bug.
It seems to me, in order to fix it, we would have to avoid allocating
memory on the AbortTransaction path. All smgrGetPendingDeletes() needs
to allocate is a few dozen bytes (depending on the number of relations
to be deleted). Perhaps it could allocate those bytes as list of pending
deletes fills up. Or maybe we can somehow avoid needing to record the
relnodes to be deleted in order for the abort to succeed.
I'm still not sure why foreign keys on large insert statements don't eat
memory on 7.4, but do on 8.0+.
Regards,
Jeff Davis