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 1tDX3V-001Lvx-34 for pgsql-bugs@arkaria.postgresql.org; Tue, 19 Nov 2024 22:50:45 +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 1tDX3T-000KxV-O3 for pgsql-bugs@arkaria.postgresql.org; Tue, 19 Nov 2024 22:50:43 +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 1tDX3T-000KxG-EX for pgsql-bugs@lists.postgresql.org; Tue, 19 Nov 2024 22:50:43 +0000 Received: from mail-qt1-x82c.google.com ([2607:f8b0:4864:20::82c]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1tDX3P-002lmd-Kn for pgsql-bugs@lists.postgresql.org; Tue, 19 Nov 2024 22:50:41 +0000 Received: by mail-qt1-x82c.google.com with SMTP id d75a77b69052e-46096aadaf0so38310891cf.2 for ; Tue, 19 Nov 2024 14:50:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1732056638; x=1732661438; 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=Ah4ejiYIf4hm+d9kENgpcB67LQCazy6Lu99lx0N07Hc=; b=EC7rKyOiC4iw67GWZDi041Y2kOJfH6xY5ceLR3erpBwFyLleMSzSfzX+8h9Fb5RUie QEPU/MljUMjWshBOy+Um6Zzu+/RHd/qjWrozOF9P3k1ipLzu+zh/Yu+PMZvw+42Oytpe kyKtjys1jDCl3nol2d35CW9DLmkl+zLNg1Cje3qZpW+7r/1h2Eunk7OwJHFFwGqO/Wp+ YSk9igRCm8BQ4ljUmd/UN5jh6vlrfTviyRqDo8hYFUTs8IK8b93aqwv1vTpxvEC6sWQd t1is0cmyoV8Rm2pq1Ad/Ra2E9CS7tYU62t6dIzdXvcpc4weQ6YtmvBBWaYeRMn3UtM7D KWcA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732056639; x=1732661439; 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=Ah4ejiYIf4hm+d9kENgpcB67LQCazy6Lu99lx0N07Hc=; b=nxHxy0J2LUPgoD9KQhIFk8/s3t6sojotg5t3oRT/JwdGmg2ub3JrmaUQ1ztfJGXVXF 37arkbb24+Uq+kQY9YvyJkbDUwIo5bjQrL/huf7FQhfqvjhzgHIVn+K+JpweUOHEOr5R muALCwISW2XQfyWMDOZ2a+2Cqkzy1U2MpVpO+4p+g40jHUtoDg3FgQmw67RqI7j883qf 2oLsuMUI1ReBMFP7WZNEv+T0cIqJ8e1AxNraZ7wpNgmS7FuZJiUdE0S0rvjyJkTzD+XR WyqN2peDsERjVKj+9DZFTlCOTntAdef9qtQrYZs3p2hPF34qvxHzizvhu6ByqsLjKVUX A4wQ== X-Forwarded-Encrypted: i=1; AJvYcCXT0Pnfu9pRsNiPOaEGL1O9Zkc7CzYhwKkd1qrB08LpIzHORBjDZKMvtIhNemA4Yhy8jom8pu9Z5JLE@lists.postgresql.org X-Gm-Message-State: AOJu0YyuiNwwKky+uC8pjr8KKY8Okw2XJOd4eIa1NqKIfLR6Ose7dU9Z JDaHKjn1DBdpb2DMrscAlv2s7BhWdqVi0SWBMj774ieZef7v14lc X-Google-Smtp-Source: AGHT+IGaAH4SML0nlthDkh2o0w2ZgWKEhbeG+OlaEU5rbcj3gPe/gS0WHzq66P13MEbdiu7asaKj2w== X-Received: by 2002:a05:622a:1b94:b0:461:414e:5abe with SMTP id d75a77b69052e-4647a3faed7mr5301801cf.43.1732056638593; Tue, 19 Nov 2024 14:50:38 -0800 (PST) Received: from nathan (162-195-168-172.lightspeed.stlsmo.sbcglobal.net. [162.195.168.172]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-464685d00c2sm1806271cf.27.2024.11.19.14.50.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Nov 2024 14:50:38 -0800 (PST) Date: Tue, 19 Nov 2024 16:50:36 -0600 From: Nathan Bossart To: Tom Lane Cc: adam@labkey.com, Bertrand Drouvot , 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: <18711-7503ee3e449d2c47@postgresql.org> <3072825.1731866414@sss.pgh.pa.us> <3796535.1732044807@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <3796535.1732044807@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Tue, Nov 19, 2024 at 02:33:27PM -0500, Tom Lane wrote: > I did think of a way that we could approximate encoding-correct > truncation here, relying on the fact that what's in pg_database > is encoding-correct according to somebody: > > 1. If NAMEDATALEN-1'th byte is ASCII (high bit clear), just truncate > there and look up as usual. > > 2. If it's non-ASCII, truncate there and try to look up. On success, > we're good. On failure, if the next-to-last byte is non-ASCII, > truncate that too and try to look up. Repeat a maximum of > MAX_MULTIBYTE_CHAR_LEN-1 times before failing. > > I think this works unconditionally so long as all entries in > pg_database.datname are in the same encoding. If there's a > mixture of encodings (which we don't forbid) then in principle > you could probably select a database other than the one the > client thought it was asking for. But that seems mighty > improbable, and the answer can always be "so connect using > the name as it appears in the catalog". That's an interesting idea. That code would probably need to live in GetDatabaseTuple(), but it seems doable. We might be able to avoid the "mighty improbable" case by always truncating up to MAX_MULTIBYTE_CHAR_LEN-1 times and failing if there are multiple matches, too. -- nathan