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.96) (envelope-from ) id 1w3Zyi-001MXy-3B for pgsql-hackers@arkaria.postgresql.org; Fri, 20 Mar 2026 13:33:29 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1w3Zyh-006EXj-1E for pgsql-hackers@arkaria.postgresql.org; Fri, 20 Mar 2026 13:33:27 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1w3Zyg-006EXU-36 for pgsql-hackers@lists.postgresql.org; Fri, 20 Mar 2026 13:33:27 +0000 Received: from mail-ej1-x634.google.com ([2a00:1450:4864:20::634]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1w3Zyf-00000000Aka-19uG for pgsql-hackers@lists.postgresql.org; Fri, 20 Mar 2026 13:33:26 +0000 Received: by mail-ej1-x634.google.com with SMTP id a640c23a62f3a-b9358bc9c50so249951366b.1 for ; Fri, 20 Mar 2026 06:33:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1774013604; cv=none; d=google.com; s=arc-20240605; b=drLos3h9aPIntTAplbQwd0jK4nnzPwZZEfVaZaGZkv7aRbnEWh2NPAgUkm0iEJa1At R08vKo+rNGpIDZmHT0+mCJLKW0sAks6q4bAlQyYsy5y/81iV/aHE4PAHdM+bMcQuHj47 qx3mUaPQWowehf1g/p6sEI3DNomZrvCInWXiLwvpy97PGjn8eU98tENBR2J7rxhlH2dZ 54xo9ldb1I6rSauHdqPN+Jf+vAM9owoZw7u56BYrlAND47FgShpU2Uew7BYzAdZ3qwHX ZWJvyty7/Ojspc4UN2PV0QPrenJft8s75oGmnn6k5kEwyemjXq5bkGbPR07vFIM8LUJq KIFg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=to:subject:message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=ThjwgNuq+EIZRbkafcwRY/4BYXolaCltz7IinN70HTc=; fh=VIj4b7iNrxni1fyapuR7JijEbu7a363WW6ZbSSgfTCM=; b=eqgkD2CILixYhdmY8CwDMRTv2uWqax0gKrfpikG2YdOFim/EfpSAjI+YkxypxlFI5r 7QcEFTjJfaQE9Gak/nPleeIwCPIRn2Pqrt3BXL/iZKnd7F6A5f7mpn2laQLg3Vu3hLkI xmny23mfHxtigCrBsOWMeSoDsJreDzygdkU9uFgy+pihMqhmhtaY13sV1bBD347RRLfM y2a9Et9GDe2n3SXbEpzWrSk1SgqW4Eo45MxV1hiZpHk8dgJGHvX13c8jScIsOUMRNpaj TvBhIRR5g1tg6kDequxx+NjiovipY6QL6OxrffoPH6G/h79+MTfC9QcvT1MZdbkIX7M/ cx3Q==; darn=lists.postgresql.org ARC-Authentication-Results: i=1; mx.google.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1774013604; x=1774618404; darn=lists.postgresql.org; h=to:subject:message-id:date:from:in-reply-to:references:mime-version :from:to:cc:subject:date:message-id:reply-to; bh=ThjwgNuq+EIZRbkafcwRY/4BYXolaCltz7IinN70HTc=; b=cBoDInrDuWksras4cFa40YYmbRNFNRjqdLdiGc1E78k6uWy72hK95t4gsxgHQjMcGI 7/6oCGZ3ZUtUsecjpPdvJBqJgb5Pl0MAX6IZwPJJfTvQWoEvlZm7EzJR0mKqpHxMILVw s3s8xp5a43VMmXJWcFcCPc88VPOvDKhSKy+nU9pRnlUjA71b7qgIvF0yq6HjccyD4ngp ZiDuUOGzpvvY7yNz3BSn277yV8RK3shKhpwr/EDCULf0Uj3ZOFgQVNQa8F9VyG/LVkaA cBoQzq119kenZxmsB3Ba1cT2aJBixq+QKgZHHkGJLIgnVQjEOGKNkQgomttrg9LorCdc 7JTA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774013604; x=1774618404; h=to:subject:message-id:date:from:in-reply-to:references:mime-version :x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=ThjwgNuq+EIZRbkafcwRY/4BYXolaCltz7IinN70HTc=; b=ER2dCKisdtxrFY61uzNNzNe2qm9rOLidC1h4T4vkfbZObqb/VITwh1lwxmJAPlf3bc sKauOnCMy+GCyyFe6Q26vhPC1Z3EB5OReTxYPvSj+u7oF8VriuIvKZMhKUnelAu+vj3c iCrNMrmYF+HZrayqFM5yuD/bH6A/+6arTJSllF9THZaXPsP5XQFFoxoi8rMu9uPXEep3 WNXmlZ+85306CkFkuIo0JQ3LQZPKQt8RVvcrUJV7V5CZoOLqNjKdpt/cuY8iI113GNNP qSrPBZm3RTYRR9ag/AyELKtwAOxmg55ZZijEmKmpjDh8IgUV0/pdtm1qKEaoU4JBunWR MIYA== X-Forwarded-Encrypted: i=1; AJvYcCXJmqRIVgkN7plGb2/qtYCkepoZHqRDdAbfDT0/zsYFPzYvL6NDN84je1S7t7GrJHtiVN22IPpEafvcvZh5@lists.postgresql.org X-Gm-Message-State: AOJu0YwdVmORjwwq1/yc0rdn3VMAGjSI1qT6QBgl594t6yJ5VEeyTm7P YyZf8RKIUyqTecGugqgXp6V2FaGoaMybTOkpYe6HKcrARwublxWFElWnGspeC7tg4cYIdlt9tYC fyNs5HoMb0wR9/xSqfl4rHeFNVtX58L5uTFByqEg= X-Gm-Gg: ATEYQzzKTJmIZM9ThD8VDoMx3zmtCwPjnsY9gKmcQo1Uue4FVPpbxy6YoGJv/V9mVSa hi1RZi3pAE4+X4sO/+L4ed7BJHZ/hIv3lhqemXCd9OzT6lxRdWAvTLPK3c5CxjRlZXgC31BIhbU nxtDZoZ8oTQDq+HW9Y72VvB0meNRdb+co4owVmy824ZWwoJbq00G6E36NsLXxLZHsAePsvOswjv NucrlP178cWNnFmJb/KIv63GD0UiaI8zjbTKNW5YLxdjeDIxN5vwjdrvls4k0UTrCILoDO6zORK TXdmI4Ye4l+p37g+TetMlzF6kMNcOzKn6rfqiCY= X-Received: by 2002:a17:907:170c:b0:b97:9139:738 with SMTP id a640c23a62f3a-b982f2f0c72mr179955566b.33.1774013603274; Fri, 20 Mar 2026 06:33:23 -0700 (PDT) MIME-Version: 1.0 References: <3793879.1751492926@sss.pgh.pa.us> <10700.1751736853@sss.pgh.pa.us> In-Reply-To: From: Jianghua Yang Date: Fri, 20 Mar 2026 06:32:46 -0700 X-Gm-Features: AaiRm50gFKg3aBtbd0CWlbS0U1yjYT1kSvGEjvNHJb-RRBH7VfTS_Fy5xlYNz_E Message-ID: Subject: Re: [PATCH] initdb: Treat empty -U argument as unset username To: Tom Lane , pgsql-hackers@lists.postgresql.org Content-Type: multipart/mixed; boundary="000000000000a69de4064d74ba79" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --000000000000a69de4064d74ba79 Content-Type: multipart/alternative; boundary="000000000000a69de2064d74ba77" --000000000000a69de2064d74ba77 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hi, The underlying aclitem quoting issue has been fixed in commit 64840e46243 ("Fix inconsistent quoting of role names in ACLs"), so the concern about this patch interfering with that investigation no longer applies. Here's a rebased version of the patch. The approach is unchanged from v3: reject an empty string passed to -U/--username early with a clear error message, rather than letting it fall through to a confusing FATAL during bootstrap SQL execution. Changes: - Add an empty-string check before the existing pg_ prefix check in initdb's main(), using pg_fatal(). - Add a regression test using command_fails_like() to verify the error message. Jianghua Yang =E4=BA=8E2025=E5=B9=B47=E6=9C=885=E6=97= =A5=E5=91=A8=E5=85=AD 10:45=E5=86=99=E9=81=93=EF=BC=9A > Hi Tom, > > Thanks for the clarification. > > Just to provide a bit more context =E2=80=94 we encountered this issue in= a > production environment where initdb was being run inside a Docker > container. In such environments, the $USER environment variable may be > unset or empty, which causes initdb -U $USER to fail with a confusing > error. > > While it's true that this behavior has existed for a long time, it's > become more relevant as Docker and containerized deployments have become > common. This issue can be hard to diagnose for users unfamiliar with the > internals of initdb, especially since the failure message isn't very > informative in this case. > > I understand your point about not wanting to merge the patch prematurely > if it could obscure underlying problems. That said, this particular fix > seems orthogonal to the ACL parsing issue and addresses a real-world > usability problem with minimal risk. > > Would you be open to reconsidering a standalone merge of this patch, or > perhaps applying a minimal workaround for cases where $USER is unset? > > Thanks again for your time and consideration. > > Best regards, > Jianghua Yang > > Tom Lane =E4=BA=8E2025=E5=B9=B47=E6=9C=885=E6=97=A5= =E5=91=A8=E5=85=AD 10:34=E5=86=99=E9=81=93=EF=BC=9A > >> Jianghua Yang writes: >> > I wanted to ask if this patch can be merged first, as it seems to be a >> > separate issue different from the aclitem parsing problem Tom discusse= d >> in >> > >> https://www.postgresql.org/message-id/3792884.1751492172%40sss.pgh.pa.us >> >> Merging your patch will make it more difficult to poke at these >> underlying issues, so I'm not in a hurry to do that. It's not >> like this is an urgent issue: initdb has behaved like that for >> years if not decades, and nobody's complained before. >> >> regards, tom lane >> > --000000000000a69de2064d74ba77 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hi,

=C2=A0 The underlying aclitem quoting issue has= been fixed in commit 64840e46243
=C2=A0 ("Fix inconsistent quoting= of role names in ACLs"), so the concern about
=C2=A0 this patch in= terfering with that investigation no longer applies.

=C2=A0 Here'= ;s a rebased version of the patch. The approach is unchanged from v3:
= =C2=A0 reject an empty string passed to -U/--username early with a clear er= ror
=C2=A0 message, rather than letting it fall through to a confusing F= ATAL during
=C2=A0 bootstrap SQL execution.

=C2=A0 Changes:
= =C2=A0 - Add an empty-string check before the existing pg_ prefix check
= =C2=A0 =C2=A0 in initdb's main(), using pg_fatal().
=C2=A0 - Add a r= egression test using command_fails_like() to verify the
=C2=A0 =C2=A0 er= ror message.

Jianghua Yang <yjhjstz@gmail.com> =E4=BA=8E2025=E5=B9=B47=E6=9C=885= =E6=97=A5=E5=91=A8=E5=85=AD 10:45=E5=86=99=E9=81=93=EF=BC=9A

Hi Tom,

Thanks for the clarification.

Just to provide a bit more context =E2=80=94 we encountered this issue i= n a production environment where initdb was being run inside a= Docker container. In such environments, the $USER environment= variable may be unset or empty, which causes initdb -U $USER = to fail with a confusing error.

While it's true that this behavior has existed for a long time, it&#= 39;s become more relevant as Docker and containerized deployments have beco= me common. This issue can be hard to diagnose for users unfamiliar with the= internals of initdb, especially since the failure message isn= 't very informative in this case.

I understand your point about not wanting to merge the patch prematurely= if it could obscure underlying problems. That said, this particular fix se= ems orthogonal to the ACL parsing issue and addresses a real-world usabilit= y problem with minimal risk.

Would you be open to reconsidering a standalone merge of this patch, or = perhaps applying a minimal workaround for cases where $USER is= unset?

Thanks again for your time and consideration.

Best regards,
Jianghua Yang


Tom Lane <tgl@sss.pgh.pa.us> =E4=BA=8E2025=E5=B9=B47=E6=9C=885=E6= =97=A5=E5=91=A8=E5=85=AD 10:34=E5=86=99=E9=81=93=EF=BC=9A
Jianghua Yang <yjhjstz@gmail.com> writes: > I wanted to ask if this patch can be merged first, as it seems to be a=
> separate issue different from the aclitem parsing problem Tom discusse= d in
> https://www.postgresql.= org/message-id/3792884.1751492172%40sss.pgh.pa.us

Merging your patch will make it more difficult to poke at these
underlying issues, so I'm not in a hurry to do that.=C2=A0 It's not=
like this is an urgent issue: initdb has behaved like that for
years if not decades, and nobody's complained before.

=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 regards, tom lane
--000000000000a69de2064d74ba77-- --000000000000a69de4064d74ba79 Content-Type: application/octet-stream; name="0001-initdb-reject-empty-string-for-U-username-option.patch" Content-Disposition: attachment; filename="0001-initdb-reject-empty-string-for-U-username-option.patch" Content-Transfer-Encoding: base64 Content-ID: X-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