In my environment I have worked on schema refresh frequently in different situation. In production I have done schema refresh during the database downtime.Mostly schema refresh is used to avoid the database fragmentation.
I have automated the above activity.Refer the below script.
******************************************************************************************
##############################################################################
##############################################################################
#!/bin/sh
. $HOME/.bash_profile
cd /home/oracle/dbatest/raja/mknode/schemarefresh
RUNDATE=`date “+%d%m%y at %H:%M:%S”`
DBHOME=$ORACLE_HOME
PATH=/home/oracle/dbatest/raja/mknode/schemarefresh
mknod export_pipe p
gzip -cNf $ORACLE_SID.dmp.gz &
exp parfile=/home/oracle/dbatest/raja/mknode/schemarefresh/exp_param file=export_pipe log=$PATH/export_$ORACLE_SID.log
cat $PATH/export_$ORACLE_SID.log | grep “EXP-” > $PATH/exp_$ORACLE_SID.err
mail -s “Status of $ORACLE_SID export backup on $RUNDATE ” rajabaskar.thangaraj@abcde.com < $PATH/exp_$ORACLE_SID.err
rm -f export_pipe p
WORDCOUNT=`wc $PATH/exp_$ORACLE_SID.err | awk ‘{print $1}’`
if [ $WORDCOUNT -ne 0 ]; then
exit 16;
else
sh /home/oracle/dbatest/raja/mknode/schemarefresh/killuser.sh
sh /home/oracle/dbatest/raja/mknode/schemarefresh/killuser_script.sh
sh /home/oracle/dbatest/raja/mknode/schemarefresh/usercreation.sh
sh /home/oracle/dbatest/raja/mknode/schemarefresh/imppipemail.sh
fi
Script 2
*******************************************************************
##############################################################################
##############################################################################
userid=testpipe1/testpipe1 owner=testpipe1 buffer=10485667 statistics=none object_consistent=y
Script 3
*******************************************************************
##############################################################################
##############################################################################
#!bin/ksh
. $HOME/.bash_profile
sqlplus /nolog << EOF
conn dba/dba123@test as sysdba
set feedback off
set heading off
@/home/oracle/dbatest/raja/mknode/schemarefresh/finduser.sql
Disconnect
Exit
Script 4
*******************************************************************
##############################################################################
##############################################################################
spool /home/oracle/dbatest/raja/mknode/schemarefresh/killuser_script.sh
select ‘kill -9 ‘|| V$P.SPID || ‘;’ from v$session V$S,v$process V$P
where V$S.PADDR = V$P.ADDR and V$S.SID in (select distinct sid from v$session
where schemaname=’TESTPIPE1′) order by V$S.PROCESS,V$S.SID;
spool off
exit
Note: This script generate the syntax like this ” kill -9 142345 ” .
Script 5
*******************************************************************
##############################################################################
##############################################################################
Drop user testpipe cascade;
create user testpipe
identified by testpipe
default tablespace users
quota unlimited on users;
grant connect,resource,imp_full_database to testpipe;
Script 6
*******************************************************************
##############################################################################
##############################################################################
#!bin/ksh
. $HOME/.bash_profile
sqlplus /nolog <
conn dba/dba123@test
@/home/oracle/dbatest/raja/mknode/schemarefresh/dropandrecreateuser.sql
Disconnect
Exit
Script 7
*******************************************************************
##############################################################################
##############################################################################
#!/bin/sh
. $HOME/.bash_profile
cd /home/oracle/dbatest/raja/mknode/schemarefresh/
PATH=/home/oracle/dbatest/raja/mknode/schemarefresh
mknod import_pipe p
gunzip -c $ORACLE_SID.dmp.gz > import_pipe &
imp parfile=/home/oracle/dbatest/raja/mknode/schemarefresh/imp_param file=import_pipe log=$PATH/import_$ORACLE_SID.log
cat $PATH/import_$ORACLE_SID.log | grep “IMP-” > $PATH/imp_$ORACLE_SID.err
mail -s “Status of $ORACLE_SID import done on $RUNDATE ” rajabaskar.thangaraj@abcde.com < $PATH/imp_$ORACLE_SID.err
rm -f import_pipe p
*******************************************************************
##############################################################################
##############################################################################
userid=testpipe/testpipe fromuser=demo touser=testpipe buffer=10485667 statistics=none commit=y
In this script i have used the mknod option.No need to use this mknod for this activity.Because schema refresh on same server.
Compression & uncompression activity affect the system performance.
More detais about MKNOD :http://www.primeinspiration.com/programming/database/oracle/84-using-mknod-during-export.html
I Hope this article helped you to understand the automated schema refresh.Suggestions are welcome.