Skip to content

Commit 010e523

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 d2bf06d commit 010e523

File tree

1 file changed

+22
-17
lines changed

1 file changed

+22
-17
lines changed

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

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -22,27 +22,32 @@
2222
$node->append_conf('postgresql.conf', 'wal_keep_size=1GB');
2323
$node->start;
2424

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

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

4853
my $initfile = $node->safe_psql('postgres',

0 commit comments

Comments
 (0)