Cannot commit or rollback in “security definer” PL/pgSQL proc

From: Bryn Llewellyn <bryn(at)yugabyte(dot)com>
To: pgsql-hackers list <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Cannot commit or rollback in “security definer” PL/pgSQL proc
Date: 2019-10-21 05:43:12
Message-ID: 25D689AE-8C20-4A19-A3C5-1D878B4D09A2@yugabyte.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Here’s a cut-down version of Umair Shahid’s blog post here:

https://www.2ndquadrant.com/en/blog/postgresql-11-server-side-procedures-part-1/ <https://www.2ndquadrant.com/en/blog/postgresql-11-server-side-procedures-part-1/>
__________

create table t(k int primary key, v int not null);

create or replace procedure p()
language plpgsql
security invoker
as $$
begin
insert into t(k, v) values(1, 17);
rollback;
insert into t(k, v) values(1, 42);
commit;
end
$$;

call p();
select * from t order by k;
__________

It runs without error and shows that the effect of “rollback” and “commit” is what the names of those statements tells you to expect.

The post starts with “Thanks to the work done by 2ndQuadrant contributors, we now have the ability to write Stored Procedures in PostgreSQL… [with] transaction control – allowing us to COMMIT and ROLLBACK inside procedures.”. I believe that Umair is referring to work done by Peter Eisentraut.

But simply change “security invoker” to “security definer” and rerun the test. You get the notorious error “2D000: invalid transaction termination”.

Please tell me that this is a plain bug—and not the intended semantics.

Browse pgsql-hackers by date

  From Date Subject
Next Message Amit Kapila 2019-10-21 05:53:02 Re: Questions/Observations related to Gist vacuum
Previous Message Pavel Stehule 2019-10-21 05:38:06 Re: dropdb --force