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

From: Daniel Gustafsson <daniel(at)yesql(dot)se>
To: Jianghua Yang <yjhjstz(at)gmail(dot)com>
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 14:01:26
Message-ID: CEDBFBDE-2BBA-4568-8B9B-42AD74E377EA@yesql.se
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

> On 2 Jul 2025, at 15:52, Jianghua Yang <yjhjstz(at)gmail(dot)com> wrote:
>
> 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.

+ pg_log_error("superuser name must not be empty");
+ exit(1);

I would prefer pg_fatal() for this.

--
Daniel Gustafsson

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Andres Freund 2025-07-02 14:04:23 Re: Add progressive backoff to XactLockTableWait functions
Previous Message Fujii Masao 2025-07-02 13:55:16 Re: Add progressive backoff to XactLockTableWait functions