autocommit for multi call store procedure
Hi guys,
I am using pgadmin4 to interact with Postgres database. For now I would
like to run 2 store procedure (those have commit statement in begin end
block). I enable autocommit and run call 2 store procedures at the same
time. However, there is an error with invalid transaction termination.
Could you help me on this issue?
Thanks,
Trang
Have you used an EXCEPTION block in the procedure?
Regards,
Ninad Shah
On Thu, 16 Sept 2021 at 13:06, Trang Le <trang.le@evizi.com> wrote:
Show quoted text
Hi guys,
I am using pgadmin4 to interact with Postgres database. For now I would
like to run 2 store procedure (those have commit statement in begin end
block). I enable autocommit and run call 2 store procedures at the same
time. However, there is an error with invalid transaction termination.Could you help me on this issue?
Thanks,
Trang
On 9/16/21 12:36 AM, Trang Le wrote:
Hi guys,
I am using pgadmin4 to interact with Postgres database. For now I would
like to run 2 store procedure (those have commit statement in begin end
block). I enable autocommit and run call 2 store procedures at the same
time. However, there is an error with invalid transaction termination.Could you help me on this issue?
Maybe but will need to see:
1) The content of the procedures.
2) The manner in which they are called.
3) The actual complete error message.
Thanks,
Trang
--
Adrian Klaver
adrian.klaver@aklaver.com
Hi Adrian,
I am processing this issue with Ninad.
Could you double check it?
Regards,
Trang
---------- Forwarded message ---------
From: Trang Le <trang.le@evizi.com>
Date: Fri, Sep 17, 2021 at 8:19 AM
Subject: Re: autocommit for multi call store procedure
To: Ninad Shah <nshah.postgres@gmail.com>
Hi Ninad,
Thanks for your sharing.
It's weird I can run in pgadmin4.
call PRC_ADDRESS_DS_TEST(); call PRC_ADDRESS_DS_TEST1();
[image: image.png]
Could you check it in pgadmin4?
Regard,
Trang
On Fri, Sep 17, 2021 at 12:20 AM Ninad Shah <nshah.postgres@gmail.com>
wrote:
Show quoted text
Hi Trang,
The way you are executing It invokes functions sequentially. test1 will be
executed first then test2.And yes, it works for me.
postgres=# call transaction_test1(); call transaction_test2();
CALL
CALLIn your case, you are facing the issue with the first call statement.
Kindly check your version.Regards,
Ninad ShahOn Thu, 16 Sept 2021 at 15:29, Trang Le <trang.le@evizi.com> wrote:
Hi Ninah,
Could you please run those queries at the same time?
call transaction_test1();
call transaction_test2();I run in new windows
[image: image.png]
Regards,
TrangOn Thu, Sep 16, 2021 at 4:53 PM Ninad Shah <nshah.postgres@gmail.com>
wrote:Hi Trang,
I tried it on version 13.3, and both the cases work as expected. Not
only that but also by applying different variations in the procedure, it
delivers desired results.*Case 1:*
Do not use the call statement inside a procedure, rather just put simple
INSERT statements followed by COMMIT, and it works as expected.postgres=# CREATE or replace PROCEDURE transaction_test3()
postgres-# LANGUAGE plpgsql
postgres-# AS $$
postgres$# DECLARE
postgres$# r RECORD;
postgres$# BEGIN
postgres$# INSERT INTO test_table VALUES (1, 'test1');
postgres$# INSERT INTO test_table VALUES (2, 'test2');
postgres$# COMMIT;
postgres$# END;
postgres$# $$;
CREATE PROCEDURE
postgres=#
postgres=#
postgres=# call transaction_test3();
CALL*Case 2:*
Use 2 call statements inside a nested BEGIN block followed by a COMMIT
statement. This also works as expected.postgres=# CREATE or replace PROCEDURE transaction_test4()
postgres-# LANGUAGE plpgsql
postgres-# AS $$
postgres$# DECLARE
postgres$# r RECORD;
postgres$# BEGIN
postgres$# BEGIN
postgres$# call transaction_test1();
postgres$# call transaction_test2();
postgres$# COMMIT;
postgres$# END;
postgres$# END;
postgres$# $$;
CREATE PROCEDURE
postgres=#
postgres=#
postgres=# call transaction_test4();
CALLAdditionally, in all the cases, data is getting inserted into a test
table.Kindly verify what version you are using?
Regards,
Ninad ShahOn Thu, 16 Sept 2021 at 14:59, Trang Le <trang.le@evizi.com> wrote:
Hi Ninah,
I already double checked with this case, it has the same problem.
Could you please double check the attached file?
Regards,
TrangOn Thu, Sep 16, 2021 at 4:20 PM Ninad Shah <nshah.postgres@gmail.com>
wrote:I saw some examples where COMMIT statements are part of FOR loops.
Would you try using a loop?
Regards,
Ninad ShahOn Thu, 16 Sept 2021 at 13:12, Trang Le <trang.le@evizi.com> wrote:
No, I leaved exception to sub-block. So it does not effect. I
committed in end of outer block and inside exceptionThis is my query
CREATE OR REPLACE PROCEDURE mdm.prc_address_ds_test(
)
LANGUAGE 'plpgsql'
AS $BODY$
BEGIN
CALL mdm.prc_log_job(v_job_id, v_cnt, v_job_desc, v_trx_type, 0,
v_start_ts);
BEGIN
v_cnt := v_cnt + 1;
v_start_ts := clock_timestamp();
v_job_desc := 'Insert records in address_ds test';
v_trx_type := 'I';
GET DIAGNOSTICS sql$rowcount = ROW_COUNT;
CALL mdm.prc_log_job(v_job_id, v_cnt, v_job_desc, v_trx_type,
sql$rowcount, v_start_ts);
EXCEPTION
WHEN others THEN
v_cnt := v_cnt + 1;
GET DIAGNOSTICS sql$rowcount = ROW_COUNT;
GET STACKED DIAGNOSTICS aws$frmt_err_bcktrc = PG_EXCEPTION_CONTEXT;
begin
CALL mdm.prc_log_job(v_job_id, v_cnt, v_job_desc, v_trx_type,
sql$rowcount::bigint, v_start_ts, substring(aws$frmt_err_bcktrc, 0, 4000));
commit;
end;
RAISE USING hint = -20101, message = aws$frmt_err_bcktrc, detail =
'User-defined exception';
END;
CALL mdm.prc_log_job(job_id => v_job_id, job_id_seq_num => v_cnt,
job_trx_type => NULL, job_trx_cnt => NULL::bigint,
job_desc => CONCAT('END JOB: ', v_job_nme)::character varying,
job_start_ts => v_start_ts);
commit;
END;
$BODY$;On Thu, Sep 16, 2021 at 2:38 PM Ninad Shah <nshah.postgres@gmail.com>
wrote:Have you used an EXCEPTION block in the procedure?
Regards,
Ninad ShahOn Thu, 16 Sept 2021 at 13:06, Trang Le <trang.le@evizi.com> wrote:
Hi guys,
I am using pgadmin4 to interact with Postgres database. For now I
would like to run 2 store procedure (those have commit statement in begin
end block). I enable autocommit and run call 2 store procedures at the same
time. However, there is an error with invalid transaction termination.Could you help me on this issue?
Thanks,
Trang
Import Notes
Reply to msg id not found: CAFfZjThPy-CrkMX2XJtQaAKQv+8PxBXDybxNoHUXwEzo7xm0BA@mail.gmail.com
On Thursday, September 16, 2021, Trang Le <trang.le@evizi.com> wrote
Could you double check it?
We’re testing your failing code, not that PostgreSQL is working as
intended. Suggest you get rid of all the stuff that doesn’t produce errors
and focus on trying to supply a minimal script that produces the unexpected
error. Then send that as a single email, probably with an attachment and
some explanations.
David J.
On 9/16/21 6:32 PM, Trang Le wrote:
Hi Adrian,
I am processing this issue with Ninad.
Could you double check it?
I have no idea what the forwarded message was showing. Too many changes
in code. As David suggested reduce this down to a simple test case that
demonstrates your issue.
Regards,
Trang
--
Adrian Klaver
adrian.klaver@aklaver.com