88 *
99 *
1010 * IDENTIFICATION
11- * $PostgreSQL: pgsql/src/backend/utils/cache/relcache.c,v 1.239 2006/04/25 22:46:05 tgl Exp $
11+ * $PostgreSQL: pgsql/src/backend/utils/cache/relcache.c,v 1.240 2006/05/04 18:51:35 tgl Exp $
1212 *
1313 *-------------------------------------------------------------------------
1414 */
@@ -2156,10 +2156,11 @@ RelationBuildLocalRelation(const char *relname,
21562156 *
21572157 *This initializes the relation descriptor cache. At the time
21582158 *that this is invoked, we can't do database access yet (mainly
2159- *because the transaction subsystem is not up), so we can't get
2160- *"real" info. However it's okay to read the pg_internal.init
2161- *cache file, if one is available. Otherwise we make phony
2162- *entries for the minimum set of nailed-in-cache relations.
2159+ *because the transaction subsystem is not up); all we are doing
2160+ *is making an empty cache hashtable. This must be done before
2161+ *starting the initialization transaction, because otherwise
2162+ *AtEOXact_RelationCache would crash if that transaction aborts
2163+ *before we can get the relcache set up.
21632164 */
21642165
21652166#define INITRELCACHESIZE 400
@@ -2188,10 +2189,38 @@ RelationCacheInitialize(void)
21882189RelationIdCache = hash_create ("Relcache by OID" ,INITRELCACHESIZE ,
21892190& ctl ,HASH_ELEM |HASH_FUNCTION );
21902191
2192+ MemoryContextSwitchTo (oldcxt );
2193+ }
2194+
2195+ /*
2196+ *RelationCacheInitializePhase2
2197+ *
2198+ *This is called as soon as the catcache and transaction system
2199+ *are functional. At this point we can actually read data from
2200+ *the system catalogs. We first try to read pre-computed relcache
2201+ *entries from the pg_internal.init file. If that's missing or
2202+ *broken, make phony entries for the minimum set of nailed-in-cache
2203+ *relations. Then (unless bootstrapping) make sure we have entries
2204+ *for the critical system indexes. Once we've done all this, we
2205+ *have enough infrastructure to open any system catalog or use any
2206+ *catcache. The last step is to rewrite pg_internal.init if needed.
2207+ */
2208+ void
2209+ RelationCacheInitializePhase2 (void )
2210+ {
2211+ HASH_SEQ_STATUS status ;
2212+ RelIdCacheEnt * idhentry ;
2213+ MemoryContext oldcxt ;
2214+
21912215/*
2192- * Try to load the relcache cache file. If successful, we're done for
2193- * now. Otherwise, initialize the cache with pre-made descriptors for the
2194- * critical "nailed-in" system catalogs.
2216+ * switch to cache memory context
2217+ */
2218+ oldcxt = MemoryContextSwitchTo (CacheMemoryContext );
2219+
2220+ /*
2221+ * Try to load the relcache cache file. If unsuccessful, bootstrap the
2222+ * cache with pre-made descriptors for the critical "nailed-in" system
2223+ * catalogs.
21952224 */
21962225if (IsBootstrapProcessingMode ()||
21972226!load_relcache_init_file ())
@@ -2209,23 +2238,8 @@ RelationCacheInitialize(void)
22092238}
22102239
22112240MemoryContextSwitchTo (oldcxt );
2212- }
2213-
2214- /*
2215- *RelationCacheInitializePhase2
2216- *
2217- *This is called as soon as the catcache and transaction system
2218- *are functional. At this point we can actually read data from
2219- *the system catalogs. Update the relcache entries made during
2220- *RelationCacheInitialize, and make sure we have entries for the
2221- *critical system indexes.
2222- */
2223- void
2224- RelationCacheInitializePhase2 (void )
2225- {
2226- HASH_SEQ_STATUS status ;
2227- RelIdCacheEnt * idhentry ;
22282241
2242+ /* In bootstrap mode, the faked-up formrdesc info is all we'll have */
22292243if (IsBootstrapProcessingMode ())
22302244return ;
22312245
@@ -2334,20 +2348,10 @@ RelationCacheInitializePhase2(void)
23342348if (relation -> rd_rel -> reltriggers > 0 && relation -> trigdesc == NULL )
23352349RelationBuildTriggers (relation );
23362350}
2337- }
2338-
2339- /*
2340- *RelationCacheInitializePhase3
2341- *
2342- *Final step of relcache initialization: write out a new relcache
2343- *cache file if one is needed.
2344- */
2345- void
2346- RelationCacheInitializePhase3 (void )
2347- {
2348- if (IsBootstrapProcessingMode ())
2349- return ;
23502351
2352+ /*
2353+ * Lastly, write out a new relcache cache file if one is needed.
2354+ */
23512355if (needNewCacheFile )
23522356{
23532357/*