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 1unzKb-00E3oH-Sd for pgpool-hackers@arkaria.postgresql.org; Mon, 18 Aug 2025 12:51:23 +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 1unzKb-00GQZu-6y for pgpool-hackers@arkaria.postgresql.org; Mon, 18 Aug 2025 12:51: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 1unzKb-00GQZm-1B for pgpool-hackers@lists.postgresql.org; Mon, 18 Aug 2025 12:51:21 +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 1unzKY-000W6S-2P for pgpool-hackers@lists.postgresql.org; Mon, 18 Aug 2025 12:51:21 +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:Cc:To:Message-Id:Date:Sender :Reply-To:Content-ID:Content-Description; bh=1AEY9vxo76PY3Mrcd+IzS68YuCpvGKbWc7BH92Z77vE=; b=fxYr1pyVzwrosGKtnAWov3Nn5d jBSZBZ3DBapIMKeBhyBhXsF+Z/B3qF0t5qJ93q6FQ3HTTRMNFPy6yIauNgcbfxr6xHr19M8xoPgow sY6VbKn9qEKxo9aWdUsjnLyfJpWB0RVfLukpBnLDMqTwvPr7nQO7Uz4CvSrmIcZWqYxAOaIOB6udj gxZ/s2BsVar/6C2wqvj0/VxbahvQYs4wIu93WlqMtOsQZrkfVeDIfsjjtRIG8F8icyPwnskh/DAAS CEbCG+VN0MznJp/sGb5JXN+eX4LzXhOX5tYkX1d/oDvlGJc2on92W+V0lFKwKrVaBLPDoeDrb8tEq X/5EUa2Q==; Received: from [2409:11:4120:300:eee0:b3f1:88d3:8d22] (helo=localhost) by meldrar.postgresql.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256 (Exim 4.96) (envelope-from ) id 1unzKV-000zbY-04; Mon, 18 Aug 2025 12:51:18 +0000 Date: Mon, 18 Aug 2025 21:51:06 +0900 (JST) Message-Id: <20250818.215106.1325564662459771705.ishii@postgresql.org> To: nadav@tailorbrands.com Cc: pgpool-hackers@lists.postgresql.org Subject: Re: Proposal: recent access based routing for primary-replica setups From: Tatsuo Ishii In-Reply-To: References: X-Mailer: Mew version 6.8 on Emacs 26.3 Mime-Version: 1.0 Content-Type: Text/Plain; charset=iso-2022-jp Content-Transfer-Encoding: 7bit X-Host-Lookup-Failed: Reverse DNS lookup failed for 2409:11:4120:300:eee0:b3f1:88d3:8d22 (failed) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hello Nadav, Thank you for the proposal. I have a few questions. > Hello all, > > My name is Nadav Shatz, I’m the CTO at Tailor Brands and have been working > with PostgreSQL in high-traffic, distributed environments for many years. > Most of my focus has been on backend architecture, scaling, and performance > optimization, and I’m a long-time user and admirer of the Postgres > ecosystem. > > I’d like to propose adding a feature to pgpool-II for *recent access based > routing* in primary-replica setups. The idea is similar to what we’ve > described in this article > , > and is also reflected in this pgcat PR > . The core concept is to > route read queries to the primary if they occur shortly after a write, > reducing replica lag inconsistencies while still benefiting from read > scaling. > > *How it would work (high-level):* > > > - > > > *External “effective lag” via config (hot-reloaded): *Instead of relying on > pgpool-II’s replication delay checks (which don’t map well to Aurora > semantics), we’ll expose a *config value* representing the effective > replica lag (or directly the TTL to use for “recency”). This value > is *pushed > by an external controller* and *hot-reloaded* (no restarts). The > relevant knobs might look like: > > - > > enable_recent_access_routing (boolean, default off) > - > > recent_access_ttl_ms (integer, default 0, can be hot-reloaded) If my understanding is correct, the "external controller" updates "recent_access_ttl_ms" to let pgpool know the current delay of replica. My question is, what if there are multiple replicas. In this case the "external controller" calculates the average latency of each replica? Another question is, how often the external controller updates and reload pgpool.conf. If it's like every second, probably it could give unacceptable load to pgpool because reloading pgpool.conf is expensive operation. > enable_query_parser (boolean, required for this feature, default off) What does this do? Why do you need this? > *In-memory recent-access map: *Each worker maintains a lightweight per-DB > in-memory map of *recently written relations*. On any write Is "per-DB in-memory map" in shared memory? > (INSERT/UPDATE/DELETE/UPSERT/TRUNCATE), we record the touched relations > with a TTL derived from recent_access_ttl_ms. Entries expire > automatically; writes refresh them. How do you automatically expire the entries? Are you going to implement something like a auto sweeper process? > *Routing + query parsing: *For incoming statements we parse enough to > answer two questions: (1) is it a read or a write? and (2) which relations > are referenced? If a read touches any “recently written” relation, we *force > route to primary*; otherwise we allow normal read load-balancing to > replicas. Pgpool-II already does (1) and (2). > *Notes on behavior & ops:* > > > - > > *Config & hot reload:* Operators (or an external controller) can update > recent_access_ttl_ms dynamically and trigger hot reload to adapt to > changing conditions―no reliance on Aurora internals. > - > > *Safety levers:* a global max TTL, optional allow/deny lists, and > metrics (e.g., “reads forced to primary due to recency”) for visibility. Please elaborate more on this. Allow/deny what? > *Defaults & compatibility:* all defaults are safe/off; enabling requires > explicit opt-in. Sounds good. > I’ll prepare the code changes and send a patch/PR, but before diving in I > wanted to check if anyone has *objections, concerns, or preferred > alternatives*―particularly around parser hooks, shared memory use, or > hot-reload mechanics in pgpool-II. Probably you should consider adding a pcp command to notice pgpool the "recent_access_ttl_ms". That is far more efficient than reloading pgpool.conf. > Thanks for considering, > -- > Nadav Shatz > Tailor Brands | CTO Best regards, -- Tatsuo Ishii SRA OSS K.K. English: http://www.sraoss.co.jp/index_en/ Japanese:http://www.sraoss.co.jp