Hi,
I have a stored procedure that does a lot of INSERT/UDATE to 3
tables. And When I call the stored procedure, I get a Transaction Log
Full error. When I want to do is turning off the transaction log on
those 3 tables that the stored procedure is using.
Now, since I call the stored procedure on the command line (CLI),
where do I run ALTER TABLE ... ACTIVATE NOT LOGGED INITIALLY statement
? Do I have to put them inside the stored procedure ? Or Do I run the
command before I call the SP ? I am on Linux, DB2 8.2
We don't want to configure the logs to make it bigger because this
is just a one time run to populate the tables. And we have to use the
procedure to migrate those data.
Thanks for any inputs/advices
N. 11 5186
from command line is also simple
db2 -c- alter table
db2 -c- call sp
db2 commit
Hi All,
I just want to add some more information on the subject. Basically
my Stored Procedure looks like this :
CREATE PROCEDURE DB.PWC (V_ID CHAR(6), OUT RETURN_VAL INT)
LANGUAGE SQL
BEGIN
DECLARE..
DECLARE..
INSERT INTO TABLE A..
UPDATE TABLE A.. ha*********@gmail.com wrote: Hi, I have a stored procedure that does a lot of INSERT/UDATE to 3 tables. And When I call the stored procedure, I get a Transaction Log Full error. When I want to do is turning off the transaction log on those 3 tables that the stored procedure is using. Now, since I call the stored procedure on the command line (CLI), where do I run ALTER TABLE ... ACTIVATE NOT LOGGED INITIALLY statement ? Do I have to put them inside the stored procedure ? Or Do I run the command before I call the SP ? I am on Linux, DB2 8.2 We don't want to configure the logs to make it bigger because this is just a one time run to populate the tables. And we have to use the procedure to migrate those data.
Can you add commits into your stored procedure?
Otherwise,
db2 +c "alter table ... activate not logged initially"
db2 +c "call ..."
db2 commit
The +c option turns disables auto-commit.
Hi Ian,
Thank you for the reply. I have been trying to figure out
how to do a COMMIT inside the stored procedure, but I
don't think it can be easily done. Anytime I add a COMMIT
in the procedure, I got the error saying something about
the cursot not opened...
Do you think my problem was because I called the stored
procedure without "+c" in front of my CALL statement ?
Thanks,
N
Can you try if this works?
CREATE PROCEDURE DB.PWC (V_ID CHAR(6), OUT RETURN_VAL INT)
LANGUAGE SQL
P1:BEGIN
BEGIN
DECLARE..
DECLARE..
INSERT INTO TABLE A..
UPDATE TABLE A..
END;
.BEGIN
DECLARE..
DECLARE..
INSERT INTO TABLE B..
UPDATE TABLE B..
END;
BEGIN
. DECLARE..
DECLARE..
INSERT INTO TABLE C..
UPDATE TABLE C..
END;
END P1 ha*********@gmail.com wrote: Hi Ian, Thank you for the reply. I have been trying to figure out how to do a COMMIT inside the stored procedure, but I don't think it can be easily done. Anytime I add a COMMIT in the procedure, I got the error saying something about the cursot not opened... Do you think my problem was because I called the stored procedure without "+c" in front of my CALL statement ?
Thanks, N
DECLARE your cursor WITH HOLD.
By default cursors get closed on COMMIT. WITH HOLD suspends this behavior.
Also you can place the ALTER into the procedure.
Try: EXECUTE IMMEDIATE ALTER ....
Cheers
Serge
--
Serge Rielau
DB2 SQL Compiler Development
IBM Toronto Lab
Hi Serge,
Thanks for the tips.
I tried to add EXECUTE IMMEDIATE ALTER TABLE DB.A ACTIVATE NOT
LOGGED INITIALLY
in my procedure. But it failed to create. Am I not putting it in the
right place ? Or is my syntax incorrect ?
Can I activate not logged for more than 1 table at a time ?
CREATE PROCEDURE DB.PWC (V_ID CHAR(6), OUT RETURN_VAL INT)
LANGUAGE SQL
BEGIN
EXECUTE IMMEDIATE ALTER TABLE DB.A ACTIVATE NOT LOGGED INITIALLY
DECLARE..
DECLARE..
INSERT INTO TABLE A..
UPDATE TABLE A.. ha*********@gmail.com wrote: Hi Serge, Thanks for the tips. I tried to add EXECUTE IMMEDIATE ALTER TABLE DB.A ACTIVATE NOT LOGGED INITIALLY in my procedure. But it failed to create. Am I not putting it in the right place ? Or is my syntax incorrect ? Can I activate not logged for more than 1 table at a time ?
CREATE PROCEDURE DB.PWC (V_ID CHAR(6), OUT RETURN_VAL INT) LANGUAGE SQL
BEGIN
EXECUTE IMMEDIATE ALTER TABLE DB.A ACTIVATE NOT LOGGED INITIALLY
DECLARE.. DECLARE..
INSERT INTO TABLE A.. UPDATE TABLE A.. . . INSERT INTO TABLE B.. UPDATE TABLE B.. . . INSERT INTO TABLE C.. UPDATE TABLE C..
END
Try
EXECUTE IMMEDIATE 'ALTER TABLE ...';
If that does not work:
SET txt = 'ALTER TABLE ...';
EXECUTE IMMEDIATE txt;
will work for sure.. I do it rarely myself.
Cheers
Serge
--
Serge Rielau
DB2 SQL Compiler Development
IBM Toronto Lab
<ha*********@gmail.com> wrote in message
news:11*********************@o13g2000cwo.googlegro ups.com... Hi Serge, Thanks for the tips. I tried to add EXECUTE IMMEDIATE ALTER TABLE DB.A ACTIVATE NOT LOGGED INITIALLY in my procedure. But it failed to create. Am I not putting it in the right place ? Or is my syntax incorrect ?
It needs to come after the DECLARE statements but before your insert/update
queries.
--
Matt Emmerton
Hi, Serge
Here is an example of our code. Basically, we manually do the
looping
and set our variables and use those variables to INSERT/UPDATE into the
underlying tables. I'm interested in using CURSOR WITH HOLD. But I
guess
I'm not very experienced. I tried to use EXECUTE IMMEDIATE. It built
and ran, but I got some other errors saying that the table is not
accessible (can't insert/update). It was very strange. I think the
safest way is to
try to commit every n rows, so that the transaction log is not filled
up.
I'm looping through around 1 million rows from TABLE1 into variables,
and
use them to populate 3 tables accordingly. Maybe my code is not very
efficient. Do you have any advice on how to work around this
transaction log ? We do not want to increase our Log Size because this
is a migration script. It will be run only once in a blue moon.
Thanks,
CREATE PROCEDURE db2.pkc (v_in_proc_id CHAR(6),
OUT RETURN_VAL INTEGER )
LANGUAGE SQL
BEGIN
DECLARE ...;
DECLARE ...;
DECLARE ...;
DECLARE CONTINUE HANDLER FOR SQLEXCEPTION
BEGIN
INSERT INTO TABLE (..) VALUES (..);
END;
FOR DUMMY_LOOP AS SELECT
COL1,
COL2,
COL3
FROM TABLE1
DO
SET v_1 = COL1;
SET v_2 = COL2;
SET v_3 = COL3;
BEGIN
BEGIN
DECLARE continue HANDLER FOR dup_key
BEGIN
UPDATE TABLE_A
SET COL_A = ..
END;
INSERT INTO TABLE_A VALUES ( .. );
END ;
BEGIN
DECLARE continue HANDLER FOR dup_key
BEGIN
UPDATE TABLE_B
SET COL_B = ..
END;
INSERT INTO TABLE_B VALUES ( .. ); ha*********@yahoo.com wrote: Hi, Serge Here is an example of our code. Basically, we manually do the looping and set our variables and use those variables to INSERT/UPDATE into the
underlying tables. I'm interested in using CURSOR WITH HOLD. But I guess I'm not very experienced. I tried to use EXECUTE IMMEDIATE. It built and ran, but I got some other errors saying that the table is not accessible (can't insert/update). It was very strange. I think the safest way is to try to commit every n rows, so that the transaction log is not filled up. I'm looping through around 1 million rows from TABLE1 into variables, and use them to populate 3 tables accordingly. Maybe my code is not very efficient. Do you have any advice on how to work around this transaction log ? We do not want to increase our Log Size because this is a migration script. It will be run only once in a blue moon.
Thanks,
CREATE PROCEDURE db2.pkc (v_in_proc_id CHAR(6), OUT RETURN_VAL INTEGER )
LANGUAGE SQL
BEGIN
DECLARE ...; DECLARE ...; DECLARE ...;
DECLARE CONTINUE HANDLER FOR SQLEXCEPTION
BEGIN INSERT INTO TABLE (..) VALUES (..); END;
FOR DUMMY_LOOP AS SELECT COL1, COL2, COL3 FROM TABLE1
DO
SET v_1 = COL1; SET v_2 = COL2; SET v_3 = COL3;
BEGIN
BEGIN
DECLARE continue HANDLER FOR dup_key BEGIN
UPDATE TABLE_A SET COL_A = ..
END;
INSERT INTO TABLE_A VALUES ( .. );
END ;
BEGIN
DECLARE continue HANDLER FOR dup_key BEGIN
UPDATE TABLE_B SET COL_B = ..
END;
INSERT INTO TABLE_B VALUES ( .. );
. . .
END
This isn't what I thought you did... I thought you picked teh tabel name
from the FOR loop itself....
First of: Good going with the nested handlers! Nice to see someone use
neste compounds as they are meant to be used.
You can simply the code quite a bit by using MERGE.
BEGIN
FOR THIS AS dummy CURSOR WITH HOLD
FOR SELECT PK1, COL1, PK2, COL2, PK3, COL3 FROM TABLE1
DO
MERGE INTO TABLEA AS T
USING (VALUES(THIS.PK1, THIS.COL1)) AS S(PK, C1)
ON T.PK = S.PK
WHEN MATCHED THEN UPDATE SET T.C1 = S.C1;
WHEN NOT MATCHED THEN INSERT VALUES (S.PK, S.C1);
MERGE .... ;
COMMIT;
END FOR;
END
Cheers
Serge
--
Serge Rielau
DB2 SQL Compiler Development
IBM Toronto Lab This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Deepak Mehta |
last post by:
i have to update two tables from ASP pages with same data but i want
that both of them should be updated at one time. If either of them is
not updated then my transaction should roll back.I want...
|
by: steven.cooper |
last post by:
Does anyone know exactly what behaviour is exhibited when running a
stored procedure and the log file fills up while the procedure is still
running?
I am seeing, through a created history table, a...
|
by: Mark |
last post by:
If a java applicaiton using the type 4 driver calls a DB2 stored
procedure, does the stored procedure need to do its own commit when
updates are completed? If the stored procedure does a commit or...
|
by: Henry |
last post by:
My application uses Oracle stored procedure to modify multiple tables.
but OracleClient does not support table-like arrays in one execution,
therefore, I need call many times of the stored...
|
by: Irfan |
last post by:
There are several ways of handling Transactions in DotNet. Some of them are
1. Using COM+ Serviced Component.
2. Using ADO .Net
3. using stored procedure
What is the best way of handling...
|
by: Dino L. |
last post by:
How can I run stored procedure (MSSQL) ?
|
by: ucasesoftware |
last post by:
i need to use this :
Private Shared Sub Demo1()
Dim db As SqlConnection = New SqlConnection("connstringhere")
Dim transaction As SqlTransaction
db.Open
transaction = db.BeginTransaction
Try...
|
by: Siv |
last post by:
Hi,
I have a stored procedure that I want to execute and then wait in a loop
showing a timer whilst it completes and then carry on once I get
notification that it has completed. The main reason...
|
by: sridhar21 |
last post by:
Hi to all
this is sridhar
i need example to created stored procedure with transaction in sql and how to call that stored procedure in C#
thanxs
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |