In rebuild_relation(), don't access an already-closed relcache entry.
authorTom Lane
Sat, 4 Mar 2017 21:09:33 +0000 (16:09 -0500)
committerTom Lane
Sat, 4 Mar 2017 21:09:33 +0000 (16:09 -0500)
commit807df31d19e7014df1d3621292589d3653f614f2
tree5054824f30c945113d1078ae98338e8b00de9d3e
parent2cc16380a46d4c2103aa6caa6aaf0170863f8509
In rebuild_relation(), don't access an already-closed relcache entry.

This reliably fails with -DRELCACHE_FORCE_RELEASE, as reported by
Andrew Dunstan, and could sometimes fail in normal operation, resulting
in a wrong persistence value being used for the transient table.
It's not immediately clear to me what effects that might have beyond
the risk of a crash while accessing OldHeap->rd_rel->relpersistence,
but it's probably not good.

Bug introduced by commit f41872d0c, and made substantially worse by
commit 85b506bbf, which added a second such access significantly
later than the heap_close.  I doubt the first reference could fail
in a production scenario, but the second one definitely could.

Discussion: https://postgr.es/m/7b52f900-0579-cda9-ae2e-de5da17090e6@2ndQuadrant.com
src/backend/commands/cluster.c