Eat XIDs more efficiently in recovery TAP test.

The point of this loop is to insert 1000 rows into the test table
and consume 1000 XIDs.  I can't see any good reason why it's useful
to launch 1000 psqls and 1000 backend processes to accomplish that.
Pushing the looping into a plpgsql DO block shaves about 10 seconds
off the runtime of the src/test/recovery TAP tests on my machine;
that's over 10% of the runtime of that test suite.

It is, in fact, sufficiently more efficient that we now demonstrably
need wait_slot_xmins() afterwards, or the slaves' xmins may not have
moved yet.
This commit is contained in:
Tom Lane 2017-06-28 22:11:12 -04:00
parent 1ae8536545
commit 08aed6604d

View File

@ -224,19 +224,33 @@ isnt($xmin, '', 'xmin of cascaded slot non-null with hs feedback');
is($catalog_xmin, '', 'catalog xmin of cascaded slot still null with hs_feedback');
note "doing some work to advance xmin";
for my $i (10000 .. 11000)
{
$node_master->safe_psql('postgres', qq[INSERT INTO tab_int VALUES ($i);]);
}
$node_master->safe_psql('postgres', q{
do $$
begin
for i in 10000..11000 loop
-- use an exception block so that each iteration eats an XID
begin
insert into tab_int values (i);
exception
when division_by_zero then null;
end;
end loop;
end$$;
});
$node_master->safe_psql('postgres', 'VACUUM;');
$node_master->safe_psql('postgres', 'CHECKPOINT;');
wait_slot_xmins($node_master, $slotname_1, "xmin <> '$xmin'");
my ($xmin2, $catalog_xmin2) = get_slot_xmins($node_master, $slotname_1);
note "new xmin $xmin2, old xmin $xmin";
isnt($xmin2, $xmin, 'xmin of non-cascaded slot with hs feedback has changed');
is($catalog_xmin2, '',
'catalog xmin of non-cascaded slot still null with hs_feedback unchanged');
wait_slot_xmins($node_standby_1, $slotname_2, "xmin <> '$xmin'");
($xmin2, $catalog_xmin2) = get_slot_xmins($node_standby_1, $slotname_2);
note "new xmin $xmin2, old xmin $xmin";
isnt($xmin2, $xmin, 'xmin of cascaded slot with hs feedback has changed');