Hiroshi spotted the fundamental problem we were having:
RelationFlushRelation would happily flush a relation-cache
entry that still had an open file entry at the md.c and fd.c
levels. This resulted in a permanent leak of md and vfd
file descriptors, which was most easily observable as a leakage
of kernel file descriptors (though fd.c would eventually
recycle same). smgrclose() in RelationFlushRelation fixes it.
While I was poking at this I found a number of other problems
in md.c having to do with multiple-segment relations. I believe
they're all fixed now. I have been able to run initdb and the
regression tests with a 64Kb segment size, which never worked
before.
I stuck my neck out to the extent of committing these changes
into 6.5.* as well as current. I'd recommend a few more days
of beta-testing before we release 6.5.2 ;-). Marc, can you
make a new 6.5.2 candidate tarball?
regards, tom lane