mirror of
https://github.com/postgres/postgres.git
synced 2025-04-18 13:44:19 +03:00
Rework option set of vacuumlo
Like oid2name, vacuumlo has been lacking consistency with other utilities for its options: - Connection options gain long aliases. - Document environment variables which could be used: PGHOST, PGPORT and PGUSER. Documentation and code is reordered to be more consistent. A basic set of TAP tests has been added while on it. Author: Tatsuro Yamada Reviewed-by: Michael Paquier Discussion: https://postgr.es/m/c7e7f25c-1747-cd0f-9335-390bc97b2db5@lab.ntt.co.jp
This commit is contained in:
parent
1aaf532dea
commit
bfea331a5e
2
contrib/vacuumlo/.gitignore
vendored
2
contrib/vacuumlo/.gitignore
vendored
@ -1 +1,3 @@
|
|||||||
/vacuumlo
|
/vacuumlo
|
||||||
|
|
||||||
|
/tmp_check/
|
||||||
|
@ -19,3 +19,9 @@ top_builddir = ../..
|
|||||||
include $(top_builddir)/src/Makefile.global
|
include $(top_builddir)/src/Makefile.global
|
||||||
include $(top_srcdir)/contrib/contrib-global.mk
|
include $(top_srcdir)/contrib/contrib-global.mk
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
check:
|
||||||
|
$(prove_check)
|
||||||
|
|
||||||
|
installcheck:
|
||||||
|
$(prove_installcheck)
|
||||||
|
9
contrib/vacuumlo/t/001_basic.pl
Normal file
9
contrib/vacuumlo/t/001_basic.pl
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
use strict;
|
||||||
|
use warnings;
|
||||||
|
|
||||||
|
use TestLib;
|
||||||
|
use Test::More tests => 8;
|
||||||
|
|
||||||
|
program_help_ok('vacuumlo');
|
||||||
|
program_version_ok('vacuumlo');
|
||||||
|
program_options_handling_ok('vacuumlo');
|
@ -26,6 +26,7 @@
|
|||||||
#include "fe_utils/connect.h"
|
#include "fe_utils/connect.h"
|
||||||
#include "libpq-fe.h"
|
#include "libpq-fe.h"
|
||||||
#include "pg_getopt.h"
|
#include "pg_getopt.h"
|
||||||
|
#include "getopt_long.h"
|
||||||
|
|
||||||
#define BUFSIZE 1024
|
#define BUFSIZE 1024
|
||||||
|
|
||||||
@ -434,17 +435,17 @@ usage(const char *progname)
|
|||||||
printf("%s removes unreferenced large objects from databases.\n\n", progname);
|
printf("%s removes unreferenced large objects from databases.\n\n", progname);
|
||||||
printf("Usage:\n %s [OPTION]... DBNAME...\n\n", progname);
|
printf("Usage:\n %s [OPTION]... DBNAME...\n\n", progname);
|
||||||
printf("Options:\n");
|
printf("Options:\n");
|
||||||
printf(" -l LIMIT commit after removing each LIMIT large objects\n");
|
printf(" -l, --limit=LIMIT commit after removing each LIMIT large objects\n");
|
||||||
printf(" -n don't remove large objects, just show what would be done\n");
|
printf(" -n, --dry-run don't remove large objects, just show what would be done\n");
|
||||||
printf(" -v write a lot of progress messages\n");
|
printf(" -v, --verbose write a lot of progress messages\n");
|
||||||
printf(" -V, --version output version information, then exit\n");
|
printf(" -V, --version output version information, then exit\n");
|
||||||
printf(" -?, --help show this help, then exit\n");
|
printf(" -?, --help show this help, then exit\n");
|
||||||
printf("\nConnection options:\n");
|
printf("\nConnection options:\n");
|
||||||
printf(" -h HOSTNAME database server host or socket directory\n");
|
printf(" -h, --host=HOSTNAME database server host or socket directory\n");
|
||||||
printf(" -p PORT database server port\n");
|
printf(" -p, --port=PORT database server port\n");
|
||||||
printf(" -U USERNAME user name to connect as\n");
|
printf(" -U, --username=USERNAME user name to connect as\n");
|
||||||
printf(" -w never prompt for password\n");
|
printf(" -w, --no-password never prompt for password\n");
|
||||||
printf(" -W force password prompt\n");
|
printf(" -W, --password force password prompt\n");
|
||||||
printf("\n");
|
printf("\n");
|
||||||
printf("Report bugs to <pgsql-bugs@postgresql.org>.\n");
|
printf("Report bugs to <pgsql-bugs@postgresql.org>.\n");
|
||||||
}
|
}
|
||||||
@ -453,11 +454,26 @@ usage(const char *progname)
|
|||||||
int
|
int
|
||||||
main(int argc, char **argv)
|
main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
|
static struct option long_options[] = {
|
||||||
|
{"host", required_argument, NULL, 'h'},
|
||||||
|
{"limit", required_argument, NULL, 'l'},
|
||||||
|
{"dry-run", no_argument, NULL, 'n'},
|
||||||
|
{"port", required_argument, NULL, 'p'},
|
||||||
|
{"username", required_argument, NULL, 'U'},
|
||||||
|
{"verbose", no_argument, NULL, 'v'},
|
||||||
|
{"version", no_argument, NULL, 'V'},
|
||||||
|
{"no-password", no_argument, NULL, 'w'},
|
||||||
|
{"password", no_argument, NULL, 'W'},
|
||||||
|
{"help", no_argument, NULL, '?'},
|
||||||
|
{NULL, 0, NULL, 0}
|
||||||
|
};
|
||||||
|
|
||||||
int rc = 0;
|
int rc = 0;
|
||||||
struct _param param;
|
struct _param param;
|
||||||
int c;
|
int c;
|
||||||
int port;
|
int port;
|
||||||
const char *progname;
|
const char *progname;
|
||||||
|
int optindex;
|
||||||
|
|
||||||
progname = get_progname(argv[0]);
|
progname = get_progname(argv[0]);
|
||||||
|
|
||||||
@ -486,25 +502,15 @@ main(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
while (1)
|
while ((c = getopt_long(argc, argv, "h:l:np:U:vwW", long_options, &optindex)) != -1)
|
||||||
{
|
{
|
||||||
c = getopt(argc, argv, "h:l:U:p:vnwW");
|
|
||||||
if (c == -1)
|
|
||||||
break;
|
|
||||||
|
|
||||||
switch (c)
|
switch (c)
|
||||||
{
|
{
|
||||||
case '?':
|
case '?':
|
||||||
fprintf(stderr, _("Try \"%s --help\" for more information.\n"), progname);
|
fprintf(stderr, _("Try \"%s --help\" for more information.\n"), progname);
|
||||||
exit(1);
|
exit(1);
|
||||||
case ':':
|
case 'h':
|
||||||
exit(1);
|
param.pg_host = pg_strdup(optarg);
|
||||||
case 'v':
|
|
||||||
param.verbose = 1;
|
|
||||||
break;
|
|
||||||
case 'n':
|
|
||||||
param.dry_run = 1;
|
|
||||||
param.verbose = 1;
|
|
||||||
break;
|
break;
|
||||||
case 'l':
|
case 'l':
|
||||||
param.transaction_limit = strtol(optarg, NULL, 10);
|
param.transaction_limit = strtol(optarg, NULL, 10);
|
||||||
@ -516,14 +522,9 @@ main(int argc, char **argv)
|
|||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'U':
|
case 'n':
|
||||||
param.pg_user = pg_strdup(optarg);
|
param.dry_run = 1;
|
||||||
break;
|
param.verbose = 1;
|
||||||
case 'w':
|
|
||||||
param.pg_prompt = TRI_NO;
|
|
||||||
break;
|
|
||||||
case 'W':
|
|
||||||
param.pg_prompt = TRI_YES;
|
|
||||||
break;
|
break;
|
||||||
case 'p':
|
case 'p':
|
||||||
port = strtol(optarg, NULL, 10);
|
port = strtol(optarg, NULL, 10);
|
||||||
@ -534,9 +535,21 @@ main(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
param.pg_port = pg_strdup(optarg);
|
param.pg_port = pg_strdup(optarg);
|
||||||
break;
|
break;
|
||||||
case 'h':
|
case 'U':
|
||||||
param.pg_host = pg_strdup(optarg);
|
param.pg_user = pg_strdup(optarg);
|
||||||
break;
|
break;
|
||||||
|
case 'v':
|
||||||
|
param.verbose = 1;
|
||||||
|
break;
|
||||||
|
case 'w':
|
||||||
|
param.pg_prompt = TRI_NO;
|
||||||
|
break;
|
||||||
|
case 'W':
|
||||||
|
param.pg_prompt = TRI_YES;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
fprintf(stderr, _("Try \"%s --help\" for more information.\n"), progname);
|
||||||
|
exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -55,7 +55,8 @@
|
|||||||
|
|
||||||
<variablelist>
|
<variablelist>
|
||||||
<varlistentry>
|
<varlistentry>
|
||||||
<term><option>-l</option> <replaceable>limit</replaceable></term>
|
<term><option>-l <replaceable class="parameter">limit</replaceable></option></term>
|
||||||
|
<term><option>--limit=<replaceable class="parameter">limit</replaceable></option></term>
|
||||||
<listitem>
|
<listitem>
|
||||||
<para>
|
<para>
|
||||||
Remove no more than <replaceable>limit</replaceable> large objects per
|
Remove no more than <replaceable>limit</replaceable> large objects per
|
||||||
@ -69,6 +70,7 @@
|
|||||||
|
|
||||||
<varlistentry>
|
<varlistentry>
|
||||||
<term><option>-n</option></term>
|
<term><option>-n</option></term>
|
||||||
|
<term><option>--dry-run</option></term>
|
||||||
<listitem>
|
<listitem>
|
||||||
<para>Don't remove anything, just show what would be done.</para>
|
<para>Don't remove anything, just show what would be done.</para>
|
||||||
</listitem>
|
</listitem>
|
||||||
@ -76,6 +78,7 @@
|
|||||||
|
|
||||||
<varlistentry>
|
<varlistentry>
|
||||||
<term><option>-v</option></term>
|
<term><option>-v</option></term>
|
||||||
|
<term><option>--verbose</option></term>
|
||||||
<listitem>
|
<listitem>
|
||||||
<para>Write a lot of progress messages.</para>
|
<para>Write a lot of progress messages.</para>
|
||||||
</listitem>
|
</listitem>
|
||||||
@ -110,21 +113,24 @@
|
|||||||
|
|
||||||
<variablelist>
|
<variablelist>
|
||||||
<varlistentry>
|
<varlistentry>
|
||||||
<term><option>-h</option> <replaceable>hostname</replaceable></term>
|
<term><option>-h <replaceable class="parameter">host</replaceable></option></term>
|
||||||
|
<term><option>--host=<replaceable class="parameter">host</replaceable></option></term>
|
||||||
<listitem>
|
<listitem>
|
||||||
<para>Database server's host.</para>
|
<para>Database server's host.</para>
|
||||||
</listitem>
|
</listitem>
|
||||||
</varlistentry>
|
</varlistentry>
|
||||||
|
|
||||||
<varlistentry>
|
<varlistentry>
|
||||||
<term><option>-p</option> <replaceable>port</replaceable></term>
|
<term><option>-p <replaceable>port</replaceable></option></term>
|
||||||
|
<term><option>--port=<replaceable class="parameter">port</replaceable></option></term>
|
||||||
<listitem>
|
<listitem>
|
||||||
<para>Database server's port.</para>
|
<para>Database server's port.</para>
|
||||||
</listitem>
|
</listitem>
|
||||||
</varlistentry>
|
</varlistentry>
|
||||||
|
|
||||||
<varlistentry>
|
<varlistentry>
|
||||||
<term><option>-U</option> <replaceable>username</replaceable></term>
|
<term><option>-U <replaceable>username</replaceable></option></term>
|
||||||
|
<term><option>--username=<replaceable class="parameter">username</replaceable></option></term>
|
||||||
<listitem>
|
<listitem>
|
||||||
<para>User name to connect as.</para>
|
<para>User name to connect as.</para>
|
||||||
</listitem>
|
</listitem>
|
||||||
@ -146,6 +152,7 @@
|
|||||||
|
|
||||||
<varlistentry>
|
<varlistentry>
|
||||||
<term><option>-W</option></term>
|
<term><option>-W</option></term>
|
||||||
|
<term><option>--password</option></term>
|
||||||
<listitem>
|
<listitem>
|
||||||
<para>
|
<para>
|
||||||
Force <application>vacuumlo</application> to prompt for a
|
Force <application>vacuumlo</application> to prompt for a
|
||||||
@ -167,6 +174,30 @@
|
|||||||
</para>
|
</para>
|
||||||
</refsect1>
|
</refsect1>
|
||||||
|
|
||||||
|
<refsect1>
|
||||||
|
<title>Environment</title>
|
||||||
|
|
||||||
|
<variablelist>
|
||||||
|
<varlistentry>
|
||||||
|
<term><envar>PGHOST</envar></term>
|
||||||
|
<term><envar>PGPORT</envar></term>
|
||||||
|
<term><envar>PGUSER</envar></term>
|
||||||
|
|
||||||
|
<listitem>
|
||||||
|
<para>
|
||||||
|
Default connection parameters.
|
||||||
|
</para>
|
||||||
|
</listitem>
|
||||||
|
</varlistentry>
|
||||||
|
</variablelist>
|
||||||
|
|
||||||
|
<para>
|
||||||
|
This utility, like most other <productname>PostgreSQL</productname> utilities,
|
||||||
|
also uses the environment variables supported by <application>libpq</application>
|
||||||
|
(see <xref linkend="libpq-envars"/>).
|
||||||
|
</para>
|
||||||
|
</refsect1>
|
||||||
|
|
||||||
<refsect1>
|
<refsect1>
|
||||||
<title>Notes</title>
|
<title>Notes</title>
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user