If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > generate runstats command

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-25-12, 14:55
db2girl db2girl is offline
∞∞∞∞∞∞
 
Join Date: Aug 2008
Location: Toronto, Canada
Posts: 1,816
generate runstats command

I used the following to generate the runstats command for all tables:

db2 -x "select 'runstats on table '|| rtrim(tabschema) || '.' || rtrim(tabname)||' with distribution on key columns and detailed indexes all;' from syscat.tables where type = 'T'" > runstats.sql


But it doesn't work for tables such as CANDLE.KLZ_CPU_Averages_M (mixed case) or CANDLE.Application_Transaction/Program_Long-Term_History (special char).


The following generates the runstats command that works but would like to know if there is a better way to accomplish the same:

db2 -x "select 'runstats on table '|| rtrim(tabschema) || '.\' || '\"' || rtrim(tabname)|| '\' || '\"' ||' with distribution on key columns and detailed indexes all;' from syscat.tables where type = 'T'" > runstats.sql


This generates:

runstats on table CANDLE.\"KLZ_CPU_Averages_M\" with distribution on key columns and detailed indexes all;


Can you please suggest a better way to generate the runstats command?
Reply With Quote
  #2 (permalink)  
Old 01-25-12, 15:14
db2girl db2girl is offline
∞∞∞∞∞∞
 
Join Date: Aug 2008
Location: Toronto, Canada
Posts: 1,816
Actually, for it to work with db2 -tvf, I just need the double quotes:
runstats on table CANDLE."KLZ_CPU_Averages_M" with distribution on key columns and detailed indexes all;


But with ksh, I need:
db2 runstats on table CANDLE.\"KLZ_CPU_Averages_M\" with distribution on key columns and detailed indexes all


Please suggest how to improve the following:

db2 -x "select 'db2 runstats on table '|| rtrim(tabschema) || '.\' || '\"' || rtrim(tabname)|| '\' || '\"' ||' with distribution on key columns and
detailed indexes all' from syscat.tables where type = 'T'" > runstats.sql
Reply With Quote
  #3 (permalink)  
Old 01-25-12, 17:02
Marcus_A Marcus_A is offline
Registered User
 
Join Date: May 2003
Location: USA
Posts: 5,198
At first glance your generate runstats SQL looks fine.

I would find the person who created the case-sensitive table names and send them to Singapore for caning.
LiveLeak.com - Caning in Singapore
__________________
M. A. Feldman
IBM Certified DBA on DB2 for Linux, UNIX, and Windows
IBM Certified DBA on DB2 for z/OS and OS/390
Reply With Quote
  #4 (permalink)  
Old 01-25-12, 19:56
stolze stolze is offline
Registered User
 
Join Date: Jan 2007
Location: Jena, Germany
Posts: 2,662
Or you get used to the fact that all database systems allow delimited identifiers these days and start to always use the double-quotes. ;-)
__________________
Knut Stolze
IBM DB2 Analytics Accelerator
IBM Germany Research & Development
Reply With Quote
  #5 (permalink)  
Old 01-26-12, 02:58
dr_te_z dr_te_z is offline
Registered User
 
Join Date: Jan 2009
Location: Zoetermeer, Holland
Posts: 555
Tut mir leid Knut, I vote for the Singapore option
Reply With Quote
  #6 (permalink)  
Old 01-26-12, 09:48
db2girl db2girl is offline
∞∞∞∞∞∞
 
Join Date: Aug 2008
Location: Toronto, Canada
Posts: 1,816
There is no better way to generate: \" and \" ?


These tables are part of Tivoli Data Warehouse product. Caning is way too severe and I read it can't be used for women and men over 50.
Reply With Quote
  #7 (permalink)  
Old 01-26-12, 13:44
stolze stolze is offline
Registered User
 
Join Date: Jan 2007
Location: Jena, Germany
Posts: 2,662
I would probably wrap the formatting into a simple SQL UDF, which does the concatenation and wrapping into ". Then you call this UDF:
Code:
SELECT 'db2 runstats on table '|| format_table_name(tabschema, tabname) || ' with distribution on key columns and detailed indexes all'
FROM syscat.tables where type = 'T'
__________________
Knut Stolze
IBM DB2 Analytics Accelerator
IBM Germany Research & Development
Reply With Quote
  #8 (permalink)  
Old 01-26-12, 20:14
db2girl db2girl is offline
∞∞∞∞∞∞
 
Join Date: Aug 2008
Location: Toronto, Canada
Posts: 1,816
Quote:
Originally Posted by stolze View Post
I would probably wrap the formatting into a simple SQL UDF, which does the concatenation and wrapping into ".
I've never written one before. Could you please show an example of format_table_name?
Reply With Quote
  #9 (permalink)  
Old 01-26-12, 20:29
db2girl db2girl is offline
∞∞∞∞∞∞
 
Join Date: Aug 2008
Location: Toronto, Canada
Posts: 1,816
This site has some bug. This is a new thread, but it's got so many Views...
Reply With Quote
  #10 (permalink)  
Old 01-26-12, 21:50
stolze stolze is offline
Registered User
 
Join Date: Jan 2007
Location: Jena, Germany
Posts: 2,662
I don't have a DB2 instance at hand right now. So here is an untested version:
Code:
CREATE FUNCTION format_table_name(schemaName VARCHAR(128), tableName VARCHAR(128))
   RETURNS VARCHAR(261)
   LANGUAGE SQL
   DETERMINISTIC
   CONTAINS SQL
   RETURN '"' || RTRIM(schemaName) || '"."' || RTRIM(tableName) || '"'
__________________
Knut Stolze
IBM DB2 Analytics Accelerator
IBM Germany Research & Development
Reply With Quote
  #11 (permalink)  
Old 01-27-12, 07:05
Marcus_A Marcus_A is offline
Registered User
 
Join Date: May 2003
Location: USA
Posts: 5,198
I personally don't think it is a good idea for any DBA maint scripts to rely on custom functions, views, etc that are not part of the DB. This is especially true for databases created by vendor packages.
__________________
M. A. Feldman
IBM Certified DBA on DB2 for Linux, UNIX, and Windows
IBM Certified DBA on DB2 for z/OS and OS/390
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On