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 1uWycU-0048F7-JW for pgsql-hackers@arkaria.postgresql.org; Wed, 02 Jul 2025 14:39:30 +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 1uWycS-002FbD-6W for pgsql-hackers@arkaria.postgresql.org; Wed, 02 Jul 2025 14:39:28 +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.94.2) (envelope-from ) id 1uWycR-002Fb4-CH for pgsql-hackers@lists.postgresql.org; Wed, 02 Jul 2025 14:39:28 +0000 Received: from fout-b5-smtp.messagingengine.com ([202.12.124.148]) by makus.postgresql.org with smtp (Exim 4.96) (envelope-from ) id 1uWycP-005Aad-2k for pgsql-hackers@lists.postgresql.org; Wed, 02 Jul 2025 14:39:26 +0000 Received: from phl-compute-04.internal (phl-compute-04.phl.internal [10.202.2.44]) by mailfout.stl.internal (Postfix) with ESMTP id 2F8F81D0007E; Wed, 2 Jul 2025 10:39:25 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-04.internal (MEProxy); Wed, 02 Jul 2025 10:39:25 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=eisentraut.org; h=cc:content-transfer-encoding:content-type:content-type:date :date:from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to; s=fm1; t=1751467165; x=1751553565; bh=YFg0DXAG6DDe1GYQk5NKSEGGqerZzfFu3eUgnuT326g=; b= nePC2X6ig3zTW8cMJLCz+StNwgh7FCu9x7eYMYTfyRvqj9ojOxsyyzHMO2cIyi4b O9yt1NL1x+KbelsdF93rkuT5ls36OMBoXtuRw4BazeyGfCO69Rs0u0uflkxLvfDr mhfwb7CCYxU/GfybbMXrXDDNr/tFYN/OrJ5ndY4zAZDxO8pZfPoMTGp2KpA6iFe0 XbXiCbD3uCqfA48AIIcC6B5wE4y/wr2KPikDQQdIpBoDUtHUvJIa77TbZzsEOte0 Ia0QwnaCM/z0S1AT7lz3Hw4aoUCO/gzaGv9h2yVTXwL2/jjNeo7/xLDoa4ySJOjq zkuo8n0Nk+xSccEQBrMBwQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm2; t=1751467165; x=1751553565; bh=Y Fg0DXAG6DDe1GYQk5NKSEGGqerZzfFu3eUgnuT326g=; b=XLBWH4wbfPiz4X3zB 6HgwB/6aVmJeqLv95zCKsO3P4xYWsEkdQMNmtFp7r/oQKbJ2lLLNJb15INAVPk1i S1vX01hr3zbq1W2GIcWkVAWelio0WGngRWlNHLnCpmRd8rCTiflX0nRkVbGr3oVk WP6c75iPhJUgyG9qyLOMjGCa7SJoE5zkzltEwqHLZFPttfihLFqSH1MAEuzmd/qd l95RHzTauU2a3WaDitnN6chLxIX10EQTzeXW5k2Pju3tB19tUAGDlwELWytXdOqN r+52zz8sfh/3cHO6MORbEHT55JXxiEbe20MyOv3u9vhaILgicpziBplgYdEv+1rZ zUt2Q== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeffedrtdefgddujeeiiecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpuffrtefokffrpgfnqfghnecuuegr ihhlohhuthemuceftddtnecunecujfgurhepkfffgggfuffvfhfhjggtgfesthejredttd dvjeenucfhrhhomheprfgvthgvrhcugfhishgvnhhtrhgruhhtuceophgvthgvrhesvghi shgvnhhtrhgruhhtrdhorhhgqeenucggtffrrghtthgvrhhnpeehiedvhfeuhfeugefgfe ehgeejtdevuefhtefhueefvddugfdtueehgfefudfhffenucevlhhushhtvghrufhiiigv pedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehpvghtvghrsegvihhsvghnthhrrghuth drohhrghdpnhgspghrtghpthhtohepvddpmhhouggvpehsmhhtphhouhhtpdhrtghpthht ohephihjhhhjshhtiiesghhmrghilhdrtghomhdprhgtphhtthhopehpghhsqhhlqdhhrg gtkhgvrhhssehlihhsthhsrdhpohhsthhgrhgvshhqlhdrohhrgh X-ME-Proxy: Feedback-ID: ie0a040ee:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 2 Jul 2025 10:39:23 -0400 (EDT) Message-ID: Date: Wed, 2 Jul 2025 16:39:22 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] initdb: Treat empty -U argument as unset username To: Jianghua Yang , pgsql-hackers@lists.postgresql.org References: Content-Language: en-US From: Peter Eisentraut In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 02.07.25 04:55, Jianghua Yang wrote: > While working with `initdb`, I noticed that passing an empty string to > the `-U` option (e.g., `initdb -U ''`) causes it to fail with a > misleading error: > > performing post-bootstrap initialization ... 2025-07-01 19:48:42.006 PDT > [14888] FATAL:role """ does not exist at character 72 > > 2025-07-01 19:48:42.006 PDT [14888] STATEMENT: > > UPDATE pg_class SET relacl = (SELECT array_agg(a.acl) FROM(SELECT > E'=r/""' as acl UNION SELECT unnest(pg_catalog.acldefault(CASE WHEN > relkind = 'S' THEN 's'ELSE 'r' END::"char",10::oid)) ) as a) WHERE > relkind IN ('r', 'v', 'm', 'S')AND relacl IS NULL; > > This happens because `initdb` accepts the empty string as a valid role > name and attempts to use it as the database superuser, which is not > intended and fails during bootstrap SQL. I'll start by saying, of course an empty user name isn't going to work, so we should reject it. But let's dig a little deeper into why it fails. Observe the error: FATAL:role """ does not exist at character 72 It thinks that the role name is `"` (a sole double-quote, not empty!). Why is that? This error comes from the literal E'=r/""' interpreted as an aclitem value. The aclitem parsing ends up in getid() in src/backend/utils/adt/acl.c, which thinks that an input string consisting entirely of "" is an escaped double quote. Maybe it's worth fixing that, and making putid() also print empty user names correspondingly. Alternatively, it's the fault of initdb that it constructs aclitem values that don't follow the aclitem-specific quoting rules. Another thought is, if we don't allow zero-length names, shouldn't namein() reject empty input strings? Then this whole thing would fail as postgres.bki is being loaded. (This is more hypothetical, since this appears to break a number of other things.) All of this is to say, it's worth looking at the actual cause and think about if there are related problems, maybe other name patterns that we don't handle well, instead of just papering over it at the top level.