Results 1 to 3 of 3
  1. #1
    Join Date
    Jun 2016
    Posts
    2

    Answered: Running imports/exports in parallel with sub shell

    Hey all ,

    So was doing a bit of digging around trying to script an annoying process we use. Essentially export tables from production DB and import them into the current Test DB.
    By hand what we do is open 3 different terminals and run them parallel to reduce the time. There's no locking issue or anything which prevents them from running at the same time.

    I was trying to just do
    Code:
    db2 -tf export1.sql &
    pid1=$!
    db2 -tf export2.sql &
    pid2=$!
    db2 -tf export3.sql &
    pid=$!
    
    wait pid1
    wait pid2
    wait pid3
    but then I found it was only doing them sequentially. Looking online I found this.
    This is expected. The 'db2' process (the "front-end" process)
    communicates with the 'db2bp' process (the "back-end" process), and
    db2bp does all of the actual work. You can only have a single db2bp
    associated with your shell, and db2bp can only communicate with a
    single db2 process



    So I followed the advice and essentially made a script like so
    Code:
    #!/bin/ksh
    
    function run_db2 {
        file=$1
    
        (
           . /home/db2inst1/.profile
           db2 -tvf ${file}
        ) &
    }
    
    
    run_db2 export1.sql
    run_db2 export2.sql
    run_db2 export3.sql
    
    wait
    
    print "Extracts done."

    However I notice that it took a long time to complete...
    Did a little test and running this
    bash-4.2$ touch timestart; db2 -tf export1.sql ; db2 -tf export3.sql ; db2 -tf export3.sql ; touch timestop
    bash-4.2$ touch timestart2 ;nohup sh wrapper_import.sh ; touch timestop2


    Had the same time. What exactly am i doing wrong ?

  2. Best Answer
    Posted by mark.b

    "Hi,

    try this:
    Code:
    for n in 1 2 3; do
      nohup /bin/ksh -c ". /home/db2inst1/.profile; db2 -tvf export${n}.sql; exit 0" > /dev/null 2>&1 &
    done
    "


  3. #2
    Join Date
    Jul 2013
    Location
    Moscow, Russia
    Posts
    666
    Provided Answers: 55
    Hi,

    try this:
    Code:
    for n in 1 2 3; do
      nohup /bin/ksh -c ". /home/db2inst1/.profile; db2 -tvf export${n}.sql; exit 0" > /dev/null 2>&1 &
    done
    Regards,
    Mark.

  4. #3
    Join Date
    Jun 2016
    Posts
    2
    Quote Originally Posted by mark.b View Post
    Hi,

    try this:
    Code:
    for n in 1 2 3; do
      nohup /bin/ksh -c ". /home/db2inst1/.profile; db2 -tvf export${n}.sql; exit 0" > /dev/null 2>&1 &
    done
    Thank you so much for this !

    Seems to be working fine .... added this to it though for tracking since I wasn't able to track the nohup job itself for some reason

    Code:
    rm /home/db2inst1/pids
    i=0
    for n in 1 2 3; do
        i=$((i + 1))  
        nohup /bin/ksh -c ". /home/db2inst1/.profile; db2 -tvf export${n}.sql; exit 0" >;echo $! >> /home/db2inst1/pids /dev/null 2>&1 &
    done
    for i in $(cat /home/db2inst1/pids);do
        wait ${i}
    done
    Works pretty well but for some reason one of the process ID's isn't being tracked or echo'd into the file. Will investigate further but I just want to thank you so much for helping on this. Was a highly frustrating experience !

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •