Backgrounding a linux task

Problem:  Want to make a Oracle mview refresh run in the background so it doesnt timeout after 2 hours of running (our company’s network timeout)

On the Oracle Server

  • Create the file with the SQL code you want to run. Mine is called mv_fp.sql
  • BEGIN
      DBMS_SNAPSHOT.REFRESH(
        LIST => 'SCHEMA.MV_MVIEW'
       ,METHOD => 'C'
       ,PUSH_DEFERRED_RPC => TRUE
       ,REFRESH_AFTER_ERRORS => FALSE
       ,PURGE_OPTION => 1
       ,PARALLELISM => 4
       ,ATOMIC_REFRESH => TRUE
       ,NESTED => FALSE);
    END;
    /
  • Create the file with the shell code you want to run. Mine is called mv_fp.sh
  • export ORACLE_SID=MYDB
    sqlplus schema/password << eof
    @mv_fp.sql
    exit
    eof
    • Grant execute access on the .sh file

    chmod 744 mv_fp.sh
    • Run the following to background the task

    nohup ./mv_fp.sh > nohup_mv_fp.out 2>&1 &
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: