11/*-------------------------------------------------------------------------
22 *
33 *checkfiles.c
4- *support to clean up stale relation fileson crash recovery
4+ *check for stale relation filesduring crash recovery
55 *
66 *If a backend crashes while in a transaction that has created or
77 *deleted a relfilenode, a stale file can be left over in the data
1414 *files, and use the 'dirty' flag to determine if we should run this on
1515 *a clean startup.
1616 *
17- * $PostgreSQL: pgsql/src/backend/utils/init/checkfiles.c,v 1.1 2005/05/02 18:26:53 momjian Exp $
17+ * $PostgreSQL: pgsql/src/backend/utils/init/checkfiles.c,v 1.2 2005/05/05 22: 18:27 tgl Exp $
1818 *
1919 *-------------------------------------------------------------------------
2020 */
2121#include "postgres.h"
2222
23+ #include "access/heapam.h"
24+ #include "access/relscan.h"
25+ #include "access/skey.h"
26+ #include "catalog/catalog.h"
27+ #include "catalog/pg_tablespace.h"
28+ #include "miscadmin.h"
2329#include "storage/fd.h"
24-
2530#include "utils/flatfiles.h"
26- #include "miscadmin.h"
27- #include "catalog/pg_tablespace.h"
28- #include "catalog/catalog.h"
29- #include "access/skey.h"
3031#include "utils/fmgroids.h"
31- #include "access/relscan.h"
32- #include "access/heapam.h"
3332#include "utils/resowner.h"
3433
34+
3535static void CheckStaleRelFilesFrom (Oid tablespaceoid ,Oid dboid );
3636static void CheckStaleRelFilesFromTablespace (Oid tablespaceoid );
3737
@@ -52,11 +52,6 @@ AllocateDirChecked(char *path)
5252/*
5353 * Scan through all tablespaces for relations left over
5454 * by aborted transactions.
55- *
56- * For example, if a transaction issues
57- * BEGIN; CREATE TABLE foobar ();
58- * and then the backend crashes, the file is left in the
59- * tablespace until CheckStaleRelFiles deletes it.
6055 */
6156void
6257CheckStaleRelFiles (void )
@@ -125,31 +120,18 @@ CheckStaleRelFilesFrom(Oid tablespaceoid, Oid dboid)
125120struct dirent * de ;
126121HASHCTL hashctl ;
127122HTAB * relfilenodeHash ;
128- MemoryContext mcxt ;
129123RelFileNode rnode ;
130124char * path ;
131125
132- /*
133- * We create a private memory context so that we can easily deallocate the
134- * hash table and its contents
135- */
136- mcxt = AllocSetContextCreate (TopMemoryContext ,"CheckStaleRelFiles" ,
137- ALLOCSET_DEFAULT_MINSIZE ,
138- ALLOCSET_DEFAULT_INITSIZE ,
139- ALLOCSET_DEFAULT_MAXSIZE );
140-
141- hashctl .hash = tag_hash ;
142-
143126/*
144127 * The entry contents is not used for anything, we just check if an oid is
145128 * in the hash table or not.
146129 */
147130hashctl .keysize = sizeof (Oid );
148- hashctl .entrysize = 1 ;
149- hashctl .hcxt = mcxt ;
131+ hashctl .entrysize = sizeof ( Oid ) ;
132+ hashctl .hash = tag_hash ;
150133relfilenodeHash = hash_create ("relfilenodeHash" ,100 ,& hashctl ,
151- HASH_FUNCTION
152- |HASH_ELEM |HASH_CONTEXT );
134+ HASH_FUNCTION |HASH_ELEM );
153135
154136/* Read all relfilenodes from pg_class into the hash table */
155137{
@@ -209,10 +191,9 @@ CheckStaleRelFilesFrom(Oid tablespaceoid, Oid dboid)
209191rnode .relNode = relfilenode ;
210192
211193filepath = relpath (rnode );
212-
213194ereport (LOG ,
214195(errcode_for_file_access (),
215- errmsg ("The table or index file \"%s\" is stale and canbe safely removed" ,
196+ errmsg ("table or index file \"%s\" is stale and can safely be removed" ,
216197filepath )));
217198pfree (filepath );
218199}
@@ -221,5 +202,4 @@ CheckStaleRelFilesFrom(Oid tablespaceoid, Oid dboid)
221202FreeDir (dirdesc );
222203pfree (path );
223204hash_destroy (relfilenodeHash );
224- MemoryContextDelete (mcxt );
225205}