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 > DB2 Maintenance Batch...

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-26-10, 13:20
mitsubishi3000gt mitsubishi3000gt is offline
Registered User
 
Join Date: Jan 2010
Posts: 8
Question DB2 Maintenance Batch...

Good afternoon everyone,

I am trying to create a very basic DB2 batch file that will connect to a specific database and then issue the REORGCHK command.

I started off with:

db2cmd DB2 connect to <database> user <username> using <password>
*** the above command in the batch file gets me connected to that database ***

Then i issue the other second part which is to REORGCHK the tables

db2 reorgchk update statistics on table all > (output.txt path)
*** At this point manually ran it would work but via the batch file it just sits at the login successful window***

Not sure if anyone has accomplished this or how are other DB2 admin accomplishing this, so that it is automatically and not manually.

Thank you in advance for all of your assistance,

Mit
Reply With Quote
  #2 (permalink)  
Old 01-26-10, 13:28
ARWinner ARWinner is offline
Registered User
 
Join Date: Jan 2003
Posts: 3,575
What is your DB2 version and OS? Can you post your entire "DB2 batch" file?

Andy
Reply With Quote
  #3 (permalink)  
Old 01-26-10, 13:33
mitsubishi3000gt mitsubishi3000gt is offline
Registered User
 
Join Date: Jan 2010
Posts: 8
This is running on a windows server 2003 and with DB Enterprise edition.

The batch file that i currently have is something like.

@echo off
Rem Connect to database
db2cmd DB2 connect to <database> user <username> using <password>
db2 reorgchk update statistics on table all > (output.txt path)
pause

But the second command where i am telling it to run the reorgchk never runs.
Reply With Quote
  #4 (permalink)  
Old 01-26-10, 13:40
n_i n_i is offline
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,449
1. Look at the correct db2cmd invokation in the manual. The way you are trying to do it, db2cmd never returns.
2. Even if it does, the connection you establish there will be closed, because db2cmd creates a separate shell.
Reply With Quote
  #5 (permalink)  
Old 01-26-10, 13:40
ARWinner ARWinner is offline
Registered User
 
Join Date: Jan 2003
Posts: 3,575
Do it this way:

Put all of your DB2 statements is a DB2 script like this:

connect to <database> user <username> using <password>;
reorgchk update statistics on table all

Then you batch would be:

db2cmd DB2 -z output.txt -svf <DB2 script filename>

Andy
Reply With Quote
  #6 (permalink)  
Old 01-26-10, 13:43
n_i n_i is offline
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,449
You may want to check out this thread: dos scripits for db2
Reply With Quote
  #7 (permalink)  
Old 01-26-10, 14:11
mitsubishi3000gt mitsubishi3000gt is offline
Registered User
 
Join Date: Jan 2010
Posts: 8
Ok so this is what i have for a batch file since i am currently running it from the desktop.

c:
cd \Program Files\IBM\SQLLIB\BIN
db2cmd db2setcp "&#37;1 %2 %3 %4 %5 %6 %7 %8 %9"
db2cmd db2 connect to <database name> user <username> using <password>
====to this point the batch file runs and connects to the DB ===
db2 reorgchk update statistics on table all > "c:\Program Files\IBM\Logs\reorgchk.txt"

==== above is the command line that i can not seem to get working ===

Do i need to write the above commands on a different file extension other than .bat?

How can i get it to work?
Reply With Quote
  #8 (permalink)  
Old 01-26-10, 14:16
ARWinner ARWinner is offline
Registered User
 
Join Date: Jan 2003
Posts: 3,575
Your problem is that db2cmd spawns off the process so what happens next is unrelated. Look at the link that Nick supplied.

Andy
Reply With Quote
  #9 (permalink)  
Old 01-26-10, 14:50
mitsubishi3000gt mitsubishi3000gt is offline
Registered User
 
Join Date: Jan 2010
Posts: 8
Hi Andy,

So how should i write this batch file so that db2cmd does not spawn off?

I checked the above link and added the code line;

@echo off
rem If we're not called from DB2CLP, call ourselves again
if "&#37;DB2CLP%" == "" db2cmd /c /i /w %0 %* & goto :eof

c:
cd \Program Files\IBM\SQLLIB\BIN
db2cmd db2setcp "%1 %2 %3 %4 %5 %6 %7 %8 %9"
db2cmd db2 connect to <database name> user <username> using <password>
db2 reorgchk update statistics on table all > "c:\Program Files\IBM\Logs\reorgchk.txt"

And nothing happens.

How should i be writting this batch file?
Reply With Quote
  #10 (permalink)  
Old 01-26-10, 14:57
ARWinner ARWinner is offline
Registered User
 
Join Date: Jan 2003
Posts: 3,575
Based on the link, it should look like:

Code:
@echo off
c:
cd \Program Files\IBM\SQLLIB\BIN
rem If we're not called from DB2CLP, call ourselves again
if "%DB2CLP%" == "" db2cmd /c /i /w %0 %* & goto :eof

db2 connect to <database name> user <username> using <password>
db2 reorgchk update statistics on table all > "c:\Program Files\IBM\Logs\reorgchk.txt"
Andy
Reply With Quote
  #11 (permalink)  
Old 01-26-10, 15:08
dav1mo dav1mo is offline
Registered User
 
Join Date: Dec 2007
Location: Richmond, VA
Posts: 782
He told you several posts ago to remove the db2cmd from your script and then use db2cmd when executing the script.
Dave
Reply With Quote
  #12 (permalink)  
Old 01-26-10, 15:08
mitsubishi3000gt mitsubishi3000gt is offline
Registered User
 
Join Date: Jan 2010
Posts: 8
Once i run the above batch, i get a very quick message on the screen and disappears.

'c:\Documents' is not recognized as an internal or external command.

Any ideas?
Reply With Quote
  #13 (permalink)  
Old 01-26-10, 15:13
n_i n_i is offline
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,449
Quote:
Originally Posted by mitsubishi3000gt View Post

Any ideas?
Yes, I've got one. Read dos scripits for db2 again.
Reply With Quote
  #14 (permalink)  
Old 01-26-10, 15:13
ARWinner ARWinner is offline
Registered User
 
Join Date: Jan 2003
Posts: 3,575
Open the "Command Prompt" window and try to execute from there and see what you get. Also try from the "DB2 Command Window"

Andy
Reply With Quote
  #15 (permalink)  
Old 01-26-10, 15:19
mitsubishi3000gt mitsubishi3000gt is offline
Registered User
 
Join Date: Jan 2010
Posts: 8
Hi Andy,

Is there a way to use DB2 command window right from the start within a batch file. Because that is how i have been doing the maintenance on it, via the DB2 command window one command at it time.

Please advise and if there is anyone who is already doing what i am trying to accomplish please share the code.

Thank you,

Mit
Reply With Quote
Reply

Tags
db2, maintenance, reorgchk

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