]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
Flush statistics during idle periods in parallel apply worker.
authorAmit Kapila <akapila@postgresql.org>
Mon, 20 Apr 2026 05:01:11 +0000 (10:31 +0530)
committerAmit Kapila <akapila@postgresql.org>
Mon, 20 Apr 2026 05:01:11 +0000 (10:31 +0530)
Parallel apply workers previously failed to report statistics while
waiting for new work in the main loop. This resulted in the stats from the
most recent transaction remaining unbuffered, leading to arbitrary
reporting delays—particularly when streamed transactions were infrequent.

This commit ensures that statistics are explicitly flushed when the worker
is idle, providing timely visibility into accumulated worker activity.

Author: Zhijie Hou <houzj.fnst@fujitsu.com>
Reviewed-by: Chao Li <li.evan.chao@gmail.com>
Reviewed-by: Amit Kapila <amit.kapila16@gmail.com>
Backpatch-through: 16, where it was introduced
Discussion: https://postgr.es/m/TYRPR01MB1419579F217CC4332B615589594202@TYRPR01MB14195.jpnprd01.prod.outlook.com

src/backend/replication/logical/applyparallelworker.c

index 798e8d85b3efcf848ae061bb5dd4bc51b6727bfc..e10f653fde798566b57510ebaa2e11eb24123b2f 100644 (file)
@@ -815,6 +815,15 @@ LogicalParallelApplyLoop(shm_mq_handle *mqh)
 
                                if (rc & WL_LATCH_SET)
                                        ResetLatch(MyLatch);
+
+                               /*
+                                * Force stats reporting to avoid long delays. There can be
+                                * long idle gaps before the leader assigns the next
+                                * transaction, and the only opportunity to report stats
+                                * during such gaps is here.
+                                */
+                               if ((rc & WL_TIMEOUT) && !IsTransactionState())
+                                       pgstat_report_stat(true);
                        }
                }
                else