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 1tE8t7-005SDo-BT for pgsql-bugs@arkaria.postgresql.org; Thu, 21 Nov 2024 15:14:33 +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 1tE8t5-00GlMH-QO for pgsql-bugs@arkaria.postgresql.org; Thu, 21 Nov 2024 15:14:31 +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 1tE8t5-00GlM8-H3 for pgsql-bugs@lists.postgresql.org; Thu, 21 Nov 2024 15:14:31 +0000 Received: from mail-qv1-xf31.google.com ([2607:f8b0:4864:20::f31]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1tE8t2-0034D8-Ga for pgsql-bugs@lists.postgresql.org; Thu, 21 Nov 2024 15:14:30 +0000 Received: by mail-qv1-xf31.google.com with SMTP id 6a1803df08f44-6d41176505fso8742816d6.2 for ; Thu, 21 Nov 2024 07:14:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1732202067; x=1732806867; darn=lists.postgresql.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=F7EPsKhfoR3mV4Q8dPOL9SRDKwJ6jPiMW7rXoh4PMNY=; b=POgypWG9PVcDbELuNRGR0wm201YsUQOJlIHPFp17DR0s24TGPKfw3ic3VO0SVA16na lyoHIXR0v38oDTUNwW0iNzJ3HAeVqp8uc8H4R1WnEklQgEzD8p6qDy4zp6KgNtnXiDG+ KB+FAjmxGwmA5PU42Y5v0xsSwKk0qtJcbjGZ8yvpMcw2H6vIGxa6/Lw/JTwsiCkDeEw0 wgaVJfR/KmhKy4Ld8WVDo8CUiDC+gvOCgavJRWonApO6e+Tt6UvqAm8pHGPfMp6K/vmT MR0WWBxH54vXc9H7TlpdpGPH8F6S3TqhZdJ7LU+lynhw/BS8tuNdNpQ8h5zAW936mRvd rSkA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732202067; x=1732806867; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=F7EPsKhfoR3mV4Q8dPOL9SRDKwJ6jPiMW7rXoh4PMNY=; b=HSe/ezdmlps14jepTZejgfYKe0PAE46bPerBrLWG4C5ADCeLy1tJ2WcfsKaIUTt4jr ITLmhRIsCtjwMMDqZTwdmEIaMarBKZKdDIB7AVMC3rCJUo7ObK+UkkUun1Z6NdAbgfxs lIAd1diWCQocuiwc+4g4xFzXg7by9yeJcfSiuYbKUwwLtr74Zr4XkNQtAaYomAHARpP9 J/xg4gph7HaBVB65mf4biR/JbcRP34xQEsDGAF1exwkB167FysN8iAj5ZENkI7TVNwpK AJP96ByKiN1CcxMjSi81OMDxrPNW24vjKi6SIs1VCcdVAp4KfqMcn62AjgDwZurj8v/h QF/w== X-Forwarded-Encrypted: i=1; AJvYcCUkJyZUcPIdha8gPgAZ4MyL+eSExj1XcHh2QZCvoqUYXDGxGy8zbwsuNGidISYdSrtkG9IRPY6p42Fw@lists.postgresql.org X-Gm-Message-State: AOJu0YxseLDyYiHN9Z4emvnmhzrAmH/K9FhsRBspaBM6qYTnWZX4fqUN 7zO6inLo2KN/j1sxbOCCf4q23yPvQu0F2Vc3IKb1aegzhqq6cr9r X-Gm-Gg: ASbGncvnzWtPh8/6pSkANkWiUHynW1KlbGkEtbMa+IsU4lpfPgMTHscAM7527XbqO2V oXno+QcYUSdPNCLTtwb9kmxH2S/M3X0yi/PfmCAYeFNNzgR8ldcp6d7gAxcZEtRT1AefcE15+F5 L5E/2PQWE2wxSNqhKv8rvIfC8rK24o9Pn5Wq9EXar8dbvMk1zQ3Vo77GQK1Gc+vnwpR7NiLo5ms IfGDqgBXIFETec/I4fSWs54OP6ZBdrQOWJTPVt1Vqb/Cb8Rihm6lIKYQfAMWQTT+9fTbNTaB6XC Vw7zjU08fngXQPWoUAAo3h8n8TWB22lbVDfeAI1y X-Google-Smtp-Source: AGHT+IEdPFyQaOY1HKsf0z9N8vdvXlZr3bP7T1hU+/f4xm1X5+nLdgQ0A/nFjbBAWl7riQpO+NCExw== X-Received: by 2002:ad4:5e86:0:b0:6d3:f54c:e412 with SMTP id 6a1803df08f44-6d4377e6fafmr110759246d6.16.1732202066037; Thu, 21 Nov 2024 07:14:26 -0800 (PST) Received: from nathan (162-195-168-172.lightspeed.stlsmo.sbcglobal.net. [162.195.168.172]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6d4380d8b6bsm24463046d6.34.2024.11.21.07.14.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Nov 2024 07:14:25 -0800 (PST) Date: Thu, 21 Nov 2024 09:14:23 -0600 From: Nathan Bossart To: Bruce Momjian Cc: Bertrand Drouvot , Tom Lane , adam@labkey.com, pgsql-bugs@lists.postgresql.org Subject: Re: BUG #18711: Attempting a connection with a database name longer than 63 characters now fails Message-ID: References: <154104.1732118090@sss.pgh.pa.us> <158506.1732120196@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Thu, Nov 21, 2024 at 09:47:56AM -0500, Bruce Momjian wrote: > On Thu, Nov 21, 2024 at 02:35:50PM +0000, Bertrand Drouvot wrote: >> On Thu, Nov 21, 2024 at 09:21:16AM -0500, Bruce Momjian wrote: >> > I don't understand this logic. Why are two bytes important? If we knew >> > it was UTF8 we could check for non-first bytes always starting with >> > bits 10, but we can't know that. >> >> I think this is because this is a reliable way to detect if the truncation happened >> in the middle of a character, without needing to know the specifics of the encoding. >> >> My understanding is that the key insight is that in any multibyte encoding, all >> bytes within a multibyte character will have their high bits set. >> >> That's just my understanding from the code and Tom's previous explanations: I >> might be wrong as not an expert in this area. > > But the logic doesn't make sense. Why would two bytes be any different > than one? Tom provided a concise explanation upthread [0]. My understanding is the same as Bertrand's, i.e., this is an easy way to rule out a bunch of cases where we know that we couldn't possibly have truncated in the middle of a multi-byte character. This allows us to avoid doing multiple pg_database lookups. > I assumed you would just remove all trailing high-bit bytes > and stop and the first non-high-bit byte. I think this risks truncating more than one multi-byte character, which would cause the login path to truncate differently than the CREATE/ALTER DATABASE path (which is encoding-aware). > Also, do we really expect > there to be trailing multi-byte characters and then some ASCII before > it? Isn't it likely it will be all ASCII or all multi-byte characters? > I guess for Latin1, it would work fine, but I assume for Asian > languages, it will be almost all multi-byte characters. I guess digits > would be ASCII. All of these seem within the realm of possibility to me. > This all just seems very unfocused. I see the following options: * Try to do multibyte-aware truncation (the patch at hand). * Only truncate for all-ASCII identifiers for historical purposes. Folks using non-ASCII characters in database names will need to specify the datname exactly during login. * ERROR for long identifiers instead of automatically truncating (upthread this was considered a non-starter since this behavior has been around for so long). * Revert the patch, leaving multibyte database names potentially broken (AFAIK Bertrand's initial report is the only one). * Do nothing, so folks who previously relied on the truncation will now have to specify the datname exactly during login as of >= v17. [0] https://postgr.es/m/158506.1732120196%40sss.pgh.pa.us -- nathan