Ensure unlogged tables are reset even if crash recovery errors out.
Ensure unlogged tables are reset even if crash recovery errors out.

Unlogged relations are reset at the end of crash recovery as they're
only synced to disk during a proper shutdown. Unfortunately that and
later steps can fail, e.g. due to running out of space. This reset
was, up to now performed after marking the database as having finished
crash recovery successfully. As out of space errors trigger a crash
restart that could lead to the situation that not all unlogged
relations are reset.

Once that happend usage of unlogged relations could yield errors like
"could not open file "...": No such file or directory". Luckily
clusters that show the problem can be fixed by performing a immediate
shutdown, and starting the database again.

To fix, just call ResetUnloggedRelations(UNLOGGED_RELATION_INIT)
earlier, before marking the database as having successfully recovered.

Discussion: 20140912112246.GA4984@alap3.anarazel.de

Backpatch to 9.1 where unlogged tables were introduced.

Abhijit Menon-Sen and Andres Freund

greenplum-db/gpdb,ashwinstar/gpdb,ashwinstar/gpdb,adam8157/gpdb,greenplum-db/gpdb,50wu/gpdb,greenplum-db/gpdb,xinzweb/gpdb,50wu/gpdb,50wu/gpdb,lisakowen/gpdb,lisakowen/gpdb,ashwinstar/gpdb,greenplum-db/gpdb,greenplum-db/gpdb,xinzweb/gpdb,xinzweb/gpdb,xinzweb/gpdb,xinzweb/gpdb,xinzweb/gpdb,jmcatamney/gpdb,lisakowen/gpdb,lisakowen/gpdb,adam8157/gpdb,jmcatamney/gpdb,50wu/gpdb,lisakowen/gpdb,lisakowen/gpdb,xinzweb/gpdb,50wu/gpdb,greenplum-db/gpdb,jmcatamney/gpdb,50wu/gpdb,ashwinstar/gpdb,ashwinstar/gpdb,jmcatamney/gpdb,greenplum-db/gpdb,jmcatamney/gpdb,greenplum-db/gpdb,jmcatamney/gpdb,ashwinstar/gpdb,jmcatamney/gpdb,ashwinstar/gpdb,lisakowen/gpdb,adam8157/gpdb,ashwinstar/gpdb,lisakowen/gpdb,50wu/gpdb,adam8157/gpdb,50wu/gpdb,xinzweb/gpdb,adam8157/gpdb,adam8157/gpdb,jmcatamney/gpdb,adam8157/gpdb,adam8157/gpdb