Re: [PATCH] initdb: Treat empty -U argument as unset username

From: Jianghua Yang <yjhjstz(at)gmail(dot)com>
To: daniel(at)yesql(dot)se
Cc: Robert Treat <rob(at)xzilla(dot)net>, "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>, pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Re: [PATCH] initdb: Treat empty -U argument as unset username
Date: 2025-07-02 13:52:09
Message-ID: CAAZLFmSY_s6TOsiTwjzqrc2Y4uShATuWcEEN8O8cdtpkS=zfLg@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi hackers,

Based on the suggestion that we should explicitly reject empty usernames
instead of silently falling back, I’ve updated the patch accordingly.

### Changes in v2:

- `initdb` now errors out immediately if the `-U` or `--username` argument
is an empty string.
- The error message is:

superuser name must not be empty

- A regression test is added to `src/bin/initdb/t/001_initdb.pl` to verify
that the case `initdb -U ''` fails as expected.

This approach avoids any ambiguity about whether an empty username is
valid, and fails early with a clear message. It also brings consistency
with existing checks, such as the one disallowing superuser names starting
with `pg_`.

Let me know if this looks acceptable or if further refinement is needed.

Patch attached.

Best regards,
Jianghua Yang

Daniel Gustafsson <daniel(at)yesql(dot)se> 于2025年7月2日周三 00:16写道:

> > On 2 Jul 2025, at 06:31, Robert Treat <rob(at)xzilla(dot)net> wrote:
>
> > FWIW, I tend to agree with David; I feel like if a user passes in -U,
> > there was probably a reason, and a good error message would be more
> > useful in clarifying things rather than blindly pushing forward with
> > potentially the wrong thing.
>
> Agreed, and it's not even clear that the previous code was intentionally
> trying
> to allow an empty -U. An improved error message would be a good patch
> though.
>
> --
> Daniel Gustafsson
>
>

Attachment Content-Type Size
0001-initdb-Reject-empty-string-for-U-username-option.patch application/octet-stream 1.7 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Fujii Masao 2025-07-02 13:55:16 Re: Add progressive backoff to XactLockTableWait functions
Previous Message Amit Langote 2025-07-02 13:48:22 Re: Proposal: Global Index for PostgreSQL