Re: pg_ctl only allows 12 parameters?

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Ron Johnson <ronljohnsonjr(at)gmail(dot)com>
Cc: Nathan Bossart <nathan(at)postgresql(dot)org>, "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>, Pgsql-admin <pgsql-admin(at)lists(dot)postgresql(dot)org>
Subject: Re: pg_ctl only allows 12 parameters?
Date: 2023-12-18 19:28:05
Message-ID: 4005894.1702927685@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin

Ron Johnson <ronljohnsonjr(at)gmail(dot)com> writes:
> On Mon, Dec 18, 2023 at 12:02 PM Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
>> Looking at the v14 pg_ctl code, I see it has an extra level of
>> looping around getopt_long to try to cope with implementations
>> that don't permute the arguments. So in theory it should work as
>> documented everywhere. But I could see how things might get
>> confused, if the subroutine misidentifies what is a switch.

> There must be some PEBKAC involved that pg_ctl error handling didn't
> explain well, because _this_ unreformatted command works.

After studying the code some more, I think I can reproduce it:

$ pg_ctl restart foo -o "whatever"
pg_ctl: too many command-line arguments (first is "restart")
Try "pg_ctl --help" for more information.

It should be complaining about "foo", but the message mentions
"restart" instead. I think you must have had something in your
non-working command that did not get interpreted as being a
switch or a switch argument, leading to the misleading report.

That's with v14. HEAD gets this right:

$ pg_ctl restart foo -o "whatever"
pg_ctl: too many command-line arguments (first is "foo")
Try "pg_ctl --help" for more information.

The change in behavior is evidently due to commit 03d1080d8, which
got rid of the extra level of looping in pg_ctl's use of getopt_long.
I surmise that after we loop around and re-invoke getopt_long,
glibc's getopt_long resets "optind" to the first non-option argument,
rather than honoring the increment from the bottom of the loop.

This seems like a bug to me, but I'm not sure if I want to
propose back-patching 03d1080d8 (and 411b72034) to deal with
it. That code hasn't made it into a stable branch yet, so
a back-patch would be a little bit risky.

regards, tom lane

In response to

Browse pgsql-admin by date

  From Date Subject
Next Message GF 2023-12-18 19:30:45 Re: Guidance required to summarize the migration breaking changes between PG versions
Previous Message Ron Johnson 2023-12-18 18:03:02 Re: pg_ctl only allows 12 parameters?