如果我们有这样的程序:
create procedure check_all_accounts()
as $code$
declare
id varchar;
rec record;
begin
for rec in select acc.id from main.account acc where acc.type_id = 'ACT'
loop
raise notice '%: Checking Account %', substring(clock_timestamp()::varchar, 1, 19), rec.id;
call main.check_and_cleanup(rec.id);
-- commit; -- Does not work within procedure
end loop;
exception
when others then
raise notice 'Failed for Account %s. Error: %', rec.id, sqlerrm;
end; $code$ language plpgsql;
它为我运行了大约 52'000 个循环,然后服务器抱怨 Transaction Cash 内存已满。 如果我以这样的块运行它,它会像
commit
一样工作。
do $code$
declare
id varchar;
rec record;
begin
for rec in select acc.id from main.account acc where acc.type_id = 'ACT'
loop
raise notice '%: Checking Account %', substring(clock_timestamp()::varchar, 1, 19), rec.id;
call main.check_and_cleanup(rec.id);
commit; -- Commit is allowed/needed here
end loop;
end; $code$
我需要从一个过程中运行它,我该如何解决这个问题? 我希望所有的循环都能通过,但是在交易现金被填满后它就失败了。
get stacked diagnostics
给出的确切错误消息详细信息:
53200
out of shared memory