create table if not exists test (a int);
create or replace function testfn (cnt int) returns void as $$
begin
  for i in 1..cnt loop
    begin
      insert into test values (i);
    exception when division_by_zero then
      raise notice 'caught error';
      return;
    end;
  end loop;
end;
$$
language plpgsql;
select pg_create_logical_replication_slot('s', 'test_decoding');
select testfn(100000);
set logical_decoding_work_mem to '5GB'; -- '4MB' to invoke eviction.
select from pg_logical_slot_peek_changes('s', null, null);
select from pg_logical_slot_peek_changes('s', null, null);
select from pg_logical_slot_peek_changes('s', null, null);
