I am trying a pre-load a user table during InitPostgres. I tried to mimic
the relevant actions in ReverifyDatabase to carry this out. I manage to
load the first block of the table. However, if a table is more than 1
block, I end up getting warnings about relcache reference leaks. It looks
like I need to increase the size of the relcache. Can anyone comment on
the approach and/or give me any advanced warnings about messing with the
relcache?
Thanks!
Code follows:
/*** APC 4/1/04* */static void
PreLoadUserTable(Oid relationId)
{Relation pgdbrel;HeapScanDesc pgtblscan;HeapTuple tup;int i;fprintf(stdout, "APC: PreLoadTable for
relation(%d).\n", relationId);
// pgdbrel = heap_open(relationId, AccessShareLock);
/* APC numKeys seems to be 0 for user tables *//* pgdbscan = heap_beginscan(pgdbrel, SnapshotNow, 1, &key);
*/pgtblscan= heap_beginscan(pgdbrel, SnapshotNow, 0, NULL);
fprintf(stdout, "APC: the number of blocks (%d)\n", pgtblscan->rs_rd->rd_nblocks);/* XXX how to really load all the
blocks,this approach is wrong */for (i=0; i<=i<pgtblscan->rs_rd->rd_nblocks; i++) { fprintf(stdout, "APC: the number
ofblocks (%d) for round(%d)\n", pgtblscan->rs_rd->rd_nblocks, i); tup = heap_getnext(pgtblscan,
ForwardScanDirection); if (!HeapTupleIsValid(tup)) { /* OOPS */ heap_close(pgdbrel,
AccessShareLock);
/* ereport.... */ fprintf(stderr, "APC: FATAL ERROR unable to load the table during
round(%d).\n",i); }}heap_endscan(pgtblscan);heap_close(pgdbrel, AccessShareLock);
fprintf(stdout, "APC: PreLoadTable finished for relation(%d).\n", relationId);
}