Cleanest method to truncate a table- no inserting rows...

Post questions here relative to DataStage Server Edition for such areas as Server job design, DS Basic, Routines, Job Sequences, etc.

Moderators: chulett, rschirm, roy

Post Reply
crsimms
Charter Member
Charter Member
Posts: 21
Joined: Mon May 30, 2005 4:21 am
Contact:

Cleanest method to truncate a table- no inserting rows...

Post by crsimms »

All,

This may sound silly, but what is the cleanest method to have a job truncate a table only. That is the job does not also insert rows afterwards into the table and does not require a driver table or file to kick off the process. Currently I am using a transformer stage with a stage variable to drive a Dynamic RDBMS stage where the Update action is defined as User-defined SQL and the SQL contains the truncate table statement. However, I am running into a "ORA-01036: illegal variable name/number" error which I attribute to the dummy column within the link.

Thanks,


CSimms
Chris Simms

Mobile: +972 989 0919
kris007
Charter Member
Charter Member
Posts: 1102
Joined: Tue Jan 24, 2006 5:38 pm
Location: Riverside, RI

Post by kris007 »

Could you post the userdefined SQL in here. The error message says you have declared someting which is not acceptable
Also why do you want to use the User defined SQL. You can always set the Updateaction to "truncate table then insert rows" provided you have a constraint in transformer which is set to '@FALSE'. This won't insert any rows!

HTH
Kris.
crsimms
Charter Member
Charter Member
Posts: 21
Joined: Mon May 30, 2005 4:21 am
Contact:

Post by crsimms »

Kris,

The SQL is as follows:

TRUNCATE TABLE STAGING.#J_TABLE_NAME#_SNAP_KEYS

I am attempting to not use the Truncate then Insert rows Update action as I do not want to define a particular column as the table name is dynamic. I have tried to use the Truncate only option which looks like it would work, but the job only hangs.

Thanks,

CSIMMS
Chris Simms

Mobile: +972 989 0919
DSguru2B
Charter Member
Charter Member
Posts: 6854
Joined: Wed Feb 09, 2005 3:44 pm
Location: Houston, TX

Post by DSguru2B »

I would suggest writing a shell script that executes all the truncates. You can fire that script in DataStage.
You sure you have the truncate permissions. The job shouldnt hang as its not a logged operation.
Try running it again and then contact your dba to see what is that thread, created by you, is doing at the database. Does it even reach the database or not?
Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep.
kris007
Charter Member
Charter Member
Posts: 1102
Joined: Tue Jan 24, 2006 5:38 pm
Location: Riverside, RI

Post by kris007 »

So, now what is the column you have defined in the columns tab?

One thing you could do is, define a dummy column in OCI stage, which I guess you are already doing. In your User defined sql write..

Code: Select all

Select "something" from dual

and In your Before SQL or After SQL tab use the truncate statement. I see that it can work.

HTH
Kris
Kris

Where's the "Any" key?-Homer Simpson
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Why do you need User Defined SQL? As you've found, that's going to cause you nothing but grief trying to bind things. :?

The DRS stage when set to Oracle has two truncate Update actions:

Truncate only
Truncate table then insert rows

Seems like either would work for you, considering you aren't planning on sending any rows to the stage.

Edited to add: Ah, reading comprehension is a wonderful thing. Just saw your comments on these two options. I'd suggest the generic sqlplus script that truncates a passed in table name, that's one method we've used in the past that's simple to implement.
-craig

"You can never have too many knives" -- Logan Nine Fingers
crsimms
Charter Member
Charter Member
Posts: 21
Joined: Mon May 30, 2005 4:21 am
Contact:

Post by crsimms »

All,

First, the database user has truncate permissions. I can do this under the user in a tool such as Toad. The job hangs though using the Truncate only option and I am not sure why. I have been at places where the script method was employed, but I am trying to keep the solution strictly within DataStage. because of the dynamic nature of the table names, maybe I should attempt what Kris has suggested. I still do not understand why the DRS stage is not working correctly.

Thanks,
Chris Simms

Mobile: +972 989 0919
DSguru2B
Charter Member
Charter Member
Posts: 6854
Joined: Wed Feb 09, 2005 3:44 pm
Location: Houston, TX

Post by DSguru2B »

Did you ask your DBA to see what that particular thread is doing on the database?
Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep.
kris007
Charter Member
Charter Member
Posts: 1102
Joined: Tue Jan 24, 2006 5:38 pm
Location: Riverside, RI

Post by kris007 »

I think you should also consider what DSGuru2B has suggested because I remember once when that happened to me. The truncate job took for ever. Though I can't recollect what happened exactly at that time and how I(we) fixed it, I would suggest to give that one a shot. What happens when you truncate the same table from SQLplus or TOAD or whatever tool you use? Does the table get truncated?
Kris

Where's the "Any" key?-Homer Simpson
DSguru2B
Charter Member
Charter Member
Posts: 6854
Joined: Wed Feb 09, 2005 3:44 pm
Location: Houston, TX

Post by DSguru2B »

I bet it does get truncated from outside DataStage. My main point is that he should issue the truncate from within datastage and make sure that thread reaches the database for one, and investigate what that thread is doing at the database level by involving the DBA. Only he can monitor the process and let crsimms know whats going on.
Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep.
crsimms
Charter Member
Charter Member
Posts: 21
Joined: Mon May 30, 2005 4:21 am
Contact:

Post by crsimms »

DSguru2B and kris007,

Yes, the table successfully truncates under Toad. I do need to check with our DBA as the Truncate only Update action is truncating the table as well. However, I need to see if the thread is actually being released or is holding on for whatever reason.

Thanks,
Chris Simms

Mobile: +972 989 0919
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Would you be opposed to using an ODBC stage for this? It will support a link with a dummy column that is not bound into the sql and your user-defined sql can be simply 'TRUNCATE TABLE XXXX'.

Done that before as well.
-craig

"You can never have too many knives" -- Logan Nine Fingers
crsimms
Charter Member
Charter Member
Posts: 21
Joined: Mon May 30, 2005 4:21 am
Contact:

Post by crsimms »

All,

The DSR stage is executing the truncate table command and the table is being truncated. According to our DBA, no locks are being maintained on table which is good but the session is listed as inactive which is bad. It appears that Oracle is waiting for DataStage to close the connection but DataStage is just sitting there.

Strange and aggravating at the same time. :evil:
Chris Simms

Mobile: +972 989 0919
DSguru2B
Charter Member
Charter Member
Posts: 6854
Joined: Wed Feb 09, 2005 3:44 pm
Location: Houston, TX

Post by DSguru2B »

Dont let DataStage sit alone. Join it and have a cup of tea :twisted:
Well atleast now we know that the thread reaches the database and truncates the table successfully. Let the job run. See how much time does it take to finish the job.
Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep.
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

What is your commit size (rows per transaction)?
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Post Reply