Fix help option of contrib/oid2name
Hi,
Almost all client applications and extensions will show "Options" and
"Connection options" sections when running with help option (--help).
However, "oid2name" was different, there is only the Options section.
For example,
$ vacuumlo --help
vacuumlo removes unreferenced large objects from databases.
Usage:
vacuumlo [OPTION]... DBNAME...
Options:
-l LIMIT commit after removing each LIMIT large objects
-n don't remove large objects, just show what would be done
-v write a lot of progress messages
-V, --version output version information, then exit
-?, --help show this help, then exit
Connection options:
-h HOSTNAME database server host or socket directory
-p PORT database server port
-U USERNAME user name to connect as
-w never prompt for password
-W force password prompt
$ oid2name --help
oid2name helps examining the file structure used by PostgreSQL.
Usage:
oid2name [OPTION]...
Options:
-d DBNAME database to connect to
-f FILENODE show info for table with given file node
-H HOSTNAME database server host or socket directory
-i show indexes and sequences too
-o OID show info for table with given OID
-p PORT database server port number
-q quiet (don't show headers)
-s show all tablespaces
-S show system objects too
-t TABLE show info for named table
-U NAME connect as specified database user
-V, --version output version information, then exit
-x extended (show additional columns)
-?, --help show this help, then exit
Above oid2name's "-d, -H, -p and -U" options are related to Connection
Options. So, it would be beter to write it in Connection options.
For consistency, attached patch divides the Options section of oid2name
into two sections, Options and Connection options.
Regards,
Tatsuro Yamada
NTT Open Source Software Center
Attachments:
fix_oid2name_help_option.patchtext/x-patch; name=fix_oid2name_help_option.patchDownload
diff --git a/contrib/oid2name/oid2name.c b/contrib/oid2name/oid2name.c
index 63e360c4c5..157eebb3dd 100644
--- a/contrib/oid2name/oid2name.c
+++ b/contrib/oid2name/oid2name.c
@@ -176,23 +176,25 @@ help(const char *progname)
"Usage:\n"
" %s [OPTION]...\n"
"\nOptions:\n"
- " -d DBNAME database to connect to\n"
" -f FILENODE show info for table with given file node\n"
- " -H HOSTNAME database server host or socket directory\n"
" -i show indexes and sequences too\n"
" -o OID show info for table with given OID\n"
- " -p PORT database server port number\n"
" -q quiet (don't show headers)\n"
" -s show all tablespaces\n"
" -S show system objects too\n"
" -t TABLE show info for named table\n"
- " -U NAME connect as specified database user\n"
" -V, --version output version information, then exit\n"
" -x extended (show additional columns)\n"
" -?, --help show this help, then exit\n"
+ "\nConnection options:\n"
+ " -d DBNAME database to connect to\n"
+ " -H HOSTNAME database server host or socket directory\n"
+ " -p PORT database server port number\n"
+ " -U NAME connect as specified database user\n"
"\nThe default action is to show all database OIDs.\n\n"
"Report bugs to <pgsql-bugs@postgresql.org>.\n",
progname, progname);
+
}
/*
Tatsuro Yamada wrote:
Almost all client applications and extensions will show "Options" and
"Connection options" sections when running with help option (--help).
However, "oid2name" was different, there is only the Options section.For consistency, attached patch divides the Options section of oid2name
into two sections, Options and Connection options.
I don't think it is super important, but +1 for consistency.
Yours,
Laurenz Albe
On Thu, Aug 16, 2018 at 12:40:42PM +0200, Laurenz Albe wrote:
I don't think it is super important, but +1 for consistency.
I agree on both points. Any objections if I apply what's proposed here
on HEAD?
--
Michael
On Thu, Aug 16, 2018 at 08:57:57PM +0900, Michael Paquier wrote:
I agree on both points. Any objections if I apply what's proposed here
on HEAD?
I have been looking at this patch. And while consistency is nice, I
think that if we are cleaning up this stuff we could do a bit more to
be more consistent with the other binary tools:
- Addition of long options for connection options.
- removal of -h, and use it for host value instead of "-H".
- Use "USERNAME" instead of "NAME" in help().
vacuumlo could also be improved a bit...
--
Michael
Hi Laurenz and Michael,
On 2018/08/16 20:57, Michael Paquier wrote:
On Thu, Aug 16, 2018 at 12:40:42PM +0200, Laurenz Albe wrote:
I don't think it is super important, but +1 for consistency.
Thanks! :)
I agree on both points. Any objections if I apply what's proposed here
on HEAD?
I have no objection. The patch is for improvement, not bug fix.
But if you think it needs back-patch, please let me know, I can create it.
Thank you for taking your time!
Regards,
Tatsuro Yamada
NTT Open Source Software Center
On Fri, Aug 17, 2018 at 12:19:42PM +0900, Tatsuro Yamada wrote:
But if you think it needs back-patch, please let me know, I can create it.
This would not be back-patched.
--
Michael
On 2018/08/17 12:31, Michael Paquier wrote:
On Fri, Aug 17, 2018 at 12:19:42PM +0900, Tatsuro Yamada wrote:
But if you think it needs back-patch, please let me know, I can create it.
This would not be back-patched.
I see.
Thanks,
Tatsuro Yamada
On 2018/08/17 11:47, Michael Paquier wrote:
On Thu, Aug 16, 2018 at 08:57:57PM +0900, Michael Paquier wrote:
I agree on both points. Any objections if I apply what's proposed here
on HEAD?I have been looking at this patch. And while consistency is nice, I
think that if we are cleaning up this stuff we could do a bit more to
be more consistent with the other binary tools:
- Addition of long options for connection options.
- removal of -h, and use it for host value instead of "-H".
- Use "USERNAME" instead of "NAME" in help().vacuumlo could also be improved a bit...
Yeah, I'll revise the patch based on your suggestions.
Regards,
Tatsuro Yamada
On 2018/08/17 12:42, Tatsuro Yamada wrote:
On 2018/08/17 11:47, Michael Paquier wrote:
On Thu, Aug 16, 2018 at 08:57:57PM +0900, Michael Paquier wrote:
I agree on both points.� Any objections if I apply what's proposed here
on HEAD?I have been looking at this patch.� And while consistency is nice, I
think that if we are cleaning up this stuff we could do a bit more to
be more consistent with the other binary tools:
- Addition of long options for connection options.
- removal of -h, and use it for host value instead of "-H".
- Use "USERNAME" instead of "NAME" in help().vacuumlo could also be improved a bit...
Yeah, I'll revise the patch based on your suggestions.
I created WIP patch for oid2name and vacuumlo includes followings:
oid2name and vacuumlo
- Add long options
only oid2name
- Replace -H with -h
- Replace NAME with USERNAME
I'll revise their documents and create new patch next week, probably. :)
Regards,
Tatsuro Yamada
Attachments:
fix_help_option_for_oid2name_vacuumlo_wip1.patchtext/x-patch; name=fix_help_option_for_oid2name_vacuumlo_wip1.patchDownload
diff --git a/contrib/oid2name/oid2name.c b/contrib/oid2name/oid2name.c
index 63e360c4c5..3501a9c2cc 100644
--- a/contrib/oid2name/oid2name.c
+++ b/contrib/oid2name/oid2name.c
@@ -60,8 +60,25 @@ void sql_exec_dumpalltbspc(PGconn *, struct options *);
void
get_opts(int argc, char **argv, struct options *my_opts)
{
+ static struct option long_options[] = {
+ {"host", required_argument, NULL, 'h'},
+ {"port", required_argument, NULL, 'p'},
+ {"username", required_argument, NULL, 'U'},
+ {"dbname", required_argument, NULL, 'd'},
+ {"tablename", required_argument, NULL, 't'},
+ {"oid", required_argument, NULL, 'o'},
+ {"filenode", no_argument, NULL, 'f'},
+ {"quiet", no_argument, NULL, 'q'},
+ {"system", no_argument, NULL, 'S'},
+ {"extend", no_argument, NULL, 'x'},
+ {"index", no_argument, NULL, 'i'},
+ {"tablespace", no_argument, NULL, 's'},
+ {NULL, 0, NULL, 0}
+ };
+
int c;
const char *progname;
+ int optindex;
progname = get_progname(argv[0]);
@@ -93,10 +110,25 @@ get_opts(int argc, char **argv, struct options *my_opts)
}
/* get opts */
- while ((c = getopt(argc, argv, "H:p:U:d:t:o:f:qSxish")) != -1)
+ while ((c = getopt_long(argc, argv, "h:p:U:d:t:o:f:qSxis", long_options, &optindex)) != -1)
{
switch (c)
{
+ /* host to connect to */
+ case 'h':
+ my_opts->hostname = pg_strdup(optarg);
+ break;
+
+ /* port to connect to on remote host */
+ case 'p':
+ my_opts->port = pg_strdup(optarg);
+ break;
+
+ /* username */
+ case 'U':
+ my_opts->username = pg_strdup(optarg);
+ break;
+
/* specify the database */
case 'd':
my_opts->dbname = pg_strdup(optarg);
@@ -122,46 +154,26 @@ get_opts(int argc, char **argv, struct options *my_opts)
my_opts->quiet = true;
break;
- /* host to connect to */
- case 'H':
- my_opts->hostname = pg_strdup(optarg);
- break;
-
- /* port to connect to on remote host */
- case 'p':
- my_opts->port = pg_strdup(optarg);
- break;
-
- /* username */
- case 'U':
- my_opts->username = pg_strdup(optarg);
- break;
-
/* display system tables */
case 'S':
my_opts->systables = true;
break;
- /* also display indexes */
- case 'i':
- my_opts->indexes = true;
- break;
-
/* display extra columns */
case 'x':
my_opts->extended = true;
break;
+ /* also display indexes */
+ case 'i':
+ my_opts->indexes = true;
+ break;
+
/* dump tablespaces only */
case 's':
my_opts->tablespaces = true;
break;
- case 'h':
- help(progname);
- exit(0);
- break;
-
default:
fprintf(stderr, _("Try \"%s --help\" for more information.\n"), progname);
exit(1);
@@ -176,20 +188,21 @@ help(const char *progname)
"Usage:\n"
" %s [OPTION]...\n"
"\nOptions:\n"
- " -d DBNAME database to connect to\n"
- " -f FILENODE show info for table with given file node\n"
- " -H HOSTNAME database server host or socket directory\n"
- " -i show indexes and sequences too\n"
- " -o OID show info for table with given OID\n"
- " -p PORT database server port number\n"
- " -q quiet (don't show headers)\n"
- " -s show all tablespaces\n"
- " -S show system objects too\n"
- " -t TABLE show info for named table\n"
- " -U NAME connect as specified database user\n"
- " -V, --version output version information, then exit\n"
- " -x extended (show additional columns)\n"
- " -?, --help show this help, then exit\n"
+ " -f, --filenode FILENODE show info for table with given file node\n"
+ " -i, --index show indexes and sequences too\n"
+ " -o, --oid=OID show info for table with given OID\n"
+ " -q, --quiet quiet (don't show headers)\n"
+ " -s, --tablespace show all tablespaces\n"
+ " -S, --system show system objects too\n"
+ " -t, --table=TABLE show info for named table\n"
+ " -V, --version output version information, then exit\n"
+ " -x, --extend extended (show additional columns)\n"
+ " -?, --help show this help, then exit\n"
+ "\nConnection options:\n"
+ " -d, --dbname=DBNAME database to connect to\n"
+ " -h, --host=HOSTNAME database server host or socket directory\n"
+ " -p, --port=PORT database server port number\n"
+ " -U, --username=USERNAME connect as specified database user\n"
"\nThe default action is to show all database OIDs.\n\n"
"Report bugs to <pgsql-bugs@postgresql.org>.\n",
progname, progname);
diff --git a/contrib/vacuumlo/vacuumlo.c b/contrib/vacuumlo/vacuumlo.c
index 7eb474ca3e..321ce8ae8c 100644
--- a/contrib/vacuumlo/vacuumlo.c
+++ b/contrib/vacuumlo/vacuumlo.c
@@ -434,17 +434,17 @@ usage(const char *progname)
printf("%s removes unreferenced large objects from databases.\n\n", progname);
printf("Usage:\n %s [OPTION]... DBNAME...\n\n", progname);
printf("Options:\n");
- printf(" -l LIMIT commit after removing each LIMIT large objects\n");
- printf(" -n don't remove large objects, just show what would be done\n");
- printf(" -v write a lot of progress messages\n");
- printf(" -V, --version output version information, then exit\n");
- printf(" -?, --help show this help, then exit\n");
+ printf(" -l, --limit=LIMIT commit after removing each LIMIT large objects\n");
+ printf(" -n, --dry-run don't remove large objects, just show what would be done\n");
+ printf(" -v, --verbose write a lot of progress messages\n");
+ printf(" -V, --version output version information, then exit\n");
+ printf(" -?, --help show this help, then exit\n");
printf("\nConnection options:\n");
- printf(" -h HOSTNAME database server host or socket directory\n");
- printf(" -p PORT database server port\n");
- printf(" -U USERNAME user name to connect as\n");
- printf(" -w never prompt for password\n");
- printf(" -W force password prompt\n");
+ printf(" -h, --host=HOSTNAME database server host or socket directory\n");
+ printf(" -p, --port=PORT database server port\n");
+ printf(" -U, --username=USERNAME user name to connect as\n");
+ printf(" -w, --no-password never prompt for password\n");
+ printf(" -W, --password force password prompt\n");
printf("\n");
printf("Report bugs to <pgsql-bugs@postgresql.org>.\n");
}
@@ -453,11 +453,24 @@ usage(const char *progname)
int
main(int argc, char **argv)
{
+ static struct option long_options[] = {
+ {"host", required_argument, NULL, 'h'},
+ {"limit", required_argument, NULL, 'l'},
+ {"username", required_argument, NULL, 'U'},
+ {"port", required_argument, NULL, 'p'},
+ {"verbose", no_argument, NULL, 'v'},
+ {"dry-run", no_argument, NULL, 'n'},
+ {"no-password", no_argument, NULL, 'w'},
+ {"password", no_argument, NULL, 'W'},
+ {NULL, 0, NULL, 0}
+ };
+
int rc = 0;
struct _param param;
int c;
int port;
const char *progname;
+ int optindex;
progname = get_progname(argv[0]);
@@ -486,12 +499,8 @@ main(int argc, char **argv)
}
}
- while (1)
+ while((c = getopt_long(argc, argv, "h:l:U:p:vnwW", long_options, &optindex)) != -1)
{
- c = getopt(argc, argv, "h:l:U:p:vnwW");
- if (c == -1)
- break;
-
switch (c)
{
case '?':
On 2018-Aug-17, Tatsuro Yamada wrote:
only oid2name
- Replace -H with -h
I think this one is a bad idea, as it'll break scripts.
--
�lvaro Herrera https://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
Alvaro Herrera <alvherre@2ndquadrant.com> writes:
On 2018-Aug-17, Tatsuro Yamada wrote:
only oid2name
- Replace -H with -h
I think this one is a bad idea, as it'll break scripts.
Well, we can't remove the -H option, for that reason. But I think
we could get away with repurposing -h to also mean "--host", rather
than "--help" as it is now. Seems unlikely that any scripts are
depending on it to mean --help, nor are users likely to expect that
when none of our other programs treat it that way.
regards, tom lane
On August 17, 2018 10:53:48 PM GMT+09:00, Tom Lane <tgl@sss.pgh.pa.us> wrote:
Well, we can't remove the -H option, for that reason. But I think
we could get away with repurposing -h to also mean "--host", rather
than "--help" as it is now. Seems unlikely that any scripts are
depending on it to mean --help, nor are users likely to expect that
when none of our other programs treat it that way.
Yeah, I don't see much point in mapping -h to --help. Let's map silently -H to --host then. Would you prefer if -H is still documented? Or would it be better if it is not documented, mapping silently?
--
Michael
Michael Paquier <michael@paquier.xyz> writes:
On August 17, 2018 10:53:48 PM GMT+09:00, Tom Lane <tgl@sss.pgh.pa.us> wrote:
Well, we can't remove the -H option, for that reason. But I think
we could get away with repurposing -h to also mean "--host", rather
than "--help" as it is now. Seems unlikely that any scripts are
depending on it to mean --help, nor are users likely to expect that
when none of our other programs treat it that way.
Yeah, I don't see much point in mapping -h to --help. Let's map silently -H to --host then. Would you prefer if -H is still documented? Or would it be better if it is not documented, mapping silently?
I think it probably needs to stay documented, but we could mark it as
deprecated ...
regards, tom lane
On August 18, 2018 10:52:33 AM GMT+09:00, Tom Lane <tgl@sss.pgh.pa.us> wrote:
I think it probably needs to stay documented, but we could mark it as
deprecated ...
Okay, no issues with doing so.
--
Michael
On August 18, 2018 10:52:33 AM GMT+09:00, Tom Lane <tgl@sss.pgh.pa.us> wrote:
I think it probably needs to stay documented, but we could mark it as
deprecated ...Okay, no issues with doing so.
I revised the patch like following:
vacuumlo:
Document
- Add long options
- Add environment section
oid2name:
Document
- Add long options
- Add environment section
- Remove deprecated and unhandled option "-P password"
Code
- Revive handling "-H host" option silently
I didn't add "-H" to the help message because it's a deprecated option.
I guess that that means "silently" as you said on previous email.
Should I add it? For example,
Not added "-H". (current patch)
--------
Connection options:
-d, --dbname=DBNAME database to connect to
-h, --host=HOSTNAME database server host or socket directory
-p, --port=PORT database server port number
-U, --username=USERNAME connect as specified database user
--------
Added "-H" to the help message after "-h"
--------
Connection options:
-d, --dbname=DBNAME database to connect to
-h, -H, --host=HOSTNAME database server host or socket directory
-p, --port=PORT database server port number
-U, --username=USERNAME connect as specified database user
--------
Please find the attached patch.
Regards,
Tatsuro Yamada
Attachments:
fix_help_option_for_oid2name_vacuumlo_wip2.patchtext/x-patch; name=fix_help_option_for_oid2name_vacuumlo_wip2.patchDownload
diff --git a/contrib/oid2name/oid2name.c b/contrib/oid2name/oid2name.c
index 63e360c4c5..5f6813f91c 100644
--- a/contrib/oid2name/oid2name.c
+++ b/contrib/oid2name/oid2name.c
@@ -60,8 +60,26 @@ void sql_exec_dumpalltbspc(PGconn *, struct options *);
void
get_opts(int argc, char **argv, struct options *my_opts)
{
+ static struct option long_options[] = {
+ {"host", required_argument, NULL, 'h'},
+ {"host", required_argument, NULL, 'H'}, /* deprecated */
+ {"port", required_argument, NULL, 'p'},
+ {"username", required_argument, NULL, 'U'},
+ {"dbname", required_argument, NULL, 'd'},
+ {"tablename", required_argument, NULL, 't'},
+ {"oid", required_argument, NULL, 'o'},
+ {"filenode", required_argument, NULL, 'f'},
+ {"quiet", no_argument, NULL, 'q'},
+ {"system", no_argument, NULL, 'S'},
+ {"extend", no_argument, NULL, 'x'},
+ {"index", no_argument, NULL, 'i'},
+ {"tablespace", no_argument, NULL, 's'},
+ {NULL, 0, NULL, 0}
+ };
+
int c;
const char *progname;
+ int optindex;
progname = get_progname(argv[0]);
@@ -93,10 +111,30 @@ get_opts(int argc, char **argv, struct options *my_opts)
}
/* get opts */
- while ((c = getopt(argc, argv, "H:p:U:d:t:o:f:qSxish")) != -1)
+ while ((c = getopt_long(argc, argv, "H:h:p:U:d:t:o:f:qSxis", long_options, &optindex)) != -1)
{
switch (c)
{
+ /* host to connect to */
+ case 'h':
+ my_opts->hostname = pg_strdup(optarg);
+ break;
+
+ /* (deprecated) host to connect to */
+ case 'H':
+ my_opts->hostname = pg_strdup(optarg);
+ break;
+
+ /* port to connect to on remote host */
+ case 'p':
+ my_opts->port = pg_strdup(optarg);
+ break;
+
+ /* username */
+ case 'U':
+ my_opts->username = pg_strdup(optarg);
+ break;
+
/* specify the database */
case 'd':
my_opts->dbname = pg_strdup(optarg);
@@ -122,46 +160,26 @@ get_opts(int argc, char **argv, struct options *my_opts)
my_opts->quiet = true;
break;
- /* host to connect to */
- case 'H':
- my_opts->hostname = pg_strdup(optarg);
- break;
-
- /* port to connect to on remote host */
- case 'p':
- my_opts->port = pg_strdup(optarg);
- break;
-
- /* username */
- case 'U':
- my_opts->username = pg_strdup(optarg);
- break;
-
/* display system tables */
case 'S':
my_opts->systables = true;
break;
- /* also display indexes */
- case 'i':
- my_opts->indexes = true;
- break;
-
/* display extra columns */
case 'x':
my_opts->extended = true;
break;
+ /* also display indexes */
+ case 'i':
+ my_opts->indexes = true;
+ break;
+
/* dump tablespaces only */
case 's':
my_opts->tablespaces = true;
break;
- case 'h':
- help(progname);
- exit(0);
- break;
-
default:
fprintf(stderr, _("Try \"%s --help\" for more information.\n"), progname);
exit(1);
@@ -176,20 +194,21 @@ help(const char *progname)
"Usage:\n"
" %s [OPTION]...\n"
"\nOptions:\n"
- " -d DBNAME database to connect to\n"
- " -f FILENODE show info for table with given file node\n"
- " -H HOSTNAME database server host or socket directory\n"
- " -i show indexes and sequences too\n"
- " -o OID show info for table with given OID\n"
- " -p PORT database server port number\n"
- " -q quiet (don't show headers)\n"
- " -s show all tablespaces\n"
- " -S show system objects too\n"
- " -t TABLE show info for named table\n"
- " -U NAME connect as specified database user\n"
- " -V, --version output version information, then exit\n"
- " -x extended (show additional columns)\n"
- " -?, --help show this help, then exit\n"
+ " -f, --filenode FILENODE show info for table with given file node\n"
+ " -i, --index show indexes and sequences too\n"
+ " -o, --oid=OID show info for table with given OID\n"
+ " -q, --quiet quiet (don't show headers)\n"
+ " -s, --tablespace show all tablespaces\n"
+ " -S, --system show system objects too\n"
+ " -t, --table=TABLE show info for named table\n"
+ " -V, --version output version information, then exit\n"
+ " -x, --extend extended (show additional columns)\n"
+ " -?, --help show this help, then exit\n"
+ "\nConnection options:\n"
+ " -d, --dbname=DBNAME database to connect to\n"
+ " -h, --host=HOSTNAME database server host or socket directory\n"
+ " -p, --port=PORT database server port number\n"
+ " -U, --username=USERNAME connect as specified database user\n"
"\nThe default action is to show all database OIDs.\n\n"
"Report bugs to <pgsql-bugs@postgresql.org>.\n",
progname, progname);
diff --git a/contrib/vacuumlo/vacuumlo.c b/contrib/vacuumlo/vacuumlo.c
index 7eb474ca3e..321ce8ae8c 100644
--- a/contrib/vacuumlo/vacuumlo.c
+++ b/contrib/vacuumlo/vacuumlo.c
@@ -434,17 +434,17 @@ usage(const char *progname)
printf("%s removes unreferenced large objects from databases.\n\n", progname);
printf("Usage:\n %s [OPTION]... DBNAME...\n\n", progname);
printf("Options:\n");
- printf(" -l LIMIT commit after removing each LIMIT large objects\n");
- printf(" -n don't remove large objects, just show what would be done\n");
- printf(" -v write a lot of progress messages\n");
- printf(" -V, --version output version information, then exit\n");
- printf(" -?, --help show this help, then exit\n");
+ printf(" -l, --limit=LIMIT commit after removing each LIMIT large objects\n");
+ printf(" -n, --dry-run don't remove large objects, just show what would be done\n");
+ printf(" -v, --verbose write a lot of progress messages\n");
+ printf(" -V, --version output version information, then exit\n");
+ printf(" -?, --help show this help, then exit\n");
printf("\nConnection options:\n");
- printf(" -h HOSTNAME database server host or socket directory\n");
- printf(" -p PORT database server port\n");
- printf(" -U USERNAME user name to connect as\n");
- printf(" -w never prompt for password\n");
- printf(" -W force password prompt\n");
+ printf(" -h, --host=HOSTNAME database server host or socket directory\n");
+ printf(" -p, --port=PORT database server port\n");
+ printf(" -U, --username=USERNAME user name to connect as\n");
+ printf(" -w, --no-password never prompt for password\n");
+ printf(" -W, --password force password prompt\n");
printf("\n");
printf("Report bugs to <pgsql-bugs@postgresql.org>.\n");
}
@@ -453,11 +453,24 @@ usage(const char *progname)
int
main(int argc, char **argv)
{
+ static struct option long_options[] = {
+ {"host", required_argument, NULL, 'h'},
+ {"limit", required_argument, NULL, 'l'},
+ {"username", required_argument, NULL, 'U'},
+ {"port", required_argument, NULL, 'p'},
+ {"verbose", no_argument, NULL, 'v'},
+ {"dry-run", no_argument, NULL, 'n'},
+ {"no-password", no_argument, NULL, 'w'},
+ {"password", no_argument, NULL, 'W'},
+ {NULL, 0, NULL, 0}
+ };
+
int rc = 0;
struct _param param;
int c;
int port;
const char *progname;
+ int optindex;
progname = get_progname(argv[0]);
@@ -486,12 +499,8 @@ main(int argc, char **argv)
}
}
- while (1)
+ while((c = getopt_long(argc, argv, "h:l:U:p:vnwW", long_options, &optindex)) != -1)
{
- c = getopt(argc, argv, "h:l:U:p:vnwW");
- if (c == -1)
- break;
-
switch (c)
{
case '?':
diff --git a/doc/src/sgml/oid2name.sgml b/doc/src/sgml/oid2name.sgml
index dd875281c8..8f369cc4c2 100644
--- a/doc/src/sgml/oid2name.sgml
+++ b/doc/src/sgml/oid2name.sgml
@@ -60,45 +60,52 @@
<variablelist>
<varlistentry>
- <term><option>-f</option> <replaceable>filenode</replaceable></term>
- <listitem><para>show info for table with filenode <replaceable>filenode</replaceable></para></listitem>
+ <term><option>-f <replaceable class="parameter">filenode</replaceable></option></term>
+ <term><option>--filenode=<replaceable class="parameter">filenode</replaceable></option></term>
+ <listitem><para>show info for table with filenode <replaceable class="parameter">filenode</replaceable>.</para></listitem>
</varlistentry>
<varlistentry>
- <term><option>-i</option></term>
- <listitem><para>include indexes and sequences in the listing</para></listitem>
+ <term><option>-i </option></term>
+ <term><option>--index</option></term>
+ <listitem><para>include indexes and sequences in the listing.</para></listitem>
</varlistentry>
<varlistentry>
- <term><option>-o</option> <replaceable>oid</replaceable></term>
- <listitem><para>show info for table with OID <replaceable>oid</replaceable></para></listitem>
+ <term><option>-o <replaceable class="parameter">oid</replaceable></option></term>
+ <term><option>--oid=<replaceable class="parameter">oid</replaceable></option></term>
+ <listitem><para>show info for table with OID <replaceable class="parameter">oid</replaceable>.</para></listitem>
</varlistentry>
<varlistentry>
- <term><option>-q</option></term>
- <listitem><para>omit headers (useful for scripting)</para></listitem>
+ <term><option>-q </option></term>
+ <term><option>-quiet</option></term>
+ <listitem><para>omit headers (useful for scripting).</para></listitem>
</varlistentry>
<varlistentry>
- <term><option>-s</option></term>
- <listitem><para>show tablespace OIDs</para></listitem>
+ <term><option>-s </option></term>
+ <term><option>--tablespace</option></term>
+ <listitem><para>show tablespace OIDs.</para></listitem>
</varlistentry>
<varlistentry>
- <term><option>-S</option></term>
+ <term><option>-S </option></term>
+ <term><option>--system</option></term>
<listitem><para>include system objects (those in
<option>information_schema</option>, <option>pg_toast</option>
- and <option>pg_catalog</option> schemas)
+ and <option>pg_catalog</option> schemas).
</para></listitem>
</varlistentry>
<varlistentry>
- <term><option>-t</option> <replaceable>tablename_pattern</replaceable></term>
- <listitem><para>show info for table(s) matching <replaceable>tablename_pattern</replaceable></para></listitem>
+ <term><option>-t <replaceable class="parameter">tablename_pattern</replaceable></option></term>
+ <term><option>--tablename=<replaceable class="parameter">tablename_pattern</replaceable></option></term>
+ <listitem><para>show info for table(s) matching <replaceable class="parameter">tablename_pattern</replaceable>.</para></listitem>
</varlistentry>
<varlistentry>
- <term><option>-V</option></term>
+ <term><option>-V </option></term>
<term><option>--version</option></term>
<listitem>
<para>
@@ -108,14 +115,15 @@
</varlistentry>
<varlistentry>
- <term><option>-x</option></term>
+ <term><option>-x </option></term>
+ <term><option>--extend</option></term>
<listitem><para>display more information about each object shown: tablespace name,
- schema name, and OID
+ schema name, and OID.
</para></listitem>
</varlistentry>
<varlistentry>
- <term><option>-?</option></term>
+ <term><option>-? </option></term>
<term><option>--help</option></term>
<listitem>
<para>
@@ -133,29 +141,27 @@
<variablelist>
<varlistentry>
- <term><option>-d</option> <replaceable>database</replaceable></term>
- <listitem><para>database to connect to</para></listitem>
+ <term><option>-d <replaceable>database</replaceable></option></term>
+ <term><option>--dbname=<replaceable class="parameter">database</replaceable></option></term>
+ <listitem><para>database to connect to.</para></listitem>
</varlistentry>
<varlistentry>
- <term><option>-H</option> <replaceable>host</replaceable></term>
- <listitem><para>database server's host</para></listitem>
+ <term><option>-h <replaceable class="parameter">host</replaceable></option></term>
+ <term><option>--host=<replaceable class="parameter">host</replaceable></option></term>
+ <listitem><para>database server's host. -H is also able to use instead -h, however it's a deprecated option.</para></listitem>
</varlistentry>
<varlistentry>
- <term><option>-p</option> <replaceable>port</replaceable></term>
- <listitem><para>database server's port</para></listitem>
+ <term><option>-p <replaceable>port</replaceable></option></term>
+ <term><option>--port=<replaceable class="parameter">port</replaceable></option></term>
+ <listitem><para>database server's port.</para></listitem>
</varlistentry>
<varlistentry>
- <term><option>-U</option> <replaceable>username</replaceable></term>
- <listitem><para>user name to connect as</para></listitem>
- </varlistentry>
-
- <varlistentry>
- <term><option>-P</option> <replaceable>password</replaceable></term>
- <listitem><para>password (deprecated — putting this on the command line
- is a security hazard)</para></listitem>
+ <term><option>-U <replaceable>username</replaceable></option></term>
+ <term><option>--username=<replaceable class="parameter">username</replaceable></option></term>
+ <listitem><para>user name to connect as.</para></listitem>
</varlistentry>
</variablelist>
@@ -188,6 +194,30 @@
</para>
</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>
<title>Notes</title>
diff --git a/doc/src/sgml/vacuumlo.sgml b/doc/src/sgml/vacuumlo.sgml
index 0b4dfc2b17..e46c27030b 100644
--- a/doc/src/sgml/vacuumlo.sgml
+++ b/doc/src/sgml/vacuumlo.sgml
@@ -55,10 +55,11 @@
<variablelist>
<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>
<para>
- Remove no more than <replaceable>limit</replaceable> large objects per
+ Remove no more than <replaceable class="parameter">limit</replaceable> large objects per
transaction (default 1000). Since the server acquires a lock per LO
removed, removing too many LOs in one transaction risks exceeding
<xref linkend="guc-max-locks-per-transaction"/>. Set the limit to
@@ -68,21 +69,23 @@
</varlistentry>
<varlistentry>
- <term><option>-n</option></term>
+ <term><option>-n </option></term>
+ <term><option>--dry-run</option></term>
<listitem>
<para>Don't remove anything, just show what would be done.</para>
</listitem>
</varlistentry>
<varlistentry>
- <term><option>-v</option></term>
+ <term><option>-v </option></term>
+ <term><option>--verbose</option></term>
<listitem>
<para>Write a lot of progress messages.</para>
</listitem>
</varlistentry>
<varlistentry>
- <term><option>-V</option></term>
+ <term><option>-V </option></term>
<term><option>--version</option></term>
<listitem>
<para>
@@ -92,7 +95,7 @@
</varlistentry>
<varlistentry>
- <term><option>-?</option></term>
+ <term><option>-? </option></term>
<term><option>--help</option></term>
<listitem>
<para>
@@ -110,28 +113,31 @@
<variablelist>
<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>
<para>Database server's host.</para>
</listitem>
</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>
<para>Database server's port.</para>
</listitem>
</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>
<para>User name to connect as.</para>
</listitem>
</varlistentry>
<varlistentry>
- <term><option>-w</option></term>
+ <term><option>-w </option></term>
<term><option>--no-password</option></term>
<listitem>
<para>
@@ -145,7 +151,8 @@
</varlistentry>
<varlistentry>
- <term><option>-W</option></term>
+ <term><option>-W </option></term>
+ <term><option>--passowrd</option></term>
<listitem>
<para>
Force <application>vacuumlo</application> to prompt for a
@@ -167,6 +174,30 @@
</para>
</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>
<title>Notes</title>
On Mon, Aug 20, 2018 at 12:30:29PM +0900, Tatsuro Yamada wrote:
vacuumlo:
Document
- Add long options
- Add environment section
Let's keep things simple by not adding long options where it is not
especially obvious, so I would suggest to keep the patch simple and just
add long options for connection options.
oid2name:
Document
- Add long options
- Add environment section
- Remove deprecated and unhandled option "-P password"
Is this a good idea? I doubt that it is used but keeping it would not
cause any breakage, and removing it could.
oid2name supports also PGDATABASE.
Code
- Revive handling "-H host" option silentlyI didn't add "-H" to the help message because it's a deprecated
option.
It seems to me that this should be still documented in both --help and
in the docs, and that we should just mark it as deprecated in both.
I guess that that means "silently" as you said on previous email.
Should I add it? For example,[...]
Let's use a different line for that. See for example how pg_standby -k
is treated.
I can see why you have reordered the options, this is more consistent
with things in src/bin/scripts.
We could have as well some basic TAP tests for both utilities while on
it. Something as simple as the first tests in 050_dropdb.pl would do a
fine first shot.
--
Michael
On 2018/08/20 13:54, Michael Paquier wrote:
On Mon, Aug 20, 2018 at 12:30:29PM +0900, Tatsuro Yamada wrote:
vacuumlo:
Document
- Add long options
- Add environment sectionLet's keep things simple by not adding long options where it is not
especially obvious, so I would suggest to keep the patch simple and just
add long options for connection options.
Okay.
oid2name:
Document
- Add long options
- Add environment section
- Remove deprecated and unhandled option "-P password"Is this a good idea? I doubt that it is used but keeping it would not
cause any breakage, and removing it could.
Yeah, why I remove that code is that there is no code to handle "-P" option,
and it caused error when executing the command with the option like this:
$ oid2name -P hoge
oid2name: invalid option -- 'P'
Therefore, "-P" is a manual bag. I investigated more using git log command and
understood followings:
1. -P option was removed on 4192f2d85
2. -P option revived in only the manual on 2963d8228
So, we have 2 options, remove -P option from the manual or revive the code
regarding to -P option (I mean it is like a git revert 4192f2d85).
oid2name supports also PGDATABASE.
As far as I know, this environment variable is also unused because
I could not get the results as I expected. So, I didn't add it to the manual.
For example, following command expected that it shows about "postgres", but
it couldn't.
$ env |grep PG
...
PGDATABASE=postgres
...
$ oid2name
All databases:
Oid Database Name Tablespace
----------------------------------
16392 hogedb pg_default
13310 postgres pg_default
13309 template0 pg_default
1 template1 pg_default
$ oid2name -d postgres
From database "postgres":
Filenode Table Name
----------------------
16388 t1
Code
- Revive handling "-H host" option silentlyI didn't add "-H" to the help message because it's a deprecated
option.It seems to me that this should be still documented in both --help and
in the docs, and that we should just mark it as deprecated in both.I guess that that means "silently" as you said on previous email.
Should I add it? For example,[...]
Let's use a different line for that. See for example how pg_standby -k
is treated.
I will do that.
I can see why you have reordered the options, this is more consistent
with things in src/bin/scripts.We could have as well some basic TAP tests for both utilities while on
it. Something as simple as the first tests in 050_dropdb.pl would do a
fine first shot.
For now, I'm not sure about TAP test but I knew both utilities have no
regression tests. It would be better to use something tests.
Regards,
Tatsuro Yamada
On Mon, Aug 20, 2018 at 03:51:07PM +0900, Tatsuro Yamada wrote:
On 2018/08/20 13:54, Michael Paquier wrote:
Therefore, "-P" is a manual bag. I investigated more using git log command and
understood followings:1. -P option was removed on 4192f2d85
2. -P option revived in only the manual on 2963d8228
Bruce did that to keep a trace of it in the docs, let's nuke it then, we
don't handle it and the documentation is mentioning the thing as
deprecated since 2010.
oid2name supports also PGDATABASE.
As far as I know, this environment variable is also unused because
I could not get the results as I expected. So, I didn't add it to the manual.
For example, following command expected that it shows about "postgres", but
it couldn't.
Yep, you're right.
For now, I'm not sure about TAP test but I knew both utilities have no
regression tests. It would be better to use something tests.
If you don't add them, I think that I would just that myself, just to
have some basics. Not that it is a barrier for this patch anyway.
--
Michael
On 2018/08/20 17:38, Michael Paquier wrote:
On Mon, Aug 20, 2018 at 03:51:07PM +0900, Tatsuro Yamada wrote:
On 2018/08/20 13:54, Michael Paquier wrote:
Therefore, "-P" is a manual bag. I investigated more using git log command and
understood followings:1. -P option was removed on 4192f2d85
2. -P option revived in only the manual on 2963d8228Bruce did that to keep a trace of it in the docs, let's nuke it then, we
don't handle it and the documentation is mentioning the thing as
deprecated since 2010.
Yep, right.
I see, and will remove -P option's explanation from the manual.
For now, I'm not sure about TAP test but I knew both utilities have no
regression tests. It would be better to use something tests.If you don't add them, I think that I would just that myself, just to
have some basics. Not that it is a barrier for this patch anyway.
Hmm...
As long as I've come this far, I'll do it through.
BTW, can I add the patch to the Commitfest September?
The patch includes improvements and bug fix as you know, So, I can divide the
patch into 2 patches for that.
Which one is better to create, 2 patches or 1 patch?
I summed up fixes of oid2name and vacuumlo so far, the next patch will include
following stuffs:
oid2name
bug fix
- Remove "-P password" option from the document
improvements
- Divide "Options section" into "Options" and "Connection Options" sections in
the help message (--help)
- Add long options only for Connection options (-d, -H, -h, -p and -U)
- Add "-H host" and "-h host" options to the help message and the document
- Add environment variable (PGHOST, PGPORT and PGUSER) to the document
- Add TAP tests for checking command-line options
vacuumlo
improvements
- Add long options only for Connection options (-h, -p and -U)
- Add environment variable (PGHOST, PGPORT and PGUSER) to the document
- Add TAP tests for checking command-line options
Thanks,
Tatsuro Yamada
On Tue, Aug 21, 2018 at 12:26:15PM +0900, Tatsuro Yamada wrote:
BTW, can I add the patch to the Commitfest September?
You should.
The patch includes improvements and bug fix as you know, So, I can divide the
patch into 2 patches for that.
I am not really seeing any bug fix, but if you think so then splitting
into two patches would help in making the difference for sure.
--
Michael
On 2018/08/21 12:40, Michael Paquier wrote:
On Tue, Aug 21, 2018 at 12:26:15PM +0900, Tatsuro Yamada wrote:
BTW, can I add the patch to the Commitfest September?
You should.
Thanks, I'll do that.
The patch includes improvements and bug fix as you know, So, I can divide the
patch into 2 patches for that.I am not really seeing any bug fix, but if you think so then splitting
into two patches would help in making the difference for sure.
Yep, I meant the bug fix is below:
oid2name
- Remove "-P password" option from the document
As I wrote before, "-P option" is not works well because there is no code to handle
that option in the code. So, it will be removed on next patch.
I'll send 2 patches in this week, probably.
Regards,
Tatsuro Yamada
On 2018/08/21 12:57, Tatsuro Yamada wrote:
On 2018/08/21 12:40, Michael Paquier wrote:
On Tue, Aug 21, 2018 at 12:26:15PM +0900, Tatsuro Yamada wrote:
BTW, can I add the patch to the Commitfest September?
You should.
Thanks, I'll do that.
I'll send 2 patches in this week, probably.
I revised the patch and created new tap tests.
fix_oid2name_wip3.patch:
bug fix
- Remove "-P password" option from the document
improvements
- Divide "Options section" into "Options" and "Connection Options" sections in
the help message (--help)
- Add long options
- Add "-H host" and "-h host" options to the help message and the document
- Add environment variable (PGHOST, PGPORT and PGUSER) to the document
fix_vacuumlo_wip3.patch:
improvements
- Add long options
- Add environment variable (PGHOST, PGPORT and PGUSER) to the document
Regarding to Long options,
I read the following both codes and I understand meanings of short options, so I
leave all long options in patches not only for connection options.
oid2name.c
/* these are the opts structures for command line params */
struct options
{
eary *tables;
eary *oids;
eary *filenodes;
bool quiet;
bool systables;
bool indexes;
bool nodb;
bool extended;
bool tablespaces;
char *dbname;
char *hostname;
char *port;
char *username;
const char *progname;
};
vacuumlo.c
struct _param
{
char *pg_user;
enum trivalue pg_prompt;
char *pg_port;
char *pg_host;
const char *progname;
int verbose;
int dry_run;
long transaction_limit;
};
Following TAP tests is for checking command-line options but I coudn't add some
test cases such as it is required argument and mixed varaiety of options.
I'm not sure about naming rule of tap test, so I added 300 and 301 to names as
temporarily. Please rename these files to more suitable names.
300_oid2name.pl
301_vacuumlo.pl
Please find attached files.
Thanks,
Tatsuro Yamada
Attachments:
fix_vacuumlo_wip3.patchtext/x-patch; name=fix_vacuumlo_wip3.patchDownload
diff --git a/contrib/vacuumlo/vacuumlo.c b/contrib/vacuumlo/vacuumlo.c
index 7eb474ca3e..bcd7c1c90b 100644
--- a/contrib/vacuumlo/vacuumlo.c
+++ b/contrib/vacuumlo/vacuumlo.c
@@ -434,17 +434,17 @@ usage(const char *progname)
printf("%s removes unreferenced large objects from databases.\n\n", progname);
printf("Usage:\n %s [OPTION]... DBNAME...\n\n", progname);
printf("Options:\n");
- printf(" -l LIMIT commit after removing each LIMIT large objects\n");
- printf(" -n don't remove large objects, just show what would be done\n");
- printf(" -v write a lot of progress messages\n");
- printf(" -V, --version output version information, then exit\n");
- printf(" -?, --help show this help, then exit\n");
+ printf(" -l, --limit=LIMIT commit after removing each LIMIT large objects\n");
+ printf(" -n, --dry-run don't remove large objects, just show what would be done\n");
+ printf(" -v, --verbose write a lot of progress messages\n");
+ printf(" -V, --version output version information, then exit\n");
+ printf(" -?, --help show this help, then exit\n");
printf("\nConnection options:\n");
- printf(" -h HOSTNAME database server host or socket directory\n");
- printf(" -p PORT database server port\n");
- printf(" -U USERNAME user name to connect as\n");
- printf(" -w never prompt for password\n");
- printf(" -W force password prompt\n");
+ printf(" -h, --host=HOSTNAME database server host or socket directory\n");
+ printf(" -p, --port=PORT database server port\n");
+ printf(" -U, --username=USERNAME user name to connect as\n");
+ printf(" -w, --no-password never prompt for password\n");
+ printf(" -W, --password force password prompt\n");
printf("\n");
printf("Report bugs to <pgsql-bugs@postgresql.org>.\n");
}
@@ -453,11 +453,24 @@ usage(const char *progname)
int
main(int argc, char **argv)
{
+ static struct option long_options[] = {
+ {"host", required_argument, NULL, 'h'},
+ {"limit", required_argument, NULL, 'l'},
+ {"username", required_argument, NULL, 'U'},
+ {"port", required_argument, NULL, 'p'},
+ {"verbose", no_argument, NULL, 'v'},
+ {"dry-run", no_argument, NULL, 'n'},
+ {"no-password", no_argument, NULL, 'w'},
+ {"password", no_argument, NULL, 'W'},
+ {NULL, 0, NULL, 0}
+ };
+
int rc = 0;
struct _param param;
int c;
int port;
const char *progname;
+ int optindex;
progname = get_progname(argv[0]);
@@ -486,25 +499,14 @@ main(int argc, char **argv)
}
}
- while (1)
+ while((c = getopt_long(argc, argv, "h:l:U:p:vnwW", long_options, &optindex)) != -1)
{
- c = getopt(argc, argv, "h:l:U:p:vnwW");
- if (c == -1)
- break;
-
switch (c)
{
- case '?':
- fprintf(stderr, _("Try \"%s --help\" for more information.\n"), progname);
- exit(1);
case ':':
exit(1);
- case 'v':
- param.verbose = 1;
- break;
- case 'n':
- param.dry_run = 1;
- param.verbose = 1;
+ case 'h':
+ param.pg_host = pg_strdup(optarg);
break;
case 'l':
param.transaction_limit = strtol(optarg, NULL, 10);
@@ -519,12 +521,6 @@ main(int argc, char **argv)
case 'U':
param.pg_user = pg_strdup(optarg);
break;
- case 'w':
- param.pg_prompt = TRI_NO;
- break;
- case 'W':
- param.pg_prompt = TRI_YES;
- break;
case 'p':
port = strtol(optarg, NULL, 10);
if ((port < 1) || (port > 65535))
@@ -534,8 +530,18 @@ main(int argc, char **argv)
}
param.pg_port = pg_strdup(optarg);
break;
- case 'h':
- param.pg_host = pg_strdup(optarg);
+ case 'v':
+ param.verbose = 1;
+ break;
+ case 'n':
+ param.dry_run = 1;
+ param.verbose = 1;
+ break;
+ case 'w':
+ param.pg_prompt = TRI_NO;
+ break;
+ case 'W':
+ param.pg_prompt = TRI_YES;
break;
}
}
diff --git a/doc/src/sgml/vacuumlo.sgml b/doc/src/sgml/vacuumlo.sgml
index 0b4dfc2b17..e46c27030b 100644
--- a/doc/src/sgml/vacuumlo.sgml
+++ b/doc/src/sgml/vacuumlo.sgml
@@ -55,10 +55,11 @@
<variablelist>
<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>
<para>
- Remove no more than <replaceable>limit</replaceable> large objects per
+ Remove no more than <replaceable class="parameter">limit</replaceable> large objects per
transaction (default 1000). Since the server acquires a lock per LO
removed, removing too many LOs in one transaction risks exceeding
<xref linkend="guc-max-locks-per-transaction"/>. Set the limit to
@@ -68,21 +69,23 @@
</varlistentry>
<varlistentry>
- <term><option>-n</option></term>
+ <term><option>-n </option></term>
+ <term><option>--dry-run</option></term>
<listitem>
<para>Don't remove anything, just show what would be done.</para>
</listitem>
</varlistentry>
<varlistentry>
- <term><option>-v</option></term>
+ <term><option>-v </option></term>
+ <term><option>--verbose</option></term>
<listitem>
<para>Write a lot of progress messages.</para>
</listitem>
</varlistentry>
<varlistentry>
- <term><option>-V</option></term>
+ <term><option>-V </option></term>
<term><option>--version</option></term>
<listitem>
<para>
@@ -92,7 +95,7 @@
</varlistentry>
<varlistentry>
- <term><option>-?</option></term>
+ <term><option>-? </option></term>
<term><option>--help</option></term>
<listitem>
<para>
@@ -110,28 +113,31 @@
<variablelist>
<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>
<para>Database server's host.</para>
</listitem>
</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>
<para>Database server's port.</para>
</listitem>
</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>
<para>User name to connect as.</para>
</listitem>
</varlistentry>
<varlistentry>
- <term><option>-w</option></term>
+ <term><option>-w </option></term>
<term><option>--no-password</option></term>
<listitem>
<para>
@@ -145,7 +151,8 @@
</varlistentry>
<varlistentry>
- <term><option>-W</option></term>
+ <term><option>-W </option></term>
+ <term><option>--passowrd</option></term>
<listitem>
<para>
Force <application>vacuumlo</application> to prompt for a
@@ -167,6 +174,30 @@
</para>
</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>
<title>Notes</title>
fix_oid2name_wip3.patchtext/x-patch; name=fix_oid2name_wip3.patchDownload
diff --git a/contrib/oid2name/oid2name.c b/contrib/oid2name/oid2name.c
index 63e360c4c5..2779af78e8 100644
--- a/contrib/oid2name/oid2name.c
+++ b/contrib/oid2name/oid2name.c
@@ -60,8 +60,26 @@ void sql_exec_dumpalltbspc(PGconn *, struct options *);
void
get_opts(int argc, char **argv, struct options *my_opts)
{
+ static struct option long_options[] = {
+ {"host", required_argument, NULL, 'h'},
+ {"host", required_argument, NULL, 'H'}, /* deprecated */
+ {"port", required_argument, NULL, 'p'},
+ {"username", required_argument, NULL, 'U'},
+ {"dbname", required_argument, NULL, 'd'},
+ {"table", required_argument, NULL, 't'},
+ {"oid", required_argument, NULL, 'o'},
+ {"filenode", required_argument, NULL, 'f'},
+ {"quiet", no_argument, NULL, 'q'},
+ {"systable", no_argument, NULL, 'S'},
+ {"extended", no_argument, NULL, 'x'},
+ {"index", no_argument, NULL, 'i'},
+ {"tablespace", no_argument, NULL, 's'},
+ {NULL, 0, NULL, 0}
+ };
+
int c;
const char *progname;
+ int optindex;
progname = get_progname(argv[0]);
@@ -93,10 +111,30 @@ get_opts(int argc, char **argv, struct options *my_opts)
}
/* get opts */
- while ((c = getopt(argc, argv, "H:p:U:d:t:o:f:qSxish")) != -1)
+ while ((c = getopt_long(argc, argv, "h:H:p:U:d:t:o:f:qSxis", long_options, &optindex)) != -1)
{
switch (c)
{
+ /* host to connect to */
+ case 'h':
+ my_opts->hostname = pg_strdup(optarg);
+ break;
+
+ /* (deprecated) host to connect to */
+ case 'H':
+ my_opts->hostname = pg_strdup(optarg);
+ break;
+
+ /* port to connect to on remote host */
+ case 'p':
+ my_opts->port = pg_strdup(optarg);
+ break;
+
+ /* username */
+ case 'U':
+ my_opts->username = pg_strdup(optarg);
+ break;
+
/* specify the database */
case 'd':
my_opts->dbname = pg_strdup(optarg);
@@ -122,46 +160,26 @@ get_opts(int argc, char **argv, struct options *my_opts)
my_opts->quiet = true;
break;
- /* host to connect to */
- case 'H':
- my_opts->hostname = pg_strdup(optarg);
- break;
-
- /* port to connect to on remote host */
- case 'p':
- my_opts->port = pg_strdup(optarg);
- break;
-
- /* username */
- case 'U':
- my_opts->username = pg_strdup(optarg);
- break;
-
/* display system tables */
case 'S':
my_opts->systables = true;
break;
- /* also display indexes */
- case 'i':
- my_opts->indexes = true;
- break;
-
/* display extra columns */
case 'x':
my_opts->extended = true;
break;
+ /* also display indexes */
+ case 'i':
+ my_opts->indexes = true;
+ break;
+
/* dump tablespaces only */
case 's':
my_opts->tablespaces = true;
break;
- case 'h':
- help(progname);
- exit(0);
- break;
-
default:
fprintf(stderr, _("Try \"%s --help\" for more information.\n"), progname);
exit(1);
@@ -176,20 +194,22 @@ help(const char *progname)
"Usage:\n"
" %s [OPTION]...\n"
"\nOptions:\n"
- " -d DBNAME database to connect to\n"
- " -f FILENODE show info for table with given file node\n"
- " -H HOSTNAME database server host or socket directory\n"
- " -i show indexes and sequences too\n"
- " -o OID show info for table with given OID\n"
- " -p PORT database server port number\n"
- " -q quiet (don't show headers)\n"
- " -s show all tablespaces\n"
- " -S show system objects too\n"
- " -t TABLE show info for named table\n"
- " -U NAME connect as specified database user\n"
- " -V, --version output version information, then exit\n"
- " -x extended (show additional columns)\n"
- " -?, --help show this help, then exit\n"
+ " -f, --filenode FILENODE show info for table with given file node\n"
+ " -i, --index show indexes and sequences too\n"
+ " -o, --oid=OID show info for table with given OID\n"
+ " -q, --quiet quiet (don't show headers)\n"
+ " -s, --tablespace show all tablespaces\n"
+ " -S, --systable show system objects too\n"
+ " -t, --table=TABLE show info for named table\n"
+ " -V, --version output version information, then exit\n"
+ " -x, --extended extended (show additional columns)\n"
+ " -?, --help show this help, then exit\n"
+ "\nConnection options:\n"
+ " -d, --dbname=DBNAME database to connect to\n"
+ " -h, --host=HOSTNAME database server host or socket directory\n"
+ " -H is same as -h but deprecated\n"
+ " -p, --port=PORT database server port number\n"
+ " -U, --username=USERNAME connect as specified database user\n"
"\nThe default action is to show all database OIDs.\n\n"
"Report bugs to <pgsql-bugs@postgresql.org>.\n",
progname, progname);
diff --git a/doc/src/sgml/oid2name.sgml b/doc/src/sgml/oid2name.sgml
index dd875281c8..ae68828abb 100644
--- a/doc/src/sgml/oid2name.sgml
+++ b/doc/src/sgml/oid2name.sgml
@@ -60,45 +60,52 @@
<variablelist>
<varlistentry>
- <term><option>-f</option> <replaceable>filenode</replaceable></term>
- <listitem><para>show info for table with filenode <replaceable>filenode</replaceable></para></listitem>
+ <term><option>-f <replaceable class="parameter">filenode</replaceable></option></term>
+ <term><option>--filenode=<replaceable class="parameter">filenode</replaceable></option></term>
+ <listitem><para>show info for table with filenode <replaceable class="parameter">filenode</replaceable>.</para></listitem>
</varlistentry>
<varlistentry>
- <term><option>-i</option></term>
- <listitem><para>include indexes and sequences in the listing</para></listitem>
+ <term><option>-i </option></term>
+ <term><option>--index</option></term>
+ <listitem><para>include indexes and sequences in the listing.</para></listitem>
</varlistentry>
<varlistentry>
- <term><option>-o</option> <replaceable>oid</replaceable></term>
- <listitem><para>show info for table with OID <replaceable>oid</replaceable></para></listitem>
+ <term><option>-o <replaceable class="parameter">oid</replaceable></option></term>
+ <term><option>--oid=<replaceable class="parameter">oid</replaceable></option></term>
+ <listitem><para>show info for table with OID <replaceable class="parameter">oid</replaceable>.</para></listitem>
</varlistentry>
<varlistentry>
- <term><option>-q</option></term>
- <listitem><para>omit headers (useful for scripting)</para></listitem>
+ <term><option>-q </option></term>
+ <term><option>--quiet</option></term>
+ <listitem><para>omit headers (useful for scripting).</para></listitem>
</varlistentry>
<varlistentry>
- <term><option>-s</option></term>
- <listitem><para>show tablespace OIDs</para></listitem>
+ <term><option>-s </option></term>
+ <term><option>--tablespac</option></term>
+ <listitem><para>show tablespace OIDs.</para></listitem>
</varlistentry>
<varlistentry>
- <term><option>-S</option></term>
+ <term><option>-S </option></term>
+ <term><option>--system</option></term>
<listitem><para>include system objects (those in
<option>information_schema</option>, <option>pg_toast</option>
- and <option>pg_catalog</option> schemas)
+ and <option>pg_catalog</option> schemas).
</para></listitem>
</varlistentry>
<varlistentry>
- <term><option>-t</option> <replaceable>tablename_pattern</replaceable></term>
- <listitem><para>show info for table(s) matching <replaceable>tablename_pattern</replaceable></para></listitem>
+ <term><option>-t <replaceable class="parameter">tablename_pattern</replaceable></option></term>
+ <term><option>--tablename=<replaceable class="parameter">tablename_pattern</replaceable></option></term>
+ <listitem><para>show info for table(s) matching <replaceable class="parameter">tablename_pattern</replaceable>.</para></listitem>
</varlistentry>
<varlistentry>
- <term><option>-V</option></term>
+ <term><option>-V </option></term>
<term><option>--version</option></term>
<listitem>
<para>
@@ -108,14 +115,15 @@
</varlistentry>
<varlistentry>
- <term><option>-x</option></term>
+ <term><option>-x </option></term>
+ <term><option>--extended</option></term>
<listitem><para>display more information about each object shown: tablespace name,
- schema name, and OID
+ schema name, and OID.
</para></listitem>
</varlistentry>
<varlistentry>
- <term><option>-?</option></term>
+ <term><option>-? </option></term>
<term><option>--help</option></term>
<listitem>
<para>
@@ -133,29 +141,27 @@
<variablelist>
<varlistentry>
- <term><option>-d</option> <replaceable>database</replaceable></term>
- <listitem><para>database to connect to</para></listitem>
+ <term><option>-d <replaceable>database</replaceable></option></term>
+ <term><option>--dbname=<replaceable class="parameter">database</replaceable></option></term>
+ <listitem><para>database to connect to.</para></listitem>
</varlistentry>
<varlistentry>
- <term><option>-H</option> <replaceable>host</replaceable></term>
- <listitem><para>database server's host</para></listitem>
+ <term><option>-h <replaceable class="parameter">host</replaceable></option></term>
+ <term><option>--host=<replaceable class="parameter">host</replaceable></option></term>
+ <listitem><para>database server's host. -H is also able to use instead -h, however it's a deprecated option.</para></listitem>
</varlistentry>
<varlistentry>
- <term><option>-p</option> <replaceable>port</replaceable></term>
- <listitem><para>database server's port</para></listitem>
+ <term><option>-p <replaceable>port</replaceable></option></term>
+ <term><option>--port=<replaceable class="parameter">port</replaceable></option></term>
+ <listitem><para>database server's port.</para></listitem>
</varlistentry>
<varlistentry>
- <term><option>-U</option> <replaceable>username</replaceable></term>
- <listitem><para>user name to connect as</para></listitem>
- </varlistentry>
-
- <varlistentry>
- <term><option>-P</option> <replaceable>password</replaceable></term>
- <listitem><para>password (deprecated — putting this on the command line
- is a security hazard)</para></listitem>
+ <term><option>-U <replaceable>username</replaceable></option></term>
+ <term><option>--username=<replaceable class="parameter">username</replaceable></option></term>
+ <listitem><para>user name to connect as.</para></listitem>
</varlistentry>
</variablelist>
@@ -188,6 +194,30 @@
</para>
</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>
<title>Notes</title>
On 2018/08/21 12:57, Tatsuro Yamada wrote:
On 2018/08/21 12:40, Michael Paquier wrote:
On Tue, Aug 21, 2018 at 12:26:15PM +0900, Tatsuro Yamada wrote:
BTW, can I add the patch to the Commitfest September?
You should.
Thanks, I'll do that.
I'll send 2 patches in this week, probably.
(I resend this email because I forgot to mark CC on my previous email. Sorry.)
I revised the patch and created new tap tests.
fix_oid2name_wip3.patch:
bug fix
- Remove "-P password" option from the document
improvements
- Divide "Options section" into "Options" and "Connection Options" sections in
the help message (--help)
- Add long options
- Add "-H host" and "-h host" options to the help message and the document
- Add environment variable (PGHOST, PGPORT and PGUSER) to the document
fix_vacuumlo_wip3.patch:
improvements
- Add long options
- Add environment variable (PGHOST, PGPORT and PGUSER) to the document
Regarding to Long options,
I read the following both codes and I understand meanings of short options, so I
leave all long options in patches not only for connection options.
oid2name.c
/* these are the opts structures for command line params */
struct options
{
eary *tables;
eary *oids;
eary *filenodes;
bool quiet;
bool systables;
bool indexes;
bool nodb;
bool extended;
bool tablespaces;
char *dbname;
char *hostname;
char *port;
char *username;
const char *progname;
};
vacuumlo.c
struct _param
{
char *pg_user;
enum trivalue pg_prompt;
char *pg_port;
char *pg_host;
const char *progname;
int verbose;
int dry_run;
long transaction_limit;
};
Following TAP tests is for checking command-line options but I coudn't add some
test cases such as it is required argument and mixed varaiety of options.
I'm not sure about naming rule of tap test, so I added 300 and 301 to names as
temporarily. Please rename these files to more suitable names.
300_oid2name.pl
301_vacuumlo.pl
Please find attached files.
Thanks,
Tatsuro Yamada
Attachments:
fix_oid2name_wip3.patchtext/x-patch; name=fix_oid2name_wip3.patchDownload
diff --git a/contrib/oid2name/oid2name.c b/contrib/oid2name/oid2name.c
index 63e360c4c5..2779af78e8 100644
--- a/contrib/oid2name/oid2name.c
+++ b/contrib/oid2name/oid2name.c
@@ -60,8 +60,26 @@ void sql_exec_dumpalltbspc(PGconn *, struct options *);
void
get_opts(int argc, char **argv, struct options *my_opts)
{
+ static struct option long_options[] = {
+ {"host", required_argument, NULL, 'h'},
+ {"host", required_argument, NULL, 'H'}, /* deprecated */
+ {"port", required_argument, NULL, 'p'},
+ {"username", required_argument, NULL, 'U'},
+ {"dbname", required_argument, NULL, 'd'},
+ {"table", required_argument, NULL, 't'},
+ {"oid", required_argument, NULL, 'o'},
+ {"filenode", required_argument, NULL, 'f'},
+ {"quiet", no_argument, NULL, 'q'},
+ {"systable", no_argument, NULL, 'S'},
+ {"extended", no_argument, NULL, 'x'},
+ {"index", no_argument, NULL, 'i'},
+ {"tablespace", no_argument, NULL, 's'},
+ {NULL, 0, NULL, 0}
+ };
+
int c;
const char *progname;
+ int optindex;
progname = get_progname(argv[0]);
@@ -93,10 +111,30 @@ get_opts(int argc, char **argv, struct options *my_opts)
}
/* get opts */
- while ((c = getopt(argc, argv, "H:p:U:d:t:o:f:qSxish")) != -1)
+ while ((c = getopt_long(argc, argv, "h:H:p:U:d:t:o:f:qSxis", long_options, &optindex)) != -1)
{
switch (c)
{
+ /* host to connect to */
+ case 'h':
+ my_opts->hostname = pg_strdup(optarg);
+ break;
+
+ /* (deprecated) host to connect to */
+ case 'H':
+ my_opts->hostname = pg_strdup(optarg);
+ break;
+
+ /* port to connect to on remote host */
+ case 'p':
+ my_opts->port = pg_strdup(optarg);
+ break;
+
+ /* username */
+ case 'U':
+ my_opts->username = pg_strdup(optarg);
+ break;
+
/* specify the database */
case 'd':
my_opts->dbname = pg_strdup(optarg);
@@ -122,46 +160,26 @@ get_opts(int argc, char **argv, struct options *my_opts)
my_opts->quiet = true;
break;
- /* host to connect to */
- case 'H':
- my_opts->hostname = pg_strdup(optarg);
- break;
-
- /* port to connect to on remote host */
- case 'p':
- my_opts->port = pg_strdup(optarg);
- break;
-
- /* username */
- case 'U':
- my_opts->username = pg_strdup(optarg);
- break;
-
/* display system tables */
case 'S':
my_opts->systables = true;
break;
- /* also display indexes */
- case 'i':
- my_opts->indexes = true;
- break;
-
/* display extra columns */
case 'x':
my_opts->extended = true;
break;
+ /* also display indexes */
+ case 'i':
+ my_opts->indexes = true;
+ break;
+
/* dump tablespaces only */
case 's':
my_opts->tablespaces = true;
break;
- case 'h':
- help(progname);
- exit(0);
- break;
-
default:
fprintf(stderr, _("Try \"%s --help\" for more information.\n"), progname);
exit(1);
@@ -176,20 +194,22 @@ help(const char *progname)
"Usage:\n"
" %s [OPTION]...\n"
"\nOptions:\n"
- " -d DBNAME database to connect to\n"
- " -f FILENODE show info for table with given file node\n"
- " -H HOSTNAME database server host or socket directory\n"
- " -i show indexes and sequences too\n"
- " -o OID show info for table with given OID\n"
- " -p PORT database server port number\n"
- " -q quiet (don't show headers)\n"
- " -s show all tablespaces\n"
- " -S show system objects too\n"
- " -t TABLE show info for named table\n"
- " -U NAME connect as specified database user\n"
- " -V, --version output version information, then exit\n"
- " -x extended (show additional columns)\n"
- " -?, --help show this help, then exit\n"
+ " -f, --filenode FILENODE show info for table with given file node\n"
+ " -i, --index show indexes and sequences too\n"
+ " -o, --oid=OID show info for table with given OID\n"
+ " -q, --quiet quiet (don't show headers)\n"
+ " -s, --tablespace show all tablespaces\n"
+ " -S, --systable show system objects too\n"
+ " -t, --table=TABLE show info for named table\n"
+ " -V, --version output version information, then exit\n"
+ " -x, --extended extended (show additional columns)\n"
+ " -?, --help show this help, then exit\n"
+ "\nConnection options:\n"
+ " -d, --dbname=DBNAME database to connect to\n"
+ " -h, --host=HOSTNAME database server host or socket directory\n"
+ " -H is same as -h but deprecated\n"
+ " -p, --port=PORT database server port number\n"
+ " -U, --username=USERNAME connect as specified database user\n"
"\nThe default action is to show all database OIDs.\n\n"
"Report bugs to <pgsql-bugs@postgresql.org>.\n",
progname, progname);
diff --git a/doc/src/sgml/oid2name.sgml b/doc/src/sgml/oid2name.sgml
index dd875281c8..ae68828abb 100644
--- a/doc/src/sgml/oid2name.sgml
+++ b/doc/src/sgml/oid2name.sgml
@@ -60,45 +60,52 @@
<variablelist>
<varlistentry>
- <term><option>-f</option> <replaceable>filenode</replaceable></term>
- <listitem><para>show info for table with filenode <replaceable>filenode</replaceable></para></listitem>
+ <term><option>-f <replaceable class="parameter">filenode</replaceable></option></term>
+ <term><option>--filenode=<replaceable class="parameter">filenode</replaceable></option></term>
+ <listitem><para>show info for table with filenode <replaceable class="parameter">filenode</replaceable>.</para></listitem>
</varlistentry>
<varlistentry>
- <term><option>-i</option></term>
- <listitem><para>include indexes and sequences in the listing</para></listitem>
+ <term><option>-i </option></term>
+ <term><option>--index</option></term>
+ <listitem><para>include indexes and sequences in the listing.</para></listitem>
</varlistentry>
<varlistentry>
- <term><option>-o</option> <replaceable>oid</replaceable></term>
- <listitem><para>show info for table with OID <replaceable>oid</replaceable></para></listitem>
+ <term><option>-o <replaceable class="parameter">oid</replaceable></option></term>
+ <term><option>--oid=<replaceable class="parameter">oid</replaceable></option></term>
+ <listitem><para>show info for table with OID <replaceable class="parameter">oid</replaceable>.</para></listitem>
</varlistentry>
<varlistentry>
- <term><option>-q</option></term>
- <listitem><para>omit headers (useful for scripting)</para></listitem>
+ <term><option>-q </option></term>
+ <term><option>--quiet</option></term>
+ <listitem><para>omit headers (useful for scripting).</para></listitem>
</varlistentry>
<varlistentry>
- <term><option>-s</option></term>
- <listitem><para>show tablespace OIDs</para></listitem>
+ <term><option>-s </option></term>
+ <term><option>--tablespac</option></term>
+ <listitem><para>show tablespace OIDs.</para></listitem>
</varlistentry>
<varlistentry>
- <term><option>-S</option></term>
+ <term><option>-S </option></term>
+ <term><option>--system</option></term>
<listitem><para>include system objects (those in
<option>information_schema</option>, <option>pg_toast</option>
- and <option>pg_catalog</option> schemas)
+ and <option>pg_catalog</option> schemas).
</para></listitem>
</varlistentry>
<varlistentry>
- <term><option>-t</option> <replaceable>tablename_pattern</replaceable></term>
- <listitem><para>show info for table(s) matching <replaceable>tablename_pattern</replaceable></para></listitem>
+ <term><option>-t <replaceable class="parameter">tablename_pattern</replaceable></option></term>
+ <term><option>--tablename=<replaceable class="parameter">tablename_pattern</replaceable></option></term>
+ <listitem><para>show info for table(s) matching <replaceable class="parameter">tablename_pattern</replaceable>.</para></listitem>
</varlistentry>
<varlistentry>
- <term><option>-V</option></term>
+ <term><option>-V </option></term>
<term><option>--version</option></term>
<listitem>
<para>
@@ -108,14 +115,15 @@
</varlistentry>
<varlistentry>
- <term><option>-x</option></term>
+ <term><option>-x </option></term>
+ <term><option>--extended</option></term>
<listitem><para>display more information about each object shown: tablespace name,
- schema name, and OID
+ schema name, and OID.
</para></listitem>
</varlistentry>
<varlistentry>
- <term><option>-?</option></term>
+ <term><option>-? </option></term>
<term><option>--help</option></term>
<listitem>
<para>
@@ -133,29 +141,27 @@
<variablelist>
<varlistentry>
- <term><option>-d</option> <replaceable>database</replaceable></term>
- <listitem><para>database to connect to</para></listitem>
+ <term><option>-d <replaceable>database</replaceable></option></term>
+ <term><option>--dbname=<replaceable class="parameter">database</replaceable></option></term>
+ <listitem><para>database to connect to.</para></listitem>
</varlistentry>
<varlistentry>
- <term><option>-H</option> <replaceable>host</replaceable></term>
- <listitem><para>database server's host</para></listitem>
+ <term><option>-h <replaceable class="parameter">host</replaceable></option></term>
+ <term><option>--host=<replaceable class="parameter">host</replaceable></option></term>
+ <listitem><para>database server's host. -H is also able to use instead -h, however it's a deprecated option.</para></listitem>
</varlistentry>
<varlistentry>
- <term><option>-p</option> <replaceable>port</replaceable></term>
- <listitem><para>database server's port</para></listitem>
+ <term><option>-p <replaceable>port</replaceable></option></term>
+ <term><option>--port=<replaceable class="parameter">port</replaceable></option></term>
+ <listitem><para>database server's port.</para></listitem>
</varlistentry>
<varlistentry>
- <term><option>-U</option> <replaceable>username</replaceable></term>
- <listitem><para>user name to connect as</para></listitem>
- </varlistentry>
-
- <varlistentry>
- <term><option>-P</option> <replaceable>password</replaceable></term>
- <listitem><para>password (deprecated — putting this on the command line
- is a security hazard)</para></listitem>
+ <term><option>-U <replaceable>username</replaceable></option></term>
+ <term><option>--username=<replaceable class="parameter">username</replaceable></option></term>
+ <listitem><para>user name to connect as.</para></listitem>
</varlistentry>
</variablelist>
@@ -188,6 +194,30 @@
</para>
</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>
<title>Notes</title>
fix_vacuumlo_wip3.patchtext/x-patch; name=fix_vacuumlo_wip3.patchDownload
diff --git a/contrib/vacuumlo/vacuumlo.c b/contrib/vacuumlo/vacuumlo.c
index 7eb474ca3e..bcd7c1c90b 100644
--- a/contrib/vacuumlo/vacuumlo.c
+++ b/contrib/vacuumlo/vacuumlo.c
@@ -434,17 +434,17 @@ usage(const char *progname)
printf("%s removes unreferenced large objects from databases.\n\n", progname);
printf("Usage:\n %s [OPTION]... DBNAME...\n\n", progname);
printf("Options:\n");
- printf(" -l LIMIT commit after removing each LIMIT large objects\n");
- printf(" -n don't remove large objects, just show what would be done\n");
- printf(" -v write a lot of progress messages\n");
- printf(" -V, --version output version information, then exit\n");
- printf(" -?, --help show this help, then exit\n");
+ printf(" -l, --limit=LIMIT commit after removing each LIMIT large objects\n");
+ printf(" -n, --dry-run don't remove large objects, just show what would be done\n");
+ printf(" -v, --verbose write a lot of progress messages\n");
+ printf(" -V, --version output version information, then exit\n");
+ printf(" -?, --help show this help, then exit\n");
printf("\nConnection options:\n");
- printf(" -h HOSTNAME database server host or socket directory\n");
- printf(" -p PORT database server port\n");
- printf(" -U USERNAME user name to connect as\n");
- printf(" -w never prompt for password\n");
- printf(" -W force password prompt\n");
+ printf(" -h, --host=HOSTNAME database server host or socket directory\n");
+ printf(" -p, --port=PORT database server port\n");
+ printf(" -U, --username=USERNAME user name to connect as\n");
+ printf(" -w, --no-password never prompt for password\n");
+ printf(" -W, --password force password prompt\n");
printf("\n");
printf("Report bugs to <pgsql-bugs@postgresql.org>.\n");
}
@@ -453,11 +453,24 @@ usage(const char *progname)
int
main(int argc, char **argv)
{
+ static struct option long_options[] = {
+ {"host", required_argument, NULL, 'h'},
+ {"limit", required_argument, NULL, 'l'},
+ {"username", required_argument, NULL, 'U'},
+ {"port", required_argument, NULL, 'p'},
+ {"verbose", no_argument, NULL, 'v'},
+ {"dry-run", no_argument, NULL, 'n'},
+ {"no-password", no_argument, NULL, 'w'},
+ {"password", no_argument, NULL, 'W'},
+ {NULL, 0, NULL, 0}
+ };
+
int rc = 0;
struct _param param;
int c;
int port;
const char *progname;
+ int optindex;
progname = get_progname(argv[0]);
@@ -486,25 +499,14 @@ main(int argc, char **argv)
}
}
- while (1)
+ while((c = getopt_long(argc, argv, "h:l:U:p:vnwW", long_options, &optindex)) != -1)
{
- c = getopt(argc, argv, "h:l:U:p:vnwW");
- if (c == -1)
- break;
-
switch (c)
{
- case '?':
- fprintf(stderr, _("Try \"%s --help\" for more information.\n"), progname);
- exit(1);
case ':':
exit(1);
- case 'v':
- param.verbose = 1;
- break;
- case 'n':
- param.dry_run = 1;
- param.verbose = 1;
+ case 'h':
+ param.pg_host = pg_strdup(optarg);
break;
case 'l':
param.transaction_limit = strtol(optarg, NULL, 10);
@@ -519,12 +521,6 @@ main(int argc, char **argv)
case 'U':
param.pg_user = pg_strdup(optarg);
break;
- case 'w':
- param.pg_prompt = TRI_NO;
- break;
- case 'W':
- param.pg_prompt = TRI_YES;
- break;
case 'p':
port = strtol(optarg, NULL, 10);
if ((port < 1) || (port > 65535))
@@ -534,8 +530,18 @@ main(int argc, char **argv)
}
param.pg_port = pg_strdup(optarg);
break;
- case 'h':
- param.pg_host = pg_strdup(optarg);
+ case 'v':
+ param.verbose = 1;
+ break;
+ case 'n':
+ param.dry_run = 1;
+ param.verbose = 1;
+ break;
+ case 'w':
+ param.pg_prompt = TRI_NO;
+ break;
+ case 'W':
+ param.pg_prompt = TRI_YES;
break;
}
}
diff --git a/doc/src/sgml/vacuumlo.sgml b/doc/src/sgml/vacuumlo.sgml
index 0b4dfc2b17..e46c27030b 100644
--- a/doc/src/sgml/vacuumlo.sgml
+++ b/doc/src/sgml/vacuumlo.sgml
@@ -55,10 +55,11 @@
<variablelist>
<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>
<para>
- Remove no more than <replaceable>limit</replaceable> large objects per
+ Remove no more than <replaceable class="parameter">limit</replaceable> large objects per
transaction (default 1000). Since the server acquires a lock per LO
removed, removing too many LOs in one transaction risks exceeding
<xref linkend="guc-max-locks-per-transaction"/>. Set the limit to
@@ -68,21 +69,23 @@
</varlistentry>
<varlistentry>
- <term><option>-n</option></term>
+ <term><option>-n </option></term>
+ <term><option>--dry-run</option></term>
<listitem>
<para>Don't remove anything, just show what would be done.</para>
</listitem>
</varlistentry>
<varlistentry>
- <term><option>-v</option></term>
+ <term><option>-v </option></term>
+ <term><option>--verbose</option></term>
<listitem>
<para>Write a lot of progress messages.</para>
</listitem>
</varlistentry>
<varlistentry>
- <term><option>-V</option></term>
+ <term><option>-V </option></term>
<term><option>--version</option></term>
<listitem>
<para>
@@ -92,7 +95,7 @@
</varlistentry>
<varlistentry>
- <term><option>-?</option></term>
+ <term><option>-? </option></term>
<term><option>--help</option></term>
<listitem>
<para>
@@ -110,28 +113,31 @@
<variablelist>
<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>
<para>Database server's host.</para>
</listitem>
</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>
<para>Database server's port.</para>
</listitem>
</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>
<para>User name to connect as.</para>
</listitem>
</varlistentry>
<varlistentry>
- <term><option>-w</option></term>
+ <term><option>-w </option></term>
<term><option>--no-password</option></term>
<listitem>
<para>
@@ -145,7 +151,8 @@
</varlistentry>
<varlistentry>
- <term><option>-W</option></term>
+ <term><option>-W </option></term>
+ <term><option>--passowrd</option></term>
<listitem>
<para>
Force <application>vacuumlo</application> to prompt for a
@@ -167,6 +174,30 @@
</para>
</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>
<title>Notes</title>
On Fri, Aug 24, 2018 at 01:32:47PM +0900, Tatsuro Yamada wrote:
I revised the patch and created new tap tests.
Thanks, I have looked at the patch set. And here are some notes about
issues found while reviewing. For oid2name:
- Documentation had some typos, --tablename was used instead of --table.
- Using plural forms for some options makes more sense to me, like
--indexes, --system-objects, --tablespaces
- I have tweaked the description of -H in usage().
- An '=' was missing for --filenode
- I have reordered the options in alphabetical order.
- Added some basic tap tests, and added correct handling of the tests in
oid2name/Makefile.
- Inclusion of getopt_long.h has been missing, this would have caused
failures on Windows.
- getopt_long() has been reordered to be alphabetical. Same thing for
long_options[]. This has the advantage to ease the review and code
read.
- Some formatting issues with option docs, leading to some noise diffs.
For vacuumlo:
- Some typos in documentation.
- Documentation format was rather weird for some options, so I made the
whole consistent.
- I agree with the option names you put.
- Reorganization of the options.
- Added basic TAP tests, and fixed Makefile.
- default clause was missing from the option set.
Attached are updated patches, which I would be fine to commit. What do
you think?
--
Michael
Attachments:
0001-Rework-option-set-of-oid2name.patchtext/x-diff; charset=us-asciiDownload
From 6f2a0931ddf9ab1b742d0bbc6bac3930d982b60b Mon Sep 17 00:00:00 2001
From: Michael Paquier <michael@paquier.xyz>
Date: Mon, 27 Aug 2018 19:00:51 +0900
Subject: [PATCH 1/2] Rework option set of oid2name
oid2name has done little effort to keep an interface consistent with
other binary utilities:
- -H was used instead of -h/-host. This option is now marked as
deprecated, still its output is accepted to be backward-compatible.
- -P has been removed from the code, and was still documented.
- All options gain long aliases, making connection options more similar
to other binaries.
- Document environment variables which could be used: PGHOST, PGPORT and
PGUSER.
A basic set of TAP tests is added on the way.
Author: Tatsuro Yamada
Reviewed-by: Michael Paquier
Discussion: https://postgr.es/m/c7e7f25c-1747-cd0f-9335-390bc97b2db5@lab.ntt.co.jp
---
contrib/oid2name/.gitignore | 2 +
contrib/oid2name/Makefile | 6 ++
contrib/oid2name/oid2name.c | 124 ++++++++++++++++++--------------
contrib/oid2name/t/001_basic.pl | 12 ++++
doc/src/sgml/oid2name.sgml | 81 +++++++++++++++------
5 files changed, 151 insertions(+), 74 deletions(-)
create mode 100644 contrib/oid2name/t/001_basic.pl
diff --git a/contrib/oid2name/.gitignore b/contrib/oid2name/.gitignore
index fdefde108d..0410fb7afa 100644
--- a/contrib/oid2name/.gitignore
+++ b/contrib/oid2name/.gitignore
@@ -1 +1,3 @@
/oid2name
+
+/tmp_check/
diff --git a/contrib/oid2name/Makefile b/contrib/oid2name/Makefile
index 3eef8f60be..77b72880f5 100644
--- a/contrib/oid2name/Makefile
+++ b/contrib/oid2name/Makefile
@@ -19,3 +19,9 @@ top_builddir = ../..
include $(top_builddir)/src/Makefile.global
include $(top_srcdir)/contrib/contrib-global.mk
endif
+
+check:
+ $(prove_check)
+
+installcheck:
+ $(prove_installcheck)
diff --git a/contrib/oid2name/oid2name.c b/contrib/oid2name/oid2name.c
index 63e360c4c5..aa122ca0e9 100644
--- a/contrib/oid2name/oid2name.c
+++ b/contrib/oid2name/oid2name.c
@@ -14,6 +14,8 @@
#include "fe_utils/connect.h"
#include "libpq-fe.h"
#include "pg_getopt.h"
+#include "getopt_long.h"
+
/* an extensible array to keep track of elements to show */
typedef struct
@@ -60,8 +62,28 @@ void sql_exec_dumpalltbspc(PGconn *, struct options *);
void
get_opts(int argc, char **argv, struct options *my_opts)
{
+ static struct option long_options[] = {
+ {"dbname", required_argument, NULL, 'd'},
+ {"host", required_argument, NULL, 'h'},
+ {"host", required_argument, NULL, 'H'}, /* deprecated */
+ {"filenode", required_argument, NULL, 'f'},
+ {"indexes", no_argument, NULL, 'i'},
+ {"oid", required_argument, NULL, 'o'},
+ {"port", required_argument, NULL, 'p'},
+ {"quiet", no_argument, NULL, 'q'},
+ {"tablespaces", no_argument, NULL, 's'},
+ {"system-objects", no_argument, NULL, 'S'},
+ {"table", required_argument, NULL, 't'},
+ {"username", required_argument, NULL, 'U'},
+ {"version", no_argument, NULL, 'V'},
+ {"extended", no_argument, NULL, 'x'},
+ {"help", no_argument, NULL, '?'},
+ {NULL, 0, NULL, 0}
+ };
+
int c;
const char *progname;
+ int optindex;
progname = get_progname(argv[0]);
@@ -93,7 +115,7 @@ get_opts(int argc, char **argv, struct options *my_opts)
}
/* get opts */
- while ((c = getopt(argc, argv, "H:p:U:d:t:o:f:qSxish")) != -1)
+ while ((c = getopt_long(argc, argv, "d:f:h:H:io:p:qsSt:U:x", long_options, &optindex)) != -1)
{
switch (c)
{
@@ -102,54 +124,35 @@ get_opts(int argc, char **argv, struct options *my_opts)
my_opts->dbname = pg_strdup(optarg);
break;
- /* specify one tablename to show */
- case 't':
- add_one_elt(optarg, my_opts->tables);
- break;
-
- /* specify one Oid to show */
- case 'o':
- add_one_elt(optarg, my_opts->oids);
- break;
-
/* specify one filenode to show */
case 'f':
add_one_elt(optarg, my_opts->filenodes);
break;
- /* don't show headers */
- case 'q':
- my_opts->quiet = true;
- break;
-
/* host to connect to */
- case 'H':
+ case 'H': /* deprecated */
+ case 'h':
my_opts->hostname = pg_strdup(optarg);
break;
- /* port to connect to on remote host */
- case 'p':
- my_opts->port = pg_strdup(optarg);
- break;
-
- /* username */
- case 'U':
- my_opts->username = pg_strdup(optarg);
- break;
-
- /* display system tables */
- case 'S':
- my_opts->systables = true;
- break;
-
/* also display indexes */
case 'i':
my_opts->indexes = true;
break;
- /* display extra columns */
- case 'x':
- my_opts->extended = true;
+ /* specify one Oid to show */
+ case 'o':
+ add_one_elt(optarg, my_opts->oids);
+ break;
+
+ /* port to connect to on remote host */
+ case 'p':
+ my_opts->port = pg_strdup(optarg);
+ break;
+
+ /* don't show headers */
+ case 'q':
+ my_opts->quiet = true;
break;
/* dump tablespaces only */
@@ -157,9 +160,24 @@ get_opts(int argc, char **argv, struct options *my_opts)
my_opts->tablespaces = true;
break;
- case 'h':
- help(progname);
- exit(0);
+ /* display system tables */
+ case 'S':
+ my_opts->systables = true;
+ break;
+
+ /* specify one tablename to show */
+ case 't':
+ add_one_elt(optarg, my_opts->tables);
+ break;
+
+ /* username */
+ case 'U':
+ my_opts->username = pg_strdup(optarg);
+ break;
+
+ /* display extra columns */
+ case 'x':
+ my_opts->extended = true;
break;
default:
@@ -176,20 +194,22 @@ help(const char *progname)
"Usage:\n"
" %s [OPTION]...\n"
"\nOptions:\n"
- " -d DBNAME database to connect to\n"
- " -f FILENODE show info for table with given file node\n"
- " -H HOSTNAME database server host or socket directory\n"
- " -i show indexes and sequences too\n"
- " -o OID show info for table with given OID\n"
- " -p PORT database server port number\n"
- " -q quiet (don't show headers)\n"
- " -s show all tablespaces\n"
- " -S show system objects too\n"
- " -t TABLE show info for named table\n"
- " -U NAME connect as specified database user\n"
- " -V, --version output version information, then exit\n"
- " -x extended (show additional columns)\n"
- " -?, --help show this help, then exit\n"
+ " -f, --filenode=FILENODE show info for table with given file node\n"
+ " -i, --indexes show indexes and sequences too\n"
+ " -o, --oid=OID show info for table with given OID\n"
+ " -q, --quiet quiet (don't show headers)\n"
+ " -s, --tablespaces show all tablespaces\n"
+ " -S, --system-objects show system objects too\n"
+ " -t, --table=TABLE show info for named table\n"
+ " -V, --version output version information, then exit\n"
+ " -x, --extended extended (show additional columns)\n"
+ " -?, --help show this help, then exit\n"
+ "\nConnection options:\n"
+ " -d, --dbname=DBNAME database to connect to\n"
+ " -h, --host=HOSTNAME database server host or socket directory\n"
+ " -H same as -h, deprecated option\n"
+ " -p, --port=PORT database server port number\n"
+ " -U, --username=USERNAME connect as specified database user\n"
"\nThe default action is to show all database OIDs.\n\n"
"Report bugs to <pgsql-bugs@postgresql.org>.\n",
progname, progname);
diff --git a/contrib/oid2name/t/001_basic.pl b/contrib/oid2name/t/001_basic.pl
new file mode 100644
index 0000000000..fa2c5743f6
--- /dev/null
+++ b/contrib/oid2name/t/001_basic.pl
@@ -0,0 +1,12 @@
+use strict;
+use warnings;
+
+use TestLib;
+use Test::More tests => 8;
+
+#########################################
+# Basic checks
+
+program_help_ok('oid2name');
+program_version_ok('oid2name');
+program_options_handling_ok('oid2name');
diff --git a/doc/src/sgml/oid2name.sgml b/doc/src/sgml/oid2name.sgml
index dd875281c8..536682ac5a 100644
--- a/doc/src/sgml/oid2name.sgml
+++ b/doc/src/sgml/oid2name.sgml
@@ -60,41 +60,48 @@
<variablelist>
<varlistentry>
- <term><option>-f</option> <replaceable>filenode</replaceable></term>
- <listitem><para>show info for table with filenode <replaceable>filenode</replaceable></para></listitem>
+ <term><option>-f <replaceable class="parameter">filenode</replaceable></option></term>
+ <term><option>--filenode=<replaceable class="parameter">filenode</replaceable></option></term>
+ <listitem><para>show info for table with filenode <replaceable>filenode</replaceable>.</para></listitem>
</varlistentry>
<varlistentry>
<term><option>-i</option></term>
- <listitem><para>include indexes and sequences in the listing</para></listitem>
+ <term><option>--indexes</option></term>
+ <listitem><para>include indexes and sequences in the listing.</para></listitem>
</varlistentry>
<varlistentry>
- <term><option>-o</option> <replaceable>oid</replaceable></term>
- <listitem><para>show info for table with OID <replaceable>oid</replaceable></para></listitem>
+ <term><option>-o <replaceable class="parameter">oid</replaceable></option></term>
+ <term><option>--oid=<replaceable class="parameter">oid</replaceable></option></term>
+ <listitem><para>show info for table with OID <replaceable>oid</replaceable>.</para></listitem>
</varlistentry>
<varlistentry>
<term><option>-q</option></term>
- <listitem><para>omit headers (useful for scripting)</para></listitem>
+ <term><option>--quiet</option></term>
+ <listitem><para>omit headers (useful for scripting).</para></listitem>
</varlistentry>
<varlistentry>
<term><option>-s</option></term>
- <listitem><para>show tablespace OIDs</para></listitem>
+ <term><option>--tablespaces</option></term>
+ <listitem><para>show tablespace OIDs.</para></listitem>
</varlistentry>
<varlistentry>
<term><option>-S</option></term>
+ <term><option>--system-objects</option></term>
<listitem><para>include system objects (those in
<option>information_schema</option>, <option>pg_toast</option>
- and <option>pg_catalog</option> schemas)
+ and <option>pg_catalog</option> schemas).
</para></listitem>
</varlistentry>
<varlistentry>
- <term><option>-t</option> <replaceable>tablename_pattern</replaceable></term>
- <listitem><para>show info for table(s) matching <replaceable>tablename_pattern</replaceable></para></listitem>
+ <term><option>-t <replaceable class="parameter">tablename_pattern</replaceable></option></term>
+ <term><option>--table=<replaceable class="parameter">tablename_pattern</replaceable></option></term>
+ <listitem><para>show info for table(s) matching <replaceable class="parameter">tablename_pattern</replaceable>.</para></listitem>
</varlistentry>
<varlistentry>
@@ -109,8 +116,9 @@
<varlistentry>
<term><option>-x</option></term>
+ <term><option>--extended</option></term>
<listitem><para>display more information about each object shown: tablespace name,
- schema name, and OID
+ schema name, and OID.
</para></listitem>
</varlistentry>
@@ -133,29 +141,34 @@
<variablelist>
<varlistentry>
- <term><option>-d</option> <replaceable>database</replaceable></term>
- <listitem><para>database to connect to</para></listitem>
+ <term><option>-d <replaceable class="parameter">database</replaceable></option></term>
+ <term><option>--dbname=<replaceable class="parameter">database</replaceable></option></term>
+ <listitem><para>database to connect to.</para></listitem>
</varlistentry>
<varlistentry>
- <term><option>-H</option> <replaceable>host</replaceable></term>
- <listitem><para>database server's host</para></listitem>
+ <term><option>-h <replaceable class="parameter">host</replaceable></option></term>
+ <term><option>--host=<replaceable class="parameter">host</replaceable></option></term>
+ <listitem><para>database server's host.</para></listitem>
</varlistentry>
<varlistentry>
- <term><option>-p</option> <replaceable>port</replaceable></term>
- <listitem><para>database server's port</para></listitem>
+ <term><option>-H <replaceable class="parameter">host</replaceable></option></term>
+ <listitem><para>database server's host. Use of this parameter is
+ <emphasis>deprecated</emphasis> as of
+ <productname>PostgreSQL</productname> 12.</para></listitem>
</varlistentry>
<varlistentry>
- <term><option>-U</option> <replaceable>username</replaceable></term>
- <listitem><para>user name to connect as</para></listitem>
+ <term><option>-p <replaceable class="parameter">port</replaceable></option></term>
+ <term><option>--port=<replaceable class="parameter">port</replaceable></option></term>
+ <listitem><para>database server's port.</para></listitem>
</varlistentry>
<varlistentry>
- <term><option>-P</option> <replaceable>password</replaceable></term>
- <listitem><para>password (deprecated — putting this on the command line
- is a security hazard)</para></listitem>
+ <term><option>-U <replaceable class="parameter">username</replaceable></option></term>
+ <term><option>--username=<replaceable class="parameter">username</replaceable></option></term>
+ <listitem><para>user name to connect as.</para></listitem>
</varlistentry>
</variablelist>
@@ -188,6 +201,30 @@
</para>
</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>
<title>Notes</title>
--
2.18.0
0002-Rework-option-set-of-vacuumlo.patchtext/x-diff; charset=us-asciiDownload
From f7e5840ec52c44cad3f9b9dd0ceccfe14135c628 Mon Sep 17 00:00:00 2001
From: Michael Paquier <michael@paquier.xyz>
Date: Mon, 27 Aug 2018 19:01:13 +0900
Subject: [PATCH 2/2] 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
---
contrib/vacuumlo/.gitignore | 2 +
contrib/vacuumlo/Makefile | 6 +++
contrib/vacuumlo/t/001_basic.pl | 9 ++++
contrib/vacuumlo/vacuumlo.c | 82 ++++++++++++++++++---------------
doc/src/sgml/vacuumlo.sgml | 39 ++++++++++++++--
5 files changed, 98 insertions(+), 40 deletions(-)
create mode 100644 contrib/vacuumlo/t/001_basic.pl
diff --git a/contrib/vacuumlo/.gitignore b/contrib/vacuumlo/.gitignore
index 07f6ab4fd7..f3f0ce3d80 100644
--- a/contrib/vacuumlo/.gitignore
+++ b/contrib/vacuumlo/.gitignore
@@ -1 +1,3 @@
/vacuumlo
+
+/tmp_check/
diff --git a/contrib/vacuumlo/Makefile b/contrib/vacuumlo/Makefile
index 71106ff69c..06c5f43f1b 100644
--- a/contrib/vacuumlo/Makefile
+++ b/contrib/vacuumlo/Makefile
@@ -19,3 +19,9 @@ top_builddir = ../..
include $(top_builddir)/src/Makefile.global
include $(top_srcdir)/contrib/contrib-global.mk
endif
+
+check:
+ $(prove_check)
+
+installcheck:
+ $(prove_installcheck)
diff --git a/contrib/vacuumlo/t/001_basic.pl b/contrib/vacuumlo/t/001_basic.pl
new file mode 100644
index 0000000000..2bfb6ce17d
--- /dev/null
+++ b/contrib/vacuumlo/t/001_basic.pl
@@ -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');
diff --git a/contrib/vacuumlo/vacuumlo.c b/contrib/vacuumlo/vacuumlo.c
index 7eb474ca3e..26040115a9 100644
--- a/contrib/vacuumlo/vacuumlo.c
+++ b/contrib/vacuumlo/vacuumlo.c
@@ -26,6 +26,7 @@
#include "fe_utils/connect.h"
#include "libpq-fe.h"
#include "pg_getopt.h"
+#include "getopt_long.h"
#define BUFSIZE 1024
@@ -434,17 +435,17 @@ usage(const char *progname)
printf("%s removes unreferenced large objects from databases.\n\n", progname);
printf("Usage:\n %s [OPTION]... DBNAME...\n\n", progname);
printf("Options:\n");
- printf(" -l LIMIT commit after removing each LIMIT large objects\n");
- printf(" -n don't remove large objects, just show what would be done\n");
- printf(" -v write a lot of progress messages\n");
- printf(" -V, --version output version information, then exit\n");
- printf(" -?, --help show this help, then exit\n");
+ printf(" -l, --limit=LIMIT commit after removing each LIMIT large objects\n");
+ printf(" -n, --dry-run don't remove large objects, just show what would be done\n");
+ printf(" -v, --verbose write a lot of progress messages\n");
+ printf(" -V, --version output version information, then exit\n");
+ printf(" -?, --help show this help, then exit\n");
printf("\nConnection options:\n");
- printf(" -h HOSTNAME database server host or socket directory\n");
- printf(" -p PORT database server port\n");
- printf(" -U USERNAME user name to connect as\n");
- printf(" -w never prompt for password\n");
- printf(" -W force password prompt\n");
+ printf(" -h, --host=HOSTNAME database server host or socket directory\n");
+ printf(" -p, --port=PORT database server port\n");
+ printf(" -U, --username=USERNAME user name to connect as\n");
+ printf(" -w, --no-password never prompt for password\n");
+ printf(" -W, --password force password prompt\n");
printf("\n");
printf("Report bugs to <pgsql-bugs@postgresql.org>.\n");
}
@@ -453,11 +454,26 @@ usage(const char *progname)
int
main(int argc, char **argv)
{
+ static struct option long_options[] = {
+ {"host", required_argument, NULL, 'h'},
+ {"limit", required_argument, NULL, 'l'},
+ {"port", required_argument, NULL, 'p'},
+ {"dry-run", no_argument, NULL, 'n'},
+ {"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;
struct _param param;
int c;
int port;
const char *progname;
+ int optindex;
progname = get_progname(argv[0]);
@@ -486,25 +502,12 @@ 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)
{
- case '?':
- fprintf(stderr, _("Try \"%s --help\" for more information.\n"), progname);
- exit(1);
- case ':':
- exit(1);
- case 'v':
- param.verbose = 1;
- break;
- case 'n':
- param.dry_run = 1;
- param.verbose = 1;
+ case 'h':
+ param.pg_host = pg_strdup(optarg);
break;
case 'l':
param.transaction_limit = strtol(optarg, NULL, 10);
@@ -516,14 +519,9 @@ main(int argc, char **argv)
exit(1);
}
break;
- case 'U':
- param.pg_user = pg_strdup(optarg);
- break;
- case 'w':
- param.pg_prompt = TRI_NO;
- break;
- case 'W':
- param.pg_prompt = TRI_YES;
+ case 'n':
+ param.dry_run = 1;
+ param.verbose = 1;
break;
case 'p':
port = strtol(optarg, NULL, 10);
@@ -534,9 +532,21 @@ main(int argc, char **argv)
}
param.pg_port = pg_strdup(optarg);
break;
- case 'h':
- param.pg_host = pg_strdup(optarg);
+ case 'U':
+ param.pg_user = pg_strdup(optarg);
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);
}
}
diff --git a/doc/src/sgml/vacuumlo.sgml b/doc/src/sgml/vacuumlo.sgml
index 0b4dfc2b17..0b57a77af4 100644
--- a/doc/src/sgml/vacuumlo.sgml
+++ b/doc/src/sgml/vacuumlo.sgml
@@ -55,7 +55,8 @@
<variablelist>
<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>
<para>
Remove no more than <replaceable>limit</replaceable> large objects per
@@ -69,6 +70,7 @@
<varlistentry>
<term><option>-n</option></term>
+ <term><option>--dry-run</option></term>
<listitem>
<para>Don't remove anything, just show what would be done.</para>
</listitem>
@@ -76,6 +78,7 @@
<varlistentry>
<term><option>-v</option></term>
+ <term><option>--verbose</option></term>
<listitem>
<para>Write a lot of progress messages.</para>
</listitem>
@@ -110,21 +113,24 @@
<variablelist>
<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>
<para>Database server's host.</para>
</listitem>
</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>
<para>Database server's port.</para>
</listitem>
</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>
<para>User name to connect as.</para>
</listitem>
@@ -146,6 +152,7 @@
<varlistentry>
<term><option>-W</option></term>
+ <term><option>--password</option></term>
<listitem>
<para>
Force <application>vacuumlo</application> to prompt for a
@@ -167,6 +174,30 @@
</para>
</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>
<title>Notes</title>
--
2.18.0
On Mon, Aug 27, 2018 at 07:03:18PM +0900, Michael Paquier wrote:
Thanks, I have looked at the patch set.
I have been through the set once again, and pushed both things. Thanks
a lot Yamada-san.
--
Michael
On 2018/08/28 22:36, Michael Paquier wrote:
On Mon, Aug 27, 2018 at 07:03:18PM +0900, Michael Paquier wrote:
Thanks, I have looked at the patch set.
I have been through the set once again, and pushed both things. Thanks
a lot Yamada-san.
Thank you very much for your time to review and revise the patch! :)
In this year, I will try to review someone's patch as you did.
Please let me know if you need reviewer.
Regards,
Tatsuro Yamada