pre-loading a user table.

From: Ana Cerejo <ana(dot)cerejo(at)yale(dot)edu>
To: pgsql-hackers(at)postgresql(dot)org
Subject: pre-loading a user table.
Date: 2004-04-01 20:10:05
Message-ID: Pine.LNX.4.44.0404011459001.28104-100000@ares.its.yale.edu
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

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);

}

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Jim Seymour 2004-04-01 21:50:58 Problems Vacuum'ing
Previous Message Chris Browne 2004-04-01 19:42:05 Re: Update on PITR