8
8
*
9
9
*
10
10
* 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 $
12
12
*
13
13
*-------------------------------------------------------------------------
14
14
*/
@@ -2156,10 +2156,11 @@ RelationBuildLocalRelation(const char *relname,
2156
2156
*
2157
2157
*This initializes the relation descriptor cache. At the time
2158
2158
*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.
2163
2164
*/
2164
2165
2165
2166
#define INITRELCACHESIZE 400
@@ -2188,10 +2189,38 @@ RelationCacheInitialize(void)
2188
2189
RelationIdCache = hash_create ("Relcache by OID" ,INITRELCACHESIZE ,
2189
2190
& ctl ,HASH_ELEM |HASH_FUNCTION );
2190
2191
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
+
2191
2215
/*
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.
2195
2224
*/
2196
2225
if (IsBootstrapProcessingMode ()||
2197
2226
!load_relcache_init_file ())
@@ -2209,23 +2238,8 @@ RelationCacheInitialize(void)
2209
2238
}
2210
2239
2211
2240
MemoryContextSwitchTo (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 ;
2228
2241
2242
+ /* In bootstrap mode, the faked-up formrdesc info is all we'll have */
2229
2243
if (IsBootstrapProcessingMode ())
2230
2244
return ;
2231
2245
@@ -2334,20 +2348,10 @@ RelationCacheInitializePhase2(void)
2334
2348
if (relation -> rd_rel -> reltriggers > 0 && relation -> trigdesc == NULL )
2335
2349
RelationBuildTriggers (relation );
2336
2350
}
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 ;
2350
2351
2352
+ /*
2353
+ * Lastly, write out a new relcache cache file if one is needed.
2354
+ */
2351
2355
if (needNewCacheFile )
2352
2356
{
2353
2357
/*