Add RelationOpenSmgr() calls to ensure rd_smgr is valid when we try to
authorTom Lane <[email protected]>
Sat, 7 Jan 2006 22:46:07 +0000 (22:46 +0000)
committerTom Lane <[email protected]>
Sat, 7 Jan 2006 22:46:07 +0000 (22:46 +0000)
use it.  While it normally has been opened earlier during btree index
build, testing shows that it's possible for the link to be closed again
if an sinval reset occurs while the index is being built.

src/backend/access/nbtree/nbtsort.c

index 447bd6e120ac440dabd2cb67aa6fab76918be7f8..d7b10de9fd5ce5147c8678b6c04356a29a9202b7 100644 (file)
@@ -273,6 +273,9 @@ _bt_blnewpage(uint32 level)
 static void
 _bt_blwritepage(BTWriteState *wstate, Page page, BlockNumber blkno)
 {
+       /* Ensure rd_smgr is open (could have been closed by relcache flush!) */
+       RelationOpenSmgr(wstate->index);
+
        /* XLOG stuff */
        if (wstate->btws_use_wal)
        {
@@ -817,5 +820,8 @@ _bt_load(BTWriteState *wstate, BTSpool *btspool, BTSpool *btspool2)
         * disk when the crash occurs.
         */
        if (!wstate->index->rd_istemp)
+       {
+               RelationOpenSmgr(wstate->index);
                smgrimmedsync(wstate->index->rd_smgr);
+       }
 }