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

Commit ef719e7

Browse files
committed
Stabilize pg_stat_io writes test
Counting writes only for io_context = 'normal' is unreliable, as backends using a buffer access strategy could flush all of the dirty buffers out from under the other backends and checkpointer. Change the test to count writes in any context. This achieves roughly the same coverage anyway. Reported-by: Justin Pryzby <pryzby@telsasoft.com> Author: Melanie Plageman <melanieplageman@gmail.com> Discussion: https://www.postgresql.org/message-id/ZAnWU8WbXEDjrfUE%40telsasoft.com
1 parent 7730ceb commit ef719e7

File tree

2 files changed

+8
-9
lines changed

2 files changed

+8
-9
lines changed

src/test/regress/expected/stats.out

+4-4
Original file line numberDiff line numberDiff line change
@@ -1137,6 +1137,9 @@ SELECT pg_stat_get_subscription_stats(NULL);
11371137
-- extends.
11381138
SELECT sum(extends) AS io_sum_shared_before_extends
11391139
FROM pg_stat_io WHERE io_context = 'normal' AND io_object = 'relation' \gset
1140+
SELECT sum(writes) AS writes, sum(fsyncs) AS fsyncs
1141+
FROM pg_stat_io
1142+
WHERE io_object = 'relation' \gset io_sum_shared_before_
11401143
CREATE TABLE test_io_shared(a int);
11411144
INSERT INTO test_io_shared SELECT i FROM generate_series(1,100)i;
11421145
SELECT pg_stat_force_next_flush();
@@ -1155,15 +1158,12 @@ SELECT :io_sum_shared_after_extends > :io_sum_shared_before_extends;
11551158

11561159
-- After a checkpoint, there should be some additional IOCONTEXT_NORMAL writes
11571160
-- and fsyncs.
1158-
SELECT sum(writes) AS writes, sum(fsyncs) AS fsyncs
1159-
FROM pg_stat_io
1160-
WHERE io_context = 'normal' AND io_object = 'relation' \gset io_sum_shared_before_
11611161
-- See comment above for rationale for two explicit CHECKPOINTs.
11621162
CHECKPOINT;
11631163
CHECKPOINT;
11641164
SELECT sum(writes) AS writes, sum(fsyncs) AS fsyncs
11651165
FROM pg_stat_io
1166-
WHERE io_context = 'normal' AND io_object = 'relation' \gset io_sum_shared_after_
1166+
WHERE io_object = 'relation' \gset io_sum_shared_after_
11671167
SELECT :io_sum_shared_after_writes > :io_sum_shared_before_writes;
11681168
?column?
11691169
----------

src/test/regress/sql/stats.sql

+4-5
Original file line numberDiff line numberDiff line change
@@ -549,6 +549,9 @@ SELECT pg_stat_get_subscription_stats(NULL);
549549
-- extends.
550550
SELECT sum(extends) AS io_sum_shared_before_extends
551551
FROM pg_stat_io WHERE io_context = 'normal' AND io_object = 'relation' \gset
552+
SELECT sum(writes) AS writes, sum(fsyncs) AS fsyncs
553+
FROM pg_stat_io
554+
WHERE io_object = 'relation' \gset io_sum_shared_before_
552555
CREATE TABLE test_io_shared(a int);
553556
INSERT INTO test_io_shared SELECT i FROM generate_series(1,100)i;
554557
SELECT pg_stat_force_next_flush();
@@ -558,16 +561,12 @@ SELECT :io_sum_shared_after_extends > :io_sum_shared_before_extends;
558561

559562
-- After a checkpoint, there should be some additional IOCONTEXT_NORMAL writes
560563
-- and fsyncs.
561-
SELECT sum(writes) AS writes, sum(fsyncs) AS fsyncs
562-
FROM pg_stat_io
563-
WHERE io_context = 'normal' AND io_object = 'relation' \gset io_sum_shared_before_
564564
-- See comment above for rationale for two explicit CHECKPOINTs.
565565
CHECKPOINT;
566566
CHECKPOINT;
567567
SELECT sum(writes) AS writes, sum(fsyncs) AS fsyncs
568568
FROM pg_stat_io
569-
WHERE io_context = 'normal' AND io_object = 'relation' \gset io_sum_shared_after_
570-
569+
WHERE io_object = 'relation' \gset io_sum_shared_after_
571570
SELECT :io_sum_shared_after_writes > :io_sum_shared_before_writes;
572571
SELECT current_setting('fsync') = 'off'
573572
OR :io_sum_shared_after_fsyncs > :io_sum_shared_before_fsyncs;

0 commit comments

Comments
 (0)