mirror of https://github.com/postgres/postgres
Change recently added test code for stability
The test code added with ff9f111bce
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
This commit is contained in:
parent
7b8237bbec
commit
5ec87619bc
|
@ -22,38 +22,34 @@ $node->init(allows_streaming => 1);
|
|||
$node->append_conf('postgresql.conf', 'wal_keep_segments=16');
|
||||
$node->start;
|
||||
|
||||
$node->safe_psql('postgres', 'create table filler (a int)');
|
||||
|
||||
# First, measure how many bytes does the insertion of 1000 rows produce
|
||||
my $start_lsn = $node->safe_psql('postgres',
|
||||
q{select pg_current_xlog_insert_location() - '0/0'});
|
||||
$node->safe_psql('postgres',
|
||||
'insert into filler select * from generate_series(1, 1000)');
|
||||
my $end_lsn = $node->safe_psql('postgres',
|
||||
q{select pg_current_xlog_insert_location() - '0/0'});
|
||||
my $rows_walsize = $end_lsn - $start_lsn;
|
||||
note "rows walsize $rows_walsize";
|
||||
|
||||
note "before fill ",
|
||||
$node->safe_psql('postgres', 'select pg_current_xlog_insert_location()');
|
||||
$node->safe_psql('postgres', 'create table filler (a int, b text)');
|
||||
|
||||
# Now consume all remaining room in the current WAL segment, leaving
|
||||
# space enough only for the start of a largish record.
|
||||
$node->safe_psql(
|
||||
'postgres', qq{
|
||||
WITH segsize AS (
|
||||
SELECT setting::int
|
||||
FROM pg_settings WHERE name = 'wal_segment_size'
|
||||
), walblksz AS (
|
||||
SELECT setting::int
|
||||
FROM pg_settings WHERE name = 'wal_block_size'
|
||||
), setting AS (
|
||||
SELECT segsize.setting * walblksz.setting AS wal_segsize
|
||||
FROM segsize, walblksz
|
||||
)
|
||||
INSERT INTO filler
|
||||
SELECT g FROM setting,
|
||||
generate_series(1, 1000 * (wal_segsize - ((pg_current_xlog_insert_location() - '0/0') % wal_segsize)) / $rows_walsize) g
|
||||
'postgres', q{
|
||||
DO $$
|
||||
DECLARE
|
||||
wal_segsize int :=
|
||||
(max(setting) filter (where name = 'wal_segment_size'))::int *
|
||||
(max(setting) filter (where name = 'wal_block_size'))::int from pg_settings ;
|
||||
remain int;
|
||||
iters int := 0;
|
||||
BEGIN
|
||||
LOOP
|
||||
INSERT into filler
|
||||
select g, repeat(md5(g::text), (random() * 60 + 1)::int)
|
||||
from generate_series(1, 10) g;
|
||||
|
||||
remain := wal_segsize - (pg_current_xlog_insert_location() - '0/0') % wal_segsize;
|
||||
IF remain < 2 * setting::int from pg_settings where name = 'block_size' THEN
|
||||
RAISE log 'exiting after % iterations, % bytes to end of WAL segment', iters, remain;
|
||||
EXIT;
|
||||
END IF;
|
||||
iters := iters + 1;
|
||||
END LOOP;
|
||||
END
|
||||
$$;
|
||||
});
|
||||
|
||||
note "start ",
|
||||
|
|
Loading…
Reference in New Issue