@@ -348,6 +348,8 @@ static void pgstat_send_tabstats(TimestampTz now, bool disconnect);
348
348
static void pgstat_send_tabstat (PgStat_MsgTabstat * tsmsg , TimestampTz now );
349
349
static void pgstat_update_dbstats (PgStat_MsgTabstat * tsmsg , TimestampTz now );
350
350
static void pgstat_send_funcstats (void );
351
+ static void pgstat_wal_initialize (void );
352
+ static bool pgstat_wal_pending (void );
351
353
static void pgstat_send_slru (void );
352
354
static HTAB * pgstat_collect_oids (Oid catalogid , AttrNumber anum_oid );
353
355
static bool pgstat_should_report_connstat (void );
@@ -882,17 +884,10 @@ pgstat_report_stat(bool disconnect)
882
884
883
885
/*
884
886
* Don't expend a clock check if nothing to do.
885
- *
886
- * To determine whether any WAL activity has occurred since last time, not
887
- * only the number of generated WAL records but also the numbers of WAL
888
- * writes and syncs need to be checked. Because even transaction that
889
- * generates no WAL records can write or sync WAL data when flushing the
890
- * data pages.
891
887
*/
892
888
if (!have_relation_stats &&
893
889
pgStatXactCommit == 0 && pgStatXactRollback == 0 &&
894
- pgWalUsage .wal_records == prevWalUsage .wal_records &&
895
- WalStats .m_wal_write == 0 && WalStats .m_wal_sync == 0 &&
890
+ !pgstat_wal_pending () &&
896
891
!have_function_stats && !disconnect )
897
892
return ;
898
893
@@ -3168,12 +3163,7 @@ pgstat_initialize(void)
3168
3163
{
3169
3164
Assert (!pgstat_is_initialized );
3170
3165
3171
- /*
3172
- * Initialize prevWalUsage with pgWalUsage so that pgstat_send_wal() can
3173
- * calculate how much pgWalUsage counters are increased by subtracting
3174
- * prevWalUsage from pgWalUsage.
3175
- */
3176
- prevWalUsage = pgWalUsage ;
3166
+ pgstat_wal_initialize ();
3177
3167
3178
3168
/* Set up a process-exit hook to clean up */
3179
3169
before_shmem_exit (pgstat_shutdown_hook , 0 );
@@ -3415,6 +3405,32 @@ pgstat_send_wal(bool force)
3415
3405
MemSet (& WalStats , 0 , sizeof (WalStats ));
3416
3406
}
3417
3407
3408
+ static void
3409
+ pgstat_wal_initialize (void )
3410
+ {
3411
+ /*
3412
+ * Initialize prevWalUsage with pgWalUsage so that pgstat_send_wal() can
3413
+ * calculate how much pgWalUsage counters are increased by subtracting
3414
+ * prevWalUsage from pgWalUsage.
3415
+ */
3416
+ prevWalUsage = pgWalUsage ;
3417
+ }
3418
+
3419
+ /*
3420
+ * To determine whether any WAL activity has occurred since last time, not
3421
+ * only the number of generated WAL records but also the numbers of WAL
3422
+ * writes and syncs need to be checked. Because even transaction that
3423
+ * generates no WAL records can write or sync WAL data when flushing the
3424
+ * data pages.
3425
+ */
3426
+ static bool
3427
+ pgstat_wal_pending (void )
3428
+ {
3429
+ return pgWalUsage .wal_records != prevWalUsage .wal_records ||
3430
+ WalStats .m_wal_write != 0 ||
3431
+ WalStats .m_wal_sync != 0 ;
3432
+ }
3433
+
3418
3434
/* ----------
3419
3435
* pgstat_send_slru() -
3420
3436
*
0 commit comments