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 1tCjZP-00BryP-Fk for pgsql-bugs@arkaria.postgresql.org; Sun, 17 Nov 2024 18:00:22 +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 1tCjZM-0010wB-Pk for pgsql-bugs@arkaria.postgresql.org; Sun, 17 Nov 2024 18:00:21 +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 1tCjZM-0010vn-Gp for pgsql-bugs@lists.postgresql.org; Sun, 17 Nov 2024 18:00:21 +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 1tCjZI-002RkP-B8 for pgsql-bugs@lists.postgresql.org; Sun, 17 Nov 2024 18:00:20 +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 4AHI0EwK3072826; Sun, 17 Nov 2024 13:00:14 -0500 From: Tom Lane To: adam@labkey.com cc: Bertrand Drouvot , Nathan Bossart , pgsql-bugs@lists.postgresql.org Subject: Re: BUG #18711: Attempting a connection with a database name longer than 63 characters now fails In-reply-to: <18711-7503ee3e449d2c47@postgresql.org> References: <18711-7503ee3e449d2c47@postgresql.org> Comments: In-reply-to PG Bug reporting form message dated "Sat, 16 Nov 2024 00:12:27 +0000" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <3072824.1731866414.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Sun, 17 Nov 2024 13:00:14 -0500 Message-ID: <3072825.1731866414@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk PG Bug reporting form writes: > For many years, our test infrastructure has used database names that are > longer than the stated maximum length of 63 characters. The PostgreSQL > server simply truncates these names to 63 characters in all operations a= nd > everything works fine. Starting with 17.x, our application is able to CR= EATE > and ALTER databases with long names, but all connection attempts using t= hem > fail with an error: database "" does not exist Yeah, this was an intentional change in v17: commit 562bee0fc13dc95710b8db6a48edad2f3d052f2e Author: Nathan Bossart Date: Mon Jul 3 13:18:05 2023 -0700 Don't truncate database and user names in startup packets. = Unlike commands such as CREATE DATABASE, ProcessStartupPacket() does not perform multibyte-aware truncation of overlength names. This means that connection attempts might fail even if the user provides the same overlength names that were used in CREATE DATABASE, CREATE ROLE, etc. Ideally, we'd do the same multibyte- aware truncation in both code paths, but it doesn't seem worth the added complexity of trying to discover the encoding of the names. Instead, let's simply skip truncating the names in the startup packet and let the user/database lookup fail later on. With this change, users must provide the exact names stored in the catalogs, even if the names were truncated. = This reverts commit d18c1d1f51. = Author: Bertrand Drouvot Reviewed-by: Kyotaro Horiguchi, Tom Lane Discussion: https://postgr.es/m/07436793-1426-29b2-f924-db7422a05fb7%4= 0gmail.com As said, the difficulty is that we don't know what encoding the incoming name is meant to be in, and with multibyte encodings that matters. The name actually stored in the catalog might be less than 63 bytes long if it was truncated in a multibyte-aware way, so that the former behavior of blindly truncating at 63 bytes can still yield unexpected no-such-database results. I can imagine still performing the truncation if the incoming name is all-ASCII, but that seems like a hack. The world isn't nearly as ASCII-centric as it was in 2001. regards, tom lane