Wednesday, December 2, 2015

How to run a sql script on all the nodes of the exadata box and all running instances.


This method can be used to run a sql script in the "connect" file on all the running instances in the exadata cluster.There can be many ways of doing it .I am highlighting one of the ways of doing it as below.
The first step is to create the following two files containing our scripts.The first script command_20151130.sh contains the OS command to get the instance name and to run the second script.The second script named "connect" contains the actual sqls that we want to run on each of the running instances on the exadata machine

$cat command_20151130.sh
ps -ef |grep ora_pmon | grep -v grep | awk '{print $NF}' | cut -d '_' -f3 | while read line; do /tmp/connect_20151130.sh $line; done

$cat connect.sh
export ORACLE_SID=$1
export ORAENV_ASK=NO
. oraenv
sqlplus -s / as sysdba << EOF
select instance_name from v\$instance;
show parameter local_listener
exit;
EOF

Now since we have the OS command and the sql script prepared following steps can be used .

#Step 1. Following command can be used to copy the above 2 files to all the nodes in the /tmp or any other location of the choice.

$ for f in $( cat ~/dbs_group ) ; do scp connect.sh,command.sh oracle@$f:/tmp; done

#Step 2. Change the permission of these files on all the nodes to make them executatble

dcli -l oracle -g ~/dbs_group chmod u+x /tmp/connect.sh ; chmod u+x command_20151130.sh

#Step 3 .Run the final command  as following on all the nodes.

$dcli -l oracle -g dbs_group /tmp/command_20151130.sh

#Step 4.  After it's all done it is good idea to clean up the /tmp dir on each db node to free up the space.

$dcli -g ~/dbs_group -l oracle rm /tmp/connect_20151130.sh ; rm /tmp/command_20151130.sh


1 comment:

Anonymous said...

Casino Site Review - Online Casino in Cambodia
This Casino site is owned by SBC Asia and is open and owned by Casino 카지노 룰렛 Official. Read the Casino Site review here to get information about it.