

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 of blocks (%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);

} 


Thu, 1 Apr 2004 15:10:05 -0500 (EST)
Ana Cerejo <ana.cerejo@yale.edu>
pre-loading a user table.
Ana Cerejo <ana.cerejo@yale.edu> writes:
> 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?

You've broken something and you haven't got the foggiest idea what :-(
... but "increasing the size of the relcache" definitely isn't the
solution, because it isn't fixed-size.

Why do you think it useful to preload something during InitPostgres,
anyway?  Any heavily used table will certainly be present in shared
buffers already, and even more surely present in kernel buffers.

			regards, tom lane

Fri, 02 Apr 2004 01:17:10 -0500
Tom Lane <tgl@sss.pgh.pa.us>
Re: pre-loading a user table. 