8
8
*
9
9
*
10
10
* IDENTIFICATION
11
- * $Header: /cvsroot/pgsql/contrib/vacuumlo/vacuumlo.c,v 1.24 2003/08/08 21:41:25 momjian Exp $
11
+ * $Header: /cvsroot/pgsql/contrib/vacuumlo/vacuumlo.c,v 1.25 2003/09/24 05:38:38 tgl Exp $
12
12
*
13
13
*-------------------------------------------------------------------------
14
14
*/
@@ -98,10 +98,13 @@ vacuumlo(char *database, struct _param * param)
98
98
fprintf (stdout , "Test run: no large objects will be removed!\n" );
99
99
}
100
100
101
- res = PQexec (conn , "SET search_path = public" );
101
+ /*
102
+ * Don't get fooled by any non-system catalogs
103
+ */
104
+ res = PQexec (conn , "SET search_path = pg_catalog" );
102
105
if (PQresultStatus (res ) != PGRES_COMMAND_OK )
103
106
{
104
- fprintf (stderr , "Failed to set search_path on :\n" );
107
+ fprintf (stderr , "Failed to set search_path:\n" );
105
108
fprintf (stderr , "%s" , PQerrorMessage (conn ));
106
109
PQclear (res );
107
110
PQfinish (conn );
@@ -113,9 +116,8 @@ vacuumlo(char *database, struct _param * param)
113
116
* First we create and populate the LO temp table
114
117
*/
115
118
buf [0 ] = '\0' ;
116
- strcat (buf , "SELECT DISTINCT loid AS lo " );
117
- strcat (buf , "INTO TEMP TABLE vacuum_l " );
118
- strcat (buf , "FROM pg_largeobject " );
119
+ strcat (buf , "CREATE TEMP TABLE vacuum_l AS " );
120
+ strcat (buf , "SELECT DISTINCT loid AS lo FROM pg_largeobject " );
119
121
res = PQexec (conn , buf );
120
122
if (PQresultStatus (res ) != PGRES_COMMAND_OK )
121
123
{
@@ -132,7 +134,7 @@ vacuumlo(char *database, struct _param * param)
132
134
* for the DELETEs below.
133
135
*/
134
136
buf [0 ] = '\0' ;
135
- strcat (buf , "VACUUM ANALYZE vacuum_l " );
137
+ strcat (buf , "VACUUM ANALYZE vacuum_l" );
136
138
res = PQexec (conn , buf );
137
139
if (PQresultStatus (res ) != PGRES_COMMAND_OK )
138
140
{
@@ -145,7 +147,7 @@ vacuumlo(char *database, struct _param * param)
145
147
PQclear (res );
146
148
147
149
/*
148
- * Now find any candidate tables who have columns of type oid.
150
+ * Now find any candidate tables that have columns of type oid.
149
151
*
150
152
* NOTE: we ignore system tables and temp tables by the expedient of
151
153
* rejecting tables in schemas named 'pg_*'. In particular, the temp
@@ -157,9 +159,9 @@ vacuumlo(char *database, struct _param * param)
157
159
* shouldn't matter for correctness, but it saves time.
158
160
*/
159
161
buf [0 ] = '\0' ;
160
- strcat (buf , "SELECT c.relname, a.attname " );
162
+ strcat (buf , "SELECT s.nspname, c.relname, a.attname " );
161
163
strcat (buf , "FROM pg_class c, pg_attribute a, pg_namespace s, pg_type t " );
162
- strcat (buf , "WHERE a.attnum > 0 " );
164
+ strcat (buf , "WHERE a.attnum > 0 AND NOT a.attisdropped " );
163
165
strcat (buf , " AND a.attrelid = c.oid " );
164
166
strcat (buf , " AND a.atttypid = t.oid " );
165
167
strcat (buf , " AND c.relnamespace = s.oid " );
@@ -178,14 +180,16 @@ vacuumlo(char *database, struct _param * param)
178
180
179
181
for (i = 0 ; i < PQntuples (res ); i ++ )
180
182
{
181
- char * table ,
183
+ char * schema ,
184
+ * table ,
182
185
* field ;
183
186
184
- table = PQgetvalue (res , i , 0 );
185
- field = PQgetvalue (res , i , 1 );
187
+ schema = PQgetvalue (res , i , 0 );
188
+ table = PQgetvalue (res , i , 1 );
189
+ field = PQgetvalue (res , i , 2 );
186
190
187
191
if (param -> verbose )
188
- fprintf (stdout , "Checking %s in %s\n" , field , table );
192
+ fprintf (stdout , "Checking %s in %s.%s \n" , field , schema , table );
189
193
190
194
/*
191
195
* The "IN" construct used here was horribly inefficient before
@@ -194,13 +198,13 @@ vacuumlo(char *database, struct _param * param)
194
198
*/
195
199
snprintf (buf , BUFSIZE ,
196
200
"DELETE FROM vacuum_l "
197
- "WHERE lo IN (SELECT \"%s\" FROM \"%s\")" ,
198
- field , table );
201
+ "WHERE lo IN (SELECT \"%s\" FROM \"%s\".\"%s\" )" ,
202
+ field , schema , table );
199
203
res2 = PQexec (conn , buf );
200
204
if (PQresultStatus (res2 ) != PGRES_COMMAND_OK )
201
205
{
202
- fprintf (stderr , "Failed to check %s in table %s:\n" ,
203
- field , table );
206
+ fprintf (stderr , "Failed to check %s in table %s.%s :\n" ,
207
+ field , schema , table );
204
208
fprintf (stderr , "%s" , PQerrorMessage (conn ));
205
209
PQclear (res2 );
206
210
PQclear (res );
0 commit comments