Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rFJHh-009IHq-Lk for pgsql-admin@arkaria.postgresql.org; Mon, 18 Dec 2023 19:28:13 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1rFJHe-00C5R2-Jc for pgsql-admin@arkaria.postgresql.org; Mon, 18 Dec 2023 19:28:10 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rFJHe-00C5Q6-84 for pgsql-admin@lists.postgresql.org; Mon, 18 Dec 2023 19:28:10 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rFJHb-00Cff4-N9; Mon, 18 Dec 2023 19:28:09 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 3BIJS5Il4005895; Mon, 18 Dec 2023 14:28:05 -0500 From: Tom Lane To: Ron Johnson cc: Nathan Bossart , "David G. Johnston" , Pgsql-admin Subject: Re: pg_ctl only allows 12 parameters? In-reply-to: References: <3960907.1702915763@sss.pgh.pa.us> <3973210.1702918924@sss.pgh.pa.us> Comments: In-reply-to Ron Johnson message dated "Mon, 18 Dec 2023 13:03:02 -0500" MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-ID: <4005893.1702927685.1@sss.pgh.pa.us> Content-Transfer-Encoding: 8bit Date: Mon, 18 Dec 2023 14:28:05 -0500 Message-ID: <4005894.1702927685@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Ron Johnson writes: > On Mon, Dec 18, 2023 at 12:02 PM Tom Lane 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