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 1uZ3RC-00FZpt-BC for pgsql-performance@arkaria.postgresql.org; Tue, 08 Jul 2025 08:12:26 +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 1uZ3RA-006TOL-0l for pgsql-performance@arkaria.postgresql.org; Tue, 08 Jul 2025 08:12:24 +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 1uZ3R9-006TO8-IK for pgsql-performance@lists.postgresql.org; Tue, 08 Jul 2025 08:12:24 +0000 Received: from mail-ed1-x52c.google.com ([2a00:1450:4864:20::52c]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1uZ3R8-006BbL-0x for pgsql-performance@postgresql.org; Tue, 08 Jul 2025 08:12:23 +0000 Received: by mail-ed1-x52c.google.com with SMTP id 4fb4d7f45d1cf-60dffae17f3so6872603a12.1 for ; Tue, 08 Jul 2025 01:12:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1751962340; x=1752567140; darn=postgresql.org; h=to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=xECelx4LCfh5WqTrtSwloXaUTzOfCr/1QFHa7vggAcg=; b=AD/HU5VHB1mskWinZ32tcikWUExajMHmw2axxavQM1FSy/0xLGzO2TsWpyoetWNbJz 9CBaHs6ne6Kw1l5eMrY7BHedyXf+ZTKv8exBL1KZjGthXlpYXFx/T8pPbOAOQPQmu3ny Z8dmU9bFTqxPoCQP8LgMq1YoHS1IG0bTuxZB3f+mZk8XepI3zBOTr1m54pUojSThJmY3 RJ2bejYSEYPhXJPzzFsAQEy+eNh5MkRHyBX50c+nTpqLcDhcd6OQcRGyQOipo9nVfYRQ AIINoygPKjSbF9NdeqZJQnKlg297ChH9NWJjQnxcixh4pJM8NwnL/JrlXwRngs6QkmGd s2FQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1751962340; x=1752567140; h=to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=xECelx4LCfh5WqTrtSwloXaUTzOfCr/1QFHa7vggAcg=; b=IGm3skxTrXU9CEOwKr4cxhaXUzWgbhHcjc8Y7nCz20ZAEuKQgKh74zbxzRw7GdCWSU YbaStFAWrfs1hUwdjg+kLLP5eHcJ+1IBgZ5T0extr54i81alk/PUz2p6JBpJVs4dXmBC BCFeuJebpD1R63NdItxXeivXWRiVSEDLkQ5z+Z0vpPkDAjyzyt+ukqvNQXkf9FUfDDzr V58X0hRbX/MSlNSPEGfc0BLZxa+Ragn4gBYgK0vAAHnVD899Yk21wWkAwqCuP3Lwo65x f18rok5x6STOCwBFlfmWkG2b80LOvbUcUOTPH3/ZfoeYZMNXAALPrSml6tF7V7Bnzl2M 6/aA== X-Gm-Message-State: AOJu0Yx+tAlfhaI5/vuS8sUDePVpydPoy89Z0ykWv1HLULUAA2M3la0c Xh3u77byIo8BtWR0lwPRopcVEJF070CR1TLpUxompTAIO/XiX9nfVnT02VAE04KrtFycXOEX6F0 0MYy0FKRtRRMQKfWk5MdVxqPEAM+6hX5X/VfV X-Gm-Gg: ASbGncuVZLqGtxjVEmQmCwFwWduchoLjsO4QfTkOiL5p2BUuYi7gAliJAlxlX+lzjQo jD+YzKqP1zyG6JTi6DgwIS8uKaA+PGjXbZqfgwGsvMSTb7xHkVk8wplCKQuc8dE/MGqwEog+oJS XQnr9cNNM3lqG0DNwuaRIKIbK7LbRYbPPEC+3jTKIUSm7LS8Q28g0041+rvRep/mJVbWyVxpJIc IVze2JCsxdvuRzC X-Google-Smtp-Source: AGHT+IFXdXa4NQLErW+hnBZgceZ+jV+s1KTck7xg6DpNz2ci+vpCGoc6xJZxWYtjul5Kh6vNk1tv+Rej5nvh86nqmZU= X-Received: by 2002:a17:907:9709:b0:ae6:abef:6609 with SMTP id a640c23a62f3a-ae6abef68a7mr341373766b.53.1751962340172; Tue, 08 Jul 2025 01:12:20 -0700 (PDT) MIME-Version: 1.0 From: Dharin Shah Date: Tue, 8 Jul 2025 10:12:09 +0200 X-Gm-Features: Ac12FXzWqKUJG5h8P4rRpBz5TrzF1A70QEaonJ91FSXFXh43t8fFkO4V9hztHno Message-ID: Subject: WAL Replay Buffer Invalidation Conflicts During Page Truncation on Read Replicas To: pgsql-performance@postgresql.org Content-Type: multipart/alternative; boundary="000000000000f227e60639668434" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --000000000000f227e60639668434 Content-Type: text/plain; charset="UTF-8" Hello All, I'm experiencing significant read query blocking on Aurora PostgreSQL read replicas during VACUUM relation truncation, particularly with TOAST tables. This affects a high-traffic service (~3000 req/sec) and causes application downtime. *Problem Summary:* WAL replay of relation truncation operations on read replicas triggers buffer invalidation that requires AccessExclusive locks, blocking concurrent read queries for extended periods. *Environment Details:* - Aurora PostgreSQL (read replica setup) - Workload: Async writes to primary, read-only queries on replica - TOAST table with ~4KB average compressed column size - maintenance_work_mem: 2087MB * Observed Behavior:* * [23541]: select gzipped_dto from dl1_0 where (dl1_0.entity_id,dl1_0.language_code) in (($1,$2)) 2025-06-28 11:57:34 UTC: process 23574 still waiting for AccessShareLock on relation 20655 after 1000.035 ms* The blocking coincides with substantial TOAST table truncation: *2025-06-28 11:57:39 UTC::@:[8399]:LOG: automatic vacuum of table "delivery.pg_toast.pg_toast_20652": index scans: 1 pages: 212964 removed, 434375 remain, 78055 scanned (12.06% of total) tuples: 198922 removed, 2015440 remain, 866 are dead but not yet removable removable cutoff: 1066590201, which was 783 XIDs old when operation ended frozen: 3 pages from table (0.00% of total) had 19 tuples frozen index scan needed: 39600 pages from table (6.12% of total) had 199413 dead item identifiers removed index "pg_toast_20652_index": pages: 16131 in total, 35 newly deleted, 7574 currently deleted, 7539 reusable I/O timings: read: 173469.911 ms, write: 0.000 ms avg read rate: 9.198 MB/s, avg write rate: 0.000 MB/s buffer usage: 220870 hits, 213040 misses, 0 dirtied WAL usage: 0 records, 0 full page images, 0 bytes system usage: CPU: user: 2.97 s, system: 1.86 s, elapsed: 180.95 s* *Analysis:* The vacuum reclaimed 212,964 pages (33% of the relation), indicating legitimate space reclamation. With maintenance_work_mem set to 2087MB, memory constraints aren't limiting the vacuum process. However, WAL replay of the truncation operation on the read replica requires invalidating these pages from shared_buffers, which conflicts with ongoing read queries. *Questions for Discussion:* 1. Batch Buffer Invalidation: Could buffer invalidation during WAL replay be batched or deferred to reduce lock contention duration? 2. Replica-Specific Truncation Policy: Should read replicas have different truncation thresholds (REL_TRUNCATE_MINIMUM/REL_TRUNCATE_FRACTION) to balance space reclamation against query availability? 3. Cloud-Native Considerations: In cloud environments like Aurora with separate storage layers, is immediate buffer invalidation during truncation replay necessary, or could this be optimized? 4. Lock Duration Optimization: The current truncation process holds AccessExclusive locks during the entire invalidation. Could this be shortened through incremental processing? *Potential Approaches:* - Implement configurable truncation behavior for standby servers - Add batching/throttling to buffer invalidation during WAL replay - Provide a way to defer truncation replay during high read activity periods This issue particularly affects TOAST tables due to their chunked storage pattern creating more opportunities for dead space, but the core problem applies to any significant relation truncation on read replicas. Has anyone else encountered this issue? Are there existing configuration options or patches that address WAL replay buffer invalidation conflicts? Thanks for any insights. Thanks, Dharin --000000000000f227e60639668434 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hello All,

I'm experiencing si= gnificant read query blocking on Aurora PostgreSQL read replicas during VAC= UUM relation truncation, particularly with TOAST tables. This affects a hig= h-traffic service (~3000 req/sec) and causes application downtime.

<= b>Problem Summary:
=C2=A0 WAL replay of relation truncation operatio= ns on read replicas triggers buffer invalidation that requires AccessExclus= ive locks, blocking concurrent read queries for extended periods.

Environment Details:
=C2=A0 - Aurora PostgreSQL (read replica setup= )
=C2=A0 - Workload: Async writes to primary, read-only queries on repli= ca
=C2=A0 - TOAST table with ~4KB average compressed column size
=C2= =A0 - maintenance_work_mem: 2087MB

=C2=A0Observed Behavior:=C2=A0 [23541]: select gzipped_dto from <table> dl1_0 where (dl1= _0.entity_id,dl1_0.language_code) in (($1,$2))
=C2=A0 2025-06-28 11:57:3= 4 UTC: process 23574 still waiting for AccessShareLock on relation 20655 af= ter 1000.035 ms


=C2=A0 The blocking coincides with substantial T= OAST table truncation:

2025-06-28 11:57:39 UTC::@:[8399]:LOG: =C2= =A0automatic vacuum of table "delivery.pg_toast.pg_toast_20652": = index scans: 1
pages: 212964 removed, 434375 remain, 78055 scanned (12.= 06% of total)
tuples: 198922 removed, 2015440 remain, 866 are dead but = not yet removable
removable cutoff: 1066590201, which was 783 XIDs old = when operation ended
frozen: 3 pages from table (0.00% of total) had 19= tuples frozen
index scan needed: 39600 pages from table (6.12% of tota= l) had 199413 dead item identifiers removed
index "pg_toast_20652_= index": pages: 16131 in total, 35 newly deleted, 7574 currently delete= d, 7539 reusable
I/O timings: read: 173469.911 ms, write: 0.000 ms
= avg read rate: 9.198 MB/s, avg write rate: 0.000 MB/s
buffer usage: 220= 870 hits, 213040 misses, 0 dirtied
WAL usage: 0 records, 0 full page im= ages, 0 bytes
system usage: CPU: user: 2.97 s, system: 1.86 s, elapsed:= 180.95 s


Analysis:
=C2=A0 The vacuum reclaimed 212,96= 4 pages (33% of the relation), indicating legitimate space reclamation. Wit= h maintenance_work_mem set to 2087MB, memory constraints aren't limitin= g the vacuum process. However, WAL replay of the truncation
=C2=A0 opera= tion on the read replica requires invalidating these pages from shared_buff= ers, which conflicts with ongoing read queries.

Questions for Dis= cussion:

=C2=A0 1. Batch Buffer Invalidation: Could buffer inval= idation during WAL replay be batched or deferred to reduce lock contention = duration?
=C2=A0 2. Replica-Specific Truncation Policy: Should read repl= icas have different truncation thresholds (REL_TRUNCATE_MINIMUM/REL_TRUNCAT= E_FRACTION) to balance space reclamation against query availability?
=C2= =A0 3. Cloud-Native Considerations: In cloud environments like Aurora with = separate storage layers, is immediate buffer invalidation during truncation= replay necessary, or could this be optimized?
=C2=A0 4. Lock Duration O= ptimization: The current truncation process holds AccessExclusive locks dur= ing the entire invalidation. Could this be shortened through incremental pr= ocessing?

Potential Approaches:
=C2=A0 - Implement configu= rable truncation behavior for standby servers
=C2=A0 - Add batching/thro= ttling to buffer invalidation during WAL replay
=C2=A0 - Provide a way t= o defer truncation replay during high read activity periods

This iss= ue particularly affects TOAST tables due to their chunked storage pattern c= reating more opportunities for dead space, but the core problem applies to = any significant relation truncation on read replicas.

Has anyone els= e encountered this issue? Are there existing configuration options or patch= es that address WAL replay buffer invalidation conflicts?

Thanks for any insights.

Thanks,
Dharin
--000000000000f227e60639668434--