Skip to content

Commit 5ec8761

Browse files
committed
Change recently added test code for stability
The test code added with ff9f111 fails under valgrind, and probably other slow cases too, because if (say) autovacuum runs in between and produces WAL of its own, the large INSERT fails to account for that in the LSN calculations. Rewrite to use a DO loop. Per complaint from Andres Freund Backpatch to all branches. Discussion: https://postgr.es/m/20211013180338.5guyqzpkcisqugrl@alap3.anarazel.de
1 parent 7b8237b commit 5ec8761

File tree

1 file changed

+24
-28
lines changed

1 file changed

+24
-28
lines changed

src/test/recovery/t/026_overwrite_contrecord.pl

Lines changed: 24 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -22,38 +22,34 @@
2222
$node->append_conf('postgresql.conf', 'wal_keep_segments=16');
2323
$node->start;
2424

25-
$node->safe_psql('postgres', 'create table filler (a int)');
26-
27-
# First, measure how many bytes does the insertion of 1000 rows produce
28-
my $start_lsn = $node->safe_psql('postgres',
29-
q{select pg_current_xlog_insert_location() - '0/0'});
30-
$node->safe_psql('postgres',
31-
'insert into filler select * from generate_series(1, 1000)');
32-
my $end_lsn = $node->safe_psql('postgres',
33-
q{select pg_current_xlog_insert_location() - '0/0'});
34-
my $rows_walsize = $end_lsn - $start_lsn;
35-
note "rows walsize $rows_walsize";
36-
37-
note "before fill ",
38-
$node->safe_psql('postgres', 'select pg_current_xlog_insert_location()');
25+
$node->safe_psql('postgres', 'create table filler (a int, b text)');
3926

4027
# Now consume all remaining room in the current WAL segment, leaving
4128
# space enough only for the start of a largish record.
4229
$node->safe_psql(
43-
'postgres', qq{
44-
WITH segsize AS (
45-
SELECT setting::int
46-
FROM pg_settings WHERE name = 'wal_segment_size'
47-
), walblksz AS (
48-
SELECT setting::int
49-
FROM pg_settings WHERE name = 'wal_block_size'
50-
), setting AS (
51-
SELECT segsize.setting * walblksz.setting AS wal_segsize
52-
FROM segsize, walblksz
53-
)
54-
INSERT INTO filler
55-
SELECT g FROM setting,
56-
generate_series(1, 1000 * (wal_segsize - ((pg_current_xlog_insert_location() - '0/0') % wal_segsize)) / $rows_walsize) g
30+
'postgres', q{
31+
DO $$
32+
DECLARE
33+
wal_segsize int :=
34+
(max(setting) filter (where name = 'wal_segment_size'))::int *
35+
(max(setting) filter (where name = 'wal_block_size'))::int from pg_settings ;
36+
remain int;
37+
iters int := 0;
38+
BEGIN
39+
LOOP
40+
INSERT into filler
41+
select g, repeat(md5(g::text), (random() * 60 + 1)::int)
42+
from generate_series(1, 10) g;
43+
44+
remain := wal_segsize - (pg_current_xlog_insert_location() - '0/0') % wal_segsize;
45+
IF remain < 2 * setting::int from pg_settings where name = 'block_size' THEN
46+
RAISE log 'exiting after % iterations, % bytes to end of WAL segment', iters, remain;
47+
EXIT;
48+
END IF;
49+
iters := iters + 1;
50+
END LOOP;
51+
END
52+
$$;
5753
});
5854

5955
note "start ",

0 commit comments

Comments
 (0)