vacuumlo.patch
application/octet-stream
diff --git a/contrib/vacuumlo/vacuumlo.c b/contrib/vacuumlo/vacuumlo.c
index f6e2a28..b9ef1ca 100644
--- a/contrib/vacuumlo/vacuumlo.c
+++ b/contrib/vacuumlo/vacuumlo.c
@@ -23,6 +23,7 @@
#include "libpq-fe.h"
#include "libpq/libpq-fs.h"
+#include <limits.h>
#define atooid(x) ((Oid) strtoul((x), NULL, 10))
@@ -48,6 +49,7 @@ struct _param
char *pg_host;
int verbose;
int dry_run;
+ int transaction_limit;
};
int vacuumlo(char *, struct _param *);
@@ -286,6 +288,8 @@ vacuumlo(char *database, struct _param * param)
}
else
deleted++;
+ if (param->transaction_limit != 0 && deleted >= param->transaction_limit)
+ break;
}
PQclear(res);
@@ -311,6 +315,7 @@ usage(const char *progname)
printf("Usage:\n %s [OPTION]... DBNAME...\n\n", progname);
printf("Options:\n");
printf(" -h HOSTNAME database server host or socket directory\n");
+ printf(" -l LIMIT stop after removing LIMIT large objects\n");
printf(" -n don't remove large objects, just show what would be done\n");
printf(" -p PORT database server port\n");
printf(" -U USERNAME user name to connect as\n");
@@ -342,6 +347,7 @@ main(int argc, char **argv)
param.pg_port = NULL;
param.verbose = 0;
param.dry_run = 0;
+ param.transaction_limit = 0;
if (argc > 1)
{
@@ -359,7 +365,7 @@ main(int argc, char **argv)
while (1)
{
- c = getopt(argc, argv, "h:U:p:vnwW");
+ c = getopt(argc, argv, "h:l:U:p:vnwW");
if (c == -1)
break;
@@ -395,6 +401,14 @@ main(int argc, char **argv)
}
param.pg_port = strdup(optarg);
break;
+ case 'l':
+ param.transaction_limit = strtol(optarg, NULL, 10);
+ if ((param.transaction_limit < 0) || (param.transaction_limit > INT_MAX))
+ {
+ fprintf(stderr, "%s: invalid transaction limit number: %s, valid range is form 0(disabled) to INT_MAX(%i).\n", progname, optarg, INT_MAX);
+ exit(1);
+ }
+ break;
case 'h':
param.pg_host = strdup(optarg);
break;
diff --git a/doc/src/sgml/vacuumlo.sgml b/doc/src/sgml/vacuumlo.sgml
index 471a6ca..1a1ee98 100644
--- a/doc/src/sgml/vacuumlo.sgml
+++ b/doc/src/sgml/vacuumlo.sgml
@@ -57,6 +57,13 @@ vacuumlo [options] database [database2 ... databaseN]
</varlistentry>
<varlistentry>
+ <term><option>-l</option> <replaceable>limit</></term>
+ <listitem>
+ <para>Stop after removing LIMIT large objects. Useful to avoid exceeding max_locks_per_transaction.</para>
+ </listitem>
+ </varlistentry>
+
+ <varlistentry>
<term><option>-w</></term>
<term><option>--no-password</></term>
<listitem>