Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit f4694e0

Browse files
committed
Fix some gaps in pg_stat_io with WAL receiver and WAL summarizer
The WAL receiver and WAL summarizer processes gain each one a call to pgstat_report_wal(), to make sure that they report their WAL statistics to pgstats, gathering data for pg_stat_io. In the WAL receiver, the stats reports are timed with status updates sent to the primary, that depend on wal_receiver_status_interval and wal_receiver_timeout. This is a conservative choice, but perhaps we could be more aggressive with the frequency of the stats reports. An interesting historical fact is that the WAL receiver does writes and syncs of WAL, but it has never reported its statistics to pgstats in pg_stat_wal. In the WAL summarizer, the stats reports are done each time the process waits for WAL. While on it, pg_stat_io is adjusted so as these two processes do not report any rows when IOObject is not WAL, making the view easier to use with less rows. Two tests are added in TAP, checking statistics for the WAL summarizer and the WAL receiver. Status updates in the WAL receiver are currently possible in the recovery test 001_stream_rep.pl. Reviewed-by: Bertrand Drouvot <bertranddrouvot.pg@gmail.com> Discussion: https://postgr.es/m/Z8UKZyVSHUUQJHNb@paquier.xyz
1 parent 54d2360 commit f4694e0

File tree

5 files changed

+39
-1
lines changed

5 files changed

+39
-1
lines changed

src/backend/postmaster/walsummarizer.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#include "common/blkreftable.h"
3434
#include "libpq/pqsignal.h"
3535
#include "miscadmin.h"
36+
#include "pgstat.h"
3637
#include "postmaster/auxprocess.h"
3738
#include "postmaster/interrupt.h"
3839
#include "postmaster/walsummarizer.h"
@@ -1636,6 +1637,9 @@ summarizer_wait_for_wal(void)
16361637
sleep_quanta -= pages_read_since_last_sleep;
16371638
}
16381639

1640+
/* Report pending statistics to the cumulative stats system. */
1641+
pgstat_report_wal(false);
1642+
16391643
/* OK, now sleep. */
16401644
(void) WaitLatch(MyLatch,
16411645
WL_LATCH_SET | WL_TIMEOUT | WL_EXIT_ON_PM_DEATH,

src/backend/replication/walreceiver.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -583,6 +583,16 @@ WalReceiverMain(const void *startup_data, size_t startup_data_len)
583583
*/
584584
bool requestReply = false;
585585

586+
/*
587+
* Report pending statistics to the cumulative stats
588+
* system. This location is useful for the report as it
589+
* is not within a tight loop in the WAL receiver, to
590+
* avoid bloating pgstats with requests, while also making
591+
* sure that the reports happen each time a status update
592+
* is sent.
593+
*/
594+
pgstat_report_wal(false);
595+
586596
/*
587597
* Check if time since last receive from primary has
588598
* reached the configured limit.

src/backend/utils/activity/pgstat_io.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -435,12 +435,22 @@ pgstat_tracks_io_object(BackendType bktype, IOObject io_object,
435435
*/
436436
no_temp_rel = bktype == B_AUTOVAC_LAUNCHER || bktype == B_BG_WRITER ||
437437
bktype == B_CHECKPOINTER || bktype == B_AUTOVAC_WORKER ||
438-
bktype == B_STANDALONE_BACKEND || bktype == B_STARTUP;
438+
bktype == B_STANDALONE_BACKEND || bktype == B_STARTUP ||
439+
bktype == B_WAL_SUMMARIZER || bktype == B_WAL_WRITER ||
440+
bktype == B_WAL_RECEIVER;
439441

440442
if (no_temp_rel && io_context == IOCONTEXT_NORMAL &&
441443
io_object == IOOBJECT_TEMP_RELATION)
442444
return false;
443445

446+
/*
447+
* Some BackendTypes only perform IO under IOOBJECT_WAL, hence exclude all
448+
* rows for all the other objects for these.
449+
*/
450+
if ((bktype == B_WAL_SUMMARIZER || bktype == B_WAL_RECEIVER ||
451+
bktype == B_WAL_WRITER) && io_object != IOOBJECT_WAL)
452+
return false;
453+
444454
/*
445455
* Some BackendTypes do not currently perform any IO in certain
446456
* IOContexts, and, while it may not be inherently incorrect for them to

src/bin/pg_walsummary/t/002_blocks.pl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,13 @@
4646
EOM
4747
ok($result, "WAL summarization caught up after insert");
4848

49+
# The WAL summarizer should have generated some IO statistics.
50+
my $stats_reads = $node1->safe_psql(
51+
'postgres',
52+
qq{SELECT sum(reads) > 0 FROM pg_stat_io
53+
WHERE backend_type = 'walsummarizer' AND object = 'wal'});
54+
is($stats_reads, 't', "WAL summarizer generates statistics for WAL reads");
55+
4956
# Find the highest LSN that is summarized on disk.
5057
my $summarized_lsn = $node1->safe_psql('postgres', <<EOM);
5158
SELECT MAX(end_lsn) AS summarized_lsn FROM pg_available_wal_summaries()

src/test/recovery/t/001_stream_rep.pl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -506,6 +506,13 @@ sub replay_check
506506
$node_standby_2->enable_streaming($node_primary);
507507
$node_standby_2->reload;
508508

509+
# The WAL receiver should have generated some IO statistics.
510+
my $stats_reads = $node_standby_1->safe_psql(
511+
'postgres',
512+
qq{SELECT sum(writes) > 0 FROM pg_stat_io
513+
WHERE backend_type = 'walreceiver' AND object = 'wal'});
514+
is($stats_reads, 't', "WAL receiver generates statistics for WAL writes");
515+
509516
# be sure do not streaming from cascade
510517
$node_standby_1->stop;
511518

0 commit comments

Comments
 (0)