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 1uZofc-008c4R-Bp for pgpool-hackers@arkaria.postgresql.org; Thu, 10 Jul 2025 10:38:28 +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 1uZofa-00BB7z-Bp for pgpool-hackers@arkaria.postgresql.org; Thu, 10 Jul 2025 10:38:26 +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 1uZofa-00BB7s-45 for pgpool-hackers@lists.postgresql.org; Thu, 10 Jul 2025 10:38:26 +0000 Received: from meldrar.postgresql.org ([2a02:c0:301:0:ffff::31]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1uZofY-006pGr-1G for pgpool-hackers@lists.postgresql.org; Thu, 10 Jul 2025 10:38:26 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=postgresql.org; s=20171124; h=Content-Transfer-Encoding:Content-Type: Mime-Version:References:In-Reply-To:From:Subject:To:Message-Id:Date:Sender: Reply-To:Cc:Content-ID:Content-Description; bh=hnOk6DE6IQdZdWcXJqTMv5v8LjcrOqu452q1yWtdz4w=; b=OPt5Csa7FD3+FRztkjv58qOurT oLlDWBmjyQAa86AdjO8HoNPQSwLmVmElqGowaP+uIKuQmKeCcgxpa6wMGjA/fvz6GWkXEq9m7jP2G l3yoDuw6eqoJLaYlEtY29Xeaac0KtDcsLLTKYuOERj1lB3UBJLDOJVnHMcwUawKtMm1NDFUmGylRO VrxXC0cLCIUN7LeLbtYbGtjZaOuqex4cRVcYCONbxr9OhMFz1MyrY6+25kWVFQaIdM8TAW7WKl3TP 84h7swiVVUk/AAiySA+clNRAd3kIwNJGalW/eS3ExuURMhHRSAoanwGyunLDpCUWZuTSVooT2s9dn McLxJNaw==; Received: from [2409:11:4120:300:1c94:37f:efca:c15f] (helo=localhost) by meldrar.postgresql.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256 (Exim 4.96) (envelope-from ) id 1uZofV-007uJ8-1W for pgpool-hackers@lists.postgresql.org; Thu, 10 Jul 2025 10:38:24 +0000 Date: Thu, 10 Jul 2025 19:38:13 +0900 (JST) Message-Id: <20250710.193813.29844576698476540.ishii@postgresql.org> To: pgpool-hackers@lists.postgresql.org Subject: Re: Feature: implement NegotiateProtocolVersion message From: Tatsuo Ishii In-Reply-To: <20250709.160004.803224268243106375.ishii@postgresql.org> References: <20250708.112133.1324153277751075866.ishii@postgresql.org> <20250709.160004.803224268243106375.ishii@postgresql.org> X-Mailer: Mew version 6.8 on Emacs 26.3 Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Host-Lookup-Failed: Reverse DNS lookup failed for 2409:11:4120:300:1c94:37f:efca:c15f (failed) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk >> NegotiateProtocolVersion message is a message sent from backend to >> frontend. After a startup message is sent from frontend to backend, >> and the minor protocol version in the startup message is not supported >> by the backend, the backend sends back a NegotiateProtocolVersion >> message along with the latest minor protocol version it supports. >> >> For example, PostgreSQL 18 client could request a protocol version 3.2 >> against PostgreSQL 17 server, then the PG17 server sends back the >> NegotiateProtocolVersion message with protocol version 3.0 since it >> does not support 3.2. If the PG18 client accepts it, then from now on >> the protocol version 3.0 is used for the communication. >> >> At this point, as PG18's psql (or libpq) uses protocol version 3.0 by >> default, PG18 (or before) server will not send back the >> NegotiateProtocolVersion message because the versions support 3.0. >> >> The only case when 3.2 is used, is PG18's psql (or libpq) uses a >> connection option max_protocol_version (or environment variable >> PGMAXPROTOCOLVERSION) being set to "3.2". I don't know if the case >> happen in the wild after PG18 is released, but I would like to prepare >> for the situation by implementing NegotiateProtocolVersion message in >> Pgpool-II 4.7. Attached patch does followings for the purpose. >> >> - Add ProcessNegotiateProtocol() to pool_do_auth() to process the >> message while handling a startup message. It reads the message from >> all backend, then forward it to frontend. The message is saved in >> ConnectionInfo for the case below. It also save the major and minor >> protocol version after negotiation to POOL_CONNECTION_POOL_SLOT for >> later use. The version numbers are also saved to ConnectionInfo so >> that pcp_proc_info shows them. >> >> - When a client connects to pgpool, it looks for cached connections in >> the connection: pgpool tries to match the startup message with the >> one in the connection pool. Since the startup message in the >> connection pool is saved at the time when the client connects to >> pgpool, it is possible that two connection cache are created with >> same user and database. Suppose there's a connection cache with a >> startup message having protocol version 3.0, and a new client tries >> to connect to pgpool using protocol version 3.2. Pgpool looks for a >> connection cache with the startup message having protocol version >> 3.2, not 3.0. As a result a new connection cache entry is created >> with protocol version 3.2. >> >> - When a client uses the connection pool, the saved >> NegotiateProtocolVersion message is sent to frontend to emulate the >> protocol negotiation. >> >> - The frontend/backend protocol 3.2 changes the BackendKeyData message >> format but it's not implemented in this patch yet. I will work on it >> later on. > > Attached is the v2 patch fixing bug in v1. Also some protocol related > macros are imported from PostgreSQL. v2 patch pushed. Best regards, -- Tatsuo Ishii SRA OSS K.K. English: http://www.sraoss.co.jp/index_en/ Japanese:http://www.sraoss.co.jp