Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit77489f4

Browse files
committed
Update vacuumlo to be properly schema-aware. Improve documentation.
1 parent98bf004 commit77489f4

File tree

2 files changed

+31
-20
lines changed

2 files changed

+31
-20
lines changed

‎contrib/vacuumlo/README.vacuumlo

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
$Header: /cvsroot/pgsql/contrib/vacuumlo/Attic/README.vacuumlo,v 1.2 2000/11/21 17:54:21 tgl Exp $
1+
$Header: /cvsroot/pgsql/contrib/vacuumlo/Attic/README.vacuumlo,v 1.3 2003/08/04 22:03:39 tgl Exp $
22

33
This is a simple utility that will remove any orphaned large objects out of a
44
PostgreSQL database. An orphaned LO is considered to be any LO whose OID
@@ -14,19 +14,27 @@ Simply run make. A single executable "vacuumlo" is created.
1414
Usage
1515
-----
1616

17-
vacuumlo [-v] database [db2 ...dbn]
17+
vacuumlo [options] database [database2 ...databasen]
1818

19-
The -v flag outputs some progress messages to stdout.
19+
All databases named on the command line are processed. Available options
20+
include:
21+
22+
-v Write a lot of progress messages
23+
-n Don't remove large objects, just show what would be done
24+
-U username Username to connect as
25+
-W Prompt for password
26+
-h hostname Database server host
27+
-p port Database server port
2028

2129

2230
Method
2331
------
2432

25-
First, it builds a temporary table which contains all of theoid's of the
33+
First, it builds a temporary table which contains all of theOIDs of the
2634
large objects in that database.
2735

28-
It then scans through all columns in the database that are of type'oid',
29-
and removes any matching entries from the temporary table.
36+
It then scans through all columns in the database that are of type"oid"
37+
or "lo",and removes matching entries from the temporary table.
3038

3139
The remaining entries in the temp table identify orphaned LOs. These are
3240
removed.

‎contrib/vacuumlo/vacuumlo.c

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/contrib/vacuumlo/vacuumlo.c,v 1.21 2003/08/0402:39:56 momjian Exp $
11+
* $Header: /cvsroot/pgsql/contrib/vacuumlo/vacuumlo.c,v 1.22 2003/08/0422:03:39 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -256,8 +256,9 @@ vacuumlo(char *database, struct _param * param)
256256
/*
257257
* Now find any candidate tables who have columns of type oid.
258258
*
259-
* NOTE: the temp table formed above is ignored, because its real table
260-
* name will be pg_something. Also, pg_largeobject will be ignored.
259+
* NOTE: we ignore system tables and temp tables by the expedient of
260+
* rejecting tables in schemas named 'pg_*'. In particular, the temp
261+
* table formed above is ignored, and pg_largeobject will be too.
261262
* If either of these were scanned, obviously we'd end up with nothing
262263
* to delete...
263264
*
@@ -266,14 +267,14 @@ vacuumlo(char *database, struct _param * param)
266267
*/
267268
buf[0]='\0';
268269
strcat(buf,"SELECT c.relname, a.attname ");
269-
strcat(buf,"FROM pg_class c, pg_attribute a, pg_type t ");
270+
strcat(buf,"FROM pg_class c, pg_attribute a,pg_namespace s,pg_type t ");
270271
strcat(buf,"WHERE a.attnum > 0 ");
271272
strcat(buf," AND a.attrelid = c.oid ");
272273
strcat(buf," AND a.atttypid = t.oid ");
274+
strcat(buf," AND c.relnamespace = s.oid ");
273275
strcat(buf," AND t.typname in ('oid', 'lo') ");
274276
strcat(buf," AND c.relkind = 'r'");
275-
strcat(buf," AND c.relname NOT LIKE 'pg_%'");
276-
strcat(buf," AND c.relname != 'vacuum_l'");
277+
strcat(buf," AND s.nspname NOT LIKE 'pg\\\\_%'");
277278
res=PQexec(conn,buf);
278279
if (PQresultStatus(res)!=PGRES_TUPLES_OK)
279280
{
@@ -296,12 +297,14 @@ vacuumlo(char *database, struct _param * param)
296297
fprintf(stdout,"Checking %s in %s\n",field,table);
297298

298299
/*
299-
*We use a DELETE with implicit join for efficiency. This is a
300-
* Postgres-ism and not portable to other DBMSs, but then this
301-
*whole program is a Postgres-ism.
300+
*The "IN" construct used here was horribly inefficient before
301+
* Postgres 7.4, but should be now competitive if not better than
302+
*the bogus join we used before.
302303
*/
303-
snprintf(buf,BUFSIZE,"DELETE FROM vacuum_l WHERE lo = \"%s\".\"%s\" ",
304-
table,field);
304+
snprintf(buf,BUFSIZE,
305+
"DELETE FROM vacuum_l "
306+
"WHERE lo IN (SELECT \"%s\" FROM \"%s\")",
307+
field,table);
305308
res2=PQexec(conn,buf);
306309
if (PQresultStatus(res2)!=PGRES_COMMAND_OK)
307310
{
@@ -388,10 +391,10 @@ void
388391
usage(void)
389392
{
390393
fprintf(stdout,"vacuumlo removes unreferenced large objects from databases\n\n");
391-
fprintf(stdout,"Usage:\n vacuumlo [options] dbname [dbnames...]\n\n");
394+
fprintf(stdout,"Usage:\n vacuumlo [options] dbname [dbname...]\n\n");
392395
fprintf(stdout,"Options:\n");
393-
fprintf(stdout," -v\t\tWrite a lot ofoutput\n");
394-
fprintf(stdout," -n\t\tDon't removeanylargeobject, just show what would be done\n");
396+
fprintf(stdout," -v\t\tWrite a lot ofprogress messages\n");
397+
fprintf(stdout," -n\t\tDon't remove largeobjects, just show what would be done\n");
395398
fprintf(stdout," -U username\tUsername to connect as\n");
396399
fprintf(stdout," -W\t\tPrompt for password\n");
397400
fprintf(stdout," -h hostname\tDatabase server host\n");

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp