SPI Interface to Call Procedure with Transaction Control Statements?

From: Jack LIU <toliujiayi(at)gmail(dot)com>
To: pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: SPI Interface to Call Procedure with Transaction Control Statements?
Date: 2019-01-14 05:43:40
Message-ID: CABZ0cG1eqp2ujK1gfR2b-pV6jZopGB6JGX1dFjiiK+d3+OwBOw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi All,

I sent an email with the same problem in pgsql-general mailing but no one
has responded, so I try to reach out by asking this question in the hacker
list.

In PG-11, procedures were introduced. In the pg_partman PostgreSQL
extension, a procedure named run_maintenance_proc was developed to replace
run_maintenance function. I was trying to call this procedure in pg_partman
with SPI_execute() interface and this is the command being executed:
CALL "partman".run_maintenance_proc(p_analyze := true, p_jobmon := true)

Detailed code please see: https://github.com/pgpartman/pg_partman/pull/242

I received the following error:

2019-01-02 20:13:04.951 PST [26446] ERROR: invalid transaction termination
2019-01-02 20:13:04.951 PST [26446] CONTEXT: PL/pgSQL function
partman.run_maintenance_proc(integer,boolean,boolean,boolean) line 45
at COMMIT

Apparently, the transaction control command 'COMMIT' is not allowed in a
procedure CALL function. But I can CALL this procedure in psql directly.

According to the documentation of CALL, "If CALL is executed in a
transaction block, then the called procedure cannot execute transaction
control statements. Transaction control statements are only allowed if CALL is
executed in its own transaction."

Therefore, it looks like that SPI_execute() is calling the procedure within
a transaction block. So Is there any SPI interface that can be used in an
extension library to call a procedure with transaction control commands? (I
tried to use SPI_connect_ext(SPI_OPT_NONATOMIC) to establish a nonatomic
connection but it doesn't help.)

Thanks,

Jiayi Liu

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Andrew Gierth 2019-01-14 06:21:14 Re: SPI Interface to Call Procedure with Transaction Control Statements?
Previous Message Craig Ringer 2019-01-14 04:18:53 Re: Reviving the "Stopping logical replication protocol" patch from Vladimir Gordichuk