<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
		<id>https://mailnest.com/dbawiki/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Stuart</id>
		<title>dbawiki - User contributions [en]</title>
		<link rel="self" type="application/atom+xml" href="https://mailnest.com/dbawiki/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Stuart"/>
		<link rel="alternate" type="text/html" href="https://mailnest.com/dbawiki/index.php/Special:Contributions/Stuart"/>
		<updated>2026-04-04T03:32:03Z</updated>
		<subtitle>User contributions</subtitle>
		<generator>MediaWiki 1.29.3</generator>

	<entry>
		<id>https://mailnest.com/dbawiki/index.php?title=Database_Status&amp;diff=3403</id>
		<title>Database Status</title>
		<link rel="alternate" type="text/html" href="https://mailnest.com/dbawiki/index.php?title=Database_Status&amp;diff=3403"/>
				<updated>2018-12-09T14:41:28Z</updated>
		
		<summary type="html">&lt;p&gt;Stuart: /* Show the ten largest objects in the database */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;===Check datafiles for their recovery status (compared with what is in the controlfile)===&lt;br /&gt;
Depending on how the database was last shut down (or recovered), this will show if data files are to of sync with the control file.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 1000 pages 100 numwidth 15&lt;br /&gt;
col name for a60&lt;br /&gt;
col stats for a6&lt;br /&gt;
col datafile_status for a18&lt;br /&gt;
select&lt;br /&gt;
a.name&lt;br /&gt;
,a.status&lt;br /&gt;
,a.file#&lt;br /&gt;
,a.checkpoint_change# control_file_SCN&lt;br /&gt;
,b.checkpoint_change# datafile_SCN&lt;br /&gt;
,case&lt;br /&gt;
when ((a.checkpoint_change# - b.checkpoint_change#) = 0) THEN &amp;#039;Startup Normal&amp;#039;&lt;br /&gt;
when ((b.checkpoint_change#) = 0) THEN &amp;#039;File Missing?&amp;#039;&lt;br /&gt;
when ((a.checkpoint_change# - b.checkpoint_change#) &amp;gt; 0) THEN &amp;#039;Media Rec. Req.&amp;#039;&lt;br /&gt;
when ((a.checkpoint_change# - b.checkpoint_change#) &amp;lt; 0) THEN &amp;#039;Old Control File&amp;#039;&lt;br /&gt;
else &amp;#039;what the ?&amp;#039;&lt;br /&gt;
end datafile_status&lt;br /&gt;
from v$datafile a        -- control file SCN for datafile&lt;br /&gt;
    ,v$datafile_header b -- datafile header SCN&lt;br /&gt;
where a.file# = b.file#&lt;br /&gt;
order by a.file#&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===How to stop and start a database on a Solaris Veritas cluster===&lt;br /&gt;
Using command line...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Cluster logfile		/var/VRTSvcs/log/engine_A.log&lt;br /&gt;
Cluster status		hastatus -sum&lt;br /&gt;
Clear failed resource	hares -clear $SID_ORA -sys $host &lt;br /&gt;
Start database		hares -online $SID_ORA -sys $host &lt;br /&gt;
Start listener		hares -online $SID_LSNR -sys $host&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or using a script...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cat cluster_database.ksh start|stop &amp;lt;SID&amp;gt;&lt;br /&gt;
#!/bin/ksh&lt;br /&gt;
#set -x &lt;br /&gt;
&lt;br /&gt;
database=$2&lt;br /&gt;
PATH=$PATH:/opt/VRTSvcs/bin&lt;br /&gt;
export PATH&lt;br /&gt;
DATUM=`date +%Y%m%d`&lt;br /&gt;
LOGFILE=&amp;quot;/oracle/logs/cluster_scripts.${DATUM}.log&amp;quot;&lt;br /&gt;
typeset -i count&lt;br /&gt;
typeset -i seconds&lt;br /&gt;
count=1&lt;br /&gt;
seconds=0&lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;`date +%Y%m%d-%H%M`: we will $1 database ${database}&amp;quot; | tee -a ${LOGFILE}&lt;br /&gt;
#########################################################################&lt;br /&gt;
# Run this script as root to stop/start Oracle database incl. listeners #&lt;br /&gt;
#########################################################################&lt;br /&gt;
#&lt;br /&gt;
case $1 in&lt;br /&gt;
start)&lt;br /&gt;
        #system=`hares -value ${database}_ORA LastOnline`&lt;br /&gt;
        #if [ -z &amp;quot;${system}&amp;quot; ]&lt;br /&gt;
        #then&lt;br /&gt;
                #system=`uname -n`&lt;br /&gt;
        #fi&lt;br /&gt;
        diskgroup=&amp;quot;`echo $database | tr [A-Z] [a-z]`dg&amp;quot;&lt;br /&gt;
        system=`hares -state ${diskgroup} | grep ONLINE | nawk &amp;#039;{print $3}&amp;#039;`&lt;br /&gt;
        if [ -z &amp;quot;${system}&amp;quot; ]&lt;br /&gt;
        then&lt;br /&gt;
                echo &amp;quot;resource group ${database} has not been started on any system in the cluster. Please request administrator to start resourcegroup&amp;quot; | tee -a ${LOGFILE}&lt;br /&gt;
        fi&lt;br /&gt;
        status=`hares -state ${database}_ORA -sys ${system} | nawk &amp;#039;{print $NF}&amp;#039;`&lt;br /&gt;
        if [ &amp;quot;${status}&amp;quot; = &amp;quot;FAULTED&amp;quot; ]&lt;br /&gt;
        then&lt;br /&gt;
                echo &amp;quot;`date +%Y%m%d-%H%M`: Clearing faulted resource ${database}_ORA on system ${system}&amp;quot; | tee -a ${LOGFILE}&lt;br /&gt;
                hares -clear ${database}_ORA -sys ${system} 2&amp;gt;&amp;amp;1 | tee -a ${LOGFILE}&lt;br /&gt;
        fi&lt;br /&gt;
        echo &amp;quot;`date +%Y%m%d-%H%M`: Onlining resource ${database}_ORA on system ${system}&amp;quot;  | tee -a ${LOGFILE}&lt;br /&gt;
        hares -online ${database}_ORA -sys ${system} 2&amp;gt;&amp;amp;1 | tee -a ${LOGFILE}&lt;br /&gt;
        sleep 5&lt;br /&gt;
        temp=`hares -state ${database}_ORA | grep ONLINE | nawk &amp;#039;{print $3}&amp;#039;`&lt;br /&gt;
        while [ -z &amp;quot;${temp}&amp;quot; ]&lt;br /&gt;
        do&lt;br /&gt;
                seconds=count*5&lt;br /&gt;
                echo &amp;quot;`date +%Y%m%d-%H%M`: Database resource ${database}_ORA not yet online after ${seconds} seconds&amp;quot; | tee -a ${LOGFILE}&lt;br /&gt;
                echo &amp;quot;`date +%Y%m%d-%H%M`: Status of resource ${database}_ORA&amp;quot; | tee -a ${LOGFILE}&lt;br /&gt;
                hares -state ${database}_ORA 2&amp;gt;&amp;amp;1 | tee -a ${LOGFILE}&lt;br /&gt;
                if [ $seconds -gt 300 ]&lt;br /&gt;
                then&lt;br /&gt;
                        echo &amp;quot;`date +%Y%m%d-%H%M`: Database resource ${database}_ORA still not online after ${seconds} seconds. We are exiting the script. Please check the Oracle alert log&amp;quot; | tee -a ${LOGFILE}&lt;br /&gt;
                        exit 1&lt;br /&gt;
                fi&lt;br /&gt;
                sleep 5&lt;br /&gt;
                temp=`hares -state ${database}_ORA | grep ONLINE | nawk &amp;#039;{print $3}&amp;#039;`&lt;br /&gt;
                count=count+1&lt;br /&gt;
        done&lt;br /&gt;
        echo &amp;quot;`date +%Y%m%d-%H%M`: Database Resource ${database}_ORA is online on system ${system}&amp;quot; | tee -a ${LOGFILE}&lt;br /&gt;
        system=`hares -value ${database}_LSNR LastOnline`&lt;br /&gt;
        if [ &amp;quot;${status}&amp;quot; = &amp;quot;FAULTED&amp;quot; ]&lt;br /&gt;
        then&lt;br /&gt;
                echo &amp;quot;`date +%Y%m%d-%H%M`: Clearing faulted resource ${database}_LSNR on system ${system}&amp;quot; | tee -a ${LOGFILE}&lt;br /&gt;
                hares -clear ${database}_LSNR -sys ${system}&lt;br /&gt;
        fi&lt;br /&gt;
        echo &amp;quot;`date +%Y%m%d-%H%M`: Onlining resource ${database}_LSNR on system ${system}&amp;quot;  | tee -a ${LOGFILE}&lt;br /&gt;
        hares -online ${database}_LSNR -sys ${system} 2&amp;gt;&amp;amp;1 | tee -a ${LOGFILE}&lt;br /&gt;
        count=1&lt;br /&gt;
        sleep 5&lt;br /&gt;
        temp=`hares -state ${database}_LSNR | grep ONLINE | nawk &amp;#039;{print $3}&amp;#039;`&lt;br /&gt;
        while [ -z &amp;quot;${temp}&amp;quot; ]&lt;br /&gt;
        do&lt;br /&gt;
                seconds=count*5&lt;br /&gt;
                echo &amp;quot;`date +%Y%m%d-%H%M`: Listener resource ${database}_LSNR not yet online after ${seconds} seconds&amp;quot; | tee -a ${LOGFILE}&lt;br /&gt;
                echo &amp;quot;`date +%Y%m%d-%H%M`: Status of resource ${database}_LSNR&amp;quot; | tee -a ${LOGFILE}&lt;br /&gt;
                hares -state ${database}_LSNR 2&amp;gt;&amp;amp;1 | tee -a ${LOGFILE}&lt;br /&gt;
                if [ $seconds -gt 300 ]&lt;br /&gt;
                then&lt;br /&gt;
                        echo &amp;quot;`date +%Y%m%d-%H%M`: Listener resource ${database}_LSNR still not online after ${seconds} seconds. We are exiting the script. Please check the Listener alert log&amp;quot; | tee -a ${LOGFILE}&lt;br /&gt;
                        exit 1&lt;br /&gt;
                fi&lt;br /&gt;
                sleep 5&lt;br /&gt;
                temp=`hares -state ${database}_LSNR | grep ONLINE | nawk &amp;#039;{print $3}&amp;#039;`&lt;br /&gt;
                count=count+1&lt;br /&gt;
        done&lt;br /&gt;
        echo &amp;quot;`date +%Y%m%d-%H%M`: Listener Resource ${database}_LSNR is online on system ${system}&amp;quot; | tee -a ${LOGFILE}&lt;br /&gt;
        resources=`hares -dep | grep &amp;quot;${database}_LSNR$&amp;quot; | nawk &amp;#039;{print $2}&amp;#039;`&lt;br /&gt;
        for res in ${resources}&lt;br /&gt;
        do&lt;br /&gt;
                echo &amp;quot;`date +%Y%m%d-%H%M`: Onlining resource ${res} on system ${system}&amp;quot; | tee -a ${LOGFILE}&lt;br /&gt;
                hares -online ${res} -sys ${system}&lt;br /&gt;
                sleep 5&lt;br /&gt;
                echo &amp;quot;`date +%Y%m%d-%H%M`: Status of resource ${res}&amp;quot;  | tee -a ${LOGFILE}&lt;br /&gt;
                hares -state ${res} 2&amp;gt;&amp;amp;1 | tee -a ${LOGFILE}&lt;br /&gt;
        done&lt;br /&gt;
        ;;&lt;br /&gt;
stop)&lt;br /&gt;
        typeset -i count&lt;br /&gt;
        count=0&lt;br /&gt;
        resources=`hares -dep | grep &amp;quot;${database}_LSNR$&amp;quot; | nawk &amp;#039;{print $2}&amp;#039;`&lt;br /&gt;
        for res in ${resources}&lt;br /&gt;
        do&lt;br /&gt;
                echo &amp;quot;`date +%Y%m%d-%H%M`: Offlining resource ${res} on system ${system} which depends on resource ${database}_LSNR&amp;quot; | tee -a ${LOGFILE}&lt;br /&gt;
                system=`hares -state ${res} | grep ONLINE | nawk &amp;#039;{print $3}&amp;#039;`&lt;br /&gt;
                if [ -n &amp;quot;${system}&amp;quot; ]&lt;br /&gt;
                then&lt;br /&gt;
                        hares -offline ${res} -sys ${system} 2&amp;gt;&amp;amp;1 | tee -a ${LOGFILE}&lt;br /&gt;
                fi&lt;br /&gt;
                sleep 5&lt;br /&gt;
                temp=`hares -state ${res} | tail +2 | grep -v OFFLINE | grep -v FAULTED | nawk &amp;#039;{print $3}&amp;#039;`&lt;br /&gt;
                count=1&lt;br /&gt;
                while [ -n &amp;quot;${temp}&amp;quot; ]&lt;br /&gt;
                do&lt;br /&gt;
                        seconds=count*5&lt;br /&gt;
                        echo &amp;quot;`date +%Y%m%d-%H%M`: resource ${res} not yet offline after ${seconds} seconds&amp;quot; | tee -a ${LOGFILE}&lt;br /&gt;
                        echo &amp;quot;`date +%Y%m%d-%H%M`: Status of resource ${res}&amp;quot; | tee -a ${LOGFILE}&lt;br /&gt;
                        hares -state ${res} 2&amp;gt;&amp;amp;1 | tee -a ${LOGFILE}&lt;br /&gt;
                        if [ $seconds -gt 300 ]&lt;br /&gt;
                        then&lt;br /&gt;
                                echo &amp;quot;`date +%Y%m%d-%H%M`: resource ${res} still not offline after ${seconds} seconds. We are exiting the script. Please check the alert log&amp;quot; | tee -a ${LOGFILE}&lt;br /&gt;
                                exit 1&lt;br /&gt;
                        fi&lt;br /&gt;
                        sleep 5&lt;br /&gt;
                        count=count+1&lt;br /&gt;
                        temp=`hares -state ${res} | tail +2 | grep -v OFFLINE | grep -v FAULTED | nawk &amp;#039;{print$3}&amp;#039;`&lt;br /&gt;
                done&lt;br /&gt;
                FAULTED=`hares -state ${res} | grep FAULTED | nawk &amp;#039;{print $3}&amp;#039;`&lt;br /&gt;
                if [ -n &amp;quot;${FAULTED}&amp;quot; ]&lt;br /&gt;
                then&lt;br /&gt;
                        hares -clear ${res} -sys ${system} 2&amp;gt;&amp;amp;1 | tee -a ${LOGFILE}&lt;br /&gt;
                fi&lt;br /&gt;
                echo &amp;quot;`date +%Y%m%d-%H%M`: Resource ${res} is offline on system ${system}&amp;quot; | tee -a ${LOGFILE}&lt;br /&gt;
        done&lt;br /&gt;
&lt;br /&gt;
        system=`hares -state ${database}_LSNR | grep ONLINE | nawk &amp;#039;{print$3}&amp;#039;`&lt;br /&gt;
        if [ -n &amp;quot;${system}&amp;quot; ]&lt;br /&gt;
        then&lt;br /&gt;
                echo &amp;quot;`date +%Y%m%d-%H%M`: Stopping ${database}_LSNR on ${system}&amp;quot; | tee -a ${LOGFILE}&lt;br /&gt;
                hares -offline ${database}_LSNR -sys ${system} 2&amp;gt;&amp;amp;1 | tee -a ${LOGFILE}&lt;br /&gt;
        fi&lt;br /&gt;
        sleep 5&lt;br /&gt;
        count=1&lt;br /&gt;
        temp=`hares -state ${database}_LSNR | tail +2 | grep -v OFFLINE | grep -v FAULTED | nawk &amp;#039;{print$3}&amp;#039;`&lt;br /&gt;
        while [ -n &amp;quot;${temp}&amp;quot; ]&lt;br /&gt;
        do&lt;br /&gt;
                seconds=count*5&lt;br /&gt;
                echo &amp;quot;`date +%Y%m%d-%H%M`: Listener resource ${database}_LSNR not yet offline after ${seconds} seconds&amp;quot; | tee -a ${LOGFILE}&lt;br /&gt;
                echo &amp;quot;`date +%Y%m%d-%H%M`: Status of resource ${database}_LSNR&amp;quot; | tee -a ${LOGFILE}&lt;br /&gt;
                hares -state ${database}_LSNR 2&amp;gt;&amp;amp;1 | tee -a ${LOGFILE}&lt;br /&gt;
                if [ $seconds -gt 300 ]&lt;br /&gt;
                then&lt;br /&gt;
                        echo &amp;quot;`date +%Y%m%d-%H%M`: Listener resource ${database}_LSNR still not offline after ${seconds} seconds. We are exiting the script. Please check the listener alert log&amp;quot; | tee -a ${LOGFILE}&lt;br /&gt;
                        exit 1&lt;br /&gt;
                fi&lt;br /&gt;
                sleep 5&lt;br /&gt;
                count=count+1&lt;br /&gt;
                temp=`hares -state ${database}_LSNR | tail +2 | grep -v OFFLINE | grep -v FAULTED | nawk &amp;#039;{print$3}&amp;#039;`&lt;br /&gt;
        done&lt;br /&gt;
        echo &amp;quot;`date +%Y%m%d-%H%M`: Listener Resource ${database}_LSNR is offline on system ${system}&amp;quot; | tee -a ${LOGFILE}&lt;br /&gt;
        system=`hares -state ${database}_ORA | grep ONLINE | nawk &amp;#039;{print$3}&amp;#039;`&lt;br /&gt;
        if [ -n &amp;quot;${system}&amp;quot; ]&lt;br /&gt;
        then&lt;br /&gt;
                echo &amp;quot;`date +%Y%m%d-%H%M`: Stopping ${database}_ORA on ${system}&amp;quot; | tee -a ${LOGFILE}&lt;br /&gt;
                hares -offline ${database}_ORA -sys ${system} 2&amp;gt;&amp;amp;1 | tee -a ${LOGFILE}&lt;br /&gt;
        fi&lt;br /&gt;
        sleep 5&lt;br /&gt;
        count=1&lt;br /&gt;
        temp=`hares -state ${database}_ORA | tail +2 | grep -v OFFLINE | grep -v FAULTED | nawk &amp;#039;{print$3}&amp;#039;`&lt;br /&gt;
        while [ -n &amp;quot;${temp}&amp;quot; ]&lt;br /&gt;
        do&lt;br /&gt;
                seconds=count*5&lt;br /&gt;
                echo &amp;quot;`date +%Y%m%d-%H%M`: Database resource ${database}_ORA not yet offline after ${seconds} seconds&amp;quot; | tee -a ${LOGFILE}&lt;br /&gt;
                echo &amp;quot;`date +%Y%m%d-%H%M`: Status of resource ${database}_ORA&amp;quot; | tee -a ${LOGFILE}&lt;br /&gt;
                hares -state ${database}_ORA 2&amp;gt;&amp;amp;1 | tee -a ${LOGFILE}&lt;br /&gt;
                if [ $seconds -gt 300 ]&lt;br /&gt;
                then&lt;br /&gt;
                        echo &amp;quot;`date +%Y%m%d-%H%M`: Database resource ${database}_ORA still not offline after ${seconds} seconds. We are exiting the script. Please check the database alert log&amp;quot; | tee -a ${LOGFILE}&lt;br /&gt;
                        exit 1&lt;br /&gt;
                fi&lt;br /&gt;
                sleep 5&lt;br /&gt;
                count=count+1&lt;br /&gt;
                temp=`hares -state ${database}_ORA | tail +2 | grep -v OFFLINE | grep -v FAULTED | nawk &amp;#039;{print$3}&amp;#039;`&lt;br /&gt;
        done&lt;br /&gt;
        echo &amp;quot;`date +%Y%m%d-%H%M`: Database Resource ${database}_ORA is offline on system ${system}&amp;quot; | tee -a ${LOGFILE}&lt;br /&gt;
&lt;br /&gt;
        ;;&lt;br /&gt;
esac&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*[[Tablespaces]]&lt;br /&gt;
&lt;br /&gt;
===Following a database crash...===&lt;br /&gt;
Check the status of the datafiles and tablespaces. They might need recovering.&amp;lt;br /&amp;gt;&lt;br /&gt;
Restarted and checked alert log. datafile 6 was in RECOVER status&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
SQL&amp;gt; recover datafile 6;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Checked dba_datafiles. File is now in OFFLINE status&lt;br /&gt;
&lt;br /&gt;
SQL&amp;gt; alter database datafile 6 online;&lt;br /&gt;
&lt;br /&gt;
...&lt;br /&gt;
Errors in file e:\oracle\product\admin\arisppmp\bdump\arisppmp_lgwr_5104.trc:&lt;br /&gt;
ORA-00494: enqueue [CF] held for too long (more than 900 seconds) by &amp;#039;inst 1, osid 4956&amp;#039;&lt;br /&gt;
&lt;br /&gt;
Wed Apr 30 02:35:29 2014&lt;br /&gt;
System State dumped to trace file e:\oracle\product\admin\arisppmp\bdump\arisppmp_lgwr_5104.trc&lt;br /&gt;
Wed Apr 30 02:35:30 2014&lt;br /&gt;
Errors in file e:\oracle\product\admin\arisppmp\udump\arisppmp_ora_13032.trc:&lt;br /&gt;
ORA-00603: ORACLE server session terminated by fatal error&lt;br /&gt;
ORA-00376: file 6 cannot be read at this time&lt;br /&gt;
ORA-01110: data file 6: &amp;#039;G:\ORADATA\ARISPPMP\ARISPPMP01.DBF&amp;#039;&lt;br /&gt;
ORA-00376: file 6 cannot be read at this time&lt;br /&gt;
ORA-01110: data file 6: &amp;#039;G:\ORADATA\ARISPPMP\ARISPPMP01.DBF&amp;#039;&lt;br /&gt;
&lt;br /&gt;
Killing enqueue blocker (pid=4956) on resource CF-00000000-00000000&lt;br /&gt;
 by killing session 167.1&lt;br /&gt;
Wed Apr 30 02:35:38 2014&lt;br /&gt;
Errors in file e:\oracle\product\admin\arisppmp\bdump\arisppmp_dbw0_4956.trc:&lt;br /&gt;
&lt;br /&gt;
Wed Apr 30 02:40:30 2014&lt;br /&gt;
Errors in file e:\oracle\product\admin\arisppmp\bdump\arisppmp_lgwr_5104.trc:&lt;br /&gt;
ORA-00494: enqueue [CF] held for too long (more than 900 seconds) by &amp;#039;inst 1, osid 4956&amp;#039;&lt;br /&gt;
&lt;br /&gt;
Wed Apr 30 02:40:30 2014&lt;br /&gt;
System State dumped to trace file e:\oracle\product\admin\arisppmp\bdump\arisppmp_lgwr_5104.trc&lt;br /&gt;
Killing enqueue blocker (pid=4956) on resource CF-00000000-00000000&lt;br /&gt;
 by terminating the process&lt;br /&gt;
LGWR: terminating instance due to error 2103&lt;br /&gt;
Wed Apr 30 02:40:32 2014&lt;br /&gt;
Errors in file e:\oracle\product\admin\arisppmp\bdump\arisppmp_arc1_6920.trc:&lt;br /&gt;
ORA-02103: PCC: inconsistent cursor cache (out-of-range cuc ref)&lt;br /&gt;
&lt;br /&gt;
Wed Apr 30 02:40:32 2014&lt;br /&gt;
Errors in file e:\oracle\product\admin\arisppmp\bdump\arisppmp_arc0_6912.trc:&lt;br /&gt;
ORA-02103: PCC: inconsistent cursor cache (out-of-range cuc ref)&lt;br /&gt;
&lt;br /&gt;
Wed Apr 30 02:40:33 2014&lt;br /&gt;
Errors in file e:\oracle\product\admin\arisppmp\bdump\arisppmp_arc0_6912.trc:&lt;br /&gt;
ORA-02103: PCC: inconsistent cursor cache (out-of-range cuc ref)&lt;br /&gt;
&lt;br /&gt;
Wed Apr 30 02:40:33 2014&lt;br /&gt;
Master background archival failure: 2103&lt;br /&gt;
Wed Apr 30 02:40:33 2014&lt;br /&gt;
Errors in file e:\oracle\product\admin\arisppmp\bdump\arisppmp_psp0_4848.trc:&lt;br /&gt;
ORA-02103: PCC: inconsistent cursor cache (out-of-range cuc ref)&lt;br /&gt;
&lt;br /&gt;
Wed Apr 30 02:40:33 2014&lt;br /&gt;
Errors in file e:\oracle\product\admin\arisppmp\bdump\arisppmp_dbw2_5056.trc:&lt;br /&gt;
ORA-02103: PCC: inconsistent cursor cache (out-of-range cuc ref)&lt;br /&gt;
&lt;br /&gt;
Wed Apr 30 02:40:35 2014&lt;br /&gt;
Errors in file e:\oracle\product\admin\arisppmp\bdump\arisppmp_smon_5208.trc:&lt;br /&gt;
ORA-02103: PCC: inconsistent cursor cache (out-of-range cuc ref)&lt;br /&gt;
&lt;br /&gt;
Wed Apr 30 02:40:36 2014&lt;br /&gt;
Instance terminated by LGWR, pid = 5104&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===How big is the database?===&lt;br /&gt;
Calculate the total database size&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 132&lt;br /&gt;
col dbname for a9  heading &amp;quot;Database&amp;quot;&lt;br /&gt;
col dbsize for a15 heading &amp;quot;Size&amp;quot;&lt;br /&gt;
col dbused for a15 heading &amp;quot;Used space&amp;quot;&lt;br /&gt;
col dbfree for a15 heading &amp;quot;Free space&amp;quot;&lt;br /&gt;
with used_space as&lt;br /&gt;
(&lt;br /&gt;
select  bytes&lt;br /&gt;
from    v$datafile&lt;br /&gt;
union   all&lt;br /&gt;
select  bytes&lt;br /&gt;
from    v$tempfile&lt;br /&gt;
union   all&lt;br /&gt;
select  bytes&lt;br /&gt;
from    v$log&lt;br /&gt;
)&lt;br /&gt;
, free_space as&lt;br /&gt;
(&lt;br /&gt;
select sum(bytes) sum_bytes&lt;br /&gt;
from dba_free_space&lt;br /&gt;
)&lt;br /&gt;
select vd.name                                                                                            dbname&lt;br /&gt;
,      round(sum(used_space.bytes)/1024/1024/1024 ) || &amp;#039; GB&amp;#039;                                              dbsize&lt;br /&gt;
,      round(sum(used_space.bytes)/1024/1024/1024 ) - round(free_space.sum_bytes/1024/1024/1024) || &amp;#039; GB&amp;#039; dbused&lt;br /&gt;
,      round(free_space.sum_bytes/1024/1024/1024) || &amp;#039; GB&amp;#039;                                                dbfree&lt;br /&gt;
from   free_space&lt;br /&gt;
,      used_space&lt;br /&gt;
,      v$database vd&lt;br /&gt;
group  by vd.name&lt;br /&gt;
,      free_space.sum_bytes&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===How big are the tablespaces?===&lt;br /&gt;
Report the database size in terms of tablespace&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set pages 100 lines 200&lt;br /&gt;
select df.tablespace_name                                                    &amp;quot;Tablespace&amp;quot;&lt;br /&gt;
,      totalusedspace                                                        &amp;quot;Used MB&amp;quot;&lt;br /&gt;
,      (df.totalspace - tu.totalusedspace)                                   &amp;quot;Free MB&amp;quot;&lt;br /&gt;
,      df.totalspace                                                         &amp;quot;Total MB&amp;quot;&lt;br /&gt;
,      round( 100 * ( (df.totalspace - tu.totalusedspace) / df.totalspace) ) &amp;quot;Pct. Free&amp;quot;&lt;br /&gt;
from   (&lt;br /&gt;
       select tablespace_name&lt;br /&gt;
       ,      round(sum(bytes) / 1048576) totalspace&lt;br /&gt;
       from   dba_data_files&lt;br /&gt;
       group  by tablespace_name&lt;br /&gt;
       ) df&lt;br /&gt;
,      (&lt;br /&gt;
       select round(sum(bytes)/(1024*1024)) totalusedspace&lt;br /&gt;
       ,      tablespace_name&lt;br /&gt;
       from   dba_segments&lt;br /&gt;
       group  by tablespace_name&lt;br /&gt;
       ) tu&lt;br /&gt;
where  df.tablespace_name  = tu.tablespace_name&lt;br /&gt;
and    df.totalspace      != 0&lt;br /&gt;
order  by 5&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Database Free space report===&lt;br /&gt;
From [http://asktom.oracle.com/pls/asktom/ASKTOM.download_file?p_file=6551402703363001567 asktom]&lt;br /&gt;
&lt;br /&gt;
*Tablespace Name: name of tablespace, leading &amp;#039;*&amp;#039; indicates a good locally managed tablespace, leading blank means it is a bad dictionary managed tablespace. Second character of A implies ASSM managed storage, second character of M implies manually managed (pctused, freelists, etc are used to control space utilization)&lt;br /&gt;
*Mbytes: allocated space of the tablespace, sum of mbytes consumed by all datafiles associated with tablespace.&lt;br /&gt;
*Used: space in the tablespace that is used by some segment.&lt;br /&gt;
*Free: space in the tablespace not allocated to any segment.&lt;br /&gt;
*%Used: ratio of free to allocated space&lt;br /&gt;
*largest: mostly useful with dictionary managed tablespaces, the size of the largest contiguous set of blocks available. If this number in a dictionary managed tablespace is smaller than the next extent for some object, that object could fail with &amp;quot;out of space&amp;quot; even if the FREE column says there is lots of free space.&lt;br /&gt;
*MaxPoss Kbytes: the autoextend max size (note CAN be smaller than the allocated size!!!! you can set the maxsize to be less than the current size of a file)&lt;br /&gt;
*%Max Used: how much of the maximum autoextend size has been used so far &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set linesize 132&lt;br /&gt;
-------------------------------------------------------&lt;br /&gt;
-- This SQL Plus script lists freespace by tablespace&lt;br /&gt;
--------------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
column dummy noprint&lt;br /&gt;
column  pct_used      format 999.9             heading &amp;quot;%|Used&amp;quot; &lt;br /&gt;
column  name          format a19               heading &amp;quot;Tablespace Name&amp;quot; &lt;br /&gt;
column  Mbytes        format 999,999,999       heading &amp;quot;MBytes&amp;quot; &lt;br /&gt;
column  used          format 999,999,999       heading &amp;quot;Used&amp;quot; &lt;br /&gt;
column  free          format 999,999,999       heading &amp;quot;Free&amp;quot; &lt;br /&gt;
column  largest       format 999,999,999       heading &amp;quot;Largest&amp;quot; &lt;br /&gt;
column  max_size      format 9,999,999,999,999 heading &amp;quot;MaxPoss|Mbytes&amp;quot;&lt;br /&gt;
column  pct_max_used  format 999.9             heading &amp;quot;%|Max|Used&amp;quot; &lt;br /&gt;
break   on report&lt;br /&gt;
compute sum of mbytes on report&lt;br /&gt;
compute sum of free on report&lt;br /&gt;
compute sum of used on report&lt;br /&gt;
&lt;br /&gt;
select (select decode(extent_management,&amp;#039;LOCAL&amp;#039;,&amp;#039;*&amp;#039;,&amp;#039; &amp;#039;) ||&lt;br /&gt;
               decode(segment_space_management,&amp;#039;AUTO&amp;#039;,&amp;#039;a &amp;#039;,&amp;#039;m &amp;#039;)&lt;br /&gt;
              from dba_tablespaces where tablespace_name = b.tablespace_name) || nvl(b.tablespace_name,&lt;br /&gt;
                         nvl(a.tablespace_name,&amp;#039;UNKOWN&amp;#039;)) name,&lt;br /&gt;
           mbytes_alloc mbytes,&lt;br /&gt;
           mbytes_alloc-nvl(mbytes_free,0) used,&lt;br /&gt;
           nvl(mbytes_free,0) free,&lt;br /&gt;
           ((mbytes_alloc-nvl(mbytes_free,0))/&lt;br /&gt;
                                                  mbytes_alloc)*100 pct_used,&lt;br /&gt;
           nvl(largest,0) largest,&lt;br /&gt;
           nvl(mbytes_max,mbytes_alloc) Max_Size,&lt;br /&gt;
           decode( mbytes_max, 0, 0, (mbytes_alloc/mbytes_max)*100) pct_max_used&lt;br /&gt;
from ( select sum(bytes)/1024/1024 mbytes_free,&lt;br /&gt;
                          max(bytes)/1024/1024 largest,&lt;br /&gt;
                          tablespace_name&lt;br /&gt;
           from  sys.dba_free_space&lt;br /&gt;
           group by tablespace_name ) a,&lt;br /&gt;
     ( select sum(bytes)/1024/1024 mbytes_alloc,&lt;br /&gt;
                          sum(maxbytes)/1024/1024 mbytes_max,&lt;br /&gt;
                          tablespace_name&lt;br /&gt;
           from sys.dba_data_files&lt;br /&gt;
           group by tablespace_name&lt;br /&gt;
           union all&lt;br /&gt;
      select sum(bytes)/1024/1024 mbytes_alloc,&lt;br /&gt;
                          sum(maxbytes)/1024/1024 mbytes_max,&lt;br /&gt;
                          tablespace_name&lt;br /&gt;
           from sys.dba_temp_files&lt;br /&gt;
           group by tablespace_name )b&lt;br /&gt;
where a.tablespace_name (+) = b.tablespace_name&lt;br /&gt;
order by 8&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Which schemas are taking up all of the space?===&lt;br /&gt;
 set pages 999&lt;br /&gt;
 col &amp;quot;size MB&amp;quot; format 999,999,999&lt;br /&gt;
 col &amp;quot;Objects&amp;quot; format 999,999,999&lt;br /&gt;
 select obj.owner &amp;quot;Owner&amp;quot;&lt;br /&gt;
 ,      obj_cnt &amp;quot;Objects&amp;quot;&lt;br /&gt;
 ,      decode(seg_size, NULL, 0, seg_size) &amp;quot;size MB&amp;quot;&lt;br /&gt;
 from   (select owner, count(*) obj_cnt from dba_objects group by owner) obj&lt;br /&gt;
 ,      (select owner, ceil(sum(bytes)/1024/1024) seg_size&lt;br /&gt;
        from dba_segments group by owner) seg&lt;br /&gt;
 where  obj.owner  = seg.owner(+)&lt;br /&gt;
 order  by 3 desc&lt;br /&gt;
 ,      2 desc&lt;br /&gt;
 ,      1;&lt;br /&gt;
===Show the ten largest objects in the database===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
colowner format a15&lt;br /&gt;
colsegment_name format a30&lt;br /&gt;
colsegment_type format a15&lt;br /&gt;
colmb format 999,999,999&lt;br /&gt;
select owner&lt;br /&gt;
,      segment_name&lt;br /&gt;
,      segment_type&lt;br /&gt;
,      mb&lt;br /&gt;
from   (&lt;br /&gt;
       select owner&lt;br /&gt;
       ,      segment_name&lt;br /&gt;
       ,      segment_type&lt;br /&gt;
       ,      bytes / 1024 / 1024 &amp;quot;MB&amp;quot;&lt;br /&gt;
       from   dba_segments&lt;br /&gt;
       order  by bytes desc&lt;br /&gt;
       )&lt;br /&gt;
where  1=1&lt;br /&gt;
and    rownum &amp;lt; 11;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Is java installed in the database?===&lt;br /&gt;
This will return 9000&amp;#039;ish if it is&lt;br /&gt;
 select count(*)&lt;br /&gt;
 from   all_objects&lt;br /&gt;
 where  1=1&lt;br /&gt;
 and    object_type like &amp;#039;%JAVA%&amp;#039;&lt;br /&gt;
 and    owner = &amp;#039;SYS&amp;#039;;&lt;br /&gt;
===Show character set information===&lt;br /&gt;
 select * from nls_database_parameters;&lt;br /&gt;
===Show all used features===&lt;br /&gt;
 select name&lt;br /&gt;
 ,      detected_usages&lt;br /&gt;
 from   dba_feature_usage_statistics&lt;br /&gt;
 where  1=1&lt;br /&gt;
 and    detected_usages &amp;gt; 0;&lt;br /&gt;
===Move a database from one host to another without RMAN===&lt;br /&gt;
Once upon a time, this was the only way to move a database to a different server. Now it&amp;#039;s not common as RMAN can do it so well.&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;On source server&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
====Get a text version of the controlfile====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter database backup controlfile to trace as &amp;#039;/tmp/&amp;amp;database_name._cf.sql&amp;#039;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Grab a copy of the pfile====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
create pfile=&amp;#039;/tmp/init_&amp;amp;database..ora&amp;#039; from spfile;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Send these 2 files to the destination server====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
scp /tmp/init*ora /tmp/*_cf.sql oracle@${dest_host}:/tmp/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Shutdown the database====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
shu immediate&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Copy the database datafiles to the new host (see in the controlfile creation script where they are)====&lt;br /&gt;
As we are going to reopen the database with resetlogs, no need to copy the redo logs.&amp;lt;br /&amp;gt;&lt;br /&gt;
As a new did will be created, no need to copy the archivelogs. If we need the old database back, we can just restart it on this server.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
scp /cln/exp/ora_data3/cocpit/*dbf oracle@hn512:/cln/exp/ora_data2/cocpit/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;On destination server&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
====Edit the files====&lt;br /&gt;
* Change path names for new filesystem(s)&lt;br /&gt;
* Create any directories that don&amp;#039;t exist (archivelog, audit, ...)&lt;br /&gt;
* Modify the controlfile recreation script&lt;br /&gt;
** Remove Part #1 (use the resetlogs option)&lt;br /&gt;
** Change REUSE to SET&lt;br /&gt;
** Remove the recover database and open statements&lt;br /&gt;
** Comment out the alter tablespace temp statements. Might need it after opening.&lt;br /&gt;
====Add database entry to /etc/oratab====&lt;br /&gt;
====Create or add entry to listener.ora====&lt;br /&gt;
====Create or add entry to tnsnames.ora====&lt;br /&gt;
====Setup environment for database====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
. .oraenv&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Copy init file to where it can be used====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cp /tmp/init${ORACLE_SID}.ora ${ORACLE_HOME}/dbs/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Create the new controlfile====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cd /tmp&lt;br /&gt;
sqlplus / as sysdba&lt;br /&gt;
@&amp;amp;database_name._cf&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Mount the database====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter database mount&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Open the database====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter database open resetlogs&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Check the database====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 2000 pages 100&lt;br /&gt;
col file_name for a80&lt;br /&gt;
select file_name, status, online_status from dba_data_files;&lt;br /&gt;
select file_name, status, online_status from dba_temp_files;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Stuart</name></author>	</entry>

	<entry>
		<id>https://mailnest.com/dbawiki/index.php?title=Unix/Linux&amp;diff=3402</id>
		<title>Unix/Linux</title>
		<link rel="alternate" type="text/html" href="https://mailnest.com/dbawiki/index.php?title=Unix/Linux&amp;diff=3402"/>
				<updated>2018-12-06T00:18:32Z</updated>
		
		<summary type="html">&lt;p&gt;Stuart: /* Use sed to delete the first line of a file or command output printing from the second line onwards */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;* [http://hyperpolyglot.org/unix-shells#var-expansion Good shell comparison including variable expansion - hyperpolyglot.org]&lt;br /&gt;
* [http://pubs.opengroup.org/onlinepubs/9699919799/utilities/toc.html Shell coding standards - opengroup.org]&lt;br /&gt;
* [http://aix4admins.blogspot.be aix4admins]&lt;br /&gt;
* [http://linuxgazette.net/issue55/okopnik.html The Deep, Dark Secrets of Bash]&lt;br /&gt;
* [http://www.speakeasy.org/~arkay/216-7.4KshFunctions.html Korn Shell Functions]&lt;br /&gt;
* [http://www.grymoire.com/Unix/AwkRef.html AWK reference from Bruce Barnett]&lt;br /&gt;
* [http://www.catonmat.net/blog/wp-content/uploads/2008/09/awk1line.txt HANDY AWK ONE-LINERS]&lt;br /&gt;
* [http://www.grymoire.com/unix/Quote.html Unix quoting from from Bruce Barnett (grymoire)]&lt;br /&gt;
* [http://www.mpi-inf.mpg.de/departments/rg1/teaching/unixffb-ss98/quoting-guide.html Another excellent quoting tutorial]&lt;br /&gt;
* [http://aix4admins.blogspot.be/2015/02/snapshot-fs-snapshot-snapshot-is-state.html AIX snapshot technology]&lt;br /&gt;
* [[RaspberryPi]]&lt;br /&gt;
* [[SSH]]&lt;br /&gt;
* [http://www.anattatechnologies.com/q/2013/04/multiuser-screen/ Screen sharing from Unix using screen]&lt;br /&gt;
* [https://robots.thoughtbot.com/a-tmux-crash-course Screen sharing from Unix using tmux]&lt;br /&gt;
* [http://www.csb.yale.edu/userguides/wordprocess/vi-summary.html Handy ex and vi reference]&lt;br /&gt;
* [[Fedora install for my own purposes]]&lt;br /&gt;
&lt;br /&gt;
===How to automatically download and process email attachments from Gmail===&lt;br /&gt;
==== Useful references====&lt;br /&gt;
* [http://www.courier-mta.org/maildrop/maildrop.html maildrop]&lt;br /&gt;
* [http://www.wonkity.com/~wblock/docs/html/maildrop.html Using maildrop As A Mail Delivery Agent (MDA)]&lt;br /&gt;
* [http://manpages.ubuntu.com/manpages/trusty/man7/maildropex.7.html .mailfilter examples]&lt;br /&gt;
* [https://www.axllent.org/docs/view/gmail-pop3-with-fetchmail/ Setting up fetchmail with Gmail]&lt;br /&gt;
* [https://www.linode.com/docs/email/clients/using-fetchmail-to-retrieve-email/ Using Fetchmail to Retrieve Email]&lt;br /&gt;
&lt;br /&gt;
Eventually, after months of trying different things, came up with this combination of tools that worked very well.&lt;br /&gt;
====Install tools====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo dnf -y install fetchmail maildrop uudeview openssl&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Set Gmail account up for POP and disable IMAP&lt;br /&gt;
====Configure fetchmail====&lt;br /&gt;
This is the part that talks to Gmail and downloads the emails to the local machine.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
vi ~/.fetchmailrc&lt;br /&gt;
&lt;br /&gt;
set postmaster &amp;quot;&amp;lt;username&amp;gt;&amp;quot;&lt;br /&gt;
#set daemon 600&lt;br /&gt;
poll pop.gmail.com with proto POP3&lt;br /&gt;
    user &amp;quot;account@gmail.com&amp;quot; there with password &amp;#039;&amp;lt;password&amp;gt;&amp;#039; is &amp;lt;username&amp;gt; here options ssl nokeep&lt;br /&gt;
    mda &amp;quot;/usr/bin/maildrop .mailfilter&amp;quot;&lt;br /&gt;
#    sslcertfile /etc/ssl/certs/ca-bundle.crt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
If fetchmail complains about ssl certificates, try specifying wherein is with the sslcertfile line&lt;br /&gt;
==== Configure maildrop====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
maildirmake maildrop&lt;br /&gt;
maildirmake backup&lt;br /&gt;
&lt;br /&gt;
vi ~/.mailfilter&lt;br /&gt;
&lt;br /&gt;
LOGFILE = &amp;quot;/home/dbahawk/maildrop/maildrop.log&amp;quot;&lt;br /&gt;
DEFAULT=&amp;quot;$HOME/maildrop&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# keep a copy&lt;br /&gt;
cc backup&lt;br /&gt;
`cd backup/new &amp;amp;&amp;amp; rm -f dummy \`ls -t | sed -e 1,50d\``&lt;br /&gt;
&lt;br /&gt;
if (/^To:.*getmail@...\.dnsalias\.org$/)&lt;br /&gt;
   {&lt;br /&gt;
        to Maildir/getmail/&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
#if (/^To:.*dbahawk/)&lt;br /&gt;
#   {&lt;br /&gt;
#        to maildrop&lt;br /&gt;
#   }&lt;br /&gt;
&lt;br /&gt;
if (/^To:.*dbahawk/)&lt;br /&gt;
    dotlock &amp;quot;auto.lock&amp;quot; {&lt;br /&gt;
    to &amp;quot;|uudeview -c -i&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Not really sure why this filter is not working properly. The cc works but the To: check doesn&amp;#039;t. So I have a shell that runs separately to process the emails in the backup mail directory.&lt;br /&gt;
&lt;br /&gt;
====uudeview====&lt;br /&gt;
This is a clever program that can extract attachments from emails and put them in a directory of you choosing.&amp;lt;br /&amp;gt;&lt;br /&gt;
This shell runs from cron at regular intervals to run the whole process&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/usr/bin/ksh&lt;br /&gt;
&lt;br /&gt;
# fetch any new mail from Gmail (uses .fetchmailrc)&lt;br /&gt;
# fetchmail log is $HOME/maildrop/maildrop.log&lt;br /&gt;
fetchmail -d0&lt;br /&gt;
&lt;br /&gt;
# fetchmail uses maildrop as mda (uses .mailfilter) to save messages to a maildir.&lt;br /&gt;
# this is not working correctly but still copies the messages to backup&lt;br /&gt;
&lt;br /&gt;
# pull out the attachments and send them to the incoming directory for the collector to process when it wakes up&lt;br /&gt;
uudeview -c -i -p ~/Downloads/dbahawk_forward backup/new/*&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Use sed to repeat characters===&lt;br /&gt;
echo an &amp;#039;=&amp;#039; sign then use the loop feature of sed to run round a loop a further 79 times replacing what you&amp;#039;ve got with the same thing plus and extra one!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
echo &amp;quot;=&amp;quot; | sed -e :a -e &amp;#039;s/^=\{1,79\}$/&amp;amp;=/;ta&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Convert between lower and upper case using ansi standard===&lt;br /&gt;
This way should be portable and give predictable results&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
LOWER_SID=$(echo &amp;quot;${SID}&amp;quot; | tr &amp;#039;[:upper:]&amp;#039; &amp;#039;[:lower:]&amp;#039;)&lt;br /&gt;
UPPER_SID=$(echo &amp;quot;${SID}&amp;quot; | tr &amp;#039;[:lower:]&amp;#039; &amp;#039;[:upper:]&amp;#039;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Use sed to delete the first line of a file or command output printing from the second line onwards===&lt;br /&gt;
Actually deceptively simple. Example remove the header from df output.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
df -k | sed 1d&lt;br /&gt;
&lt;br /&gt;
or more formally&lt;br /&gt;
&lt;br /&gt;
df -k | sed -e &amp;#039;1,1d&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
As a useful extension, suppose TO_DATA_DIR contains multiple directories, this will total the free space for all relevant filesystems&amp;lt;br /&amp;gt;&lt;br /&gt;
This one is specific to AIX, for other Unixes and Linux, use $4 instead of $3.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SPACE_AVAILABLE=$(df -k $TO_DATA_DIR | sed 1d | awk &amp;#039;BEGIN {i=0} {i=i+$3} END {print i}&amp;#039;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Use sed to munge a controlfile into submission!===&lt;br /&gt;
* delete comment lines&lt;br /&gt;
* delete all lines after the one starting with a semicolon&lt;br /&gt;
* delete all blank lines&lt;br /&gt;
* change reuse to set&lt;br /&gt;
* change archivelog (with word boundaries) to noarchivelog&lt;br /&gt;
* change old sid to new sid&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sqlplus -s / as sysdba&amp;lt;&amp;lt;&amp;#039;EOSQL&amp;#039; &amp;gt;/dev/null&lt;br /&gt;
alter database backup controlfile to trace as &amp;#039;/tmp/regenerate_controlfile.sql&amp;#039; reuse resetlogs;&lt;br /&gt;
EOSQL&lt;br /&gt;
OLDSID=&amp;#039;PROD&amp;#039;&lt;br /&gt;
NEWSID=&amp;#039;TEST&amp;#039;&lt;br /&gt;
sed  -e &amp;#039;/^--/d&amp;#039; -e &amp;#039;/^\;/q&amp;#039; -e &amp;#039;/^ *$/d&amp;#039; -e &amp;#039;s/REUSE/SET/&amp;#039; -e &amp;#039;s/\&amp;lt;ARCHIVELOG\&amp;gt;/NOARCHIVELOG/&amp;#039; -e &amp;#039;s/\&amp;quot;&amp;#039;${OLDSID}&amp;#039;\&amp;quot;/\&amp;quot;&amp;#039;${NEWSID}&amp;#039;\&amp;quot;/&amp;#039; /tmp/regenerate_controlfile.sql&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Find all files where a certain text does not exist===&lt;br /&gt;
Mostly we want to search for files containing a particular string but how to find those files that do not contain some text.&amp;lt;br /&amp;gt;&lt;br /&gt;
Using xargs instead of -exec forces the filename to be printed. -H should do this but doesn&amp;#039;t seem to in this case.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
find . -name &amp;quot;*cfg&amp;quot; | xargs grep -H -c TO_CV_HOST {} \; | grep &amp;#039;:0$&amp;#039; | cut -d: -f1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Use tar and gzip to copy files more efficiently across network between hosts===&lt;br /&gt;
From the destination server, this will connect to the source, tar up each file and pull it back to the current server&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ssh oracle@hn5211 &amp;quot;cd /oracle/ora_data4/iten3/ &amp;amp;&amp;amp; tar -cf - . | gzip &amp;quot; | ( cd /oracle/ora_data2/iten/ &amp;amp;&amp;amp; gunzip -c | tar -xvf - . )&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===double hash and double percent in shell variables to trim off characters from variables===&lt;br /&gt;
&amp;lt;nowiki&amp;gt;#&amp;lt;/nowiki&amp;gt;  - trims everything from the start of line till the FIRST occurrence of following character (abstemious) :-)&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;nowiki&amp;gt;##&amp;lt;/nowiki&amp;gt; - trims everything from the start of line till the LAST occurrence of following character (greedy)&amp;lt;br /&amp;gt;&lt;br /&gt;
%  - trims everything from the end of line backwards till the FIRST occurrence of following character (abstemious)&amp;lt;br /&amp;gt;&lt;br /&gt;
%% - trims everything from the end of line backwards till the LAST occurrence of following character (greedy)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
FILENAME=&amp;quot;/home/bey9at77/hello.txt&amp;quot;&lt;br /&gt;
FILE_STUB1=${FILENAME##*/}&lt;br /&gt;
FILE_STUB=${FILE_STUB1%.*}&lt;br /&gt;
echo $FILE_STUB&lt;br /&gt;
hello&lt;br /&gt;
FILE_EXT=${FILENAME##*.}&lt;br /&gt;
echo $FILE_EXT&lt;br /&gt;
txt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;nowiki&amp;gt;#&amp;lt;/nowiki&amp;gt; - remove prefix reluctantly&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;nowiki&amp;gt;##&amp;lt;/nowiki&amp;gt; - remove prefix greedily&amp;lt;br /&amp;gt;&lt;br /&gt;
% - remove suffix reluctantly&amp;lt;br /&amp;gt;&lt;br /&gt;
%% - remove suffix greedily&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
words=&amp;quot;do.re.mi&amp;quot;&lt;br /&gt;
&lt;br /&gt;
echo ${words#*.}&lt;br /&gt;
&lt;br /&gt;
echo ${words##*.}&lt;br /&gt;
&lt;br /&gt;
echo ${words%.*}&lt;br /&gt;
&lt;br /&gt;
echo ${words%%.*}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===The best shell script ever. An example of how scripting should be done===&lt;br /&gt;
It was written by someone at Oracle. Unfortunately (s)he did not put any author comment in it. Also unfortunately I cannot show it here as it is protected behind Oracles support website.&amp;lt;br /&amp;gt;&lt;br /&gt;
If you have an Oracle Metalink id, you can get the complete script [https://support.oracle.com/epmos/faces/DocumentDisplay?id=949322.1 here]&amp;lt;br /&amp;gt;&lt;br /&gt;
Here is a snippet of a function that demonstrates proper commenting and a very good style.&amp;lt;br &amp;gt;&lt;br /&gt;
The script is called physru.sh and upgrades an Oracle database in a rolling upgrade fashion by using a physical standby.&amp;lt;br /&amp;gt;&lt;br /&gt;
There are 4500 lines in the full script but it is so easy to read and understand because of the way it&amp;#039;s written, it&amp;#039;s like a breath of fresh air. Well done whoever you are!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
###############################################################################&lt;br /&gt;
# NAME:        wait_mrp_active&lt;br /&gt;
#&lt;br /&gt;
# DESCRIPTION: &lt;br /&gt;
#   Wait for $MRP_START_TIMEOUT minutes to confirm that the MRP is active.  If&lt;br /&gt;
#   we can&amp;#039;t detect an active MRP, abort the script with an error.&lt;br /&gt;
#&lt;br /&gt;
# INPUT(S):&lt;br /&gt;
#   Arguments:&lt;br /&gt;
#     $1: database user&lt;br /&gt;
#     $2: user password&lt;br /&gt;
#     $3: tns service name&lt;br /&gt;
#     $4: database unique name&lt;br /&gt;
#&lt;br /&gt;
#   Globals:&lt;br /&gt;
#     None&lt;br /&gt;
#&lt;br /&gt;
# RETURN:&lt;br /&gt;
#   None&lt;br /&gt;
#&lt;br /&gt;
###############################################################################&lt;br /&gt;
wait_mrp_active()&lt;br /&gt;
{&lt;br /&gt;
  display &amp;quot;confirming media recovery is running&amp;quot;&lt;br /&gt;
  l_wma_status=1&lt;br /&gt;
  l_wma_curtime=`perl -e &amp;#039;print int(time)&amp;#039;`&lt;br /&gt;
  l_wma_exptime=`expr $MRP_START_TIMEOUT &amp;quot;*&amp;quot; 60`&lt;br /&gt;
  l_wma_maxtime=`expr $l_wma_curtime + $l_wma_exptime`&lt;br /&gt;
  while [ &amp;quot;$l_wma_curtime&amp;quot; -lt &amp;quot;$l_wma_maxtime&amp;quot; ]&lt;br /&gt;
  do&lt;br /&gt;
    is_mrp_running $1 $2 $3 $4&lt;br /&gt;
    if [ &amp;quot;$?&amp;quot; -gt &amp;quot;0&amp;quot; ]; then&lt;br /&gt;
      l_wma_status=0&lt;br /&gt;
      break&lt;br /&gt;
    fi&lt;br /&gt;
&lt;br /&gt;
    sleep $MRP_START_INTERVAL&lt;br /&gt;
    l_wma_curtime=`perl -e &amp;#039;print int(time)&amp;#039;`&lt;br /&gt;
  done&lt;br /&gt;
  chkerr $l_wma_status &amp;quot;could not detect an active MRP after $MRP_START_TIMEOUT minutes&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===split variable (eg. filename) into separate variables using set===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
FILENAME=&amp;quot;split_this_into_bits&amp;quot;&lt;br /&gt;
set $(echo ${FILENAME} | sed &amp;#039;s/_/ /g&amp;#039;)&lt;br /&gt;
echo $4 $3 $2 $1&lt;br /&gt;
bits into this split&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Centre align text on a line in bash shell===&lt;br /&gt;
Doesn&amp;#039;t work in Korn shell due to %*s&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#COLUMNS=$(tput cols)   # width of the current window&lt;br /&gt;
COLUMNS=80&lt;br /&gt;
title=&amp;quot;Hello world!&amp;quot;&lt;br /&gt;
printf &amp;quot;%*s\n&amp;quot; $(((${#title}+$COLUMNS)/2)) &amp;quot;$title&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
and as a one-liner&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
printf &amp;quot;%*s\n&amp;quot; $(( ( $(echo $* | wc -c ) + 80 ) / 2 )) &amp;quot;$*&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This works in Korn shell...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
TITLE=&amp;quot;$1&amp;quot;&lt;br /&gt;
LINEWIDTH=80&lt;br /&gt;
&lt;br /&gt;
LPAD=$(((${#TITLE}+$LINEWIDTH)/2))&lt;br /&gt;
printf %${LPAD}s &amp;quot;$TITLE&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Right justify text (or repeat characters) on a line with leader dots!===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
function rpadwait {&lt;br /&gt;
    text=$1&lt;br /&gt;
# -------------------------&lt;br /&gt;
# suppress newline for echo&lt;br /&gt;
# -------------------------&lt;br /&gt;
N=&lt;br /&gt;
C=&lt;br /&gt;
if echo &amp;quot;\c&amp;quot; | grep c &amp;gt;/dev/null 2&amp;gt;&amp;amp;1; then&lt;br /&gt;
    N=&amp;#039;-n&amp;#039;&lt;br /&gt;
else&lt;br /&gt;
    C=&amp;#039;\c&amp;#039;&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
    echo ${N} &amp;quot;${text}${C}&amp;quot; | sed -e :a -e &amp;#039;s/^.\{1,80\}$/&amp;amp;\./;ta&amp;#039;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===cron jobs not submitted - daemon run out of child processes?===&lt;br /&gt;
Sometimes have problems with NFS mounts and this causes cron jobs to hang. If they are scheduled to run regularly, eventually cron will no longer be able to start any more jobs.&amp;lt;br /&amp;gt;&lt;br /&gt;
* Check the cron log &amp;#039;&amp;#039;&amp;#039;/var/adm/cron/log&amp;#039;&amp;#039;&amp;#039; to see if there are any errors or other messages around the time the jobs should run.&lt;br /&gt;
If cron has hit its process limit (default 100), it will try again after a number of seconds (default 60).&amp;lt;br /&amp;gt;&lt;br /&gt;
Both the number of jobs and wait time are configured in the file &amp;#039;&amp;#039;&amp;#039;/var/adm/cron/queuedefs&amp;#039;&amp;#039;&amp;#039;. If it is unusual for cron to be running so many jobs, you can check the process table to view the jobs cron has created. These jobs will have parent process id (PPID) of the cron daemon.&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ ps -ef | grep cron | grep -v grep&lt;br /&gt;
    root  6750314        1   0   Apr 24      -  3:39 /usr/sbin/cron&lt;br /&gt;
solax025:root[/home/root]# ps -T 6750314&lt;br /&gt;
      PID    TTY  TIME CMD&lt;br /&gt;
  6750314      -  3:39 cron&lt;br /&gt;
 21168296      -  0:00     \--bsh&lt;br /&gt;
 58982414      -  0:00         \--sadc&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
In this example, we only have 1 job running&lt;br /&gt;
&lt;br /&gt;
===Find long-running processes with a cron job===&lt;br /&gt;
Processes running longer than 24 hours have a date instead of a start time...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
58 08,14 * * * /home/ibmtools/scripts/oracle/dosh -vc &amp;quot;ps -ef|grep &amp;#039;ibmtools/scripts/oracle&amp;#039;|perl -nae &amp;#039;print if \$F[4] !~/:/&amp;#039;&amp;quot; &amp;gt;/tmp/lrp.txt; [[ $(grep -c ibmtools /tmp/lrp.txt) -ne 0 ]] &amp;amp;&amp;amp; cat /tmp/lrp.txt|mailx -s &amp;#039;*** long running processes - please check ***&amp;#039; reporting@companymail.com&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Process command line arguments in shell===&lt;br /&gt;
Borrowed from Mozilla Firefox installer&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
## Command line arg defaults&lt;br /&gt;
##&lt;br /&gt;
moz_debug=0&lt;br /&gt;
moz_debugger=&amp;quot;&amp;quot;&lt;br /&gt;
moz_debugger_args=&amp;quot;&amp;quot;&lt;br /&gt;
#&lt;br /&gt;
##&lt;br /&gt;
## Parse the command line&lt;br /&gt;
##&lt;br /&gt;
while [ $# -gt 0 ]&lt;br /&gt;
do&lt;br /&gt;
  case $1 in&lt;br /&gt;
    -g | --debug)&lt;br /&gt;
      moz_debug=1&lt;br /&gt;
      shift&lt;br /&gt;
      ;;&lt;br /&gt;
    -d | --debugger)&lt;br /&gt;
      moz_debugger=$2;&lt;br /&gt;
      if [ &amp;quot;${moz_debugger}&amp;quot; != &amp;quot;&amp;quot; ]; then&lt;br /&gt;
	shift 2&lt;br /&gt;
      else&lt;br /&gt;
        echo &amp;quot;-d requires an argument&amp;quot;&lt;br /&gt;
        exit 1&lt;br /&gt;
      fi&lt;br /&gt;
      ;;&lt;br /&gt;
    -a | --debugger-args)&lt;br /&gt;
      moz_debugger_args=$2;&lt;br /&gt;
      if [ &amp;quot;${moz_debugger_args}&amp;quot; != &amp;quot;&amp;quot; ]; then&lt;br /&gt;
	shift 2&lt;br /&gt;
      else&lt;br /&gt;
        echo &amp;quot;-a requires an argument&amp;quot;&lt;br /&gt;
        exit 1&lt;br /&gt;
      fi&lt;br /&gt;
      ;;&lt;br /&gt;
    *)&lt;br /&gt;
      break;&lt;br /&gt;
      ;;&lt;br /&gt;
  esac&lt;br /&gt;
done&lt;br /&gt;
#&lt;br /&gt;
##&lt;br /&gt;
## Program name given in $1&lt;br /&gt;
##&lt;br /&gt;
if [ $# -gt 0 ]&lt;br /&gt;
then&lt;br /&gt;
	MOZ_PROGRAM=$1&lt;br /&gt;
	shift&lt;br /&gt;
fi&lt;br /&gt;
##&lt;br /&gt;
## Program not given, try to guess a default&lt;br /&gt;
##&lt;br /&gt;
if [ -z &amp;quot;$MOZ_PROGRAM&amp;quot; ]&lt;br /&gt;
then&lt;br /&gt;
	##&lt;br /&gt;
	## Try this script&amp;#039;s name with &amp;#039;-bin&amp;#039; appended&lt;br /&gt;
	##&lt;br /&gt;
	if [ -x &amp;quot;$MOZ_DEFAULT_NAME&amp;quot; ]&lt;br /&gt;
	then&lt;br /&gt;
		MOZ_PROGRAM=$MOZ_DEFAULT_NAME&lt;br /&gt;
	##&lt;br /&gt;
	## Try mozilla-bin&lt;br /&gt;
	## &lt;br /&gt;
	elif [ -x &amp;quot;$MOZ_APPRUNNER_NAME&amp;quot; ]&lt;br /&gt;
	then&lt;br /&gt;
		MOZ_PROGRAM=$MOZ_APPRUNNER_NAME&lt;br /&gt;
	fi&lt;br /&gt;
fi&lt;br /&gt;
#&lt;br /&gt;
#&lt;br /&gt;
##&lt;br /&gt;
## Make sure the program is executable&lt;br /&gt;
##&lt;br /&gt;
if [ ! -x &amp;quot;$MOZ_PROGRAM&amp;quot; ]&lt;br /&gt;
then&lt;br /&gt;
	moz_bail &amp;quot;Cannot execute $MOZ_PROGRAM.&amp;quot;&lt;br /&gt;
fi&lt;br /&gt;
#&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Carry XWindows settings across sessions===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# ----------------------&lt;br /&gt;
# push XWindows settings&lt;br /&gt;
# ----------------------&lt;br /&gt;
[[ &amp;quot;$(uname)&amp;quot; == &amp;quot;SunOS&amp;quot; ]] &amp;amp;&amp;amp; PATH=/usr/openwin/bin:$PATH&lt;br /&gt;
WHOAMI=$(id | awk -F&amp;#039;)&amp;#039; &amp;#039;{print $1}&amp;#039; | awk -F&amp;#039;(&amp;#039; &amp;#039;{print $2}&amp;#039;)&lt;br /&gt;
xauth list &amp;gt; /tmp/xauth_list_$WHOAMI&lt;br /&gt;
chmod 777 /tmp/xauth_list_$WHOAMI&lt;br /&gt;
&lt;br /&gt;
echo $DISPLAY &amp;gt; /tmp/xdisplay_$WHOAMI&lt;br /&gt;
chmod 777 /tmp/xdisplay_$WHOAMI&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Cross-platform version of whoami===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
WHOAMI=$(id | awk -F&amp;#039;)&amp;#039; &amp;#039;{print $1}&amp;#039; | awk -F&amp;#039;(&amp;#039; &amp;#039;{print $2}&amp;#039;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Set terminal title from command line===&lt;br /&gt;
Put something like this in the .profile&amp;lt;br /&amp;gt;&lt;br /&gt;
-n     do not output the trailing newline&amp;lt;br /&amp;gt;&lt;br /&gt;
-e     enable interpretation of backslash escapes&amp;lt;br /&amp;gt;&lt;br /&gt;
|0     sets title of window and icon&amp;lt;br /&amp;gt;&lt;br /&gt;
|1     sets title of icon only&amp;lt;br /&amp;gt;&lt;br /&gt;
|2     sets title of window only&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
echo -en &amp;quot;\033]0;`hostname`\007&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
echo -en &amp;quot;\033]2;`hostname`\007&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Remove blank lines and comments (also indented ones) from a file===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
awk -F\: &amp;#039;!/^($|[:space:]*#)/ {print $2}&amp;#039; /etc/oratab | sort | uniq&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or as part of a script that removes comments and blank lines from all Korn shell scripts in a directory&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/usr/bin/ksh&lt;br /&gt;
for i in $(ls *ksh); do&lt;br /&gt;
    perl -p -i -e &amp;#039;s/^\s*#[^!]*$//; s/^\s*$//&amp;#039; $i&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Return elements of an array in Korn shell===&lt;br /&gt;
From [http://unix.stackexchange.com/questions/188202/processing-output-from-an-sqlite-db-into-a-ksh-array-with-spaces here]&amp;lt;br /&amp;gt;&lt;br /&gt;
Could be used to separate the columns of an SQL select when returning to the shell&amp;lt;br /&amp;gt;&lt;br /&gt;
This approach eliminates the need to put quotes around text with spaces in it.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
echo $KSH_VERSION&lt;br /&gt;
x=&amp;quot;Red,Yellow is a color,Blue&amp;quot;&lt;br /&gt;
oIFS=$IFS&lt;br /&gt;
IFS=,&lt;br /&gt;
y=($x)&lt;br /&gt;
IFS=$oIFS&lt;br /&gt;
echo ${y[1]}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===A decent Unix Prompt===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
export PS1=&amp;quot;`uname -n`:`whoami`[\${PWD}]# &amp;quot;&lt;br /&gt;
or&lt;br /&gt;
export PS1=&amp;#039;($?) $&amp;#039;ORACLE_SID&amp;quot; &amp;quot;`whoami`&amp;quot;@&amp;quot;`uname -n`&amp;quot;:&amp;quot;&amp;#039;$&amp;#039;PWD&amp;quot;&amp;gt; &amp;quot;&lt;br /&gt;
export EDITOR=vi&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Simple arithmetic===&lt;br /&gt;
pipe the calculation into the shell calculator&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
space_in_kb=$(echo $1 / 1024 | bc)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Calculate the remainder (modulo) of a division calculation&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
if [[ $(echo &amp;quot;${NUMBER} % 2&amp;quot; | bc) -eq 0 ]]; then&lt;br /&gt;
    echo &amp;quot;${NUMBER} is even&amp;quot;&lt;br /&gt;
else&lt;br /&gt;
    echo &amp;quot;${NUMBER} is odd&amp;quot;&lt;br /&gt;
fi&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or do it in awk if scientific notation maybe involved&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
function calc { awk &amp;quot;BEGIN{print $*}&amp;quot;; }&lt;br /&gt;
&lt;br /&gt;
if [[ $(calc &amp;quot;${SPACE_USED} + ${SPACE_AVAILABLE} - ${DATABASE_SIZE&amp;quot;) -le 0 ]]; then&lt;br /&gt;
    echo &amp;quot;NOK&amp;quot;&lt;br /&gt;
fi&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Script encryption and passphrase protection===&lt;br /&gt;
Encrypt a shell script with the ability to execute the encrypted version&lt;br /&gt;
* from [http://www.commandlinefu.com/commands/browse commandlinefu.com]&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
scrypt(){ [ -n &amp;quot;$1&amp;quot; ]&amp;amp;&amp;amp;{ echo &amp;#039;. &amp;lt;(echo &amp;quot;$(tail -n+2 $0|base64 -d|mcrypt -dq)&amp;quot;); exit;&amp;#039;&amp;gt;$1.scrypt;cat $1|mcrypt|base64 &amp;gt;&amp;gt;$1.scrypt;chmod +x $1.scrypt;};}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Virtual host configuration in Apache http.conf===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;VirtualHost *:80&amp;gt;&lt;br /&gt;
        ServerName dbamon&lt;br /&gt;
        DocumentRoot &amp;quot;/Volumes/data/Sites/dbamon_push&amp;quot;&lt;br /&gt;
        &amp;lt;Directory &amp;quot;/Volumes/data/Sites/dbamon_push&amp;quot;&amp;gt;&lt;br /&gt;
                Options Includes FollowSymLinks&lt;br /&gt;
                AllowOverride All&lt;br /&gt;
                Order allow,deny&lt;br /&gt;
                Allow from all&lt;br /&gt;
        &amp;lt;/Directory&amp;gt;&lt;br /&gt;
&amp;lt;/VirtualHost&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
and in /etc/hosts, add...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
127.0.0.1  dbamon&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Mount a website (or any other remote resource) locally using WebDav===&lt;br /&gt;
Redhat/CentOS&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
yum install fuse-davfs2&lt;br /&gt;
or&lt;br /&gt;
yum install wdfs.x86_64&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Debian&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
apt-get install davfs2&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
then...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo mkdir /mnt/webdav  # or whatever you&amp;#039;d like to call the directory&lt;br /&gt;
sudo mount.davfs [-o option[,option]...] device mount_point&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
In man&amp;#039;s terms, that last line would translate to:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
id  #suppose this returns uid=501 and gid=502&lt;br /&gt;
sudo mount.davfs -o 501,502 https://your/web/site /mnt/webdav&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Mac OSX&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
osascript -e &amp;#039; mount volume &amp;quot;http://username:password@webdav.address:portnum&amp;quot; &amp;#039;&lt;br /&gt;
or&lt;br /&gt;
osascript -e &amp;#039; mount volume &amp;quot;http://username@webdav.address:portnum&amp;quot; &amp;#039;&lt;br /&gt;
or&lt;br /&gt;
osascript -e &amp;#039; try mount volume &amp;quot;http://webdav.address:portnum&amp;quot; &amp;#039;&lt;br /&gt;
or&lt;br /&gt;
mount -t webdav http://webdav.address:portnum /mnt/webdav  # this one won&amp;#039;t show up in the Finder Sidebar.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Add current hostname to list of hosts on an xcat server===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
CMD=&amp;quot;nodels&amp;quot;&lt;br /&gt;
HOST=`hostname`&lt;br /&gt;
(echo &amp;quot;$HOST&amp;quot;; $CMD) | while read server&lt;br /&gt;
do&lt;br /&gt;
    echo &amp;quot;server:$server&amp;quot;&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===What is todays &amp;#039;Day Of the Year&amp;#039; number?===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
DOY=`perl -e &amp;#039;print sub{$_[7]}-&amp;gt;(localtime)+1;&amp;#039;`&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Convert Julian day numbers to dates===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
for day in 8 33 36 61 64 91 96 121 126 152 155 182 187 215 218 244 247 274 279 306 309 335 338 365; do date -d &amp;quot;`date +%Y`-01-01 +$(( ${day} - 1 ))days&amp;quot; +%d-%m-%Y; done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Send crontab job output to a date formatted log file===&lt;br /&gt;
This will run a job every 5 minutes and send the output to a file ending with a time in hours and minutes.&amp;lt;br /&amp;gt;&lt;br /&gt;
The thing to note is the escaped percent signs. This is because a % sign is interpreted by cron to mean a newline character. Everything after the first % is treated as input to the program.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
*/5 *  * * * /var/www/cgi-bin/dbamon_collector.ksh       &amp;gt;/tmp/dbamon_collector.log.$(date &amp;quot;+\%H\%M&amp;quot;) 2&amp;gt;&amp;amp;1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Edit crontab file without crontab -e===&lt;br /&gt;
It can happen that you need to add or modify a line in the crontab of many users or across many servers at once.&amp;lt;br /&amp;gt;&lt;br /&gt;
In principle, there&amp;#039;s nothing wrong with modifying the crontab file directly. You just lose the advantages of file locking (and syntax checking) that crontab -e offers.&amp;lt;br /&amp;gt;&lt;br /&gt;
Here we take a backup of the current crontab, print it out, echo an extra command and ask cron to use these as input (thus overwriting the existing crontab file). Just don&amp;#039;t run this close to midnight :-)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
crontab -l &amp;gt; /tmp/crontab.`date &amp;#039;+%Y%m%d&amp;#039;`&lt;br /&gt;
(&lt;br /&gt;
cat /tmp/crontab.`date +&amp;#039;%Y%m%d&amp;#039;`&lt;br /&gt;
echo &amp;quot;02 10 * * * /home/ibmtools/scripts/oracle/export_parfile.ksh -s SID -f JDBEOP1.parfile&amp;quot;&lt;br /&gt;
) | crontab -&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
crontab -l &amp;gt; /tmp/crontab.backup&lt;br /&gt;
crontab -l &amp;gt; /tmp/crontab.$$&lt;br /&gt;
perl -p -i -e &amp;#039;s!backup_send_tsm_dump!backup_export2tsm!g&amp;#039; /tmp/crontab.$$&lt;br /&gt;
crontab /tmp/crontab.$$&lt;br /&gt;
rm /tmp/crontab.$$&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
crontab -l &amp;gt;$HOME/crontab.$(date &amp;#039;+%Y%m%d&amp;#039;)&lt;br /&gt;
crontab -l | perl -p -e &amp;#039;s|/nas/software/oracle/scripts|/oracle/scripts|&amp;#039; | crontab&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Use shell to convert a number in scientific notation to normal===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
var2convert=&amp;#039;1.2345678e3&amp;#039;&lt;br /&gt;
printf -v var2convert &amp;quot;%.f&amp;quot; $var2convert&lt;br /&gt;
echo $var2convert  # magic!&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Check for jobs running longer that 24 hours===&lt;br /&gt;
Run from the management server across all Unix servers. Checks the 5th column in a ps listing. If it doesn&amp;#039;t find a : (time separator), the process is running longer than 24 hours.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# ---------------------------------------&lt;br /&gt;
# report on long running oraibm processes&lt;br /&gt;
# ---------------------------------------&lt;br /&gt;
01 17,14 * * * rm -f /tmp/lrp.txt;/home/ibmtools/scripts/oracle/dosh -vc \&amp;quot;ps -ef|egrep &amp;#039;oraibm|scripts/oracle&amp;#039;&amp;gt;/tmp/lrp.txt;perl -nae &amp;#039;print if \$F[4] !~/:/&amp;#039; /tmp/lrp.txt\&amp;quot; &amp;gt;&amp;gt;/tmp/lrp.txt;[[ $(egrep -c &amp;#039;oraibm|scripts/or&lt;br /&gt;
acle&amp;#039; /tmp/lrp.txt) -ne 0 ]] &amp;amp;&amp;amp; cat /tmp/lrp.txt|mailx -s &amp;#039;*** long running processes - please check ***&amp;#039; bey9at77@mail.com&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Global find and replace with perl (restricted to list of files provided by Unix find command)===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
find . -type f -exec perl -i -pe &amp;#039;s/something/else/g&amp;#039; {} \;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===perl function to make filenames lower case===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
function lower { &lt;br /&gt;
   perl -e &amp;#039;for (@ARGV) { rename $_, lc($_) unless -e lc($_); }&amp;#039; * &lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===From the management server, search the TNS listener port for each database on a server and make an inline substitution in the ITM config files!===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
for i in `/home/ibmtools/scripts/oracle/dosh -c &amp;quot;ls -al /opt/IBM/ITM/config/*rz*cfg|grep -v lrwx&amp;quot;|awk &amp;#039;{print $NF}&amp;#039;`; do&lt;br /&gt;
    server=`echo $i|cut -d_ -f1 | awk -F&amp;#039;/&amp;#039; &amp;#039;{print $NF}&amp;#039;`&lt;br /&gt;
    db=`echo $i|cut -d&amp;#039;.&amp;#039; -f1 | awk -F&amp;#039;_&amp;#039; &amp;#039;{print $NF}&amp;#039;`&lt;br /&gt;
    OH=`ssh $server grep &amp;quot;^$db&amp;quot; /etc/oratab|cut -d: -f2`&lt;br /&gt;
    LISTENERPORT=`ssh $server cat $OH/network/admin/listener.ora|perl -00 -ne &amp;#039;print $1 if /&amp;#039;$db&amp;#039;.*PORT.*=.*(\d{4})/s&amp;#039;`&lt;br /&gt;
    ssh $server perl -p -i.bak -e &amp;#039;s/1521/&amp;#039;$LISTENERPORT&amp;#039;/&amp;#039; $i&lt;br /&gt;
    ssh $server ls -al ${i}*&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Run a job from cron every Nth day of the month===&lt;br /&gt;
Example. Execute a job every third Saturday of the month.&amp;lt;br /&amp;gt;&lt;br /&gt;
Paste this into a file called calenday and put it in /usr/local/bin so it&amp;#039;s (probably) on the PATH&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/usr/bin/ksh&lt;br /&gt;
&lt;br /&gt;
# ix is the week number of the month (&amp;quot;2&amp;quot;nd Friday of the month, &amp;quot;3&amp;quot;rd Tuesday of the month)&lt;br /&gt;
# dy is the day number in Unix format (0 for Sunday, 1 for Monday, ... 6 for Saturday)&lt;br /&gt;
# eg. &amp;quot;calenday 3 6&amp;quot; returns the date of 3rd Saturday of the month.&lt;br /&gt;
&lt;br /&gt;
ix=$1&lt;br /&gt;
dy=$2&lt;br /&gt;
SCHAR=$((($dy*2)+$dy+1))&lt;br /&gt;
ECHAR=$(($SCHAR+1))&lt;br /&gt;
cal `date &amp;#039;+%m %Y&amp;#039;` | egrep &amp;quot;\&amp;lt;[0-9]{1,2}\&amp;gt;&amp;quot; | cut -c${SCHAR}-${ECHAR} | xargs | awk {&amp;#039;print $&amp;#039;$ix&amp;#039;}&amp;#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Now in crontab, you should be able to do something like this:&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
15 20 * * * [[ `calenday 3 6` -eq `/bin/date &amp;#039;+%d&amp;#039;` ]] &amp;amp;&amp;amp; su - oracle -c &amp;quot;run_my_backup.ksh&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will also work on some Unices..&amp;lt;br /&amp;gt;&lt;br /&gt;
We send backups to a special TSM node on the second Friday of each month. This report must run a day later - but that is not guaranteed to be the second Saturday or even the 3rd. So...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
30 12 8-14 * 5 sleep 86400 &amp;amp;&amp;amp; su - oracle -c &amp;quot;/usr/bin/perl -ne &amp;#039;print if /ORX_M_SOL/ .. /^STOP/&amp;#039; /home/oracle/incoming/dbamon_spool_tsm_*.SOL | grep Archive | grep -v Client | mailx -s &amp;#039;Monthly TSM backups&amp;#039; orareport@xxxxxx.com&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ps listing does not show start time after 24 hours===&lt;br /&gt;
But you can see elapsed time using your own ps command&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/usr/bin/ps -eo etime,user,pid,ppid,cpu,start,tty,time,args|tail -n +2|sort&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ps -ef cuts off args cmd column on Solaris===&lt;br /&gt;
====To see more than 80 characters of the last column on Solaris====&lt;br /&gt;
This shows all the individual arguments to the command&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
pargs &amp;lt;pid&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This shows the ps listing in &amp;#039;compatibility&amp;#039; mode (there are more compatibility commands in /usr/xpg4/bin)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/usr/ucb/ps auww&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====To see more than 80 characters of the last column on AIX====&lt;br /&gt;
This shows the full argument listing of a process (NOTE: no minus sign!)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ps eww &amp;lt;pid&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Remove blank / empty lines from vi ===&lt;br /&gt;
Maybe you cut and pasted a file from Windows and it&amp;#039;s full of blank lines and Control-M&amp;#039;s now&amp;lt;br /&amp;gt;&lt;br /&gt;
There are several methods but I think this is the easiest to remember&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
:g/^$/d&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Right pad a variable===&lt;br /&gt;
a function like rpad in SQL but for Shell&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
function rpad {&lt;br /&gt;
text=$1&lt;br /&gt;
padwidth=$2&lt;br /&gt;
padchar=$3&lt;br /&gt;
echo &amp;quot;$text&amp;quot; | sed -e :a -e &amp;#039;s/^.\{1,&amp;#039;$padwidth&amp;#039;\}$/&amp;amp;\&amp;#039;$padchar&amp;#039;/;ta&amp;#039;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Connect to a Windows server from Linux using rdesktop===&lt;br /&gt;
My remmina stopped working so rolled my own. Very simple really. Put this is a shell.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
tsocks rdesktop -z -P -x m -a 16 -d MAIND -u sbarkley -p ****** -r disk:SOL=$HOME/Documents/SOL -g 95% 150.251.112.38 &amp;amp;&lt;br /&gt;
&lt;br /&gt;
where...&lt;br /&gt;
-z    - enables compression&lt;br /&gt;
-P    - enables bitmap caching (saves network traffic)&lt;br /&gt;
-x m  - disables eye-candy features&lt;br /&gt;
-a 16 - reduce colour pallete to 16 colours&lt;br /&gt;
-d    - domain to connect to&lt;br /&gt;
-u    - username&lt;br /&gt;
-p    - password&lt;br /&gt;
-r    - setup a shared folder&lt;br /&gt;
-g    - geometry (use W x H or percentage)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Slight problems with rdesktop not working 100% of the time. Now using xfreerdp. Seems better...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
xfreerdp -g 90% --ignore-certificate --gdi sw -K -d wdcrhbp05 -u oraibm -p &amp;quot;`cat $HOME/scripts/.oraibm.password`&amp;quot; -T &amp;quot;wdcrhbp05_oraibm&amp;quot; --plugin cliprdr --plugin rdpdr --data disk:SOL:/home/bey9at77/Documents/SOL -- --plugin rdpsnd --data alsa -- 150.251.112.25 &amp;amp;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Reset your password bypassing password rules===&lt;br /&gt;
must be done as root&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
echo &amp;quot;user:new_password&amp;quot; | chpasswd&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Sum the sizes of all files of an ls listing===&lt;br /&gt;
It&amp;#039;ll check to see if the sum of filesizes corresponds with the df -g (or h) listing (can get messed up due to open but deleted files)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cd /oracle/export&lt;br /&gt;
df -g .&lt;br /&gt;
find . -name &amp;quot;*dmp*&amp;quot; -ls |  awk &amp;#039;{ SUM += $7} END { print SUM/1024/1024/1024 }&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Mount an iso image under Linux===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
mkdir -p /mnt/cdrom&lt;br /&gt;
mount -o loop /dev/cdrom /mnt/cdrom&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===How many processors on the machine?===&lt;br /&gt;
* AIX&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
lsdev -C|grep Process|wc -l&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Solaris&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
psrinfo -v|grep &amp;quot;Status of processor&amp;quot;|wc -l&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Linux&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cat /proc/cpuinfo|grep processor|wc -l&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Quick, simple, understandable example of how to use RRDTool===&lt;br /&gt;
* [[RRDTool]]&lt;br /&gt;
&lt;br /&gt;
===Use expect to respond automatically to interactive programs===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/usr/bin/expect -f&lt;br /&gt;
spawn /usr/tivoli/tsm/client/oracle/bin64/tdpoconf passw -tdpo_optfile=/oracle/[lindex $argv 0]/admin/tdpo.opt&lt;br /&gt;
expect &amp;quot;assword:&amp;quot; {send &amp;quot;password\r&amp;quot;}&lt;br /&gt;
expect &amp;quot;assword:&amp;quot; {send &amp;quot;password\r&amp;quot;}&lt;br /&gt;
expect &amp;quot;assword:&amp;quot; {send &amp;quot;password\r&amp;quot;}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Use expect to allow file copy with scp (if ssh keys are not an option)===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/usr/bin/expect -f&lt;br /&gt;
spawn scp /home/oracle/.profile oracle@hn512:/tmp/prfl&lt;br /&gt;
set pass &amp;quot;thepassword&amp;quot;&lt;br /&gt;
expect {&lt;br /&gt;
        password: {send &amp;quot;$pass\r&amp;quot; ; exp_continue}&lt;br /&gt;
        eof exit&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Within a shell script set up simultaneous output to both terminal and a file using a FIFO (named pipes)===&lt;br /&gt;
or &amp;quot;How to send shell output to screen/stdout as well as to a logfile using tee and redirection with exec&amp;quot;&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
examples [http://www.unix.com/shell-programming-and-scripting/85584-redirect-within-ksh.html here on unix.com]&lt;br /&gt;
* general info on redirections [http://www.catonmat.net/blog/bash-one-liners-explained-part-three/ here at catonmat.net]&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/ksh&lt;br /&gt;
&lt;br /&gt;
REDIR=test.redir&lt;br /&gt;
FIFO=test.pipe&lt;br /&gt;
[[ -e $FIFO ]] || mkfifo $FIFO&lt;br /&gt;
&lt;br /&gt;
# make a new channel(3) and copy channel 1&amp;#039;s destination as its own (does NOT POINT TO channel 1&amp;#039;s destination)&lt;br /&gt;
# this allows the normal output to continue to STDOUT but also get printed to whatever file is attached to channel 3&lt;br /&gt;
exec 3&amp;gt;&amp;amp;1&lt;br /&gt;
&lt;br /&gt;
# anything coming in on the pipe, send it to $REDIR and to channel 3&lt;br /&gt;
tee $REDIR &amp;lt;$FIFO &amp;gt;&amp;amp;3 &amp;amp;&lt;br /&gt;
&lt;br /&gt;
# redirect STDOUT to the pipe&lt;br /&gt;
exec &amp;gt; $FIFO&lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;going to default output&amp;quot;&lt;br /&gt;
echo &amp;quot;forcing to channel 1&amp;quot; &amp;gt;&amp;amp;1&lt;br /&gt;
echo &amp;quot;forcing to channel 2&amp;quot; &amp;gt;&amp;amp;2&lt;br /&gt;
echo &amp;quot;forcing to channel 3&amp;quot; &amp;gt;&amp;amp;3&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====More elaborate example====&lt;br /&gt;
found [http://stackoverflow.com/questions/2288939/create-a-pipe-that-writes-to-multiple-files-tee here on stackoverflow]&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/sh&lt;br /&gt;
&lt;br /&gt;
# Author: Harvey Chapman &amp;lt;hchapman _AT_ 3gfp.com&amp;gt;&lt;br /&gt;
# Description: POSIX shell functions that can be used with tee to simultaneously put&lt;br /&gt;
#              stderr and stdout to both a file and stdout&lt;br /&gt;
#&lt;br /&gt;
# Based on:&lt;br /&gt;
#    Re: How to redirect stderr and stdout to a file plus display at the same time&lt;br /&gt;
#    http://www.travishartwell.net/blog/2006/08/19_2220&lt;br /&gt;
&lt;br /&gt;
#&lt;br /&gt;
# Original example function from Travis Hartwell&amp;#039;s blog.&lt;br /&gt;
# Note: I&amp;#039;ve made minor changes to it.&lt;br /&gt;
example()&lt;br /&gt;
{&lt;br /&gt;
  OUTPUT_LOG=output.log&lt;br /&gt;
  OUTPUT_PIPE=output.pipe&lt;br /&gt;
&lt;br /&gt;
  # This should really be -p to test that it&amp;#039;s a pipe.&lt;br /&gt;
  if [ ! -e $OUTPUT_PIPE ]; then&lt;br /&gt;
      mkfifo $OUTPUT_PIPE&lt;br /&gt;
  fi&lt;br /&gt;
&lt;br /&gt;
  # This should really be -f to test that it&amp;#039;s a regular file.&lt;br /&gt;
  if [ -e $OUTPUT_LOG ]; then&lt;br /&gt;
      rm $OUTPUT_LOG&lt;br /&gt;
  fi&lt;br /&gt;
&lt;br /&gt;
  exec 3&amp;gt;&amp;amp;1 4&amp;gt;&amp;amp;2&lt;br /&gt;
  tee $OUTPUT_LOG &amp;lt; $OUTPUT_PIPE &amp;gt;&amp;amp;3 &amp;amp;&lt;br /&gt;
  tpid=$!&lt;br /&gt;
  exec &amp;gt; $OUTPUT_PIPE 2&amp;gt;&amp;amp;1&lt;br /&gt;
&lt;br /&gt;
  echo &amp;quot;This is on standard out&amp;quot;&lt;br /&gt;
  echo &amp;quot;This is on standard err&amp;quot; &amp;gt;&amp;amp;2&lt;br /&gt;
&lt;br /&gt;
  exec 1&amp;gt;&amp;amp;3 3&amp;gt;&amp;amp;- 2&amp;gt;&amp;amp;4 4&amp;gt;&amp;amp;-&lt;br /&gt;
  wait $tpid&lt;br /&gt;
&lt;br /&gt;
  rm $OUTPUT_PIPE&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
# A slightly reduced version of example()&lt;br /&gt;
example2()&lt;br /&gt;
{&lt;br /&gt;
  OUTPUT_LOG=output.log&lt;br /&gt;
  OUTPUT_PIPE=output.pipe&lt;br /&gt;
&lt;br /&gt;
  rm -f $OUTPUT_PIPE&lt;br /&gt;
  mkfifo $OUTPUT_PIPE&lt;br /&gt;
  rm -f $OUTPUT_LOG&lt;br /&gt;
&lt;br /&gt;
  tee $OUTPUT_LOG &amp;lt; $OUTPUT_PIPE &amp;amp;&lt;br /&gt;
  tpid=$!&lt;br /&gt;
&lt;br /&gt;
  exec 3&amp;gt;&amp;amp;1 4&amp;gt;&amp;amp;2 &amp;gt;$OUTPUT_PIPE 2&amp;gt;&amp;amp;1&lt;br /&gt;
&lt;br /&gt;
  echo &amp;quot;This is on standard out&amp;quot;&lt;br /&gt;
  echo &amp;quot;This is on standard err&amp;quot; &amp;gt;&amp;amp;2&lt;br /&gt;
&lt;br /&gt;
  exec 1&amp;gt;&amp;amp;3 3&amp;gt;&amp;amp;- 2&amp;gt;&amp;amp;4 4&amp;gt;&amp;amp;-&lt;br /&gt;
  wait $tpid&lt;br /&gt;
  rm -f $OUTPUT_PIPE&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
#&lt;br /&gt;
# Logging methods based on above. See the example below for how to use them.&lt;br /&gt;
#&lt;br /&gt;
&lt;br /&gt;
# Usage: start_logging [delete_existing_logfile]&lt;br /&gt;
start_logging()&lt;br /&gt;
{&lt;br /&gt;
  # Check to see if OUTPUT_LOG and OUTPUT_PIPE need to be defined.&lt;br /&gt;
  if [ -z &amp;quot;$OUTPUT_LOG&amp;quot; ]; then&lt;br /&gt;
    OUTPUT_LOG=output.log&lt;br /&gt;
  fi&lt;br /&gt;
  if [ -z &amp;quot;$OUTPUT_PIPE&amp;quot; ]; then&lt;br /&gt;
    OUTPUT_PIPE=output.pipe&lt;br /&gt;
  fi&lt;br /&gt;
  # Make sure that we&amp;#039;re not already logging.&lt;br /&gt;
  if [ -n &amp;quot;$OUTPUT_PID&amp;quot; ]; then&lt;br /&gt;
    echo &amp;quot;Logging already started!&amp;quot;&lt;br /&gt;
    return 1&lt;br /&gt;
  fi&lt;br /&gt;
&lt;br /&gt;
  # Always remove the log and pipe first.&lt;br /&gt;
  rm -f $OUTPUT_PIPE&lt;br /&gt;
  # Delete the logfile first if told to.&lt;br /&gt;
  if [ &amp;quot;$1&amp;quot; = delete_existing_logfile ]; then&lt;br /&gt;
    rm -f $OUTPUT_LOG&lt;br /&gt;
  fi&lt;br /&gt;
&lt;br /&gt;
  mkfifo $OUTPUT_PIPE&lt;br /&gt;
  tee -a $OUTPUT_LOG &amp;lt; $OUTPUT_PIPE &amp;amp;&lt;br /&gt;
  OUTPUT_PID=$!&lt;br /&gt;
&lt;br /&gt;
  exec 3&amp;gt;&amp;amp;1 4&amp;gt;&amp;amp;2 &amp;gt;$OUTPUT_PIPE 2&amp;gt;&amp;amp;1&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
stop_logging()&lt;br /&gt;
{&lt;br /&gt;
  # Make sure that we&amp;#039;re currently logging.&lt;br /&gt;
  if [ -z &amp;quot;$OUTPUT_PID&amp;quot; ]; then&lt;br /&gt;
    echo &amp;quot;Logging not yet started!&amp;quot;&lt;br /&gt;
    return 1&lt;br /&gt;
  fi&lt;br /&gt;
  exec 1&amp;gt;&amp;amp;3 3&amp;gt;&amp;amp;- 2&amp;gt;&amp;amp;4 4&amp;gt;&amp;amp;-&lt;br /&gt;
  wait $OUTPUT_PID&lt;br /&gt;
  rm -f $OUTPUT_PIPE&lt;br /&gt;
  unset OUTPUT_PID&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
example3()&lt;br /&gt;
{&lt;br /&gt;
  start_logging&lt;br /&gt;
  #start_logging delete_existing_logfile&lt;br /&gt;
  echo &amp;quot;This is on standard out&amp;quot;&lt;br /&gt;
  echo &amp;quot;This is on standard err&amp;quot; &amp;gt;&amp;amp;2&lt;br /&gt;
  stop_logging&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===RedHat root filesystem has gone read-only===&lt;br /&gt;
* [http://www.unixarena.com/2013/09/redhat-linux-how-to-fix-read-only-root.html How to fix read only root file system]&lt;br /&gt;
&lt;br /&gt;
===Kill all processes for a user===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
for prc in `ps -ef | grep -E &amp;quot;^ +[o]racle&amp;quot; | awk &amp;#039;{print $2}&amp;#039;`; do&lt;br /&gt;
    kill $prc&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===isRGHere===&lt;br /&gt;
Checks if resource group is on this leg of an HACMP cluster. Returns 0 if true else 1.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/usr/bin/ksh&lt;br /&gt;
&lt;br /&gt;
SCRIPT=`basename $0`&lt;br /&gt;
&lt;br /&gt;
function rctest&lt;br /&gt;
{&lt;br /&gt;
exitcode=$1&lt;br /&gt;
msg=$2&lt;br /&gt;
if [ $exitcode -ne 0 ]; then&lt;br /&gt;
        echo &amp;quot;********************************************************************************&amp;quot;&lt;br /&gt;
        echo &amp;quot;\nScript $SCRIPT finished with errors.&amp;quot;&lt;br /&gt;
        echo &amp;quot;$msg.&amp;quot;&lt;br /&gt;
        echo &amp;quot;Returncode : $exitcode.&amp;quot;&lt;br /&gt;
        echo &amp;quot;\n********************************************************************************&amp;quot;&lt;br /&gt;
&lt;br /&gt;
        fi&lt;br /&gt;
exit $exitcode&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
RGINFO=/usr/es/sbin/cluster/utilities/clRGinfo&lt;br /&gt;
[[ ! -f $RGINFO ]] &amp;amp;&amp;amp;  rctest 1 &amp;quot;clRGinfo not found&amp;quot;&lt;br /&gt;
&lt;br /&gt;
if [ $# -eq 1 ]&lt;br /&gt;
then&lt;br /&gt;
        RG=`echo $1 | cut -c 1-14`&lt;br /&gt;
else&lt;br /&gt;
        rctest 10  &amp;quot;Usage: `basename $0` &amp;lt;RG name&amp;gt;&amp;quot;&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
$RGINFO |grep -qwp $RG ||  rctest 9 &amp;quot;$RG is not defined&amp;quot;&lt;br /&gt;
&lt;br /&gt;
THISNODE=`/usr/es/sbin/cluster/utilities/get_local_nodename | cut -c 1-14`&lt;br /&gt;
$RGINFO |grep -wp $RG |grep -w $THISNODE |grep -wq ONLINE&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===AIX: add a user to a group===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
chgrpmem -m + oracle ibmtls&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Find swear words in scripts by comparing it to a list found on the internet===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
wget &amp;quot;http://www.bannedwordlist.com/lists/swearWords.csv&amp;quot; -O /tmp/s ; for word in $(cat /tmp/s | sed -e &amp;#039;s/ /_/g&amp;#039; -e &amp;#039;s/,/ /g&amp;#039;) ; do grep -wR $word *; done | less&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===grep -p (for paragraph) works on AIX but not on Linux or Solaris===&lt;br /&gt;
Use awk instead&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
awk &amp;#039;BEGIN {FS=&amp;quot;\n&amp;quot; RS=&amp;quot;\n\n&amp;quot;} /search pattern/ { do something }&amp;#039; &amp;lt;file&amp;gt;&lt;br /&gt;
/usr/xpg4/bin/awk &amp;#039;BEGIN {RS=&amp;quot;\n\n&amp;quot;;FS=&amp;quot;\n&amp;quot;} /AGRHDWQ1/ {print $2}&amp;#039; dsm.sys | awk &amp;#039;{print $NF}&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
this prints the last word of the second &amp;#039;&amp;#039;line&amp;#039;&amp;#039; in the paragraph in dsm.sys that contains the search term AGRHDWQ1.&amp;lt;br /&amp;gt;&lt;br /&gt;
Or slightly simpler...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
awk -v RS=&amp;#039;&amp;#039; &amp;#039;/NHAPPLP1/&amp;#039; /etc/tsm/dsm.sys     # (use /usr/xpg4/bin/awk on Solaris)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or, case insensitively:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
awk -v RS=&amp;#039;&amp;#039; &amp;#039;tolower($0) ~/so_u_clubqa_orx_d_cab/&amp;#039; /etc/tsm/dsm.sys&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Using -v means you don&amp;#039;t have to use a BEGIN section.&lt;br /&gt;
&lt;br /&gt;
===debug/redirect log of a shell===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/usr/bin/ksh&lt;br /&gt;
exec 2&amp;gt;/tmp/mytest&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Different ways of Iteration in korn shell with a while loop===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
IFS=&amp;quot;|&amp;quot;&lt;br /&gt;
exec 0&amp;lt;$statfile&lt;br /&gt;
while read host db started stopped&lt;br /&gt;
do&lt;br /&gt;
    rrdfile=&amp;quot;export_duration_${host}_${db}.rrd&amp;quot;&lt;br /&gt;
    $RRDTOOL update ${RRDDIR}/${rrdfile} $started:$started $stopped&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
while read host db started stopped&lt;br /&gt;
do&lt;br /&gt;
    rrdfile=&amp;quot;export_duration_${host}_${db}.rrd&amp;quot;&lt;br /&gt;
    $RRDTOOL update ${RRDDIR}/${rrdfile} $started:$started $stopped&lt;br /&gt;
done &amp;lt;statfile&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    cat $statfile | sort -nk4 | while IFS=\| read host db type started stopped&lt;br /&gt;
    do&lt;br /&gt;
        [[ &amp;quot;$stopped&amp;quot; == &amp;quot;&amp;quot; ]] &amp;amp;&amp;amp; continue&lt;br /&gt;
        rrdfile=&amp;quot;export_duration_${host}_${db}.rrd&amp;quot;&lt;br /&gt;
        $RRDTOOL update ${RRDDIR}/${rrdfile} ${started}:${started}:${stopped}&lt;br /&gt;
        [[ $? -ne 0 ]] &amp;amp;&amp;amp; echo &amp;quot;nok: $?&amp;quot;&lt;br /&gt;
    done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Filesystem 100% full, what&amp;#039;s taking up all the space?===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
find /oracle/endur -xdev -ls|sort -nr +6|head&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/dev/esb01fs010001      1.00      0.00  100%     1838    69% /oracle&lt;br /&gt;
beuxdsysesb01:root[/root]# cd /oracle&lt;br /&gt;
beuxdsysesb01:root[/oracle]# du -gsx * | sort -n&lt;br /&gt;
0.00    checkpoints&lt;br /&gt;
0.00    flash_recovery_area&lt;br /&gt;
0.00    lost+found&lt;br /&gt;
0.00    oraInst.loc&lt;br /&gt;
0.00    oraInventory&lt;br /&gt;
0.09    admin&lt;br /&gt;
0.99    diag&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
cd  diag and repeat until culprits are found&lt;br /&gt;
&lt;br /&gt;
===Show paged memory hogs on AIX===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
svmon -Pt20 | perl -e &amp;#039;while(&amp;lt;&amp;gt;){print if($.==2||$&amp;amp;&amp;amp;&amp;amp;!$s++);$.=0 if(/^-+$/)}&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Capitalise the first letter of a word in Korn Shell===&lt;br /&gt;
Not as easy as it sounds if it needs to work in non-ksh93 shells&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
function capit { &lt;br /&gt;
    typeset -u first&lt;br /&gt;
    first=${1%&amp;quot;${1#?}&amp;quot;}&lt;br /&gt;
    printf &amp;quot;%s\n&amp;quot; &amp;quot;${first}${1#?}&amp;quot;&lt;br /&gt;
    return 0&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or maybe more neatly done in Perl...&amp;lt;br /&amp;gt;&lt;br /&gt;
This will capitalise each word in a sentence passed into it&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
function capit { &lt;br /&gt;
    echo &amp;quot;$1&amp;quot; |  perl -pe &amp;quot;s/([\w&amp;#039;]+)/\u\L\1/g&amp;quot;&lt;br /&gt;
    return 0&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Remove / rename a directory / file containing weird control characters===&lt;br /&gt;
Use ls with -i to see inode listing&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ls -bali&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Use find with -inum to get the filename and -exec to remove it&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
find . -inum &amp;lt;inode from ls listing&amp;gt; -exec rm -f {} \;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Run a local script on a remote host===&lt;br /&gt;
Doing it this way means we do not need to scp the shell over to the host before executing it!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ssh user@host &amp;#039;sh&amp;#039; &amp;lt; your_script.sh&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
First of all, this command is a redirection: your shell will open the file your_script.sh and feed it as input to the ssh command. ssh, in turn, will tunnel its stdin to the remote command, namely, sh instance. And sh without arguments reads its script from stdin. So we got sh instance, which is launched on remote host, but reads commands from your local file.&lt;br /&gt;
&lt;br /&gt;
===Get a list of running instances - but only those started by the current user===&lt;br /&gt;
This is the way I wanted to do it but there&amp;#039;s an issue. Where does that spare } character come from? Anyone?&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ps -ef | grep [p]mon | awk -v dbowner=$(id -un) &amp;#039;{ if ($1==dbowner) { gsub(/ora_pmon_/,&amp;quot;&amp;quot;,$NF); print $NF; } }&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
ps listing&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ ps -ef | grep [p]mon&lt;br /&gt;
  oracle 13304024        1   0   Jun 07      -  2:39 ora_pmon_reportk&lt;br /&gt;
  oracle 26018178        1   0   Jun 07      -  3:01 ora_pmon_dwh_perf&lt;br /&gt;
  oracle 29229432        1   0   Jun 07      -  2:30 ora_pmon_adso&lt;br /&gt;
 oraebso 18022994        1   0   Jun 07      -  2:38 ora_pmon_EBSO&lt;br /&gt;
  oracle 30278192        1   0   Jun 07      -  2:48 ora_pmon_owb112k&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Results of above command&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
reportk&lt;br /&gt;
dwh_perf&lt;br /&gt;
adso&lt;br /&gt;
}&lt;br /&gt;
owb112k&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Workaround 1. Send the ps listing to a file and work on it without pipes. Works but it&amp;#039;s a bit long-winded especially as we have to clean up afterwards.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ps -ef | grep [p]mon&amp;gt;/tmp/results.$$ 2&amp;gt;/dev/null; awk -v dbowner=$(id -un) &amp;#039;{ if ($1==dbowner) { gsub(/ora_pmon_/,&amp;quot;&amp;quot;,$NF); print $NF; } }&amp;#039; /tmp/results.$$; rm -f /tmp/results.$$&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Workaround 2. Don&amp;#039;t like the grep -v but until I find out where that } is coming from..&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ps -ef | grep [p]mon | awk -v dbowner=$(id -un) &amp;#039;{ if ($1==dbowner) { gsub(/ora_pmon_/,&amp;quot;&amp;quot;,$NF); print $NF; } }&amp;#039; | egrep -v &amp;#039;grep|}|ASM&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Return a list of Oracle databases running on a list of remote servers===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/ksh&lt;br /&gt;
&lt;br /&gt;
serverlist=`cat /home/tools/ini/system/oracle_servers | sort -n | tr &amp;quot;\n&amp;quot; &amp;quot; &amp;quot;`&lt;br /&gt;
&lt;br /&gt;
if [ -z &amp;quot;${serverlist}&amp;quot; ]&lt;br /&gt;
then&lt;br /&gt;
    echo &amp;quot;no servers found&amp;quot; &amp;amp;&amp;amp; exit 1&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
for server in ${serverlist}&lt;br /&gt;
do&lt;br /&gt;
    ssh ${server} &amp;quot;ps -ef | grep [o]ra_pmon_&amp;quot; &amp;gt;/tmp/${server}.dblist&lt;br /&gt;
done&lt;br /&gt;
&lt;br /&gt;
for server in ${serverlist}&lt;br /&gt;
do&lt;br /&gt;
    cat /tmp/${server}.dblist | awk -F_ -v SRV=${server} &amp;#039;BEGIN {print SRV &amp;quot;:&amp;quot;} {print $NF}&amp;#039; | tr &amp;quot;\n&amp;quot; &amp;quot; &amp;quot;&lt;br /&gt;
    echo&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Clever trick to check whether SQL output needs sending to someone===&lt;br /&gt;
Using an exit status from SQL*Plus back to the shell so we can decide what to do.  Nice one!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
tempfile=/tmp/audit_locked_accounts_$ORACLE_SID.txt&lt;br /&gt;
&lt;br /&gt;
# Start sqlplus and check for locked accounts&lt;br /&gt;
sqlplus -S &amp;quot;/ as sysdba&amp;quot; &amp;lt;&amp;lt; EOF &amp;gt; $tempfile&lt;br /&gt;
set pages 0&lt;br /&gt;
select &amp;#039;The following accounts were found to be unlocked and should not be&amp;#039;&lt;br /&gt;
from dual;&lt;br /&gt;
&lt;br /&gt;
def exit_status = 0&lt;br /&gt;
col xs new_value exit_status&lt;br /&gt;
&lt;br /&gt;
select username&lt;br /&gt;
,      account_status&lt;br /&gt;
,      1 as xs&lt;br /&gt;
from   dba_users&lt;br /&gt;
where  account_status != &amp;#039;LOCKED&amp;#039;&lt;br /&gt;
and    username in (&amp;#039;HR&amp;#039;, &amp;#039;SCOTT&amp;#039;, &amp;#039;OUTLN&amp;#039;, &amp;#039;MDSYS&amp;#039;, &amp;#039;CTXSYS&amp;#039;)&lt;br /&gt;
/&lt;br /&gt;
exit &amp;amp;exit_status&lt;br /&gt;
EOF&lt;br /&gt;
&lt;br /&gt;
# If the exit status of sqlplus was not 0 then we will send an email&lt;br /&gt;
if [ $? != 0 ]; then&lt;br /&gt;
    mail -s &amp;quot;Accounts Unlocked in $ORACLE_SID&amp;quot; oracle &amp;lt; $tempfile&lt;br /&gt;
fi&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Check RMAN logfiles for errors from cron every day===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
00 09 * * * /home/tools/scripts/oracle/dosh &amp;#039;find /home/tools/logs/rman -name &amp;quot;*online.log&amp;quot; -mtime -1 -exec sed -ne &amp;quot;/^RMAN-/,/^$/p&amp;quot; {} \\; -ls&amp;#039; | mailx&lt;br /&gt;
 -s &amp;#039;RMAN errors last night&amp;#039; stuart@domain.com&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/home/ibmtools/scripts/oracle/dosh &amp;#039;find /oracle/export -name &amp;quot;expdp*log&amp;quot; -mtime -1 -exec grep ORA- {} \; -ls&amp;#039; | mailx -s &amp;#039;Datapump errors for Baxter last night&amp;#039; stuart@domain.com&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===An alternative to getopts===&lt;br /&gt;
These methods have the advantage of allowing arguments of any length not just 1 character&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
countArgs=$#&lt;br /&gt;
while [[ $# -gt 0 ]]&lt;br /&gt;
do&lt;br /&gt;
    idx1=$($ECHO $1|$GREP &amp;quot;=&amp;quot;|wc -l)&lt;br /&gt;
    if [[ $idx1 -gt 0 ]]; then&lt;br /&gt;
        key=$($ECHO $1|$CUT -d &amp;#039;=&amp;#039; -f 1)&lt;br /&gt;
        value=$($ECHO $1|$CUT -d &amp;#039;=&amp;#039; -f 2)&lt;br /&gt;
    else&lt;br /&gt;
        key=$($ECHO $1|$CUT -d &amp;#039;=&amp;#039; -f 1)&lt;br /&gt;
        idx2=$($ECHO $1|$GREP &amp;quot;^-&amp;quot;|wc -l)&lt;br /&gt;
        if [[ $idx2 -eq 0 ]]; then&lt;br /&gt;
            $ECHO -e &amp;quot;\n ERROR: $1 is an unsupported argument passed to agentDeploy.sh.\n&amp;quot;  &lt;br /&gt;
            usage&lt;br /&gt;
            exit 1&lt;br /&gt;
        fi&lt;br /&gt;
    fi&lt;br /&gt;
&lt;br /&gt;
    case &amp;quot;$key&amp;quot; in&lt;br /&gt;
    -help)&lt;br /&gt;
        if [[ $upgradeFlag ]]; then&lt;br /&gt;
            upgradeUsage&lt;br /&gt;
        else&lt;br /&gt;
            freshUsage&lt;br /&gt;
        fi&lt;br /&gt;
        exit 0;;&lt;br /&gt;
    AGENT_BASE_DIR)&lt;br /&gt;
        agentBaseDir=$($ECHO $value|$SED &amp;#039;s/\/$//&amp;#039;)&lt;br /&gt;
        checkBaseFlag=TRUE;;&lt;br /&gt;
    OMS_HOST)&lt;br /&gt;
        omsHost=$value&lt;br /&gt;
        checkOMSHost=TRUE;;&lt;br /&gt;
    EM_UPLOAD_PORT)&lt;br /&gt;
        omsPort=$value&lt;br /&gt;
        checkOMSPort=TRUE;;&lt;br /&gt;
    AGENT_INSTANCE_HOME)&lt;br /&gt;
        instHome=$($ECHO $value | $SED &amp;#039;s/\/$//&amp;#039;);;&lt;br /&gt;
    AGENT_REGISTRATION_PASSWORD)&lt;br /&gt;
        pswd=$value;;&lt;br /&gt;
    s_encrSecurePwd)&lt;br /&gt;
        pswd=$value;;  &lt;br /&gt;
    RESPONSE_FILE)&lt;br /&gt;
        rspFlag=TRUE  &lt;br /&gt;
        rspLoc=$value;;&lt;br /&gt;
    OLD_AGENT_VERSION)&lt;br /&gt;
        oldAgentVersion=$value;;            &lt;br /&gt;
    OLDHOME)&lt;br /&gt;
        oldHome=$value;;    &lt;br /&gt;
    -debug)&lt;br /&gt;
        debugSwitch=TRUE;;&lt;br /&gt;
    -forceConfigure)&lt;br /&gt;
        forceFlag=TRUE;;&lt;br /&gt;
    -configOnly)&lt;br /&gt;
        configFlag=TRUE    &lt;br /&gt;
        validationFlag=TRUE;;&lt;br /&gt;
    -agentImageLocation)&lt;br /&gt;
        archiveLoc=$value&lt;br /&gt;
        checkArchiveFlag=TRUE;;&lt;br /&gt;
    -invPtrLoc) shift&lt;br /&gt;
        ptrLoc=$1;;&lt;br /&gt;
    -Upgrade)&lt;br /&gt;
        UpgradeFlag=TRUE&lt;br /&gt;
        validFlag=TRUE;;&lt;br /&gt;
    INVENTORY_LOCATION)&lt;br /&gt;
        validFlag=TRUE;;&lt;br /&gt;
    b_forceInstCheck)&lt;br /&gt;
        validFlag=TRUE&lt;br /&gt;
        forcefullFlag=TRUE;;&lt;br /&gt;
    -prereqOnly)&lt;br /&gt;
        validationFlag=TRUE&lt;br /&gt;
        prereqFlag=TRUE;;&lt;br /&gt;
    -executeRootsh)&lt;br /&gt;
        validFlag=TRUE;;&lt;br /&gt;
    *)  idx=$($ECHO $1|$GREP &amp;quot;^-&amp;quot;|wc -l)&lt;br /&gt;
        if [[ $idx -eq 0 ]]; then&lt;br /&gt;
            validFlag=TRUE&lt;br /&gt;
        else&lt;br /&gt;
            $ECHO -e &amp;quot;\n ERROR: Invalid argument $key passed.&amp;quot;&lt;br /&gt;
            usage&lt;br /&gt;
            exit 1          &lt;br /&gt;
        fi&lt;br /&gt;
    esac&lt;br /&gt;
    shift&lt;br /&gt;
done&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
another way - found in /etc/init.d/functions (daemon function) in Fedora&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    while [ &amp;quot;$1&amp;quot; != &amp;quot;${1##[-+]}&amp;quot; ]; do&lt;br /&gt;
        case $1 in&lt;br /&gt;
        &amp;#039;&amp;#039;)&lt;br /&gt;
            echo $&amp;quot;$0: Usage: daemon [+/-nicelevel] {program}&amp;quot; &amp;quot;[arg1]...&amp;quot;&lt;br /&gt;
            return 1&lt;br /&gt;
            ;;&lt;br /&gt;
        --check)&lt;br /&gt;
            base=$2&lt;br /&gt;
            gotbase=&amp;quot;yes&amp;quot;&lt;br /&gt;
            shift 2&lt;br /&gt;
            ;;&lt;br /&gt;
        --check=?*)&lt;br /&gt;
            base=${1#--check=}&lt;br /&gt;
            gotbase=&amp;quot;yes&amp;quot;&lt;br /&gt;
            shift&lt;br /&gt;
            ;;&lt;br /&gt;
        --user)&lt;br /&gt;
            user=$2&lt;br /&gt;
            shift 2&lt;br /&gt;
            ;;&lt;br /&gt;
        --user=?*)&lt;br /&gt;
            user=${1#--user=}&lt;br /&gt;
            shift&lt;br /&gt;
            ;;&lt;br /&gt;
        --pidfile)&lt;br /&gt;
            pid_file=$2&lt;br /&gt;
            shift 2&lt;br /&gt;
            ;;&lt;br /&gt;
        --pidfile=?*)&lt;br /&gt;
            pid_file=${1#--pidfile=}&lt;br /&gt;
            shift&lt;br /&gt;
            ;;&lt;br /&gt;
        --force)&lt;br /&gt;
            force=&amp;quot;force&amp;quot;&lt;br /&gt;
            shift&lt;br /&gt;
            ;;&lt;br /&gt;
        [-+][0-9]*)&lt;br /&gt;
            nice=&amp;quot;nice -n $1&amp;quot;&lt;br /&gt;
            shift&lt;br /&gt;
            ;;&lt;br /&gt;
        *)&lt;br /&gt;
            echo $&amp;quot;$0: Usage: daemon [+/-nicelevel] {program}&amp;quot; &amp;quot;[arg1]...&amp;quot;&lt;br /&gt;
            return 1&lt;br /&gt;
            ;;&lt;br /&gt;
      esac&lt;br /&gt;
    done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
another way - found in adstrtal.sh (middleware start script for EBS)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#&lt;br /&gt;
# Parse Arguments&lt;br /&gt;
#&lt;br /&gt;
&lt;br /&gt;
for nxtarg in $*&lt;br /&gt;
do&lt;br /&gt;
  arg=`echo $nxtarg | sed &amp;#039;s/^//&amp;#039;`&lt;br /&gt;
&lt;br /&gt;
  case $arg in&lt;br /&gt;
    -secureapps)    if test &amp;quot;$secureapps&amp;quot; = &amp;quot;&amp;quot; ; then&lt;br /&gt;
                       secureapps=$arg&lt;br /&gt;
                    else&lt;br /&gt;
                       echo &amp;quot;$0: Duplicate Argument passed : $arg&amp;quot;&lt;br /&gt;
                       usage&lt;br /&gt;
                    fi&lt;br /&gt;
                ;;&lt;br /&gt;
    -nodbchk)       if test &amp;quot;$nodbchk&amp;quot; = &amp;quot;&amp;quot; ; then&lt;br /&gt;
                       nodbchk=$arg&lt;br /&gt;
                    else&lt;br /&gt;
                       echo &amp;quot;$0: Duplicate Argument passed : $arg&amp;quot;&lt;br /&gt;
                       usage&lt;br /&gt;
                    fi&lt;br /&gt;
                ;;&lt;br /&gt;
    -nopromptmsg)   if test &amp;quot;$nopromptmsg&amp;quot; = &amp;quot;&amp;quot; ; then&lt;br /&gt;
                       nopromptmsg=$arg&lt;br /&gt;
                    else&lt;br /&gt;
                       echo &amp;quot;$0: Duplicate Argument passed : $arg&amp;quot;&lt;br /&gt;
                       usage&lt;br /&gt;
                    fi&lt;br /&gt;
                ;;&lt;br /&gt;
    *)              if test &amp;quot;$unpw&amp;quot; = &amp;quot;&amp;quot; ; then&lt;br /&gt;
                       unpw=$arg&lt;br /&gt;
                    else&lt;br /&gt;
                       echo &amp;quot;$0: Duplicate Argument passed : $arg&amp;quot;&lt;br /&gt;
                       usage&lt;br /&gt;
                    fi&lt;br /&gt;
  esac&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
and another in adautocfg.sh&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
for myarg in $*&lt;br /&gt;
do&lt;br /&gt;
&lt;br /&gt;
  arg=`echo $myarg | sed &amp;#039;s/^-//&amp;#039;`&lt;br /&gt;
  case $arg in&lt;br /&gt;
    appspass=*)&lt;br /&gt;
            appspass=`echo $arg | sed &amp;#039;s/appspass=//g&amp;#039;`&lt;br /&gt;
            shift&lt;br /&gt;
            ;;&lt;br /&gt;
    nocustom)&lt;br /&gt;
            myparams=&amp;quot;$myparams $arg&amp;quot;&lt;br /&gt;
            shift&lt;br /&gt;
            ;;&lt;br /&gt;
    noversionchecks)&lt;br /&gt;
            myparams=&amp;quot;$myparams $arg&amp;quot;&lt;br /&gt;
            shift&lt;br /&gt;
            ;;&lt;br /&gt;
    promptmsg=*)&lt;br /&gt;
            promptmsg=`echo $arg | sed &amp;#039;s/promptmsg=//g&amp;#039;`&lt;br /&gt;
            shift&lt;br /&gt;
            ;;&lt;br /&gt;
        *)  echo &amp;quot;$0: unrecognized action specified&amp;quot;&lt;br /&gt;
            exit 1&lt;br /&gt;
  esac&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Run a script on multiple servers===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/ksh&lt;br /&gt;
# ==============================================================================&lt;br /&gt;
# Name         : dosh   (Distributed Oracle SHell)&lt;br /&gt;
# Description  : Runs a command on all Oracle servers&lt;br /&gt;
#&lt;br /&gt;
# Parameters   : h - displays help&lt;br /&gt;
#                v - verbose (default, like all unix commands is silent)&lt;br /&gt;
#                c - command to be executed&lt;br /&gt;
#&lt;br /&gt;
# Example      : ./dosh -v -c &amp;#039;ls -al&amp;#039;&lt;br /&gt;
#&lt;br /&gt;
# Modification History&lt;br /&gt;
# ====================&lt;br /&gt;
# When      Who               What&lt;br /&gt;
# ========= ================= ==================================================&lt;br /&gt;
# 08-FEB-13 Stuart Barkley    Created&lt;br /&gt;
# ==============================================================================&lt;br /&gt;
&lt;br /&gt;
# --------------------------------------------------------------------------&lt;br /&gt;
# this list of servers is generated by the DBAMON tool so will be up to date&lt;br /&gt;
# --------------------------------------------------------------------------&lt;br /&gt;
serverfile=/home/ibmtools/etc/oracle/oracle_servers&lt;br /&gt;
[[ -z &amp;quot;${serverfile}&amp;quot; ]] &amp;amp;&amp;amp; echo &amp;quot;Server list ${serverfile} not found&amp;quot; &amp;amp;&amp;amp; exit 1&lt;br /&gt;
&lt;br /&gt;
serverlist=`cat ${serverfile} | sort -n | tr &amp;quot;\n&amp;quot; &amp;quot; &amp;quot;`&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
# -------------------------&lt;br /&gt;
# get the arguments, if any&lt;br /&gt;
# -------------------------&lt;br /&gt;
while getopts &amp;quot;hvc:&amp;quot; OPT&lt;br /&gt;
do&lt;br /&gt;
    case &amp;quot;$OPT&amp;quot; in&lt;br /&gt;
    h) echo &amp;quot;\nUsage: $0 [-v] [-h] -c &amp;#039;&amp;lt;command_to_be_executed_remotely&amp;gt;&amp;#039;\n&amp;quot;;&lt;br /&gt;
       exit;&lt;br /&gt;
       ;;&lt;br /&gt;
    v) VERBOSE=&amp;quot;Y&amp;quot;;&lt;br /&gt;
       ;;&lt;br /&gt;
    c) CMMND=$OPTARG;&lt;br /&gt;
       ;;&lt;br /&gt;
    *) echo &amp;quot;\nUsage: $0 [-v] [-h] -c &amp;#039;&amp;lt;command_to_be_executed_remotely&amp;gt;&amp;#039;\n&amp;quot;;&lt;br /&gt;
       exit;&lt;br /&gt;
       ;;&lt;br /&gt;
    esac&lt;br /&gt;
done&lt;br /&gt;
shift $((OPTIND-1))&lt;br /&gt;
VERBOSE=${VERBOSE:-&amp;quot;N&amp;quot;}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
# --------------------------------&lt;br /&gt;
# check we have required arguments&lt;br /&gt;
# --------------------------------&lt;br /&gt;
[[ -z $CMMND ]] &amp;amp;&amp;amp; echo &amp;quot;Enter command to be executed like this: $0 -c &amp;#039;ls -al&amp;#039;&amp;quot; &amp;amp;&amp;amp; exit 1&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
# ----------------------------&lt;br /&gt;
# loop over the remote servers&lt;br /&gt;
# ----------------------------&lt;br /&gt;
for server in ${serverlist}&lt;br /&gt;
do&lt;br /&gt;
    if [[ &amp;quot;$VERBOSE&amp;quot; == &amp;quot;Y&amp;quot; ]]; then&lt;br /&gt;
        echo ${server} `date +&amp;#039;%d-%b-%Y %H:%M:%S&amp;#039;`&lt;br /&gt;
        echo &amp;quot;------------------------------------&amp;quot;&lt;br /&gt;
        set -x&lt;br /&gt;
    fi&lt;br /&gt;
    ssh ${server} &amp;quot;$CMMND&amp;quot;&lt;br /&gt;
    set +x&lt;br /&gt;
    [[ &amp;quot;$VERBOSE&amp;quot; == &amp;quot;Y&amp;quot; ]] &amp;amp;&amp;amp; echo&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
to be investigated... this one might be cleverer than mine...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
tmpdir=${TMPDIR:-/tmp}/pssh.$$&lt;br /&gt;
count=0&lt;br /&gt;
while userhost; do&lt;br /&gt;
    ssh -n -o BatchMode=yes ${userhost} &amp;#039;uname -a&amp;#039; &amp;gt; ${tmpdir}/${userhost} 2&amp;gt;&amp;amp;1 &amp;amp;&lt;br /&gt;
    count=`expr $count + 1`&lt;br /&gt;
done &amp;lt; userhost.lst&lt;br /&gt;
while [ $count -gt 0 ]; do&lt;br /&gt;
    wait $pids&lt;br /&gt;
    count=`expr $count - 1`&lt;br /&gt;
done&lt;br /&gt;
echo &amp;quot;Output for hosts are in $tmpdir&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
improved version...&amp;lt;br /&amp;gt;&lt;br /&gt;
just escape double quotes and dollar signs...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/ksh&lt;br /&gt;
# ==============================================================================&lt;br /&gt;
# Name         : dosh   (Distributed Oracle SHell)&lt;br /&gt;
# Description  : Runs a command on all Oracle servers&lt;br /&gt;
#&lt;br /&gt;
# Parameters   : h - displays help&lt;br /&gt;
#                v - verbose (default, like all unix commands is silent)&lt;br /&gt;
#                c - command to be executed&lt;br /&gt;
#&lt;br /&gt;
# Example      : ./dosh -v -c &amp;#039;ls -al&amp;#039;&lt;br /&gt;
#&lt;br /&gt;
# Modification History&lt;br /&gt;
# ====================&lt;br /&gt;
# When      Who               What&lt;br /&gt;
# ========= ================= ==================================================&lt;br /&gt;
# 08-FEB-13 Stuart Barkley    Created&lt;br /&gt;
# 08-JUL-15 Stuart Barkley    Background execution mode&lt;br /&gt;
# ==============================================================================&lt;br /&gt;
# --------------------------------------------------------------------------&lt;br /&gt;
# this list of servers is generated by the DBAMON tool so will be up to date&lt;br /&gt;
# --------------------------------------------------------------------------&lt;br /&gt;
serverfile=/home/ibmtools/etc/oracle/oracle_servers&lt;br /&gt;
[[ -z &amp;quot;${serverfile}&amp;quot; ]] &amp;amp;&amp;amp; echo &amp;quot;Server list ${serverfile} not found&amp;quot; &amp;amp;&amp;amp; exit 1&lt;br /&gt;
&lt;br /&gt;
serverlist=`cat ${serverfile} | sort -n | tr &amp;quot;\n&amp;quot; &amp;quot; &amp;quot;`&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
# -------------------------&lt;br /&gt;
# get the arguments, if any&lt;br /&gt;
# -------------------------&lt;br /&gt;
while getopts &amp;quot;hbvc:&amp;quot; OPT&lt;br /&gt;
do&lt;br /&gt;
    case &amp;quot;$OPT&amp;quot; in&lt;br /&gt;
    h) echo &amp;quot;\nUsage: $0 [-b] [-v] [-h] -c &amp;#039;&amp;lt;command_to_be_executed_remotely&amp;gt;&amp;#039;\n&amp;quot;;&lt;br /&gt;
       exit;&lt;br /&gt;
       ;;&lt;br /&gt;
    b) BACKGROUND=&amp;quot;Y&amp;quot;;&lt;br /&gt;
       ;;&lt;br /&gt;
    v) VERBOSE=&amp;quot;Y&amp;quot;;&lt;br /&gt;
       ;;&lt;br /&gt;
    c) CMMND=$OPTARG;&lt;br /&gt;
       ;;&lt;br /&gt;
    *) echo &amp;quot;\nUsage: $0 [-b] [-v] [-h] -c &amp;#039;&amp;lt;command_to_be_executed_remotely&amp;gt;&amp;#039;\n&amp;quot;;&lt;br /&gt;
       exit;&lt;br /&gt;
       ;;&lt;br /&gt;
    esac&lt;br /&gt;
done&lt;br /&gt;
shift $((OPTIND-1))&lt;br /&gt;
VERBOSE=${VERBOSE:-&amp;quot;N&amp;quot;}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
# --------------------------------&lt;br /&gt;
# check we have required arguments&lt;br /&gt;
# --------------------------------&lt;br /&gt;
[[ -z $CMMND ]] &amp;amp;&amp;amp; echo &amp;quot;Enter command to be executed like this: $0 -c &amp;#039;ls -al&amp;#039;&amp;quot; &amp;amp;&amp;amp; exit 1&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
# ---------------------------------&lt;br /&gt;
# put the thing to be run in a file&lt;br /&gt;
# ---------------------------------&lt;br /&gt;
printf &amp;quot;%s\n&amp;quot; &amp;quot;$CMMND&amp;quot; &amp;gt; /tmp/dosh.$$&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
# ----------------------------&lt;br /&gt;
# loop over the remote servers&lt;br /&gt;
# ----------------------------&lt;br /&gt;
for server in ${serverlist}&lt;br /&gt;
do&lt;br /&gt;
    if [[ &amp;quot;$VERBOSE&amp;quot; == &amp;quot;Y&amp;quot; ]]; then&lt;br /&gt;
        printf &amp;quot;%s\n&amp;quot; ${server} `date +&amp;#039;%d-%b-%Y %H:%M:%S&amp;#039;`&lt;br /&gt;
        printf &amp;quot;%s\n&amp;quot; &amp;quot;------------------------------------&amp;quot;&lt;br /&gt;
        set -x&lt;br /&gt;
    fi&lt;br /&gt;
    scp -q /tmp/dosh.$$ ${server}:/tmp/&lt;br /&gt;
    if [[ &amp;quot;$BACKGROUND&amp;quot; == &amp;quot;Y&amp;quot; ]]; then&lt;br /&gt;
        ssh -n -o BatchMode=yes ${server} &amp;quot;ksh /tmp/dosh.$$; rm -f /tmp/dosh.$$&amp;quot;&amp;gt; /tmp/dosh_${server}.out 2&amp;gt;&amp;amp;1 &amp;amp;&lt;br /&gt;
    else&lt;br /&gt;
        ssh -n -o BatchMode=yes ${server} &amp;quot;ksh /tmp/dosh.$$; rm -f /tmp/dosh.$$&amp;quot;&lt;br /&gt;
    fi&lt;br /&gt;
    set +x&lt;br /&gt;
    [[ &amp;quot;$VERBOSE&amp;quot; == &amp;quot;Y&amp;quot; ]] &amp;amp;&amp;amp; echo&lt;br /&gt;
done&lt;br /&gt;
rm -f /tmp/dosh.$$&lt;br /&gt;
&lt;br /&gt;
[[ &amp;quot;$BACKGROUND&amp;quot; == &amp;quot;Y&amp;quot; ]] &amp;amp;&amp;amp; printf &amp;quot;%s\n&amp;quot; &amp;quot;Type &amp;#039;ls -altr /tmp/dosh*out&amp;#039; to see output from the commands&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===How can a shell script find out what directory it is in?===&lt;br /&gt;
basename $0 does not always give the desired answer (might give &amp;quot;./&amp;quot;!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
DIR=&amp;quot;$(cd &amp;quot;$(dirname &amp;quot;$0&amp;quot;)&amp;quot; &amp;amp;&amp;amp; pwd)&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Array processing===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
array=(1 2 3)&lt;br /&gt;
unset array[2]&lt;br /&gt;
echo ${array[2]}          # null&lt;br /&gt;
indices=(${!array[@]})    # create an array of the indices of &amp;quot;array&amp;quot;&lt;br /&gt;
size=${#indices[@]}       # the size of &amp;quot;array&amp;quot; is the number of indices into it&lt;br /&gt;
size=${#array[@]}         # same&lt;br /&gt;
echo ${array[@]: -1}      # you can use slices to get array elements, -1 is the last one, etc.&lt;br /&gt;
for element in ${array[@]}; do    # iterate over the array without an index&lt;br /&gt;
&lt;br /&gt;
for index in ${indices[@]}        # iterate over the array WITH an index&lt;br /&gt;
do&lt;br /&gt;
    echo &amp;quot;Index: ${index}, Element: ${array[index]}&amp;quot;&lt;br /&gt;
done&lt;br /&gt;
&lt;br /&gt;
for index in ${!array[@]}         # iterate over the array WITH an index, directly&lt;br /&gt;
&lt;br /&gt;
array+=(&amp;quot;new element&amp;quot;)    # append a new element without referring to an index&lt;br /&gt;
((counter++))             # shorter than ((counter=counter+1)) or ((counter+=1))&lt;br /&gt;
if [[ $var == 3 ]]        # you can use the more &amp;quot;natural&amp;quot; comparison operators inside double square brackets&lt;br /&gt;
while [[ $var &amp;lt; 11 ]]     # another example&lt;br /&gt;
echo ${array[${index}-1]  # math inside an array subscript&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Send an email by talking directly to an smtp server===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
telnet smtp.domain.com 25 &amp;lt;&amp;lt;EOTXT&amp;gt;&amp;gt;/tmp/smtp.log&lt;br /&gt;
HELO me.domain.com&lt;br /&gt;
MAIL FROM:&amp;lt;stuart@domain.com&amp;gt;&lt;br /&gt;
RCPT TO:&amp;lt;anne@domain.com&amp;gt;&lt;br /&gt;
DATA&lt;br /&gt;
From: Stuart &amp;lt;stuart@domain.com&amp;gt;&lt;br /&gt;
To: Anne &amp;lt;anne@domain.com&amp;gt;&lt;br /&gt;
Subject: testing smtp email&lt;br /&gt;
&lt;br /&gt;
Hello, this should appear in the body&lt;br /&gt;
.&lt;br /&gt;
QUIT&lt;br /&gt;
EOTXT&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Send an email by talking directly to an smtp server via file descriptor (no telnet! this time), adding authentication===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
&lt;br /&gt;
#&lt;br /&gt;
# mail.sh&lt;br /&gt;
#&lt;br /&gt;
# 2008 - Mike Golvach - eggi@comcast.net&lt;br /&gt;
# 2010 - Rayber&lt;br /&gt;
#&lt;br /&gt;
# Creative Commons Attribution-Noncommercial-Share Alike 3.0 United States License&lt;br /&gt;
#&lt;br /&gt;
&lt;br /&gt;
if [ $# -ne 7 ]&lt;br /&gt;
then&lt;br /&gt;
echo &amp;quot;Usage: $0 FromAdress ToAdress Domain MailServer MailTextFile AuthEmail AuthPass&amp;quot;&lt;br /&gt;
exit 1&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
from=$1&lt;br /&gt;
to=$2&lt;br /&gt;
domain=$3&lt;br /&gt;
mailserver=$4&lt;br /&gt;
mailtext=$5&lt;br /&gt;
authemail=`echo $6|openssl enc -base64|awk &amp;#039;sub(&amp;quot;..$&amp;quot;, &amp;quot;&amp;quot;)&amp;#039;`&lt;br /&gt;
authpass=`echo $7|openssl enc -base64|awk &amp;#039;sub(&amp;quot;..$&amp;quot;, &amp;quot;&amp;quot;)&amp;#039;`&lt;br /&gt;
&lt;br /&gt;
if [ ! -f $mailtext ]&lt;br /&gt;
then&lt;br /&gt;
echo &amp;quot;Cannot find your mail text file. Exiting...&amp;quot;&lt;br /&gt;
exit 1&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
exec 9&amp;lt;&amp;gt;/dev/tcp/$mailserver/25&lt;br /&gt;
echo &amp;quot;HELO $domain&amp;quot; &amp;gt;&amp;amp;9&lt;br /&gt;
read -r temp &amp;lt;&amp;amp;9&lt;br /&gt;
echo &amp;quot;$temp&amp;quot;&lt;br /&gt;
echo &amp;quot;auth login&amp;quot; &amp;gt;&amp;amp;9&lt;br /&gt;
read -r temp &amp;lt;&amp;amp;9&lt;br /&gt;
echo &amp;quot;$authemail&amp;quot; &amp;gt;&amp;amp;9&lt;br /&gt;
read -r temp &amp;lt;&amp;amp;9&lt;br /&gt;
echo &amp;quot;$authpass&amp;quot; &amp;gt;&amp;amp;9&lt;br /&gt;
read -r temp &amp;lt;&amp;amp;9&lt;br /&gt;
echo &amp;quot;Mail From: $from&amp;quot; &amp;gt;&amp;amp;9&lt;br /&gt;
read -r temp &amp;lt;&amp;amp;9&lt;br /&gt;
echo &amp;quot;$temp&amp;quot;&lt;br /&gt;
echo &amp;quot;Rcpt To: $to&amp;quot; &amp;gt;&amp;amp;9&lt;br /&gt;
read -r temp &amp;lt;&amp;amp;9&lt;br /&gt;
echo &amp;quot;$temp&amp;quot;&lt;br /&gt;
echo &amp;quot;Data&amp;quot; &amp;gt;&amp;amp;9&lt;br /&gt;
read -r temp &amp;lt;&amp;amp;9&lt;br /&gt;
echo &amp;quot;$temp&amp;quot;&lt;br /&gt;
cat $mailtext &amp;gt;&amp;amp;9&lt;br /&gt;
echo &amp;quot;.&amp;quot; &amp;gt;&amp;amp;9&lt;br /&gt;
read -r temp &amp;lt;&amp;amp;9&lt;br /&gt;
echo &amp;quot;$temp&amp;quot;&lt;br /&gt;
echo &amp;quot;quit&amp;quot; &amp;gt;&amp;amp;9&lt;br /&gt;
read -r temp &amp;lt;&amp;amp;9&lt;br /&gt;
echo &amp;quot;$temp&amp;quot;&lt;br /&gt;
9&amp;gt;&amp;amp;-&lt;br /&gt;
9&amp;lt;&amp;amp;-&lt;br /&gt;
echo &amp;quot;All Done Sending Email. See above for errors&amp;quot;&lt;br /&gt;
exit 0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== rsync examples===&lt;br /&gt;
Also see [[Distribute files to multiple servers using rsync and ssh]]&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/sh&lt;br /&gt;
ssh  &amp;lt;remote_host&amp;gt; &amp;#039;/bin/mkdir -p /etc /etc/rc.config.d /etc/security /etc/mail&amp;#039;&lt;br /&gt;
rsync --rsync-path /usr/bin/rsync -Liprogtz --out-format=%f%L  /etc/passwd /etc/passwd.post /etc/group /etc/hosts /etc/services /etc/resolv.conf /etc/exclude.rootvg &amp;lt;remote_host&amp;gt;:/etc&lt;br /&gt;
rsync --rsync-path /usr/bin/rsync -Liprogtz --out-format=%f%L  /etc/hosts.allow.xcat &amp;lt;remote_host&amp;gt;:/etc/hosts.allow&lt;br /&gt;
rsync --rsync-path /usr/bin/rsync -Liprogtz --out-format=%f%L  /etc/rc.config.d/sap &amp;lt;remote_host&amp;gt;:/etc/rc.config.d&lt;br /&gt;
rsync --rsync-path /usr/bin/rsync -Liprogtz --out-format=%f%L  /etc/security/group /etc/security/limits /etc/security/login.cfg /etc/security/passwd /etc/security/user &amp;lt;remote_host&amp;gt;:/etc/security&lt;br /&gt;
rsync --rsync-path /usr/bin/rsync -Liprogtz --out-format=%f%L  /etc/mail/sendmail.cf &amp;lt;remote_host&amp;gt;:/etc/mail&lt;br /&gt;
&lt;br /&gt;
rsync -av --progress /home/ibmtools/scripts/oracle/* benouerp07:/home/ibmtools/scripts/oracle/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Handy aliases===&lt;br /&gt;
Strip out comments and blank lines from a file&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alias strip=&amp;#039;grep -Ev &amp;#039;\&amp;#039;&amp;#039;^(#|$)&amp;#039;\&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Does a ps and a grep&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alias psg=&amp;#039;ps -ef | grep -v $$ | grep -i &amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Getting a decent listing of filesystem space available. It is ordered such that the filesystems with no space left are at the end.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
OS=$(uname -s)&lt;br /&gt;
[[ &amp;quot;$OS&amp;quot; == &amp;quot;SunOS&amp;quot; ]] &amp;amp;&amp;amp; alias dfg=&amp;#039;df -h|sed -e &amp;#039;1d&amp;#039;|sort -n -k5|awk &amp;#039;\&amp;#039;&amp;#039; BEGIN {printf(&amp;quot;%-35s%-10s%-10s%-6s%-30s\n&amp;quot;,&amp;quot;Filesystem&amp;quot;,&amp;quot;Total&amp;quot;,&amp;quot;Free&amp;quot;,&amp;quot;%Used&amp;quot;,&amp;quot;Mounted on&amp;quot;)} {printf(&amp;quot;%-35s%-10s%-10s%-6s%-30s\n&amp;quot;,$1,$2,$4,$5,$6)}&amp;#039;\&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
[[ &amp;quot;$OS&amp;quot; == &amp;quot;AIX&amp;quot; ]]   &amp;amp;&amp;amp; alias dfg=&amp;#039;df -g|sed -e &amp;#039;1d&amp;#039;|sort -n -k4|awk &amp;#039;\&amp;#039;&amp;#039; BEGIN {printf(&amp;quot;%-35s%-10s%-10s%-6s%-30s\n&amp;quot;,&amp;quot;Filesystem&amp;quot;,&amp;quot;Total GB&amp;quot;,&amp;quot;Free&amp;quot;,&amp;quot;%Used&amp;quot;,&amp;quot;Mounted on&amp;quot;)} {printf(&amp;quot;%-35s%-10s%-10s%-6s%-30s\n&amp;quot;,$1,$2,$3,$4,$7)}&amp;#039;\&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
A handy way of listing subdirectories and their files&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alias filetree=&amp;quot;find . -print | sed -e &amp;#039;s;[^/]*/;|____;g;s;____|; |;g&amp;#039;&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Watch progress of a copy&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alias cpProgress=&amp;quot;rsync --progress -ravz&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Reboots Linksys router&amp;lt;pre&amp;gt;&lt;br /&gt;
alias rebootlinksys=&amp;quot;curl -u &amp;#039;admin:password&amp;#039; &amp;#039;http://192.168.1.2/setup.cgi?todo=reboot&amp;#039;&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Nice one for bash. Colour codes the prompt depending on the outcome of the previous command&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
bash_prompt_command()&lt;br /&gt;
{&lt;br /&gt;
    RTN=$?&lt;br /&gt;
    prevCmd=$(prevCmd $RTN)&lt;br /&gt;
}&lt;br /&gt;
PROMPT_COMMAND=bash_prompt_command&lt;br /&gt;
prevCmd()&lt;br /&gt;
{&lt;br /&gt;
    if [ $1 == 0 ] ; then&lt;br /&gt;
        echo $GREEN&lt;br /&gt;
    else&lt;br /&gt;
        echo $RED&lt;br /&gt;
    fi&lt;br /&gt;
}&lt;br /&gt;
if [ $(tput colors) -gt 0 ] ; then&lt;br /&gt;
    RED=$(tput setaf 1)&lt;br /&gt;
    GREEN=$(tput setaf 2)&lt;br /&gt;
    RST=$(tput op)&lt;br /&gt;
fi&lt;br /&gt;
export PS1=&amp;quot;\[\e[36m\]\u.\h.\W\[\e[0m\]\[\$prevCmd\]&amp;gt;\[$RST\]&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Mmmm, to be looked into. Executes remote commands on a unix box using curl.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#/bin/sh&lt;br /&gt;
#&lt;br /&gt;
# WAG320N-HACK&lt;br /&gt;
# Ver. 1.0&lt;br /&gt;
# 12/09/2010&lt;br /&gt;
#&lt;br /&gt;
# This program is free software: you can redistribute it and/or modify&lt;br /&gt;
# it under the terms of the GNU General Public License as published by&lt;br /&gt;
# the Free Software Foundation, either version 3 of the License, or&lt;br /&gt;
# (at your option) any later version.&lt;br /&gt;
#&lt;br /&gt;
# This program is distributed in the hope that it will be useful,&lt;br /&gt;
# but WITHOUT ANY WARRANTY; without even the implied warranty of&lt;br /&gt;
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the&lt;br /&gt;
# GNU General Public License for more details.&lt;br /&gt;
#&lt;br /&gt;
# You should have received a copy of the GNU General Public License&lt;br /&gt;
# along with this program.  If not, see &amp;lt;http://www.gnu.org/licenses/&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
# Set username and password in the form of &amp;quot;username:password&amp;quot;&lt;br /&gt;
# example: &amp;quot;admin:admin&amp;quot;&lt;br /&gt;
my_access=&amp;quot;admin:admin&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Parameters test&lt;br /&gt;
if [ -z &amp;quot;$1&amp;quot; ]&lt;br /&gt;
then&lt;br /&gt;
  echo &amp;quot;wag320n-hack.sh: missing remote command&amp;quot;&lt;br /&gt;
  echo &amp;quot;usage: wag320n-hack.sh &amp;lt;remote command&amp;gt;&amp;quot;&lt;br /&gt;
  echo &amp;quot;example: wag320n-hack.sh /bin/ls -la /usr/sbin&amp;quot;&lt;br /&gt;
  echo &amp;quot;Note: always use full path&amp;quot;&lt;br /&gt;
  echo &amp;quot;&amp;quot;&lt;br /&gt;
  echo &amp;quot;wag320n-hack.sh - Ver. 1.0 - 12/09/2010&amp;quot;&lt;br /&gt;
  echo &amp;quot;Licensed under GPL V. 3&amp;quot;&lt;br /&gt;
  echo &amp;quot;&amp;quot;&lt;br /&gt;
  exit 0&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
# Get the command&lt;br /&gt;
my_command=&amp;quot;ping_size=&amp;quot;&amp;#039;$(&amp;#039;&amp;quot;$@&amp;quot;&amp;#039; 1&amp;gt;&amp;amp;2)&amp;#039;&lt;br /&gt;
&lt;br /&gt;
curl -s -G -u &amp;quot;$my_access&amp;quot; --data-urlencode &amp;#039;todo=ping_test&amp;#039; --data-urlencode &amp;#039;this_file=Diagnostics.htm&amp;#039; --data-urlencode &amp;#039;next_file=Ping.htm&amp;#039; --data-urlencode &amp;#039;c4_ping_ipaddr=192.168.1.1&amp;#039; --data-urlencode &amp;#039;ping_timeout=5000&amp;#039; --data-urlencode &amp;#039;ping_interval=1000&amp;#039; --data-urlencode &amp;#039;ping_number=1&amp;#039; --data-urlencode &amp;quot;$my_command&amp;quot; http://192.168.1.1/setup.cgi | sed -e &amp;#039;/HTTP\/1.0 200 OK/q&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===How to configure SSH with public/private keys===&lt;br /&gt;
* [http://www.unixpeople.com/HOWTO/configuring.ssh.html unixpeople.com]&lt;br /&gt;
===Use SSH config file===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Host server10&lt;br /&gt;
  Hostname 1.2.3.4&lt;br /&gt;
  IdentityFile ~/.ssh/id_dsa&lt;br /&gt;
  user foobar&lt;br /&gt;
  Port 30000&lt;br /&gt;
  ForwardX11Trusted yes&lt;br /&gt;
  TCPKeepAlive yes&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
then just connect using&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ssh server10&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===A decent sed tutorial===&lt;br /&gt;
From [http://www.grymoire.com/Unix/Sed.html grymoire.com]&lt;br /&gt;
===A decent korn/bash shell tutorial===&lt;br /&gt;
From [http://www.dartmouth.edu/~rc/classes/ksh/print_pages.shtml dartmouth.edu]&lt;br /&gt;
Reproduced here just in case it disappears!&lt;br /&gt;
[[Advanced shell scripting]]&lt;br /&gt;
&lt;br /&gt;
===trap===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
     Example Handling Traps With ksh - Discussion of the kill command&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
EXAMPLE TEMPLATE:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
PRODUCT:    HP-UX 11iV1 Version B.11.11&lt;br /&gt;
            HP Tru64 V5.1B PK4&lt;br /&gt;
            Sun/Solaris SunOS V5.8&lt;br /&gt;
            Linux 2.6 kernel&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
COMPONENT:  ksh&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
SOURCE:     Philippe Vouters&lt;br /&gt;
            Fontainebleau/France&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
LOW COST HIGH-TECH PRODUCTS:  http://techno-star.fr&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
OVERVIEW:&lt;br /&gt;
&lt;br /&gt;
The ksh script below shows how to eventually handle traps in the situation &lt;br /&gt;
where someone might try to kill a script by killing individual commands run &lt;br /&gt;
by that script or the entire process group a script is running in. The kill &lt;br /&gt;
command (usually a shell builtin) may be used to send a signal to a process &lt;br /&gt;
group (with the -&amp;lt;pid&amp;gt; syntax) or an individual process. The example ksh &lt;br /&gt;
script below runs /bin/sleep as the foreground process, the example ksh &lt;br /&gt;
scripts immediately returns when the /bin/sleep process has terminated. Most &lt;br /&gt;
signals sent to the shell are ignored until after the foreground process &lt;br /&gt;
terminates. This is in order to avoid creating zombie processes. Therefore a &lt;br /&gt;
kill &amp;lt;pid&amp;gt; on the example ksh script waits for the termination of the &lt;br /&gt;
/bin/sleep process.&lt;br /&gt;
&lt;br /&gt;
The status value $? in the trap refers to the exit status of the command to run &lt;br /&gt;
and therefore is the exit status of the /bin/sleep process. The called function &lt;br /&gt;
in the trap handler shows how to correctly examine the effect of the kill &lt;br /&gt;
command on the shell or it&amp;#039;s children.&lt;br /&gt;
&lt;br /&gt;
To examine the value of $? in a trap handler means that you must understand what&lt;br /&gt;
it can be set and how different signals delivered to either the shell or the &lt;br /&gt;
foreground process (or the process group) might affect the value of $?.&lt;br /&gt;
&lt;br /&gt;
The example shell script prints $? using echo but it does not perform tests on &lt;br /&gt;
the value of $?. For a complete solution when attempting to trap signals in a &lt;br /&gt;
shell you would also need code that examined the value of $? after the &lt;br /&gt;
foreground process had completed.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*** CAUTION ***&lt;br /&gt;
&lt;br /&gt;
This sample script has been tested using HP-UX B.11.11, HP Tru64 V5.1B PK4, &lt;br /&gt;
SunOS V5.8 and Fedora Core 4 (homed version of Red Hat Linux).  However, we&lt;br /&gt;
cannot guarantee its effectiveness because of the possibility of error in &lt;br /&gt;
transmitting or implementing it. It is meant to be used as a template for &lt;br /&gt;
writing your own scripts, and may require modification for use on your system. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
SCRIPT NOTES:&lt;br /&gt;
&lt;br /&gt;
To notice that the ksh script and /bin/sleep share the same process group&lt;br /&gt;
identifier (PGID), issue the following commands:&lt;br /&gt;
&lt;br /&gt;
[philippe@victor ~]$ who&lt;br /&gt;
philippe :0           Jan 10 10:16&lt;br /&gt;
philippe pts/1        Jan 10 21:30 (:0.0)&lt;br /&gt;
philippe pts/2        Jan 10 21:30 (:0.0)&lt;br /&gt;
[philippe@victor ~]$ tty&lt;br /&gt;
/dev/pts/1&lt;br /&gt;
[philippe@victor ~]$ ps -j -t pts/2&lt;br /&gt;
  PID  PGID   SID TTY          TIME CMD&lt;br /&gt;
11072 11072 11072 pts/2    00:00:00 bash&lt;br /&gt;
11113 11113 11072 pts/2    00:00:00 ksh&lt;br /&gt;
11116 11113 11072 pts/2    00:00:00 sleep&lt;br /&gt;
&lt;br /&gt;
In this case sending kill -INT -11113 will send SIGINT to the process group &lt;br /&gt;
11113. Both of the ksh and sleep processes are contained within this process &lt;br /&gt;
group.&lt;br /&gt;
&lt;br /&gt;
Important Note:&lt;br /&gt;
&lt;br /&gt;
On HP-UX, you have to $ export UNIX95=1 in order to be able to use the&lt;br /&gt;
-j option of the ps command.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
SCRIPT:&lt;br /&gt;
&lt;br /&gt;
                             COPYRIGHT (C) 2005 BY&lt;br /&gt;
                              HEWLETT-PACKARD COMPANY&lt;br /&gt;
                                ALL RIGHTS RESERVED.&lt;br /&gt;
&lt;br /&gt;
     THIS SOFTWARE IS FURNISHED UNDER A LICENSE AND MAY BE USED AND COPIED&lt;br /&gt;
     ONLY IN ACCORDANCE WITH THE TERMS OF SUCH LICENSE AND WITH THE INCLUSION&lt;br /&gt;
     OF THE ABOVE COPYRIGHT NOTICE.  THIS SOFTWARE OR ANY OTHER COPIES&lt;br /&gt;
     THEREOF MAY NOT BE PROVIDED OR OTHERWISE MADE AVAILABLE TO ANY OTHER&lt;br /&gt;
     PERSON.  NO TITLE TO AND OWNERSHIP OF THE SOFTWARE IS HEREBY TRANSFERRED.&lt;br /&gt;
&lt;br /&gt;
     THE INFORMATION IN THIS SOFTWARE IS SUBJECT TO CHANGE WITHOUT NOTICE AND&lt;br /&gt;
     SHOULD NOT BE CONSTRUED AS A COMMITMENT BY HEWLETT-PACKARD COMPANY.&lt;br /&gt;
&lt;br /&gt;
     HP ASSUMES NO RESPONSIBILITY FOR THE USE OR RELIABILITY OF ITS&lt;br /&gt;
     SOFTWARE ON EQUIPMENT THAT IS NOT SUPPLIED BY HP.&lt;br /&gt;
&lt;br /&gt;
     NO RESPONSIBILITY IS ASSUMED FOR THE USE OR RELIABILITY OF SOFTWARE&lt;br /&gt;
     ON EQUIPMENT THAT IS NOT SUPPLIED BY HEWLETT-PACKARD COMPANY.&lt;br /&gt;
&lt;br /&gt;
     SUPPORT FOR THIS SOFTWARE IS NOT COVERED UNDER ANY HP SOFTWARE&lt;br /&gt;
     PRODUCT SUPPORT CONTRACT, BUT MAY BE PROVIDED UNDER THE TERMS OF THE&lt;br /&gt;
     CONSULTING AGREEMENT UNDER WHICH THIS SOFTWARE WAS DEVELOPED.&lt;br /&gt;
&lt;br /&gt;
#!/bin/ksh&lt;br /&gt;
function handle_signal&lt;br /&gt;
{&lt;br /&gt;
        print -n &amp;quot;pid $$ recieved $2 &amp;quot;&lt;br /&gt;
        if [[ $1 = 0 ]];then&lt;br /&gt;
            print but foreground command ended successfully&lt;br /&gt;
        else&lt;br /&gt;
                if [[ $1 = $3 ]];then&lt;br /&gt;
                    print and so did the last foreground command&lt;br /&gt;
                else&lt;br /&gt;
                    print -n &amp;quot;and the exit status of the last foreground &amp;quot;&lt;br /&gt;
                    print command was $1&lt;br /&gt;
                fi&lt;br /&gt;
        fi&lt;br /&gt;
        # Kill our process group and then ourselves with SIGTERM, giving a &lt;br /&gt;
        # pid of 0 sends the signal to our process group. Killing the process&lt;br /&gt;
        # group should kill us as well, this assumes that SIGTERM is not &lt;br /&gt;
        # handled by any process in the process group.&lt;br /&gt;
        #&lt;br /&gt;
        # This code could be replaced with an exit with an exit value that&lt;br /&gt;
        # would indicate what the problem was to the caller. That is replace &lt;br /&gt;
        # these two lines with:&lt;br /&gt;
        #&lt;br /&gt;
        # exit $3&lt;br /&gt;
        #&lt;br /&gt;
        # or a specific exit code could be used.&lt;br /&gt;
        #&lt;br /&gt;
        kill -TERM 0&lt;br /&gt;
        kill -TERM $$&lt;br /&gt;
        }&lt;br /&gt;
OS=$(uname -a | awk &amp;#039;{print $1}&amp;#039;)&lt;br /&gt;
if [[ &amp;quot;$OS&amp;quot; = &amp;quot;Linux&amp;quot; ]]; then&lt;br /&gt;
    offset=256&lt;br /&gt;
elif [[ (&amp;quot;$OS&amp;quot; = &amp;quot;HP-UX&amp;quot;) || &lt;br /&gt;
        (&amp;quot;$OS&amp;quot; = &amp;quot;SunOS&amp;quot;) || &lt;br /&gt;
        (&amp;quot;$OS&amp;quot; = &amp;quot;OSF1&amp;quot;) ]]; then&lt;br /&gt;
   offset=128&lt;br /&gt;
fi&lt;br /&gt;
trap &amp;#039;RC=$?; handle_signal $RC SIGINT $offset+2&amp;#039; INT&lt;br /&gt;
trap &amp;#039;RC=$?; handle_signal $RC SIGQUIT $offset+3&amp;#039; QUIT&lt;br /&gt;
/bin/sleep 20&lt;br /&gt;
echo $?&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===DNS not working===&lt;br /&gt;
Ping to an IP address works&lt;br /&gt;
 ping 74.125.136.103&lt;br /&gt;
but this doesn&amp;#039;t&lt;br /&gt;
 ping www.google.com&lt;br /&gt;
&lt;br /&gt;
Check resolv.conf&lt;br /&gt;
 cat /etc/resolv.conf&lt;br /&gt;
 nameserver 95.130.132.17&lt;br /&gt;
 nameserver 95.130.132.18&lt;br /&gt;
I had changed internet provider and forgot to update this. Just to set it to the router address and let that do the resolution&lt;br /&gt;
 nameserver 192.168.1.1&lt;br /&gt;
&lt;br /&gt;
===File descriptors===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
exec 3&amp;lt;&amp;gt; /tmp/foo  #open fd 3 for r/w&lt;br /&gt;
echo &amp;quot;test&amp;quot; &amp;gt;&amp;amp;3&lt;br /&gt;
exec 3&amp;gt;&amp;amp;- #close fd 3.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
exec 3&amp;lt;&amp;gt; myfile.txt&lt;br /&gt;
while read line &amp;lt;&amp;amp;3&lt;br /&gt;
do {&lt;br /&gt;
  echo &amp;quot;$line&amp;quot;&lt;br /&gt;
  (( Lines++ ));                   #  Incremented values of this variable&lt;br /&gt;
                                   #+ accessible outside loop.&lt;br /&gt;
                                   #  No subshell, no problem.&lt;br /&gt;
}&lt;br /&gt;
done&lt;br /&gt;
exec 3&amp;gt;&amp;amp;-&lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;Number of lines read = $Lines&amp;quot;     # 8&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Mmm. See our output and also tee it to a log file!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
&lt;br /&gt;
echo hello&lt;br /&gt;
&lt;br /&gt;
if test -t 1; then&lt;br /&gt;
    # Stdout is a terminal.&lt;br /&gt;
    exec &amp;gt;log&lt;br /&gt;
else&lt;br /&gt;
    # Stdout is not a terminal.&lt;br /&gt;
    npipe=/tmp/$$.tmp&lt;br /&gt;
    trap &amp;quot;rm -f $npipe&amp;quot; EXIT&lt;br /&gt;
    mknod $npipe p&lt;br /&gt;
    tee &amp;lt;$npipe log &amp;amp;&lt;br /&gt;
    exec 1&amp;gt;&amp;amp;-&lt;br /&gt;
    exec 1&amp;gt;$npipe&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
echo goodbye&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Create new image with kvm===&lt;br /&gt;
Ref: http://www.cyberciti.biz/faq/kvm-virtualization-in-redhat-centos-scientific-linux-6/&amp;lt;br /&amp;gt;&lt;br /&gt;
Build an empty space for a CentOS virtual machine&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
qemu-img create -f qcow2 centos.img 12G&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Tried creating image with&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo virt-install -n CentOS --description &amp;quot;Trying out CentOS&amp;quot; --ram=1024 --vcpus=1 --cpu host --hvm --cdrom /home/bey9at77/Downloads/c6-x86_64-20130910-1.qcow2 --graphics vnc --disk path=/var/lib/libvirt/images/centos.img,bus=virtio,size=10&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
gives error&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Starting install...&lt;br /&gt;
Allocating &amp;#039;centos.img&amp;#039;                                                                                                                                                                                               |  10 GB     00:00     &lt;br /&gt;
ERROR    internal error Process exited while reading console log output: char device redirected to /dev/pts/1&lt;br /&gt;
qemu-kvm: -drive file=/home/bey9at77/Downloads/c6-x86_64-20130910-1.qcow2.bz2,if=none,media=cdrom,id=drive-ide0-1-0,readonly=on,format=raw: could not open disk image /home/bey9at77/Downloads/c6-x86_64-20130910-1.qcow2: Permission denied&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===rpm / yum commands===&lt;br /&gt;
====Install an RPM Package====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rpm -ivh pidgin-2.7.9-5.el6.2.i686.rpm&lt;br /&gt;
&lt;br /&gt;
-i - install&lt;br /&gt;
-v - verbose&lt;br /&gt;
-h - print progress hashes&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Check dependencies of RPM Package before Installing====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rpm -qpR BitTorrent-5.2.2-1-Python2.4.noarch.rpm&lt;br /&gt;
&lt;br /&gt;
-q - query&lt;br /&gt;
-p - list package capabilities&lt;br /&gt;
-R - list dependent package capabilities&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Install RPM Package with all dependencies====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
yum install BitTorrent-5.2.2-1-Python2.4.noarch.rpm&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Install RPM Package with all dependencies (when RPM has been downloaded to local machine)====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
yum localinstall BitTorrent-5.2.2-1-Python2.4.noarch.rpm&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Force Install a RPM Package without dependencies====&lt;br /&gt;
Package will not work if dependencies are required&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rpm -ivh --nodeps BitTorrent-5.2.2-1-Python2.4.noarch.rpm&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Check an Installed RPM Package====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rpm -q BitTorrent&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====List all files of an installed RPM package====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rpm -ql BitTorrent&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====List All Installed RPM Packages====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rpm -qa&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Query information about an installed RPM package====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rpm -qi vsftpd&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Query information about a not yet installed RPM package====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rpm -qip sqlbuddy-1.3.3-1.noarch.rpm&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====(Forcibly) Remove an RPM Package====&lt;br /&gt;
Use package name (as seen in -qi above), not full name&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rpm -ev (--nodeps) vsftpd&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Query a file that was installed as part of an RPM Package (which package contained this file)====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rpm -qf /usr/bin/htpasswd&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Verify an RPM package====&lt;br /&gt;
Compares information of installed files of the package against the rpm database&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rpm -Vp sqlbuddy-1.3.3-1.noarch.rpm&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Rebuild corrupted RPM database====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cd /var/lib&lt;br /&gt;
rm __db*&lt;br /&gt;
rpm --rebuilddb&lt;br /&gt;
rpmdb_verify Packages&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Install rpmforge repository===&lt;br /&gt;
* Download rpmforge-release-0.5.3-1.el6.rf.x86_64.rpm&lt;br /&gt;
* Import the key&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo rpm --import http://apt.sw.be/RPM-GPG-KEY.dag.txt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Install the repository&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo rpm -i rpmforge-release-0.5.3-1.el6.rf.x86_64.rpm&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Check the installation&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rpm -K rpmforge-release-0.5.3-1.el6.rf.x86_64.rpm&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Test it&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo yum install terminator&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Install rpmfusion repository===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
su -c &amp;#039;yum localinstall --nogpgcheck http://download1.rpmfusion.org/free/el/updates/6/i386/rpmfusion-free-release-6-1.noarch.rpm http://download1.rpmfusion.org/nonfree/el/updates/6/i386/rpmfusion-nonfree-release-6-1.noarch.rpm&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===config file for yum===&lt;br /&gt;
Checkout this file for global yum config&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/etc/sysconfig/yum-cron-background&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Setup Oracle Enterprise Linux (RedHat) with yum server===&lt;br /&gt;
You need to download the yum .repo file from the server, as per the steps below. After this, you need to enable a flag in the .repo file as per your operating system version. Having done these two steps, when you run yum install &amp;lt;pkgname&amp;gt; command on your linux box, the Oracle&amp;#039;s yum server will be scanned, the dependent &amp;amp; the relevant rpm&amp;#039;s will be download and installed for you.&amp;lt;br /&amp;gt;&lt;br /&gt;
 cd /etc/yum.repos.d&lt;br /&gt;
To download files here&lt;br /&gt;
 wget http://public-yum.oracle.com/public-yum-el5.repo&lt;br /&gt;
&lt;br /&gt;
A file named public-yum-el5.repo will be created in your directory&amp;lt;br /&amp;gt;&lt;br /&gt;
Edit this file and enter enabled=1 against the operating systems which is relevant to you&lt;br /&gt;
 vi public-yum-el5.repo&lt;br /&gt;
&lt;br /&gt;
Next run the yum command&lt;br /&gt;
 yum install package-name&lt;br /&gt;
&lt;br /&gt;
===To change to static IP address (Raspberry Pi)===&lt;br /&gt;
As root:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cd /etc/networks&lt;br /&gt;
vi interfaces&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
replace the line “iface eth0 inet dhcp” with&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
iface eth0 inet static&lt;br /&gt;
address 192.168.1.100&lt;br /&gt;
netmask 255.255.255.0&lt;br /&gt;
gateway 192.168.1.1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You should also take a look at the file /etc/resolv.conf and check it has a nameserver entry (probably pointing at your default gateway) or direct to your ISP name servers.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
nameserver 192.168.1.1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Troubleshoot wireless network problems===&lt;br /&gt;
* [https://www.blackmoreops.com/2014/09/18/connect-to-wifi-network-from-command-line-in-linux/ connect to wifi network from command-line in linux - from blackmoreops.com]&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Short summary of all the things you need to do in just few lines&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
root@kali:~# iw dev&lt;br /&gt;
root@kali:~# ip link set wlan0 up&lt;br /&gt;
root@kali:~# iw wlan0 scan&lt;br /&gt;
root@kali:~# wpa_passphrase blackMOREOps &amp;gt;&amp;gt; /etc/wpa_supplicant.conf&lt;br /&gt;
root@kali:~# wpa_supplicant -i wlan0 -c /etc/wpa_supplicant.conf&lt;br /&gt;
root@kali:~# iw wlan0 link&lt;br /&gt;
root@kali:~# dhclient wlan0&lt;br /&gt;
root@kali:~# ping 8.8.8.8&lt;br /&gt;
(Where wlan0 is wifi adapter and blackMOREOps is SSID)&lt;br /&gt;
(Add Routing manually)&lt;br /&gt;
root@kali:~# ip route add default via 10.0.0.138 dev wlan0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===To change to static IP address (Redhat/CentOS)===&lt;br /&gt;
As root:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
vi /etc/sysconfig/network-scripts/ifcfg-eth0&lt;br /&gt;
DEVICE=eth0&lt;br /&gt;
BOOTPROTO=STATIC&lt;br /&gt;
IPADDR=192.168.1.111&lt;br /&gt;
NETMASK=255.255.255.0&lt;br /&gt;
GATEWAY=192.168.1.1&lt;br /&gt;
ONBOOT=yes&lt;br /&gt;
DNS1=8.8.8.8&lt;br /&gt;
DNS2=8.8.4.4&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Resrart the network interface&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/etc/init.d/network stop&lt;br /&gt;
/etc/init.d/network start&lt;br /&gt;
or&lt;br /&gt;
service network restart&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Check name server entry in resolv.conf&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
vi /etc/resolv.conf&lt;br /&gt;
nameserver 192.168.1.1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Enable processes / services to start at boot time===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo chkconfig httpd on&lt;br /&gt;
sudo chkconfig mysqld on&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Run a command on lots of servers in parallel===&lt;br /&gt;
This is a damn fine AIX utility - part of the CSM Distributed Shell.&lt;br /&gt;
 dsh -a &amp;quot;ls -al /etc/apache2/*conf&amp;quot;&lt;br /&gt;
will list the Apache configuration file on all reachable servers (nodes)&lt;br /&gt;
===Download a gzip file and pipe it into tar===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cd ~ &amp;amp;&amp;amp; wget -O - &amp;quot;https://www.dropbox.com/download?plat=lnx.x86_64&amp;quot; | tar xzf -&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Check in a script to make sure it is run only by root===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
RUID=`/usr/bin/id|$AWK -F\( &amp;#039;{print $1}&amp;#039;|$AWK -F\= &amp;#039;{print $2}&amp;#039;`&lt;br /&gt;
if [ ${RUID} != &amp;quot;0&amp;quot; ];then&lt;br /&gt;
   $ECHO &amp;quot;This script must be executed as root&amp;quot;&lt;br /&gt;
   exit 1&lt;br /&gt;
fi&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Set terminal to use Backspace key to erase previous character instead of Control-H===&lt;br /&gt;
Been looking for this for a long time.&amp;lt;br /&amp;gt;&lt;br /&gt;
You can put:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
stty erase &amp;lt;CTRL-V&amp;gt;&amp;lt;Backspace key&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
in your .profile but this will be ruined if you do a copy/paste into another file.&amp;lt;br /&amp;gt;&lt;br /&gt;
I wanted a way of doing this without entering the control character in the .profile. Finally stumbled upon it. And it&amp;#039;s so simple. Just escape the caret!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
stty erase \^?&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Put this in the .profile. It&amp;#039;s copy/pastable and it works!&amp;lt;br /&amp;gt;&lt;br /&gt;
If you want CTRL-H to be your erase character, just do this:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
stty erase \^H&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Play with the terminal settings and reset them again either side of requesting a password===&lt;br /&gt;
The -g option of stty gives a compact list of all the settings or the terminal and can be used as input to stty&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
OLDCONFIG=`stty -g`          # save terminal configuration&lt;br /&gt;
stty -echo                   # turn character echoing off&lt;br /&gt;
echo &amp;quot;Enter password: \c&amp;quot;&lt;br /&gt;
read PASSWD                  # get the password&lt;br /&gt;
stty $OLDCONFIG              # restore terminal configuration&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Reset terminal to &amp;quot;sane&amp;quot; characteristics===&lt;br /&gt;
If you&amp;#039;ve done a cat of a binary file or something else weird and your terminal is left in a mess, the following key sequence should bring it back to normal&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;CTRL-J&amp;gt;stty sane&amp;lt;CTRL-J&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Install OpenOffice on RedHat Enterprise when yum install doesn&amp;#039;t!===&lt;br /&gt;
Download Package&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
wget http://sourceforge.net/projects/openofficeorg.mirror/files/4.0.1/binaries/en-US/Apache_OpenOffice_4.0.1_Linux_x86-64_install-rpm_en-US.tar.gz/download -O Apache_OpenOffice_4.0.1_Linux_x86-64_install-rpm_en-US.tar.gz&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Change to root&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo su -&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Remove the old stuff&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
yum remove openoffice* libreoffice*&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Extract Package&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
tar -xvf Apache_OpenOffice_4.0.1*&lt;br /&gt;
cd en-US&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Install Package and exit root&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rpm -Uvh RPMS/*.rpm RPMS/desktop-integration/openoffice4.0-redhat-*.rpm&lt;br /&gt;
exit&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Start it&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
openoffice4&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===What does this do?===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
while IFS= read -r line; do&lt;br /&gt;
    echo &amp;quot;[$(date &amp;quot;+%F %T&amp;quot;)] - $line&amp;quot;&lt;br /&gt;
done &amp;lt; &amp;lt;(iwevent)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
while IFS= read -r line; do&lt;br /&gt;
    printf &amp;quot;%s\n%s\n&amp;quot; &amp;quot;$line&amp;quot; &amp;quot;Yohooo! One more package.&amp;quot;&lt;br /&gt;
done &amp;lt; &amp;lt;(tcpdump -i any -nS)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===List of Special Characters and what they mean===&lt;br /&gt;
From [http://www.grymoire.com/Unix/Quote.html Bruce Barnett]&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Character	Where	Meaning&lt;br /&gt;
&amp;lt;RETURN&amp;gt;	csh, sh	Execute command&lt;br /&gt;
#	csh, sh, ASCII files	Start a comment&lt;br /&gt;
&amp;lt;SPACE&amp;gt;	csh, sh	Argument separator&lt;br /&gt;
`	csh, sh	Command substitution&lt;br /&gt;
&amp;quot;	csh, sh	Weak Quotes&lt;br /&gt;
&amp;#039;	csh, sh	Strong Quotes&lt;br /&gt;
\	csh, sh	Single Character Quote&lt;br /&gt;
variable	sh, csh	Variable&lt;br /&gt;
variable	csh, sh	Same as variable&lt;br /&gt;
|	csh, sh	Pipe character&lt;br /&gt;
^	sh	Pipe Character&lt;br /&gt;
&amp;amp;	csh, sh	Run program in background&lt;br /&gt;
?	csh, sh	Match one character&lt;br /&gt;
*	csh, sh	Match any number of characters&lt;br /&gt;
;	csh, sh	Command separator&lt;br /&gt;
;;	sh	End of Case statement&lt;br /&gt;
~	csh	Home Directory&lt;br /&gt;
~user	csh	User&amp;#039;s Home Directory&lt;br /&gt;
!	csh	History of Commands&lt;br /&gt;
-	Programs	Start of optional argument&lt;br /&gt;
$#	csh, sh	Number of arguments to script&lt;br /&gt;
$*	csh, sh	Arguments to script&lt;br /&gt;
$@	sh	Original arguments to script&lt;br /&gt;
$-	sh	Flags passed to shell&lt;br /&gt;
$?	sh	Status of previous command&lt;br /&gt;
$$	sh	Process identification number&lt;br /&gt;
$!	sh	PID of last background job&lt;br /&gt;
&amp;amp;&amp;amp;	sh	Short-circuit AND&lt;br /&gt;
||	sh	Short-circuit OR&lt;br /&gt;
.	csh, sh	Typ. filename extension&lt;br /&gt;
.	sh	Source a file and execute as command&lt;br /&gt;
:	sh	Nothing command&lt;br /&gt;
:	sh	Separates Values in environment variables&lt;br /&gt;
:	csh	Variable modifier&lt;br /&gt;
Character	Where	Meaning&lt;br /&gt;
[ ]	csh, sh	Match range of characters&lt;br /&gt;
[ ]	sh	Test&lt;br /&gt;
%job	csh	Identifies job Number&lt;br /&gt;
(cmd;cmd)	csh. sh	Runs cmd;cmd as a sub-shell&lt;br /&gt;
{ }	csh	In-line expansions&lt;br /&gt;
{cmd;cmd }	sh	Like (cmd;cmd ) without a subshell&lt;br /&gt;
&amp;gt;ofile	csh, sh	Standard output&lt;br /&gt;
&amp;gt;&amp;gt;ofile	csh, sh	Append to standard output&lt;br /&gt;
&amp;lt;ifile	csh, sh	Standard Input&lt;br /&gt;
&amp;lt;&amp;lt;word	csh, sh	Read until word, substitute variables&lt;br /&gt;
&amp;lt;&amp;lt;\word	csh, sh	Read until word, no substitution&lt;br /&gt;
&amp;lt;&amp;lt;-word	sh	Read until word, ignoring TABS&lt;br /&gt;
&amp;gt;&amp;gt;!file	csh	Append to file, ignore error if not there&lt;br /&gt;
&amp;gt;!file	csh	Output to new file, ignore error if not there&lt;br /&gt;
&amp;gt;&amp;amp;file	csh	Send standard &amp;amp; error output to file&lt;br /&gt;
&amp;lt;&amp;amp;digit	sh	Switch Standard Input to file&lt;br /&gt;
&amp;lt;&amp;amp;-	sh	Close Standard Input&lt;br /&gt;
&amp;gt;&amp;amp;digit	sh	Switch Standard Output to file&lt;br /&gt;
&amp;gt;&amp;amp;-	sh	Close Standard Output&lt;br /&gt;
digit1&amp;lt;&amp;amp;digit2	sh	Connect digit2 to digit1&lt;br /&gt;
digit&amp;lt;&amp;amp;-	sh	Close file digit&lt;br /&gt;
digit2&amp;gt;&amp;amp;digit1	sh	Connect digit2 to digit1&lt;br /&gt;
digit&amp;gt;&amp;amp;-	sh	Close file digit&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Stuart</name></author>	</entry>

	<entry>
		<id>https://mailnest.com/dbawiki/index.php?title=Unix/Linux&amp;diff=3401</id>
		<title>Unix/Linux</title>
		<link rel="alternate" type="text/html" href="https://mailnest.com/dbawiki/index.php?title=Unix/Linux&amp;diff=3401"/>
				<updated>2018-12-06T00:13:59Z</updated>
		
		<summary type="html">&lt;p&gt;Stuart: /* Configure maildrop */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;* [http://hyperpolyglot.org/unix-shells#var-expansion Good shell comparison including variable expansion - hyperpolyglot.org]&lt;br /&gt;
* [http://pubs.opengroup.org/onlinepubs/9699919799/utilities/toc.html Shell coding standards - opengroup.org]&lt;br /&gt;
* [http://aix4admins.blogspot.be aix4admins]&lt;br /&gt;
* [http://linuxgazette.net/issue55/okopnik.html The Deep, Dark Secrets of Bash]&lt;br /&gt;
* [http://www.speakeasy.org/~arkay/216-7.4KshFunctions.html Korn Shell Functions]&lt;br /&gt;
* [http://www.grymoire.com/Unix/AwkRef.html AWK reference from Bruce Barnett]&lt;br /&gt;
* [http://www.catonmat.net/blog/wp-content/uploads/2008/09/awk1line.txt HANDY AWK ONE-LINERS]&lt;br /&gt;
* [http://www.grymoire.com/unix/Quote.html Unix quoting from from Bruce Barnett (grymoire)]&lt;br /&gt;
* [http://www.mpi-inf.mpg.de/departments/rg1/teaching/unixffb-ss98/quoting-guide.html Another excellent quoting tutorial]&lt;br /&gt;
* [http://aix4admins.blogspot.be/2015/02/snapshot-fs-snapshot-snapshot-is-state.html AIX snapshot technology]&lt;br /&gt;
* [[RaspberryPi]]&lt;br /&gt;
* [[SSH]]&lt;br /&gt;
* [http://www.anattatechnologies.com/q/2013/04/multiuser-screen/ Screen sharing from Unix using screen]&lt;br /&gt;
* [https://robots.thoughtbot.com/a-tmux-crash-course Screen sharing from Unix using tmux]&lt;br /&gt;
* [http://www.csb.yale.edu/userguides/wordprocess/vi-summary.html Handy ex and vi reference]&lt;br /&gt;
* [[Fedora install for my own purposes]]&lt;br /&gt;
&lt;br /&gt;
===How to automatically download and process email attachments from Gmail===&lt;br /&gt;
==== Useful references====&lt;br /&gt;
* [http://www.courier-mta.org/maildrop/maildrop.html maildrop]&lt;br /&gt;
* [http://www.wonkity.com/~wblock/docs/html/maildrop.html Using maildrop As A Mail Delivery Agent (MDA)]&lt;br /&gt;
* [http://manpages.ubuntu.com/manpages/trusty/man7/maildropex.7.html .mailfilter examples]&lt;br /&gt;
* [https://www.axllent.org/docs/view/gmail-pop3-with-fetchmail/ Setting up fetchmail with Gmail]&lt;br /&gt;
* [https://www.linode.com/docs/email/clients/using-fetchmail-to-retrieve-email/ Using Fetchmail to Retrieve Email]&lt;br /&gt;
&lt;br /&gt;
Eventually, after months of trying different things, came up with this combination of tools that worked very well.&lt;br /&gt;
====Install tools====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo dnf -y install fetchmail maildrop uudeview openssl&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Set Gmail account up for POP and disable IMAP&lt;br /&gt;
====Configure fetchmail====&lt;br /&gt;
This is the part that talks to Gmail and downloads the emails to the local machine.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
vi ~/.fetchmailrc&lt;br /&gt;
&lt;br /&gt;
set postmaster &amp;quot;&amp;lt;username&amp;gt;&amp;quot;&lt;br /&gt;
#set daemon 600&lt;br /&gt;
poll pop.gmail.com with proto POP3&lt;br /&gt;
    user &amp;quot;account@gmail.com&amp;quot; there with password &amp;#039;&amp;lt;password&amp;gt;&amp;#039; is &amp;lt;username&amp;gt; here options ssl nokeep&lt;br /&gt;
    mda &amp;quot;/usr/bin/maildrop .mailfilter&amp;quot;&lt;br /&gt;
#    sslcertfile /etc/ssl/certs/ca-bundle.crt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
If fetchmail complains about ssl certificates, try specifying wherein is with the sslcertfile line&lt;br /&gt;
==== Configure maildrop====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
maildirmake maildrop&lt;br /&gt;
maildirmake backup&lt;br /&gt;
&lt;br /&gt;
vi ~/.mailfilter&lt;br /&gt;
&lt;br /&gt;
LOGFILE = &amp;quot;/home/dbahawk/maildrop/maildrop.log&amp;quot;&lt;br /&gt;
DEFAULT=&amp;quot;$HOME/maildrop&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# keep a copy&lt;br /&gt;
cc backup&lt;br /&gt;
`cd backup/new &amp;amp;&amp;amp; rm -f dummy \`ls -t | sed -e 1,50d\``&lt;br /&gt;
&lt;br /&gt;
if (/^To:.*getmail@...\.dnsalias\.org$/)&lt;br /&gt;
   {&lt;br /&gt;
        to Maildir/getmail/&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
#if (/^To:.*dbahawk/)&lt;br /&gt;
#   {&lt;br /&gt;
#        to maildrop&lt;br /&gt;
#   }&lt;br /&gt;
&lt;br /&gt;
if (/^To:.*dbahawk/)&lt;br /&gt;
    dotlock &amp;quot;auto.lock&amp;quot; {&lt;br /&gt;
    to &amp;quot;|uudeview -c -i&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Not really sure why this filter is not working properly. The cc works but the To: check doesn&amp;#039;t. So I have a shell that runs separately to process the emails in the backup mail directory.&lt;br /&gt;
&lt;br /&gt;
====uudeview====&lt;br /&gt;
This is a clever program that can extract attachments from emails and put them in a directory of you choosing.&amp;lt;br /&amp;gt;&lt;br /&gt;
This shell runs from cron at regular intervals to run the whole process&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/usr/bin/ksh&lt;br /&gt;
&lt;br /&gt;
# fetch any new mail from Gmail (uses .fetchmailrc)&lt;br /&gt;
# fetchmail log is $HOME/maildrop/maildrop.log&lt;br /&gt;
fetchmail -d0&lt;br /&gt;
&lt;br /&gt;
# fetchmail uses maildrop as mda (uses .mailfilter) to save messages to a maildir.&lt;br /&gt;
# this is not working correctly but still copies the messages to backup&lt;br /&gt;
&lt;br /&gt;
# pull out the attachments and send them to the incoming directory for the collector to process when it wakes up&lt;br /&gt;
uudeview -c -i -p ~/Downloads/dbahawk_forward backup/new/*&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Use sed to repeat characters===&lt;br /&gt;
echo an &amp;#039;=&amp;#039; sign then use the loop feature of sed to run round a loop a further 79 times replacing what you&amp;#039;ve got with the same thing plus and extra one!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
echo &amp;quot;=&amp;quot; | sed -e :a -e &amp;#039;s/^=\{1,79\}$/&amp;amp;=/;ta&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Convert between lower and upper case using ansi standard===&lt;br /&gt;
This way should be portable and give predictable results&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
LOWER_SID=$(echo &amp;quot;${SID}&amp;quot; | tr &amp;#039;[:upper:]&amp;#039; &amp;#039;[:lower:]&amp;#039;)&lt;br /&gt;
UPPER_SID=$(echo &amp;quot;${SID}&amp;quot; | tr &amp;#039;[:lower:]&amp;#039; &amp;#039;[:upper:]&amp;#039;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Use sed to delete the first line of a file or command output printing from the second line onwards===&lt;br /&gt;
Actually deceptively simple. Example remove the header from df output.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
df -k | sed 1d&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
As a useful extension, suppose TO_DATA_DIR contains multiple directories, this will total the free space for all relevant filesystems&amp;lt;br /&amp;gt;&lt;br /&gt;
This one is specific to AIX, for other Unixes and Linux, use $4 instead of $3.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SPACE_AVAILABLE=$(df -k $TO_DATA_DIR | sed 1d | awk &amp;#039;BEGIN {i=0} {i=i+$3} END {print i}&amp;#039;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Use sed to munge a controlfile into submission!===&lt;br /&gt;
* delete comment lines&lt;br /&gt;
* delete all lines after the one starting with a semicolon&lt;br /&gt;
* delete all blank lines&lt;br /&gt;
* change reuse to set&lt;br /&gt;
* change archivelog (with word boundaries) to noarchivelog&lt;br /&gt;
* change old sid to new sid&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sqlplus -s / as sysdba&amp;lt;&amp;lt;&amp;#039;EOSQL&amp;#039; &amp;gt;/dev/null&lt;br /&gt;
alter database backup controlfile to trace as &amp;#039;/tmp/regenerate_controlfile.sql&amp;#039; reuse resetlogs;&lt;br /&gt;
EOSQL&lt;br /&gt;
OLDSID=&amp;#039;PROD&amp;#039;&lt;br /&gt;
NEWSID=&amp;#039;TEST&amp;#039;&lt;br /&gt;
sed  -e &amp;#039;/^--/d&amp;#039; -e &amp;#039;/^\;/q&amp;#039; -e &amp;#039;/^ *$/d&amp;#039; -e &amp;#039;s/REUSE/SET/&amp;#039; -e &amp;#039;s/\&amp;lt;ARCHIVELOG\&amp;gt;/NOARCHIVELOG/&amp;#039; -e &amp;#039;s/\&amp;quot;&amp;#039;${OLDSID}&amp;#039;\&amp;quot;/\&amp;quot;&amp;#039;${NEWSID}&amp;#039;\&amp;quot;/&amp;#039; /tmp/regenerate_controlfile.sql&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Find all files where a certain text does not exist===&lt;br /&gt;
Mostly we want to search for files containing a particular string but how to find those files that do not contain some text.&amp;lt;br /&amp;gt;&lt;br /&gt;
Using xargs instead of -exec forces the filename to be printed. -H should do this but doesn&amp;#039;t seem to in this case.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
find . -name &amp;quot;*cfg&amp;quot; | xargs grep -H -c TO_CV_HOST {} \; | grep &amp;#039;:0$&amp;#039; | cut -d: -f1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Use tar and gzip to copy files more efficiently across network between hosts===&lt;br /&gt;
From the destination server, this will connect to the source, tar up each file and pull it back to the current server&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ssh oracle@hn5211 &amp;quot;cd /oracle/ora_data4/iten3/ &amp;amp;&amp;amp; tar -cf - . | gzip &amp;quot; | ( cd /oracle/ora_data2/iten/ &amp;amp;&amp;amp; gunzip -c | tar -xvf - . )&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===double hash and double percent in shell variables to trim off characters from variables===&lt;br /&gt;
&amp;lt;nowiki&amp;gt;#&amp;lt;/nowiki&amp;gt;  - trims everything from the start of line till the FIRST occurrence of following character (abstemious) :-)&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;nowiki&amp;gt;##&amp;lt;/nowiki&amp;gt; - trims everything from the start of line till the LAST occurrence of following character (greedy)&amp;lt;br /&amp;gt;&lt;br /&gt;
%  - trims everything from the end of line backwards till the FIRST occurrence of following character (abstemious)&amp;lt;br /&amp;gt;&lt;br /&gt;
%% - trims everything from the end of line backwards till the LAST occurrence of following character (greedy)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
FILENAME=&amp;quot;/home/bey9at77/hello.txt&amp;quot;&lt;br /&gt;
FILE_STUB1=${FILENAME##*/}&lt;br /&gt;
FILE_STUB=${FILE_STUB1%.*}&lt;br /&gt;
echo $FILE_STUB&lt;br /&gt;
hello&lt;br /&gt;
FILE_EXT=${FILENAME##*.}&lt;br /&gt;
echo $FILE_EXT&lt;br /&gt;
txt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;nowiki&amp;gt;#&amp;lt;/nowiki&amp;gt; - remove prefix reluctantly&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;nowiki&amp;gt;##&amp;lt;/nowiki&amp;gt; - remove prefix greedily&amp;lt;br /&amp;gt;&lt;br /&gt;
% - remove suffix reluctantly&amp;lt;br /&amp;gt;&lt;br /&gt;
%% - remove suffix greedily&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
words=&amp;quot;do.re.mi&amp;quot;&lt;br /&gt;
&lt;br /&gt;
echo ${words#*.}&lt;br /&gt;
&lt;br /&gt;
echo ${words##*.}&lt;br /&gt;
&lt;br /&gt;
echo ${words%.*}&lt;br /&gt;
&lt;br /&gt;
echo ${words%%.*}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===The best shell script ever. An example of how scripting should be done===&lt;br /&gt;
It was written by someone at Oracle. Unfortunately (s)he did not put any author comment in it. Also unfortunately I cannot show it here as it is protected behind Oracles support website.&amp;lt;br /&amp;gt;&lt;br /&gt;
If you have an Oracle Metalink id, you can get the complete script [https://support.oracle.com/epmos/faces/DocumentDisplay?id=949322.1 here]&amp;lt;br /&amp;gt;&lt;br /&gt;
Here is a snippet of a function that demonstrates proper commenting and a very good style.&amp;lt;br &amp;gt;&lt;br /&gt;
The script is called physru.sh and upgrades an Oracle database in a rolling upgrade fashion by using a physical standby.&amp;lt;br /&amp;gt;&lt;br /&gt;
There are 4500 lines in the full script but it is so easy to read and understand because of the way it&amp;#039;s written, it&amp;#039;s like a breath of fresh air. Well done whoever you are!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
###############################################################################&lt;br /&gt;
# NAME:        wait_mrp_active&lt;br /&gt;
#&lt;br /&gt;
# DESCRIPTION: &lt;br /&gt;
#   Wait for $MRP_START_TIMEOUT minutes to confirm that the MRP is active.  If&lt;br /&gt;
#   we can&amp;#039;t detect an active MRP, abort the script with an error.&lt;br /&gt;
#&lt;br /&gt;
# INPUT(S):&lt;br /&gt;
#   Arguments:&lt;br /&gt;
#     $1: database user&lt;br /&gt;
#     $2: user password&lt;br /&gt;
#     $3: tns service name&lt;br /&gt;
#     $4: database unique name&lt;br /&gt;
#&lt;br /&gt;
#   Globals:&lt;br /&gt;
#     None&lt;br /&gt;
#&lt;br /&gt;
# RETURN:&lt;br /&gt;
#   None&lt;br /&gt;
#&lt;br /&gt;
###############################################################################&lt;br /&gt;
wait_mrp_active()&lt;br /&gt;
{&lt;br /&gt;
  display &amp;quot;confirming media recovery is running&amp;quot;&lt;br /&gt;
  l_wma_status=1&lt;br /&gt;
  l_wma_curtime=`perl -e &amp;#039;print int(time)&amp;#039;`&lt;br /&gt;
  l_wma_exptime=`expr $MRP_START_TIMEOUT &amp;quot;*&amp;quot; 60`&lt;br /&gt;
  l_wma_maxtime=`expr $l_wma_curtime + $l_wma_exptime`&lt;br /&gt;
  while [ &amp;quot;$l_wma_curtime&amp;quot; -lt &amp;quot;$l_wma_maxtime&amp;quot; ]&lt;br /&gt;
  do&lt;br /&gt;
    is_mrp_running $1 $2 $3 $4&lt;br /&gt;
    if [ &amp;quot;$?&amp;quot; -gt &amp;quot;0&amp;quot; ]; then&lt;br /&gt;
      l_wma_status=0&lt;br /&gt;
      break&lt;br /&gt;
    fi&lt;br /&gt;
&lt;br /&gt;
    sleep $MRP_START_INTERVAL&lt;br /&gt;
    l_wma_curtime=`perl -e &amp;#039;print int(time)&amp;#039;`&lt;br /&gt;
  done&lt;br /&gt;
  chkerr $l_wma_status &amp;quot;could not detect an active MRP after $MRP_START_TIMEOUT minutes&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===split variable (eg. filename) into separate variables using set===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
FILENAME=&amp;quot;split_this_into_bits&amp;quot;&lt;br /&gt;
set $(echo ${FILENAME} | sed &amp;#039;s/_/ /g&amp;#039;)&lt;br /&gt;
echo $4 $3 $2 $1&lt;br /&gt;
bits into this split&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Centre align text on a line in bash shell===&lt;br /&gt;
Doesn&amp;#039;t work in Korn shell due to %*s&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#COLUMNS=$(tput cols)   # width of the current window&lt;br /&gt;
COLUMNS=80&lt;br /&gt;
title=&amp;quot;Hello world!&amp;quot;&lt;br /&gt;
printf &amp;quot;%*s\n&amp;quot; $(((${#title}+$COLUMNS)/2)) &amp;quot;$title&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
and as a one-liner&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
printf &amp;quot;%*s\n&amp;quot; $(( ( $(echo $* | wc -c ) + 80 ) / 2 )) &amp;quot;$*&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This works in Korn shell...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
TITLE=&amp;quot;$1&amp;quot;&lt;br /&gt;
LINEWIDTH=80&lt;br /&gt;
&lt;br /&gt;
LPAD=$(((${#TITLE}+$LINEWIDTH)/2))&lt;br /&gt;
printf %${LPAD}s &amp;quot;$TITLE&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Right justify text (or repeat characters) on a line with leader dots!===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
function rpadwait {&lt;br /&gt;
    text=$1&lt;br /&gt;
# -------------------------&lt;br /&gt;
# suppress newline for echo&lt;br /&gt;
# -------------------------&lt;br /&gt;
N=&lt;br /&gt;
C=&lt;br /&gt;
if echo &amp;quot;\c&amp;quot; | grep c &amp;gt;/dev/null 2&amp;gt;&amp;amp;1; then&lt;br /&gt;
    N=&amp;#039;-n&amp;#039;&lt;br /&gt;
else&lt;br /&gt;
    C=&amp;#039;\c&amp;#039;&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
    echo ${N} &amp;quot;${text}${C}&amp;quot; | sed -e :a -e &amp;#039;s/^.\{1,80\}$/&amp;amp;\./;ta&amp;#039;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===cron jobs not submitted - daemon run out of child processes?===&lt;br /&gt;
Sometimes have problems with NFS mounts and this causes cron jobs to hang. If they are scheduled to run regularly, eventually cron will no longer be able to start any more jobs.&amp;lt;br /&amp;gt;&lt;br /&gt;
* Check the cron log &amp;#039;&amp;#039;&amp;#039;/var/adm/cron/log&amp;#039;&amp;#039;&amp;#039; to see if there are any errors or other messages around the time the jobs should run.&lt;br /&gt;
If cron has hit its process limit (default 100), it will try again after a number of seconds (default 60).&amp;lt;br /&amp;gt;&lt;br /&gt;
Both the number of jobs and wait time are configured in the file &amp;#039;&amp;#039;&amp;#039;/var/adm/cron/queuedefs&amp;#039;&amp;#039;&amp;#039;. If it is unusual for cron to be running so many jobs, you can check the process table to view the jobs cron has created. These jobs will have parent process id (PPID) of the cron daemon.&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ ps -ef | grep cron | grep -v grep&lt;br /&gt;
    root  6750314        1   0   Apr 24      -  3:39 /usr/sbin/cron&lt;br /&gt;
solax025:root[/home/root]# ps -T 6750314&lt;br /&gt;
      PID    TTY  TIME CMD&lt;br /&gt;
  6750314      -  3:39 cron&lt;br /&gt;
 21168296      -  0:00     \--bsh&lt;br /&gt;
 58982414      -  0:00         \--sadc&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
In this example, we only have 1 job running&lt;br /&gt;
&lt;br /&gt;
===Find long-running processes with a cron job===&lt;br /&gt;
Processes running longer than 24 hours have a date instead of a start time...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
58 08,14 * * * /home/ibmtools/scripts/oracle/dosh -vc &amp;quot;ps -ef|grep &amp;#039;ibmtools/scripts/oracle&amp;#039;|perl -nae &amp;#039;print if \$F[4] !~/:/&amp;#039;&amp;quot; &amp;gt;/tmp/lrp.txt; [[ $(grep -c ibmtools /tmp/lrp.txt) -ne 0 ]] &amp;amp;&amp;amp; cat /tmp/lrp.txt|mailx -s &amp;#039;*** long running processes - please check ***&amp;#039; reporting@companymail.com&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Process command line arguments in shell===&lt;br /&gt;
Borrowed from Mozilla Firefox installer&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
## Command line arg defaults&lt;br /&gt;
##&lt;br /&gt;
moz_debug=0&lt;br /&gt;
moz_debugger=&amp;quot;&amp;quot;&lt;br /&gt;
moz_debugger_args=&amp;quot;&amp;quot;&lt;br /&gt;
#&lt;br /&gt;
##&lt;br /&gt;
## Parse the command line&lt;br /&gt;
##&lt;br /&gt;
while [ $# -gt 0 ]&lt;br /&gt;
do&lt;br /&gt;
  case $1 in&lt;br /&gt;
    -g | --debug)&lt;br /&gt;
      moz_debug=1&lt;br /&gt;
      shift&lt;br /&gt;
      ;;&lt;br /&gt;
    -d | --debugger)&lt;br /&gt;
      moz_debugger=$2;&lt;br /&gt;
      if [ &amp;quot;${moz_debugger}&amp;quot; != &amp;quot;&amp;quot; ]; then&lt;br /&gt;
	shift 2&lt;br /&gt;
      else&lt;br /&gt;
        echo &amp;quot;-d requires an argument&amp;quot;&lt;br /&gt;
        exit 1&lt;br /&gt;
      fi&lt;br /&gt;
      ;;&lt;br /&gt;
    -a | --debugger-args)&lt;br /&gt;
      moz_debugger_args=$2;&lt;br /&gt;
      if [ &amp;quot;${moz_debugger_args}&amp;quot; != &amp;quot;&amp;quot; ]; then&lt;br /&gt;
	shift 2&lt;br /&gt;
      else&lt;br /&gt;
        echo &amp;quot;-a requires an argument&amp;quot;&lt;br /&gt;
        exit 1&lt;br /&gt;
      fi&lt;br /&gt;
      ;;&lt;br /&gt;
    *)&lt;br /&gt;
      break;&lt;br /&gt;
      ;;&lt;br /&gt;
  esac&lt;br /&gt;
done&lt;br /&gt;
#&lt;br /&gt;
##&lt;br /&gt;
## Program name given in $1&lt;br /&gt;
##&lt;br /&gt;
if [ $# -gt 0 ]&lt;br /&gt;
then&lt;br /&gt;
	MOZ_PROGRAM=$1&lt;br /&gt;
	shift&lt;br /&gt;
fi&lt;br /&gt;
##&lt;br /&gt;
## Program not given, try to guess a default&lt;br /&gt;
##&lt;br /&gt;
if [ -z &amp;quot;$MOZ_PROGRAM&amp;quot; ]&lt;br /&gt;
then&lt;br /&gt;
	##&lt;br /&gt;
	## Try this script&amp;#039;s name with &amp;#039;-bin&amp;#039; appended&lt;br /&gt;
	##&lt;br /&gt;
	if [ -x &amp;quot;$MOZ_DEFAULT_NAME&amp;quot; ]&lt;br /&gt;
	then&lt;br /&gt;
		MOZ_PROGRAM=$MOZ_DEFAULT_NAME&lt;br /&gt;
	##&lt;br /&gt;
	## Try mozilla-bin&lt;br /&gt;
	## &lt;br /&gt;
	elif [ -x &amp;quot;$MOZ_APPRUNNER_NAME&amp;quot; ]&lt;br /&gt;
	then&lt;br /&gt;
		MOZ_PROGRAM=$MOZ_APPRUNNER_NAME&lt;br /&gt;
	fi&lt;br /&gt;
fi&lt;br /&gt;
#&lt;br /&gt;
#&lt;br /&gt;
##&lt;br /&gt;
## Make sure the program is executable&lt;br /&gt;
##&lt;br /&gt;
if [ ! -x &amp;quot;$MOZ_PROGRAM&amp;quot; ]&lt;br /&gt;
then&lt;br /&gt;
	moz_bail &amp;quot;Cannot execute $MOZ_PROGRAM.&amp;quot;&lt;br /&gt;
fi&lt;br /&gt;
#&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Carry XWindows settings across sessions===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# ----------------------&lt;br /&gt;
# push XWindows settings&lt;br /&gt;
# ----------------------&lt;br /&gt;
[[ &amp;quot;$(uname)&amp;quot; == &amp;quot;SunOS&amp;quot; ]] &amp;amp;&amp;amp; PATH=/usr/openwin/bin:$PATH&lt;br /&gt;
WHOAMI=$(id | awk -F&amp;#039;)&amp;#039; &amp;#039;{print $1}&amp;#039; | awk -F&amp;#039;(&amp;#039; &amp;#039;{print $2}&amp;#039;)&lt;br /&gt;
xauth list &amp;gt; /tmp/xauth_list_$WHOAMI&lt;br /&gt;
chmod 777 /tmp/xauth_list_$WHOAMI&lt;br /&gt;
&lt;br /&gt;
echo $DISPLAY &amp;gt; /tmp/xdisplay_$WHOAMI&lt;br /&gt;
chmod 777 /tmp/xdisplay_$WHOAMI&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Cross-platform version of whoami===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
WHOAMI=$(id | awk -F&amp;#039;)&amp;#039; &amp;#039;{print $1}&amp;#039; | awk -F&amp;#039;(&amp;#039; &amp;#039;{print $2}&amp;#039;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Set terminal title from command line===&lt;br /&gt;
Put something like this in the .profile&amp;lt;br /&amp;gt;&lt;br /&gt;
-n     do not output the trailing newline&amp;lt;br /&amp;gt;&lt;br /&gt;
-e     enable interpretation of backslash escapes&amp;lt;br /&amp;gt;&lt;br /&gt;
|0     sets title of window and icon&amp;lt;br /&amp;gt;&lt;br /&gt;
|1     sets title of icon only&amp;lt;br /&amp;gt;&lt;br /&gt;
|2     sets title of window only&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
echo -en &amp;quot;\033]0;`hostname`\007&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
echo -en &amp;quot;\033]2;`hostname`\007&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Remove blank lines and comments (also indented ones) from a file===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
awk -F\: &amp;#039;!/^($|[:space:]*#)/ {print $2}&amp;#039; /etc/oratab | sort | uniq&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or as part of a script that removes comments and blank lines from all Korn shell scripts in a directory&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/usr/bin/ksh&lt;br /&gt;
for i in $(ls *ksh); do&lt;br /&gt;
    perl -p -i -e &amp;#039;s/^\s*#[^!]*$//; s/^\s*$//&amp;#039; $i&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Return elements of an array in Korn shell===&lt;br /&gt;
From [http://unix.stackexchange.com/questions/188202/processing-output-from-an-sqlite-db-into-a-ksh-array-with-spaces here]&amp;lt;br /&amp;gt;&lt;br /&gt;
Could be used to separate the columns of an SQL select when returning to the shell&amp;lt;br /&amp;gt;&lt;br /&gt;
This approach eliminates the need to put quotes around text with spaces in it.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
echo $KSH_VERSION&lt;br /&gt;
x=&amp;quot;Red,Yellow is a color,Blue&amp;quot;&lt;br /&gt;
oIFS=$IFS&lt;br /&gt;
IFS=,&lt;br /&gt;
y=($x)&lt;br /&gt;
IFS=$oIFS&lt;br /&gt;
echo ${y[1]}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===A decent Unix Prompt===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
export PS1=&amp;quot;`uname -n`:`whoami`[\${PWD}]# &amp;quot;&lt;br /&gt;
or&lt;br /&gt;
export PS1=&amp;#039;($?) $&amp;#039;ORACLE_SID&amp;quot; &amp;quot;`whoami`&amp;quot;@&amp;quot;`uname -n`&amp;quot;:&amp;quot;&amp;#039;$&amp;#039;PWD&amp;quot;&amp;gt; &amp;quot;&lt;br /&gt;
export EDITOR=vi&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Simple arithmetic===&lt;br /&gt;
pipe the calculation into the shell calculator&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
space_in_kb=$(echo $1 / 1024 | bc)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Calculate the remainder (modulo) of a division calculation&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
if [[ $(echo &amp;quot;${NUMBER} % 2&amp;quot; | bc) -eq 0 ]]; then&lt;br /&gt;
    echo &amp;quot;${NUMBER} is even&amp;quot;&lt;br /&gt;
else&lt;br /&gt;
    echo &amp;quot;${NUMBER} is odd&amp;quot;&lt;br /&gt;
fi&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or do it in awk if scientific notation maybe involved&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
function calc { awk &amp;quot;BEGIN{print $*}&amp;quot;; }&lt;br /&gt;
&lt;br /&gt;
if [[ $(calc &amp;quot;${SPACE_USED} + ${SPACE_AVAILABLE} - ${DATABASE_SIZE&amp;quot;) -le 0 ]]; then&lt;br /&gt;
    echo &amp;quot;NOK&amp;quot;&lt;br /&gt;
fi&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Script encryption and passphrase protection===&lt;br /&gt;
Encrypt a shell script with the ability to execute the encrypted version&lt;br /&gt;
* from [http://www.commandlinefu.com/commands/browse commandlinefu.com]&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
scrypt(){ [ -n &amp;quot;$1&amp;quot; ]&amp;amp;&amp;amp;{ echo &amp;#039;. &amp;lt;(echo &amp;quot;$(tail -n+2 $0|base64 -d|mcrypt -dq)&amp;quot;); exit;&amp;#039;&amp;gt;$1.scrypt;cat $1|mcrypt|base64 &amp;gt;&amp;gt;$1.scrypt;chmod +x $1.scrypt;};}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Virtual host configuration in Apache http.conf===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;VirtualHost *:80&amp;gt;&lt;br /&gt;
        ServerName dbamon&lt;br /&gt;
        DocumentRoot &amp;quot;/Volumes/data/Sites/dbamon_push&amp;quot;&lt;br /&gt;
        &amp;lt;Directory &amp;quot;/Volumes/data/Sites/dbamon_push&amp;quot;&amp;gt;&lt;br /&gt;
                Options Includes FollowSymLinks&lt;br /&gt;
                AllowOverride All&lt;br /&gt;
                Order allow,deny&lt;br /&gt;
                Allow from all&lt;br /&gt;
        &amp;lt;/Directory&amp;gt;&lt;br /&gt;
&amp;lt;/VirtualHost&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
and in /etc/hosts, add...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
127.0.0.1  dbamon&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Mount a website (or any other remote resource) locally using WebDav===&lt;br /&gt;
Redhat/CentOS&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
yum install fuse-davfs2&lt;br /&gt;
or&lt;br /&gt;
yum install wdfs.x86_64&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Debian&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
apt-get install davfs2&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
then...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo mkdir /mnt/webdav  # or whatever you&amp;#039;d like to call the directory&lt;br /&gt;
sudo mount.davfs [-o option[,option]...] device mount_point&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
In man&amp;#039;s terms, that last line would translate to:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
id  #suppose this returns uid=501 and gid=502&lt;br /&gt;
sudo mount.davfs -o 501,502 https://your/web/site /mnt/webdav&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Mac OSX&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
osascript -e &amp;#039; mount volume &amp;quot;http://username:password@webdav.address:portnum&amp;quot; &amp;#039;&lt;br /&gt;
or&lt;br /&gt;
osascript -e &amp;#039; mount volume &amp;quot;http://username@webdav.address:portnum&amp;quot; &amp;#039;&lt;br /&gt;
or&lt;br /&gt;
osascript -e &amp;#039; try mount volume &amp;quot;http://webdav.address:portnum&amp;quot; &amp;#039;&lt;br /&gt;
or&lt;br /&gt;
mount -t webdav http://webdav.address:portnum /mnt/webdav  # this one won&amp;#039;t show up in the Finder Sidebar.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Add current hostname to list of hosts on an xcat server===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
CMD=&amp;quot;nodels&amp;quot;&lt;br /&gt;
HOST=`hostname`&lt;br /&gt;
(echo &amp;quot;$HOST&amp;quot;; $CMD) | while read server&lt;br /&gt;
do&lt;br /&gt;
    echo &amp;quot;server:$server&amp;quot;&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===What is todays &amp;#039;Day Of the Year&amp;#039; number?===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
DOY=`perl -e &amp;#039;print sub{$_[7]}-&amp;gt;(localtime)+1;&amp;#039;`&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Convert Julian day numbers to dates===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
for day in 8 33 36 61 64 91 96 121 126 152 155 182 187 215 218 244 247 274 279 306 309 335 338 365; do date -d &amp;quot;`date +%Y`-01-01 +$(( ${day} - 1 ))days&amp;quot; +%d-%m-%Y; done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Send crontab job output to a date formatted log file===&lt;br /&gt;
This will run a job every 5 minutes and send the output to a file ending with a time in hours and minutes.&amp;lt;br /&amp;gt;&lt;br /&gt;
The thing to note is the escaped percent signs. This is because a % sign is interpreted by cron to mean a newline character. Everything after the first % is treated as input to the program.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
*/5 *  * * * /var/www/cgi-bin/dbamon_collector.ksh       &amp;gt;/tmp/dbamon_collector.log.$(date &amp;quot;+\%H\%M&amp;quot;) 2&amp;gt;&amp;amp;1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Edit crontab file without crontab -e===&lt;br /&gt;
It can happen that you need to add or modify a line in the crontab of many users or across many servers at once.&amp;lt;br /&amp;gt;&lt;br /&gt;
In principle, there&amp;#039;s nothing wrong with modifying the crontab file directly. You just lose the advantages of file locking (and syntax checking) that crontab -e offers.&amp;lt;br /&amp;gt;&lt;br /&gt;
Here we take a backup of the current crontab, print it out, echo an extra command and ask cron to use these as input (thus overwriting the existing crontab file). Just don&amp;#039;t run this close to midnight :-)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
crontab -l &amp;gt; /tmp/crontab.`date &amp;#039;+%Y%m%d&amp;#039;`&lt;br /&gt;
(&lt;br /&gt;
cat /tmp/crontab.`date +&amp;#039;%Y%m%d&amp;#039;`&lt;br /&gt;
echo &amp;quot;02 10 * * * /home/ibmtools/scripts/oracle/export_parfile.ksh -s SID -f JDBEOP1.parfile&amp;quot;&lt;br /&gt;
) | crontab -&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
crontab -l &amp;gt; /tmp/crontab.backup&lt;br /&gt;
crontab -l &amp;gt; /tmp/crontab.$$&lt;br /&gt;
perl -p -i -e &amp;#039;s!backup_send_tsm_dump!backup_export2tsm!g&amp;#039; /tmp/crontab.$$&lt;br /&gt;
crontab /tmp/crontab.$$&lt;br /&gt;
rm /tmp/crontab.$$&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
crontab -l &amp;gt;$HOME/crontab.$(date &amp;#039;+%Y%m%d&amp;#039;)&lt;br /&gt;
crontab -l | perl -p -e &amp;#039;s|/nas/software/oracle/scripts|/oracle/scripts|&amp;#039; | crontab&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Use shell to convert a number in scientific notation to normal===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
var2convert=&amp;#039;1.2345678e3&amp;#039;&lt;br /&gt;
printf -v var2convert &amp;quot;%.f&amp;quot; $var2convert&lt;br /&gt;
echo $var2convert  # magic!&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Check for jobs running longer that 24 hours===&lt;br /&gt;
Run from the management server across all Unix servers. Checks the 5th column in a ps listing. If it doesn&amp;#039;t find a : (time separator), the process is running longer than 24 hours.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# ---------------------------------------&lt;br /&gt;
# report on long running oraibm processes&lt;br /&gt;
# ---------------------------------------&lt;br /&gt;
01 17,14 * * * rm -f /tmp/lrp.txt;/home/ibmtools/scripts/oracle/dosh -vc \&amp;quot;ps -ef|egrep &amp;#039;oraibm|scripts/oracle&amp;#039;&amp;gt;/tmp/lrp.txt;perl -nae &amp;#039;print if \$F[4] !~/:/&amp;#039; /tmp/lrp.txt\&amp;quot; &amp;gt;&amp;gt;/tmp/lrp.txt;[[ $(egrep -c &amp;#039;oraibm|scripts/or&lt;br /&gt;
acle&amp;#039; /tmp/lrp.txt) -ne 0 ]] &amp;amp;&amp;amp; cat /tmp/lrp.txt|mailx -s &amp;#039;*** long running processes - please check ***&amp;#039; bey9at77@mail.com&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Global find and replace with perl (restricted to list of files provided by Unix find command)===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
find . -type f -exec perl -i -pe &amp;#039;s/something/else/g&amp;#039; {} \;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===perl function to make filenames lower case===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
function lower { &lt;br /&gt;
   perl -e &amp;#039;for (@ARGV) { rename $_, lc($_) unless -e lc($_); }&amp;#039; * &lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===From the management server, search the TNS listener port for each database on a server and make an inline substitution in the ITM config files!===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
for i in `/home/ibmtools/scripts/oracle/dosh -c &amp;quot;ls -al /opt/IBM/ITM/config/*rz*cfg|grep -v lrwx&amp;quot;|awk &amp;#039;{print $NF}&amp;#039;`; do&lt;br /&gt;
    server=`echo $i|cut -d_ -f1 | awk -F&amp;#039;/&amp;#039; &amp;#039;{print $NF}&amp;#039;`&lt;br /&gt;
    db=`echo $i|cut -d&amp;#039;.&amp;#039; -f1 | awk -F&amp;#039;_&amp;#039; &amp;#039;{print $NF}&amp;#039;`&lt;br /&gt;
    OH=`ssh $server grep &amp;quot;^$db&amp;quot; /etc/oratab|cut -d: -f2`&lt;br /&gt;
    LISTENERPORT=`ssh $server cat $OH/network/admin/listener.ora|perl -00 -ne &amp;#039;print $1 if /&amp;#039;$db&amp;#039;.*PORT.*=.*(\d{4})/s&amp;#039;`&lt;br /&gt;
    ssh $server perl -p -i.bak -e &amp;#039;s/1521/&amp;#039;$LISTENERPORT&amp;#039;/&amp;#039; $i&lt;br /&gt;
    ssh $server ls -al ${i}*&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Run a job from cron every Nth day of the month===&lt;br /&gt;
Example. Execute a job every third Saturday of the month.&amp;lt;br /&amp;gt;&lt;br /&gt;
Paste this into a file called calenday and put it in /usr/local/bin so it&amp;#039;s (probably) on the PATH&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/usr/bin/ksh&lt;br /&gt;
&lt;br /&gt;
# ix is the week number of the month (&amp;quot;2&amp;quot;nd Friday of the month, &amp;quot;3&amp;quot;rd Tuesday of the month)&lt;br /&gt;
# dy is the day number in Unix format (0 for Sunday, 1 for Monday, ... 6 for Saturday)&lt;br /&gt;
# eg. &amp;quot;calenday 3 6&amp;quot; returns the date of 3rd Saturday of the month.&lt;br /&gt;
&lt;br /&gt;
ix=$1&lt;br /&gt;
dy=$2&lt;br /&gt;
SCHAR=$((($dy*2)+$dy+1))&lt;br /&gt;
ECHAR=$(($SCHAR+1))&lt;br /&gt;
cal `date &amp;#039;+%m %Y&amp;#039;` | egrep &amp;quot;\&amp;lt;[0-9]{1,2}\&amp;gt;&amp;quot; | cut -c${SCHAR}-${ECHAR} | xargs | awk {&amp;#039;print $&amp;#039;$ix&amp;#039;}&amp;#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Now in crontab, you should be able to do something like this:&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
15 20 * * * [[ `calenday 3 6` -eq `/bin/date &amp;#039;+%d&amp;#039;` ]] &amp;amp;&amp;amp; su - oracle -c &amp;quot;run_my_backup.ksh&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will also work on some Unices..&amp;lt;br /&amp;gt;&lt;br /&gt;
We send backups to a special TSM node on the second Friday of each month. This report must run a day later - but that is not guaranteed to be the second Saturday or even the 3rd. So...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
30 12 8-14 * 5 sleep 86400 &amp;amp;&amp;amp; su - oracle -c &amp;quot;/usr/bin/perl -ne &amp;#039;print if /ORX_M_SOL/ .. /^STOP/&amp;#039; /home/oracle/incoming/dbamon_spool_tsm_*.SOL | grep Archive | grep -v Client | mailx -s &amp;#039;Monthly TSM backups&amp;#039; orareport@xxxxxx.com&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ps listing does not show start time after 24 hours===&lt;br /&gt;
But you can see elapsed time using your own ps command&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/usr/bin/ps -eo etime,user,pid,ppid,cpu,start,tty,time,args|tail -n +2|sort&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ps -ef cuts off args cmd column on Solaris===&lt;br /&gt;
====To see more than 80 characters of the last column on Solaris====&lt;br /&gt;
This shows all the individual arguments to the command&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
pargs &amp;lt;pid&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This shows the ps listing in &amp;#039;compatibility&amp;#039; mode (there are more compatibility commands in /usr/xpg4/bin)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/usr/ucb/ps auww&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====To see more than 80 characters of the last column on AIX====&lt;br /&gt;
This shows the full argument listing of a process (NOTE: no minus sign!)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ps eww &amp;lt;pid&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Remove blank / empty lines from vi ===&lt;br /&gt;
Maybe you cut and pasted a file from Windows and it&amp;#039;s full of blank lines and Control-M&amp;#039;s now&amp;lt;br /&amp;gt;&lt;br /&gt;
There are several methods but I think this is the easiest to remember&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
:g/^$/d&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Right pad a variable===&lt;br /&gt;
a function like rpad in SQL but for Shell&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
function rpad {&lt;br /&gt;
text=$1&lt;br /&gt;
padwidth=$2&lt;br /&gt;
padchar=$3&lt;br /&gt;
echo &amp;quot;$text&amp;quot; | sed -e :a -e &amp;#039;s/^.\{1,&amp;#039;$padwidth&amp;#039;\}$/&amp;amp;\&amp;#039;$padchar&amp;#039;/;ta&amp;#039;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Connect to a Windows server from Linux using rdesktop===&lt;br /&gt;
My remmina stopped working so rolled my own. Very simple really. Put this is a shell.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
tsocks rdesktop -z -P -x m -a 16 -d MAIND -u sbarkley -p ****** -r disk:SOL=$HOME/Documents/SOL -g 95% 150.251.112.38 &amp;amp;&lt;br /&gt;
&lt;br /&gt;
where...&lt;br /&gt;
-z    - enables compression&lt;br /&gt;
-P    - enables bitmap caching (saves network traffic)&lt;br /&gt;
-x m  - disables eye-candy features&lt;br /&gt;
-a 16 - reduce colour pallete to 16 colours&lt;br /&gt;
-d    - domain to connect to&lt;br /&gt;
-u    - username&lt;br /&gt;
-p    - password&lt;br /&gt;
-r    - setup a shared folder&lt;br /&gt;
-g    - geometry (use W x H or percentage)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Slight problems with rdesktop not working 100% of the time. Now using xfreerdp. Seems better...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
xfreerdp -g 90% --ignore-certificate --gdi sw -K -d wdcrhbp05 -u oraibm -p &amp;quot;`cat $HOME/scripts/.oraibm.password`&amp;quot; -T &amp;quot;wdcrhbp05_oraibm&amp;quot; --plugin cliprdr --plugin rdpdr --data disk:SOL:/home/bey9at77/Documents/SOL -- --plugin rdpsnd --data alsa -- 150.251.112.25 &amp;amp;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Reset your password bypassing password rules===&lt;br /&gt;
must be done as root&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
echo &amp;quot;user:new_password&amp;quot; | chpasswd&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Sum the sizes of all files of an ls listing===&lt;br /&gt;
It&amp;#039;ll check to see if the sum of filesizes corresponds with the df -g (or h) listing (can get messed up due to open but deleted files)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cd /oracle/export&lt;br /&gt;
df -g .&lt;br /&gt;
find . -name &amp;quot;*dmp*&amp;quot; -ls |  awk &amp;#039;{ SUM += $7} END { print SUM/1024/1024/1024 }&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Mount an iso image under Linux===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
mkdir -p /mnt/cdrom&lt;br /&gt;
mount -o loop /dev/cdrom /mnt/cdrom&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===How many processors on the machine?===&lt;br /&gt;
* AIX&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
lsdev -C|grep Process|wc -l&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Solaris&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
psrinfo -v|grep &amp;quot;Status of processor&amp;quot;|wc -l&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Linux&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cat /proc/cpuinfo|grep processor|wc -l&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Quick, simple, understandable example of how to use RRDTool===&lt;br /&gt;
* [[RRDTool]]&lt;br /&gt;
&lt;br /&gt;
===Use expect to respond automatically to interactive programs===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/usr/bin/expect -f&lt;br /&gt;
spawn /usr/tivoli/tsm/client/oracle/bin64/tdpoconf passw -tdpo_optfile=/oracle/[lindex $argv 0]/admin/tdpo.opt&lt;br /&gt;
expect &amp;quot;assword:&amp;quot; {send &amp;quot;password\r&amp;quot;}&lt;br /&gt;
expect &amp;quot;assword:&amp;quot; {send &amp;quot;password\r&amp;quot;}&lt;br /&gt;
expect &amp;quot;assword:&amp;quot; {send &amp;quot;password\r&amp;quot;}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Use expect to allow file copy with scp (if ssh keys are not an option)===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/usr/bin/expect -f&lt;br /&gt;
spawn scp /home/oracle/.profile oracle@hn512:/tmp/prfl&lt;br /&gt;
set pass &amp;quot;thepassword&amp;quot;&lt;br /&gt;
expect {&lt;br /&gt;
        password: {send &amp;quot;$pass\r&amp;quot; ; exp_continue}&lt;br /&gt;
        eof exit&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Within a shell script set up simultaneous output to both terminal and a file using a FIFO (named pipes)===&lt;br /&gt;
or &amp;quot;How to send shell output to screen/stdout as well as to a logfile using tee and redirection with exec&amp;quot;&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
examples [http://www.unix.com/shell-programming-and-scripting/85584-redirect-within-ksh.html here on unix.com]&lt;br /&gt;
* general info on redirections [http://www.catonmat.net/blog/bash-one-liners-explained-part-three/ here at catonmat.net]&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/ksh&lt;br /&gt;
&lt;br /&gt;
REDIR=test.redir&lt;br /&gt;
FIFO=test.pipe&lt;br /&gt;
[[ -e $FIFO ]] || mkfifo $FIFO&lt;br /&gt;
&lt;br /&gt;
# make a new channel(3) and copy channel 1&amp;#039;s destination as its own (does NOT POINT TO channel 1&amp;#039;s destination)&lt;br /&gt;
# this allows the normal output to continue to STDOUT but also get printed to whatever file is attached to channel 3&lt;br /&gt;
exec 3&amp;gt;&amp;amp;1&lt;br /&gt;
&lt;br /&gt;
# anything coming in on the pipe, send it to $REDIR and to channel 3&lt;br /&gt;
tee $REDIR &amp;lt;$FIFO &amp;gt;&amp;amp;3 &amp;amp;&lt;br /&gt;
&lt;br /&gt;
# redirect STDOUT to the pipe&lt;br /&gt;
exec &amp;gt; $FIFO&lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;going to default output&amp;quot;&lt;br /&gt;
echo &amp;quot;forcing to channel 1&amp;quot; &amp;gt;&amp;amp;1&lt;br /&gt;
echo &amp;quot;forcing to channel 2&amp;quot; &amp;gt;&amp;amp;2&lt;br /&gt;
echo &amp;quot;forcing to channel 3&amp;quot; &amp;gt;&amp;amp;3&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====More elaborate example====&lt;br /&gt;
found [http://stackoverflow.com/questions/2288939/create-a-pipe-that-writes-to-multiple-files-tee here on stackoverflow]&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/sh&lt;br /&gt;
&lt;br /&gt;
# Author: Harvey Chapman &amp;lt;hchapman _AT_ 3gfp.com&amp;gt;&lt;br /&gt;
# Description: POSIX shell functions that can be used with tee to simultaneously put&lt;br /&gt;
#              stderr and stdout to both a file and stdout&lt;br /&gt;
#&lt;br /&gt;
# Based on:&lt;br /&gt;
#    Re: How to redirect stderr and stdout to a file plus display at the same time&lt;br /&gt;
#    http://www.travishartwell.net/blog/2006/08/19_2220&lt;br /&gt;
&lt;br /&gt;
#&lt;br /&gt;
# Original example function from Travis Hartwell&amp;#039;s blog.&lt;br /&gt;
# Note: I&amp;#039;ve made minor changes to it.&lt;br /&gt;
example()&lt;br /&gt;
{&lt;br /&gt;
  OUTPUT_LOG=output.log&lt;br /&gt;
  OUTPUT_PIPE=output.pipe&lt;br /&gt;
&lt;br /&gt;
  # This should really be -p to test that it&amp;#039;s a pipe.&lt;br /&gt;
  if [ ! -e $OUTPUT_PIPE ]; then&lt;br /&gt;
      mkfifo $OUTPUT_PIPE&lt;br /&gt;
  fi&lt;br /&gt;
&lt;br /&gt;
  # This should really be -f to test that it&amp;#039;s a regular file.&lt;br /&gt;
  if [ -e $OUTPUT_LOG ]; then&lt;br /&gt;
      rm $OUTPUT_LOG&lt;br /&gt;
  fi&lt;br /&gt;
&lt;br /&gt;
  exec 3&amp;gt;&amp;amp;1 4&amp;gt;&amp;amp;2&lt;br /&gt;
  tee $OUTPUT_LOG &amp;lt; $OUTPUT_PIPE &amp;gt;&amp;amp;3 &amp;amp;&lt;br /&gt;
  tpid=$!&lt;br /&gt;
  exec &amp;gt; $OUTPUT_PIPE 2&amp;gt;&amp;amp;1&lt;br /&gt;
&lt;br /&gt;
  echo &amp;quot;This is on standard out&amp;quot;&lt;br /&gt;
  echo &amp;quot;This is on standard err&amp;quot; &amp;gt;&amp;amp;2&lt;br /&gt;
&lt;br /&gt;
  exec 1&amp;gt;&amp;amp;3 3&amp;gt;&amp;amp;- 2&amp;gt;&amp;amp;4 4&amp;gt;&amp;amp;-&lt;br /&gt;
  wait $tpid&lt;br /&gt;
&lt;br /&gt;
  rm $OUTPUT_PIPE&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
# A slightly reduced version of example()&lt;br /&gt;
example2()&lt;br /&gt;
{&lt;br /&gt;
  OUTPUT_LOG=output.log&lt;br /&gt;
  OUTPUT_PIPE=output.pipe&lt;br /&gt;
&lt;br /&gt;
  rm -f $OUTPUT_PIPE&lt;br /&gt;
  mkfifo $OUTPUT_PIPE&lt;br /&gt;
  rm -f $OUTPUT_LOG&lt;br /&gt;
&lt;br /&gt;
  tee $OUTPUT_LOG &amp;lt; $OUTPUT_PIPE &amp;amp;&lt;br /&gt;
  tpid=$!&lt;br /&gt;
&lt;br /&gt;
  exec 3&amp;gt;&amp;amp;1 4&amp;gt;&amp;amp;2 &amp;gt;$OUTPUT_PIPE 2&amp;gt;&amp;amp;1&lt;br /&gt;
&lt;br /&gt;
  echo &amp;quot;This is on standard out&amp;quot;&lt;br /&gt;
  echo &amp;quot;This is on standard err&amp;quot; &amp;gt;&amp;amp;2&lt;br /&gt;
&lt;br /&gt;
  exec 1&amp;gt;&amp;amp;3 3&amp;gt;&amp;amp;- 2&amp;gt;&amp;amp;4 4&amp;gt;&amp;amp;-&lt;br /&gt;
  wait $tpid&lt;br /&gt;
  rm -f $OUTPUT_PIPE&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
#&lt;br /&gt;
# Logging methods based on above. See the example below for how to use them.&lt;br /&gt;
#&lt;br /&gt;
&lt;br /&gt;
# Usage: start_logging [delete_existing_logfile]&lt;br /&gt;
start_logging()&lt;br /&gt;
{&lt;br /&gt;
  # Check to see if OUTPUT_LOG and OUTPUT_PIPE need to be defined.&lt;br /&gt;
  if [ -z &amp;quot;$OUTPUT_LOG&amp;quot; ]; then&lt;br /&gt;
    OUTPUT_LOG=output.log&lt;br /&gt;
  fi&lt;br /&gt;
  if [ -z &amp;quot;$OUTPUT_PIPE&amp;quot; ]; then&lt;br /&gt;
    OUTPUT_PIPE=output.pipe&lt;br /&gt;
  fi&lt;br /&gt;
  # Make sure that we&amp;#039;re not already logging.&lt;br /&gt;
  if [ -n &amp;quot;$OUTPUT_PID&amp;quot; ]; then&lt;br /&gt;
    echo &amp;quot;Logging already started!&amp;quot;&lt;br /&gt;
    return 1&lt;br /&gt;
  fi&lt;br /&gt;
&lt;br /&gt;
  # Always remove the log and pipe first.&lt;br /&gt;
  rm -f $OUTPUT_PIPE&lt;br /&gt;
  # Delete the logfile first if told to.&lt;br /&gt;
  if [ &amp;quot;$1&amp;quot; = delete_existing_logfile ]; then&lt;br /&gt;
    rm -f $OUTPUT_LOG&lt;br /&gt;
  fi&lt;br /&gt;
&lt;br /&gt;
  mkfifo $OUTPUT_PIPE&lt;br /&gt;
  tee -a $OUTPUT_LOG &amp;lt; $OUTPUT_PIPE &amp;amp;&lt;br /&gt;
  OUTPUT_PID=$!&lt;br /&gt;
&lt;br /&gt;
  exec 3&amp;gt;&amp;amp;1 4&amp;gt;&amp;amp;2 &amp;gt;$OUTPUT_PIPE 2&amp;gt;&amp;amp;1&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
stop_logging()&lt;br /&gt;
{&lt;br /&gt;
  # Make sure that we&amp;#039;re currently logging.&lt;br /&gt;
  if [ -z &amp;quot;$OUTPUT_PID&amp;quot; ]; then&lt;br /&gt;
    echo &amp;quot;Logging not yet started!&amp;quot;&lt;br /&gt;
    return 1&lt;br /&gt;
  fi&lt;br /&gt;
  exec 1&amp;gt;&amp;amp;3 3&amp;gt;&amp;amp;- 2&amp;gt;&amp;amp;4 4&amp;gt;&amp;amp;-&lt;br /&gt;
  wait $OUTPUT_PID&lt;br /&gt;
  rm -f $OUTPUT_PIPE&lt;br /&gt;
  unset OUTPUT_PID&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
example3()&lt;br /&gt;
{&lt;br /&gt;
  start_logging&lt;br /&gt;
  #start_logging delete_existing_logfile&lt;br /&gt;
  echo &amp;quot;This is on standard out&amp;quot;&lt;br /&gt;
  echo &amp;quot;This is on standard err&amp;quot; &amp;gt;&amp;amp;2&lt;br /&gt;
  stop_logging&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===RedHat root filesystem has gone read-only===&lt;br /&gt;
* [http://www.unixarena.com/2013/09/redhat-linux-how-to-fix-read-only-root.html How to fix read only root file system]&lt;br /&gt;
&lt;br /&gt;
===Kill all processes for a user===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
for prc in `ps -ef | grep -E &amp;quot;^ +[o]racle&amp;quot; | awk &amp;#039;{print $2}&amp;#039;`; do&lt;br /&gt;
    kill $prc&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===isRGHere===&lt;br /&gt;
Checks if resource group is on this leg of an HACMP cluster. Returns 0 if true else 1.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/usr/bin/ksh&lt;br /&gt;
&lt;br /&gt;
SCRIPT=`basename $0`&lt;br /&gt;
&lt;br /&gt;
function rctest&lt;br /&gt;
{&lt;br /&gt;
exitcode=$1&lt;br /&gt;
msg=$2&lt;br /&gt;
if [ $exitcode -ne 0 ]; then&lt;br /&gt;
        echo &amp;quot;********************************************************************************&amp;quot;&lt;br /&gt;
        echo &amp;quot;\nScript $SCRIPT finished with errors.&amp;quot;&lt;br /&gt;
        echo &amp;quot;$msg.&amp;quot;&lt;br /&gt;
        echo &amp;quot;Returncode : $exitcode.&amp;quot;&lt;br /&gt;
        echo &amp;quot;\n********************************************************************************&amp;quot;&lt;br /&gt;
&lt;br /&gt;
        fi&lt;br /&gt;
exit $exitcode&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
RGINFO=/usr/es/sbin/cluster/utilities/clRGinfo&lt;br /&gt;
[[ ! -f $RGINFO ]] &amp;amp;&amp;amp;  rctest 1 &amp;quot;clRGinfo not found&amp;quot;&lt;br /&gt;
&lt;br /&gt;
if [ $# -eq 1 ]&lt;br /&gt;
then&lt;br /&gt;
        RG=`echo $1 | cut -c 1-14`&lt;br /&gt;
else&lt;br /&gt;
        rctest 10  &amp;quot;Usage: `basename $0` &amp;lt;RG name&amp;gt;&amp;quot;&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
$RGINFO |grep -qwp $RG ||  rctest 9 &amp;quot;$RG is not defined&amp;quot;&lt;br /&gt;
&lt;br /&gt;
THISNODE=`/usr/es/sbin/cluster/utilities/get_local_nodename | cut -c 1-14`&lt;br /&gt;
$RGINFO |grep -wp $RG |grep -w $THISNODE |grep -wq ONLINE&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===AIX: add a user to a group===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
chgrpmem -m + oracle ibmtls&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Find swear words in scripts by comparing it to a list found on the internet===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
wget &amp;quot;http://www.bannedwordlist.com/lists/swearWords.csv&amp;quot; -O /tmp/s ; for word in $(cat /tmp/s | sed -e &amp;#039;s/ /_/g&amp;#039; -e &amp;#039;s/,/ /g&amp;#039;) ; do grep -wR $word *; done | less&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===grep -p (for paragraph) works on AIX but not on Linux or Solaris===&lt;br /&gt;
Use awk instead&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
awk &amp;#039;BEGIN {FS=&amp;quot;\n&amp;quot; RS=&amp;quot;\n\n&amp;quot;} /search pattern/ { do something }&amp;#039; &amp;lt;file&amp;gt;&lt;br /&gt;
/usr/xpg4/bin/awk &amp;#039;BEGIN {RS=&amp;quot;\n\n&amp;quot;;FS=&amp;quot;\n&amp;quot;} /AGRHDWQ1/ {print $2}&amp;#039; dsm.sys | awk &amp;#039;{print $NF}&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
this prints the last word of the second &amp;#039;&amp;#039;line&amp;#039;&amp;#039; in the paragraph in dsm.sys that contains the search term AGRHDWQ1.&amp;lt;br /&amp;gt;&lt;br /&gt;
Or slightly simpler...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
awk -v RS=&amp;#039;&amp;#039; &amp;#039;/NHAPPLP1/&amp;#039; /etc/tsm/dsm.sys     # (use /usr/xpg4/bin/awk on Solaris)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or, case insensitively:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
awk -v RS=&amp;#039;&amp;#039; &amp;#039;tolower($0) ~/so_u_clubqa_orx_d_cab/&amp;#039; /etc/tsm/dsm.sys&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Using -v means you don&amp;#039;t have to use a BEGIN section.&lt;br /&gt;
&lt;br /&gt;
===debug/redirect log of a shell===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/usr/bin/ksh&lt;br /&gt;
exec 2&amp;gt;/tmp/mytest&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Different ways of Iteration in korn shell with a while loop===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
IFS=&amp;quot;|&amp;quot;&lt;br /&gt;
exec 0&amp;lt;$statfile&lt;br /&gt;
while read host db started stopped&lt;br /&gt;
do&lt;br /&gt;
    rrdfile=&amp;quot;export_duration_${host}_${db}.rrd&amp;quot;&lt;br /&gt;
    $RRDTOOL update ${RRDDIR}/${rrdfile} $started:$started $stopped&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
while read host db started stopped&lt;br /&gt;
do&lt;br /&gt;
    rrdfile=&amp;quot;export_duration_${host}_${db}.rrd&amp;quot;&lt;br /&gt;
    $RRDTOOL update ${RRDDIR}/${rrdfile} $started:$started $stopped&lt;br /&gt;
done &amp;lt;statfile&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    cat $statfile | sort -nk4 | while IFS=\| read host db type started stopped&lt;br /&gt;
    do&lt;br /&gt;
        [[ &amp;quot;$stopped&amp;quot; == &amp;quot;&amp;quot; ]] &amp;amp;&amp;amp; continue&lt;br /&gt;
        rrdfile=&amp;quot;export_duration_${host}_${db}.rrd&amp;quot;&lt;br /&gt;
        $RRDTOOL update ${RRDDIR}/${rrdfile} ${started}:${started}:${stopped}&lt;br /&gt;
        [[ $? -ne 0 ]] &amp;amp;&amp;amp; echo &amp;quot;nok: $?&amp;quot;&lt;br /&gt;
    done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Filesystem 100% full, what&amp;#039;s taking up all the space?===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
find /oracle/endur -xdev -ls|sort -nr +6|head&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/dev/esb01fs010001      1.00      0.00  100%     1838    69% /oracle&lt;br /&gt;
beuxdsysesb01:root[/root]# cd /oracle&lt;br /&gt;
beuxdsysesb01:root[/oracle]# du -gsx * | sort -n&lt;br /&gt;
0.00    checkpoints&lt;br /&gt;
0.00    flash_recovery_area&lt;br /&gt;
0.00    lost+found&lt;br /&gt;
0.00    oraInst.loc&lt;br /&gt;
0.00    oraInventory&lt;br /&gt;
0.09    admin&lt;br /&gt;
0.99    diag&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
cd  diag and repeat until culprits are found&lt;br /&gt;
&lt;br /&gt;
===Show paged memory hogs on AIX===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
svmon -Pt20 | perl -e &amp;#039;while(&amp;lt;&amp;gt;){print if($.==2||$&amp;amp;&amp;amp;&amp;amp;!$s++);$.=0 if(/^-+$/)}&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Capitalise the first letter of a word in Korn Shell===&lt;br /&gt;
Not as easy as it sounds if it needs to work in non-ksh93 shells&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
function capit { &lt;br /&gt;
    typeset -u first&lt;br /&gt;
    first=${1%&amp;quot;${1#?}&amp;quot;}&lt;br /&gt;
    printf &amp;quot;%s\n&amp;quot; &amp;quot;${first}${1#?}&amp;quot;&lt;br /&gt;
    return 0&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or maybe more neatly done in Perl...&amp;lt;br /&amp;gt;&lt;br /&gt;
This will capitalise each word in a sentence passed into it&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
function capit { &lt;br /&gt;
    echo &amp;quot;$1&amp;quot; |  perl -pe &amp;quot;s/([\w&amp;#039;]+)/\u\L\1/g&amp;quot;&lt;br /&gt;
    return 0&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Remove / rename a directory / file containing weird control characters===&lt;br /&gt;
Use ls with -i to see inode listing&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ls -bali&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Use find with -inum to get the filename and -exec to remove it&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
find . -inum &amp;lt;inode from ls listing&amp;gt; -exec rm -f {} \;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Run a local script on a remote host===&lt;br /&gt;
Doing it this way means we do not need to scp the shell over to the host before executing it!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ssh user@host &amp;#039;sh&amp;#039; &amp;lt; your_script.sh&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
First of all, this command is a redirection: your shell will open the file your_script.sh and feed it as input to the ssh command. ssh, in turn, will tunnel its stdin to the remote command, namely, sh instance. And sh without arguments reads its script from stdin. So we got sh instance, which is launched on remote host, but reads commands from your local file.&lt;br /&gt;
&lt;br /&gt;
===Get a list of running instances - but only those started by the current user===&lt;br /&gt;
This is the way I wanted to do it but there&amp;#039;s an issue. Where does that spare } character come from? Anyone?&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ps -ef | grep [p]mon | awk -v dbowner=$(id -un) &amp;#039;{ if ($1==dbowner) { gsub(/ora_pmon_/,&amp;quot;&amp;quot;,$NF); print $NF; } }&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
ps listing&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ ps -ef | grep [p]mon&lt;br /&gt;
  oracle 13304024        1   0   Jun 07      -  2:39 ora_pmon_reportk&lt;br /&gt;
  oracle 26018178        1   0   Jun 07      -  3:01 ora_pmon_dwh_perf&lt;br /&gt;
  oracle 29229432        1   0   Jun 07      -  2:30 ora_pmon_adso&lt;br /&gt;
 oraebso 18022994        1   0   Jun 07      -  2:38 ora_pmon_EBSO&lt;br /&gt;
  oracle 30278192        1   0   Jun 07      -  2:48 ora_pmon_owb112k&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Results of above command&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
reportk&lt;br /&gt;
dwh_perf&lt;br /&gt;
adso&lt;br /&gt;
}&lt;br /&gt;
owb112k&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Workaround 1. Send the ps listing to a file and work on it without pipes. Works but it&amp;#039;s a bit long-winded especially as we have to clean up afterwards.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ps -ef | grep [p]mon&amp;gt;/tmp/results.$$ 2&amp;gt;/dev/null; awk -v dbowner=$(id -un) &amp;#039;{ if ($1==dbowner) { gsub(/ora_pmon_/,&amp;quot;&amp;quot;,$NF); print $NF; } }&amp;#039; /tmp/results.$$; rm -f /tmp/results.$$&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Workaround 2. Don&amp;#039;t like the grep -v but until I find out where that } is coming from..&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ps -ef | grep [p]mon | awk -v dbowner=$(id -un) &amp;#039;{ if ($1==dbowner) { gsub(/ora_pmon_/,&amp;quot;&amp;quot;,$NF); print $NF; } }&amp;#039; | egrep -v &amp;#039;grep|}|ASM&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Return a list of Oracle databases running on a list of remote servers===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/ksh&lt;br /&gt;
&lt;br /&gt;
serverlist=`cat /home/tools/ini/system/oracle_servers | sort -n | tr &amp;quot;\n&amp;quot; &amp;quot; &amp;quot;`&lt;br /&gt;
&lt;br /&gt;
if [ -z &amp;quot;${serverlist}&amp;quot; ]&lt;br /&gt;
then&lt;br /&gt;
    echo &amp;quot;no servers found&amp;quot; &amp;amp;&amp;amp; exit 1&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
for server in ${serverlist}&lt;br /&gt;
do&lt;br /&gt;
    ssh ${server} &amp;quot;ps -ef | grep [o]ra_pmon_&amp;quot; &amp;gt;/tmp/${server}.dblist&lt;br /&gt;
done&lt;br /&gt;
&lt;br /&gt;
for server in ${serverlist}&lt;br /&gt;
do&lt;br /&gt;
    cat /tmp/${server}.dblist | awk -F_ -v SRV=${server} &amp;#039;BEGIN {print SRV &amp;quot;:&amp;quot;} {print $NF}&amp;#039; | tr &amp;quot;\n&amp;quot; &amp;quot; &amp;quot;&lt;br /&gt;
    echo&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Clever trick to check whether SQL output needs sending to someone===&lt;br /&gt;
Using an exit status from SQL*Plus back to the shell so we can decide what to do.  Nice one!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
tempfile=/tmp/audit_locked_accounts_$ORACLE_SID.txt&lt;br /&gt;
&lt;br /&gt;
# Start sqlplus and check for locked accounts&lt;br /&gt;
sqlplus -S &amp;quot;/ as sysdba&amp;quot; &amp;lt;&amp;lt; EOF &amp;gt; $tempfile&lt;br /&gt;
set pages 0&lt;br /&gt;
select &amp;#039;The following accounts were found to be unlocked and should not be&amp;#039;&lt;br /&gt;
from dual;&lt;br /&gt;
&lt;br /&gt;
def exit_status = 0&lt;br /&gt;
col xs new_value exit_status&lt;br /&gt;
&lt;br /&gt;
select username&lt;br /&gt;
,      account_status&lt;br /&gt;
,      1 as xs&lt;br /&gt;
from   dba_users&lt;br /&gt;
where  account_status != &amp;#039;LOCKED&amp;#039;&lt;br /&gt;
and    username in (&amp;#039;HR&amp;#039;, &amp;#039;SCOTT&amp;#039;, &amp;#039;OUTLN&amp;#039;, &amp;#039;MDSYS&amp;#039;, &amp;#039;CTXSYS&amp;#039;)&lt;br /&gt;
/&lt;br /&gt;
exit &amp;amp;exit_status&lt;br /&gt;
EOF&lt;br /&gt;
&lt;br /&gt;
# If the exit status of sqlplus was not 0 then we will send an email&lt;br /&gt;
if [ $? != 0 ]; then&lt;br /&gt;
    mail -s &amp;quot;Accounts Unlocked in $ORACLE_SID&amp;quot; oracle &amp;lt; $tempfile&lt;br /&gt;
fi&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Check RMAN logfiles for errors from cron every day===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
00 09 * * * /home/tools/scripts/oracle/dosh &amp;#039;find /home/tools/logs/rman -name &amp;quot;*online.log&amp;quot; -mtime -1 -exec sed -ne &amp;quot;/^RMAN-/,/^$/p&amp;quot; {} \\; -ls&amp;#039; | mailx&lt;br /&gt;
 -s &amp;#039;RMAN errors last night&amp;#039; stuart@domain.com&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/home/ibmtools/scripts/oracle/dosh &amp;#039;find /oracle/export -name &amp;quot;expdp*log&amp;quot; -mtime -1 -exec grep ORA- {} \; -ls&amp;#039; | mailx -s &amp;#039;Datapump errors for Baxter last night&amp;#039; stuart@domain.com&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===An alternative to getopts===&lt;br /&gt;
These methods have the advantage of allowing arguments of any length not just 1 character&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
countArgs=$#&lt;br /&gt;
while [[ $# -gt 0 ]]&lt;br /&gt;
do&lt;br /&gt;
    idx1=$($ECHO $1|$GREP &amp;quot;=&amp;quot;|wc -l)&lt;br /&gt;
    if [[ $idx1 -gt 0 ]]; then&lt;br /&gt;
        key=$($ECHO $1|$CUT -d &amp;#039;=&amp;#039; -f 1)&lt;br /&gt;
        value=$($ECHO $1|$CUT -d &amp;#039;=&amp;#039; -f 2)&lt;br /&gt;
    else&lt;br /&gt;
        key=$($ECHO $1|$CUT -d &amp;#039;=&amp;#039; -f 1)&lt;br /&gt;
        idx2=$($ECHO $1|$GREP &amp;quot;^-&amp;quot;|wc -l)&lt;br /&gt;
        if [[ $idx2 -eq 0 ]]; then&lt;br /&gt;
            $ECHO -e &amp;quot;\n ERROR: $1 is an unsupported argument passed to agentDeploy.sh.\n&amp;quot;  &lt;br /&gt;
            usage&lt;br /&gt;
            exit 1&lt;br /&gt;
        fi&lt;br /&gt;
    fi&lt;br /&gt;
&lt;br /&gt;
    case &amp;quot;$key&amp;quot; in&lt;br /&gt;
    -help)&lt;br /&gt;
        if [[ $upgradeFlag ]]; then&lt;br /&gt;
            upgradeUsage&lt;br /&gt;
        else&lt;br /&gt;
            freshUsage&lt;br /&gt;
        fi&lt;br /&gt;
        exit 0;;&lt;br /&gt;
    AGENT_BASE_DIR)&lt;br /&gt;
        agentBaseDir=$($ECHO $value|$SED &amp;#039;s/\/$//&amp;#039;)&lt;br /&gt;
        checkBaseFlag=TRUE;;&lt;br /&gt;
    OMS_HOST)&lt;br /&gt;
        omsHost=$value&lt;br /&gt;
        checkOMSHost=TRUE;;&lt;br /&gt;
    EM_UPLOAD_PORT)&lt;br /&gt;
        omsPort=$value&lt;br /&gt;
        checkOMSPort=TRUE;;&lt;br /&gt;
    AGENT_INSTANCE_HOME)&lt;br /&gt;
        instHome=$($ECHO $value | $SED &amp;#039;s/\/$//&amp;#039;);;&lt;br /&gt;
    AGENT_REGISTRATION_PASSWORD)&lt;br /&gt;
        pswd=$value;;&lt;br /&gt;
    s_encrSecurePwd)&lt;br /&gt;
        pswd=$value;;  &lt;br /&gt;
    RESPONSE_FILE)&lt;br /&gt;
        rspFlag=TRUE  &lt;br /&gt;
        rspLoc=$value;;&lt;br /&gt;
    OLD_AGENT_VERSION)&lt;br /&gt;
        oldAgentVersion=$value;;            &lt;br /&gt;
    OLDHOME)&lt;br /&gt;
        oldHome=$value;;    &lt;br /&gt;
    -debug)&lt;br /&gt;
        debugSwitch=TRUE;;&lt;br /&gt;
    -forceConfigure)&lt;br /&gt;
        forceFlag=TRUE;;&lt;br /&gt;
    -configOnly)&lt;br /&gt;
        configFlag=TRUE    &lt;br /&gt;
        validationFlag=TRUE;;&lt;br /&gt;
    -agentImageLocation)&lt;br /&gt;
        archiveLoc=$value&lt;br /&gt;
        checkArchiveFlag=TRUE;;&lt;br /&gt;
    -invPtrLoc) shift&lt;br /&gt;
        ptrLoc=$1;;&lt;br /&gt;
    -Upgrade)&lt;br /&gt;
        UpgradeFlag=TRUE&lt;br /&gt;
        validFlag=TRUE;;&lt;br /&gt;
    INVENTORY_LOCATION)&lt;br /&gt;
        validFlag=TRUE;;&lt;br /&gt;
    b_forceInstCheck)&lt;br /&gt;
        validFlag=TRUE&lt;br /&gt;
        forcefullFlag=TRUE;;&lt;br /&gt;
    -prereqOnly)&lt;br /&gt;
        validationFlag=TRUE&lt;br /&gt;
        prereqFlag=TRUE;;&lt;br /&gt;
    -executeRootsh)&lt;br /&gt;
        validFlag=TRUE;;&lt;br /&gt;
    *)  idx=$($ECHO $1|$GREP &amp;quot;^-&amp;quot;|wc -l)&lt;br /&gt;
        if [[ $idx -eq 0 ]]; then&lt;br /&gt;
            validFlag=TRUE&lt;br /&gt;
        else&lt;br /&gt;
            $ECHO -e &amp;quot;\n ERROR: Invalid argument $key passed.&amp;quot;&lt;br /&gt;
            usage&lt;br /&gt;
            exit 1          &lt;br /&gt;
        fi&lt;br /&gt;
    esac&lt;br /&gt;
    shift&lt;br /&gt;
done&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
another way - found in /etc/init.d/functions (daemon function) in Fedora&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    while [ &amp;quot;$1&amp;quot; != &amp;quot;${1##[-+]}&amp;quot; ]; do&lt;br /&gt;
        case $1 in&lt;br /&gt;
        &amp;#039;&amp;#039;)&lt;br /&gt;
            echo $&amp;quot;$0: Usage: daemon [+/-nicelevel] {program}&amp;quot; &amp;quot;[arg1]...&amp;quot;&lt;br /&gt;
            return 1&lt;br /&gt;
            ;;&lt;br /&gt;
        --check)&lt;br /&gt;
            base=$2&lt;br /&gt;
            gotbase=&amp;quot;yes&amp;quot;&lt;br /&gt;
            shift 2&lt;br /&gt;
            ;;&lt;br /&gt;
        --check=?*)&lt;br /&gt;
            base=${1#--check=}&lt;br /&gt;
            gotbase=&amp;quot;yes&amp;quot;&lt;br /&gt;
            shift&lt;br /&gt;
            ;;&lt;br /&gt;
        --user)&lt;br /&gt;
            user=$2&lt;br /&gt;
            shift 2&lt;br /&gt;
            ;;&lt;br /&gt;
        --user=?*)&lt;br /&gt;
            user=${1#--user=}&lt;br /&gt;
            shift&lt;br /&gt;
            ;;&lt;br /&gt;
        --pidfile)&lt;br /&gt;
            pid_file=$2&lt;br /&gt;
            shift 2&lt;br /&gt;
            ;;&lt;br /&gt;
        --pidfile=?*)&lt;br /&gt;
            pid_file=${1#--pidfile=}&lt;br /&gt;
            shift&lt;br /&gt;
            ;;&lt;br /&gt;
        --force)&lt;br /&gt;
            force=&amp;quot;force&amp;quot;&lt;br /&gt;
            shift&lt;br /&gt;
            ;;&lt;br /&gt;
        [-+][0-9]*)&lt;br /&gt;
            nice=&amp;quot;nice -n $1&amp;quot;&lt;br /&gt;
            shift&lt;br /&gt;
            ;;&lt;br /&gt;
        *)&lt;br /&gt;
            echo $&amp;quot;$0: Usage: daemon [+/-nicelevel] {program}&amp;quot; &amp;quot;[arg1]...&amp;quot;&lt;br /&gt;
            return 1&lt;br /&gt;
            ;;&lt;br /&gt;
      esac&lt;br /&gt;
    done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
another way - found in adstrtal.sh (middleware start script for EBS)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#&lt;br /&gt;
# Parse Arguments&lt;br /&gt;
#&lt;br /&gt;
&lt;br /&gt;
for nxtarg in $*&lt;br /&gt;
do&lt;br /&gt;
  arg=`echo $nxtarg | sed &amp;#039;s/^//&amp;#039;`&lt;br /&gt;
&lt;br /&gt;
  case $arg in&lt;br /&gt;
    -secureapps)    if test &amp;quot;$secureapps&amp;quot; = &amp;quot;&amp;quot; ; then&lt;br /&gt;
                       secureapps=$arg&lt;br /&gt;
                    else&lt;br /&gt;
                       echo &amp;quot;$0: Duplicate Argument passed : $arg&amp;quot;&lt;br /&gt;
                       usage&lt;br /&gt;
                    fi&lt;br /&gt;
                ;;&lt;br /&gt;
    -nodbchk)       if test &amp;quot;$nodbchk&amp;quot; = &amp;quot;&amp;quot; ; then&lt;br /&gt;
                       nodbchk=$arg&lt;br /&gt;
                    else&lt;br /&gt;
                       echo &amp;quot;$0: Duplicate Argument passed : $arg&amp;quot;&lt;br /&gt;
                       usage&lt;br /&gt;
                    fi&lt;br /&gt;
                ;;&lt;br /&gt;
    -nopromptmsg)   if test &amp;quot;$nopromptmsg&amp;quot; = &amp;quot;&amp;quot; ; then&lt;br /&gt;
                       nopromptmsg=$arg&lt;br /&gt;
                    else&lt;br /&gt;
                       echo &amp;quot;$0: Duplicate Argument passed : $arg&amp;quot;&lt;br /&gt;
                       usage&lt;br /&gt;
                    fi&lt;br /&gt;
                ;;&lt;br /&gt;
    *)              if test &amp;quot;$unpw&amp;quot; = &amp;quot;&amp;quot; ; then&lt;br /&gt;
                       unpw=$arg&lt;br /&gt;
                    else&lt;br /&gt;
                       echo &amp;quot;$0: Duplicate Argument passed : $arg&amp;quot;&lt;br /&gt;
                       usage&lt;br /&gt;
                    fi&lt;br /&gt;
  esac&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
and another in adautocfg.sh&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
for myarg in $*&lt;br /&gt;
do&lt;br /&gt;
&lt;br /&gt;
  arg=`echo $myarg | sed &amp;#039;s/^-//&amp;#039;`&lt;br /&gt;
  case $arg in&lt;br /&gt;
    appspass=*)&lt;br /&gt;
            appspass=`echo $arg | sed &amp;#039;s/appspass=//g&amp;#039;`&lt;br /&gt;
            shift&lt;br /&gt;
            ;;&lt;br /&gt;
    nocustom)&lt;br /&gt;
            myparams=&amp;quot;$myparams $arg&amp;quot;&lt;br /&gt;
            shift&lt;br /&gt;
            ;;&lt;br /&gt;
    noversionchecks)&lt;br /&gt;
            myparams=&amp;quot;$myparams $arg&amp;quot;&lt;br /&gt;
            shift&lt;br /&gt;
            ;;&lt;br /&gt;
    promptmsg=*)&lt;br /&gt;
            promptmsg=`echo $arg | sed &amp;#039;s/promptmsg=//g&amp;#039;`&lt;br /&gt;
            shift&lt;br /&gt;
            ;;&lt;br /&gt;
        *)  echo &amp;quot;$0: unrecognized action specified&amp;quot;&lt;br /&gt;
            exit 1&lt;br /&gt;
  esac&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Run a script on multiple servers===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/ksh&lt;br /&gt;
# ==============================================================================&lt;br /&gt;
# Name         : dosh   (Distributed Oracle SHell)&lt;br /&gt;
# Description  : Runs a command on all Oracle servers&lt;br /&gt;
#&lt;br /&gt;
# Parameters   : h - displays help&lt;br /&gt;
#                v - verbose (default, like all unix commands is silent)&lt;br /&gt;
#                c - command to be executed&lt;br /&gt;
#&lt;br /&gt;
# Example      : ./dosh -v -c &amp;#039;ls -al&amp;#039;&lt;br /&gt;
#&lt;br /&gt;
# Modification History&lt;br /&gt;
# ====================&lt;br /&gt;
# When      Who               What&lt;br /&gt;
# ========= ================= ==================================================&lt;br /&gt;
# 08-FEB-13 Stuart Barkley    Created&lt;br /&gt;
# ==============================================================================&lt;br /&gt;
&lt;br /&gt;
# --------------------------------------------------------------------------&lt;br /&gt;
# this list of servers is generated by the DBAMON tool so will be up to date&lt;br /&gt;
# --------------------------------------------------------------------------&lt;br /&gt;
serverfile=/home/ibmtools/etc/oracle/oracle_servers&lt;br /&gt;
[[ -z &amp;quot;${serverfile}&amp;quot; ]] &amp;amp;&amp;amp; echo &amp;quot;Server list ${serverfile} not found&amp;quot; &amp;amp;&amp;amp; exit 1&lt;br /&gt;
&lt;br /&gt;
serverlist=`cat ${serverfile} | sort -n | tr &amp;quot;\n&amp;quot; &amp;quot; &amp;quot;`&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
# -------------------------&lt;br /&gt;
# get the arguments, if any&lt;br /&gt;
# -------------------------&lt;br /&gt;
while getopts &amp;quot;hvc:&amp;quot; OPT&lt;br /&gt;
do&lt;br /&gt;
    case &amp;quot;$OPT&amp;quot; in&lt;br /&gt;
    h) echo &amp;quot;\nUsage: $0 [-v] [-h] -c &amp;#039;&amp;lt;command_to_be_executed_remotely&amp;gt;&amp;#039;\n&amp;quot;;&lt;br /&gt;
       exit;&lt;br /&gt;
       ;;&lt;br /&gt;
    v) VERBOSE=&amp;quot;Y&amp;quot;;&lt;br /&gt;
       ;;&lt;br /&gt;
    c) CMMND=$OPTARG;&lt;br /&gt;
       ;;&lt;br /&gt;
    *) echo &amp;quot;\nUsage: $0 [-v] [-h] -c &amp;#039;&amp;lt;command_to_be_executed_remotely&amp;gt;&amp;#039;\n&amp;quot;;&lt;br /&gt;
       exit;&lt;br /&gt;
       ;;&lt;br /&gt;
    esac&lt;br /&gt;
done&lt;br /&gt;
shift $((OPTIND-1))&lt;br /&gt;
VERBOSE=${VERBOSE:-&amp;quot;N&amp;quot;}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
# --------------------------------&lt;br /&gt;
# check we have required arguments&lt;br /&gt;
# --------------------------------&lt;br /&gt;
[[ -z $CMMND ]] &amp;amp;&amp;amp; echo &amp;quot;Enter command to be executed like this: $0 -c &amp;#039;ls -al&amp;#039;&amp;quot; &amp;amp;&amp;amp; exit 1&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
# ----------------------------&lt;br /&gt;
# loop over the remote servers&lt;br /&gt;
# ----------------------------&lt;br /&gt;
for server in ${serverlist}&lt;br /&gt;
do&lt;br /&gt;
    if [[ &amp;quot;$VERBOSE&amp;quot; == &amp;quot;Y&amp;quot; ]]; then&lt;br /&gt;
        echo ${server} `date +&amp;#039;%d-%b-%Y %H:%M:%S&amp;#039;`&lt;br /&gt;
        echo &amp;quot;------------------------------------&amp;quot;&lt;br /&gt;
        set -x&lt;br /&gt;
    fi&lt;br /&gt;
    ssh ${server} &amp;quot;$CMMND&amp;quot;&lt;br /&gt;
    set +x&lt;br /&gt;
    [[ &amp;quot;$VERBOSE&amp;quot; == &amp;quot;Y&amp;quot; ]] &amp;amp;&amp;amp; echo&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
to be investigated... this one might be cleverer than mine...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
tmpdir=${TMPDIR:-/tmp}/pssh.$$&lt;br /&gt;
count=0&lt;br /&gt;
while userhost; do&lt;br /&gt;
    ssh -n -o BatchMode=yes ${userhost} &amp;#039;uname -a&amp;#039; &amp;gt; ${tmpdir}/${userhost} 2&amp;gt;&amp;amp;1 &amp;amp;&lt;br /&gt;
    count=`expr $count + 1`&lt;br /&gt;
done &amp;lt; userhost.lst&lt;br /&gt;
while [ $count -gt 0 ]; do&lt;br /&gt;
    wait $pids&lt;br /&gt;
    count=`expr $count - 1`&lt;br /&gt;
done&lt;br /&gt;
echo &amp;quot;Output for hosts are in $tmpdir&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
improved version...&amp;lt;br /&amp;gt;&lt;br /&gt;
just escape double quotes and dollar signs...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/ksh&lt;br /&gt;
# ==============================================================================&lt;br /&gt;
# Name         : dosh   (Distributed Oracle SHell)&lt;br /&gt;
# Description  : Runs a command on all Oracle servers&lt;br /&gt;
#&lt;br /&gt;
# Parameters   : h - displays help&lt;br /&gt;
#                v - verbose (default, like all unix commands is silent)&lt;br /&gt;
#                c - command to be executed&lt;br /&gt;
#&lt;br /&gt;
# Example      : ./dosh -v -c &amp;#039;ls -al&amp;#039;&lt;br /&gt;
#&lt;br /&gt;
# Modification History&lt;br /&gt;
# ====================&lt;br /&gt;
# When      Who               What&lt;br /&gt;
# ========= ================= ==================================================&lt;br /&gt;
# 08-FEB-13 Stuart Barkley    Created&lt;br /&gt;
# 08-JUL-15 Stuart Barkley    Background execution mode&lt;br /&gt;
# ==============================================================================&lt;br /&gt;
# --------------------------------------------------------------------------&lt;br /&gt;
# this list of servers is generated by the DBAMON tool so will be up to date&lt;br /&gt;
# --------------------------------------------------------------------------&lt;br /&gt;
serverfile=/home/ibmtools/etc/oracle/oracle_servers&lt;br /&gt;
[[ -z &amp;quot;${serverfile}&amp;quot; ]] &amp;amp;&amp;amp; echo &amp;quot;Server list ${serverfile} not found&amp;quot; &amp;amp;&amp;amp; exit 1&lt;br /&gt;
&lt;br /&gt;
serverlist=`cat ${serverfile} | sort -n | tr &amp;quot;\n&amp;quot; &amp;quot; &amp;quot;`&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
# -------------------------&lt;br /&gt;
# get the arguments, if any&lt;br /&gt;
# -------------------------&lt;br /&gt;
while getopts &amp;quot;hbvc:&amp;quot; OPT&lt;br /&gt;
do&lt;br /&gt;
    case &amp;quot;$OPT&amp;quot; in&lt;br /&gt;
    h) echo &amp;quot;\nUsage: $0 [-b] [-v] [-h] -c &amp;#039;&amp;lt;command_to_be_executed_remotely&amp;gt;&amp;#039;\n&amp;quot;;&lt;br /&gt;
       exit;&lt;br /&gt;
       ;;&lt;br /&gt;
    b) BACKGROUND=&amp;quot;Y&amp;quot;;&lt;br /&gt;
       ;;&lt;br /&gt;
    v) VERBOSE=&amp;quot;Y&amp;quot;;&lt;br /&gt;
       ;;&lt;br /&gt;
    c) CMMND=$OPTARG;&lt;br /&gt;
       ;;&lt;br /&gt;
    *) echo &amp;quot;\nUsage: $0 [-b] [-v] [-h] -c &amp;#039;&amp;lt;command_to_be_executed_remotely&amp;gt;&amp;#039;\n&amp;quot;;&lt;br /&gt;
       exit;&lt;br /&gt;
       ;;&lt;br /&gt;
    esac&lt;br /&gt;
done&lt;br /&gt;
shift $((OPTIND-1))&lt;br /&gt;
VERBOSE=${VERBOSE:-&amp;quot;N&amp;quot;}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
# --------------------------------&lt;br /&gt;
# check we have required arguments&lt;br /&gt;
# --------------------------------&lt;br /&gt;
[[ -z $CMMND ]] &amp;amp;&amp;amp; echo &amp;quot;Enter command to be executed like this: $0 -c &amp;#039;ls -al&amp;#039;&amp;quot; &amp;amp;&amp;amp; exit 1&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
# ---------------------------------&lt;br /&gt;
# put the thing to be run in a file&lt;br /&gt;
# ---------------------------------&lt;br /&gt;
printf &amp;quot;%s\n&amp;quot; &amp;quot;$CMMND&amp;quot; &amp;gt; /tmp/dosh.$$&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
# ----------------------------&lt;br /&gt;
# loop over the remote servers&lt;br /&gt;
# ----------------------------&lt;br /&gt;
for server in ${serverlist}&lt;br /&gt;
do&lt;br /&gt;
    if [[ &amp;quot;$VERBOSE&amp;quot; == &amp;quot;Y&amp;quot; ]]; then&lt;br /&gt;
        printf &amp;quot;%s\n&amp;quot; ${server} `date +&amp;#039;%d-%b-%Y %H:%M:%S&amp;#039;`&lt;br /&gt;
        printf &amp;quot;%s\n&amp;quot; &amp;quot;------------------------------------&amp;quot;&lt;br /&gt;
        set -x&lt;br /&gt;
    fi&lt;br /&gt;
    scp -q /tmp/dosh.$$ ${server}:/tmp/&lt;br /&gt;
    if [[ &amp;quot;$BACKGROUND&amp;quot; == &amp;quot;Y&amp;quot; ]]; then&lt;br /&gt;
        ssh -n -o BatchMode=yes ${server} &amp;quot;ksh /tmp/dosh.$$; rm -f /tmp/dosh.$$&amp;quot;&amp;gt; /tmp/dosh_${server}.out 2&amp;gt;&amp;amp;1 &amp;amp;&lt;br /&gt;
    else&lt;br /&gt;
        ssh -n -o BatchMode=yes ${server} &amp;quot;ksh /tmp/dosh.$$; rm -f /tmp/dosh.$$&amp;quot;&lt;br /&gt;
    fi&lt;br /&gt;
    set +x&lt;br /&gt;
    [[ &amp;quot;$VERBOSE&amp;quot; == &amp;quot;Y&amp;quot; ]] &amp;amp;&amp;amp; echo&lt;br /&gt;
done&lt;br /&gt;
rm -f /tmp/dosh.$$&lt;br /&gt;
&lt;br /&gt;
[[ &amp;quot;$BACKGROUND&amp;quot; == &amp;quot;Y&amp;quot; ]] &amp;amp;&amp;amp; printf &amp;quot;%s\n&amp;quot; &amp;quot;Type &amp;#039;ls -altr /tmp/dosh*out&amp;#039; to see output from the commands&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===How can a shell script find out what directory it is in?===&lt;br /&gt;
basename $0 does not always give the desired answer (might give &amp;quot;./&amp;quot;!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
DIR=&amp;quot;$(cd &amp;quot;$(dirname &amp;quot;$0&amp;quot;)&amp;quot; &amp;amp;&amp;amp; pwd)&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Array processing===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
array=(1 2 3)&lt;br /&gt;
unset array[2]&lt;br /&gt;
echo ${array[2]}          # null&lt;br /&gt;
indices=(${!array[@]})    # create an array of the indices of &amp;quot;array&amp;quot;&lt;br /&gt;
size=${#indices[@]}       # the size of &amp;quot;array&amp;quot; is the number of indices into it&lt;br /&gt;
size=${#array[@]}         # same&lt;br /&gt;
echo ${array[@]: -1}      # you can use slices to get array elements, -1 is the last one, etc.&lt;br /&gt;
for element in ${array[@]}; do    # iterate over the array without an index&lt;br /&gt;
&lt;br /&gt;
for index in ${indices[@]}        # iterate over the array WITH an index&lt;br /&gt;
do&lt;br /&gt;
    echo &amp;quot;Index: ${index}, Element: ${array[index]}&amp;quot;&lt;br /&gt;
done&lt;br /&gt;
&lt;br /&gt;
for index in ${!array[@]}         # iterate over the array WITH an index, directly&lt;br /&gt;
&lt;br /&gt;
array+=(&amp;quot;new element&amp;quot;)    # append a new element without referring to an index&lt;br /&gt;
((counter++))             # shorter than ((counter=counter+1)) or ((counter+=1))&lt;br /&gt;
if [[ $var == 3 ]]        # you can use the more &amp;quot;natural&amp;quot; comparison operators inside double square brackets&lt;br /&gt;
while [[ $var &amp;lt; 11 ]]     # another example&lt;br /&gt;
echo ${array[${index}-1]  # math inside an array subscript&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Send an email by talking directly to an smtp server===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
telnet smtp.domain.com 25 &amp;lt;&amp;lt;EOTXT&amp;gt;&amp;gt;/tmp/smtp.log&lt;br /&gt;
HELO me.domain.com&lt;br /&gt;
MAIL FROM:&amp;lt;stuart@domain.com&amp;gt;&lt;br /&gt;
RCPT TO:&amp;lt;anne@domain.com&amp;gt;&lt;br /&gt;
DATA&lt;br /&gt;
From: Stuart &amp;lt;stuart@domain.com&amp;gt;&lt;br /&gt;
To: Anne &amp;lt;anne@domain.com&amp;gt;&lt;br /&gt;
Subject: testing smtp email&lt;br /&gt;
&lt;br /&gt;
Hello, this should appear in the body&lt;br /&gt;
.&lt;br /&gt;
QUIT&lt;br /&gt;
EOTXT&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Send an email by talking directly to an smtp server via file descriptor (no telnet! this time), adding authentication===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
&lt;br /&gt;
#&lt;br /&gt;
# mail.sh&lt;br /&gt;
#&lt;br /&gt;
# 2008 - Mike Golvach - eggi@comcast.net&lt;br /&gt;
# 2010 - Rayber&lt;br /&gt;
#&lt;br /&gt;
# Creative Commons Attribution-Noncommercial-Share Alike 3.0 United States License&lt;br /&gt;
#&lt;br /&gt;
&lt;br /&gt;
if [ $# -ne 7 ]&lt;br /&gt;
then&lt;br /&gt;
echo &amp;quot;Usage: $0 FromAdress ToAdress Domain MailServer MailTextFile AuthEmail AuthPass&amp;quot;&lt;br /&gt;
exit 1&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
from=$1&lt;br /&gt;
to=$2&lt;br /&gt;
domain=$3&lt;br /&gt;
mailserver=$4&lt;br /&gt;
mailtext=$5&lt;br /&gt;
authemail=`echo $6|openssl enc -base64|awk &amp;#039;sub(&amp;quot;..$&amp;quot;, &amp;quot;&amp;quot;)&amp;#039;`&lt;br /&gt;
authpass=`echo $7|openssl enc -base64|awk &amp;#039;sub(&amp;quot;..$&amp;quot;, &amp;quot;&amp;quot;)&amp;#039;`&lt;br /&gt;
&lt;br /&gt;
if [ ! -f $mailtext ]&lt;br /&gt;
then&lt;br /&gt;
echo &amp;quot;Cannot find your mail text file. Exiting...&amp;quot;&lt;br /&gt;
exit 1&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
exec 9&amp;lt;&amp;gt;/dev/tcp/$mailserver/25&lt;br /&gt;
echo &amp;quot;HELO $domain&amp;quot; &amp;gt;&amp;amp;9&lt;br /&gt;
read -r temp &amp;lt;&amp;amp;9&lt;br /&gt;
echo &amp;quot;$temp&amp;quot;&lt;br /&gt;
echo &amp;quot;auth login&amp;quot; &amp;gt;&amp;amp;9&lt;br /&gt;
read -r temp &amp;lt;&amp;amp;9&lt;br /&gt;
echo &amp;quot;$authemail&amp;quot; &amp;gt;&amp;amp;9&lt;br /&gt;
read -r temp &amp;lt;&amp;amp;9&lt;br /&gt;
echo &amp;quot;$authpass&amp;quot; &amp;gt;&amp;amp;9&lt;br /&gt;
read -r temp &amp;lt;&amp;amp;9&lt;br /&gt;
echo &amp;quot;Mail From: $from&amp;quot; &amp;gt;&amp;amp;9&lt;br /&gt;
read -r temp &amp;lt;&amp;amp;9&lt;br /&gt;
echo &amp;quot;$temp&amp;quot;&lt;br /&gt;
echo &amp;quot;Rcpt To: $to&amp;quot; &amp;gt;&amp;amp;9&lt;br /&gt;
read -r temp &amp;lt;&amp;amp;9&lt;br /&gt;
echo &amp;quot;$temp&amp;quot;&lt;br /&gt;
echo &amp;quot;Data&amp;quot; &amp;gt;&amp;amp;9&lt;br /&gt;
read -r temp &amp;lt;&amp;amp;9&lt;br /&gt;
echo &amp;quot;$temp&amp;quot;&lt;br /&gt;
cat $mailtext &amp;gt;&amp;amp;9&lt;br /&gt;
echo &amp;quot;.&amp;quot; &amp;gt;&amp;amp;9&lt;br /&gt;
read -r temp &amp;lt;&amp;amp;9&lt;br /&gt;
echo &amp;quot;$temp&amp;quot;&lt;br /&gt;
echo &amp;quot;quit&amp;quot; &amp;gt;&amp;amp;9&lt;br /&gt;
read -r temp &amp;lt;&amp;amp;9&lt;br /&gt;
echo &amp;quot;$temp&amp;quot;&lt;br /&gt;
9&amp;gt;&amp;amp;-&lt;br /&gt;
9&amp;lt;&amp;amp;-&lt;br /&gt;
echo &amp;quot;All Done Sending Email. See above for errors&amp;quot;&lt;br /&gt;
exit 0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== rsync examples===&lt;br /&gt;
Also see [[Distribute files to multiple servers using rsync and ssh]]&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/sh&lt;br /&gt;
ssh  &amp;lt;remote_host&amp;gt; &amp;#039;/bin/mkdir -p /etc /etc/rc.config.d /etc/security /etc/mail&amp;#039;&lt;br /&gt;
rsync --rsync-path /usr/bin/rsync -Liprogtz --out-format=%f%L  /etc/passwd /etc/passwd.post /etc/group /etc/hosts /etc/services /etc/resolv.conf /etc/exclude.rootvg &amp;lt;remote_host&amp;gt;:/etc&lt;br /&gt;
rsync --rsync-path /usr/bin/rsync -Liprogtz --out-format=%f%L  /etc/hosts.allow.xcat &amp;lt;remote_host&amp;gt;:/etc/hosts.allow&lt;br /&gt;
rsync --rsync-path /usr/bin/rsync -Liprogtz --out-format=%f%L  /etc/rc.config.d/sap &amp;lt;remote_host&amp;gt;:/etc/rc.config.d&lt;br /&gt;
rsync --rsync-path /usr/bin/rsync -Liprogtz --out-format=%f%L  /etc/security/group /etc/security/limits /etc/security/login.cfg /etc/security/passwd /etc/security/user &amp;lt;remote_host&amp;gt;:/etc/security&lt;br /&gt;
rsync --rsync-path /usr/bin/rsync -Liprogtz --out-format=%f%L  /etc/mail/sendmail.cf &amp;lt;remote_host&amp;gt;:/etc/mail&lt;br /&gt;
&lt;br /&gt;
rsync -av --progress /home/ibmtools/scripts/oracle/* benouerp07:/home/ibmtools/scripts/oracle/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Handy aliases===&lt;br /&gt;
Strip out comments and blank lines from a file&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alias strip=&amp;#039;grep -Ev &amp;#039;\&amp;#039;&amp;#039;^(#|$)&amp;#039;\&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Does a ps and a grep&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alias psg=&amp;#039;ps -ef | grep -v $$ | grep -i &amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Getting a decent listing of filesystem space available. It is ordered such that the filesystems with no space left are at the end.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
OS=$(uname -s)&lt;br /&gt;
[[ &amp;quot;$OS&amp;quot; == &amp;quot;SunOS&amp;quot; ]] &amp;amp;&amp;amp; alias dfg=&amp;#039;df -h|sed -e &amp;#039;1d&amp;#039;|sort -n -k5|awk &amp;#039;\&amp;#039;&amp;#039; BEGIN {printf(&amp;quot;%-35s%-10s%-10s%-6s%-30s\n&amp;quot;,&amp;quot;Filesystem&amp;quot;,&amp;quot;Total&amp;quot;,&amp;quot;Free&amp;quot;,&amp;quot;%Used&amp;quot;,&amp;quot;Mounted on&amp;quot;)} {printf(&amp;quot;%-35s%-10s%-10s%-6s%-30s\n&amp;quot;,$1,$2,$4,$5,$6)}&amp;#039;\&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
[[ &amp;quot;$OS&amp;quot; == &amp;quot;AIX&amp;quot; ]]   &amp;amp;&amp;amp; alias dfg=&amp;#039;df -g|sed -e &amp;#039;1d&amp;#039;|sort -n -k4|awk &amp;#039;\&amp;#039;&amp;#039; BEGIN {printf(&amp;quot;%-35s%-10s%-10s%-6s%-30s\n&amp;quot;,&amp;quot;Filesystem&amp;quot;,&amp;quot;Total GB&amp;quot;,&amp;quot;Free&amp;quot;,&amp;quot;%Used&amp;quot;,&amp;quot;Mounted on&amp;quot;)} {printf(&amp;quot;%-35s%-10s%-10s%-6s%-30s\n&amp;quot;,$1,$2,$3,$4,$7)}&amp;#039;\&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
A handy way of listing subdirectories and their files&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alias filetree=&amp;quot;find . -print | sed -e &amp;#039;s;[^/]*/;|____;g;s;____|; |;g&amp;#039;&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Watch progress of a copy&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alias cpProgress=&amp;quot;rsync --progress -ravz&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Reboots Linksys router&amp;lt;pre&amp;gt;&lt;br /&gt;
alias rebootlinksys=&amp;quot;curl -u &amp;#039;admin:password&amp;#039; &amp;#039;http://192.168.1.2/setup.cgi?todo=reboot&amp;#039;&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Nice one for bash. Colour codes the prompt depending on the outcome of the previous command&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
bash_prompt_command()&lt;br /&gt;
{&lt;br /&gt;
    RTN=$?&lt;br /&gt;
    prevCmd=$(prevCmd $RTN)&lt;br /&gt;
}&lt;br /&gt;
PROMPT_COMMAND=bash_prompt_command&lt;br /&gt;
prevCmd()&lt;br /&gt;
{&lt;br /&gt;
    if [ $1 == 0 ] ; then&lt;br /&gt;
        echo $GREEN&lt;br /&gt;
    else&lt;br /&gt;
        echo $RED&lt;br /&gt;
    fi&lt;br /&gt;
}&lt;br /&gt;
if [ $(tput colors) -gt 0 ] ; then&lt;br /&gt;
    RED=$(tput setaf 1)&lt;br /&gt;
    GREEN=$(tput setaf 2)&lt;br /&gt;
    RST=$(tput op)&lt;br /&gt;
fi&lt;br /&gt;
export PS1=&amp;quot;\[\e[36m\]\u.\h.\W\[\e[0m\]\[\$prevCmd\]&amp;gt;\[$RST\]&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Mmmm, to be looked into. Executes remote commands on a unix box using curl.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#/bin/sh&lt;br /&gt;
#&lt;br /&gt;
# WAG320N-HACK&lt;br /&gt;
# Ver. 1.0&lt;br /&gt;
# 12/09/2010&lt;br /&gt;
#&lt;br /&gt;
# This program is free software: you can redistribute it and/or modify&lt;br /&gt;
# it under the terms of the GNU General Public License as published by&lt;br /&gt;
# the Free Software Foundation, either version 3 of the License, or&lt;br /&gt;
# (at your option) any later version.&lt;br /&gt;
#&lt;br /&gt;
# This program is distributed in the hope that it will be useful,&lt;br /&gt;
# but WITHOUT ANY WARRANTY; without even the implied warranty of&lt;br /&gt;
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the&lt;br /&gt;
# GNU General Public License for more details.&lt;br /&gt;
#&lt;br /&gt;
# You should have received a copy of the GNU General Public License&lt;br /&gt;
# along with this program.  If not, see &amp;lt;http://www.gnu.org/licenses/&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
# Set username and password in the form of &amp;quot;username:password&amp;quot;&lt;br /&gt;
# example: &amp;quot;admin:admin&amp;quot;&lt;br /&gt;
my_access=&amp;quot;admin:admin&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Parameters test&lt;br /&gt;
if [ -z &amp;quot;$1&amp;quot; ]&lt;br /&gt;
then&lt;br /&gt;
  echo &amp;quot;wag320n-hack.sh: missing remote command&amp;quot;&lt;br /&gt;
  echo &amp;quot;usage: wag320n-hack.sh &amp;lt;remote command&amp;gt;&amp;quot;&lt;br /&gt;
  echo &amp;quot;example: wag320n-hack.sh /bin/ls -la /usr/sbin&amp;quot;&lt;br /&gt;
  echo &amp;quot;Note: always use full path&amp;quot;&lt;br /&gt;
  echo &amp;quot;&amp;quot;&lt;br /&gt;
  echo &amp;quot;wag320n-hack.sh - Ver. 1.0 - 12/09/2010&amp;quot;&lt;br /&gt;
  echo &amp;quot;Licensed under GPL V. 3&amp;quot;&lt;br /&gt;
  echo &amp;quot;&amp;quot;&lt;br /&gt;
  exit 0&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
# Get the command&lt;br /&gt;
my_command=&amp;quot;ping_size=&amp;quot;&amp;#039;$(&amp;#039;&amp;quot;$@&amp;quot;&amp;#039; 1&amp;gt;&amp;amp;2)&amp;#039;&lt;br /&gt;
&lt;br /&gt;
curl -s -G -u &amp;quot;$my_access&amp;quot; --data-urlencode &amp;#039;todo=ping_test&amp;#039; --data-urlencode &amp;#039;this_file=Diagnostics.htm&amp;#039; --data-urlencode &amp;#039;next_file=Ping.htm&amp;#039; --data-urlencode &amp;#039;c4_ping_ipaddr=192.168.1.1&amp;#039; --data-urlencode &amp;#039;ping_timeout=5000&amp;#039; --data-urlencode &amp;#039;ping_interval=1000&amp;#039; --data-urlencode &amp;#039;ping_number=1&amp;#039; --data-urlencode &amp;quot;$my_command&amp;quot; http://192.168.1.1/setup.cgi | sed -e &amp;#039;/HTTP\/1.0 200 OK/q&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===How to configure SSH with public/private keys===&lt;br /&gt;
* [http://www.unixpeople.com/HOWTO/configuring.ssh.html unixpeople.com]&lt;br /&gt;
===Use SSH config file===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Host server10&lt;br /&gt;
  Hostname 1.2.3.4&lt;br /&gt;
  IdentityFile ~/.ssh/id_dsa&lt;br /&gt;
  user foobar&lt;br /&gt;
  Port 30000&lt;br /&gt;
  ForwardX11Trusted yes&lt;br /&gt;
  TCPKeepAlive yes&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
then just connect using&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ssh server10&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===A decent sed tutorial===&lt;br /&gt;
From [http://www.grymoire.com/Unix/Sed.html grymoire.com]&lt;br /&gt;
===A decent korn/bash shell tutorial===&lt;br /&gt;
From [http://www.dartmouth.edu/~rc/classes/ksh/print_pages.shtml dartmouth.edu]&lt;br /&gt;
Reproduced here just in case it disappears!&lt;br /&gt;
[[Advanced shell scripting]]&lt;br /&gt;
&lt;br /&gt;
===trap===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
     Example Handling Traps With ksh - Discussion of the kill command&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
EXAMPLE TEMPLATE:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
PRODUCT:    HP-UX 11iV1 Version B.11.11&lt;br /&gt;
            HP Tru64 V5.1B PK4&lt;br /&gt;
            Sun/Solaris SunOS V5.8&lt;br /&gt;
            Linux 2.6 kernel&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
COMPONENT:  ksh&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
SOURCE:     Philippe Vouters&lt;br /&gt;
            Fontainebleau/France&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
LOW COST HIGH-TECH PRODUCTS:  http://techno-star.fr&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
OVERVIEW:&lt;br /&gt;
&lt;br /&gt;
The ksh script below shows how to eventually handle traps in the situation &lt;br /&gt;
where someone might try to kill a script by killing individual commands run &lt;br /&gt;
by that script or the entire process group a script is running in. The kill &lt;br /&gt;
command (usually a shell builtin) may be used to send a signal to a process &lt;br /&gt;
group (with the -&amp;lt;pid&amp;gt; syntax) or an individual process. The example ksh &lt;br /&gt;
script below runs /bin/sleep as the foreground process, the example ksh &lt;br /&gt;
scripts immediately returns when the /bin/sleep process has terminated. Most &lt;br /&gt;
signals sent to the shell are ignored until after the foreground process &lt;br /&gt;
terminates. This is in order to avoid creating zombie processes. Therefore a &lt;br /&gt;
kill &amp;lt;pid&amp;gt; on the example ksh script waits for the termination of the &lt;br /&gt;
/bin/sleep process.&lt;br /&gt;
&lt;br /&gt;
The status value $? in the trap refers to the exit status of the command to run &lt;br /&gt;
and therefore is the exit status of the /bin/sleep process. The called function &lt;br /&gt;
in the trap handler shows how to correctly examine the effect of the kill &lt;br /&gt;
command on the shell or it&amp;#039;s children.&lt;br /&gt;
&lt;br /&gt;
To examine the value of $? in a trap handler means that you must understand what&lt;br /&gt;
it can be set and how different signals delivered to either the shell or the &lt;br /&gt;
foreground process (or the process group) might affect the value of $?.&lt;br /&gt;
&lt;br /&gt;
The example shell script prints $? using echo but it does not perform tests on &lt;br /&gt;
the value of $?. For a complete solution when attempting to trap signals in a &lt;br /&gt;
shell you would also need code that examined the value of $? after the &lt;br /&gt;
foreground process had completed.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*** CAUTION ***&lt;br /&gt;
&lt;br /&gt;
This sample script has been tested using HP-UX B.11.11, HP Tru64 V5.1B PK4, &lt;br /&gt;
SunOS V5.8 and Fedora Core 4 (homed version of Red Hat Linux).  However, we&lt;br /&gt;
cannot guarantee its effectiveness because of the possibility of error in &lt;br /&gt;
transmitting or implementing it. It is meant to be used as a template for &lt;br /&gt;
writing your own scripts, and may require modification for use on your system. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
SCRIPT NOTES:&lt;br /&gt;
&lt;br /&gt;
To notice that the ksh script and /bin/sleep share the same process group&lt;br /&gt;
identifier (PGID), issue the following commands:&lt;br /&gt;
&lt;br /&gt;
[philippe@victor ~]$ who&lt;br /&gt;
philippe :0           Jan 10 10:16&lt;br /&gt;
philippe pts/1        Jan 10 21:30 (:0.0)&lt;br /&gt;
philippe pts/2        Jan 10 21:30 (:0.0)&lt;br /&gt;
[philippe@victor ~]$ tty&lt;br /&gt;
/dev/pts/1&lt;br /&gt;
[philippe@victor ~]$ ps -j -t pts/2&lt;br /&gt;
  PID  PGID   SID TTY          TIME CMD&lt;br /&gt;
11072 11072 11072 pts/2    00:00:00 bash&lt;br /&gt;
11113 11113 11072 pts/2    00:00:00 ksh&lt;br /&gt;
11116 11113 11072 pts/2    00:00:00 sleep&lt;br /&gt;
&lt;br /&gt;
In this case sending kill -INT -11113 will send SIGINT to the process group &lt;br /&gt;
11113. Both of the ksh and sleep processes are contained within this process &lt;br /&gt;
group.&lt;br /&gt;
&lt;br /&gt;
Important Note:&lt;br /&gt;
&lt;br /&gt;
On HP-UX, you have to $ export UNIX95=1 in order to be able to use the&lt;br /&gt;
-j option of the ps command.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
SCRIPT:&lt;br /&gt;
&lt;br /&gt;
                             COPYRIGHT (C) 2005 BY&lt;br /&gt;
                              HEWLETT-PACKARD COMPANY&lt;br /&gt;
                                ALL RIGHTS RESERVED.&lt;br /&gt;
&lt;br /&gt;
     THIS SOFTWARE IS FURNISHED UNDER A LICENSE AND MAY BE USED AND COPIED&lt;br /&gt;
     ONLY IN ACCORDANCE WITH THE TERMS OF SUCH LICENSE AND WITH THE INCLUSION&lt;br /&gt;
     OF THE ABOVE COPYRIGHT NOTICE.  THIS SOFTWARE OR ANY OTHER COPIES&lt;br /&gt;
     THEREOF MAY NOT BE PROVIDED OR OTHERWISE MADE AVAILABLE TO ANY OTHER&lt;br /&gt;
     PERSON.  NO TITLE TO AND OWNERSHIP OF THE SOFTWARE IS HEREBY TRANSFERRED.&lt;br /&gt;
&lt;br /&gt;
     THE INFORMATION IN THIS SOFTWARE IS SUBJECT TO CHANGE WITHOUT NOTICE AND&lt;br /&gt;
     SHOULD NOT BE CONSTRUED AS A COMMITMENT BY HEWLETT-PACKARD COMPANY.&lt;br /&gt;
&lt;br /&gt;
     HP ASSUMES NO RESPONSIBILITY FOR THE USE OR RELIABILITY OF ITS&lt;br /&gt;
     SOFTWARE ON EQUIPMENT THAT IS NOT SUPPLIED BY HP.&lt;br /&gt;
&lt;br /&gt;
     NO RESPONSIBILITY IS ASSUMED FOR THE USE OR RELIABILITY OF SOFTWARE&lt;br /&gt;
     ON EQUIPMENT THAT IS NOT SUPPLIED BY HEWLETT-PACKARD COMPANY.&lt;br /&gt;
&lt;br /&gt;
     SUPPORT FOR THIS SOFTWARE IS NOT COVERED UNDER ANY HP SOFTWARE&lt;br /&gt;
     PRODUCT SUPPORT CONTRACT, BUT MAY BE PROVIDED UNDER THE TERMS OF THE&lt;br /&gt;
     CONSULTING AGREEMENT UNDER WHICH THIS SOFTWARE WAS DEVELOPED.&lt;br /&gt;
&lt;br /&gt;
#!/bin/ksh&lt;br /&gt;
function handle_signal&lt;br /&gt;
{&lt;br /&gt;
        print -n &amp;quot;pid $$ recieved $2 &amp;quot;&lt;br /&gt;
        if [[ $1 = 0 ]];then&lt;br /&gt;
            print but foreground command ended successfully&lt;br /&gt;
        else&lt;br /&gt;
                if [[ $1 = $3 ]];then&lt;br /&gt;
                    print and so did the last foreground command&lt;br /&gt;
                else&lt;br /&gt;
                    print -n &amp;quot;and the exit status of the last foreground &amp;quot;&lt;br /&gt;
                    print command was $1&lt;br /&gt;
                fi&lt;br /&gt;
        fi&lt;br /&gt;
        # Kill our process group and then ourselves with SIGTERM, giving a &lt;br /&gt;
        # pid of 0 sends the signal to our process group. Killing the process&lt;br /&gt;
        # group should kill us as well, this assumes that SIGTERM is not &lt;br /&gt;
        # handled by any process in the process group.&lt;br /&gt;
        #&lt;br /&gt;
        # This code could be replaced with an exit with an exit value that&lt;br /&gt;
        # would indicate what the problem was to the caller. That is replace &lt;br /&gt;
        # these two lines with:&lt;br /&gt;
        #&lt;br /&gt;
        # exit $3&lt;br /&gt;
        #&lt;br /&gt;
        # or a specific exit code could be used.&lt;br /&gt;
        #&lt;br /&gt;
        kill -TERM 0&lt;br /&gt;
        kill -TERM $$&lt;br /&gt;
        }&lt;br /&gt;
OS=$(uname -a | awk &amp;#039;{print $1}&amp;#039;)&lt;br /&gt;
if [[ &amp;quot;$OS&amp;quot; = &amp;quot;Linux&amp;quot; ]]; then&lt;br /&gt;
    offset=256&lt;br /&gt;
elif [[ (&amp;quot;$OS&amp;quot; = &amp;quot;HP-UX&amp;quot;) || &lt;br /&gt;
        (&amp;quot;$OS&amp;quot; = &amp;quot;SunOS&amp;quot;) || &lt;br /&gt;
        (&amp;quot;$OS&amp;quot; = &amp;quot;OSF1&amp;quot;) ]]; then&lt;br /&gt;
   offset=128&lt;br /&gt;
fi&lt;br /&gt;
trap &amp;#039;RC=$?; handle_signal $RC SIGINT $offset+2&amp;#039; INT&lt;br /&gt;
trap &amp;#039;RC=$?; handle_signal $RC SIGQUIT $offset+3&amp;#039; QUIT&lt;br /&gt;
/bin/sleep 20&lt;br /&gt;
echo $?&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===DNS not working===&lt;br /&gt;
Ping to an IP address works&lt;br /&gt;
 ping 74.125.136.103&lt;br /&gt;
but this doesn&amp;#039;t&lt;br /&gt;
 ping www.google.com&lt;br /&gt;
&lt;br /&gt;
Check resolv.conf&lt;br /&gt;
 cat /etc/resolv.conf&lt;br /&gt;
 nameserver 95.130.132.17&lt;br /&gt;
 nameserver 95.130.132.18&lt;br /&gt;
I had changed internet provider and forgot to update this. Just to set it to the router address and let that do the resolution&lt;br /&gt;
 nameserver 192.168.1.1&lt;br /&gt;
&lt;br /&gt;
===File descriptors===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
exec 3&amp;lt;&amp;gt; /tmp/foo  #open fd 3 for r/w&lt;br /&gt;
echo &amp;quot;test&amp;quot; &amp;gt;&amp;amp;3&lt;br /&gt;
exec 3&amp;gt;&amp;amp;- #close fd 3.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
exec 3&amp;lt;&amp;gt; myfile.txt&lt;br /&gt;
while read line &amp;lt;&amp;amp;3&lt;br /&gt;
do {&lt;br /&gt;
  echo &amp;quot;$line&amp;quot;&lt;br /&gt;
  (( Lines++ ));                   #  Incremented values of this variable&lt;br /&gt;
                                   #+ accessible outside loop.&lt;br /&gt;
                                   #  No subshell, no problem.&lt;br /&gt;
}&lt;br /&gt;
done&lt;br /&gt;
exec 3&amp;gt;&amp;amp;-&lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;Number of lines read = $Lines&amp;quot;     # 8&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Mmm. See our output and also tee it to a log file!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
&lt;br /&gt;
echo hello&lt;br /&gt;
&lt;br /&gt;
if test -t 1; then&lt;br /&gt;
    # Stdout is a terminal.&lt;br /&gt;
    exec &amp;gt;log&lt;br /&gt;
else&lt;br /&gt;
    # Stdout is not a terminal.&lt;br /&gt;
    npipe=/tmp/$$.tmp&lt;br /&gt;
    trap &amp;quot;rm -f $npipe&amp;quot; EXIT&lt;br /&gt;
    mknod $npipe p&lt;br /&gt;
    tee &amp;lt;$npipe log &amp;amp;&lt;br /&gt;
    exec 1&amp;gt;&amp;amp;-&lt;br /&gt;
    exec 1&amp;gt;$npipe&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
echo goodbye&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Create new image with kvm===&lt;br /&gt;
Ref: http://www.cyberciti.biz/faq/kvm-virtualization-in-redhat-centos-scientific-linux-6/&amp;lt;br /&amp;gt;&lt;br /&gt;
Build an empty space for a CentOS virtual machine&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
qemu-img create -f qcow2 centos.img 12G&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Tried creating image with&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo virt-install -n CentOS --description &amp;quot;Trying out CentOS&amp;quot; --ram=1024 --vcpus=1 --cpu host --hvm --cdrom /home/bey9at77/Downloads/c6-x86_64-20130910-1.qcow2 --graphics vnc --disk path=/var/lib/libvirt/images/centos.img,bus=virtio,size=10&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
gives error&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Starting install...&lt;br /&gt;
Allocating &amp;#039;centos.img&amp;#039;                                                                                                                                                                                               |  10 GB     00:00     &lt;br /&gt;
ERROR    internal error Process exited while reading console log output: char device redirected to /dev/pts/1&lt;br /&gt;
qemu-kvm: -drive file=/home/bey9at77/Downloads/c6-x86_64-20130910-1.qcow2.bz2,if=none,media=cdrom,id=drive-ide0-1-0,readonly=on,format=raw: could not open disk image /home/bey9at77/Downloads/c6-x86_64-20130910-1.qcow2: Permission denied&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===rpm / yum commands===&lt;br /&gt;
====Install an RPM Package====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rpm -ivh pidgin-2.7.9-5.el6.2.i686.rpm&lt;br /&gt;
&lt;br /&gt;
-i - install&lt;br /&gt;
-v - verbose&lt;br /&gt;
-h - print progress hashes&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Check dependencies of RPM Package before Installing====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rpm -qpR BitTorrent-5.2.2-1-Python2.4.noarch.rpm&lt;br /&gt;
&lt;br /&gt;
-q - query&lt;br /&gt;
-p - list package capabilities&lt;br /&gt;
-R - list dependent package capabilities&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Install RPM Package with all dependencies====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
yum install BitTorrent-5.2.2-1-Python2.4.noarch.rpm&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Install RPM Package with all dependencies (when RPM has been downloaded to local machine)====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
yum localinstall BitTorrent-5.2.2-1-Python2.4.noarch.rpm&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Force Install a RPM Package without dependencies====&lt;br /&gt;
Package will not work if dependencies are required&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rpm -ivh --nodeps BitTorrent-5.2.2-1-Python2.4.noarch.rpm&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Check an Installed RPM Package====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rpm -q BitTorrent&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====List all files of an installed RPM package====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rpm -ql BitTorrent&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====List All Installed RPM Packages====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rpm -qa&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Query information about an installed RPM package====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rpm -qi vsftpd&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Query information about a not yet installed RPM package====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rpm -qip sqlbuddy-1.3.3-1.noarch.rpm&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====(Forcibly) Remove an RPM Package====&lt;br /&gt;
Use package name (as seen in -qi above), not full name&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rpm -ev (--nodeps) vsftpd&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Query a file that was installed as part of an RPM Package (which package contained this file)====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rpm -qf /usr/bin/htpasswd&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Verify an RPM package====&lt;br /&gt;
Compares information of installed files of the package against the rpm database&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rpm -Vp sqlbuddy-1.3.3-1.noarch.rpm&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Rebuild corrupted RPM database====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cd /var/lib&lt;br /&gt;
rm __db*&lt;br /&gt;
rpm --rebuilddb&lt;br /&gt;
rpmdb_verify Packages&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Install rpmforge repository===&lt;br /&gt;
* Download rpmforge-release-0.5.3-1.el6.rf.x86_64.rpm&lt;br /&gt;
* Import the key&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo rpm --import http://apt.sw.be/RPM-GPG-KEY.dag.txt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Install the repository&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo rpm -i rpmforge-release-0.5.3-1.el6.rf.x86_64.rpm&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Check the installation&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rpm -K rpmforge-release-0.5.3-1.el6.rf.x86_64.rpm&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Test it&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo yum install terminator&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Install rpmfusion repository===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
su -c &amp;#039;yum localinstall --nogpgcheck http://download1.rpmfusion.org/free/el/updates/6/i386/rpmfusion-free-release-6-1.noarch.rpm http://download1.rpmfusion.org/nonfree/el/updates/6/i386/rpmfusion-nonfree-release-6-1.noarch.rpm&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===config file for yum===&lt;br /&gt;
Checkout this file for global yum config&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/etc/sysconfig/yum-cron-background&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Setup Oracle Enterprise Linux (RedHat) with yum server===&lt;br /&gt;
You need to download the yum .repo file from the server, as per the steps below. After this, you need to enable a flag in the .repo file as per your operating system version. Having done these two steps, when you run yum install &amp;lt;pkgname&amp;gt; command on your linux box, the Oracle&amp;#039;s yum server will be scanned, the dependent &amp;amp; the relevant rpm&amp;#039;s will be download and installed for you.&amp;lt;br /&amp;gt;&lt;br /&gt;
 cd /etc/yum.repos.d&lt;br /&gt;
To download files here&lt;br /&gt;
 wget http://public-yum.oracle.com/public-yum-el5.repo&lt;br /&gt;
&lt;br /&gt;
A file named public-yum-el5.repo will be created in your directory&amp;lt;br /&amp;gt;&lt;br /&gt;
Edit this file and enter enabled=1 against the operating systems which is relevant to you&lt;br /&gt;
 vi public-yum-el5.repo&lt;br /&gt;
&lt;br /&gt;
Next run the yum command&lt;br /&gt;
 yum install package-name&lt;br /&gt;
&lt;br /&gt;
===To change to static IP address (Raspberry Pi)===&lt;br /&gt;
As root:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cd /etc/networks&lt;br /&gt;
vi interfaces&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
replace the line “iface eth0 inet dhcp” with&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
iface eth0 inet static&lt;br /&gt;
address 192.168.1.100&lt;br /&gt;
netmask 255.255.255.0&lt;br /&gt;
gateway 192.168.1.1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You should also take a look at the file /etc/resolv.conf and check it has a nameserver entry (probably pointing at your default gateway) or direct to your ISP name servers.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
nameserver 192.168.1.1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Troubleshoot wireless network problems===&lt;br /&gt;
* [https://www.blackmoreops.com/2014/09/18/connect-to-wifi-network-from-command-line-in-linux/ connect to wifi network from command-line in linux - from blackmoreops.com]&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Short summary of all the things you need to do in just few lines&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
root@kali:~# iw dev&lt;br /&gt;
root@kali:~# ip link set wlan0 up&lt;br /&gt;
root@kali:~# iw wlan0 scan&lt;br /&gt;
root@kali:~# wpa_passphrase blackMOREOps &amp;gt;&amp;gt; /etc/wpa_supplicant.conf&lt;br /&gt;
root@kali:~# wpa_supplicant -i wlan0 -c /etc/wpa_supplicant.conf&lt;br /&gt;
root@kali:~# iw wlan0 link&lt;br /&gt;
root@kali:~# dhclient wlan0&lt;br /&gt;
root@kali:~# ping 8.8.8.8&lt;br /&gt;
(Where wlan0 is wifi adapter and blackMOREOps is SSID)&lt;br /&gt;
(Add Routing manually)&lt;br /&gt;
root@kali:~# ip route add default via 10.0.0.138 dev wlan0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===To change to static IP address (Redhat/CentOS)===&lt;br /&gt;
As root:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
vi /etc/sysconfig/network-scripts/ifcfg-eth0&lt;br /&gt;
DEVICE=eth0&lt;br /&gt;
BOOTPROTO=STATIC&lt;br /&gt;
IPADDR=192.168.1.111&lt;br /&gt;
NETMASK=255.255.255.0&lt;br /&gt;
GATEWAY=192.168.1.1&lt;br /&gt;
ONBOOT=yes&lt;br /&gt;
DNS1=8.8.8.8&lt;br /&gt;
DNS2=8.8.4.4&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Resrart the network interface&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/etc/init.d/network stop&lt;br /&gt;
/etc/init.d/network start&lt;br /&gt;
or&lt;br /&gt;
service network restart&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Check name server entry in resolv.conf&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
vi /etc/resolv.conf&lt;br /&gt;
nameserver 192.168.1.1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Enable processes / services to start at boot time===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo chkconfig httpd on&lt;br /&gt;
sudo chkconfig mysqld on&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Run a command on lots of servers in parallel===&lt;br /&gt;
This is a damn fine AIX utility - part of the CSM Distributed Shell.&lt;br /&gt;
 dsh -a &amp;quot;ls -al /etc/apache2/*conf&amp;quot;&lt;br /&gt;
will list the Apache configuration file on all reachable servers (nodes)&lt;br /&gt;
===Download a gzip file and pipe it into tar===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cd ~ &amp;amp;&amp;amp; wget -O - &amp;quot;https://www.dropbox.com/download?plat=lnx.x86_64&amp;quot; | tar xzf -&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Check in a script to make sure it is run only by root===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
RUID=`/usr/bin/id|$AWK -F\( &amp;#039;{print $1}&amp;#039;|$AWK -F\= &amp;#039;{print $2}&amp;#039;`&lt;br /&gt;
if [ ${RUID} != &amp;quot;0&amp;quot; ];then&lt;br /&gt;
   $ECHO &amp;quot;This script must be executed as root&amp;quot;&lt;br /&gt;
   exit 1&lt;br /&gt;
fi&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Set terminal to use Backspace key to erase previous character instead of Control-H===&lt;br /&gt;
Been looking for this for a long time.&amp;lt;br /&amp;gt;&lt;br /&gt;
You can put:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
stty erase &amp;lt;CTRL-V&amp;gt;&amp;lt;Backspace key&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
in your .profile but this will be ruined if you do a copy/paste into another file.&amp;lt;br /&amp;gt;&lt;br /&gt;
I wanted a way of doing this without entering the control character in the .profile. Finally stumbled upon it. And it&amp;#039;s so simple. Just escape the caret!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
stty erase \^?&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Put this in the .profile. It&amp;#039;s copy/pastable and it works!&amp;lt;br /&amp;gt;&lt;br /&gt;
If you want CTRL-H to be your erase character, just do this:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
stty erase \^H&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Play with the terminal settings and reset them again either side of requesting a password===&lt;br /&gt;
The -g option of stty gives a compact list of all the settings or the terminal and can be used as input to stty&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
OLDCONFIG=`stty -g`          # save terminal configuration&lt;br /&gt;
stty -echo                   # turn character echoing off&lt;br /&gt;
echo &amp;quot;Enter password: \c&amp;quot;&lt;br /&gt;
read PASSWD                  # get the password&lt;br /&gt;
stty $OLDCONFIG              # restore terminal configuration&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Reset terminal to &amp;quot;sane&amp;quot; characteristics===&lt;br /&gt;
If you&amp;#039;ve done a cat of a binary file or something else weird and your terminal is left in a mess, the following key sequence should bring it back to normal&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;CTRL-J&amp;gt;stty sane&amp;lt;CTRL-J&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Install OpenOffice on RedHat Enterprise when yum install doesn&amp;#039;t!===&lt;br /&gt;
Download Package&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
wget http://sourceforge.net/projects/openofficeorg.mirror/files/4.0.1/binaries/en-US/Apache_OpenOffice_4.0.1_Linux_x86-64_install-rpm_en-US.tar.gz/download -O Apache_OpenOffice_4.0.1_Linux_x86-64_install-rpm_en-US.tar.gz&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Change to root&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo su -&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Remove the old stuff&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
yum remove openoffice* libreoffice*&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Extract Package&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
tar -xvf Apache_OpenOffice_4.0.1*&lt;br /&gt;
cd en-US&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Install Package and exit root&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rpm -Uvh RPMS/*.rpm RPMS/desktop-integration/openoffice4.0-redhat-*.rpm&lt;br /&gt;
exit&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Start it&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
openoffice4&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===What does this do?===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
while IFS= read -r line; do&lt;br /&gt;
    echo &amp;quot;[$(date &amp;quot;+%F %T&amp;quot;)] - $line&amp;quot;&lt;br /&gt;
done &amp;lt; &amp;lt;(iwevent)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
while IFS= read -r line; do&lt;br /&gt;
    printf &amp;quot;%s\n%s\n&amp;quot; &amp;quot;$line&amp;quot; &amp;quot;Yohooo! One more package.&amp;quot;&lt;br /&gt;
done &amp;lt; &amp;lt;(tcpdump -i any -nS)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===List of Special Characters and what they mean===&lt;br /&gt;
From [http://www.grymoire.com/Unix/Quote.html Bruce Barnett]&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Character	Where	Meaning&lt;br /&gt;
&amp;lt;RETURN&amp;gt;	csh, sh	Execute command&lt;br /&gt;
#	csh, sh, ASCII files	Start a comment&lt;br /&gt;
&amp;lt;SPACE&amp;gt;	csh, sh	Argument separator&lt;br /&gt;
`	csh, sh	Command substitution&lt;br /&gt;
&amp;quot;	csh, sh	Weak Quotes&lt;br /&gt;
&amp;#039;	csh, sh	Strong Quotes&lt;br /&gt;
\	csh, sh	Single Character Quote&lt;br /&gt;
variable	sh, csh	Variable&lt;br /&gt;
variable	csh, sh	Same as variable&lt;br /&gt;
|	csh, sh	Pipe character&lt;br /&gt;
^	sh	Pipe Character&lt;br /&gt;
&amp;amp;	csh, sh	Run program in background&lt;br /&gt;
?	csh, sh	Match one character&lt;br /&gt;
*	csh, sh	Match any number of characters&lt;br /&gt;
;	csh, sh	Command separator&lt;br /&gt;
;;	sh	End of Case statement&lt;br /&gt;
~	csh	Home Directory&lt;br /&gt;
~user	csh	User&amp;#039;s Home Directory&lt;br /&gt;
!	csh	History of Commands&lt;br /&gt;
-	Programs	Start of optional argument&lt;br /&gt;
$#	csh, sh	Number of arguments to script&lt;br /&gt;
$*	csh, sh	Arguments to script&lt;br /&gt;
$@	sh	Original arguments to script&lt;br /&gt;
$-	sh	Flags passed to shell&lt;br /&gt;
$?	sh	Status of previous command&lt;br /&gt;
$$	sh	Process identification number&lt;br /&gt;
$!	sh	PID of last background job&lt;br /&gt;
&amp;amp;&amp;amp;	sh	Short-circuit AND&lt;br /&gt;
||	sh	Short-circuit OR&lt;br /&gt;
.	csh, sh	Typ. filename extension&lt;br /&gt;
.	sh	Source a file and execute as command&lt;br /&gt;
:	sh	Nothing command&lt;br /&gt;
:	sh	Separates Values in environment variables&lt;br /&gt;
:	csh	Variable modifier&lt;br /&gt;
Character	Where	Meaning&lt;br /&gt;
[ ]	csh, sh	Match range of characters&lt;br /&gt;
[ ]	sh	Test&lt;br /&gt;
%job	csh	Identifies job Number&lt;br /&gt;
(cmd;cmd)	csh. sh	Runs cmd;cmd as a sub-shell&lt;br /&gt;
{ }	csh	In-line expansions&lt;br /&gt;
{cmd;cmd }	sh	Like (cmd;cmd ) without a subshell&lt;br /&gt;
&amp;gt;ofile	csh, sh	Standard output&lt;br /&gt;
&amp;gt;&amp;gt;ofile	csh, sh	Append to standard output&lt;br /&gt;
&amp;lt;ifile	csh, sh	Standard Input&lt;br /&gt;
&amp;lt;&amp;lt;word	csh, sh	Read until word, substitute variables&lt;br /&gt;
&amp;lt;&amp;lt;\word	csh, sh	Read until word, no substitution&lt;br /&gt;
&amp;lt;&amp;lt;-word	sh	Read until word, ignoring TABS&lt;br /&gt;
&amp;gt;&amp;gt;!file	csh	Append to file, ignore error if not there&lt;br /&gt;
&amp;gt;!file	csh	Output to new file, ignore error if not there&lt;br /&gt;
&amp;gt;&amp;amp;file	csh	Send standard &amp;amp; error output to file&lt;br /&gt;
&amp;lt;&amp;amp;digit	sh	Switch Standard Input to file&lt;br /&gt;
&amp;lt;&amp;amp;-	sh	Close Standard Input&lt;br /&gt;
&amp;gt;&amp;amp;digit	sh	Switch Standard Output to file&lt;br /&gt;
&amp;gt;&amp;amp;-	sh	Close Standard Output&lt;br /&gt;
digit1&amp;lt;&amp;amp;digit2	sh	Connect digit2 to digit1&lt;br /&gt;
digit&amp;lt;&amp;amp;-	sh	Close file digit&lt;br /&gt;
digit2&amp;gt;&amp;amp;digit1	sh	Connect digit2 to digit1&lt;br /&gt;
digit&amp;gt;&amp;amp;-	sh	Close file digit&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Stuart</name></author>	</entry>

	<entry>
		<id>https://mailnest.com/dbawiki/index.php?title=Unix/Linux&amp;diff=3400</id>
		<title>Unix/Linux</title>
		<link rel="alternate" type="text/html" href="https://mailnest.com/dbawiki/index.php?title=Unix/Linux&amp;diff=3400"/>
				<updated>2018-12-06T00:11:58Z</updated>
		
		<summary type="html">&lt;p&gt;Stuart: /* uudeview */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;* [http://hyperpolyglot.org/unix-shells#var-expansion Good shell comparison including variable expansion - hyperpolyglot.org]&lt;br /&gt;
* [http://pubs.opengroup.org/onlinepubs/9699919799/utilities/toc.html Shell coding standards - opengroup.org]&lt;br /&gt;
* [http://aix4admins.blogspot.be aix4admins]&lt;br /&gt;
* [http://linuxgazette.net/issue55/okopnik.html The Deep, Dark Secrets of Bash]&lt;br /&gt;
* [http://www.speakeasy.org/~arkay/216-7.4KshFunctions.html Korn Shell Functions]&lt;br /&gt;
* [http://www.grymoire.com/Unix/AwkRef.html AWK reference from Bruce Barnett]&lt;br /&gt;
* [http://www.catonmat.net/blog/wp-content/uploads/2008/09/awk1line.txt HANDY AWK ONE-LINERS]&lt;br /&gt;
* [http://www.grymoire.com/unix/Quote.html Unix quoting from from Bruce Barnett (grymoire)]&lt;br /&gt;
* [http://www.mpi-inf.mpg.de/departments/rg1/teaching/unixffb-ss98/quoting-guide.html Another excellent quoting tutorial]&lt;br /&gt;
* [http://aix4admins.blogspot.be/2015/02/snapshot-fs-snapshot-snapshot-is-state.html AIX snapshot technology]&lt;br /&gt;
* [[RaspberryPi]]&lt;br /&gt;
* [[SSH]]&lt;br /&gt;
* [http://www.anattatechnologies.com/q/2013/04/multiuser-screen/ Screen sharing from Unix using screen]&lt;br /&gt;
* [https://robots.thoughtbot.com/a-tmux-crash-course Screen sharing from Unix using tmux]&lt;br /&gt;
* [http://www.csb.yale.edu/userguides/wordprocess/vi-summary.html Handy ex and vi reference]&lt;br /&gt;
* [[Fedora install for my own purposes]]&lt;br /&gt;
&lt;br /&gt;
===How to automatically download and process email attachments from Gmail===&lt;br /&gt;
==== Useful references====&lt;br /&gt;
* [http://www.courier-mta.org/maildrop/maildrop.html maildrop]&lt;br /&gt;
* [http://www.wonkity.com/~wblock/docs/html/maildrop.html Using maildrop As A Mail Delivery Agent (MDA)]&lt;br /&gt;
* [http://manpages.ubuntu.com/manpages/trusty/man7/maildropex.7.html .mailfilter examples]&lt;br /&gt;
* [https://www.axllent.org/docs/view/gmail-pop3-with-fetchmail/ Setting up fetchmail with Gmail]&lt;br /&gt;
* [https://www.linode.com/docs/email/clients/using-fetchmail-to-retrieve-email/ Using Fetchmail to Retrieve Email]&lt;br /&gt;
&lt;br /&gt;
Eventually, after months of trying different things, came up with this combination of tools that worked very well.&lt;br /&gt;
====Install tools====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo dnf -y install fetchmail maildrop uudeview openssl&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Set Gmail account up for POP and disable IMAP&lt;br /&gt;
====Configure fetchmail====&lt;br /&gt;
This is the part that talks to Gmail and downloads the emails to the local machine.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
vi ~/.fetchmailrc&lt;br /&gt;
&lt;br /&gt;
set postmaster &amp;quot;&amp;lt;username&amp;gt;&amp;quot;&lt;br /&gt;
#set daemon 600&lt;br /&gt;
poll pop.gmail.com with proto POP3&lt;br /&gt;
    user &amp;quot;account@gmail.com&amp;quot; there with password &amp;#039;&amp;lt;password&amp;gt;&amp;#039; is &amp;lt;username&amp;gt; here options ssl nokeep&lt;br /&gt;
    mda &amp;quot;/usr/bin/maildrop .mailfilter&amp;quot;&lt;br /&gt;
#    sslcertfile /etc/ssl/certs/ca-bundle.crt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
If fetchmail complains about ssl certificates, try specifying wherein is with the sslcertfile line&lt;br /&gt;
==== Configure maildrop====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
vi ~/.mailfilter&lt;br /&gt;
&lt;br /&gt;
LOGFILE = &amp;quot;/home/dbahawk/maildrop/maildrop.log&amp;quot;&lt;br /&gt;
DEFAULT=&amp;quot;$HOME/maildrop&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# keep a copy&lt;br /&gt;
cc backup&lt;br /&gt;
`cd backup/new &amp;amp;&amp;amp; rm -f dummy \`ls -t | sed -e 1,50d\``&lt;br /&gt;
&lt;br /&gt;
if (/^To:.*getmail@...\.dnsalias\.org$/)&lt;br /&gt;
   {&lt;br /&gt;
        to Maildir/getmail/&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
#if (/^To:.*dbahawk/)&lt;br /&gt;
#   {&lt;br /&gt;
#        to maildrop&lt;br /&gt;
#   }&lt;br /&gt;
&lt;br /&gt;
if (/^To:.*dbahawk/)&lt;br /&gt;
    dotlock &amp;quot;auto.lock&amp;quot; {&lt;br /&gt;
    to &amp;quot;|uudeview -c -i&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Not really sure why this filter is not working properly. The cc works but the To: check doesn&amp;#039;t. So I have a shell that runs separately to process the emails in the backup mail directory.&lt;br /&gt;
====uudeview====&lt;br /&gt;
This is a clever program that can extract attachments from emails and put them in a directory of you choosing.&amp;lt;br /&amp;gt;&lt;br /&gt;
This shell runs from cron at regular intervals to run the whole process&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/usr/bin/ksh&lt;br /&gt;
&lt;br /&gt;
# fetch any new mail from Gmail (uses .fetchmailrc)&lt;br /&gt;
# fetchmail log is $HOME/maildrop/maildrop.log&lt;br /&gt;
fetchmail -d0&lt;br /&gt;
&lt;br /&gt;
# fetchmail uses maildrop as mda (uses .mailfilter) to save messages to a maildir.&lt;br /&gt;
# this is not working correctly but still copies the messages to backup&lt;br /&gt;
&lt;br /&gt;
# pull out the attachments and send them to the incoming directory for the collector to process when it wakes up&lt;br /&gt;
uudeview -c -i -p ~/Downloads/dbahawk_forward backup/new/*&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Use sed to repeat characters===&lt;br /&gt;
echo an &amp;#039;=&amp;#039; sign then use the loop feature of sed to run round a loop a further 79 times replacing what you&amp;#039;ve got with the same thing plus and extra one!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
echo &amp;quot;=&amp;quot; | sed -e :a -e &amp;#039;s/^=\{1,79\}$/&amp;amp;=/;ta&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Convert between lower and upper case using ansi standard===&lt;br /&gt;
This way should be portable and give predictable results&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
LOWER_SID=$(echo &amp;quot;${SID}&amp;quot; | tr &amp;#039;[:upper:]&amp;#039; &amp;#039;[:lower:]&amp;#039;)&lt;br /&gt;
UPPER_SID=$(echo &amp;quot;${SID}&amp;quot; | tr &amp;#039;[:lower:]&amp;#039; &amp;#039;[:upper:]&amp;#039;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Use sed to delete the first line of a file or command output printing from the second line onwards===&lt;br /&gt;
Actually deceptively simple. Example remove the header from df output.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
df -k | sed 1d&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
As a useful extension, suppose TO_DATA_DIR contains multiple directories, this will total the free space for all relevant filesystems&amp;lt;br /&amp;gt;&lt;br /&gt;
This one is specific to AIX, for other Unixes and Linux, use $4 instead of $3.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SPACE_AVAILABLE=$(df -k $TO_DATA_DIR | sed 1d | awk &amp;#039;BEGIN {i=0} {i=i+$3} END {print i}&amp;#039;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Use sed to munge a controlfile into submission!===&lt;br /&gt;
* delete comment lines&lt;br /&gt;
* delete all lines after the one starting with a semicolon&lt;br /&gt;
* delete all blank lines&lt;br /&gt;
* change reuse to set&lt;br /&gt;
* change archivelog (with word boundaries) to noarchivelog&lt;br /&gt;
* change old sid to new sid&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sqlplus -s / as sysdba&amp;lt;&amp;lt;&amp;#039;EOSQL&amp;#039; &amp;gt;/dev/null&lt;br /&gt;
alter database backup controlfile to trace as &amp;#039;/tmp/regenerate_controlfile.sql&amp;#039; reuse resetlogs;&lt;br /&gt;
EOSQL&lt;br /&gt;
OLDSID=&amp;#039;PROD&amp;#039;&lt;br /&gt;
NEWSID=&amp;#039;TEST&amp;#039;&lt;br /&gt;
sed  -e &amp;#039;/^--/d&amp;#039; -e &amp;#039;/^\;/q&amp;#039; -e &amp;#039;/^ *$/d&amp;#039; -e &amp;#039;s/REUSE/SET/&amp;#039; -e &amp;#039;s/\&amp;lt;ARCHIVELOG\&amp;gt;/NOARCHIVELOG/&amp;#039; -e &amp;#039;s/\&amp;quot;&amp;#039;${OLDSID}&amp;#039;\&amp;quot;/\&amp;quot;&amp;#039;${NEWSID}&amp;#039;\&amp;quot;/&amp;#039; /tmp/regenerate_controlfile.sql&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Find all files where a certain text does not exist===&lt;br /&gt;
Mostly we want to search for files containing a particular string but how to find those files that do not contain some text.&amp;lt;br /&amp;gt;&lt;br /&gt;
Using xargs instead of -exec forces the filename to be printed. -H should do this but doesn&amp;#039;t seem to in this case.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
find . -name &amp;quot;*cfg&amp;quot; | xargs grep -H -c TO_CV_HOST {} \; | grep &amp;#039;:0$&amp;#039; | cut -d: -f1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Use tar and gzip to copy files more efficiently across network between hosts===&lt;br /&gt;
From the destination server, this will connect to the source, tar up each file and pull it back to the current server&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ssh oracle@hn5211 &amp;quot;cd /oracle/ora_data4/iten3/ &amp;amp;&amp;amp; tar -cf - . | gzip &amp;quot; | ( cd /oracle/ora_data2/iten/ &amp;amp;&amp;amp; gunzip -c | tar -xvf - . )&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===double hash and double percent in shell variables to trim off characters from variables===&lt;br /&gt;
&amp;lt;nowiki&amp;gt;#&amp;lt;/nowiki&amp;gt;  - trims everything from the start of line till the FIRST occurrence of following character (abstemious) :-)&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;nowiki&amp;gt;##&amp;lt;/nowiki&amp;gt; - trims everything from the start of line till the LAST occurrence of following character (greedy)&amp;lt;br /&amp;gt;&lt;br /&gt;
%  - trims everything from the end of line backwards till the FIRST occurrence of following character (abstemious)&amp;lt;br /&amp;gt;&lt;br /&gt;
%% - trims everything from the end of line backwards till the LAST occurrence of following character (greedy)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
FILENAME=&amp;quot;/home/bey9at77/hello.txt&amp;quot;&lt;br /&gt;
FILE_STUB1=${FILENAME##*/}&lt;br /&gt;
FILE_STUB=${FILE_STUB1%.*}&lt;br /&gt;
echo $FILE_STUB&lt;br /&gt;
hello&lt;br /&gt;
FILE_EXT=${FILENAME##*.}&lt;br /&gt;
echo $FILE_EXT&lt;br /&gt;
txt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;nowiki&amp;gt;#&amp;lt;/nowiki&amp;gt; - remove prefix reluctantly&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;nowiki&amp;gt;##&amp;lt;/nowiki&amp;gt; - remove prefix greedily&amp;lt;br /&amp;gt;&lt;br /&gt;
% - remove suffix reluctantly&amp;lt;br /&amp;gt;&lt;br /&gt;
%% - remove suffix greedily&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
words=&amp;quot;do.re.mi&amp;quot;&lt;br /&gt;
&lt;br /&gt;
echo ${words#*.}&lt;br /&gt;
&lt;br /&gt;
echo ${words##*.}&lt;br /&gt;
&lt;br /&gt;
echo ${words%.*}&lt;br /&gt;
&lt;br /&gt;
echo ${words%%.*}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===The best shell script ever. An example of how scripting should be done===&lt;br /&gt;
It was written by someone at Oracle. Unfortunately (s)he did not put any author comment in it. Also unfortunately I cannot show it here as it is protected behind Oracles support website.&amp;lt;br /&amp;gt;&lt;br /&gt;
If you have an Oracle Metalink id, you can get the complete script [https://support.oracle.com/epmos/faces/DocumentDisplay?id=949322.1 here]&amp;lt;br /&amp;gt;&lt;br /&gt;
Here is a snippet of a function that demonstrates proper commenting and a very good style.&amp;lt;br &amp;gt;&lt;br /&gt;
The script is called physru.sh and upgrades an Oracle database in a rolling upgrade fashion by using a physical standby.&amp;lt;br /&amp;gt;&lt;br /&gt;
There are 4500 lines in the full script but it is so easy to read and understand because of the way it&amp;#039;s written, it&amp;#039;s like a breath of fresh air. Well done whoever you are!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
###############################################################################&lt;br /&gt;
# NAME:        wait_mrp_active&lt;br /&gt;
#&lt;br /&gt;
# DESCRIPTION: &lt;br /&gt;
#   Wait for $MRP_START_TIMEOUT minutes to confirm that the MRP is active.  If&lt;br /&gt;
#   we can&amp;#039;t detect an active MRP, abort the script with an error.&lt;br /&gt;
#&lt;br /&gt;
# INPUT(S):&lt;br /&gt;
#   Arguments:&lt;br /&gt;
#     $1: database user&lt;br /&gt;
#     $2: user password&lt;br /&gt;
#     $3: tns service name&lt;br /&gt;
#     $4: database unique name&lt;br /&gt;
#&lt;br /&gt;
#   Globals:&lt;br /&gt;
#     None&lt;br /&gt;
#&lt;br /&gt;
# RETURN:&lt;br /&gt;
#   None&lt;br /&gt;
#&lt;br /&gt;
###############################################################################&lt;br /&gt;
wait_mrp_active()&lt;br /&gt;
{&lt;br /&gt;
  display &amp;quot;confirming media recovery is running&amp;quot;&lt;br /&gt;
  l_wma_status=1&lt;br /&gt;
  l_wma_curtime=`perl -e &amp;#039;print int(time)&amp;#039;`&lt;br /&gt;
  l_wma_exptime=`expr $MRP_START_TIMEOUT &amp;quot;*&amp;quot; 60`&lt;br /&gt;
  l_wma_maxtime=`expr $l_wma_curtime + $l_wma_exptime`&lt;br /&gt;
  while [ &amp;quot;$l_wma_curtime&amp;quot; -lt &amp;quot;$l_wma_maxtime&amp;quot; ]&lt;br /&gt;
  do&lt;br /&gt;
    is_mrp_running $1 $2 $3 $4&lt;br /&gt;
    if [ &amp;quot;$?&amp;quot; -gt &amp;quot;0&amp;quot; ]; then&lt;br /&gt;
      l_wma_status=0&lt;br /&gt;
      break&lt;br /&gt;
    fi&lt;br /&gt;
&lt;br /&gt;
    sleep $MRP_START_INTERVAL&lt;br /&gt;
    l_wma_curtime=`perl -e &amp;#039;print int(time)&amp;#039;`&lt;br /&gt;
  done&lt;br /&gt;
  chkerr $l_wma_status &amp;quot;could not detect an active MRP after $MRP_START_TIMEOUT minutes&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===split variable (eg. filename) into separate variables using set===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
FILENAME=&amp;quot;split_this_into_bits&amp;quot;&lt;br /&gt;
set $(echo ${FILENAME} | sed &amp;#039;s/_/ /g&amp;#039;)&lt;br /&gt;
echo $4 $3 $2 $1&lt;br /&gt;
bits into this split&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Centre align text on a line in bash shell===&lt;br /&gt;
Doesn&amp;#039;t work in Korn shell due to %*s&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#COLUMNS=$(tput cols)   # width of the current window&lt;br /&gt;
COLUMNS=80&lt;br /&gt;
title=&amp;quot;Hello world!&amp;quot;&lt;br /&gt;
printf &amp;quot;%*s\n&amp;quot; $(((${#title}+$COLUMNS)/2)) &amp;quot;$title&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
and as a one-liner&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
printf &amp;quot;%*s\n&amp;quot; $(( ( $(echo $* | wc -c ) + 80 ) / 2 )) &amp;quot;$*&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This works in Korn shell...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
TITLE=&amp;quot;$1&amp;quot;&lt;br /&gt;
LINEWIDTH=80&lt;br /&gt;
&lt;br /&gt;
LPAD=$(((${#TITLE}+$LINEWIDTH)/2))&lt;br /&gt;
printf %${LPAD}s &amp;quot;$TITLE&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Right justify text (or repeat characters) on a line with leader dots!===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
function rpadwait {&lt;br /&gt;
    text=$1&lt;br /&gt;
# -------------------------&lt;br /&gt;
# suppress newline for echo&lt;br /&gt;
# -------------------------&lt;br /&gt;
N=&lt;br /&gt;
C=&lt;br /&gt;
if echo &amp;quot;\c&amp;quot; | grep c &amp;gt;/dev/null 2&amp;gt;&amp;amp;1; then&lt;br /&gt;
    N=&amp;#039;-n&amp;#039;&lt;br /&gt;
else&lt;br /&gt;
    C=&amp;#039;\c&amp;#039;&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
    echo ${N} &amp;quot;${text}${C}&amp;quot; | sed -e :a -e &amp;#039;s/^.\{1,80\}$/&amp;amp;\./;ta&amp;#039;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===cron jobs not submitted - daemon run out of child processes?===&lt;br /&gt;
Sometimes have problems with NFS mounts and this causes cron jobs to hang. If they are scheduled to run regularly, eventually cron will no longer be able to start any more jobs.&amp;lt;br /&amp;gt;&lt;br /&gt;
* Check the cron log &amp;#039;&amp;#039;&amp;#039;/var/adm/cron/log&amp;#039;&amp;#039;&amp;#039; to see if there are any errors or other messages around the time the jobs should run.&lt;br /&gt;
If cron has hit its process limit (default 100), it will try again after a number of seconds (default 60).&amp;lt;br /&amp;gt;&lt;br /&gt;
Both the number of jobs and wait time are configured in the file &amp;#039;&amp;#039;&amp;#039;/var/adm/cron/queuedefs&amp;#039;&amp;#039;&amp;#039;. If it is unusual for cron to be running so many jobs, you can check the process table to view the jobs cron has created. These jobs will have parent process id (PPID) of the cron daemon.&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ ps -ef | grep cron | grep -v grep&lt;br /&gt;
    root  6750314        1   0   Apr 24      -  3:39 /usr/sbin/cron&lt;br /&gt;
solax025:root[/home/root]# ps -T 6750314&lt;br /&gt;
      PID    TTY  TIME CMD&lt;br /&gt;
  6750314      -  3:39 cron&lt;br /&gt;
 21168296      -  0:00     \--bsh&lt;br /&gt;
 58982414      -  0:00         \--sadc&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
In this example, we only have 1 job running&lt;br /&gt;
&lt;br /&gt;
===Find long-running processes with a cron job===&lt;br /&gt;
Processes running longer than 24 hours have a date instead of a start time...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
58 08,14 * * * /home/ibmtools/scripts/oracle/dosh -vc &amp;quot;ps -ef|grep &amp;#039;ibmtools/scripts/oracle&amp;#039;|perl -nae &amp;#039;print if \$F[4] !~/:/&amp;#039;&amp;quot; &amp;gt;/tmp/lrp.txt; [[ $(grep -c ibmtools /tmp/lrp.txt) -ne 0 ]] &amp;amp;&amp;amp; cat /tmp/lrp.txt|mailx -s &amp;#039;*** long running processes - please check ***&amp;#039; reporting@companymail.com&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Process command line arguments in shell===&lt;br /&gt;
Borrowed from Mozilla Firefox installer&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
## Command line arg defaults&lt;br /&gt;
##&lt;br /&gt;
moz_debug=0&lt;br /&gt;
moz_debugger=&amp;quot;&amp;quot;&lt;br /&gt;
moz_debugger_args=&amp;quot;&amp;quot;&lt;br /&gt;
#&lt;br /&gt;
##&lt;br /&gt;
## Parse the command line&lt;br /&gt;
##&lt;br /&gt;
while [ $# -gt 0 ]&lt;br /&gt;
do&lt;br /&gt;
  case $1 in&lt;br /&gt;
    -g | --debug)&lt;br /&gt;
      moz_debug=1&lt;br /&gt;
      shift&lt;br /&gt;
      ;;&lt;br /&gt;
    -d | --debugger)&lt;br /&gt;
      moz_debugger=$2;&lt;br /&gt;
      if [ &amp;quot;${moz_debugger}&amp;quot; != &amp;quot;&amp;quot; ]; then&lt;br /&gt;
	shift 2&lt;br /&gt;
      else&lt;br /&gt;
        echo &amp;quot;-d requires an argument&amp;quot;&lt;br /&gt;
        exit 1&lt;br /&gt;
      fi&lt;br /&gt;
      ;;&lt;br /&gt;
    -a | --debugger-args)&lt;br /&gt;
      moz_debugger_args=$2;&lt;br /&gt;
      if [ &amp;quot;${moz_debugger_args}&amp;quot; != &amp;quot;&amp;quot; ]; then&lt;br /&gt;
	shift 2&lt;br /&gt;
      else&lt;br /&gt;
        echo &amp;quot;-a requires an argument&amp;quot;&lt;br /&gt;
        exit 1&lt;br /&gt;
      fi&lt;br /&gt;
      ;;&lt;br /&gt;
    *)&lt;br /&gt;
      break;&lt;br /&gt;
      ;;&lt;br /&gt;
  esac&lt;br /&gt;
done&lt;br /&gt;
#&lt;br /&gt;
##&lt;br /&gt;
## Program name given in $1&lt;br /&gt;
##&lt;br /&gt;
if [ $# -gt 0 ]&lt;br /&gt;
then&lt;br /&gt;
	MOZ_PROGRAM=$1&lt;br /&gt;
	shift&lt;br /&gt;
fi&lt;br /&gt;
##&lt;br /&gt;
## Program not given, try to guess a default&lt;br /&gt;
##&lt;br /&gt;
if [ -z &amp;quot;$MOZ_PROGRAM&amp;quot; ]&lt;br /&gt;
then&lt;br /&gt;
	##&lt;br /&gt;
	## Try this script&amp;#039;s name with &amp;#039;-bin&amp;#039; appended&lt;br /&gt;
	##&lt;br /&gt;
	if [ -x &amp;quot;$MOZ_DEFAULT_NAME&amp;quot; ]&lt;br /&gt;
	then&lt;br /&gt;
		MOZ_PROGRAM=$MOZ_DEFAULT_NAME&lt;br /&gt;
	##&lt;br /&gt;
	## Try mozilla-bin&lt;br /&gt;
	## &lt;br /&gt;
	elif [ -x &amp;quot;$MOZ_APPRUNNER_NAME&amp;quot; ]&lt;br /&gt;
	then&lt;br /&gt;
		MOZ_PROGRAM=$MOZ_APPRUNNER_NAME&lt;br /&gt;
	fi&lt;br /&gt;
fi&lt;br /&gt;
#&lt;br /&gt;
#&lt;br /&gt;
##&lt;br /&gt;
## Make sure the program is executable&lt;br /&gt;
##&lt;br /&gt;
if [ ! -x &amp;quot;$MOZ_PROGRAM&amp;quot; ]&lt;br /&gt;
then&lt;br /&gt;
	moz_bail &amp;quot;Cannot execute $MOZ_PROGRAM.&amp;quot;&lt;br /&gt;
fi&lt;br /&gt;
#&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Carry XWindows settings across sessions===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# ----------------------&lt;br /&gt;
# push XWindows settings&lt;br /&gt;
# ----------------------&lt;br /&gt;
[[ &amp;quot;$(uname)&amp;quot; == &amp;quot;SunOS&amp;quot; ]] &amp;amp;&amp;amp; PATH=/usr/openwin/bin:$PATH&lt;br /&gt;
WHOAMI=$(id | awk -F&amp;#039;)&amp;#039; &amp;#039;{print $1}&amp;#039; | awk -F&amp;#039;(&amp;#039; &amp;#039;{print $2}&amp;#039;)&lt;br /&gt;
xauth list &amp;gt; /tmp/xauth_list_$WHOAMI&lt;br /&gt;
chmod 777 /tmp/xauth_list_$WHOAMI&lt;br /&gt;
&lt;br /&gt;
echo $DISPLAY &amp;gt; /tmp/xdisplay_$WHOAMI&lt;br /&gt;
chmod 777 /tmp/xdisplay_$WHOAMI&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Cross-platform version of whoami===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
WHOAMI=$(id | awk -F&amp;#039;)&amp;#039; &amp;#039;{print $1}&amp;#039; | awk -F&amp;#039;(&amp;#039; &amp;#039;{print $2}&amp;#039;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Set terminal title from command line===&lt;br /&gt;
Put something like this in the .profile&amp;lt;br /&amp;gt;&lt;br /&gt;
-n     do not output the trailing newline&amp;lt;br /&amp;gt;&lt;br /&gt;
-e     enable interpretation of backslash escapes&amp;lt;br /&amp;gt;&lt;br /&gt;
|0     sets title of window and icon&amp;lt;br /&amp;gt;&lt;br /&gt;
|1     sets title of icon only&amp;lt;br /&amp;gt;&lt;br /&gt;
|2     sets title of window only&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
echo -en &amp;quot;\033]0;`hostname`\007&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
echo -en &amp;quot;\033]2;`hostname`\007&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Remove blank lines and comments (also indented ones) from a file===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
awk -F\: &amp;#039;!/^($|[:space:]*#)/ {print $2}&amp;#039; /etc/oratab | sort | uniq&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or as part of a script that removes comments and blank lines from all Korn shell scripts in a directory&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/usr/bin/ksh&lt;br /&gt;
for i in $(ls *ksh); do&lt;br /&gt;
    perl -p -i -e &amp;#039;s/^\s*#[^!]*$//; s/^\s*$//&amp;#039; $i&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Return elements of an array in Korn shell===&lt;br /&gt;
From [http://unix.stackexchange.com/questions/188202/processing-output-from-an-sqlite-db-into-a-ksh-array-with-spaces here]&amp;lt;br /&amp;gt;&lt;br /&gt;
Could be used to separate the columns of an SQL select when returning to the shell&amp;lt;br /&amp;gt;&lt;br /&gt;
This approach eliminates the need to put quotes around text with spaces in it.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
echo $KSH_VERSION&lt;br /&gt;
x=&amp;quot;Red,Yellow is a color,Blue&amp;quot;&lt;br /&gt;
oIFS=$IFS&lt;br /&gt;
IFS=,&lt;br /&gt;
y=($x)&lt;br /&gt;
IFS=$oIFS&lt;br /&gt;
echo ${y[1]}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===A decent Unix Prompt===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
export PS1=&amp;quot;`uname -n`:`whoami`[\${PWD}]# &amp;quot;&lt;br /&gt;
or&lt;br /&gt;
export PS1=&amp;#039;($?) $&amp;#039;ORACLE_SID&amp;quot; &amp;quot;`whoami`&amp;quot;@&amp;quot;`uname -n`&amp;quot;:&amp;quot;&amp;#039;$&amp;#039;PWD&amp;quot;&amp;gt; &amp;quot;&lt;br /&gt;
export EDITOR=vi&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Simple arithmetic===&lt;br /&gt;
pipe the calculation into the shell calculator&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
space_in_kb=$(echo $1 / 1024 | bc)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Calculate the remainder (modulo) of a division calculation&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
if [[ $(echo &amp;quot;${NUMBER} % 2&amp;quot; | bc) -eq 0 ]]; then&lt;br /&gt;
    echo &amp;quot;${NUMBER} is even&amp;quot;&lt;br /&gt;
else&lt;br /&gt;
    echo &amp;quot;${NUMBER} is odd&amp;quot;&lt;br /&gt;
fi&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or do it in awk if scientific notation maybe involved&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
function calc { awk &amp;quot;BEGIN{print $*}&amp;quot;; }&lt;br /&gt;
&lt;br /&gt;
if [[ $(calc &amp;quot;${SPACE_USED} + ${SPACE_AVAILABLE} - ${DATABASE_SIZE&amp;quot;) -le 0 ]]; then&lt;br /&gt;
    echo &amp;quot;NOK&amp;quot;&lt;br /&gt;
fi&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Script encryption and passphrase protection===&lt;br /&gt;
Encrypt a shell script with the ability to execute the encrypted version&lt;br /&gt;
* from [http://www.commandlinefu.com/commands/browse commandlinefu.com]&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
scrypt(){ [ -n &amp;quot;$1&amp;quot; ]&amp;amp;&amp;amp;{ echo &amp;#039;. &amp;lt;(echo &amp;quot;$(tail -n+2 $0|base64 -d|mcrypt -dq)&amp;quot;); exit;&amp;#039;&amp;gt;$1.scrypt;cat $1|mcrypt|base64 &amp;gt;&amp;gt;$1.scrypt;chmod +x $1.scrypt;};}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Virtual host configuration in Apache http.conf===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;VirtualHost *:80&amp;gt;&lt;br /&gt;
        ServerName dbamon&lt;br /&gt;
        DocumentRoot &amp;quot;/Volumes/data/Sites/dbamon_push&amp;quot;&lt;br /&gt;
        &amp;lt;Directory &amp;quot;/Volumes/data/Sites/dbamon_push&amp;quot;&amp;gt;&lt;br /&gt;
                Options Includes FollowSymLinks&lt;br /&gt;
                AllowOverride All&lt;br /&gt;
                Order allow,deny&lt;br /&gt;
                Allow from all&lt;br /&gt;
        &amp;lt;/Directory&amp;gt;&lt;br /&gt;
&amp;lt;/VirtualHost&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
and in /etc/hosts, add...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
127.0.0.1  dbamon&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Mount a website (or any other remote resource) locally using WebDav===&lt;br /&gt;
Redhat/CentOS&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
yum install fuse-davfs2&lt;br /&gt;
or&lt;br /&gt;
yum install wdfs.x86_64&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Debian&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
apt-get install davfs2&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
then...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo mkdir /mnt/webdav  # or whatever you&amp;#039;d like to call the directory&lt;br /&gt;
sudo mount.davfs [-o option[,option]...] device mount_point&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
In man&amp;#039;s terms, that last line would translate to:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
id  #suppose this returns uid=501 and gid=502&lt;br /&gt;
sudo mount.davfs -o 501,502 https://your/web/site /mnt/webdav&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Mac OSX&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
osascript -e &amp;#039; mount volume &amp;quot;http://username:password@webdav.address:portnum&amp;quot; &amp;#039;&lt;br /&gt;
or&lt;br /&gt;
osascript -e &amp;#039; mount volume &amp;quot;http://username@webdav.address:portnum&amp;quot; &amp;#039;&lt;br /&gt;
or&lt;br /&gt;
osascript -e &amp;#039; try mount volume &amp;quot;http://webdav.address:portnum&amp;quot; &amp;#039;&lt;br /&gt;
or&lt;br /&gt;
mount -t webdav http://webdav.address:portnum /mnt/webdav  # this one won&amp;#039;t show up in the Finder Sidebar.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Add current hostname to list of hosts on an xcat server===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
CMD=&amp;quot;nodels&amp;quot;&lt;br /&gt;
HOST=`hostname`&lt;br /&gt;
(echo &amp;quot;$HOST&amp;quot;; $CMD) | while read server&lt;br /&gt;
do&lt;br /&gt;
    echo &amp;quot;server:$server&amp;quot;&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===What is todays &amp;#039;Day Of the Year&amp;#039; number?===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
DOY=`perl -e &amp;#039;print sub{$_[7]}-&amp;gt;(localtime)+1;&amp;#039;`&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Convert Julian day numbers to dates===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
for day in 8 33 36 61 64 91 96 121 126 152 155 182 187 215 218 244 247 274 279 306 309 335 338 365; do date -d &amp;quot;`date +%Y`-01-01 +$(( ${day} - 1 ))days&amp;quot; +%d-%m-%Y; done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Send crontab job output to a date formatted log file===&lt;br /&gt;
This will run a job every 5 minutes and send the output to a file ending with a time in hours and minutes.&amp;lt;br /&amp;gt;&lt;br /&gt;
The thing to note is the escaped percent signs. This is because a % sign is interpreted by cron to mean a newline character. Everything after the first % is treated as input to the program.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
*/5 *  * * * /var/www/cgi-bin/dbamon_collector.ksh       &amp;gt;/tmp/dbamon_collector.log.$(date &amp;quot;+\%H\%M&amp;quot;) 2&amp;gt;&amp;amp;1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Edit crontab file without crontab -e===&lt;br /&gt;
It can happen that you need to add or modify a line in the crontab of many users or across many servers at once.&amp;lt;br /&amp;gt;&lt;br /&gt;
In principle, there&amp;#039;s nothing wrong with modifying the crontab file directly. You just lose the advantages of file locking (and syntax checking) that crontab -e offers.&amp;lt;br /&amp;gt;&lt;br /&gt;
Here we take a backup of the current crontab, print it out, echo an extra command and ask cron to use these as input (thus overwriting the existing crontab file). Just don&amp;#039;t run this close to midnight :-)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
crontab -l &amp;gt; /tmp/crontab.`date &amp;#039;+%Y%m%d&amp;#039;`&lt;br /&gt;
(&lt;br /&gt;
cat /tmp/crontab.`date +&amp;#039;%Y%m%d&amp;#039;`&lt;br /&gt;
echo &amp;quot;02 10 * * * /home/ibmtools/scripts/oracle/export_parfile.ksh -s SID -f JDBEOP1.parfile&amp;quot;&lt;br /&gt;
) | crontab -&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
crontab -l &amp;gt; /tmp/crontab.backup&lt;br /&gt;
crontab -l &amp;gt; /tmp/crontab.$$&lt;br /&gt;
perl -p -i -e &amp;#039;s!backup_send_tsm_dump!backup_export2tsm!g&amp;#039; /tmp/crontab.$$&lt;br /&gt;
crontab /tmp/crontab.$$&lt;br /&gt;
rm /tmp/crontab.$$&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
crontab -l &amp;gt;$HOME/crontab.$(date &amp;#039;+%Y%m%d&amp;#039;)&lt;br /&gt;
crontab -l | perl -p -e &amp;#039;s|/nas/software/oracle/scripts|/oracle/scripts|&amp;#039; | crontab&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Use shell to convert a number in scientific notation to normal===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
var2convert=&amp;#039;1.2345678e3&amp;#039;&lt;br /&gt;
printf -v var2convert &amp;quot;%.f&amp;quot; $var2convert&lt;br /&gt;
echo $var2convert  # magic!&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Check for jobs running longer that 24 hours===&lt;br /&gt;
Run from the management server across all Unix servers. Checks the 5th column in a ps listing. If it doesn&amp;#039;t find a : (time separator), the process is running longer than 24 hours.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# ---------------------------------------&lt;br /&gt;
# report on long running oraibm processes&lt;br /&gt;
# ---------------------------------------&lt;br /&gt;
01 17,14 * * * rm -f /tmp/lrp.txt;/home/ibmtools/scripts/oracle/dosh -vc \&amp;quot;ps -ef|egrep &amp;#039;oraibm|scripts/oracle&amp;#039;&amp;gt;/tmp/lrp.txt;perl -nae &amp;#039;print if \$F[4] !~/:/&amp;#039; /tmp/lrp.txt\&amp;quot; &amp;gt;&amp;gt;/tmp/lrp.txt;[[ $(egrep -c &amp;#039;oraibm|scripts/or&lt;br /&gt;
acle&amp;#039; /tmp/lrp.txt) -ne 0 ]] &amp;amp;&amp;amp; cat /tmp/lrp.txt|mailx -s &amp;#039;*** long running processes - please check ***&amp;#039; bey9at77@mail.com&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Global find and replace with perl (restricted to list of files provided by Unix find command)===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
find . -type f -exec perl -i -pe &amp;#039;s/something/else/g&amp;#039; {} \;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===perl function to make filenames lower case===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
function lower { &lt;br /&gt;
   perl -e &amp;#039;for (@ARGV) { rename $_, lc($_) unless -e lc($_); }&amp;#039; * &lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===From the management server, search the TNS listener port for each database on a server and make an inline substitution in the ITM config files!===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
for i in `/home/ibmtools/scripts/oracle/dosh -c &amp;quot;ls -al /opt/IBM/ITM/config/*rz*cfg|grep -v lrwx&amp;quot;|awk &amp;#039;{print $NF}&amp;#039;`; do&lt;br /&gt;
    server=`echo $i|cut -d_ -f1 | awk -F&amp;#039;/&amp;#039; &amp;#039;{print $NF}&amp;#039;`&lt;br /&gt;
    db=`echo $i|cut -d&amp;#039;.&amp;#039; -f1 | awk -F&amp;#039;_&amp;#039; &amp;#039;{print $NF}&amp;#039;`&lt;br /&gt;
    OH=`ssh $server grep &amp;quot;^$db&amp;quot; /etc/oratab|cut -d: -f2`&lt;br /&gt;
    LISTENERPORT=`ssh $server cat $OH/network/admin/listener.ora|perl -00 -ne &amp;#039;print $1 if /&amp;#039;$db&amp;#039;.*PORT.*=.*(\d{4})/s&amp;#039;`&lt;br /&gt;
    ssh $server perl -p -i.bak -e &amp;#039;s/1521/&amp;#039;$LISTENERPORT&amp;#039;/&amp;#039; $i&lt;br /&gt;
    ssh $server ls -al ${i}*&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Run a job from cron every Nth day of the month===&lt;br /&gt;
Example. Execute a job every third Saturday of the month.&amp;lt;br /&amp;gt;&lt;br /&gt;
Paste this into a file called calenday and put it in /usr/local/bin so it&amp;#039;s (probably) on the PATH&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/usr/bin/ksh&lt;br /&gt;
&lt;br /&gt;
# ix is the week number of the month (&amp;quot;2&amp;quot;nd Friday of the month, &amp;quot;3&amp;quot;rd Tuesday of the month)&lt;br /&gt;
# dy is the day number in Unix format (0 for Sunday, 1 for Monday, ... 6 for Saturday)&lt;br /&gt;
# eg. &amp;quot;calenday 3 6&amp;quot; returns the date of 3rd Saturday of the month.&lt;br /&gt;
&lt;br /&gt;
ix=$1&lt;br /&gt;
dy=$2&lt;br /&gt;
SCHAR=$((($dy*2)+$dy+1))&lt;br /&gt;
ECHAR=$(($SCHAR+1))&lt;br /&gt;
cal `date &amp;#039;+%m %Y&amp;#039;` | egrep &amp;quot;\&amp;lt;[0-9]{1,2}\&amp;gt;&amp;quot; | cut -c${SCHAR}-${ECHAR} | xargs | awk {&amp;#039;print $&amp;#039;$ix&amp;#039;}&amp;#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Now in crontab, you should be able to do something like this:&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
15 20 * * * [[ `calenday 3 6` -eq `/bin/date &amp;#039;+%d&amp;#039;` ]] &amp;amp;&amp;amp; su - oracle -c &amp;quot;run_my_backup.ksh&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will also work on some Unices..&amp;lt;br /&amp;gt;&lt;br /&gt;
We send backups to a special TSM node on the second Friday of each month. This report must run a day later - but that is not guaranteed to be the second Saturday or even the 3rd. So...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
30 12 8-14 * 5 sleep 86400 &amp;amp;&amp;amp; su - oracle -c &amp;quot;/usr/bin/perl -ne &amp;#039;print if /ORX_M_SOL/ .. /^STOP/&amp;#039; /home/oracle/incoming/dbamon_spool_tsm_*.SOL | grep Archive | grep -v Client | mailx -s &amp;#039;Monthly TSM backups&amp;#039; orareport@xxxxxx.com&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ps listing does not show start time after 24 hours===&lt;br /&gt;
But you can see elapsed time using your own ps command&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/usr/bin/ps -eo etime,user,pid,ppid,cpu,start,tty,time,args|tail -n +2|sort&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ps -ef cuts off args cmd column on Solaris===&lt;br /&gt;
====To see more than 80 characters of the last column on Solaris====&lt;br /&gt;
This shows all the individual arguments to the command&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
pargs &amp;lt;pid&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This shows the ps listing in &amp;#039;compatibility&amp;#039; mode (there are more compatibility commands in /usr/xpg4/bin)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/usr/ucb/ps auww&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====To see more than 80 characters of the last column on AIX====&lt;br /&gt;
This shows the full argument listing of a process (NOTE: no minus sign!)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ps eww &amp;lt;pid&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Remove blank / empty lines from vi ===&lt;br /&gt;
Maybe you cut and pasted a file from Windows and it&amp;#039;s full of blank lines and Control-M&amp;#039;s now&amp;lt;br /&amp;gt;&lt;br /&gt;
There are several methods but I think this is the easiest to remember&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
:g/^$/d&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Right pad a variable===&lt;br /&gt;
a function like rpad in SQL but for Shell&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
function rpad {&lt;br /&gt;
text=$1&lt;br /&gt;
padwidth=$2&lt;br /&gt;
padchar=$3&lt;br /&gt;
echo &amp;quot;$text&amp;quot; | sed -e :a -e &amp;#039;s/^.\{1,&amp;#039;$padwidth&amp;#039;\}$/&amp;amp;\&amp;#039;$padchar&amp;#039;/;ta&amp;#039;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Connect to a Windows server from Linux using rdesktop===&lt;br /&gt;
My remmina stopped working so rolled my own. Very simple really. Put this is a shell.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
tsocks rdesktop -z -P -x m -a 16 -d MAIND -u sbarkley -p ****** -r disk:SOL=$HOME/Documents/SOL -g 95% 150.251.112.38 &amp;amp;&lt;br /&gt;
&lt;br /&gt;
where...&lt;br /&gt;
-z    - enables compression&lt;br /&gt;
-P    - enables bitmap caching (saves network traffic)&lt;br /&gt;
-x m  - disables eye-candy features&lt;br /&gt;
-a 16 - reduce colour pallete to 16 colours&lt;br /&gt;
-d    - domain to connect to&lt;br /&gt;
-u    - username&lt;br /&gt;
-p    - password&lt;br /&gt;
-r    - setup a shared folder&lt;br /&gt;
-g    - geometry (use W x H or percentage)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Slight problems with rdesktop not working 100% of the time. Now using xfreerdp. Seems better...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
xfreerdp -g 90% --ignore-certificate --gdi sw -K -d wdcrhbp05 -u oraibm -p &amp;quot;`cat $HOME/scripts/.oraibm.password`&amp;quot; -T &amp;quot;wdcrhbp05_oraibm&amp;quot; --plugin cliprdr --plugin rdpdr --data disk:SOL:/home/bey9at77/Documents/SOL -- --plugin rdpsnd --data alsa -- 150.251.112.25 &amp;amp;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Reset your password bypassing password rules===&lt;br /&gt;
must be done as root&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
echo &amp;quot;user:new_password&amp;quot; | chpasswd&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Sum the sizes of all files of an ls listing===&lt;br /&gt;
It&amp;#039;ll check to see if the sum of filesizes corresponds with the df -g (or h) listing (can get messed up due to open but deleted files)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cd /oracle/export&lt;br /&gt;
df -g .&lt;br /&gt;
find . -name &amp;quot;*dmp*&amp;quot; -ls |  awk &amp;#039;{ SUM += $7} END { print SUM/1024/1024/1024 }&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Mount an iso image under Linux===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
mkdir -p /mnt/cdrom&lt;br /&gt;
mount -o loop /dev/cdrom /mnt/cdrom&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===How many processors on the machine?===&lt;br /&gt;
* AIX&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
lsdev -C|grep Process|wc -l&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Solaris&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
psrinfo -v|grep &amp;quot;Status of processor&amp;quot;|wc -l&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Linux&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cat /proc/cpuinfo|grep processor|wc -l&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Quick, simple, understandable example of how to use RRDTool===&lt;br /&gt;
* [[RRDTool]]&lt;br /&gt;
&lt;br /&gt;
===Use expect to respond automatically to interactive programs===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/usr/bin/expect -f&lt;br /&gt;
spawn /usr/tivoli/tsm/client/oracle/bin64/tdpoconf passw -tdpo_optfile=/oracle/[lindex $argv 0]/admin/tdpo.opt&lt;br /&gt;
expect &amp;quot;assword:&amp;quot; {send &amp;quot;password\r&amp;quot;}&lt;br /&gt;
expect &amp;quot;assword:&amp;quot; {send &amp;quot;password\r&amp;quot;}&lt;br /&gt;
expect &amp;quot;assword:&amp;quot; {send &amp;quot;password\r&amp;quot;}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Use expect to allow file copy with scp (if ssh keys are not an option)===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/usr/bin/expect -f&lt;br /&gt;
spawn scp /home/oracle/.profile oracle@hn512:/tmp/prfl&lt;br /&gt;
set pass &amp;quot;thepassword&amp;quot;&lt;br /&gt;
expect {&lt;br /&gt;
        password: {send &amp;quot;$pass\r&amp;quot; ; exp_continue}&lt;br /&gt;
        eof exit&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Within a shell script set up simultaneous output to both terminal and a file using a FIFO (named pipes)===&lt;br /&gt;
or &amp;quot;How to send shell output to screen/stdout as well as to a logfile using tee and redirection with exec&amp;quot;&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
examples [http://www.unix.com/shell-programming-and-scripting/85584-redirect-within-ksh.html here on unix.com]&lt;br /&gt;
* general info on redirections [http://www.catonmat.net/blog/bash-one-liners-explained-part-three/ here at catonmat.net]&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/ksh&lt;br /&gt;
&lt;br /&gt;
REDIR=test.redir&lt;br /&gt;
FIFO=test.pipe&lt;br /&gt;
[[ -e $FIFO ]] || mkfifo $FIFO&lt;br /&gt;
&lt;br /&gt;
# make a new channel(3) and copy channel 1&amp;#039;s destination as its own (does NOT POINT TO channel 1&amp;#039;s destination)&lt;br /&gt;
# this allows the normal output to continue to STDOUT but also get printed to whatever file is attached to channel 3&lt;br /&gt;
exec 3&amp;gt;&amp;amp;1&lt;br /&gt;
&lt;br /&gt;
# anything coming in on the pipe, send it to $REDIR and to channel 3&lt;br /&gt;
tee $REDIR &amp;lt;$FIFO &amp;gt;&amp;amp;3 &amp;amp;&lt;br /&gt;
&lt;br /&gt;
# redirect STDOUT to the pipe&lt;br /&gt;
exec &amp;gt; $FIFO&lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;going to default output&amp;quot;&lt;br /&gt;
echo &amp;quot;forcing to channel 1&amp;quot; &amp;gt;&amp;amp;1&lt;br /&gt;
echo &amp;quot;forcing to channel 2&amp;quot; &amp;gt;&amp;amp;2&lt;br /&gt;
echo &amp;quot;forcing to channel 3&amp;quot; &amp;gt;&amp;amp;3&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====More elaborate example====&lt;br /&gt;
found [http://stackoverflow.com/questions/2288939/create-a-pipe-that-writes-to-multiple-files-tee here on stackoverflow]&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/sh&lt;br /&gt;
&lt;br /&gt;
# Author: Harvey Chapman &amp;lt;hchapman _AT_ 3gfp.com&amp;gt;&lt;br /&gt;
# Description: POSIX shell functions that can be used with tee to simultaneously put&lt;br /&gt;
#              stderr and stdout to both a file and stdout&lt;br /&gt;
#&lt;br /&gt;
# Based on:&lt;br /&gt;
#    Re: How to redirect stderr and stdout to a file plus display at the same time&lt;br /&gt;
#    http://www.travishartwell.net/blog/2006/08/19_2220&lt;br /&gt;
&lt;br /&gt;
#&lt;br /&gt;
# Original example function from Travis Hartwell&amp;#039;s blog.&lt;br /&gt;
# Note: I&amp;#039;ve made minor changes to it.&lt;br /&gt;
example()&lt;br /&gt;
{&lt;br /&gt;
  OUTPUT_LOG=output.log&lt;br /&gt;
  OUTPUT_PIPE=output.pipe&lt;br /&gt;
&lt;br /&gt;
  # This should really be -p to test that it&amp;#039;s a pipe.&lt;br /&gt;
  if [ ! -e $OUTPUT_PIPE ]; then&lt;br /&gt;
      mkfifo $OUTPUT_PIPE&lt;br /&gt;
  fi&lt;br /&gt;
&lt;br /&gt;
  # This should really be -f to test that it&amp;#039;s a regular file.&lt;br /&gt;
  if [ -e $OUTPUT_LOG ]; then&lt;br /&gt;
      rm $OUTPUT_LOG&lt;br /&gt;
  fi&lt;br /&gt;
&lt;br /&gt;
  exec 3&amp;gt;&amp;amp;1 4&amp;gt;&amp;amp;2&lt;br /&gt;
  tee $OUTPUT_LOG &amp;lt; $OUTPUT_PIPE &amp;gt;&amp;amp;3 &amp;amp;&lt;br /&gt;
  tpid=$!&lt;br /&gt;
  exec &amp;gt; $OUTPUT_PIPE 2&amp;gt;&amp;amp;1&lt;br /&gt;
&lt;br /&gt;
  echo &amp;quot;This is on standard out&amp;quot;&lt;br /&gt;
  echo &amp;quot;This is on standard err&amp;quot; &amp;gt;&amp;amp;2&lt;br /&gt;
&lt;br /&gt;
  exec 1&amp;gt;&amp;amp;3 3&amp;gt;&amp;amp;- 2&amp;gt;&amp;amp;4 4&amp;gt;&amp;amp;-&lt;br /&gt;
  wait $tpid&lt;br /&gt;
&lt;br /&gt;
  rm $OUTPUT_PIPE&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
# A slightly reduced version of example()&lt;br /&gt;
example2()&lt;br /&gt;
{&lt;br /&gt;
  OUTPUT_LOG=output.log&lt;br /&gt;
  OUTPUT_PIPE=output.pipe&lt;br /&gt;
&lt;br /&gt;
  rm -f $OUTPUT_PIPE&lt;br /&gt;
  mkfifo $OUTPUT_PIPE&lt;br /&gt;
  rm -f $OUTPUT_LOG&lt;br /&gt;
&lt;br /&gt;
  tee $OUTPUT_LOG &amp;lt; $OUTPUT_PIPE &amp;amp;&lt;br /&gt;
  tpid=$!&lt;br /&gt;
&lt;br /&gt;
  exec 3&amp;gt;&amp;amp;1 4&amp;gt;&amp;amp;2 &amp;gt;$OUTPUT_PIPE 2&amp;gt;&amp;amp;1&lt;br /&gt;
&lt;br /&gt;
  echo &amp;quot;This is on standard out&amp;quot;&lt;br /&gt;
  echo &amp;quot;This is on standard err&amp;quot; &amp;gt;&amp;amp;2&lt;br /&gt;
&lt;br /&gt;
  exec 1&amp;gt;&amp;amp;3 3&amp;gt;&amp;amp;- 2&amp;gt;&amp;amp;4 4&amp;gt;&amp;amp;-&lt;br /&gt;
  wait $tpid&lt;br /&gt;
  rm -f $OUTPUT_PIPE&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
#&lt;br /&gt;
# Logging methods based on above. See the example below for how to use them.&lt;br /&gt;
#&lt;br /&gt;
&lt;br /&gt;
# Usage: start_logging [delete_existing_logfile]&lt;br /&gt;
start_logging()&lt;br /&gt;
{&lt;br /&gt;
  # Check to see if OUTPUT_LOG and OUTPUT_PIPE need to be defined.&lt;br /&gt;
  if [ -z &amp;quot;$OUTPUT_LOG&amp;quot; ]; then&lt;br /&gt;
    OUTPUT_LOG=output.log&lt;br /&gt;
  fi&lt;br /&gt;
  if [ -z &amp;quot;$OUTPUT_PIPE&amp;quot; ]; then&lt;br /&gt;
    OUTPUT_PIPE=output.pipe&lt;br /&gt;
  fi&lt;br /&gt;
  # Make sure that we&amp;#039;re not already logging.&lt;br /&gt;
  if [ -n &amp;quot;$OUTPUT_PID&amp;quot; ]; then&lt;br /&gt;
    echo &amp;quot;Logging already started!&amp;quot;&lt;br /&gt;
    return 1&lt;br /&gt;
  fi&lt;br /&gt;
&lt;br /&gt;
  # Always remove the log and pipe first.&lt;br /&gt;
  rm -f $OUTPUT_PIPE&lt;br /&gt;
  # Delete the logfile first if told to.&lt;br /&gt;
  if [ &amp;quot;$1&amp;quot; = delete_existing_logfile ]; then&lt;br /&gt;
    rm -f $OUTPUT_LOG&lt;br /&gt;
  fi&lt;br /&gt;
&lt;br /&gt;
  mkfifo $OUTPUT_PIPE&lt;br /&gt;
  tee -a $OUTPUT_LOG &amp;lt; $OUTPUT_PIPE &amp;amp;&lt;br /&gt;
  OUTPUT_PID=$!&lt;br /&gt;
&lt;br /&gt;
  exec 3&amp;gt;&amp;amp;1 4&amp;gt;&amp;amp;2 &amp;gt;$OUTPUT_PIPE 2&amp;gt;&amp;amp;1&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
stop_logging()&lt;br /&gt;
{&lt;br /&gt;
  # Make sure that we&amp;#039;re currently logging.&lt;br /&gt;
  if [ -z &amp;quot;$OUTPUT_PID&amp;quot; ]; then&lt;br /&gt;
    echo &amp;quot;Logging not yet started!&amp;quot;&lt;br /&gt;
    return 1&lt;br /&gt;
  fi&lt;br /&gt;
  exec 1&amp;gt;&amp;amp;3 3&amp;gt;&amp;amp;- 2&amp;gt;&amp;amp;4 4&amp;gt;&amp;amp;-&lt;br /&gt;
  wait $OUTPUT_PID&lt;br /&gt;
  rm -f $OUTPUT_PIPE&lt;br /&gt;
  unset OUTPUT_PID&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
example3()&lt;br /&gt;
{&lt;br /&gt;
  start_logging&lt;br /&gt;
  #start_logging delete_existing_logfile&lt;br /&gt;
  echo &amp;quot;This is on standard out&amp;quot;&lt;br /&gt;
  echo &amp;quot;This is on standard err&amp;quot; &amp;gt;&amp;amp;2&lt;br /&gt;
  stop_logging&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===RedHat root filesystem has gone read-only===&lt;br /&gt;
* [http://www.unixarena.com/2013/09/redhat-linux-how-to-fix-read-only-root.html How to fix read only root file system]&lt;br /&gt;
&lt;br /&gt;
===Kill all processes for a user===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
for prc in `ps -ef | grep -E &amp;quot;^ +[o]racle&amp;quot; | awk &amp;#039;{print $2}&amp;#039;`; do&lt;br /&gt;
    kill $prc&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===isRGHere===&lt;br /&gt;
Checks if resource group is on this leg of an HACMP cluster. Returns 0 if true else 1.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/usr/bin/ksh&lt;br /&gt;
&lt;br /&gt;
SCRIPT=`basename $0`&lt;br /&gt;
&lt;br /&gt;
function rctest&lt;br /&gt;
{&lt;br /&gt;
exitcode=$1&lt;br /&gt;
msg=$2&lt;br /&gt;
if [ $exitcode -ne 0 ]; then&lt;br /&gt;
        echo &amp;quot;********************************************************************************&amp;quot;&lt;br /&gt;
        echo &amp;quot;\nScript $SCRIPT finished with errors.&amp;quot;&lt;br /&gt;
        echo &amp;quot;$msg.&amp;quot;&lt;br /&gt;
        echo &amp;quot;Returncode : $exitcode.&amp;quot;&lt;br /&gt;
        echo &amp;quot;\n********************************************************************************&amp;quot;&lt;br /&gt;
&lt;br /&gt;
        fi&lt;br /&gt;
exit $exitcode&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
RGINFO=/usr/es/sbin/cluster/utilities/clRGinfo&lt;br /&gt;
[[ ! -f $RGINFO ]] &amp;amp;&amp;amp;  rctest 1 &amp;quot;clRGinfo not found&amp;quot;&lt;br /&gt;
&lt;br /&gt;
if [ $# -eq 1 ]&lt;br /&gt;
then&lt;br /&gt;
        RG=`echo $1 | cut -c 1-14`&lt;br /&gt;
else&lt;br /&gt;
        rctest 10  &amp;quot;Usage: `basename $0` &amp;lt;RG name&amp;gt;&amp;quot;&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
$RGINFO |grep -qwp $RG ||  rctest 9 &amp;quot;$RG is not defined&amp;quot;&lt;br /&gt;
&lt;br /&gt;
THISNODE=`/usr/es/sbin/cluster/utilities/get_local_nodename | cut -c 1-14`&lt;br /&gt;
$RGINFO |grep -wp $RG |grep -w $THISNODE |grep -wq ONLINE&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===AIX: add a user to a group===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
chgrpmem -m + oracle ibmtls&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Find swear words in scripts by comparing it to a list found on the internet===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
wget &amp;quot;http://www.bannedwordlist.com/lists/swearWords.csv&amp;quot; -O /tmp/s ; for word in $(cat /tmp/s | sed -e &amp;#039;s/ /_/g&amp;#039; -e &amp;#039;s/,/ /g&amp;#039;) ; do grep -wR $word *; done | less&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===grep -p (for paragraph) works on AIX but not on Linux or Solaris===&lt;br /&gt;
Use awk instead&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
awk &amp;#039;BEGIN {FS=&amp;quot;\n&amp;quot; RS=&amp;quot;\n\n&amp;quot;} /search pattern/ { do something }&amp;#039; &amp;lt;file&amp;gt;&lt;br /&gt;
/usr/xpg4/bin/awk &amp;#039;BEGIN {RS=&amp;quot;\n\n&amp;quot;;FS=&amp;quot;\n&amp;quot;} /AGRHDWQ1/ {print $2}&amp;#039; dsm.sys | awk &amp;#039;{print $NF}&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
this prints the last word of the second &amp;#039;&amp;#039;line&amp;#039;&amp;#039; in the paragraph in dsm.sys that contains the search term AGRHDWQ1.&amp;lt;br /&amp;gt;&lt;br /&gt;
Or slightly simpler...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
awk -v RS=&amp;#039;&amp;#039; &amp;#039;/NHAPPLP1/&amp;#039; /etc/tsm/dsm.sys     # (use /usr/xpg4/bin/awk on Solaris)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or, case insensitively:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
awk -v RS=&amp;#039;&amp;#039; &amp;#039;tolower($0) ~/so_u_clubqa_orx_d_cab/&amp;#039; /etc/tsm/dsm.sys&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Using -v means you don&amp;#039;t have to use a BEGIN section.&lt;br /&gt;
&lt;br /&gt;
===debug/redirect log of a shell===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/usr/bin/ksh&lt;br /&gt;
exec 2&amp;gt;/tmp/mytest&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Different ways of Iteration in korn shell with a while loop===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
IFS=&amp;quot;|&amp;quot;&lt;br /&gt;
exec 0&amp;lt;$statfile&lt;br /&gt;
while read host db started stopped&lt;br /&gt;
do&lt;br /&gt;
    rrdfile=&amp;quot;export_duration_${host}_${db}.rrd&amp;quot;&lt;br /&gt;
    $RRDTOOL update ${RRDDIR}/${rrdfile} $started:$started $stopped&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
while read host db started stopped&lt;br /&gt;
do&lt;br /&gt;
    rrdfile=&amp;quot;export_duration_${host}_${db}.rrd&amp;quot;&lt;br /&gt;
    $RRDTOOL update ${RRDDIR}/${rrdfile} $started:$started $stopped&lt;br /&gt;
done &amp;lt;statfile&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    cat $statfile | sort -nk4 | while IFS=\| read host db type started stopped&lt;br /&gt;
    do&lt;br /&gt;
        [[ &amp;quot;$stopped&amp;quot; == &amp;quot;&amp;quot; ]] &amp;amp;&amp;amp; continue&lt;br /&gt;
        rrdfile=&amp;quot;export_duration_${host}_${db}.rrd&amp;quot;&lt;br /&gt;
        $RRDTOOL update ${RRDDIR}/${rrdfile} ${started}:${started}:${stopped}&lt;br /&gt;
        [[ $? -ne 0 ]] &amp;amp;&amp;amp; echo &amp;quot;nok: $?&amp;quot;&lt;br /&gt;
    done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Filesystem 100% full, what&amp;#039;s taking up all the space?===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
find /oracle/endur -xdev -ls|sort -nr +6|head&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/dev/esb01fs010001      1.00      0.00  100%     1838    69% /oracle&lt;br /&gt;
beuxdsysesb01:root[/root]# cd /oracle&lt;br /&gt;
beuxdsysesb01:root[/oracle]# du -gsx * | sort -n&lt;br /&gt;
0.00    checkpoints&lt;br /&gt;
0.00    flash_recovery_area&lt;br /&gt;
0.00    lost+found&lt;br /&gt;
0.00    oraInst.loc&lt;br /&gt;
0.00    oraInventory&lt;br /&gt;
0.09    admin&lt;br /&gt;
0.99    diag&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
cd  diag and repeat until culprits are found&lt;br /&gt;
&lt;br /&gt;
===Show paged memory hogs on AIX===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
svmon -Pt20 | perl -e &amp;#039;while(&amp;lt;&amp;gt;){print if($.==2||$&amp;amp;&amp;amp;&amp;amp;!$s++);$.=0 if(/^-+$/)}&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Capitalise the first letter of a word in Korn Shell===&lt;br /&gt;
Not as easy as it sounds if it needs to work in non-ksh93 shells&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
function capit { &lt;br /&gt;
    typeset -u first&lt;br /&gt;
    first=${1%&amp;quot;${1#?}&amp;quot;}&lt;br /&gt;
    printf &amp;quot;%s\n&amp;quot; &amp;quot;${first}${1#?}&amp;quot;&lt;br /&gt;
    return 0&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or maybe more neatly done in Perl...&amp;lt;br /&amp;gt;&lt;br /&gt;
This will capitalise each word in a sentence passed into it&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
function capit { &lt;br /&gt;
    echo &amp;quot;$1&amp;quot; |  perl -pe &amp;quot;s/([\w&amp;#039;]+)/\u\L\1/g&amp;quot;&lt;br /&gt;
    return 0&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Remove / rename a directory / file containing weird control characters===&lt;br /&gt;
Use ls with -i to see inode listing&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ls -bali&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Use find with -inum to get the filename and -exec to remove it&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
find . -inum &amp;lt;inode from ls listing&amp;gt; -exec rm -f {} \;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Run a local script on a remote host===&lt;br /&gt;
Doing it this way means we do not need to scp the shell over to the host before executing it!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ssh user@host &amp;#039;sh&amp;#039; &amp;lt; your_script.sh&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
First of all, this command is a redirection: your shell will open the file your_script.sh and feed it as input to the ssh command. ssh, in turn, will tunnel its stdin to the remote command, namely, sh instance. And sh without arguments reads its script from stdin. So we got sh instance, which is launched on remote host, but reads commands from your local file.&lt;br /&gt;
&lt;br /&gt;
===Get a list of running instances - but only those started by the current user===&lt;br /&gt;
This is the way I wanted to do it but there&amp;#039;s an issue. Where does that spare } character come from? Anyone?&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ps -ef | grep [p]mon | awk -v dbowner=$(id -un) &amp;#039;{ if ($1==dbowner) { gsub(/ora_pmon_/,&amp;quot;&amp;quot;,$NF); print $NF; } }&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
ps listing&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ ps -ef | grep [p]mon&lt;br /&gt;
  oracle 13304024        1   0   Jun 07      -  2:39 ora_pmon_reportk&lt;br /&gt;
  oracle 26018178        1   0   Jun 07      -  3:01 ora_pmon_dwh_perf&lt;br /&gt;
  oracle 29229432        1   0   Jun 07      -  2:30 ora_pmon_adso&lt;br /&gt;
 oraebso 18022994        1   0   Jun 07      -  2:38 ora_pmon_EBSO&lt;br /&gt;
  oracle 30278192        1   0   Jun 07      -  2:48 ora_pmon_owb112k&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Results of above command&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
reportk&lt;br /&gt;
dwh_perf&lt;br /&gt;
adso&lt;br /&gt;
}&lt;br /&gt;
owb112k&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Workaround 1. Send the ps listing to a file and work on it without pipes. Works but it&amp;#039;s a bit long-winded especially as we have to clean up afterwards.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ps -ef | grep [p]mon&amp;gt;/tmp/results.$$ 2&amp;gt;/dev/null; awk -v dbowner=$(id -un) &amp;#039;{ if ($1==dbowner) { gsub(/ora_pmon_/,&amp;quot;&amp;quot;,$NF); print $NF; } }&amp;#039; /tmp/results.$$; rm -f /tmp/results.$$&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Workaround 2. Don&amp;#039;t like the grep -v but until I find out where that } is coming from..&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ps -ef | grep [p]mon | awk -v dbowner=$(id -un) &amp;#039;{ if ($1==dbowner) { gsub(/ora_pmon_/,&amp;quot;&amp;quot;,$NF); print $NF; } }&amp;#039; | egrep -v &amp;#039;grep|}|ASM&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Return a list of Oracle databases running on a list of remote servers===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/ksh&lt;br /&gt;
&lt;br /&gt;
serverlist=`cat /home/tools/ini/system/oracle_servers | sort -n | tr &amp;quot;\n&amp;quot; &amp;quot; &amp;quot;`&lt;br /&gt;
&lt;br /&gt;
if [ -z &amp;quot;${serverlist}&amp;quot; ]&lt;br /&gt;
then&lt;br /&gt;
    echo &amp;quot;no servers found&amp;quot; &amp;amp;&amp;amp; exit 1&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
for server in ${serverlist}&lt;br /&gt;
do&lt;br /&gt;
    ssh ${server} &amp;quot;ps -ef | grep [o]ra_pmon_&amp;quot; &amp;gt;/tmp/${server}.dblist&lt;br /&gt;
done&lt;br /&gt;
&lt;br /&gt;
for server in ${serverlist}&lt;br /&gt;
do&lt;br /&gt;
    cat /tmp/${server}.dblist | awk -F_ -v SRV=${server} &amp;#039;BEGIN {print SRV &amp;quot;:&amp;quot;} {print $NF}&amp;#039; | tr &amp;quot;\n&amp;quot; &amp;quot; &amp;quot;&lt;br /&gt;
    echo&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Clever trick to check whether SQL output needs sending to someone===&lt;br /&gt;
Using an exit status from SQL*Plus back to the shell so we can decide what to do.  Nice one!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
tempfile=/tmp/audit_locked_accounts_$ORACLE_SID.txt&lt;br /&gt;
&lt;br /&gt;
# Start sqlplus and check for locked accounts&lt;br /&gt;
sqlplus -S &amp;quot;/ as sysdba&amp;quot; &amp;lt;&amp;lt; EOF &amp;gt; $tempfile&lt;br /&gt;
set pages 0&lt;br /&gt;
select &amp;#039;The following accounts were found to be unlocked and should not be&amp;#039;&lt;br /&gt;
from dual;&lt;br /&gt;
&lt;br /&gt;
def exit_status = 0&lt;br /&gt;
col xs new_value exit_status&lt;br /&gt;
&lt;br /&gt;
select username&lt;br /&gt;
,      account_status&lt;br /&gt;
,      1 as xs&lt;br /&gt;
from   dba_users&lt;br /&gt;
where  account_status != &amp;#039;LOCKED&amp;#039;&lt;br /&gt;
and    username in (&amp;#039;HR&amp;#039;, &amp;#039;SCOTT&amp;#039;, &amp;#039;OUTLN&amp;#039;, &amp;#039;MDSYS&amp;#039;, &amp;#039;CTXSYS&amp;#039;)&lt;br /&gt;
/&lt;br /&gt;
exit &amp;amp;exit_status&lt;br /&gt;
EOF&lt;br /&gt;
&lt;br /&gt;
# If the exit status of sqlplus was not 0 then we will send an email&lt;br /&gt;
if [ $? != 0 ]; then&lt;br /&gt;
    mail -s &amp;quot;Accounts Unlocked in $ORACLE_SID&amp;quot; oracle &amp;lt; $tempfile&lt;br /&gt;
fi&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Check RMAN logfiles for errors from cron every day===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
00 09 * * * /home/tools/scripts/oracle/dosh &amp;#039;find /home/tools/logs/rman -name &amp;quot;*online.log&amp;quot; -mtime -1 -exec sed -ne &amp;quot;/^RMAN-/,/^$/p&amp;quot; {} \\; -ls&amp;#039; | mailx&lt;br /&gt;
 -s &amp;#039;RMAN errors last night&amp;#039; stuart@domain.com&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/home/ibmtools/scripts/oracle/dosh &amp;#039;find /oracle/export -name &amp;quot;expdp*log&amp;quot; -mtime -1 -exec grep ORA- {} \; -ls&amp;#039; | mailx -s &amp;#039;Datapump errors for Baxter last night&amp;#039; stuart@domain.com&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===An alternative to getopts===&lt;br /&gt;
These methods have the advantage of allowing arguments of any length not just 1 character&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
countArgs=$#&lt;br /&gt;
while [[ $# -gt 0 ]]&lt;br /&gt;
do&lt;br /&gt;
    idx1=$($ECHO $1|$GREP &amp;quot;=&amp;quot;|wc -l)&lt;br /&gt;
    if [[ $idx1 -gt 0 ]]; then&lt;br /&gt;
        key=$($ECHO $1|$CUT -d &amp;#039;=&amp;#039; -f 1)&lt;br /&gt;
        value=$($ECHO $1|$CUT -d &amp;#039;=&amp;#039; -f 2)&lt;br /&gt;
    else&lt;br /&gt;
        key=$($ECHO $1|$CUT -d &amp;#039;=&amp;#039; -f 1)&lt;br /&gt;
        idx2=$($ECHO $1|$GREP &amp;quot;^-&amp;quot;|wc -l)&lt;br /&gt;
        if [[ $idx2 -eq 0 ]]; then&lt;br /&gt;
            $ECHO -e &amp;quot;\n ERROR: $1 is an unsupported argument passed to agentDeploy.sh.\n&amp;quot;  &lt;br /&gt;
            usage&lt;br /&gt;
            exit 1&lt;br /&gt;
        fi&lt;br /&gt;
    fi&lt;br /&gt;
&lt;br /&gt;
    case &amp;quot;$key&amp;quot; in&lt;br /&gt;
    -help)&lt;br /&gt;
        if [[ $upgradeFlag ]]; then&lt;br /&gt;
            upgradeUsage&lt;br /&gt;
        else&lt;br /&gt;
            freshUsage&lt;br /&gt;
        fi&lt;br /&gt;
        exit 0;;&lt;br /&gt;
    AGENT_BASE_DIR)&lt;br /&gt;
        agentBaseDir=$($ECHO $value|$SED &amp;#039;s/\/$//&amp;#039;)&lt;br /&gt;
        checkBaseFlag=TRUE;;&lt;br /&gt;
    OMS_HOST)&lt;br /&gt;
        omsHost=$value&lt;br /&gt;
        checkOMSHost=TRUE;;&lt;br /&gt;
    EM_UPLOAD_PORT)&lt;br /&gt;
        omsPort=$value&lt;br /&gt;
        checkOMSPort=TRUE;;&lt;br /&gt;
    AGENT_INSTANCE_HOME)&lt;br /&gt;
        instHome=$($ECHO $value | $SED &amp;#039;s/\/$//&amp;#039;);;&lt;br /&gt;
    AGENT_REGISTRATION_PASSWORD)&lt;br /&gt;
        pswd=$value;;&lt;br /&gt;
    s_encrSecurePwd)&lt;br /&gt;
        pswd=$value;;  &lt;br /&gt;
    RESPONSE_FILE)&lt;br /&gt;
        rspFlag=TRUE  &lt;br /&gt;
        rspLoc=$value;;&lt;br /&gt;
    OLD_AGENT_VERSION)&lt;br /&gt;
        oldAgentVersion=$value;;            &lt;br /&gt;
    OLDHOME)&lt;br /&gt;
        oldHome=$value;;    &lt;br /&gt;
    -debug)&lt;br /&gt;
        debugSwitch=TRUE;;&lt;br /&gt;
    -forceConfigure)&lt;br /&gt;
        forceFlag=TRUE;;&lt;br /&gt;
    -configOnly)&lt;br /&gt;
        configFlag=TRUE    &lt;br /&gt;
        validationFlag=TRUE;;&lt;br /&gt;
    -agentImageLocation)&lt;br /&gt;
        archiveLoc=$value&lt;br /&gt;
        checkArchiveFlag=TRUE;;&lt;br /&gt;
    -invPtrLoc) shift&lt;br /&gt;
        ptrLoc=$1;;&lt;br /&gt;
    -Upgrade)&lt;br /&gt;
        UpgradeFlag=TRUE&lt;br /&gt;
        validFlag=TRUE;;&lt;br /&gt;
    INVENTORY_LOCATION)&lt;br /&gt;
        validFlag=TRUE;;&lt;br /&gt;
    b_forceInstCheck)&lt;br /&gt;
        validFlag=TRUE&lt;br /&gt;
        forcefullFlag=TRUE;;&lt;br /&gt;
    -prereqOnly)&lt;br /&gt;
        validationFlag=TRUE&lt;br /&gt;
        prereqFlag=TRUE;;&lt;br /&gt;
    -executeRootsh)&lt;br /&gt;
        validFlag=TRUE;;&lt;br /&gt;
    *)  idx=$($ECHO $1|$GREP &amp;quot;^-&amp;quot;|wc -l)&lt;br /&gt;
        if [[ $idx -eq 0 ]]; then&lt;br /&gt;
            validFlag=TRUE&lt;br /&gt;
        else&lt;br /&gt;
            $ECHO -e &amp;quot;\n ERROR: Invalid argument $key passed.&amp;quot;&lt;br /&gt;
            usage&lt;br /&gt;
            exit 1          &lt;br /&gt;
        fi&lt;br /&gt;
    esac&lt;br /&gt;
    shift&lt;br /&gt;
done&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
another way - found in /etc/init.d/functions (daemon function) in Fedora&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    while [ &amp;quot;$1&amp;quot; != &amp;quot;${1##[-+]}&amp;quot; ]; do&lt;br /&gt;
        case $1 in&lt;br /&gt;
        &amp;#039;&amp;#039;)&lt;br /&gt;
            echo $&amp;quot;$0: Usage: daemon [+/-nicelevel] {program}&amp;quot; &amp;quot;[arg1]...&amp;quot;&lt;br /&gt;
            return 1&lt;br /&gt;
            ;;&lt;br /&gt;
        --check)&lt;br /&gt;
            base=$2&lt;br /&gt;
            gotbase=&amp;quot;yes&amp;quot;&lt;br /&gt;
            shift 2&lt;br /&gt;
            ;;&lt;br /&gt;
        --check=?*)&lt;br /&gt;
            base=${1#--check=}&lt;br /&gt;
            gotbase=&amp;quot;yes&amp;quot;&lt;br /&gt;
            shift&lt;br /&gt;
            ;;&lt;br /&gt;
        --user)&lt;br /&gt;
            user=$2&lt;br /&gt;
            shift 2&lt;br /&gt;
            ;;&lt;br /&gt;
        --user=?*)&lt;br /&gt;
            user=${1#--user=}&lt;br /&gt;
            shift&lt;br /&gt;
            ;;&lt;br /&gt;
        --pidfile)&lt;br /&gt;
            pid_file=$2&lt;br /&gt;
            shift 2&lt;br /&gt;
            ;;&lt;br /&gt;
        --pidfile=?*)&lt;br /&gt;
            pid_file=${1#--pidfile=}&lt;br /&gt;
            shift&lt;br /&gt;
            ;;&lt;br /&gt;
        --force)&lt;br /&gt;
            force=&amp;quot;force&amp;quot;&lt;br /&gt;
            shift&lt;br /&gt;
            ;;&lt;br /&gt;
        [-+][0-9]*)&lt;br /&gt;
            nice=&amp;quot;nice -n $1&amp;quot;&lt;br /&gt;
            shift&lt;br /&gt;
            ;;&lt;br /&gt;
        *)&lt;br /&gt;
            echo $&amp;quot;$0: Usage: daemon [+/-nicelevel] {program}&amp;quot; &amp;quot;[arg1]...&amp;quot;&lt;br /&gt;
            return 1&lt;br /&gt;
            ;;&lt;br /&gt;
      esac&lt;br /&gt;
    done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
another way - found in adstrtal.sh (middleware start script for EBS)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#&lt;br /&gt;
# Parse Arguments&lt;br /&gt;
#&lt;br /&gt;
&lt;br /&gt;
for nxtarg in $*&lt;br /&gt;
do&lt;br /&gt;
  arg=`echo $nxtarg | sed &amp;#039;s/^//&amp;#039;`&lt;br /&gt;
&lt;br /&gt;
  case $arg in&lt;br /&gt;
    -secureapps)    if test &amp;quot;$secureapps&amp;quot; = &amp;quot;&amp;quot; ; then&lt;br /&gt;
                       secureapps=$arg&lt;br /&gt;
                    else&lt;br /&gt;
                       echo &amp;quot;$0: Duplicate Argument passed : $arg&amp;quot;&lt;br /&gt;
                       usage&lt;br /&gt;
                    fi&lt;br /&gt;
                ;;&lt;br /&gt;
    -nodbchk)       if test &amp;quot;$nodbchk&amp;quot; = &amp;quot;&amp;quot; ; then&lt;br /&gt;
                       nodbchk=$arg&lt;br /&gt;
                    else&lt;br /&gt;
                       echo &amp;quot;$0: Duplicate Argument passed : $arg&amp;quot;&lt;br /&gt;
                       usage&lt;br /&gt;
                    fi&lt;br /&gt;
                ;;&lt;br /&gt;
    -nopromptmsg)   if test &amp;quot;$nopromptmsg&amp;quot; = &amp;quot;&amp;quot; ; then&lt;br /&gt;
                       nopromptmsg=$arg&lt;br /&gt;
                    else&lt;br /&gt;
                       echo &amp;quot;$0: Duplicate Argument passed : $arg&amp;quot;&lt;br /&gt;
                       usage&lt;br /&gt;
                    fi&lt;br /&gt;
                ;;&lt;br /&gt;
    *)              if test &amp;quot;$unpw&amp;quot; = &amp;quot;&amp;quot; ; then&lt;br /&gt;
                       unpw=$arg&lt;br /&gt;
                    else&lt;br /&gt;
                       echo &amp;quot;$0: Duplicate Argument passed : $arg&amp;quot;&lt;br /&gt;
                       usage&lt;br /&gt;
                    fi&lt;br /&gt;
  esac&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
and another in adautocfg.sh&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
for myarg in $*&lt;br /&gt;
do&lt;br /&gt;
&lt;br /&gt;
  arg=`echo $myarg | sed &amp;#039;s/^-//&amp;#039;`&lt;br /&gt;
  case $arg in&lt;br /&gt;
    appspass=*)&lt;br /&gt;
            appspass=`echo $arg | sed &amp;#039;s/appspass=//g&amp;#039;`&lt;br /&gt;
            shift&lt;br /&gt;
            ;;&lt;br /&gt;
    nocustom)&lt;br /&gt;
            myparams=&amp;quot;$myparams $arg&amp;quot;&lt;br /&gt;
            shift&lt;br /&gt;
            ;;&lt;br /&gt;
    noversionchecks)&lt;br /&gt;
            myparams=&amp;quot;$myparams $arg&amp;quot;&lt;br /&gt;
            shift&lt;br /&gt;
            ;;&lt;br /&gt;
    promptmsg=*)&lt;br /&gt;
            promptmsg=`echo $arg | sed &amp;#039;s/promptmsg=//g&amp;#039;`&lt;br /&gt;
            shift&lt;br /&gt;
            ;;&lt;br /&gt;
        *)  echo &amp;quot;$0: unrecognized action specified&amp;quot;&lt;br /&gt;
            exit 1&lt;br /&gt;
  esac&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Run a script on multiple servers===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/ksh&lt;br /&gt;
# ==============================================================================&lt;br /&gt;
# Name         : dosh   (Distributed Oracle SHell)&lt;br /&gt;
# Description  : Runs a command on all Oracle servers&lt;br /&gt;
#&lt;br /&gt;
# Parameters   : h - displays help&lt;br /&gt;
#                v - verbose (default, like all unix commands is silent)&lt;br /&gt;
#                c - command to be executed&lt;br /&gt;
#&lt;br /&gt;
# Example      : ./dosh -v -c &amp;#039;ls -al&amp;#039;&lt;br /&gt;
#&lt;br /&gt;
# Modification History&lt;br /&gt;
# ====================&lt;br /&gt;
# When      Who               What&lt;br /&gt;
# ========= ================= ==================================================&lt;br /&gt;
# 08-FEB-13 Stuart Barkley    Created&lt;br /&gt;
# ==============================================================================&lt;br /&gt;
&lt;br /&gt;
# --------------------------------------------------------------------------&lt;br /&gt;
# this list of servers is generated by the DBAMON tool so will be up to date&lt;br /&gt;
# --------------------------------------------------------------------------&lt;br /&gt;
serverfile=/home/ibmtools/etc/oracle/oracle_servers&lt;br /&gt;
[[ -z &amp;quot;${serverfile}&amp;quot; ]] &amp;amp;&amp;amp; echo &amp;quot;Server list ${serverfile} not found&amp;quot; &amp;amp;&amp;amp; exit 1&lt;br /&gt;
&lt;br /&gt;
serverlist=`cat ${serverfile} | sort -n | tr &amp;quot;\n&amp;quot; &amp;quot; &amp;quot;`&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
# -------------------------&lt;br /&gt;
# get the arguments, if any&lt;br /&gt;
# -------------------------&lt;br /&gt;
while getopts &amp;quot;hvc:&amp;quot; OPT&lt;br /&gt;
do&lt;br /&gt;
    case &amp;quot;$OPT&amp;quot; in&lt;br /&gt;
    h) echo &amp;quot;\nUsage: $0 [-v] [-h] -c &amp;#039;&amp;lt;command_to_be_executed_remotely&amp;gt;&amp;#039;\n&amp;quot;;&lt;br /&gt;
       exit;&lt;br /&gt;
       ;;&lt;br /&gt;
    v) VERBOSE=&amp;quot;Y&amp;quot;;&lt;br /&gt;
       ;;&lt;br /&gt;
    c) CMMND=$OPTARG;&lt;br /&gt;
       ;;&lt;br /&gt;
    *) echo &amp;quot;\nUsage: $0 [-v] [-h] -c &amp;#039;&amp;lt;command_to_be_executed_remotely&amp;gt;&amp;#039;\n&amp;quot;;&lt;br /&gt;
       exit;&lt;br /&gt;
       ;;&lt;br /&gt;
    esac&lt;br /&gt;
done&lt;br /&gt;
shift $((OPTIND-1))&lt;br /&gt;
VERBOSE=${VERBOSE:-&amp;quot;N&amp;quot;}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
# --------------------------------&lt;br /&gt;
# check we have required arguments&lt;br /&gt;
# --------------------------------&lt;br /&gt;
[[ -z $CMMND ]] &amp;amp;&amp;amp; echo &amp;quot;Enter command to be executed like this: $0 -c &amp;#039;ls -al&amp;#039;&amp;quot; &amp;amp;&amp;amp; exit 1&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
# ----------------------------&lt;br /&gt;
# loop over the remote servers&lt;br /&gt;
# ----------------------------&lt;br /&gt;
for server in ${serverlist}&lt;br /&gt;
do&lt;br /&gt;
    if [[ &amp;quot;$VERBOSE&amp;quot; == &amp;quot;Y&amp;quot; ]]; then&lt;br /&gt;
        echo ${server} `date +&amp;#039;%d-%b-%Y %H:%M:%S&amp;#039;`&lt;br /&gt;
        echo &amp;quot;------------------------------------&amp;quot;&lt;br /&gt;
        set -x&lt;br /&gt;
    fi&lt;br /&gt;
    ssh ${server} &amp;quot;$CMMND&amp;quot;&lt;br /&gt;
    set +x&lt;br /&gt;
    [[ &amp;quot;$VERBOSE&amp;quot; == &amp;quot;Y&amp;quot; ]] &amp;amp;&amp;amp; echo&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
to be investigated... this one might be cleverer than mine...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
tmpdir=${TMPDIR:-/tmp}/pssh.$$&lt;br /&gt;
count=0&lt;br /&gt;
while userhost; do&lt;br /&gt;
    ssh -n -o BatchMode=yes ${userhost} &amp;#039;uname -a&amp;#039; &amp;gt; ${tmpdir}/${userhost} 2&amp;gt;&amp;amp;1 &amp;amp;&lt;br /&gt;
    count=`expr $count + 1`&lt;br /&gt;
done &amp;lt; userhost.lst&lt;br /&gt;
while [ $count -gt 0 ]; do&lt;br /&gt;
    wait $pids&lt;br /&gt;
    count=`expr $count - 1`&lt;br /&gt;
done&lt;br /&gt;
echo &amp;quot;Output for hosts are in $tmpdir&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
improved version...&amp;lt;br /&amp;gt;&lt;br /&gt;
just escape double quotes and dollar signs...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/ksh&lt;br /&gt;
# ==============================================================================&lt;br /&gt;
# Name         : dosh   (Distributed Oracle SHell)&lt;br /&gt;
# Description  : Runs a command on all Oracle servers&lt;br /&gt;
#&lt;br /&gt;
# Parameters   : h - displays help&lt;br /&gt;
#                v - verbose (default, like all unix commands is silent)&lt;br /&gt;
#                c - command to be executed&lt;br /&gt;
#&lt;br /&gt;
# Example      : ./dosh -v -c &amp;#039;ls -al&amp;#039;&lt;br /&gt;
#&lt;br /&gt;
# Modification History&lt;br /&gt;
# ====================&lt;br /&gt;
# When      Who               What&lt;br /&gt;
# ========= ================= ==================================================&lt;br /&gt;
# 08-FEB-13 Stuart Barkley    Created&lt;br /&gt;
# 08-JUL-15 Stuart Barkley    Background execution mode&lt;br /&gt;
# ==============================================================================&lt;br /&gt;
# --------------------------------------------------------------------------&lt;br /&gt;
# this list of servers is generated by the DBAMON tool so will be up to date&lt;br /&gt;
# --------------------------------------------------------------------------&lt;br /&gt;
serverfile=/home/ibmtools/etc/oracle/oracle_servers&lt;br /&gt;
[[ -z &amp;quot;${serverfile}&amp;quot; ]] &amp;amp;&amp;amp; echo &amp;quot;Server list ${serverfile} not found&amp;quot; &amp;amp;&amp;amp; exit 1&lt;br /&gt;
&lt;br /&gt;
serverlist=`cat ${serverfile} | sort -n | tr &amp;quot;\n&amp;quot; &amp;quot; &amp;quot;`&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
# -------------------------&lt;br /&gt;
# get the arguments, if any&lt;br /&gt;
# -------------------------&lt;br /&gt;
while getopts &amp;quot;hbvc:&amp;quot; OPT&lt;br /&gt;
do&lt;br /&gt;
    case &amp;quot;$OPT&amp;quot; in&lt;br /&gt;
    h) echo &amp;quot;\nUsage: $0 [-b] [-v] [-h] -c &amp;#039;&amp;lt;command_to_be_executed_remotely&amp;gt;&amp;#039;\n&amp;quot;;&lt;br /&gt;
       exit;&lt;br /&gt;
       ;;&lt;br /&gt;
    b) BACKGROUND=&amp;quot;Y&amp;quot;;&lt;br /&gt;
       ;;&lt;br /&gt;
    v) VERBOSE=&amp;quot;Y&amp;quot;;&lt;br /&gt;
       ;;&lt;br /&gt;
    c) CMMND=$OPTARG;&lt;br /&gt;
       ;;&lt;br /&gt;
    *) echo &amp;quot;\nUsage: $0 [-b] [-v] [-h] -c &amp;#039;&amp;lt;command_to_be_executed_remotely&amp;gt;&amp;#039;\n&amp;quot;;&lt;br /&gt;
       exit;&lt;br /&gt;
       ;;&lt;br /&gt;
    esac&lt;br /&gt;
done&lt;br /&gt;
shift $((OPTIND-1))&lt;br /&gt;
VERBOSE=${VERBOSE:-&amp;quot;N&amp;quot;}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
# --------------------------------&lt;br /&gt;
# check we have required arguments&lt;br /&gt;
# --------------------------------&lt;br /&gt;
[[ -z $CMMND ]] &amp;amp;&amp;amp; echo &amp;quot;Enter command to be executed like this: $0 -c &amp;#039;ls -al&amp;#039;&amp;quot; &amp;amp;&amp;amp; exit 1&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
# ---------------------------------&lt;br /&gt;
# put the thing to be run in a file&lt;br /&gt;
# ---------------------------------&lt;br /&gt;
printf &amp;quot;%s\n&amp;quot; &amp;quot;$CMMND&amp;quot; &amp;gt; /tmp/dosh.$$&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
# ----------------------------&lt;br /&gt;
# loop over the remote servers&lt;br /&gt;
# ----------------------------&lt;br /&gt;
for server in ${serverlist}&lt;br /&gt;
do&lt;br /&gt;
    if [[ &amp;quot;$VERBOSE&amp;quot; == &amp;quot;Y&amp;quot; ]]; then&lt;br /&gt;
        printf &amp;quot;%s\n&amp;quot; ${server} `date +&amp;#039;%d-%b-%Y %H:%M:%S&amp;#039;`&lt;br /&gt;
        printf &amp;quot;%s\n&amp;quot; &amp;quot;------------------------------------&amp;quot;&lt;br /&gt;
        set -x&lt;br /&gt;
    fi&lt;br /&gt;
    scp -q /tmp/dosh.$$ ${server}:/tmp/&lt;br /&gt;
    if [[ &amp;quot;$BACKGROUND&amp;quot; == &amp;quot;Y&amp;quot; ]]; then&lt;br /&gt;
        ssh -n -o BatchMode=yes ${server} &amp;quot;ksh /tmp/dosh.$$; rm -f /tmp/dosh.$$&amp;quot;&amp;gt; /tmp/dosh_${server}.out 2&amp;gt;&amp;amp;1 &amp;amp;&lt;br /&gt;
    else&lt;br /&gt;
        ssh -n -o BatchMode=yes ${server} &amp;quot;ksh /tmp/dosh.$$; rm -f /tmp/dosh.$$&amp;quot;&lt;br /&gt;
    fi&lt;br /&gt;
    set +x&lt;br /&gt;
    [[ &amp;quot;$VERBOSE&amp;quot; == &amp;quot;Y&amp;quot; ]] &amp;amp;&amp;amp; echo&lt;br /&gt;
done&lt;br /&gt;
rm -f /tmp/dosh.$$&lt;br /&gt;
&lt;br /&gt;
[[ &amp;quot;$BACKGROUND&amp;quot; == &amp;quot;Y&amp;quot; ]] &amp;amp;&amp;amp; printf &amp;quot;%s\n&amp;quot; &amp;quot;Type &amp;#039;ls -altr /tmp/dosh*out&amp;#039; to see output from the commands&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===How can a shell script find out what directory it is in?===&lt;br /&gt;
basename $0 does not always give the desired answer (might give &amp;quot;./&amp;quot;!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
DIR=&amp;quot;$(cd &amp;quot;$(dirname &amp;quot;$0&amp;quot;)&amp;quot; &amp;amp;&amp;amp; pwd)&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Array processing===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
array=(1 2 3)&lt;br /&gt;
unset array[2]&lt;br /&gt;
echo ${array[2]}          # null&lt;br /&gt;
indices=(${!array[@]})    # create an array of the indices of &amp;quot;array&amp;quot;&lt;br /&gt;
size=${#indices[@]}       # the size of &amp;quot;array&amp;quot; is the number of indices into it&lt;br /&gt;
size=${#array[@]}         # same&lt;br /&gt;
echo ${array[@]: -1}      # you can use slices to get array elements, -1 is the last one, etc.&lt;br /&gt;
for element in ${array[@]}; do    # iterate over the array without an index&lt;br /&gt;
&lt;br /&gt;
for index in ${indices[@]}        # iterate over the array WITH an index&lt;br /&gt;
do&lt;br /&gt;
    echo &amp;quot;Index: ${index}, Element: ${array[index]}&amp;quot;&lt;br /&gt;
done&lt;br /&gt;
&lt;br /&gt;
for index in ${!array[@]}         # iterate over the array WITH an index, directly&lt;br /&gt;
&lt;br /&gt;
array+=(&amp;quot;new element&amp;quot;)    # append a new element without referring to an index&lt;br /&gt;
((counter++))             # shorter than ((counter=counter+1)) or ((counter+=1))&lt;br /&gt;
if [[ $var == 3 ]]        # you can use the more &amp;quot;natural&amp;quot; comparison operators inside double square brackets&lt;br /&gt;
while [[ $var &amp;lt; 11 ]]     # another example&lt;br /&gt;
echo ${array[${index}-1]  # math inside an array subscript&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Send an email by talking directly to an smtp server===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
telnet smtp.domain.com 25 &amp;lt;&amp;lt;EOTXT&amp;gt;&amp;gt;/tmp/smtp.log&lt;br /&gt;
HELO me.domain.com&lt;br /&gt;
MAIL FROM:&amp;lt;stuart@domain.com&amp;gt;&lt;br /&gt;
RCPT TO:&amp;lt;anne@domain.com&amp;gt;&lt;br /&gt;
DATA&lt;br /&gt;
From: Stuart &amp;lt;stuart@domain.com&amp;gt;&lt;br /&gt;
To: Anne &amp;lt;anne@domain.com&amp;gt;&lt;br /&gt;
Subject: testing smtp email&lt;br /&gt;
&lt;br /&gt;
Hello, this should appear in the body&lt;br /&gt;
.&lt;br /&gt;
QUIT&lt;br /&gt;
EOTXT&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Send an email by talking directly to an smtp server via file descriptor (no telnet! this time), adding authentication===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
&lt;br /&gt;
#&lt;br /&gt;
# mail.sh&lt;br /&gt;
#&lt;br /&gt;
# 2008 - Mike Golvach - eggi@comcast.net&lt;br /&gt;
# 2010 - Rayber&lt;br /&gt;
#&lt;br /&gt;
# Creative Commons Attribution-Noncommercial-Share Alike 3.0 United States License&lt;br /&gt;
#&lt;br /&gt;
&lt;br /&gt;
if [ $# -ne 7 ]&lt;br /&gt;
then&lt;br /&gt;
echo &amp;quot;Usage: $0 FromAdress ToAdress Domain MailServer MailTextFile AuthEmail AuthPass&amp;quot;&lt;br /&gt;
exit 1&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
from=$1&lt;br /&gt;
to=$2&lt;br /&gt;
domain=$3&lt;br /&gt;
mailserver=$4&lt;br /&gt;
mailtext=$5&lt;br /&gt;
authemail=`echo $6|openssl enc -base64|awk &amp;#039;sub(&amp;quot;..$&amp;quot;, &amp;quot;&amp;quot;)&amp;#039;`&lt;br /&gt;
authpass=`echo $7|openssl enc -base64|awk &amp;#039;sub(&amp;quot;..$&amp;quot;, &amp;quot;&amp;quot;)&amp;#039;`&lt;br /&gt;
&lt;br /&gt;
if [ ! -f $mailtext ]&lt;br /&gt;
then&lt;br /&gt;
echo &amp;quot;Cannot find your mail text file. Exiting...&amp;quot;&lt;br /&gt;
exit 1&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
exec 9&amp;lt;&amp;gt;/dev/tcp/$mailserver/25&lt;br /&gt;
echo &amp;quot;HELO $domain&amp;quot; &amp;gt;&amp;amp;9&lt;br /&gt;
read -r temp &amp;lt;&amp;amp;9&lt;br /&gt;
echo &amp;quot;$temp&amp;quot;&lt;br /&gt;
echo &amp;quot;auth login&amp;quot; &amp;gt;&amp;amp;9&lt;br /&gt;
read -r temp &amp;lt;&amp;amp;9&lt;br /&gt;
echo &amp;quot;$authemail&amp;quot; &amp;gt;&amp;amp;9&lt;br /&gt;
read -r temp &amp;lt;&amp;amp;9&lt;br /&gt;
echo &amp;quot;$authpass&amp;quot; &amp;gt;&amp;amp;9&lt;br /&gt;
read -r temp &amp;lt;&amp;amp;9&lt;br /&gt;
echo &amp;quot;Mail From: $from&amp;quot; &amp;gt;&amp;amp;9&lt;br /&gt;
read -r temp &amp;lt;&amp;amp;9&lt;br /&gt;
echo &amp;quot;$temp&amp;quot;&lt;br /&gt;
echo &amp;quot;Rcpt To: $to&amp;quot; &amp;gt;&amp;amp;9&lt;br /&gt;
read -r temp &amp;lt;&amp;amp;9&lt;br /&gt;
echo &amp;quot;$temp&amp;quot;&lt;br /&gt;
echo &amp;quot;Data&amp;quot; &amp;gt;&amp;amp;9&lt;br /&gt;
read -r temp &amp;lt;&amp;amp;9&lt;br /&gt;
echo &amp;quot;$temp&amp;quot;&lt;br /&gt;
cat $mailtext &amp;gt;&amp;amp;9&lt;br /&gt;
echo &amp;quot;.&amp;quot; &amp;gt;&amp;amp;9&lt;br /&gt;
read -r temp &amp;lt;&amp;amp;9&lt;br /&gt;
echo &amp;quot;$temp&amp;quot;&lt;br /&gt;
echo &amp;quot;quit&amp;quot; &amp;gt;&amp;amp;9&lt;br /&gt;
read -r temp &amp;lt;&amp;amp;9&lt;br /&gt;
echo &amp;quot;$temp&amp;quot;&lt;br /&gt;
9&amp;gt;&amp;amp;-&lt;br /&gt;
9&amp;lt;&amp;amp;-&lt;br /&gt;
echo &amp;quot;All Done Sending Email. See above for errors&amp;quot;&lt;br /&gt;
exit 0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== rsync examples===&lt;br /&gt;
Also see [[Distribute files to multiple servers using rsync and ssh]]&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/sh&lt;br /&gt;
ssh  &amp;lt;remote_host&amp;gt; &amp;#039;/bin/mkdir -p /etc /etc/rc.config.d /etc/security /etc/mail&amp;#039;&lt;br /&gt;
rsync --rsync-path /usr/bin/rsync -Liprogtz --out-format=%f%L  /etc/passwd /etc/passwd.post /etc/group /etc/hosts /etc/services /etc/resolv.conf /etc/exclude.rootvg &amp;lt;remote_host&amp;gt;:/etc&lt;br /&gt;
rsync --rsync-path /usr/bin/rsync -Liprogtz --out-format=%f%L  /etc/hosts.allow.xcat &amp;lt;remote_host&amp;gt;:/etc/hosts.allow&lt;br /&gt;
rsync --rsync-path /usr/bin/rsync -Liprogtz --out-format=%f%L  /etc/rc.config.d/sap &amp;lt;remote_host&amp;gt;:/etc/rc.config.d&lt;br /&gt;
rsync --rsync-path /usr/bin/rsync -Liprogtz --out-format=%f%L  /etc/security/group /etc/security/limits /etc/security/login.cfg /etc/security/passwd /etc/security/user &amp;lt;remote_host&amp;gt;:/etc/security&lt;br /&gt;
rsync --rsync-path /usr/bin/rsync -Liprogtz --out-format=%f%L  /etc/mail/sendmail.cf &amp;lt;remote_host&amp;gt;:/etc/mail&lt;br /&gt;
&lt;br /&gt;
rsync -av --progress /home/ibmtools/scripts/oracle/* benouerp07:/home/ibmtools/scripts/oracle/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Handy aliases===&lt;br /&gt;
Strip out comments and blank lines from a file&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alias strip=&amp;#039;grep -Ev &amp;#039;\&amp;#039;&amp;#039;^(#|$)&amp;#039;\&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Does a ps and a grep&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alias psg=&amp;#039;ps -ef | grep -v $$ | grep -i &amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Getting a decent listing of filesystem space available. It is ordered such that the filesystems with no space left are at the end.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
OS=$(uname -s)&lt;br /&gt;
[[ &amp;quot;$OS&amp;quot; == &amp;quot;SunOS&amp;quot; ]] &amp;amp;&amp;amp; alias dfg=&amp;#039;df -h|sed -e &amp;#039;1d&amp;#039;|sort -n -k5|awk &amp;#039;\&amp;#039;&amp;#039; BEGIN {printf(&amp;quot;%-35s%-10s%-10s%-6s%-30s\n&amp;quot;,&amp;quot;Filesystem&amp;quot;,&amp;quot;Total&amp;quot;,&amp;quot;Free&amp;quot;,&amp;quot;%Used&amp;quot;,&amp;quot;Mounted on&amp;quot;)} {printf(&amp;quot;%-35s%-10s%-10s%-6s%-30s\n&amp;quot;,$1,$2,$4,$5,$6)}&amp;#039;\&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
[[ &amp;quot;$OS&amp;quot; == &amp;quot;AIX&amp;quot; ]]   &amp;amp;&amp;amp; alias dfg=&amp;#039;df -g|sed -e &amp;#039;1d&amp;#039;|sort -n -k4|awk &amp;#039;\&amp;#039;&amp;#039; BEGIN {printf(&amp;quot;%-35s%-10s%-10s%-6s%-30s\n&amp;quot;,&amp;quot;Filesystem&amp;quot;,&amp;quot;Total GB&amp;quot;,&amp;quot;Free&amp;quot;,&amp;quot;%Used&amp;quot;,&amp;quot;Mounted on&amp;quot;)} {printf(&amp;quot;%-35s%-10s%-10s%-6s%-30s\n&amp;quot;,$1,$2,$3,$4,$7)}&amp;#039;\&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
A handy way of listing subdirectories and their files&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alias filetree=&amp;quot;find . -print | sed -e &amp;#039;s;[^/]*/;|____;g;s;____|; |;g&amp;#039;&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Watch progress of a copy&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alias cpProgress=&amp;quot;rsync --progress -ravz&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Reboots Linksys router&amp;lt;pre&amp;gt;&lt;br /&gt;
alias rebootlinksys=&amp;quot;curl -u &amp;#039;admin:password&amp;#039; &amp;#039;http://192.168.1.2/setup.cgi?todo=reboot&amp;#039;&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Nice one for bash. Colour codes the prompt depending on the outcome of the previous command&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
bash_prompt_command()&lt;br /&gt;
{&lt;br /&gt;
    RTN=$?&lt;br /&gt;
    prevCmd=$(prevCmd $RTN)&lt;br /&gt;
}&lt;br /&gt;
PROMPT_COMMAND=bash_prompt_command&lt;br /&gt;
prevCmd()&lt;br /&gt;
{&lt;br /&gt;
    if [ $1 == 0 ] ; then&lt;br /&gt;
        echo $GREEN&lt;br /&gt;
    else&lt;br /&gt;
        echo $RED&lt;br /&gt;
    fi&lt;br /&gt;
}&lt;br /&gt;
if [ $(tput colors) -gt 0 ] ; then&lt;br /&gt;
    RED=$(tput setaf 1)&lt;br /&gt;
    GREEN=$(tput setaf 2)&lt;br /&gt;
    RST=$(tput op)&lt;br /&gt;
fi&lt;br /&gt;
export PS1=&amp;quot;\[\e[36m\]\u.\h.\W\[\e[0m\]\[\$prevCmd\]&amp;gt;\[$RST\]&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Mmmm, to be looked into. Executes remote commands on a unix box using curl.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#/bin/sh&lt;br /&gt;
#&lt;br /&gt;
# WAG320N-HACK&lt;br /&gt;
# Ver. 1.0&lt;br /&gt;
# 12/09/2010&lt;br /&gt;
#&lt;br /&gt;
# This program is free software: you can redistribute it and/or modify&lt;br /&gt;
# it under the terms of the GNU General Public License as published by&lt;br /&gt;
# the Free Software Foundation, either version 3 of the License, or&lt;br /&gt;
# (at your option) any later version.&lt;br /&gt;
#&lt;br /&gt;
# This program is distributed in the hope that it will be useful,&lt;br /&gt;
# but WITHOUT ANY WARRANTY; without even the implied warranty of&lt;br /&gt;
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the&lt;br /&gt;
# GNU General Public License for more details.&lt;br /&gt;
#&lt;br /&gt;
# You should have received a copy of the GNU General Public License&lt;br /&gt;
# along with this program.  If not, see &amp;lt;http://www.gnu.org/licenses/&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
# Set username and password in the form of &amp;quot;username:password&amp;quot;&lt;br /&gt;
# example: &amp;quot;admin:admin&amp;quot;&lt;br /&gt;
my_access=&amp;quot;admin:admin&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Parameters test&lt;br /&gt;
if [ -z &amp;quot;$1&amp;quot; ]&lt;br /&gt;
then&lt;br /&gt;
  echo &amp;quot;wag320n-hack.sh: missing remote command&amp;quot;&lt;br /&gt;
  echo &amp;quot;usage: wag320n-hack.sh &amp;lt;remote command&amp;gt;&amp;quot;&lt;br /&gt;
  echo &amp;quot;example: wag320n-hack.sh /bin/ls -la /usr/sbin&amp;quot;&lt;br /&gt;
  echo &amp;quot;Note: always use full path&amp;quot;&lt;br /&gt;
  echo &amp;quot;&amp;quot;&lt;br /&gt;
  echo &amp;quot;wag320n-hack.sh - Ver. 1.0 - 12/09/2010&amp;quot;&lt;br /&gt;
  echo &amp;quot;Licensed under GPL V. 3&amp;quot;&lt;br /&gt;
  echo &amp;quot;&amp;quot;&lt;br /&gt;
  exit 0&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
# Get the command&lt;br /&gt;
my_command=&amp;quot;ping_size=&amp;quot;&amp;#039;$(&amp;#039;&amp;quot;$@&amp;quot;&amp;#039; 1&amp;gt;&amp;amp;2)&amp;#039;&lt;br /&gt;
&lt;br /&gt;
curl -s -G -u &amp;quot;$my_access&amp;quot; --data-urlencode &amp;#039;todo=ping_test&amp;#039; --data-urlencode &amp;#039;this_file=Diagnostics.htm&amp;#039; --data-urlencode &amp;#039;next_file=Ping.htm&amp;#039; --data-urlencode &amp;#039;c4_ping_ipaddr=192.168.1.1&amp;#039; --data-urlencode &amp;#039;ping_timeout=5000&amp;#039; --data-urlencode &amp;#039;ping_interval=1000&amp;#039; --data-urlencode &amp;#039;ping_number=1&amp;#039; --data-urlencode &amp;quot;$my_command&amp;quot; http://192.168.1.1/setup.cgi | sed -e &amp;#039;/HTTP\/1.0 200 OK/q&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===How to configure SSH with public/private keys===&lt;br /&gt;
* [http://www.unixpeople.com/HOWTO/configuring.ssh.html unixpeople.com]&lt;br /&gt;
===Use SSH config file===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Host server10&lt;br /&gt;
  Hostname 1.2.3.4&lt;br /&gt;
  IdentityFile ~/.ssh/id_dsa&lt;br /&gt;
  user foobar&lt;br /&gt;
  Port 30000&lt;br /&gt;
  ForwardX11Trusted yes&lt;br /&gt;
  TCPKeepAlive yes&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
then just connect using&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ssh server10&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===A decent sed tutorial===&lt;br /&gt;
From [http://www.grymoire.com/Unix/Sed.html grymoire.com]&lt;br /&gt;
===A decent korn/bash shell tutorial===&lt;br /&gt;
From [http://www.dartmouth.edu/~rc/classes/ksh/print_pages.shtml dartmouth.edu]&lt;br /&gt;
Reproduced here just in case it disappears!&lt;br /&gt;
[[Advanced shell scripting]]&lt;br /&gt;
&lt;br /&gt;
===trap===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
     Example Handling Traps With ksh - Discussion of the kill command&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
EXAMPLE TEMPLATE:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
PRODUCT:    HP-UX 11iV1 Version B.11.11&lt;br /&gt;
            HP Tru64 V5.1B PK4&lt;br /&gt;
            Sun/Solaris SunOS V5.8&lt;br /&gt;
            Linux 2.6 kernel&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
COMPONENT:  ksh&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
SOURCE:     Philippe Vouters&lt;br /&gt;
            Fontainebleau/France&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
LOW COST HIGH-TECH PRODUCTS:  http://techno-star.fr&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
OVERVIEW:&lt;br /&gt;
&lt;br /&gt;
The ksh script below shows how to eventually handle traps in the situation &lt;br /&gt;
where someone might try to kill a script by killing individual commands run &lt;br /&gt;
by that script or the entire process group a script is running in. The kill &lt;br /&gt;
command (usually a shell builtin) may be used to send a signal to a process &lt;br /&gt;
group (with the -&amp;lt;pid&amp;gt; syntax) or an individual process. The example ksh &lt;br /&gt;
script below runs /bin/sleep as the foreground process, the example ksh &lt;br /&gt;
scripts immediately returns when the /bin/sleep process has terminated. Most &lt;br /&gt;
signals sent to the shell are ignored until after the foreground process &lt;br /&gt;
terminates. This is in order to avoid creating zombie processes. Therefore a &lt;br /&gt;
kill &amp;lt;pid&amp;gt; on the example ksh script waits for the termination of the &lt;br /&gt;
/bin/sleep process.&lt;br /&gt;
&lt;br /&gt;
The status value $? in the trap refers to the exit status of the command to run &lt;br /&gt;
and therefore is the exit status of the /bin/sleep process. The called function &lt;br /&gt;
in the trap handler shows how to correctly examine the effect of the kill &lt;br /&gt;
command on the shell or it&amp;#039;s children.&lt;br /&gt;
&lt;br /&gt;
To examine the value of $? in a trap handler means that you must understand what&lt;br /&gt;
it can be set and how different signals delivered to either the shell or the &lt;br /&gt;
foreground process (or the process group) might affect the value of $?.&lt;br /&gt;
&lt;br /&gt;
The example shell script prints $? using echo but it does not perform tests on &lt;br /&gt;
the value of $?. For a complete solution when attempting to trap signals in a &lt;br /&gt;
shell you would also need code that examined the value of $? after the &lt;br /&gt;
foreground process had completed.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*** CAUTION ***&lt;br /&gt;
&lt;br /&gt;
This sample script has been tested using HP-UX B.11.11, HP Tru64 V5.1B PK4, &lt;br /&gt;
SunOS V5.8 and Fedora Core 4 (homed version of Red Hat Linux).  However, we&lt;br /&gt;
cannot guarantee its effectiveness because of the possibility of error in &lt;br /&gt;
transmitting or implementing it. It is meant to be used as a template for &lt;br /&gt;
writing your own scripts, and may require modification for use on your system. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
SCRIPT NOTES:&lt;br /&gt;
&lt;br /&gt;
To notice that the ksh script and /bin/sleep share the same process group&lt;br /&gt;
identifier (PGID), issue the following commands:&lt;br /&gt;
&lt;br /&gt;
[philippe@victor ~]$ who&lt;br /&gt;
philippe :0           Jan 10 10:16&lt;br /&gt;
philippe pts/1        Jan 10 21:30 (:0.0)&lt;br /&gt;
philippe pts/2        Jan 10 21:30 (:0.0)&lt;br /&gt;
[philippe@victor ~]$ tty&lt;br /&gt;
/dev/pts/1&lt;br /&gt;
[philippe@victor ~]$ ps -j -t pts/2&lt;br /&gt;
  PID  PGID   SID TTY          TIME CMD&lt;br /&gt;
11072 11072 11072 pts/2    00:00:00 bash&lt;br /&gt;
11113 11113 11072 pts/2    00:00:00 ksh&lt;br /&gt;
11116 11113 11072 pts/2    00:00:00 sleep&lt;br /&gt;
&lt;br /&gt;
In this case sending kill -INT -11113 will send SIGINT to the process group &lt;br /&gt;
11113. Both of the ksh and sleep processes are contained within this process &lt;br /&gt;
group.&lt;br /&gt;
&lt;br /&gt;
Important Note:&lt;br /&gt;
&lt;br /&gt;
On HP-UX, you have to $ export UNIX95=1 in order to be able to use the&lt;br /&gt;
-j option of the ps command.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
SCRIPT:&lt;br /&gt;
&lt;br /&gt;
                             COPYRIGHT (C) 2005 BY&lt;br /&gt;
                              HEWLETT-PACKARD COMPANY&lt;br /&gt;
                                ALL RIGHTS RESERVED.&lt;br /&gt;
&lt;br /&gt;
     THIS SOFTWARE IS FURNISHED UNDER A LICENSE AND MAY BE USED AND COPIED&lt;br /&gt;
     ONLY IN ACCORDANCE WITH THE TERMS OF SUCH LICENSE AND WITH THE INCLUSION&lt;br /&gt;
     OF THE ABOVE COPYRIGHT NOTICE.  THIS SOFTWARE OR ANY OTHER COPIES&lt;br /&gt;
     THEREOF MAY NOT BE PROVIDED OR OTHERWISE MADE AVAILABLE TO ANY OTHER&lt;br /&gt;
     PERSON.  NO TITLE TO AND OWNERSHIP OF THE SOFTWARE IS HEREBY TRANSFERRED.&lt;br /&gt;
&lt;br /&gt;
     THE INFORMATION IN THIS SOFTWARE IS SUBJECT TO CHANGE WITHOUT NOTICE AND&lt;br /&gt;
     SHOULD NOT BE CONSTRUED AS A COMMITMENT BY HEWLETT-PACKARD COMPANY.&lt;br /&gt;
&lt;br /&gt;
     HP ASSUMES NO RESPONSIBILITY FOR THE USE OR RELIABILITY OF ITS&lt;br /&gt;
     SOFTWARE ON EQUIPMENT THAT IS NOT SUPPLIED BY HP.&lt;br /&gt;
&lt;br /&gt;
     NO RESPONSIBILITY IS ASSUMED FOR THE USE OR RELIABILITY OF SOFTWARE&lt;br /&gt;
     ON EQUIPMENT THAT IS NOT SUPPLIED BY HEWLETT-PACKARD COMPANY.&lt;br /&gt;
&lt;br /&gt;
     SUPPORT FOR THIS SOFTWARE IS NOT COVERED UNDER ANY HP SOFTWARE&lt;br /&gt;
     PRODUCT SUPPORT CONTRACT, BUT MAY BE PROVIDED UNDER THE TERMS OF THE&lt;br /&gt;
     CONSULTING AGREEMENT UNDER WHICH THIS SOFTWARE WAS DEVELOPED.&lt;br /&gt;
&lt;br /&gt;
#!/bin/ksh&lt;br /&gt;
function handle_signal&lt;br /&gt;
{&lt;br /&gt;
        print -n &amp;quot;pid $$ recieved $2 &amp;quot;&lt;br /&gt;
        if [[ $1 = 0 ]];then&lt;br /&gt;
            print but foreground command ended successfully&lt;br /&gt;
        else&lt;br /&gt;
                if [[ $1 = $3 ]];then&lt;br /&gt;
                    print and so did the last foreground command&lt;br /&gt;
                else&lt;br /&gt;
                    print -n &amp;quot;and the exit status of the last foreground &amp;quot;&lt;br /&gt;
                    print command was $1&lt;br /&gt;
                fi&lt;br /&gt;
        fi&lt;br /&gt;
        # Kill our process group and then ourselves with SIGTERM, giving a &lt;br /&gt;
        # pid of 0 sends the signal to our process group. Killing the process&lt;br /&gt;
        # group should kill us as well, this assumes that SIGTERM is not &lt;br /&gt;
        # handled by any process in the process group.&lt;br /&gt;
        #&lt;br /&gt;
        # This code could be replaced with an exit with an exit value that&lt;br /&gt;
        # would indicate what the problem was to the caller. That is replace &lt;br /&gt;
        # these two lines with:&lt;br /&gt;
        #&lt;br /&gt;
        # exit $3&lt;br /&gt;
        #&lt;br /&gt;
        # or a specific exit code could be used.&lt;br /&gt;
        #&lt;br /&gt;
        kill -TERM 0&lt;br /&gt;
        kill -TERM $$&lt;br /&gt;
        }&lt;br /&gt;
OS=$(uname -a | awk &amp;#039;{print $1}&amp;#039;)&lt;br /&gt;
if [[ &amp;quot;$OS&amp;quot; = &amp;quot;Linux&amp;quot; ]]; then&lt;br /&gt;
    offset=256&lt;br /&gt;
elif [[ (&amp;quot;$OS&amp;quot; = &amp;quot;HP-UX&amp;quot;) || &lt;br /&gt;
        (&amp;quot;$OS&amp;quot; = &amp;quot;SunOS&amp;quot;) || &lt;br /&gt;
        (&amp;quot;$OS&amp;quot; = &amp;quot;OSF1&amp;quot;) ]]; then&lt;br /&gt;
   offset=128&lt;br /&gt;
fi&lt;br /&gt;
trap &amp;#039;RC=$?; handle_signal $RC SIGINT $offset+2&amp;#039; INT&lt;br /&gt;
trap &amp;#039;RC=$?; handle_signal $RC SIGQUIT $offset+3&amp;#039; QUIT&lt;br /&gt;
/bin/sleep 20&lt;br /&gt;
echo $?&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===DNS not working===&lt;br /&gt;
Ping to an IP address works&lt;br /&gt;
 ping 74.125.136.103&lt;br /&gt;
but this doesn&amp;#039;t&lt;br /&gt;
 ping www.google.com&lt;br /&gt;
&lt;br /&gt;
Check resolv.conf&lt;br /&gt;
 cat /etc/resolv.conf&lt;br /&gt;
 nameserver 95.130.132.17&lt;br /&gt;
 nameserver 95.130.132.18&lt;br /&gt;
I had changed internet provider and forgot to update this. Just to set it to the router address and let that do the resolution&lt;br /&gt;
 nameserver 192.168.1.1&lt;br /&gt;
&lt;br /&gt;
===File descriptors===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
exec 3&amp;lt;&amp;gt; /tmp/foo  #open fd 3 for r/w&lt;br /&gt;
echo &amp;quot;test&amp;quot; &amp;gt;&amp;amp;3&lt;br /&gt;
exec 3&amp;gt;&amp;amp;- #close fd 3.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
exec 3&amp;lt;&amp;gt; myfile.txt&lt;br /&gt;
while read line &amp;lt;&amp;amp;3&lt;br /&gt;
do {&lt;br /&gt;
  echo &amp;quot;$line&amp;quot;&lt;br /&gt;
  (( Lines++ ));                   #  Incremented values of this variable&lt;br /&gt;
                                   #+ accessible outside loop.&lt;br /&gt;
                                   #  No subshell, no problem.&lt;br /&gt;
}&lt;br /&gt;
done&lt;br /&gt;
exec 3&amp;gt;&amp;amp;-&lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;Number of lines read = $Lines&amp;quot;     # 8&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Mmm. See our output and also tee it to a log file!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
&lt;br /&gt;
echo hello&lt;br /&gt;
&lt;br /&gt;
if test -t 1; then&lt;br /&gt;
    # Stdout is a terminal.&lt;br /&gt;
    exec &amp;gt;log&lt;br /&gt;
else&lt;br /&gt;
    # Stdout is not a terminal.&lt;br /&gt;
    npipe=/tmp/$$.tmp&lt;br /&gt;
    trap &amp;quot;rm -f $npipe&amp;quot; EXIT&lt;br /&gt;
    mknod $npipe p&lt;br /&gt;
    tee &amp;lt;$npipe log &amp;amp;&lt;br /&gt;
    exec 1&amp;gt;&amp;amp;-&lt;br /&gt;
    exec 1&amp;gt;$npipe&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
echo goodbye&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Create new image with kvm===&lt;br /&gt;
Ref: http://www.cyberciti.biz/faq/kvm-virtualization-in-redhat-centos-scientific-linux-6/&amp;lt;br /&amp;gt;&lt;br /&gt;
Build an empty space for a CentOS virtual machine&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
qemu-img create -f qcow2 centos.img 12G&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Tried creating image with&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo virt-install -n CentOS --description &amp;quot;Trying out CentOS&amp;quot; --ram=1024 --vcpus=1 --cpu host --hvm --cdrom /home/bey9at77/Downloads/c6-x86_64-20130910-1.qcow2 --graphics vnc --disk path=/var/lib/libvirt/images/centos.img,bus=virtio,size=10&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
gives error&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Starting install...&lt;br /&gt;
Allocating &amp;#039;centos.img&amp;#039;                                                                                                                                                                                               |  10 GB     00:00     &lt;br /&gt;
ERROR    internal error Process exited while reading console log output: char device redirected to /dev/pts/1&lt;br /&gt;
qemu-kvm: -drive file=/home/bey9at77/Downloads/c6-x86_64-20130910-1.qcow2.bz2,if=none,media=cdrom,id=drive-ide0-1-0,readonly=on,format=raw: could not open disk image /home/bey9at77/Downloads/c6-x86_64-20130910-1.qcow2: Permission denied&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===rpm / yum commands===&lt;br /&gt;
====Install an RPM Package====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rpm -ivh pidgin-2.7.9-5.el6.2.i686.rpm&lt;br /&gt;
&lt;br /&gt;
-i - install&lt;br /&gt;
-v - verbose&lt;br /&gt;
-h - print progress hashes&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Check dependencies of RPM Package before Installing====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rpm -qpR BitTorrent-5.2.2-1-Python2.4.noarch.rpm&lt;br /&gt;
&lt;br /&gt;
-q - query&lt;br /&gt;
-p - list package capabilities&lt;br /&gt;
-R - list dependent package capabilities&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Install RPM Package with all dependencies====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
yum install BitTorrent-5.2.2-1-Python2.4.noarch.rpm&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Install RPM Package with all dependencies (when RPM has been downloaded to local machine)====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
yum localinstall BitTorrent-5.2.2-1-Python2.4.noarch.rpm&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Force Install a RPM Package without dependencies====&lt;br /&gt;
Package will not work if dependencies are required&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rpm -ivh --nodeps BitTorrent-5.2.2-1-Python2.4.noarch.rpm&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Check an Installed RPM Package====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rpm -q BitTorrent&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====List all files of an installed RPM package====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rpm -ql BitTorrent&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====List All Installed RPM Packages====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rpm -qa&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Query information about an installed RPM package====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rpm -qi vsftpd&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Query information about a not yet installed RPM package====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rpm -qip sqlbuddy-1.3.3-1.noarch.rpm&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====(Forcibly) Remove an RPM Package====&lt;br /&gt;
Use package name (as seen in -qi above), not full name&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rpm -ev (--nodeps) vsftpd&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Query a file that was installed as part of an RPM Package (which package contained this file)====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rpm -qf /usr/bin/htpasswd&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Verify an RPM package====&lt;br /&gt;
Compares information of installed files of the package against the rpm database&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rpm -Vp sqlbuddy-1.3.3-1.noarch.rpm&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Rebuild corrupted RPM database====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cd /var/lib&lt;br /&gt;
rm __db*&lt;br /&gt;
rpm --rebuilddb&lt;br /&gt;
rpmdb_verify Packages&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Install rpmforge repository===&lt;br /&gt;
* Download rpmforge-release-0.5.3-1.el6.rf.x86_64.rpm&lt;br /&gt;
* Import the key&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo rpm --import http://apt.sw.be/RPM-GPG-KEY.dag.txt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Install the repository&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo rpm -i rpmforge-release-0.5.3-1.el6.rf.x86_64.rpm&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Check the installation&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rpm -K rpmforge-release-0.5.3-1.el6.rf.x86_64.rpm&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Test it&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo yum install terminator&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Install rpmfusion repository===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
su -c &amp;#039;yum localinstall --nogpgcheck http://download1.rpmfusion.org/free/el/updates/6/i386/rpmfusion-free-release-6-1.noarch.rpm http://download1.rpmfusion.org/nonfree/el/updates/6/i386/rpmfusion-nonfree-release-6-1.noarch.rpm&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===config file for yum===&lt;br /&gt;
Checkout this file for global yum config&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/etc/sysconfig/yum-cron-background&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Setup Oracle Enterprise Linux (RedHat) with yum server===&lt;br /&gt;
You need to download the yum .repo file from the server, as per the steps below. After this, you need to enable a flag in the .repo file as per your operating system version. Having done these two steps, when you run yum install &amp;lt;pkgname&amp;gt; command on your linux box, the Oracle&amp;#039;s yum server will be scanned, the dependent &amp;amp; the relevant rpm&amp;#039;s will be download and installed for you.&amp;lt;br /&amp;gt;&lt;br /&gt;
 cd /etc/yum.repos.d&lt;br /&gt;
To download files here&lt;br /&gt;
 wget http://public-yum.oracle.com/public-yum-el5.repo&lt;br /&gt;
&lt;br /&gt;
A file named public-yum-el5.repo will be created in your directory&amp;lt;br /&amp;gt;&lt;br /&gt;
Edit this file and enter enabled=1 against the operating systems which is relevant to you&lt;br /&gt;
 vi public-yum-el5.repo&lt;br /&gt;
&lt;br /&gt;
Next run the yum command&lt;br /&gt;
 yum install package-name&lt;br /&gt;
&lt;br /&gt;
===To change to static IP address (Raspberry Pi)===&lt;br /&gt;
As root:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cd /etc/networks&lt;br /&gt;
vi interfaces&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
replace the line “iface eth0 inet dhcp” with&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
iface eth0 inet static&lt;br /&gt;
address 192.168.1.100&lt;br /&gt;
netmask 255.255.255.0&lt;br /&gt;
gateway 192.168.1.1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You should also take a look at the file /etc/resolv.conf and check it has a nameserver entry (probably pointing at your default gateway) or direct to your ISP name servers.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
nameserver 192.168.1.1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Troubleshoot wireless network problems===&lt;br /&gt;
* [https://www.blackmoreops.com/2014/09/18/connect-to-wifi-network-from-command-line-in-linux/ connect to wifi network from command-line in linux - from blackmoreops.com]&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Short summary of all the things you need to do in just few lines&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
root@kali:~# iw dev&lt;br /&gt;
root@kali:~# ip link set wlan0 up&lt;br /&gt;
root@kali:~# iw wlan0 scan&lt;br /&gt;
root@kali:~# wpa_passphrase blackMOREOps &amp;gt;&amp;gt; /etc/wpa_supplicant.conf&lt;br /&gt;
root@kali:~# wpa_supplicant -i wlan0 -c /etc/wpa_supplicant.conf&lt;br /&gt;
root@kali:~# iw wlan0 link&lt;br /&gt;
root@kali:~# dhclient wlan0&lt;br /&gt;
root@kali:~# ping 8.8.8.8&lt;br /&gt;
(Where wlan0 is wifi adapter and blackMOREOps is SSID)&lt;br /&gt;
(Add Routing manually)&lt;br /&gt;
root@kali:~# ip route add default via 10.0.0.138 dev wlan0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===To change to static IP address (Redhat/CentOS)===&lt;br /&gt;
As root:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
vi /etc/sysconfig/network-scripts/ifcfg-eth0&lt;br /&gt;
DEVICE=eth0&lt;br /&gt;
BOOTPROTO=STATIC&lt;br /&gt;
IPADDR=192.168.1.111&lt;br /&gt;
NETMASK=255.255.255.0&lt;br /&gt;
GATEWAY=192.168.1.1&lt;br /&gt;
ONBOOT=yes&lt;br /&gt;
DNS1=8.8.8.8&lt;br /&gt;
DNS2=8.8.4.4&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Resrart the network interface&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/etc/init.d/network stop&lt;br /&gt;
/etc/init.d/network start&lt;br /&gt;
or&lt;br /&gt;
service network restart&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Check name server entry in resolv.conf&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
vi /etc/resolv.conf&lt;br /&gt;
nameserver 192.168.1.1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Enable processes / services to start at boot time===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo chkconfig httpd on&lt;br /&gt;
sudo chkconfig mysqld on&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Run a command on lots of servers in parallel===&lt;br /&gt;
This is a damn fine AIX utility - part of the CSM Distributed Shell.&lt;br /&gt;
 dsh -a &amp;quot;ls -al /etc/apache2/*conf&amp;quot;&lt;br /&gt;
will list the Apache configuration file on all reachable servers (nodes)&lt;br /&gt;
===Download a gzip file and pipe it into tar===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cd ~ &amp;amp;&amp;amp; wget -O - &amp;quot;https://www.dropbox.com/download?plat=lnx.x86_64&amp;quot; | tar xzf -&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Check in a script to make sure it is run only by root===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
RUID=`/usr/bin/id|$AWK -F\( &amp;#039;{print $1}&amp;#039;|$AWK -F\= &amp;#039;{print $2}&amp;#039;`&lt;br /&gt;
if [ ${RUID} != &amp;quot;0&amp;quot; ];then&lt;br /&gt;
   $ECHO &amp;quot;This script must be executed as root&amp;quot;&lt;br /&gt;
   exit 1&lt;br /&gt;
fi&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Set terminal to use Backspace key to erase previous character instead of Control-H===&lt;br /&gt;
Been looking for this for a long time.&amp;lt;br /&amp;gt;&lt;br /&gt;
You can put:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
stty erase &amp;lt;CTRL-V&amp;gt;&amp;lt;Backspace key&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
in your .profile but this will be ruined if you do a copy/paste into another file.&amp;lt;br /&amp;gt;&lt;br /&gt;
I wanted a way of doing this without entering the control character in the .profile. Finally stumbled upon it. And it&amp;#039;s so simple. Just escape the caret!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
stty erase \^?&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Put this in the .profile. It&amp;#039;s copy/pastable and it works!&amp;lt;br /&amp;gt;&lt;br /&gt;
If you want CTRL-H to be your erase character, just do this:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
stty erase \^H&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Play with the terminal settings and reset them again either side of requesting a password===&lt;br /&gt;
The -g option of stty gives a compact list of all the settings or the terminal and can be used as input to stty&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
OLDCONFIG=`stty -g`          # save terminal configuration&lt;br /&gt;
stty -echo                   # turn character echoing off&lt;br /&gt;
echo &amp;quot;Enter password: \c&amp;quot;&lt;br /&gt;
read PASSWD                  # get the password&lt;br /&gt;
stty $OLDCONFIG              # restore terminal configuration&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Reset terminal to &amp;quot;sane&amp;quot; characteristics===&lt;br /&gt;
If you&amp;#039;ve done a cat of a binary file or something else weird and your terminal is left in a mess, the following key sequence should bring it back to normal&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;CTRL-J&amp;gt;stty sane&amp;lt;CTRL-J&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Install OpenOffice on RedHat Enterprise when yum install doesn&amp;#039;t!===&lt;br /&gt;
Download Package&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
wget http://sourceforge.net/projects/openofficeorg.mirror/files/4.0.1/binaries/en-US/Apache_OpenOffice_4.0.1_Linux_x86-64_install-rpm_en-US.tar.gz/download -O Apache_OpenOffice_4.0.1_Linux_x86-64_install-rpm_en-US.tar.gz&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Change to root&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo su -&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Remove the old stuff&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
yum remove openoffice* libreoffice*&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Extract Package&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
tar -xvf Apache_OpenOffice_4.0.1*&lt;br /&gt;
cd en-US&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Install Package and exit root&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rpm -Uvh RPMS/*.rpm RPMS/desktop-integration/openoffice4.0-redhat-*.rpm&lt;br /&gt;
exit&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Start it&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
openoffice4&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===What does this do?===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
while IFS= read -r line; do&lt;br /&gt;
    echo &amp;quot;[$(date &amp;quot;+%F %T&amp;quot;)] - $line&amp;quot;&lt;br /&gt;
done &amp;lt; &amp;lt;(iwevent)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
while IFS= read -r line; do&lt;br /&gt;
    printf &amp;quot;%s\n%s\n&amp;quot; &amp;quot;$line&amp;quot; &amp;quot;Yohooo! One more package.&amp;quot;&lt;br /&gt;
done &amp;lt; &amp;lt;(tcpdump -i any -nS)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===List of Special Characters and what they mean===&lt;br /&gt;
From [http://www.grymoire.com/Unix/Quote.html Bruce Barnett]&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Character	Where	Meaning&lt;br /&gt;
&amp;lt;RETURN&amp;gt;	csh, sh	Execute command&lt;br /&gt;
#	csh, sh, ASCII files	Start a comment&lt;br /&gt;
&amp;lt;SPACE&amp;gt;	csh, sh	Argument separator&lt;br /&gt;
`	csh, sh	Command substitution&lt;br /&gt;
&amp;quot;	csh, sh	Weak Quotes&lt;br /&gt;
&amp;#039;	csh, sh	Strong Quotes&lt;br /&gt;
\	csh, sh	Single Character Quote&lt;br /&gt;
variable	sh, csh	Variable&lt;br /&gt;
variable	csh, sh	Same as variable&lt;br /&gt;
|	csh, sh	Pipe character&lt;br /&gt;
^	sh	Pipe Character&lt;br /&gt;
&amp;amp;	csh, sh	Run program in background&lt;br /&gt;
?	csh, sh	Match one character&lt;br /&gt;
*	csh, sh	Match any number of characters&lt;br /&gt;
;	csh, sh	Command separator&lt;br /&gt;
;;	sh	End of Case statement&lt;br /&gt;
~	csh	Home Directory&lt;br /&gt;
~user	csh	User&amp;#039;s Home Directory&lt;br /&gt;
!	csh	History of Commands&lt;br /&gt;
-	Programs	Start of optional argument&lt;br /&gt;
$#	csh, sh	Number of arguments to script&lt;br /&gt;
$*	csh, sh	Arguments to script&lt;br /&gt;
$@	sh	Original arguments to script&lt;br /&gt;
$-	sh	Flags passed to shell&lt;br /&gt;
$?	sh	Status of previous command&lt;br /&gt;
$$	sh	Process identification number&lt;br /&gt;
$!	sh	PID of last background job&lt;br /&gt;
&amp;amp;&amp;amp;	sh	Short-circuit AND&lt;br /&gt;
||	sh	Short-circuit OR&lt;br /&gt;
.	csh, sh	Typ. filename extension&lt;br /&gt;
.	sh	Source a file and execute as command&lt;br /&gt;
:	sh	Nothing command&lt;br /&gt;
:	sh	Separates Values in environment variables&lt;br /&gt;
:	csh	Variable modifier&lt;br /&gt;
Character	Where	Meaning&lt;br /&gt;
[ ]	csh, sh	Match range of characters&lt;br /&gt;
[ ]	sh	Test&lt;br /&gt;
%job	csh	Identifies job Number&lt;br /&gt;
(cmd;cmd)	csh. sh	Runs cmd;cmd as a sub-shell&lt;br /&gt;
{ }	csh	In-line expansions&lt;br /&gt;
{cmd;cmd }	sh	Like (cmd;cmd ) without a subshell&lt;br /&gt;
&amp;gt;ofile	csh, sh	Standard output&lt;br /&gt;
&amp;gt;&amp;gt;ofile	csh, sh	Append to standard output&lt;br /&gt;
&amp;lt;ifile	csh, sh	Standard Input&lt;br /&gt;
&amp;lt;&amp;lt;word	csh, sh	Read until word, substitute variables&lt;br /&gt;
&amp;lt;&amp;lt;\word	csh, sh	Read until word, no substitution&lt;br /&gt;
&amp;lt;&amp;lt;-word	sh	Read until word, ignoring TABS&lt;br /&gt;
&amp;gt;&amp;gt;!file	csh	Append to file, ignore error if not there&lt;br /&gt;
&amp;gt;!file	csh	Output to new file, ignore error if not there&lt;br /&gt;
&amp;gt;&amp;amp;file	csh	Send standard &amp;amp; error output to file&lt;br /&gt;
&amp;lt;&amp;amp;digit	sh	Switch Standard Input to file&lt;br /&gt;
&amp;lt;&amp;amp;-	sh	Close Standard Input&lt;br /&gt;
&amp;gt;&amp;amp;digit	sh	Switch Standard Output to file&lt;br /&gt;
&amp;gt;&amp;amp;-	sh	Close Standard Output&lt;br /&gt;
digit1&amp;lt;&amp;amp;digit2	sh	Connect digit2 to digit1&lt;br /&gt;
digit&amp;lt;&amp;amp;-	sh	Close file digit&lt;br /&gt;
digit2&amp;gt;&amp;amp;digit1	sh	Connect digit2 to digit1&lt;br /&gt;
digit&amp;gt;&amp;amp;-	sh	Close file digit&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Stuart</name></author>	</entry>

	<entry>
		<id>https://mailnest.com/dbawiki/index.php?title=Unix/Linux&amp;diff=3399</id>
		<title>Unix/Linux</title>
		<link rel="alternate" type="text/html" href="https://mailnest.com/dbawiki/index.php?title=Unix/Linux&amp;diff=3399"/>
				<updated>2018-12-06T00:11:29Z</updated>
		
		<summary type="html">&lt;p&gt;Stuart: /* uudeview */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;* [http://hyperpolyglot.org/unix-shells#var-expansion Good shell comparison including variable expansion - hyperpolyglot.org]&lt;br /&gt;
* [http://pubs.opengroup.org/onlinepubs/9699919799/utilities/toc.html Shell coding standards - opengroup.org]&lt;br /&gt;
* [http://aix4admins.blogspot.be aix4admins]&lt;br /&gt;
* [http://linuxgazette.net/issue55/okopnik.html The Deep, Dark Secrets of Bash]&lt;br /&gt;
* [http://www.speakeasy.org/~arkay/216-7.4KshFunctions.html Korn Shell Functions]&lt;br /&gt;
* [http://www.grymoire.com/Unix/AwkRef.html AWK reference from Bruce Barnett]&lt;br /&gt;
* [http://www.catonmat.net/blog/wp-content/uploads/2008/09/awk1line.txt HANDY AWK ONE-LINERS]&lt;br /&gt;
* [http://www.grymoire.com/unix/Quote.html Unix quoting from from Bruce Barnett (grymoire)]&lt;br /&gt;
* [http://www.mpi-inf.mpg.de/departments/rg1/teaching/unixffb-ss98/quoting-guide.html Another excellent quoting tutorial]&lt;br /&gt;
* [http://aix4admins.blogspot.be/2015/02/snapshot-fs-snapshot-snapshot-is-state.html AIX snapshot technology]&lt;br /&gt;
* [[RaspberryPi]]&lt;br /&gt;
* [[SSH]]&lt;br /&gt;
* [http://www.anattatechnologies.com/q/2013/04/multiuser-screen/ Screen sharing from Unix using screen]&lt;br /&gt;
* [https://robots.thoughtbot.com/a-tmux-crash-course Screen sharing from Unix using tmux]&lt;br /&gt;
* [http://www.csb.yale.edu/userguides/wordprocess/vi-summary.html Handy ex and vi reference]&lt;br /&gt;
* [[Fedora install for my own purposes]]&lt;br /&gt;
&lt;br /&gt;
===How to automatically download and process email attachments from Gmail===&lt;br /&gt;
==== Useful references====&lt;br /&gt;
* [http://www.courier-mta.org/maildrop/maildrop.html maildrop]&lt;br /&gt;
* [http://www.wonkity.com/~wblock/docs/html/maildrop.html Using maildrop As A Mail Delivery Agent (MDA)]&lt;br /&gt;
* [http://manpages.ubuntu.com/manpages/trusty/man7/maildropex.7.html .mailfilter examples]&lt;br /&gt;
* [https://www.axllent.org/docs/view/gmail-pop3-with-fetchmail/ Setting up fetchmail with Gmail]&lt;br /&gt;
* [https://www.linode.com/docs/email/clients/using-fetchmail-to-retrieve-email/ Using Fetchmail to Retrieve Email]&lt;br /&gt;
&lt;br /&gt;
Eventually, after months of trying different things, came up with this combination of tools that worked very well.&lt;br /&gt;
====Install tools====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo dnf -y install fetchmail maildrop uudeview openssl&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Set Gmail account up for POP and disable IMAP&lt;br /&gt;
====Configure fetchmail====&lt;br /&gt;
This is the part that talks to Gmail and downloads the emails to the local machine.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
vi ~/.fetchmailrc&lt;br /&gt;
&lt;br /&gt;
set postmaster &amp;quot;&amp;lt;username&amp;gt;&amp;quot;&lt;br /&gt;
#set daemon 600&lt;br /&gt;
poll pop.gmail.com with proto POP3&lt;br /&gt;
    user &amp;quot;account@gmail.com&amp;quot; there with password &amp;#039;&amp;lt;password&amp;gt;&amp;#039; is &amp;lt;username&amp;gt; here options ssl nokeep&lt;br /&gt;
    mda &amp;quot;/usr/bin/maildrop .mailfilter&amp;quot;&lt;br /&gt;
#    sslcertfile /etc/ssl/certs/ca-bundle.crt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
If fetchmail complains about ssl certificates, try specifying wherein is with the sslcertfile line&lt;br /&gt;
==== Configure maildrop====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
vi ~/.mailfilter&lt;br /&gt;
&lt;br /&gt;
LOGFILE = &amp;quot;/home/dbahawk/maildrop/maildrop.log&amp;quot;&lt;br /&gt;
DEFAULT=&amp;quot;$HOME/maildrop&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# keep a copy&lt;br /&gt;
cc backup&lt;br /&gt;
`cd backup/new &amp;amp;&amp;amp; rm -f dummy \`ls -t | sed -e 1,50d\``&lt;br /&gt;
&lt;br /&gt;
if (/^To:.*getmail@...\.dnsalias\.org$/)&lt;br /&gt;
   {&lt;br /&gt;
        to Maildir/getmail/&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
#if (/^To:.*dbahawk/)&lt;br /&gt;
#   {&lt;br /&gt;
#        to maildrop&lt;br /&gt;
#   }&lt;br /&gt;
&lt;br /&gt;
if (/^To:.*dbahawk/)&lt;br /&gt;
    dotlock &amp;quot;auto.lock&amp;quot; {&lt;br /&gt;
    to &amp;quot;|uudeview -c -i&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Not really sure why this filter is not working properly. The cc works but the To: check doesn&amp;#039;t. So I have a shell that runs separately to process the emails in the backup mail directory.&lt;br /&gt;
====uudeview====&lt;br /&gt;
This is a clever program that can extract attachments from emails and put them in a directory of you choosing.&amp;lt;br /&amp;gt;&lt;br /&gt;
This shell runs from cron at regular intervals to run the whole process&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/usr/bin/ksh&lt;br /&gt;
&lt;br /&gt;
# fetch any new mail from Gmail (uses .fetchmailrc)&lt;br /&gt;
# fetchmail log is $HOME/maildrop/maildrop.log&lt;br /&gt;
fetchmail -d0&lt;br /&gt;
&lt;br /&gt;
# fetchmail uses maildrop as mda (uses .mailfilter) to save messages to  a maildir.&lt;br /&gt;
# this is not working correctly but still copies the messages to backup&lt;br /&gt;
&lt;br /&gt;
# pull out the attachments and send them to the incoming directory for the collector to process when it wakes up&lt;br /&gt;
uudeview -c -i -p ~/Downloads/dbahawk_forward backup/new/*&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Use sed to repeat characters===&lt;br /&gt;
echo an &amp;#039;=&amp;#039; sign then use the loop feature of sed to run round a loop a further 79 times replacing what you&amp;#039;ve got with the same thing plus and extra one!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
echo &amp;quot;=&amp;quot; | sed -e :a -e &amp;#039;s/^=\{1,79\}$/&amp;amp;=/;ta&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Convert between lower and upper case using ansi standard===&lt;br /&gt;
This way should be portable and give predictable results&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
LOWER_SID=$(echo &amp;quot;${SID}&amp;quot; | tr &amp;#039;[:upper:]&amp;#039; &amp;#039;[:lower:]&amp;#039;)&lt;br /&gt;
UPPER_SID=$(echo &amp;quot;${SID}&amp;quot; | tr &amp;#039;[:lower:]&amp;#039; &amp;#039;[:upper:]&amp;#039;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Use sed to delete the first line of a file or command output printing from the second line onwards===&lt;br /&gt;
Actually deceptively simple. Example remove the header from df output.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
df -k | sed 1d&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
As a useful extension, suppose TO_DATA_DIR contains multiple directories, this will total the free space for all relevant filesystems&amp;lt;br /&amp;gt;&lt;br /&gt;
This one is specific to AIX, for other Unixes and Linux, use $4 instead of $3.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SPACE_AVAILABLE=$(df -k $TO_DATA_DIR | sed 1d | awk &amp;#039;BEGIN {i=0} {i=i+$3} END {print i}&amp;#039;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Use sed to munge a controlfile into submission!===&lt;br /&gt;
* delete comment lines&lt;br /&gt;
* delete all lines after the one starting with a semicolon&lt;br /&gt;
* delete all blank lines&lt;br /&gt;
* change reuse to set&lt;br /&gt;
* change archivelog (with word boundaries) to noarchivelog&lt;br /&gt;
* change old sid to new sid&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sqlplus -s / as sysdba&amp;lt;&amp;lt;&amp;#039;EOSQL&amp;#039; &amp;gt;/dev/null&lt;br /&gt;
alter database backup controlfile to trace as &amp;#039;/tmp/regenerate_controlfile.sql&amp;#039; reuse resetlogs;&lt;br /&gt;
EOSQL&lt;br /&gt;
OLDSID=&amp;#039;PROD&amp;#039;&lt;br /&gt;
NEWSID=&amp;#039;TEST&amp;#039;&lt;br /&gt;
sed  -e &amp;#039;/^--/d&amp;#039; -e &amp;#039;/^\;/q&amp;#039; -e &amp;#039;/^ *$/d&amp;#039; -e &amp;#039;s/REUSE/SET/&amp;#039; -e &amp;#039;s/\&amp;lt;ARCHIVELOG\&amp;gt;/NOARCHIVELOG/&amp;#039; -e &amp;#039;s/\&amp;quot;&amp;#039;${OLDSID}&amp;#039;\&amp;quot;/\&amp;quot;&amp;#039;${NEWSID}&amp;#039;\&amp;quot;/&amp;#039; /tmp/regenerate_controlfile.sql&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Find all files where a certain text does not exist===&lt;br /&gt;
Mostly we want to search for files containing a particular string but how to find those files that do not contain some text.&amp;lt;br /&amp;gt;&lt;br /&gt;
Using xargs instead of -exec forces the filename to be printed. -H should do this but doesn&amp;#039;t seem to in this case.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
find . -name &amp;quot;*cfg&amp;quot; | xargs grep -H -c TO_CV_HOST {} \; | grep &amp;#039;:0$&amp;#039; | cut -d: -f1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Use tar and gzip to copy files more efficiently across network between hosts===&lt;br /&gt;
From the destination server, this will connect to the source, tar up each file and pull it back to the current server&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ssh oracle@hn5211 &amp;quot;cd /oracle/ora_data4/iten3/ &amp;amp;&amp;amp; tar -cf - . | gzip &amp;quot; | ( cd /oracle/ora_data2/iten/ &amp;amp;&amp;amp; gunzip -c | tar -xvf - . )&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===double hash and double percent in shell variables to trim off characters from variables===&lt;br /&gt;
&amp;lt;nowiki&amp;gt;#&amp;lt;/nowiki&amp;gt;  - trims everything from the start of line till the FIRST occurrence of following character (abstemious) :-)&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;nowiki&amp;gt;##&amp;lt;/nowiki&amp;gt; - trims everything from the start of line till the LAST occurrence of following character (greedy)&amp;lt;br /&amp;gt;&lt;br /&gt;
%  - trims everything from the end of line backwards till the FIRST occurrence of following character (abstemious)&amp;lt;br /&amp;gt;&lt;br /&gt;
%% - trims everything from the end of line backwards till the LAST occurrence of following character (greedy)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
FILENAME=&amp;quot;/home/bey9at77/hello.txt&amp;quot;&lt;br /&gt;
FILE_STUB1=${FILENAME##*/}&lt;br /&gt;
FILE_STUB=${FILE_STUB1%.*}&lt;br /&gt;
echo $FILE_STUB&lt;br /&gt;
hello&lt;br /&gt;
FILE_EXT=${FILENAME##*.}&lt;br /&gt;
echo $FILE_EXT&lt;br /&gt;
txt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;nowiki&amp;gt;#&amp;lt;/nowiki&amp;gt; - remove prefix reluctantly&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;nowiki&amp;gt;##&amp;lt;/nowiki&amp;gt; - remove prefix greedily&amp;lt;br /&amp;gt;&lt;br /&gt;
% - remove suffix reluctantly&amp;lt;br /&amp;gt;&lt;br /&gt;
%% - remove suffix greedily&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
words=&amp;quot;do.re.mi&amp;quot;&lt;br /&gt;
&lt;br /&gt;
echo ${words#*.}&lt;br /&gt;
&lt;br /&gt;
echo ${words##*.}&lt;br /&gt;
&lt;br /&gt;
echo ${words%.*}&lt;br /&gt;
&lt;br /&gt;
echo ${words%%.*}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===The best shell script ever. An example of how scripting should be done===&lt;br /&gt;
It was written by someone at Oracle. Unfortunately (s)he did not put any author comment in it. Also unfortunately I cannot show it here as it is protected behind Oracles support website.&amp;lt;br /&amp;gt;&lt;br /&gt;
If you have an Oracle Metalink id, you can get the complete script [https://support.oracle.com/epmos/faces/DocumentDisplay?id=949322.1 here]&amp;lt;br /&amp;gt;&lt;br /&gt;
Here is a snippet of a function that demonstrates proper commenting and a very good style.&amp;lt;br &amp;gt;&lt;br /&gt;
The script is called physru.sh and upgrades an Oracle database in a rolling upgrade fashion by using a physical standby.&amp;lt;br /&amp;gt;&lt;br /&gt;
There are 4500 lines in the full script but it is so easy to read and understand because of the way it&amp;#039;s written, it&amp;#039;s like a breath of fresh air. Well done whoever you are!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
###############################################################################&lt;br /&gt;
# NAME:        wait_mrp_active&lt;br /&gt;
#&lt;br /&gt;
# DESCRIPTION: &lt;br /&gt;
#   Wait for $MRP_START_TIMEOUT minutes to confirm that the MRP is active.  If&lt;br /&gt;
#   we can&amp;#039;t detect an active MRP, abort the script with an error.&lt;br /&gt;
#&lt;br /&gt;
# INPUT(S):&lt;br /&gt;
#   Arguments:&lt;br /&gt;
#     $1: database user&lt;br /&gt;
#     $2: user password&lt;br /&gt;
#     $3: tns service name&lt;br /&gt;
#     $4: database unique name&lt;br /&gt;
#&lt;br /&gt;
#   Globals:&lt;br /&gt;
#     None&lt;br /&gt;
#&lt;br /&gt;
# RETURN:&lt;br /&gt;
#   None&lt;br /&gt;
#&lt;br /&gt;
###############################################################################&lt;br /&gt;
wait_mrp_active()&lt;br /&gt;
{&lt;br /&gt;
  display &amp;quot;confirming media recovery is running&amp;quot;&lt;br /&gt;
  l_wma_status=1&lt;br /&gt;
  l_wma_curtime=`perl -e &amp;#039;print int(time)&amp;#039;`&lt;br /&gt;
  l_wma_exptime=`expr $MRP_START_TIMEOUT &amp;quot;*&amp;quot; 60`&lt;br /&gt;
  l_wma_maxtime=`expr $l_wma_curtime + $l_wma_exptime`&lt;br /&gt;
  while [ &amp;quot;$l_wma_curtime&amp;quot; -lt &amp;quot;$l_wma_maxtime&amp;quot; ]&lt;br /&gt;
  do&lt;br /&gt;
    is_mrp_running $1 $2 $3 $4&lt;br /&gt;
    if [ &amp;quot;$?&amp;quot; -gt &amp;quot;0&amp;quot; ]; then&lt;br /&gt;
      l_wma_status=0&lt;br /&gt;
      break&lt;br /&gt;
    fi&lt;br /&gt;
&lt;br /&gt;
    sleep $MRP_START_INTERVAL&lt;br /&gt;
    l_wma_curtime=`perl -e &amp;#039;print int(time)&amp;#039;`&lt;br /&gt;
  done&lt;br /&gt;
  chkerr $l_wma_status &amp;quot;could not detect an active MRP after $MRP_START_TIMEOUT minutes&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===split variable (eg. filename) into separate variables using set===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
FILENAME=&amp;quot;split_this_into_bits&amp;quot;&lt;br /&gt;
set $(echo ${FILENAME} | sed &amp;#039;s/_/ /g&amp;#039;)&lt;br /&gt;
echo $4 $3 $2 $1&lt;br /&gt;
bits into this split&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Centre align text on a line in bash shell===&lt;br /&gt;
Doesn&amp;#039;t work in Korn shell due to %*s&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#COLUMNS=$(tput cols)   # width of the current window&lt;br /&gt;
COLUMNS=80&lt;br /&gt;
title=&amp;quot;Hello world!&amp;quot;&lt;br /&gt;
printf &amp;quot;%*s\n&amp;quot; $(((${#title}+$COLUMNS)/2)) &amp;quot;$title&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
and as a one-liner&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
printf &amp;quot;%*s\n&amp;quot; $(( ( $(echo $* | wc -c ) + 80 ) / 2 )) &amp;quot;$*&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This works in Korn shell...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
TITLE=&amp;quot;$1&amp;quot;&lt;br /&gt;
LINEWIDTH=80&lt;br /&gt;
&lt;br /&gt;
LPAD=$(((${#TITLE}+$LINEWIDTH)/2))&lt;br /&gt;
printf %${LPAD}s &amp;quot;$TITLE&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Right justify text (or repeat characters) on a line with leader dots!===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
function rpadwait {&lt;br /&gt;
    text=$1&lt;br /&gt;
# -------------------------&lt;br /&gt;
# suppress newline for echo&lt;br /&gt;
# -------------------------&lt;br /&gt;
N=&lt;br /&gt;
C=&lt;br /&gt;
if echo &amp;quot;\c&amp;quot; | grep c &amp;gt;/dev/null 2&amp;gt;&amp;amp;1; then&lt;br /&gt;
    N=&amp;#039;-n&amp;#039;&lt;br /&gt;
else&lt;br /&gt;
    C=&amp;#039;\c&amp;#039;&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
    echo ${N} &amp;quot;${text}${C}&amp;quot; | sed -e :a -e &amp;#039;s/^.\{1,80\}$/&amp;amp;\./;ta&amp;#039;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===cron jobs not submitted - daemon run out of child processes?===&lt;br /&gt;
Sometimes have problems with NFS mounts and this causes cron jobs to hang. If they are scheduled to run regularly, eventually cron will no longer be able to start any more jobs.&amp;lt;br /&amp;gt;&lt;br /&gt;
* Check the cron log &amp;#039;&amp;#039;&amp;#039;/var/adm/cron/log&amp;#039;&amp;#039;&amp;#039; to see if there are any errors or other messages around the time the jobs should run.&lt;br /&gt;
If cron has hit its process limit (default 100), it will try again after a number of seconds (default 60).&amp;lt;br /&amp;gt;&lt;br /&gt;
Both the number of jobs and wait time are configured in the file &amp;#039;&amp;#039;&amp;#039;/var/adm/cron/queuedefs&amp;#039;&amp;#039;&amp;#039;. If it is unusual for cron to be running so many jobs, you can check the process table to view the jobs cron has created. These jobs will have parent process id (PPID) of the cron daemon.&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ ps -ef | grep cron | grep -v grep&lt;br /&gt;
    root  6750314        1   0   Apr 24      -  3:39 /usr/sbin/cron&lt;br /&gt;
solax025:root[/home/root]# ps -T 6750314&lt;br /&gt;
      PID    TTY  TIME CMD&lt;br /&gt;
  6750314      -  3:39 cron&lt;br /&gt;
 21168296      -  0:00     \--bsh&lt;br /&gt;
 58982414      -  0:00         \--sadc&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
In this example, we only have 1 job running&lt;br /&gt;
&lt;br /&gt;
===Find long-running processes with a cron job===&lt;br /&gt;
Processes running longer than 24 hours have a date instead of a start time...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
58 08,14 * * * /home/ibmtools/scripts/oracle/dosh -vc &amp;quot;ps -ef|grep &amp;#039;ibmtools/scripts/oracle&amp;#039;|perl -nae &amp;#039;print if \$F[4] !~/:/&amp;#039;&amp;quot; &amp;gt;/tmp/lrp.txt; [[ $(grep -c ibmtools /tmp/lrp.txt) -ne 0 ]] &amp;amp;&amp;amp; cat /tmp/lrp.txt|mailx -s &amp;#039;*** long running processes - please check ***&amp;#039; reporting@companymail.com&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Process command line arguments in shell===&lt;br /&gt;
Borrowed from Mozilla Firefox installer&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
## Command line arg defaults&lt;br /&gt;
##&lt;br /&gt;
moz_debug=0&lt;br /&gt;
moz_debugger=&amp;quot;&amp;quot;&lt;br /&gt;
moz_debugger_args=&amp;quot;&amp;quot;&lt;br /&gt;
#&lt;br /&gt;
##&lt;br /&gt;
## Parse the command line&lt;br /&gt;
##&lt;br /&gt;
while [ $# -gt 0 ]&lt;br /&gt;
do&lt;br /&gt;
  case $1 in&lt;br /&gt;
    -g | --debug)&lt;br /&gt;
      moz_debug=1&lt;br /&gt;
      shift&lt;br /&gt;
      ;;&lt;br /&gt;
    -d | --debugger)&lt;br /&gt;
      moz_debugger=$2;&lt;br /&gt;
      if [ &amp;quot;${moz_debugger}&amp;quot; != &amp;quot;&amp;quot; ]; then&lt;br /&gt;
	shift 2&lt;br /&gt;
      else&lt;br /&gt;
        echo &amp;quot;-d requires an argument&amp;quot;&lt;br /&gt;
        exit 1&lt;br /&gt;
      fi&lt;br /&gt;
      ;;&lt;br /&gt;
    -a | --debugger-args)&lt;br /&gt;
      moz_debugger_args=$2;&lt;br /&gt;
      if [ &amp;quot;${moz_debugger_args}&amp;quot; != &amp;quot;&amp;quot; ]; then&lt;br /&gt;
	shift 2&lt;br /&gt;
      else&lt;br /&gt;
        echo &amp;quot;-a requires an argument&amp;quot;&lt;br /&gt;
        exit 1&lt;br /&gt;
      fi&lt;br /&gt;
      ;;&lt;br /&gt;
    *)&lt;br /&gt;
      break;&lt;br /&gt;
      ;;&lt;br /&gt;
  esac&lt;br /&gt;
done&lt;br /&gt;
#&lt;br /&gt;
##&lt;br /&gt;
## Program name given in $1&lt;br /&gt;
##&lt;br /&gt;
if [ $# -gt 0 ]&lt;br /&gt;
then&lt;br /&gt;
	MOZ_PROGRAM=$1&lt;br /&gt;
	shift&lt;br /&gt;
fi&lt;br /&gt;
##&lt;br /&gt;
## Program not given, try to guess a default&lt;br /&gt;
##&lt;br /&gt;
if [ -z &amp;quot;$MOZ_PROGRAM&amp;quot; ]&lt;br /&gt;
then&lt;br /&gt;
	##&lt;br /&gt;
	## Try this script&amp;#039;s name with &amp;#039;-bin&amp;#039; appended&lt;br /&gt;
	##&lt;br /&gt;
	if [ -x &amp;quot;$MOZ_DEFAULT_NAME&amp;quot; ]&lt;br /&gt;
	then&lt;br /&gt;
		MOZ_PROGRAM=$MOZ_DEFAULT_NAME&lt;br /&gt;
	##&lt;br /&gt;
	## Try mozilla-bin&lt;br /&gt;
	## &lt;br /&gt;
	elif [ -x &amp;quot;$MOZ_APPRUNNER_NAME&amp;quot; ]&lt;br /&gt;
	then&lt;br /&gt;
		MOZ_PROGRAM=$MOZ_APPRUNNER_NAME&lt;br /&gt;
	fi&lt;br /&gt;
fi&lt;br /&gt;
#&lt;br /&gt;
#&lt;br /&gt;
##&lt;br /&gt;
## Make sure the program is executable&lt;br /&gt;
##&lt;br /&gt;
if [ ! -x &amp;quot;$MOZ_PROGRAM&amp;quot; ]&lt;br /&gt;
then&lt;br /&gt;
	moz_bail &amp;quot;Cannot execute $MOZ_PROGRAM.&amp;quot;&lt;br /&gt;
fi&lt;br /&gt;
#&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Carry XWindows settings across sessions===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# ----------------------&lt;br /&gt;
# push XWindows settings&lt;br /&gt;
# ----------------------&lt;br /&gt;
[[ &amp;quot;$(uname)&amp;quot; == &amp;quot;SunOS&amp;quot; ]] &amp;amp;&amp;amp; PATH=/usr/openwin/bin:$PATH&lt;br /&gt;
WHOAMI=$(id | awk -F&amp;#039;)&amp;#039; &amp;#039;{print $1}&amp;#039; | awk -F&amp;#039;(&amp;#039; &amp;#039;{print $2}&amp;#039;)&lt;br /&gt;
xauth list &amp;gt; /tmp/xauth_list_$WHOAMI&lt;br /&gt;
chmod 777 /tmp/xauth_list_$WHOAMI&lt;br /&gt;
&lt;br /&gt;
echo $DISPLAY &amp;gt; /tmp/xdisplay_$WHOAMI&lt;br /&gt;
chmod 777 /tmp/xdisplay_$WHOAMI&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Cross-platform version of whoami===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
WHOAMI=$(id | awk -F&amp;#039;)&amp;#039; &amp;#039;{print $1}&amp;#039; | awk -F&amp;#039;(&amp;#039; &amp;#039;{print $2}&amp;#039;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Set terminal title from command line===&lt;br /&gt;
Put something like this in the .profile&amp;lt;br /&amp;gt;&lt;br /&gt;
-n     do not output the trailing newline&amp;lt;br /&amp;gt;&lt;br /&gt;
-e     enable interpretation of backslash escapes&amp;lt;br /&amp;gt;&lt;br /&gt;
|0     sets title of window and icon&amp;lt;br /&amp;gt;&lt;br /&gt;
|1     sets title of icon only&amp;lt;br /&amp;gt;&lt;br /&gt;
|2     sets title of window only&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
echo -en &amp;quot;\033]0;`hostname`\007&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
echo -en &amp;quot;\033]2;`hostname`\007&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Remove blank lines and comments (also indented ones) from a file===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
awk -F\: &amp;#039;!/^($|[:space:]*#)/ {print $2}&amp;#039; /etc/oratab | sort | uniq&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or as part of a script that removes comments and blank lines from all Korn shell scripts in a directory&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/usr/bin/ksh&lt;br /&gt;
for i in $(ls *ksh); do&lt;br /&gt;
    perl -p -i -e &amp;#039;s/^\s*#[^!]*$//; s/^\s*$//&amp;#039; $i&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Return elements of an array in Korn shell===&lt;br /&gt;
From [http://unix.stackexchange.com/questions/188202/processing-output-from-an-sqlite-db-into-a-ksh-array-with-spaces here]&amp;lt;br /&amp;gt;&lt;br /&gt;
Could be used to separate the columns of an SQL select when returning to the shell&amp;lt;br /&amp;gt;&lt;br /&gt;
This approach eliminates the need to put quotes around text with spaces in it.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
echo $KSH_VERSION&lt;br /&gt;
x=&amp;quot;Red,Yellow is a color,Blue&amp;quot;&lt;br /&gt;
oIFS=$IFS&lt;br /&gt;
IFS=,&lt;br /&gt;
y=($x)&lt;br /&gt;
IFS=$oIFS&lt;br /&gt;
echo ${y[1]}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===A decent Unix Prompt===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
export PS1=&amp;quot;`uname -n`:`whoami`[\${PWD}]# &amp;quot;&lt;br /&gt;
or&lt;br /&gt;
export PS1=&amp;#039;($?) $&amp;#039;ORACLE_SID&amp;quot; &amp;quot;`whoami`&amp;quot;@&amp;quot;`uname -n`&amp;quot;:&amp;quot;&amp;#039;$&amp;#039;PWD&amp;quot;&amp;gt; &amp;quot;&lt;br /&gt;
export EDITOR=vi&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Simple arithmetic===&lt;br /&gt;
pipe the calculation into the shell calculator&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
space_in_kb=$(echo $1 / 1024 | bc)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Calculate the remainder (modulo) of a division calculation&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
if [[ $(echo &amp;quot;${NUMBER} % 2&amp;quot; | bc) -eq 0 ]]; then&lt;br /&gt;
    echo &amp;quot;${NUMBER} is even&amp;quot;&lt;br /&gt;
else&lt;br /&gt;
    echo &amp;quot;${NUMBER} is odd&amp;quot;&lt;br /&gt;
fi&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or do it in awk if scientific notation maybe involved&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
function calc { awk &amp;quot;BEGIN{print $*}&amp;quot;; }&lt;br /&gt;
&lt;br /&gt;
if [[ $(calc &amp;quot;${SPACE_USED} + ${SPACE_AVAILABLE} - ${DATABASE_SIZE&amp;quot;) -le 0 ]]; then&lt;br /&gt;
    echo &amp;quot;NOK&amp;quot;&lt;br /&gt;
fi&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Script encryption and passphrase protection===&lt;br /&gt;
Encrypt a shell script with the ability to execute the encrypted version&lt;br /&gt;
* from [http://www.commandlinefu.com/commands/browse commandlinefu.com]&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
scrypt(){ [ -n &amp;quot;$1&amp;quot; ]&amp;amp;&amp;amp;{ echo &amp;#039;. &amp;lt;(echo &amp;quot;$(tail -n+2 $0|base64 -d|mcrypt -dq)&amp;quot;); exit;&amp;#039;&amp;gt;$1.scrypt;cat $1|mcrypt|base64 &amp;gt;&amp;gt;$1.scrypt;chmod +x $1.scrypt;};}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Virtual host configuration in Apache http.conf===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;VirtualHost *:80&amp;gt;&lt;br /&gt;
        ServerName dbamon&lt;br /&gt;
        DocumentRoot &amp;quot;/Volumes/data/Sites/dbamon_push&amp;quot;&lt;br /&gt;
        &amp;lt;Directory &amp;quot;/Volumes/data/Sites/dbamon_push&amp;quot;&amp;gt;&lt;br /&gt;
                Options Includes FollowSymLinks&lt;br /&gt;
                AllowOverride All&lt;br /&gt;
                Order allow,deny&lt;br /&gt;
                Allow from all&lt;br /&gt;
        &amp;lt;/Directory&amp;gt;&lt;br /&gt;
&amp;lt;/VirtualHost&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
and in /etc/hosts, add...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
127.0.0.1  dbamon&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Mount a website (or any other remote resource) locally using WebDav===&lt;br /&gt;
Redhat/CentOS&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
yum install fuse-davfs2&lt;br /&gt;
or&lt;br /&gt;
yum install wdfs.x86_64&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Debian&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
apt-get install davfs2&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
then...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo mkdir /mnt/webdav  # or whatever you&amp;#039;d like to call the directory&lt;br /&gt;
sudo mount.davfs [-o option[,option]...] device mount_point&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
In man&amp;#039;s terms, that last line would translate to:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
id  #suppose this returns uid=501 and gid=502&lt;br /&gt;
sudo mount.davfs -o 501,502 https://your/web/site /mnt/webdav&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Mac OSX&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
osascript -e &amp;#039; mount volume &amp;quot;http://username:password@webdav.address:portnum&amp;quot; &amp;#039;&lt;br /&gt;
or&lt;br /&gt;
osascript -e &amp;#039; mount volume &amp;quot;http://username@webdav.address:portnum&amp;quot; &amp;#039;&lt;br /&gt;
or&lt;br /&gt;
osascript -e &amp;#039; try mount volume &amp;quot;http://webdav.address:portnum&amp;quot; &amp;#039;&lt;br /&gt;
or&lt;br /&gt;
mount -t webdav http://webdav.address:portnum /mnt/webdav  # this one won&amp;#039;t show up in the Finder Sidebar.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Add current hostname to list of hosts on an xcat server===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
CMD=&amp;quot;nodels&amp;quot;&lt;br /&gt;
HOST=`hostname`&lt;br /&gt;
(echo &amp;quot;$HOST&amp;quot;; $CMD) | while read server&lt;br /&gt;
do&lt;br /&gt;
    echo &amp;quot;server:$server&amp;quot;&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===What is todays &amp;#039;Day Of the Year&amp;#039; number?===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
DOY=`perl -e &amp;#039;print sub{$_[7]}-&amp;gt;(localtime)+1;&amp;#039;`&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Convert Julian day numbers to dates===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
for day in 8 33 36 61 64 91 96 121 126 152 155 182 187 215 218 244 247 274 279 306 309 335 338 365; do date -d &amp;quot;`date +%Y`-01-01 +$(( ${day} - 1 ))days&amp;quot; +%d-%m-%Y; done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Send crontab job output to a date formatted log file===&lt;br /&gt;
This will run a job every 5 minutes and send the output to a file ending with a time in hours and minutes.&amp;lt;br /&amp;gt;&lt;br /&gt;
The thing to note is the escaped percent signs. This is because a % sign is interpreted by cron to mean a newline character. Everything after the first % is treated as input to the program.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
*/5 *  * * * /var/www/cgi-bin/dbamon_collector.ksh       &amp;gt;/tmp/dbamon_collector.log.$(date &amp;quot;+\%H\%M&amp;quot;) 2&amp;gt;&amp;amp;1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Edit crontab file without crontab -e===&lt;br /&gt;
It can happen that you need to add or modify a line in the crontab of many users or across many servers at once.&amp;lt;br /&amp;gt;&lt;br /&gt;
In principle, there&amp;#039;s nothing wrong with modifying the crontab file directly. You just lose the advantages of file locking (and syntax checking) that crontab -e offers.&amp;lt;br /&amp;gt;&lt;br /&gt;
Here we take a backup of the current crontab, print it out, echo an extra command and ask cron to use these as input (thus overwriting the existing crontab file). Just don&amp;#039;t run this close to midnight :-)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
crontab -l &amp;gt; /tmp/crontab.`date &amp;#039;+%Y%m%d&amp;#039;`&lt;br /&gt;
(&lt;br /&gt;
cat /tmp/crontab.`date +&amp;#039;%Y%m%d&amp;#039;`&lt;br /&gt;
echo &amp;quot;02 10 * * * /home/ibmtools/scripts/oracle/export_parfile.ksh -s SID -f JDBEOP1.parfile&amp;quot;&lt;br /&gt;
) | crontab -&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
crontab -l &amp;gt; /tmp/crontab.backup&lt;br /&gt;
crontab -l &amp;gt; /tmp/crontab.$$&lt;br /&gt;
perl -p -i -e &amp;#039;s!backup_send_tsm_dump!backup_export2tsm!g&amp;#039; /tmp/crontab.$$&lt;br /&gt;
crontab /tmp/crontab.$$&lt;br /&gt;
rm /tmp/crontab.$$&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
crontab -l &amp;gt;$HOME/crontab.$(date &amp;#039;+%Y%m%d&amp;#039;)&lt;br /&gt;
crontab -l | perl -p -e &amp;#039;s|/nas/software/oracle/scripts|/oracle/scripts|&amp;#039; | crontab&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Use shell to convert a number in scientific notation to normal===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
var2convert=&amp;#039;1.2345678e3&amp;#039;&lt;br /&gt;
printf -v var2convert &amp;quot;%.f&amp;quot; $var2convert&lt;br /&gt;
echo $var2convert  # magic!&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Check for jobs running longer that 24 hours===&lt;br /&gt;
Run from the management server across all Unix servers. Checks the 5th column in a ps listing. If it doesn&amp;#039;t find a : (time separator), the process is running longer than 24 hours.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# ---------------------------------------&lt;br /&gt;
# report on long running oraibm processes&lt;br /&gt;
# ---------------------------------------&lt;br /&gt;
01 17,14 * * * rm -f /tmp/lrp.txt;/home/ibmtools/scripts/oracle/dosh -vc \&amp;quot;ps -ef|egrep &amp;#039;oraibm|scripts/oracle&amp;#039;&amp;gt;/tmp/lrp.txt;perl -nae &amp;#039;print if \$F[4] !~/:/&amp;#039; /tmp/lrp.txt\&amp;quot; &amp;gt;&amp;gt;/tmp/lrp.txt;[[ $(egrep -c &amp;#039;oraibm|scripts/or&lt;br /&gt;
acle&amp;#039; /tmp/lrp.txt) -ne 0 ]] &amp;amp;&amp;amp; cat /tmp/lrp.txt|mailx -s &amp;#039;*** long running processes - please check ***&amp;#039; bey9at77@mail.com&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Global find and replace with perl (restricted to list of files provided by Unix find command)===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
find . -type f -exec perl -i -pe &amp;#039;s/something/else/g&amp;#039; {} \;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===perl function to make filenames lower case===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
function lower { &lt;br /&gt;
   perl -e &amp;#039;for (@ARGV) { rename $_, lc($_) unless -e lc($_); }&amp;#039; * &lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===From the management server, search the TNS listener port for each database on a server and make an inline substitution in the ITM config files!===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
for i in `/home/ibmtools/scripts/oracle/dosh -c &amp;quot;ls -al /opt/IBM/ITM/config/*rz*cfg|grep -v lrwx&amp;quot;|awk &amp;#039;{print $NF}&amp;#039;`; do&lt;br /&gt;
    server=`echo $i|cut -d_ -f1 | awk -F&amp;#039;/&amp;#039; &amp;#039;{print $NF}&amp;#039;`&lt;br /&gt;
    db=`echo $i|cut -d&amp;#039;.&amp;#039; -f1 | awk -F&amp;#039;_&amp;#039; &amp;#039;{print $NF}&amp;#039;`&lt;br /&gt;
    OH=`ssh $server grep &amp;quot;^$db&amp;quot; /etc/oratab|cut -d: -f2`&lt;br /&gt;
    LISTENERPORT=`ssh $server cat $OH/network/admin/listener.ora|perl -00 -ne &amp;#039;print $1 if /&amp;#039;$db&amp;#039;.*PORT.*=.*(\d{4})/s&amp;#039;`&lt;br /&gt;
    ssh $server perl -p -i.bak -e &amp;#039;s/1521/&amp;#039;$LISTENERPORT&amp;#039;/&amp;#039; $i&lt;br /&gt;
    ssh $server ls -al ${i}*&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Run a job from cron every Nth day of the month===&lt;br /&gt;
Example. Execute a job every third Saturday of the month.&amp;lt;br /&amp;gt;&lt;br /&gt;
Paste this into a file called calenday and put it in /usr/local/bin so it&amp;#039;s (probably) on the PATH&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/usr/bin/ksh&lt;br /&gt;
&lt;br /&gt;
# ix is the week number of the month (&amp;quot;2&amp;quot;nd Friday of the month, &amp;quot;3&amp;quot;rd Tuesday of the month)&lt;br /&gt;
# dy is the day number in Unix format (0 for Sunday, 1 for Monday, ... 6 for Saturday)&lt;br /&gt;
# eg. &amp;quot;calenday 3 6&amp;quot; returns the date of 3rd Saturday of the month.&lt;br /&gt;
&lt;br /&gt;
ix=$1&lt;br /&gt;
dy=$2&lt;br /&gt;
SCHAR=$((($dy*2)+$dy+1))&lt;br /&gt;
ECHAR=$(($SCHAR+1))&lt;br /&gt;
cal `date &amp;#039;+%m %Y&amp;#039;` | egrep &amp;quot;\&amp;lt;[0-9]{1,2}\&amp;gt;&amp;quot; | cut -c${SCHAR}-${ECHAR} | xargs | awk {&amp;#039;print $&amp;#039;$ix&amp;#039;}&amp;#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Now in crontab, you should be able to do something like this:&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
15 20 * * * [[ `calenday 3 6` -eq `/bin/date &amp;#039;+%d&amp;#039;` ]] &amp;amp;&amp;amp; su - oracle -c &amp;quot;run_my_backup.ksh&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will also work on some Unices..&amp;lt;br /&amp;gt;&lt;br /&gt;
We send backups to a special TSM node on the second Friday of each month. This report must run a day later - but that is not guaranteed to be the second Saturday or even the 3rd. So...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
30 12 8-14 * 5 sleep 86400 &amp;amp;&amp;amp; su - oracle -c &amp;quot;/usr/bin/perl -ne &amp;#039;print if /ORX_M_SOL/ .. /^STOP/&amp;#039; /home/oracle/incoming/dbamon_spool_tsm_*.SOL | grep Archive | grep -v Client | mailx -s &amp;#039;Monthly TSM backups&amp;#039; orareport@xxxxxx.com&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ps listing does not show start time after 24 hours===&lt;br /&gt;
But you can see elapsed time using your own ps command&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/usr/bin/ps -eo etime,user,pid,ppid,cpu,start,tty,time,args|tail -n +2|sort&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ps -ef cuts off args cmd column on Solaris===&lt;br /&gt;
====To see more than 80 characters of the last column on Solaris====&lt;br /&gt;
This shows all the individual arguments to the command&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
pargs &amp;lt;pid&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This shows the ps listing in &amp;#039;compatibility&amp;#039; mode (there are more compatibility commands in /usr/xpg4/bin)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/usr/ucb/ps auww&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====To see more than 80 characters of the last column on AIX====&lt;br /&gt;
This shows the full argument listing of a process (NOTE: no minus sign!)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ps eww &amp;lt;pid&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Remove blank / empty lines from vi ===&lt;br /&gt;
Maybe you cut and pasted a file from Windows and it&amp;#039;s full of blank lines and Control-M&amp;#039;s now&amp;lt;br /&amp;gt;&lt;br /&gt;
There are several methods but I think this is the easiest to remember&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
:g/^$/d&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Right pad a variable===&lt;br /&gt;
a function like rpad in SQL but for Shell&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
function rpad {&lt;br /&gt;
text=$1&lt;br /&gt;
padwidth=$2&lt;br /&gt;
padchar=$3&lt;br /&gt;
echo &amp;quot;$text&amp;quot; | sed -e :a -e &amp;#039;s/^.\{1,&amp;#039;$padwidth&amp;#039;\}$/&amp;amp;\&amp;#039;$padchar&amp;#039;/;ta&amp;#039;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Connect to a Windows server from Linux using rdesktop===&lt;br /&gt;
My remmina stopped working so rolled my own. Very simple really. Put this is a shell.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
tsocks rdesktop -z -P -x m -a 16 -d MAIND -u sbarkley -p ****** -r disk:SOL=$HOME/Documents/SOL -g 95% 150.251.112.38 &amp;amp;&lt;br /&gt;
&lt;br /&gt;
where...&lt;br /&gt;
-z    - enables compression&lt;br /&gt;
-P    - enables bitmap caching (saves network traffic)&lt;br /&gt;
-x m  - disables eye-candy features&lt;br /&gt;
-a 16 - reduce colour pallete to 16 colours&lt;br /&gt;
-d    - domain to connect to&lt;br /&gt;
-u    - username&lt;br /&gt;
-p    - password&lt;br /&gt;
-r    - setup a shared folder&lt;br /&gt;
-g    - geometry (use W x H or percentage)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Slight problems with rdesktop not working 100% of the time. Now using xfreerdp. Seems better...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
xfreerdp -g 90% --ignore-certificate --gdi sw -K -d wdcrhbp05 -u oraibm -p &amp;quot;`cat $HOME/scripts/.oraibm.password`&amp;quot; -T &amp;quot;wdcrhbp05_oraibm&amp;quot; --plugin cliprdr --plugin rdpdr --data disk:SOL:/home/bey9at77/Documents/SOL -- --plugin rdpsnd --data alsa -- 150.251.112.25 &amp;amp;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Reset your password bypassing password rules===&lt;br /&gt;
must be done as root&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
echo &amp;quot;user:new_password&amp;quot; | chpasswd&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Sum the sizes of all files of an ls listing===&lt;br /&gt;
It&amp;#039;ll check to see if the sum of filesizes corresponds with the df -g (or h) listing (can get messed up due to open but deleted files)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cd /oracle/export&lt;br /&gt;
df -g .&lt;br /&gt;
find . -name &amp;quot;*dmp*&amp;quot; -ls |  awk &amp;#039;{ SUM += $7} END { print SUM/1024/1024/1024 }&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Mount an iso image under Linux===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
mkdir -p /mnt/cdrom&lt;br /&gt;
mount -o loop /dev/cdrom /mnt/cdrom&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===How many processors on the machine?===&lt;br /&gt;
* AIX&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
lsdev -C|grep Process|wc -l&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Solaris&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
psrinfo -v|grep &amp;quot;Status of processor&amp;quot;|wc -l&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Linux&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cat /proc/cpuinfo|grep processor|wc -l&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Quick, simple, understandable example of how to use RRDTool===&lt;br /&gt;
* [[RRDTool]]&lt;br /&gt;
&lt;br /&gt;
===Use expect to respond automatically to interactive programs===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/usr/bin/expect -f&lt;br /&gt;
spawn /usr/tivoli/tsm/client/oracle/bin64/tdpoconf passw -tdpo_optfile=/oracle/[lindex $argv 0]/admin/tdpo.opt&lt;br /&gt;
expect &amp;quot;assword:&amp;quot; {send &amp;quot;password\r&amp;quot;}&lt;br /&gt;
expect &amp;quot;assword:&amp;quot; {send &amp;quot;password\r&amp;quot;}&lt;br /&gt;
expect &amp;quot;assword:&amp;quot; {send &amp;quot;password\r&amp;quot;}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Use expect to allow file copy with scp (if ssh keys are not an option)===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/usr/bin/expect -f&lt;br /&gt;
spawn scp /home/oracle/.profile oracle@hn512:/tmp/prfl&lt;br /&gt;
set pass &amp;quot;thepassword&amp;quot;&lt;br /&gt;
expect {&lt;br /&gt;
        password: {send &amp;quot;$pass\r&amp;quot; ; exp_continue}&lt;br /&gt;
        eof exit&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Within a shell script set up simultaneous output to both terminal and a file using a FIFO (named pipes)===&lt;br /&gt;
or &amp;quot;How to send shell output to screen/stdout as well as to a logfile using tee and redirection with exec&amp;quot;&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
examples [http://www.unix.com/shell-programming-and-scripting/85584-redirect-within-ksh.html here on unix.com]&lt;br /&gt;
* general info on redirections [http://www.catonmat.net/blog/bash-one-liners-explained-part-three/ here at catonmat.net]&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/ksh&lt;br /&gt;
&lt;br /&gt;
REDIR=test.redir&lt;br /&gt;
FIFO=test.pipe&lt;br /&gt;
[[ -e $FIFO ]] || mkfifo $FIFO&lt;br /&gt;
&lt;br /&gt;
# make a new channel(3) and copy channel 1&amp;#039;s destination as its own (does NOT POINT TO channel 1&amp;#039;s destination)&lt;br /&gt;
# this allows the normal output to continue to STDOUT but also get printed to whatever file is attached to channel 3&lt;br /&gt;
exec 3&amp;gt;&amp;amp;1&lt;br /&gt;
&lt;br /&gt;
# anything coming in on the pipe, send it to $REDIR and to channel 3&lt;br /&gt;
tee $REDIR &amp;lt;$FIFO &amp;gt;&amp;amp;3 &amp;amp;&lt;br /&gt;
&lt;br /&gt;
# redirect STDOUT to the pipe&lt;br /&gt;
exec &amp;gt; $FIFO&lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;going to default output&amp;quot;&lt;br /&gt;
echo &amp;quot;forcing to channel 1&amp;quot; &amp;gt;&amp;amp;1&lt;br /&gt;
echo &amp;quot;forcing to channel 2&amp;quot; &amp;gt;&amp;amp;2&lt;br /&gt;
echo &amp;quot;forcing to channel 3&amp;quot; &amp;gt;&amp;amp;3&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====More elaborate example====&lt;br /&gt;
found [http://stackoverflow.com/questions/2288939/create-a-pipe-that-writes-to-multiple-files-tee here on stackoverflow]&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/sh&lt;br /&gt;
&lt;br /&gt;
# Author: Harvey Chapman &amp;lt;hchapman _AT_ 3gfp.com&amp;gt;&lt;br /&gt;
# Description: POSIX shell functions that can be used with tee to simultaneously put&lt;br /&gt;
#              stderr and stdout to both a file and stdout&lt;br /&gt;
#&lt;br /&gt;
# Based on:&lt;br /&gt;
#    Re: How to redirect stderr and stdout to a file plus display at the same time&lt;br /&gt;
#    http://www.travishartwell.net/blog/2006/08/19_2220&lt;br /&gt;
&lt;br /&gt;
#&lt;br /&gt;
# Original example function from Travis Hartwell&amp;#039;s blog.&lt;br /&gt;
# Note: I&amp;#039;ve made minor changes to it.&lt;br /&gt;
example()&lt;br /&gt;
{&lt;br /&gt;
  OUTPUT_LOG=output.log&lt;br /&gt;
  OUTPUT_PIPE=output.pipe&lt;br /&gt;
&lt;br /&gt;
  # This should really be -p to test that it&amp;#039;s a pipe.&lt;br /&gt;
  if [ ! -e $OUTPUT_PIPE ]; then&lt;br /&gt;
      mkfifo $OUTPUT_PIPE&lt;br /&gt;
  fi&lt;br /&gt;
&lt;br /&gt;
  # This should really be -f to test that it&amp;#039;s a regular file.&lt;br /&gt;
  if [ -e $OUTPUT_LOG ]; then&lt;br /&gt;
      rm $OUTPUT_LOG&lt;br /&gt;
  fi&lt;br /&gt;
&lt;br /&gt;
  exec 3&amp;gt;&amp;amp;1 4&amp;gt;&amp;amp;2&lt;br /&gt;
  tee $OUTPUT_LOG &amp;lt; $OUTPUT_PIPE &amp;gt;&amp;amp;3 &amp;amp;&lt;br /&gt;
  tpid=$!&lt;br /&gt;
  exec &amp;gt; $OUTPUT_PIPE 2&amp;gt;&amp;amp;1&lt;br /&gt;
&lt;br /&gt;
  echo &amp;quot;This is on standard out&amp;quot;&lt;br /&gt;
  echo &amp;quot;This is on standard err&amp;quot; &amp;gt;&amp;amp;2&lt;br /&gt;
&lt;br /&gt;
  exec 1&amp;gt;&amp;amp;3 3&amp;gt;&amp;amp;- 2&amp;gt;&amp;amp;4 4&amp;gt;&amp;amp;-&lt;br /&gt;
  wait $tpid&lt;br /&gt;
&lt;br /&gt;
  rm $OUTPUT_PIPE&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
# A slightly reduced version of example()&lt;br /&gt;
example2()&lt;br /&gt;
{&lt;br /&gt;
  OUTPUT_LOG=output.log&lt;br /&gt;
  OUTPUT_PIPE=output.pipe&lt;br /&gt;
&lt;br /&gt;
  rm -f $OUTPUT_PIPE&lt;br /&gt;
  mkfifo $OUTPUT_PIPE&lt;br /&gt;
  rm -f $OUTPUT_LOG&lt;br /&gt;
&lt;br /&gt;
  tee $OUTPUT_LOG &amp;lt; $OUTPUT_PIPE &amp;amp;&lt;br /&gt;
  tpid=$!&lt;br /&gt;
&lt;br /&gt;
  exec 3&amp;gt;&amp;amp;1 4&amp;gt;&amp;amp;2 &amp;gt;$OUTPUT_PIPE 2&amp;gt;&amp;amp;1&lt;br /&gt;
&lt;br /&gt;
  echo &amp;quot;This is on standard out&amp;quot;&lt;br /&gt;
  echo &amp;quot;This is on standard err&amp;quot; &amp;gt;&amp;amp;2&lt;br /&gt;
&lt;br /&gt;
  exec 1&amp;gt;&amp;amp;3 3&amp;gt;&amp;amp;- 2&amp;gt;&amp;amp;4 4&amp;gt;&amp;amp;-&lt;br /&gt;
  wait $tpid&lt;br /&gt;
  rm -f $OUTPUT_PIPE&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
#&lt;br /&gt;
# Logging methods based on above. See the example below for how to use them.&lt;br /&gt;
#&lt;br /&gt;
&lt;br /&gt;
# Usage: start_logging [delete_existing_logfile]&lt;br /&gt;
start_logging()&lt;br /&gt;
{&lt;br /&gt;
  # Check to see if OUTPUT_LOG and OUTPUT_PIPE need to be defined.&lt;br /&gt;
  if [ -z &amp;quot;$OUTPUT_LOG&amp;quot; ]; then&lt;br /&gt;
    OUTPUT_LOG=output.log&lt;br /&gt;
  fi&lt;br /&gt;
  if [ -z &amp;quot;$OUTPUT_PIPE&amp;quot; ]; then&lt;br /&gt;
    OUTPUT_PIPE=output.pipe&lt;br /&gt;
  fi&lt;br /&gt;
  # Make sure that we&amp;#039;re not already logging.&lt;br /&gt;
  if [ -n &amp;quot;$OUTPUT_PID&amp;quot; ]; then&lt;br /&gt;
    echo &amp;quot;Logging already started!&amp;quot;&lt;br /&gt;
    return 1&lt;br /&gt;
  fi&lt;br /&gt;
&lt;br /&gt;
  # Always remove the log and pipe first.&lt;br /&gt;
  rm -f $OUTPUT_PIPE&lt;br /&gt;
  # Delete the logfile first if told to.&lt;br /&gt;
  if [ &amp;quot;$1&amp;quot; = delete_existing_logfile ]; then&lt;br /&gt;
    rm -f $OUTPUT_LOG&lt;br /&gt;
  fi&lt;br /&gt;
&lt;br /&gt;
  mkfifo $OUTPUT_PIPE&lt;br /&gt;
  tee -a $OUTPUT_LOG &amp;lt; $OUTPUT_PIPE &amp;amp;&lt;br /&gt;
  OUTPUT_PID=$!&lt;br /&gt;
&lt;br /&gt;
  exec 3&amp;gt;&amp;amp;1 4&amp;gt;&amp;amp;2 &amp;gt;$OUTPUT_PIPE 2&amp;gt;&amp;amp;1&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
stop_logging()&lt;br /&gt;
{&lt;br /&gt;
  # Make sure that we&amp;#039;re currently logging.&lt;br /&gt;
  if [ -z &amp;quot;$OUTPUT_PID&amp;quot; ]; then&lt;br /&gt;
    echo &amp;quot;Logging not yet started!&amp;quot;&lt;br /&gt;
    return 1&lt;br /&gt;
  fi&lt;br /&gt;
  exec 1&amp;gt;&amp;amp;3 3&amp;gt;&amp;amp;- 2&amp;gt;&amp;amp;4 4&amp;gt;&amp;amp;-&lt;br /&gt;
  wait $OUTPUT_PID&lt;br /&gt;
  rm -f $OUTPUT_PIPE&lt;br /&gt;
  unset OUTPUT_PID&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
example3()&lt;br /&gt;
{&lt;br /&gt;
  start_logging&lt;br /&gt;
  #start_logging delete_existing_logfile&lt;br /&gt;
  echo &amp;quot;This is on standard out&amp;quot;&lt;br /&gt;
  echo &amp;quot;This is on standard err&amp;quot; &amp;gt;&amp;amp;2&lt;br /&gt;
  stop_logging&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===RedHat root filesystem has gone read-only===&lt;br /&gt;
* [http://www.unixarena.com/2013/09/redhat-linux-how-to-fix-read-only-root.html How to fix read only root file system]&lt;br /&gt;
&lt;br /&gt;
===Kill all processes for a user===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
for prc in `ps -ef | grep -E &amp;quot;^ +[o]racle&amp;quot; | awk &amp;#039;{print $2}&amp;#039;`; do&lt;br /&gt;
    kill $prc&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===isRGHere===&lt;br /&gt;
Checks if resource group is on this leg of an HACMP cluster. Returns 0 if true else 1.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/usr/bin/ksh&lt;br /&gt;
&lt;br /&gt;
SCRIPT=`basename $0`&lt;br /&gt;
&lt;br /&gt;
function rctest&lt;br /&gt;
{&lt;br /&gt;
exitcode=$1&lt;br /&gt;
msg=$2&lt;br /&gt;
if [ $exitcode -ne 0 ]; then&lt;br /&gt;
        echo &amp;quot;********************************************************************************&amp;quot;&lt;br /&gt;
        echo &amp;quot;\nScript $SCRIPT finished with errors.&amp;quot;&lt;br /&gt;
        echo &amp;quot;$msg.&amp;quot;&lt;br /&gt;
        echo &amp;quot;Returncode : $exitcode.&amp;quot;&lt;br /&gt;
        echo &amp;quot;\n********************************************************************************&amp;quot;&lt;br /&gt;
&lt;br /&gt;
        fi&lt;br /&gt;
exit $exitcode&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
RGINFO=/usr/es/sbin/cluster/utilities/clRGinfo&lt;br /&gt;
[[ ! -f $RGINFO ]] &amp;amp;&amp;amp;  rctest 1 &amp;quot;clRGinfo not found&amp;quot;&lt;br /&gt;
&lt;br /&gt;
if [ $# -eq 1 ]&lt;br /&gt;
then&lt;br /&gt;
        RG=`echo $1 | cut -c 1-14`&lt;br /&gt;
else&lt;br /&gt;
        rctest 10  &amp;quot;Usage: `basename $0` &amp;lt;RG name&amp;gt;&amp;quot;&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
$RGINFO |grep -qwp $RG ||  rctest 9 &amp;quot;$RG is not defined&amp;quot;&lt;br /&gt;
&lt;br /&gt;
THISNODE=`/usr/es/sbin/cluster/utilities/get_local_nodename | cut -c 1-14`&lt;br /&gt;
$RGINFO |grep -wp $RG |grep -w $THISNODE |grep -wq ONLINE&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===AIX: add a user to a group===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
chgrpmem -m + oracle ibmtls&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Find swear words in scripts by comparing it to a list found on the internet===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
wget &amp;quot;http://www.bannedwordlist.com/lists/swearWords.csv&amp;quot; -O /tmp/s ; for word in $(cat /tmp/s | sed -e &amp;#039;s/ /_/g&amp;#039; -e &amp;#039;s/,/ /g&amp;#039;) ; do grep -wR $word *; done | less&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===grep -p (for paragraph) works on AIX but not on Linux or Solaris===&lt;br /&gt;
Use awk instead&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
awk &amp;#039;BEGIN {FS=&amp;quot;\n&amp;quot; RS=&amp;quot;\n\n&amp;quot;} /search pattern/ { do something }&amp;#039; &amp;lt;file&amp;gt;&lt;br /&gt;
/usr/xpg4/bin/awk &amp;#039;BEGIN {RS=&amp;quot;\n\n&amp;quot;;FS=&amp;quot;\n&amp;quot;} /AGRHDWQ1/ {print $2}&amp;#039; dsm.sys | awk &amp;#039;{print $NF}&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
this prints the last word of the second &amp;#039;&amp;#039;line&amp;#039;&amp;#039; in the paragraph in dsm.sys that contains the search term AGRHDWQ1.&amp;lt;br /&amp;gt;&lt;br /&gt;
Or slightly simpler...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
awk -v RS=&amp;#039;&amp;#039; &amp;#039;/NHAPPLP1/&amp;#039; /etc/tsm/dsm.sys     # (use /usr/xpg4/bin/awk on Solaris)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or, case insensitively:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
awk -v RS=&amp;#039;&amp;#039; &amp;#039;tolower($0) ~/so_u_clubqa_orx_d_cab/&amp;#039; /etc/tsm/dsm.sys&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Using -v means you don&amp;#039;t have to use a BEGIN section.&lt;br /&gt;
&lt;br /&gt;
===debug/redirect log of a shell===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/usr/bin/ksh&lt;br /&gt;
exec 2&amp;gt;/tmp/mytest&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Different ways of Iteration in korn shell with a while loop===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
IFS=&amp;quot;|&amp;quot;&lt;br /&gt;
exec 0&amp;lt;$statfile&lt;br /&gt;
while read host db started stopped&lt;br /&gt;
do&lt;br /&gt;
    rrdfile=&amp;quot;export_duration_${host}_${db}.rrd&amp;quot;&lt;br /&gt;
    $RRDTOOL update ${RRDDIR}/${rrdfile} $started:$started $stopped&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
while read host db started stopped&lt;br /&gt;
do&lt;br /&gt;
    rrdfile=&amp;quot;export_duration_${host}_${db}.rrd&amp;quot;&lt;br /&gt;
    $RRDTOOL update ${RRDDIR}/${rrdfile} $started:$started $stopped&lt;br /&gt;
done &amp;lt;statfile&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    cat $statfile | sort -nk4 | while IFS=\| read host db type started stopped&lt;br /&gt;
    do&lt;br /&gt;
        [[ &amp;quot;$stopped&amp;quot; == &amp;quot;&amp;quot; ]] &amp;amp;&amp;amp; continue&lt;br /&gt;
        rrdfile=&amp;quot;export_duration_${host}_${db}.rrd&amp;quot;&lt;br /&gt;
        $RRDTOOL update ${RRDDIR}/${rrdfile} ${started}:${started}:${stopped}&lt;br /&gt;
        [[ $? -ne 0 ]] &amp;amp;&amp;amp; echo &amp;quot;nok: $?&amp;quot;&lt;br /&gt;
    done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Filesystem 100% full, what&amp;#039;s taking up all the space?===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
find /oracle/endur -xdev -ls|sort -nr +6|head&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/dev/esb01fs010001      1.00      0.00  100%     1838    69% /oracle&lt;br /&gt;
beuxdsysesb01:root[/root]# cd /oracle&lt;br /&gt;
beuxdsysesb01:root[/oracle]# du -gsx * | sort -n&lt;br /&gt;
0.00    checkpoints&lt;br /&gt;
0.00    flash_recovery_area&lt;br /&gt;
0.00    lost+found&lt;br /&gt;
0.00    oraInst.loc&lt;br /&gt;
0.00    oraInventory&lt;br /&gt;
0.09    admin&lt;br /&gt;
0.99    diag&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
cd  diag and repeat until culprits are found&lt;br /&gt;
&lt;br /&gt;
===Show paged memory hogs on AIX===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
svmon -Pt20 | perl -e &amp;#039;while(&amp;lt;&amp;gt;){print if($.==2||$&amp;amp;&amp;amp;&amp;amp;!$s++);$.=0 if(/^-+$/)}&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Capitalise the first letter of a word in Korn Shell===&lt;br /&gt;
Not as easy as it sounds if it needs to work in non-ksh93 shells&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
function capit { &lt;br /&gt;
    typeset -u first&lt;br /&gt;
    first=${1%&amp;quot;${1#?}&amp;quot;}&lt;br /&gt;
    printf &amp;quot;%s\n&amp;quot; &amp;quot;${first}${1#?}&amp;quot;&lt;br /&gt;
    return 0&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or maybe more neatly done in Perl...&amp;lt;br /&amp;gt;&lt;br /&gt;
This will capitalise each word in a sentence passed into it&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
function capit { &lt;br /&gt;
    echo &amp;quot;$1&amp;quot; |  perl -pe &amp;quot;s/([\w&amp;#039;]+)/\u\L\1/g&amp;quot;&lt;br /&gt;
    return 0&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Remove / rename a directory / file containing weird control characters===&lt;br /&gt;
Use ls with -i to see inode listing&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ls -bali&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Use find with -inum to get the filename and -exec to remove it&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
find . -inum &amp;lt;inode from ls listing&amp;gt; -exec rm -f {} \;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Run a local script on a remote host===&lt;br /&gt;
Doing it this way means we do not need to scp the shell over to the host before executing it!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ssh user@host &amp;#039;sh&amp;#039; &amp;lt; your_script.sh&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
First of all, this command is a redirection: your shell will open the file your_script.sh and feed it as input to the ssh command. ssh, in turn, will tunnel its stdin to the remote command, namely, sh instance. And sh without arguments reads its script from stdin. So we got sh instance, which is launched on remote host, but reads commands from your local file.&lt;br /&gt;
&lt;br /&gt;
===Get a list of running instances - but only those started by the current user===&lt;br /&gt;
This is the way I wanted to do it but there&amp;#039;s an issue. Where does that spare } character come from? Anyone?&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ps -ef | grep [p]mon | awk -v dbowner=$(id -un) &amp;#039;{ if ($1==dbowner) { gsub(/ora_pmon_/,&amp;quot;&amp;quot;,$NF); print $NF; } }&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
ps listing&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ ps -ef | grep [p]mon&lt;br /&gt;
  oracle 13304024        1   0   Jun 07      -  2:39 ora_pmon_reportk&lt;br /&gt;
  oracle 26018178        1   0   Jun 07      -  3:01 ora_pmon_dwh_perf&lt;br /&gt;
  oracle 29229432        1   0   Jun 07      -  2:30 ora_pmon_adso&lt;br /&gt;
 oraebso 18022994        1   0   Jun 07      -  2:38 ora_pmon_EBSO&lt;br /&gt;
  oracle 30278192        1   0   Jun 07      -  2:48 ora_pmon_owb112k&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Results of above command&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
reportk&lt;br /&gt;
dwh_perf&lt;br /&gt;
adso&lt;br /&gt;
}&lt;br /&gt;
owb112k&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Workaround 1. Send the ps listing to a file and work on it without pipes. Works but it&amp;#039;s a bit long-winded especially as we have to clean up afterwards.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ps -ef | grep [p]mon&amp;gt;/tmp/results.$$ 2&amp;gt;/dev/null; awk -v dbowner=$(id -un) &amp;#039;{ if ($1==dbowner) { gsub(/ora_pmon_/,&amp;quot;&amp;quot;,$NF); print $NF; } }&amp;#039; /tmp/results.$$; rm -f /tmp/results.$$&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Workaround 2. Don&amp;#039;t like the grep -v but until I find out where that } is coming from..&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ps -ef | grep [p]mon | awk -v dbowner=$(id -un) &amp;#039;{ if ($1==dbowner) { gsub(/ora_pmon_/,&amp;quot;&amp;quot;,$NF); print $NF; } }&amp;#039; | egrep -v &amp;#039;grep|}|ASM&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Return a list of Oracle databases running on a list of remote servers===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/ksh&lt;br /&gt;
&lt;br /&gt;
serverlist=`cat /home/tools/ini/system/oracle_servers | sort -n | tr &amp;quot;\n&amp;quot; &amp;quot; &amp;quot;`&lt;br /&gt;
&lt;br /&gt;
if [ -z &amp;quot;${serverlist}&amp;quot; ]&lt;br /&gt;
then&lt;br /&gt;
    echo &amp;quot;no servers found&amp;quot; &amp;amp;&amp;amp; exit 1&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
for server in ${serverlist}&lt;br /&gt;
do&lt;br /&gt;
    ssh ${server} &amp;quot;ps -ef | grep [o]ra_pmon_&amp;quot; &amp;gt;/tmp/${server}.dblist&lt;br /&gt;
done&lt;br /&gt;
&lt;br /&gt;
for server in ${serverlist}&lt;br /&gt;
do&lt;br /&gt;
    cat /tmp/${server}.dblist | awk -F_ -v SRV=${server} &amp;#039;BEGIN {print SRV &amp;quot;:&amp;quot;} {print $NF}&amp;#039; | tr &amp;quot;\n&amp;quot; &amp;quot; &amp;quot;&lt;br /&gt;
    echo&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Clever trick to check whether SQL output needs sending to someone===&lt;br /&gt;
Using an exit status from SQL*Plus back to the shell so we can decide what to do.  Nice one!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
tempfile=/tmp/audit_locked_accounts_$ORACLE_SID.txt&lt;br /&gt;
&lt;br /&gt;
# Start sqlplus and check for locked accounts&lt;br /&gt;
sqlplus -S &amp;quot;/ as sysdba&amp;quot; &amp;lt;&amp;lt; EOF &amp;gt; $tempfile&lt;br /&gt;
set pages 0&lt;br /&gt;
select &amp;#039;The following accounts were found to be unlocked and should not be&amp;#039;&lt;br /&gt;
from dual;&lt;br /&gt;
&lt;br /&gt;
def exit_status = 0&lt;br /&gt;
col xs new_value exit_status&lt;br /&gt;
&lt;br /&gt;
select username&lt;br /&gt;
,      account_status&lt;br /&gt;
,      1 as xs&lt;br /&gt;
from   dba_users&lt;br /&gt;
where  account_status != &amp;#039;LOCKED&amp;#039;&lt;br /&gt;
and    username in (&amp;#039;HR&amp;#039;, &amp;#039;SCOTT&amp;#039;, &amp;#039;OUTLN&amp;#039;, &amp;#039;MDSYS&amp;#039;, &amp;#039;CTXSYS&amp;#039;)&lt;br /&gt;
/&lt;br /&gt;
exit &amp;amp;exit_status&lt;br /&gt;
EOF&lt;br /&gt;
&lt;br /&gt;
# If the exit status of sqlplus was not 0 then we will send an email&lt;br /&gt;
if [ $? != 0 ]; then&lt;br /&gt;
    mail -s &amp;quot;Accounts Unlocked in $ORACLE_SID&amp;quot; oracle &amp;lt; $tempfile&lt;br /&gt;
fi&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Check RMAN logfiles for errors from cron every day===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
00 09 * * * /home/tools/scripts/oracle/dosh &amp;#039;find /home/tools/logs/rman -name &amp;quot;*online.log&amp;quot; -mtime -1 -exec sed -ne &amp;quot;/^RMAN-/,/^$/p&amp;quot; {} \\; -ls&amp;#039; | mailx&lt;br /&gt;
 -s &amp;#039;RMAN errors last night&amp;#039; stuart@domain.com&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/home/ibmtools/scripts/oracle/dosh &amp;#039;find /oracle/export -name &amp;quot;expdp*log&amp;quot; -mtime -1 -exec grep ORA- {} \; -ls&amp;#039; | mailx -s &amp;#039;Datapump errors for Baxter last night&amp;#039; stuart@domain.com&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===An alternative to getopts===&lt;br /&gt;
These methods have the advantage of allowing arguments of any length not just 1 character&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
countArgs=$#&lt;br /&gt;
while [[ $# -gt 0 ]]&lt;br /&gt;
do&lt;br /&gt;
    idx1=$($ECHO $1|$GREP &amp;quot;=&amp;quot;|wc -l)&lt;br /&gt;
    if [[ $idx1 -gt 0 ]]; then&lt;br /&gt;
        key=$($ECHO $1|$CUT -d &amp;#039;=&amp;#039; -f 1)&lt;br /&gt;
        value=$($ECHO $1|$CUT -d &amp;#039;=&amp;#039; -f 2)&lt;br /&gt;
    else&lt;br /&gt;
        key=$($ECHO $1|$CUT -d &amp;#039;=&amp;#039; -f 1)&lt;br /&gt;
        idx2=$($ECHO $1|$GREP &amp;quot;^-&amp;quot;|wc -l)&lt;br /&gt;
        if [[ $idx2 -eq 0 ]]; then&lt;br /&gt;
            $ECHO -e &amp;quot;\n ERROR: $1 is an unsupported argument passed to agentDeploy.sh.\n&amp;quot;  &lt;br /&gt;
            usage&lt;br /&gt;
            exit 1&lt;br /&gt;
        fi&lt;br /&gt;
    fi&lt;br /&gt;
&lt;br /&gt;
    case &amp;quot;$key&amp;quot; in&lt;br /&gt;
    -help)&lt;br /&gt;
        if [[ $upgradeFlag ]]; then&lt;br /&gt;
            upgradeUsage&lt;br /&gt;
        else&lt;br /&gt;
            freshUsage&lt;br /&gt;
        fi&lt;br /&gt;
        exit 0;;&lt;br /&gt;
    AGENT_BASE_DIR)&lt;br /&gt;
        agentBaseDir=$($ECHO $value|$SED &amp;#039;s/\/$//&amp;#039;)&lt;br /&gt;
        checkBaseFlag=TRUE;;&lt;br /&gt;
    OMS_HOST)&lt;br /&gt;
        omsHost=$value&lt;br /&gt;
        checkOMSHost=TRUE;;&lt;br /&gt;
    EM_UPLOAD_PORT)&lt;br /&gt;
        omsPort=$value&lt;br /&gt;
        checkOMSPort=TRUE;;&lt;br /&gt;
    AGENT_INSTANCE_HOME)&lt;br /&gt;
        instHome=$($ECHO $value | $SED &amp;#039;s/\/$//&amp;#039;);;&lt;br /&gt;
    AGENT_REGISTRATION_PASSWORD)&lt;br /&gt;
        pswd=$value;;&lt;br /&gt;
    s_encrSecurePwd)&lt;br /&gt;
        pswd=$value;;  &lt;br /&gt;
    RESPONSE_FILE)&lt;br /&gt;
        rspFlag=TRUE  &lt;br /&gt;
        rspLoc=$value;;&lt;br /&gt;
    OLD_AGENT_VERSION)&lt;br /&gt;
        oldAgentVersion=$value;;            &lt;br /&gt;
    OLDHOME)&lt;br /&gt;
        oldHome=$value;;    &lt;br /&gt;
    -debug)&lt;br /&gt;
        debugSwitch=TRUE;;&lt;br /&gt;
    -forceConfigure)&lt;br /&gt;
        forceFlag=TRUE;;&lt;br /&gt;
    -configOnly)&lt;br /&gt;
        configFlag=TRUE    &lt;br /&gt;
        validationFlag=TRUE;;&lt;br /&gt;
    -agentImageLocation)&lt;br /&gt;
        archiveLoc=$value&lt;br /&gt;
        checkArchiveFlag=TRUE;;&lt;br /&gt;
    -invPtrLoc) shift&lt;br /&gt;
        ptrLoc=$1;;&lt;br /&gt;
    -Upgrade)&lt;br /&gt;
        UpgradeFlag=TRUE&lt;br /&gt;
        validFlag=TRUE;;&lt;br /&gt;
    INVENTORY_LOCATION)&lt;br /&gt;
        validFlag=TRUE;;&lt;br /&gt;
    b_forceInstCheck)&lt;br /&gt;
        validFlag=TRUE&lt;br /&gt;
        forcefullFlag=TRUE;;&lt;br /&gt;
    -prereqOnly)&lt;br /&gt;
        validationFlag=TRUE&lt;br /&gt;
        prereqFlag=TRUE;;&lt;br /&gt;
    -executeRootsh)&lt;br /&gt;
        validFlag=TRUE;;&lt;br /&gt;
    *)  idx=$($ECHO $1|$GREP &amp;quot;^-&amp;quot;|wc -l)&lt;br /&gt;
        if [[ $idx -eq 0 ]]; then&lt;br /&gt;
            validFlag=TRUE&lt;br /&gt;
        else&lt;br /&gt;
            $ECHO -e &amp;quot;\n ERROR: Invalid argument $key passed.&amp;quot;&lt;br /&gt;
            usage&lt;br /&gt;
            exit 1          &lt;br /&gt;
        fi&lt;br /&gt;
    esac&lt;br /&gt;
    shift&lt;br /&gt;
done&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
another way - found in /etc/init.d/functions (daemon function) in Fedora&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    while [ &amp;quot;$1&amp;quot; != &amp;quot;${1##[-+]}&amp;quot; ]; do&lt;br /&gt;
        case $1 in&lt;br /&gt;
        &amp;#039;&amp;#039;)&lt;br /&gt;
            echo $&amp;quot;$0: Usage: daemon [+/-nicelevel] {program}&amp;quot; &amp;quot;[arg1]...&amp;quot;&lt;br /&gt;
            return 1&lt;br /&gt;
            ;;&lt;br /&gt;
        --check)&lt;br /&gt;
            base=$2&lt;br /&gt;
            gotbase=&amp;quot;yes&amp;quot;&lt;br /&gt;
            shift 2&lt;br /&gt;
            ;;&lt;br /&gt;
        --check=?*)&lt;br /&gt;
            base=${1#--check=}&lt;br /&gt;
            gotbase=&amp;quot;yes&amp;quot;&lt;br /&gt;
            shift&lt;br /&gt;
            ;;&lt;br /&gt;
        --user)&lt;br /&gt;
            user=$2&lt;br /&gt;
            shift 2&lt;br /&gt;
            ;;&lt;br /&gt;
        --user=?*)&lt;br /&gt;
            user=${1#--user=}&lt;br /&gt;
            shift&lt;br /&gt;
            ;;&lt;br /&gt;
        --pidfile)&lt;br /&gt;
            pid_file=$2&lt;br /&gt;
            shift 2&lt;br /&gt;
            ;;&lt;br /&gt;
        --pidfile=?*)&lt;br /&gt;
            pid_file=${1#--pidfile=}&lt;br /&gt;
            shift&lt;br /&gt;
            ;;&lt;br /&gt;
        --force)&lt;br /&gt;
            force=&amp;quot;force&amp;quot;&lt;br /&gt;
            shift&lt;br /&gt;
            ;;&lt;br /&gt;
        [-+][0-9]*)&lt;br /&gt;
            nice=&amp;quot;nice -n $1&amp;quot;&lt;br /&gt;
            shift&lt;br /&gt;
            ;;&lt;br /&gt;
        *)&lt;br /&gt;
            echo $&amp;quot;$0: Usage: daemon [+/-nicelevel] {program}&amp;quot; &amp;quot;[arg1]...&amp;quot;&lt;br /&gt;
            return 1&lt;br /&gt;
            ;;&lt;br /&gt;
      esac&lt;br /&gt;
    done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
another way - found in adstrtal.sh (middleware start script for EBS)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#&lt;br /&gt;
# Parse Arguments&lt;br /&gt;
#&lt;br /&gt;
&lt;br /&gt;
for nxtarg in $*&lt;br /&gt;
do&lt;br /&gt;
  arg=`echo $nxtarg | sed &amp;#039;s/^//&amp;#039;`&lt;br /&gt;
&lt;br /&gt;
  case $arg in&lt;br /&gt;
    -secureapps)    if test &amp;quot;$secureapps&amp;quot; = &amp;quot;&amp;quot; ; then&lt;br /&gt;
                       secureapps=$arg&lt;br /&gt;
                    else&lt;br /&gt;
                       echo &amp;quot;$0: Duplicate Argument passed : $arg&amp;quot;&lt;br /&gt;
                       usage&lt;br /&gt;
                    fi&lt;br /&gt;
                ;;&lt;br /&gt;
    -nodbchk)       if test &amp;quot;$nodbchk&amp;quot; = &amp;quot;&amp;quot; ; then&lt;br /&gt;
                       nodbchk=$arg&lt;br /&gt;
                    else&lt;br /&gt;
                       echo &amp;quot;$0: Duplicate Argument passed : $arg&amp;quot;&lt;br /&gt;
                       usage&lt;br /&gt;
                    fi&lt;br /&gt;
                ;;&lt;br /&gt;
    -nopromptmsg)   if test &amp;quot;$nopromptmsg&amp;quot; = &amp;quot;&amp;quot; ; then&lt;br /&gt;
                       nopromptmsg=$arg&lt;br /&gt;
                    else&lt;br /&gt;
                       echo &amp;quot;$0: Duplicate Argument passed : $arg&amp;quot;&lt;br /&gt;
                       usage&lt;br /&gt;
                    fi&lt;br /&gt;
                ;;&lt;br /&gt;
    *)              if test &amp;quot;$unpw&amp;quot; = &amp;quot;&amp;quot; ; then&lt;br /&gt;
                       unpw=$arg&lt;br /&gt;
                    else&lt;br /&gt;
                       echo &amp;quot;$0: Duplicate Argument passed : $arg&amp;quot;&lt;br /&gt;
                       usage&lt;br /&gt;
                    fi&lt;br /&gt;
  esac&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
and another in adautocfg.sh&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
for myarg in $*&lt;br /&gt;
do&lt;br /&gt;
&lt;br /&gt;
  arg=`echo $myarg | sed &amp;#039;s/^-//&amp;#039;`&lt;br /&gt;
  case $arg in&lt;br /&gt;
    appspass=*)&lt;br /&gt;
            appspass=`echo $arg | sed &amp;#039;s/appspass=//g&amp;#039;`&lt;br /&gt;
            shift&lt;br /&gt;
            ;;&lt;br /&gt;
    nocustom)&lt;br /&gt;
            myparams=&amp;quot;$myparams $arg&amp;quot;&lt;br /&gt;
            shift&lt;br /&gt;
            ;;&lt;br /&gt;
    noversionchecks)&lt;br /&gt;
            myparams=&amp;quot;$myparams $arg&amp;quot;&lt;br /&gt;
            shift&lt;br /&gt;
            ;;&lt;br /&gt;
    promptmsg=*)&lt;br /&gt;
            promptmsg=`echo $arg | sed &amp;#039;s/promptmsg=//g&amp;#039;`&lt;br /&gt;
            shift&lt;br /&gt;
            ;;&lt;br /&gt;
        *)  echo &amp;quot;$0: unrecognized action specified&amp;quot;&lt;br /&gt;
            exit 1&lt;br /&gt;
  esac&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Run a script on multiple servers===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/ksh&lt;br /&gt;
# ==============================================================================&lt;br /&gt;
# Name         : dosh   (Distributed Oracle SHell)&lt;br /&gt;
# Description  : Runs a command on all Oracle servers&lt;br /&gt;
#&lt;br /&gt;
# Parameters   : h - displays help&lt;br /&gt;
#                v - verbose (default, like all unix commands is silent)&lt;br /&gt;
#                c - command to be executed&lt;br /&gt;
#&lt;br /&gt;
# Example      : ./dosh -v -c &amp;#039;ls -al&amp;#039;&lt;br /&gt;
#&lt;br /&gt;
# Modification History&lt;br /&gt;
# ====================&lt;br /&gt;
# When      Who               What&lt;br /&gt;
# ========= ================= ==================================================&lt;br /&gt;
# 08-FEB-13 Stuart Barkley    Created&lt;br /&gt;
# ==============================================================================&lt;br /&gt;
&lt;br /&gt;
# --------------------------------------------------------------------------&lt;br /&gt;
# this list of servers is generated by the DBAMON tool so will be up to date&lt;br /&gt;
# --------------------------------------------------------------------------&lt;br /&gt;
serverfile=/home/ibmtools/etc/oracle/oracle_servers&lt;br /&gt;
[[ -z &amp;quot;${serverfile}&amp;quot; ]] &amp;amp;&amp;amp; echo &amp;quot;Server list ${serverfile} not found&amp;quot; &amp;amp;&amp;amp; exit 1&lt;br /&gt;
&lt;br /&gt;
serverlist=`cat ${serverfile} | sort -n | tr &amp;quot;\n&amp;quot; &amp;quot; &amp;quot;`&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
# -------------------------&lt;br /&gt;
# get the arguments, if any&lt;br /&gt;
# -------------------------&lt;br /&gt;
while getopts &amp;quot;hvc:&amp;quot; OPT&lt;br /&gt;
do&lt;br /&gt;
    case &amp;quot;$OPT&amp;quot; in&lt;br /&gt;
    h) echo &amp;quot;\nUsage: $0 [-v] [-h] -c &amp;#039;&amp;lt;command_to_be_executed_remotely&amp;gt;&amp;#039;\n&amp;quot;;&lt;br /&gt;
       exit;&lt;br /&gt;
       ;;&lt;br /&gt;
    v) VERBOSE=&amp;quot;Y&amp;quot;;&lt;br /&gt;
       ;;&lt;br /&gt;
    c) CMMND=$OPTARG;&lt;br /&gt;
       ;;&lt;br /&gt;
    *) echo &amp;quot;\nUsage: $0 [-v] [-h] -c &amp;#039;&amp;lt;command_to_be_executed_remotely&amp;gt;&amp;#039;\n&amp;quot;;&lt;br /&gt;
       exit;&lt;br /&gt;
       ;;&lt;br /&gt;
    esac&lt;br /&gt;
done&lt;br /&gt;
shift $((OPTIND-1))&lt;br /&gt;
VERBOSE=${VERBOSE:-&amp;quot;N&amp;quot;}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
# --------------------------------&lt;br /&gt;
# check we have required arguments&lt;br /&gt;
# --------------------------------&lt;br /&gt;
[[ -z $CMMND ]] &amp;amp;&amp;amp; echo &amp;quot;Enter command to be executed like this: $0 -c &amp;#039;ls -al&amp;#039;&amp;quot; &amp;amp;&amp;amp; exit 1&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
# ----------------------------&lt;br /&gt;
# loop over the remote servers&lt;br /&gt;
# ----------------------------&lt;br /&gt;
for server in ${serverlist}&lt;br /&gt;
do&lt;br /&gt;
    if [[ &amp;quot;$VERBOSE&amp;quot; == &amp;quot;Y&amp;quot; ]]; then&lt;br /&gt;
        echo ${server} `date +&amp;#039;%d-%b-%Y %H:%M:%S&amp;#039;`&lt;br /&gt;
        echo &amp;quot;------------------------------------&amp;quot;&lt;br /&gt;
        set -x&lt;br /&gt;
    fi&lt;br /&gt;
    ssh ${server} &amp;quot;$CMMND&amp;quot;&lt;br /&gt;
    set +x&lt;br /&gt;
    [[ &amp;quot;$VERBOSE&amp;quot; == &amp;quot;Y&amp;quot; ]] &amp;amp;&amp;amp; echo&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
to be investigated... this one might be cleverer than mine...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
tmpdir=${TMPDIR:-/tmp}/pssh.$$&lt;br /&gt;
count=0&lt;br /&gt;
while userhost; do&lt;br /&gt;
    ssh -n -o BatchMode=yes ${userhost} &amp;#039;uname -a&amp;#039; &amp;gt; ${tmpdir}/${userhost} 2&amp;gt;&amp;amp;1 &amp;amp;&lt;br /&gt;
    count=`expr $count + 1`&lt;br /&gt;
done &amp;lt; userhost.lst&lt;br /&gt;
while [ $count -gt 0 ]; do&lt;br /&gt;
    wait $pids&lt;br /&gt;
    count=`expr $count - 1`&lt;br /&gt;
done&lt;br /&gt;
echo &amp;quot;Output for hosts are in $tmpdir&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
improved version...&amp;lt;br /&amp;gt;&lt;br /&gt;
just escape double quotes and dollar signs...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/ksh&lt;br /&gt;
# ==============================================================================&lt;br /&gt;
# Name         : dosh   (Distributed Oracle SHell)&lt;br /&gt;
# Description  : Runs a command on all Oracle servers&lt;br /&gt;
#&lt;br /&gt;
# Parameters   : h - displays help&lt;br /&gt;
#                v - verbose (default, like all unix commands is silent)&lt;br /&gt;
#                c - command to be executed&lt;br /&gt;
#&lt;br /&gt;
# Example      : ./dosh -v -c &amp;#039;ls -al&amp;#039;&lt;br /&gt;
#&lt;br /&gt;
# Modification History&lt;br /&gt;
# ====================&lt;br /&gt;
# When      Who               What&lt;br /&gt;
# ========= ================= ==================================================&lt;br /&gt;
# 08-FEB-13 Stuart Barkley    Created&lt;br /&gt;
# 08-JUL-15 Stuart Barkley    Background execution mode&lt;br /&gt;
# ==============================================================================&lt;br /&gt;
# --------------------------------------------------------------------------&lt;br /&gt;
# this list of servers is generated by the DBAMON tool so will be up to date&lt;br /&gt;
# --------------------------------------------------------------------------&lt;br /&gt;
serverfile=/home/ibmtools/etc/oracle/oracle_servers&lt;br /&gt;
[[ -z &amp;quot;${serverfile}&amp;quot; ]] &amp;amp;&amp;amp; echo &amp;quot;Server list ${serverfile} not found&amp;quot; &amp;amp;&amp;amp; exit 1&lt;br /&gt;
&lt;br /&gt;
serverlist=`cat ${serverfile} | sort -n | tr &amp;quot;\n&amp;quot; &amp;quot; &amp;quot;`&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
# -------------------------&lt;br /&gt;
# get the arguments, if any&lt;br /&gt;
# -------------------------&lt;br /&gt;
while getopts &amp;quot;hbvc:&amp;quot; OPT&lt;br /&gt;
do&lt;br /&gt;
    case &amp;quot;$OPT&amp;quot; in&lt;br /&gt;
    h) echo &amp;quot;\nUsage: $0 [-b] [-v] [-h] -c &amp;#039;&amp;lt;command_to_be_executed_remotely&amp;gt;&amp;#039;\n&amp;quot;;&lt;br /&gt;
       exit;&lt;br /&gt;
       ;;&lt;br /&gt;
    b) BACKGROUND=&amp;quot;Y&amp;quot;;&lt;br /&gt;
       ;;&lt;br /&gt;
    v) VERBOSE=&amp;quot;Y&amp;quot;;&lt;br /&gt;
       ;;&lt;br /&gt;
    c) CMMND=$OPTARG;&lt;br /&gt;
       ;;&lt;br /&gt;
    *) echo &amp;quot;\nUsage: $0 [-b] [-v] [-h] -c &amp;#039;&amp;lt;command_to_be_executed_remotely&amp;gt;&amp;#039;\n&amp;quot;;&lt;br /&gt;
       exit;&lt;br /&gt;
       ;;&lt;br /&gt;
    esac&lt;br /&gt;
done&lt;br /&gt;
shift $((OPTIND-1))&lt;br /&gt;
VERBOSE=${VERBOSE:-&amp;quot;N&amp;quot;}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
# --------------------------------&lt;br /&gt;
# check we have required arguments&lt;br /&gt;
# --------------------------------&lt;br /&gt;
[[ -z $CMMND ]] &amp;amp;&amp;amp; echo &amp;quot;Enter command to be executed like this: $0 -c &amp;#039;ls -al&amp;#039;&amp;quot; &amp;amp;&amp;amp; exit 1&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
# ---------------------------------&lt;br /&gt;
# put the thing to be run in a file&lt;br /&gt;
# ---------------------------------&lt;br /&gt;
printf &amp;quot;%s\n&amp;quot; &amp;quot;$CMMND&amp;quot; &amp;gt; /tmp/dosh.$$&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
# ----------------------------&lt;br /&gt;
# loop over the remote servers&lt;br /&gt;
# ----------------------------&lt;br /&gt;
for server in ${serverlist}&lt;br /&gt;
do&lt;br /&gt;
    if [[ &amp;quot;$VERBOSE&amp;quot; == &amp;quot;Y&amp;quot; ]]; then&lt;br /&gt;
        printf &amp;quot;%s\n&amp;quot; ${server} `date +&amp;#039;%d-%b-%Y %H:%M:%S&amp;#039;`&lt;br /&gt;
        printf &amp;quot;%s\n&amp;quot; &amp;quot;------------------------------------&amp;quot;&lt;br /&gt;
        set -x&lt;br /&gt;
    fi&lt;br /&gt;
    scp -q /tmp/dosh.$$ ${server}:/tmp/&lt;br /&gt;
    if [[ &amp;quot;$BACKGROUND&amp;quot; == &amp;quot;Y&amp;quot; ]]; then&lt;br /&gt;
        ssh -n -o BatchMode=yes ${server} &amp;quot;ksh /tmp/dosh.$$; rm -f /tmp/dosh.$$&amp;quot;&amp;gt; /tmp/dosh_${server}.out 2&amp;gt;&amp;amp;1 &amp;amp;&lt;br /&gt;
    else&lt;br /&gt;
        ssh -n -o BatchMode=yes ${server} &amp;quot;ksh /tmp/dosh.$$; rm -f /tmp/dosh.$$&amp;quot;&lt;br /&gt;
    fi&lt;br /&gt;
    set +x&lt;br /&gt;
    [[ &amp;quot;$VERBOSE&amp;quot; == &amp;quot;Y&amp;quot; ]] &amp;amp;&amp;amp; echo&lt;br /&gt;
done&lt;br /&gt;
rm -f /tmp/dosh.$$&lt;br /&gt;
&lt;br /&gt;
[[ &amp;quot;$BACKGROUND&amp;quot; == &amp;quot;Y&amp;quot; ]] &amp;amp;&amp;amp; printf &amp;quot;%s\n&amp;quot; &amp;quot;Type &amp;#039;ls -altr /tmp/dosh*out&amp;#039; to see output from the commands&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===How can a shell script find out what directory it is in?===&lt;br /&gt;
basename $0 does not always give the desired answer (might give &amp;quot;./&amp;quot;!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
DIR=&amp;quot;$(cd &amp;quot;$(dirname &amp;quot;$0&amp;quot;)&amp;quot; &amp;amp;&amp;amp; pwd)&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Array processing===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
array=(1 2 3)&lt;br /&gt;
unset array[2]&lt;br /&gt;
echo ${array[2]}          # null&lt;br /&gt;
indices=(${!array[@]})    # create an array of the indices of &amp;quot;array&amp;quot;&lt;br /&gt;
size=${#indices[@]}       # the size of &amp;quot;array&amp;quot; is the number of indices into it&lt;br /&gt;
size=${#array[@]}         # same&lt;br /&gt;
echo ${array[@]: -1}      # you can use slices to get array elements, -1 is the last one, etc.&lt;br /&gt;
for element in ${array[@]}; do    # iterate over the array without an index&lt;br /&gt;
&lt;br /&gt;
for index in ${indices[@]}        # iterate over the array WITH an index&lt;br /&gt;
do&lt;br /&gt;
    echo &amp;quot;Index: ${index}, Element: ${array[index]}&amp;quot;&lt;br /&gt;
done&lt;br /&gt;
&lt;br /&gt;
for index in ${!array[@]}         # iterate over the array WITH an index, directly&lt;br /&gt;
&lt;br /&gt;
array+=(&amp;quot;new element&amp;quot;)    # append a new element without referring to an index&lt;br /&gt;
((counter++))             # shorter than ((counter=counter+1)) or ((counter+=1))&lt;br /&gt;
if [[ $var == 3 ]]        # you can use the more &amp;quot;natural&amp;quot; comparison operators inside double square brackets&lt;br /&gt;
while [[ $var &amp;lt; 11 ]]     # another example&lt;br /&gt;
echo ${array[${index}-1]  # math inside an array subscript&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Send an email by talking directly to an smtp server===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
telnet smtp.domain.com 25 &amp;lt;&amp;lt;EOTXT&amp;gt;&amp;gt;/tmp/smtp.log&lt;br /&gt;
HELO me.domain.com&lt;br /&gt;
MAIL FROM:&amp;lt;stuart@domain.com&amp;gt;&lt;br /&gt;
RCPT TO:&amp;lt;anne@domain.com&amp;gt;&lt;br /&gt;
DATA&lt;br /&gt;
From: Stuart &amp;lt;stuart@domain.com&amp;gt;&lt;br /&gt;
To: Anne &amp;lt;anne@domain.com&amp;gt;&lt;br /&gt;
Subject: testing smtp email&lt;br /&gt;
&lt;br /&gt;
Hello, this should appear in the body&lt;br /&gt;
.&lt;br /&gt;
QUIT&lt;br /&gt;
EOTXT&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Send an email by talking directly to an smtp server via file descriptor (no telnet! this time), adding authentication===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
&lt;br /&gt;
#&lt;br /&gt;
# mail.sh&lt;br /&gt;
#&lt;br /&gt;
# 2008 - Mike Golvach - eggi@comcast.net&lt;br /&gt;
# 2010 - Rayber&lt;br /&gt;
#&lt;br /&gt;
# Creative Commons Attribution-Noncommercial-Share Alike 3.0 United States License&lt;br /&gt;
#&lt;br /&gt;
&lt;br /&gt;
if [ $# -ne 7 ]&lt;br /&gt;
then&lt;br /&gt;
echo &amp;quot;Usage: $0 FromAdress ToAdress Domain MailServer MailTextFile AuthEmail AuthPass&amp;quot;&lt;br /&gt;
exit 1&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
from=$1&lt;br /&gt;
to=$2&lt;br /&gt;
domain=$3&lt;br /&gt;
mailserver=$4&lt;br /&gt;
mailtext=$5&lt;br /&gt;
authemail=`echo $6|openssl enc -base64|awk &amp;#039;sub(&amp;quot;..$&amp;quot;, &amp;quot;&amp;quot;)&amp;#039;`&lt;br /&gt;
authpass=`echo $7|openssl enc -base64|awk &amp;#039;sub(&amp;quot;..$&amp;quot;, &amp;quot;&amp;quot;)&amp;#039;`&lt;br /&gt;
&lt;br /&gt;
if [ ! -f $mailtext ]&lt;br /&gt;
then&lt;br /&gt;
echo &amp;quot;Cannot find your mail text file. Exiting...&amp;quot;&lt;br /&gt;
exit 1&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
exec 9&amp;lt;&amp;gt;/dev/tcp/$mailserver/25&lt;br /&gt;
echo &amp;quot;HELO $domain&amp;quot; &amp;gt;&amp;amp;9&lt;br /&gt;
read -r temp &amp;lt;&amp;amp;9&lt;br /&gt;
echo &amp;quot;$temp&amp;quot;&lt;br /&gt;
echo &amp;quot;auth login&amp;quot; &amp;gt;&amp;amp;9&lt;br /&gt;
read -r temp &amp;lt;&amp;amp;9&lt;br /&gt;
echo &amp;quot;$authemail&amp;quot; &amp;gt;&amp;amp;9&lt;br /&gt;
read -r temp &amp;lt;&amp;amp;9&lt;br /&gt;
echo &amp;quot;$authpass&amp;quot; &amp;gt;&amp;amp;9&lt;br /&gt;
read -r temp &amp;lt;&amp;amp;9&lt;br /&gt;
echo &amp;quot;Mail From: $from&amp;quot; &amp;gt;&amp;amp;9&lt;br /&gt;
read -r temp &amp;lt;&amp;amp;9&lt;br /&gt;
echo &amp;quot;$temp&amp;quot;&lt;br /&gt;
echo &amp;quot;Rcpt To: $to&amp;quot; &amp;gt;&amp;amp;9&lt;br /&gt;
read -r temp &amp;lt;&amp;amp;9&lt;br /&gt;
echo &amp;quot;$temp&amp;quot;&lt;br /&gt;
echo &amp;quot;Data&amp;quot; &amp;gt;&amp;amp;9&lt;br /&gt;
read -r temp &amp;lt;&amp;amp;9&lt;br /&gt;
echo &amp;quot;$temp&amp;quot;&lt;br /&gt;
cat $mailtext &amp;gt;&amp;amp;9&lt;br /&gt;
echo &amp;quot;.&amp;quot; &amp;gt;&amp;amp;9&lt;br /&gt;
read -r temp &amp;lt;&amp;amp;9&lt;br /&gt;
echo &amp;quot;$temp&amp;quot;&lt;br /&gt;
echo &amp;quot;quit&amp;quot; &amp;gt;&amp;amp;9&lt;br /&gt;
read -r temp &amp;lt;&amp;amp;9&lt;br /&gt;
echo &amp;quot;$temp&amp;quot;&lt;br /&gt;
9&amp;gt;&amp;amp;-&lt;br /&gt;
9&amp;lt;&amp;amp;-&lt;br /&gt;
echo &amp;quot;All Done Sending Email. See above for errors&amp;quot;&lt;br /&gt;
exit 0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== rsync examples===&lt;br /&gt;
Also see [[Distribute files to multiple servers using rsync and ssh]]&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/sh&lt;br /&gt;
ssh  &amp;lt;remote_host&amp;gt; &amp;#039;/bin/mkdir -p /etc /etc/rc.config.d /etc/security /etc/mail&amp;#039;&lt;br /&gt;
rsync --rsync-path /usr/bin/rsync -Liprogtz --out-format=%f%L  /etc/passwd /etc/passwd.post /etc/group /etc/hosts /etc/services /etc/resolv.conf /etc/exclude.rootvg &amp;lt;remote_host&amp;gt;:/etc&lt;br /&gt;
rsync --rsync-path /usr/bin/rsync -Liprogtz --out-format=%f%L  /etc/hosts.allow.xcat &amp;lt;remote_host&amp;gt;:/etc/hosts.allow&lt;br /&gt;
rsync --rsync-path /usr/bin/rsync -Liprogtz --out-format=%f%L  /etc/rc.config.d/sap &amp;lt;remote_host&amp;gt;:/etc/rc.config.d&lt;br /&gt;
rsync --rsync-path /usr/bin/rsync -Liprogtz --out-format=%f%L  /etc/security/group /etc/security/limits /etc/security/login.cfg /etc/security/passwd /etc/security/user &amp;lt;remote_host&amp;gt;:/etc/security&lt;br /&gt;
rsync --rsync-path /usr/bin/rsync -Liprogtz --out-format=%f%L  /etc/mail/sendmail.cf &amp;lt;remote_host&amp;gt;:/etc/mail&lt;br /&gt;
&lt;br /&gt;
rsync -av --progress /home/ibmtools/scripts/oracle/* benouerp07:/home/ibmtools/scripts/oracle/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Handy aliases===&lt;br /&gt;
Strip out comments and blank lines from a file&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alias strip=&amp;#039;grep -Ev &amp;#039;\&amp;#039;&amp;#039;^(#|$)&amp;#039;\&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Does a ps and a grep&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alias psg=&amp;#039;ps -ef | grep -v $$ | grep -i &amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Getting a decent listing of filesystem space available. It is ordered such that the filesystems with no space left are at the end.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
OS=$(uname -s)&lt;br /&gt;
[[ &amp;quot;$OS&amp;quot; == &amp;quot;SunOS&amp;quot; ]] &amp;amp;&amp;amp; alias dfg=&amp;#039;df -h|sed -e &amp;#039;1d&amp;#039;|sort -n -k5|awk &amp;#039;\&amp;#039;&amp;#039; BEGIN {printf(&amp;quot;%-35s%-10s%-10s%-6s%-30s\n&amp;quot;,&amp;quot;Filesystem&amp;quot;,&amp;quot;Total&amp;quot;,&amp;quot;Free&amp;quot;,&amp;quot;%Used&amp;quot;,&amp;quot;Mounted on&amp;quot;)} {printf(&amp;quot;%-35s%-10s%-10s%-6s%-30s\n&amp;quot;,$1,$2,$4,$5,$6)}&amp;#039;\&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
[[ &amp;quot;$OS&amp;quot; == &amp;quot;AIX&amp;quot; ]]   &amp;amp;&amp;amp; alias dfg=&amp;#039;df -g|sed -e &amp;#039;1d&amp;#039;|sort -n -k4|awk &amp;#039;\&amp;#039;&amp;#039; BEGIN {printf(&amp;quot;%-35s%-10s%-10s%-6s%-30s\n&amp;quot;,&amp;quot;Filesystem&amp;quot;,&amp;quot;Total GB&amp;quot;,&amp;quot;Free&amp;quot;,&amp;quot;%Used&amp;quot;,&amp;quot;Mounted on&amp;quot;)} {printf(&amp;quot;%-35s%-10s%-10s%-6s%-30s\n&amp;quot;,$1,$2,$3,$4,$7)}&amp;#039;\&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
A handy way of listing subdirectories and their files&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alias filetree=&amp;quot;find . -print | sed -e &amp;#039;s;[^/]*/;|____;g;s;____|; |;g&amp;#039;&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Watch progress of a copy&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alias cpProgress=&amp;quot;rsync --progress -ravz&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Reboots Linksys router&amp;lt;pre&amp;gt;&lt;br /&gt;
alias rebootlinksys=&amp;quot;curl -u &amp;#039;admin:password&amp;#039; &amp;#039;http://192.168.1.2/setup.cgi?todo=reboot&amp;#039;&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Nice one for bash. Colour codes the prompt depending on the outcome of the previous command&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
bash_prompt_command()&lt;br /&gt;
{&lt;br /&gt;
    RTN=$?&lt;br /&gt;
    prevCmd=$(prevCmd $RTN)&lt;br /&gt;
}&lt;br /&gt;
PROMPT_COMMAND=bash_prompt_command&lt;br /&gt;
prevCmd()&lt;br /&gt;
{&lt;br /&gt;
    if [ $1 == 0 ] ; then&lt;br /&gt;
        echo $GREEN&lt;br /&gt;
    else&lt;br /&gt;
        echo $RED&lt;br /&gt;
    fi&lt;br /&gt;
}&lt;br /&gt;
if [ $(tput colors) -gt 0 ] ; then&lt;br /&gt;
    RED=$(tput setaf 1)&lt;br /&gt;
    GREEN=$(tput setaf 2)&lt;br /&gt;
    RST=$(tput op)&lt;br /&gt;
fi&lt;br /&gt;
export PS1=&amp;quot;\[\e[36m\]\u.\h.\W\[\e[0m\]\[\$prevCmd\]&amp;gt;\[$RST\]&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Mmmm, to be looked into. Executes remote commands on a unix box using curl.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#/bin/sh&lt;br /&gt;
#&lt;br /&gt;
# WAG320N-HACK&lt;br /&gt;
# Ver. 1.0&lt;br /&gt;
# 12/09/2010&lt;br /&gt;
#&lt;br /&gt;
# This program is free software: you can redistribute it and/or modify&lt;br /&gt;
# it under the terms of the GNU General Public License as published by&lt;br /&gt;
# the Free Software Foundation, either version 3 of the License, or&lt;br /&gt;
# (at your option) any later version.&lt;br /&gt;
#&lt;br /&gt;
# This program is distributed in the hope that it will be useful,&lt;br /&gt;
# but WITHOUT ANY WARRANTY; without even the implied warranty of&lt;br /&gt;
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the&lt;br /&gt;
# GNU General Public License for more details.&lt;br /&gt;
#&lt;br /&gt;
# You should have received a copy of the GNU General Public License&lt;br /&gt;
# along with this program.  If not, see &amp;lt;http://www.gnu.org/licenses/&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
# Set username and password in the form of &amp;quot;username:password&amp;quot;&lt;br /&gt;
# example: &amp;quot;admin:admin&amp;quot;&lt;br /&gt;
my_access=&amp;quot;admin:admin&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Parameters test&lt;br /&gt;
if [ -z &amp;quot;$1&amp;quot; ]&lt;br /&gt;
then&lt;br /&gt;
  echo &amp;quot;wag320n-hack.sh: missing remote command&amp;quot;&lt;br /&gt;
  echo &amp;quot;usage: wag320n-hack.sh &amp;lt;remote command&amp;gt;&amp;quot;&lt;br /&gt;
  echo &amp;quot;example: wag320n-hack.sh /bin/ls -la /usr/sbin&amp;quot;&lt;br /&gt;
  echo &amp;quot;Note: always use full path&amp;quot;&lt;br /&gt;
  echo &amp;quot;&amp;quot;&lt;br /&gt;
  echo &amp;quot;wag320n-hack.sh - Ver. 1.0 - 12/09/2010&amp;quot;&lt;br /&gt;
  echo &amp;quot;Licensed under GPL V. 3&amp;quot;&lt;br /&gt;
  echo &amp;quot;&amp;quot;&lt;br /&gt;
  exit 0&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
# Get the command&lt;br /&gt;
my_command=&amp;quot;ping_size=&amp;quot;&amp;#039;$(&amp;#039;&amp;quot;$@&amp;quot;&amp;#039; 1&amp;gt;&amp;amp;2)&amp;#039;&lt;br /&gt;
&lt;br /&gt;
curl -s -G -u &amp;quot;$my_access&amp;quot; --data-urlencode &amp;#039;todo=ping_test&amp;#039; --data-urlencode &amp;#039;this_file=Diagnostics.htm&amp;#039; --data-urlencode &amp;#039;next_file=Ping.htm&amp;#039; --data-urlencode &amp;#039;c4_ping_ipaddr=192.168.1.1&amp;#039; --data-urlencode &amp;#039;ping_timeout=5000&amp;#039; --data-urlencode &amp;#039;ping_interval=1000&amp;#039; --data-urlencode &amp;#039;ping_number=1&amp;#039; --data-urlencode &amp;quot;$my_command&amp;quot; http://192.168.1.1/setup.cgi | sed -e &amp;#039;/HTTP\/1.0 200 OK/q&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===How to configure SSH with public/private keys===&lt;br /&gt;
* [http://www.unixpeople.com/HOWTO/configuring.ssh.html unixpeople.com]&lt;br /&gt;
===Use SSH config file===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Host server10&lt;br /&gt;
  Hostname 1.2.3.4&lt;br /&gt;
  IdentityFile ~/.ssh/id_dsa&lt;br /&gt;
  user foobar&lt;br /&gt;
  Port 30000&lt;br /&gt;
  ForwardX11Trusted yes&lt;br /&gt;
  TCPKeepAlive yes&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
then just connect using&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ssh server10&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===A decent sed tutorial===&lt;br /&gt;
From [http://www.grymoire.com/Unix/Sed.html grymoire.com]&lt;br /&gt;
===A decent korn/bash shell tutorial===&lt;br /&gt;
From [http://www.dartmouth.edu/~rc/classes/ksh/print_pages.shtml dartmouth.edu]&lt;br /&gt;
Reproduced here just in case it disappears!&lt;br /&gt;
[[Advanced shell scripting]]&lt;br /&gt;
&lt;br /&gt;
===trap===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
     Example Handling Traps With ksh - Discussion of the kill command&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
EXAMPLE TEMPLATE:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
PRODUCT:    HP-UX 11iV1 Version B.11.11&lt;br /&gt;
            HP Tru64 V5.1B PK4&lt;br /&gt;
            Sun/Solaris SunOS V5.8&lt;br /&gt;
            Linux 2.6 kernel&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
COMPONENT:  ksh&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
SOURCE:     Philippe Vouters&lt;br /&gt;
            Fontainebleau/France&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
LOW COST HIGH-TECH PRODUCTS:  http://techno-star.fr&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
OVERVIEW:&lt;br /&gt;
&lt;br /&gt;
The ksh script below shows how to eventually handle traps in the situation &lt;br /&gt;
where someone might try to kill a script by killing individual commands run &lt;br /&gt;
by that script or the entire process group a script is running in. The kill &lt;br /&gt;
command (usually a shell builtin) may be used to send a signal to a process &lt;br /&gt;
group (with the -&amp;lt;pid&amp;gt; syntax) or an individual process. The example ksh &lt;br /&gt;
script below runs /bin/sleep as the foreground process, the example ksh &lt;br /&gt;
scripts immediately returns when the /bin/sleep process has terminated. Most &lt;br /&gt;
signals sent to the shell are ignored until after the foreground process &lt;br /&gt;
terminates. This is in order to avoid creating zombie processes. Therefore a &lt;br /&gt;
kill &amp;lt;pid&amp;gt; on the example ksh script waits for the termination of the &lt;br /&gt;
/bin/sleep process.&lt;br /&gt;
&lt;br /&gt;
The status value $? in the trap refers to the exit status of the command to run &lt;br /&gt;
and therefore is the exit status of the /bin/sleep process. The called function &lt;br /&gt;
in the trap handler shows how to correctly examine the effect of the kill &lt;br /&gt;
command on the shell or it&amp;#039;s children.&lt;br /&gt;
&lt;br /&gt;
To examine the value of $? in a trap handler means that you must understand what&lt;br /&gt;
it can be set and how different signals delivered to either the shell or the &lt;br /&gt;
foreground process (or the process group) might affect the value of $?.&lt;br /&gt;
&lt;br /&gt;
The example shell script prints $? using echo but it does not perform tests on &lt;br /&gt;
the value of $?. For a complete solution when attempting to trap signals in a &lt;br /&gt;
shell you would also need code that examined the value of $? after the &lt;br /&gt;
foreground process had completed.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*** CAUTION ***&lt;br /&gt;
&lt;br /&gt;
This sample script has been tested using HP-UX B.11.11, HP Tru64 V5.1B PK4, &lt;br /&gt;
SunOS V5.8 and Fedora Core 4 (homed version of Red Hat Linux).  However, we&lt;br /&gt;
cannot guarantee its effectiveness because of the possibility of error in &lt;br /&gt;
transmitting or implementing it. It is meant to be used as a template for &lt;br /&gt;
writing your own scripts, and may require modification for use on your system. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
SCRIPT NOTES:&lt;br /&gt;
&lt;br /&gt;
To notice that the ksh script and /bin/sleep share the same process group&lt;br /&gt;
identifier (PGID), issue the following commands:&lt;br /&gt;
&lt;br /&gt;
[philippe@victor ~]$ who&lt;br /&gt;
philippe :0           Jan 10 10:16&lt;br /&gt;
philippe pts/1        Jan 10 21:30 (:0.0)&lt;br /&gt;
philippe pts/2        Jan 10 21:30 (:0.0)&lt;br /&gt;
[philippe@victor ~]$ tty&lt;br /&gt;
/dev/pts/1&lt;br /&gt;
[philippe@victor ~]$ ps -j -t pts/2&lt;br /&gt;
  PID  PGID   SID TTY          TIME CMD&lt;br /&gt;
11072 11072 11072 pts/2    00:00:00 bash&lt;br /&gt;
11113 11113 11072 pts/2    00:00:00 ksh&lt;br /&gt;
11116 11113 11072 pts/2    00:00:00 sleep&lt;br /&gt;
&lt;br /&gt;
In this case sending kill -INT -11113 will send SIGINT to the process group &lt;br /&gt;
11113. Both of the ksh and sleep processes are contained within this process &lt;br /&gt;
group.&lt;br /&gt;
&lt;br /&gt;
Important Note:&lt;br /&gt;
&lt;br /&gt;
On HP-UX, you have to $ export UNIX95=1 in order to be able to use the&lt;br /&gt;
-j option of the ps command.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
SCRIPT:&lt;br /&gt;
&lt;br /&gt;
                             COPYRIGHT (C) 2005 BY&lt;br /&gt;
                              HEWLETT-PACKARD COMPANY&lt;br /&gt;
                                ALL RIGHTS RESERVED.&lt;br /&gt;
&lt;br /&gt;
     THIS SOFTWARE IS FURNISHED UNDER A LICENSE AND MAY BE USED AND COPIED&lt;br /&gt;
     ONLY IN ACCORDANCE WITH THE TERMS OF SUCH LICENSE AND WITH THE INCLUSION&lt;br /&gt;
     OF THE ABOVE COPYRIGHT NOTICE.  THIS SOFTWARE OR ANY OTHER COPIES&lt;br /&gt;
     THEREOF MAY NOT BE PROVIDED OR OTHERWISE MADE AVAILABLE TO ANY OTHER&lt;br /&gt;
     PERSON.  NO TITLE TO AND OWNERSHIP OF THE SOFTWARE IS HEREBY TRANSFERRED.&lt;br /&gt;
&lt;br /&gt;
     THE INFORMATION IN THIS SOFTWARE IS SUBJECT TO CHANGE WITHOUT NOTICE AND&lt;br /&gt;
     SHOULD NOT BE CONSTRUED AS A COMMITMENT BY HEWLETT-PACKARD COMPANY.&lt;br /&gt;
&lt;br /&gt;
     HP ASSUMES NO RESPONSIBILITY FOR THE USE OR RELIABILITY OF ITS&lt;br /&gt;
     SOFTWARE ON EQUIPMENT THAT IS NOT SUPPLIED BY HP.&lt;br /&gt;
&lt;br /&gt;
     NO RESPONSIBILITY IS ASSUMED FOR THE USE OR RELIABILITY OF SOFTWARE&lt;br /&gt;
     ON EQUIPMENT THAT IS NOT SUPPLIED BY HEWLETT-PACKARD COMPANY.&lt;br /&gt;
&lt;br /&gt;
     SUPPORT FOR THIS SOFTWARE IS NOT COVERED UNDER ANY HP SOFTWARE&lt;br /&gt;
     PRODUCT SUPPORT CONTRACT, BUT MAY BE PROVIDED UNDER THE TERMS OF THE&lt;br /&gt;
     CONSULTING AGREEMENT UNDER WHICH THIS SOFTWARE WAS DEVELOPED.&lt;br /&gt;
&lt;br /&gt;
#!/bin/ksh&lt;br /&gt;
function handle_signal&lt;br /&gt;
{&lt;br /&gt;
        print -n &amp;quot;pid $$ recieved $2 &amp;quot;&lt;br /&gt;
        if [[ $1 = 0 ]];then&lt;br /&gt;
            print but foreground command ended successfully&lt;br /&gt;
        else&lt;br /&gt;
                if [[ $1 = $3 ]];then&lt;br /&gt;
                    print and so did the last foreground command&lt;br /&gt;
                else&lt;br /&gt;
                    print -n &amp;quot;and the exit status of the last foreground &amp;quot;&lt;br /&gt;
                    print command was $1&lt;br /&gt;
                fi&lt;br /&gt;
        fi&lt;br /&gt;
        # Kill our process group and then ourselves with SIGTERM, giving a &lt;br /&gt;
        # pid of 0 sends the signal to our process group. Killing the process&lt;br /&gt;
        # group should kill us as well, this assumes that SIGTERM is not &lt;br /&gt;
        # handled by any process in the process group.&lt;br /&gt;
        #&lt;br /&gt;
        # This code could be replaced with an exit with an exit value that&lt;br /&gt;
        # would indicate what the problem was to the caller. That is replace &lt;br /&gt;
        # these two lines with:&lt;br /&gt;
        #&lt;br /&gt;
        # exit $3&lt;br /&gt;
        #&lt;br /&gt;
        # or a specific exit code could be used.&lt;br /&gt;
        #&lt;br /&gt;
        kill -TERM 0&lt;br /&gt;
        kill -TERM $$&lt;br /&gt;
        }&lt;br /&gt;
OS=$(uname -a | awk &amp;#039;{print $1}&amp;#039;)&lt;br /&gt;
if [[ &amp;quot;$OS&amp;quot; = &amp;quot;Linux&amp;quot; ]]; then&lt;br /&gt;
    offset=256&lt;br /&gt;
elif [[ (&amp;quot;$OS&amp;quot; = &amp;quot;HP-UX&amp;quot;) || &lt;br /&gt;
        (&amp;quot;$OS&amp;quot; = &amp;quot;SunOS&amp;quot;) || &lt;br /&gt;
        (&amp;quot;$OS&amp;quot; = &amp;quot;OSF1&amp;quot;) ]]; then&lt;br /&gt;
   offset=128&lt;br /&gt;
fi&lt;br /&gt;
trap &amp;#039;RC=$?; handle_signal $RC SIGINT $offset+2&amp;#039; INT&lt;br /&gt;
trap &amp;#039;RC=$?; handle_signal $RC SIGQUIT $offset+3&amp;#039; QUIT&lt;br /&gt;
/bin/sleep 20&lt;br /&gt;
echo $?&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===DNS not working===&lt;br /&gt;
Ping to an IP address works&lt;br /&gt;
 ping 74.125.136.103&lt;br /&gt;
but this doesn&amp;#039;t&lt;br /&gt;
 ping www.google.com&lt;br /&gt;
&lt;br /&gt;
Check resolv.conf&lt;br /&gt;
 cat /etc/resolv.conf&lt;br /&gt;
 nameserver 95.130.132.17&lt;br /&gt;
 nameserver 95.130.132.18&lt;br /&gt;
I had changed internet provider and forgot to update this. Just to set it to the router address and let that do the resolution&lt;br /&gt;
 nameserver 192.168.1.1&lt;br /&gt;
&lt;br /&gt;
===File descriptors===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
exec 3&amp;lt;&amp;gt; /tmp/foo  #open fd 3 for r/w&lt;br /&gt;
echo &amp;quot;test&amp;quot; &amp;gt;&amp;amp;3&lt;br /&gt;
exec 3&amp;gt;&amp;amp;- #close fd 3.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
exec 3&amp;lt;&amp;gt; myfile.txt&lt;br /&gt;
while read line &amp;lt;&amp;amp;3&lt;br /&gt;
do {&lt;br /&gt;
  echo &amp;quot;$line&amp;quot;&lt;br /&gt;
  (( Lines++ ));                   #  Incremented values of this variable&lt;br /&gt;
                                   #+ accessible outside loop.&lt;br /&gt;
                                   #  No subshell, no problem.&lt;br /&gt;
}&lt;br /&gt;
done&lt;br /&gt;
exec 3&amp;gt;&amp;amp;-&lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;Number of lines read = $Lines&amp;quot;     # 8&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Mmm. See our output and also tee it to a log file!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
&lt;br /&gt;
echo hello&lt;br /&gt;
&lt;br /&gt;
if test -t 1; then&lt;br /&gt;
    # Stdout is a terminal.&lt;br /&gt;
    exec &amp;gt;log&lt;br /&gt;
else&lt;br /&gt;
    # Stdout is not a terminal.&lt;br /&gt;
    npipe=/tmp/$$.tmp&lt;br /&gt;
    trap &amp;quot;rm -f $npipe&amp;quot; EXIT&lt;br /&gt;
    mknod $npipe p&lt;br /&gt;
    tee &amp;lt;$npipe log &amp;amp;&lt;br /&gt;
    exec 1&amp;gt;&amp;amp;-&lt;br /&gt;
    exec 1&amp;gt;$npipe&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
echo goodbye&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Create new image with kvm===&lt;br /&gt;
Ref: http://www.cyberciti.biz/faq/kvm-virtualization-in-redhat-centos-scientific-linux-6/&amp;lt;br /&amp;gt;&lt;br /&gt;
Build an empty space for a CentOS virtual machine&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
qemu-img create -f qcow2 centos.img 12G&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Tried creating image with&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo virt-install -n CentOS --description &amp;quot;Trying out CentOS&amp;quot; --ram=1024 --vcpus=1 --cpu host --hvm --cdrom /home/bey9at77/Downloads/c6-x86_64-20130910-1.qcow2 --graphics vnc --disk path=/var/lib/libvirt/images/centos.img,bus=virtio,size=10&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
gives error&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Starting install...&lt;br /&gt;
Allocating &amp;#039;centos.img&amp;#039;                                                                                                                                                                                               |  10 GB     00:00     &lt;br /&gt;
ERROR    internal error Process exited while reading console log output: char device redirected to /dev/pts/1&lt;br /&gt;
qemu-kvm: -drive file=/home/bey9at77/Downloads/c6-x86_64-20130910-1.qcow2.bz2,if=none,media=cdrom,id=drive-ide0-1-0,readonly=on,format=raw: could not open disk image /home/bey9at77/Downloads/c6-x86_64-20130910-1.qcow2: Permission denied&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===rpm / yum commands===&lt;br /&gt;
====Install an RPM Package====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rpm -ivh pidgin-2.7.9-5.el6.2.i686.rpm&lt;br /&gt;
&lt;br /&gt;
-i - install&lt;br /&gt;
-v - verbose&lt;br /&gt;
-h - print progress hashes&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Check dependencies of RPM Package before Installing====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rpm -qpR BitTorrent-5.2.2-1-Python2.4.noarch.rpm&lt;br /&gt;
&lt;br /&gt;
-q - query&lt;br /&gt;
-p - list package capabilities&lt;br /&gt;
-R - list dependent package capabilities&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Install RPM Package with all dependencies====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
yum install BitTorrent-5.2.2-1-Python2.4.noarch.rpm&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Install RPM Package with all dependencies (when RPM has been downloaded to local machine)====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
yum localinstall BitTorrent-5.2.2-1-Python2.4.noarch.rpm&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Force Install a RPM Package without dependencies====&lt;br /&gt;
Package will not work if dependencies are required&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rpm -ivh --nodeps BitTorrent-5.2.2-1-Python2.4.noarch.rpm&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Check an Installed RPM Package====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rpm -q BitTorrent&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====List all files of an installed RPM package====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rpm -ql BitTorrent&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====List All Installed RPM Packages====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rpm -qa&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Query information about an installed RPM package====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rpm -qi vsftpd&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Query information about a not yet installed RPM package====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rpm -qip sqlbuddy-1.3.3-1.noarch.rpm&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====(Forcibly) Remove an RPM Package====&lt;br /&gt;
Use package name (as seen in -qi above), not full name&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rpm -ev (--nodeps) vsftpd&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Query a file that was installed as part of an RPM Package (which package contained this file)====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rpm -qf /usr/bin/htpasswd&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Verify an RPM package====&lt;br /&gt;
Compares information of installed files of the package against the rpm database&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rpm -Vp sqlbuddy-1.3.3-1.noarch.rpm&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Rebuild corrupted RPM database====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cd /var/lib&lt;br /&gt;
rm __db*&lt;br /&gt;
rpm --rebuilddb&lt;br /&gt;
rpmdb_verify Packages&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Install rpmforge repository===&lt;br /&gt;
* Download rpmforge-release-0.5.3-1.el6.rf.x86_64.rpm&lt;br /&gt;
* Import the key&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo rpm --import http://apt.sw.be/RPM-GPG-KEY.dag.txt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Install the repository&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo rpm -i rpmforge-release-0.5.3-1.el6.rf.x86_64.rpm&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Check the installation&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rpm -K rpmforge-release-0.5.3-1.el6.rf.x86_64.rpm&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Test it&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo yum install terminator&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Install rpmfusion repository===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
su -c &amp;#039;yum localinstall --nogpgcheck http://download1.rpmfusion.org/free/el/updates/6/i386/rpmfusion-free-release-6-1.noarch.rpm http://download1.rpmfusion.org/nonfree/el/updates/6/i386/rpmfusion-nonfree-release-6-1.noarch.rpm&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===config file for yum===&lt;br /&gt;
Checkout this file for global yum config&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/etc/sysconfig/yum-cron-background&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Setup Oracle Enterprise Linux (RedHat) with yum server===&lt;br /&gt;
You need to download the yum .repo file from the server, as per the steps below. After this, you need to enable a flag in the .repo file as per your operating system version. Having done these two steps, when you run yum install &amp;lt;pkgname&amp;gt; command on your linux box, the Oracle&amp;#039;s yum server will be scanned, the dependent &amp;amp; the relevant rpm&amp;#039;s will be download and installed for you.&amp;lt;br /&amp;gt;&lt;br /&gt;
 cd /etc/yum.repos.d&lt;br /&gt;
To download files here&lt;br /&gt;
 wget http://public-yum.oracle.com/public-yum-el5.repo&lt;br /&gt;
&lt;br /&gt;
A file named public-yum-el5.repo will be created in your directory&amp;lt;br /&amp;gt;&lt;br /&gt;
Edit this file and enter enabled=1 against the operating systems which is relevant to you&lt;br /&gt;
 vi public-yum-el5.repo&lt;br /&gt;
&lt;br /&gt;
Next run the yum command&lt;br /&gt;
 yum install package-name&lt;br /&gt;
&lt;br /&gt;
===To change to static IP address (Raspberry Pi)===&lt;br /&gt;
As root:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cd /etc/networks&lt;br /&gt;
vi interfaces&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
replace the line “iface eth0 inet dhcp” with&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
iface eth0 inet static&lt;br /&gt;
address 192.168.1.100&lt;br /&gt;
netmask 255.255.255.0&lt;br /&gt;
gateway 192.168.1.1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You should also take a look at the file /etc/resolv.conf and check it has a nameserver entry (probably pointing at your default gateway) or direct to your ISP name servers.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
nameserver 192.168.1.1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Troubleshoot wireless network problems===&lt;br /&gt;
* [https://www.blackmoreops.com/2014/09/18/connect-to-wifi-network-from-command-line-in-linux/ connect to wifi network from command-line in linux - from blackmoreops.com]&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Short summary of all the things you need to do in just few lines&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
root@kali:~# iw dev&lt;br /&gt;
root@kali:~# ip link set wlan0 up&lt;br /&gt;
root@kali:~# iw wlan0 scan&lt;br /&gt;
root@kali:~# wpa_passphrase blackMOREOps &amp;gt;&amp;gt; /etc/wpa_supplicant.conf&lt;br /&gt;
root@kali:~# wpa_supplicant -i wlan0 -c /etc/wpa_supplicant.conf&lt;br /&gt;
root@kali:~# iw wlan0 link&lt;br /&gt;
root@kali:~# dhclient wlan0&lt;br /&gt;
root@kali:~# ping 8.8.8.8&lt;br /&gt;
(Where wlan0 is wifi adapter and blackMOREOps is SSID)&lt;br /&gt;
(Add Routing manually)&lt;br /&gt;
root@kali:~# ip route add default via 10.0.0.138 dev wlan0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===To change to static IP address (Redhat/CentOS)===&lt;br /&gt;
As root:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
vi /etc/sysconfig/network-scripts/ifcfg-eth0&lt;br /&gt;
DEVICE=eth0&lt;br /&gt;
BOOTPROTO=STATIC&lt;br /&gt;
IPADDR=192.168.1.111&lt;br /&gt;
NETMASK=255.255.255.0&lt;br /&gt;
GATEWAY=192.168.1.1&lt;br /&gt;
ONBOOT=yes&lt;br /&gt;
DNS1=8.8.8.8&lt;br /&gt;
DNS2=8.8.4.4&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Resrart the network interface&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/etc/init.d/network stop&lt;br /&gt;
/etc/init.d/network start&lt;br /&gt;
or&lt;br /&gt;
service network restart&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Check name server entry in resolv.conf&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
vi /etc/resolv.conf&lt;br /&gt;
nameserver 192.168.1.1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Enable processes / services to start at boot time===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo chkconfig httpd on&lt;br /&gt;
sudo chkconfig mysqld on&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Run a command on lots of servers in parallel===&lt;br /&gt;
This is a damn fine AIX utility - part of the CSM Distributed Shell.&lt;br /&gt;
 dsh -a &amp;quot;ls -al /etc/apache2/*conf&amp;quot;&lt;br /&gt;
will list the Apache configuration file on all reachable servers (nodes)&lt;br /&gt;
===Download a gzip file and pipe it into tar===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cd ~ &amp;amp;&amp;amp; wget -O - &amp;quot;https://www.dropbox.com/download?plat=lnx.x86_64&amp;quot; | tar xzf -&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Check in a script to make sure it is run only by root===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
RUID=`/usr/bin/id|$AWK -F\( &amp;#039;{print $1}&amp;#039;|$AWK -F\= &amp;#039;{print $2}&amp;#039;`&lt;br /&gt;
if [ ${RUID} != &amp;quot;0&amp;quot; ];then&lt;br /&gt;
   $ECHO &amp;quot;This script must be executed as root&amp;quot;&lt;br /&gt;
   exit 1&lt;br /&gt;
fi&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Set terminal to use Backspace key to erase previous character instead of Control-H===&lt;br /&gt;
Been looking for this for a long time.&amp;lt;br /&amp;gt;&lt;br /&gt;
You can put:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
stty erase &amp;lt;CTRL-V&amp;gt;&amp;lt;Backspace key&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
in your .profile but this will be ruined if you do a copy/paste into another file.&amp;lt;br /&amp;gt;&lt;br /&gt;
I wanted a way of doing this without entering the control character in the .profile. Finally stumbled upon it. And it&amp;#039;s so simple. Just escape the caret!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
stty erase \^?&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Put this in the .profile. It&amp;#039;s copy/pastable and it works!&amp;lt;br /&amp;gt;&lt;br /&gt;
If you want CTRL-H to be your erase character, just do this:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
stty erase \^H&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Play with the terminal settings and reset them again either side of requesting a password===&lt;br /&gt;
The -g option of stty gives a compact list of all the settings or the terminal and can be used as input to stty&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
OLDCONFIG=`stty -g`          # save terminal configuration&lt;br /&gt;
stty -echo                   # turn character echoing off&lt;br /&gt;
echo &amp;quot;Enter password: \c&amp;quot;&lt;br /&gt;
read PASSWD                  # get the password&lt;br /&gt;
stty $OLDCONFIG              # restore terminal configuration&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Reset terminal to &amp;quot;sane&amp;quot; characteristics===&lt;br /&gt;
If you&amp;#039;ve done a cat of a binary file or something else weird and your terminal is left in a mess, the following key sequence should bring it back to normal&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;CTRL-J&amp;gt;stty sane&amp;lt;CTRL-J&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Install OpenOffice on RedHat Enterprise when yum install doesn&amp;#039;t!===&lt;br /&gt;
Download Package&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
wget http://sourceforge.net/projects/openofficeorg.mirror/files/4.0.1/binaries/en-US/Apache_OpenOffice_4.0.1_Linux_x86-64_install-rpm_en-US.tar.gz/download -O Apache_OpenOffice_4.0.1_Linux_x86-64_install-rpm_en-US.tar.gz&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Change to root&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo su -&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Remove the old stuff&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
yum remove openoffice* libreoffice*&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Extract Package&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
tar -xvf Apache_OpenOffice_4.0.1*&lt;br /&gt;
cd en-US&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Install Package and exit root&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rpm -Uvh RPMS/*.rpm RPMS/desktop-integration/openoffice4.0-redhat-*.rpm&lt;br /&gt;
exit&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Start it&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
openoffice4&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===What does this do?===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
while IFS= read -r line; do&lt;br /&gt;
    echo &amp;quot;[$(date &amp;quot;+%F %T&amp;quot;)] - $line&amp;quot;&lt;br /&gt;
done &amp;lt; &amp;lt;(iwevent)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
while IFS= read -r line; do&lt;br /&gt;
    printf &amp;quot;%s\n%s\n&amp;quot; &amp;quot;$line&amp;quot; &amp;quot;Yohooo! One more package.&amp;quot;&lt;br /&gt;
done &amp;lt; &amp;lt;(tcpdump -i any -nS)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===List of Special Characters and what they mean===&lt;br /&gt;
From [http://www.grymoire.com/Unix/Quote.html Bruce Barnett]&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Character	Where	Meaning&lt;br /&gt;
&amp;lt;RETURN&amp;gt;	csh, sh	Execute command&lt;br /&gt;
#	csh, sh, ASCII files	Start a comment&lt;br /&gt;
&amp;lt;SPACE&amp;gt;	csh, sh	Argument separator&lt;br /&gt;
`	csh, sh	Command substitution&lt;br /&gt;
&amp;quot;	csh, sh	Weak Quotes&lt;br /&gt;
&amp;#039;	csh, sh	Strong Quotes&lt;br /&gt;
\	csh, sh	Single Character Quote&lt;br /&gt;
variable	sh, csh	Variable&lt;br /&gt;
variable	csh, sh	Same as variable&lt;br /&gt;
|	csh, sh	Pipe character&lt;br /&gt;
^	sh	Pipe Character&lt;br /&gt;
&amp;amp;	csh, sh	Run program in background&lt;br /&gt;
?	csh, sh	Match one character&lt;br /&gt;
*	csh, sh	Match any number of characters&lt;br /&gt;
;	csh, sh	Command separator&lt;br /&gt;
;;	sh	End of Case statement&lt;br /&gt;
~	csh	Home Directory&lt;br /&gt;
~user	csh	User&amp;#039;s Home Directory&lt;br /&gt;
!	csh	History of Commands&lt;br /&gt;
-	Programs	Start of optional argument&lt;br /&gt;
$#	csh, sh	Number of arguments to script&lt;br /&gt;
$*	csh, sh	Arguments to script&lt;br /&gt;
$@	sh	Original arguments to script&lt;br /&gt;
$-	sh	Flags passed to shell&lt;br /&gt;
$?	sh	Status of previous command&lt;br /&gt;
$$	sh	Process identification number&lt;br /&gt;
$!	sh	PID of last background job&lt;br /&gt;
&amp;amp;&amp;amp;	sh	Short-circuit AND&lt;br /&gt;
||	sh	Short-circuit OR&lt;br /&gt;
.	csh, sh	Typ. filename extension&lt;br /&gt;
.	sh	Source a file and execute as command&lt;br /&gt;
:	sh	Nothing command&lt;br /&gt;
:	sh	Separates Values in environment variables&lt;br /&gt;
:	csh	Variable modifier&lt;br /&gt;
Character	Where	Meaning&lt;br /&gt;
[ ]	csh, sh	Match range of characters&lt;br /&gt;
[ ]	sh	Test&lt;br /&gt;
%job	csh	Identifies job Number&lt;br /&gt;
(cmd;cmd)	csh. sh	Runs cmd;cmd as a sub-shell&lt;br /&gt;
{ }	csh	In-line expansions&lt;br /&gt;
{cmd;cmd }	sh	Like (cmd;cmd ) without a subshell&lt;br /&gt;
&amp;gt;ofile	csh, sh	Standard output&lt;br /&gt;
&amp;gt;&amp;gt;ofile	csh, sh	Append to standard output&lt;br /&gt;
&amp;lt;ifile	csh, sh	Standard Input&lt;br /&gt;
&amp;lt;&amp;lt;word	csh, sh	Read until word, substitute variables&lt;br /&gt;
&amp;lt;&amp;lt;\word	csh, sh	Read until word, no substitution&lt;br /&gt;
&amp;lt;&amp;lt;-word	sh	Read until word, ignoring TABS&lt;br /&gt;
&amp;gt;&amp;gt;!file	csh	Append to file, ignore error if not there&lt;br /&gt;
&amp;gt;!file	csh	Output to new file, ignore error if not there&lt;br /&gt;
&amp;gt;&amp;amp;file	csh	Send standard &amp;amp; error output to file&lt;br /&gt;
&amp;lt;&amp;amp;digit	sh	Switch Standard Input to file&lt;br /&gt;
&amp;lt;&amp;amp;-	sh	Close Standard Input&lt;br /&gt;
&amp;gt;&amp;amp;digit	sh	Switch Standard Output to file&lt;br /&gt;
&amp;gt;&amp;amp;-	sh	Close Standard Output&lt;br /&gt;
digit1&amp;lt;&amp;amp;digit2	sh	Connect digit2 to digit1&lt;br /&gt;
digit&amp;lt;&amp;amp;-	sh	Close file digit&lt;br /&gt;
digit2&amp;gt;&amp;amp;digit1	sh	Connect digit2 to digit1&lt;br /&gt;
digit&amp;gt;&amp;amp;-	sh	Close file digit&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Stuart</name></author>	</entry>

	<entry>
		<id>https://mailnest.com/dbawiki/index.php?title=Unix/Linux&amp;diff=3398</id>
		<title>Unix/Linux</title>
		<link rel="alternate" type="text/html" href="https://mailnest.com/dbawiki/index.php?title=Unix/Linux&amp;diff=3398"/>
				<updated>2018-12-06T00:05:56Z</updated>
		
		<summary type="html">&lt;p&gt;Stuart: /* Use sed to repeat characters */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;* [http://hyperpolyglot.org/unix-shells#var-expansion Good shell comparison including variable expansion - hyperpolyglot.org]&lt;br /&gt;
* [http://pubs.opengroup.org/onlinepubs/9699919799/utilities/toc.html Shell coding standards - opengroup.org]&lt;br /&gt;
* [http://aix4admins.blogspot.be aix4admins]&lt;br /&gt;
* [http://linuxgazette.net/issue55/okopnik.html The Deep, Dark Secrets of Bash]&lt;br /&gt;
* [http://www.speakeasy.org/~arkay/216-7.4KshFunctions.html Korn Shell Functions]&lt;br /&gt;
* [http://www.grymoire.com/Unix/AwkRef.html AWK reference from Bruce Barnett]&lt;br /&gt;
* [http://www.catonmat.net/blog/wp-content/uploads/2008/09/awk1line.txt HANDY AWK ONE-LINERS]&lt;br /&gt;
* [http://www.grymoire.com/unix/Quote.html Unix quoting from from Bruce Barnett (grymoire)]&lt;br /&gt;
* [http://www.mpi-inf.mpg.de/departments/rg1/teaching/unixffb-ss98/quoting-guide.html Another excellent quoting tutorial]&lt;br /&gt;
* [http://aix4admins.blogspot.be/2015/02/snapshot-fs-snapshot-snapshot-is-state.html AIX snapshot technology]&lt;br /&gt;
* [[RaspberryPi]]&lt;br /&gt;
* [[SSH]]&lt;br /&gt;
* [http://www.anattatechnologies.com/q/2013/04/multiuser-screen/ Screen sharing from Unix using screen]&lt;br /&gt;
* [https://robots.thoughtbot.com/a-tmux-crash-course Screen sharing from Unix using tmux]&lt;br /&gt;
* [http://www.csb.yale.edu/userguides/wordprocess/vi-summary.html Handy ex and vi reference]&lt;br /&gt;
* [[Fedora install for my own purposes]]&lt;br /&gt;
&lt;br /&gt;
===How to automatically download and process email attachments from Gmail===&lt;br /&gt;
==== Useful references====&lt;br /&gt;
* [http://www.courier-mta.org/maildrop/maildrop.html maildrop]&lt;br /&gt;
* [http://www.wonkity.com/~wblock/docs/html/maildrop.html Using maildrop As A Mail Delivery Agent (MDA)]&lt;br /&gt;
* [http://manpages.ubuntu.com/manpages/trusty/man7/maildropex.7.html .mailfilter examples]&lt;br /&gt;
* [https://www.axllent.org/docs/view/gmail-pop3-with-fetchmail/ Setting up fetchmail with Gmail]&lt;br /&gt;
* [https://www.linode.com/docs/email/clients/using-fetchmail-to-retrieve-email/ Using Fetchmail to Retrieve Email]&lt;br /&gt;
&lt;br /&gt;
Eventually, after months of trying different things, came up with this combination of tools that worked very well.&lt;br /&gt;
====Install tools====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo dnf -y install fetchmail maildrop uudeview openssl&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Set Gmail account up for POP and disable IMAP&lt;br /&gt;
====Configure fetchmail====&lt;br /&gt;
This is the part that talks to Gmail and downloads the emails to the local machine.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
vi ~/.fetchmailrc&lt;br /&gt;
&lt;br /&gt;
set postmaster &amp;quot;&amp;lt;username&amp;gt;&amp;quot;&lt;br /&gt;
#set daemon 600&lt;br /&gt;
poll pop.gmail.com with proto POP3&lt;br /&gt;
    user &amp;quot;account@gmail.com&amp;quot; there with password &amp;#039;&amp;lt;password&amp;gt;&amp;#039; is &amp;lt;username&amp;gt; here options ssl nokeep&lt;br /&gt;
    mda &amp;quot;/usr/bin/maildrop .mailfilter&amp;quot;&lt;br /&gt;
#    sslcertfile /etc/ssl/certs/ca-bundle.crt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
If fetchmail complains about ssl certificates, try specifying wherein is with the sslcertfile line&lt;br /&gt;
==== Configure maildrop====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
vi ~/.mailfilter&lt;br /&gt;
&lt;br /&gt;
LOGFILE = &amp;quot;/home/dbahawk/maildrop/maildrop.log&amp;quot;&lt;br /&gt;
DEFAULT=&amp;quot;$HOME/maildrop&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# keep a copy&lt;br /&gt;
cc backup&lt;br /&gt;
`cd backup/new &amp;amp;&amp;amp; rm -f dummy \`ls -t | sed -e 1,50d\``&lt;br /&gt;
&lt;br /&gt;
if (/^To:.*getmail@...\.dnsalias\.org$/)&lt;br /&gt;
   {&lt;br /&gt;
        to Maildir/getmail/&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
#if (/^To:.*dbahawk/)&lt;br /&gt;
#   {&lt;br /&gt;
#        to maildrop&lt;br /&gt;
#   }&lt;br /&gt;
&lt;br /&gt;
if (/^To:.*dbahawk/)&lt;br /&gt;
    dotlock &amp;quot;auto.lock&amp;quot; {&lt;br /&gt;
    to &amp;quot;|uudeview -c -i&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Not really sure why this filter is not working properly. The cc works but the To: check doesn&amp;#039;t. So I have a shell that runs separately to process the emails in the backup mail directory.&lt;br /&gt;
====uudeview====&lt;br /&gt;
&lt;br /&gt;
===Use sed to repeat characters===&lt;br /&gt;
echo an &amp;#039;=&amp;#039; sign then use the loop feature of sed to run round a loop a further 79 times replacing what you&amp;#039;ve got with the same thing plus and extra one!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
echo &amp;quot;=&amp;quot; | sed -e :a -e &amp;#039;s/^=\{1,79\}$/&amp;amp;=/;ta&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Convert between lower and upper case using ansi standard===&lt;br /&gt;
This way should be portable and give predictable results&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
LOWER_SID=$(echo &amp;quot;${SID}&amp;quot; | tr &amp;#039;[:upper:]&amp;#039; &amp;#039;[:lower:]&amp;#039;)&lt;br /&gt;
UPPER_SID=$(echo &amp;quot;${SID}&amp;quot; | tr &amp;#039;[:lower:]&amp;#039; &amp;#039;[:upper:]&amp;#039;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Use sed to delete the first line of a file or command output printing from the second line onwards===&lt;br /&gt;
Actually deceptively simple. Example remove the header from df output.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
df -k | sed 1d&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
As a useful extension, suppose TO_DATA_DIR contains multiple directories, this will total the free space for all relevant filesystems&amp;lt;br /&amp;gt;&lt;br /&gt;
This one is specific to AIX, for other Unixes and Linux, use $4 instead of $3.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SPACE_AVAILABLE=$(df -k $TO_DATA_DIR | sed 1d | awk &amp;#039;BEGIN {i=0} {i=i+$3} END {print i}&amp;#039;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Use sed to munge a controlfile into submission!===&lt;br /&gt;
* delete comment lines&lt;br /&gt;
* delete all lines after the one starting with a semicolon&lt;br /&gt;
* delete all blank lines&lt;br /&gt;
* change reuse to set&lt;br /&gt;
* change archivelog (with word boundaries) to noarchivelog&lt;br /&gt;
* change old sid to new sid&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sqlplus -s / as sysdba&amp;lt;&amp;lt;&amp;#039;EOSQL&amp;#039; &amp;gt;/dev/null&lt;br /&gt;
alter database backup controlfile to trace as &amp;#039;/tmp/regenerate_controlfile.sql&amp;#039; reuse resetlogs;&lt;br /&gt;
EOSQL&lt;br /&gt;
OLDSID=&amp;#039;PROD&amp;#039;&lt;br /&gt;
NEWSID=&amp;#039;TEST&amp;#039;&lt;br /&gt;
sed  -e &amp;#039;/^--/d&amp;#039; -e &amp;#039;/^\;/q&amp;#039; -e &amp;#039;/^ *$/d&amp;#039; -e &amp;#039;s/REUSE/SET/&amp;#039; -e &amp;#039;s/\&amp;lt;ARCHIVELOG\&amp;gt;/NOARCHIVELOG/&amp;#039; -e &amp;#039;s/\&amp;quot;&amp;#039;${OLDSID}&amp;#039;\&amp;quot;/\&amp;quot;&amp;#039;${NEWSID}&amp;#039;\&amp;quot;/&amp;#039; /tmp/regenerate_controlfile.sql&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Find all files where a certain text does not exist===&lt;br /&gt;
Mostly we want to search for files containing a particular string but how to find those files that do not contain some text.&amp;lt;br /&amp;gt;&lt;br /&gt;
Using xargs instead of -exec forces the filename to be printed. -H should do this but doesn&amp;#039;t seem to in this case.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
find . -name &amp;quot;*cfg&amp;quot; | xargs grep -H -c TO_CV_HOST {} \; | grep &amp;#039;:0$&amp;#039; | cut -d: -f1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Use tar and gzip to copy files more efficiently across network between hosts===&lt;br /&gt;
From the destination server, this will connect to the source, tar up each file and pull it back to the current server&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ssh oracle@hn5211 &amp;quot;cd /oracle/ora_data4/iten3/ &amp;amp;&amp;amp; tar -cf - . | gzip &amp;quot; | ( cd /oracle/ora_data2/iten/ &amp;amp;&amp;amp; gunzip -c | tar -xvf - . )&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===double hash and double percent in shell variables to trim off characters from variables===&lt;br /&gt;
&amp;lt;nowiki&amp;gt;#&amp;lt;/nowiki&amp;gt;  - trims everything from the start of line till the FIRST occurrence of following character (abstemious) :-)&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;nowiki&amp;gt;##&amp;lt;/nowiki&amp;gt; - trims everything from the start of line till the LAST occurrence of following character (greedy)&amp;lt;br /&amp;gt;&lt;br /&gt;
%  - trims everything from the end of line backwards till the FIRST occurrence of following character (abstemious)&amp;lt;br /&amp;gt;&lt;br /&gt;
%% - trims everything from the end of line backwards till the LAST occurrence of following character (greedy)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
FILENAME=&amp;quot;/home/bey9at77/hello.txt&amp;quot;&lt;br /&gt;
FILE_STUB1=${FILENAME##*/}&lt;br /&gt;
FILE_STUB=${FILE_STUB1%.*}&lt;br /&gt;
echo $FILE_STUB&lt;br /&gt;
hello&lt;br /&gt;
FILE_EXT=${FILENAME##*.}&lt;br /&gt;
echo $FILE_EXT&lt;br /&gt;
txt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;nowiki&amp;gt;#&amp;lt;/nowiki&amp;gt; - remove prefix reluctantly&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;nowiki&amp;gt;##&amp;lt;/nowiki&amp;gt; - remove prefix greedily&amp;lt;br /&amp;gt;&lt;br /&gt;
% - remove suffix reluctantly&amp;lt;br /&amp;gt;&lt;br /&gt;
%% - remove suffix greedily&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
words=&amp;quot;do.re.mi&amp;quot;&lt;br /&gt;
&lt;br /&gt;
echo ${words#*.}&lt;br /&gt;
&lt;br /&gt;
echo ${words##*.}&lt;br /&gt;
&lt;br /&gt;
echo ${words%.*}&lt;br /&gt;
&lt;br /&gt;
echo ${words%%.*}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===The best shell script ever. An example of how scripting should be done===&lt;br /&gt;
It was written by someone at Oracle. Unfortunately (s)he did not put any author comment in it. Also unfortunately I cannot show it here as it is protected behind Oracles support website.&amp;lt;br /&amp;gt;&lt;br /&gt;
If you have an Oracle Metalink id, you can get the complete script [https://support.oracle.com/epmos/faces/DocumentDisplay?id=949322.1 here]&amp;lt;br /&amp;gt;&lt;br /&gt;
Here is a snippet of a function that demonstrates proper commenting and a very good style.&amp;lt;br &amp;gt;&lt;br /&gt;
The script is called physru.sh and upgrades an Oracle database in a rolling upgrade fashion by using a physical standby.&amp;lt;br /&amp;gt;&lt;br /&gt;
There are 4500 lines in the full script but it is so easy to read and understand because of the way it&amp;#039;s written, it&amp;#039;s like a breath of fresh air. Well done whoever you are!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
###############################################################################&lt;br /&gt;
# NAME:        wait_mrp_active&lt;br /&gt;
#&lt;br /&gt;
# DESCRIPTION: &lt;br /&gt;
#   Wait for $MRP_START_TIMEOUT minutes to confirm that the MRP is active.  If&lt;br /&gt;
#   we can&amp;#039;t detect an active MRP, abort the script with an error.&lt;br /&gt;
#&lt;br /&gt;
# INPUT(S):&lt;br /&gt;
#   Arguments:&lt;br /&gt;
#     $1: database user&lt;br /&gt;
#     $2: user password&lt;br /&gt;
#     $3: tns service name&lt;br /&gt;
#     $4: database unique name&lt;br /&gt;
#&lt;br /&gt;
#   Globals:&lt;br /&gt;
#     None&lt;br /&gt;
#&lt;br /&gt;
# RETURN:&lt;br /&gt;
#   None&lt;br /&gt;
#&lt;br /&gt;
###############################################################################&lt;br /&gt;
wait_mrp_active()&lt;br /&gt;
{&lt;br /&gt;
  display &amp;quot;confirming media recovery is running&amp;quot;&lt;br /&gt;
  l_wma_status=1&lt;br /&gt;
  l_wma_curtime=`perl -e &amp;#039;print int(time)&amp;#039;`&lt;br /&gt;
  l_wma_exptime=`expr $MRP_START_TIMEOUT &amp;quot;*&amp;quot; 60`&lt;br /&gt;
  l_wma_maxtime=`expr $l_wma_curtime + $l_wma_exptime`&lt;br /&gt;
  while [ &amp;quot;$l_wma_curtime&amp;quot; -lt &amp;quot;$l_wma_maxtime&amp;quot; ]&lt;br /&gt;
  do&lt;br /&gt;
    is_mrp_running $1 $2 $3 $4&lt;br /&gt;
    if [ &amp;quot;$?&amp;quot; -gt &amp;quot;0&amp;quot; ]; then&lt;br /&gt;
      l_wma_status=0&lt;br /&gt;
      break&lt;br /&gt;
    fi&lt;br /&gt;
&lt;br /&gt;
    sleep $MRP_START_INTERVAL&lt;br /&gt;
    l_wma_curtime=`perl -e &amp;#039;print int(time)&amp;#039;`&lt;br /&gt;
  done&lt;br /&gt;
  chkerr $l_wma_status &amp;quot;could not detect an active MRP after $MRP_START_TIMEOUT minutes&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===split variable (eg. filename) into separate variables using set===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
FILENAME=&amp;quot;split_this_into_bits&amp;quot;&lt;br /&gt;
set $(echo ${FILENAME} | sed &amp;#039;s/_/ /g&amp;#039;)&lt;br /&gt;
echo $4 $3 $2 $1&lt;br /&gt;
bits into this split&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Centre align text on a line in bash shell===&lt;br /&gt;
Doesn&amp;#039;t work in Korn shell due to %*s&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#COLUMNS=$(tput cols)   # width of the current window&lt;br /&gt;
COLUMNS=80&lt;br /&gt;
title=&amp;quot;Hello world!&amp;quot;&lt;br /&gt;
printf &amp;quot;%*s\n&amp;quot; $(((${#title}+$COLUMNS)/2)) &amp;quot;$title&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
and as a one-liner&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
printf &amp;quot;%*s\n&amp;quot; $(( ( $(echo $* | wc -c ) + 80 ) / 2 )) &amp;quot;$*&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This works in Korn shell...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
TITLE=&amp;quot;$1&amp;quot;&lt;br /&gt;
LINEWIDTH=80&lt;br /&gt;
&lt;br /&gt;
LPAD=$(((${#TITLE}+$LINEWIDTH)/2))&lt;br /&gt;
printf %${LPAD}s &amp;quot;$TITLE&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Right justify text (or repeat characters) on a line with leader dots!===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
function rpadwait {&lt;br /&gt;
    text=$1&lt;br /&gt;
# -------------------------&lt;br /&gt;
# suppress newline for echo&lt;br /&gt;
# -------------------------&lt;br /&gt;
N=&lt;br /&gt;
C=&lt;br /&gt;
if echo &amp;quot;\c&amp;quot; | grep c &amp;gt;/dev/null 2&amp;gt;&amp;amp;1; then&lt;br /&gt;
    N=&amp;#039;-n&amp;#039;&lt;br /&gt;
else&lt;br /&gt;
    C=&amp;#039;\c&amp;#039;&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
    echo ${N} &amp;quot;${text}${C}&amp;quot; | sed -e :a -e &amp;#039;s/^.\{1,80\}$/&amp;amp;\./;ta&amp;#039;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===cron jobs not submitted - daemon run out of child processes?===&lt;br /&gt;
Sometimes have problems with NFS mounts and this causes cron jobs to hang. If they are scheduled to run regularly, eventually cron will no longer be able to start any more jobs.&amp;lt;br /&amp;gt;&lt;br /&gt;
* Check the cron log &amp;#039;&amp;#039;&amp;#039;/var/adm/cron/log&amp;#039;&amp;#039;&amp;#039; to see if there are any errors or other messages around the time the jobs should run.&lt;br /&gt;
If cron has hit its process limit (default 100), it will try again after a number of seconds (default 60).&amp;lt;br /&amp;gt;&lt;br /&gt;
Both the number of jobs and wait time are configured in the file &amp;#039;&amp;#039;&amp;#039;/var/adm/cron/queuedefs&amp;#039;&amp;#039;&amp;#039;. If it is unusual for cron to be running so many jobs, you can check the process table to view the jobs cron has created. These jobs will have parent process id (PPID) of the cron daemon.&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ ps -ef | grep cron | grep -v grep&lt;br /&gt;
    root  6750314        1   0   Apr 24      -  3:39 /usr/sbin/cron&lt;br /&gt;
solax025:root[/home/root]# ps -T 6750314&lt;br /&gt;
      PID    TTY  TIME CMD&lt;br /&gt;
  6750314      -  3:39 cron&lt;br /&gt;
 21168296      -  0:00     \--bsh&lt;br /&gt;
 58982414      -  0:00         \--sadc&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
In this example, we only have 1 job running&lt;br /&gt;
&lt;br /&gt;
===Find long-running processes with a cron job===&lt;br /&gt;
Processes running longer than 24 hours have a date instead of a start time...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
58 08,14 * * * /home/ibmtools/scripts/oracle/dosh -vc &amp;quot;ps -ef|grep &amp;#039;ibmtools/scripts/oracle&amp;#039;|perl -nae &amp;#039;print if \$F[4] !~/:/&amp;#039;&amp;quot; &amp;gt;/tmp/lrp.txt; [[ $(grep -c ibmtools /tmp/lrp.txt) -ne 0 ]] &amp;amp;&amp;amp; cat /tmp/lrp.txt|mailx -s &amp;#039;*** long running processes - please check ***&amp;#039; reporting@companymail.com&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Process command line arguments in shell===&lt;br /&gt;
Borrowed from Mozilla Firefox installer&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
## Command line arg defaults&lt;br /&gt;
##&lt;br /&gt;
moz_debug=0&lt;br /&gt;
moz_debugger=&amp;quot;&amp;quot;&lt;br /&gt;
moz_debugger_args=&amp;quot;&amp;quot;&lt;br /&gt;
#&lt;br /&gt;
##&lt;br /&gt;
## Parse the command line&lt;br /&gt;
##&lt;br /&gt;
while [ $# -gt 0 ]&lt;br /&gt;
do&lt;br /&gt;
  case $1 in&lt;br /&gt;
    -g | --debug)&lt;br /&gt;
      moz_debug=1&lt;br /&gt;
      shift&lt;br /&gt;
      ;;&lt;br /&gt;
    -d | --debugger)&lt;br /&gt;
      moz_debugger=$2;&lt;br /&gt;
      if [ &amp;quot;${moz_debugger}&amp;quot; != &amp;quot;&amp;quot; ]; then&lt;br /&gt;
	shift 2&lt;br /&gt;
      else&lt;br /&gt;
        echo &amp;quot;-d requires an argument&amp;quot;&lt;br /&gt;
        exit 1&lt;br /&gt;
      fi&lt;br /&gt;
      ;;&lt;br /&gt;
    -a | --debugger-args)&lt;br /&gt;
      moz_debugger_args=$2;&lt;br /&gt;
      if [ &amp;quot;${moz_debugger_args}&amp;quot; != &amp;quot;&amp;quot; ]; then&lt;br /&gt;
	shift 2&lt;br /&gt;
      else&lt;br /&gt;
        echo &amp;quot;-a requires an argument&amp;quot;&lt;br /&gt;
        exit 1&lt;br /&gt;
      fi&lt;br /&gt;
      ;;&lt;br /&gt;
    *)&lt;br /&gt;
      break;&lt;br /&gt;
      ;;&lt;br /&gt;
  esac&lt;br /&gt;
done&lt;br /&gt;
#&lt;br /&gt;
##&lt;br /&gt;
## Program name given in $1&lt;br /&gt;
##&lt;br /&gt;
if [ $# -gt 0 ]&lt;br /&gt;
then&lt;br /&gt;
	MOZ_PROGRAM=$1&lt;br /&gt;
	shift&lt;br /&gt;
fi&lt;br /&gt;
##&lt;br /&gt;
## Program not given, try to guess a default&lt;br /&gt;
##&lt;br /&gt;
if [ -z &amp;quot;$MOZ_PROGRAM&amp;quot; ]&lt;br /&gt;
then&lt;br /&gt;
	##&lt;br /&gt;
	## Try this script&amp;#039;s name with &amp;#039;-bin&amp;#039; appended&lt;br /&gt;
	##&lt;br /&gt;
	if [ -x &amp;quot;$MOZ_DEFAULT_NAME&amp;quot; ]&lt;br /&gt;
	then&lt;br /&gt;
		MOZ_PROGRAM=$MOZ_DEFAULT_NAME&lt;br /&gt;
	##&lt;br /&gt;
	## Try mozilla-bin&lt;br /&gt;
	## &lt;br /&gt;
	elif [ -x &amp;quot;$MOZ_APPRUNNER_NAME&amp;quot; ]&lt;br /&gt;
	then&lt;br /&gt;
		MOZ_PROGRAM=$MOZ_APPRUNNER_NAME&lt;br /&gt;
	fi&lt;br /&gt;
fi&lt;br /&gt;
#&lt;br /&gt;
#&lt;br /&gt;
##&lt;br /&gt;
## Make sure the program is executable&lt;br /&gt;
##&lt;br /&gt;
if [ ! -x &amp;quot;$MOZ_PROGRAM&amp;quot; ]&lt;br /&gt;
then&lt;br /&gt;
	moz_bail &amp;quot;Cannot execute $MOZ_PROGRAM.&amp;quot;&lt;br /&gt;
fi&lt;br /&gt;
#&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Carry XWindows settings across sessions===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# ----------------------&lt;br /&gt;
# push XWindows settings&lt;br /&gt;
# ----------------------&lt;br /&gt;
[[ &amp;quot;$(uname)&amp;quot; == &amp;quot;SunOS&amp;quot; ]] &amp;amp;&amp;amp; PATH=/usr/openwin/bin:$PATH&lt;br /&gt;
WHOAMI=$(id | awk -F&amp;#039;)&amp;#039; &amp;#039;{print $1}&amp;#039; | awk -F&amp;#039;(&amp;#039; &amp;#039;{print $2}&amp;#039;)&lt;br /&gt;
xauth list &amp;gt; /tmp/xauth_list_$WHOAMI&lt;br /&gt;
chmod 777 /tmp/xauth_list_$WHOAMI&lt;br /&gt;
&lt;br /&gt;
echo $DISPLAY &amp;gt; /tmp/xdisplay_$WHOAMI&lt;br /&gt;
chmod 777 /tmp/xdisplay_$WHOAMI&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Cross-platform version of whoami===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
WHOAMI=$(id | awk -F&amp;#039;)&amp;#039; &amp;#039;{print $1}&amp;#039; | awk -F&amp;#039;(&amp;#039; &amp;#039;{print $2}&amp;#039;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Set terminal title from command line===&lt;br /&gt;
Put something like this in the .profile&amp;lt;br /&amp;gt;&lt;br /&gt;
-n     do not output the trailing newline&amp;lt;br /&amp;gt;&lt;br /&gt;
-e     enable interpretation of backslash escapes&amp;lt;br /&amp;gt;&lt;br /&gt;
|0     sets title of window and icon&amp;lt;br /&amp;gt;&lt;br /&gt;
|1     sets title of icon only&amp;lt;br /&amp;gt;&lt;br /&gt;
|2     sets title of window only&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
echo -en &amp;quot;\033]0;`hostname`\007&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
echo -en &amp;quot;\033]2;`hostname`\007&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Remove blank lines and comments (also indented ones) from a file===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
awk -F\: &amp;#039;!/^($|[:space:]*#)/ {print $2}&amp;#039; /etc/oratab | sort | uniq&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or as part of a script that removes comments and blank lines from all Korn shell scripts in a directory&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/usr/bin/ksh&lt;br /&gt;
for i in $(ls *ksh); do&lt;br /&gt;
    perl -p -i -e &amp;#039;s/^\s*#[^!]*$//; s/^\s*$//&amp;#039; $i&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Return elements of an array in Korn shell===&lt;br /&gt;
From [http://unix.stackexchange.com/questions/188202/processing-output-from-an-sqlite-db-into-a-ksh-array-with-spaces here]&amp;lt;br /&amp;gt;&lt;br /&gt;
Could be used to separate the columns of an SQL select when returning to the shell&amp;lt;br /&amp;gt;&lt;br /&gt;
This approach eliminates the need to put quotes around text with spaces in it.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
echo $KSH_VERSION&lt;br /&gt;
x=&amp;quot;Red,Yellow is a color,Blue&amp;quot;&lt;br /&gt;
oIFS=$IFS&lt;br /&gt;
IFS=,&lt;br /&gt;
y=($x)&lt;br /&gt;
IFS=$oIFS&lt;br /&gt;
echo ${y[1]}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===A decent Unix Prompt===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
export PS1=&amp;quot;`uname -n`:`whoami`[\${PWD}]# &amp;quot;&lt;br /&gt;
or&lt;br /&gt;
export PS1=&amp;#039;($?) $&amp;#039;ORACLE_SID&amp;quot; &amp;quot;`whoami`&amp;quot;@&amp;quot;`uname -n`&amp;quot;:&amp;quot;&amp;#039;$&amp;#039;PWD&amp;quot;&amp;gt; &amp;quot;&lt;br /&gt;
export EDITOR=vi&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Simple arithmetic===&lt;br /&gt;
pipe the calculation into the shell calculator&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
space_in_kb=$(echo $1 / 1024 | bc)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Calculate the remainder (modulo) of a division calculation&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
if [[ $(echo &amp;quot;${NUMBER} % 2&amp;quot; | bc) -eq 0 ]]; then&lt;br /&gt;
    echo &amp;quot;${NUMBER} is even&amp;quot;&lt;br /&gt;
else&lt;br /&gt;
    echo &amp;quot;${NUMBER} is odd&amp;quot;&lt;br /&gt;
fi&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or do it in awk if scientific notation maybe involved&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
function calc { awk &amp;quot;BEGIN{print $*}&amp;quot;; }&lt;br /&gt;
&lt;br /&gt;
if [[ $(calc &amp;quot;${SPACE_USED} + ${SPACE_AVAILABLE} - ${DATABASE_SIZE&amp;quot;) -le 0 ]]; then&lt;br /&gt;
    echo &amp;quot;NOK&amp;quot;&lt;br /&gt;
fi&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Script encryption and passphrase protection===&lt;br /&gt;
Encrypt a shell script with the ability to execute the encrypted version&lt;br /&gt;
* from [http://www.commandlinefu.com/commands/browse commandlinefu.com]&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
scrypt(){ [ -n &amp;quot;$1&amp;quot; ]&amp;amp;&amp;amp;{ echo &amp;#039;. &amp;lt;(echo &amp;quot;$(tail -n+2 $0|base64 -d|mcrypt -dq)&amp;quot;); exit;&amp;#039;&amp;gt;$1.scrypt;cat $1|mcrypt|base64 &amp;gt;&amp;gt;$1.scrypt;chmod +x $1.scrypt;};}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Virtual host configuration in Apache http.conf===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;VirtualHost *:80&amp;gt;&lt;br /&gt;
        ServerName dbamon&lt;br /&gt;
        DocumentRoot &amp;quot;/Volumes/data/Sites/dbamon_push&amp;quot;&lt;br /&gt;
        &amp;lt;Directory &amp;quot;/Volumes/data/Sites/dbamon_push&amp;quot;&amp;gt;&lt;br /&gt;
                Options Includes FollowSymLinks&lt;br /&gt;
                AllowOverride All&lt;br /&gt;
                Order allow,deny&lt;br /&gt;
                Allow from all&lt;br /&gt;
        &amp;lt;/Directory&amp;gt;&lt;br /&gt;
&amp;lt;/VirtualHost&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
and in /etc/hosts, add...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
127.0.0.1  dbamon&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Mount a website (or any other remote resource) locally using WebDav===&lt;br /&gt;
Redhat/CentOS&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
yum install fuse-davfs2&lt;br /&gt;
or&lt;br /&gt;
yum install wdfs.x86_64&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Debian&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
apt-get install davfs2&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
then...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo mkdir /mnt/webdav  # or whatever you&amp;#039;d like to call the directory&lt;br /&gt;
sudo mount.davfs [-o option[,option]...] device mount_point&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
In man&amp;#039;s terms, that last line would translate to:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
id  #suppose this returns uid=501 and gid=502&lt;br /&gt;
sudo mount.davfs -o 501,502 https://your/web/site /mnt/webdav&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Mac OSX&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
osascript -e &amp;#039; mount volume &amp;quot;http://username:password@webdav.address:portnum&amp;quot; &amp;#039;&lt;br /&gt;
or&lt;br /&gt;
osascript -e &amp;#039; mount volume &amp;quot;http://username@webdav.address:portnum&amp;quot; &amp;#039;&lt;br /&gt;
or&lt;br /&gt;
osascript -e &amp;#039; try mount volume &amp;quot;http://webdav.address:portnum&amp;quot; &amp;#039;&lt;br /&gt;
or&lt;br /&gt;
mount -t webdav http://webdav.address:portnum /mnt/webdav  # this one won&amp;#039;t show up in the Finder Sidebar.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Add current hostname to list of hosts on an xcat server===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
CMD=&amp;quot;nodels&amp;quot;&lt;br /&gt;
HOST=`hostname`&lt;br /&gt;
(echo &amp;quot;$HOST&amp;quot;; $CMD) | while read server&lt;br /&gt;
do&lt;br /&gt;
    echo &amp;quot;server:$server&amp;quot;&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===What is todays &amp;#039;Day Of the Year&amp;#039; number?===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
DOY=`perl -e &amp;#039;print sub{$_[7]}-&amp;gt;(localtime)+1;&amp;#039;`&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Convert Julian day numbers to dates===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
for day in 8 33 36 61 64 91 96 121 126 152 155 182 187 215 218 244 247 274 279 306 309 335 338 365; do date -d &amp;quot;`date +%Y`-01-01 +$(( ${day} - 1 ))days&amp;quot; +%d-%m-%Y; done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Send crontab job output to a date formatted log file===&lt;br /&gt;
This will run a job every 5 minutes and send the output to a file ending with a time in hours and minutes.&amp;lt;br /&amp;gt;&lt;br /&gt;
The thing to note is the escaped percent signs. This is because a % sign is interpreted by cron to mean a newline character. Everything after the first % is treated as input to the program.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
*/5 *  * * * /var/www/cgi-bin/dbamon_collector.ksh       &amp;gt;/tmp/dbamon_collector.log.$(date &amp;quot;+\%H\%M&amp;quot;) 2&amp;gt;&amp;amp;1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Edit crontab file without crontab -e===&lt;br /&gt;
It can happen that you need to add or modify a line in the crontab of many users or across many servers at once.&amp;lt;br /&amp;gt;&lt;br /&gt;
In principle, there&amp;#039;s nothing wrong with modifying the crontab file directly. You just lose the advantages of file locking (and syntax checking) that crontab -e offers.&amp;lt;br /&amp;gt;&lt;br /&gt;
Here we take a backup of the current crontab, print it out, echo an extra command and ask cron to use these as input (thus overwriting the existing crontab file). Just don&amp;#039;t run this close to midnight :-)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
crontab -l &amp;gt; /tmp/crontab.`date &amp;#039;+%Y%m%d&amp;#039;`&lt;br /&gt;
(&lt;br /&gt;
cat /tmp/crontab.`date +&amp;#039;%Y%m%d&amp;#039;`&lt;br /&gt;
echo &amp;quot;02 10 * * * /home/ibmtools/scripts/oracle/export_parfile.ksh -s SID -f JDBEOP1.parfile&amp;quot;&lt;br /&gt;
) | crontab -&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
crontab -l &amp;gt; /tmp/crontab.backup&lt;br /&gt;
crontab -l &amp;gt; /tmp/crontab.$$&lt;br /&gt;
perl -p -i -e &amp;#039;s!backup_send_tsm_dump!backup_export2tsm!g&amp;#039; /tmp/crontab.$$&lt;br /&gt;
crontab /tmp/crontab.$$&lt;br /&gt;
rm /tmp/crontab.$$&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
crontab -l &amp;gt;$HOME/crontab.$(date &amp;#039;+%Y%m%d&amp;#039;)&lt;br /&gt;
crontab -l | perl -p -e &amp;#039;s|/nas/software/oracle/scripts|/oracle/scripts|&amp;#039; | crontab&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Use shell to convert a number in scientific notation to normal===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
var2convert=&amp;#039;1.2345678e3&amp;#039;&lt;br /&gt;
printf -v var2convert &amp;quot;%.f&amp;quot; $var2convert&lt;br /&gt;
echo $var2convert  # magic!&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Check for jobs running longer that 24 hours===&lt;br /&gt;
Run from the management server across all Unix servers. Checks the 5th column in a ps listing. If it doesn&amp;#039;t find a : (time separator), the process is running longer than 24 hours.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# ---------------------------------------&lt;br /&gt;
# report on long running oraibm processes&lt;br /&gt;
# ---------------------------------------&lt;br /&gt;
01 17,14 * * * rm -f /tmp/lrp.txt;/home/ibmtools/scripts/oracle/dosh -vc \&amp;quot;ps -ef|egrep &amp;#039;oraibm|scripts/oracle&amp;#039;&amp;gt;/tmp/lrp.txt;perl -nae &amp;#039;print if \$F[4] !~/:/&amp;#039; /tmp/lrp.txt\&amp;quot; &amp;gt;&amp;gt;/tmp/lrp.txt;[[ $(egrep -c &amp;#039;oraibm|scripts/or&lt;br /&gt;
acle&amp;#039; /tmp/lrp.txt) -ne 0 ]] &amp;amp;&amp;amp; cat /tmp/lrp.txt|mailx -s &amp;#039;*** long running processes - please check ***&amp;#039; bey9at77@mail.com&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Global find and replace with perl (restricted to list of files provided by Unix find command)===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
find . -type f -exec perl -i -pe &amp;#039;s/something/else/g&amp;#039; {} \;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===perl function to make filenames lower case===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
function lower { &lt;br /&gt;
   perl -e &amp;#039;for (@ARGV) { rename $_, lc($_) unless -e lc($_); }&amp;#039; * &lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===From the management server, search the TNS listener port for each database on a server and make an inline substitution in the ITM config files!===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
for i in `/home/ibmtools/scripts/oracle/dosh -c &amp;quot;ls -al /opt/IBM/ITM/config/*rz*cfg|grep -v lrwx&amp;quot;|awk &amp;#039;{print $NF}&amp;#039;`; do&lt;br /&gt;
    server=`echo $i|cut -d_ -f1 | awk -F&amp;#039;/&amp;#039; &amp;#039;{print $NF}&amp;#039;`&lt;br /&gt;
    db=`echo $i|cut -d&amp;#039;.&amp;#039; -f1 | awk -F&amp;#039;_&amp;#039; &amp;#039;{print $NF}&amp;#039;`&lt;br /&gt;
    OH=`ssh $server grep &amp;quot;^$db&amp;quot; /etc/oratab|cut -d: -f2`&lt;br /&gt;
    LISTENERPORT=`ssh $server cat $OH/network/admin/listener.ora|perl -00 -ne &amp;#039;print $1 if /&amp;#039;$db&amp;#039;.*PORT.*=.*(\d{4})/s&amp;#039;`&lt;br /&gt;
    ssh $server perl -p -i.bak -e &amp;#039;s/1521/&amp;#039;$LISTENERPORT&amp;#039;/&amp;#039; $i&lt;br /&gt;
    ssh $server ls -al ${i}*&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Run a job from cron every Nth day of the month===&lt;br /&gt;
Example. Execute a job every third Saturday of the month.&amp;lt;br /&amp;gt;&lt;br /&gt;
Paste this into a file called calenday and put it in /usr/local/bin so it&amp;#039;s (probably) on the PATH&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/usr/bin/ksh&lt;br /&gt;
&lt;br /&gt;
# ix is the week number of the month (&amp;quot;2&amp;quot;nd Friday of the month, &amp;quot;3&amp;quot;rd Tuesday of the month)&lt;br /&gt;
# dy is the day number in Unix format (0 for Sunday, 1 for Monday, ... 6 for Saturday)&lt;br /&gt;
# eg. &amp;quot;calenday 3 6&amp;quot; returns the date of 3rd Saturday of the month.&lt;br /&gt;
&lt;br /&gt;
ix=$1&lt;br /&gt;
dy=$2&lt;br /&gt;
SCHAR=$((($dy*2)+$dy+1))&lt;br /&gt;
ECHAR=$(($SCHAR+1))&lt;br /&gt;
cal `date &amp;#039;+%m %Y&amp;#039;` | egrep &amp;quot;\&amp;lt;[0-9]{1,2}\&amp;gt;&amp;quot; | cut -c${SCHAR}-${ECHAR} | xargs | awk {&amp;#039;print $&amp;#039;$ix&amp;#039;}&amp;#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Now in crontab, you should be able to do something like this:&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
15 20 * * * [[ `calenday 3 6` -eq `/bin/date &amp;#039;+%d&amp;#039;` ]] &amp;amp;&amp;amp; su - oracle -c &amp;quot;run_my_backup.ksh&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will also work on some Unices..&amp;lt;br /&amp;gt;&lt;br /&gt;
We send backups to a special TSM node on the second Friday of each month. This report must run a day later - but that is not guaranteed to be the second Saturday or even the 3rd. So...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
30 12 8-14 * 5 sleep 86400 &amp;amp;&amp;amp; su - oracle -c &amp;quot;/usr/bin/perl -ne &amp;#039;print if /ORX_M_SOL/ .. /^STOP/&amp;#039; /home/oracle/incoming/dbamon_spool_tsm_*.SOL | grep Archive | grep -v Client | mailx -s &amp;#039;Monthly TSM backups&amp;#039; orareport@xxxxxx.com&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ps listing does not show start time after 24 hours===&lt;br /&gt;
But you can see elapsed time using your own ps command&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/usr/bin/ps -eo etime,user,pid,ppid,cpu,start,tty,time,args|tail -n +2|sort&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ps -ef cuts off args cmd column on Solaris===&lt;br /&gt;
====To see more than 80 characters of the last column on Solaris====&lt;br /&gt;
This shows all the individual arguments to the command&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
pargs &amp;lt;pid&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This shows the ps listing in &amp;#039;compatibility&amp;#039; mode (there are more compatibility commands in /usr/xpg4/bin)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/usr/ucb/ps auww&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====To see more than 80 characters of the last column on AIX====&lt;br /&gt;
This shows the full argument listing of a process (NOTE: no minus sign!)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ps eww &amp;lt;pid&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Remove blank / empty lines from vi ===&lt;br /&gt;
Maybe you cut and pasted a file from Windows and it&amp;#039;s full of blank lines and Control-M&amp;#039;s now&amp;lt;br /&amp;gt;&lt;br /&gt;
There are several methods but I think this is the easiest to remember&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
:g/^$/d&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Right pad a variable===&lt;br /&gt;
a function like rpad in SQL but for Shell&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
function rpad {&lt;br /&gt;
text=$1&lt;br /&gt;
padwidth=$2&lt;br /&gt;
padchar=$3&lt;br /&gt;
echo &amp;quot;$text&amp;quot; | sed -e :a -e &amp;#039;s/^.\{1,&amp;#039;$padwidth&amp;#039;\}$/&amp;amp;\&amp;#039;$padchar&amp;#039;/;ta&amp;#039;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Connect to a Windows server from Linux using rdesktop===&lt;br /&gt;
My remmina stopped working so rolled my own. Very simple really. Put this is a shell.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
tsocks rdesktop -z -P -x m -a 16 -d MAIND -u sbarkley -p ****** -r disk:SOL=$HOME/Documents/SOL -g 95% 150.251.112.38 &amp;amp;&lt;br /&gt;
&lt;br /&gt;
where...&lt;br /&gt;
-z    - enables compression&lt;br /&gt;
-P    - enables bitmap caching (saves network traffic)&lt;br /&gt;
-x m  - disables eye-candy features&lt;br /&gt;
-a 16 - reduce colour pallete to 16 colours&lt;br /&gt;
-d    - domain to connect to&lt;br /&gt;
-u    - username&lt;br /&gt;
-p    - password&lt;br /&gt;
-r    - setup a shared folder&lt;br /&gt;
-g    - geometry (use W x H or percentage)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Slight problems with rdesktop not working 100% of the time. Now using xfreerdp. Seems better...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
xfreerdp -g 90% --ignore-certificate --gdi sw -K -d wdcrhbp05 -u oraibm -p &amp;quot;`cat $HOME/scripts/.oraibm.password`&amp;quot; -T &amp;quot;wdcrhbp05_oraibm&amp;quot; --plugin cliprdr --plugin rdpdr --data disk:SOL:/home/bey9at77/Documents/SOL -- --plugin rdpsnd --data alsa -- 150.251.112.25 &amp;amp;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Reset your password bypassing password rules===&lt;br /&gt;
must be done as root&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
echo &amp;quot;user:new_password&amp;quot; | chpasswd&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Sum the sizes of all files of an ls listing===&lt;br /&gt;
It&amp;#039;ll check to see if the sum of filesizes corresponds with the df -g (or h) listing (can get messed up due to open but deleted files)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cd /oracle/export&lt;br /&gt;
df -g .&lt;br /&gt;
find . -name &amp;quot;*dmp*&amp;quot; -ls |  awk &amp;#039;{ SUM += $7} END { print SUM/1024/1024/1024 }&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Mount an iso image under Linux===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
mkdir -p /mnt/cdrom&lt;br /&gt;
mount -o loop /dev/cdrom /mnt/cdrom&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===How many processors on the machine?===&lt;br /&gt;
* AIX&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
lsdev -C|grep Process|wc -l&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Solaris&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
psrinfo -v|grep &amp;quot;Status of processor&amp;quot;|wc -l&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Linux&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cat /proc/cpuinfo|grep processor|wc -l&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Quick, simple, understandable example of how to use RRDTool===&lt;br /&gt;
* [[RRDTool]]&lt;br /&gt;
&lt;br /&gt;
===Use expect to respond automatically to interactive programs===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/usr/bin/expect -f&lt;br /&gt;
spawn /usr/tivoli/tsm/client/oracle/bin64/tdpoconf passw -tdpo_optfile=/oracle/[lindex $argv 0]/admin/tdpo.opt&lt;br /&gt;
expect &amp;quot;assword:&amp;quot; {send &amp;quot;password\r&amp;quot;}&lt;br /&gt;
expect &amp;quot;assword:&amp;quot; {send &amp;quot;password\r&amp;quot;}&lt;br /&gt;
expect &amp;quot;assword:&amp;quot; {send &amp;quot;password\r&amp;quot;}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Use expect to allow file copy with scp (if ssh keys are not an option)===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/usr/bin/expect -f&lt;br /&gt;
spawn scp /home/oracle/.profile oracle@hn512:/tmp/prfl&lt;br /&gt;
set pass &amp;quot;thepassword&amp;quot;&lt;br /&gt;
expect {&lt;br /&gt;
        password: {send &amp;quot;$pass\r&amp;quot; ; exp_continue}&lt;br /&gt;
        eof exit&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Within a shell script set up simultaneous output to both terminal and a file using a FIFO (named pipes)===&lt;br /&gt;
or &amp;quot;How to send shell output to screen/stdout as well as to a logfile using tee and redirection with exec&amp;quot;&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
examples [http://www.unix.com/shell-programming-and-scripting/85584-redirect-within-ksh.html here on unix.com]&lt;br /&gt;
* general info on redirections [http://www.catonmat.net/blog/bash-one-liners-explained-part-three/ here at catonmat.net]&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/ksh&lt;br /&gt;
&lt;br /&gt;
REDIR=test.redir&lt;br /&gt;
FIFO=test.pipe&lt;br /&gt;
[[ -e $FIFO ]] || mkfifo $FIFO&lt;br /&gt;
&lt;br /&gt;
# make a new channel(3) and copy channel 1&amp;#039;s destination as its own (does NOT POINT TO channel 1&amp;#039;s destination)&lt;br /&gt;
# this allows the normal output to continue to STDOUT but also get printed to whatever file is attached to channel 3&lt;br /&gt;
exec 3&amp;gt;&amp;amp;1&lt;br /&gt;
&lt;br /&gt;
# anything coming in on the pipe, send it to $REDIR and to channel 3&lt;br /&gt;
tee $REDIR &amp;lt;$FIFO &amp;gt;&amp;amp;3 &amp;amp;&lt;br /&gt;
&lt;br /&gt;
# redirect STDOUT to the pipe&lt;br /&gt;
exec &amp;gt; $FIFO&lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;going to default output&amp;quot;&lt;br /&gt;
echo &amp;quot;forcing to channel 1&amp;quot; &amp;gt;&amp;amp;1&lt;br /&gt;
echo &amp;quot;forcing to channel 2&amp;quot; &amp;gt;&amp;amp;2&lt;br /&gt;
echo &amp;quot;forcing to channel 3&amp;quot; &amp;gt;&amp;amp;3&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====More elaborate example====&lt;br /&gt;
found [http://stackoverflow.com/questions/2288939/create-a-pipe-that-writes-to-multiple-files-tee here on stackoverflow]&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/sh&lt;br /&gt;
&lt;br /&gt;
# Author: Harvey Chapman &amp;lt;hchapman _AT_ 3gfp.com&amp;gt;&lt;br /&gt;
# Description: POSIX shell functions that can be used with tee to simultaneously put&lt;br /&gt;
#              stderr and stdout to both a file and stdout&lt;br /&gt;
#&lt;br /&gt;
# Based on:&lt;br /&gt;
#    Re: How to redirect stderr and stdout to a file plus display at the same time&lt;br /&gt;
#    http://www.travishartwell.net/blog/2006/08/19_2220&lt;br /&gt;
&lt;br /&gt;
#&lt;br /&gt;
# Original example function from Travis Hartwell&amp;#039;s blog.&lt;br /&gt;
# Note: I&amp;#039;ve made minor changes to it.&lt;br /&gt;
example()&lt;br /&gt;
{&lt;br /&gt;
  OUTPUT_LOG=output.log&lt;br /&gt;
  OUTPUT_PIPE=output.pipe&lt;br /&gt;
&lt;br /&gt;
  # This should really be -p to test that it&amp;#039;s a pipe.&lt;br /&gt;
  if [ ! -e $OUTPUT_PIPE ]; then&lt;br /&gt;
      mkfifo $OUTPUT_PIPE&lt;br /&gt;
  fi&lt;br /&gt;
&lt;br /&gt;
  # This should really be -f to test that it&amp;#039;s a regular file.&lt;br /&gt;
  if [ -e $OUTPUT_LOG ]; then&lt;br /&gt;
      rm $OUTPUT_LOG&lt;br /&gt;
  fi&lt;br /&gt;
&lt;br /&gt;
  exec 3&amp;gt;&amp;amp;1 4&amp;gt;&amp;amp;2&lt;br /&gt;
  tee $OUTPUT_LOG &amp;lt; $OUTPUT_PIPE &amp;gt;&amp;amp;3 &amp;amp;&lt;br /&gt;
  tpid=$!&lt;br /&gt;
  exec &amp;gt; $OUTPUT_PIPE 2&amp;gt;&amp;amp;1&lt;br /&gt;
&lt;br /&gt;
  echo &amp;quot;This is on standard out&amp;quot;&lt;br /&gt;
  echo &amp;quot;This is on standard err&amp;quot; &amp;gt;&amp;amp;2&lt;br /&gt;
&lt;br /&gt;
  exec 1&amp;gt;&amp;amp;3 3&amp;gt;&amp;amp;- 2&amp;gt;&amp;amp;4 4&amp;gt;&amp;amp;-&lt;br /&gt;
  wait $tpid&lt;br /&gt;
&lt;br /&gt;
  rm $OUTPUT_PIPE&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
# A slightly reduced version of example()&lt;br /&gt;
example2()&lt;br /&gt;
{&lt;br /&gt;
  OUTPUT_LOG=output.log&lt;br /&gt;
  OUTPUT_PIPE=output.pipe&lt;br /&gt;
&lt;br /&gt;
  rm -f $OUTPUT_PIPE&lt;br /&gt;
  mkfifo $OUTPUT_PIPE&lt;br /&gt;
  rm -f $OUTPUT_LOG&lt;br /&gt;
&lt;br /&gt;
  tee $OUTPUT_LOG &amp;lt; $OUTPUT_PIPE &amp;amp;&lt;br /&gt;
  tpid=$!&lt;br /&gt;
&lt;br /&gt;
  exec 3&amp;gt;&amp;amp;1 4&amp;gt;&amp;amp;2 &amp;gt;$OUTPUT_PIPE 2&amp;gt;&amp;amp;1&lt;br /&gt;
&lt;br /&gt;
  echo &amp;quot;This is on standard out&amp;quot;&lt;br /&gt;
  echo &amp;quot;This is on standard err&amp;quot; &amp;gt;&amp;amp;2&lt;br /&gt;
&lt;br /&gt;
  exec 1&amp;gt;&amp;amp;3 3&amp;gt;&amp;amp;- 2&amp;gt;&amp;amp;4 4&amp;gt;&amp;amp;-&lt;br /&gt;
  wait $tpid&lt;br /&gt;
  rm -f $OUTPUT_PIPE&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
#&lt;br /&gt;
# Logging methods based on above. See the example below for how to use them.&lt;br /&gt;
#&lt;br /&gt;
&lt;br /&gt;
# Usage: start_logging [delete_existing_logfile]&lt;br /&gt;
start_logging()&lt;br /&gt;
{&lt;br /&gt;
  # Check to see if OUTPUT_LOG and OUTPUT_PIPE need to be defined.&lt;br /&gt;
  if [ -z &amp;quot;$OUTPUT_LOG&amp;quot; ]; then&lt;br /&gt;
    OUTPUT_LOG=output.log&lt;br /&gt;
  fi&lt;br /&gt;
  if [ -z &amp;quot;$OUTPUT_PIPE&amp;quot; ]; then&lt;br /&gt;
    OUTPUT_PIPE=output.pipe&lt;br /&gt;
  fi&lt;br /&gt;
  # Make sure that we&amp;#039;re not already logging.&lt;br /&gt;
  if [ -n &amp;quot;$OUTPUT_PID&amp;quot; ]; then&lt;br /&gt;
    echo &amp;quot;Logging already started!&amp;quot;&lt;br /&gt;
    return 1&lt;br /&gt;
  fi&lt;br /&gt;
&lt;br /&gt;
  # Always remove the log and pipe first.&lt;br /&gt;
  rm -f $OUTPUT_PIPE&lt;br /&gt;
  # Delete the logfile first if told to.&lt;br /&gt;
  if [ &amp;quot;$1&amp;quot; = delete_existing_logfile ]; then&lt;br /&gt;
    rm -f $OUTPUT_LOG&lt;br /&gt;
  fi&lt;br /&gt;
&lt;br /&gt;
  mkfifo $OUTPUT_PIPE&lt;br /&gt;
  tee -a $OUTPUT_LOG &amp;lt; $OUTPUT_PIPE &amp;amp;&lt;br /&gt;
  OUTPUT_PID=$!&lt;br /&gt;
&lt;br /&gt;
  exec 3&amp;gt;&amp;amp;1 4&amp;gt;&amp;amp;2 &amp;gt;$OUTPUT_PIPE 2&amp;gt;&amp;amp;1&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
stop_logging()&lt;br /&gt;
{&lt;br /&gt;
  # Make sure that we&amp;#039;re currently logging.&lt;br /&gt;
  if [ -z &amp;quot;$OUTPUT_PID&amp;quot; ]; then&lt;br /&gt;
    echo &amp;quot;Logging not yet started!&amp;quot;&lt;br /&gt;
    return 1&lt;br /&gt;
  fi&lt;br /&gt;
  exec 1&amp;gt;&amp;amp;3 3&amp;gt;&amp;amp;- 2&amp;gt;&amp;amp;4 4&amp;gt;&amp;amp;-&lt;br /&gt;
  wait $OUTPUT_PID&lt;br /&gt;
  rm -f $OUTPUT_PIPE&lt;br /&gt;
  unset OUTPUT_PID&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
example3()&lt;br /&gt;
{&lt;br /&gt;
  start_logging&lt;br /&gt;
  #start_logging delete_existing_logfile&lt;br /&gt;
  echo &amp;quot;This is on standard out&amp;quot;&lt;br /&gt;
  echo &amp;quot;This is on standard err&amp;quot; &amp;gt;&amp;amp;2&lt;br /&gt;
  stop_logging&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===RedHat root filesystem has gone read-only===&lt;br /&gt;
* [http://www.unixarena.com/2013/09/redhat-linux-how-to-fix-read-only-root.html How to fix read only root file system]&lt;br /&gt;
&lt;br /&gt;
===Kill all processes for a user===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
for prc in `ps -ef | grep -E &amp;quot;^ +[o]racle&amp;quot; | awk &amp;#039;{print $2}&amp;#039;`; do&lt;br /&gt;
    kill $prc&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===isRGHere===&lt;br /&gt;
Checks if resource group is on this leg of an HACMP cluster. Returns 0 if true else 1.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/usr/bin/ksh&lt;br /&gt;
&lt;br /&gt;
SCRIPT=`basename $0`&lt;br /&gt;
&lt;br /&gt;
function rctest&lt;br /&gt;
{&lt;br /&gt;
exitcode=$1&lt;br /&gt;
msg=$2&lt;br /&gt;
if [ $exitcode -ne 0 ]; then&lt;br /&gt;
        echo &amp;quot;********************************************************************************&amp;quot;&lt;br /&gt;
        echo &amp;quot;\nScript $SCRIPT finished with errors.&amp;quot;&lt;br /&gt;
        echo &amp;quot;$msg.&amp;quot;&lt;br /&gt;
        echo &amp;quot;Returncode : $exitcode.&amp;quot;&lt;br /&gt;
        echo &amp;quot;\n********************************************************************************&amp;quot;&lt;br /&gt;
&lt;br /&gt;
        fi&lt;br /&gt;
exit $exitcode&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
RGINFO=/usr/es/sbin/cluster/utilities/clRGinfo&lt;br /&gt;
[[ ! -f $RGINFO ]] &amp;amp;&amp;amp;  rctest 1 &amp;quot;clRGinfo not found&amp;quot;&lt;br /&gt;
&lt;br /&gt;
if [ $# -eq 1 ]&lt;br /&gt;
then&lt;br /&gt;
        RG=`echo $1 | cut -c 1-14`&lt;br /&gt;
else&lt;br /&gt;
        rctest 10  &amp;quot;Usage: `basename $0` &amp;lt;RG name&amp;gt;&amp;quot;&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
$RGINFO |grep -qwp $RG ||  rctest 9 &amp;quot;$RG is not defined&amp;quot;&lt;br /&gt;
&lt;br /&gt;
THISNODE=`/usr/es/sbin/cluster/utilities/get_local_nodename | cut -c 1-14`&lt;br /&gt;
$RGINFO |grep -wp $RG |grep -w $THISNODE |grep -wq ONLINE&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===AIX: add a user to a group===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
chgrpmem -m + oracle ibmtls&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Find swear words in scripts by comparing it to a list found on the internet===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
wget &amp;quot;http://www.bannedwordlist.com/lists/swearWords.csv&amp;quot; -O /tmp/s ; for word in $(cat /tmp/s | sed -e &amp;#039;s/ /_/g&amp;#039; -e &amp;#039;s/,/ /g&amp;#039;) ; do grep -wR $word *; done | less&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===grep -p (for paragraph) works on AIX but not on Linux or Solaris===&lt;br /&gt;
Use awk instead&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
awk &amp;#039;BEGIN {FS=&amp;quot;\n&amp;quot; RS=&amp;quot;\n\n&amp;quot;} /search pattern/ { do something }&amp;#039; &amp;lt;file&amp;gt;&lt;br /&gt;
/usr/xpg4/bin/awk &amp;#039;BEGIN {RS=&amp;quot;\n\n&amp;quot;;FS=&amp;quot;\n&amp;quot;} /AGRHDWQ1/ {print $2}&amp;#039; dsm.sys | awk &amp;#039;{print $NF}&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
this prints the last word of the second &amp;#039;&amp;#039;line&amp;#039;&amp;#039; in the paragraph in dsm.sys that contains the search term AGRHDWQ1.&amp;lt;br /&amp;gt;&lt;br /&gt;
Or slightly simpler...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
awk -v RS=&amp;#039;&amp;#039; &amp;#039;/NHAPPLP1/&amp;#039; /etc/tsm/dsm.sys     # (use /usr/xpg4/bin/awk on Solaris)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or, case insensitively:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
awk -v RS=&amp;#039;&amp;#039; &amp;#039;tolower($0) ~/so_u_clubqa_orx_d_cab/&amp;#039; /etc/tsm/dsm.sys&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Using -v means you don&amp;#039;t have to use a BEGIN section.&lt;br /&gt;
&lt;br /&gt;
===debug/redirect log of a shell===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/usr/bin/ksh&lt;br /&gt;
exec 2&amp;gt;/tmp/mytest&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Different ways of Iteration in korn shell with a while loop===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
IFS=&amp;quot;|&amp;quot;&lt;br /&gt;
exec 0&amp;lt;$statfile&lt;br /&gt;
while read host db started stopped&lt;br /&gt;
do&lt;br /&gt;
    rrdfile=&amp;quot;export_duration_${host}_${db}.rrd&amp;quot;&lt;br /&gt;
    $RRDTOOL update ${RRDDIR}/${rrdfile} $started:$started $stopped&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
while read host db started stopped&lt;br /&gt;
do&lt;br /&gt;
    rrdfile=&amp;quot;export_duration_${host}_${db}.rrd&amp;quot;&lt;br /&gt;
    $RRDTOOL update ${RRDDIR}/${rrdfile} $started:$started $stopped&lt;br /&gt;
done &amp;lt;statfile&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    cat $statfile | sort -nk4 | while IFS=\| read host db type started stopped&lt;br /&gt;
    do&lt;br /&gt;
        [[ &amp;quot;$stopped&amp;quot; == &amp;quot;&amp;quot; ]] &amp;amp;&amp;amp; continue&lt;br /&gt;
        rrdfile=&amp;quot;export_duration_${host}_${db}.rrd&amp;quot;&lt;br /&gt;
        $RRDTOOL update ${RRDDIR}/${rrdfile} ${started}:${started}:${stopped}&lt;br /&gt;
        [[ $? -ne 0 ]] &amp;amp;&amp;amp; echo &amp;quot;nok: $?&amp;quot;&lt;br /&gt;
    done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Filesystem 100% full, what&amp;#039;s taking up all the space?===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
find /oracle/endur -xdev -ls|sort -nr +6|head&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/dev/esb01fs010001      1.00      0.00  100%     1838    69% /oracle&lt;br /&gt;
beuxdsysesb01:root[/root]# cd /oracle&lt;br /&gt;
beuxdsysesb01:root[/oracle]# du -gsx * | sort -n&lt;br /&gt;
0.00    checkpoints&lt;br /&gt;
0.00    flash_recovery_area&lt;br /&gt;
0.00    lost+found&lt;br /&gt;
0.00    oraInst.loc&lt;br /&gt;
0.00    oraInventory&lt;br /&gt;
0.09    admin&lt;br /&gt;
0.99    diag&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
cd  diag and repeat until culprits are found&lt;br /&gt;
&lt;br /&gt;
===Show paged memory hogs on AIX===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
svmon -Pt20 | perl -e &amp;#039;while(&amp;lt;&amp;gt;){print if($.==2||$&amp;amp;&amp;amp;&amp;amp;!$s++);$.=0 if(/^-+$/)}&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Capitalise the first letter of a word in Korn Shell===&lt;br /&gt;
Not as easy as it sounds if it needs to work in non-ksh93 shells&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
function capit { &lt;br /&gt;
    typeset -u first&lt;br /&gt;
    first=${1%&amp;quot;${1#?}&amp;quot;}&lt;br /&gt;
    printf &amp;quot;%s\n&amp;quot; &amp;quot;${first}${1#?}&amp;quot;&lt;br /&gt;
    return 0&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or maybe more neatly done in Perl...&amp;lt;br /&amp;gt;&lt;br /&gt;
This will capitalise each word in a sentence passed into it&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
function capit { &lt;br /&gt;
    echo &amp;quot;$1&amp;quot; |  perl -pe &amp;quot;s/([\w&amp;#039;]+)/\u\L\1/g&amp;quot;&lt;br /&gt;
    return 0&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Remove / rename a directory / file containing weird control characters===&lt;br /&gt;
Use ls with -i to see inode listing&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ls -bali&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Use find with -inum to get the filename and -exec to remove it&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
find . -inum &amp;lt;inode from ls listing&amp;gt; -exec rm -f {} \;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Run a local script on a remote host===&lt;br /&gt;
Doing it this way means we do not need to scp the shell over to the host before executing it!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ssh user@host &amp;#039;sh&amp;#039; &amp;lt; your_script.sh&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
First of all, this command is a redirection: your shell will open the file your_script.sh and feed it as input to the ssh command. ssh, in turn, will tunnel its stdin to the remote command, namely, sh instance. And sh without arguments reads its script from stdin. So we got sh instance, which is launched on remote host, but reads commands from your local file.&lt;br /&gt;
&lt;br /&gt;
===Get a list of running instances - but only those started by the current user===&lt;br /&gt;
This is the way I wanted to do it but there&amp;#039;s an issue. Where does that spare } character come from? Anyone?&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ps -ef | grep [p]mon | awk -v dbowner=$(id -un) &amp;#039;{ if ($1==dbowner) { gsub(/ora_pmon_/,&amp;quot;&amp;quot;,$NF); print $NF; } }&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
ps listing&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ ps -ef | grep [p]mon&lt;br /&gt;
  oracle 13304024        1   0   Jun 07      -  2:39 ora_pmon_reportk&lt;br /&gt;
  oracle 26018178        1   0   Jun 07      -  3:01 ora_pmon_dwh_perf&lt;br /&gt;
  oracle 29229432        1   0   Jun 07      -  2:30 ora_pmon_adso&lt;br /&gt;
 oraebso 18022994        1   0   Jun 07      -  2:38 ora_pmon_EBSO&lt;br /&gt;
  oracle 30278192        1   0   Jun 07      -  2:48 ora_pmon_owb112k&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Results of above command&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
reportk&lt;br /&gt;
dwh_perf&lt;br /&gt;
adso&lt;br /&gt;
}&lt;br /&gt;
owb112k&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Workaround 1. Send the ps listing to a file and work on it without pipes. Works but it&amp;#039;s a bit long-winded especially as we have to clean up afterwards.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ps -ef | grep [p]mon&amp;gt;/tmp/results.$$ 2&amp;gt;/dev/null; awk -v dbowner=$(id -un) &amp;#039;{ if ($1==dbowner) { gsub(/ora_pmon_/,&amp;quot;&amp;quot;,$NF); print $NF; } }&amp;#039; /tmp/results.$$; rm -f /tmp/results.$$&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Workaround 2. Don&amp;#039;t like the grep -v but until I find out where that } is coming from..&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ps -ef | grep [p]mon | awk -v dbowner=$(id -un) &amp;#039;{ if ($1==dbowner) { gsub(/ora_pmon_/,&amp;quot;&amp;quot;,$NF); print $NF; } }&amp;#039; | egrep -v &amp;#039;grep|}|ASM&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Return a list of Oracle databases running on a list of remote servers===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/ksh&lt;br /&gt;
&lt;br /&gt;
serverlist=`cat /home/tools/ini/system/oracle_servers | sort -n | tr &amp;quot;\n&amp;quot; &amp;quot; &amp;quot;`&lt;br /&gt;
&lt;br /&gt;
if [ -z &amp;quot;${serverlist}&amp;quot; ]&lt;br /&gt;
then&lt;br /&gt;
    echo &amp;quot;no servers found&amp;quot; &amp;amp;&amp;amp; exit 1&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
for server in ${serverlist}&lt;br /&gt;
do&lt;br /&gt;
    ssh ${server} &amp;quot;ps -ef | grep [o]ra_pmon_&amp;quot; &amp;gt;/tmp/${server}.dblist&lt;br /&gt;
done&lt;br /&gt;
&lt;br /&gt;
for server in ${serverlist}&lt;br /&gt;
do&lt;br /&gt;
    cat /tmp/${server}.dblist | awk -F_ -v SRV=${server} &amp;#039;BEGIN {print SRV &amp;quot;:&amp;quot;} {print $NF}&amp;#039; | tr &amp;quot;\n&amp;quot; &amp;quot; &amp;quot;&lt;br /&gt;
    echo&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Clever trick to check whether SQL output needs sending to someone===&lt;br /&gt;
Using an exit status from SQL*Plus back to the shell so we can decide what to do.  Nice one!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
tempfile=/tmp/audit_locked_accounts_$ORACLE_SID.txt&lt;br /&gt;
&lt;br /&gt;
# Start sqlplus and check for locked accounts&lt;br /&gt;
sqlplus -S &amp;quot;/ as sysdba&amp;quot; &amp;lt;&amp;lt; EOF &amp;gt; $tempfile&lt;br /&gt;
set pages 0&lt;br /&gt;
select &amp;#039;The following accounts were found to be unlocked and should not be&amp;#039;&lt;br /&gt;
from dual;&lt;br /&gt;
&lt;br /&gt;
def exit_status = 0&lt;br /&gt;
col xs new_value exit_status&lt;br /&gt;
&lt;br /&gt;
select username&lt;br /&gt;
,      account_status&lt;br /&gt;
,      1 as xs&lt;br /&gt;
from   dba_users&lt;br /&gt;
where  account_status != &amp;#039;LOCKED&amp;#039;&lt;br /&gt;
and    username in (&amp;#039;HR&amp;#039;, &amp;#039;SCOTT&amp;#039;, &amp;#039;OUTLN&amp;#039;, &amp;#039;MDSYS&amp;#039;, &amp;#039;CTXSYS&amp;#039;)&lt;br /&gt;
/&lt;br /&gt;
exit &amp;amp;exit_status&lt;br /&gt;
EOF&lt;br /&gt;
&lt;br /&gt;
# If the exit status of sqlplus was not 0 then we will send an email&lt;br /&gt;
if [ $? != 0 ]; then&lt;br /&gt;
    mail -s &amp;quot;Accounts Unlocked in $ORACLE_SID&amp;quot; oracle &amp;lt; $tempfile&lt;br /&gt;
fi&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Check RMAN logfiles for errors from cron every day===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
00 09 * * * /home/tools/scripts/oracle/dosh &amp;#039;find /home/tools/logs/rman -name &amp;quot;*online.log&amp;quot; -mtime -1 -exec sed -ne &amp;quot;/^RMAN-/,/^$/p&amp;quot; {} \\; -ls&amp;#039; | mailx&lt;br /&gt;
 -s &amp;#039;RMAN errors last night&amp;#039; stuart@domain.com&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/home/ibmtools/scripts/oracle/dosh &amp;#039;find /oracle/export -name &amp;quot;expdp*log&amp;quot; -mtime -1 -exec grep ORA- {} \; -ls&amp;#039; | mailx -s &amp;#039;Datapump errors for Baxter last night&amp;#039; stuart@domain.com&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===An alternative to getopts===&lt;br /&gt;
These methods have the advantage of allowing arguments of any length not just 1 character&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
countArgs=$#&lt;br /&gt;
while [[ $# -gt 0 ]]&lt;br /&gt;
do&lt;br /&gt;
    idx1=$($ECHO $1|$GREP &amp;quot;=&amp;quot;|wc -l)&lt;br /&gt;
    if [[ $idx1 -gt 0 ]]; then&lt;br /&gt;
        key=$($ECHO $1|$CUT -d &amp;#039;=&amp;#039; -f 1)&lt;br /&gt;
        value=$($ECHO $1|$CUT -d &amp;#039;=&amp;#039; -f 2)&lt;br /&gt;
    else&lt;br /&gt;
        key=$($ECHO $1|$CUT -d &amp;#039;=&amp;#039; -f 1)&lt;br /&gt;
        idx2=$($ECHO $1|$GREP &amp;quot;^-&amp;quot;|wc -l)&lt;br /&gt;
        if [[ $idx2 -eq 0 ]]; then&lt;br /&gt;
            $ECHO -e &amp;quot;\n ERROR: $1 is an unsupported argument passed to agentDeploy.sh.\n&amp;quot;  &lt;br /&gt;
            usage&lt;br /&gt;
            exit 1&lt;br /&gt;
        fi&lt;br /&gt;
    fi&lt;br /&gt;
&lt;br /&gt;
    case &amp;quot;$key&amp;quot; in&lt;br /&gt;
    -help)&lt;br /&gt;
        if [[ $upgradeFlag ]]; then&lt;br /&gt;
            upgradeUsage&lt;br /&gt;
        else&lt;br /&gt;
            freshUsage&lt;br /&gt;
        fi&lt;br /&gt;
        exit 0;;&lt;br /&gt;
    AGENT_BASE_DIR)&lt;br /&gt;
        agentBaseDir=$($ECHO $value|$SED &amp;#039;s/\/$//&amp;#039;)&lt;br /&gt;
        checkBaseFlag=TRUE;;&lt;br /&gt;
    OMS_HOST)&lt;br /&gt;
        omsHost=$value&lt;br /&gt;
        checkOMSHost=TRUE;;&lt;br /&gt;
    EM_UPLOAD_PORT)&lt;br /&gt;
        omsPort=$value&lt;br /&gt;
        checkOMSPort=TRUE;;&lt;br /&gt;
    AGENT_INSTANCE_HOME)&lt;br /&gt;
        instHome=$($ECHO $value | $SED &amp;#039;s/\/$//&amp;#039;);;&lt;br /&gt;
    AGENT_REGISTRATION_PASSWORD)&lt;br /&gt;
        pswd=$value;;&lt;br /&gt;
    s_encrSecurePwd)&lt;br /&gt;
        pswd=$value;;  &lt;br /&gt;
    RESPONSE_FILE)&lt;br /&gt;
        rspFlag=TRUE  &lt;br /&gt;
        rspLoc=$value;;&lt;br /&gt;
    OLD_AGENT_VERSION)&lt;br /&gt;
        oldAgentVersion=$value;;            &lt;br /&gt;
    OLDHOME)&lt;br /&gt;
        oldHome=$value;;    &lt;br /&gt;
    -debug)&lt;br /&gt;
        debugSwitch=TRUE;;&lt;br /&gt;
    -forceConfigure)&lt;br /&gt;
        forceFlag=TRUE;;&lt;br /&gt;
    -configOnly)&lt;br /&gt;
        configFlag=TRUE    &lt;br /&gt;
        validationFlag=TRUE;;&lt;br /&gt;
    -agentImageLocation)&lt;br /&gt;
        archiveLoc=$value&lt;br /&gt;
        checkArchiveFlag=TRUE;;&lt;br /&gt;
    -invPtrLoc) shift&lt;br /&gt;
        ptrLoc=$1;;&lt;br /&gt;
    -Upgrade)&lt;br /&gt;
        UpgradeFlag=TRUE&lt;br /&gt;
        validFlag=TRUE;;&lt;br /&gt;
    INVENTORY_LOCATION)&lt;br /&gt;
        validFlag=TRUE;;&lt;br /&gt;
    b_forceInstCheck)&lt;br /&gt;
        validFlag=TRUE&lt;br /&gt;
        forcefullFlag=TRUE;;&lt;br /&gt;
    -prereqOnly)&lt;br /&gt;
        validationFlag=TRUE&lt;br /&gt;
        prereqFlag=TRUE;;&lt;br /&gt;
    -executeRootsh)&lt;br /&gt;
        validFlag=TRUE;;&lt;br /&gt;
    *)  idx=$($ECHO $1|$GREP &amp;quot;^-&amp;quot;|wc -l)&lt;br /&gt;
        if [[ $idx -eq 0 ]]; then&lt;br /&gt;
            validFlag=TRUE&lt;br /&gt;
        else&lt;br /&gt;
            $ECHO -e &amp;quot;\n ERROR: Invalid argument $key passed.&amp;quot;&lt;br /&gt;
            usage&lt;br /&gt;
            exit 1          &lt;br /&gt;
        fi&lt;br /&gt;
    esac&lt;br /&gt;
    shift&lt;br /&gt;
done&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
another way - found in /etc/init.d/functions (daemon function) in Fedora&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    while [ &amp;quot;$1&amp;quot; != &amp;quot;${1##[-+]}&amp;quot; ]; do&lt;br /&gt;
        case $1 in&lt;br /&gt;
        &amp;#039;&amp;#039;)&lt;br /&gt;
            echo $&amp;quot;$0: Usage: daemon [+/-nicelevel] {program}&amp;quot; &amp;quot;[arg1]...&amp;quot;&lt;br /&gt;
            return 1&lt;br /&gt;
            ;;&lt;br /&gt;
        --check)&lt;br /&gt;
            base=$2&lt;br /&gt;
            gotbase=&amp;quot;yes&amp;quot;&lt;br /&gt;
            shift 2&lt;br /&gt;
            ;;&lt;br /&gt;
        --check=?*)&lt;br /&gt;
            base=${1#--check=}&lt;br /&gt;
            gotbase=&amp;quot;yes&amp;quot;&lt;br /&gt;
            shift&lt;br /&gt;
            ;;&lt;br /&gt;
        --user)&lt;br /&gt;
            user=$2&lt;br /&gt;
            shift 2&lt;br /&gt;
            ;;&lt;br /&gt;
        --user=?*)&lt;br /&gt;
            user=${1#--user=}&lt;br /&gt;
            shift&lt;br /&gt;
            ;;&lt;br /&gt;
        --pidfile)&lt;br /&gt;
            pid_file=$2&lt;br /&gt;
            shift 2&lt;br /&gt;
            ;;&lt;br /&gt;
        --pidfile=?*)&lt;br /&gt;
            pid_file=${1#--pidfile=}&lt;br /&gt;
            shift&lt;br /&gt;
            ;;&lt;br /&gt;
        --force)&lt;br /&gt;
            force=&amp;quot;force&amp;quot;&lt;br /&gt;
            shift&lt;br /&gt;
            ;;&lt;br /&gt;
        [-+][0-9]*)&lt;br /&gt;
            nice=&amp;quot;nice -n $1&amp;quot;&lt;br /&gt;
            shift&lt;br /&gt;
            ;;&lt;br /&gt;
        *)&lt;br /&gt;
            echo $&amp;quot;$0: Usage: daemon [+/-nicelevel] {program}&amp;quot; &amp;quot;[arg1]...&amp;quot;&lt;br /&gt;
            return 1&lt;br /&gt;
            ;;&lt;br /&gt;
      esac&lt;br /&gt;
    done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
another way - found in adstrtal.sh (middleware start script for EBS)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#&lt;br /&gt;
# Parse Arguments&lt;br /&gt;
#&lt;br /&gt;
&lt;br /&gt;
for nxtarg in $*&lt;br /&gt;
do&lt;br /&gt;
  arg=`echo $nxtarg | sed &amp;#039;s/^//&amp;#039;`&lt;br /&gt;
&lt;br /&gt;
  case $arg in&lt;br /&gt;
    -secureapps)    if test &amp;quot;$secureapps&amp;quot; = &amp;quot;&amp;quot; ; then&lt;br /&gt;
                       secureapps=$arg&lt;br /&gt;
                    else&lt;br /&gt;
                       echo &amp;quot;$0: Duplicate Argument passed : $arg&amp;quot;&lt;br /&gt;
                       usage&lt;br /&gt;
                    fi&lt;br /&gt;
                ;;&lt;br /&gt;
    -nodbchk)       if test &amp;quot;$nodbchk&amp;quot; = &amp;quot;&amp;quot; ; then&lt;br /&gt;
                       nodbchk=$arg&lt;br /&gt;
                    else&lt;br /&gt;
                       echo &amp;quot;$0: Duplicate Argument passed : $arg&amp;quot;&lt;br /&gt;
                       usage&lt;br /&gt;
                    fi&lt;br /&gt;
                ;;&lt;br /&gt;
    -nopromptmsg)   if test &amp;quot;$nopromptmsg&amp;quot; = &amp;quot;&amp;quot; ; then&lt;br /&gt;
                       nopromptmsg=$arg&lt;br /&gt;
                    else&lt;br /&gt;
                       echo &amp;quot;$0: Duplicate Argument passed : $arg&amp;quot;&lt;br /&gt;
                       usage&lt;br /&gt;
                    fi&lt;br /&gt;
                ;;&lt;br /&gt;
    *)              if test &amp;quot;$unpw&amp;quot; = &amp;quot;&amp;quot; ; then&lt;br /&gt;
                       unpw=$arg&lt;br /&gt;
                    else&lt;br /&gt;
                       echo &amp;quot;$0: Duplicate Argument passed : $arg&amp;quot;&lt;br /&gt;
                       usage&lt;br /&gt;
                    fi&lt;br /&gt;
  esac&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
and another in adautocfg.sh&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
for myarg in $*&lt;br /&gt;
do&lt;br /&gt;
&lt;br /&gt;
  arg=`echo $myarg | sed &amp;#039;s/^-//&amp;#039;`&lt;br /&gt;
  case $arg in&lt;br /&gt;
    appspass=*)&lt;br /&gt;
            appspass=`echo $arg | sed &amp;#039;s/appspass=//g&amp;#039;`&lt;br /&gt;
            shift&lt;br /&gt;
            ;;&lt;br /&gt;
    nocustom)&lt;br /&gt;
            myparams=&amp;quot;$myparams $arg&amp;quot;&lt;br /&gt;
            shift&lt;br /&gt;
            ;;&lt;br /&gt;
    noversionchecks)&lt;br /&gt;
            myparams=&amp;quot;$myparams $arg&amp;quot;&lt;br /&gt;
            shift&lt;br /&gt;
            ;;&lt;br /&gt;
    promptmsg=*)&lt;br /&gt;
            promptmsg=`echo $arg | sed &amp;#039;s/promptmsg=//g&amp;#039;`&lt;br /&gt;
            shift&lt;br /&gt;
            ;;&lt;br /&gt;
        *)  echo &amp;quot;$0: unrecognized action specified&amp;quot;&lt;br /&gt;
            exit 1&lt;br /&gt;
  esac&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Run a script on multiple servers===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/ksh&lt;br /&gt;
# ==============================================================================&lt;br /&gt;
# Name         : dosh   (Distributed Oracle SHell)&lt;br /&gt;
# Description  : Runs a command on all Oracle servers&lt;br /&gt;
#&lt;br /&gt;
# Parameters   : h - displays help&lt;br /&gt;
#                v - verbose (default, like all unix commands is silent)&lt;br /&gt;
#                c - command to be executed&lt;br /&gt;
#&lt;br /&gt;
# Example      : ./dosh -v -c &amp;#039;ls -al&amp;#039;&lt;br /&gt;
#&lt;br /&gt;
# Modification History&lt;br /&gt;
# ====================&lt;br /&gt;
# When      Who               What&lt;br /&gt;
# ========= ================= ==================================================&lt;br /&gt;
# 08-FEB-13 Stuart Barkley    Created&lt;br /&gt;
# ==============================================================================&lt;br /&gt;
&lt;br /&gt;
# --------------------------------------------------------------------------&lt;br /&gt;
# this list of servers is generated by the DBAMON tool so will be up to date&lt;br /&gt;
# --------------------------------------------------------------------------&lt;br /&gt;
serverfile=/home/ibmtools/etc/oracle/oracle_servers&lt;br /&gt;
[[ -z &amp;quot;${serverfile}&amp;quot; ]] &amp;amp;&amp;amp; echo &amp;quot;Server list ${serverfile} not found&amp;quot; &amp;amp;&amp;amp; exit 1&lt;br /&gt;
&lt;br /&gt;
serverlist=`cat ${serverfile} | sort -n | tr &amp;quot;\n&amp;quot; &amp;quot; &amp;quot;`&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
# -------------------------&lt;br /&gt;
# get the arguments, if any&lt;br /&gt;
# -------------------------&lt;br /&gt;
while getopts &amp;quot;hvc:&amp;quot; OPT&lt;br /&gt;
do&lt;br /&gt;
    case &amp;quot;$OPT&amp;quot; in&lt;br /&gt;
    h) echo &amp;quot;\nUsage: $0 [-v] [-h] -c &amp;#039;&amp;lt;command_to_be_executed_remotely&amp;gt;&amp;#039;\n&amp;quot;;&lt;br /&gt;
       exit;&lt;br /&gt;
       ;;&lt;br /&gt;
    v) VERBOSE=&amp;quot;Y&amp;quot;;&lt;br /&gt;
       ;;&lt;br /&gt;
    c) CMMND=$OPTARG;&lt;br /&gt;
       ;;&lt;br /&gt;
    *) echo &amp;quot;\nUsage: $0 [-v] [-h] -c &amp;#039;&amp;lt;command_to_be_executed_remotely&amp;gt;&amp;#039;\n&amp;quot;;&lt;br /&gt;
       exit;&lt;br /&gt;
       ;;&lt;br /&gt;
    esac&lt;br /&gt;
done&lt;br /&gt;
shift $((OPTIND-1))&lt;br /&gt;
VERBOSE=${VERBOSE:-&amp;quot;N&amp;quot;}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
# --------------------------------&lt;br /&gt;
# check we have required arguments&lt;br /&gt;
# --------------------------------&lt;br /&gt;
[[ -z $CMMND ]] &amp;amp;&amp;amp; echo &amp;quot;Enter command to be executed like this: $0 -c &amp;#039;ls -al&amp;#039;&amp;quot; &amp;amp;&amp;amp; exit 1&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
# ----------------------------&lt;br /&gt;
# loop over the remote servers&lt;br /&gt;
# ----------------------------&lt;br /&gt;
for server in ${serverlist}&lt;br /&gt;
do&lt;br /&gt;
    if [[ &amp;quot;$VERBOSE&amp;quot; == &amp;quot;Y&amp;quot; ]]; then&lt;br /&gt;
        echo ${server} `date +&amp;#039;%d-%b-%Y %H:%M:%S&amp;#039;`&lt;br /&gt;
        echo &amp;quot;------------------------------------&amp;quot;&lt;br /&gt;
        set -x&lt;br /&gt;
    fi&lt;br /&gt;
    ssh ${server} &amp;quot;$CMMND&amp;quot;&lt;br /&gt;
    set +x&lt;br /&gt;
    [[ &amp;quot;$VERBOSE&amp;quot; == &amp;quot;Y&amp;quot; ]] &amp;amp;&amp;amp; echo&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
to be investigated... this one might be cleverer than mine...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
tmpdir=${TMPDIR:-/tmp}/pssh.$$&lt;br /&gt;
count=0&lt;br /&gt;
while userhost; do&lt;br /&gt;
    ssh -n -o BatchMode=yes ${userhost} &amp;#039;uname -a&amp;#039; &amp;gt; ${tmpdir}/${userhost} 2&amp;gt;&amp;amp;1 &amp;amp;&lt;br /&gt;
    count=`expr $count + 1`&lt;br /&gt;
done &amp;lt; userhost.lst&lt;br /&gt;
while [ $count -gt 0 ]; do&lt;br /&gt;
    wait $pids&lt;br /&gt;
    count=`expr $count - 1`&lt;br /&gt;
done&lt;br /&gt;
echo &amp;quot;Output for hosts are in $tmpdir&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
improved version...&amp;lt;br /&amp;gt;&lt;br /&gt;
just escape double quotes and dollar signs...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/ksh&lt;br /&gt;
# ==============================================================================&lt;br /&gt;
# Name         : dosh   (Distributed Oracle SHell)&lt;br /&gt;
# Description  : Runs a command on all Oracle servers&lt;br /&gt;
#&lt;br /&gt;
# Parameters   : h - displays help&lt;br /&gt;
#                v - verbose (default, like all unix commands is silent)&lt;br /&gt;
#                c - command to be executed&lt;br /&gt;
#&lt;br /&gt;
# Example      : ./dosh -v -c &amp;#039;ls -al&amp;#039;&lt;br /&gt;
#&lt;br /&gt;
# Modification History&lt;br /&gt;
# ====================&lt;br /&gt;
# When      Who               What&lt;br /&gt;
# ========= ================= ==================================================&lt;br /&gt;
# 08-FEB-13 Stuart Barkley    Created&lt;br /&gt;
# 08-JUL-15 Stuart Barkley    Background execution mode&lt;br /&gt;
# ==============================================================================&lt;br /&gt;
# --------------------------------------------------------------------------&lt;br /&gt;
# this list of servers is generated by the DBAMON tool so will be up to date&lt;br /&gt;
# --------------------------------------------------------------------------&lt;br /&gt;
serverfile=/home/ibmtools/etc/oracle/oracle_servers&lt;br /&gt;
[[ -z &amp;quot;${serverfile}&amp;quot; ]] &amp;amp;&amp;amp; echo &amp;quot;Server list ${serverfile} not found&amp;quot; &amp;amp;&amp;amp; exit 1&lt;br /&gt;
&lt;br /&gt;
serverlist=`cat ${serverfile} | sort -n | tr &amp;quot;\n&amp;quot; &amp;quot; &amp;quot;`&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
# -------------------------&lt;br /&gt;
# get the arguments, if any&lt;br /&gt;
# -------------------------&lt;br /&gt;
while getopts &amp;quot;hbvc:&amp;quot; OPT&lt;br /&gt;
do&lt;br /&gt;
    case &amp;quot;$OPT&amp;quot; in&lt;br /&gt;
    h) echo &amp;quot;\nUsage: $0 [-b] [-v] [-h] -c &amp;#039;&amp;lt;command_to_be_executed_remotely&amp;gt;&amp;#039;\n&amp;quot;;&lt;br /&gt;
       exit;&lt;br /&gt;
       ;;&lt;br /&gt;
    b) BACKGROUND=&amp;quot;Y&amp;quot;;&lt;br /&gt;
       ;;&lt;br /&gt;
    v) VERBOSE=&amp;quot;Y&amp;quot;;&lt;br /&gt;
       ;;&lt;br /&gt;
    c) CMMND=$OPTARG;&lt;br /&gt;
       ;;&lt;br /&gt;
    *) echo &amp;quot;\nUsage: $0 [-b] [-v] [-h] -c &amp;#039;&amp;lt;command_to_be_executed_remotely&amp;gt;&amp;#039;\n&amp;quot;;&lt;br /&gt;
       exit;&lt;br /&gt;
       ;;&lt;br /&gt;
    esac&lt;br /&gt;
done&lt;br /&gt;
shift $((OPTIND-1))&lt;br /&gt;
VERBOSE=${VERBOSE:-&amp;quot;N&amp;quot;}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
# --------------------------------&lt;br /&gt;
# check we have required arguments&lt;br /&gt;
# --------------------------------&lt;br /&gt;
[[ -z $CMMND ]] &amp;amp;&amp;amp; echo &amp;quot;Enter command to be executed like this: $0 -c &amp;#039;ls -al&amp;#039;&amp;quot; &amp;amp;&amp;amp; exit 1&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
# ---------------------------------&lt;br /&gt;
# put the thing to be run in a file&lt;br /&gt;
# ---------------------------------&lt;br /&gt;
printf &amp;quot;%s\n&amp;quot; &amp;quot;$CMMND&amp;quot; &amp;gt; /tmp/dosh.$$&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
# ----------------------------&lt;br /&gt;
# loop over the remote servers&lt;br /&gt;
# ----------------------------&lt;br /&gt;
for server in ${serverlist}&lt;br /&gt;
do&lt;br /&gt;
    if [[ &amp;quot;$VERBOSE&amp;quot; == &amp;quot;Y&amp;quot; ]]; then&lt;br /&gt;
        printf &amp;quot;%s\n&amp;quot; ${server} `date +&amp;#039;%d-%b-%Y %H:%M:%S&amp;#039;`&lt;br /&gt;
        printf &amp;quot;%s\n&amp;quot; &amp;quot;------------------------------------&amp;quot;&lt;br /&gt;
        set -x&lt;br /&gt;
    fi&lt;br /&gt;
    scp -q /tmp/dosh.$$ ${server}:/tmp/&lt;br /&gt;
    if [[ &amp;quot;$BACKGROUND&amp;quot; == &amp;quot;Y&amp;quot; ]]; then&lt;br /&gt;
        ssh -n -o BatchMode=yes ${server} &amp;quot;ksh /tmp/dosh.$$; rm -f /tmp/dosh.$$&amp;quot;&amp;gt; /tmp/dosh_${server}.out 2&amp;gt;&amp;amp;1 &amp;amp;&lt;br /&gt;
    else&lt;br /&gt;
        ssh -n -o BatchMode=yes ${server} &amp;quot;ksh /tmp/dosh.$$; rm -f /tmp/dosh.$$&amp;quot;&lt;br /&gt;
    fi&lt;br /&gt;
    set +x&lt;br /&gt;
    [[ &amp;quot;$VERBOSE&amp;quot; == &amp;quot;Y&amp;quot; ]] &amp;amp;&amp;amp; echo&lt;br /&gt;
done&lt;br /&gt;
rm -f /tmp/dosh.$$&lt;br /&gt;
&lt;br /&gt;
[[ &amp;quot;$BACKGROUND&amp;quot; == &amp;quot;Y&amp;quot; ]] &amp;amp;&amp;amp; printf &amp;quot;%s\n&amp;quot; &amp;quot;Type &amp;#039;ls -altr /tmp/dosh*out&amp;#039; to see output from the commands&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===How can a shell script find out what directory it is in?===&lt;br /&gt;
basename $0 does not always give the desired answer (might give &amp;quot;./&amp;quot;!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
DIR=&amp;quot;$(cd &amp;quot;$(dirname &amp;quot;$0&amp;quot;)&amp;quot; &amp;amp;&amp;amp; pwd)&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Array processing===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
array=(1 2 3)&lt;br /&gt;
unset array[2]&lt;br /&gt;
echo ${array[2]}          # null&lt;br /&gt;
indices=(${!array[@]})    # create an array of the indices of &amp;quot;array&amp;quot;&lt;br /&gt;
size=${#indices[@]}       # the size of &amp;quot;array&amp;quot; is the number of indices into it&lt;br /&gt;
size=${#array[@]}         # same&lt;br /&gt;
echo ${array[@]: -1}      # you can use slices to get array elements, -1 is the last one, etc.&lt;br /&gt;
for element in ${array[@]}; do    # iterate over the array without an index&lt;br /&gt;
&lt;br /&gt;
for index in ${indices[@]}        # iterate over the array WITH an index&lt;br /&gt;
do&lt;br /&gt;
    echo &amp;quot;Index: ${index}, Element: ${array[index]}&amp;quot;&lt;br /&gt;
done&lt;br /&gt;
&lt;br /&gt;
for index in ${!array[@]}         # iterate over the array WITH an index, directly&lt;br /&gt;
&lt;br /&gt;
array+=(&amp;quot;new element&amp;quot;)    # append a new element without referring to an index&lt;br /&gt;
((counter++))             # shorter than ((counter=counter+1)) or ((counter+=1))&lt;br /&gt;
if [[ $var == 3 ]]        # you can use the more &amp;quot;natural&amp;quot; comparison operators inside double square brackets&lt;br /&gt;
while [[ $var &amp;lt; 11 ]]     # another example&lt;br /&gt;
echo ${array[${index}-1]  # math inside an array subscript&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Send an email by talking directly to an smtp server===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
telnet smtp.domain.com 25 &amp;lt;&amp;lt;EOTXT&amp;gt;&amp;gt;/tmp/smtp.log&lt;br /&gt;
HELO me.domain.com&lt;br /&gt;
MAIL FROM:&amp;lt;stuart@domain.com&amp;gt;&lt;br /&gt;
RCPT TO:&amp;lt;anne@domain.com&amp;gt;&lt;br /&gt;
DATA&lt;br /&gt;
From: Stuart &amp;lt;stuart@domain.com&amp;gt;&lt;br /&gt;
To: Anne &amp;lt;anne@domain.com&amp;gt;&lt;br /&gt;
Subject: testing smtp email&lt;br /&gt;
&lt;br /&gt;
Hello, this should appear in the body&lt;br /&gt;
.&lt;br /&gt;
QUIT&lt;br /&gt;
EOTXT&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Send an email by talking directly to an smtp server via file descriptor (no telnet! this time), adding authentication===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
&lt;br /&gt;
#&lt;br /&gt;
# mail.sh&lt;br /&gt;
#&lt;br /&gt;
# 2008 - Mike Golvach - eggi@comcast.net&lt;br /&gt;
# 2010 - Rayber&lt;br /&gt;
#&lt;br /&gt;
# Creative Commons Attribution-Noncommercial-Share Alike 3.0 United States License&lt;br /&gt;
#&lt;br /&gt;
&lt;br /&gt;
if [ $# -ne 7 ]&lt;br /&gt;
then&lt;br /&gt;
echo &amp;quot;Usage: $0 FromAdress ToAdress Domain MailServer MailTextFile AuthEmail AuthPass&amp;quot;&lt;br /&gt;
exit 1&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
from=$1&lt;br /&gt;
to=$2&lt;br /&gt;
domain=$3&lt;br /&gt;
mailserver=$4&lt;br /&gt;
mailtext=$5&lt;br /&gt;
authemail=`echo $6|openssl enc -base64|awk &amp;#039;sub(&amp;quot;..$&amp;quot;, &amp;quot;&amp;quot;)&amp;#039;`&lt;br /&gt;
authpass=`echo $7|openssl enc -base64|awk &amp;#039;sub(&amp;quot;..$&amp;quot;, &amp;quot;&amp;quot;)&amp;#039;`&lt;br /&gt;
&lt;br /&gt;
if [ ! -f $mailtext ]&lt;br /&gt;
then&lt;br /&gt;
echo &amp;quot;Cannot find your mail text file. Exiting...&amp;quot;&lt;br /&gt;
exit 1&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
exec 9&amp;lt;&amp;gt;/dev/tcp/$mailserver/25&lt;br /&gt;
echo &amp;quot;HELO $domain&amp;quot; &amp;gt;&amp;amp;9&lt;br /&gt;
read -r temp &amp;lt;&amp;amp;9&lt;br /&gt;
echo &amp;quot;$temp&amp;quot;&lt;br /&gt;
echo &amp;quot;auth login&amp;quot; &amp;gt;&amp;amp;9&lt;br /&gt;
read -r temp &amp;lt;&amp;amp;9&lt;br /&gt;
echo &amp;quot;$authemail&amp;quot; &amp;gt;&amp;amp;9&lt;br /&gt;
read -r temp &amp;lt;&amp;amp;9&lt;br /&gt;
echo &amp;quot;$authpass&amp;quot; &amp;gt;&amp;amp;9&lt;br /&gt;
read -r temp &amp;lt;&amp;amp;9&lt;br /&gt;
echo &amp;quot;Mail From: $from&amp;quot; &amp;gt;&amp;amp;9&lt;br /&gt;
read -r temp &amp;lt;&amp;amp;9&lt;br /&gt;
echo &amp;quot;$temp&amp;quot;&lt;br /&gt;
echo &amp;quot;Rcpt To: $to&amp;quot; &amp;gt;&amp;amp;9&lt;br /&gt;
read -r temp &amp;lt;&amp;amp;9&lt;br /&gt;
echo &amp;quot;$temp&amp;quot;&lt;br /&gt;
echo &amp;quot;Data&amp;quot; &amp;gt;&amp;amp;9&lt;br /&gt;
read -r temp &amp;lt;&amp;amp;9&lt;br /&gt;
echo &amp;quot;$temp&amp;quot;&lt;br /&gt;
cat $mailtext &amp;gt;&amp;amp;9&lt;br /&gt;
echo &amp;quot;.&amp;quot; &amp;gt;&amp;amp;9&lt;br /&gt;
read -r temp &amp;lt;&amp;amp;9&lt;br /&gt;
echo &amp;quot;$temp&amp;quot;&lt;br /&gt;
echo &amp;quot;quit&amp;quot; &amp;gt;&amp;amp;9&lt;br /&gt;
read -r temp &amp;lt;&amp;amp;9&lt;br /&gt;
echo &amp;quot;$temp&amp;quot;&lt;br /&gt;
9&amp;gt;&amp;amp;-&lt;br /&gt;
9&amp;lt;&amp;amp;-&lt;br /&gt;
echo &amp;quot;All Done Sending Email. See above for errors&amp;quot;&lt;br /&gt;
exit 0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== rsync examples===&lt;br /&gt;
Also see [[Distribute files to multiple servers using rsync and ssh]]&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/sh&lt;br /&gt;
ssh  &amp;lt;remote_host&amp;gt; &amp;#039;/bin/mkdir -p /etc /etc/rc.config.d /etc/security /etc/mail&amp;#039;&lt;br /&gt;
rsync --rsync-path /usr/bin/rsync -Liprogtz --out-format=%f%L  /etc/passwd /etc/passwd.post /etc/group /etc/hosts /etc/services /etc/resolv.conf /etc/exclude.rootvg &amp;lt;remote_host&amp;gt;:/etc&lt;br /&gt;
rsync --rsync-path /usr/bin/rsync -Liprogtz --out-format=%f%L  /etc/hosts.allow.xcat &amp;lt;remote_host&amp;gt;:/etc/hosts.allow&lt;br /&gt;
rsync --rsync-path /usr/bin/rsync -Liprogtz --out-format=%f%L  /etc/rc.config.d/sap &amp;lt;remote_host&amp;gt;:/etc/rc.config.d&lt;br /&gt;
rsync --rsync-path /usr/bin/rsync -Liprogtz --out-format=%f%L  /etc/security/group /etc/security/limits /etc/security/login.cfg /etc/security/passwd /etc/security/user &amp;lt;remote_host&amp;gt;:/etc/security&lt;br /&gt;
rsync --rsync-path /usr/bin/rsync -Liprogtz --out-format=%f%L  /etc/mail/sendmail.cf &amp;lt;remote_host&amp;gt;:/etc/mail&lt;br /&gt;
&lt;br /&gt;
rsync -av --progress /home/ibmtools/scripts/oracle/* benouerp07:/home/ibmtools/scripts/oracle/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Handy aliases===&lt;br /&gt;
Strip out comments and blank lines from a file&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alias strip=&amp;#039;grep -Ev &amp;#039;\&amp;#039;&amp;#039;^(#|$)&amp;#039;\&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Does a ps and a grep&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alias psg=&amp;#039;ps -ef | grep -v $$ | grep -i &amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Getting a decent listing of filesystem space available. It is ordered such that the filesystems with no space left are at the end.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
OS=$(uname -s)&lt;br /&gt;
[[ &amp;quot;$OS&amp;quot; == &amp;quot;SunOS&amp;quot; ]] &amp;amp;&amp;amp; alias dfg=&amp;#039;df -h|sed -e &amp;#039;1d&amp;#039;|sort -n -k5|awk &amp;#039;\&amp;#039;&amp;#039; BEGIN {printf(&amp;quot;%-35s%-10s%-10s%-6s%-30s\n&amp;quot;,&amp;quot;Filesystem&amp;quot;,&amp;quot;Total&amp;quot;,&amp;quot;Free&amp;quot;,&amp;quot;%Used&amp;quot;,&amp;quot;Mounted on&amp;quot;)} {printf(&amp;quot;%-35s%-10s%-10s%-6s%-30s\n&amp;quot;,$1,$2,$4,$5,$6)}&amp;#039;\&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
[[ &amp;quot;$OS&amp;quot; == &amp;quot;AIX&amp;quot; ]]   &amp;amp;&amp;amp; alias dfg=&amp;#039;df -g|sed -e &amp;#039;1d&amp;#039;|sort -n -k4|awk &amp;#039;\&amp;#039;&amp;#039; BEGIN {printf(&amp;quot;%-35s%-10s%-10s%-6s%-30s\n&amp;quot;,&amp;quot;Filesystem&amp;quot;,&amp;quot;Total GB&amp;quot;,&amp;quot;Free&amp;quot;,&amp;quot;%Used&amp;quot;,&amp;quot;Mounted on&amp;quot;)} {printf(&amp;quot;%-35s%-10s%-10s%-6s%-30s\n&amp;quot;,$1,$2,$3,$4,$7)}&amp;#039;\&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
A handy way of listing subdirectories and their files&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alias filetree=&amp;quot;find . -print | sed -e &amp;#039;s;[^/]*/;|____;g;s;____|; |;g&amp;#039;&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Watch progress of a copy&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alias cpProgress=&amp;quot;rsync --progress -ravz&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Reboots Linksys router&amp;lt;pre&amp;gt;&lt;br /&gt;
alias rebootlinksys=&amp;quot;curl -u &amp;#039;admin:password&amp;#039; &amp;#039;http://192.168.1.2/setup.cgi?todo=reboot&amp;#039;&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Nice one for bash. Colour codes the prompt depending on the outcome of the previous command&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
bash_prompt_command()&lt;br /&gt;
{&lt;br /&gt;
    RTN=$?&lt;br /&gt;
    prevCmd=$(prevCmd $RTN)&lt;br /&gt;
}&lt;br /&gt;
PROMPT_COMMAND=bash_prompt_command&lt;br /&gt;
prevCmd()&lt;br /&gt;
{&lt;br /&gt;
    if [ $1 == 0 ] ; then&lt;br /&gt;
        echo $GREEN&lt;br /&gt;
    else&lt;br /&gt;
        echo $RED&lt;br /&gt;
    fi&lt;br /&gt;
}&lt;br /&gt;
if [ $(tput colors) -gt 0 ] ; then&lt;br /&gt;
    RED=$(tput setaf 1)&lt;br /&gt;
    GREEN=$(tput setaf 2)&lt;br /&gt;
    RST=$(tput op)&lt;br /&gt;
fi&lt;br /&gt;
export PS1=&amp;quot;\[\e[36m\]\u.\h.\W\[\e[0m\]\[\$prevCmd\]&amp;gt;\[$RST\]&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Mmmm, to be looked into. Executes remote commands on a unix box using curl.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#/bin/sh&lt;br /&gt;
#&lt;br /&gt;
# WAG320N-HACK&lt;br /&gt;
# Ver. 1.0&lt;br /&gt;
# 12/09/2010&lt;br /&gt;
#&lt;br /&gt;
# This program is free software: you can redistribute it and/or modify&lt;br /&gt;
# it under the terms of the GNU General Public License as published by&lt;br /&gt;
# the Free Software Foundation, either version 3 of the License, or&lt;br /&gt;
# (at your option) any later version.&lt;br /&gt;
#&lt;br /&gt;
# This program is distributed in the hope that it will be useful,&lt;br /&gt;
# but WITHOUT ANY WARRANTY; without even the implied warranty of&lt;br /&gt;
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the&lt;br /&gt;
# GNU General Public License for more details.&lt;br /&gt;
#&lt;br /&gt;
# You should have received a copy of the GNU General Public License&lt;br /&gt;
# along with this program.  If not, see &amp;lt;http://www.gnu.org/licenses/&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
# Set username and password in the form of &amp;quot;username:password&amp;quot;&lt;br /&gt;
# example: &amp;quot;admin:admin&amp;quot;&lt;br /&gt;
my_access=&amp;quot;admin:admin&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Parameters test&lt;br /&gt;
if [ -z &amp;quot;$1&amp;quot; ]&lt;br /&gt;
then&lt;br /&gt;
  echo &amp;quot;wag320n-hack.sh: missing remote command&amp;quot;&lt;br /&gt;
  echo &amp;quot;usage: wag320n-hack.sh &amp;lt;remote command&amp;gt;&amp;quot;&lt;br /&gt;
  echo &amp;quot;example: wag320n-hack.sh /bin/ls -la /usr/sbin&amp;quot;&lt;br /&gt;
  echo &amp;quot;Note: always use full path&amp;quot;&lt;br /&gt;
  echo &amp;quot;&amp;quot;&lt;br /&gt;
  echo &amp;quot;wag320n-hack.sh - Ver. 1.0 - 12/09/2010&amp;quot;&lt;br /&gt;
  echo &amp;quot;Licensed under GPL V. 3&amp;quot;&lt;br /&gt;
  echo &amp;quot;&amp;quot;&lt;br /&gt;
  exit 0&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
# Get the command&lt;br /&gt;
my_command=&amp;quot;ping_size=&amp;quot;&amp;#039;$(&amp;#039;&amp;quot;$@&amp;quot;&amp;#039; 1&amp;gt;&amp;amp;2)&amp;#039;&lt;br /&gt;
&lt;br /&gt;
curl -s -G -u &amp;quot;$my_access&amp;quot; --data-urlencode &amp;#039;todo=ping_test&amp;#039; --data-urlencode &amp;#039;this_file=Diagnostics.htm&amp;#039; --data-urlencode &amp;#039;next_file=Ping.htm&amp;#039; --data-urlencode &amp;#039;c4_ping_ipaddr=192.168.1.1&amp;#039; --data-urlencode &amp;#039;ping_timeout=5000&amp;#039; --data-urlencode &amp;#039;ping_interval=1000&amp;#039; --data-urlencode &amp;#039;ping_number=1&amp;#039; --data-urlencode &amp;quot;$my_command&amp;quot; http://192.168.1.1/setup.cgi | sed -e &amp;#039;/HTTP\/1.0 200 OK/q&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===How to configure SSH with public/private keys===&lt;br /&gt;
* [http://www.unixpeople.com/HOWTO/configuring.ssh.html unixpeople.com]&lt;br /&gt;
===Use SSH config file===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Host server10&lt;br /&gt;
  Hostname 1.2.3.4&lt;br /&gt;
  IdentityFile ~/.ssh/id_dsa&lt;br /&gt;
  user foobar&lt;br /&gt;
  Port 30000&lt;br /&gt;
  ForwardX11Trusted yes&lt;br /&gt;
  TCPKeepAlive yes&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
then just connect using&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ssh server10&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===A decent sed tutorial===&lt;br /&gt;
From [http://www.grymoire.com/Unix/Sed.html grymoire.com]&lt;br /&gt;
===A decent korn/bash shell tutorial===&lt;br /&gt;
From [http://www.dartmouth.edu/~rc/classes/ksh/print_pages.shtml dartmouth.edu]&lt;br /&gt;
Reproduced here just in case it disappears!&lt;br /&gt;
[[Advanced shell scripting]]&lt;br /&gt;
&lt;br /&gt;
===trap===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
     Example Handling Traps With ksh - Discussion of the kill command&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
EXAMPLE TEMPLATE:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
PRODUCT:    HP-UX 11iV1 Version B.11.11&lt;br /&gt;
            HP Tru64 V5.1B PK4&lt;br /&gt;
            Sun/Solaris SunOS V5.8&lt;br /&gt;
            Linux 2.6 kernel&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
COMPONENT:  ksh&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
SOURCE:     Philippe Vouters&lt;br /&gt;
            Fontainebleau/France&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
LOW COST HIGH-TECH PRODUCTS:  http://techno-star.fr&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
OVERVIEW:&lt;br /&gt;
&lt;br /&gt;
The ksh script below shows how to eventually handle traps in the situation &lt;br /&gt;
where someone might try to kill a script by killing individual commands run &lt;br /&gt;
by that script or the entire process group a script is running in. The kill &lt;br /&gt;
command (usually a shell builtin) may be used to send a signal to a process &lt;br /&gt;
group (with the -&amp;lt;pid&amp;gt; syntax) or an individual process. The example ksh &lt;br /&gt;
script below runs /bin/sleep as the foreground process, the example ksh &lt;br /&gt;
scripts immediately returns when the /bin/sleep process has terminated. Most &lt;br /&gt;
signals sent to the shell are ignored until after the foreground process &lt;br /&gt;
terminates. This is in order to avoid creating zombie processes. Therefore a &lt;br /&gt;
kill &amp;lt;pid&amp;gt; on the example ksh script waits for the termination of the &lt;br /&gt;
/bin/sleep process.&lt;br /&gt;
&lt;br /&gt;
The status value $? in the trap refers to the exit status of the command to run &lt;br /&gt;
and therefore is the exit status of the /bin/sleep process. The called function &lt;br /&gt;
in the trap handler shows how to correctly examine the effect of the kill &lt;br /&gt;
command on the shell or it&amp;#039;s children.&lt;br /&gt;
&lt;br /&gt;
To examine the value of $? in a trap handler means that you must understand what&lt;br /&gt;
it can be set and how different signals delivered to either the shell or the &lt;br /&gt;
foreground process (or the process group) might affect the value of $?.&lt;br /&gt;
&lt;br /&gt;
The example shell script prints $? using echo but it does not perform tests on &lt;br /&gt;
the value of $?. For a complete solution when attempting to trap signals in a &lt;br /&gt;
shell you would also need code that examined the value of $? after the &lt;br /&gt;
foreground process had completed.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*** CAUTION ***&lt;br /&gt;
&lt;br /&gt;
This sample script has been tested using HP-UX B.11.11, HP Tru64 V5.1B PK4, &lt;br /&gt;
SunOS V5.8 and Fedora Core 4 (homed version of Red Hat Linux).  However, we&lt;br /&gt;
cannot guarantee its effectiveness because of the possibility of error in &lt;br /&gt;
transmitting or implementing it. It is meant to be used as a template for &lt;br /&gt;
writing your own scripts, and may require modification for use on your system. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
SCRIPT NOTES:&lt;br /&gt;
&lt;br /&gt;
To notice that the ksh script and /bin/sleep share the same process group&lt;br /&gt;
identifier (PGID), issue the following commands:&lt;br /&gt;
&lt;br /&gt;
[philippe@victor ~]$ who&lt;br /&gt;
philippe :0           Jan 10 10:16&lt;br /&gt;
philippe pts/1        Jan 10 21:30 (:0.0)&lt;br /&gt;
philippe pts/2        Jan 10 21:30 (:0.0)&lt;br /&gt;
[philippe@victor ~]$ tty&lt;br /&gt;
/dev/pts/1&lt;br /&gt;
[philippe@victor ~]$ ps -j -t pts/2&lt;br /&gt;
  PID  PGID   SID TTY          TIME CMD&lt;br /&gt;
11072 11072 11072 pts/2    00:00:00 bash&lt;br /&gt;
11113 11113 11072 pts/2    00:00:00 ksh&lt;br /&gt;
11116 11113 11072 pts/2    00:00:00 sleep&lt;br /&gt;
&lt;br /&gt;
In this case sending kill -INT -11113 will send SIGINT to the process group &lt;br /&gt;
11113. Both of the ksh and sleep processes are contained within this process &lt;br /&gt;
group.&lt;br /&gt;
&lt;br /&gt;
Important Note:&lt;br /&gt;
&lt;br /&gt;
On HP-UX, you have to $ export UNIX95=1 in order to be able to use the&lt;br /&gt;
-j option of the ps command.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
SCRIPT:&lt;br /&gt;
&lt;br /&gt;
                             COPYRIGHT (C) 2005 BY&lt;br /&gt;
                              HEWLETT-PACKARD COMPANY&lt;br /&gt;
                                ALL RIGHTS RESERVED.&lt;br /&gt;
&lt;br /&gt;
     THIS SOFTWARE IS FURNISHED UNDER A LICENSE AND MAY BE USED AND COPIED&lt;br /&gt;
     ONLY IN ACCORDANCE WITH THE TERMS OF SUCH LICENSE AND WITH THE INCLUSION&lt;br /&gt;
     OF THE ABOVE COPYRIGHT NOTICE.  THIS SOFTWARE OR ANY OTHER COPIES&lt;br /&gt;
     THEREOF MAY NOT BE PROVIDED OR OTHERWISE MADE AVAILABLE TO ANY OTHER&lt;br /&gt;
     PERSON.  NO TITLE TO AND OWNERSHIP OF THE SOFTWARE IS HEREBY TRANSFERRED.&lt;br /&gt;
&lt;br /&gt;
     THE INFORMATION IN THIS SOFTWARE IS SUBJECT TO CHANGE WITHOUT NOTICE AND&lt;br /&gt;
     SHOULD NOT BE CONSTRUED AS A COMMITMENT BY HEWLETT-PACKARD COMPANY.&lt;br /&gt;
&lt;br /&gt;
     HP ASSUMES NO RESPONSIBILITY FOR THE USE OR RELIABILITY OF ITS&lt;br /&gt;
     SOFTWARE ON EQUIPMENT THAT IS NOT SUPPLIED BY HP.&lt;br /&gt;
&lt;br /&gt;
     NO RESPONSIBILITY IS ASSUMED FOR THE USE OR RELIABILITY OF SOFTWARE&lt;br /&gt;
     ON EQUIPMENT THAT IS NOT SUPPLIED BY HEWLETT-PACKARD COMPANY.&lt;br /&gt;
&lt;br /&gt;
     SUPPORT FOR THIS SOFTWARE IS NOT COVERED UNDER ANY HP SOFTWARE&lt;br /&gt;
     PRODUCT SUPPORT CONTRACT, BUT MAY BE PROVIDED UNDER THE TERMS OF THE&lt;br /&gt;
     CONSULTING AGREEMENT UNDER WHICH THIS SOFTWARE WAS DEVELOPED.&lt;br /&gt;
&lt;br /&gt;
#!/bin/ksh&lt;br /&gt;
function handle_signal&lt;br /&gt;
{&lt;br /&gt;
        print -n &amp;quot;pid $$ recieved $2 &amp;quot;&lt;br /&gt;
        if [[ $1 = 0 ]];then&lt;br /&gt;
            print but foreground command ended successfully&lt;br /&gt;
        else&lt;br /&gt;
                if [[ $1 = $3 ]];then&lt;br /&gt;
                    print and so did the last foreground command&lt;br /&gt;
                else&lt;br /&gt;
                    print -n &amp;quot;and the exit status of the last foreground &amp;quot;&lt;br /&gt;
                    print command was $1&lt;br /&gt;
                fi&lt;br /&gt;
        fi&lt;br /&gt;
        # Kill our process group and then ourselves with SIGTERM, giving a &lt;br /&gt;
        # pid of 0 sends the signal to our process group. Killing the process&lt;br /&gt;
        # group should kill us as well, this assumes that SIGTERM is not &lt;br /&gt;
        # handled by any process in the process group.&lt;br /&gt;
        #&lt;br /&gt;
        # This code could be replaced with an exit with an exit value that&lt;br /&gt;
        # would indicate what the problem was to the caller. That is replace &lt;br /&gt;
        # these two lines with:&lt;br /&gt;
        #&lt;br /&gt;
        # exit $3&lt;br /&gt;
        #&lt;br /&gt;
        # or a specific exit code could be used.&lt;br /&gt;
        #&lt;br /&gt;
        kill -TERM 0&lt;br /&gt;
        kill -TERM $$&lt;br /&gt;
        }&lt;br /&gt;
OS=$(uname -a | awk &amp;#039;{print $1}&amp;#039;)&lt;br /&gt;
if [[ &amp;quot;$OS&amp;quot; = &amp;quot;Linux&amp;quot; ]]; then&lt;br /&gt;
    offset=256&lt;br /&gt;
elif [[ (&amp;quot;$OS&amp;quot; = &amp;quot;HP-UX&amp;quot;) || &lt;br /&gt;
        (&amp;quot;$OS&amp;quot; = &amp;quot;SunOS&amp;quot;) || &lt;br /&gt;
        (&amp;quot;$OS&amp;quot; = &amp;quot;OSF1&amp;quot;) ]]; then&lt;br /&gt;
   offset=128&lt;br /&gt;
fi&lt;br /&gt;
trap &amp;#039;RC=$?; handle_signal $RC SIGINT $offset+2&amp;#039; INT&lt;br /&gt;
trap &amp;#039;RC=$?; handle_signal $RC SIGQUIT $offset+3&amp;#039; QUIT&lt;br /&gt;
/bin/sleep 20&lt;br /&gt;
echo $?&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===DNS not working===&lt;br /&gt;
Ping to an IP address works&lt;br /&gt;
 ping 74.125.136.103&lt;br /&gt;
but this doesn&amp;#039;t&lt;br /&gt;
 ping www.google.com&lt;br /&gt;
&lt;br /&gt;
Check resolv.conf&lt;br /&gt;
 cat /etc/resolv.conf&lt;br /&gt;
 nameserver 95.130.132.17&lt;br /&gt;
 nameserver 95.130.132.18&lt;br /&gt;
I had changed internet provider and forgot to update this. Just to set it to the router address and let that do the resolution&lt;br /&gt;
 nameserver 192.168.1.1&lt;br /&gt;
&lt;br /&gt;
===File descriptors===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
exec 3&amp;lt;&amp;gt; /tmp/foo  #open fd 3 for r/w&lt;br /&gt;
echo &amp;quot;test&amp;quot; &amp;gt;&amp;amp;3&lt;br /&gt;
exec 3&amp;gt;&amp;amp;- #close fd 3.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
exec 3&amp;lt;&amp;gt; myfile.txt&lt;br /&gt;
while read line &amp;lt;&amp;amp;3&lt;br /&gt;
do {&lt;br /&gt;
  echo &amp;quot;$line&amp;quot;&lt;br /&gt;
  (( Lines++ ));                   #  Incremented values of this variable&lt;br /&gt;
                                   #+ accessible outside loop.&lt;br /&gt;
                                   #  No subshell, no problem.&lt;br /&gt;
}&lt;br /&gt;
done&lt;br /&gt;
exec 3&amp;gt;&amp;amp;-&lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;Number of lines read = $Lines&amp;quot;     # 8&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Mmm. See our output and also tee it to a log file!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
&lt;br /&gt;
echo hello&lt;br /&gt;
&lt;br /&gt;
if test -t 1; then&lt;br /&gt;
    # Stdout is a terminal.&lt;br /&gt;
    exec &amp;gt;log&lt;br /&gt;
else&lt;br /&gt;
    # Stdout is not a terminal.&lt;br /&gt;
    npipe=/tmp/$$.tmp&lt;br /&gt;
    trap &amp;quot;rm -f $npipe&amp;quot; EXIT&lt;br /&gt;
    mknod $npipe p&lt;br /&gt;
    tee &amp;lt;$npipe log &amp;amp;&lt;br /&gt;
    exec 1&amp;gt;&amp;amp;-&lt;br /&gt;
    exec 1&amp;gt;$npipe&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
echo goodbye&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Create new image with kvm===&lt;br /&gt;
Ref: http://www.cyberciti.biz/faq/kvm-virtualization-in-redhat-centos-scientific-linux-6/&amp;lt;br /&amp;gt;&lt;br /&gt;
Build an empty space for a CentOS virtual machine&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
qemu-img create -f qcow2 centos.img 12G&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Tried creating image with&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo virt-install -n CentOS --description &amp;quot;Trying out CentOS&amp;quot; --ram=1024 --vcpus=1 --cpu host --hvm --cdrom /home/bey9at77/Downloads/c6-x86_64-20130910-1.qcow2 --graphics vnc --disk path=/var/lib/libvirt/images/centos.img,bus=virtio,size=10&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
gives error&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Starting install...&lt;br /&gt;
Allocating &amp;#039;centos.img&amp;#039;                                                                                                                                                                                               |  10 GB     00:00     &lt;br /&gt;
ERROR    internal error Process exited while reading console log output: char device redirected to /dev/pts/1&lt;br /&gt;
qemu-kvm: -drive file=/home/bey9at77/Downloads/c6-x86_64-20130910-1.qcow2.bz2,if=none,media=cdrom,id=drive-ide0-1-0,readonly=on,format=raw: could not open disk image /home/bey9at77/Downloads/c6-x86_64-20130910-1.qcow2: Permission denied&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===rpm / yum commands===&lt;br /&gt;
====Install an RPM Package====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rpm -ivh pidgin-2.7.9-5.el6.2.i686.rpm&lt;br /&gt;
&lt;br /&gt;
-i - install&lt;br /&gt;
-v - verbose&lt;br /&gt;
-h - print progress hashes&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Check dependencies of RPM Package before Installing====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rpm -qpR BitTorrent-5.2.2-1-Python2.4.noarch.rpm&lt;br /&gt;
&lt;br /&gt;
-q - query&lt;br /&gt;
-p - list package capabilities&lt;br /&gt;
-R - list dependent package capabilities&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Install RPM Package with all dependencies====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
yum install BitTorrent-5.2.2-1-Python2.4.noarch.rpm&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Install RPM Package with all dependencies (when RPM has been downloaded to local machine)====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
yum localinstall BitTorrent-5.2.2-1-Python2.4.noarch.rpm&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Force Install a RPM Package without dependencies====&lt;br /&gt;
Package will not work if dependencies are required&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rpm -ivh --nodeps BitTorrent-5.2.2-1-Python2.4.noarch.rpm&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Check an Installed RPM Package====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rpm -q BitTorrent&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====List all files of an installed RPM package====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rpm -ql BitTorrent&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====List All Installed RPM Packages====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rpm -qa&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Query information about an installed RPM package====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rpm -qi vsftpd&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Query information about a not yet installed RPM package====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rpm -qip sqlbuddy-1.3.3-1.noarch.rpm&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====(Forcibly) Remove an RPM Package====&lt;br /&gt;
Use package name (as seen in -qi above), not full name&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rpm -ev (--nodeps) vsftpd&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Query a file that was installed as part of an RPM Package (which package contained this file)====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rpm -qf /usr/bin/htpasswd&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Verify an RPM package====&lt;br /&gt;
Compares information of installed files of the package against the rpm database&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rpm -Vp sqlbuddy-1.3.3-1.noarch.rpm&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Rebuild corrupted RPM database====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cd /var/lib&lt;br /&gt;
rm __db*&lt;br /&gt;
rpm --rebuilddb&lt;br /&gt;
rpmdb_verify Packages&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Install rpmforge repository===&lt;br /&gt;
* Download rpmforge-release-0.5.3-1.el6.rf.x86_64.rpm&lt;br /&gt;
* Import the key&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo rpm --import http://apt.sw.be/RPM-GPG-KEY.dag.txt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Install the repository&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo rpm -i rpmforge-release-0.5.3-1.el6.rf.x86_64.rpm&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Check the installation&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rpm -K rpmforge-release-0.5.3-1.el6.rf.x86_64.rpm&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Test it&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo yum install terminator&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Install rpmfusion repository===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
su -c &amp;#039;yum localinstall --nogpgcheck http://download1.rpmfusion.org/free/el/updates/6/i386/rpmfusion-free-release-6-1.noarch.rpm http://download1.rpmfusion.org/nonfree/el/updates/6/i386/rpmfusion-nonfree-release-6-1.noarch.rpm&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===config file for yum===&lt;br /&gt;
Checkout this file for global yum config&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/etc/sysconfig/yum-cron-background&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Setup Oracle Enterprise Linux (RedHat) with yum server===&lt;br /&gt;
You need to download the yum .repo file from the server, as per the steps below. After this, you need to enable a flag in the .repo file as per your operating system version. Having done these two steps, when you run yum install &amp;lt;pkgname&amp;gt; command on your linux box, the Oracle&amp;#039;s yum server will be scanned, the dependent &amp;amp; the relevant rpm&amp;#039;s will be download and installed for you.&amp;lt;br /&amp;gt;&lt;br /&gt;
 cd /etc/yum.repos.d&lt;br /&gt;
To download files here&lt;br /&gt;
 wget http://public-yum.oracle.com/public-yum-el5.repo&lt;br /&gt;
&lt;br /&gt;
A file named public-yum-el5.repo will be created in your directory&amp;lt;br /&amp;gt;&lt;br /&gt;
Edit this file and enter enabled=1 against the operating systems which is relevant to you&lt;br /&gt;
 vi public-yum-el5.repo&lt;br /&gt;
&lt;br /&gt;
Next run the yum command&lt;br /&gt;
 yum install package-name&lt;br /&gt;
&lt;br /&gt;
===To change to static IP address (Raspberry Pi)===&lt;br /&gt;
As root:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cd /etc/networks&lt;br /&gt;
vi interfaces&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
replace the line “iface eth0 inet dhcp” with&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
iface eth0 inet static&lt;br /&gt;
address 192.168.1.100&lt;br /&gt;
netmask 255.255.255.0&lt;br /&gt;
gateway 192.168.1.1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You should also take a look at the file /etc/resolv.conf and check it has a nameserver entry (probably pointing at your default gateway) or direct to your ISP name servers.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
nameserver 192.168.1.1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Troubleshoot wireless network problems===&lt;br /&gt;
* [https://www.blackmoreops.com/2014/09/18/connect-to-wifi-network-from-command-line-in-linux/ connect to wifi network from command-line in linux - from blackmoreops.com]&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Short summary of all the things you need to do in just few lines&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
root@kali:~# iw dev&lt;br /&gt;
root@kali:~# ip link set wlan0 up&lt;br /&gt;
root@kali:~# iw wlan0 scan&lt;br /&gt;
root@kali:~# wpa_passphrase blackMOREOps &amp;gt;&amp;gt; /etc/wpa_supplicant.conf&lt;br /&gt;
root@kali:~# wpa_supplicant -i wlan0 -c /etc/wpa_supplicant.conf&lt;br /&gt;
root@kali:~# iw wlan0 link&lt;br /&gt;
root@kali:~# dhclient wlan0&lt;br /&gt;
root@kali:~# ping 8.8.8.8&lt;br /&gt;
(Where wlan0 is wifi adapter and blackMOREOps is SSID)&lt;br /&gt;
(Add Routing manually)&lt;br /&gt;
root@kali:~# ip route add default via 10.0.0.138 dev wlan0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===To change to static IP address (Redhat/CentOS)===&lt;br /&gt;
As root:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
vi /etc/sysconfig/network-scripts/ifcfg-eth0&lt;br /&gt;
DEVICE=eth0&lt;br /&gt;
BOOTPROTO=STATIC&lt;br /&gt;
IPADDR=192.168.1.111&lt;br /&gt;
NETMASK=255.255.255.0&lt;br /&gt;
GATEWAY=192.168.1.1&lt;br /&gt;
ONBOOT=yes&lt;br /&gt;
DNS1=8.8.8.8&lt;br /&gt;
DNS2=8.8.4.4&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Resrart the network interface&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/etc/init.d/network stop&lt;br /&gt;
/etc/init.d/network start&lt;br /&gt;
or&lt;br /&gt;
service network restart&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Check name server entry in resolv.conf&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
vi /etc/resolv.conf&lt;br /&gt;
nameserver 192.168.1.1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Enable processes / services to start at boot time===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo chkconfig httpd on&lt;br /&gt;
sudo chkconfig mysqld on&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Run a command on lots of servers in parallel===&lt;br /&gt;
This is a damn fine AIX utility - part of the CSM Distributed Shell.&lt;br /&gt;
 dsh -a &amp;quot;ls -al /etc/apache2/*conf&amp;quot;&lt;br /&gt;
will list the Apache configuration file on all reachable servers (nodes)&lt;br /&gt;
===Download a gzip file and pipe it into tar===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cd ~ &amp;amp;&amp;amp; wget -O - &amp;quot;https://www.dropbox.com/download?plat=lnx.x86_64&amp;quot; | tar xzf -&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Check in a script to make sure it is run only by root===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
RUID=`/usr/bin/id|$AWK -F\( &amp;#039;{print $1}&amp;#039;|$AWK -F\= &amp;#039;{print $2}&amp;#039;`&lt;br /&gt;
if [ ${RUID} != &amp;quot;0&amp;quot; ];then&lt;br /&gt;
   $ECHO &amp;quot;This script must be executed as root&amp;quot;&lt;br /&gt;
   exit 1&lt;br /&gt;
fi&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Set terminal to use Backspace key to erase previous character instead of Control-H===&lt;br /&gt;
Been looking for this for a long time.&amp;lt;br /&amp;gt;&lt;br /&gt;
You can put:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
stty erase &amp;lt;CTRL-V&amp;gt;&amp;lt;Backspace key&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
in your .profile but this will be ruined if you do a copy/paste into another file.&amp;lt;br /&amp;gt;&lt;br /&gt;
I wanted a way of doing this without entering the control character in the .profile. Finally stumbled upon it. And it&amp;#039;s so simple. Just escape the caret!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
stty erase \^?&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Put this in the .profile. It&amp;#039;s copy/pastable and it works!&amp;lt;br /&amp;gt;&lt;br /&gt;
If you want CTRL-H to be your erase character, just do this:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
stty erase \^H&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Play with the terminal settings and reset them again either side of requesting a password===&lt;br /&gt;
The -g option of stty gives a compact list of all the settings or the terminal and can be used as input to stty&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
OLDCONFIG=`stty -g`          # save terminal configuration&lt;br /&gt;
stty -echo                   # turn character echoing off&lt;br /&gt;
echo &amp;quot;Enter password: \c&amp;quot;&lt;br /&gt;
read PASSWD                  # get the password&lt;br /&gt;
stty $OLDCONFIG              # restore terminal configuration&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Reset terminal to &amp;quot;sane&amp;quot; characteristics===&lt;br /&gt;
If you&amp;#039;ve done a cat of a binary file or something else weird and your terminal is left in a mess, the following key sequence should bring it back to normal&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;CTRL-J&amp;gt;stty sane&amp;lt;CTRL-J&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Install OpenOffice on RedHat Enterprise when yum install doesn&amp;#039;t!===&lt;br /&gt;
Download Package&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
wget http://sourceforge.net/projects/openofficeorg.mirror/files/4.0.1/binaries/en-US/Apache_OpenOffice_4.0.1_Linux_x86-64_install-rpm_en-US.tar.gz/download -O Apache_OpenOffice_4.0.1_Linux_x86-64_install-rpm_en-US.tar.gz&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Change to root&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo su -&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Remove the old stuff&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
yum remove openoffice* libreoffice*&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Extract Package&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
tar -xvf Apache_OpenOffice_4.0.1*&lt;br /&gt;
cd en-US&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Install Package and exit root&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rpm -Uvh RPMS/*.rpm RPMS/desktop-integration/openoffice4.0-redhat-*.rpm&lt;br /&gt;
exit&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Start it&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
openoffice4&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===What does this do?===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
while IFS= read -r line; do&lt;br /&gt;
    echo &amp;quot;[$(date &amp;quot;+%F %T&amp;quot;)] - $line&amp;quot;&lt;br /&gt;
done &amp;lt; &amp;lt;(iwevent)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
while IFS= read -r line; do&lt;br /&gt;
    printf &amp;quot;%s\n%s\n&amp;quot; &amp;quot;$line&amp;quot; &amp;quot;Yohooo! One more package.&amp;quot;&lt;br /&gt;
done &amp;lt; &amp;lt;(tcpdump -i any -nS)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===List of Special Characters and what they mean===&lt;br /&gt;
From [http://www.grymoire.com/Unix/Quote.html Bruce Barnett]&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Character	Where	Meaning&lt;br /&gt;
&amp;lt;RETURN&amp;gt;	csh, sh	Execute command&lt;br /&gt;
#	csh, sh, ASCII files	Start a comment&lt;br /&gt;
&amp;lt;SPACE&amp;gt;	csh, sh	Argument separator&lt;br /&gt;
`	csh, sh	Command substitution&lt;br /&gt;
&amp;quot;	csh, sh	Weak Quotes&lt;br /&gt;
&amp;#039;	csh, sh	Strong Quotes&lt;br /&gt;
\	csh, sh	Single Character Quote&lt;br /&gt;
variable	sh, csh	Variable&lt;br /&gt;
variable	csh, sh	Same as variable&lt;br /&gt;
|	csh, sh	Pipe character&lt;br /&gt;
^	sh	Pipe Character&lt;br /&gt;
&amp;amp;	csh, sh	Run program in background&lt;br /&gt;
?	csh, sh	Match one character&lt;br /&gt;
*	csh, sh	Match any number of characters&lt;br /&gt;
;	csh, sh	Command separator&lt;br /&gt;
;;	sh	End of Case statement&lt;br /&gt;
~	csh	Home Directory&lt;br /&gt;
~user	csh	User&amp;#039;s Home Directory&lt;br /&gt;
!	csh	History of Commands&lt;br /&gt;
-	Programs	Start of optional argument&lt;br /&gt;
$#	csh, sh	Number of arguments to script&lt;br /&gt;
$*	csh, sh	Arguments to script&lt;br /&gt;
$@	sh	Original arguments to script&lt;br /&gt;
$-	sh	Flags passed to shell&lt;br /&gt;
$?	sh	Status of previous command&lt;br /&gt;
$$	sh	Process identification number&lt;br /&gt;
$!	sh	PID of last background job&lt;br /&gt;
&amp;amp;&amp;amp;	sh	Short-circuit AND&lt;br /&gt;
||	sh	Short-circuit OR&lt;br /&gt;
.	csh, sh	Typ. filename extension&lt;br /&gt;
.	sh	Source a file and execute as command&lt;br /&gt;
:	sh	Nothing command&lt;br /&gt;
:	sh	Separates Values in environment variables&lt;br /&gt;
:	csh	Variable modifier&lt;br /&gt;
Character	Where	Meaning&lt;br /&gt;
[ ]	csh, sh	Match range of characters&lt;br /&gt;
[ ]	sh	Test&lt;br /&gt;
%job	csh	Identifies job Number&lt;br /&gt;
(cmd;cmd)	csh. sh	Runs cmd;cmd as a sub-shell&lt;br /&gt;
{ }	csh	In-line expansions&lt;br /&gt;
{cmd;cmd }	sh	Like (cmd;cmd ) without a subshell&lt;br /&gt;
&amp;gt;ofile	csh, sh	Standard output&lt;br /&gt;
&amp;gt;&amp;gt;ofile	csh, sh	Append to standard output&lt;br /&gt;
&amp;lt;ifile	csh, sh	Standard Input&lt;br /&gt;
&amp;lt;&amp;lt;word	csh, sh	Read until word, substitute variables&lt;br /&gt;
&amp;lt;&amp;lt;\word	csh, sh	Read until word, no substitution&lt;br /&gt;
&amp;lt;&amp;lt;-word	sh	Read until word, ignoring TABS&lt;br /&gt;
&amp;gt;&amp;gt;!file	csh	Append to file, ignore error if not there&lt;br /&gt;
&amp;gt;!file	csh	Output to new file, ignore error if not there&lt;br /&gt;
&amp;gt;&amp;amp;file	csh	Send standard &amp;amp; error output to file&lt;br /&gt;
&amp;lt;&amp;amp;digit	sh	Switch Standard Input to file&lt;br /&gt;
&amp;lt;&amp;amp;-	sh	Close Standard Input&lt;br /&gt;
&amp;gt;&amp;amp;digit	sh	Switch Standard Output to file&lt;br /&gt;
&amp;gt;&amp;amp;-	sh	Close Standard Output&lt;br /&gt;
digit1&amp;lt;&amp;amp;digit2	sh	Connect digit2 to digit1&lt;br /&gt;
digit&amp;lt;&amp;amp;-	sh	Close file digit&lt;br /&gt;
digit2&amp;gt;&amp;amp;digit1	sh	Connect digit2 to digit1&lt;br /&gt;
digit&amp;gt;&amp;amp;-	sh	Close file digit&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Stuart</name></author>	</entry>

	<entry>
		<id>https://mailnest.com/dbawiki/index.php?title=Snippets&amp;diff=3397</id>
		<title>Snippets</title>
		<link rel="alternate" type="text/html" href="https://mailnest.com/dbawiki/index.php?title=Snippets&amp;diff=3397"/>
				<updated>2018-12-05T12:54:16Z</updated>
		
		<summary type="html">&lt;p&gt;Stuart: /* How to get value of ORACLE_HOME from shell environment into SQL*Plus or PL/SQL */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;===Protecting an Apache Web Server directory with htaccess===&lt;br /&gt;
* [https://davidwalsh.name/password-protect-directory-using-htaccess https://davidwalsh.name/password-protect-directory-using-htaccess]&lt;br /&gt;
* [http://www.htaccesstools.com/articles/password-protection/ http://www.htaccesstools.com/articles/password-protection/]&lt;br /&gt;
Two files are needed.&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;The .htaccess Code&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
AuthType Basic&lt;br /&gt;
AuthName &amp;quot;restricted area&amp;quot;&lt;br /&gt;
AuthUserFile /home/davidwalsh/html/protect-me-dir/.htpasswd&lt;br /&gt;
require valid-user&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;The .htpasswd Code&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
davidwalsh:daWHfZrDLB88.&lt;br /&gt;
rodstewart:roFulYxC2.8ws&lt;br /&gt;
cssexpert:csmnmq.M8T5ho&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Protecting a lighttpd directory with htaccess===&lt;br /&gt;
Generate an MD5 hash with the tools above and paste into this file&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
vi /etc/lighttpd/.htpasswd&lt;br /&gt;
stuart:3#$567890#$56789056789&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Check modules.conf file to ensure mod_auth and mod_rewrite are enabled&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
vi /etc/lighttpd/modules.conf&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Alter the lighttpd.conf file to allow the authentication&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#auth directives&lt;br /&gt;
auth.backend = &amp;quot;htpasswd&amp;quot;&lt;br /&gt;
auth.backend.htpasswd.userfile = &amp;quot;/etc/lighttpd/.htpasswd&amp;quot;&lt;br /&gt;
auth.debug = 1&lt;br /&gt;
$HTTP[&amp;quot;url&amp;quot;] =~ &amp;quot;^/cgi-bin&amp;quot; {&lt;br /&gt;
        auth.require = ( &amp;quot;&amp;quot; =&amp;gt;&lt;br /&gt;
        (&lt;br /&gt;
        &amp;quot;method&amp;quot; =&amp;gt; &amp;quot;basic&amp;quot;,&lt;br /&gt;
        &amp;quot;realm&amp;quot; =&amp;gt; &amp;quot;DbaHawk access&amp;quot;,&lt;br /&gt;
        &amp;quot;require&amp;quot; =&amp;gt; &amp;quot;valid-user&amp;quot;&lt;br /&gt;
        ) )&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Restart the lighttpd server&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
systemctl stop lighttpd&lt;br /&gt;
systemctl start lighttpd&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
I tried it with htdigest but could not get it to protest the directory!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#auth.backend = &amp;quot;htdigest&amp;quot;&lt;br /&gt;
#auth.backend.htdigest.userfile = &amp;quot;/etc/lighttpd/lighttpd.user.htdigest&amp;quot;&lt;br /&gt;
#auth.require = (&lt;br /&gt;
#    &amp;quot;/var/www/cgi-bin/&amp;quot; =&amp;gt; (&lt;br /&gt;
#    &amp;quot;method&amp;quot;  =&amp;gt; &amp;quot;basic&amp;quot;,&lt;br /&gt;
#    &amp;quot;realm&amp;quot;   =&amp;gt; &amp;quot;DbaHawk access&amp;quot;,&lt;br /&gt;
#    &amp;quot;require&amp;quot; =&amp;gt; &amp;quot;valid-user&amp;quot;&lt;br /&gt;
#    ),&lt;br /&gt;
#)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Rename a datafile if the filename contains junk / unprintable characters===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter tablespace ts_thaler_data offline;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Oracle have a document that describes a few ways of doing it in [https://support.oracle.com/rs?type=doc&amp;amp;id=824473.1 Note 824473.1]&lt;br /&gt;
If the filename contains control characters and cannot be selected in the normal way, use ls -ali to find the node number and then use find with -inum to rename (or move) the file&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ls -baltri&lt;br /&gt;
total 47474984&lt;br /&gt;
12409 -rw-r-----    1 oracle   oinstall 1073750016 Sep 26 13:56 ts_thaler_data_02\1776.dbf&lt;br /&gt;
12350 -rw-r-----    1 oracle   oinstall 5242888192 Sep 26 13:56 ts_thaler_data_01.dbf&lt;br /&gt;
&lt;br /&gt;
find . -inum 12409 -exec mv {} ts_thaler_data_06.dbf \;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Work out what the database thinks the name is and rename it there too! AskTom has a discussion on it [https://asktom.oracle.com/pls/apex/asktom.search?tag=rename-datafile-with-dummy-characters-after-dbf here]&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select substr(name,i,1),ascii(substr(name,i,1)) from ( select name from v$datafile where file# = 9), ( select rownum i from dual connect by level &amp;lt;= 50);&lt;br /&gt;
SUBS ASCII(SUBSTR(NAME,I,1))&lt;br /&gt;
---- -----------------------&lt;br /&gt;
t                        116&lt;br /&gt;
s                        115&lt;br /&gt;
_                         95&lt;br /&gt;
t                        116&lt;br /&gt;
h                        104&lt;br /&gt;
a                         97&lt;br /&gt;
l                        108&lt;br /&gt;
e                        101&lt;br /&gt;
r                        114&lt;br /&gt;
_                         95&lt;br /&gt;
d                        100&lt;br /&gt;
a                         97&lt;br /&gt;
t                        116&lt;br /&gt;
a                         97&lt;br /&gt;
_                         95&lt;br /&gt;
0                         48&lt;br /&gt;
2                         50&lt;br /&gt;
                         127&lt;br /&gt;
2                         50&lt;br /&gt;
.                         46&lt;br /&gt;
d                        100&lt;br /&gt;
b                         98&lt;br /&gt;
f                        102&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
You can see there&amp;#039;s a 127 just before the .dbf... this crept in a the backspace key was not working correctly.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set serveroutput on&lt;br /&gt;
declare&lt;br /&gt;
   fname1 varchar2(100);&lt;br /&gt;
   fname2 varchar2(100);&lt;br /&gt;
begin&lt;br /&gt;
  select name into fname1 from v$datafile where file# = 9;&lt;br /&gt;
  fname2 := replace(fname1,chr(127));&lt;br /&gt;
  &lt;br /&gt;
  dbms_output.put_line(&amp;#039;alter database rename file &amp;#039;&amp;#039;&amp;#039;||fname1||&amp;#039;&amp;#039;&amp;#039; to &amp;#039;&amp;#039;&amp;#039;||fname2||&amp;#039;&amp;#039;&amp;#039;&amp;#039;);&lt;br /&gt;
  execute immediate &amp;#039;alter database rename file &amp;#039;&amp;#039;&amp;#039;||fname1||&amp;#039;&amp;#039;&amp;#039; to &amp;#039;&amp;#039;&amp;#039;||fname2||&amp;#039;&amp;#039;&amp;#039;&amp;#039;;&lt;br /&gt;
end;&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
alter tablespace ts_thaler_data_online;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Generate creation of directory names from dba_directories===&lt;br /&gt;
Before deleting or dropping directories in the database, use this script to generate the create statements&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select &amp;#039;create or replace directory &amp;#039;||directory_name||&amp;#039; as &amp;#039;&amp;#039;&amp;#039;||directory_path||&amp;#039;&amp;#039;&amp;#039;;&amp;#039; from dba_directories;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Check if current (dot) directory is in PATH variable===&lt;br /&gt;
Using bareword comparison to check PATH variable&amp;lt;pre&amp;gt;&lt;br /&gt;
if [[ :$PATH: == *:&amp;quot;.&amp;quot;:* ]] ; then&lt;br /&gt;
    echo &amp;quot;in path&amp;quot;&lt;br /&gt;
else&lt;br /&gt;
    echo &amp;quot;not in path&amp;quot;&lt;br /&gt;
fi&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===tail a logfile from within the script you are writing it to===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#&lt;br /&gt;
# display logfile in real time&lt;br /&gt;
#&lt;br /&gt;
( tail -0f ${LOGFILE} ) &amp;amp;&lt;br /&gt;
tailPID=$!&lt;br /&gt;
&lt;br /&gt;
trap &amp;quot;kill $tailPID&amp;quot; 0 1 2 3 5 9 15&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Dump package, procedure etc. from dba_source in a way that it can be used to recreate it===&lt;br /&gt;
From [https://asktom.oracle.com/pls/apex/f?p=100:11:0::::P11_QUESTION_ID:454220160386 Ask Tom]&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 1000 pages 1000 feedb off verif off&lt;br /&gt;
select decode( type||&amp;#039;-&amp;#039;||to_char(line,&amp;#039;fm99999&amp;#039;), &amp;#039;PACKAGE BODY-1&amp;#039;, &amp;#039;/&amp;#039;||chr(10), null) ||&lt;br /&gt;
       decode(line,1,&amp;#039;create or replace &amp;#039;, &amp;#039;&amp;#039; ) ||&lt;br /&gt;
       text text&lt;br /&gt;
from   dba_source&lt;br /&gt;
where  owner = upper(&amp;#039;&amp;amp;owner&amp;#039;)&lt;br /&gt;
and    name  = upper(&amp;#039;&amp;amp;object_to_show&amp;#039;)&lt;br /&gt;
order  by type&lt;br /&gt;
,      line&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===A trick to exit out of SQL*Plus (using divide by zero) depending on answer to a question===&lt;br /&gt;
This example is taken from ReviewLite.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
-- Settings for customized functionality&lt;br /&gt;
define SCRIPT_OO=_OPTIONS_ONLY -- collect only options information&lt;br /&gt;
define SCRIPT_OO=&amp;#039;&amp;#039;            -- collect all information [default behavior]&lt;br /&gt;
&lt;br /&gt;
define SCRIPT_TS=_TIME_STAMP   -- include timestamp in names of the output directory and output files: YYYY.MM.DD.HH24.MI.SS; script does not prompt for license agreement&lt;br /&gt;
define SCRIPT_TS=&amp;#039;\home\oracle\options&amp;#039;            -- standard names for output directory and output files; script prompts for license agreement [default behavior]&lt;br /&gt;
&lt;br /&gt;
-- PROMT FOR LICENSE AGREEMENT ACCEPTANCE&lt;br /&gt;
DEFINE LANSWER=N&lt;br /&gt;
SET TERMOUT ON&lt;br /&gt;
ACCEPT &amp;amp;SCRIPT_TS LANSWER FORMAT A1 PROMPT &amp;#039;Accept License Agreement? (y\n): &amp;#039;&lt;br /&gt;
&lt;br /&gt;
-- FORCE &amp;quot;divisor is equal to zero&amp;quot; AND SQLERROR EXIT IF NOT ACCEPTED&lt;br /&gt;
-- WILL ALSO CONTINUE IF SCRIPT_TS SUBSTITUTION VARIABLE IS NOT NULL&lt;br /&gt;
SET TERMOUT OFF&lt;br /&gt;
WHENEVER SQLERROR EXIT&lt;br /&gt;
select 1/decode(&amp;#039; &amp;amp;LANSWER&amp;#039;, &amp;#039;Y&amp;#039;, null, &amp;#039;y&amp;#039;, null, decode(&amp;#039; &amp;amp;SCRIPT_TS&amp;#039;, null, 0, null)) as &amp;quot; &amp;quot; from dual;&lt;br /&gt;
WHENEVER SQLERROR CONTINUE&lt;br /&gt;
SET TERMOUT ON&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===How to uninstall optional components such as OWB, APEX, EM, OLAP, OWM from an Oracle database===&lt;br /&gt;
* [http://fast-dba.blogspot.be/2014/04/how-to-remove-unwanted-components-from.html fast-dba.blogspot.be]&lt;br /&gt;
&lt;br /&gt;
===Find unique indexes / primary index / key columns in a table===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
col owner       for a12&lt;br /&gt;
col table_name  for a32&lt;br /&gt;
col column_name for a32&lt;br /&gt;
col position    for 99&lt;br /&gt;
col status      for a10&lt;br /&gt;
set lines 1000 pages 100&lt;br /&gt;
&lt;br /&gt;
SELECT cons.owner&lt;br /&gt;
,      cols.table_name&lt;br /&gt;
,      cols.column_name&lt;br /&gt;
,      cols.position&lt;br /&gt;
,      cons.status&lt;br /&gt;
FROM   all_constraints  cons&lt;br /&gt;
,      all_cons_columns cols&lt;br /&gt;
WHERE  1=1&lt;br /&gt;
and    cols.owner           = &amp;#039;&amp;amp;TABLE_OWNER&amp;#039;&lt;br /&gt;
and    cols.table_name      = &amp;#039;&amp;amp;TABLE_NAME&amp;#039;&lt;br /&gt;
AND    cons.constraint_type = &amp;#039;P&amp;#039;&lt;br /&gt;
AND    cons.constraint_name = cols.constraint_name&lt;br /&gt;
AND    cons.owner           = cols.owner&lt;br /&gt;
ORDER  BY cols.table_name&lt;br /&gt;
,      cols.position&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Display the oracle instances running on the local server===&lt;br /&gt;
sed could be shorter but this one works cross-platform&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alias oenv=&amp;#039;ps -ef|grep pmon|grep -v grep|awk -F_ &amp;quot;{print \$NF}&amp;quot;|sort|uniq|sed -e &amp;quot;:a&amp;quot; -e &amp;quot;N&amp;quot; -e &amp;quot;\$!ba&amp;quot; -e &amp;quot;s/\n/ /g&amp;quot;&amp;#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Display which databases are scheduled for backup in cron===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
for i in `ps -ef | grep [o]ra_pmon | awk -F_ &amp;#039;{print $NF}&amp;#039;`; do&lt;br /&gt;
    crontab -l | grep $i | grep backup_export | awk &amp;#039;{print $2&amp;quot;:&amp;quot;$1&amp;quot; - &amp;quot;$17}&amp;#039;&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Trace SQL statements using autotrace and explain plan===&lt;br /&gt;
If the plustrace (plustrc.sql) role has been granted, explaining sql statements (without running the statement) is as easy as&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter session set sql_trace=true;&lt;br /&gt;
set autotrace traceonly explain&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Write to a trace log from PL/SQL===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
dbms_system.ksdwrt(1,&amp;#039;message sent to a trace file&amp;#039;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Invisible / hidden / virtual columns===&lt;br /&gt;
Article showing how to dump blocks also.&amp;lt;br /&amp;gt;&lt;br /&gt;
[https://www.oracle.com/technetwork/articles/database/invisible-columns-odb12c-2331522.html Tips and Tricks: Invisible Columns in Oracle Database 12c by Alex Zaballa, Oracle Ace and Daniel Da Meda (OCM)]&lt;br /&gt;
&lt;br /&gt;
===Write to the alert log from PL/SQL===&lt;br /&gt;
* [https://www.databasejournal.com/features/oracle/article.php/3386731/Inserting-Custom-Messages-in-Oracle-AlertTrace-files.htm Inserting Custom Messages in Oracle Alert/Trace files]&lt;br /&gt;
Writes to trace file&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
dbms_system.ksdwrt(1,&amp;#039;message sent to trace log&amp;#039;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Writes to the alertlog&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
dbms_system.ksdwrt(2,&amp;#039;message sent to the alertlog&amp;#039;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Writes to the alertlog and trace file&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
dbms_system.ksdwrt(3,&amp;#039;message sent to trace file and the alert log&amp;#039;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Also available, KSDIND, KSDDDT and KSDFLS&lt;br /&gt;
&lt;br /&gt;
===Do distributed SQL transactions exist?===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select * from dba_2pc_pending;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
if yes, and to commit them...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select local_tran_id from dba_2pc_pending;&lt;br /&gt;
exec dbms_transaction.purge_lost_db_entry(&amp;#039;&amp;#039;);&lt;br /&gt;
commit;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Setup optional parameters and default values in an SQL*Plus script===&lt;br /&gt;
Some forgotten SQL*Plus tricks from the good old days and some new ones...&lt;br /&gt;
* [http://www.orafaq.com/wiki/SQL*Plus_FAQ#What_is_the_difference_between_.21_and_HOST.3F orafaq.com]&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set termout off&lt;br /&gt;
col p1 new_value 1&lt;br /&gt;
col p2 new_value 2&lt;br /&gt;
col p3 new_value 3&lt;br /&gt;
select null p1, null p2, null p3 from dual where  1=2;&lt;br /&gt;
select nvl(&amp;#039;&amp;amp;1&amp;#039;,&amp;#039;def1&amp;#039;) p1, nvl(&amp;#039;&amp;amp;2&amp;#039;,&amp;#039;def2&amp;#039;) p2, nvl(&amp;#039;&amp;amp;3&amp;#039;,&amp;#039;def3&amp;#039;) p3 from dual;&lt;br /&gt;
set termout on&lt;br /&gt;
prompt 1=&amp;quot;&amp;amp;1&amp;quot;&lt;br /&gt;
prompt 2=&amp;quot;&amp;amp;2&amp;quot;&lt;br /&gt;
prompt 3=&amp;quot;&amp;amp;3&amp;quot;&lt;br /&gt;
undef 1&lt;br /&gt;
undef 2&lt;br /&gt;
undef 3&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Display / show users with sysdba &amp;amp; sysoper privileges===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select * from v$pwfile_users;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Show path names of data files using instr===&lt;br /&gt;
Use to find the pathnames of all the filesystems/directories in which a database is housed.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select distinct substr(name,1,(instr(name,&amp;#039;/&amp;#039;,-1,1)-1)) path_name from v$datafile&lt;br /&gt;
union&lt;br /&gt;
select distinct substr(name,1,(instr(name,&amp;#039;/&amp;#039;,-1,1)-1)) path_name from v$tempfile&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Does a dataguard standby exist for this database?===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SELECT SUBSTR(value,INSTR(value,&amp;#039;=&amp;#039;,INSTR(UPPER(value),&amp;#039;SERVICE&amp;#039;))+1)&lt;br /&gt;
FROM   v$parameter&lt;br /&gt;
WHERE  name LIKE &amp;#039;log_archive_dest%&amp;#039; AND UPPER(value) LIKE &amp;#039;SERVICE%&amp;#039;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
gives something like this if found...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SUBSTR(VALUE,INSTR(VALUE,&amp;#039;=&amp;#039;,INSTR(UPPER(VALUE),&amp;#039;SERVICE&amp;#039;))+1)&lt;br /&gt;
--------------------------------------------------------------------------------&lt;br /&gt;
&amp;quot;jdbeop1_standby&amp;quot;, LGWR ASYNC NOAFFIRM delay=0 optional compression=disable m&lt;br /&gt;
ax_failure=0 max_connections=1 reopen=300 db_unique_name=&amp;quot;jdbeop1_standby&amp;quot; ne&lt;br /&gt;
t_timeout=60, valid_for=(all_logfiles,primary_role)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===List values for all init parameters in v$parameter (including default values for undocumented (hidden) parameters===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select i.ksppinm||&amp;#039;;&amp;#039;||sv.ksppstvl&lt;br /&gt;
from   x$ksppi  i&lt;br /&gt;
,      x$ksppsv sv&lt;br /&gt;
where  i.indx = sv.indx&lt;br /&gt;
order  by i.ksppinm;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Log file reports pipe errors===&lt;br /&gt;
Found these in the log file&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
solax005:root[/opt/IBM/ITM/logs]# tail solax005_or_RMANV11_col.out&lt;br /&gt;
CIR1880E (024955) Open Probe pipe error 2. Pipe=/opt/IBM/ITM/tmp/solax005_or_RMANV11/prb_RMANV11_kor_solax005_30024832_5346_pipe&lt;br /&gt;
CIR1880E (030938) Open Probe pipe error 2. Pipe=/opt/IBM/ITM/tmp/solax005_or_RMANV11/prb_RMANV11_kor_solax005_30030830_5406_pipe&lt;br /&gt;
CIR1880E (031923) Open Probe pipe error 2. Pipe=/opt/IBM/ITM/tmp/solax005_or_RMANV11/prb_RMANV11_kor_solax005_30031832_5434_pipe&lt;br /&gt;
CIR1880E (033934) Open Probe pipe error 2. Pipe=/opt/IBM/ITM/tmp/solax005_or_RMANV11/prb_RMANV11_kor_solax005_30033831_5495_pipe&lt;br /&gt;
CIR1880E (034918) Open Probe pipe error 2. Pipe=/opt/IBM/ITM/tmp/solax005_or_RMANV11/prb_RMANV11_kor_solax005_30034833_5521_pipe&lt;br /&gt;
CIR1880E (041927) Open Probe pipe error 2. Pipe=/opt/IBM/ITM/tmp/solax005_or_RMANV11/prb_RMANV11_kor_solax005_30041835_5610_pipe&lt;br /&gt;
CIR1880E (042931) Open Probe pipe error 2. Pipe=/opt/IBM/ITM/tmp/solax005_or_RMANV11/prb_RMANV11_kor_solax005_30042832_5642_pipe&lt;br /&gt;
CIR1880E (045928) Open Probe pipe error 2. Pipe=/opt/IBM/ITM/tmp/solax005_or_RMANV11/prb_RMANV11_kor_solax005_30045835_5730_pipe&lt;br /&gt;
CIR1880E (052927) Open Probe pipe error 2. Pipe=/opt/IBM/ITM/tmp/solax005_or_RMANV11/prb_RMANV11_kor_solax005_30052838_5819_pipe&lt;br /&gt;
CIR1880E (090929) Open Probe pipe error 2. Pipe=/opt/IBM/ITM/tmp/solax005_or_RMANV11/prb_RMANV11_kor_solax005_30090833_6487_pipe&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This could be due to a timeout on the pipe.&amp;lt;br /&amp;gt;&lt;br /&gt;
Increase parameters and restart agent. Add following lines to or.config:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
export COLL_WAIT_TIMEOUT=&amp;#039;200&amp;#039;&lt;br /&gt;
export WAIT_TIMEOUT=&amp;#039;200&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Find the most recent archived SCN number===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
col next_change# for 999999999999999&lt;br /&gt;
set numwidth 15&lt;br /&gt;
&lt;br /&gt;
select max(next_change#)&lt;br /&gt;
from   v$archived_log&lt;br /&gt;
where  (thread#, next_change#) in ( select thread#, max(next_change#)&lt;br /&gt;
                                    from   v$archived_log&lt;br /&gt;
                                    where  archived     = &amp;#039;YES&amp;#039;&lt;br /&gt;
                                    and    status       = &amp;#039;A&amp;#039;&lt;br /&gt;
                                    and    resetlogs_id = ( select resetlogs_id&lt;br /&gt;
                                                            from   v$database_incarnation&lt;br /&gt;
                                                            where  status = &amp;#039;CURRENT&amp;#039;&lt;br /&gt;
                                                          )&lt;br /&gt;
                                    group by thread#&lt;br /&gt;
                                  )&lt;br /&gt;
and    status = &amp;#039;A&amp;#039;&lt;br /&gt;
and    resetlogs_id = ( select resetlogs_id&lt;br /&gt;
                        from   v$database_incarnation&lt;br /&gt;
                        where  status = &amp;#039;CURRENT&amp;#039;&lt;br /&gt;
                      )&lt;br /&gt;
order  by next_change# asc;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Monitoring says database inactive===&lt;br /&gt;
* Check the candle user password has not expired in the database.&lt;br /&gt;
* There may be a clue in the log file. Check /opt/IBM/ITM/logs/`hostname`_or_${SID}_col.out&lt;br /&gt;
* Check limits for itmora account in /etc/security/limits. Should be same as oracle user.&lt;br /&gt;
* Check the config file. We had this issue when a new ORACLE_HOME was installed but the cfg file still had the old one in it.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
export ITM_HOME=/opt/IBM/ITM&lt;br /&gt;
cd $ITM_HOME/config&lt;br /&gt;
vi solax005_or_SRV2R.cfg&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#  IBM Tivoli Monitoring for Databases: Oracle Agent&lt;br /&gt;
#  Configuration file: solax005_or_SRV2R.cfg&lt;br /&gt;
#  Written by CandleDBconfig version: 1.4 on 31Jul13 13:39:41&lt;br /&gt;
&lt;br /&gt;
#  Note: this is a Korn-shell script that is &amp;quot;sourced&amp;quot; to create the&lt;br /&gt;
#  environment for a Monitoring Agent for Oracle.  It can be used to create&lt;br /&gt;
#  the environment to run the IBM-supplied database grant scripts.&lt;br /&gt;
&lt;br /&gt;
#  IBM does not recommend that you modify this file, but you can change the&lt;br /&gt;
#  data values or add new exported variables as long as the file is a valid ksh&lt;br /&gt;
#  script that executes with zero return code, and values remain quoted with &amp;quot;&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
#  Following environment variables are set for convenience in running grants.&lt;br /&gt;
   export ORACLE_SID=&amp;quot;SRV2R&amp;quot;&lt;br /&gt;
   export ORACLE_HOME=&amp;quot;/oracle/product/11.2.0.1&amp;quot;&lt;br /&gt;
   # IY92195  COLL_DISABLE_CURSORS setting&lt;br /&gt;
   export TNS_ADMIN=&amp;quot;/oracle/product/11.2.0.1/network/admin&amp;quot;&lt;br /&gt;
&lt;br /&gt;
#  Following variables are set for the setup scripts&lt;br /&gt;
   db_sid=&amp;quot;SRV2R&amp;quot;&lt;br /&gt;
   db_home=&amp;quot;/oracle/product/11.2.0.1&amp;quot;&lt;br /&gt;
   db_initfilename=&amp;quot;&amp;quot;&lt;br /&gt;
   db_login=&amp;quot;tivoli&amp;quot;&lt;br /&gt;
   db_password=&amp;quot;795D8822BC49477323815CD21C1E66E966E48EEE19C6A98056224D649B0FE316E6A11DC3F4E9BB5E226B65A8&amp;quot;&lt;br /&gt;
   db_ver=&amp;quot;11.x&amp;quot;&lt;br /&gt;
   db_type=&amp;quot;kor&amp;quot;&lt;br /&gt;
   db_tns=&amp;quot;/oracle/product/11.2.0.1/network/admin&amp;quot;&lt;br /&gt;
   db_extparms=&amp;quot;&amp;quot;&lt;br /&gt;
   db_hostname=&amp;quot;solax005&amp;quot;&lt;br /&gt;
   db_reason=&amp;quot;AIX_ps_ceww&amp;quot;&lt;br /&gt;
   db_pipedir=&amp;quot;&amp;quot;&lt;br /&gt;
   db_installstatus=&amp;quot;CONFIGSUCCESS&amp;quot;&lt;br /&gt;
&lt;br /&gt;
#  User-defined environment variables&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Solution:&amp;lt;br /&amp;gt;&lt;br /&gt;
* Change all occurrences of 11.2.0.1 to 11.2.0.3&lt;br /&gt;
* Restart agent&lt;br /&gt;
&lt;br /&gt;
===Alerts due to password expiring (or being changed in the database but not in ITM!)===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cd $ITM_HOME/logs&lt;br /&gt;
ls -altr | grep WM820T&lt;br /&gt;
tail -20 solax005_or_WM820T_col.out&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
CGN1521E (161614) Interval collection failed for cursor KORHART2&lt;br /&gt;
RCD0110S (161614) Invalid Oracle logon id (tivoli) or password given&lt;br /&gt;
 Please contact DBA to correct userid or password&lt;br /&gt;
CGN1521E (161614) Interval collection failed for cursor KORHART4&lt;br /&gt;
CGN1525E (161614) One or more interval cursors failed&lt;br /&gt;
RCD0110S (161714) Invalid Oracle logon id (tivoli) or password given&lt;br /&gt;
 Please contact DBA to correct userid or password&lt;br /&gt;
CGN1521E (161714) Interval collection failed for cursor KORHART2&lt;br /&gt;
RCD0110S (161714) Invalid Oracle logon id (tivoli) or password given&lt;br /&gt;
 Please contact DBA to correct userid or password&lt;br /&gt;
CGN1521E (161714) Interval collection failed for cursor KORHART4&lt;br /&gt;
CGN1525E (161714) One or more interval cursors failed&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Solution:&amp;lt;br /&amp;gt;&lt;br /&gt;
* Run agent reconfigure to setup the new password for the candle user (tivoli)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
export ITM_HOME=/opt/IBM/ITM&lt;br /&gt;
$ITM_HOME/bin/itmcmd config -A or&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Restart agent&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
export ITM_HOME=/opt/IBM/ITM&lt;br /&gt;
$ITM_HOME/smitools/scripts/StartAgent.sh restart or -o WM820T&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Many agents started with root user instead of itmora===&lt;br /&gt;
This can happen if the server is rebooted before the agents have been added to the itmora list using kdyedit / kciedit&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
export CANDLEHOME=/opt/IBM/ITM&lt;br /&gt;
export ITM_HOME=/opt/IBM/ITM&lt;br /&gt;
$ITM_HOME/smitools/scripts/kdyedit list&lt;br /&gt;
Type Runas      Inst                &lt;br /&gt;
or   root       AGPDEV              &lt;br /&gt;
or   root       BO1R                &lt;br /&gt;
or   root       DEV3                &lt;br /&gt;
or   root       EMREP               &lt;br /&gt;
or   root       ICR                 &lt;br /&gt;
or   itmora     MAPDEV              &lt;br /&gt;
or   itmora     MAPER               &lt;br /&gt;
or   itmora     PED                 &lt;br /&gt;
or   itmora     PER                 &lt;br /&gt;
or   itmora     RMANV11             &lt;br /&gt;
or   itmora     SRV2R               &lt;br /&gt;
or   itmora     WM820Q              &lt;br /&gt;
or   itmora     WM820T              &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ITM_HOME/smitools/scripts/kciedit list&lt;br /&gt;
Type Runas      Inst                &lt;br /&gt;
or   root       AGPDEV              &lt;br /&gt;
or   root       BO1R                &lt;br /&gt;
or   root       DEV3                &lt;br /&gt;
or   root       EMREP               &lt;br /&gt;
or   root       ICR                 &lt;br /&gt;
or   itmora     MAPDEV              &lt;br /&gt;
or   itmora     MAPER               &lt;br /&gt;
or   itmora     PED                 &lt;br /&gt;
or   itmora     PER                 &lt;br /&gt;
or   itmora     RMANV11             &lt;br /&gt;
or   itmora     SRV2R               &lt;br /&gt;
or   itmora     WM820Q              &lt;br /&gt;
or   itmora     WM820T              &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Solution: Add these instances to the itmora list&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
./kdyedit -t or -i AGPDEV -r itmora add&lt;br /&gt;
./kciedit -t or -i AGPDEV -r itmora add&lt;br /&gt;
...&lt;br /&gt;
./kdyedit -t or -i ICR -r itmora add&lt;br /&gt;
./kciedit -t or -i ICR -r itmora add&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ITM_HOME/smitools/scripts/kciedit list&lt;br /&gt;
Type Runas      Inst                &lt;br /&gt;
or   itmora     AGPDEV              &lt;br /&gt;
or   itmora     BO1R                &lt;br /&gt;
or   itmora     DEV3                &lt;br /&gt;
or   itmora     EMREP               &lt;br /&gt;
or   itmora     ICR                 &lt;br /&gt;
or   itmora     MAPDEV              &lt;br /&gt;
or   itmora     MAPER               &lt;br /&gt;
or   itmora     PED                 &lt;br /&gt;
or   itmora     PER                 &lt;br /&gt;
or   itmora     RMANV11             &lt;br /&gt;
or   itmora     SRV2R               &lt;br /&gt;
or   itmora     WM820Q              &lt;br /&gt;
or   itmora     WM820T              &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Kill any agents still running as root&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ps -ef |grep kor | grep root&lt;br /&gt;
kill -9 &amp;lt;process id&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Because these agents were owned by root, there will be permissions issues when trying to restart the agents with itmora so these need to be fixed before restarting the agents.&amp;lt;br /&amp;gt;&lt;br /&gt;
The simplest way of doing this is to run lockdown.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
export CANDLEHOME=/opt/IBM/ITM&lt;br /&gt;
$CANDLEHOME/smitools/scripts/lockdown.sh&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===See which processes are causing paging===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
svmon -Pt20 | perl -e &amp;#039;while(&amp;lt;&amp;gt;){print if($.==2||$&amp;amp;&amp;amp;&amp;amp;!$s++);$.=0 if(/^-+$/)}&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===How to return several variables from SQL*Plus back to Korn shell script===&lt;br /&gt;
Return multiple columns/elements from Oracle to shell script at the same time&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sqlplus -s sys/${SYS_PASSWORD}@${SID} as sysdba&amp;lt;&amp;lt;EOSQL | read SPACE_AFTER_INSTALL TOTAL_SPACE_AVAILABLE&lt;br /&gt;
set numwid 15 headi off newpa none feedb off&lt;br /&gt;
select sign(${SPACE_USED} + ${SPACE_AVAILABLE} - ${DATABASE_SIZE}), trim(${SPACE_USED} + ${SPACE_AVAILABLE})&lt;br /&gt;
from dual&lt;br /&gt;
/&lt;br /&gt;
EOSQL&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===How to get a shell environment variable from the operating system into the SQL or PL/SQL environment===&lt;br /&gt;
This has been bugging me for years. Something you would think simple... what is ORACLE_HOME? I know it&amp;#039;s a question mark at the SQL prompt but how to get it&amp;#039;s O/S value?&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
declare&lt;br /&gt;
    var1 varchar2(200);&lt;br /&gt;
begin&lt;br /&gt;
    dbms_system.get_env (&amp;#039;ORACLE_HOME&amp;#039;, var1);&lt;br /&gt;
    dbms_output.put_line (&amp;#039;ORACLE_HOME: &amp;#039;||var1);&lt;br /&gt;
end;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or in SQL*Plus&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
variable var1 varchar2(200);&lt;br /&gt;
exec dbms_system.get_env (&amp;#039;ORACLE_HOME&amp;#039;, :var1);&lt;br /&gt;
select :var1 from dual;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
That got me thinking... if this just gets stuff from the environment, it can fetch any exported variable?!?!&amp;lt;br /&amp;gt;&lt;br /&gt;
From the shell:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
export running_sids=`ps -ef | grep [p]mon | awk -F_ &amp;#039;{print $NF}&amp;#039;`&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
and now in SQL*Plus:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
variable sids varchar2(240);&lt;br /&gt;
exec dbms_system.get_env (&amp;#039;running_sids&amp;#039;, :sids);&lt;br /&gt;
select :sids from dual;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Wow!&lt;br /&gt;
&lt;br /&gt;
===How long/wide can a database name/sid be?===&lt;br /&gt;
Depends on where you look but taking the minimum here as &amp;quot;safe&amp;quot;, it should still be limited to 8 characters...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
col table_name for a30&lt;br /&gt;
col data_type  for a12&lt;br /&gt;
select table_name, data_type, data_length from dba_tab_columns where column_name = &amp;#039;DB_NAME&amp;#039;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This is 11gR2&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
TABLE_NAME                     DATA_TYPE    DATA_LENGTH&lt;br /&gt;
------------------------------ ------------ -----------&lt;br /&gt;
LOGMNRG_DICTIONARY$            VARCHAR2               9&lt;br /&gt;
SYS_FBA_CONTEXT_AUD            VARCHAR2             256&lt;br /&gt;
V_$LOGMNR_DICTIONARY           VARCHAR2               9&lt;br /&gt;
V_$LOGMNR_LOGS                 VARCHAR2               8&lt;br /&gt;
GV_$LOGMNR_DICTIONARY          VARCHAR2               9&lt;br /&gt;
GV_$LOGMNR_LOGS                VARCHAR2               8&lt;br /&gt;
V_$LOGMNR_LOGFILE              VARCHAR2               8&lt;br /&gt;
V_$LOGMNR_SESSION              VARCHAR2             128&lt;br /&gt;
GV_$LOGMNR_LOGFILE             VARCHAR2               8&lt;br /&gt;
GV_$LOGMNR_SESSION             VARCHAR2             128&lt;br /&gt;
GV_$ASM_CLIENT                 VARCHAR2               8&lt;br /&gt;
V_$ASM_CLIENT                  VARCHAR2               8&lt;br /&gt;
GV_$IOS_CLIENT                 VARCHAR2              64&lt;br /&gt;
V_$IOS_CLIENT                  VARCHAR2              64&lt;br /&gt;
DBA_PDB_HISTORY                VARCHAR2             128&lt;br /&gt;
CDB_PDB_HISTORY                VARCHAR2             128&lt;br /&gt;
SSCR_CAP$                      VARCHAR2            4000&lt;br /&gt;
SSCR_RES$                      VARCHAR2            4000&lt;br /&gt;
DBA_SSCR_CAPTURE               VARCHAR2            4000&lt;br /&gt;
CDB_SSCR_CAPTURE               VARCHAR2            4000&lt;br /&gt;
DBA_SSCR_RESTORE               VARCHAR2            4000&lt;br /&gt;
CDB_SSCR_RESTORE               VARCHAR2            4000&lt;br /&gt;
WRM$_DATABASE_INSTANCE         VARCHAR2               9&lt;br /&gt;
INT$DBA_HIST_DATABASE_INSTANCE VARCHAR2               9&lt;br /&gt;
DBA_HIST_DATABASE_INSTANCE     VARCHAR2               9&lt;br /&gt;
CDB_HIST_DATABASE_INSTANCE     VARCHAR2               9&lt;br /&gt;
LOGMNR_DICTIONARY$             VARCHAR2               9&lt;br /&gt;
&lt;br /&gt;
27 rows selected.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===What character set (characterset) was the database built with?===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
col name  for a40&lt;br /&gt;
col value for a60&lt;br /&gt;
select * from nls_database_parameters;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
col name   for a40&lt;br /&gt;
col value$ for a60&lt;br /&gt;
select name,value$ from props$ where name = &amp;#039;NLS_CHARACTERSET&amp;#039;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===How to get value of ORACLE_HOME from shell environment into SQL*Plus or PL/SQL===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
var orahome varchar2(2000);&lt;br /&gt;
exec dbms_system.get_env(&amp;#039;ORACLE_HOME&amp;#039;, :orahome);&lt;br /&gt;
print orahome&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===How to find ORACLE_HOME from pmon process for a SID if there is no entry in oratab===&lt;br /&gt;
If database is created without dbca (datafile and controlfile copy), no entry will be automatically made in /etc/oratab.&amp;lt;br /&amp;gt;&lt;br /&gt;
So the problem is that you need to find out which of the ORACLE_HOMEs is being used by the running instances.&lt;br /&gt;
* Solaris, Linux&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ ps -ef | grep [p]mon&lt;br /&gt;
  oracle 10848     1   0 00:21:20 ?           2:11 ora_pmon_JDBEOP1&lt;br /&gt;
$ pwdx 10848&lt;br /&gt;
10848:  /oracle/JDBEOP1/product/11204/dbs&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* AIX&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ ps -ef | grep [p]mon&lt;br /&gt;
  oracle 13893878        1   0   Aug 12      -  7:53 ora_pmon_GOAQ1&lt;br /&gt;
$ ls -al /proc/13893878/cwd&lt;br /&gt;
lr-x------    2 oracle   dba               0 Aug 12 13:37  cwd -&amp;gt; /data/opt/app/product/11.2.0.4/db_1/dbs/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or&amp;lt;br /&amp;gt;&lt;br /&gt;
This command (ps eww) gives lots of information about the given process (pmon in this case). Tells you where the instance was started, whether it was started from SQL*Plus or RMAN, the http_proxy and loads more useful bits!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ps -ef | grep [p]mon | awk &amp;#039;{print $2}&amp;#039; | xargs -I {} ps eww {} | awk &amp;#039;{print $1 &amp;quot; &amp;quot; $5 &amp;quot; &amp;quot; $6 &amp;quot; &amp;quot; $0}&amp;#039; | sed &amp;#039;s/\(S*\) \(S*\) .*ORACLE_HOME/\1 \2/g&amp;#039; | cut -f1,2,3 -d&amp;quot; &amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Escape the underscore(_) or percent(%) character in an SQL statement===&lt;br /&gt;
The underscore matches any single character so to return data containing an underscore means having to use an escape character.&amp;lt;br /&amp;gt;&lt;br /&gt;
Here I use the backslash(\) so it is easy for Unix people to understand the mechanism.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select username from dba_users where username like &amp;#039;ENDUR\_DEV%&amp;#039; escape &amp;#039;\&amp;#039;; &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Validate, analyse and rebuild indexes===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set feedback off&lt;br /&gt;
set linesize 132&lt;br /&gt;
set serveroutput on&lt;br /&gt;
set trimspool on&lt;br /&gt;
&lt;br /&gt;
declare&lt;br /&gt;
    LOCKED exception;&lt;br /&gt;
    pragma exception_init (LOCKED, -54);&lt;br /&gt;
&lt;br /&gt;
    dbase         char(8);&lt;br /&gt;
    dbuser        varchar2(30);&lt;br /&gt;
    index_name    varchar(30);&lt;br /&gt;
    free_text     varchar2(50);&lt;br /&gt;
    pctused       number;&lt;br /&gt;
    height    number;&lt;br /&gt;
    index_mb      number;&lt;br /&gt;
    analyze_sql   varchar2(100);&lt;br /&gt;
    pct_used_sql  varchar2(150);&lt;br /&gt;
    rebuild_sql   varchar2(150);&lt;br /&gt;
 &lt;br /&gt;
    cursor c1 is&lt;br /&gt;
    select segment_name, bytes&lt;br /&gt;
    from   user_segments&lt;br /&gt;
    where  segment_type = &amp;#039;INDEX&amp;#039;&lt;br /&gt;
    and    segment_name like &amp;#039;DW%&amp;#039;&lt;br /&gt;
    and    segment_name not like &amp;#039;BIN%&amp;#039;&lt;br /&gt;
    and    bytes/1024   &amp;gt;= 1024&lt;br /&gt;
    order  by 2;&lt;br /&gt;
&lt;br /&gt;
-- validate the index&lt;br /&gt;
procedure validate_index (v_ind in varchar2) is&lt;br /&gt;
begin&lt;br /&gt;
    analyze_sql := &amp;#039;analyze index &amp;#039;||v_ind||&amp;#039; validate structure&amp;#039;;&lt;br /&gt;
    begin&lt;br /&gt;
        execute immediate analyze_sql;&lt;br /&gt;
    exception&lt;br /&gt;
    when LOCKED then&lt;br /&gt;
        dbms_output.put_line (v_ind||&amp;#039; locked - skipping&amp;#039;);&lt;br /&gt;
        pctused := 100;&lt;br /&gt;
        return;&lt;br /&gt;
    when others then&lt;br /&gt;
        dbms_output.put_line (analyze_sql);&lt;br /&gt;
        raise;&lt;br /&gt;
    end;&lt;br /&gt;
&lt;br /&gt;
    pct_used_sql := &amp;#039;select pct_used, round(blocks*8192/(1024*1024)), height from index_stats where name = &amp;#039;&amp;#039;&amp;#039;||v_ind||&amp;#039;&amp;#039;&amp;#039;&amp;#039;;&lt;br /&gt;
    execute immediate pct_used_sql into pctused, index_mb, height;&lt;br /&gt;
    if pctused is null then&lt;br /&gt;
        pctused := 0;&lt;br /&gt;
    end if;&lt;br /&gt;
    dbms_output.put_line (rpad(v_ind,35)||&amp;#039; (pct used &amp;#039;||pctused||&amp;#039;% size &amp;#039;||index_mb||&amp;#039;Mb height &amp;#039; || height ||&amp;#039;)&amp;#039;);&lt;br /&gt;
end validate_index;&lt;br /&gt;
 &lt;br /&gt;
-- execute SQL and trace if errors&lt;br /&gt;
procedure run_sql (v_sql in varchar2) is&lt;br /&gt;
begin&lt;br /&gt;
    execute immediate v_sql;&lt;br /&gt;
exception&lt;br /&gt;
when others then&lt;br /&gt;
    dbms_output.put_line (v_sql);&lt;br /&gt;
    raise;&lt;br /&gt;
end run_sql;&lt;br /&gt;
 &lt;br /&gt;
--&lt;br /&gt;
-- Script starts here&lt;br /&gt;
--&lt;br /&gt;
begin&lt;br /&gt;
    dbms_output.enable(1000000);&lt;br /&gt;
    -- Set up database name and schema&lt;br /&gt;
    -- select name into dbase  from v$database;&lt;br /&gt;
    select user into dbuser from dual;&lt;br /&gt;
    dbms_output.put_line(&amp;#039;============================================================================= *&amp;#039;);&lt;br /&gt;
    -- dbms_output.put_line(&amp;#039;* Indexes rebuild report for &amp;#039;||dbuser||&amp;#039; on &amp;#039;||dbase);&lt;br /&gt;
    dbms_output.put_line(&amp;#039;============================================================================= *&amp;#039;);&lt;br /&gt;
&lt;br /&gt;
    -- Loop around Indexes&lt;br /&gt;
    for x in c1 loop&lt;br /&gt;
        index_name := x.segment_name;&lt;br /&gt;
        validate_index (index_name );&lt;br /&gt;
        if pctused &amp;lt; 81 then&lt;br /&gt;
            if x.bytes/1024/1024 &amp;lt; 100 then&lt;br /&gt;
                rebuild_sql := &amp;#039;alter index &amp;#039;||x.segment_name||&amp;#039; rebuild online&amp;#039;;&lt;br /&gt;
            else&lt;br /&gt;
                rebuild_sql := &amp;#039;alter index &amp;#039;||x.segment_name||&amp;#039; coalesce&amp;#039;;&lt;br /&gt;
            end if;&lt;br /&gt;
            dbms_output.put_line (rebuild_sql);&lt;br /&gt;
            run_sql (rebuild_sql);&lt;br /&gt;
            validate_index (index_name);&lt;br /&gt;
        end if;&lt;br /&gt;
    end loop;&lt;br /&gt;
end;&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
set feed on&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Rebuild unusable indexes on a table===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select &amp;#039;alter index &amp;#039;||owner||&amp;#039;.&amp;#039;||index_name||&amp;#039; rebuild;&amp;#039;&lt;br /&gt;
from   dba_indexes&lt;br /&gt;
where  1=1&lt;br /&gt;
and    status    != &amp;#039;VALID&amp;#039;&lt;br /&gt;
and    owner     not in (&amp;#039;SYS&amp;#039;,&amp;#039;SYSTEM&amp;#039;)&lt;br /&gt;
--and    owner      = &amp;#039;WM822PP&amp;#039;&lt;br /&gt;
--and    table_name = &amp;#039;WF_PLANTS&amp;#039;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Pull the latest cfengine changes now instead of waiting for scheduled time===&lt;br /&gt;
For one host&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/opt/cfengine/bin/cfagent -ID dbaTime&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
On all hosts at the same time&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/home/ibmtools/scripts/oracle/dosh -c &amp;quot;/opt/cfengine/bin/cfagent -ID dbaTime&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Check status of datafiles without dba_data_files or v$datafile===&lt;br /&gt;
If the database is in mount mode, most tables are unavailable. This query uses the x$ (c based) tables and are always available&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set linesize 200;&lt;br /&gt;
set pagesize 100;&lt;br /&gt;
col inst_id for 9999999 heading &amp;#039;Instance #&amp;#039;&lt;br /&gt;
col file_nr for 9999999 heading &amp;#039;File #&amp;#039;&lt;br /&gt;
col file_name for A50 heading &amp;#039;File name&amp;#039;&lt;br /&gt;
col checkpoint_change_nr for 99999999999999 heading &amp;#039;Checkpoint #&amp;#039;&lt;br /&gt;
col checkpoint_change_time for A20 heading &amp;#039;Checkpoint time&amp;#039;&lt;br /&gt;
col last_change_nr for 99999999999999 heading &amp;#039;Last change #&amp;#039;&lt;br /&gt;
SELECT&lt;br /&gt;
      fe.inst_id,&lt;br /&gt;
      fe.fenum file_nr,&lt;br /&gt;
      fn.fnnam file_name,&lt;br /&gt;
      TO_NUMBER (fe.fecps) checkpoint_change_nr,&lt;br /&gt;
      fe.fecpt checkpoint_change_time,&lt;br /&gt;
      fe.fests last_change_nr,&lt;br /&gt;
      DECODE (&lt;br /&gt;
              fe.fetsn,&lt;br /&gt;
              0, DECODE (BITAND (fe.festa, 2), 0, &amp;#039;SYSOFF&amp;#039;, &amp;#039;SYSTEM&amp;#039;),&lt;br /&gt;
              DECODE (BITAND (fe.festa, 18),&lt;br /&gt;
                      0, &amp;#039;OFFLINE&amp;#039;,&lt;br /&gt;
                      2, &amp;#039;ONLINE&amp;#039;,&lt;br /&gt;
                      &amp;#039;RECOVER&amp;#039;)&lt;br /&gt;
      ) status&lt;br /&gt;
FROM x$kccfe fe,&lt;br /&gt;
     x$kccfn fn&lt;br /&gt;
WHERE    (   (fe.fepax != 65535 AND fe.fepax != 0 )&lt;br /&gt;
          OR (fe.fepax = 65535 OR fe.fepax = 0)&lt;br /&gt;
         )&lt;br /&gt;
     AND fn.fnfno = fe.fenum&lt;br /&gt;
     AND fe.fefnh = fn.fnnum&lt;br /&gt;
     AND fe.fedup != 0&lt;br /&gt;
     AND fn.fntyp = 4&lt;br /&gt;
     AND fn.fnnam IS NOT NULL&lt;br /&gt;
     AND BITAND (fn.fnflg, 4) != 4&lt;br /&gt;
ORDER BY fe.fenum&lt;br /&gt;
;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Check highest allocated extent in datafile (likely slow when having many extents)===&lt;br /&gt;
* Script to Detect Tablespace Fragmentation ( Doc ID 1020182.6 )&lt;br /&gt;
* How to shrink or reduce the datafile size by finding the high water mark (HWM) ( Doc ID 1600774.1 )&lt;br /&gt;
* How to find Objects Fragmented below High Water Mark ( Doc ID 337651.1 )&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
column file_name format a50;&lt;br /&gt;
column tablespace_name format a15;&lt;br /&gt;
column highwater format 9999999999;&lt;br /&gt;
set pagesize 9999&lt;br /&gt;
&lt;br /&gt;
select a.tablespace_name&lt;br /&gt;
,a.file_name&lt;br /&gt;
,(b.maximum+c.blocks-1)*d.db_block_size highwater&lt;br /&gt;
from dba_data_files a&lt;br /&gt;
,(select file_id,max(block_id) maximum&lt;br /&gt;
from dba_extents&lt;br /&gt;
group by file_id) b&lt;br /&gt;
,dba_extents c&lt;br /&gt;
,(select value db_block_size&lt;br /&gt;
from v$parameter&lt;br /&gt;
where name=&amp;#039;db_block_size&amp;#039;) d&lt;br /&gt;
where a.file_id = b.file_id&lt;br /&gt;
and c.file_id = b.file_id&lt;br /&gt;
and c.block_id = b.maximum&lt;br /&gt;
order by a.tablespace_name,a.file_name&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Runup to this was...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set markup html on spool on&lt;br /&gt;
spool db_info.html&lt;br /&gt;
set echo on&lt;br /&gt;
select * from dba_tablespaces where tablespace_name = &amp;#039;&amp;amp;&amp;amp;tablespace_name&amp;#039;;&lt;br /&gt;
select * from dba_data_files where tablespace_name = &amp;#039;&amp;amp;tablespace_name&amp;#039;;&lt;br /&gt;
select * from (select * from dba_extents where tablespace_name = &amp;#039;&amp;amp;tablespace_name&amp;#039; order by block_id desc) where rownum &amp;lt;301;&lt;br /&gt;
spool off&lt;br /&gt;
set markup html off&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select owner, segment_type, count(*) from dba_segments where tablesapce_name=&amp;#039;&amp;amp;tablespace_name&amp;#039; group by owner, segment_type;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
begin&lt;br /&gt;
for ii in (select owner, segment_name, segment_type from dba_segments where tablespace_name = &amp;#039;&amp;amp;tablespace_name&amp;#039; and segment_type like &amp;#039;TABLE%&amp;#039; and segment_name not like &amp;#039;%DATAPUMP%&amp;#039;)&lt;br /&gt;
loop&lt;br /&gt;
if ii.segment_type=&amp;#039;TABLE&amp;#039; then&lt;br /&gt;
begin&lt;br /&gt;
execute immediate(&amp;#039;alter table &amp;#039;||ii.owner||&amp;#039;.&amp;#039;||ii.segment_name||&amp;#039; enable row movement&amp;#039;);&lt;br /&gt;
execute immediate(&amp;#039;alter table &amp;#039;||ii.owner||&amp;#039;.&amp;#039;||ii.segment_name||&amp;#039; shrink space cascade&amp;#039;);&lt;br /&gt;
exception when others then&lt;br /&gt;
dbms_output.put_line(&amp;#039;FAILED 1: alter table &amp;#039;||ii.owner||&amp;#039;.&amp;#039;||ii.segment_name||&amp;#039; shrink space cascade : &amp;#039;||SQLERRM);&lt;br /&gt;
end;&lt;br /&gt;
end if;&lt;br /&gt;
end loop;&lt;br /&gt;
end;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Procedure to shrink space in tables and indexes===&lt;br /&gt;
* [http://www.oracle-wiki.net/startdocsreallifeshrinkexample Using the Oracle Shrink Command] - lots of good stuff at this site&lt;br /&gt;
Written by [https://asktom.oracle.com/pls/apex/f%3Fp%3D100:11:0::::P11_QUESTION_ID:5645095700346948864 Tom Kyte]&amp;lt;br /&amp;gt;&lt;br /&gt;
Depending on the Oracle version, this procedure may or may not work! It does not include the compact clause (neither does it re-analyse to prove it worked).&amp;lt;br /&amp;gt;&lt;br /&gt;
[http://www.oracle-wiki.net/startdocsreallifeshrinkexample Here] is a worked example that shows the complete process - oracle-wiki.net&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
create or replace procedure shrink_all&lt;br /&gt;
as&lt;br /&gt;
    l_sql        varchar2(4000);&lt;br /&gt;
    l_sql2       varchar2(4000);&lt;br /&gt;
    row_movement exception;&lt;br /&gt;
    pragma       exception_init( row_movement, -10636 );&lt;br /&gt;
begin&lt;br /&gt;
    for x in (select table_name&lt;br /&gt;
              ,      owner&lt;br /&gt;
              from   t&lt;br /&gt;
              where  sgm_space_management = &amp;#039;AUTO&amp;#039;)&lt;br /&gt;
    loop&lt;br /&gt;
        l_sql := &amp;#039;alter table &amp;quot;&amp;#039; || x.owner || &amp;#039;&amp;quot;.&amp;quot;&amp;#039; || x.table_name || &amp;#039;&amp;quot; shrink space&amp;#039;;&lt;br /&gt;
        dbms_output.put_line( l_sql );&lt;br /&gt;
&lt;br /&gt;
        begin&lt;br /&gt;
            execute immediate l_sql;&lt;br /&gt;
        exception&lt;br /&gt;
        when row_movement&lt;br /&gt;
        then&lt;br /&gt;
            dbms_output.put_line( &amp;#039;failed due to row movement...&amp;#039; );&lt;br /&gt;
            l_sql2 := &amp;#039;alter table &amp;quot;&amp;#039; || x.owner || &amp;#039;&amp;quot;.&amp;quot;&amp;#039; || x.table_name || &amp;#039;&amp;quot; enable row movement&amp;#039;;&lt;br /&gt;
            dbms_output.put_line( l_sql2 );&lt;br /&gt;
            execute immediate l_sql2;&lt;br /&gt;
            dbms_output.put_line( l_sql );&lt;br /&gt;
            execute immediate l_sql;&lt;br /&gt;
        end;&lt;br /&gt;
&lt;br /&gt;
        for y in (select owner&lt;br /&gt;
                  ,      index_name&lt;br /&gt;
                  from   dba_indexes&lt;br /&gt;
                  where  table_owner = x.owner&lt;br /&gt;
                  and    table_name  = x.table_name )&lt;br /&gt;
        loop&lt;br /&gt;
            l_sql := &amp;#039;alter index &amp;quot;&amp;#039; || y.owner || &amp;#039;&amp;quot;.&amp;quot;&amp;#039; || y.index_name || &amp;#039;&amp;quot; shrink space&amp;#039;;&lt;br /&gt;
            dbms_output.put_line( l_sql );&lt;br /&gt;
            execute immediate l_sql;&lt;br /&gt;
        end loop;&lt;br /&gt;
&lt;br /&gt;
    end loop;&lt;br /&gt;
end;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===How to delete/kill a distributed transaction===&lt;br /&gt;
From [http://www.pouwiel.com/?p=2204 pouwiel.com]&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SQL&amp;gt; SELECT LOCAL_TRAN_ID, GLOBAL_TRAN_ID,to_char(FAIL_TIME,&amp;#039;dd-mon-yyyy HH24:MI:SS&amp;#039;),STATE, MIXED FROM DBA_2PC_PENDING;&lt;br /&gt;
&lt;br /&gt;
LOCAL_TRAN_ID&lt;br /&gt;
----------------------&lt;br /&gt;
GLOBAL_TRAN_ID&lt;br /&gt;
--------------------------------------------------------------------------------&lt;br /&gt;
TO_CHAR(FAIL_TIME,&amp;#039;D STATE MIX&lt;br /&gt;
-------------------- ---------------- ---&lt;br /&gt;
8.19.321913&lt;br /&gt;
1463898948.0000013CDE8005110000000179F68840A089FFFEE644B640AED6B02438B2F39D9665F&lt;br /&gt;
AFB&lt;br /&gt;
15-feb-2013 16:37:41 prepared no&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
SQL&amp;gt; SELECT LOCAL_TRAN_ID, IN_OUT,INTERFACE, DATABASE FROM DBA_2PC_NEIGHBORS;&lt;br /&gt;
&lt;br /&gt;
LOCAL_TRAN_ID IN_ I&lt;br /&gt;
---------------------- --- -&lt;br /&gt;
DATABASE&lt;br /&gt;
--------------------------------------------------------------------------------&lt;br /&gt;
8.19.321913 in N&lt;br /&gt;
jdbc_11&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
SQL&amp;gt; rollback force &amp;#039;8.19.321913&amp;#039;;&lt;br /&gt;
&lt;br /&gt;
Rollback complete.&lt;br /&gt;
&lt;br /&gt;
SQL&amp;gt; execute dbms_transaction.purge_lost_db_entry(&amp;#039;8.19.321913&amp;#039;);&lt;br /&gt;
&lt;br /&gt;
PL/SQL procedure successfully completed.&lt;br /&gt;
&lt;br /&gt;
SQL&amp;gt; commit;&lt;br /&gt;
&lt;br /&gt;
Commit complete.&lt;br /&gt;
&lt;br /&gt;
SQL&amp;gt; SELECT LOCAL_TRAN_ID, GLOBAL_TRAN_ID,to_char(FAIL_TIME,&amp;#039;dd-mon-yyyy HH24:MI:SS&amp;#039;),STATE, MIXED FROM DBA_2PC_PENDING;&lt;br /&gt;
&lt;br /&gt;
no rows selected&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Be aware that the support document 159377.1 does not speak of the rollback force. If you don’t execute that particular command it will not work.&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORACLE_BASE is getting set to the same value as ORACLE_HOME when using . oraenv===&lt;br /&gt;
Permissions problem. Make sure the user has &amp;#039;&amp;#039;&amp;#039;write&amp;#039;&amp;#039;&amp;#039; access to oraclehomeproperties.xml file!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ls -al $ORACLE_HOME/inventory/ContentsXML/oraclehomeproperties.xml&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Change permissions as appropriate.&lt;br /&gt;
A different approach which should give the same end result would be to grant the orabase executable the setuid bit.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
chmod u+s $ORACLE_HOME/bin/orabase&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This allows any user to set the environment as the orabase executable will be run with the permissions of its owner.&lt;br /&gt;
===Move table partitions to a different tablespace===&lt;br /&gt;
Are you getting errors due to partitions belonging to a different tablespace and you want to drop the current tablepace?&amp;lt;br /&amp;gt;&lt;br /&gt;
ORA-14404: partitioned table contains partitions in a different tablespace&amp;lt;br /&amp;gt;&lt;br /&gt;
====Find tables with partitions in more than one tablespace====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 2000 pages 50&lt;br /&gt;
col table_owner for a30&lt;br /&gt;
col table_name for a30&lt;br /&gt;
select table_owner&lt;br /&gt;
 ,     table_name&lt;br /&gt;
,      count(*)&lt;br /&gt;
from   dba_tab_partitions&lt;br /&gt;
where  table_owner != &amp;#039;SYS&amp;#039;&lt;br /&gt;
group  by table_owner&lt;br /&gt;
,      table_name&lt;br /&gt;
having count(*) &amp;gt; 1&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
See which tables have partitions across multiple tablespaces...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 1000 pages 100&lt;br /&gt;
col table_name for a50&lt;br /&gt;
select distinct b.table_owner||&amp;#039;.&amp;#039;||b.table_name table_name&lt;br /&gt;
,      a.tablespace_name ts1&lt;br /&gt;
,      b.tablespace_name ts2&lt;br /&gt;
from   (&lt;br /&gt;
       select distinct tablespace_name&lt;br /&gt;
       ,      table_name&lt;br /&gt;
       ,      partition_name&lt;br /&gt;
       from   dba_tab_partitions&lt;br /&gt;
       )                  a&lt;br /&gt;
,      dba_tab_partitions b&lt;br /&gt;
where  a.table_name       = b.table_name&lt;br /&gt;
and    a.tablespace_name != b.tablespace_name&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Generate statements to move the partitions from one tablespace to another...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select &amp;#039;alter table &amp;#039;||b.table_owner||&amp;#039;.&amp;#039;||b.table_name||&amp;#039; move partition &amp;#039;||b.partition_name||&amp;#039; tablespace &amp;amp;NEW_TABLESPACE;&amp;#039;&lt;br /&gt;
from   (&lt;br /&gt;
       select distinct table_name&lt;br /&gt;
       ,      partition_name&lt;br /&gt;
       from   dba_tab_partitions&lt;br /&gt;
       where  tablespace_name = &amp;#039;&amp;amp;&amp;amp;OLD_TABLESPACE&amp;#039;&lt;br /&gt;
       )                  a&lt;br /&gt;
,      dba_tab_partitions b&lt;br /&gt;
where  a.table_name       = b.table_name&lt;br /&gt;
and    b.tablespace_name != &amp;#039;&amp;amp;OLD_TABLESPACE&amp;#039;&lt;br /&gt;
/&lt;br /&gt;
undef OLD_TABLESPACE&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====What&amp;#039;s left hanging around?====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
col SEGMENT_TYPE for a20&lt;br /&gt;
col OWNER for a20&lt;br /&gt;
col SEGMENT_NAME for a40&lt;br /&gt;
col PARTITION_NAME for a15&lt;br /&gt;
col TABLESPACE_NAME for a30&lt;br /&gt;
select segment_type&lt;br /&gt;
,      owner&lt;br /&gt;
,      segment_name&lt;br /&gt;
,      partition_name&lt;br /&gt;
,      tablespace_name&lt;br /&gt;
from   dba_segments&lt;br /&gt;
where  tablespace_name in (&amp;#039;TS_THALER_IOT_OLD&amp;#039;,&amp;#039;TS_THALER_CU&amp;#039;,&amp;#039;TS_THALER_BACKUP&amp;#039;,&amp;#039;TS_THALER_PART_OLD&amp;#039;)&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
select table_owner&lt;br /&gt;
,      table_name&lt;br /&gt;
from   dba_indexes&lt;br /&gt;
where  index_name = &amp;#039;&amp;amp;index_name&amp;#039;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===What edition is my database (Standard, Enterprise, XE...)?===&lt;br /&gt;
Only works from 12c :-(&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select edition from sys.registry$ where cid=&amp;#039;CATPROC&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Is database a CDB with PDBs?===&lt;br /&gt;
Needs a bit of work. Won&amp;#039;t work pre-12c obviously and also not on Standby databases if they are in MOUNT mode&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
for db in $(ps -ef | grep [p]mon|awk -F_ &amp;#039;{print $NF}&amp;#039;)&lt;br /&gt;
do&lt;br /&gt;
    export ORACLE_SID=${db}&lt;br /&gt;
    ORAENV_ASK=NO&lt;br /&gt;
    . oraenv &amp;gt;/dev/null 2&amp;gt;&amp;amp;1&lt;br /&gt;
    sqlplus -s / as sysdba&amp;lt;&amp;lt;&amp;#039;EOSQL&amp;#039;&lt;br /&gt;
set head off newpa none&lt;br /&gt;
select name&lt;br /&gt;
,      (select count(*) from v$pdbs) npdbs&lt;br /&gt;
from   v$database&lt;br /&gt;
/&lt;br /&gt;
EOSQL&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
version 2&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
function is_db_cdb return boolean&lt;br /&gt;
is&lt;br /&gt;
    b_is_cdb        boolean := false;&lt;br /&gt;
    l_is_cdb        varchar2(3) := &amp;#039;NO&amp;#039;;&lt;br /&gt;
    e_col_not_found exception;&lt;br /&gt;
    pragma          exception_init(e_col_not_found, -904);&lt;br /&gt;
begin&lt;br /&gt;
    begin&lt;br /&gt;
        execute immediate &amp;#039;select cdb from v$database&amp;#039; &lt;br /&gt;
        into l_is_cdb;&lt;br /&gt;
    exception&lt;br /&gt;
        when e_col_not_found then l_is_cdb := &amp;#039;NO&amp;#039;;  -- ORA-00904&lt;br /&gt;
    end;&lt;br /&gt;
&lt;br /&gt;
    if (l_is_cdb = &amp;#039;YES&amp;#039;) then&lt;br /&gt;
        return TRUE;&lt;br /&gt;
    else&lt;br /&gt;
        return FALSE;  -- either not a cdb or pre-12.1 database&lt;br /&gt;
    end if;&lt;br /&gt;
&lt;br /&gt;
end is_db_cdb;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===List triggers in the database===&lt;br /&gt;
This query specifically lists after login triggers &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select obj.con_id&lt;br /&gt;
,      pdb.name&lt;br /&gt;
,      obj.owner&lt;br /&gt;
,      obj.object_name&lt;br /&gt;
,      to_char(obj.created, &amp;#039;DD/MM/YYYY HH24:MI:SS&amp;#039;)       created_str&lt;br /&gt;
,      to_char(obj.last_ddl_time, &amp;#039;DD/MM/YYYY HH24:MI:SS&amp;#039;) last_ddl_str&lt;br /&gt;
from   cdb_objects   obj&lt;br /&gt;
join   cdb_triggers trgs&lt;br /&gt;
       on (   obj.con_id      = trgs.con_id&lt;br /&gt;
          and obj.owner       = trgs.owner&lt;br /&gt;
          and obj.object_name = trgs.trigger_name&lt;br /&gt;
          )&lt;br /&gt;
join   v$pdbs pdb&lt;br /&gt;
       on ( obj.con_id  = pdb.con_id )&lt;br /&gt;
where  trgs.trigger_type     = &amp;#039;AFTER EVENT&amp;#039;&lt;br /&gt;
and    trgs.triggering_event like &amp;#039;LOGON%&amp;#039;&lt;br /&gt;
and    trgs.status           = &amp;#039;ENABLED&amp;#039;&lt;br /&gt;
order  by object_name&lt;br /&gt;
,      obj.last_ddl_time&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===List the pluggable databases (PDB) in a container database (CDB)===&lt;br /&gt;
The network_name column shows what you should find in tnsnames.ora for this db connection&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select name,network_name,pdb from v$services;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select * from v$pdbs;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Start and stop a pluggable database===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter pluggable database pdb1 open;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter pluggable database pdb1 close immediate;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Swith to a pluggable database===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter session set container=pdb1;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Reopen pluggable databases at container startup===&lt;br /&gt;
By default pluggable databases in a container remain in a MOUNT state when the container starts up.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select name, open_mode from v$pdbs where name = &amp;#039;PDB1&amp;#039;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
To modify this, open it and save its state&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter pluggable database pdb1 open;&lt;br /&gt;
alter pluggable database pdb1 save state;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
To see a log of issues with pluggable databases&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select * from pdb_plug_in_violations where type = &amp;#039;ERROR&amp;#039; and status != &amp;#039;RESOLVED&amp;#039; and name = &amp;#039;PDB1&amp;#039;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===What is the current container id in a cdb?===&lt;br /&gt;
CDB$ROOT is container id 1. User containers start from 2.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select sys_context(&amp;#039;USERENV&amp;#039;,&amp;#039;CON_ID&amp;#039;) from dual&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===What is the current container name in a cdb?===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select sys_context(&amp;#039;USERENV&amp;#039;,&amp;#039;CON_NAME&amp;#039;) from dual&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or just&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
show con_name&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Switching Between Containers===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SQL&amp;gt; show con_name&lt;br /&gt;
&lt;br /&gt;
CON_NAME&lt;br /&gt;
------------------------------&lt;br /&gt;
CDB$ROOT&lt;br /&gt;
&lt;br /&gt;
SQL&amp;gt; alter session set container=tstklok;&lt;br /&gt;
&lt;br /&gt;
Session altered.&lt;br /&gt;
&lt;br /&gt;
SQL&amp;gt;  show con_name&lt;br /&gt;
&lt;br /&gt;
CON_NAME&lt;br /&gt;
------------------------------&lt;br /&gt;
TSTKLOK&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Direct connection to pluggable database===&lt;br /&gt;
These must be made using a service (defined in tnsnames.ora). Each pluggable database automatically registers a service with the listener (v$services).&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sqlplus appuser/apppwd@tstklok&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or using ezconnect&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SQL&amp;gt; conn appuser/apppwd@//localhost:1521/tstklok&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===What platform is the database running on?===&lt;br /&gt;
Could be useful for handling line endings...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select platform_name from v$database&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
if instr(db_platform, &amp;#039;WINDOWS&amp;#039;) != 0 then&lt;br /&gt;
    crlf := CHR(13) || CHR(10);       -- Windows gets the \r and \n&lt;br /&gt;
else&lt;br /&gt;
    crlf := CHR (10);                 -- Just \n for the rest of the world&lt;br /&gt;
end if;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Is the database 32 or 64 bit?===&lt;br /&gt;
If the answer is 1,7,10,15,16 or 17, then it is 32bit, everything else should be 64bit.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select platform_id from v$database&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===What features is my database using?===&lt;br /&gt;
Before converting to Standard Edition, check the features here - some may be Enterprise specific.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
col name for a45&lt;br /&gt;
col description for a85&lt;br /&gt;
set lines 2000&lt;br /&gt;
select name&lt;br /&gt;
,      detected_usages&lt;br /&gt;
,      description&lt;br /&gt;
from   dba_feature_usage_statistics&lt;br /&gt;
where  1=1&lt;br /&gt;
and    currently_used = &amp;#039;TRUE&amp;#039;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===How many redo log switches per hour?===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 100&lt;br /&gt;
col &amp;quot;YYYYMMDD HH24&amp;quot; for a14&lt;br /&gt;
select to_char(first_time,&amp;#039;yyyymmdd hh24&amp;#039;) &amp;quot;YYYYMMDD HH24&amp;quot;&lt;br /&gt;
,      count(1)                            num_switches&lt;br /&gt;
from   v$log_history&lt;br /&gt;
group  by to_char(first_time,&amp;#039;yyyymmdd hh24&amp;#039;)&lt;br /&gt;
order  by 1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or a bit fancier version...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rem *********************************************************** &lt;br /&gt;
rem&lt;br /&gt;
rem	File: log_history.sql &lt;br /&gt;
rem	Description: Log switch rates from v$log_history &lt;br /&gt;
rem   &lt;br /&gt;
rem	From &amp;#039;Oracle Performance Survival Guide&amp;#039; by Guy Harrison&lt;br /&gt;
rem		Chapter 21 Page 637&lt;br /&gt;
rem		ISBN: 978-0137011957&lt;br /&gt;
rem		See www.guyharrison.net for further information&lt;br /&gt;
rem  &lt;br /&gt;
rem		This work is in the public domain NSA &lt;br /&gt;
rem   &lt;br /&gt;
rem&lt;br /&gt;
rem ********************************************************* &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
col min_minutes format 9999.99 &lt;br /&gt;
col max_minutes format 9999.99 &lt;br /&gt;
col avg_minutes format 9999.99 &lt;br /&gt;
set pagesize 1000&lt;br /&gt;
set lines 70&lt;br /&gt;
set echo on &lt;br /&gt;
&lt;br /&gt;
WITH log_history AS&lt;br /&gt;
       (SELECT thread#, first_time,&lt;br /&gt;
               LAG(first_time) OVER (ORDER BY thread#, sequence#)&lt;br /&gt;
                  last_first_time,&lt;br /&gt;
               (first_time&lt;br /&gt;
                - LAG(first_time) OVER (ORDER BY thread#, sequence#))&lt;br /&gt;
                    * 24* 60   last_log_time_minutes,&lt;br /&gt;
               LAG(thread#) OVER (ORDER BY thread#, sequence#)&lt;br /&gt;
                   last_thread#&lt;br /&gt;
        FROM v$log_history)&lt;br /&gt;
SELECT ROUND(MIN(last_log_time_minutes), 2) min_minutes,&lt;br /&gt;
       ROUND(MAX(last_log_time_minutes), 2) max_minutes,&lt;br /&gt;
       ROUND(AVG(last_log_time_minutes), 2) avg_minutes&lt;br /&gt;
FROM log_history&lt;br /&gt;
WHERE     last_first_time IS NOT NULL&lt;br /&gt;
      AND last_thread# = thread#&lt;br /&gt;
      AND first_time &amp;gt; SYSDATE - 1; &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Show redo log groups/members===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
col instance       for a8&lt;br /&gt;
col thread         for 999&lt;br /&gt;
col groupno        for 999&lt;br /&gt;
col member         for a35&lt;br /&gt;
col redo_file_type for a15&lt;br /&gt;
col log_status     for a10&lt;br /&gt;
col logsize_m      for 99999&lt;br /&gt;
col archived       for a12&lt;br /&gt;
&lt;br /&gt;
SELECT i.instance_name   instance&lt;br /&gt;
,      i.thread#         thread&lt;br /&gt;
,      f.group#          groupno&lt;br /&gt;
,      f.member          member&lt;br /&gt;
,      f.type            redo_file_type&lt;br /&gt;
,      l.status          log_status&lt;br /&gt;
,      l.bytes/1024/1024 logsize_m&lt;br /&gt;
,      l.archived        archived&lt;br /&gt;
FROM   gv$logfile  f&lt;br /&gt;
,      gv$log      l&lt;br /&gt;
,      gv$instance i&lt;br /&gt;
WHERE  1=1&lt;br /&gt;
and    f.group#  = l.group#&lt;br /&gt;
AND    l.thread# = i.thread#&lt;br /&gt;
AND    i.inst_id = f.inst_id&lt;br /&gt;
AND    f.inst_id = l.inst_id&lt;br /&gt;
ORDER  BY i.instance_name&lt;br /&gt;
,      f.group#&lt;br /&gt;
,      f.member;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Korn shell timestamp function===&lt;br /&gt;
Example usage: echo &amp;quot;`ts`: Checking backup status&amp;quot;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
function ts {&lt;br /&gt;
    date +&amp;#039;%d-%b-%Y %H:%M:%S&amp;#039;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Drop a database===&lt;br /&gt;
Dropping a database including backups should be considered criminal in a production environment!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sqlplus / as sysdba&lt;br /&gt;
startup force mount exclusive restrict&lt;br /&gt;
exit&lt;br /&gt;
rman target /&lt;br /&gt;
drop database including backups noprompt;&lt;br /&gt;
exit&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
RMAN&amp;gt; connect target sys/pass@test&lt;br /&gt;
connected to target database: test (dbid=123456789)&lt;br /&gt;
&lt;br /&gt;
RMAN&amp;gt; startup force mount&lt;br /&gt;
RMAN&amp;gt; sql &amp;#039;alter system enable restricted session&amp;#039;;&lt;br /&gt;
RMAN&amp;gt; drop database including backups noprompt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Use sub-select or in-line views to update base tables===&lt;br /&gt;
Inline views can be used to update base table data&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
update&lt;br /&gt;
    (&lt;br /&gt;
    select p.list_price&lt;br /&gt;
    from   products           p&lt;br /&gt;
    ,      product_categories pc&lt;br /&gt;
    where  1=1&lt;br /&gt;
    and    p.category_id    = pc.category_id&lt;br /&gt;
    and    pc.category_name = &amp;#039;CPU&amp;#039;&lt;br /&gt;
    )&lt;br /&gt;
set list_price = list_price * 1.15; &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Use sub-select or in-line views to delete base table data===&lt;br /&gt;
A different way to delete rows in base tables, using Inline views or subselect&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
delete&lt;br /&gt;
    (&lt;br /&gt;
    select p.list_price&lt;br /&gt;
    from   products           p&lt;br /&gt;
    ,      product_categories pc&lt;br /&gt;
    where  1=1&lt;br /&gt;
    and    p.category_id    = pc.category_id&lt;br /&gt;
    and    pc.category_name = &amp;#039;CPU&amp;#039;&lt;br /&gt;
    )&lt;br /&gt;
where list_price &amp;lt; 1000; &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Mass update of files using perl inline script===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
for server in `cat /home/tools/etc/oracle/oracle_servers`; do&lt;br /&gt;
    ssh $server “perl -p -i -e &amp;#039;s/T01/D01/&amp;#039; /home/tools/scripts/rman/inclexcl.lst”&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===How to use vi-style editing in SQL*Plus===&lt;br /&gt;
These instructions are for Redhat but other versions will be very similar&lt;br /&gt;
* Download rlwrap from [http://dl.fedoraproject.org/pub/epel/5/x86_64/repoview/rlwrap.html] or [http://dl.fedoraproject.org/pub/epel/6/x86_64/repoview/rlwrap.html]&lt;br /&gt;
* sudo yum install rlwrap&lt;br /&gt;
* build a dictionary file for autocomplete on pressing Tab&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
vi $HOME/sql.dict&lt;br /&gt;
select&lt;br /&gt;
from&lt;br /&gt;
dba_users&lt;br /&gt;
dba_data_files&lt;br /&gt;
dba_tablespaces&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alias sysdba=&amp;#039;rlwrap -f $HOME/sql.dict sqlplus / as sysdba&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or for general command use...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alias sqlplus=&amp;#039;rlwrap -D2 -ic sqlplus&amp;#039;&lt;br /&gt;
alias dgmgrl=&amp;#039;rlwrap -D2 -ic dgmgrl&amp;#039;&lt;br /&gt;
alias rman=&amp;#039;rlwrap -D2 -ic rman&amp;#039;&lt;br /&gt;
alias asmcmd=&amp;#039;rlwrap -D2 -ic asmcmd&amp;#039;&lt;br /&gt;
alias lsnrctl=&amp;#039;rlwrap -D2 -ic lsnrctl&amp;#039;&lt;br /&gt;
alias adrci=&amp;#039;rlwrap -D2 -ic adrci&amp;#039;&lt;br /&gt;
alias impdp=&amp;#039;rlwrap -D2 -ic impdp&amp;#039;&lt;br /&gt;
alias expdp=&amp;#039;rlwrap -D2 -ic expdp&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Execute an SQL statement on all databases on all servers for a customer===&lt;br /&gt;
Run from customer&amp;#039;s management server&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
./dosh -c &amp;quot;su - oracle -c &amp;#039;/home/tools/scripts/oracle/all_db_do -v \&amp;quot;select username, account_status, profile from dba_users order by 3;\&amp;quot;&amp;#039;&amp;quot; &amp;gt;user_status.lst&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SCRIPTS_DIR=/home/tools/scripts/oracle&lt;br /&gt;
$SCRIPTS_DIR/dosh -c &amp;quot;su - oraibm -c \&amp;quot;$SCRIPTS_DIR/all_db_do &amp;#039;alter user ops\\\$oraibm profile oracle_system_user;&amp;#039;\&amp;quot;&amp;quot;&lt;br /&gt;
$SCRIPTS_DIR/dosh2 -c &amp;quot;su - oraibm -c \&amp;quot;$SCRIPTS_DIR/all_db_do &amp;#039;alter user ops$oraibm profile oracle_system_user;&amp;#039;\&amp;quot;&amp;quot;&lt;br /&gt;
$SCRIPTS_DIR/dosh2 -c &amp;quot;su - oraibm -c \&amp;quot;$SCRIPTS_DIR/all_db_do &amp;#039;alter system set control_file_record_keep_time=31;&amp;#039;\&amp;quot;&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Where is the alert log/alertlog?===&lt;br /&gt;
Older systems&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select value from v$parameter where name=&amp;#039;background_dump_dest&amp;#039;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Newer systems&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select value from v$diag_info where name=&amp;#039;Diag Trace&amp;#039;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Grant normal users access to the alertlog table (sys.x$dbgalertext)===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
create view x$dbgalertext_v as select * from x$dbgalertext;&lt;br /&gt;
grant select on x$dbgalertext_v to &amp;amp;&amp;amp;grantee;&lt;br /&gt;
create or replace synonym &amp;amp;grantee..x$dbgalertext for sys.x$dbgalertext_v;&lt;br /&gt;
undef grantee&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Search alert log for ORA-00600 and ORA-07445 errors===&lt;br /&gt;
Scan the database table version of the alertlog for errors without reporting what was already found.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select indx, message_text from x$dbgalertext where message_text like &amp;#039;%ORA-00600%&amp;#039; or message_text like &amp;#039;%ORA-07445%&amp;#039; and indx &amp;gt; &amp;amp;last_queried_indx order by indx desc;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Simulating errors in alert log===&lt;br /&gt;
Sometimes you need to inject error messages into the alertlog to test your monitoring system. This generates the entries in the alertlog and in x$dbgalertext table.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
exec sys.dbms_system.ksdwrt(2, &amp;#039;ORA-07445: Testing this error code for Zenoss, do not investigate.&amp;#039;);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This additionally creates a trace file.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
exec sys.dbms_system.ksdwrt(3, &amp;#039;ORA-00600: Testing this error code for Zenoss, do not investigate.&amp;#039;);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===tail the database alert log===&lt;br /&gt;
If an ADR error is displayed, then ORACLE_SID is probably not set&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alias alertlog=&amp;#039;adrci exec=&amp;quot;set home diag/rdbms/$(echo $ORACLE_SID | tr A-Z a-z)/$ORACLE_SID; show alert -tail -f&amp;quot;&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===What is my WAN ip address?===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
curl -A &amp;quot;Mozilla/4.0&amp;quot; http://checkip.dyndns.org/ 2&amp;gt;/dev/null | perl -ne &amp;#039;print $1 if /Current IP Address: (\d+\.\d+\.\d+\.\d+)/&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
curl -A &amp;quot;Mozilla/4.0&amp;quot; http://myip.dnsdynamic.org/ 2&amp;gt;/dev/null&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Wait for child pid to finish in background and report its status===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# submit a process to the background&lt;br /&gt;
export_schema1.ksh &amp;amp;&lt;br /&gt;
bgpid=$!&lt;br /&gt;
&lt;br /&gt;
while (ps -ef | grep $bgpid | grep -v grep); do&lt;br /&gt;
    # still running...&lt;br /&gt;
    sleep 600&lt;br /&gt;
done&lt;br /&gt;
&lt;br /&gt;
# should be finished&lt;br /&gt;
wait $bgpid&lt;br /&gt;
bgstatus=$?&lt;br /&gt;
echo background process ended with status $bgstatus&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/usr/bin/ksh&lt;br /&gt;
# submit a few processes to the background&lt;br /&gt;
# wait for them all to finish&lt;br /&gt;
# concat their logfiles&lt;br /&gt;
&lt;br /&gt;
(./sleeper.sh;echo &amp;quot;sleeper 1 finished&amp;quot;)&amp;gt;sleeper1.log &amp;amp;&lt;br /&gt;
PIDLIST=&amp;quot;$PIDLIST $!&amp;quot;&lt;br /&gt;
echo &amp;quot;PIDLIST is $PIDLIST ...&amp;quot;&lt;br /&gt;
sleep 5&lt;br /&gt;
&lt;br /&gt;
(./sleeper.sh;echo &amp;quot;sleeper 2 finished&amp;quot;)&amp;gt;sleeper2.log &amp;amp;&lt;br /&gt;
PIDLIST=&amp;quot;$PIDLIST $!&amp;quot;&lt;br /&gt;
echo &amp;quot;PIDLIST is $PIDLIST ...&amp;quot;&lt;br /&gt;
sleep 5&lt;br /&gt;
&lt;br /&gt;
(./sleeper.sh;echo &amp;quot;sleeper 3 finished&amp;quot;)&amp;gt;sleeper3.log &amp;amp;&lt;br /&gt;
PIDLIST=&amp;quot;$PIDLIST $!&amp;quot;&lt;br /&gt;
echo &amp;quot;PIDLIST is $PIDLIST ...&amp;quot;&lt;br /&gt;
sleep 5&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;Now 15 seconds later, we have 3 pids: $PIDLIST&amp;quot;&lt;br /&gt;
for PID in $PIDLIST; do&lt;br /&gt;
    wait $PID&lt;br /&gt;
    echo &amp;quot;$PID exited with status $?&amp;quot;&lt;br /&gt;
done&lt;br /&gt;
&lt;br /&gt;
# all jobs should have ended, concat their logs&lt;br /&gt;
cat sleeper*log &amp;gt; sleepers.log&lt;br /&gt;
cat sleepers.log&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Real world example&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/usr/bin/ksh&lt;br /&gt;
# ==============================================================================&lt;br /&gt;
# Name         : export_JDBEOP1.ksh&lt;br /&gt;
# Description  : Run export in pieces for performance reasons&lt;br /&gt;
#&lt;br /&gt;
# Parameters   : &lt;br /&gt;
#&lt;br /&gt;
# Notes        : Also decide whether to exclude PDARC schema or not&lt;br /&gt;
#                depending on what day it is&lt;br /&gt;
#&lt;br /&gt;
#&lt;br /&gt;
# Modification History&lt;br /&gt;
# ====================&lt;br /&gt;
# When      Who               What&lt;br /&gt;
# ========= ================= ==================================================&lt;br /&gt;
# 15-OCT-13 Stuart Barkley    Created&lt;br /&gt;
# ==============================================================================&lt;br /&gt;
&lt;br /&gt;
STARTTIME=`date &amp;#039;+%Y%m%d%H%M%S&amp;#039;`&lt;br /&gt;
DAYNO=`date +%u`&lt;br /&gt;
PROGNAME=`basename $0`&lt;br /&gt;
SCRIPTS_DIR=/home/tools/scripts/oracle&lt;br /&gt;
DATA_DIR=/oracle/JDBEOP1/admin/change&lt;br /&gt;
EXPORT_DIR=/oracle/export/JDBEOP1&lt;br /&gt;
&lt;br /&gt;
# marker so we can find our files later&lt;br /&gt;
MARKERFILE=/tmp/start_$PROGNAME_$$&lt;br /&gt;
touch $MARKERFILE&lt;br /&gt;
&lt;br /&gt;
$SCRIPTS_DIR/expdp_PARFILE.ksh -s JDBEOP1 -u PRODDTA -p 4 -k 2 -f $DATA_DIR/JDBEOP1_PRODDTA.parfile &amp;amp;&lt;br /&gt;
PIDLIST=&amp;quot;$PIDLIST $!&amp;quot;&lt;br /&gt;
echo &amp;quot;PIDLIST is $PIDLIST ...&amp;quot;&lt;br /&gt;
&lt;br /&gt;
$SCRIPTS_DIR/expdp_PARFILE.ksh -s JDBEOP1 -u PRODCTL -p 2 -k 2 -f $DATA_DIR/JDBEOP1_PRODCTL.parfile &amp;amp;&lt;br /&gt;
PIDLIST=&amp;quot;$PIDLIST $!&amp;quot;&lt;br /&gt;
echo &amp;quot;PIDLIST is $PIDLIST ...&amp;quot;&lt;br /&gt;
&lt;br /&gt;
$SCRIPTS_DIR/expdp_PARFILE.ksh -s JDBEOP1 -u NOPRODNOPDARC -p 4 -k 2 -f $DATA_DIR/JDBEOP1_NOPROD_NOPDARC.parfile &amp;amp;&lt;br /&gt;
PIDLIST=&amp;quot;$PIDLIST $!&amp;quot;&lt;br /&gt;
echo &amp;quot;PIDLIST is $PIDLIST ...&amp;quot;&lt;br /&gt;
&lt;br /&gt;
if [[ $DAYNO -eq 1 ]]; then&lt;br /&gt;
    $SCRIPTS_DIR/expdp_PARFILE.ksh -s JDBEOP1 -u NOPROD -p 4 -k 2 -f $DATA_DIR/JDBEOP1_NOPROD.parfile &amp;amp;&lt;br /&gt;
    PIDLIST=&amp;quot;$PIDLIST $!&amp;quot;&lt;br /&gt;
    echo &amp;quot;PIDLIST is $PIDLIST ...&amp;quot;&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
# now sit and wait for the exports to finish&lt;br /&gt;
for PID in $PIDLIST; do&lt;br /&gt;
    echo &amp;quot;waiting for pid $PID to finish&amp;quot;&lt;br /&gt;
    wait $PID&lt;br /&gt;
    echo &amp;quot;$PID exited with status $?&amp;quot;&lt;br /&gt;
done&lt;br /&gt;
&lt;br /&gt;
# collect all log files up into one&lt;br /&gt;
cd $EXPORT_DIR&lt;br /&gt;
for i in `find . -name &amp;quot;expdp_JDBEOP1*log&amp;quot; -newer $MARKERFILE`; do&lt;br /&gt;
    cat $i &amp;gt; expdp_JDBEOP1_D_FULL_${STARTTIME}.log&lt;br /&gt;
done&lt;br /&gt;
&lt;br /&gt;
rm $MARKLERFILE&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Create private DB link for a user without knowing his password===&lt;br /&gt;
* Inspired by [http://oradbatips.blogspot.co.uk/2010/01/tip-84-create-private-db-link-for-user.html oradbatips.blogspot.co.uk]&lt;br /&gt;
It uses a clever package, dbms_sys_sql.&amp;lt;br /&amp;gt;&lt;br /&gt;
Also useful for executing anything on behalf of another user.&amp;lt;br /&amp;gt;&lt;br /&gt;
Here is an example on how to create private database link for a user.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
create or replace procedure link_creator ( p_owner varchar2, p_dblink_name varchar2, p_username varchar2, p_password varchar2, p_address varchar2 ) as&lt;br /&gt;
    uid number;&lt;br /&gt;
    sqltext varchar2(1000) := &amp;#039;create [public] database link [link_name] connect to [username] identified by [password] using &amp;#039;&amp;#039;[address]&amp;#039;&amp;#039;&amp;#039;;&lt;br /&gt;
    myint integer;&lt;br /&gt;
begin&lt;br /&gt;
    if upper(p_owner) = &amp;#039;PUBLIC&amp;#039; then&lt;br /&gt;
        sqltext := replace(sqltext, &amp;#039;[public]&amp;#039;, &amp;#039;public&amp;#039;);&lt;br /&gt;
    else&lt;br /&gt;
        sqltext := replace(sqltext, &amp;#039;[public]&amp;#039;, &amp;#039;&amp;#039;);&lt;br /&gt;
    end if;&lt;br /&gt;
    sqltext := replace(sqltext, &amp;#039;[linkname]&amp;#039;, p_dblink_name);&lt;br /&gt;
    sqltext := replace(sqltext, &amp;#039;[username]&amp;#039;, p_username);&lt;br /&gt;
    sqltext := replace(sqltext, &amp;#039;[password]&amp;#039;, p_password);&lt;br /&gt;
    sqltext := replace(sqltext, &amp;#039;[address]&amp;#039;, p_address);&lt;br /&gt;
&lt;br /&gt;
    select user_id&lt;br /&gt;
    into   uid&lt;br /&gt;
    from   dba_users&lt;br /&gt;
    where  username = decode(upper(p_owner), &amp;#039;PUBLIC&amp;#039;, &amp;#039;SYS&amp;#039;, p_owner)&lt;br /&gt;
    ;&lt;br /&gt;
    myint:=sys.dbms_sys_sql.open_cursor();&lt;br /&gt;
    sys.dbms_sys_sql.parse_as_user ( myint, sqltext, dbms_sql.native, uid );&lt;br /&gt;
    sys.dbms_sys_sql.close_cursor(myint);&lt;br /&gt;
end;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Here we can generate SQL to rebuild the links for future use. Note the password is no longer stored in this column.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set pages 1000&lt;br /&gt;
select &amp;#039;begin link_creator ( &amp;#039;&amp;#039;&amp;#039;|| u.name ||&amp;#039;&amp;#039;&amp;#039;,&amp;#039;&amp;#039;&amp;#039;|| l.name ||&amp;#039;&amp;#039;&amp;#039;,&amp;#039;&amp;#039;&amp;#039;|| l.userid ||&amp;#039;&amp;#039;&amp;#039;,&amp;#039;&amp;#039;&amp;#039;|| l.password ||&amp;#039;&amp;#039;&amp;#039;,&amp;#039;&amp;#039;&amp;#039;|| l.host ||&amp;#039;&amp;#039;&amp;#039;); end;&amp;#039;|| chr(10) ||&amp;#039;/&amp;#039; link_text&lt;br /&gt;
from   sys.link$ l&lt;br /&gt;
,      sys.user$ u&lt;br /&gt;
where  l.owner# = u.user#&lt;br /&gt;
;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Another method to create a db_link from sys on behalf of a user is to create a procedure under that users name that does the db link creation====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
grant create database link to &amp;amp;&amp;amp;user;&lt;br /&gt;
&lt;br /&gt;
create or replace procedure &amp;amp;user..create_db_link as&lt;br /&gt;
begin&lt;br /&gt;
    execute immediate &amp;#039;create database link &amp;amp;link_name connect to &amp;amp;user identified by &amp;amp;users_password using &amp;#039;&amp;#039;&amp;amp;tns_connect_identifier&amp;#039;&amp;#039;&amp;#039;;&lt;br /&gt;
end create_db_link;&lt;br /&gt;
&lt;br /&gt;
exec &amp;amp;user..create_db_link;&lt;br /&gt;
&lt;br /&gt;
revoke create database link from &amp;amp;user;&lt;br /&gt;
&lt;br /&gt;
drop procedure &amp;amp;user..create_db_link;&lt;br /&gt;
undef user&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Create a comma separated list of columns from a select statement===&lt;br /&gt;
Method 1:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SELECT parent_id,&lt;br /&gt;
       RTRIM(XMLAGG(XMLELEMENT(e,child_id || &amp;#039;,&amp;#039;)).EXTRACT(&amp;#039;//text()&amp;#039;),&amp;#039;,&amp;#039;) AS &amp;quot;Children&amp;quot;&lt;br /&gt;
FROM   parentChildTable&lt;br /&gt;
WHERE  parent_id = 0&lt;br /&gt;
GROUP  BY parent_id&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SELECT parent_id,&lt;br /&gt;
       LISTAGG(child_id, &amp;#039;,&amp;#039;) WITHIN GROUP (ORDER BY child_id) AS &amp;quot;Children&amp;quot;&lt;br /&gt;
  FROM parentChildTable&lt;br /&gt;
 WHERE parent_id = 0&lt;br /&gt;
 GROUP BY parent_id&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Method 2 (undocumented and cannot therefore be relied on to continue working in the same manner):&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SELECT wmsys.wm_concat(&amp;lt;column_name&amp;gt;)&lt;br /&gt;
FROM &amp;lt;table_name&amp;gt;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Start an instant one-line webserver in current directory===&lt;br /&gt;
Need to quickly share/copy a file or read an html file on Linux? Start a web server!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
python -m SimpleHTTPServer 8000&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
and point your browser to http://localhost:8000&amp;lt;br /&amp;gt;&lt;br /&gt;
or&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
while true; do nc -l -p 80 -q 1 &amp;lt; index.html; done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Get SQL*Plus to generate HTML===&lt;br /&gt;
* [http://docs.oracle.com/cd/E11882_01/server.112/e16604/ch_seven.htm#CHDCECJG official guide]&lt;br /&gt;
One way to do it... use -m(arkup) option to specify:&amp;lt;br /&amp;gt;&lt;br /&gt;
html on/off - specifies whether to output html output or not&lt;br /&gt;
head - specify your own customised head contents&amp;lt;br /&amp;gt;&lt;br /&gt;
spool off - as a part of the -m tag means do not print the default &amp;amp;lt;html&amp;amp;gt;, &amp;amp;lt;head&amp;amp;gt; and &amp;amp;lt;body&amp;amp;gt; tags&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sqlplus -m &amp;quot;html on head &amp;#039;&amp;lt;link rel=&amp;quot;stylesheet&amp;quot; href=&amp;quot;/dbamon_golden.css&amp;quot; type=&amp;quot;text/css&amp;quot; /&amp;gt;&amp;#039; spool off&amp;quot; / as sysdba&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sqlplus / as sysdba&lt;br /&gt;
set markup html on head &amp;#039;&amp;lt;link rel=&amp;quot;stylesheet&amp;quot; href=&amp;quot;/dbamon_golden.css&amp;quot; type=&amp;quot;text/css&amp;quot; /&amp;gt;&amp;#039; body &amp;quot;&amp;quot; table &amp;quot;&amp;quot; spool off&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
besides html and head, you can also specify:&amp;lt;br /&amp;gt;&lt;br /&gt;
body - specify your own customised body attributes&amp;lt;br /&amp;gt;&lt;br /&gt;
table - override the default table options&amp;lt;br /&amp;gt;&lt;br /&gt;
entmap - turn on or off the html replacement characters (&amp;amp;lt, &amp;amp;gt, etc...)&amp;lt;br /&amp;gt;&lt;br /&gt;
preformat - uses the &amp;amp;lt;pre&amp;amp;gt; tag to format output exactly as required&amp;lt;br /&amp;gt;&lt;br /&gt;
* another little gem...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
----------------------------------------&lt;br /&gt;
-- get the last SQL*Plus output in HTML&lt;br /&gt;
-- after Tanel Poder&lt;br /&gt;
----------------------------------------&lt;br /&gt;
&lt;br /&gt;
set termout off&lt;br /&gt;
&lt;br /&gt;
set markup HTML ON HEAD &amp;quot; -&lt;br /&gt;
 -&lt;br /&gt;
&amp;quot; -&lt;br /&gt;
BODY &amp;quot;&amp;quot; -&lt;br /&gt;
TABLE &amp;quot;border=&amp;#039;1&amp;#039; align=&amp;#039;center&amp;#039; summary=&amp;#039;Script output&amp;#039;&amp;quot; -&lt;br /&gt;
SPOOL ON ENTMAP ON PREFORMAT OFF&lt;br /&gt;
&lt;br /&gt;
spool myoutput.html&lt;br /&gt;
&lt;br /&gt;
l&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
spool off&lt;br /&gt;
set markup html off spool off&lt;br /&gt;
host firefox myoutput.html&lt;br /&gt;
set termout on&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===HTML SELECT - Trigger JavaScript ONCHANGE event even when the option is not changed===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;select onchange=&amp;quot;jsFunction()&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;option value=&amp;quot;&amp;quot; disabled selected style=&amp;quot;display:none;&amp;quot;&amp;gt;Label&amp;lt;/option&amp;gt;&lt;br /&gt;
  &amp;lt;option value=&amp;quot;1&amp;quot;&amp;gt;1&amp;lt;/option&amp;gt;&lt;br /&gt;
  &amp;lt;option value=&amp;quot;2&amp;quot;&amp;gt;2&amp;lt;/option&amp;gt;&lt;br /&gt;
  &amp;lt;option value=&amp;quot;3&amp;quot;&amp;gt;3&amp;lt;/option&amp;gt;&lt;br /&gt;
&amp;lt;/select&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Display horizontal bar graph in HTML table data cell===&lt;br /&gt;
Using Perl&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
print (&amp;#039;&amp;lt;td class=&amp;quot;left&amp;quot;&amp;gt;&amp;#039; .&lt;br /&gt;
            &amp;#039;&amp;lt;div style=&amp;quot;background-color:#8097BE;width:&amp;quot;&amp;#039;,$allocpercused  ,&amp;#039;%;&amp;quot; /&amp;gt;&amp;#039; .&lt;br /&gt;
            &amp;#039;&amp;lt;div style=&amp;quot;background-color:red;    width:&amp;quot;&amp;#039;,$automaxpercused,&amp;#039;%;&amp;quot; /&amp;gt;&amp;#039; .&lt;br /&gt;
            $tspace .&lt;br /&gt;
       &amp;#039;&amp;lt;/td&amp;gt;&amp;#039;&lt;br /&gt;
);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Depending on which way around the divs are, you get different interpretations&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
print (&amp;quot;&amp;lt;td class=\&amp;quot;left\&amp;quot;&amp;gt;&amp;quot; .&lt;br /&gt;
            &amp;quot;&amp;lt;div style=\&amp;quot;border-right:2px solid red; width:&amp;quot;,($automaxpercused&amp;gt;99)?(100):($automaxpercused),&amp;quot;%;\&amp;quot; /&amp;gt;&amp;quot; .&lt;br /&gt;
            &amp;quot;&amp;lt;div style=\&amp;quot;background-color:#8097BE;width:&amp;quot;,$allocpercused  ,&amp;quot;%;\&amp;quot; /&amp;gt;&amp;quot; .&lt;br /&gt;
            $tspace .&lt;br /&gt;
       &amp;quot;&amp;lt;/td&amp;gt;&amp;quot;&lt;br /&gt;
);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====References====&lt;br /&gt;
* [http://stackoverflow.com/questions/5324996/comma-separated-list-as-a-result-of-select-statement-in-oracle stackoverflow.com]&lt;br /&gt;
* [http://www.salvis.com/blog/?p=207 A whole page showing how to do it in all versions back to 7!]&lt;/div&gt;</summary>
		<author><name>Stuart</name></author>	</entry>

	<entry>
		<id>https://mailnest.com/dbawiki/index.php?title=Snippets&amp;diff=3396</id>
		<title>Snippets</title>
		<link rel="alternate" type="text/html" href="https://mailnest.com/dbawiki/index.php?title=Snippets&amp;diff=3396"/>
				<updated>2018-12-05T12:53:55Z</updated>
		
		<summary type="html">&lt;p&gt;Stuart: /* How to find ORACLE_HOME from pmon process for a SID if there is no entry in oratab */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;===Protecting an Apache Web Server directory with htaccess===&lt;br /&gt;
* [https://davidwalsh.name/password-protect-directory-using-htaccess https://davidwalsh.name/password-protect-directory-using-htaccess]&lt;br /&gt;
* [http://www.htaccesstools.com/articles/password-protection/ http://www.htaccesstools.com/articles/password-protection/]&lt;br /&gt;
Two files are needed.&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;The .htaccess Code&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
AuthType Basic&lt;br /&gt;
AuthName &amp;quot;restricted area&amp;quot;&lt;br /&gt;
AuthUserFile /home/davidwalsh/html/protect-me-dir/.htpasswd&lt;br /&gt;
require valid-user&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;The .htpasswd Code&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
davidwalsh:daWHfZrDLB88.&lt;br /&gt;
rodstewart:roFulYxC2.8ws&lt;br /&gt;
cssexpert:csmnmq.M8T5ho&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Protecting a lighttpd directory with htaccess===&lt;br /&gt;
Generate an MD5 hash with the tools above and paste into this file&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
vi /etc/lighttpd/.htpasswd&lt;br /&gt;
stuart:3#$567890#$56789056789&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Check modules.conf file to ensure mod_auth and mod_rewrite are enabled&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
vi /etc/lighttpd/modules.conf&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Alter the lighttpd.conf file to allow the authentication&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#auth directives&lt;br /&gt;
auth.backend = &amp;quot;htpasswd&amp;quot;&lt;br /&gt;
auth.backend.htpasswd.userfile = &amp;quot;/etc/lighttpd/.htpasswd&amp;quot;&lt;br /&gt;
auth.debug = 1&lt;br /&gt;
$HTTP[&amp;quot;url&amp;quot;] =~ &amp;quot;^/cgi-bin&amp;quot; {&lt;br /&gt;
        auth.require = ( &amp;quot;&amp;quot; =&amp;gt;&lt;br /&gt;
        (&lt;br /&gt;
        &amp;quot;method&amp;quot; =&amp;gt; &amp;quot;basic&amp;quot;,&lt;br /&gt;
        &amp;quot;realm&amp;quot; =&amp;gt; &amp;quot;DbaHawk access&amp;quot;,&lt;br /&gt;
        &amp;quot;require&amp;quot; =&amp;gt; &amp;quot;valid-user&amp;quot;&lt;br /&gt;
        ) )&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Restart the lighttpd server&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
systemctl stop lighttpd&lt;br /&gt;
systemctl start lighttpd&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
I tried it with htdigest but could not get it to protest the directory!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#auth.backend = &amp;quot;htdigest&amp;quot;&lt;br /&gt;
#auth.backend.htdigest.userfile = &amp;quot;/etc/lighttpd/lighttpd.user.htdigest&amp;quot;&lt;br /&gt;
#auth.require = (&lt;br /&gt;
#    &amp;quot;/var/www/cgi-bin/&amp;quot; =&amp;gt; (&lt;br /&gt;
#    &amp;quot;method&amp;quot;  =&amp;gt; &amp;quot;basic&amp;quot;,&lt;br /&gt;
#    &amp;quot;realm&amp;quot;   =&amp;gt; &amp;quot;DbaHawk access&amp;quot;,&lt;br /&gt;
#    &amp;quot;require&amp;quot; =&amp;gt; &amp;quot;valid-user&amp;quot;&lt;br /&gt;
#    ),&lt;br /&gt;
#)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Rename a datafile if the filename contains junk / unprintable characters===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter tablespace ts_thaler_data offline;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Oracle have a document that describes a few ways of doing it in [https://support.oracle.com/rs?type=doc&amp;amp;id=824473.1 Note 824473.1]&lt;br /&gt;
If the filename contains control characters and cannot be selected in the normal way, use ls -ali to find the node number and then use find with -inum to rename (or move) the file&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ls -baltri&lt;br /&gt;
total 47474984&lt;br /&gt;
12409 -rw-r-----    1 oracle   oinstall 1073750016 Sep 26 13:56 ts_thaler_data_02\1776.dbf&lt;br /&gt;
12350 -rw-r-----    1 oracle   oinstall 5242888192 Sep 26 13:56 ts_thaler_data_01.dbf&lt;br /&gt;
&lt;br /&gt;
find . -inum 12409 -exec mv {} ts_thaler_data_06.dbf \;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Work out what the database thinks the name is and rename it there too! AskTom has a discussion on it [https://asktom.oracle.com/pls/apex/asktom.search?tag=rename-datafile-with-dummy-characters-after-dbf here]&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select substr(name,i,1),ascii(substr(name,i,1)) from ( select name from v$datafile where file# = 9), ( select rownum i from dual connect by level &amp;lt;= 50);&lt;br /&gt;
SUBS ASCII(SUBSTR(NAME,I,1))&lt;br /&gt;
---- -----------------------&lt;br /&gt;
t                        116&lt;br /&gt;
s                        115&lt;br /&gt;
_                         95&lt;br /&gt;
t                        116&lt;br /&gt;
h                        104&lt;br /&gt;
a                         97&lt;br /&gt;
l                        108&lt;br /&gt;
e                        101&lt;br /&gt;
r                        114&lt;br /&gt;
_                         95&lt;br /&gt;
d                        100&lt;br /&gt;
a                         97&lt;br /&gt;
t                        116&lt;br /&gt;
a                         97&lt;br /&gt;
_                         95&lt;br /&gt;
0                         48&lt;br /&gt;
2                         50&lt;br /&gt;
                         127&lt;br /&gt;
2                         50&lt;br /&gt;
.                         46&lt;br /&gt;
d                        100&lt;br /&gt;
b                         98&lt;br /&gt;
f                        102&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
You can see there&amp;#039;s a 127 just before the .dbf... this crept in a the backspace key was not working correctly.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set serveroutput on&lt;br /&gt;
declare&lt;br /&gt;
   fname1 varchar2(100);&lt;br /&gt;
   fname2 varchar2(100);&lt;br /&gt;
begin&lt;br /&gt;
  select name into fname1 from v$datafile where file# = 9;&lt;br /&gt;
  fname2 := replace(fname1,chr(127));&lt;br /&gt;
  &lt;br /&gt;
  dbms_output.put_line(&amp;#039;alter database rename file &amp;#039;&amp;#039;&amp;#039;||fname1||&amp;#039;&amp;#039;&amp;#039; to &amp;#039;&amp;#039;&amp;#039;||fname2||&amp;#039;&amp;#039;&amp;#039;&amp;#039;);&lt;br /&gt;
  execute immediate &amp;#039;alter database rename file &amp;#039;&amp;#039;&amp;#039;||fname1||&amp;#039;&amp;#039;&amp;#039; to &amp;#039;&amp;#039;&amp;#039;||fname2||&amp;#039;&amp;#039;&amp;#039;&amp;#039;;&lt;br /&gt;
end;&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
alter tablespace ts_thaler_data_online;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Generate creation of directory names from dba_directories===&lt;br /&gt;
Before deleting or dropping directories in the database, use this script to generate the create statements&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select &amp;#039;create or replace directory &amp;#039;||directory_name||&amp;#039; as &amp;#039;&amp;#039;&amp;#039;||directory_path||&amp;#039;&amp;#039;&amp;#039;;&amp;#039; from dba_directories;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Check if current (dot) directory is in PATH variable===&lt;br /&gt;
Using bareword comparison to check PATH variable&amp;lt;pre&amp;gt;&lt;br /&gt;
if [[ :$PATH: == *:&amp;quot;.&amp;quot;:* ]] ; then&lt;br /&gt;
    echo &amp;quot;in path&amp;quot;&lt;br /&gt;
else&lt;br /&gt;
    echo &amp;quot;not in path&amp;quot;&lt;br /&gt;
fi&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===tail a logfile from within the script you are writing it to===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#&lt;br /&gt;
# display logfile in real time&lt;br /&gt;
#&lt;br /&gt;
( tail -0f ${LOGFILE} ) &amp;amp;&lt;br /&gt;
tailPID=$!&lt;br /&gt;
&lt;br /&gt;
trap &amp;quot;kill $tailPID&amp;quot; 0 1 2 3 5 9 15&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Dump package, procedure etc. from dba_source in a way that it can be used to recreate it===&lt;br /&gt;
From [https://asktom.oracle.com/pls/apex/f?p=100:11:0::::P11_QUESTION_ID:454220160386 Ask Tom]&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 1000 pages 1000 feedb off verif off&lt;br /&gt;
select decode( type||&amp;#039;-&amp;#039;||to_char(line,&amp;#039;fm99999&amp;#039;), &amp;#039;PACKAGE BODY-1&amp;#039;, &amp;#039;/&amp;#039;||chr(10), null) ||&lt;br /&gt;
       decode(line,1,&amp;#039;create or replace &amp;#039;, &amp;#039;&amp;#039; ) ||&lt;br /&gt;
       text text&lt;br /&gt;
from   dba_source&lt;br /&gt;
where  owner = upper(&amp;#039;&amp;amp;owner&amp;#039;)&lt;br /&gt;
and    name  = upper(&amp;#039;&amp;amp;object_to_show&amp;#039;)&lt;br /&gt;
order  by type&lt;br /&gt;
,      line&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===A trick to exit out of SQL*Plus (using divide by zero) depending on answer to a question===&lt;br /&gt;
This example is taken from ReviewLite.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
-- Settings for customized functionality&lt;br /&gt;
define SCRIPT_OO=_OPTIONS_ONLY -- collect only options information&lt;br /&gt;
define SCRIPT_OO=&amp;#039;&amp;#039;            -- collect all information [default behavior]&lt;br /&gt;
&lt;br /&gt;
define SCRIPT_TS=_TIME_STAMP   -- include timestamp in names of the output directory and output files: YYYY.MM.DD.HH24.MI.SS; script does not prompt for license agreement&lt;br /&gt;
define SCRIPT_TS=&amp;#039;\home\oracle\options&amp;#039;            -- standard names for output directory and output files; script prompts for license agreement [default behavior]&lt;br /&gt;
&lt;br /&gt;
-- PROMT FOR LICENSE AGREEMENT ACCEPTANCE&lt;br /&gt;
DEFINE LANSWER=N&lt;br /&gt;
SET TERMOUT ON&lt;br /&gt;
ACCEPT &amp;amp;SCRIPT_TS LANSWER FORMAT A1 PROMPT &amp;#039;Accept License Agreement? (y\n): &amp;#039;&lt;br /&gt;
&lt;br /&gt;
-- FORCE &amp;quot;divisor is equal to zero&amp;quot; AND SQLERROR EXIT IF NOT ACCEPTED&lt;br /&gt;
-- WILL ALSO CONTINUE IF SCRIPT_TS SUBSTITUTION VARIABLE IS NOT NULL&lt;br /&gt;
SET TERMOUT OFF&lt;br /&gt;
WHENEVER SQLERROR EXIT&lt;br /&gt;
select 1/decode(&amp;#039; &amp;amp;LANSWER&amp;#039;, &amp;#039;Y&amp;#039;, null, &amp;#039;y&amp;#039;, null, decode(&amp;#039; &amp;amp;SCRIPT_TS&amp;#039;, null, 0, null)) as &amp;quot; &amp;quot; from dual;&lt;br /&gt;
WHENEVER SQLERROR CONTINUE&lt;br /&gt;
SET TERMOUT ON&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===How to uninstall optional components such as OWB, APEX, EM, OLAP, OWM from an Oracle database===&lt;br /&gt;
* [http://fast-dba.blogspot.be/2014/04/how-to-remove-unwanted-components-from.html fast-dba.blogspot.be]&lt;br /&gt;
&lt;br /&gt;
===Find unique indexes / primary index / key columns in a table===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
col owner       for a12&lt;br /&gt;
col table_name  for a32&lt;br /&gt;
col column_name for a32&lt;br /&gt;
col position    for 99&lt;br /&gt;
col status      for a10&lt;br /&gt;
set lines 1000 pages 100&lt;br /&gt;
&lt;br /&gt;
SELECT cons.owner&lt;br /&gt;
,      cols.table_name&lt;br /&gt;
,      cols.column_name&lt;br /&gt;
,      cols.position&lt;br /&gt;
,      cons.status&lt;br /&gt;
FROM   all_constraints  cons&lt;br /&gt;
,      all_cons_columns cols&lt;br /&gt;
WHERE  1=1&lt;br /&gt;
and    cols.owner           = &amp;#039;&amp;amp;TABLE_OWNER&amp;#039;&lt;br /&gt;
and    cols.table_name      = &amp;#039;&amp;amp;TABLE_NAME&amp;#039;&lt;br /&gt;
AND    cons.constraint_type = &amp;#039;P&amp;#039;&lt;br /&gt;
AND    cons.constraint_name = cols.constraint_name&lt;br /&gt;
AND    cons.owner           = cols.owner&lt;br /&gt;
ORDER  BY cols.table_name&lt;br /&gt;
,      cols.position&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Display the oracle instances running on the local server===&lt;br /&gt;
sed could be shorter but this one works cross-platform&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alias oenv=&amp;#039;ps -ef|grep pmon|grep -v grep|awk -F_ &amp;quot;{print \$NF}&amp;quot;|sort|uniq|sed -e &amp;quot;:a&amp;quot; -e &amp;quot;N&amp;quot; -e &amp;quot;\$!ba&amp;quot; -e &amp;quot;s/\n/ /g&amp;quot;&amp;#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Display which databases are scheduled for backup in cron===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
for i in `ps -ef | grep [o]ra_pmon | awk -F_ &amp;#039;{print $NF}&amp;#039;`; do&lt;br /&gt;
    crontab -l | grep $i | grep backup_export | awk &amp;#039;{print $2&amp;quot;:&amp;quot;$1&amp;quot; - &amp;quot;$17}&amp;#039;&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Trace SQL statements using autotrace and explain plan===&lt;br /&gt;
If the plustrace (plustrc.sql) role has been granted, explaining sql statements (without running the statement) is as easy as&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter session set sql_trace=true;&lt;br /&gt;
set autotrace traceonly explain&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Write to a trace log from PL/SQL===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
dbms_system.ksdwrt(1,&amp;#039;message sent to a trace file&amp;#039;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Invisible / hidden / virtual columns===&lt;br /&gt;
Article showing how to dump blocks also.&amp;lt;br /&amp;gt;&lt;br /&gt;
[https://www.oracle.com/technetwork/articles/database/invisible-columns-odb12c-2331522.html Tips and Tricks: Invisible Columns in Oracle Database 12c by Alex Zaballa, Oracle Ace and Daniel Da Meda (OCM)]&lt;br /&gt;
&lt;br /&gt;
===Write to the alert log from PL/SQL===&lt;br /&gt;
* [https://www.databasejournal.com/features/oracle/article.php/3386731/Inserting-Custom-Messages-in-Oracle-AlertTrace-files.htm Inserting Custom Messages in Oracle Alert/Trace files]&lt;br /&gt;
Writes to trace file&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
dbms_system.ksdwrt(1,&amp;#039;message sent to trace log&amp;#039;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Writes to the alertlog&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
dbms_system.ksdwrt(2,&amp;#039;message sent to the alertlog&amp;#039;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Writes to the alertlog and trace file&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
dbms_system.ksdwrt(3,&amp;#039;message sent to trace file and the alert log&amp;#039;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Also available, KSDIND, KSDDDT and KSDFLS&lt;br /&gt;
&lt;br /&gt;
===Do distributed SQL transactions exist?===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select * from dba_2pc_pending;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
if yes, and to commit them...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select local_tran_id from dba_2pc_pending;&lt;br /&gt;
exec dbms_transaction.purge_lost_db_entry(&amp;#039;&amp;#039;);&lt;br /&gt;
commit;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Setup optional parameters and default values in an SQL*Plus script===&lt;br /&gt;
Some forgotten SQL*Plus tricks from the good old days and some new ones...&lt;br /&gt;
* [http://www.orafaq.com/wiki/SQL*Plus_FAQ#What_is_the_difference_between_.21_and_HOST.3F orafaq.com]&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set termout off&lt;br /&gt;
col p1 new_value 1&lt;br /&gt;
col p2 new_value 2&lt;br /&gt;
col p3 new_value 3&lt;br /&gt;
select null p1, null p2, null p3 from dual where  1=2;&lt;br /&gt;
select nvl(&amp;#039;&amp;amp;1&amp;#039;,&amp;#039;def1&amp;#039;) p1, nvl(&amp;#039;&amp;amp;2&amp;#039;,&amp;#039;def2&amp;#039;) p2, nvl(&amp;#039;&amp;amp;3&amp;#039;,&amp;#039;def3&amp;#039;) p3 from dual;&lt;br /&gt;
set termout on&lt;br /&gt;
prompt 1=&amp;quot;&amp;amp;1&amp;quot;&lt;br /&gt;
prompt 2=&amp;quot;&amp;amp;2&amp;quot;&lt;br /&gt;
prompt 3=&amp;quot;&amp;amp;3&amp;quot;&lt;br /&gt;
undef 1&lt;br /&gt;
undef 2&lt;br /&gt;
undef 3&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Display / show users with sysdba &amp;amp; sysoper privileges===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select * from v$pwfile_users;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Show path names of data files using instr===&lt;br /&gt;
Use to find the pathnames of all the filesystems/directories in which a database is housed.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select distinct substr(name,1,(instr(name,&amp;#039;/&amp;#039;,-1,1)-1)) path_name from v$datafile&lt;br /&gt;
union&lt;br /&gt;
select distinct substr(name,1,(instr(name,&amp;#039;/&amp;#039;,-1,1)-1)) path_name from v$tempfile&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Does a dataguard standby exist for this database?===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SELECT SUBSTR(value,INSTR(value,&amp;#039;=&amp;#039;,INSTR(UPPER(value),&amp;#039;SERVICE&amp;#039;))+1)&lt;br /&gt;
FROM   v$parameter&lt;br /&gt;
WHERE  name LIKE &amp;#039;log_archive_dest%&amp;#039; AND UPPER(value) LIKE &amp;#039;SERVICE%&amp;#039;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
gives something like this if found...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SUBSTR(VALUE,INSTR(VALUE,&amp;#039;=&amp;#039;,INSTR(UPPER(VALUE),&amp;#039;SERVICE&amp;#039;))+1)&lt;br /&gt;
--------------------------------------------------------------------------------&lt;br /&gt;
&amp;quot;jdbeop1_standby&amp;quot;, LGWR ASYNC NOAFFIRM delay=0 optional compression=disable m&lt;br /&gt;
ax_failure=0 max_connections=1 reopen=300 db_unique_name=&amp;quot;jdbeop1_standby&amp;quot; ne&lt;br /&gt;
t_timeout=60, valid_for=(all_logfiles,primary_role)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===List values for all init parameters in v$parameter (including default values for undocumented (hidden) parameters===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select i.ksppinm||&amp;#039;;&amp;#039;||sv.ksppstvl&lt;br /&gt;
from   x$ksppi  i&lt;br /&gt;
,      x$ksppsv sv&lt;br /&gt;
where  i.indx = sv.indx&lt;br /&gt;
order  by i.ksppinm;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Log file reports pipe errors===&lt;br /&gt;
Found these in the log file&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
solax005:root[/opt/IBM/ITM/logs]# tail solax005_or_RMANV11_col.out&lt;br /&gt;
CIR1880E (024955) Open Probe pipe error 2. Pipe=/opt/IBM/ITM/tmp/solax005_or_RMANV11/prb_RMANV11_kor_solax005_30024832_5346_pipe&lt;br /&gt;
CIR1880E (030938) Open Probe pipe error 2. Pipe=/opt/IBM/ITM/tmp/solax005_or_RMANV11/prb_RMANV11_kor_solax005_30030830_5406_pipe&lt;br /&gt;
CIR1880E (031923) Open Probe pipe error 2. Pipe=/opt/IBM/ITM/tmp/solax005_or_RMANV11/prb_RMANV11_kor_solax005_30031832_5434_pipe&lt;br /&gt;
CIR1880E (033934) Open Probe pipe error 2. Pipe=/opt/IBM/ITM/tmp/solax005_or_RMANV11/prb_RMANV11_kor_solax005_30033831_5495_pipe&lt;br /&gt;
CIR1880E (034918) Open Probe pipe error 2. Pipe=/opt/IBM/ITM/tmp/solax005_or_RMANV11/prb_RMANV11_kor_solax005_30034833_5521_pipe&lt;br /&gt;
CIR1880E (041927) Open Probe pipe error 2. Pipe=/opt/IBM/ITM/tmp/solax005_or_RMANV11/prb_RMANV11_kor_solax005_30041835_5610_pipe&lt;br /&gt;
CIR1880E (042931) Open Probe pipe error 2. Pipe=/opt/IBM/ITM/tmp/solax005_or_RMANV11/prb_RMANV11_kor_solax005_30042832_5642_pipe&lt;br /&gt;
CIR1880E (045928) Open Probe pipe error 2. Pipe=/opt/IBM/ITM/tmp/solax005_or_RMANV11/prb_RMANV11_kor_solax005_30045835_5730_pipe&lt;br /&gt;
CIR1880E (052927) Open Probe pipe error 2. Pipe=/opt/IBM/ITM/tmp/solax005_or_RMANV11/prb_RMANV11_kor_solax005_30052838_5819_pipe&lt;br /&gt;
CIR1880E (090929) Open Probe pipe error 2. Pipe=/opt/IBM/ITM/tmp/solax005_or_RMANV11/prb_RMANV11_kor_solax005_30090833_6487_pipe&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This could be due to a timeout on the pipe.&amp;lt;br /&amp;gt;&lt;br /&gt;
Increase parameters and restart agent. Add following lines to or.config:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
export COLL_WAIT_TIMEOUT=&amp;#039;200&amp;#039;&lt;br /&gt;
export WAIT_TIMEOUT=&amp;#039;200&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Find the most recent archived SCN number===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
col next_change# for 999999999999999&lt;br /&gt;
set numwidth 15&lt;br /&gt;
&lt;br /&gt;
select max(next_change#)&lt;br /&gt;
from   v$archived_log&lt;br /&gt;
where  (thread#, next_change#) in ( select thread#, max(next_change#)&lt;br /&gt;
                                    from   v$archived_log&lt;br /&gt;
                                    where  archived     = &amp;#039;YES&amp;#039;&lt;br /&gt;
                                    and    status       = &amp;#039;A&amp;#039;&lt;br /&gt;
                                    and    resetlogs_id = ( select resetlogs_id&lt;br /&gt;
                                                            from   v$database_incarnation&lt;br /&gt;
                                                            where  status = &amp;#039;CURRENT&amp;#039;&lt;br /&gt;
                                                          )&lt;br /&gt;
                                    group by thread#&lt;br /&gt;
                                  )&lt;br /&gt;
and    status = &amp;#039;A&amp;#039;&lt;br /&gt;
and    resetlogs_id = ( select resetlogs_id&lt;br /&gt;
                        from   v$database_incarnation&lt;br /&gt;
                        where  status = &amp;#039;CURRENT&amp;#039;&lt;br /&gt;
                      )&lt;br /&gt;
order  by next_change# asc;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Monitoring says database inactive===&lt;br /&gt;
* Check the candle user password has not expired in the database.&lt;br /&gt;
* There may be a clue in the log file. Check /opt/IBM/ITM/logs/`hostname`_or_${SID}_col.out&lt;br /&gt;
* Check limits for itmora account in /etc/security/limits. Should be same as oracle user.&lt;br /&gt;
* Check the config file. We had this issue when a new ORACLE_HOME was installed but the cfg file still had the old one in it.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
export ITM_HOME=/opt/IBM/ITM&lt;br /&gt;
cd $ITM_HOME/config&lt;br /&gt;
vi solax005_or_SRV2R.cfg&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#  IBM Tivoli Monitoring for Databases: Oracle Agent&lt;br /&gt;
#  Configuration file: solax005_or_SRV2R.cfg&lt;br /&gt;
#  Written by CandleDBconfig version: 1.4 on 31Jul13 13:39:41&lt;br /&gt;
&lt;br /&gt;
#  Note: this is a Korn-shell script that is &amp;quot;sourced&amp;quot; to create the&lt;br /&gt;
#  environment for a Monitoring Agent for Oracle.  It can be used to create&lt;br /&gt;
#  the environment to run the IBM-supplied database grant scripts.&lt;br /&gt;
&lt;br /&gt;
#  IBM does not recommend that you modify this file, but you can change the&lt;br /&gt;
#  data values or add new exported variables as long as the file is a valid ksh&lt;br /&gt;
#  script that executes with zero return code, and values remain quoted with &amp;quot;&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
#  Following environment variables are set for convenience in running grants.&lt;br /&gt;
   export ORACLE_SID=&amp;quot;SRV2R&amp;quot;&lt;br /&gt;
   export ORACLE_HOME=&amp;quot;/oracle/product/11.2.0.1&amp;quot;&lt;br /&gt;
   # IY92195  COLL_DISABLE_CURSORS setting&lt;br /&gt;
   export TNS_ADMIN=&amp;quot;/oracle/product/11.2.0.1/network/admin&amp;quot;&lt;br /&gt;
&lt;br /&gt;
#  Following variables are set for the setup scripts&lt;br /&gt;
   db_sid=&amp;quot;SRV2R&amp;quot;&lt;br /&gt;
   db_home=&amp;quot;/oracle/product/11.2.0.1&amp;quot;&lt;br /&gt;
   db_initfilename=&amp;quot;&amp;quot;&lt;br /&gt;
   db_login=&amp;quot;tivoli&amp;quot;&lt;br /&gt;
   db_password=&amp;quot;795D8822BC49477323815CD21C1E66E966E48EEE19C6A98056224D649B0FE316E6A11DC3F4E9BB5E226B65A8&amp;quot;&lt;br /&gt;
   db_ver=&amp;quot;11.x&amp;quot;&lt;br /&gt;
   db_type=&amp;quot;kor&amp;quot;&lt;br /&gt;
   db_tns=&amp;quot;/oracle/product/11.2.0.1/network/admin&amp;quot;&lt;br /&gt;
   db_extparms=&amp;quot;&amp;quot;&lt;br /&gt;
   db_hostname=&amp;quot;solax005&amp;quot;&lt;br /&gt;
   db_reason=&amp;quot;AIX_ps_ceww&amp;quot;&lt;br /&gt;
   db_pipedir=&amp;quot;&amp;quot;&lt;br /&gt;
   db_installstatus=&amp;quot;CONFIGSUCCESS&amp;quot;&lt;br /&gt;
&lt;br /&gt;
#  User-defined environment variables&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Solution:&amp;lt;br /&amp;gt;&lt;br /&gt;
* Change all occurrences of 11.2.0.1 to 11.2.0.3&lt;br /&gt;
* Restart agent&lt;br /&gt;
&lt;br /&gt;
===Alerts due to password expiring (or being changed in the database but not in ITM!)===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cd $ITM_HOME/logs&lt;br /&gt;
ls -altr | grep WM820T&lt;br /&gt;
tail -20 solax005_or_WM820T_col.out&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
CGN1521E (161614) Interval collection failed for cursor KORHART2&lt;br /&gt;
RCD0110S (161614) Invalid Oracle logon id (tivoli) or password given&lt;br /&gt;
 Please contact DBA to correct userid or password&lt;br /&gt;
CGN1521E (161614) Interval collection failed for cursor KORHART4&lt;br /&gt;
CGN1525E (161614) One or more interval cursors failed&lt;br /&gt;
RCD0110S (161714) Invalid Oracle logon id (tivoli) or password given&lt;br /&gt;
 Please contact DBA to correct userid or password&lt;br /&gt;
CGN1521E (161714) Interval collection failed for cursor KORHART2&lt;br /&gt;
RCD0110S (161714) Invalid Oracle logon id (tivoli) or password given&lt;br /&gt;
 Please contact DBA to correct userid or password&lt;br /&gt;
CGN1521E (161714) Interval collection failed for cursor KORHART4&lt;br /&gt;
CGN1525E (161714) One or more interval cursors failed&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Solution:&amp;lt;br /&amp;gt;&lt;br /&gt;
* Run agent reconfigure to setup the new password for the candle user (tivoli)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
export ITM_HOME=/opt/IBM/ITM&lt;br /&gt;
$ITM_HOME/bin/itmcmd config -A or&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Restart agent&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
export ITM_HOME=/opt/IBM/ITM&lt;br /&gt;
$ITM_HOME/smitools/scripts/StartAgent.sh restart or -o WM820T&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Many agents started with root user instead of itmora===&lt;br /&gt;
This can happen if the server is rebooted before the agents have been added to the itmora list using kdyedit / kciedit&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
export CANDLEHOME=/opt/IBM/ITM&lt;br /&gt;
export ITM_HOME=/opt/IBM/ITM&lt;br /&gt;
$ITM_HOME/smitools/scripts/kdyedit list&lt;br /&gt;
Type Runas      Inst                &lt;br /&gt;
or   root       AGPDEV              &lt;br /&gt;
or   root       BO1R                &lt;br /&gt;
or   root       DEV3                &lt;br /&gt;
or   root       EMREP               &lt;br /&gt;
or   root       ICR                 &lt;br /&gt;
or   itmora     MAPDEV              &lt;br /&gt;
or   itmora     MAPER               &lt;br /&gt;
or   itmora     PED                 &lt;br /&gt;
or   itmora     PER                 &lt;br /&gt;
or   itmora     RMANV11             &lt;br /&gt;
or   itmora     SRV2R               &lt;br /&gt;
or   itmora     WM820Q              &lt;br /&gt;
or   itmora     WM820T              &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ITM_HOME/smitools/scripts/kciedit list&lt;br /&gt;
Type Runas      Inst                &lt;br /&gt;
or   root       AGPDEV              &lt;br /&gt;
or   root       BO1R                &lt;br /&gt;
or   root       DEV3                &lt;br /&gt;
or   root       EMREP               &lt;br /&gt;
or   root       ICR                 &lt;br /&gt;
or   itmora     MAPDEV              &lt;br /&gt;
or   itmora     MAPER               &lt;br /&gt;
or   itmora     PED                 &lt;br /&gt;
or   itmora     PER                 &lt;br /&gt;
or   itmora     RMANV11             &lt;br /&gt;
or   itmora     SRV2R               &lt;br /&gt;
or   itmora     WM820Q              &lt;br /&gt;
or   itmora     WM820T              &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Solution: Add these instances to the itmora list&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
./kdyedit -t or -i AGPDEV -r itmora add&lt;br /&gt;
./kciedit -t or -i AGPDEV -r itmora add&lt;br /&gt;
...&lt;br /&gt;
./kdyedit -t or -i ICR -r itmora add&lt;br /&gt;
./kciedit -t or -i ICR -r itmora add&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ITM_HOME/smitools/scripts/kciedit list&lt;br /&gt;
Type Runas      Inst                &lt;br /&gt;
or   itmora     AGPDEV              &lt;br /&gt;
or   itmora     BO1R                &lt;br /&gt;
or   itmora     DEV3                &lt;br /&gt;
or   itmora     EMREP               &lt;br /&gt;
or   itmora     ICR                 &lt;br /&gt;
or   itmora     MAPDEV              &lt;br /&gt;
or   itmora     MAPER               &lt;br /&gt;
or   itmora     PED                 &lt;br /&gt;
or   itmora     PER                 &lt;br /&gt;
or   itmora     RMANV11             &lt;br /&gt;
or   itmora     SRV2R               &lt;br /&gt;
or   itmora     WM820Q              &lt;br /&gt;
or   itmora     WM820T              &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Kill any agents still running as root&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ps -ef |grep kor | grep root&lt;br /&gt;
kill -9 &amp;lt;process id&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Because these agents were owned by root, there will be permissions issues when trying to restart the agents with itmora so these need to be fixed before restarting the agents.&amp;lt;br /&amp;gt;&lt;br /&gt;
The simplest way of doing this is to run lockdown.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
export CANDLEHOME=/opt/IBM/ITM&lt;br /&gt;
$CANDLEHOME/smitools/scripts/lockdown.sh&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===See which processes are causing paging===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
svmon -Pt20 | perl -e &amp;#039;while(&amp;lt;&amp;gt;){print if($.==2||$&amp;amp;&amp;amp;&amp;amp;!$s++);$.=0 if(/^-+$/)}&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===How to return several variables from SQL*Plus back to Korn shell script===&lt;br /&gt;
Return multiple columns/elements from Oracle to shell script at the same time&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sqlplus -s sys/${SYS_PASSWORD}@${SID} as sysdba&amp;lt;&amp;lt;EOSQL | read SPACE_AFTER_INSTALL TOTAL_SPACE_AVAILABLE&lt;br /&gt;
set numwid 15 headi off newpa none feedb off&lt;br /&gt;
select sign(${SPACE_USED} + ${SPACE_AVAILABLE} - ${DATABASE_SIZE}), trim(${SPACE_USED} + ${SPACE_AVAILABLE})&lt;br /&gt;
from dual&lt;br /&gt;
/&lt;br /&gt;
EOSQL&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===How to get a shell environment variable from the operating system into the SQL or PL/SQL environment===&lt;br /&gt;
This has been bugging me for years. Something you would think simple... what is ORACLE_HOME? I know it&amp;#039;s a question mark at the SQL prompt but how to get it&amp;#039;s O/S value?&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
declare&lt;br /&gt;
    var1 varchar2(200);&lt;br /&gt;
begin&lt;br /&gt;
    dbms_system.get_env (&amp;#039;ORACLE_HOME&amp;#039;, var1);&lt;br /&gt;
    dbms_output.put_line (&amp;#039;ORACLE_HOME: &amp;#039;||var1);&lt;br /&gt;
end;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or in SQL*Plus&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
variable var1 varchar2(200);&lt;br /&gt;
exec dbms_system.get_env (&amp;#039;ORACLE_HOME&amp;#039;, :var1);&lt;br /&gt;
select :var1 from dual;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
That got me thinking... if this just gets stuff from the environment, it can fetch any exported variable?!?!&amp;lt;br /&amp;gt;&lt;br /&gt;
From the shell:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
export running_sids=`ps -ef | grep [p]mon | awk -F_ &amp;#039;{print $NF}&amp;#039;`&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
and now in SQL*Plus:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
variable sids varchar2(240);&lt;br /&gt;
exec dbms_system.get_env (&amp;#039;running_sids&amp;#039;, :sids);&lt;br /&gt;
select :sids from dual;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Wow!&lt;br /&gt;
&lt;br /&gt;
===How long/wide can a database name/sid be?===&lt;br /&gt;
Depends on where you look but taking the minimum here as &amp;quot;safe&amp;quot;, it should still be limited to 8 characters...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
col table_name for a30&lt;br /&gt;
col data_type  for a12&lt;br /&gt;
select table_name, data_type, data_length from dba_tab_columns where column_name = &amp;#039;DB_NAME&amp;#039;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This is 11gR2&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
TABLE_NAME                     DATA_TYPE    DATA_LENGTH&lt;br /&gt;
------------------------------ ------------ -----------&lt;br /&gt;
LOGMNRG_DICTIONARY$            VARCHAR2               9&lt;br /&gt;
SYS_FBA_CONTEXT_AUD            VARCHAR2             256&lt;br /&gt;
V_$LOGMNR_DICTIONARY           VARCHAR2               9&lt;br /&gt;
V_$LOGMNR_LOGS                 VARCHAR2               8&lt;br /&gt;
GV_$LOGMNR_DICTIONARY          VARCHAR2               9&lt;br /&gt;
GV_$LOGMNR_LOGS                VARCHAR2               8&lt;br /&gt;
V_$LOGMNR_LOGFILE              VARCHAR2               8&lt;br /&gt;
V_$LOGMNR_SESSION              VARCHAR2             128&lt;br /&gt;
GV_$LOGMNR_LOGFILE             VARCHAR2               8&lt;br /&gt;
GV_$LOGMNR_SESSION             VARCHAR2             128&lt;br /&gt;
GV_$ASM_CLIENT                 VARCHAR2               8&lt;br /&gt;
V_$ASM_CLIENT                  VARCHAR2               8&lt;br /&gt;
GV_$IOS_CLIENT                 VARCHAR2              64&lt;br /&gt;
V_$IOS_CLIENT                  VARCHAR2              64&lt;br /&gt;
DBA_PDB_HISTORY                VARCHAR2             128&lt;br /&gt;
CDB_PDB_HISTORY                VARCHAR2             128&lt;br /&gt;
SSCR_CAP$                      VARCHAR2            4000&lt;br /&gt;
SSCR_RES$                      VARCHAR2            4000&lt;br /&gt;
DBA_SSCR_CAPTURE               VARCHAR2            4000&lt;br /&gt;
CDB_SSCR_CAPTURE               VARCHAR2            4000&lt;br /&gt;
DBA_SSCR_RESTORE               VARCHAR2            4000&lt;br /&gt;
CDB_SSCR_RESTORE               VARCHAR2            4000&lt;br /&gt;
WRM$_DATABASE_INSTANCE         VARCHAR2               9&lt;br /&gt;
INT$DBA_HIST_DATABASE_INSTANCE VARCHAR2               9&lt;br /&gt;
DBA_HIST_DATABASE_INSTANCE     VARCHAR2               9&lt;br /&gt;
CDB_HIST_DATABASE_INSTANCE     VARCHAR2               9&lt;br /&gt;
LOGMNR_DICTIONARY$             VARCHAR2               9&lt;br /&gt;
&lt;br /&gt;
27 rows selected.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===What character set (characterset) was the database built with?===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
col name  for a40&lt;br /&gt;
col value for a60&lt;br /&gt;
select * from nls_database_parameters;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
col name   for a40&lt;br /&gt;
col value$ for a60&lt;br /&gt;
select name,value$ from props$ where name = &amp;#039;NLS_CHARACTERSET&amp;#039;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===How to get value of ORACLE_HOME from shell environment into SQL*Plus or PL/SQL===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
var orahome varchar2(2000);&lt;br /&gt;
exec dbms_system.get_env(&amp;#039;ORACLE_HOME&amp;#039;, :orahome) ;&lt;br /&gt;
print orahome&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===How to find ORACLE_HOME from pmon process for a SID if there is no entry in oratab===&lt;br /&gt;
If database is created without dbca (datafile and controlfile copy), no entry will be automatically made in /etc/oratab.&amp;lt;br /&amp;gt;&lt;br /&gt;
So the problem is that you need to find out which of the ORACLE_HOMEs is being used by the running instances.&lt;br /&gt;
* Solaris, Linux&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ ps -ef | grep [p]mon&lt;br /&gt;
  oracle 10848     1   0 00:21:20 ?           2:11 ora_pmon_JDBEOP1&lt;br /&gt;
$ pwdx 10848&lt;br /&gt;
10848:  /oracle/JDBEOP1/product/11204/dbs&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* AIX&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ ps -ef | grep [p]mon&lt;br /&gt;
  oracle 13893878        1   0   Aug 12      -  7:53 ora_pmon_GOAQ1&lt;br /&gt;
$ ls -al /proc/13893878/cwd&lt;br /&gt;
lr-x------    2 oracle   dba               0 Aug 12 13:37  cwd -&amp;gt; /data/opt/app/product/11.2.0.4/db_1/dbs/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or&amp;lt;br /&amp;gt;&lt;br /&gt;
This command (ps eww) gives lots of information about the given process (pmon in this case). Tells you where the instance was started, whether it was started from SQL*Plus or RMAN, the http_proxy and loads more useful bits!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ps -ef | grep [p]mon | awk &amp;#039;{print $2}&amp;#039; | xargs -I {} ps eww {} | awk &amp;#039;{print $1 &amp;quot; &amp;quot; $5 &amp;quot; &amp;quot; $6 &amp;quot; &amp;quot; $0}&amp;#039; | sed &amp;#039;s/\(S*\) \(S*\) .*ORACLE_HOME/\1 \2/g&amp;#039; | cut -f1,2,3 -d&amp;quot; &amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Escape the underscore(_) or percent(%) character in an SQL statement===&lt;br /&gt;
The underscore matches any single character so to return data containing an underscore means having to use an escape character.&amp;lt;br /&amp;gt;&lt;br /&gt;
Here I use the backslash(\) so it is easy for Unix people to understand the mechanism.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select username from dba_users where username like &amp;#039;ENDUR\_DEV%&amp;#039; escape &amp;#039;\&amp;#039;; &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Validate, analyse and rebuild indexes===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set feedback off&lt;br /&gt;
set linesize 132&lt;br /&gt;
set serveroutput on&lt;br /&gt;
set trimspool on&lt;br /&gt;
&lt;br /&gt;
declare&lt;br /&gt;
    LOCKED exception;&lt;br /&gt;
    pragma exception_init (LOCKED, -54);&lt;br /&gt;
&lt;br /&gt;
    dbase         char(8);&lt;br /&gt;
    dbuser        varchar2(30);&lt;br /&gt;
    index_name    varchar(30);&lt;br /&gt;
    free_text     varchar2(50);&lt;br /&gt;
    pctused       number;&lt;br /&gt;
    height    number;&lt;br /&gt;
    index_mb      number;&lt;br /&gt;
    analyze_sql   varchar2(100);&lt;br /&gt;
    pct_used_sql  varchar2(150);&lt;br /&gt;
    rebuild_sql   varchar2(150);&lt;br /&gt;
 &lt;br /&gt;
    cursor c1 is&lt;br /&gt;
    select segment_name, bytes&lt;br /&gt;
    from   user_segments&lt;br /&gt;
    where  segment_type = &amp;#039;INDEX&amp;#039;&lt;br /&gt;
    and    segment_name like &amp;#039;DW%&amp;#039;&lt;br /&gt;
    and    segment_name not like &amp;#039;BIN%&amp;#039;&lt;br /&gt;
    and    bytes/1024   &amp;gt;= 1024&lt;br /&gt;
    order  by 2;&lt;br /&gt;
&lt;br /&gt;
-- validate the index&lt;br /&gt;
procedure validate_index (v_ind in varchar2) is&lt;br /&gt;
begin&lt;br /&gt;
    analyze_sql := &amp;#039;analyze index &amp;#039;||v_ind||&amp;#039; validate structure&amp;#039;;&lt;br /&gt;
    begin&lt;br /&gt;
        execute immediate analyze_sql;&lt;br /&gt;
    exception&lt;br /&gt;
    when LOCKED then&lt;br /&gt;
        dbms_output.put_line (v_ind||&amp;#039; locked - skipping&amp;#039;);&lt;br /&gt;
        pctused := 100;&lt;br /&gt;
        return;&lt;br /&gt;
    when others then&lt;br /&gt;
        dbms_output.put_line (analyze_sql);&lt;br /&gt;
        raise;&lt;br /&gt;
    end;&lt;br /&gt;
&lt;br /&gt;
    pct_used_sql := &amp;#039;select pct_used, round(blocks*8192/(1024*1024)), height from index_stats where name = &amp;#039;&amp;#039;&amp;#039;||v_ind||&amp;#039;&amp;#039;&amp;#039;&amp;#039;;&lt;br /&gt;
    execute immediate pct_used_sql into pctused, index_mb, height;&lt;br /&gt;
    if pctused is null then&lt;br /&gt;
        pctused := 0;&lt;br /&gt;
    end if;&lt;br /&gt;
    dbms_output.put_line (rpad(v_ind,35)||&amp;#039; (pct used &amp;#039;||pctused||&amp;#039;% size &amp;#039;||index_mb||&amp;#039;Mb height &amp;#039; || height ||&amp;#039;)&amp;#039;);&lt;br /&gt;
end validate_index;&lt;br /&gt;
 &lt;br /&gt;
-- execute SQL and trace if errors&lt;br /&gt;
procedure run_sql (v_sql in varchar2) is&lt;br /&gt;
begin&lt;br /&gt;
    execute immediate v_sql;&lt;br /&gt;
exception&lt;br /&gt;
when others then&lt;br /&gt;
    dbms_output.put_line (v_sql);&lt;br /&gt;
    raise;&lt;br /&gt;
end run_sql;&lt;br /&gt;
 &lt;br /&gt;
--&lt;br /&gt;
-- Script starts here&lt;br /&gt;
--&lt;br /&gt;
begin&lt;br /&gt;
    dbms_output.enable(1000000);&lt;br /&gt;
    -- Set up database name and schema&lt;br /&gt;
    -- select name into dbase  from v$database;&lt;br /&gt;
    select user into dbuser from dual;&lt;br /&gt;
    dbms_output.put_line(&amp;#039;============================================================================= *&amp;#039;);&lt;br /&gt;
    -- dbms_output.put_line(&amp;#039;* Indexes rebuild report for &amp;#039;||dbuser||&amp;#039; on &amp;#039;||dbase);&lt;br /&gt;
    dbms_output.put_line(&amp;#039;============================================================================= *&amp;#039;);&lt;br /&gt;
&lt;br /&gt;
    -- Loop around Indexes&lt;br /&gt;
    for x in c1 loop&lt;br /&gt;
        index_name := x.segment_name;&lt;br /&gt;
        validate_index (index_name );&lt;br /&gt;
        if pctused &amp;lt; 81 then&lt;br /&gt;
            if x.bytes/1024/1024 &amp;lt; 100 then&lt;br /&gt;
                rebuild_sql := &amp;#039;alter index &amp;#039;||x.segment_name||&amp;#039; rebuild online&amp;#039;;&lt;br /&gt;
            else&lt;br /&gt;
                rebuild_sql := &amp;#039;alter index &amp;#039;||x.segment_name||&amp;#039; coalesce&amp;#039;;&lt;br /&gt;
            end if;&lt;br /&gt;
            dbms_output.put_line (rebuild_sql);&lt;br /&gt;
            run_sql (rebuild_sql);&lt;br /&gt;
            validate_index (index_name);&lt;br /&gt;
        end if;&lt;br /&gt;
    end loop;&lt;br /&gt;
end;&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
set feed on&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Rebuild unusable indexes on a table===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select &amp;#039;alter index &amp;#039;||owner||&amp;#039;.&amp;#039;||index_name||&amp;#039; rebuild;&amp;#039;&lt;br /&gt;
from   dba_indexes&lt;br /&gt;
where  1=1&lt;br /&gt;
and    status    != &amp;#039;VALID&amp;#039;&lt;br /&gt;
and    owner     not in (&amp;#039;SYS&amp;#039;,&amp;#039;SYSTEM&amp;#039;)&lt;br /&gt;
--and    owner      = &amp;#039;WM822PP&amp;#039;&lt;br /&gt;
--and    table_name = &amp;#039;WF_PLANTS&amp;#039;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Pull the latest cfengine changes now instead of waiting for scheduled time===&lt;br /&gt;
For one host&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/opt/cfengine/bin/cfagent -ID dbaTime&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
On all hosts at the same time&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/home/ibmtools/scripts/oracle/dosh -c &amp;quot;/opt/cfengine/bin/cfagent -ID dbaTime&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Check status of datafiles without dba_data_files or v$datafile===&lt;br /&gt;
If the database is in mount mode, most tables are unavailable. This query uses the x$ (c based) tables and are always available&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set linesize 200;&lt;br /&gt;
set pagesize 100;&lt;br /&gt;
col inst_id for 9999999 heading &amp;#039;Instance #&amp;#039;&lt;br /&gt;
col file_nr for 9999999 heading &amp;#039;File #&amp;#039;&lt;br /&gt;
col file_name for A50 heading &amp;#039;File name&amp;#039;&lt;br /&gt;
col checkpoint_change_nr for 99999999999999 heading &amp;#039;Checkpoint #&amp;#039;&lt;br /&gt;
col checkpoint_change_time for A20 heading &amp;#039;Checkpoint time&amp;#039;&lt;br /&gt;
col last_change_nr for 99999999999999 heading &amp;#039;Last change #&amp;#039;&lt;br /&gt;
SELECT&lt;br /&gt;
      fe.inst_id,&lt;br /&gt;
      fe.fenum file_nr,&lt;br /&gt;
      fn.fnnam file_name,&lt;br /&gt;
      TO_NUMBER (fe.fecps) checkpoint_change_nr,&lt;br /&gt;
      fe.fecpt checkpoint_change_time,&lt;br /&gt;
      fe.fests last_change_nr,&lt;br /&gt;
      DECODE (&lt;br /&gt;
              fe.fetsn,&lt;br /&gt;
              0, DECODE (BITAND (fe.festa, 2), 0, &amp;#039;SYSOFF&amp;#039;, &amp;#039;SYSTEM&amp;#039;),&lt;br /&gt;
              DECODE (BITAND (fe.festa, 18),&lt;br /&gt;
                      0, &amp;#039;OFFLINE&amp;#039;,&lt;br /&gt;
                      2, &amp;#039;ONLINE&amp;#039;,&lt;br /&gt;
                      &amp;#039;RECOVER&amp;#039;)&lt;br /&gt;
      ) status&lt;br /&gt;
FROM x$kccfe fe,&lt;br /&gt;
     x$kccfn fn&lt;br /&gt;
WHERE    (   (fe.fepax != 65535 AND fe.fepax != 0 )&lt;br /&gt;
          OR (fe.fepax = 65535 OR fe.fepax = 0)&lt;br /&gt;
         )&lt;br /&gt;
     AND fn.fnfno = fe.fenum&lt;br /&gt;
     AND fe.fefnh = fn.fnnum&lt;br /&gt;
     AND fe.fedup != 0&lt;br /&gt;
     AND fn.fntyp = 4&lt;br /&gt;
     AND fn.fnnam IS NOT NULL&lt;br /&gt;
     AND BITAND (fn.fnflg, 4) != 4&lt;br /&gt;
ORDER BY fe.fenum&lt;br /&gt;
;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Check highest allocated extent in datafile (likely slow when having many extents)===&lt;br /&gt;
* Script to Detect Tablespace Fragmentation ( Doc ID 1020182.6 )&lt;br /&gt;
* How to shrink or reduce the datafile size by finding the high water mark (HWM) ( Doc ID 1600774.1 )&lt;br /&gt;
* How to find Objects Fragmented below High Water Mark ( Doc ID 337651.1 )&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
column file_name format a50;&lt;br /&gt;
column tablespace_name format a15;&lt;br /&gt;
column highwater format 9999999999;&lt;br /&gt;
set pagesize 9999&lt;br /&gt;
&lt;br /&gt;
select a.tablespace_name&lt;br /&gt;
,a.file_name&lt;br /&gt;
,(b.maximum+c.blocks-1)*d.db_block_size highwater&lt;br /&gt;
from dba_data_files a&lt;br /&gt;
,(select file_id,max(block_id) maximum&lt;br /&gt;
from dba_extents&lt;br /&gt;
group by file_id) b&lt;br /&gt;
,dba_extents c&lt;br /&gt;
,(select value db_block_size&lt;br /&gt;
from v$parameter&lt;br /&gt;
where name=&amp;#039;db_block_size&amp;#039;) d&lt;br /&gt;
where a.file_id = b.file_id&lt;br /&gt;
and c.file_id = b.file_id&lt;br /&gt;
and c.block_id = b.maximum&lt;br /&gt;
order by a.tablespace_name,a.file_name&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Runup to this was...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set markup html on spool on&lt;br /&gt;
spool db_info.html&lt;br /&gt;
set echo on&lt;br /&gt;
select * from dba_tablespaces where tablespace_name = &amp;#039;&amp;amp;&amp;amp;tablespace_name&amp;#039;;&lt;br /&gt;
select * from dba_data_files where tablespace_name = &amp;#039;&amp;amp;tablespace_name&amp;#039;;&lt;br /&gt;
select * from (select * from dba_extents where tablespace_name = &amp;#039;&amp;amp;tablespace_name&amp;#039; order by block_id desc) where rownum &amp;lt;301;&lt;br /&gt;
spool off&lt;br /&gt;
set markup html off&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select owner, segment_type, count(*) from dba_segments where tablesapce_name=&amp;#039;&amp;amp;tablespace_name&amp;#039; group by owner, segment_type;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
begin&lt;br /&gt;
for ii in (select owner, segment_name, segment_type from dba_segments where tablespace_name = &amp;#039;&amp;amp;tablespace_name&amp;#039; and segment_type like &amp;#039;TABLE%&amp;#039; and segment_name not like &amp;#039;%DATAPUMP%&amp;#039;)&lt;br /&gt;
loop&lt;br /&gt;
if ii.segment_type=&amp;#039;TABLE&amp;#039; then&lt;br /&gt;
begin&lt;br /&gt;
execute immediate(&amp;#039;alter table &amp;#039;||ii.owner||&amp;#039;.&amp;#039;||ii.segment_name||&amp;#039; enable row movement&amp;#039;);&lt;br /&gt;
execute immediate(&amp;#039;alter table &amp;#039;||ii.owner||&amp;#039;.&amp;#039;||ii.segment_name||&amp;#039; shrink space cascade&amp;#039;);&lt;br /&gt;
exception when others then&lt;br /&gt;
dbms_output.put_line(&amp;#039;FAILED 1: alter table &amp;#039;||ii.owner||&amp;#039;.&amp;#039;||ii.segment_name||&amp;#039; shrink space cascade : &amp;#039;||SQLERRM);&lt;br /&gt;
end;&lt;br /&gt;
end if;&lt;br /&gt;
end loop;&lt;br /&gt;
end;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Procedure to shrink space in tables and indexes===&lt;br /&gt;
* [http://www.oracle-wiki.net/startdocsreallifeshrinkexample Using the Oracle Shrink Command] - lots of good stuff at this site&lt;br /&gt;
Written by [https://asktom.oracle.com/pls/apex/f%3Fp%3D100:11:0::::P11_QUESTION_ID:5645095700346948864 Tom Kyte]&amp;lt;br /&amp;gt;&lt;br /&gt;
Depending on the Oracle version, this procedure may or may not work! It does not include the compact clause (neither does it re-analyse to prove it worked).&amp;lt;br /&amp;gt;&lt;br /&gt;
[http://www.oracle-wiki.net/startdocsreallifeshrinkexample Here] is a worked example that shows the complete process - oracle-wiki.net&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
create or replace procedure shrink_all&lt;br /&gt;
as&lt;br /&gt;
    l_sql        varchar2(4000);&lt;br /&gt;
    l_sql2       varchar2(4000);&lt;br /&gt;
    row_movement exception;&lt;br /&gt;
    pragma       exception_init( row_movement, -10636 );&lt;br /&gt;
begin&lt;br /&gt;
    for x in (select table_name&lt;br /&gt;
              ,      owner&lt;br /&gt;
              from   t&lt;br /&gt;
              where  sgm_space_management = &amp;#039;AUTO&amp;#039;)&lt;br /&gt;
    loop&lt;br /&gt;
        l_sql := &amp;#039;alter table &amp;quot;&amp;#039; || x.owner || &amp;#039;&amp;quot;.&amp;quot;&amp;#039; || x.table_name || &amp;#039;&amp;quot; shrink space&amp;#039;;&lt;br /&gt;
        dbms_output.put_line( l_sql );&lt;br /&gt;
&lt;br /&gt;
        begin&lt;br /&gt;
            execute immediate l_sql;&lt;br /&gt;
        exception&lt;br /&gt;
        when row_movement&lt;br /&gt;
        then&lt;br /&gt;
            dbms_output.put_line( &amp;#039;failed due to row movement...&amp;#039; );&lt;br /&gt;
            l_sql2 := &amp;#039;alter table &amp;quot;&amp;#039; || x.owner || &amp;#039;&amp;quot;.&amp;quot;&amp;#039; || x.table_name || &amp;#039;&amp;quot; enable row movement&amp;#039;;&lt;br /&gt;
            dbms_output.put_line( l_sql2 );&lt;br /&gt;
            execute immediate l_sql2;&lt;br /&gt;
            dbms_output.put_line( l_sql );&lt;br /&gt;
            execute immediate l_sql;&lt;br /&gt;
        end;&lt;br /&gt;
&lt;br /&gt;
        for y in (select owner&lt;br /&gt;
                  ,      index_name&lt;br /&gt;
                  from   dba_indexes&lt;br /&gt;
                  where  table_owner = x.owner&lt;br /&gt;
                  and    table_name  = x.table_name )&lt;br /&gt;
        loop&lt;br /&gt;
            l_sql := &amp;#039;alter index &amp;quot;&amp;#039; || y.owner || &amp;#039;&amp;quot;.&amp;quot;&amp;#039; || y.index_name || &amp;#039;&amp;quot; shrink space&amp;#039;;&lt;br /&gt;
            dbms_output.put_line( l_sql );&lt;br /&gt;
            execute immediate l_sql;&lt;br /&gt;
        end loop;&lt;br /&gt;
&lt;br /&gt;
    end loop;&lt;br /&gt;
end;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===How to delete/kill a distributed transaction===&lt;br /&gt;
From [http://www.pouwiel.com/?p=2204 pouwiel.com]&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SQL&amp;gt; SELECT LOCAL_TRAN_ID, GLOBAL_TRAN_ID,to_char(FAIL_TIME,&amp;#039;dd-mon-yyyy HH24:MI:SS&amp;#039;),STATE, MIXED FROM DBA_2PC_PENDING;&lt;br /&gt;
&lt;br /&gt;
LOCAL_TRAN_ID&lt;br /&gt;
----------------------&lt;br /&gt;
GLOBAL_TRAN_ID&lt;br /&gt;
--------------------------------------------------------------------------------&lt;br /&gt;
TO_CHAR(FAIL_TIME,&amp;#039;D STATE MIX&lt;br /&gt;
-------------------- ---------------- ---&lt;br /&gt;
8.19.321913&lt;br /&gt;
1463898948.0000013CDE8005110000000179F68840A089FFFEE644B640AED6B02438B2F39D9665F&lt;br /&gt;
AFB&lt;br /&gt;
15-feb-2013 16:37:41 prepared no&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
SQL&amp;gt; SELECT LOCAL_TRAN_ID, IN_OUT,INTERFACE, DATABASE FROM DBA_2PC_NEIGHBORS;&lt;br /&gt;
&lt;br /&gt;
LOCAL_TRAN_ID IN_ I&lt;br /&gt;
---------------------- --- -&lt;br /&gt;
DATABASE&lt;br /&gt;
--------------------------------------------------------------------------------&lt;br /&gt;
8.19.321913 in N&lt;br /&gt;
jdbc_11&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
SQL&amp;gt; rollback force &amp;#039;8.19.321913&amp;#039;;&lt;br /&gt;
&lt;br /&gt;
Rollback complete.&lt;br /&gt;
&lt;br /&gt;
SQL&amp;gt; execute dbms_transaction.purge_lost_db_entry(&amp;#039;8.19.321913&amp;#039;);&lt;br /&gt;
&lt;br /&gt;
PL/SQL procedure successfully completed.&lt;br /&gt;
&lt;br /&gt;
SQL&amp;gt; commit;&lt;br /&gt;
&lt;br /&gt;
Commit complete.&lt;br /&gt;
&lt;br /&gt;
SQL&amp;gt; SELECT LOCAL_TRAN_ID, GLOBAL_TRAN_ID,to_char(FAIL_TIME,&amp;#039;dd-mon-yyyy HH24:MI:SS&amp;#039;),STATE, MIXED FROM DBA_2PC_PENDING;&lt;br /&gt;
&lt;br /&gt;
no rows selected&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Be aware that the support document 159377.1 does not speak of the rollback force. If you don’t execute that particular command it will not work.&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORACLE_BASE is getting set to the same value as ORACLE_HOME when using . oraenv===&lt;br /&gt;
Permissions problem. Make sure the user has &amp;#039;&amp;#039;&amp;#039;write&amp;#039;&amp;#039;&amp;#039; access to oraclehomeproperties.xml file!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ls -al $ORACLE_HOME/inventory/ContentsXML/oraclehomeproperties.xml&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Change permissions as appropriate.&lt;br /&gt;
A different approach which should give the same end result would be to grant the orabase executable the setuid bit.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
chmod u+s $ORACLE_HOME/bin/orabase&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This allows any user to set the environment as the orabase executable will be run with the permissions of its owner.&lt;br /&gt;
===Move table partitions to a different tablespace===&lt;br /&gt;
Are you getting errors due to partitions belonging to a different tablespace and you want to drop the current tablepace?&amp;lt;br /&amp;gt;&lt;br /&gt;
ORA-14404: partitioned table contains partitions in a different tablespace&amp;lt;br /&amp;gt;&lt;br /&gt;
====Find tables with partitions in more than one tablespace====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 2000 pages 50&lt;br /&gt;
col table_owner for a30&lt;br /&gt;
col table_name for a30&lt;br /&gt;
select table_owner&lt;br /&gt;
 ,     table_name&lt;br /&gt;
,      count(*)&lt;br /&gt;
from   dba_tab_partitions&lt;br /&gt;
where  table_owner != &amp;#039;SYS&amp;#039;&lt;br /&gt;
group  by table_owner&lt;br /&gt;
,      table_name&lt;br /&gt;
having count(*) &amp;gt; 1&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
See which tables have partitions across multiple tablespaces...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 1000 pages 100&lt;br /&gt;
col table_name for a50&lt;br /&gt;
select distinct b.table_owner||&amp;#039;.&amp;#039;||b.table_name table_name&lt;br /&gt;
,      a.tablespace_name ts1&lt;br /&gt;
,      b.tablespace_name ts2&lt;br /&gt;
from   (&lt;br /&gt;
       select distinct tablespace_name&lt;br /&gt;
       ,      table_name&lt;br /&gt;
       ,      partition_name&lt;br /&gt;
       from   dba_tab_partitions&lt;br /&gt;
       )                  a&lt;br /&gt;
,      dba_tab_partitions b&lt;br /&gt;
where  a.table_name       = b.table_name&lt;br /&gt;
and    a.tablespace_name != b.tablespace_name&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Generate statements to move the partitions from one tablespace to another...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select &amp;#039;alter table &amp;#039;||b.table_owner||&amp;#039;.&amp;#039;||b.table_name||&amp;#039; move partition &amp;#039;||b.partition_name||&amp;#039; tablespace &amp;amp;NEW_TABLESPACE;&amp;#039;&lt;br /&gt;
from   (&lt;br /&gt;
       select distinct table_name&lt;br /&gt;
       ,      partition_name&lt;br /&gt;
       from   dba_tab_partitions&lt;br /&gt;
       where  tablespace_name = &amp;#039;&amp;amp;&amp;amp;OLD_TABLESPACE&amp;#039;&lt;br /&gt;
       )                  a&lt;br /&gt;
,      dba_tab_partitions b&lt;br /&gt;
where  a.table_name       = b.table_name&lt;br /&gt;
and    b.tablespace_name != &amp;#039;&amp;amp;OLD_TABLESPACE&amp;#039;&lt;br /&gt;
/&lt;br /&gt;
undef OLD_TABLESPACE&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====What&amp;#039;s left hanging around?====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
col SEGMENT_TYPE for a20&lt;br /&gt;
col OWNER for a20&lt;br /&gt;
col SEGMENT_NAME for a40&lt;br /&gt;
col PARTITION_NAME for a15&lt;br /&gt;
col TABLESPACE_NAME for a30&lt;br /&gt;
select segment_type&lt;br /&gt;
,      owner&lt;br /&gt;
,      segment_name&lt;br /&gt;
,      partition_name&lt;br /&gt;
,      tablespace_name&lt;br /&gt;
from   dba_segments&lt;br /&gt;
where  tablespace_name in (&amp;#039;TS_THALER_IOT_OLD&amp;#039;,&amp;#039;TS_THALER_CU&amp;#039;,&amp;#039;TS_THALER_BACKUP&amp;#039;,&amp;#039;TS_THALER_PART_OLD&amp;#039;)&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
select table_owner&lt;br /&gt;
,      table_name&lt;br /&gt;
from   dba_indexes&lt;br /&gt;
where  index_name = &amp;#039;&amp;amp;index_name&amp;#039;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===What edition is my database (Standard, Enterprise, XE...)?===&lt;br /&gt;
Only works from 12c :-(&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select edition from sys.registry$ where cid=&amp;#039;CATPROC&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Is database a CDB with PDBs?===&lt;br /&gt;
Needs a bit of work. Won&amp;#039;t work pre-12c obviously and also not on Standby databases if they are in MOUNT mode&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
for db in $(ps -ef | grep [p]mon|awk -F_ &amp;#039;{print $NF}&amp;#039;)&lt;br /&gt;
do&lt;br /&gt;
    export ORACLE_SID=${db}&lt;br /&gt;
    ORAENV_ASK=NO&lt;br /&gt;
    . oraenv &amp;gt;/dev/null 2&amp;gt;&amp;amp;1&lt;br /&gt;
    sqlplus -s / as sysdba&amp;lt;&amp;lt;&amp;#039;EOSQL&amp;#039;&lt;br /&gt;
set head off newpa none&lt;br /&gt;
select name&lt;br /&gt;
,      (select count(*) from v$pdbs) npdbs&lt;br /&gt;
from   v$database&lt;br /&gt;
/&lt;br /&gt;
EOSQL&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
version 2&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
function is_db_cdb return boolean&lt;br /&gt;
is&lt;br /&gt;
    b_is_cdb        boolean := false;&lt;br /&gt;
    l_is_cdb        varchar2(3) := &amp;#039;NO&amp;#039;;&lt;br /&gt;
    e_col_not_found exception;&lt;br /&gt;
    pragma          exception_init(e_col_not_found, -904);&lt;br /&gt;
begin&lt;br /&gt;
    begin&lt;br /&gt;
        execute immediate &amp;#039;select cdb from v$database&amp;#039; &lt;br /&gt;
        into l_is_cdb;&lt;br /&gt;
    exception&lt;br /&gt;
        when e_col_not_found then l_is_cdb := &amp;#039;NO&amp;#039;;  -- ORA-00904&lt;br /&gt;
    end;&lt;br /&gt;
&lt;br /&gt;
    if (l_is_cdb = &amp;#039;YES&amp;#039;) then&lt;br /&gt;
        return TRUE;&lt;br /&gt;
    else&lt;br /&gt;
        return FALSE;  -- either not a cdb or pre-12.1 database&lt;br /&gt;
    end if;&lt;br /&gt;
&lt;br /&gt;
end is_db_cdb;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===List triggers in the database===&lt;br /&gt;
This query specifically lists after login triggers &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select obj.con_id&lt;br /&gt;
,      pdb.name&lt;br /&gt;
,      obj.owner&lt;br /&gt;
,      obj.object_name&lt;br /&gt;
,      to_char(obj.created, &amp;#039;DD/MM/YYYY HH24:MI:SS&amp;#039;)       created_str&lt;br /&gt;
,      to_char(obj.last_ddl_time, &amp;#039;DD/MM/YYYY HH24:MI:SS&amp;#039;) last_ddl_str&lt;br /&gt;
from   cdb_objects   obj&lt;br /&gt;
join   cdb_triggers trgs&lt;br /&gt;
       on (   obj.con_id      = trgs.con_id&lt;br /&gt;
          and obj.owner       = trgs.owner&lt;br /&gt;
          and obj.object_name = trgs.trigger_name&lt;br /&gt;
          )&lt;br /&gt;
join   v$pdbs pdb&lt;br /&gt;
       on ( obj.con_id  = pdb.con_id )&lt;br /&gt;
where  trgs.trigger_type     = &amp;#039;AFTER EVENT&amp;#039;&lt;br /&gt;
and    trgs.triggering_event like &amp;#039;LOGON%&amp;#039;&lt;br /&gt;
and    trgs.status           = &amp;#039;ENABLED&amp;#039;&lt;br /&gt;
order  by object_name&lt;br /&gt;
,      obj.last_ddl_time&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===List the pluggable databases (PDB) in a container database (CDB)===&lt;br /&gt;
The network_name column shows what you should find in tnsnames.ora for this db connection&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select name,network_name,pdb from v$services;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select * from v$pdbs;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Start and stop a pluggable database===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter pluggable database pdb1 open;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter pluggable database pdb1 close immediate;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Swith to a pluggable database===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter session set container=pdb1;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Reopen pluggable databases at container startup===&lt;br /&gt;
By default pluggable databases in a container remain in a MOUNT state when the container starts up.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select name, open_mode from v$pdbs where name = &amp;#039;PDB1&amp;#039;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
To modify this, open it and save its state&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter pluggable database pdb1 open;&lt;br /&gt;
alter pluggable database pdb1 save state;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
To see a log of issues with pluggable databases&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select * from pdb_plug_in_violations where type = &amp;#039;ERROR&amp;#039; and status != &amp;#039;RESOLVED&amp;#039; and name = &amp;#039;PDB1&amp;#039;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===What is the current container id in a cdb?===&lt;br /&gt;
CDB$ROOT is container id 1. User containers start from 2.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select sys_context(&amp;#039;USERENV&amp;#039;,&amp;#039;CON_ID&amp;#039;) from dual&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===What is the current container name in a cdb?===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select sys_context(&amp;#039;USERENV&amp;#039;,&amp;#039;CON_NAME&amp;#039;) from dual&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or just&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
show con_name&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Switching Between Containers===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SQL&amp;gt; show con_name&lt;br /&gt;
&lt;br /&gt;
CON_NAME&lt;br /&gt;
------------------------------&lt;br /&gt;
CDB$ROOT&lt;br /&gt;
&lt;br /&gt;
SQL&amp;gt; alter session set container=tstklok;&lt;br /&gt;
&lt;br /&gt;
Session altered.&lt;br /&gt;
&lt;br /&gt;
SQL&amp;gt;  show con_name&lt;br /&gt;
&lt;br /&gt;
CON_NAME&lt;br /&gt;
------------------------------&lt;br /&gt;
TSTKLOK&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Direct connection to pluggable database===&lt;br /&gt;
These must be made using a service (defined in tnsnames.ora). Each pluggable database automatically registers a service with the listener (v$services).&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sqlplus appuser/apppwd@tstklok&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or using ezconnect&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SQL&amp;gt; conn appuser/apppwd@//localhost:1521/tstklok&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===What platform is the database running on?===&lt;br /&gt;
Could be useful for handling line endings...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select platform_name from v$database&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
if instr(db_platform, &amp;#039;WINDOWS&amp;#039;) != 0 then&lt;br /&gt;
    crlf := CHR(13) || CHR(10);       -- Windows gets the \r and \n&lt;br /&gt;
else&lt;br /&gt;
    crlf := CHR (10);                 -- Just \n for the rest of the world&lt;br /&gt;
end if;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Is the database 32 or 64 bit?===&lt;br /&gt;
If the answer is 1,7,10,15,16 or 17, then it is 32bit, everything else should be 64bit.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select platform_id from v$database&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===What features is my database using?===&lt;br /&gt;
Before converting to Standard Edition, check the features here - some may be Enterprise specific.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
col name for a45&lt;br /&gt;
col description for a85&lt;br /&gt;
set lines 2000&lt;br /&gt;
select name&lt;br /&gt;
,      detected_usages&lt;br /&gt;
,      description&lt;br /&gt;
from   dba_feature_usage_statistics&lt;br /&gt;
where  1=1&lt;br /&gt;
and    currently_used = &amp;#039;TRUE&amp;#039;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===How many redo log switches per hour?===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 100&lt;br /&gt;
col &amp;quot;YYYYMMDD HH24&amp;quot; for a14&lt;br /&gt;
select to_char(first_time,&amp;#039;yyyymmdd hh24&amp;#039;) &amp;quot;YYYYMMDD HH24&amp;quot;&lt;br /&gt;
,      count(1)                            num_switches&lt;br /&gt;
from   v$log_history&lt;br /&gt;
group  by to_char(first_time,&amp;#039;yyyymmdd hh24&amp;#039;)&lt;br /&gt;
order  by 1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or a bit fancier version...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rem *********************************************************** &lt;br /&gt;
rem&lt;br /&gt;
rem	File: log_history.sql &lt;br /&gt;
rem	Description: Log switch rates from v$log_history &lt;br /&gt;
rem   &lt;br /&gt;
rem	From &amp;#039;Oracle Performance Survival Guide&amp;#039; by Guy Harrison&lt;br /&gt;
rem		Chapter 21 Page 637&lt;br /&gt;
rem		ISBN: 978-0137011957&lt;br /&gt;
rem		See www.guyharrison.net for further information&lt;br /&gt;
rem  &lt;br /&gt;
rem		This work is in the public domain NSA &lt;br /&gt;
rem   &lt;br /&gt;
rem&lt;br /&gt;
rem ********************************************************* &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
col min_minutes format 9999.99 &lt;br /&gt;
col max_minutes format 9999.99 &lt;br /&gt;
col avg_minutes format 9999.99 &lt;br /&gt;
set pagesize 1000&lt;br /&gt;
set lines 70&lt;br /&gt;
set echo on &lt;br /&gt;
&lt;br /&gt;
WITH log_history AS&lt;br /&gt;
       (SELECT thread#, first_time,&lt;br /&gt;
               LAG(first_time) OVER (ORDER BY thread#, sequence#)&lt;br /&gt;
                  last_first_time,&lt;br /&gt;
               (first_time&lt;br /&gt;
                - LAG(first_time) OVER (ORDER BY thread#, sequence#))&lt;br /&gt;
                    * 24* 60   last_log_time_minutes,&lt;br /&gt;
               LAG(thread#) OVER (ORDER BY thread#, sequence#)&lt;br /&gt;
                   last_thread#&lt;br /&gt;
        FROM v$log_history)&lt;br /&gt;
SELECT ROUND(MIN(last_log_time_minutes), 2) min_minutes,&lt;br /&gt;
       ROUND(MAX(last_log_time_minutes), 2) max_minutes,&lt;br /&gt;
       ROUND(AVG(last_log_time_minutes), 2) avg_minutes&lt;br /&gt;
FROM log_history&lt;br /&gt;
WHERE     last_first_time IS NOT NULL&lt;br /&gt;
      AND last_thread# = thread#&lt;br /&gt;
      AND first_time &amp;gt; SYSDATE - 1; &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Show redo log groups/members===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
col instance       for a8&lt;br /&gt;
col thread         for 999&lt;br /&gt;
col groupno        for 999&lt;br /&gt;
col member         for a35&lt;br /&gt;
col redo_file_type for a15&lt;br /&gt;
col log_status     for a10&lt;br /&gt;
col logsize_m      for 99999&lt;br /&gt;
col archived       for a12&lt;br /&gt;
&lt;br /&gt;
SELECT i.instance_name   instance&lt;br /&gt;
,      i.thread#         thread&lt;br /&gt;
,      f.group#          groupno&lt;br /&gt;
,      f.member          member&lt;br /&gt;
,      f.type            redo_file_type&lt;br /&gt;
,      l.status          log_status&lt;br /&gt;
,      l.bytes/1024/1024 logsize_m&lt;br /&gt;
,      l.archived        archived&lt;br /&gt;
FROM   gv$logfile  f&lt;br /&gt;
,      gv$log      l&lt;br /&gt;
,      gv$instance i&lt;br /&gt;
WHERE  1=1&lt;br /&gt;
and    f.group#  = l.group#&lt;br /&gt;
AND    l.thread# = i.thread#&lt;br /&gt;
AND    i.inst_id = f.inst_id&lt;br /&gt;
AND    f.inst_id = l.inst_id&lt;br /&gt;
ORDER  BY i.instance_name&lt;br /&gt;
,      f.group#&lt;br /&gt;
,      f.member;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Korn shell timestamp function===&lt;br /&gt;
Example usage: echo &amp;quot;`ts`: Checking backup status&amp;quot;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
function ts {&lt;br /&gt;
    date +&amp;#039;%d-%b-%Y %H:%M:%S&amp;#039;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Drop a database===&lt;br /&gt;
Dropping a database including backups should be considered criminal in a production environment!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sqlplus / as sysdba&lt;br /&gt;
startup force mount exclusive restrict&lt;br /&gt;
exit&lt;br /&gt;
rman target /&lt;br /&gt;
drop database including backups noprompt;&lt;br /&gt;
exit&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
RMAN&amp;gt; connect target sys/pass@test&lt;br /&gt;
connected to target database: test (dbid=123456789)&lt;br /&gt;
&lt;br /&gt;
RMAN&amp;gt; startup force mount&lt;br /&gt;
RMAN&amp;gt; sql &amp;#039;alter system enable restricted session&amp;#039;;&lt;br /&gt;
RMAN&amp;gt; drop database including backups noprompt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Use sub-select or in-line views to update base tables===&lt;br /&gt;
Inline views can be used to update base table data&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
update&lt;br /&gt;
    (&lt;br /&gt;
    select p.list_price&lt;br /&gt;
    from   products           p&lt;br /&gt;
    ,      product_categories pc&lt;br /&gt;
    where  1=1&lt;br /&gt;
    and    p.category_id    = pc.category_id&lt;br /&gt;
    and    pc.category_name = &amp;#039;CPU&amp;#039;&lt;br /&gt;
    )&lt;br /&gt;
set list_price = list_price * 1.15; &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Use sub-select or in-line views to delete base table data===&lt;br /&gt;
A different way to delete rows in base tables, using Inline views or subselect&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
delete&lt;br /&gt;
    (&lt;br /&gt;
    select p.list_price&lt;br /&gt;
    from   products           p&lt;br /&gt;
    ,      product_categories pc&lt;br /&gt;
    where  1=1&lt;br /&gt;
    and    p.category_id    = pc.category_id&lt;br /&gt;
    and    pc.category_name = &amp;#039;CPU&amp;#039;&lt;br /&gt;
    )&lt;br /&gt;
where list_price &amp;lt; 1000; &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Mass update of files using perl inline script===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
for server in `cat /home/tools/etc/oracle/oracle_servers`; do&lt;br /&gt;
    ssh $server “perl -p -i -e &amp;#039;s/T01/D01/&amp;#039; /home/tools/scripts/rman/inclexcl.lst”&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===How to use vi-style editing in SQL*Plus===&lt;br /&gt;
These instructions are for Redhat but other versions will be very similar&lt;br /&gt;
* Download rlwrap from [http://dl.fedoraproject.org/pub/epel/5/x86_64/repoview/rlwrap.html] or [http://dl.fedoraproject.org/pub/epel/6/x86_64/repoview/rlwrap.html]&lt;br /&gt;
* sudo yum install rlwrap&lt;br /&gt;
* build a dictionary file for autocomplete on pressing Tab&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
vi $HOME/sql.dict&lt;br /&gt;
select&lt;br /&gt;
from&lt;br /&gt;
dba_users&lt;br /&gt;
dba_data_files&lt;br /&gt;
dba_tablespaces&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alias sysdba=&amp;#039;rlwrap -f $HOME/sql.dict sqlplus / as sysdba&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or for general command use...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alias sqlplus=&amp;#039;rlwrap -D2 -ic sqlplus&amp;#039;&lt;br /&gt;
alias dgmgrl=&amp;#039;rlwrap -D2 -ic dgmgrl&amp;#039;&lt;br /&gt;
alias rman=&amp;#039;rlwrap -D2 -ic rman&amp;#039;&lt;br /&gt;
alias asmcmd=&amp;#039;rlwrap -D2 -ic asmcmd&amp;#039;&lt;br /&gt;
alias lsnrctl=&amp;#039;rlwrap -D2 -ic lsnrctl&amp;#039;&lt;br /&gt;
alias adrci=&amp;#039;rlwrap -D2 -ic adrci&amp;#039;&lt;br /&gt;
alias impdp=&amp;#039;rlwrap -D2 -ic impdp&amp;#039;&lt;br /&gt;
alias expdp=&amp;#039;rlwrap -D2 -ic expdp&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Execute an SQL statement on all databases on all servers for a customer===&lt;br /&gt;
Run from customer&amp;#039;s management server&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
./dosh -c &amp;quot;su - oracle -c &amp;#039;/home/tools/scripts/oracle/all_db_do -v \&amp;quot;select username, account_status, profile from dba_users order by 3;\&amp;quot;&amp;#039;&amp;quot; &amp;gt;user_status.lst&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SCRIPTS_DIR=/home/tools/scripts/oracle&lt;br /&gt;
$SCRIPTS_DIR/dosh -c &amp;quot;su - oraibm -c \&amp;quot;$SCRIPTS_DIR/all_db_do &amp;#039;alter user ops\\\$oraibm profile oracle_system_user;&amp;#039;\&amp;quot;&amp;quot;&lt;br /&gt;
$SCRIPTS_DIR/dosh2 -c &amp;quot;su - oraibm -c \&amp;quot;$SCRIPTS_DIR/all_db_do &amp;#039;alter user ops$oraibm profile oracle_system_user;&amp;#039;\&amp;quot;&amp;quot;&lt;br /&gt;
$SCRIPTS_DIR/dosh2 -c &amp;quot;su - oraibm -c \&amp;quot;$SCRIPTS_DIR/all_db_do &amp;#039;alter system set control_file_record_keep_time=31;&amp;#039;\&amp;quot;&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Where is the alert log/alertlog?===&lt;br /&gt;
Older systems&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select value from v$parameter where name=&amp;#039;background_dump_dest&amp;#039;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Newer systems&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select value from v$diag_info where name=&amp;#039;Diag Trace&amp;#039;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Grant normal users access to the alertlog table (sys.x$dbgalertext)===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
create view x$dbgalertext_v as select * from x$dbgalertext;&lt;br /&gt;
grant select on x$dbgalertext_v to &amp;amp;&amp;amp;grantee;&lt;br /&gt;
create or replace synonym &amp;amp;grantee..x$dbgalertext for sys.x$dbgalertext_v;&lt;br /&gt;
undef grantee&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Search alert log for ORA-00600 and ORA-07445 errors===&lt;br /&gt;
Scan the database table version of the alertlog for errors without reporting what was already found.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select indx, message_text from x$dbgalertext where message_text like &amp;#039;%ORA-00600%&amp;#039; or message_text like &amp;#039;%ORA-07445%&amp;#039; and indx &amp;gt; &amp;amp;last_queried_indx order by indx desc;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Simulating errors in alert log===&lt;br /&gt;
Sometimes you need to inject error messages into the alertlog to test your monitoring system. This generates the entries in the alertlog and in x$dbgalertext table.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
exec sys.dbms_system.ksdwrt(2, &amp;#039;ORA-07445: Testing this error code for Zenoss, do not investigate.&amp;#039;);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This additionally creates a trace file.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
exec sys.dbms_system.ksdwrt(3, &amp;#039;ORA-00600: Testing this error code for Zenoss, do not investigate.&amp;#039;);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===tail the database alert log===&lt;br /&gt;
If an ADR error is displayed, then ORACLE_SID is probably not set&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alias alertlog=&amp;#039;adrci exec=&amp;quot;set home diag/rdbms/$(echo $ORACLE_SID | tr A-Z a-z)/$ORACLE_SID; show alert -tail -f&amp;quot;&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===What is my WAN ip address?===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
curl -A &amp;quot;Mozilla/4.0&amp;quot; http://checkip.dyndns.org/ 2&amp;gt;/dev/null | perl -ne &amp;#039;print $1 if /Current IP Address: (\d+\.\d+\.\d+\.\d+)/&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
curl -A &amp;quot;Mozilla/4.0&amp;quot; http://myip.dnsdynamic.org/ 2&amp;gt;/dev/null&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Wait for child pid to finish in background and report its status===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# submit a process to the background&lt;br /&gt;
export_schema1.ksh &amp;amp;&lt;br /&gt;
bgpid=$!&lt;br /&gt;
&lt;br /&gt;
while (ps -ef | grep $bgpid | grep -v grep); do&lt;br /&gt;
    # still running...&lt;br /&gt;
    sleep 600&lt;br /&gt;
done&lt;br /&gt;
&lt;br /&gt;
# should be finished&lt;br /&gt;
wait $bgpid&lt;br /&gt;
bgstatus=$?&lt;br /&gt;
echo background process ended with status $bgstatus&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/usr/bin/ksh&lt;br /&gt;
# submit a few processes to the background&lt;br /&gt;
# wait for them all to finish&lt;br /&gt;
# concat their logfiles&lt;br /&gt;
&lt;br /&gt;
(./sleeper.sh;echo &amp;quot;sleeper 1 finished&amp;quot;)&amp;gt;sleeper1.log &amp;amp;&lt;br /&gt;
PIDLIST=&amp;quot;$PIDLIST $!&amp;quot;&lt;br /&gt;
echo &amp;quot;PIDLIST is $PIDLIST ...&amp;quot;&lt;br /&gt;
sleep 5&lt;br /&gt;
&lt;br /&gt;
(./sleeper.sh;echo &amp;quot;sleeper 2 finished&amp;quot;)&amp;gt;sleeper2.log &amp;amp;&lt;br /&gt;
PIDLIST=&amp;quot;$PIDLIST $!&amp;quot;&lt;br /&gt;
echo &amp;quot;PIDLIST is $PIDLIST ...&amp;quot;&lt;br /&gt;
sleep 5&lt;br /&gt;
&lt;br /&gt;
(./sleeper.sh;echo &amp;quot;sleeper 3 finished&amp;quot;)&amp;gt;sleeper3.log &amp;amp;&lt;br /&gt;
PIDLIST=&amp;quot;$PIDLIST $!&amp;quot;&lt;br /&gt;
echo &amp;quot;PIDLIST is $PIDLIST ...&amp;quot;&lt;br /&gt;
sleep 5&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;Now 15 seconds later, we have 3 pids: $PIDLIST&amp;quot;&lt;br /&gt;
for PID in $PIDLIST; do&lt;br /&gt;
    wait $PID&lt;br /&gt;
    echo &amp;quot;$PID exited with status $?&amp;quot;&lt;br /&gt;
done&lt;br /&gt;
&lt;br /&gt;
# all jobs should have ended, concat their logs&lt;br /&gt;
cat sleeper*log &amp;gt; sleepers.log&lt;br /&gt;
cat sleepers.log&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Real world example&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/usr/bin/ksh&lt;br /&gt;
# ==============================================================================&lt;br /&gt;
# Name         : export_JDBEOP1.ksh&lt;br /&gt;
# Description  : Run export in pieces for performance reasons&lt;br /&gt;
#&lt;br /&gt;
# Parameters   : &lt;br /&gt;
#&lt;br /&gt;
# Notes        : Also decide whether to exclude PDARC schema or not&lt;br /&gt;
#                depending on what day it is&lt;br /&gt;
#&lt;br /&gt;
#&lt;br /&gt;
# Modification History&lt;br /&gt;
# ====================&lt;br /&gt;
# When      Who               What&lt;br /&gt;
# ========= ================= ==================================================&lt;br /&gt;
# 15-OCT-13 Stuart Barkley    Created&lt;br /&gt;
# ==============================================================================&lt;br /&gt;
&lt;br /&gt;
STARTTIME=`date &amp;#039;+%Y%m%d%H%M%S&amp;#039;`&lt;br /&gt;
DAYNO=`date +%u`&lt;br /&gt;
PROGNAME=`basename $0`&lt;br /&gt;
SCRIPTS_DIR=/home/tools/scripts/oracle&lt;br /&gt;
DATA_DIR=/oracle/JDBEOP1/admin/change&lt;br /&gt;
EXPORT_DIR=/oracle/export/JDBEOP1&lt;br /&gt;
&lt;br /&gt;
# marker so we can find our files later&lt;br /&gt;
MARKERFILE=/tmp/start_$PROGNAME_$$&lt;br /&gt;
touch $MARKERFILE&lt;br /&gt;
&lt;br /&gt;
$SCRIPTS_DIR/expdp_PARFILE.ksh -s JDBEOP1 -u PRODDTA -p 4 -k 2 -f $DATA_DIR/JDBEOP1_PRODDTA.parfile &amp;amp;&lt;br /&gt;
PIDLIST=&amp;quot;$PIDLIST $!&amp;quot;&lt;br /&gt;
echo &amp;quot;PIDLIST is $PIDLIST ...&amp;quot;&lt;br /&gt;
&lt;br /&gt;
$SCRIPTS_DIR/expdp_PARFILE.ksh -s JDBEOP1 -u PRODCTL -p 2 -k 2 -f $DATA_DIR/JDBEOP1_PRODCTL.parfile &amp;amp;&lt;br /&gt;
PIDLIST=&amp;quot;$PIDLIST $!&amp;quot;&lt;br /&gt;
echo &amp;quot;PIDLIST is $PIDLIST ...&amp;quot;&lt;br /&gt;
&lt;br /&gt;
$SCRIPTS_DIR/expdp_PARFILE.ksh -s JDBEOP1 -u NOPRODNOPDARC -p 4 -k 2 -f $DATA_DIR/JDBEOP1_NOPROD_NOPDARC.parfile &amp;amp;&lt;br /&gt;
PIDLIST=&amp;quot;$PIDLIST $!&amp;quot;&lt;br /&gt;
echo &amp;quot;PIDLIST is $PIDLIST ...&amp;quot;&lt;br /&gt;
&lt;br /&gt;
if [[ $DAYNO -eq 1 ]]; then&lt;br /&gt;
    $SCRIPTS_DIR/expdp_PARFILE.ksh -s JDBEOP1 -u NOPROD -p 4 -k 2 -f $DATA_DIR/JDBEOP1_NOPROD.parfile &amp;amp;&lt;br /&gt;
    PIDLIST=&amp;quot;$PIDLIST $!&amp;quot;&lt;br /&gt;
    echo &amp;quot;PIDLIST is $PIDLIST ...&amp;quot;&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
# now sit and wait for the exports to finish&lt;br /&gt;
for PID in $PIDLIST; do&lt;br /&gt;
    echo &amp;quot;waiting for pid $PID to finish&amp;quot;&lt;br /&gt;
    wait $PID&lt;br /&gt;
    echo &amp;quot;$PID exited with status $?&amp;quot;&lt;br /&gt;
done&lt;br /&gt;
&lt;br /&gt;
# collect all log files up into one&lt;br /&gt;
cd $EXPORT_DIR&lt;br /&gt;
for i in `find . -name &amp;quot;expdp_JDBEOP1*log&amp;quot; -newer $MARKERFILE`; do&lt;br /&gt;
    cat $i &amp;gt; expdp_JDBEOP1_D_FULL_${STARTTIME}.log&lt;br /&gt;
done&lt;br /&gt;
&lt;br /&gt;
rm $MARKLERFILE&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Create private DB link for a user without knowing his password===&lt;br /&gt;
* Inspired by [http://oradbatips.blogspot.co.uk/2010/01/tip-84-create-private-db-link-for-user.html oradbatips.blogspot.co.uk]&lt;br /&gt;
It uses a clever package, dbms_sys_sql.&amp;lt;br /&amp;gt;&lt;br /&gt;
Also useful for executing anything on behalf of another user.&amp;lt;br /&amp;gt;&lt;br /&gt;
Here is an example on how to create private database link for a user.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
create or replace procedure link_creator ( p_owner varchar2, p_dblink_name varchar2, p_username varchar2, p_password varchar2, p_address varchar2 ) as&lt;br /&gt;
    uid number;&lt;br /&gt;
    sqltext varchar2(1000) := &amp;#039;create [public] database link [link_name] connect to [username] identified by [password] using &amp;#039;&amp;#039;[address]&amp;#039;&amp;#039;&amp;#039;;&lt;br /&gt;
    myint integer;&lt;br /&gt;
begin&lt;br /&gt;
    if upper(p_owner) = &amp;#039;PUBLIC&amp;#039; then&lt;br /&gt;
        sqltext := replace(sqltext, &amp;#039;[public]&amp;#039;, &amp;#039;public&amp;#039;);&lt;br /&gt;
    else&lt;br /&gt;
        sqltext := replace(sqltext, &amp;#039;[public]&amp;#039;, &amp;#039;&amp;#039;);&lt;br /&gt;
    end if;&lt;br /&gt;
    sqltext := replace(sqltext, &amp;#039;[linkname]&amp;#039;, p_dblink_name);&lt;br /&gt;
    sqltext := replace(sqltext, &amp;#039;[username]&amp;#039;, p_username);&lt;br /&gt;
    sqltext := replace(sqltext, &amp;#039;[password]&amp;#039;, p_password);&lt;br /&gt;
    sqltext := replace(sqltext, &amp;#039;[address]&amp;#039;, p_address);&lt;br /&gt;
&lt;br /&gt;
    select user_id&lt;br /&gt;
    into   uid&lt;br /&gt;
    from   dba_users&lt;br /&gt;
    where  username = decode(upper(p_owner), &amp;#039;PUBLIC&amp;#039;, &amp;#039;SYS&amp;#039;, p_owner)&lt;br /&gt;
    ;&lt;br /&gt;
    myint:=sys.dbms_sys_sql.open_cursor();&lt;br /&gt;
    sys.dbms_sys_sql.parse_as_user ( myint, sqltext, dbms_sql.native, uid );&lt;br /&gt;
    sys.dbms_sys_sql.close_cursor(myint);&lt;br /&gt;
end;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Here we can generate SQL to rebuild the links for future use. Note the password is no longer stored in this column.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set pages 1000&lt;br /&gt;
select &amp;#039;begin link_creator ( &amp;#039;&amp;#039;&amp;#039;|| u.name ||&amp;#039;&amp;#039;&amp;#039;,&amp;#039;&amp;#039;&amp;#039;|| l.name ||&amp;#039;&amp;#039;&amp;#039;,&amp;#039;&amp;#039;&amp;#039;|| l.userid ||&amp;#039;&amp;#039;&amp;#039;,&amp;#039;&amp;#039;&amp;#039;|| l.password ||&amp;#039;&amp;#039;&amp;#039;,&amp;#039;&amp;#039;&amp;#039;|| l.host ||&amp;#039;&amp;#039;&amp;#039;); end;&amp;#039;|| chr(10) ||&amp;#039;/&amp;#039; link_text&lt;br /&gt;
from   sys.link$ l&lt;br /&gt;
,      sys.user$ u&lt;br /&gt;
where  l.owner# = u.user#&lt;br /&gt;
;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Another method to create a db_link from sys on behalf of a user is to create a procedure under that users name that does the db link creation====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
grant create database link to &amp;amp;&amp;amp;user;&lt;br /&gt;
&lt;br /&gt;
create or replace procedure &amp;amp;user..create_db_link as&lt;br /&gt;
begin&lt;br /&gt;
    execute immediate &amp;#039;create database link &amp;amp;link_name connect to &amp;amp;user identified by &amp;amp;users_password using &amp;#039;&amp;#039;&amp;amp;tns_connect_identifier&amp;#039;&amp;#039;&amp;#039;;&lt;br /&gt;
end create_db_link;&lt;br /&gt;
&lt;br /&gt;
exec &amp;amp;user..create_db_link;&lt;br /&gt;
&lt;br /&gt;
revoke create database link from &amp;amp;user;&lt;br /&gt;
&lt;br /&gt;
drop procedure &amp;amp;user..create_db_link;&lt;br /&gt;
undef user&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Create a comma separated list of columns from a select statement===&lt;br /&gt;
Method 1:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SELECT parent_id,&lt;br /&gt;
       RTRIM(XMLAGG(XMLELEMENT(e,child_id || &amp;#039;,&amp;#039;)).EXTRACT(&amp;#039;//text()&amp;#039;),&amp;#039;,&amp;#039;) AS &amp;quot;Children&amp;quot;&lt;br /&gt;
FROM   parentChildTable&lt;br /&gt;
WHERE  parent_id = 0&lt;br /&gt;
GROUP  BY parent_id&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SELECT parent_id,&lt;br /&gt;
       LISTAGG(child_id, &amp;#039;,&amp;#039;) WITHIN GROUP (ORDER BY child_id) AS &amp;quot;Children&amp;quot;&lt;br /&gt;
  FROM parentChildTable&lt;br /&gt;
 WHERE parent_id = 0&lt;br /&gt;
 GROUP BY parent_id&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Method 2 (undocumented and cannot therefore be relied on to continue working in the same manner):&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SELECT wmsys.wm_concat(&amp;lt;column_name&amp;gt;)&lt;br /&gt;
FROM &amp;lt;table_name&amp;gt;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Start an instant one-line webserver in current directory===&lt;br /&gt;
Need to quickly share/copy a file or read an html file on Linux? Start a web server!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
python -m SimpleHTTPServer 8000&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
and point your browser to http://localhost:8000&amp;lt;br /&amp;gt;&lt;br /&gt;
or&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
while true; do nc -l -p 80 -q 1 &amp;lt; index.html; done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Get SQL*Plus to generate HTML===&lt;br /&gt;
* [http://docs.oracle.com/cd/E11882_01/server.112/e16604/ch_seven.htm#CHDCECJG official guide]&lt;br /&gt;
One way to do it... use -m(arkup) option to specify:&amp;lt;br /&amp;gt;&lt;br /&gt;
html on/off - specifies whether to output html output or not&lt;br /&gt;
head - specify your own customised head contents&amp;lt;br /&amp;gt;&lt;br /&gt;
spool off - as a part of the -m tag means do not print the default &amp;amp;lt;html&amp;amp;gt;, &amp;amp;lt;head&amp;amp;gt; and &amp;amp;lt;body&amp;amp;gt; tags&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sqlplus -m &amp;quot;html on head &amp;#039;&amp;lt;link rel=&amp;quot;stylesheet&amp;quot; href=&amp;quot;/dbamon_golden.css&amp;quot; type=&amp;quot;text/css&amp;quot; /&amp;gt;&amp;#039; spool off&amp;quot; / as sysdba&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sqlplus / as sysdba&lt;br /&gt;
set markup html on head &amp;#039;&amp;lt;link rel=&amp;quot;stylesheet&amp;quot; href=&amp;quot;/dbamon_golden.css&amp;quot; type=&amp;quot;text/css&amp;quot; /&amp;gt;&amp;#039; body &amp;quot;&amp;quot; table &amp;quot;&amp;quot; spool off&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
besides html and head, you can also specify:&amp;lt;br /&amp;gt;&lt;br /&gt;
body - specify your own customised body attributes&amp;lt;br /&amp;gt;&lt;br /&gt;
table - override the default table options&amp;lt;br /&amp;gt;&lt;br /&gt;
entmap - turn on or off the html replacement characters (&amp;amp;lt, &amp;amp;gt, etc...)&amp;lt;br /&amp;gt;&lt;br /&gt;
preformat - uses the &amp;amp;lt;pre&amp;amp;gt; tag to format output exactly as required&amp;lt;br /&amp;gt;&lt;br /&gt;
* another little gem...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
----------------------------------------&lt;br /&gt;
-- get the last SQL*Plus output in HTML&lt;br /&gt;
-- after Tanel Poder&lt;br /&gt;
----------------------------------------&lt;br /&gt;
&lt;br /&gt;
set termout off&lt;br /&gt;
&lt;br /&gt;
set markup HTML ON HEAD &amp;quot; -&lt;br /&gt;
 -&lt;br /&gt;
&amp;quot; -&lt;br /&gt;
BODY &amp;quot;&amp;quot; -&lt;br /&gt;
TABLE &amp;quot;border=&amp;#039;1&amp;#039; align=&amp;#039;center&amp;#039; summary=&amp;#039;Script output&amp;#039;&amp;quot; -&lt;br /&gt;
SPOOL ON ENTMAP ON PREFORMAT OFF&lt;br /&gt;
&lt;br /&gt;
spool myoutput.html&lt;br /&gt;
&lt;br /&gt;
l&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
spool off&lt;br /&gt;
set markup html off spool off&lt;br /&gt;
host firefox myoutput.html&lt;br /&gt;
set termout on&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===HTML SELECT - Trigger JavaScript ONCHANGE event even when the option is not changed===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;select onchange=&amp;quot;jsFunction()&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;option value=&amp;quot;&amp;quot; disabled selected style=&amp;quot;display:none;&amp;quot;&amp;gt;Label&amp;lt;/option&amp;gt;&lt;br /&gt;
  &amp;lt;option value=&amp;quot;1&amp;quot;&amp;gt;1&amp;lt;/option&amp;gt;&lt;br /&gt;
  &amp;lt;option value=&amp;quot;2&amp;quot;&amp;gt;2&amp;lt;/option&amp;gt;&lt;br /&gt;
  &amp;lt;option value=&amp;quot;3&amp;quot;&amp;gt;3&amp;lt;/option&amp;gt;&lt;br /&gt;
&amp;lt;/select&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Display horizontal bar graph in HTML table data cell===&lt;br /&gt;
Using Perl&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
print (&amp;#039;&amp;lt;td class=&amp;quot;left&amp;quot;&amp;gt;&amp;#039; .&lt;br /&gt;
            &amp;#039;&amp;lt;div style=&amp;quot;background-color:#8097BE;width:&amp;quot;&amp;#039;,$allocpercused  ,&amp;#039;%;&amp;quot; /&amp;gt;&amp;#039; .&lt;br /&gt;
            &amp;#039;&amp;lt;div style=&amp;quot;background-color:red;    width:&amp;quot;&amp;#039;,$automaxpercused,&amp;#039;%;&amp;quot; /&amp;gt;&amp;#039; .&lt;br /&gt;
            $tspace .&lt;br /&gt;
       &amp;#039;&amp;lt;/td&amp;gt;&amp;#039;&lt;br /&gt;
);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Depending on which way around the divs are, you get different interpretations&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
print (&amp;quot;&amp;lt;td class=\&amp;quot;left\&amp;quot;&amp;gt;&amp;quot; .&lt;br /&gt;
            &amp;quot;&amp;lt;div style=\&amp;quot;border-right:2px solid red; width:&amp;quot;,($automaxpercused&amp;gt;99)?(100):($automaxpercused),&amp;quot;%;\&amp;quot; /&amp;gt;&amp;quot; .&lt;br /&gt;
            &amp;quot;&amp;lt;div style=\&amp;quot;background-color:#8097BE;width:&amp;quot;,$allocpercused  ,&amp;quot;%;\&amp;quot; /&amp;gt;&amp;quot; .&lt;br /&gt;
            $tspace .&lt;br /&gt;
       &amp;quot;&amp;lt;/td&amp;gt;&amp;quot;&lt;br /&gt;
);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====References====&lt;br /&gt;
* [http://stackoverflow.com/questions/5324996/comma-separated-list-as-a-result-of-select-statement-in-oracle stackoverflow.com]&lt;br /&gt;
* [http://www.salvis.com/blog/?p=207 A whole page showing how to do it in all versions back to 7!]&lt;/div&gt;</summary>
		<author><name>Stuart</name></author>	</entry>

	<entry>
		<id>https://mailnest.com/dbawiki/index.php?title=Snippets&amp;diff=3395</id>
		<title>Snippets</title>
		<link rel="alternate" type="text/html" href="https://mailnest.com/dbawiki/index.php?title=Snippets&amp;diff=3395"/>
				<updated>2018-12-04T20:08:08Z</updated>
		
		<summary type="html">&lt;p&gt;Stuart: /* Write to the alert log from PL/SQL */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;===Protecting an Apache Web Server directory with htaccess===&lt;br /&gt;
* [https://davidwalsh.name/password-protect-directory-using-htaccess https://davidwalsh.name/password-protect-directory-using-htaccess]&lt;br /&gt;
* [http://www.htaccesstools.com/articles/password-protection/ http://www.htaccesstools.com/articles/password-protection/]&lt;br /&gt;
Two files are needed.&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;The .htaccess Code&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
AuthType Basic&lt;br /&gt;
AuthName &amp;quot;restricted area&amp;quot;&lt;br /&gt;
AuthUserFile /home/davidwalsh/html/protect-me-dir/.htpasswd&lt;br /&gt;
require valid-user&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;The .htpasswd Code&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
davidwalsh:daWHfZrDLB88.&lt;br /&gt;
rodstewart:roFulYxC2.8ws&lt;br /&gt;
cssexpert:csmnmq.M8T5ho&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Protecting a lighttpd directory with htaccess===&lt;br /&gt;
Generate an MD5 hash with the tools above and paste into this file&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
vi /etc/lighttpd/.htpasswd&lt;br /&gt;
stuart:3#$567890#$56789056789&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Check modules.conf file to ensure mod_auth and mod_rewrite are enabled&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
vi /etc/lighttpd/modules.conf&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Alter the lighttpd.conf file to allow the authentication&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#auth directives&lt;br /&gt;
auth.backend = &amp;quot;htpasswd&amp;quot;&lt;br /&gt;
auth.backend.htpasswd.userfile = &amp;quot;/etc/lighttpd/.htpasswd&amp;quot;&lt;br /&gt;
auth.debug = 1&lt;br /&gt;
$HTTP[&amp;quot;url&amp;quot;] =~ &amp;quot;^/cgi-bin&amp;quot; {&lt;br /&gt;
        auth.require = ( &amp;quot;&amp;quot; =&amp;gt;&lt;br /&gt;
        (&lt;br /&gt;
        &amp;quot;method&amp;quot; =&amp;gt; &amp;quot;basic&amp;quot;,&lt;br /&gt;
        &amp;quot;realm&amp;quot; =&amp;gt; &amp;quot;DbaHawk access&amp;quot;,&lt;br /&gt;
        &amp;quot;require&amp;quot; =&amp;gt; &amp;quot;valid-user&amp;quot;&lt;br /&gt;
        ) )&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Restart the lighttpd server&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
systemctl stop lighttpd&lt;br /&gt;
systemctl start lighttpd&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
I tried it with htdigest but could not get it to protest the directory!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#auth.backend = &amp;quot;htdigest&amp;quot;&lt;br /&gt;
#auth.backend.htdigest.userfile = &amp;quot;/etc/lighttpd/lighttpd.user.htdigest&amp;quot;&lt;br /&gt;
#auth.require = (&lt;br /&gt;
#    &amp;quot;/var/www/cgi-bin/&amp;quot; =&amp;gt; (&lt;br /&gt;
#    &amp;quot;method&amp;quot;  =&amp;gt; &amp;quot;basic&amp;quot;,&lt;br /&gt;
#    &amp;quot;realm&amp;quot;   =&amp;gt; &amp;quot;DbaHawk access&amp;quot;,&lt;br /&gt;
#    &amp;quot;require&amp;quot; =&amp;gt; &amp;quot;valid-user&amp;quot;&lt;br /&gt;
#    ),&lt;br /&gt;
#)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Rename a datafile if the filename contains junk / unprintable characters===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter tablespace ts_thaler_data offline;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Oracle have a document that describes a few ways of doing it in [https://support.oracle.com/rs?type=doc&amp;amp;id=824473.1 Note 824473.1]&lt;br /&gt;
If the filename contains control characters and cannot be selected in the normal way, use ls -ali to find the node number and then use find with -inum to rename (or move) the file&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ls -baltri&lt;br /&gt;
total 47474984&lt;br /&gt;
12409 -rw-r-----    1 oracle   oinstall 1073750016 Sep 26 13:56 ts_thaler_data_02\1776.dbf&lt;br /&gt;
12350 -rw-r-----    1 oracle   oinstall 5242888192 Sep 26 13:56 ts_thaler_data_01.dbf&lt;br /&gt;
&lt;br /&gt;
find . -inum 12409 -exec mv {} ts_thaler_data_06.dbf \;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Work out what the database thinks the name is and rename it there too! AskTom has a discussion on it [https://asktom.oracle.com/pls/apex/asktom.search?tag=rename-datafile-with-dummy-characters-after-dbf here]&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select substr(name,i,1),ascii(substr(name,i,1)) from ( select name from v$datafile where file# = 9), ( select rownum i from dual connect by level &amp;lt;= 50);&lt;br /&gt;
SUBS ASCII(SUBSTR(NAME,I,1))&lt;br /&gt;
---- -----------------------&lt;br /&gt;
t                        116&lt;br /&gt;
s                        115&lt;br /&gt;
_                         95&lt;br /&gt;
t                        116&lt;br /&gt;
h                        104&lt;br /&gt;
a                         97&lt;br /&gt;
l                        108&lt;br /&gt;
e                        101&lt;br /&gt;
r                        114&lt;br /&gt;
_                         95&lt;br /&gt;
d                        100&lt;br /&gt;
a                         97&lt;br /&gt;
t                        116&lt;br /&gt;
a                         97&lt;br /&gt;
_                         95&lt;br /&gt;
0                         48&lt;br /&gt;
2                         50&lt;br /&gt;
                         127&lt;br /&gt;
2                         50&lt;br /&gt;
.                         46&lt;br /&gt;
d                        100&lt;br /&gt;
b                         98&lt;br /&gt;
f                        102&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
You can see there&amp;#039;s a 127 just before the .dbf... this crept in a the backspace key was not working correctly.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set serveroutput on&lt;br /&gt;
declare&lt;br /&gt;
   fname1 varchar2(100);&lt;br /&gt;
   fname2 varchar2(100);&lt;br /&gt;
begin&lt;br /&gt;
  select name into fname1 from v$datafile where file# = 9;&lt;br /&gt;
  fname2 := replace(fname1,chr(127));&lt;br /&gt;
  &lt;br /&gt;
  dbms_output.put_line(&amp;#039;alter database rename file &amp;#039;&amp;#039;&amp;#039;||fname1||&amp;#039;&amp;#039;&amp;#039; to &amp;#039;&amp;#039;&amp;#039;||fname2||&amp;#039;&amp;#039;&amp;#039;&amp;#039;);&lt;br /&gt;
  execute immediate &amp;#039;alter database rename file &amp;#039;&amp;#039;&amp;#039;||fname1||&amp;#039;&amp;#039;&amp;#039; to &amp;#039;&amp;#039;&amp;#039;||fname2||&amp;#039;&amp;#039;&amp;#039;&amp;#039;;&lt;br /&gt;
end;&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
alter tablespace ts_thaler_data_online;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Generate creation of directory names from dba_directories===&lt;br /&gt;
Before deleting or dropping directories in the database, use this script to generate the create statements&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select &amp;#039;create or replace directory &amp;#039;||directory_name||&amp;#039; as &amp;#039;&amp;#039;&amp;#039;||directory_path||&amp;#039;&amp;#039;&amp;#039;;&amp;#039; from dba_directories;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Check if current (dot) directory is in PATH variable===&lt;br /&gt;
Using bareword comparison to check PATH variable&amp;lt;pre&amp;gt;&lt;br /&gt;
if [[ :$PATH: == *:&amp;quot;.&amp;quot;:* ]] ; then&lt;br /&gt;
    echo &amp;quot;in path&amp;quot;&lt;br /&gt;
else&lt;br /&gt;
    echo &amp;quot;not in path&amp;quot;&lt;br /&gt;
fi&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===tail a logfile from within the script you are writing it to===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#&lt;br /&gt;
# display logfile in real time&lt;br /&gt;
#&lt;br /&gt;
( tail -0f ${LOGFILE} ) &amp;amp;&lt;br /&gt;
tailPID=$!&lt;br /&gt;
&lt;br /&gt;
trap &amp;quot;kill $tailPID&amp;quot; 0 1 2 3 5 9 15&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Dump package, procedure etc. from dba_source in a way that it can be used to recreate it===&lt;br /&gt;
From [https://asktom.oracle.com/pls/apex/f?p=100:11:0::::P11_QUESTION_ID:454220160386 Ask Tom]&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 1000 pages 1000 feedb off verif off&lt;br /&gt;
select decode( type||&amp;#039;-&amp;#039;||to_char(line,&amp;#039;fm99999&amp;#039;), &amp;#039;PACKAGE BODY-1&amp;#039;, &amp;#039;/&amp;#039;||chr(10), null) ||&lt;br /&gt;
       decode(line,1,&amp;#039;create or replace &amp;#039;, &amp;#039;&amp;#039; ) ||&lt;br /&gt;
       text text&lt;br /&gt;
from   dba_source&lt;br /&gt;
where  owner = upper(&amp;#039;&amp;amp;owner&amp;#039;)&lt;br /&gt;
and    name  = upper(&amp;#039;&amp;amp;object_to_show&amp;#039;)&lt;br /&gt;
order  by type&lt;br /&gt;
,      line&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===A trick to exit out of SQL*Plus (using divide by zero) depending on answer to a question===&lt;br /&gt;
This example is taken from ReviewLite.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
-- Settings for customized functionality&lt;br /&gt;
define SCRIPT_OO=_OPTIONS_ONLY -- collect only options information&lt;br /&gt;
define SCRIPT_OO=&amp;#039;&amp;#039;            -- collect all information [default behavior]&lt;br /&gt;
&lt;br /&gt;
define SCRIPT_TS=_TIME_STAMP   -- include timestamp in names of the output directory and output files: YYYY.MM.DD.HH24.MI.SS; script does not prompt for license agreement&lt;br /&gt;
define SCRIPT_TS=&amp;#039;\home\oracle\options&amp;#039;            -- standard names for output directory and output files; script prompts for license agreement [default behavior]&lt;br /&gt;
&lt;br /&gt;
-- PROMT FOR LICENSE AGREEMENT ACCEPTANCE&lt;br /&gt;
DEFINE LANSWER=N&lt;br /&gt;
SET TERMOUT ON&lt;br /&gt;
ACCEPT &amp;amp;SCRIPT_TS LANSWER FORMAT A1 PROMPT &amp;#039;Accept License Agreement? (y\n): &amp;#039;&lt;br /&gt;
&lt;br /&gt;
-- FORCE &amp;quot;divisor is equal to zero&amp;quot; AND SQLERROR EXIT IF NOT ACCEPTED&lt;br /&gt;
-- WILL ALSO CONTINUE IF SCRIPT_TS SUBSTITUTION VARIABLE IS NOT NULL&lt;br /&gt;
SET TERMOUT OFF&lt;br /&gt;
WHENEVER SQLERROR EXIT&lt;br /&gt;
select 1/decode(&amp;#039; &amp;amp;LANSWER&amp;#039;, &amp;#039;Y&amp;#039;, null, &amp;#039;y&amp;#039;, null, decode(&amp;#039; &amp;amp;SCRIPT_TS&amp;#039;, null, 0, null)) as &amp;quot; &amp;quot; from dual;&lt;br /&gt;
WHENEVER SQLERROR CONTINUE&lt;br /&gt;
SET TERMOUT ON&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===How to uninstall optional components such as OWB, APEX, EM, OLAP, OWM from an Oracle database===&lt;br /&gt;
* [http://fast-dba.blogspot.be/2014/04/how-to-remove-unwanted-components-from.html fast-dba.blogspot.be]&lt;br /&gt;
&lt;br /&gt;
===Find unique indexes / primary index / key columns in a table===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
col owner       for a12&lt;br /&gt;
col table_name  for a32&lt;br /&gt;
col column_name for a32&lt;br /&gt;
col position    for 99&lt;br /&gt;
col status      for a10&lt;br /&gt;
set lines 1000 pages 100&lt;br /&gt;
&lt;br /&gt;
SELECT cons.owner&lt;br /&gt;
,      cols.table_name&lt;br /&gt;
,      cols.column_name&lt;br /&gt;
,      cols.position&lt;br /&gt;
,      cons.status&lt;br /&gt;
FROM   all_constraints  cons&lt;br /&gt;
,      all_cons_columns cols&lt;br /&gt;
WHERE  1=1&lt;br /&gt;
and    cols.owner           = &amp;#039;&amp;amp;TABLE_OWNER&amp;#039;&lt;br /&gt;
and    cols.table_name      = &amp;#039;&amp;amp;TABLE_NAME&amp;#039;&lt;br /&gt;
AND    cons.constraint_type = &amp;#039;P&amp;#039;&lt;br /&gt;
AND    cons.constraint_name = cols.constraint_name&lt;br /&gt;
AND    cons.owner           = cols.owner&lt;br /&gt;
ORDER  BY cols.table_name&lt;br /&gt;
,      cols.position&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Display the oracle instances running on the local server===&lt;br /&gt;
sed could be shorter but this one works cross-platform&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alias oenv=&amp;#039;ps -ef|grep pmon|grep -v grep|awk -F_ &amp;quot;{print \$NF}&amp;quot;|sort|uniq|sed -e &amp;quot;:a&amp;quot; -e &amp;quot;N&amp;quot; -e &amp;quot;\$!ba&amp;quot; -e &amp;quot;s/\n/ /g&amp;quot;&amp;#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Display which databases are scheduled for backup in cron===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
for i in `ps -ef | grep [o]ra_pmon | awk -F_ &amp;#039;{print $NF}&amp;#039;`; do&lt;br /&gt;
    crontab -l | grep $i | grep backup_export | awk &amp;#039;{print $2&amp;quot;:&amp;quot;$1&amp;quot; - &amp;quot;$17}&amp;#039;&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Trace SQL statements using autotrace and explain plan===&lt;br /&gt;
If the plustrace (plustrc.sql) role has been granted, explaining sql statements (without running the statement) is as easy as&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter session set sql_trace=true;&lt;br /&gt;
set autotrace traceonly explain&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Write to a trace log from PL/SQL===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
dbms_system.ksdwrt(1,&amp;#039;message sent to a trace file&amp;#039;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Invisible / hidden / virtual columns===&lt;br /&gt;
Article showing how to dump blocks also.&amp;lt;br /&amp;gt;&lt;br /&gt;
[https://www.oracle.com/technetwork/articles/database/invisible-columns-odb12c-2331522.html Tips and Tricks: Invisible Columns in Oracle Database 12c by Alex Zaballa, Oracle Ace and Daniel Da Meda (OCM)]&lt;br /&gt;
&lt;br /&gt;
===Write to the alert log from PL/SQL===&lt;br /&gt;
* [https://www.databasejournal.com/features/oracle/article.php/3386731/Inserting-Custom-Messages-in-Oracle-AlertTrace-files.htm Inserting Custom Messages in Oracle Alert/Trace files]&lt;br /&gt;
Writes to trace file&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
dbms_system.ksdwrt(1,&amp;#039;message sent to trace log&amp;#039;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Writes to the alertlog&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
dbms_system.ksdwrt(2,&amp;#039;message sent to the alertlog&amp;#039;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Writes to the alertlog and trace file&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
dbms_system.ksdwrt(3,&amp;#039;message sent to trace file and the alert log&amp;#039;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Also available, KSDIND, KSDDDT and KSDFLS&lt;br /&gt;
&lt;br /&gt;
===Do distributed SQL transactions exist?===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select * from dba_2pc_pending;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
if yes, and to commit them...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select local_tran_id from dba_2pc_pending;&lt;br /&gt;
exec dbms_transaction.purge_lost_db_entry(&amp;#039;&amp;#039;);&lt;br /&gt;
commit;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Setup optional parameters and default values in an SQL*Plus script===&lt;br /&gt;
Some forgotten SQL*Plus tricks from the good old days and some new ones...&lt;br /&gt;
* [http://www.orafaq.com/wiki/SQL*Plus_FAQ#What_is_the_difference_between_.21_and_HOST.3F orafaq.com]&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set termout off&lt;br /&gt;
col p1 new_value 1&lt;br /&gt;
col p2 new_value 2&lt;br /&gt;
col p3 new_value 3&lt;br /&gt;
select null p1, null p2, null p3 from dual where  1=2;&lt;br /&gt;
select nvl(&amp;#039;&amp;amp;1&amp;#039;,&amp;#039;def1&amp;#039;) p1, nvl(&amp;#039;&amp;amp;2&amp;#039;,&amp;#039;def2&amp;#039;) p2, nvl(&amp;#039;&amp;amp;3&amp;#039;,&amp;#039;def3&amp;#039;) p3 from dual;&lt;br /&gt;
set termout on&lt;br /&gt;
prompt 1=&amp;quot;&amp;amp;1&amp;quot;&lt;br /&gt;
prompt 2=&amp;quot;&amp;amp;2&amp;quot;&lt;br /&gt;
prompt 3=&amp;quot;&amp;amp;3&amp;quot;&lt;br /&gt;
undef 1&lt;br /&gt;
undef 2&lt;br /&gt;
undef 3&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Display / show users with sysdba &amp;amp; sysoper privileges===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select * from v$pwfile_users;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Show path names of data files using instr===&lt;br /&gt;
Use to find the pathnames of all the filesystems/directories in which a database is housed.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select distinct substr(name,1,(instr(name,&amp;#039;/&amp;#039;,-1,1)-1)) path_name from v$datafile&lt;br /&gt;
union&lt;br /&gt;
select distinct substr(name,1,(instr(name,&amp;#039;/&amp;#039;,-1,1)-1)) path_name from v$tempfile&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Does a dataguard standby exist for this database?===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SELECT SUBSTR(value,INSTR(value,&amp;#039;=&amp;#039;,INSTR(UPPER(value),&amp;#039;SERVICE&amp;#039;))+1)&lt;br /&gt;
FROM   v$parameter&lt;br /&gt;
WHERE  name LIKE &amp;#039;log_archive_dest%&amp;#039; AND UPPER(value) LIKE &amp;#039;SERVICE%&amp;#039;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
gives something like this if found...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SUBSTR(VALUE,INSTR(VALUE,&amp;#039;=&amp;#039;,INSTR(UPPER(VALUE),&amp;#039;SERVICE&amp;#039;))+1)&lt;br /&gt;
--------------------------------------------------------------------------------&lt;br /&gt;
&amp;quot;jdbeop1_standby&amp;quot;, LGWR ASYNC NOAFFIRM delay=0 optional compression=disable m&lt;br /&gt;
ax_failure=0 max_connections=1 reopen=300 db_unique_name=&amp;quot;jdbeop1_standby&amp;quot; ne&lt;br /&gt;
t_timeout=60, valid_for=(all_logfiles,primary_role)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===List values for all init parameters in v$parameter (including default values for undocumented (hidden) parameters===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select i.ksppinm||&amp;#039;;&amp;#039;||sv.ksppstvl&lt;br /&gt;
from   x$ksppi  i&lt;br /&gt;
,      x$ksppsv sv&lt;br /&gt;
where  i.indx = sv.indx&lt;br /&gt;
order  by i.ksppinm;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Log file reports pipe errors===&lt;br /&gt;
Found these in the log file&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
solax005:root[/opt/IBM/ITM/logs]# tail solax005_or_RMANV11_col.out&lt;br /&gt;
CIR1880E (024955) Open Probe pipe error 2. Pipe=/opt/IBM/ITM/tmp/solax005_or_RMANV11/prb_RMANV11_kor_solax005_30024832_5346_pipe&lt;br /&gt;
CIR1880E (030938) Open Probe pipe error 2. Pipe=/opt/IBM/ITM/tmp/solax005_or_RMANV11/prb_RMANV11_kor_solax005_30030830_5406_pipe&lt;br /&gt;
CIR1880E (031923) Open Probe pipe error 2. Pipe=/opt/IBM/ITM/tmp/solax005_or_RMANV11/prb_RMANV11_kor_solax005_30031832_5434_pipe&lt;br /&gt;
CIR1880E (033934) Open Probe pipe error 2. Pipe=/opt/IBM/ITM/tmp/solax005_or_RMANV11/prb_RMANV11_kor_solax005_30033831_5495_pipe&lt;br /&gt;
CIR1880E (034918) Open Probe pipe error 2. Pipe=/opt/IBM/ITM/tmp/solax005_or_RMANV11/prb_RMANV11_kor_solax005_30034833_5521_pipe&lt;br /&gt;
CIR1880E (041927) Open Probe pipe error 2. Pipe=/opt/IBM/ITM/tmp/solax005_or_RMANV11/prb_RMANV11_kor_solax005_30041835_5610_pipe&lt;br /&gt;
CIR1880E (042931) Open Probe pipe error 2. Pipe=/opt/IBM/ITM/tmp/solax005_or_RMANV11/prb_RMANV11_kor_solax005_30042832_5642_pipe&lt;br /&gt;
CIR1880E (045928) Open Probe pipe error 2. Pipe=/opt/IBM/ITM/tmp/solax005_or_RMANV11/prb_RMANV11_kor_solax005_30045835_5730_pipe&lt;br /&gt;
CIR1880E (052927) Open Probe pipe error 2. Pipe=/opt/IBM/ITM/tmp/solax005_or_RMANV11/prb_RMANV11_kor_solax005_30052838_5819_pipe&lt;br /&gt;
CIR1880E (090929) Open Probe pipe error 2. Pipe=/opt/IBM/ITM/tmp/solax005_or_RMANV11/prb_RMANV11_kor_solax005_30090833_6487_pipe&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This could be due to a timeout on the pipe.&amp;lt;br /&amp;gt;&lt;br /&gt;
Increase parameters and restart agent. Add following lines to or.config:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
export COLL_WAIT_TIMEOUT=&amp;#039;200&amp;#039;&lt;br /&gt;
export WAIT_TIMEOUT=&amp;#039;200&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Find the most recent archived SCN number===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
col next_change# for 999999999999999&lt;br /&gt;
set numwidth 15&lt;br /&gt;
&lt;br /&gt;
select max(next_change#)&lt;br /&gt;
from   v$archived_log&lt;br /&gt;
where  (thread#, next_change#) in ( select thread#, max(next_change#)&lt;br /&gt;
                                    from   v$archived_log&lt;br /&gt;
                                    where  archived     = &amp;#039;YES&amp;#039;&lt;br /&gt;
                                    and    status       = &amp;#039;A&amp;#039;&lt;br /&gt;
                                    and    resetlogs_id = ( select resetlogs_id&lt;br /&gt;
                                                            from   v$database_incarnation&lt;br /&gt;
                                                            where  status = &amp;#039;CURRENT&amp;#039;&lt;br /&gt;
                                                          )&lt;br /&gt;
                                    group by thread#&lt;br /&gt;
                                  )&lt;br /&gt;
and    status = &amp;#039;A&amp;#039;&lt;br /&gt;
and    resetlogs_id = ( select resetlogs_id&lt;br /&gt;
                        from   v$database_incarnation&lt;br /&gt;
                        where  status = &amp;#039;CURRENT&amp;#039;&lt;br /&gt;
                      )&lt;br /&gt;
order  by next_change# asc;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Monitoring says database inactive===&lt;br /&gt;
* Check the candle user password has not expired in the database.&lt;br /&gt;
* There may be a clue in the log file. Check /opt/IBM/ITM/logs/`hostname`_or_${SID}_col.out&lt;br /&gt;
* Check limits for itmora account in /etc/security/limits. Should be same as oracle user.&lt;br /&gt;
* Check the config file. We had this issue when a new ORACLE_HOME was installed but the cfg file still had the old one in it.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
export ITM_HOME=/opt/IBM/ITM&lt;br /&gt;
cd $ITM_HOME/config&lt;br /&gt;
vi solax005_or_SRV2R.cfg&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#  IBM Tivoli Monitoring for Databases: Oracle Agent&lt;br /&gt;
#  Configuration file: solax005_or_SRV2R.cfg&lt;br /&gt;
#  Written by CandleDBconfig version: 1.4 on 31Jul13 13:39:41&lt;br /&gt;
&lt;br /&gt;
#  Note: this is a Korn-shell script that is &amp;quot;sourced&amp;quot; to create the&lt;br /&gt;
#  environment for a Monitoring Agent for Oracle.  It can be used to create&lt;br /&gt;
#  the environment to run the IBM-supplied database grant scripts.&lt;br /&gt;
&lt;br /&gt;
#  IBM does not recommend that you modify this file, but you can change the&lt;br /&gt;
#  data values or add new exported variables as long as the file is a valid ksh&lt;br /&gt;
#  script that executes with zero return code, and values remain quoted with &amp;quot;&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
#  Following environment variables are set for convenience in running grants.&lt;br /&gt;
   export ORACLE_SID=&amp;quot;SRV2R&amp;quot;&lt;br /&gt;
   export ORACLE_HOME=&amp;quot;/oracle/product/11.2.0.1&amp;quot;&lt;br /&gt;
   # IY92195  COLL_DISABLE_CURSORS setting&lt;br /&gt;
   export TNS_ADMIN=&amp;quot;/oracle/product/11.2.0.1/network/admin&amp;quot;&lt;br /&gt;
&lt;br /&gt;
#  Following variables are set for the setup scripts&lt;br /&gt;
   db_sid=&amp;quot;SRV2R&amp;quot;&lt;br /&gt;
   db_home=&amp;quot;/oracle/product/11.2.0.1&amp;quot;&lt;br /&gt;
   db_initfilename=&amp;quot;&amp;quot;&lt;br /&gt;
   db_login=&amp;quot;tivoli&amp;quot;&lt;br /&gt;
   db_password=&amp;quot;795D8822BC49477323815CD21C1E66E966E48EEE19C6A98056224D649B0FE316E6A11DC3F4E9BB5E226B65A8&amp;quot;&lt;br /&gt;
   db_ver=&amp;quot;11.x&amp;quot;&lt;br /&gt;
   db_type=&amp;quot;kor&amp;quot;&lt;br /&gt;
   db_tns=&amp;quot;/oracle/product/11.2.0.1/network/admin&amp;quot;&lt;br /&gt;
   db_extparms=&amp;quot;&amp;quot;&lt;br /&gt;
   db_hostname=&amp;quot;solax005&amp;quot;&lt;br /&gt;
   db_reason=&amp;quot;AIX_ps_ceww&amp;quot;&lt;br /&gt;
   db_pipedir=&amp;quot;&amp;quot;&lt;br /&gt;
   db_installstatus=&amp;quot;CONFIGSUCCESS&amp;quot;&lt;br /&gt;
&lt;br /&gt;
#  User-defined environment variables&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Solution:&amp;lt;br /&amp;gt;&lt;br /&gt;
* Change all occurrences of 11.2.0.1 to 11.2.0.3&lt;br /&gt;
* Restart agent&lt;br /&gt;
&lt;br /&gt;
===Alerts due to password expiring (or being changed in the database but not in ITM!)===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cd $ITM_HOME/logs&lt;br /&gt;
ls -altr | grep WM820T&lt;br /&gt;
tail -20 solax005_or_WM820T_col.out&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
CGN1521E (161614) Interval collection failed for cursor KORHART2&lt;br /&gt;
RCD0110S (161614) Invalid Oracle logon id (tivoli) or password given&lt;br /&gt;
 Please contact DBA to correct userid or password&lt;br /&gt;
CGN1521E (161614) Interval collection failed for cursor KORHART4&lt;br /&gt;
CGN1525E (161614) One or more interval cursors failed&lt;br /&gt;
RCD0110S (161714) Invalid Oracle logon id (tivoli) or password given&lt;br /&gt;
 Please contact DBA to correct userid or password&lt;br /&gt;
CGN1521E (161714) Interval collection failed for cursor KORHART2&lt;br /&gt;
RCD0110S (161714) Invalid Oracle logon id (tivoli) or password given&lt;br /&gt;
 Please contact DBA to correct userid or password&lt;br /&gt;
CGN1521E (161714) Interval collection failed for cursor KORHART4&lt;br /&gt;
CGN1525E (161714) One or more interval cursors failed&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Solution:&amp;lt;br /&amp;gt;&lt;br /&gt;
* Run agent reconfigure to setup the new password for the candle user (tivoli)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
export ITM_HOME=/opt/IBM/ITM&lt;br /&gt;
$ITM_HOME/bin/itmcmd config -A or&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Restart agent&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
export ITM_HOME=/opt/IBM/ITM&lt;br /&gt;
$ITM_HOME/smitools/scripts/StartAgent.sh restart or -o WM820T&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Many agents started with root user instead of itmora===&lt;br /&gt;
This can happen if the server is rebooted before the agents have been added to the itmora list using kdyedit / kciedit&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
export CANDLEHOME=/opt/IBM/ITM&lt;br /&gt;
export ITM_HOME=/opt/IBM/ITM&lt;br /&gt;
$ITM_HOME/smitools/scripts/kdyedit list&lt;br /&gt;
Type Runas      Inst                &lt;br /&gt;
or   root       AGPDEV              &lt;br /&gt;
or   root       BO1R                &lt;br /&gt;
or   root       DEV3                &lt;br /&gt;
or   root       EMREP               &lt;br /&gt;
or   root       ICR                 &lt;br /&gt;
or   itmora     MAPDEV              &lt;br /&gt;
or   itmora     MAPER               &lt;br /&gt;
or   itmora     PED                 &lt;br /&gt;
or   itmora     PER                 &lt;br /&gt;
or   itmora     RMANV11             &lt;br /&gt;
or   itmora     SRV2R               &lt;br /&gt;
or   itmora     WM820Q              &lt;br /&gt;
or   itmora     WM820T              &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ITM_HOME/smitools/scripts/kciedit list&lt;br /&gt;
Type Runas      Inst                &lt;br /&gt;
or   root       AGPDEV              &lt;br /&gt;
or   root       BO1R                &lt;br /&gt;
or   root       DEV3                &lt;br /&gt;
or   root       EMREP               &lt;br /&gt;
or   root       ICR                 &lt;br /&gt;
or   itmora     MAPDEV              &lt;br /&gt;
or   itmora     MAPER               &lt;br /&gt;
or   itmora     PED                 &lt;br /&gt;
or   itmora     PER                 &lt;br /&gt;
or   itmora     RMANV11             &lt;br /&gt;
or   itmora     SRV2R               &lt;br /&gt;
or   itmora     WM820Q              &lt;br /&gt;
or   itmora     WM820T              &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Solution: Add these instances to the itmora list&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
./kdyedit -t or -i AGPDEV -r itmora add&lt;br /&gt;
./kciedit -t or -i AGPDEV -r itmora add&lt;br /&gt;
...&lt;br /&gt;
./kdyedit -t or -i ICR -r itmora add&lt;br /&gt;
./kciedit -t or -i ICR -r itmora add&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ITM_HOME/smitools/scripts/kciedit list&lt;br /&gt;
Type Runas      Inst                &lt;br /&gt;
or   itmora     AGPDEV              &lt;br /&gt;
or   itmora     BO1R                &lt;br /&gt;
or   itmora     DEV3                &lt;br /&gt;
or   itmora     EMREP               &lt;br /&gt;
or   itmora     ICR                 &lt;br /&gt;
or   itmora     MAPDEV              &lt;br /&gt;
or   itmora     MAPER               &lt;br /&gt;
or   itmora     PED                 &lt;br /&gt;
or   itmora     PER                 &lt;br /&gt;
or   itmora     RMANV11             &lt;br /&gt;
or   itmora     SRV2R               &lt;br /&gt;
or   itmora     WM820Q              &lt;br /&gt;
or   itmora     WM820T              &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Kill any agents still running as root&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ps -ef |grep kor | grep root&lt;br /&gt;
kill -9 &amp;lt;process id&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Because these agents were owned by root, there will be permissions issues when trying to restart the agents with itmora so these need to be fixed before restarting the agents.&amp;lt;br /&amp;gt;&lt;br /&gt;
The simplest way of doing this is to run lockdown.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
export CANDLEHOME=/opt/IBM/ITM&lt;br /&gt;
$CANDLEHOME/smitools/scripts/lockdown.sh&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===See which processes are causing paging===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
svmon -Pt20 | perl -e &amp;#039;while(&amp;lt;&amp;gt;){print if($.==2||$&amp;amp;&amp;amp;&amp;amp;!$s++);$.=0 if(/^-+$/)}&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===How to return several variables from SQL*Plus back to Korn shell script===&lt;br /&gt;
Return multiple columns/elements from Oracle to shell script at the same time&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sqlplus -s sys/${SYS_PASSWORD}@${SID} as sysdba&amp;lt;&amp;lt;EOSQL | read SPACE_AFTER_INSTALL TOTAL_SPACE_AVAILABLE&lt;br /&gt;
set numwid 15 headi off newpa none feedb off&lt;br /&gt;
select sign(${SPACE_USED} + ${SPACE_AVAILABLE} - ${DATABASE_SIZE}), trim(${SPACE_USED} + ${SPACE_AVAILABLE})&lt;br /&gt;
from dual&lt;br /&gt;
/&lt;br /&gt;
EOSQL&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===How to get a shell environment variable from the operating system into the SQL or PL/SQL environment===&lt;br /&gt;
This has been bugging me for years. Something you would think simple... what is ORACLE_HOME? I know it&amp;#039;s a question mark at the SQL prompt but how to get it&amp;#039;s O/S value?&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
declare&lt;br /&gt;
    var1 varchar2(200);&lt;br /&gt;
begin&lt;br /&gt;
    dbms_system.get_env (&amp;#039;ORACLE_HOME&amp;#039;, var1);&lt;br /&gt;
    dbms_output.put_line (&amp;#039;ORACLE_HOME: &amp;#039;||var1);&lt;br /&gt;
end;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or in SQL*Plus&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
variable var1 varchar2(200);&lt;br /&gt;
exec dbms_system.get_env (&amp;#039;ORACLE_HOME&amp;#039;, :var1);&lt;br /&gt;
select :var1 from dual;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
That got me thinking... if this just gets stuff from the environment, it can fetch any exported variable?!?!&amp;lt;br /&amp;gt;&lt;br /&gt;
From the shell:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
export running_sids=`ps -ef | grep [p]mon | awk -F_ &amp;#039;{print $NF}&amp;#039;`&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
and now in SQL*Plus:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
variable sids varchar2(240);&lt;br /&gt;
exec dbms_system.get_env (&amp;#039;running_sids&amp;#039;, :sids);&lt;br /&gt;
select :sids from dual;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Wow!&lt;br /&gt;
&lt;br /&gt;
===How long/wide can a database name/sid be?===&lt;br /&gt;
Depends on where you look but taking the minimum here as &amp;quot;safe&amp;quot;, it should still be limited to 8 characters...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
col table_name for a30&lt;br /&gt;
col data_type  for a12&lt;br /&gt;
select table_name, data_type, data_length from dba_tab_columns where column_name = &amp;#039;DB_NAME&amp;#039;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This is 11gR2&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
TABLE_NAME                     DATA_TYPE    DATA_LENGTH&lt;br /&gt;
------------------------------ ------------ -----------&lt;br /&gt;
LOGMNRG_DICTIONARY$            VARCHAR2               9&lt;br /&gt;
SYS_FBA_CONTEXT_AUD            VARCHAR2             256&lt;br /&gt;
V_$LOGMNR_DICTIONARY           VARCHAR2               9&lt;br /&gt;
V_$LOGMNR_LOGS                 VARCHAR2               8&lt;br /&gt;
GV_$LOGMNR_DICTIONARY          VARCHAR2               9&lt;br /&gt;
GV_$LOGMNR_LOGS                VARCHAR2               8&lt;br /&gt;
V_$LOGMNR_LOGFILE              VARCHAR2               8&lt;br /&gt;
V_$LOGMNR_SESSION              VARCHAR2             128&lt;br /&gt;
GV_$LOGMNR_LOGFILE             VARCHAR2               8&lt;br /&gt;
GV_$LOGMNR_SESSION             VARCHAR2             128&lt;br /&gt;
GV_$ASM_CLIENT                 VARCHAR2               8&lt;br /&gt;
V_$ASM_CLIENT                  VARCHAR2               8&lt;br /&gt;
GV_$IOS_CLIENT                 VARCHAR2              64&lt;br /&gt;
V_$IOS_CLIENT                  VARCHAR2              64&lt;br /&gt;
DBA_PDB_HISTORY                VARCHAR2             128&lt;br /&gt;
CDB_PDB_HISTORY                VARCHAR2             128&lt;br /&gt;
SSCR_CAP$                      VARCHAR2            4000&lt;br /&gt;
SSCR_RES$                      VARCHAR2            4000&lt;br /&gt;
DBA_SSCR_CAPTURE               VARCHAR2            4000&lt;br /&gt;
CDB_SSCR_CAPTURE               VARCHAR2            4000&lt;br /&gt;
DBA_SSCR_RESTORE               VARCHAR2            4000&lt;br /&gt;
CDB_SSCR_RESTORE               VARCHAR2            4000&lt;br /&gt;
WRM$_DATABASE_INSTANCE         VARCHAR2               9&lt;br /&gt;
INT$DBA_HIST_DATABASE_INSTANCE VARCHAR2               9&lt;br /&gt;
DBA_HIST_DATABASE_INSTANCE     VARCHAR2               9&lt;br /&gt;
CDB_HIST_DATABASE_INSTANCE     VARCHAR2               9&lt;br /&gt;
LOGMNR_DICTIONARY$             VARCHAR2               9&lt;br /&gt;
&lt;br /&gt;
27 rows selected.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===What character set (characterset) was the database built with?===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
col name  for a40&lt;br /&gt;
col value for a60&lt;br /&gt;
select * from nls_database_parameters;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
col name   for a40&lt;br /&gt;
col value$ for a60&lt;br /&gt;
select name,value$ from props$ where name = &amp;#039;NLS_CHARACTERSET&amp;#039;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===How to find ORACLE_HOME from pmon process for a SID if there is no entry in oratab===&lt;br /&gt;
If database is created without dbca (datafile and controlfile copy), no entry will be automatically made in /etc/oratab.&amp;lt;br /&amp;gt;&lt;br /&gt;
So the problem is that you need to find out which of the ORACLE_HOMEs is being used by the running instances.&lt;br /&gt;
* Solaris, Linux&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ ps -ef | grep [p]mon&lt;br /&gt;
  oracle 10848     1   0 00:21:20 ?           2:11 ora_pmon_JDBEOP1&lt;br /&gt;
$ pwdx 10848&lt;br /&gt;
10848:  /oracle/JDBEOP1/product/11204/dbs&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* AIX&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ ps -ef | grep [p]mon&lt;br /&gt;
  oracle 13893878        1   0   Aug 12      -  7:53 ora_pmon_GOAQ1&lt;br /&gt;
$ ls -al /proc/13893878/cwd&lt;br /&gt;
lr-x------    2 oracle   dba               0 Aug 12 13:37  cwd -&amp;gt; /data/opt/app/product/11.2.0.4/db_1/dbs/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or&amp;lt;br /&amp;gt;&lt;br /&gt;
This command (ps eww) gives lots of information about the given process (pmon in this case). Tells you where the instance was started, whether it was started from SQL*Plus or RMAN, the http_proxy and loads more useful bits!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ps -ef | grep [p]mon | awk &amp;#039;{print $2}&amp;#039; | xargs -I {} ps eww {} | awk &amp;#039;{print $1 &amp;quot; &amp;quot; $5 &amp;quot; &amp;quot; $6 &amp;quot; &amp;quot; $0}&amp;#039; | sed &amp;#039;s/\(S*\) \(S*\) .*ORACLE_HOME/\1 \2/g&amp;#039; | cut -f1,2,3 -d&amp;quot; &amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Escape the underscore(_) or percent(%) character in an SQL statement===&lt;br /&gt;
The underscore matches any single character so to return data containing an underscore means having to use an escape character.&amp;lt;br /&amp;gt;&lt;br /&gt;
Here I use the backslash(\) so it is easy for Unix people to understand the mechanism.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select username from dba_users where username like &amp;#039;ENDUR\_DEV%&amp;#039; escape &amp;#039;\&amp;#039;; &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Validate, analyse and rebuild indexes===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set feedback off&lt;br /&gt;
set linesize 132&lt;br /&gt;
set serveroutput on&lt;br /&gt;
set trimspool on&lt;br /&gt;
&lt;br /&gt;
declare&lt;br /&gt;
    LOCKED exception;&lt;br /&gt;
    pragma exception_init (LOCKED, -54);&lt;br /&gt;
&lt;br /&gt;
    dbase         char(8);&lt;br /&gt;
    dbuser        varchar2(30);&lt;br /&gt;
    index_name    varchar(30);&lt;br /&gt;
    free_text     varchar2(50);&lt;br /&gt;
    pctused       number;&lt;br /&gt;
    height    number;&lt;br /&gt;
    index_mb      number;&lt;br /&gt;
    analyze_sql   varchar2(100);&lt;br /&gt;
    pct_used_sql  varchar2(150);&lt;br /&gt;
    rebuild_sql   varchar2(150);&lt;br /&gt;
 &lt;br /&gt;
    cursor c1 is&lt;br /&gt;
    select segment_name, bytes&lt;br /&gt;
    from   user_segments&lt;br /&gt;
    where  segment_type = &amp;#039;INDEX&amp;#039;&lt;br /&gt;
    and    segment_name like &amp;#039;DW%&amp;#039;&lt;br /&gt;
    and    segment_name not like &amp;#039;BIN%&amp;#039;&lt;br /&gt;
    and    bytes/1024   &amp;gt;= 1024&lt;br /&gt;
    order  by 2;&lt;br /&gt;
&lt;br /&gt;
-- validate the index&lt;br /&gt;
procedure validate_index (v_ind in varchar2) is&lt;br /&gt;
begin&lt;br /&gt;
    analyze_sql := &amp;#039;analyze index &amp;#039;||v_ind||&amp;#039; validate structure&amp;#039;;&lt;br /&gt;
    begin&lt;br /&gt;
        execute immediate analyze_sql;&lt;br /&gt;
    exception&lt;br /&gt;
    when LOCKED then&lt;br /&gt;
        dbms_output.put_line (v_ind||&amp;#039; locked - skipping&amp;#039;);&lt;br /&gt;
        pctused := 100;&lt;br /&gt;
        return;&lt;br /&gt;
    when others then&lt;br /&gt;
        dbms_output.put_line (analyze_sql);&lt;br /&gt;
        raise;&lt;br /&gt;
    end;&lt;br /&gt;
&lt;br /&gt;
    pct_used_sql := &amp;#039;select pct_used, round(blocks*8192/(1024*1024)), height from index_stats where name = &amp;#039;&amp;#039;&amp;#039;||v_ind||&amp;#039;&amp;#039;&amp;#039;&amp;#039;;&lt;br /&gt;
    execute immediate pct_used_sql into pctused, index_mb, height;&lt;br /&gt;
    if pctused is null then&lt;br /&gt;
        pctused := 0;&lt;br /&gt;
    end if;&lt;br /&gt;
    dbms_output.put_line (rpad(v_ind,35)||&amp;#039; (pct used &amp;#039;||pctused||&amp;#039;% size &amp;#039;||index_mb||&amp;#039;Mb height &amp;#039; || height ||&amp;#039;)&amp;#039;);&lt;br /&gt;
end validate_index;&lt;br /&gt;
 &lt;br /&gt;
-- execute SQL and trace if errors&lt;br /&gt;
procedure run_sql (v_sql in varchar2) is&lt;br /&gt;
begin&lt;br /&gt;
    execute immediate v_sql;&lt;br /&gt;
exception&lt;br /&gt;
when others then&lt;br /&gt;
    dbms_output.put_line (v_sql);&lt;br /&gt;
    raise;&lt;br /&gt;
end run_sql;&lt;br /&gt;
 &lt;br /&gt;
--&lt;br /&gt;
-- Script starts here&lt;br /&gt;
--&lt;br /&gt;
begin&lt;br /&gt;
    dbms_output.enable(1000000);&lt;br /&gt;
    -- Set up database name and schema&lt;br /&gt;
    -- select name into dbase  from v$database;&lt;br /&gt;
    select user into dbuser from dual;&lt;br /&gt;
    dbms_output.put_line(&amp;#039;============================================================================= *&amp;#039;);&lt;br /&gt;
    -- dbms_output.put_line(&amp;#039;* Indexes rebuild report for &amp;#039;||dbuser||&amp;#039; on &amp;#039;||dbase);&lt;br /&gt;
    dbms_output.put_line(&amp;#039;============================================================================= *&amp;#039;);&lt;br /&gt;
&lt;br /&gt;
    -- Loop around Indexes&lt;br /&gt;
    for x in c1 loop&lt;br /&gt;
        index_name := x.segment_name;&lt;br /&gt;
        validate_index (index_name );&lt;br /&gt;
        if pctused &amp;lt; 81 then&lt;br /&gt;
            if x.bytes/1024/1024 &amp;lt; 100 then&lt;br /&gt;
                rebuild_sql := &amp;#039;alter index &amp;#039;||x.segment_name||&amp;#039; rebuild online&amp;#039;;&lt;br /&gt;
            else&lt;br /&gt;
                rebuild_sql := &amp;#039;alter index &amp;#039;||x.segment_name||&amp;#039; coalesce&amp;#039;;&lt;br /&gt;
            end if;&lt;br /&gt;
            dbms_output.put_line (rebuild_sql);&lt;br /&gt;
            run_sql (rebuild_sql);&lt;br /&gt;
            validate_index (index_name);&lt;br /&gt;
        end if;&lt;br /&gt;
    end loop;&lt;br /&gt;
end;&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
set feed on&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Rebuild unusable indexes on a table===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select &amp;#039;alter index &amp;#039;||owner||&amp;#039;.&amp;#039;||index_name||&amp;#039; rebuild;&amp;#039;&lt;br /&gt;
from   dba_indexes&lt;br /&gt;
where  1=1&lt;br /&gt;
and    status    != &amp;#039;VALID&amp;#039;&lt;br /&gt;
and    owner     not in (&amp;#039;SYS&amp;#039;,&amp;#039;SYSTEM&amp;#039;)&lt;br /&gt;
--and    owner      = &amp;#039;WM822PP&amp;#039;&lt;br /&gt;
--and    table_name = &amp;#039;WF_PLANTS&amp;#039;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Pull the latest cfengine changes now instead of waiting for scheduled time===&lt;br /&gt;
For one host&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/opt/cfengine/bin/cfagent -ID dbaTime&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
On all hosts at the same time&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/home/ibmtools/scripts/oracle/dosh -c &amp;quot;/opt/cfengine/bin/cfagent -ID dbaTime&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Check status of datafiles without dba_data_files or v$datafile===&lt;br /&gt;
If the database is in mount mode, most tables are unavailable. This query uses the x$ (c based) tables and are always available&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set linesize 200;&lt;br /&gt;
set pagesize 100;&lt;br /&gt;
col inst_id for 9999999 heading &amp;#039;Instance #&amp;#039;&lt;br /&gt;
col file_nr for 9999999 heading &amp;#039;File #&amp;#039;&lt;br /&gt;
col file_name for A50 heading &amp;#039;File name&amp;#039;&lt;br /&gt;
col checkpoint_change_nr for 99999999999999 heading &amp;#039;Checkpoint #&amp;#039;&lt;br /&gt;
col checkpoint_change_time for A20 heading &amp;#039;Checkpoint time&amp;#039;&lt;br /&gt;
col last_change_nr for 99999999999999 heading &amp;#039;Last change #&amp;#039;&lt;br /&gt;
SELECT&lt;br /&gt;
      fe.inst_id,&lt;br /&gt;
      fe.fenum file_nr,&lt;br /&gt;
      fn.fnnam file_name,&lt;br /&gt;
      TO_NUMBER (fe.fecps) checkpoint_change_nr,&lt;br /&gt;
      fe.fecpt checkpoint_change_time,&lt;br /&gt;
      fe.fests last_change_nr,&lt;br /&gt;
      DECODE (&lt;br /&gt;
              fe.fetsn,&lt;br /&gt;
              0, DECODE (BITAND (fe.festa, 2), 0, &amp;#039;SYSOFF&amp;#039;, &amp;#039;SYSTEM&amp;#039;),&lt;br /&gt;
              DECODE (BITAND (fe.festa, 18),&lt;br /&gt;
                      0, &amp;#039;OFFLINE&amp;#039;,&lt;br /&gt;
                      2, &amp;#039;ONLINE&amp;#039;,&lt;br /&gt;
                      &amp;#039;RECOVER&amp;#039;)&lt;br /&gt;
      ) status&lt;br /&gt;
FROM x$kccfe fe,&lt;br /&gt;
     x$kccfn fn&lt;br /&gt;
WHERE    (   (fe.fepax != 65535 AND fe.fepax != 0 )&lt;br /&gt;
          OR (fe.fepax = 65535 OR fe.fepax = 0)&lt;br /&gt;
         )&lt;br /&gt;
     AND fn.fnfno = fe.fenum&lt;br /&gt;
     AND fe.fefnh = fn.fnnum&lt;br /&gt;
     AND fe.fedup != 0&lt;br /&gt;
     AND fn.fntyp = 4&lt;br /&gt;
     AND fn.fnnam IS NOT NULL&lt;br /&gt;
     AND BITAND (fn.fnflg, 4) != 4&lt;br /&gt;
ORDER BY fe.fenum&lt;br /&gt;
;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Check highest allocated extent in datafile (likely slow when having many extents)===&lt;br /&gt;
* Script to Detect Tablespace Fragmentation ( Doc ID 1020182.6 )&lt;br /&gt;
* How to shrink or reduce the datafile size by finding the high water mark (HWM) ( Doc ID 1600774.1 )&lt;br /&gt;
* How to find Objects Fragmented below High Water Mark ( Doc ID 337651.1 )&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
column file_name format a50;&lt;br /&gt;
column tablespace_name format a15;&lt;br /&gt;
column highwater format 9999999999;&lt;br /&gt;
set pagesize 9999&lt;br /&gt;
&lt;br /&gt;
select a.tablespace_name&lt;br /&gt;
,a.file_name&lt;br /&gt;
,(b.maximum+c.blocks-1)*d.db_block_size highwater&lt;br /&gt;
from dba_data_files a&lt;br /&gt;
,(select file_id,max(block_id) maximum&lt;br /&gt;
from dba_extents&lt;br /&gt;
group by file_id) b&lt;br /&gt;
,dba_extents c&lt;br /&gt;
,(select value db_block_size&lt;br /&gt;
from v$parameter&lt;br /&gt;
where name=&amp;#039;db_block_size&amp;#039;) d&lt;br /&gt;
where a.file_id = b.file_id&lt;br /&gt;
and c.file_id = b.file_id&lt;br /&gt;
and c.block_id = b.maximum&lt;br /&gt;
order by a.tablespace_name,a.file_name&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Runup to this was...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set markup html on spool on&lt;br /&gt;
spool db_info.html&lt;br /&gt;
set echo on&lt;br /&gt;
select * from dba_tablespaces where tablespace_name = &amp;#039;&amp;amp;&amp;amp;tablespace_name&amp;#039;;&lt;br /&gt;
select * from dba_data_files where tablespace_name = &amp;#039;&amp;amp;tablespace_name&amp;#039;;&lt;br /&gt;
select * from (select * from dba_extents where tablespace_name = &amp;#039;&amp;amp;tablespace_name&amp;#039; order by block_id desc) where rownum &amp;lt;301;&lt;br /&gt;
spool off&lt;br /&gt;
set markup html off&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select owner, segment_type, count(*) from dba_segments where tablesapce_name=&amp;#039;&amp;amp;tablespace_name&amp;#039; group by owner, segment_type;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
begin&lt;br /&gt;
for ii in (select owner, segment_name, segment_type from dba_segments where tablespace_name = &amp;#039;&amp;amp;tablespace_name&amp;#039; and segment_type like &amp;#039;TABLE%&amp;#039; and segment_name not like &amp;#039;%DATAPUMP%&amp;#039;)&lt;br /&gt;
loop&lt;br /&gt;
if ii.segment_type=&amp;#039;TABLE&amp;#039; then&lt;br /&gt;
begin&lt;br /&gt;
execute immediate(&amp;#039;alter table &amp;#039;||ii.owner||&amp;#039;.&amp;#039;||ii.segment_name||&amp;#039; enable row movement&amp;#039;);&lt;br /&gt;
execute immediate(&amp;#039;alter table &amp;#039;||ii.owner||&amp;#039;.&amp;#039;||ii.segment_name||&amp;#039; shrink space cascade&amp;#039;);&lt;br /&gt;
exception when others then&lt;br /&gt;
dbms_output.put_line(&amp;#039;FAILED 1: alter table &amp;#039;||ii.owner||&amp;#039;.&amp;#039;||ii.segment_name||&amp;#039; shrink space cascade : &amp;#039;||SQLERRM);&lt;br /&gt;
end;&lt;br /&gt;
end if;&lt;br /&gt;
end loop;&lt;br /&gt;
end;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Procedure to shrink space in tables and indexes===&lt;br /&gt;
* [http://www.oracle-wiki.net/startdocsreallifeshrinkexample Using the Oracle Shrink Command] - lots of good stuff at this site&lt;br /&gt;
Written by [https://asktom.oracle.com/pls/apex/f%3Fp%3D100:11:0::::P11_QUESTION_ID:5645095700346948864 Tom Kyte]&amp;lt;br /&amp;gt;&lt;br /&gt;
Depending on the Oracle version, this procedure may or may not work! It does not include the compact clause (neither does it re-analyse to prove it worked).&amp;lt;br /&amp;gt;&lt;br /&gt;
[http://www.oracle-wiki.net/startdocsreallifeshrinkexample Here] is a worked example that shows the complete process - oracle-wiki.net&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
create or replace procedure shrink_all&lt;br /&gt;
as&lt;br /&gt;
    l_sql        varchar2(4000);&lt;br /&gt;
    l_sql2       varchar2(4000);&lt;br /&gt;
    row_movement exception;&lt;br /&gt;
    pragma       exception_init( row_movement, -10636 );&lt;br /&gt;
begin&lt;br /&gt;
    for x in (select table_name&lt;br /&gt;
              ,      owner&lt;br /&gt;
              from   t&lt;br /&gt;
              where  sgm_space_management = &amp;#039;AUTO&amp;#039;)&lt;br /&gt;
    loop&lt;br /&gt;
        l_sql := &amp;#039;alter table &amp;quot;&amp;#039; || x.owner || &amp;#039;&amp;quot;.&amp;quot;&amp;#039; || x.table_name || &amp;#039;&amp;quot; shrink space&amp;#039;;&lt;br /&gt;
        dbms_output.put_line( l_sql );&lt;br /&gt;
&lt;br /&gt;
        begin&lt;br /&gt;
            execute immediate l_sql;&lt;br /&gt;
        exception&lt;br /&gt;
        when row_movement&lt;br /&gt;
        then&lt;br /&gt;
            dbms_output.put_line( &amp;#039;failed due to row movement...&amp;#039; );&lt;br /&gt;
            l_sql2 := &amp;#039;alter table &amp;quot;&amp;#039; || x.owner || &amp;#039;&amp;quot;.&amp;quot;&amp;#039; || x.table_name || &amp;#039;&amp;quot; enable row movement&amp;#039;;&lt;br /&gt;
            dbms_output.put_line( l_sql2 );&lt;br /&gt;
            execute immediate l_sql2;&lt;br /&gt;
            dbms_output.put_line( l_sql );&lt;br /&gt;
            execute immediate l_sql;&lt;br /&gt;
        end;&lt;br /&gt;
&lt;br /&gt;
        for y in (select owner&lt;br /&gt;
                  ,      index_name&lt;br /&gt;
                  from   dba_indexes&lt;br /&gt;
                  where  table_owner = x.owner&lt;br /&gt;
                  and    table_name  = x.table_name )&lt;br /&gt;
        loop&lt;br /&gt;
            l_sql := &amp;#039;alter index &amp;quot;&amp;#039; || y.owner || &amp;#039;&amp;quot;.&amp;quot;&amp;#039; || y.index_name || &amp;#039;&amp;quot; shrink space&amp;#039;;&lt;br /&gt;
            dbms_output.put_line( l_sql );&lt;br /&gt;
            execute immediate l_sql;&lt;br /&gt;
        end loop;&lt;br /&gt;
&lt;br /&gt;
    end loop;&lt;br /&gt;
end;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===How to delete/kill a distributed transaction===&lt;br /&gt;
From [http://www.pouwiel.com/?p=2204 pouwiel.com]&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SQL&amp;gt; SELECT LOCAL_TRAN_ID, GLOBAL_TRAN_ID,to_char(FAIL_TIME,&amp;#039;dd-mon-yyyy HH24:MI:SS&amp;#039;),STATE, MIXED FROM DBA_2PC_PENDING;&lt;br /&gt;
&lt;br /&gt;
LOCAL_TRAN_ID&lt;br /&gt;
----------------------&lt;br /&gt;
GLOBAL_TRAN_ID&lt;br /&gt;
--------------------------------------------------------------------------------&lt;br /&gt;
TO_CHAR(FAIL_TIME,&amp;#039;D STATE MIX&lt;br /&gt;
-------------------- ---------------- ---&lt;br /&gt;
8.19.321913&lt;br /&gt;
1463898948.0000013CDE8005110000000179F68840A089FFFEE644B640AED6B02438B2F39D9665F&lt;br /&gt;
AFB&lt;br /&gt;
15-feb-2013 16:37:41 prepared no&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
SQL&amp;gt; SELECT LOCAL_TRAN_ID, IN_OUT,INTERFACE, DATABASE FROM DBA_2PC_NEIGHBORS;&lt;br /&gt;
&lt;br /&gt;
LOCAL_TRAN_ID IN_ I&lt;br /&gt;
---------------------- --- -&lt;br /&gt;
DATABASE&lt;br /&gt;
--------------------------------------------------------------------------------&lt;br /&gt;
8.19.321913 in N&lt;br /&gt;
jdbc_11&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
SQL&amp;gt; rollback force &amp;#039;8.19.321913&amp;#039;;&lt;br /&gt;
&lt;br /&gt;
Rollback complete.&lt;br /&gt;
&lt;br /&gt;
SQL&amp;gt; execute dbms_transaction.purge_lost_db_entry(&amp;#039;8.19.321913&amp;#039;);&lt;br /&gt;
&lt;br /&gt;
PL/SQL procedure successfully completed.&lt;br /&gt;
&lt;br /&gt;
SQL&amp;gt; commit;&lt;br /&gt;
&lt;br /&gt;
Commit complete.&lt;br /&gt;
&lt;br /&gt;
SQL&amp;gt; SELECT LOCAL_TRAN_ID, GLOBAL_TRAN_ID,to_char(FAIL_TIME,&amp;#039;dd-mon-yyyy HH24:MI:SS&amp;#039;),STATE, MIXED FROM DBA_2PC_PENDING;&lt;br /&gt;
&lt;br /&gt;
no rows selected&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Be aware that the support document 159377.1 does not speak of the rollback force. If you don’t execute that particular command it will not work.&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORACLE_BASE is getting set to the same value as ORACLE_HOME when using . oraenv===&lt;br /&gt;
Permissions problem. Make sure the user has &amp;#039;&amp;#039;&amp;#039;write&amp;#039;&amp;#039;&amp;#039; access to oraclehomeproperties.xml file!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ls -al $ORACLE_HOME/inventory/ContentsXML/oraclehomeproperties.xml&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Change permissions as appropriate.&lt;br /&gt;
A different approach which should give the same end result would be to grant the orabase executable the setuid bit.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
chmod u+s $ORACLE_HOME/bin/orabase&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This allows any user to set the environment as the orabase executable will be run with the permissions of its owner.&lt;br /&gt;
===Move table partitions to a different tablespace===&lt;br /&gt;
Are you getting errors due to partitions belonging to a different tablespace and you want to drop the current tablepace?&amp;lt;br /&amp;gt;&lt;br /&gt;
ORA-14404: partitioned table contains partitions in a different tablespace&amp;lt;br /&amp;gt;&lt;br /&gt;
====Find tables with partitions in more than one tablespace====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 2000 pages 50&lt;br /&gt;
col table_owner for a30&lt;br /&gt;
col table_name for a30&lt;br /&gt;
select table_owner&lt;br /&gt;
 ,     table_name&lt;br /&gt;
,      count(*)&lt;br /&gt;
from   dba_tab_partitions&lt;br /&gt;
where  table_owner != &amp;#039;SYS&amp;#039;&lt;br /&gt;
group  by table_owner&lt;br /&gt;
,      table_name&lt;br /&gt;
having count(*) &amp;gt; 1&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
See which tables have partitions across multiple tablespaces...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 1000 pages 100&lt;br /&gt;
col table_name for a50&lt;br /&gt;
select distinct b.table_owner||&amp;#039;.&amp;#039;||b.table_name table_name&lt;br /&gt;
,      a.tablespace_name ts1&lt;br /&gt;
,      b.tablespace_name ts2&lt;br /&gt;
from   (&lt;br /&gt;
       select distinct tablespace_name&lt;br /&gt;
       ,      table_name&lt;br /&gt;
       ,      partition_name&lt;br /&gt;
       from   dba_tab_partitions&lt;br /&gt;
       )                  a&lt;br /&gt;
,      dba_tab_partitions b&lt;br /&gt;
where  a.table_name       = b.table_name&lt;br /&gt;
and    a.tablespace_name != b.tablespace_name&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Generate statements to move the partitions from one tablespace to another...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select &amp;#039;alter table &amp;#039;||b.table_owner||&amp;#039;.&amp;#039;||b.table_name||&amp;#039; move partition &amp;#039;||b.partition_name||&amp;#039; tablespace &amp;amp;NEW_TABLESPACE;&amp;#039;&lt;br /&gt;
from   (&lt;br /&gt;
       select distinct table_name&lt;br /&gt;
       ,      partition_name&lt;br /&gt;
       from   dba_tab_partitions&lt;br /&gt;
       where  tablespace_name = &amp;#039;&amp;amp;&amp;amp;OLD_TABLESPACE&amp;#039;&lt;br /&gt;
       )                  a&lt;br /&gt;
,      dba_tab_partitions b&lt;br /&gt;
where  a.table_name       = b.table_name&lt;br /&gt;
and    b.tablespace_name != &amp;#039;&amp;amp;OLD_TABLESPACE&amp;#039;&lt;br /&gt;
/&lt;br /&gt;
undef OLD_TABLESPACE&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====What&amp;#039;s left hanging around?====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
col SEGMENT_TYPE for a20&lt;br /&gt;
col OWNER for a20&lt;br /&gt;
col SEGMENT_NAME for a40&lt;br /&gt;
col PARTITION_NAME for a15&lt;br /&gt;
col TABLESPACE_NAME for a30&lt;br /&gt;
select segment_type&lt;br /&gt;
,      owner&lt;br /&gt;
,      segment_name&lt;br /&gt;
,      partition_name&lt;br /&gt;
,      tablespace_name&lt;br /&gt;
from   dba_segments&lt;br /&gt;
where  tablespace_name in (&amp;#039;TS_THALER_IOT_OLD&amp;#039;,&amp;#039;TS_THALER_CU&amp;#039;,&amp;#039;TS_THALER_BACKUP&amp;#039;,&amp;#039;TS_THALER_PART_OLD&amp;#039;)&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
select table_owner&lt;br /&gt;
,      table_name&lt;br /&gt;
from   dba_indexes&lt;br /&gt;
where  index_name = &amp;#039;&amp;amp;index_name&amp;#039;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===What edition is my database (Standard, Enterprise, XE...)?===&lt;br /&gt;
Only works from 12c :-(&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select edition from sys.registry$ where cid=&amp;#039;CATPROC&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Is database a CDB with PDBs?===&lt;br /&gt;
Needs a bit of work. Won&amp;#039;t work pre-12c obviously and also not on Standby databases if they are in MOUNT mode&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
for db in $(ps -ef | grep [p]mon|awk -F_ &amp;#039;{print $NF}&amp;#039;)&lt;br /&gt;
do&lt;br /&gt;
    export ORACLE_SID=${db}&lt;br /&gt;
    ORAENV_ASK=NO&lt;br /&gt;
    . oraenv &amp;gt;/dev/null 2&amp;gt;&amp;amp;1&lt;br /&gt;
    sqlplus -s / as sysdba&amp;lt;&amp;lt;&amp;#039;EOSQL&amp;#039;&lt;br /&gt;
set head off newpa none&lt;br /&gt;
select name&lt;br /&gt;
,      (select count(*) from v$pdbs) npdbs&lt;br /&gt;
from   v$database&lt;br /&gt;
/&lt;br /&gt;
EOSQL&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
version 2&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
function is_db_cdb return boolean&lt;br /&gt;
is&lt;br /&gt;
    b_is_cdb        boolean := false;&lt;br /&gt;
    l_is_cdb        varchar2(3) := &amp;#039;NO&amp;#039;;&lt;br /&gt;
    e_col_not_found exception;&lt;br /&gt;
    pragma          exception_init(e_col_not_found, -904);&lt;br /&gt;
begin&lt;br /&gt;
    begin&lt;br /&gt;
        execute immediate &amp;#039;select cdb from v$database&amp;#039; &lt;br /&gt;
        into l_is_cdb;&lt;br /&gt;
    exception&lt;br /&gt;
        when e_col_not_found then l_is_cdb := &amp;#039;NO&amp;#039;;  -- ORA-00904&lt;br /&gt;
    end;&lt;br /&gt;
&lt;br /&gt;
    if (l_is_cdb = &amp;#039;YES&amp;#039;) then&lt;br /&gt;
        return TRUE;&lt;br /&gt;
    else&lt;br /&gt;
        return FALSE;  -- either not a cdb or pre-12.1 database&lt;br /&gt;
    end if;&lt;br /&gt;
&lt;br /&gt;
end is_db_cdb;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===List triggers in the database===&lt;br /&gt;
This query specifically lists after login triggers &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select obj.con_id&lt;br /&gt;
,      pdb.name&lt;br /&gt;
,      obj.owner&lt;br /&gt;
,      obj.object_name&lt;br /&gt;
,      to_char(obj.created, &amp;#039;DD/MM/YYYY HH24:MI:SS&amp;#039;)       created_str&lt;br /&gt;
,      to_char(obj.last_ddl_time, &amp;#039;DD/MM/YYYY HH24:MI:SS&amp;#039;) last_ddl_str&lt;br /&gt;
from   cdb_objects   obj&lt;br /&gt;
join   cdb_triggers trgs&lt;br /&gt;
       on (   obj.con_id      = trgs.con_id&lt;br /&gt;
          and obj.owner       = trgs.owner&lt;br /&gt;
          and obj.object_name = trgs.trigger_name&lt;br /&gt;
          )&lt;br /&gt;
join   v$pdbs pdb&lt;br /&gt;
       on ( obj.con_id  = pdb.con_id )&lt;br /&gt;
where  trgs.trigger_type     = &amp;#039;AFTER EVENT&amp;#039;&lt;br /&gt;
and    trgs.triggering_event like &amp;#039;LOGON%&amp;#039;&lt;br /&gt;
and    trgs.status           = &amp;#039;ENABLED&amp;#039;&lt;br /&gt;
order  by object_name&lt;br /&gt;
,      obj.last_ddl_time&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===List the pluggable databases (PDB) in a container database (CDB)===&lt;br /&gt;
The network_name column shows what you should find in tnsnames.ora for this db connection&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select name,network_name,pdb from v$services;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select * from v$pdbs;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Start and stop a pluggable database===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter pluggable database pdb1 open;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter pluggable database pdb1 close immediate;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Swith to a pluggable database===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter session set container=pdb1;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Reopen pluggable databases at container startup===&lt;br /&gt;
By default pluggable databases in a container remain in a MOUNT state when the container starts up.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select name, open_mode from v$pdbs where name = &amp;#039;PDB1&amp;#039;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
To modify this, open it and save its state&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter pluggable database pdb1 open;&lt;br /&gt;
alter pluggable database pdb1 save state;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
To see a log of issues with pluggable databases&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select * from pdb_plug_in_violations where type = &amp;#039;ERROR&amp;#039; and status != &amp;#039;RESOLVED&amp;#039; and name = &amp;#039;PDB1&amp;#039;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===What is the current container id in a cdb?===&lt;br /&gt;
CDB$ROOT is container id 1. User containers start from 2.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select sys_context(&amp;#039;USERENV&amp;#039;,&amp;#039;CON_ID&amp;#039;) from dual&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===What is the current container name in a cdb?===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select sys_context(&amp;#039;USERENV&amp;#039;,&amp;#039;CON_NAME&amp;#039;) from dual&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or just&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
show con_name&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Switching Between Containers===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SQL&amp;gt; show con_name&lt;br /&gt;
&lt;br /&gt;
CON_NAME&lt;br /&gt;
------------------------------&lt;br /&gt;
CDB$ROOT&lt;br /&gt;
&lt;br /&gt;
SQL&amp;gt; alter session set container=tstklok;&lt;br /&gt;
&lt;br /&gt;
Session altered.&lt;br /&gt;
&lt;br /&gt;
SQL&amp;gt;  show con_name&lt;br /&gt;
&lt;br /&gt;
CON_NAME&lt;br /&gt;
------------------------------&lt;br /&gt;
TSTKLOK&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Direct connection to pluggable database===&lt;br /&gt;
These must be made using a service (defined in tnsnames.ora). Each pluggable database automatically registers a service with the listener (v$services).&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sqlplus appuser/apppwd@tstklok&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or using ezconnect&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SQL&amp;gt; conn appuser/apppwd@//localhost:1521/tstklok&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===What platform is the database running on?===&lt;br /&gt;
Could be useful for handling line endings...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select platform_name from v$database&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
if instr(db_platform, &amp;#039;WINDOWS&amp;#039;) != 0 then&lt;br /&gt;
    crlf := CHR(13) || CHR(10);       -- Windows gets the \r and \n&lt;br /&gt;
else&lt;br /&gt;
    crlf := CHR (10);                 -- Just \n for the rest of the world&lt;br /&gt;
end if;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Is the database 32 or 64 bit?===&lt;br /&gt;
If the answer is 1,7,10,15,16 or 17, then it is 32bit, everything else should be 64bit.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select platform_id from v$database&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===What features is my database using?===&lt;br /&gt;
Before converting to Standard Edition, check the features here - some may be Enterprise specific.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
col name for a45&lt;br /&gt;
col description for a85&lt;br /&gt;
set lines 2000&lt;br /&gt;
select name&lt;br /&gt;
,      detected_usages&lt;br /&gt;
,      description&lt;br /&gt;
from   dba_feature_usage_statistics&lt;br /&gt;
where  1=1&lt;br /&gt;
and    currently_used = &amp;#039;TRUE&amp;#039;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===How many redo log switches per hour?===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 100&lt;br /&gt;
col &amp;quot;YYYYMMDD HH24&amp;quot; for a14&lt;br /&gt;
select to_char(first_time,&amp;#039;yyyymmdd hh24&amp;#039;) &amp;quot;YYYYMMDD HH24&amp;quot;&lt;br /&gt;
,      count(1)                            num_switches&lt;br /&gt;
from   v$log_history&lt;br /&gt;
group  by to_char(first_time,&amp;#039;yyyymmdd hh24&amp;#039;)&lt;br /&gt;
order  by 1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or a bit fancier version...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rem *********************************************************** &lt;br /&gt;
rem&lt;br /&gt;
rem	File: log_history.sql &lt;br /&gt;
rem	Description: Log switch rates from v$log_history &lt;br /&gt;
rem   &lt;br /&gt;
rem	From &amp;#039;Oracle Performance Survival Guide&amp;#039; by Guy Harrison&lt;br /&gt;
rem		Chapter 21 Page 637&lt;br /&gt;
rem		ISBN: 978-0137011957&lt;br /&gt;
rem		See www.guyharrison.net for further information&lt;br /&gt;
rem  &lt;br /&gt;
rem		This work is in the public domain NSA &lt;br /&gt;
rem   &lt;br /&gt;
rem&lt;br /&gt;
rem ********************************************************* &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
col min_minutes format 9999.99 &lt;br /&gt;
col max_minutes format 9999.99 &lt;br /&gt;
col avg_minutes format 9999.99 &lt;br /&gt;
set pagesize 1000&lt;br /&gt;
set lines 70&lt;br /&gt;
set echo on &lt;br /&gt;
&lt;br /&gt;
WITH log_history AS&lt;br /&gt;
       (SELECT thread#, first_time,&lt;br /&gt;
               LAG(first_time) OVER (ORDER BY thread#, sequence#)&lt;br /&gt;
                  last_first_time,&lt;br /&gt;
               (first_time&lt;br /&gt;
                - LAG(first_time) OVER (ORDER BY thread#, sequence#))&lt;br /&gt;
                    * 24* 60   last_log_time_minutes,&lt;br /&gt;
               LAG(thread#) OVER (ORDER BY thread#, sequence#)&lt;br /&gt;
                   last_thread#&lt;br /&gt;
        FROM v$log_history)&lt;br /&gt;
SELECT ROUND(MIN(last_log_time_minutes), 2) min_minutes,&lt;br /&gt;
       ROUND(MAX(last_log_time_minutes), 2) max_minutes,&lt;br /&gt;
       ROUND(AVG(last_log_time_minutes), 2) avg_minutes&lt;br /&gt;
FROM log_history&lt;br /&gt;
WHERE     last_first_time IS NOT NULL&lt;br /&gt;
      AND last_thread# = thread#&lt;br /&gt;
      AND first_time &amp;gt; SYSDATE - 1; &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Show redo log groups/members===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
col instance       for a8&lt;br /&gt;
col thread         for 999&lt;br /&gt;
col groupno        for 999&lt;br /&gt;
col member         for a35&lt;br /&gt;
col redo_file_type for a15&lt;br /&gt;
col log_status     for a10&lt;br /&gt;
col logsize_m      for 99999&lt;br /&gt;
col archived       for a12&lt;br /&gt;
&lt;br /&gt;
SELECT i.instance_name   instance&lt;br /&gt;
,      i.thread#         thread&lt;br /&gt;
,      f.group#          groupno&lt;br /&gt;
,      f.member          member&lt;br /&gt;
,      f.type            redo_file_type&lt;br /&gt;
,      l.status          log_status&lt;br /&gt;
,      l.bytes/1024/1024 logsize_m&lt;br /&gt;
,      l.archived        archived&lt;br /&gt;
FROM   gv$logfile  f&lt;br /&gt;
,      gv$log      l&lt;br /&gt;
,      gv$instance i&lt;br /&gt;
WHERE  1=1&lt;br /&gt;
and    f.group#  = l.group#&lt;br /&gt;
AND    l.thread# = i.thread#&lt;br /&gt;
AND    i.inst_id = f.inst_id&lt;br /&gt;
AND    f.inst_id = l.inst_id&lt;br /&gt;
ORDER  BY i.instance_name&lt;br /&gt;
,      f.group#&lt;br /&gt;
,      f.member;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Korn shell timestamp function===&lt;br /&gt;
Example usage: echo &amp;quot;`ts`: Checking backup status&amp;quot;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
function ts {&lt;br /&gt;
    date +&amp;#039;%d-%b-%Y %H:%M:%S&amp;#039;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Drop a database===&lt;br /&gt;
Dropping a database including backups should be considered criminal in a production environment!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sqlplus / as sysdba&lt;br /&gt;
startup force mount exclusive restrict&lt;br /&gt;
exit&lt;br /&gt;
rman target /&lt;br /&gt;
drop database including backups noprompt;&lt;br /&gt;
exit&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
RMAN&amp;gt; connect target sys/pass@test&lt;br /&gt;
connected to target database: test (dbid=123456789)&lt;br /&gt;
&lt;br /&gt;
RMAN&amp;gt; startup force mount&lt;br /&gt;
RMAN&amp;gt; sql &amp;#039;alter system enable restricted session&amp;#039;;&lt;br /&gt;
RMAN&amp;gt; drop database including backups noprompt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Use sub-select or in-line views to update base tables===&lt;br /&gt;
Inline views can be used to update base table data&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
update&lt;br /&gt;
    (&lt;br /&gt;
    select p.list_price&lt;br /&gt;
    from   products           p&lt;br /&gt;
    ,      product_categories pc&lt;br /&gt;
    where  1=1&lt;br /&gt;
    and    p.category_id    = pc.category_id&lt;br /&gt;
    and    pc.category_name = &amp;#039;CPU&amp;#039;&lt;br /&gt;
    )&lt;br /&gt;
set list_price = list_price * 1.15; &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Use sub-select or in-line views to delete base table data===&lt;br /&gt;
A different way to delete rows in base tables, using Inline views or subselect&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
delete&lt;br /&gt;
    (&lt;br /&gt;
    select p.list_price&lt;br /&gt;
    from   products           p&lt;br /&gt;
    ,      product_categories pc&lt;br /&gt;
    where  1=1&lt;br /&gt;
    and    p.category_id    = pc.category_id&lt;br /&gt;
    and    pc.category_name = &amp;#039;CPU&amp;#039;&lt;br /&gt;
    )&lt;br /&gt;
where list_price &amp;lt; 1000; &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Mass update of files using perl inline script===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
for server in `cat /home/tools/etc/oracle/oracle_servers`; do&lt;br /&gt;
    ssh $server “perl -p -i -e &amp;#039;s/T01/D01/&amp;#039; /home/tools/scripts/rman/inclexcl.lst”&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===How to use vi-style editing in SQL*Plus===&lt;br /&gt;
These instructions are for Redhat but other versions will be very similar&lt;br /&gt;
* Download rlwrap from [http://dl.fedoraproject.org/pub/epel/5/x86_64/repoview/rlwrap.html] or [http://dl.fedoraproject.org/pub/epel/6/x86_64/repoview/rlwrap.html]&lt;br /&gt;
* sudo yum install rlwrap&lt;br /&gt;
* build a dictionary file for autocomplete on pressing Tab&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
vi $HOME/sql.dict&lt;br /&gt;
select&lt;br /&gt;
from&lt;br /&gt;
dba_users&lt;br /&gt;
dba_data_files&lt;br /&gt;
dba_tablespaces&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alias sysdba=&amp;#039;rlwrap -f $HOME/sql.dict sqlplus / as sysdba&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or for general command use...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alias sqlplus=&amp;#039;rlwrap -D2 -ic sqlplus&amp;#039;&lt;br /&gt;
alias dgmgrl=&amp;#039;rlwrap -D2 -ic dgmgrl&amp;#039;&lt;br /&gt;
alias rman=&amp;#039;rlwrap -D2 -ic rman&amp;#039;&lt;br /&gt;
alias asmcmd=&amp;#039;rlwrap -D2 -ic asmcmd&amp;#039;&lt;br /&gt;
alias lsnrctl=&amp;#039;rlwrap -D2 -ic lsnrctl&amp;#039;&lt;br /&gt;
alias adrci=&amp;#039;rlwrap -D2 -ic adrci&amp;#039;&lt;br /&gt;
alias impdp=&amp;#039;rlwrap -D2 -ic impdp&amp;#039;&lt;br /&gt;
alias expdp=&amp;#039;rlwrap -D2 -ic expdp&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Execute an SQL statement on all databases on all servers for a customer===&lt;br /&gt;
Run from customer&amp;#039;s management server&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
./dosh -c &amp;quot;su - oracle -c &amp;#039;/home/tools/scripts/oracle/all_db_do -v \&amp;quot;select username, account_status, profile from dba_users order by 3;\&amp;quot;&amp;#039;&amp;quot; &amp;gt;user_status.lst&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SCRIPTS_DIR=/home/tools/scripts/oracle&lt;br /&gt;
$SCRIPTS_DIR/dosh -c &amp;quot;su - oraibm -c \&amp;quot;$SCRIPTS_DIR/all_db_do &amp;#039;alter user ops\\\$oraibm profile oracle_system_user;&amp;#039;\&amp;quot;&amp;quot;&lt;br /&gt;
$SCRIPTS_DIR/dosh2 -c &amp;quot;su - oraibm -c \&amp;quot;$SCRIPTS_DIR/all_db_do &amp;#039;alter user ops$oraibm profile oracle_system_user;&amp;#039;\&amp;quot;&amp;quot;&lt;br /&gt;
$SCRIPTS_DIR/dosh2 -c &amp;quot;su - oraibm -c \&amp;quot;$SCRIPTS_DIR/all_db_do &amp;#039;alter system set control_file_record_keep_time=31;&amp;#039;\&amp;quot;&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Where is the alert log/alertlog?===&lt;br /&gt;
Older systems&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select value from v$parameter where name=&amp;#039;background_dump_dest&amp;#039;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Newer systems&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select value from v$diag_info where name=&amp;#039;Diag Trace&amp;#039;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Grant normal users access to the alertlog table (sys.x$dbgalertext)===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
create view x$dbgalertext_v as select * from x$dbgalertext;&lt;br /&gt;
grant select on x$dbgalertext_v to &amp;amp;&amp;amp;grantee;&lt;br /&gt;
create or replace synonym &amp;amp;grantee..x$dbgalertext for sys.x$dbgalertext_v;&lt;br /&gt;
undef grantee&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Search alert log for ORA-00600 and ORA-07445 errors===&lt;br /&gt;
Scan the database table version of the alertlog for errors without reporting what was already found.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select indx, message_text from x$dbgalertext where message_text like &amp;#039;%ORA-00600%&amp;#039; or message_text like &amp;#039;%ORA-07445%&amp;#039; and indx &amp;gt; &amp;amp;last_queried_indx order by indx desc;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Simulating errors in alert log===&lt;br /&gt;
Sometimes you need to inject error messages into the alertlog to test your monitoring system. This generates the entries in the alertlog and in x$dbgalertext table.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
exec sys.dbms_system.ksdwrt(2, &amp;#039;ORA-07445: Testing this error code for Zenoss, do not investigate.&amp;#039;);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This additionally creates a trace file.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
exec sys.dbms_system.ksdwrt(3, &amp;#039;ORA-00600: Testing this error code for Zenoss, do not investigate.&amp;#039;);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===tail the database alert log===&lt;br /&gt;
If an ADR error is displayed, then ORACLE_SID is probably not set&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alias alertlog=&amp;#039;adrci exec=&amp;quot;set home diag/rdbms/$(echo $ORACLE_SID | tr A-Z a-z)/$ORACLE_SID; show alert -tail -f&amp;quot;&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===What is my WAN ip address?===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
curl -A &amp;quot;Mozilla/4.0&amp;quot; http://checkip.dyndns.org/ 2&amp;gt;/dev/null | perl -ne &amp;#039;print $1 if /Current IP Address: (\d+\.\d+\.\d+\.\d+)/&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
curl -A &amp;quot;Mozilla/4.0&amp;quot; http://myip.dnsdynamic.org/ 2&amp;gt;/dev/null&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Wait for child pid to finish in background and report its status===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# submit a process to the background&lt;br /&gt;
export_schema1.ksh &amp;amp;&lt;br /&gt;
bgpid=$!&lt;br /&gt;
&lt;br /&gt;
while (ps -ef | grep $bgpid | grep -v grep); do&lt;br /&gt;
    # still running...&lt;br /&gt;
    sleep 600&lt;br /&gt;
done&lt;br /&gt;
&lt;br /&gt;
# should be finished&lt;br /&gt;
wait $bgpid&lt;br /&gt;
bgstatus=$?&lt;br /&gt;
echo background process ended with status $bgstatus&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/usr/bin/ksh&lt;br /&gt;
# submit a few processes to the background&lt;br /&gt;
# wait for them all to finish&lt;br /&gt;
# concat their logfiles&lt;br /&gt;
&lt;br /&gt;
(./sleeper.sh;echo &amp;quot;sleeper 1 finished&amp;quot;)&amp;gt;sleeper1.log &amp;amp;&lt;br /&gt;
PIDLIST=&amp;quot;$PIDLIST $!&amp;quot;&lt;br /&gt;
echo &amp;quot;PIDLIST is $PIDLIST ...&amp;quot;&lt;br /&gt;
sleep 5&lt;br /&gt;
&lt;br /&gt;
(./sleeper.sh;echo &amp;quot;sleeper 2 finished&amp;quot;)&amp;gt;sleeper2.log &amp;amp;&lt;br /&gt;
PIDLIST=&amp;quot;$PIDLIST $!&amp;quot;&lt;br /&gt;
echo &amp;quot;PIDLIST is $PIDLIST ...&amp;quot;&lt;br /&gt;
sleep 5&lt;br /&gt;
&lt;br /&gt;
(./sleeper.sh;echo &amp;quot;sleeper 3 finished&amp;quot;)&amp;gt;sleeper3.log &amp;amp;&lt;br /&gt;
PIDLIST=&amp;quot;$PIDLIST $!&amp;quot;&lt;br /&gt;
echo &amp;quot;PIDLIST is $PIDLIST ...&amp;quot;&lt;br /&gt;
sleep 5&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;Now 15 seconds later, we have 3 pids: $PIDLIST&amp;quot;&lt;br /&gt;
for PID in $PIDLIST; do&lt;br /&gt;
    wait $PID&lt;br /&gt;
    echo &amp;quot;$PID exited with status $?&amp;quot;&lt;br /&gt;
done&lt;br /&gt;
&lt;br /&gt;
# all jobs should have ended, concat their logs&lt;br /&gt;
cat sleeper*log &amp;gt; sleepers.log&lt;br /&gt;
cat sleepers.log&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Real world example&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/usr/bin/ksh&lt;br /&gt;
# ==============================================================================&lt;br /&gt;
# Name         : export_JDBEOP1.ksh&lt;br /&gt;
# Description  : Run export in pieces for performance reasons&lt;br /&gt;
#&lt;br /&gt;
# Parameters   : &lt;br /&gt;
#&lt;br /&gt;
# Notes        : Also decide whether to exclude PDARC schema or not&lt;br /&gt;
#                depending on what day it is&lt;br /&gt;
#&lt;br /&gt;
#&lt;br /&gt;
# Modification History&lt;br /&gt;
# ====================&lt;br /&gt;
# When      Who               What&lt;br /&gt;
# ========= ================= ==================================================&lt;br /&gt;
# 15-OCT-13 Stuart Barkley    Created&lt;br /&gt;
# ==============================================================================&lt;br /&gt;
&lt;br /&gt;
STARTTIME=`date &amp;#039;+%Y%m%d%H%M%S&amp;#039;`&lt;br /&gt;
DAYNO=`date +%u`&lt;br /&gt;
PROGNAME=`basename $0`&lt;br /&gt;
SCRIPTS_DIR=/home/tools/scripts/oracle&lt;br /&gt;
DATA_DIR=/oracle/JDBEOP1/admin/change&lt;br /&gt;
EXPORT_DIR=/oracle/export/JDBEOP1&lt;br /&gt;
&lt;br /&gt;
# marker so we can find our files later&lt;br /&gt;
MARKERFILE=/tmp/start_$PROGNAME_$$&lt;br /&gt;
touch $MARKERFILE&lt;br /&gt;
&lt;br /&gt;
$SCRIPTS_DIR/expdp_PARFILE.ksh -s JDBEOP1 -u PRODDTA -p 4 -k 2 -f $DATA_DIR/JDBEOP1_PRODDTA.parfile &amp;amp;&lt;br /&gt;
PIDLIST=&amp;quot;$PIDLIST $!&amp;quot;&lt;br /&gt;
echo &amp;quot;PIDLIST is $PIDLIST ...&amp;quot;&lt;br /&gt;
&lt;br /&gt;
$SCRIPTS_DIR/expdp_PARFILE.ksh -s JDBEOP1 -u PRODCTL -p 2 -k 2 -f $DATA_DIR/JDBEOP1_PRODCTL.parfile &amp;amp;&lt;br /&gt;
PIDLIST=&amp;quot;$PIDLIST $!&amp;quot;&lt;br /&gt;
echo &amp;quot;PIDLIST is $PIDLIST ...&amp;quot;&lt;br /&gt;
&lt;br /&gt;
$SCRIPTS_DIR/expdp_PARFILE.ksh -s JDBEOP1 -u NOPRODNOPDARC -p 4 -k 2 -f $DATA_DIR/JDBEOP1_NOPROD_NOPDARC.parfile &amp;amp;&lt;br /&gt;
PIDLIST=&amp;quot;$PIDLIST $!&amp;quot;&lt;br /&gt;
echo &amp;quot;PIDLIST is $PIDLIST ...&amp;quot;&lt;br /&gt;
&lt;br /&gt;
if [[ $DAYNO -eq 1 ]]; then&lt;br /&gt;
    $SCRIPTS_DIR/expdp_PARFILE.ksh -s JDBEOP1 -u NOPROD -p 4 -k 2 -f $DATA_DIR/JDBEOP1_NOPROD.parfile &amp;amp;&lt;br /&gt;
    PIDLIST=&amp;quot;$PIDLIST $!&amp;quot;&lt;br /&gt;
    echo &amp;quot;PIDLIST is $PIDLIST ...&amp;quot;&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
# now sit and wait for the exports to finish&lt;br /&gt;
for PID in $PIDLIST; do&lt;br /&gt;
    echo &amp;quot;waiting for pid $PID to finish&amp;quot;&lt;br /&gt;
    wait $PID&lt;br /&gt;
    echo &amp;quot;$PID exited with status $?&amp;quot;&lt;br /&gt;
done&lt;br /&gt;
&lt;br /&gt;
# collect all log files up into one&lt;br /&gt;
cd $EXPORT_DIR&lt;br /&gt;
for i in `find . -name &amp;quot;expdp_JDBEOP1*log&amp;quot; -newer $MARKERFILE`; do&lt;br /&gt;
    cat $i &amp;gt; expdp_JDBEOP1_D_FULL_${STARTTIME}.log&lt;br /&gt;
done&lt;br /&gt;
&lt;br /&gt;
rm $MARKLERFILE&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Create private DB link for a user without knowing his password===&lt;br /&gt;
* Inspired by [http://oradbatips.blogspot.co.uk/2010/01/tip-84-create-private-db-link-for-user.html oradbatips.blogspot.co.uk]&lt;br /&gt;
It uses a clever package, dbms_sys_sql.&amp;lt;br /&amp;gt;&lt;br /&gt;
Also useful for executing anything on behalf of another user.&amp;lt;br /&amp;gt;&lt;br /&gt;
Here is an example on how to create private database link for a user.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
create or replace procedure link_creator ( p_owner varchar2, p_dblink_name varchar2, p_username varchar2, p_password varchar2, p_address varchar2 ) as&lt;br /&gt;
    uid number;&lt;br /&gt;
    sqltext varchar2(1000) := &amp;#039;create [public] database link [link_name] connect to [username] identified by [password] using &amp;#039;&amp;#039;[address]&amp;#039;&amp;#039;&amp;#039;;&lt;br /&gt;
    myint integer;&lt;br /&gt;
begin&lt;br /&gt;
    if upper(p_owner) = &amp;#039;PUBLIC&amp;#039; then&lt;br /&gt;
        sqltext := replace(sqltext, &amp;#039;[public]&amp;#039;, &amp;#039;public&amp;#039;);&lt;br /&gt;
    else&lt;br /&gt;
        sqltext := replace(sqltext, &amp;#039;[public]&amp;#039;, &amp;#039;&amp;#039;);&lt;br /&gt;
    end if;&lt;br /&gt;
    sqltext := replace(sqltext, &amp;#039;[linkname]&amp;#039;, p_dblink_name);&lt;br /&gt;
    sqltext := replace(sqltext, &amp;#039;[username]&amp;#039;, p_username);&lt;br /&gt;
    sqltext := replace(sqltext, &amp;#039;[password]&amp;#039;, p_password);&lt;br /&gt;
    sqltext := replace(sqltext, &amp;#039;[address]&amp;#039;, p_address);&lt;br /&gt;
&lt;br /&gt;
    select user_id&lt;br /&gt;
    into   uid&lt;br /&gt;
    from   dba_users&lt;br /&gt;
    where  username = decode(upper(p_owner), &amp;#039;PUBLIC&amp;#039;, &amp;#039;SYS&amp;#039;, p_owner)&lt;br /&gt;
    ;&lt;br /&gt;
    myint:=sys.dbms_sys_sql.open_cursor();&lt;br /&gt;
    sys.dbms_sys_sql.parse_as_user ( myint, sqltext, dbms_sql.native, uid );&lt;br /&gt;
    sys.dbms_sys_sql.close_cursor(myint);&lt;br /&gt;
end;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Here we can generate SQL to rebuild the links for future use. Note the password is no longer stored in this column.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set pages 1000&lt;br /&gt;
select &amp;#039;begin link_creator ( &amp;#039;&amp;#039;&amp;#039;|| u.name ||&amp;#039;&amp;#039;&amp;#039;,&amp;#039;&amp;#039;&amp;#039;|| l.name ||&amp;#039;&amp;#039;&amp;#039;,&amp;#039;&amp;#039;&amp;#039;|| l.userid ||&amp;#039;&amp;#039;&amp;#039;,&amp;#039;&amp;#039;&amp;#039;|| l.password ||&amp;#039;&amp;#039;&amp;#039;,&amp;#039;&amp;#039;&amp;#039;|| l.host ||&amp;#039;&amp;#039;&amp;#039;); end;&amp;#039;|| chr(10) ||&amp;#039;/&amp;#039; link_text&lt;br /&gt;
from   sys.link$ l&lt;br /&gt;
,      sys.user$ u&lt;br /&gt;
where  l.owner# = u.user#&lt;br /&gt;
;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Another method to create a db_link from sys on behalf of a user is to create a procedure under that users name that does the db link creation====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
grant create database link to &amp;amp;&amp;amp;user;&lt;br /&gt;
&lt;br /&gt;
create or replace procedure &amp;amp;user..create_db_link as&lt;br /&gt;
begin&lt;br /&gt;
    execute immediate &amp;#039;create database link &amp;amp;link_name connect to &amp;amp;user identified by &amp;amp;users_password using &amp;#039;&amp;#039;&amp;amp;tns_connect_identifier&amp;#039;&amp;#039;&amp;#039;;&lt;br /&gt;
end create_db_link;&lt;br /&gt;
&lt;br /&gt;
exec &amp;amp;user..create_db_link;&lt;br /&gt;
&lt;br /&gt;
revoke create database link from &amp;amp;user;&lt;br /&gt;
&lt;br /&gt;
drop procedure &amp;amp;user..create_db_link;&lt;br /&gt;
undef user&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Create a comma separated list of columns from a select statement===&lt;br /&gt;
Method 1:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SELECT parent_id,&lt;br /&gt;
       RTRIM(XMLAGG(XMLELEMENT(e,child_id || &amp;#039;,&amp;#039;)).EXTRACT(&amp;#039;//text()&amp;#039;),&amp;#039;,&amp;#039;) AS &amp;quot;Children&amp;quot;&lt;br /&gt;
FROM   parentChildTable&lt;br /&gt;
WHERE  parent_id = 0&lt;br /&gt;
GROUP  BY parent_id&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SELECT parent_id,&lt;br /&gt;
       LISTAGG(child_id, &amp;#039;,&amp;#039;) WITHIN GROUP (ORDER BY child_id) AS &amp;quot;Children&amp;quot;&lt;br /&gt;
  FROM parentChildTable&lt;br /&gt;
 WHERE parent_id = 0&lt;br /&gt;
 GROUP BY parent_id&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Method 2 (undocumented and cannot therefore be relied on to continue working in the same manner):&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SELECT wmsys.wm_concat(&amp;lt;column_name&amp;gt;)&lt;br /&gt;
FROM &amp;lt;table_name&amp;gt;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Start an instant one-line webserver in current directory===&lt;br /&gt;
Need to quickly share/copy a file or read an html file on Linux? Start a web server!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
python -m SimpleHTTPServer 8000&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
and point your browser to http://localhost:8000&amp;lt;br /&amp;gt;&lt;br /&gt;
or&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
while true; do nc -l -p 80 -q 1 &amp;lt; index.html; done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Get SQL*Plus to generate HTML===&lt;br /&gt;
* [http://docs.oracle.com/cd/E11882_01/server.112/e16604/ch_seven.htm#CHDCECJG official guide]&lt;br /&gt;
One way to do it... use -m(arkup) option to specify:&amp;lt;br /&amp;gt;&lt;br /&gt;
html on/off - specifies whether to output html output or not&lt;br /&gt;
head - specify your own customised head contents&amp;lt;br /&amp;gt;&lt;br /&gt;
spool off - as a part of the -m tag means do not print the default &amp;amp;lt;html&amp;amp;gt;, &amp;amp;lt;head&amp;amp;gt; and &amp;amp;lt;body&amp;amp;gt; tags&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sqlplus -m &amp;quot;html on head &amp;#039;&amp;lt;link rel=&amp;quot;stylesheet&amp;quot; href=&amp;quot;/dbamon_golden.css&amp;quot; type=&amp;quot;text/css&amp;quot; /&amp;gt;&amp;#039; spool off&amp;quot; / as sysdba&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sqlplus / as sysdba&lt;br /&gt;
set markup html on head &amp;#039;&amp;lt;link rel=&amp;quot;stylesheet&amp;quot; href=&amp;quot;/dbamon_golden.css&amp;quot; type=&amp;quot;text/css&amp;quot; /&amp;gt;&amp;#039; body &amp;quot;&amp;quot; table &amp;quot;&amp;quot; spool off&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
besides html and head, you can also specify:&amp;lt;br /&amp;gt;&lt;br /&gt;
body - specify your own customised body attributes&amp;lt;br /&amp;gt;&lt;br /&gt;
table - override the default table options&amp;lt;br /&amp;gt;&lt;br /&gt;
entmap - turn on or off the html replacement characters (&amp;amp;lt, &amp;amp;gt, etc...)&amp;lt;br /&amp;gt;&lt;br /&gt;
preformat - uses the &amp;amp;lt;pre&amp;amp;gt; tag to format output exactly as required&amp;lt;br /&amp;gt;&lt;br /&gt;
* another little gem...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
----------------------------------------&lt;br /&gt;
-- get the last SQL*Plus output in HTML&lt;br /&gt;
-- after Tanel Poder&lt;br /&gt;
----------------------------------------&lt;br /&gt;
&lt;br /&gt;
set termout off&lt;br /&gt;
&lt;br /&gt;
set markup HTML ON HEAD &amp;quot; -&lt;br /&gt;
 -&lt;br /&gt;
&amp;quot; -&lt;br /&gt;
BODY &amp;quot;&amp;quot; -&lt;br /&gt;
TABLE &amp;quot;border=&amp;#039;1&amp;#039; align=&amp;#039;center&amp;#039; summary=&amp;#039;Script output&amp;#039;&amp;quot; -&lt;br /&gt;
SPOOL ON ENTMAP ON PREFORMAT OFF&lt;br /&gt;
&lt;br /&gt;
spool myoutput.html&lt;br /&gt;
&lt;br /&gt;
l&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
spool off&lt;br /&gt;
set markup html off spool off&lt;br /&gt;
host firefox myoutput.html&lt;br /&gt;
set termout on&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===HTML SELECT - Trigger JavaScript ONCHANGE event even when the option is not changed===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;select onchange=&amp;quot;jsFunction()&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;option value=&amp;quot;&amp;quot; disabled selected style=&amp;quot;display:none;&amp;quot;&amp;gt;Label&amp;lt;/option&amp;gt;&lt;br /&gt;
  &amp;lt;option value=&amp;quot;1&amp;quot;&amp;gt;1&amp;lt;/option&amp;gt;&lt;br /&gt;
  &amp;lt;option value=&amp;quot;2&amp;quot;&amp;gt;2&amp;lt;/option&amp;gt;&lt;br /&gt;
  &amp;lt;option value=&amp;quot;3&amp;quot;&amp;gt;3&amp;lt;/option&amp;gt;&lt;br /&gt;
&amp;lt;/select&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Display horizontal bar graph in HTML table data cell===&lt;br /&gt;
Using Perl&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
print (&amp;#039;&amp;lt;td class=&amp;quot;left&amp;quot;&amp;gt;&amp;#039; .&lt;br /&gt;
            &amp;#039;&amp;lt;div style=&amp;quot;background-color:#8097BE;width:&amp;quot;&amp;#039;,$allocpercused  ,&amp;#039;%;&amp;quot; /&amp;gt;&amp;#039; .&lt;br /&gt;
            &amp;#039;&amp;lt;div style=&amp;quot;background-color:red;    width:&amp;quot;&amp;#039;,$automaxpercused,&amp;#039;%;&amp;quot; /&amp;gt;&amp;#039; .&lt;br /&gt;
            $tspace .&lt;br /&gt;
       &amp;#039;&amp;lt;/td&amp;gt;&amp;#039;&lt;br /&gt;
);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Depending on which way around the divs are, you get different interpretations&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
print (&amp;quot;&amp;lt;td class=\&amp;quot;left\&amp;quot;&amp;gt;&amp;quot; .&lt;br /&gt;
            &amp;quot;&amp;lt;div style=\&amp;quot;border-right:2px solid red; width:&amp;quot;,($automaxpercused&amp;gt;99)?(100):($automaxpercused),&amp;quot;%;\&amp;quot; /&amp;gt;&amp;quot; .&lt;br /&gt;
            &amp;quot;&amp;lt;div style=\&amp;quot;background-color:#8097BE;width:&amp;quot;,$allocpercused  ,&amp;quot;%;\&amp;quot; /&amp;gt;&amp;quot; .&lt;br /&gt;
            $tspace .&lt;br /&gt;
       &amp;quot;&amp;lt;/td&amp;gt;&amp;quot;&lt;br /&gt;
);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====References====&lt;br /&gt;
* [http://stackoverflow.com/questions/5324996/comma-separated-list-as-a-result-of-select-statement-in-oracle stackoverflow.com]&lt;br /&gt;
* [http://www.salvis.com/blog/?p=207 A whole page showing how to do it in all versions back to 7!]&lt;/div&gt;</summary>
		<author><name>Stuart</name></author>	</entry>

	<entry>
		<id>https://mailnest.com/dbawiki/index.php?title=Snippets&amp;diff=3394</id>
		<title>Snippets</title>
		<link rel="alternate" type="text/html" href="https://mailnest.com/dbawiki/index.php?title=Snippets&amp;diff=3394"/>
				<updated>2018-12-04T20:07:25Z</updated>
		
		<summary type="html">&lt;p&gt;Stuart: /* Write to the alert log from PL/SQL */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;===Protecting an Apache Web Server directory with htaccess===&lt;br /&gt;
* [https://davidwalsh.name/password-protect-directory-using-htaccess https://davidwalsh.name/password-protect-directory-using-htaccess]&lt;br /&gt;
* [http://www.htaccesstools.com/articles/password-protection/ http://www.htaccesstools.com/articles/password-protection/]&lt;br /&gt;
Two files are needed.&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;The .htaccess Code&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
AuthType Basic&lt;br /&gt;
AuthName &amp;quot;restricted area&amp;quot;&lt;br /&gt;
AuthUserFile /home/davidwalsh/html/protect-me-dir/.htpasswd&lt;br /&gt;
require valid-user&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;The .htpasswd Code&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
davidwalsh:daWHfZrDLB88.&lt;br /&gt;
rodstewart:roFulYxC2.8ws&lt;br /&gt;
cssexpert:csmnmq.M8T5ho&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Protecting a lighttpd directory with htaccess===&lt;br /&gt;
Generate an MD5 hash with the tools above and paste into this file&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
vi /etc/lighttpd/.htpasswd&lt;br /&gt;
stuart:3#$567890#$56789056789&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Check modules.conf file to ensure mod_auth and mod_rewrite are enabled&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
vi /etc/lighttpd/modules.conf&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Alter the lighttpd.conf file to allow the authentication&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#auth directives&lt;br /&gt;
auth.backend = &amp;quot;htpasswd&amp;quot;&lt;br /&gt;
auth.backend.htpasswd.userfile = &amp;quot;/etc/lighttpd/.htpasswd&amp;quot;&lt;br /&gt;
auth.debug = 1&lt;br /&gt;
$HTTP[&amp;quot;url&amp;quot;] =~ &amp;quot;^/cgi-bin&amp;quot; {&lt;br /&gt;
        auth.require = ( &amp;quot;&amp;quot; =&amp;gt;&lt;br /&gt;
        (&lt;br /&gt;
        &amp;quot;method&amp;quot; =&amp;gt; &amp;quot;basic&amp;quot;,&lt;br /&gt;
        &amp;quot;realm&amp;quot; =&amp;gt; &amp;quot;DbaHawk access&amp;quot;,&lt;br /&gt;
        &amp;quot;require&amp;quot; =&amp;gt; &amp;quot;valid-user&amp;quot;&lt;br /&gt;
        ) )&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Restart the lighttpd server&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
systemctl stop lighttpd&lt;br /&gt;
systemctl start lighttpd&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
I tried it with htdigest but could not get it to protest the directory!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#auth.backend = &amp;quot;htdigest&amp;quot;&lt;br /&gt;
#auth.backend.htdigest.userfile = &amp;quot;/etc/lighttpd/lighttpd.user.htdigest&amp;quot;&lt;br /&gt;
#auth.require = (&lt;br /&gt;
#    &amp;quot;/var/www/cgi-bin/&amp;quot; =&amp;gt; (&lt;br /&gt;
#    &amp;quot;method&amp;quot;  =&amp;gt; &amp;quot;basic&amp;quot;,&lt;br /&gt;
#    &amp;quot;realm&amp;quot;   =&amp;gt; &amp;quot;DbaHawk access&amp;quot;,&lt;br /&gt;
#    &amp;quot;require&amp;quot; =&amp;gt; &amp;quot;valid-user&amp;quot;&lt;br /&gt;
#    ),&lt;br /&gt;
#)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Rename a datafile if the filename contains junk / unprintable characters===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter tablespace ts_thaler_data offline;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Oracle have a document that describes a few ways of doing it in [https://support.oracle.com/rs?type=doc&amp;amp;id=824473.1 Note 824473.1]&lt;br /&gt;
If the filename contains control characters and cannot be selected in the normal way, use ls -ali to find the node number and then use find with -inum to rename (or move) the file&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ls -baltri&lt;br /&gt;
total 47474984&lt;br /&gt;
12409 -rw-r-----    1 oracle   oinstall 1073750016 Sep 26 13:56 ts_thaler_data_02\1776.dbf&lt;br /&gt;
12350 -rw-r-----    1 oracle   oinstall 5242888192 Sep 26 13:56 ts_thaler_data_01.dbf&lt;br /&gt;
&lt;br /&gt;
find . -inum 12409 -exec mv {} ts_thaler_data_06.dbf \;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Work out what the database thinks the name is and rename it there too! AskTom has a discussion on it [https://asktom.oracle.com/pls/apex/asktom.search?tag=rename-datafile-with-dummy-characters-after-dbf here]&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select substr(name,i,1),ascii(substr(name,i,1)) from ( select name from v$datafile where file# = 9), ( select rownum i from dual connect by level &amp;lt;= 50);&lt;br /&gt;
SUBS ASCII(SUBSTR(NAME,I,1))&lt;br /&gt;
---- -----------------------&lt;br /&gt;
t                        116&lt;br /&gt;
s                        115&lt;br /&gt;
_                         95&lt;br /&gt;
t                        116&lt;br /&gt;
h                        104&lt;br /&gt;
a                         97&lt;br /&gt;
l                        108&lt;br /&gt;
e                        101&lt;br /&gt;
r                        114&lt;br /&gt;
_                         95&lt;br /&gt;
d                        100&lt;br /&gt;
a                         97&lt;br /&gt;
t                        116&lt;br /&gt;
a                         97&lt;br /&gt;
_                         95&lt;br /&gt;
0                         48&lt;br /&gt;
2                         50&lt;br /&gt;
                         127&lt;br /&gt;
2                         50&lt;br /&gt;
.                         46&lt;br /&gt;
d                        100&lt;br /&gt;
b                         98&lt;br /&gt;
f                        102&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
You can see there&amp;#039;s a 127 just before the .dbf... this crept in a the backspace key was not working correctly.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set serveroutput on&lt;br /&gt;
declare&lt;br /&gt;
   fname1 varchar2(100);&lt;br /&gt;
   fname2 varchar2(100);&lt;br /&gt;
begin&lt;br /&gt;
  select name into fname1 from v$datafile where file# = 9;&lt;br /&gt;
  fname2 := replace(fname1,chr(127));&lt;br /&gt;
  &lt;br /&gt;
  dbms_output.put_line(&amp;#039;alter database rename file &amp;#039;&amp;#039;&amp;#039;||fname1||&amp;#039;&amp;#039;&amp;#039; to &amp;#039;&amp;#039;&amp;#039;||fname2||&amp;#039;&amp;#039;&amp;#039;&amp;#039;);&lt;br /&gt;
  execute immediate &amp;#039;alter database rename file &amp;#039;&amp;#039;&amp;#039;||fname1||&amp;#039;&amp;#039;&amp;#039; to &amp;#039;&amp;#039;&amp;#039;||fname2||&amp;#039;&amp;#039;&amp;#039;&amp;#039;;&lt;br /&gt;
end;&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
alter tablespace ts_thaler_data_online;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Generate creation of directory names from dba_directories===&lt;br /&gt;
Before deleting or dropping directories in the database, use this script to generate the create statements&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select &amp;#039;create or replace directory &amp;#039;||directory_name||&amp;#039; as &amp;#039;&amp;#039;&amp;#039;||directory_path||&amp;#039;&amp;#039;&amp;#039;;&amp;#039; from dba_directories;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Check if current (dot) directory is in PATH variable===&lt;br /&gt;
Using bareword comparison to check PATH variable&amp;lt;pre&amp;gt;&lt;br /&gt;
if [[ :$PATH: == *:&amp;quot;.&amp;quot;:* ]] ; then&lt;br /&gt;
    echo &amp;quot;in path&amp;quot;&lt;br /&gt;
else&lt;br /&gt;
    echo &amp;quot;not in path&amp;quot;&lt;br /&gt;
fi&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===tail a logfile from within the script you are writing it to===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#&lt;br /&gt;
# display logfile in real time&lt;br /&gt;
#&lt;br /&gt;
( tail -0f ${LOGFILE} ) &amp;amp;&lt;br /&gt;
tailPID=$!&lt;br /&gt;
&lt;br /&gt;
trap &amp;quot;kill $tailPID&amp;quot; 0 1 2 3 5 9 15&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Dump package, procedure etc. from dba_source in a way that it can be used to recreate it===&lt;br /&gt;
From [https://asktom.oracle.com/pls/apex/f?p=100:11:0::::P11_QUESTION_ID:454220160386 Ask Tom]&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 1000 pages 1000 feedb off verif off&lt;br /&gt;
select decode( type||&amp;#039;-&amp;#039;||to_char(line,&amp;#039;fm99999&amp;#039;), &amp;#039;PACKAGE BODY-1&amp;#039;, &amp;#039;/&amp;#039;||chr(10), null) ||&lt;br /&gt;
       decode(line,1,&amp;#039;create or replace &amp;#039;, &amp;#039;&amp;#039; ) ||&lt;br /&gt;
       text text&lt;br /&gt;
from   dba_source&lt;br /&gt;
where  owner = upper(&amp;#039;&amp;amp;owner&amp;#039;)&lt;br /&gt;
and    name  = upper(&amp;#039;&amp;amp;object_to_show&amp;#039;)&lt;br /&gt;
order  by type&lt;br /&gt;
,      line&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===A trick to exit out of SQL*Plus (using divide by zero) depending on answer to a question===&lt;br /&gt;
This example is taken from ReviewLite.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
-- Settings for customized functionality&lt;br /&gt;
define SCRIPT_OO=_OPTIONS_ONLY -- collect only options information&lt;br /&gt;
define SCRIPT_OO=&amp;#039;&amp;#039;            -- collect all information [default behavior]&lt;br /&gt;
&lt;br /&gt;
define SCRIPT_TS=_TIME_STAMP   -- include timestamp in names of the output directory and output files: YYYY.MM.DD.HH24.MI.SS; script does not prompt for license agreement&lt;br /&gt;
define SCRIPT_TS=&amp;#039;\home\oracle\options&amp;#039;            -- standard names for output directory and output files; script prompts for license agreement [default behavior]&lt;br /&gt;
&lt;br /&gt;
-- PROMT FOR LICENSE AGREEMENT ACCEPTANCE&lt;br /&gt;
DEFINE LANSWER=N&lt;br /&gt;
SET TERMOUT ON&lt;br /&gt;
ACCEPT &amp;amp;SCRIPT_TS LANSWER FORMAT A1 PROMPT &amp;#039;Accept License Agreement? (y\n): &amp;#039;&lt;br /&gt;
&lt;br /&gt;
-- FORCE &amp;quot;divisor is equal to zero&amp;quot; AND SQLERROR EXIT IF NOT ACCEPTED&lt;br /&gt;
-- WILL ALSO CONTINUE IF SCRIPT_TS SUBSTITUTION VARIABLE IS NOT NULL&lt;br /&gt;
SET TERMOUT OFF&lt;br /&gt;
WHENEVER SQLERROR EXIT&lt;br /&gt;
select 1/decode(&amp;#039; &amp;amp;LANSWER&amp;#039;, &amp;#039;Y&amp;#039;, null, &amp;#039;y&amp;#039;, null, decode(&amp;#039; &amp;amp;SCRIPT_TS&amp;#039;, null, 0, null)) as &amp;quot; &amp;quot; from dual;&lt;br /&gt;
WHENEVER SQLERROR CONTINUE&lt;br /&gt;
SET TERMOUT ON&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===How to uninstall optional components such as OWB, APEX, EM, OLAP, OWM from an Oracle database===&lt;br /&gt;
* [http://fast-dba.blogspot.be/2014/04/how-to-remove-unwanted-components-from.html fast-dba.blogspot.be]&lt;br /&gt;
&lt;br /&gt;
===Find unique indexes / primary index / key columns in a table===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
col owner       for a12&lt;br /&gt;
col table_name  for a32&lt;br /&gt;
col column_name for a32&lt;br /&gt;
col position    for 99&lt;br /&gt;
col status      for a10&lt;br /&gt;
set lines 1000 pages 100&lt;br /&gt;
&lt;br /&gt;
SELECT cons.owner&lt;br /&gt;
,      cols.table_name&lt;br /&gt;
,      cols.column_name&lt;br /&gt;
,      cols.position&lt;br /&gt;
,      cons.status&lt;br /&gt;
FROM   all_constraints  cons&lt;br /&gt;
,      all_cons_columns cols&lt;br /&gt;
WHERE  1=1&lt;br /&gt;
and    cols.owner           = &amp;#039;&amp;amp;TABLE_OWNER&amp;#039;&lt;br /&gt;
and    cols.table_name      = &amp;#039;&amp;amp;TABLE_NAME&amp;#039;&lt;br /&gt;
AND    cons.constraint_type = &amp;#039;P&amp;#039;&lt;br /&gt;
AND    cons.constraint_name = cols.constraint_name&lt;br /&gt;
AND    cons.owner           = cols.owner&lt;br /&gt;
ORDER  BY cols.table_name&lt;br /&gt;
,      cols.position&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Display the oracle instances running on the local server===&lt;br /&gt;
sed could be shorter but this one works cross-platform&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alias oenv=&amp;#039;ps -ef|grep pmon|grep -v grep|awk -F_ &amp;quot;{print \$NF}&amp;quot;|sort|uniq|sed -e &amp;quot;:a&amp;quot; -e &amp;quot;N&amp;quot; -e &amp;quot;\$!ba&amp;quot; -e &amp;quot;s/\n/ /g&amp;quot;&amp;#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Display which databases are scheduled for backup in cron===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
for i in `ps -ef | grep [o]ra_pmon | awk -F_ &amp;#039;{print $NF}&amp;#039;`; do&lt;br /&gt;
    crontab -l | grep $i | grep backup_export | awk &amp;#039;{print $2&amp;quot;:&amp;quot;$1&amp;quot; - &amp;quot;$17}&amp;#039;&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Trace SQL statements using autotrace and explain plan===&lt;br /&gt;
If the plustrace (plustrc.sql) role has been granted, explaining sql statements (without running the statement) is as easy as&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter session set sql_trace=true;&lt;br /&gt;
set autotrace traceonly explain&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Write to a trace log from PL/SQL===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
dbms_system.ksdwrt(1,&amp;#039;message sent to a trace file&amp;#039;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Invisible / hidden / virtual columns===&lt;br /&gt;
Article showing how to dump blocks also.&amp;lt;br /&amp;gt;&lt;br /&gt;
[https://www.oracle.com/technetwork/articles/database/invisible-columns-odb12c-2331522.html Tips and Tricks: Invisible Columns in Oracle Database 12c by Alex Zaballa, Oracle Ace and Daniel Da Meda (OCM)]&lt;br /&gt;
&lt;br /&gt;
===Write to the alert log from PL/SQL===&lt;br /&gt;
* [https://www.databasejournal.com/features/oracle/article.php/3386731/Inserting-Custom-Messages-in-Oracle-AlertTrace-files.htm Inserting Custom Messages in Oracle Alert/Trace files]&lt;br /&gt;
Writes to trace file&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
dbms_system.ksdwrt(1,&amp;#039;message sent to the alert log&amp;#039;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Writes to the alertlog&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
dbms_system.ksdwrt(2,&amp;#039;message sent to the alert log&amp;#039;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Writes to the alertlog and trace file&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
dbms_system.ksdwrt(3,&amp;#039;message sent to the alert log&amp;#039;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Also available, KSDIND, KSDDDT and KSDFLS&lt;br /&gt;
&lt;br /&gt;
===Do distributed SQL transactions exist?===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select * from dba_2pc_pending;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
if yes, and to commit them...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select local_tran_id from dba_2pc_pending;&lt;br /&gt;
exec dbms_transaction.purge_lost_db_entry(&amp;#039;&amp;#039;);&lt;br /&gt;
commit;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Setup optional parameters and default values in an SQL*Plus script===&lt;br /&gt;
Some forgotten SQL*Plus tricks from the good old days and some new ones...&lt;br /&gt;
* [http://www.orafaq.com/wiki/SQL*Plus_FAQ#What_is_the_difference_between_.21_and_HOST.3F orafaq.com]&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set termout off&lt;br /&gt;
col p1 new_value 1&lt;br /&gt;
col p2 new_value 2&lt;br /&gt;
col p3 new_value 3&lt;br /&gt;
select null p1, null p2, null p3 from dual where  1=2;&lt;br /&gt;
select nvl(&amp;#039;&amp;amp;1&amp;#039;,&amp;#039;def1&amp;#039;) p1, nvl(&amp;#039;&amp;amp;2&amp;#039;,&amp;#039;def2&amp;#039;) p2, nvl(&amp;#039;&amp;amp;3&amp;#039;,&amp;#039;def3&amp;#039;) p3 from dual;&lt;br /&gt;
set termout on&lt;br /&gt;
prompt 1=&amp;quot;&amp;amp;1&amp;quot;&lt;br /&gt;
prompt 2=&amp;quot;&amp;amp;2&amp;quot;&lt;br /&gt;
prompt 3=&amp;quot;&amp;amp;3&amp;quot;&lt;br /&gt;
undef 1&lt;br /&gt;
undef 2&lt;br /&gt;
undef 3&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Display / show users with sysdba &amp;amp; sysoper privileges===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select * from v$pwfile_users;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Show path names of data files using instr===&lt;br /&gt;
Use to find the pathnames of all the filesystems/directories in which a database is housed.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select distinct substr(name,1,(instr(name,&amp;#039;/&amp;#039;,-1,1)-1)) path_name from v$datafile&lt;br /&gt;
union&lt;br /&gt;
select distinct substr(name,1,(instr(name,&amp;#039;/&amp;#039;,-1,1)-1)) path_name from v$tempfile&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Does a dataguard standby exist for this database?===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SELECT SUBSTR(value,INSTR(value,&amp;#039;=&amp;#039;,INSTR(UPPER(value),&amp;#039;SERVICE&amp;#039;))+1)&lt;br /&gt;
FROM   v$parameter&lt;br /&gt;
WHERE  name LIKE &amp;#039;log_archive_dest%&amp;#039; AND UPPER(value) LIKE &amp;#039;SERVICE%&amp;#039;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
gives something like this if found...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SUBSTR(VALUE,INSTR(VALUE,&amp;#039;=&amp;#039;,INSTR(UPPER(VALUE),&amp;#039;SERVICE&amp;#039;))+1)&lt;br /&gt;
--------------------------------------------------------------------------------&lt;br /&gt;
&amp;quot;jdbeop1_standby&amp;quot;, LGWR ASYNC NOAFFIRM delay=0 optional compression=disable m&lt;br /&gt;
ax_failure=0 max_connections=1 reopen=300 db_unique_name=&amp;quot;jdbeop1_standby&amp;quot; ne&lt;br /&gt;
t_timeout=60, valid_for=(all_logfiles,primary_role)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===List values for all init parameters in v$parameter (including default values for undocumented (hidden) parameters===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select i.ksppinm||&amp;#039;;&amp;#039;||sv.ksppstvl&lt;br /&gt;
from   x$ksppi  i&lt;br /&gt;
,      x$ksppsv sv&lt;br /&gt;
where  i.indx = sv.indx&lt;br /&gt;
order  by i.ksppinm;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Log file reports pipe errors===&lt;br /&gt;
Found these in the log file&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
solax005:root[/opt/IBM/ITM/logs]# tail solax005_or_RMANV11_col.out&lt;br /&gt;
CIR1880E (024955) Open Probe pipe error 2. Pipe=/opt/IBM/ITM/tmp/solax005_or_RMANV11/prb_RMANV11_kor_solax005_30024832_5346_pipe&lt;br /&gt;
CIR1880E (030938) Open Probe pipe error 2. Pipe=/opt/IBM/ITM/tmp/solax005_or_RMANV11/prb_RMANV11_kor_solax005_30030830_5406_pipe&lt;br /&gt;
CIR1880E (031923) Open Probe pipe error 2. Pipe=/opt/IBM/ITM/tmp/solax005_or_RMANV11/prb_RMANV11_kor_solax005_30031832_5434_pipe&lt;br /&gt;
CIR1880E (033934) Open Probe pipe error 2. Pipe=/opt/IBM/ITM/tmp/solax005_or_RMANV11/prb_RMANV11_kor_solax005_30033831_5495_pipe&lt;br /&gt;
CIR1880E (034918) Open Probe pipe error 2. Pipe=/opt/IBM/ITM/tmp/solax005_or_RMANV11/prb_RMANV11_kor_solax005_30034833_5521_pipe&lt;br /&gt;
CIR1880E (041927) Open Probe pipe error 2. Pipe=/opt/IBM/ITM/tmp/solax005_or_RMANV11/prb_RMANV11_kor_solax005_30041835_5610_pipe&lt;br /&gt;
CIR1880E (042931) Open Probe pipe error 2. Pipe=/opt/IBM/ITM/tmp/solax005_or_RMANV11/prb_RMANV11_kor_solax005_30042832_5642_pipe&lt;br /&gt;
CIR1880E (045928) Open Probe pipe error 2. Pipe=/opt/IBM/ITM/tmp/solax005_or_RMANV11/prb_RMANV11_kor_solax005_30045835_5730_pipe&lt;br /&gt;
CIR1880E (052927) Open Probe pipe error 2. Pipe=/opt/IBM/ITM/tmp/solax005_or_RMANV11/prb_RMANV11_kor_solax005_30052838_5819_pipe&lt;br /&gt;
CIR1880E (090929) Open Probe pipe error 2. Pipe=/opt/IBM/ITM/tmp/solax005_or_RMANV11/prb_RMANV11_kor_solax005_30090833_6487_pipe&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This could be due to a timeout on the pipe.&amp;lt;br /&amp;gt;&lt;br /&gt;
Increase parameters and restart agent. Add following lines to or.config:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
export COLL_WAIT_TIMEOUT=&amp;#039;200&amp;#039;&lt;br /&gt;
export WAIT_TIMEOUT=&amp;#039;200&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Find the most recent archived SCN number===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
col next_change# for 999999999999999&lt;br /&gt;
set numwidth 15&lt;br /&gt;
&lt;br /&gt;
select max(next_change#)&lt;br /&gt;
from   v$archived_log&lt;br /&gt;
where  (thread#, next_change#) in ( select thread#, max(next_change#)&lt;br /&gt;
                                    from   v$archived_log&lt;br /&gt;
                                    where  archived     = &amp;#039;YES&amp;#039;&lt;br /&gt;
                                    and    status       = &amp;#039;A&amp;#039;&lt;br /&gt;
                                    and    resetlogs_id = ( select resetlogs_id&lt;br /&gt;
                                                            from   v$database_incarnation&lt;br /&gt;
                                                            where  status = &amp;#039;CURRENT&amp;#039;&lt;br /&gt;
                                                          )&lt;br /&gt;
                                    group by thread#&lt;br /&gt;
                                  )&lt;br /&gt;
and    status = &amp;#039;A&amp;#039;&lt;br /&gt;
and    resetlogs_id = ( select resetlogs_id&lt;br /&gt;
                        from   v$database_incarnation&lt;br /&gt;
                        where  status = &amp;#039;CURRENT&amp;#039;&lt;br /&gt;
                      )&lt;br /&gt;
order  by next_change# asc;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Monitoring says database inactive===&lt;br /&gt;
* Check the candle user password has not expired in the database.&lt;br /&gt;
* There may be a clue in the log file. Check /opt/IBM/ITM/logs/`hostname`_or_${SID}_col.out&lt;br /&gt;
* Check limits for itmora account in /etc/security/limits. Should be same as oracle user.&lt;br /&gt;
* Check the config file. We had this issue when a new ORACLE_HOME was installed but the cfg file still had the old one in it.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
export ITM_HOME=/opt/IBM/ITM&lt;br /&gt;
cd $ITM_HOME/config&lt;br /&gt;
vi solax005_or_SRV2R.cfg&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#  IBM Tivoli Monitoring for Databases: Oracle Agent&lt;br /&gt;
#  Configuration file: solax005_or_SRV2R.cfg&lt;br /&gt;
#  Written by CandleDBconfig version: 1.4 on 31Jul13 13:39:41&lt;br /&gt;
&lt;br /&gt;
#  Note: this is a Korn-shell script that is &amp;quot;sourced&amp;quot; to create the&lt;br /&gt;
#  environment for a Monitoring Agent for Oracle.  It can be used to create&lt;br /&gt;
#  the environment to run the IBM-supplied database grant scripts.&lt;br /&gt;
&lt;br /&gt;
#  IBM does not recommend that you modify this file, but you can change the&lt;br /&gt;
#  data values or add new exported variables as long as the file is a valid ksh&lt;br /&gt;
#  script that executes with zero return code, and values remain quoted with &amp;quot;&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
#  Following environment variables are set for convenience in running grants.&lt;br /&gt;
   export ORACLE_SID=&amp;quot;SRV2R&amp;quot;&lt;br /&gt;
   export ORACLE_HOME=&amp;quot;/oracle/product/11.2.0.1&amp;quot;&lt;br /&gt;
   # IY92195  COLL_DISABLE_CURSORS setting&lt;br /&gt;
   export TNS_ADMIN=&amp;quot;/oracle/product/11.2.0.1/network/admin&amp;quot;&lt;br /&gt;
&lt;br /&gt;
#  Following variables are set for the setup scripts&lt;br /&gt;
   db_sid=&amp;quot;SRV2R&amp;quot;&lt;br /&gt;
   db_home=&amp;quot;/oracle/product/11.2.0.1&amp;quot;&lt;br /&gt;
   db_initfilename=&amp;quot;&amp;quot;&lt;br /&gt;
   db_login=&amp;quot;tivoli&amp;quot;&lt;br /&gt;
   db_password=&amp;quot;795D8822BC49477323815CD21C1E66E966E48EEE19C6A98056224D649B0FE316E6A11DC3F4E9BB5E226B65A8&amp;quot;&lt;br /&gt;
   db_ver=&amp;quot;11.x&amp;quot;&lt;br /&gt;
   db_type=&amp;quot;kor&amp;quot;&lt;br /&gt;
   db_tns=&amp;quot;/oracle/product/11.2.0.1/network/admin&amp;quot;&lt;br /&gt;
   db_extparms=&amp;quot;&amp;quot;&lt;br /&gt;
   db_hostname=&amp;quot;solax005&amp;quot;&lt;br /&gt;
   db_reason=&amp;quot;AIX_ps_ceww&amp;quot;&lt;br /&gt;
   db_pipedir=&amp;quot;&amp;quot;&lt;br /&gt;
   db_installstatus=&amp;quot;CONFIGSUCCESS&amp;quot;&lt;br /&gt;
&lt;br /&gt;
#  User-defined environment variables&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Solution:&amp;lt;br /&amp;gt;&lt;br /&gt;
* Change all occurrences of 11.2.0.1 to 11.2.0.3&lt;br /&gt;
* Restart agent&lt;br /&gt;
&lt;br /&gt;
===Alerts due to password expiring (or being changed in the database but not in ITM!)===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cd $ITM_HOME/logs&lt;br /&gt;
ls -altr | grep WM820T&lt;br /&gt;
tail -20 solax005_or_WM820T_col.out&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
CGN1521E (161614) Interval collection failed for cursor KORHART2&lt;br /&gt;
RCD0110S (161614) Invalid Oracle logon id (tivoli) or password given&lt;br /&gt;
 Please contact DBA to correct userid or password&lt;br /&gt;
CGN1521E (161614) Interval collection failed for cursor KORHART4&lt;br /&gt;
CGN1525E (161614) One or more interval cursors failed&lt;br /&gt;
RCD0110S (161714) Invalid Oracle logon id (tivoli) or password given&lt;br /&gt;
 Please contact DBA to correct userid or password&lt;br /&gt;
CGN1521E (161714) Interval collection failed for cursor KORHART2&lt;br /&gt;
RCD0110S (161714) Invalid Oracle logon id (tivoli) or password given&lt;br /&gt;
 Please contact DBA to correct userid or password&lt;br /&gt;
CGN1521E (161714) Interval collection failed for cursor KORHART4&lt;br /&gt;
CGN1525E (161714) One or more interval cursors failed&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Solution:&amp;lt;br /&amp;gt;&lt;br /&gt;
* Run agent reconfigure to setup the new password for the candle user (tivoli)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
export ITM_HOME=/opt/IBM/ITM&lt;br /&gt;
$ITM_HOME/bin/itmcmd config -A or&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Restart agent&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
export ITM_HOME=/opt/IBM/ITM&lt;br /&gt;
$ITM_HOME/smitools/scripts/StartAgent.sh restart or -o WM820T&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Many agents started with root user instead of itmora===&lt;br /&gt;
This can happen if the server is rebooted before the agents have been added to the itmora list using kdyedit / kciedit&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
export CANDLEHOME=/opt/IBM/ITM&lt;br /&gt;
export ITM_HOME=/opt/IBM/ITM&lt;br /&gt;
$ITM_HOME/smitools/scripts/kdyedit list&lt;br /&gt;
Type Runas      Inst                &lt;br /&gt;
or   root       AGPDEV              &lt;br /&gt;
or   root       BO1R                &lt;br /&gt;
or   root       DEV3                &lt;br /&gt;
or   root       EMREP               &lt;br /&gt;
or   root       ICR                 &lt;br /&gt;
or   itmora     MAPDEV              &lt;br /&gt;
or   itmora     MAPER               &lt;br /&gt;
or   itmora     PED                 &lt;br /&gt;
or   itmora     PER                 &lt;br /&gt;
or   itmora     RMANV11             &lt;br /&gt;
or   itmora     SRV2R               &lt;br /&gt;
or   itmora     WM820Q              &lt;br /&gt;
or   itmora     WM820T              &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ITM_HOME/smitools/scripts/kciedit list&lt;br /&gt;
Type Runas      Inst                &lt;br /&gt;
or   root       AGPDEV              &lt;br /&gt;
or   root       BO1R                &lt;br /&gt;
or   root       DEV3                &lt;br /&gt;
or   root       EMREP               &lt;br /&gt;
or   root       ICR                 &lt;br /&gt;
or   itmora     MAPDEV              &lt;br /&gt;
or   itmora     MAPER               &lt;br /&gt;
or   itmora     PED                 &lt;br /&gt;
or   itmora     PER                 &lt;br /&gt;
or   itmora     RMANV11             &lt;br /&gt;
or   itmora     SRV2R               &lt;br /&gt;
or   itmora     WM820Q              &lt;br /&gt;
or   itmora     WM820T              &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Solution: Add these instances to the itmora list&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
./kdyedit -t or -i AGPDEV -r itmora add&lt;br /&gt;
./kciedit -t or -i AGPDEV -r itmora add&lt;br /&gt;
...&lt;br /&gt;
./kdyedit -t or -i ICR -r itmora add&lt;br /&gt;
./kciedit -t or -i ICR -r itmora add&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ITM_HOME/smitools/scripts/kciedit list&lt;br /&gt;
Type Runas      Inst                &lt;br /&gt;
or   itmora     AGPDEV              &lt;br /&gt;
or   itmora     BO1R                &lt;br /&gt;
or   itmora     DEV3                &lt;br /&gt;
or   itmora     EMREP               &lt;br /&gt;
or   itmora     ICR                 &lt;br /&gt;
or   itmora     MAPDEV              &lt;br /&gt;
or   itmora     MAPER               &lt;br /&gt;
or   itmora     PED                 &lt;br /&gt;
or   itmora     PER                 &lt;br /&gt;
or   itmora     RMANV11             &lt;br /&gt;
or   itmora     SRV2R               &lt;br /&gt;
or   itmora     WM820Q              &lt;br /&gt;
or   itmora     WM820T              &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Kill any agents still running as root&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ps -ef |grep kor | grep root&lt;br /&gt;
kill -9 &amp;lt;process id&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Because these agents were owned by root, there will be permissions issues when trying to restart the agents with itmora so these need to be fixed before restarting the agents.&amp;lt;br /&amp;gt;&lt;br /&gt;
The simplest way of doing this is to run lockdown.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
export CANDLEHOME=/opt/IBM/ITM&lt;br /&gt;
$CANDLEHOME/smitools/scripts/lockdown.sh&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===See which processes are causing paging===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
svmon -Pt20 | perl -e &amp;#039;while(&amp;lt;&amp;gt;){print if($.==2||$&amp;amp;&amp;amp;&amp;amp;!$s++);$.=0 if(/^-+$/)}&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===How to return several variables from SQL*Plus back to Korn shell script===&lt;br /&gt;
Return multiple columns/elements from Oracle to shell script at the same time&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sqlplus -s sys/${SYS_PASSWORD}@${SID} as sysdba&amp;lt;&amp;lt;EOSQL | read SPACE_AFTER_INSTALL TOTAL_SPACE_AVAILABLE&lt;br /&gt;
set numwid 15 headi off newpa none feedb off&lt;br /&gt;
select sign(${SPACE_USED} + ${SPACE_AVAILABLE} - ${DATABASE_SIZE}), trim(${SPACE_USED} + ${SPACE_AVAILABLE})&lt;br /&gt;
from dual&lt;br /&gt;
/&lt;br /&gt;
EOSQL&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===How to get a shell environment variable from the operating system into the SQL or PL/SQL environment===&lt;br /&gt;
This has been bugging me for years. Something you would think simple... what is ORACLE_HOME? I know it&amp;#039;s a question mark at the SQL prompt but how to get it&amp;#039;s O/S value?&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
declare&lt;br /&gt;
    var1 varchar2(200);&lt;br /&gt;
begin&lt;br /&gt;
    dbms_system.get_env (&amp;#039;ORACLE_HOME&amp;#039;, var1);&lt;br /&gt;
    dbms_output.put_line (&amp;#039;ORACLE_HOME: &amp;#039;||var1);&lt;br /&gt;
end;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or in SQL*Plus&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
variable var1 varchar2(200);&lt;br /&gt;
exec dbms_system.get_env (&amp;#039;ORACLE_HOME&amp;#039;, :var1);&lt;br /&gt;
select :var1 from dual;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
That got me thinking... if this just gets stuff from the environment, it can fetch any exported variable?!?!&amp;lt;br /&amp;gt;&lt;br /&gt;
From the shell:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
export running_sids=`ps -ef | grep [p]mon | awk -F_ &amp;#039;{print $NF}&amp;#039;`&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
and now in SQL*Plus:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
variable sids varchar2(240);&lt;br /&gt;
exec dbms_system.get_env (&amp;#039;running_sids&amp;#039;, :sids);&lt;br /&gt;
select :sids from dual;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Wow!&lt;br /&gt;
&lt;br /&gt;
===How long/wide can a database name/sid be?===&lt;br /&gt;
Depends on where you look but taking the minimum here as &amp;quot;safe&amp;quot;, it should still be limited to 8 characters...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
col table_name for a30&lt;br /&gt;
col data_type  for a12&lt;br /&gt;
select table_name, data_type, data_length from dba_tab_columns where column_name = &amp;#039;DB_NAME&amp;#039;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This is 11gR2&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
TABLE_NAME                     DATA_TYPE    DATA_LENGTH&lt;br /&gt;
------------------------------ ------------ -----------&lt;br /&gt;
LOGMNRG_DICTIONARY$            VARCHAR2               9&lt;br /&gt;
SYS_FBA_CONTEXT_AUD            VARCHAR2             256&lt;br /&gt;
V_$LOGMNR_DICTIONARY           VARCHAR2               9&lt;br /&gt;
V_$LOGMNR_LOGS                 VARCHAR2               8&lt;br /&gt;
GV_$LOGMNR_DICTIONARY          VARCHAR2               9&lt;br /&gt;
GV_$LOGMNR_LOGS                VARCHAR2               8&lt;br /&gt;
V_$LOGMNR_LOGFILE              VARCHAR2               8&lt;br /&gt;
V_$LOGMNR_SESSION              VARCHAR2             128&lt;br /&gt;
GV_$LOGMNR_LOGFILE             VARCHAR2               8&lt;br /&gt;
GV_$LOGMNR_SESSION             VARCHAR2             128&lt;br /&gt;
GV_$ASM_CLIENT                 VARCHAR2               8&lt;br /&gt;
V_$ASM_CLIENT                  VARCHAR2               8&lt;br /&gt;
GV_$IOS_CLIENT                 VARCHAR2              64&lt;br /&gt;
V_$IOS_CLIENT                  VARCHAR2              64&lt;br /&gt;
DBA_PDB_HISTORY                VARCHAR2             128&lt;br /&gt;
CDB_PDB_HISTORY                VARCHAR2             128&lt;br /&gt;
SSCR_CAP$                      VARCHAR2            4000&lt;br /&gt;
SSCR_RES$                      VARCHAR2            4000&lt;br /&gt;
DBA_SSCR_CAPTURE               VARCHAR2            4000&lt;br /&gt;
CDB_SSCR_CAPTURE               VARCHAR2            4000&lt;br /&gt;
DBA_SSCR_RESTORE               VARCHAR2            4000&lt;br /&gt;
CDB_SSCR_RESTORE               VARCHAR2            4000&lt;br /&gt;
WRM$_DATABASE_INSTANCE         VARCHAR2               9&lt;br /&gt;
INT$DBA_HIST_DATABASE_INSTANCE VARCHAR2               9&lt;br /&gt;
DBA_HIST_DATABASE_INSTANCE     VARCHAR2               9&lt;br /&gt;
CDB_HIST_DATABASE_INSTANCE     VARCHAR2               9&lt;br /&gt;
LOGMNR_DICTIONARY$             VARCHAR2               9&lt;br /&gt;
&lt;br /&gt;
27 rows selected.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===What character set (characterset) was the database built with?===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
col name  for a40&lt;br /&gt;
col value for a60&lt;br /&gt;
select * from nls_database_parameters;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
col name   for a40&lt;br /&gt;
col value$ for a60&lt;br /&gt;
select name,value$ from props$ where name = &amp;#039;NLS_CHARACTERSET&amp;#039;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===How to find ORACLE_HOME from pmon process for a SID if there is no entry in oratab===&lt;br /&gt;
If database is created without dbca (datafile and controlfile copy), no entry will be automatically made in /etc/oratab.&amp;lt;br /&amp;gt;&lt;br /&gt;
So the problem is that you need to find out which of the ORACLE_HOMEs is being used by the running instances.&lt;br /&gt;
* Solaris, Linux&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ ps -ef | grep [p]mon&lt;br /&gt;
  oracle 10848     1   0 00:21:20 ?           2:11 ora_pmon_JDBEOP1&lt;br /&gt;
$ pwdx 10848&lt;br /&gt;
10848:  /oracle/JDBEOP1/product/11204/dbs&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* AIX&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ ps -ef | grep [p]mon&lt;br /&gt;
  oracle 13893878        1   0   Aug 12      -  7:53 ora_pmon_GOAQ1&lt;br /&gt;
$ ls -al /proc/13893878/cwd&lt;br /&gt;
lr-x------    2 oracle   dba               0 Aug 12 13:37  cwd -&amp;gt; /data/opt/app/product/11.2.0.4/db_1/dbs/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or&amp;lt;br /&amp;gt;&lt;br /&gt;
This command (ps eww) gives lots of information about the given process (pmon in this case). Tells you where the instance was started, whether it was started from SQL*Plus or RMAN, the http_proxy and loads more useful bits!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ps -ef | grep [p]mon | awk &amp;#039;{print $2}&amp;#039; | xargs -I {} ps eww {} | awk &amp;#039;{print $1 &amp;quot; &amp;quot; $5 &amp;quot; &amp;quot; $6 &amp;quot; &amp;quot; $0}&amp;#039; | sed &amp;#039;s/\(S*\) \(S*\) .*ORACLE_HOME/\1 \2/g&amp;#039; | cut -f1,2,3 -d&amp;quot; &amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Escape the underscore(_) or percent(%) character in an SQL statement===&lt;br /&gt;
The underscore matches any single character so to return data containing an underscore means having to use an escape character.&amp;lt;br /&amp;gt;&lt;br /&gt;
Here I use the backslash(\) so it is easy for Unix people to understand the mechanism.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select username from dba_users where username like &amp;#039;ENDUR\_DEV%&amp;#039; escape &amp;#039;\&amp;#039;; &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Validate, analyse and rebuild indexes===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set feedback off&lt;br /&gt;
set linesize 132&lt;br /&gt;
set serveroutput on&lt;br /&gt;
set trimspool on&lt;br /&gt;
&lt;br /&gt;
declare&lt;br /&gt;
    LOCKED exception;&lt;br /&gt;
    pragma exception_init (LOCKED, -54);&lt;br /&gt;
&lt;br /&gt;
    dbase         char(8);&lt;br /&gt;
    dbuser        varchar2(30);&lt;br /&gt;
    index_name    varchar(30);&lt;br /&gt;
    free_text     varchar2(50);&lt;br /&gt;
    pctused       number;&lt;br /&gt;
    height    number;&lt;br /&gt;
    index_mb      number;&lt;br /&gt;
    analyze_sql   varchar2(100);&lt;br /&gt;
    pct_used_sql  varchar2(150);&lt;br /&gt;
    rebuild_sql   varchar2(150);&lt;br /&gt;
 &lt;br /&gt;
    cursor c1 is&lt;br /&gt;
    select segment_name, bytes&lt;br /&gt;
    from   user_segments&lt;br /&gt;
    where  segment_type = &amp;#039;INDEX&amp;#039;&lt;br /&gt;
    and    segment_name like &amp;#039;DW%&amp;#039;&lt;br /&gt;
    and    segment_name not like &amp;#039;BIN%&amp;#039;&lt;br /&gt;
    and    bytes/1024   &amp;gt;= 1024&lt;br /&gt;
    order  by 2;&lt;br /&gt;
&lt;br /&gt;
-- validate the index&lt;br /&gt;
procedure validate_index (v_ind in varchar2) is&lt;br /&gt;
begin&lt;br /&gt;
    analyze_sql := &amp;#039;analyze index &amp;#039;||v_ind||&amp;#039; validate structure&amp;#039;;&lt;br /&gt;
    begin&lt;br /&gt;
        execute immediate analyze_sql;&lt;br /&gt;
    exception&lt;br /&gt;
    when LOCKED then&lt;br /&gt;
        dbms_output.put_line (v_ind||&amp;#039; locked - skipping&amp;#039;);&lt;br /&gt;
        pctused := 100;&lt;br /&gt;
        return;&lt;br /&gt;
    when others then&lt;br /&gt;
        dbms_output.put_line (analyze_sql);&lt;br /&gt;
        raise;&lt;br /&gt;
    end;&lt;br /&gt;
&lt;br /&gt;
    pct_used_sql := &amp;#039;select pct_used, round(blocks*8192/(1024*1024)), height from index_stats where name = &amp;#039;&amp;#039;&amp;#039;||v_ind||&amp;#039;&amp;#039;&amp;#039;&amp;#039;;&lt;br /&gt;
    execute immediate pct_used_sql into pctused, index_mb, height;&lt;br /&gt;
    if pctused is null then&lt;br /&gt;
        pctused := 0;&lt;br /&gt;
    end if;&lt;br /&gt;
    dbms_output.put_line (rpad(v_ind,35)||&amp;#039; (pct used &amp;#039;||pctused||&amp;#039;% size &amp;#039;||index_mb||&amp;#039;Mb height &amp;#039; || height ||&amp;#039;)&amp;#039;);&lt;br /&gt;
end validate_index;&lt;br /&gt;
 &lt;br /&gt;
-- execute SQL and trace if errors&lt;br /&gt;
procedure run_sql (v_sql in varchar2) is&lt;br /&gt;
begin&lt;br /&gt;
    execute immediate v_sql;&lt;br /&gt;
exception&lt;br /&gt;
when others then&lt;br /&gt;
    dbms_output.put_line (v_sql);&lt;br /&gt;
    raise;&lt;br /&gt;
end run_sql;&lt;br /&gt;
 &lt;br /&gt;
--&lt;br /&gt;
-- Script starts here&lt;br /&gt;
--&lt;br /&gt;
begin&lt;br /&gt;
    dbms_output.enable(1000000);&lt;br /&gt;
    -- Set up database name and schema&lt;br /&gt;
    -- select name into dbase  from v$database;&lt;br /&gt;
    select user into dbuser from dual;&lt;br /&gt;
    dbms_output.put_line(&amp;#039;============================================================================= *&amp;#039;);&lt;br /&gt;
    -- dbms_output.put_line(&amp;#039;* Indexes rebuild report for &amp;#039;||dbuser||&amp;#039; on &amp;#039;||dbase);&lt;br /&gt;
    dbms_output.put_line(&amp;#039;============================================================================= *&amp;#039;);&lt;br /&gt;
&lt;br /&gt;
    -- Loop around Indexes&lt;br /&gt;
    for x in c1 loop&lt;br /&gt;
        index_name := x.segment_name;&lt;br /&gt;
        validate_index (index_name );&lt;br /&gt;
        if pctused &amp;lt; 81 then&lt;br /&gt;
            if x.bytes/1024/1024 &amp;lt; 100 then&lt;br /&gt;
                rebuild_sql := &amp;#039;alter index &amp;#039;||x.segment_name||&amp;#039; rebuild online&amp;#039;;&lt;br /&gt;
            else&lt;br /&gt;
                rebuild_sql := &amp;#039;alter index &amp;#039;||x.segment_name||&amp;#039; coalesce&amp;#039;;&lt;br /&gt;
            end if;&lt;br /&gt;
            dbms_output.put_line (rebuild_sql);&lt;br /&gt;
            run_sql (rebuild_sql);&lt;br /&gt;
            validate_index (index_name);&lt;br /&gt;
        end if;&lt;br /&gt;
    end loop;&lt;br /&gt;
end;&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
set feed on&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Rebuild unusable indexes on a table===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select &amp;#039;alter index &amp;#039;||owner||&amp;#039;.&amp;#039;||index_name||&amp;#039; rebuild;&amp;#039;&lt;br /&gt;
from   dba_indexes&lt;br /&gt;
where  1=1&lt;br /&gt;
and    status    != &amp;#039;VALID&amp;#039;&lt;br /&gt;
and    owner     not in (&amp;#039;SYS&amp;#039;,&amp;#039;SYSTEM&amp;#039;)&lt;br /&gt;
--and    owner      = &amp;#039;WM822PP&amp;#039;&lt;br /&gt;
--and    table_name = &amp;#039;WF_PLANTS&amp;#039;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Pull the latest cfengine changes now instead of waiting for scheduled time===&lt;br /&gt;
For one host&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/opt/cfengine/bin/cfagent -ID dbaTime&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
On all hosts at the same time&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/home/ibmtools/scripts/oracle/dosh -c &amp;quot;/opt/cfengine/bin/cfagent -ID dbaTime&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Check status of datafiles without dba_data_files or v$datafile===&lt;br /&gt;
If the database is in mount mode, most tables are unavailable. This query uses the x$ (c based) tables and are always available&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set linesize 200;&lt;br /&gt;
set pagesize 100;&lt;br /&gt;
col inst_id for 9999999 heading &amp;#039;Instance #&amp;#039;&lt;br /&gt;
col file_nr for 9999999 heading &amp;#039;File #&amp;#039;&lt;br /&gt;
col file_name for A50 heading &amp;#039;File name&amp;#039;&lt;br /&gt;
col checkpoint_change_nr for 99999999999999 heading &amp;#039;Checkpoint #&amp;#039;&lt;br /&gt;
col checkpoint_change_time for A20 heading &amp;#039;Checkpoint time&amp;#039;&lt;br /&gt;
col last_change_nr for 99999999999999 heading &amp;#039;Last change #&amp;#039;&lt;br /&gt;
SELECT&lt;br /&gt;
      fe.inst_id,&lt;br /&gt;
      fe.fenum file_nr,&lt;br /&gt;
      fn.fnnam file_name,&lt;br /&gt;
      TO_NUMBER (fe.fecps) checkpoint_change_nr,&lt;br /&gt;
      fe.fecpt checkpoint_change_time,&lt;br /&gt;
      fe.fests last_change_nr,&lt;br /&gt;
      DECODE (&lt;br /&gt;
              fe.fetsn,&lt;br /&gt;
              0, DECODE (BITAND (fe.festa, 2), 0, &amp;#039;SYSOFF&amp;#039;, &amp;#039;SYSTEM&amp;#039;),&lt;br /&gt;
              DECODE (BITAND (fe.festa, 18),&lt;br /&gt;
                      0, &amp;#039;OFFLINE&amp;#039;,&lt;br /&gt;
                      2, &amp;#039;ONLINE&amp;#039;,&lt;br /&gt;
                      &amp;#039;RECOVER&amp;#039;)&lt;br /&gt;
      ) status&lt;br /&gt;
FROM x$kccfe fe,&lt;br /&gt;
     x$kccfn fn&lt;br /&gt;
WHERE    (   (fe.fepax != 65535 AND fe.fepax != 0 )&lt;br /&gt;
          OR (fe.fepax = 65535 OR fe.fepax = 0)&lt;br /&gt;
         )&lt;br /&gt;
     AND fn.fnfno = fe.fenum&lt;br /&gt;
     AND fe.fefnh = fn.fnnum&lt;br /&gt;
     AND fe.fedup != 0&lt;br /&gt;
     AND fn.fntyp = 4&lt;br /&gt;
     AND fn.fnnam IS NOT NULL&lt;br /&gt;
     AND BITAND (fn.fnflg, 4) != 4&lt;br /&gt;
ORDER BY fe.fenum&lt;br /&gt;
;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Check highest allocated extent in datafile (likely slow when having many extents)===&lt;br /&gt;
* Script to Detect Tablespace Fragmentation ( Doc ID 1020182.6 )&lt;br /&gt;
* How to shrink or reduce the datafile size by finding the high water mark (HWM) ( Doc ID 1600774.1 )&lt;br /&gt;
* How to find Objects Fragmented below High Water Mark ( Doc ID 337651.1 )&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
column file_name format a50;&lt;br /&gt;
column tablespace_name format a15;&lt;br /&gt;
column highwater format 9999999999;&lt;br /&gt;
set pagesize 9999&lt;br /&gt;
&lt;br /&gt;
select a.tablespace_name&lt;br /&gt;
,a.file_name&lt;br /&gt;
,(b.maximum+c.blocks-1)*d.db_block_size highwater&lt;br /&gt;
from dba_data_files a&lt;br /&gt;
,(select file_id,max(block_id) maximum&lt;br /&gt;
from dba_extents&lt;br /&gt;
group by file_id) b&lt;br /&gt;
,dba_extents c&lt;br /&gt;
,(select value db_block_size&lt;br /&gt;
from v$parameter&lt;br /&gt;
where name=&amp;#039;db_block_size&amp;#039;) d&lt;br /&gt;
where a.file_id = b.file_id&lt;br /&gt;
and c.file_id = b.file_id&lt;br /&gt;
and c.block_id = b.maximum&lt;br /&gt;
order by a.tablespace_name,a.file_name&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Runup to this was...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set markup html on spool on&lt;br /&gt;
spool db_info.html&lt;br /&gt;
set echo on&lt;br /&gt;
select * from dba_tablespaces where tablespace_name = &amp;#039;&amp;amp;&amp;amp;tablespace_name&amp;#039;;&lt;br /&gt;
select * from dba_data_files where tablespace_name = &amp;#039;&amp;amp;tablespace_name&amp;#039;;&lt;br /&gt;
select * from (select * from dba_extents where tablespace_name = &amp;#039;&amp;amp;tablespace_name&amp;#039; order by block_id desc) where rownum &amp;lt;301;&lt;br /&gt;
spool off&lt;br /&gt;
set markup html off&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select owner, segment_type, count(*) from dba_segments where tablesapce_name=&amp;#039;&amp;amp;tablespace_name&amp;#039; group by owner, segment_type;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
begin&lt;br /&gt;
for ii in (select owner, segment_name, segment_type from dba_segments where tablespace_name = &amp;#039;&amp;amp;tablespace_name&amp;#039; and segment_type like &amp;#039;TABLE%&amp;#039; and segment_name not like &amp;#039;%DATAPUMP%&amp;#039;)&lt;br /&gt;
loop&lt;br /&gt;
if ii.segment_type=&amp;#039;TABLE&amp;#039; then&lt;br /&gt;
begin&lt;br /&gt;
execute immediate(&amp;#039;alter table &amp;#039;||ii.owner||&amp;#039;.&amp;#039;||ii.segment_name||&amp;#039; enable row movement&amp;#039;);&lt;br /&gt;
execute immediate(&amp;#039;alter table &amp;#039;||ii.owner||&amp;#039;.&amp;#039;||ii.segment_name||&amp;#039; shrink space cascade&amp;#039;);&lt;br /&gt;
exception when others then&lt;br /&gt;
dbms_output.put_line(&amp;#039;FAILED 1: alter table &amp;#039;||ii.owner||&amp;#039;.&amp;#039;||ii.segment_name||&amp;#039; shrink space cascade : &amp;#039;||SQLERRM);&lt;br /&gt;
end;&lt;br /&gt;
end if;&lt;br /&gt;
end loop;&lt;br /&gt;
end;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Procedure to shrink space in tables and indexes===&lt;br /&gt;
* [http://www.oracle-wiki.net/startdocsreallifeshrinkexample Using the Oracle Shrink Command] - lots of good stuff at this site&lt;br /&gt;
Written by [https://asktom.oracle.com/pls/apex/f%3Fp%3D100:11:0::::P11_QUESTION_ID:5645095700346948864 Tom Kyte]&amp;lt;br /&amp;gt;&lt;br /&gt;
Depending on the Oracle version, this procedure may or may not work! It does not include the compact clause (neither does it re-analyse to prove it worked).&amp;lt;br /&amp;gt;&lt;br /&gt;
[http://www.oracle-wiki.net/startdocsreallifeshrinkexample Here] is a worked example that shows the complete process - oracle-wiki.net&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
create or replace procedure shrink_all&lt;br /&gt;
as&lt;br /&gt;
    l_sql        varchar2(4000);&lt;br /&gt;
    l_sql2       varchar2(4000);&lt;br /&gt;
    row_movement exception;&lt;br /&gt;
    pragma       exception_init( row_movement, -10636 );&lt;br /&gt;
begin&lt;br /&gt;
    for x in (select table_name&lt;br /&gt;
              ,      owner&lt;br /&gt;
              from   t&lt;br /&gt;
              where  sgm_space_management = &amp;#039;AUTO&amp;#039;)&lt;br /&gt;
    loop&lt;br /&gt;
        l_sql := &amp;#039;alter table &amp;quot;&amp;#039; || x.owner || &amp;#039;&amp;quot;.&amp;quot;&amp;#039; || x.table_name || &amp;#039;&amp;quot; shrink space&amp;#039;;&lt;br /&gt;
        dbms_output.put_line( l_sql );&lt;br /&gt;
&lt;br /&gt;
        begin&lt;br /&gt;
            execute immediate l_sql;&lt;br /&gt;
        exception&lt;br /&gt;
        when row_movement&lt;br /&gt;
        then&lt;br /&gt;
            dbms_output.put_line( &amp;#039;failed due to row movement...&amp;#039; );&lt;br /&gt;
            l_sql2 := &amp;#039;alter table &amp;quot;&amp;#039; || x.owner || &amp;#039;&amp;quot;.&amp;quot;&amp;#039; || x.table_name || &amp;#039;&amp;quot; enable row movement&amp;#039;;&lt;br /&gt;
            dbms_output.put_line( l_sql2 );&lt;br /&gt;
            execute immediate l_sql2;&lt;br /&gt;
            dbms_output.put_line( l_sql );&lt;br /&gt;
            execute immediate l_sql;&lt;br /&gt;
        end;&lt;br /&gt;
&lt;br /&gt;
        for y in (select owner&lt;br /&gt;
                  ,      index_name&lt;br /&gt;
                  from   dba_indexes&lt;br /&gt;
                  where  table_owner = x.owner&lt;br /&gt;
                  and    table_name  = x.table_name )&lt;br /&gt;
        loop&lt;br /&gt;
            l_sql := &amp;#039;alter index &amp;quot;&amp;#039; || y.owner || &amp;#039;&amp;quot;.&amp;quot;&amp;#039; || y.index_name || &amp;#039;&amp;quot; shrink space&amp;#039;;&lt;br /&gt;
            dbms_output.put_line( l_sql );&lt;br /&gt;
            execute immediate l_sql;&lt;br /&gt;
        end loop;&lt;br /&gt;
&lt;br /&gt;
    end loop;&lt;br /&gt;
end;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===How to delete/kill a distributed transaction===&lt;br /&gt;
From [http://www.pouwiel.com/?p=2204 pouwiel.com]&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SQL&amp;gt; SELECT LOCAL_TRAN_ID, GLOBAL_TRAN_ID,to_char(FAIL_TIME,&amp;#039;dd-mon-yyyy HH24:MI:SS&amp;#039;),STATE, MIXED FROM DBA_2PC_PENDING;&lt;br /&gt;
&lt;br /&gt;
LOCAL_TRAN_ID&lt;br /&gt;
----------------------&lt;br /&gt;
GLOBAL_TRAN_ID&lt;br /&gt;
--------------------------------------------------------------------------------&lt;br /&gt;
TO_CHAR(FAIL_TIME,&amp;#039;D STATE MIX&lt;br /&gt;
-------------------- ---------------- ---&lt;br /&gt;
8.19.321913&lt;br /&gt;
1463898948.0000013CDE8005110000000179F68840A089FFFEE644B640AED6B02438B2F39D9665F&lt;br /&gt;
AFB&lt;br /&gt;
15-feb-2013 16:37:41 prepared no&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
SQL&amp;gt; SELECT LOCAL_TRAN_ID, IN_OUT,INTERFACE, DATABASE FROM DBA_2PC_NEIGHBORS;&lt;br /&gt;
&lt;br /&gt;
LOCAL_TRAN_ID IN_ I&lt;br /&gt;
---------------------- --- -&lt;br /&gt;
DATABASE&lt;br /&gt;
--------------------------------------------------------------------------------&lt;br /&gt;
8.19.321913 in N&lt;br /&gt;
jdbc_11&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
SQL&amp;gt; rollback force &amp;#039;8.19.321913&amp;#039;;&lt;br /&gt;
&lt;br /&gt;
Rollback complete.&lt;br /&gt;
&lt;br /&gt;
SQL&amp;gt; execute dbms_transaction.purge_lost_db_entry(&amp;#039;8.19.321913&amp;#039;);&lt;br /&gt;
&lt;br /&gt;
PL/SQL procedure successfully completed.&lt;br /&gt;
&lt;br /&gt;
SQL&amp;gt; commit;&lt;br /&gt;
&lt;br /&gt;
Commit complete.&lt;br /&gt;
&lt;br /&gt;
SQL&amp;gt; SELECT LOCAL_TRAN_ID, GLOBAL_TRAN_ID,to_char(FAIL_TIME,&amp;#039;dd-mon-yyyy HH24:MI:SS&amp;#039;),STATE, MIXED FROM DBA_2PC_PENDING;&lt;br /&gt;
&lt;br /&gt;
no rows selected&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Be aware that the support document 159377.1 does not speak of the rollback force. If you don’t execute that particular command it will not work.&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORACLE_BASE is getting set to the same value as ORACLE_HOME when using . oraenv===&lt;br /&gt;
Permissions problem. Make sure the user has &amp;#039;&amp;#039;&amp;#039;write&amp;#039;&amp;#039;&amp;#039; access to oraclehomeproperties.xml file!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ls -al $ORACLE_HOME/inventory/ContentsXML/oraclehomeproperties.xml&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Change permissions as appropriate.&lt;br /&gt;
A different approach which should give the same end result would be to grant the orabase executable the setuid bit.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
chmod u+s $ORACLE_HOME/bin/orabase&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This allows any user to set the environment as the orabase executable will be run with the permissions of its owner.&lt;br /&gt;
===Move table partitions to a different tablespace===&lt;br /&gt;
Are you getting errors due to partitions belonging to a different tablespace and you want to drop the current tablepace?&amp;lt;br /&amp;gt;&lt;br /&gt;
ORA-14404: partitioned table contains partitions in a different tablespace&amp;lt;br /&amp;gt;&lt;br /&gt;
====Find tables with partitions in more than one tablespace====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 2000 pages 50&lt;br /&gt;
col table_owner for a30&lt;br /&gt;
col table_name for a30&lt;br /&gt;
select table_owner&lt;br /&gt;
 ,     table_name&lt;br /&gt;
,      count(*)&lt;br /&gt;
from   dba_tab_partitions&lt;br /&gt;
where  table_owner != &amp;#039;SYS&amp;#039;&lt;br /&gt;
group  by table_owner&lt;br /&gt;
,      table_name&lt;br /&gt;
having count(*) &amp;gt; 1&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
See which tables have partitions across multiple tablespaces...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 1000 pages 100&lt;br /&gt;
col table_name for a50&lt;br /&gt;
select distinct b.table_owner||&amp;#039;.&amp;#039;||b.table_name table_name&lt;br /&gt;
,      a.tablespace_name ts1&lt;br /&gt;
,      b.tablespace_name ts2&lt;br /&gt;
from   (&lt;br /&gt;
       select distinct tablespace_name&lt;br /&gt;
       ,      table_name&lt;br /&gt;
       ,      partition_name&lt;br /&gt;
       from   dba_tab_partitions&lt;br /&gt;
       )                  a&lt;br /&gt;
,      dba_tab_partitions b&lt;br /&gt;
where  a.table_name       = b.table_name&lt;br /&gt;
and    a.tablespace_name != b.tablespace_name&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Generate statements to move the partitions from one tablespace to another...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select &amp;#039;alter table &amp;#039;||b.table_owner||&amp;#039;.&amp;#039;||b.table_name||&amp;#039; move partition &amp;#039;||b.partition_name||&amp;#039; tablespace &amp;amp;NEW_TABLESPACE;&amp;#039;&lt;br /&gt;
from   (&lt;br /&gt;
       select distinct table_name&lt;br /&gt;
       ,      partition_name&lt;br /&gt;
       from   dba_tab_partitions&lt;br /&gt;
       where  tablespace_name = &amp;#039;&amp;amp;&amp;amp;OLD_TABLESPACE&amp;#039;&lt;br /&gt;
       )                  a&lt;br /&gt;
,      dba_tab_partitions b&lt;br /&gt;
where  a.table_name       = b.table_name&lt;br /&gt;
and    b.tablespace_name != &amp;#039;&amp;amp;OLD_TABLESPACE&amp;#039;&lt;br /&gt;
/&lt;br /&gt;
undef OLD_TABLESPACE&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====What&amp;#039;s left hanging around?====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
col SEGMENT_TYPE for a20&lt;br /&gt;
col OWNER for a20&lt;br /&gt;
col SEGMENT_NAME for a40&lt;br /&gt;
col PARTITION_NAME for a15&lt;br /&gt;
col TABLESPACE_NAME for a30&lt;br /&gt;
select segment_type&lt;br /&gt;
,      owner&lt;br /&gt;
,      segment_name&lt;br /&gt;
,      partition_name&lt;br /&gt;
,      tablespace_name&lt;br /&gt;
from   dba_segments&lt;br /&gt;
where  tablespace_name in (&amp;#039;TS_THALER_IOT_OLD&amp;#039;,&amp;#039;TS_THALER_CU&amp;#039;,&amp;#039;TS_THALER_BACKUP&amp;#039;,&amp;#039;TS_THALER_PART_OLD&amp;#039;)&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
select table_owner&lt;br /&gt;
,      table_name&lt;br /&gt;
from   dba_indexes&lt;br /&gt;
where  index_name = &amp;#039;&amp;amp;index_name&amp;#039;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===What edition is my database (Standard, Enterprise, XE...)?===&lt;br /&gt;
Only works from 12c :-(&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select edition from sys.registry$ where cid=&amp;#039;CATPROC&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Is database a CDB with PDBs?===&lt;br /&gt;
Needs a bit of work. Won&amp;#039;t work pre-12c obviously and also not on Standby databases if they are in MOUNT mode&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
for db in $(ps -ef | grep [p]mon|awk -F_ &amp;#039;{print $NF}&amp;#039;)&lt;br /&gt;
do&lt;br /&gt;
    export ORACLE_SID=${db}&lt;br /&gt;
    ORAENV_ASK=NO&lt;br /&gt;
    . oraenv &amp;gt;/dev/null 2&amp;gt;&amp;amp;1&lt;br /&gt;
    sqlplus -s / as sysdba&amp;lt;&amp;lt;&amp;#039;EOSQL&amp;#039;&lt;br /&gt;
set head off newpa none&lt;br /&gt;
select name&lt;br /&gt;
,      (select count(*) from v$pdbs) npdbs&lt;br /&gt;
from   v$database&lt;br /&gt;
/&lt;br /&gt;
EOSQL&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
version 2&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
function is_db_cdb return boolean&lt;br /&gt;
is&lt;br /&gt;
    b_is_cdb        boolean := false;&lt;br /&gt;
    l_is_cdb        varchar2(3) := &amp;#039;NO&amp;#039;;&lt;br /&gt;
    e_col_not_found exception;&lt;br /&gt;
    pragma          exception_init(e_col_not_found, -904);&lt;br /&gt;
begin&lt;br /&gt;
    begin&lt;br /&gt;
        execute immediate &amp;#039;select cdb from v$database&amp;#039; &lt;br /&gt;
        into l_is_cdb;&lt;br /&gt;
    exception&lt;br /&gt;
        when e_col_not_found then l_is_cdb := &amp;#039;NO&amp;#039;;  -- ORA-00904&lt;br /&gt;
    end;&lt;br /&gt;
&lt;br /&gt;
    if (l_is_cdb = &amp;#039;YES&amp;#039;) then&lt;br /&gt;
        return TRUE;&lt;br /&gt;
    else&lt;br /&gt;
        return FALSE;  -- either not a cdb or pre-12.1 database&lt;br /&gt;
    end if;&lt;br /&gt;
&lt;br /&gt;
end is_db_cdb;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===List triggers in the database===&lt;br /&gt;
This query specifically lists after login triggers &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select obj.con_id&lt;br /&gt;
,      pdb.name&lt;br /&gt;
,      obj.owner&lt;br /&gt;
,      obj.object_name&lt;br /&gt;
,      to_char(obj.created, &amp;#039;DD/MM/YYYY HH24:MI:SS&amp;#039;)       created_str&lt;br /&gt;
,      to_char(obj.last_ddl_time, &amp;#039;DD/MM/YYYY HH24:MI:SS&amp;#039;) last_ddl_str&lt;br /&gt;
from   cdb_objects   obj&lt;br /&gt;
join   cdb_triggers trgs&lt;br /&gt;
       on (   obj.con_id      = trgs.con_id&lt;br /&gt;
          and obj.owner       = trgs.owner&lt;br /&gt;
          and obj.object_name = trgs.trigger_name&lt;br /&gt;
          )&lt;br /&gt;
join   v$pdbs pdb&lt;br /&gt;
       on ( obj.con_id  = pdb.con_id )&lt;br /&gt;
where  trgs.trigger_type     = &amp;#039;AFTER EVENT&amp;#039;&lt;br /&gt;
and    trgs.triggering_event like &amp;#039;LOGON%&amp;#039;&lt;br /&gt;
and    trgs.status           = &amp;#039;ENABLED&amp;#039;&lt;br /&gt;
order  by object_name&lt;br /&gt;
,      obj.last_ddl_time&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===List the pluggable databases (PDB) in a container database (CDB)===&lt;br /&gt;
The network_name column shows what you should find in tnsnames.ora for this db connection&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select name,network_name,pdb from v$services;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select * from v$pdbs;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Start and stop a pluggable database===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter pluggable database pdb1 open;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter pluggable database pdb1 close immediate;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Swith to a pluggable database===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter session set container=pdb1;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Reopen pluggable databases at container startup===&lt;br /&gt;
By default pluggable databases in a container remain in a MOUNT state when the container starts up.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select name, open_mode from v$pdbs where name = &amp;#039;PDB1&amp;#039;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
To modify this, open it and save its state&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter pluggable database pdb1 open;&lt;br /&gt;
alter pluggable database pdb1 save state;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
To see a log of issues with pluggable databases&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select * from pdb_plug_in_violations where type = &amp;#039;ERROR&amp;#039; and status != &amp;#039;RESOLVED&amp;#039; and name = &amp;#039;PDB1&amp;#039;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===What is the current container id in a cdb?===&lt;br /&gt;
CDB$ROOT is container id 1. User containers start from 2.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select sys_context(&amp;#039;USERENV&amp;#039;,&amp;#039;CON_ID&amp;#039;) from dual&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===What is the current container name in a cdb?===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select sys_context(&amp;#039;USERENV&amp;#039;,&amp;#039;CON_NAME&amp;#039;) from dual&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or just&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
show con_name&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Switching Between Containers===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SQL&amp;gt; show con_name&lt;br /&gt;
&lt;br /&gt;
CON_NAME&lt;br /&gt;
------------------------------&lt;br /&gt;
CDB$ROOT&lt;br /&gt;
&lt;br /&gt;
SQL&amp;gt; alter session set container=tstklok;&lt;br /&gt;
&lt;br /&gt;
Session altered.&lt;br /&gt;
&lt;br /&gt;
SQL&amp;gt;  show con_name&lt;br /&gt;
&lt;br /&gt;
CON_NAME&lt;br /&gt;
------------------------------&lt;br /&gt;
TSTKLOK&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Direct connection to pluggable database===&lt;br /&gt;
These must be made using a service (defined in tnsnames.ora). Each pluggable database automatically registers a service with the listener (v$services).&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sqlplus appuser/apppwd@tstklok&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or using ezconnect&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SQL&amp;gt; conn appuser/apppwd@//localhost:1521/tstklok&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===What platform is the database running on?===&lt;br /&gt;
Could be useful for handling line endings...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select platform_name from v$database&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
if instr(db_platform, &amp;#039;WINDOWS&amp;#039;) != 0 then&lt;br /&gt;
    crlf := CHR(13) || CHR(10);       -- Windows gets the \r and \n&lt;br /&gt;
else&lt;br /&gt;
    crlf := CHR (10);                 -- Just \n for the rest of the world&lt;br /&gt;
end if;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Is the database 32 or 64 bit?===&lt;br /&gt;
If the answer is 1,7,10,15,16 or 17, then it is 32bit, everything else should be 64bit.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select platform_id from v$database&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===What features is my database using?===&lt;br /&gt;
Before converting to Standard Edition, check the features here - some may be Enterprise specific.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
col name for a45&lt;br /&gt;
col description for a85&lt;br /&gt;
set lines 2000&lt;br /&gt;
select name&lt;br /&gt;
,      detected_usages&lt;br /&gt;
,      description&lt;br /&gt;
from   dba_feature_usage_statistics&lt;br /&gt;
where  1=1&lt;br /&gt;
and    currently_used = &amp;#039;TRUE&amp;#039;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===How many redo log switches per hour?===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 100&lt;br /&gt;
col &amp;quot;YYYYMMDD HH24&amp;quot; for a14&lt;br /&gt;
select to_char(first_time,&amp;#039;yyyymmdd hh24&amp;#039;) &amp;quot;YYYYMMDD HH24&amp;quot;&lt;br /&gt;
,      count(1)                            num_switches&lt;br /&gt;
from   v$log_history&lt;br /&gt;
group  by to_char(first_time,&amp;#039;yyyymmdd hh24&amp;#039;)&lt;br /&gt;
order  by 1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or a bit fancier version...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rem *********************************************************** &lt;br /&gt;
rem&lt;br /&gt;
rem	File: log_history.sql &lt;br /&gt;
rem	Description: Log switch rates from v$log_history &lt;br /&gt;
rem   &lt;br /&gt;
rem	From &amp;#039;Oracle Performance Survival Guide&amp;#039; by Guy Harrison&lt;br /&gt;
rem		Chapter 21 Page 637&lt;br /&gt;
rem		ISBN: 978-0137011957&lt;br /&gt;
rem		See www.guyharrison.net for further information&lt;br /&gt;
rem  &lt;br /&gt;
rem		This work is in the public domain NSA &lt;br /&gt;
rem   &lt;br /&gt;
rem&lt;br /&gt;
rem ********************************************************* &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
col min_minutes format 9999.99 &lt;br /&gt;
col max_minutes format 9999.99 &lt;br /&gt;
col avg_minutes format 9999.99 &lt;br /&gt;
set pagesize 1000&lt;br /&gt;
set lines 70&lt;br /&gt;
set echo on &lt;br /&gt;
&lt;br /&gt;
WITH log_history AS&lt;br /&gt;
       (SELECT thread#, first_time,&lt;br /&gt;
               LAG(first_time) OVER (ORDER BY thread#, sequence#)&lt;br /&gt;
                  last_first_time,&lt;br /&gt;
               (first_time&lt;br /&gt;
                - LAG(first_time) OVER (ORDER BY thread#, sequence#))&lt;br /&gt;
                    * 24* 60   last_log_time_minutes,&lt;br /&gt;
               LAG(thread#) OVER (ORDER BY thread#, sequence#)&lt;br /&gt;
                   last_thread#&lt;br /&gt;
        FROM v$log_history)&lt;br /&gt;
SELECT ROUND(MIN(last_log_time_minutes), 2) min_minutes,&lt;br /&gt;
       ROUND(MAX(last_log_time_minutes), 2) max_minutes,&lt;br /&gt;
       ROUND(AVG(last_log_time_minutes), 2) avg_minutes&lt;br /&gt;
FROM log_history&lt;br /&gt;
WHERE     last_first_time IS NOT NULL&lt;br /&gt;
      AND last_thread# = thread#&lt;br /&gt;
      AND first_time &amp;gt; SYSDATE - 1; &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Show redo log groups/members===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
col instance       for a8&lt;br /&gt;
col thread         for 999&lt;br /&gt;
col groupno        for 999&lt;br /&gt;
col member         for a35&lt;br /&gt;
col redo_file_type for a15&lt;br /&gt;
col log_status     for a10&lt;br /&gt;
col logsize_m      for 99999&lt;br /&gt;
col archived       for a12&lt;br /&gt;
&lt;br /&gt;
SELECT i.instance_name   instance&lt;br /&gt;
,      i.thread#         thread&lt;br /&gt;
,      f.group#          groupno&lt;br /&gt;
,      f.member          member&lt;br /&gt;
,      f.type            redo_file_type&lt;br /&gt;
,      l.status          log_status&lt;br /&gt;
,      l.bytes/1024/1024 logsize_m&lt;br /&gt;
,      l.archived        archived&lt;br /&gt;
FROM   gv$logfile  f&lt;br /&gt;
,      gv$log      l&lt;br /&gt;
,      gv$instance i&lt;br /&gt;
WHERE  1=1&lt;br /&gt;
and    f.group#  = l.group#&lt;br /&gt;
AND    l.thread# = i.thread#&lt;br /&gt;
AND    i.inst_id = f.inst_id&lt;br /&gt;
AND    f.inst_id = l.inst_id&lt;br /&gt;
ORDER  BY i.instance_name&lt;br /&gt;
,      f.group#&lt;br /&gt;
,      f.member;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Korn shell timestamp function===&lt;br /&gt;
Example usage: echo &amp;quot;`ts`: Checking backup status&amp;quot;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
function ts {&lt;br /&gt;
    date +&amp;#039;%d-%b-%Y %H:%M:%S&amp;#039;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Drop a database===&lt;br /&gt;
Dropping a database including backups should be considered criminal in a production environment!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sqlplus / as sysdba&lt;br /&gt;
startup force mount exclusive restrict&lt;br /&gt;
exit&lt;br /&gt;
rman target /&lt;br /&gt;
drop database including backups noprompt;&lt;br /&gt;
exit&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
RMAN&amp;gt; connect target sys/pass@test&lt;br /&gt;
connected to target database: test (dbid=123456789)&lt;br /&gt;
&lt;br /&gt;
RMAN&amp;gt; startup force mount&lt;br /&gt;
RMAN&amp;gt; sql &amp;#039;alter system enable restricted session&amp;#039;;&lt;br /&gt;
RMAN&amp;gt; drop database including backups noprompt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Use sub-select or in-line views to update base tables===&lt;br /&gt;
Inline views can be used to update base table data&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
update&lt;br /&gt;
    (&lt;br /&gt;
    select p.list_price&lt;br /&gt;
    from   products           p&lt;br /&gt;
    ,      product_categories pc&lt;br /&gt;
    where  1=1&lt;br /&gt;
    and    p.category_id    = pc.category_id&lt;br /&gt;
    and    pc.category_name = &amp;#039;CPU&amp;#039;&lt;br /&gt;
    )&lt;br /&gt;
set list_price = list_price * 1.15; &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Use sub-select or in-line views to delete base table data===&lt;br /&gt;
A different way to delete rows in base tables, using Inline views or subselect&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
delete&lt;br /&gt;
    (&lt;br /&gt;
    select p.list_price&lt;br /&gt;
    from   products           p&lt;br /&gt;
    ,      product_categories pc&lt;br /&gt;
    where  1=1&lt;br /&gt;
    and    p.category_id    = pc.category_id&lt;br /&gt;
    and    pc.category_name = &amp;#039;CPU&amp;#039;&lt;br /&gt;
    )&lt;br /&gt;
where list_price &amp;lt; 1000; &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Mass update of files using perl inline script===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
for server in `cat /home/tools/etc/oracle/oracle_servers`; do&lt;br /&gt;
    ssh $server “perl -p -i -e &amp;#039;s/T01/D01/&amp;#039; /home/tools/scripts/rman/inclexcl.lst”&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===How to use vi-style editing in SQL*Plus===&lt;br /&gt;
These instructions are for Redhat but other versions will be very similar&lt;br /&gt;
* Download rlwrap from [http://dl.fedoraproject.org/pub/epel/5/x86_64/repoview/rlwrap.html] or [http://dl.fedoraproject.org/pub/epel/6/x86_64/repoview/rlwrap.html]&lt;br /&gt;
* sudo yum install rlwrap&lt;br /&gt;
* build a dictionary file for autocomplete on pressing Tab&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
vi $HOME/sql.dict&lt;br /&gt;
select&lt;br /&gt;
from&lt;br /&gt;
dba_users&lt;br /&gt;
dba_data_files&lt;br /&gt;
dba_tablespaces&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alias sysdba=&amp;#039;rlwrap -f $HOME/sql.dict sqlplus / as sysdba&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or for general command use...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alias sqlplus=&amp;#039;rlwrap -D2 -ic sqlplus&amp;#039;&lt;br /&gt;
alias dgmgrl=&amp;#039;rlwrap -D2 -ic dgmgrl&amp;#039;&lt;br /&gt;
alias rman=&amp;#039;rlwrap -D2 -ic rman&amp;#039;&lt;br /&gt;
alias asmcmd=&amp;#039;rlwrap -D2 -ic asmcmd&amp;#039;&lt;br /&gt;
alias lsnrctl=&amp;#039;rlwrap -D2 -ic lsnrctl&amp;#039;&lt;br /&gt;
alias adrci=&amp;#039;rlwrap -D2 -ic adrci&amp;#039;&lt;br /&gt;
alias impdp=&amp;#039;rlwrap -D2 -ic impdp&amp;#039;&lt;br /&gt;
alias expdp=&amp;#039;rlwrap -D2 -ic expdp&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Execute an SQL statement on all databases on all servers for a customer===&lt;br /&gt;
Run from customer&amp;#039;s management server&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
./dosh -c &amp;quot;su - oracle -c &amp;#039;/home/tools/scripts/oracle/all_db_do -v \&amp;quot;select username, account_status, profile from dba_users order by 3;\&amp;quot;&amp;#039;&amp;quot; &amp;gt;user_status.lst&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SCRIPTS_DIR=/home/tools/scripts/oracle&lt;br /&gt;
$SCRIPTS_DIR/dosh -c &amp;quot;su - oraibm -c \&amp;quot;$SCRIPTS_DIR/all_db_do &amp;#039;alter user ops\\\$oraibm profile oracle_system_user;&amp;#039;\&amp;quot;&amp;quot;&lt;br /&gt;
$SCRIPTS_DIR/dosh2 -c &amp;quot;su - oraibm -c \&amp;quot;$SCRIPTS_DIR/all_db_do &amp;#039;alter user ops$oraibm profile oracle_system_user;&amp;#039;\&amp;quot;&amp;quot;&lt;br /&gt;
$SCRIPTS_DIR/dosh2 -c &amp;quot;su - oraibm -c \&amp;quot;$SCRIPTS_DIR/all_db_do &amp;#039;alter system set control_file_record_keep_time=31;&amp;#039;\&amp;quot;&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Where is the alert log/alertlog?===&lt;br /&gt;
Older systems&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select value from v$parameter where name=&amp;#039;background_dump_dest&amp;#039;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Newer systems&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select value from v$diag_info where name=&amp;#039;Diag Trace&amp;#039;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Grant normal users access to the alertlog table (sys.x$dbgalertext)===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
create view x$dbgalertext_v as select * from x$dbgalertext;&lt;br /&gt;
grant select on x$dbgalertext_v to &amp;amp;&amp;amp;grantee;&lt;br /&gt;
create or replace synonym &amp;amp;grantee..x$dbgalertext for sys.x$dbgalertext_v;&lt;br /&gt;
undef grantee&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Search alert log for ORA-00600 and ORA-07445 errors===&lt;br /&gt;
Scan the database table version of the alertlog for errors without reporting what was already found.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select indx, message_text from x$dbgalertext where message_text like &amp;#039;%ORA-00600%&amp;#039; or message_text like &amp;#039;%ORA-07445%&amp;#039; and indx &amp;gt; &amp;amp;last_queried_indx order by indx desc;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Simulating errors in alert log===&lt;br /&gt;
Sometimes you need to inject error messages into the alertlog to test your monitoring system. This generates the entries in the alertlog and in x$dbgalertext table.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
exec sys.dbms_system.ksdwrt(2, &amp;#039;ORA-07445: Testing this error code for Zenoss, do not investigate.&amp;#039;);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This additionally creates a trace file.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
exec sys.dbms_system.ksdwrt(3, &amp;#039;ORA-00600: Testing this error code for Zenoss, do not investigate.&amp;#039;);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===tail the database alert log===&lt;br /&gt;
If an ADR error is displayed, then ORACLE_SID is probably not set&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alias alertlog=&amp;#039;adrci exec=&amp;quot;set home diag/rdbms/$(echo $ORACLE_SID | tr A-Z a-z)/$ORACLE_SID; show alert -tail -f&amp;quot;&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===What is my WAN ip address?===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
curl -A &amp;quot;Mozilla/4.0&amp;quot; http://checkip.dyndns.org/ 2&amp;gt;/dev/null | perl -ne &amp;#039;print $1 if /Current IP Address: (\d+\.\d+\.\d+\.\d+)/&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
curl -A &amp;quot;Mozilla/4.0&amp;quot; http://myip.dnsdynamic.org/ 2&amp;gt;/dev/null&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Wait for child pid to finish in background and report its status===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# submit a process to the background&lt;br /&gt;
export_schema1.ksh &amp;amp;&lt;br /&gt;
bgpid=$!&lt;br /&gt;
&lt;br /&gt;
while (ps -ef | grep $bgpid | grep -v grep); do&lt;br /&gt;
    # still running...&lt;br /&gt;
    sleep 600&lt;br /&gt;
done&lt;br /&gt;
&lt;br /&gt;
# should be finished&lt;br /&gt;
wait $bgpid&lt;br /&gt;
bgstatus=$?&lt;br /&gt;
echo background process ended with status $bgstatus&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/usr/bin/ksh&lt;br /&gt;
# submit a few processes to the background&lt;br /&gt;
# wait for them all to finish&lt;br /&gt;
# concat their logfiles&lt;br /&gt;
&lt;br /&gt;
(./sleeper.sh;echo &amp;quot;sleeper 1 finished&amp;quot;)&amp;gt;sleeper1.log &amp;amp;&lt;br /&gt;
PIDLIST=&amp;quot;$PIDLIST $!&amp;quot;&lt;br /&gt;
echo &amp;quot;PIDLIST is $PIDLIST ...&amp;quot;&lt;br /&gt;
sleep 5&lt;br /&gt;
&lt;br /&gt;
(./sleeper.sh;echo &amp;quot;sleeper 2 finished&amp;quot;)&amp;gt;sleeper2.log &amp;amp;&lt;br /&gt;
PIDLIST=&amp;quot;$PIDLIST $!&amp;quot;&lt;br /&gt;
echo &amp;quot;PIDLIST is $PIDLIST ...&amp;quot;&lt;br /&gt;
sleep 5&lt;br /&gt;
&lt;br /&gt;
(./sleeper.sh;echo &amp;quot;sleeper 3 finished&amp;quot;)&amp;gt;sleeper3.log &amp;amp;&lt;br /&gt;
PIDLIST=&amp;quot;$PIDLIST $!&amp;quot;&lt;br /&gt;
echo &amp;quot;PIDLIST is $PIDLIST ...&amp;quot;&lt;br /&gt;
sleep 5&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;Now 15 seconds later, we have 3 pids: $PIDLIST&amp;quot;&lt;br /&gt;
for PID in $PIDLIST; do&lt;br /&gt;
    wait $PID&lt;br /&gt;
    echo &amp;quot;$PID exited with status $?&amp;quot;&lt;br /&gt;
done&lt;br /&gt;
&lt;br /&gt;
# all jobs should have ended, concat their logs&lt;br /&gt;
cat sleeper*log &amp;gt; sleepers.log&lt;br /&gt;
cat sleepers.log&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Real world example&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/usr/bin/ksh&lt;br /&gt;
# ==============================================================================&lt;br /&gt;
# Name         : export_JDBEOP1.ksh&lt;br /&gt;
# Description  : Run export in pieces for performance reasons&lt;br /&gt;
#&lt;br /&gt;
# Parameters   : &lt;br /&gt;
#&lt;br /&gt;
# Notes        : Also decide whether to exclude PDARC schema or not&lt;br /&gt;
#                depending on what day it is&lt;br /&gt;
#&lt;br /&gt;
#&lt;br /&gt;
# Modification History&lt;br /&gt;
# ====================&lt;br /&gt;
# When      Who               What&lt;br /&gt;
# ========= ================= ==================================================&lt;br /&gt;
# 15-OCT-13 Stuart Barkley    Created&lt;br /&gt;
# ==============================================================================&lt;br /&gt;
&lt;br /&gt;
STARTTIME=`date &amp;#039;+%Y%m%d%H%M%S&amp;#039;`&lt;br /&gt;
DAYNO=`date +%u`&lt;br /&gt;
PROGNAME=`basename $0`&lt;br /&gt;
SCRIPTS_DIR=/home/tools/scripts/oracle&lt;br /&gt;
DATA_DIR=/oracle/JDBEOP1/admin/change&lt;br /&gt;
EXPORT_DIR=/oracle/export/JDBEOP1&lt;br /&gt;
&lt;br /&gt;
# marker so we can find our files later&lt;br /&gt;
MARKERFILE=/tmp/start_$PROGNAME_$$&lt;br /&gt;
touch $MARKERFILE&lt;br /&gt;
&lt;br /&gt;
$SCRIPTS_DIR/expdp_PARFILE.ksh -s JDBEOP1 -u PRODDTA -p 4 -k 2 -f $DATA_DIR/JDBEOP1_PRODDTA.parfile &amp;amp;&lt;br /&gt;
PIDLIST=&amp;quot;$PIDLIST $!&amp;quot;&lt;br /&gt;
echo &amp;quot;PIDLIST is $PIDLIST ...&amp;quot;&lt;br /&gt;
&lt;br /&gt;
$SCRIPTS_DIR/expdp_PARFILE.ksh -s JDBEOP1 -u PRODCTL -p 2 -k 2 -f $DATA_DIR/JDBEOP1_PRODCTL.parfile &amp;amp;&lt;br /&gt;
PIDLIST=&amp;quot;$PIDLIST $!&amp;quot;&lt;br /&gt;
echo &amp;quot;PIDLIST is $PIDLIST ...&amp;quot;&lt;br /&gt;
&lt;br /&gt;
$SCRIPTS_DIR/expdp_PARFILE.ksh -s JDBEOP1 -u NOPRODNOPDARC -p 4 -k 2 -f $DATA_DIR/JDBEOP1_NOPROD_NOPDARC.parfile &amp;amp;&lt;br /&gt;
PIDLIST=&amp;quot;$PIDLIST $!&amp;quot;&lt;br /&gt;
echo &amp;quot;PIDLIST is $PIDLIST ...&amp;quot;&lt;br /&gt;
&lt;br /&gt;
if [[ $DAYNO -eq 1 ]]; then&lt;br /&gt;
    $SCRIPTS_DIR/expdp_PARFILE.ksh -s JDBEOP1 -u NOPROD -p 4 -k 2 -f $DATA_DIR/JDBEOP1_NOPROD.parfile &amp;amp;&lt;br /&gt;
    PIDLIST=&amp;quot;$PIDLIST $!&amp;quot;&lt;br /&gt;
    echo &amp;quot;PIDLIST is $PIDLIST ...&amp;quot;&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
# now sit and wait for the exports to finish&lt;br /&gt;
for PID in $PIDLIST; do&lt;br /&gt;
    echo &amp;quot;waiting for pid $PID to finish&amp;quot;&lt;br /&gt;
    wait $PID&lt;br /&gt;
    echo &amp;quot;$PID exited with status $?&amp;quot;&lt;br /&gt;
done&lt;br /&gt;
&lt;br /&gt;
# collect all log files up into one&lt;br /&gt;
cd $EXPORT_DIR&lt;br /&gt;
for i in `find . -name &amp;quot;expdp_JDBEOP1*log&amp;quot; -newer $MARKERFILE`; do&lt;br /&gt;
    cat $i &amp;gt; expdp_JDBEOP1_D_FULL_${STARTTIME}.log&lt;br /&gt;
done&lt;br /&gt;
&lt;br /&gt;
rm $MARKLERFILE&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Create private DB link for a user without knowing his password===&lt;br /&gt;
* Inspired by [http://oradbatips.blogspot.co.uk/2010/01/tip-84-create-private-db-link-for-user.html oradbatips.blogspot.co.uk]&lt;br /&gt;
It uses a clever package, dbms_sys_sql.&amp;lt;br /&amp;gt;&lt;br /&gt;
Also useful for executing anything on behalf of another user.&amp;lt;br /&amp;gt;&lt;br /&gt;
Here is an example on how to create private database link for a user.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
create or replace procedure link_creator ( p_owner varchar2, p_dblink_name varchar2, p_username varchar2, p_password varchar2, p_address varchar2 ) as&lt;br /&gt;
    uid number;&lt;br /&gt;
    sqltext varchar2(1000) := &amp;#039;create [public] database link [link_name] connect to [username] identified by [password] using &amp;#039;&amp;#039;[address]&amp;#039;&amp;#039;&amp;#039;;&lt;br /&gt;
    myint integer;&lt;br /&gt;
begin&lt;br /&gt;
    if upper(p_owner) = &amp;#039;PUBLIC&amp;#039; then&lt;br /&gt;
        sqltext := replace(sqltext, &amp;#039;[public]&amp;#039;, &amp;#039;public&amp;#039;);&lt;br /&gt;
    else&lt;br /&gt;
        sqltext := replace(sqltext, &amp;#039;[public]&amp;#039;, &amp;#039;&amp;#039;);&lt;br /&gt;
    end if;&lt;br /&gt;
    sqltext := replace(sqltext, &amp;#039;[linkname]&amp;#039;, p_dblink_name);&lt;br /&gt;
    sqltext := replace(sqltext, &amp;#039;[username]&amp;#039;, p_username);&lt;br /&gt;
    sqltext := replace(sqltext, &amp;#039;[password]&amp;#039;, p_password);&lt;br /&gt;
    sqltext := replace(sqltext, &amp;#039;[address]&amp;#039;, p_address);&lt;br /&gt;
&lt;br /&gt;
    select user_id&lt;br /&gt;
    into   uid&lt;br /&gt;
    from   dba_users&lt;br /&gt;
    where  username = decode(upper(p_owner), &amp;#039;PUBLIC&amp;#039;, &amp;#039;SYS&amp;#039;, p_owner)&lt;br /&gt;
    ;&lt;br /&gt;
    myint:=sys.dbms_sys_sql.open_cursor();&lt;br /&gt;
    sys.dbms_sys_sql.parse_as_user ( myint, sqltext, dbms_sql.native, uid );&lt;br /&gt;
    sys.dbms_sys_sql.close_cursor(myint);&lt;br /&gt;
end;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Here we can generate SQL to rebuild the links for future use. Note the password is no longer stored in this column.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set pages 1000&lt;br /&gt;
select &amp;#039;begin link_creator ( &amp;#039;&amp;#039;&amp;#039;|| u.name ||&amp;#039;&amp;#039;&amp;#039;,&amp;#039;&amp;#039;&amp;#039;|| l.name ||&amp;#039;&amp;#039;&amp;#039;,&amp;#039;&amp;#039;&amp;#039;|| l.userid ||&amp;#039;&amp;#039;&amp;#039;,&amp;#039;&amp;#039;&amp;#039;|| l.password ||&amp;#039;&amp;#039;&amp;#039;,&amp;#039;&amp;#039;&amp;#039;|| l.host ||&amp;#039;&amp;#039;&amp;#039;); end;&amp;#039;|| chr(10) ||&amp;#039;/&amp;#039; link_text&lt;br /&gt;
from   sys.link$ l&lt;br /&gt;
,      sys.user$ u&lt;br /&gt;
where  l.owner# = u.user#&lt;br /&gt;
;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Another method to create a db_link from sys on behalf of a user is to create a procedure under that users name that does the db link creation====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
grant create database link to &amp;amp;&amp;amp;user;&lt;br /&gt;
&lt;br /&gt;
create or replace procedure &amp;amp;user..create_db_link as&lt;br /&gt;
begin&lt;br /&gt;
    execute immediate &amp;#039;create database link &amp;amp;link_name connect to &amp;amp;user identified by &amp;amp;users_password using &amp;#039;&amp;#039;&amp;amp;tns_connect_identifier&amp;#039;&amp;#039;&amp;#039;;&lt;br /&gt;
end create_db_link;&lt;br /&gt;
&lt;br /&gt;
exec &amp;amp;user..create_db_link;&lt;br /&gt;
&lt;br /&gt;
revoke create database link from &amp;amp;user;&lt;br /&gt;
&lt;br /&gt;
drop procedure &amp;amp;user..create_db_link;&lt;br /&gt;
undef user&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Create a comma separated list of columns from a select statement===&lt;br /&gt;
Method 1:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SELECT parent_id,&lt;br /&gt;
       RTRIM(XMLAGG(XMLELEMENT(e,child_id || &amp;#039;,&amp;#039;)).EXTRACT(&amp;#039;//text()&amp;#039;),&amp;#039;,&amp;#039;) AS &amp;quot;Children&amp;quot;&lt;br /&gt;
FROM   parentChildTable&lt;br /&gt;
WHERE  parent_id = 0&lt;br /&gt;
GROUP  BY parent_id&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SELECT parent_id,&lt;br /&gt;
       LISTAGG(child_id, &amp;#039;,&amp;#039;) WITHIN GROUP (ORDER BY child_id) AS &amp;quot;Children&amp;quot;&lt;br /&gt;
  FROM parentChildTable&lt;br /&gt;
 WHERE parent_id = 0&lt;br /&gt;
 GROUP BY parent_id&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Method 2 (undocumented and cannot therefore be relied on to continue working in the same manner):&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SELECT wmsys.wm_concat(&amp;lt;column_name&amp;gt;)&lt;br /&gt;
FROM &amp;lt;table_name&amp;gt;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Start an instant one-line webserver in current directory===&lt;br /&gt;
Need to quickly share/copy a file or read an html file on Linux? Start a web server!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
python -m SimpleHTTPServer 8000&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
and point your browser to http://localhost:8000&amp;lt;br /&amp;gt;&lt;br /&gt;
or&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
while true; do nc -l -p 80 -q 1 &amp;lt; index.html; done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Get SQL*Plus to generate HTML===&lt;br /&gt;
* [http://docs.oracle.com/cd/E11882_01/server.112/e16604/ch_seven.htm#CHDCECJG official guide]&lt;br /&gt;
One way to do it... use -m(arkup) option to specify:&amp;lt;br /&amp;gt;&lt;br /&gt;
html on/off - specifies whether to output html output or not&lt;br /&gt;
head - specify your own customised head contents&amp;lt;br /&amp;gt;&lt;br /&gt;
spool off - as a part of the -m tag means do not print the default &amp;amp;lt;html&amp;amp;gt;, &amp;amp;lt;head&amp;amp;gt; and &amp;amp;lt;body&amp;amp;gt; tags&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sqlplus -m &amp;quot;html on head &amp;#039;&amp;lt;link rel=&amp;quot;stylesheet&amp;quot; href=&amp;quot;/dbamon_golden.css&amp;quot; type=&amp;quot;text/css&amp;quot; /&amp;gt;&amp;#039; spool off&amp;quot; / as sysdba&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sqlplus / as sysdba&lt;br /&gt;
set markup html on head &amp;#039;&amp;lt;link rel=&amp;quot;stylesheet&amp;quot; href=&amp;quot;/dbamon_golden.css&amp;quot; type=&amp;quot;text/css&amp;quot; /&amp;gt;&amp;#039; body &amp;quot;&amp;quot; table &amp;quot;&amp;quot; spool off&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
besides html and head, you can also specify:&amp;lt;br /&amp;gt;&lt;br /&gt;
body - specify your own customised body attributes&amp;lt;br /&amp;gt;&lt;br /&gt;
table - override the default table options&amp;lt;br /&amp;gt;&lt;br /&gt;
entmap - turn on or off the html replacement characters (&amp;amp;lt, &amp;amp;gt, etc...)&amp;lt;br /&amp;gt;&lt;br /&gt;
preformat - uses the &amp;amp;lt;pre&amp;amp;gt; tag to format output exactly as required&amp;lt;br /&amp;gt;&lt;br /&gt;
* another little gem...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
----------------------------------------&lt;br /&gt;
-- get the last SQL*Plus output in HTML&lt;br /&gt;
-- after Tanel Poder&lt;br /&gt;
----------------------------------------&lt;br /&gt;
&lt;br /&gt;
set termout off&lt;br /&gt;
&lt;br /&gt;
set markup HTML ON HEAD &amp;quot; -&lt;br /&gt;
 -&lt;br /&gt;
&amp;quot; -&lt;br /&gt;
BODY &amp;quot;&amp;quot; -&lt;br /&gt;
TABLE &amp;quot;border=&amp;#039;1&amp;#039; align=&amp;#039;center&amp;#039; summary=&amp;#039;Script output&amp;#039;&amp;quot; -&lt;br /&gt;
SPOOL ON ENTMAP ON PREFORMAT OFF&lt;br /&gt;
&lt;br /&gt;
spool myoutput.html&lt;br /&gt;
&lt;br /&gt;
l&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
spool off&lt;br /&gt;
set markup html off spool off&lt;br /&gt;
host firefox myoutput.html&lt;br /&gt;
set termout on&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===HTML SELECT - Trigger JavaScript ONCHANGE event even when the option is not changed===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;select onchange=&amp;quot;jsFunction()&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;option value=&amp;quot;&amp;quot; disabled selected style=&amp;quot;display:none;&amp;quot;&amp;gt;Label&amp;lt;/option&amp;gt;&lt;br /&gt;
  &amp;lt;option value=&amp;quot;1&amp;quot;&amp;gt;1&amp;lt;/option&amp;gt;&lt;br /&gt;
  &amp;lt;option value=&amp;quot;2&amp;quot;&amp;gt;2&amp;lt;/option&amp;gt;&lt;br /&gt;
  &amp;lt;option value=&amp;quot;3&amp;quot;&amp;gt;3&amp;lt;/option&amp;gt;&lt;br /&gt;
&amp;lt;/select&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Display horizontal bar graph in HTML table data cell===&lt;br /&gt;
Using Perl&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
print (&amp;#039;&amp;lt;td class=&amp;quot;left&amp;quot;&amp;gt;&amp;#039; .&lt;br /&gt;
            &amp;#039;&amp;lt;div style=&amp;quot;background-color:#8097BE;width:&amp;quot;&amp;#039;,$allocpercused  ,&amp;#039;%;&amp;quot; /&amp;gt;&amp;#039; .&lt;br /&gt;
            &amp;#039;&amp;lt;div style=&amp;quot;background-color:red;    width:&amp;quot;&amp;#039;,$automaxpercused,&amp;#039;%;&amp;quot; /&amp;gt;&amp;#039; .&lt;br /&gt;
            $tspace .&lt;br /&gt;
       &amp;#039;&amp;lt;/td&amp;gt;&amp;#039;&lt;br /&gt;
);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Depending on which way around the divs are, you get different interpretations&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
print (&amp;quot;&amp;lt;td class=\&amp;quot;left\&amp;quot;&amp;gt;&amp;quot; .&lt;br /&gt;
            &amp;quot;&amp;lt;div style=\&amp;quot;border-right:2px solid red; width:&amp;quot;,($automaxpercused&amp;gt;99)?(100):($automaxpercused),&amp;quot;%;\&amp;quot; /&amp;gt;&amp;quot; .&lt;br /&gt;
            &amp;quot;&amp;lt;div style=\&amp;quot;background-color:#8097BE;width:&amp;quot;,$allocpercused  ,&amp;quot;%;\&amp;quot; /&amp;gt;&amp;quot; .&lt;br /&gt;
            $tspace .&lt;br /&gt;
       &amp;quot;&amp;lt;/td&amp;gt;&amp;quot;&lt;br /&gt;
);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====References====&lt;br /&gt;
* [http://stackoverflow.com/questions/5324996/comma-separated-list-as-a-result-of-select-statement-in-oracle stackoverflow.com]&lt;br /&gt;
* [http://www.salvis.com/blog/?p=207 A whole page showing how to do it in all versions back to 7!]&lt;/div&gt;</summary>
		<author><name>Stuart</name></author>	</entry>

	<entry>
		<id>https://mailnest.com/dbawiki/index.php?title=Backup_and_Recovery&amp;diff=3393</id>
		<title>Backup and Recovery</title>
		<link rel="alternate" type="text/html" href="https://mailnest.com/dbawiki/index.php?title=Backup_and_Recovery&amp;diff=3393"/>
				<updated>2018-12-04T10:44:19Z</updated>
		
		<summary type="html">&lt;p&gt;Stuart: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;* [[RMAN]]&lt;br /&gt;
* [[Datapump]]&lt;br /&gt;
* [[TSM]]&lt;br /&gt;
* [[Tivoli Data Protection for Oracle (TDPO)]]&lt;/div&gt;</summary>
		<author><name>Stuart</name></author>	</entry>

	<entry>
		<id>https://mailnest.com/dbawiki/index.php?title=Data_Pump&amp;diff=3392</id>
		<title>Data Pump</title>
		<link rel="alternate" type="text/html" href="https://mailnest.com/dbawiki/index.php?title=Data_Pump&amp;diff=3392"/>
				<updated>2018-12-04T10:43:25Z</updated>
		
		<summary type="html">&lt;p&gt;Stuart: Blanked the page&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Stuart</name></author>	</entry>

	<entry>
		<id>https://mailnest.com/dbawiki/index.php?title=Datapump&amp;diff=3390</id>
		<title>Datapump</title>
		<link rel="alternate" type="text/html" href="https://mailnest.com/dbawiki/index.php?title=Datapump&amp;diff=3390"/>
				<updated>2018-12-04T10:43:02Z</updated>
		
		<summary type="html">&lt;p&gt;Stuart: Stuart moved page Data Pump to Datapump&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;* [http://jensenmo.blogspot.be/2012/10/optimising-data-pump-export-and-import.html Morten Jensen&amp;#039;s tips for Optimising Data Pump Export and Import Performance]&lt;br /&gt;
* [http://oradbastuff.blogspot.co.uk/2011/11/expdp-slow-after-upgrade-from-11106-to.html expdp slow after upgrade]&lt;br /&gt;
===Use the flashback parameter to export and import a consistent dump===&lt;br /&gt;
&lt;br /&gt;
This performs a consistent dump of 2 schemas&amp;lt;br /&amp;gt;&lt;br /&gt;
Keeping the parameters in a file allows it to be reused for the import:&lt;br /&gt;
&lt;br /&gt;
 expdp system/***** parfile=db_params.par&lt;br /&gt;
&lt;br /&gt;
where db_params.par would look like this:&lt;br /&gt;
 flashback_time=systimestamp&lt;br /&gt;
 directory=DATA_PUMP_DIR&lt;br /&gt;
 dumpfile=db_schemas.dmp&lt;br /&gt;
 logfile=db_schemas.log&lt;br /&gt;
 schemas=(apps,test)&lt;br /&gt;
&lt;br /&gt;
The SCN that most closely matches the specified time(stamp) is found, and this SCN is used to enable the Flashback utility.&amp;lt;br /&amp;gt;&lt;br /&gt;
The export operation is performed with data that is consistent as of this SCN.&amp;lt;br /&amp;gt;&lt;br /&gt;
By default expdp is consistent only for the table it is currently exporting. Use &amp;#039;flashback_time=systimestamp&amp;#039; to simulate the old export &amp;#039;consistent=y&amp;#039;&lt;br /&gt;
&lt;br /&gt;
===Typical export with Data Pump===&lt;br /&gt;
This method is useful to dynamically build a script.&lt;br /&gt;
Note the %u to generate the parallel file names...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SID=$1&lt;br /&gt;
TIMESTAMP=`date +&amp;#039;%Y%m%d%H%M%S&amp;#039;`&lt;br /&gt;
FLASHBACK_TO=&amp;quot;to_timestamp(&amp;#039;13-02-2018 13:35:00&amp;#039;, &amp;#039;DD-MM-YYYY HH24:MI:SS&amp;#039;)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
expdp &amp;quot;/&amp;quot;                                                  \&lt;br /&gt;
dumpfile=expdp_${SID}_D_FULL_${TIMESTAMP}_%u.dmp           \&lt;br /&gt;
logfile=expdp_${SID}_D_FULL_${TIMESTAMP}.log               \&lt;br /&gt;
job_name=expdp_${SID}_D_FULL_${TIMESTAMP}                  \&lt;br /&gt;
flashback_time=${FLASHBACK_TO}                             \&lt;br /&gt;
directory=data_pump_dir                                    \&lt;br /&gt;
reuse_dumpfiles=y                                          \&lt;br /&gt;
parallel=8                                                 \&lt;br /&gt;
full=y                                                     \&lt;br /&gt;
exclude=statistics&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Reduce the amount of data exported/imported with clauses like these...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
exclude=table:&amp;quot;in (select table_name from dba_tables where owner = &amp;#039;eucvdta&amp;#039;  and table_name like &amp;#039;F4%&amp;#039;)&amp;quot;  \&lt;br /&gt;
exclude=table:&amp;quot;in (select table_name from dba_tables where owner = &amp;#039;eucrpdta&amp;#039;  and table_name like &amp;#039;F4%&amp;#039;)&amp;quot; \&lt;br /&gt;
query=prd1.op_log:&amp;#039;&amp;quot;where trunc(creation_date) &amp;gt; trunc(sysdate-7)&amp;quot;&amp;#039;   \&lt;br /&gt;
QUERY=SIM_HEADER:&amp;quot;WHERE run_time &amp;gt; (SELECT TRUNC(MAX(run_time))-7 FROM sim_header) OR run_time IN (SELECT TRUNC(run_time, &amp;#039;YEAR&amp;#039;)-1 FROM sim_header)&amp;quot;&lt;br /&gt;
QUERY=SIM_BLOB:&amp;quot;WHERE sim_run_id &amp;gt; (SELECT MIN(sim_run_id) FROM sim_header WHERE run_time &amp;gt; (SELECT TRUNC(MAX(run_time))-7 FROM sim_header)) OR sim_run_id IN (SELECT sim_run_id FROM sim_header WHERE run_time IN (SELECT TRUNC(run_time, &amp;#039;YEAR&amp;#039;)-1 FROM sim_header))&amp;quot;&lt;br /&gt;
QUERY=SIM_HEADER_DETAILS: &amp;quot;WHERE sim_run_id &amp;gt; (SELECT MIN(sim_run_id) FROM sim_header WHERE run_time &amp;gt; (SELECT TRUNC(MAX(run_time))-7 FROM sim_header)) OR sim_run_id IN (SELECT sim_run_id FROM sim_header WHERE run_time IN (SELECT TRUNC(run_time, &amp;#039;YEAR&amp;#039;)-1 FROM sim_header))&amp;quot;&lt;br /&gt;
QUERY=SIM_DETAILS_BLOB: &amp;quot;WHERE unique_sim_key IN (SELECT unique_sim_key FROM sim_header_details WHERE sim_run_id &amp;gt; (SELECT MIN(sim_run_id) FROM sim_header WHERE run_time &amp;gt; (SELECT TRUNC(MAX(run_time))-7 FROM sim_header)) OR sim_run_id IN (SELECT sim_run_id FROM sim_header WHERE run_time IN (SELECT TRUNC(run_time, &amp;#039;YEAR&amp;#039;)-1 FROM sim_header)))&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Could be made neater by using a parfile...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
expdp / parfile=/home/ibmtools/etc/oracle/nhapplp1_full.parfile&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
and the parfile could look like this&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
full=y&lt;br /&gt;
reuse_dumpfiles=y&lt;br /&gt;
compression=all&lt;br /&gt;
exclude=statistics&lt;br /&gt;
parallel=6&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Datapump pitfalls/gotchas===&lt;br /&gt;
* Exclude a single table from a full export&lt;br /&gt;
If you have a par file like this and expect it to work, you will be disappointed:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
exclude=table:&amp;quot;in (&amp;#039;scott.emp&amp;#039;)&amp;quot;&lt;br /&gt;
full=y&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The emp table will be exported!&amp;lt;br /&amp;gt;&lt;br /&gt;
To get this to work, you need to use a trick...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
query=scott.emp:&amp;quot;where rownum &amp;lt; 1&amp;quot;&lt;br /&gt;
full=y&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
* exclude and include are conceptually different...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
exclude=function:&amp;quot;in (&amp;#039;scott.raise_sal&amp;#039;)&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
is not the same as&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
include=function:&amp;quot;not in (&amp;#039;scott.raise_sal&amp;#039;)&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
the first one does what you think it will do... it exports all objects except a function called raise_sal owned by scott.&amp;lt;br /&amp;gt;&lt;br /&gt;
the second one, convoluted though it is, will not do what you might think. It exports all functions (and only functions) except raise_sal owned by scott.&lt;br /&gt;
===Find partition ed tables in database===&lt;br /&gt;
Before converting a database from Enterprise Edition to Standard Edition (Metalink: 139642.1), partitioned tables will need to be merged (as Standard Edition does not allow them)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select table_name&lt;br /&gt;
,      count(partition_name)&lt;br /&gt;
from   dba_tab_partitions&lt;br /&gt;
where  1=1&lt;br /&gt;
and    table_owner not in (&amp;#039;SYS&amp;#039;,&amp;#039;SYSTEM&amp;#039;,&amp;#039;PUBLIC&amp;#039;,&amp;#039;CTXSYS&amp;#039;,&amp;#039;MDSYS&amp;#039;,&amp;#039;AUDSYS&amp;#039;)&lt;br /&gt;
group  by table_name&lt;br /&gt;
order  by 1;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Get more detailed information while Data pump is working===&lt;br /&gt;
To get an idea of how long it takes to export each object, add this to the parfile (or command line)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
metrics=y&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Keep the master table after a successful data pump session===&lt;br /&gt;
To see what went on in the master table, add this to the parfile (or command line)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
keep_master=y&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The master table contains all the data pump log messages.&amp;lt;br /&amp;gt;&lt;br /&gt;
It is used to track the detailed progress of a Data Pump job - which is more than the log messages.&amp;lt;br /&amp;gt;&lt;br /&gt;
Amongst other things it conatins:&lt;br /&gt;
* Completed rows of a table.&lt;br /&gt;
* Total number of errors during data pump operation.&lt;br /&gt;
* Elapsed time for each table to do data pump export/import operation.&lt;br /&gt;
* The current set of dump files.&lt;br /&gt;
* The current state of every object exported or imported and their locations in the dump file set.&lt;br /&gt;
* The job&amp;#039;s user-supplied parameters.&lt;br /&gt;
* The status of every worker process.&lt;br /&gt;
* The state of current job status and restart information.&lt;br /&gt;
* The dump file location, the directory name information.&lt;br /&gt;
===Trace the Data pump job===&lt;br /&gt;
* More info here: [https://dbasolutions.wikispaces.com/Expdp+-+Trace https://dbasolutions.wikispaces.com/Expdp+-+Trace]&lt;br /&gt;
Tracing can be enabled by specifying an 7 digit hexadecimal mask in the TRACE parameter of expdp or impdp.&amp;lt;br /&amp;gt;&lt;br /&gt;
The first three digits enable tracing for a specific DataPump component, while the last four digits are usually: 0300.&amp;lt;br /&amp;gt;&lt;br /&gt;
Any leading zero’s can be omitted, and the value specified for the TRACE parameter is not case sensitive.&amp;lt;br /&amp;gt;&lt;br /&gt;
TRACE does not add anything to the output of DataPump, it creates additional trace files.&amp;lt;br /&amp;gt;&lt;br /&gt;
Add TRACE=&amp;lt;hex digits below&amp;gt; to the parfile (or command line)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Here is a summary of the Data Pump trace levels:&lt;br /&gt;
  10300 SHDW: To trace the Shadow process&lt;br /&gt;
  20300 KUPV: To trace Fixed table&lt;br /&gt;
  40300 &amp;#039;div&amp;#039; To trace Process services&lt;br /&gt;
  80300 KUPM: To trace Master Control Process&lt;br /&gt;
 100300 KUPF: To trace File Manager&lt;br /&gt;
 200300 KUPC: To trace Queue services&lt;br /&gt;
 400300 KUPW: To trace Worker process(es)        &lt;br /&gt;
 800300 KUPD: To trace Data Package&lt;br /&gt;
1000300 META: To trace Metadata Package&lt;br /&gt;
1FF0300 &amp;#039;all&amp;#039; To trace all components, full tracing&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====To trace an already running export job====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
expdp system/manager attach=sys_export_full_01&lt;br /&gt;
Export&amp;gt; stop&lt;br /&gt;
expdp system/manager attach=sys_export_full_01 trace=480300&lt;br /&gt;
Export&amp;gt; cont&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Check to see if the objects can be recovered from the recyclebin===&lt;br /&gt;
This would save time restoring from tape/dumps&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select original_name,ts_name,operation,droptime,can_undrop from dba_recyclebin where owner=&amp;#039;PRODDTA&amp;#039; order by droptime;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
flashback table proddta.F5642026 to before drop;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Check the indexes and restore as necessary...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select index_name from dba_indexes where owner = &amp;#039;PRODDTA&amp;#039; and table_name = &amp;#039;F5642026&amp;#039;;&lt;br /&gt;
alter index &amp;quot;bin$dbo9uchtzsbgqfemiadccq==$0&amp;quot; rename to proddta.F5642026_IX;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Import tables from a dump file into a schema===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
impdp \&amp;#039;/ as sysdba\&amp;#039; parfile=import_tables.par&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
where import_tables.par looks something like this&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
directory=DATA_PUMP_DIR_JDBEOP1&lt;br /&gt;
dumpfile=expdp_JDBEOP1_D_PRODDTA_20131007200000_%U.dmp&lt;br /&gt;
logfile=RESTORE_20131012.log&lt;br /&gt;
job_name=RESTORE_20131012&lt;br /&gt;
tables=(PRODDTA.F47032,PRODDTA.F47031,PRODDTA.F47022,PRODDTA.F47021,PRODDTA.F4311Z1,PRODDTA.F4301Z1)&lt;br /&gt;
remap_schema=PRODDTA:DMIRROR&lt;br /&gt;
remap_tablespace=PRODDTAT:RESTORE_TS_2013&lt;br /&gt;
remap_tablespace=PRODDTAI:RESTORE_TS_2013&lt;br /&gt;
table_exists_action=replace&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
where directory has already been created with&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
create or replace directory DATA_PUMP_DIR_JDBEOP1 as &amp;#039;/oracle/export/ubenoa26_jdbeop1&amp;#039;;&lt;br /&gt;
grant read,write on &amp;lt;DATA_PUMP_DIR_JDBEOP1 to OPS$IMPDP;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====without a par file and with a transform to ignore table creation attributes====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
impdp \&amp;#039;/ as sysdba\&amp;#039;                        \&lt;br /&gt;
    DIRECTORY=DATA_PUMP_DIR                  \&lt;br /&gt;
    tables=SY812.F00950,SY812.F95921         \&lt;br /&gt;
    transform=segment_attributes:n           \&lt;br /&gt;
    parallel=5                               \&lt;br /&gt;
    remap_schema=SY812:QAC_REPORT_TEST       \&lt;br /&gt;
    remap_tablespace=SY812T:QAC_REPORT_TEST  \&lt;br /&gt;
    dumpfile=expdp_JDB_20140531200001_%u.dmp \&lt;br /&gt;
    job_name=impdp_SY812                     \&lt;br /&gt;
    logfile=impdp_JDBEOP1_SY812.log&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====replace existing tables in an existing schema====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
impdp \&amp;#039;/ as sysdba\&amp;#039;                                      \&lt;br /&gt;
    directory=data_pump_dir                                \&lt;br /&gt;
    tables=proddta.F5642026,proddta.F596111                \&lt;br /&gt;
    transform=segment_attributes:n                         \&lt;br /&gt;
    parallel=5                                             \          &lt;br /&gt;
    dumpfile=expdp_JDBEOP1_D_PRODDTA_20140725210000_%u.dmp \&lt;br /&gt;
    job_name=impdp_JDBEOP1_D_PRODDTA_F5642026_F596111      \&lt;br /&gt;
    logfile=impdp_JDBEOP1_D_PRODDTA_F5642026_F596111.log&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====import existing tables into a different schema====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
impdp \&amp;#039;/ as sysdba\&amp;#039;                                                          \&lt;br /&gt;
directory=data_pump_dir                                                        \&lt;br /&gt;
tables=DWH.FACT_OPEX,DWH.FACT_OPEX_PTC,DWH.FACT_AFIN_SCEN,DWH.FACT_AFIN_PTC    \&lt;br /&gt;
remap_schema=DWH:_kantal                                                       \&lt;br /&gt;
remap_tablespace=USERS:TOOLS,INDX:TOOLS                                        \&lt;br /&gt;
dumpfile=backup_export_10g_CODWHP1_20151104210000_%u.dmp                       \&lt;br /&gt;
job_name=import_DWH_TABLES                                                     \&lt;br /&gt;
logfile=import_DWH_TABLES.log &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====import existing partitioned tables into a different schema====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
impdp \&amp;#039;/ as sysdba\&amp;#039;                                                          \&lt;br /&gt;
directory=data_pump_dir                                                        \&lt;br /&gt;
tables=TIP_PRD1.EODMARKETPNL:SYS_P1751,TIP_PRD1.PHYSICALPOSITION:SYS_P16591    \&lt;br /&gt;
remap_schema=DWH:_kantal                                                       \&lt;br /&gt;
remap_tablespace=USERS:TOOLS,INDX:TOOLS                                        \&lt;br /&gt;
dumpfile=backup_export_10g_CODWHP1_20151104210000_%u.dmp                       \&lt;br /&gt;
job_name=import_DWH_TABLES                                                     \&lt;br /&gt;
logfile=import_DWH_TABLES.log &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Processing object type SCHEMA_EXPORT/TABLE/INDEX/FUNCTIONAL_INDEX/INDEX===&lt;br /&gt;
Import is taking a long time and stuck on this line. Is it waiting for something or just slow?&amp;lt;br /&amp;gt;&lt;br /&gt;
Datapump does not import indexes, it recreates them using create index statements. This can be slow, especially as all the metadata uses just 1 worker.&lt;br /&gt;
====Check the status of the job====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select * from dba_datapump_jobs;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Check to see if the impdp session is waiting for resources====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select vsw.*&lt;br /&gt;
from   dba_datapump_sessions dds&lt;br /&gt;
,      v$session vs&lt;br /&gt;
,      v$session_wait vsw&lt;br /&gt;
where  dds.saddr = vs.saddr&lt;br /&gt;
and    vs.sid    = vsw.sid&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Check dba_resumable for data pump jobs====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select * from dba_resumable;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Check alert log for possible error/warning messages====&lt;br /&gt;
&lt;br /&gt;
===Find out what Datapump jobs are running===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SET lines 200&lt;br /&gt;
COL owner_name FORMAT a10;&lt;br /&gt;
COL job_name FORMAT a20&lt;br /&gt;
COL state FORMAT a11&lt;br /&gt;
COL operation LIKE state&lt;br /&gt;
COL job_mode LIKE state&lt;br /&gt;
&lt;br /&gt;
SELECT job_name&lt;br /&gt;
,      owner_name&lt;br /&gt;
,      operation&lt;br /&gt;
,      job_mode&lt;br /&gt;
,      state&lt;br /&gt;
,      attached_sessions&lt;br /&gt;
FROM   dba_datapump_jobs&lt;br /&gt;
WHERE  1=1&lt;br /&gt;
and    job_name NOT LIKE &amp;#039;BIN$%&amp;#039;&lt;br /&gt;
ORDER  BY 2,1&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
JOB_NAME             OWNER_NAME OPERATION   JOB_MODE    STATE       ATTACHED_SESSIONS&lt;br /&gt;
-------------------- ---------- ----------- ----------- ----------- -----------------&lt;br /&gt;
EXP_20131018100328   OPS$ORADP  EXPORT      FULL        EXECUTING                   1&lt;br /&gt;
&lt;br /&gt;
SQL&amp;gt; &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Kill a datapump job with PL/SQL===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SET serveroutput on&lt;br /&gt;
SET lines 100&lt;br /&gt;
DECLARE&lt;br /&gt;
    l_handle NUMBER;&lt;br /&gt;
BEGIN&lt;br /&gt;
    l_handle := DBMS_DATAPUMP.ATTACH(&amp;#039;EXP_20131018100328&amp;#039;,&amp;#039;OPS$ORADP&amp;#039;);&lt;br /&gt;
    DBMS_DATAPUMP.STOP_JOB (l_handle,1,0);&lt;br /&gt;
END;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Connect to a running export Datapump job from command line===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
expdp / attach=&amp;quot;expdp_JDBEOT21_D_FULL_20130228143835&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
expdp \&amp;#039;/ as sysdba\&amp;#039; attach=&amp;quot;expdp_JDBEOT21_D_FULL_20130228143835&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Suspend a running data pump===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
stop_job&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Restart a previously suspended data pump job===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
start_job&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Terminate a data pump job===&lt;br /&gt;
Also kills the operating system processes&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
kill_job&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Drop erroneous Data Pump master tables===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select &amp;#039;DROP TABLE &amp;#039;||owner||&amp;#039;.&amp;#039;||table_name||&amp;#039; purge;&amp;#039;&lt;br /&gt;
from   dba_tables&lt;br /&gt;
where  1=1&lt;br /&gt;
and    table_name like &amp;#039;%SYS%EXPORT%&amp;#039;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
and&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set pages 100 lines 200&lt;br /&gt;
select &amp;#039;drop table &amp;quot;&amp;#039; || o.owner||&amp;#039;&amp;quot;.&amp;quot;&amp;#039;||object_name || &amp;#039;&amp;quot; purge;&amp;#039;&lt;br /&gt;
from   dba_objects o&lt;br /&gt;
,      dba_datapump_jobs j&lt;br /&gt;
where  1=1&lt;br /&gt;
and    o.owner       = j.owner_name&lt;br /&gt;
and    o.object_name = j.job_name&lt;br /&gt;
and    j.state      != &amp;#039;EXECUTING&amp;#039;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Did the import work?===&lt;br /&gt;
Moving a database with Data pump? Check the number of rows imported against those exported!&amp;lt;br /&amp;gt;&lt;br /&gt;
I noticed that sometimes, maybe tables with BLOB/LOB columns?, that the import does not import all rows...&amp;lt;br /&amp;gt;&lt;br /&gt;
eg:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Processing object type DATABASE_EXPORT/SCHEMA/TABLE/PRE_TABLE_ACTION&lt;br /&gt;
Processing object type DATABASE_EXPORT/SCHEMA/TABLE/TABLE_DATA&lt;br /&gt;
. . imported &amp;quot;WM712&amp;quot;.&amp;quot;BIZDOCCONTENT&amp;quot;                     104.8 GB       0 out of 10389777 rows&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Run this on the import logfile to check for this condition&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cat import_WM712P.log | perl -ne &amp;#039;if (m/(\d+) out of (\d+) rows/) { print if $1 != $2; }&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or a more thorough approach... count the number of records in all tables both locally and remotely for comparison.&amp;lt;br /&amp;gt;&lt;br /&gt;
Change value for l_remote_tns. File in csv format is created in DATA_PUMP_DIR.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set serveroutput on&lt;br /&gt;
declare&lt;br /&gt;
    cursor c_tables is&lt;br /&gt;
    select owner&lt;br /&gt;
    ,      table_name&lt;br /&gt;
    from   dba_tables&lt;br /&gt;
    where  1=1&lt;br /&gt;
    and    tablespace_name not in (&amp;#039;SYSTEM&amp;#039;,&amp;#039;SYSAUX&amp;#039;,&amp;#039;TEMP&amp;#039;)&lt;br /&gt;
    ;&lt;br /&gt;
    l_remote_tns       varchar2(100) := &amp;#039;wm712windows&amp;#039;;&lt;br /&gt;
    l_sql              varchar2(240) := null;&lt;br /&gt;
    l_local_row_count  number        := 0;&lt;br /&gt;
    l_remote_row_count number        := 0;&lt;br /&gt;
    f_file             utl_file.file_type;&lt;br /&gt;
begin&lt;br /&gt;
    dbms_output.enable(null);&lt;br /&gt;
    f_file := utl_file.fopen(&amp;#039;DATA_PUMP_DIR&amp;#039;,&amp;#039;table_row_count.csv&amp;#039;,&amp;#039;W&amp;#039;);&lt;br /&gt;
    utl_file.put_line (f_file, &amp;#039;Table;Local;Remote&amp;#039;);&lt;br /&gt;
    for r_tables in c_tables&lt;br /&gt;
    loop&lt;br /&gt;
        l_sql := &amp;#039;select count(1) into :l_local_row_count from &amp;#039;||r_tables.owner||&amp;#039;.&amp;#039;||r_tables.table_name;&lt;br /&gt;
        execute immediate l_sql into l_local_row_count;&lt;br /&gt;
        l_sql := &amp;#039;select count(1) into :l_remote_row_count from &amp;#039;||r_tables.owner||&amp;#039;.&amp;#039;||r_tables.table_name||&amp;#039;@&amp;#039;||l_remote_tns;&lt;br /&gt;
        l_remote_row_count := 0;&lt;br /&gt;
        begin&lt;br /&gt;
            execute immediate l_sql into l_remote_row_count;&lt;br /&gt;
        exception&lt;br /&gt;
        when others then&lt;br /&gt;
            null;&lt;br /&gt;
        end;&lt;br /&gt;
        --dbms_output.put_line (r_tables.owner||&amp;#039;.&amp;#039;||r_tables.table_name||&amp;#039;;&amp;#039;||l_local_row_count||&amp;#039;;&amp;#039;||l_remote_row_count);&lt;br /&gt;
        utl_file.put_line (f_file, r_tables.owner||&amp;#039;.&amp;#039;||r_tables.table_name||&amp;#039;;&amp;#039;||l_remote_row_count||&amp;#039;;&amp;#039;||l_local_row_count);&lt;br /&gt;
    end loop;&lt;br /&gt;
    utl_file.fclose (f_file);&lt;br /&gt;
exception&lt;br /&gt;
when others then&lt;br /&gt;
    dbms_output.put_line(&amp;#039;Problem: &amp;#039;||sqlerrm);&lt;br /&gt;
end;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Import into schemas and tablespaces other than those contained in the export dump file===&lt;br /&gt;
These will have to be manually pre-created&lt;br /&gt;
 CREATE USER MACHPENAL PROFILE &amp;quot;DEFAULT&amp;quot; IDENTIFIED BY ****** DEFAULT TABLESPACE &amp;quot;ACCMACH&amp;quot; TEMPORARY TABLESPACE &amp;quot;MACH_TEMP&amp;quot; QUOTA UNLIMITED ON &amp;quot;ACCMACH&amp;quot; QUOTA UNLIMITED ON &amp;quot;MACHX_TBS&amp;quot; ACCOUNT UNLOCK;&lt;br /&gt;
 GRANT ALTER SESSION TO &amp;quot;MACHPENAL&amp;quot;;&lt;br /&gt;
 GRANT CREATE JOB TO &amp;quot;MACHPENAL&amp;quot;;&lt;br /&gt;
 GRANT CREATE MATERIALIZED VIEW TO &amp;quot;MACHPENAL&amp;quot;;&lt;br /&gt;
 GRANT MANAGE SCHEDULER TO &amp;quot;MACHPENAL&amp;quot;;&lt;br /&gt;
 GRANT RESUMABLE TO &amp;quot;MACHPENAL&amp;quot;;&lt;br /&gt;
 GRANT UNLIMITED TABLESPACE TO &amp;quot;MACHPENAL&amp;quot;;&lt;br /&gt;
 GRANT EXECUTE ON &amp;quot;SYS&amp;quot;.&amp;quot;DBMS_LOCK&amp;quot; TO &amp;quot;MACHPENAL&amp;quot;;&lt;br /&gt;
 GRANT &amp;quot;CONNECT&amp;quot; TO &amp;quot;MACHPENAL&amp;quot;;&lt;br /&gt;
 GRANT &amp;quot;MACHP_ROLE&amp;quot; TO &amp;quot;MACHPENAL&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
 impdp system/****** parfile=impdp_prd_accmach.par&lt;br /&gt;
where parfile looks something like this:&lt;br /&gt;
 SCHEMAS=(CHEOPSPENAL,CHEOPSCIVIL,CHEOPSTECH,CHEOPSFIX)&lt;br /&gt;
 #INCLUDE=POST_TABLE_ACTION&lt;br /&gt;
 #INCLUDE=TRIGGER&lt;br /&gt;
 #INCLUDE=PROCACT_SCHEMA&lt;br /&gt;
 EXCLUDE=STATISTICS&lt;br /&gt;
 REMAP_TABLESPACE=CHEOPSCIVIL_AXYLIS:ACCMACH                                     &lt;br /&gt;
 REMAP_TABLESPACE=CHEOPSCIVIL_DEFAULT:ACCMACH                                    &lt;br /&gt;
 REMAP_TABLESPACE=CHEOPSCIVIL_JPABL:ACCMACH                                      &lt;br /&gt;
 REMAP_TABLESPACE=CHEOPSCIVIL_JPADL1:ACCMACH                                     &lt;br /&gt;
 REMAP_TABLESPACE=CHEOPSCIVIL_JPADL2:ACCMACH                                     &lt;br /&gt;
 REMAP_TABLESPACE=CHEOPSCIVIL_JPAND:ACCMACH                                      &lt;br /&gt;
 REMAP_TABLESPACE=CHEOPSCIVIL_JPARL:ACCMACH                                      &lt;br /&gt;
 REMAP_TABLESPACE=CHEOPSCIVIL_JPATH:ACCMACH   &lt;br /&gt;
 ...&lt;br /&gt;
 REMAP_TABLESPACE=CHEOPSCIVIL_VGVRN:ACCMACH                                      &lt;br /&gt;
 REMAP_TABLESPACE=CHEOPSCIVIL_VGVVD:ACCMACH                                      &lt;br /&gt;
 REMAP_TABLESPACE=CHEOPSCIVIL_VGWLB:ACCMACH                                      &lt;br /&gt;
 REMAP_TABLESPACE=CHEOPSCIVIL_VGWLW:ACCMACH                                      &lt;br /&gt;
 REMAP_TABLESPACE=CHEOPSCIVIL_VGWRG:ACCMACH&lt;br /&gt;
 REMAP_SCHEMA=CHEOPSFIX:MACHFIX&lt;br /&gt;
 REMAP_SCHEMA=CHEOPSCIVIL:MACHCIVIL&lt;br /&gt;
 REMAP_SCHEMA=CHEOPSTECH:MACHTECH&lt;br /&gt;
 REMAP_SCHEMA=CHEOPSPENAL:MACHPENAL&lt;br /&gt;
 DUMPFILE=expdp_prdmach_F_230311_%U.dmp&lt;br /&gt;
 LOGFILE=impdp_refresh_240311.log&lt;br /&gt;
 DIRECTORY=expdp_dir&lt;br /&gt;
 PARALLEL=8&lt;br /&gt;
&lt;br /&gt;
===Change parallelism after expdp has started===&lt;br /&gt;
Export started with 1 worker but taking a long time? Change the number of parallel workers!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
expdp \&amp;#039;\/ as sysdba\&amp;#039; attach=SYS_EXPORT_TABLE_01&lt;br /&gt;
&lt;br /&gt;
Export: Release 12.1.0.2.0 - Production on Mon Oct 1 15:44:41 2018&lt;br /&gt;
&lt;br /&gt;
Copyright (c) 1982, 2014, Oracle and/or its affiliates.  All rights reserved.&lt;br /&gt;
&lt;br /&gt;
Connected to: Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production&lt;br /&gt;
With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options&lt;br /&gt;
&lt;br /&gt;
Job: SYS_EXPORT_TABLE_01&lt;br /&gt;
  Owner: SYS&lt;br /&gt;
  Operation: EXPORT&lt;br /&gt;
  Creator Privs: TRUE&lt;br /&gt;
  GUID: 772B5F839E8000ECE0530A085A3842B1&lt;br /&gt;
  Start Time: Monday, 01 October, 2018 14:59:20&lt;br /&gt;
  Mode: TABLE&lt;br /&gt;
  Instance: crelant&lt;br /&gt;
  Max Parallelism: 1&lt;br /&gt;
  Timezone: +02:00&lt;br /&gt;
  Timezone version: 18&lt;br /&gt;
  Endianness: BIG&lt;br /&gt;
  NLS character set: AL32UTF8&lt;br /&gt;
  NLS NCHAR character set: AL16UTF16&lt;br /&gt;
  EXPORT Job Parameters:&lt;br /&gt;
  Parameter Name      Parameter Value:&lt;br /&gt;
     CLIENT_COMMAND        /******** AS SYSDBA parfile=/oracle/scripts/expdp_clnt_tables.par&lt;br /&gt;
  State: EXECUTING&lt;br /&gt;
  Bytes Processed: 73,116,744,528&lt;br /&gt;
  Percent Done: 50&lt;br /&gt;
  Current Parallelism: 1&lt;br /&gt;
  Job Error Count: 0&lt;br /&gt;
  Dump File: /cln/tst/ora_data1/clnt/archivelog/clnt_tables_20180926.dmp&lt;br /&gt;
    bytes written: 73,117,818,880&lt;br /&gt;
&lt;br /&gt;
Worker 1 Status:&lt;br /&gt;
  Instance ID: 1&lt;br /&gt;
  Instance name: clnt&lt;br /&gt;
  Host name: hn5306.cln.be&lt;br /&gt;
  Process Name: DW00&lt;br /&gt;
  State: EXECUTING&lt;br /&gt;
  Object Schema: TPK&lt;br /&gt;
  Object Name: EID01&lt;br /&gt;
  Object Type: TABLE_EXPORT/TABLE/TABLE_DATA&lt;br /&gt;
  Completed Objects: 5&lt;br /&gt;
  Total Objects: 192&lt;br /&gt;
  Completed Rows: 835,298&lt;br /&gt;
  Worker Parallelism: 1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Export&amp;gt; parallel=4&lt;br /&gt;
&lt;br /&gt;
Export&amp;gt; status&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Job: SYS_EXPORT_TABLE_01&lt;br /&gt;
  Operation: EXPORT&lt;br /&gt;
  Mode: TABLE&lt;br /&gt;
  State: EXECUTING&lt;br /&gt;
  Bytes Processed: 73,116,744,528&lt;br /&gt;
  Percent Done: 50&lt;br /&gt;
  Current Parallelism: 4&lt;br /&gt;
  Job Error Count: 0&lt;br /&gt;
  Dump File: /cln/tst/ora_data1/clnt/archivelog/clnt_tables_20180926.dmp&lt;br /&gt;
    bytes written: 73,117,818,880&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Worker 1 Status:&lt;br /&gt;
  Instance ID: 1&lt;br /&gt;
  Instance name: clnt&lt;br /&gt;
  Host name: hn5306.cln.be&lt;br /&gt;
  Process Name: DW00&lt;br /&gt;
  State: EXECUTING&lt;br /&gt;
  Object Schema: TPK&lt;br /&gt;
  Object Name: CCD01&lt;br /&gt;
  Object Type: TABLE_EXPORT/TABLE/TABLE_DATA&lt;br /&gt;
  Completed Objects: 10&lt;br /&gt;
  Total Objects: 192&lt;br /&gt;
  Completed Rows: 317,968&lt;br /&gt;
  Worker Parallelism: 1&lt;br /&gt;
&lt;br /&gt;
Worker 2 Status:&lt;br /&gt;
  Instance ID: 1&lt;br /&gt;
  Instance name: clnt&lt;br /&gt;
  Host name: hn5306.cln.be&lt;br /&gt;
  Process Name: DW01&lt;br /&gt;
  State: EXECUTING&lt;br /&gt;
  Object Schema: TPK&lt;br /&gt;
  Object Name: BCD18&lt;br /&gt;
  Object Type: TABLE_EXPORT/TABLE/TABLE_DATA&lt;br /&gt;
  Completed Objects: 4&lt;br /&gt;
  Total Objects: 192&lt;br /&gt;
  Worker Parallelism: 1&lt;br /&gt;
&lt;br /&gt;
Worker 3 Status:&lt;br /&gt;
  Instance ID: 1&lt;br /&gt;
  Instance name: clnt&lt;br /&gt;
  Host name: hn5306.cln.be&lt;br /&gt;
  Process Name: DW02&lt;br /&gt;
  State: EXECUTING&lt;br /&gt;
  Object Schema: TPK&lt;br /&gt;
  Object Name: FCD06&lt;br /&gt;
  Object Type: TABLE_EXPORT/TABLE/TABLE_DATA&lt;br /&gt;
  Completed Objects: 4&lt;br /&gt;
  Total Objects: 192&lt;br /&gt;
  Worker Parallelism: 1&lt;br /&gt;
&lt;br /&gt;
Worker 4 Status:&lt;br /&gt;
  Instance ID: 1&lt;br /&gt;
  Instance name: clnt&lt;br /&gt;
  Host name: hn5306.cln.be&lt;br /&gt;
  Process Name: DW03&lt;br /&gt;
  State: EXECUTING&lt;br /&gt;
  Object Schema: TPK&lt;br /&gt;
  Object Name: CBD10&lt;br /&gt;
  Object Type: TABLE_EXPORT/TABLE/TABLE_DATA&lt;br /&gt;
  Completed Objects: 4&lt;br /&gt;
  Total Objects: 192&lt;br /&gt;
  Worker Parallelism: 1&lt;br /&gt;
&lt;br /&gt;
Export&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Monitor Data Pump sessions===&lt;br /&gt;
 select s.sid&lt;br /&gt;
 ,      s.serial#&lt;br /&gt;
 from   v$session s&lt;br /&gt;
 ,      dba_datapump_sessions dps&lt;br /&gt;
 where s.saddr = dps.saddr;&lt;br /&gt;
&lt;br /&gt;
Once the session is identified, you can see the parallel query slave sessions spawned off by the main Data Pump session by querying the V$PX_SESSION view:&lt;br /&gt;
 select sid from v$px_session&lt;br /&gt;
 where qcsid = &amp;lt;DP Session ID&amp;gt;;&lt;br /&gt;
&lt;br /&gt;
===How long will the export take?===&lt;br /&gt;
Data Pump sends information about its progress to the longops view and can be consulted thus:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select sid&lt;br /&gt;
,      serial#&lt;br /&gt;
,      sofar&lt;br /&gt;
,      totalwork &lt;br /&gt;
from   v$session_longops &lt;br /&gt;
where  1=1&lt;br /&gt;
and    opname = &amp;#039;&amp;lt;DP Job Name&amp;gt;&amp;#039; &lt;br /&gt;
and    sofar != totalwork&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select vsl.*&lt;br /&gt;
from   v$session_longops vsl&lt;br /&gt;
where  1=1&lt;br /&gt;
and    (vsl.sid,vsl.serial#) in (select sid,serial# from dba_datapump_sessions)&lt;br /&gt;
and    vsl.sofar != vsl.totalwork&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set serveroutput on&lt;br /&gt;
DECLARE&lt;br /&gt;
  ind NUMBER;              -- Loop index&lt;br /&gt;
  h1 NUMBER;               -- Data Pump job handle&lt;br /&gt;
  percent_done NUMBER;     -- Percentage of job complete&lt;br /&gt;
  job_state VARCHAR2(30);  -- To keep track of job state&lt;br /&gt;
  js ku$_JobStatus;        -- The job status from get_status&lt;br /&gt;
  ws ku$_WorkerStatusList; -- Worker status&lt;br /&gt;
  sts ku$_Status;          -- The status object returned by get_status&lt;br /&gt;
BEGIN&lt;br /&gt;
h1 := DBMS_DATAPUMP.attach(&amp;#039;&amp;amp;JOB_NAME&amp;#039;, &amp;#039;&amp;amp;OWNER&amp;#039;); -- job name and owner&lt;br /&gt;
dbms_datapump.get_status(h1,&lt;br /&gt;
           dbms_datapump.ku$_status_job_error +&lt;br /&gt;
           dbms_datapump.ku$_status_job_status +&lt;br /&gt;
           dbms_datapump.ku$_status_wip, 0, job_state, sts);&lt;br /&gt;
js := sts.job_status;&lt;br /&gt;
ws := js.worker_status_list;&lt;br /&gt;
      dbms_output.put_line(&amp;#039;*** Job percent done = &amp;#039; ||&lt;br /&gt;
                           to_char(js.percent_done));&lt;br /&gt;
      dbms_output.put_line(&amp;#039;restarts - &amp;#039;||js.restart_count);&lt;br /&gt;
ind := ws.first;&lt;br /&gt;
  while ind is not null loop&lt;br /&gt;
    dbms_output.put_line(&amp;#039;rows completed - &amp;#039;||ws(ind).completed_rows);&lt;br /&gt;
    ind := ws.next(ind);&lt;br /&gt;
  end loop;&lt;br /&gt;
DBMS_DATAPUMP.detach(h1);&lt;br /&gt;
end;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Debugging a Data Pump session===&lt;br /&gt;
While exporting/importing, the Datapump job can sometimes appear to hang. What is it doing?&amp;lt;br /&amp;gt;&lt;br /&gt;
Firstly, we can add &amp;quot;METRICS=Y&amp;quot; to the parameter file. This gives a bit more logging info.&amp;lt;br /&amp;gt;&lt;br /&gt;
Next, we can dig deeper into the session using the session id.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 150 pages 100&lt;br /&gt;
col program for a30&lt;br /&gt;
col username for a15&lt;br /&gt;
col spid for a7&lt;br /&gt;
col job_name for a25&lt;br /&gt;
select to_char (sysdate, &amp;#039;DD-MON-YY HH24:MI:SS&amp;#039;) timenow&lt;br /&gt;
,      s.program&lt;br /&gt;
,      s.sid&lt;br /&gt;
,      s.status&lt;br /&gt;
,      s.username&lt;br /&gt;
,      dds.job_name&lt;br /&gt;
,      p.spid&lt;br /&gt;
,      s.serial#&lt;br /&gt;
,      p.pid&lt;br /&gt;
from   v$session s&lt;br /&gt;
,      v$process p&lt;br /&gt;
,      dba_datapump_sessions dds&lt;br /&gt;
where  p.addr  = s.paddr&lt;br /&gt;
and    s.saddr = dds.saddr&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select sw.sid&lt;br /&gt;
,      sw.event&lt;br /&gt;
,      sw.seconds_in_wait&lt;br /&gt;
from   v$session s&lt;br /&gt;
,      dba_datapump_sessions dds&lt;br /&gt;
,      v$session_wait sw&lt;br /&gt;
where  dds.saddr = s.saddr&lt;br /&gt;
and    s.sid     = sw.sid&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
execute sys.dbms_system.set_ev (&amp;amp;sid,15,10046,8,&amp;#039;&amp;#039;);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
then go to the user dump directory and use tkprof to read the trace file.&lt;br /&gt;
&lt;br /&gt;
===Enable logging during a datpump impdp/expdp===&lt;br /&gt;
As of 12c, much better logging is available:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
expdp / full=y dump_file=test.dmp logfile=test.log logtime=all&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This prefixes all messages in the logfile with a timestamp.&lt;br /&gt;
&lt;br /&gt;
===Enabling SQL trace===&lt;br /&gt;
Cannot simply use:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter session set sql_trace=true;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
as Data Pump starts another session. An event has to be set:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select sid&lt;br /&gt;
,      serial#&lt;br /&gt;
,      username&lt;br /&gt;
,      program&lt;br /&gt;
from   v$session &lt;br /&gt;
where  1=1&lt;br /&gt;
and    upper(program) like &amp;#039;%(DW%)&amp;#039;&lt;br /&gt;
or     upper(program) like &amp;#039;%(DM%)&amp;#039;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
then use the sid and serial# to set the event:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
exec dbms_system.set_ev(&amp;lt;sid&amp;gt;, &amp;lt;serial#&amp;gt;, 10046, 12, &amp;#039;&amp;#039; );&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Trace files will be in user-dump_dest&lt;br /&gt;
&lt;br /&gt;
For the full beans on what Data Pump can do, visit [http://www.rampant-books.com/art_nanda_datapump.htm Arup Nanda&amp;#039;s Data Pump page]&lt;br /&gt;
&lt;br /&gt;
===Restore a schema from a dumpfile into a new schema so that user can pick his objects===&lt;br /&gt;
* Restore relevant file from [[TSM]]&lt;br /&gt;
* Connect to the database as sysdba and&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
create tablespace temp_recovery&lt;br /&gt;
       datafile &amp;#039;/oracle/&amp;lt;ORACLE_SID&amp;gt;/oradata1/temp_recovery.dbf&amp;#039;&lt;br /&gt;
       size 100M autoextend on next 100M maxsize 20000M&lt;br /&gt;
       extent management local&lt;br /&gt;
       segment space management auto;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Create a new schema to put the recovered data&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
create user temp_recovery identified by temp_recovery default tablespace temp_recovery temporary tablespace temp;&lt;br /&gt;
grant connect, resource to temp_recovery;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create a par file to remap the schema and tablespace&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
vi impdp_schema.par   &lt;br /&gt;
&lt;br /&gt;
directory=DATA_PUMP_DIR&lt;br /&gt;
dumpfile=/oracle/export/&amp;lt;ORACLE_SID&amp;gt;/expdp_&amp;lt;ORACLE_SID&amp;gt;_D_FULL_20120918213006_%U.dmp&lt;br /&gt;
logfile=impdp_schema.log&lt;br /&gt;
job_name=impdp_schema&lt;br /&gt;
schemas=SCHEMA_TO_RECOVER&lt;br /&gt;
remap_schema=SCHEMA_TO_RECOVER:temp_recovery&lt;br /&gt;
remap_tablespace=USERS:temp_recovery&lt;br /&gt;
table_exists_action=skip&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Run the import&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
impdp \&amp;#039;/ as sysdba\&amp;#039; parfile=impdp_schema.par&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Restore schemas from dump. Clean out schema objects first.===&lt;br /&gt;
You can also drop schema but then you lose all grants.&amp;lt;br /&amp;gt;&lt;br /&gt;
Check we have the dump files...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ll&lt;br /&gt;
-rw-r-----   1 GPTASKP2 dba      8540041216 Oct 17 21:17 expdp_GPTASKP2_D_FULL_20131017210003_01.dmp&lt;br /&gt;
-rw-r-----   1 GPTASKP2 dba      9391812608 Oct 17 21:17 expdp_GPTASKP2_D_FULL_20131017210003_02.dmp&lt;br /&gt;
-rw-r-----   1 GPTASKP2 dba      32161792 Oct 17 21:17 expdp_GPTASKP2_D_FULL_20131017210003_03.dmp&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Backup schemas just in case...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cat expdp_just_in_case.ksh&lt;br /&gt;
expdp \&amp;#039;/ as sysdba\&amp;#039;                                      \&lt;br /&gt;
    DIRECTORY=DATA_PUMP_DIR                                \&lt;br /&gt;
    schemas=GPCOMP4,GPCOMP6                                \&lt;br /&gt;
    dumpfile=expdp_GPTASKP2_JUST_IN_CASE_201310181500.dmp  \&lt;br /&gt;
    job_name=impdp_GPTASKP2_GPCOMP4_GPCOMP6                \&lt;br /&gt;
    logfile=expdp_GPTASKP2_GPCOMP4_GPCOMP6.log&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Clean out schemas to be imported...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/usr/bin/ksh&lt;br /&gt;
# ==============================================================================&lt;br /&gt;
# Name         : userman_clean_out_schema.ksh&lt;br /&gt;
# Description  : Rids a schema of all objects. An empty shell ready for import.&lt;br /&gt;
#&lt;br /&gt;
# Parameters   : 1 - -u &amp;lt;schema name to clean out&amp;gt;&lt;br /&gt;
#                2 - -e if you want the schema to be wiped automatically&lt;br /&gt;
#&lt;br /&gt;
# Notes        : Generates an SQL file and an execution spool file&lt;br /&gt;
#&lt;br /&gt;
# Modification History&lt;br /&gt;
# ====================&lt;br /&gt;
# When      Who               What&lt;br /&gt;
# ========= ================= ==================================================&lt;br /&gt;
# 09-NOV-13 Stuart Barkley    Created&lt;br /&gt;
# 06-JAN-14 Stuart Barkley    Added SYNONYM&lt;br /&gt;
# 23-JAN-14 Stuart Barkley    Added -e option and tidied&lt;br /&gt;
# 25-APR-14 Stuart Barkley    Create files in /tmp to avoid permissions errors&lt;br /&gt;
# ==============================================================================&lt;br /&gt;
&lt;br /&gt;
ts=`date +&amp;quot;%Y%M%d&amp;quot;`&lt;br /&gt;
&lt;br /&gt;
# ----------------------------&lt;br /&gt;
# get any command line options&lt;br /&gt;
# ----------------------------&lt;br /&gt;
unset USERNAME&lt;br /&gt;
&lt;br /&gt;
DOIT=&amp;quot;N&amp;quot;&lt;br /&gt;
while getopts &amp;quot;u:e&amp;quot; OPT&lt;br /&gt;
do&lt;br /&gt;
    case &amp;quot;$OPT&amp;quot; in&lt;br /&gt;
    u) USERNAME=$OPTARG;;&lt;br /&gt;
    e) DOIT=&amp;quot;Y&amp;quot;;;&lt;br /&gt;
    esac&lt;br /&gt;
done&lt;br /&gt;
shift $((OPTIND-1))&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
# --------------------------&lt;br /&gt;
# check mandatory parameters&lt;br /&gt;
# --------------------------&lt;br /&gt;
if [[ -z $USERNAME ]]; then&lt;br /&gt;
    echo &amp;quot;&amp;quot;&lt;br /&gt;
    echo &amp;quot;Usage:  `basename $0` [-e] -u &amp;lt;schemaname to wipe&amp;gt;&amp;quot;&lt;br /&gt;
    echo &amp;quot;specifying -e makes the script go ahead and do the wipe automatically&amp;quot;&lt;br /&gt;
    echo &amp;quot;&amp;quot;&lt;br /&gt;
    exit 1&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
sqlplus -s / as sysdba &amp;lt;&amp;lt;EOSQL&lt;br /&gt;
set pages 0&lt;br /&gt;
set feedb off&lt;br /&gt;
set verif off&lt;br /&gt;
spool  /tmp/userman_clean_out_${USERNAME}.sql&lt;br /&gt;
select &amp;#039;drop &amp;#039;||object_type||&amp;#039; &amp;quot;&amp;#039;||owner||&amp;#039;&amp;quot;.&amp;quot;&amp;#039;||object_name||&amp;#039;&amp;quot;&amp;#039;||decode(object_type,&amp;#039;TABLE&amp;#039;,&amp;#039; CASCADE CONSTRAINTS PURGE;&amp;#039;,&amp;#039;;&amp;#039;) text&lt;br /&gt;
from   dba_objects&lt;br /&gt;
where  1=1&lt;br /&gt;
and    owner       = &amp;#039;$USERNAME&amp;#039;&lt;br /&gt;
order  by object_type&lt;br /&gt;
,      object_name&lt;br /&gt;
/&lt;br /&gt;
spool off&lt;br /&gt;
EOSQL&lt;br /&gt;
&lt;br /&gt;
if [[ &amp;quot;$DOIT&amp;quot; == &amp;quot;Y&amp;quot; ]]; then&lt;br /&gt;
    echo &amp;quot;wiping user...&amp;quot;&lt;br /&gt;
    sqlplus -s / as sysdba &amp;lt;&amp;lt;EOSQL&lt;br /&gt;
spool /tmp/userman_clean_out_${USERNAME}_run.log&lt;br /&gt;
set termo on echo on feedb on&lt;br /&gt;
start /tmp/userman_clean_out_${USERNAME}.sql&lt;br /&gt;
&lt;br /&gt;
purge recyclebin;&lt;br /&gt;
spool off&lt;br /&gt;
EOSQL&lt;br /&gt;
    echo &amp;quot;done wiping user&amp;quot;&lt;br /&gt;
else&lt;br /&gt;
    echo &amp;quot;To execute this automatically, add &amp;#039;-e&amp;#039; as a parameter to the script&amp;quot;&lt;br /&gt;
    echo &amp;quot;or you can manually run the sql file I just generated: userman_clean_out_${USERNAME}.sql&amp;quot;&lt;br /&gt;
fi&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
Import the required data...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cat impdp_GPTASKP2_GPCOMP4_GPCOMP6.ksh&lt;br /&gt;
impdp \&amp;#039;/ as sysdba\&amp;#039;                                     \&lt;br /&gt;
    DIRECTORY=DATA_PUMP_DIR                               \&lt;br /&gt;
    schemas=GPCOMP4,GPCOMP6                               \&lt;br /&gt;
    dumpfile=expdp_GPTASKP2_D_FULL_20131017210003_%u.dmp  \&lt;br /&gt;
    job_name=impdp_GPTASKP2_GPCOMP4_GPCOMP6               \&lt;br /&gt;
    logfile=impdp_GPTASKP2_GPCOMP4_GPCOMP6&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Alternatively, drop and recreate the schema / user using dbms_metadata get_ddl and get_granted_ddl====&lt;br /&gt;
Run this &amp;#039;&amp;#039;&amp;#039;before&amp;#039;&amp;#039;&amp;#039; dropping the schema to generate DDL necessary to recreate it&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sqlplus -s /nolog &amp;lt;&amp;lt;EOSQL 2&amp;gt;/tmp/results.$$&lt;br /&gt;
connect / as sysdba&lt;br /&gt;
whenever sqlerror continue&lt;br /&gt;
set hea off echo off pages 0 newp none long 99999 lin 2000 trims on feed off veri off&lt;br /&gt;
&lt;br /&gt;
execute dbms_metadata.set_transform_param(dbms_metadata.session_transform,&amp;#039;SQLTERMINATOR&amp;#039;,true);&lt;br /&gt;
spool /tmp/recreate_schemae_$$.sql&lt;br /&gt;
&lt;br /&gt;
select to_char( dbms_metadata.get_ddl         ( &amp;#039;USER&amp;#039;,         du.username ) ) from dba_users du where du.username in upper(&amp;#039;${SCHEMAE}&amp;#039;);&lt;br /&gt;
select to_char( dbms_metadata.get_granted_ddl ( &amp;#039;ROLE_GRANT&amp;#039;,   du.username ) ) from dba_users du where du.username in upper(&amp;#039;${SCHEMAE}&amp;#039;);&lt;br /&gt;
select to_char( dbms_metadata.get_granted_ddl ( &amp;#039;DEFAULT_ROLE&amp;#039;, du.username ) ) from dba_users du where du.username in upper(&amp;#039;${SCHEMAE}&amp;#039;);&lt;br /&gt;
select to_char( dbms_metadata.get_granted_ddl ( &amp;#039;SYSTEM_GRANT&amp;#039;, du.username ) ) from dba_users du where du.username in upper(&amp;#039;${SCHEMAE}&amp;#039;);&lt;br /&gt;
select to_char( dbms_metadata.get_granted_ddl ( &amp;#039;OBJECT_GRANT&amp;#039;, du.username ) ) from dba_users du where du.username in upper(&amp;#039;${SCHEMAE}&amp;#039;);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
-- db_links do not work properly with dbms_metadata if they are for a different schema&lt;br /&gt;
select &amp;#039;create &amp;#039;                                      ||&lt;br /&gt;
       decode (u.name, &amp;#039;PUBLIC&amp;#039;, &amp;#039;public &amp;#039;)           ||&lt;br /&gt;
       &amp;#039;database link &amp;quot;&amp;#039;                              ||&lt;br /&gt;
       decode (u.name, &amp;#039;PUBLIC&amp;#039;, null, u.name || &amp;#039;.&amp;#039;) ||&lt;br /&gt;
       l.name                                         ||&lt;br /&gt;
       &amp;#039;&amp;quot; connect to &amp;quot;&amp;#039;                               ||&lt;br /&gt;
       l.userid                                       ||&lt;br /&gt;
       &amp;#039;&amp;quot; identified by values &amp;quot;&amp;#039;                     ||&lt;br /&gt;
       l.passwordx                                    ||&lt;br /&gt;
       &amp;#039;&amp;quot; using &amp;quot;&amp;#039;                                    ||&lt;br /&gt;
       l.host                                         ||&lt;br /&gt;
       &amp;#039;&amp;quot;&amp;#039;                                            ||&lt;br /&gt;
       &amp;#039;;&amp;#039; text&lt;br /&gt;
from   sys.link$ l&lt;br /&gt;
,      sys.user$ u&lt;br /&gt;
where  1=1&lt;br /&gt;
and    l.owner# = u.user#&lt;br /&gt;
and    u.name   in upper(&amp;#039;${SCHEMAE}&amp;#039;);&lt;br /&gt;
&lt;br /&gt;
spool off&lt;br /&gt;
EOSQL&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====References====&lt;br /&gt;
* Master Note for Data Pump [ID 1264715.1]&lt;br /&gt;
* Checklist For Slow Performance Of DataPump Export (expdp) And Import (impdp) [ID 453895.1]&lt;br /&gt;
* Parallel Capabilities of Oracle Data Pump [ID 365459.1]&lt;br /&gt;
* [http://jensenmo.blogspot.be/2012/10/optimising-data-pump-export-and-import.html Morton Jensen&amp;#039;s Optimising Data Pump Export and Import Performance / investigation into speeding up LOB import/export]&lt;/div&gt;</summary>
		<author><name>Stuart</name></author>	</entry>

	<entry>
		<id>https://mailnest.com/dbawiki/index.php?title=Data_Pump&amp;diff=3391</id>
		<title>Data Pump</title>
		<link rel="alternate" type="text/html" href="https://mailnest.com/dbawiki/index.php?title=Data_Pump&amp;diff=3391"/>
				<updated>2018-12-04T10:43:02Z</updated>
		
		<summary type="html">&lt;p&gt;Stuart: Stuart moved page Data Pump to Datapump&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;#REDIRECT [[Datapump]]&lt;/div&gt;</summary>
		<author><name>Stuart</name></author>	</entry>

	<entry>
		<id>https://mailnest.com/dbawiki/index.php?title=Adrci&amp;diff=3389</id>
		<title>Adrci</title>
		<link rel="alternate" type="text/html" href="https://mailnest.com/dbawiki/index.php?title=Adrci&amp;diff=3389"/>
				<updated>2018-11-28T14:03:56Z</updated>
		
		<summary type="html">&lt;p&gt;Stuart: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;===Reference links===&lt;br /&gt;
* [http://intermediatesql.com/oracle/oracle-11g-xml-alert-logs-surprise-they-are-actually-more-convenient-to-work-with/ Convenient access to adrci log files]&lt;br /&gt;
* [http://arup.blogspot.co.uk/2013/04/switching-back-to-regular-listener-log.html Switch back to old-style listener log file - not using adr]&lt;br /&gt;
* [https://oracle-base.com/articles/11g/automatic-diagnostics-repository-11gr1 adrci at oracle-base.com]&lt;br /&gt;
The new way to package problems and their incidents up for Oracle Support.&amp;lt;br /&amp;gt;&lt;br /&gt;
A useful way to keep the purging of trace files under control.&amp;lt;br /&amp;gt;&lt;br /&gt;
With an Oracle database environment setup, type:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
adrci&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
To get out, type:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
adrci&amp;gt; exit&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
To get help, type:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
adrci&amp;gt; help&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Show registered ORACLE_HOMEs&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
show home&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Set one of the homes&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set home diag/rdbms/orcl&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
tail the alert log (adrci reads the XML version of the alert log)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
show alert -tail -f&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Are there any problems?&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
show problem&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Show the incident(s) of this problem&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
show incident&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Show more detail about an incident&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
show incident -mode detail -p &amp;quot;incident_id=&amp;lt;incident number&amp;gt;&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Show the incident trace file for this incident&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
show trace /u01/app/oracle/diag/rdbms/orcl/orcl/incident/incdir_6201/orcl_ora_2299_i6201.trc&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Package a problem up for Oracle Support&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ips create package problem 1 correlate all&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Zip a problem package for Oracle Support&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ips generate package 2 in &amp;quot;/home/oracle&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
To see current setup, type:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
adrci&amp;gt; show control&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Purging trace and dump files in 11g with adrci===&lt;br /&gt;
SHORTP_POLICY and LONGP_POLICY are number of hours to keep trace files and alert files respectively. These can be changed by typing:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set control (SHORTP_POLICY=240)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Trace files will now be deleted after 10 days.&amp;lt;br /&amp;gt;&lt;br /&gt;
If space is running low, you can manually delete trace files.&amp;lt;br /&amp;gt;&lt;br /&gt;
This deletes all trace files older than 1 day (note the age parameter is minutes, not hours).&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
purge -age 3600 -type trace&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Show the tracefiles in reverse time order&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
show tracefile -rt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Use ADR command line interface from shell===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
adrci exec=&amp;quot;show homes&amp;quot;&lt;br /&gt;
adrci exec=&amp;quot;set home diag/tnslsnr/ravjde01/listener_ravjde1;show control&amp;quot;&lt;br /&gt;
adrci exec=&amp;quot;set home diag/tnslsnr/ravjde01/listener_ravjde1;set control (shortp_policy=360,longp_policy=720);purge;show control;&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Show ADR homes related to databases&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ORACLE_HOME/bin/adrci exec=&amp;quot;show homes&amp;quot; | grep &amp;quot;rdbms&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Shell script to purge ADR data===&lt;br /&gt;
Found [http://www.dadbm.com/oracle-database-housekeeping-methods-adr-files-purge/ here]&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Purge ADR contents (adr_purge.sh)&lt;br /&gt;
purge_log () {&lt;br /&gt;
purge_min=$(( 24 * 60 * $2 ))&lt;br /&gt;
echo “INFO: purging $1 older than $2 days”&lt;br /&gt;
adrci exec=”set homepath $file_line;purge -age $purge_min -type $1″&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
echo “INFO: adrci purge started at `date`”&lt;br /&gt;
adrci exec=”show homes”|grep -v : | while read file_line&lt;br /&gt;
do&lt;br /&gt;
echo “INFO: adrci purging diagnostic destination ” $file_line&lt;br /&gt;
echo “——————————————————————————-”&lt;br /&gt;
purge_log ALERT 365&lt;br /&gt;
purge_log INCIDENT 273&lt;br /&gt;
purge_log TRACE 120&lt;br /&gt;
purge_log CDUMP 75&lt;br /&gt;
purge_log HM 75&lt;br /&gt;
echo “——————————————————————————-”&lt;br /&gt;
done&lt;br /&gt;
echo&lt;br /&gt;
echo “INFO: adrci purge finished at `date`”&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Create a package to send to Oracle Support===&lt;br /&gt;
A problem may consist of one or more incidents.&lt;br /&gt;
====Find the problem id====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
show incident -mode detail -p &amp;quot;incident_id=&amp;lt;incident_id&amp;gt;&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Create a package containing all incidents for this problem====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ips create package problem &amp;lt;proble_id&amp;gt; correlate all&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Generate a zipped package file====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ips generate package &amp;lt;proble_id&amp;gt; in &amp;quot;/tmp&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Stuart</name></author>	</entry>

	<entry>
		<id>https://mailnest.com/dbawiki/index.php?title=Adrci&amp;diff=3388</id>
		<title>Adrci</title>
		<link rel="alternate" type="text/html" href="https://mailnest.com/dbawiki/index.php?title=Adrci&amp;diff=3388"/>
				<updated>2018-11-28T13:29:17Z</updated>
		
		<summary type="html">&lt;p&gt;Stuart: /* Create a package to send to Oracle Support */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;* [http://intermediatesql.com/oracle/oracle-11g-xml-alert-logs-surprise-they-are-actually-more-convenient-to-work-with/ Convenient access to adrci log files]&lt;br /&gt;
* [http://arup.blogspot.co.uk/2013/04/switching-back-to-regular-listener-log.html Switch back to old-style listener log file - not using adr]&lt;br /&gt;
The new way to package problems and their incidents up for Oracle Support.&amp;lt;br /&amp;gt;&lt;br /&gt;
A useful way to keep the purging of trace files under control.&amp;lt;br /&amp;gt;&lt;br /&gt;
With an Oracle database environment setup, type:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
adrci&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
To get out, type:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
adrci&amp;gt; exit&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
To get help, type:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
adrci&amp;gt; help&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Show registered ORACLE_HOMEs&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
show home&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Set one of the homes&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set home diag/rdbms/orcl&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
tail the alert log (adrci reads the XML version of the alert log)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
show alert -tail -f&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Are there any problems?&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
show problem&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Show the incident(s) of this problem&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
show incident&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Show more detail about an incident&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
show incident -mode detail -p &amp;quot;incident_id=&amp;lt;incident number&amp;gt;&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Show the incident trace file for this incident&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
show trace /u01/app/oracle/diag/rdbms/orcl/orcl/incident/incdir_6201/orcl_ora_2299_i6201.trc&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Package a problem up for Oracle Support&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ips create package problem 1 correlate all&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Zip a problem package for Oracle Support&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ips generate package 2 in &amp;quot;/home/oracle&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
To see current setup, type:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
adrci&amp;gt; show control&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Purging trace and dump files in 11g with adrci===&lt;br /&gt;
SHORTP_POLICY and LONGP_POLICY are number of hours to keep trace files and alert files respectively. These can be changed by typing:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set control (SHORTP_POLICY=240)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Trace files will now be deleted after 10 days.&amp;lt;br /&amp;gt;&lt;br /&gt;
If space is running low, you can manually delete trace files.&amp;lt;br /&amp;gt;&lt;br /&gt;
This deletes all trace files older than 1 day (note the age parameter is minutes, not hours).&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
purge -age 3600 -type trace&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Show the tracefiles in reverse time order&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
show tracefile -rt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Use ADR command line interface from shell===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
adrci exec=&amp;quot;show homes&amp;quot;&lt;br /&gt;
adrci exec=&amp;quot;set home diag/tnslsnr/ravjde01/listener_ravjde1;show control&amp;quot;&lt;br /&gt;
adrci exec=&amp;quot;set home diag/tnslsnr/ravjde01/listener_ravjde1;set control (shortp_policy=360,longp_policy=720);purge;show control;&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Show ADR homes related to databases&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ORACLE_HOME/bin/adrci exec=&amp;quot;show homes&amp;quot; | grep &amp;quot;rdbms&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Shell script to purge ADR data===&lt;br /&gt;
Found [http://www.dadbm.com/oracle-database-housekeeping-methods-adr-files-purge/ here]&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Purge ADR contents (adr_purge.sh)&lt;br /&gt;
purge_log () {&lt;br /&gt;
purge_min=$(( 24 * 60 * $2 ))&lt;br /&gt;
echo “INFO: purging $1 older than $2 days”&lt;br /&gt;
adrci exec=”set homepath $file_line;purge -age $purge_min -type $1″&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
echo “INFO: adrci purge started at `date`”&lt;br /&gt;
adrci exec=”show homes”|grep -v : | while read file_line&lt;br /&gt;
do&lt;br /&gt;
echo “INFO: adrci purging diagnostic destination ” $file_line&lt;br /&gt;
echo “——————————————————————————-”&lt;br /&gt;
purge_log ALERT 365&lt;br /&gt;
purge_log INCIDENT 273&lt;br /&gt;
purge_log TRACE 120&lt;br /&gt;
purge_log CDUMP 75&lt;br /&gt;
purge_log HM 75&lt;br /&gt;
echo “——————————————————————————-”&lt;br /&gt;
done&lt;br /&gt;
echo&lt;br /&gt;
echo “INFO: adrci purge finished at `date`”&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Create a package to send to Oracle Support===&lt;br /&gt;
A problem may consist of one or more incidents.&lt;br /&gt;
====Find the problem id====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
show incident -mode detail -p &amp;quot;incident_id=&amp;lt;incident_id&amp;gt;&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Create a package containing all incidents for this problem====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ips create package problem &amp;lt;proble_id&amp;gt; correlate all&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Generate a zipped package file====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ips generate package &amp;lt;proble_id&amp;gt; in &amp;quot;/tmp&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Stuart</name></author>	</entry>

	<entry>
		<id>https://mailnest.com/dbawiki/index.php?title=Adrci&amp;diff=3387</id>
		<title>Adrci</title>
		<link rel="alternate" type="text/html" href="https://mailnest.com/dbawiki/index.php?title=Adrci&amp;diff=3387"/>
				<updated>2018-11-28T13:28:32Z</updated>
		
		<summary type="html">&lt;p&gt;Stuart: /* Create a package to send to Oracle Support */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;* [http://intermediatesql.com/oracle/oracle-11g-xml-alert-logs-surprise-they-are-actually-more-convenient-to-work-with/ Convenient access to adrci log files]&lt;br /&gt;
* [http://arup.blogspot.co.uk/2013/04/switching-back-to-regular-listener-log.html Switch back to old-style listener log file - not using adr]&lt;br /&gt;
The new way to package problems and their incidents up for Oracle Support.&amp;lt;br /&amp;gt;&lt;br /&gt;
A useful way to keep the purging of trace files under control.&amp;lt;br /&amp;gt;&lt;br /&gt;
With an Oracle database environment setup, type:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
adrci&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
To get out, type:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
adrci&amp;gt; exit&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
To get help, type:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
adrci&amp;gt; help&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Show registered ORACLE_HOMEs&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
show home&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Set one of the homes&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set home diag/rdbms/orcl&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
tail the alert log (adrci reads the XML version of the alert log)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
show alert -tail -f&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Are there any problems?&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
show problem&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Show the incident(s) of this problem&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
show incident&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Show more detail about an incident&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
show incident -mode detail -p &amp;quot;incident_id=&amp;lt;incident number&amp;gt;&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Show the incident trace file for this incident&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
show trace /u01/app/oracle/diag/rdbms/orcl/orcl/incident/incdir_6201/orcl_ora_2299_i6201.trc&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Package a problem up for Oracle Support&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ips create package problem 1 correlate all&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Zip a problem package for Oracle Support&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ips generate package 2 in &amp;quot;/home/oracle&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
To see current setup, type:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
adrci&amp;gt; show control&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Purging trace and dump files in 11g with adrci===&lt;br /&gt;
SHORTP_POLICY and LONGP_POLICY are number of hours to keep trace files and alert files respectively. These can be changed by typing:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set control (SHORTP_POLICY=240)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Trace files will now be deleted after 10 days.&amp;lt;br /&amp;gt;&lt;br /&gt;
If space is running low, you can manually delete trace files.&amp;lt;br /&amp;gt;&lt;br /&gt;
This deletes all trace files older than 1 day (note the age parameter is minutes, not hours).&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
purge -age 3600 -type trace&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Show the tracefiles in reverse time order&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
show tracefile -rt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Use ADR command line interface from shell===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
adrci exec=&amp;quot;show homes&amp;quot;&lt;br /&gt;
adrci exec=&amp;quot;set home diag/tnslsnr/ravjde01/listener_ravjde1;show control&amp;quot;&lt;br /&gt;
adrci exec=&amp;quot;set home diag/tnslsnr/ravjde01/listener_ravjde1;set control (shortp_policy=360,longp_policy=720);purge;show control;&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Show ADR homes related to databases&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ORACLE_HOME/bin/adrci exec=&amp;quot;show homes&amp;quot; | grep &amp;quot;rdbms&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Shell script to purge ADR data===&lt;br /&gt;
Found [http://www.dadbm.com/oracle-database-housekeeping-methods-adr-files-purge/ here]&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Purge ADR contents (adr_purge.sh)&lt;br /&gt;
purge_log () {&lt;br /&gt;
purge_min=$(( 24 * 60 * $2 ))&lt;br /&gt;
echo “INFO: purging $1 older than $2 days”&lt;br /&gt;
adrci exec=”set homepath $file_line;purge -age $purge_min -type $1″&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
echo “INFO: adrci purge started at `date`”&lt;br /&gt;
adrci exec=”show homes”|grep -v : | while read file_line&lt;br /&gt;
do&lt;br /&gt;
echo “INFO: adrci purging diagnostic destination ” $file_line&lt;br /&gt;
echo “——————————————————————————-”&lt;br /&gt;
purge_log ALERT 365&lt;br /&gt;
purge_log INCIDENT 273&lt;br /&gt;
purge_log TRACE 120&lt;br /&gt;
purge_log CDUMP 75&lt;br /&gt;
purge_log HM 75&lt;br /&gt;
echo “——————————————————————————-”&lt;br /&gt;
done&lt;br /&gt;
echo&lt;br /&gt;
echo “INFO: adrci purge finished at `date`”&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Create a package to send to Oracle Support===&lt;br /&gt;
A problem may consist of one or more incidents.&lt;br /&gt;
* Find the problem id&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
show incident -mode detail -p &amp;quot;incident_id=&amp;lt;incident_id&amp;gt;&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* create a package containing all incidents for this problem&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ips create package problem &amp;lt;proble_id&amp;gt; correlate all&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* generate a zipped package file&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ips generate package &amp;lt;proble_id&amp;gt; in &amp;quot;/tmp&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Stuart</name></author>	</entry>

	<entry>
		<id>https://mailnest.com/dbawiki/index.php?title=Adrci&amp;diff=3386</id>
		<title>Adrci</title>
		<link rel="alternate" type="text/html" href="https://mailnest.com/dbawiki/index.php?title=Adrci&amp;diff=3386"/>
				<updated>2018-11-28T13:24:59Z</updated>
		
		<summary type="html">&lt;p&gt;Stuart: /* Shell script to purge ADR data */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;* [http://intermediatesql.com/oracle/oracle-11g-xml-alert-logs-surprise-they-are-actually-more-convenient-to-work-with/ Convenient access to adrci log files]&lt;br /&gt;
* [http://arup.blogspot.co.uk/2013/04/switching-back-to-regular-listener-log.html Switch back to old-style listener log file - not using adr]&lt;br /&gt;
The new way to package problems and their incidents up for Oracle Support.&amp;lt;br /&amp;gt;&lt;br /&gt;
A useful way to keep the purging of trace files under control.&amp;lt;br /&amp;gt;&lt;br /&gt;
With an Oracle database environment setup, type:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
adrci&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
To get out, type:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
adrci&amp;gt; exit&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
To get help, type:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
adrci&amp;gt; help&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Show registered ORACLE_HOMEs&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
show home&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Set one of the homes&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set home diag/rdbms/orcl&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
tail the alert log (adrci reads the XML version of the alert log)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
show alert -tail -f&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Are there any problems?&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
show problem&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Show the incident(s) of this problem&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
show incident&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Show more detail about an incident&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
show incident -mode detail -p &amp;quot;incident_id=&amp;lt;incident number&amp;gt;&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Show the incident trace file for this incident&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
show trace /u01/app/oracle/diag/rdbms/orcl/orcl/incident/incdir_6201/orcl_ora_2299_i6201.trc&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Package a problem up for Oracle Support&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ips create package problem 1 correlate all&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Zip a problem package for Oracle Support&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ips generate package 2 in &amp;quot;/home/oracle&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
To see current setup, type:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
adrci&amp;gt; show control&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Purging trace and dump files in 11g with adrci===&lt;br /&gt;
SHORTP_POLICY and LONGP_POLICY are number of hours to keep trace files and alert files respectively. These can be changed by typing:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set control (SHORTP_POLICY=240)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Trace files will now be deleted after 10 days.&amp;lt;br /&amp;gt;&lt;br /&gt;
If space is running low, you can manually delete trace files.&amp;lt;br /&amp;gt;&lt;br /&gt;
This deletes all trace files older than 1 day (note the age parameter is minutes, not hours).&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
purge -age 3600 -type trace&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Show the tracefiles in reverse time order&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
show tracefile -rt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Use ADR command line interface from shell===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
adrci exec=&amp;quot;show homes&amp;quot;&lt;br /&gt;
adrci exec=&amp;quot;set home diag/tnslsnr/ravjde01/listener_ravjde1;show control&amp;quot;&lt;br /&gt;
adrci exec=&amp;quot;set home diag/tnslsnr/ravjde01/listener_ravjde1;set control (shortp_policy=360,longp_policy=720);purge;show control;&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Show ADR homes related to databases&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ORACLE_HOME/bin/adrci exec=&amp;quot;show homes&amp;quot; | grep &amp;quot;rdbms&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Shell script to purge ADR data===&lt;br /&gt;
Found [http://www.dadbm.com/oracle-database-housekeeping-methods-adr-files-purge/ here]&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Purge ADR contents (adr_purge.sh)&lt;br /&gt;
purge_log () {&lt;br /&gt;
purge_min=$(( 24 * 60 * $2 ))&lt;br /&gt;
echo “INFO: purging $1 older than $2 days”&lt;br /&gt;
adrci exec=”set homepath $file_line;purge -age $purge_min -type $1″&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
echo “INFO: adrci purge started at `date`”&lt;br /&gt;
adrci exec=”show homes”|grep -v : | while read file_line&lt;br /&gt;
do&lt;br /&gt;
echo “INFO: adrci purging diagnostic destination ” $file_line&lt;br /&gt;
echo “——————————————————————————-”&lt;br /&gt;
purge_log ALERT 365&lt;br /&gt;
purge_log INCIDENT 273&lt;br /&gt;
purge_log TRACE 120&lt;br /&gt;
purge_log CDUMP 75&lt;br /&gt;
purge_log HM 75&lt;br /&gt;
echo “——————————————————————————-”&lt;br /&gt;
done&lt;br /&gt;
echo&lt;br /&gt;
echo “INFO: adrci purge finished at `date`”&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Create a package to send to Oracle Support===&lt;br /&gt;
A problem may consist of one or more incidents.&lt;br /&gt;
* Find the problem id&lt;br /&gt;
* create a package containing all incidents for this problem&lt;br /&gt;
* generate a zipped package file&lt;/div&gt;</summary>
		<author><name>Stuart</name></author>	</entry>

	<entry>
		<id>https://mailnest.com/dbawiki/index.php?title=Adrci&amp;diff=3385</id>
		<title>Adrci</title>
		<link rel="alternate" type="text/html" href="https://mailnest.com/dbawiki/index.php?title=Adrci&amp;diff=3385"/>
				<updated>2018-11-28T13:16:44Z</updated>
		
		<summary type="html">&lt;p&gt;Stuart: /* adrci */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;* [http://intermediatesql.com/oracle/oracle-11g-xml-alert-logs-surprise-they-are-actually-more-convenient-to-work-with/ Convenient access to adrci log files]&lt;br /&gt;
* [http://arup.blogspot.co.uk/2013/04/switching-back-to-regular-listener-log.html Switch back to old-style listener log file - not using adr]&lt;br /&gt;
The new way to package problems and their incidents up for Oracle Support.&amp;lt;br /&amp;gt;&lt;br /&gt;
A useful way to keep the purging of trace files under control.&amp;lt;br /&amp;gt;&lt;br /&gt;
With an Oracle database environment setup, type:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
adrci&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
To get out, type:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
adrci&amp;gt; exit&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
To get help, type:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
adrci&amp;gt; help&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Show registered ORACLE_HOMEs&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
show home&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Set one of the homes&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set home diag/rdbms/orcl&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
tail the alert log (adrci reads the XML version of the alert log)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
show alert -tail -f&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Are there any problems?&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
show problem&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Show the incident(s) of this problem&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
show incident&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Show more detail about an incident&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
show incident -mode detail -p &amp;quot;incident_id=&amp;lt;incident number&amp;gt;&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Show the incident trace file for this incident&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
show trace /u01/app/oracle/diag/rdbms/orcl/orcl/incident/incdir_6201/orcl_ora_2299_i6201.trc&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Package a problem up for Oracle Support&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ips create package problem 1 correlate all&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Zip a problem package for Oracle Support&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ips generate package 2 in &amp;quot;/home/oracle&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
To see current setup, type:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
adrci&amp;gt; show control&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Purging trace and dump files in 11g with adrci===&lt;br /&gt;
SHORTP_POLICY and LONGP_POLICY are number of hours to keep trace files and alert files respectively. These can be changed by typing:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set control (SHORTP_POLICY=240)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Trace files will now be deleted after 10 days.&amp;lt;br /&amp;gt;&lt;br /&gt;
If space is running low, you can manually delete trace files.&amp;lt;br /&amp;gt;&lt;br /&gt;
This deletes all trace files older than 1 day (note the age parameter is minutes, not hours).&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
purge -age 3600 -type trace&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Show the tracefiles in reverse time order&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
show tracefile -rt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Use ADR command line interface from shell===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
adrci exec=&amp;quot;show homes&amp;quot;&lt;br /&gt;
adrci exec=&amp;quot;set home diag/tnslsnr/ravjde01/listener_ravjde1;show control&amp;quot;&lt;br /&gt;
adrci exec=&amp;quot;set home diag/tnslsnr/ravjde01/listener_ravjde1;set control (shortp_policy=360,longp_policy=720);purge;show control;&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Show ADR homes related to databases&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ORACLE_HOME/bin/adrci exec=&amp;quot;show homes&amp;quot; | grep &amp;quot;rdbms&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Shell script to purge ADR data===&lt;br /&gt;
Found [http://www.dadbm.com/oracle-database-housekeeping-methods-adr-files-purge/ here]&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Purge ADR contents (adr_purge.sh)&lt;br /&gt;
purge_log () {&lt;br /&gt;
purge_min=$(( 24 * 60 * $2 ))&lt;br /&gt;
echo “INFO: purging $1 older than $2 days”&lt;br /&gt;
adrci exec=”set homepath $file_line;purge -age $purge_min -type $1″&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
echo “INFO: adrci purge started at `date`”&lt;br /&gt;
adrci exec=”show homes”|grep -v : | while read file_line&lt;br /&gt;
do&lt;br /&gt;
echo “INFO: adrci purging diagnostic destination ” $file_line&lt;br /&gt;
echo “——————————————————————————-”&lt;br /&gt;
purge_log ALERT 365&lt;br /&gt;
purge_log INCIDENT 273&lt;br /&gt;
purge_log TRACE 120&lt;br /&gt;
purge_log CDUMP 75&lt;br /&gt;
purge_log HM 75&lt;br /&gt;
echo “——————————————————————————-”&lt;br /&gt;
done&lt;br /&gt;
echo&lt;br /&gt;
echo “INFO: adrci purge finished at `date`”&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Stuart</name></author>	</entry>

	<entry>
		<id>https://mailnest.com/dbawiki/index.php?title=Adrci&amp;diff=3384</id>
		<title>Adrci</title>
		<link rel="alternate" type="text/html" href="https://mailnest.com/dbawiki/index.php?title=Adrci&amp;diff=3384"/>
				<updated>2018-11-28T13:10:32Z</updated>
		
		<summary type="html">&lt;p&gt;Stuart: /* Purging trace and dump files in 11g with adrci */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;* [http://intermediatesql.com/oracle/oracle-11g-xml-alert-logs-surprise-they-are-actually-more-convenient-to-work-with/ Convenient access to adrci log files]&lt;br /&gt;
* [http://arup.blogspot.co.uk/2013/04/switching-back-to-regular-listener-log.html Switch back to old-style listener log file - not using adr]&lt;br /&gt;
===adrci===&lt;br /&gt;
The new way to package problems and their incidents up for Oracle Support.&amp;lt;br /&amp;gt;&lt;br /&gt;
A useful way to keep the purging of trace files under control.&amp;lt;br /&amp;gt;&lt;br /&gt;
With an Oracle database environment setup, type:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
adrci&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
To get out, type:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
adrci&amp;gt; exit&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
To get help, type:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
adrci&amp;gt; help&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Show registered ORACLE_HOMEs&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
show home&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Set one of the homes&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set home diag/rdbms/orcl&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
tail the alert log (adrci reads the XML version of the alert log)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
show alert -tail -f&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Are there any problems?&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
show problem&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Show the incident(s) of this problem&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
show incident&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Show more detail about an incident&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
show incident -mode detail -p &amp;quot;incident_id=&amp;lt;incident number&amp;gt;&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Show the incident trace file for this incident&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
show trace /u01/app/oracle/diag/rdbms/orcl/orcl/incident/incdir_6201/orcl_ora_2299_i6201.trc&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Package a problem up for Oracle Support&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ips create package problem 1 correlate all&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Zip a problem package for Oracle Support&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ips generate package 2 in &amp;quot;/home/oracle&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
To see current setup, type:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
adrci&amp;gt; show control&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Purging trace and dump files in 11g with adrci===&lt;br /&gt;
SHORTP_POLICY and LONGP_POLICY are number of hours to keep trace files and alert files respectively. These can be changed by typing:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set control (SHORTP_POLICY=240)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Trace files will now be deleted after 10 days.&amp;lt;br /&amp;gt;&lt;br /&gt;
If space is running low, you can manually delete trace files.&amp;lt;br /&amp;gt;&lt;br /&gt;
This deletes all trace files older than 1 day (note the age parameter is minutes, not hours).&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
purge -age 3600 -type trace&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Show the tracefiles in reverse time order&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
show tracefile -rt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Use ADR command line interface from shell===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
adrci exec=&amp;quot;show homes&amp;quot;&lt;br /&gt;
adrci exec=&amp;quot;set home diag/tnslsnr/ravjde01/listener_ravjde1;show control&amp;quot;&lt;br /&gt;
adrci exec=&amp;quot;set home diag/tnslsnr/ravjde01/listener_ravjde1;set control (shortp_policy=360,longp_policy=720);purge;show control;&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Show ADR homes related to databases&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ORACLE_HOME/bin/adrci exec=&amp;quot;show homes&amp;quot; | grep &amp;quot;rdbms&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Shell script to purge ADR data===&lt;br /&gt;
Found [http://www.dadbm.com/oracle-database-housekeeping-methods-adr-files-purge/ here]&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Purge ADR contents (adr_purge.sh)&lt;br /&gt;
purge_log () {&lt;br /&gt;
purge_min=$(( 24 * 60 * $2 ))&lt;br /&gt;
echo “INFO: purging $1 older than $2 days”&lt;br /&gt;
adrci exec=”set homepath $file_line;purge -age $purge_min -type $1″&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
echo “INFO: adrci purge started at `date`”&lt;br /&gt;
adrci exec=”show homes”|grep -v : | while read file_line&lt;br /&gt;
do&lt;br /&gt;
echo “INFO: adrci purging diagnostic destination ” $file_line&lt;br /&gt;
echo “——————————————————————————-”&lt;br /&gt;
purge_log ALERT 365&lt;br /&gt;
purge_log INCIDENT 273&lt;br /&gt;
purge_log TRACE 120&lt;br /&gt;
purge_log CDUMP 75&lt;br /&gt;
purge_log HM 75&lt;br /&gt;
echo “——————————————————————————-”&lt;br /&gt;
done&lt;br /&gt;
echo&lt;br /&gt;
echo “INFO: adrci purge finished at `date`”&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Stuart</name></author>	</entry>

	<entry>
		<id>https://mailnest.com/dbawiki/index.php?title=Adrci&amp;diff=3383</id>
		<title>Adrci</title>
		<link rel="alternate" type="text/html" href="https://mailnest.com/dbawiki/index.php?title=Adrci&amp;diff=3383"/>
				<updated>2018-11-28T13:09:17Z</updated>
		
		<summary type="html">&lt;p&gt;Stuart: /* adrci */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;* [http://intermediatesql.com/oracle/oracle-11g-xml-alert-logs-surprise-they-are-actually-more-convenient-to-work-with/ Convenient access to adrci log files]&lt;br /&gt;
* [http://arup.blogspot.co.uk/2013/04/switching-back-to-regular-listener-log.html Switch back to old-style listener log file - not using adr]&lt;br /&gt;
===adrci===&lt;br /&gt;
The new way to package problems and their incidents up for Oracle Support.&amp;lt;br /&amp;gt;&lt;br /&gt;
A useful way to keep the purging of trace files under control.&amp;lt;br /&amp;gt;&lt;br /&gt;
With an Oracle database environment setup, type:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
adrci&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
To get out, type:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
adrci&amp;gt; exit&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
To get help, type:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
adrci&amp;gt; help&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Show registered ORACLE_HOMEs&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
show home&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Set one of the homes&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set home diag/rdbms/orcl&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
tail the alert log (adrci reads the XML version of the alert log)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
show alert -tail -f&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Are there any problems?&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
show problem&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Show the incident(s) of this problem&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
show incident&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Show more detail about an incident&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
show incident -mode detail -p &amp;quot;incident_id=&amp;lt;incident number&amp;gt;&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Show the incident trace file for this incident&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
show trace /u01/app/oracle/diag/rdbms/orcl/orcl/incident/incdir_6201/orcl_ora_2299_i6201.trc&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Package a problem up for Oracle Support&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ips create package problem 1 correlate all&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Zip a problem package for Oracle Support&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ips generate package 2 in &amp;quot;/home/oracle&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
To see current setup, type:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
adrci&amp;gt; show control&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Purging trace and dump files in 11g with adrci====&lt;br /&gt;
SHORTP_POLICY and LONGP_POLICY are number of hours to keep trace files and alert files respectively. These can be changed by typing:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set control (SHORTP_POLICY=240)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Trace files will now be deleted after 10 days.&amp;lt;br /&amp;gt;&lt;br /&gt;
If space is running low, you can manually delete trace files.&amp;lt;br /&amp;gt;&lt;br /&gt;
This deletes all trace files older than 1 day (note the age parameter is minutes, not hours).&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
purge -age 3600 -type trace&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Show the tracefiles in reverse time order&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
show tracefile -rt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Use ADR command line interface from shell===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
adrci exec=&amp;quot;show homes&amp;quot;&lt;br /&gt;
adrci exec=&amp;quot;set home diag/tnslsnr/ravjde01/listener_ravjde1;show control&amp;quot;&lt;br /&gt;
adrci exec=&amp;quot;set home diag/tnslsnr/ravjde01/listener_ravjde1;set control (shortp_policy=360,longp_policy=720);purge;show control;&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Show ADR homes related to databases&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ORACLE_HOME/bin/adrci exec=&amp;quot;show homes&amp;quot; | grep &amp;quot;rdbms&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Shell script to purge ADR data===&lt;br /&gt;
Found [http://www.dadbm.com/oracle-database-housekeeping-methods-adr-files-purge/ here]&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Purge ADR contents (adr_purge.sh)&lt;br /&gt;
purge_log () {&lt;br /&gt;
purge_min=$(( 24 * 60 * $2 ))&lt;br /&gt;
echo “INFO: purging $1 older than $2 days”&lt;br /&gt;
adrci exec=”set homepath $file_line;purge -age $purge_min -type $1″&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
echo “INFO: adrci purge started at `date`”&lt;br /&gt;
adrci exec=”show homes”|grep -v : | while read file_line&lt;br /&gt;
do&lt;br /&gt;
echo “INFO: adrci purging diagnostic destination ” $file_line&lt;br /&gt;
echo “——————————————————————————-”&lt;br /&gt;
purge_log ALERT 365&lt;br /&gt;
purge_log INCIDENT 273&lt;br /&gt;
purge_log TRACE 120&lt;br /&gt;
purge_log CDUMP 75&lt;br /&gt;
purge_log HM 75&lt;br /&gt;
echo “——————————————————————————-”&lt;br /&gt;
done&lt;br /&gt;
echo&lt;br /&gt;
echo “INFO: adrci purge finished at `date`”&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Stuart</name></author>	</entry>

	<entry>
		<id>https://mailnest.com/dbawiki/index.php?title=Adrci&amp;diff=3382</id>
		<title>Adrci</title>
		<link rel="alternate" type="text/html" href="https://mailnest.com/dbawiki/index.php?title=Adrci&amp;diff=3382"/>
				<updated>2018-11-28T13:07:53Z</updated>
		
		<summary type="html">&lt;p&gt;Stuart: Stuart moved page Purging trace and dump files in 11g with adrci to Adrci without leaving a redirect&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;* [http://intermediatesql.com/oracle/oracle-11g-xml-alert-logs-surprise-they-are-actually-more-convenient-to-work-with/ Convenient access to adrci log files]&lt;br /&gt;
* [http://arup.blogspot.co.uk/2013/04/switching-back-to-regular-listener-log.html Switch back to old-style listener log file - not using adr]&lt;br /&gt;
===adrci===&lt;br /&gt;
The new way to package problems and their incidents up for Oracle Support.&amp;lt;br /&amp;gt;&lt;br /&gt;
A useful way to keep the purging of trace files under control.&amp;lt;br /&amp;gt;&lt;br /&gt;
With an Oracle database environment setup, type:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
adrci&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
To get out, type:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
adrci&amp;gt; exit&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
To get help, type:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
adrci&amp;gt; help&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Show registered ORACLE_HOMEs&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
show home&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Set one of the homes&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set home diag/rdbms/orcl&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
tail the alert log (adrci reads the XML version of the alert log)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
show alert -tail -f&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Are there any problems?&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
show problem&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Show the incident(s) of this problem&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
show incident&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Show more detail about an incident&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
show incident -mode detail -p &amp;quot;incident_id=&amp;lt;incident number&amp;gt;&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Show the incident trace file for this incident&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
show trace /u01/app/oracle/diag/rdbms/orcl/orcl/incident/incdir_6201/orcl_ora_2299_i6201.trc&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Package a problem up for Oracle Support&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ips create package problem 1 correlate all&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Zip a problem package for Oracle Support&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ips generate package 2 in &amp;quot;/home/oracle&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
To see current setup, type:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
adrci&amp;gt; show control&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
SHORTP_POLICY and LONGP_POLICY are number of hours to keep trace files and alert files respectively. These can be changed by typing:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set control (SHORTP_POLICY=240)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Trace files will now be deleted after 10 days.&amp;lt;br /&amp;gt;&lt;br /&gt;
If space is running low, you can manually delete trace files.&amp;lt;br /&amp;gt;&lt;br /&gt;
This deletes all trace files older than 1 day (note the age parameter is minutes, not hours).&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
purge -age 3600 -type trace&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Show the tracefiles in reverse time order&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
show tracefile -rt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Use ADR command line interface from shell===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
adrci exec=&amp;quot;show homes&amp;quot;&lt;br /&gt;
adrci exec=&amp;quot;set home diag/tnslsnr/ravjde01/listener_ravjde1;show control&amp;quot;&lt;br /&gt;
adrci exec=&amp;quot;set home diag/tnslsnr/ravjde01/listener_ravjde1;set control (shortp_policy=360,longp_policy=720);purge;show control;&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Show ADR homes related to databases&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ORACLE_HOME/bin/adrci exec=&amp;quot;show homes&amp;quot; | grep &amp;quot;rdbms&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Shell script to purge ADR data===&lt;br /&gt;
Found [http://www.dadbm.com/oracle-database-housekeeping-methods-adr-files-purge/ here]&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Purge ADR contents (adr_purge.sh)&lt;br /&gt;
purge_log () {&lt;br /&gt;
purge_min=$(( 24 * 60 * $2 ))&lt;br /&gt;
echo “INFO: purging $1 older than $2 days”&lt;br /&gt;
adrci exec=”set homepath $file_line;purge -age $purge_min -type $1″&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
echo “INFO: adrci purge started at `date`”&lt;br /&gt;
adrci exec=”show homes”|grep -v : | while read file_line&lt;br /&gt;
do&lt;br /&gt;
echo “INFO: adrci purging diagnostic destination ” $file_line&lt;br /&gt;
echo “——————————————————————————-”&lt;br /&gt;
purge_log ALERT 365&lt;br /&gt;
purge_log INCIDENT 273&lt;br /&gt;
purge_log TRACE 120&lt;br /&gt;
purge_log CDUMP 75&lt;br /&gt;
purge_log HM 75&lt;br /&gt;
echo “——————————————————————————-”&lt;br /&gt;
done&lt;br /&gt;
echo&lt;br /&gt;
echo “INFO: adrci purge finished at `date`”&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Stuart</name></author>	</entry>

	<entry>
		<id>https://mailnest.com/dbawiki/index.php?title=Unix/Linux&amp;diff=3381</id>
		<title>Unix/Linux</title>
		<link rel="alternate" type="text/html" href="https://mailnest.com/dbawiki/index.php?title=Unix/Linux&amp;diff=3381"/>
				<updated>2018-11-27T11:48:10Z</updated>
		
		<summary type="html">&lt;p&gt;Stuart: /* ps listing does not show start time after 24 hours */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;* [http://hyperpolyglot.org/unix-shells#var-expansion Good shell comparison including variable expansion - hyperpolyglot.org]&lt;br /&gt;
* [http://pubs.opengroup.org/onlinepubs/9699919799/utilities/toc.html Shell coding standards - opengroup.org]&lt;br /&gt;
* [http://aix4admins.blogspot.be aix4admins]&lt;br /&gt;
* [http://linuxgazette.net/issue55/okopnik.html The Deep, Dark Secrets of Bash]&lt;br /&gt;
* [http://www.speakeasy.org/~arkay/216-7.4KshFunctions.html Korn Shell Functions]&lt;br /&gt;
* [http://www.grymoire.com/Unix/AwkRef.html AWK reference from Bruce Barnett]&lt;br /&gt;
* [http://www.catonmat.net/blog/wp-content/uploads/2008/09/awk1line.txt HANDY AWK ONE-LINERS]&lt;br /&gt;
* [http://www.grymoire.com/unix/Quote.html Unix quoting from from Bruce Barnett (grymoire)]&lt;br /&gt;
* [http://www.mpi-inf.mpg.de/departments/rg1/teaching/unixffb-ss98/quoting-guide.html Another excellent quoting tutorial]&lt;br /&gt;
* [http://aix4admins.blogspot.be/2015/02/snapshot-fs-snapshot-snapshot-is-state.html AIX snapshot technology]&lt;br /&gt;
* [[RaspberryPi]]&lt;br /&gt;
* [[SSH]]&lt;br /&gt;
* [http://www.anattatechnologies.com/q/2013/04/multiuser-screen/ Screen sharing from Unix using screen]&lt;br /&gt;
* [https://robots.thoughtbot.com/a-tmux-crash-course Screen sharing from Unix using tmux]&lt;br /&gt;
* [http://www.csb.yale.edu/userguides/wordprocess/vi-summary.html Handy ex and vi reference]&lt;br /&gt;
* [[Fedora install for my own purposes]]&lt;br /&gt;
&lt;br /&gt;
===Use sed to repeat characters===&lt;br /&gt;
echo an &amp;#039;=&amp;#039; sign then use the loop feature of sed to run round a loop a further 79 times replacing what you&amp;#039;ve got with the same thing plus and extra one!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
echo &amp;quot;=&amp;quot; | sed -e :a -e &amp;#039;s/^=\{1,79\}$/&amp;amp;=/;ta&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Convert between lower and upper case using ansi standard===&lt;br /&gt;
This way should be portable and give predictable results&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
LOWER_SID=$(echo &amp;quot;${SID}&amp;quot; | tr &amp;#039;[:upper:]&amp;#039; &amp;#039;[:lower:]&amp;#039;)&lt;br /&gt;
UPPER_SID=$(echo &amp;quot;${SID}&amp;quot; | tr &amp;#039;[:lower:]&amp;#039; &amp;#039;[:upper:]&amp;#039;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Use sed to delete the first line of a file or command output printing from the second line onwards===&lt;br /&gt;
Actually deceptively simple. Example remove the header from df output.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
df -k | sed 1d&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
As a useful extension, suppose TO_DATA_DIR contains multiple directories, this will total the free space for all relevant filesystems&amp;lt;br /&amp;gt;&lt;br /&gt;
This one is specific to AIX, for other Unixes and Linux, use $4 instead of $3.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SPACE_AVAILABLE=$(df -k $TO_DATA_DIR | sed 1d | awk &amp;#039;BEGIN {i=0} {i=i+$3} END {print i}&amp;#039;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Use sed to munge a controlfile into submission!===&lt;br /&gt;
* delete comment lines&lt;br /&gt;
* delete all lines after the one starting with a semicolon&lt;br /&gt;
* delete all blank lines&lt;br /&gt;
* change reuse to set&lt;br /&gt;
* change archivelog (with word boundaries) to noarchivelog&lt;br /&gt;
* change old sid to new sid&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sqlplus -s / as sysdba&amp;lt;&amp;lt;&amp;#039;EOSQL&amp;#039; &amp;gt;/dev/null&lt;br /&gt;
alter database backup controlfile to trace as &amp;#039;/tmp/regenerate_controlfile.sql&amp;#039; reuse resetlogs;&lt;br /&gt;
EOSQL&lt;br /&gt;
OLDSID=&amp;#039;PROD&amp;#039;&lt;br /&gt;
NEWSID=&amp;#039;TEST&amp;#039;&lt;br /&gt;
sed  -e &amp;#039;/^--/d&amp;#039; -e &amp;#039;/^\;/q&amp;#039; -e &amp;#039;/^ *$/d&amp;#039; -e &amp;#039;s/REUSE/SET/&amp;#039; -e &amp;#039;s/\&amp;lt;ARCHIVELOG\&amp;gt;/NOARCHIVELOG/&amp;#039; -e &amp;#039;s/\&amp;quot;&amp;#039;${OLDSID}&amp;#039;\&amp;quot;/\&amp;quot;&amp;#039;${NEWSID}&amp;#039;\&amp;quot;/&amp;#039; /tmp/regenerate_controlfile.sql&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Find all files where a certain text does not exist===&lt;br /&gt;
Mostly we want to search for files containing a particular string but how to find those files that do not contain some text.&amp;lt;br /&amp;gt;&lt;br /&gt;
Using xargs instead of -exec forces the filename to be printed. -H should do this but doesn&amp;#039;t seem to in this case.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
find . -name &amp;quot;*cfg&amp;quot; | xargs grep -H -c TO_CV_HOST {} \; | grep &amp;#039;:0$&amp;#039; | cut -d: -f1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Use tar and gzip to copy files more efficiently across network between hosts===&lt;br /&gt;
From the destination server, this will connect to the source, tar up each file and pull it back to the current server&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ssh oracle@hn5211 &amp;quot;cd /oracle/ora_data4/iten3/ &amp;amp;&amp;amp; tar -cf - . | gzip &amp;quot; | ( cd /oracle/ora_data2/iten/ &amp;amp;&amp;amp; gunzip -c | tar -xvf - . )&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===double hash and double percent in shell variables to trim off characters from variables===&lt;br /&gt;
&amp;lt;nowiki&amp;gt;#&amp;lt;/nowiki&amp;gt;  - trims everything from the start of line till the FIRST occurrence of following character (abstemious) :-)&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;nowiki&amp;gt;##&amp;lt;/nowiki&amp;gt; - trims everything from the start of line till the LAST occurrence of following character (greedy)&amp;lt;br /&amp;gt;&lt;br /&gt;
%  - trims everything from the end of line backwards till the FIRST occurrence of following character (abstemious)&amp;lt;br /&amp;gt;&lt;br /&gt;
%% - trims everything from the end of line backwards till the LAST occurrence of following character (greedy)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
FILENAME=&amp;quot;/home/bey9at77/hello.txt&amp;quot;&lt;br /&gt;
FILE_STUB1=${FILENAME##*/}&lt;br /&gt;
FILE_STUB=${FILE_STUB1%.*}&lt;br /&gt;
echo $FILE_STUB&lt;br /&gt;
hello&lt;br /&gt;
FILE_EXT=${FILENAME##*.}&lt;br /&gt;
echo $FILE_EXT&lt;br /&gt;
txt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;nowiki&amp;gt;#&amp;lt;/nowiki&amp;gt; - remove prefix reluctantly&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;nowiki&amp;gt;##&amp;lt;/nowiki&amp;gt; - remove prefix greedily&amp;lt;br /&amp;gt;&lt;br /&gt;
% - remove suffix reluctantly&amp;lt;br /&amp;gt;&lt;br /&gt;
%% - remove suffix greedily&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
words=&amp;quot;do.re.mi&amp;quot;&lt;br /&gt;
&lt;br /&gt;
echo ${words#*.}&lt;br /&gt;
&lt;br /&gt;
echo ${words##*.}&lt;br /&gt;
&lt;br /&gt;
echo ${words%.*}&lt;br /&gt;
&lt;br /&gt;
echo ${words%%.*}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===The best shell script ever. An example of how scripting should be done===&lt;br /&gt;
It was written by someone at Oracle. Unfortunately (s)he did not put any author comment in it. Also unfortunately I cannot show it here as it is protected behind Oracles support website.&amp;lt;br /&amp;gt;&lt;br /&gt;
If you have an Oracle Metalink id, you can get the complete script [https://support.oracle.com/epmos/faces/DocumentDisplay?id=949322.1 here]&amp;lt;br /&amp;gt;&lt;br /&gt;
Here is a snippet of a function that demonstrates proper commenting and a very good style.&amp;lt;br &amp;gt;&lt;br /&gt;
The script is called physru.sh and upgrades an Oracle database in a rolling upgrade fashion by using a physical standby.&amp;lt;br /&amp;gt;&lt;br /&gt;
There are 4500 lines in the full script but it is so easy to read and understand because of the way it&amp;#039;s written, it&amp;#039;s like a breath of fresh air. Well done whoever you are!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
###############################################################################&lt;br /&gt;
# NAME:        wait_mrp_active&lt;br /&gt;
#&lt;br /&gt;
# DESCRIPTION: &lt;br /&gt;
#   Wait for $MRP_START_TIMEOUT minutes to confirm that the MRP is active.  If&lt;br /&gt;
#   we can&amp;#039;t detect an active MRP, abort the script with an error.&lt;br /&gt;
#&lt;br /&gt;
# INPUT(S):&lt;br /&gt;
#   Arguments:&lt;br /&gt;
#     $1: database user&lt;br /&gt;
#     $2: user password&lt;br /&gt;
#     $3: tns service name&lt;br /&gt;
#     $4: database unique name&lt;br /&gt;
#&lt;br /&gt;
#   Globals:&lt;br /&gt;
#     None&lt;br /&gt;
#&lt;br /&gt;
# RETURN:&lt;br /&gt;
#   None&lt;br /&gt;
#&lt;br /&gt;
###############################################################################&lt;br /&gt;
wait_mrp_active()&lt;br /&gt;
{&lt;br /&gt;
  display &amp;quot;confirming media recovery is running&amp;quot;&lt;br /&gt;
  l_wma_status=1&lt;br /&gt;
  l_wma_curtime=`perl -e &amp;#039;print int(time)&amp;#039;`&lt;br /&gt;
  l_wma_exptime=`expr $MRP_START_TIMEOUT &amp;quot;*&amp;quot; 60`&lt;br /&gt;
  l_wma_maxtime=`expr $l_wma_curtime + $l_wma_exptime`&lt;br /&gt;
  while [ &amp;quot;$l_wma_curtime&amp;quot; -lt &amp;quot;$l_wma_maxtime&amp;quot; ]&lt;br /&gt;
  do&lt;br /&gt;
    is_mrp_running $1 $2 $3 $4&lt;br /&gt;
    if [ &amp;quot;$?&amp;quot; -gt &amp;quot;0&amp;quot; ]; then&lt;br /&gt;
      l_wma_status=0&lt;br /&gt;
      break&lt;br /&gt;
    fi&lt;br /&gt;
&lt;br /&gt;
    sleep $MRP_START_INTERVAL&lt;br /&gt;
    l_wma_curtime=`perl -e &amp;#039;print int(time)&amp;#039;`&lt;br /&gt;
  done&lt;br /&gt;
  chkerr $l_wma_status &amp;quot;could not detect an active MRP after $MRP_START_TIMEOUT minutes&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===split variable (eg. filename) into separate variables using set===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
FILENAME=&amp;quot;split_this_into_bits&amp;quot;&lt;br /&gt;
set $(echo ${FILENAME} | sed &amp;#039;s/_/ /g&amp;#039;)&lt;br /&gt;
echo $4 $3 $2 $1&lt;br /&gt;
bits into this split&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Centre align text on a line in bash shell===&lt;br /&gt;
Doesn&amp;#039;t work in Korn shell due to %*s&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#COLUMNS=$(tput cols)   # width of the current window&lt;br /&gt;
COLUMNS=80&lt;br /&gt;
title=&amp;quot;Hello world!&amp;quot;&lt;br /&gt;
printf &amp;quot;%*s\n&amp;quot; $(((${#title}+$COLUMNS)/2)) &amp;quot;$title&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
and as a one-liner&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
printf &amp;quot;%*s\n&amp;quot; $(( ( $(echo $* | wc -c ) + 80 ) / 2 )) &amp;quot;$*&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This works in Korn shell...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
TITLE=&amp;quot;$1&amp;quot;&lt;br /&gt;
LINEWIDTH=80&lt;br /&gt;
&lt;br /&gt;
LPAD=$(((${#TITLE}+$LINEWIDTH)/2))&lt;br /&gt;
printf %${LPAD}s &amp;quot;$TITLE&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Right justify text (or repeat characters) on a line with leader dots!===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
function rpadwait {&lt;br /&gt;
    text=$1&lt;br /&gt;
# -------------------------&lt;br /&gt;
# suppress newline for echo&lt;br /&gt;
# -------------------------&lt;br /&gt;
N=&lt;br /&gt;
C=&lt;br /&gt;
if echo &amp;quot;\c&amp;quot; | grep c &amp;gt;/dev/null 2&amp;gt;&amp;amp;1; then&lt;br /&gt;
    N=&amp;#039;-n&amp;#039;&lt;br /&gt;
else&lt;br /&gt;
    C=&amp;#039;\c&amp;#039;&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
    echo ${N} &amp;quot;${text}${C}&amp;quot; | sed -e :a -e &amp;#039;s/^.\{1,80\}$/&amp;amp;\./;ta&amp;#039;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===cron jobs not submitted - daemon run out of child processes?===&lt;br /&gt;
Sometimes have problems with NFS mounts and this causes cron jobs to hang. If they are scheduled to run regularly, eventually cron will no longer be able to start any more jobs.&amp;lt;br /&amp;gt;&lt;br /&gt;
* Check the cron log &amp;#039;&amp;#039;&amp;#039;/var/adm/cron/log&amp;#039;&amp;#039;&amp;#039; to see if there are any errors or other messages around the time the jobs should run.&lt;br /&gt;
If cron has hit its process limit (default 100), it will try again after a number of seconds (default 60).&amp;lt;br /&amp;gt;&lt;br /&gt;
Both the number of jobs and wait time are configured in the file &amp;#039;&amp;#039;&amp;#039;/var/adm/cron/queuedefs&amp;#039;&amp;#039;&amp;#039;. If it is unusual for cron to be running so many jobs, you can check the process table to view the jobs cron has created. These jobs will have parent process id (PPID) of the cron daemon.&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ ps -ef | grep cron | grep -v grep&lt;br /&gt;
    root  6750314        1   0   Apr 24      -  3:39 /usr/sbin/cron&lt;br /&gt;
solax025:root[/home/root]# ps -T 6750314&lt;br /&gt;
      PID    TTY  TIME CMD&lt;br /&gt;
  6750314      -  3:39 cron&lt;br /&gt;
 21168296      -  0:00     \--bsh&lt;br /&gt;
 58982414      -  0:00         \--sadc&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
In this example, we only have 1 job running&lt;br /&gt;
&lt;br /&gt;
===Find long-running processes with a cron job===&lt;br /&gt;
Processes running longer than 24 hours have a date instead of a start time...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
58 08,14 * * * /home/ibmtools/scripts/oracle/dosh -vc &amp;quot;ps -ef|grep &amp;#039;ibmtools/scripts/oracle&amp;#039;|perl -nae &amp;#039;print if \$F[4] !~/:/&amp;#039;&amp;quot; &amp;gt;/tmp/lrp.txt; [[ $(grep -c ibmtools /tmp/lrp.txt) -ne 0 ]] &amp;amp;&amp;amp; cat /tmp/lrp.txt|mailx -s &amp;#039;*** long running processes - please check ***&amp;#039; reporting@companymail.com&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Process command line arguments in shell===&lt;br /&gt;
Borrowed from Mozilla Firefox installer&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
## Command line arg defaults&lt;br /&gt;
##&lt;br /&gt;
moz_debug=0&lt;br /&gt;
moz_debugger=&amp;quot;&amp;quot;&lt;br /&gt;
moz_debugger_args=&amp;quot;&amp;quot;&lt;br /&gt;
#&lt;br /&gt;
##&lt;br /&gt;
## Parse the command line&lt;br /&gt;
##&lt;br /&gt;
while [ $# -gt 0 ]&lt;br /&gt;
do&lt;br /&gt;
  case $1 in&lt;br /&gt;
    -g | --debug)&lt;br /&gt;
      moz_debug=1&lt;br /&gt;
      shift&lt;br /&gt;
      ;;&lt;br /&gt;
    -d | --debugger)&lt;br /&gt;
      moz_debugger=$2;&lt;br /&gt;
      if [ &amp;quot;${moz_debugger}&amp;quot; != &amp;quot;&amp;quot; ]; then&lt;br /&gt;
	shift 2&lt;br /&gt;
      else&lt;br /&gt;
        echo &amp;quot;-d requires an argument&amp;quot;&lt;br /&gt;
        exit 1&lt;br /&gt;
      fi&lt;br /&gt;
      ;;&lt;br /&gt;
    -a | --debugger-args)&lt;br /&gt;
      moz_debugger_args=$2;&lt;br /&gt;
      if [ &amp;quot;${moz_debugger_args}&amp;quot; != &amp;quot;&amp;quot; ]; then&lt;br /&gt;
	shift 2&lt;br /&gt;
      else&lt;br /&gt;
        echo &amp;quot;-a requires an argument&amp;quot;&lt;br /&gt;
        exit 1&lt;br /&gt;
      fi&lt;br /&gt;
      ;;&lt;br /&gt;
    *)&lt;br /&gt;
      break;&lt;br /&gt;
      ;;&lt;br /&gt;
  esac&lt;br /&gt;
done&lt;br /&gt;
#&lt;br /&gt;
##&lt;br /&gt;
## Program name given in $1&lt;br /&gt;
##&lt;br /&gt;
if [ $# -gt 0 ]&lt;br /&gt;
then&lt;br /&gt;
	MOZ_PROGRAM=$1&lt;br /&gt;
	shift&lt;br /&gt;
fi&lt;br /&gt;
##&lt;br /&gt;
## Program not given, try to guess a default&lt;br /&gt;
##&lt;br /&gt;
if [ -z &amp;quot;$MOZ_PROGRAM&amp;quot; ]&lt;br /&gt;
then&lt;br /&gt;
	##&lt;br /&gt;
	## Try this script&amp;#039;s name with &amp;#039;-bin&amp;#039; appended&lt;br /&gt;
	##&lt;br /&gt;
	if [ -x &amp;quot;$MOZ_DEFAULT_NAME&amp;quot; ]&lt;br /&gt;
	then&lt;br /&gt;
		MOZ_PROGRAM=$MOZ_DEFAULT_NAME&lt;br /&gt;
	##&lt;br /&gt;
	## Try mozilla-bin&lt;br /&gt;
	## &lt;br /&gt;
	elif [ -x &amp;quot;$MOZ_APPRUNNER_NAME&amp;quot; ]&lt;br /&gt;
	then&lt;br /&gt;
		MOZ_PROGRAM=$MOZ_APPRUNNER_NAME&lt;br /&gt;
	fi&lt;br /&gt;
fi&lt;br /&gt;
#&lt;br /&gt;
#&lt;br /&gt;
##&lt;br /&gt;
## Make sure the program is executable&lt;br /&gt;
##&lt;br /&gt;
if [ ! -x &amp;quot;$MOZ_PROGRAM&amp;quot; ]&lt;br /&gt;
then&lt;br /&gt;
	moz_bail &amp;quot;Cannot execute $MOZ_PROGRAM.&amp;quot;&lt;br /&gt;
fi&lt;br /&gt;
#&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Carry XWindows settings across sessions===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# ----------------------&lt;br /&gt;
# push XWindows settings&lt;br /&gt;
# ----------------------&lt;br /&gt;
[[ &amp;quot;$(uname)&amp;quot; == &amp;quot;SunOS&amp;quot; ]] &amp;amp;&amp;amp; PATH=/usr/openwin/bin:$PATH&lt;br /&gt;
WHOAMI=$(id | awk -F&amp;#039;)&amp;#039; &amp;#039;{print $1}&amp;#039; | awk -F&amp;#039;(&amp;#039; &amp;#039;{print $2}&amp;#039;)&lt;br /&gt;
xauth list &amp;gt; /tmp/xauth_list_$WHOAMI&lt;br /&gt;
chmod 777 /tmp/xauth_list_$WHOAMI&lt;br /&gt;
&lt;br /&gt;
echo $DISPLAY &amp;gt; /tmp/xdisplay_$WHOAMI&lt;br /&gt;
chmod 777 /tmp/xdisplay_$WHOAMI&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Cross-platform version of whoami===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
WHOAMI=$(id | awk -F&amp;#039;)&amp;#039; &amp;#039;{print $1}&amp;#039; | awk -F&amp;#039;(&amp;#039; &amp;#039;{print $2}&amp;#039;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Set terminal title from command line===&lt;br /&gt;
Put something like this in the .profile&amp;lt;br /&amp;gt;&lt;br /&gt;
-n     do not output the trailing newline&amp;lt;br /&amp;gt;&lt;br /&gt;
-e     enable interpretation of backslash escapes&amp;lt;br /&amp;gt;&lt;br /&gt;
|0     sets title of window and icon&amp;lt;br /&amp;gt;&lt;br /&gt;
|1     sets title of icon only&amp;lt;br /&amp;gt;&lt;br /&gt;
|2     sets title of window only&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
echo -en &amp;quot;\033]0;`hostname`\007&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
echo -en &amp;quot;\033]2;`hostname`\007&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Remove blank lines and comments (also indented ones) from a file===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
awk -F\: &amp;#039;!/^($|[:space:]*#)/ {print $2}&amp;#039; /etc/oratab | sort | uniq&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or as part of a script that removes comments and blank lines from all Korn shell scripts in a directory&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/usr/bin/ksh&lt;br /&gt;
for i in $(ls *ksh); do&lt;br /&gt;
    perl -p -i -e &amp;#039;s/^\s*#[^!]*$//; s/^\s*$//&amp;#039; $i&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Return elements of an array in Korn shell===&lt;br /&gt;
From [http://unix.stackexchange.com/questions/188202/processing-output-from-an-sqlite-db-into-a-ksh-array-with-spaces here]&amp;lt;br /&amp;gt;&lt;br /&gt;
Could be used to separate the columns of an SQL select when returning to the shell&amp;lt;br /&amp;gt;&lt;br /&gt;
This approach eliminates the need to put quotes around text with spaces in it.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
echo $KSH_VERSION&lt;br /&gt;
x=&amp;quot;Red,Yellow is a color,Blue&amp;quot;&lt;br /&gt;
oIFS=$IFS&lt;br /&gt;
IFS=,&lt;br /&gt;
y=($x)&lt;br /&gt;
IFS=$oIFS&lt;br /&gt;
echo ${y[1]}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===A decent Unix Prompt===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
export PS1=&amp;quot;`uname -n`:`whoami`[\${PWD}]# &amp;quot;&lt;br /&gt;
or&lt;br /&gt;
export PS1=&amp;#039;($?) $&amp;#039;ORACLE_SID&amp;quot; &amp;quot;`whoami`&amp;quot;@&amp;quot;`uname -n`&amp;quot;:&amp;quot;&amp;#039;$&amp;#039;PWD&amp;quot;&amp;gt; &amp;quot;&lt;br /&gt;
export EDITOR=vi&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Simple arithmetic===&lt;br /&gt;
pipe the calculation into the shell calculator&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
space_in_kb=$(echo $1 / 1024 | bc)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Calculate the remainder (modulo) of a division calculation&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
if [[ $(echo &amp;quot;${NUMBER} % 2&amp;quot; | bc) -eq 0 ]]; then&lt;br /&gt;
    echo &amp;quot;${NUMBER} is even&amp;quot;&lt;br /&gt;
else&lt;br /&gt;
    echo &amp;quot;${NUMBER} is odd&amp;quot;&lt;br /&gt;
fi&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or do it in awk if scientific notation maybe involved&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
function calc { awk &amp;quot;BEGIN{print $*}&amp;quot;; }&lt;br /&gt;
&lt;br /&gt;
if [[ $(calc &amp;quot;${SPACE_USED} + ${SPACE_AVAILABLE} - ${DATABASE_SIZE&amp;quot;) -le 0 ]]; then&lt;br /&gt;
    echo &amp;quot;NOK&amp;quot;&lt;br /&gt;
fi&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Script encryption and passphrase protection===&lt;br /&gt;
Encrypt a shell script with the ability to execute the encrypted version&lt;br /&gt;
* from [http://www.commandlinefu.com/commands/browse commandlinefu.com]&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
scrypt(){ [ -n &amp;quot;$1&amp;quot; ]&amp;amp;&amp;amp;{ echo &amp;#039;. &amp;lt;(echo &amp;quot;$(tail -n+2 $0|base64 -d|mcrypt -dq)&amp;quot;); exit;&amp;#039;&amp;gt;$1.scrypt;cat $1|mcrypt|base64 &amp;gt;&amp;gt;$1.scrypt;chmod +x $1.scrypt;};}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Virtual host configuration in Apache http.conf===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;VirtualHost *:80&amp;gt;&lt;br /&gt;
        ServerName dbamon&lt;br /&gt;
        DocumentRoot &amp;quot;/Volumes/data/Sites/dbamon_push&amp;quot;&lt;br /&gt;
        &amp;lt;Directory &amp;quot;/Volumes/data/Sites/dbamon_push&amp;quot;&amp;gt;&lt;br /&gt;
                Options Includes FollowSymLinks&lt;br /&gt;
                AllowOverride All&lt;br /&gt;
                Order allow,deny&lt;br /&gt;
                Allow from all&lt;br /&gt;
        &amp;lt;/Directory&amp;gt;&lt;br /&gt;
&amp;lt;/VirtualHost&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
and in /etc/hosts, add...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
127.0.0.1  dbamon&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Mount a website (or any other remote resource) locally using WebDav===&lt;br /&gt;
Redhat/CentOS&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
yum install fuse-davfs2&lt;br /&gt;
or&lt;br /&gt;
yum install wdfs.x86_64&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Debian&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
apt-get install davfs2&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
then...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo mkdir /mnt/webdav  # or whatever you&amp;#039;d like to call the directory&lt;br /&gt;
sudo mount.davfs [-o option[,option]...] device mount_point&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
In man&amp;#039;s terms, that last line would translate to:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
id  #suppose this returns uid=501 and gid=502&lt;br /&gt;
sudo mount.davfs -o 501,502 https://your/web/site /mnt/webdav&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Mac OSX&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
osascript -e &amp;#039; mount volume &amp;quot;http://username:password@webdav.address:portnum&amp;quot; &amp;#039;&lt;br /&gt;
or&lt;br /&gt;
osascript -e &amp;#039; mount volume &amp;quot;http://username@webdav.address:portnum&amp;quot; &amp;#039;&lt;br /&gt;
or&lt;br /&gt;
osascript -e &amp;#039; try mount volume &amp;quot;http://webdav.address:portnum&amp;quot; &amp;#039;&lt;br /&gt;
or&lt;br /&gt;
mount -t webdav http://webdav.address:portnum /mnt/webdav  # this one won&amp;#039;t show up in the Finder Sidebar.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Add current hostname to list of hosts on an xcat server===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
CMD=&amp;quot;nodels&amp;quot;&lt;br /&gt;
HOST=`hostname`&lt;br /&gt;
(echo &amp;quot;$HOST&amp;quot;; $CMD) | while read server&lt;br /&gt;
do&lt;br /&gt;
    echo &amp;quot;server:$server&amp;quot;&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===What is todays &amp;#039;Day Of the Year&amp;#039; number?===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
DOY=`perl -e &amp;#039;print sub{$_[7]}-&amp;gt;(localtime)+1;&amp;#039;`&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Convert Julian day numbers to dates===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
for day in 8 33 36 61 64 91 96 121 126 152 155 182 187 215 218 244 247 274 279 306 309 335 338 365; do date -d &amp;quot;`date +%Y`-01-01 +$(( ${day} - 1 ))days&amp;quot; +%d-%m-%Y; done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Send crontab job output to a date formatted log file===&lt;br /&gt;
This will run a job every 5 minutes and send the output to a file ending with a time in hours and minutes.&amp;lt;br /&amp;gt;&lt;br /&gt;
The thing to note is the escaped percent signs. This is because a % sign is interpreted by cron to mean a newline character. Everything after the first % is treated as input to the program.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
*/5 *  * * * /var/www/cgi-bin/dbamon_collector.ksh       &amp;gt;/tmp/dbamon_collector.log.$(date &amp;quot;+\%H\%M&amp;quot;) 2&amp;gt;&amp;amp;1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Edit crontab file without crontab -e===&lt;br /&gt;
It can happen that you need to add or modify a line in the crontab of many users or across many servers at once.&amp;lt;br /&amp;gt;&lt;br /&gt;
In principle, there&amp;#039;s nothing wrong with modifying the crontab file directly. You just lose the advantages of file locking (and syntax checking) that crontab -e offers.&amp;lt;br /&amp;gt;&lt;br /&gt;
Here we take a backup of the current crontab, print it out, echo an extra command and ask cron to use these as input (thus overwriting the existing crontab file). Just don&amp;#039;t run this close to midnight :-)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
crontab -l &amp;gt; /tmp/crontab.`date &amp;#039;+%Y%m%d&amp;#039;`&lt;br /&gt;
(&lt;br /&gt;
cat /tmp/crontab.`date +&amp;#039;%Y%m%d&amp;#039;`&lt;br /&gt;
echo &amp;quot;02 10 * * * /home/ibmtools/scripts/oracle/export_parfile.ksh -s SID -f JDBEOP1.parfile&amp;quot;&lt;br /&gt;
) | crontab -&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
crontab -l &amp;gt; /tmp/crontab.backup&lt;br /&gt;
crontab -l &amp;gt; /tmp/crontab.$$&lt;br /&gt;
perl -p -i -e &amp;#039;s!backup_send_tsm_dump!backup_export2tsm!g&amp;#039; /tmp/crontab.$$&lt;br /&gt;
crontab /tmp/crontab.$$&lt;br /&gt;
rm /tmp/crontab.$$&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
crontab -l &amp;gt;$HOME/crontab.$(date &amp;#039;+%Y%m%d&amp;#039;)&lt;br /&gt;
crontab -l | perl -p -e &amp;#039;s|/nas/software/oracle/scripts|/oracle/scripts|&amp;#039; | crontab&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Use shell to convert a number in scientific notation to normal===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
var2convert=&amp;#039;1.2345678e3&amp;#039;&lt;br /&gt;
printf -v var2convert &amp;quot;%.f&amp;quot; $var2convert&lt;br /&gt;
echo $var2convert  # magic!&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Check for jobs running longer that 24 hours===&lt;br /&gt;
Run from the management server across all Unix servers. Checks the 5th column in a ps listing. If it doesn&amp;#039;t find a : (time separator), the process is running longer than 24 hours.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# ---------------------------------------&lt;br /&gt;
# report on long running oraibm processes&lt;br /&gt;
# ---------------------------------------&lt;br /&gt;
01 17,14 * * * rm -f /tmp/lrp.txt;/home/ibmtools/scripts/oracle/dosh -vc \&amp;quot;ps -ef|egrep &amp;#039;oraibm|scripts/oracle&amp;#039;&amp;gt;/tmp/lrp.txt;perl -nae &amp;#039;print if \$F[4] !~/:/&amp;#039; /tmp/lrp.txt\&amp;quot; &amp;gt;&amp;gt;/tmp/lrp.txt;[[ $(egrep -c &amp;#039;oraibm|scripts/or&lt;br /&gt;
acle&amp;#039; /tmp/lrp.txt) -ne 0 ]] &amp;amp;&amp;amp; cat /tmp/lrp.txt|mailx -s &amp;#039;*** long running processes - please check ***&amp;#039; bey9at77@mail.com&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Global find and replace with perl (restricted to list of files provided by Unix find command)===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
find . -type f -exec perl -i -pe &amp;#039;s/something/else/g&amp;#039; {} \;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===perl function to make filenames lower case===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
function lower { &lt;br /&gt;
   perl -e &amp;#039;for (@ARGV) { rename $_, lc($_) unless -e lc($_); }&amp;#039; * &lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===From the management server, search the TNS listener port for each database on a server and make an inline substitution in the ITM config files!===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
for i in `/home/ibmtools/scripts/oracle/dosh -c &amp;quot;ls -al /opt/IBM/ITM/config/*rz*cfg|grep -v lrwx&amp;quot;|awk &amp;#039;{print $NF}&amp;#039;`; do&lt;br /&gt;
    server=`echo $i|cut -d_ -f1 | awk -F&amp;#039;/&amp;#039; &amp;#039;{print $NF}&amp;#039;`&lt;br /&gt;
    db=`echo $i|cut -d&amp;#039;.&amp;#039; -f1 | awk -F&amp;#039;_&amp;#039; &amp;#039;{print $NF}&amp;#039;`&lt;br /&gt;
    OH=`ssh $server grep &amp;quot;^$db&amp;quot; /etc/oratab|cut -d: -f2`&lt;br /&gt;
    LISTENERPORT=`ssh $server cat $OH/network/admin/listener.ora|perl -00 -ne &amp;#039;print $1 if /&amp;#039;$db&amp;#039;.*PORT.*=.*(\d{4})/s&amp;#039;`&lt;br /&gt;
    ssh $server perl -p -i.bak -e &amp;#039;s/1521/&amp;#039;$LISTENERPORT&amp;#039;/&amp;#039; $i&lt;br /&gt;
    ssh $server ls -al ${i}*&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Run a job from cron every Nth day of the month===&lt;br /&gt;
Example. Execute a job every third Saturday of the month.&amp;lt;br /&amp;gt;&lt;br /&gt;
Paste this into a file called calenday and put it in /usr/local/bin so it&amp;#039;s (probably) on the PATH&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/usr/bin/ksh&lt;br /&gt;
&lt;br /&gt;
# ix is the week number of the month (&amp;quot;2&amp;quot;nd Friday of the month, &amp;quot;3&amp;quot;rd Tuesday of the month)&lt;br /&gt;
# dy is the day number in Unix format (0 for Sunday, 1 for Monday, ... 6 for Saturday)&lt;br /&gt;
# eg. &amp;quot;calenday 3 6&amp;quot; returns the date of 3rd Saturday of the month.&lt;br /&gt;
&lt;br /&gt;
ix=$1&lt;br /&gt;
dy=$2&lt;br /&gt;
SCHAR=$((($dy*2)+$dy+1))&lt;br /&gt;
ECHAR=$(($SCHAR+1))&lt;br /&gt;
cal `date &amp;#039;+%m %Y&amp;#039;` | egrep &amp;quot;\&amp;lt;[0-9]{1,2}\&amp;gt;&amp;quot; | cut -c${SCHAR}-${ECHAR} | xargs | awk {&amp;#039;print $&amp;#039;$ix&amp;#039;}&amp;#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Now in crontab, you should be able to do something like this:&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
15 20 * * * [[ `calenday 3 6` -eq `/bin/date &amp;#039;+%d&amp;#039;` ]] &amp;amp;&amp;amp; su - oracle -c &amp;quot;run_my_backup.ksh&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will also work on some Unices..&amp;lt;br /&amp;gt;&lt;br /&gt;
We send backups to a special TSM node on the second Friday of each month. This report must run a day later - but that is not guaranteed to be the second Saturday or even the 3rd. So...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
30 12 8-14 * 5 sleep 86400 &amp;amp;&amp;amp; su - oracle -c &amp;quot;/usr/bin/perl -ne &amp;#039;print if /ORX_M_SOL/ .. /^STOP/&amp;#039; /home/oracle/incoming/dbamon_spool_tsm_*.SOL | grep Archive | grep -v Client | mailx -s &amp;#039;Monthly TSM backups&amp;#039; orareport@xxxxxx.com&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ps listing does not show start time after 24 hours===&lt;br /&gt;
But you can see elapsed time using your own ps command&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/usr/bin/ps -eo etime,user,pid,ppid,cpu,start,tty,time,args|tail -n +2|sort&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ps -ef cuts off args cmd column on Solaris===&lt;br /&gt;
====To see more than 80 characters of the last column on Solaris====&lt;br /&gt;
This shows all the individual arguments to the command&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
pargs &amp;lt;pid&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This shows the ps listing in &amp;#039;compatibility&amp;#039; mode (there are more compatibility commands in /usr/xpg4/bin)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/usr/ucb/ps auww&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====To see more than 80 characters of the last column on AIX====&lt;br /&gt;
This shows the full argument listing of a process (NOTE: no minus sign!)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ps eww &amp;lt;pid&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Remove blank / empty lines from vi ===&lt;br /&gt;
Maybe you cut and pasted a file from Windows and it&amp;#039;s full of blank lines and Control-M&amp;#039;s now&amp;lt;br /&amp;gt;&lt;br /&gt;
There are several methods but I think this is the easiest to remember&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
:g/^$/d&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Right pad a variable===&lt;br /&gt;
a function like rpad in SQL but for Shell&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
function rpad {&lt;br /&gt;
text=$1&lt;br /&gt;
padwidth=$2&lt;br /&gt;
padchar=$3&lt;br /&gt;
echo &amp;quot;$text&amp;quot; | sed -e :a -e &amp;#039;s/^.\{1,&amp;#039;$padwidth&amp;#039;\}$/&amp;amp;\&amp;#039;$padchar&amp;#039;/;ta&amp;#039;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Connect to a Windows server from Linux using rdesktop===&lt;br /&gt;
My remmina stopped working so rolled my own. Very simple really. Put this is a shell.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
tsocks rdesktop -z -P -x m -a 16 -d MAIND -u sbarkley -p ****** -r disk:SOL=$HOME/Documents/SOL -g 95% 150.251.112.38 &amp;amp;&lt;br /&gt;
&lt;br /&gt;
where...&lt;br /&gt;
-z    - enables compression&lt;br /&gt;
-P    - enables bitmap caching (saves network traffic)&lt;br /&gt;
-x m  - disables eye-candy features&lt;br /&gt;
-a 16 - reduce colour pallete to 16 colours&lt;br /&gt;
-d    - domain to connect to&lt;br /&gt;
-u    - username&lt;br /&gt;
-p    - password&lt;br /&gt;
-r    - setup a shared folder&lt;br /&gt;
-g    - geometry (use W x H or percentage)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Slight problems with rdesktop not working 100% of the time. Now using xfreerdp. Seems better...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
xfreerdp -g 90% --ignore-certificate --gdi sw -K -d wdcrhbp05 -u oraibm -p &amp;quot;`cat $HOME/scripts/.oraibm.password`&amp;quot; -T &amp;quot;wdcrhbp05_oraibm&amp;quot; --plugin cliprdr --plugin rdpdr --data disk:SOL:/home/bey9at77/Documents/SOL -- --plugin rdpsnd --data alsa -- 150.251.112.25 &amp;amp;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Reset your password bypassing password rules===&lt;br /&gt;
must be done as root&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
echo &amp;quot;user:new_password&amp;quot; | chpasswd&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Sum the sizes of all files of an ls listing===&lt;br /&gt;
It&amp;#039;ll check to see if the sum of filesizes corresponds with the df -g (or h) listing (can get messed up due to open but deleted files)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cd /oracle/export&lt;br /&gt;
df -g .&lt;br /&gt;
find . -name &amp;quot;*dmp*&amp;quot; -ls |  awk &amp;#039;{ SUM += $7} END { print SUM/1024/1024/1024 }&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Mount an iso image under Linux===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
mkdir -p /mnt/cdrom&lt;br /&gt;
mount -o loop /dev/cdrom /mnt/cdrom&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===How many processors on the machine?===&lt;br /&gt;
* AIX&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
lsdev -C|grep Process|wc -l&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Solaris&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
psrinfo -v|grep &amp;quot;Status of processor&amp;quot;|wc -l&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Linux&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cat /proc/cpuinfo|grep processor|wc -l&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Quick, simple, understandable example of how to use RRDTool===&lt;br /&gt;
* [[RRDTool]]&lt;br /&gt;
&lt;br /&gt;
===Use expect to respond automatically to interactive programs===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/usr/bin/expect -f&lt;br /&gt;
spawn /usr/tivoli/tsm/client/oracle/bin64/tdpoconf passw -tdpo_optfile=/oracle/[lindex $argv 0]/admin/tdpo.opt&lt;br /&gt;
expect &amp;quot;assword:&amp;quot; {send &amp;quot;password\r&amp;quot;}&lt;br /&gt;
expect &amp;quot;assword:&amp;quot; {send &amp;quot;password\r&amp;quot;}&lt;br /&gt;
expect &amp;quot;assword:&amp;quot; {send &amp;quot;password\r&amp;quot;}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Use expect to allow file copy with scp (if ssh keys are not an option)===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/usr/bin/expect -f&lt;br /&gt;
spawn scp /home/oracle/.profile oracle@hn512:/tmp/prfl&lt;br /&gt;
set pass &amp;quot;thepassword&amp;quot;&lt;br /&gt;
expect {&lt;br /&gt;
        password: {send &amp;quot;$pass\r&amp;quot; ; exp_continue}&lt;br /&gt;
        eof exit&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Within a shell script set up simultaneous output to both terminal and a file using a FIFO (named pipes)===&lt;br /&gt;
or &amp;quot;How to send shell output to screen/stdout as well as to a logfile using tee and redirection with exec&amp;quot;&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
examples [http://www.unix.com/shell-programming-and-scripting/85584-redirect-within-ksh.html here on unix.com]&lt;br /&gt;
* general info on redirections [http://www.catonmat.net/blog/bash-one-liners-explained-part-three/ here at catonmat.net]&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/ksh&lt;br /&gt;
&lt;br /&gt;
REDIR=test.redir&lt;br /&gt;
FIFO=test.pipe&lt;br /&gt;
[[ -e $FIFO ]] || mkfifo $FIFO&lt;br /&gt;
&lt;br /&gt;
# make a new channel(3) and copy channel 1&amp;#039;s destination as its own (does NOT POINT TO channel 1&amp;#039;s destination)&lt;br /&gt;
# this allows the normal output to continue to STDOUT but also get printed to whatever file is attached to channel 3&lt;br /&gt;
exec 3&amp;gt;&amp;amp;1&lt;br /&gt;
&lt;br /&gt;
# anything coming in on the pipe, send it to $REDIR and to channel 3&lt;br /&gt;
tee $REDIR &amp;lt;$FIFO &amp;gt;&amp;amp;3 &amp;amp;&lt;br /&gt;
&lt;br /&gt;
# redirect STDOUT to the pipe&lt;br /&gt;
exec &amp;gt; $FIFO&lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;going to default output&amp;quot;&lt;br /&gt;
echo &amp;quot;forcing to channel 1&amp;quot; &amp;gt;&amp;amp;1&lt;br /&gt;
echo &amp;quot;forcing to channel 2&amp;quot; &amp;gt;&amp;amp;2&lt;br /&gt;
echo &amp;quot;forcing to channel 3&amp;quot; &amp;gt;&amp;amp;3&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====More elaborate example====&lt;br /&gt;
found [http://stackoverflow.com/questions/2288939/create-a-pipe-that-writes-to-multiple-files-tee here on stackoverflow]&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/sh&lt;br /&gt;
&lt;br /&gt;
# Author: Harvey Chapman &amp;lt;hchapman _AT_ 3gfp.com&amp;gt;&lt;br /&gt;
# Description: POSIX shell functions that can be used with tee to simultaneously put&lt;br /&gt;
#              stderr and stdout to both a file and stdout&lt;br /&gt;
#&lt;br /&gt;
# Based on:&lt;br /&gt;
#    Re: How to redirect stderr and stdout to a file plus display at the same time&lt;br /&gt;
#    http://www.travishartwell.net/blog/2006/08/19_2220&lt;br /&gt;
&lt;br /&gt;
#&lt;br /&gt;
# Original example function from Travis Hartwell&amp;#039;s blog.&lt;br /&gt;
# Note: I&amp;#039;ve made minor changes to it.&lt;br /&gt;
example()&lt;br /&gt;
{&lt;br /&gt;
  OUTPUT_LOG=output.log&lt;br /&gt;
  OUTPUT_PIPE=output.pipe&lt;br /&gt;
&lt;br /&gt;
  # This should really be -p to test that it&amp;#039;s a pipe.&lt;br /&gt;
  if [ ! -e $OUTPUT_PIPE ]; then&lt;br /&gt;
      mkfifo $OUTPUT_PIPE&lt;br /&gt;
  fi&lt;br /&gt;
&lt;br /&gt;
  # This should really be -f to test that it&amp;#039;s a regular file.&lt;br /&gt;
  if [ -e $OUTPUT_LOG ]; then&lt;br /&gt;
      rm $OUTPUT_LOG&lt;br /&gt;
  fi&lt;br /&gt;
&lt;br /&gt;
  exec 3&amp;gt;&amp;amp;1 4&amp;gt;&amp;amp;2&lt;br /&gt;
  tee $OUTPUT_LOG &amp;lt; $OUTPUT_PIPE &amp;gt;&amp;amp;3 &amp;amp;&lt;br /&gt;
  tpid=$!&lt;br /&gt;
  exec &amp;gt; $OUTPUT_PIPE 2&amp;gt;&amp;amp;1&lt;br /&gt;
&lt;br /&gt;
  echo &amp;quot;This is on standard out&amp;quot;&lt;br /&gt;
  echo &amp;quot;This is on standard err&amp;quot; &amp;gt;&amp;amp;2&lt;br /&gt;
&lt;br /&gt;
  exec 1&amp;gt;&amp;amp;3 3&amp;gt;&amp;amp;- 2&amp;gt;&amp;amp;4 4&amp;gt;&amp;amp;-&lt;br /&gt;
  wait $tpid&lt;br /&gt;
&lt;br /&gt;
  rm $OUTPUT_PIPE&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
# A slightly reduced version of example()&lt;br /&gt;
example2()&lt;br /&gt;
{&lt;br /&gt;
  OUTPUT_LOG=output.log&lt;br /&gt;
  OUTPUT_PIPE=output.pipe&lt;br /&gt;
&lt;br /&gt;
  rm -f $OUTPUT_PIPE&lt;br /&gt;
  mkfifo $OUTPUT_PIPE&lt;br /&gt;
  rm -f $OUTPUT_LOG&lt;br /&gt;
&lt;br /&gt;
  tee $OUTPUT_LOG &amp;lt; $OUTPUT_PIPE &amp;amp;&lt;br /&gt;
  tpid=$!&lt;br /&gt;
&lt;br /&gt;
  exec 3&amp;gt;&amp;amp;1 4&amp;gt;&amp;amp;2 &amp;gt;$OUTPUT_PIPE 2&amp;gt;&amp;amp;1&lt;br /&gt;
&lt;br /&gt;
  echo &amp;quot;This is on standard out&amp;quot;&lt;br /&gt;
  echo &amp;quot;This is on standard err&amp;quot; &amp;gt;&amp;amp;2&lt;br /&gt;
&lt;br /&gt;
  exec 1&amp;gt;&amp;amp;3 3&amp;gt;&amp;amp;- 2&amp;gt;&amp;amp;4 4&amp;gt;&amp;amp;-&lt;br /&gt;
  wait $tpid&lt;br /&gt;
  rm -f $OUTPUT_PIPE&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
#&lt;br /&gt;
# Logging methods based on above. See the example below for how to use them.&lt;br /&gt;
#&lt;br /&gt;
&lt;br /&gt;
# Usage: start_logging [delete_existing_logfile]&lt;br /&gt;
start_logging()&lt;br /&gt;
{&lt;br /&gt;
  # Check to see if OUTPUT_LOG and OUTPUT_PIPE need to be defined.&lt;br /&gt;
  if [ -z &amp;quot;$OUTPUT_LOG&amp;quot; ]; then&lt;br /&gt;
    OUTPUT_LOG=output.log&lt;br /&gt;
  fi&lt;br /&gt;
  if [ -z &amp;quot;$OUTPUT_PIPE&amp;quot; ]; then&lt;br /&gt;
    OUTPUT_PIPE=output.pipe&lt;br /&gt;
  fi&lt;br /&gt;
  # Make sure that we&amp;#039;re not already logging.&lt;br /&gt;
  if [ -n &amp;quot;$OUTPUT_PID&amp;quot; ]; then&lt;br /&gt;
    echo &amp;quot;Logging already started!&amp;quot;&lt;br /&gt;
    return 1&lt;br /&gt;
  fi&lt;br /&gt;
&lt;br /&gt;
  # Always remove the log and pipe first.&lt;br /&gt;
  rm -f $OUTPUT_PIPE&lt;br /&gt;
  # Delete the logfile first if told to.&lt;br /&gt;
  if [ &amp;quot;$1&amp;quot; = delete_existing_logfile ]; then&lt;br /&gt;
    rm -f $OUTPUT_LOG&lt;br /&gt;
  fi&lt;br /&gt;
&lt;br /&gt;
  mkfifo $OUTPUT_PIPE&lt;br /&gt;
  tee -a $OUTPUT_LOG &amp;lt; $OUTPUT_PIPE &amp;amp;&lt;br /&gt;
  OUTPUT_PID=$!&lt;br /&gt;
&lt;br /&gt;
  exec 3&amp;gt;&amp;amp;1 4&amp;gt;&amp;amp;2 &amp;gt;$OUTPUT_PIPE 2&amp;gt;&amp;amp;1&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
stop_logging()&lt;br /&gt;
{&lt;br /&gt;
  # Make sure that we&amp;#039;re currently logging.&lt;br /&gt;
  if [ -z &amp;quot;$OUTPUT_PID&amp;quot; ]; then&lt;br /&gt;
    echo &amp;quot;Logging not yet started!&amp;quot;&lt;br /&gt;
    return 1&lt;br /&gt;
  fi&lt;br /&gt;
  exec 1&amp;gt;&amp;amp;3 3&amp;gt;&amp;amp;- 2&amp;gt;&amp;amp;4 4&amp;gt;&amp;amp;-&lt;br /&gt;
  wait $OUTPUT_PID&lt;br /&gt;
  rm -f $OUTPUT_PIPE&lt;br /&gt;
  unset OUTPUT_PID&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
example3()&lt;br /&gt;
{&lt;br /&gt;
  start_logging&lt;br /&gt;
  #start_logging delete_existing_logfile&lt;br /&gt;
  echo &amp;quot;This is on standard out&amp;quot;&lt;br /&gt;
  echo &amp;quot;This is on standard err&amp;quot; &amp;gt;&amp;amp;2&lt;br /&gt;
  stop_logging&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===RedHat root filesystem has gone read-only===&lt;br /&gt;
* [http://www.unixarena.com/2013/09/redhat-linux-how-to-fix-read-only-root.html How to fix read only root file system]&lt;br /&gt;
&lt;br /&gt;
===Kill all processes for a user===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
for prc in `ps -ef | grep -E &amp;quot;^ +[o]racle&amp;quot; | awk &amp;#039;{print $2}&amp;#039;`; do&lt;br /&gt;
    kill $prc&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===isRGHere===&lt;br /&gt;
Checks if resource group is on this leg of an HACMP cluster. Returns 0 if true else 1.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/usr/bin/ksh&lt;br /&gt;
&lt;br /&gt;
SCRIPT=`basename $0`&lt;br /&gt;
&lt;br /&gt;
function rctest&lt;br /&gt;
{&lt;br /&gt;
exitcode=$1&lt;br /&gt;
msg=$2&lt;br /&gt;
if [ $exitcode -ne 0 ]; then&lt;br /&gt;
        echo &amp;quot;********************************************************************************&amp;quot;&lt;br /&gt;
        echo &amp;quot;\nScript $SCRIPT finished with errors.&amp;quot;&lt;br /&gt;
        echo &amp;quot;$msg.&amp;quot;&lt;br /&gt;
        echo &amp;quot;Returncode : $exitcode.&amp;quot;&lt;br /&gt;
        echo &amp;quot;\n********************************************************************************&amp;quot;&lt;br /&gt;
&lt;br /&gt;
        fi&lt;br /&gt;
exit $exitcode&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
RGINFO=/usr/es/sbin/cluster/utilities/clRGinfo&lt;br /&gt;
[[ ! -f $RGINFO ]] &amp;amp;&amp;amp;  rctest 1 &amp;quot;clRGinfo not found&amp;quot;&lt;br /&gt;
&lt;br /&gt;
if [ $# -eq 1 ]&lt;br /&gt;
then&lt;br /&gt;
        RG=`echo $1 | cut -c 1-14`&lt;br /&gt;
else&lt;br /&gt;
        rctest 10  &amp;quot;Usage: `basename $0` &amp;lt;RG name&amp;gt;&amp;quot;&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
$RGINFO |grep -qwp $RG ||  rctest 9 &amp;quot;$RG is not defined&amp;quot;&lt;br /&gt;
&lt;br /&gt;
THISNODE=`/usr/es/sbin/cluster/utilities/get_local_nodename | cut -c 1-14`&lt;br /&gt;
$RGINFO |grep -wp $RG |grep -w $THISNODE |grep -wq ONLINE&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===AIX: add a user to a group===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
chgrpmem -m + oracle ibmtls&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Find swear words in scripts by comparing it to a list found on the internet===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
wget &amp;quot;http://www.bannedwordlist.com/lists/swearWords.csv&amp;quot; -O /tmp/s ; for word in $(cat /tmp/s | sed -e &amp;#039;s/ /_/g&amp;#039; -e &amp;#039;s/,/ /g&amp;#039;) ; do grep -wR $word *; done | less&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===grep -p (for paragraph) works on AIX but not on Linux or Solaris===&lt;br /&gt;
Use awk instead&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
awk &amp;#039;BEGIN {FS=&amp;quot;\n&amp;quot; RS=&amp;quot;\n\n&amp;quot;} /search pattern/ { do something }&amp;#039; &amp;lt;file&amp;gt;&lt;br /&gt;
/usr/xpg4/bin/awk &amp;#039;BEGIN {RS=&amp;quot;\n\n&amp;quot;;FS=&amp;quot;\n&amp;quot;} /AGRHDWQ1/ {print $2}&amp;#039; dsm.sys | awk &amp;#039;{print $NF}&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
this prints the last word of the second &amp;#039;&amp;#039;line&amp;#039;&amp;#039; in the paragraph in dsm.sys that contains the search term AGRHDWQ1.&amp;lt;br /&amp;gt;&lt;br /&gt;
Or slightly simpler...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
awk -v RS=&amp;#039;&amp;#039; &amp;#039;/NHAPPLP1/&amp;#039; /etc/tsm/dsm.sys     # (use /usr/xpg4/bin/awk on Solaris)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or, case insensitively:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
awk -v RS=&amp;#039;&amp;#039; &amp;#039;tolower($0) ~/so_u_clubqa_orx_d_cab/&amp;#039; /etc/tsm/dsm.sys&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Using -v means you don&amp;#039;t have to use a BEGIN section.&lt;br /&gt;
&lt;br /&gt;
===debug/redirect log of a shell===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/usr/bin/ksh&lt;br /&gt;
exec 2&amp;gt;/tmp/mytest&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Different ways of Iteration in korn shell with a while loop===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
IFS=&amp;quot;|&amp;quot;&lt;br /&gt;
exec 0&amp;lt;$statfile&lt;br /&gt;
while read host db started stopped&lt;br /&gt;
do&lt;br /&gt;
    rrdfile=&amp;quot;export_duration_${host}_${db}.rrd&amp;quot;&lt;br /&gt;
    $RRDTOOL update ${RRDDIR}/${rrdfile} $started:$started $stopped&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
while read host db started stopped&lt;br /&gt;
do&lt;br /&gt;
    rrdfile=&amp;quot;export_duration_${host}_${db}.rrd&amp;quot;&lt;br /&gt;
    $RRDTOOL update ${RRDDIR}/${rrdfile} $started:$started $stopped&lt;br /&gt;
done &amp;lt;statfile&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    cat $statfile | sort -nk4 | while IFS=\| read host db type started stopped&lt;br /&gt;
    do&lt;br /&gt;
        [[ &amp;quot;$stopped&amp;quot; == &amp;quot;&amp;quot; ]] &amp;amp;&amp;amp; continue&lt;br /&gt;
        rrdfile=&amp;quot;export_duration_${host}_${db}.rrd&amp;quot;&lt;br /&gt;
        $RRDTOOL update ${RRDDIR}/${rrdfile} ${started}:${started}:${stopped}&lt;br /&gt;
        [[ $? -ne 0 ]] &amp;amp;&amp;amp; echo &amp;quot;nok: $?&amp;quot;&lt;br /&gt;
    done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Filesystem 100% full, what&amp;#039;s taking up all the space?===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
find /oracle/endur -xdev -ls|sort -nr +6|head&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/dev/esb01fs010001      1.00      0.00  100%     1838    69% /oracle&lt;br /&gt;
beuxdsysesb01:root[/root]# cd /oracle&lt;br /&gt;
beuxdsysesb01:root[/oracle]# du -gsx * | sort -n&lt;br /&gt;
0.00    checkpoints&lt;br /&gt;
0.00    flash_recovery_area&lt;br /&gt;
0.00    lost+found&lt;br /&gt;
0.00    oraInst.loc&lt;br /&gt;
0.00    oraInventory&lt;br /&gt;
0.09    admin&lt;br /&gt;
0.99    diag&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
cd  diag and repeat until culprits are found&lt;br /&gt;
&lt;br /&gt;
===Show paged memory hogs on AIX===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
svmon -Pt20 | perl -e &amp;#039;while(&amp;lt;&amp;gt;){print if($.==2||$&amp;amp;&amp;amp;&amp;amp;!$s++);$.=0 if(/^-+$/)}&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Capitalise the first letter of a word in Korn Shell===&lt;br /&gt;
Not as easy as it sounds if it needs to work in non-ksh93 shells&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
function capit { &lt;br /&gt;
    typeset -u first&lt;br /&gt;
    first=${1%&amp;quot;${1#?}&amp;quot;}&lt;br /&gt;
    printf &amp;quot;%s\n&amp;quot; &amp;quot;${first}${1#?}&amp;quot;&lt;br /&gt;
    return 0&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or maybe more neatly done in Perl...&amp;lt;br /&amp;gt;&lt;br /&gt;
This will capitalise each word in a sentence passed into it&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
function capit { &lt;br /&gt;
    echo &amp;quot;$1&amp;quot; |  perl -pe &amp;quot;s/([\w&amp;#039;]+)/\u\L\1/g&amp;quot;&lt;br /&gt;
    return 0&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Remove / rename a directory / file containing weird control characters===&lt;br /&gt;
Use ls with -i to see inode listing&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ls -bali&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Use find with -inum to get the filename and -exec to remove it&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
find . -inum &amp;lt;inode from ls listing&amp;gt; -exec rm -f {} \;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Run a local script on a remote host===&lt;br /&gt;
Doing it this way means we do not need to scp the shell over to the host before executing it!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ssh user@host &amp;#039;sh&amp;#039; &amp;lt; your_script.sh&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
First of all, this command is a redirection: your shell will open the file your_script.sh and feed it as input to the ssh command. ssh, in turn, will tunnel its stdin to the remote command, namely, sh instance. And sh without arguments reads its script from stdin. So we got sh instance, which is launched on remote host, but reads commands from your local file.&lt;br /&gt;
&lt;br /&gt;
===Get a list of running instances - but only those started by the current user===&lt;br /&gt;
This is the way I wanted to do it but there&amp;#039;s an issue. Where does that spare } character come from? Anyone?&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ps -ef | grep [p]mon | awk -v dbowner=$(id -un) &amp;#039;{ if ($1==dbowner) { gsub(/ora_pmon_/,&amp;quot;&amp;quot;,$NF); print $NF; } }&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
ps listing&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ ps -ef | grep [p]mon&lt;br /&gt;
  oracle 13304024        1   0   Jun 07      -  2:39 ora_pmon_reportk&lt;br /&gt;
  oracle 26018178        1   0   Jun 07      -  3:01 ora_pmon_dwh_perf&lt;br /&gt;
  oracle 29229432        1   0   Jun 07      -  2:30 ora_pmon_adso&lt;br /&gt;
 oraebso 18022994        1   0   Jun 07      -  2:38 ora_pmon_EBSO&lt;br /&gt;
  oracle 30278192        1   0   Jun 07      -  2:48 ora_pmon_owb112k&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Results of above command&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
reportk&lt;br /&gt;
dwh_perf&lt;br /&gt;
adso&lt;br /&gt;
}&lt;br /&gt;
owb112k&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Workaround 1. Send the ps listing to a file and work on it without pipes. Works but it&amp;#039;s a bit long-winded especially as we have to clean up afterwards.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ps -ef | grep [p]mon&amp;gt;/tmp/results.$$ 2&amp;gt;/dev/null; awk -v dbowner=$(id -un) &amp;#039;{ if ($1==dbowner) { gsub(/ora_pmon_/,&amp;quot;&amp;quot;,$NF); print $NF; } }&amp;#039; /tmp/results.$$; rm -f /tmp/results.$$&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Workaround 2. Don&amp;#039;t like the grep -v but until I find out where that } is coming from..&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ps -ef | grep [p]mon | awk -v dbowner=$(id -un) &amp;#039;{ if ($1==dbowner) { gsub(/ora_pmon_/,&amp;quot;&amp;quot;,$NF); print $NF; } }&amp;#039; | egrep -v &amp;#039;grep|}|ASM&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Return a list of Oracle databases running on a list of remote servers===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/ksh&lt;br /&gt;
&lt;br /&gt;
serverlist=`cat /home/tools/ini/system/oracle_servers | sort -n | tr &amp;quot;\n&amp;quot; &amp;quot; &amp;quot;`&lt;br /&gt;
&lt;br /&gt;
if [ -z &amp;quot;${serverlist}&amp;quot; ]&lt;br /&gt;
then&lt;br /&gt;
    echo &amp;quot;no servers found&amp;quot; &amp;amp;&amp;amp; exit 1&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
for server in ${serverlist}&lt;br /&gt;
do&lt;br /&gt;
    ssh ${server} &amp;quot;ps -ef | grep [o]ra_pmon_&amp;quot; &amp;gt;/tmp/${server}.dblist&lt;br /&gt;
done&lt;br /&gt;
&lt;br /&gt;
for server in ${serverlist}&lt;br /&gt;
do&lt;br /&gt;
    cat /tmp/${server}.dblist | awk -F_ -v SRV=${server} &amp;#039;BEGIN {print SRV &amp;quot;:&amp;quot;} {print $NF}&amp;#039; | tr &amp;quot;\n&amp;quot; &amp;quot; &amp;quot;&lt;br /&gt;
    echo&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Clever trick to check whether SQL output needs sending to someone===&lt;br /&gt;
Using an exit status from SQL*Plus back to the shell so we can decide what to do.  Nice one!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
tempfile=/tmp/audit_locked_accounts_$ORACLE_SID.txt&lt;br /&gt;
&lt;br /&gt;
# Start sqlplus and check for locked accounts&lt;br /&gt;
sqlplus -S &amp;quot;/ as sysdba&amp;quot; &amp;lt;&amp;lt; EOF &amp;gt; $tempfile&lt;br /&gt;
set pages 0&lt;br /&gt;
select &amp;#039;The following accounts were found to be unlocked and should not be&amp;#039;&lt;br /&gt;
from dual;&lt;br /&gt;
&lt;br /&gt;
def exit_status = 0&lt;br /&gt;
col xs new_value exit_status&lt;br /&gt;
&lt;br /&gt;
select username&lt;br /&gt;
,      account_status&lt;br /&gt;
,      1 as xs&lt;br /&gt;
from   dba_users&lt;br /&gt;
where  account_status != &amp;#039;LOCKED&amp;#039;&lt;br /&gt;
and    username in (&amp;#039;HR&amp;#039;, &amp;#039;SCOTT&amp;#039;, &amp;#039;OUTLN&amp;#039;, &amp;#039;MDSYS&amp;#039;, &amp;#039;CTXSYS&amp;#039;)&lt;br /&gt;
/&lt;br /&gt;
exit &amp;amp;exit_status&lt;br /&gt;
EOF&lt;br /&gt;
&lt;br /&gt;
# If the exit status of sqlplus was not 0 then we will send an email&lt;br /&gt;
if [ $? != 0 ]; then&lt;br /&gt;
    mail -s &amp;quot;Accounts Unlocked in $ORACLE_SID&amp;quot; oracle &amp;lt; $tempfile&lt;br /&gt;
fi&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Check RMAN logfiles for errors from cron every day===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
00 09 * * * /home/tools/scripts/oracle/dosh &amp;#039;find /home/tools/logs/rman -name &amp;quot;*online.log&amp;quot; -mtime -1 -exec sed -ne &amp;quot;/^RMAN-/,/^$/p&amp;quot; {} \\; -ls&amp;#039; | mailx&lt;br /&gt;
 -s &amp;#039;RMAN errors last night&amp;#039; stuart@domain.com&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/home/ibmtools/scripts/oracle/dosh &amp;#039;find /oracle/export -name &amp;quot;expdp*log&amp;quot; -mtime -1 -exec grep ORA- {} \; -ls&amp;#039; | mailx -s &amp;#039;Datapump errors for Baxter last night&amp;#039; stuart@domain.com&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===An alternative to getopts===&lt;br /&gt;
These methods have the advantage of allowing arguments of any length not just 1 character&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
countArgs=$#&lt;br /&gt;
while [[ $# -gt 0 ]]&lt;br /&gt;
do&lt;br /&gt;
    idx1=$($ECHO $1|$GREP &amp;quot;=&amp;quot;|wc -l)&lt;br /&gt;
    if [[ $idx1 -gt 0 ]]; then&lt;br /&gt;
        key=$($ECHO $1|$CUT -d &amp;#039;=&amp;#039; -f 1)&lt;br /&gt;
        value=$($ECHO $1|$CUT -d &amp;#039;=&amp;#039; -f 2)&lt;br /&gt;
    else&lt;br /&gt;
        key=$($ECHO $1|$CUT -d &amp;#039;=&amp;#039; -f 1)&lt;br /&gt;
        idx2=$($ECHO $1|$GREP &amp;quot;^-&amp;quot;|wc -l)&lt;br /&gt;
        if [[ $idx2 -eq 0 ]]; then&lt;br /&gt;
            $ECHO -e &amp;quot;\n ERROR: $1 is an unsupported argument passed to agentDeploy.sh.\n&amp;quot;  &lt;br /&gt;
            usage&lt;br /&gt;
            exit 1&lt;br /&gt;
        fi&lt;br /&gt;
    fi&lt;br /&gt;
&lt;br /&gt;
    case &amp;quot;$key&amp;quot; in&lt;br /&gt;
    -help)&lt;br /&gt;
        if [[ $upgradeFlag ]]; then&lt;br /&gt;
            upgradeUsage&lt;br /&gt;
        else&lt;br /&gt;
            freshUsage&lt;br /&gt;
        fi&lt;br /&gt;
        exit 0;;&lt;br /&gt;
    AGENT_BASE_DIR)&lt;br /&gt;
        agentBaseDir=$($ECHO $value|$SED &amp;#039;s/\/$//&amp;#039;)&lt;br /&gt;
        checkBaseFlag=TRUE;;&lt;br /&gt;
    OMS_HOST)&lt;br /&gt;
        omsHost=$value&lt;br /&gt;
        checkOMSHost=TRUE;;&lt;br /&gt;
    EM_UPLOAD_PORT)&lt;br /&gt;
        omsPort=$value&lt;br /&gt;
        checkOMSPort=TRUE;;&lt;br /&gt;
    AGENT_INSTANCE_HOME)&lt;br /&gt;
        instHome=$($ECHO $value | $SED &amp;#039;s/\/$//&amp;#039;);;&lt;br /&gt;
    AGENT_REGISTRATION_PASSWORD)&lt;br /&gt;
        pswd=$value;;&lt;br /&gt;
    s_encrSecurePwd)&lt;br /&gt;
        pswd=$value;;  &lt;br /&gt;
    RESPONSE_FILE)&lt;br /&gt;
        rspFlag=TRUE  &lt;br /&gt;
        rspLoc=$value;;&lt;br /&gt;
    OLD_AGENT_VERSION)&lt;br /&gt;
        oldAgentVersion=$value;;            &lt;br /&gt;
    OLDHOME)&lt;br /&gt;
        oldHome=$value;;    &lt;br /&gt;
    -debug)&lt;br /&gt;
        debugSwitch=TRUE;;&lt;br /&gt;
    -forceConfigure)&lt;br /&gt;
        forceFlag=TRUE;;&lt;br /&gt;
    -configOnly)&lt;br /&gt;
        configFlag=TRUE    &lt;br /&gt;
        validationFlag=TRUE;;&lt;br /&gt;
    -agentImageLocation)&lt;br /&gt;
        archiveLoc=$value&lt;br /&gt;
        checkArchiveFlag=TRUE;;&lt;br /&gt;
    -invPtrLoc) shift&lt;br /&gt;
        ptrLoc=$1;;&lt;br /&gt;
    -Upgrade)&lt;br /&gt;
        UpgradeFlag=TRUE&lt;br /&gt;
        validFlag=TRUE;;&lt;br /&gt;
    INVENTORY_LOCATION)&lt;br /&gt;
        validFlag=TRUE;;&lt;br /&gt;
    b_forceInstCheck)&lt;br /&gt;
        validFlag=TRUE&lt;br /&gt;
        forcefullFlag=TRUE;;&lt;br /&gt;
    -prereqOnly)&lt;br /&gt;
        validationFlag=TRUE&lt;br /&gt;
        prereqFlag=TRUE;;&lt;br /&gt;
    -executeRootsh)&lt;br /&gt;
        validFlag=TRUE;;&lt;br /&gt;
    *)  idx=$($ECHO $1|$GREP &amp;quot;^-&amp;quot;|wc -l)&lt;br /&gt;
        if [[ $idx -eq 0 ]]; then&lt;br /&gt;
            validFlag=TRUE&lt;br /&gt;
        else&lt;br /&gt;
            $ECHO -e &amp;quot;\n ERROR: Invalid argument $key passed.&amp;quot;&lt;br /&gt;
            usage&lt;br /&gt;
            exit 1          &lt;br /&gt;
        fi&lt;br /&gt;
    esac&lt;br /&gt;
    shift&lt;br /&gt;
done&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
another way - found in /etc/init.d/functions (daemon function) in Fedora&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    while [ &amp;quot;$1&amp;quot; != &amp;quot;${1##[-+]}&amp;quot; ]; do&lt;br /&gt;
        case $1 in&lt;br /&gt;
        &amp;#039;&amp;#039;)&lt;br /&gt;
            echo $&amp;quot;$0: Usage: daemon [+/-nicelevel] {program}&amp;quot; &amp;quot;[arg1]...&amp;quot;&lt;br /&gt;
            return 1&lt;br /&gt;
            ;;&lt;br /&gt;
        --check)&lt;br /&gt;
            base=$2&lt;br /&gt;
            gotbase=&amp;quot;yes&amp;quot;&lt;br /&gt;
            shift 2&lt;br /&gt;
            ;;&lt;br /&gt;
        --check=?*)&lt;br /&gt;
            base=${1#--check=}&lt;br /&gt;
            gotbase=&amp;quot;yes&amp;quot;&lt;br /&gt;
            shift&lt;br /&gt;
            ;;&lt;br /&gt;
        --user)&lt;br /&gt;
            user=$2&lt;br /&gt;
            shift 2&lt;br /&gt;
            ;;&lt;br /&gt;
        --user=?*)&lt;br /&gt;
            user=${1#--user=}&lt;br /&gt;
            shift&lt;br /&gt;
            ;;&lt;br /&gt;
        --pidfile)&lt;br /&gt;
            pid_file=$2&lt;br /&gt;
            shift 2&lt;br /&gt;
            ;;&lt;br /&gt;
        --pidfile=?*)&lt;br /&gt;
            pid_file=${1#--pidfile=}&lt;br /&gt;
            shift&lt;br /&gt;
            ;;&lt;br /&gt;
        --force)&lt;br /&gt;
            force=&amp;quot;force&amp;quot;&lt;br /&gt;
            shift&lt;br /&gt;
            ;;&lt;br /&gt;
        [-+][0-9]*)&lt;br /&gt;
            nice=&amp;quot;nice -n $1&amp;quot;&lt;br /&gt;
            shift&lt;br /&gt;
            ;;&lt;br /&gt;
        *)&lt;br /&gt;
            echo $&amp;quot;$0: Usage: daemon [+/-nicelevel] {program}&amp;quot; &amp;quot;[arg1]...&amp;quot;&lt;br /&gt;
            return 1&lt;br /&gt;
            ;;&lt;br /&gt;
      esac&lt;br /&gt;
    done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
another way - found in adstrtal.sh (middleware start script for EBS)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#&lt;br /&gt;
# Parse Arguments&lt;br /&gt;
#&lt;br /&gt;
&lt;br /&gt;
for nxtarg in $*&lt;br /&gt;
do&lt;br /&gt;
  arg=`echo $nxtarg | sed &amp;#039;s/^//&amp;#039;`&lt;br /&gt;
&lt;br /&gt;
  case $arg in&lt;br /&gt;
    -secureapps)    if test &amp;quot;$secureapps&amp;quot; = &amp;quot;&amp;quot; ; then&lt;br /&gt;
                       secureapps=$arg&lt;br /&gt;
                    else&lt;br /&gt;
                       echo &amp;quot;$0: Duplicate Argument passed : $arg&amp;quot;&lt;br /&gt;
                       usage&lt;br /&gt;
                    fi&lt;br /&gt;
                ;;&lt;br /&gt;
    -nodbchk)       if test &amp;quot;$nodbchk&amp;quot; = &amp;quot;&amp;quot; ; then&lt;br /&gt;
                       nodbchk=$arg&lt;br /&gt;
                    else&lt;br /&gt;
                       echo &amp;quot;$0: Duplicate Argument passed : $arg&amp;quot;&lt;br /&gt;
                       usage&lt;br /&gt;
                    fi&lt;br /&gt;
                ;;&lt;br /&gt;
    -nopromptmsg)   if test &amp;quot;$nopromptmsg&amp;quot; = &amp;quot;&amp;quot; ; then&lt;br /&gt;
                       nopromptmsg=$arg&lt;br /&gt;
                    else&lt;br /&gt;
                       echo &amp;quot;$0: Duplicate Argument passed : $arg&amp;quot;&lt;br /&gt;
                       usage&lt;br /&gt;
                    fi&lt;br /&gt;
                ;;&lt;br /&gt;
    *)              if test &amp;quot;$unpw&amp;quot; = &amp;quot;&amp;quot; ; then&lt;br /&gt;
                       unpw=$arg&lt;br /&gt;
                    else&lt;br /&gt;
                       echo &amp;quot;$0: Duplicate Argument passed : $arg&amp;quot;&lt;br /&gt;
                       usage&lt;br /&gt;
                    fi&lt;br /&gt;
  esac&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
and another in adautocfg.sh&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
for myarg in $*&lt;br /&gt;
do&lt;br /&gt;
&lt;br /&gt;
  arg=`echo $myarg | sed &amp;#039;s/^-//&amp;#039;`&lt;br /&gt;
  case $arg in&lt;br /&gt;
    appspass=*)&lt;br /&gt;
            appspass=`echo $arg | sed &amp;#039;s/appspass=//g&amp;#039;`&lt;br /&gt;
            shift&lt;br /&gt;
            ;;&lt;br /&gt;
    nocustom)&lt;br /&gt;
            myparams=&amp;quot;$myparams $arg&amp;quot;&lt;br /&gt;
            shift&lt;br /&gt;
            ;;&lt;br /&gt;
    noversionchecks)&lt;br /&gt;
            myparams=&amp;quot;$myparams $arg&amp;quot;&lt;br /&gt;
            shift&lt;br /&gt;
            ;;&lt;br /&gt;
    promptmsg=*)&lt;br /&gt;
            promptmsg=`echo $arg | sed &amp;#039;s/promptmsg=//g&amp;#039;`&lt;br /&gt;
            shift&lt;br /&gt;
            ;;&lt;br /&gt;
        *)  echo &amp;quot;$0: unrecognized action specified&amp;quot;&lt;br /&gt;
            exit 1&lt;br /&gt;
  esac&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Run a script on multiple servers===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/ksh&lt;br /&gt;
# ==============================================================================&lt;br /&gt;
# Name         : dosh   (Distributed Oracle SHell)&lt;br /&gt;
# Description  : Runs a command on all Oracle servers&lt;br /&gt;
#&lt;br /&gt;
# Parameters   : h - displays help&lt;br /&gt;
#                v - verbose (default, like all unix commands is silent)&lt;br /&gt;
#                c - command to be executed&lt;br /&gt;
#&lt;br /&gt;
# Example      : ./dosh -v -c &amp;#039;ls -al&amp;#039;&lt;br /&gt;
#&lt;br /&gt;
# Modification History&lt;br /&gt;
# ====================&lt;br /&gt;
# When      Who               What&lt;br /&gt;
# ========= ================= ==================================================&lt;br /&gt;
# 08-FEB-13 Stuart Barkley    Created&lt;br /&gt;
# ==============================================================================&lt;br /&gt;
&lt;br /&gt;
# --------------------------------------------------------------------------&lt;br /&gt;
# this list of servers is generated by the DBAMON tool so will be up to date&lt;br /&gt;
# --------------------------------------------------------------------------&lt;br /&gt;
serverfile=/home/ibmtools/etc/oracle/oracle_servers&lt;br /&gt;
[[ -z &amp;quot;${serverfile}&amp;quot; ]] &amp;amp;&amp;amp; echo &amp;quot;Server list ${serverfile} not found&amp;quot; &amp;amp;&amp;amp; exit 1&lt;br /&gt;
&lt;br /&gt;
serverlist=`cat ${serverfile} | sort -n | tr &amp;quot;\n&amp;quot; &amp;quot; &amp;quot;`&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
# -------------------------&lt;br /&gt;
# get the arguments, if any&lt;br /&gt;
# -------------------------&lt;br /&gt;
while getopts &amp;quot;hvc:&amp;quot; OPT&lt;br /&gt;
do&lt;br /&gt;
    case &amp;quot;$OPT&amp;quot; in&lt;br /&gt;
    h) echo &amp;quot;\nUsage: $0 [-v] [-h] -c &amp;#039;&amp;lt;command_to_be_executed_remotely&amp;gt;&amp;#039;\n&amp;quot;;&lt;br /&gt;
       exit;&lt;br /&gt;
       ;;&lt;br /&gt;
    v) VERBOSE=&amp;quot;Y&amp;quot;;&lt;br /&gt;
       ;;&lt;br /&gt;
    c) CMMND=$OPTARG;&lt;br /&gt;
       ;;&lt;br /&gt;
    *) echo &amp;quot;\nUsage: $0 [-v] [-h] -c &amp;#039;&amp;lt;command_to_be_executed_remotely&amp;gt;&amp;#039;\n&amp;quot;;&lt;br /&gt;
       exit;&lt;br /&gt;
       ;;&lt;br /&gt;
    esac&lt;br /&gt;
done&lt;br /&gt;
shift $((OPTIND-1))&lt;br /&gt;
VERBOSE=${VERBOSE:-&amp;quot;N&amp;quot;}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
# --------------------------------&lt;br /&gt;
# check we have required arguments&lt;br /&gt;
# --------------------------------&lt;br /&gt;
[[ -z $CMMND ]] &amp;amp;&amp;amp; echo &amp;quot;Enter command to be executed like this: $0 -c &amp;#039;ls -al&amp;#039;&amp;quot; &amp;amp;&amp;amp; exit 1&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
# ----------------------------&lt;br /&gt;
# loop over the remote servers&lt;br /&gt;
# ----------------------------&lt;br /&gt;
for server in ${serverlist}&lt;br /&gt;
do&lt;br /&gt;
    if [[ &amp;quot;$VERBOSE&amp;quot; == &amp;quot;Y&amp;quot; ]]; then&lt;br /&gt;
        echo ${server} `date +&amp;#039;%d-%b-%Y %H:%M:%S&amp;#039;`&lt;br /&gt;
        echo &amp;quot;------------------------------------&amp;quot;&lt;br /&gt;
        set -x&lt;br /&gt;
    fi&lt;br /&gt;
    ssh ${server} &amp;quot;$CMMND&amp;quot;&lt;br /&gt;
    set +x&lt;br /&gt;
    [[ &amp;quot;$VERBOSE&amp;quot; == &amp;quot;Y&amp;quot; ]] &amp;amp;&amp;amp; echo&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
to be investigated... this one might be cleverer than mine...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
tmpdir=${TMPDIR:-/tmp}/pssh.$$&lt;br /&gt;
count=0&lt;br /&gt;
while userhost; do&lt;br /&gt;
    ssh -n -o BatchMode=yes ${userhost} &amp;#039;uname -a&amp;#039; &amp;gt; ${tmpdir}/${userhost} 2&amp;gt;&amp;amp;1 &amp;amp;&lt;br /&gt;
    count=`expr $count + 1`&lt;br /&gt;
done &amp;lt; userhost.lst&lt;br /&gt;
while [ $count -gt 0 ]; do&lt;br /&gt;
    wait $pids&lt;br /&gt;
    count=`expr $count - 1`&lt;br /&gt;
done&lt;br /&gt;
echo &amp;quot;Output for hosts are in $tmpdir&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
improved version...&amp;lt;br /&amp;gt;&lt;br /&gt;
just escape double quotes and dollar signs...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/ksh&lt;br /&gt;
# ==============================================================================&lt;br /&gt;
# Name         : dosh   (Distributed Oracle SHell)&lt;br /&gt;
# Description  : Runs a command on all Oracle servers&lt;br /&gt;
#&lt;br /&gt;
# Parameters   : h - displays help&lt;br /&gt;
#                v - verbose (default, like all unix commands is silent)&lt;br /&gt;
#                c - command to be executed&lt;br /&gt;
#&lt;br /&gt;
# Example      : ./dosh -v -c &amp;#039;ls -al&amp;#039;&lt;br /&gt;
#&lt;br /&gt;
# Modification History&lt;br /&gt;
# ====================&lt;br /&gt;
# When      Who               What&lt;br /&gt;
# ========= ================= ==================================================&lt;br /&gt;
# 08-FEB-13 Stuart Barkley    Created&lt;br /&gt;
# 08-JUL-15 Stuart Barkley    Background execution mode&lt;br /&gt;
# ==============================================================================&lt;br /&gt;
# --------------------------------------------------------------------------&lt;br /&gt;
# this list of servers is generated by the DBAMON tool so will be up to date&lt;br /&gt;
# --------------------------------------------------------------------------&lt;br /&gt;
serverfile=/home/ibmtools/etc/oracle/oracle_servers&lt;br /&gt;
[[ -z &amp;quot;${serverfile}&amp;quot; ]] &amp;amp;&amp;amp; echo &amp;quot;Server list ${serverfile} not found&amp;quot; &amp;amp;&amp;amp; exit 1&lt;br /&gt;
&lt;br /&gt;
serverlist=`cat ${serverfile} | sort -n | tr &amp;quot;\n&amp;quot; &amp;quot; &amp;quot;`&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
# -------------------------&lt;br /&gt;
# get the arguments, if any&lt;br /&gt;
# -------------------------&lt;br /&gt;
while getopts &amp;quot;hbvc:&amp;quot; OPT&lt;br /&gt;
do&lt;br /&gt;
    case &amp;quot;$OPT&amp;quot; in&lt;br /&gt;
    h) echo &amp;quot;\nUsage: $0 [-b] [-v] [-h] -c &amp;#039;&amp;lt;command_to_be_executed_remotely&amp;gt;&amp;#039;\n&amp;quot;;&lt;br /&gt;
       exit;&lt;br /&gt;
       ;;&lt;br /&gt;
    b) BACKGROUND=&amp;quot;Y&amp;quot;;&lt;br /&gt;
       ;;&lt;br /&gt;
    v) VERBOSE=&amp;quot;Y&amp;quot;;&lt;br /&gt;
       ;;&lt;br /&gt;
    c) CMMND=$OPTARG;&lt;br /&gt;
       ;;&lt;br /&gt;
    *) echo &amp;quot;\nUsage: $0 [-b] [-v] [-h] -c &amp;#039;&amp;lt;command_to_be_executed_remotely&amp;gt;&amp;#039;\n&amp;quot;;&lt;br /&gt;
       exit;&lt;br /&gt;
       ;;&lt;br /&gt;
    esac&lt;br /&gt;
done&lt;br /&gt;
shift $((OPTIND-1))&lt;br /&gt;
VERBOSE=${VERBOSE:-&amp;quot;N&amp;quot;}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
# --------------------------------&lt;br /&gt;
# check we have required arguments&lt;br /&gt;
# --------------------------------&lt;br /&gt;
[[ -z $CMMND ]] &amp;amp;&amp;amp; echo &amp;quot;Enter command to be executed like this: $0 -c &amp;#039;ls -al&amp;#039;&amp;quot; &amp;amp;&amp;amp; exit 1&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
# ---------------------------------&lt;br /&gt;
# put the thing to be run in a file&lt;br /&gt;
# ---------------------------------&lt;br /&gt;
printf &amp;quot;%s\n&amp;quot; &amp;quot;$CMMND&amp;quot; &amp;gt; /tmp/dosh.$$&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
# ----------------------------&lt;br /&gt;
# loop over the remote servers&lt;br /&gt;
# ----------------------------&lt;br /&gt;
for server in ${serverlist}&lt;br /&gt;
do&lt;br /&gt;
    if [[ &amp;quot;$VERBOSE&amp;quot; == &amp;quot;Y&amp;quot; ]]; then&lt;br /&gt;
        printf &amp;quot;%s\n&amp;quot; ${server} `date +&amp;#039;%d-%b-%Y %H:%M:%S&amp;#039;`&lt;br /&gt;
        printf &amp;quot;%s\n&amp;quot; &amp;quot;------------------------------------&amp;quot;&lt;br /&gt;
        set -x&lt;br /&gt;
    fi&lt;br /&gt;
    scp -q /tmp/dosh.$$ ${server}:/tmp/&lt;br /&gt;
    if [[ &amp;quot;$BACKGROUND&amp;quot; == &amp;quot;Y&amp;quot; ]]; then&lt;br /&gt;
        ssh -n -o BatchMode=yes ${server} &amp;quot;ksh /tmp/dosh.$$; rm -f /tmp/dosh.$$&amp;quot;&amp;gt; /tmp/dosh_${server}.out 2&amp;gt;&amp;amp;1 &amp;amp;&lt;br /&gt;
    else&lt;br /&gt;
        ssh -n -o BatchMode=yes ${server} &amp;quot;ksh /tmp/dosh.$$; rm -f /tmp/dosh.$$&amp;quot;&lt;br /&gt;
    fi&lt;br /&gt;
    set +x&lt;br /&gt;
    [[ &amp;quot;$VERBOSE&amp;quot; == &amp;quot;Y&amp;quot; ]] &amp;amp;&amp;amp; echo&lt;br /&gt;
done&lt;br /&gt;
rm -f /tmp/dosh.$$&lt;br /&gt;
&lt;br /&gt;
[[ &amp;quot;$BACKGROUND&amp;quot; == &amp;quot;Y&amp;quot; ]] &amp;amp;&amp;amp; printf &amp;quot;%s\n&amp;quot; &amp;quot;Type &amp;#039;ls -altr /tmp/dosh*out&amp;#039; to see output from the commands&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===How can a shell script find out what directory it is in?===&lt;br /&gt;
basename $0 does not always give the desired answer (might give &amp;quot;./&amp;quot;!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
DIR=&amp;quot;$(cd &amp;quot;$(dirname &amp;quot;$0&amp;quot;)&amp;quot; &amp;amp;&amp;amp; pwd)&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Array processing===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
array=(1 2 3)&lt;br /&gt;
unset array[2]&lt;br /&gt;
echo ${array[2]}          # null&lt;br /&gt;
indices=(${!array[@]})    # create an array of the indices of &amp;quot;array&amp;quot;&lt;br /&gt;
size=${#indices[@]}       # the size of &amp;quot;array&amp;quot; is the number of indices into it&lt;br /&gt;
size=${#array[@]}         # same&lt;br /&gt;
echo ${array[@]: -1}      # you can use slices to get array elements, -1 is the last one, etc.&lt;br /&gt;
for element in ${array[@]}; do    # iterate over the array without an index&lt;br /&gt;
&lt;br /&gt;
for index in ${indices[@]}        # iterate over the array WITH an index&lt;br /&gt;
do&lt;br /&gt;
    echo &amp;quot;Index: ${index}, Element: ${array[index]}&amp;quot;&lt;br /&gt;
done&lt;br /&gt;
&lt;br /&gt;
for index in ${!array[@]}         # iterate over the array WITH an index, directly&lt;br /&gt;
&lt;br /&gt;
array+=(&amp;quot;new element&amp;quot;)    # append a new element without referring to an index&lt;br /&gt;
((counter++))             # shorter than ((counter=counter+1)) or ((counter+=1))&lt;br /&gt;
if [[ $var == 3 ]]        # you can use the more &amp;quot;natural&amp;quot; comparison operators inside double square brackets&lt;br /&gt;
while [[ $var &amp;lt; 11 ]]     # another example&lt;br /&gt;
echo ${array[${index}-1]  # math inside an array subscript&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Send an email by talking directly to an smtp server===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
telnet smtp.domain.com 25 &amp;lt;&amp;lt;EOTXT&amp;gt;&amp;gt;/tmp/smtp.log&lt;br /&gt;
HELO me.domain.com&lt;br /&gt;
MAIL FROM:&amp;lt;stuart@domain.com&amp;gt;&lt;br /&gt;
RCPT TO:&amp;lt;anne@domain.com&amp;gt;&lt;br /&gt;
DATA&lt;br /&gt;
From: Stuart &amp;lt;stuart@domain.com&amp;gt;&lt;br /&gt;
To: Anne &amp;lt;anne@domain.com&amp;gt;&lt;br /&gt;
Subject: testing smtp email&lt;br /&gt;
&lt;br /&gt;
Hello, this should appear in the body&lt;br /&gt;
.&lt;br /&gt;
QUIT&lt;br /&gt;
EOTXT&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Send an email by talking directly to an smtp server via file descriptor (no telnet! this time), adding authentication===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
&lt;br /&gt;
#&lt;br /&gt;
# mail.sh&lt;br /&gt;
#&lt;br /&gt;
# 2008 - Mike Golvach - eggi@comcast.net&lt;br /&gt;
# 2010 - Rayber&lt;br /&gt;
#&lt;br /&gt;
# Creative Commons Attribution-Noncommercial-Share Alike 3.0 United States License&lt;br /&gt;
#&lt;br /&gt;
&lt;br /&gt;
if [ $# -ne 7 ]&lt;br /&gt;
then&lt;br /&gt;
echo &amp;quot;Usage: $0 FromAdress ToAdress Domain MailServer MailTextFile AuthEmail AuthPass&amp;quot;&lt;br /&gt;
exit 1&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
from=$1&lt;br /&gt;
to=$2&lt;br /&gt;
domain=$3&lt;br /&gt;
mailserver=$4&lt;br /&gt;
mailtext=$5&lt;br /&gt;
authemail=`echo $6|openssl enc -base64|awk &amp;#039;sub(&amp;quot;..$&amp;quot;, &amp;quot;&amp;quot;)&amp;#039;`&lt;br /&gt;
authpass=`echo $7|openssl enc -base64|awk &amp;#039;sub(&amp;quot;..$&amp;quot;, &amp;quot;&amp;quot;)&amp;#039;`&lt;br /&gt;
&lt;br /&gt;
if [ ! -f $mailtext ]&lt;br /&gt;
then&lt;br /&gt;
echo &amp;quot;Cannot find your mail text file. Exiting...&amp;quot;&lt;br /&gt;
exit 1&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
exec 9&amp;lt;&amp;gt;/dev/tcp/$mailserver/25&lt;br /&gt;
echo &amp;quot;HELO $domain&amp;quot; &amp;gt;&amp;amp;9&lt;br /&gt;
read -r temp &amp;lt;&amp;amp;9&lt;br /&gt;
echo &amp;quot;$temp&amp;quot;&lt;br /&gt;
echo &amp;quot;auth login&amp;quot; &amp;gt;&amp;amp;9&lt;br /&gt;
read -r temp &amp;lt;&amp;amp;9&lt;br /&gt;
echo &amp;quot;$authemail&amp;quot; &amp;gt;&amp;amp;9&lt;br /&gt;
read -r temp &amp;lt;&amp;amp;9&lt;br /&gt;
echo &amp;quot;$authpass&amp;quot; &amp;gt;&amp;amp;9&lt;br /&gt;
read -r temp &amp;lt;&amp;amp;9&lt;br /&gt;
echo &amp;quot;Mail From: $from&amp;quot; &amp;gt;&amp;amp;9&lt;br /&gt;
read -r temp &amp;lt;&amp;amp;9&lt;br /&gt;
echo &amp;quot;$temp&amp;quot;&lt;br /&gt;
echo &amp;quot;Rcpt To: $to&amp;quot; &amp;gt;&amp;amp;9&lt;br /&gt;
read -r temp &amp;lt;&amp;amp;9&lt;br /&gt;
echo &amp;quot;$temp&amp;quot;&lt;br /&gt;
echo &amp;quot;Data&amp;quot; &amp;gt;&amp;amp;9&lt;br /&gt;
read -r temp &amp;lt;&amp;amp;9&lt;br /&gt;
echo &amp;quot;$temp&amp;quot;&lt;br /&gt;
cat $mailtext &amp;gt;&amp;amp;9&lt;br /&gt;
echo &amp;quot;.&amp;quot; &amp;gt;&amp;amp;9&lt;br /&gt;
read -r temp &amp;lt;&amp;amp;9&lt;br /&gt;
echo &amp;quot;$temp&amp;quot;&lt;br /&gt;
echo &amp;quot;quit&amp;quot; &amp;gt;&amp;amp;9&lt;br /&gt;
read -r temp &amp;lt;&amp;amp;9&lt;br /&gt;
echo &amp;quot;$temp&amp;quot;&lt;br /&gt;
9&amp;gt;&amp;amp;-&lt;br /&gt;
9&amp;lt;&amp;amp;-&lt;br /&gt;
echo &amp;quot;All Done Sending Email. See above for errors&amp;quot;&lt;br /&gt;
exit 0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== rsync examples===&lt;br /&gt;
Also see [[Distribute files to multiple servers using rsync and ssh]]&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/sh&lt;br /&gt;
ssh  &amp;lt;remote_host&amp;gt; &amp;#039;/bin/mkdir -p /etc /etc/rc.config.d /etc/security /etc/mail&amp;#039;&lt;br /&gt;
rsync --rsync-path /usr/bin/rsync -Liprogtz --out-format=%f%L  /etc/passwd /etc/passwd.post /etc/group /etc/hosts /etc/services /etc/resolv.conf /etc/exclude.rootvg &amp;lt;remote_host&amp;gt;:/etc&lt;br /&gt;
rsync --rsync-path /usr/bin/rsync -Liprogtz --out-format=%f%L  /etc/hosts.allow.xcat &amp;lt;remote_host&amp;gt;:/etc/hosts.allow&lt;br /&gt;
rsync --rsync-path /usr/bin/rsync -Liprogtz --out-format=%f%L  /etc/rc.config.d/sap &amp;lt;remote_host&amp;gt;:/etc/rc.config.d&lt;br /&gt;
rsync --rsync-path /usr/bin/rsync -Liprogtz --out-format=%f%L  /etc/security/group /etc/security/limits /etc/security/login.cfg /etc/security/passwd /etc/security/user &amp;lt;remote_host&amp;gt;:/etc/security&lt;br /&gt;
rsync --rsync-path /usr/bin/rsync -Liprogtz --out-format=%f%L  /etc/mail/sendmail.cf &amp;lt;remote_host&amp;gt;:/etc/mail&lt;br /&gt;
&lt;br /&gt;
rsync -av --progress /home/ibmtools/scripts/oracle/* benouerp07:/home/ibmtools/scripts/oracle/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Handy aliases===&lt;br /&gt;
Strip out comments and blank lines from a file&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alias strip=&amp;#039;grep -Ev &amp;#039;\&amp;#039;&amp;#039;^(#|$)&amp;#039;\&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Does a ps and a grep&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alias psg=&amp;#039;ps -ef | grep -v $$ | grep -i &amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Getting a decent listing of filesystem space available. It is ordered such that the filesystems with no space left are at the end.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
OS=$(uname -s)&lt;br /&gt;
[[ &amp;quot;$OS&amp;quot; == &amp;quot;SunOS&amp;quot; ]] &amp;amp;&amp;amp; alias dfg=&amp;#039;df -h|sed -e &amp;#039;1d&amp;#039;|sort -n -k5|awk &amp;#039;\&amp;#039;&amp;#039; BEGIN {printf(&amp;quot;%-35s%-10s%-10s%-6s%-30s\n&amp;quot;,&amp;quot;Filesystem&amp;quot;,&amp;quot;Total&amp;quot;,&amp;quot;Free&amp;quot;,&amp;quot;%Used&amp;quot;,&amp;quot;Mounted on&amp;quot;)} {printf(&amp;quot;%-35s%-10s%-10s%-6s%-30s\n&amp;quot;,$1,$2,$4,$5,$6)}&amp;#039;\&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
[[ &amp;quot;$OS&amp;quot; == &amp;quot;AIX&amp;quot; ]]   &amp;amp;&amp;amp; alias dfg=&amp;#039;df -g|sed -e &amp;#039;1d&amp;#039;|sort -n -k4|awk &amp;#039;\&amp;#039;&amp;#039; BEGIN {printf(&amp;quot;%-35s%-10s%-10s%-6s%-30s\n&amp;quot;,&amp;quot;Filesystem&amp;quot;,&amp;quot;Total GB&amp;quot;,&amp;quot;Free&amp;quot;,&amp;quot;%Used&amp;quot;,&amp;quot;Mounted on&amp;quot;)} {printf(&amp;quot;%-35s%-10s%-10s%-6s%-30s\n&amp;quot;,$1,$2,$3,$4,$7)}&amp;#039;\&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
A handy way of listing subdirectories and their files&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alias filetree=&amp;quot;find . -print | sed -e &amp;#039;s;[^/]*/;|____;g;s;____|; |;g&amp;#039;&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Watch progress of a copy&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alias cpProgress=&amp;quot;rsync --progress -ravz&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Reboots Linksys router&amp;lt;pre&amp;gt;&lt;br /&gt;
alias rebootlinksys=&amp;quot;curl -u &amp;#039;admin:password&amp;#039; &amp;#039;http://192.168.1.2/setup.cgi?todo=reboot&amp;#039;&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Nice one for bash. Colour codes the prompt depending on the outcome of the previous command&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
bash_prompt_command()&lt;br /&gt;
{&lt;br /&gt;
    RTN=$?&lt;br /&gt;
    prevCmd=$(prevCmd $RTN)&lt;br /&gt;
}&lt;br /&gt;
PROMPT_COMMAND=bash_prompt_command&lt;br /&gt;
prevCmd()&lt;br /&gt;
{&lt;br /&gt;
    if [ $1 == 0 ] ; then&lt;br /&gt;
        echo $GREEN&lt;br /&gt;
    else&lt;br /&gt;
        echo $RED&lt;br /&gt;
    fi&lt;br /&gt;
}&lt;br /&gt;
if [ $(tput colors) -gt 0 ] ; then&lt;br /&gt;
    RED=$(tput setaf 1)&lt;br /&gt;
    GREEN=$(tput setaf 2)&lt;br /&gt;
    RST=$(tput op)&lt;br /&gt;
fi&lt;br /&gt;
export PS1=&amp;quot;\[\e[36m\]\u.\h.\W\[\e[0m\]\[\$prevCmd\]&amp;gt;\[$RST\]&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Mmmm, to be looked into. Executes remote commands on a unix box using curl.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#/bin/sh&lt;br /&gt;
#&lt;br /&gt;
# WAG320N-HACK&lt;br /&gt;
# Ver. 1.0&lt;br /&gt;
# 12/09/2010&lt;br /&gt;
#&lt;br /&gt;
# This program is free software: you can redistribute it and/or modify&lt;br /&gt;
# it under the terms of the GNU General Public License as published by&lt;br /&gt;
# the Free Software Foundation, either version 3 of the License, or&lt;br /&gt;
# (at your option) any later version.&lt;br /&gt;
#&lt;br /&gt;
# This program is distributed in the hope that it will be useful,&lt;br /&gt;
# but WITHOUT ANY WARRANTY; without even the implied warranty of&lt;br /&gt;
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the&lt;br /&gt;
# GNU General Public License for more details.&lt;br /&gt;
#&lt;br /&gt;
# You should have received a copy of the GNU General Public License&lt;br /&gt;
# along with this program.  If not, see &amp;lt;http://www.gnu.org/licenses/&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
# Set username and password in the form of &amp;quot;username:password&amp;quot;&lt;br /&gt;
# example: &amp;quot;admin:admin&amp;quot;&lt;br /&gt;
my_access=&amp;quot;admin:admin&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Parameters test&lt;br /&gt;
if [ -z &amp;quot;$1&amp;quot; ]&lt;br /&gt;
then&lt;br /&gt;
  echo &amp;quot;wag320n-hack.sh: missing remote command&amp;quot;&lt;br /&gt;
  echo &amp;quot;usage: wag320n-hack.sh &amp;lt;remote command&amp;gt;&amp;quot;&lt;br /&gt;
  echo &amp;quot;example: wag320n-hack.sh /bin/ls -la /usr/sbin&amp;quot;&lt;br /&gt;
  echo &amp;quot;Note: always use full path&amp;quot;&lt;br /&gt;
  echo &amp;quot;&amp;quot;&lt;br /&gt;
  echo &amp;quot;wag320n-hack.sh - Ver. 1.0 - 12/09/2010&amp;quot;&lt;br /&gt;
  echo &amp;quot;Licensed under GPL V. 3&amp;quot;&lt;br /&gt;
  echo &amp;quot;&amp;quot;&lt;br /&gt;
  exit 0&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
# Get the command&lt;br /&gt;
my_command=&amp;quot;ping_size=&amp;quot;&amp;#039;$(&amp;#039;&amp;quot;$@&amp;quot;&amp;#039; 1&amp;gt;&amp;amp;2)&amp;#039;&lt;br /&gt;
&lt;br /&gt;
curl -s -G -u &amp;quot;$my_access&amp;quot; --data-urlencode &amp;#039;todo=ping_test&amp;#039; --data-urlencode &amp;#039;this_file=Diagnostics.htm&amp;#039; --data-urlencode &amp;#039;next_file=Ping.htm&amp;#039; --data-urlencode &amp;#039;c4_ping_ipaddr=192.168.1.1&amp;#039; --data-urlencode &amp;#039;ping_timeout=5000&amp;#039; --data-urlencode &amp;#039;ping_interval=1000&amp;#039; --data-urlencode &amp;#039;ping_number=1&amp;#039; --data-urlencode &amp;quot;$my_command&amp;quot; http://192.168.1.1/setup.cgi | sed -e &amp;#039;/HTTP\/1.0 200 OK/q&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===How to configure SSH with public/private keys===&lt;br /&gt;
* [http://www.unixpeople.com/HOWTO/configuring.ssh.html unixpeople.com]&lt;br /&gt;
===Use SSH config file===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Host server10&lt;br /&gt;
  Hostname 1.2.3.4&lt;br /&gt;
  IdentityFile ~/.ssh/id_dsa&lt;br /&gt;
  user foobar&lt;br /&gt;
  Port 30000&lt;br /&gt;
  ForwardX11Trusted yes&lt;br /&gt;
  TCPKeepAlive yes&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
then just connect using&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ssh server10&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===A decent sed tutorial===&lt;br /&gt;
From [http://www.grymoire.com/Unix/Sed.html grymoire.com]&lt;br /&gt;
===A decent korn/bash shell tutorial===&lt;br /&gt;
From [http://www.dartmouth.edu/~rc/classes/ksh/print_pages.shtml dartmouth.edu]&lt;br /&gt;
Reproduced here just in case it disappears!&lt;br /&gt;
[[Advanced shell scripting]]&lt;br /&gt;
&lt;br /&gt;
===trap===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
     Example Handling Traps With ksh - Discussion of the kill command&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
EXAMPLE TEMPLATE:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
PRODUCT:    HP-UX 11iV1 Version B.11.11&lt;br /&gt;
            HP Tru64 V5.1B PK4&lt;br /&gt;
            Sun/Solaris SunOS V5.8&lt;br /&gt;
            Linux 2.6 kernel&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
COMPONENT:  ksh&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
SOURCE:     Philippe Vouters&lt;br /&gt;
            Fontainebleau/France&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
LOW COST HIGH-TECH PRODUCTS:  http://techno-star.fr&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
OVERVIEW:&lt;br /&gt;
&lt;br /&gt;
The ksh script below shows how to eventually handle traps in the situation &lt;br /&gt;
where someone might try to kill a script by killing individual commands run &lt;br /&gt;
by that script or the entire process group a script is running in. The kill &lt;br /&gt;
command (usually a shell builtin) may be used to send a signal to a process &lt;br /&gt;
group (with the -&amp;lt;pid&amp;gt; syntax) or an individual process. The example ksh &lt;br /&gt;
script below runs /bin/sleep as the foreground process, the example ksh &lt;br /&gt;
scripts immediately returns when the /bin/sleep process has terminated. Most &lt;br /&gt;
signals sent to the shell are ignored until after the foreground process &lt;br /&gt;
terminates. This is in order to avoid creating zombie processes. Therefore a &lt;br /&gt;
kill &amp;lt;pid&amp;gt; on the example ksh script waits for the termination of the &lt;br /&gt;
/bin/sleep process.&lt;br /&gt;
&lt;br /&gt;
The status value $? in the trap refers to the exit status of the command to run &lt;br /&gt;
and therefore is the exit status of the /bin/sleep process. The called function &lt;br /&gt;
in the trap handler shows how to correctly examine the effect of the kill &lt;br /&gt;
command on the shell or it&amp;#039;s children.&lt;br /&gt;
&lt;br /&gt;
To examine the value of $? in a trap handler means that you must understand what&lt;br /&gt;
it can be set and how different signals delivered to either the shell or the &lt;br /&gt;
foreground process (or the process group) might affect the value of $?.&lt;br /&gt;
&lt;br /&gt;
The example shell script prints $? using echo but it does not perform tests on &lt;br /&gt;
the value of $?. For a complete solution when attempting to trap signals in a &lt;br /&gt;
shell you would also need code that examined the value of $? after the &lt;br /&gt;
foreground process had completed.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*** CAUTION ***&lt;br /&gt;
&lt;br /&gt;
This sample script has been tested using HP-UX B.11.11, HP Tru64 V5.1B PK4, &lt;br /&gt;
SunOS V5.8 and Fedora Core 4 (homed version of Red Hat Linux).  However, we&lt;br /&gt;
cannot guarantee its effectiveness because of the possibility of error in &lt;br /&gt;
transmitting or implementing it. It is meant to be used as a template for &lt;br /&gt;
writing your own scripts, and may require modification for use on your system. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
SCRIPT NOTES:&lt;br /&gt;
&lt;br /&gt;
To notice that the ksh script and /bin/sleep share the same process group&lt;br /&gt;
identifier (PGID), issue the following commands:&lt;br /&gt;
&lt;br /&gt;
[philippe@victor ~]$ who&lt;br /&gt;
philippe :0           Jan 10 10:16&lt;br /&gt;
philippe pts/1        Jan 10 21:30 (:0.0)&lt;br /&gt;
philippe pts/2        Jan 10 21:30 (:0.0)&lt;br /&gt;
[philippe@victor ~]$ tty&lt;br /&gt;
/dev/pts/1&lt;br /&gt;
[philippe@victor ~]$ ps -j -t pts/2&lt;br /&gt;
  PID  PGID   SID TTY          TIME CMD&lt;br /&gt;
11072 11072 11072 pts/2    00:00:00 bash&lt;br /&gt;
11113 11113 11072 pts/2    00:00:00 ksh&lt;br /&gt;
11116 11113 11072 pts/2    00:00:00 sleep&lt;br /&gt;
&lt;br /&gt;
In this case sending kill -INT -11113 will send SIGINT to the process group &lt;br /&gt;
11113. Both of the ksh and sleep processes are contained within this process &lt;br /&gt;
group.&lt;br /&gt;
&lt;br /&gt;
Important Note:&lt;br /&gt;
&lt;br /&gt;
On HP-UX, you have to $ export UNIX95=1 in order to be able to use the&lt;br /&gt;
-j option of the ps command.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
SCRIPT:&lt;br /&gt;
&lt;br /&gt;
                             COPYRIGHT (C) 2005 BY&lt;br /&gt;
                              HEWLETT-PACKARD COMPANY&lt;br /&gt;
                                ALL RIGHTS RESERVED.&lt;br /&gt;
&lt;br /&gt;
     THIS SOFTWARE IS FURNISHED UNDER A LICENSE AND MAY BE USED AND COPIED&lt;br /&gt;
     ONLY IN ACCORDANCE WITH THE TERMS OF SUCH LICENSE AND WITH THE INCLUSION&lt;br /&gt;
     OF THE ABOVE COPYRIGHT NOTICE.  THIS SOFTWARE OR ANY OTHER COPIES&lt;br /&gt;
     THEREOF MAY NOT BE PROVIDED OR OTHERWISE MADE AVAILABLE TO ANY OTHER&lt;br /&gt;
     PERSON.  NO TITLE TO AND OWNERSHIP OF THE SOFTWARE IS HEREBY TRANSFERRED.&lt;br /&gt;
&lt;br /&gt;
     THE INFORMATION IN THIS SOFTWARE IS SUBJECT TO CHANGE WITHOUT NOTICE AND&lt;br /&gt;
     SHOULD NOT BE CONSTRUED AS A COMMITMENT BY HEWLETT-PACKARD COMPANY.&lt;br /&gt;
&lt;br /&gt;
     HP ASSUMES NO RESPONSIBILITY FOR THE USE OR RELIABILITY OF ITS&lt;br /&gt;
     SOFTWARE ON EQUIPMENT THAT IS NOT SUPPLIED BY HP.&lt;br /&gt;
&lt;br /&gt;
     NO RESPONSIBILITY IS ASSUMED FOR THE USE OR RELIABILITY OF SOFTWARE&lt;br /&gt;
     ON EQUIPMENT THAT IS NOT SUPPLIED BY HEWLETT-PACKARD COMPANY.&lt;br /&gt;
&lt;br /&gt;
     SUPPORT FOR THIS SOFTWARE IS NOT COVERED UNDER ANY HP SOFTWARE&lt;br /&gt;
     PRODUCT SUPPORT CONTRACT, BUT MAY BE PROVIDED UNDER THE TERMS OF THE&lt;br /&gt;
     CONSULTING AGREEMENT UNDER WHICH THIS SOFTWARE WAS DEVELOPED.&lt;br /&gt;
&lt;br /&gt;
#!/bin/ksh&lt;br /&gt;
function handle_signal&lt;br /&gt;
{&lt;br /&gt;
        print -n &amp;quot;pid $$ recieved $2 &amp;quot;&lt;br /&gt;
        if [[ $1 = 0 ]];then&lt;br /&gt;
            print but foreground command ended successfully&lt;br /&gt;
        else&lt;br /&gt;
                if [[ $1 = $3 ]];then&lt;br /&gt;
                    print and so did the last foreground command&lt;br /&gt;
                else&lt;br /&gt;
                    print -n &amp;quot;and the exit status of the last foreground &amp;quot;&lt;br /&gt;
                    print command was $1&lt;br /&gt;
                fi&lt;br /&gt;
        fi&lt;br /&gt;
        # Kill our process group and then ourselves with SIGTERM, giving a &lt;br /&gt;
        # pid of 0 sends the signal to our process group. Killing the process&lt;br /&gt;
        # group should kill us as well, this assumes that SIGTERM is not &lt;br /&gt;
        # handled by any process in the process group.&lt;br /&gt;
        #&lt;br /&gt;
        # This code could be replaced with an exit with an exit value that&lt;br /&gt;
        # would indicate what the problem was to the caller. That is replace &lt;br /&gt;
        # these two lines with:&lt;br /&gt;
        #&lt;br /&gt;
        # exit $3&lt;br /&gt;
        #&lt;br /&gt;
        # or a specific exit code could be used.&lt;br /&gt;
        #&lt;br /&gt;
        kill -TERM 0&lt;br /&gt;
        kill -TERM $$&lt;br /&gt;
        }&lt;br /&gt;
OS=$(uname -a | awk &amp;#039;{print $1}&amp;#039;)&lt;br /&gt;
if [[ &amp;quot;$OS&amp;quot; = &amp;quot;Linux&amp;quot; ]]; then&lt;br /&gt;
    offset=256&lt;br /&gt;
elif [[ (&amp;quot;$OS&amp;quot; = &amp;quot;HP-UX&amp;quot;) || &lt;br /&gt;
        (&amp;quot;$OS&amp;quot; = &amp;quot;SunOS&amp;quot;) || &lt;br /&gt;
        (&amp;quot;$OS&amp;quot; = &amp;quot;OSF1&amp;quot;) ]]; then&lt;br /&gt;
   offset=128&lt;br /&gt;
fi&lt;br /&gt;
trap &amp;#039;RC=$?; handle_signal $RC SIGINT $offset+2&amp;#039; INT&lt;br /&gt;
trap &amp;#039;RC=$?; handle_signal $RC SIGQUIT $offset+3&amp;#039; QUIT&lt;br /&gt;
/bin/sleep 20&lt;br /&gt;
echo $?&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===DNS not working===&lt;br /&gt;
Ping to an IP address works&lt;br /&gt;
 ping 74.125.136.103&lt;br /&gt;
but this doesn&amp;#039;t&lt;br /&gt;
 ping www.google.com&lt;br /&gt;
&lt;br /&gt;
Check resolv.conf&lt;br /&gt;
 cat /etc/resolv.conf&lt;br /&gt;
 nameserver 95.130.132.17&lt;br /&gt;
 nameserver 95.130.132.18&lt;br /&gt;
I had changed internet provider and forgot to update this. Just to set it to the router address and let that do the resolution&lt;br /&gt;
 nameserver 192.168.1.1&lt;br /&gt;
&lt;br /&gt;
===File descriptors===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
exec 3&amp;lt;&amp;gt; /tmp/foo  #open fd 3 for r/w&lt;br /&gt;
echo &amp;quot;test&amp;quot; &amp;gt;&amp;amp;3&lt;br /&gt;
exec 3&amp;gt;&amp;amp;- #close fd 3.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
exec 3&amp;lt;&amp;gt; myfile.txt&lt;br /&gt;
while read line &amp;lt;&amp;amp;3&lt;br /&gt;
do {&lt;br /&gt;
  echo &amp;quot;$line&amp;quot;&lt;br /&gt;
  (( Lines++ ));                   #  Incremented values of this variable&lt;br /&gt;
                                   #+ accessible outside loop.&lt;br /&gt;
                                   #  No subshell, no problem.&lt;br /&gt;
}&lt;br /&gt;
done&lt;br /&gt;
exec 3&amp;gt;&amp;amp;-&lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;Number of lines read = $Lines&amp;quot;     # 8&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Mmm. See our output and also tee it to a log file!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
&lt;br /&gt;
echo hello&lt;br /&gt;
&lt;br /&gt;
if test -t 1; then&lt;br /&gt;
    # Stdout is a terminal.&lt;br /&gt;
    exec &amp;gt;log&lt;br /&gt;
else&lt;br /&gt;
    # Stdout is not a terminal.&lt;br /&gt;
    npipe=/tmp/$$.tmp&lt;br /&gt;
    trap &amp;quot;rm -f $npipe&amp;quot; EXIT&lt;br /&gt;
    mknod $npipe p&lt;br /&gt;
    tee &amp;lt;$npipe log &amp;amp;&lt;br /&gt;
    exec 1&amp;gt;&amp;amp;-&lt;br /&gt;
    exec 1&amp;gt;$npipe&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
echo goodbye&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Create new image with kvm===&lt;br /&gt;
Ref: http://www.cyberciti.biz/faq/kvm-virtualization-in-redhat-centos-scientific-linux-6/&amp;lt;br /&amp;gt;&lt;br /&gt;
Build an empty space for a CentOS virtual machine&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
qemu-img create -f qcow2 centos.img 12G&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Tried creating image with&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo virt-install -n CentOS --description &amp;quot;Trying out CentOS&amp;quot; --ram=1024 --vcpus=1 --cpu host --hvm --cdrom /home/bey9at77/Downloads/c6-x86_64-20130910-1.qcow2 --graphics vnc --disk path=/var/lib/libvirt/images/centos.img,bus=virtio,size=10&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
gives error&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Starting install...&lt;br /&gt;
Allocating &amp;#039;centos.img&amp;#039;                                                                                                                                                                                               |  10 GB     00:00     &lt;br /&gt;
ERROR    internal error Process exited while reading console log output: char device redirected to /dev/pts/1&lt;br /&gt;
qemu-kvm: -drive file=/home/bey9at77/Downloads/c6-x86_64-20130910-1.qcow2.bz2,if=none,media=cdrom,id=drive-ide0-1-0,readonly=on,format=raw: could not open disk image /home/bey9at77/Downloads/c6-x86_64-20130910-1.qcow2: Permission denied&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===rpm / yum commands===&lt;br /&gt;
====Install an RPM Package====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rpm -ivh pidgin-2.7.9-5.el6.2.i686.rpm&lt;br /&gt;
&lt;br /&gt;
-i - install&lt;br /&gt;
-v - verbose&lt;br /&gt;
-h - print progress hashes&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Check dependencies of RPM Package before Installing====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rpm -qpR BitTorrent-5.2.2-1-Python2.4.noarch.rpm&lt;br /&gt;
&lt;br /&gt;
-q - query&lt;br /&gt;
-p - list package capabilities&lt;br /&gt;
-R - list dependent package capabilities&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Install RPM Package with all dependencies====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
yum install BitTorrent-5.2.2-1-Python2.4.noarch.rpm&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Install RPM Package with all dependencies (when RPM has been downloaded to local machine)====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
yum localinstall BitTorrent-5.2.2-1-Python2.4.noarch.rpm&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Force Install a RPM Package without dependencies====&lt;br /&gt;
Package will not work if dependencies are required&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rpm -ivh --nodeps BitTorrent-5.2.2-1-Python2.4.noarch.rpm&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Check an Installed RPM Package====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rpm -q BitTorrent&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====List all files of an installed RPM package====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rpm -ql BitTorrent&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====List All Installed RPM Packages====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rpm -qa&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Query information about an installed RPM package====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rpm -qi vsftpd&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Query information about a not yet installed RPM package====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rpm -qip sqlbuddy-1.3.3-1.noarch.rpm&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====(Forcibly) Remove an RPM Package====&lt;br /&gt;
Use package name (as seen in -qi above), not full name&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rpm -ev (--nodeps) vsftpd&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Query a file that was installed as part of an RPM Package (which package contained this file)====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rpm -qf /usr/bin/htpasswd&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Verify an RPM package====&lt;br /&gt;
Compares information of installed files of the package against the rpm database&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rpm -Vp sqlbuddy-1.3.3-1.noarch.rpm&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Rebuild corrupted RPM database====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cd /var/lib&lt;br /&gt;
rm __db*&lt;br /&gt;
rpm --rebuilddb&lt;br /&gt;
rpmdb_verify Packages&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Install rpmforge repository===&lt;br /&gt;
* Download rpmforge-release-0.5.3-1.el6.rf.x86_64.rpm&lt;br /&gt;
* Import the key&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo rpm --import http://apt.sw.be/RPM-GPG-KEY.dag.txt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Install the repository&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo rpm -i rpmforge-release-0.5.3-1.el6.rf.x86_64.rpm&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Check the installation&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rpm -K rpmforge-release-0.5.3-1.el6.rf.x86_64.rpm&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Test it&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo yum install terminator&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Install rpmfusion repository===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
su -c &amp;#039;yum localinstall --nogpgcheck http://download1.rpmfusion.org/free/el/updates/6/i386/rpmfusion-free-release-6-1.noarch.rpm http://download1.rpmfusion.org/nonfree/el/updates/6/i386/rpmfusion-nonfree-release-6-1.noarch.rpm&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===config file for yum===&lt;br /&gt;
Checkout this file for global yum config&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/etc/sysconfig/yum-cron-background&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Setup Oracle Enterprise Linux (RedHat) with yum server===&lt;br /&gt;
You need to download the yum .repo file from the server, as per the steps below. After this, you need to enable a flag in the .repo file as per your operating system version. Having done these two steps, when you run yum install &amp;lt;pkgname&amp;gt; command on your linux box, the Oracle&amp;#039;s yum server will be scanned, the dependent &amp;amp; the relevant rpm&amp;#039;s will be download and installed for you.&amp;lt;br /&amp;gt;&lt;br /&gt;
 cd /etc/yum.repos.d&lt;br /&gt;
To download files here&lt;br /&gt;
 wget http://public-yum.oracle.com/public-yum-el5.repo&lt;br /&gt;
&lt;br /&gt;
A file named public-yum-el5.repo will be created in your directory&amp;lt;br /&amp;gt;&lt;br /&gt;
Edit this file and enter enabled=1 against the operating systems which is relevant to you&lt;br /&gt;
 vi public-yum-el5.repo&lt;br /&gt;
&lt;br /&gt;
Next run the yum command&lt;br /&gt;
 yum install package-name&lt;br /&gt;
&lt;br /&gt;
===To change to static IP address (Raspberry Pi)===&lt;br /&gt;
As root:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cd /etc/networks&lt;br /&gt;
vi interfaces&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
replace the line “iface eth0 inet dhcp” with&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
iface eth0 inet static&lt;br /&gt;
address 192.168.1.100&lt;br /&gt;
netmask 255.255.255.0&lt;br /&gt;
gateway 192.168.1.1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You should also take a look at the file /etc/resolv.conf and check it has a nameserver entry (probably pointing at your default gateway) or direct to your ISP name servers.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
nameserver 192.168.1.1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Troubleshoot wireless network problems===&lt;br /&gt;
* [https://www.blackmoreops.com/2014/09/18/connect-to-wifi-network-from-command-line-in-linux/ connect to wifi network from command-line in linux - from blackmoreops.com]&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Short summary of all the things you need to do in just few lines&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
root@kali:~# iw dev&lt;br /&gt;
root@kali:~# ip link set wlan0 up&lt;br /&gt;
root@kali:~# iw wlan0 scan&lt;br /&gt;
root@kali:~# wpa_passphrase blackMOREOps &amp;gt;&amp;gt; /etc/wpa_supplicant.conf&lt;br /&gt;
root@kali:~# wpa_supplicant -i wlan0 -c /etc/wpa_supplicant.conf&lt;br /&gt;
root@kali:~# iw wlan0 link&lt;br /&gt;
root@kali:~# dhclient wlan0&lt;br /&gt;
root@kali:~# ping 8.8.8.8&lt;br /&gt;
(Where wlan0 is wifi adapter and blackMOREOps is SSID)&lt;br /&gt;
(Add Routing manually)&lt;br /&gt;
root@kali:~# ip route add default via 10.0.0.138 dev wlan0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===To change to static IP address (Redhat/CentOS)===&lt;br /&gt;
As root:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
vi /etc/sysconfig/network-scripts/ifcfg-eth0&lt;br /&gt;
DEVICE=eth0&lt;br /&gt;
BOOTPROTO=STATIC&lt;br /&gt;
IPADDR=192.168.1.111&lt;br /&gt;
NETMASK=255.255.255.0&lt;br /&gt;
GATEWAY=192.168.1.1&lt;br /&gt;
ONBOOT=yes&lt;br /&gt;
DNS1=8.8.8.8&lt;br /&gt;
DNS2=8.8.4.4&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Resrart the network interface&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/etc/init.d/network stop&lt;br /&gt;
/etc/init.d/network start&lt;br /&gt;
or&lt;br /&gt;
service network restart&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Check name server entry in resolv.conf&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
vi /etc/resolv.conf&lt;br /&gt;
nameserver 192.168.1.1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Enable processes / services to start at boot time===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo chkconfig httpd on&lt;br /&gt;
sudo chkconfig mysqld on&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Run a command on lots of servers in parallel===&lt;br /&gt;
This is a damn fine AIX utility - part of the CSM Distributed Shell.&lt;br /&gt;
 dsh -a &amp;quot;ls -al /etc/apache2/*conf&amp;quot;&lt;br /&gt;
will list the Apache configuration file on all reachable servers (nodes)&lt;br /&gt;
===Download a gzip file and pipe it into tar===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cd ~ &amp;amp;&amp;amp; wget -O - &amp;quot;https://www.dropbox.com/download?plat=lnx.x86_64&amp;quot; | tar xzf -&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Check in a script to make sure it is run only by root===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
RUID=`/usr/bin/id|$AWK -F\( &amp;#039;{print $1}&amp;#039;|$AWK -F\= &amp;#039;{print $2}&amp;#039;`&lt;br /&gt;
if [ ${RUID} != &amp;quot;0&amp;quot; ];then&lt;br /&gt;
   $ECHO &amp;quot;This script must be executed as root&amp;quot;&lt;br /&gt;
   exit 1&lt;br /&gt;
fi&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Set terminal to use Backspace key to erase previous character instead of Control-H===&lt;br /&gt;
Been looking for this for a long time.&amp;lt;br /&amp;gt;&lt;br /&gt;
You can put:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
stty erase &amp;lt;CTRL-V&amp;gt;&amp;lt;Backspace key&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
in your .profile but this will be ruined if you do a copy/paste into another file.&amp;lt;br /&amp;gt;&lt;br /&gt;
I wanted a way of doing this without entering the control character in the .profile. Finally stumbled upon it. And it&amp;#039;s so simple. Just escape the caret!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
stty erase \^?&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Put this in the .profile. It&amp;#039;s copy/pastable and it works!&amp;lt;br /&amp;gt;&lt;br /&gt;
If you want CTRL-H to be your erase character, just do this:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
stty erase \^H&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Play with the terminal settings and reset them again either side of requesting a password===&lt;br /&gt;
The -g option of stty gives a compact list of all the settings or the terminal and can be used as input to stty&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
OLDCONFIG=`stty -g`          # save terminal configuration&lt;br /&gt;
stty -echo                   # turn character echoing off&lt;br /&gt;
echo &amp;quot;Enter password: \c&amp;quot;&lt;br /&gt;
read PASSWD                  # get the password&lt;br /&gt;
stty $OLDCONFIG              # restore terminal configuration&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Reset terminal to &amp;quot;sane&amp;quot; characteristics===&lt;br /&gt;
If you&amp;#039;ve done a cat of a binary file or something else weird and your terminal is left in a mess, the following key sequence should bring it back to normal&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;CTRL-J&amp;gt;stty sane&amp;lt;CTRL-J&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Install OpenOffice on RedHat Enterprise when yum install doesn&amp;#039;t!===&lt;br /&gt;
Download Package&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
wget http://sourceforge.net/projects/openofficeorg.mirror/files/4.0.1/binaries/en-US/Apache_OpenOffice_4.0.1_Linux_x86-64_install-rpm_en-US.tar.gz/download -O Apache_OpenOffice_4.0.1_Linux_x86-64_install-rpm_en-US.tar.gz&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Change to root&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo su -&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Remove the old stuff&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
yum remove openoffice* libreoffice*&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Extract Package&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
tar -xvf Apache_OpenOffice_4.0.1*&lt;br /&gt;
cd en-US&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Install Package and exit root&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rpm -Uvh RPMS/*.rpm RPMS/desktop-integration/openoffice4.0-redhat-*.rpm&lt;br /&gt;
exit&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Start it&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
openoffice4&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===What does this do?===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
while IFS= read -r line; do&lt;br /&gt;
    echo &amp;quot;[$(date &amp;quot;+%F %T&amp;quot;)] - $line&amp;quot;&lt;br /&gt;
done &amp;lt; &amp;lt;(iwevent)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
while IFS= read -r line; do&lt;br /&gt;
    printf &amp;quot;%s\n%s\n&amp;quot; &amp;quot;$line&amp;quot; &amp;quot;Yohooo! One more package.&amp;quot;&lt;br /&gt;
done &amp;lt; &amp;lt;(tcpdump -i any -nS)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===List of Special Characters and what they mean===&lt;br /&gt;
From [http://www.grymoire.com/Unix/Quote.html Bruce Barnett]&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Character	Where	Meaning&lt;br /&gt;
&amp;lt;RETURN&amp;gt;	csh, sh	Execute command&lt;br /&gt;
#	csh, sh, ASCII files	Start a comment&lt;br /&gt;
&amp;lt;SPACE&amp;gt;	csh, sh	Argument separator&lt;br /&gt;
`	csh, sh	Command substitution&lt;br /&gt;
&amp;quot;	csh, sh	Weak Quotes&lt;br /&gt;
&amp;#039;	csh, sh	Strong Quotes&lt;br /&gt;
\	csh, sh	Single Character Quote&lt;br /&gt;
variable	sh, csh	Variable&lt;br /&gt;
variable	csh, sh	Same as variable&lt;br /&gt;
|	csh, sh	Pipe character&lt;br /&gt;
^	sh	Pipe Character&lt;br /&gt;
&amp;amp;	csh, sh	Run program in background&lt;br /&gt;
?	csh, sh	Match one character&lt;br /&gt;
*	csh, sh	Match any number of characters&lt;br /&gt;
;	csh, sh	Command separator&lt;br /&gt;
;;	sh	End of Case statement&lt;br /&gt;
~	csh	Home Directory&lt;br /&gt;
~user	csh	User&amp;#039;s Home Directory&lt;br /&gt;
!	csh	History of Commands&lt;br /&gt;
-	Programs	Start of optional argument&lt;br /&gt;
$#	csh, sh	Number of arguments to script&lt;br /&gt;
$*	csh, sh	Arguments to script&lt;br /&gt;
$@	sh	Original arguments to script&lt;br /&gt;
$-	sh	Flags passed to shell&lt;br /&gt;
$?	sh	Status of previous command&lt;br /&gt;
$$	sh	Process identification number&lt;br /&gt;
$!	sh	PID of last background job&lt;br /&gt;
&amp;amp;&amp;amp;	sh	Short-circuit AND&lt;br /&gt;
||	sh	Short-circuit OR&lt;br /&gt;
.	csh, sh	Typ. filename extension&lt;br /&gt;
.	sh	Source a file and execute as command&lt;br /&gt;
:	sh	Nothing command&lt;br /&gt;
:	sh	Separates Values in environment variables&lt;br /&gt;
:	csh	Variable modifier&lt;br /&gt;
Character	Where	Meaning&lt;br /&gt;
[ ]	csh, sh	Match range of characters&lt;br /&gt;
[ ]	sh	Test&lt;br /&gt;
%job	csh	Identifies job Number&lt;br /&gt;
(cmd;cmd)	csh. sh	Runs cmd;cmd as a sub-shell&lt;br /&gt;
{ }	csh	In-line expansions&lt;br /&gt;
{cmd;cmd }	sh	Like (cmd;cmd ) without a subshell&lt;br /&gt;
&amp;gt;ofile	csh, sh	Standard output&lt;br /&gt;
&amp;gt;&amp;gt;ofile	csh, sh	Append to standard output&lt;br /&gt;
&amp;lt;ifile	csh, sh	Standard Input&lt;br /&gt;
&amp;lt;&amp;lt;word	csh, sh	Read until word, substitute variables&lt;br /&gt;
&amp;lt;&amp;lt;\word	csh, sh	Read until word, no substitution&lt;br /&gt;
&amp;lt;&amp;lt;-word	sh	Read until word, ignoring TABS&lt;br /&gt;
&amp;gt;&amp;gt;!file	csh	Append to file, ignore error if not there&lt;br /&gt;
&amp;gt;!file	csh	Output to new file, ignore error if not there&lt;br /&gt;
&amp;gt;&amp;amp;file	csh	Send standard &amp;amp; error output to file&lt;br /&gt;
&amp;lt;&amp;amp;digit	sh	Switch Standard Input to file&lt;br /&gt;
&amp;lt;&amp;amp;-	sh	Close Standard Input&lt;br /&gt;
&amp;gt;&amp;amp;digit	sh	Switch Standard Output to file&lt;br /&gt;
&amp;gt;&amp;amp;-	sh	Close Standard Output&lt;br /&gt;
digit1&amp;lt;&amp;amp;digit2	sh	Connect digit2 to digit1&lt;br /&gt;
digit&amp;lt;&amp;amp;-	sh	Close file digit&lt;br /&gt;
digit2&amp;gt;&amp;amp;digit1	sh	Connect digit2 to digit1&lt;br /&gt;
digit&amp;gt;&amp;amp;-	sh	Close file digit&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Stuart</name></author>	</entry>

	<entry>
		<id>https://mailnest.com/dbawiki/index.php?title=Unix/Linux&amp;diff=3380</id>
		<title>Unix/Linux</title>
		<link rel="alternate" type="text/html" href="https://mailnest.com/dbawiki/index.php?title=Unix/Linux&amp;diff=3380"/>
				<updated>2018-11-27T11:47:55Z</updated>
		
		<summary type="html">&lt;p&gt;Stuart: /* ps listing does not show start time after 24 hours */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;* [http://hyperpolyglot.org/unix-shells#var-expansion Good shell comparison including variable expansion - hyperpolyglot.org]&lt;br /&gt;
* [http://pubs.opengroup.org/onlinepubs/9699919799/utilities/toc.html Shell coding standards - opengroup.org]&lt;br /&gt;
* [http://aix4admins.blogspot.be aix4admins]&lt;br /&gt;
* [http://linuxgazette.net/issue55/okopnik.html The Deep, Dark Secrets of Bash]&lt;br /&gt;
* [http://www.speakeasy.org/~arkay/216-7.4KshFunctions.html Korn Shell Functions]&lt;br /&gt;
* [http://www.grymoire.com/Unix/AwkRef.html AWK reference from Bruce Barnett]&lt;br /&gt;
* [http://www.catonmat.net/blog/wp-content/uploads/2008/09/awk1line.txt HANDY AWK ONE-LINERS]&lt;br /&gt;
* [http://www.grymoire.com/unix/Quote.html Unix quoting from from Bruce Barnett (grymoire)]&lt;br /&gt;
* [http://www.mpi-inf.mpg.de/departments/rg1/teaching/unixffb-ss98/quoting-guide.html Another excellent quoting tutorial]&lt;br /&gt;
* [http://aix4admins.blogspot.be/2015/02/snapshot-fs-snapshot-snapshot-is-state.html AIX snapshot technology]&lt;br /&gt;
* [[RaspberryPi]]&lt;br /&gt;
* [[SSH]]&lt;br /&gt;
* [http://www.anattatechnologies.com/q/2013/04/multiuser-screen/ Screen sharing from Unix using screen]&lt;br /&gt;
* [https://robots.thoughtbot.com/a-tmux-crash-course Screen sharing from Unix using tmux]&lt;br /&gt;
* [http://www.csb.yale.edu/userguides/wordprocess/vi-summary.html Handy ex and vi reference]&lt;br /&gt;
* [[Fedora install for my own purposes]]&lt;br /&gt;
&lt;br /&gt;
===Use sed to repeat characters===&lt;br /&gt;
echo an &amp;#039;=&amp;#039; sign then use the loop feature of sed to run round a loop a further 79 times replacing what you&amp;#039;ve got with the same thing plus and extra one!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
echo &amp;quot;=&amp;quot; | sed -e :a -e &amp;#039;s/^=\{1,79\}$/&amp;amp;=/;ta&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Convert between lower and upper case using ansi standard===&lt;br /&gt;
This way should be portable and give predictable results&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
LOWER_SID=$(echo &amp;quot;${SID}&amp;quot; | tr &amp;#039;[:upper:]&amp;#039; &amp;#039;[:lower:]&amp;#039;)&lt;br /&gt;
UPPER_SID=$(echo &amp;quot;${SID}&amp;quot; | tr &amp;#039;[:lower:]&amp;#039; &amp;#039;[:upper:]&amp;#039;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Use sed to delete the first line of a file or command output printing from the second line onwards===&lt;br /&gt;
Actually deceptively simple. Example remove the header from df output.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
df -k | sed 1d&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
As a useful extension, suppose TO_DATA_DIR contains multiple directories, this will total the free space for all relevant filesystems&amp;lt;br /&amp;gt;&lt;br /&gt;
This one is specific to AIX, for other Unixes and Linux, use $4 instead of $3.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SPACE_AVAILABLE=$(df -k $TO_DATA_DIR | sed 1d | awk &amp;#039;BEGIN {i=0} {i=i+$3} END {print i}&amp;#039;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Use sed to munge a controlfile into submission!===&lt;br /&gt;
* delete comment lines&lt;br /&gt;
* delete all lines after the one starting with a semicolon&lt;br /&gt;
* delete all blank lines&lt;br /&gt;
* change reuse to set&lt;br /&gt;
* change archivelog (with word boundaries) to noarchivelog&lt;br /&gt;
* change old sid to new sid&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sqlplus -s / as sysdba&amp;lt;&amp;lt;&amp;#039;EOSQL&amp;#039; &amp;gt;/dev/null&lt;br /&gt;
alter database backup controlfile to trace as &amp;#039;/tmp/regenerate_controlfile.sql&amp;#039; reuse resetlogs;&lt;br /&gt;
EOSQL&lt;br /&gt;
OLDSID=&amp;#039;PROD&amp;#039;&lt;br /&gt;
NEWSID=&amp;#039;TEST&amp;#039;&lt;br /&gt;
sed  -e &amp;#039;/^--/d&amp;#039; -e &amp;#039;/^\;/q&amp;#039; -e &amp;#039;/^ *$/d&amp;#039; -e &amp;#039;s/REUSE/SET/&amp;#039; -e &amp;#039;s/\&amp;lt;ARCHIVELOG\&amp;gt;/NOARCHIVELOG/&amp;#039; -e &amp;#039;s/\&amp;quot;&amp;#039;${OLDSID}&amp;#039;\&amp;quot;/\&amp;quot;&amp;#039;${NEWSID}&amp;#039;\&amp;quot;/&amp;#039; /tmp/regenerate_controlfile.sql&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Find all files where a certain text does not exist===&lt;br /&gt;
Mostly we want to search for files containing a particular string but how to find those files that do not contain some text.&amp;lt;br /&amp;gt;&lt;br /&gt;
Using xargs instead of -exec forces the filename to be printed. -H should do this but doesn&amp;#039;t seem to in this case.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
find . -name &amp;quot;*cfg&amp;quot; | xargs grep -H -c TO_CV_HOST {} \; | grep &amp;#039;:0$&amp;#039; | cut -d: -f1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Use tar and gzip to copy files more efficiently across network between hosts===&lt;br /&gt;
From the destination server, this will connect to the source, tar up each file and pull it back to the current server&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ssh oracle@hn5211 &amp;quot;cd /oracle/ora_data4/iten3/ &amp;amp;&amp;amp; tar -cf - . | gzip &amp;quot; | ( cd /oracle/ora_data2/iten/ &amp;amp;&amp;amp; gunzip -c | tar -xvf - . )&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===double hash and double percent in shell variables to trim off characters from variables===&lt;br /&gt;
&amp;lt;nowiki&amp;gt;#&amp;lt;/nowiki&amp;gt;  - trims everything from the start of line till the FIRST occurrence of following character (abstemious) :-)&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;nowiki&amp;gt;##&amp;lt;/nowiki&amp;gt; - trims everything from the start of line till the LAST occurrence of following character (greedy)&amp;lt;br /&amp;gt;&lt;br /&gt;
%  - trims everything from the end of line backwards till the FIRST occurrence of following character (abstemious)&amp;lt;br /&amp;gt;&lt;br /&gt;
%% - trims everything from the end of line backwards till the LAST occurrence of following character (greedy)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
FILENAME=&amp;quot;/home/bey9at77/hello.txt&amp;quot;&lt;br /&gt;
FILE_STUB1=${FILENAME##*/}&lt;br /&gt;
FILE_STUB=${FILE_STUB1%.*}&lt;br /&gt;
echo $FILE_STUB&lt;br /&gt;
hello&lt;br /&gt;
FILE_EXT=${FILENAME##*.}&lt;br /&gt;
echo $FILE_EXT&lt;br /&gt;
txt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;nowiki&amp;gt;#&amp;lt;/nowiki&amp;gt; - remove prefix reluctantly&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;nowiki&amp;gt;##&amp;lt;/nowiki&amp;gt; - remove prefix greedily&amp;lt;br /&amp;gt;&lt;br /&gt;
% - remove suffix reluctantly&amp;lt;br /&amp;gt;&lt;br /&gt;
%% - remove suffix greedily&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
words=&amp;quot;do.re.mi&amp;quot;&lt;br /&gt;
&lt;br /&gt;
echo ${words#*.}&lt;br /&gt;
&lt;br /&gt;
echo ${words##*.}&lt;br /&gt;
&lt;br /&gt;
echo ${words%.*}&lt;br /&gt;
&lt;br /&gt;
echo ${words%%.*}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===The best shell script ever. An example of how scripting should be done===&lt;br /&gt;
It was written by someone at Oracle. Unfortunately (s)he did not put any author comment in it. Also unfortunately I cannot show it here as it is protected behind Oracles support website.&amp;lt;br /&amp;gt;&lt;br /&gt;
If you have an Oracle Metalink id, you can get the complete script [https://support.oracle.com/epmos/faces/DocumentDisplay?id=949322.1 here]&amp;lt;br /&amp;gt;&lt;br /&gt;
Here is a snippet of a function that demonstrates proper commenting and a very good style.&amp;lt;br &amp;gt;&lt;br /&gt;
The script is called physru.sh and upgrades an Oracle database in a rolling upgrade fashion by using a physical standby.&amp;lt;br /&amp;gt;&lt;br /&gt;
There are 4500 lines in the full script but it is so easy to read and understand because of the way it&amp;#039;s written, it&amp;#039;s like a breath of fresh air. Well done whoever you are!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
###############################################################################&lt;br /&gt;
# NAME:        wait_mrp_active&lt;br /&gt;
#&lt;br /&gt;
# DESCRIPTION: &lt;br /&gt;
#   Wait for $MRP_START_TIMEOUT minutes to confirm that the MRP is active.  If&lt;br /&gt;
#   we can&amp;#039;t detect an active MRP, abort the script with an error.&lt;br /&gt;
#&lt;br /&gt;
# INPUT(S):&lt;br /&gt;
#   Arguments:&lt;br /&gt;
#     $1: database user&lt;br /&gt;
#     $2: user password&lt;br /&gt;
#     $3: tns service name&lt;br /&gt;
#     $4: database unique name&lt;br /&gt;
#&lt;br /&gt;
#   Globals:&lt;br /&gt;
#     None&lt;br /&gt;
#&lt;br /&gt;
# RETURN:&lt;br /&gt;
#   None&lt;br /&gt;
#&lt;br /&gt;
###############################################################################&lt;br /&gt;
wait_mrp_active()&lt;br /&gt;
{&lt;br /&gt;
  display &amp;quot;confirming media recovery is running&amp;quot;&lt;br /&gt;
  l_wma_status=1&lt;br /&gt;
  l_wma_curtime=`perl -e &amp;#039;print int(time)&amp;#039;`&lt;br /&gt;
  l_wma_exptime=`expr $MRP_START_TIMEOUT &amp;quot;*&amp;quot; 60`&lt;br /&gt;
  l_wma_maxtime=`expr $l_wma_curtime + $l_wma_exptime`&lt;br /&gt;
  while [ &amp;quot;$l_wma_curtime&amp;quot; -lt &amp;quot;$l_wma_maxtime&amp;quot; ]&lt;br /&gt;
  do&lt;br /&gt;
    is_mrp_running $1 $2 $3 $4&lt;br /&gt;
    if [ &amp;quot;$?&amp;quot; -gt &amp;quot;0&amp;quot; ]; then&lt;br /&gt;
      l_wma_status=0&lt;br /&gt;
      break&lt;br /&gt;
    fi&lt;br /&gt;
&lt;br /&gt;
    sleep $MRP_START_INTERVAL&lt;br /&gt;
    l_wma_curtime=`perl -e &amp;#039;print int(time)&amp;#039;`&lt;br /&gt;
  done&lt;br /&gt;
  chkerr $l_wma_status &amp;quot;could not detect an active MRP after $MRP_START_TIMEOUT minutes&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===split variable (eg. filename) into separate variables using set===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
FILENAME=&amp;quot;split_this_into_bits&amp;quot;&lt;br /&gt;
set $(echo ${FILENAME} | sed &amp;#039;s/_/ /g&amp;#039;)&lt;br /&gt;
echo $4 $3 $2 $1&lt;br /&gt;
bits into this split&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Centre align text on a line in bash shell===&lt;br /&gt;
Doesn&amp;#039;t work in Korn shell due to %*s&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#COLUMNS=$(tput cols)   # width of the current window&lt;br /&gt;
COLUMNS=80&lt;br /&gt;
title=&amp;quot;Hello world!&amp;quot;&lt;br /&gt;
printf &amp;quot;%*s\n&amp;quot; $(((${#title}+$COLUMNS)/2)) &amp;quot;$title&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
and as a one-liner&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
printf &amp;quot;%*s\n&amp;quot; $(( ( $(echo $* | wc -c ) + 80 ) / 2 )) &amp;quot;$*&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This works in Korn shell...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
TITLE=&amp;quot;$1&amp;quot;&lt;br /&gt;
LINEWIDTH=80&lt;br /&gt;
&lt;br /&gt;
LPAD=$(((${#TITLE}+$LINEWIDTH)/2))&lt;br /&gt;
printf %${LPAD}s &amp;quot;$TITLE&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Right justify text (or repeat characters) on a line with leader dots!===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
function rpadwait {&lt;br /&gt;
    text=$1&lt;br /&gt;
# -------------------------&lt;br /&gt;
# suppress newline for echo&lt;br /&gt;
# -------------------------&lt;br /&gt;
N=&lt;br /&gt;
C=&lt;br /&gt;
if echo &amp;quot;\c&amp;quot; | grep c &amp;gt;/dev/null 2&amp;gt;&amp;amp;1; then&lt;br /&gt;
    N=&amp;#039;-n&amp;#039;&lt;br /&gt;
else&lt;br /&gt;
    C=&amp;#039;\c&amp;#039;&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
    echo ${N} &amp;quot;${text}${C}&amp;quot; | sed -e :a -e &amp;#039;s/^.\{1,80\}$/&amp;amp;\./;ta&amp;#039;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===cron jobs not submitted - daemon run out of child processes?===&lt;br /&gt;
Sometimes have problems with NFS mounts and this causes cron jobs to hang. If they are scheduled to run regularly, eventually cron will no longer be able to start any more jobs.&amp;lt;br /&amp;gt;&lt;br /&gt;
* Check the cron log &amp;#039;&amp;#039;&amp;#039;/var/adm/cron/log&amp;#039;&amp;#039;&amp;#039; to see if there are any errors or other messages around the time the jobs should run.&lt;br /&gt;
If cron has hit its process limit (default 100), it will try again after a number of seconds (default 60).&amp;lt;br /&amp;gt;&lt;br /&gt;
Both the number of jobs and wait time are configured in the file &amp;#039;&amp;#039;&amp;#039;/var/adm/cron/queuedefs&amp;#039;&amp;#039;&amp;#039;. If it is unusual for cron to be running so many jobs, you can check the process table to view the jobs cron has created. These jobs will have parent process id (PPID) of the cron daemon.&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ ps -ef | grep cron | grep -v grep&lt;br /&gt;
    root  6750314        1   0   Apr 24      -  3:39 /usr/sbin/cron&lt;br /&gt;
solax025:root[/home/root]# ps -T 6750314&lt;br /&gt;
      PID    TTY  TIME CMD&lt;br /&gt;
  6750314      -  3:39 cron&lt;br /&gt;
 21168296      -  0:00     \--bsh&lt;br /&gt;
 58982414      -  0:00         \--sadc&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
In this example, we only have 1 job running&lt;br /&gt;
&lt;br /&gt;
===Find long-running processes with a cron job===&lt;br /&gt;
Processes running longer than 24 hours have a date instead of a start time...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
58 08,14 * * * /home/ibmtools/scripts/oracle/dosh -vc &amp;quot;ps -ef|grep &amp;#039;ibmtools/scripts/oracle&amp;#039;|perl -nae &amp;#039;print if \$F[4] !~/:/&amp;#039;&amp;quot; &amp;gt;/tmp/lrp.txt; [[ $(grep -c ibmtools /tmp/lrp.txt) -ne 0 ]] &amp;amp;&amp;amp; cat /tmp/lrp.txt|mailx -s &amp;#039;*** long running processes - please check ***&amp;#039; reporting@companymail.com&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Process command line arguments in shell===&lt;br /&gt;
Borrowed from Mozilla Firefox installer&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
## Command line arg defaults&lt;br /&gt;
##&lt;br /&gt;
moz_debug=0&lt;br /&gt;
moz_debugger=&amp;quot;&amp;quot;&lt;br /&gt;
moz_debugger_args=&amp;quot;&amp;quot;&lt;br /&gt;
#&lt;br /&gt;
##&lt;br /&gt;
## Parse the command line&lt;br /&gt;
##&lt;br /&gt;
while [ $# -gt 0 ]&lt;br /&gt;
do&lt;br /&gt;
  case $1 in&lt;br /&gt;
    -g | --debug)&lt;br /&gt;
      moz_debug=1&lt;br /&gt;
      shift&lt;br /&gt;
      ;;&lt;br /&gt;
    -d | --debugger)&lt;br /&gt;
      moz_debugger=$2;&lt;br /&gt;
      if [ &amp;quot;${moz_debugger}&amp;quot; != &amp;quot;&amp;quot; ]; then&lt;br /&gt;
	shift 2&lt;br /&gt;
      else&lt;br /&gt;
        echo &amp;quot;-d requires an argument&amp;quot;&lt;br /&gt;
        exit 1&lt;br /&gt;
      fi&lt;br /&gt;
      ;;&lt;br /&gt;
    -a | --debugger-args)&lt;br /&gt;
      moz_debugger_args=$2;&lt;br /&gt;
      if [ &amp;quot;${moz_debugger_args}&amp;quot; != &amp;quot;&amp;quot; ]; then&lt;br /&gt;
	shift 2&lt;br /&gt;
      else&lt;br /&gt;
        echo &amp;quot;-a requires an argument&amp;quot;&lt;br /&gt;
        exit 1&lt;br /&gt;
      fi&lt;br /&gt;
      ;;&lt;br /&gt;
    *)&lt;br /&gt;
      break;&lt;br /&gt;
      ;;&lt;br /&gt;
  esac&lt;br /&gt;
done&lt;br /&gt;
#&lt;br /&gt;
##&lt;br /&gt;
## Program name given in $1&lt;br /&gt;
##&lt;br /&gt;
if [ $# -gt 0 ]&lt;br /&gt;
then&lt;br /&gt;
	MOZ_PROGRAM=$1&lt;br /&gt;
	shift&lt;br /&gt;
fi&lt;br /&gt;
##&lt;br /&gt;
## Program not given, try to guess a default&lt;br /&gt;
##&lt;br /&gt;
if [ -z &amp;quot;$MOZ_PROGRAM&amp;quot; ]&lt;br /&gt;
then&lt;br /&gt;
	##&lt;br /&gt;
	## Try this script&amp;#039;s name with &amp;#039;-bin&amp;#039; appended&lt;br /&gt;
	##&lt;br /&gt;
	if [ -x &amp;quot;$MOZ_DEFAULT_NAME&amp;quot; ]&lt;br /&gt;
	then&lt;br /&gt;
		MOZ_PROGRAM=$MOZ_DEFAULT_NAME&lt;br /&gt;
	##&lt;br /&gt;
	## Try mozilla-bin&lt;br /&gt;
	## &lt;br /&gt;
	elif [ -x &amp;quot;$MOZ_APPRUNNER_NAME&amp;quot; ]&lt;br /&gt;
	then&lt;br /&gt;
		MOZ_PROGRAM=$MOZ_APPRUNNER_NAME&lt;br /&gt;
	fi&lt;br /&gt;
fi&lt;br /&gt;
#&lt;br /&gt;
#&lt;br /&gt;
##&lt;br /&gt;
## Make sure the program is executable&lt;br /&gt;
##&lt;br /&gt;
if [ ! -x &amp;quot;$MOZ_PROGRAM&amp;quot; ]&lt;br /&gt;
then&lt;br /&gt;
	moz_bail &amp;quot;Cannot execute $MOZ_PROGRAM.&amp;quot;&lt;br /&gt;
fi&lt;br /&gt;
#&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Carry XWindows settings across sessions===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# ----------------------&lt;br /&gt;
# push XWindows settings&lt;br /&gt;
# ----------------------&lt;br /&gt;
[[ &amp;quot;$(uname)&amp;quot; == &amp;quot;SunOS&amp;quot; ]] &amp;amp;&amp;amp; PATH=/usr/openwin/bin:$PATH&lt;br /&gt;
WHOAMI=$(id | awk -F&amp;#039;)&amp;#039; &amp;#039;{print $1}&amp;#039; | awk -F&amp;#039;(&amp;#039; &amp;#039;{print $2}&amp;#039;)&lt;br /&gt;
xauth list &amp;gt; /tmp/xauth_list_$WHOAMI&lt;br /&gt;
chmod 777 /tmp/xauth_list_$WHOAMI&lt;br /&gt;
&lt;br /&gt;
echo $DISPLAY &amp;gt; /tmp/xdisplay_$WHOAMI&lt;br /&gt;
chmod 777 /tmp/xdisplay_$WHOAMI&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Cross-platform version of whoami===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
WHOAMI=$(id | awk -F&amp;#039;)&amp;#039; &amp;#039;{print $1}&amp;#039; | awk -F&amp;#039;(&amp;#039; &amp;#039;{print $2}&amp;#039;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Set terminal title from command line===&lt;br /&gt;
Put something like this in the .profile&amp;lt;br /&amp;gt;&lt;br /&gt;
-n     do not output the trailing newline&amp;lt;br /&amp;gt;&lt;br /&gt;
-e     enable interpretation of backslash escapes&amp;lt;br /&amp;gt;&lt;br /&gt;
|0     sets title of window and icon&amp;lt;br /&amp;gt;&lt;br /&gt;
|1     sets title of icon only&amp;lt;br /&amp;gt;&lt;br /&gt;
|2     sets title of window only&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
echo -en &amp;quot;\033]0;`hostname`\007&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
echo -en &amp;quot;\033]2;`hostname`\007&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Remove blank lines and comments (also indented ones) from a file===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
awk -F\: &amp;#039;!/^($|[:space:]*#)/ {print $2}&amp;#039; /etc/oratab | sort | uniq&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or as part of a script that removes comments and blank lines from all Korn shell scripts in a directory&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/usr/bin/ksh&lt;br /&gt;
for i in $(ls *ksh); do&lt;br /&gt;
    perl -p -i -e &amp;#039;s/^\s*#[^!]*$//; s/^\s*$//&amp;#039; $i&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Return elements of an array in Korn shell===&lt;br /&gt;
From [http://unix.stackexchange.com/questions/188202/processing-output-from-an-sqlite-db-into-a-ksh-array-with-spaces here]&amp;lt;br /&amp;gt;&lt;br /&gt;
Could be used to separate the columns of an SQL select when returning to the shell&amp;lt;br /&amp;gt;&lt;br /&gt;
This approach eliminates the need to put quotes around text with spaces in it.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
echo $KSH_VERSION&lt;br /&gt;
x=&amp;quot;Red,Yellow is a color,Blue&amp;quot;&lt;br /&gt;
oIFS=$IFS&lt;br /&gt;
IFS=,&lt;br /&gt;
y=($x)&lt;br /&gt;
IFS=$oIFS&lt;br /&gt;
echo ${y[1]}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===A decent Unix Prompt===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
export PS1=&amp;quot;`uname -n`:`whoami`[\${PWD}]# &amp;quot;&lt;br /&gt;
or&lt;br /&gt;
export PS1=&amp;#039;($?) $&amp;#039;ORACLE_SID&amp;quot; &amp;quot;`whoami`&amp;quot;@&amp;quot;`uname -n`&amp;quot;:&amp;quot;&amp;#039;$&amp;#039;PWD&amp;quot;&amp;gt; &amp;quot;&lt;br /&gt;
export EDITOR=vi&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Simple arithmetic===&lt;br /&gt;
pipe the calculation into the shell calculator&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
space_in_kb=$(echo $1 / 1024 | bc)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Calculate the remainder (modulo) of a division calculation&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
if [[ $(echo &amp;quot;${NUMBER} % 2&amp;quot; | bc) -eq 0 ]]; then&lt;br /&gt;
    echo &amp;quot;${NUMBER} is even&amp;quot;&lt;br /&gt;
else&lt;br /&gt;
    echo &amp;quot;${NUMBER} is odd&amp;quot;&lt;br /&gt;
fi&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or do it in awk if scientific notation maybe involved&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
function calc { awk &amp;quot;BEGIN{print $*}&amp;quot;; }&lt;br /&gt;
&lt;br /&gt;
if [[ $(calc &amp;quot;${SPACE_USED} + ${SPACE_AVAILABLE} - ${DATABASE_SIZE&amp;quot;) -le 0 ]]; then&lt;br /&gt;
    echo &amp;quot;NOK&amp;quot;&lt;br /&gt;
fi&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Script encryption and passphrase protection===&lt;br /&gt;
Encrypt a shell script with the ability to execute the encrypted version&lt;br /&gt;
* from [http://www.commandlinefu.com/commands/browse commandlinefu.com]&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
scrypt(){ [ -n &amp;quot;$1&amp;quot; ]&amp;amp;&amp;amp;{ echo &amp;#039;. &amp;lt;(echo &amp;quot;$(tail -n+2 $0|base64 -d|mcrypt -dq)&amp;quot;); exit;&amp;#039;&amp;gt;$1.scrypt;cat $1|mcrypt|base64 &amp;gt;&amp;gt;$1.scrypt;chmod +x $1.scrypt;};}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Virtual host configuration in Apache http.conf===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;VirtualHost *:80&amp;gt;&lt;br /&gt;
        ServerName dbamon&lt;br /&gt;
        DocumentRoot &amp;quot;/Volumes/data/Sites/dbamon_push&amp;quot;&lt;br /&gt;
        &amp;lt;Directory &amp;quot;/Volumes/data/Sites/dbamon_push&amp;quot;&amp;gt;&lt;br /&gt;
                Options Includes FollowSymLinks&lt;br /&gt;
                AllowOverride All&lt;br /&gt;
                Order allow,deny&lt;br /&gt;
                Allow from all&lt;br /&gt;
        &amp;lt;/Directory&amp;gt;&lt;br /&gt;
&amp;lt;/VirtualHost&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
and in /etc/hosts, add...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
127.0.0.1  dbamon&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Mount a website (or any other remote resource) locally using WebDav===&lt;br /&gt;
Redhat/CentOS&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
yum install fuse-davfs2&lt;br /&gt;
or&lt;br /&gt;
yum install wdfs.x86_64&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Debian&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
apt-get install davfs2&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
then...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo mkdir /mnt/webdav  # or whatever you&amp;#039;d like to call the directory&lt;br /&gt;
sudo mount.davfs [-o option[,option]...] device mount_point&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
In man&amp;#039;s terms, that last line would translate to:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
id  #suppose this returns uid=501 and gid=502&lt;br /&gt;
sudo mount.davfs -o 501,502 https://your/web/site /mnt/webdav&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Mac OSX&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
osascript -e &amp;#039; mount volume &amp;quot;http://username:password@webdav.address:portnum&amp;quot; &amp;#039;&lt;br /&gt;
or&lt;br /&gt;
osascript -e &amp;#039; mount volume &amp;quot;http://username@webdav.address:portnum&amp;quot; &amp;#039;&lt;br /&gt;
or&lt;br /&gt;
osascript -e &amp;#039; try mount volume &amp;quot;http://webdav.address:portnum&amp;quot; &amp;#039;&lt;br /&gt;
or&lt;br /&gt;
mount -t webdav http://webdav.address:portnum /mnt/webdav  # this one won&amp;#039;t show up in the Finder Sidebar.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Add current hostname to list of hosts on an xcat server===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
CMD=&amp;quot;nodels&amp;quot;&lt;br /&gt;
HOST=`hostname`&lt;br /&gt;
(echo &amp;quot;$HOST&amp;quot;; $CMD) | while read server&lt;br /&gt;
do&lt;br /&gt;
    echo &amp;quot;server:$server&amp;quot;&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===What is todays &amp;#039;Day Of the Year&amp;#039; number?===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
DOY=`perl -e &amp;#039;print sub{$_[7]}-&amp;gt;(localtime)+1;&amp;#039;`&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Convert Julian day numbers to dates===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
for day in 8 33 36 61 64 91 96 121 126 152 155 182 187 215 218 244 247 274 279 306 309 335 338 365; do date -d &amp;quot;`date +%Y`-01-01 +$(( ${day} - 1 ))days&amp;quot; +%d-%m-%Y; done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Send crontab job output to a date formatted log file===&lt;br /&gt;
This will run a job every 5 minutes and send the output to a file ending with a time in hours and minutes.&amp;lt;br /&amp;gt;&lt;br /&gt;
The thing to note is the escaped percent signs. This is because a % sign is interpreted by cron to mean a newline character. Everything after the first % is treated as input to the program.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
*/5 *  * * * /var/www/cgi-bin/dbamon_collector.ksh       &amp;gt;/tmp/dbamon_collector.log.$(date &amp;quot;+\%H\%M&amp;quot;) 2&amp;gt;&amp;amp;1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Edit crontab file without crontab -e===&lt;br /&gt;
It can happen that you need to add or modify a line in the crontab of many users or across many servers at once.&amp;lt;br /&amp;gt;&lt;br /&gt;
In principle, there&amp;#039;s nothing wrong with modifying the crontab file directly. You just lose the advantages of file locking (and syntax checking) that crontab -e offers.&amp;lt;br /&amp;gt;&lt;br /&gt;
Here we take a backup of the current crontab, print it out, echo an extra command and ask cron to use these as input (thus overwriting the existing crontab file). Just don&amp;#039;t run this close to midnight :-)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
crontab -l &amp;gt; /tmp/crontab.`date &amp;#039;+%Y%m%d&amp;#039;`&lt;br /&gt;
(&lt;br /&gt;
cat /tmp/crontab.`date +&amp;#039;%Y%m%d&amp;#039;`&lt;br /&gt;
echo &amp;quot;02 10 * * * /home/ibmtools/scripts/oracle/export_parfile.ksh -s SID -f JDBEOP1.parfile&amp;quot;&lt;br /&gt;
) | crontab -&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
crontab -l &amp;gt; /tmp/crontab.backup&lt;br /&gt;
crontab -l &amp;gt; /tmp/crontab.$$&lt;br /&gt;
perl -p -i -e &amp;#039;s!backup_send_tsm_dump!backup_export2tsm!g&amp;#039; /tmp/crontab.$$&lt;br /&gt;
crontab /tmp/crontab.$$&lt;br /&gt;
rm /tmp/crontab.$$&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
crontab -l &amp;gt;$HOME/crontab.$(date &amp;#039;+%Y%m%d&amp;#039;)&lt;br /&gt;
crontab -l | perl -p -e &amp;#039;s|/nas/software/oracle/scripts|/oracle/scripts|&amp;#039; | crontab&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Use shell to convert a number in scientific notation to normal===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
var2convert=&amp;#039;1.2345678e3&amp;#039;&lt;br /&gt;
printf -v var2convert &amp;quot;%.f&amp;quot; $var2convert&lt;br /&gt;
echo $var2convert  # magic!&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Check for jobs running longer that 24 hours===&lt;br /&gt;
Run from the management server across all Unix servers. Checks the 5th column in a ps listing. If it doesn&amp;#039;t find a : (time separator), the process is running longer than 24 hours.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# ---------------------------------------&lt;br /&gt;
# report on long running oraibm processes&lt;br /&gt;
# ---------------------------------------&lt;br /&gt;
01 17,14 * * * rm -f /tmp/lrp.txt;/home/ibmtools/scripts/oracle/dosh -vc \&amp;quot;ps -ef|egrep &amp;#039;oraibm|scripts/oracle&amp;#039;&amp;gt;/tmp/lrp.txt;perl -nae &amp;#039;print if \$F[4] !~/:/&amp;#039; /tmp/lrp.txt\&amp;quot; &amp;gt;&amp;gt;/tmp/lrp.txt;[[ $(egrep -c &amp;#039;oraibm|scripts/or&lt;br /&gt;
acle&amp;#039; /tmp/lrp.txt) -ne 0 ]] &amp;amp;&amp;amp; cat /tmp/lrp.txt|mailx -s &amp;#039;*** long running processes - please check ***&amp;#039; bey9at77@mail.com&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Global find and replace with perl (restricted to list of files provided by Unix find command)===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
find . -type f -exec perl -i -pe &amp;#039;s/something/else/g&amp;#039; {} \;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===perl function to make filenames lower case===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
function lower { &lt;br /&gt;
   perl -e &amp;#039;for (@ARGV) { rename $_, lc($_) unless -e lc($_); }&amp;#039; * &lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===From the management server, search the TNS listener port for each database on a server and make an inline substitution in the ITM config files!===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
for i in `/home/ibmtools/scripts/oracle/dosh -c &amp;quot;ls -al /opt/IBM/ITM/config/*rz*cfg|grep -v lrwx&amp;quot;|awk &amp;#039;{print $NF}&amp;#039;`; do&lt;br /&gt;
    server=`echo $i|cut -d_ -f1 | awk -F&amp;#039;/&amp;#039; &amp;#039;{print $NF}&amp;#039;`&lt;br /&gt;
    db=`echo $i|cut -d&amp;#039;.&amp;#039; -f1 | awk -F&amp;#039;_&amp;#039; &amp;#039;{print $NF}&amp;#039;`&lt;br /&gt;
    OH=`ssh $server grep &amp;quot;^$db&amp;quot; /etc/oratab|cut -d: -f2`&lt;br /&gt;
    LISTENERPORT=`ssh $server cat $OH/network/admin/listener.ora|perl -00 -ne &amp;#039;print $1 if /&amp;#039;$db&amp;#039;.*PORT.*=.*(\d{4})/s&amp;#039;`&lt;br /&gt;
    ssh $server perl -p -i.bak -e &amp;#039;s/1521/&amp;#039;$LISTENERPORT&amp;#039;/&amp;#039; $i&lt;br /&gt;
    ssh $server ls -al ${i}*&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Run a job from cron every Nth day of the month===&lt;br /&gt;
Example. Execute a job every third Saturday of the month.&amp;lt;br /&amp;gt;&lt;br /&gt;
Paste this into a file called calenday and put it in /usr/local/bin so it&amp;#039;s (probably) on the PATH&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/usr/bin/ksh&lt;br /&gt;
&lt;br /&gt;
# ix is the week number of the month (&amp;quot;2&amp;quot;nd Friday of the month, &amp;quot;3&amp;quot;rd Tuesday of the month)&lt;br /&gt;
# dy is the day number in Unix format (0 for Sunday, 1 for Monday, ... 6 for Saturday)&lt;br /&gt;
# eg. &amp;quot;calenday 3 6&amp;quot; returns the date of 3rd Saturday of the month.&lt;br /&gt;
&lt;br /&gt;
ix=$1&lt;br /&gt;
dy=$2&lt;br /&gt;
SCHAR=$((($dy*2)+$dy+1))&lt;br /&gt;
ECHAR=$(($SCHAR+1))&lt;br /&gt;
cal `date &amp;#039;+%m %Y&amp;#039;` | egrep &amp;quot;\&amp;lt;[0-9]{1,2}\&amp;gt;&amp;quot; | cut -c${SCHAR}-${ECHAR} | xargs | awk {&amp;#039;print $&amp;#039;$ix&amp;#039;}&amp;#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Now in crontab, you should be able to do something like this:&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
15 20 * * * [[ `calenday 3 6` -eq `/bin/date &amp;#039;+%d&amp;#039;` ]] &amp;amp;&amp;amp; su - oracle -c &amp;quot;run_my_backup.ksh&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will also work on some Unices..&amp;lt;br /&amp;gt;&lt;br /&gt;
We send backups to a special TSM node on the second Friday of each month. This report must run a day later - but that is not guaranteed to be the second Saturday or even the 3rd. So...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
30 12 8-14 * 5 sleep 86400 &amp;amp;&amp;amp; su - oracle -c &amp;quot;/usr/bin/perl -ne &amp;#039;print if /ORX_M_SOL/ .. /^STOP/&amp;#039; /home/oracle/incoming/dbamon_spool_tsm_*.SOL | grep Archive | grep -v Client | mailx -s &amp;#039;Monthly TSM backups&amp;#039; orareport@xxxxxx.com&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ps listing does not show start time after 24 hours===&lt;br /&gt;
But you can see elapsed time using your own ps command&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/usr/bin/ps -eo etime,user,pid,ppid,cpu,start,tty,time,args |tail -n +2|sort&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ps -ef cuts off args cmd column on Solaris===&lt;br /&gt;
====To see more than 80 characters of the last column on Solaris====&lt;br /&gt;
This shows all the individual arguments to the command&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
pargs &amp;lt;pid&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This shows the ps listing in &amp;#039;compatibility&amp;#039; mode (there are more compatibility commands in /usr/xpg4/bin)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/usr/ucb/ps auww&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====To see more than 80 characters of the last column on AIX====&lt;br /&gt;
This shows the full argument listing of a process (NOTE: no minus sign!)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ps eww &amp;lt;pid&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Remove blank / empty lines from vi ===&lt;br /&gt;
Maybe you cut and pasted a file from Windows and it&amp;#039;s full of blank lines and Control-M&amp;#039;s now&amp;lt;br /&amp;gt;&lt;br /&gt;
There are several methods but I think this is the easiest to remember&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
:g/^$/d&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Right pad a variable===&lt;br /&gt;
a function like rpad in SQL but for Shell&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
function rpad {&lt;br /&gt;
text=$1&lt;br /&gt;
padwidth=$2&lt;br /&gt;
padchar=$3&lt;br /&gt;
echo &amp;quot;$text&amp;quot; | sed -e :a -e &amp;#039;s/^.\{1,&amp;#039;$padwidth&amp;#039;\}$/&amp;amp;\&amp;#039;$padchar&amp;#039;/;ta&amp;#039;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Connect to a Windows server from Linux using rdesktop===&lt;br /&gt;
My remmina stopped working so rolled my own. Very simple really. Put this is a shell.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
tsocks rdesktop -z -P -x m -a 16 -d MAIND -u sbarkley -p ****** -r disk:SOL=$HOME/Documents/SOL -g 95% 150.251.112.38 &amp;amp;&lt;br /&gt;
&lt;br /&gt;
where...&lt;br /&gt;
-z    - enables compression&lt;br /&gt;
-P    - enables bitmap caching (saves network traffic)&lt;br /&gt;
-x m  - disables eye-candy features&lt;br /&gt;
-a 16 - reduce colour pallete to 16 colours&lt;br /&gt;
-d    - domain to connect to&lt;br /&gt;
-u    - username&lt;br /&gt;
-p    - password&lt;br /&gt;
-r    - setup a shared folder&lt;br /&gt;
-g    - geometry (use W x H or percentage)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Slight problems with rdesktop not working 100% of the time. Now using xfreerdp. Seems better...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
xfreerdp -g 90% --ignore-certificate --gdi sw -K -d wdcrhbp05 -u oraibm -p &amp;quot;`cat $HOME/scripts/.oraibm.password`&amp;quot; -T &amp;quot;wdcrhbp05_oraibm&amp;quot; --plugin cliprdr --plugin rdpdr --data disk:SOL:/home/bey9at77/Documents/SOL -- --plugin rdpsnd --data alsa -- 150.251.112.25 &amp;amp;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Reset your password bypassing password rules===&lt;br /&gt;
must be done as root&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
echo &amp;quot;user:new_password&amp;quot; | chpasswd&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Sum the sizes of all files of an ls listing===&lt;br /&gt;
It&amp;#039;ll check to see if the sum of filesizes corresponds with the df -g (or h) listing (can get messed up due to open but deleted files)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cd /oracle/export&lt;br /&gt;
df -g .&lt;br /&gt;
find . -name &amp;quot;*dmp*&amp;quot; -ls |  awk &amp;#039;{ SUM += $7} END { print SUM/1024/1024/1024 }&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Mount an iso image under Linux===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
mkdir -p /mnt/cdrom&lt;br /&gt;
mount -o loop /dev/cdrom /mnt/cdrom&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===How many processors on the machine?===&lt;br /&gt;
* AIX&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
lsdev -C|grep Process|wc -l&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Solaris&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
psrinfo -v|grep &amp;quot;Status of processor&amp;quot;|wc -l&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Linux&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cat /proc/cpuinfo|grep processor|wc -l&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Quick, simple, understandable example of how to use RRDTool===&lt;br /&gt;
* [[RRDTool]]&lt;br /&gt;
&lt;br /&gt;
===Use expect to respond automatically to interactive programs===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/usr/bin/expect -f&lt;br /&gt;
spawn /usr/tivoli/tsm/client/oracle/bin64/tdpoconf passw -tdpo_optfile=/oracle/[lindex $argv 0]/admin/tdpo.opt&lt;br /&gt;
expect &amp;quot;assword:&amp;quot; {send &amp;quot;password\r&amp;quot;}&lt;br /&gt;
expect &amp;quot;assword:&amp;quot; {send &amp;quot;password\r&amp;quot;}&lt;br /&gt;
expect &amp;quot;assword:&amp;quot; {send &amp;quot;password\r&amp;quot;}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Use expect to allow file copy with scp (if ssh keys are not an option)===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/usr/bin/expect -f&lt;br /&gt;
spawn scp /home/oracle/.profile oracle@hn512:/tmp/prfl&lt;br /&gt;
set pass &amp;quot;thepassword&amp;quot;&lt;br /&gt;
expect {&lt;br /&gt;
        password: {send &amp;quot;$pass\r&amp;quot; ; exp_continue}&lt;br /&gt;
        eof exit&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Within a shell script set up simultaneous output to both terminal and a file using a FIFO (named pipes)===&lt;br /&gt;
or &amp;quot;How to send shell output to screen/stdout as well as to a logfile using tee and redirection with exec&amp;quot;&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
examples [http://www.unix.com/shell-programming-and-scripting/85584-redirect-within-ksh.html here on unix.com]&lt;br /&gt;
* general info on redirections [http://www.catonmat.net/blog/bash-one-liners-explained-part-three/ here at catonmat.net]&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/ksh&lt;br /&gt;
&lt;br /&gt;
REDIR=test.redir&lt;br /&gt;
FIFO=test.pipe&lt;br /&gt;
[[ -e $FIFO ]] || mkfifo $FIFO&lt;br /&gt;
&lt;br /&gt;
# make a new channel(3) and copy channel 1&amp;#039;s destination as its own (does NOT POINT TO channel 1&amp;#039;s destination)&lt;br /&gt;
# this allows the normal output to continue to STDOUT but also get printed to whatever file is attached to channel 3&lt;br /&gt;
exec 3&amp;gt;&amp;amp;1&lt;br /&gt;
&lt;br /&gt;
# anything coming in on the pipe, send it to $REDIR and to channel 3&lt;br /&gt;
tee $REDIR &amp;lt;$FIFO &amp;gt;&amp;amp;3 &amp;amp;&lt;br /&gt;
&lt;br /&gt;
# redirect STDOUT to the pipe&lt;br /&gt;
exec &amp;gt; $FIFO&lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;going to default output&amp;quot;&lt;br /&gt;
echo &amp;quot;forcing to channel 1&amp;quot; &amp;gt;&amp;amp;1&lt;br /&gt;
echo &amp;quot;forcing to channel 2&amp;quot; &amp;gt;&amp;amp;2&lt;br /&gt;
echo &amp;quot;forcing to channel 3&amp;quot; &amp;gt;&amp;amp;3&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====More elaborate example====&lt;br /&gt;
found [http://stackoverflow.com/questions/2288939/create-a-pipe-that-writes-to-multiple-files-tee here on stackoverflow]&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/sh&lt;br /&gt;
&lt;br /&gt;
# Author: Harvey Chapman &amp;lt;hchapman _AT_ 3gfp.com&amp;gt;&lt;br /&gt;
# Description: POSIX shell functions that can be used with tee to simultaneously put&lt;br /&gt;
#              stderr and stdout to both a file and stdout&lt;br /&gt;
#&lt;br /&gt;
# Based on:&lt;br /&gt;
#    Re: How to redirect stderr and stdout to a file plus display at the same time&lt;br /&gt;
#    http://www.travishartwell.net/blog/2006/08/19_2220&lt;br /&gt;
&lt;br /&gt;
#&lt;br /&gt;
# Original example function from Travis Hartwell&amp;#039;s blog.&lt;br /&gt;
# Note: I&amp;#039;ve made minor changes to it.&lt;br /&gt;
example()&lt;br /&gt;
{&lt;br /&gt;
  OUTPUT_LOG=output.log&lt;br /&gt;
  OUTPUT_PIPE=output.pipe&lt;br /&gt;
&lt;br /&gt;
  # This should really be -p to test that it&amp;#039;s a pipe.&lt;br /&gt;
  if [ ! -e $OUTPUT_PIPE ]; then&lt;br /&gt;
      mkfifo $OUTPUT_PIPE&lt;br /&gt;
  fi&lt;br /&gt;
&lt;br /&gt;
  # This should really be -f to test that it&amp;#039;s a regular file.&lt;br /&gt;
  if [ -e $OUTPUT_LOG ]; then&lt;br /&gt;
      rm $OUTPUT_LOG&lt;br /&gt;
  fi&lt;br /&gt;
&lt;br /&gt;
  exec 3&amp;gt;&amp;amp;1 4&amp;gt;&amp;amp;2&lt;br /&gt;
  tee $OUTPUT_LOG &amp;lt; $OUTPUT_PIPE &amp;gt;&amp;amp;3 &amp;amp;&lt;br /&gt;
  tpid=$!&lt;br /&gt;
  exec &amp;gt; $OUTPUT_PIPE 2&amp;gt;&amp;amp;1&lt;br /&gt;
&lt;br /&gt;
  echo &amp;quot;This is on standard out&amp;quot;&lt;br /&gt;
  echo &amp;quot;This is on standard err&amp;quot; &amp;gt;&amp;amp;2&lt;br /&gt;
&lt;br /&gt;
  exec 1&amp;gt;&amp;amp;3 3&amp;gt;&amp;amp;- 2&amp;gt;&amp;amp;4 4&amp;gt;&amp;amp;-&lt;br /&gt;
  wait $tpid&lt;br /&gt;
&lt;br /&gt;
  rm $OUTPUT_PIPE&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
# A slightly reduced version of example()&lt;br /&gt;
example2()&lt;br /&gt;
{&lt;br /&gt;
  OUTPUT_LOG=output.log&lt;br /&gt;
  OUTPUT_PIPE=output.pipe&lt;br /&gt;
&lt;br /&gt;
  rm -f $OUTPUT_PIPE&lt;br /&gt;
  mkfifo $OUTPUT_PIPE&lt;br /&gt;
  rm -f $OUTPUT_LOG&lt;br /&gt;
&lt;br /&gt;
  tee $OUTPUT_LOG &amp;lt; $OUTPUT_PIPE &amp;amp;&lt;br /&gt;
  tpid=$!&lt;br /&gt;
&lt;br /&gt;
  exec 3&amp;gt;&amp;amp;1 4&amp;gt;&amp;amp;2 &amp;gt;$OUTPUT_PIPE 2&amp;gt;&amp;amp;1&lt;br /&gt;
&lt;br /&gt;
  echo &amp;quot;This is on standard out&amp;quot;&lt;br /&gt;
  echo &amp;quot;This is on standard err&amp;quot; &amp;gt;&amp;amp;2&lt;br /&gt;
&lt;br /&gt;
  exec 1&amp;gt;&amp;amp;3 3&amp;gt;&amp;amp;- 2&amp;gt;&amp;amp;4 4&amp;gt;&amp;amp;-&lt;br /&gt;
  wait $tpid&lt;br /&gt;
  rm -f $OUTPUT_PIPE&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
#&lt;br /&gt;
# Logging methods based on above. See the example below for how to use them.&lt;br /&gt;
#&lt;br /&gt;
&lt;br /&gt;
# Usage: start_logging [delete_existing_logfile]&lt;br /&gt;
start_logging()&lt;br /&gt;
{&lt;br /&gt;
  # Check to see if OUTPUT_LOG and OUTPUT_PIPE need to be defined.&lt;br /&gt;
  if [ -z &amp;quot;$OUTPUT_LOG&amp;quot; ]; then&lt;br /&gt;
    OUTPUT_LOG=output.log&lt;br /&gt;
  fi&lt;br /&gt;
  if [ -z &amp;quot;$OUTPUT_PIPE&amp;quot; ]; then&lt;br /&gt;
    OUTPUT_PIPE=output.pipe&lt;br /&gt;
  fi&lt;br /&gt;
  # Make sure that we&amp;#039;re not already logging.&lt;br /&gt;
  if [ -n &amp;quot;$OUTPUT_PID&amp;quot; ]; then&lt;br /&gt;
    echo &amp;quot;Logging already started!&amp;quot;&lt;br /&gt;
    return 1&lt;br /&gt;
  fi&lt;br /&gt;
&lt;br /&gt;
  # Always remove the log and pipe first.&lt;br /&gt;
  rm -f $OUTPUT_PIPE&lt;br /&gt;
  # Delete the logfile first if told to.&lt;br /&gt;
  if [ &amp;quot;$1&amp;quot; = delete_existing_logfile ]; then&lt;br /&gt;
    rm -f $OUTPUT_LOG&lt;br /&gt;
  fi&lt;br /&gt;
&lt;br /&gt;
  mkfifo $OUTPUT_PIPE&lt;br /&gt;
  tee -a $OUTPUT_LOG &amp;lt; $OUTPUT_PIPE &amp;amp;&lt;br /&gt;
  OUTPUT_PID=$!&lt;br /&gt;
&lt;br /&gt;
  exec 3&amp;gt;&amp;amp;1 4&amp;gt;&amp;amp;2 &amp;gt;$OUTPUT_PIPE 2&amp;gt;&amp;amp;1&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
stop_logging()&lt;br /&gt;
{&lt;br /&gt;
  # Make sure that we&amp;#039;re currently logging.&lt;br /&gt;
  if [ -z &amp;quot;$OUTPUT_PID&amp;quot; ]; then&lt;br /&gt;
    echo &amp;quot;Logging not yet started!&amp;quot;&lt;br /&gt;
    return 1&lt;br /&gt;
  fi&lt;br /&gt;
  exec 1&amp;gt;&amp;amp;3 3&amp;gt;&amp;amp;- 2&amp;gt;&amp;amp;4 4&amp;gt;&amp;amp;-&lt;br /&gt;
  wait $OUTPUT_PID&lt;br /&gt;
  rm -f $OUTPUT_PIPE&lt;br /&gt;
  unset OUTPUT_PID&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
example3()&lt;br /&gt;
{&lt;br /&gt;
  start_logging&lt;br /&gt;
  #start_logging delete_existing_logfile&lt;br /&gt;
  echo &amp;quot;This is on standard out&amp;quot;&lt;br /&gt;
  echo &amp;quot;This is on standard err&amp;quot; &amp;gt;&amp;amp;2&lt;br /&gt;
  stop_logging&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===RedHat root filesystem has gone read-only===&lt;br /&gt;
* [http://www.unixarena.com/2013/09/redhat-linux-how-to-fix-read-only-root.html How to fix read only root file system]&lt;br /&gt;
&lt;br /&gt;
===Kill all processes for a user===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
for prc in `ps -ef | grep -E &amp;quot;^ +[o]racle&amp;quot; | awk &amp;#039;{print $2}&amp;#039;`; do&lt;br /&gt;
    kill $prc&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===isRGHere===&lt;br /&gt;
Checks if resource group is on this leg of an HACMP cluster. Returns 0 if true else 1.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/usr/bin/ksh&lt;br /&gt;
&lt;br /&gt;
SCRIPT=`basename $0`&lt;br /&gt;
&lt;br /&gt;
function rctest&lt;br /&gt;
{&lt;br /&gt;
exitcode=$1&lt;br /&gt;
msg=$2&lt;br /&gt;
if [ $exitcode -ne 0 ]; then&lt;br /&gt;
        echo &amp;quot;********************************************************************************&amp;quot;&lt;br /&gt;
        echo &amp;quot;\nScript $SCRIPT finished with errors.&amp;quot;&lt;br /&gt;
        echo &amp;quot;$msg.&amp;quot;&lt;br /&gt;
        echo &amp;quot;Returncode : $exitcode.&amp;quot;&lt;br /&gt;
        echo &amp;quot;\n********************************************************************************&amp;quot;&lt;br /&gt;
&lt;br /&gt;
        fi&lt;br /&gt;
exit $exitcode&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
RGINFO=/usr/es/sbin/cluster/utilities/clRGinfo&lt;br /&gt;
[[ ! -f $RGINFO ]] &amp;amp;&amp;amp;  rctest 1 &amp;quot;clRGinfo not found&amp;quot;&lt;br /&gt;
&lt;br /&gt;
if [ $# -eq 1 ]&lt;br /&gt;
then&lt;br /&gt;
        RG=`echo $1 | cut -c 1-14`&lt;br /&gt;
else&lt;br /&gt;
        rctest 10  &amp;quot;Usage: `basename $0` &amp;lt;RG name&amp;gt;&amp;quot;&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
$RGINFO |grep -qwp $RG ||  rctest 9 &amp;quot;$RG is not defined&amp;quot;&lt;br /&gt;
&lt;br /&gt;
THISNODE=`/usr/es/sbin/cluster/utilities/get_local_nodename | cut -c 1-14`&lt;br /&gt;
$RGINFO |grep -wp $RG |grep -w $THISNODE |grep -wq ONLINE&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===AIX: add a user to a group===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
chgrpmem -m + oracle ibmtls&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Find swear words in scripts by comparing it to a list found on the internet===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
wget &amp;quot;http://www.bannedwordlist.com/lists/swearWords.csv&amp;quot; -O /tmp/s ; for word in $(cat /tmp/s | sed -e &amp;#039;s/ /_/g&amp;#039; -e &amp;#039;s/,/ /g&amp;#039;) ; do grep -wR $word *; done | less&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===grep -p (for paragraph) works on AIX but not on Linux or Solaris===&lt;br /&gt;
Use awk instead&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
awk &amp;#039;BEGIN {FS=&amp;quot;\n&amp;quot; RS=&amp;quot;\n\n&amp;quot;} /search pattern/ { do something }&amp;#039; &amp;lt;file&amp;gt;&lt;br /&gt;
/usr/xpg4/bin/awk &amp;#039;BEGIN {RS=&amp;quot;\n\n&amp;quot;;FS=&amp;quot;\n&amp;quot;} /AGRHDWQ1/ {print $2}&amp;#039; dsm.sys | awk &amp;#039;{print $NF}&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
this prints the last word of the second &amp;#039;&amp;#039;line&amp;#039;&amp;#039; in the paragraph in dsm.sys that contains the search term AGRHDWQ1.&amp;lt;br /&amp;gt;&lt;br /&gt;
Or slightly simpler...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
awk -v RS=&amp;#039;&amp;#039; &amp;#039;/NHAPPLP1/&amp;#039; /etc/tsm/dsm.sys     # (use /usr/xpg4/bin/awk on Solaris)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or, case insensitively:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
awk -v RS=&amp;#039;&amp;#039; &amp;#039;tolower($0) ~/so_u_clubqa_orx_d_cab/&amp;#039; /etc/tsm/dsm.sys&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Using -v means you don&amp;#039;t have to use a BEGIN section.&lt;br /&gt;
&lt;br /&gt;
===debug/redirect log of a shell===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/usr/bin/ksh&lt;br /&gt;
exec 2&amp;gt;/tmp/mytest&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Different ways of Iteration in korn shell with a while loop===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
IFS=&amp;quot;|&amp;quot;&lt;br /&gt;
exec 0&amp;lt;$statfile&lt;br /&gt;
while read host db started stopped&lt;br /&gt;
do&lt;br /&gt;
    rrdfile=&amp;quot;export_duration_${host}_${db}.rrd&amp;quot;&lt;br /&gt;
    $RRDTOOL update ${RRDDIR}/${rrdfile} $started:$started $stopped&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
while read host db started stopped&lt;br /&gt;
do&lt;br /&gt;
    rrdfile=&amp;quot;export_duration_${host}_${db}.rrd&amp;quot;&lt;br /&gt;
    $RRDTOOL update ${RRDDIR}/${rrdfile} $started:$started $stopped&lt;br /&gt;
done &amp;lt;statfile&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    cat $statfile | sort -nk4 | while IFS=\| read host db type started stopped&lt;br /&gt;
    do&lt;br /&gt;
        [[ &amp;quot;$stopped&amp;quot; == &amp;quot;&amp;quot; ]] &amp;amp;&amp;amp; continue&lt;br /&gt;
        rrdfile=&amp;quot;export_duration_${host}_${db}.rrd&amp;quot;&lt;br /&gt;
        $RRDTOOL update ${RRDDIR}/${rrdfile} ${started}:${started}:${stopped}&lt;br /&gt;
        [[ $? -ne 0 ]] &amp;amp;&amp;amp; echo &amp;quot;nok: $?&amp;quot;&lt;br /&gt;
    done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Filesystem 100% full, what&amp;#039;s taking up all the space?===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
find /oracle/endur -xdev -ls|sort -nr +6|head&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/dev/esb01fs010001      1.00      0.00  100%     1838    69% /oracle&lt;br /&gt;
beuxdsysesb01:root[/root]# cd /oracle&lt;br /&gt;
beuxdsysesb01:root[/oracle]# du -gsx * | sort -n&lt;br /&gt;
0.00    checkpoints&lt;br /&gt;
0.00    flash_recovery_area&lt;br /&gt;
0.00    lost+found&lt;br /&gt;
0.00    oraInst.loc&lt;br /&gt;
0.00    oraInventory&lt;br /&gt;
0.09    admin&lt;br /&gt;
0.99    diag&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
cd  diag and repeat until culprits are found&lt;br /&gt;
&lt;br /&gt;
===Show paged memory hogs on AIX===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
svmon -Pt20 | perl -e &amp;#039;while(&amp;lt;&amp;gt;){print if($.==2||$&amp;amp;&amp;amp;&amp;amp;!$s++);$.=0 if(/^-+$/)}&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Capitalise the first letter of a word in Korn Shell===&lt;br /&gt;
Not as easy as it sounds if it needs to work in non-ksh93 shells&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
function capit { &lt;br /&gt;
    typeset -u first&lt;br /&gt;
    first=${1%&amp;quot;${1#?}&amp;quot;}&lt;br /&gt;
    printf &amp;quot;%s\n&amp;quot; &amp;quot;${first}${1#?}&amp;quot;&lt;br /&gt;
    return 0&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or maybe more neatly done in Perl...&amp;lt;br /&amp;gt;&lt;br /&gt;
This will capitalise each word in a sentence passed into it&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
function capit { &lt;br /&gt;
    echo &amp;quot;$1&amp;quot; |  perl -pe &amp;quot;s/([\w&amp;#039;]+)/\u\L\1/g&amp;quot;&lt;br /&gt;
    return 0&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Remove / rename a directory / file containing weird control characters===&lt;br /&gt;
Use ls with -i to see inode listing&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ls -bali&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Use find with -inum to get the filename and -exec to remove it&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
find . -inum &amp;lt;inode from ls listing&amp;gt; -exec rm -f {} \;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Run a local script on a remote host===&lt;br /&gt;
Doing it this way means we do not need to scp the shell over to the host before executing it!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ssh user@host &amp;#039;sh&amp;#039; &amp;lt; your_script.sh&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
First of all, this command is a redirection: your shell will open the file your_script.sh and feed it as input to the ssh command. ssh, in turn, will tunnel its stdin to the remote command, namely, sh instance. And sh without arguments reads its script from stdin. So we got sh instance, which is launched on remote host, but reads commands from your local file.&lt;br /&gt;
&lt;br /&gt;
===Get a list of running instances - but only those started by the current user===&lt;br /&gt;
This is the way I wanted to do it but there&amp;#039;s an issue. Where does that spare } character come from? Anyone?&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ps -ef | grep [p]mon | awk -v dbowner=$(id -un) &amp;#039;{ if ($1==dbowner) { gsub(/ora_pmon_/,&amp;quot;&amp;quot;,$NF); print $NF; } }&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
ps listing&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ ps -ef | grep [p]mon&lt;br /&gt;
  oracle 13304024        1   0   Jun 07      -  2:39 ora_pmon_reportk&lt;br /&gt;
  oracle 26018178        1   0   Jun 07      -  3:01 ora_pmon_dwh_perf&lt;br /&gt;
  oracle 29229432        1   0   Jun 07      -  2:30 ora_pmon_adso&lt;br /&gt;
 oraebso 18022994        1   0   Jun 07      -  2:38 ora_pmon_EBSO&lt;br /&gt;
  oracle 30278192        1   0   Jun 07      -  2:48 ora_pmon_owb112k&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Results of above command&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
reportk&lt;br /&gt;
dwh_perf&lt;br /&gt;
adso&lt;br /&gt;
}&lt;br /&gt;
owb112k&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Workaround 1. Send the ps listing to a file and work on it without pipes. Works but it&amp;#039;s a bit long-winded especially as we have to clean up afterwards.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ps -ef | grep [p]mon&amp;gt;/tmp/results.$$ 2&amp;gt;/dev/null; awk -v dbowner=$(id -un) &amp;#039;{ if ($1==dbowner) { gsub(/ora_pmon_/,&amp;quot;&amp;quot;,$NF); print $NF; } }&amp;#039; /tmp/results.$$; rm -f /tmp/results.$$&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Workaround 2. Don&amp;#039;t like the grep -v but until I find out where that } is coming from..&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ps -ef | grep [p]mon | awk -v dbowner=$(id -un) &amp;#039;{ if ($1==dbowner) { gsub(/ora_pmon_/,&amp;quot;&amp;quot;,$NF); print $NF; } }&amp;#039; | egrep -v &amp;#039;grep|}|ASM&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Return a list of Oracle databases running on a list of remote servers===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/ksh&lt;br /&gt;
&lt;br /&gt;
serverlist=`cat /home/tools/ini/system/oracle_servers | sort -n | tr &amp;quot;\n&amp;quot; &amp;quot; &amp;quot;`&lt;br /&gt;
&lt;br /&gt;
if [ -z &amp;quot;${serverlist}&amp;quot; ]&lt;br /&gt;
then&lt;br /&gt;
    echo &amp;quot;no servers found&amp;quot; &amp;amp;&amp;amp; exit 1&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
for server in ${serverlist}&lt;br /&gt;
do&lt;br /&gt;
    ssh ${server} &amp;quot;ps -ef | grep [o]ra_pmon_&amp;quot; &amp;gt;/tmp/${server}.dblist&lt;br /&gt;
done&lt;br /&gt;
&lt;br /&gt;
for server in ${serverlist}&lt;br /&gt;
do&lt;br /&gt;
    cat /tmp/${server}.dblist | awk -F_ -v SRV=${server} &amp;#039;BEGIN {print SRV &amp;quot;:&amp;quot;} {print $NF}&amp;#039; | tr &amp;quot;\n&amp;quot; &amp;quot; &amp;quot;&lt;br /&gt;
    echo&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Clever trick to check whether SQL output needs sending to someone===&lt;br /&gt;
Using an exit status from SQL*Plus back to the shell so we can decide what to do.  Nice one!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
tempfile=/tmp/audit_locked_accounts_$ORACLE_SID.txt&lt;br /&gt;
&lt;br /&gt;
# Start sqlplus and check for locked accounts&lt;br /&gt;
sqlplus -S &amp;quot;/ as sysdba&amp;quot; &amp;lt;&amp;lt; EOF &amp;gt; $tempfile&lt;br /&gt;
set pages 0&lt;br /&gt;
select &amp;#039;The following accounts were found to be unlocked and should not be&amp;#039;&lt;br /&gt;
from dual;&lt;br /&gt;
&lt;br /&gt;
def exit_status = 0&lt;br /&gt;
col xs new_value exit_status&lt;br /&gt;
&lt;br /&gt;
select username&lt;br /&gt;
,      account_status&lt;br /&gt;
,      1 as xs&lt;br /&gt;
from   dba_users&lt;br /&gt;
where  account_status != &amp;#039;LOCKED&amp;#039;&lt;br /&gt;
and    username in (&amp;#039;HR&amp;#039;, &amp;#039;SCOTT&amp;#039;, &amp;#039;OUTLN&amp;#039;, &amp;#039;MDSYS&amp;#039;, &amp;#039;CTXSYS&amp;#039;)&lt;br /&gt;
/&lt;br /&gt;
exit &amp;amp;exit_status&lt;br /&gt;
EOF&lt;br /&gt;
&lt;br /&gt;
# If the exit status of sqlplus was not 0 then we will send an email&lt;br /&gt;
if [ $? != 0 ]; then&lt;br /&gt;
    mail -s &amp;quot;Accounts Unlocked in $ORACLE_SID&amp;quot; oracle &amp;lt; $tempfile&lt;br /&gt;
fi&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Check RMAN logfiles for errors from cron every day===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
00 09 * * * /home/tools/scripts/oracle/dosh &amp;#039;find /home/tools/logs/rman -name &amp;quot;*online.log&amp;quot; -mtime -1 -exec sed -ne &amp;quot;/^RMAN-/,/^$/p&amp;quot; {} \\; -ls&amp;#039; | mailx&lt;br /&gt;
 -s &amp;#039;RMAN errors last night&amp;#039; stuart@domain.com&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/home/ibmtools/scripts/oracle/dosh &amp;#039;find /oracle/export -name &amp;quot;expdp*log&amp;quot; -mtime -1 -exec grep ORA- {} \; -ls&amp;#039; | mailx -s &amp;#039;Datapump errors for Baxter last night&amp;#039; stuart@domain.com&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===An alternative to getopts===&lt;br /&gt;
These methods have the advantage of allowing arguments of any length not just 1 character&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
countArgs=$#&lt;br /&gt;
while [[ $# -gt 0 ]]&lt;br /&gt;
do&lt;br /&gt;
    idx1=$($ECHO $1|$GREP &amp;quot;=&amp;quot;|wc -l)&lt;br /&gt;
    if [[ $idx1 -gt 0 ]]; then&lt;br /&gt;
        key=$($ECHO $1|$CUT -d &amp;#039;=&amp;#039; -f 1)&lt;br /&gt;
        value=$($ECHO $1|$CUT -d &amp;#039;=&amp;#039; -f 2)&lt;br /&gt;
    else&lt;br /&gt;
        key=$($ECHO $1|$CUT -d &amp;#039;=&amp;#039; -f 1)&lt;br /&gt;
        idx2=$($ECHO $1|$GREP &amp;quot;^-&amp;quot;|wc -l)&lt;br /&gt;
        if [[ $idx2 -eq 0 ]]; then&lt;br /&gt;
            $ECHO -e &amp;quot;\n ERROR: $1 is an unsupported argument passed to agentDeploy.sh.\n&amp;quot;  &lt;br /&gt;
            usage&lt;br /&gt;
            exit 1&lt;br /&gt;
        fi&lt;br /&gt;
    fi&lt;br /&gt;
&lt;br /&gt;
    case &amp;quot;$key&amp;quot; in&lt;br /&gt;
    -help)&lt;br /&gt;
        if [[ $upgradeFlag ]]; then&lt;br /&gt;
            upgradeUsage&lt;br /&gt;
        else&lt;br /&gt;
            freshUsage&lt;br /&gt;
        fi&lt;br /&gt;
        exit 0;;&lt;br /&gt;
    AGENT_BASE_DIR)&lt;br /&gt;
        agentBaseDir=$($ECHO $value|$SED &amp;#039;s/\/$//&amp;#039;)&lt;br /&gt;
        checkBaseFlag=TRUE;;&lt;br /&gt;
    OMS_HOST)&lt;br /&gt;
        omsHost=$value&lt;br /&gt;
        checkOMSHost=TRUE;;&lt;br /&gt;
    EM_UPLOAD_PORT)&lt;br /&gt;
        omsPort=$value&lt;br /&gt;
        checkOMSPort=TRUE;;&lt;br /&gt;
    AGENT_INSTANCE_HOME)&lt;br /&gt;
        instHome=$($ECHO $value | $SED &amp;#039;s/\/$//&amp;#039;);;&lt;br /&gt;
    AGENT_REGISTRATION_PASSWORD)&lt;br /&gt;
        pswd=$value;;&lt;br /&gt;
    s_encrSecurePwd)&lt;br /&gt;
        pswd=$value;;  &lt;br /&gt;
    RESPONSE_FILE)&lt;br /&gt;
        rspFlag=TRUE  &lt;br /&gt;
        rspLoc=$value;;&lt;br /&gt;
    OLD_AGENT_VERSION)&lt;br /&gt;
        oldAgentVersion=$value;;            &lt;br /&gt;
    OLDHOME)&lt;br /&gt;
        oldHome=$value;;    &lt;br /&gt;
    -debug)&lt;br /&gt;
        debugSwitch=TRUE;;&lt;br /&gt;
    -forceConfigure)&lt;br /&gt;
        forceFlag=TRUE;;&lt;br /&gt;
    -configOnly)&lt;br /&gt;
        configFlag=TRUE    &lt;br /&gt;
        validationFlag=TRUE;;&lt;br /&gt;
    -agentImageLocation)&lt;br /&gt;
        archiveLoc=$value&lt;br /&gt;
        checkArchiveFlag=TRUE;;&lt;br /&gt;
    -invPtrLoc) shift&lt;br /&gt;
        ptrLoc=$1;;&lt;br /&gt;
    -Upgrade)&lt;br /&gt;
        UpgradeFlag=TRUE&lt;br /&gt;
        validFlag=TRUE;;&lt;br /&gt;
    INVENTORY_LOCATION)&lt;br /&gt;
        validFlag=TRUE;;&lt;br /&gt;
    b_forceInstCheck)&lt;br /&gt;
        validFlag=TRUE&lt;br /&gt;
        forcefullFlag=TRUE;;&lt;br /&gt;
    -prereqOnly)&lt;br /&gt;
        validationFlag=TRUE&lt;br /&gt;
        prereqFlag=TRUE;;&lt;br /&gt;
    -executeRootsh)&lt;br /&gt;
        validFlag=TRUE;;&lt;br /&gt;
    *)  idx=$($ECHO $1|$GREP &amp;quot;^-&amp;quot;|wc -l)&lt;br /&gt;
        if [[ $idx -eq 0 ]]; then&lt;br /&gt;
            validFlag=TRUE&lt;br /&gt;
        else&lt;br /&gt;
            $ECHO -e &amp;quot;\n ERROR: Invalid argument $key passed.&amp;quot;&lt;br /&gt;
            usage&lt;br /&gt;
            exit 1          &lt;br /&gt;
        fi&lt;br /&gt;
    esac&lt;br /&gt;
    shift&lt;br /&gt;
done&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
another way - found in /etc/init.d/functions (daemon function) in Fedora&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    while [ &amp;quot;$1&amp;quot; != &amp;quot;${1##[-+]}&amp;quot; ]; do&lt;br /&gt;
        case $1 in&lt;br /&gt;
        &amp;#039;&amp;#039;)&lt;br /&gt;
            echo $&amp;quot;$0: Usage: daemon [+/-nicelevel] {program}&amp;quot; &amp;quot;[arg1]...&amp;quot;&lt;br /&gt;
            return 1&lt;br /&gt;
            ;;&lt;br /&gt;
        --check)&lt;br /&gt;
            base=$2&lt;br /&gt;
            gotbase=&amp;quot;yes&amp;quot;&lt;br /&gt;
            shift 2&lt;br /&gt;
            ;;&lt;br /&gt;
        --check=?*)&lt;br /&gt;
            base=${1#--check=}&lt;br /&gt;
            gotbase=&amp;quot;yes&amp;quot;&lt;br /&gt;
            shift&lt;br /&gt;
            ;;&lt;br /&gt;
        --user)&lt;br /&gt;
            user=$2&lt;br /&gt;
            shift 2&lt;br /&gt;
            ;;&lt;br /&gt;
        --user=?*)&lt;br /&gt;
            user=${1#--user=}&lt;br /&gt;
            shift&lt;br /&gt;
            ;;&lt;br /&gt;
        --pidfile)&lt;br /&gt;
            pid_file=$2&lt;br /&gt;
            shift 2&lt;br /&gt;
            ;;&lt;br /&gt;
        --pidfile=?*)&lt;br /&gt;
            pid_file=${1#--pidfile=}&lt;br /&gt;
            shift&lt;br /&gt;
            ;;&lt;br /&gt;
        --force)&lt;br /&gt;
            force=&amp;quot;force&amp;quot;&lt;br /&gt;
            shift&lt;br /&gt;
            ;;&lt;br /&gt;
        [-+][0-9]*)&lt;br /&gt;
            nice=&amp;quot;nice -n $1&amp;quot;&lt;br /&gt;
            shift&lt;br /&gt;
            ;;&lt;br /&gt;
        *)&lt;br /&gt;
            echo $&amp;quot;$0: Usage: daemon [+/-nicelevel] {program}&amp;quot; &amp;quot;[arg1]...&amp;quot;&lt;br /&gt;
            return 1&lt;br /&gt;
            ;;&lt;br /&gt;
      esac&lt;br /&gt;
    done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
another way - found in adstrtal.sh (middleware start script for EBS)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#&lt;br /&gt;
# Parse Arguments&lt;br /&gt;
#&lt;br /&gt;
&lt;br /&gt;
for nxtarg in $*&lt;br /&gt;
do&lt;br /&gt;
  arg=`echo $nxtarg | sed &amp;#039;s/^//&amp;#039;`&lt;br /&gt;
&lt;br /&gt;
  case $arg in&lt;br /&gt;
    -secureapps)    if test &amp;quot;$secureapps&amp;quot; = &amp;quot;&amp;quot; ; then&lt;br /&gt;
                       secureapps=$arg&lt;br /&gt;
                    else&lt;br /&gt;
                       echo &amp;quot;$0: Duplicate Argument passed : $arg&amp;quot;&lt;br /&gt;
                       usage&lt;br /&gt;
                    fi&lt;br /&gt;
                ;;&lt;br /&gt;
    -nodbchk)       if test &amp;quot;$nodbchk&amp;quot; = &amp;quot;&amp;quot; ; then&lt;br /&gt;
                       nodbchk=$arg&lt;br /&gt;
                    else&lt;br /&gt;
                       echo &amp;quot;$0: Duplicate Argument passed : $arg&amp;quot;&lt;br /&gt;
                       usage&lt;br /&gt;
                    fi&lt;br /&gt;
                ;;&lt;br /&gt;
    -nopromptmsg)   if test &amp;quot;$nopromptmsg&amp;quot; = &amp;quot;&amp;quot; ; then&lt;br /&gt;
                       nopromptmsg=$arg&lt;br /&gt;
                    else&lt;br /&gt;
                       echo &amp;quot;$0: Duplicate Argument passed : $arg&amp;quot;&lt;br /&gt;
                       usage&lt;br /&gt;
                    fi&lt;br /&gt;
                ;;&lt;br /&gt;
    *)              if test &amp;quot;$unpw&amp;quot; = &amp;quot;&amp;quot; ; then&lt;br /&gt;
                       unpw=$arg&lt;br /&gt;
                    else&lt;br /&gt;
                       echo &amp;quot;$0: Duplicate Argument passed : $arg&amp;quot;&lt;br /&gt;
                       usage&lt;br /&gt;
                    fi&lt;br /&gt;
  esac&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
and another in adautocfg.sh&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
for myarg in $*&lt;br /&gt;
do&lt;br /&gt;
&lt;br /&gt;
  arg=`echo $myarg | sed &amp;#039;s/^-//&amp;#039;`&lt;br /&gt;
  case $arg in&lt;br /&gt;
    appspass=*)&lt;br /&gt;
            appspass=`echo $arg | sed &amp;#039;s/appspass=//g&amp;#039;`&lt;br /&gt;
            shift&lt;br /&gt;
            ;;&lt;br /&gt;
    nocustom)&lt;br /&gt;
            myparams=&amp;quot;$myparams $arg&amp;quot;&lt;br /&gt;
            shift&lt;br /&gt;
            ;;&lt;br /&gt;
    noversionchecks)&lt;br /&gt;
            myparams=&amp;quot;$myparams $arg&amp;quot;&lt;br /&gt;
            shift&lt;br /&gt;
            ;;&lt;br /&gt;
    promptmsg=*)&lt;br /&gt;
            promptmsg=`echo $arg | sed &amp;#039;s/promptmsg=//g&amp;#039;`&lt;br /&gt;
            shift&lt;br /&gt;
            ;;&lt;br /&gt;
        *)  echo &amp;quot;$0: unrecognized action specified&amp;quot;&lt;br /&gt;
            exit 1&lt;br /&gt;
  esac&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Run a script on multiple servers===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/ksh&lt;br /&gt;
# ==============================================================================&lt;br /&gt;
# Name         : dosh   (Distributed Oracle SHell)&lt;br /&gt;
# Description  : Runs a command on all Oracle servers&lt;br /&gt;
#&lt;br /&gt;
# Parameters   : h - displays help&lt;br /&gt;
#                v - verbose (default, like all unix commands is silent)&lt;br /&gt;
#                c - command to be executed&lt;br /&gt;
#&lt;br /&gt;
# Example      : ./dosh -v -c &amp;#039;ls -al&amp;#039;&lt;br /&gt;
#&lt;br /&gt;
# Modification History&lt;br /&gt;
# ====================&lt;br /&gt;
# When      Who               What&lt;br /&gt;
# ========= ================= ==================================================&lt;br /&gt;
# 08-FEB-13 Stuart Barkley    Created&lt;br /&gt;
# ==============================================================================&lt;br /&gt;
&lt;br /&gt;
# --------------------------------------------------------------------------&lt;br /&gt;
# this list of servers is generated by the DBAMON tool so will be up to date&lt;br /&gt;
# --------------------------------------------------------------------------&lt;br /&gt;
serverfile=/home/ibmtools/etc/oracle/oracle_servers&lt;br /&gt;
[[ -z &amp;quot;${serverfile}&amp;quot; ]] &amp;amp;&amp;amp; echo &amp;quot;Server list ${serverfile} not found&amp;quot; &amp;amp;&amp;amp; exit 1&lt;br /&gt;
&lt;br /&gt;
serverlist=`cat ${serverfile} | sort -n | tr &amp;quot;\n&amp;quot; &amp;quot; &amp;quot;`&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
# -------------------------&lt;br /&gt;
# get the arguments, if any&lt;br /&gt;
# -------------------------&lt;br /&gt;
while getopts &amp;quot;hvc:&amp;quot; OPT&lt;br /&gt;
do&lt;br /&gt;
    case &amp;quot;$OPT&amp;quot; in&lt;br /&gt;
    h) echo &amp;quot;\nUsage: $0 [-v] [-h] -c &amp;#039;&amp;lt;command_to_be_executed_remotely&amp;gt;&amp;#039;\n&amp;quot;;&lt;br /&gt;
       exit;&lt;br /&gt;
       ;;&lt;br /&gt;
    v) VERBOSE=&amp;quot;Y&amp;quot;;&lt;br /&gt;
       ;;&lt;br /&gt;
    c) CMMND=$OPTARG;&lt;br /&gt;
       ;;&lt;br /&gt;
    *) echo &amp;quot;\nUsage: $0 [-v] [-h] -c &amp;#039;&amp;lt;command_to_be_executed_remotely&amp;gt;&amp;#039;\n&amp;quot;;&lt;br /&gt;
       exit;&lt;br /&gt;
       ;;&lt;br /&gt;
    esac&lt;br /&gt;
done&lt;br /&gt;
shift $((OPTIND-1))&lt;br /&gt;
VERBOSE=${VERBOSE:-&amp;quot;N&amp;quot;}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
# --------------------------------&lt;br /&gt;
# check we have required arguments&lt;br /&gt;
# --------------------------------&lt;br /&gt;
[[ -z $CMMND ]] &amp;amp;&amp;amp; echo &amp;quot;Enter command to be executed like this: $0 -c &amp;#039;ls -al&amp;#039;&amp;quot; &amp;amp;&amp;amp; exit 1&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
# ----------------------------&lt;br /&gt;
# loop over the remote servers&lt;br /&gt;
# ----------------------------&lt;br /&gt;
for server in ${serverlist}&lt;br /&gt;
do&lt;br /&gt;
    if [[ &amp;quot;$VERBOSE&amp;quot; == &amp;quot;Y&amp;quot; ]]; then&lt;br /&gt;
        echo ${server} `date +&amp;#039;%d-%b-%Y %H:%M:%S&amp;#039;`&lt;br /&gt;
        echo &amp;quot;------------------------------------&amp;quot;&lt;br /&gt;
        set -x&lt;br /&gt;
    fi&lt;br /&gt;
    ssh ${server} &amp;quot;$CMMND&amp;quot;&lt;br /&gt;
    set +x&lt;br /&gt;
    [[ &amp;quot;$VERBOSE&amp;quot; == &amp;quot;Y&amp;quot; ]] &amp;amp;&amp;amp; echo&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
to be investigated... this one might be cleverer than mine...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
tmpdir=${TMPDIR:-/tmp}/pssh.$$&lt;br /&gt;
count=0&lt;br /&gt;
while userhost; do&lt;br /&gt;
    ssh -n -o BatchMode=yes ${userhost} &amp;#039;uname -a&amp;#039; &amp;gt; ${tmpdir}/${userhost} 2&amp;gt;&amp;amp;1 &amp;amp;&lt;br /&gt;
    count=`expr $count + 1`&lt;br /&gt;
done &amp;lt; userhost.lst&lt;br /&gt;
while [ $count -gt 0 ]; do&lt;br /&gt;
    wait $pids&lt;br /&gt;
    count=`expr $count - 1`&lt;br /&gt;
done&lt;br /&gt;
echo &amp;quot;Output for hosts are in $tmpdir&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
improved version...&amp;lt;br /&amp;gt;&lt;br /&gt;
just escape double quotes and dollar signs...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/ksh&lt;br /&gt;
# ==============================================================================&lt;br /&gt;
# Name         : dosh   (Distributed Oracle SHell)&lt;br /&gt;
# Description  : Runs a command on all Oracle servers&lt;br /&gt;
#&lt;br /&gt;
# Parameters   : h - displays help&lt;br /&gt;
#                v - verbose (default, like all unix commands is silent)&lt;br /&gt;
#                c - command to be executed&lt;br /&gt;
#&lt;br /&gt;
# Example      : ./dosh -v -c &amp;#039;ls -al&amp;#039;&lt;br /&gt;
#&lt;br /&gt;
# Modification History&lt;br /&gt;
# ====================&lt;br /&gt;
# When      Who               What&lt;br /&gt;
# ========= ================= ==================================================&lt;br /&gt;
# 08-FEB-13 Stuart Barkley    Created&lt;br /&gt;
# 08-JUL-15 Stuart Barkley    Background execution mode&lt;br /&gt;
# ==============================================================================&lt;br /&gt;
# --------------------------------------------------------------------------&lt;br /&gt;
# this list of servers is generated by the DBAMON tool so will be up to date&lt;br /&gt;
# --------------------------------------------------------------------------&lt;br /&gt;
serverfile=/home/ibmtools/etc/oracle/oracle_servers&lt;br /&gt;
[[ -z &amp;quot;${serverfile}&amp;quot; ]] &amp;amp;&amp;amp; echo &amp;quot;Server list ${serverfile} not found&amp;quot; &amp;amp;&amp;amp; exit 1&lt;br /&gt;
&lt;br /&gt;
serverlist=`cat ${serverfile} | sort -n | tr &amp;quot;\n&amp;quot; &amp;quot; &amp;quot;`&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
# -------------------------&lt;br /&gt;
# get the arguments, if any&lt;br /&gt;
# -------------------------&lt;br /&gt;
while getopts &amp;quot;hbvc:&amp;quot; OPT&lt;br /&gt;
do&lt;br /&gt;
    case &amp;quot;$OPT&amp;quot; in&lt;br /&gt;
    h) echo &amp;quot;\nUsage: $0 [-b] [-v] [-h] -c &amp;#039;&amp;lt;command_to_be_executed_remotely&amp;gt;&amp;#039;\n&amp;quot;;&lt;br /&gt;
       exit;&lt;br /&gt;
       ;;&lt;br /&gt;
    b) BACKGROUND=&amp;quot;Y&amp;quot;;&lt;br /&gt;
       ;;&lt;br /&gt;
    v) VERBOSE=&amp;quot;Y&amp;quot;;&lt;br /&gt;
       ;;&lt;br /&gt;
    c) CMMND=$OPTARG;&lt;br /&gt;
       ;;&lt;br /&gt;
    *) echo &amp;quot;\nUsage: $0 [-b] [-v] [-h] -c &amp;#039;&amp;lt;command_to_be_executed_remotely&amp;gt;&amp;#039;\n&amp;quot;;&lt;br /&gt;
       exit;&lt;br /&gt;
       ;;&lt;br /&gt;
    esac&lt;br /&gt;
done&lt;br /&gt;
shift $((OPTIND-1))&lt;br /&gt;
VERBOSE=${VERBOSE:-&amp;quot;N&amp;quot;}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
# --------------------------------&lt;br /&gt;
# check we have required arguments&lt;br /&gt;
# --------------------------------&lt;br /&gt;
[[ -z $CMMND ]] &amp;amp;&amp;amp; echo &amp;quot;Enter command to be executed like this: $0 -c &amp;#039;ls -al&amp;#039;&amp;quot; &amp;amp;&amp;amp; exit 1&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
# ---------------------------------&lt;br /&gt;
# put the thing to be run in a file&lt;br /&gt;
# ---------------------------------&lt;br /&gt;
printf &amp;quot;%s\n&amp;quot; &amp;quot;$CMMND&amp;quot; &amp;gt; /tmp/dosh.$$&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
# ----------------------------&lt;br /&gt;
# loop over the remote servers&lt;br /&gt;
# ----------------------------&lt;br /&gt;
for server in ${serverlist}&lt;br /&gt;
do&lt;br /&gt;
    if [[ &amp;quot;$VERBOSE&amp;quot; == &amp;quot;Y&amp;quot; ]]; then&lt;br /&gt;
        printf &amp;quot;%s\n&amp;quot; ${server} `date +&amp;#039;%d-%b-%Y %H:%M:%S&amp;#039;`&lt;br /&gt;
        printf &amp;quot;%s\n&amp;quot; &amp;quot;------------------------------------&amp;quot;&lt;br /&gt;
        set -x&lt;br /&gt;
    fi&lt;br /&gt;
    scp -q /tmp/dosh.$$ ${server}:/tmp/&lt;br /&gt;
    if [[ &amp;quot;$BACKGROUND&amp;quot; == &amp;quot;Y&amp;quot; ]]; then&lt;br /&gt;
        ssh -n -o BatchMode=yes ${server} &amp;quot;ksh /tmp/dosh.$$; rm -f /tmp/dosh.$$&amp;quot;&amp;gt; /tmp/dosh_${server}.out 2&amp;gt;&amp;amp;1 &amp;amp;&lt;br /&gt;
    else&lt;br /&gt;
        ssh -n -o BatchMode=yes ${server} &amp;quot;ksh /tmp/dosh.$$; rm -f /tmp/dosh.$$&amp;quot;&lt;br /&gt;
    fi&lt;br /&gt;
    set +x&lt;br /&gt;
    [[ &amp;quot;$VERBOSE&amp;quot; == &amp;quot;Y&amp;quot; ]] &amp;amp;&amp;amp; echo&lt;br /&gt;
done&lt;br /&gt;
rm -f /tmp/dosh.$$&lt;br /&gt;
&lt;br /&gt;
[[ &amp;quot;$BACKGROUND&amp;quot; == &amp;quot;Y&amp;quot; ]] &amp;amp;&amp;amp; printf &amp;quot;%s\n&amp;quot; &amp;quot;Type &amp;#039;ls -altr /tmp/dosh*out&amp;#039; to see output from the commands&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===How can a shell script find out what directory it is in?===&lt;br /&gt;
basename $0 does not always give the desired answer (might give &amp;quot;./&amp;quot;!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
DIR=&amp;quot;$(cd &amp;quot;$(dirname &amp;quot;$0&amp;quot;)&amp;quot; &amp;amp;&amp;amp; pwd)&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Array processing===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
array=(1 2 3)&lt;br /&gt;
unset array[2]&lt;br /&gt;
echo ${array[2]}          # null&lt;br /&gt;
indices=(${!array[@]})    # create an array of the indices of &amp;quot;array&amp;quot;&lt;br /&gt;
size=${#indices[@]}       # the size of &amp;quot;array&amp;quot; is the number of indices into it&lt;br /&gt;
size=${#array[@]}         # same&lt;br /&gt;
echo ${array[@]: -1}      # you can use slices to get array elements, -1 is the last one, etc.&lt;br /&gt;
for element in ${array[@]}; do    # iterate over the array without an index&lt;br /&gt;
&lt;br /&gt;
for index in ${indices[@]}        # iterate over the array WITH an index&lt;br /&gt;
do&lt;br /&gt;
    echo &amp;quot;Index: ${index}, Element: ${array[index]}&amp;quot;&lt;br /&gt;
done&lt;br /&gt;
&lt;br /&gt;
for index in ${!array[@]}         # iterate over the array WITH an index, directly&lt;br /&gt;
&lt;br /&gt;
array+=(&amp;quot;new element&amp;quot;)    # append a new element without referring to an index&lt;br /&gt;
((counter++))             # shorter than ((counter=counter+1)) or ((counter+=1))&lt;br /&gt;
if [[ $var == 3 ]]        # you can use the more &amp;quot;natural&amp;quot; comparison operators inside double square brackets&lt;br /&gt;
while [[ $var &amp;lt; 11 ]]     # another example&lt;br /&gt;
echo ${array[${index}-1]  # math inside an array subscript&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Send an email by talking directly to an smtp server===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
telnet smtp.domain.com 25 &amp;lt;&amp;lt;EOTXT&amp;gt;&amp;gt;/tmp/smtp.log&lt;br /&gt;
HELO me.domain.com&lt;br /&gt;
MAIL FROM:&amp;lt;stuart@domain.com&amp;gt;&lt;br /&gt;
RCPT TO:&amp;lt;anne@domain.com&amp;gt;&lt;br /&gt;
DATA&lt;br /&gt;
From: Stuart &amp;lt;stuart@domain.com&amp;gt;&lt;br /&gt;
To: Anne &amp;lt;anne@domain.com&amp;gt;&lt;br /&gt;
Subject: testing smtp email&lt;br /&gt;
&lt;br /&gt;
Hello, this should appear in the body&lt;br /&gt;
.&lt;br /&gt;
QUIT&lt;br /&gt;
EOTXT&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Send an email by talking directly to an smtp server via file descriptor (no telnet! this time), adding authentication===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
&lt;br /&gt;
#&lt;br /&gt;
# mail.sh&lt;br /&gt;
#&lt;br /&gt;
# 2008 - Mike Golvach - eggi@comcast.net&lt;br /&gt;
# 2010 - Rayber&lt;br /&gt;
#&lt;br /&gt;
# Creative Commons Attribution-Noncommercial-Share Alike 3.0 United States License&lt;br /&gt;
#&lt;br /&gt;
&lt;br /&gt;
if [ $# -ne 7 ]&lt;br /&gt;
then&lt;br /&gt;
echo &amp;quot;Usage: $0 FromAdress ToAdress Domain MailServer MailTextFile AuthEmail AuthPass&amp;quot;&lt;br /&gt;
exit 1&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
from=$1&lt;br /&gt;
to=$2&lt;br /&gt;
domain=$3&lt;br /&gt;
mailserver=$4&lt;br /&gt;
mailtext=$5&lt;br /&gt;
authemail=`echo $6|openssl enc -base64|awk &amp;#039;sub(&amp;quot;..$&amp;quot;, &amp;quot;&amp;quot;)&amp;#039;`&lt;br /&gt;
authpass=`echo $7|openssl enc -base64|awk &amp;#039;sub(&amp;quot;..$&amp;quot;, &amp;quot;&amp;quot;)&amp;#039;`&lt;br /&gt;
&lt;br /&gt;
if [ ! -f $mailtext ]&lt;br /&gt;
then&lt;br /&gt;
echo &amp;quot;Cannot find your mail text file. Exiting...&amp;quot;&lt;br /&gt;
exit 1&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
exec 9&amp;lt;&amp;gt;/dev/tcp/$mailserver/25&lt;br /&gt;
echo &amp;quot;HELO $domain&amp;quot; &amp;gt;&amp;amp;9&lt;br /&gt;
read -r temp &amp;lt;&amp;amp;9&lt;br /&gt;
echo &amp;quot;$temp&amp;quot;&lt;br /&gt;
echo &amp;quot;auth login&amp;quot; &amp;gt;&amp;amp;9&lt;br /&gt;
read -r temp &amp;lt;&amp;amp;9&lt;br /&gt;
echo &amp;quot;$authemail&amp;quot; &amp;gt;&amp;amp;9&lt;br /&gt;
read -r temp &amp;lt;&amp;amp;9&lt;br /&gt;
echo &amp;quot;$authpass&amp;quot; &amp;gt;&amp;amp;9&lt;br /&gt;
read -r temp &amp;lt;&amp;amp;9&lt;br /&gt;
echo &amp;quot;Mail From: $from&amp;quot; &amp;gt;&amp;amp;9&lt;br /&gt;
read -r temp &amp;lt;&amp;amp;9&lt;br /&gt;
echo &amp;quot;$temp&amp;quot;&lt;br /&gt;
echo &amp;quot;Rcpt To: $to&amp;quot; &amp;gt;&amp;amp;9&lt;br /&gt;
read -r temp &amp;lt;&amp;amp;9&lt;br /&gt;
echo &amp;quot;$temp&amp;quot;&lt;br /&gt;
echo &amp;quot;Data&amp;quot; &amp;gt;&amp;amp;9&lt;br /&gt;
read -r temp &amp;lt;&amp;amp;9&lt;br /&gt;
echo &amp;quot;$temp&amp;quot;&lt;br /&gt;
cat $mailtext &amp;gt;&amp;amp;9&lt;br /&gt;
echo &amp;quot;.&amp;quot; &amp;gt;&amp;amp;9&lt;br /&gt;
read -r temp &amp;lt;&amp;amp;9&lt;br /&gt;
echo &amp;quot;$temp&amp;quot;&lt;br /&gt;
echo &amp;quot;quit&amp;quot; &amp;gt;&amp;amp;9&lt;br /&gt;
read -r temp &amp;lt;&amp;amp;9&lt;br /&gt;
echo &amp;quot;$temp&amp;quot;&lt;br /&gt;
9&amp;gt;&amp;amp;-&lt;br /&gt;
9&amp;lt;&amp;amp;-&lt;br /&gt;
echo &amp;quot;All Done Sending Email. See above for errors&amp;quot;&lt;br /&gt;
exit 0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== rsync examples===&lt;br /&gt;
Also see [[Distribute files to multiple servers using rsync and ssh]]&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/sh&lt;br /&gt;
ssh  &amp;lt;remote_host&amp;gt; &amp;#039;/bin/mkdir -p /etc /etc/rc.config.d /etc/security /etc/mail&amp;#039;&lt;br /&gt;
rsync --rsync-path /usr/bin/rsync -Liprogtz --out-format=%f%L  /etc/passwd /etc/passwd.post /etc/group /etc/hosts /etc/services /etc/resolv.conf /etc/exclude.rootvg &amp;lt;remote_host&amp;gt;:/etc&lt;br /&gt;
rsync --rsync-path /usr/bin/rsync -Liprogtz --out-format=%f%L  /etc/hosts.allow.xcat &amp;lt;remote_host&amp;gt;:/etc/hosts.allow&lt;br /&gt;
rsync --rsync-path /usr/bin/rsync -Liprogtz --out-format=%f%L  /etc/rc.config.d/sap &amp;lt;remote_host&amp;gt;:/etc/rc.config.d&lt;br /&gt;
rsync --rsync-path /usr/bin/rsync -Liprogtz --out-format=%f%L  /etc/security/group /etc/security/limits /etc/security/login.cfg /etc/security/passwd /etc/security/user &amp;lt;remote_host&amp;gt;:/etc/security&lt;br /&gt;
rsync --rsync-path /usr/bin/rsync -Liprogtz --out-format=%f%L  /etc/mail/sendmail.cf &amp;lt;remote_host&amp;gt;:/etc/mail&lt;br /&gt;
&lt;br /&gt;
rsync -av --progress /home/ibmtools/scripts/oracle/* benouerp07:/home/ibmtools/scripts/oracle/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Handy aliases===&lt;br /&gt;
Strip out comments and blank lines from a file&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alias strip=&amp;#039;grep -Ev &amp;#039;\&amp;#039;&amp;#039;^(#|$)&amp;#039;\&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Does a ps and a grep&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alias psg=&amp;#039;ps -ef | grep -v $$ | grep -i &amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Getting a decent listing of filesystem space available. It is ordered such that the filesystems with no space left are at the end.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
OS=$(uname -s)&lt;br /&gt;
[[ &amp;quot;$OS&amp;quot; == &amp;quot;SunOS&amp;quot; ]] &amp;amp;&amp;amp; alias dfg=&amp;#039;df -h|sed -e &amp;#039;1d&amp;#039;|sort -n -k5|awk &amp;#039;\&amp;#039;&amp;#039; BEGIN {printf(&amp;quot;%-35s%-10s%-10s%-6s%-30s\n&amp;quot;,&amp;quot;Filesystem&amp;quot;,&amp;quot;Total&amp;quot;,&amp;quot;Free&amp;quot;,&amp;quot;%Used&amp;quot;,&amp;quot;Mounted on&amp;quot;)} {printf(&amp;quot;%-35s%-10s%-10s%-6s%-30s\n&amp;quot;,$1,$2,$4,$5,$6)}&amp;#039;\&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
[[ &amp;quot;$OS&amp;quot; == &amp;quot;AIX&amp;quot; ]]   &amp;amp;&amp;amp; alias dfg=&amp;#039;df -g|sed -e &amp;#039;1d&amp;#039;|sort -n -k4|awk &amp;#039;\&amp;#039;&amp;#039; BEGIN {printf(&amp;quot;%-35s%-10s%-10s%-6s%-30s\n&amp;quot;,&amp;quot;Filesystem&amp;quot;,&amp;quot;Total GB&amp;quot;,&amp;quot;Free&amp;quot;,&amp;quot;%Used&amp;quot;,&amp;quot;Mounted on&amp;quot;)} {printf(&amp;quot;%-35s%-10s%-10s%-6s%-30s\n&amp;quot;,$1,$2,$3,$4,$7)}&amp;#039;\&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
A handy way of listing subdirectories and their files&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alias filetree=&amp;quot;find . -print | sed -e &amp;#039;s;[^/]*/;|____;g;s;____|; |;g&amp;#039;&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Watch progress of a copy&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alias cpProgress=&amp;quot;rsync --progress -ravz&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Reboots Linksys router&amp;lt;pre&amp;gt;&lt;br /&gt;
alias rebootlinksys=&amp;quot;curl -u &amp;#039;admin:password&amp;#039; &amp;#039;http://192.168.1.2/setup.cgi?todo=reboot&amp;#039;&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Nice one for bash. Colour codes the prompt depending on the outcome of the previous command&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
bash_prompt_command()&lt;br /&gt;
{&lt;br /&gt;
    RTN=$?&lt;br /&gt;
    prevCmd=$(prevCmd $RTN)&lt;br /&gt;
}&lt;br /&gt;
PROMPT_COMMAND=bash_prompt_command&lt;br /&gt;
prevCmd()&lt;br /&gt;
{&lt;br /&gt;
    if [ $1 == 0 ] ; then&lt;br /&gt;
        echo $GREEN&lt;br /&gt;
    else&lt;br /&gt;
        echo $RED&lt;br /&gt;
    fi&lt;br /&gt;
}&lt;br /&gt;
if [ $(tput colors) -gt 0 ] ; then&lt;br /&gt;
    RED=$(tput setaf 1)&lt;br /&gt;
    GREEN=$(tput setaf 2)&lt;br /&gt;
    RST=$(tput op)&lt;br /&gt;
fi&lt;br /&gt;
export PS1=&amp;quot;\[\e[36m\]\u.\h.\W\[\e[0m\]\[\$prevCmd\]&amp;gt;\[$RST\]&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Mmmm, to be looked into. Executes remote commands on a unix box using curl.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#/bin/sh&lt;br /&gt;
#&lt;br /&gt;
# WAG320N-HACK&lt;br /&gt;
# Ver. 1.0&lt;br /&gt;
# 12/09/2010&lt;br /&gt;
#&lt;br /&gt;
# This program is free software: you can redistribute it and/or modify&lt;br /&gt;
# it under the terms of the GNU General Public License as published by&lt;br /&gt;
# the Free Software Foundation, either version 3 of the License, or&lt;br /&gt;
# (at your option) any later version.&lt;br /&gt;
#&lt;br /&gt;
# This program is distributed in the hope that it will be useful,&lt;br /&gt;
# but WITHOUT ANY WARRANTY; without even the implied warranty of&lt;br /&gt;
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the&lt;br /&gt;
# GNU General Public License for more details.&lt;br /&gt;
#&lt;br /&gt;
# You should have received a copy of the GNU General Public License&lt;br /&gt;
# along with this program.  If not, see &amp;lt;http://www.gnu.org/licenses/&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
# Set username and password in the form of &amp;quot;username:password&amp;quot;&lt;br /&gt;
# example: &amp;quot;admin:admin&amp;quot;&lt;br /&gt;
my_access=&amp;quot;admin:admin&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Parameters test&lt;br /&gt;
if [ -z &amp;quot;$1&amp;quot; ]&lt;br /&gt;
then&lt;br /&gt;
  echo &amp;quot;wag320n-hack.sh: missing remote command&amp;quot;&lt;br /&gt;
  echo &amp;quot;usage: wag320n-hack.sh &amp;lt;remote command&amp;gt;&amp;quot;&lt;br /&gt;
  echo &amp;quot;example: wag320n-hack.sh /bin/ls -la /usr/sbin&amp;quot;&lt;br /&gt;
  echo &amp;quot;Note: always use full path&amp;quot;&lt;br /&gt;
  echo &amp;quot;&amp;quot;&lt;br /&gt;
  echo &amp;quot;wag320n-hack.sh - Ver. 1.0 - 12/09/2010&amp;quot;&lt;br /&gt;
  echo &amp;quot;Licensed under GPL V. 3&amp;quot;&lt;br /&gt;
  echo &amp;quot;&amp;quot;&lt;br /&gt;
  exit 0&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
# Get the command&lt;br /&gt;
my_command=&amp;quot;ping_size=&amp;quot;&amp;#039;$(&amp;#039;&amp;quot;$@&amp;quot;&amp;#039; 1&amp;gt;&amp;amp;2)&amp;#039;&lt;br /&gt;
&lt;br /&gt;
curl -s -G -u &amp;quot;$my_access&amp;quot; --data-urlencode &amp;#039;todo=ping_test&amp;#039; --data-urlencode &amp;#039;this_file=Diagnostics.htm&amp;#039; --data-urlencode &amp;#039;next_file=Ping.htm&amp;#039; --data-urlencode &amp;#039;c4_ping_ipaddr=192.168.1.1&amp;#039; --data-urlencode &amp;#039;ping_timeout=5000&amp;#039; --data-urlencode &amp;#039;ping_interval=1000&amp;#039; --data-urlencode &amp;#039;ping_number=1&amp;#039; --data-urlencode &amp;quot;$my_command&amp;quot; http://192.168.1.1/setup.cgi | sed -e &amp;#039;/HTTP\/1.0 200 OK/q&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===How to configure SSH with public/private keys===&lt;br /&gt;
* [http://www.unixpeople.com/HOWTO/configuring.ssh.html unixpeople.com]&lt;br /&gt;
===Use SSH config file===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Host server10&lt;br /&gt;
  Hostname 1.2.3.4&lt;br /&gt;
  IdentityFile ~/.ssh/id_dsa&lt;br /&gt;
  user foobar&lt;br /&gt;
  Port 30000&lt;br /&gt;
  ForwardX11Trusted yes&lt;br /&gt;
  TCPKeepAlive yes&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
then just connect using&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ssh server10&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===A decent sed tutorial===&lt;br /&gt;
From [http://www.grymoire.com/Unix/Sed.html grymoire.com]&lt;br /&gt;
===A decent korn/bash shell tutorial===&lt;br /&gt;
From [http://www.dartmouth.edu/~rc/classes/ksh/print_pages.shtml dartmouth.edu]&lt;br /&gt;
Reproduced here just in case it disappears!&lt;br /&gt;
[[Advanced shell scripting]]&lt;br /&gt;
&lt;br /&gt;
===trap===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
     Example Handling Traps With ksh - Discussion of the kill command&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
EXAMPLE TEMPLATE:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
PRODUCT:    HP-UX 11iV1 Version B.11.11&lt;br /&gt;
            HP Tru64 V5.1B PK4&lt;br /&gt;
            Sun/Solaris SunOS V5.8&lt;br /&gt;
            Linux 2.6 kernel&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
COMPONENT:  ksh&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
SOURCE:     Philippe Vouters&lt;br /&gt;
            Fontainebleau/France&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
LOW COST HIGH-TECH PRODUCTS:  http://techno-star.fr&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
OVERVIEW:&lt;br /&gt;
&lt;br /&gt;
The ksh script below shows how to eventually handle traps in the situation &lt;br /&gt;
where someone might try to kill a script by killing individual commands run &lt;br /&gt;
by that script or the entire process group a script is running in. The kill &lt;br /&gt;
command (usually a shell builtin) may be used to send a signal to a process &lt;br /&gt;
group (with the -&amp;lt;pid&amp;gt; syntax) or an individual process. The example ksh &lt;br /&gt;
script below runs /bin/sleep as the foreground process, the example ksh &lt;br /&gt;
scripts immediately returns when the /bin/sleep process has terminated. Most &lt;br /&gt;
signals sent to the shell are ignored until after the foreground process &lt;br /&gt;
terminates. This is in order to avoid creating zombie processes. Therefore a &lt;br /&gt;
kill &amp;lt;pid&amp;gt; on the example ksh script waits for the termination of the &lt;br /&gt;
/bin/sleep process.&lt;br /&gt;
&lt;br /&gt;
The status value $? in the trap refers to the exit status of the command to run &lt;br /&gt;
and therefore is the exit status of the /bin/sleep process. The called function &lt;br /&gt;
in the trap handler shows how to correctly examine the effect of the kill &lt;br /&gt;
command on the shell or it&amp;#039;s children.&lt;br /&gt;
&lt;br /&gt;
To examine the value of $? in a trap handler means that you must understand what&lt;br /&gt;
it can be set and how different signals delivered to either the shell or the &lt;br /&gt;
foreground process (or the process group) might affect the value of $?.&lt;br /&gt;
&lt;br /&gt;
The example shell script prints $? using echo but it does not perform tests on &lt;br /&gt;
the value of $?. For a complete solution when attempting to trap signals in a &lt;br /&gt;
shell you would also need code that examined the value of $? after the &lt;br /&gt;
foreground process had completed.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*** CAUTION ***&lt;br /&gt;
&lt;br /&gt;
This sample script has been tested using HP-UX B.11.11, HP Tru64 V5.1B PK4, &lt;br /&gt;
SunOS V5.8 and Fedora Core 4 (homed version of Red Hat Linux).  However, we&lt;br /&gt;
cannot guarantee its effectiveness because of the possibility of error in &lt;br /&gt;
transmitting or implementing it. It is meant to be used as a template for &lt;br /&gt;
writing your own scripts, and may require modification for use on your system. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
SCRIPT NOTES:&lt;br /&gt;
&lt;br /&gt;
To notice that the ksh script and /bin/sleep share the same process group&lt;br /&gt;
identifier (PGID), issue the following commands:&lt;br /&gt;
&lt;br /&gt;
[philippe@victor ~]$ who&lt;br /&gt;
philippe :0           Jan 10 10:16&lt;br /&gt;
philippe pts/1        Jan 10 21:30 (:0.0)&lt;br /&gt;
philippe pts/2        Jan 10 21:30 (:0.0)&lt;br /&gt;
[philippe@victor ~]$ tty&lt;br /&gt;
/dev/pts/1&lt;br /&gt;
[philippe@victor ~]$ ps -j -t pts/2&lt;br /&gt;
  PID  PGID   SID TTY          TIME CMD&lt;br /&gt;
11072 11072 11072 pts/2    00:00:00 bash&lt;br /&gt;
11113 11113 11072 pts/2    00:00:00 ksh&lt;br /&gt;
11116 11113 11072 pts/2    00:00:00 sleep&lt;br /&gt;
&lt;br /&gt;
In this case sending kill -INT -11113 will send SIGINT to the process group &lt;br /&gt;
11113. Both of the ksh and sleep processes are contained within this process &lt;br /&gt;
group.&lt;br /&gt;
&lt;br /&gt;
Important Note:&lt;br /&gt;
&lt;br /&gt;
On HP-UX, you have to $ export UNIX95=1 in order to be able to use the&lt;br /&gt;
-j option of the ps command.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
SCRIPT:&lt;br /&gt;
&lt;br /&gt;
                             COPYRIGHT (C) 2005 BY&lt;br /&gt;
                              HEWLETT-PACKARD COMPANY&lt;br /&gt;
                                ALL RIGHTS RESERVED.&lt;br /&gt;
&lt;br /&gt;
     THIS SOFTWARE IS FURNISHED UNDER A LICENSE AND MAY BE USED AND COPIED&lt;br /&gt;
     ONLY IN ACCORDANCE WITH THE TERMS OF SUCH LICENSE AND WITH THE INCLUSION&lt;br /&gt;
     OF THE ABOVE COPYRIGHT NOTICE.  THIS SOFTWARE OR ANY OTHER COPIES&lt;br /&gt;
     THEREOF MAY NOT BE PROVIDED OR OTHERWISE MADE AVAILABLE TO ANY OTHER&lt;br /&gt;
     PERSON.  NO TITLE TO AND OWNERSHIP OF THE SOFTWARE IS HEREBY TRANSFERRED.&lt;br /&gt;
&lt;br /&gt;
     THE INFORMATION IN THIS SOFTWARE IS SUBJECT TO CHANGE WITHOUT NOTICE AND&lt;br /&gt;
     SHOULD NOT BE CONSTRUED AS A COMMITMENT BY HEWLETT-PACKARD COMPANY.&lt;br /&gt;
&lt;br /&gt;
     HP ASSUMES NO RESPONSIBILITY FOR THE USE OR RELIABILITY OF ITS&lt;br /&gt;
     SOFTWARE ON EQUIPMENT THAT IS NOT SUPPLIED BY HP.&lt;br /&gt;
&lt;br /&gt;
     NO RESPONSIBILITY IS ASSUMED FOR THE USE OR RELIABILITY OF SOFTWARE&lt;br /&gt;
     ON EQUIPMENT THAT IS NOT SUPPLIED BY HEWLETT-PACKARD COMPANY.&lt;br /&gt;
&lt;br /&gt;
     SUPPORT FOR THIS SOFTWARE IS NOT COVERED UNDER ANY HP SOFTWARE&lt;br /&gt;
     PRODUCT SUPPORT CONTRACT, BUT MAY BE PROVIDED UNDER THE TERMS OF THE&lt;br /&gt;
     CONSULTING AGREEMENT UNDER WHICH THIS SOFTWARE WAS DEVELOPED.&lt;br /&gt;
&lt;br /&gt;
#!/bin/ksh&lt;br /&gt;
function handle_signal&lt;br /&gt;
{&lt;br /&gt;
        print -n &amp;quot;pid $$ recieved $2 &amp;quot;&lt;br /&gt;
        if [[ $1 = 0 ]];then&lt;br /&gt;
            print but foreground command ended successfully&lt;br /&gt;
        else&lt;br /&gt;
                if [[ $1 = $3 ]];then&lt;br /&gt;
                    print and so did the last foreground command&lt;br /&gt;
                else&lt;br /&gt;
                    print -n &amp;quot;and the exit status of the last foreground &amp;quot;&lt;br /&gt;
                    print command was $1&lt;br /&gt;
                fi&lt;br /&gt;
        fi&lt;br /&gt;
        # Kill our process group and then ourselves with SIGTERM, giving a &lt;br /&gt;
        # pid of 0 sends the signal to our process group. Killing the process&lt;br /&gt;
        # group should kill us as well, this assumes that SIGTERM is not &lt;br /&gt;
        # handled by any process in the process group.&lt;br /&gt;
        #&lt;br /&gt;
        # This code could be replaced with an exit with an exit value that&lt;br /&gt;
        # would indicate what the problem was to the caller. That is replace &lt;br /&gt;
        # these two lines with:&lt;br /&gt;
        #&lt;br /&gt;
        # exit $3&lt;br /&gt;
        #&lt;br /&gt;
        # or a specific exit code could be used.&lt;br /&gt;
        #&lt;br /&gt;
        kill -TERM 0&lt;br /&gt;
        kill -TERM $$&lt;br /&gt;
        }&lt;br /&gt;
OS=$(uname -a | awk &amp;#039;{print $1}&amp;#039;)&lt;br /&gt;
if [[ &amp;quot;$OS&amp;quot; = &amp;quot;Linux&amp;quot; ]]; then&lt;br /&gt;
    offset=256&lt;br /&gt;
elif [[ (&amp;quot;$OS&amp;quot; = &amp;quot;HP-UX&amp;quot;) || &lt;br /&gt;
        (&amp;quot;$OS&amp;quot; = &amp;quot;SunOS&amp;quot;) || &lt;br /&gt;
        (&amp;quot;$OS&amp;quot; = &amp;quot;OSF1&amp;quot;) ]]; then&lt;br /&gt;
   offset=128&lt;br /&gt;
fi&lt;br /&gt;
trap &amp;#039;RC=$?; handle_signal $RC SIGINT $offset+2&amp;#039; INT&lt;br /&gt;
trap &amp;#039;RC=$?; handle_signal $RC SIGQUIT $offset+3&amp;#039; QUIT&lt;br /&gt;
/bin/sleep 20&lt;br /&gt;
echo $?&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===DNS not working===&lt;br /&gt;
Ping to an IP address works&lt;br /&gt;
 ping 74.125.136.103&lt;br /&gt;
but this doesn&amp;#039;t&lt;br /&gt;
 ping www.google.com&lt;br /&gt;
&lt;br /&gt;
Check resolv.conf&lt;br /&gt;
 cat /etc/resolv.conf&lt;br /&gt;
 nameserver 95.130.132.17&lt;br /&gt;
 nameserver 95.130.132.18&lt;br /&gt;
I had changed internet provider and forgot to update this. Just to set it to the router address and let that do the resolution&lt;br /&gt;
 nameserver 192.168.1.1&lt;br /&gt;
&lt;br /&gt;
===File descriptors===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
exec 3&amp;lt;&amp;gt; /tmp/foo  #open fd 3 for r/w&lt;br /&gt;
echo &amp;quot;test&amp;quot; &amp;gt;&amp;amp;3&lt;br /&gt;
exec 3&amp;gt;&amp;amp;- #close fd 3.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
exec 3&amp;lt;&amp;gt; myfile.txt&lt;br /&gt;
while read line &amp;lt;&amp;amp;3&lt;br /&gt;
do {&lt;br /&gt;
  echo &amp;quot;$line&amp;quot;&lt;br /&gt;
  (( Lines++ ));                   #  Incremented values of this variable&lt;br /&gt;
                                   #+ accessible outside loop.&lt;br /&gt;
                                   #  No subshell, no problem.&lt;br /&gt;
}&lt;br /&gt;
done&lt;br /&gt;
exec 3&amp;gt;&amp;amp;-&lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;Number of lines read = $Lines&amp;quot;     # 8&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Mmm. See our output and also tee it to a log file!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
&lt;br /&gt;
echo hello&lt;br /&gt;
&lt;br /&gt;
if test -t 1; then&lt;br /&gt;
    # Stdout is a terminal.&lt;br /&gt;
    exec &amp;gt;log&lt;br /&gt;
else&lt;br /&gt;
    # Stdout is not a terminal.&lt;br /&gt;
    npipe=/tmp/$$.tmp&lt;br /&gt;
    trap &amp;quot;rm -f $npipe&amp;quot; EXIT&lt;br /&gt;
    mknod $npipe p&lt;br /&gt;
    tee &amp;lt;$npipe log &amp;amp;&lt;br /&gt;
    exec 1&amp;gt;&amp;amp;-&lt;br /&gt;
    exec 1&amp;gt;$npipe&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
echo goodbye&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Create new image with kvm===&lt;br /&gt;
Ref: http://www.cyberciti.biz/faq/kvm-virtualization-in-redhat-centos-scientific-linux-6/&amp;lt;br /&amp;gt;&lt;br /&gt;
Build an empty space for a CentOS virtual machine&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
qemu-img create -f qcow2 centos.img 12G&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Tried creating image with&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo virt-install -n CentOS --description &amp;quot;Trying out CentOS&amp;quot; --ram=1024 --vcpus=1 --cpu host --hvm --cdrom /home/bey9at77/Downloads/c6-x86_64-20130910-1.qcow2 --graphics vnc --disk path=/var/lib/libvirt/images/centos.img,bus=virtio,size=10&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
gives error&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Starting install...&lt;br /&gt;
Allocating &amp;#039;centos.img&amp;#039;                                                                                                                                                                                               |  10 GB     00:00     &lt;br /&gt;
ERROR    internal error Process exited while reading console log output: char device redirected to /dev/pts/1&lt;br /&gt;
qemu-kvm: -drive file=/home/bey9at77/Downloads/c6-x86_64-20130910-1.qcow2.bz2,if=none,media=cdrom,id=drive-ide0-1-0,readonly=on,format=raw: could not open disk image /home/bey9at77/Downloads/c6-x86_64-20130910-1.qcow2: Permission denied&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===rpm / yum commands===&lt;br /&gt;
====Install an RPM Package====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rpm -ivh pidgin-2.7.9-5.el6.2.i686.rpm&lt;br /&gt;
&lt;br /&gt;
-i - install&lt;br /&gt;
-v - verbose&lt;br /&gt;
-h - print progress hashes&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Check dependencies of RPM Package before Installing====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rpm -qpR BitTorrent-5.2.2-1-Python2.4.noarch.rpm&lt;br /&gt;
&lt;br /&gt;
-q - query&lt;br /&gt;
-p - list package capabilities&lt;br /&gt;
-R - list dependent package capabilities&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Install RPM Package with all dependencies====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
yum install BitTorrent-5.2.2-1-Python2.4.noarch.rpm&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Install RPM Package with all dependencies (when RPM has been downloaded to local machine)====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
yum localinstall BitTorrent-5.2.2-1-Python2.4.noarch.rpm&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Force Install a RPM Package without dependencies====&lt;br /&gt;
Package will not work if dependencies are required&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rpm -ivh --nodeps BitTorrent-5.2.2-1-Python2.4.noarch.rpm&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Check an Installed RPM Package====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rpm -q BitTorrent&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====List all files of an installed RPM package====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rpm -ql BitTorrent&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====List All Installed RPM Packages====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rpm -qa&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Query information about an installed RPM package====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rpm -qi vsftpd&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Query information about a not yet installed RPM package====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rpm -qip sqlbuddy-1.3.3-1.noarch.rpm&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====(Forcibly) Remove an RPM Package====&lt;br /&gt;
Use package name (as seen in -qi above), not full name&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rpm -ev (--nodeps) vsftpd&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Query a file that was installed as part of an RPM Package (which package contained this file)====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rpm -qf /usr/bin/htpasswd&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Verify an RPM package====&lt;br /&gt;
Compares information of installed files of the package against the rpm database&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rpm -Vp sqlbuddy-1.3.3-1.noarch.rpm&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Rebuild corrupted RPM database====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cd /var/lib&lt;br /&gt;
rm __db*&lt;br /&gt;
rpm --rebuilddb&lt;br /&gt;
rpmdb_verify Packages&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Install rpmforge repository===&lt;br /&gt;
* Download rpmforge-release-0.5.3-1.el6.rf.x86_64.rpm&lt;br /&gt;
* Import the key&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo rpm --import http://apt.sw.be/RPM-GPG-KEY.dag.txt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Install the repository&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo rpm -i rpmforge-release-0.5.3-1.el6.rf.x86_64.rpm&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Check the installation&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rpm -K rpmforge-release-0.5.3-1.el6.rf.x86_64.rpm&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Test it&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo yum install terminator&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Install rpmfusion repository===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
su -c &amp;#039;yum localinstall --nogpgcheck http://download1.rpmfusion.org/free/el/updates/6/i386/rpmfusion-free-release-6-1.noarch.rpm http://download1.rpmfusion.org/nonfree/el/updates/6/i386/rpmfusion-nonfree-release-6-1.noarch.rpm&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===config file for yum===&lt;br /&gt;
Checkout this file for global yum config&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/etc/sysconfig/yum-cron-background&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Setup Oracle Enterprise Linux (RedHat) with yum server===&lt;br /&gt;
You need to download the yum .repo file from the server, as per the steps below. After this, you need to enable a flag in the .repo file as per your operating system version. Having done these two steps, when you run yum install &amp;lt;pkgname&amp;gt; command on your linux box, the Oracle&amp;#039;s yum server will be scanned, the dependent &amp;amp; the relevant rpm&amp;#039;s will be download and installed for you.&amp;lt;br /&amp;gt;&lt;br /&gt;
 cd /etc/yum.repos.d&lt;br /&gt;
To download files here&lt;br /&gt;
 wget http://public-yum.oracle.com/public-yum-el5.repo&lt;br /&gt;
&lt;br /&gt;
A file named public-yum-el5.repo will be created in your directory&amp;lt;br /&amp;gt;&lt;br /&gt;
Edit this file and enter enabled=1 against the operating systems which is relevant to you&lt;br /&gt;
 vi public-yum-el5.repo&lt;br /&gt;
&lt;br /&gt;
Next run the yum command&lt;br /&gt;
 yum install package-name&lt;br /&gt;
&lt;br /&gt;
===To change to static IP address (Raspberry Pi)===&lt;br /&gt;
As root:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cd /etc/networks&lt;br /&gt;
vi interfaces&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
replace the line “iface eth0 inet dhcp” with&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
iface eth0 inet static&lt;br /&gt;
address 192.168.1.100&lt;br /&gt;
netmask 255.255.255.0&lt;br /&gt;
gateway 192.168.1.1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You should also take a look at the file /etc/resolv.conf and check it has a nameserver entry (probably pointing at your default gateway) or direct to your ISP name servers.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
nameserver 192.168.1.1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Troubleshoot wireless network problems===&lt;br /&gt;
* [https://www.blackmoreops.com/2014/09/18/connect-to-wifi-network-from-command-line-in-linux/ connect to wifi network from command-line in linux - from blackmoreops.com]&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Short summary of all the things you need to do in just few lines&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
root@kali:~# iw dev&lt;br /&gt;
root@kali:~# ip link set wlan0 up&lt;br /&gt;
root@kali:~# iw wlan0 scan&lt;br /&gt;
root@kali:~# wpa_passphrase blackMOREOps &amp;gt;&amp;gt; /etc/wpa_supplicant.conf&lt;br /&gt;
root@kali:~# wpa_supplicant -i wlan0 -c /etc/wpa_supplicant.conf&lt;br /&gt;
root@kali:~# iw wlan0 link&lt;br /&gt;
root@kali:~# dhclient wlan0&lt;br /&gt;
root@kali:~# ping 8.8.8.8&lt;br /&gt;
(Where wlan0 is wifi adapter and blackMOREOps is SSID)&lt;br /&gt;
(Add Routing manually)&lt;br /&gt;
root@kali:~# ip route add default via 10.0.0.138 dev wlan0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===To change to static IP address (Redhat/CentOS)===&lt;br /&gt;
As root:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
vi /etc/sysconfig/network-scripts/ifcfg-eth0&lt;br /&gt;
DEVICE=eth0&lt;br /&gt;
BOOTPROTO=STATIC&lt;br /&gt;
IPADDR=192.168.1.111&lt;br /&gt;
NETMASK=255.255.255.0&lt;br /&gt;
GATEWAY=192.168.1.1&lt;br /&gt;
ONBOOT=yes&lt;br /&gt;
DNS1=8.8.8.8&lt;br /&gt;
DNS2=8.8.4.4&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Resrart the network interface&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/etc/init.d/network stop&lt;br /&gt;
/etc/init.d/network start&lt;br /&gt;
or&lt;br /&gt;
service network restart&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Check name server entry in resolv.conf&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
vi /etc/resolv.conf&lt;br /&gt;
nameserver 192.168.1.1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Enable processes / services to start at boot time===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo chkconfig httpd on&lt;br /&gt;
sudo chkconfig mysqld on&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Run a command on lots of servers in parallel===&lt;br /&gt;
This is a damn fine AIX utility - part of the CSM Distributed Shell.&lt;br /&gt;
 dsh -a &amp;quot;ls -al /etc/apache2/*conf&amp;quot;&lt;br /&gt;
will list the Apache configuration file on all reachable servers (nodes)&lt;br /&gt;
===Download a gzip file and pipe it into tar===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cd ~ &amp;amp;&amp;amp; wget -O - &amp;quot;https://www.dropbox.com/download?plat=lnx.x86_64&amp;quot; | tar xzf -&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Check in a script to make sure it is run only by root===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
RUID=`/usr/bin/id|$AWK -F\( &amp;#039;{print $1}&amp;#039;|$AWK -F\= &amp;#039;{print $2}&amp;#039;`&lt;br /&gt;
if [ ${RUID} != &amp;quot;0&amp;quot; ];then&lt;br /&gt;
   $ECHO &amp;quot;This script must be executed as root&amp;quot;&lt;br /&gt;
   exit 1&lt;br /&gt;
fi&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Set terminal to use Backspace key to erase previous character instead of Control-H===&lt;br /&gt;
Been looking for this for a long time.&amp;lt;br /&amp;gt;&lt;br /&gt;
You can put:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
stty erase &amp;lt;CTRL-V&amp;gt;&amp;lt;Backspace key&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
in your .profile but this will be ruined if you do a copy/paste into another file.&amp;lt;br /&amp;gt;&lt;br /&gt;
I wanted a way of doing this without entering the control character in the .profile. Finally stumbled upon it. And it&amp;#039;s so simple. Just escape the caret!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
stty erase \^?&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Put this in the .profile. It&amp;#039;s copy/pastable and it works!&amp;lt;br /&amp;gt;&lt;br /&gt;
If you want CTRL-H to be your erase character, just do this:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
stty erase \^H&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Play with the terminal settings and reset them again either side of requesting a password===&lt;br /&gt;
The -g option of stty gives a compact list of all the settings or the terminal and can be used as input to stty&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
OLDCONFIG=`stty -g`          # save terminal configuration&lt;br /&gt;
stty -echo                   # turn character echoing off&lt;br /&gt;
echo &amp;quot;Enter password: \c&amp;quot;&lt;br /&gt;
read PASSWD                  # get the password&lt;br /&gt;
stty $OLDCONFIG              # restore terminal configuration&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Reset terminal to &amp;quot;sane&amp;quot; characteristics===&lt;br /&gt;
If you&amp;#039;ve done a cat of a binary file or something else weird and your terminal is left in a mess, the following key sequence should bring it back to normal&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;CTRL-J&amp;gt;stty sane&amp;lt;CTRL-J&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Install OpenOffice on RedHat Enterprise when yum install doesn&amp;#039;t!===&lt;br /&gt;
Download Package&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
wget http://sourceforge.net/projects/openofficeorg.mirror/files/4.0.1/binaries/en-US/Apache_OpenOffice_4.0.1_Linux_x86-64_install-rpm_en-US.tar.gz/download -O Apache_OpenOffice_4.0.1_Linux_x86-64_install-rpm_en-US.tar.gz&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Change to root&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo su -&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Remove the old stuff&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
yum remove openoffice* libreoffice*&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Extract Package&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
tar -xvf Apache_OpenOffice_4.0.1*&lt;br /&gt;
cd en-US&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Install Package and exit root&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rpm -Uvh RPMS/*.rpm RPMS/desktop-integration/openoffice4.0-redhat-*.rpm&lt;br /&gt;
exit&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Start it&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
openoffice4&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===What does this do?===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
while IFS= read -r line; do&lt;br /&gt;
    echo &amp;quot;[$(date &amp;quot;+%F %T&amp;quot;)] - $line&amp;quot;&lt;br /&gt;
done &amp;lt; &amp;lt;(iwevent)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
while IFS= read -r line; do&lt;br /&gt;
    printf &amp;quot;%s\n%s\n&amp;quot; &amp;quot;$line&amp;quot; &amp;quot;Yohooo! One more package.&amp;quot;&lt;br /&gt;
done &amp;lt; &amp;lt;(tcpdump -i any -nS)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===List of Special Characters and what they mean===&lt;br /&gt;
From [http://www.grymoire.com/Unix/Quote.html Bruce Barnett]&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Character	Where	Meaning&lt;br /&gt;
&amp;lt;RETURN&amp;gt;	csh, sh	Execute command&lt;br /&gt;
#	csh, sh, ASCII files	Start a comment&lt;br /&gt;
&amp;lt;SPACE&amp;gt;	csh, sh	Argument separator&lt;br /&gt;
`	csh, sh	Command substitution&lt;br /&gt;
&amp;quot;	csh, sh	Weak Quotes&lt;br /&gt;
&amp;#039;	csh, sh	Strong Quotes&lt;br /&gt;
\	csh, sh	Single Character Quote&lt;br /&gt;
variable	sh, csh	Variable&lt;br /&gt;
variable	csh, sh	Same as variable&lt;br /&gt;
|	csh, sh	Pipe character&lt;br /&gt;
^	sh	Pipe Character&lt;br /&gt;
&amp;amp;	csh, sh	Run program in background&lt;br /&gt;
?	csh, sh	Match one character&lt;br /&gt;
*	csh, sh	Match any number of characters&lt;br /&gt;
;	csh, sh	Command separator&lt;br /&gt;
;;	sh	End of Case statement&lt;br /&gt;
~	csh	Home Directory&lt;br /&gt;
~user	csh	User&amp;#039;s Home Directory&lt;br /&gt;
!	csh	History of Commands&lt;br /&gt;
-	Programs	Start of optional argument&lt;br /&gt;
$#	csh, sh	Number of arguments to script&lt;br /&gt;
$*	csh, sh	Arguments to script&lt;br /&gt;
$@	sh	Original arguments to script&lt;br /&gt;
$-	sh	Flags passed to shell&lt;br /&gt;
$?	sh	Status of previous command&lt;br /&gt;
$$	sh	Process identification number&lt;br /&gt;
$!	sh	PID of last background job&lt;br /&gt;
&amp;amp;&amp;amp;	sh	Short-circuit AND&lt;br /&gt;
||	sh	Short-circuit OR&lt;br /&gt;
.	csh, sh	Typ. filename extension&lt;br /&gt;
.	sh	Source a file and execute as command&lt;br /&gt;
:	sh	Nothing command&lt;br /&gt;
:	sh	Separates Values in environment variables&lt;br /&gt;
:	csh	Variable modifier&lt;br /&gt;
Character	Where	Meaning&lt;br /&gt;
[ ]	csh, sh	Match range of characters&lt;br /&gt;
[ ]	sh	Test&lt;br /&gt;
%job	csh	Identifies job Number&lt;br /&gt;
(cmd;cmd)	csh. sh	Runs cmd;cmd as a sub-shell&lt;br /&gt;
{ }	csh	In-line expansions&lt;br /&gt;
{cmd;cmd }	sh	Like (cmd;cmd ) without a subshell&lt;br /&gt;
&amp;gt;ofile	csh, sh	Standard output&lt;br /&gt;
&amp;gt;&amp;gt;ofile	csh, sh	Append to standard output&lt;br /&gt;
&amp;lt;ifile	csh, sh	Standard Input&lt;br /&gt;
&amp;lt;&amp;lt;word	csh, sh	Read until word, substitute variables&lt;br /&gt;
&amp;lt;&amp;lt;\word	csh, sh	Read until word, no substitution&lt;br /&gt;
&amp;lt;&amp;lt;-word	sh	Read until word, ignoring TABS&lt;br /&gt;
&amp;gt;&amp;gt;!file	csh	Append to file, ignore error if not there&lt;br /&gt;
&amp;gt;!file	csh	Output to new file, ignore error if not there&lt;br /&gt;
&amp;gt;&amp;amp;file	csh	Send standard &amp;amp; error output to file&lt;br /&gt;
&amp;lt;&amp;amp;digit	sh	Switch Standard Input to file&lt;br /&gt;
&amp;lt;&amp;amp;-	sh	Close Standard Input&lt;br /&gt;
&amp;gt;&amp;amp;digit	sh	Switch Standard Output to file&lt;br /&gt;
&amp;gt;&amp;amp;-	sh	Close Standard Output&lt;br /&gt;
digit1&amp;lt;&amp;amp;digit2	sh	Connect digit2 to digit1&lt;br /&gt;
digit&amp;lt;&amp;amp;-	sh	Close file digit&lt;br /&gt;
digit2&amp;gt;&amp;amp;digit1	sh	Connect digit2 to digit1&lt;br /&gt;
digit&amp;gt;&amp;amp;-	sh	Close file digit&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Stuart</name></author>	</entry>

	<entry>
		<id>https://mailnest.com/dbawiki/index.php?title=Unix/Linux&amp;diff=3379</id>
		<title>Unix/Linux</title>
		<link rel="alternate" type="text/html" href="https://mailnest.com/dbawiki/index.php?title=Unix/Linux&amp;diff=3379"/>
				<updated>2018-11-27T11:47:37Z</updated>
		
		<summary type="html">&lt;p&gt;Stuart: /* ps -ef cuts off args cmd column on Solaris */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;* [http://hyperpolyglot.org/unix-shells#var-expansion Good shell comparison including variable expansion - hyperpolyglot.org]&lt;br /&gt;
* [http://pubs.opengroup.org/onlinepubs/9699919799/utilities/toc.html Shell coding standards - opengroup.org]&lt;br /&gt;
* [http://aix4admins.blogspot.be aix4admins]&lt;br /&gt;
* [http://linuxgazette.net/issue55/okopnik.html The Deep, Dark Secrets of Bash]&lt;br /&gt;
* [http://www.speakeasy.org/~arkay/216-7.4KshFunctions.html Korn Shell Functions]&lt;br /&gt;
* [http://www.grymoire.com/Unix/AwkRef.html AWK reference from Bruce Barnett]&lt;br /&gt;
* [http://www.catonmat.net/blog/wp-content/uploads/2008/09/awk1line.txt HANDY AWK ONE-LINERS]&lt;br /&gt;
* [http://www.grymoire.com/unix/Quote.html Unix quoting from from Bruce Barnett (grymoire)]&lt;br /&gt;
* [http://www.mpi-inf.mpg.de/departments/rg1/teaching/unixffb-ss98/quoting-guide.html Another excellent quoting tutorial]&lt;br /&gt;
* [http://aix4admins.blogspot.be/2015/02/snapshot-fs-snapshot-snapshot-is-state.html AIX snapshot technology]&lt;br /&gt;
* [[RaspberryPi]]&lt;br /&gt;
* [[SSH]]&lt;br /&gt;
* [http://www.anattatechnologies.com/q/2013/04/multiuser-screen/ Screen sharing from Unix using screen]&lt;br /&gt;
* [https://robots.thoughtbot.com/a-tmux-crash-course Screen sharing from Unix using tmux]&lt;br /&gt;
* [http://www.csb.yale.edu/userguides/wordprocess/vi-summary.html Handy ex and vi reference]&lt;br /&gt;
* [[Fedora install for my own purposes]]&lt;br /&gt;
&lt;br /&gt;
===Use sed to repeat characters===&lt;br /&gt;
echo an &amp;#039;=&amp;#039; sign then use the loop feature of sed to run round a loop a further 79 times replacing what you&amp;#039;ve got with the same thing plus and extra one!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
echo &amp;quot;=&amp;quot; | sed -e :a -e &amp;#039;s/^=\{1,79\}$/&amp;amp;=/;ta&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Convert between lower and upper case using ansi standard===&lt;br /&gt;
This way should be portable and give predictable results&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
LOWER_SID=$(echo &amp;quot;${SID}&amp;quot; | tr &amp;#039;[:upper:]&amp;#039; &amp;#039;[:lower:]&amp;#039;)&lt;br /&gt;
UPPER_SID=$(echo &amp;quot;${SID}&amp;quot; | tr &amp;#039;[:lower:]&amp;#039; &amp;#039;[:upper:]&amp;#039;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Use sed to delete the first line of a file or command output printing from the second line onwards===&lt;br /&gt;
Actually deceptively simple. Example remove the header from df output.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
df -k | sed 1d&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
As a useful extension, suppose TO_DATA_DIR contains multiple directories, this will total the free space for all relevant filesystems&amp;lt;br /&amp;gt;&lt;br /&gt;
This one is specific to AIX, for other Unixes and Linux, use $4 instead of $3.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SPACE_AVAILABLE=$(df -k $TO_DATA_DIR | sed 1d | awk &amp;#039;BEGIN {i=0} {i=i+$3} END {print i}&amp;#039;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Use sed to munge a controlfile into submission!===&lt;br /&gt;
* delete comment lines&lt;br /&gt;
* delete all lines after the one starting with a semicolon&lt;br /&gt;
* delete all blank lines&lt;br /&gt;
* change reuse to set&lt;br /&gt;
* change archivelog (with word boundaries) to noarchivelog&lt;br /&gt;
* change old sid to new sid&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sqlplus -s / as sysdba&amp;lt;&amp;lt;&amp;#039;EOSQL&amp;#039; &amp;gt;/dev/null&lt;br /&gt;
alter database backup controlfile to trace as &amp;#039;/tmp/regenerate_controlfile.sql&amp;#039; reuse resetlogs;&lt;br /&gt;
EOSQL&lt;br /&gt;
OLDSID=&amp;#039;PROD&amp;#039;&lt;br /&gt;
NEWSID=&amp;#039;TEST&amp;#039;&lt;br /&gt;
sed  -e &amp;#039;/^--/d&amp;#039; -e &amp;#039;/^\;/q&amp;#039; -e &amp;#039;/^ *$/d&amp;#039; -e &amp;#039;s/REUSE/SET/&amp;#039; -e &amp;#039;s/\&amp;lt;ARCHIVELOG\&amp;gt;/NOARCHIVELOG/&amp;#039; -e &amp;#039;s/\&amp;quot;&amp;#039;${OLDSID}&amp;#039;\&amp;quot;/\&amp;quot;&amp;#039;${NEWSID}&amp;#039;\&amp;quot;/&amp;#039; /tmp/regenerate_controlfile.sql&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Find all files where a certain text does not exist===&lt;br /&gt;
Mostly we want to search for files containing a particular string but how to find those files that do not contain some text.&amp;lt;br /&amp;gt;&lt;br /&gt;
Using xargs instead of -exec forces the filename to be printed. -H should do this but doesn&amp;#039;t seem to in this case.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
find . -name &amp;quot;*cfg&amp;quot; | xargs grep -H -c TO_CV_HOST {} \; | grep &amp;#039;:0$&amp;#039; | cut -d: -f1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Use tar and gzip to copy files more efficiently across network between hosts===&lt;br /&gt;
From the destination server, this will connect to the source, tar up each file and pull it back to the current server&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ssh oracle@hn5211 &amp;quot;cd /oracle/ora_data4/iten3/ &amp;amp;&amp;amp; tar -cf - . | gzip &amp;quot; | ( cd /oracle/ora_data2/iten/ &amp;amp;&amp;amp; gunzip -c | tar -xvf - . )&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===double hash and double percent in shell variables to trim off characters from variables===&lt;br /&gt;
&amp;lt;nowiki&amp;gt;#&amp;lt;/nowiki&amp;gt;  - trims everything from the start of line till the FIRST occurrence of following character (abstemious) :-)&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;nowiki&amp;gt;##&amp;lt;/nowiki&amp;gt; - trims everything from the start of line till the LAST occurrence of following character (greedy)&amp;lt;br /&amp;gt;&lt;br /&gt;
%  - trims everything from the end of line backwards till the FIRST occurrence of following character (abstemious)&amp;lt;br /&amp;gt;&lt;br /&gt;
%% - trims everything from the end of line backwards till the LAST occurrence of following character (greedy)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
FILENAME=&amp;quot;/home/bey9at77/hello.txt&amp;quot;&lt;br /&gt;
FILE_STUB1=${FILENAME##*/}&lt;br /&gt;
FILE_STUB=${FILE_STUB1%.*}&lt;br /&gt;
echo $FILE_STUB&lt;br /&gt;
hello&lt;br /&gt;
FILE_EXT=${FILENAME##*.}&lt;br /&gt;
echo $FILE_EXT&lt;br /&gt;
txt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;nowiki&amp;gt;#&amp;lt;/nowiki&amp;gt; - remove prefix reluctantly&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;nowiki&amp;gt;##&amp;lt;/nowiki&amp;gt; - remove prefix greedily&amp;lt;br /&amp;gt;&lt;br /&gt;
% - remove suffix reluctantly&amp;lt;br /&amp;gt;&lt;br /&gt;
%% - remove suffix greedily&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
words=&amp;quot;do.re.mi&amp;quot;&lt;br /&gt;
&lt;br /&gt;
echo ${words#*.}&lt;br /&gt;
&lt;br /&gt;
echo ${words##*.}&lt;br /&gt;
&lt;br /&gt;
echo ${words%.*}&lt;br /&gt;
&lt;br /&gt;
echo ${words%%.*}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===The best shell script ever. An example of how scripting should be done===&lt;br /&gt;
It was written by someone at Oracle. Unfortunately (s)he did not put any author comment in it. Also unfortunately I cannot show it here as it is protected behind Oracles support website.&amp;lt;br /&amp;gt;&lt;br /&gt;
If you have an Oracle Metalink id, you can get the complete script [https://support.oracle.com/epmos/faces/DocumentDisplay?id=949322.1 here]&amp;lt;br /&amp;gt;&lt;br /&gt;
Here is a snippet of a function that demonstrates proper commenting and a very good style.&amp;lt;br &amp;gt;&lt;br /&gt;
The script is called physru.sh and upgrades an Oracle database in a rolling upgrade fashion by using a physical standby.&amp;lt;br /&amp;gt;&lt;br /&gt;
There are 4500 lines in the full script but it is so easy to read and understand because of the way it&amp;#039;s written, it&amp;#039;s like a breath of fresh air. Well done whoever you are!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
###############################################################################&lt;br /&gt;
# NAME:        wait_mrp_active&lt;br /&gt;
#&lt;br /&gt;
# DESCRIPTION: &lt;br /&gt;
#   Wait for $MRP_START_TIMEOUT minutes to confirm that the MRP is active.  If&lt;br /&gt;
#   we can&amp;#039;t detect an active MRP, abort the script with an error.&lt;br /&gt;
#&lt;br /&gt;
# INPUT(S):&lt;br /&gt;
#   Arguments:&lt;br /&gt;
#     $1: database user&lt;br /&gt;
#     $2: user password&lt;br /&gt;
#     $3: tns service name&lt;br /&gt;
#     $4: database unique name&lt;br /&gt;
#&lt;br /&gt;
#   Globals:&lt;br /&gt;
#     None&lt;br /&gt;
#&lt;br /&gt;
# RETURN:&lt;br /&gt;
#   None&lt;br /&gt;
#&lt;br /&gt;
###############################################################################&lt;br /&gt;
wait_mrp_active()&lt;br /&gt;
{&lt;br /&gt;
  display &amp;quot;confirming media recovery is running&amp;quot;&lt;br /&gt;
  l_wma_status=1&lt;br /&gt;
  l_wma_curtime=`perl -e &amp;#039;print int(time)&amp;#039;`&lt;br /&gt;
  l_wma_exptime=`expr $MRP_START_TIMEOUT &amp;quot;*&amp;quot; 60`&lt;br /&gt;
  l_wma_maxtime=`expr $l_wma_curtime + $l_wma_exptime`&lt;br /&gt;
  while [ &amp;quot;$l_wma_curtime&amp;quot; -lt &amp;quot;$l_wma_maxtime&amp;quot; ]&lt;br /&gt;
  do&lt;br /&gt;
    is_mrp_running $1 $2 $3 $4&lt;br /&gt;
    if [ &amp;quot;$?&amp;quot; -gt &amp;quot;0&amp;quot; ]; then&lt;br /&gt;
      l_wma_status=0&lt;br /&gt;
      break&lt;br /&gt;
    fi&lt;br /&gt;
&lt;br /&gt;
    sleep $MRP_START_INTERVAL&lt;br /&gt;
    l_wma_curtime=`perl -e &amp;#039;print int(time)&amp;#039;`&lt;br /&gt;
  done&lt;br /&gt;
  chkerr $l_wma_status &amp;quot;could not detect an active MRP after $MRP_START_TIMEOUT minutes&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===split variable (eg. filename) into separate variables using set===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
FILENAME=&amp;quot;split_this_into_bits&amp;quot;&lt;br /&gt;
set $(echo ${FILENAME} | sed &amp;#039;s/_/ /g&amp;#039;)&lt;br /&gt;
echo $4 $3 $2 $1&lt;br /&gt;
bits into this split&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Centre align text on a line in bash shell===&lt;br /&gt;
Doesn&amp;#039;t work in Korn shell due to %*s&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#COLUMNS=$(tput cols)   # width of the current window&lt;br /&gt;
COLUMNS=80&lt;br /&gt;
title=&amp;quot;Hello world!&amp;quot;&lt;br /&gt;
printf &amp;quot;%*s\n&amp;quot; $(((${#title}+$COLUMNS)/2)) &amp;quot;$title&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
and as a one-liner&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
printf &amp;quot;%*s\n&amp;quot; $(( ( $(echo $* | wc -c ) + 80 ) / 2 )) &amp;quot;$*&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This works in Korn shell...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
TITLE=&amp;quot;$1&amp;quot;&lt;br /&gt;
LINEWIDTH=80&lt;br /&gt;
&lt;br /&gt;
LPAD=$(((${#TITLE}+$LINEWIDTH)/2))&lt;br /&gt;
printf %${LPAD}s &amp;quot;$TITLE&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Right justify text (or repeat characters) on a line with leader dots!===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
function rpadwait {&lt;br /&gt;
    text=$1&lt;br /&gt;
# -------------------------&lt;br /&gt;
# suppress newline for echo&lt;br /&gt;
# -------------------------&lt;br /&gt;
N=&lt;br /&gt;
C=&lt;br /&gt;
if echo &amp;quot;\c&amp;quot; | grep c &amp;gt;/dev/null 2&amp;gt;&amp;amp;1; then&lt;br /&gt;
    N=&amp;#039;-n&amp;#039;&lt;br /&gt;
else&lt;br /&gt;
    C=&amp;#039;\c&amp;#039;&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
    echo ${N} &amp;quot;${text}${C}&amp;quot; | sed -e :a -e &amp;#039;s/^.\{1,80\}$/&amp;amp;\./;ta&amp;#039;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===cron jobs not submitted - daemon run out of child processes?===&lt;br /&gt;
Sometimes have problems with NFS mounts and this causes cron jobs to hang. If they are scheduled to run regularly, eventually cron will no longer be able to start any more jobs.&amp;lt;br /&amp;gt;&lt;br /&gt;
* Check the cron log &amp;#039;&amp;#039;&amp;#039;/var/adm/cron/log&amp;#039;&amp;#039;&amp;#039; to see if there are any errors or other messages around the time the jobs should run.&lt;br /&gt;
If cron has hit its process limit (default 100), it will try again after a number of seconds (default 60).&amp;lt;br /&amp;gt;&lt;br /&gt;
Both the number of jobs and wait time are configured in the file &amp;#039;&amp;#039;&amp;#039;/var/adm/cron/queuedefs&amp;#039;&amp;#039;&amp;#039;. If it is unusual for cron to be running so many jobs, you can check the process table to view the jobs cron has created. These jobs will have parent process id (PPID) of the cron daemon.&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ ps -ef | grep cron | grep -v grep&lt;br /&gt;
    root  6750314        1   0   Apr 24      -  3:39 /usr/sbin/cron&lt;br /&gt;
solax025:root[/home/root]# ps -T 6750314&lt;br /&gt;
      PID    TTY  TIME CMD&lt;br /&gt;
  6750314      -  3:39 cron&lt;br /&gt;
 21168296      -  0:00     \--bsh&lt;br /&gt;
 58982414      -  0:00         \--sadc&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
In this example, we only have 1 job running&lt;br /&gt;
&lt;br /&gt;
===Find long-running processes with a cron job===&lt;br /&gt;
Processes running longer than 24 hours have a date instead of a start time...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
58 08,14 * * * /home/ibmtools/scripts/oracle/dosh -vc &amp;quot;ps -ef|grep &amp;#039;ibmtools/scripts/oracle&amp;#039;|perl -nae &amp;#039;print if \$F[4] !~/:/&amp;#039;&amp;quot; &amp;gt;/tmp/lrp.txt; [[ $(grep -c ibmtools /tmp/lrp.txt) -ne 0 ]] &amp;amp;&amp;amp; cat /tmp/lrp.txt|mailx -s &amp;#039;*** long running processes - please check ***&amp;#039; reporting@companymail.com&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Process command line arguments in shell===&lt;br /&gt;
Borrowed from Mozilla Firefox installer&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
## Command line arg defaults&lt;br /&gt;
##&lt;br /&gt;
moz_debug=0&lt;br /&gt;
moz_debugger=&amp;quot;&amp;quot;&lt;br /&gt;
moz_debugger_args=&amp;quot;&amp;quot;&lt;br /&gt;
#&lt;br /&gt;
##&lt;br /&gt;
## Parse the command line&lt;br /&gt;
##&lt;br /&gt;
while [ $# -gt 0 ]&lt;br /&gt;
do&lt;br /&gt;
  case $1 in&lt;br /&gt;
    -g | --debug)&lt;br /&gt;
      moz_debug=1&lt;br /&gt;
      shift&lt;br /&gt;
      ;;&lt;br /&gt;
    -d | --debugger)&lt;br /&gt;
      moz_debugger=$2;&lt;br /&gt;
      if [ &amp;quot;${moz_debugger}&amp;quot; != &amp;quot;&amp;quot; ]; then&lt;br /&gt;
	shift 2&lt;br /&gt;
      else&lt;br /&gt;
        echo &amp;quot;-d requires an argument&amp;quot;&lt;br /&gt;
        exit 1&lt;br /&gt;
      fi&lt;br /&gt;
      ;;&lt;br /&gt;
    -a | --debugger-args)&lt;br /&gt;
      moz_debugger_args=$2;&lt;br /&gt;
      if [ &amp;quot;${moz_debugger_args}&amp;quot; != &amp;quot;&amp;quot; ]; then&lt;br /&gt;
	shift 2&lt;br /&gt;
      else&lt;br /&gt;
        echo &amp;quot;-a requires an argument&amp;quot;&lt;br /&gt;
        exit 1&lt;br /&gt;
      fi&lt;br /&gt;
      ;;&lt;br /&gt;
    *)&lt;br /&gt;
      break;&lt;br /&gt;
      ;;&lt;br /&gt;
  esac&lt;br /&gt;
done&lt;br /&gt;
#&lt;br /&gt;
##&lt;br /&gt;
## Program name given in $1&lt;br /&gt;
##&lt;br /&gt;
if [ $# -gt 0 ]&lt;br /&gt;
then&lt;br /&gt;
	MOZ_PROGRAM=$1&lt;br /&gt;
	shift&lt;br /&gt;
fi&lt;br /&gt;
##&lt;br /&gt;
## Program not given, try to guess a default&lt;br /&gt;
##&lt;br /&gt;
if [ -z &amp;quot;$MOZ_PROGRAM&amp;quot; ]&lt;br /&gt;
then&lt;br /&gt;
	##&lt;br /&gt;
	## Try this script&amp;#039;s name with &amp;#039;-bin&amp;#039; appended&lt;br /&gt;
	##&lt;br /&gt;
	if [ -x &amp;quot;$MOZ_DEFAULT_NAME&amp;quot; ]&lt;br /&gt;
	then&lt;br /&gt;
		MOZ_PROGRAM=$MOZ_DEFAULT_NAME&lt;br /&gt;
	##&lt;br /&gt;
	## Try mozilla-bin&lt;br /&gt;
	## &lt;br /&gt;
	elif [ -x &amp;quot;$MOZ_APPRUNNER_NAME&amp;quot; ]&lt;br /&gt;
	then&lt;br /&gt;
		MOZ_PROGRAM=$MOZ_APPRUNNER_NAME&lt;br /&gt;
	fi&lt;br /&gt;
fi&lt;br /&gt;
#&lt;br /&gt;
#&lt;br /&gt;
##&lt;br /&gt;
## Make sure the program is executable&lt;br /&gt;
##&lt;br /&gt;
if [ ! -x &amp;quot;$MOZ_PROGRAM&amp;quot; ]&lt;br /&gt;
then&lt;br /&gt;
	moz_bail &amp;quot;Cannot execute $MOZ_PROGRAM.&amp;quot;&lt;br /&gt;
fi&lt;br /&gt;
#&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Carry XWindows settings across sessions===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# ----------------------&lt;br /&gt;
# push XWindows settings&lt;br /&gt;
# ----------------------&lt;br /&gt;
[[ &amp;quot;$(uname)&amp;quot; == &amp;quot;SunOS&amp;quot; ]] &amp;amp;&amp;amp; PATH=/usr/openwin/bin:$PATH&lt;br /&gt;
WHOAMI=$(id | awk -F&amp;#039;)&amp;#039; &amp;#039;{print $1}&amp;#039; | awk -F&amp;#039;(&amp;#039; &amp;#039;{print $2}&amp;#039;)&lt;br /&gt;
xauth list &amp;gt; /tmp/xauth_list_$WHOAMI&lt;br /&gt;
chmod 777 /tmp/xauth_list_$WHOAMI&lt;br /&gt;
&lt;br /&gt;
echo $DISPLAY &amp;gt; /tmp/xdisplay_$WHOAMI&lt;br /&gt;
chmod 777 /tmp/xdisplay_$WHOAMI&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Cross-platform version of whoami===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
WHOAMI=$(id | awk -F&amp;#039;)&amp;#039; &amp;#039;{print $1}&amp;#039; | awk -F&amp;#039;(&amp;#039; &amp;#039;{print $2}&amp;#039;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Set terminal title from command line===&lt;br /&gt;
Put something like this in the .profile&amp;lt;br /&amp;gt;&lt;br /&gt;
-n     do not output the trailing newline&amp;lt;br /&amp;gt;&lt;br /&gt;
-e     enable interpretation of backslash escapes&amp;lt;br /&amp;gt;&lt;br /&gt;
|0     sets title of window and icon&amp;lt;br /&amp;gt;&lt;br /&gt;
|1     sets title of icon only&amp;lt;br /&amp;gt;&lt;br /&gt;
|2     sets title of window only&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
echo -en &amp;quot;\033]0;`hostname`\007&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
echo -en &amp;quot;\033]2;`hostname`\007&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Remove blank lines and comments (also indented ones) from a file===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
awk -F\: &amp;#039;!/^($|[:space:]*#)/ {print $2}&amp;#039; /etc/oratab | sort | uniq&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or as part of a script that removes comments and blank lines from all Korn shell scripts in a directory&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/usr/bin/ksh&lt;br /&gt;
for i in $(ls *ksh); do&lt;br /&gt;
    perl -p -i -e &amp;#039;s/^\s*#[^!]*$//; s/^\s*$//&amp;#039; $i&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Return elements of an array in Korn shell===&lt;br /&gt;
From [http://unix.stackexchange.com/questions/188202/processing-output-from-an-sqlite-db-into-a-ksh-array-with-spaces here]&amp;lt;br /&amp;gt;&lt;br /&gt;
Could be used to separate the columns of an SQL select when returning to the shell&amp;lt;br /&amp;gt;&lt;br /&gt;
This approach eliminates the need to put quotes around text with spaces in it.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
echo $KSH_VERSION&lt;br /&gt;
x=&amp;quot;Red,Yellow is a color,Blue&amp;quot;&lt;br /&gt;
oIFS=$IFS&lt;br /&gt;
IFS=,&lt;br /&gt;
y=($x)&lt;br /&gt;
IFS=$oIFS&lt;br /&gt;
echo ${y[1]}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===A decent Unix Prompt===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
export PS1=&amp;quot;`uname -n`:`whoami`[\${PWD}]# &amp;quot;&lt;br /&gt;
or&lt;br /&gt;
export PS1=&amp;#039;($?) $&amp;#039;ORACLE_SID&amp;quot; &amp;quot;`whoami`&amp;quot;@&amp;quot;`uname -n`&amp;quot;:&amp;quot;&amp;#039;$&amp;#039;PWD&amp;quot;&amp;gt; &amp;quot;&lt;br /&gt;
export EDITOR=vi&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Simple arithmetic===&lt;br /&gt;
pipe the calculation into the shell calculator&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
space_in_kb=$(echo $1 / 1024 | bc)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Calculate the remainder (modulo) of a division calculation&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
if [[ $(echo &amp;quot;${NUMBER} % 2&amp;quot; | bc) -eq 0 ]]; then&lt;br /&gt;
    echo &amp;quot;${NUMBER} is even&amp;quot;&lt;br /&gt;
else&lt;br /&gt;
    echo &amp;quot;${NUMBER} is odd&amp;quot;&lt;br /&gt;
fi&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or do it in awk if scientific notation maybe involved&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
function calc { awk &amp;quot;BEGIN{print $*}&amp;quot;; }&lt;br /&gt;
&lt;br /&gt;
if [[ $(calc &amp;quot;${SPACE_USED} + ${SPACE_AVAILABLE} - ${DATABASE_SIZE&amp;quot;) -le 0 ]]; then&lt;br /&gt;
    echo &amp;quot;NOK&amp;quot;&lt;br /&gt;
fi&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Script encryption and passphrase protection===&lt;br /&gt;
Encrypt a shell script with the ability to execute the encrypted version&lt;br /&gt;
* from [http://www.commandlinefu.com/commands/browse commandlinefu.com]&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
scrypt(){ [ -n &amp;quot;$1&amp;quot; ]&amp;amp;&amp;amp;{ echo &amp;#039;. &amp;lt;(echo &amp;quot;$(tail -n+2 $0|base64 -d|mcrypt -dq)&amp;quot;); exit;&amp;#039;&amp;gt;$1.scrypt;cat $1|mcrypt|base64 &amp;gt;&amp;gt;$1.scrypt;chmod +x $1.scrypt;};}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Virtual host configuration in Apache http.conf===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;VirtualHost *:80&amp;gt;&lt;br /&gt;
        ServerName dbamon&lt;br /&gt;
        DocumentRoot &amp;quot;/Volumes/data/Sites/dbamon_push&amp;quot;&lt;br /&gt;
        &amp;lt;Directory &amp;quot;/Volumes/data/Sites/dbamon_push&amp;quot;&amp;gt;&lt;br /&gt;
                Options Includes FollowSymLinks&lt;br /&gt;
                AllowOverride All&lt;br /&gt;
                Order allow,deny&lt;br /&gt;
                Allow from all&lt;br /&gt;
        &amp;lt;/Directory&amp;gt;&lt;br /&gt;
&amp;lt;/VirtualHost&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
and in /etc/hosts, add...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
127.0.0.1  dbamon&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Mount a website (or any other remote resource) locally using WebDav===&lt;br /&gt;
Redhat/CentOS&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
yum install fuse-davfs2&lt;br /&gt;
or&lt;br /&gt;
yum install wdfs.x86_64&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Debian&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
apt-get install davfs2&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
then...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo mkdir /mnt/webdav  # or whatever you&amp;#039;d like to call the directory&lt;br /&gt;
sudo mount.davfs [-o option[,option]...] device mount_point&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
In man&amp;#039;s terms, that last line would translate to:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
id  #suppose this returns uid=501 and gid=502&lt;br /&gt;
sudo mount.davfs -o 501,502 https://your/web/site /mnt/webdav&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Mac OSX&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
osascript -e &amp;#039; mount volume &amp;quot;http://username:password@webdav.address:portnum&amp;quot; &amp;#039;&lt;br /&gt;
or&lt;br /&gt;
osascript -e &amp;#039; mount volume &amp;quot;http://username@webdav.address:portnum&amp;quot; &amp;#039;&lt;br /&gt;
or&lt;br /&gt;
osascript -e &amp;#039; try mount volume &amp;quot;http://webdav.address:portnum&amp;quot; &amp;#039;&lt;br /&gt;
or&lt;br /&gt;
mount -t webdav http://webdav.address:portnum /mnt/webdav  # this one won&amp;#039;t show up in the Finder Sidebar.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Add current hostname to list of hosts on an xcat server===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
CMD=&amp;quot;nodels&amp;quot;&lt;br /&gt;
HOST=`hostname`&lt;br /&gt;
(echo &amp;quot;$HOST&amp;quot;; $CMD) | while read server&lt;br /&gt;
do&lt;br /&gt;
    echo &amp;quot;server:$server&amp;quot;&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===What is todays &amp;#039;Day Of the Year&amp;#039; number?===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
DOY=`perl -e &amp;#039;print sub{$_[7]}-&amp;gt;(localtime)+1;&amp;#039;`&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Convert Julian day numbers to dates===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
for day in 8 33 36 61 64 91 96 121 126 152 155 182 187 215 218 244 247 274 279 306 309 335 338 365; do date -d &amp;quot;`date +%Y`-01-01 +$(( ${day} - 1 ))days&amp;quot; +%d-%m-%Y; done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Send crontab job output to a date formatted log file===&lt;br /&gt;
This will run a job every 5 minutes and send the output to a file ending with a time in hours and minutes.&amp;lt;br /&amp;gt;&lt;br /&gt;
The thing to note is the escaped percent signs. This is because a % sign is interpreted by cron to mean a newline character. Everything after the first % is treated as input to the program.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
*/5 *  * * * /var/www/cgi-bin/dbamon_collector.ksh       &amp;gt;/tmp/dbamon_collector.log.$(date &amp;quot;+\%H\%M&amp;quot;) 2&amp;gt;&amp;amp;1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Edit crontab file without crontab -e===&lt;br /&gt;
It can happen that you need to add or modify a line in the crontab of many users or across many servers at once.&amp;lt;br /&amp;gt;&lt;br /&gt;
In principle, there&amp;#039;s nothing wrong with modifying the crontab file directly. You just lose the advantages of file locking (and syntax checking) that crontab -e offers.&amp;lt;br /&amp;gt;&lt;br /&gt;
Here we take a backup of the current crontab, print it out, echo an extra command and ask cron to use these as input (thus overwriting the existing crontab file). Just don&amp;#039;t run this close to midnight :-)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
crontab -l &amp;gt; /tmp/crontab.`date &amp;#039;+%Y%m%d&amp;#039;`&lt;br /&gt;
(&lt;br /&gt;
cat /tmp/crontab.`date +&amp;#039;%Y%m%d&amp;#039;`&lt;br /&gt;
echo &amp;quot;02 10 * * * /home/ibmtools/scripts/oracle/export_parfile.ksh -s SID -f JDBEOP1.parfile&amp;quot;&lt;br /&gt;
) | crontab -&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
crontab -l &amp;gt; /tmp/crontab.backup&lt;br /&gt;
crontab -l &amp;gt; /tmp/crontab.$$&lt;br /&gt;
perl -p -i -e &amp;#039;s!backup_send_tsm_dump!backup_export2tsm!g&amp;#039; /tmp/crontab.$$&lt;br /&gt;
crontab /tmp/crontab.$$&lt;br /&gt;
rm /tmp/crontab.$$&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
crontab -l &amp;gt;$HOME/crontab.$(date &amp;#039;+%Y%m%d&amp;#039;)&lt;br /&gt;
crontab -l | perl -p -e &amp;#039;s|/nas/software/oracle/scripts|/oracle/scripts|&amp;#039; | crontab&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Use shell to convert a number in scientific notation to normal===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
var2convert=&amp;#039;1.2345678e3&amp;#039;&lt;br /&gt;
printf -v var2convert &amp;quot;%.f&amp;quot; $var2convert&lt;br /&gt;
echo $var2convert  # magic!&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Check for jobs running longer that 24 hours===&lt;br /&gt;
Run from the management server across all Unix servers. Checks the 5th column in a ps listing. If it doesn&amp;#039;t find a : (time separator), the process is running longer than 24 hours.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# ---------------------------------------&lt;br /&gt;
# report on long running oraibm processes&lt;br /&gt;
# ---------------------------------------&lt;br /&gt;
01 17,14 * * * rm -f /tmp/lrp.txt;/home/ibmtools/scripts/oracle/dosh -vc \&amp;quot;ps -ef|egrep &amp;#039;oraibm|scripts/oracle&amp;#039;&amp;gt;/tmp/lrp.txt;perl -nae &amp;#039;print if \$F[4] !~/:/&amp;#039; /tmp/lrp.txt\&amp;quot; &amp;gt;&amp;gt;/tmp/lrp.txt;[[ $(egrep -c &amp;#039;oraibm|scripts/or&lt;br /&gt;
acle&amp;#039; /tmp/lrp.txt) -ne 0 ]] &amp;amp;&amp;amp; cat /tmp/lrp.txt|mailx -s &amp;#039;*** long running processes - please check ***&amp;#039; bey9at77@mail.com&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Global find and replace with perl (restricted to list of files provided by Unix find command)===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
find . -type f -exec perl -i -pe &amp;#039;s/something/else/g&amp;#039; {} \;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===perl function to make filenames lower case===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
function lower { &lt;br /&gt;
   perl -e &amp;#039;for (@ARGV) { rename $_, lc($_) unless -e lc($_); }&amp;#039; * &lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===From the management server, search the TNS listener port for each database on a server and make an inline substitution in the ITM config files!===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
for i in `/home/ibmtools/scripts/oracle/dosh -c &amp;quot;ls -al /opt/IBM/ITM/config/*rz*cfg|grep -v lrwx&amp;quot;|awk &amp;#039;{print $NF}&amp;#039;`; do&lt;br /&gt;
    server=`echo $i|cut -d_ -f1 | awk -F&amp;#039;/&amp;#039; &amp;#039;{print $NF}&amp;#039;`&lt;br /&gt;
    db=`echo $i|cut -d&amp;#039;.&amp;#039; -f1 | awk -F&amp;#039;_&amp;#039; &amp;#039;{print $NF}&amp;#039;`&lt;br /&gt;
    OH=`ssh $server grep &amp;quot;^$db&amp;quot; /etc/oratab|cut -d: -f2`&lt;br /&gt;
    LISTENERPORT=`ssh $server cat $OH/network/admin/listener.ora|perl -00 -ne &amp;#039;print $1 if /&amp;#039;$db&amp;#039;.*PORT.*=.*(\d{4})/s&amp;#039;`&lt;br /&gt;
    ssh $server perl -p -i.bak -e &amp;#039;s/1521/&amp;#039;$LISTENERPORT&amp;#039;/&amp;#039; $i&lt;br /&gt;
    ssh $server ls -al ${i}*&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Run a job from cron every Nth day of the month===&lt;br /&gt;
Example. Execute a job every third Saturday of the month.&amp;lt;br /&amp;gt;&lt;br /&gt;
Paste this into a file called calenday and put it in /usr/local/bin so it&amp;#039;s (probably) on the PATH&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/usr/bin/ksh&lt;br /&gt;
&lt;br /&gt;
# ix is the week number of the month (&amp;quot;2&amp;quot;nd Friday of the month, &amp;quot;3&amp;quot;rd Tuesday of the month)&lt;br /&gt;
# dy is the day number in Unix format (0 for Sunday, 1 for Monday, ... 6 for Saturday)&lt;br /&gt;
# eg. &amp;quot;calenday 3 6&amp;quot; returns the date of 3rd Saturday of the month.&lt;br /&gt;
&lt;br /&gt;
ix=$1&lt;br /&gt;
dy=$2&lt;br /&gt;
SCHAR=$((($dy*2)+$dy+1))&lt;br /&gt;
ECHAR=$(($SCHAR+1))&lt;br /&gt;
cal `date &amp;#039;+%m %Y&amp;#039;` | egrep &amp;quot;\&amp;lt;[0-9]{1,2}\&amp;gt;&amp;quot; | cut -c${SCHAR}-${ECHAR} | xargs | awk {&amp;#039;print $&amp;#039;$ix&amp;#039;}&amp;#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Now in crontab, you should be able to do something like this:&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
15 20 * * * [[ `calenday 3 6` -eq `/bin/date &amp;#039;+%d&amp;#039;` ]] &amp;amp;&amp;amp; su - oracle -c &amp;quot;run_my_backup.ksh&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will also work on some Unices..&amp;lt;br /&amp;gt;&lt;br /&gt;
We send backups to a special TSM node on the second Friday of each month. This report must run a day later - but that is not guaranteed to be the second Saturday or even the 3rd. So...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
30 12 8-14 * 5 sleep 86400 &amp;amp;&amp;amp; su - oracle -c &amp;quot;/usr/bin/perl -ne &amp;#039;print if /ORX_M_SOL/ .. /^STOP/&amp;#039; /home/oracle/incoming/dbamon_spool_tsm_*.SOL | grep Archive | grep -v Client | mailx -s &amp;#039;Monthly TSM backups&amp;#039; orareport@xxxxxx.com&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ps listing does not show start time after 24 hours===&lt;br /&gt;
But you can see elapsed time using your own ps coomand&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/usr/bin/ps -eo etime,user,pid,ppid,cpu,start,tty,time,args |tail -n +2|sort&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===ps -ef cuts off args cmd column on Solaris===&lt;br /&gt;
====To see more than 80 characters of the last column on Solaris====&lt;br /&gt;
This shows all the individual arguments to the command&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
pargs &amp;lt;pid&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This shows the ps listing in &amp;#039;compatibility&amp;#039; mode (there are more compatibility commands in /usr/xpg4/bin)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/usr/ucb/ps auww&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====To see more than 80 characters of the last column on AIX====&lt;br /&gt;
This shows the full argument listing of a process (NOTE: no minus sign!)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ps eww &amp;lt;pid&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Remove blank / empty lines from vi ===&lt;br /&gt;
Maybe you cut and pasted a file from Windows and it&amp;#039;s full of blank lines and Control-M&amp;#039;s now&amp;lt;br /&amp;gt;&lt;br /&gt;
There are several methods but I think this is the easiest to remember&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
:g/^$/d&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Right pad a variable===&lt;br /&gt;
a function like rpad in SQL but for Shell&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
function rpad {&lt;br /&gt;
text=$1&lt;br /&gt;
padwidth=$2&lt;br /&gt;
padchar=$3&lt;br /&gt;
echo &amp;quot;$text&amp;quot; | sed -e :a -e &amp;#039;s/^.\{1,&amp;#039;$padwidth&amp;#039;\}$/&amp;amp;\&amp;#039;$padchar&amp;#039;/;ta&amp;#039;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Connect to a Windows server from Linux using rdesktop===&lt;br /&gt;
My remmina stopped working so rolled my own. Very simple really. Put this is a shell.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
tsocks rdesktop -z -P -x m -a 16 -d MAIND -u sbarkley -p ****** -r disk:SOL=$HOME/Documents/SOL -g 95% 150.251.112.38 &amp;amp;&lt;br /&gt;
&lt;br /&gt;
where...&lt;br /&gt;
-z    - enables compression&lt;br /&gt;
-P    - enables bitmap caching (saves network traffic)&lt;br /&gt;
-x m  - disables eye-candy features&lt;br /&gt;
-a 16 - reduce colour pallete to 16 colours&lt;br /&gt;
-d    - domain to connect to&lt;br /&gt;
-u    - username&lt;br /&gt;
-p    - password&lt;br /&gt;
-r    - setup a shared folder&lt;br /&gt;
-g    - geometry (use W x H or percentage)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Slight problems with rdesktop not working 100% of the time. Now using xfreerdp. Seems better...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
xfreerdp -g 90% --ignore-certificate --gdi sw -K -d wdcrhbp05 -u oraibm -p &amp;quot;`cat $HOME/scripts/.oraibm.password`&amp;quot; -T &amp;quot;wdcrhbp05_oraibm&amp;quot; --plugin cliprdr --plugin rdpdr --data disk:SOL:/home/bey9at77/Documents/SOL -- --plugin rdpsnd --data alsa -- 150.251.112.25 &amp;amp;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Reset your password bypassing password rules===&lt;br /&gt;
must be done as root&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
echo &amp;quot;user:new_password&amp;quot; | chpasswd&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Sum the sizes of all files of an ls listing===&lt;br /&gt;
It&amp;#039;ll check to see if the sum of filesizes corresponds with the df -g (or h) listing (can get messed up due to open but deleted files)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cd /oracle/export&lt;br /&gt;
df -g .&lt;br /&gt;
find . -name &amp;quot;*dmp*&amp;quot; -ls |  awk &amp;#039;{ SUM += $7} END { print SUM/1024/1024/1024 }&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Mount an iso image under Linux===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
mkdir -p /mnt/cdrom&lt;br /&gt;
mount -o loop /dev/cdrom /mnt/cdrom&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===How many processors on the machine?===&lt;br /&gt;
* AIX&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
lsdev -C|grep Process|wc -l&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Solaris&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
psrinfo -v|grep &amp;quot;Status of processor&amp;quot;|wc -l&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Linux&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cat /proc/cpuinfo|grep processor|wc -l&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Quick, simple, understandable example of how to use RRDTool===&lt;br /&gt;
* [[RRDTool]]&lt;br /&gt;
&lt;br /&gt;
===Use expect to respond automatically to interactive programs===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/usr/bin/expect -f&lt;br /&gt;
spawn /usr/tivoli/tsm/client/oracle/bin64/tdpoconf passw -tdpo_optfile=/oracle/[lindex $argv 0]/admin/tdpo.opt&lt;br /&gt;
expect &amp;quot;assword:&amp;quot; {send &amp;quot;password\r&amp;quot;}&lt;br /&gt;
expect &amp;quot;assword:&amp;quot; {send &amp;quot;password\r&amp;quot;}&lt;br /&gt;
expect &amp;quot;assword:&amp;quot; {send &amp;quot;password\r&amp;quot;}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Use expect to allow file copy with scp (if ssh keys are not an option)===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/usr/bin/expect -f&lt;br /&gt;
spawn scp /home/oracle/.profile oracle@hn512:/tmp/prfl&lt;br /&gt;
set pass &amp;quot;thepassword&amp;quot;&lt;br /&gt;
expect {&lt;br /&gt;
        password: {send &amp;quot;$pass\r&amp;quot; ; exp_continue}&lt;br /&gt;
        eof exit&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Within a shell script set up simultaneous output to both terminal and a file using a FIFO (named pipes)===&lt;br /&gt;
or &amp;quot;How to send shell output to screen/stdout as well as to a logfile using tee and redirection with exec&amp;quot;&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
examples [http://www.unix.com/shell-programming-and-scripting/85584-redirect-within-ksh.html here on unix.com]&lt;br /&gt;
* general info on redirections [http://www.catonmat.net/blog/bash-one-liners-explained-part-three/ here at catonmat.net]&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/ksh&lt;br /&gt;
&lt;br /&gt;
REDIR=test.redir&lt;br /&gt;
FIFO=test.pipe&lt;br /&gt;
[[ -e $FIFO ]] || mkfifo $FIFO&lt;br /&gt;
&lt;br /&gt;
# make a new channel(3) and copy channel 1&amp;#039;s destination as its own (does NOT POINT TO channel 1&amp;#039;s destination)&lt;br /&gt;
# this allows the normal output to continue to STDOUT but also get printed to whatever file is attached to channel 3&lt;br /&gt;
exec 3&amp;gt;&amp;amp;1&lt;br /&gt;
&lt;br /&gt;
# anything coming in on the pipe, send it to $REDIR and to channel 3&lt;br /&gt;
tee $REDIR &amp;lt;$FIFO &amp;gt;&amp;amp;3 &amp;amp;&lt;br /&gt;
&lt;br /&gt;
# redirect STDOUT to the pipe&lt;br /&gt;
exec &amp;gt; $FIFO&lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;going to default output&amp;quot;&lt;br /&gt;
echo &amp;quot;forcing to channel 1&amp;quot; &amp;gt;&amp;amp;1&lt;br /&gt;
echo &amp;quot;forcing to channel 2&amp;quot; &amp;gt;&amp;amp;2&lt;br /&gt;
echo &amp;quot;forcing to channel 3&amp;quot; &amp;gt;&amp;amp;3&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====More elaborate example====&lt;br /&gt;
found [http://stackoverflow.com/questions/2288939/create-a-pipe-that-writes-to-multiple-files-tee here on stackoverflow]&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/sh&lt;br /&gt;
&lt;br /&gt;
# Author: Harvey Chapman &amp;lt;hchapman _AT_ 3gfp.com&amp;gt;&lt;br /&gt;
# Description: POSIX shell functions that can be used with tee to simultaneously put&lt;br /&gt;
#              stderr and stdout to both a file and stdout&lt;br /&gt;
#&lt;br /&gt;
# Based on:&lt;br /&gt;
#    Re: How to redirect stderr and stdout to a file plus display at the same time&lt;br /&gt;
#    http://www.travishartwell.net/blog/2006/08/19_2220&lt;br /&gt;
&lt;br /&gt;
#&lt;br /&gt;
# Original example function from Travis Hartwell&amp;#039;s blog.&lt;br /&gt;
# Note: I&amp;#039;ve made minor changes to it.&lt;br /&gt;
example()&lt;br /&gt;
{&lt;br /&gt;
  OUTPUT_LOG=output.log&lt;br /&gt;
  OUTPUT_PIPE=output.pipe&lt;br /&gt;
&lt;br /&gt;
  # This should really be -p to test that it&amp;#039;s a pipe.&lt;br /&gt;
  if [ ! -e $OUTPUT_PIPE ]; then&lt;br /&gt;
      mkfifo $OUTPUT_PIPE&lt;br /&gt;
  fi&lt;br /&gt;
&lt;br /&gt;
  # This should really be -f to test that it&amp;#039;s a regular file.&lt;br /&gt;
  if [ -e $OUTPUT_LOG ]; then&lt;br /&gt;
      rm $OUTPUT_LOG&lt;br /&gt;
  fi&lt;br /&gt;
&lt;br /&gt;
  exec 3&amp;gt;&amp;amp;1 4&amp;gt;&amp;amp;2&lt;br /&gt;
  tee $OUTPUT_LOG &amp;lt; $OUTPUT_PIPE &amp;gt;&amp;amp;3 &amp;amp;&lt;br /&gt;
  tpid=$!&lt;br /&gt;
  exec &amp;gt; $OUTPUT_PIPE 2&amp;gt;&amp;amp;1&lt;br /&gt;
&lt;br /&gt;
  echo &amp;quot;This is on standard out&amp;quot;&lt;br /&gt;
  echo &amp;quot;This is on standard err&amp;quot; &amp;gt;&amp;amp;2&lt;br /&gt;
&lt;br /&gt;
  exec 1&amp;gt;&amp;amp;3 3&amp;gt;&amp;amp;- 2&amp;gt;&amp;amp;4 4&amp;gt;&amp;amp;-&lt;br /&gt;
  wait $tpid&lt;br /&gt;
&lt;br /&gt;
  rm $OUTPUT_PIPE&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
# A slightly reduced version of example()&lt;br /&gt;
example2()&lt;br /&gt;
{&lt;br /&gt;
  OUTPUT_LOG=output.log&lt;br /&gt;
  OUTPUT_PIPE=output.pipe&lt;br /&gt;
&lt;br /&gt;
  rm -f $OUTPUT_PIPE&lt;br /&gt;
  mkfifo $OUTPUT_PIPE&lt;br /&gt;
  rm -f $OUTPUT_LOG&lt;br /&gt;
&lt;br /&gt;
  tee $OUTPUT_LOG &amp;lt; $OUTPUT_PIPE &amp;amp;&lt;br /&gt;
  tpid=$!&lt;br /&gt;
&lt;br /&gt;
  exec 3&amp;gt;&amp;amp;1 4&amp;gt;&amp;amp;2 &amp;gt;$OUTPUT_PIPE 2&amp;gt;&amp;amp;1&lt;br /&gt;
&lt;br /&gt;
  echo &amp;quot;This is on standard out&amp;quot;&lt;br /&gt;
  echo &amp;quot;This is on standard err&amp;quot; &amp;gt;&amp;amp;2&lt;br /&gt;
&lt;br /&gt;
  exec 1&amp;gt;&amp;amp;3 3&amp;gt;&amp;amp;- 2&amp;gt;&amp;amp;4 4&amp;gt;&amp;amp;-&lt;br /&gt;
  wait $tpid&lt;br /&gt;
  rm -f $OUTPUT_PIPE&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
#&lt;br /&gt;
# Logging methods based on above. See the example below for how to use them.&lt;br /&gt;
#&lt;br /&gt;
&lt;br /&gt;
# Usage: start_logging [delete_existing_logfile]&lt;br /&gt;
start_logging()&lt;br /&gt;
{&lt;br /&gt;
  # Check to see if OUTPUT_LOG and OUTPUT_PIPE need to be defined.&lt;br /&gt;
  if [ -z &amp;quot;$OUTPUT_LOG&amp;quot; ]; then&lt;br /&gt;
    OUTPUT_LOG=output.log&lt;br /&gt;
  fi&lt;br /&gt;
  if [ -z &amp;quot;$OUTPUT_PIPE&amp;quot; ]; then&lt;br /&gt;
    OUTPUT_PIPE=output.pipe&lt;br /&gt;
  fi&lt;br /&gt;
  # Make sure that we&amp;#039;re not already logging.&lt;br /&gt;
  if [ -n &amp;quot;$OUTPUT_PID&amp;quot; ]; then&lt;br /&gt;
    echo &amp;quot;Logging already started!&amp;quot;&lt;br /&gt;
    return 1&lt;br /&gt;
  fi&lt;br /&gt;
&lt;br /&gt;
  # Always remove the log and pipe first.&lt;br /&gt;
  rm -f $OUTPUT_PIPE&lt;br /&gt;
  # Delete the logfile first if told to.&lt;br /&gt;
  if [ &amp;quot;$1&amp;quot; = delete_existing_logfile ]; then&lt;br /&gt;
    rm -f $OUTPUT_LOG&lt;br /&gt;
  fi&lt;br /&gt;
&lt;br /&gt;
  mkfifo $OUTPUT_PIPE&lt;br /&gt;
  tee -a $OUTPUT_LOG &amp;lt; $OUTPUT_PIPE &amp;amp;&lt;br /&gt;
  OUTPUT_PID=$!&lt;br /&gt;
&lt;br /&gt;
  exec 3&amp;gt;&amp;amp;1 4&amp;gt;&amp;amp;2 &amp;gt;$OUTPUT_PIPE 2&amp;gt;&amp;amp;1&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
stop_logging()&lt;br /&gt;
{&lt;br /&gt;
  # Make sure that we&amp;#039;re currently logging.&lt;br /&gt;
  if [ -z &amp;quot;$OUTPUT_PID&amp;quot; ]; then&lt;br /&gt;
    echo &amp;quot;Logging not yet started!&amp;quot;&lt;br /&gt;
    return 1&lt;br /&gt;
  fi&lt;br /&gt;
  exec 1&amp;gt;&amp;amp;3 3&amp;gt;&amp;amp;- 2&amp;gt;&amp;amp;4 4&amp;gt;&amp;amp;-&lt;br /&gt;
  wait $OUTPUT_PID&lt;br /&gt;
  rm -f $OUTPUT_PIPE&lt;br /&gt;
  unset OUTPUT_PID&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
example3()&lt;br /&gt;
{&lt;br /&gt;
  start_logging&lt;br /&gt;
  #start_logging delete_existing_logfile&lt;br /&gt;
  echo &amp;quot;This is on standard out&amp;quot;&lt;br /&gt;
  echo &amp;quot;This is on standard err&amp;quot; &amp;gt;&amp;amp;2&lt;br /&gt;
  stop_logging&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===RedHat root filesystem has gone read-only===&lt;br /&gt;
* [http://www.unixarena.com/2013/09/redhat-linux-how-to-fix-read-only-root.html How to fix read only root file system]&lt;br /&gt;
&lt;br /&gt;
===Kill all processes for a user===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
for prc in `ps -ef | grep -E &amp;quot;^ +[o]racle&amp;quot; | awk &amp;#039;{print $2}&amp;#039;`; do&lt;br /&gt;
    kill $prc&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===isRGHere===&lt;br /&gt;
Checks if resource group is on this leg of an HACMP cluster. Returns 0 if true else 1.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/usr/bin/ksh&lt;br /&gt;
&lt;br /&gt;
SCRIPT=`basename $0`&lt;br /&gt;
&lt;br /&gt;
function rctest&lt;br /&gt;
{&lt;br /&gt;
exitcode=$1&lt;br /&gt;
msg=$2&lt;br /&gt;
if [ $exitcode -ne 0 ]; then&lt;br /&gt;
        echo &amp;quot;********************************************************************************&amp;quot;&lt;br /&gt;
        echo &amp;quot;\nScript $SCRIPT finished with errors.&amp;quot;&lt;br /&gt;
        echo &amp;quot;$msg.&amp;quot;&lt;br /&gt;
        echo &amp;quot;Returncode : $exitcode.&amp;quot;&lt;br /&gt;
        echo &amp;quot;\n********************************************************************************&amp;quot;&lt;br /&gt;
&lt;br /&gt;
        fi&lt;br /&gt;
exit $exitcode&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
RGINFO=/usr/es/sbin/cluster/utilities/clRGinfo&lt;br /&gt;
[[ ! -f $RGINFO ]] &amp;amp;&amp;amp;  rctest 1 &amp;quot;clRGinfo not found&amp;quot;&lt;br /&gt;
&lt;br /&gt;
if [ $# -eq 1 ]&lt;br /&gt;
then&lt;br /&gt;
        RG=`echo $1 | cut -c 1-14`&lt;br /&gt;
else&lt;br /&gt;
        rctest 10  &amp;quot;Usage: `basename $0` &amp;lt;RG name&amp;gt;&amp;quot;&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
$RGINFO |grep -qwp $RG ||  rctest 9 &amp;quot;$RG is not defined&amp;quot;&lt;br /&gt;
&lt;br /&gt;
THISNODE=`/usr/es/sbin/cluster/utilities/get_local_nodename | cut -c 1-14`&lt;br /&gt;
$RGINFO |grep -wp $RG |grep -w $THISNODE |grep -wq ONLINE&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===AIX: add a user to a group===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
chgrpmem -m + oracle ibmtls&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Find swear words in scripts by comparing it to a list found on the internet===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
wget &amp;quot;http://www.bannedwordlist.com/lists/swearWords.csv&amp;quot; -O /tmp/s ; for word in $(cat /tmp/s | sed -e &amp;#039;s/ /_/g&amp;#039; -e &amp;#039;s/,/ /g&amp;#039;) ; do grep -wR $word *; done | less&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===grep -p (for paragraph) works on AIX but not on Linux or Solaris===&lt;br /&gt;
Use awk instead&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
awk &amp;#039;BEGIN {FS=&amp;quot;\n&amp;quot; RS=&amp;quot;\n\n&amp;quot;} /search pattern/ { do something }&amp;#039; &amp;lt;file&amp;gt;&lt;br /&gt;
/usr/xpg4/bin/awk &amp;#039;BEGIN {RS=&amp;quot;\n\n&amp;quot;;FS=&amp;quot;\n&amp;quot;} /AGRHDWQ1/ {print $2}&amp;#039; dsm.sys | awk &amp;#039;{print $NF}&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
this prints the last word of the second &amp;#039;&amp;#039;line&amp;#039;&amp;#039; in the paragraph in dsm.sys that contains the search term AGRHDWQ1.&amp;lt;br /&amp;gt;&lt;br /&gt;
Or slightly simpler...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
awk -v RS=&amp;#039;&amp;#039; &amp;#039;/NHAPPLP1/&amp;#039; /etc/tsm/dsm.sys     # (use /usr/xpg4/bin/awk on Solaris)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or, case insensitively:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
awk -v RS=&amp;#039;&amp;#039; &amp;#039;tolower($0) ~/so_u_clubqa_orx_d_cab/&amp;#039; /etc/tsm/dsm.sys&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Using -v means you don&amp;#039;t have to use a BEGIN section.&lt;br /&gt;
&lt;br /&gt;
===debug/redirect log of a shell===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/usr/bin/ksh&lt;br /&gt;
exec 2&amp;gt;/tmp/mytest&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Different ways of Iteration in korn shell with a while loop===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
IFS=&amp;quot;|&amp;quot;&lt;br /&gt;
exec 0&amp;lt;$statfile&lt;br /&gt;
while read host db started stopped&lt;br /&gt;
do&lt;br /&gt;
    rrdfile=&amp;quot;export_duration_${host}_${db}.rrd&amp;quot;&lt;br /&gt;
    $RRDTOOL update ${RRDDIR}/${rrdfile} $started:$started $stopped&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
while read host db started stopped&lt;br /&gt;
do&lt;br /&gt;
    rrdfile=&amp;quot;export_duration_${host}_${db}.rrd&amp;quot;&lt;br /&gt;
    $RRDTOOL update ${RRDDIR}/${rrdfile} $started:$started $stopped&lt;br /&gt;
done &amp;lt;statfile&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    cat $statfile | sort -nk4 | while IFS=\| read host db type started stopped&lt;br /&gt;
    do&lt;br /&gt;
        [[ &amp;quot;$stopped&amp;quot; == &amp;quot;&amp;quot; ]] &amp;amp;&amp;amp; continue&lt;br /&gt;
        rrdfile=&amp;quot;export_duration_${host}_${db}.rrd&amp;quot;&lt;br /&gt;
        $RRDTOOL update ${RRDDIR}/${rrdfile} ${started}:${started}:${stopped}&lt;br /&gt;
        [[ $? -ne 0 ]] &amp;amp;&amp;amp; echo &amp;quot;nok: $?&amp;quot;&lt;br /&gt;
    done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Filesystem 100% full, what&amp;#039;s taking up all the space?===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
find /oracle/endur -xdev -ls|sort -nr +6|head&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/dev/esb01fs010001      1.00      0.00  100%     1838    69% /oracle&lt;br /&gt;
beuxdsysesb01:root[/root]# cd /oracle&lt;br /&gt;
beuxdsysesb01:root[/oracle]# du -gsx * | sort -n&lt;br /&gt;
0.00    checkpoints&lt;br /&gt;
0.00    flash_recovery_area&lt;br /&gt;
0.00    lost+found&lt;br /&gt;
0.00    oraInst.loc&lt;br /&gt;
0.00    oraInventory&lt;br /&gt;
0.09    admin&lt;br /&gt;
0.99    diag&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
cd  diag and repeat until culprits are found&lt;br /&gt;
&lt;br /&gt;
===Show paged memory hogs on AIX===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
svmon -Pt20 | perl -e &amp;#039;while(&amp;lt;&amp;gt;){print if($.==2||$&amp;amp;&amp;amp;&amp;amp;!$s++);$.=0 if(/^-+$/)}&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Capitalise the first letter of a word in Korn Shell===&lt;br /&gt;
Not as easy as it sounds if it needs to work in non-ksh93 shells&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
function capit { &lt;br /&gt;
    typeset -u first&lt;br /&gt;
    first=${1%&amp;quot;${1#?}&amp;quot;}&lt;br /&gt;
    printf &amp;quot;%s\n&amp;quot; &amp;quot;${first}${1#?}&amp;quot;&lt;br /&gt;
    return 0&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or maybe more neatly done in Perl...&amp;lt;br /&amp;gt;&lt;br /&gt;
This will capitalise each word in a sentence passed into it&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
function capit { &lt;br /&gt;
    echo &amp;quot;$1&amp;quot; |  perl -pe &amp;quot;s/([\w&amp;#039;]+)/\u\L\1/g&amp;quot;&lt;br /&gt;
    return 0&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Remove / rename a directory / file containing weird control characters===&lt;br /&gt;
Use ls with -i to see inode listing&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ls -bali&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Use find with -inum to get the filename and -exec to remove it&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
find . -inum &amp;lt;inode from ls listing&amp;gt; -exec rm -f {} \;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Run a local script on a remote host===&lt;br /&gt;
Doing it this way means we do not need to scp the shell over to the host before executing it!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ssh user@host &amp;#039;sh&amp;#039; &amp;lt; your_script.sh&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
First of all, this command is a redirection: your shell will open the file your_script.sh and feed it as input to the ssh command. ssh, in turn, will tunnel its stdin to the remote command, namely, sh instance. And sh without arguments reads its script from stdin. So we got sh instance, which is launched on remote host, but reads commands from your local file.&lt;br /&gt;
&lt;br /&gt;
===Get a list of running instances - but only those started by the current user===&lt;br /&gt;
This is the way I wanted to do it but there&amp;#039;s an issue. Where does that spare } character come from? Anyone?&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ps -ef | grep [p]mon | awk -v dbowner=$(id -un) &amp;#039;{ if ($1==dbowner) { gsub(/ora_pmon_/,&amp;quot;&amp;quot;,$NF); print $NF; } }&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
ps listing&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ ps -ef | grep [p]mon&lt;br /&gt;
  oracle 13304024        1   0   Jun 07      -  2:39 ora_pmon_reportk&lt;br /&gt;
  oracle 26018178        1   0   Jun 07      -  3:01 ora_pmon_dwh_perf&lt;br /&gt;
  oracle 29229432        1   0   Jun 07      -  2:30 ora_pmon_adso&lt;br /&gt;
 oraebso 18022994        1   0   Jun 07      -  2:38 ora_pmon_EBSO&lt;br /&gt;
  oracle 30278192        1   0   Jun 07      -  2:48 ora_pmon_owb112k&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Results of above command&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
reportk&lt;br /&gt;
dwh_perf&lt;br /&gt;
adso&lt;br /&gt;
}&lt;br /&gt;
owb112k&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Workaround 1. Send the ps listing to a file and work on it without pipes. Works but it&amp;#039;s a bit long-winded especially as we have to clean up afterwards.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ps -ef | grep [p]mon&amp;gt;/tmp/results.$$ 2&amp;gt;/dev/null; awk -v dbowner=$(id -un) &amp;#039;{ if ($1==dbowner) { gsub(/ora_pmon_/,&amp;quot;&amp;quot;,$NF); print $NF; } }&amp;#039; /tmp/results.$$; rm -f /tmp/results.$$&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Workaround 2. Don&amp;#039;t like the grep -v but until I find out where that } is coming from..&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ps -ef | grep [p]mon | awk -v dbowner=$(id -un) &amp;#039;{ if ($1==dbowner) { gsub(/ora_pmon_/,&amp;quot;&amp;quot;,$NF); print $NF; } }&amp;#039; | egrep -v &amp;#039;grep|}|ASM&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Return a list of Oracle databases running on a list of remote servers===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/ksh&lt;br /&gt;
&lt;br /&gt;
serverlist=`cat /home/tools/ini/system/oracle_servers | sort -n | tr &amp;quot;\n&amp;quot; &amp;quot; &amp;quot;`&lt;br /&gt;
&lt;br /&gt;
if [ -z &amp;quot;${serverlist}&amp;quot; ]&lt;br /&gt;
then&lt;br /&gt;
    echo &amp;quot;no servers found&amp;quot; &amp;amp;&amp;amp; exit 1&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
for server in ${serverlist}&lt;br /&gt;
do&lt;br /&gt;
    ssh ${server} &amp;quot;ps -ef | grep [o]ra_pmon_&amp;quot; &amp;gt;/tmp/${server}.dblist&lt;br /&gt;
done&lt;br /&gt;
&lt;br /&gt;
for server in ${serverlist}&lt;br /&gt;
do&lt;br /&gt;
    cat /tmp/${server}.dblist | awk -F_ -v SRV=${server} &amp;#039;BEGIN {print SRV &amp;quot;:&amp;quot;} {print $NF}&amp;#039; | tr &amp;quot;\n&amp;quot; &amp;quot; &amp;quot;&lt;br /&gt;
    echo&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Clever trick to check whether SQL output needs sending to someone===&lt;br /&gt;
Using an exit status from SQL*Plus back to the shell so we can decide what to do.  Nice one!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
tempfile=/tmp/audit_locked_accounts_$ORACLE_SID.txt&lt;br /&gt;
&lt;br /&gt;
# Start sqlplus and check for locked accounts&lt;br /&gt;
sqlplus -S &amp;quot;/ as sysdba&amp;quot; &amp;lt;&amp;lt; EOF &amp;gt; $tempfile&lt;br /&gt;
set pages 0&lt;br /&gt;
select &amp;#039;The following accounts were found to be unlocked and should not be&amp;#039;&lt;br /&gt;
from dual;&lt;br /&gt;
&lt;br /&gt;
def exit_status = 0&lt;br /&gt;
col xs new_value exit_status&lt;br /&gt;
&lt;br /&gt;
select username&lt;br /&gt;
,      account_status&lt;br /&gt;
,      1 as xs&lt;br /&gt;
from   dba_users&lt;br /&gt;
where  account_status != &amp;#039;LOCKED&amp;#039;&lt;br /&gt;
and    username in (&amp;#039;HR&amp;#039;, &amp;#039;SCOTT&amp;#039;, &amp;#039;OUTLN&amp;#039;, &amp;#039;MDSYS&amp;#039;, &amp;#039;CTXSYS&amp;#039;)&lt;br /&gt;
/&lt;br /&gt;
exit &amp;amp;exit_status&lt;br /&gt;
EOF&lt;br /&gt;
&lt;br /&gt;
# If the exit status of sqlplus was not 0 then we will send an email&lt;br /&gt;
if [ $? != 0 ]; then&lt;br /&gt;
    mail -s &amp;quot;Accounts Unlocked in $ORACLE_SID&amp;quot; oracle &amp;lt; $tempfile&lt;br /&gt;
fi&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Check RMAN logfiles for errors from cron every day===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
00 09 * * * /home/tools/scripts/oracle/dosh &amp;#039;find /home/tools/logs/rman -name &amp;quot;*online.log&amp;quot; -mtime -1 -exec sed -ne &amp;quot;/^RMAN-/,/^$/p&amp;quot; {} \\; -ls&amp;#039; | mailx&lt;br /&gt;
 -s &amp;#039;RMAN errors last night&amp;#039; stuart@domain.com&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/home/ibmtools/scripts/oracle/dosh &amp;#039;find /oracle/export -name &amp;quot;expdp*log&amp;quot; -mtime -1 -exec grep ORA- {} \; -ls&amp;#039; | mailx -s &amp;#039;Datapump errors for Baxter last night&amp;#039; stuart@domain.com&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===An alternative to getopts===&lt;br /&gt;
These methods have the advantage of allowing arguments of any length not just 1 character&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
countArgs=$#&lt;br /&gt;
while [[ $# -gt 0 ]]&lt;br /&gt;
do&lt;br /&gt;
    idx1=$($ECHO $1|$GREP &amp;quot;=&amp;quot;|wc -l)&lt;br /&gt;
    if [[ $idx1 -gt 0 ]]; then&lt;br /&gt;
        key=$($ECHO $1|$CUT -d &amp;#039;=&amp;#039; -f 1)&lt;br /&gt;
        value=$($ECHO $1|$CUT -d &amp;#039;=&amp;#039; -f 2)&lt;br /&gt;
    else&lt;br /&gt;
        key=$($ECHO $1|$CUT -d &amp;#039;=&amp;#039; -f 1)&lt;br /&gt;
        idx2=$($ECHO $1|$GREP &amp;quot;^-&amp;quot;|wc -l)&lt;br /&gt;
        if [[ $idx2 -eq 0 ]]; then&lt;br /&gt;
            $ECHO -e &amp;quot;\n ERROR: $1 is an unsupported argument passed to agentDeploy.sh.\n&amp;quot;  &lt;br /&gt;
            usage&lt;br /&gt;
            exit 1&lt;br /&gt;
        fi&lt;br /&gt;
    fi&lt;br /&gt;
&lt;br /&gt;
    case &amp;quot;$key&amp;quot; in&lt;br /&gt;
    -help)&lt;br /&gt;
        if [[ $upgradeFlag ]]; then&lt;br /&gt;
            upgradeUsage&lt;br /&gt;
        else&lt;br /&gt;
            freshUsage&lt;br /&gt;
        fi&lt;br /&gt;
        exit 0;;&lt;br /&gt;
    AGENT_BASE_DIR)&lt;br /&gt;
        agentBaseDir=$($ECHO $value|$SED &amp;#039;s/\/$//&amp;#039;)&lt;br /&gt;
        checkBaseFlag=TRUE;;&lt;br /&gt;
    OMS_HOST)&lt;br /&gt;
        omsHost=$value&lt;br /&gt;
        checkOMSHost=TRUE;;&lt;br /&gt;
    EM_UPLOAD_PORT)&lt;br /&gt;
        omsPort=$value&lt;br /&gt;
        checkOMSPort=TRUE;;&lt;br /&gt;
    AGENT_INSTANCE_HOME)&lt;br /&gt;
        instHome=$($ECHO $value | $SED &amp;#039;s/\/$//&amp;#039;);;&lt;br /&gt;
    AGENT_REGISTRATION_PASSWORD)&lt;br /&gt;
        pswd=$value;;&lt;br /&gt;
    s_encrSecurePwd)&lt;br /&gt;
        pswd=$value;;  &lt;br /&gt;
    RESPONSE_FILE)&lt;br /&gt;
        rspFlag=TRUE  &lt;br /&gt;
        rspLoc=$value;;&lt;br /&gt;
    OLD_AGENT_VERSION)&lt;br /&gt;
        oldAgentVersion=$value;;            &lt;br /&gt;
    OLDHOME)&lt;br /&gt;
        oldHome=$value;;    &lt;br /&gt;
    -debug)&lt;br /&gt;
        debugSwitch=TRUE;;&lt;br /&gt;
    -forceConfigure)&lt;br /&gt;
        forceFlag=TRUE;;&lt;br /&gt;
    -configOnly)&lt;br /&gt;
        configFlag=TRUE    &lt;br /&gt;
        validationFlag=TRUE;;&lt;br /&gt;
    -agentImageLocation)&lt;br /&gt;
        archiveLoc=$value&lt;br /&gt;
        checkArchiveFlag=TRUE;;&lt;br /&gt;
    -invPtrLoc) shift&lt;br /&gt;
        ptrLoc=$1;;&lt;br /&gt;
    -Upgrade)&lt;br /&gt;
        UpgradeFlag=TRUE&lt;br /&gt;
        validFlag=TRUE;;&lt;br /&gt;
    INVENTORY_LOCATION)&lt;br /&gt;
        validFlag=TRUE;;&lt;br /&gt;
    b_forceInstCheck)&lt;br /&gt;
        validFlag=TRUE&lt;br /&gt;
        forcefullFlag=TRUE;;&lt;br /&gt;
    -prereqOnly)&lt;br /&gt;
        validationFlag=TRUE&lt;br /&gt;
        prereqFlag=TRUE;;&lt;br /&gt;
    -executeRootsh)&lt;br /&gt;
        validFlag=TRUE;;&lt;br /&gt;
    *)  idx=$($ECHO $1|$GREP &amp;quot;^-&amp;quot;|wc -l)&lt;br /&gt;
        if [[ $idx -eq 0 ]]; then&lt;br /&gt;
            validFlag=TRUE&lt;br /&gt;
        else&lt;br /&gt;
            $ECHO -e &amp;quot;\n ERROR: Invalid argument $key passed.&amp;quot;&lt;br /&gt;
            usage&lt;br /&gt;
            exit 1          &lt;br /&gt;
        fi&lt;br /&gt;
    esac&lt;br /&gt;
    shift&lt;br /&gt;
done&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
another way - found in /etc/init.d/functions (daemon function) in Fedora&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    while [ &amp;quot;$1&amp;quot; != &amp;quot;${1##[-+]}&amp;quot; ]; do&lt;br /&gt;
        case $1 in&lt;br /&gt;
        &amp;#039;&amp;#039;)&lt;br /&gt;
            echo $&amp;quot;$0: Usage: daemon [+/-nicelevel] {program}&amp;quot; &amp;quot;[arg1]...&amp;quot;&lt;br /&gt;
            return 1&lt;br /&gt;
            ;;&lt;br /&gt;
        --check)&lt;br /&gt;
            base=$2&lt;br /&gt;
            gotbase=&amp;quot;yes&amp;quot;&lt;br /&gt;
            shift 2&lt;br /&gt;
            ;;&lt;br /&gt;
        --check=?*)&lt;br /&gt;
            base=${1#--check=}&lt;br /&gt;
            gotbase=&amp;quot;yes&amp;quot;&lt;br /&gt;
            shift&lt;br /&gt;
            ;;&lt;br /&gt;
        --user)&lt;br /&gt;
            user=$2&lt;br /&gt;
            shift 2&lt;br /&gt;
            ;;&lt;br /&gt;
        --user=?*)&lt;br /&gt;
            user=${1#--user=}&lt;br /&gt;
            shift&lt;br /&gt;
            ;;&lt;br /&gt;
        --pidfile)&lt;br /&gt;
            pid_file=$2&lt;br /&gt;
            shift 2&lt;br /&gt;
            ;;&lt;br /&gt;
        --pidfile=?*)&lt;br /&gt;
            pid_file=${1#--pidfile=}&lt;br /&gt;
            shift&lt;br /&gt;
            ;;&lt;br /&gt;
        --force)&lt;br /&gt;
            force=&amp;quot;force&amp;quot;&lt;br /&gt;
            shift&lt;br /&gt;
            ;;&lt;br /&gt;
        [-+][0-9]*)&lt;br /&gt;
            nice=&amp;quot;nice -n $1&amp;quot;&lt;br /&gt;
            shift&lt;br /&gt;
            ;;&lt;br /&gt;
        *)&lt;br /&gt;
            echo $&amp;quot;$0: Usage: daemon [+/-nicelevel] {program}&amp;quot; &amp;quot;[arg1]...&amp;quot;&lt;br /&gt;
            return 1&lt;br /&gt;
            ;;&lt;br /&gt;
      esac&lt;br /&gt;
    done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
another way - found in adstrtal.sh (middleware start script for EBS)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#&lt;br /&gt;
# Parse Arguments&lt;br /&gt;
#&lt;br /&gt;
&lt;br /&gt;
for nxtarg in $*&lt;br /&gt;
do&lt;br /&gt;
  arg=`echo $nxtarg | sed &amp;#039;s/^//&amp;#039;`&lt;br /&gt;
&lt;br /&gt;
  case $arg in&lt;br /&gt;
    -secureapps)    if test &amp;quot;$secureapps&amp;quot; = &amp;quot;&amp;quot; ; then&lt;br /&gt;
                       secureapps=$arg&lt;br /&gt;
                    else&lt;br /&gt;
                       echo &amp;quot;$0: Duplicate Argument passed : $arg&amp;quot;&lt;br /&gt;
                       usage&lt;br /&gt;
                    fi&lt;br /&gt;
                ;;&lt;br /&gt;
    -nodbchk)       if test &amp;quot;$nodbchk&amp;quot; = &amp;quot;&amp;quot; ; then&lt;br /&gt;
                       nodbchk=$arg&lt;br /&gt;
                    else&lt;br /&gt;
                       echo &amp;quot;$0: Duplicate Argument passed : $arg&amp;quot;&lt;br /&gt;
                       usage&lt;br /&gt;
                    fi&lt;br /&gt;
                ;;&lt;br /&gt;
    -nopromptmsg)   if test &amp;quot;$nopromptmsg&amp;quot; = &amp;quot;&amp;quot; ; then&lt;br /&gt;
                       nopromptmsg=$arg&lt;br /&gt;
                    else&lt;br /&gt;
                       echo &amp;quot;$0: Duplicate Argument passed : $arg&amp;quot;&lt;br /&gt;
                       usage&lt;br /&gt;
                    fi&lt;br /&gt;
                ;;&lt;br /&gt;
    *)              if test &amp;quot;$unpw&amp;quot; = &amp;quot;&amp;quot; ; then&lt;br /&gt;
                       unpw=$arg&lt;br /&gt;
                    else&lt;br /&gt;
                       echo &amp;quot;$0: Duplicate Argument passed : $arg&amp;quot;&lt;br /&gt;
                       usage&lt;br /&gt;
                    fi&lt;br /&gt;
  esac&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
and another in adautocfg.sh&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
for myarg in $*&lt;br /&gt;
do&lt;br /&gt;
&lt;br /&gt;
  arg=`echo $myarg | sed &amp;#039;s/^-//&amp;#039;`&lt;br /&gt;
  case $arg in&lt;br /&gt;
    appspass=*)&lt;br /&gt;
            appspass=`echo $arg | sed &amp;#039;s/appspass=//g&amp;#039;`&lt;br /&gt;
            shift&lt;br /&gt;
            ;;&lt;br /&gt;
    nocustom)&lt;br /&gt;
            myparams=&amp;quot;$myparams $arg&amp;quot;&lt;br /&gt;
            shift&lt;br /&gt;
            ;;&lt;br /&gt;
    noversionchecks)&lt;br /&gt;
            myparams=&amp;quot;$myparams $arg&amp;quot;&lt;br /&gt;
            shift&lt;br /&gt;
            ;;&lt;br /&gt;
    promptmsg=*)&lt;br /&gt;
            promptmsg=`echo $arg | sed &amp;#039;s/promptmsg=//g&amp;#039;`&lt;br /&gt;
            shift&lt;br /&gt;
            ;;&lt;br /&gt;
        *)  echo &amp;quot;$0: unrecognized action specified&amp;quot;&lt;br /&gt;
            exit 1&lt;br /&gt;
  esac&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Run a script on multiple servers===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/ksh&lt;br /&gt;
# ==============================================================================&lt;br /&gt;
# Name         : dosh   (Distributed Oracle SHell)&lt;br /&gt;
# Description  : Runs a command on all Oracle servers&lt;br /&gt;
#&lt;br /&gt;
# Parameters   : h - displays help&lt;br /&gt;
#                v - verbose (default, like all unix commands is silent)&lt;br /&gt;
#                c - command to be executed&lt;br /&gt;
#&lt;br /&gt;
# Example      : ./dosh -v -c &amp;#039;ls -al&amp;#039;&lt;br /&gt;
#&lt;br /&gt;
# Modification History&lt;br /&gt;
# ====================&lt;br /&gt;
# When      Who               What&lt;br /&gt;
# ========= ================= ==================================================&lt;br /&gt;
# 08-FEB-13 Stuart Barkley    Created&lt;br /&gt;
# ==============================================================================&lt;br /&gt;
&lt;br /&gt;
# --------------------------------------------------------------------------&lt;br /&gt;
# this list of servers is generated by the DBAMON tool so will be up to date&lt;br /&gt;
# --------------------------------------------------------------------------&lt;br /&gt;
serverfile=/home/ibmtools/etc/oracle/oracle_servers&lt;br /&gt;
[[ -z &amp;quot;${serverfile}&amp;quot; ]] &amp;amp;&amp;amp; echo &amp;quot;Server list ${serverfile} not found&amp;quot; &amp;amp;&amp;amp; exit 1&lt;br /&gt;
&lt;br /&gt;
serverlist=`cat ${serverfile} | sort -n | tr &amp;quot;\n&amp;quot; &amp;quot; &amp;quot;`&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
# -------------------------&lt;br /&gt;
# get the arguments, if any&lt;br /&gt;
# -------------------------&lt;br /&gt;
while getopts &amp;quot;hvc:&amp;quot; OPT&lt;br /&gt;
do&lt;br /&gt;
    case &amp;quot;$OPT&amp;quot; in&lt;br /&gt;
    h) echo &amp;quot;\nUsage: $0 [-v] [-h] -c &amp;#039;&amp;lt;command_to_be_executed_remotely&amp;gt;&amp;#039;\n&amp;quot;;&lt;br /&gt;
       exit;&lt;br /&gt;
       ;;&lt;br /&gt;
    v) VERBOSE=&amp;quot;Y&amp;quot;;&lt;br /&gt;
       ;;&lt;br /&gt;
    c) CMMND=$OPTARG;&lt;br /&gt;
       ;;&lt;br /&gt;
    *) echo &amp;quot;\nUsage: $0 [-v] [-h] -c &amp;#039;&amp;lt;command_to_be_executed_remotely&amp;gt;&amp;#039;\n&amp;quot;;&lt;br /&gt;
       exit;&lt;br /&gt;
       ;;&lt;br /&gt;
    esac&lt;br /&gt;
done&lt;br /&gt;
shift $((OPTIND-1))&lt;br /&gt;
VERBOSE=${VERBOSE:-&amp;quot;N&amp;quot;}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
# --------------------------------&lt;br /&gt;
# check we have required arguments&lt;br /&gt;
# --------------------------------&lt;br /&gt;
[[ -z $CMMND ]] &amp;amp;&amp;amp; echo &amp;quot;Enter command to be executed like this: $0 -c &amp;#039;ls -al&amp;#039;&amp;quot; &amp;amp;&amp;amp; exit 1&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
# ----------------------------&lt;br /&gt;
# loop over the remote servers&lt;br /&gt;
# ----------------------------&lt;br /&gt;
for server in ${serverlist}&lt;br /&gt;
do&lt;br /&gt;
    if [[ &amp;quot;$VERBOSE&amp;quot; == &amp;quot;Y&amp;quot; ]]; then&lt;br /&gt;
        echo ${server} `date +&amp;#039;%d-%b-%Y %H:%M:%S&amp;#039;`&lt;br /&gt;
        echo &amp;quot;------------------------------------&amp;quot;&lt;br /&gt;
        set -x&lt;br /&gt;
    fi&lt;br /&gt;
    ssh ${server} &amp;quot;$CMMND&amp;quot;&lt;br /&gt;
    set +x&lt;br /&gt;
    [[ &amp;quot;$VERBOSE&amp;quot; == &amp;quot;Y&amp;quot; ]] &amp;amp;&amp;amp; echo&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
to be investigated... this one might be cleverer than mine...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
tmpdir=${TMPDIR:-/tmp}/pssh.$$&lt;br /&gt;
count=0&lt;br /&gt;
while userhost; do&lt;br /&gt;
    ssh -n -o BatchMode=yes ${userhost} &amp;#039;uname -a&amp;#039; &amp;gt; ${tmpdir}/${userhost} 2&amp;gt;&amp;amp;1 &amp;amp;&lt;br /&gt;
    count=`expr $count + 1`&lt;br /&gt;
done &amp;lt; userhost.lst&lt;br /&gt;
while [ $count -gt 0 ]; do&lt;br /&gt;
    wait $pids&lt;br /&gt;
    count=`expr $count - 1`&lt;br /&gt;
done&lt;br /&gt;
echo &amp;quot;Output for hosts are in $tmpdir&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
improved version...&amp;lt;br /&amp;gt;&lt;br /&gt;
just escape double quotes and dollar signs...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/ksh&lt;br /&gt;
# ==============================================================================&lt;br /&gt;
# Name         : dosh   (Distributed Oracle SHell)&lt;br /&gt;
# Description  : Runs a command on all Oracle servers&lt;br /&gt;
#&lt;br /&gt;
# Parameters   : h - displays help&lt;br /&gt;
#                v - verbose (default, like all unix commands is silent)&lt;br /&gt;
#                c - command to be executed&lt;br /&gt;
#&lt;br /&gt;
# Example      : ./dosh -v -c &amp;#039;ls -al&amp;#039;&lt;br /&gt;
#&lt;br /&gt;
# Modification History&lt;br /&gt;
# ====================&lt;br /&gt;
# When      Who               What&lt;br /&gt;
# ========= ================= ==================================================&lt;br /&gt;
# 08-FEB-13 Stuart Barkley    Created&lt;br /&gt;
# 08-JUL-15 Stuart Barkley    Background execution mode&lt;br /&gt;
# ==============================================================================&lt;br /&gt;
# --------------------------------------------------------------------------&lt;br /&gt;
# this list of servers is generated by the DBAMON tool so will be up to date&lt;br /&gt;
# --------------------------------------------------------------------------&lt;br /&gt;
serverfile=/home/ibmtools/etc/oracle/oracle_servers&lt;br /&gt;
[[ -z &amp;quot;${serverfile}&amp;quot; ]] &amp;amp;&amp;amp; echo &amp;quot;Server list ${serverfile} not found&amp;quot; &amp;amp;&amp;amp; exit 1&lt;br /&gt;
&lt;br /&gt;
serverlist=`cat ${serverfile} | sort -n | tr &amp;quot;\n&amp;quot; &amp;quot; &amp;quot;`&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
# -------------------------&lt;br /&gt;
# get the arguments, if any&lt;br /&gt;
# -------------------------&lt;br /&gt;
while getopts &amp;quot;hbvc:&amp;quot; OPT&lt;br /&gt;
do&lt;br /&gt;
    case &amp;quot;$OPT&amp;quot; in&lt;br /&gt;
    h) echo &amp;quot;\nUsage: $0 [-b] [-v] [-h] -c &amp;#039;&amp;lt;command_to_be_executed_remotely&amp;gt;&amp;#039;\n&amp;quot;;&lt;br /&gt;
       exit;&lt;br /&gt;
       ;;&lt;br /&gt;
    b) BACKGROUND=&amp;quot;Y&amp;quot;;&lt;br /&gt;
       ;;&lt;br /&gt;
    v) VERBOSE=&amp;quot;Y&amp;quot;;&lt;br /&gt;
       ;;&lt;br /&gt;
    c) CMMND=$OPTARG;&lt;br /&gt;
       ;;&lt;br /&gt;
    *) echo &amp;quot;\nUsage: $0 [-b] [-v] [-h] -c &amp;#039;&amp;lt;command_to_be_executed_remotely&amp;gt;&amp;#039;\n&amp;quot;;&lt;br /&gt;
       exit;&lt;br /&gt;
       ;;&lt;br /&gt;
    esac&lt;br /&gt;
done&lt;br /&gt;
shift $((OPTIND-1))&lt;br /&gt;
VERBOSE=${VERBOSE:-&amp;quot;N&amp;quot;}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
# --------------------------------&lt;br /&gt;
# check we have required arguments&lt;br /&gt;
# --------------------------------&lt;br /&gt;
[[ -z $CMMND ]] &amp;amp;&amp;amp; echo &amp;quot;Enter command to be executed like this: $0 -c &amp;#039;ls -al&amp;#039;&amp;quot; &amp;amp;&amp;amp; exit 1&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
# ---------------------------------&lt;br /&gt;
# put the thing to be run in a file&lt;br /&gt;
# ---------------------------------&lt;br /&gt;
printf &amp;quot;%s\n&amp;quot; &amp;quot;$CMMND&amp;quot; &amp;gt; /tmp/dosh.$$&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
# ----------------------------&lt;br /&gt;
# loop over the remote servers&lt;br /&gt;
# ----------------------------&lt;br /&gt;
for server in ${serverlist}&lt;br /&gt;
do&lt;br /&gt;
    if [[ &amp;quot;$VERBOSE&amp;quot; == &amp;quot;Y&amp;quot; ]]; then&lt;br /&gt;
        printf &amp;quot;%s\n&amp;quot; ${server} `date +&amp;#039;%d-%b-%Y %H:%M:%S&amp;#039;`&lt;br /&gt;
        printf &amp;quot;%s\n&amp;quot; &amp;quot;------------------------------------&amp;quot;&lt;br /&gt;
        set -x&lt;br /&gt;
    fi&lt;br /&gt;
    scp -q /tmp/dosh.$$ ${server}:/tmp/&lt;br /&gt;
    if [[ &amp;quot;$BACKGROUND&amp;quot; == &amp;quot;Y&amp;quot; ]]; then&lt;br /&gt;
        ssh -n -o BatchMode=yes ${server} &amp;quot;ksh /tmp/dosh.$$; rm -f /tmp/dosh.$$&amp;quot;&amp;gt; /tmp/dosh_${server}.out 2&amp;gt;&amp;amp;1 &amp;amp;&lt;br /&gt;
    else&lt;br /&gt;
        ssh -n -o BatchMode=yes ${server} &amp;quot;ksh /tmp/dosh.$$; rm -f /tmp/dosh.$$&amp;quot;&lt;br /&gt;
    fi&lt;br /&gt;
    set +x&lt;br /&gt;
    [[ &amp;quot;$VERBOSE&amp;quot; == &amp;quot;Y&amp;quot; ]] &amp;amp;&amp;amp; echo&lt;br /&gt;
done&lt;br /&gt;
rm -f /tmp/dosh.$$&lt;br /&gt;
&lt;br /&gt;
[[ &amp;quot;$BACKGROUND&amp;quot; == &amp;quot;Y&amp;quot; ]] &amp;amp;&amp;amp; printf &amp;quot;%s\n&amp;quot; &amp;quot;Type &amp;#039;ls -altr /tmp/dosh*out&amp;#039; to see output from the commands&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===How can a shell script find out what directory it is in?===&lt;br /&gt;
basename $0 does not always give the desired answer (might give &amp;quot;./&amp;quot;!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
DIR=&amp;quot;$(cd &amp;quot;$(dirname &amp;quot;$0&amp;quot;)&amp;quot; &amp;amp;&amp;amp; pwd)&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Array processing===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
array=(1 2 3)&lt;br /&gt;
unset array[2]&lt;br /&gt;
echo ${array[2]}          # null&lt;br /&gt;
indices=(${!array[@]})    # create an array of the indices of &amp;quot;array&amp;quot;&lt;br /&gt;
size=${#indices[@]}       # the size of &amp;quot;array&amp;quot; is the number of indices into it&lt;br /&gt;
size=${#array[@]}         # same&lt;br /&gt;
echo ${array[@]: -1}      # you can use slices to get array elements, -1 is the last one, etc.&lt;br /&gt;
for element in ${array[@]}; do    # iterate over the array without an index&lt;br /&gt;
&lt;br /&gt;
for index in ${indices[@]}        # iterate over the array WITH an index&lt;br /&gt;
do&lt;br /&gt;
    echo &amp;quot;Index: ${index}, Element: ${array[index]}&amp;quot;&lt;br /&gt;
done&lt;br /&gt;
&lt;br /&gt;
for index in ${!array[@]}         # iterate over the array WITH an index, directly&lt;br /&gt;
&lt;br /&gt;
array+=(&amp;quot;new element&amp;quot;)    # append a new element without referring to an index&lt;br /&gt;
((counter++))             # shorter than ((counter=counter+1)) or ((counter+=1))&lt;br /&gt;
if [[ $var == 3 ]]        # you can use the more &amp;quot;natural&amp;quot; comparison operators inside double square brackets&lt;br /&gt;
while [[ $var &amp;lt; 11 ]]     # another example&lt;br /&gt;
echo ${array[${index}-1]  # math inside an array subscript&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Send an email by talking directly to an smtp server===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
telnet smtp.domain.com 25 &amp;lt;&amp;lt;EOTXT&amp;gt;&amp;gt;/tmp/smtp.log&lt;br /&gt;
HELO me.domain.com&lt;br /&gt;
MAIL FROM:&amp;lt;stuart@domain.com&amp;gt;&lt;br /&gt;
RCPT TO:&amp;lt;anne@domain.com&amp;gt;&lt;br /&gt;
DATA&lt;br /&gt;
From: Stuart &amp;lt;stuart@domain.com&amp;gt;&lt;br /&gt;
To: Anne &amp;lt;anne@domain.com&amp;gt;&lt;br /&gt;
Subject: testing smtp email&lt;br /&gt;
&lt;br /&gt;
Hello, this should appear in the body&lt;br /&gt;
.&lt;br /&gt;
QUIT&lt;br /&gt;
EOTXT&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Send an email by talking directly to an smtp server via file descriptor (no telnet! this time), adding authentication===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
&lt;br /&gt;
#&lt;br /&gt;
# mail.sh&lt;br /&gt;
#&lt;br /&gt;
# 2008 - Mike Golvach - eggi@comcast.net&lt;br /&gt;
# 2010 - Rayber&lt;br /&gt;
#&lt;br /&gt;
# Creative Commons Attribution-Noncommercial-Share Alike 3.0 United States License&lt;br /&gt;
#&lt;br /&gt;
&lt;br /&gt;
if [ $# -ne 7 ]&lt;br /&gt;
then&lt;br /&gt;
echo &amp;quot;Usage: $0 FromAdress ToAdress Domain MailServer MailTextFile AuthEmail AuthPass&amp;quot;&lt;br /&gt;
exit 1&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
from=$1&lt;br /&gt;
to=$2&lt;br /&gt;
domain=$3&lt;br /&gt;
mailserver=$4&lt;br /&gt;
mailtext=$5&lt;br /&gt;
authemail=`echo $6|openssl enc -base64|awk &amp;#039;sub(&amp;quot;..$&amp;quot;, &amp;quot;&amp;quot;)&amp;#039;`&lt;br /&gt;
authpass=`echo $7|openssl enc -base64|awk &amp;#039;sub(&amp;quot;..$&amp;quot;, &amp;quot;&amp;quot;)&amp;#039;`&lt;br /&gt;
&lt;br /&gt;
if [ ! -f $mailtext ]&lt;br /&gt;
then&lt;br /&gt;
echo &amp;quot;Cannot find your mail text file. Exiting...&amp;quot;&lt;br /&gt;
exit 1&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
exec 9&amp;lt;&amp;gt;/dev/tcp/$mailserver/25&lt;br /&gt;
echo &amp;quot;HELO $domain&amp;quot; &amp;gt;&amp;amp;9&lt;br /&gt;
read -r temp &amp;lt;&amp;amp;9&lt;br /&gt;
echo &amp;quot;$temp&amp;quot;&lt;br /&gt;
echo &amp;quot;auth login&amp;quot; &amp;gt;&amp;amp;9&lt;br /&gt;
read -r temp &amp;lt;&amp;amp;9&lt;br /&gt;
echo &amp;quot;$authemail&amp;quot; &amp;gt;&amp;amp;9&lt;br /&gt;
read -r temp &amp;lt;&amp;amp;9&lt;br /&gt;
echo &amp;quot;$authpass&amp;quot; &amp;gt;&amp;amp;9&lt;br /&gt;
read -r temp &amp;lt;&amp;amp;9&lt;br /&gt;
echo &amp;quot;Mail From: $from&amp;quot; &amp;gt;&amp;amp;9&lt;br /&gt;
read -r temp &amp;lt;&amp;amp;9&lt;br /&gt;
echo &amp;quot;$temp&amp;quot;&lt;br /&gt;
echo &amp;quot;Rcpt To: $to&amp;quot; &amp;gt;&amp;amp;9&lt;br /&gt;
read -r temp &amp;lt;&amp;amp;9&lt;br /&gt;
echo &amp;quot;$temp&amp;quot;&lt;br /&gt;
echo &amp;quot;Data&amp;quot; &amp;gt;&amp;amp;9&lt;br /&gt;
read -r temp &amp;lt;&amp;amp;9&lt;br /&gt;
echo &amp;quot;$temp&amp;quot;&lt;br /&gt;
cat $mailtext &amp;gt;&amp;amp;9&lt;br /&gt;
echo &amp;quot;.&amp;quot; &amp;gt;&amp;amp;9&lt;br /&gt;
read -r temp &amp;lt;&amp;amp;9&lt;br /&gt;
echo &amp;quot;$temp&amp;quot;&lt;br /&gt;
echo &amp;quot;quit&amp;quot; &amp;gt;&amp;amp;9&lt;br /&gt;
read -r temp &amp;lt;&amp;amp;9&lt;br /&gt;
echo &amp;quot;$temp&amp;quot;&lt;br /&gt;
9&amp;gt;&amp;amp;-&lt;br /&gt;
9&amp;lt;&amp;amp;-&lt;br /&gt;
echo &amp;quot;All Done Sending Email. See above for errors&amp;quot;&lt;br /&gt;
exit 0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== rsync examples===&lt;br /&gt;
Also see [[Distribute files to multiple servers using rsync and ssh]]&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/sh&lt;br /&gt;
ssh  &amp;lt;remote_host&amp;gt; &amp;#039;/bin/mkdir -p /etc /etc/rc.config.d /etc/security /etc/mail&amp;#039;&lt;br /&gt;
rsync --rsync-path /usr/bin/rsync -Liprogtz --out-format=%f%L  /etc/passwd /etc/passwd.post /etc/group /etc/hosts /etc/services /etc/resolv.conf /etc/exclude.rootvg &amp;lt;remote_host&amp;gt;:/etc&lt;br /&gt;
rsync --rsync-path /usr/bin/rsync -Liprogtz --out-format=%f%L  /etc/hosts.allow.xcat &amp;lt;remote_host&amp;gt;:/etc/hosts.allow&lt;br /&gt;
rsync --rsync-path /usr/bin/rsync -Liprogtz --out-format=%f%L  /etc/rc.config.d/sap &amp;lt;remote_host&amp;gt;:/etc/rc.config.d&lt;br /&gt;
rsync --rsync-path /usr/bin/rsync -Liprogtz --out-format=%f%L  /etc/security/group /etc/security/limits /etc/security/login.cfg /etc/security/passwd /etc/security/user &amp;lt;remote_host&amp;gt;:/etc/security&lt;br /&gt;
rsync --rsync-path /usr/bin/rsync -Liprogtz --out-format=%f%L  /etc/mail/sendmail.cf &amp;lt;remote_host&amp;gt;:/etc/mail&lt;br /&gt;
&lt;br /&gt;
rsync -av --progress /home/ibmtools/scripts/oracle/* benouerp07:/home/ibmtools/scripts/oracle/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Handy aliases===&lt;br /&gt;
Strip out comments and blank lines from a file&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alias strip=&amp;#039;grep -Ev &amp;#039;\&amp;#039;&amp;#039;^(#|$)&amp;#039;\&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Does a ps and a grep&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alias psg=&amp;#039;ps -ef | grep -v $$ | grep -i &amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Getting a decent listing of filesystem space available. It is ordered such that the filesystems with no space left are at the end.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
OS=$(uname -s)&lt;br /&gt;
[[ &amp;quot;$OS&amp;quot; == &amp;quot;SunOS&amp;quot; ]] &amp;amp;&amp;amp; alias dfg=&amp;#039;df -h|sed -e &amp;#039;1d&amp;#039;|sort -n -k5|awk &amp;#039;\&amp;#039;&amp;#039; BEGIN {printf(&amp;quot;%-35s%-10s%-10s%-6s%-30s\n&amp;quot;,&amp;quot;Filesystem&amp;quot;,&amp;quot;Total&amp;quot;,&amp;quot;Free&amp;quot;,&amp;quot;%Used&amp;quot;,&amp;quot;Mounted on&amp;quot;)} {printf(&amp;quot;%-35s%-10s%-10s%-6s%-30s\n&amp;quot;,$1,$2,$4,$5,$6)}&amp;#039;\&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
[[ &amp;quot;$OS&amp;quot; == &amp;quot;AIX&amp;quot; ]]   &amp;amp;&amp;amp; alias dfg=&amp;#039;df -g|sed -e &amp;#039;1d&amp;#039;|sort -n -k4|awk &amp;#039;\&amp;#039;&amp;#039; BEGIN {printf(&amp;quot;%-35s%-10s%-10s%-6s%-30s\n&amp;quot;,&amp;quot;Filesystem&amp;quot;,&amp;quot;Total GB&amp;quot;,&amp;quot;Free&amp;quot;,&amp;quot;%Used&amp;quot;,&amp;quot;Mounted on&amp;quot;)} {printf(&amp;quot;%-35s%-10s%-10s%-6s%-30s\n&amp;quot;,$1,$2,$3,$4,$7)}&amp;#039;\&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
A handy way of listing subdirectories and their files&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alias filetree=&amp;quot;find . -print | sed -e &amp;#039;s;[^/]*/;|____;g;s;____|; |;g&amp;#039;&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Watch progress of a copy&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alias cpProgress=&amp;quot;rsync --progress -ravz&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Reboots Linksys router&amp;lt;pre&amp;gt;&lt;br /&gt;
alias rebootlinksys=&amp;quot;curl -u &amp;#039;admin:password&amp;#039; &amp;#039;http://192.168.1.2/setup.cgi?todo=reboot&amp;#039;&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Nice one for bash. Colour codes the prompt depending on the outcome of the previous command&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
bash_prompt_command()&lt;br /&gt;
{&lt;br /&gt;
    RTN=$?&lt;br /&gt;
    prevCmd=$(prevCmd $RTN)&lt;br /&gt;
}&lt;br /&gt;
PROMPT_COMMAND=bash_prompt_command&lt;br /&gt;
prevCmd()&lt;br /&gt;
{&lt;br /&gt;
    if [ $1 == 0 ] ; then&lt;br /&gt;
        echo $GREEN&lt;br /&gt;
    else&lt;br /&gt;
        echo $RED&lt;br /&gt;
    fi&lt;br /&gt;
}&lt;br /&gt;
if [ $(tput colors) -gt 0 ] ; then&lt;br /&gt;
    RED=$(tput setaf 1)&lt;br /&gt;
    GREEN=$(tput setaf 2)&lt;br /&gt;
    RST=$(tput op)&lt;br /&gt;
fi&lt;br /&gt;
export PS1=&amp;quot;\[\e[36m\]\u.\h.\W\[\e[0m\]\[\$prevCmd\]&amp;gt;\[$RST\]&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Mmmm, to be looked into. Executes remote commands on a unix box using curl.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#/bin/sh&lt;br /&gt;
#&lt;br /&gt;
# WAG320N-HACK&lt;br /&gt;
# Ver. 1.0&lt;br /&gt;
# 12/09/2010&lt;br /&gt;
#&lt;br /&gt;
# This program is free software: you can redistribute it and/or modify&lt;br /&gt;
# it under the terms of the GNU General Public License as published by&lt;br /&gt;
# the Free Software Foundation, either version 3 of the License, or&lt;br /&gt;
# (at your option) any later version.&lt;br /&gt;
#&lt;br /&gt;
# This program is distributed in the hope that it will be useful,&lt;br /&gt;
# but WITHOUT ANY WARRANTY; without even the implied warranty of&lt;br /&gt;
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the&lt;br /&gt;
# GNU General Public License for more details.&lt;br /&gt;
#&lt;br /&gt;
# You should have received a copy of the GNU General Public License&lt;br /&gt;
# along with this program.  If not, see &amp;lt;http://www.gnu.org/licenses/&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
# Set username and password in the form of &amp;quot;username:password&amp;quot;&lt;br /&gt;
# example: &amp;quot;admin:admin&amp;quot;&lt;br /&gt;
my_access=&amp;quot;admin:admin&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Parameters test&lt;br /&gt;
if [ -z &amp;quot;$1&amp;quot; ]&lt;br /&gt;
then&lt;br /&gt;
  echo &amp;quot;wag320n-hack.sh: missing remote command&amp;quot;&lt;br /&gt;
  echo &amp;quot;usage: wag320n-hack.sh &amp;lt;remote command&amp;gt;&amp;quot;&lt;br /&gt;
  echo &amp;quot;example: wag320n-hack.sh /bin/ls -la /usr/sbin&amp;quot;&lt;br /&gt;
  echo &amp;quot;Note: always use full path&amp;quot;&lt;br /&gt;
  echo &amp;quot;&amp;quot;&lt;br /&gt;
  echo &amp;quot;wag320n-hack.sh - Ver. 1.0 - 12/09/2010&amp;quot;&lt;br /&gt;
  echo &amp;quot;Licensed under GPL V. 3&amp;quot;&lt;br /&gt;
  echo &amp;quot;&amp;quot;&lt;br /&gt;
  exit 0&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
# Get the command&lt;br /&gt;
my_command=&amp;quot;ping_size=&amp;quot;&amp;#039;$(&amp;#039;&amp;quot;$@&amp;quot;&amp;#039; 1&amp;gt;&amp;amp;2)&amp;#039;&lt;br /&gt;
&lt;br /&gt;
curl -s -G -u &amp;quot;$my_access&amp;quot; --data-urlencode &amp;#039;todo=ping_test&amp;#039; --data-urlencode &amp;#039;this_file=Diagnostics.htm&amp;#039; --data-urlencode &amp;#039;next_file=Ping.htm&amp;#039; --data-urlencode &amp;#039;c4_ping_ipaddr=192.168.1.1&amp;#039; --data-urlencode &amp;#039;ping_timeout=5000&amp;#039; --data-urlencode &amp;#039;ping_interval=1000&amp;#039; --data-urlencode &amp;#039;ping_number=1&amp;#039; --data-urlencode &amp;quot;$my_command&amp;quot; http://192.168.1.1/setup.cgi | sed -e &amp;#039;/HTTP\/1.0 200 OK/q&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===How to configure SSH with public/private keys===&lt;br /&gt;
* [http://www.unixpeople.com/HOWTO/configuring.ssh.html unixpeople.com]&lt;br /&gt;
===Use SSH config file===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Host server10&lt;br /&gt;
  Hostname 1.2.3.4&lt;br /&gt;
  IdentityFile ~/.ssh/id_dsa&lt;br /&gt;
  user foobar&lt;br /&gt;
  Port 30000&lt;br /&gt;
  ForwardX11Trusted yes&lt;br /&gt;
  TCPKeepAlive yes&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
then just connect using&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ssh server10&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===A decent sed tutorial===&lt;br /&gt;
From [http://www.grymoire.com/Unix/Sed.html grymoire.com]&lt;br /&gt;
===A decent korn/bash shell tutorial===&lt;br /&gt;
From [http://www.dartmouth.edu/~rc/classes/ksh/print_pages.shtml dartmouth.edu]&lt;br /&gt;
Reproduced here just in case it disappears!&lt;br /&gt;
[[Advanced shell scripting]]&lt;br /&gt;
&lt;br /&gt;
===trap===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
     Example Handling Traps With ksh - Discussion of the kill command&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
EXAMPLE TEMPLATE:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
PRODUCT:    HP-UX 11iV1 Version B.11.11&lt;br /&gt;
            HP Tru64 V5.1B PK4&lt;br /&gt;
            Sun/Solaris SunOS V5.8&lt;br /&gt;
            Linux 2.6 kernel&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
COMPONENT:  ksh&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
SOURCE:     Philippe Vouters&lt;br /&gt;
            Fontainebleau/France&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
LOW COST HIGH-TECH PRODUCTS:  http://techno-star.fr&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
OVERVIEW:&lt;br /&gt;
&lt;br /&gt;
The ksh script below shows how to eventually handle traps in the situation &lt;br /&gt;
where someone might try to kill a script by killing individual commands run &lt;br /&gt;
by that script or the entire process group a script is running in. The kill &lt;br /&gt;
command (usually a shell builtin) may be used to send a signal to a process &lt;br /&gt;
group (with the -&amp;lt;pid&amp;gt; syntax) or an individual process. The example ksh &lt;br /&gt;
script below runs /bin/sleep as the foreground process, the example ksh &lt;br /&gt;
scripts immediately returns when the /bin/sleep process has terminated. Most &lt;br /&gt;
signals sent to the shell are ignored until after the foreground process &lt;br /&gt;
terminates. This is in order to avoid creating zombie processes. Therefore a &lt;br /&gt;
kill &amp;lt;pid&amp;gt; on the example ksh script waits for the termination of the &lt;br /&gt;
/bin/sleep process.&lt;br /&gt;
&lt;br /&gt;
The status value $? in the trap refers to the exit status of the command to run &lt;br /&gt;
and therefore is the exit status of the /bin/sleep process. The called function &lt;br /&gt;
in the trap handler shows how to correctly examine the effect of the kill &lt;br /&gt;
command on the shell or it&amp;#039;s children.&lt;br /&gt;
&lt;br /&gt;
To examine the value of $? in a trap handler means that you must understand what&lt;br /&gt;
it can be set and how different signals delivered to either the shell or the &lt;br /&gt;
foreground process (or the process group) might affect the value of $?.&lt;br /&gt;
&lt;br /&gt;
The example shell script prints $? using echo but it does not perform tests on &lt;br /&gt;
the value of $?. For a complete solution when attempting to trap signals in a &lt;br /&gt;
shell you would also need code that examined the value of $? after the &lt;br /&gt;
foreground process had completed.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*** CAUTION ***&lt;br /&gt;
&lt;br /&gt;
This sample script has been tested using HP-UX B.11.11, HP Tru64 V5.1B PK4, &lt;br /&gt;
SunOS V5.8 and Fedora Core 4 (homed version of Red Hat Linux).  However, we&lt;br /&gt;
cannot guarantee its effectiveness because of the possibility of error in &lt;br /&gt;
transmitting or implementing it. It is meant to be used as a template for &lt;br /&gt;
writing your own scripts, and may require modification for use on your system. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
SCRIPT NOTES:&lt;br /&gt;
&lt;br /&gt;
To notice that the ksh script and /bin/sleep share the same process group&lt;br /&gt;
identifier (PGID), issue the following commands:&lt;br /&gt;
&lt;br /&gt;
[philippe@victor ~]$ who&lt;br /&gt;
philippe :0           Jan 10 10:16&lt;br /&gt;
philippe pts/1        Jan 10 21:30 (:0.0)&lt;br /&gt;
philippe pts/2        Jan 10 21:30 (:0.0)&lt;br /&gt;
[philippe@victor ~]$ tty&lt;br /&gt;
/dev/pts/1&lt;br /&gt;
[philippe@victor ~]$ ps -j -t pts/2&lt;br /&gt;
  PID  PGID   SID TTY          TIME CMD&lt;br /&gt;
11072 11072 11072 pts/2    00:00:00 bash&lt;br /&gt;
11113 11113 11072 pts/2    00:00:00 ksh&lt;br /&gt;
11116 11113 11072 pts/2    00:00:00 sleep&lt;br /&gt;
&lt;br /&gt;
In this case sending kill -INT -11113 will send SIGINT to the process group &lt;br /&gt;
11113. Both of the ksh and sleep processes are contained within this process &lt;br /&gt;
group.&lt;br /&gt;
&lt;br /&gt;
Important Note:&lt;br /&gt;
&lt;br /&gt;
On HP-UX, you have to $ export UNIX95=1 in order to be able to use the&lt;br /&gt;
-j option of the ps command.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
SCRIPT:&lt;br /&gt;
&lt;br /&gt;
                             COPYRIGHT (C) 2005 BY&lt;br /&gt;
                              HEWLETT-PACKARD COMPANY&lt;br /&gt;
                                ALL RIGHTS RESERVED.&lt;br /&gt;
&lt;br /&gt;
     THIS SOFTWARE IS FURNISHED UNDER A LICENSE AND MAY BE USED AND COPIED&lt;br /&gt;
     ONLY IN ACCORDANCE WITH THE TERMS OF SUCH LICENSE AND WITH THE INCLUSION&lt;br /&gt;
     OF THE ABOVE COPYRIGHT NOTICE.  THIS SOFTWARE OR ANY OTHER COPIES&lt;br /&gt;
     THEREOF MAY NOT BE PROVIDED OR OTHERWISE MADE AVAILABLE TO ANY OTHER&lt;br /&gt;
     PERSON.  NO TITLE TO AND OWNERSHIP OF THE SOFTWARE IS HEREBY TRANSFERRED.&lt;br /&gt;
&lt;br /&gt;
     THE INFORMATION IN THIS SOFTWARE IS SUBJECT TO CHANGE WITHOUT NOTICE AND&lt;br /&gt;
     SHOULD NOT BE CONSTRUED AS A COMMITMENT BY HEWLETT-PACKARD COMPANY.&lt;br /&gt;
&lt;br /&gt;
     HP ASSUMES NO RESPONSIBILITY FOR THE USE OR RELIABILITY OF ITS&lt;br /&gt;
     SOFTWARE ON EQUIPMENT THAT IS NOT SUPPLIED BY HP.&lt;br /&gt;
&lt;br /&gt;
     NO RESPONSIBILITY IS ASSUMED FOR THE USE OR RELIABILITY OF SOFTWARE&lt;br /&gt;
     ON EQUIPMENT THAT IS NOT SUPPLIED BY HEWLETT-PACKARD COMPANY.&lt;br /&gt;
&lt;br /&gt;
     SUPPORT FOR THIS SOFTWARE IS NOT COVERED UNDER ANY HP SOFTWARE&lt;br /&gt;
     PRODUCT SUPPORT CONTRACT, BUT MAY BE PROVIDED UNDER THE TERMS OF THE&lt;br /&gt;
     CONSULTING AGREEMENT UNDER WHICH THIS SOFTWARE WAS DEVELOPED.&lt;br /&gt;
&lt;br /&gt;
#!/bin/ksh&lt;br /&gt;
function handle_signal&lt;br /&gt;
{&lt;br /&gt;
        print -n &amp;quot;pid $$ recieved $2 &amp;quot;&lt;br /&gt;
        if [[ $1 = 0 ]];then&lt;br /&gt;
            print but foreground command ended successfully&lt;br /&gt;
        else&lt;br /&gt;
                if [[ $1 = $3 ]];then&lt;br /&gt;
                    print and so did the last foreground command&lt;br /&gt;
                else&lt;br /&gt;
                    print -n &amp;quot;and the exit status of the last foreground &amp;quot;&lt;br /&gt;
                    print command was $1&lt;br /&gt;
                fi&lt;br /&gt;
        fi&lt;br /&gt;
        # Kill our process group and then ourselves with SIGTERM, giving a &lt;br /&gt;
        # pid of 0 sends the signal to our process group. Killing the process&lt;br /&gt;
        # group should kill us as well, this assumes that SIGTERM is not &lt;br /&gt;
        # handled by any process in the process group.&lt;br /&gt;
        #&lt;br /&gt;
        # This code could be replaced with an exit with an exit value that&lt;br /&gt;
        # would indicate what the problem was to the caller. That is replace &lt;br /&gt;
        # these two lines with:&lt;br /&gt;
        #&lt;br /&gt;
        # exit $3&lt;br /&gt;
        #&lt;br /&gt;
        # or a specific exit code could be used.&lt;br /&gt;
        #&lt;br /&gt;
        kill -TERM 0&lt;br /&gt;
        kill -TERM $$&lt;br /&gt;
        }&lt;br /&gt;
OS=$(uname -a | awk &amp;#039;{print $1}&amp;#039;)&lt;br /&gt;
if [[ &amp;quot;$OS&amp;quot; = &amp;quot;Linux&amp;quot; ]]; then&lt;br /&gt;
    offset=256&lt;br /&gt;
elif [[ (&amp;quot;$OS&amp;quot; = &amp;quot;HP-UX&amp;quot;) || &lt;br /&gt;
        (&amp;quot;$OS&amp;quot; = &amp;quot;SunOS&amp;quot;) || &lt;br /&gt;
        (&amp;quot;$OS&amp;quot; = &amp;quot;OSF1&amp;quot;) ]]; then&lt;br /&gt;
   offset=128&lt;br /&gt;
fi&lt;br /&gt;
trap &amp;#039;RC=$?; handle_signal $RC SIGINT $offset+2&amp;#039; INT&lt;br /&gt;
trap &amp;#039;RC=$?; handle_signal $RC SIGQUIT $offset+3&amp;#039; QUIT&lt;br /&gt;
/bin/sleep 20&lt;br /&gt;
echo $?&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===DNS not working===&lt;br /&gt;
Ping to an IP address works&lt;br /&gt;
 ping 74.125.136.103&lt;br /&gt;
but this doesn&amp;#039;t&lt;br /&gt;
 ping www.google.com&lt;br /&gt;
&lt;br /&gt;
Check resolv.conf&lt;br /&gt;
 cat /etc/resolv.conf&lt;br /&gt;
 nameserver 95.130.132.17&lt;br /&gt;
 nameserver 95.130.132.18&lt;br /&gt;
I had changed internet provider and forgot to update this. Just to set it to the router address and let that do the resolution&lt;br /&gt;
 nameserver 192.168.1.1&lt;br /&gt;
&lt;br /&gt;
===File descriptors===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
exec 3&amp;lt;&amp;gt; /tmp/foo  #open fd 3 for r/w&lt;br /&gt;
echo &amp;quot;test&amp;quot; &amp;gt;&amp;amp;3&lt;br /&gt;
exec 3&amp;gt;&amp;amp;- #close fd 3.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
exec 3&amp;lt;&amp;gt; myfile.txt&lt;br /&gt;
while read line &amp;lt;&amp;amp;3&lt;br /&gt;
do {&lt;br /&gt;
  echo &amp;quot;$line&amp;quot;&lt;br /&gt;
  (( Lines++ ));                   #  Incremented values of this variable&lt;br /&gt;
                                   #+ accessible outside loop.&lt;br /&gt;
                                   #  No subshell, no problem.&lt;br /&gt;
}&lt;br /&gt;
done&lt;br /&gt;
exec 3&amp;gt;&amp;amp;-&lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;Number of lines read = $Lines&amp;quot;     # 8&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Mmm. See our output and also tee it to a log file!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
&lt;br /&gt;
echo hello&lt;br /&gt;
&lt;br /&gt;
if test -t 1; then&lt;br /&gt;
    # Stdout is a terminal.&lt;br /&gt;
    exec &amp;gt;log&lt;br /&gt;
else&lt;br /&gt;
    # Stdout is not a terminal.&lt;br /&gt;
    npipe=/tmp/$$.tmp&lt;br /&gt;
    trap &amp;quot;rm -f $npipe&amp;quot; EXIT&lt;br /&gt;
    mknod $npipe p&lt;br /&gt;
    tee &amp;lt;$npipe log &amp;amp;&lt;br /&gt;
    exec 1&amp;gt;&amp;amp;-&lt;br /&gt;
    exec 1&amp;gt;$npipe&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
echo goodbye&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Create new image with kvm===&lt;br /&gt;
Ref: http://www.cyberciti.biz/faq/kvm-virtualization-in-redhat-centos-scientific-linux-6/&amp;lt;br /&amp;gt;&lt;br /&gt;
Build an empty space for a CentOS virtual machine&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
qemu-img create -f qcow2 centos.img 12G&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Tried creating image with&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo virt-install -n CentOS --description &amp;quot;Trying out CentOS&amp;quot; --ram=1024 --vcpus=1 --cpu host --hvm --cdrom /home/bey9at77/Downloads/c6-x86_64-20130910-1.qcow2 --graphics vnc --disk path=/var/lib/libvirt/images/centos.img,bus=virtio,size=10&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
gives error&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Starting install...&lt;br /&gt;
Allocating &amp;#039;centos.img&amp;#039;                                                                                                                                                                                               |  10 GB     00:00     &lt;br /&gt;
ERROR    internal error Process exited while reading console log output: char device redirected to /dev/pts/1&lt;br /&gt;
qemu-kvm: -drive file=/home/bey9at77/Downloads/c6-x86_64-20130910-1.qcow2.bz2,if=none,media=cdrom,id=drive-ide0-1-0,readonly=on,format=raw: could not open disk image /home/bey9at77/Downloads/c6-x86_64-20130910-1.qcow2: Permission denied&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===rpm / yum commands===&lt;br /&gt;
====Install an RPM Package====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rpm -ivh pidgin-2.7.9-5.el6.2.i686.rpm&lt;br /&gt;
&lt;br /&gt;
-i - install&lt;br /&gt;
-v - verbose&lt;br /&gt;
-h - print progress hashes&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Check dependencies of RPM Package before Installing====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rpm -qpR BitTorrent-5.2.2-1-Python2.4.noarch.rpm&lt;br /&gt;
&lt;br /&gt;
-q - query&lt;br /&gt;
-p - list package capabilities&lt;br /&gt;
-R - list dependent package capabilities&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Install RPM Package with all dependencies====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
yum install BitTorrent-5.2.2-1-Python2.4.noarch.rpm&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Install RPM Package with all dependencies (when RPM has been downloaded to local machine)====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
yum localinstall BitTorrent-5.2.2-1-Python2.4.noarch.rpm&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Force Install a RPM Package without dependencies====&lt;br /&gt;
Package will not work if dependencies are required&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rpm -ivh --nodeps BitTorrent-5.2.2-1-Python2.4.noarch.rpm&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Check an Installed RPM Package====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rpm -q BitTorrent&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====List all files of an installed RPM package====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rpm -ql BitTorrent&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====List All Installed RPM Packages====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rpm -qa&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Query information about an installed RPM package====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rpm -qi vsftpd&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Query information about a not yet installed RPM package====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rpm -qip sqlbuddy-1.3.3-1.noarch.rpm&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====(Forcibly) Remove an RPM Package====&lt;br /&gt;
Use package name (as seen in -qi above), not full name&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rpm -ev (--nodeps) vsftpd&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Query a file that was installed as part of an RPM Package (which package contained this file)====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rpm -qf /usr/bin/htpasswd&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Verify an RPM package====&lt;br /&gt;
Compares information of installed files of the package against the rpm database&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rpm -Vp sqlbuddy-1.3.3-1.noarch.rpm&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Rebuild corrupted RPM database====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cd /var/lib&lt;br /&gt;
rm __db*&lt;br /&gt;
rpm --rebuilddb&lt;br /&gt;
rpmdb_verify Packages&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Install rpmforge repository===&lt;br /&gt;
* Download rpmforge-release-0.5.3-1.el6.rf.x86_64.rpm&lt;br /&gt;
* Import the key&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo rpm --import http://apt.sw.be/RPM-GPG-KEY.dag.txt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Install the repository&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo rpm -i rpmforge-release-0.5.3-1.el6.rf.x86_64.rpm&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Check the installation&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rpm -K rpmforge-release-0.5.3-1.el6.rf.x86_64.rpm&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Test it&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo yum install terminator&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Install rpmfusion repository===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
su -c &amp;#039;yum localinstall --nogpgcheck http://download1.rpmfusion.org/free/el/updates/6/i386/rpmfusion-free-release-6-1.noarch.rpm http://download1.rpmfusion.org/nonfree/el/updates/6/i386/rpmfusion-nonfree-release-6-1.noarch.rpm&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===config file for yum===&lt;br /&gt;
Checkout this file for global yum config&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/etc/sysconfig/yum-cron-background&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Setup Oracle Enterprise Linux (RedHat) with yum server===&lt;br /&gt;
You need to download the yum .repo file from the server, as per the steps below. After this, you need to enable a flag in the .repo file as per your operating system version. Having done these two steps, when you run yum install &amp;lt;pkgname&amp;gt; command on your linux box, the Oracle&amp;#039;s yum server will be scanned, the dependent &amp;amp; the relevant rpm&amp;#039;s will be download and installed for you.&amp;lt;br /&amp;gt;&lt;br /&gt;
 cd /etc/yum.repos.d&lt;br /&gt;
To download files here&lt;br /&gt;
 wget http://public-yum.oracle.com/public-yum-el5.repo&lt;br /&gt;
&lt;br /&gt;
A file named public-yum-el5.repo will be created in your directory&amp;lt;br /&amp;gt;&lt;br /&gt;
Edit this file and enter enabled=1 against the operating systems which is relevant to you&lt;br /&gt;
 vi public-yum-el5.repo&lt;br /&gt;
&lt;br /&gt;
Next run the yum command&lt;br /&gt;
 yum install package-name&lt;br /&gt;
&lt;br /&gt;
===To change to static IP address (Raspberry Pi)===&lt;br /&gt;
As root:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cd /etc/networks&lt;br /&gt;
vi interfaces&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
replace the line “iface eth0 inet dhcp” with&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
iface eth0 inet static&lt;br /&gt;
address 192.168.1.100&lt;br /&gt;
netmask 255.255.255.0&lt;br /&gt;
gateway 192.168.1.1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You should also take a look at the file /etc/resolv.conf and check it has a nameserver entry (probably pointing at your default gateway) or direct to your ISP name servers.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
nameserver 192.168.1.1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Troubleshoot wireless network problems===&lt;br /&gt;
* [https://www.blackmoreops.com/2014/09/18/connect-to-wifi-network-from-command-line-in-linux/ connect to wifi network from command-line in linux - from blackmoreops.com]&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Short summary of all the things you need to do in just few lines&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
root@kali:~# iw dev&lt;br /&gt;
root@kali:~# ip link set wlan0 up&lt;br /&gt;
root@kali:~# iw wlan0 scan&lt;br /&gt;
root@kali:~# wpa_passphrase blackMOREOps &amp;gt;&amp;gt; /etc/wpa_supplicant.conf&lt;br /&gt;
root@kali:~# wpa_supplicant -i wlan0 -c /etc/wpa_supplicant.conf&lt;br /&gt;
root@kali:~# iw wlan0 link&lt;br /&gt;
root@kali:~# dhclient wlan0&lt;br /&gt;
root@kali:~# ping 8.8.8.8&lt;br /&gt;
(Where wlan0 is wifi adapter and blackMOREOps is SSID)&lt;br /&gt;
(Add Routing manually)&lt;br /&gt;
root@kali:~# ip route add default via 10.0.0.138 dev wlan0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===To change to static IP address (Redhat/CentOS)===&lt;br /&gt;
As root:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
vi /etc/sysconfig/network-scripts/ifcfg-eth0&lt;br /&gt;
DEVICE=eth0&lt;br /&gt;
BOOTPROTO=STATIC&lt;br /&gt;
IPADDR=192.168.1.111&lt;br /&gt;
NETMASK=255.255.255.0&lt;br /&gt;
GATEWAY=192.168.1.1&lt;br /&gt;
ONBOOT=yes&lt;br /&gt;
DNS1=8.8.8.8&lt;br /&gt;
DNS2=8.8.4.4&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Resrart the network interface&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/etc/init.d/network stop&lt;br /&gt;
/etc/init.d/network start&lt;br /&gt;
or&lt;br /&gt;
service network restart&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Check name server entry in resolv.conf&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
vi /etc/resolv.conf&lt;br /&gt;
nameserver 192.168.1.1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Enable processes / services to start at boot time===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo chkconfig httpd on&lt;br /&gt;
sudo chkconfig mysqld on&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Run a command on lots of servers in parallel===&lt;br /&gt;
This is a damn fine AIX utility - part of the CSM Distributed Shell.&lt;br /&gt;
 dsh -a &amp;quot;ls -al /etc/apache2/*conf&amp;quot;&lt;br /&gt;
will list the Apache configuration file on all reachable servers (nodes)&lt;br /&gt;
===Download a gzip file and pipe it into tar===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cd ~ &amp;amp;&amp;amp; wget -O - &amp;quot;https://www.dropbox.com/download?plat=lnx.x86_64&amp;quot; | tar xzf -&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Check in a script to make sure it is run only by root===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
RUID=`/usr/bin/id|$AWK -F\( &amp;#039;{print $1}&amp;#039;|$AWK -F\= &amp;#039;{print $2}&amp;#039;`&lt;br /&gt;
if [ ${RUID} != &amp;quot;0&amp;quot; ];then&lt;br /&gt;
   $ECHO &amp;quot;This script must be executed as root&amp;quot;&lt;br /&gt;
   exit 1&lt;br /&gt;
fi&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Set terminal to use Backspace key to erase previous character instead of Control-H===&lt;br /&gt;
Been looking for this for a long time.&amp;lt;br /&amp;gt;&lt;br /&gt;
You can put:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
stty erase &amp;lt;CTRL-V&amp;gt;&amp;lt;Backspace key&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
in your .profile but this will be ruined if you do a copy/paste into another file.&amp;lt;br /&amp;gt;&lt;br /&gt;
I wanted a way of doing this without entering the control character in the .profile. Finally stumbled upon it. And it&amp;#039;s so simple. Just escape the caret!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
stty erase \^?&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Put this in the .profile. It&amp;#039;s copy/pastable and it works!&amp;lt;br /&amp;gt;&lt;br /&gt;
If you want CTRL-H to be your erase character, just do this:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
stty erase \^H&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Play with the terminal settings and reset them again either side of requesting a password===&lt;br /&gt;
The -g option of stty gives a compact list of all the settings or the terminal and can be used as input to stty&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
OLDCONFIG=`stty -g`          # save terminal configuration&lt;br /&gt;
stty -echo                   # turn character echoing off&lt;br /&gt;
echo &amp;quot;Enter password: \c&amp;quot;&lt;br /&gt;
read PASSWD                  # get the password&lt;br /&gt;
stty $OLDCONFIG              # restore terminal configuration&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Reset terminal to &amp;quot;sane&amp;quot; characteristics===&lt;br /&gt;
If you&amp;#039;ve done a cat of a binary file or something else weird and your terminal is left in a mess, the following key sequence should bring it back to normal&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;CTRL-J&amp;gt;stty sane&amp;lt;CTRL-J&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Install OpenOffice on RedHat Enterprise when yum install doesn&amp;#039;t!===&lt;br /&gt;
Download Package&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
wget http://sourceforge.net/projects/openofficeorg.mirror/files/4.0.1/binaries/en-US/Apache_OpenOffice_4.0.1_Linux_x86-64_install-rpm_en-US.tar.gz/download -O Apache_OpenOffice_4.0.1_Linux_x86-64_install-rpm_en-US.tar.gz&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Change to root&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo su -&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Remove the old stuff&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
yum remove openoffice* libreoffice*&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Extract Package&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
tar -xvf Apache_OpenOffice_4.0.1*&lt;br /&gt;
cd en-US&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Install Package and exit root&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rpm -Uvh RPMS/*.rpm RPMS/desktop-integration/openoffice4.0-redhat-*.rpm&lt;br /&gt;
exit&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Start it&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
openoffice4&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===What does this do?===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
while IFS= read -r line; do&lt;br /&gt;
    echo &amp;quot;[$(date &amp;quot;+%F %T&amp;quot;)] - $line&amp;quot;&lt;br /&gt;
done &amp;lt; &amp;lt;(iwevent)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
while IFS= read -r line; do&lt;br /&gt;
    printf &amp;quot;%s\n%s\n&amp;quot; &amp;quot;$line&amp;quot; &amp;quot;Yohooo! One more package.&amp;quot;&lt;br /&gt;
done &amp;lt; &amp;lt;(tcpdump -i any -nS)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===List of Special Characters and what they mean===&lt;br /&gt;
From [http://www.grymoire.com/Unix/Quote.html Bruce Barnett]&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Character	Where	Meaning&lt;br /&gt;
&amp;lt;RETURN&amp;gt;	csh, sh	Execute command&lt;br /&gt;
#	csh, sh, ASCII files	Start a comment&lt;br /&gt;
&amp;lt;SPACE&amp;gt;	csh, sh	Argument separator&lt;br /&gt;
`	csh, sh	Command substitution&lt;br /&gt;
&amp;quot;	csh, sh	Weak Quotes&lt;br /&gt;
&amp;#039;	csh, sh	Strong Quotes&lt;br /&gt;
\	csh, sh	Single Character Quote&lt;br /&gt;
variable	sh, csh	Variable&lt;br /&gt;
variable	csh, sh	Same as variable&lt;br /&gt;
|	csh, sh	Pipe character&lt;br /&gt;
^	sh	Pipe Character&lt;br /&gt;
&amp;amp;	csh, sh	Run program in background&lt;br /&gt;
?	csh, sh	Match one character&lt;br /&gt;
*	csh, sh	Match any number of characters&lt;br /&gt;
;	csh, sh	Command separator&lt;br /&gt;
;;	sh	End of Case statement&lt;br /&gt;
~	csh	Home Directory&lt;br /&gt;
~user	csh	User&amp;#039;s Home Directory&lt;br /&gt;
!	csh	History of Commands&lt;br /&gt;
-	Programs	Start of optional argument&lt;br /&gt;
$#	csh, sh	Number of arguments to script&lt;br /&gt;
$*	csh, sh	Arguments to script&lt;br /&gt;
$@	sh	Original arguments to script&lt;br /&gt;
$-	sh	Flags passed to shell&lt;br /&gt;
$?	sh	Status of previous command&lt;br /&gt;
$$	sh	Process identification number&lt;br /&gt;
$!	sh	PID of last background job&lt;br /&gt;
&amp;amp;&amp;amp;	sh	Short-circuit AND&lt;br /&gt;
||	sh	Short-circuit OR&lt;br /&gt;
.	csh, sh	Typ. filename extension&lt;br /&gt;
.	sh	Source a file and execute as command&lt;br /&gt;
:	sh	Nothing command&lt;br /&gt;
:	sh	Separates Values in environment variables&lt;br /&gt;
:	csh	Variable modifier&lt;br /&gt;
Character	Where	Meaning&lt;br /&gt;
[ ]	csh, sh	Match range of characters&lt;br /&gt;
[ ]	sh	Test&lt;br /&gt;
%job	csh	Identifies job Number&lt;br /&gt;
(cmd;cmd)	csh. sh	Runs cmd;cmd as a sub-shell&lt;br /&gt;
{ }	csh	In-line expansions&lt;br /&gt;
{cmd;cmd }	sh	Like (cmd;cmd ) without a subshell&lt;br /&gt;
&amp;gt;ofile	csh, sh	Standard output&lt;br /&gt;
&amp;gt;&amp;gt;ofile	csh, sh	Append to standard output&lt;br /&gt;
&amp;lt;ifile	csh, sh	Standard Input&lt;br /&gt;
&amp;lt;&amp;lt;word	csh, sh	Read until word, substitute variables&lt;br /&gt;
&amp;lt;&amp;lt;\word	csh, sh	Read until word, no substitution&lt;br /&gt;
&amp;lt;&amp;lt;-word	sh	Read until word, ignoring TABS&lt;br /&gt;
&amp;gt;&amp;gt;!file	csh	Append to file, ignore error if not there&lt;br /&gt;
&amp;gt;!file	csh	Output to new file, ignore error if not there&lt;br /&gt;
&amp;gt;&amp;amp;file	csh	Send standard &amp;amp; error output to file&lt;br /&gt;
&amp;lt;&amp;amp;digit	sh	Switch Standard Input to file&lt;br /&gt;
&amp;lt;&amp;amp;-	sh	Close Standard Input&lt;br /&gt;
&amp;gt;&amp;amp;digit	sh	Switch Standard Output to file&lt;br /&gt;
&amp;gt;&amp;amp;-	sh	Close Standard Output&lt;br /&gt;
digit1&amp;lt;&amp;amp;digit2	sh	Connect digit2 to digit1&lt;br /&gt;
digit&amp;lt;&amp;amp;-	sh	Close file digit&lt;br /&gt;
digit2&amp;gt;&amp;amp;digit1	sh	Connect digit2 to digit1&lt;br /&gt;
digit&amp;gt;&amp;amp;-	sh	Close file digit&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Stuart</name></author>	</entry>

	<entry>
		<id>https://mailnest.com/dbawiki/index.php?title=Handy_scripts&amp;diff=3378</id>
		<title>Handy scripts</title>
		<link rel="alternate" type="text/html" href="https://mailnest.com/dbawiki/index.php?title=Handy_scripts&amp;diff=3378"/>
				<updated>2018-11-21T13:17:45Z</updated>
		
		<summary type="html">&lt;p&gt;Stuart: /* External table for the Alert log (pre 11g) */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==SQL==&lt;br /&gt;
* [[Database Overview - from idevelopment]] [http://www.idevelopment.info/data/Oracle/DBA_scripts/Database_Administration/dba_snapshot_database_10g.sql online version]&lt;br /&gt;
* [[Extract ddl with &amp;quot;dbms metadata.get ddl&amp;quot;]]&lt;br /&gt;
* [http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:83012348058 Connecting as another user via proxy in SQL*Plus]&lt;br /&gt;
* [http://www.petefinnigan.com/tools.htm Password cracker and role and priv tools from Pete Finnigan]&lt;br /&gt;
* [http://www.oracle.com/technetwork/articles/sql/11g-pivot-097235.html Using pivot tables in SQL - XML and XLS (Excel) also)]&lt;br /&gt;
===List all instances running on a server===&lt;br /&gt;
Sounds simple enough and indeed pre 12.1, is was as easy as either&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ps -ef | grep [p]mon | awk -F_ &amp;#039;{print $NF}&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or this one is safer in case you have an underscore character in your SID name!!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SIDLIST=$(${PS} -ef | ${GREP} [o]ra_pmon | ${AWK} &amp;#039;{print $NF}&amp;#039; | sed -e &amp;#039;s/ora_pmon_//&amp;#039; | egrep -v &amp;#039;grep|///|sed|awk|ASM|^$&amp;#039;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
but now we have the added complication of CDB/PDB (container / pluggable databases) so a fair bit more work is needed!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/ksh&lt;br /&gt;
# ==============================================================================&lt;br /&gt;
# Name         : list_server_db&lt;br /&gt;
# Description  : List all running databases found on a server&lt;br /&gt;
#&lt;br /&gt;
# Parameters   : none&lt;br /&gt;
#&lt;br /&gt;
# Notes        : none&lt;br /&gt;
#&lt;br /&gt;
# Modification History&lt;br /&gt;
# ====================&lt;br /&gt;
# When      Who               What&lt;br /&gt;
# ========= ================= ==================================================&lt;br /&gt;
# 21-DEC-16 Stuart Barkley    Created&lt;br /&gt;
# ==============================================================================&lt;br /&gt;
for db in $(ps -ef | grep [p]mon|awk -F_ &amp;#039;{print $NF}&amp;#039;)&lt;br /&gt;
do&lt;br /&gt;
    export ORACLE_SID=${db}&lt;br /&gt;
    ORAENV_ASK=NO&lt;br /&gt;
    . oraenv &amp;gt;/dev/null 2&amp;gt;&amp;amp;1&lt;br /&gt;
    sqlplus -s / as sysdba&amp;lt;&amp;lt;EOSQL&lt;br /&gt;
set serveroutput on feed off pages 0 head off newpa none&lt;br /&gt;
declare&lt;br /&gt;
    e_col_not_found exception;&lt;br /&gt;
    e_not_mounted   exception;&lt;br /&gt;
    pragma          exception_init(e_not_mounted, -01507);&lt;br /&gt;
    pragma          exception_init(e_col_not_found, -904);&lt;br /&gt;
    l_db_name       varchar2(20);&lt;br /&gt;
    l_database_role varchar2(20);&lt;br /&gt;
    l_cdb           varchar2(20);&lt;br /&gt;
    l_status        varchar2(20);&lt;br /&gt;
    type varchar2_tab is table of varchar2(240) index by binary_integer;&lt;br /&gt;
    t_pdbs          varchar2_tab;&lt;br /&gt;
begin&lt;br /&gt;
    begin&lt;br /&gt;
        dbms_output.enable(null);&lt;br /&gt;
        execute immediate &amp;#039;select name, database_role, cdb from v\$database&amp;#039; into l_db_name, l_database_role, l_cdb;&lt;br /&gt;
        if l_cdb = &amp;#039;YES&amp;#039; then&lt;br /&gt;
            l_status := &amp;#039;CDB&amp;#039;;&lt;br /&gt;
            execute immediate &amp;#039;select name from v\$pdbs&amp;#039; bulk collect into t_pdbs;&lt;br /&gt;
            for i in nvl(t_pdbs.first,1) .. nvl(t_pdbs.last,0)&lt;br /&gt;
            loop&lt;br /&gt;
                dbms_output.put_line (t_pdbs(i)||&amp;#039;:PDB&amp;#039;);&lt;br /&gt;
            end loop;&lt;br /&gt;
        else&lt;br /&gt;
            l_status := &amp;#039;Independent&amp;#039;;  -- col CDB exists but this is not one&lt;br /&gt;
        end if;&lt;br /&gt;
        if l_database_role like &amp;#039;%STANDBY%&amp;#039; then&lt;br /&gt;
            l_status := &amp;#039;Standby&amp;#039;;&lt;br /&gt;
        end if;&lt;br /&gt;
    exception&lt;br /&gt;
    when e_not_mounted then&lt;br /&gt;
        l_status := &amp;#039;Not Mounted&amp;#039;;&lt;br /&gt;
    when e_col_not_found then&lt;br /&gt;
        l_status := &amp;#039;pre12&amp;#039;;&lt;br /&gt;
    end;&lt;br /&gt;
&lt;br /&gt;
    dbms_output.put_line (&amp;#039;${db}&amp;#039;||&amp;#039;:&amp;#039;||l_status);&lt;br /&gt;
&lt;br /&gt;
end;&lt;br /&gt;
/&lt;br /&gt;
EOSQL&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Run a command or script on all databases in tnsnames.ora===&lt;br /&gt;
Very handy if you have a global tnsnames.ora accessible to all clients.&amp;lt;br /&amp;gt;&lt;br /&gt;
So from a client install, this has access to all databases.&amp;lt;br /&amp;gt;&lt;br /&gt;
Any files created can be created on the client so no need to scp to all the machines to recover spool files etc.&amp;lt;br /&amp;gt;&lt;br /&gt;
Downside: Cannot connect as sysdba across tns so password will need to be known for whatever user is used.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/ksh&lt;br /&gt;
TNSNAMES=&amp;quot;./tnsnames.ora&amp;quot;&lt;br /&gt;
[[ ! -r &amp;quot;${TNSNAMES}&amp;quot; ]] &amp;amp;&amp;amp; echo &amp;quot;${TNSNAMES} is not accessible&amp;quot; &amp;amp;&amp;amp; exit 1&lt;br /&gt;
&lt;br /&gt;
SIDLIST=$(perl -ne &amp;#039;print &amp;quot;$1\n&amp;quot; if /(?:SID|SERVICE_NAME)\s*=\s*(\S+?)\)/&amp;#039; ${TNSNAMES}|sort|uniq|xargs)&lt;br /&gt;
for SID in ${SIDLIST}&lt;br /&gt;
do&lt;br /&gt;
    echo &amp;quot;Processing $SID&amp;quot;&lt;br /&gt;
    ls -al | grep &amp;quot;^d&amp;quot; | grep &amp;quot;\_${SID}&amp;quot; &amp;gt;/dev/null&lt;br /&gt;
    if [[ $? -ne 0 ]]; then&lt;br /&gt;
        echo &amp;#039;exit&amp;#039; | sqlplus system/xxxxxx@${SID} @ReviewLite17.1.sql &amp;gt;/dev/null 2&amp;gt;&amp;amp;1&lt;br /&gt;
    else&lt;br /&gt;
        echo &amp;quot;directory already exists so must have done this SID&amp;quot;&lt;br /&gt;
    fi&lt;br /&gt;
done&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Run a command or script on all databases in oratab===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/usr/bin/ksh&lt;br /&gt;
# ==============================================================================&lt;br /&gt;
# Name         : all_db_do&lt;br /&gt;
# Description  : Loops over all the databases in oratab and executes the&lt;br /&gt;
#                specified SQL command - be careful!&lt;br /&gt;
#&lt;br /&gt;
# Parameters   : -v flag for verbose&lt;br /&gt;
#                [-f &amp;lt;filename&amp;gt; | &amp;lt;quoted SQL command to be executed&amp;gt;]&lt;br /&gt;
#&lt;br /&gt;
# Example      : all_db_do &amp;#039;alter system switch logfile;&amp;#039;&lt;br /&gt;
#                all_db_do -f sessions.sql&lt;br /&gt;
#&lt;br /&gt;
# Notes        : none&lt;br /&gt;
#&lt;br /&gt;
# Modification History&lt;br /&gt;
# ====================&lt;br /&gt;
# When      Who               What&lt;br /&gt;
# ========= ================= ==================================================&lt;br /&gt;
# 14-JAN-13 Stuart Barkley    Created&lt;br /&gt;
# 25-FEB-13 Stuart Barkley    Adapt for Solaris&lt;br /&gt;
# 21-MAR-13 Stuart Barkley    Check db is running first&lt;br /&gt;
# 29-APR-13 Stuart Barkley    Added verbose flag processing&lt;br /&gt;
# 24-MAY-13 Stuart Barkley    Wrap / as sysdba in quotes for older versions&lt;br /&gt;
# 23-JUN-16 Stuart Barkley    Add -f to run a file containing sql&lt;br /&gt;
# ==============================================================================&lt;br /&gt;
&lt;br /&gt;
PROGNAME=$(basename $0)&lt;br /&gt;
OS=$(uname -s)&lt;br /&gt;
&lt;br /&gt;
AWK=$(which awk)&lt;br /&gt;
GREP=$(which grep)&lt;br /&gt;
if [[ &amp;quot;${OS}&amp;quot; == &amp;quot;SunOS&amp;quot; ]]; then&lt;br /&gt;
    AWK=/usr/xpg4/bin/awk&lt;br /&gt;
    GREP=/usr/xpg4/bin/grep&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
if [[ ! -r /etc/oratab ]]; then&lt;br /&gt;
    if [[ &amp;quot;${OS}&amp;quot; == &amp;quot;SunOS&amp;quot; ]]; then&lt;br /&gt;
        echo &amp;quot;oratab is not where we want it. Please run &amp;#039;ln -s /var/opt/oracle/oratab /etc/oratab&amp;#039; as root and retry&amp;quot; &amp;amp;&amp;amp; exit 1&lt;br /&gt;
    else&lt;br /&gt;
        echo &amp;quot;Either Oracle is not installed or database is running without an oratab&amp;quot; &amp;amp;&amp;amp; exit 1&lt;br /&gt;
    fi&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
# -------------------------&lt;br /&gt;
# get the arguments, if any&lt;br /&gt;
# -------------------------&lt;br /&gt;
unset VERBOSE&lt;br /&gt;
while getopts &amp;quot;vf:&amp;quot; flag&lt;br /&gt;
do&lt;br /&gt;
    case &amp;quot;$flag&amp;quot; in&lt;br /&gt;
    v) VERBOSE=1;;&lt;br /&gt;
    f) FILE2RUN=$OPTARG;;&lt;br /&gt;
    esac&lt;br /&gt;
done&lt;br /&gt;
shift $((OPTIND-1))&lt;br /&gt;
&lt;br /&gt;
if [[ -z ${FILE2RUN} ]]; then&lt;br /&gt;
    # no file, need an SQL supplied&lt;br /&gt;
    if [[ -z $1 ]]; then&lt;br /&gt;
        echo &amp;quot;Usage: $0 [-v] [-f &amp;lt;filename&amp;gt; | &amp;lt;quoted SQL command to be executed&amp;gt;]&amp;quot;&lt;br /&gt;
        echo &amp;quot;eg: $0 -f sessions.sql&amp;quot;&lt;br /&gt;
        echo &amp;quot;eg: $0 &amp;#039;alter system switch logfile;&amp;#039;&amp;quot;&lt;br /&gt;
        exit 1&lt;br /&gt;
    fi&lt;br /&gt;
    SQL=$1&lt;br /&gt;
elif [[ -s ${FILE2RUN} ]]; then&lt;br /&gt;
    # file supplied and exists&lt;br /&gt;
    SQL=&amp;quot;@${FILE2RUN}&amp;quot;&lt;br /&gt;
else&lt;br /&gt;
    # file supplied, does it exist&lt;br /&gt;
    echo &amp;quot;File ${FILE2RUN} is empty or does not exist&amp;quot;&lt;br /&gt;
    echo &amp;quot;Usage: $0 [-v] [-f &amp;lt;filename&amp;gt; | &amp;lt;quoted SQL command to be executed&amp;gt;]&amp;quot;&lt;br /&gt;
    echo &amp;quot;eg: $0 -f sessions.sql&amp;quot;&lt;br /&gt;
    echo &amp;quot;eg: $0 &amp;#039;alter system switch logfile;&amp;#039;&amp;quot;&lt;br /&gt;
    exit 1&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
export ORAENV_ASK=NO&lt;br /&gt;
&lt;br /&gt;
for db in $(${AWK} -F: &amp;#039;NF &amp;amp;&amp;amp; $1 !~/[#*]/ {print $1}&amp;#039;  /etc/oratab)&lt;br /&gt;
do&lt;br /&gt;
    if ( [[ $1 != &amp;quot;startup&amp;quot; ]] &amp;amp;&amp;amp; [[ $(ps -ef | ${GREP} -c -E [o]ra_pmon_${db}) -eq 0 ]] ); then&lt;br /&gt;
        [[ ! -z &amp;quot;$VERBOSE&amp;quot; ]] &amp;amp;&amp;amp; echo &amp;quot;$db is not running, skipping...&amp;quot;&lt;br /&gt;
        continue&lt;br /&gt;
    fi&lt;br /&gt;
    echo&lt;br /&gt;
    [[ ! -z &amp;quot;$VERBOSE&amp;quot; ]] &amp;amp;&amp;amp; echo &amp;quot;vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv&amp;quot;&lt;br /&gt;
    [[ ! -z &amp;quot;$VERBOSE&amp;quot; ]] &amp;amp;&amp;amp; echo $db&lt;br /&gt;
    ORACLE_SID=$db&lt;br /&gt;
    . oraenv &amp;gt;/dev/null&lt;br /&gt;
    sqlplus -s &amp;quot;/ as sysdba&amp;quot; &amp;lt;&amp;lt;EOSQL&lt;br /&gt;
define SID=$ORACLE_SID&lt;br /&gt;
col comp_name format a50&lt;br /&gt;
col value for a40&lt;br /&gt;
set linesize 1000&lt;br /&gt;
set pagesize 100&lt;br /&gt;
$SQL&lt;br /&gt;
EOSQL&lt;br /&gt;
    [[ ! -z &amp;quot;$VERBOSE&amp;quot; ]] &amp;amp;&amp;amp; echo &amp;quot;^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^&amp;quot;&lt;br /&gt;
done&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
all_db_do &amp;quot;create or replace directory data_pump_dir as &amp;#039;/oracle/export/&amp;amp;SID&amp;#039;;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
all_db_do &amp;quot;archive log list&amp;quot;&lt;br /&gt;
&lt;br /&gt;
all_db_do &amp;quot;shutdown immediate&amp;quot;&lt;br /&gt;
&lt;br /&gt;
all_db_do &amp;#039;alter system set log_archive_dest_1=&amp;quot;location=/oracle/arch/&amp;amp;SID&amp;quot; scope=both;&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Run an SQL command on behalf of another user===&lt;br /&gt;
It can be used to execute any sql command as a specified user provided this procedure is created in sys schema.&amp;lt;br /&amp;gt;&lt;br /&gt;
* not got this working properly yet *&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set serveroutput on&lt;br /&gt;
create or replace procedure run_sql_as_user ( p_schema_name in varchar2&lt;br /&gt;
                                            , p_sql         in varchar2&lt;br /&gt;
                                            ) is&lt;br /&gt;
    l_user_id dba_users.user_id%type;&lt;br /&gt;
    l_cursor  number;&lt;br /&gt;
    l_rc      number;&lt;br /&gt;
begin&lt;br /&gt;
    dbms_output.enable(null);&lt;br /&gt;
    begin&lt;br /&gt;
        select u.user_id&lt;br /&gt;
        into   l_user_id&lt;br /&gt;
        from   dba_users u&lt;br /&gt;
        where  u.username = p_schema_name;&lt;br /&gt;
    exception&lt;br /&gt;
    when no_data_found then&lt;br /&gt;
        raise_application_error (-20001, &amp;#039;Cannot find user &amp;#039;||p_schema_name);&lt;br /&gt;
    end;&lt;br /&gt;
    l_cursor := dbms_sys_sql.open_cursor;&lt;br /&gt;
    dbms_sys_sql.parse_as_user ( c             =&amp;gt; l_cursor&lt;br /&gt;
                               , statement     =&amp;gt; p_sql&lt;br /&gt;
                               , language_flag =&amp;gt; dbms_sql.native&lt;br /&gt;
                               , userid        =&amp;gt; l_user_id&lt;br /&gt;
    );&lt;br /&gt;
    l_rc := dbms_sys_sql.execute(l_cursor);&lt;br /&gt;
    dbms_sys_sql.close_cursor(l_cursor);&lt;br /&gt;
exception&lt;br /&gt;
when others then&lt;br /&gt;
    raise_application_error (-20001, &amp;#039;ERROR: &amp;#039;||sqlerrm);&lt;br /&gt;
end;&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Run a script on all databases listed in tnsnames.ora===&lt;br /&gt;
Can run an SQL command file on all SID/SERVICE found in a tnsnames.ora file. I use this from a client laptop having a global tns file on it.&amp;lt;br /&amp;gt;&lt;br /&gt;
This way it&amp;#039;s not necessary to copy the file onto every host before executing it. Any files created by the script will be created on the client.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/ksh&lt;br /&gt;
&lt;br /&gt;
TNSNAMES=&amp;quot;./tnsnames.ora&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[ ! -r &amp;quot;${TNSNAMES}&amp;quot; ]] &amp;amp;&amp;amp; echo &amp;quot;${TNSNAMES} is not accessible&amp;quot; &amp;amp;&amp;amp; exit 1&lt;br /&gt;
&lt;br /&gt;
SIDLIST=$(perl -ne &amp;#039;print &amp;quot;$1\n&amp;quot; if /(?:SID|SERVICE_NAME)\s*=\s*(\S+?)\)/&amp;#039; ${TNSNAMES}|sort|uniq|xargs)&lt;br /&gt;
for SID in ${SIDLIST}&lt;br /&gt;
do&lt;br /&gt;
    echo &amp;quot;Processing $SID&amp;quot;&lt;br /&gt;
    ls -al | grep &amp;quot;^d&amp;quot; | grep &amp;quot;\_${SID}&amp;quot; &amp;gt;/dev/null&lt;br /&gt;
    if [[ $? -ne 0 ]]; then&lt;br /&gt;
        echo &amp;#039;exit&amp;#039; | sqlplus system/password@${SID} @ReviewLite17.1.sql &amp;gt;/dev/null 2&amp;gt;&amp;amp;1&lt;br /&gt;
    else&lt;br /&gt;
        echo &amp;quot;directory already exists so must have done this SID&amp;quot;&lt;br /&gt;
    fi&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===List invalid objects===&lt;br /&gt;
 set lines 200&lt;br /&gt;
 set pages 200&lt;br /&gt;
 col obj format a40&lt;br /&gt;
 select owner||&amp;#039;.&amp;#039;||object_name obj&lt;br /&gt;
 ,      object_type&lt;br /&gt;
 from   dba_objects&lt;br /&gt;
 where  1=1&lt;br /&gt;
 and    status = &amp;#039;INVALID&amp;#039;;&lt;br /&gt;
===Recompile all invalid objects===&lt;br /&gt;
@?/rdbms/admin/utlrp.sql&lt;br /&gt;
===See how much space is left in the flash recovery area (FRA)===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select name&lt;br /&gt;
,      to_char (space_limit, &amp;#039;999,999,999,999&amp;#039;) as space_limit&lt;br /&gt;
,      to_char (space_limit - space_used + space_reclaimable&lt;br /&gt;
,               &amp;#039;999,999,999,999&amp;#039;)&lt;br /&gt;
           as space_available&lt;br /&gt;
,      round ( (space_used - space_reclaimable) / space_limit * 100, 1)&lt;br /&gt;
           as pct_full&lt;br /&gt;
from   v$recovery_file_dest;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# ==============================================&lt;br /&gt;
# Check FRA to see how much space is reclaimable&lt;br /&gt;
# ==============================================&lt;br /&gt;
fra_reclaim_check() {&lt;br /&gt;
&lt;br /&gt;
LOGFILE=${RMAN_LogDir}/${ORACLE_SID}_`date &amp;#039;+%Y%m&amp;#039;`_${V_SCRIPT}.log&lt;br /&gt;
sqlplus &amp;quot;/ as sysdba&amp;quot; &amp;lt;&amp;lt;EOSQL &amp;gt; /tmp/results.$$&lt;br /&gt;
set vefify off echo off heading off newpage none linesize 1000 echo off&lt;br /&gt;
select &amp;#039;Filesystem:&amp;#039;||name||&lt;br /&gt;
       &amp;#039;; Total(Gb):&amp;#039;||round((space_limit/1073741824),2) ||&lt;br /&gt;
       &amp;#039;; Reclaimable(Gb):&amp;#039;||round((space_reclaimable/1073741824),2) ||&lt;br /&gt;
       &amp;#039;; Reclaimable(%):&amp;#039;||round( ((space_reclaimable/1073741824)/(space_limit/1073741824)*100),2 )&lt;br /&gt;
from   v$recovery_file_dest&lt;br /&gt;
/&lt;br /&gt;
EOSQL&lt;br /&gt;
cat /tmp/results.$$ &amp;gt;&amp;gt; $LOGFILE&lt;br /&gt;
rm /tmp/results.$$&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===How far back can we flashback?===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
col time_now              for a25&lt;br /&gt;
col time_oldest_flashback for a25&lt;br /&gt;
select to_char(sysdate,&amp;#039;DD-MON-YY HH24:MI&amp;#039;)                    time_now&lt;br /&gt;
,      to_char(fdl.oldest_flashback_time, &amp;#039;DD-MON-YY HH24:MI&amp;#039;) time_oldest_flashback&lt;br /&gt;
,      round((sysdate-fdl.oldest_flashback_time)*24,1)         hours_flashback_possible&lt;br /&gt;
from   v$database d&lt;br /&gt;
,      v$flashback_database_log fdl&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===DBA privs tables===&lt;br /&gt;
 DBA_AQ_AGENT_PRIVS&lt;br /&gt;
 DBA_COL_PRIVS&lt;br /&gt;
 DBA_PRIV_AUDIT_OPTS&lt;br /&gt;
 DBA_REPGROUP_PRIVILEGES&lt;br /&gt;
 DBA_ROLE_PRIVS&lt;br /&gt;
 DBA_RSRC_CONSUMER_GROUP_PRIVS&lt;br /&gt;
 DBA_RSRC_MANAGER_SYSTEM_PRIVS&lt;br /&gt;
 DBA_SYS_PRIVS&lt;br /&gt;
 DBA_TAB_PRIVS&lt;br /&gt;
 DBA_WM_SYS_PRIVS&lt;br /&gt;
 DBA_WORKSPACE_PRIVS&lt;br /&gt;
&lt;br /&gt;
===Schedule a shell job===&lt;br /&gt;
 begin&lt;br /&gt;
     dbms_scheduler.create_program ( program_name   =&amp;gt; &amp;#039;myshelljob&amp;#039;&lt;br /&gt;
                                   , program_action =&amp;gt; &amp;#039;/home/oracle/scripts/shell.sh&amp;#039;&lt;br /&gt;
                                   , program_type   =&amp;gt; &amp;#039;EXECUTABLE&amp;#039;&lt;br /&gt;
                                   , comments       =&amp;gt; &amp;#039;Run a shell&amp;#039;&lt;br /&gt;
                                   , enabled        =&amp;gt; TRUE&lt;br /&gt;
                                   );&lt;br /&gt;
 end;&lt;br /&gt;
 /&lt;br /&gt;
===Start the job===&lt;br /&gt;
 begin&lt;br /&gt;
     dbms_sheduler.create_job ( job_name     =&amp;gt; &amp;#039;myshelljob&amp;#039;&lt;br /&gt;
                              , program_name =&amp;gt; &amp;#039;myshelljob&amp;#039;&lt;br /&gt;
                              , start_date   =&amp;gt;&lt;br /&gt;
                              );&lt;br /&gt;
 /&lt;br /&gt;
&lt;br /&gt;
===What statement is a user running?===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select a.sid&lt;br /&gt;
,      a.serial#&lt;br /&gt;
,      b.sql_text&lt;br /&gt;
from   v$session a&lt;br /&gt;
,      v$sqlarea b&lt;br /&gt;
where  a.sql_address = b.address&lt;br /&gt;
and    a.username    = &amp;#039;&amp;amp;username&amp;#039;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===See what statements all users are running===&lt;br /&gt;
Useful to see what is happening when process limit is reached&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 300 pages 1000&lt;br /&gt;
&lt;br /&gt;
col username for a10&lt;br /&gt;
col command for 999 head &amp;quot;CMD&amp;quot;&lt;br /&gt;
col lockwait for a10&lt;br /&gt;
col status for a8&lt;br /&gt;
col schemaname for a12&lt;br /&gt;
col osuser for a10&lt;br /&gt;
col process for a10&lt;br /&gt;
col program for a20&lt;br /&gt;
col machine for a10&lt;br /&gt;
col action for a10&lt;br /&gt;
col module for a10&lt;br /&gt;
col identifier for a10&lt;br /&gt;
col event for a27&lt;br /&gt;
col state for a8&lt;br /&gt;
col service_name for a10&lt;br /&gt;
col serial# for 999999&lt;br /&gt;
&lt;br /&gt;
select a.username&lt;br /&gt;
,      a.command&lt;br /&gt;
,      a.lockwait&lt;br /&gt;
,      a.status&lt;br /&gt;
,      a.schemaname&lt;br /&gt;
,      a.osuser&lt;br /&gt;
,      a.process&lt;br /&gt;
,      a.machine&lt;br /&gt;
,      a.program&lt;br /&gt;
,      a.type&lt;br /&gt;
--,      a.sql_exec_start&lt;br /&gt;
--,      a.plsql_object_id&lt;br /&gt;
--,      a.plsql_subprogram_id&lt;br /&gt;
--,      a.module&lt;br /&gt;
--,      a.action&lt;br /&gt;
,      a.logon_time&lt;br /&gt;
,      a.event&lt;br /&gt;
,      a.wait_time&lt;br /&gt;
,      a.seconds_in_wait&lt;br /&gt;
,      a.state&lt;br /&gt;
--,      a.service_name&lt;br /&gt;
,      a.serial#&lt;br /&gt;
,      b.sql_text&lt;br /&gt;
from   v$session a&lt;br /&gt;
,      v$sqlarea b&lt;br /&gt;
where  a.sql_address = b.address&lt;br /&gt;
order  by a.logon_time desc&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
set lines 80&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===A logminer session===&lt;br /&gt;
Mine all SQL statements in a 10 minute period&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sqlplus / as sysdba&lt;br /&gt;
alter session set nls_date_format = &amp;#039;DD-MON-YYYY HH24:MI:SS&amp;#039;;&lt;br /&gt;
execute dbms_logmnr.start_logmnr ( starttime =&amp;gt; &amp;#039;27-OCT-2009 11:05:00&amp;#039;&lt;br /&gt;
                                 , endtime   =&amp;gt; &amp;#039;27-OCT-2009 11:15:00&amp;#039;&lt;br /&gt;
                                 , options   =&amp;gt; dbms_logmnr.dict_from_online_catalog+dbms_logmnr.continuous_mine&lt;br /&gt;
                                 );&lt;br /&gt;
create table mycontents as select * from v$logmnr_contents;&lt;br /&gt;
execute dbms_logmnr.end_logmnr(); &lt;br /&gt;
&lt;br /&gt;
select * from mycontents;&lt;br /&gt;
&lt;br /&gt;
drop table mycontents;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Huge Pages===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
#&lt;br /&gt;
# hugepages_settings.sh&lt;br /&gt;
#&lt;br /&gt;
# Linux bash script to compute values for the&lt;br /&gt;
# recommended HugePages/HugeTLB configuration&lt;br /&gt;
#&lt;br /&gt;
# Note: This script does calculation for all shared memory&lt;br /&gt;
# segments available when the script is run, no matter it&lt;br /&gt;
# is an Oracle RDBMS shared memory segment or not.&lt;br /&gt;
# Check for the kernel version&lt;br /&gt;
KERN=`uname -r | awk -F. &amp;#039;{ printf(&amp;quot;%d.%d\n&amp;quot;,$1,$2); }&amp;#039;`&lt;br /&gt;
# Find out the HugePage size&lt;br /&gt;
HPG_SZ=`grep Hugepagesize /proc/meminfo | awk {&amp;#039;print $2&amp;#039;}`&lt;br /&gt;
# Start from 1 pages to be on the safe side and guarantee 1 free HugePage&lt;br /&gt;
NUM_PG=1&lt;br /&gt;
# Cumulative number of pages required to handle the running shared memory segments&lt;br /&gt;
for SEG_BYTES in `ipcs -m | awk {&amp;#039;print $5&amp;#039;} | grep &amp;quot;[0-9][0-9]*&amp;quot;`&lt;br /&gt;
do&lt;br /&gt;
   MIN_PG=`echo &amp;quot;$SEG_BYTES/($HPG_SZ*1024)&amp;quot; | bc -q`&lt;br /&gt;
   if [ $MIN_PG -gt 0 ]; then&lt;br /&gt;
      NUM_PG=`echo &amp;quot;$NUM_PG+$MIN_PG+1&amp;quot; | bc -q`&lt;br /&gt;
   fi&lt;br /&gt;
done&lt;br /&gt;
# Finish with results&lt;br /&gt;
case $KERN in&lt;br /&gt;
   &amp;#039;2.4&amp;#039;) HUGETLB_POOL=`echo &amp;quot;$NUM_PG*$HPG_SZ/1024&amp;quot; | bc -q`;&lt;br /&gt;
          echo &amp;quot;Recommended setting: vm.hugetlb_pool = $HUGETLB_POOL&amp;quot; ;;&lt;br /&gt;
   &amp;#039;2.6&amp;#039; | &amp;#039;3.8&amp;#039;) echo &amp;quot;Recommended setting: vm.nr_hugepages = $NUM_PG&amp;quot; ;;&lt;br /&gt;
    *) echo &amp;quot;Unrecognized kernel version $KERN. Exiting.&amp;quot; ;;&lt;br /&gt;
esac&lt;br /&gt;
# End&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Pretty longops listing===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 2000 pages 1000&lt;br /&gt;
col opname for a34 head &amp;quot;Job&amp;quot;&lt;br /&gt;
col message for a60&lt;br /&gt;
col perc_done for a10 head &amp;quot;Done&amp;quot;&lt;br /&gt;
col started for a18&lt;br /&gt;
col killer for a15&lt;br /&gt;
col mins_busy head &amp;quot;Mins busy&amp;quot;&lt;br /&gt;
col mins_left head &amp;quot;Mins left&amp;quot;&lt;br /&gt;
select sid||&amp;#039;,&amp;#039;||serial#                       killer&lt;br /&gt;
,      opname&lt;br /&gt;
,      message&lt;br /&gt;
,      round ((sofar/totalwork),4)*100||&amp;#039;%&amp;#039;    perc_done&lt;br /&gt;
,      to_char(start_time,&amp;#039;DD-MON-YY HH24:MI&amp;#039;) started&lt;br /&gt;
,      floor(elapsed_seconds/60)               mins_busy&lt;br /&gt;
,      ceil(time_remaining/60)                 mins_left&lt;br /&gt;
from   v$session_longops&lt;br /&gt;
where  1=1&lt;br /&gt;
and    sofar     != totalwork&lt;br /&gt;
and    totalwork != 0&lt;br /&gt;
and    opname    like &amp;#039;RMAN%&amp;#039;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select * from v$session where module=&amp;#039;Data Pump Worker&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or attach to the impdp job and it shows percentage done.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Get the SID from v$session_longops and plug it into v$session to check the SQL command details.&lt;br /&gt;
&lt;br /&gt;
Current Running SQLs&lt;br /&gt;
--------------------&lt;br /&gt;
set pages 1000 lines 2000&lt;br /&gt;
col program  format a40&lt;br /&gt;
col sql_text format a130&lt;br /&gt;
&lt;br /&gt;
select s.sid&lt;br /&gt;
,      s.status&lt;br /&gt;
,      s.last_call_et&lt;br /&gt;
,      s.program&lt;br /&gt;
,      sa.sql_id&lt;br /&gt;
,      sa.sql_text&lt;br /&gt;
from   v$session s&lt;br /&gt;
,      v$sqlarea sa&lt;br /&gt;
where  s.sql_id = sa.sql_id&lt;br /&gt;
and    s.sid = &amp;#039;&amp;amp;sid&amp;#039;&lt;br /&gt;
/ &lt;br /&gt;
&lt;br /&gt;
set pages 1000 lines 2000&lt;br /&gt;
col USERNAME for a10&lt;br /&gt;
col OSUSER   for a10&lt;br /&gt;
col MACHINE  for a10&lt;br /&gt;
&lt;br /&gt;
select s.sid&lt;br /&gt;
,      s.serial#&lt;br /&gt;
,      p.spid&lt;br /&gt;
,      s.username&lt;br /&gt;
,      s.osuser&lt;br /&gt;
,      s.status&lt;br /&gt;
,      s.process fg_pid&lt;br /&gt;
,      s.longon_time&lt;br /&gt;
,      s.machine&lt;br /&gt;
,      p.spid bg_pid&lt;br /&gt;
from   gv$session s&lt;br /&gt;
,      gv$process p&lt;br /&gt;
where  s.addr = p.addr&lt;br /&gt;
and    s.sid  = &amp;#039;&amp;amp;sid&amp;#039;&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
$ps -ef | grep &amp;lt;spid&amp;gt;&lt;br /&gt;
&lt;br /&gt;
set pages 1000 lines 2000&lt;br /&gt;
SELECT INST_ID&lt;br /&gt;
,      SID&lt;br /&gt;
,      SERIAL#&lt;br /&gt;
,      SQL_ID&lt;br /&gt;
,      USERNAME&lt;br /&gt;
,      PROGRAM&lt;br /&gt;
,      MACHINE&lt;br /&gt;
,      SERVICE_NAME&lt;br /&gt;
FROM   GV$SESSION&lt;br /&gt;
WHERE  SID IN (&amp;#039;&amp;lt;SID_NO.1&amp;gt;&amp;#039;,&amp;#039;&amp;lt;SID_NO.2&amp;gt;&amp;#039;)&lt;br /&gt;
/&lt;br /&gt;
Active Running SQLs&lt;br /&gt;
--------------------&lt;br /&gt;
set pages 1000 lines 2000&lt;br /&gt;
col SPID     for a10&lt;br /&gt;
col PROGRAM  for a15&lt;br /&gt;
col OSUSER   for a10&lt;br /&gt;
col ACTION   for a10&lt;br /&gt;
col EVENT    for a25&lt;br /&gt;
col SQL_TEXT for a25&lt;br /&gt;
col MACHINE  for a10&lt;br /&gt;
col P1TEXT   for a10 &lt;br /&gt;
col P2TEXT   for a10&lt;br /&gt;
col P3TEXT   for a10  &lt;br /&gt;
SELECT b.sid&lt;br /&gt;
,      b.serial#&lt;br /&gt;
,      a.spid&lt;br /&gt;
,      b.sql_id&lt;br /&gt;
,      b.program&lt;br /&gt;
,      b.osuser&lt;br /&gt;
,      b.machine&lt;br /&gt;
,      b.type&lt;br /&gt;
,      b.event&lt;br /&gt;
,      b.action&lt;br /&gt;
,      b.p1text&lt;br /&gt;
,      b.p2text&lt;br /&gt;
,      b.p3text&lt;br /&gt;
,      b.state&lt;br /&gt;
,      c.sql_text&lt;br /&gt;
,      b.logon_time&lt;br /&gt;
FROM   v$process a&lt;br /&gt;
,      v$session b&lt;br /&gt;
,      v$sqltext c&lt;br /&gt;
WHERE  a.addr           = b.paddr&lt;br /&gt;
AND    b.sql_hash_value = c.hash_value&lt;br /&gt;
AND    b.STATUS         = &amp;#039;ACTIVE&amp;#039;&lt;br /&gt;
AND    b.sid            = &amp;#039;&amp;amp;sid&amp;#039;&lt;br /&gt;
ORDER  BY a.spid&lt;br /&gt;
,      c.piece&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
OR - Use the below Query &lt;br /&gt;
&lt;br /&gt;
Longops.sql&lt;br /&gt;
----------- &lt;br /&gt;
set pages 50000 lines 32767&lt;br /&gt;
col OPNAME for a10&lt;br /&gt;
col SID form 9999&lt;br /&gt;
col SERIAL form 9999999&lt;br /&gt;
col PROGRAM for a10&lt;br /&gt;
col USERNAME for a10&lt;br /&gt;
col SQL_TEXT for a40&lt;br /&gt;
col START_TIME for a10&lt;br /&gt;
col LAST_UPDATE_TIME for a10&lt;br /&gt;
col TARGET for a25&lt;br /&gt;
col MESSAGE for a25&lt;br /&gt;
&lt;br /&gt;
alter session set nls_date_format = &amp;#039;DD-MM-YYYY HH24:MI:SS&amp;#039;;&lt;br /&gt;
&lt;br /&gt;
SELECT l.inst_id,l.sid, l.serial#, l.sql_id, l.opname, l.username, l.target, l.sofar, l.totalwork, l.start_time,l.last_update_time,round(l.time_remaining/60,2) &amp;quot;REMAIN MINS&amp;quot;, round(l.elapsed_seconds/60,2) &amp;quot;ELAPSED MINS&amp;quot;, round((l.time_remaining+l.elapsed_seconds)/60,2) &amp;quot;TOTAL MINS&amp;quot;, ROUND(l.SOFAR/l.TOTALWORK*100,2) &amp;quot;%_COMPLETE&amp;quot;, l.message,s.sql_text &lt;br /&gt;
FROM gv$session_longops l &lt;br /&gt;
LEFT OUTER JOIN v$sql s on s.hash_value=l.sql_hash_value and s.address=l.sql_address and s.child_number=0&lt;br /&gt;
WHERE l.OPNAME NOT LIKE &amp;#039;RMAN%&amp;#039; AND l.OPNAME NOT LIKE &amp;#039;%aggregate%&amp;#039; AND l.TOTALWORK != 0 AND l.sofar&amp;lt;&amp;gt;l.totalwork AND l.time_remaining &amp;gt; 0&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Apply the database patch after the ORACLE_HOME has been patched===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ORAENV_ASK=NO&lt;br /&gt;
export ORACLE_SID=$1&lt;br /&gt;
. oraenv&lt;br /&gt;
&lt;br /&gt;
sqlplus /nolog &amp;lt;&amp;lt;EOSQL&lt;br /&gt;
connect / as sysdba&lt;br /&gt;
startup&lt;br /&gt;
@?/rdbms/admin/catbundle.sql psu apply&lt;br /&gt;
@?/rdbms/admin/utlrp.sql&lt;br /&gt;
purge dba_recyclebin;&lt;br /&gt;
&lt;br /&gt;
prompt check patch apply...&lt;br /&gt;
set lines 150&lt;br /&gt;
col action_time for a50&lt;br /&gt;
col comp_name for a50&lt;br /&gt;
col comments for a50&lt;br /&gt;
&lt;br /&gt;
select action_time,action,comments from sys.registry\$history where trunc(action_time) = trunc(sysdate);&lt;br /&gt;
select comp_name,version,status,modified from dba_registry;&lt;br /&gt;
exit&lt;br /&gt;
EOSQL&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Show how much archivelog data is generated per day===&lt;br /&gt;
A companion script for &amp;#039;how many log switches in a day&amp;#039;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
col orderby noprint&lt;br /&gt;
select trunc(first_time) orderby&lt;br /&gt;
,      to_char(first_time,&amp;#039;DD-MON-YYYY&amp;#039;) &amp;quot;Date&amp;quot;&lt;br /&gt;
,      round(sum(bytes/1024/1024/1024),2) arch_logs_gigs&lt;br /&gt;
from (&lt;br /&gt;
    select unique (blocks * block_size) bytes,&lt;br /&gt;
    thread#,&lt;br /&gt;
    sequence#,&lt;br /&gt;
    resetlogs_change#,&lt;br /&gt;
    first_time&lt;br /&gt;
    from v$archived_log&lt;br /&gt;
)&lt;br /&gt;
group by trunc(first_time)&lt;br /&gt;
,      to_char(first_time, &amp;#039;DD-MON-YYYY&amp;#039;)&lt;br /&gt;
order by trunc(first_time) desc&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Abort a hanging database even when sysdba cannot connect===&lt;br /&gt;
Unable to connect to database with sqlplus / as sysdba because audit file cannot be created?&lt;br /&gt;
* [http://tech.e2sn.com/oracle/troubleshooting/hang/how-to-log-on-even-when-sysdba-can-t-do-so tech.e2sn.com]&lt;br /&gt;
* [http://blog.dbi-services.com/oracle-is-hanging-dont-forget-hanganalyze-and-systemstate/ blog.dbi-services.com]&lt;br /&gt;
Instead of just killing the pmon process, there is a kinder (and more useful) way to kill the database.&amp;lt;br /&amp;gt;&lt;br /&gt;
Use the hidden, undocumented &amp;#039;prelim&amp;#039; switch parameter to sqlplus to make a connection to the database without creating SGA session data structures.&amp;lt;br /&amp;gt;&lt;br /&gt;
It can be very useful for hang analysis so the possible cause can be found after the database has been restarted.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sqlplus -prelim / as sysdba&lt;br /&gt;
oradebug unlimit&lt;br /&gt;
oradebug hanganalyze 3&lt;br /&gt;
oradebug setmypid              -- or oradebug setorapname diag&lt;br /&gt;
oradebug dump ashdumpseconds 30&lt;br /&gt;
oradebug dump systemstate 10   -- or oradebug dump systemstate 266&lt;br /&gt;
oradebug tracefile_name&lt;br /&gt;
shutdown abort&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Lists Oracle session with kill session statement all ready to go===&lt;br /&gt;
disconnect attempts to kill the o/s processes too. kill doesn&amp;#039;t.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
col killer for a60&lt;br /&gt;
col osuser for a12&lt;br /&gt;
col logon  for a23&lt;br /&gt;
col spid   for a8&lt;br /&gt;
col username for a15&lt;br /&gt;
col program for a50&lt;br /&gt;
set lines 2000&lt;br /&gt;
select &amp;#039;alter system disconnect session &amp;#039;&amp;#039;&amp;#039;||s.sid||&amp;#039;,&amp;#039;||s.serial#||&amp;#039;&amp;#039;&amp;#039; immediate;&amp;#039; killer&lt;br /&gt;
,      s.inst_id&lt;br /&gt;
,      to_char(s.logon_time,&amp;#039;DD-MON-YY HH24:MI:SS&amp;#039;) logon&lt;br /&gt;
,      sci.osuser&lt;br /&gt;
,      p.spid&lt;br /&gt;
,      s.username&lt;br /&gt;
,      s.program&lt;br /&gt;
from   gv$session s&lt;br /&gt;
,      gv$session_connect_info sci&lt;br /&gt;
,      gv$process p&lt;br /&gt;
where  1=1&lt;br /&gt;
and    p.addr     = s.paddr&lt;br /&gt;
and    p.inst_id  = s.inst_id&lt;br /&gt;
and    s.sid      = sci.sid&lt;br /&gt;
and    s.serial#  = sci.serial#&lt;br /&gt;
and    s.type    != &amp;#039;BACKGROUND&amp;#039;&lt;br /&gt;
and    sci.osuser = &amp;#039;oraibm&amp;#039;&lt;br /&gt;
order  by s.logon_time desc&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
KILLER                                                          INST_ID LOGON                   OSUSER       SPID     USERNAME        PROGRAM&lt;br /&gt;
------------------------------------------------------------ ---------- ----------------------- ------------ -------- --------------- --------------------------------------------------&lt;br /&gt;
alter system disconnect session &amp;#039;490,33947&amp;#039; immediate;                1 23-JUN-16 13:30:53      oraibm       23205    SYS             sqlplus@benouerp07 (TNS V1-V3)&lt;br /&gt;
alter system disconnect session &amp;#039;490,33947&amp;#039; immediate;                1 23-JUN-16 13:30:53      oraibm       23205    SYS             sqlplus@benouerp07 (TNS V1-V3)&lt;br /&gt;
alter system disconnect session &amp;#039;490,33947&amp;#039; immediate;                1 23-JUN-16 13:30:53      oraibm       23205    SYS             sqlplus@benouerp07 (TNS V1-V3)&lt;br /&gt;
alter system disconnect session &amp;#039;490,33947&amp;#039; immediate;                1 23-JUN-16 13:30:53      oraibm       23205    SYS             sqlplus@benouerp07 (TNS V1-V3)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===How much space is being used by a guaranteed restore point?===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
show parameter recovery&lt;br /&gt;
set numwi 15&lt;br /&gt;
set lines 200&lt;br /&gt;
col name for a40&lt;br /&gt;
col time for a23&lt;br /&gt;
col gigs_limit head &amp;quot;Max (but check df -g also!)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
select name&lt;br /&gt;
,      time&lt;br /&gt;
,      round(storage_size/1024/1024/1024,2) gigs_used&lt;br /&gt;
from   v$restore_point&lt;br /&gt;
where  1=1&lt;br /&gt;
and    guarantee_flashback_database = &amp;#039;YES&amp;#039;&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
select * from v$flash_recovery_area_usage&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
select name&lt;br /&gt;
,      round(space_used/1024/1024/1024,2) gigs_used&lt;br /&gt;
,      round(space_limit/1024/1024/1024,2) gigs_limit&lt;br /&gt;
,      space_reclaimable&lt;br /&gt;
,      number_of_files&lt;br /&gt;
from v$recovery_file_dest&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Get statistics for LOB columns in a table===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select &lt;br /&gt;
  max(dbms_lob.getlength(lob_content)) max_len&lt;br /&gt;
, avg(dbms_lob.getlength(lob_content)) avg_len&lt;br /&gt;
, min(dbms_lob.getlength(lob_content)) min_len&lt;br /&gt;
, sum(case when dbms_lob.getlength(lob_content) &amp;lt;= 4000 then 1&lt;br /&gt;
else 0 end) &amp;quot;&amp;lt;4k&amp;quot;&lt;br /&gt;
, sum(case when dbms_lob.getlength(lob_content) &amp;gt; 4000 then 1&lt;br /&gt;
else 0 end) &amp;quot;&amp;gt;4k&amp;quot;&lt;br /&gt;
, sum(case when dbms_lob.getlength(lob_content) is null then 1 else&lt;br /&gt;
0 end) &amp;quot;is null&amp;quot;&lt;br /&gt;
from &amp;amp;tablename&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===badprivs.sql===&lt;br /&gt;
Check to see if any ordinary users have privileges / access / grants / rights they should not have&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select grantee, privilege, admin_option&lt;br /&gt;
from   sys.dba_sys_privs&lt;br /&gt;
where  (       privilege like &amp;#039;% ANY %&amp;#039;&lt;br /&gt;
        or     privilege in (&amp;#039;BECOME USER&amp;#039;, &amp;#039;UNLIMITED TABLESPACE&amp;#039;)&lt;br /&gt;
        or     admin_option = &amp;#039;YES&amp;#039;&lt;br /&gt;
       )&lt;br /&gt;
and    grantee not in (&amp;#039;SYS&amp;#039;, &amp;#039;SYSTEM&amp;#039;, &amp;#039;OUTLN&amp;#039;, &amp;#039;AQ_ADMINISTRATOR_ROLE&amp;#039;,&lt;br /&gt;
                      &amp;#039;DBA&amp;#039;, &amp;#039;EXP_FULL_DATABASE&amp;#039;, &amp;#039;IMP_FULL_DATABASE&amp;#039;,&lt;br /&gt;
                      &amp;#039;OEM_MONITOR&amp;#039;, &amp;#039;CTXSYS&amp;#039;, &amp;#039;DBSNMP&amp;#039;, &amp;#039;IFSSYS&amp;#039;,&lt;br /&gt;
                      &amp;#039;IFSSYS$CM&amp;#039;, &amp;#039;MDSYS&amp;#039;, &amp;#039;ORDPLUGINS&amp;#039;, &amp;#039;ORDSYS&amp;#039;,&lt;br /&gt;
                      &amp;#039;TIMESERIES_DBA&amp;#039;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Generate a list of tablespaces ready for a migration===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set echo off&lt;br /&gt;
set lines 300&lt;br /&gt;
set pages 0&lt;br /&gt;
Set headi off&lt;br /&gt;
set feedb off&lt;br /&gt;
set long 32000&lt;br /&gt;
&lt;br /&gt;
spool migration_create_target_tablespaces.sql&lt;br /&gt;
&lt;br /&gt;
exec dbms_metadata.set_transform_param(dbms_metadata.session_transform,&amp;#039;SQLTERMINATOR&amp;#039;,TRUE);&lt;br /&gt;
select DBMS_METADATA.GET_DDL(&amp;#039;TABLESPACE&amp;#039;,tablespace_name) from dba_tablespaces&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
spool off&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===List the privileges assigned to users on directories===&lt;br /&gt;
table_name is the name of the directory...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select grantor&lt;br /&gt;
,      grantee&lt;br /&gt;
,      table_schema&lt;br /&gt;
,      table_name&lt;br /&gt;
,      privilege&lt;br /&gt;
from   all_tab_privs&lt;br /&gt;
where  table_name = &amp;#039;DATA_PUMP_DIR&amp;#039;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===List the privileges assigned to users on packages/procedures===&lt;br /&gt;
table_name is the name of the package...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select grantor&lt;br /&gt;
,      grantee&lt;br /&gt;
,      table_schema&lt;br /&gt;
,      table_name&lt;br /&gt;
,      privilege&lt;br /&gt;
from   all_tab_privs&lt;br /&gt;
where  upper(table_name) like upper(&amp;#039;%UTL_FILE%&amp;#039;)&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===List the system privileges assigned to a user (used to copy user as or clone user as)===&lt;br /&gt;
Maybe this one is better [[Extract ddl with &amp;quot;dbms metadata.get ddl&amp;quot;]]&lt;br /&gt;
&lt;br /&gt;
 SELECT LPAD(&amp;#039; &amp;#039;, 2*level) || granted_role &amp;quot;USER PRIVS&amp;quot;&lt;br /&gt;
 FROM (&lt;br /&gt;
   SELECT NULL grantee,  username granted_role&lt;br /&gt;
   FROM dba_users&lt;br /&gt;
   WHERE username LIKE UPPER(&amp;#039;%&amp;amp;uname%&amp;#039;)&lt;br /&gt;
   UNION&lt;br /&gt;
   SELECT grantee, granted_role&lt;br /&gt;
   FROM dba_role_privs&lt;br /&gt;
   UNION&lt;br /&gt;
   SELECT grantee, privilege&lt;br /&gt;
   FROM dba_sys_privs)&lt;br /&gt;
 START WITH grantee IS NULL&lt;br /&gt;
 CONNECT BY grantee = prior granted_role;&lt;br /&gt;
&lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
 SELECT path&lt;br /&gt;
 FROM (&lt;br /&gt;
   SELECT grantee,&lt;br /&gt;
          sys_connect_by_path(privilege, &amp;#039;:&amp;#039;)||&amp;#039;:&amp;#039;||grantee path&lt;br /&gt;
   FROM (&lt;br /&gt;
     SELECT grantee, privilege, 0 role&lt;br /&gt;
     FROM dba_sys_privs&lt;br /&gt;
     UNION ALL&lt;br /&gt;
     SELECT grantee, granted_role, 1 role&lt;br /&gt;
     FROM dba_role_privs)&lt;br /&gt;
   CONNECT BY privilege=prior grantee&lt;br /&gt;
   START WITH role = 0)&lt;br /&gt;
 WHERE grantee IN (&lt;br /&gt;
    SELECT username&lt;br /&gt;
    FROM dba_users&lt;br /&gt;
    WHERE lock_date IS NULL&lt;br /&gt;
    AND password != &amp;#039;EXTERNAL&amp;#039;&lt;br /&gt;
    AND username != &amp;#039;SYS&amp;#039;)&lt;br /&gt;
 OR grantee=&amp;#039;PUBLIC&amp;#039;&lt;br /&gt;
&lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
for a migration from 10g...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set headi off&lt;br /&gt;
set feedb off&lt;br /&gt;
set long  9999999&lt;br /&gt;
set pages 0&lt;br /&gt;
set lines 300&lt;br /&gt;
&lt;br /&gt;
spool migration_create_target_users_grants.sql&lt;br /&gt;
&lt;br /&gt;
select dbms_metadata.get_ddl(&amp;#039;USER&amp;#039;, username) || &amp;#039;;&amp;#039; ddl&lt;br /&gt;
from dba_users&lt;br /&gt;
where  1=1&lt;br /&gt;
and    username like upper(&amp;#039;%&amp;amp;&amp;amp;USER_NAME%&amp;#039;)&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
select &amp;#039;grant &amp;#039;||privilege|| &amp;#039; to &amp;#039; || grantee || &amp;#039;;&amp;#039;&lt;br /&gt;
from   dba_sys_privs&lt;br /&gt;
where  1=1&lt;br /&gt;
and    grantee like upper(&amp;#039;%&amp;amp;&amp;amp;USER_NAME%&amp;#039;)&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
select &amp;#039;grant &amp;#039;||granted_role|| &amp;#039; to &amp;#039; || grantee || &amp;#039;;&amp;#039;&lt;br /&gt;
from   dba_role_privs&lt;br /&gt;
where  1=1&lt;br /&gt;
and    grantee like upper(&amp;#039;%&amp;amp;&amp;amp;USER_NAME%&amp;#039;)&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
spool off&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or for a migration on 11g...!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set head off&lt;br /&gt;
set pages 0&lt;br /&gt;
set long 9999999&lt;br /&gt;
col ddl for a1000&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
SELECT DBMS_METADATA.GET_DDL(&amp;#039;USER&amp;#039;, USERNAME) || &amp;#039;;&amp;#039; DDL&lt;br /&gt;
FROM DBA_USERS&lt;br /&gt;
where  1=1&lt;br /&gt;
and    default_tablespace not in (&amp;#039;SYSTEM&amp;#039;,&amp;#039;SYSAUX&amp;#039;)&lt;br /&gt;
and    upper(username) like &amp;#039;%&amp;#039;||upper(&amp;#039;&amp;amp;&amp;amp;username&amp;#039;)||&amp;#039;%&amp;#039;&lt;br /&gt;
UNION ALL&lt;br /&gt;
SELECT DBMS_METADATA.GET_GRANTED_DDL(&amp;#039;ROLE_GRANT&amp;#039;, USERNAME) || &amp;#039;;&amp;#039; DDL&lt;br /&gt;
FROM DBA_USERS&lt;br /&gt;
where  1=1&lt;br /&gt;
and    default_tablespace not in (&amp;#039;SYSTEM&amp;#039;,&amp;#039;SYSAUX&amp;#039;)&lt;br /&gt;
and    upper(username) like &amp;#039;%&amp;#039;||upper(&amp;#039;&amp;amp;&amp;amp;username&amp;#039;)||&amp;#039;%&amp;#039;&lt;br /&gt;
UNION ALL&lt;br /&gt;
SELECT DBMS_METADATA.GET_GRANTED_DDL(&amp;#039;SYSTEM_GRANT&amp;#039;, USERNAME) || &amp;#039;;&amp;#039; DDL&lt;br /&gt;
FROM DBA_USERS&lt;br /&gt;
where  1=1&lt;br /&gt;
and    default_tablespace not in (&amp;#039;SYSTEM&amp;#039;,&amp;#039;SYSAUX&amp;#039;)&lt;br /&gt;
and    upper(username) like &amp;#039;%&amp;#039;||upper(&amp;#039;&amp;amp;&amp;amp;username&amp;#039;)||&amp;#039;%&amp;#039;&lt;br /&gt;
UNION ALL&lt;br /&gt;
SELECT DBMS_METADATA.GET_GRANTED_DDL(&amp;#039;OBJECT_GRANT&amp;#039;, USERNAME) || &amp;#039;;&amp;#039; DDL&lt;br /&gt;
FROM DBA_USERS&lt;br /&gt;
where  1=1&lt;br /&gt;
and    default_tablespace not in (&amp;#039;SYSTEM&amp;#039;,&amp;#039;SYSAUX&amp;#039;)&lt;br /&gt;
and    upper(username) like &amp;#039;%&amp;#039;||upper(&amp;#039;&amp;amp;&amp;amp;username&amp;#039;)||&amp;#039;%&amp;#039;&lt;br /&gt;
&lt;br /&gt;
spool migration_create_users_grants.sql&lt;br /&gt;
/&lt;br /&gt;
spool off&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Move datafiles between filesystems===&lt;br /&gt;
* [https://blogs.oracle.com/alejandrovargas/moving-a-datafile-from-file-system-to-asm Moving a datafile from File System to ASM (does not have to be ASM!) - oracle.com]&lt;br /&gt;
* [https://docs.oracle.com/database/121/OSTMG/GUID-3B8D0956-0888-452D-A9E4-9FB8D98577E0.htm#OSTMG89997 Moving Data Files Between Oracle ASM (does not have to be ASM!) Using RMAN - oracle.com]&lt;br /&gt;
* [https://oracle-base.com/articles/misc/renaming-or-moving-oracle-files Moving a data file online between filesystems - oracle-base.com]&lt;br /&gt;
====Set the relevant datafile offline====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter database datafile 125 offline;&lt;br /&gt;
alter database datafile 126 offline;&lt;br /&gt;
alter database datafile 127 offline;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Rename the files on the filesystem using o/s commands====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter tablespace ts_thaler_data_offline;&lt;br /&gt;
&lt;br /&gt;
host mv &amp;#039;/cln/tst/ora_data1/clnt/data4/ts_thaler_data_113.dbf&amp;#039; &amp;#039;/cln/tst/ora_data1/clnt/data1/ts_thaler_data_113.dbf&amp;#039;&lt;br /&gt;
host mv &amp;#039;/cln/tst/ora_data1/clnt/data4/ts_thaler_data_114.dbf&amp;#039; &amp;#039;/cln/tst/ora_data1/clnt/data1/ts_thaler_data_114.dbf&amp;#039;&lt;br /&gt;
host mv &amp;#039;/cln/tst/ora_data1/clnt/data4/ts_thaler_data_115.dbf&amp;#039; &amp;#039;/cln/tst/ora_data1/clnt/data1/ts_thaler_data_115.dbf&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Run the relevant alter commands to inform the control files of the new locations====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter database move datafile &amp;#039;/cln/tst/ora_data1/clnt/data4/ts_thaler_data_113.dbf&amp;#039; to &amp;#039;/cln/tst/ora_data1/clnt/data1/ts_thaler_data_113.dbf&amp;#039;&lt;br /&gt;
alter database move datafile &amp;#039;/cln/tst/ora_data1/clnt/data4/ts_thaler_data_114.dbf&amp;#039; to &amp;#039;/cln/tst/ora_data1/clnt/data1/ts_thaler_data_114.dbf&amp;#039;&lt;br /&gt;
alter database move datafile &amp;#039;/cln/tst/ora_data1/clnt/data4/ts_thaler_data_115.dbf&amp;#039; to &amp;#039;/cln/tst/ora_data1/clnt/data1/ts_thaler_data_115.dbf&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Recover the datafiles====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
recover datafile 125;&lt;br /&gt;
recover datafile 126;&lt;br /&gt;
recover datafile 127;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Set the relevant datafile online====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter database datafile 125 online;&lt;br /&gt;
alter database datafile 126 online;&lt;br /&gt;
alter database datafile 127 online;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Check all is well with the datafiles by using an appropriate statement====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 2000 pages 100&lt;br /&gt;
select file_id, file_name, status, online_status from dba_data_files where tablespace_name = &amp;#039;TS_THALER_DATA&amp;#039; order by 2;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Rename a datafile on 12c====&lt;br /&gt;
If you&amp;#039;re lucky enough to be on 12c, it&amp;#039;s one command - no need to offline the datafile!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SQL&amp;gt; alter database move datafile &amp;#039;/oracle/ora_data2/prod/data4/ts_thaler_data_113.dbf&amp;#039; to &amp;#039;/oracle/ora_data2/prod/data3/ts_thaler_data_113.dbf&amp;#039;;&lt;br /&gt;
&lt;br /&gt;
Database altered.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Pass parameter/argument into perl one-liner script from shell===&lt;br /&gt;
Trick? Just use ARGV to pass them in...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
FREQ=$(perl -e &amp;#039;my @CAL=split(&amp;quot;;&amp;quot;,$ARGV[0]);shift @CAL;print $CAL[$ARGV[1]];&amp;#039; -- &amp;quot;$LINE&amp;quot; $offset)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
DUMP_DATE=`perl -MTime::Local -e &amp;#039;print(timelocal(0,$ARGV[0],$ARGV[1],$ARGV[2],$ARGV[3],$ARGV[4]))&amp;#039; -- $MI $HH $DD $MM $YYYY`&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or export the variable from shell and access it via the ENV hash&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
export db=ENDP1&lt;br /&gt;
perl -p -i -e &amp;#039;s!DSMI_LOG.+$!DSMI_LOG           /oracle/$ENV{db}/admin/tdpoerror_$ENV{db}!&amp;#039; ${db}/admin/tdpo.opt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Return epoch seconds in Perl===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
perl -e &amp;#039;print time();&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or to convert a specific day of the year to epoch seconds&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
use POSIX;&lt;br /&gt;
my $epochsecs = mktime(0,0,0, $jday, 0, $year-1900);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or for a specific date (careful though - month is 0-11 not 1-12!...&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
use Time::Local;&lt;br /&gt;
#                          SS MM HH DD MM YYYY&lt;br /&gt;
my $epochsecs = timelocal (30,10,19,03,04,2014);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or more long-winded but delimited by anything...&amp;lt;br /&amp;gt;&lt;br /&gt;
Supply the date/time in any delimited format. Eg. YYYY-MM-DD:HH:MI&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/usr/bin/perl -w&lt;br /&gt;
use Time::Local;&lt;br /&gt;
&lt;br /&gt;
sub date2epoch { &lt;br /&gt;
  my($s) = @_;&lt;br /&gt;
  my($year, $month, $day, $hour, $minute, $second);&lt;br /&gt;
&lt;br /&gt;
  if($s =~ m{^\s*(\d{1,4})\W*0*(\d{1,2})\W*0*(\d{1,2})\W*0*&lt;br /&gt;
                 (\d{0,2})\W*0*(\d{0,2})\W*0*(\d{0,2})}x) {&lt;br /&gt;
    $year = $1;  $month = $2;   $day = $3;&lt;br /&gt;
    $hour = $4;  $minute = $5;  $second = $6;&lt;br /&gt;
    $hour |= 0;  $minute |= 0;  $second |= 0;  # defaults.&lt;br /&gt;
    $year = ($year&amp;lt;100 ? ($year&amp;lt;70 ? 2000+$year : 1900+$year) : $year);&lt;br /&gt;
    return timelocal($second,$minute,$hour,$day,$month-1,$year);  &lt;br /&gt;
  }&lt;br /&gt;
  return -1;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Return epoch seconds in DOS/VBS/Windows===&lt;br /&gt;
Paste this code into epoch.vbs&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
function date2epoch(p_date)&lt;br /&gt;
    date2epoch = DateDiff(&amp;quot;s&amp;quot;, &amp;quot;01/01/1970 00:00:00&amp;quot;, p_date)&lt;br /&gt;
end function&lt;br /&gt;
&lt;br /&gt;
Wscript.Echo date2epoch(Now())&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
and call from a DOS box like this&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cscript //nologo epoch.vbs&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Return date from epoch seconds in Perl===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
perl -e &amp;#039;print scalar (localtime (1243269270))&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Return epoch seconds from julian day number in Perl===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
use POSIX;&lt;br /&gt;
my ($year, $jday) = (2012,60);&lt;br /&gt;
my $epochsecs = mktime(0,0,0, $jday, 0, $year-1900);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Extract specific pieces of a date from an epoch timestamp in Perl===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
use POSIX;&lt;br /&gt;
# return localtime into an array&lt;br /&gt;
my @tm = localtime $epochsecs;&lt;br /&gt;
&lt;br /&gt;
my $yyyymmdd = strftime &amp;quot;%Y%m%d&amp;quot;, @tm;&lt;br /&gt;
print $yyyymmdd.&amp;quot;\n&amp;quot;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Return epoch seconds in Shell (linux)===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
date -d &amp;quot;2014/04/03 18:34:30&amp;quot; &amp;quot;+%s&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Return date from epoch seconds in Shell (linux)===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
date -d @1396542870&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Return epoch seconds in PL/SQL===&lt;br /&gt;
You cannot just use sysdate as that is timezone sensitive... (epoch seconds are in UTC/GMT)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select round((cast(sys_extract_utc(systimestamp) as date) - to_date(&amp;#039;01-JAN-1970 00:00:00&amp;#039;,&amp;#039;DD-MON-YYYY HH24:MI:SS&amp;#039;))*24*60*60) from dual;&lt;br /&gt;
or&lt;br /&gt;
select round((vd.created - to_date(&amp;#039;01-JAN-1970 00:00:00&amp;#039;,&amp;#039;DD-MON-YYYY HH24:MI:SS&amp;#039;))*24*60*60)  created from v$database vd;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
How long has this instance been up (in minutes)?&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select round((cast(sys_extract_utc(systimestamp) as date) - startup_time)*24*60) up_mins from v$instance;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Return date from epoch seconds in SQL===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select to_char(to_date(&amp;#039;19700101&amp;#039;,&amp;#039;YYYYMMDD&amp;#039;) + ((&amp;amp;epoch)/24/60/60),&amp;#039;DD-MON-YYYY HH24:MI:SS&amp;#039;) utc_date from dual;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===A database overview using the sys.plato package===&lt;br /&gt;
 exec plato.help;&lt;br /&gt;
or&lt;br /&gt;
 exec plato.complete(&amp;#039;HTM&amp;#039;);&lt;br /&gt;
&lt;br /&gt;
===List datafiles for a tablespace===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select *&lt;br /&gt;
from   dba_data_files&lt;br /&gt;
where  1=1&lt;br /&gt;
and    tablespace_name =&amp;#039;&amp;amp;ts_name&amp;#039;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Show graph of available and free space in tablespaces===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
-- =============================================================================&lt;br /&gt;
-- File Name    : http://www.oracle-base.com/dba/monitoring/ts_free_space.sql&lt;br /&gt;
-- Author       : Tim Hall&lt;br /&gt;
-- Description  : Displays a list of tablespaces and their used/full status.&lt;br /&gt;
-- Requirements : Access to the DBA views.&lt;br /&gt;
-- Call Syntax  : @ts_free_space.sql&lt;br /&gt;
-- Last Modified: 13-OCT-2012 - Created. Based on ts_full.sql&lt;br /&gt;
--&lt;br /&gt;
-- Modification History&lt;br /&gt;
-- ====================&lt;br /&gt;
-- When      Who               What&lt;br /&gt;
-- ========= ================= =================================================&lt;br /&gt;
-- 13-NOV-13 Stuart Barkley    Added cols free_pct and used_pct&lt;br /&gt;
-- =============================================================================&lt;br /&gt;
SET PAGESIZE 140 lines 180&lt;br /&gt;
COLUMN used_pct FORMAT A11&lt;br /&gt;
COLUMN max_used_pct FORMAT A11&lt;br /&gt;
&lt;br /&gt;
    SELECT tablespace_name                                                                      tablespace_name&lt;br /&gt;
    ,      size_mb                                                                              size_mb&lt;br /&gt;
    ,      free_mb                                                                              free_mb&lt;br /&gt;
    ,      TRUNC((free_mb/size_mb) * 100)                                                       free_pct&lt;br /&gt;
    ,      RPAD(&amp;#039; &amp;#039;|| RPAD(&amp;#039;X&amp;#039;,ROUND((size_mb-free_mb)/size_mb*10,0), &amp;#039;X&amp;#039;),11,&amp;#039;-&amp;#039;)              used_pct&lt;br /&gt;
    ,      max_size_mb                                                                          max_size_mb&lt;br /&gt;
    ,      max_free_mb                                                                          max_free_mb&lt;br /&gt;
    ,      TRUNC((max_free_mb/max_size_mb) * 100)                                               max_free_pct&lt;br /&gt;
    ,      RPAD(&amp;#039; &amp;#039;|| RPAD(&amp;#039;X&amp;#039;,ROUND((max_size_mb-max_free_mb)/max_size_mb*10,0), &amp;#039;X&amp;#039;),11,&amp;#039;-&amp;#039;)  max_used_pct&lt;br /&gt;
    from   (&lt;br /&gt;
           select a.tablespace_name                                         tablespace_name&lt;br /&gt;
           ,      b.size_mb                                                 size_mb&lt;br /&gt;
           ,      a.free_mb                                                 free_mb&lt;br /&gt;
           ,      b.max_size_mb                                             max_size_mb&lt;br /&gt;
           ,      a.free_mb + (b.max_size_mb - b.size_mb)                   max_free_mb&lt;br /&gt;
           from   (&lt;br /&gt;
                  select tablespace_name                                    tablespace_name&lt;br /&gt;
                  ,      trunc(sum(bytes)/1024/1024)                        free_mb&lt;br /&gt;
                  from   dba_free_space&lt;br /&gt;
                  group  by tablespace_name&lt;br /&gt;
                  ) a&lt;br /&gt;
           ,      (&lt;br /&gt;
                  select tablespace_name                                    tablespace_name&lt;br /&gt;
                  ,        trunc(sum(bytes)/1024/1024)                      size_mb&lt;br /&gt;
                  ,        trunc(sum(greatest(bytes,maxbytes))/1024/1024)   max_size_mb&lt;br /&gt;
                  from   dba_data_files&lt;br /&gt;
                  group by tablespace_name&lt;br /&gt;
                  ) b&lt;br /&gt;
           ,      v$instance vi&lt;br /&gt;
           where  a.tablespace_name = b.tablespace_name&lt;br /&gt;
           )&lt;br /&gt;
    order  by tablespace_name;&lt;br /&gt;
&lt;br /&gt;
set lines 80&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Another method for calculating free space in tablespace  using segments===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select df.tablespace_name &amp;quot;Tablespace&amp;quot;&lt;br /&gt;
,      totalusedspace &amp;quot;Used MB&amp;quot;&lt;br /&gt;
,      (df.totalspace - tu.totalusedspace) &amp;quot;Free MB&amp;quot;&lt;br /&gt;
,      df.totalspace &amp;quot;Total MB&amp;quot;&lt;br /&gt;
,      round(100 * ( (df.totalspace - tu.totalusedspace)/ df.totalspace)) &amp;quot;Pct. Free&amp;quot;&lt;br /&gt;
from   (&lt;br /&gt;
       select tablespace_name&lt;br /&gt;
,      round(sum(bytes) / 1048576) totalspace&lt;br /&gt;
       from   dba_data_files&lt;br /&gt;
       group  by tablespace_name&lt;br /&gt;
       ) df&lt;br /&gt;
,      (&lt;br /&gt;
       select round(sum(bytes)/(1024*1024)) totalusedspace&lt;br /&gt;
       ,      tablespace_name&lt;br /&gt;
       from   dba_segments&lt;br /&gt;
       group  by tablespace_name&lt;br /&gt;
       ) tu&lt;br /&gt;
where  df.tablespace_name = tu.tablespace_name;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Work out maximum possible size of a datafile===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select round( (4*1024*1024*value) / (1024*1024*1024) ,2) maxfilesizeingigabytes from v$parameter where name=&amp;#039;db_block_size&amp;#039;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or, as tablespaces can have block sizes differing from that of the init.ora parameter...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select round( (4*1024*1024*block_size) / (1024*1024*1024) ,2) maxfilesizeingigabytes from dba_tablespaces where tablespace_name=&amp;#039;&amp;amp;tablespace_name&amp;#039;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Show size and maxsize at datafile level===&lt;br /&gt;
datafiles&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set pages 100 lines 200&lt;br /&gt;
col file_name for a60&lt;br /&gt;
select sum(bytes)/1024/1024      mbytes_alloc&lt;br /&gt;
,      sum(maxbytes)/1024/1024   mbytes_max&lt;br /&gt;
,      file_name&lt;br /&gt;
from   sys.dba_data_files&lt;br /&gt;
group  by file_name&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
tempfiles&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set pages 100 lines 200&lt;br /&gt;
col file_name for a60&lt;br /&gt;
select sum(bytes)/1024/1024      mbytes_alloc&lt;br /&gt;
,      sum(maxbytes)/1024/1024   mbytes_max&lt;br /&gt;
,      file_name&lt;br /&gt;
from   sys.dba_temp_files&lt;br /&gt;
group  by file_name&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Resize the online redo logfiles===&lt;br /&gt;
Found a more concise, smarter way of doing it [http://www.oracle-wiki.net/startdocshowtorecreateredogrps here] - oracle-wiki.net&amp;lt;br /&amp;gt;&lt;br /&gt;
Switching logs too often? Redolog files too small?&amp;lt;br /&amp;gt;&lt;br /&gt;
* Show current log groups&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 1000&lt;br /&gt;
col group_member for a60&lt;br /&gt;
select l.group#          group_number&lt;br /&gt;
,      (bytes/1024/1024) megs&lt;br /&gt;
,      l.status          group_status&lt;br /&gt;
,      f.member          group_member&lt;br /&gt;
,      l.archived        archived&lt;br /&gt;
,      f.type            file_type&lt;br /&gt;
from   v$log     l&lt;br /&gt;
,      v$logfile f&lt;br /&gt;
where  l.group# = f.group#&lt;br /&gt;
order  by l.group#&lt;br /&gt;
,      f.member&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Create additional (bigger) groups&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
define SID=TIBQFW&lt;br /&gt;
alter database add logfile group 6  &amp;#039;/oracle/&amp;amp;SID/oradata1/redo1.log&amp;#039; size 1G;&lt;br /&gt;
alter database add logfile group 7  &amp;#039;/oracle/&amp;amp;SID/oradata2/redo2.log&amp;#039; size 1G;&lt;br /&gt;
alter database add logfile group 8  &amp;#039;/oracle/&amp;amp;SID/oradata3/redo3.log&amp;#039; size 1G;&lt;br /&gt;
alter database add logfile group 9  &amp;#039;/oracle/&amp;amp;SID/oradata1/redo4.log&amp;#039; size 1G;&lt;br /&gt;
alter database add logfile group 10 &amp;#039;/oracle/&amp;amp;SID/oradata2/redo5.log&amp;#039; size 1G;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or if you use multiple members...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter database add logfile group 6 (&amp;#039;/oracle/&amp;amp;SID/oradata1/redo/redo01a.log&amp;#039;, &amp;#039;/oracle/&amp;amp;SID/oradata1/redo01b&amp;#039;) size 50M;&lt;br /&gt;
alter database add logfile group 7 (&amp;#039;/oracle/&amp;amp;SID/oradata1/redo/redo02a.log&amp;#039;, &amp;#039;/oracle/&amp;amp;SID/oradata1/redo02b&amp;#039;) size 50M;&lt;br /&gt;
alter database add logfile group 8 (&amp;#039;/oracle/&amp;amp;SID/oradata1/redo/redo03a.log&amp;#039;, &amp;#039;/oracle/&amp;amp;SID/oradata1/redo03b&amp;#039;) size 50M;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Switch archivelogs until the new ones are current and the old ones are inactive&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter system switch logfile;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
If the old logs are not yet inactive, checkpoint the database&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter system checkpoint;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Drop the old groups&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter database drop logfile group 1;&lt;br /&gt;
alter database drop logfile group 2;&lt;br /&gt;
alter database drop logfile group 3;&lt;br /&gt;
alter database drop logfile group 4;&lt;br /&gt;
alter database drop logfile group 5;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Increase the existing size of a datafile===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter database datafile &amp;#039;&amp;amp;full_path_of_datafile&amp;#039; resize &amp;amp;new_meg_size.M;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Increase the max size of a tempfile===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter database tempfile &amp;#039;/oracle/ENDP1/oradata90/temp01.dbf&amp;#039; autoextend on maxsize unlimited;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Find out what processes are using the temp tablespace===&lt;br /&gt;
Temporary tablespace is used for sorting query results. Find them with this.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SELECT b.tablespace,b.segfile#,b.segblk#,b.blocks,a.sid,a.serial#,&lt;br /&gt;
a.username,a.osuser, a.status&lt;br /&gt;
FROM v$session a,v$sort_usage b&lt;br /&gt;
WHERE a.saddr = b.session_addr;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Increase the maximum size of a datafile===&lt;br /&gt;
Although this can be set lower than existing size, try not to. It makes the reports look weird!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter database&lt;br /&gt;
      datafile &amp;#039;&amp;amp;full_path_of_datafile&amp;#039;&lt;br /&gt;
      autoextend on&lt;br /&gt;
      maxsize &amp;amp;new_meg_size.m;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Find schemas (users) with objects created outside their default tablespace===&lt;br /&gt;
Indexes could be a notable exception if they are created in an index tablespace&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 200&lt;br /&gt;
col owner           for a20&lt;br /&gt;
col segment_name    for a45&lt;br /&gt;
col tablespace_name for a32&lt;br /&gt;
select owner&lt;br /&gt;
,      segment_name&lt;br /&gt;
,      tablespace_name&lt;br /&gt;
from   dba_segments&lt;br /&gt;
where  exists (select username from dba_users where username = owner)&lt;br /&gt;
and    tablespace_name != (select default_tablespace from dba_users where username = owner)&lt;br /&gt;
and    owner = &amp;#039;&amp;amp;owner&amp;#039;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Add a datafile to a tablespace===&lt;br /&gt;
&amp;#039;unlimited&amp;#039; will default to the maximum datafile size for the current db_block_size&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter tablepace &amp;amp;tablespace_name&lt;br /&gt;
      add datafile &amp;#039;&amp;amp;full_path_of_datafile&amp;#039;&lt;br /&gt;
      size 100M&lt;br /&gt;
      autoextend on&lt;br /&gt;
      next 100M&lt;br /&gt;
      maxsize unlimited&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===List all datafiles with their size===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set pages 1000 lines 2000&lt;br /&gt;
col filetype for a15&lt;br /&gt;
col name for a60&lt;br /&gt;
break on report&lt;br /&gt;
compute sum of gig on report&lt;br /&gt;
&lt;br /&gt;
select filetype&lt;br /&gt;
,      name&lt;br /&gt;
,      gig&lt;br /&gt;
from   (&lt;br /&gt;
       select &amp;#039;datafile&amp;#039; filetype&lt;br /&gt;
       ,      name&lt;br /&gt;
       ,      bytes/1024/1024 gig&lt;br /&gt;
       from   v$datafile&lt;br /&gt;
       union all&lt;br /&gt;
       select &amp;#039;tempfile&amp;#039; filetype&lt;br /&gt;
       ,      name&lt;br /&gt;
       ,      bytes/1024/1024&lt;br /&gt;
       from   v$tempfile&lt;br /&gt;
       union all&lt;br /&gt;
       select &amp;#039;logfile&amp;#039; filetype&lt;br /&gt;
       ,      lf.member &amp;quot;name&amp;quot;&lt;br /&gt;
       ,      l.bytes/1024/1024&lt;br /&gt;
       from   v$logfile lf&lt;br /&gt;
       ,      v$log     l&lt;br /&gt;
       where  1=1&lt;br /&gt;
       and    lf.group# = l.group#&lt;br /&gt;
       ) used&lt;br /&gt;
,      (&lt;br /&gt;
       select sum(bytes)/1024/1024&lt;br /&gt;
       from   dba_free_space&lt;br /&gt;
       ) free&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Database size (How big is my database?)===&lt;br /&gt;
There are different interpretations of what constitutes the size of a database...&amp;lt;br /&amp;gt;&lt;br /&gt;
Is it the space allocated to the datafiles or only the space taken up by the data? Are tempfiles included? Are redo logs included? etc...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 132&lt;br /&gt;
col dbname for a9  heading &amp;quot;Database&amp;quot;&lt;br /&gt;
col dbsize for a15 heading &amp;quot;Size&amp;quot;&lt;br /&gt;
col dbused for a15 heading &amp;quot;Used space&amp;quot;&lt;br /&gt;
col dbfree for a15 heading &amp;quot;Free space&amp;quot;&lt;br /&gt;
with used_space as&lt;br /&gt;
(&lt;br /&gt;
select  bytes&lt;br /&gt;
from    v$datafile&lt;br /&gt;
union   all&lt;br /&gt;
select  bytes&lt;br /&gt;
from    v$tempfile&lt;br /&gt;
union   all&lt;br /&gt;
select  bytes&lt;br /&gt;
from    v$log&lt;br /&gt;
)&lt;br /&gt;
, free_space as&lt;br /&gt;
(&lt;br /&gt;
select sum(bytes) sum_bytes&lt;br /&gt;
from dba_free_space&lt;br /&gt;
)&lt;br /&gt;
select vd.name                                                                                            dbname&lt;br /&gt;
,      round(sum(used_space.bytes)/1024/1024/1024 ) || &amp;#039; GB&amp;#039;                                              dbsize&lt;br /&gt;
,      round(sum(used_space.bytes)/1024/1024/1024 ) - round(free_space.sum_bytes/1024/1024/1024) || &amp;#039; GB&amp;#039; dbused&lt;br /&gt;
,      round(free_space.sum_bytes/1024/1024/1024) || &amp;#039; GB&amp;#039;                                                dbfree&lt;br /&gt;
from   free_space&lt;br /&gt;
,      used_space&lt;br /&gt;
,      v$database vd&lt;br /&gt;
group  by vd.name&lt;br /&gt;
,      free_space.sum_bytes&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Drop datafile from temp tablespace===&lt;br /&gt;
Database is completely stuck because the temporary tablespace has grown to fill all available room.&amp;lt;br /&amp;gt;&lt;br /&gt;
Look around for at least some log files to delete in order to get connected (audit files, sqlnet logs, listener logs)&amp;lt;br /&amp;gt;&lt;br /&gt;
Once connected, change the default temporary tablespace to a small one so we can remove the original.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
create temporary tablespace temp2 tempfile &amp;#039;/oracle/RMANV12/oradata2/temp2.dbf&amp;#039; size 5M;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter database default temporary tablespace temp2;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
I found trying to drop the datafile like this didn&amp;#039;t work, just hung there (probably active tranactions)...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
drop tablespace temp including contents and datafiles;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
So did it like this...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter database tempfile &amp;#039;/oracle/RMANV12/oradata2/temp.dbf&amp;#039; drop including datafiles;&lt;br /&gt;
&lt;br /&gt;
Database altered.&lt;br /&gt;
&lt;br /&gt;
drop tablespace temp including contents and datafiles;&lt;br /&gt;
&lt;br /&gt;
Tablespace dropped.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
... an alternative would be to find the sessions using the temp space and kill them...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select sid, serial#, status from v$session where serial# in (select session_num from v$sort_usage);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Then to be neat and tidy, rename the temp2 tablespace back to temp.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
create temporary tablespace temp tempfile &amp;#039;/oracle/RMANV12/oradata2/temp.dbf&amp;#039; size 256M reuse autoextend on next 128M maxsize 1G;&lt;br /&gt;
alter database default temporary tablespace temp;&lt;br /&gt;
drop tablespace temp2 including contents and datafiles;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Although the last statement will not work until any transactions using it have been rolled back or committed.&lt;br /&gt;
&lt;br /&gt;
===List files that are in hot-backup mode===&lt;br /&gt;
 set lines 100&lt;br /&gt;
 set pages 100&lt;br /&gt;
 col name format a60&lt;br /&gt;
 &lt;br /&gt;
 select df.name&lt;br /&gt;
 ,      b.status&lt;br /&gt;
 ,      to_char(time, &amp;#039;hh24:mi:ss dd/mm/yyyy&amp;#039;) time&lt;br /&gt;
 from   v$datafile   df&lt;br /&gt;
 ,      v$backup     b&lt;br /&gt;
 where  1=1&lt;br /&gt;
 and    df.file# = b.file#&lt;br /&gt;
 and    b.status = &amp;#039;ACTIVE&amp;#039;&lt;br /&gt;
 order  by b.file#;&lt;br /&gt;
&lt;br /&gt;
===Waiting for snapshot control file enqueue===&lt;br /&gt;
Script to identify sessions causing RMAN to hang because of &amp;#039;waiting for snapshot control file enqueue&amp;#039; message&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 2000&lt;br /&gt;
col killer     for a70&lt;br /&gt;
col program    for a20&lt;br /&gt;
col module     for a20&lt;br /&gt;
col action     for a20&lt;br /&gt;
col logon_time for a20&lt;br /&gt;
&lt;br /&gt;
select &amp;#039;alter system disconnect session &amp;#039;&amp;#039;&amp;#039;||s.sid||&amp;#039;,&amp;#039;||s.serial#||&amp;#039;&amp;#039;&amp;#039; immediate;&amp;#039; killer&lt;br /&gt;
,      username&lt;br /&gt;
,      program&lt;br /&gt;
,      module&lt;br /&gt;
,      action&lt;br /&gt;
,      logon_time&lt;br /&gt;
from   v$session s&lt;br /&gt;
,      v$enqueue_lock l&lt;br /&gt;
where  l.sid  = s.sid&lt;br /&gt;
and    l.type = &amp;#039;CF&amp;#039;&lt;br /&gt;
and    l.id1  = 0&lt;br /&gt;
and    l.id2  = 2&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Info on blocking processes===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select s1.username || &amp;#039;@&amp;#039; || s1.machine&lt;br /&gt;
       || &amp;#039; ( SID=&amp;#039; || s1.sid || &amp;#039; )  is blocking &amp;#039;&lt;br /&gt;
       || s2.username || &amp;#039;@&amp;#039; || s2.machine || &amp;#039; ( SID=&amp;#039; || s2.sid || &amp;#039; ) &amp;#039;  blocking_status&lt;br /&gt;
from   v$lock l1&lt;br /&gt;
,      v$session s1&lt;br /&gt;
,      v$lock l2&lt;br /&gt;
,      v$session s2&lt;br /&gt;
where  s1.sid     = l1.sid&lt;br /&gt;
and    s2.sid     = l2.sid&lt;br /&gt;
and    l1.block   = 1&lt;br /&gt;
and    l2.request &amp;gt; 0&lt;br /&gt;
and    l1.id1     = l2.id1&lt;br /&gt;
and    l2.id2     = l2.id2&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
session doing the blocking&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select *&lt;br /&gt;
from  v$lock l1&lt;br /&gt;
where 1=1&lt;br /&gt;
and   block = 1 ;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
sessions being blocked&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select *&lt;br /&gt;
from   v$lock l1&lt;br /&gt;
where  1=1&lt;br /&gt;
and    id2 = 85203&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
info on session doing the blocking&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select row_wait_obj#, row_wait_file#, row_wait_block#, row_wait_row#&lt;br /&gt;
from   v$session&lt;br /&gt;
where  sid = 234&lt;br /&gt;
&lt;br /&gt;
select do.object_name&lt;br /&gt;
,      row_wait_obj#&lt;br /&gt;
,      row_wait_file#&lt;br /&gt;
,      row_wait_block#&lt;br /&gt;
,      row_wait_row#&lt;br /&gt;
,      dbms_rowid.rowid_create ( 1, ROW_WAIT_OBJ#, ROW_WAIT_FILE#, ROW_WAIT_BLOCK#, ROW_WAIT_ROW# ) row_id&lt;br /&gt;
from   v$session   s&lt;br /&gt;
,      dba_objects do&lt;br /&gt;
where  sid=234&lt;br /&gt;
and    s.ROW_WAIT_OBJ# = do.OBJECT_ID;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Show locked objects===&lt;br /&gt;
 set lines 100&lt;br /&gt;
 set pages 999&lt;br /&gt;
 col username   format a20&lt;br /&gt;
 col sess_id    format a10&lt;br /&gt;
 col object     format a25&lt;br /&gt;
 col mode_held  format a10&lt;br /&gt;
 select oracle_username||&amp;#039; (&amp;#039;||s.osuser||&amp;#039;)&amp;#039; username&lt;br /&gt;
 ,      s.sid||&amp;#039;,&amp;#039;||s.serial# sess_id&lt;br /&gt;
 ,      owner||&amp;#039;.&amp;#039;||object_name object&lt;br /&gt;
 ,      object_type&lt;br /&gt;
 ,      decode ( l.block&lt;br /&gt;
               , 0, &amp;#039;Not Blocking&amp;#039;&lt;br /&gt;
               , 1, &amp;#039;Blocking&amp;#039;&lt;br /&gt;
               , 2, &amp;#039;Global&amp;#039;&lt;br /&gt;
               ) status&lt;br /&gt;
 ,      decode ( v.locked_mode&lt;br /&gt;
               , 0, &amp;#039;None&amp;#039;&lt;br /&gt;
               , 1, &amp;#039;Null&amp;#039;&lt;br /&gt;
               , 2, &amp;#039;Row-S (SS)&amp;#039;&lt;br /&gt;
               , 3, &amp;#039;Row-X (SX)&amp;#039;&lt;br /&gt;
               , 4, &amp;#039;Share&amp;#039;&lt;br /&gt;
               , 5, &amp;#039;S/Row-X (SSX)&amp;#039;&lt;br /&gt;
               , 6, &amp;#039;Exclusive&amp;#039;, TO_CHAR(lmode)&lt;br /&gt;
               ) mode_held&lt;br /&gt;
 from   v$locked_object v&lt;br /&gt;
 ,      dba_objects d&lt;br /&gt;
 ,      v$lock l&lt;br /&gt;
 ,      v$session s&lt;br /&gt;
 where  1=1&lt;br /&gt;
 and    v.object_id = d.object_id&lt;br /&gt;
 and    v.object_id = l.id1&lt;br /&gt;
 and    v.session_id = s.sid&lt;br /&gt;
 order  by oracle_username&lt;br /&gt;
 ,	session_id;&lt;br /&gt;
&lt;br /&gt;
===Show which row is locked===&lt;br /&gt;
 select do.object_name&lt;br /&gt;
 ,      row_wait_obj#&lt;br /&gt;
 ,      row_wait_file#&lt;br /&gt;
 ,      row_wait_block#&lt;br /&gt;
 ,      row_wait_row#&lt;br /&gt;
 ,      dbms_rowid.rowid_create (1, ROW_WAIT_OBJ#, ROW_WAIT_FILE#, ROW_WAIT_BLOCK#, ROW_WAIT_ROW#)&lt;br /&gt;
 from   v$session   s&lt;br /&gt;
 ,      dba_objects do&lt;br /&gt;
 where  1=1&lt;br /&gt;
 and    s.ROW_WAIT_OBJ# = do.OBJECT_ID&lt;br /&gt;
 and    sid             = &amp;amp;sid;&lt;br /&gt;
&lt;br /&gt;
===Check what is audited on a database===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set pagesize 100&lt;br /&gt;
set linesize 256&lt;br /&gt;
select audit_option,success,failure from dba_stmt_audit_opts;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===How old is the oldest audit record?===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select extract (day from (systimestamp - min(ntimestamp#))) days_old from aud$;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Check what objects are being audited===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
tti col 60 &amp;#039;Object Audit Options (dba_obj_audit_opts)&amp;#039; skip col 50 &amp;#039;A=By Access, S=By Session. Left=on success, right=on failure&amp;#039; skip 2&lt;br /&gt;
set lines 1000 pages 100&lt;br /&gt;
col alt for a3 head &amp;quot;Alt|er&amp;quot;&lt;br /&gt;
col aud for a3 head &amp;quot;Aud|it&amp;quot;&lt;br /&gt;
col com for a3 head &amp;quot;Com|ent&amp;quot;&lt;br /&gt;
col del for a3 head &amp;quot;Del|ete&amp;quot;&lt;br /&gt;
col gra for a3 head &amp;quot;Gra|nt&amp;quot;&lt;br /&gt;
col ind for a3 head &amp;quot;Ind|ex&amp;quot;&lt;br /&gt;
col ins for a3 head &amp;quot;Ins|ert&amp;quot;&lt;br /&gt;
col loc for a3 head &amp;quot;Lo|ck&amp;quot;&lt;br /&gt;
col ren for a3 head &amp;quot;Ren|ame&amp;quot;&lt;br /&gt;
col sel for a3 head &amp;quot;Sel|ect&amp;quot;&lt;br /&gt;
col upd for a3 head &amp;quot;Upd|ate&amp;quot;&lt;br /&gt;
col ref for a3 head &amp;quot;Ref|rnc&amp;quot;&lt;br /&gt;
col exe for a3 head &amp;quot;Exe|cut&amp;quot;&lt;br /&gt;
col cre for a3 head &amp;quot;Cre|ate&amp;quot;&lt;br /&gt;
col rea for a3 head &amp;quot;Re|ad&amp;quot;&lt;br /&gt;
col wri for a3 head &amp;quot;Wri|te&amp;quot;&lt;br /&gt;
col fbk for a3 head &amp;quot;Fla|sh&amp;quot;&lt;br /&gt;
	&lt;br /&gt;
select *&lt;br /&gt;
from   dba_obj_audit_opts&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Procedure to delete old audit records===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select text from all_source where lower(name)=&amp;#039;purge_audit_trail&amp;#039;;&lt;br /&gt;
&lt;br /&gt;
TEXT&lt;br /&gt;
------------------------------------------------------------------------------------------------&lt;br /&gt;
PROCEDURE purge_audit_trail IS&lt;br /&gt;
BEGIN&lt;br /&gt;
-- set the last archive timestamp&lt;br /&gt;
DBMS_AUDIT_MGMT.SET_LAST_ARCHIVE_TIMESTAMP(&lt;br /&gt;
       audit_trail_type    =&amp;gt; DBMS_AUDIT_MGMT.AUDIT_TRAIL_AUD_STD,&lt;br /&gt;
       last_archive_time   =&amp;gt; systimestamp - interval &amp;#039;365&amp;#039; day,&lt;br /&gt;
       rac_instance_number =&amp;gt; null&lt;br /&gt;
                                          );&lt;br /&gt;
-- purge audit trail till last archive timestamp&lt;br /&gt;
DBMS_AUDIT_MGMT.CLEAN_AUDIT_TRAIL( audit_trail_type =&amp;gt; DBMS_AUDIT_MGMT.AUDIT_TRAIL_AUD_STD&lt;br /&gt;
, use_last_arch_timestamp =&amp;gt; TRUE);&lt;br /&gt;
&lt;br /&gt;
END purge_audit_trail;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Job setup to run the audit purge===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
BEGIN&lt;br /&gt;
sys.dbms_scheduler.create_job(&lt;br /&gt;
    job_name =&amp;gt; &amp;#039;&amp;quot;SYS&amp;quot;.&amp;quot;PURGE_AUDIT_TRAIL_JOB&amp;quot;&amp;#039;,&lt;br /&gt;
    job_type =&amp;gt; &amp;#039;STORED_PROCEDURE&amp;#039;,&lt;br /&gt;
    job_action =&amp;gt; &amp;#039;&amp;quot;SYS&amp;quot;.&amp;quot;PURGE_AUDIT_TRAIL&amp;quot;&amp;#039;,&lt;br /&gt;
    repeat_interval =&amp;gt; &amp;#039;FREQ=DAILY;BYHOUR=20;BYMINUTE=0;BYSECOND=0&amp;#039;,&lt;br /&gt;
    start_date =&amp;gt; to_timestamp_tz(&amp;#039;2012-02-22 Europe/Paris&amp;#039;, &amp;#039;YYYY-MM-DD TZR&amp;#039;),&lt;br /&gt;
    job_class =&amp;gt; &amp;#039;&amp;quot;DEFAULT_JOB_CLASS&amp;quot;&amp;#039;,&lt;br /&gt;
    comments =&amp;gt; &amp;#039;purge audit trails until last archive timestamp&amp;#039;,&lt;br /&gt;
    auto_drop =&amp;gt; FALSE,&lt;br /&gt;
    enabled =&amp;gt; FALSE&lt;br /&gt;
);&lt;br /&gt;
sys.dbms_scheduler.set_attribute( name =&amp;gt; &amp;#039;&amp;quot;SYS&amp;quot;.&amp;quot;PURGE_AUDIT_TRAIL_JOB&amp;quot;&amp;#039;, attribute =&amp;gt; &amp;#039;logging_level&amp;#039;, value =&amp;gt; DBMS_SCHEDULER.LOGGING_OFF);&lt;br /&gt;
sys.dbms_scheduler.set_attribute( name =&amp;gt; &amp;#039;&amp;quot;SYS&amp;quot;.&amp;quot;PURGE_AUDIT_TRAIL_JOB&amp;quot;&amp;#039;, attribute =&amp;gt; &amp;#039;job_weight&amp;#039;, value =&amp;gt; 1);&lt;br /&gt;
sys.dbms_scheduler.enable( &amp;#039;&amp;quot;SYS&amp;quot;.&amp;quot;PURGE_AUDIT_TRAIL_JOB&amp;quot;&amp;#039; );&lt;br /&gt;
END;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===A list of all SIDs in oratab that should restart after a server boot===&lt;br /&gt;
Using awk&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
awk -F: &amp;#039;$NF==&amp;quot;Y&amp;quot; &amp;amp;&amp;amp; $1 !~/[#]/ {print $1}&amp;#039;  /etc/oratab&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Using perl&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
perl -F: -ne &amp;#039;print &amp;quot;$1\n&amp;quot; if /(\w+):(.+):Y$/&amp;#039; /etc/oratab&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Move the admin directories to a new location===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
./all_db_do &amp;quot;alter system set audit_file_dest=&amp;#039;/oracle/&amp;amp;SID/admin/adump&amp;#039; scope=spfile;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
./all_db_do &amp;quot;shutdown immediate&amp;quot;&lt;br /&gt;
&lt;br /&gt;
for db in `awk -F: &amp;#039;NF &amp;amp;&amp;amp; $1 !~/[#*]/ {print $1}&amp;#039;  /etc/oratab`&lt;br /&gt;
do&lt;br /&gt;
    echo $db&lt;br /&gt;
    mkdir -p /oracle/${db}/admin&lt;br /&gt;
    echo &amp;quot;/oracle/${db}/admin created&amp;quot;&lt;br /&gt;
    mv /oracle/admin/${db}/adump /oracle/${db}/admin/&lt;br /&gt;
    mv /oracle/admin/${db}/dpdump /oracle/${db}/admin/&lt;br /&gt;
    echo &amp;quot;Moved /oracle/admin/${db}/adump to /oracle/${db}/admin/&amp;quot;&lt;br /&gt;
done&lt;br /&gt;
&lt;br /&gt;
./all_db_do startup&lt;br /&gt;
&lt;br /&gt;
./all_db_do &amp;quot;create pfile from spfile;&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Check if the Standby database is up-to-date with the primary database===&lt;br /&gt;
 select arch.thread# &amp;quot;Thread&amp;quot;&lt;br /&gt;
 ,      arch.sequence# &amp;quot;Last Sequence Received&amp;quot;&lt;br /&gt;
 ,      appl.sequence# &amp;quot;Last Sequence Applied&amp;quot;&lt;br /&gt;
 ,      (arch.sequence# - appl.sequence#) &amp;quot;Difference&amp;quot;&lt;br /&gt;
 from   (&lt;br /&gt;
        select thread#&lt;br /&gt;
        ,      sequence#&lt;br /&gt;
        from   v$archived_log&lt;br /&gt;
        where  1=1&lt;br /&gt;
        and    ( thread#,first_time ) in (&lt;br /&gt;
                                         select thread#, max(first_time)&lt;br /&gt;
                                         from   v$archived_log&lt;br /&gt;
                                         group  by thread#&lt;br /&gt;
                                         )&lt;br /&gt;
        ) arch&lt;br /&gt;
        ,&lt;br /&gt;
        (&lt;br /&gt;
        select thread#&lt;br /&gt;
        ,      sequence#&lt;br /&gt;
        from   v$log_history&lt;br /&gt;
        where  1=1&lt;br /&gt;
        and    ( thread#,first_time ) in ( select thread# ,max(first_time)&lt;br /&gt;
                                           from   v$log_history&lt;br /&gt;
                                           group  by thread#&lt;br /&gt;
                                          )&lt;br /&gt;
        ) appl&lt;br /&gt;
 where  1=1&lt;br /&gt;
 and    arch.thread# = appl.thread#&lt;br /&gt;
 order  by 1;&lt;br /&gt;
&lt;br /&gt;
===Check for gaps on the Standby database===&lt;br /&gt;
Run this on the standby&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select thread#, low_sequence#, high_sequence# from v$archive_gap;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or run this on the Primary to see the latest generated archive...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select thread#   &amp;quot;Thread&amp;quot;&lt;br /&gt;
,      sequence# &amp;quot;Last sequence generated&amp;quot;&lt;br /&gt;
from   v$archived_log&lt;br /&gt;
where  (thread#, first_time) in ( select thread#, max(first_time)&lt;br /&gt;
                                  from   v$archived_log&lt;br /&gt;
                                  group  by thread#&lt;br /&gt;
                                )&lt;br /&gt;
order  by 1&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
and run this on the standby to check for received but not yet applied logs (this could be normal if a lag has been set)...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select arch.thread# &amp;quot;Thread&amp;quot;&lt;br /&gt;
,      arch.sequence# &amp;quot;Last sequence received&amp;quot;&lt;br /&gt;
,      appl.sequence# &amp;quot;Last sequence applied&amp;quot;&lt;br /&gt;
,      (arch.sequence#-appl.sequence#) &amp;quot;Difference&amp;quot;&lt;br /&gt;
from   (&lt;br /&gt;
       select thread#&lt;br /&gt;
       ,      sequence#&lt;br /&gt;
       from   v$archived_log&lt;br /&gt;
       where  (thread#,first_time ) in (select thread#, max(first_time)&lt;br /&gt;
                                        from   v$archived_log&lt;br /&gt;
                                        group  by thread#&lt;br /&gt;
                                       )&lt;br /&gt;
       ) arch&lt;br /&gt;
,      (&lt;br /&gt;
       select thread#&lt;br /&gt;
       ,      sequence#&lt;br /&gt;
       from   v$log_history&lt;br /&gt;
       where  (thread#,first_time ) in (select thread#, max(first_time)&lt;br /&gt;
                                        from   v$log_history&lt;br /&gt;
                                        group  by thread#&lt;br /&gt;
                                       )&lt;br /&gt;
      ) appl&lt;br /&gt;
where arch.thread# = appl.thread#&lt;br /&gt;
order by 1&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Compare the results from Primary and Secondary to detect possible network problems or other errors in shipping.&lt;br /&gt;
&lt;br /&gt;
===Ignore case-sensitive passwords in 11g (deprecated in 12c)===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter system set SEC_CASE_SENSITIVE_LOGON = false scope=both&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===External table for the Alert log (pre 11g)===&lt;br /&gt;
Modified to use (the better) scripts found on [http://www.adp-gmbh.ch/ora/admin/scripts/read_alert_log.html Rene Nyffenegger&amp;#039;s site]&amp;lt;br /&amp;gt;&lt;br /&gt;
This script generates the required DDL for the alertlog table&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
column db    new_value _DB    noprint;&lt;br /&gt;
column bdump new_value _bdump noprint;&lt;br /&gt;
&lt;br /&gt;
select i&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Alert log (11g+)===&lt;br /&gt;
This reads the log.xml file (which contains the same information as alert.log)&amp;lt;br /&amp;gt;&lt;br /&gt;
Show the messages put in the alert log in the last 24 hours&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select substr(MESSAGE_TEXT, 1, 300) message_text&lt;br /&gt;
,      count(*) cnt&lt;br /&gt;
from   X$DBGALERTEXT&lt;br /&gt;
where  1=1&lt;br /&gt;
and    (MESSAGE_TEXT like &amp;#039;%ORA-%&amp;#039; or upper(MESSAGE_TEXT) like &amp;#039;%ERROR%&amp;#039;)&lt;br /&gt;
and    cast(ORIGINATING_TIMESTAMP as DATE) &amp;gt; sysdate - &amp;amp;days_ago/1440&lt;br /&gt;
group  by substr(MESSAGE_TEXT, 1, 300)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
There is also a fixed table X$DBGDIREXT which returns all file and directory names under [diagnostic_dest]/diag directory:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select lpad(&amp;#039; &amp;#039;,lvl,&amp;#039; &amp;#039;)||logical_file file_name&lt;br /&gt;
from   x$dbgdirext&lt;br /&gt;
where  rownum &amp;lt;=20;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Directory paths available in v$diag_info===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 2000&lt;br /&gt;
col name for a35&lt;br /&gt;
col value for a100 wrap&lt;br /&gt;
select * from v$diag_info;&lt;br /&gt;
&lt;br /&gt;
   INST_ID NAME                                VALUE                                                                                                    CON_ID&lt;br /&gt;
---------- ----------------------------------- ---------------------------------------------------------------------------------------------------- ----------&lt;br /&gt;
         1 Diag Enabled                        TRUE                                                                                                          0&lt;br /&gt;
         1 ADR Base                            /cln/prg/ora_bin2/app/oracle                                                                               0&lt;br /&gt;
         1 ADR Home                            /cln/prg/ora_bin2/app/oracle/diag/rdbms/bild/bild                                                          0&lt;br /&gt;
         1 Diag Trace                          /cln/prg/ora_bin2/app/oracle/diag/rdbms/bild/bild/trace                                                    0&lt;br /&gt;
         1 Diag Alert                          /cln/prg/ora_bin2/app/oracle/diag/rdbms/bild/bild/alert                                                    0&lt;br /&gt;
         1 Diag Incident                       /cln/prg/ora_bin2/app/oracle/diag/rdbms/bild/bild/incident                                                 0&lt;br /&gt;
         1 Diag Cdump                          /cln/prg/ora_bin2/app/oracle/diag/rdbms/bild/bild/cdump                                                    0&lt;br /&gt;
         1 Health Monitor                      /cln/prg/ora_bin2/app/oracle/diag/rdbms/bild/bild/hm                                                       0&lt;br /&gt;
         1 Default Trace File                  /cln/prg/ora_bin2/app/oracle/diag/rdbms/bild/bild/trace/bild_ora_44696768.trc                              0&lt;br /&gt;
         1 Active Problem Count                0                                                                                                             0&lt;br /&gt;
         1 Active Incident Count               0                                                                                                             0&lt;br /&gt;
&lt;br /&gt;
11 rows selected.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Find out the names of the active trace files for the running processes===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select pid, program, tracefile from v$process;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Request was to duplicate a large tablespace from production to test environment===&lt;br /&gt;
...but rather than copy the terabytes of data, create the destination tablespace with just the most recent months data&amp;lt;br /&amp;gt;&lt;br /&gt;
====See what the source data looks like====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
col table_owner    for a20&lt;br /&gt;
col table_name     for a30&lt;br /&gt;
col partition_name for a20&lt;br /&gt;
set pages 100 lines 1000&lt;br /&gt;
&lt;br /&gt;
select table_owner&lt;br /&gt;
,      table_name&lt;br /&gt;
,      partition_name&lt;br /&gt;
,      partition_position&lt;br /&gt;
,      tablespace_name&lt;br /&gt;
from   dba_tab_partitions&lt;br /&gt;
where  tablespace_name = &amp;#039;ADS_ARCHIVE&amp;#039;&lt;br /&gt;
order  by 1,2,3,4&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This query produces something like this...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
TABLE_OWNER          TABLE_NAME                     PARTITION_NAME       PARTITION_POSITION TABLESPACE_NAME                &lt;br /&gt;
-------------------- ------------------------------ -------------------- ------------------ ------------------------------ &lt;br /&gt;
ADS_ARCHIVE          BIL_DAY_INV_CTR_ARC            Y2017_Q1_M01_D01                      1 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          BIL_HIS_DETAIL_FAC_ARC         Y2016_Q2_M05_D04                      1 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          BIL_HIS_DETAIL_FAC_ARC         Y2016_Q2_M05_D09                      2 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          BIL_MTH_INV_CTR_ARC            Y2017_Q1_M01_D01                      1 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          FAH_DAY_CBA_BGAAP_ARC          Y2011_Q4_M12_D30                      1 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          FAH_DAY_CBA_BGAAP_ARC          Y2011_Q4_M12_D31                      2 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          FAH_DAY_CBA_IFRS_ARC           Y2011_Q4_M12_D30                      1 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          FAH_DAY_CBA_IFRS_ARC           Y2011_Q4_M12_D31                      2 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          FAH_DAY_MVT_BGAAP_ARC          Y2011_Q4_M12_D30                      1 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          FAH_DAY_MVT_BGAAP_ARC          Y2011_Q4_M12_D31                      2 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          FAH_DAY_MVT_BGAAP_ARC          Y2012_Q1_M03_D31                      3 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          FAH_DAY_MVT_BGAAP_ARC          Y2012_Q2_M04_D01                      4 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          FAH_DAY_MVT_BGAAP_ARC          Y2012_Q4_M10_D12                      5 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          FAH_DAY_MVT_BGAAP_ARC          Y2012_Q4_M10_D13                      6 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          FAH_DAY_MVT_BGAAP_ARC          Y2012_Q4_M10_D14                      7 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          FAH_DAY_MVT_BGAAP_ARC_TST      Y2011_Q4_M12_D30                      1 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          FAH_DAY_MVT_BGAAP_ARC_TST      Y2011_Q4_M12_D31                      2 ADS_ARCHIVE&lt;br /&gt;
...&lt;br /&gt;
ADS_ARCHIVE          SBP_HIS_LINES_ARC              P_LS                                  3 ADS_ARCHIVE                  &lt;br /&gt;
ADS_ARCHIVE          THA_DAY_INV_CTR_ARC            Y2011_Q4_M12_D30                      1 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          THA_DAY_INV_CTR_ARC            Y2011_Q4_M12_D31                      2 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          THA_INV_HEAVY_ARC              Y2011_Q4_M12_D30                      1 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          THA_INV_HEAVY_ARC              Y2011_Q4_M12_D31                      2 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          THA_INV_LIGHT_ARC              Y2011_Q4_M12_D30                      1 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          THA_INV_LIGHT_ARC              Y2012_Q4_M10_D12                      2 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          THA_INV_LIGHT_ARC              Y2012_Q4_M10_D13                      3 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          THA_INV_LIGHT_ARC              Y2012_Q4_M10_D15                      4 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          THA_INV_LIGHT_ARC              Y2012_Q4_M10_D16                      5 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          THA_INV_LIGHT_ARC              Y2012_Q4_M10_D17                      6 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          THA_INV_LIGHT_ARC              Y2012_Q4_M10_D18                      7 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          THA_INV_LIGHT_ARC              Y2012_Q4_M10_D19                      8 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          THA_INV_LIGHT_ARC              Y2012_Q4_M10_D20                      9 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          THA_INV_LIGHT_ARC              Y2012_Q4_M10_D21                     10 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          THA_INV_LIGHT_ARC              Y2012_Q4_M10_D22                     11 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          THA_INV_LIGHT_ARC              Y2012_Q4_M10_D23                     12 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          THA_INV_LIGHT_ARC              Y2012_Q4_M10_D24                     13 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          THA_MTH_INV_CTR_ARC            Y2011_Q4_M12_D30                      1 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          THA_MTH_INV_CTR_ARC            Y2011_Q4_M12_D31                      2 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          THA_MTH_INV_CTR_ARC            Y2013_Q2_M04_D30                      3 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          XBD01_TEMP_HIS_ARC             Y2012_Q4_M12_D31                      1 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          T_RPT_RECO_THA_INV_ACC_ARC     Y2011_Q4_M12_D30                      1 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          T_RPT_RECO_THA_INV_ACC_ARC     Y2011_Q4_M12_D31                      2 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          T_RPT_RECO_THA_INV_MTH_ARC     Y2011_Q4_M12_D30                      1 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          T_RPT_RECO_THA_INV_MTH_ARC     Y2011_Q4_M12_D31                      2 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          XBD01_TEMP_HIS_ARC             Y2012_Q4_M12_D31                      1 ADS_ARCHIVE&lt;br /&gt;
ADS_DBA              FAH_DAY_CBA_BGAAP              Y2016_Q3_M07_D12                   1657 ADS_ARCHIVE&lt;br /&gt;
ADS_DBA              FAH_DAY_CBA_BGAAP              Y2016_Q4_M12_D13                   1811 ADS_ARCHIVE&lt;br /&gt;
ADS_DBA              FAH_DAY_MVT_IFRS               Y2016_Q4_M10_D10                   1654 ADS_ARCHIVE&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Capture the tablespace metadata====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set long 1000000&lt;br /&gt;
select dbms_metadata.get_ddl ( &amp;#039;TABLESPACE&amp;#039;, &amp;#039;ADS_ARCHIVE&amp;#039;) from dual&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
produces...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
CREATE TABLESPACE &amp;quot;ADS_ARCHIVE&amp;quot; DATAFILE&lt;br /&gt;
  &amp;#039;/oracle/tst/ora_data3/adst/ads_archive01.dbf&amp;#039; SIZE 104857600&lt;br /&gt;
  AUTOEXTEND ON NEXT 104857600 MAXSIZE 32000M,&lt;br /&gt;
...&lt;br /&gt;
  &amp;#039;/oracle/tst/ora_data3/adst/ads_archive66.dbf&amp;#039; SIZE 104857600&lt;br /&gt;
  AUTOEXTEND ON NEXT 104857600 MAXSIZE 3200M,&lt;br /&gt;
  LOGGING ONLINE PERMANENT BLOCKSIZE 8192&lt;br /&gt;
  EXTENT MANAGEMENT LOCAL AUTOALLOCATE DEFAULT&lt;br /&gt;
 NOCOMPRESS  SEGMENT SPACE MANAGEMENT AUTO&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Capture the tablespace objects&amp;#039; metadata====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cat&amp;lt;&amp;lt;EOCAT &amp;gt;expdp_adst_ads_archive_metadata.par&lt;br /&gt;
userid=&amp;#039;/ as sysdba&amp;#039;&lt;br /&gt;
dumpfile=adst_ads_archive_metadata.dmp&lt;br /&gt;
logfile=expdp_adst_ads_archive_metadata.log&lt;br /&gt;
tablespaces=ADS_ARCHIVE&lt;br /&gt;
parallel=20&lt;br /&gt;
content=metadata_only&lt;br /&gt;
exclude=statistics&lt;br /&gt;
EOCAT&lt;br /&gt;
&lt;br /&gt;
expdp parfile=expdp_adst_ads_archive_metadata.par&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Find the partitions with data from the most recent month====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cat &amp;lt;&amp;lt;EOCAT&amp;gt;/tmp/adst_ads_archive_partitions.sql&lt;br /&gt;
set termo off echo off lines 1000 feedb off headi off newpa none trims on&lt;br /&gt;
spool /tmp/adst_ads_archive_partitions.lst&lt;br /&gt;
select table_owner||&amp;#039;.&amp;#039;||table_name||&amp;#039;:&amp;#039;||partition_name&lt;br /&gt;
from   dba_tab_partitions&lt;br /&gt;
where  tablespace_name = &amp;#039;ADS_ARCHIVE&amp;#039;&lt;br /&gt;
and    partition_name like &amp;#039;Y2017_Q1_M01%&amp;#039;&lt;br /&gt;
/&lt;br /&gt;
spool off&lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;@/tmp/adst_ads_archive_partitions.sql&amp;quot; | sqlplus / as sysdba&lt;br /&gt;
EOCAT&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
produces...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_CBA_BGAAP_ARC:Y2017_Q1_M01_D07&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_IFRS_ARC:Y2017_Q1_M02_D26&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_IFRS_ARC:Y2017_Q1_M02_D25&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_IFRS_ARC:Y2017_Q1_M02_D19&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_IFRS_ARC:Y2017_Q1_M02_D18&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_IFRS_ARC:Y2017_Q1_M02_D12&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_IFRS_ARC:Y2017_Q1_M02_D11&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_IFRS_ARC:Y2017_Q1_M02_D05&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_BGAAP_ARC:Y2017_Q1_M02_D26&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_BGAAP_ARC:Y2017_Q1_M02_D25&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_BGAAP_ARC:Y2017_Q1_M02_D19&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_BGAAP_ARC:Y2017_Q1_M02_D18&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_BGAAP_ARC:Y2017_Q1_M02_D12&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_BGAAP_ARC:Y2017_Q1_M02_D11&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_BGAAP_ARC:Y2017_Q1_M02_D05&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_BGAAP_ARC:Y2017_Q1_M02_D04&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_BGAAP_ARC:Y2017_Q1_M01_D29&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_BGAAP_ARC:Y2017_Q1_M01_D28&lt;br /&gt;
...&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_BGAAP_ARC:Y2017_Q1_M01_D22&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_BGAAP_ARC:Y2017_Q1_M01_D21&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_BGAAP_ARC:Y2017_Q1_M01_D15&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_BGAAP_ARC:Y2017_Q1_M01_D14&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_BGAAP_ARC:Y2017_Q1_M01_D08&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_BGAAP_ARC:Y2017_Q1_M01_D07&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_BGAAP_ARC:Y2017_Q1_M01_D01&lt;br /&gt;
ADS_ARCHIVE.BIL_MTH_INV_CTR_ARC:Y2017_Q1_M01_D01&lt;br /&gt;
ADS_ARCHIVE.BIL_DAY_INV_CTR_ARC:Y2017_Q1_M01_D01&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_IFRS_ARC:Y2017_Q1_M02_D04&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_IFRS_ARC:Y2017_Q1_M01_D29&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_IFRS_ARC:Y2017_Q1_M01_D28&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_IFRS_ARC:Y2017_Q1_M01_D22&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Export the data in these partitions====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cat&amp;lt;&amp;lt;EOCAT &amp;gt;expdp_adst_ads_archive_partitions.par&lt;br /&gt;
userid=&amp;#039;/ as sysdba&amp;#039;&lt;br /&gt;
dumpfile=adst_ads_archive_Y2017_%U.dmp&lt;br /&gt;
logfile=expdp_adst_ads_archive_Y2017.log&lt;br /&gt;
EOCAT&lt;br /&gt;
&lt;br /&gt;
cat /tmp/adst_ads_archive_partitions.lst | perl -p -i -e &amp;#039;s/^/tables=/&amp;#039;g &amp;gt;&amp;gt;expdp_adst_ads_archive_partitions.par&lt;br /&gt;
&lt;br /&gt;
cat&amp;lt;&amp;lt;EOCAT &amp;gt;&amp;gt;expdp_adst_ads_archive_partitions.par&lt;br /&gt;
parallel=20&lt;br /&gt;
exclude=statistics&lt;br /&gt;
EOCAT&lt;br /&gt;
&lt;br /&gt;
expdp parfile=expdp_adst_ads_archive_partitions.par&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Drop the old tablespace====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
drop tablespace ads_archive including contents and datafiles&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Recreate the tablepspace using the metadata capture above====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
create tablespace &amp;quot;ADS_ARCHIVE&amp;quot;&lt;br /&gt;
datafile &amp;#039;/oracle/tst/ora_data3/adst/ads_archive01.dbf&amp;#039; size 100M autoextend on next 50M maxsize unlimited&lt;br /&gt;
,        &amp;#039;/oracle/tst/ora_data3/adst/ads_archive02.dbf&amp;#039; size 100M autoextend on next 50M maxsize unlimited&lt;br /&gt;
,        &amp;#039;/oracle/tst/ora_data3/adst/ads_archive03.dbf&amp;#039; size 100M autoextend on next 50M maxsize unlimited&lt;br /&gt;
,        &amp;#039;/oracle/tst/ora_data3/adst/ads_archive04.dbf&amp;#039; size 100M autoextend on next 50M maxsize unlimited&lt;br /&gt;
,        &amp;#039;/oracle/tst/ora_data3/adst/ads_archive05.dbf&amp;#039; size 100M autoextend on next 50M maxsize unlimited&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Import the tablespace metadata====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cat&amp;lt;&amp;lt;EOCAT &amp;gt;impdp_adst_ads_archive_metadata.par&lt;br /&gt;
userid=&amp;#039;/ as sysdba&amp;#039;&lt;br /&gt;
dumpfile=adst_ads_archive_metadata.dmp&lt;br /&gt;
logfile=impdp_adst_ads_archive_metadata.log&lt;br /&gt;
EOCAT&lt;br /&gt;
&lt;br /&gt;
impdp parfile=impdp_adst_ads_archive_metadata.par&lt;br /&gt;
&lt;br /&gt;
select &amp;#039;alter index &amp;#039;|| owner||&amp;#039;.&amp;#039;||index_name||&amp;#039; rebuild online parallel 8;&amp;#039;&lt;br /&gt;
from   dba_indexes&lt;br /&gt;
where  status = &amp;#039;UNUSABLE&amp;#039;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Import the last month partition data====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cat&amp;lt;&amp;lt;EOCAT &amp;gt;impdp_adst_ads_archive_partitions.par&lt;br /&gt;
userid=&amp;#039;/ as sysdba&amp;#039;&lt;br /&gt;
dumpfile=adst_ads_archive_Y2017_%U.dmp&lt;br /&gt;
logfile=impdp_adst_ads_archive_Y2017.log&lt;br /&gt;
table_exists_action=append&lt;br /&gt;
parallel=20&lt;br /&gt;
EOCAT&lt;br /&gt;
&lt;br /&gt;
impdp parfile=impdp_adst_ads_archive_partitions.par&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Write to a TCP/IP socket from PL/SQL===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
declare&lt;br /&gt;
 bt_conn               utl_tcp.connection;&lt;br /&gt;
 retval                binary_integer;&lt;br /&gt;
 l_sequence            varchar2(30) := &amp;#039;Sequence Number 101021&amp;#039;;&lt;br /&gt;
begin&lt;br /&gt;
 bt_conn := utl_tcp.open_connection(remote_host =&amp;gt; &amp;#039;10.10.1.1&amp;#039;&lt;br /&gt;
                                   ,remote_port =&amp;gt; 5000&lt;br /&gt;
                                   ,tx_timeout =&amp;gt; 1&lt;br /&gt;
                                   )&lt;br /&gt;
 ;&lt;br /&gt;
 retval := utl_tcp.write_line(bt_conn,l_sequence)&lt;br /&gt;
 ;&lt;br /&gt;
 utl_tcp.flush(bt_conn)&lt;br /&gt;
 ;&lt;br /&gt;
 utl_tcp.close_connection(bt_conn)&lt;br /&gt;
 ;&lt;br /&gt;
exception&lt;br /&gt;
 when others then&lt;br /&gt;
  raise_application_error(-20101, sqlerrm)&lt;br /&gt;
  ; &lt;br /&gt;
  utl_tcp.close_connection(bt_conn)&lt;br /&gt;
  ;&lt;br /&gt;
end&lt;br /&gt;
;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
and read from it using netcat in another session&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
nc -lk 5000&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
produces&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Sequence Number 101021&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Execute a script as a different user===&lt;br /&gt;
Some things have to be done as the user and cannot be done as sys (eg. creating and dropping jobs or create and drop a database link)&amp;lt;br /&amp;gt;&lt;br /&gt;
It is possible to login as the user by saving, changing and resetting his password (using identified by values) but using dbms_sys_sql is another option&amp;lt;br /&amp;gt;&lt;br /&gt;
Create a PL/SQL procedure to drop a db link&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
create or replace procedure drop_dblink ( p_schema_name in varchar2&lt;br /&gt;
                                        , p_dblink      in varchar2&lt;br /&gt;
                                        ) is&lt;br /&gt;
    l_plsql   varchar2(1000);&lt;br /&gt;
    l_cur     number;&lt;br /&gt;
    l_uid     number;&lt;br /&gt;
    l_rc      number;&lt;br /&gt;
begin&lt;br /&gt;
    select  du.user_id&lt;br /&gt;
    into    l_uid&lt;br /&gt;
    from    dba_users du&lt;br /&gt;
    where   du.username = p_schema_name&lt;br /&gt;
    ;&lt;br /&gt;
    plsql := &amp;#039;drop database link &amp;quot;&amp;#039;||p_dblink||&amp;#039;&amp;quot;&amp;#039;;&lt;br /&gt;
    l_cur := sys.dbms_sys_sql.open_cursor;&lt;br /&gt;
    sys.dbms_sys_sql.parse_as_user(&lt;br /&gt;
        c             =&amp;gt; l_cur,&lt;br /&gt;
        statement     =&amp;gt; l_plsql,&lt;br /&gt;
        language_flag =&amp;gt; dbms_sql.native,&lt;br /&gt;
        userid        =&amp;gt; l_uid&lt;br /&gt;
    );&lt;br /&gt;
    l_rc := sys.dbms_sys_sql.execute(l_cur);&lt;br /&gt;
    sys.dbms_sys_sql.close_cursor(l_cur);&lt;br /&gt;
end;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Generate the calls to the procedure with the required parameters&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select &amp;#039;exec drop_dblink (&amp;#039;&amp;#039;&amp;#039;|| owner ||&amp;#039;&amp;#039;&amp;#039;&amp;#039;||&amp;#039;, &amp;#039;||&amp;#039;&amp;#039;&amp;#039;&amp;#039;||db_link||&amp;#039;&amp;#039;&amp;#039;&amp;#039;||&amp;#039;);&amp;#039;&lt;br /&gt;
from   dba_db_links&lt;br /&gt;
where  owner   != &amp;#039;PUBLIC&amp;#039;&lt;br /&gt;
and    db_link like &amp;#039;%FTST%&amp;#039;&lt;br /&gt;
or     db_link like &amp;#039;%HDEV%&amp;#039;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
and this reveals the lines to be executed&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
exec drop_dblink (&amp;#039;USER1&amp;#039;, &amp;#039;DBL_FTST.WORLD&amp;#039;);&lt;br /&gt;
exec drop_dblink (&amp;#039;USER1&amp;#039;, &amp;#039;DBL_HDEV.WORLD&amp;#039;);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Drop the procedure when finished with it&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
drop procedure drop_dblink;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
or do it as an anonymous block in one go...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
declare&lt;br /&gt;
    uid number;&lt;br /&gt;
    sqltext varchar2(1000) := &amp;#039;drop database link &amp;quot;&amp;amp;DB_LINK&amp;quot;&amp;#039;;&lt;br /&gt;
    myint integer;&lt;br /&gt;
begin&lt;br /&gt;
    select user_id into uid from dba_users where username = &amp;#039;&amp;amp;USERNAME&amp;#039;;&lt;br /&gt;
    myint:=sys.dbms_sys_sql.open_cursor();&lt;br /&gt;
    sys.dbms_sys_sql.parse_as_user(myint,sqltext,dbms_sql.native,UID);&lt;br /&gt;
    sys.dbms_sys_sql.close_cursor(myint);&lt;br /&gt;
end;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Handling single quote marks inside SQL statements===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SQL&amp;gt; SELECT &amp;#039;D&amp;#039;&amp;#039;COSTA&amp;#039; name FROM DUAL;&lt;br /&gt;
&lt;br /&gt;
NAME&lt;br /&gt;
-------&lt;br /&gt;
D&amp;#039;COSTA&lt;br /&gt;
&lt;br /&gt;
Alternatively, use the 10g+ quoting method:&lt;br /&gt;
&lt;br /&gt;
SQL&amp;gt; SELECT q&amp;#039;$D&amp;#039;COSTA$&amp;#039; NAME FROM DUAL;&lt;br /&gt;
&lt;br /&gt;
NAME&lt;br /&gt;
-------&lt;br /&gt;
D&amp;#039;COSTA&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Run a script on all databases in /etc/oratab===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
export ORAENV_ASK=NO&lt;br /&gt;
for db in `awk -F: &amp;#039;NF &amp;amp;&amp;amp; $1 !~/[#*]/ {print $1}&amp;#039;  /etc/oratab`&lt;br /&gt;
do&lt;br /&gt;
    echo $db&lt;br /&gt;
    ORACLE_SID=$db&lt;br /&gt;
    . oraenv&lt;br /&gt;
    sqlplus -V&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Schedule a cron job to run on the last day of each month===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
0 23 28-31 * * [ $(date -d +1day +%d) -eq 1 ] &amp;amp;&amp;amp; su - oracle -c &amp;quot;dsmc  arch -server=SO_U_`hostname`_ORX_M_SOL &amp;#039;/oracle/export/PV6/expdp_PV6_D_FULL_`date +\%Y\%m\%d`*&amp;#039;&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===How to tell if a year is a leap year or not - using cal instead of reinventing the wheel===&lt;br /&gt;
Test: Why is Julian day 0, 17th November 1858?&amp;lt;br /&amp;gt;&lt;br /&gt;
Pretty comprehensive answer: [http://h71000.www7.hp.com/wizard/wiz_2315.html here] and [http://mentalfloss.com/article/51370/why-our-calendars-skipped-11-days-1752 here]&amp;lt;br /&amp;gt;&lt;br /&gt;
Also attempts to answer the question why typing &amp;#039;cal 09 1752&amp;#039; on Unix systems looks so odd!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
function leap {&lt;br /&gt;
#  This function tells you if the year passed in as a parameter is a leap year or not...&lt;br /&gt;
if [[ $(cal 2 ${1:-$(date &amp;#039;+%Y&amp;#039;)} | egrep &amp;#039;\&amp;lt;[[:digit:]]{1,2}\&amp;gt;&amp;#039; | wc -w) -eq 29 ]]; then&lt;br /&gt;
    leap=&amp;#039;Y&amp;#039;&lt;br /&gt;
else&lt;br /&gt;
    leap=&amp;#039;N&amp;#039;&lt;br /&gt;
fi&lt;br /&gt;
echo ${leap}&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Reset an expired (and/or locked) user password to the same value===&lt;br /&gt;
Can be used to save user passwords for example in a test environment before destroying them with a copy of production.&amp;lt;br /&amp;gt;&lt;br /&gt;
Simple, quick and easy version. Run this then pick and choose the statements you want to run.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 200 pages 200&lt;br /&gt;
col user_list for a200 head &amp;quot;Expired User List&amp;quot;&lt;br /&gt;
&lt;br /&gt;
select &amp;#039;alter user &amp;#039; ||su.name||&amp;#039; identified by values&amp;#039;||&amp;#039;&amp;#039;&amp;#039;&amp;#039;||spare4||&amp;#039;;&amp;#039;||su.password||&amp;#039;&amp;#039;&amp;#039; account unlock;&amp;#039; user_list&lt;br /&gt;
from   sys.user$ su&lt;br /&gt;
,      dba_users du&lt;br /&gt;
where  1=1&lt;br /&gt;
and    su.name              = du.username&lt;br /&gt;
and    du.oracle_maintained = &amp;#039;N&amp;#039;&lt;br /&gt;
and    (account_status      like &amp;#039;EXPIRED%&amp;#039; or account_status like &amp;#039;%LOCKED&amp;#039;)&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
More industrialised version. Create a package.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
create or replace package dba_utils&lt;br /&gt;
as&lt;br /&gt;
    procedure reset_password ( p_userlist in varchar2 );&lt;br /&gt;
end dba_utils;&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
create or replace package body dba_utils&lt;br /&gt;
as&lt;br /&gt;
&lt;br /&gt;
procedure reset_password ( p_userlist in varchar2 )&lt;br /&gt;
is&lt;br /&gt;
    cursor c1 ( p_userlist in varchar2 ) is&lt;br /&gt;
    select username&lt;br /&gt;
    ,      regexp_substr ( dbms_metadata.get_ddl(&amp;#039;USER&amp;#039;, username), &amp;#039;&amp;#039;&amp;#039;[^&amp;#039;&amp;#039;]+&amp;#039;&amp;#039;&amp;#039; ) pwd&lt;br /&gt;
    from   dba_users&lt;br /&gt;
    where  1=1&lt;br /&gt;
    and    username in upper( p_userlist )&lt;br /&gt;
    ;&lt;br /&gt;
begin&lt;br /&gt;
    dbms_output.enable(null);&lt;br /&gt;
    for r1 in c1 ( p_userlist )&lt;br /&gt;
    loop&lt;br /&gt;
        begin&lt;br /&gt;
            execute immediate &amp;#039;alter user &amp;#039; || r1.username || &amp;#039; account unlock&amp;#039;;&lt;br /&gt;
            execute immediate &amp;#039;alter user &amp;#039; || r1.username || &amp;#039; identified by values &amp;#039; || r1.pwd;&lt;br /&gt;
        exception&lt;br /&gt;
        when others then&lt;br /&gt;
            dbms_output.put_line(&amp;#039;Unable to modify user &amp;#039; || r1.username);&lt;br /&gt;
        end;&lt;br /&gt;
    end loop;&lt;br /&gt;
end reset_password;&lt;br /&gt;
&lt;br /&gt;
end dba_utils;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Call it&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set serveroutput on&lt;br /&gt;
exec dba_utils.reset_password (&amp;#039;STUART&amp;#039;);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Latch, mutex and beyond===&lt;br /&gt;
A fine example of how to write scripts from SQL*Plus that interact with the shell underneath&amp;lt;br /&amp;gt;&lt;br /&gt;
Found [https://andreynikolaev.wordpress.com/demonstration-scripts/cursor_pin_s_contention-sql/ here at andreynikolaev.wordpress.com]&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/*&lt;br /&gt;
     This file is part of demos for &amp;quot;Mutex Internals&amp;quot;  seminar v.04.04.2011&lt;br /&gt;
     Andrey S. Nikolaev (Andrey.Nikolaev@rdtex.ru) &lt;br /&gt;
     https://andreynikolaev.wordpress.com &lt;br /&gt;
 &lt;br /&gt;
     &amp;quot;Cursor: pin S&amp;quot; contention testcase.&lt;br /&gt;
 &lt;br /&gt;
     The script spawn several sessions to induce &amp;quot;Cursor: pin S&amp;quot;, &lt;br /&gt;
     creates AWR snapshots and generates AWR report&lt;br /&gt;
 &lt;br /&gt;
     Beware: The script will restart the test database.&lt;br /&gt;
 &lt;br /&gt;
     usage: sqlplus /nolog @cursor_pin_s_contention.sql &amp;lt;parallelism&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
*/ &lt;br /&gt;
connect / as sysdba&lt;br /&gt;
startup force&lt;br /&gt;
set echo off&lt;br /&gt;
set define %&lt;br /&gt;
set verify off&lt;br /&gt;
set head off&lt;br /&gt;
set linesize 300&lt;br /&gt;
 &lt;br /&gt;
/* spawn parallel processes to create load on mutex */&lt;br /&gt;
spool one_thread.tmp&lt;br /&gt;
select &amp;#039;set verify off&amp;#039; from dual;&lt;br /&gt;
select &amp;#039;alter session set session_cached_cursors = 50;&amp;#039; from dual; &lt;br /&gt;
select &amp;#039;begin for i in 1..1000000 loop&amp;#039; from dual;&lt;br /&gt;
select &amp;#039;      execute immediate &amp;#039;&amp;#039;select 1 from dual where 1=2&amp;#039;&amp;#039;;&amp;#039; from dual;&lt;br /&gt;
select &amp;#039;end loop; end;&amp;#039;||chr(10)||&amp;#039;/&amp;#039; from dual;&lt;br /&gt;
spool off&lt;br /&gt;
 &lt;br /&gt;
/* sleep while AWR initialized */&lt;br /&gt;
host sleep 5&lt;br /&gt;
 &lt;br /&gt;
exec dbms_workload_repository.create_snapshot();&lt;br /&gt;
 &lt;br /&gt;
spool many_threads.tmp&lt;br /&gt;
select &amp;#039;host sqlplus &amp;quot;/ as sysdba&amp;quot; @one_thread.tmp &amp;amp;&amp;#039;&lt;br /&gt;
from dba_objects where rownum &amp;lt;= %1;&lt;br /&gt;
spool off&lt;br /&gt;
 &lt;br /&gt;
@many_threads.tmp&lt;br /&gt;
host sleep 50&lt;br /&gt;
set echo on&lt;br /&gt;
exec dbms_workload_repository.create_snapshot();&lt;br /&gt;
set markup html on&lt;br /&gt;
set head on&lt;br /&gt;
spool mutex_sleep_history.htm&lt;br /&gt;
select to_char(SLEEP_TIMESTAMP,&amp;#039;hh:mi:ss.ff&amp;#039;) SLEEP_TIMESTAMP,MUTEX_ADDR,MUTEX_IDENTIFIER,MUTEX_TYPE,&lt;br /&gt;
       GETS,SLEEPS,REQUESTING_SESSION,BLOCKING_SESSION,&lt;br /&gt;
       LOCATION,MUTEX_VALUE from x$mutex_sleep_history order by sleep_timestamp;&lt;br /&gt;
spool off&lt;br /&gt;
 &lt;br /&gt;
set define &amp;amp;&lt;br /&gt;
set markup html off&lt;br /&gt;
set echo off heading on underline on;&lt;br /&gt;
column inst_num  heading &amp;quot;Inst Num&amp;quot;  new_value inst_num  format 99999;&lt;br /&gt;
column inst_name heading &amp;quot;Instance&amp;quot;  new_value inst_name format a12;&lt;br /&gt;
column db_name   heading &amp;quot;DB Name&amp;quot;   new_value db_name   format a12;&lt;br /&gt;
column dbid      heading &amp;quot;DB Id&amp;quot;     new_value dbid      format 9999999999 just c;&lt;br /&gt;
select d.dbid            dbid&lt;br /&gt;
     , d.name            db_name&lt;br /&gt;
     , i.instance_number inst_num&lt;br /&gt;
     , i.instance_name   inst_name&lt;br /&gt;
  from v$database d,&lt;br /&gt;
       v$instance i;&lt;br /&gt;
define num_days=1;&lt;br /&gt;
define report_type=&amp;#039;html&amp;#039;;&lt;br /&gt;
col end_snap new_value end_snap;&lt;br /&gt;
col begin_snap new_value begin_snap;&lt;br /&gt;
select max(snap_id) end_snap from dba_hist_snapshot where dbid=&amp;amp;dbid;&lt;br /&gt;
select max(snap_id) begin_snap from dba_hist_snapshot where dbid=&amp;amp;dbid and snap_id &amp;lt; &amp;amp;end_snap;&lt;br /&gt;
define report_name=&amp;#039;awr_report.htm&amp;#039;;&lt;br /&gt;
@?/rdbms/admin/awrrpti&lt;br /&gt;
exit&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==shell==&lt;br /&gt;
[http://www.databasejournal.com/features/oracle/article.php/3869076/Alert-Log-Scraping-with-Oracles-ADRCI-Utility.htm Alert Log scraping with ADRCI]&lt;br /&gt;
&lt;br /&gt;
====Count the number of background processes for a particular SID====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SID=RAVJDE1&lt;br /&gt;
ps -ef|cut -c54-100|awk -v SID=$SID &amp;#039;$0 ~ /&amp;#039;$SID&amp;#039;$/ {print}&amp;#039;|wc -l&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or ...this will work with any OS (so long as the process is at the end of the &amp;lt;strong&amp;gt;ps -ef&amp;lt;/strong&amp;gt; or &amp;lt;strong&amp;gt;ps -aux&amp;lt;/strong&amp;gt; listing&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SID=RAVJDE1&lt;br /&gt;
ps -ef|awk -v SID=$SID -F_ &amp;#039;{ $NF ~ /&amp;#039;$SID&amp;#039;$/ {print} }&amp;#039;|wc -l&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Pick the columns you want in the ps listing&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ps -efo user,pid,ppid=MOM -o args&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Find Oracle errors in the most recent DataPump log files====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
00 09 * * * /home/tools/scripts/oracle/dosh &amp;#039;find /oracle/export -name &amp;quot;expdp*log&amp;quot; -mtime -1 -exec grep ORA- {} \; -ls&amp;#039; | mailx -s &amp;#039;Datapump errors for &amp;lt;customer&amp;gt;last night&amp;#039; stuart@domain.com&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Find the 10 largest directories on a particular filesystem====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
du -ag /oracle | sort -nr | head -n 10&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Find the 10 largest files on a particular mount point====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
find /home -size +1G -ls | sort -nr +6 | head -10&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
find /home -xdev -ls | sort -nr +6 | head -10&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Split a file in pieces using sed====&lt;br /&gt;
Using fixed line numbers&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sed -ne &amp;#039;1,12p&amp;#039; file &amp;gt; text.part1&lt;br /&gt;
sed -ne &amp;#039;13,$p&amp;#039; file &amp;gt; text.part2&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Using line with a /pattern/ on it&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sed -e &amp;#039;/hello/q&amp;#039; tt.dat | grep -v hello &amp;gt; text.part1&lt;br /&gt;
sed -n `sed -n &amp;#039;/hello/=&amp;#039; tt.dat`&amp;#039;,$p&amp;#039; tt.dat | grep -v hello &amp;gt; text.part2&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Split a file in pieces using Perl====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
perl -ne &amp;#039;print if 1 .. /marker line/&amp;#039; text.dat &amp;gt;text.part1&lt;br /&gt;
perl -ne &amp;#039;print if /marker line/ .. eof()&amp;#039; text.dat &amp;gt;text.part2&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Find and display RMAN errors in an RMAN log file====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sed -ne &amp;#039;/^RMAN-/,/^$/p&amp;#039;  RMAN_&amp;lt;SID&amp;gt;_&amp;lt;DATE&amp;gt;.log&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==cmd==&lt;br /&gt;
*[http://www.dba-oracle.com/t_scripts_windows_export.htm Database Export - from DBA Oracle (Burleson)]&lt;br /&gt;
==Perl==&lt;br /&gt;
===For all files in a directory, replace a keyword (SSIIDD) in a file with another (a parameter)===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
for i in `ls`&lt;br /&gt;
do&lt;br /&gt;
    perl -p -i -e &amp;#039;s/SSIIDD/&amp;#039;$SID&amp;#039;/g&amp;#039; $i&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Parse tnsnames.ora to get just the service names===&lt;br /&gt;
[[http://stackoverflow.com/questions/12605415/parsing-tnsnames-ora-with-regex-to-just-get-name from here]]&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
perl -ne &amp;#039;print if m/^([^#()\W ][a-zA-Z.]*(?:[.][a-zA-Z]*\s?=)?)/&amp;#039; $TNS_ADMIN/tnsnames.ora&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===and use that to check the listener status===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
for svc in `perl -ne &amp;#039;print if m/^([^#()\W ][a-zA-Z.]*(?:[.][a-zA-Z]*\s?=)?)/&amp;#039; $TNS_ADMIN/tnsnames.ora | sed -e &amp;#039;s/=//&amp;#039;` ;do&lt;br /&gt;
    tnsping $svc&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Stuart</name></author>	</entry>

	<entry>
		<id>https://mailnest.com/dbawiki/index.php?title=Handy_scripts&amp;diff=3377</id>
		<title>Handy scripts</title>
		<link rel="alternate" type="text/html" href="https://mailnest.com/dbawiki/index.php?title=Handy_scripts&amp;diff=3377"/>
				<updated>2018-11-21T13:17:36Z</updated>
		
		<summary type="html">&lt;p&gt;Stuart: /* External table for the Alert log (pre 11g) */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==SQL==&lt;br /&gt;
* [[Database Overview - from idevelopment]] [http://www.idevelopment.info/data/Oracle/DBA_scripts/Database_Administration/dba_snapshot_database_10g.sql online version]&lt;br /&gt;
* [[Extract ddl with &amp;quot;dbms metadata.get ddl&amp;quot;]]&lt;br /&gt;
* [http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:83012348058 Connecting as another user via proxy in SQL*Plus]&lt;br /&gt;
* [http://www.petefinnigan.com/tools.htm Password cracker and role and priv tools from Pete Finnigan]&lt;br /&gt;
* [http://www.oracle.com/technetwork/articles/sql/11g-pivot-097235.html Using pivot tables in SQL - XML and XLS (Excel) also)]&lt;br /&gt;
===List all instances running on a server===&lt;br /&gt;
Sounds simple enough and indeed pre 12.1, is was as easy as either&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ps -ef | grep [p]mon | awk -F_ &amp;#039;{print $NF}&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or this one is safer in case you have an underscore character in your SID name!!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SIDLIST=$(${PS} -ef | ${GREP} [o]ra_pmon | ${AWK} &amp;#039;{print $NF}&amp;#039; | sed -e &amp;#039;s/ora_pmon_//&amp;#039; | egrep -v &amp;#039;grep|///|sed|awk|ASM|^$&amp;#039;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
but now we have the added complication of CDB/PDB (container / pluggable databases) so a fair bit more work is needed!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/ksh&lt;br /&gt;
# ==============================================================================&lt;br /&gt;
# Name         : list_server_db&lt;br /&gt;
# Description  : List all running databases found on a server&lt;br /&gt;
#&lt;br /&gt;
# Parameters   : none&lt;br /&gt;
#&lt;br /&gt;
# Notes        : none&lt;br /&gt;
#&lt;br /&gt;
# Modification History&lt;br /&gt;
# ====================&lt;br /&gt;
# When      Who               What&lt;br /&gt;
# ========= ================= ==================================================&lt;br /&gt;
# 21-DEC-16 Stuart Barkley    Created&lt;br /&gt;
# ==============================================================================&lt;br /&gt;
for db in $(ps -ef | grep [p]mon|awk -F_ &amp;#039;{print $NF}&amp;#039;)&lt;br /&gt;
do&lt;br /&gt;
    export ORACLE_SID=${db}&lt;br /&gt;
    ORAENV_ASK=NO&lt;br /&gt;
    . oraenv &amp;gt;/dev/null 2&amp;gt;&amp;amp;1&lt;br /&gt;
    sqlplus -s / as sysdba&amp;lt;&amp;lt;EOSQL&lt;br /&gt;
set serveroutput on feed off pages 0 head off newpa none&lt;br /&gt;
declare&lt;br /&gt;
    e_col_not_found exception;&lt;br /&gt;
    e_not_mounted   exception;&lt;br /&gt;
    pragma          exception_init(e_not_mounted, -01507);&lt;br /&gt;
    pragma          exception_init(e_col_not_found, -904);&lt;br /&gt;
    l_db_name       varchar2(20);&lt;br /&gt;
    l_database_role varchar2(20);&lt;br /&gt;
    l_cdb           varchar2(20);&lt;br /&gt;
    l_status        varchar2(20);&lt;br /&gt;
    type varchar2_tab is table of varchar2(240) index by binary_integer;&lt;br /&gt;
    t_pdbs          varchar2_tab;&lt;br /&gt;
begin&lt;br /&gt;
    begin&lt;br /&gt;
        dbms_output.enable(null);&lt;br /&gt;
        execute immediate &amp;#039;select name, database_role, cdb from v\$database&amp;#039; into l_db_name, l_database_role, l_cdb;&lt;br /&gt;
        if l_cdb = &amp;#039;YES&amp;#039; then&lt;br /&gt;
            l_status := &amp;#039;CDB&amp;#039;;&lt;br /&gt;
            execute immediate &amp;#039;select name from v\$pdbs&amp;#039; bulk collect into t_pdbs;&lt;br /&gt;
            for i in nvl(t_pdbs.first,1) .. nvl(t_pdbs.last,0)&lt;br /&gt;
            loop&lt;br /&gt;
                dbms_output.put_line (t_pdbs(i)||&amp;#039;:PDB&amp;#039;);&lt;br /&gt;
            end loop;&lt;br /&gt;
        else&lt;br /&gt;
            l_status := &amp;#039;Independent&amp;#039;;  -- col CDB exists but this is not one&lt;br /&gt;
        end if;&lt;br /&gt;
        if l_database_role like &amp;#039;%STANDBY%&amp;#039; then&lt;br /&gt;
            l_status := &amp;#039;Standby&amp;#039;;&lt;br /&gt;
        end if;&lt;br /&gt;
    exception&lt;br /&gt;
    when e_not_mounted then&lt;br /&gt;
        l_status := &amp;#039;Not Mounted&amp;#039;;&lt;br /&gt;
    when e_col_not_found then&lt;br /&gt;
        l_status := &amp;#039;pre12&amp;#039;;&lt;br /&gt;
    end;&lt;br /&gt;
&lt;br /&gt;
    dbms_output.put_line (&amp;#039;${db}&amp;#039;||&amp;#039;:&amp;#039;||l_status);&lt;br /&gt;
&lt;br /&gt;
end;&lt;br /&gt;
/&lt;br /&gt;
EOSQL&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Run a command or script on all databases in tnsnames.ora===&lt;br /&gt;
Very handy if you have a global tnsnames.ora accessible to all clients.&amp;lt;br /&amp;gt;&lt;br /&gt;
So from a client install, this has access to all databases.&amp;lt;br /&amp;gt;&lt;br /&gt;
Any files created can be created on the client so no need to scp to all the machines to recover spool files etc.&amp;lt;br /&amp;gt;&lt;br /&gt;
Downside: Cannot connect as sysdba across tns so password will need to be known for whatever user is used.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/ksh&lt;br /&gt;
TNSNAMES=&amp;quot;./tnsnames.ora&amp;quot;&lt;br /&gt;
[[ ! -r &amp;quot;${TNSNAMES}&amp;quot; ]] &amp;amp;&amp;amp; echo &amp;quot;${TNSNAMES} is not accessible&amp;quot; &amp;amp;&amp;amp; exit 1&lt;br /&gt;
&lt;br /&gt;
SIDLIST=$(perl -ne &amp;#039;print &amp;quot;$1\n&amp;quot; if /(?:SID|SERVICE_NAME)\s*=\s*(\S+?)\)/&amp;#039; ${TNSNAMES}|sort|uniq|xargs)&lt;br /&gt;
for SID in ${SIDLIST}&lt;br /&gt;
do&lt;br /&gt;
    echo &amp;quot;Processing $SID&amp;quot;&lt;br /&gt;
    ls -al | grep &amp;quot;^d&amp;quot; | grep &amp;quot;\_${SID}&amp;quot; &amp;gt;/dev/null&lt;br /&gt;
    if [[ $? -ne 0 ]]; then&lt;br /&gt;
        echo &amp;#039;exit&amp;#039; | sqlplus system/xxxxxx@${SID} @ReviewLite17.1.sql &amp;gt;/dev/null 2&amp;gt;&amp;amp;1&lt;br /&gt;
    else&lt;br /&gt;
        echo &amp;quot;directory already exists so must have done this SID&amp;quot;&lt;br /&gt;
    fi&lt;br /&gt;
done&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Run a command or script on all databases in oratab===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/usr/bin/ksh&lt;br /&gt;
# ==============================================================================&lt;br /&gt;
# Name         : all_db_do&lt;br /&gt;
# Description  : Loops over all the databases in oratab and executes the&lt;br /&gt;
#                specified SQL command - be careful!&lt;br /&gt;
#&lt;br /&gt;
# Parameters   : -v flag for verbose&lt;br /&gt;
#                [-f &amp;lt;filename&amp;gt; | &amp;lt;quoted SQL command to be executed&amp;gt;]&lt;br /&gt;
#&lt;br /&gt;
# Example      : all_db_do &amp;#039;alter system switch logfile;&amp;#039;&lt;br /&gt;
#                all_db_do -f sessions.sql&lt;br /&gt;
#&lt;br /&gt;
# Notes        : none&lt;br /&gt;
#&lt;br /&gt;
# Modification History&lt;br /&gt;
# ====================&lt;br /&gt;
# When      Who               What&lt;br /&gt;
# ========= ================= ==================================================&lt;br /&gt;
# 14-JAN-13 Stuart Barkley    Created&lt;br /&gt;
# 25-FEB-13 Stuart Barkley    Adapt for Solaris&lt;br /&gt;
# 21-MAR-13 Stuart Barkley    Check db is running first&lt;br /&gt;
# 29-APR-13 Stuart Barkley    Added verbose flag processing&lt;br /&gt;
# 24-MAY-13 Stuart Barkley    Wrap / as sysdba in quotes for older versions&lt;br /&gt;
# 23-JUN-16 Stuart Barkley    Add -f to run a file containing sql&lt;br /&gt;
# ==============================================================================&lt;br /&gt;
&lt;br /&gt;
PROGNAME=$(basename $0)&lt;br /&gt;
OS=$(uname -s)&lt;br /&gt;
&lt;br /&gt;
AWK=$(which awk)&lt;br /&gt;
GREP=$(which grep)&lt;br /&gt;
if [[ &amp;quot;${OS}&amp;quot; == &amp;quot;SunOS&amp;quot; ]]; then&lt;br /&gt;
    AWK=/usr/xpg4/bin/awk&lt;br /&gt;
    GREP=/usr/xpg4/bin/grep&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
if [[ ! -r /etc/oratab ]]; then&lt;br /&gt;
    if [[ &amp;quot;${OS}&amp;quot; == &amp;quot;SunOS&amp;quot; ]]; then&lt;br /&gt;
        echo &amp;quot;oratab is not where we want it. Please run &amp;#039;ln -s /var/opt/oracle/oratab /etc/oratab&amp;#039; as root and retry&amp;quot; &amp;amp;&amp;amp; exit 1&lt;br /&gt;
    else&lt;br /&gt;
        echo &amp;quot;Either Oracle is not installed or database is running without an oratab&amp;quot; &amp;amp;&amp;amp; exit 1&lt;br /&gt;
    fi&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
# -------------------------&lt;br /&gt;
# get the arguments, if any&lt;br /&gt;
# -------------------------&lt;br /&gt;
unset VERBOSE&lt;br /&gt;
while getopts &amp;quot;vf:&amp;quot; flag&lt;br /&gt;
do&lt;br /&gt;
    case &amp;quot;$flag&amp;quot; in&lt;br /&gt;
    v) VERBOSE=1;;&lt;br /&gt;
    f) FILE2RUN=$OPTARG;;&lt;br /&gt;
    esac&lt;br /&gt;
done&lt;br /&gt;
shift $((OPTIND-1))&lt;br /&gt;
&lt;br /&gt;
if [[ -z ${FILE2RUN} ]]; then&lt;br /&gt;
    # no file, need an SQL supplied&lt;br /&gt;
    if [[ -z $1 ]]; then&lt;br /&gt;
        echo &amp;quot;Usage: $0 [-v] [-f &amp;lt;filename&amp;gt; | &amp;lt;quoted SQL command to be executed&amp;gt;]&amp;quot;&lt;br /&gt;
        echo &amp;quot;eg: $0 -f sessions.sql&amp;quot;&lt;br /&gt;
        echo &amp;quot;eg: $0 &amp;#039;alter system switch logfile;&amp;#039;&amp;quot;&lt;br /&gt;
        exit 1&lt;br /&gt;
    fi&lt;br /&gt;
    SQL=$1&lt;br /&gt;
elif [[ -s ${FILE2RUN} ]]; then&lt;br /&gt;
    # file supplied and exists&lt;br /&gt;
    SQL=&amp;quot;@${FILE2RUN}&amp;quot;&lt;br /&gt;
else&lt;br /&gt;
    # file supplied, does it exist&lt;br /&gt;
    echo &amp;quot;File ${FILE2RUN} is empty or does not exist&amp;quot;&lt;br /&gt;
    echo &amp;quot;Usage: $0 [-v] [-f &amp;lt;filename&amp;gt; | &amp;lt;quoted SQL command to be executed&amp;gt;]&amp;quot;&lt;br /&gt;
    echo &amp;quot;eg: $0 -f sessions.sql&amp;quot;&lt;br /&gt;
    echo &amp;quot;eg: $0 &amp;#039;alter system switch logfile;&amp;#039;&amp;quot;&lt;br /&gt;
    exit 1&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
export ORAENV_ASK=NO&lt;br /&gt;
&lt;br /&gt;
for db in $(${AWK} -F: &amp;#039;NF &amp;amp;&amp;amp; $1 !~/[#*]/ {print $1}&amp;#039;  /etc/oratab)&lt;br /&gt;
do&lt;br /&gt;
    if ( [[ $1 != &amp;quot;startup&amp;quot; ]] &amp;amp;&amp;amp; [[ $(ps -ef | ${GREP} -c -E [o]ra_pmon_${db}) -eq 0 ]] ); then&lt;br /&gt;
        [[ ! -z &amp;quot;$VERBOSE&amp;quot; ]] &amp;amp;&amp;amp; echo &amp;quot;$db is not running, skipping...&amp;quot;&lt;br /&gt;
        continue&lt;br /&gt;
    fi&lt;br /&gt;
    echo&lt;br /&gt;
    [[ ! -z &amp;quot;$VERBOSE&amp;quot; ]] &amp;amp;&amp;amp; echo &amp;quot;vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv&amp;quot;&lt;br /&gt;
    [[ ! -z &amp;quot;$VERBOSE&amp;quot; ]] &amp;amp;&amp;amp; echo $db&lt;br /&gt;
    ORACLE_SID=$db&lt;br /&gt;
    . oraenv &amp;gt;/dev/null&lt;br /&gt;
    sqlplus -s &amp;quot;/ as sysdba&amp;quot; &amp;lt;&amp;lt;EOSQL&lt;br /&gt;
define SID=$ORACLE_SID&lt;br /&gt;
col comp_name format a50&lt;br /&gt;
col value for a40&lt;br /&gt;
set linesize 1000&lt;br /&gt;
set pagesize 100&lt;br /&gt;
$SQL&lt;br /&gt;
EOSQL&lt;br /&gt;
    [[ ! -z &amp;quot;$VERBOSE&amp;quot; ]] &amp;amp;&amp;amp; echo &amp;quot;^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^&amp;quot;&lt;br /&gt;
done&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
all_db_do &amp;quot;create or replace directory data_pump_dir as &amp;#039;/oracle/export/&amp;amp;SID&amp;#039;;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
all_db_do &amp;quot;archive log list&amp;quot;&lt;br /&gt;
&lt;br /&gt;
all_db_do &amp;quot;shutdown immediate&amp;quot;&lt;br /&gt;
&lt;br /&gt;
all_db_do &amp;#039;alter system set log_archive_dest_1=&amp;quot;location=/oracle/arch/&amp;amp;SID&amp;quot; scope=both;&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Run an SQL command on behalf of another user===&lt;br /&gt;
It can be used to execute any sql command as a specified user provided this procedure is created in sys schema.&amp;lt;br /&amp;gt;&lt;br /&gt;
* not got this working properly yet *&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set serveroutput on&lt;br /&gt;
create or replace procedure run_sql_as_user ( p_schema_name in varchar2&lt;br /&gt;
                                            , p_sql         in varchar2&lt;br /&gt;
                                            ) is&lt;br /&gt;
    l_user_id dba_users.user_id%type;&lt;br /&gt;
    l_cursor  number;&lt;br /&gt;
    l_rc      number;&lt;br /&gt;
begin&lt;br /&gt;
    dbms_output.enable(null);&lt;br /&gt;
    begin&lt;br /&gt;
        select u.user_id&lt;br /&gt;
        into   l_user_id&lt;br /&gt;
        from   dba_users u&lt;br /&gt;
        where  u.username = p_schema_name;&lt;br /&gt;
    exception&lt;br /&gt;
    when no_data_found then&lt;br /&gt;
        raise_application_error (-20001, &amp;#039;Cannot find user &amp;#039;||p_schema_name);&lt;br /&gt;
    end;&lt;br /&gt;
    l_cursor := dbms_sys_sql.open_cursor;&lt;br /&gt;
    dbms_sys_sql.parse_as_user ( c             =&amp;gt; l_cursor&lt;br /&gt;
                               , statement     =&amp;gt; p_sql&lt;br /&gt;
                               , language_flag =&amp;gt; dbms_sql.native&lt;br /&gt;
                               , userid        =&amp;gt; l_user_id&lt;br /&gt;
    );&lt;br /&gt;
    l_rc := dbms_sys_sql.execute(l_cursor);&lt;br /&gt;
    dbms_sys_sql.close_cursor(l_cursor);&lt;br /&gt;
exception&lt;br /&gt;
when others then&lt;br /&gt;
    raise_application_error (-20001, &amp;#039;ERROR: &amp;#039;||sqlerrm);&lt;br /&gt;
end;&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Run a script on all databases listed in tnsnames.ora===&lt;br /&gt;
Can run an SQL command file on all SID/SERVICE found in a tnsnames.ora file. I use this from a client laptop having a global tns file on it.&amp;lt;br /&amp;gt;&lt;br /&gt;
This way it&amp;#039;s not necessary to copy the file onto every host before executing it. Any files created by the script will be created on the client.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/ksh&lt;br /&gt;
&lt;br /&gt;
TNSNAMES=&amp;quot;./tnsnames.ora&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[ ! -r &amp;quot;${TNSNAMES}&amp;quot; ]] &amp;amp;&amp;amp; echo &amp;quot;${TNSNAMES} is not accessible&amp;quot; &amp;amp;&amp;amp; exit 1&lt;br /&gt;
&lt;br /&gt;
SIDLIST=$(perl -ne &amp;#039;print &amp;quot;$1\n&amp;quot; if /(?:SID|SERVICE_NAME)\s*=\s*(\S+?)\)/&amp;#039; ${TNSNAMES}|sort|uniq|xargs)&lt;br /&gt;
for SID in ${SIDLIST}&lt;br /&gt;
do&lt;br /&gt;
    echo &amp;quot;Processing $SID&amp;quot;&lt;br /&gt;
    ls -al | grep &amp;quot;^d&amp;quot; | grep &amp;quot;\_${SID}&amp;quot; &amp;gt;/dev/null&lt;br /&gt;
    if [[ $? -ne 0 ]]; then&lt;br /&gt;
        echo &amp;#039;exit&amp;#039; | sqlplus system/password@${SID} @ReviewLite17.1.sql &amp;gt;/dev/null 2&amp;gt;&amp;amp;1&lt;br /&gt;
    else&lt;br /&gt;
        echo &amp;quot;directory already exists so must have done this SID&amp;quot;&lt;br /&gt;
    fi&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===List invalid objects===&lt;br /&gt;
 set lines 200&lt;br /&gt;
 set pages 200&lt;br /&gt;
 col obj format a40&lt;br /&gt;
 select owner||&amp;#039;.&amp;#039;||object_name obj&lt;br /&gt;
 ,      object_type&lt;br /&gt;
 from   dba_objects&lt;br /&gt;
 where  1=1&lt;br /&gt;
 and    status = &amp;#039;INVALID&amp;#039;;&lt;br /&gt;
===Recompile all invalid objects===&lt;br /&gt;
@?/rdbms/admin/utlrp.sql&lt;br /&gt;
===See how much space is left in the flash recovery area (FRA)===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select name&lt;br /&gt;
,      to_char (space_limit, &amp;#039;999,999,999,999&amp;#039;) as space_limit&lt;br /&gt;
,      to_char (space_limit - space_used + space_reclaimable&lt;br /&gt;
,               &amp;#039;999,999,999,999&amp;#039;)&lt;br /&gt;
           as space_available&lt;br /&gt;
,      round ( (space_used - space_reclaimable) / space_limit * 100, 1)&lt;br /&gt;
           as pct_full&lt;br /&gt;
from   v$recovery_file_dest;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# ==============================================&lt;br /&gt;
# Check FRA to see how much space is reclaimable&lt;br /&gt;
# ==============================================&lt;br /&gt;
fra_reclaim_check() {&lt;br /&gt;
&lt;br /&gt;
LOGFILE=${RMAN_LogDir}/${ORACLE_SID}_`date &amp;#039;+%Y%m&amp;#039;`_${V_SCRIPT}.log&lt;br /&gt;
sqlplus &amp;quot;/ as sysdba&amp;quot; &amp;lt;&amp;lt;EOSQL &amp;gt; /tmp/results.$$&lt;br /&gt;
set vefify off echo off heading off newpage none linesize 1000 echo off&lt;br /&gt;
select &amp;#039;Filesystem:&amp;#039;||name||&lt;br /&gt;
       &amp;#039;; Total(Gb):&amp;#039;||round((space_limit/1073741824),2) ||&lt;br /&gt;
       &amp;#039;; Reclaimable(Gb):&amp;#039;||round((space_reclaimable/1073741824),2) ||&lt;br /&gt;
       &amp;#039;; Reclaimable(%):&amp;#039;||round( ((space_reclaimable/1073741824)/(space_limit/1073741824)*100),2 )&lt;br /&gt;
from   v$recovery_file_dest&lt;br /&gt;
/&lt;br /&gt;
EOSQL&lt;br /&gt;
cat /tmp/results.$$ &amp;gt;&amp;gt; $LOGFILE&lt;br /&gt;
rm /tmp/results.$$&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===How far back can we flashback?===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
col time_now              for a25&lt;br /&gt;
col time_oldest_flashback for a25&lt;br /&gt;
select to_char(sysdate,&amp;#039;DD-MON-YY HH24:MI&amp;#039;)                    time_now&lt;br /&gt;
,      to_char(fdl.oldest_flashback_time, &amp;#039;DD-MON-YY HH24:MI&amp;#039;) time_oldest_flashback&lt;br /&gt;
,      round((sysdate-fdl.oldest_flashback_time)*24,1)         hours_flashback_possible&lt;br /&gt;
from   v$database d&lt;br /&gt;
,      v$flashback_database_log fdl&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===DBA privs tables===&lt;br /&gt;
 DBA_AQ_AGENT_PRIVS&lt;br /&gt;
 DBA_COL_PRIVS&lt;br /&gt;
 DBA_PRIV_AUDIT_OPTS&lt;br /&gt;
 DBA_REPGROUP_PRIVILEGES&lt;br /&gt;
 DBA_ROLE_PRIVS&lt;br /&gt;
 DBA_RSRC_CONSUMER_GROUP_PRIVS&lt;br /&gt;
 DBA_RSRC_MANAGER_SYSTEM_PRIVS&lt;br /&gt;
 DBA_SYS_PRIVS&lt;br /&gt;
 DBA_TAB_PRIVS&lt;br /&gt;
 DBA_WM_SYS_PRIVS&lt;br /&gt;
 DBA_WORKSPACE_PRIVS&lt;br /&gt;
&lt;br /&gt;
===Schedule a shell job===&lt;br /&gt;
 begin&lt;br /&gt;
     dbms_scheduler.create_program ( program_name   =&amp;gt; &amp;#039;myshelljob&amp;#039;&lt;br /&gt;
                                   , program_action =&amp;gt; &amp;#039;/home/oracle/scripts/shell.sh&amp;#039;&lt;br /&gt;
                                   , program_type   =&amp;gt; &amp;#039;EXECUTABLE&amp;#039;&lt;br /&gt;
                                   , comments       =&amp;gt; &amp;#039;Run a shell&amp;#039;&lt;br /&gt;
                                   , enabled        =&amp;gt; TRUE&lt;br /&gt;
                                   );&lt;br /&gt;
 end;&lt;br /&gt;
 /&lt;br /&gt;
===Start the job===&lt;br /&gt;
 begin&lt;br /&gt;
     dbms_sheduler.create_job ( job_name     =&amp;gt; &amp;#039;myshelljob&amp;#039;&lt;br /&gt;
                              , program_name =&amp;gt; &amp;#039;myshelljob&amp;#039;&lt;br /&gt;
                              , start_date   =&amp;gt;&lt;br /&gt;
                              );&lt;br /&gt;
 /&lt;br /&gt;
&lt;br /&gt;
===What statement is a user running?===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select a.sid&lt;br /&gt;
,      a.serial#&lt;br /&gt;
,      b.sql_text&lt;br /&gt;
from   v$session a&lt;br /&gt;
,      v$sqlarea b&lt;br /&gt;
where  a.sql_address = b.address&lt;br /&gt;
and    a.username    = &amp;#039;&amp;amp;username&amp;#039;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===See what statements all users are running===&lt;br /&gt;
Useful to see what is happening when process limit is reached&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 300 pages 1000&lt;br /&gt;
&lt;br /&gt;
col username for a10&lt;br /&gt;
col command for 999 head &amp;quot;CMD&amp;quot;&lt;br /&gt;
col lockwait for a10&lt;br /&gt;
col status for a8&lt;br /&gt;
col schemaname for a12&lt;br /&gt;
col osuser for a10&lt;br /&gt;
col process for a10&lt;br /&gt;
col program for a20&lt;br /&gt;
col machine for a10&lt;br /&gt;
col action for a10&lt;br /&gt;
col module for a10&lt;br /&gt;
col identifier for a10&lt;br /&gt;
col event for a27&lt;br /&gt;
col state for a8&lt;br /&gt;
col service_name for a10&lt;br /&gt;
col serial# for 999999&lt;br /&gt;
&lt;br /&gt;
select a.username&lt;br /&gt;
,      a.command&lt;br /&gt;
,      a.lockwait&lt;br /&gt;
,      a.status&lt;br /&gt;
,      a.schemaname&lt;br /&gt;
,      a.osuser&lt;br /&gt;
,      a.process&lt;br /&gt;
,      a.machine&lt;br /&gt;
,      a.program&lt;br /&gt;
,      a.type&lt;br /&gt;
--,      a.sql_exec_start&lt;br /&gt;
--,      a.plsql_object_id&lt;br /&gt;
--,      a.plsql_subprogram_id&lt;br /&gt;
--,      a.module&lt;br /&gt;
--,      a.action&lt;br /&gt;
,      a.logon_time&lt;br /&gt;
,      a.event&lt;br /&gt;
,      a.wait_time&lt;br /&gt;
,      a.seconds_in_wait&lt;br /&gt;
,      a.state&lt;br /&gt;
--,      a.service_name&lt;br /&gt;
,      a.serial#&lt;br /&gt;
,      b.sql_text&lt;br /&gt;
from   v$session a&lt;br /&gt;
,      v$sqlarea b&lt;br /&gt;
where  a.sql_address = b.address&lt;br /&gt;
order  by a.logon_time desc&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
set lines 80&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===A logminer session===&lt;br /&gt;
Mine all SQL statements in a 10 minute period&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sqlplus / as sysdba&lt;br /&gt;
alter session set nls_date_format = &amp;#039;DD-MON-YYYY HH24:MI:SS&amp;#039;;&lt;br /&gt;
execute dbms_logmnr.start_logmnr ( starttime =&amp;gt; &amp;#039;27-OCT-2009 11:05:00&amp;#039;&lt;br /&gt;
                                 , endtime   =&amp;gt; &amp;#039;27-OCT-2009 11:15:00&amp;#039;&lt;br /&gt;
                                 , options   =&amp;gt; dbms_logmnr.dict_from_online_catalog+dbms_logmnr.continuous_mine&lt;br /&gt;
                                 );&lt;br /&gt;
create table mycontents as select * from v$logmnr_contents;&lt;br /&gt;
execute dbms_logmnr.end_logmnr(); &lt;br /&gt;
&lt;br /&gt;
select * from mycontents;&lt;br /&gt;
&lt;br /&gt;
drop table mycontents;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Huge Pages===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
#&lt;br /&gt;
# hugepages_settings.sh&lt;br /&gt;
#&lt;br /&gt;
# Linux bash script to compute values for the&lt;br /&gt;
# recommended HugePages/HugeTLB configuration&lt;br /&gt;
#&lt;br /&gt;
# Note: This script does calculation for all shared memory&lt;br /&gt;
# segments available when the script is run, no matter it&lt;br /&gt;
# is an Oracle RDBMS shared memory segment or not.&lt;br /&gt;
# Check for the kernel version&lt;br /&gt;
KERN=`uname -r | awk -F. &amp;#039;{ printf(&amp;quot;%d.%d\n&amp;quot;,$1,$2); }&amp;#039;`&lt;br /&gt;
# Find out the HugePage size&lt;br /&gt;
HPG_SZ=`grep Hugepagesize /proc/meminfo | awk {&amp;#039;print $2&amp;#039;}`&lt;br /&gt;
# Start from 1 pages to be on the safe side and guarantee 1 free HugePage&lt;br /&gt;
NUM_PG=1&lt;br /&gt;
# Cumulative number of pages required to handle the running shared memory segments&lt;br /&gt;
for SEG_BYTES in `ipcs -m | awk {&amp;#039;print $5&amp;#039;} | grep &amp;quot;[0-9][0-9]*&amp;quot;`&lt;br /&gt;
do&lt;br /&gt;
   MIN_PG=`echo &amp;quot;$SEG_BYTES/($HPG_SZ*1024)&amp;quot; | bc -q`&lt;br /&gt;
   if [ $MIN_PG -gt 0 ]; then&lt;br /&gt;
      NUM_PG=`echo &amp;quot;$NUM_PG+$MIN_PG+1&amp;quot; | bc -q`&lt;br /&gt;
   fi&lt;br /&gt;
done&lt;br /&gt;
# Finish with results&lt;br /&gt;
case $KERN in&lt;br /&gt;
   &amp;#039;2.4&amp;#039;) HUGETLB_POOL=`echo &amp;quot;$NUM_PG*$HPG_SZ/1024&amp;quot; | bc -q`;&lt;br /&gt;
          echo &amp;quot;Recommended setting: vm.hugetlb_pool = $HUGETLB_POOL&amp;quot; ;;&lt;br /&gt;
   &amp;#039;2.6&amp;#039; | &amp;#039;3.8&amp;#039;) echo &amp;quot;Recommended setting: vm.nr_hugepages = $NUM_PG&amp;quot; ;;&lt;br /&gt;
    *) echo &amp;quot;Unrecognized kernel version $KERN. Exiting.&amp;quot; ;;&lt;br /&gt;
esac&lt;br /&gt;
# End&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Pretty longops listing===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 2000 pages 1000&lt;br /&gt;
col opname for a34 head &amp;quot;Job&amp;quot;&lt;br /&gt;
col message for a60&lt;br /&gt;
col perc_done for a10 head &amp;quot;Done&amp;quot;&lt;br /&gt;
col started for a18&lt;br /&gt;
col killer for a15&lt;br /&gt;
col mins_busy head &amp;quot;Mins busy&amp;quot;&lt;br /&gt;
col mins_left head &amp;quot;Mins left&amp;quot;&lt;br /&gt;
select sid||&amp;#039;,&amp;#039;||serial#                       killer&lt;br /&gt;
,      opname&lt;br /&gt;
,      message&lt;br /&gt;
,      round ((sofar/totalwork),4)*100||&amp;#039;%&amp;#039;    perc_done&lt;br /&gt;
,      to_char(start_time,&amp;#039;DD-MON-YY HH24:MI&amp;#039;) started&lt;br /&gt;
,      floor(elapsed_seconds/60)               mins_busy&lt;br /&gt;
,      ceil(time_remaining/60)                 mins_left&lt;br /&gt;
from   v$session_longops&lt;br /&gt;
where  1=1&lt;br /&gt;
and    sofar     != totalwork&lt;br /&gt;
and    totalwork != 0&lt;br /&gt;
and    opname    like &amp;#039;RMAN%&amp;#039;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select * from v$session where module=&amp;#039;Data Pump Worker&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or attach to the impdp job and it shows percentage done.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Get the SID from v$session_longops and plug it into v$session to check the SQL command details.&lt;br /&gt;
&lt;br /&gt;
Current Running SQLs&lt;br /&gt;
--------------------&lt;br /&gt;
set pages 1000 lines 2000&lt;br /&gt;
col program  format a40&lt;br /&gt;
col sql_text format a130&lt;br /&gt;
&lt;br /&gt;
select s.sid&lt;br /&gt;
,      s.status&lt;br /&gt;
,      s.last_call_et&lt;br /&gt;
,      s.program&lt;br /&gt;
,      sa.sql_id&lt;br /&gt;
,      sa.sql_text&lt;br /&gt;
from   v$session s&lt;br /&gt;
,      v$sqlarea sa&lt;br /&gt;
where  s.sql_id = sa.sql_id&lt;br /&gt;
and    s.sid = &amp;#039;&amp;amp;sid&amp;#039;&lt;br /&gt;
/ &lt;br /&gt;
&lt;br /&gt;
set pages 1000 lines 2000&lt;br /&gt;
col USERNAME for a10&lt;br /&gt;
col OSUSER   for a10&lt;br /&gt;
col MACHINE  for a10&lt;br /&gt;
&lt;br /&gt;
select s.sid&lt;br /&gt;
,      s.serial#&lt;br /&gt;
,      p.spid&lt;br /&gt;
,      s.username&lt;br /&gt;
,      s.osuser&lt;br /&gt;
,      s.status&lt;br /&gt;
,      s.process fg_pid&lt;br /&gt;
,      s.longon_time&lt;br /&gt;
,      s.machine&lt;br /&gt;
,      p.spid bg_pid&lt;br /&gt;
from   gv$session s&lt;br /&gt;
,      gv$process p&lt;br /&gt;
where  s.addr = p.addr&lt;br /&gt;
and    s.sid  = &amp;#039;&amp;amp;sid&amp;#039;&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
$ps -ef | grep &amp;lt;spid&amp;gt;&lt;br /&gt;
&lt;br /&gt;
set pages 1000 lines 2000&lt;br /&gt;
SELECT INST_ID&lt;br /&gt;
,      SID&lt;br /&gt;
,      SERIAL#&lt;br /&gt;
,      SQL_ID&lt;br /&gt;
,      USERNAME&lt;br /&gt;
,      PROGRAM&lt;br /&gt;
,      MACHINE&lt;br /&gt;
,      SERVICE_NAME&lt;br /&gt;
FROM   GV$SESSION&lt;br /&gt;
WHERE  SID IN (&amp;#039;&amp;lt;SID_NO.1&amp;gt;&amp;#039;,&amp;#039;&amp;lt;SID_NO.2&amp;gt;&amp;#039;)&lt;br /&gt;
/&lt;br /&gt;
Active Running SQLs&lt;br /&gt;
--------------------&lt;br /&gt;
set pages 1000 lines 2000&lt;br /&gt;
col SPID     for a10&lt;br /&gt;
col PROGRAM  for a15&lt;br /&gt;
col OSUSER   for a10&lt;br /&gt;
col ACTION   for a10&lt;br /&gt;
col EVENT    for a25&lt;br /&gt;
col SQL_TEXT for a25&lt;br /&gt;
col MACHINE  for a10&lt;br /&gt;
col P1TEXT   for a10 &lt;br /&gt;
col P2TEXT   for a10&lt;br /&gt;
col P3TEXT   for a10  &lt;br /&gt;
SELECT b.sid&lt;br /&gt;
,      b.serial#&lt;br /&gt;
,      a.spid&lt;br /&gt;
,      b.sql_id&lt;br /&gt;
,      b.program&lt;br /&gt;
,      b.osuser&lt;br /&gt;
,      b.machine&lt;br /&gt;
,      b.type&lt;br /&gt;
,      b.event&lt;br /&gt;
,      b.action&lt;br /&gt;
,      b.p1text&lt;br /&gt;
,      b.p2text&lt;br /&gt;
,      b.p3text&lt;br /&gt;
,      b.state&lt;br /&gt;
,      c.sql_text&lt;br /&gt;
,      b.logon_time&lt;br /&gt;
FROM   v$process a&lt;br /&gt;
,      v$session b&lt;br /&gt;
,      v$sqltext c&lt;br /&gt;
WHERE  a.addr           = b.paddr&lt;br /&gt;
AND    b.sql_hash_value = c.hash_value&lt;br /&gt;
AND    b.STATUS         = &amp;#039;ACTIVE&amp;#039;&lt;br /&gt;
AND    b.sid            = &amp;#039;&amp;amp;sid&amp;#039;&lt;br /&gt;
ORDER  BY a.spid&lt;br /&gt;
,      c.piece&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
OR - Use the below Query &lt;br /&gt;
&lt;br /&gt;
Longops.sql&lt;br /&gt;
----------- &lt;br /&gt;
set pages 50000 lines 32767&lt;br /&gt;
col OPNAME for a10&lt;br /&gt;
col SID form 9999&lt;br /&gt;
col SERIAL form 9999999&lt;br /&gt;
col PROGRAM for a10&lt;br /&gt;
col USERNAME for a10&lt;br /&gt;
col SQL_TEXT for a40&lt;br /&gt;
col START_TIME for a10&lt;br /&gt;
col LAST_UPDATE_TIME for a10&lt;br /&gt;
col TARGET for a25&lt;br /&gt;
col MESSAGE for a25&lt;br /&gt;
&lt;br /&gt;
alter session set nls_date_format = &amp;#039;DD-MM-YYYY HH24:MI:SS&amp;#039;;&lt;br /&gt;
&lt;br /&gt;
SELECT l.inst_id,l.sid, l.serial#, l.sql_id, l.opname, l.username, l.target, l.sofar, l.totalwork, l.start_time,l.last_update_time,round(l.time_remaining/60,2) &amp;quot;REMAIN MINS&amp;quot;, round(l.elapsed_seconds/60,2) &amp;quot;ELAPSED MINS&amp;quot;, round((l.time_remaining+l.elapsed_seconds)/60,2) &amp;quot;TOTAL MINS&amp;quot;, ROUND(l.SOFAR/l.TOTALWORK*100,2) &amp;quot;%_COMPLETE&amp;quot;, l.message,s.sql_text &lt;br /&gt;
FROM gv$session_longops l &lt;br /&gt;
LEFT OUTER JOIN v$sql s on s.hash_value=l.sql_hash_value and s.address=l.sql_address and s.child_number=0&lt;br /&gt;
WHERE l.OPNAME NOT LIKE &amp;#039;RMAN%&amp;#039; AND l.OPNAME NOT LIKE &amp;#039;%aggregate%&amp;#039; AND l.TOTALWORK != 0 AND l.sofar&amp;lt;&amp;gt;l.totalwork AND l.time_remaining &amp;gt; 0&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Apply the database patch after the ORACLE_HOME has been patched===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ORAENV_ASK=NO&lt;br /&gt;
export ORACLE_SID=$1&lt;br /&gt;
. oraenv&lt;br /&gt;
&lt;br /&gt;
sqlplus /nolog &amp;lt;&amp;lt;EOSQL&lt;br /&gt;
connect / as sysdba&lt;br /&gt;
startup&lt;br /&gt;
@?/rdbms/admin/catbundle.sql psu apply&lt;br /&gt;
@?/rdbms/admin/utlrp.sql&lt;br /&gt;
purge dba_recyclebin;&lt;br /&gt;
&lt;br /&gt;
prompt check patch apply...&lt;br /&gt;
set lines 150&lt;br /&gt;
col action_time for a50&lt;br /&gt;
col comp_name for a50&lt;br /&gt;
col comments for a50&lt;br /&gt;
&lt;br /&gt;
select action_time,action,comments from sys.registry\$history where trunc(action_time) = trunc(sysdate);&lt;br /&gt;
select comp_name,version,status,modified from dba_registry;&lt;br /&gt;
exit&lt;br /&gt;
EOSQL&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Show how much archivelog data is generated per day===&lt;br /&gt;
A companion script for &amp;#039;how many log switches in a day&amp;#039;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
col orderby noprint&lt;br /&gt;
select trunc(first_time) orderby&lt;br /&gt;
,      to_char(first_time,&amp;#039;DD-MON-YYYY&amp;#039;) &amp;quot;Date&amp;quot;&lt;br /&gt;
,      round(sum(bytes/1024/1024/1024),2) arch_logs_gigs&lt;br /&gt;
from (&lt;br /&gt;
    select unique (blocks * block_size) bytes,&lt;br /&gt;
    thread#,&lt;br /&gt;
    sequence#,&lt;br /&gt;
    resetlogs_change#,&lt;br /&gt;
    first_time&lt;br /&gt;
    from v$archived_log&lt;br /&gt;
)&lt;br /&gt;
group by trunc(first_time)&lt;br /&gt;
,      to_char(first_time, &amp;#039;DD-MON-YYYY&amp;#039;)&lt;br /&gt;
order by trunc(first_time) desc&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Abort a hanging database even when sysdba cannot connect===&lt;br /&gt;
Unable to connect to database with sqlplus / as sysdba because audit file cannot be created?&lt;br /&gt;
* [http://tech.e2sn.com/oracle/troubleshooting/hang/how-to-log-on-even-when-sysdba-can-t-do-so tech.e2sn.com]&lt;br /&gt;
* [http://blog.dbi-services.com/oracle-is-hanging-dont-forget-hanganalyze-and-systemstate/ blog.dbi-services.com]&lt;br /&gt;
Instead of just killing the pmon process, there is a kinder (and more useful) way to kill the database.&amp;lt;br /&amp;gt;&lt;br /&gt;
Use the hidden, undocumented &amp;#039;prelim&amp;#039; switch parameter to sqlplus to make a connection to the database without creating SGA session data structures.&amp;lt;br /&amp;gt;&lt;br /&gt;
It can be very useful for hang analysis so the possible cause can be found after the database has been restarted.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sqlplus -prelim / as sysdba&lt;br /&gt;
oradebug unlimit&lt;br /&gt;
oradebug hanganalyze 3&lt;br /&gt;
oradebug setmypid              -- or oradebug setorapname diag&lt;br /&gt;
oradebug dump ashdumpseconds 30&lt;br /&gt;
oradebug dump systemstate 10   -- or oradebug dump systemstate 266&lt;br /&gt;
oradebug tracefile_name&lt;br /&gt;
shutdown abort&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Lists Oracle session with kill session statement all ready to go===&lt;br /&gt;
disconnect attempts to kill the o/s processes too. kill doesn&amp;#039;t.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
col killer for a60&lt;br /&gt;
col osuser for a12&lt;br /&gt;
col logon  for a23&lt;br /&gt;
col spid   for a8&lt;br /&gt;
col username for a15&lt;br /&gt;
col program for a50&lt;br /&gt;
set lines 2000&lt;br /&gt;
select &amp;#039;alter system disconnect session &amp;#039;&amp;#039;&amp;#039;||s.sid||&amp;#039;,&amp;#039;||s.serial#||&amp;#039;&amp;#039;&amp;#039; immediate;&amp;#039; killer&lt;br /&gt;
,      s.inst_id&lt;br /&gt;
,      to_char(s.logon_time,&amp;#039;DD-MON-YY HH24:MI:SS&amp;#039;) logon&lt;br /&gt;
,      sci.osuser&lt;br /&gt;
,      p.spid&lt;br /&gt;
,      s.username&lt;br /&gt;
,      s.program&lt;br /&gt;
from   gv$session s&lt;br /&gt;
,      gv$session_connect_info sci&lt;br /&gt;
,      gv$process p&lt;br /&gt;
where  1=1&lt;br /&gt;
and    p.addr     = s.paddr&lt;br /&gt;
and    p.inst_id  = s.inst_id&lt;br /&gt;
and    s.sid      = sci.sid&lt;br /&gt;
and    s.serial#  = sci.serial#&lt;br /&gt;
and    s.type    != &amp;#039;BACKGROUND&amp;#039;&lt;br /&gt;
and    sci.osuser = &amp;#039;oraibm&amp;#039;&lt;br /&gt;
order  by s.logon_time desc&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
KILLER                                                          INST_ID LOGON                   OSUSER       SPID     USERNAME        PROGRAM&lt;br /&gt;
------------------------------------------------------------ ---------- ----------------------- ------------ -------- --------------- --------------------------------------------------&lt;br /&gt;
alter system disconnect session &amp;#039;490,33947&amp;#039; immediate;                1 23-JUN-16 13:30:53      oraibm       23205    SYS             sqlplus@benouerp07 (TNS V1-V3)&lt;br /&gt;
alter system disconnect session &amp;#039;490,33947&amp;#039; immediate;                1 23-JUN-16 13:30:53      oraibm       23205    SYS             sqlplus@benouerp07 (TNS V1-V3)&lt;br /&gt;
alter system disconnect session &amp;#039;490,33947&amp;#039; immediate;                1 23-JUN-16 13:30:53      oraibm       23205    SYS             sqlplus@benouerp07 (TNS V1-V3)&lt;br /&gt;
alter system disconnect session &amp;#039;490,33947&amp;#039; immediate;                1 23-JUN-16 13:30:53      oraibm       23205    SYS             sqlplus@benouerp07 (TNS V1-V3)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===How much space is being used by a guaranteed restore point?===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
show parameter recovery&lt;br /&gt;
set numwi 15&lt;br /&gt;
set lines 200&lt;br /&gt;
col name for a40&lt;br /&gt;
col time for a23&lt;br /&gt;
col gigs_limit head &amp;quot;Max (but check df -g also!)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
select name&lt;br /&gt;
,      time&lt;br /&gt;
,      round(storage_size/1024/1024/1024,2) gigs_used&lt;br /&gt;
from   v$restore_point&lt;br /&gt;
where  1=1&lt;br /&gt;
and    guarantee_flashback_database = &amp;#039;YES&amp;#039;&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
select * from v$flash_recovery_area_usage&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
select name&lt;br /&gt;
,      round(space_used/1024/1024/1024,2) gigs_used&lt;br /&gt;
,      round(space_limit/1024/1024/1024,2) gigs_limit&lt;br /&gt;
,      space_reclaimable&lt;br /&gt;
,      number_of_files&lt;br /&gt;
from v$recovery_file_dest&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Get statistics for LOB columns in a table===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select &lt;br /&gt;
  max(dbms_lob.getlength(lob_content)) max_len&lt;br /&gt;
, avg(dbms_lob.getlength(lob_content)) avg_len&lt;br /&gt;
, min(dbms_lob.getlength(lob_content)) min_len&lt;br /&gt;
, sum(case when dbms_lob.getlength(lob_content) &amp;lt;= 4000 then 1&lt;br /&gt;
else 0 end) &amp;quot;&amp;lt;4k&amp;quot;&lt;br /&gt;
, sum(case when dbms_lob.getlength(lob_content) &amp;gt; 4000 then 1&lt;br /&gt;
else 0 end) &amp;quot;&amp;gt;4k&amp;quot;&lt;br /&gt;
, sum(case when dbms_lob.getlength(lob_content) is null then 1 else&lt;br /&gt;
0 end) &amp;quot;is null&amp;quot;&lt;br /&gt;
from &amp;amp;tablename&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===badprivs.sql===&lt;br /&gt;
Check to see if any ordinary users have privileges / access / grants / rights they should not have&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select grantee, privilege, admin_option&lt;br /&gt;
from   sys.dba_sys_privs&lt;br /&gt;
where  (       privilege like &amp;#039;% ANY %&amp;#039;&lt;br /&gt;
        or     privilege in (&amp;#039;BECOME USER&amp;#039;, &amp;#039;UNLIMITED TABLESPACE&amp;#039;)&lt;br /&gt;
        or     admin_option = &amp;#039;YES&amp;#039;&lt;br /&gt;
       )&lt;br /&gt;
and    grantee not in (&amp;#039;SYS&amp;#039;, &amp;#039;SYSTEM&amp;#039;, &amp;#039;OUTLN&amp;#039;, &amp;#039;AQ_ADMINISTRATOR_ROLE&amp;#039;,&lt;br /&gt;
                      &amp;#039;DBA&amp;#039;, &amp;#039;EXP_FULL_DATABASE&amp;#039;, &amp;#039;IMP_FULL_DATABASE&amp;#039;,&lt;br /&gt;
                      &amp;#039;OEM_MONITOR&amp;#039;, &amp;#039;CTXSYS&amp;#039;, &amp;#039;DBSNMP&amp;#039;, &amp;#039;IFSSYS&amp;#039;,&lt;br /&gt;
                      &amp;#039;IFSSYS$CM&amp;#039;, &amp;#039;MDSYS&amp;#039;, &amp;#039;ORDPLUGINS&amp;#039;, &amp;#039;ORDSYS&amp;#039;,&lt;br /&gt;
                      &amp;#039;TIMESERIES_DBA&amp;#039;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Generate a list of tablespaces ready for a migration===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set echo off&lt;br /&gt;
set lines 300&lt;br /&gt;
set pages 0&lt;br /&gt;
Set headi off&lt;br /&gt;
set feedb off&lt;br /&gt;
set long 32000&lt;br /&gt;
&lt;br /&gt;
spool migration_create_target_tablespaces.sql&lt;br /&gt;
&lt;br /&gt;
exec dbms_metadata.set_transform_param(dbms_metadata.session_transform,&amp;#039;SQLTERMINATOR&amp;#039;,TRUE);&lt;br /&gt;
select DBMS_METADATA.GET_DDL(&amp;#039;TABLESPACE&amp;#039;,tablespace_name) from dba_tablespaces&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
spool off&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===List the privileges assigned to users on directories===&lt;br /&gt;
table_name is the name of the directory...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select grantor&lt;br /&gt;
,      grantee&lt;br /&gt;
,      table_schema&lt;br /&gt;
,      table_name&lt;br /&gt;
,      privilege&lt;br /&gt;
from   all_tab_privs&lt;br /&gt;
where  table_name = &amp;#039;DATA_PUMP_DIR&amp;#039;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===List the privileges assigned to users on packages/procedures===&lt;br /&gt;
table_name is the name of the package...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select grantor&lt;br /&gt;
,      grantee&lt;br /&gt;
,      table_schema&lt;br /&gt;
,      table_name&lt;br /&gt;
,      privilege&lt;br /&gt;
from   all_tab_privs&lt;br /&gt;
where  upper(table_name) like upper(&amp;#039;%UTL_FILE%&amp;#039;)&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===List the system privileges assigned to a user (used to copy user as or clone user as)===&lt;br /&gt;
Maybe this one is better [[Extract ddl with &amp;quot;dbms metadata.get ddl&amp;quot;]]&lt;br /&gt;
&lt;br /&gt;
 SELECT LPAD(&amp;#039; &amp;#039;, 2*level) || granted_role &amp;quot;USER PRIVS&amp;quot;&lt;br /&gt;
 FROM (&lt;br /&gt;
   SELECT NULL grantee,  username granted_role&lt;br /&gt;
   FROM dba_users&lt;br /&gt;
   WHERE username LIKE UPPER(&amp;#039;%&amp;amp;uname%&amp;#039;)&lt;br /&gt;
   UNION&lt;br /&gt;
   SELECT grantee, granted_role&lt;br /&gt;
   FROM dba_role_privs&lt;br /&gt;
   UNION&lt;br /&gt;
   SELECT grantee, privilege&lt;br /&gt;
   FROM dba_sys_privs)&lt;br /&gt;
 START WITH grantee IS NULL&lt;br /&gt;
 CONNECT BY grantee = prior granted_role;&lt;br /&gt;
&lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
 SELECT path&lt;br /&gt;
 FROM (&lt;br /&gt;
   SELECT grantee,&lt;br /&gt;
          sys_connect_by_path(privilege, &amp;#039;:&amp;#039;)||&amp;#039;:&amp;#039;||grantee path&lt;br /&gt;
   FROM (&lt;br /&gt;
     SELECT grantee, privilege, 0 role&lt;br /&gt;
     FROM dba_sys_privs&lt;br /&gt;
     UNION ALL&lt;br /&gt;
     SELECT grantee, granted_role, 1 role&lt;br /&gt;
     FROM dba_role_privs)&lt;br /&gt;
   CONNECT BY privilege=prior grantee&lt;br /&gt;
   START WITH role = 0)&lt;br /&gt;
 WHERE grantee IN (&lt;br /&gt;
    SELECT username&lt;br /&gt;
    FROM dba_users&lt;br /&gt;
    WHERE lock_date IS NULL&lt;br /&gt;
    AND password != &amp;#039;EXTERNAL&amp;#039;&lt;br /&gt;
    AND username != &amp;#039;SYS&amp;#039;)&lt;br /&gt;
 OR grantee=&amp;#039;PUBLIC&amp;#039;&lt;br /&gt;
&lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
for a migration from 10g...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set headi off&lt;br /&gt;
set feedb off&lt;br /&gt;
set long  9999999&lt;br /&gt;
set pages 0&lt;br /&gt;
set lines 300&lt;br /&gt;
&lt;br /&gt;
spool migration_create_target_users_grants.sql&lt;br /&gt;
&lt;br /&gt;
select dbms_metadata.get_ddl(&amp;#039;USER&amp;#039;, username) || &amp;#039;;&amp;#039; ddl&lt;br /&gt;
from dba_users&lt;br /&gt;
where  1=1&lt;br /&gt;
and    username like upper(&amp;#039;%&amp;amp;&amp;amp;USER_NAME%&amp;#039;)&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
select &amp;#039;grant &amp;#039;||privilege|| &amp;#039; to &amp;#039; || grantee || &amp;#039;;&amp;#039;&lt;br /&gt;
from   dba_sys_privs&lt;br /&gt;
where  1=1&lt;br /&gt;
and    grantee like upper(&amp;#039;%&amp;amp;&amp;amp;USER_NAME%&amp;#039;)&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
select &amp;#039;grant &amp;#039;||granted_role|| &amp;#039; to &amp;#039; || grantee || &amp;#039;;&amp;#039;&lt;br /&gt;
from   dba_role_privs&lt;br /&gt;
where  1=1&lt;br /&gt;
and    grantee like upper(&amp;#039;%&amp;amp;&amp;amp;USER_NAME%&amp;#039;)&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
spool off&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or for a migration on 11g...!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set head off&lt;br /&gt;
set pages 0&lt;br /&gt;
set long 9999999&lt;br /&gt;
col ddl for a1000&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
SELECT DBMS_METADATA.GET_DDL(&amp;#039;USER&amp;#039;, USERNAME) || &amp;#039;;&amp;#039; DDL&lt;br /&gt;
FROM DBA_USERS&lt;br /&gt;
where  1=1&lt;br /&gt;
and    default_tablespace not in (&amp;#039;SYSTEM&amp;#039;,&amp;#039;SYSAUX&amp;#039;)&lt;br /&gt;
and    upper(username) like &amp;#039;%&amp;#039;||upper(&amp;#039;&amp;amp;&amp;amp;username&amp;#039;)||&amp;#039;%&amp;#039;&lt;br /&gt;
UNION ALL&lt;br /&gt;
SELECT DBMS_METADATA.GET_GRANTED_DDL(&amp;#039;ROLE_GRANT&amp;#039;, USERNAME) || &amp;#039;;&amp;#039; DDL&lt;br /&gt;
FROM DBA_USERS&lt;br /&gt;
where  1=1&lt;br /&gt;
and    default_tablespace not in (&amp;#039;SYSTEM&amp;#039;,&amp;#039;SYSAUX&amp;#039;)&lt;br /&gt;
and    upper(username) like &amp;#039;%&amp;#039;||upper(&amp;#039;&amp;amp;&amp;amp;username&amp;#039;)||&amp;#039;%&amp;#039;&lt;br /&gt;
UNION ALL&lt;br /&gt;
SELECT DBMS_METADATA.GET_GRANTED_DDL(&amp;#039;SYSTEM_GRANT&amp;#039;, USERNAME) || &amp;#039;;&amp;#039; DDL&lt;br /&gt;
FROM DBA_USERS&lt;br /&gt;
where  1=1&lt;br /&gt;
and    default_tablespace not in (&amp;#039;SYSTEM&amp;#039;,&amp;#039;SYSAUX&amp;#039;)&lt;br /&gt;
and    upper(username) like &amp;#039;%&amp;#039;||upper(&amp;#039;&amp;amp;&amp;amp;username&amp;#039;)||&amp;#039;%&amp;#039;&lt;br /&gt;
UNION ALL&lt;br /&gt;
SELECT DBMS_METADATA.GET_GRANTED_DDL(&amp;#039;OBJECT_GRANT&amp;#039;, USERNAME) || &amp;#039;;&amp;#039; DDL&lt;br /&gt;
FROM DBA_USERS&lt;br /&gt;
where  1=1&lt;br /&gt;
and    default_tablespace not in (&amp;#039;SYSTEM&amp;#039;,&amp;#039;SYSAUX&amp;#039;)&lt;br /&gt;
and    upper(username) like &amp;#039;%&amp;#039;||upper(&amp;#039;&amp;amp;&amp;amp;username&amp;#039;)||&amp;#039;%&amp;#039;&lt;br /&gt;
&lt;br /&gt;
spool migration_create_users_grants.sql&lt;br /&gt;
/&lt;br /&gt;
spool off&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Move datafiles between filesystems===&lt;br /&gt;
* [https://blogs.oracle.com/alejandrovargas/moving-a-datafile-from-file-system-to-asm Moving a datafile from File System to ASM (does not have to be ASM!) - oracle.com]&lt;br /&gt;
* [https://docs.oracle.com/database/121/OSTMG/GUID-3B8D0956-0888-452D-A9E4-9FB8D98577E0.htm#OSTMG89997 Moving Data Files Between Oracle ASM (does not have to be ASM!) Using RMAN - oracle.com]&lt;br /&gt;
* [https://oracle-base.com/articles/misc/renaming-or-moving-oracle-files Moving a data file online between filesystems - oracle-base.com]&lt;br /&gt;
====Set the relevant datafile offline====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter database datafile 125 offline;&lt;br /&gt;
alter database datafile 126 offline;&lt;br /&gt;
alter database datafile 127 offline;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Rename the files on the filesystem using o/s commands====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter tablespace ts_thaler_data_offline;&lt;br /&gt;
&lt;br /&gt;
host mv &amp;#039;/cln/tst/ora_data1/clnt/data4/ts_thaler_data_113.dbf&amp;#039; &amp;#039;/cln/tst/ora_data1/clnt/data1/ts_thaler_data_113.dbf&amp;#039;&lt;br /&gt;
host mv &amp;#039;/cln/tst/ora_data1/clnt/data4/ts_thaler_data_114.dbf&amp;#039; &amp;#039;/cln/tst/ora_data1/clnt/data1/ts_thaler_data_114.dbf&amp;#039;&lt;br /&gt;
host mv &amp;#039;/cln/tst/ora_data1/clnt/data4/ts_thaler_data_115.dbf&amp;#039; &amp;#039;/cln/tst/ora_data1/clnt/data1/ts_thaler_data_115.dbf&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Run the relevant alter commands to inform the control files of the new locations====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter database move datafile &amp;#039;/cln/tst/ora_data1/clnt/data4/ts_thaler_data_113.dbf&amp;#039; to &amp;#039;/cln/tst/ora_data1/clnt/data1/ts_thaler_data_113.dbf&amp;#039;&lt;br /&gt;
alter database move datafile &amp;#039;/cln/tst/ora_data1/clnt/data4/ts_thaler_data_114.dbf&amp;#039; to &amp;#039;/cln/tst/ora_data1/clnt/data1/ts_thaler_data_114.dbf&amp;#039;&lt;br /&gt;
alter database move datafile &amp;#039;/cln/tst/ora_data1/clnt/data4/ts_thaler_data_115.dbf&amp;#039; to &amp;#039;/cln/tst/ora_data1/clnt/data1/ts_thaler_data_115.dbf&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Recover the datafiles====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
recover datafile 125;&lt;br /&gt;
recover datafile 126;&lt;br /&gt;
recover datafile 127;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Set the relevant datafile online====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter database datafile 125 online;&lt;br /&gt;
alter database datafile 126 online;&lt;br /&gt;
alter database datafile 127 online;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Check all is well with the datafiles by using an appropriate statement====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 2000 pages 100&lt;br /&gt;
select file_id, file_name, status, online_status from dba_data_files where tablespace_name = &amp;#039;TS_THALER_DATA&amp;#039; order by 2;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Rename a datafile on 12c====&lt;br /&gt;
If you&amp;#039;re lucky enough to be on 12c, it&amp;#039;s one command - no need to offline the datafile!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SQL&amp;gt; alter database move datafile &amp;#039;/oracle/ora_data2/prod/data4/ts_thaler_data_113.dbf&amp;#039; to &amp;#039;/oracle/ora_data2/prod/data3/ts_thaler_data_113.dbf&amp;#039;;&lt;br /&gt;
&lt;br /&gt;
Database altered.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Pass parameter/argument into perl one-liner script from shell===&lt;br /&gt;
Trick? Just use ARGV to pass them in...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
FREQ=$(perl -e &amp;#039;my @CAL=split(&amp;quot;;&amp;quot;,$ARGV[0]);shift @CAL;print $CAL[$ARGV[1]];&amp;#039; -- &amp;quot;$LINE&amp;quot; $offset)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
DUMP_DATE=`perl -MTime::Local -e &amp;#039;print(timelocal(0,$ARGV[0],$ARGV[1],$ARGV[2],$ARGV[3],$ARGV[4]))&amp;#039; -- $MI $HH $DD $MM $YYYY`&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or export the variable from shell and access it via the ENV hash&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
export db=ENDP1&lt;br /&gt;
perl -p -i -e &amp;#039;s!DSMI_LOG.+$!DSMI_LOG           /oracle/$ENV{db}/admin/tdpoerror_$ENV{db}!&amp;#039; ${db}/admin/tdpo.opt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Return epoch seconds in Perl===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
perl -e &amp;#039;print time();&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or to convert a specific day of the year to epoch seconds&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
use POSIX;&lt;br /&gt;
my $epochsecs = mktime(0,0,0, $jday, 0, $year-1900);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or for a specific date (careful though - month is 0-11 not 1-12!...&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
use Time::Local;&lt;br /&gt;
#                          SS MM HH DD MM YYYY&lt;br /&gt;
my $epochsecs = timelocal (30,10,19,03,04,2014);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or more long-winded but delimited by anything...&amp;lt;br /&amp;gt;&lt;br /&gt;
Supply the date/time in any delimited format. Eg. YYYY-MM-DD:HH:MI&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/usr/bin/perl -w&lt;br /&gt;
use Time::Local;&lt;br /&gt;
&lt;br /&gt;
sub date2epoch { &lt;br /&gt;
  my($s) = @_;&lt;br /&gt;
  my($year, $month, $day, $hour, $minute, $second);&lt;br /&gt;
&lt;br /&gt;
  if($s =~ m{^\s*(\d{1,4})\W*0*(\d{1,2})\W*0*(\d{1,2})\W*0*&lt;br /&gt;
                 (\d{0,2})\W*0*(\d{0,2})\W*0*(\d{0,2})}x) {&lt;br /&gt;
    $year = $1;  $month = $2;   $day = $3;&lt;br /&gt;
    $hour = $4;  $minute = $5;  $second = $6;&lt;br /&gt;
    $hour |= 0;  $minute |= 0;  $second |= 0;  # defaults.&lt;br /&gt;
    $year = ($year&amp;lt;100 ? ($year&amp;lt;70 ? 2000+$year : 1900+$year) : $year);&lt;br /&gt;
    return timelocal($second,$minute,$hour,$day,$month-1,$year);  &lt;br /&gt;
  }&lt;br /&gt;
  return -1;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Return epoch seconds in DOS/VBS/Windows===&lt;br /&gt;
Paste this code into epoch.vbs&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
function date2epoch(p_date)&lt;br /&gt;
    date2epoch = DateDiff(&amp;quot;s&amp;quot;, &amp;quot;01/01/1970 00:00:00&amp;quot;, p_date)&lt;br /&gt;
end function&lt;br /&gt;
&lt;br /&gt;
Wscript.Echo date2epoch(Now())&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
and call from a DOS box like this&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cscript //nologo epoch.vbs&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Return date from epoch seconds in Perl===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
perl -e &amp;#039;print scalar (localtime (1243269270))&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Return epoch seconds from julian day number in Perl===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
use POSIX;&lt;br /&gt;
my ($year, $jday) = (2012,60);&lt;br /&gt;
my $epochsecs = mktime(0,0,0, $jday, 0, $year-1900);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Extract specific pieces of a date from an epoch timestamp in Perl===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
use POSIX;&lt;br /&gt;
# return localtime into an array&lt;br /&gt;
my @tm = localtime $epochsecs;&lt;br /&gt;
&lt;br /&gt;
my $yyyymmdd = strftime &amp;quot;%Y%m%d&amp;quot;, @tm;&lt;br /&gt;
print $yyyymmdd.&amp;quot;\n&amp;quot;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Return epoch seconds in Shell (linux)===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
date -d &amp;quot;2014/04/03 18:34:30&amp;quot; &amp;quot;+%s&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Return date from epoch seconds in Shell (linux)===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
date -d @1396542870&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Return epoch seconds in PL/SQL===&lt;br /&gt;
You cannot just use sysdate as that is timezone sensitive... (epoch seconds are in UTC/GMT)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select round((cast(sys_extract_utc(systimestamp) as date) - to_date(&amp;#039;01-JAN-1970 00:00:00&amp;#039;,&amp;#039;DD-MON-YYYY HH24:MI:SS&amp;#039;))*24*60*60) from dual;&lt;br /&gt;
or&lt;br /&gt;
select round((vd.created - to_date(&amp;#039;01-JAN-1970 00:00:00&amp;#039;,&amp;#039;DD-MON-YYYY HH24:MI:SS&amp;#039;))*24*60*60)  created from v$database vd;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
How long has this instance been up (in minutes)?&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select round((cast(sys_extract_utc(systimestamp) as date) - startup_time)*24*60) up_mins from v$instance;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Return date from epoch seconds in SQL===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select to_char(to_date(&amp;#039;19700101&amp;#039;,&amp;#039;YYYYMMDD&amp;#039;) + ((&amp;amp;epoch)/24/60/60),&amp;#039;DD-MON-YYYY HH24:MI:SS&amp;#039;) utc_date from dual;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===A database overview using the sys.plato package===&lt;br /&gt;
 exec plato.help;&lt;br /&gt;
or&lt;br /&gt;
 exec plato.complete(&amp;#039;HTM&amp;#039;);&lt;br /&gt;
&lt;br /&gt;
===List datafiles for a tablespace===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select *&lt;br /&gt;
from   dba_data_files&lt;br /&gt;
where  1=1&lt;br /&gt;
and    tablespace_name =&amp;#039;&amp;amp;ts_name&amp;#039;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Show graph of available and free space in tablespaces===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
-- =============================================================================&lt;br /&gt;
-- File Name    : http://www.oracle-base.com/dba/monitoring/ts_free_space.sql&lt;br /&gt;
-- Author       : Tim Hall&lt;br /&gt;
-- Description  : Displays a list of tablespaces and their used/full status.&lt;br /&gt;
-- Requirements : Access to the DBA views.&lt;br /&gt;
-- Call Syntax  : @ts_free_space.sql&lt;br /&gt;
-- Last Modified: 13-OCT-2012 - Created. Based on ts_full.sql&lt;br /&gt;
--&lt;br /&gt;
-- Modification History&lt;br /&gt;
-- ====================&lt;br /&gt;
-- When      Who               What&lt;br /&gt;
-- ========= ================= =================================================&lt;br /&gt;
-- 13-NOV-13 Stuart Barkley    Added cols free_pct and used_pct&lt;br /&gt;
-- =============================================================================&lt;br /&gt;
SET PAGESIZE 140 lines 180&lt;br /&gt;
COLUMN used_pct FORMAT A11&lt;br /&gt;
COLUMN max_used_pct FORMAT A11&lt;br /&gt;
&lt;br /&gt;
    SELECT tablespace_name                                                                      tablespace_name&lt;br /&gt;
    ,      size_mb                                                                              size_mb&lt;br /&gt;
    ,      free_mb                                                                              free_mb&lt;br /&gt;
    ,      TRUNC((free_mb/size_mb) * 100)                                                       free_pct&lt;br /&gt;
    ,      RPAD(&amp;#039; &amp;#039;|| RPAD(&amp;#039;X&amp;#039;,ROUND((size_mb-free_mb)/size_mb*10,0), &amp;#039;X&amp;#039;),11,&amp;#039;-&amp;#039;)              used_pct&lt;br /&gt;
    ,      max_size_mb                                                                          max_size_mb&lt;br /&gt;
    ,      max_free_mb                                                                          max_free_mb&lt;br /&gt;
    ,      TRUNC((max_free_mb/max_size_mb) * 100)                                               max_free_pct&lt;br /&gt;
    ,      RPAD(&amp;#039; &amp;#039;|| RPAD(&amp;#039;X&amp;#039;,ROUND((max_size_mb-max_free_mb)/max_size_mb*10,0), &amp;#039;X&amp;#039;),11,&amp;#039;-&amp;#039;)  max_used_pct&lt;br /&gt;
    from   (&lt;br /&gt;
           select a.tablespace_name                                         tablespace_name&lt;br /&gt;
           ,      b.size_mb                                                 size_mb&lt;br /&gt;
           ,      a.free_mb                                                 free_mb&lt;br /&gt;
           ,      b.max_size_mb                                             max_size_mb&lt;br /&gt;
           ,      a.free_mb + (b.max_size_mb - b.size_mb)                   max_free_mb&lt;br /&gt;
           from   (&lt;br /&gt;
                  select tablespace_name                                    tablespace_name&lt;br /&gt;
                  ,      trunc(sum(bytes)/1024/1024)                        free_mb&lt;br /&gt;
                  from   dba_free_space&lt;br /&gt;
                  group  by tablespace_name&lt;br /&gt;
                  ) a&lt;br /&gt;
           ,      (&lt;br /&gt;
                  select tablespace_name                                    tablespace_name&lt;br /&gt;
                  ,        trunc(sum(bytes)/1024/1024)                      size_mb&lt;br /&gt;
                  ,        trunc(sum(greatest(bytes,maxbytes))/1024/1024)   max_size_mb&lt;br /&gt;
                  from   dba_data_files&lt;br /&gt;
                  group by tablespace_name&lt;br /&gt;
                  ) b&lt;br /&gt;
           ,      v$instance vi&lt;br /&gt;
           where  a.tablespace_name = b.tablespace_name&lt;br /&gt;
           )&lt;br /&gt;
    order  by tablespace_name;&lt;br /&gt;
&lt;br /&gt;
set lines 80&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Another method for calculating free space in tablespace  using segments===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select df.tablespace_name &amp;quot;Tablespace&amp;quot;&lt;br /&gt;
,      totalusedspace &amp;quot;Used MB&amp;quot;&lt;br /&gt;
,      (df.totalspace - tu.totalusedspace) &amp;quot;Free MB&amp;quot;&lt;br /&gt;
,      df.totalspace &amp;quot;Total MB&amp;quot;&lt;br /&gt;
,      round(100 * ( (df.totalspace - tu.totalusedspace)/ df.totalspace)) &amp;quot;Pct. Free&amp;quot;&lt;br /&gt;
from   (&lt;br /&gt;
       select tablespace_name&lt;br /&gt;
,      round(sum(bytes) / 1048576) totalspace&lt;br /&gt;
       from   dba_data_files&lt;br /&gt;
       group  by tablespace_name&lt;br /&gt;
       ) df&lt;br /&gt;
,      (&lt;br /&gt;
       select round(sum(bytes)/(1024*1024)) totalusedspace&lt;br /&gt;
       ,      tablespace_name&lt;br /&gt;
       from   dba_segments&lt;br /&gt;
       group  by tablespace_name&lt;br /&gt;
       ) tu&lt;br /&gt;
where  df.tablespace_name = tu.tablespace_name;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Work out maximum possible size of a datafile===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select round( (4*1024*1024*value) / (1024*1024*1024) ,2) maxfilesizeingigabytes from v$parameter where name=&amp;#039;db_block_size&amp;#039;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or, as tablespaces can have block sizes differing from that of the init.ora parameter...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select round( (4*1024*1024*block_size) / (1024*1024*1024) ,2) maxfilesizeingigabytes from dba_tablespaces where tablespace_name=&amp;#039;&amp;amp;tablespace_name&amp;#039;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Show size and maxsize at datafile level===&lt;br /&gt;
datafiles&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set pages 100 lines 200&lt;br /&gt;
col file_name for a60&lt;br /&gt;
select sum(bytes)/1024/1024      mbytes_alloc&lt;br /&gt;
,      sum(maxbytes)/1024/1024   mbytes_max&lt;br /&gt;
,      file_name&lt;br /&gt;
from   sys.dba_data_files&lt;br /&gt;
group  by file_name&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
tempfiles&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set pages 100 lines 200&lt;br /&gt;
col file_name for a60&lt;br /&gt;
select sum(bytes)/1024/1024      mbytes_alloc&lt;br /&gt;
,      sum(maxbytes)/1024/1024   mbytes_max&lt;br /&gt;
,      file_name&lt;br /&gt;
from   sys.dba_temp_files&lt;br /&gt;
group  by file_name&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Resize the online redo logfiles===&lt;br /&gt;
Found a more concise, smarter way of doing it [http://www.oracle-wiki.net/startdocshowtorecreateredogrps here] - oracle-wiki.net&amp;lt;br /&amp;gt;&lt;br /&gt;
Switching logs too often? Redolog files too small?&amp;lt;br /&amp;gt;&lt;br /&gt;
* Show current log groups&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 1000&lt;br /&gt;
col group_member for a60&lt;br /&gt;
select l.group#          group_number&lt;br /&gt;
,      (bytes/1024/1024) megs&lt;br /&gt;
,      l.status          group_status&lt;br /&gt;
,      f.member          group_member&lt;br /&gt;
,      l.archived        archived&lt;br /&gt;
,      f.type            file_type&lt;br /&gt;
from   v$log     l&lt;br /&gt;
,      v$logfile f&lt;br /&gt;
where  l.group# = f.group#&lt;br /&gt;
order  by l.group#&lt;br /&gt;
,      f.member&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Create additional (bigger) groups&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
define SID=TIBQFW&lt;br /&gt;
alter database add logfile group 6  &amp;#039;/oracle/&amp;amp;SID/oradata1/redo1.log&amp;#039; size 1G;&lt;br /&gt;
alter database add logfile group 7  &amp;#039;/oracle/&amp;amp;SID/oradata2/redo2.log&amp;#039; size 1G;&lt;br /&gt;
alter database add logfile group 8  &amp;#039;/oracle/&amp;amp;SID/oradata3/redo3.log&amp;#039; size 1G;&lt;br /&gt;
alter database add logfile group 9  &amp;#039;/oracle/&amp;amp;SID/oradata1/redo4.log&amp;#039; size 1G;&lt;br /&gt;
alter database add logfile group 10 &amp;#039;/oracle/&amp;amp;SID/oradata2/redo5.log&amp;#039; size 1G;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or if you use multiple members...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter database add logfile group 6 (&amp;#039;/oracle/&amp;amp;SID/oradata1/redo/redo01a.log&amp;#039;, &amp;#039;/oracle/&amp;amp;SID/oradata1/redo01b&amp;#039;) size 50M;&lt;br /&gt;
alter database add logfile group 7 (&amp;#039;/oracle/&amp;amp;SID/oradata1/redo/redo02a.log&amp;#039;, &amp;#039;/oracle/&amp;amp;SID/oradata1/redo02b&amp;#039;) size 50M;&lt;br /&gt;
alter database add logfile group 8 (&amp;#039;/oracle/&amp;amp;SID/oradata1/redo/redo03a.log&amp;#039;, &amp;#039;/oracle/&amp;amp;SID/oradata1/redo03b&amp;#039;) size 50M;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Switch archivelogs until the new ones are current and the old ones are inactive&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter system switch logfile;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
If the old logs are not yet inactive, checkpoint the database&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter system checkpoint;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Drop the old groups&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter database drop logfile group 1;&lt;br /&gt;
alter database drop logfile group 2;&lt;br /&gt;
alter database drop logfile group 3;&lt;br /&gt;
alter database drop logfile group 4;&lt;br /&gt;
alter database drop logfile group 5;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Increase the existing size of a datafile===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter database datafile &amp;#039;&amp;amp;full_path_of_datafile&amp;#039; resize &amp;amp;new_meg_size.M;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Increase the max size of a tempfile===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter database tempfile &amp;#039;/oracle/ENDP1/oradata90/temp01.dbf&amp;#039; autoextend on maxsize unlimited;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Find out what processes are using the temp tablespace===&lt;br /&gt;
Temporary tablespace is used for sorting query results. Find them with this.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SELECT b.tablespace,b.segfile#,b.segblk#,b.blocks,a.sid,a.serial#,&lt;br /&gt;
a.username,a.osuser, a.status&lt;br /&gt;
FROM v$session a,v$sort_usage b&lt;br /&gt;
WHERE a.saddr = b.session_addr;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Increase the maximum size of a datafile===&lt;br /&gt;
Although this can be set lower than existing size, try not to. It makes the reports look weird!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter database&lt;br /&gt;
      datafile &amp;#039;&amp;amp;full_path_of_datafile&amp;#039;&lt;br /&gt;
      autoextend on&lt;br /&gt;
      maxsize &amp;amp;new_meg_size.m;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Find schemas (users) with objects created outside their default tablespace===&lt;br /&gt;
Indexes could be a notable exception if they are created in an index tablespace&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 200&lt;br /&gt;
col owner           for a20&lt;br /&gt;
col segment_name    for a45&lt;br /&gt;
col tablespace_name for a32&lt;br /&gt;
select owner&lt;br /&gt;
,      segment_name&lt;br /&gt;
,      tablespace_name&lt;br /&gt;
from   dba_segments&lt;br /&gt;
where  exists (select username from dba_users where username = owner)&lt;br /&gt;
and    tablespace_name != (select default_tablespace from dba_users where username = owner)&lt;br /&gt;
and    owner = &amp;#039;&amp;amp;owner&amp;#039;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Add a datafile to a tablespace===&lt;br /&gt;
&amp;#039;unlimited&amp;#039; will default to the maximum datafile size for the current db_block_size&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter tablepace &amp;amp;tablespace_name&lt;br /&gt;
      add datafile &amp;#039;&amp;amp;full_path_of_datafile&amp;#039;&lt;br /&gt;
      size 100M&lt;br /&gt;
      autoextend on&lt;br /&gt;
      next 100M&lt;br /&gt;
      maxsize unlimited&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===List all datafiles with their size===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set pages 1000 lines 2000&lt;br /&gt;
col filetype for a15&lt;br /&gt;
col name for a60&lt;br /&gt;
break on report&lt;br /&gt;
compute sum of gig on report&lt;br /&gt;
&lt;br /&gt;
select filetype&lt;br /&gt;
,      name&lt;br /&gt;
,      gig&lt;br /&gt;
from   (&lt;br /&gt;
       select &amp;#039;datafile&amp;#039; filetype&lt;br /&gt;
       ,      name&lt;br /&gt;
       ,      bytes/1024/1024 gig&lt;br /&gt;
       from   v$datafile&lt;br /&gt;
       union all&lt;br /&gt;
       select &amp;#039;tempfile&amp;#039; filetype&lt;br /&gt;
       ,      name&lt;br /&gt;
       ,      bytes/1024/1024&lt;br /&gt;
       from   v$tempfile&lt;br /&gt;
       union all&lt;br /&gt;
       select &amp;#039;logfile&amp;#039; filetype&lt;br /&gt;
       ,      lf.member &amp;quot;name&amp;quot;&lt;br /&gt;
       ,      l.bytes/1024/1024&lt;br /&gt;
       from   v$logfile lf&lt;br /&gt;
       ,      v$log     l&lt;br /&gt;
       where  1=1&lt;br /&gt;
       and    lf.group# = l.group#&lt;br /&gt;
       ) used&lt;br /&gt;
,      (&lt;br /&gt;
       select sum(bytes)/1024/1024&lt;br /&gt;
       from   dba_free_space&lt;br /&gt;
       ) free&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Database size (How big is my database?)===&lt;br /&gt;
There are different interpretations of what constitutes the size of a database...&amp;lt;br /&amp;gt;&lt;br /&gt;
Is it the space allocated to the datafiles or only the space taken up by the data? Are tempfiles included? Are redo logs included? etc...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 132&lt;br /&gt;
col dbname for a9  heading &amp;quot;Database&amp;quot;&lt;br /&gt;
col dbsize for a15 heading &amp;quot;Size&amp;quot;&lt;br /&gt;
col dbused for a15 heading &amp;quot;Used space&amp;quot;&lt;br /&gt;
col dbfree for a15 heading &amp;quot;Free space&amp;quot;&lt;br /&gt;
with used_space as&lt;br /&gt;
(&lt;br /&gt;
select  bytes&lt;br /&gt;
from    v$datafile&lt;br /&gt;
union   all&lt;br /&gt;
select  bytes&lt;br /&gt;
from    v$tempfile&lt;br /&gt;
union   all&lt;br /&gt;
select  bytes&lt;br /&gt;
from    v$log&lt;br /&gt;
)&lt;br /&gt;
, free_space as&lt;br /&gt;
(&lt;br /&gt;
select sum(bytes) sum_bytes&lt;br /&gt;
from dba_free_space&lt;br /&gt;
)&lt;br /&gt;
select vd.name                                                                                            dbname&lt;br /&gt;
,      round(sum(used_space.bytes)/1024/1024/1024 ) || &amp;#039; GB&amp;#039;                                              dbsize&lt;br /&gt;
,      round(sum(used_space.bytes)/1024/1024/1024 ) - round(free_space.sum_bytes/1024/1024/1024) || &amp;#039; GB&amp;#039; dbused&lt;br /&gt;
,      round(free_space.sum_bytes/1024/1024/1024) || &amp;#039; GB&amp;#039;                                                dbfree&lt;br /&gt;
from   free_space&lt;br /&gt;
,      used_space&lt;br /&gt;
,      v$database vd&lt;br /&gt;
group  by vd.name&lt;br /&gt;
,      free_space.sum_bytes&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Drop datafile from temp tablespace===&lt;br /&gt;
Database is completely stuck because the temporary tablespace has grown to fill all available room.&amp;lt;br /&amp;gt;&lt;br /&gt;
Look around for at least some log files to delete in order to get connected (audit files, sqlnet logs, listener logs)&amp;lt;br /&amp;gt;&lt;br /&gt;
Once connected, change the default temporary tablespace to a small one so we can remove the original.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
create temporary tablespace temp2 tempfile &amp;#039;/oracle/RMANV12/oradata2/temp2.dbf&amp;#039; size 5M;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter database default temporary tablespace temp2;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
I found trying to drop the datafile like this didn&amp;#039;t work, just hung there (probably active tranactions)...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
drop tablespace temp including contents and datafiles;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
So did it like this...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter database tempfile &amp;#039;/oracle/RMANV12/oradata2/temp.dbf&amp;#039; drop including datafiles;&lt;br /&gt;
&lt;br /&gt;
Database altered.&lt;br /&gt;
&lt;br /&gt;
drop tablespace temp including contents and datafiles;&lt;br /&gt;
&lt;br /&gt;
Tablespace dropped.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
... an alternative would be to find the sessions using the temp space and kill them...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select sid, serial#, status from v$session where serial# in (select session_num from v$sort_usage);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Then to be neat and tidy, rename the temp2 tablespace back to temp.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
create temporary tablespace temp tempfile &amp;#039;/oracle/RMANV12/oradata2/temp.dbf&amp;#039; size 256M reuse autoextend on next 128M maxsize 1G;&lt;br /&gt;
alter database default temporary tablespace temp;&lt;br /&gt;
drop tablespace temp2 including contents and datafiles;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Although the last statement will not work until any transactions using it have been rolled back or committed.&lt;br /&gt;
&lt;br /&gt;
===List files that are in hot-backup mode===&lt;br /&gt;
 set lines 100&lt;br /&gt;
 set pages 100&lt;br /&gt;
 col name format a60&lt;br /&gt;
 &lt;br /&gt;
 select df.name&lt;br /&gt;
 ,      b.status&lt;br /&gt;
 ,      to_char(time, &amp;#039;hh24:mi:ss dd/mm/yyyy&amp;#039;) time&lt;br /&gt;
 from   v$datafile   df&lt;br /&gt;
 ,      v$backup     b&lt;br /&gt;
 where  1=1&lt;br /&gt;
 and    df.file# = b.file#&lt;br /&gt;
 and    b.status = &amp;#039;ACTIVE&amp;#039;&lt;br /&gt;
 order  by b.file#;&lt;br /&gt;
&lt;br /&gt;
===Waiting for snapshot control file enqueue===&lt;br /&gt;
Script to identify sessions causing RMAN to hang because of &amp;#039;waiting for snapshot control file enqueue&amp;#039; message&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 2000&lt;br /&gt;
col killer     for a70&lt;br /&gt;
col program    for a20&lt;br /&gt;
col module     for a20&lt;br /&gt;
col action     for a20&lt;br /&gt;
col logon_time for a20&lt;br /&gt;
&lt;br /&gt;
select &amp;#039;alter system disconnect session &amp;#039;&amp;#039;&amp;#039;||s.sid||&amp;#039;,&amp;#039;||s.serial#||&amp;#039;&amp;#039;&amp;#039; immediate;&amp;#039; killer&lt;br /&gt;
,      username&lt;br /&gt;
,      program&lt;br /&gt;
,      module&lt;br /&gt;
,      action&lt;br /&gt;
,      logon_time&lt;br /&gt;
from   v$session s&lt;br /&gt;
,      v$enqueue_lock l&lt;br /&gt;
where  l.sid  = s.sid&lt;br /&gt;
and    l.type = &amp;#039;CF&amp;#039;&lt;br /&gt;
and    l.id1  = 0&lt;br /&gt;
and    l.id2  = 2&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Info on blocking processes===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select s1.username || &amp;#039;@&amp;#039; || s1.machine&lt;br /&gt;
       || &amp;#039; ( SID=&amp;#039; || s1.sid || &amp;#039; )  is blocking &amp;#039;&lt;br /&gt;
       || s2.username || &amp;#039;@&amp;#039; || s2.machine || &amp;#039; ( SID=&amp;#039; || s2.sid || &amp;#039; ) &amp;#039;  blocking_status&lt;br /&gt;
from   v$lock l1&lt;br /&gt;
,      v$session s1&lt;br /&gt;
,      v$lock l2&lt;br /&gt;
,      v$session s2&lt;br /&gt;
where  s1.sid     = l1.sid&lt;br /&gt;
and    s2.sid     = l2.sid&lt;br /&gt;
and    l1.block   = 1&lt;br /&gt;
and    l2.request &amp;gt; 0&lt;br /&gt;
and    l1.id1     = l2.id1&lt;br /&gt;
and    l2.id2     = l2.id2&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
session doing the blocking&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select *&lt;br /&gt;
from  v$lock l1&lt;br /&gt;
where 1=1&lt;br /&gt;
and   block = 1 ;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
sessions being blocked&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select *&lt;br /&gt;
from   v$lock l1&lt;br /&gt;
where  1=1&lt;br /&gt;
and    id2 = 85203&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
info on session doing the blocking&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select row_wait_obj#, row_wait_file#, row_wait_block#, row_wait_row#&lt;br /&gt;
from   v$session&lt;br /&gt;
where  sid = 234&lt;br /&gt;
&lt;br /&gt;
select do.object_name&lt;br /&gt;
,      row_wait_obj#&lt;br /&gt;
,      row_wait_file#&lt;br /&gt;
,      row_wait_block#&lt;br /&gt;
,      row_wait_row#&lt;br /&gt;
,      dbms_rowid.rowid_create ( 1, ROW_WAIT_OBJ#, ROW_WAIT_FILE#, ROW_WAIT_BLOCK#, ROW_WAIT_ROW# ) row_id&lt;br /&gt;
from   v$session   s&lt;br /&gt;
,      dba_objects do&lt;br /&gt;
where  sid=234&lt;br /&gt;
and    s.ROW_WAIT_OBJ# = do.OBJECT_ID;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Show locked objects===&lt;br /&gt;
 set lines 100&lt;br /&gt;
 set pages 999&lt;br /&gt;
 col username   format a20&lt;br /&gt;
 col sess_id    format a10&lt;br /&gt;
 col object     format a25&lt;br /&gt;
 col mode_held  format a10&lt;br /&gt;
 select oracle_username||&amp;#039; (&amp;#039;||s.osuser||&amp;#039;)&amp;#039; username&lt;br /&gt;
 ,      s.sid||&amp;#039;,&amp;#039;||s.serial# sess_id&lt;br /&gt;
 ,      owner||&amp;#039;.&amp;#039;||object_name object&lt;br /&gt;
 ,      object_type&lt;br /&gt;
 ,      decode ( l.block&lt;br /&gt;
               , 0, &amp;#039;Not Blocking&amp;#039;&lt;br /&gt;
               , 1, &amp;#039;Blocking&amp;#039;&lt;br /&gt;
               , 2, &amp;#039;Global&amp;#039;&lt;br /&gt;
               ) status&lt;br /&gt;
 ,      decode ( v.locked_mode&lt;br /&gt;
               , 0, &amp;#039;None&amp;#039;&lt;br /&gt;
               , 1, &amp;#039;Null&amp;#039;&lt;br /&gt;
               , 2, &amp;#039;Row-S (SS)&amp;#039;&lt;br /&gt;
               , 3, &amp;#039;Row-X (SX)&amp;#039;&lt;br /&gt;
               , 4, &amp;#039;Share&amp;#039;&lt;br /&gt;
               , 5, &amp;#039;S/Row-X (SSX)&amp;#039;&lt;br /&gt;
               , 6, &amp;#039;Exclusive&amp;#039;, TO_CHAR(lmode)&lt;br /&gt;
               ) mode_held&lt;br /&gt;
 from   v$locked_object v&lt;br /&gt;
 ,      dba_objects d&lt;br /&gt;
 ,      v$lock l&lt;br /&gt;
 ,      v$session s&lt;br /&gt;
 where  1=1&lt;br /&gt;
 and    v.object_id = d.object_id&lt;br /&gt;
 and    v.object_id = l.id1&lt;br /&gt;
 and    v.session_id = s.sid&lt;br /&gt;
 order  by oracle_username&lt;br /&gt;
 ,	session_id;&lt;br /&gt;
&lt;br /&gt;
===Show which row is locked===&lt;br /&gt;
 select do.object_name&lt;br /&gt;
 ,      row_wait_obj#&lt;br /&gt;
 ,      row_wait_file#&lt;br /&gt;
 ,      row_wait_block#&lt;br /&gt;
 ,      row_wait_row#&lt;br /&gt;
 ,      dbms_rowid.rowid_create (1, ROW_WAIT_OBJ#, ROW_WAIT_FILE#, ROW_WAIT_BLOCK#, ROW_WAIT_ROW#)&lt;br /&gt;
 from   v$session   s&lt;br /&gt;
 ,      dba_objects do&lt;br /&gt;
 where  1=1&lt;br /&gt;
 and    s.ROW_WAIT_OBJ# = do.OBJECT_ID&lt;br /&gt;
 and    sid             = &amp;amp;sid;&lt;br /&gt;
&lt;br /&gt;
===Check what is audited on a database===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set pagesize 100&lt;br /&gt;
set linesize 256&lt;br /&gt;
select audit_option,success,failure from dba_stmt_audit_opts;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===How old is the oldest audit record?===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select extract (day from (systimestamp - min(ntimestamp#))) days_old from aud$;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Check what objects are being audited===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
tti col 60 &amp;#039;Object Audit Options (dba_obj_audit_opts)&amp;#039; skip col 50 &amp;#039;A=By Access, S=By Session. Left=on success, right=on failure&amp;#039; skip 2&lt;br /&gt;
set lines 1000 pages 100&lt;br /&gt;
col alt for a3 head &amp;quot;Alt|er&amp;quot;&lt;br /&gt;
col aud for a3 head &amp;quot;Aud|it&amp;quot;&lt;br /&gt;
col com for a3 head &amp;quot;Com|ent&amp;quot;&lt;br /&gt;
col del for a3 head &amp;quot;Del|ete&amp;quot;&lt;br /&gt;
col gra for a3 head &amp;quot;Gra|nt&amp;quot;&lt;br /&gt;
col ind for a3 head &amp;quot;Ind|ex&amp;quot;&lt;br /&gt;
col ins for a3 head &amp;quot;Ins|ert&amp;quot;&lt;br /&gt;
col loc for a3 head &amp;quot;Lo|ck&amp;quot;&lt;br /&gt;
col ren for a3 head &amp;quot;Ren|ame&amp;quot;&lt;br /&gt;
col sel for a3 head &amp;quot;Sel|ect&amp;quot;&lt;br /&gt;
col upd for a3 head &amp;quot;Upd|ate&amp;quot;&lt;br /&gt;
col ref for a3 head &amp;quot;Ref|rnc&amp;quot;&lt;br /&gt;
col exe for a3 head &amp;quot;Exe|cut&amp;quot;&lt;br /&gt;
col cre for a3 head &amp;quot;Cre|ate&amp;quot;&lt;br /&gt;
col rea for a3 head &amp;quot;Re|ad&amp;quot;&lt;br /&gt;
col wri for a3 head &amp;quot;Wri|te&amp;quot;&lt;br /&gt;
col fbk for a3 head &amp;quot;Fla|sh&amp;quot;&lt;br /&gt;
	&lt;br /&gt;
select *&lt;br /&gt;
from   dba_obj_audit_opts&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Procedure to delete old audit records===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select text from all_source where lower(name)=&amp;#039;purge_audit_trail&amp;#039;;&lt;br /&gt;
&lt;br /&gt;
TEXT&lt;br /&gt;
------------------------------------------------------------------------------------------------&lt;br /&gt;
PROCEDURE purge_audit_trail IS&lt;br /&gt;
BEGIN&lt;br /&gt;
-- set the last archive timestamp&lt;br /&gt;
DBMS_AUDIT_MGMT.SET_LAST_ARCHIVE_TIMESTAMP(&lt;br /&gt;
       audit_trail_type    =&amp;gt; DBMS_AUDIT_MGMT.AUDIT_TRAIL_AUD_STD,&lt;br /&gt;
       last_archive_time   =&amp;gt; systimestamp - interval &amp;#039;365&amp;#039; day,&lt;br /&gt;
       rac_instance_number =&amp;gt; null&lt;br /&gt;
                                          );&lt;br /&gt;
-- purge audit trail till last archive timestamp&lt;br /&gt;
DBMS_AUDIT_MGMT.CLEAN_AUDIT_TRAIL( audit_trail_type =&amp;gt; DBMS_AUDIT_MGMT.AUDIT_TRAIL_AUD_STD&lt;br /&gt;
, use_last_arch_timestamp =&amp;gt; TRUE);&lt;br /&gt;
&lt;br /&gt;
END purge_audit_trail;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Job setup to run the audit purge===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
BEGIN&lt;br /&gt;
sys.dbms_scheduler.create_job(&lt;br /&gt;
    job_name =&amp;gt; &amp;#039;&amp;quot;SYS&amp;quot;.&amp;quot;PURGE_AUDIT_TRAIL_JOB&amp;quot;&amp;#039;,&lt;br /&gt;
    job_type =&amp;gt; &amp;#039;STORED_PROCEDURE&amp;#039;,&lt;br /&gt;
    job_action =&amp;gt; &amp;#039;&amp;quot;SYS&amp;quot;.&amp;quot;PURGE_AUDIT_TRAIL&amp;quot;&amp;#039;,&lt;br /&gt;
    repeat_interval =&amp;gt; &amp;#039;FREQ=DAILY;BYHOUR=20;BYMINUTE=0;BYSECOND=0&amp;#039;,&lt;br /&gt;
    start_date =&amp;gt; to_timestamp_tz(&amp;#039;2012-02-22 Europe/Paris&amp;#039;, &amp;#039;YYYY-MM-DD TZR&amp;#039;),&lt;br /&gt;
    job_class =&amp;gt; &amp;#039;&amp;quot;DEFAULT_JOB_CLASS&amp;quot;&amp;#039;,&lt;br /&gt;
    comments =&amp;gt; &amp;#039;purge audit trails until last archive timestamp&amp;#039;,&lt;br /&gt;
    auto_drop =&amp;gt; FALSE,&lt;br /&gt;
    enabled =&amp;gt; FALSE&lt;br /&gt;
);&lt;br /&gt;
sys.dbms_scheduler.set_attribute( name =&amp;gt; &amp;#039;&amp;quot;SYS&amp;quot;.&amp;quot;PURGE_AUDIT_TRAIL_JOB&amp;quot;&amp;#039;, attribute =&amp;gt; &amp;#039;logging_level&amp;#039;, value =&amp;gt; DBMS_SCHEDULER.LOGGING_OFF);&lt;br /&gt;
sys.dbms_scheduler.set_attribute( name =&amp;gt; &amp;#039;&amp;quot;SYS&amp;quot;.&amp;quot;PURGE_AUDIT_TRAIL_JOB&amp;quot;&amp;#039;, attribute =&amp;gt; &amp;#039;job_weight&amp;#039;, value =&amp;gt; 1);&lt;br /&gt;
sys.dbms_scheduler.enable( &amp;#039;&amp;quot;SYS&amp;quot;.&amp;quot;PURGE_AUDIT_TRAIL_JOB&amp;quot;&amp;#039; );&lt;br /&gt;
END;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===A list of all SIDs in oratab that should restart after a server boot===&lt;br /&gt;
Using awk&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
awk -F: &amp;#039;$NF==&amp;quot;Y&amp;quot; &amp;amp;&amp;amp; $1 !~/[#]/ {print $1}&amp;#039;  /etc/oratab&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Using perl&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
perl -F: -ne &amp;#039;print &amp;quot;$1\n&amp;quot; if /(\w+):(.+):Y$/&amp;#039; /etc/oratab&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Move the admin directories to a new location===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
./all_db_do &amp;quot;alter system set audit_file_dest=&amp;#039;/oracle/&amp;amp;SID/admin/adump&amp;#039; scope=spfile;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
./all_db_do &amp;quot;shutdown immediate&amp;quot;&lt;br /&gt;
&lt;br /&gt;
for db in `awk -F: &amp;#039;NF &amp;amp;&amp;amp; $1 !~/[#*]/ {print $1}&amp;#039;  /etc/oratab`&lt;br /&gt;
do&lt;br /&gt;
    echo $db&lt;br /&gt;
    mkdir -p /oracle/${db}/admin&lt;br /&gt;
    echo &amp;quot;/oracle/${db}/admin created&amp;quot;&lt;br /&gt;
    mv /oracle/admin/${db}/adump /oracle/${db}/admin/&lt;br /&gt;
    mv /oracle/admin/${db}/dpdump /oracle/${db}/admin/&lt;br /&gt;
    echo &amp;quot;Moved /oracle/admin/${db}/adump to /oracle/${db}/admin/&amp;quot;&lt;br /&gt;
done&lt;br /&gt;
&lt;br /&gt;
./all_db_do startup&lt;br /&gt;
&lt;br /&gt;
./all_db_do &amp;quot;create pfile from spfile;&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Check if the Standby database is up-to-date with the primary database===&lt;br /&gt;
 select arch.thread# &amp;quot;Thread&amp;quot;&lt;br /&gt;
 ,      arch.sequence# &amp;quot;Last Sequence Received&amp;quot;&lt;br /&gt;
 ,      appl.sequence# &amp;quot;Last Sequence Applied&amp;quot;&lt;br /&gt;
 ,      (arch.sequence# - appl.sequence#) &amp;quot;Difference&amp;quot;&lt;br /&gt;
 from   (&lt;br /&gt;
        select thread#&lt;br /&gt;
        ,      sequence#&lt;br /&gt;
        from   v$archived_log&lt;br /&gt;
        where  1=1&lt;br /&gt;
        and    ( thread#,first_time ) in (&lt;br /&gt;
                                         select thread#, max(first_time)&lt;br /&gt;
                                         from   v$archived_log&lt;br /&gt;
                                         group  by thread#&lt;br /&gt;
                                         )&lt;br /&gt;
        ) arch&lt;br /&gt;
        ,&lt;br /&gt;
        (&lt;br /&gt;
        select thread#&lt;br /&gt;
        ,      sequence#&lt;br /&gt;
        from   v$log_history&lt;br /&gt;
        where  1=1&lt;br /&gt;
        and    ( thread#,first_time ) in ( select thread# ,max(first_time)&lt;br /&gt;
                                           from   v$log_history&lt;br /&gt;
                                           group  by thread#&lt;br /&gt;
                                          )&lt;br /&gt;
        ) appl&lt;br /&gt;
 where  1=1&lt;br /&gt;
 and    arch.thread# = appl.thread#&lt;br /&gt;
 order  by 1;&lt;br /&gt;
&lt;br /&gt;
===Check for gaps on the Standby database===&lt;br /&gt;
Run this on the standby&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select thread#, low_sequence#, high_sequence# from v$archive_gap;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or run this on the Primary to see the latest generated archive...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select thread#   &amp;quot;Thread&amp;quot;&lt;br /&gt;
,      sequence# &amp;quot;Last sequence generated&amp;quot;&lt;br /&gt;
from   v$archived_log&lt;br /&gt;
where  (thread#, first_time) in ( select thread#, max(first_time)&lt;br /&gt;
                                  from   v$archived_log&lt;br /&gt;
                                  group  by thread#&lt;br /&gt;
                                )&lt;br /&gt;
order  by 1&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
and run this on the standby to check for received but not yet applied logs (this could be normal if a lag has been set)...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select arch.thread# &amp;quot;Thread&amp;quot;&lt;br /&gt;
,      arch.sequence# &amp;quot;Last sequence received&amp;quot;&lt;br /&gt;
,      appl.sequence# &amp;quot;Last sequence applied&amp;quot;&lt;br /&gt;
,      (arch.sequence#-appl.sequence#) &amp;quot;Difference&amp;quot;&lt;br /&gt;
from   (&lt;br /&gt;
       select thread#&lt;br /&gt;
       ,      sequence#&lt;br /&gt;
       from   v$archived_log&lt;br /&gt;
       where  (thread#,first_time ) in (select thread#, max(first_time)&lt;br /&gt;
                                        from   v$archived_log&lt;br /&gt;
                                        group  by thread#&lt;br /&gt;
                                       )&lt;br /&gt;
       ) arch&lt;br /&gt;
,      (&lt;br /&gt;
       select thread#&lt;br /&gt;
       ,      sequence#&lt;br /&gt;
       from   v$log_history&lt;br /&gt;
       where  (thread#,first_time ) in (select thread#, max(first_time)&lt;br /&gt;
                                        from   v$log_history&lt;br /&gt;
                                        group  by thread#&lt;br /&gt;
                                       )&lt;br /&gt;
      ) appl&lt;br /&gt;
where arch.thread# = appl.thread#&lt;br /&gt;
order by 1&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Compare the results from Primary and Secondary to detect possible network problems or other errors in shipping.&lt;br /&gt;
&lt;br /&gt;
===Ignore case-sensitive passwords in 11g (deprecated in 12c)===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter system set SEC_CASE_SENSITIVE_LOGON = false scope=both&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===External table for the Alert log (pre 11g)===&lt;br /&gt;
Modified to use (the better) scripts found on [http://www.adp-gmbh.ch/ora/admin/scripts/read_alert_log.html Rene Nyffenegger&amp;#039;s site]&amp;lt;br /&amp;gt;&lt;br /&gt;
This script generates the required DDL for the alertlog table&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
column db    new_value _DB    noprint;&lt;br /&gt;
column bdump new_value _bdump noprint;&lt;br /&gt;
&lt;br /&gt;
select &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Alert log (11g+)===&lt;br /&gt;
This reads the log.xml file (which contains the same information as alert.log)&amp;lt;br /&amp;gt;&lt;br /&gt;
Show the messages put in the alert log in the last 24 hours&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select substr(MESSAGE_TEXT, 1, 300) message_text&lt;br /&gt;
,      count(*) cnt&lt;br /&gt;
from   X$DBGALERTEXT&lt;br /&gt;
where  1=1&lt;br /&gt;
and    (MESSAGE_TEXT like &amp;#039;%ORA-%&amp;#039; or upper(MESSAGE_TEXT) like &amp;#039;%ERROR%&amp;#039;)&lt;br /&gt;
and    cast(ORIGINATING_TIMESTAMP as DATE) &amp;gt; sysdate - &amp;amp;days_ago/1440&lt;br /&gt;
group  by substr(MESSAGE_TEXT, 1, 300)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
There is also a fixed table X$DBGDIREXT which returns all file and directory names under [diagnostic_dest]/diag directory:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select lpad(&amp;#039; &amp;#039;,lvl,&amp;#039; &amp;#039;)||logical_file file_name&lt;br /&gt;
from   x$dbgdirext&lt;br /&gt;
where  rownum &amp;lt;=20;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Directory paths available in v$diag_info===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 2000&lt;br /&gt;
col name for a35&lt;br /&gt;
col value for a100 wrap&lt;br /&gt;
select * from v$diag_info;&lt;br /&gt;
&lt;br /&gt;
   INST_ID NAME                                VALUE                                                                                                    CON_ID&lt;br /&gt;
---------- ----------------------------------- ---------------------------------------------------------------------------------------------------- ----------&lt;br /&gt;
         1 Diag Enabled                        TRUE                                                                                                          0&lt;br /&gt;
         1 ADR Base                            /cln/prg/ora_bin2/app/oracle                                                                               0&lt;br /&gt;
         1 ADR Home                            /cln/prg/ora_bin2/app/oracle/diag/rdbms/bild/bild                                                          0&lt;br /&gt;
         1 Diag Trace                          /cln/prg/ora_bin2/app/oracle/diag/rdbms/bild/bild/trace                                                    0&lt;br /&gt;
         1 Diag Alert                          /cln/prg/ora_bin2/app/oracle/diag/rdbms/bild/bild/alert                                                    0&lt;br /&gt;
         1 Diag Incident                       /cln/prg/ora_bin2/app/oracle/diag/rdbms/bild/bild/incident                                                 0&lt;br /&gt;
         1 Diag Cdump                          /cln/prg/ora_bin2/app/oracle/diag/rdbms/bild/bild/cdump                                                    0&lt;br /&gt;
         1 Health Monitor                      /cln/prg/ora_bin2/app/oracle/diag/rdbms/bild/bild/hm                                                       0&lt;br /&gt;
         1 Default Trace File                  /cln/prg/ora_bin2/app/oracle/diag/rdbms/bild/bild/trace/bild_ora_44696768.trc                              0&lt;br /&gt;
         1 Active Problem Count                0                                                                                                             0&lt;br /&gt;
         1 Active Incident Count               0                                                                                                             0&lt;br /&gt;
&lt;br /&gt;
11 rows selected.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Find out the names of the active trace files for the running processes===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select pid, program, tracefile from v$process;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Request was to duplicate a large tablespace from production to test environment===&lt;br /&gt;
...but rather than copy the terabytes of data, create the destination tablespace with just the most recent months data&amp;lt;br /&amp;gt;&lt;br /&gt;
====See what the source data looks like====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
col table_owner    for a20&lt;br /&gt;
col table_name     for a30&lt;br /&gt;
col partition_name for a20&lt;br /&gt;
set pages 100 lines 1000&lt;br /&gt;
&lt;br /&gt;
select table_owner&lt;br /&gt;
,      table_name&lt;br /&gt;
,      partition_name&lt;br /&gt;
,      partition_position&lt;br /&gt;
,      tablespace_name&lt;br /&gt;
from   dba_tab_partitions&lt;br /&gt;
where  tablespace_name = &amp;#039;ADS_ARCHIVE&amp;#039;&lt;br /&gt;
order  by 1,2,3,4&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This query produces something like this...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
TABLE_OWNER          TABLE_NAME                     PARTITION_NAME       PARTITION_POSITION TABLESPACE_NAME                &lt;br /&gt;
-------------------- ------------------------------ -------------------- ------------------ ------------------------------ &lt;br /&gt;
ADS_ARCHIVE          BIL_DAY_INV_CTR_ARC            Y2017_Q1_M01_D01                      1 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          BIL_HIS_DETAIL_FAC_ARC         Y2016_Q2_M05_D04                      1 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          BIL_HIS_DETAIL_FAC_ARC         Y2016_Q2_M05_D09                      2 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          BIL_MTH_INV_CTR_ARC            Y2017_Q1_M01_D01                      1 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          FAH_DAY_CBA_BGAAP_ARC          Y2011_Q4_M12_D30                      1 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          FAH_DAY_CBA_BGAAP_ARC          Y2011_Q4_M12_D31                      2 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          FAH_DAY_CBA_IFRS_ARC           Y2011_Q4_M12_D30                      1 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          FAH_DAY_CBA_IFRS_ARC           Y2011_Q4_M12_D31                      2 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          FAH_DAY_MVT_BGAAP_ARC          Y2011_Q4_M12_D30                      1 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          FAH_DAY_MVT_BGAAP_ARC          Y2011_Q4_M12_D31                      2 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          FAH_DAY_MVT_BGAAP_ARC          Y2012_Q1_M03_D31                      3 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          FAH_DAY_MVT_BGAAP_ARC          Y2012_Q2_M04_D01                      4 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          FAH_DAY_MVT_BGAAP_ARC          Y2012_Q4_M10_D12                      5 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          FAH_DAY_MVT_BGAAP_ARC          Y2012_Q4_M10_D13                      6 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          FAH_DAY_MVT_BGAAP_ARC          Y2012_Q4_M10_D14                      7 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          FAH_DAY_MVT_BGAAP_ARC_TST      Y2011_Q4_M12_D30                      1 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          FAH_DAY_MVT_BGAAP_ARC_TST      Y2011_Q4_M12_D31                      2 ADS_ARCHIVE&lt;br /&gt;
...&lt;br /&gt;
ADS_ARCHIVE          SBP_HIS_LINES_ARC              P_LS                                  3 ADS_ARCHIVE                  &lt;br /&gt;
ADS_ARCHIVE          THA_DAY_INV_CTR_ARC            Y2011_Q4_M12_D30                      1 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          THA_DAY_INV_CTR_ARC            Y2011_Q4_M12_D31                      2 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          THA_INV_HEAVY_ARC              Y2011_Q4_M12_D30                      1 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          THA_INV_HEAVY_ARC              Y2011_Q4_M12_D31                      2 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          THA_INV_LIGHT_ARC              Y2011_Q4_M12_D30                      1 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          THA_INV_LIGHT_ARC              Y2012_Q4_M10_D12                      2 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          THA_INV_LIGHT_ARC              Y2012_Q4_M10_D13                      3 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          THA_INV_LIGHT_ARC              Y2012_Q4_M10_D15                      4 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          THA_INV_LIGHT_ARC              Y2012_Q4_M10_D16                      5 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          THA_INV_LIGHT_ARC              Y2012_Q4_M10_D17                      6 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          THA_INV_LIGHT_ARC              Y2012_Q4_M10_D18                      7 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          THA_INV_LIGHT_ARC              Y2012_Q4_M10_D19                      8 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          THA_INV_LIGHT_ARC              Y2012_Q4_M10_D20                      9 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          THA_INV_LIGHT_ARC              Y2012_Q4_M10_D21                     10 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          THA_INV_LIGHT_ARC              Y2012_Q4_M10_D22                     11 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          THA_INV_LIGHT_ARC              Y2012_Q4_M10_D23                     12 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          THA_INV_LIGHT_ARC              Y2012_Q4_M10_D24                     13 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          THA_MTH_INV_CTR_ARC            Y2011_Q4_M12_D30                      1 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          THA_MTH_INV_CTR_ARC            Y2011_Q4_M12_D31                      2 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          THA_MTH_INV_CTR_ARC            Y2013_Q2_M04_D30                      3 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          XBD01_TEMP_HIS_ARC             Y2012_Q4_M12_D31                      1 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          T_RPT_RECO_THA_INV_ACC_ARC     Y2011_Q4_M12_D30                      1 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          T_RPT_RECO_THA_INV_ACC_ARC     Y2011_Q4_M12_D31                      2 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          T_RPT_RECO_THA_INV_MTH_ARC     Y2011_Q4_M12_D30                      1 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          T_RPT_RECO_THA_INV_MTH_ARC     Y2011_Q4_M12_D31                      2 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          XBD01_TEMP_HIS_ARC             Y2012_Q4_M12_D31                      1 ADS_ARCHIVE&lt;br /&gt;
ADS_DBA              FAH_DAY_CBA_BGAAP              Y2016_Q3_M07_D12                   1657 ADS_ARCHIVE&lt;br /&gt;
ADS_DBA              FAH_DAY_CBA_BGAAP              Y2016_Q4_M12_D13                   1811 ADS_ARCHIVE&lt;br /&gt;
ADS_DBA              FAH_DAY_MVT_IFRS               Y2016_Q4_M10_D10                   1654 ADS_ARCHIVE&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Capture the tablespace metadata====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set long 1000000&lt;br /&gt;
select dbms_metadata.get_ddl ( &amp;#039;TABLESPACE&amp;#039;, &amp;#039;ADS_ARCHIVE&amp;#039;) from dual&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
produces...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
CREATE TABLESPACE &amp;quot;ADS_ARCHIVE&amp;quot; DATAFILE&lt;br /&gt;
  &amp;#039;/oracle/tst/ora_data3/adst/ads_archive01.dbf&amp;#039; SIZE 104857600&lt;br /&gt;
  AUTOEXTEND ON NEXT 104857600 MAXSIZE 32000M,&lt;br /&gt;
...&lt;br /&gt;
  &amp;#039;/oracle/tst/ora_data3/adst/ads_archive66.dbf&amp;#039; SIZE 104857600&lt;br /&gt;
  AUTOEXTEND ON NEXT 104857600 MAXSIZE 3200M,&lt;br /&gt;
  LOGGING ONLINE PERMANENT BLOCKSIZE 8192&lt;br /&gt;
  EXTENT MANAGEMENT LOCAL AUTOALLOCATE DEFAULT&lt;br /&gt;
 NOCOMPRESS  SEGMENT SPACE MANAGEMENT AUTO&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Capture the tablespace objects&amp;#039; metadata====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cat&amp;lt;&amp;lt;EOCAT &amp;gt;expdp_adst_ads_archive_metadata.par&lt;br /&gt;
userid=&amp;#039;/ as sysdba&amp;#039;&lt;br /&gt;
dumpfile=adst_ads_archive_metadata.dmp&lt;br /&gt;
logfile=expdp_adst_ads_archive_metadata.log&lt;br /&gt;
tablespaces=ADS_ARCHIVE&lt;br /&gt;
parallel=20&lt;br /&gt;
content=metadata_only&lt;br /&gt;
exclude=statistics&lt;br /&gt;
EOCAT&lt;br /&gt;
&lt;br /&gt;
expdp parfile=expdp_adst_ads_archive_metadata.par&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Find the partitions with data from the most recent month====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cat &amp;lt;&amp;lt;EOCAT&amp;gt;/tmp/adst_ads_archive_partitions.sql&lt;br /&gt;
set termo off echo off lines 1000 feedb off headi off newpa none trims on&lt;br /&gt;
spool /tmp/adst_ads_archive_partitions.lst&lt;br /&gt;
select table_owner||&amp;#039;.&amp;#039;||table_name||&amp;#039;:&amp;#039;||partition_name&lt;br /&gt;
from   dba_tab_partitions&lt;br /&gt;
where  tablespace_name = &amp;#039;ADS_ARCHIVE&amp;#039;&lt;br /&gt;
and    partition_name like &amp;#039;Y2017_Q1_M01%&amp;#039;&lt;br /&gt;
/&lt;br /&gt;
spool off&lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;@/tmp/adst_ads_archive_partitions.sql&amp;quot; | sqlplus / as sysdba&lt;br /&gt;
EOCAT&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
produces...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_CBA_BGAAP_ARC:Y2017_Q1_M01_D07&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_IFRS_ARC:Y2017_Q1_M02_D26&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_IFRS_ARC:Y2017_Q1_M02_D25&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_IFRS_ARC:Y2017_Q1_M02_D19&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_IFRS_ARC:Y2017_Q1_M02_D18&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_IFRS_ARC:Y2017_Q1_M02_D12&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_IFRS_ARC:Y2017_Q1_M02_D11&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_IFRS_ARC:Y2017_Q1_M02_D05&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_BGAAP_ARC:Y2017_Q1_M02_D26&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_BGAAP_ARC:Y2017_Q1_M02_D25&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_BGAAP_ARC:Y2017_Q1_M02_D19&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_BGAAP_ARC:Y2017_Q1_M02_D18&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_BGAAP_ARC:Y2017_Q1_M02_D12&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_BGAAP_ARC:Y2017_Q1_M02_D11&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_BGAAP_ARC:Y2017_Q1_M02_D05&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_BGAAP_ARC:Y2017_Q1_M02_D04&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_BGAAP_ARC:Y2017_Q1_M01_D29&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_BGAAP_ARC:Y2017_Q1_M01_D28&lt;br /&gt;
...&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_BGAAP_ARC:Y2017_Q1_M01_D22&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_BGAAP_ARC:Y2017_Q1_M01_D21&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_BGAAP_ARC:Y2017_Q1_M01_D15&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_BGAAP_ARC:Y2017_Q1_M01_D14&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_BGAAP_ARC:Y2017_Q1_M01_D08&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_BGAAP_ARC:Y2017_Q1_M01_D07&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_BGAAP_ARC:Y2017_Q1_M01_D01&lt;br /&gt;
ADS_ARCHIVE.BIL_MTH_INV_CTR_ARC:Y2017_Q1_M01_D01&lt;br /&gt;
ADS_ARCHIVE.BIL_DAY_INV_CTR_ARC:Y2017_Q1_M01_D01&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_IFRS_ARC:Y2017_Q1_M02_D04&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_IFRS_ARC:Y2017_Q1_M01_D29&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_IFRS_ARC:Y2017_Q1_M01_D28&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_IFRS_ARC:Y2017_Q1_M01_D22&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Export the data in these partitions====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cat&amp;lt;&amp;lt;EOCAT &amp;gt;expdp_adst_ads_archive_partitions.par&lt;br /&gt;
userid=&amp;#039;/ as sysdba&amp;#039;&lt;br /&gt;
dumpfile=adst_ads_archive_Y2017_%U.dmp&lt;br /&gt;
logfile=expdp_adst_ads_archive_Y2017.log&lt;br /&gt;
EOCAT&lt;br /&gt;
&lt;br /&gt;
cat /tmp/adst_ads_archive_partitions.lst | perl -p -i -e &amp;#039;s/^/tables=/&amp;#039;g &amp;gt;&amp;gt;expdp_adst_ads_archive_partitions.par&lt;br /&gt;
&lt;br /&gt;
cat&amp;lt;&amp;lt;EOCAT &amp;gt;&amp;gt;expdp_adst_ads_archive_partitions.par&lt;br /&gt;
parallel=20&lt;br /&gt;
exclude=statistics&lt;br /&gt;
EOCAT&lt;br /&gt;
&lt;br /&gt;
expdp parfile=expdp_adst_ads_archive_partitions.par&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Drop the old tablespace====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
drop tablespace ads_archive including contents and datafiles&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Recreate the tablepspace using the metadata capture above====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
create tablespace &amp;quot;ADS_ARCHIVE&amp;quot;&lt;br /&gt;
datafile &amp;#039;/oracle/tst/ora_data3/adst/ads_archive01.dbf&amp;#039; size 100M autoextend on next 50M maxsize unlimited&lt;br /&gt;
,        &amp;#039;/oracle/tst/ora_data3/adst/ads_archive02.dbf&amp;#039; size 100M autoextend on next 50M maxsize unlimited&lt;br /&gt;
,        &amp;#039;/oracle/tst/ora_data3/adst/ads_archive03.dbf&amp;#039; size 100M autoextend on next 50M maxsize unlimited&lt;br /&gt;
,        &amp;#039;/oracle/tst/ora_data3/adst/ads_archive04.dbf&amp;#039; size 100M autoextend on next 50M maxsize unlimited&lt;br /&gt;
,        &amp;#039;/oracle/tst/ora_data3/adst/ads_archive05.dbf&amp;#039; size 100M autoextend on next 50M maxsize unlimited&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Import the tablespace metadata====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cat&amp;lt;&amp;lt;EOCAT &amp;gt;impdp_adst_ads_archive_metadata.par&lt;br /&gt;
userid=&amp;#039;/ as sysdba&amp;#039;&lt;br /&gt;
dumpfile=adst_ads_archive_metadata.dmp&lt;br /&gt;
logfile=impdp_adst_ads_archive_metadata.log&lt;br /&gt;
EOCAT&lt;br /&gt;
&lt;br /&gt;
impdp parfile=impdp_adst_ads_archive_metadata.par&lt;br /&gt;
&lt;br /&gt;
select &amp;#039;alter index &amp;#039;|| owner||&amp;#039;.&amp;#039;||index_name||&amp;#039; rebuild online parallel 8;&amp;#039;&lt;br /&gt;
from   dba_indexes&lt;br /&gt;
where  status = &amp;#039;UNUSABLE&amp;#039;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Import the last month partition data====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cat&amp;lt;&amp;lt;EOCAT &amp;gt;impdp_adst_ads_archive_partitions.par&lt;br /&gt;
userid=&amp;#039;/ as sysdba&amp;#039;&lt;br /&gt;
dumpfile=adst_ads_archive_Y2017_%U.dmp&lt;br /&gt;
logfile=impdp_adst_ads_archive_Y2017.log&lt;br /&gt;
table_exists_action=append&lt;br /&gt;
parallel=20&lt;br /&gt;
EOCAT&lt;br /&gt;
&lt;br /&gt;
impdp parfile=impdp_adst_ads_archive_partitions.par&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Write to a TCP/IP socket from PL/SQL===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
declare&lt;br /&gt;
 bt_conn               utl_tcp.connection;&lt;br /&gt;
 retval                binary_integer;&lt;br /&gt;
 l_sequence            varchar2(30) := &amp;#039;Sequence Number 101021&amp;#039;;&lt;br /&gt;
begin&lt;br /&gt;
 bt_conn := utl_tcp.open_connection(remote_host =&amp;gt; &amp;#039;10.10.1.1&amp;#039;&lt;br /&gt;
                                   ,remote_port =&amp;gt; 5000&lt;br /&gt;
                                   ,tx_timeout =&amp;gt; 1&lt;br /&gt;
                                   )&lt;br /&gt;
 ;&lt;br /&gt;
 retval := utl_tcp.write_line(bt_conn,l_sequence)&lt;br /&gt;
 ;&lt;br /&gt;
 utl_tcp.flush(bt_conn)&lt;br /&gt;
 ;&lt;br /&gt;
 utl_tcp.close_connection(bt_conn)&lt;br /&gt;
 ;&lt;br /&gt;
exception&lt;br /&gt;
 when others then&lt;br /&gt;
  raise_application_error(-20101, sqlerrm)&lt;br /&gt;
  ; &lt;br /&gt;
  utl_tcp.close_connection(bt_conn)&lt;br /&gt;
  ;&lt;br /&gt;
end&lt;br /&gt;
;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
and read from it using netcat in another session&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
nc -lk 5000&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
produces&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Sequence Number 101021&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Execute a script as a different user===&lt;br /&gt;
Some things have to be done as the user and cannot be done as sys (eg. creating and dropping jobs or create and drop a database link)&amp;lt;br /&amp;gt;&lt;br /&gt;
It is possible to login as the user by saving, changing and resetting his password (using identified by values) but using dbms_sys_sql is another option&amp;lt;br /&amp;gt;&lt;br /&gt;
Create a PL/SQL procedure to drop a db link&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
create or replace procedure drop_dblink ( p_schema_name in varchar2&lt;br /&gt;
                                        , p_dblink      in varchar2&lt;br /&gt;
                                        ) is&lt;br /&gt;
    l_plsql   varchar2(1000);&lt;br /&gt;
    l_cur     number;&lt;br /&gt;
    l_uid     number;&lt;br /&gt;
    l_rc      number;&lt;br /&gt;
begin&lt;br /&gt;
    select  du.user_id&lt;br /&gt;
    into    l_uid&lt;br /&gt;
    from    dba_users du&lt;br /&gt;
    where   du.username = p_schema_name&lt;br /&gt;
    ;&lt;br /&gt;
    plsql := &amp;#039;drop database link &amp;quot;&amp;#039;||p_dblink||&amp;#039;&amp;quot;&amp;#039;;&lt;br /&gt;
    l_cur := sys.dbms_sys_sql.open_cursor;&lt;br /&gt;
    sys.dbms_sys_sql.parse_as_user(&lt;br /&gt;
        c             =&amp;gt; l_cur,&lt;br /&gt;
        statement     =&amp;gt; l_plsql,&lt;br /&gt;
        language_flag =&amp;gt; dbms_sql.native,&lt;br /&gt;
        userid        =&amp;gt; l_uid&lt;br /&gt;
    );&lt;br /&gt;
    l_rc := sys.dbms_sys_sql.execute(l_cur);&lt;br /&gt;
    sys.dbms_sys_sql.close_cursor(l_cur);&lt;br /&gt;
end;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Generate the calls to the procedure with the required parameters&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select &amp;#039;exec drop_dblink (&amp;#039;&amp;#039;&amp;#039;|| owner ||&amp;#039;&amp;#039;&amp;#039;&amp;#039;||&amp;#039;, &amp;#039;||&amp;#039;&amp;#039;&amp;#039;&amp;#039;||db_link||&amp;#039;&amp;#039;&amp;#039;&amp;#039;||&amp;#039;);&amp;#039;&lt;br /&gt;
from   dba_db_links&lt;br /&gt;
where  owner   != &amp;#039;PUBLIC&amp;#039;&lt;br /&gt;
and    db_link like &amp;#039;%FTST%&amp;#039;&lt;br /&gt;
or     db_link like &amp;#039;%HDEV%&amp;#039;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
and this reveals the lines to be executed&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
exec drop_dblink (&amp;#039;USER1&amp;#039;, &amp;#039;DBL_FTST.WORLD&amp;#039;);&lt;br /&gt;
exec drop_dblink (&amp;#039;USER1&amp;#039;, &amp;#039;DBL_HDEV.WORLD&amp;#039;);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Drop the procedure when finished with it&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
drop procedure drop_dblink;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
or do it as an anonymous block in one go...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
declare&lt;br /&gt;
    uid number;&lt;br /&gt;
    sqltext varchar2(1000) := &amp;#039;drop database link &amp;quot;&amp;amp;DB_LINK&amp;quot;&amp;#039;;&lt;br /&gt;
    myint integer;&lt;br /&gt;
begin&lt;br /&gt;
    select user_id into uid from dba_users where username = &amp;#039;&amp;amp;USERNAME&amp;#039;;&lt;br /&gt;
    myint:=sys.dbms_sys_sql.open_cursor();&lt;br /&gt;
    sys.dbms_sys_sql.parse_as_user(myint,sqltext,dbms_sql.native,UID);&lt;br /&gt;
    sys.dbms_sys_sql.close_cursor(myint);&lt;br /&gt;
end;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Handling single quote marks inside SQL statements===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SQL&amp;gt; SELECT &amp;#039;D&amp;#039;&amp;#039;COSTA&amp;#039; name FROM DUAL;&lt;br /&gt;
&lt;br /&gt;
NAME&lt;br /&gt;
-------&lt;br /&gt;
D&amp;#039;COSTA&lt;br /&gt;
&lt;br /&gt;
Alternatively, use the 10g+ quoting method:&lt;br /&gt;
&lt;br /&gt;
SQL&amp;gt; SELECT q&amp;#039;$D&amp;#039;COSTA$&amp;#039; NAME FROM DUAL;&lt;br /&gt;
&lt;br /&gt;
NAME&lt;br /&gt;
-------&lt;br /&gt;
D&amp;#039;COSTA&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Run a script on all databases in /etc/oratab===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
export ORAENV_ASK=NO&lt;br /&gt;
for db in `awk -F: &amp;#039;NF &amp;amp;&amp;amp; $1 !~/[#*]/ {print $1}&amp;#039;  /etc/oratab`&lt;br /&gt;
do&lt;br /&gt;
    echo $db&lt;br /&gt;
    ORACLE_SID=$db&lt;br /&gt;
    . oraenv&lt;br /&gt;
    sqlplus -V&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Schedule a cron job to run on the last day of each month===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
0 23 28-31 * * [ $(date -d +1day +%d) -eq 1 ] &amp;amp;&amp;amp; su - oracle -c &amp;quot;dsmc  arch -server=SO_U_`hostname`_ORX_M_SOL &amp;#039;/oracle/export/PV6/expdp_PV6_D_FULL_`date +\%Y\%m\%d`*&amp;#039;&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===How to tell if a year is a leap year or not - using cal instead of reinventing the wheel===&lt;br /&gt;
Test: Why is Julian day 0, 17th November 1858?&amp;lt;br /&amp;gt;&lt;br /&gt;
Pretty comprehensive answer: [http://h71000.www7.hp.com/wizard/wiz_2315.html here] and [http://mentalfloss.com/article/51370/why-our-calendars-skipped-11-days-1752 here]&amp;lt;br /&amp;gt;&lt;br /&gt;
Also attempts to answer the question why typing &amp;#039;cal 09 1752&amp;#039; on Unix systems looks so odd!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
function leap {&lt;br /&gt;
#  This function tells you if the year passed in as a parameter is a leap year or not...&lt;br /&gt;
if [[ $(cal 2 ${1:-$(date &amp;#039;+%Y&amp;#039;)} | egrep &amp;#039;\&amp;lt;[[:digit:]]{1,2}\&amp;gt;&amp;#039; | wc -w) -eq 29 ]]; then&lt;br /&gt;
    leap=&amp;#039;Y&amp;#039;&lt;br /&gt;
else&lt;br /&gt;
    leap=&amp;#039;N&amp;#039;&lt;br /&gt;
fi&lt;br /&gt;
echo ${leap}&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Reset an expired (and/or locked) user password to the same value===&lt;br /&gt;
Can be used to save user passwords for example in a test environment before destroying them with a copy of production.&amp;lt;br /&amp;gt;&lt;br /&gt;
Simple, quick and easy version. Run this then pick and choose the statements you want to run.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 200 pages 200&lt;br /&gt;
col user_list for a200 head &amp;quot;Expired User List&amp;quot;&lt;br /&gt;
&lt;br /&gt;
select &amp;#039;alter user &amp;#039; ||su.name||&amp;#039; identified by values&amp;#039;||&amp;#039;&amp;#039;&amp;#039;&amp;#039;||spare4||&amp;#039;;&amp;#039;||su.password||&amp;#039;&amp;#039;&amp;#039; account unlock;&amp;#039; user_list&lt;br /&gt;
from   sys.user$ su&lt;br /&gt;
,      dba_users du&lt;br /&gt;
where  1=1&lt;br /&gt;
and    su.name              = du.username&lt;br /&gt;
and    du.oracle_maintained = &amp;#039;N&amp;#039;&lt;br /&gt;
and    (account_status      like &amp;#039;EXPIRED%&amp;#039; or account_status like &amp;#039;%LOCKED&amp;#039;)&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
More industrialised version. Create a package.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
create or replace package dba_utils&lt;br /&gt;
as&lt;br /&gt;
    procedure reset_password ( p_userlist in varchar2 );&lt;br /&gt;
end dba_utils;&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
create or replace package body dba_utils&lt;br /&gt;
as&lt;br /&gt;
&lt;br /&gt;
procedure reset_password ( p_userlist in varchar2 )&lt;br /&gt;
is&lt;br /&gt;
    cursor c1 ( p_userlist in varchar2 ) is&lt;br /&gt;
    select username&lt;br /&gt;
    ,      regexp_substr ( dbms_metadata.get_ddl(&amp;#039;USER&amp;#039;, username), &amp;#039;&amp;#039;&amp;#039;[^&amp;#039;&amp;#039;]+&amp;#039;&amp;#039;&amp;#039; ) pwd&lt;br /&gt;
    from   dba_users&lt;br /&gt;
    where  1=1&lt;br /&gt;
    and    username in upper( p_userlist )&lt;br /&gt;
    ;&lt;br /&gt;
begin&lt;br /&gt;
    dbms_output.enable(null);&lt;br /&gt;
    for r1 in c1 ( p_userlist )&lt;br /&gt;
    loop&lt;br /&gt;
        begin&lt;br /&gt;
            execute immediate &amp;#039;alter user &amp;#039; || r1.username || &amp;#039; account unlock&amp;#039;;&lt;br /&gt;
            execute immediate &amp;#039;alter user &amp;#039; || r1.username || &amp;#039; identified by values &amp;#039; || r1.pwd;&lt;br /&gt;
        exception&lt;br /&gt;
        when others then&lt;br /&gt;
            dbms_output.put_line(&amp;#039;Unable to modify user &amp;#039; || r1.username);&lt;br /&gt;
        end;&lt;br /&gt;
    end loop;&lt;br /&gt;
end reset_password;&lt;br /&gt;
&lt;br /&gt;
end dba_utils;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Call it&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set serveroutput on&lt;br /&gt;
exec dba_utils.reset_password (&amp;#039;STUART&amp;#039;);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Latch, mutex and beyond===&lt;br /&gt;
A fine example of how to write scripts from SQL*Plus that interact with the shell underneath&amp;lt;br /&amp;gt;&lt;br /&gt;
Found [https://andreynikolaev.wordpress.com/demonstration-scripts/cursor_pin_s_contention-sql/ here at andreynikolaev.wordpress.com]&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/*&lt;br /&gt;
     This file is part of demos for &amp;quot;Mutex Internals&amp;quot;  seminar v.04.04.2011&lt;br /&gt;
     Andrey S. Nikolaev (Andrey.Nikolaev@rdtex.ru) &lt;br /&gt;
     https://andreynikolaev.wordpress.com &lt;br /&gt;
 &lt;br /&gt;
     &amp;quot;Cursor: pin S&amp;quot; contention testcase.&lt;br /&gt;
 &lt;br /&gt;
     The script spawn several sessions to induce &amp;quot;Cursor: pin S&amp;quot;, &lt;br /&gt;
     creates AWR snapshots and generates AWR report&lt;br /&gt;
 &lt;br /&gt;
     Beware: The script will restart the test database.&lt;br /&gt;
 &lt;br /&gt;
     usage: sqlplus /nolog @cursor_pin_s_contention.sql &amp;lt;parallelism&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
*/ &lt;br /&gt;
connect / as sysdba&lt;br /&gt;
startup force&lt;br /&gt;
set echo off&lt;br /&gt;
set define %&lt;br /&gt;
set verify off&lt;br /&gt;
set head off&lt;br /&gt;
set linesize 300&lt;br /&gt;
 &lt;br /&gt;
/* spawn parallel processes to create load on mutex */&lt;br /&gt;
spool one_thread.tmp&lt;br /&gt;
select &amp;#039;set verify off&amp;#039; from dual;&lt;br /&gt;
select &amp;#039;alter session set session_cached_cursors = 50;&amp;#039; from dual; &lt;br /&gt;
select &amp;#039;begin for i in 1..1000000 loop&amp;#039; from dual;&lt;br /&gt;
select &amp;#039;      execute immediate &amp;#039;&amp;#039;select 1 from dual where 1=2&amp;#039;&amp;#039;;&amp;#039; from dual;&lt;br /&gt;
select &amp;#039;end loop; end;&amp;#039;||chr(10)||&amp;#039;/&amp;#039; from dual;&lt;br /&gt;
spool off&lt;br /&gt;
 &lt;br /&gt;
/* sleep while AWR initialized */&lt;br /&gt;
host sleep 5&lt;br /&gt;
 &lt;br /&gt;
exec dbms_workload_repository.create_snapshot();&lt;br /&gt;
 &lt;br /&gt;
spool many_threads.tmp&lt;br /&gt;
select &amp;#039;host sqlplus &amp;quot;/ as sysdba&amp;quot; @one_thread.tmp &amp;amp;&amp;#039;&lt;br /&gt;
from dba_objects where rownum &amp;lt;= %1;&lt;br /&gt;
spool off&lt;br /&gt;
 &lt;br /&gt;
@many_threads.tmp&lt;br /&gt;
host sleep 50&lt;br /&gt;
set echo on&lt;br /&gt;
exec dbms_workload_repository.create_snapshot();&lt;br /&gt;
set markup html on&lt;br /&gt;
set head on&lt;br /&gt;
spool mutex_sleep_history.htm&lt;br /&gt;
select to_char(SLEEP_TIMESTAMP,&amp;#039;hh:mi:ss.ff&amp;#039;) SLEEP_TIMESTAMP,MUTEX_ADDR,MUTEX_IDENTIFIER,MUTEX_TYPE,&lt;br /&gt;
       GETS,SLEEPS,REQUESTING_SESSION,BLOCKING_SESSION,&lt;br /&gt;
       LOCATION,MUTEX_VALUE from x$mutex_sleep_history order by sleep_timestamp;&lt;br /&gt;
spool off&lt;br /&gt;
 &lt;br /&gt;
set define &amp;amp;&lt;br /&gt;
set markup html off&lt;br /&gt;
set echo off heading on underline on;&lt;br /&gt;
column inst_num  heading &amp;quot;Inst Num&amp;quot;  new_value inst_num  format 99999;&lt;br /&gt;
column inst_name heading &amp;quot;Instance&amp;quot;  new_value inst_name format a12;&lt;br /&gt;
column db_name   heading &amp;quot;DB Name&amp;quot;   new_value db_name   format a12;&lt;br /&gt;
column dbid      heading &amp;quot;DB Id&amp;quot;     new_value dbid      format 9999999999 just c;&lt;br /&gt;
select d.dbid            dbid&lt;br /&gt;
     , d.name            db_name&lt;br /&gt;
     , i.instance_number inst_num&lt;br /&gt;
     , i.instance_name   inst_name&lt;br /&gt;
  from v$database d,&lt;br /&gt;
       v$instance i;&lt;br /&gt;
define num_days=1;&lt;br /&gt;
define report_type=&amp;#039;html&amp;#039;;&lt;br /&gt;
col end_snap new_value end_snap;&lt;br /&gt;
col begin_snap new_value begin_snap;&lt;br /&gt;
select max(snap_id) end_snap from dba_hist_snapshot where dbid=&amp;amp;dbid;&lt;br /&gt;
select max(snap_id) begin_snap from dba_hist_snapshot where dbid=&amp;amp;dbid and snap_id &amp;lt; &amp;amp;end_snap;&lt;br /&gt;
define report_name=&amp;#039;awr_report.htm&amp;#039;;&lt;br /&gt;
@?/rdbms/admin/awrrpti&lt;br /&gt;
exit&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==shell==&lt;br /&gt;
[http://www.databasejournal.com/features/oracle/article.php/3869076/Alert-Log-Scraping-with-Oracles-ADRCI-Utility.htm Alert Log scraping with ADRCI]&lt;br /&gt;
&lt;br /&gt;
====Count the number of background processes for a particular SID====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SID=RAVJDE1&lt;br /&gt;
ps -ef|cut -c54-100|awk -v SID=$SID &amp;#039;$0 ~ /&amp;#039;$SID&amp;#039;$/ {print}&amp;#039;|wc -l&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or ...this will work with any OS (so long as the process is at the end of the &amp;lt;strong&amp;gt;ps -ef&amp;lt;/strong&amp;gt; or &amp;lt;strong&amp;gt;ps -aux&amp;lt;/strong&amp;gt; listing&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SID=RAVJDE1&lt;br /&gt;
ps -ef|awk -v SID=$SID -F_ &amp;#039;{ $NF ~ /&amp;#039;$SID&amp;#039;$/ {print} }&amp;#039;|wc -l&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Pick the columns you want in the ps listing&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ps -efo user,pid,ppid=MOM -o args&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Find Oracle errors in the most recent DataPump log files====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
00 09 * * * /home/tools/scripts/oracle/dosh &amp;#039;find /oracle/export -name &amp;quot;expdp*log&amp;quot; -mtime -1 -exec grep ORA- {} \; -ls&amp;#039; | mailx -s &amp;#039;Datapump errors for &amp;lt;customer&amp;gt;last night&amp;#039; stuart@domain.com&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Find the 10 largest directories on a particular filesystem====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
du -ag /oracle | sort -nr | head -n 10&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Find the 10 largest files on a particular mount point====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
find /home -size +1G -ls | sort -nr +6 | head -10&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
find /home -xdev -ls | sort -nr +6 | head -10&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Split a file in pieces using sed====&lt;br /&gt;
Using fixed line numbers&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sed -ne &amp;#039;1,12p&amp;#039; file &amp;gt; text.part1&lt;br /&gt;
sed -ne &amp;#039;13,$p&amp;#039; file &amp;gt; text.part2&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Using line with a /pattern/ on it&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sed -e &amp;#039;/hello/q&amp;#039; tt.dat | grep -v hello &amp;gt; text.part1&lt;br /&gt;
sed -n `sed -n &amp;#039;/hello/=&amp;#039; tt.dat`&amp;#039;,$p&amp;#039; tt.dat | grep -v hello &amp;gt; text.part2&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Split a file in pieces using Perl====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
perl -ne &amp;#039;print if 1 .. /marker line/&amp;#039; text.dat &amp;gt;text.part1&lt;br /&gt;
perl -ne &amp;#039;print if /marker line/ .. eof()&amp;#039; text.dat &amp;gt;text.part2&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Find and display RMAN errors in an RMAN log file====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sed -ne &amp;#039;/^RMAN-/,/^$/p&amp;#039;  RMAN_&amp;lt;SID&amp;gt;_&amp;lt;DATE&amp;gt;.log&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==cmd==&lt;br /&gt;
*[http://www.dba-oracle.com/t_scripts_windows_export.htm Database Export - from DBA Oracle (Burleson)]&lt;br /&gt;
==Perl==&lt;br /&gt;
===For all files in a directory, replace a keyword (SSIIDD) in a file with another (a parameter)===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
for i in `ls`&lt;br /&gt;
do&lt;br /&gt;
    perl -p -i -e &amp;#039;s/SSIIDD/&amp;#039;$SID&amp;#039;/g&amp;#039; $i&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Parse tnsnames.ora to get just the service names===&lt;br /&gt;
[[http://stackoverflow.com/questions/12605415/parsing-tnsnames-ora-with-regex-to-just-get-name from here]]&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
perl -ne &amp;#039;print if m/^([^#()\W ][a-zA-Z.]*(?:[.][a-zA-Z]*\s?=)?)/&amp;#039; $TNS_ADMIN/tnsnames.ora&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===and use that to check the listener status===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
for svc in `perl -ne &amp;#039;print if m/^([^#()\W ][a-zA-Z.]*(?:[.][a-zA-Z]*\s?=)?)/&amp;#039; $TNS_ADMIN/tnsnames.ora | sed -e &amp;#039;s/=//&amp;#039;` ;do&lt;br /&gt;
    tnsping $svc&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Stuart</name></author>	</entry>

	<entry>
		<id>https://mailnest.com/dbawiki/index.php?title=Handy_scripts&amp;diff=3376</id>
		<title>Handy scripts</title>
		<link rel="alternate" type="text/html" href="https://mailnest.com/dbawiki/index.php?title=Handy_scripts&amp;diff=3376"/>
				<updated>2018-11-21T13:16:57Z</updated>
		
		<summary type="html">&lt;p&gt;Stuart: /* External table for the Alert log (pre 11g) */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==SQL==&lt;br /&gt;
* [[Database Overview - from idevelopment]] [http://www.idevelopment.info/data/Oracle/DBA_scripts/Database_Administration/dba_snapshot_database_10g.sql online version]&lt;br /&gt;
* [[Extract ddl with &amp;quot;dbms metadata.get ddl&amp;quot;]]&lt;br /&gt;
* [http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:83012348058 Connecting as another user via proxy in SQL*Plus]&lt;br /&gt;
* [http://www.petefinnigan.com/tools.htm Password cracker and role and priv tools from Pete Finnigan]&lt;br /&gt;
* [http://www.oracle.com/technetwork/articles/sql/11g-pivot-097235.html Using pivot tables in SQL - XML and XLS (Excel) also)]&lt;br /&gt;
===List all instances running on a server===&lt;br /&gt;
Sounds simple enough and indeed pre 12.1, is was as easy as either&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ps -ef | grep [p]mon | awk -F_ &amp;#039;{print $NF}&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or this one is safer in case you have an underscore character in your SID name!!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SIDLIST=$(${PS} -ef | ${GREP} [o]ra_pmon | ${AWK} &amp;#039;{print $NF}&amp;#039; | sed -e &amp;#039;s/ora_pmon_//&amp;#039; | egrep -v &amp;#039;grep|///|sed|awk|ASM|^$&amp;#039;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
but now we have the added complication of CDB/PDB (container / pluggable databases) so a fair bit more work is needed!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/ksh&lt;br /&gt;
# ==============================================================================&lt;br /&gt;
# Name         : list_server_db&lt;br /&gt;
# Description  : List all running databases found on a server&lt;br /&gt;
#&lt;br /&gt;
# Parameters   : none&lt;br /&gt;
#&lt;br /&gt;
# Notes        : none&lt;br /&gt;
#&lt;br /&gt;
# Modification History&lt;br /&gt;
# ====================&lt;br /&gt;
# When      Who               What&lt;br /&gt;
# ========= ================= ==================================================&lt;br /&gt;
# 21-DEC-16 Stuart Barkley    Created&lt;br /&gt;
# ==============================================================================&lt;br /&gt;
for db in $(ps -ef | grep [p]mon|awk -F_ &amp;#039;{print $NF}&amp;#039;)&lt;br /&gt;
do&lt;br /&gt;
    export ORACLE_SID=${db}&lt;br /&gt;
    ORAENV_ASK=NO&lt;br /&gt;
    . oraenv &amp;gt;/dev/null 2&amp;gt;&amp;amp;1&lt;br /&gt;
    sqlplus -s / as sysdba&amp;lt;&amp;lt;EOSQL&lt;br /&gt;
set serveroutput on feed off pages 0 head off newpa none&lt;br /&gt;
declare&lt;br /&gt;
    e_col_not_found exception;&lt;br /&gt;
    e_not_mounted   exception;&lt;br /&gt;
    pragma          exception_init(e_not_mounted, -01507);&lt;br /&gt;
    pragma          exception_init(e_col_not_found, -904);&lt;br /&gt;
    l_db_name       varchar2(20);&lt;br /&gt;
    l_database_role varchar2(20);&lt;br /&gt;
    l_cdb           varchar2(20);&lt;br /&gt;
    l_status        varchar2(20);&lt;br /&gt;
    type varchar2_tab is table of varchar2(240) index by binary_integer;&lt;br /&gt;
    t_pdbs          varchar2_tab;&lt;br /&gt;
begin&lt;br /&gt;
    begin&lt;br /&gt;
        dbms_output.enable(null);&lt;br /&gt;
        execute immediate &amp;#039;select name, database_role, cdb from v\$database&amp;#039; into l_db_name, l_database_role, l_cdb;&lt;br /&gt;
        if l_cdb = &amp;#039;YES&amp;#039; then&lt;br /&gt;
            l_status := &amp;#039;CDB&amp;#039;;&lt;br /&gt;
            execute immediate &amp;#039;select name from v\$pdbs&amp;#039; bulk collect into t_pdbs;&lt;br /&gt;
            for i in nvl(t_pdbs.first,1) .. nvl(t_pdbs.last,0)&lt;br /&gt;
            loop&lt;br /&gt;
                dbms_output.put_line (t_pdbs(i)||&amp;#039;:PDB&amp;#039;);&lt;br /&gt;
            end loop;&lt;br /&gt;
        else&lt;br /&gt;
            l_status := &amp;#039;Independent&amp;#039;;  -- col CDB exists but this is not one&lt;br /&gt;
        end if;&lt;br /&gt;
        if l_database_role like &amp;#039;%STANDBY%&amp;#039; then&lt;br /&gt;
            l_status := &amp;#039;Standby&amp;#039;;&lt;br /&gt;
        end if;&lt;br /&gt;
    exception&lt;br /&gt;
    when e_not_mounted then&lt;br /&gt;
        l_status := &amp;#039;Not Mounted&amp;#039;;&lt;br /&gt;
    when e_col_not_found then&lt;br /&gt;
        l_status := &amp;#039;pre12&amp;#039;;&lt;br /&gt;
    end;&lt;br /&gt;
&lt;br /&gt;
    dbms_output.put_line (&amp;#039;${db}&amp;#039;||&amp;#039;:&amp;#039;||l_status);&lt;br /&gt;
&lt;br /&gt;
end;&lt;br /&gt;
/&lt;br /&gt;
EOSQL&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Run a command or script on all databases in tnsnames.ora===&lt;br /&gt;
Very handy if you have a global tnsnames.ora accessible to all clients.&amp;lt;br /&amp;gt;&lt;br /&gt;
So from a client install, this has access to all databases.&amp;lt;br /&amp;gt;&lt;br /&gt;
Any files created can be created on the client so no need to scp to all the machines to recover spool files etc.&amp;lt;br /&amp;gt;&lt;br /&gt;
Downside: Cannot connect as sysdba across tns so password will need to be known for whatever user is used.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/ksh&lt;br /&gt;
TNSNAMES=&amp;quot;./tnsnames.ora&amp;quot;&lt;br /&gt;
[[ ! -r &amp;quot;${TNSNAMES}&amp;quot; ]] &amp;amp;&amp;amp; echo &amp;quot;${TNSNAMES} is not accessible&amp;quot; &amp;amp;&amp;amp; exit 1&lt;br /&gt;
&lt;br /&gt;
SIDLIST=$(perl -ne &amp;#039;print &amp;quot;$1\n&amp;quot; if /(?:SID|SERVICE_NAME)\s*=\s*(\S+?)\)/&amp;#039; ${TNSNAMES}|sort|uniq|xargs)&lt;br /&gt;
for SID in ${SIDLIST}&lt;br /&gt;
do&lt;br /&gt;
    echo &amp;quot;Processing $SID&amp;quot;&lt;br /&gt;
    ls -al | grep &amp;quot;^d&amp;quot; | grep &amp;quot;\_${SID}&amp;quot; &amp;gt;/dev/null&lt;br /&gt;
    if [[ $? -ne 0 ]]; then&lt;br /&gt;
        echo &amp;#039;exit&amp;#039; | sqlplus system/xxxxxx@${SID} @ReviewLite17.1.sql &amp;gt;/dev/null 2&amp;gt;&amp;amp;1&lt;br /&gt;
    else&lt;br /&gt;
        echo &amp;quot;directory already exists so must have done this SID&amp;quot;&lt;br /&gt;
    fi&lt;br /&gt;
done&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Run a command or script on all databases in oratab===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/usr/bin/ksh&lt;br /&gt;
# ==============================================================================&lt;br /&gt;
# Name         : all_db_do&lt;br /&gt;
# Description  : Loops over all the databases in oratab and executes the&lt;br /&gt;
#                specified SQL command - be careful!&lt;br /&gt;
#&lt;br /&gt;
# Parameters   : -v flag for verbose&lt;br /&gt;
#                [-f &amp;lt;filename&amp;gt; | &amp;lt;quoted SQL command to be executed&amp;gt;]&lt;br /&gt;
#&lt;br /&gt;
# Example      : all_db_do &amp;#039;alter system switch logfile;&amp;#039;&lt;br /&gt;
#                all_db_do -f sessions.sql&lt;br /&gt;
#&lt;br /&gt;
# Notes        : none&lt;br /&gt;
#&lt;br /&gt;
# Modification History&lt;br /&gt;
# ====================&lt;br /&gt;
# When      Who               What&lt;br /&gt;
# ========= ================= ==================================================&lt;br /&gt;
# 14-JAN-13 Stuart Barkley    Created&lt;br /&gt;
# 25-FEB-13 Stuart Barkley    Adapt for Solaris&lt;br /&gt;
# 21-MAR-13 Stuart Barkley    Check db is running first&lt;br /&gt;
# 29-APR-13 Stuart Barkley    Added verbose flag processing&lt;br /&gt;
# 24-MAY-13 Stuart Barkley    Wrap / as sysdba in quotes for older versions&lt;br /&gt;
# 23-JUN-16 Stuart Barkley    Add -f to run a file containing sql&lt;br /&gt;
# ==============================================================================&lt;br /&gt;
&lt;br /&gt;
PROGNAME=$(basename $0)&lt;br /&gt;
OS=$(uname -s)&lt;br /&gt;
&lt;br /&gt;
AWK=$(which awk)&lt;br /&gt;
GREP=$(which grep)&lt;br /&gt;
if [[ &amp;quot;${OS}&amp;quot; == &amp;quot;SunOS&amp;quot; ]]; then&lt;br /&gt;
    AWK=/usr/xpg4/bin/awk&lt;br /&gt;
    GREP=/usr/xpg4/bin/grep&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
if [[ ! -r /etc/oratab ]]; then&lt;br /&gt;
    if [[ &amp;quot;${OS}&amp;quot; == &amp;quot;SunOS&amp;quot; ]]; then&lt;br /&gt;
        echo &amp;quot;oratab is not where we want it. Please run &amp;#039;ln -s /var/opt/oracle/oratab /etc/oratab&amp;#039; as root and retry&amp;quot; &amp;amp;&amp;amp; exit 1&lt;br /&gt;
    else&lt;br /&gt;
        echo &amp;quot;Either Oracle is not installed or database is running without an oratab&amp;quot; &amp;amp;&amp;amp; exit 1&lt;br /&gt;
    fi&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
# -------------------------&lt;br /&gt;
# get the arguments, if any&lt;br /&gt;
# -------------------------&lt;br /&gt;
unset VERBOSE&lt;br /&gt;
while getopts &amp;quot;vf:&amp;quot; flag&lt;br /&gt;
do&lt;br /&gt;
    case &amp;quot;$flag&amp;quot; in&lt;br /&gt;
    v) VERBOSE=1;;&lt;br /&gt;
    f) FILE2RUN=$OPTARG;;&lt;br /&gt;
    esac&lt;br /&gt;
done&lt;br /&gt;
shift $((OPTIND-1))&lt;br /&gt;
&lt;br /&gt;
if [[ -z ${FILE2RUN} ]]; then&lt;br /&gt;
    # no file, need an SQL supplied&lt;br /&gt;
    if [[ -z $1 ]]; then&lt;br /&gt;
        echo &amp;quot;Usage: $0 [-v] [-f &amp;lt;filename&amp;gt; | &amp;lt;quoted SQL command to be executed&amp;gt;]&amp;quot;&lt;br /&gt;
        echo &amp;quot;eg: $0 -f sessions.sql&amp;quot;&lt;br /&gt;
        echo &amp;quot;eg: $0 &amp;#039;alter system switch logfile;&amp;#039;&amp;quot;&lt;br /&gt;
        exit 1&lt;br /&gt;
    fi&lt;br /&gt;
    SQL=$1&lt;br /&gt;
elif [[ -s ${FILE2RUN} ]]; then&lt;br /&gt;
    # file supplied and exists&lt;br /&gt;
    SQL=&amp;quot;@${FILE2RUN}&amp;quot;&lt;br /&gt;
else&lt;br /&gt;
    # file supplied, does it exist&lt;br /&gt;
    echo &amp;quot;File ${FILE2RUN} is empty or does not exist&amp;quot;&lt;br /&gt;
    echo &amp;quot;Usage: $0 [-v] [-f &amp;lt;filename&amp;gt; | &amp;lt;quoted SQL command to be executed&amp;gt;]&amp;quot;&lt;br /&gt;
    echo &amp;quot;eg: $0 -f sessions.sql&amp;quot;&lt;br /&gt;
    echo &amp;quot;eg: $0 &amp;#039;alter system switch logfile;&amp;#039;&amp;quot;&lt;br /&gt;
    exit 1&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
export ORAENV_ASK=NO&lt;br /&gt;
&lt;br /&gt;
for db in $(${AWK} -F: &amp;#039;NF &amp;amp;&amp;amp; $1 !~/[#*]/ {print $1}&amp;#039;  /etc/oratab)&lt;br /&gt;
do&lt;br /&gt;
    if ( [[ $1 != &amp;quot;startup&amp;quot; ]] &amp;amp;&amp;amp; [[ $(ps -ef | ${GREP} -c -E [o]ra_pmon_${db}) -eq 0 ]] ); then&lt;br /&gt;
        [[ ! -z &amp;quot;$VERBOSE&amp;quot; ]] &amp;amp;&amp;amp; echo &amp;quot;$db is not running, skipping...&amp;quot;&lt;br /&gt;
        continue&lt;br /&gt;
    fi&lt;br /&gt;
    echo&lt;br /&gt;
    [[ ! -z &amp;quot;$VERBOSE&amp;quot; ]] &amp;amp;&amp;amp; echo &amp;quot;vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv&amp;quot;&lt;br /&gt;
    [[ ! -z &amp;quot;$VERBOSE&amp;quot; ]] &amp;amp;&amp;amp; echo $db&lt;br /&gt;
    ORACLE_SID=$db&lt;br /&gt;
    . oraenv &amp;gt;/dev/null&lt;br /&gt;
    sqlplus -s &amp;quot;/ as sysdba&amp;quot; &amp;lt;&amp;lt;EOSQL&lt;br /&gt;
define SID=$ORACLE_SID&lt;br /&gt;
col comp_name format a50&lt;br /&gt;
col value for a40&lt;br /&gt;
set linesize 1000&lt;br /&gt;
set pagesize 100&lt;br /&gt;
$SQL&lt;br /&gt;
EOSQL&lt;br /&gt;
    [[ ! -z &amp;quot;$VERBOSE&amp;quot; ]] &amp;amp;&amp;amp; echo &amp;quot;^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^&amp;quot;&lt;br /&gt;
done&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
all_db_do &amp;quot;create or replace directory data_pump_dir as &amp;#039;/oracle/export/&amp;amp;SID&amp;#039;;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
all_db_do &amp;quot;archive log list&amp;quot;&lt;br /&gt;
&lt;br /&gt;
all_db_do &amp;quot;shutdown immediate&amp;quot;&lt;br /&gt;
&lt;br /&gt;
all_db_do &amp;#039;alter system set log_archive_dest_1=&amp;quot;location=/oracle/arch/&amp;amp;SID&amp;quot; scope=both;&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Run an SQL command on behalf of another user===&lt;br /&gt;
It can be used to execute any sql command as a specified user provided this procedure is created in sys schema.&amp;lt;br /&amp;gt;&lt;br /&gt;
* not got this working properly yet *&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set serveroutput on&lt;br /&gt;
create or replace procedure run_sql_as_user ( p_schema_name in varchar2&lt;br /&gt;
                                            , p_sql         in varchar2&lt;br /&gt;
                                            ) is&lt;br /&gt;
    l_user_id dba_users.user_id%type;&lt;br /&gt;
    l_cursor  number;&lt;br /&gt;
    l_rc      number;&lt;br /&gt;
begin&lt;br /&gt;
    dbms_output.enable(null);&lt;br /&gt;
    begin&lt;br /&gt;
        select u.user_id&lt;br /&gt;
        into   l_user_id&lt;br /&gt;
        from   dba_users u&lt;br /&gt;
        where  u.username = p_schema_name;&lt;br /&gt;
    exception&lt;br /&gt;
    when no_data_found then&lt;br /&gt;
        raise_application_error (-20001, &amp;#039;Cannot find user &amp;#039;||p_schema_name);&lt;br /&gt;
    end;&lt;br /&gt;
    l_cursor := dbms_sys_sql.open_cursor;&lt;br /&gt;
    dbms_sys_sql.parse_as_user ( c             =&amp;gt; l_cursor&lt;br /&gt;
                               , statement     =&amp;gt; p_sql&lt;br /&gt;
                               , language_flag =&amp;gt; dbms_sql.native&lt;br /&gt;
                               , userid        =&amp;gt; l_user_id&lt;br /&gt;
    );&lt;br /&gt;
    l_rc := dbms_sys_sql.execute(l_cursor);&lt;br /&gt;
    dbms_sys_sql.close_cursor(l_cursor);&lt;br /&gt;
exception&lt;br /&gt;
when others then&lt;br /&gt;
    raise_application_error (-20001, &amp;#039;ERROR: &amp;#039;||sqlerrm);&lt;br /&gt;
end;&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Run a script on all databases listed in tnsnames.ora===&lt;br /&gt;
Can run an SQL command file on all SID/SERVICE found in a tnsnames.ora file. I use this from a client laptop having a global tns file on it.&amp;lt;br /&amp;gt;&lt;br /&gt;
This way it&amp;#039;s not necessary to copy the file onto every host before executing it. Any files created by the script will be created on the client.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/ksh&lt;br /&gt;
&lt;br /&gt;
TNSNAMES=&amp;quot;./tnsnames.ora&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[ ! -r &amp;quot;${TNSNAMES}&amp;quot; ]] &amp;amp;&amp;amp; echo &amp;quot;${TNSNAMES} is not accessible&amp;quot; &amp;amp;&amp;amp; exit 1&lt;br /&gt;
&lt;br /&gt;
SIDLIST=$(perl -ne &amp;#039;print &amp;quot;$1\n&amp;quot; if /(?:SID|SERVICE_NAME)\s*=\s*(\S+?)\)/&amp;#039; ${TNSNAMES}|sort|uniq|xargs)&lt;br /&gt;
for SID in ${SIDLIST}&lt;br /&gt;
do&lt;br /&gt;
    echo &amp;quot;Processing $SID&amp;quot;&lt;br /&gt;
    ls -al | grep &amp;quot;^d&amp;quot; | grep &amp;quot;\_${SID}&amp;quot; &amp;gt;/dev/null&lt;br /&gt;
    if [[ $? -ne 0 ]]; then&lt;br /&gt;
        echo &amp;#039;exit&amp;#039; | sqlplus system/password@${SID} @ReviewLite17.1.sql &amp;gt;/dev/null 2&amp;gt;&amp;amp;1&lt;br /&gt;
    else&lt;br /&gt;
        echo &amp;quot;directory already exists so must have done this SID&amp;quot;&lt;br /&gt;
    fi&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===List invalid objects===&lt;br /&gt;
 set lines 200&lt;br /&gt;
 set pages 200&lt;br /&gt;
 col obj format a40&lt;br /&gt;
 select owner||&amp;#039;.&amp;#039;||object_name obj&lt;br /&gt;
 ,      object_type&lt;br /&gt;
 from   dba_objects&lt;br /&gt;
 where  1=1&lt;br /&gt;
 and    status = &amp;#039;INVALID&amp;#039;;&lt;br /&gt;
===Recompile all invalid objects===&lt;br /&gt;
@?/rdbms/admin/utlrp.sql&lt;br /&gt;
===See how much space is left in the flash recovery area (FRA)===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select name&lt;br /&gt;
,      to_char (space_limit, &amp;#039;999,999,999,999&amp;#039;) as space_limit&lt;br /&gt;
,      to_char (space_limit - space_used + space_reclaimable&lt;br /&gt;
,               &amp;#039;999,999,999,999&amp;#039;)&lt;br /&gt;
           as space_available&lt;br /&gt;
,      round ( (space_used - space_reclaimable) / space_limit * 100, 1)&lt;br /&gt;
           as pct_full&lt;br /&gt;
from   v$recovery_file_dest;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# ==============================================&lt;br /&gt;
# Check FRA to see how much space is reclaimable&lt;br /&gt;
# ==============================================&lt;br /&gt;
fra_reclaim_check() {&lt;br /&gt;
&lt;br /&gt;
LOGFILE=${RMAN_LogDir}/${ORACLE_SID}_`date &amp;#039;+%Y%m&amp;#039;`_${V_SCRIPT}.log&lt;br /&gt;
sqlplus &amp;quot;/ as sysdba&amp;quot; &amp;lt;&amp;lt;EOSQL &amp;gt; /tmp/results.$$&lt;br /&gt;
set vefify off echo off heading off newpage none linesize 1000 echo off&lt;br /&gt;
select &amp;#039;Filesystem:&amp;#039;||name||&lt;br /&gt;
       &amp;#039;; Total(Gb):&amp;#039;||round((space_limit/1073741824),2) ||&lt;br /&gt;
       &amp;#039;; Reclaimable(Gb):&amp;#039;||round((space_reclaimable/1073741824),2) ||&lt;br /&gt;
       &amp;#039;; Reclaimable(%):&amp;#039;||round( ((space_reclaimable/1073741824)/(space_limit/1073741824)*100),2 )&lt;br /&gt;
from   v$recovery_file_dest&lt;br /&gt;
/&lt;br /&gt;
EOSQL&lt;br /&gt;
cat /tmp/results.$$ &amp;gt;&amp;gt; $LOGFILE&lt;br /&gt;
rm /tmp/results.$$&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===How far back can we flashback?===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
col time_now              for a25&lt;br /&gt;
col time_oldest_flashback for a25&lt;br /&gt;
select to_char(sysdate,&amp;#039;DD-MON-YY HH24:MI&amp;#039;)                    time_now&lt;br /&gt;
,      to_char(fdl.oldest_flashback_time, &amp;#039;DD-MON-YY HH24:MI&amp;#039;) time_oldest_flashback&lt;br /&gt;
,      round((sysdate-fdl.oldest_flashback_time)*24,1)         hours_flashback_possible&lt;br /&gt;
from   v$database d&lt;br /&gt;
,      v$flashback_database_log fdl&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===DBA privs tables===&lt;br /&gt;
 DBA_AQ_AGENT_PRIVS&lt;br /&gt;
 DBA_COL_PRIVS&lt;br /&gt;
 DBA_PRIV_AUDIT_OPTS&lt;br /&gt;
 DBA_REPGROUP_PRIVILEGES&lt;br /&gt;
 DBA_ROLE_PRIVS&lt;br /&gt;
 DBA_RSRC_CONSUMER_GROUP_PRIVS&lt;br /&gt;
 DBA_RSRC_MANAGER_SYSTEM_PRIVS&lt;br /&gt;
 DBA_SYS_PRIVS&lt;br /&gt;
 DBA_TAB_PRIVS&lt;br /&gt;
 DBA_WM_SYS_PRIVS&lt;br /&gt;
 DBA_WORKSPACE_PRIVS&lt;br /&gt;
&lt;br /&gt;
===Schedule a shell job===&lt;br /&gt;
 begin&lt;br /&gt;
     dbms_scheduler.create_program ( program_name   =&amp;gt; &amp;#039;myshelljob&amp;#039;&lt;br /&gt;
                                   , program_action =&amp;gt; &amp;#039;/home/oracle/scripts/shell.sh&amp;#039;&lt;br /&gt;
                                   , program_type   =&amp;gt; &amp;#039;EXECUTABLE&amp;#039;&lt;br /&gt;
                                   , comments       =&amp;gt; &amp;#039;Run a shell&amp;#039;&lt;br /&gt;
                                   , enabled        =&amp;gt; TRUE&lt;br /&gt;
                                   );&lt;br /&gt;
 end;&lt;br /&gt;
 /&lt;br /&gt;
===Start the job===&lt;br /&gt;
 begin&lt;br /&gt;
     dbms_sheduler.create_job ( job_name     =&amp;gt; &amp;#039;myshelljob&amp;#039;&lt;br /&gt;
                              , program_name =&amp;gt; &amp;#039;myshelljob&amp;#039;&lt;br /&gt;
                              , start_date   =&amp;gt;&lt;br /&gt;
                              );&lt;br /&gt;
 /&lt;br /&gt;
&lt;br /&gt;
===What statement is a user running?===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select a.sid&lt;br /&gt;
,      a.serial#&lt;br /&gt;
,      b.sql_text&lt;br /&gt;
from   v$session a&lt;br /&gt;
,      v$sqlarea b&lt;br /&gt;
where  a.sql_address = b.address&lt;br /&gt;
and    a.username    = &amp;#039;&amp;amp;username&amp;#039;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===See what statements all users are running===&lt;br /&gt;
Useful to see what is happening when process limit is reached&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 300 pages 1000&lt;br /&gt;
&lt;br /&gt;
col username for a10&lt;br /&gt;
col command for 999 head &amp;quot;CMD&amp;quot;&lt;br /&gt;
col lockwait for a10&lt;br /&gt;
col status for a8&lt;br /&gt;
col schemaname for a12&lt;br /&gt;
col osuser for a10&lt;br /&gt;
col process for a10&lt;br /&gt;
col program for a20&lt;br /&gt;
col machine for a10&lt;br /&gt;
col action for a10&lt;br /&gt;
col module for a10&lt;br /&gt;
col identifier for a10&lt;br /&gt;
col event for a27&lt;br /&gt;
col state for a8&lt;br /&gt;
col service_name for a10&lt;br /&gt;
col serial# for 999999&lt;br /&gt;
&lt;br /&gt;
select a.username&lt;br /&gt;
,      a.command&lt;br /&gt;
,      a.lockwait&lt;br /&gt;
,      a.status&lt;br /&gt;
,      a.schemaname&lt;br /&gt;
,      a.osuser&lt;br /&gt;
,      a.process&lt;br /&gt;
,      a.machine&lt;br /&gt;
,      a.program&lt;br /&gt;
,      a.type&lt;br /&gt;
--,      a.sql_exec_start&lt;br /&gt;
--,      a.plsql_object_id&lt;br /&gt;
--,      a.plsql_subprogram_id&lt;br /&gt;
--,      a.module&lt;br /&gt;
--,      a.action&lt;br /&gt;
,      a.logon_time&lt;br /&gt;
,      a.event&lt;br /&gt;
,      a.wait_time&lt;br /&gt;
,      a.seconds_in_wait&lt;br /&gt;
,      a.state&lt;br /&gt;
--,      a.service_name&lt;br /&gt;
,      a.serial#&lt;br /&gt;
,      b.sql_text&lt;br /&gt;
from   v$session a&lt;br /&gt;
,      v$sqlarea b&lt;br /&gt;
where  a.sql_address = b.address&lt;br /&gt;
order  by a.logon_time desc&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
set lines 80&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===A logminer session===&lt;br /&gt;
Mine all SQL statements in a 10 minute period&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sqlplus / as sysdba&lt;br /&gt;
alter session set nls_date_format = &amp;#039;DD-MON-YYYY HH24:MI:SS&amp;#039;;&lt;br /&gt;
execute dbms_logmnr.start_logmnr ( starttime =&amp;gt; &amp;#039;27-OCT-2009 11:05:00&amp;#039;&lt;br /&gt;
                                 , endtime   =&amp;gt; &amp;#039;27-OCT-2009 11:15:00&amp;#039;&lt;br /&gt;
                                 , options   =&amp;gt; dbms_logmnr.dict_from_online_catalog+dbms_logmnr.continuous_mine&lt;br /&gt;
                                 );&lt;br /&gt;
create table mycontents as select * from v$logmnr_contents;&lt;br /&gt;
execute dbms_logmnr.end_logmnr(); &lt;br /&gt;
&lt;br /&gt;
select * from mycontents;&lt;br /&gt;
&lt;br /&gt;
drop table mycontents;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Huge Pages===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
#&lt;br /&gt;
# hugepages_settings.sh&lt;br /&gt;
#&lt;br /&gt;
# Linux bash script to compute values for the&lt;br /&gt;
# recommended HugePages/HugeTLB configuration&lt;br /&gt;
#&lt;br /&gt;
# Note: This script does calculation for all shared memory&lt;br /&gt;
# segments available when the script is run, no matter it&lt;br /&gt;
# is an Oracle RDBMS shared memory segment or not.&lt;br /&gt;
# Check for the kernel version&lt;br /&gt;
KERN=`uname -r | awk -F. &amp;#039;{ printf(&amp;quot;%d.%d\n&amp;quot;,$1,$2); }&amp;#039;`&lt;br /&gt;
# Find out the HugePage size&lt;br /&gt;
HPG_SZ=`grep Hugepagesize /proc/meminfo | awk {&amp;#039;print $2&amp;#039;}`&lt;br /&gt;
# Start from 1 pages to be on the safe side and guarantee 1 free HugePage&lt;br /&gt;
NUM_PG=1&lt;br /&gt;
# Cumulative number of pages required to handle the running shared memory segments&lt;br /&gt;
for SEG_BYTES in `ipcs -m | awk {&amp;#039;print $5&amp;#039;} | grep &amp;quot;[0-9][0-9]*&amp;quot;`&lt;br /&gt;
do&lt;br /&gt;
   MIN_PG=`echo &amp;quot;$SEG_BYTES/($HPG_SZ*1024)&amp;quot; | bc -q`&lt;br /&gt;
   if [ $MIN_PG -gt 0 ]; then&lt;br /&gt;
      NUM_PG=`echo &amp;quot;$NUM_PG+$MIN_PG+1&amp;quot; | bc -q`&lt;br /&gt;
   fi&lt;br /&gt;
done&lt;br /&gt;
# Finish with results&lt;br /&gt;
case $KERN in&lt;br /&gt;
   &amp;#039;2.4&amp;#039;) HUGETLB_POOL=`echo &amp;quot;$NUM_PG*$HPG_SZ/1024&amp;quot; | bc -q`;&lt;br /&gt;
          echo &amp;quot;Recommended setting: vm.hugetlb_pool = $HUGETLB_POOL&amp;quot; ;;&lt;br /&gt;
   &amp;#039;2.6&amp;#039; | &amp;#039;3.8&amp;#039;) echo &amp;quot;Recommended setting: vm.nr_hugepages = $NUM_PG&amp;quot; ;;&lt;br /&gt;
    *) echo &amp;quot;Unrecognized kernel version $KERN. Exiting.&amp;quot; ;;&lt;br /&gt;
esac&lt;br /&gt;
# End&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Pretty longops listing===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 2000 pages 1000&lt;br /&gt;
col opname for a34 head &amp;quot;Job&amp;quot;&lt;br /&gt;
col message for a60&lt;br /&gt;
col perc_done for a10 head &amp;quot;Done&amp;quot;&lt;br /&gt;
col started for a18&lt;br /&gt;
col killer for a15&lt;br /&gt;
col mins_busy head &amp;quot;Mins busy&amp;quot;&lt;br /&gt;
col mins_left head &amp;quot;Mins left&amp;quot;&lt;br /&gt;
select sid||&amp;#039;,&amp;#039;||serial#                       killer&lt;br /&gt;
,      opname&lt;br /&gt;
,      message&lt;br /&gt;
,      round ((sofar/totalwork),4)*100||&amp;#039;%&amp;#039;    perc_done&lt;br /&gt;
,      to_char(start_time,&amp;#039;DD-MON-YY HH24:MI&amp;#039;) started&lt;br /&gt;
,      floor(elapsed_seconds/60)               mins_busy&lt;br /&gt;
,      ceil(time_remaining/60)                 mins_left&lt;br /&gt;
from   v$session_longops&lt;br /&gt;
where  1=1&lt;br /&gt;
and    sofar     != totalwork&lt;br /&gt;
and    totalwork != 0&lt;br /&gt;
and    opname    like &amp;#039;RMAN%&amp;#039;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select * from v$session where module=&amp;#039;Data Pump Worker&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or attach to the impdp job and it shows percentage done.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Get the SID from v$session_longops and plug it into v$session to check the SQL command details.&lt;br /&gt;
&lt;br /&gt;
Current Running SQLs&lt;br /&gt;
--------------------&lt;br /&gt;
set pages 1000 lines 2000&lt;br /&gt;
col program  format a40&lt;br /&gt;
col sql_text format a130&lt;br /&gt;
&lt;br /&gt;
select s.sid&lt;br /&gt;
,      s.status&lt;br /&gt;
,      s.last_call_et&lt;br /&gt;
,      s.program&lt;br /&gt;
,      sa.sql_id&lt;br /&gt;
,      sa.sql_text&lt;br /&gt;
from   v$session s&lt;br /&gt;
,      v$sqlarea sa&lt;br /&gt;
where  s.sql_id = sa.sql_id&lt;br /&gt;
and    s.sid = &amp;#039;&amp;amp;sid&amp;#039;&lt;br /&gt;
/ &lt;br /&gt;
&lt;br /&gt;
set pages 1000 lines 2000&lt;br /&gt;
col USERNAME for a10&lt;br /&gt;
col OSUSER   for a10&lt;br /&gt;
col MACHINE  for a10&lt;br /&gt;
&lt;br /&gt;
select s.sid&lt;br /&gt;
,      s.serial#&lt;br /&gt;
,      p.spid&lt;br /&gt;
,      s.username&lt;br /&gt;
,      s.osuser&lt;br /&gt;
,      s.status&lt;br /&gt;
,      s.process fg_pid&lt;br /&gt;
,      s.longon_time&lt;br /&gt;
,      s.machine&lt;br /&gt;
,      p.spid bg_pid&lt;br /&gt;
from   gv$session s&lt;br /&gt;
,      gv$process p&lt;br /&gt;
where  s.addr = p.addr&lt;br /&gt;
and    s.sid  = &amp;#039;&amp;amp;sid&amp;#039;&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
$ps -ef | grep &amp;lt;spid&amp;gt;&lt;br /&gt;
&lt;br /&gt;
set pages 1000 lines 2000&lt;br /&gt;
SELECT INST_ID&lt;br /&gt;
,      SID&lt;br /&gt;
,      SERIAL#&lt;br /&gt;
,      SQL_ID&lt;br /&gt;
,      USERNAME&lt;br /&gt;
,      PROGRAM&lt;br /&gt;
,      MACHINE&lt;br /&gt;
,      SERVICE_NAME&lt;br /&gt;
FROM   GV$SESSION&lt;br /&gt;
WHERE  SID IN (&amp;#039;&amp;lt;SID_NO.1&amp;gt;&amp;#039;,&amp;#039;&amp;lt;SID_NO.2&amp;gt;&amp;#039;)&lt;br /&gt;
/&lt;br /&gt;
Active Running SQLs&lt;br /&gt;
--------------------&lt;br /&gt;
set pages 1000 lines 2000&lt;br /&gt;
col SPID     for a10&lt;br /&gt;
col PROGRAM  for a15&lt;br /&gt;
col OSUSER   for a10&lt;br /&gt;
col ACTION   for a10&lt;br /&gt;
col EVENT    for a25&lt;br /&gt;
col SQL_TEXT for a25&lt;br /&gt;
col MACHINE  for a10&lt;br /&gt;
col P1TEXT   for a10 &lt;br /&gt;
col P2TEXT   for a10&lt;br /&gt;
col P3TEXT   for a10  &lt;br /&gt;
SELECT b.sid&lt;br /&gt;
,      b.serial#&lt;br /&gt;
,      a.spid&lt;br /&gt;
,      b.sql_id&lt;br /&gt;
,      b.program&lt;br /&gt;
,      b.osuser&lt;br /&gt;
,      b.machine&lt;br /&gt;
,      b.type&lt;br /&gt;
,      b.event&lt;br /&gt;
,      b.action&lt;br /&gt;
,      b.p1text&lt;br /&gt;
,      b.p2text&lt;br /&gt;
,      b.p3text&lt;br /&gt;
,      b.state&lt;br /&gt;
,      c.sql_text&lt;br /&gt;
,      b.logon_time&lt;br /&gt;
FROM   v$process a&lt;br /&gt;
,      v$session b&lt;br /&gt;
,      v$sqltext c&lt;br /&gt;
WHERE  a.addr           = b.paddr&lt;br /&gt;
AND    b.sql_hash_value = c.hash_value&lt;br /&gt;
AND    b.STATUS         = &amp;#039;ACTIVE&amp;#039;&lt;br /&gt;
AND    b.sid            = &amp;#039;&amp;amp;sid&amp;#039;&lt;br /&gt;
ORDER  BY a.spid&lt;br /&gt;
,      c.piece&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
OR - Use the below Query &lt;br /&gt;
&lt;br /&gt;
Longops.sql&lt;br /&gt;
----------- &lt;br /&gt;
set pages 50000 lines 32767&lt;br /&gt;
col OPNAME for a10&lt;br /&gt;
col SID form 9999&lt;br /&gt;
col SERIAL form 9999999&lt;br /&gt;
col PROGRAM for a10&lt;br /&gt;
col USERNAME for a10&lt;br /&gt;
col SQL_TEXT for a40&lt;br /&gt;
col START_TIME for a10&lt;br /&gt;
col LAST_UPDATE_TIME for a10&lt;br /&gt;
col TARGET for a25&lt;br /&gt;
col MESSAGE for a25&lt;br /&gt;
&lt;br /&gt;
alter session set nls_date_format = &amp;#039;DD-MM-YYYY HH24:MI:SS&amp;#039;;&lt;br /&gt;
&lt;br /&gt;
SELECT l.inst_id,l.sid, l.serial#, l.sql_id, l.opname, l.username, l.target, l.sofar, l.totalwork, l.start_time,l.last_update_time,round(l.time_remaining/60,2) &amp;quot;REMAIN MINS&amp;quot;, round(l.elapsed_seconds/60,2) &amp;quot;ELAPSED MINS&amp;quot;, round((l.time_remaining+l.elapsed_seconds)/60,2) &amp;quot;TOTAL MINS&amp;quot;, ROUND(l.SOFAR/l.TOTALWORK*100,2) &amp;quot;%_COMPLETE&amp;quot;, l.message,s.sql_text &lt;br /&gt;
FROM gv$session_longops l &lt;br /&gt;
LEFT OUTER JOIN v$sql s on s.hash_value=l.sql_hash_value and s.address=l.sql_address and s.child_number=0&lt;br /&gt;
WHERE l.OPNAME NOT LIKE &amp;#039;RMAN%&amp;#039; AND l.OPNAME NOT LIKE &amp;#039;%aggregate%&amp;#039; AND l.TOTALWORK != 0 AND l.sofar&amp;lt;&amp;gt;l.totalwork AND l.time_remaining &amp;gt; 0&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Apply the database patch after the ORACLE_HOME has been patched===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ORAENV_ASK=NO&lt;br /&gt;
export ORACLE_SID=$1&lt;br /&gt;
. oraenv&lt;br /&gt;
&lt;br /&gt;
sqlplus /nolog &amp;lt;&amp;lt;EOSQL&lt;br /&gt;
connect / as sysdba&lt;br /&gt;
startup&lt;br /&gt;
@?/rdbms/admin/catbundle.sql psu apply&lt;br /&gt;
@?/rdbms/admin/utlrp.sql&lt;br /&gt;
purge dba_recyclebin;&lt;br /&gt;
&lt;br /&gt;
prompt check patch apply...&lt;br /&gt;
set lines 150&lt;br /&gt;
col action_time for a50&lt;br /&gt;
col comp_name for a50&lt;br /&gt;
col comments for a50&lt;br /&gt;
&lt;br /&gt;
select action_time,action,comments from sys.registry\$history where trunc(action_time) = trunc(sysdate);&lt;br /&gt;
select comp_name,version,status,modified from dba_registry;&lt;br /&gt;
exit&lt;br /&gt;
EOSQL&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Show how much archivelog data is generated per day===&lt;br /&gt;
A companion script for &amp;#039;how many log switches in a day&amp;#039;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
col orderby noprint&lt;br /&gt;
select trunc(first_time) orderby&lt;br /&gt;
,      to_char(first_time,&amp;#039;DD-MON-YYYY&amp;#039;) &amp;quot;Date&amp;quot;&lt;br /&gt;
,      round(sum(bytes/1024/1024/1024),2) arch_logs_gigs&lt;br /&gt;
from (&lt;br /&gt;
    select unique (blocks * block_size) bytes,&lt;br /&gt;
    thread#,&lt;br /&gt;
    sequence#,&lt;br /&gt;
    resetlogs_change#,&lt;br /&gt;
    first_time&lt;br /&gt;
    from v$archived_log&lt;br /&gt;
)&lt;br /&gt;
group by trunc(first_time)&lt;br /&gt;
,      to_char(first_time, &amp;#039;DD-MON-YYYY&amp;#039;)&lt;br /&gt;
order by trunc(first_time) desc&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Abort a hanging database even when sysdba cannot connect===&lt;br /&gt;
Unable to connect to database with sqlplus / as sysdba because audit file cannot be created?&lt;br /&gt;
* [http://tech.e2sn.com/oracle/troubleshooting/hang/how-to-log-on-even-when-sysdba-can-t-do-so tech.e2sn.com]&lt;br /&gt;
* [http://blog.dbi-services.com/oracle-is-hanging-dont-forget-hanganalyze-and-systemstate/ blog.dbi-services.com]&lt;br /&gt;
Instead of just killing the pmon process, there is a kinder (and more useful) way to kill the database.&amp;lt;br /&amp;gt;&lt;br /&gt;
Use the hidden, undocumented &amp;#039;prelim&amp;#039; switch parameter to sqlplus to make a connection to the database without creating SGA session data structures.&amp;lt;br /&amp;gt;&lt;br /&gt;
It can be very useful for hang analysis so the possible cause can be found after the database has been restarted.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sqlplus -prelim / as sysdba&lt;br /&gt;
oradebug unlimit&lt;br /&gt;
oradebug hanganalyze 3&lt;br /&gt;
oradebug setmypid              -- or oradebug setorapname diag&lt;br /&gt;
oradebug dump ashdumpseconds 30&lt;br /&gt;
oradebug dump systemstate 10   -- or oradebug dump systemstate 266&lt;br /&gt;
oradebug tracefile_name&lt;br /&gt;
shutdown abort&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Lists Oracle session with kill session statement all ready to go===&lt;br /&gt;
disconnect attempts to kill the o/s processes too. kill doesn&amp;#039;t.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
col killer for a60&lt;br /&gt;
col osuser for a12&lt;br /&gt;
col logon  for a23&lt;br /&gt;
col spid   for a8&lt;br /&gt;
col username for a15&lt;br /&gt;
col program for a50&lt;br /&gt;
set lines 2000&lt;br /&gt;
select &amp;#039;alter system disconnect session &amp;#039;&amp;#039;&amp;#039;||s.sid||&amp;#039;,&amp;#039;||s.serial#||&amp;#039;&amp;#039;&amp;#039; immediate;&amp;#039; killer&lt;br /&gt;
,      s.inst_id&lt;br /&gt;
,      to_char(s.logon_time,&amp;#039;DD-MON-YY HH24:MI:SS&amp;#039;) logon&lt;br /&gt;
,      sci.osuser&lt;br /&gt;
,      p.spid&lt;br /&gt;
,      s.username&lt;br /&gt;
,      s.program&lt;br /&gt;
from   gv$session s&lt;br /&gt;
,      gv$session_connect_info sci&lt;br /&gt;
,      gv$process p&lt;br /&gt;
where  1=1&lt;br /&gt;
and    p.addr     = s.paddr&lt;br /&gt;
and    p.inst_id  = s.inst_id&lt;br /&gt;
and    s.sid      = sci.sid&lt;br /&gt;
and    s.serial#  = sci.serial#&lt;br /&gt;
and    s.type    != &amp;#039;BACKGROUND&amp;#039;&lt;br /&gt;
and    sci.osuser = &amp;#039;oraibm&amp;#039;&lt;br /&gt;
order  by s.logon_time desc&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
KILLER                                                          INST_ID LOGON                   OSUSER       SPID     USERNAME        PROGRAM&lt;br /&gt;
------------------------------------------------------------ ---------- ----------------------- ------------ -------- --------------- --------------------------------------------------&lt;br /&gt;
alter system disconnect session &amp;#039;490,33947&amp;#039; immediate;                1 23-JUN-16 13:30:53      oraibm       23205    SYS             sqlplus@benouerp07 (TNS V1-V3)&lt;br /&gt;
alter system disconnect session &amp;#039;490,33947&amp;#039; immediate;                1 23-JUN-16 13:30:53      oraibm       23205    SYS             sqlplus@benouerp07 (TNS V1-V3)&lt;br /&gt;
alter system disconnect session &amp;#039;490,33947&amp;#039; immediate;                1 23-JUN-16 13:30:53      oraibm       23205    SYS             sqlplus@benouerp07 (TNS V1-V3)&lt;br /&gt;
alter system disconnect session &amp;#039;490,33947&amp;#039; immediate;                1 23-JUN-16 13:30:53      oraibm       23205    SYS             sqlplus@benouerp07 (TNS V1-V3)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===How much space is being used by a guaranteed restore point?===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
show parameter recovery&lt;br /&gt;
set numwi 15&lt;br /&gt;
set lines 200&lt;br /&gt;
col name for a40&lt;br /&gt;
col time for a23&lt;br /&gt;
col gigs_limit head &amp;quot;Max (but check df -g also!)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
select name&lt;br /&gt;
,      time&lt;br /&gt;
,      round(storage_size/1024/1024/1024,2) gigs_used&lt;br /&gt;
from   v$restore_point&lt;br /&gt;
where  1=1&lt;br /&gt;
and    guarantee_flashback_database = &amp;#039;YES&amp;#039;&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
select * from v$flash_recovery_area_usage&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
select name&lt;br /&gt;
,      round(space_used/1024/1024/1024,2) gigs_used&lt;br /&gt;
,      round(space_limit/1024/1024/1024,2) gigs_limit&lt;br /&gt;
,      space_reclaimable&lt;br /&gt;
,      number_of_files&lt;br /&gt;
from v$recovery_file_dest&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Get statistics for LOB columns in a table===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select &lt;br /&gt;
  max(dbms_lob.getlength(lob_content)) max_len&lt;br /&gt;
, avg(dbms_lob.getlength(lob_content)) avg_len&lt;br /&gt;
, min(dbms_lob.getlength(lob_content)) min_len&lt;br /&gt;
, sum(case when dbms_lob.getlength(lob_content) &amp;lt;= 4000 then 1&lt;br /&gt;
else 0 end) &amp;quot;&amp;lt;4k&amp;quot;&lt;br /&gt;
, sum(case when dbms_lob.getlength(lob_content) &amp;gt; 4000 then 1&lt;br /&gt;
else 0 end) &amp;quot;&amp;gt;4k&amp;quot;&lt;br /&gt;
, sum(case when dbms_lob.getlength(lob_content) is null then 1 else&lt;br /&gt;
0 end) &amp;quot;is null&amp;quot;&lt;br /&gt;
from &amp;amp;tablename&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===badprivs.sql===&lt;br /&gt;
Check to see if any ordinary users have privileges / access / grants / rights they should not have&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select grantee, privilege, admin_option&lt;br /&gt;
from   sys.dba_sys_privs&lt;br /&gt;
where  (       privilege like &amp;#039;% ANY %&amp;#039;&lt;br /&gt;
        or     privilege in (&amp;#039;BECOME USER&amp;#039;, &amp;#039;UNLIMITED TABLESPACE&amp;#039;)&lt;br /&gt;
        or     admin_option = &amp;#039;YES&amp;#039;&lt;br /&gt;
       )&lt;br /&gt;
and    grantee not in (&amp;#039;SYS&amp;#039;, &amp;#039;SYSTEM&amp;#039;, &amp;#039;OUTLN&amp;#039;, &amp;#039;AQ_ADMINISTRATOR_ROLE&amp;#039;,&lt;br /&gt;
                      &amp;#039;DBA&amp;#039;, &amp;#039;EXP_FULL_DATABASE&amp;#039;, &amp;#039;IMP_FULL_DATABASE&amp;#039;,&lt;br /&gt;
                      &amp;#039;OEM_MONITOR&amp;#039;, &amp;#039;CTXSYS&amp;#039;, &amp;#039;DBSNMP&amp;#039;, &amp;#039;IFSSYS&amp;#039;,&lt;br /&gt;
                      &amp;#039;IFSSYS$CM&amp;#039;, &amp;#039;MDSYS&amp;#039;, &amp;#039;ORDPLUGINS&amp;#039;, &amp;#039;ORDSYS&amp;#039;,&lt;br /&gt;
                      &amp;#039;TIMESERIES_DBA&amp;#039;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Generate a list of tablespaces ready for a migration===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set echo off&lt;br /&gt;
set lines 300&lt;br /&gt;
set pages 0&lt;br /&gt;
Set headi off&lt;br /&gt;
set feedb off&lt;br /&gt;
set long 32000&lt;br /&gt;
&lt;br /&gt;
spool migration_create_target_tablespaces.sql&lt;br /&gt;
&lt;br /&gt;
exec dbms_metadata.set_transform_param(dbms_metadata.session_transform,&amp;#039;SQLTERMINATOR&amp;#039;,TRUE);&lt;br /&gt;
select DBMS_METADATA.GET_DDL(&amp;#039;TABLESPACE&amp;#039;,tablespace_name) from dba_tablespaces&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
spool off&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===List the privileges assigned to users on directories===&lt;br /&gt;
table_name is the name of the directory...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select grantor&lt;br /&gt;
,      grantee&lt;br /&gt;
,      table_schema&lt;br /&gt;
,      table_name&lt;br /&gt;
,      privilege&lt;br /&gt;
from   all_tab_privs&lt;br /&gt;
where  table_name = &amp;#039;DATA_PUMP_DIR&amp;#039;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===List the privileges assigned to users on packages/procedures===&lt;br /&gt;
table_name is the name of the package...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select grantor&lt;br /&gt;
,      grantee&lt;br /&gt;
,      table_schema&lt;br /&gt;
,      table_name&lt;br /&gt;
,      privilege&lt;br /&gt;
from   all_tab_privs&lt;br /&gt;
where  upper(table_name) like upper(&amp;#039;%UTL_FILE%&amp;#039;)&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===List the system privileges assigned to a user (used to copy user as or clone user as)===&lt;br /&gt;
Maybe this one is better [[Extract ddl with &amp;quot;dbms metadata.get ddl&amp;quot;]]&lt;br /&gt;
&lt;br /&gt;
 SELECT LPAD(&amp;#039; &amp;#039;, 2*level) || granted_role &amp;quot;USER PRIVS&amp;quot;&lt;br /&gt;
 FROM (&lt;br /&gt;
   SELECT NULL grantee,  username granted_role&lt;br /&gt;
   FROM dba_users&lt;br /&gt;
   WHERE username LIKE UPPER(&amp;#039;%&amp;amp;uname%&amp;#039;)&lt;br /&gt;
   UNION&lt;br /&gt;
   SELECT grantee, granted_role&lt;br /&gt;
   FROM dba_role_privs&lt;br /&gt;
   UNION&lt;br /&gt;
   SELECT grantee, privilege&lt;br /&gt;
   FROM dba_sys_privs)&lt;br /&gt;
 START WITH grantee IS NULL&lt;br /&gt;
 CONNECT BY grantee = prior granted_role;&lt;br /&gt;
&lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
 SELECT path&lt;br /&gt;
 FROM (&lt;br /&gt;
   SELECT grantee,&lt;br /&gt;
          sys_connect_by_path(privilege, &amp;#039;:&amp;#039;)||&amp;#039;:&amp;#039;||grantee path&lt;br /&gt;
   FROM (&lt;br /&gt;
     SELECT grantee, privilege, 0 role&lt;br /&gt;
     FROM dba_sys_privs&lt;br /&gt;
     UNION ALL&lt;br /&gt;
     SELECT grantee, granted_role, 1 role&lt;br /&gt;
     FROM dba_role_privs)&lt;br /&gt;
   CONNECT BY privilege=prior grantee&lt;br /&gt;
   START WITH role = 0)&lt;br /&gt;
 WHERE grantee IN (&lt;br /&gt;
    SELECT username&lt;br /&gt;
    FROM dba_users&lt;br /&gt;
    WHERE lock_date IS NULL&lt;br /&gt;
    AND password != &amp;#039;EXTERNAL&amp;#039;&lt;br /&gt;
    AND username != &amp;#039;SYS&amp;#039;)&lt;br /&gt;
 OR grantee=&amp;#039;PUBLIC&amp;#039;&lt;br /&gt;
&lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
for a migration from 10g...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set headi off&lt;br /&gt;
set feedb off&lt;br /&gt;
set long  9999999&lt;br /&gt;
set pages 0&lt;br /&gt;
set lines 300&lt;br /&gt;
&lt;br /&gt;
spool migration_create_target_users_grants.sql&lt;br /&gt;
&lt;br /&gt;
select dbms_metadata.get_ddl(&amp;#039;USER&amp;#039;, username) || &amp;#039;;&amp;#039; ddl&lt;br /&gt;
from dba_users&lt;br /&gt;
where  1=1&lt;br /&gt;
and    username like upper(&amp;#039;%&amp;amp;&amp;amp;USER_NAME%&amp;#039;)&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
select &amp;#039;grant &amp;#039;||privilege|| &amp;#039; to &amp;#039; || grantee || &amp;#039;;&amp;#039;&lt;br /&gt;
from   dba_sys_privs&lt;br /&gt;
where  1=1&lt;br /&gt;
and    grantee like upper(&amp;#039;%&amp;amp;&amp;amp;USER_NAME%&amp;#039;)&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
select &amp;#039;grant &amp;#039;||granted_role|| &amp;#039; to &amp;#039; || grantee || &amp;#039;;&amp;#039;&lt;br /&gt;
from   dba_role_privs&lt;br /&gt;
where  1=1&lt;br /&gt;
and    grantee like upper(&amp;#039;%&amp;amp;&amp;amp;USER_NAME%&amp;#039;)&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
spool off&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or for a migration on 11g...!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set head off&lt;br /&gt;
set pages 0&lt;br /&gt;
set long 9999999&lt;br /&gt;
col ddl for a1000&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
SELECT DBMS_METADATA.GET_DDL(&amp;#039;USER&amp;#039;, USERNAME) || &amp;#039;;&amp;#039; DDL&lt;br /&gt;
FROM DBA_USERS&lt;br /&gt;
where  1=1&lt;br /&gt;
and    default_tablespace not in (&amp;#039;SYSTEM&amp;#039;,&amp;#039;SYSAUX&amp;#039;)&lt;br /&gt;
and    upper(username) like &amp;#039;%&amp;#039;||upper(&amp;#039;&amp;amp;&amp;amp;username&amp;#039;)||&amp;#039;%&amp;#039;&lt;br /&gt;
UNION ALL&lt;br /&gt;
SELECT DBMS_METADATA.GET_GRANTED_DDL(&amp;#039;ROLE_GRANT&amp;#039;, USERNAME) || &amp;#039;;&amp;#039; DDL&lt;br /&gt;
FROM DBA_USERS&lt;br /&gt;
where  1=1&lt;br /&gt;
and    default_tablespace not in (&amp;#039;SYSTEM&amp;#039;,&amp;#039;SYSAUX&amp;#039;)&lt;br /&gt;
and    upper(username) like &amp;#039;%&amp;#039;||upper(&amp;#039;&amp;amp;&amp;amp;username&amp;#039;)||&amp;#039;%&amp;#039;&lt;br /&gt;
UNION ALL&lt;br /&gt;
SELECT DBMS_METADATA.GET_GRANTED_DDL(&amp;#039;SYSTEM_GRANT&amp;#039;, USERNAME) || &amp;#039;;&amp;#039; DDL&lt;br /&gt;
FROM DBA_USERS&lt;br /&gt;
where  1=1&lt;br /&gt;
and    default_tablespace not in (&amp;#039;SYSTEM&amp;#039;,&amp;#039;SYSAUX&amp;#039;)&lt;br /&gt;
and    upper(username) like &amp;#039;%&amp;#039;||upper(&amp;#039;&amp;amp;&amp;amp;username&amp;#039;)||&amp;#039;%&amp;#039;&lt;br /&gt;
UNION ALL&lt;br /&gt;
SELECT DBMS_METADATA.GET_GRANTED_DDL(&amp;#039;OBJECT_GRANT&amp;#039;, USERNAME) || &amp;#039;;&amp;#039; DDL&lt;br /&gt;
FROM DBA_USERS&lt;br /&gt;
where  1=1&lt;br /&gt;
and    default_tablespace not in (&amp;#039;SYSTEM&amp;#039;,&amp;#039;SYSAUX&amp;#039;)&lt;br /&gt;
and    upper(username) like &amp;#039;%&amp;#039;||upper(&amp;#039;&amp;amp;&amp;amp;username&amp;#039;)||&amp;#039;%&amp;#039;&lt;br /&gt;
&lt;br /&gt;
spool migration_create_users_grants.sql&lt;br /&gt;
/&lt;br /&gt;
spool off&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Move datafiles between filesystems===&lt;br /&gt;
* [https://blogs.oracle.com/alejandrovargas/moving-a-datafile-from-file-system-to-asm Moving a datafile from File System to ASM (does not have to be ASM!) - oracle.com]&lt;br /&gt;
* [https://docs.oracle.com/database/121/OSTMG/GUID-3B8D0956-0888-452D-A9E4-9FB8D98577E0.htm#OSTMG89997 Moving Data Files Between Oracle ASM (does not have to be ASM!) Using RMAN - oracle.com]&lt;br /&gt;
* [https://oracle-base.com/articles/misc/renaming-or-moving-oracle-files Moving a data file online between filesystems - oracle-base.com]&lt;br /&gt;
====Set the relevant datafile offline====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter database datafile 125 offline;&lt;br /&gt;
alter database datafile 126 offline;&lt;br /&gt;
alter database datafile 127 offline;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Rename the files on the filesystem using o/s commands====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter tablespace ts_thaler_data_offline;&lt;br /&gt;
&lt;br /&gt;
host mv &amp;#039;/cln/tst/ora_data1/clnt/data4/ts_thaler_data_113.dbf&amp;#039; &amp;#039;/cln/tst/ora_data1/clnt/data1/ts_thaler_data_113.dbf&amp;#039;&lt;br /&gt;
host mv &amp;#039;/cln/tst/ora_data1/clnt/data4/ts_thaler_data_114.dbf&amp;#039; &amp;#039;/cln/tst/ora_data1/clnt/data1/ts_thaler_data_114.dbf&amp;#039;&lt;br /&gt;
host mv &amp;#039;/cln/tst/ora_data1/clnt/data4/ts_thaler_data_115.dbf&amp;#039; &amp;#039;/cln/tst/ora_data1/clnt/data1/ts_thaler_data_115.dbf&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Run the relevant alter commands to inform the control files of the new locations====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter database move datafile &amp;#039;/cln/tst/ora_data1/clnt/data4/ts_thaler_data_113.dbf&amp;#039; to &amp;#039;/cln/tst/ora_data1/clnt/data1/ts_thaler_data_113.dbf&amp;#039;&lt;br /&gt;
alter database move datafile &amp;#039;/cln/tst/ora_data1/clnt/data4/ts_thaler_data_114.dbf&amp;#039; to &amp;#039;/cln/tst/ora_data1/clnt/data1/ts_thaler_data_114.dbf&amp;#039;&lt;br /&gt;
alter database move datafile &amp;#039;/cln/tst/ora_data1/clnt/data4/ts_thaler_data_115.dbf&amp;#039; to &amp;#039;/cln/tst/ora_data1/clnt/data1/ts_thaler_data_115.dbf&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Recover the datafiles====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
recover datafile 125;&lt;br /&gt;
recover datafile 126;&lt;br /&gt;
recover datafile 127;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Set the relevant datafile online====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter database datafile 125 online;&lt;br /&gt;
alter database datafile 126 online;&lt;br /&gt;
alter database datafile 127 online;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Check all is well with the datafiles by using an appropriate statement====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 2000 pages 100&lt;br /&gt;
select file_id, file_name, status, online_status from dba_data_files where tablespace_name = &amp;#039;TS_THALER_DATA&amp;#039; order by 2;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Rename a datafile on 12c====&lt;br /&gt;
If you&amp;#039;re lucky enough to be on 12c, it&amp;#039;s one command - no need to offline the datafile!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SQL&amp;gt; alter database move datafile &amp;#039;/oracle/ora_data2/prod/data4/ts_thaler_data_113.dbf&amp;#039; to &amp;#039;/oracle/ora_data2/prod/data3/ts_thaler_data_113.dbf&amp;#039;;&lt;br /&gt;
&lt;br /&gt;
Database altered.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Pass parameter/argument into perl one-liner script from shell===&lt;br /&gt;
Trick? Just use ARGV to pass them in...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
FREQ=$(perl -e &amp;#039;my @CAL=split(&amp;quot;;&amp;quot;,$ARGV[0]);shift @CAL;print $CAL[$ARGV[1]];&amp;#039; -- &amp;quot;$LINE&amp;quot; $offset)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
DUMP_DATE=`perl -MTime::Local -e &amp;#039;print(timelocal(0,$ARGV[0],$ARGV[1],$ARGV[2],$ARGV[3],$ARGV[4]))&amp;#039; -- $MI $HH $DD $MM $YYYY`&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or export the variable from shell and access it via the ENV hash&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
export db=ENDP1&lt;br /&gt;
perl -p -i -e &amp;#039;s!DSMI_LOG.+$!DSMI_LOG           /oracle/$ENV{db}/admin/tdpoerror_$ENV{db}!&amp;#039; ${db}/admin/tdpo.opt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Return epoch seconds in Perl===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
perl -e &amp;#039;print time();&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or to convert a specific day of the year to epoch seconds&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
use POSIX;&lt;br /&gt;
my $epochsecs = mktime(0,0,0, $jday, 0, $year-1900);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or for a specific date (careful though - month is 0-11 not 1-12!...&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
use Time::Local;&lt;br /&gt;
#                          SS MM HH DD MM YYYY&lt;br /&gt;
my $epochsecs = timelocal (30,10,19,03,04,2014);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or more long-winded but delimited by anything...&amp;lt;br /&amp;gt;&lt;br /&gt;
Supply the date/time in any delimited format. Eg. YYYY-MM-DD:HH:MI&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/usr/bin/perl -w&lt;br /&gt;
use Time::Local;&lt;br /&gt;
&lt;br /&gt;
sub date2epoch { &lt;br /&gt;
  my($s) = @_;&lt;br /&gt;
  my($year, $month, $day, $hour, $minute, $second);&lt;br /&gt;
&lt;br /&gt;
  if($s =~ m{^\s*(\d{1,4})\W*0*(\d{1,2})\W*0*(\d{1,2})\W*0*&lt;br /&gt;
                 (\d{0,2})\W*0*(\d{0,2})\W*0*(\d{0,2})}x) {&lt;br /&gt;
    $year = $1;  $month = $2;   $day = $3;&lt;br /&gt;
    $hour = $4;  $minute = $5;  $second = $6;&lt;br /&gt;
    $hour |= 0;  $minute |= 0;  $second |= 0;  # defaults.&lt;br /&gt;
    $year = ($year&amp;lt;100 ? ($year&amp;lt;70 ? 2000+$year : 1900+$year) : $year);&lt;br /&gt;
    return timelocal($second,$minute,$hour,$day,$month-1,$year);  &lt;br /&gt;
  }&lt;br /&gt;
  return -1;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Return epoch seconds in DOS/VBS/Windows===&lt;br /&gt;
Paste this code into epoch.vbs&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
function date2epoch(p_date)&lt;br /&gt;
    date2epoch = DateDiff(&amp;quot;s&amp;quot;, &amp;quot;01/01/1970 00:00:00&amp;quot;, p_date)&lt;br /&gt;
end function&lt;br /&gt;
&lt;br /&gt;
Wscript.Echo date2epoch(Now())&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
and call from a DOS box like this&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cscript //nologo epoch.vbs&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Return date from epoch seconds in Perl===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
perl -e &amp;#039;print scalar (localtime (1243269270))&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Return epoch seconds from julian day number in Perl===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
use POSIX;&lt;br /&gt;
my ($year, $jday) = (2012,60);&lt;br /&gt;
my $epochsecs = mktime(0,0,0, $jday, 0, $year-1900);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Extract specific pieces of a date from an epoch timestamp in Perl===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
use POSIX;&lt;br /&gt;
# return localtime into an array&lt;br /&gt;
my @tm = localtime $epochsecs;&lt;br /&gt;
&lt;br /&gt;
my $yyyymmdd = strftime &amp;quot;%Y%m%d&amp;quot;, @tm;&lt;br /&gt;
print $yyyymmdd.&amp;quot;\n&amp;quot;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Return epoch seconds in Shell (linux)===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
date -d &amp;quot;2014/04/03 18:34:30&amp;quot; &amp;quot;+%s&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Return date from epoch seconds in Shell (linux)===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
date -d @1396542870&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Return epoch seconds in PL/SQL===&lt;br /&gt;
You cannot just use sysdate as that is timezone sensitive... (epoch seconds are in UTC/GMT)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select round((cast(sys_extract_utc(systimestamp) as date) - to_date(&amp;#039;01-JAN-1970 00:00:00&amp;#039;,&amp;#039;DD-MON-YYYY HH24:MI:SS&amp;#039;))*24*60*60) from dual;&lt;br /&gt;
or&lt;br /&gt;
select round((vd.created - to_date(&amp;#039;01-JAN-1970 00:00:00&amp;#039;,&amp;#039;DD-MON-YYYY HH24:MI:SS&amp;#039;))*24*60*60)  created from v$database vd;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
How long has this instance been up (in minutes)?&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select round((cast(sys_extract_utc(systimestamp) as date) - startup_time)*24*60) up_mins from v$instance;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Return date from epoch seconds in SQL===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select to_char(to_date(&amp;#039;19700101&amp;#039;,&amp;#039;YYYYMMDD&amp;#039;) + ((&amp;amp;epoch)/24/60/60),&amp;#039;DD-MON-YYYY HH24:MI:SS&amp;#039;) utc_date from dual;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===A database overview using the sys.plato package===&lt;br /&gt;
 exec plato.help;&lt;br /&gt;
or&lt;br /&gt;
 exec plato.complete(&amp;#039;HTM&amp;#039;);&lt;br /&gt;
&lt;br /&gt;
===List datafiles for a tablespace===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select *&lt;br /&gt;
from   dba_data_files&lt;br /&gt;
where  1=1&lt;br /&gt;
and    tablespace_name =&amp;#039;&amp;amp;ts_name&amp;#039;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Show graph of available and free space in tablespaces===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
-- =============================================================================&lt;br /&gt;
-- File Name    : http://www.oracle-base.com/dba/monitoring/ts_free_space.sql&lt;br /&gt;
-- Author       : Tim Hall&lt;br /&gt;
-- Description  : Displays a list of tablespaces and their used/full status.&lt;br /&gt;
-- Requirements : Access to the DBA views.&lt;br /&gt;
-- Call Syntax  : @ts_free_space.sql&lt;br /&gt;
-- Last Modified: 13-OCT-2012 - Created. Based on ts_full.sql&lt;br /&gt;
--&lt;br /&gt;
-- Modification History&lt;br /&gt;
-- ====================&lt;br /&gt;
-- When      Who               What&lt;br /&gt;
-- ========= ================= =================================================&lt;br /&gt;
-- 13-NOV-13 Stuart Barkley    Added cols free_pct and used_pct&lt;br /&gt;
-- =============================================================================&lt;br /&gt;
SET PAGESIZE 140 lines 180&lt;br /&gt;
COLUMN used_pct FORMAT A11&lt;br /&gt;
COLUMN max_used_pct FORMAT A11&lt;br /&gt;
&lt;br /&gt;
    SELECT tablespace_name                                                                      tablespace_name&lt;br /&gt;
    ,      size_mb                                                                              size_mb&lt;br /&gt;
    ,      free_mb                                                                              free_mb&lt;br /&gt;
    ,      TRUNC((free_mb/size_mb) * 100)                                                       free_pct&lt;br /&gt;
    ,      RPAD(&amp;#039; &amp;#039;|| RPAD(&amp;#039;X&amp;#039;,ROUND((size_mb-free_mb)/size_mb*10,0), &amp;#039;X&amp;#039;),11,&amp;#039;-&amp;#039;)              used_pct&lt;br /&gt;
    ,      max_size_mb                                                                          max_size_mb&lt;br /&gt;
    ,      max_free_mb                                                                          max_free_mb&lt;br /&gt;
    ,      TRUNC((max_free_mb/max_size_mb) * 100)                                               max_free_pct&lt;br /&gt;
    ,      RPAD(&amp;#039; &amp;#039;|| RPAD(&amp;#039;X&amp;#039;,ROUND((max_size_mb-max_free_mb)/max_size_mb*10,0), &amp;#039;X&amp;#039;),11,&amp;#039;-&amp;#039;)  max_used_pct&lt;br /&gt;
    from   (&lt;br /&gt;
           select a.tablespace_name                                         tablespace_name&lt;br /&gt;
           ,      b.size_mb                                                 size_mb&lt;br /&gt;
           ,      a.free_mb                                                 free_mb&lt;br /&gt;
           ,      b.max_size_mb                                             max_size_mb&lt;br /&gt;
           ,      a.free_mb + (b.max_size_mb - b.size_mb)                   max_free_mb&lt;br /&gt;
           from   (&lt;br /&gt;
                  select tablespace_name                                    tablespace_name&lt;br /&gt;
                  ,      trunc(sum(bytes)/1024/1024)                        free_mb&lt;br /&gt;
                  from   dba_free_space&lt;br /&gt;
                  group  by tablespace_name&lt;br /&gt;
                  ) a&lt;br /&gt;
           ,      (&lt;br /&gt;
                  select tablespace_name                                    tablespace_name&lt;br /&gt;
                  ,        trunc(sum(bytes)/1024/1024)                      size_mb&lt;br /&gt;
                  ,        trunc(sum(greatest(bytes,maxbytes))/1024/1024)   max_size_mb&lt;br /&gt;
                  from   dba_data_files&lt;br /&gt;
                  group by tablespace_name&lt;br /&gt;
                  ) b&lt;br /&gt;
           ,      v$instance vi&lt;br /&gt;
           where  a.tablespace_name = b.tablespace_name&lt;br /&gt;
           )&lt;br /&gt;
    order  by tablespace_name;&lt;br /&gt;
&lt;br /&gt;
set lines 80&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Another method for calculating free space in tablespace  using segments===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select df.tablespace_name &amp;quot;Tablespace&amp;quot;&lt;br /&gt;
,      totalusedspace &amp;quot;Used MB&amp;quot;&lt;br /&gt;
,      (df.totalspace - tu.totalusedspace) &amp;quot;Free MB&amp;quot;&lt;br /&gt;
,      df.totalspace &amp;quot;Total MB&amp;quot;&lt;br /&gt;
,      round(100 * ( (df.totalspace - tu.totalusedspace)/ df.totalspace)) &amp;quot;Pct. Free&amp;quot;&lt;br /&gt;
from   (&lt;br /&gt;
       select tablespace_name&lt;br /&gt;
,      round(sum(bytes) / 1048576) totalspace&lt;br /&gt;
       from   dba_data_files&lt;br /&gt;
       group  by tablespace_name&lt;br /&gt;
       ) df&lt;br /&gt;
,      (&lt;br /&gt;
       select round(sum(bytes)/(1024*1024)) totalusedspace&lt;br /&gt;
       ,      tablespace_name&lt;br /&gt;
       from   dba_segments&lt;br /&gt;
       group  by tablespace_name&lt;br /&gt;
       ) tu&lt;br /&gt;
where  df.tablespace_name = tu.tablespace_name;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Work out maximum possible size of a datafile===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select round( (4*1024*1024*value) / (1024*1024*1024) ,2) maxfilesizeingigabytes from v$parameter where name=&amp;#039;db_block_size&amp;#039;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or, as tablespaces can have block sizes differing from that of the init.ora parameter...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select round( (4*1024*1024*block_size) / (1024*1024*1024) ,2) maxfilesizeingigabytes from dba_tablespaces where tablespace_name=&amp;#039;&amp;amp;tablespace_name&amp;#039;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Show size and maxsize at datafile level===&lt;br /&gt;
datafiles&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set pages 100 lines 200&lt;br /&gt;
col file_name for a60&lt;br /&gt;
select sum(bytes)/1024/1024      mbytes_alloc&lt;br /&gt;
,      sum(maxbytes)/1024/1024   mbytes_max&lt;br /&gt;
,      file_name&lt;br /&gt;
from   sys.dba_data_files&lt;br /&gt;
group  by file_name&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
tempfiles&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set pages 100 lines 200&lt;br /&gt;
col file_name for a60&lt;br /&gt;
select sum(bytes)/1024/1024      mbytes_alloc&lt;br /&gt;
,      sum(maxbytes)/1024/1024   mbytes_max&lt;br /&gt;
,      file_name&lt;br /&gt;
from   sys.dba_temp_files&lt;br /&gt;
group  by file_name&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Resize the online redo logfiles===&lt;br /&gt;
Found a more concise, smarter way of doing it [http://www.oracle-wiki.net/startdocshowtorecreateredogrps here] - oracle-wiki.net&amp;lt;br /&amp;gt;&lt;br /&gt;
Switching logs too often? Redolog files too small?&amp;lt;br /&amp;gt;&lt;br /&gt;
* Show current log groups&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 1000&lt;br /&gt;
col group_member for a60&lt;br /&gt;
select l.group#          group_number&lt;br /&gt;
,      (bytes/1024/1024) megs&lt;br /&gt;
,      l.status          group_status&lt;br /&gt;
,      f.member          group_member&lt;br /&gt;
,      l.archived        archived&lt;br /&gt;
,      f.type            file_type&lt;br /&gt;
from   v$log     l&lt;br /&gt;
,      v$logfile f&lt;br /&gt;
where  l.group# = f.group#&lt;br /&gt;
order  by l.group#&lt;br /&gt;
,      f.member&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Create additional (bigger) groups&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
define SID=TIBQFW&lt;br /&gt;
alter database add logfile group 6  &amp;#039;/oracle/&amp;amp;SID/oradata1/redo1.log&amp;#039; size 1G;&lt;br /&gt;
alter database add logfile group 7  &amp;#039;/oracle/&amp;amp;SID/oradata2/redo2.log&amp;#039; size 1G;&lt;br /&gt;
alter database add logfile group 8  &amp;#039;/oracle/&amp;amp;SID/oradata3/redo3.log&amp;#039; size 1G;&lt;br /&gt;
alter database add logfile group 9  &amp;#039;/oracle/&amp;amp;SID/oradata1/redo4.log&amp;#039; size 1G;&lt;br /&gt;
alter database add logfile group 10 &amp;#039;/oracle/&amp;amp;SID/oradata2/redo5.log&amp;#039; size 1G;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or if you use multiple members...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter database add logfile group 6 (&amp;#039;/oracle/&amp;amp;SID/oradata1/redo/redo01a.log&amp;#039;, &amp;#039;/oracle/&amp;amp;SID/oradata1/redo01b&amp;#039;) size 50M;&lt;br /&gt;
alter database add logfile group 7 (&amp;#039;/oracle/&amp;amp;SID/oradata1/redo/redo02a.log&amp;#039;, &amp;#039;/oracle/&amp;amp;SID/oradata1/redo02b&amp;#039;) size 50M;&lt;br /&gt;
alter database add logfile group 8 (&amp;#039;/oracle/&amp;amp;SID/oradata1/redo/redo03a.log&amp;#039;, &amp;#039;/oracle/&amp;amp;SID/oradata1/redo03b&amp;#039;) size 50M;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Switch archivelogs until the new ones are current and the old ones are inactive&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter system switch logfile;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
If the old logs are not yet inactive, checkpoint the database&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter system checkpoint;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Drop the old groups&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter database drop logfile group 1;&lt;br /&gt;
alter database drop logfile group 2;&lt;br /&gt;
alter database drop logfile group 3;&lt;br /&gt;
alter database drop logfile group 4;&lt;br /&gt;
alter database drop logfile group 5;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Increase the existing size of a datafile===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter database datafile &amp;#039;&amp;amp;full_path_of_datafile&amp;#039; resize &amp;amp;new_meg_size.M;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Increase the max size of a tempfile===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter database tempfile &amp;#039;/oracle/ENDP1/oradata90/temp01.dbf&amp;#039; autoextend on maxsize unlimited;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Find out what processes are using the temp tablespace===&lt;br /&gt;
Temporary tablespace is used for sorting query results. Find them with this.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SELECT b.tablespace,b.segfile#,b.segblk#,b.blocks,a.sid,a.serial#,&lt;br /&gt;
a.username,a.osuser, a.status&lt;br /&gt;
FROM v$session a,v$sort_usage b&lt;br /&gt;
WHERE a.saddr = b.session_addr;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Increase the maximum size of a datafile===&lt;br /&gt;
Although this can be set lower than existing size, try not to. It makes the reports look weird!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter database&lt;br /&gt;
      datafile &amp;#039;&amp;amp;full_path_of_datafile&amp;#039;&lt;br /&gt;
      autoextend on&lt;br /&gt;
      maxsize &amp;amp;new_meg_size.m;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Find schemas (users) with objects created outside their default tablespace===&lt;br /&gt;
Indexes could be a notable exception if they are created in an index tablespace&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 200&lt;br /&gt;
col owner           for a20&lt;br /&gt;
col segment_name    for a45&lt;br /&gt;
col tablespace_name for a32&lt;br /&gt;
select owner&lt;br /&gt;
,      segment_name&lt;br /&gt;
,      tablespace_name&lt;br /&gt;
from   dba_segments&lt;br /&gt;
where  exists (select username from dba_users where username = owner)&lt;br /&gt;
and    tablespace_name != (select default_tablespace from dba_users where username = owner)&lt;br /&gt;
and    owner = &amp;#039;&amp;amp;owner&amp;#039;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Add a datafile to a tablespace===&lt;br /&gt;
&amp;#039;unlimited&amp;#039; will default to the maximum datafile size for the current db_block_size&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter tablepace &amp;amp;tablespace_name&lt;br /&gt;
      add datafile &amp;#039;&amp;amp;full_path_of_datafile&amp;#039;&lt;br /&gt;
      size 100M&lt;br /&gt;
      autoextend on&lt;br /&gt;
      next 100M&lt;br /&gt;
      maxsize unlimited&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===List all datafiles with their size===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set pages 1000 lines 2000&lt;br /&gt;
col filetype for a15&lt;br /&gt;
col name for a60&lt;br /&gt;
break on report&lt;br /&gt;
compute sum of gig on report&lt;br /&gt;
&lt;br /&gt;
select filetype&lt;br /&gt;
,      name&lt;br /&gt;
,      gig&lt;br /&gt;
from   (&lt;br /&gt;
       select &amp;#039;datafile&amp;#039; filetype&lt;br /&gt;
       ,      name&lt;br /&gt;
       ,      bytes/1024/1024 gig&lt;br /&gt;
       from   v$datafile&lt;br /&gt;
       union all&lt;br /&gt;
       select &amp;#039;tempfile&amp;#039; filetype&lt;br /&gt;
       ,      name&lt;br /&gt;
       ,      bytes/1024/1024&lt;br /&gt;
       from   v$tempfile&lt;br /&gt;
       union all&lt;br /&gt;
       select &amp;#039;logfile&amp;#039; filetype&lt;br /&gt;
       ,      lf.member &amp;quot;name&amp;quot;&lt;br /&gt;
       ,      l.bytes/1024/1024&lt;br /&gt;
       from   v$logfile lf&lt;br /&gt;
       ,      v$log     l&lt;br /&gt;
       where  1=1&lt;br /&gt;
       and    lf.group# = l.group#&lt;br /&gt;
       ) used&lt;br /&gt;
,      (&lt;br /&gt;
       select sum(bytes)/1024/1024&lt;br /&gt;
       from   dba_free_space&lt;br /&gt;
       ) free&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Database size (How big is my database?)===&lt;br /&gt;
There are different interpretations of what constitutes the size of a database...&amp;lt;br /&amp;gt;&lt;br /&gt;
Is it the space allocated to the datafiles or only the space taken up by the data? Are tempfiles included? Are redo logs included? etc...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 132&lt;br /&gt;
col dbname for a9  heading &amp;quot;Database&amp;quot;&lt;br /&gt;
col dbsize for a15 heading &amp;quot;Size&amp;quot;&lt;br /&gt;
col dbused for a15 heading &amp;quot;Used space&amp;quot;&lt;br /&gt;
col dbfree for a15 heading &amp;quot;Free space&amp;quot;&lt;br /&gt;
with used_space as&lt;br /&gt;
(&lt;br /&gt;
select  bytes&lt;br /&gt;
from    v$datafile&lt;br /&gt;
union   all&lt;br /&gt;
select  bytes&lt;br /&gt;
from    v$tempfile&lt;br /&gt;
union   all&lt;br /&gt;
select  bytes&lt;br /&gt;
from    v$log&lt;br /&gt;
)&lt;br /&gt;
, free_space as&lt;br /&gt;
(&lt;br /&gt;
select sum(bytes) sum_bytes&lt;br /&gt;
from dba_free_space&lt;br /&gt;
)&lt;br /&gt;
select vd.name                                                                                            dbname&lt;br /&gt;
,      round(sum(used_space.bytes)/1024/1024/1024 ) || &amp;#039; GB&amp;#039;                                              dbsize&lt;br /&gt;
,      round(sum(used_space.bytes)/1024/1024/1024 ) - round(free_space.sum_bytes/1024/1024/1024) || &amp;#039; GB&amp;#039; dbused&lt;br /&gt;
,      round(free_space.sum_bytes/1024/1024/1024) || &amp;#039; GB&amp;#039;                                                dbfree&lt;br /&gt;
from   free_space&lt;br /&gt;
,      used_space&lt;br /&gt;
,      v$database vd&lt;br /&gt;
group  by vd.name&lt;br /&gt;
,      free_space.sum_bytes&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Drop datafile from temp tablespace===&lt;br /&gt;
Database is completely stuck because the temporary tablespace has grown to fill all available room.&amp;lt;br /&amp;gt;&lt;br /&gt;
Look around for at least some log files to delete in order to get connected (audit files, sqlnet logs, listener logs)&amp;lt;br /&amp;gt;&lt;br /&gt;
Once connected, change the default temporary tablespace to a small one so we can remove the original.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
create temporary tablespace temp2 tempfile &amp;#039;/oracle/RMANV12/oradata2/temp2.dbf&amp;#039; size 5M;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter database default temporary tablespace temp2;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
I found trying to drop the datafile like this didn&amp;#039;t work, just hung there (probably active tranactions)...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
drop tablespace temp including contents and datafiles;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
So did it like this...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter database tempfile &amp;#039;/oracle/RMANV12/oradata2/temp.dbf&amp;#039; drop including datafiles;&lt;br /&gt;
&lt;br /&gt;
Database altered.&lt;br /&gt;
&lt;br /&gt;
drop tablespace temp including contents and datafiles;&lt;br /&gt;
&lt;br /&gt;
Tablespace dropped.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
... an alternative would be to find the sessions using the temp space and kill them...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select sid, serial#, status from v$session where serial# in (select session_num from v$sort_usage);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Then to be neat and tidy, rename the temp2 tablespace back to temp.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
create temporary tablespace temp tempfile &amp;#039;/oracle/RMANV12/oradata2/temp.dbf&amp;#039; size 256M reuse autoextend on next 128M maxsize 1G;&lt;br /&gt;
alter database default temporary tablespace temp;&lt;br /&gt;
drop tablespace temp2 including contents and datafiles;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Although the last statement will not work until any transactions using it have been rolled back or committed.&lt;br /&gt;
&lt;br /&gt;
===List files that are in hot-backup mode===&lt;br /&gt;
 set lines 100&lt;br /&gt;
 set pages 100&lt;br /&gt;
 col name format a60&lt;br /&gt;
 &lt;br /&gt;
 select df.name&lt;br /&gt;
 ,      b.status&lt;br /&gt;
 ,      to_char(time, &amp;#039;hh24:mi:ss dd/mm/yyyy&amp;#039;) time&lt;br /&gt;
 from   v$datafile   df&lt;br /&gt;
 ,      v$backup     b&lt;br /&gt;
 where  1=1&lt;br /&gt;
 and    df.file# = b.file#&lt;br /&gt;
 and    b.status = &amp;#039;ACTIVE&amp;#039;&lt;br /&gt;
 order  by b.file#;&lt;br /&gt;
&lt;br /&gt;
===Waiting for snapshot control file enqueue===&lt;br /&gt;
Script to identify sessions causing RMAN to hang because of &amp;#039;waiting for snapshot control file enqueue&amp;#039; message&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 2000&lt;br /&gt;
col killer     for a70&lt;br /&gt;
col program    for a20&lt;br /&gt;
col module     for a20&lt;br /&gt;
col action     for a20&lt;br /&gt;
col logon_time for a20&lt;br /&gt;
&lt;br /&gt;
select &amp;#039;alter system disconnect session &amp;#039;&amp;#039;&amp;#039;||s.sid||&amp;#039;,&amp;#039;||s.serial#||&amp;#039;&amp;#039;&amp;#039; immediate;&amp;#039; killer&lt;br /&gt;
,      username&lt;br /&gt;
,      program&lt;br /&gt;
,      module&lt;br /&gt;
,      action&lt;br /&gt;
,      logon_time&lt;br /&gt;
from   v$session s&lt;br /&gt;
,      v$enqueue_lock l&lt;br /&gt;
where  l.sid  = s.sid&lt;br /&gt;
and    l.type = &amp;#039;CF&amp;#039;&lt;br /&gt;
and    l.id1  = 0&lt;br /&gt;
and    l.id2  = 2&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Info on blocking processes===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select s1.username || &amp;#039;@&amp;#039; || s1.machine&lt;br /&gt;
       || &amp;#039; ( SID=&amp;#039; || s1.sid || &amp;#039; )  is blocking &amp;#039;&lt;br /&gt;
       || s2.username || &amp;#039;@&amp;#039; || s2.machine || &amp;#039; ( SID=&amp;#039; || s2.sid || &amp;#039; ) &amp;#039;  blocking_status&lt;br /&gt;
from   v$lock l1&lt;br /&gt;
,      v$session s1&lt;br /&gt;
,      v$lock l2&lt;br /&gt;
,      v$session s2&lt;br /&gt;
where  s1.sid     = l1.sid&lt;br /&gt;
and    s2.sid     = l2.sid&lt;br /&gt;
and    l1.block   = 1&lt;br /&gt;
and    l2.request &amp;gt; 0&lt;br /&gt;
and    l1.id1     = l2.id1&lt;br /&gt;
and    l2.id2     = l2.id2&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
session doing the blocking&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select *&lt;br /&gt;
from  v$lock l1&lt;br /&gt;
where 1=1&lt;br /&gt;
and   block = 1 ;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
sessions being blocked&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select *&lt;br /&gt;
from   v$lock l1&lt;br /&gt;
where  1=1&lt;br /&gt;
and    id2 = 85203&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
info on session doing the blocking&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select row_wait_obj#, row_wait_file#, row_wait_block#, row_wait_row#&lt;br /&gt;
from   v$session&lt;br /&gt;
where  sid = 234&lt;br /&gt;
&lt;br /&gt;
select do.object_name&lt;br /&gt;
,      row_wait_obj#&lt;br /&gt;
,      row_wait_file#&lt;br /&gt;
,      row_wait_block#&lt;br /&gt;
,      row_wait_row#&lt;br /&gt;
,      dbms_rowid.rowid_create ( 1, ROW_WAIT_OBJ#, ROW_WAIT_FILE#, ROW_WAIT_BLOCK#, ROW_WAIT_ROW# ) row_id&lt;br /&gt;
from   v$session   s&lt;br /&gt;
,      dba_objects do&lt;br /&gt;
where  sid=234&lt;br /&gt;
and    s.ROW_WAIT_OBJ# = do.OBJECT_ID;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Show locked objects===&lt;br /&gt;
 set lines 100&lt;br /&gt;
 set pages 999&lt;br /&gt;
 col username   format a20&lt;br /&gt;
 col sess_id    format a10&lt;br /&gt;
 col object     format a25&lt;br /&gt;
 col mode_held  format a10&lt;br /&gt;
 select oracle_username||&amp;#039; (&amp;#039;||s.osuser||&amp;#039;)&amp;#039; username&lt;br /&gt;
 ,      s.sid||&amp;#039;,&amp;#039;||s.serial# sess_id&lt;br /&gt;
 ,      owner||&amp;#039;.&amp;#039;||object_name object&lt;br /&gt;
 ,      object_type&lt;br /&gt;
 ,      decode ( l.block&lt;br /&gt;
               , 0, &amp;#039;Not Blocking&amp;#039;&lt;br /&gt;
               , 1, &amp;#039;Blocking&amp;#039;&lt;br /&gt;
               , 2, &amp;#039;Global&amp;#039;&lt;br /&gt;
               ) status&lt;br /&gt;
 ,      decode ( v.locked_mode&lt;br /&gt;
               , 0, &amp;#039;None&amp;#039;&lt;br /&gt;
               , 1, &amp;#039;Null&amp;#039;&lt;br /&gt;
               , 2, &amp;#039;Row-S (SS)&amp;#039;&lt;br /&gt;
               , 3, &amp;#039;Row-X (SX)&amp;#039;&lt;br /&gt;
               , 4, &amp;#039;Share&amp;#039;&lt;br /&gt;
               , 5, &amp;#039;S/Row-X (SSX)&amp;#039;&lt;br /&gt;
               , 6, &amp;#039;Exclusive&amp;#039;, TO_CHAR(lmode)&lt;br /&gt;
               ) mode_held&lt;br /&gt;
 from   v$locked_object v&lt;br /&gt;
 ,      dba_objects d&lt;br /&gt;
 ,      v$lock l&lt;br /&gt;
 ,      v$session s&lt;br /&gt;
 where  1=1&lt;br /&gt;
 and    v.object_id = d.object_id&lt;br /&gt;
 and    v.object_id = l.id1&lt;br /&gt;
 and    v.session_id = s.sid&lt;br /&gt;
 order  by oracle_username&lt;br /&gt;
 ,	session_id;&lt;br /&gt;
&lt;br /&gt;
===Show which row is locked===&lt;br /&gt;
 select do.object_name&lt;br /&gt;
 ,      row_wait_obj#&lt;br /&gt;
 ,      row_wait_file#&lt;br /&gt;
 ,      row_wait_block#&lt;br /&gt;
 ,      row_wait_row#&lt;br /&gt;
 ,      dbms_rowid.rowid_create (1, ROW_WAIT_OBJ#, ROW_WAIT_FILE#, ROW_WAIT_BLOCK#, ROW_WAIT_ROW#)&lt;br /&gt;
 from   v$session   s&lt;br /&gt;
 ,      dba_objects do&lt;br /&gt;
 where  1=1&lt;br /&gt;
 and    s.ROW_WAIT_OBJ# = do.OBJECT_ID&lt;br /&gt;
 and    sid             = &amp;amp;sid;&lt;br /&gt;
&lt;br /&gt;
===Check what is audited on a database===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set pagesize 100&lt;br /&gt;
set linesize 256&lt;br /&gt;
select audit_option,success,failure from dba_stmt_audit_opts;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===How old is the oldest audit record?===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select extract (day from (systimestamp - min(ntimestamp#))) days_old from aud$;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Check what objects are being audited===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
tti col 60 &amp;#039;Object Audit Options (dba_obj_audit_opts)&amp;#039; skip col 50 &amp;#039;A=By Access, S=By Session. Left=on success, right=on failure&amp;#039; skip 2&lt;br /&gt;
set lines 1000 pages 100&lt;br /&gt;
col alt for a3 head &amp;quot;Alt|er&amp;quot;&lt;br /&gt;
col aud for a3 head &amp;quot;Aud|it&amp;quot;&lt;br /&gt;
col com for a3 head &amp;quot;Com|ent&amp;quot;&lt;br /&gt;
col del for a3 head &amp;quot;Del|ete&amp;quot;&lt;br /&gt;
col gra for a3 head &amp;quot;Gra|nt&amp;quot;&lt;br /&gt;
col ind for a3 head &amp;quot;Ind|ex&amp;quot;&lt;br /&gt;
col ins for a3 head &amp;quot;Ins|ert&amp;quot;&lt;br /&gt;
col loc for a3 head &amp;quot;Lo|ck&amp;quot;&lt;br /&gt;
col ren for a3 head &amp;quot;Ren|ame&amp;quot;&lt;br /&gt;
col sel for a3 head &amp;quot;Sel|ect&amp;quot;&lt;br /&gt;
col upd for a3 head &amp;quot;Upd|ate&amp;quot;&lt;br /&gt;
col ref for a3 head &amp;quot;Ref|rnc&amp;quot;&lt;br /&gt;
col exe for a3 head &amp;quot;Exe|cut&amp;quot;&lt;br /&gt;
col cre for a3 head &amp;quot;Cre|ate&amp;quot;&lt;br /&gt;
col rea for a3 head &amp;quot;Re|ad&amp;quot;&lt;br /&gt;
col wri for a3 head &amp;quot;Wri|te&amp;quot;&lt;br /&gt;
col fbk for a3 head &amp;quot;Fla|sh&amp;quot;&lt;br /&gt;
	&lt;br /&gt;
select *&lt;br /&gt;
from   dba_obj_audit_opts&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Procedure to delete old audit records===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select text from all_source where lower(name)=&amp;#039;purge_audit_trail&amp;#039;;&lt;br /&gt;
&lt;br /&gt;
TEXT&lt;br /&gt;
------------------------------------------------------------------------------------------------&lt;br /&gt;
PROCEDURE purge_audit_trail IS&lt;br /&gt;
BEGIN&lt;br /&gt;
-- set the last archive timestamp&lt;br /&gt;
DBMS_AUDIT_MGMT.SET_LAST_ARCHIVE_TIMESTAMP(&lt;br /&gt;
       audit_trail_type    =&amp;gt; DBMS_AUDIT_MGMT.AUDIT_TRAIL_AUD_STD,&lt;br /&gt;
       last_archive_time   =&amp;gt; systimestamp - interval &amp;#039;365&amp;#039; day,&lt;br /&gt;
       rac_instance_number =&amp;gt; null&lt;br /&gt;
                                          );&lt;br /&gt;
-- purge audit trail till last archive timestamp&lt;br /&gt;
DBMS_AUDIT_MGMT.CLEAN_AUDIT_TRAIL( audit_trail_type =&amp;gt; DBMS_AUDIT_MGMT.AUDIT_TRAIL_AUD_STD&lt;br /&gt;
, use_last_arch_timestamp =&amp;gt; TRUE);&lt;br /&gt;
&lt;br /&gt;
END purge_audit_trail;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Job setup to run the audit purge===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
BEGIN&lt;br /&gt;
sys.dbms_scheduler.create_job(&lt;br /&gt;
    job_name =&amp;gt; &amp;#039;&amp;quot;SYS&amp;quot;.&amp;quot;PURGE_AUDIT_TRAIL_JOB&amp;quot;&amp;#039;,&lt;br /&gt;
    job_type =&amp;gt; &amp;#039;STORED_PROCEDURE&amp;#039;,&lt;br /&gt;
    job_action =&amp;gt; &amp;#039;&amp;quot;SYS&amp;quot;.&amp;quot;PURGE_AUDIT_TRAIL&amp;quot;&amp;#039;,&lt;br /&gt;
    repeat_interval =&amp;gt; &amp;#039;FREQ=DAILY;BYHOUR=20;BYMINUTE=0;BYSECOND=0&amp;#039;,&lt;br /&gt;
    start_date =&amp;gt; to_timestamp_tz(&amp;#039;2012-02-22 Europe/Paris&amp;#039;, &amp;#039;YYYY-MM-DD TZR&amp;#039;),&lt;br /&gt;
    job_class =&amp;gt; &amp;#039;&amp;quot;DEFAULT_JOB_CLASS&amp;quot;&amp;#039;,&lt;br /&gt;
    comments =&amp;gt; &amp;#039;purge audit trails until last archive timestamp&amp;#039;,&lt;br /&gt;
    auto_drop =&amp;gt; FALSE,&lt;br /&gt;
    enabled =&amp;gt; FALSE&lt;br /&gt;
);&lt;br /&gt;
sys.dbms_scheduler.set_attribute( name =&amp;gt; &amp;#039;&amp;quot;SYS&amp;quot;.&amp;quot;PURGE_AUDIT_TRAIL_JOB&amp;quot;&amp;#039;, attribute =&amp;gt; &amp;#039;logging_level&amp;#039;, value =&amp;gt; DBMS_SCHEDULER.LOGGING_OFF);&lt;br /&gt;
sys.dbms_scheduler.set_attribute( name =&amp;gt; &amp;#039;&amp;quot;SYS&amp;quot;.&amp;quot;PURGE_AUDIT_TRAIL_JOB&amp;quot;&amp;#039;, attribute =&amp;gt; &amp;#039;job_weight&amp;#039;, value =&amp;gt; 1);&lt;br /&gt;
sys.dbms_scheduler.enable( &amp;#039;&amp;quot;SYS&amp;quot;.&amp;quot;PURGE_AUDIT_TRAIL_JOB&amp;quot;&amp;#039; );&lt;br /&gt;
END;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===A list of all SIDs in oratab that should restart after a server boot===&lt;br /&gt;
Using awk&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
awk -F: &amp;#039;$NF==&amp;quot;Y&amp;quot; &amp;amp;&amp;amp; $1 !~/[#]/ {print $1}&amp;#039;  /etc/oratab&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Using perl&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
perl -F: -ne &amp;#039;print &amp;quot;$1\n&amp;quot; if /(\w+):(.+):Y$/&amp;#039; /etc/oratab&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Move the admin directories to a new location===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
./all_db_do &amp;quot;alter system set audit_file_dest=&amp;#039;/oracle/&amp;amp;SID/admin/adump&amp;#039; scope=spfile;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
./all_db_do &amp;quot;shutdown immediate&amp;quot;&lt;br /&gt;
&lt;br /&gt;
for db in `awk -F: &amp;#039;NF &amp;amp;&amp;amp; $1 !~/[#*]/ {print $1}&amp;#039;  /etc/oratab`&lt;br /&gt;
do&lt;br /&gt;
    echo $db&lt;br /&gt;
    mkdir -p /oracle/${db}/admin&lt;br /&gt;
    echo &amp;quot;/oracle/${db}/admin created&amp;quot;&lt;br /&gt;
    mv /oracle/admin/${db}/adump /oracle/${db}/admin/&lt;br /&gt;
    mv /oracle/admin/${db}/dpdump /oracle/${db}/admin/&lt;br /&gt;
    echo &amp;quot;Moved /oracle/admin/${db}/adump to /oracle/${db}/admin/&amp;quot;&lt;br /&gt;
done&lt;br /&gt;
&lt;br /&gt;
./all_db_do startup&lt;br /&gt;
&lt;br /&gt;
./all_db_do &amp;quot;create pfile from spfile;&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Check if the Standby database is up-to-date with the primary database===&lt;br /&gt;
 select arch.thread# &amp;quot;Thread&amp;quot;&lt;br /&gt;
 ,      arch.sequence# &amp;quot;Last Sequence Received&amp;quot;&lt;br /&gt;
 ,      appl.sequence# &amp;quot;Last Sequence Applied&amp;quot;&lt;br /&gt;
 ,      (arch.sequence# - appl.sequence#) &amp;quot;Difference&amp;quot;&lt;br /&gt;
 from   (&lt;br /&gt;
        select thread#&lt;br /&gt;
        ,      sequence#&lt;br /&gt;
        from   v$archived_log&lt;br /&gt;
        where  1=1&lt;br /&gt;
        and    ( thread#,first_time ) in (&lt;br /&gt;
                                         select thread#, max(first_time)&lt;br /&gt;
                                         from   v$archived_log&lt;br /&gt;
                                         group  by thread#&lt;br /&gt;
                                         )&lt;br /&gt;
        ) arch&lt;br /&gt;
        ,&lt;br /&gt;
        (&lt;br /&gt;
        select thread#&lt;br /&gt;
        ,      sequence#&lt;br /&gt;
        from   v$log_history&lt;br /&gt;
        where  1=1&lt;br /&gt;
        and    ( thread#,first_time ) in ( select thread# ,max(first_time)&lt;br /&gt;
                                           from   v$log_history&lt;br /&gt;
                                           group  by thread#&lt;br /&gt;
                                          )&lt;br /&gt;
        ) appl&lt;br /&gt;
 where  1=1&lt;br /&gt;
 and    arch.thread# = appl.thread#&lt;br /&gt;
 order  by 1;&lt;br /&gt;
&lt;br /&gt;
===Check for gaps on the Standby database===&lt;br /&gt;
Run this on the standby&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select thread#, low_sequence#, high_sequence# from v$archive_gap;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or run this on the Primary to see the latest generated archive...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select thread#   &amp;quot;Thread&amp;quot;&lt;br /&gt;
,      sequence# &amp;quot;Last sequence generated&amp;quot;&lt;br /&gt;
from   v$archived_log&lt;br /&gt;
where  (thread#, first_time) in ( select thread#, max(first_time)&lt;br /&gt;
                                  from   v$archived_log&lt;br /&gt;
                                  group  by thread#&lt;br /&gt;
                                )&lt;br /&gt;
order  by 1&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
and run this on the standby to check for received but not yet applied logs (this could be normal if a lag has been set)...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select arch.thread# &amp;quot;Thread&amp;quot;&lt;br /&gt;
,      arch.sequence# &amp;quot;Last sequence received&amp;quot;&lt;br /&gt;
,      appl.sequence# &amp;quot;Last sequence applied&amp;quot;&lt;br /&gt;
,      (arch.sequence#-appl.sequence#) &amp;quot;Difference&amp;quot;&lt;br /&gt;
from   (&lt;br /&gt;
       select thread#&lt;br /&gt;
       ,      sequence#&lt;br /&gt;
       from   v$archived_log&lt;br /&gt;
       where  (thread#,first_time ) in (select thread#, max(first_time)&lt;br /&gt;
                                        from   v$archived_log&lt;br /&gt;
                                        group  by thread#&lt;br /&gt;
                                       )&lt;br /&gt;
       ) arch&lt;br /&gt;
,      (&lt;br /&gt;
       select thread#&lt;br /&gt;
       ,      sequence#&lt;br /&gt;
       from   v$log_history&lt;br /&gt;
       where  (thread#,first_time ) in (select thread#, max(first_time)&lt;br /&gt;
                                        from   v$log_history&lt;br /&gt;
                                        group  by thread#&lt;br /&gt;
                                       )&lt;br /&gt;
      ) appl&lt;br /&gt;
where arch.thread# = appl.thread#&lt;br /&gt;
order by 1&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Compare the results from Primary and Secondary to detect possible network problems or other errors in shipping.&lt;br /&gt;
&lt;br /&gt;
===Ignore case-sensitive passwords in 11g (deprecated in 12c)===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter system set SEC_CASE_SENSITIVE_LOGON = false scope=both&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===External table for the Alert log (pre 11g)===&lt;br /&gt;
Modified to use (the better) scripts found on [http://www.adp-gmbh.ch/ora/admin/scripts/read_alert_log.html Rene Nyffenegger&amp;#039;s site]&amp;lt;br /&amp;gt;&lt;br /&gt;
This script generates the required DDL for the alertlog table&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
column db    new_value _DB    noprint;&lt;br /&gt;
column bdump new_value _bdump noprint;&lt;br /&gt;
&lt;br /&gt;
select&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Alert log (11g+)===&lt;br /&gt;
This reads the log.xml file (which contains the same information as alert.log)&amp;lt;br /&amp;gt;&lt;br /&gt;
Show the messages put in the alert log in the last 24 hours&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select substr(MESSAGE_TEXT, 1, 300) message_text&lt;br /&gt;
,      count(*) cnt&lt;br /&gt;
from   X$DBGALERTEXT&lt;br /&gt;
where  1=1&lt;br /&gt;
and    (MESSAGE_TEXT like &amp;#039;%ORA-%&amp;#039; or upper(MESSAGE_TEXT) like &amp;#039;%ERROR%&amp;#039;)&lt;br /&gt;
and    cast(ORIGINATING_TIMESTAMP as DATE) &amp;gt; sysdate - &amp;amp;days_ago/1440&lt;br /&gt;
group  by substr(MESSAGE_TEXT, 1, 300)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
There is also a fixed table X$DBGDIREXT which returns all file and directory names under [diagnostic_dest]/diag directory:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select lpad(&amp;#039; &amp;#039;,lvl,&amp;#039; &amp;#039;)||logical_file file_name&lt;br /&gt;
from   x$dbgdirext&lt;br /&gt;
where  rownum &amp;lt;=20;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Directory paths available in v$diag_info===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 2000&lt;br /&gt;
col name for a35&lt;br /&gt;
col value for a100 wrap&lt;br /&gt;
select * from v$diag_info;&lt;br /&gt;
&lt;br /&gt;
   INST_ID NAME                                VALUE                                                                                                    CON_ID&lt;br /&gt;
---------- ----------------------------------- ---------------------------------------------------------------------------------------------------- ----------&lt;br /&gt;
         1 Diag Enabled                        TRUE                                                                                                          0&lt;br /&gt;
         1 ADR Base                            /cln/prg/ora_bin2/app/oracle                                                                               0&lt;br /&gt;
         1 ADR Home                            /cln/prg/ora_bin2/app/oracle/diag/rdbms/bild/bild                                                          0&lt;br /&gt;
         1 Diag Trace                          /cln/prg/ora_bin2/app/oracle/diag/rdbms/bild/bild/trace                                                    0&lt;br /&gt;
         1 Diag Alert                          /cln/prg/ora_bin2/app/oracle/diag/rdbms/bild/bild/alert                                                    0&lt;br /&gt;
         1 Diag Incident                       /cln/prg/ora_bin2/app/oracle/diag/rdbms/bild/bild/incident                                                 0&lt;br /&gt;
         1 Diag Cdump                          /cln/prg/ora_bin2/app/oracle/diag/rdbms/bild/bild/cdump                                                    0&lt;br /&gt;
         1 Health Monitor                      /cln/prg/ora_bin2/app/oracle/diag/rdbms/bild/bild/hm                                                       0&lt;br /&gt;
         1 Default Trace File                  /cln/prg/ora_bin2/app/oracle/diag/rdbms/bild/bild/trace/bild_ora_44696768.trc                              0&lt;br /&gt;
         1 Active Problem Count                0                                                                                                             0&lt;br /&gt;
         1 Active Incident Count               0                                                                                                             0&lt;br /&gt;
&lt;br /&gt;
11 rows selected.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Find out the names of the active trace files for the running processes===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select pid, program, tracefile from v$process;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Request was to duplicate a large tablespace from production to test environment===&lt;br /&gt;
...but rather than copy the terabytes of data, create the destination tablespace with just the most recent months data&amp;lt;br /&amp;gt;&lt;br /&gt;
====See what the source data looks like====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
col table_owner    for a20&lt;br /&gt;
col table_name     for a30&lt;br /&gt;
col partition_name for a20&lt;br /&gt;
set pages 100 lines 1000&lt;br /&gt;
&lt;br /&gt;
select table_owner&lt;br /&gt;
,      table_name&lt;br /&gt;
,      partition_name&lt;br /&gt;
,      partition_position&lt;br /&gt;
,      tablespace_name&lt;br /&gt;
from   dba_tab_partitions&lt;br /&gt;
where  tablespace_name = &amp;#039;ADS_ARCHIVE&amp;#039;&lt;br /&gt;
order  by 1,2,3,4&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This query produces something like this...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
TABLE_OWNER          TABLE_NAME                     PARTITION_NAME       PARTITION_POSITION TABLESPACE_NAME                &lt;br /&gt;
-------------------- ------------------------------ -------------------- ------------------ ------------------------------ &lt;br /&gt;
ADS_ARCHIVE          BIL_DAY_INV_CTR_ARC            Y2017_Q1_M01_D01                      1 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          BIL_HIS_DETAIL_FAC_ARC         Y2016_Q2_M05_D04                      1 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          BIL_HIS_DETAIL_FAC_ARC         Y2016_Q2_M05_D09                      2 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          BIL_MTH_INV_CTR_ARC            Y2017_Q1_M01_D01                      1 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          FAH_DAY_CBA_BGAAP_ARC          Y2011_Q4_M12_D30                      1 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          FAH_DAY_CBA_BGAAP_ARC          Y2011_Q4_M12_D31                      2 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          FAH_DAY_CBA_IFRS_ARC           Y2011_Q4_M12_D30                      1 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          FAH_DAY_CBA_IFRS_ARC           Y2011_Q4_M12_D31                      2 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          FAH_DAY_MVT_BGAAP_ARC          Y2011_Q4_M12_D30                      1 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          FAH_DAY_MVT_BGAAP_ARC          Y2011_Q4_M12_D31                      2 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          FAH_DAY_MVT_BGAAP_ARC          Y2012_Q1_M03_D31                      3 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          FAH_DAY_MVT_BGAAP_ARC          Y2012_Q2_M04_D01                      4 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          FAH_DAY_MVT_BGAAP_ARC          Y2012_Q4_M10_D12                      5 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          FAH_DAY_MVT_BGAAP_ARC          Y2012_Q4_M10_D13                      6 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          FAH_DAY_MVT_BGAAP_ARC          Y2012_Q4_M10_D14                      7 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          FAH_DAY_MVT_BGAAP_ARC_TST      Y2011_Q4_M12_D30                      1 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          FAH_DAY_MVT_BGAAP_ARC_TST      Y2011_Q4_M12_D31                      2 ADS_ARCHIVE&lt;br /&gt;
...&lt;br /&gt;
ADS_ARCHIVE          SBP_HIS_LINES_ARC              P_LS                                  3 ADS_ARCHIVE                  &lt;br /&gt;
ADS_ARCHIVE          THA_DAY_INV_CTR_ARC            Y2011_Q4_M12_D30                      1 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          THA_DAY_INV_CTR_ARC            Y2011_Q4_M12_D31                      2 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          THA_INV_HEAVY_ARC              Y2011_Q4_M12_D30                      1 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          THA_INV_HEAVY_ARC              Y2011_Q4_M12_D31                      2 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          THA_INV_LIGHT_ARC              Y2011_Q4_M12_D30                      1 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          THA_INV_LIGHT_ARC              Y2012_Q4_M10_D12                      2 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          THA_INV_LIGHT_ARC              Y2012_Q4_M10_D13                      3 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          THA_INV_LIGHT_ARC              Y2012_Q4_M10_D15                      4 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          THA_INV_LIGHT_ARC              Y2012_Q4_M10_D16                      5 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          THA_INV_LIGHT_ARC              Y2012_Q4_M10_D17                      6 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          THA_INV_LIGHT_ARC              Y2012_Q4_M10_D18                      7 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          THA_INV_LIGHT_ARC              Y2012_Q4_M10_D19                      8 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          THA_INV_LIGHT_ARC              Y2012_Q4_M10_D20                      9 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          THA_INV_LIGHT_ARC              Y2012_Q4_M10_D21                     10 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          THA_INV_LIGHT_ARC              Y2012_Q4_M10_D22                     11 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          THA_INV_LIGHT_ARC              Y2012_Q4_M10_D23                     12 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          THA_INV_LIGHT_ARC              Y2012_Q4_M10_D24                     13 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          THA_MTH_INV_CTR_ARC            Y2011_Q4_M12_D30                      1 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          THA_MTH_INV_CTR_ARC            Y2011_Q4_M12_D31                      2 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          THA_MTH_INV_CTR_ARC            Y2013_Q2_M04_D30                      3 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          XBD01_TEMP_HIS_ARC             Y2012_Q4_M12_D31                      1 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          T_RPT_RECO_THA_INV_ACC_ARC     Y2011_Q4_M12_D30                      1 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          T_RPT_RECO_THA_INV_ACC_ARC     Y2011_Q4_M12_D31                      2 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          T_RPT_RECO_THA_INV_MTH_ARC     Y2011_Q4_M12_D30                      1 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          T_RPT_RECO_THA_INV_MTH_ARC     Y2011_Q4_M12_D31                      2 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          XBD01_TEMP_HIS_ARC             Y2012_Q4_M12_D31                      1 ADS_ARCHIVE&lt;br /&gt;
ADS_DBA              FAH_DAY_CBA_BGAAP              Y2016_Q3_M07_D12                   1657 ADS_ARCHIVE&lt;br /&gt;
ADS_DBA              FAH_DAY_CBA_BGAAP              Y2016_Q4_M12_D13                   1811 ADS_ARCHIVE&lt;br /&gt;
ADS_DBA              FAH_DAY_MVT_IFRS               Y2016_Q4_M10_D10                   1654 ADS_ARCHIVE&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Capture the tablespace metadata====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set long 1000000&lt;br /&gt;
select dbms_metadata.get_ddl ( &amp;#039;TABLESPACE&amp;#039;, &amp;#039;ADS_ARCHIVE&amp;#039;) from dual&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
produces...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
CREATE TABLESPACE &amp;quot;ADS_ARCHIVE&amp;quot; DATAFILE&lt;br /&gt;
  &amp;#039;/oracle/tst/ora_data3/adst/ads_archive01.dbf&amp;#039; SIZE 104857600&lt;br /&gt;
  AUTOEXTEND ON NEXT 104857600 MAXSIZE 32000M,&lt;br /&gt;
...&lt;br /&gt;
  &amp;#039;/oracle/tst/ora_data3/adst/ads_archive66.dbf&amp;#039; SIZE 104857600&lt;br /&gt;
  AUTOEXTEND ON NEXT 104857600 MAXSIZE 3200M,&lt;br /&gt;
  LOGGING ONLINE PERMANENT BLOCKSIZE 8192&lt;br /&gt;
  EXTENT MANAGEMENT LOCAL AUTOALLOCATE DEFAULT&lt;br /&gt;
 NOCOMPRESS  SEGMENT SPACE MANAGEMENT AUTO&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Capture the tablespace objects&amp;#039; metadata====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cat&amp;lt;&amp;lt;EOCAT &amp;gt;expdp_adst_ads_archive_metadata.par&lt;br /&gt;
userid=&amp;#039;/ as sysdba&amp;#039;&lt;br /&gt;
dumpfile=adst_ads_archive_metadata.dmp&lt;br /&gt;
logfile=expdp_adst_ads_archive_metadata.log&lt;br /&gt;
tablespaces=ADS_ARCHIVE&lt;br /&gt;
parallel=20&lt;br /&gt;
content=metadata_only&lt;br /&gt;
exclude=statistics&lt;br /&gt;
EOCAT&lt;br /&gt;
&lt;br /&gt;
expdp parfile=expdp_adst_ads_archive_metadata.par&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Find the partitions with data from the most recent month====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cat &amp;lt;&amp;lt;EOCAT&amp;gt;/tmp/adst_ads_archive_partitions.sql&lt;br /&gt;
set termo off echo off lines 1000 feedb off headi off newpa none trims on&lt;br /&gt;
spool /tmp/adst_ads_archive_partitions.lst&lt;br /&gt;
select table_owner||&amp;#039;.&amp;#039;||table_name||&amp;#039;:&amp;#039;||partition_name&lt;br /&gt;
from   dba_tab_partitions&lt;br /&gt;
where  tablespace_name = &amp;#039;ADS_ARCHIVE&amp;#039;&lt;br /&gt;
and    partition_name like &amp;#039;Y2017_Q1_M01%&amp;#039;&lt;br /&gt;
/&lt;br /&gt;
spool off&lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;@/tmp/adst_ads_archive_partitions.sql&amp;quot; | sqlplus / as sysdba&lt;br /&gt;
EOCAT&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
produces...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_CBA_BGAAP_ARC:Y2017_Q1_M01_D07&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_IFRS_ARC:Y2017_Q1_M02_D26&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_IFRS_ARC:Y2017_Q1_M02_D25&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_IFRS_ARC:Y2017_Q1_M02_D19&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_IFRS_ARC:Y2017_Q1_M02_D18&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_IFRS_ARC:Y2017_Q1_M02_D12&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_IFRS_ARC:Y2017_Q1_M02_D11&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_IFRS_ARC:Y2017_Q1_M02_D05&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_BGAAP_ARC:Y2017_Q1_M02_D26&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_BGAAP_ARC:Y2017_Q1_M02_D25&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_BGAAP_ARC:Y2017_Q1_M02_D19&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_BGAAP_ARC:Y2017_Q1_M02_D18&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_BGAAP_ARC:Y2017_Q1_M02_D12&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_BGAAP_ARC:Y2017_Q1_M02_D11&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_BGAAP_ARC:Y2017_Q1_M02_D05&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_BGAAP_ARC:Y2017_Q1_M02_D04&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_BGAAP_ARC:Y2017_Q1_M01_D29&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_BGAAP_ARC:Y2017_Q1_M01_D28&lt;br /&gt;
...&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_BGAAP_ARC:Y2017_Q1_M01_D22&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_BGAAP_ARC:Y2017_Q1_M01_D21&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_BGAAP_ARC:Y2017_Q1_M01_D15&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_BGAAP_ARC:Y2017_Q1_M01_D14&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_BGAAP_ARC:Y2017_Q1_M01_D08&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_BGAAP_ARC:Y2017_Q1_M01_D07&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_BGAAP_ARC:Y2017_Q1_M01_D01&lt;br /&gt;
ADS_ARCHIVE.BIL_MTH_INV_CTR_ARC:Y2017_Q1_M01_D01&lt;br /&gt;
ADS_ARCHIVE.BIL_DAY_INV_CTR_ARC:Y2017_Q1_M01_D01&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_IFRS_ARC:Y2017_Q1_M02_D04&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_IFRS_ARC:Y2017_Q1_M01_D29&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_IFRS_ARC:Y2017_Q1_M01_D28&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_IFRS_ARC:Y2017_Q1_M01_D22&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Export the data in these partitions====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cat&amp;lt;&amp;lt;EOCAT &amp;gt;expdp_adst_ads_archive_partitions.par&lt;br /&gt;
userid=&amp;#039;/ as sysdba&amp;#039;&lt;br /&gt;
dumpfile=adst_ads_archive_Y2017_%U.dmp&lt;br /&gt;
logfile=expdp_adst_ads_archive_Y2017.log&lt;br /&gt;
EOCAT&lt;br /&gt;
&lt;br /&gt;
cat /tmp/adst_ads_archive_partitions.lst | perl -p -i -e &amp;#039;s/^/tables=/&amp;#039;g &amp;gt;&amp;gt;expdp_adst_ads_archive_partitions.par&lt;br /&gt;
&lt;br /&gt;
cat&amp;lt;&amp;lt;EOCAT &amp;gt;&amp;gt;expdp_adst_ads_archive_partitions.par&lt;br /&gt;
parallel=20&lt;br /&gt;
exclude=statistics&lt;br /&gt;
EOCAT&lt;br /&gt;
&lt;br /&gt;
expdp parfile=expdp_adst_ads_archive_partitions.par&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Drop the old tablespace====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
drop tablespace ads_archive including contents and datafiles&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Recreate the tablepspace using the metadata capture above====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
create tablespace &amp;quot;ADS_ARCHIVE&amp;quot;&lt;br /&gt;
datafile &amp;#039;/oracle/tst/ora_data3/adst/ads_archive01.dbf&amp;#039; size 100M autoextend on next 50M maxsize unlimited&lt;br /&gt;
,        &amp;#039;/oracle/tst/ora_data3/adst/ads_archive02.dbf&amp;#039; size 100M autoextend on next 50M maxsize unlimited&lt;br /&gt;
,        &amp;#039;/oracle/tst/ora_data3/adst/ads_archive03.dbf&amp;#039; size 100M autoextend on next 50M maxsize unlimited&lt;br /&gt;
,        &amp;#039;/oracle/tst/ora_data3/adst/ads_archive04.dbf&amp;#039; size 100M autoextend on next 50M maxsize unlimited&lt;br /&gt;
,        &amp;#039;/oracle/tst/ora_data3/adst/ads_archive05.dbf&amp;#039; size 100M autoextend on next 50M maxsize unlimited&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Import the tablespace metadata====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cat&amp;lt;&amp;lt;EOCAT &amp;gt;impdp_adst_ads_archive_metadata.par&lt;br /&gt;
userid=&amp;#039;/ as sysdba&amp;#039;&lt;br /&gt;
dumpfile=adst_ads_archive_metadata.dmp&lt;br /&gt;
logfile=impdp_adst_ads_archive_metadata.log&lt;br /&gt;
EOCAT&lt;br /&gt;
&lt;br /&gt;
impdp parfile=impdp_adst_ads_archive_metadata.par&lt;br /&gt;
&lt;br /&gt;
select &amp;#039;alter index &amp;#039;|| owner||&amp;#039;.&amp;#039;||index_name||&amp;#039; rebuild online parallel 8;&amp;#039;&lt;br /&gt;
from   dba_indexes&lt;br /&gt;
where  status = &amp;#039;UNUSABLE&amp;#039;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Import the last month partition data====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cat&amp;lt;&amp;lt;EOCAT &amp;gt;impdp_adst_ads_archive_partitions.par&lt;br /&gt;
userid=&amp;#039;/ as sysdba&amp;#039;&lt;br /&gt;
dumpfile=adst_ads_archive_Y2017_%U.dmp&lt;br /&gt;
logfile=impdp_adst_ads_archive_Y2017.log&lt;br /&gt;
table_exists_action=append&lt;br /&gt;
parallel=20&lt;br /&gt;
EOCAT&lt;br /&gt;
&lt;br /&gt;
impdp parfile=impdp_adst_ads_archive_partitions.par&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Write to a TCP/IP socket from PL/SQL===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
declare&lt;br /&gt;
 bt_conn               utl_tcp.connection;&lt;br /&gt;
 retval                binary_integer;&lt;br /&gt;
 l_sequence            varchar2(30) := &amp;#039;Sequence Number 101021&amp;#039;;&lt;br /&gt;
begin&lt;br /&gt;
 bt_conn := utl_tcp.open_connection(remote_host =&amp;gt; &amp;#039;10.10.1.1&amp;#039;&lt;br /&gt;
                                   ,remote_port =&amp;gt; 5000&lt;br /&gt;
                                   ,tx_timeout =&amp;gt; 1&lt;br /&gt;
                                   )&lt;br /&gt;
 ;&lt;br /&gt;
 retval := utl_tcp.write_line(bt_conn,l_sequence)&lt;br /&gt;
 ;&lt;br /&gt;
 utl_tcp.flush(bt_conn)&lt;br /&gt;
 ;&lt;br /&gt;
 utl_tcp.close_connection(bt_conn)&lt;br /&gt;
 ;&lt;br /&gt;
exception&lt;br /&gt;
 when others then&lt;br /&gt;
  raise_application_error(-20101, sqlerrm)&lt;br /&gt;
  ; &lt;br /&gt;
  utl_tcp.close_connection(bt_conn)&lt;br /&gt;
  ;&lt;br /&gt;
end&lt;br /&gt;
;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
and read from it using netcat in another session&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
nc -lk 5000&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
produces&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Sequence Number 101021&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Execute a script as a different user===&lt;br /&gt;
Some things have to be done as the user and cannot be done as sys (eg. creating and dropping jobs or create and drop a database link)&amp;lt;br /&amp;gt;&lt;br /&gt;
It is possible to login as the user by saving, changing and resetting his password (using identified by values) but using dbms_sys_sql is another option&amp;lt;br /&amp;gt;&lt;br /&gt;
Create a PL/SQL procedure to drop a db link&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
create or replace procedure drop_dblink ( p_schema_name in varchar2&lt;br /&gt;
                                        , p_dblink      in varchar2&lt;br /&gt;
                                        ) is&lt;br /&gt;
    l_plsql   varchar2(1000);&lt;br /&gt;
    l_cur     number;&lt;br /&gt;
    l_uid     number;&lt;br /&gt;
    l_rc      number;&lt;br /&gt;
begin&lt;br /&gt;
    select  du.user_id&lt;br /&gt;
    into    l_uid&lt;br /&gt;
    from    dba_users du&lt;br /&gt;
    where   du.username = p_schema_name&lt;br /&gt;
    ;&lt;br /&gt;
    plsql := &amp;#039;drop database link &amp;quot;&amp;#039;||p_dblink||&amp;#039;&amp;quot;&amp;#039;;&lt;br /&gt;
    l_cur := sys.dbms_sys_sql.open_cursor;&lt;br /&gt;
    sys.dbms_sys_sql.parse_as_user(&lt;br /&gt;
        c             =&amp;gt; l_cur,&lt;br /&gt;
        statement     =&amp;gt; l_plsql,&lt;br /&gt;
        language_flag =&amp;gt; dbms_sql.native,&lt;br /&gt;
        userid        =&amp;gt; l_uid&lt;br /&gt;
    );&lt;br /&gt;
    l_rc := sys.dbms_sys_sql.execute(l_cur);&lt;br /&gt;
    sys.dbms_sys_sql.close_cursor(l_cur);&lt;br /&gt;
end;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Generate the calls to the procedure with the required parameters&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select &amp;#039;exec drop_dblink (&amp;#039;&amp;#039;&amp;#039;|| owner ||&amp;#039;&amp;#039;&amp;#039;&amp;#039;||&amp;#039;, &amp;#039;||&amp;#039;&amp;#039;&amp;#039;&amp;#039;||db_link||&amp;#039;&amp;#039;&amp;#039;&amp;#039;||&amp;#039;);&amp;#039;&lt;br /&gt;
from   dba_db_links&lt;br /&gt;
where  owner   != &amp;#039;PUBLIC&amp;#039;&lt;br /&gt;
and    db_link like &amp;#039;%FTST%&amp;#039;&lt;br /&gt;
or     db_link like &amp;#039;%HDEV%&amp;#039;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
and this reveals the lines to be executed&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
exec drop_dblink (&amp;#039;USER1&amp;#039;, &amp;#039;DBL_FTST.WORLD&amp;#039;);&lt;br /&gt;
exec drop_dblink (&amp;#039;USER1&amp;#039;, &amp;#039;DBL_HDEV.WORLD&amp;#039;);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Drop the procedure when finished with it&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
drop procedure drop_dblink;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
or do it as an anonymous block in one go...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
declare&lt;br /&gt;
    uid number;&lt;br /&gt;
    sqltext varchar2(1000) := &amp;#039;drop database link &amp;quot;&amp;amp;DB_LINK&amp;quot;&amp;#039;;&lt;br /&gt;
    myint integer;&lt;br /&gt;
begin&lt;br /&gt;
    select user_id into uid from dba_users where username = &amp;#039;&amp;amp;USERNAME&amp;#039;;&lt;br /&gt;
    myint:=sys.dbms_sys_sql.open_cursor();&lt;br /&gt;
    sys.dbms_sys_sql.parse_as_user(myint,sqltext,dbms_sql.native,UID);&lt;br /&gt;
    sys.dbms_sys_sql.close_cursor(myint);&lt;br /&gt;
end;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Handling single quote marks inside SQL statements===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SQL&amp;gt; SELECT &amp;#039;D&amp;#039;&amp;#039;COSTA&amp;#039; name FROM DUAL;&lt;br /&gt;
&lt;br /&gt;
NAME&lt;br /&gt;
-------&lt;br /&gt;
D&amp;#039;COSTA&lt;br /&gt;
&lt;br /&gt;
Alternatively, use the 10g+ quoting method:&lt;br /&gt;
&lt;br /&gt;
SQL&amp;gt; SELECT q&amp;#039;$D&amp;#039;COSTA$&amp;#039; NAME FROM DUAL;&lt;br /&gt;
&lt;br /&gt;
NAME&lt;br /&gt;
-------&lt;br /&gt;
D&amp;#039;COSTA&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Run a script on all databases in /etc/oratab===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
export ORAENV_ASK=NO&lt;br /&gt;
for db in `awk -F: &amp;#039;NF &amp;amp;&amp;amp; $1 !~/[#*]/ {print $1}&amp;#039;  /etc/oratab`&lt;br /&gt;
do&lt;br /&gt;
    echo $db&lt;br /&gt;
    ORACLE_SID=$db&lt;br /&gt;
    . oraenv&lt;br /&gt;
    sqlplus -V&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Schedule a cron job to run on the last day of each month===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
0 23 28-31 * * [ $(date -d +1day +%d) -eq 1 ] &amp;amp;&amp;amp; su - oracle -c &amp;quot;dsmc  arch -server=SO_U_`hostname`_ORX_M_SOL &amp;#039;/oracle/export/PV6/expdp_PV6_D_FULL_`date +\%Y\%m\%d`*&amp;#039;&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===How to tell if a year is a leap year or not - using cal instead of reinventing the wheel===&lt;br /&gt;
Test: Why is Julian day 0, 17th November 1858?&amp;lt;br /&amp;gt;&lt;br /&gt;
Pretty comprehensive answer: [http://h71000.www7.hp.com/wizard/wiz_2315.html here] and [http://mentalfloss.com/article/51370/why-our-calendars-skipped-11-days-1752 here]&amp;lt;br /&amp;gt;&lt;br /&gt;
Also attempts to answer the question why typing &amp;#039;cal 09 1752&amp;#039; on Unix systems looks so odd!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
function leap {&lt;br /&gt;
#  This function tells you if the year passed in as a parameter is a leap year or not...&lt;br /&gt;
if [[ $(cal 2 ${1:-$(date &amp;#039;+%Y&amp;#039;)} | egrep &amp;#039;\&amp;lt;[[:digit:]]{1,2}\&amp;gt;&amp;#039; | wc -w) -eq 29 ]]; then&lt;br /&gt;
    leap=&amp;#039;Y&amp;#039;&lt;br /&gt;
else&lt;br /&gt;
    leap=&amp;#039;N&amp;#039;&lt;br /&gt;
fi&lt;br /&gt;
echo ${leap}&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Reset an expired (and/or locked) user password to the same value===&lt;br /&gt;
Can be used to save user passwords for example in a test environment before destroying them with a copy of production.&amp;lt;br /&amp;gt;&lt;br /&gt;
Simple, quick and easy version. Run this then pick and choose the statements you want to run.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 200 pages 200&lt;br /&gt;
col user_list for a200 head &amp;quot;Expired User List&amp;quot;&lt;br /&gt;
&lt;br /&gt;
select &amp;#039;alter user &amp;#039; ||su.name||&amp;#039; identified by values&amp;#039;||&amp;#039;&amp;#039;&amp;#039;&amp;#039;||spare4||&amp;#039;;&amp;#039;||su.password||&amp;#039;&amp;#039;&amp;#039; account unlock;&amp;#039; user_list&lt;br /&gt;
from   sys.user$ su&lt;br /&gt;
,      dba_users du&lt;br /&gt;
where  1=1&lt;br /&gt;
and    su.name              = du.username&lt;br /&gt;
and    du.oracle_maintained = &amp;#039;N&amp;#039;&lt;br /&gt;
and    (account_status      like &amp;#039;EXPIRED%&amp;#039; or account_status like &amp;#039;%LOCKED&amp;#039;)&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
More industrialised version. Create a package.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
create or replace package dba_utils&lt;br /&gt;
as&lt;br /&gt;
    procedure reset_password ( p_userlist in varchar2 );&lt;br /&gt;
end dba_utils;&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
create or replace package body dba_utils&lt;br /&gt;
as&lt;br /&gt;
&lt;br /&gt;
procedure reset_password ( p_userlist in varchar2 )&lt;br /&gt;
is&lt;br /&gt;
    cursor c1 ( p_userlist in varchar2 ) is&lt;br /&gt;
    select username&lt;br /&gt;
    ,      regexp_substr ( dbms_metadata.get_ddl(&amp;#039;USER&amp;#039;, username), &amp;#039;&amp;#039;&amp;#039;[^&amp;#039;&amp;#039;]+&amp;#039;&amp;#039;&amp;#039; ) pwd&lt;br /&gt;
    from   dba_users&lt;br /&gt;
    where  1=1&lt;br /&gt;
    and    username in upper( p_userlist )&lt;br /&gt;
    ;&lt;br /&gt;
begin&lt;br /&gt;
    dbms_output.enable(null);&lt;br /&gt;
    for r1 in c1 ( p_userlist )&lt;br /&gt;
    loop&lt;br /&gt;
        begin&lt;br /&gt;
            execute immediate &amp;#039;alter user &amp;#039; || r1.username || &amp;#039; account unlock&amp;#039;;&lt;br /&gt;
            execute immediate &amp;#039;alter user &amp;#039; || r1.username || &amp;#039; identified by values &amp;#039; || r1.pwd;&lt;br /&gt;
        exception&lt;br /&gt;
        when others then&lt;br /&gt;
            dbms_output.put_line(&amp;#039;Unable to modify user &amp;#039; || r1.username);&lt;br /&gt;
        end;&lt;br /&gt;
    end loop;&lt;br /&gt;
end reset_password;&lt;br /&gt;
&lt;br /&gt;
end dba_utils;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Call it&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set serveroutput on&lt;br /&gt;
exec dba_utils.reset_password (&amp;#039;STUART&amp;#039;);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Latch, mutex and beyond===&lt;br /&gt;
A fine example of how to write scripts from SQL*Plus that interact with the shell underneath&amp;lt;br /&amp;gt;&lt;br /&gt;
Found [https://andreynikolaev.wordpress.com/demonstration-scripts/cursor_pin_s_contention-sql/ here at andreynikolaev.wordpress.com]&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/*&lt;br /&gt;
     This file is part of demos for &amp;quot;Mutex Internals&amp;quot;  seminar v.04.04.2011&lt;br /&gt;
     Andrey S. Nikolaev (Andrey.Nikolaev@rdtex.ru) &lt;br /&gt;
     https://andreynikolaev.wordpress.com &lt;br /&gt;
 &lt;br /&gt;
     &amp;quot;Cursor: pin S&amp;quot; contention testcase.&lt;br /&gt;
 &lt;br /&gt;
     The script spawn several sessions to induce &amp;quot;Cursor: pin S&amp;quot;, &lt;br /&gt;
     creates AWR snapshots and generates AWR report&lt;br /&gt;
 &lt;br /&gt;
     Beware: The script will restart the test database.&lt;br /&gt;
 &lt;br /&gt;
     usage: sqlplus /nolog @cursor_pin_s_contention.sql &amp;lt;parallelism&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
*/ &lt;br /&gt;
connect / as sysdba&lt;br /&gt;
startup force&lt;br /&gt;
set echo off&lt;br /&gt;
set define %&lt;br /&gt;
set verify off&lt;br /&gt;
set head off&lt;br /&gt;
set linesize 300&lt;br /&gt;
 &lt;br /&gt;
/* spawn parallel processes to create load on mutex */&lt;br /&gt;
spool one_thread.tmp&lt;br /&gt;
select &amp;#039;set verify off&amp;#039; from dual;&lt;br /&gt;
select &amp;#039;alter session set session_cached_cursors = 50;&amp;#039; from dual; &lt;br /&gt;
select &amp;#039;begin for i in 1..1000000 loop&amp;#039; from dual;&lt;br /&gt;
select &amp;#039;      execute immediate &amp;#039;&amp;#039;select 1 from dual where 1=2&amp;#039;&amp;#039;;&amp;#039; from dual;&lt;br /&gt;
select &amp;#039;end loop; end;&amp;#039;||chr(10)||&amp;#039;/&amp;#039; from dual;&lt;br /&gt;
spool off&lt;br /&gt;
 &lt;br /&gt;
/* sleep while AWR initialized */&lt;br /&gt;
host sleep 5&lt;br /&gt;
 &lt;br /&gt;
exec dbms_workload_repository.create_snapshot();&lt;br /&gt;
 &lt;br /&gt;
spool many_threads.tmp&lt;br /&gt;
select &amp;#039;host sqlplus &amp;quot;/ as sysdba&amp;quot; @one_thread.tmp &amp;amp;&amp;#039;&lt;br /&gt;
from dba_objects where rownum &amp;lt;= %1;&lt;br /&gt;
spool off&lt;br /&gt;
 &lt;br /&gt;
@many_threads.tmp&lt;br /&gt;
host sleep 50&lt;br /&gt;
set echo on&lt;br /&gt;
exec dbms_workload_repository.create_snapshot();&lt;br /&gt;
set markup html on&lt;br /&gt;
set head on&lt;br /&gt;
spool mutex_sleep_history.htm&lt;br /&gt;
select to_char(SLEEP_TIMESTAMP,&amp;#039;hh:mi:ss.ff&amp;#039;) SLEEP_TIMESTAMP,MUTEX_ADDR,MUTEX_IDENTIFIER,MUTEX_TYPE,&lt;br /&gt;
       GETS,SLEEPS,REQUESTING_SESSION,BLOCKING_SESSION,&lt;br /&gt;
       LOCATION,MUTEX_VALUE from x$mutex_sleep_history order by sleep_timestamp;&lt;br /&gt;
spool off&lt;br /&gt;
 &lt;br /&gt;
set define &amp;amp;&lt;br /&gt;
set markup html off&lt;br /&gt;
set echo off heading on underline on;&lt;br /&gt;
column inst_num  heading &amp;quot;Inst Num&amp;quot;  new_value inst_num  format 99999;&lt;br /&gt;
column inst_name heading &amp;quot;Instance&amp;quot;  new_value inst_name format a12;&lt;br /&gt;
column db_name   heading &amp;quot;DB Name&amp;quot;   new_value db_name   format a12;&lt;br /&gt;
column dbid      heading &amp;quot;DB Id&amp;quot;     new_value dbid      format 9999999999 just c;&lt;br /&gt;
select d.dbid            dbid&lt;br /&gt;
     , d.name            db_name&lt;br /&gt;
     , i.instance_number inst_num&lt;br /&gt;
     , i.instance_name   inst_name&lt;br /&gt;
  from v$database d,&lt;br /&gt;
       v$instance i;&lt;br /&gt;
define num_days=1;&lt;br /&gt;
define report_type=&amp;#039;html&amp;#039;;&lt;br /&gt;
col end_snap new_value end_snap;&lt;br /&gt;
col begin_snap new_value begin_snap;&lt;br /&gt;
select max(snap_id) end_snap from dba_hist_snapshot where dbid=&amp;amp;dbid;&lt;br /&gt;
select max(snap_id) begin_snap from dba_hist_snapshot where dbid=&amp;amp;dbid and snap_id &amp;lt; &amp;amp;end_snap;&lt;br /&gt;
define report_name=&amp;#039;awr_report.htm&amp;#039;;&lt;br /&gt;
@?/rdbms/admin/awrrpti&lt;br /&gt;
exit&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==shell==&lt;br /&gt;
[http://www.databasejournal.com/features/oracle/article.php/3869076/Alert-Log-Scraping-with-Oracles-ADRCI-Utility.htm Alert Log scraping with ADRCI]&lt;br /&gt;
&lt;br /&gt;
====Count the number of background processes for a particular SID====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SID=RAVJDE1&lt;br /&gt;
ps -ef|cut -c54-100|awk -v SID=$SID &amp;#039;$0 ~ /&amp;#039;$SID&amp;#039;$/ {print}&amp;#039;|wc -l&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or ...this will work with any OS (so long as the process is at the end of the &amp;lt;strong&amp;gt;ps -ef&amp;lt;/strong&amp;gt; or &amp;lt;strong&amp;gt;ps -aux&amp;lt;/strong&amp;gt; listing&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SID=RAVJDE1&lt;br /&gt;
ps -ef|awk -v SID=$SID -F_ &amp;#039;{ $NF ~ /&amp;#039;$SID&amp;#039;$/ {print} }&amp;#039;|wc -l&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Pick the columns you want in the ps listing&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ps -efo user,pid,ppid=MOM -o args&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Find Oracle errors in the most recent DataPump log files====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
00 09 * * * /home/tools/scripts/oracle/dosh &amp;#039;find /oracle/export -name &amp;quot;expdp*log&amp;quot; -mtime -1 -exec grep ORA- {} \; -ls&amp;#039; | mailx -s &amp;#039;Datapump errors for &amp;lt;customer&amp;gt;last night&amp;#039; stuart@domain.com&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Find the 10 largest directories on a particular filesystem====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
du -ag /oracle | sort -nr | head -n 10&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Find the 10 largest files on a particular mount point====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
find /home -size +1G -ls | sort -nr +6 | head -10&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
find /home -xdev -ls | sort -nr +6 | head -10&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Split a file in pieces using sed====&lt;br /&gt;
Using fixed line numbers&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sed -ne &amp;#039;1,12p&amp;#039; file &amp;gt; text.part1&lt;br /&gt;
sed -ne &amp;#039;13,$p&amp;#039; file &amp;gt; text.part2&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Using line with a /pattern/ on it&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sed -e &amp;#039;/hello/q&amp;#039; tt.dat | grep -v hello &amp;gt; text.part1&lt;br /&gt;
sed -n `sed -n &amp;#039;/hello/=&amp;#039; tt.dat`&amp;#039;,$p&amp;#039; tt.dat | grep -v hello &amp;gt; text.part2&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Split a file in pieces using Perl====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
perl -ne &amp;#039;print if 1 .. /marker line/&amp;#039; text.dat &amp;gt;text.part1&lt;br /&gt;
perl -ne &amp;#039;print if /marker line/ .. eof()&amp;#039; text.dat &amp;gt;text.part2&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Find and display RMAN errors in an RMAN log file====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sed -ne &amp;#039;/^RMAN-/,/^$/p&amp;#039;  RMAN_&amp;lt;SID&amp;gt;_&amp;lt;DATE&amp;gt;.log&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==cmd==&lt;br /&gt;
*[http://www.dba-oracle.com/t_scripts_windows_export.htm Database Export - from DBA Oracle (Burleson)]&lt;br /&gt;
==Perl==&lt;br /&gt;
===For all files in a directory, replace a keyword (SSIIDD) in a file with another (a parameter)===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
for i in `ls`&lt;br /&gt;
do&lt;br /&gt;
    perl -p -i -e &amp;#039;s/SSIIDD/&amp;#039;$SID&amp;#039;/g&amp;#039; $i&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Parse tnsnames.ora to get just the service names===&lt;br /&gt;
[[http://stackoverflow.com/questions/12605415/parsing-tnsnames-ora-with-regex-to-just-get-name from here]]&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
perl -ne &amp;#039;print if m/^([^#()\W ][a-zA-Z.]*(?:[.][a-zA-Z]*\s?=)?)/&amp;#039; $TNS_ADMIN/tnsnames.ora&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===and use that to check the listener status===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
for svc in `perl -ne &amp;#039;print if m/^([^#()\W ][a-zA-Z.]*(?:[.][a-zA-Z]*\s?=)?)/&amp;#039; $TNS_ADMIN/tnsnames.ora | sed -e &amp;#039;s/=//&amp;#039;` ;do&lt;br /&gt;
    tnsping $svc&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Stuart</name></author>	</entry>

	<entry>
		<id>https://mailnest.com/dbawiki/index.php?title=Handy_scripts&amp;diff=3375</id>
		<title>Handy scripts</title>
		<link rel="alternate" type="text/html" href="https://mailnest.com/dbawiki/index.php?title=Handy_scripts&amp;diff=3375"/>
				<updated>2018-11-21T12:00:32Z</updated>
		
		<summary type="html">&lt;p&gt;Stuart: /* External table for the Alert log (pre 11g) */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==SQL==&lt;br /&gt;
* [[Database Overview - from idevelopment]] [http://www.idevelopment.info/data/Oracle/DBA_scripts/Database_Administration/dba_snapshot_database_10g.sql online version]&lt;br /&gt;
* [[Extract ddl with &amp;quot;dbms metadata.get ddl&amp;quot;]]&lt;br /&gt;
* [http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:83012348058 Connecting as another user via proxy in SQL*Plus]&lt;br /&gt;
* [http://www.petefinnigan.com/tools.htm Password cracker and role and priv tools from Pete Finnigan]&lt;br /&gt;
* [http://www.oracle.com/technetwork/articles/sql/11g-pivot-097235.html Using pivot tables in SQL - XML and XLS (Excel) also)]&lt;br /&gt;
===List all instances running on a server===&lt;br /&gt;
Sounds simple enough and indeed pre 12.1, is was as easy as either&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ps -ef | grep [p]mon | awk -F_ &amp;#039;{print $NF}&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or this one is safer in case you have an underscore character in your SID name!!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SIDLIST=$(${PS} -ef | ${GREP} [o]ra_pmon | ${AWK} &amp;#039;{print $NF}&amp;#039; | sed -e &amp;#039;s/ora_pmon_//&amp;#039; | egrep -v &amp;#039;grep|///|sed|awk|ASM|^$&amp;#039;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
but now we have the added complication of CDB/PDB (container / pluggable databases) so a fair bit more work is needed!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/ksh&lt;br /&gt;
# ==============================================================================&lt;br /&gt;
# Name         : list_server_db&lt;br /&gt;
# Description  : List all running databases found on a server&lt;br /&gt;
#&lt;br /&gt;
# Parameters   : none&lt;br /&gt;
#&lt;br /&gt;
# Notes        : none&lt;br /&gt;
#&lt;br /&gt;
# Modification History&lt;br /&gt;
# ====================&lt;br /&gt;
# When      Who               What&lt;br /&gt;
# ========= ================= ==================================================&lt;br /&gt;
# 21-DEC-16 Stuart Barkley    Created&lt;br /&gt;
# ==============================================================================&lt;br /&gt;
for db in $(ps -ef | grep [p]mon|awk -F_ &amp;#039;{print $NF}&amp;#039;)&lt;br /&gt;
do&lt;br /&gt;
    export ORACLE_SID=${db}&lt;br /&gt;
    ORAENV_ASK=NO&lt;br /&gt;
    . oraenv &amp;gt;/dev/null 2&amp;gt;&amp;amp;1&lt;br /&gt;
    sqlplus -s / as sysdba&amp;lt;&amp;lt;EOSQL&lt;br /&gt;
set serveroutput on feed off pages 0 head off newpa none&lt;br /&gt;
declare&lt;br /&gt;
    e_col_not_found exception;&lt;br /&gt;
    e_not_mounted   exception;&lt;br /&gt;
    pragma          exception_init(e_not_mounted, -01507);&lt;br /&gt;
    pragma          exception_init(e_col_not_found, -904);&lt;br /&gt;
    l_db_name       varchar2(20);&lt;br /&gt;
    l_database_role varchar2(20);&lt;br /&gt;
    l_cdb           varchar2(20);&lt;br /&gt;
    l_status        varchar2(20);&lt;br /&gt;
    type varchar2_tab is table of varchar2(240) index by binary_integer;&lt;br /&gt;
    t_pdbs          varchar2_tab;&lt;br /&gt;
begin&lt;br /&gt;
    begin&lt;br /&gt;
        dbms_output.enable(null);&lt;br /&gt;
        execute immediate &amp;#039;select name, database_role, cdb from v\$database&amp;#039; into l_db_name, l_database_role, l_cdb;&lt;br /&gt;
        if l_cdb = &amp;#039;YES&amp;#039; then&lt;br /&gt;
            l_status := &amp;#039;CDB&amp;#039;;&lt;br /&gt;
            execute immediate &amp;#039;select name from v\$pdbs&amp;#039; bulk collect into t_pdbs;&lt;br /&gt;
            for i in nvl(t_pdbs.first,1) .. nvl(t_pdbs.last,0)&lt;br /&gt;
            loop&lt;br /&gt;
                dbms_output.put_line (t_pdbs(i)||&amp;#039;:PDB&amp;#039;);&lt;br /&gt;
            end loop;&lt;br /&gt;
        else&lt;br /&gt;
            l_status := &amp;#039;Independent&amp;#039;;  -- col CDB exists but this is not one&lt;br /&gt;
        end if;&lt;br /&gt;
        if l_database_role like &amp;#039;%STANDBY%&amp;#039; then&lt;br /&gt;
            l_status := &amp;#039;Standby&amp;#039;;&lt;br /&gt;
        end if;&lt;br /&gt;
    exception&lt;br /&gt;
    when e_not_mounted then&lt;br /&gt;
        l_status := &amp;#039;Not Mounted&amp;#039;;&lt;br /&gt;
    when e_col_not_found then&lt;br /&gt;
        l_status := &amp;#039;pre12&amp;#039;;&lt;br /&gt;
    end;&lt;br /&gt;
&lt;br /&gt;
    dbms_output.put_line (&amp;#039;${db}&amp;#039;||&amp;#039;:&amp;#039;||l_status);&lt;br /&gt;
&lt;br /&gt;
end;&lt;br /&gt;
/&lt;br /&gt;
EOSQL&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Run a command or script on all databases in tnsnames.ora===&lt;br /&gt;
Very handy if you have a global tnsnames.ora accessible to all clients.&amp;lt;br /&amp;gt;&lt;br /&gt;
So from a client install, this has access to all databases.&amp;lt;br /&amp;gt;&lt;br /&gt;
Any files created can be created on the client so no need to scp to all the machines to recover spool files etc.&amp;lt;br /&amp;gt;&lt;br /&gt;
Downside: Cannot connect as sysdba across tns so password will need to be known for whatever user is used.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/ksh&lt;br /&gt;
TNSNAMES=&amp;quot;./tnsnames.ora&amp;quot;&lt;br /&gt;
[[ ! -r &amp;quot;${TNSNAMES}&amp;quot; ]] &amp;amp;&amp;amp; echo &amp;quot;${TNSNAMES} is not accessible&amp;quot; &amp;amp;&amp;amp; exit 1&lt;br /&gt;
&lt;br /&gt;
SIDLIST=$(perl -ne &amp;#039;print &amp;quot;$1\n&amp;quot; if /(?:SID|SERVICE_NAME)\s*=\s*(\S+?)\)/&amp;#039; ${TNSNAMES}|sort|uniq|xargs)&lt;br /&gt;
for SID in ${SIDLIST}&lt;br /&gt;
do&lt;br /&gt;
    echo &amp;quot;Processing $SID&amp;quot;&lt;br /&gt;
    ls -al | grep &amp;quot;^d&amp;quot; | grep &amp;quot;\_${SID}&amp;quot; &amp;gt;/dev/null&lt;br /&gt;
    if [[ $? -ne 0 ]]; then&lt;br /&gt;
        echo &amp;#039;exit&amp;#039; | sqlplus system/xxxxxx@${SID} @ReviewLite17.1.sql &amp;gt;/dev/null 2&amp;gt;&amp;amp;1&lt;br /&gt;
    else&lt;br /&gt;
        echo &amp;quot;directory already exists so must have done this SID&amp;quot;&lt;br /&gt;
    fi&lt;br /&gt;
done&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Run a command or script on all databases in oratab===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/usr/bin/ksh&lt;br /&gt;
# ==============================================================================&lt;br /&gt;
# Name         : all_db_do&lt;br /&gt;
# Description  : Loops over all the databases in oratab and executes the&lt;br /&gt;
#                specified SQL command - be careful!&lt;br /&gt;
#&lt;br /&gt;
# Parameters   : -v flag for verbose&lt;br /&gt;
#                [-f &amp;lt;filename&amp;gt; | &amp;lt;quoted SQL command to be executed&amp;gt;]&lt;br /&gt;
#&lt;br /&gt;
# Example      : all_db_do &amp;#039;alter system switch logfile;&amp;#039;&lt;br /&gt;
#                all_db_do -f sessions.sql&lt;br /&gt;
#&lt;br /&gt;
# Notes        : none&lt;br /&gt;
#&lt;br /&gt;
# Modification History&lt;br /&gt;
# ====================&lt;br /&gt;
# When      Who               What&lt;br /&gt;
# ========= ================= ==================================================&lt;br /&gt;
# 14-JAN-13 Stuart Barkley    Created&lt;br /&gt;
# 25-FEB-13 Stuart Barkley    Adapt for Solaris&lt;br /&gt;
# 21-MAR-13 Stuart Barkley    Check db is running first&lt;br /&gt;
# 29-APR-13 Stuart Barkley    Added verbose flag processing&lt;br /&gt;
# 24-MAY-13 Stuart Barkley    Wrap / as sysdba in quotes for older versions&lt;br /&gt;
# 23-JUN-16 Stuart Barkley    Add -f to run a file containing sql&lt;br /&gt;
# ==============================================================================&lt;br /&gt;
&lt;br /&gt;
PROGNAME=$(basename $0)&lt;br /&gt;
OS=$(uname -s)&lt;br /&gt;
&lt;br /&gt;
AWK=$(which awk)&lt;br /&gt;
GREP=$(which grep)&lt;br /&gt;
if [[ &amp;quot;${OS}&amp;quot; == &amp;quot;SunOS&amp;quot; ]]; then&lt;br /&gt;
    AWK=/usr/xpg4/bin/awk&lt;br /&gt;
    GREP=/usr/xpg4/bin/grep&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
if [[ ! -r /etc/oratab ]]; then&lt;br /&gt;
    if [[ &amp;quot;${OS}&amp;quot; == &amp;quot;SunOS&amp;quot; ]]; then&lt;br /&gt;
        echo &amp;quot;oratab is not where we want it. Please run &amp;#039;ln -s /var/opt/oracle/oratab /etc/oratab&amp;#039; as root and retry&amp;quot; &amp;amp;&amp;amp; exit 1&lt;br /&gt;
    else&lt;br /&gt;
        echo &amp;quot;Either Oracle is not installed or database is running without an oratab&amp;quot; &amp;amp;&amp;amp; exit 1&lt;br /&gt;
    fi&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
# -------------------------&lt;br /&gt;
# get the arguments, if any&lt;br /&gt;
# -------------------------&lt;br /&gt;
unset VERBOSE&lt;br /&gt;
while getopts &amp;quot;vf:&amp;quot; flag&lt;br /&gt;
do&lt;br /&gt;
    case &amp;quot;$flag&amp;quot; in&lt;br /&gt;
    v) VERBOSE=1;;&lt;br /&gt;
    f) FILE2RUN=$OPTARG;;&lt;br /&gt;
    esac&lt;br /&gt;
done&lt;br /&gt;
shift $((OPTIND-1))&lt;br /&gt;
&lt;br /&gt;
if [[ -z ${FILE2RUN} ]]; then&lt;br /&gt;
    # no file, need an SQL supplied&lt;br /&gt;
    if [[ -z $1 ]]; then&lt;br /&gt;
        echo &amp;quot;Usage: $0 [-v] [-f &amp;lt;filename&amp;gt; | &amp;lt;quoted SQL command to be executed&amp;gt;]&amp;quot;&lt;br /&gt;
        echo &amp;quot;eg: $0 -f sessions.sql&amp;quot;&lt;br /&gt;
        echo &amp;quot;eg: $0 &amp;#039;alter system switch logfile;&amp;#039;&amp;quot;&lt;br /&gt;
        exit 1&lt;br /&gt;
    fi&lt;br /&gt;
    SQL=$1&lt;br /&gt;
elif [[ -s ${FILE2RUN} ]]; then&lt;br /&gt;
    # file supplied and exists&lt;br /&gt;
    SQL=&amp;quot;@${FILE2RUN}&amp;quot;&lt;br /&gt;
else&lt;br /&gt;
    # file supplied, does it exist&lt;br /&gt;
    echo &amp;quot;File ${FILE2RUN} is empty or does not exist&amp;quot;&lt;br /&gt;
    echo &amp;quot;Usage: $0 [-v] [-f &amp;lt;filename&amp;gt; | &amp;lt;quoted SQL command to be executed&amp;gt;]&amp;quot;&lt;br /&gt;
    echo &amp;quot;eg: $0 -f sessions.sql&amp;quot;&lt;br /&gt;
    echo &amp;quot;eg: $0 &amp;#039;alter system switch logfile;&amp;#039;&amp;quot;&lt;br /&gt;
    exit 1&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
export ORAENV_ASK=NO&lt;br /&gt;
&lt;br /&gt;
for db in $(${AWK} -F: &amp;#039;NF &amp;amp;&amp;amp; $1 !~/[#*]/ {print $1}&amp;#039;  /etc/oratab)&lt;br /&gt;
do&lt;br /&gt;
    if ( [[ $1 != &amp;quot;startup&amp;quot; ]] &amp;amp;&amp;amp; [[ $(ps -ef | ${GREP} -c -E [o]ra_pmon_${db}) -eq 0 ]] ); then&lt;br /&gt;
        [[ ! -z &amp;quot;$VERBOSE&amp;quot; ]] &amp;amp;&amp;amp; echo &amp;quot;$db is not running, skipping...&amp;quot;&lt;br /&gt;
        continue&lt;br /&gt;
    fi&lt;br /&gt;
    echo&lt;br /&gt;
    [[ ! -z &amp;quot;$VERBOSE&amp;quot; ]] &amp;amp;&amp;amp; echo &amp;quot;vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv&amp;quot;&lt;br /&gt;
    [[ ! -z &amp;quot;$VERBOSE&amp;quot; ]] &amp;amp;&amp;amp; echo $db&lt;br /&gt;
    ORACLE_SID=$db&lt;br /&gt;
    . oraenv &amp;gt;/dev/null&lt;br /&gt;
    sqlplus -s &amp;quot;/ as sysdba&amp;quot; &amp;lt;&amp;lt;EOSQL&lt;br /&gt;
define SID=$ORACLE_SID&lt;br /&gt;
col comp_name format a50&lt;br /&gt;
col value for a40&lt;br /&gt;
set linesize 1000&lt;br /&gt;
set pagesize 100&lt;br /&gt;
$SQL&lt;br /&gt;
EOSQL&lt;br /&gt;
    [[ ! -z &amp;quot;$VERBOSE&amp;quot; ]] &amp;amp;&amp;amp; echo &amp;quot;^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^&amp;quot;&lt;br /&gt;
done&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
all_db_do &amp;quot;create or replace directory data_pump_dir as &amp;#039;/oracle/export/&amp;amp;SID&amp;#039;;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
all_db_do &amp;quot;archive log list&amp;quot;&lt;br /&gt;
&lt;br /&gt;
all_db_do &amp;quot;shutdown immediate&amp;quot;&lt;br /&gt;
&lt;br /&gt;
all_db_do &amp;#039;alter system set log_archive_dest_1=&amp;quot;location=/oracle/arch/&amp;amp;SID&amp;quot; scope=both;&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Run an SQL command on behalf of another user===&lt;br /&gt;
It can be used to execute any sql command as a specified user provided this procedure is created in sys schema.&amp;lt;br /&amp;gt;&lt;br /&gt;
* not got this working properly yet *&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set serveroutput on&lt;br /&gt;
create or replace procedure run_sql_as_user ( p_schema_name in varchar2&lt;br /&gt;
                                            , p_sql         in varchar2&lt;br /&gt;
                                            ) is&lt;br /&gt;
    l_user_id dba_users.user_id%type;&lt;br /&gt;
    l_cursor  number;&lt;br /&gt;
    l_rc      number;&lt;br /&gt;
begin&lt;br /&gt;
    dbms_output.enable(null);&lt;br /&gt;
    begin&lt;br /&gt;
        select u.user_id&lt;br /&gt;
        into   l_user_id&lt;br /&gt;
        from   dba_users u&lt;br /&gt;
        where  u.username = p_schema_name;&lt;br /&gt;
    exception&lt;br /&gt;
    when no_data_found then&lt;br /&gt;
        raise_application_error (-20001, &amp;#039;Cannot find user &amp;#039;||p_schema_name);&lt;br /&gt;
    end;&lt;br /&gt;
    l_cursor := dbms_sys_sql.open_cursor;&lt;br /&gt;
    dbms_sys_sql.parse_as_user ( c             =&amp;gt; l_cursor&lt;br /&gt;
                               , statement     =&amp;gt; p_sql&lt;br /&gt;
                               , language_flag =&amp;gt; dbms_sql.native&lt;br /&gt;
                               , userid        =&amp;gt; l_user_id&lt;br /&gt;
    );&lt;br /&gt;
    l_rc := dbms_sys_sql.execute(l_cursor);&lt;br /&gt;
    dbms_sys_sql.close_cursor(l_cursor);&lt;br /&gt;
exception&lt;br /&gt;
when others then&lt;br /&gt;
    raise_application_error (-20001, &amp;#039;ERROR: &amp;#039;||sqlerrm);&lt;br /&gt;
end;&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Run a script on all databases listed in tnsnames.ora===&lt;br /&gt;
Can run an SQL command file on all SID/SERVICE found in a tnsnames.ora file. I use this from a client laptop having a global tns file on it.&amp;lt;br /&amp;gt;&lt;br /&gt;
This way it&amp;#039;s not necessary to copy the file onto every host before executing it. Any files created by the script will be created on the client.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/ksh&lt;br /&gt;
&lt;br /&gt;
TNSNAMES=&amp;quot;./tnsnames.ora&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[ ! -r &amp;quot;${TNSNAMES}&amp;quot; ]] &amp;amp;&amp;amp; echo &amp;quot;${TNSNAMES} is not accessible&amp;quot; &amp;amp;&amp;amp; exit 1&lt;br /&gt;
&lt;br /&gt;
SIDLIST=$(perl -ne &amp;#039;print &amp;quot;$1\n&amp;quot; if /(?:SID|SERVICE_NAME)\s*=\s*(\S+?)\)/&amp;#039; ${TNSNAMES}|sort|uniq|xargs)&lt;br /&gt;
for SID in ${SIDLIST}&lt;br /&gt;
do&lt;br /&gt;
    echo &amp;quot;Processing $SID&amp;quot;&lt;br /&gt;
    ls -al | grep &amp;quot;^d&amp;quot; | grep &amp;quot;\_${SID}&amp;quot; &amp;gt;/dev/null&lt;br /&gt;
    if [[ $? -ne 0 ]]; then&lt;br /&gt;
        echo &amp;#039;exit&amp;#039; | sqlplus system/password@${SID} @ReviewLite17.1.sql &amp;gt;/dev/null 2&amp;gt;&amp;amp;1&lt;br /&gt;
    else&lt;br /&gt;
        echo &amp;quot;directory already exists so must have done this SID&amp;quot;&lt;br /&gt;
    fi&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===List invalid objects===&lt;br /&gt;
 set lines 200&lt;br /&gt;
 set pages 200&lt;br /&gt;
 col obj format a40&lt;br /&gt;
 select owner||&amp;#039;.&amp;#039;||object_name obj&lt;br /&gt;
 ,      object_type&lt;br /&gt;
 from   dba_objects&lt;br /&gt;
 where  1=1&lt;br /&gt;
 and    status = &amp;#039;INVALID&amp;#039;;&lt;br /&gt;
===Recompile all invalid objects===&lt;br /&gt;
@?/rdbms/admin/utlrp.sql&lt;br /&gt;
===See how much space is left in the flash recovery area (FRA)===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select name&lt;br /&gt;
,      to_char (space_limit, &amp;#039;999,999,999,999&amp;#039;) as space_limit&lt;br /&gt;
,      to_char (space_limit - space_used + space_reclaimable&lt;br /&gt;
,               &amp;#039;999,999,999,999&amp;#039;)&lt;br /&gt;
           as space_available&lt;br /&gt;
,      round ( (space_used - space_reclaimable) / space_limit * 100, 1)&lt;br /&gt;
           as pct_full&lt;br /&gt;
from   v$recovery_file_dest;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# ==============================================&lt;br /&gt;
# Check FRA to see how much space is reclaimable&lt;br /&gt;
# ==============================================&lt;br /&gt;
fra_reclaim_check() {&lt;br /&gt;
&lt;br /&gt;
LOGFILE=${RMAN_LogDir}/${ORACLE_SID}_`date &amp;#039;+%Y%m&amp;#039;`_${V_SCRIPT}.log&lt;br /&gt;
sqlplus &amp;quot;/ as sysdba&amp;quot; &amp;lt;&amp;lt;EOSQL &amp;gt; /tmp/results.$$&lt;br /&gt;
set vefify off echo off heading off newpage none linesize 1000 echo off&lt;br /&gt;
select &amp;#039;Filesystem:&amp;#039;||name||&lt;br /&gt;
       &amp;#039;; Total(Gb):&amp;#039;||round((space_limit/1073741824),2) ||&lt;br /&gt;
       &amp;#039;; Reclaimable(Gb):&amp;#039;||round((space_reclaimable/1073741824),2) ||&lt;br /&gt;
       &amp;#039;; Reclaimable(%):&amp;#039;||round( ((space_reclaimable/1073741824)/(space_limit/1073741824)*100),2 )&lt;br /&gt;
from   v$recovery_file_dest&lt;br /&gt;
/&lt;br /&gt;
EOSQL&lt;br /&gt;
cat /tmp/results.$$ &amp;gt;&amp;gt; $LOGFILE&lt;br /&gt;
rm /tmp/results.$$&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===How far back can we flashback?===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
col time_now              for a25&lt;br /&gt;
col time_oldest_flashback for a25&lt;br /&gt;
select to_char(sysdate,&amp;#039;DD-MON-YY HH24:MI&amp;#039;)                    time_now&lt;br /&gt;
,      to_char(fdl.oldest_flashback_time, &amp;#039;DD-MON-YY HH24:MI&amp;#039;) time_oldest_flashback&lt;br /&gt;
,      round((sysdate-fdl.oldest_flashback_time)*24,1)         hours_flashback_possible&lt;br /&gt;
from   v$database d&lt;br /&gt;
,      v$flashback_database_log fdl&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===DBA privs tables===&lt;br /&gt;
 DBA_AQ_AGENT_PRIVS&lt;br /&gt;
 DBA_COL_PRIVS&lt;br /&gt;
 DBA_PRIV_AUDIT_OPTS&lt;br /&gt;
 DBA_REPGROUP_PRIVILEGES&lt;br /&gt;
 DBA_ROLE_PRIVS&lt;br /&gt;
 DBA_RSRC_CONSUMER_GROUP_PRIVS&lt;br /&gt;
 DBA_RSRC_MANAGER_SYSTEM_PRIVS&lt;br /&gt;
 DBA_SYS_PRIVS&lt;br /&gt;
 DBA_TAB_PRIVS&lt;br /&gt;
 DBA_WM_SYS_PRIVS&lt;br /&gt;
 DBA_WORKSPACE_PRIVS&lt;br /&gt;
&lt;br /&gt;
===Schedule a shell job===&lt;br /&gt;
 begin&lt;br /&gt;
     dbms_scheduler.create_program ( program_name   =&amp;gt; &amp;#039;myshelljob&amp;#039;&lt;br /&gt;
                                   , program_action =&amp;gt; &amp;#039;/home/oracle/scripts/shell.sh&amp;#039;&lt;br /&gt;
                                   , program_type   =&amp;gt; &amp;#039;EXECUTABLE&amp;#039;&lt;br /&gt;
                                   , comments       =&amp;gt; &amp;#039;Run a shell&amp;#039;&lt;br /&gt;
                                   , enabled        =&amp;gt; TRUE&lt;br /&gt;
                                   );&lt;br /&gt;
 end;&lt;br /&gt;
 /&lt;br /&gt;
===Start the job===&lt;br /&gt;
 begin&lt;br /&gt;
     dbms_sheduler.create_job ( job_name     =&amp;gt; &amp;#039;myshelljob&amp;#039;&lt;br /&gt;
                              , program_name =&amp;gt; &amp;#039;myshelljob&amp;#039;&lt;br /&gt;
                              , start_date   =&amp;gt;&lt;br /&gt;
                              );&lt;br /&gt;
 /&lt;br /&gt;
&lt;br /&gt;
===What statement is a user running?===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select a.sid&lt;br /&gt;
,      a.serial#&lt;br /&gt;
,      b.sql_text&lt;br /&gt;
from   v$session a&lt;br /&gt;
,      v$sqlarea b&lt;br /&gt;
where  a.sql_address = b.address&lt;br /&gt;
and    a.username    = &amp;#039;&amp;amp;username&amp;#039;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===See what statements all users are running===&lt;br /&gt;
Useful to see what is happening when process limit is reached&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 300 pages 1000&lt;br /&gt;
&lt;br /&gt;
col username for a10&lt;br /&gt;
col command for 999 head &amp;quot;CMD&amp;quot;&lt;br /&gt;
col lockwait for a10&lt;br /&gt;
col status for a8&lt;br /&gt;
col schemaname for a12&lt;br /&gt;
col osuser for a10&lt;br /&gt;
col process for a10&lt;br /&gt;
col program for a20&lt;br /&gt;
col machine for a10&lt;br /&gt;
col action for a10&lt;br /&gt;
col module for a10&lt;br /&gt;
col identifier for a10&lt;br /&gt;
col event for a27&lt;br /&gt;
col state for a8&lt;br /&gt;
col service_name for a10&lt;br /&gt;
col serial# for 999999&lt;br /&gt;
&lt;br /&gt;
select a.username&lt;br /&gt;
,      a.command&lt;br /&gt;
,      a.lockwait&lt;br /&gt;
,      a.status&lt;br /&gt;
,      a.schemaname&lt;br /&gt;
,      a.osuser&lt;br /&gt;
,      a.process&lt;br /&gt;
,      a.machine&lt;br /&gt;
,      a.program&lt;br /&gt;
,      a.type&lt;br /&gt;
--,      a.sql_exec_start&lt;br /&gt;
--,      a.plsql_object_id&lt;br /&gt;
--,      a.plsql_subprogram_id&lt;br /&gt;
--,      a.module&lt;br /&gt;
--,      a.action&lt;br /&gt;
,      a.logon_time&lt;br /&gt;
,      a.event&lt;br /&gt;
,      a.wait_time&lt;br /&gt;
,      a.seconds_in_wait&lt;br /&gt;
,      a.state&lt;br /&gt;
--,      a.service_name&lt;br /&gt;
,      a.serial#&lt;br /&gt;
,      b.sql_text&lt;br /&gt;
from   v$session a&lt;br /&gt;
,      v$sqlarea b&lt;br /&gt;
where  a.sql_address = b.address&lt;br /&gt;
order  by a.logon_time desc&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
set lines 80&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===A logminer session===&lt;br /&gt;
Mine all SQL statements in a 10 minute period&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sqlplus / as sysdba&lt;br /&gt;
alter session set nls_date_format = &amp;#039;DD-MON-YYYY HH24:MI:SS&amp;#039;;&lt;br /&gt;
execute dbms_logmnr.start_logmnr ( starttime =&amp;gt; &amp;#039;27-OCT-2009 11:05:00&amp;#039;&lt;br /&gt;
                                 , endtime   =&amp;gt; &amp;#039;27-OCT-2009 11:15:00&amp;#039;&lt;br /&gt;
                                 , options   =&amp;gt; dbms_logmnr.dict_from_online_catalog+dbms_logmnr.continuous_mine&lt;br /&gt;
                                 );&lt;br /&gt;
create table mycontents as select * from v$logmnr_contents;&lt;br /&gt;
execute dbms_logmnr.end_logmnr(); &lt;br /&gt;
&lt;br /&gt;
select * from mycontents;&lt;br /&gt;
&lt;br /&gt;
drop table mycontents;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Huge Pages===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
#&lt;br /&gt;
# hugepages_settings.sh&lt;br /&gt;
#&lt;br /&gt;
# Linux bash script to compute values for the&lt;br /&gt;
# recommended HugePages/HugeTLB configuration&lt;br /&gt;
#&lt;br /&gt;
# Note: This script does calculation for all shared memory&lt;br /&gt;
# segments available when the script is run, no matter it&lt;br /&gt;
# is an Oracle RDBMS shared memory segment or not.&lt;br /&gt;
# Check for the kernel version&lt;br /&gt;
KERN=`uname -r | awk -F. &amp;#039;{ printf(&amp;quot;%d.%d\n&amp;quot;,$1,$2); }&amp;#039;`&lt;br /&gt;
# Find out the HugePage size&lt;br /&gt;
HPG_SZ=`grep Hugepagesize /proc/meminfo | awk {&amp;#039;print $2&amp;#039;}`&lt;br /&gt;
# Start from 1 pages to be on the safe side and guarantee 1 free HugePage&lt;br /&gt;
NUM_PG=1&lt;br /&gt;
# Cumulative number of pages required to handle the running shared memory segments&lt;br /&gt;
for SEG_BYTES in `ipcs -m | awk {&amp;#039;print $5&amp;#039;} | grep &amp;quot;[0-9][0-9]*&amp;quot;`&lt;br /&gt;
do&lt;br /&gt;
   MIN_PG=`echo &amp;quot;$SEG_BYTES/($HPG_SZ*1024)&amp;quot; | bc -q`&lt;br /&gt;
   if [ $MIN_PG -gt 0 ]; then&lt;br /&gt;
      NUM_PG=`echo &amp;quot;$NUM_PG+$MIN_PG+1&amp;quot; | bc -q`&lt;br /&gt;
   fi&lt;br /&gt;
done&lt;br /&gt;
# Finish with results&lt;br /&gt;
case $KERN in&lt;br /&gt;
   &amp;#039;2.4&amp;#039;) HUGETLB_POOL=`echo &amp;quot;$NUM_PG*$HPG_SZ/1024&amp;quot; | bc -q`;&lt;br /&gt;
          echo &amp;quot;Recommended setting: vm.hugetlb_pool = $HUGETLB_POOL&amp;quot; ;;&lt;br /&gt;
   &amp;#039;2.6&amp;#039; | &amp;#039;3.8&amp;#039;) echo &amp;quot;Recommended setting: vm.nr_hugepages = $NUM_PG&amp;quot; ;;&lt;br /&gt;
    *) echo &amp;quot;Unrecognized kernel version $KERN. Exiting.&amp;quot; ;;&lt;br /&gt;
esac&lt;br /&gt;
# End&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Pretty longops listing===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 2000 pages 1000&lt;br /&gt;
col opname for a34 head &amp;quot;Job&amp;quot;&lt;br /&gt;
col message for a60&lt;br /&gt;
col perc_done for a10 head &amp;quot;Done&amp;quot;&lt;br /&gt;
col started for a18&lt;br /&gt;
col killer for a15&lt;br /&gt;
col mins_busy head &amp;quot;Mins busy&amp;quot;&lt;br /&gt;
col mins_left head &amp;quot;Mins left&amp;quot;&lt;br /&gt;
select sid||&amp;#039;,&amp;#039;||serial#                       killer&lt;br /&gt;
,      opname&lt;br /&gt;
,      message&lt;br /&gt;
,      round ((sofar/totalwork),4)*100||&amp;#039;%&amp;#039;    perc_done&lt;br /&gt;
,      to_char(start_time,&amp;#039;DD-MON-YY HH24:MI&amp;#039;) started&lt;br /&gt;
,      floor(elapsed_seconds/60)               mins_busy&lt;br /&gt;
,      ceil(time_remaining/60)                 mins_left&lt;br /&gt;
from   v$session_longops&lt;br /&gt;
where  1=1&lt;br /&gt;
and    sofar     != totalwork&lt;br /&gt;
and    totalwork != 0&lt;br /&gt;
and    opname    like &amp;#039;RMAN%&amp;#039;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select * from v$session where module=&amp;#039;Data Pump Worker&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or attach to the impdp job and it shows percentage done.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Get the SID from v$session_longops and plug it into v$session to check the SQL command details.&lt;br /&gt;
&lt;br /&gt;
Current Running SQLs&lt;br /&gt;
--------------------&lt;br /&gt;
set pages 1000 lines 2000&lt;br /&gt;
col program  format a40&lt;br /&gt;
col sql_text format a130&lt;br /&gt;
&lt;br /&gt;
select s.sid&lt;br /&gt;
,      s.status&lt;br /&gt;
,      s.last_call_et&lt;br /&gt;
,      s.program&lt;br /&gt;
,      sa.sql_id&lt;br /&gt;
,      sa.sql_text&lt;br /&gt;
from   v$session s&lt;br /&gt;
,      v$sqlarea sa&lt;br /&gt;
where  s.sql_id = sa.sql_id&lt;br /&gt;
and    s.sid = &amp;#039;&amp;amp;sid&amp;#039;&lt;br /&gt;
/ &lt;br /&gt;
&lt;br /&gt;
set pages 1000 lines 2000&lt;br /&gt;
col USERNAME for a10&lt;br /&gt;
col OSUSER   for a10&lt;br /&gt;
col MACHINE  for a10&lt;br /&gt;
&lt;br /&gt;
select s.sid&lt;br /&gt;
,      s.serial#&lt;br /&gt;
,      p.spid&lt;br /&gt;
,      s.username&lt;br /&gt;
,      s.osuser&lt;br /&gt;
,      s.status&lt;br /&gt;
,      s.process fg_pid&lt;br /&gt;
,      s.longon_time&lt;br /&gt;
,      s.machine&lt;br /&gt;
,      p.spid bg_pid&lt;br /&gt;
from   gv$session s&lt;br /&gt;
,      gv$process p&lt;br /&gt;
where  s.addr = p.addr&lt;br /&gt;
and    s.sid  = &amp;#039;&amp;amp;sid&amp;#039;&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
$ps -ef | grep &amp;lt;spid&amp;gt;&lt;br /&gt;
&lt;br /&gt;
set pages 1000 lines 2000&lt;br /&gt;
SELECT INST_ID&lt;br /&gt;
,      SID&lt;br /&gt;
,      SERIAL#&lt;br /&gt;
,      SQL_ID&lt;br /&gt;
,      USERNAME&lt;br /&gt;
,      PROGRAM&lt;br /&gt;
,      MACHINE&lt;br /&gt;
,      SERVICE_NAME&lt;br /&gt;
FROM   GV$SESSION&lt;br /&gt;
WHERE  SID IN (&amp;#039;&amp;lt;SID_NO.1&amp;gt;&amp;#039;,&amp;#039;&amp;lt;SID_NO.2&amp;gt;&amp;#039;)&lt;br /&gt;
/&lt;br /&gt;
Active Running SQLs&lt;br /&gt;
--------------------&lt;br /&gt;
set pages 1000 lines 2000&lt;br /&gt;
col SPID     for a10&lt;br /&gt;
col PROGRAM  for a15&lt;br /&gt;
col OSUSER   for a10&lt;br /&gt;
col ACTION   for a10&lt;br /&gt;
col EVENT    for a25&lt;br /&gt;
col SQL_TEXT for a25&lt;br /&gt;
col MACHINE  for a10&lt;br /&gt;
col P1TEXT   for a10 &lt;br /&gt;
col P2TEXT   for a10&lt;br /&gt;
col P3TEXT   for a10  &lt;br /&gt;
SELECT b.sid&lt;br /&gt;
,      b.serial#&lt;br /&gt;
,      a.spid&lt;br /&gt;
,      b.sql_id&lt;br /&gt;
,      b.program&lt;br /&gt;
,      b.osuser&lt;br /&gt;
,      b.machine&lt;br /&gt;
,      b.type&lt;br /&gt;
,      b.event&lt;br /&gt;
,      b.action&lt;br /&gt;
,      b.p1text&lt;br /&gt;
,      b.p2text&lt;br /&gt;
,      b.p3text&lt;br /&gt;
,      b.state&lt;br /&gt;
,      c.sql_text&lt;br /&gt;
,      b.logon_time&lt;br /&gt;
FROM   v$process a&lt;br /&gt;
,      v$session b&lt;br /&gt;
,      v$sqltext c&lt;br /&gt;
WHERE  a.addr           = b.paddr&lt;br /&gt;
AND    b.sql_hash_value = c.hash_value&lt;br /&gt;
AND    b.STATUS         = &amp;#039;ACTIVE&amp;#039;&lt;br /&gt;
AND    b.sid            = &amp;#039;&amp;amp;sid&amp;#039;&lt;br /&gt;
ORDER  BY a.spid&lt;br /&gt;
,      c.piece&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
OR - Use the below Query &lt;br /&gt;
&lt;br /&gt;
Longops.sql&lt;br /&gt;
----------- &lt;br /&gt;
set pages 50000 lines 32767&lt;br /&gt;
col OPNAME for a10&lt;br /&gt;
col SID form 9999&lt;br /&gt;
col SERIAL form 9999999&lt;br /&gt;
col PROGRAM for a10&lt;br /&gt;
col USERNAME for a10&lt;br /&gt;
col SQL_TEXT for a40&lt;br /&gt;
col START_TIME for a10&lt;br /&gt;
col LAST_UPDATE_TIME for a10&lt;br /&gt;
col TARGET for a25&lt;br /&gt;
col MESSAGE for a25&lt;br /&gt;
&lt;br /&gt;
alter session set nls_date_format = &amp;#039;DD-MM-YYYY HH24:MI:SS&amp;#039;;&lt;br /&gt;
&lt;br /&gt;
SELECT l.inst_id,l.sid, l.serial#, l.sql_id, l.opname, l.username, l.target, l.sofar, l.totalwork, l.start_time,l.last_update_time,round(l.time_remaining/60,2) &amp;quot;REMAIN MINS&amp;quot;, round(l.elapsed_seconds/60,2) &amp;quot;ELAPSED MINS&amp;quot;, round((l.time_remaining+l.elapsed_seconds)/60,2) &amp;quot;TOTAL MINS&amp;quot;, ROUND(l.SOFAR/l.TOTALWORK*100,2) &amp;quot;%_COMPLETE&amp;quot;, l.message,s.sql_text &lt;br /&gt;
FROM gv$session_longops l &lt;br /&gt;
LEFT OUTER JOIN v$sql s on s.hash_value=l.sql_hash_value and s.address=l.sql_address and s.child_number=0&lt;br /&gt;
WHERE l.OPNAME NOT LIKE &amp;#039;RMAN%&amp;#039; AND l.OPNAME NOT LIKE &amp;#039;%aggregate%&amp;#039; AND l.TOTALWORK != 0 AND l.sofar&amp;lt;&amp;gt;l.totalwork AND l.time_remaining &amp;gt; 0&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Apply the database patch after the ORACLE_HOME has been patched===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ORAENV_ASK=NO&lt;br /&gt;
export ORACLE_SID=$1&lt;br /&gt;
. oraenv&lt;br /&gt;
&lt;br /&gt;
sqlplus /nolog &amp;lt;&amp;lt;EOSQL&lt;br /&gt;
connect / as sysdba&lt;br /&gt;
startup&lt;br /&gt;
@?/rdbms/admin/catbundle.sql psu apply&lt;br /&gt;
@?/rdbms/admin/utlrp.sql&lt;br /&gt;
purge dba_recyclebin;&lt;br /&gt;
&lt;br /&gt;
prompt check patch apply...&lt;br /&gt;
set lines 150&lt;br /&gt;
col action_time for a50&lt;br /&gt;
col comp_name for a50&lt;br /&gt;
col comments for a50&lt;br /&gt;
&lt;br /&gt;
select action_time,action,comments from sys.registry\$history where trunc(action_time) = trunc(sysdate);&lt;br /&gt;
select comp_name,version,status,modified from dba_registry;&lt;br /&gt;
exit&lt;br /&gt;
EOSQL&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Show how much archivelog data is generated per day===&lt;br /&gt;
A companion script for &amp;#039;how many log switches in a day&amp;#039;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
col orderby noprint&lt;br /&gt;
select trunc(first_time) orderby&lt;br /&gt;
,      to_char(first_time,&amp;#039;DD-MON-YYYY&amp;#039;) &amp;quot;Date&amp;quot;&lt;br /&gt;
,      round(sum(bytes/1024/1024/1024),2) arch_logs_gigs&lt;br /&gt;
from (&lt;br /&gt;
    select unique (blocks * block_size) bytes,&lt;br /&gt;
    thread#,&lt;br /&gt;
    sequence#,&lt;br /&gt;
    resetlogs_change#,&lt;br /&gt;
    first_time&lt;br /&gt;
    from v$archived_log&lt;br /&gt;
)&lt;br /&gt;
group by trunc(first_time)&lt;br /&gt;
,      to_char(first_time, &amp;#039;DD-MON-YYYY&amp;#039;)&lt;br /&gt;
order by trunc(first_time) desc&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Abort a hanging database even when sysdba cannot connect===&lt;br /&gt;
Unable to connect to database with sqlplus / as sysdba because audit file cannot be created?&lt;br /&gt;
* [http://tech.e2sn.com/oracle/troubleshooting/hang/how-to-log-on-even-when-sysdba-can-t-do-so tech.e2sn.com]&lt;br /&gt;
* [http://blog.dbi-services.com/oracle-is-hanging-dont-forget-hanganalyze-and-systemstate/ blog.dbi-services.com]&lt;br /&gt;
Instead of just killing the pmon process, there is a kinder (and more useful) way to kill the database.&amp;lt;br /&amp;gt;&lt;br /&gt;
Use the hidden, undocumented &amp;#039;prelim&amp;#039; switch parameter to sqlplus to make a connection to the database without creating SGA session data structures.&amp;lt;br /&amp;gt;&lt;br /&gt;
It can be very useful for hang analysis so the possible cause can be found after the database has been restarted.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sqlplus -prelim / as sysdba&lt;br /&gt;
oradebug unlimit&lt;br /&gt;
oradebug hanganalyze 3&lt;br /&gt;
oradebug setmypid              -- or oradebug setorapname diag&lt;br /&gt;
oradebug dump ashdumpseconds 30&lt;br /&gt;
oradebug dump systemstate 10   -- or oradebug dump systemstate 266&lt;br /&gt;
oradebug tracefile_name&lt;br /&gt;
shutdown abort&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Lists Oracle session with kill session statement all ready to go===&lt;br /&gt;
disconnect attempts to kill the o/s processes too. kill doesn&amp;#039;t.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
col killer for a60&lt;br /&gt;
col osuser for a12&lt;br /&gt;
col logon  for a23&lt;br /&gt;
col spid   for a8&lt;br /&gt;
col username for a15&lt;br /&gt;
col program for a50&lt;br /&gt;
set lines 2000&lt;br /&gt;
select &amp;#039;alter system disconnect session &amp;#039;&amp;#039;&amp;#039;||s.sid||&amp;#039;,&amp;#039;||s.serial#||&amp;#039;&amp;#039;&amp;#039; immediate;&amp;#039; killer&lt;br /&gt;
,      s.inst_id&lt;br /&gt;
,      to_char(s.logon_time,&amp;#039;DD-MON-YY HH24:MI:SS&amp;#039;) logon&lt;br /&gt;
,      sci.osuser&lt;br /&gt;
,      p.spid&lt;br /&gt;
,      s.username&lt;br /&gt;
,      s.program&lt;br /&gt;
from   gv$session s&lt;br /&gt;
,      gv$session_connect_info sci&lt;br /&gt;
,      gv$process p&lt;br /&gt;
where  1=1&lt;br /&gt;
and    p.addr     = s.paddr&lt;br /&gt;
and    p.inst_id  = s.inst_id&lt;br /&gt;
and    s.sid      = sci.sid&lt;br /&gt;
and    s.serial#  = sci.serial#&lt;br /&gt;
and    s.type    != &amp;#039;BACKGROUND&amp;#039;&lt;br /&gt;
and    sci.osuser = &amp;#039;oraibm&amp;#039;&lt;br /&gt;
order  by s.logon_time desc&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
KILLER                                                          INST_ID LOGON                   OSUSER       SPID     USERNAME        PROGRAM&lt;br /&gt;
------------------------------------------------------------ ---------- ----------------------- ------------ -------- --------------- --------------------------------------------------&lt;br /&gt;
alter system disconnect session &amp;#039;490,33947&amp;#039; immediate;                1 23-JUN-16 13:30:53      oraibm       23205    SYS             sqlplus@benouerp07 (TNS V1-V3)&lt;br /&gt;
alter system disconnect session &amp;#039;490,33947&amp;#039; immediate;                1 23-JUN-16 13:30:53      oraibm       23205    SYS             sqlplus@benouerp07 (TNS V1-V3)&lt;br /&gt;
alter system disconnect session &amp;#039;490,33947&amp;#039; immediate;                1 23-JUN-16 13:30:53      oraibm       23205    SYS             sqlplus@benouerp07 (TNS V1-V3)&lt;br /&gt;
alter system disconnect session &amp;#039;490,33947&amp;#039; immediate;                1 23-JUN-16 13:30:53      oraibm       23205    SYS             sqlplus@benouerp07 (TNS V1-V3)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===How much space is being used by a guaranteed restore point?===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
show parameter recovery&lt;br /&gt;
set numwi 15&lt;br /&gt;
set lines 200&lt;br /&gt;
col name for a40&lt;br /&gt;
col time for a23&lt;br /&gt;
col gigs_limit head &amp;quot;Max (but check df -g also!)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
select name&lt;br /&gt;
,      time&lt;br /&gt;
,      round(storage_size/1024/1024/1024,2) gigs_used&lt;br /&gt;
from   v$restore_point&lt;br /&gt;
where  1=1&lt;br /&gt;
and    guarantee_flashback_database = &amp;#039;YES&amp;#039;&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
select * from v$flash_recovery_area_usage&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
select name&lt;br /&gt;
,      round(space_used/1024/1024/1024,2) gigs_used&lt;br /&gt;
,      round(space_limit/1024/1024/1024,2) gigs_limit&lt;br /&gt;
,      space_reclaimable&lt;br /&gt;
,      number_of_files&lt;br /&gt;
from v$recovery_file_dest&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Get statistics for LOB columns in a table===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select &lt;br /&gt;
  max(dbms_lob.getlength(lob_content)) max_len&lt;br /&gt;
, avg(dbms_lob.getlength(lob_content)) avg_len&lt;br /&gt;
, min(dbms_lob.getlength(lob_content)) min_len&lt;br /&gt;
, sum(case when dbms_lob.getlength(lob_content) &amp;lt;= 4000 then 1&lt;br /&gt;
else 0 end) &amp;quot;&amp;lt;4k&amp;quot;&lt;br /&gt;
, sum(case when dbms_lob.getlength(lob_content) &amp;gt; 4000 then 1&lt;br /&gt;
else 0 end) &amp;quot;&amp;gt;4k&amp;quot;&lt;br /&gt;
, sum(case when dbms_lob.getlength(lob_content) is null then 1 else&lt;br /&gt;
0 end) &amp;quot;is null&amp;quot;&lt;br /&gt;
from &amp;amp;tablename&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===badprivs.sql===&lt;br /&gt;
Check to see if any ordinary users have privileges / access / grants / rights they should not have&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select grantee, privilege, admin_option&lt;br /&gt;
from   sys.dba_sys_privs&lt;br /&gt;
where  (       privilege like &amp;#039;% ANY %&amp;#039;&lt;br /&gt;
        or     privilege in (&amp;#039;BECOME USER&amp;#039;, &amp;#039;UNLIMITED TABLESPACE&amp;#039;)&lt;br /&gt;
        or     admin_option = &amp;#039;YES&amp;#039;&lt;br /&gt;
       )&lt;br /&gt;
and    grantee not in (&amp;#039;SYS&amp;#039;, &amp;#039;SYSTEM&amp;#039;, &amp;#039;OUTLN&amp;#039;, &amp;#039;AQ_ADMINISTRATOR_ROLE&amp;#039;,&lt;br /&gt;
                      &amp;#039;DBA&amp;#039;, &amp;#039;EXP_FULL_DATABASE&amp;#039;, &amp;#039;IMP_FULL_DATABASE&amp;#039;,&lt;br /&gt;
                      &amp;#039;OEM_MONITOR&amp;#039;, &amp;#039;CTXSYS&amp;#039;, &amp;#039;DBSNMP&amp;#039;, &amp;#039;IFSSYS&amp;#039;,&lt;br /&gt;
                      &amp;#039;IFSSYS$CM&amp;#039;, &amp;#039;MDSYS&amp;#039;, &amp;#039;ORDPLUGINS&amp;#039;, &amp;#039;ORDSYS&amp;#039;,&lt;br /&gt;
                      &amp;#039;TIMESERIES_DBA&amp;#039;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Generate a list of tablespaces ready for a migration===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set echo off&lt;br /&gt;
set lines 300&lt;br /&gt;
set pages 0&lt;br /&gt;
Set headi off&lt;br /&gt;
set feedb off&lt;br /&gt;
set long 32000&lt;br /&gt;
&lt;br /&gt;
spool migration_create_target_tablespaces.sql&lt;br /&gt;
&lt;br /&gt;
exec dbms_metadata.set_transform_param(dbms_metadata.session_transform,&amp;#039;SQLTERMINATOR&amp;#039;,TRUE);&lt;br /&gt;
select DBMS_METADATA.GET_DDL(&amp;#039;TABLESPACE&amp;#039;,tablespace_name) from dba_tablespaces&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
spool off&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===List the privileges assigned to users on directories===&lt;br /&gt;
table_name is the name of the directory...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select grantor&lt;br /&gt;
,      grantee&lt;br /&gt;
,      table_schema&lt;br /&gt;
,      table_name&lt;br /&gt;
,      privilege&lt;br /&gt;
from   all_tab_privs&lt;br /&gt;
where  table_name = &amp;#039;DATA_PUMP_DIR&amp;#039;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===List the privileges assigned to users on packages/procedures===&lt;br /&gt;
table_name is the name of the package...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select grantor&lt;br /&gt;
,      grantee&lt;br /&gt;
,      table_schema&lt;br /&gt;
,      table_name&lt;br /&gt;
,      privilege&lt;br /&gt;
from   all_tab_privs&lt;br /&gt;
where  upper(table_name) like upper(&amp;#039;%UTL_FILE%&amp;#039;)&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===List the system privileges assigned to a user (used to copy user as or clone user as)===&lt;br /&gt;
Maybe this one is better [[Extract ddl with &amp;quot;dbms metadata.get ddl&amp;quot;]]&lt;br /&gt;
&lt;br /&gt;
 SELECT LPAD(&amp;#039; &amp;#039;, 2*level) || granted_role &amp;quot;USER PRIVS&amp;quot;&lt;br /&gt;
 FROM (&lt;br /&gt;
   SELECT NULL grantee,  username granted_role&lt;br /&gt;
   FROM dba_users&lt;br /&gt;
   WHERE username LIKE UPPER(&amp;#039;%&amp;amp;uname%&amp;#039;)&lt;br /&gt;
   UNION&lt;br /&gt;
   SELECT grantee, granted_role&lt;br /&gt;
   FROM dba_role_privs&lt;br /&gt;
   UNION&lt;br /&gt;
   SELECT grantee, privilege&lt;br /&gt;
   FROM dba_sys_privs)&lt;br /&gt;
 START WITH grantee IS NULL&lt;br /&gt;
 CONNECT BY grantee = prior granted_role;&lt;br /&gt;
&lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
 SELECT path&lt;br /&gt;
 FROM (&lt;br /&gt;
   SELECT grantee,&lt;br /&gt;
          sys_connect_by_path(privilege, &amp;#039;:&amp;#039;)||&amp;#039;:&amp;#039;||grantee path&lt;br /&gt;
   FROM (&lt;br /&gt;
     SELECT grantee, privilege, 0 role&lt;br /&gt;
     FROM dba_sys_privs&lt;br /&gt;
     UNION ALL&lt;br /&gt;
     SELECT grantee, granted_role, 1 role&lt;br /&gt;
     FROM dba_role_privs)&lt;br /&gt;
   CONNECT BY privilege=prior grantee&lt;br /&gt;
   START WITH role = 0)&lt;br /&gt;
 WHERE grantee IN (&lt;br /&gt;
    SELECT username&lt;br /&gt;
    FROM dba_users&lt;br /&gt;
    WHERE lock_date IS NULL&lt;br /&gt;
    AND password != &amp;#039;EXTERNAL&amp;#039;&lt;br /&gt;
    AND username != &amp;#039;SYS&amp;#039;)&lt;br /&gt;
 OR grantee=&amp;#039;PUBLIC&amp;#039;&lt;br /&gt;
&lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
for a migration from 10g...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set headi off&lt;br /&gt;
set feedb off&lt;br /&gt;
set long  9999999&lt;br /&gt;
set pages 0&lt;br /&gt;
set lines 300&lt;br /&gt;
&lt;br /&gt;
spool migration_create_target_users_grants.sql&lt;br /&gt;
&lt;br /&gt;
select dbms_metadata.get_ddl(&amp;#039;USER&amp;#039;, username) || &amp;#039;;&amp;#039; ddl&lt;br /&gt;
from dba_users&lt;br /&gt;
where  1=1&lt;br /&gt;
and    username like upper(&amp;#039;%&amp;amp;&amp;amp;USER_NAME%&amp;#039;)&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
select &amp;#039;grant &amp;#039;||privilege|| &amp;#039; to &amp;#039; || grantee || &amp;#039;;&amp;#039;&lt;br /&gt;
from   dba_sys_privs&lt;br /&gt;
where  1=1&lt;br /&gt;
and    grantee like upper(&amp;#039;%&amp;amp;&amp;amp;USER_NAME%&amp;#039;)&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
select &amp;#039;grant &amp;#039;||granted_role|| &amp;#039; to &amp;#039; || grantee || &amp;#039;;&amp;#039;&lt;br /&gt;
from   dba_role_privs&lt;br /&gt;
where  1=1&lt;br /&gt;
and    grantee like upper(&amp;#039;%&amp;amp;&amp;amp;USER_NAME%&amp;#039;)&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
spool off&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or for a migration on 11g...!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set head off&lt;br /&gt;
set pages 0&lt;br /&gt;
set long 9999999&lt;br /&gt;
col ddl for a1000&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
SELECT DBMS_METADATA.GET_DDL(&amp;#039;USER&amp;#039;, USERNAME) || &amp;#039;;&amp;#039; DDL&lt;br /&gt;
FROM DBA_USERS&lt;br /&gt;
where  1=1&lt;br /&gt;
and    default_tablespace not in (&amp;#039;SYSTEM&amp;#039;,&amp;#039;SYSAUX&amp;#039;)&lt;br /&gt;
and    upper(username) like &amp;#039;%&amp;#039;||upper(&amp;#039;&amp;amp;&amp;amp;username&amp;#039;)||&amp;#039;%&amp;#039;&lt;br /&gt;
UNION ALL&lt;br /&gt;
SELECT DBMS_METADATA.GET_GRANTED_DDL(&amp;#039;ROLE_GRANT&amp;#039;, USERNAME) || &amp;#039;;&amp;#039; DDL&lt;br /&gt;
FROM DBA_USERS&lt;br /&gt;
where  1=1&lt;br /&gt;
and    default_tablespace not in (&amp;#039;SYSTEM&amp;#039;,&amp;#039;SYSAUX&amp;#039;)&lt;br /&gt;
and    upper(username) like &amp;#039;%&amp;#039;||upper(&amp;#039;&amp;amp;&amp;amp;username&amp;#039;)||&amp;#039;%&amp;#039;&lt;br /&gt;
UNION ALL&lt;br /&gt;
SELECT DBMS_METADATA.GET_GRANTED_DDL(&amp;#039;SYSTEM_GRANT&amp;#039;, USERNAME) || &amp;#039;;&amp;#039; DDL&lt;br /&gt;
FROM DBA_USERS&lt;br /&gt;
where  1=1&lt;br /&gt;
and    default_tablespace not in (&amp;#039;SYSTEM&amp;#039;,&amp;#039;SYSAUX&amp;#039;)&lt;br /&gt;
and    upper(username) like &amp;#039;%&amp;#039;||upper(&amp;#039;&amp;amp;&amp;amp;username&amp;#039;)||&amp;#039;%&amp;#039;&lt;br /&gt;
UNION ALL&lt;br /&gt;
SELECT DBMS_METADATA.GET_GRANTED_DDL(&amp;#039;OBJECT_GRANT&amp;#039;, USERNAME) || &amp;#039;;&amp;#039; DDL&lt;br /&gt;
FROM DBA_USERS&lt;br /&gt;
where  1=1&lt;br /&gt;
and    default_tablespace not in (&amp;#039;SYSTEM&amp;#039;,&amp;#039;SYSAUX&amp;#039;)&lt;br /&gt;
and    upper(username) like &amp;#039;%&amp;#039;||upper(&amp;#039;&amp;amp;&amp;amp;username&amp;#039;)||&amp;#039;%&amp;#039;&lt;br /&gt;
&lt;br /&gt;
spool migration_create_users_grants.sql&lt;br /&gt;
/&lt;br /&gt;
spool off&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Move datafiles between filesystems===&lt;br /&gt;
* [https://blogs.oracle.com/alejandrovargas/moving-a-datafile-from-file-system-to-asm Moving a datafile from File System to ASM (does not have to be ASM!) - oracle.com]&lt;br /&gt;
* [https://docs.oracle.com/database/121/OSTMG/GUID-3B8D0956-0888-452D-A9E4-9FB8D98577E0.htm#OSTMG89997 Moving Data Files Between Oracle ASM (does not have to be ASM!) Using RMAN - oracle.com]&lt;br /&gt;
* [https://oracle-base.com/articles/misc/renaming-or-moving-oracle-files Moving a data file online between filesystems - oracle-base.com]&lt;br /&gt;
====Set the relevant datafile offline====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter database datafile 125 offline;&lt;br /&gt;
alter database datafile 126 offline;&lt;br /&gt;
alter database datafile 127 offline;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Rename the files on the filesystem using o/s commands====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter tablespace ts_thaler_data_offline;&lt;br /&gt;
&lt;br /&gt;
host mv &amp;#039;/cln/tst/ora_data1/clnt/data4/ts_thaler_data_113.dbf&amp;#039; &amp;#039;/cln/tst/ora_data1/clnt/data1/ts_thaler_data_113.dbf&amp;#039;&lt;br /&gt;
host mv &amp;#039;/cln/tst/ora_data1/clnt/data4/ts_thaler_data_114.dbf&amp;#039; &amp;#039;/cln/tst/ora_data1/clnt/data1/ts_thaler_data_114.dbf&amp;#039;&lt;br /&gt;
host mv &amp;#039;/cln/tst/ora_data1/clnt/data4/ts_thaler_data_115.dbf&amp;#039; &amp;#039;/cln/tst/ora_data1/clnt/data1/ts_thaler_data_115.dbf&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Run the relevant alter commands to inform the control files of the new locations====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter database move datafile &amp;#039;/cln/tst/ora_data1/clnt/data4/ts_thaler_data_113.dbf&amp;#039; to &amp;#039;/cln/tst/ora_data1/clnt/data1/ts_thaler_data_113.dbf&amp;#039;&lt;br /&gt;
alter database move datafile &amp;#039;/cln/tst/ora_data1/clnt/data4/ts_thaler_data_114.dbf&amp;#039; to &amp;#039;/cln/tst/ora_data1/clnt/data1/ts_thaler_data_114.dbf&amp;#039;&lt;br /&gt;
alter database move datafile &amp;#039;/cln/tst/ora_data1/clnt/data4/ts_thaler_data_115.dbf&amp;#039; to &amp;#039;/cln/tst/ora_data1/clnt/data1/ts_thaler_data_115.dbf&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Recover the datafiles====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
recover datafile 125;&lt;br /&gt;
recover datafile 126;&lt;br /&gt;
recover datafile 127;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Set the relevant datafile online====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter database datafile 125 online;&lt;br /&gt;
alter database datafile 126 online;&lt;br /&gt;
alter database datafile 127 online;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Check all is well with the datafiles by using an appropriate statement====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 2000 pages 100&lt;br /&gt;
select file_id, file_name, status, online_status from dba_data_files where tablespace_name = &amp;#039;TS_THALER_DATA&amp;#039; order by 2;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Rename a datafile on 12c====&lt;br /&gt;
If you&amp;#039;re lucky enough to be on 12c, it&amp;#039;s one command - no need to offline the datafile!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SQL&amp;gt; alter database move datafile &amp;#039;/oracle/ora_data2/prod/data4/ts_thaler_data_113.dbf&amp;#039; to &amp;#039;/oracle/ora_data2/prod/data3/ts_thaler_data_113.dbf&amp;#039;;&lt;br /&gt;
&lt;br /&gt;
Database altered.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Pass parameter/argument into perl one-liner script from shell===&lt;br /&gt;
Trick? Just use ARGV to pass them in...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
FREQ=$(perl -e &amp;#039;my @CAL=split(&amp;quot;;&amp;quot;,$ARGV[0]);shift @CAL;print $CAL[$ARGV[1]];&amp;#039; -- &amp;quot;$LINE&amp;quot; $offset)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
DUMP_DATE=`perl -MTime::Local -e &amp;#039;print(timelocal(0,$ARGV[0],$ARGV[1],$ARGV[2],$ARGV[3],$ARGV[4]))&amp;#039; -- $MI $HH $DD $MM $YYYY`&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or export the variable from shell and access it via the ENV hash&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
export db=ENDP1&lt;br /&gt;
perl -p -i -e &amp;#039;s!DSMI_LOG.+$!DSMI_LOG           /oracle/$ENV{db}/admin/tdpoerror_$ENV{db}!&amp;#039; ${db}/admin/tdpo.opt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Return epoch seconds in Perl===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
perl -e &amp;#039;print time();&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or to convert a specific day of the year to epoch seconds&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
use POSIX;&lt;br /&gt;
my $epochsecs = mktime(0,0,0, $jday, 0, $year-1900);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or for a specific date (careful though - month is 0-11 not 1-12!...&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
use Time::Local;&lt;br /&gt;
#                          SS MM HH DD MM YYYY&lt;br /&gt;
my $epochsecs = timelocal (30,10,19,03,04,2014);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or more long-winded but delimited by anything...&amp;lt;br /&amp;gt;&lt;br /&gt;
Supply the date/time in any delimited format. Eg. YYYY-MM-DD:HH:MI&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/usr/bin/perl -w&lt;br /&gt;
use Time::Local;&lt;br /&gt;
&lt;br /&gt;
sub date2epoch { &lt;br /&gt;
  my($s) = @_;&lt;br /&gt;
  my($year, $month, $day, $hour, $minute, $second);&lt;br /&gt;
&lt;br /&gt;
  if($s =~ m{^\s*(\d{1,4})\W*0*(\d{1,2})\W*0*(\d{1,2})\W*0*&lt;br /&gt;
                 (\d{0,2})\W*0*(\d{0,2})\W*0*(\d{0,2})}x) {&lt;br /&gt;
    $year = $1;  $month = $2;   $day = $3;&lt;br /&gt;
    $hour = $4;  $minute = $5;  $second = $6;&lt;br /&gt;
    $hour |= 0;  $minute |= 0;  $second |= 0;  # defaults.&lt;br /&gt;
    $year = ($year&amp;lt;100 ? ($year&amp;lt;70 ? 2000+$year : 1900+$year) : $year);&lt;br /&gt;
    return timelocal($second,$minute,$hour,$day,$month-1,$year);  &lt;br /&gt;
  }&lt;br /&gt;
  return -1;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Return epoch seconds in DOS/VBS/Windows===&lt;br /&gt;
Paste this code into epoch.vbs&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
function date2epoch(p_date)&lt;br /&gt;
    date2epoch = DateDiff(&amp;quot;s&amp;quot;, &amp;quot;01/01/1970 00:00:00&amp;quot;, p_date)&lt;br /&gt;
end function&lt;br /&gt;
&lt;br /&gt;
Wscript.Echo date2epoch(Now())&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
and call from a DOS box like this&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cscript //nologo epoch.vbs&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Return date from epoch seconds in Perl===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
perl -e &amp;#039;print scalar (localtime (1243269270))&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Return epoch seconds from julian day number in Perl===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
use POSIX;&lt;br /&gt;
my ($year, $jday) = (2012,60);&lt;br /&gt;
my $epochsecs = mktime(0,0,0, $jday, 0, $year-1900);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Extract specific pieces of a date from an epoch timestamp in Perl===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
use POSIX;&lt;br /&gt;
# return localtime into an array&lt;br /&gt;
my @tm = localtime $epochsecs;&lt;br /&gt;
&lt;br /&gt;
my $yyyymmdd = strftime &amp;quot;%Y%m%d&amp;quot;, @tm;&lt;br /&gt;
print $yyyymmdd.&amp;quot;\n&amp;quot;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Return epoch seconds in Shell (linux)===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
date -d &amp;quot;2014/04/03 18:34:30&amp;quot; &amp;quot;+%s&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Return date from epoch seconds in Shell (linux)===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
date -d @1396542870&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Return epoch seconds in PL/SQL===&lt;br /&gt;
You cannot just use sysdate as that is timezone sensitive... (epoch seconds are in UTC/GMT)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select round((cast(sys_extract_utc(systimestamp) as date) - to_date(&amp;#039;01-JAN-1970 00:00:00&amp;#039;,&amp;#039;DD-MON-YYYY HH24:MI:SS&amp;#039;))*24*60*60) from dual;&lt;br /&gt;
or&lt;br /&gt;
select round((vd.created - to_date(&amp;#039;01-JAN-1970 00:00:00&amp;#039;,&amp;#039;DD-MON-YYYY HH24:MI:SS&amp;#039;))*24*60*60)  created from v$database vd;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
How long has this instance been up (in minutes)?&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select round((cast(sys_extract_utc(systimestamp) as date) - startup_time)*24*60) up_mins from v$instance;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Return date from epoch seconds in SQL===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select to_char(to_date(&amp;#039;19700101&amp;#039;,&amp;#039;YYYYMMDD&amp;#039;) + ((&amp;amp;epoch)/24/60/60),&amp;#039;DD-MON-YYYY HH24:MI:SS&amp;#039;) utc_date from dual;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===A database overview using the sys.plato package===&lt;br /&gt;
 exec plato.help;&lt;br /&gt;
or&lt;br /&gt;
 exec plato.complete(&amp;#039;HTM&amp;#039;);&lt;br /&gt;
&lt;br /&gt;
===List datafiles for a tablespace===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select *&lt;br /&gt;
from   dba_data_files&lt;br /&gt;
where  1=1&lt;br /&gt;
and    tablespace_name =&amp;#039;&amp;amp;ts_name&amp;#039;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Show graph of available and free space in tablespaces===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
-- =============================================================================&lt;br /&gt;
-- File Name    : http://www.oracle-base.com/dba/monitoring/ts_free_space.sql&lt;br /&gt;
-- Author       : Tim Hall&lt;br /&gt;
-- Description  : Displays a list of tablespaces and their used/full status.&lt;br /&gt;
-- Requirements : Access to the DBA views.&lt;br /&gt;
-- Call Syntax  : @ts_free_space.sql&lt;br /&gt;
-- Last Modified: 13-OCT-2012 - Created. Based on ts_full.sql&lt;br /&gt;
--&lt;br /&gt;
-- Modification History&lt;br /&gt;
-- ====================&lt;br /&gt;
-- When      Who               What&lt;br /&gt;
-- ========= ================= =================================================&lt;br /&gt;
-- 13-NOV-13 Stuart Barkley    Added cols free_pct and used_pct&lt;br /&gt;
-- =============================================================================&lt;br /&gt;
SET PAGESIZE 140 lines 180&lt;br /&gt;
COLUMN used_pct FORMAT A11&lt;br /&gt;
COLUMN max_used_pct FORMAT A11&lt;br /&gt;
&lt;br /&gt;
    SELECT tablespace_name                                                                      tablespace_name&lt;br /&gt;
    ,      size_mb                                                                              size_mb&lt;br /&gt;
    ,      free_mb                                                                              free_mb&lt;br /&gt;
    ,      TRUNC((free_mb/size_mb) * 100)                                                       free_pct&lt;br /&gt;
    ,      RPAD(&amp;#039; &amp;#039;|| RPAD(&amp;#039;X&amp;#039;,ROUND((size_mb-free_mb)/size_mb*10,0), &amp;#039;X&amp;#039;),11,&amp;#039;-&amp;#039;)              used_pct&lt;br /&gt;
    ,      max_size_mb                                                                          max_size_mb&lt;br /&gt;
    ,      max_free_mb                                                                          max_free_mb&lt;br /&gt;
    ,      TRUNC((max_free_mb/max_size_mb) * 100)                                               max_free_pct&lt;br /&gt;
    ,      RPAD(&amp;#039; &amp;#039;|| RPAD(&amp;#039;X&amp;#039;,ROUND((max_size_mb-max_free_mb)/max_size_mb*10,0), &amp;#039;X&amp;#039;),11,&amp;#039;-&amp;#039;)  max_used_pct&lt;br /&gt;
    from   (&lt;br /&gt;
           select a.tablespace_name                                         tablespace_name&lt;br /&gt;
           ,      b.size_mb                                                 size_mb&lt;br /&gt;
           ,      a.free_mb                                                 free_mb&lt;br /&gt;
           ,      b.max_size_mb                                             max_size_mb&lt;br /&gt;
           ,      a.free_mb + (b.max_size_mb - b.size_mb)                   max_free_mb&lt;br /&gt;
           from   (&lt;br /&gt;
                  select tablespace_name                                    tablespace_name&lt;br /&gt;
                  ,      trunc(sum(bytes)/1024/1024)                        free_mb&lt;br /&gt;
                  from   dba_free_space&lt;br /&gt;
                  group  by tablespace_name&lt;br /&gt;
                  ) a&lt;br /&gt;
           ,      (&lt;br /&gt;
                  select tablespace_name                                    tablespace_name&lt;br /&gt;
                  ,        trunc(sum(bytes)/1024/1024)                      size_mb&lt;br /&gt;
                  ,        trunc(sum(greatest(bytes,maxbytes))/1024/1024)   max_size_mb&lt;br /&gt;
                  from   dba_data_files&lt;br /&gt;
                  group by tablespace_name&lt;br /&gt;
                  ) b&lt;br /&gt;
           ,      v$instance vi&lt;br /&gt;
           where  a.tablespace_name = b.tablespace_name&lt;br /&gt;
           )&lt;br /&gt;
    order  by tablespace_name;&lt;br /&gt;
&lt;br /&gt;
set lines 80&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Another method for calculating free space in tablespace  using segments===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select df.tablespace_name &amp;quot;Tablespace&amp;quot;&lt;br /&gt;
,      totalusedspace &amp;quot;Used MB&amp;quot;&lt;br /&gt;
,      (df.totalspace - tu.totalusedspace) &amp;quot;Free MB&amp;quot;&lt;br /&gt;
,      df.totalspace &amp;quot;Total MB&amp;quot;&lt;br /&gt;
,      round(100 * ( (df.totalspace - tu.totalusedspace)/ df.totalspace)) &amp;quot;Pct. Free&amp;quot;&lt;br /&gt;
from   (&lt;br /&gt;
       select tablespace_name&lt;br /&gt;
,      round(sum(bytes) / 1048576) totalspace&lt;br /&gt;
       from   dba_data_files&lt;br /&gt;
       group  by tablespace_name&lt;br /&gt;
       ) df&lt;br /&gt;
,      (&lt;br /&gt;
       select round(sum(bytes)/(1024*1024)) totalusedspace&lt;br /&gt;
       ,      tablespace_name&lt;br /&gt;
       from   dba_segments&lt;br /&gt;
       group  by tablespace_name&lt;br /&gt;
       ) tu&lt;br /&gt;
where  df.tablespace_name = tu.tablespace_name;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Work out maximum possible size of a datafile===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select round( (4*1024*1024*value) / (1024*1024*1024) ,2) maxfilesizeingigabytes from v$parameter where name=&amp;#039;db_block_size&amp;#039;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or, as tablespaces can have block sizes differing from that of the init.ora parameter...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select round( (4*1024*1024*block_size) / (1024*1024*1024) ,2) maxfilesizeingigabytes from dba_tablespaces where tablespace_name=&amp;#039;&amp;amp;tablespace_name&amp;#039;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Show size and maxsize at datafile level===&lt;br /&gt;
datafiles&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set pages 100 lines 200&lt;br /&gt;
col file_name for a60&lt;br /&gt;
select sum(bytes)/1024/1024      mbytes_alloc&lt;br /&gt;
,      sum(maxbytes)/1024/1024   mbytes_max&lt;br /&gt;
,      file_name&lt;br /&gt;
from   sys.dba_data_files&lt;br /&gt;
group  by file_name&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
tempfiles&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set pages 100 lines 200&lt;br /&gt;
col file_name for a60&lt;br /&gt;
select sum(bytes)/1024/1024      mbytes_alloc&lt;br /&gt;
,      sum(maxbytes)/1024/1024   mbytes_max&lt;br /&gt;
,      file_name&lt;br /&gt;
from   sys.dba_temp_files&lt;br /&gt;
group  by file_name&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Resize the online redo logfiles===&lt;br /&gt;
Found a more concise, smarter way of doing it [http://www.oracle-wiki.net/startdocshowtorecreateredogrps here] - oracle-wiki.net&amp;lt;br /&amp;gt;&lt;br /&gt;
Switching logs too often? Redolog files too small?&amp;lt;br /&amp;gt;&lt;br /&gt;
* Show current log groups&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 1000&lt;br /&gt;
col group_member for a60&lt;br /&gt;
select l.group#          group_number&lt;br /&gt;
,      (bytes/1024/1024) megs&lt;br /&gt;
,      l.status          group_status&lt;br /&gt;
,      f.member          group_member&lt;br /&gt;
,      l.archived        archived&lt;br /&gt;
,      f.type            file_type&lt;br /&gt;
from   v$log     l&lt;br /&gt;
,      v$logfile f&lt;br /&gt;
where  l.group# = f.group#&lt;br /&gt;
order  by l.group#&lt;br /&gt;
,      f.member&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Create additional (bigger) groups&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
define SID=TIBQFW&lt;br /&gt;
alter database add logfile group 6  &amp;#039;/oracle/&amp;amp;SID/oradata1/redo1.log&amp;#039; size 1G;&lt;br /&gt;
alter database add logfile group 7  &amp;#039;/oracle/&amp;amp;SID/oradata2/redo2.log&amp;#039; size 1G;&lt;br /&gt;
alter database add logfile group 8  &amp;#039;/oracle/&amp;amp;SID/oradata3/redo3.log&amp;#039; size 1G;&lt;br /&gt;
alter database add logfile group 9  &amp;#039;/oracle/&amp;amp;SID/oradata1/redo4.log&amp;#039; size 1G;&lt;br /&gt;
alter database add logfile group 10 &amp;#039;/oracle/&amp;amp;SID/oradata2/redo5.log&amp;#039; size 1G;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or if you use multiple members...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter database add logfile group 6 (&amp;#039;/oracle/&amp;amp;SID/oradata1/redo/redo01a.log&amp;#039;, &amp;#039;/oracle/&amp;amp;SID/oradata1/redo01b&amp;#039;) size 50M;&lt;br /&gt;
alter database add logfile group 7 (&amp;#039;/oracle/&amp;amp;SID/oradata1/redo/redo02a.log&amp;#039;, &amp;#039;/oracle/&amp;amp;SID/oradata1/redo02b&amp;#039;) size 50M;&lt;br /&gt;
alter database add logfile group 8 (&amp;#039;/oracle/&amp;amp;SID/oradata1/redo/redo03a.log&amp;#039;, &amp;#039;/oracle/&amp;amp;SID/oradata1/redo03b&amp;#039;) size 50M;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Switch archivelogs until the new ones are current and the old ones are inactive&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter system switch logfile;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
If the old logs are not yet inactive, checkpoint the database&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter system checkpoint;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Drop the old groups&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter database drop logfile group 1;&lt;br /&gt;
alter database drop logfile group 2;&lt;br /&gt;
alter database drop logfile group 3;&lt;br /&gt;
alter database drop logfile group 4;&lt;br /&gt;
alter database drop logfile group 5;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Increase the existing size of a datafile===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter database datafile &amp;#039;&amp;amp;full_path_of_datafile&amp;#039; resize &amp;amp;new_meg_size.M;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Increase the max size of a tempfile===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter database tempfile &amp;#039;/oracle/ENDP1/oradata90/temp01.dbf&amp;#039; autoextend on maxsize unlimited;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Find out what processes are using the temp tablespace===&lt;br /&gt;
Temporary tablespace is used for sorting query results. Find them with this.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SELECT b.tablespace,b.segfile#,b.segblk#,b.blocks,a.sid,a.serial#,&lt;br /&gt;
a.username,a.osuser, a.status&lt;br /&gt;
FROM v$session a,v$sort_usage b&lt;br /&gt;
WHERE a.saddr = b.session_addr;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Increase the maximum size of a datafile===&lt;br /&gt;
Although this can be set lower than existing size, try not to. It makes the reports look weird!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter database&lt;br /&gt;
      datafile &amp;#039;&amp;amp;full_path_of_datafile&amp;#039;&lt;br /&gt;
      autoextend on&lt;br /&gt;
      maxsize &amp;amp;new_meg_size.m;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Find schemas (users) with objects created outside their default tablespace===&lt;br /&gt;
Indexes could be a notable exception if they are created in an index tablespace&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 200&lt;br /&gt;
col owner           for a20&lt;br /&gt;
col segment_name    for a45&lt;br /&gt;
col tablespace_name for a32&lt;br /&gt;
select owner&lt;br /&gt;
,      segment_name&lt;br /&gt;
,      tablespace_name&lt;br /&gt;
from   dba_segments&lt;br /&gt;
where  exists (select username from dba_users where username = owner)&lt;br /&gt;
and    tablespace_name != (select default_tablespace from dba_users where username = owner)&lt;br /&gt;
and    owner = &amp;#039;&amp;amp;owner&amp;#039;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Add a datafile to a tablespace===&lt;br /&gt;
&amp;#039;unlimited&amp;#039; will default to the maximum datafile size for the current db_block_size&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter tablepace &amp;amp;tablespace_name&lt;br /&gt;
      add datafile &amp;#039;&amp;amp;full_path_of_datafile&amp;#039;&lt;br /&gt;
      size 100M&lt;br /&gt;
      autoextend on&lt;br /&gt;
      next 100M&lt;br /&gt;
      maxsize unlimited&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===List all datafiles with their size===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set pages 1000 lines 2000&lt;br /&gt;
col filetype for a15&lt;br /&gt;
col name for a60&lt;br /&gt;
break on report&lt;br /&gt;
compute sum of gig on report&lt;br /&gt;
&lt;br /&gt;
select filetype&lt;br /&gt;
,      name&lt;br /&gt;
,      gig&lt;br /&gt;
from   (&lt;br /&gt;
       select &amp;#039;datafile&amp;#039; filetype&lt;br /&gt;
       ,      name&lt;br /&gt;
       ,      bytes/1024/1024 gig&lt;br /&gt;
       from   v$datafile&lt;br /&gt;
       union all&lt;br /&gt;
       select &amp;#039;tempfile&amp;#039; filetype&lt;br /&gt;
       ,      name&lt;br /&gt;
       ,      bytes/1024/1024&lt;br /&gt;
       from   v$tempfile&lt;br /&gt;
       union all&lt;br /&gt;
       select &amp;#039;logfile&amp;#039; filetype&lt;br /&gt;
       ,      lf.member &amp;quot;name&amp;quot;&lt;br /&gt;
       ,      l.bytes/1024/1024&lt;br /&gt;
       from   v$logfile lf&lt;br /&gt;
       ,      v$log     l&lt;br /&gt;
       where  1=1&lt;br /&gt;
       and    lf.group# = l.group#&lt;br /&gt;
       ) used&lt;br /&gt;
,      (&lt;br /&gt;
       select sum(bytes)/1024/1024&lt;br /&gt;
       from   dba_free_space&lt;br /&gt;
       ) free&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Database size (How big is my database?)===&lt;br /&gt;
There are different interpretations of what constitutes the size of a database...&amp;lt;br /&amp;gt;&lt;br /&gt;
Is it the space allocated to the datafiles or only the space taken up by the data? Are tempfiles included? Are redo logs included? etc...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 132&lt;br /&gt;
col dbname for a9  heading &amp;quot;Database&amp;quot;&lt;br /&gt;
col dbsize for a15 heading &amp;quot;Size&amp;quot;&lt;br /&gt;
col dbused for a15 heading &amp;quot;Used space&amp;quot;&lt;br /&gt;
col dbfree for a15 heading &amp;quot;Free space&amp;quot;&lt;br /&gt;
with used_space as&lt;br /&gt;
(&lt;br /&gt;
select  bytes&lt;br /&gt;
from    v$datafile&lt;br /&gt;
union   all&lt;br /&gt;
select  bytes&lt;br /&gt;
from    v$tempfile&lt;br /&gt;
union   all&lt;br /&gt;
select  bytes&lt;br /&gt;
from    v$log&lt;br /&gt;
)&lt;br /&gt;
, free_space as&lt;br /&gt;
(&lt;br /&gt;
select sum(bytes) sum_bytes&lt;br /&gt;
from dba_free_space&lt;br /&gt;
)&lt;br /&gt;
select vd.name                                                                                            dbname&lt;br /&gt;
,      round(sum(used_space.bytes)/1024/1024/1024 ) || &amp;#039; GB&amp;#039;                                              dbsize&lt;br /&gt;
,      round(sum(used_space.bytes)/1024/1024/1024 ) - round(free_space.sum_bytes/1024/1024/1024) || &amp;#039; GB&amp;#039; dbused&lt;br /&gt;
,      round(free_space.sum_bytes/1024/1024/1024) || &amp;#039; GB&amp;#039;                                                dbfree&lt;br /&gt;
from   free_space&lt;br /&gt;
,      used_space&lt;br /&gt;
,      v$database vd&lt;br /&gt;
group  by vd.name&lt;br /&gt;
,      free_space.sum_bytes&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Drop datafile from temp tablespace===&lt;br /&gt;
Database is completely stuck because the temporary tablespace has grown to fill all available room.&amp;lt;br /&amp;gt;&lt;br /&gt;
Look around for at least some log files to delete in order to get connected (audit files, sqlnet logs, listener logs)&amp;lt;br /&amp;gt;&lt;br /&gt;
Once connected, change the default temporary tablespace to a small one so we can remove the original.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
create temporary tablespace temp2 tempfile &amp;#039;/oracle/RMANV12/oradata2/temp2.dbf&amp;#039; size 5M;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter database default temporary tablespace temp2;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
I found trying to drop the datafile like this didn&amp;#039;t work, just hung there (probably active tranactions)...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
drop tablespace temp including contents and datafiles;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
So did it like this...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter database tempfile &amp;#039;/oracle/RMANV12/oradata2/temp.dbf&amp;#039; drop including datafiles;&lt;br /&gt;
&lt;br /&gt;
Database altered.&lt;br /&gt;
&lt;br /&gt;
drop tablespace temp including contents and datafiles;&lt;br /&gt;
&lt;br /&gt;
Tablespace dropped.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
... an alternative would be to find the sessions using the temp space and kill them...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select sid, serial#, status from v$session where serial# in (select session_num from v$sort_usage);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Then to be neat and tidy, rename the temp2 tablespace back to temp.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
create temporary tablespace temp tempfile &amp;#039;/oracle/RMANV12/oradata2/temp.dbf&amp;#039; size 256M reuse autoextend on next 128M maxsize 1G;&lt;br /&gt;
alter database default temporary tablespace temp;&lt;br /&gt;
drop tablespace temp2 including contents and datafiles;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Although the last statement will not work until any transactions using it have been rolled back or committed.&lt;br /&gt;
&lt;br /&gt;
===List files that are in hot-backup mode===&lt;br /&gt;
 set lines 100&lt;br /&gt;
 set pages 100&lt;br /&gt;
 col name format a60&lt;br /&gt;
 &lt;br /&gt;
 select df.name&lt;br /&gt;
 ,      b.status&lt;br /&gt;
 ,      to_char(time, &amp;#039;hh24:mi:ss dd/mm/yyyy&amp;#039;) time&lt;br /&gt;
 from   v$datafile   df&lt;br /&gt;
 ,      v$backup     b&lt;br /&gt;
 where  1=1&lt;br /&gt;
 and    df.file# = b.file#&lt;br /&gt;
 and    b.status = &amp;#039;ACTIVE&amp;#039;&lt;br /&gt;
 order  by b.file#;&lt;br /&gt;
&lt;br /&gt;
===Waiting for snapshot control file enqueue===&lt;br /&gt;
Script to identify sessions causing RMAN to hang because of &amp;#039;waiting for snapshot control file enqueue&amp;#039; message&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 2000&lt;br /&gt;
col killer     for a70&lt;br /&gt;
col program    for a20&lt;br /&gt;
col module     for a20&lt;br /&gt;
col action     for a20&lt;br /&gt;
col logon_time for a20&lt;br /&gt;
&lt;br /&gt;
select &amp;#039;alter system disconnect session &amp;#039;&amp;#039;&amp;#039;||s.sid||&amp;#039;,&amp;#039;||s.serial#||&amp;#039;&amp;#039;&amp;#039; immediate;&amp;#039; killer&lt;br /&gt;
,      username&lt;br /&gt;
,      program&lt;br /&gt;
,      module&lt;br /&gt;
,      action&lt;br /&gt;
,      logon_time&lt;br /&gt;
from   v$session s&lt;br /&gt;
,      v$enqueue_lock l&lt;br /&gt;
where  l.sid  = s.sid&lt;br /&gt;
and    l.type = &amp;#039;CF&amp;#039;&lt;br /&gt;
and    l.id1  = 0&lt;br /&gt;
and    l.id2  = 2&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Info on blocking processes===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select s1.username || &amp;#039;@&amp;#039; || s1.machine&lt;br /&gt;
       || &amp;#039; ( SID=&amp;#039; || s1.sid || &amp;#039; )  is blocking &amp;#039;&lt;br /&gt;
       || s2.username || &amp;#039;@&amp;#039; || s2.machine || &amp;#039; ( SID=&amp;#039; || s2.sid || &amp;#039; ) &amp;#039;  blocking_status&lt;br /&gt;
from   v$lock l1&lt;br /&gt;
,      v$session s1&lt;br /&gt;
,      v$lock l2&lt;br /&gt;
,      v$session s2&lt;br /&gt;
where  s1.sid     = l1.sid&lt;br /&gt;
and    s2.sid     = l2.sid&lt;br /&gt;
and    l1.block   = 1&lt;br /&gt;
and    l2.request &amp;gt; 0&lt;br /&gt;
and    l1.id1     = l2.id1&lt;br /&gt;
and    l2.id2     = l2.id2&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
session doing the blocking&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select *&lt;br /&gt;
from  v$lock l1&lt;br /&gt;
where 1=1&lt;br /&gt;
and   block = 1 ;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
sessions being blocked&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select *&lt;br /&gt;
from   v$lock l1&lt;br /&gt;
where  1=1&lt;br /&gt;
and    id2 = 85203&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
info on session doing the blocking&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select row_wait_obj#, row_wait_file#, row_wait_block#, row_wait_row#&lt;br /&gt;
from   v$session&lt;br /&gt;
where  sid = 234&lt;br /&gt;
&lt;br /&gt;
select do.object_name&lt;br /&gt;
,      row_wait_obj#&lt;br /&gt;
,      row_wait_file#&lt;br /&gt;
,      row_wait_block#&lt;br /&gt;
,      row_wait_row#&lt;br /&gt;
,      dbms_rowid.rowid_create ( 1, ROW_WAIT_OBJ#, ROW_WAIT_FILE#, ROW_WAIT_BLOCK#, ROW_WAIT_ROW# ) row_id&lt;br /&gt;
from   v$session   s&lt;br /&gt;
,      dba_objects do&lt;br /&gt;
where  sid=234&lt;br /&gt;
and    s.ROW_WAIT_OBJ# = do.OBJECT_ID;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Show locked objects===&lt;br /&gt;
 set lines 100&lt;br /&gt;
 set pages 999&lt;br /&gt;
 col username   format a20&lt;br /&gt;
 col sess_id    format a10&lt;br /&gt;
 col object     format a25&lt;br /&gt;
 col mode_held  format a10&lt;br /&gt;
 select oracle_username||&amp;#039; (&amp;#039;||s.osuser||&amp;#039;)&amp;#039; username&lt;br /&gt;
 ,      s.sid||&amp;#039;,&amp;#039;||s.serial# sess_id&lt;br /&gt;
 ,      owner||&amp;#039;.&amp;#039;||object_name object&lt;br /&gt;
 ,      object_type&lt;br /&gt;
 ,      decode ( l.block&lt;br /&gt;
               , 0, &amp;#039;Not Blocking&amp;#039;&lt;br /&gt;
               , 1, &amp;#039;Blocking&amp;#039;&lt;br /&gt;
               , 2, &amp;#039;Global&amp;#039;&lt;br /&gt;
               ) status&lt;br /&gt;
 ,      decode ( v.locked_mode&lt;br /&gt;
               , 0, &amp;#039;None&amp;#039;&lt;br /&gt;
               , 1, &amp;#039;Null&amp;#039;&lt;br /&gt;
               , 2, &amp;#039;Row-S (SS)&amp;#039;&lt;br /&gt;
               , 3, &amp;#039;Row-X (SX)&amp;#039;&lt;br /&gt;
               , 4, &amp;#039;Share&amp;#039;&lt;br /&gt;
               , 5, &amp;#039;S/Row-X (SSX)&amp;#039;&lt;br /&gt;
               , 6, &amp;#039;Exclusive&amp;#039;, TO_CHAR(lmode)&lt;br /&gt;
               ) mode_held&lt;br /&gt;
 from   v$locked_object v&lt;br /&gt;
 ,      dba_objects d&lt;br /&gt;
 ,      v$lock l&lt;br /&gt;
 ,      v$session s&lt;br /&gt;
 where  1=1&lt;br /&gt;
 and    v.object_id = d.object_id&lt;br /&gt;
 and    v.object_id = l.id1&lt;br /&gt;
 and    v.session_id = s.sid&lt;br /&gt;
 order  by oracle_username&lt;br /&gt;
 ,	session_id;&lt;br /&gt;
&lt;br /&gt;
===Show which row is locked===&lt;br /&gt;
 select do.object_name&lt;br /&gt;
 ,      row_wait_obj#&lt;br /&gt;
 ,      row_wait_file#&lt;br /&gt;
 ,      row_wait_block#&lt;br /&gt;
 ,      row_wait_row#&lt;br /&gt;
 ,      dbms_rowid.rowid_create (1, ROW_WAIT_OBJ#, ROW_WAIT_FILE#, ROW_WAIT_BLOCK#, ROW_WAIT_ROW#)&lt;br /&gt;
 from   v$session   s&lt;br /&gt;
 ,      dba_objects do&lt;br /&gt;
 where  1=1&lt;br /&gt;
 and    s.ROW_WAIT_OBJ# = do.OBJECT_ID&lt;br /&gt;
 and    sid             = &amp;amp;sid;&lt;br /&gt;
&lt;br /&gt;
===Check what is audited on a database===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set pagesize 100&lt;br /&gt;
set linesize 256&lt;br /&gt;
select audit_option,success,failure from dba_stmt_audit_opts;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===How old is the oldest audit record?===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select extract (day from (systimestamp - min(ntimestamp#))) days_old from aud$;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Check what objects are being audited===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
tti col 60 &amp;#039;Object Audit Options (dba_obj_audit_opts)&amp;#039; skip col 50 &amp;#039;A=By Access, S=By Session. Left=on success, right=on failure&amp;#039; skip 2&lt;br /&gt;
set lines 1000 pages 100&lt;br /&gt;
col alt for a3 head &amp;quot;Alt|er&amp;quot;&lt;br /&gt;
col aud for a3 head &amp;quot;Aud|it&amp;quot;&lt;br /&gt;
col com for a3 head &amp;quot;Com|ent&amp;quot;&lt;br /&gt;
col del for a3 head &amp;quot;Del|ete&amp;quot;&lt;br /&gt;
col gra for a3 head &amp;quot;Gra|nt&amp;quot;&lt;br /&gt;
col ind for a3 head &amp;quot;Ind|ex&amp;quot;&lt;br /&gt;
col ins for a3 head &amp;quot;Ins|ert&amp;quot;&lt;br /&gt;
col loc for a3 head &amp;quot;Lo|ck&amp;quot;&lt;br /&gt;
col ren for a3 head &amp;quot;Ren|ame&amp;quot;&lt;br /&gt;
col sel for a3 head &amp;quot;Sel|ect&amp;quot;&lt;br /&gt;
col upd for a3 head &amp;quot;Upd|ate&amp;quot;&lt;br /&gt;
col ref for a3 head &amp;quot;Ref|rnc&amp;quot;&lt;br /&gt;
col exe for a3 head &amp;quot;Exe|cut&amp;quot;&lt;br /&gt;
col cre for a3 head &amp;quot;Cre|ate&amp;quot;&lt;br /&gt;
col rea for a3 head &amp;quot;Re|ad&amp;quot;&lt;br /&gt;
col wri for a3 head &amp;quot;Wri|te&amp;quot;&lt;br /&gt;
col fbk for a3 head &amp;quot;Fla|sh&amp;quot;&lt;br /&gt;
	&lt;br /&gt;
select *&lt;br /&gt;
from   dba_obj_audit_opts&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Procedure to delete old audit records===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select text from all_source where lower(name)=&amp;#039;purge_audit_trail&amp;#039;;&lt;br /&gt;
&lt;br /&gt;
TEXT&lt;br /&gt;
------------------------------------------------------------------------------------------------&lt;br /&gt;
PROCEDURE purge_audit_trail IS&lt;br /&gt;
BEGIN&lt;br /&gt;
-- set the last archive timestamp&lt;br /&gt;
DBMS_AUDIT_MGMT.SET_LAST_ARCHIVE_TIMESTAMP(&lt;br /&gt;
       audit_trail_type    =&amp;gt; DBMS_AUDIT_MGMT.AUDIT_TRAIL_AUD_STD,&lt;br /&gt;
       last_archive_time   =&amp;gt; systimestamp - interval &amp;#039;365&amp;#039; day,&lt;br /&gt;
       rac_instance_number =&amp;gt; null&lt;br /&gt;
                                          );&lt;br /&gt;
-- purge audit trail till last archive timestamp&lt;br /&gt;
DBMS_AUDIT_MGMT.CLEAN_AUDIT_TRAIL( audit_trail_type =&amp;gt; DBMS_AUDIT_MGMT.AUDIT_TRAIL_AUD_STD&lt;br /&gt;
, use_last_arch_timestamp =&amp;gt; TRUE);&lt;br /&gt;
&lt;br /&gt;
END purge_audit_trail;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Job setup to run the audit purge===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
BEGIN&lt;br /&gt;
sys.dbms_scheduler.create_job(&lt;br /&gt;
    job_name =&amp;gt; &amp;#039;&amp;quot;SYS&amp;quot;.&amp;quot;PURGE_AUDIT_TRAIL_JOB&amp;quot;&amp;#039;,&lt;br /&gt;
    job_type =&amp;gt; &amp;#039;STORED_PROCEDURE&amp;#039;,&lt;br /&gt;
    job_action =&amp;gt; &amp;#039;&amp;quot;SYS&amp;quot;.&amp;quot;PURGE_AUDIT_TRAIL&amp;quot;&amp;#039;,&lt;br /&gt;
    repeat_interval =&amp;gt; &amp;#039;FREQ=DAILY;BYHOUR=20;BYMINUTE=0;BYSECOND=0&amp;#039;,&lt;br /&gt;
    start_date =&amp;gt; to_timestamp_tz(&amp;#039;2012-02-22 Europe/Paris&amp;#039;, &amp;#039;YYYY-MM-DD TZR&amp;#039;),&lt;br /&gt;
    job_class =&amp;gt; &amp;#039;&amp;quot;DEFAULT_JOB_CLASS&amp;quot;&amp;#039;,&lt;br /&gt;
    comments =&amp;gt; &amp;#039;purge audit trails until last archive timestamp&amp;#039;,&lt;br /&gt;
    auto_drop =&amp;gt; FALSE,&lt;br /&gt;
    enabled =&amp;gt; FALSE&lt;br /&gt;
);&lt;br /&gt;
sys.dbms_scheduler.set_attribute( name =&amp;gt; &amp;#039;&amp;quot;SYS&amp;quot;.&amp;quot;PURGE_AUDIT_TRAIL_JOB&amp;quot;&amp;#039;, attribute =&amp;gt; &amp;#039;logging_level&amp;#039;, value =&amp;gt; DBMS_SCHEDULER.LOGGING_OFF);&lt;br /&gt;
sys.dbms_scheduler.set_attribute( name =&amp;gt; &amp;#039;&amp;quot;SYS&amp;quot;.&amp;quot;PURGE_AUDIT_TRAIL_JOB&amp;quot;&amp;#039;, attribute =&amp;gt; &amp;#039;job_weight&amp;#039;, value =&amp;gt; 1);&lt;br /&gt;
sys.dbms_scheduler.enable( &amp;#039;&amp;quot;SYS&amp;quot;.&amp;quot;PURGE_AUDIT_TRAIL_JOB&amp;quot;&amp;#039; );&lt;br /&gt;
END;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===A list of all SIDs in oratab that should restart after a server boot===&lt;br /&gt;
Using awk&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
awk -F: &amp;#039;$NF==&amp;quot;Y&amp;quot; &amp;amp;&amp;amp; $1 !~/[#]/ {print $1}&amp;#039;  /etc/oratab&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Using perl&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
perl -F: -ne &amp;#039;print &amp;quot;$1\n&amp;quot; if /(\w+):(.+):Y$/&amp;#039; /etc/oratab&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Move the admin directories to a new location===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
./all_db_do &amp;quot;alter system set audit_file_dest=&amp;#039;/oracle/&amp;amp;SID/admin/adump&amp;#039; scope=spfile;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
./all_db_do &amp;quot;shutdown immediate&amp;quot;&lt;br /&gt;
&lt;br /&gt;
for db in `awk -F: &amp;#039;NF &amp;amp;&amp;amp; $1 !~/[#*]/ {print $1}&amp;#039;  /etc/oratab`&lt;br /&gt;
do&lt;br /&gt;
    echo $db&lt;br /&gt;
    mkdir -p /oracle/${db}/admin&lt;br /&gt;
    echo &amp;quot;/oracle/${db}/admin created&amp;quot;&lt;br /&gt;
    mv /oracle/admin/${db}/adump /oracle/${db}/admin/&lt;br /&gt;
    mv /oracle/admin/${db}/dpdump /oracle/${db}/admin/&lt;br /&gt;
    echo &amp;quot;Moved /oracle/admin/${db}/adump to /oracle/${db}/admin/&amp;quot;&lt;br /&gt;
done&lt;br /&gt;
&lt;br /&gt;
./all_db_do startup&lt;br /&gt;
&lt;br /&gt;
./all_db_do &amp;quot;create pfile from spfile;&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Check if the Standby database is up-to-date with the primary database===&lt;br /&gt;
 select arch.thread# &amp;quot;Thread&amp;quot;&lt;br /&gt;
 ,      arch.sequence# &amp;quot;Last Sequence Received&amp;quot;&lt;br /&gt;
 ,      appl.sequence# &amp;quot;Last Sequence Applied&amp;quot;&lt;br /&gt;
 ,      (arch.sequence# - appl.sequence#) &amp;quot;Difference&amp;quot;&lt;br /&gt;
 from   (&lt;br /&gt;
        select thread#&lt;br /&gt;
        ,      sequence#&lt;br /&gt;
        from   v$archived_log&lt;br /&gt;
        where  1=1&lt;br /&gt;
        and    ( thread#,first_time ) in (&lt;br /&gt;
                                         select thread#, max(first_time)&lt;br /&gt;
                                         from   v$archived_log&lt;br /&gt;
                                         group  by thread#&lt;br /&gt;
                                         )&lt;br /&gt;
        ) arch&lt;br /&gt;
        ,&lt;br /&gt;
        (&lt;br /&gt;
        select thread#&lt;br /&gt;
        ,      sequence#&lt;br /&gt;
        from   v$log_history&lt;br /&gt;
        where  1=1&lt;br /&gt;
        and    ( thread#,first_time ) in ( select thread# ,max(first_time)&lt;br /&gt;
                                           from   v$log_history&lt;br /&gt;
                                           group  by thread#&lt;br /&gt;
                                          )&lt;br /&gt;
        ) appl&lt;br /&gt;
 where  1=1&lt;br /&gt;
 and    arch.thread# = appl.thread#&lt;br /&gt;
 order  by 1;&lt;br /&gt;
&lt;br /&gt;
===Check for gaps on the Standby database===&lt;br /&gt;
Run this on the standby&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select thread#, low_sequence#, high_sequence# from v$archive_gap;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or run this on the Primary to see the latest generated archive...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select thread#   &amp;quot;Thread&amp;quot;&lt;br /&gt;
,      sequence# &amp;quot;Last sequence generated&amp;quot;&lt;br /&gt;
from   v$archived_log&lt;br /&gt;
where  (thread#, first_time) in ( select thread#, max(first_time)&lt;br /&gt;
                                  from   v$archived_log&lt;br /&gt;
                                  group  by thread#&lt;br /&gt;
                                )&lt;br /&gt;
order  by 1&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
and run this on the standby to check for received but not yet applied logs (this could be normal if a lag has been set)...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select arch.thread# &amp;quot;Thread&amp;quot;&lt;br /&gt;
,      arch.sequence# &amp;quot;Last sequence received&amp;quot;&lt;br /&gt;
,      appl.sequence# &amp;quot;Last sequence applied&amp;quot;&lt;br /&gt;
,      (arch.sequence#-appl.sequence#) &amp;quot;Difference&amp;quot;&lt;br /&gt;
from   (&lt;br /&gt;
       select thread#&lt;br /&gt;
       ,      sequence#&lt;br /&gt;
       from   v$archived_log&lt;br /&gt;
       where  (thread#,first_time ) in (select thread#, max(first_time)&lt;br /&gt;
                                        from   v$archived_log&lt;br /&gt;
                                        group  by thread#&lt;br /&gt;
                                       )&lt;br /&gt;
       ) arch&lt;br /&gt;
,      (&lt;br /&gt;
       select thread#&lt;br /&gt;
       ,      sequence#&lt;br /&gt;
       from   v$log_history&lt;br /&gt;
       where  (thread#,first_time ) in (select thread#, max(first_time)&lt;br /&gt;
                                        from   v$log_history&lt;br /&gt;
                                        group  by thread#&lt;br /&gt;
                                       )&lt;br /&gt;
      ) appl&lt;br /&gt;
where arch.thread# = appl.thread#&lt;br /&gt;
order by 1&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Compare the results from Primary and Secondary to detect possible network problems or other errors in shipping.&lt;br /&gt;
&lt;br /&gt;
===Ignore case-sensitive passwords in 11g (deprecated in 12c)===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter system set SEC_CASE_SENSITIVE_LOGON = false scope=both&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===External table for the Alert log (pre 11g)===&lt;br /&gt;
Modified to use (the better) scripts found on [http://www.adp-gmbh.ch/ora/admin/scripts/read_alert_log.html Rene Nyffenegger&amp;#039;s site]&amp;lt;br /&amp;gt;&lt;br /&gt;
This script generates the required DDL for the alertlog table&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
column db    new_value _DB    noprint;&lt;br /&gt;
column bdump new_value _bdump noprint;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Alert log (11g+)===&lt;br /&gt;
This reads the log.xml file (which contains the same information as alert.log)&amp;lt;br /&amp;gt;&lt;br /&gt;
Show the messages put in the alert log in the last 24 hours&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select substr(MESSAGE_TEXT, 1, 300) message_text&lt;br /&gt;
,      count(*) cnt&lt;br /&gt;
from   X$DBGALERTEXT&lt;br /&gt;
where  1=1&lt;br /&gt;
and    (MESSAGE_TEXT like &amp;#039;%ORA-%&amp;#039; or upper(MESSAGE_TEXT) like &amp;#039;%ERROR%&amp;#039;)&lt;br /&gt;
and    cast(ORIGINATING_TIMESTAMP as DATE) &amp;gt; sysdate - &amp;amp;days_ago/1440&lt;br /&gt;
group  by substr(MESSAGE_TEXT, 1, 300)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
There is also a fixed table X$DBGDIREXT which returns all file and directory names under [diagnostic_dest]/diag directory:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select lpad(&amp;#039; &amp;#039;,lvl,&amp;#039; &amp;#039;)||logical_file file_name&lt;br /&gt;
from   x$dbgdirext&lt;br /&gt;
where  rownum &amp;lt;=20;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Directory paths available in v$diag_info===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 2000&lt;br /&gt;
col name for a35&lt;br /&gt;
col value for a100 wrap&lt;br /&gt;
select * from v$diag_info;&lt;br /&gt;
&lt;br /&gt;
   INST_ID NAME                                VALUE                                                                                                    CON_ID&lt;br /&gt;
---------- ----------------------------------- ---------------------------------------------------------------------------------------------------- ----------&lt;br /&gt;
         1 Diag Enabled                        TRUE                                                                                                          0&lt;br /&gt;
         1 ADR Base                            /cln/prg/ora_bin2/app/oracle                                                                               0&lt;br /&gt;
         1 ADR Home                            /cln/prg/ora_bin2/app/oracle/diag/rdbms/bild/bild                                                          0&lt;br /&gt;
         1 Diag Trace                          /cln/prg/ora_bin2/app/oracle/diag/rdbms/bild/bild/trace                                                    0&lt;br /&gt;
         1 Diag Alert                          /cln/prg/ora_bin2/app/oracle/diag/rdbms/bild/bild/alert                                                    0&lt;br /&gt;
         1 Diag Incident                       /cln/prg/ora_bin2/app/oracle/diag/rdbms/bild/bild/incident                                                 0&lt;br /&gt;
         1 Diag Cdump                          /cln/prg/ora_bin2/app/oracle/diag/rdbms/bild/bild/cdump                                                    0&lt;br /&gt;
         1 Health Monitor                      /cln/prg/ora_bin2/app/oracle/diag/rdbms/bild/bild/hm                                                       0&lt;br /&gt;
         1 Default Trace File                  /cln/prg/ora_bin2/app/oracle/diag/rdbms/bild/bild/trace/bild_ora_44696768.trc                              0&lt;br /&gt;
         1 Active Problem Count                0                                                                                                             0&lt;br /&gt;
         1 Active Incident Count               0                                                                                                             0&lt;br /&gt;
&lt;br /&gt;
11 rows selected.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Find out the names of the active trace files for the running processes===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select pid, program, tracefile from v$process;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Request was to duplicate a large tablespace from production to test environment===&lt;br /&gt;
...but rather than copy the terabytes of data, create the destination tablespace with just the most recent months data&amp;lt;br /&amp;gt;&lt;br /&gt;
====See what the source data looks like====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
col table_owner    for a20&lt;br /&gt;
col table_name     for a30&lt;br /&gt;
col partition_name for a20&lt;br /&gt;
set pages 100 lines 1000&lt;br /&gt;
&lt;br /&gt;
select table_owner&lt;br /&gt;
,      table_name&lt;br /&gt;
,      partition_name&lt;br /&gt;
,      partition_position&lt;br /&gt;
,      tablespace_name&lt;br /&gt;
from   dba_tab_partitions&lt;br /&gt;
where  tablespace_name = &amp;#039;ADS_ARCHIVE&amp;#039;&lt;br /&gt;
order  by 1,2,3,4&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This query produces something like this...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
TABLE_OWNER          TABLE_NAME                     PARTITION_NAME       PARTITION_POSITION TABLESPACE_NAME                &lt;br /&gt;
-------------------- ------------------------------ -------------------- ------------------ ------------------------------ &lt;br /&gt;
ADS_ARCHIVE          BIL_DAY_INV_CTR_ARC            Y2017_Q1_M01_D01                      1 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          BIL_HIS_DETAIL_FAC_ARC         Y2016_Q2_M05_D04                      1 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          BIL_HIS_DETAIL_FAC_ARC         Y2016_Q2_M05_D09                      2 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          BIL_MTH_INV_CTR_ARC            Y2017_Q1_M01_D01                      1 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          FAH_DAY_CBA_BGAAP_ARC          Y2011_Q4_M12_D30                      1 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          FAH_DAY_CBA_BGAAP_ARC          Y2011_Q4_M12_D31                      2 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          FAH_DAY_CBA_IFRS_ARC           Y2011_Q4_M12_D30                      1 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          FAH_DAY_CBA_IFRS_ARC           Y2011_Q4_M12_D31                      2 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          FAH_DAY_MVT_BGAAP_ARC          Y2011_Q4_M12_D30                      1 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          FAH_DAY_MVT_BGAAP_ARC          Y2011_Q4_M12_D31                      2 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          FAH_DAY_MVT_BGAAP_ARC          Y2012_Q1_M03_D31                      3 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          FAH_DAY_MVT_BGAAP_ARC          Y2012_Q2_M04_D01                      4 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          FAH_DAY_MVT_BGAAP_ARC          Y2012_Q4_M10_D12                      5 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          FAH_DAY_MVT_BGAAP_ARC          Y2012_Q4_M10_D13                      6 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          FAH_DAY_MVT_BGAAP_ARC          Y2012_Q4_M10_D14                      7 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          FAH_DAY_MVT_BGAAP_ARC_TST      Y2011_Q4_M12_D30                      1 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          FAH_DAY_MVT_BGAAP_ARC_TST      Y2011_Q4_M12_D31                      2 ADS_ARCHIVE&lt;br /&gt;
...&lt;br /&gt;
ADS_ARCHIVE          SBP_HIS_LINES_ARC              P_LS                                  3 ADS_ARCHIVE                  &lt;br /&gt;
ADS_ARCHIVE          THA_DAY_INV_CTR_ARC            Y2011_Q4_M12_D30                      1 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          THA_DAY_INV_CTR_ARC            Y2011_Q4_M12_D31                      2 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          THA_INV_HEAVY_ARC              Y2011_Q4_M12_D30                      1 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          THA_INV_HEAVY_ARC              Y2011_Q4_M12_D31                      2 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          THA_INV_LIGHT_ARC              Y2011_Q4_M12_D30                      1 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          THA_INV_LIGHT_ARC              Y2012_Q4_M10_D12                      2 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          THA_INV_LIGHT_ARC              Y2012_Q4_M10_D13                      3 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          THA_INV_LIGHT_ARC              Y2012_Q4_M10_D15                      4 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          THA_INV_LIGHT_ARC              Y2012_Q4_M10_D16                      5 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          THA_INV_LIGHT_ARC              Y2012_Q4_M10_D17                      6 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          THA_INV_LIGHT_ARC              Y2012_Q4_M10_D18                      7 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          THA_INV_LIGHT_ARC              Y2012_Q4_M10_D19                      8 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          THA_INV_LIGHT_ARC              Y2012_Q4_M10_D20                      9 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          THA_INV_LIGHT_ARC              Y2012_Q4_M10_D21                     10 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          THA_INV_LIGHT_ARC              Y2012_Q4_M10_D22                     11 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          THA_INV_LIGHT_ARC              Y2012_Q4_M10_D23                     12 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          THA_INV_LIGHT_ARC              Y2012_Q4_M10_D24                     13 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          THA_MTH_INV_CTR_ARC            Y2011_Q4_M12_D30                      1 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          THA_MTH_INV_CTR_ARC            Y2011_Q4_M12_D31                      2 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          THA_MTH_INV_CTR_ARC            Y2013_Q2_M04_D30                      3 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          XBD01_TEMP_HIS_ARC             Y2012_Q4_M12_D31                      1 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          T_RPT_RECO_THA_INV_ACC_ARC     Y2011_Q4_M12_D30                      1 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          T_RPT_RECO_THA_INV_ACC_ARC     Y2011_Q4_M12_D31                      2 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          T_RPT_RECO_THA_INV_MTH_ARC     Y2011_Q4_M12_D30                      1 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          T_RPT_RECO_THA_INV_MTH_ARC     Y2011_Q4_M12_D31                      2 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          XBD01_TEMP_HIS_ARC             Y2012_Q4_M12_D31                      1 ADS_ARCHIVE&lt;br /&gt;
ADS_DBA              FAH_DAY_CBA_BGAAP              Y2016_Q3_M07_D12                   1657 ADS_ARCHIVE&lt;br /&gt;
ADS_DBA              FAH_DAY_CBA_BGAAP              Y2016_Q4_M12_D13                   1811 ADS_ARCHIVE&lt;br /&gt;
ADS_DBA              FAH_DAY_MVT_IFRS               Y2016_Q4_M10_D10                   1654 ADS_ARCHIVE&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Capture the tablespace metadata====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set long 1000000&lt;br /&gt;
select dbms_metadata.get_ddl ( &amp;#039;TABLESPACE&amp;#039;, &amp;#039;ADS_ARCHIVE&amp;#039;) from dual&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
produces...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
CREATE TABLESPACE &amp;quot;ADS_ARCHIVE&amp;quot; DATAFILE&lt;br /&gt;
  &amp;#039;/oracle/tst/ora_data3/adst/ads_archive01.dbf&amp;#039; SIZE 104857600&lt;br /&gt;
  AUTOEXTEND ON NEXT 104857600 MAXSIZE 32000M,&lt;br /&gt;
...&lt;br /&gt;
  &amp;#039;/oracle/tst/ora_data3/adst/ads_archive66.dbf&amp;#039; SIZE 104857600&lt;br /&gt;
  AUTOEXTEND ON NEXT 104857600 MAXSIZE 3200M,&lt;br /&gt;
  LOGGING ONLINE PERMANENT BLOCKSIZE 8192&lt;br /&gt;
  EXTENT MANAGEMENT LOCAL AUTOALLOCATE DEFAULT&lt;br /&gt;
 NOCOMPRESS  SEGMENT SPACE MANAGEMENT AUTO&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Capture the tablespace objects&amp;#039; metadata====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cat&amp;lt;&amp;lt;EOCAT &amp;gt;expdp_adst_ads_archive_metadata.par&lt;br /&gt;
userid=&amp;#039;/ as sysdba&amp;#039;&lt;br /&gt;
dumpfile=adst_ads_archive_metadata.dmp&lt;br /&gt;
logfile=expdp_adst_ads_archive_metadata.log&lt;br /&gt;
tablespaces=ADS_ARCHIVE&lt;br /&gt;
parallel=20&lt;br /&gt;
content=metadata_only&lt;br /&gt;
exclude=statistics&lt;br /&gt;
EOCAT&lt;br /&gt;
&lt;br /&gt;
expdp parfile=expdp_adst_ads_archive_metadata.par&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Find the partitions with data from the most recent month====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cat &amp;lt;&amp;lt;EOCAT&amp;gt;/tmp/adst_ads_archive_partitions.sql&lt;br /&gt;
set termo off echo off lines 1000 feedb off headi off newpa none trims on&lt;br /&gt;
spool /tmp/adst_ads_archive_partitions.lst&lt;br /&gt;
select table_owner||&amp;#039;.&amp;#039;||table_name||&amp;#039;:&amp;#039;||partition_name&lt;br /&gt;
from   dba_tab_partitions&lt;br /&gt;
where  tablespace_name = &amp;#039;ADS_ARCHIVE&amp;#039;&lt;br /&gt;
and    partition_name like &amp;#039;Y2017_Q1_M01%&amp;#039;&lt;br /&gt;
/&lt;br /&gt;
spool off&lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;@/tmp/adst_ads_archive_partitions.sql&amp;quot; | sqlplus / as sysdba&lt;br /&gt;
EOCAT&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
produces...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_CBA_BGAAP_ARC:Y2017_Q1_M01_D07&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_IFRS_ARC:Y2017_Q1_M02_D26&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_IFRS_ARC:Y2017_Q1_M02_D25&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_IFRS_ARC:Y2017_Q1_M02_D19&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_IFRS_ARC:Y2017_Q1_M02_D18&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_IFRS_ARC:Y2017_Q1_M02_D12&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_IFRS_ARC:Y2017_Q1_M02_D11&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_IFRS_ARC:Y2017_Q1_M02_D05&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_BGAAP_ARC:Y2017_Q1_M02_D26&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_BGAAP_ARC:Y2017_Q1_M02_D25&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_BGAAP_ARC:Y2017_Q1_M02_D19&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_BGAAP_ARC:Y2017_Q1_M02_D18&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_BGAAP_ARC:Y2017_Q1_M02_D12&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_BGAAP_ARC:Y2017_Q1_M02_D11&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_BGAAP_ARC:Y2017_Q1_M02_D05&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_BGAAP_ARC:Y2017_Q1_M02_D04&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_BGAAP_ARC:Y2017_Q1_M01_D29&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_BGAAP_ARC:Y2017_Q1_M01_D28&lt;br /&gt;
...&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_BGAAP_ARC:Y2017_Q1_M01_D22&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_BGAAP_ARC:Y2017_Q1_M01_D21&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_BGAAP_ARC:Y2017_Q1_M01_D15&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_BGAAP_ARC:Y2017_Q1_M01_D14&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_BGAAP_ARC:Y2017_Q1_M01_D08&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_BGAAP_ARC:Y2017_Q1_M01_D07&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_BGAAP_ARC:Y2017_Q1_M01_D01&lt;br /&gt;
ADS_ARCHIVE.BIL_MTH_INV_CTR_ARC:Y2017_Q1_M01_D01&lt;br /&gt;
ADS_ARCHIVE.BIL_DAY_INV_CTR_ARC:Y2017_Q1_M01_D01&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_IFRS_ARC:Y2017_Q1_M02_D04&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_IFRS_ARC:Y2017_Q1_M01_D29&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_IFRS_ARC:Y2017_Q1_M01_D28&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_IFRS_ARC:Y2017_Q1_M01_D22&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Export the data in these partitions====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cat&amp;lt;&amp;lt;EOCAT &amp;gt;expdp_adst_ads_archive_partitions.par&lt;br /&gt;
userid=&amp;#039;/ as sysdba&amp;#039;&lt;br /&gt;
dumpfile=adst_ads_archive_Y2017_%U.dmp&lt;br /&gt;
logfile=expdp_adst_ads_archive_Y2017.log&lt;br /&gt;
EOCAT&lt;br /&gt;
&lt;br /&gt;
cat /tmp/adst_ads_archive_partitions.lst | perl -p -i -e &amp;#039;s/^/tables=/&amp;#039;g &amp;gt;&amp;gt;expdp_adst_ads_archive_partitions.par&lt;br /&gt;
&lt;br /&gt;
cat&amp;lt;&amp;lt;EOCAT &amp;gt;&amp;gt;expdp_adst_ads_archive_partitions.par&lt;br /&gt;
parallel=20&lt;br /&gt;
exclude=statistics&lt;br /&gt;
EOCAT&lt;br /&gt;
&lt;br /&gt;
expdp parfile=expdp_adst_ads_archive_partitions.par&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Drop the old tablespace====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
drop tablespace ads_archive including contents and datafiles&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Recreate the tablepspace using the metadata capture above====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
create tablespace &amp;quot;ADS_ARCHIVE&amp;quot;&lt;br /&gt;
datafile &amp;#039;/oracle/tst/ora_data3/adst/ads_archive01.dbf&amp;#039; size 100M autoextend on next 50M maxsize unlimited&lt;br /&gt;
,        &amp;#039;/oracle/tst/ora_data3/adst/ads_archive02.dbf&amp;#039; size 100M autoextend on next 50M maxsize unlimited&lt;br /&gt;
,        &amp;#039;/oracle/tst/ora_data3/adst/ads_archive03.dbf&amp;#039; size 100M autoextend on next 50M maxsize unlimited&lt;br /&gt;
,        &amp;#039;/oracle/tst/ora_data3/adst/ads_archive04.dbf&amp;#039; size 100M autoextend on next 50M maxsize unlimited&lt;br /&gt;
,        &amp;#039;/oracle/tst/ora_data3/adst/ads_archive05.dbf&amp;#039; size 100M autoextend on next 50M maxsize unlimited&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Import the tablespace metadata====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cat&amp;lt;&amp;lt;EOCAT &amp;gt;impdp_adst_ads_archive_metadata.par&lt;br /&gt;
userid=&amp;#039;/ as sysdba&amp;#039;&lt;br /&gt;
dumpfile=adst_ads_archive_metadata.dmp&lt;br /&gt;
logfile=impdp_adst_ads_archive_metadata.log&lt;br /&gt;
EOCAT&lt;br /&gt;
&lt;br /&gt;
impdp parfile=impdp_adst_ads_archive_metadata.par&lt;br /&gt;
&lt;br /&gt;
select &amp;#039;alter index &amp;#039;|| owner||&amp;#039;.&amp;#039;||index_name||&amp;#039; rebuild online parallel 8;&amp;#039;&lt;br /&gt;
from   dba_indexes&lt;br /&gt;
where  status = &amp;#039;UNUSABLE&amp;#039;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Import the last month partition data====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cat&amp;lt;&amp;lt;EOCAT &amp;gt;impdp_adst_ads_archive_partitions.par&lt;br /&gt;
userid=&amp;#039;/ as sysdba&amp;#039;&lt;br /&gt;
dumpfile=adst_ads_archive_Y2017_%U.dmp&lt;br /&gt;
logfile=impdp_adst_ads_archive_Y2017.log&lt;br /&gt;
table_exists_action=append&lt;br /&gt;
parallel=20&lt;br /&gt;
EOCAT&lt;br /&gt;
&lt;br /&gt;
impdp parfile=impdp_adst_ads_archive_partitions.par&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Write to a TCP/IP socket from PL/SQL===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
declare&lt;br /&gt;
 bt_conn               utl_tcp.connection;&lt;br /&gt;
 retval                binary_integer;&lt;br /&gt;
 l_sequence            varchar2(30) := &amp;#039;Sequence Number 101021&amp;#039;;&lt;br /&gt;
begin&lt;br /&gt;
 bt_conn := utl_tcp.open_connection(remote_host =&amp;gt; &amp;#039;10.10.1.1&amp;#039;&lt;br /&gt;
                                   ,remote_port =&amp;gt; 5000&lt;br /&gt;
                                   ,tx_timeout =&amp;gt; 1&lt;br /&gt;
                                   )&lt;br /&gt;
 ;&lt;br /&gt;
 retval := utl_tcp.write_line(bt_conn,l_sequence)&lt;br /&gt;
 ;&lt;br /&gt;
 utl_tcp.flush(bt_conn)&lt;br /&gt;
 ;&lt;br /&gt;
 utl_tcp.close_connection(bt_conn)&lt;br /&gt;
 ;&lt;br /&gt;
exception&lt;br /&gt;
 when others then&lt;br /&gt;
  raise_application_error(-20101, sqlerrm)&lt;br /&gt;
  ; &lt;br /&gt;
  utl_tcp.close_connection(bt_conn)&lt;br /&gt;
  ;&lt;br /&gt;
end&lt;br /&gt;
;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
and read from it using netcat in another session&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
nc -lk 5000&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
produces&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Sequence Number 101021&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Execute a script as a different user===&lt;br /&gt;
Some things have to be done as the user and cannot be done as sys (eg. creating and dropping jobs or create and drop a database link)&amp;lt;br /&amp;gt;&lt;br /&gt;
It is possible to login as the user by saving, changing and resetting his password (using identified by values) but using dbms_sys_sql is another option&amp;lt;br /&amp;gt;&lt;br /&gt;
Create a PL/SQL procedure to drop a db link&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
create or replace procedure drop_dblink ( p_schema_name in varchar2&lt;br /&gt;
                                        , p_dblink      in varchar2&lt;br /&gt;
                                        ) is&lt;br /&gt;
    l_plsql   varchar2(1000);&lt;br /&gt;
    l_cur     number;&lt;br /&gt;
    l_uid     number;&lt;br /&gt;
    l_rc      number;&lt;br /&gt;
begin&lt;br /&gt;
    select  du.user_id&lt;br /&gt;
    into    l_uid&lt;br /&gt;
    from    dba_users du&lt;br /&gt;
    where   du.username = p_schema_name&lt;br /&gt;
    ;&lt;br /&gt;
    plsql := &amp;#039;drop database link &amp;quot;&amp;#039;||p_dblink||&amp;#039;&amp;quot;&amp;#039;;&lt;br /&gt;
    l_cur := sys.dbms_sys_sql.open_cursor;&lt;br /&gt;
    sys.dbms_sys_sql.parse_as_user(&lt;br /&gt;
        c             =&amp;gt; l_cur,&lt;br /&gt;
        statement     =&amp;gt; l_plsql,&lt;br /&gt;
        language_flag =&amp;gt; dbms_sql.native,&lt;br /&gt;
        userid        =&amp;gt; l_uid&lt;br /&gt;
    );&lt;br /&gt;
    l_rc := sys.dbms_sys_sql.execute(l_cur);&lt;br /&gt;
    sys.dbms_sys_sql.close_cursor(l_cur);&lt;br /&gt;
end;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Generate the calls to the procedure with the required parameters&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select &amp;#039;exec drop_dblink (&amp;#039;&amp;#039;&amp;#039;|| owner ||&amp;#039;&amp;#039;&amp;#039;&amp;#039;||&amp;#039;, &amp;#039;||&amp;#039;&amp;#039;&amp;#039;&amp;#039;||db_link||&amp;#039;&amp;#039;&amp;#039;&amp;#039;||&amp;#039;);&amp;#039;&lt;br /&gt;
from   dba_db_links&lt;br /&gt;
where  owner   != &amp;#039;PUBLIC&amp;#039;&lt;br /&gt;
and    db_link like &amp;#039;%FTST%&amp;#039;&lt;br /&gt;
or     db_link like &amp;#039;%HDEV%&amp;#039;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
and this reveals the lines to be executed&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
exec drop_dblink (&amp;#039;USER1&amp;#039;, &amp;#039;DBL_FTST.WORLD&amp;#039;);&lt;br /&gt;
exec drop_dblink (&amp;#039;USER1&amp;#039;, &amp;#039;DBL_HDEV.WORLD&amp;#039;);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Drop the procedure when finished with it&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
drop procedure drop_dblink;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
or do it as an anonymous block in one go...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
declare&lt;br /&gt;
    uid number;&lt;br /&gt;
    sqltext varchar2(1000) := &amp;#039;drop database link &amp;quot;&amp;amp;DB_LINK&amp;quot;&amp;#039;;&lt;br /&gt;
    myint integer;&lt;br /&gt;
begin&lt;br /&gt;
    select user_id into uid from dba_users where username = &amp;#039;&amp;amp;USERNAME&amp;#039;;&lt;br /&gt;
    myint:=sys.dbms_sys_sql.open_cursor();&lt;br /&gt;
    sys.dbms_sys_sql.parse_as_user(myint,sqltext,dbms_sql.native,UID);&lt;br /&gt;
    sys.dbms_sys_sql.close_cursor(myint);&lt;br /&gt;
end;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Handling single quote marks inside SQL statements===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SQL&amp;gt; SELECT &amp;#039;D&amp;#039;&amp;#039;COSTA&amp;#039; name FROM DUAL;&lt;br /&gt;
&lt;br /&gt;
NAME&lt;br /&gt;
-------&lt;br /&gt;
D&amp;#039;COSTA&lt;br /&gt;
&lt;br /&gt;
Alternatively, use the 10g+ quoting method:&lt;br /&gt;
&lt;br /&gt;
SQL&amp;gt; SELECT q&amp;#039;$D&amp;#039;COSTA$&amp;#039; NAME FROM DUAL;&lt;br /&gt;
&lt;br /&gt;
NAME&lt;br /&gt;
-------&lt;br /&gt;
D&amp;#039;COSTA&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Run a script on all databases in /etc/oratab===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
export ORAENV_ASK=NO&lt;br /&gt;
for db in `awk -F: &amp;#039;NF &amp;amp;&amp;amp; $1 !~/[#*]/ {print $1}&amp;#039;  /etc/oratab`&lt;br /&gt;
do&lt;br /&gt;
    echo $db&lt;br /&gt;
    ORACLE_SID=$db&lt;br /&gt;
    . oraenv&lt;br /&gt;
    sqlplus -V&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Schedule a cron job to run on the last day of each month===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
0 23 28-31 * * [ $(date -d +1day +%d) -eq 1 ] &amp;amp;&amp;amp; su - oracle -c &amp;quot;dsmc  arch -server=SO_U_`hostname`_ORX_M_SOL &amp;#039;/oracle/export/PV6/expdp_PV6_D_FULL_`date +\%Y\%m\%d`*&amp;#039;&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===How to tell if a year is a leap year or not - using cal instead of reinventing the wheel===&lt;br /&gt;
Test: Why is Julian day 0, 17th November 1858?&amp;lt;br /&amp;gt;&lt;br /&gt;
Pretty comprehensive answer: [http://h71000.www7.hp.com/wizard/wiz_2315.html here] and [http://mentalfloss.com/article/51370/why-our-calendars-skipped-11-days-1752 here]&amp;lt;br /&amp;gt;&lt;br /&gt;
Also attempts to answer the question why typing &amp;#039;cal 09 1752&amp;#039; on Unix systems looks so odd!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
function leap {&lt;br /&gt;
#  This function tells you if the year passed in as a parameter is a leap year or not...&lt;br /&gt;
if [[ $(cal 2 ${1:-$(date &amp;#039;+%Y&amp;#039;)} | egrep &amp;#039;\&amp;lt;[[:digit:]]{1,2}\&amp;gt;&amp;#039; | wc -w) -eq 29 ]]; then&lt;br /&gt;
    leap=&amp;#039;Y&amp;#039;&lt;br /&gt;
else&lt;br /&gt;
    leap=&amp;#039;N&amp;#039;&lt;br /&gt;
fi&lt;br /&gt;
echo ${leap}&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Reset an expired (and/or locked) user password to the same value===&lt;br /&gt;
Can be used to save user passwords for example in a test environment before destroying them with a copy of production.&amp;lt;br /&amp;gt;&lt;br /&gt;
Simple, quick and easy version. Run this then pick and choose the statements you want to run.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 200 pages 200&lt;br /&gt;
col user_list for a200 head &amp;quot;Expired User List&amp;quot;&lt;br /&gt;
&lt;br /&gt;
select &amp;#039;alter user &amp;#039; ||su.name||&amp;#039; identified by values&amp;#039;||&amp;#039;&amp;#039;&amp;#039;&amp;#039;||spare4||&amp;#039;;&amp;#039;||su.password||&amp;#039;&amp;#039;&amp;#039; account unlock;&amp;#039; user_list&lt;br /&gt;
from   sys.user$ su&lt;br /&gt;
,      dba_users du&lt;br /&gt;
where  1=1&lt;br /&gt;
and    su.name              = du.username&lt;br /&gt;
and    du.oracle_maintained = &amp;#039;N&amp;#039;&lt;br /&gt;
and    (account_status      like &amp;#039;EXPIRED%&amp;#039; or account_status like &amp;#039;%LOCKED&amp;#039;)&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
More industrialised version. Create a package.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
create or replace package dba_utils&lt;br /&gt;
as&lt;br /&gt;
    procedure reset_password ( p_userlist in varchar2 );&lt;br /&gt;
end dba_utils;&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
create or replace package body dba_utils&lt;br /&gt;
as&lt;br /&gt;
&lt;br /&gt;
procedure reset_password ( p_userlist in varchar2 )&lt;br /&gt;
is&lt;br /&gt;
    cursor c1 ( p_userlist in varchar2 ) is&lt;br /&gt;
    select username&lt;br /&gt;
    ,      regexp_substr ( dbms_metadata.get_ddl(&amp;#039;USER&amp;#039;, username), &amp;#039;&amp;#039;&amp;#039;[^&amp;#039;&amp;#039;]+&amp;#039;&amp;#039;&amp;#039; ) pwd&lt;br /&gt;
    from   dba_users&lt;br /&gt;
    where  1=1&lt;br /&gt;
    and    username in upper( p_userlist )&lt;br /&gt;
    ;&lt;br /&gt;
begin&lt;br /&gt;
    dbms_output.enable(null);&lt;br /&gt;
    for r1 in c1 ( p_userlist )&lt;br /&gt;
    loop&lt;br /&gt;
        begin&lt;br /&gt;
            execute immediate &amp;#039;alter user &amp;#039; || r1.username || &amp;#039; account unlock&amp;#039;;&lt;br /&gt;
            execute immediate &amp;#039;alter user &amp;#039; || r1.username || &amp;#039; identified by values &amp;#039; || r1.pwd;&lt;br /&gt;
        exception&lt;br /&gt;
        when others then&lt;br /&gt;
            dbms_output.put_line(&amp;#039;Unable to modify user &amp;#039; || r1.username);&lt;br /&gt;
        end;&lt;br /&gt;
    end loop;&lt;br /&gt;
end reset_password;&lt;br /&gt;
&lt;br /&gt;
end dba_utils;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Call it&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set serveroutput on&lt;br /&gt;
exec dba_utils.reset_password (&amp;#039;STUART&amp;#039;);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Latch, mutex and beyond===&lt;br /&gt;
A fine example of how to write scripts from SQL*Plus that interact with the shell underneath&amp;lt;br /&amp;gt;&lt;br /&gt;
Found [https://andreynikolaev.wordpress.com/demonstration-scripts/cursor_pin_s_contention-sql/ here at andreynikolaev.wordpress.com]&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/*&lt;br /&gt;
     This file is part of demos for &amp;quot;Mutex Internals&amp;quot;  seminar v.04.04.2011&lt;br /&gt;
     Andrey S. Nikolaev (Andrey.Nikolaev@rdtex.ru) &lt;br /&gt;
     https://andreynikolaev.wordpress.com &lt;br /&gt;
 &lt;br /&gt;
     &amp;quot;Cursor: pin S&amp;quot; contention testcase.&lt;br /&gt;
 &lt;br /&gt;
     The script spawn several sessions to induce &amp;quot;Cursor: pin S&amp;quot;, &lt;br /&gt;
     creates AWR snapshots and generates AWR report&lt;br /&gt;
 &lt;br /&gt;
     Beware: The script will restart the test database.&lt;br /&gt;
 &lt;br /&gt;
     usage: sqlplus /nolog @cursor_pin_s_contention.sql &amp;lt;parallelism&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
*/ &lt;br /&gt;
connect / as sysdba&lt;br /&gt;
startup force&lt;br /&gt;
set echo off&lt;br /&gt;
set define %&lt;br /&gt;
set verify off&lt;br /&gt;
set head off&lt;br /&gt;
set linesize 300&lt;br /&gt;
 &lt;br /&gt;
/* spawn parallel processes to create load on mutex */&lt;br /&gt;
spool one_thread.tmp&lt;br /&gt;
select &amp;#039;set verify off&amp;#039; from dual;&lt;br /&gt;
select &amp;#039;alter session set session_cached_cursors = 50;&amp;#039; from dual; &lt;br /&gt;
select &amp;#039;begin for i in 1..1000000 loop&amp;#039; from dual;&lt;br /&gt;
select &amp;#039;      execute immediate &amp;#039;&amp;#039;select 1 from dual where 1=2&amp;#039;&amp;#039;;&amp;#039; from dual;&lt;br /&gt;
select &amp;#039;end loop; end;&amp;#039;||chr(10)||&amp;#039;/&amp;#039; from dual;&lt;br /&gt;
spool off&lt;br /&gt;
 &lt;br /&gt;
/* sleep while AWR initialized */&lt;br /&gt;
host sleep 5&lt;br /&gt;
 &lt;br /&gt;
exec dbms_workload_repository.create_snapshot();&lt;br /&gt;
 &lt;br /&gt;
spool many_threads.tmp&lt;br /&gt;
select &amp;#039;host sqlplus &amp;quot;/ as sysdba&amp;quot; @one_thread.tmp &amp;amp;&amp;#039;&lt;br /&gt;
from dba_objects where rownum &amp;lt;= %1;&lt;br /&gt;
spool off&lt;br /&gt;
 &lt;br /&gt;
@many_threads.tmp&lt;br /&gt;
host sleep 50&lt;br /&gt;
set echo on&lt;br /&gt;
exec dbms_workload_repository.create_snapshot();&lt;br /&gt;
set markup html on&lt;br /&gt;
set head on&lt;br /&gt;
spool mutex_sleep_history.htm&lt;br /&gt;
select to_char(SLEEP_TIMESTAMP,&amp;#039;hh:mi:ss.ff&amp;#039;) SLEEP_TIMESTAMP,MUTEX_ADDR,MUTEX_IDENTIFIER,MUTEX_TYPE,&lt;br /&gt;
       GETS,SLEEPS,REQUESTING_SESSION,BLOCKING_SESSION,&lt;br /&gt;
       LOCATION,MUTEX_VALUE from x$mutex_sleep_history order by sleep_timestamp;&lt;br /&gt;
spool off&lt;br /&gt;
 &lt;br /&gt;
set define &amp;amp;&lt;br /&gt;
set markup html off&lt;br /&gt;
set echo off heading on underline on;&lt;br /&gt;
column inst_num  heading &amp;quot;Inst Num&amp;quot;  new_value inst_num  format 99999;&lt;br /&gt;
column inst_name heading &amp;quot;Instance&amp;quot;  new_value inst_name format a12;&lt;br /&gt;
column db_name   heading &amp;quot;DB Name&amp;quot;   new_value db_name   format a12;&lt;br /&gt;
column dbid      heading &amp;quot;DB Id&amp;quot;     new_value dbid      format 9999999999 just c;&lt;br /&gt;
select d.dbid            dbid&lt;br /&gt;
     , d.name            db_name&lt;br /&gt;
     , i.instance_number inst_num&lt;br /&gt;
     , i.instance_name   inst_name&lt;br /&gt;
  from v$database d,&lt;br /&gt;
       v$instance i;&lt;br /&gt;
define num_days=1;&lt;br /&gt;
define report_type=&amp;#039;html&amp;#039;;&lt;br /&gt;
col end_snap new_value end_snap;&lt;br /&gt;
col begin_snap new_value begin_snap;&lt;br /&gt;
select max(snap_id) end_snap from dba_hist_snapshot where dbid=&amp;amp;dbid;&lt;br /&gt;
select max(snap_id) begin_snap from dba_hist_snapshot where dbid=&amp;amp;dbid and snap_id &amp;lt; &amp;amp;end_snap;&lt;br /&gt;
define report_name=&amp;#039;awr_report.htm&amp;#039;;&lt;br /&gt;
@?/rdbms/admin/awrrpti&lt;br /&gt;
exit&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==shell==&lt;br /&gt;
[http://www.databasejournal.com/features/oracle/article.php/3869076/Alert-Log-Scraping-with-Oracles-ADRCI-Utility.htm Alert Log scraping with ADRCI]&lt;br /&gt;
&lt;br /&gt;
====Count the number of background processes for a particular SID====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SID=RAVJDE1&lt;br /&gt;
ps -ef|cut -c54-100|awk -v SID=$SID &amp;#039;$0 ~ /&amp;#039;$SID&amp;#039;$/ {print}&amp;#039;|wc -l&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or ...this will work with any OS (so long as the process is at the end of the &amp;lt;strong&amp;gt;ps -ef&amp;lt;/strong&amp;gt; or &amp;lt;strong&amp;gt;ps -aux&amp;lt;/strong&amp;gt; listing&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SID=RAVJDE1&lt;br /&gt;
ps -ef|awk -v SID=$SID -F_ &amp;#039;{ $NF ~ /&amp;#039;$SID&amp;#039;$/ {print} }&amp;#039;|wc -l&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Pick the columns you want in the ps listing&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ps -efo user,pid,ppid=MOM -o args&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Find Oracle errors in the most recent DataPump log files====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
00 09 * * * /home/tools/scripts/oracle/dosh &amp;#039;find /oracle/export -name &amp;quot;expdp*log&amp;quot; -mtime -1 -exec grep ORA- {} \; -ls&amp;#039; | mailx -s &amp;#039;Datapump errors for &amp;lt;customer&amp;gt;last night&amp;#039; stuart@domain.com&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Find the 10 largest directories on a particular filesystem====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
du -ag /oracle | sort -nr | head -n 10&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Find the 10 largest files on a particular mount point====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
find /home -size +1G -ls | sort -nr +6 | head -10&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
find /home -xdev -ls | sort -nr +6 | head -10&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Split a file in pieces using sed====&lt;br /&gt;
Using fixed line numbers&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sed -ne &amp;#039;1,12p&amp;#039; file &amp;gt; text.part1&lt;br /&gt;
sed -ne &amp;#039;13,$p&amp;#039; file &amp;gt; text.part2&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Using line with a /pattern/ on it&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sed -e &amp;#039;/hello/q&amp;#039; tt.dat | grep -v hello &amp;gt; text.part1&lt;br /&gt;
sed -n `sed -n &amp;#039;/hello/=&amp;#039; tt.dat`&amp;#039;,$p&amp;#039; tt.dat | grep -v hello &amp;gt; text.part2&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Split a file in pieces using Perl====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
perl -ne &amp;#039;print if 1 .. /marker line/&amp;#039; text.dat &amp;gt;text.part1&lt;br /&gt;
perl -ne &amp;#039;print if /marker line/ .. eof()&amp;#039; text.dat &amp;gt;text.part2&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Find and display RMAN errors in an RMAN log file====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sed -ne &amp;#039;/^RMAN-/,/^$/p&amp;#039;  RMAN_&amp;lt;SID&amp;gt;_&amp;lt;DATE&amp;gt;.log&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==cmd==&lt;br /&gt;
*[http://www.dba-oracle.com/t_scripts_windows_export.htm Database Export - from DBA Oracle (Burleson)]&lt;br /&gt;
==Perl==&lt;br /&gt;
===For all files in a directory, replace a keyword (SSIIDD) in a file with another (a parameter)===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
for i in `ls`&lt;br /&gt;
do&lt;br /&gt;
    perl -p -i -e &amp;#039;s/SSIIDD/&amp;#039;$SID&amp;#039;/g&amp;#039; $i&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Parse tnsnames.ora to get just the service names===&lt;br /&gt;
[[http://stackoverflow.com/questions/12605415/parsing-tnsnames-ora-with-regex-to-just-get-name from here]]&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
perl -ne &amp;#039;print if m/^([^#()\W ][a-zA-Z.]*(?:[.][a-zA-Z]*\s?=)?)/&amp;#039; $TNS_ADMIN/tnsnames.ora&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===and use that to check the listener status===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
for svc in `perl -ne &amp;#039;print if m/^([^#()\W ][a-zA-Z.]*(?:[.][a-zA-Z]*\s?=)?)/&amp;#039; $TNS_ADMIN/tnsnames.ora | sed -e &amp;#039;s/=//&amp;#039;` ;do&lt;br /&gt;
    tnsping $svc&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Stuart</name></author>	</entry>

	<entry>
		<id>https://mailnest.com/dbawiki/index.php?title=Handy_scripts&amp;diff=3374</id>
		<title>Handy scripts</title>
		<link rel="alternate" type="text/html" href="https://mailnest.com/dbawiki/index.php?title=Handy_scripts&amp;diff=3374"/>
				<updated>2018-11-21T11:59:45Z</updated>
		
		<summary type="html">&lt;p&gt;Stuart: /* External table for the Alert log (pre 11g) */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==SQL==&lt;br /&gt;
* [[Database Overview - from idevelopment]] [http://www.idevelopment.info/data/Oracle/DBA_scripts/Database_Administration/dba_snapshot_database_10g.sql online version]&lt;br /&gt;
* [[Extract ddl with &amp;quot;dbms metadata.get ddl&amp;quot;]]&lt;br /&gt;
* [http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:83012348058 Connecting as another user via proxy in SQL*Plus]&lt;br /&gt;
* [http://www.petefinnigan.com/tools.htm Password cracker and role and priv tools from Pete Finnigan]&lt;br /&gt;
* [http://www.oracle.com/technetwork/articles/sql/11g-pivot-097235.html Using pivot tables in SQL - XML and XLS (Excel) also)]&lt;br /&gt;
===List all instances running on a server===&lt;br /&gt;
Sounds simple enough and indeed pre 12.1, is was as easy as either&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ps -ef | grep [p]mon | awk -F_ &amp;#039;{print $NF}&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or this one is safer in case you have an underscore character in your SID name!!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SIDLIST=$(${PS} -ef | ${GREP} [o]ra_pmon | ${AWK} &amp;#039;{print $NF}&amp;#039; | sed -e &amp;#039;s/ora_pmon_//&amp;#039; | egrep -v &amp;#039;grep|///|sed|awk|ASM|^$&amp;#039;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
but now we have the added complication of CDB/PDB (container / pluggable databases) so a fair bit more work is needed!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/ksh&lt;br /&gt;
# ==============================================================================&lt;br /&gt;
# Name         : list_server_db&lt;br /&gt;
# Description  : List all running databases found on a server&lt;br /&gt;
#&lt;br /&gt;
# Parameters   : none&lt;br /&gt;
#&lt;br /&gt;
# Notes        : none&lt;br /&gt;
#&lt;br /&gt;
# Modification History&lt;br /&gt;
# ====================&lt;br /&gt;
# When      Who               What&lt;br /&gt;
# ========= ================= ==================================================&lt;br /&gt;
# 21-DEC-16 Stuart Barkley    Created&lt;br /&gt;
# ==============================================================================&lt;br /&gt;
for db in $(ps -ef | grep [p]mon|awk -F_ &amp;#039;{print $NF}&amp;#039;)&lt;br /&gt;
do&lt;br /&gt;
    export ORACLE_SID=${db}&lt;br /&gt;
    ORAENV_ASK=NO&lt;br /&gt;
    . oraenv &amp;gt;/dev/null 2&amp;gt;&amp;amp;1&lt;br /&gt;
    sqlplus -s / as sysdba&amp;lt;&amp;lt;EOSQL&lt;br /&gt;
set serveroutput on feed off pages 0 head off newpa none&lt;br /&gt;
declare&lt;br /&gt;
    e_col_not_found exception;&lt;br /&gt;
    e_not_mounted   exception;&lt;br /&gt;
    pragma          exception_init(e_not_mounted, -01507);&lt;br /&gt;
    pragma          exception_init(e_col_not_found, -904);&lt;br /&gt;
    l_db_name       varchar2(20);&lt;br /&gt;
    l_database_role varchar2(20);&lt;br /&gt;
    l_cdb           varchar2(20);&lt;br /&gt;
    l_status        varchar2(20);&lt;br /&gt;
    type varchar2_tab is table of varchar2(240) index by binary_integer;&lt;br /&gt;
    t_pdbs          varchar2_tab;&lt;br /&gt;
begin&lt;br /&gt;
    begin&lt;br /&gt;
        dbms_output.enable(null);&lt;br /&gt;
        execute immediate &amp;#039;select name, database_role, cdb from v\$database&amp;#039; into l_db_name, l_database_role, l_cdb;&lt;br /&gt;
        if l_cdb = &amp;#039;YES&amp;#039; then&lt;br /&gt;
            l_status := &amp;#039;CDB&amp;#039;;&lt;br /&gt;
            execute immediate &amp;#039;select name from v\$pdbs&amp;#039; bulk collect into t_pdbs;&lt;br /&gt;
            for i in nvl(t_pdbs.first,1) .. nvl(t_pdbs.last,0)&lt;br /&gt;
            loop&lt;br /&gt;
                dbms_output.put_line (t_pdbs(i)||&amp;#039;:PDB&amp;#039;);&lt;br /&gt;
            end loop;&lt;br /&gt;
        else&lt;br /&gt;
            l_status := &amp;#039;Independent&amp;#039;;  -- col CDB exists but this is not one&lt;br /&gt;
        end if;&lt;br /&gt;
        if l_database_role like &amp;#039;%STANDBY%&amp;#039; then&lt;br /&gt;
            l_status := &amp;#039;Standby&amp;#039;;&lt;br /&gt;
        end if;&lt;br /&gt;
    exception&lt;br /&gt;
    when e_not_mounted then&lt;br /&gt;
        l_status := &amp;#039;Not Mounted&amp;#039;;&lt;br /&gt;
    when e_col_not_found then&lt;br /&gt;
        l_status := &amp;#039;pre12&amp;#039;;&lt;br /&gt;
    end;&lt;br /&gt;
&lt;br /&gt;
    dbms_output.put_line (&amp;#039;${db}&amp;#039;||&amp;#039;:&amp;#039;||l_status);&lt;br /&gt;
&lt;br /&gt;
end;&lt;br /&gt;
/&lt;br /&gt;
EOSQL&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Run a command or script on all databases in tnsnames.ora===&lt;br /&gt;
Very handy if you have a global tnsnames.ora accessible to all clients.&amp;lt;br /&amp;gt;&lt;br /&gt;
So from a client install, this has access to all databases.&amp;lt;br /&amp;gt;&lt;br /&gt;
Any files created can be created on the client so no need to scp to all the machines to recover spool files etc.&amp;lt;br /&amp;gt;&lt;br /&gt;
Downside: Cannot connect as sysdba across tns so password will need to be known for whatever user is used.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/ksh&lt;br /&gt;
TNSNAMES=&amp;quot;./tnsnames.ora&amp;quot;&lt;br /&gt;
[[ ! -r &amp;quot;${TNSNAMES}&amp;quot; ]] &amp;amp;&amp;amp; echo &amp;quot;${TNSNAMES} is not accessible&amp;quot; &amp;amp;&amp;amp; exit 1&lt;br /&gt;
&lt;br /&gt;
SIDLIST=$(perl -ne &amp;#039;print &amp;quot;$1\n&amp;quot; if /(?:SID|SERVICE_NAME)\s*=\s*(\S+?)\)/&amp;#039; ${TNSNAMES}|sort|uniq|xargs)&lt;br /&gt;
for SID in ${SIDLIST}&lt;br /&gt;
do&lt;br /&gt;
    echo &amp;quot;Processing $SID&amp;quot;&lt;br /&gt;
    ls -al | grep &amp;quot;^d&amp;quot; | grep &amp;quot;\_${SID}&amp;quot; &amp;gt;/dev/null&lt;br /&gt;
    if [[ $? -ne 0 ]]; then&lt;br /&gt;
        echo &amp;#039;exit&amp;#039; | sqlplus system/xxxxxx@${SID} @ReviewLite17.1.sql &amp;gt;/dev/null 2&amp;gt;&amp;amp;1&lt;br /&gt;
    else&lt;br /&gt;
        echo &amp;quot;directory already exists so must have done this SID&amp;quot;&lt;br /&gt;
    fi&lt;br /&gt;
done&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Run a command or script on all databases in oratab===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/usr/bin/ksh&lt;br /&gt;
# ==============================================================================&lt;br /&gt;
# Name         : all_db_do&lt;br /&gt;
# Description  : Loops over all the databases in oratab and executes the&lt;br /&gt;
#                specified SQL command - be careful!&lt;br /&gt;
#&lt;br /&gt;
# Parameters   : -v flag for verbose&lt;br /&gt;
#                [-f &amp;lt;filename&amp;gt; | &amp;lt;quoted SQL command to be executed&amp;gt;]&lt;br /&gt;
#&lt;br /&gt;
# Example      : all_db_do &amp;#039;alter system switch logfile;&amp;#039;&lt;br /&gt;
#                all_db_do -f sessions.sql&lt;br /&gt;
#&lt;br /&gt;
# Notes        : none&lt;br /&gt;
#&lt;br /&gt;
# Modification History&lt;br /&gt;
# ====================&lt;br /&gt;
# When      Who               What&lt;br /&gt;
# ========= ================= ==================================================&lt;br /&gt;
# 14-JAN-13 Stuart Barkley    Created&lt;br /&gt;
# 25-FEB-13 Stuart Barkley    Adapt for Solaris&lt;br /&gt;
# 21-MAR-13 Stuart Barkley    Check db is running first&lt;br /&gt;
# 29-APR-13 Stuart Barkley    Added verbose flag processing&lt;br /&gt;
# 24-MAY-13 Stuart Barkley    Wrap / as sysdba in quotes for older versions&lt;br /&gt;
# 23-JUN-16 Stuart Barkley    Add -f to run a file containing sql&lt;br /&gt;
# ==============================================================================&lt;br /&gt;
&lt;br /&gt;
PROGNAME=$(basename $0)&lt;br /&gt;
OS=$(uname -s)&lt;br /&gt;
&lt;br /&gt;
AWK=$(which awk)&lt;br /&gt;
GREP=$(which grep)&lt;br /&gt;
if [[ &amp;quot;${OS}&amp;quot; == &amp;quot;SunOS&amp;quot; ]]; then&lt;br /&gt;
    AWK=/usr/xpg4/bin/awk&lt;br /&gt;
    GREP=/usr/xpg4/bin/grep&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
if [[ ! -r /etc/oratab ]]; then&lt;br /&gt;
    if [[ &amp;quot;${OS}&amp;quot; == &amp;quot;SunOS&amp;quot; ]]; then&lt;br /&gt;
        echo &amp;quot;oratab is not where we want it. Please run &amp;#039;ln -s /var/opt/oracle/oratab /etc/oratab&amp;#039; as root and retry&amp;quot; &amp;amp;&amp;amp; exit 1&lt;br /&gt;
    else&lt;br /&gt;
        echo &amp;quot;Either Oracle is not installed or database is running without an oratab&amp;quot; &amp;amp;&amp;amp; exit 1&lt;br /&gt;
    fi&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
# -------------------------&lt;br /&gt;
# get the arguments, if any&lt;br /&gt;
# -------------------------&lt;br /&gt;
unset VERBOSE&lt;br /&gt;
while getopts &amp;quot;vf:&amp;quot; flag&lt;br /&gt;
do&lt;br /&gt;
    case &amp;quot;$flag&amp;quot; in&lt;br /&gt;
    v) VERBOSE=1;;&lt;br /&gt;
    f) FILE2RUN=$OPTARG;;&lt;br /&gt;
    esac&lt;br /&gt;
done&lt;br /&gt;
shift $((OPTIND-1))&lt;br /&gt;
&lt;br /&gt;
if [[ -z ${FILE2RUN} ]]; then&lt;br /&gt;
    # no file, need an SQL supplied&lt;br /&gt;
    if [[ -z $1 ]]; then&lt;br /&gt;
        echo &amp;quot;Usage: $0 [-v] [-f &amp;lt;filename&amp;gt; | &amp;lt;quoted SQL command to be executed&amp;gt;]&amp;quot;&lt;br /&gt;
        echo &amp;quot;eg: $0 -f sessions.sql&amp;quot;&lt;br /&gt;
        echo &amp;quot;eg: $0 &amp;#039;alter system switch logfile;&amp;#039;&amp;quot;&lt;br /&gt;
        exit 1&lt;br /&gt;
    fi&lt;br /&gt;
    SQL=$1&lt;br /&gt;
elif [[ -s ${FILE2RUN} ]]; then&lt;br /&gt;
    # file supplied and exists&lt;br /&gt;
    SQL=&amp;quot;@${FILE2RUN}&amp;quot;&lt;br /&gt;
else&lt;br /&gt;
    # file supplied, does it exist&lt;br /&gt;
    echo &amp;quot;File ${FILE2RUN} is empty or does not exist&amp;quot;&lt;br /&gt;
    echo &amp;quot;Usage: $0 [-v] [-f &amp;lt;filename&amp;gt; | &amp;lt;quoted SQL command to be executed&amp;gt;]&amp;quot;&lt;br /&gt;
    echo &amp;quot;eg: $0 -f sessions.sql&amp;quot;&lt;br /&gt;
    echo &amp;quot;eg: $0 &amp;#039;alter system switch logfile;&amp;#039;&amp;quot;&lt;br /&gt;
    exit 1&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
export ORAENV_ASK=NO&lt;br /&gt;
&lt;br /&gt;
for db in $(${AWK} -F: &amp;#039;NF &amp;amp;&amp;amp; $1 !~/[#*]/ {print $1}&amp;#039;  /etc/oratab)&lt;br /&gt;
do&lt;br /&gt;
    if ( [[ $1 != &amp;quot;startup&amp;quot; ]] &amp;amp;&amp;amp; [[ $(ps -ef | ${GREP} -c -E [o]ra_pmon_${db}) -eq 0 ]] ); then&lt;br /&gt;
        [[ ! -z &amp;quot;$VERBOSE&amp;quot; ]] &amp;amp;&amp;amp; echo &amp;quot;$db is not running, skipping...&amp;quot;&lt;br /&gt;
        continue&lt;br /&gt;
    fi&lt;br /&gt;
    echo&lt;br /&gt;
    [[ ! -z &amp;quot;$VERBOSE&amp;quot; ]] &amp;amp;&amp;amp; echo &amp;quot;vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv&amp;quot;&lt;br /&gt;
    [[ ! -z &amp;quot;$VERBOSE&amp;quot; ]] &amp;amp;&amp;amp; echo $db&lt;br /&gt;
    ORACLE_SID=$db&lt;br /&gt;
    . oraenv &amp;gt;/dev/null&lt;br /&gt;
    sqlplus -s &amp;quot;/ as sysdba&amp;quot; &amp;lt;&amp;lt;EOSQL&lt;br /&gt;
define SID=$ORACLE_SID&lt;br /&gt;
col comp_name format a50&lt;br /&gt;
col value for a40&lt;br /&gt;
set linesize 1000&lt;br /&gt;
set pagesize 100&lt;br /&gt;
$SQL&lt;br /&gt;
EOSQL&lt;br /&gt;
    [[ ! -z &amp;quot;$VERBOSE&amp;quot; ]] &amp;amp;&amp;amp; echo &amp;quot;^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^&amp;quot;&lt;br /&gt;
done&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
all_db_do &amp;quot;create or replace directory data_pump_dir as &amp;#039;/oracle/export/&amp;amp;SID&amp;#039;;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
all_db_do &amp;quot;archive log list&amp;quot;&lt;br /&gt;
&lt;br /&gt;
all_db_do &amp;quot;shutdown immediate&amp;quot;&lt;br /&gt;
&lt;br /&gt;
all_db_do &amp;#039;alter system set log_archive_dest_1=&amp;quot;location=/oracle/arch/&amp;amp;SID&amp;quot; scope=both;&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Run an SQL command on behalf of another user===&lt;br /&gt;
It can be used to execute any sql command as a specified user provided this procedure is created in sys schema.&amp;lt;br /&amp;gt;&lt;br /&gt;
* not got this working properly yet *&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set serveroutput on&lt;br /&gt;
create or replace procedure run_sql_as_user ( p_schema_name in varchar2&lt;br /&gt;
                                            , p_sql         in varchar2&lt;br /&gt;
                                            ) is&lt;br /&gt;
    l_user_id dba_users.user_id%type;&lt;br /&gt;
    l_cursor  number;&lt;br /&gt;
    l_rc      number;&lt;br /&gt;
begin&lt;br /&gt;
    dbms_output.enable(null);&lt;br /&gt;
    begin&lt;br /&gt;
        select u.user_id&lt;br /&gt;
        into   l_user_id&lt;br /&gt;
        from   dba_users u&lt;br /&gt;
        where  u.username = p_schema_name;&lt;br /&gt;
    exception&lt;br /&gt;
    when no_data_found then&lt;br /&gt;
        raise_application_error (-20001, &amp;#039;Cannot find user &amp;#039;||p_schema_name);&lt;br /&gt;
    end;&lt;br /&gt;
    l_cursor := dbms_sys_sql.open_cursor;&lt;br /&gt;
    dbms_sys_sql.parse_as_user ( c             =&amp;gt; l_cursor&lt;br /&gt;
                               , statement     =&amp;gt; p_sql&lt;br /&gt;
                               , language_flag =&amp;gt; dbms_sql.native&lt;br /&gt;
                               , userid        =&amp;gt; l_user_id&lt;br /&gt;
    );&lt;br /&gt;
    l_rc := dbms_sys_sql.execute(l_cursor);&lt;br /&gt;
    dbms_sys_sql.close_cursor(l_cursor);&lt;br /&gt;
exception&lt;br /&gt;
when others then&lt;br /&gt;
    raise_application_error (-20001, &amp;#039;ERROR: &amp;#039;||sqlerrm);&lt;br /&gt;
end;&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Run a script on all databases listed in tnsnames.ora===&lt;br /&gt;
Can run an SQL command file on all SID/SERVICE found in a tnsnames.ora file. I use this from a client laptop having a global tns file on it.&amp;lt;br /&amp;gt;&lt;br /&gt;
This way it&amp;#039;s not necessary to copy the file onto every host before executing it. Any files created by the script will be created on the client.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/ksh&lt;br /&gt;
&lt;br /&gt;
TNSNAMES=&amp;quot;./tnsnames.ora&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[ ! -r &amp;quot;${TNSNAMES}&amp;quot; ]] &amp;amp;&amp;amp; echo &amp;quot;${TNSNAMES} is not accessible&amp;quot; &amp;amp;&amp;amp; exit 1&lt;br /&gt;
&lt;br /&gt;
SIDLIST=$(perl -ne &amp;#039;print &amp;quot;$1\n&amp;quot; if /(?:SID|SERVICE_NAME)\s*=\s*(\S+?)\)/&amp;#039; ${TNSNAMES}|sort|uniq|xargs)&lt;br /&gt;
for SID in ${SIDLIST}&lt;br /&gt;
do&lt;br /&gt;
    echo &amp;quot;Processing $SID&amp;quot;&lt;br /&gt;
    ls -al | grep &amp;quot;^d&amp;quot; | grep &amp;quot;\_${SID}&amp;quot; &amp;gt;/dev/null&lt;br /&gt;
    if [[ $? -ne 0 ]]; then&lt;br /&gt;
        echo &amp;#039;exit&amp;#039; | sqlplus system/password@${SID} @ReviewLite17.1.sql &amp;gt;/dev/null 2&amp;gt;&amp;amp;1&lt;br /&gt;
    else&lt;br /&gt;
        echo &amp;quot;directory already exists so must have done this SID&amp;quot;&lt;br /&gt;
    fi&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===List invalid objects===&lt;br /&gt;
 set lines 200&lt;br /&gt;
 set pages 200&lt;br /&gt;
 col obj format a40&lt;br /&gt;
 select owner||&amp;#039;.&amp;#039;||object_name obj&lt;br /&gt;
 ,      object_type&lt;br /&gt;
 from   dba_objects&lt;br /&gt;
 where  1=1&lt;br /&gt;
 and    status = &amp;#039;INVALID&amp;#039;;&lt;br /&gt;
===Recompile all invalid objects===&lt;br /&gt;
@?/rdbms/admin/utlrp.sql&lt;br /&gt;
===See how much space is left in the flash recovery area (FRA)===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select name&lt;br /&gt;
,      to_char (space_limit, &amp;#039;999,999,999,999&amp;#039;) as space_limit&lt;br /&gt;
,      to_char (space_limit - space_used + space_reclaimable&lt;br /&gt;
,               &amp;#039;999,999,999,999&amp;#039;)&lt;br /&gt;
           as space_available&lt;br /&gt;
,      round ( (space_used - space_reclaimable) / space_limit * 100, 1)&lt;br /&gt;
           as pct_full&lt;br /&gt;
from   v$recovery_file_dest;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# ==============================================&lt;br /&gt;
# Check FRA to see how much space is reclaimable&lt;br /&gt;
# ==============================================&lt;br /&gt;
fra_reclaim_check() {&lt;br /&gt;
&lt;br /&gt;
LOGFILE=${RMAN_LogDir}/${ORACLE_SID}_`date &amp;#039;+%Y%m&amp;#039;`_${V_SCRIPT}.log&lt;br /&gt;
sqlplus &amp;quot;/ as sysdba&amp;quot; &amp;lt;&amp;lt;EOSQL &amp;gt; /tmp/results.$$&lt;br /&gt;
set vefify off echo off heading off newpage none linesize 1000 echo off&lt;br /&gt;
select &amp;#039;Filesystem:&amp;#039;||name||&lt;br /&gt;
       &amp;#039;; Total(Gb):&amp;#039;||round((space_limit/1073741824),2) ||&lt;br /&gt;
       &amp;#039;; Reclaimable(Gb):&amp;#039;||round((space_reclaimable/1073741824),2) ||&lt;br /&gt;
       &amp;#039;; Reclaimable(%):&amp;#039;||round( ((space_reclaimable/1073741824)/(space_limit/1073741824)*100),2 )&lt;br /&gt;
from   v$recovery_file_dest&lt;br /&gt;
/&lt;br /&gt;
EOSQL&lt;br /&gt;
cat /tmp/results.$$ &amp;gt;&amp;gt; $LOGFILE&lt;br /&gt;
rm /tmp/results.$$&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===How far back can we flashback?===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
col time_now              for a25&lt;br /&gt;
col time_oldest_flashback for a25&lt;br /&gt;
select to_char(sysdate,&amp;#039;DD-MON-YY HH24:MI&amp;#039;)                    time_now&lt;br /&gt;
,      to_char(fdl.oldest_flashback_time, &amp;#039;DD-MON-YY HH24:MI&amp;#039;) time_oldest_flashback&lt;br /&gt;
,      round((sysdate-fdl.oldest_flashback_time)*24,1)         hours_flashback_possible&lt;br /&gt;
from   v$database d&lt;br /&gt;
,      v$flashback_database_log fdl&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===DBA privs tables===&lt;br /&gt;
 DBA_AQ_AGENT_PRIVS&lt;br /&gt;
 DBA_COL_PRIVS&lt;br /&gt;
 DBA_PRIV_AUDIT_OPTS&lt;br /&gt;
 DBA_REPGROUP_PRIVILEGES&lt;br /&gt;
 DBA_ROLE_PRIVS&lt;br /&gt;
 DBA_RSRC_CONSUMER_GROUP_PRIVS&lt;br /&gt;
 DBA_RSRC_MANAGER_SYSTEM_PRIVS&lt;br /&gt;
 DBA_SYS_PRIVS&lt;br /&gt;
 DBA_TAB_PRIVS&lt;br /&gt;
 DBA_WM_SYS_PRIVS&lt;br /&gt;
 DBA_WORKSPACE_PRIVS&lt;br /&gt;
&lt;br /&gt;
===Schedule a shell job===&lt;br /&gt;
 begin&lt;br /&gt;
     dbms_scheduler.create_program ( program_name   =&amp;gt; &amp;#039;myshelljob&amp;#039;&lt;br /&gt;
                                   , program_action =&amp;gt; &amp;#039;/home/oracle/scripts/shell.sh&amp;#039;&lt;br /&gt;
                                   , program_type   =&amp;gt; &amp;#039;EXECUTABLE&amp;#039;&lt;br /&gt;
                                   , comments       =&amp;gt; &amp;#039;Run a shell&amp;#039;&lt;br /&gt;
                                   , enabled        =&amp;gt; TRUE&lt;br /&gt;
                                   );&lt;br /&gt;
 end;&lt;br /&gt;
 /&lt;br /&gt;
===Start the job===&lt;br /&gt;
 begin&lt;br /&gt;
     dbms_sheduler.create_job ( job_name     =&amp;gt; &amp;#039;myshelljob&amp;#039;&lt;br /&gt;
                              , program_name =&amp;gt; &amp;#039;myshelljob&amp;#039;&lt;br /&gt;
                              , start_date   =&amp;gt;&lt;br /&gt;
                              );&lt;br /&gt;
 /&lt;br /&gt;
&lt;br /&gt;
===What statement is a user running?===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select a.sid&lt;br /&gt;
,      a.serial#&lt;br /&gt;
,      b.sql_text&lt;br /&gt;
from   v$session a&lt;br /&gt;
,      v$sqlarea b&lt;br /&gt;
where  a.sql_address = b.address&lt;br /&gt;
and    a.username    = &amp;#039;&amp;amp;username&amp;#039;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===See what statements all users are running===&lt;br /&gt;
Useful to see what is happening when process limit is reached&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 300 pages 1000&lt;br /&gt;
&lt;br /&gt;
col username for a10&lt;br /&gt;
col command for 999 head &amp;quot;CMD&amp;quot;&lt;br /&gt;
col lockwait for a10&lt;br /&gt;
col status for a8&lt;br /&gt;
col schemaname for a12&lt;br /&gt;
col osuser for a10&lt;br /&gt;
col process for a10&lt;br /&gt;
col program for a20&lt;br /&gt;
col machine for a10&lt;br /&gt;
col action for a10&lt;br /&gt;
col module for a10&lt;br /&gt;
col identifier for a10&lt;br /&gt;
col event for a27&lt;br /&gt;
col state for a8&lt;br /&gt;
col service_name for a10&lt;br /&gt;
col serial# for 999999&lt;br /&gt;
&lt;br /&gt;
select a.username&lt;br /&gt;
,      a.command&lt;br /&gt;
,      a.lockwait&lt;br /&gt;
,      a.status&lt;br /&gt;
,      a.schemaname&lt;br /&gt;
,      a.osuser&lt;br /&gt;
,      a.process&lt;br /&gt;
,      a.machine&lt;br /&gt;
,      a.program&lt;br /&gt;
,      a.type&lt;br /&gt;
--,      a.sql_exec_start&lt;br /&gt;
--,      a.plsql_object_id&lt;br /&gt;
--,      a.plsql_subprogram_id&lt;br /&gt;
--,      a.module&lt;br /&gt;
--,      a.action&lt;br /&gt;
,      a.logon_time&lt;br /&gt;
,      a.event&lt;br /&gt;
,      a.wait_time&lt;br /&gt;
,      a.seconds_in_wait&lt;br /&gt;
,      a.state&lt;br /&gt;
--,      a.service_name&lt;br /&gt;
,      a.serial#&lt;br /&gt;
,      b.sql_text&lt;br /&gt;
from   v$session a&lt;br /&gt;
,      v$sqlarea b&lt;br /&gt;
where  a.sql_address = b.address&lt;br /&gt;
order  by a.logon_time desc&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
set lines 80&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===A logminer session===&lt;br /&gt;
Mine all SQL statements in a 10 minute period&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sqlplus / as sysdba&lt;br /&gt;
alter session set nls_date_format = &amp;#039;DD-MON-YYYY HH24:MI:SS&amp;#039;;&lt;br /&gt;
execute dbms_logmnr.start_logmnr ( starttime =&amp;gt; &amp;#039;27-OCT-2009 11:05:00&amp;#039;&lt;br /&gt;
                                 , endtime   =&amp;gt; &amp;#039;27-OCT-2009 11:15:00&amp;#039;&lt;br /&gt;
                                 , options   =&amp;gt; dbms_logmnr.dict_from_online_catalog+dbms_logmnr.continuous_mine&lt;br /&gt;
                                 );&lt;br /&gt;
create table mycontents as select * from v$logmnr_contents;&lt;br /&gt;
execute dbms_logmnr.end_logmnr(); &lt;br /&gt;
&lt;br /&gt;
select * from mycontents;&lt;br /&gt;
&lt;br /&gt;
drop table mycontents;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Huge Pages===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
#&lt;br /&gt;
# hugepages_settings.sh&lt;br /&gt;
#&lt;br /&gt;
# Linux bash script to compute values for the&lt;br /&gt;
# recommended HugePages/HugeTLB configuration&lt;br /&gt;
#&lt;br /&gt;
# Note: This script does calculation for all shared memory&lt;br /&gt;
# segments available when the script is run, no matter it&lt;br /&gt;
# is an Oracle RDBMS shared memory segment or not.&lt;br /&gt;
# Check for the kernel version&lt;br /&gt;
KERN=`uname -r | awk -F. &amp;#039;{ printf(&amp;quot;%d.%d\n&amp;quot;,$1,$2); }&amp;#039;`&lt;br /&gt;
# Find out the HugePage size&lt;br /&gt;
HPG_SZ=`grep Hugepagesize /proc/meminfo | awk {&amp;#039;print $2&amp;#039;}`&lt;br /&gt;
# Start from 1 pages to be on the safe side and guarantee 1 free HugePage&lt;br /&gt;
NUM_PG=1&lt;br /&gt;
# Cumulative number of pages required to handle the running shared memory segments&lt;br /&gt;
for SEG_BYTES in `ipcs -m | awk {&amp;#039;print $5&amp;#039;} | grep &amp;quot;[0-9][0-9]*&amp;quot;`&lt;br /&gt;
do&lt;br /&gt;
   MIN_PG=`echo &amp;quot;$SEG_BYTES/($HPG_SZ*1024)&amp;quot; | bc -q`&lt;br /&gt;
   if [ $MIN_PG -gt 0 ]; then&lt;br /&gt;
      NUM_PG=`echo &amp;quot;$NUM_PG+$MIN_PG+1&amp;quot; | bc -q`&lt;br /&gt;
   fi&lt;br /&gt;
done&lt;br /&gt;
# Finish with results&lt;br /&gt;
case $KERN in&lt;br /&gt;
   &amp;#039;2.4&amp;#039;) HUGETLB_POOL=`echo &amp;quot;$NUM_PG*$HPG_SZ/1024&amp;quot; | bc -q`;&lt;br /&gt;
          echo &amp;quot;Recommended setting: vm.hugetlb_pool = $HUGETLB_POOL&amp;quot; ;;&lt;br /&gt;
   &amp;#039;2.6&amp;#039; | &amp;#039;3.8&amp;#039;) echo &amp;quot;Recommended setting: vm.nr_hugepages = $NUM_PG&amp;quot; ;;&lt;br /&gt;
    *) echo &amp;quot;Unrecognized kernel version $KERN. Exiting.&amp;quot; ;;&lt;br /&gt;
esac&lt;br /&gt;
# End&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Pretty longops listing===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 2000 pages 1000&lt;br /&gt;
col opname for a34 head &amp;quot;Job&amp;quot;&lt;br /&gt;
col message for a60&lt;br /&gt;
col perc_done for a10 head &amp;quot;Done&amp;quot;&lt;br /&gt;
col started for a18&lt;br /&gt;
col killer for a15&lt;br /&gt;
col mins_busy head &amp;quot;Mins busy&amp;quot;&lt;br /&gt;
col mins_left head &amp;quot;Mins left&amp;quot;&lt;br /&gt;
select sid||&amp;#039;,&amp;#039;||serial#                       killer&lt;br /&gt;
,      opname&lt;br /&gt;
,      message&lt;br /&gt;
,      round ((sofar/totalwork),4)*100||&amp;#039;%&amp;#039;    perc_done&lt;br /&gt;
,      to_char(start_time,&amp;#039;DD-MON-YY HH24:MI&amp;#039;) started&lt;br /&gt;
,      floor(elapsed_seconds/60)               mins_busy&lt;br /&gt;
,      ceil(time_remaining/60)                 mins_left&lt;br /&gt;
from   v$session_longops&lt;br /&gt;
where  1=1&lt;br /&gt;
and    sofar     != totalwork&lt;br /&gt;
and    totalwork != 0&lt;br /&gt;
and    opname    like &amp;#039;RMAN%&amp;#039;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select * from v$session where module=&amp;#039;Data Pump Worker&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or attach to the impdp job and it shows percentage done.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Get the SID from v$session_longops and plug it into v$session to check the SQL command details.&lt;br /&gt;
&lt;br /&gt;
Current Running SQLs&lt;br /&gt;
--------------------&lt;br /&gt;
set pages 1000 lines 2000&lt;br /&gt;
col program  format a40&lt;br /&gt;
col sql_text format a130&lt;br /&gt;
&lt;br /&gt;
select s.sid&lt;br /&gt;
,      s.status&lt;br /&gt;
,      s.last_call_et&lt;br /&gt;
,      s.program&lt;br /&gt;
,      sa.sql_id&lt;br /&gt;
,      sa.sql_text&lt;br /&gt;
from   v$session s&lt;br /&gt;
,      v$sqlarea sa&lt;br /&gt;
where  s.sql_id = sa.sql_id&lt;br /&gt;
and    s.sid = &amp;#039;&amp;amp;sid&amp;#039;&lt;br /&gt;
/ &lt;br /&gt;
&lt;br /&gt;
set pages 1000 lines 2000&lt;br /&gt;
col USERNAME for a10&lt;br /&gt;
col OSUSER   for a10&lt;br /&gt;
col MACHINE  for a10&lt;br /&gt;
&lt;br /&gt;
select s.sid&lt;br /&gt;
,      s.serial#&lt;br /&gt;
,      p.spid&lt;br /&gt;
,      s.username&lt;br /&gt;
,      s.osuser&lt;br /&gt;
,      s.status&lt;br /&gt;
,      s.process fg_pid&lt;br /&gt;
,      s.longon_time&lt;br /&gt;
,      s.machine&lt;br /&gt;
,      p.spid bg_pid&lt;br /&gt;
from   gv$session s&lt;br /&gt;
,      gv$process p&lt;br /&gt;
where  s.addr = p.addr&lt;br /&gt;
and    s.sid  = &amp;#039;&amp;amp;sid&amp;#039;&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
$ps -ef | grep &amp;lt;spid&amp;gt;&lt;br /&gt;
&lt;br /&gt;
set pages 1000 lines 2000&lt;br /&gt;
SELECT INST_ID&lt;br /&gt;
,      SID&lt;br /&gt;
,      SERIAL#&lt;br /&gt;
,      SQL_ID&lt;br /&gt;
,      USERNAME&lt;br /&gt;
,      PROGRAM&lt;br /&gt;
,      MACHINE&lt;br /&gt;
,      SERVICE_NAME&lt;br /&gt;
FROM   GV$SESSION&lt;br /&gt;
WHERE  SID IN (&amp;#039;&amp;lt;SID_NO.1&amp;gt;&amp;#039;,&amp;#039;&amp;lt;SID_NO.2&amp;gt;&amp;#039;)&lt;br /&gt;
/&lt;br /&gt;
Active Running SQLs&lt;br /&gt;
--------------------&lt;br /&gt;
set pages 1000 lines 2000&lt;br /&gt;
col SPID     for a10&lt;br /&gt;
col PROGRAM  for a15&lt;br /&gt;
col OSUSER   for a10&lt;br /&gt;
col ACTION   for a10&lt;br /&gt;
col EVENT    for a25&lt;br /&gt;
col SQL_TEXT for a25&lt;br /&gt;
col MACHINE  for a10&lt;br /&gt;
col P1TEXT   for a10 &lt;br /&gt;
col P2TEXT   for a10&lt;br /&gt;
col P3TEXT   for a10  &lt;br /&gt;
SELECT b.sid&lt;br /&gt;
,      b.serial#&lt;br /&gt;
,      a.spid&lt;br /&gt;
,      b.sql_id&lt;br /&gt;
,      b.program&lt;br /&gt;
,      b.osuser&lt;br /&gt;
,      b.machine&lt;br /&gt;
,      b.type&lt;br /&gt;
,      b.event&lt;br /&gt;
,      b.action&lt;br /&gt;
,      b.p1text&lt;br /&gt;
,      b.p2text&lt;br /&gt;
,      b.p3text&lt;br /&gt;
,      b.state&lt;br /&gt;
,      c.sql_text&lt;br /&gt;
,      b.logon_time&lt;br /&gt;
FROM   v$process a&lt;br /&gt;
,      v$session b&lt;br /&gt;
,      v$sqltext c&lt;br /&gt;
WHERE  a.addr           = b.paddr&lt;br /&gt;
AND    b.sql_hash_value = c.hash_value&lt;br /&gt;
AND    b.STATUS         = &amp;#039;ACTIVE&amp;#039;&lt;br /&gt;
AND    b.sid            = &amp;#039;&amp;amp;sid&amp;#039;&lt;br /&gt;
ORDER  BY a.spid&lt;br /&gt;
,      c.piece&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
OR - Use the below Query &lt;br /&gt;
&lt;br /&gt;
Longops.sql&lt;br /&gt;
----------- &lt;br /&gt;
set pages 50000 lines 32767&lt;br /&gt;
col OPNAME for a10&lt;br /&gt;
col SID form 9999&lt;br /&gt;
col SERIAL form 9999999&lt;br /&gt;
col PROGRAM for a10&lt;br /&gt;
col USERNAME for a10&lt;br /&gt;
col SQL_TEXT for a40&lt;br /&gt;
col START_TIME for a10&lt;br /&gt;
col LAST_UPDATE_TIME for a10&lt;br /&gt;
col TARGET for a25&lt;br /&gt;
col MESSAGE for a25&lt;br /&gt;
&lt;br /&gt;
alter session set nls_date_format = &amp;#039;DD-MM-YYYY HH24:MI:SS&amp;#039;;&lt;br /&gt;
&lt;br /&gt;
SELECT l.inst_id,l.sid, l.serial#, l.sql_id, l.opname, l.username, l.target, l.sofar, l.totalwork, l.start_time,l.last_update_time,round(l.time_remaining/60,2) &amp;quot;REMAIN MINS&amp;quot;, round(l.elapsed_seconds/60,2) &amp;quot;ELAPSED MINS&amp;quot;, round((l.time_remaining+l.elapsed_seconds)/60,2) &amp;quot;TOTAL MINS&amp;quot;, ROUND(l.SOFAR/l.TOTALWORK*100,2) &amp;quot;%_COMPLETE&amp;quot;, l.message,s.sql_text &lt;br /&gt;
FROM gv$session_longops l &lt;br /&gt;
LEFT OUTER JOIN v$sql s on s.hash_value=l.sql_hash_value and s.address=l.sql_address and s.child_number=0&lt;br /&gt;
WHERE l.OPNAME NOT LIKE &amp;#039;RMAN%&amp;#039; AND l.OPNAME NOT LIKE &amp;#039;%aggregate%&amp;#039; AND l.TOTALWORK != 0 AND l.sofar&amp;lt;&amp;gt;l.totalwork AND l.time_remaining &amp;gt; 0&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Apply the database patch after the ORACLE_HOME has been patched===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ORAENV_ASK=NO&lt;br /&gt;
export ORACLE_SID=$1&lt;br /&gt;
. oraenv&lt;br /&gt;
&lt;br /&gt;
sqlplus /nolog &amp;lt;&amp;lt;EOSQL&lt;br /&gt;
connect / as sysdba&lt;br /&gt;
startup&lt;br /&gt;
@?/rdbms/admin/catbundle.sql psu apply&lt;br /&gt;
@?/rdbms/admin/utlrp.sql&lt;br /&gt;
purge dba_recyclebin;&lt;br /&gt;
&lt;br /&gt;
prompt check patch apply...&lt;br /&gt;
set lines 150&lt;br /&gt;
col action_time for a50&lt;br /&gt;
col comp_name for a50&lt;br /&gt;
col comments for a50&lt;br /&gt;
&lt;br /&gt;
select action_time,action,comments from sys.registry\$history where trunc(action_time) = trunc(sysdate);&lt;br /&gt;
select comp_name,version,status,modified from dba_registry;&lt;br /&gt;
exit&lt;br /&gt;
EOSQL&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Show how much archivelog data is generated per day===&lt;br /&gt;
A companion script for &amp;#039;how many log switches in a day&amp;#039;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
col orderby noprint&lt;br /&gt;
select trunc(first_time) orderby&lt;br /&gt;
,      to_char(first_time,&amp;#039;DD-MON-YYYY&amp;#039;) &amp;quot;Date&amp;quot;&lt;br /&gt;
,      round(sum(bytes/1024/1024/1024),2) arch_logs_gigs&lt;br /&gt;
from (&lt;br /&gt;
    select unique (blocks * block_size) bytes,&lt;br /&gt;
    thread#,&lt;br /&gt;
    sequence#,&lt;br /&gt;
    resetlogs_change#,&lt;br /&gt;
    first_time&lt;br /&gt;
    from v$archived_log&lt;br /&gt;
)&lt;br /&gt;
group by trunc(first_time)&lt;br /&gt;
,      to_char(first_time, &amp;#039;DD-MON-YYYY&amp;#039;)&lt;br /&gt;
order by trunc(first_time) desc&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Abort a hanging database even when sysdba cannot connect===&lt;br /&gt;
Unable to connect to database with sqlplus / as sysdba because audit file cannot be created?&lt;br /&gt;
* [http://tech.e2sn.com/oracle/troubleshooting/hang/how-to-log-on-even-when-sysdba-can-t-do-so tech.e2sn.com]&lt;br /&gt;
* [http://blog.dbi-services.com/oracle-is-hanging-dont-forget-hanganalyze-and-systemstate/ blog.dbi-services.com]&lt;br /&gt;
Instead of just killing the pmon process, there is a kinder (and more useful) way to kill the database.&amp;lt;br /&amp;gt;&lt;br /&gt;
Use the hidden, undocumented &amp;#039;prelim&amp;#039; switch parameter to sqlplus to make a connection to the database without creating SGA session data structures.&amp;lt;br /&amp;gt;&lt;br /&gt;
It can be very useful for hang analysis so the possible cause can be found after the database has been restarted.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sqlplus -prelim / as sysdba&lt;br /&gt;
oradebug unlimit&lt;br /&gt;
oradebug hanganalyze 3&lt;br /&gt;
oradebug setmypid              -- or oradebug setorapname diag&lt;br /&gt;
oradebug dump ashdumpseconds 30&lt;br /&gt;
oradebug dump systemstate 10   -- or oradebug dump systemstate 266&lt;br /&gt;
oradebug tracefile_name&lt;br /&gt;
shutdown abort&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Lists Oracle session with kill session statement all ready to go===&lt;br /&gt;
disconnect attempts to kill the o/s processes too. kill doesn&amp;#039;t.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
col killer for a60&lt;br /&gt;
col osuser for a12&lt;br /&gt;
col logon  for a23&lt;br /&gt;
col spid   for a8&lt;br /&gt;
col username for a15&lt;br /&gt;
col program for a50&lt;br /&gt;
set lines 2000&lt;br /&gt;
select &amp;#039;alter system disconnect session &amp;#039;&amp;#039;&amp;#039;||s.sid||&amp;#039;,&amp;#039;||s.serial#||&amp;#039;&amp;#039;&amp;#039; immediate;&amp;#039; killer&lt;br /&gt;
,      s.inst_id&lt;br /&gt;
,      to_char(s.logon_time,&amp;#039;DD-MON-YY HH24:MI:SS&amp;#039;) logon&lt;br /&gt;
,      sci.osuser&lt;br /&gt;
,      p.spid&lt;br /&gt;
,      s.username&lt;br /&gt;
,      s.program&lt;br /&gt;
from   gv$session s&lt;br /&gt;
,      gv$session_connect_info sci&lt;br /&gt;
,      gv$process p&lt;br /&gt;
where  1=1&lt;br /&gt;
and    p.addr     = s.paddr&lt;br /&gt;
and    p.inst_id  = s.inst_id&lt;br /&gt;
and    s.sid      = sci.sid&lt;br /&gt;
and    s.serial#  = sci.serial#&lt;br /&gt;
and    s.type    != &amp;#039;BACKGROUND&amp;#039;&lt;br /&gt;
and    sci.osuser = &amp;#039;oraibm&amp;#039;&lt;br /&gt;
order  by s.logon_time desc&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
KILLER                                                          INST_ID LOGON                   OSUSER       SPID     USERNAME        PROGRAM&lt;br /&gt;
------------------------------------------------------------ ---------- ----------------------- ------------ -------- --------------- --------------------------------------------------&lt;br /&gt;
alter system disconnect session &amp;#039;490,33947&amp;#039; immediate;                1 23-JUN-16 13:30:53      oraibm       23205    SYS             sqlplus@benouerp07 (TNS V1-V3)&lt;br /&gt;
alter system disconnect session &amp;#039;490,33947&amp;#039; immediate;                1 23-JUN-16 13:30:53      oraibm       23205    SYS             sqlplus@benouerp07 (TNS V1-V3)&lt;br /&gt;
alter system disconnect session &amp;#039;490,33947&amp;#039; immediate;                1 23-JUN-16 13:30:53      oraibm       23205    SYS             sqlplus@benouerp07 (TNS V1-V3)&lt;br /&gt;
alter system disconnect session &amp;#039;490,33947&amp;#039; immediate;                1 23-JUN-16 13:30:53      oraibm       23205    SYS             sqlplus@benouerp07 (TNS V1-V3)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===How much space is being used by a guaranteed restore point?===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
show parameter recovery&lt;br /&gt;
set numwi 15&lt;br /&gt;
set lines 200&lt;br /&gt;
col name for a40&lt;br /&gt;
col time for a23&lt;br /&gt;
col gigs_limit head &amp;quot;Max (but check df -g also!)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
select name&lt;br /&gt;
,      time&lt;br /&gt;
,      round(storage_size/1024/1024/1024,2) gigs_used&lt;br /&gt;
from   v$restore_point&lt;br /&gt;
where  1=1&lt;br /&gt;
and    guarantee_flashback_database = &amp;#039;YES&amp;#039;&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
select * from v$flash_recovery_area_usage&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
select name&lt;br /&gt;
,      round(space_used/1024/1024/1024,2) gigs_used&lt;br /&gt;
,      round(space_limit/1024/1024/1024,2) gigs_limit&lt;br /&gt;
,      space_reclaimable&lt;br /&gt;
,      number_of_files&lt;br /&gt;
from v$recovery_file_dest&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Get statistics for LOB columns in a table===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select &lt;br /&gt;
  max(dbms_lob.getlength(lob_content)) max_len&lt;br /&gt;
, avg(dbms_lob.getlength(lob_content)) avg_len&lt;br /&gt;
, min(dbms_lob.getlength(lob_content)) min_len&lt;br /&gt;
, sum(case when dbms_lob.getlength(lob_content) &amp;lt;= 4000 then 1&lt;br /&gt;
else 0 end) &amp;quot;&amp;lt;4k&amp;quot;&lt;br /&gt;
, sum(case when dbms_lob.getlength(lob_content) &amp;gt; 4000 then 1&lt;br /&gt;
else 0 end) &amp;quot;&amp;gt;4k&amp;quot;&lt;br /&gt;
, sum(case when dbms_lob.getlength(lob_content) is null then 1 else&lt;br /&gt;
0 end) &amp;quot;is null&amp;quot;&lt;br /&gt;
from &amp;amp;tablename&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===badprivs.sql===&lt;br /&gt;
Check to see if any ordinary users have privileges / access / grants / rights they should not have&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select grantee, privilege, admin_option&lt;br /&gt;
from   sys.dba_sys_privs&lt;br /&gt;
where  (       privilege like &amp;#039;% ANY %&amp;#039;&lt;br /&gt;
        or     privilege in (&amp;#039;BECOME USER&amp;#039;, &amp;#039;UNLIMITED TABLESPACE&amp;#039;)&lt;br /&gt;
        or     admin_option = &amp;#039;YES&amp;#039;&lt;br /&gt;
       )&lt;br /&gt;
and    grantee not in (&amp;#039;SYS&amp;#039;, &amp;#039;SYSTEM&amp;#039;, &amp;#039;OUTLN&amp;#039;, &amp;#039;AQ_ADMINISTRATOR_ROLE&amp;#039;,&lt;br /&gt;
                      &amp;#039;DBA&amp;#039;, &amp;#039;EXP_FULL_DATABASE&amp;#039;, &amp;#039;IMP_FULL_DATABASE&amp;#039;,&lt;br /&gt;
                      &amp;#039;OEM_MONITOR&amp;#039;, &amp;#039;CTXSYS&amp;#039;, &amp;#039;DBSNMP&amp;#039;, &amp;#039;IFSSYS&amp;#039;,&lt;br /&gt;
                      &amp;#039;IFSSYS$CM&amp;#039;, &amp;#039;MDSYS&amp;#039;, &amp;#039;ORDPLUGINS&amp;#039;, &amp;#039;ORDSYS&amp;#039;,&lt;br /&gt;
                      &amp;#039;TIMESERIES_DBA&amp;#039;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Generate a list of tablespaces ready for a migration===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set echo off&lt;br /&gt;
set lines 300&lt;br /&gt;
set pages 0&lt;br /&gt;
Set headi off&lt;br /&gt;
set feedb off&lt;br /&gt;
set long 32000&lt;br /&gt;
&lt;br /&gt;
spool migration_create_target_tablespaces.sql&lt;br /&gt;
&lt;br /&gt;
exec dbms_metadata.set_transform_param(dbms_metadata.session_transform,&amp;#039;SQLTERMINATOR&amp;#039;,TRUE);&lt;br /&gt;
select DBMS_METADATA.GET_DDL(&amp;#039;TABLESPACE&amp;#039;,tablespace_name) from dba_tablespaces&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
spool off&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===List the privileges assigned to users on directories===&lt;br /&gt;
table_name is the name of the directory...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select grantor&lt;br /&gt;
,      grantee&lt;br /&gt;
,      table_schema&lt;br /&gt;
,      table_name&lt;br /&gt;
,      privilege&lt;br /&gt;
from   all_tab_privs&lt;br /&gt;
where  table_name = &amp;#039;DATA_PUMP_DIR&amp;#039;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===List the privileges assigned to users on packages/procedures===&lt;br /&gt;
table_name is the name of the package...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select grantor&lt;br /&gt;
,      grantee&lt;br /&gt;
,      table_schema&lt;br /&gt;
,      table_name&lt;br /&gt;
,      privilege&lt;br /&gt;
from   all_tab_privs&lt;br /&gt;
where  upper(table_name) like upper(&amp;#039;%UTL_FILE%&amp;#039;)&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===List the system privileges assigned to a user (used to copy user as or clone user as)===&lt;br /&gt;
Maybe this one is better [[Extract ddl with &amp;quot;dbms metadata.get ddl&amp;quot;]]&lt;br /&gt;
&lt;br /&gt;
 SELECT LPAD(&amp;#039; &amp;#039;, 2*level) || granted_role &amp;quot;USER PRIVS&amp;quot;&lt;br /&gt;
 FROM (&lt;br /&gt;
   SELECT NULL grantee,  username granted_role&lt;br /&gt;
   FROM dba_users&lt;br /&gt;
   WHERE username LIKE UPPER(&amp;#039;%&amp;amp;uname%&amp;#039;)&lt;br /&gt;
   UNION&lt;br /&gt;
   SELECT grantee, granted_role&lt;br /&gt;
   FROM dba_role_privs&lt;br /&gt;
   UNION&lt;br /&gt;
   SELECT grantee, privilege&lt;br /&gt;
   FROM dba_sys_privs)&lt;br /&gt;
 START WITH grantee IS NULL&lt;br /&gt;
 CONNECT BY grantee = prior granted_role;&lt;br /&gt;
&lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
 SELECT path&lt;br /&gt;
 FROM (&lt;br /&gt;
   SELECT grantee,&lt;br /&gt;
          sys_connect_by_path(privilege, &amp;#039;:&amp;#039;)||&amp;#039;:&amp;#039;||grantee path&lt;br /&gt;
   FROM (&lt;br /&gt;
     SELECT grantee, privilege, 0 role&lt;br /&gt;
     FROM dba_sys_privs&lt;br /&gt;
     UNION ALL&lt;br /&gt;
     SELECT grantee, granted_role, 1 role&lt;br /&gt;
     FROM dba_role_privs)&lt;br /&gt;
   CONNECT BY privilege=prior grantee&lt;br /&gt;
   START WITH role = 0)&lt;br /&gt;
 WHERE grantee IN (&lt;br /&gt;
    SELECT username&lt;br /&gt;
    FROM dba_users&lt;br /&gt;
    WHERE lock_date IS NULL&lt;br /&gt;
    AND password != &amp;#039;EXTERNAL&amp;#039;&lt;br /&gt;
    AND username != &amp;#039;SYS&amp;#039;)&lt;br /&gt;
 OR grantee=&amp;#039;PUBLIC&amp;#039;&lt;br /&gt;
&lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
for a migration from 10g...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set headi off&lt;br /&gt;
set feedb off&lt;br /&gt;
set long  9999999&lt;br /&gt;
set pages 0&lt;br /&gt;
set lines 300&lt;br /&gt;
&lt;br /&gt;
spool migration_create_target_users_grants.sql&lt;br /&gt;
&lt;br /&gt;
select dbms_metadata.get_ddl(&amp;#039;USER&amp;#039;, username) || &amp;#039;;&amp;#039; ddl&lt;br /&gt;
from dba_users&lt;br /&gt;
where  1=1&lt;br /&gt;
and    username like upper(&amp;#039;%&amp;amp;&amp;amp;USER_NAME%&amp;#039;)&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
select &amp;#039;grant &amp;#039;||privilege|| &amp;#039; to &amp;#039; || grantee || &amp;#039;;&amp;#039;&lt;br /&gt;
from   dba_sys_privs&lt;br /&gt;
where  1=1&lt;br /&gt;
and    grantee like upper(&amp;#039;%&amp;amp;&amp;amp;USER_NAME%&amp;#039;)&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
select &amp;#039;grant &amp;#039;||granted_role|| &amp;#039; to &amp;#039; || grantee || &amp;#039;;&amp;#039;&lt;br /&gt;
from   dba_role_privs&lt;br /&gt;
where  1=1&lt;br /&gt;
and    grantee like upper(&amp;#039;%&amp;amp;&amp;amp;USER_NAME%&amp;#039;)&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
spool off&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or for a migration on 11g...!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set head off&lt;br /&gt;
set pages 0&lt;br /&gt;
set long 9999999&lt;br /&gt;
col ddl for a1000&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
SELECT DBMS_METADATA.GET_DDL(&amp;#039;USER&amp;#039;, USERNAME) || &amp;#039;;&amp;#039; DDL&lt;br /&gt;
FROM DBA_USERS&lt;br /&gt;
where  1=1&lt;br /&gt;
and    default_tablespace not in (&amp;#039;SYSTEM&amp;#039;,&amp;#039;SYSAUX&amp;#039;)&lt;br /&gt;
and    upper(username) like &amp;#039;%&amp;#039;||upper(&amp;#039;&amp;amp;&amp;amp;username&amp;#039;)||&amp;#039;%&amp;#039;&lt;br /&gt;
UNION ALL&lt;br /&gt;
SELECT DBMS_METADATA.GET_GRANTED_DDL(&amp;#039;ROLE_GRANT&amp;#039;, USERNAME) || &amp;#039;;&amp;#039; DDL&lt;br /&gt;
FROM DBA_USERS&lt;br /&gt;
where  1=1&lt;br /&gt;
and    default_tablespace not in (&amp;#039;SYSTEM&amp;#039;,&amp;#039;SYSAUX&amp;#039;)&lt;br /&gt;
and    upper(username) like &amp;#039;%&amp;#039;||upper(&amp;#039;&amp;amp;&amp;amp;username&amp;#039;)||&amp;#039;%&amp;#039;&lt;br /&gt;
UNION ALL&lt;br /&gt;
SELECT DBMS_METADATA.GET_GRANTED_DDL(&amp;#039;SYSTEM_GRANT&amp;#039;, USERNAME) || &amp;#039;;&amp;#039; DDL&lt;br /&gt;
FROM DBA_USERS&lt;br /&gt;
where  1=1&lt;br /&gt;
and    default_tablespace not in (&amp;#039;SYSTEM&amp;#039;,&amp;#039;SYSAUX&amp;#039;)&lt;br /&gt;
and    upper(username) like &amp;#039;%&amp;#039;||upper(&amp;#039;&amp;amp;&amp;amp;username&amp;#039;)||&amp;#039;%&amp;#039;&lt;br /&gt;
UNION ALL&lt;br /&gt;
SELECT DBMS_METADATA.GET_GRANTED_DDL(&amp;#039;OBJECT_GRANT&amp;#039;, USERNAME) || &amp;#039;;&amp;#039; DDL&lt;br /&gt;
FROM DBA_USERS&lt;br /&gt;
where  1=1&lt;br /&gt;
and    default_tablespace not in (&amp;#039;SYSTEM&amp;#039;,&amp;#039;SYSAUX&amp;#039;)&lt;br /&gt;
and    upper(username) like &amp;#039;%&amp;#039;||upper(&amp;#039;&amp;amp;&amp;amp;username&amp;#039;)||&amp;#039;%&amp;#039;&lt;br /&gt;
&lt;br /&gt;
spool migration_create_users_grants.sql&lt;br /&gt;
/&lt;br /&gt;
spool off&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Move datafiles between filesystems===&lt;br /&gt;
* [https://blogs.oracle.com/alejandrovargas/moving-a-datafile-from-file-system-to-asm Moving a datafile from File System to ASM (does not have to be ASM!) - oracle.com]&lt;br /&gt;
* [https://docs.oracle.com/database/121/OSTMG/GUID-3B8D0956-0888-452D-A9E4-9FB8D98577E0.htm#OSTMG89997 Moving Data Files Between Oracle ASM (does not have to be ASM!) Using RMAN - oracle.com]&lt;br /&gt;
* [https://oracle-base.com/articles/misc/renaming-or-moving-oracle-files Moving a data file online between filesystems - oracle-base.com]&lt;br /&gt;
====Set the relevant datafile offline====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter database datafile 125 offline;&lt;br /&gt;
alter database datafile 126 offline;&lt;br /&gt;
alter database datafile 127 offline;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Rename the files on the filesystem using o/s commands====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter tablespace ts_thaler_data_offline;&lt;br /&gt;
&lt;br /&gt;
host mv &amp;#039;/cln/tst/ora_data1/clnt/data4/ts_thaler_data_113.dbf&amp;#039; &amp;#039;/cln/tst/ora_data1/clnt/data1/ts_thaler_data_113.dbf&amp;#039;&lt;br /&gt;
host mv &amp;#039;/cln/tst/ora_data1/clnt/data4/ts_thaler_data_114.dbf&amp;#039; &amp;#039;/cln/tst/ora_data1/clnt/data1/ts_thaler_data_114.dbf&amp;#039;&lt;br /&gt;
host mv &amp;#039;/cln/tst/ora_data1/clnt/data4/ts_thaler_data_115.dbf&amp;#039; &amp;#039;/cln/tst/ora_data1/clnt/data1/ts_thaler_data_115.dbf&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Run the relevant alter commands to inform the control files of the new locations====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter database move datafile &amp;#039;/cln/tst/ora_data1/clnt/data4/ts_thaler_data_113.dbf&amp;#039; to &amp;#039;/cln/tst/ora_data1/clnt/data1/ts_thaler_data_113.dbf&amp;#039;&lt;br /&gt;
alter database move datafile &amp;#039;/cln/tst/ora_data1/clnt/data4/ts_thaler_data_114.dbf&amp;#039; to &amp;#039;/cln/tst/ora_data1/clnt/data1/ts_thaler_data_114.dbf&amp;#039;&lt;br /&gt;
alter database move datafile &amp;#039;/cln/tst/ora_data1/clnt/data4/ts_thaler_data_115.dbf&amp;#039; to &amp;#039;/cln/tst/ora_data1/clnt/data1/ts_thaler_data_115.dbf&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Recover the datafiles====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
recover datafile 125;&lt;br /&gt;
recover datafile 126;&lt;br /&gt;
recover datafile 127;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Set the relevant datafile online====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter database datafile 125 online;&lt;br /&gt;
alter database datafile 126 online;&lt;br /&gt;
alter database datafile 127 online;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Check all is well with the datafiles by using an appropriate statement====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 2000 pages 100&lt;br /&gt;
select file_id, file_name, status, online_status from dba_data_files where tablespace_name = &amp;#039;TS_THALER_DATA&amp;#039; order by 2;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Rename a datafile on 12c====&lt;br /&gt;
If you&amp;#039;re lucky enough to be on 12c, it&amp;#039;s one command - no need to offline the datafile!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SQL&amp;gt; alter database move datafile &amp;#039;/oracle/ora_data2/prod/data4/ts_thaler_data_113.dbf&amp;#039; to &amp;#039;/oracle/ora_data2/prod/data3/ts_thaler_data_113.dbf&amp;#039;;&lt;br /&gt;
&lt;br /&gt;
Database altered.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Pass parameter/argument into perl one-liner script from shell===&lt;br /&gt;
Trick? Just use ARGV to pass them in...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
FREQ=$(perl -e &amp;#039;my @CAL=split(&amp;quot;;&amp;quot;,$ARGV[0]);shift @CAL;print $CAL[$ARGV[1]];&amp;#039; -- &amp;quot;$LINE&amp;quot; $offset)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
DUMP_DATE=`perl -MTime::Local -e &amp;#039;print(timelocal(0,$ARGV[0],$ARGV[1],$ARGV[2],$ARGV[3],$ARGV[4]))&amp;#039; -- $MI $HH $DD $MM $YYYY`&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or export the variable from shell and access it via the ENV hash&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
export db=ENDP1&lt;br /&gt;
perl -p -i -e &amp;#039;s!DSMI_LOG.+$!DSMI_LOG           /oracle/$ENV{db}/admin/tdpoerror_$ENV{db}!&amp;#039; ${db}/admin/tdpo.opt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Return epoch seconds in Perl===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
perl -e &amp;#039;print time();&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or to convert a specific day of the year to epoch seconds&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
use POSIX;&lt;br /&gt;
my $epochsecs = mktime(0,0,0, $jday, 0, $year-1900);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or for a specific date (careful though - month is 0-11 not 1-12!...&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
use Time::Local;&lt;br /&gt;
#                          SS MM HH DD MM YYYY&lt;br /&gt;
my $epochsecs = timelocal (30,10,19,03,04,2014);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or more long-winded but delimited by anything...&amp;lt;br /&amp;gt;&lt;br /&gt;
Supply the date/time in any delimited format. Eg. YYYY-MM-DD:HH:MI&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/usr/bin/perl -w&lt;br /&gt;
use Time::Local;&lt;br /&gt;
&lt;br /&gt;
sub date2epoch { &lt;br /&gt;
  my($s) = @_;&lt;br /&gt;
  my($year, $month, $day, $hour, $minute, $second);&lt;br /&gt;
&lt;br /&gt;
  if($s =~ m{^\s*(\d{1,4})\W*0*(\d{1,2})\W*0*(\d{1,2})\W*0*&lt;br /&gt;
                 (\d{0,2})\W*0*(\d{0,2})\W*0*(\d{0,2})}x) {&lt;br /&gt;
    $year = $1;  $month = $2;   $day = $3;&lt;br /&gt;
    $hour = $4;  $minute = $5;  $second = $6;&lt;br /&gt;
    $hour |= 0;  $minute |= 0;  $second |= 0;  # defaults.&lt;br /&gt;
    $year = ($year&amp;lt;100 ? ($year&amp;lt;70 ? 2000+$year : 1900+$year) : $year);&lt;br /&gt;
    return timelocal($second,$minute,$hour,$day,$month-1,$year);  &lt;br /&gt;
  }&lt;br /&gt;
  return -1;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Return epoch seconds in DOS/VBS/Windows===&lt;br /&gt;
Paste this code into epoch.vbs&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
function date2epoch(p_date)&lt;br /&gt;
    date2epoch = DateDiff(&amp;quot;s&amp;quot;, &amp;quot;01/01/1970 00:00:00&amp;quot;, p_date)&lt;br /&gt;
end function&lt;br /&gt;
&lt;br /&gt;
Wscript.Echo date2epoch(Now())&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
and call from a DOS box like this&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cscript //nologo epoch.vbs&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Return date from epoch seconds in Perl===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
perl -e &amp;#039;print scalar (localtime (1243269270))&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Return epoch seconds from julian day number in Perl===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
use POSIX;&lt;br /&gt;
my ($year, $jday) = (2012,60);&lt;br /&gt;
my $epochsecs = mktime(0,0,0, $jday, 0, $year-1900);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Extract specific pieces of a date from an epoch timestamp in Perl===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
use POSIX;&lt;br /&gt;
# return localtime into an array&lt;br /&gt;
my @tm = localtime $epochsecs;&lt;br /&gt;
&lt;br /&gt;
my $yyyymmdd = strftime &amp;quot;%Y%m%d&amp;quot;, @tm;&lt;br /&gt;
print $yyyymmdd.&amp;quot;\n&amp;quot;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Return epoch seconds in Shell (linux)===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
date -d &amp;quot;2014/04/03 18:34:30&amp;quot; &amp;quot;+%s&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Return date from epoch seconds in Shell (linux)===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
date -d @1396542870&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Return epoch seconds in PL/SQL===&lt;br /&gt;
You cannot just use sysdate as that is timezone sensitive... (epoch seconds are in UTC/GMT)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select round((cast(sys_extract_utc(systimestamp) as date) - to_date(&amp;#039;01-JAN-1970 00:00:00&amp;#039;,&amp;#039;DD-MON-YYYY HH24:MI:SS&amp;#039;))*24*60*60) from dual;&lt;br /&gt;
or&lt;br /&gt;
select round((vd.created - to_date(&amp;#039;01-JAN-1970 00:00:00&amp;#039;,&amp;#039;DD-MON-YYYY HH24:MI:SS&amp;#039;))*24*60*60)  created from v$database vd;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
How long has this instance been up (in minutes)?&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select round((cast(sys_extract_utc(systimestamp) as date) - startup_time)*24*60) up_mins from v$instance;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Return date from epoch seconds in SQL===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select to_char(to_date(&amp;#039;19700101&amp;#039;,&amp;#039;YYYYMMDD&amp;#039;) + ((&amp;amp;epoch)/24/60/60),&amp;#039;DD-MON-YYYY HH24:MI:SS&amp;#039;) utc_date from dual;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===A database overview using the sys.plato package===&lt;br /&gt;
 exec plato.help;&lt;br /&gt;
or&lt;br /&gt;
 exec plato.complete(&amp;#039;HTM&amp;#039;);&lt;br /&gt;
&lt;br /&gt;
===List datafiles for a tablespace===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select *&lt;br /&gt;
from   dba_data_files&lt;br /&gt;
where  1=1&lt;br /&gt;
and    tablespace_name =&amp;#039;&amp;amp;ts_name&amp;#039;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Show graph of available and free space in tablespaces===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
-- =============================================================================&lt;br /&gt;
-- File Name    : http://www.oracle-base.com/dba/monitoring/ts_free_space.sql&lt;br /&gt;
-- Author       : Tim Hall&lt;br /&gt;
-- Description  : Displays a list of tablespaces and their used/full status.&lt;br /&gt;
-- Requirements : Access to the DBA views.&lt;br /&gt;
-- Call Syntax  : @ts_free_space.sql&lt;br /&gt;
-- Last Modified: 13-OCT-2012 - Created. Based on ts_full.sql&lt;br /&gt;
--&lt;br /&gt;
-- Modification History&lt;br /&gt;
-- ====================&lt;br /&gt;
-- When      Who               What&lt;br /&gt;
-- ========= ================= =================================================&lt;br /&gt;
-- 13-NOV-13 Stuart Barkley    Added cols free_pct and used_pct&lt;br /&gt;
-- =============================================================================&lt;br /&gt;
SET PAGESIZE 140 lines 180&lt;br /&gt;
COLUMN used_pct FORMAT A11&lt;br /&gt;
COLUMN max_used_pct FORMAT A11&lt;br /&gt;
&lt;br /&gt;
    SELECT tablespace_name                                                                      tablespace_name&lt;br /&gt;
    ,      size_mb                                                                              size_mb&lt;br /&gt;
    ,      free_mb                                                                              free_mb&lt;br /&gt;
    ,      TRUNC((free_mb/size_mb) * 100)                                                       free_pct&lt;br /&gt;
    ,      RPAD(&amp;#039; &amp;#039;|| RPAD(&amp;#039;X&amp;#039;,ROUND((size_mb-free_mb)/size_mb*10,0), &amp;#039;X&amp;#039;),11,&amp;#039;-&amp;#039;)              used_pct&lt;br /&gt;
    ,      max_size_mb                                                                          max_size_mb&lt;br /&gt;
    ,      max_free_mb                                                                          max_free_mb&lt;br /&gt;
    ,      TRUNC((max_free_mb/max_size_mb) * 100)                                               max_free_pct&lt;br /&gt;
    ,      RPAD(&amp;#039; &amp;#039;|| RPAD(&amp;#039;X&amp;#039;,ROUND((max_size_mb-max_free_mb)/max_size_mb*10,0), &amp;#039;X&amp;#039;),11,&amp;#039;-&amp;#039;)  max_used_pct&lt;br /&gt;
    from   (&lt;br /&gt;
           select a.tablespace_name                                         tablespace_name&lt;br /&gt;
           ,      b.size_mb                                                 size_mb&lt;br /&gt;
           ,      a.free_mb                                                 free_mb&lt;br /&gt;
           ,      b.max_size_mb                                             max_size_mb&lt;br /&gt;
           ,      a.free_mb + (b.max_size_mb - b.size_mb)                   max_free_mb&lt;br /&gt;
           from   (&lt;br /&gt;
                  select tablespace_name                                    tablespace_name&lt;br /&gt;
                  ,      trunc(sum(bytes)/1024/1024)                        free_mb&lt;br /&gt;
                  from   dba_free_space&lt;br /&gt;
                  group  by tablespace_name&lt;br /&gt;
                  ) a&lt;br /&gt;
           ,      (&lt;br /&gt;
                  select tablespace_name                                    tablespace_name&lt;br /&gt;
                  ,        trunc(sum(bytes)/1024/1024)                      size_mb&lt;br /&gt;
                  ,        trunc(sum(greatest(bytes,maxbytes))/1024/1024)   max_size_mb&lt;br /&gt;
                  from   dba_data_files&lt;br /&gt;
                  group by tablespace_name&lt;br /&gt;
                  ) b&lt;br /&gt;
           ,      v$instance vi&lt;br /&gt;
           where  a.tablespace_name = b.tablespace_name&lt;br /&gt;
           )&lt;br /&gt;
    order  by tablespace_name;&lt;br /&gt;
&lt;br /&gt;
set lines 80&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Another method for calculating free space in tablespace  using segments===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select df.tablespace_name &amp;quot;Tablespace&amp;quot;&lt;br /&gt;
,      totalusedspace &amp;quot;Used MB&amp;quot;&lt;br /&gt;
,      (df.totalspace - tu.totalusedspace) &amp;quot;Free MB&amp;quot;&lt;br /&gt;
,      df.totalspace &amp;quot;Total MB&amp;quot;&lt;br /&gt;
,      round(100 * ( (df.totalspace - tu.totalusedspace)/ df.totalspace)) &amp;quot;Pct. Free&amp;quot;&lt;br /&gt;
from   (&lt;br /&gt;
       select tablespace_name&lt;br /&gt;
,      round(sum(bytes) / 1048576) totalspace&lt;br /&gt;
       from   dba_data_files&lt;br /&gt;
       group  by tablespace_name&lt;br /&gt;
       ) df&lt;br /&gt;
,      (&lt;br /&gt;
       select round(sum(bytes)/(1024*1024)) totalusedspace&lt;br /&gt;
       ,      tablespace_name&lt;br /&gt;
       from   dba_segments&lt;br /&gt;
       group  by tablespace_name&lt;br /&gt;
       ) tu&lt;br /&gt;
where  df.tablespace_name = tu.tablespace_name;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Work out maximum possible size of a datafile===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select round( (4*1024*1024*value) / (1024*1024*1024) ,2) maxfilesizeingigabytes from v$parameter where name=&amp;#039;db_block_size&amp;#039;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or, as tablespaces can have block sizes differing from that of the init.ora parameter...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select round( (4*1024*1024*block_size) / (1024*1024*1024) ,2) maxfilesizeingigabytes from dba_tablespaces where tablespace_name=&amp;#039;&amp;amp;tablespace_name&amp;#039;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Show size and maxsize at datafile level===&lt;br /&gt;
datafiles&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set pages 100 lines 200&lt;br /&gt;
col file_name for a60&lt;br /&gt;
select sum(bytes)/1024/1024      mbytes_alloc&lt;br /&gt;
,      sum(maxbytes)/1024/1024   mbytes_max&lt;br /&gt;
,      file_name&lt;br /&gt;
from   sys.dba_data_files&lt;br /&gt;
group  by file_name&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
tempfiles&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set pages 100 lines 200&lt;br /&gt;
col file_name for a60&lt;br /&gt;
select sum(bytes)/1024/1024      mbytes_alloc&lt;br /&gt;
,      sum(maxbytes)/1024/1024   mbytes_max&lt;br /&gt;
,      file_name&lt;br /&gt;
from   sys.dba_temp_files&lt;br /&gt;
group  by file_name&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Resize the online redo logfiles===&lt;br /&gt;
Found a more concise, smarter way of doing it [http://www.oracle-wiki.net/startdocshowtorecreateredogrps here] - oracle-wiki.net&amp;lt;br /&amp;gt;&lt;br /&gt;
Switching logs too often? Redolog files too small?&amp;lt;br /&amp;gt;&lt;br /&gt;
* Show current log groups&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 1000&lt;br /&gt;
col group_member for a60&lt;br /&gt;
select l.group#          group_number&lt;br /&gt;
,      (bytes/1024/1024) megs&lt;br /&gt;
,      l.status          group_status&lt;br /&gt;
,      f.member          group_member&lt;br /&gt;
,      l.archived        archived&lt;br /&gt;
,      f.type            file_type&lt;br /&gt;
from   v$log     l&lt;br /&gt;
,      v$logfile f&lt;br /&gt;
where  l.group# = f.group#&lt;br /&gt;
order  by l.group#&lt;br /&gt;
,      f.member&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Create additional (bigger) groups&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
define SID=TIBQFW&lt;br /&gt;
alter database add logfile group 6  &amp;#039;/oracle/&amp;amp;SID/oradata1/redo1.log&amp;#039; size 1G;&lt;br /&gt;
alter database add logfile group 7  &amp;#039;/oracle/&amp;amp;SID/oradata2/redo2.log&amp;#039; size 1G;&lt;br /&gt;
alter database add logfile group 8  &amp;#039;/oracle/&amp;amp;SID/oradata3/redo3.log&amp;#039; size 1G;&lt;br /&gt;
alter database add logfile group 9  &amp;#039;/oracle/&amp;amp;SID/oradata1/redo4.log&amp;#039; size 1G;&lt;br /&gt;
alter database add logfile group 10 &amp;#039;/oracle/&amp;amp;SID/oradata2/redo5.log&amp;#039; size 1G;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or if you use multiple members...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter database add logfile group 6 (&amp;#039;/oracle/&amp;amp;SID/oradata1/redo/redo01a.log&amp;#039;, &amp;#039;/oracle/&amp;amp;SID/oradata1/redo01b&amp;#039;) size 50M;&lt;br /&gt;
alter database add logfile group 7 (&amp;#039;/oracle/&amp;amp;SID/oradata1/redo/redo02a.log&amp;#039;, &amp;#039;/oracle/&amp;amp;SID/oradata1/redo02b&amp;#039;) size 50M;&lt;br /&gt;
alter database add logfile group 8 (&amp;#039;/oracle/&amp;amp;SID/oradata1/redo/redo03a.log&amp;#039;, &amp;#039;/oracle/&amp;amp;SID/oradata1/redo03b&amp;#039;) size 50M;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Switch archivelogs until the new ones are current and the old ones are inactive&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter system switch logfile;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
If the old logs are not yet inactive, checkpoint the database&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter system checkpoint;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Drop the old groups&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter database drop logfile group 1;&lt;br /&gt;
alter database drop logfile group 2;&lt;br /&gt;
alter database drop logfile group 3;&lt;br /&gt;
alter database drop logfile group 4;&lt;br /&gt;
alter database drop logfile group 5;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Increase the existing size of a datafile===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter database datafile &amp;#039;&amp;amp;full_path_of_datafile&amp;#039; resize &amp;amp;new_meg_size.M;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Increase the max size of a tempfile===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter database tempfile &amp;#039;/oracle/ENDP1/oradata90/temp01.dbf&amp;#039; autoextend on maxsize unlimited;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Find out what processes are using the temp tablespace===&lt;br /&gt;
Temporary tablespace is used for sorting query results. Find them with this.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SELECT b.tablespace,b.segfile#,b.segblk#,b.blocks,a.sid,a.serial#,&lt;br /&gt;
a.username,a.osuser, a.status&lt;br /&gt;
FROM v$session a,v$sort_usage b&lt;br /&gt;
WHERE a.saddr = b.session_addr;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Increase the maximum size of a datafile===&lt;br /&gt;
Although this can be set lower than existing size, try not to. It makes the reports look weird!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter database&lt;br /&gt;
      datafile &amp;#039;&amp;amp;full_path_of_datafile&amp;#039;&lt;br /&gt;
      autoextend on&lt;br /&gt;
      maxsize &amp;amp;new_meg_size.m;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Find schemas (users) with objects created outside their default tablespace===&lt;br /&gt;
Indexes could be a notable exception if they are created in an index tablespace&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 200&lt;br /&gt;
col owner           for a20&lt;br /&gt;
col segment_name    for a45&lt;br /&gt;
col tablespace_name for a32&lt;br /&gt;
select owner&lt;br /&gt;
,      segment_name&lt;br /&gt;
,      tablespace_name&lt;br /&gt;
from   dba_segments&lt;br /&gt;
where  exists (select username from dba_users where username = owner)&lt;br /&gt;
and    tablespace_name != (select default_tablespace from dba_users where username = owner)&lt;br /&gt;
and    owner = &amp;#039;&amp;amp;owner&amp;#039;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Add a datafile to a tablespace===&lt;br /&gt;
&amp;#039;unlimited&amp;#039; will default to the maximum datafile size for the current db_block_size&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter tablepace &amp;amp;tablespace_name&lt;br /&gt;
      add datafile &amp;#039;&amp;amp;full_path_of_datafile&amp;#039;&lt;br /&gt;
      size 100M&lt;br /&gt;
      autoextend on&lt;br /&gt;
      next 100M&lt;br /&gt;
      maxsize unlimited&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===List all datafiles with their size===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set pages 1000 lines 2000&lt;br /&gt;
col filetype for a15&lt;br /&gt;
col name for a60&lt;br /&gt;
break on report&lt;br /&gt;
compute sum of gig on report&lt;br /&gt;
&lt;br /&gt;
select filetype&lt;br /&gt;
,      name&lt;br /&gt;
,      gig&lt;br /&gt;
from   (&lt;br /&gt;
       select &amp;#039;datafile&amp;#039; filetype&lt;br /&gt;
       ,      name&lt;br /&gt;
       ,      bytes/1024/1024 gig&lt;br /&gt;
       from   v$datafile&lt;br /&gt;
       union all&lt;br /&gt;
       select &amp;#039;tempfile&amp;#039; filetype&lt;br /&gt;
       ,      name&lt;br /&gt;
       ,      bytes/1024/1024&lt;br /&gt;
       from   v$tempfile&lt;br /&gt;
       union all&lt;br /&gt;
       select &amp;#039;logfile&amp;#039; filetype&lt;br /&gt;
       ,      lf.member &amp;quot;name&amp;quot;&lt;br /&gt;
       ,      l.bytes/1024/1024&lt;br /&gt;
       from   v$logfile lf&lt;br /&gt;
       ,      v$log     l&lt;br /&gt;
       where  1=1&lt;br /&gt;
       and    lf.group# = l.group#&lt;br /&gt;
       ) used&lt;br /&gt;
,      (&lt;br /&gt;
       select sum(bytes)/1024/1024&lt;br /&gt;
       from   dba_free_space&lt;br /&gt;
       ) free&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Database size (How big is my database?)===&lt;br /&gt;
There are different interpretations of what constitutes the size of a database...&amp;lt;br /&amp;gt;&lt;br /&gt;
Is it the space allocated to the datafiles or only the space taken up by the data? Are tempfiles included? Are redo logs included? etc...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 132&lt;br /&gt;
col dbname for a9  heading &amp;quot;Database&amp;quot;&lt;br /&gt;
col dbsize for a15 heading &amp;quot;Size&amp;quot;&lt;br /&gt;
col dbused for a15 heading &amp;quot;Used space&amp;quot;&lt;br /&gt;
col dbfree for a15 heading &amp;quot;Free space&amp;quot;&lt;br /&gt;
with used_space as&lt;br /&gt;
(&lt;br /&gt;
select  bytes&lt;br /&gt;
from    v$datafile&lt;br /&gt;
union   all&lt;br /&gt;
select  bytes&lt;br /&gt;
from    v$tempfile&lt;br /&gt;
union   all&lt;br /&gt;
select  bytes&lt;br /&gt;
from    v$log&lt;br /&gt;
)&lt;br /&gt;
, free_space as&lt;br /&gt;
(&lt;br /&gt;
select sum(bytes) sum_bytes&lt;br /&gt;
from dba_free_space&lt;br /&gt;
)&lt;br /&gt;
select vd.name                                                                                            dbname&lt;br /&gt;
,      round(sum(used_space.bytes)/1024/1024/1024 ) || &amp;#039; GB&amp;#039;                                              dbsize&lt;br /&gt;
,      round(sum(used_space.bytes)/1024/1024/1024 ) - round(free_space.sum_bytes/1024/1024/1024) || &amp;#039; GB&amp;#039; dbused&lt;br /&gt;
,      round(free_space.sum_bytes/1024/1024/1024) || &amp;#039; GB&amp;#039;                                                dbfree&lt;br /&gt;
from   free_space&lt;br /&gt;
,      used_space&lt;br /&gt;
,      v$database vd&lt;br /&gt;
group  by vd.name&lt;br /&gt;
,      free_space.sum_bytes&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Drop datafile from temp tablespace===&lt;br /&gt;
Database is completely stuck because the temporary tablespace has grown to fill all available room.&amp;lt;br /&amp;gt;&lt;br /&gt;
Look around for at least some log files to delete in order to get connected (audit files, sqlnet logs, listener logs)&amp;lt;br /&amp;gt;&lt;br /&gt;
Once connected, change the default temporary tablespace to a small one so we can remove the original.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
create temporary tablespace temp2 tempfile &amp;#039;/oracle/RMANV12/oradata2/temp2.dbf&amp;#039; size 5M;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter database default temporary tablespace temp2;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
I found trying to drop the datafile like this didn&amp;#039;t work, just hung there (probably active tranactions)...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
drop tablespace temp including contents and datafiles;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
So did it like this...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter database tempfile &amp;#039;/oracle/RMANV12/oradata2/temp.dbf&amp;#039; drop including datafiles;&lt;br /&gt;
&lt;br /&gt;
Database altered.&lt;br /&gt;
&lt;br /&gt;
drop tablespace temp including contents and datafiles;&lt;br /&gt;
&lt;br /&gt;
Tablespace dropped.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
... an alternative would be to find the sessions using the temp space and kill them...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select sid, serial#, status from v$session where serial# in (select session_num from v$sort_usage);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Then to be neat and tidy, rename the temp2 tablespace back to temp.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
create temporary tablespace temp tempfile &amp;#039;/oracle/RMANV12/oradata2/temp.dbf&amp;#039; size 256M reuse autoextend on next 128M maxsize 1G;&lt;br /&gt;
alter database default temporary tablespace temp;&lt;br /&gt;
drop tablespace temp2 including contents and datafiles;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Although the last statement will not work until any transactions using it have been rolled back or committed.&lt;br /&gt;
&lt;br /&gt;
===List files that are in hot-backup mode===&lt;br /&gt;
 set lines 100&lt;br /&gt;
 set pages 100&lt;br /&gt;
 col name format a60&lt;br /&gt;
 &lt;br /&gt;
 select df.name&lt;br /&gt;
 ,      b.status&lt;br /&gt;
 ,      to_char(time, &amp;#039;hh24:mi:ss dd/mm/yyyy&amp;#039;) time&lt;br /&gt;
 from   v$datafile   df&lt;br /&gt;
 ,      v$backup     b&lt;br /&gt;
 where  1=1&lt;br /&gt;
 and    df.file# = b.file#&lt;br /&gt;
 and    b.status = &amp;#039;ACTIVE&amp;#039;&lt;br /&gt;
 order  by b.file#;&lt;br /&gt;
&lt;br /&gt;
===Waiting for snapshot control file enqueue===&lt;br /&gt;
Script to identify sessions causing RMAN to hang because of &amp;#039;waiting for snapshot control file enqueue&amp;#039; message&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 2000&lt;br /&gt;
col killer     for a70&lt;br /&gt;
col program    for a20&lt;br /&gt;
col module     for a20&lt;br /&gt;
col action     for a20&lt;br /&gt;
col logon_time for a20&lt;br /&gt;
&lt;br /&gt;
select &amp;#039;alter system disconnect session &amp;#039;&amp;#039;&amp;#039;||s.sid||&amp;#039;,&amp;#039;||s.serial#||&amp;#039;&amp;#039;&amp;#039; immediate;&amp;#039; killer&lt;br /&gt;
,      username&lt;br /&gt;
,      program&lt;br /&gt;
,      module&lt;br /&gt;
,      action&lt;br /&gt;
,      logon_time&lt;br /&gt;
from   v$session s&lt;br /&gt;
,      v$enqueue_lock l&lt;br /&gt;
where  l.sid  = s.sid&lt;br /&gt;
and    l.type = &amp;#039;CF&amp;#039;&lt;br /&gt;
and    l.id1  = 0&lt;br /&gt;
and    l.id2  = 2&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Info on blocking processes===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select s1.username || &amp;#039;@&amp;#039; || s1.machine&lt;br /&gt;
       || &amp;#039; ( SID=&amp;#039; || s1.sid || &amp;#039; )  is blocking &amp;#039;&lt;br /&gt;
       || s2.username || &amp;#039;@&amp;#039; || s2.machine || &amp;#039; ( SID=&amp;#039; || s2.sid || &amp;#039; ) &amp;#039;  blocking_status&lt;br /&gt;
from   v$lock l1&lt;br /&gt;
,      v$session s1&lt;br /&gt;
,      v$lock l2&lt;br /&gt;
,      v$session s2&lt;br /&gt;
where  s1.sid     = l1.sid&lt;br /&gt;
and    s2.sid     = l2.sid&lt;br /&gt;
and    l1.block   = 1&lt;br /&gt;
and    l2.request &amp;gt; 0&lt;br /&gt;
and    l1.id1     = l2.id1&lt;br /&gt;
and    l2.id2     = l2.id2&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
session doing the blocking&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select *&lt;br /&gt;
from  v$lock l1&lt;br /&gt;
where 1=1&lt;br /&gt;
and   block = 1 ;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
sessions being blocked&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select *&lt;br /&gt;
from   v$lock l1&lt;br /&gt;
where  1=1&lt;br /&gt;
and    id2 = 85203&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
info on session doing the blocking&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select row_wait_obj#, row_wait_file#, row_wait_block#, row_wait_row#&lt;br /&gt;
from   v$session&lt;br /&gt;
where  sid = 234&lt;br /&gt;
&lt;br /&gt;
select do.object_name&lt;br /&gt;
,      row_wait_obj#&lt;br /&gt;
,      row_wait_file#&lt;br /&gt;
,      row_wait_block#&lt;br /&gt;
,      row_wait_row#&lt;br /&gt;
,      dbms_rowid.rowid_create ( 1, ROW_WAIT_OBJ#, ROW_WAIT_FILE#, ROW_WAIT_BLOCK#, ROW_WAIT_ROW# ) row_id&lt;br /&gt;
from   v$session   s&lt;br /&gt;
,      dba_objects do&lt;br /&gt;
where  sid=234&lt;br /&gt;
and    s.ROW_WAIT_OBJ# = do.OBJECT_ID;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Show locked objects===&lt;br /&gt;
 set lines 100&lt;br /&gt;
 set pages 999&lt;br /&gt;
 col username   format a20&lt;br /&gt;
 col sess_id    format a10&lt;br /&gt;
 col object     format a25&lt;br /&gt;
 col mode_held  format a10&lt;br /&gt;
 select oracle_username||&amp;#039; (&amp;#039;||s.osuser||&amp;#039;)&amp;#039; username&lt;br /&gt;
 ,      s.sid||&amp;#039;,&amp;#039;||s.serial# sess_id&lt;br /&gt;
 ,      owner||&amp;#039;.&amp;#039;||object_name object&lt;br /&gt;
 ,      object_type&lt;br /&gt;
 ,      decode ( l.block&lt;br /&gt;
               , 0, &amp;#039;Not Blocking&amp;#039;&lt;br /&gt;
               , 1, &amp;#039;Blocking&amp;#039;&lt;br /&gt;
               , 2, &amp;#039;Global&amp;#039;&lt;br /&gt;
               ) status&lt;br /&gt;
 ,      decode ( v.locked_mode&lt;br /&gt;
               , 0, &amp;#039;None&amp;#039;&lt;br /&gt;
               , 1, &amp;#039;Null&amp;#039;&lt;br /&gt;
               , 2, &amp;#039;Row-S (SS)&amp;#039;&lt;br /&gt;
               , 3, &amp;#039;Row-X (SX)&amp;#039;&lt;br /&gt;
               , 4, &amp;#039;Share&amp;#039;&lt;br /&gt;
               , 5, &amp;#039;S/Row-X (SSX)&amp;#039;&lt;br /&gt;
               , 6, &amp;#039;Exclusive&amp;#039;, TO_CHAR(lmode)&lt;br /&gt;
               ) mode_held&lt;br /&gt;
 from   v$locked_object v&lt;br /&gt;
 ,      dba_objects d&lt;br /&gt;
 ,      v$lock l&lt;br /&gt;
 ,      v$session s&lt;br /&gt;
 where  1=1&lt;br /&gt;
 and    v.object_id = d.object_id&lt;br /&gt;
 and    v.object_id = l.id1&lt;br /&gt;
 and    v.session_id = s.sid&lt;br /&gt;
 order  by oracle_username&lt;br /&gt;
 ,	session_id;&lt;br /&gt;
&lt;br /&gt;
===Show which row is locked===&lt;br /&gt;
 select do.object_name&lt;br /&gt;
 ,      row_wait_obj#&lt;br /&gt;
 ,      row_wait_file#&lt;br /&gt;
 ,      row_wait_block#&lt;br /&gt;
 ,      row_wait_row#&lt;br /&gt;
 ,      dbms_rowid.rowid_create (1, ROW_WAIT_OBJ#, ROW_WAIT_FILE#, ROW_WAIT_BLOCK#, ROW_WAIT_ROW#)&lt;br /&gt;
 from   v$session   s&lt;br /&gt;
 ,      dba_objects do&lt;br /&gt;
 where  1=1&lt;br /&gt;
 and    s.ROW_WAIT_OBJ# = do.OBJECT_ID&lt;br /&gt;
 and    sid             = &amp;amp;sid;&lt;br /&gt;
&lt;br /&gt;
===Check what is audited on a database===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set pagesize 100&lt;br /&gt;
set linesize 256&lt;br /&gt;
select audit_option,success,failure from dba_stmt_audit_opts;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===How old is the oldest audit record?===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select extract (day from (systimestamp - min(ntimestamp#))) days_old from aud$;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Check what objects are being audited===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
tti col 60 &amp;#039;Object Audit Options (dba_obj_audit_opts)&amp;#039; skip col 50 &amp;#039;A=By Access, S=By Session. Left=on success, right=on failure&amp;#039; skip 2&lt;br /&gt;
set lines 1000 pages 100&lt;br /&gt;
col alt for a3 head &amp;quot;Alt|er&amp;quot;&lt;br /&gt;
col aud for a3 head &amp;quot;Aud|it&amp;quot;&lt;br /&gt;
col com for a3 head &amp;quot;Com|ent&amp;quot;&lt;br /&gt;
col del for a3 head &amp;quot;Del|ete&amp;quot;&lt;br /&gt;
col gra for a3 head &amp;quot;Gra|nt&amp;quot;&lt;br /&gt;
col ind for a3 head &amp;quot;Ind|ex&amp;quot;&lt;br /&gt;
col ins for a3 head &amp;quot;Ins|ert&amp;quot;&lt;br /&gt;
col loc for a3 head &amp;quot;Lo|ck&amp;quot;&lt;br /&gt;
col ren for a3 head &amp;quot;Ren|ame&amp;quot;&lt;br /&gt;
col sel for a3 head &amp;quot;Sel|ect&amp;quot;&lt;br /&gt;
col upd for a3 head &amp;quot;Upd|ate&amp;quot;&lt;br /&gt;
col ref for a3 head &amp;quot;Ref|rnc&amp;quot;&lt;br /&gt;
col exe for a3 head &amp;quot;Exe|cut&amp;quot;&lt;br /&gt;
col cre for a3 head &amp;quot;Cre|ate&amp;quot;&lt;br /&gt;
col rea for a3 head &amp;quot;Re|ad&amp;quot;&lt;br /&gt;
col wri for a3 head &amp;quot;Wri|te&amp;quot;&lt;br /&gt;
col fbk for a3 head &amp;quot;Fla|sh&amp;quot;&lt;br /&gt;
	&lt;br /&gt;
select *&lt;br /&gt;
from   dba_obj_audit_opts&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Procedure to delete old audit records===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select text from all_source where lower(name)=&amp;#039;purge_audit_trail&amp;#039;;&lt;br /&gt;
&lt;br /&gt;
TEXT&lt;br /&gt;
------------------------------------------------------------------------------------------------&lt;br /&gt;
PROCEDURE purge_audit_trail IS&lt;br /&gt;
BEGIN&lt;br /&gt;
-- set the last archive timestamp&lt;br /&gt;
DBMS_AUDIT_MGMT.SET_LAST_ARCHIVE_TIMESTAMP(&lt;br /&gt;
       audit_trail_type    =&amp;gt; DBMS_AUDIT_MGMT.AUDIT_TRAIL_AUD_STD,&lt;br /&gt;
       last_archive_time   =&amp;gt; systimestamp - interval &amp;#039;365&amp;#039; day,&lt;br /&gt;
       rac_instance_number =&amp;gt; null&lt;br /&gt;
                                          );&lt;br /&gt;
-- purge audit trail till last archive timestamp&lt;br /&gt;
DBMS_AUDIT_MGMT.CLEAN_AUDIT_TRAIL( audit_trail_type =&amp;gt; DBMS_AUDIT_MGMT.AUDIT_TRAIL_AUD_STD&lt;br /&gt;
, use_last_arch_timestamp =&amp;gt; TRUE);&lt;br /&gt;
&lt;br /&gt;
END purge_audit_trail;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Job setup to run the audit purge===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
BEGIN&lt;br /&gt;
sys.dbms_scheduler.create_job(&lt;br /&gt;
    job_name =&amp;gt; &amp;#039;&amp;quot;SYS&amp;quot;.&amp;quot;PURGE_AUDIT_TRAIL_JOB&amp;quot;&amp;#039;,&lt;br /&gt;
    job_type =&amp;gt; &amp;#039;STORED_PROCEDURE&amp;#039;,&lt;br /&gt;
    job_action =&amp;gt; &amp;#039;&amp;quot;SYS&amp;quot;.&amp;quot;PURGE_AUDIT_TRAIL&amp;quot;&amp;#039;,&lt;br /&gt;
    repeat_interval =&amp;gt; &amp;#039;FREQ=DAILY;BYHOUR=20;BYMINUTE=0;BYSECOND=0&amp;#039;,&lt;br /&gt;
    start_date =&amp;gt; to_timestamp_tz(&amp;#039;2012-02-22 Europe/Paris&amp;#039;, &amp;#039;YYYY-MM-DD TZR&amp;#039;),&lt;br /&gt;
    job_class =&amp;gt; &amp;#039;&amp;quot;DEFAULT_JOB_CLASS&amp;quot;&amp;#039;,&lt;br /&gt;
    comments =&amp;gt; &amp;#039;purge audit trails until last archive timestamp&amp;#039;,&lt;br /&gt;
    auto_drop =&amp;gt; FALSE,&lt;br /&gt;
    enabled =&amp;gt; FALSE&lt;br /&gt;
);&lt;br /&gt;
sys.dbms_scheduler.set_attribute( name =&amp;gt; &amp;#039;&amp;quot;SYS&amp;quot;.&amp;quot;PURGE_AUDIT_TRAIL_JOB&amp;quot;&amp;#039;, attribute =&amp;gt; &amp;#039;logging_level&amp;#039;, value =&amp;gt; DBMS_SCHEDULER.LOGGING_OFF);&lt;br /&gt;
sys.dbms_scheduler.set_attribute( name =&amp;gt; &amp;#039;&amp;quot;SYS&amp;quot;.&amp;quot;PURGE_AUDIT_TRAIL_JOB&amp;quot;&amp;#039;, attribute =&amp;gt; &amp;#039;job_weight&amp;#039;, value =&amp;gt; 1);&lt;br /&gt;
sys.dbms_scheduler.enable( &amp;#039;&amp;quot;SYS&amp;quot;.&amp;quot;PURGE_AUDIT_TRAIL_JOB&amp;quot;&amp;#039; );&lt;br /&gt;
END;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===A list of all SIDs in oratab that should restart after a server boot===&lt;br /&gt;
Using awk&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
awk -F: &amp;#039;$NF==&amp;quot;Y&amp;quot; &amp;amp;&amp;amp; $1 !~/[#]/ {print $1}&amp;#039;  /etc/oratab&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Using perl&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
perl -F: -ne &amp;#039;print &amp;quot;$1\n&amp;quot; if /(\w+):(.+):Y$/&amp;#039; /etc/oratab&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Move the admin directories to a new location===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
./all_db_do &amp;quot;alter system set audit_file_dest=&amp;#039;/oracle/&amp;amp;SID/admin/adump&amp;#039; scope=spfile;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
./all_db_do &amp;quot;shutdown immediate&amp;quot;&lt;br /&gt;
&lt;br /&gt;
for db in `awk -F: &amp;#039;NF &amp;amp;&amp;amp; $1 !~/[#*]/ {print $1}&amp;#039;  /etc/oratab`&lt;br /&gt;
do&lt;br /&gt;
    echo $db&lt;br /&gt;
    mkdir -p /oracle/${db}/admin&lt;br /&gt;
    echo &amp;quot;/oracle/${db}/admin created&amp;quot;&lt;br /&gt;
    mv /oracle/admin/${db}/adump /oracle/${db}/admin/&lt;br /&gt;
    mv /oracle/admin/${db}/dpdump /oracle/${db}/admin/&lt;br /&gt;
    echo &amp;quot;Moved /oracle/admin/${db}/adump to /oracle/${db}/admin/&amp;quot;&lt;br /&gt;
done&lt;br /&gt;
&lt;br /&gt;
./all_db_do startup&lt;br /&gt;
&lt;br /&gt;
./all_db_do &amp;quot;create pfile from spfile;&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Check if the Standby database is up-to-date with the primary database===&lt;br /&gt;
 select arch.thread# &amp;quot;Thread&amp;quot;&lt;br /&gt;
 ,      arch.sequence# &amp;quot;Last Sequence Received&amp;quot;&lt;br /&gt;
 ,      appl.sequence# &amp;quot;Last Sequence Applied&amp;quot;&lt;br /&gt;
 ,      (arch.sequence# - appl.sequence#) &amp;quot;Difference&amp;quot;&lt;br /&gt;
 from   (&lt;br /&gt;
        select thread#&lt;br /&gt;
        ,      sequence#&lt;br /&gt;
        from   v$archived_log&lt;br /&gt;
        where  1=1&lt;br /&gt;
        and    ( thread#,first_time ) in (&lt;br /&gt;
                                         select thread#, max(first_time)&lt;br /&gt;
                                         from   v$archived_log&lt;br /&gt;
                                         group  by thread#&lt;br /&gt;
                                         )&lt;br /&gt;
        ) arch&lt;br /&gt;
        ,&lt;br /&gt;
        (&lt;br /&gt;
        select thread#&lt;br /&gt;
        ,      sequence#&lt;br /&gt;
        from   v$log_history&lt;br /&gt;
        where  1=1&lt;br /&gt;
        and    ( thread#,first_time ) in ( select thread# ,max(first_time)&lt;br /&gt;
                                           from   v$log_history&lt;br /&gt;
                                           group  by thread#&lt;br /&gt;
                                          )&lt;br /&gt;
        ) appl&lt;br /&gt;
 where  1=1&lt;br /&gt;
 and    arch.thread# = appl.thread#&lt;br /&gt;
 order  by 1;&lt;br /&gt;
&lt;br /&gt;
===Check for gaps on the Standby database===&lt;br /&gt;
Run this on the standby&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select thread#, low_sequence#, high_sequence# from v$archive_gap;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or run this on the Primary to see the latest generated archive...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select thread#   &amp;quot;Thread&amp;quot;&lt;br /&gt;
,      sequence# &amp;quot;Last sequence generated&amp;quot;&lt;br /&gt;
from   v$archived_log&lt;br /&gt;
where  (thread#, first_time) in ( select thread#, max(first_time)&lt;br /&gt;
                                  from   v$archived_log&lt;br /&gt;
                                  group  by thread#&lt;br /&gt;
                                )&lt;br /&gt;
order  by 1&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
and run this on the standby to check for received but not yet applied logs (this could be normal if a lag has been set)...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select arch.thread# &amp;quot;Thread&amp;quot;&lt;br /&gt;
,      arch.sequence# &amp;quot;Last sequence received&amp;quot;&lt;br /&gt;
,      appl.sequence# &amp;quot;Last sequence applied&amp;quot;&lt;br /&gt;
,      (arch.sequence#-appl.sequence#) &amp;quot;Difference&amp;quot;&lt;br /&gt;
from   (&lt;br /&gt;
       select thread#&lt;br /&gt;
       ,      sequence#&lt;br /&gt;
       from   v$archived_log&lt;br /&gt;
       where  (thread#,first_time ) in (select thread#, max(first_time)&lt;br /&gt;
                                        from   v$archived_log&lt;br /&gt;
                                        group  by thread#&lt;br /&gt;
                                       )&lt;br /&gt;
       ) arch&lt;br /&gt;
,      (&lt;br /&gt;
       select thread#&lt;br /&gt;
       ,      sequence#&lt;br /&gt;
       from   v$log_history&lt;br /&gt;
       where  (thread#,first_time ) in (select thread#, max(first_time)&lt;br /&gt;
                                        from   v$log_history&lt;br /&gt;
                                        group  by thread#&lt;br /&gt;
                                       )&lt;br /&gt;
      ) appl&lt;br /&gt;
where arch.thread# = appl.thread#&lt;br /&gt;
order by 1&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Compare the results from Primary and Secondary to detect possible network problems or other errors in shipping.&lt;br /&gt;
&lt;br /&gt;
===Ignore case-sensitive passwords in 11g (deprecated in 12c)===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter system set SEC_CASE_SENSITIVE_LOGON = false scope=both&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===External table for the Alert log (pre 11g)===&lt;br /&gt;
Modified to use (the better) scripts found on [http://www.adp-gmbh.ch/ora/admin/scripts/read_alert_log.html Rene Nyffenegger&amp;#039;s site]&amp;lt;br /&amp;gt;&lt;br /&gt;
This script generates the required DDL for the alertlog table&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
column db    new_value _DB    noprint;&lt;br /&gt;
column bdump new_value _bdump noprint;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Alert log (11g+)===&lt;br /&gt;
This reads the log.xml file (which contains the same information as alert.log)&amp;lt;br /&amp;gt;&lt;br /&gt;
Show the messages put in the alert log in the last 24 hours&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select substr(MESSAGE_TEXT, 1, 300) message_text&lt;br /&gt;
,      count(*) cnt&lt;br /&gt;
from   X$DBGALERTEXT&lt;br /&gt;
where  1=1&lt;br /&gt;
and    (MESSAGE_TEXT like &amp;#039;%ORA-%&amp;#039; or upper(MESSAGE_TEXT) like &amp;#039;%ERROR%&amp;#039;)&lt;br /&gt;
and    cast(ORIGINATING_TIMESTAMP as DATE) &amp;gt; sysdate - &amp;amp;days_ago/1440&lt;br /&gt;
group  by substr(MESSAGE_TEXT, 1, 300)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
There is also a fixed table X$DBGDIREXT which returns all file and directory names under [diagnostic_dest]/diag directory:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select lpad(&amp;#039; &amp;#039;,lvl,&amp;#039; &amp;#039;)||logical_file file_name&lt;br /&gt;
from   x$dbgdirext&lt;br /&gt;
where  rownum &amp;lt;=20;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Directory paths available in v$diag_info===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 2000&lt;br /&gt;
col name for a35&lt;br /&gt;
col value for a100 wrap&lt;br /&gt;
select * from v$diag_info;&lt;br /&gt;
&lt;br /&gt;
   INST_ID NAME                                VALUE                                                                                                    CON_ID&lt;br /&gt;
---------- ----------------------------------- ---------------------------------------------------------------------------------------------------- ----------&lt;br /&gt;
         1 Diag Enabled                        TRUE                                                                                                          0&lt;br /&gt;
         1 ADR Base                            /cln/prg/ora_bin2/app/oracle                                                                               0&lt;br /&gt;
         1 ADR Home                            /cln/prg/ora_bin2/app/oracle/diag/rdbms/bild/bild                                                          0&lt;br /&gt;
         1 Diag Trace                          /cln/prg/ora_bin2/app/oracle/diag/rdbms/bild/bild/trace                                                    0&lt;br /&gt;
         1 Diag Alert                          /cln/prg/ora_bin2/app/oracle/diag/rdbms/bild/bild/alert                                                    0&lt;br /&gt;
         1 Diag Incident                       /cln/prg/ora_bin2/app/oracle/diag/rdbms/bild/bild/incident                                                 0&lt;br /&gt;
         1 Diag Cdump                          /cln/prg/ora_bin2/app/oracle/diag/rdbms/bild/bild/cdump                                                    0&lt;br /&gt;
         1 Health Monitor                      /cln/prg/ora_bin2/app/oracle/diag/rdbms/bild/bild/hm                                                       0&lt;br /&gt;
         1 Default Trace File                  /cln/prg/ora_bin2/app/oracle/diag/rdbms/bild/bild/trace/bild_ora_44696768.trc                              0&lt;br /&gt;
         1 Active Problem Count                0                                                                                                             0&lt;br /&gt;
         1 Active Incident Count               0                                                                                                             0&lt;br /&gt;
&lt;br /&gt;
11 rows selected.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Find out the names of the active trace files for the running processes===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select pid, program, tracefile from v$process;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Request was to duplicate a large tablespace from production to test environment===&lt;br /&gt;
...but rather than copy the terabytes of data, create the destination tablespace with just the most recent months data&amp;lt;br /&amp;gt;&lt;br /&gt;
====See what the source data looks like====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
col table_owner    for a20&lt;br /&gt;
col table_name     for a30&lt;br /&gt;
col partition_name for a20&lt;br /&gt;
set pages 100 lines 1000&lt;br /&gt;
&lt;br /&gt;
select table_owner&lt;br /&gt;
,      table_name&lt;br /&gt;
,      partition_name&lt;br /&gt;
,      partition_position&lt;br /&gt;
,      tablespace_name&lt;br /&gt;
from   dba_tab_partitions&lt;br /&gt;
where  tablespace_name = &amp;#039;ADS_ARCHIVE&amp;#039;&lt;br /&gt;
order  by 1,2,3,4&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This query produces something like this...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
TABLE_OWNER          TABLE_NAME                     PARTITION_NAME       PARTITION_POSITION TABLESPACE_NAME                &lt;br /&gt;
-------------------- ------------------------------ -------------------- ------------------ ------------------------------ &lt;br /&gt;
ADS_ARCHIVE          BIL_DAY_INV_CTR_ARC            Y2017_Q1_M01_D01                      1 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          BIL_HIS_DETAIL_FAC_ARC         Y2016_Q2_M05_D04                      1 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          BIL_HIS_DETAIL_FAC_ARC         Y2016_Q2_M05_D09                      2 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          BIL_MTH_INV_CTR_ARC            Y2017_Q1_M01_D01                      1 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          FAH_DAY_CBA_BGAAP_ARC          Y2011_Q4_M12_D30                      1 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          FAH_DAY_CBA_BGAAP_ARC          Y2011_Q4_M12_D31                      2 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          FAH_DAY_CBA_IFRS_ARC           Y2011_Q4_M12_D30                      1 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          FAH_DAY_CBA_IFRS_ARC           Y2011_Q4_M12_D31                      2 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          FAH_DAY_MVT_BGAAP_ARC          Y2011_Q4_M12_D30                      1 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          FAH_DAY_MVT_BGAAP_ARC          Y2011_Q4_M12_D31                      2 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          FAH_DAY_MVT_BGAAP_ARC          Y2012_Q1_M03_D31                      3 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          FAH_DAY_MVT_BGAAP_ARC          Y2012_Q2_M04_D01                      4 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          FAH_DAY_MVT_BGAAP_ARC          Y2012_Q4_M10_D12                      5 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          FAH_DAY_MVT_BGAAP_ARC          Y2012_Q4_M10_D13                      6 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          FAH_DAY_MVT_BGAAP_ARC          Y2012_Q4_M10_D14                      7 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          FAH_DAY_MVT_BGAAP_ARC_TST      Y2011_Q4_M12_D30                      1 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          FAH_DAY_MVT_BGAAP_ARC_TST      Y2011_Q4_M12_D31                      2 ADS_ARCHIVE&lt;br /&gt;
...&lt;br /&gt;
ADS_ARCHIVE          SBP_HIS_LINES_ARC              P_LS                                  3 ADS_ARCHIVE                  &lt;br /&gt;
ADS_ARCHIVE          THA_DAY_INV_CTR_ARC            Y2011_Q4_M12_D30                      1 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          THA_DAY_INV_CTR_ARC            Y2011_Q4_M12_D31                      2 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          THA_INV_HEAVY_ARC              Y2011_Q4_M12_D30                      1 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          THA_INV_HEAVY_ARC              Y2011_Q4_M12_D31                      2 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          THA_INV_LIGHT_ARC              Y2011_Q4_M12_D30                      1 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          THA_INV_LIGHT_ARC              Y2012_Q4_M10_D12                      2 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          THA_INV_LIGHT_ARC              Y2012_Q4_M10_D13                      3 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          THA_INV_LIGHT_ARC              Y2012_Q4_M10_D15                      4 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          THA_INV_LIGHT_ARC              Y2012_Q4_M10_D16                      5 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          THA_INV_LIGHT_ARC              Y2012_Q4_M10_D17                      6 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          THA_INV_LIGHT_ARC              Y2012_Q4_M10_D18                      7 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          THA_INV_LIGHT_ARC              Y2012_Q4_M10_D19                      8 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          THA_INV_LIGHT_ARC              Y2012_Q4_M10_D20                      9 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          THA_INV_LIGHT_ARC              Y2012_Q4_M10_D21                     10 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          THA_INV_LIGHT_ARC              Y2012_Q4_M10_D22                     11 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          THA_INV_LIGHT_ARC              Y2012_Q4_M10_D23                     12 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          THA_INV_LIGHT_ARC              Y2012_Q4_M10_D24                     13 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          THA_MTH_INV_CTR_ARC            Y2011_Q4_M12_D30                      1 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          THA_MTH_INV_CTR_ARC            Y2011_Q4_M12_D31                      2 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          THA_MTH_INV_CTR_ARC            Y2013_Q2_M04_D30                      3 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          XBD01_TEMP_HIS_ARC             Y2012_Q4_M12_D31                      1 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          T_RPT_RECO_THA_INV_ACC_ARC     Y2011_Q4_M12_D30                      1 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          T_RPT_RECO_THA_INV_ACC_ARC     Y2011_Q4_M12_D31                      2 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          T_RPT_RECO_THA_INV_MTH_ARC     Y2011_Q4_M12_D30                      1 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          T_RPT_RECO_THA_INV_MTH_ARC     Y2011_Q4_M12_D31                      2 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          XBD01_TEMP_HIS_ARC             Y2012_Q4_M12_D31                      1 ADS_ARCHIVE&lt;br /&gt;
ADS_DBA              FAH_DAY_CBA_BGAAP              Y2016_Q3_M07_D12                   1657 ADS_ARCHIVE&lt;br /&gt;
ADS_DBA              FAH_DAY_CBA_BGAAP              Y2016_Q4_M12_D13                   1811 ADS_ARCHIVE&lt;br /&gt;
ADS_DBA              FAH_DAY_MVT_IFRS               Y2016_Q4_M10_D10                   1654 ADS_ARCHIVE&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Capture the tablespace metadata====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set long 1000000&lt;br /&gt;
select dbms_metadata.get_ddl ( &amp;#039;TABLESPACE&amp;#039;, &amp;#039;ADS_ARCHIVE&amp;#039;) from dual&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
produces...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
CREATE TABLESPACE &amp;quot;ADS_ARCHIVE&amp;quot; DATAFILE&lt;br /&gt;
  &amp;#039;/oracle/tst/ora_data3/adst/ads_archive01.dbf&amp;#039; SIZE 104857600&lt;br /&gt;
  AUTOEXTEND ON NEXT 104857600 MAXSIZE 32000M,&lt;br /&gt;
...&lt;br /&gt;
  &amp;#039;/oracle/tst/ora_data3/adst/ads_archive66.dbf&amp;#039; SIZE 104857600&lt;br /&gt;
  AUTOEXTEND ON NEXT 104857600 MAXSIZE 3200M,&lt;br /&gt;
  LOGGING ONLINE PERMANENT BLOCKSIZE 8192&lt;br /&gt;
  EXTENT MANAGEMENT LOCAL AUTOALLOCATE DEFAULT&lt;br /&gt;
 NOCOMPRESS  SEGMENT SPACE MANAGEMENT AUTO&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Capture the tablespace objects&amp;#039; metadata====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cat&amp;lt;&amp;lt;EOCAT &amp;gt;expdp_adst_ads_archive_metadata.par&lt;br /&gt;
userid=&amp;#039;/ as sysdba&amp;#039;&lt;br /&gt;
dumpfile=adst_ads_archive_metadata.dmp&lt;br /&gt;
logfile=expdp_adst_ads_archive_metadata.log&lt;br /&gt;
tablespaces=ADS_ARCHIVE&lt;br /&gt;
parallel=20&lt;br /&gt;
content=metadata_only&lt;br /&gt;
exclude=statistics&lt;br /&gt;
EOCAT&lt;br /&gt;
&lt;br /&gt;
expdp parfile=expdp_adst_ads_archive_metadata.par&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Find the partitions with data from the most recent month====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cat &amp;lt;&amp;lt;EOCAT&amp;gt;/tmp/adst_ads_archive_partitions.sql&lt;br /&gt;
set termo off echo off lines 1000 feedb off headi off newpa none trims on&lt;br /&gt;
spool /tmp/adst_ads_archive_partitions.lst&lt;br /&gt;
select table_owner||&amp;#039;.&amp;#039;||table_name||&amp;#039;:&amp;#039;||partition_name&lt;br /&gt;
from   dba_tab_partitions&lt;br /&gt;
where  tablespace_name = &amp;#039;ADS_ARCHIVE&amp;#039;&lt;br /&gt;
and    partition_name like &amp;#039;Y2017_Q1_M01%&amp;#039;&lt;br /&gt;
/&lt;br /&gt;
spool off&lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;@/tmp/adst_ads_archive_partitions.sql&amp;quot; | sqlplus / as sysdba&lt;br /&gt;
EOCAT&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
produces...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_CBA_BGAAP_ARC:Y2017_Q1_M01_D07&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_IFRS_ARC:Y2017_Q1_M02_D26&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_IFRS_ARC:Y2017_Q1_M02_D25&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_IFRS_ARC:Y2017_Q1_M02_D19&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_IFRS_ARC:Y2017_Q1_M02_D18&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_IFRS_ARC:Y2017_Q1_M02_D12&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_IFRS_ARC:Y2017_Q1_M02_D11&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_IFRS_ARC:Y2017_Q1_M02_D05&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_BGAAP_ARC:Y2017_Q1_M02_D26&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_BGAAP_ARC:Y2017_Q1_M02_D25&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_BGAAP_ARC:Y2017_Q1_M02_D19&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_BGAAP_ARC:Y2017_Q1_M02_D18&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_BGAAP_ARC:Y2017_Q1_M02_D12&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_BGAAP_ARC:Y2017_Q1_M02_D11&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_BGAAP_ARC:Y2017_Q1_M02_D05&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_BGAAP_ARC:Y2017_Q1_M02_D04&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_BGAAP_ARC:Y2017_Q1_M01_D29&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_BGAAP_ARC:Y2017_Q1_M01_D28&lt;br /&gt;
...&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_BGAAP_ARC:Y2017_Q1_M01_D22&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_BGAAP_ARC:Y2017_Q1_M01_D21&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_BGAAP_ARC:Y2017_Q1_M01_D15&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_BGAAP_ARC:Y2017_Q1_M01_D14&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_BGAAP_ARC:Y2017_Q1_M01_D08&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_BGAAP_ARC:Y2017_Q1_M01_D07&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_BGAAP_ARC:Y2017_Q1_M01_D01&lt;br /&gt;
ADS_ARCHIVE.BIL_MTH_INV_CTR_ARC:Y2017_Q1_M01_D01&lt;br /&gt;
ADS_ARCHIVE.BIL_DAY_INV_CTR_ARC:Y2017_Q1_M01_D01&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_IFRS_ARC:Y2017_Q1_M02_D04&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_IFRS_ARC:Y2017_Q1_M01_D29&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_IFRS_ARC:Y2017_Q1_M01_D28&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_IFRS_ARC:Y2017_Q1_M01_D22&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Export the data in these partitions====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cat&amp;lt;&amp;lt;EOCAT &amp;gt;expdp_adst_ads_archive_partitions.par&lt;br /&gt;
userid=&amp;#039;/ as sysdba&amp;#039;&lt;br /&gt;
dumpfile=adst_ads_archive_Y2017_%U.dmp&lt;br /&gt;
logfile=expdp_adst_ads_archive_Y2017.log&lt;br /&gt;
EOCAT&lt;br /&gt;
&lt;br /&gt;
cat /tmp/adst_ads_archive_partitions.lst | perl -p -i -e &amp;#039;s/^/tables=/&amp;#039;g &amp;gt;&amp;gt;expdp_adst_ads_archive_partitions.par&lt;br /&gt;
&lt;br /&gt;
cat&amp;lt;&amp;lt;EOCAT &amp;gt;&amp;gt;expdp_adst_ads_archive_partitions.par&lt;br /&gt;
parallel=20&lt;br /&gt;
exclude=statistics&lt;br /&gt;
EOCAT&lt;br /&gt;
&lt;br /&gt;
expdp parfile=expdp_adst_ads_archive_partitions.par&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Drop the old tablespace====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
drop tablespace ads_archive including contents and datafiles&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Recreate the tablepspace using the metadata capture above====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
create tablespace &amp;quot;ADS_ARCHIVE&amp;quot;&lt;br /&gt;
datafile &amp;#039;/oracle/tst/ora_data3/adst/ads_archive01.dbf&amp;#039; size 100M autoextend on next 50M maxsize unlimited&lt;br /&gt;
,        &amp;#039;/oracle/tst/ora_data3/adst/ads_archive02.dbf&amp;#039; size 100M autoextend on next 50M maxsize unlimited&lt;br /&gt;
,        &amp;#039;/oracle/tst/ora_data3/adst/ads_archive03.dbf&amp;#039; size 100M autoextend on next 50M maxsize unlimited&lt;br /&gt;
,        &amp;#039;/oracle/tst/ora_data3/adst/ads_archive04.dbf&amp;#039; size 100M autoextend on next 50M maxsize unlimited&lt;br /&gt;
,        &amp;#039;/oracle/tst/ora_data3/adst/ads_archive05.dbf&amp;#039; size 100M autoextend on next 50M maxsize unlimited&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Import the tablespace metadata====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cat&amp;lt;&amp;lt;EOCAT &amp;gt;impdp_adst_ads_archive_metadata.par&lt;br /&gt;
userid=&amp;#039;/ as sysdba&amp;#039;&lt;br /&gt;
dumpfile=adst_ads_archive_metadata.dmp&lt;br /&gt;
logfile=impdp_adst_ads_archive_metadata.log&lt;br /&gt;
EOCAT&lt;br /&gt;
&lt;br /&gt;
impdp parfile=impdp_adst_ads_archive_metadata.par&lt;br /&gt;
&lt;br /&gt;
select &amp;#039;alter index &amp;#039;|| owner||&amp;#039;.&amp;#039;||index_name||&amp;#039; rebuild online parallel 8;&amp;#039;&lt;br /&gt;
from   dba_indexes&lt;br /&gt;
where  status = &amp;#039;UNUSABLE&amp;#039;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Import the last month partition data====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cat&amp;lt;&amp;lt;EOCAT &amp;gt;impdp_adst_ads_archive_partitions.par&lt;br /&gt;
userid=&amp;#039;/ as sysdba&amp;#039;&lt;br /&gt;
dumpfile=adst_ads_archive_Y2017_%U.dmp&lt;br /&gt;
logfile=impdp_adst_ads_archive_Y2017.log&lt;br /&gt;
table_exists_action=append&lt;br /&gt;
parallel=20&lt;br /&gt;
EOCAT&lt;br /&gt;
&lt;br /&gt;
impdp parfile=impdp_adst_ads_archive_partitions.par&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Write to a TCP/IP socket from PL/SQL===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
declare&lt;br /&gt;
 bt_conn               utl_tcp.connection;&lt;br /&gt;
 retval                binary_integer;&lt;br /&gt;
 l_sequence            varchar2(30) := &amp;#039;Sequence Number 101021&amp;#039;;&lt;br /&gt;
begin&lt;br /&gt;
 bt_conn := utl_tcp.open_connection(remote_host =&amp;gt; &amp;#039;10.10.1.1&amp;#039;&lt;br /&gt;
                                   ,remote_port =&amp;gt; 5000&lt;br /&gt;
                                   ,tx_timeout =&amp;gt; 1&lt;br /&gt;
                                   )&lt;br /&gt;
 ;&lt;br /&gt;
 retval := utl_tcp.write_line(bt_conn,l_sequence)&lt;br /&gt;
 ;&lt;br /&gt;
 utl_tcp.flush(bt_conn)&lt;br /&gt;
 ;&lt;br /&gt;
 utl_tcp.close_connection(bt_conn)&lt;br /&gt;
 ;&lt;br /&gt;
exception&lt;br /&gt;
 when others then&lt;br /&gt;
  raise_application_error(-20101, sqlerrm)&lt;br /&gt;
  ; &lt;br /&gt;
  utl_tcp.close_connection(bt_conn)&lt;br /&gt;
  ;&lt;br /&gt;
end&lt;br /&gt;
;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
and read from it using netcat in another session&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
nc -lk 5000&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
produces&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Sequence Number 101021&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Execute a script as a different user===&lt;br /&gt;
Some things have to be done as the user and cannot be done as sys (eg. creating and dropping jobs or create and drop a database link)&amp;lt;br /&amp;gt;&lt;br /&gt;
It is possible to login as the user by saving, changing and resetting his password (using identified by values) but using dbms_sys_sql is another option&amp;lt;br /&amp;gt;&lt;br /&gt;
Create a PL/SQL procedure to drop a db link&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
create or replace procedure drop_dblink ( p_schema_name in varchar2&lt;br /&gt;
                                        , p_dblink      in varchar2&lt;br /&gt;
                                        ) is&lt;br /&gt;
    l_plsql   varchar2(1000);&lt;br /&gt;
    l_cur     number;&lt;br /&gt;
    l_uid     number;&lt;br /&gt;
    l_rc      number;&lt;br /&gt;
begin&lt;br /&gt;
    select  du.user_id&lt;br /&gt;
    into    l_uid&lt;br /&gt;
    from    dba_users du&lt;br /&gt;
    where   du.username = p_schema_name&lt;br /&gt;
    ;&lt;br /&gt;
    plsql := &amp;#039;drop database link &amp;quot;&amp;#039;||p_dblink||&amp;#039;&amp;quot;&amp;#039;;&lt;br /&gt;
    l_cur := sys.dbms_sys_sql.open_cursor;&lt;br /&gt;
    sys.dbms_sys_sql.parse_as_user(&lt;br /&gt;
        c             =&amp;gt; l_cur,&lt;br /&gt;
        statement     =&amp;gt; l_plsql,&lt;br /&gt;
        language_flag =&amp;gt; dbms_sql.native,&lt;br /&gt;
        userid        =&amp;gt; l_uid&lt;br /&gt;
    );&lt;br /&gt;
    l_rc := sys.dbms_sys_sql.execute(l_cur);&lt;br /&gt;
    sys.dbms_sys_sql.close_cursor(l_cur);&lt;br /&gt;
end;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Generate the calls to the procedure with the required parameters&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select &amp;#039;exec drop_dblink (&amp;#039;&amp;#039;&amp;#039;|| owner ||&amp;#039;&amp;#039;&amp;#039;&amp;#039;||&amp;#039;, &amp;#039;||&amp;#039;&amp;#039;&amp;#039;&amp;#039;||db_link||&amp;#039;&amp;#039;&amp;#039;&amp;#039;||&amp;#039;);&amp;#039;&lt;br /&gt;
from   dba_db_links&lt;br /&gt;
where  owner   != &amp;#039;PUBLIC&amp;#039;&lt;br /&gt;
and    db_link like &amp;#039;%FTST%&amp;#039;&lt;br /&gt;
or     db_link like &amp;#039;%HDEV%&amp;#039;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
and this reveals the lines to be executed&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
exec drop_dblink (&amp;#039;USER1&amp;#039;, &amp;#039;DBL_FTST.WORLD&amp;#039;);&lt;br /&gt;
exec drop_dblink (&amp;#039;USER1&amp;#039;, &amp;#039;DBL_HDEV.WORLD&amp;#039;);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Drop the procedure when finished with it&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
drop procedure drop_dblink;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
or do it as an anonymous block in one go...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
declare&lt;br /&gt;
    uid number;&lt;br /&gt;
    sqltext varchar2(1000) := &amp;#039;drop database link &amp;quot;&amp;amp;DB_LINK&amp;quot;&amp;#039;;&lt;br /&gt;
    myint integer;&lt;br /&gt;
begin&lt;br /&gt;
    select user_id into uid from dba_users where username = &amp;#039;&amp;amp;USERNAME&amp;#039;;&lt;br /&gt;
    myint:=sys.dbms_sys_sql.open_cursor();&lt;br /&gt;
    sys.dbms_sys_sql.parse_as_user(myint,sqltext,dbms_sql.native,UID);&lt;br /&gt;
    sys.dbms_sys_sql.close_cursor(myint);&lt;br /&gt;
end;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Handling single quote marks inside SQL statements===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SQL&amp;gt; SELECT &amp;#039;D&amp;#039;&amp;#039;COSTA&amp;#039; name FROM DUAL;&lt;br /&gt;
&lt;br /&gt;
NAME&lt;br /&gt;
-------&lt;br /&gt;
D&amp;#039;COSTA&lt;br /&gt;
&lt;br /&gt;
Alternatively, use the 10g+ quoting method:&lt;br /&gt;
&lt;br /&gt;
SQL&amp;gt; SELECT q&amp;#039;$D&amp;#039;COSTA$&amp;#039; NAME FROM DUAL;&lt;br /&gt;
&lt;br /&gt;
NAME&lt;br /&gt;
-------&lt;br /&gt;
D&amp;#039;COSTA&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Run a script on all databases in /etc/oratab===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
export ORAENV_ASK=NO&lt;br /&gt;
for db in `awk -F: &amp;#039;NF &amp;amp;&amp;amp; $1 !~/[#*]/ {print $1}&amp;#039;  /etc/oratab`&lt;br /&gt;
do&lt;br /&gt;
    echo $db&lt;br /&gt;
    ORACLE_SID=$db&lt;br /&gt;
    . oraenv&lt;br /&gt;
    sqlplus -V&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Schedule a cron job to run on the last day of each month===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
0 23 28-31 * * [ $(date -d +1day +%d) -eq 1 ] &amp;amp;&amp;amp; su - oracle -c &amp;quot;dsmc  arch -server=SO_U_`hostname`_ORX_M_SOL &amp;#039;/oracle/export/PV6/expdp_PV6_D_FULL_`date +\%Y\%m\%d`*&amp;#039;&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===How to tell if a year is a leap year or not - using cal instead of reinventing the wheel===&lt;br /&gt;
Test: Why is Julian day 0, 17th November 1858?&amp;lt;br /&amp;gt;&lt;br /&gt;
Pretty comprehensive answer: [http://h71000.www7.hp.com/wizard/wiz_2315.html here] and [http://mentalfloss.com/article/51370/why-our-calendars-skipped-11-days-1752 here]&amp;lt;br /&amp;gt;&lt;br /&gt;
Also attempts to answer the question why typing &amp;#039;cal 09 1752&amp;#039; on Unix systems looks so odd!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
function leap {&lt;br /&gt;
#  This function tells you if the year passed in as a parameter is a leap year or not...&lt;br /&gt;
if [[ $(cal 2 ${1:-$(date &amp;#039;+%Y&amp;#039;)} | egrep &amp;#039;\&amp;lt;[[:digit:]]{1,2}\&amp;gt;&amp;#039; | wc -w) -eq 29 ]]; then&lt;br /&gt;
    leap=&amp;#039;Y&amp;#039;&lt;br /&gt;
else&lt;br /&gt;
    leap=&amp;#039;N&amp;#039;&lt;br /&gt;
fi&lt;br /&gt;
echo ${leap}&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Reset an expired (and/or locked) user password to the same value===&lt;br /&gt;
Can be used to save user passwords for example in a test environment before destroying them with a copy of production.&amp;lt;br /&amp;gt;&lt;br /&gt;
Simple, quick and easy version. Run this then pick and choose the statements you want to run.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 200 pages 200&lt;br /&gt;
col user_list for a200 head &amp;quot;Expired User List&amp;quot;&lt;br /&gt;
&lt;br /&gt;
select &amp;#039;alter user &amp;#039; ||su.name||&amp;#039; identified by values&amp;#039;||&amp;#039;&amp;#039;&amp;#039;&amp;#039;||spare4||&amp;#039;;&amp;#039;||su.password||&amp;#039;&amp;#039;&amp;#039; account unlock;&amp;#039; user_list&lt;br /&gt;
from   sys.user$ su&lt;br /&gt;
,      dba_users du&lt;br /&gt;
where  1=1&lt;br /&gt;
and    su.name              = du.username&lt;br /&gt;
and    du.oracle_maintained = &amp;#039;N&amp;#039;&lt;br /&gt;
and    (account_status      like &amp;#039;EXPIRED%&amp;#039; or account_status like &amp;#039;%LOCKED&amp;#039;)&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
More industrialised version. Create a package.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
create or replace package dba_utils&lt;br /&gt;
as&lt;br /&gt;
    procedure reset_password ( p_userlist in varchar2 );&lt;br /&gt;
end dba_utils;&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
create or replace package body dba_utils&lt;br /&gt;
as&lt;br /&gt;
&lt;br /&gt;
procedure reset_password ( p_userlist in varchar2 )&lt;br /&gt;
is&lt;br /&gt;
    cursor c1 ( p_userlist in varchar2 ) is&lt;br /&gt;
    select username&lt;br /&gt;
    ,      regexp_substr ( dbms_metadata.get_ddl(&amp;#039;USER&amp;#039;, username), &amp;#039;&amp;#039;&amp;#039;[^&amp;#039;&amp;#039;]+&amp;#039;&amp;#039;&amp;#039; ) pwd&lt;br /&gt;
    from   dba_users&lt;br /&gt;
    where  1=1&lt;br /&gt;
    and    username in upper( p_userlist )&lt;br /&gt;
    ;&lt;br /&gt;
begin&lt;br /&gt;
    dbms_output.enable(null);&lt;br /&gt;
    for r1 in c1 ( p_userlist )&lt;br /&gt;
    loop&lt;br /&gt;
        begin&lt;br /&gt;
            execute immediate &amp;#039;alter user &amp;#039; || r1.username || &amp;#039; account unlock&amp;#039;;&lt;br /&gt;
            execute immediate &amp;#039;alter user &amp;#039; || r1.username || &amp;#039; identified by values &amp;#039; || r1.pwd;&lt;br /&gt;
        exception&lt;br /&gt;
        when others then&lt;br /&gt;
            dbms_output.put_line(&amp;#039;Unable to modify user &amp;#039; || r1.username);&lt;br /&gt;
        end;&lt;br /&gt;
    end loop;&lt;br /&gt;
end reset_password;&lt;br /&gt;
&lt;br /&gt;
end dba_utils;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Call it&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set serveroutput on&lt;br /&gt;
exec dba_utils.reset_password (&amp;#039;STUART&amp;#039;);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Latch, mutex and beyond===&lt;br /&gt;
A fine example of how to write scripts from SQL*Plus that interact with the shell underneath&amp;lt;br /&amp;gt;&lt;br /&gt;
Found [https://andreynikolaev.wordpress.com/demonstration-scripts/cursor_pin_s_contention-sql/ here at andreynikolaev.wordpress.com]&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/*&lt;br /&gt;
     This file is part of demos for &amp;quot;Mutex Internals&amp;quot;  seminar v.04.04.2011&lt;br /&gt;
     Andrey S. Nikolaev (Andrey.Nikolaev@rdtex.ru) &lt;br /&gt;
     https://andreynikolaev.wordpress.com &lt;br /&gt;
 &lt;br /&gt;
     &amp;quot;Cursor: pin S&amp;quot; contention testcase.&lt;br /&gt;
 &lt;br /&gt;
     The script spawn several sessions to induce &amp;quot;Cursor: pin S&amp;quot;, &lt;br /&gt;
     creates AWR snapshots and generates AWR report&lt;br /&gt;
 &lt;br /&gt;
     Beware: The script will restart the test database.&lt;br /&gt;
 &lt;br /&gt;
     usage: sqlplus /nolog @cursor_pin_s_contention.sql &amp;lt;parallelism&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
*/ &lt;br /&gt;
connect / as sysdba&lt;br /&gt;
startup force&lt;br /&gt;
set echo off&lt;br /&gt;
set define %&lt;br /&gt;
set verify off&lt;br /&gt;
set head off&lt;br /&gt;
set linesize 300&lt;br /&gt;
 &lt;br /&gt;
/* spawn parallel processes to create load on mutex */&lt;br /&gt;
spool one_thread.tmp&lt;br /&gt;
select &amp;#039;set verify off&amp;#039; from dual;&lt;br /&gt;
select &amp;#039;alter session set session_cached_cursors = 50;&amp;#039; from dual; &lt;br /&gt;
select &amp;#039;begin for i in 1..1000000 loop&amp;#039; from dual;&lt;br /&gt;
select &amp;#039;      execute immediate &amp;#039;&amp;#039;select 1 from dual where 1=2&amp;#039;&amp;#039;;&amp;#039; from dual;&lt;br /&gt;
select &amp;#039;end loop; end;&amp;#039;||chr(10)||&amp;#039;/&amp;#039; from dual;&lt;br /&gt;
spool off&lt;br /&gt;
 &lt;br /&gt;
/* sleep while AWR initialized */&lt;br /&gt;
host sleep 5&lt;br /&gt;
 &lt;br /&gt;
exec dbms_workload_repository.create_snapshot();&lt;br /&gt;
 &lt;br /&gt;
spool many_threads.tmp&lt;br /&gt;
select &amp;#039;host sqlplus &amp;quot;/ as sysdba&amp;quot; @one_thread.tmp &amp;amp;&amp;#039;&lt;br /&gt;
from dba_objects where rownum &amp;lt;= %1;&lt;br /&gt;
spool off&lt;br /&gt;
 &lt;br /&gt;
@many_threads.tmp&lt;br /&gt;
host sleep 50&lt;br /&gt;
set echo on&lt;br /&gt;
exec dbms_workload_repository.create_snapshot();&lt;br /&gt;
set markup html on&lt;br /&gt;
set head on&lt;br /&gt;
spool mutex_sleep_history.htm&lt;br /&gt;
select to_char(SLEEP_TIMESTAMP,&amp;#039;hh:mi:ss.ff&amp;#039;) SLEEP_TIMESTAMP,MUTEX_ADDR,MUTEX_IDENTIFIER,MUTEX_TYPE,&lt;br /&gt;
       GETS,SLEEPS,REQUESTING_SESSION,BLOCKING_SESSION,&lt;br /&gt;
       LOCATION,MUTEX_VALUE from x$mutex_sleep_history order by sleep_timestamp;&lt;br /&gt;
spool off&lt;br /&gt;
 &lt;br /&gt;
set define &amp;amp;&lt;br /&gt;
set markup html off&lt;br /&gt;
set echo off heading on underline on;&lt;br /&gt;
column inst_num  heading &amp;quot;Inst Num&amp;quot;  new_value inst_num  format 99999;&lt;br /&gt;
column inst_name heading &amp;quot;Instance&amp;quot;  new_value inst_name format a12;&lt;br /&gt;
column db_name   heading &amp;quot;DB Name&amp;quot;   new_value db_name   format a12;&lt;br /&gt;
column dbid      heading &amp;quot;DB Id&amp;quot;     new_value dbid      format 9999999999 just c;&lt;br /&gt;
select d.dbid            dbid&lt;br /&gt;
     , d.name            db_name&lt;br /&gt;
     , i.instance_number inst_num&lt;br /&gt;
     , i.instance_name   inst_name&lt;br /&gt;
  from v$database d,&lt;br /&gt;
       v$instance i;&lt;br /&gt;
define num_days=1;&lt;br /&gt;
define report_type=&amp;#039;html&amp;#039;;&lt;br /&gt;
col end_snap new_value end_snap;&lt;br /&gt;
col begin_snap new_value begin_snap;&lt;br /&gt;
select max(snap_id) end_snap from dba_hist_snapshot where dbid=&amp;amp;dbid;&lt;br /&gt;
select max(snap_id) begin_snap from dba_hist_snapshot where dbid=&amp;amp;dbid and snap_id &amp;lt; &amp;amp;end_snap;&lt;br /&gt;
define report_name=&amp;#039;awr_report.htm&amp;#039;;&lt;br /&gt;
@?/rdbms/admin/awrrpti&lt;br /&gt;
exit&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==shell==&lt;br /&gt;
[http://www.databasejournal.com/features/oracle/article.php/3869076/Alert-Log-Scraping-with-Oracles-ADRCI-Utility.htm Alert Log scraping with ADRCI]&lt;br /&gt;
&lt;br /&gt;
====Count the number of background processes for a particular SID====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SID=RAVJDE1&lt;br /&gt;
ps -ef|cut -c54-100|awk -v SID=$SID &amp;#039;$0 ~ /&amp;#039;$SID&amp;#039;$/ {print}&amp;#039;|wc -l&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or ...this will work with any OS (so long as the process is at the end of the &amp;lt;strong&amp;gt;ps -ef&amp;lt;/strong&amp;gt; or &amp;lt;strong&amp;gt;ps -aux&amp;lt;/strong&amp;gt; listing&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SID=RAVJDE1&lt;br /&gt;
ps -ef|awk -v SID=$SID -F_ &amp;#039;{ $NF ~ /&amp;#039;$SID&amp;#039;$/ {print} }&amp;#039;|wc -l&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Pick the columns you want in the ps listing&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ps -efo user,pid,ppid=MOM -o args&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Find Oracle errors in the most recent DataPump log files====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
00 09 * * * /home/tools/scripts/oracle/dosh &amp;#039;find /oracle/export -name &amp;quot;expdp*log&amp;quot; -mtime -1 -exec grep ORA- {} \; -ls&amp;#039; | mailx -s &amp;#039;Datapump errors for &amp;lt;customer&amp;gt;last night&amp;#039; stuart@domain.com&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Find the 10 largest directories on a particular filesystem====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
du -ag /oracle | sort -nr | head -n 10&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Find the 10 largest files on a particular mount point====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
find /home -size +1G -ls | sort -nr +6 | head -10&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
find /home -xdev -ls | sort -nr +6 | head -10&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Split a file in pieces using sed====&lt;br /&gt;
Using fixed line numbers&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sed -ne &amp;#039;1,12p&amp;#039; file &amp;gt; text.part1&lt;br /&gt;
sed -ne &amp;#039;13,$p&amp;#039; file &amp;gt; text.part2&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Using line with a /pattern/ on it&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sed -e &amp;#039;/hello/q&amp;#039; tt.dat | grep -v hello &amp;gt; text.part1&lt;br /&gt;
sed -n `sed -n &amp;#039;/hello/=&amp;#039; tt.dat`&amp;#039;,$p&amp;#039; tt.dat | grep -v hello &amp;gt; text.part2&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Split a file in pieces using Perl====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
perl -ne &amp;#039;print if 1 .. /marker line/&amp;#039; text.dat &amp;gt;text.part1&lt;br /&gt;
perl -ne &amp;#039;print if /marker line/ .. eof()&amp;#039; text.dat &amp;gt;text.part2&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Find and display RMAN errors in an RMAN log file====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sed -ne &amp;#039;/^RMAN-/,/^$/p&amp;#039;  RMAN_&amp;lt;SID&amp;gt;_&amp;lt;DATE&amp;gt;.log&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==cmd==&lt;br /&gt;
*[http://www.dba-oracle.com/t_scripts_windows_export.htm Database Export - from DBA Oracle (Burleson)]&lt;br /&gt;
==Perl==&lt;br /&gt;
===For all files in a directory, replace a keyword (SSIIDD) in a file with another (a parameter)===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
for i in `ls`&lt;br /&gt;
do&lt;br /&gt;
    perl -p -i -e &amp;#039;s/SSIIDD/&amp;#039;$SID&amp;#039;/g&amp;#039; $i&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Parse tnsnames.ora to get just the service names===&lt;br /&gt;
[[http://stackoverflow.com/questions/12605415/parsing-tnsnames-ora-with-regex-to-just-get-name from here]]&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
perl -ne &amp;#039;print if m/^([^#()\W ][a-zA-Z.]*(?:[.][a-zA-Z]*\s?=)?)/&amp;#039; $TNS_ADMIN/tnsnames.ora&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===and use that to check the listener status===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
for svc in `perl -ne &amp;#039;print if m/^([^#()\W ][a-zA-Z.]*(?:[.][a-zA-Z]*\s?=)?)/&amp;#039; $TNS_ADMIN/tnsnames.ora | sed -e &amp;#039;s/=//&amp;#039;` ;do&lt;br /&gt;
    tnsping $svc&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Stuart</name></author>	</entry>

	<entry>
		<id>https://mailnest.com/dbawiki/index.php?title=Handy_scripts&amp;diff=3373</id>
		<title>Handy scripts</title>
		<link rel="alternate" type="text/html" href="https://mailnest.com/dbawiki/index.php?title=Handy_scripts&amp;diff=3373"/>
				<updated>2018-11-21T11:57:12Z</updated>
		
		<summary type="html">&lt;p&gt;Stuart: /* External table for the Alert log (pre 11g) */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==SQL==&lt;br /&gt;
* [[Database Overview - from idevelopment]] [http://www.idevelopment.info/data/Oracle/DBA_scripts/Database_Administration/dba_snapshot_database_10g.sql online version]&lt;br /&gt;
* [[Extract ddl with &amp;quot;dbms metadata.get ddl&amp;quot;]]&lt;br /&gt;
* [http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:83012348058 Connecting as another user via proxy in SQL*Plus]&lt;br /&gt;
* [http://www.petefinnigan.com/tools.htm Password cracker and role and priv tools from Pete Finnigan]&lt;br /&gt;
* [http://www.oracle.com/technetwork/articles/sql/11g-pivot-097235.html Using pivot tables in SQL - XML and XLS (Excel) also)]&lt;br /&gt;
===List all instances running on a server===&lt;br /&gt;
Sounds simple enough and indeed pre 12.1, is was as easy as either&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ps -ef | grep [p]mon | awk -F_ &amp;#039;{print $NF}&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or this one is safer in case you have an underscore character in your SID name!!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SIDLIST=$(${PS} -ef | ${GREP} [o]ra_pmon | ${AWK} &amp;#039;{print $NF}&amp;#039; | sed -e &amp;#039;s/ora_pmon_//&amp;#039; | egrep -v &amp;#039;grep|///|sed|awk|ASM|^$&amp;#039;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
but now we have the added complication of CDB/PDB (container / pluggable databases) so a fair bit more work is needed!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/ksh&lt;br /&gt;
# ==============================================================================&lt;br /&gt;
# Name         : list_server_db&lt;br /&gt;
# Description  : List all running databases found on a server&lt;br /&gt;
#&lt;br /&gt;
# Parameters   : none&lt;br /&gt;
#&lt;br /&gt;
# Notes        : none&lt;br /&gt;
#&lt;br /&gt;
# Modification History&lt;br /&gt;
# ====================&lt;br /&gt;
# When      Who               What&lt;br /&gt;
# ========= ================= ==================================================&lt;br /&gt;
# 21-DEC-16 Stuart Barkley    Created&lt;br /&gt;
# ==============================================================================&lt;br /&gt;
for db in $(ps -ef | grep [p]mon|awk -F_ &amp;#039;{print $NF}&amp;#039;)&lt;br /&gt;
do&lt;br /&gt;
    export ORACLE_SID=${db}&lt;br /&gt;
    ORAENV_ASK=NO&lt;br /&gt;
    . oraenv &amp;gt;/dev/null 2&amp;gt;&amp;amp;1&lt;br /&gt;
    sqlplus -s / as sysdba&amp;lt;&amp;lt;EOSQL&lt;br /&gt;
set serveroutput on feed off pages 0 head off newpa none&lt;br /&gt;
declare&lt;br /&gt;
    e_col_not_found exception;&lt;br /&gt;
    e_not_mounted   exception;&lt;br /&gt;
    pragma          exception_init(e_not_mounted, -01507);&lt;br /&gt;
    pragma          exception_init(e_col_not_found, -904);&lt;br /&gt;
    l_db_name       varchar2(20);&lt;br /&gt;
    l_database_role varchar2(20);&lt;br /&gt;
    l_cdb           varchar2(20);&lt;br /&gt;
    l_status        varchar2(20);&lt;br /&gt;
    type varchar2_tab is table of varchar2(240) index by binary_integer;&lt;br /&gt;
    t_pdbs          varchar2_tab;&lt;br /&gt;
begin&lt;br /&gt;
    begin&lt;br /&gt;
        dbms_output.enable(null);&lt;br /&gt;
        execute immediate &amp;#039;select name, database_role, cdb from v\$database&amp;#039; into l_db_name, l_database_role, l_cdb;&lt;br /&gt;
        if l_cdb = &amp;#039;YES&amp;#039; then&lt;br /&gt;
            l_status := &amp;#039;CDB&amp;#039;;&lt;br /&gt;
            execute immediate &amp;#039;select name from v\$pdbs&amp;#039; bulk collect into t_pdbs;&lt;br /&gt;
            for i in nvl(t_pdbs.first,1) .. nvl(t_pdbs.last,0)&lt;br /&gt;
            loop&lt;br /&gt;
                dbms_output.put_line (t_pdbs(i)||&amp;#039;:PDB&amp;#039;);&lt;br /&gt;
            end loop;&lt;br /&gt;
        else&lt;br /&gt;
            l_status := &amp;#039;Independent&amp;#039;;  -- col CDB exists but this is not one&lt;br /&gt;
        end if;&lt;br /&gt;
        if l_database_role like &amp;#039;%STANDBY%&amp;#039; then&lt;br /&gt;
            l_status := &amp;#039;Standby&amp;#039;;&lt;br /&gt;
        end if;&lt;br /&gt;
    exception&lt;br /&gt;
    when e_not_mounted then&lt;br /&gt;
        l_status := &amp;#039;Not Mounted&amp;#039;;&lt;br /&gt;
    when e_col_not_found then&lt;br /&gt;
        l_status := &amp;#039;pre12&amp;#039;;&lt;br /&gt;
    end;&lt;br /&gt;
&lt;br /&gt;
    dbms_output.put_line (&amp;#039;${db}&amp;#039;||&amp;#039;:&amp;#039;||l_status);&lt;br /&gt;
&lt;br /&gt;
end;&lt;br /&gt;
/&lt;br /&gt;
EOSQL&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Run a command or script on all databases in tnsnames.ora===&lt;br /&gt;
Very handy if you have a global tnsnames.ora accessible to all clients.&amp;lt;br /&amp;gt;&lt;br /&gt;
So from a client install, this has access to all databases.&amp;lt;br /&amp;gt;&lt;br /&gt;
Any files created can be created on the client so no need to scp to all the machines to recover spool files etc.&amp;lt;br /&amp;gt;&lt;br /&gt;
Downside: Cannot connect as sysdba across tns so password will need to be known for whatever user is used.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/ksh&lt;br /&gt;
TNSNAMES=&amp;quot;./tnsnames.ora&amp;quot;&lt;br /&gt;
[[ ! -r &amp;quot;${TNSNAMES}&amp;quot; ]] &amp;amp;&amp;amp; echo &amp;quot;${TNSNAMES} is not accessible&amp;quot; &amp;amp;&amp;amp; exit 1&lt;br /&gt;
&lt;br /&gt;
SIDLIST=$(perl -ne &amp;#039;print &amp;quot;$1\n&amp;quot; if /(?:SID|SERVICE_NAME)\s*=\s*(\S+?)\)/&amp;#039; ${TNSNAMES}|sort|uniq|xargs)&lt;br /&gt;
for SID in ${SIDLIST}&lt;br /&gt;
do&lt;br /&gt;
    echo &amp;quot;Processing $SID&amp;quot;&lt;br /&gt;
    ls -al | grep &amp;quot;^d&amp;quot; | grep &amp;quot;\_${SID}&amp;quot; &amp;gt;/dev/null&lt;br /&gt;
    if [[ $? -ne 0 ]]; then&lt;br /&gt;
        echo &amp;#039;exit&amp;#039; | sqlplus system/xxxxxx@${SID} @ReviewLite17.1.sql &amp;gt;/dev/null 2&amp;gt;&amp;amp;1&lt;br /&gt;
    else&lt;br /&gt;
        echo &amp;quot;directory already exists so must have done this SID&amp;quot;&lt;br /&gt;
    fi&lt;br /&gt;
done&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Run a command or script on all databases in oratab===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/usr/bin/ksh&lt;br /&gt;
# ==============================================================================&lt;br /&gt;
# Name         : all_db_do&lt;br /&gt;
# Description  : Loops over all the databases in oratab and executes the&lt;br /&gt;
#                specified SQL command - be careful!&lt;br /&gt;
#&lt;br /&gt;
# Parameters   : -v flag for verbose&lt;br /&gt;
#                [-f &amp;lt;filename&amp;gt; | &amp;lt;quoted SQL command to be executed&amp;gt;]&lt;br /&gt;
#&lt;br /&gt;
# Example      : all_db_do &amp;#039;alter system switch logfile;&amp;#039;&lt;br /&gt;
#                all_db_do -f sessions.sql&lt;br /&gt;
#&lt;br /&gt;
# Notes        : none&lt;br /&gt;
#&lt;br /&gt;
# Modification History&lt;br /&gt;
# ====================&lt;br /&gt;
# When      Who               What&lt;br /&gt;
# ========= ================= ==================================================&lt;br /&gt;
# 14-JAN-13 Stuart Barkley    Created&lt;br /&gt;
# 25-FEB-13 Stuart Barkley    Adapt for Solaris&lt;br /&gt;
# 21-MAR-13 Stuart Barkley    Check db is running first&lt;br /&gt;
# 29-APR-13 Stuart Barkley    Added verbose flag processing&lt;br /&gt;
# 24-MAY-13 Stuart Barkley    Wrap / as sysdba in quotes for older versions&lt;br /&gt;
# 23-JUN-16 Stuart Barkley    Add -f to run a file containing sql&lt;br /&gt;
# ==============================================================================&lt;br /&gt;
&lt;br /&gt;
PROGNAME=$(basename $0)&lt;br /&gt;
OS=$(uname -s)&lt;br /&gt;
&lt;br /&gt;
AWK=$(which awk)&lt;br /&gt;
GREP=$(which grep)&lt;br /&gt;
if [[ &amp;quot;${OS}&amp;quot; == &amp;quot;SunOS&amp;quot; ]]; then&lt;br /&gt;
    AWK=/usr/xpg4/bin/awk&lt;br /&gt;
    GREP=/usr/xpg4/bin/grep&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
if [[ ! -r /etc/oratab ]]; then&lt;br /&gt;
    if [[ &amp;quot;${OS}&amp;quot; == &amp;quot;SunOS&amp;quot; ]]; then&lt;br /&gt;
        echo &amp;quot;oratab is not where we want it. Please run &amp;#039;ln -s /var/opt/oracle/oratab /etc/oratab&amp;#039; as root and retry&amp;quot; &amp;amp;&amp;amp; exit 1&lt;br /&gt;
    else&lt;br /&gt;
        echo &amp;quot;Either Oracle is not installed or database is running without an oratab&amp;quot; &amp;amp;&amp;amp; exit 1&lt;br /&gt;
    fi&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
# -------------------------&lt;br /&gt;
# get the arguments, if any&lt;br /&gt;
# -------------------------&lt;br /&gt;
unset VERBOSE&lt;br /&gt;
while getopts &amp;quot;vf:&amp;quot; flag&lt;br /&gt;
do&lt;br /&gt;
    case &amp;quot;$flag&amp;quot; in&lt;br /&gt;
    v) VERBOSE=1;;&lt;br /&gt;
    f) FILE2RUN=$OPTARG;;&lt;br /&gt;
    esac&lt;br /&gt;
done&lt;br /&gt;
shift $((OPTIND-1))&lt;br /&gt;
&lt;br /&gt;
if [[ -z ${FILE2RUN} ]]; then&lt;br /&gt;
    # no file, need an SQL supplied&lt;br /&gt;
    if [[ -z $1 ]]; then&lt;br /&gt;
        echo &amp;quot;Usage: $0 [-v] [-f &amp;lt;filename&amp;gt; | &amp;lt;quoted SQL command to be executed&amp;gt;]&amp;quot;&lt;br /&gt;
        echo &amp;quot;eg: $0 -f sessions.sql&amp;quot;&lt;br /&gt;
        echo &amp;quot;eg: $0 &amp;#039;alter system switch logfile;&amp;#039;&amp;quot;&lt;br /&gt;
        exit 1&lt;br /&gt;
    fi&lt;br /&gt;
    SQL=$1&lt;br /&gt;
elif [[ -s ${FILE2RUN} ]]; then&lt;br /&gt;
    # file supplied and exists&lt;br /&gt;
    SQL=&amp;quot;@${FILE2RUN}&amp;quot;&lt;br /&gt;
else&lt;br /&gt;
    # file supplied, does it exist&lt;br /&gt;
    echo &amp;quot;File ${FILE2RUN} is empty or does not exist&amp;quot;&lt;br /&gt;
    echo &amp;quot;Usage: $0 [-v] [-f &amp;lt;filename&amp;gt; | &amp;lt;quoted SQL command to be executed&amp;gt;]&amp;quot;&lt;br /&gt;
    echo &amp;quot;eg: $0 -f sessions.sql&amp;quot;&lt;br /&gt;
    echo &amp;quot;eg: $0 &amp;#039;alter system switch logfile;&amp;#039;&amp;quot;&lt;br /&gt;
    exit 1&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
export ORAENV_ASK=NO&lt;br /&gt;
&lt;br /&gt;
for db in $(${AWK} -F: &amp;#039;NF &amp;amp;&amp;amp; $1 !~/[#*]/ {print $1}&amp;#039;  /etc/oratab)&lt;br /&gt;
do&lt;br /&gt;
    if ( [[ $1 != &amp;quot;startup&amp;quot; ]] &amp;amp;&amp;amp; [[ $(ps -ef | ${GREP} -c -E [o]ra_pmon_${db}) -eq 0 ]] ); then&lt;br /&gt;
        [[ ! -z &amp;quot;$VERBOSE&amp;quot; ]] &amp;amp;&amp;amp; echo &amp;quot;$db is not running, skipping...&amp;quot;&lt;br /&gt;
        continue&lt;br /&gt;
    fi&lt;br /&gt;
    echo&lt;br /&gt;
    [[ ! -z &amp;quot;$VERBOSE&amp;quot; ]] &amp;amp;&amp;amp; echo &amp;quot;vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv&amp;quot;&lt;br /&gt;
    [[ ! -z &amp;quot;$VERBOSE&amp;quot; ]] &amp;amp;&amp;amp; echo $db&lt;br /&gt;
    ORACLE_SID=$db&lt;br /&gt;
    . oraenv &amp;gt;/dev/null&lt;br /&gt;
    sqlplus -s &amp;quot;/ as sysdba&amp;quot; &amp;lt;&amp;lt;EOSQL&lt;br /&gt;
define SID=$ORACLE_SID&lt;br /&gt;
col comp_name format a50&lt;br /&gt;
col value for a40&lt;br /&gt;
set linesize 1000&lt;br /&gt;
set pagesize 100&lt;br /&gt;
$SQL&lt;br /&gt;
EOSQL&lt;br /&gt;
    [[ ! -z &amp;quot;$VERBOSE&amp;quot; ]] &amp;amp;&amp;amp; echo &amp;quot;^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^&amp;quot;&lt;br /&gt;
done&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
all_db_do &amp;quot;create or replace directory data_pump_dir as &amp;#039;/oracle/export/&amp;amp;SID&amp;#039;;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
all_db_do &amp;quot;archive log list&amp;quot;&lt;br /&gt;
&lt;br /&gt;
all_db_do &amp;quot;shutdown immediate&amp;quot;&lt;br /&gt;
&lt;br /&gt;
all_db_do &amp;#039;alter system set log_archive_dest_1=&amp;quot;location=/oracle/arch/&amp;amp;SID&amp;quot; scope=both;&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Run an SQL command on behalf of another user===&lt;br /&gt;
It can be used to execute any sql command as a specified user provided this procedure is created in sys schema.&amp;lt;br /&amp;gt;&lt;br /&gt;
* not got this working properly yet *&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set serveroutput on&lt;br /&gt;
create or replace procedure run_sql_as_user ( p_schema_name in varchar2&lt;br /&gt;
                                            , p_sql         in varchar2&lt;br /&gt;
                                            ) is&lt;br /&gt;
    l_user_id dba_users.user_id%type;&lt;br /&gt;
    l_cursor  number;&lt;br /&gt;
    l_rc      number;&lt;br /&gt;
begin&lt;br /&gt;
    dbms_output.enable(null);&lt;br /&gt;
    begin&lt;br /&gt;
        select u.user_id&lt;br /&gt;
        into   l_user_id&lt;br /&gt;
        from   dba_users u&lt;br /&gt;
        where  u.username = p_schema_name;&lt;br /&gt;
    exception&lt;br /&gt;
    when no_data_found then&lt;br /&gt;
        raise_application_error (-20001, &amp;#039;Cannot find user &amp;#039;||p_schema_name);&lt;br /&gt;
    end;&lt;br /&gt;
    l_cursor := dbms_sys_sql.open_cursor;&lt;br /&gt;
    dbms_sys_sql.parse_as_user ( c             =&amp;gt; l_cursor&lt;br /&gt;
                               , statement     =&amp;gt; p_sql&lt;br /&gt;
                               , language_flag =&amp;gt; dbms_sql.native&lt;br /&gt;
                               , userid        =&amp;gt; l_user_id&lt;br /&gt;
    );&lt;br /&gt;
    l_rc := dbms_sys_sql.execute(l_cursor);&lt;br /&gt;
    dbms_sys_sql.close_cursor(l_cursor);&lt;br /&gt;
exception&lt;br /&gt;
when others then&lt;br /&gt;
    raise_application_error (-20001, &amp;#039;ERROR: &amp;#039;||sqlerrm);&lt;br /&gt;
end;&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Run a script on all databases listed in tnsnames.ora===&lt;br /&gt;
Can run an SQL command file on all SID/SERVICE found in a tnsnames.ora file. I use this from a client laptop having a global tns file on it.&amp;lt;br /&amp;gt;&lt;br /&gt;
This way it&amp;#039;s not necessary to copy the file onto every host before executing it. Any files created by the script will be created on the client.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/ksh&lt;br /&gt;
&lt;br /&gt;
TNSNAMES=&amp;quot;./tnsnames.ora&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[ ! -r &amp;quot;${TNSNAMES}&amp;quot; ]] &amp;amp;&amp;amp; echo &amp;quot;${TNSNAMES} is not accessible&amp;quot; &amp;amp;&amp;amp; exit 1&lt;br /&gt;
&lt;br /&gt;
SIDLIST=$(perl -ne &amp;#039;print &amp;quot;$1\n&amp;quot; if /(?:SID|SERVICE_NAME)\s*=\s*(\S+?)\)/&amp;#039; ${TNSNAMES}|sort|uniq|xargs)&lt;br /&gt;
for SID in ${SIDLIST}&lt;br /&gt;
do&lt;br /&gt;
    echo &amp;quot;Processing $SID&amp;quot;&lt;br /&gt;
    ls -al | grep &amp;quot;^d&amp;quot; | grep &amp;quot;\_${SID}&amp;quot; &amp;gt;/dev/null&lt;br /&gt;
    if [[ $? -ne 0 ]]; then&lt;br /&gt;
        echo &amp;#039;exit&amp;#039; | sqlplus system/password@${SID} @ReviewLite17.1.sql &amp;gt;/dev/null 2&amp;gt;&amp;amp;1&lt;br /&gt;
    else&lt;br /&gt;
        echo &amp;quot;directory already exists so must have done this SID&amp;quot;&lt;br /&gt;
    fi&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===List invalid objects===&lt;br /&gt;
 set lines 200&lt;br /&gt;
 set pages 200&lt;br /&gt;
 col obj format a40&lt;br /&gt;
 select owner||&amp;#039;.&amp;#039;||object_name obj&lt;br /&gt;
 ,      object_type&lt;br /&gt;
 from   dba_objects&lt;br /&gt;
 where  1=1&lt;br /&gt;
 and    status = &amp;#039;INVALID&amp;#039;;&lt;br /&gt;
===Recompile all invalid objects===&lt;br /&gt;
@?/rdbms/admin/utlrp.sql&lt;br /&gt;
===See how much space is left in the flash recovery area (FRA)===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select name&lt;br /&gt;
,      to_char (space_limit, &amp;#039;999,999,999,999&amp;#039;) as space_limit&lt;br /&gt;
,      to_char (space_limit - space_used + space_reclaimable&lt;br /&gt;
,               &amp;#039;999,999,999,999&amp;#039;)&lt;br /&gt;
           as space_available&lt;br /&gt;
,      round ( (space_used - space_reclaimable) / space_limit * 100, 1)&lt;br /&gt;
           as pct_full&lt;br /&gt;
from   v$recovery_file_dest;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# ==============================================&lt;br /&gt;
# Check FRA to see how much space is reclaimable&lt;br /&gt;
# ==============================================&lt;br /&gt;
fra_reclaim_check() {&lt;br /&gt;
&lt;br /&gt;
LOGFILE=${RMAN_LogDir}/${ORACLE_SID}_`date &amp;#039;+%Y%m&amp;#039;`_${V_SCRIPT}.log&lt;br /&gt;
sqlplus &amp;quot;/ as sysdba&amp;quot; &amp;lt;&amp;lt;EOSQL &amp;gt; /tmp/results.$$&lt;br /&gt;
set vefify off echo off heading off newpage none linesize 1000 echo off&lt;br /&gt;
select &amp;#039;Filesystem:&amp;#039;||name||&lt;br /&gt;
       &amp;#039;; Total(Gb):&amp;#039;||round((space_limit/1073741824),2) ||&lt;br /&gt;
       &amp;#039;; Reclaimable(Gb):&amp;#039;||round((space_reclaimable/1073741824),2) ||&lt;br /&gt;
       &amp;#039;; Reclaimable(%):&amp;#039;||round( ((space_reclaimable/1073741824)/(space_limit/1073741824)*100),2 )&lt;br /&gt;
from   v$recovery_file_dest&lt;br /&gt;
/&lt;br /&gt;
EOSQL&lt;br /&gt;
cat /tmp/results.$$ &amp;gt;&amp;gt; $LOGFILE&lt;br /&gt;
rm /tmp/results.$$&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===How far back can we flashback?===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
col time_now              for a25&lt;br /&gt;
col time_oldest_flashback for a25&lt;br /&gt;
select to_char(sysdate,&amp;#039;DD-MON-YY HH24:MI&amp;#039;)                    time_now&lt;br /&gt;
,      to_char(fdl.oldest_flashback_time, &amp;#039;DD-MON-YY HH24:MI&amp;#039;) time_oldest_flashback&lt;br /&gt;
,      round((sysdate-fdl.oldest_flashback_time)*24,1)         hours_flashback_possible&lt;br /&gt;
from   v$database d&lt;br /&gt;
,      v$flashback_database_log fdl&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===DBA privs tables===&lt;br /&gt;
 DBA_AQ_AGENT_PRIVS&lt;br /&gt;
 DBA_COL_PRIVS&lt;br /&gt;
 DBA_PRIV_AUDIT_OPTS&lt;br /&gt;
 DBA_REPGROUP_PRIVILEGES&lt;br /&gt;
 DBA_ROLE_PRIVS&lt;br /&gt;
 DBA_RSRC_CONSUMER_GROUP_PRIVS&lt;br /&gt;
 DBA_RSRC_MANAGER_SYSTEM_PRIVS&lt;br /&gt;
 DBA_SYS_PRIVS&lt;br /&gt;
 DBA_TAB_PRIVS&lt;br /&gt;
 DBA_WM_SYS_PRIVS&lt;br /&gt;
 DBA_WORKSPACE_PRIVS&lt;br /&gt;
&lt;br /&gt;
===Schedule a shell job===&lt;br /&gt;
 begin&lt;br /&gt;
     dbms_scheduler.create_program ( program_name   =&amp;gt; &amp;#039;myshelljob&amp;#039;&lt;br /&gt;
                                   , program_action =&amp;gt; &amp;#039;/home/oracle/scripts/shell.sh&amp;#039;&lt;br /&gt;
                                   , program_type   =&amp;gt; &amp;#039;EXECUTABLE&amp;#039;&lt;br /&gt;
                                   , comments       =&amp;gt; &amp;#039;Run a shell&amp;#039;&lt;br /&gt;
                                   , enabled        =&amp;gt; TRUE&lt;br /&gt;
                                   );&lt;br /&gt;
 end;&lt;br /&gt;
 /&lt;br /&gt;
===Start the job===&lt;br /&gt;
 begin&lt;br /&gt;
     dbms_sheduler.create_job ( job_name     =&amp;gt; &amp;#039;myshelljob&amp;#039;&lt;br /&gt;
                              , program_name =&amp;gt; &amp;#039;myshelljob&amp;#039;&lt;br /&gt;
                              , start_date   =&amp;gt;&lt;br /&gt;
                              );&lt;br /&gt;
 /&lt;br /&gt;
&lt;br /&gt;
===What statement is a user running?===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select a.sid&lt;br /&gt;
,      a.serial#&lt;br /&gt;
,      b.sql_text&lt;br /&gt;
from   v$session a&lt;br /&gt;
,      v$sqlarea b&lt;br /&gt;
where  a.sql_address = b.address&lt;br /&gt;
and    a.username    = &amp;#039;&amp;amp;username&amp;#039;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===See what statements all users are running===&lt;br /&gt;
Useful to see what is happening when process limit is reached&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 300 pages 1000&lt;br /&gt;
&lt;br /&gt;
col username for a10&lt;br /&gt;
col command for 999 head &amp;quot;CMD&amp;quot;&lt;br /&gt;
col lockwait for a10&lt;br /&gt;
col status for a8&lt;br /&gt;
col schemaname for a12&lt;br /&gt;
col osuser for a10&lt;br /&gt;
col process for a10&lt;br /&gt;
col program for a20&lt;br /&gt;
col machine for a10&lt;br /&gt;
col action for a10&lt;br /&gt;
col module for a10&lt;br /&gt;
col identifier for a10&lt;br /&gt;
col event for a27&lt;br /&gt;
col state for a8&lt;br /&gt;
col service_name for a10&lt;br /&gt;
col serial# for 999999&lt;br /&gt;
&lt;br /&gt;
select a.username&lt;br /&gt;
,      a.command&lt;br /&gt;
,      a.lockwait&lt;br /&gt;
,      a.status&lt;br /&gt;
,      a.schemaname&lt;br /&gt;
,      a.osuser&lt;br /&gt;
,      a.process&lt;br /&gt;
,      a.machine&lt;br /&gt;
,      a.program&lt;br /&gt;
,      a.type&lt;br /&gt;
--,      a.sql_exec_start&lt;br /&gt;
--,      a.plsql_object_id&lt;br /&gt;
--,      a.plsql_subprogram_id&lt;br /&gt;
--,      a.module&lt;br /&gt;
--,      a.action&lt;br /&gt;
,      a.logon_time&lt;br /&gt;
,      a.event&lt;br /&gt;
,      a.wait_time&lt;br /&gt;
,      a.seconds_in_wait&lt;br /&gt;
,      a.state&lt;br /&gt;
--,      a.service_name&lt;br /&gt;
,      a.serial#&lt;br /&gt;
,      b.sql_text&lt;br /&gt;
from   v$session a&lt;br /&gt;
,      v$sqlarea b&lt;br /&gt;
where  a.sql_address = b.address&lt;br /&gt;
order  by a.logon_time desc&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
set lines 80&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===A logminer session===&lt;br /&gt;
Mine all SQL statements in a 10 minute period&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sqlplus / as sysdba&lt;br /&gt;
alter session set nls_date_format = &amp;#039;DD-MON-YYYY HH24:MI:SS&amp;#039;;&lt;br /&gt;
execute dbms_logmnr.start_logmnr ( starttime =&amp;gt; &amp;#039;27-OCT-2009 11:05:00&amp;#039;&lt;br /&gt;
                                 , endtime   =&amp;gt; &amp;#039;27-OCT-2009 11:15:00&amp;#039;&lt;br /&gt;
                                 , options   =&amp;gt; dbms_logmnr.dict_from_online_catalog+dbms_logmnr.continuous_mine&lt;br /&gt;
                                 );&lt;br /&gt;
create table mycontents as select * from v$logmnr_contents;&lt;br /&gt;
execute dbms_logmnr.end_logmnr(); &lt;br /&gt;
&lt;br /&gt;
select * from mycontents;&lt;br /&gt;
&lt;br /&gt;
drop table mycontents;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Huge Pages===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
#&lt;br /&gt;
# hugepages_settings.sh&lt;br /&gt;
#&lt;br /&gt;
# Linux bash script to compute values for the&lt;br /&gt;
# recommended HugePages/HugeTLB configuration&lt;br /&gt;
#&lt;br /&gt;
# Note: This script does calculation for all shared memory&lt;br /&gt;
# segments available when the script is run, no matter it&lt;br /&gt;
# is an Oracle RDBMS shared memory segment or not.&lt;br /&gt;
# Check for the kernel version&lt;br /&gt;
KERN=`uname -r | awk -F. &amp;#039;{ printf(&amp;quot;%d.%d\n&amp;quot;,$1,$2); }&amp;#039;`&lt;br /&gt;
# Find out the HugePage size&lt;br /&gt;
HPG_SZ=`grep Hugepagesize /proc/meminfo | awk {&amp;#039;print $2&amp;#039;}`&lt;br /&gt;
# Start from 1 pages to be on the safe side and guarantee 1 free HugePage&lt;br /&gt;
NUM_PG=1&lt;br /&gt;
# Cumulative number of pages required to handle the running shared memory segments&lt;br /&gt;
for SEG_BYTES in `ipcs -m | awk {&amp;#039;print $5&amp;#039;} | grep &amp;quot;[0-9][0-9]*&amp;quot;`&lt;br /&gt;
do&lt;br /&gt;
   MIN_PG=`echo &amp;quot;$SEG_BYTES/($HPG_SZ*1024)&amp;quot; | bc -q`&lt;br /&gt;
   if [ $MIN_PG -gt 0 ]; then&lt;br /&gt;
      NUM_PG=`echo &amp;quot;$NUM_PG+$MIN_PG+1&amp;quot; | bc -q`&lt;br /&gt;
   fi&lt;br /&gt;
done&lt;br /&gt;
# Finish with results&lt;br /&gt;
case $KERN in&lt;br /&gt;
   &amp;#039;2.4&amp;#039;) HUGETLB_POOL=`echo &amp;quot;$NUM_PG*$HPG_SZ/1024&amp;quot; | bc -q`;&lt;br /&gt;
          echo &amp;quot;Recommended setting: vm.hugetlb_pool = $HUGETLB_POOL&amp;quot; ;;&lt;br /&gt;
   &amp;#039;2.6&amp;#039; | &amp;#039;3.8&amp;#039;) echo &amp;quot;Recommended setting: vm.nr_hugepages = $NUM_PG&amp;quot; ;;&lt;br /&gt;
    *) echo &amp;quot;Unrecognized kernel version $KERN. Exiting.&amp;quot; ;;&lt;br /&gt;
esac&lt;br /&gt;
# End&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Pretty longops listing===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 2000 pages 1000&lt;br /&gt;
col opname for a34 head &amp;quot;Job&amp;quot;&lt;br /&gt;
col message for a60&lt;br /&gt;
col perc_done for a10 head &amp;quot;Done&amp;quot;&lt;br /&gt;
col started for a18&lt;br /&gt;
col killer for a15&lt;br /&gt;
col mins_busy head &amp;quot;Mins busy&amp;quot;&lt;br /&gt;
col mins_left head &amp;quot;Mins left&amp;quot;&lt;br /&gt;
select sid||&amp;#039;,&amp;#039;||serial#                       killer&lt;br /&gt;
,      opname&lt;br /&gt;
,      message&lt;br /&gt;
,      round ((sofar/totalwork),4)*100||&amp;#039;%&amp;#039;    perc_done&lt;br /&gt;
,      to_char(start_time,&amp;#039;DD-MON-YY HH24:MI&amp;#039;) started&lt;br /&gt;
,      floor(elapsed_seconds/60)               mins_busy&lt;br /&gt;
,      ceil(time_remaining/60)                 mins_left&lt;br /&gt;
from   v$session_longops&lt;br /&gt;
where  1=1&lt;br /&gt;
and    sofar     != totalwork&lt;br /&gt;
and    totalwork != 0&lt;br /&gt;
and    opname    like &amp;#039;RMAN%&amp;#039;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select * from v$session where module=&amp;#039;Data Pump Worker&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or attach to the impdp job and it shows percentage done.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Get the SID from v$session_longops and plug it into v$session to check the SQL command details.&lt;br /&gt;
&lt;br /&gt;
Current Running SQLs&lt;br /&gt;
--------------------&lt;br /&gt;
set pages 1000 lines 2000&lt;br /&gt;
col program  format a40&lt;br /&gt;
col sql_text format a130&lt;br /&gt;
&lt;br /&gt;
select s.sid&lt;br /&gt;
,      s.status&lt;br /&gt;
,      s.last_call_et&lt;br /&gt;
,      s.program&lt;br /&gt;
,      sa.sql_id&lt;br /&gt;
,      sa.sql_text&lt;br /&gt;
from   v$session s&lt;br /&gt;
,      v$sqlarea sa&lt;br /&gt;
where  s.sql_id = sa.sql_id&lt;br /&gt;
and    s.sid = &amp;#039;&amp;amp;sid&amp;#039;&lt;br /&gt;
/ &lt;br /&gt;
&lt;br /&gt;
set pages 1000 lines 2000&lt;br /&gt;
col USERNAME for a10&lt;br /&gt;
col OSUSER   for a10&lt;br /&gt;
col MACHINE  for a10&lt;br /&gt;
&lt;br /&gt;
select s.sid&lt;br /&gt;
,      s.serial#&lt;br /&gt;
,      p.spid&lt;br /&gt;
,      s.username&lt;br /&gt;
,      s.osuser&lt;br /&gt;
,      s.status&lt;br /&gt;
,      s.process fg_pid&lt;br /&gt;
,      s.longon_time&lt;br /&gt;
,      s.machine&lt;br /&gt;
,      p.spid bg_pid&lt;br /&gt;
from   gv$session s&lt;br /&gt;
,      gv$process p&lt;br /&gt;
where  s.addr = p.addr&lt;br /&gt;
and    s.sid  = &amp;#039;&amp;amp;sid&amp;#039;&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
$ps -ef | grep &amp;lt;spid&amp;gt;&lt;br /&gt;
&lt;br /&gt;
set pages 1000 lines 2000&lt;br /&gt;
SELECT INST_ID&lt;br /&gt;
,      SID&lt;br /&gt;
,      SERIAL#&lt;br /&gt;
,      SQL_ID&lt;br /&gt;
,      USERNAME&lt;br /&gt;
,      PROGRAM&lt;br /&gt;
,      MACHINE&lt;br /&gt;
,      SERVICE_NAME&lt;br /&gt;
FROM   GV$SESSION&lt;br /&gt;
WHERE  SID IN (&amp;#039;&amp;lt;SID_NO.1&amp;gt;&amp;#039;,&amp;#039;&amp;lt;SID_NO.2&amp;gt;&amp;#039;)&lt;br /&gt;
/&lt;br /&gt;
Active Running SQLs&lt;br /&gt;
--------------------&lt;br /&gt;
set pages 1000 lines 2000&lt;br /&gt;
col SPID     for a10&lt;br /&gt;
col PROGRAM  for a15&lt;br /&gt;
col OSUSER   for a10&lt;br /&gt;
col ACTION   for a10&lt;br /&gt;
col EVENT    for a25&lt;br /&gt;
col SQL_TEXT for a25&lt;br /&gt;
col MACHINE  for a10&lt;br /&gt;
col P1TEXT   for a10 &lt;br /&gt;
col P2TEXT   for a10&lt;br /&gt;
col P3TEXT   for a10  &lt;br /&gt;
SELECT b.sid&lt;br /&gt;
,      b.serial#&lt;br /&gt;
,      a.spid&lt;br /&gt;
,      b.sql_id&lt;br /&gt;
,      b.program&lt;br /&gt;
,      b.osuser&lt;br /&gt;
,      b.machine&lt;br /&gt;
,      b.type&lt;br /&gt;
,      b.event&lt;br /&gt;
,      b.action&lt;br /&gt;
,      b.p1text&lt;br /&gt;
,      b.p2text&lt;br /&gt;
,      b.p3text&lt;br /&gt;
,      b.state&lt;br /&gt;
,      c.sql_text&lt;br /&gt;
,      b.logon_time&lt;br /&gt;
FROM   v$process a&lt;br /&gt;
,      v$session b&lt;br /&gt;
,      v$sqltext c&lt;br /&gt;
WHERE  a.addr           = b.paddr&lt;br /&gt;
AND    b.sql_hash_value = c.hash_value&lt;br /&gt;
AND    b.STATUS         = &amp;#039;ACTIVE&amp;#039;&lt;br /&gt;
AND    b.sid            = &amp;#039;&amp;amp;sid&amp;#039;&lt;br /&gt;
ORDER  BY a.spid&lt;br /&gt;
,      c.piece&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
OR - Use the below Query &lt;br /&gt;
&lt;br /&gt;
Longops.sql&lt;br /&gt;
----------- &lt;br /&gt;
set pages 50000 lines 32767&lt;br /&gt;
col OPNAME for a10&lt;br /&gt;
col SID form 9999&lt;br /&gt;
col SERIAL form 9999999&lt;br /&gt;
col PROGRAM for a10&lt;br /&gt;
col USERNAME for a10&lt;br /&gt;
col SQL_TEXT for a40&lt;br /&gt;
col START_TIME for a10&lt;br /&gt;
col LAST_UPDATE_TIME for a10&lt;br /&gt;
col TARGET for a25&lt;br /&gt;
col MESSAGE for a25&lt;br /&gt;
&lt;br /&gt;
alter session set nls_date_format = &amp;#039;DD-MM-YYYY HH24:MI:SS&amp;#039;;&lt;br /&gt;
&lt;br /&gt;
SELECT l.inst_id,l.sid, l.serial#, l.sql_id, l.opname, l.username, l.target, l.sofar, l.totalwork, l.start_time,l.last_update_time,round(l.time_remaining/60,2) &amp;quot;REMAIN MINS&amp;quot;, round(l.elapsed_seconds/60,2) &amp;quot;ELAPSED MINS&amp;quot;, round((l.time_remaining+l.elapsed_seconds)/60,2) &amp;quot;TOTAL MINS&amp;quot;, ROUND(l.SOFAR/l.TOTALWORK*100,2) &amp;quot;%_COMPLETE&amp;quot;, l.message,s.sql_text &lt;br /&gt;
FROM gv$session_longops l &lt;br /&gt;
LEFT OUTER JOIN v$sql s on s.hash_value=l.sql_hash_value and s.address=l.sql_address and s.child_number=0&lt;br /&gt;
WHERE l.OPNAME NOT LIKE &amp;#039;RMAN%&amp;#039; AND l.OPNAME NOT LIKE &amp;#039;%aggregate%&amp;#039; AND l.TOTALWORK != 0 AND l.sofar&amp;lt;&amp;gt;l.totalwork AND l.time_remaining &amp;gt; 0&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Apply the database patch after the ORACLE_HOME has been patched===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ORAENV_ASK=NO&lt;br /&gt;
export ORACLE_SID=$1&lt;br /&gt;
. oraenv&lt;br /&gt;
&lt;br /&gt;
sqlplus /nolog &amp;lt;&amp;lt;EOSQL&lt;br /&gt;
connect / as sysdba&lt;br /&gt;
startup&lt;br /&gt;
@?/rdbms/admin/catbundle.sql psu apply&lt;br /&gt;
@?/rdbms/admin/utlrp.sql&lt;br /&gt;
purge dba_recyclebin;&lt;br /&gt;
&lt;br /&gt;
prompt check patch apply...&lt;br /&gt;
set lines 150&lt;br /&gt;
col action_time for a50&lt;br /&gt;
col comp_name for a50&lt;br /&gt;
col comments for a50&lt;br /&gt;
&lt;br /&gt;
select action_time,action,comments from sys.registry\$history where trunc(action_time) = trunc(sysdate);&lt;br /&gt;
select comp_name,version,status,modified from dba_registry;&lt;br /&gt;
exit&lt;br /&gt;
EOSQL&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Show how much archivelog data is generated per day===&lt;br /&gt;
A companion script for &amp;#039;how many log switches in a day&amp;#039;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
col orderby noprint&lt;br /&gt;
select trunc(first_time) orderby&lt;br /&gt;
,      to_char(first_time,&amp;#039;DD-MON-YYYY&amp;#039;) &amp;quot;Date&amp;quot;&lt;br /&gt;
,      round(sum(bytes/1024/1024/1024),2) arch_logs_gigs&lt;br /&gt;
from (&lt;br /&gt;
    select unique (blocks * block_size) bytes,&lt;br /&gt;
    thread#,&lt;br /&gt;
    sequence#,&lt;br /&gt;
    resetlogs_change#,&lt;br /&gt;
    first_time&lt;br /&gt;
    from v$archived_log&lt;br /&gt;
)&lt;br /&gt;
group by trunc(first_time)&lt;br /&gt;
,      to_char(first_time, &amp;#039;DD-MON-YYYY&amp;#039;)&lt;br /&gt;
order by trunc(first_time) desc&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Abort a hanging database even when sysdba cannot connect===&lt;br /&gt;
Unable to connect to database with sqlplus / as sysdba because audit file cannot be created?&lt;br /&gt;
* [http://tech.e2sn.com/oracle/troubleshooting/hang/how-to-log-on-even-when-sysdba-can-t-do-so tech.e2sn.com]&lt;br /&gt;
* [http://blog.dbi-services.com/oracle-is-hanging-dont-forget-hanganalyze-and-systemstate/ blog.dbi-services.com]&lt;br /&gt;
Instead of just killing the pmon process, there is a kinder (and more useful) way to kill the database.&amp;lt;br /&amp;gt;&lt;br /&gt;
Use the hidden, undocumented &amp;#039;prelim&amp;#039; switch parameter to sqlplus to make a connection to the database without creating SGA session data structures.&amp;lt;br /&amp;gt;&lt;br /&gt;
It can be very useful for hang analysis so the possible cause can be found after the database has been restarted.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sqlplus -prelim / as sysdba&lt;br /&gt;
oradebug unlimit&lt;br /&gt;
oradebug hanganalyze 3&lt;br /&gt;
oradebug setmypid              -- or oradebug setorapname diag&lt;br /&gt;
oradebug dump ashdumpseconds 30&lt;br /&gt;
oradebug dump systemstate 10   -- or oradebug dump systemstate 266&lt;br /&gt;
oradebug tracefile_name&lt;br /&gt;
shutdown abort&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Lists Oracle session with kill session statement all ready to go===&lt;br /&gt;
disconnect attempts to kill the o/s processes too. kill doesn&amp;#039;t.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
col killer for a60&lt;br /&gt;
col osuser for a12&lt;br /&gt;
col logon  for a23&lt;br /&gt;
col spid   for a8&lt;br /&gt;
col username for a15&lt;br /&gt;
col program for a50&lt;br /&gt;
set lines 2000&lt;br /&gt;
select &amp;#039;alter system disconnect session &amp;#039;&amp;#039;&amp;#039;||s.sid||&amp;#039;,&amp;#039;||s.serial#||&amp;#039;&amp;#039;&amp;#039; immediate;&amp;#039; killer&lt;br /&gt;
,      s.inst_id&lt;br /&gt;
,      to_char(s.logon_time,&amp;#039;DD-MON-YY HH24:MI:SS&amp;#039;) logon&lt;br /&gt;
,      sci.osuser&lt;br /&gt;
,      p.spid&lt;br /&gt;
,      s.username&lt;br /&gt;
,      s.program&lt;br /&gt;
from   gv$session s&lt;br /&gt;
,      gv$session_connect_info sci&lt;br /&gt;
,      gv$process p&lt;br /&gt;
where  1=1&lt;br /&gt;
and    p.addr     = s.paddr&lt;br /&gt;
and    p.inst_id  = s.inst_id&lt;br /&gt;
and    s.sid      = sci.sid&lt;br /&gt;
and    s.serial#  = sci.serial#&lt;br /&gt;
and    s.type    != &amp;#039;BACKGROUND&amp;#039;&lt;br /&gt;
and    sci.osuser = &amp;#039;oraibm&amp;#039;&lt;br /&gt;
order  by s.logon_time desc&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
KILLER                                                          INST_ID LOGON                   OSUSER       SPID     USERNAME        PROGRAM&lt;br /&gt;
------------------------------------------------------------ ---------- ----------------------- ------------ -------- --------------- --------------------------------------------------&lt;br /&gt;
alter system disconnect session &amp;#039;490,33947&amp;#039; immediate;                1 23-JUN-16 13:30:53      oraibm       23205    SYS             sqlplus@benouerp07 (TNS V1-V3)&lt;br /&gt;
alter system disconnect session &amp;#039;490,33947&amp;#039; immediate;                1 23-JUN-16 13:30:53      oraibm       23205    SYS             sqlplus@benouerp07 (TNS V1-V3)&lt;br /&gt;
alter system disconnect session &amp;#039;490,33947&amp;#039; immediate;                1 23-JUN-16 13:30:53      oraibm       23205    SYS             sqlplus@benouerp07 (TNS V1-V3)&lt;br /&gt;
alter system disconnect session &amp;#039;490,33947&amp;#039; immediate;                1 23-JUN-16 13:30:53      oraibm       23205    SYS             sqlplus@benouerp07 (TNS V1-V3)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===How much space is being used by a guaranteed restore point?===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
show parameter recovery&lt;br /&gt;
set numwi 15&lt;br /&gt;
set lines 200&lt;br /&gt;
col name for a40&lt;br /&gt;
col time for a23&lt;br /&gt;
col gigs_limit head &amp;quot;Max (but check df -g also!)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
select name&lt;br /&gt;
,      time&lt;br /&gt;
,      round(storage_size/1024/1024/1024,2) gigs_used&lt;br /&gt;
from   v$restore_point&lt;br /&gt;
where  1=1&lt;br /&gt;
and    guarantee_flashback_database = &amp;#039;YES&amp;#039;&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
select * from v$flash_recovery_area_usage&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
select name&lt;br /&gt;
,      round(space_used/1024/1024/1024,2) gigs_used&lt;br /&gt;
,      round(space_limit/1024/1024/1024,2) gigs_limit&lt;br /&gt;
,      space_reclaimable&lt;br /&gt;
,      number_of_files&lt;br /&gt;
from v$recovery_file_dest&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Get statistics for LOB columns in a table===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select &lt;br /&gt;
  max(dbms_lob.getlength(lob_content)) max_len&lt;br /&gt;
, avg(dbms_lob.getlength(lob_content)) avg_len&lt;br /&gt;
, min(dbms_lob.getlength(lob_content)) min_len&lt;br /&gt;
, sum(case when dbms_lob.getlength(lob_content) &amp;lt;= 4000 then 1&lt;br /&gt;
else 0 end) &amp;quot;&amp;lt;4k&amp;quot;&lt;br /&gt;
, sum(case when dbms_lob.getlength(lob_content) &amp;gt; 4000 then 1&lt;br /&gt;
else 0 end) &amp;quot;&amp;gt;4k&amp;quot;&lt;br /&gt;
, sum(case when dbms_lob.getlength(lob_content) is null then 1 else&lt;br /&gt;
0 end) &amp;quot;is null&amp;quot;&lt;br /&gt;
from &amp;amp;tablename&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===badprivs.sql===&lt;br /&gt;
Check to see if any ordinary users have privileges / access / grants / rights they should not have&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select grantee, privilege, admin_option&lt;br /&gt;
from   sys.dba_sys_privs&lt;br /&gt;
where  (       privilege like &amp;#039;% ANY %&amp;#039;&lt;br /&gt;
        or     privilege in (&amp;#039;BECOME USER&amp;#039;, &amp;#039;UNLIMITED TABLESPACE&amp;#039;)&lt;br /&gt;
        or     admin_option = &amp;#039;YES&amp;#039;&lt;br /&gt;
       )&lt;br /&gt;
and    grantee not in (&amp;#039;SYS&amp;#039;, &amp;#039;SYSTEM&amp;#039;, &amp;#039;OUTLN&amp;#039;, &amp;#039;AQ_ADMINISTRATOR_ROLE&amp;#039;,&lt;br /&gt;
                      &amp;#039;DBA&amp;#039;, &amp;#039;EXP_FULL_DATABASE&amp;#039;, &amp;#039;IMP_FULL_DATABASE&amp;#039;,&lt;br /&gt;
                      &amp;#039;OEM_MONITOR&amp;#039;, &amp;#039;CTXSYS&amp;#039;, &amp;#039;DBSNMP&amp;#039;, &amp;#039;IFSSYS&amp;#039;,&lt;br /&gt;
                      &amp;#039;IFSSYS$CM&amp;#039;, &amp;#039;MDSYS&amp;#039;, &amp;#039;ORDPLUGINS&amp;#039;, &amp;#039;ORDSYS&amp;#039;,&lt;br /&gt;
                      &amp;#039;TIMESERIES_DBA&amp;#039;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Generate a list of tablespaces ready for a migration===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set echo off&lt;br /&gt;
set lines 300&lt;br /&gt;
set pages 0&lt;br /&gt;
Set headi off&lt;br /&gt;
set feedb off&lt;br /&gt;
set long 32000&lt;br /&gt;
&lt;br /&gt;
spool migration_create_target_tablespaces.sql&lt;br /&gt;
&lt;br /&gt;
exec dbms_metadata.set_transform_param(dbms_metadata.session_transform,&amp;#039;SQLTERMINATOR&amp;#039;,TRUE);&lt;br /&gt;
select DBMS_METADATA.GET_DDL(&amp;#039;TABLESPACE&amp;#039;,tablespace_name) from dba_tablespaces&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
spool off&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===List the privileges assigned to users on directories===&lt;br /&gt;
table_name is the name of the directory...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select grantor&lt;br /&gt;
,      grantee&lt;br /&gt;
,      table_schema&lt;br /&gt;
,      table_name&lt;br /&gt;
,      privilege&lt;br /&gt;
from   all_tab_privs&lt;br /&gt;
where  table_name = &amp;#039;DATA_PUMP_DIR&amp;#039;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===List the privileges assigned to users on packages/procedures===&lt;br /&gt;
table_name is the name of the package...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select grantor&lt;br /&gt;
,      grantee&lt;br /&gt;
,      table_schema&lt;br /&gt;
,      table_name&lt;br /&gt;
,      privilege&lt;br /&gt;
from   all_tab_privs&lt;br /&gt;
where  upper(table_name) like upper(&amp;#039;%UTL_FILE%&amp;#039;)&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===List the system privileges assigned to a user (used to copy user as or clone user as)===&lt;br /&gt;
Maybe this one is better [[Extract ddl with &amp;quot;dbms metadata.get ddl&amp;quot;]]&lt;br /&gt;
&lt;br /&gt;
 SELECT LPAD(&amp;#039; &amp;#039;, 2*level) || granted_role &amp;quot;USER PRIVS&amp;quot;&lt;br /&gt;
 FROM (&lt;br /&gt;
   SELECT NULL grantee,  username granted_role&lt;br /&gt;
   FROM dba_users&lt;br /&gt;
   WHERE username LIKE UPPER(&amp;#039;%&amp;amp;uname%&amp;#039;)&lt;br /&gt;
   UNION&lt;br /&gt;
   SELECT grantee, granted_role&lt;br /&gt;
   FROM dba_role_privs&lt;br /&gt;
   UNION&lt;br /&gt;
   SELECT grantee, privilege&lt;br /&gt;
   FROM dba_sys_privs)&lt;br /&gt;
 START WITH grantee IS NULL&lt;br /&gt;
 CONNECT BY grantee = prior granted_role;&lt;br /&gt;
&lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
 SELECT path&lt;br /&gt;
 FROM (&lt;br /&gt;
   SELECT grantee,&lt;br /&gt;
          sys_connect_by_path(privilege, &amp;#039;:&amp;#039;)||&amp;#039;:&amp;#039;||grantee path&lt;br /&gt;
   FROM (&lt;br /&gt;
     SELECT grantee, privilege, 0 role&lt;br /&gt;
     FROM dba_sys_privs&lt;br /&gt;
     UNION ALL&lt;br /&gt;
     SELECT grantee, granted_role, 1 role&lt;br /&gt;
     FROM dba_role_privs)&lt;br /&gt;
   CONNECT BY privilege=prior grantee&lt;br /&gt;
   START WITH role = 0)&lt;br /&gt;
 WHERE grantee IN (&lt;br /&gt;
    SELECT username&lt;br /&gt;
    FROM dba_users&lt;br /&gt;
    WHERE lock_date IS NULL&lt;br /&gt;
    AND password != &amp;#039;EXTERNAL&amp;#039;&lt;br /&gt;
    AND username != &amp;#039;SYS&amp;#039;)&lt;br /&gt;
 OR grantee=&amp;#039;PUBLIC&amp;#039;&lt;br /&gt;
&lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
for a migration from 10g...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set headi off&lt;br /&gt;
set feedb off&lt;br /&gt;
set long  9999999&lt;br /&gt;
set pages 0&lt;br /&gt;
set lines 300&lt;br /&gt;
&lt;br /&gt;
spool migration_create_target_users_grants.sql&lt;br /&gt;
&lt;br /&gt;
select dbms_metadata.get_ddl(&amp;#039;USER&amp;#039;, username) || &amp;#039;;&amp;#039; ddl&lt;br /&gt;
from dba_users&lt;br /&gt;
where  1=1&lt;br /&gt;
and    username like upper(&amp;#039;%&amp;amp;&amp;amp;USER_NAME%&amp;#039;)&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
select &amp;#039;grant &amp;#039;||privilege|| &amp;#039; to &amp;#039; || grantee || &amp;#039;;&amp;#039;&lt;br /&gt;
from   dba_sys_privs&lt;br /&gt;
where  1=1&lt;br /&gt;
and    grantee like upper(&amp;#039;%&amp;amp;&amp;amp;USER_NAME%&amp;#039;)&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
select &amp;#039;grant &amp;#039;||granted_role|| &amp;#039; to &amp;#039; || grantee || &amp;#039;;&amp;#039;&lt;br /&gt;
from   dba_role_privs&lt;br /&gt;
where  1=1&lt;br /&gt;
and    grantee like upper(&amp;#039;%&amp;amp;&amp;amp;USER_NAME%&amp;#039;)&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
spool off&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or for a migration on 11g...!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set head off&lt;br /&gt;
set pages 0&lt;br /&gt;
set long 9999999&lt;br /&gt;
col ddl for a1000&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
SELECT DBMS_METADATA.GET_DDL(&amp;#039;USER&amp;#039;, USERNAME) || &amp;#039;;&amp;#039; DDL&lt;br /&gt;
FROM DBA_USERS&lt;br /&gt;
where  1=1&lt;br /&gt;
and    default_tablespace not in (&amp;#039;SYSTEM&amp;#039;,&amp;#039;SYSAUX&amp;#039;)&lt;br /&gt;
and    upper(username) like &amp;#039;%&amp;#039;||upper(&amp;#039;&amp;amp;&amp;amp;username&amp;#039;)||&amp;#039;%&amp;#039;&lt;br /&gt;
UNION ALL&lt;br /&gt;
SELECT DBMS_METADATA.GET_GRANTED_DDL(&amp;#039;ROLE_GRANT&amp;#039;, USERNAME) || &amp;#039;;&amp;#039; DDL&lt;br /&gt;
FROM DBA_USERS&lt;br /&gt;
where  1=1&lt;br /&gt;
and    default_tablespace not in (&amp;#039;SYSTEM&amp;#039;,&amp;#039;SYSAUX&amp;#039;)&lt;br /&gt;
and    upper(username) like &amp;#039;%&amp;#039;||upper(&amp;#039;&amp;amp;&amp;amp;username&amp;#039;)||&amp;#039;%&amp;#039;&lt;br /&gt;
UNION ALL&lt;br /&gt;
SELECT DBMS_METADATA.GET_GRANTED_DDL(&amp;#039;SYSTEM_GRANT&amp;#039;, USERNAME) || &amp;#039;;&amp;#039; DDL&lt;br /&gt;
FROM DBA_USERS&lt;br /&gt;
where  1=1&lt;br /&gt;
and    default_tablespace not in (&amp;#039;SYSTEM&amp;#039;,&amp;#039;SYSAUX&amp;#039;)&lt;br /&gt;
and    upper(username) like &amp;#039;%&amp;#039;||upper(&amp;#039;&amp;amp;&amp;amp;username&amp;#039;)||&amp;#039;%&amp;#039;&lt;br /&gt;
UNION ALL&lt;br /&gt;
SELECT DBMS_METADATA.GET_GRANTED_DDL(&amp;#039;OBJECT_GRANT&amp;#039;, USERNAME) || &amp;#039;;&amp;#039; DDL&lt;br /&gt;
FROM DBA_USERS&lt;br /&gt;
where  1=1&lt;br /&gt;
and    default_tablespace not in (&amp;#039;SYSTEM&amp;#039;,&amp;#039;SYSAUX&amp;#039;)&lt;br /&gt;
and    upper(username) like &amp;#039;%&amp;#039;||upper(&amp;#039;&amp;amp;&amp;amp;username&amp;#039;)||&amp;#039;%&amp;#039;&lt;br /&gt;
&lt;br /&gt;
spool migration_create_users_grants.sql&lt;br /&gt;
/&lt;br /&gt;
spool off&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Move datafiles between filesystems===&lt;br /&gt;
* [https://blogs.oracle.com/alejandrovargas/moving-a-datafile-from-file-system-to-asm Moving a datafile from File System to ASM (does not have to be ASM!) - oracle.com]&lt;br /&gt;
* [https://docs.oracle.com/database/121/OSTMG/GUID-3B8D0956-0888-452D-A9E4-9FB8D98577E0.htm#OSTMG89997 Moving Data Files Between Oracle ASM (does not have to be ASM!) Using RMAN - oracle.com]&lt;br /&gt;
* [https://oracle-base.com/articles/misc/renaming-or-moving-oracle-files Moving a data file online between filesystems - oracle-base.com]&lt;br /&gt;
====Set the relevant datafile offline====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter database datafile 125 offline;&lt;br /&gt;
alter database datafile 126 offline;&lt;br /&gt;
alter database datafile 127 offline;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Rename the files on the filesystem using o/s commands====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter tablespace ts_thaler_data_offline;&lt;br /&gt;
&lt;br /&gt;
host mv &amp;#039;/cln/tst/ora_data1/clnt/data4/ts_thaler_data_113.dbf&amp;#039; &amp;#039;/cln/tst/ora_data1/clnt/data1/ts_thaler_data_113.dbf&amp;#039;&lt;br /&gt;
host mv &amp;#039;/cln/tst/ora_data1/clnt/data4/ts_thaler_data_114.dbf&amp;#039; &amp;#039;/cln/tst/ora_data1/clnt/data1/ts_thaler_data_114.dbf&amp;#039;&lt;br /&gt;
host mv &amp;#039;/cln/tst/ora_data1/clnt/data4/ts_thaler_data_115.dbf&amp;#039; &amp;#039;/cln/tst/ora_data1/clnt/data1/ts_thaler_data_115.dbf&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Run the relevant alter commands to inform the control files of the new locations====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter database move datafile &amp;#039;/cln/tst/ora_data1/clnt/data4/ts_thaler_data_113.dbf&amp;#039; to &amp;#039;/cln/tst/ora_data1/clnt/data1/ts_thaler_data_113.dbf&amp;#039;&lt;br /&gt;
alter database move datafile &amp;#039;/cln/tst/ora_data1/clnt/data4/ts_thaler_data_114.dbf&amp;#039; to &amp;#039;/cln/tst/ora_data1/clnt/data1/ts_thaler_data_114.dbf&amp;#039;&lt;br /&gt;
alter database move datafile &amp;#039;/cln/tst/ora_data1/clnt/data4/ts_thaler_data_115.dbf&amp;#039; to &amp;#039;/cln/tst/ora_data1/clnt/data1/ts_thaler_data_115.dbf&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Recover the datafiles====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
recover datafile 125;&lt;br /&gt;
recover datafile 126;&lt;br /&gt;
recover datafile 127;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Set the relevant datafile online====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter database datafile 125 online;&lt;br /&gt;
alter database datafile 126 online;&lt;br /&gt;
alter database datafile 127 online;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Check all is well with the datafiles by using an appropriate statement====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 2000 pages 100&lt;br /&gt;
select file_id, file_name, status, online_status from dba_data_files where tablespace_name = &amp;#039;TS_THALER_DATA&amp;#039; order by 2;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Rename a datafile on 12c====&lt;br /&gt;
If you&amp;#039;re lucky enough to be on 12c, it&amp;#039;s one command - no need to offline the datafile!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SQL&amp;gt; alter database move datafile &amp;#039;/oracle/ora_data2/prod/data4/ts_thaler_data_113.dbf&amp;#039; to &amp;#039;/oracle/ora_data2/prod/data3/ts_thaler_data_113.dbf&amp;#039;;&lt;br /&gt;
&lt;br /&gt;
Database altered.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Pass parameter/argument into perl one-liner script from shell===&lt;br /&gt;
Trick? Just use ARGV to pass them in...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
FREQ=$(perl -e &amp;#039;my @CAL=split(&amp;quot;;&amp;quot;,$ARGV[0]);shift @CAL;print $CAL[$ARGV[1]];&amp;#039; -- &amp;quot;$LINE&amp;quot; $offset)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
DUMP_DATE=`perl -MTime::Local -e &amp;#039;print(timelocal(0,$ARGV[0],$ARGV[1],$ARGV[2],$ARGV[3],$ARGV[4]))&amp;#039; -- $MI $HH $DD $MM $YYYY`&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or export the variable from shell and access it via the ENV hash&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
export db=ENDP1&lt;br /&gt;
perl -p -i -e &amp;#039;s!DSMI_LOG.+$!DSMI_LOG           /oracle/$ENV{db}/admin/tdpoerror_$ENV{db}!&amp;#039; ${db}/admin/tdpo.opt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Return epoch seconds in Perl===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
perl -e &amp;#039;print time();&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or to convert a specific day of the year to epoch seconds&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
use POSIX;&lt;br /&gt;
my $epochsecs = mktime(0,0,0, $jday, 0, $year-1900);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or for a specific date (careful though - month is 0-11 not 1-12!...&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
use Time::Local;&lt;br /&gt;
#                          SS MM HH DD MM YYYY&lt;br /&gt;
my $epochsecs = timelocal (30,10,19,03,04,2014);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or more long-winded but delimited by anything...&amp;lt;br /&amp;gt;&lt;br /&gt;
Supply the date/time in any delimited format. Eg. YYYY-MM-DD:HH:MI&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/usr/bin/perl -w&lt;br /&gt;
use Time::Local;&lt;br /&gt;
&lt;br /&gt;
sub date2epoch { &lt;br /&gt;
  my($s) = @_;&lt;br /&gt;
  my($year, $month, $day, $hour, $minute, $second);&lt;br /&gt;
&lt;br /&gt;
  if($s =~ m{^\s*(\d{1,4})\W*0*(\d{1,2})\W*0*(\d{1,2})\W*0*&lt;br /&gt;
                 (\d{0,2})\W*0*(\d{0,2})\W*0*(\d{0,2})}x) {&lt;br /&gt;
    $year = $1;  $month = $2;   $day = $3;&lt;br /&gt;
    $hour = $4;  $minute = $5;  $second = $6;&lt;br /&gt;
    $hour |= 0;  $minute |= 0;  $second |= 0;  # defaults.&lt;br /&gt;
    $year = ($year&amp;lt;100 ? ($year&amp;lt;70 ? 2000+$year : 1900+$year) : $year);&lt;br /&gt;
    return timelocal($second,$minute,$hour,$day,$month-1,$year);  &lt;br /&gt;
  }&lt;br /&gt;
  return -1;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Return epoch seconds in DOS/VBS/Windows===&lt;br /&gt;
Paste this code into epoch.vbs&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
function date2epoch(p_date)&lt;br /&gt;
    date2epoch = DateDiff(&amp;quot;s&amp;quot;, &amp;quot;01/01/1970 00:00:00&amp;quot;, p_date)&lt;br /&gt;
end function&lt;br /&gt;
&lt;br /&gt;
Wscript.Echo date2epoch(Now())&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
and call from a DOS box like this&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cscript //nologo epoch.vbs&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Return date from epoch seconds in Perl===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
perl -e &amp;#039;print scalar (localtime (1243269270))&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Return epoch seconds from julian day number in Perl===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
use POSIX;&lt;br /&gt;
my ($year, $jday) = (2012,60);&lt;br /&gt;
my $epochsecs = mktime(0,0,0, $jday, 0, $year-1900);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Extract specific pieces of a date from an epoch timestamp in Perl===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
use POSIX;&lt;br /&gt;
# return localtime into an array&lt;br /&gt;
my @tm = localtime $epochsecs;&lt;br /&gt;
&lt;br /&gt;
my $yyyymmdd = strftime &amp;quot;%Y%m%d&amp;quot;, @tm;&lt;br /&gt;
print $yyyymmdd.&amp;quot;\n&amp;quot;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Return epoch seconds in Shell (linux)===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
date -d &amp;quot;2014/04/03 18:34:30&amp;quot; &amp;quot;+%s&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Return date from epoch seconds in Shell (linux)===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
date -d @1396542870&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Return epoch seconds in PL/SQL===&lt;br /&gt;
You cannot just use sysdate as that is timezone sensitive... (epoch seconds are in UTC/GMT)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select round((cast(sys_extract_utc(systimestamp) as date) - to_date(&amp;#039;01-JAN-1970 00:00:00&amp;#039;,&amp;#039;DD-MON-YYYY HH24:MI:SS&amp;#039;))*24*60*60) from dual;&lt;br /&gt;
or&lt;br /&gt;
select round((vd.created - to_date(&amp;#039;01-JAN-1970 00:00:00&amp;#039;,&amp;#039;DD-MON-YYYY HH24:MI:SS&amp;#039;))*24*60*60)  created from v$database vd;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
How long has this instance been up (in minutes)?&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select round((cast(sys_extract_utc(systimestamp) as date) - startup_time)*24*60) up_mins from v$instance;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Return date from epoch seconds in SQL===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select to_char(to_date(&amp;#039;19700101&amp;#039;,&amp;#039;YYYYMMDD&amp;#039;) + ((&amp;amp;epoch)/24/60/60),&amp;#039;DD-MON-YYYY HH24:MI:SS&amp;#039;) utc_date from dual;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===A database overview using the sys.plato package===&lt;br /&gt;
 exec plato.help;&lt;br /&gt;
or&lt;br /&gt;
 exec plato.complete(&amp;#039;HTM&amp;#039;);&lt;br /&gt;
&lt;br /&gt;
===List datafiles for a tablespace===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select *&lt;br /&gt;
from   dba_data_files&lt;br /&gt;
where  1=1&lt;br /&gt;
and    tablespace_name =&amp;#039;&amp;amp;ts_name&amp;#039;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Show graph of available and free space in tablespaces===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
-- =============================================================================&lt;br /&gt;
-- File Name    : http://www.oracle-base.com/dba/monitoring/ts_free_space.sql&lt;br /&gt;
-- Author       : Tim Hall&lt;br /&gt;
-- Description  : Displays a list of tablespaces and their used/full status.&lt;br /&gt;
-- Requirements : Access to the DBA views.&lt;br /&gt;
-- Call Syntax  : @ts_free_space.sql&lt;br /&gt;
-- Last Modified: 13-OCT-2012 - Created. Based on ts_full.sql&lt;br /&gt;
--&lt;br /&gt;
-- Modification History&lt;br /&gt;
-- ====================&lt;br /&gt;
-- When      Who               What&lt;br /&gt;
-- ========= ================= =================================================&lt;br /&gt;
-- 13-NOV-13 Stuart Barkley    Added cols free_pct and used_pct&lt;br /&gt;
-- =============================================================================&lt;br /&gt;
SET PAGESIZE 140 lines 180&lt;br /&gt;
COLUMN used_pct FORMAT A11&lt;br /&gt;
COLUMN max_used_pct FORMAT A11&lt;br /&gt;
&lt;br /&gt;
    SELECT tablespace_name                                                                      tablespace_name&lt;br /&gt;
    ,      size_mb                                                                              size_mb&lt;br /&gt;
    ,      free_mb                                                                              free_mb&lt;br /&gt;
    ,      TRUNC((free_mb/size_mb) * 100)                                                       free_pct&lt;br /&gt;
    ,      RPAD(&amp;#039; &amp;#039;|| RPAD(&amp;#039;X&amp;#039;,ROUND((size_mb-free_mb)/size_mb*10,0), &amp;#039;X&amp;#039;),11,&amp;#039;-&amp;#039;)              used_pct&lt;br /&gt;
    ,      max_size_mb                                                                          max_size_mb&lt;br /&gt;
    ,      max_free_mb                                                                          max_free_mb&lt;br /&gt;
    ,      TRUNC((max_free_mb/max_size_mb) * 100)                                               max_free_pct&lt;br /&gt;
    ,      RPAD(&amp;#039; &amp;#039;|| RPAD(&amp;#039;X&amp;#039;,ROUND((max_size_mb-max_free_mb)/max_size_mb*10,0), &amp;#039;X&amp;#039;),11,&amp;#039;-&amp;#039;)  max_used_pct&lt;br /&gt;
    from   (&lt;br /&gt;
           select a.tablespace_name                                         tablespace_name&lt;br /&gt;
           ,      b.size_mb                                                 size_mb&lt;br /&gt;
           ,      a.free_mb                                                 free_mb&lt;br /&gt;
           ,      b.max_size_mb                                             max_size_mb&lt;br /&gt;
           ,      a.free_mb + (b.max_size_mb - b.size_mb)                   max_free_mb&lt;br /&gt;
           from   (&lt;br /&gt;
                  select tablespace_name                                    tablespace_name&lt;br /&gt;
                  ,      trunc(sum(bytes)/1024/1024)                        free_mb&lt;br /&gt;
                  from   dba_free_space&lt;br /&gt;
                  group  by tablespace_name&lt;br /&gt;
                  ) a&lt;br /&gt;
           ,      (&lt;br /&gt;
                  select tablespace_name                                    tablespace_name&lt;br /&gt;
                  ,        trunc(sum(bytes)/1024/1024)                      size_mb&lt;br /&gt;
                  ,        trunc(sum(greatest(bytes,maxbytes))/1024/1024)   max_size_mb&lt;br /&gt;
                  from   dba_data_files&lt;br /&gt;
                  group by tablespace_name&lt;br /&gt;
                  ) b&lt;br /&gt;
           ,      v$instance vi&lt;br /&gt;
           where  a.tablespace_name = b.tablespace_name&lt;br /&gt;
           )&lt;br /&gt;
    order  by tablespace_name;&lt;br /&gt;
&lt;br /&gt;
set lines 80&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Another method for calculating free space in tablespace  using segments===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select df.tablespace_name &amp;quot;Tablespace&amp;quot;&lt;br /&gt;
,      totalusedspace &amp;quot;Used MB&amp;quot;&lt;br /&gt;
,      (df.totalspace - tu.totalusedspace) &amp;quot;Free MB&amp;quot;&lt;br /&gt;
,      df.totalspace &amp;quot;Total MB&amp;quot;&lt;br /&gt;
,      round(100 * ( (df.totalspace - tu.totalusedspace)/ df.totalspace)) &amp;quot;Pct. Free&amp;quot;&lt;br /&gt;
from   (&lt;br /&gt;
       select tablespace_name&lt;br /&gt;
,      round(sum(bytes) / 1048576) totalspace&lt;br /&gt;
       from   dba_data_files&lt;br /&gt;
       group  by tablespace_name&lt;br /&gt;
       ) df&lt;br /&gt;
,      (&lt;br /&gt;
       select round(sum(bytes)/(1024*1024)) totalusedspace&lt;br /&gt;
       ,      tablespace_name&lt;br /&gt;
       from   dba_segments&lt;br /&gt;
       group  by tablespace_name&lt;br /&gt;
       ) tu&lt;br /&gt;
where  df.tablespace_name = tu.tablespace_name;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Work out maximum possible size of a datafile===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select round( (4*1024*1024*value) / (1024*1024*1024) ,2) maxfilesizeingigabytes from v$parameter where name=&amp;#039;db_block_size&amp;#039;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or, as tablespaces can have block sizes differing from that of the init.ora parameter...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select round( (4*1024*1024*block_size) / (1024*1024*1024) ,2) maxfilesizeingigabytes from dba_tablespaces where tablespace_name=&amp;#039;&amp;amp;tablespace_name&amp;#039;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Show size and maxsize at datafile level===&lt;br /&gt;
datafiles&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set pages 100 lines 200&lt;br /&gt;
col file_name for a60&lt;br /&gt;
select sum(bytes)/1024/1024      mbytes_alloc&lt;br /&gt;
,      sum(maxbytes)/1024/1024   mbytes_max&lt;br /&gt;
,      file_name&lt;br /&gt;
from   sys.dba_data_files&lt;br /&gt;
group  by file_name&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
tempfiles&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set pages 100 lines 200&lt;br /&gt;
col file_name for a60&lt;br /&gt;
select sum(bytes)/1024/1024      mbytes_alloc&lt;br /&gt;
,      sum(maxbytes)/1024/1024   mbytes_max&lt;br /&gt;
,      file_name&lt;br /&gt;
from   sys.dba_temp_files&lt;br /&gt;
group  by file_name&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Resize the online redo logfiles===&lt;br /&gt;
Found a more concise, smarter way of doing it [http://www.oracle-wiki.net/startdocshowtorecreateredogrps here] - oracle-wiki.net&amp;lt;br /&amp;gt;&lt;br /&gt;
Switching logs too often? Redolog files too small?&amp;lt;br /&amp;gt;&lt;br /&gt;
* Show current log groups&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 1000&lt;br /&gt;
col group_member for a60&lt;br /&gt;
select l.group#          group_number&lt;br /&gt;
,      (bytes/1024/1024) megs&lt;br /&gt;
,      l.status          group_status&lt;br /&gt;
,      f.member          group_member&lt;br /&gt;
,      l.archived        archived&lt;br /&gt;
,      f.type            file_type&lt;br /&gt;
from   v$log     l&lt;br /&gt;
,      v$logfile f&lt;br /&gt;
where  l.group# = f.group#&lt;br /&gt;
order  by l.group#&lt;br /&gt;
,      f.member&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Create additional (bigger) groups&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
define SID=TIBQFW&lt;br /&gt;
alter database add logfile group 6  &amp;#039;/oracle/&amp;amp;SID/oradata1/redo1.log&amp;#039; size 1G;&lt;br /&gt;
alter database add logfile group 7  &amp;#039;/oracle/&amp;amp;SID/oradata2/redo2.log&amp;#039; size 1G;&lt;br /&gt;
alter database add logfile group 8  &amp;#039;/oracle/&amp;amp;SID/oradata3/redo3.log&amp;#039; size 1G;&lt;br /&gt;
alter database add logfile group 9  &amp;#039;/oracle/&amp;amp;SID/oradata1/redo4.log&amp;#039; size 1G;&lt;br /&gt;
alter database add logfile group 10 &amp;#039;/oracle/&amp;amp;SID/oradata2/redo5.log&amp;#039; size 1G;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or if you use multiple members...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter database add logfile group 6 (&amp;#039;/oracle/&amp;amp;SID/oradata1/redo/redo01a.log&amp;#039;, &amp;#039;/oracle/&amp;amp;SID/oradata1/redo01b&amp;#039;) size 50M;&lt;br /&gt;
alter database add logfile group 7 (&amp;#039;/oracle/&amp;amp;SID/oradata1/redo/redo02a.log&amp;#039;, &amp;#039;/oracle/&amp;amp;SID/oradata1/redo02b&amp;#039;) size 50M;&lt;br /&gt;
alter database add logfile group 8 (&amp;#039;/oracle/&amp;amp;SID/oradata1/redo/redo03a.log&amp;#039;, &amp;#039;/oracle/&amp;amp;SID/oradata1/redo03b&amp;#039;) size 50M;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Switch archivelogs until the new ones are current and the old ones are inactive&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter system switch logfile;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
If the old logs are not yet inactive, checkpoint the database&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter system checkpoint;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Drop the old groups&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter database drop logfile group 1;&lt;br /&gt;
alter database drop logfile group 2;&lt;br /&gt;
alter database drop logfile group 3;&lt;br /&gt;
alter database drop logfile group 4;&lt;br /&gt;
alter database drop logfile group 5;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Increase the existing size of a datafile===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter database datafile &amp;#039;&amp;amp;full_path_of_datafile&amp;#039; resize &amp;amp;new_meg_size.M;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Increase the max size of a tempfile===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter database tempfile &amp;#039;/oracle/ENDP1/oradata90/temp01.dbf&amp;#039; autoextend on maxsize unlimited;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Find out what processes are using the temp tablespace===&lt;br /&gt;
Temporary tablespace is used for sorting query results. Find them with this.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SELECT b.tablespace,b.segfile#,b.segblk#,b.blocks,a.sid,a.serial#,&lt;br /&gt;
a.username,a.osuser, a.status&lt;br /&gt;
FROM v$session a,v$sort_usage b&lt;br /&gt;
WHERE a.saddr = b.session_addr;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Increase the maximum size of a datafile===&lt;br /&gt;
Although this can be set lower than existing size, try not to. It makes the reports look weird!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter database&lt;br /&gt;
      datafile &amp;#039;&amp;amp;full_path_of_datafile&amp;#039;&lt;br /&gt;
      autoextend on&lt;br /&gt;
      maxsize &amp;amp;new_meg_size.m;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Find schemas (users) with objects created outside their default tablespace===&lt;br /&gt;
Indexes could be a notable exception if they are created in an index tablespace&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 200&lt;br /&gt;
col owner           for a20&lt;br /&gt;
col segment_name    for a45&lt;br /&gt;
col tablespace_name for a32&lt;br /&gt;
select owner&lt;br /&gt;
,      segment_name&lt;br /&gt;
,      tablespace_name&lt;br /&gt;
from   dba_segments&lt;br /&gt;
where  exists (select username from dba_users where username = owner)&lt;br /&gt;
and    tablespace_name != (select default_tablespace from dba_users where username = owner)&lt;br /&gt;
and    owner = &amp;#039;&amp;amp;owner&amp;#039;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Add a datafile to a tablespace===&lt;br /&gt;
&amp;#039;unlimited&amp;#039; will default to the maximum datafile size for the current db_block_size&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter tablepace &amp;amp;tablespace_name&lt;br /&gt;
      add datafile &amp;#039;&amp;amp;full_path_of_datafile&amp;#039;&lt;br /&gt;
      size 100M&lt;br /&gt;
      autoextend on&lt;br /&gt;
      next 100M&lt;br /&gt;
      maxsize unlimited&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===List all datafiles with their size===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set pages 1000 lines 2000&lt;br /&gt;
col filetype for a15&lt;br /&gt;
col name for a60&lt;br /&gt;
break on report&lt;br /&gt;
compute sum of gig on report&lt;br /&gt;
&lt;br /&gt;
select filetype&lt;br /&gt;
,      name&lt;br /&gt;
,      gig&lt;br /&gt;
from   (&lt;br /&gt;
       select &amp;#039;datafile&amp;#039; filetype&lt;br /&gt;
       ,      name&lt;br /&gt;
       ,      bytes/1024/1024 gig&lt;br /&gt;
       from   v$datafile&lt;br /&gt;
       union all&lt;br /&gt;
       select &amp;#039;tempfile&amp;#039; filetype&lt;br /&gt;
       ,      name&lt;br /&gt;
       ,      bytes/1024/1024&lt;br /&gt;
       from   v$tempfile&lt;br /&gt;
       union all&lt;br /&gt;
       select &amp;#039;logfile&amp;#039; filetype&lt;br /&gt;
       ,      lf.member &amp;quot;name&amp;quot;&lt;br /&gt;
       ,      l.bytes/1024/1024&lt;br /&gt;
       from   v$logfile lf&lt;br /&gt;
       ,      v$log     l&lt;br /&gt;
       where  1=1&lt;br /&gt;
       and    lf.group# = l.group#&lt;br /&gt;
       ) used&lt;br /&gt;
,      (&lt;br /&gt;
       select sum(bytes)/1024/1024&lt;br /&gt;
       from   dba_free_space&lt;br /&gt;
       ) free&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Database size (How big is my database?)===&lt;br /&gt;
There are different interpretations of what constitutes the size of a database...&amp;lt;br /&amp;gt;&lt;br /&gt;
Is it the space allocated to the datafiles or only the space taken up by the data? Are tempfiles included? Are redo logs included? etc...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 132&lt;br /&gt;
col dbname for a9  heading &amp;quot;Database&amp;quot;&lt;br /&gt;
col dbsize for a15 heading &amp;quot;Size&amp;quot;&lt;br /&gt;
col dbused for a15 heading &amp;quot;Used space&amp;quot;&lt;br /&gt;
col dbfree for a15 heading &amp;quot;Free space&amp;quot;&lt;br /&gt;
with used_space as&lt;br /&gt;
(&lt;br /&gt;
select  bytes&lt;br /&gt;
from    v$datafile&lt;br /&gt;
union   all&lt;br /&gt;
select  bytes&lt;br /&gt;
from    v$tempfile&lt;br /&gt;
union   all&lt;br /&gt;
select  bytes&lt;br /&gt;
from    v$log&lt;br /&gt;
)&lt;br /&gt;
, free_space as&lt;br /&gt;
(&lt;br /&gt;
select sum(bytes) sum_bytes&lt;br /&gt;
from dba_free_space&lt;br /&gt;
)&lt;br /&gt;
select vd.name                                                                                            dbname&lt;br /&gt;
,      round(sum(used_space.bytes)/1024/1024/1024 ) || &amp;#039; GB&amp;#039;                                              dbsize&lt;br /&gt;
,      round(sum(used_space.bytes)/1024/1024/1024 ) - round(free_space.sum_bytes/1024/1024/1024) || &amp;#039; GB&amp;#039; dbused&lt;br /&gt;
,      round(free_space.sum_bytes/1024/1024/1024) || &amp;#039; GB&amp;#039;                                                dbfree&lt;br /&gt;
from   free_space&lt;br /&gt;
,      used_space&lt;br /&gt;
,      v$database vd&lt;br /&gt;
group  by vd.name&lt;br /&gt;
,      free_space.sum_bytes&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Drop datafile from temp tablespace===&lt;br /&gt;
Database is completely stuck because the temporary tablespace has grown to fill all available room.&amp;lt;br /&amp;gt;&lt;br /&gt;
Look around for at least some log files to delete in order to get connected (audit files, sqlnet logs, listener logs)&amp;lt;br /&amp;gt;&lt;br /&gt;
Once connected, change the default temporary tablespace to a small one so we can remove the original.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
create temporary tablespace temp2 tempfile &amp;#039;/oracle/RMANV12/oradata2/temp2.dbf&amp;#039; size 5M;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter database default temporary tablespace temp2;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
I found trying to drop the datafile like this didn&amp;#039;t work, just hung there (probably active tranactions)...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
drop tablespace temp including contents and datafiles;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
So did it like this...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter database tempfile &amp;#039;/oracle/RMANV12/oradata2/temp.dbf&amp;#039; drop including datafiles;&lt;br /&gt;
&lt;br /&gt;
Database altered.&lt;br /&gt;
&lt;br /&gt;
drop tablespace temp including contents and datafiles;&lt;br /&gt;
&lt;br /&gt;
Tablespace dropped.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
... an alternative would be to find the sessions using the temp space and kill them...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select sid, serial#, status from v$session where serial# in (select session_num from v$sort_usage);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Then to be neat and tidy, rename the temp2 tablespace back to temp.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
create temporary tablespace temp tempfile &amp;#039;/oracle/RMANV12/oradata2/temp.dbf&amp;#039; size 256M reuse autoextend on next 128M maxsize 1G;&lt;br /&gt;
alter database default temporary tablespace temp;&lt;br /&gt;
drop tablespace temp2 including contents and datafiles;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Although the last statement will not work until any transactions using it have been rolled back or committed.&lt;br /&gt;
&lt;br /&gt;
===List files that are in hot-backup mode===&lt;br /&gt;
 set lines 100&lt;br /&gt;
 set pages 100&lt;br /&gt;
 col name format a60&lt;br /&gt;
 &lt;br /&gt;
 select df.name&lt;br /&gt;
 ,      b.status&lt;br /&gt;
 ,      to_char(time, &amp;#039;hh24:mi:ss dd/mm/yyyy&amp;#039;) time&lt;br /&gt;
 from   v$datafile   df&lt;br /&gt;
 ,      v$backup     b&lt;br /&gt;
 where  1=1&lt;br /&gt;
 and    df.file# = b.file#&lt;br /&gt;
 and    b.status = &amp;#039;ACTIVE&amp;#039;&lt;br /&gt;
 order  by b.file#;&lt;br /&gt;
&lt;br /&gt;
===Waiting for snapshot control file enqueue===&lt;br /&gt;
Script to identify sessions causing RMAN to hang because of &amp;#039;waiting for snapshot control file enqueue&amp;#039; message&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 2000&lt;br /&gt;
col killer     for a70&lt;br /&gt;
col program    for a20&lt;br /&gt;
col module     for a20&lt;br /&gt;
col action     for a20&lt;br /&gt;
col logon_time for a20&lt;br /&gt;
&lt;br /&gt;
select &amp;#039;alter system disconnect session &amp;#039;&amp;#039;&amp;#039;||s.sid||&amp;#039;,&amp;#039;||s.serial#||&amp;#039;&amp;#039;&amp;#039; immediate;&amp;#039; killer&lt;br /&gt;
,      username&lt;br /&gt;
,      program&lt;br /&gt;
,      module&lt;br /&gt;
,      action&lt;br /&gt;
,      logon_time&lt;br /&gt;
from   v$session s&lt;br /&gt;
,      v$enqueue_lock l&lt;br /&gt;
where  l.sid  = s.sid&lt;br /&gt;
and    l.type = &amp;#039;CF&amp;#039;&lt;br /&gt;
and    l.id1  = 0&lt;br /&gt;
and    l.id2  = 2&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Info on blocking processes===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select s1.username || &amp;#039;@&amp;#039; || s1.machine&lt;br /&gt;
       || &amp;#039; ( SID=&amp;#039; || s1.sid || &amp;#039; )  is blocking &amp;#039;&lt;br /&gt;
       || s2.username || &amp;#039;@&amp;#039; || s2.machine || &amp;#039; ( SID=&amp;#039; || s2.sid || &amp;#039; ) &amp;#039;  blocking_status&lt;br /&gt;
from   v$lock l1&lt;br /&gt;
,      v$session s1&lt;br /&gt;
,      v$lock l2&lt;br /&gt;
,      v$session s2&lt;br /&gt;
where  s1.sid     = l1.sid&lt;br /&gt;
and    s2.sid     = l2.sid&lt;br /&gt;
and    l1.block   = 1&lt;br /&gt;
and    l2.request &amp;gt; 0&lt;br /&gt;
and    l1.id1     = l2.id1&lt;br /&gt;
and    l2.id2     = l2.id2&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
session doing the blocking&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select *&lt;br /&gt;
from  v$lock l1&lt;br /&gt;
where 1=1&lt;br /&gt;
and   block = 1 ;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
sessions being blocked&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select *&lt;br /&gt;
from   v$lock l1&lt;br /&gt;
where  1=1&lt;br /&gt;
and    id2 = 85203&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
info on session doing the blocking&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select row_wait_obj#, row_wait_file#, row_wait_block#, row_wait_row#&lt;br /&gt;
from   v$session&lt;br /&gt;
where  sid = 234&lt;br /&gt;
&lt;br /&gt;
select do.object_name&lt;br /&gt;
,      row_wait_obj#&lt;br /&gt;
,      row_wait_file#&lt;br /&gt;
,      row_wait_block#&lt;br /&gt;
,      row_wait_row#&lt;br /&gt;
,      dbms_rowid.rowid_create ( 1, ROW_WAIT_OBJ#, ROW_WAIT_FILE#, ROW_WAIT_BLOCK#, ROW_WAIT_ROW# ) row_id&lt;br /&gt;
from   v$session   s&lt;br /&gt;
,      dba_objects do&lt;br /&gt;
where  sid=234&lt;br /&gt;
and    s.ROW_WAIT_OBJ# = do.OBJECT_ID;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Show locked objects===&lt;br /&gt;
 set lines 100&lt;br /&gt;
 set pages 999&lt;br /&gt;
 col username   format a20&lt;br /&gt;
 col sess_id    format a10&lt;br /&gt;
 col object     format a25&lt;br /&gt;
 col mode_held  format a10&lt;br /&gt;
 select oracle_username||&amp;#039; (&amp;#039;||s.osuser||&amp;#039;)&amp;#039; username&lt;br /&gt;
 ,      s.sid||&amp;#039;,&amp;#039;||s.serial# sess_id&lt;br /&gt;
 ,      owner||&amp;#039;.&amp;#039;||object_name object&lt;br /&gt;
 ,      object_type&lt;br /&gt;
 ,      decode ( l.block&lt;br /&gt;
               , 0, &amp;#039;Not Blocking&amp;#039;&lt;br /&gt;
               , 1, &amp;#039;Blocking&amp;#039;&lt;br /&gt;
               , 2, &amp;#039;Global&amp;#039;&lt;br /&gt;
               ) status&lt;br /&gt;
 ,      decode ( v.locked_mode&lt;br /&gt;
               , 0, &amp;#039;None&amp;#039;&lt;br /&gt;
               , 1, &amp;#039;Null&amp;#039;&lt;br /&gt;
               , 2, &amp;#039;Row-S (SS)&amp;#039;&lt;br /&gt;
               , 3, &amp;#039;Row-X (SX)&amp;#039;&lt;br /&gt;
               , 4, &amp;#039;Share&amp;#039;&lt;br /&gt;
               , 5, &amp;#039;S/Row-X (SSX)&amp;#039;&lt;br /&gt;
               , 6, &amp;#039;Exclusive&amp;#039;, TO_CHAR(lmode)&lt;br /&gt;
               ) mode_held&lt;br /&gt;
 from   v$locked_object v&lt;br /&gt;
 ,      dba_objects d&lt;br /&gt;
 ,      v$lock l&lt;br /&gt;
 ,      v$session s&lt;br /&gt;
 where  1=1&lt;br /&gt;
 and    v.object_id = d.object_id&lt;br /&gt;
 and    v.object_id = l.id1&lt;br /&gt;
 and    v.session_id = s.sid&lt;br /&gt;
 order  by oracle_username&lt;br /&gt;
 ,	session_id;&lt;br /&gt;
&lt;br /&gt;
===Show which row is locked===&lt;br /&gt;
 select do.object_name&lt;br /&gt;
 ,      row_wait_obj#&lt;br /&gt;
 ,      row_wait_file#&lt;br /&gt;
 ,      row_wait_block#&lt;br /&gt;
 ,      row_wait_row#&lt;br /&gt;
 ,      dbms_rowid.rowid_create (1, ROW_WAIT_OBJ#, ROW_WAIT_FILE#, ROW_WAIT_BLOCK#, ROW_WAIT_ROW#)&lt;br /&gt;
 from   v$session   s&lt;br /&gt;
 ,      dba_objects do&lt;br /&gt;
 where  1=1&lt;br /&gt;
 and    s.ROW_WAIT_OBJ# = do.OBJECT_ID&lt;br /&gt;
 and    sid             = &amp;amp;sid;&lt;br /&gt;
&lt;br /&gt;
===Check what is audited on a database===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set pagesize 100&lt;br /&gt;
set linesize 256&lt;br /&gt;
select audit_option,success,failure from dba_stmt_audit_opts;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===How old is the oldest audit record?===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select extract (day from (systimestamp - min(ntimestamp#))) days_old from aud$;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Check what objects are being audited===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
tti col 60 &amp;#039;Object Audit Options (dba_obj_audit_opts)&amp;#039; skip col 50 &amp;#039;A=By Access, S=By Session. Left=on success, right=on failure&amp;#039; skip 2&lt;br /&gt;
set lines 1000 pages 100&lt;br /&gt;
col alt for a3 head &amp;quot;Alt|er&amp;quot;&lt;br /&gt;
col aud for a3 head &amp;quot;Aud|it&amp;quot;&lt;br /&gt;
col com for a3 head &amp;quot;Com|ent&amp;quot;&lt;br /&gt;
col del for a3 head &amp;quot;Del|ete&amp;quot;&lt;br /&gt;
col gra for a3 head &amp;quot;Gra|nt&amp;quot;&lt;br /&gt;
col ind for a3 head &amp;quot;Ind|ex&amp;quot;&lt;br /&gt;
col ins for a3 head &amp;quot;Ins|ert&amp;quot;&lt;br /&gt;
col loc for a3 head &amp;quot;Lo|ck&amp;quot;&lt;br /&gt;
col ren for a3 head &amp;quot;Ren|ame&amp;quot;&lt;br /&gt;
col sel for a3 head &amp;quot;Sel|ect&amp;quot;&lt;br /&gt;
col upd for a3 head &amp;quot;Upd|ate&amp;quot;&lt;br /&gt;
col ref for a3 head &amp;quot;Ref|rnc&amp;quot;&lt;br /&gt;
col exe for a3 head &amp;quot;Exe|cut&amp;quot;&lt;br /&gt;
col cre for a3 head &amp;quot;Cre|ate&amp;quot;&lt;br /&gt;
col rea for a3 head &amp;quot;Re|ad&amp;quot;&lt;br /&gt;
col wri for a3 head &amp;quot;Wri|te&amp;quot;&lt;br /&gt;
col fbk for a3 head &amp;quot;Fla|sh&amp;quot;&lt;br /&gt;
	&lt;br /&gt;
select *&lt;br /&gt;
from   dba_obj_audit_opts&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Procedure to delete old audit records===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select text from all_source where lower(name)=&amp;#039;purge_audit_trail&amp;#039;;&lt;br /&gt;
&lt;br /&gt;
TEXT&lt;br /&gt;
------------------------------------------------------------------------------------------------&lt;br /&gt;
PROCEDURE purge_audit_trail IS&lt;br /&gt;
BEGIN&lt;br /&gt;
-- set the last archive timestamp&lt;br /&gt;
DBMS_AUDIT_MGMT.SET_LAST_ARCHIVE_TIMESTAMP(&lt;br /&gt;
       audit_trail_type    =&amp;gt; DBMS_AUDIT_MGMT.AUDIT_TRAIL_AUD_STD,&lt;br /&gt;
       last_archive_time   =&amp;gt; systimestamp - interval &amp;#039;365&amp;#039; day,&lt;br /&gt;
       rac_instance_number =&amp;gt; null&lt;br /&gt;
                                          );&lt;br /&gt;
-- purge audit trail till last archive timestamp&lt;br /&gt;
DBMS_AUDIT_MGMT.CLEAN_AUDIT_TRAIL( audit_trail_type =&amp;gt; DBMS_AUDIT_MGMT.AUDIT_TRAIL_AUD_STD&lt;br /&gt;
, use_last_arch_timestamp =&amp;gt; TRUE);&lt;br /&gt;
&lt;br /&gt;
END purge_audit_trail;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Job setup to run the audit purge===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
BEGIN&lt;br /&gt;
sys.dbms_scheduler.create_job(&lt;br /&gt;
    job_name =&amp;gt; &amp;#039;&amp;quot;SYS&amp;quot;.&amp;quot;PURGE_AUDIT_TRAIL_JOB&amp;quot;&amp;#039;,&lt;br /&gt;
    job_type =&amp;gt; &amp;#039;STORED_PROCEDURE&amp;#039;,&lt;br /&gt;
    job_action =&amp;gt; &amp;#039;&amp;quot;SYS&amp;quot;.&amp;quot;PURGE_AUDIT_TRAIL&amp;quot;&amp;#039;,&lt;br /&gt;
    repeat_interval =&amp;gt; &amp;#039;FREQ=DAILY;BYHOUR=20;BYMINUTE=0;BYSECOND=0&amp;#039;,&lt;br /&gt;
    start_date =&amp;gt; to_timestamp_tz(&amp;#039;2012-02-22 Europe/Paris&amp;#039;, &amp;#039;YYYY-MM-DD TZR&amp;#039;),&lt;br /&gt;
    job_class =&amp;gt; &amp;#039;&amp;quot;DEFAULT_JOB_CLASS&amp;quot;&amp;#039;,&lt;br /&gt;
    comments =&amp;gt; &amp;#039;purge audit trails until last archive timestamp&amp;#039;,&lt;br /&gt;
    auto_drop =&amp;gt; FALSE,&lt;br /&gt;
    enabled =&amp;gt; FALSE&lt;br /&gt;
);&lt;br /&gt;
sys.dbms_scheduler.set_attribute( name =&amp;gt; &amp;#039;&amp;quot;SYS&amp;quot;.&amp;quot;PURGE_AUDIT_TRAIL_JOB&amp;quot;&amp;#039;, attribute =&amp;gt; &amp;#039;logging_level&amp;#039;, value =&amp;gt; DBMS_SCHEDULER.LOGGING_OFF);&lt;br /&gt;
sys.dbms_scheduler.set_attribute( name =&amp;gt; &amp;#039;&amp;quot;SYS&amp;quot;.&amp;quot;PURGE_AUDIT_TRAIL_JOB&amp;quot;&amp;#039;, attribute =&amp;gt; &amp;#039;job_weight&amp;#039;, value =&amp;gt; 1);&lt;br /&gt;
sys.dbms_scheduler.enable( &amp;#039;&amp;quot;SYS&amp;quot;.&amp;quot;PURGE_AUDIT_TRAIL_JOB&amp;quot;&amp;#039; );&lt;br /&gt;
END;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===A list of all SIDs in oratab that should restart after a server boot===&lt;br /&gt;
Using awk&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
awk -F: &amp;#039;$NF==&amp;quot;Y&amp;quot; &amp;amp;&amp;amp; $1 !~/[#]/ {print $1}&amp;#039;  /etc/oratab&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Using perl&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
perl -F: -ne &amp;#039;print &amp;quot;$1\n&amp;quot; if /(\w+):(.+):Y$/&amp;#039; /etc/oratab&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Move the admin directories to a new location===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
./all_db_do &amp;quot;alter system set audit_file_dest=&amp;#039;/oracle/&amp;amp;SID/admin/adump&amp;#039; scope=spfile;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
./all_db_do &amp;quot;shutdown immediate&amp;quot;&lt;br /&gt;
&lt;br /&gt;
for db in `awk -F: &amp;#039;NF &amp;amp;&amp;amp; $1 !~/[#*]/ {print $1}&amp;#039;  /etc/oratab`&lt;br /&gt;
do&lt;br /&gt;
    echo $db&lt;br /&gt;
    mkdir -p /oracle/${db}/admin&lt;br /&gt;
    echo &amp;quot;/oracle/${db}/admin created&amp;quot;&lt;br /&gt;
    mv /oracle/admin/${db}/adump /oracle/${db}/admin/&lt;br /&gt;
    mv /oracle/admin/${db}/dpdump /oracle/${db}/admin/&lt;br /&gt;
    echo &amp;quot;Moved /oracle/admin/${db}/adump to /oracle/${db}/admin/&amp;quot;&lt;br /&gt;
done&lt;br /&gt;
&lt;br /&gt;
./all_db_do startup&lt;br /&gt;
&lt;br /&gt;
./all_db_do &amp;quot;create pfile from spfile;&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Check if the Standby database is up-to-date with the primary database===&lt;br /&gt;
 select arch.thread# &amp;quot;Thread&amp;quot;&lt;br /&gt;
 ,      arch.sequence# &amp;quot;Last Sequence Received&amp;quot;&lt;br /&gt;
 ,      appl.sequence# &amp;quot;Last Sequence Applied&amp;quot;&lt;br /&gt;
 ,      (arch.sequence# - appl.sequence#) &amp;quot;Difference&amp;quot;&lt;br /&gt;
 from   (&lt;br /&gt;
        select thread#&lt;br /&gt;
        ,      sequence#&lt;br /&gt;
        from   v$archived_log&lt;br /&gt;
        where  1=1&lt;br /&gt;
        and    ( thread#,first_time ) in (&lt;br /&gt;
                                         select thread#, max(first_time)&lt;br /&gt;
                                         from   v$archived_log&lt;br /&gt;
                                         group  by thread#&lt;br /&gt;
                                         )&lt;br /&gt;
        ) arch&lt;br /&gt;
        ,&lt;br /&gt;
        (&lt;br /&gt;
        select thread#&lt;br /&gt;
        ,      sequence#&lt;br /&gt;
        from   v$log_history&lt;br /&gt;
        where  1=1&lt;br /&gt;
        and    ( thread#,first_time ) in ( select thread# ,max(first_time)&lt;br /&gt;
                                           from   v$log_history&lt;br /&gt;
                                           group  by thread#&lt;br /&gt;
                                          )&lt;br /&gt;
        ) appl&lt;br /&gt;
 where  1=1&lt;br /&gt;
 and    arch.thread# = appl.thread#&lt;br /&gt;
 order  by 1;&lt;br /&gt;
&lt;br /&gt;
===Check for gaps on the Standby database===&lt;br /&gt;
Run this on the standby&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select thread#, low_sequence#, high_sequence# from v$archive_gap;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or run this on the Primary to see the latest generated archive...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select thread#   &amp;quot;Thread&amp;quot;&lt;br /&gt;
,      sequence# &amp;quot;Last sequence generated&amp;quot;&lt;br /&gt;
from   v$archived_log&lt;br /&gt;
where  (thread#, first_time) in ( select thread#, max(first_time)&lt;br /&gt;
                                  from   v$archived_log&lt;br /&gt;
                                  group  by thread#&lt;br /&gt;
                                )&lt;br /&gt;
order  by 1&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
and run this on the standby to check for received but not yet applied logs (this could be normal if a lag has been set)...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select arch.thread# &amp;quot;Thread&amp;quot;&lt;br /&gt;
,      arch.sequence# &amp;quot;Last sequence received&amp;quot;&lt;br /&gt;
,      appl.sequence# &amp;quot;Last sequence applied&amp;quot;&lt;br /&gt;
,      (arch.sequence#-appl.sequence#) &amp;quot;Difference&amp;quot;&lt;br /&gt;
from   (&lt;br /&gt;
       select thread#&lt;br /&gt;
       ,      sequence#&lt;br /&gt;
       from   v$archived_log&lt;br /&gt;
       where  (thread#,first_time ) in (select thread#, max(first_time)&lt;br /&gt;
                                        from   v$archived_log&lt;br /&gt;
                                        group  by thread#&lt;br /&gt;
                                       )&lt;br /&gt;
       ) arch&lt;br /&gt;
,      (&lt;br /&gt;
       select thread#&lt;br /&gt;
       ,      sequence#&lt;br /&gt;
       from   v$log_history&lt;br /&gt;
       where  (thread#,first_time ) in (select thread#, max(first_time)&lt;br /&gt;
                                        from   v$log_history&lt;br /&gt;
                                        group  by thread#&lt;br /&gt;
                                       )&lt;br /&gt;
      ) appl&lt;br /&gt;
where arch.thread# = appl.thread#&lt;br /&gt;
order by 1&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Compare the results from Primary and Secondary to detect possible network problems or other errors in shipping.&lt;br /&gt;
&lt;br /&gt;
===Ignore case-sensitive passwords in 11g (deprecated in 12c)===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter system set SEC_CASE_SENSITIVE_LOGON = false scope=both&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===External table for the Alert log (pre 11g)===&lt;br /&gt;
Modified to use (the better) scripts found on [http://www.adp-gmbh.ch/ora/admin/scripts/read_alert_log.html Rene Nyffenegger&amp;#039;s site]&amp;lt;br /&amp;gt;&lt;br /&gt;
This script generates the required DDL for the alertlog table&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Alert log (11g+)===&lt;br /&gt;
This reads the log.xml file (which contains the same information as alert.log)&amp;lt;br /&amp;gt;&lt;br /&gt;
Show the messages put in the alert log in the last 24 hours&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select substr(MESSAGE_TEXT, 1, 300) message_text&lt;br /&gt;
,      count(*) cnt&lt;br /&gt;
from   X$DBGALERTEXT&lt;br /&gt;
where  1=1&lt;br /&gt;
and    (MESSAGE_TEXT like &amp;#039;%ORA-%&amp;#039; or upper(MESSAGE_TEXT) like &amp;#039;%ERROR%&amp;#039;)&lt;br /&gt;
and    cast(ORIGINATING_TIMESTAMP as DATE) &amp;gt; sysdate - &amp;amp;days_ago/1440&lt;br /&gt;
group  by substr(MESSAGE_TEXT, 1, 300)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
There is also a fixed table X$DBGDIREXT which returns all file and directory names under [diagnostic_dest]/diag directory:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select lpad(&amp;#039; &amp;#039;,lvl,&amp;#039; &amp;#039;)||logical_file file_name&lt;br /&gt;
from   x$dbgdirext&lt;br /&gt;
where  rownum &amp;lt;=20;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Directory paths available in v$diag_info===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 2000&lt;br /&gt;
col name for a35&lt;br /&gt;
col value for a100 wrap&lt;br /&gt;
select * from v$diag_info;&lt;br /&gt;
&lt;br /&gt;
   INST_ID NAME                                VALUE                                                                                                    CON_ID&lt;br /&gt;
---------- ----------------------------------- ---------------------------------------------------------------------------------------------------- ----------&lt;br /&gt;
         1 Diag Enabled                        TRUE                                                                                                          0&lt;br /&gt;
         1 ADR Base                            /cln/prg/ora_bin2/app/oracle                                                                               0&lt;br /&gt;
         1 ADR Home                            /cln/prg/ora_bin2/app/oracle/diag/rdbms/bild/bild                                                          0&lt;br /&gt;
         1 Diag Trace                          /cln/prg/ora_bin2/app/oracle/diag/rdbms/bild/bild/trace                                                    0&lt;br /&gt;
         1 Diag Alert                          /cln/prg/ora_bin2/app/oracle/diag/rdbms/bild/bild/alert                                                    0&lt;br /&gt;
         1 Diag Incident                       /cln/prg/ora_bin2/app/oracle/diag/rdbms/bild/bild/incident                                                 0&lt;br /&gt;
         1 Diag Cdump                          /cln/prg/ora_bin2/app/oracle/diag/rdbms/bild/bild/cdump                                                    0&lt;br /&gt;
         1 Health Monitor                      /cln/prg/ora_bin2/app/oracle/diag/rdbms/bild/bild/hm                                                       0&lt;br /&gt;
         1 Default Trace File                  /cln/prg/ora_bin2/app/oracle/diag/rdbms/bild/bild/trace/bild_ora_44696768.trc                              0&lt;br /&gt;
         1 Active Problem Count                0                                                                                                             0&lt;br /&gt;
         1 Active Incident Count               0                                                                                                             0&lt;br /&gt;
&lt;br /&gt;
11 rows selected.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Find out the names of the active trace files for the running processes===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select pid, program, tracefile from v$process;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Request was to duplicate a large tablespace from production to test environment===&lt;br /&gt;
...but rather than copy the terabytes of data, create the destination tablespace with just the most recent months data&amp;lt;br /&amp;gt;&lt;br /&gt;
====See what the source data looks like====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
col table_owner    for a20&lt;br /&gt;
col table_name     for a30&lt;br /&gt;
col partition_name for a20&lt;br /&gt;
set pages 100 lines 1000&lt;br /&gt;
&lt;br /&gt;
select table_owner&lt;br /&gt;
,      table_name&lt;br /&gt;
,      partition_name&lt;br /&gt;
,      partition_position&lt;br /&gt;
,      tablespace_name&lt;br /&gt;
from   dba_tab_partitions&lt;br /&gt;
where  tablespace_name = &amp;#039;ADS_ARCHIVE&amp;#039;&lt;br /&gt;
order  by 1,2,3,4&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This query produces something like this...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
TABLE_OWNER          TABLE_NAME                     PARTITION_NAME       PARTITION_POSITION TABLESPACE_NAME                &lt;br /&gt;
-------------------- ------------------------------ -------------------- ------------------ ------------------------------ &lt;br /&gt;
ADS_ARCHIVE          BIL_DAY_INV_CTR_ARC            Y2017_Q1_M01_D01                      1 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          BIL_HIS_DETAIL_FAC_ARC         Y2016_Q2_M05_D04                      1 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          BIL_HIS_DETAIL_FAC_ARC         Y2016_Q2_M05_D09                      2 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          BIL_MTH_INV_CTR_ARC            Y2017_Q1_M01_D01                      1 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          FAH_DAY_CBA_BGAAP_ARC          Y2011_Q4_M12_D30                      1 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          FAH_DAY_CBA_BGAAP_ARC          Y2011_Q4_M12_D31                      2 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          FAH_DAY_CBA_IFRS_ARC           Y2011_Q4_M12_D30                      1 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          FAH_DAY_CBA_IFRS_ARC           Y2011_Q4_M12_D31                      2 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          FAH_DAY_MVT_BGAAP_ARC          Y2011_Q4_M12_D30                      1 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          FAH_DAY_MVT_BGAAP_ARC          Y2011_Q4_M12_D31                      2 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          FAH_DAY_MVT_BGAAP_ARC          Y2012_Q1_M03_D31                      3 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          FAH_DAY_MVT_BGAAP_ARC          Y2012_Q2_M04_D01                      4 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          FAH_DAY_MVT_BGAAP_ARC          Y2012_Q4_M10_D12                      5 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          FAH_DAY_MVT_BGAAP_ARC          Y2012_Q4_M10_D13                      6 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          FAH_DAY_MVT_BGAAP_ARC          Y2012_Q4_M10_D14                      7 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          FAH_DAY_MVT_BGAAP_ARC_TST      Y2011_Q4_M12_D30                      1 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          FAH_DAY_MVT_BGAAP_ARC_TST      Y2011_Q4_M12_D31                      2 ADS_ARCHIVE&lt;br /&gt;
...&lt;br /&gt;
ADS_ARCHIVE          SBP_HIS_LINES_ARC              P_LS                                  3 ADS_ARCHIVE                  &lt;br /&gt;
ADS_ARCHIVE          THA_DAY_INV_CTR_ARC            Y2011_Q4_M12_D30                      1 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          THA_DAY_INV_CTR_ARC            Y2011_Q4_M12_D31                      2 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          THA_INV_HEAVY_ARC              Y2011_Q4_M12_D30                      1 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          THA_INV_HEAVY_ARC              Y2011_Q4_M12_D31                      2 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          THA_INV_LIGHT_ARC              Y2011_Q4_M12_D30                      1 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          THA_INV_LIGHT_ARC              Y2012_Q4_M10_D12                      2 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          THA_INV_LIGHT_ARC              Y2012_Q4_M10_D13                      3 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          THA_INV_LIGHT_ARC              Y2012_Q4_M10_D15                      4 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          THA_INV_LIGHT_ARC              Y2012_Q4_M10_D16                      5 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          THA_INV_LIGHT_ARC              Y2012_Q4_M10_D17                      6 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          THA_INV_LIGHT_ARC              Y2012_Q4_M10_D18                      7 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          THA_INV_LIGHT_ARC              Y2012_Q4_M10_D19                      8 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          THA_INV_LIGHT_ARC              Y2012_Q4_M10_D20                      9 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          THA_INV_LIGHT_ARC              Y2012_Q4_M10_D21                     10 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          THA_INV_LIGHT_ARC              Y2012_Q4_M10_D22                     11 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          THA_INV_LIGHT_ARC              Y2012_Q4_M10_D23                     12 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          THA_INV_LIGHT_ARC              Y2012_Q4_M10_D24                     13 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          THA_MTH_INV_CTR_ARC            Y2011_Q4_M12_D30                      1 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          THA_MTH_INV_CTR_ARC            Y2011_Q4_M12_D31                      2 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          THA_MTH_INV_CTR_ARC            Y2013_Q2_M04_D30                      3 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          XBD01_TEMP_HIS_ARC             Y2012_Q4_M12_D31                      1 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          T_RPT_RECO_THA_INV_ACC_ARC     Y2011_Q4_M12_D30                      1 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          T_RPT_RECO_THA_INV_ACC_ARC     Y2011_Q4_M12_D31                      2 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          T_RPT_RECO_THA_INV_MTH_ARC     Y2011_Q4_M12_D30                      1 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          T_RPT_RECO_THA_INV_MTH_ARC     Y2011_Q4_M12_D31                      2 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          XBD01_TEMP_HIS_ARC             Y2012_Q4_M12_D31                      1 ADS_ARCHIVE&lt;br /&gt;
ADS_DBA              FAH_DAY_CBA_BGAAP              Y2016_Q3_M07_D12                   1657 ADS_ARCHIVE&lt;br /&gt;
ADS_DBA              FAH_DAY_CBA_BGAAP              Y2016_Q4_M12_D13                   1811 ADS_ARCHIVE&lt;br /&gt;
ADS_DBA              FAH_DAY_MVT_IFRS               Y2016_Q4_M10_D10                   1654 ADS_ARCHIVE&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Capture the tablespace metadata====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set long 1000000&lt;br /&gt;
select dbms_metadata.get_ddl ( &amp;#039;TABLESPACE&amp;#039;, &amp;#039;ADS_ARCHIVE&amp;#039;) from dual&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
produces...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
CREATE TABLESPACE &amp;quot;ADS_ARCHIVE&amp;quot; DATAFILE&lt;br /&gt;
  &amp;#039;/oracle/tst/ora_data3/adst/ads_archive01.dbf&amp;#039; SIZE 104857600&lt;br /&gt;
  AUTOEXTEND ON NEXT 104857600 MAXSIZE 32000M,&lt;br /&gt;
...&lt;br /&gt;
  &amp;#039;/oracle/tst/ora_data3/adst/ads_archive66.dbf&amp;#039; SIZE 104857600&lt;br /&gt;
  AUTOEXTEND ON NEXT 104857600 MAXSIZE 3200M,&lt;br /&gt;
  LOGGING ONLINE PERMANENT BLOCKSIZE 8192&lt;br /&gt;
  EXTENT MANAGEMENT LOCAL AUTOALLOCATE DEFAULT&lt;br /&gt;
 NOCOMPRESS  SEGMENT SPACE MANAGEMENT AUTO&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Capture the tablespace objects&amp;#039; metadata====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cat&amp;lt;&amp;lt;EOCAT &amp;gt;expdp_adst_ads_archive_metadata.par&lt;br /&gt;
userid=&amp;#039;/ as sysdba&amp;#039;&lt;br /&gt;
dumpfile=adst_ads_archive_metadata.dmp&lt;br /&gt;
logfile=expdp_adst_ads_archive_metadata.log&lt;br /&gt;
tablespaces=ADS_ARCHIVE&lt;br /&gt;
parallel=20&lt;br /&gt;
content=metadata_only&lt;br /&gt;
exclude=statistics&lt;br /&gt;
EOCAT&lt;br /&gt;
&lt;br /&gt;
expdp parfile=expdp_adst_ads_archive_metadata.par&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Find the partitions with data from the most recent month====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cat &amp;lt;&amp;lt;EOCAT&amp;gt;/tmp/adst_ads_archive_partitions.sql&lt;br /&gt;
set termo off echo off lines 1000 feedb off headi off newpa none trims on&lt;br /&gt;
spool /tmp/adst_ads_archive_partitions.lst&lt;br /&gt;
select table_owner||&amp;#039;.&amp;#039;||table_name||&amp;#039;:&amp;#039;||partition_name&lt;br /&gt;
from   dba_tab_partitions&lt;br /&gt;
where  tablespace_name = &amp;#039;ADS_ARCHIVE&amp;#039;&lt;br /&gt;
and    partition_name like &amp;#039;Y2017_Q1_M01%&amp;#039;&lt;br /&gt;
/&lt;br /&gt;
spool off&lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;@/tmp/adst_ads_archive_partitions.sql&amp;quot; | sqlplus / as sysdba&lt;br /&gt;
EOCAT&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
produces...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_CBA_BGAAP_ARC:Y2017_Q1_M01_D07&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_IFRS_ARC:Y2017_Q1_M02_D26&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_IFRS_ARC:Y2017_Q1_M02_D25&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_IFRS_ARC:Y2017_Q1_M02_D19&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_IFRS_ARC:Y2017_Q1_M02_D18&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_IFRS_ARC:Y2017_Q1_M02_D12&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_IFRS_ARC:Y2017_Q1_M02_D11&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_IFRS_ARC:Y2017_Q1_M02_D05&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_BGAAP_ARC:Y2017_Q1_M02_D26&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_BGAAP_ARC:Y2017_Q1_M02_D25&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_BGAAP_ARC:Y2017_Q1_M02_D19&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_BGAAP_ARC:Y2017_Q1_M02_D18&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_BGAAP_ARC:Y2017_Q1_M02_D12&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_BGAAP_ARC:Y2017_Q1_M02_D11&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_BGAAP_ARC:Y2017_Q1_M02_D05&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_BGAAP_ARC:Y2017_Q1_M02_D04&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_BGAAP_ARC:Y2017_Q1_M01_D29&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_BGAAP_ARC:Y2017_Q1_M01_D28&lt;br /&gt;
...&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_BGAAP_ARC:Y2017_Q1_M01_D22&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_BGAAP_ARC:Y2017_Q1_M01_D21&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_BGAAP_ARC:Y2017_Q1_M01_D15&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_BGAAP_ARC:Y2017_Q1_M01_D14&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_BGAAP_ARC:Y2017_Q1_M01_D08&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_BGAAP_ARC:Y2017_Q1_M01_D07&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_BGAAP_ARC:Y2017_Q1_M01_D01&lt;br /&gt;
ADS_ARCHIVE.BIL_MTH_INV_CTR_ARC:Y2017_Q1_M01_D01&lt;br /&gt;
ADS_ARCHIVE.BIL_DAY_INV_CTR_ARC:Y2017_Q1_M01_D01&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_IFRS_ARC:Y2017_Q1_M02_D04&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_IFRS_ARC:Y2017_Q1_M01_D29&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_IFRS_ARC:Y2017_Q1_M01_D28&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_IFRS_ARC:Y2017_Q1_M01_D22&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Export the data in these partitions====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cat&amp;lt;&amp;lt;EOCAT &amp;gt;expdp_adst_ads_archive_partitions.par&lt;br /&gt;
userid=&amp;#039;/ as sysdba&amp;#039;&lt;br /&gt;
dumpfile=adst_ads_archive_Y2017_%U.dmp&lt;br /&gt;
logfile=expdp_adst_ads_archive_Y2017.log&lt;br /&gt;
EOCAT&lt;br /&gt;
&lt;br /&gt;
cat /tmp/adst_ads_archive_partitions.lst | perl -p -i -e &amp;#039;s/^/tables=/&amp;#039;g &amp;gt;&amp;gt;expdp_adst_ads_archive_partitions.par&lt;br /&gt;
&lt;br /&gt;
cat&amp;lt;&amp;lt;EOCAT &amp;gt;&amp;gt;expdp_adst_ads_archive_partitions.par&lt;br /&gt;
parallel=20&lt;br /&gt;
exclude=statistics&lt;br /&gt;
EOCAT&lt;br /&gt;
&lt;br /&gt;
expdp parfile=expdp_adst_ads_archive_partitions.par&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Drop the old tablespace====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
drop tablespace ads_archive including contents and datafiles&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Recreate the tablepspace using the metadata capture above====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
create tablespace &amp;quot;ADS_ARCHIVE&amp;quot;&lt;br /&gt;
datafile &amp;#039;/oracle/tst/ora_data3/adst/ads_archive01.dbf&amp;#039; size 100M autoextend on next 50M maxsize unlimited&lt;br /&gt;
,        &amp;#039;/oracle/tst/ora_data3/adst/ads_archive02.dbf&amp;#039; size 100M autoextend on next 50M maxsize unlimited&lt;br /&gt;
,        &amp;#039;/oracle/tst/ora_data3/adst/ads_archive03.dbf&amp;#039; size 100M autoextend on next 50M maxsize unlimited&lt;br /&gt;
,        &amp;#039;/oracle/tst/ora_data3/adst/ads_archive04.dbf&amp;#039; size 100M autoextend on next 50M maxsize unlimited&lt;br /&gt;
,        &amp;#039;/oracle/tst/ora_data3/adst/ads_archive05.dbf&amp;#039; size 100M autoextend on next 50M maxsize unlimited&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Import the tablespace metadata====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cat&amp;lt;&amp;lt;EOCAT &amp;gt;impdp_adst_ads_archive_metadata.par&lt;br /&gt;
userid=&amp;#039;/ as sysdba&amp;#039;&lt;br /&gt;
dumpfile=adst_ads_archive_metadata.dmp&lt;br /&gt;
logfile=impdp_adst_ads_archive_metadata.log&lt;br /&gt;
EOCAT&lt;br /&gt;
&lt;br /&gt;
impdp parfile=impdp_adst_ads_archive_metadata.par&lt;br /&gt;
&lt;br /&gt;
select &amp;#039;alter index &amp;#039;|| owner||&amp;#039;.&amp;#039;||index_name||&amp;#039; rebuild online parallel 8;&amp;#039;&lt;br /&gt;
from   dba_indexes&lt;br /&gt;
where  status = &amp;#039;UNUSABLE&amp;#039;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Import the last month partition data====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cat&amp;lt;&amp;lt;EOCAT &amp;gt;impdp_adst_ads_archive_partitions.par&lt;br /&gt;
userid=&amp;#039;/ as sysdba&amp;#039;&lt;br /&gt;
dumpfile=adst_ads_archive_Y2017_%U.dmp&lt;br /&gt;
logfile=impdp_adst_ads_archive_Y2017.log&lt;br /&gt;
table_exists_action=append&lt;br /&gt;
parallel=20&lt;br /&gt;
EOCAT&lt;br /&gt;
&lt;br /&gt;
impdp parfile=impdp_adst_ads_archive_partitions.par&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Write to a TCP/IP socket from PL/SQL===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
declare&lt;br /&gt;
 bt_conn               utl_tcp.connection;&lt;br /&gt;
 retval                binary_integer;&lt;br /&gt;
 l_sequence            varchar2(30) := &amp;#039;Sequence Number 101021&amp;#039;;&lt;br /&gt;
begin&lt;br /&gt;
 bt_conn := utl_tcp.open_connection(remote_host =&amp;gt; &amp;#039;10.10.1.1&amp;#039;&lt;br /&gt;
                                   ,remote_port =&amp;gt; 5000&lt;br /&gt;
                                   ,tx_timeout =&amp;gt; 1&lt;br /&gt;
                                   )&lt;br /&gt;
 ;&lt;br /&gt;
 retval := utl_tcp.write_line(bt_conn,l_sequence)&lt;br /&gt;
 ;&lt;br /&gt;
 utl_tcp.flush(bt_conn)&lt;br /&gt;
 ;&lt;br /&gt;
 utl_tcp.close_connection(bt_conn)&lt;br /&gt;
 ;&lt;br /&gt;
exception&lt;br /&gt;
 when others then&lt;br /&gt;
  raise_application_error(-20101, sqlerrm)&lt;br /&gt;
  ; &lt;br /&gt;
  utl_tcp.close_connection(bt_conn)&lt;br /&gt;
  ;&lt;br /&gt;
end&lt;br /&gt;
;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
and read from it using netcat in another session&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
nc -lk 5000&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
produces&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Sequence Number 101021&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Execute a script as a different user===&lt;br /&gt;
Some things have to be done as the user and cannot be done as sys (eg. creating and dropping jobs or create and drop a database link)&amp;lt;br /&amp;gt;&lt;br /&gt;
It is possible to login as the user by saving, changing and resetting his password (using identified by values) but using dbms_sys_sql is another option&amp;lt;br /&amp;gt;&lt;br /&gt;
Create a PL/SQL procedure to drop a db link&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
create or replace procedure drop_dblink ( p_schema_name in varchar2&lt;br /&gt;
                                        , p_dblink      in varchar2&lt;br /&gt;
                                        ) is&lt;br /&gt;
    l_plsql   varchar2(1000);&lt;br /&gt;
    l_cur     number;&lt;br /&gt;
    l_uid     number;&lt;br /&gt;
    l_rc      number;&lt;br /&gt;
begin&lt;br /&gt;
    select  du.user_id&lt;br /&gt;
    into    l_uid&lt;br /&gt;
    from    dba_users du&lt;br /&gt;
    where   du.username = p_schema_name&lt;br /&gt;
    ;&lt;br /&gt;
    plsql := &amp;#039;drop database link &amp;quot;&amp;#039;||p_dblink||&amp;#039;&amp;quot;&amp;#039;;&lt;br /&gt;
    l_cur := sys.dbms_sys_sql.open_cursor;&lt;br /&gt;
    sys.dbms_sys_sql.parse_as_user(&lt;br /&gt;
        c             =&amp;gt; l_cur,&lt;br /&gt;
        statement     =&amp;gt; l_plsql,&lt;br /&gt;
        language_flag =&amp;gt; dbms_sql.native,&lt;br /&gt;
        userid        =&amp;gt; l_uid&lt;br /&gt;
    );&lt;br /&gt;
    l_rc := sys.dbms_sys_sql.execute(l_cur);&lt;br /&gt;
    sys.dbms_sys_sql.close_cursor(l_cur);&lt;br /&gt;
end;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Generate the calls to the procedure with the required parameters&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select &amp;#039;exec drop_dblink (&amp;#039;&amp;#039;&amp;#039;|| owner ||&amp;#039;&amp;#039;&amp;#039;&amp;#039;||&amp;#039;, &amp;#039;||&amp;#039;&amp;#039;&amp;#039;&amp;#039;||db_link||&amp;#039;&amp;#039;&amp;#039;&amp;#039;||&amp;#039;);&amp;#039;&lt;br /&gt;
from   dba_db_links&lt;br /&gt;
where  owner   != &amp;#039;PUBLIC&amp;#039;&lt;br /&gt;
and    db_link like &amp;#039;%FTST%&amp;#039;&lt;br /&gt;
or     db_link like &amp;#039;%HDEV%&amp;#039;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
and this reveals the lines to be executed&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
exec drop_dblink (&amp;#039;USER1&amp;#039;, &amp;#039;DBL_FTST.WORLD&amp;#039;);&lt;br /&gt;
exec drop_dblink (&amp;#039;USER1&amp;#039;, &amp;#039;DBL_HDEV.WORLD&amp;#039;);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Drop the procedure when finished with it&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
drop procedure drop_dblink;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
or do it as an anonymous block in one go...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
declare&lt;br /&gt;
    uid number;&lt;br /&gt;
    sqltext varchar2(1000) := &amp;#039;drop database link &amp;quot;&amp;amp;DB_LINK&amp;quot;&amp;#039;;&lt;br /&gt;
    myint integer;&lt;br /&gt;
begin&lt;br /&gt;
    select user_id into uid from dba_users where username = &amp;#039;&amp;amp;USERNAME&amp;#039;;&lt;br /&gt;
    myint:=sys.dbms_sys_sql.open_cursor();&lt;br /&gt;
    sys.dbms_sys_sql.parse_as_user(myint,sqltext,dbms_sql.native,UID);&lt;br /&gt;
    sys.dbms_sys_sql.close_cursor(myint);&lt;br /&gt;
end;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Handling single quote marks inside SQL statements===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SQL&amp;gt; SELECT &amp;#039;D&amp;#039;&amp;#039;COSTA&amp;#039; name FROM DUAL;&lt;br /&gt;
&lt;br /&gt;
NAME&lt;br /&gt;
-------&lt;br /&gt;
D&amp;#039;COSTA&lt;br /&gt;
&lt;br /&gt;
Alternatively, use the 10g+ quoting method:&lt;br /&gt;
&lt;br /&gt;
SQL&amp;gt; SELECT q&amp;#039;$D&amp;#039;COSTA$&amp;#039; NAME FROM DUAL;&lt;br /&gt;
&lt;br /&gt;
NAME&lt;br /&gt;
-------&lt;br /&gt;
D&amp;#039;COSTA&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Run a script on all databases in /etc/oratab===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
export ORAENV_ASK=NO&lt;br /&gt;
for db in `awk -F: &amp;#039;NF &amp;amp;&amp;amp; $1 !~/[#*]/ {print $1}&amp;#039;  /etc/oratab`&lt;br /&gt;
do&lt;br /&gt;
    echo $db&lt;br /&gt;
    ORACLE_SID=$db&lt;br /&gt;
    . oraenv&lt;br /&gt;
    sqlplus -V&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Schedule a cron job to run on the last day of each month===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
0 23 28-31 * * [ $(date -d +1day +%d) -eq 1 ] &amp;amp;&amp;amp; su - oracle -c &amp;quot;dsmc  arch -server=SO_U_`hostname`_ORX_M_SOL &amp;#039;/oracle/export/PV6/expdp_PV6_D_FULL_`date +\%Y\%m\%d`*&amp;#039;&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===How to tell if a year is a leap year or not - using cal instead of reinventing the wheel===&lt;br /&gt;
Test: Why is Julian day 0, 17th November 1858?&amp;lt;br /&amp;gt;&lt;br /&gt;
Pretty comprehensive answer: [http://h71000.www7.hp.com/wizard/wiz_2315.html here] and [http://mentalfloss.com/article/51370/why-our-calendars-skipped-11-days-1752 here]&amp;lt;br /&amp;gt;&lt;br /&gt;
Also attempts to answer the question why typing &amp;#039;cal 09 1752&amp;#039; on Unix systems looks so odd!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
function leap {&lt;br /&gt;
#  This function tells you if the year passed in as a parameter is a leap year or not...&lt;br /&gt;
if [[ $(cal 2 ${1:-$(date &amp;#039;+%Y&amp;#039;)} | egrep &amp;#039;\&amp;lt;[[:digit:]]{1,2}\&amp;gt;&amp;#039; | wc -w) -eq 29 ]]; then&lt;br /&gt;
    leap=&amp;#039;Y&amp;#039;&lt;br /&gt;
else&lt;br /&gt;
    leap=&amp;#039;N&amp;#039;&lt;br /&gt;
fi&lt;br /&gt;
echo ${leap}&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Reset an expired (and/or locked) user password to the same value===&lt;br /&gt;
Can be used to save user passwords for example in a test environment before destroying them with a copy of production.&amp;lt;br /&amp;gt;&lt;br /&gt;
Simple, quick and easy version. Run this then pick and choose the statements you want to run.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 200 pages 200&lt;br /&gt;
col user_list for a200 head &amp;quot;Expired User List&amp;quot;&lt;br /&gt;
&lt;br /&gt;
select &amp;#039;alter user &amp;#039; ||su.name||&amp;#039; identified by values&amp;#039;||&amp;#039;&amp;#039;&amp;#039;&amp;#039;||spare4||&amp;#039;;&amp;#039;||su.password||&amp;#039;&amp;#039;&amp;#039; account unlock;&amp;#039; user_list&lt;br /&gt;
from   sys.user$ su&lt;br /&gt;
,      dba_users du&lt;br /&gt;
where  1=1&lt;br /&gt;
and    su.name              = du.username&lt;br /&gt;
and    du.oracle_maintained = &amp;#039;N&amp;#039;&lt;br /&gt;
and    (account_status      like &amp;#039;EXPIRED%&amp;#039; or account_status like &amp;#039;%LOCKED&amp;#039;)&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
More industrialised version. Create a package.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
create or replace package dba_utils&lt;br /&gt;
as&lt;br /&gt;
    procedure reset_password ( p_userlist in varchar2 );&lt;br /&gt;
end dba_utils;&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
create or replace package body dba_utils&lt;br /&gt;
as&lt;br /&gt;
&lt;br /&gt;
procedure reset_password ( p_userlist in varchar2 )&lt;br /&gt;
is&lt;br /&gt;
    cursor c1 ( p_userlist in varchar2 ) is&lt;br /&gt;
    select username&lt;br /&gt;
    ,      regexp_substr ( dbms_metadata.get_ddl(&amp;#039;USER&amp;#039;, username), &amp;#039;&amp;#039;&amp;#039;[^&amp;#039;&amp;#039;]+&amp;#039;&amp;#039;&amp;#039; ) pwd&lt;br /&gt;
    from   dba_users&lt;br /&gt;
    where  1=1&lt;br /&gt;
    and    username in upper( p_userlist )&lt;br /&gt;
    ;&lt;br /&gt;
begin&lt;br /&gt;
    dbms_output.enable(null);&lt;br /&gt;
    for r1 in c1 ( p_userlist )&lt;br /&gt;
    loop&lt;br /&gt;
        begin&lt;br /&gt;
            execute immediate &amp;#039;alter user &amp;#039; || r1.username || &amp;#039; account unlock&amp;#039;;&lt;br /&gt;
            execute immediate &amp;#039;alter user &amp;#039; || r1.username || &amp;#039; identified by values &amp;#039; || r1.pwd;&lt;br /&gt;
        exception&lt;br /&gt;
        when others then&lt;br /&gt;
            dbms_output.put_line(&amp;#039;Unable to modify user &amp;#039; || r1.username);&lt;br /&gt;
        end;&lt;br /&gt;
    end loop;&lt;br /&gt;
end reset_password;&lt;br /&gt;
&lt;br /&gt;
end dba_utils;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Call it&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set serveroutput on&lt;br /&gt;
exec dba_utils.reset_password (&amp;#039;STUART&amp;#039;);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Latch, mutex and beyond===&lt;br /&gt;
A fine example of how to write scripts from SQL*Plus that interact with the shell underneath&amp;lt;br /&amp;gt;&lt;br /&gt;
Found [https://andreynikolaev.wordpress.com/demonstration-scripts/cursor_pin_s_contention-sql/ here at andreynikolaev.wordpress.com]&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/*&lt;br /&gt;
     This file is part of demos for &amp;quot;Mutex Internals&amp;quot;  seminar v.04.04.2011&lt;br /&gt;
     Andrey S. Nikolaev (Andrey.Nikolaev@rdtex.ru) &lt;br /&gt;
     https://andreynikolaev.wordpress.com &lt;br /&gt;
 &lt;br /&gt;
     &amp;quot;Cursor: pin S&amp;quot; contention testcase.&lt;br /&gt;
 &lt;br /&gt;
     The script spawn several sessions to induce &amp;quot;Cursor: pin S&amp;quot;, &lt;br /&gt;
     creates AWR snapshots and generates AWR report&lt;br /&gt;
 &lt;br /&gt;
     Beware: The script will restart the test database.&lt;br /&gt;
 &lt;br /&gt;
     usage: sqlplus /nolog @cursor_pin_s_contention.sql &amp;lt;parallelism&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
*/ &lt;br /&gt;
connect / as sysdba&lt;br /&gt;
startup force&lt;br /&gt;
set echo off&lt;br /&gt;
set define %&lt;br /&gt;
set verify off&lt;br /&gt;
set head off&lt;br /&gt;
set linesize 300&lt;br /&gt;
 &lt;br /&gt;
/* spawn parallel processes to create load on mutex */&lt;br /&gt;
spool one_thread.tmp&lt;br /&gt;
select &amp;#039;set verify off&amp;#039; from dual;&lt;br /&gt;
select &amp;#039;alter session set session_cached_cursors = 50;&amp;#039; from dual; &lt;br /&gt;
select &amp;#039;begin for i in 1..1000000 loop&amp;#039; from dual;&lt;br /&gt;
select &amp;#039;      execute immediate &amp;#039;&amp;#039;select 1 from dual where 1=2&amp;#039;&amp;#039;;&amp;#039; from dual;&lt;br /&gt;
select &amp;#039;end loop; end;&amp;#039;||chr(10)||&amp;#039;/&amp;#039; from dual;&lt;br /&gt;
spool off&lt;br /&gt;
 &lt;br /&gt;
/* sleep while AWR initialized */&lt;br /&gt;
host sleep 5&lt;br /&gt;
 &lt;br /&gt;
exec dbms_workload_repository.create_snapshot();&lt;br /&gt;
 &lt;br /&gt;
spool many_threads.tmp&lt;br /&gt;
select &amp;#039;host sqlplus &amp;quot;/ as sysdba&amp;quot; @one_thread.tmp &amp;amp;&amp;#039;&lt;br /&gt;
from dba_objects where rownum &amp;lt;= %1;&lt;br /&gt;
spool off&lt;br /&gt;
 &lt;br /&gt;
@many_threads.tmp&lt;br /&gt;
host sleep 50&lt;br /&gt;
set echo on&lt;br /&gt;
exec dbms_workload_repository.create_snapshot();&lt;br /&gt;
set markup html on&lt;br /&gt;
set head on&lt;br /&gt;
spool mutex_sleep_history.htm&lt;br /&gt;
select to_char(SLEEP_TIMESTAMP,&amp;#039;hh:mi:ss.ff&amp;#039;) SLEEP_TIMESTAMP,MUTEX_ADDR,MUTEX_IDENTIFIER,MUTEX_TYPE,&lt;br /&gt;
       GETS,SLEEPS,REQUESTING_SESSION,BLOCKING_SESSION,&lt;br /&gt;
       LOCATION,MUTEX_VALUE from x$mutex_sleep_history order by sleep_timestamp;&lt;br /&gt;
spool off&lt;br /&gt;
 &lt;br /&gt;
set define &amp;amp;&lt;br /&gt;
set markup html off&lt;br /&gt;
set echo off heading on underline on;&lt;br /&gt;
column inst_num  heading &amp;quot;Inst Num&amp;quot;  new_value inst_num  format 99999;&lt;br /&gt;
column inst_name heading &amp;quot;Instance&amp;quot;  new_value inst_name format a12;&lt;br /&gt;
column db_name   heading &amp;quot;DB Name&amp;quot;   new_value db_name   format a12;&lt;br /&gt;
column dbid      heading &amp;quot;DB Id&amp;quot;     new_value dbid      format 9999999999 just c;&lt;br /&gt;
select d.dbid            dbid&lt;br /&gt;
     , d.name            db_name&lt;br /&gt;
     , i.instance_number inst_num&lt;br /&gt;
     , i.instance_name   inst_name&lt;br /&gt;
  from v$database d,&lt;br /&gt;
       v$instance i;&lt;br /&gt;
define num_days=1;&lt;br /&gt;
define report_type=&amp;#039;html&amp;#039;;&lt;br /&gt;
col end_snap new_value end_snap;&lt;br /&gt;
col begin_snap new_value begin_snap;&lt;br /&gt;
select max(snap_id) end_snap from dba_hist_snapshot where dbid=&amp;amp;dbid;&lt;br /&gt;
select max(snap_id) begin_snap from dba_hist_snapshot where dbid=&amp;amp;dbid and snap_id &amp;lt; &amp;amp;end_snap;&lt;br /&gt;
define report_name=&amp;#039;awr_report.htm&amp;#039;;&lt;br /&gt;
@?/rdbms/admin/awrrpti&lt;br /&gt;
exit&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==shell==&lt;br /&gt;
[http://www.databasejournal.com/features/oracle/article.php/3869076/Alert-Log-Scraping-with-Oracles-ADRCI-Utility.htm Alert Log scraping with ADRCI]&lt;br /&gt;
&lt;br /&gt;
====Count the number of background processes for a particular SID====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SID=RAVJDE1&lt;br /&gt;
ps -ef|cut -c54-100|awk -v SID=$SID &amp;#039;$0 ~ /&amp;#039;$SID&amp;#039;$/ {print}&amp;#039;|wc -l&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or ...this will work with any OS (so long as the process is at the end of the &amp;lt;strong&amp;gt;ps -ef&amp;lt;/strong&amp;gt; or &amp;lt;strong&amp;gt;ps -aux&amp;lt;/strong&amp;gt; listing&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SID=RAVJDE1&lt;br /&gt;
ps -ef|awk -v SID=$SID -F_ &amp;#039;{ $NF ~ /&amp;#039;$SID&amp;#039;$/ {print} }&amp;#039;|wc -l&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Pick the columns you want in the ps listing&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ps -efo user,pid,ppid=MOM -o args&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Find Oracle errors in the most recent DataPump log files====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
00 09 * * * /home/tools/scripts/oracle/dosh &amp;#039;find /oracle/export -name &amp;quot;expdp*log&amp;quot; -mtime -1 -exec grep ORA- {} \; -ls&amp;#039; | mailx -s &amp;#039;Datapump errors for &amp;lt;customer&amp;gt;last night&amp;#039; stuart@domain.com&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Find the 10 largest directories on a particular filesystem====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
du -ag /oracle | sort -nr | head -n 10&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Find the 10 largest files on a particular mount point====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
find /home -size +1G -ls | sort -nr +6 | head -10&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
find /home -xdev -ls | sort -nr +6 | head -10&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Split a file in pieces using sed====&lt;br /&gt;
Using fixed line numbers&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sed -ne &amp;#039;1,12p&amp;#039; file &amp;gt; text.part1&lt;br /&gt;
sed -ne &amp;#039;13,$p&amp;#039; file &amp;gt; text.part2&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Using line with a /pattern/ on it&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sed -e &amp;#039;/hello/q&amp;#039; tt.dat | grep -v hello &amp;gt; text.part1&lt;br /&gt;
sed -n `sed -n &amp;#039;/hello/=&amp;#039; tt.dat`&amp;#039;,$p&amp;#039; tt.dat | grep -v hello &amp;gt; text.part2&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Split a file in pieces using Perl====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
perl -ne &amp;#039;print if 1 .. /marker line/&amp;#039; text.dat &amp;gt;text.part1&lt;br /&gt;
perl -ne &amp;#039;print if /marker line/ .. eof()&amp;#039; text.dat &amp;gt;text.part2&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Find and display RMAN errors in an RMAN log file====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sed -ne &amp;#039;/^RMAN-/,/^$/p&amp;#039;  RMAN_&amp;lt;SID&amp;gt;_&amp;lt;DATE&amp;gt;.log&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==cmd==&lt;br /&gt;
*[http://www.dba-oracle.com/t_scripts_windows_export.htm Database Export - from DBA Oracle (Burleson)]&lt;br /&gt;
==Perl==&lt;br /&gt;
===For all files in a directory, replace a keyword (SSIIDD) in a file with another (a parameter)===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
for i in `ls`&lt;br /&gt;
do&lt;br /&gt;
    perl -p -i -e &amp;#039;s/SSIIDD/&amp;#039;$SID&amp;#039;/g&amp;#039; $i&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Parse tnsnames.ora to get just the service names===&lt;br /&gt;
[[http://stackoverflow.com/questions/12605415/parsing-tnsnames-ora-with-regex-to-just-get-name from here]]&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
perl -ne &amp;#039;print if m/^([^#()\W ][a-zA-Z.]*(?:[.][a-zA-Z]*\s?=)?)/&amp;#039; $TNS_ADMIN/tnsnames.ora&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===and use that to check the listener status===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
for svc in `perl -ne &amp;#039;print if m/^([^#()\W ][a-zA-Z.]*(?:[.][a-zA-Z]*\s?=)?)/&amp;#039; $TNS_ADMIN/tnsnames.ora | sed -e &amp;#039;s/=//&amp;#039;` ;do&lt;br /&gt;
    tnsping $svc&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Stuart</name></author>	</entry>

	<entry>
		<id>https://mailnest.com/dbawiki/index.php?title=Handy_scripts&amp;diff=3372</id>
		<title>Handy scripts</title>
		<link rel="alternate" type="text/html" href="https://mailnest.com/dbawiki/index.php?title=Handy_scripts&amp;diff=3372"/>
				<updated>2018-11-21T11:56:41Z</updated>
		
		<summary type="html">&lt;p&gt;Stuart: /* External table for the Alert log (pre 11g) */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==SQL==&lt;br /&gt;
* [[Database Overview - from idevelopment]] [http://www.idevelopment.info/data/Oracle/DBA_scripts/Database_Administration/dba_snapshot_database_10g.sql online version]&lt;br /&gt;
* [[Extract ddl with &amp;quot;dbms metadata.get ddl&amp;quot;]]&lt;br /&gt;
* [http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:83012348058 Connecting as another user via proxy in SQL*Plus]&lt;br /&gt;
* [http://www.petefinnigan.com/tools.htm Password cracker and role and priv tools from Pete Finnigan]&lt;br /&gt;
* [http://www.oracle.com/technetwork/articles/sql/11g-pivot-097235.html Using pivot tables in SQL - XML and XLS (Excel) also)]&lt;br /&gt;
===List all instances running on a server===&lt;br /&gt;
Sounds simple enough and indeed pre 12.1, is was as easy as either&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ps -ef | grep [p]mon | awk -F_ &amp;#039;{print $NF}&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or this one is safer in case you have an underscore character in your SID name!!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SIDLIST=$(${PS} -ef | ${GREP} [o]ra_pmon | ${AWK} &amp;#039;{print $NF}&amp;#039; | sed -e &amp;#039;s/ora_pmon_//&amp;#039; | egrep -v &amp;#039;grep|///|sed|awk|ASM|^$&amp;#039;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
but now we have the added complication of CDB/PDB (container / pluggable databases) so a fair bit more work is needed!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/ksh&lt;br /&gt;
# ==============================================================================&lt;br /&gt;
# Name         : list_server_db&lt;br /&gt;
# Description  : List all running databases found on a server&lt;br /&gt;
#&lt;br /&gt;
# Parameters   : none&lt;br /&gt;
#&lt;br /&gt;
# Notes        : none&lt;br /&gt;
#&lt;br /&gt;
# Modification History&lt;br /&gt;
# ====================&lt;br /&gt;
# When      Who               What&lt;br /&gt;
# ========= ================= ==================================================&lt;br /&gt;
# 21-DEC-16 Stuart Barkley    Created&lt;br /&gt;
# ==============================================================================&lt;br /&gt;
for db in $(ps -ef | grep [p]mon|awk -F_ &amp;#039;{print $NF}&amp;#039;)&lt;br /&gt;
do&lt;br /&gt;
    export ORACLE_SID=${db}&lt;br /&gt;
    ORAENV_ASK=NO&lt;br /&gt;
    . oraenv &amp;gt;/dev/null 2&amp;gt;&amp;amp;1&lt;br /&gt;
    sqlplus -s / as sysdba&amp;lt;&amp;lt;EOSQL&lt;br /&gt;
set serveroutput on feed off pages 0 head off newpa none&lt;br /&gt;
declare&lt;br /&gt;
    e_col_not_found exception;&lt;br /&gt;
    e_not_mounted   exception;&lt;br /&gt;
    pragma          exception_init(e_not_mounted, -01507);&lt;br /&gt;
    pragma          exception_init(e_col_not_found, -904);&lt;br /&gt;
    l_db_name       varchar2(20);&lt;br /&gt;
    l_database_role varchar2(20);&lt;br /&gt;
    l_cdb           varchar2(20);&lt;br /&gt;
    l_status        varchar2(20);&lt;br /&gt;
    type varchar2_tab is table of varchar2(240) index by binary_integer;&lt;br /&gt;
    t_pdbs          varchar2_tab;&lt;br /&gt;
begin&lt;br /&gt;
    begin&lt;br /&gt;
        dbms_output.enable(null);&lt;br /&gt;
        execute immediate &amp;#039;select name, database_role, cdb from v\$database&amp;#039; into l_db_name, l_database_role, l_cdb;&lt;br /&gt;
        if l_cdb = &amp;#039;YES&amp;#039; then&lt;br /&gt;
            l_status := &amp;#039;CDB&amp;#039;;&lt;br /&gt;
            execute immediate &amp;#039;select name from v\$pdbs&amp;#039; bulk collect into t_pdbs;&lt;br /&gt;
            for i in nvl(t_pdbs.first,1) .. nvl(t_pdbs.last,0)&lt;br /&gt;
            loop&lt;br /&gt;
                dbms_output.put_line (t_pdbs(i)||&amp;#039;:PDB&amp;#039;);&lt;br /&gt;
            end loop;&lt;br /&gt;
        else&lt;br /&gt;
            l_status := &amp;#039;Independent&amp;#039;;  -- col CDB exists but this is not one&lt;br /&gt;
        end if;&lt;br /&gt;
        if l_database_role like &amp;#039;%STANDBY%&amp;#039; then&lt;br /&gt;
            l_status := &amp;#039;Standby&amp;#039;;&lt;br /&gt;
        end if;&lt;br /&gt;
    exception&lt;br /&gt;
    when e_not_mounted then&lt;br /&gt;
        l_status := &amp;#039;Not Mounted&amp;#039;;&lt;br /&gt;
    when e_col_not_found then&lt;br /&gt;
        l_status := &amp;#039;pre12&amp;#039;;&lt;br /&gt;
    end;&lt;br /&gt;
&lt;br /&gt;
    dbms_output.put_line (&amp;#039;${db}&amp;#039;||&amp;#039;:&amp;#039;||l_status);&lt;br /&gt;
&lt;br /&gt;
end;&lt;br /&gt;
/&lt;br /&gt;
EOSQL&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Run a command or script on all databases in tnsnames.ora===&lt;br /&gt;
Very handy if you have a global tnsnames.ora accessible to all clients.&amp;lt;br /&amp;gt;&lt;br /&gt;
So from a client install, this has access to all databases.&amp;lt;br /&amp;gt;&lt;br /&gt;
Any files created can be created on the client so no need to scp to all the machines to recover spool files etc.&amp;lt;br /&amp;gt;&lt;br /&gt;
Downside: Cannot connect as sysdba across tns so password will need to be known for whatever user is used.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/ksh&lt;br /&gt;
TNSNAMES=&amp;quot;./tnsnames.ora&amp;quot;&lt;br /&gt;
[[ ! -r &amp;quot;${TNSNAMES}&amp;quot; ]] &amp;amp;&amp;amp; echo &amp;quot;${TNSNAMES} is not accessible&amp;quot; &amp;amp;&amp;amp; exit 1&lt;br /&gt;
&lt;br /&gt;
SIDLIST=$(perl -ne &amp;#039;print &amp;quot;$1\n&amp;quot; if /(?:SID|SERVICE_NAME)\s*=\s*(\S+?)\)/&amp;#039; ${TNSNAMES}|sort|uniq|xargs)&lt;br /&gt;
for SID in ${SIDLIST}&lt;br /&gt;
do&lt;br /&gt;
    echo &amp;quot;Processing $SID&amp;quot;&lt;br /&gt;
    ls -al | grep &amp;quot;^d&amp;quot; | grep &amp;quot;\_${SID}&amp;quot; &amp;gt;/dev/null&lt;br /&gt;
    if [[ $? -ne 0 ]]; then&lt;br /&gt;
        echo &amp;#039;exit&amp;#039; | sqlplus system/xxxxxx@${SID} @ReviewLite17.1.sql &amp;gt;/dev/null 2&amp;gt;&amp;amp;1&lt;br /&gt;
    else&lt;br /&gt;
        echo &amp;quot;directory already exists so must have done this SID&amp;quot;&lt;br /&gt;
    fi&lt;br /&gt;
done&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Run a command or script on all databases in oratab===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/usr/bin/ksh&lt;br /&gt;
# ==============================================================================&lt;br /&gt;
# Name         : all_db_do&lt;br /&gt;
# Description  : Loops over all the databases in oratab and executes the&lt;br /&gt;
#                specified SQL command - be careful!&lt;br /&gt;
#&lt;br /&gt;
# Parameters   : -v flag for verbose&lt;br /&gt;
#                [-f &amp;lt;filename&amp;gt; | &amp;lt;quoted SQL command to be executed&amp;gt;]&lt;br /&gt;
#&lt;br /&gt;
# Example      : all_db_do &amp;#039;alter system switch logfile;&amp;#039;&lt;br /&gt;
#                all_db_do -f sessions.sql&lt;br /&gt;
#&lt;br /&gt;
# Notes        : none&lt;br /&gt;
#&lt;br /&gt;
# Modification History&lt;br /&gt;
# ====================&lt;br /&gt;
# When      Who               What&lt;br /&gt;
# ========= ================= ==================================================&lt;br /&gt;
# 14-JAN-13 Stuart Barkley    Created&lt;br /&gt;
# 25-FEB-13 Stuart Barkley    Adapt for Solaris&lt;br /&gt;
# 21-MAR-13 Stuart Barkley    Check db is running first&lt;br /&gt;
# 29-APR-13 Stuart Barkley    Added verbose flag processing&lt;br /&gt;
# 24-MAY-13 Stuart Barkley    Wrap / as sysdba in quotes for older versions&lt;br /&gt;
# 23-JUN-16 Stuart Barkley    Add -f to run a file containing sql&lt;br /&gt;
# ==============================================================================&lt;br /&gt;
&lt;br /&gt;
PROGNAME=$(basename $0)&lt;br /&gt;
OS=$(uname -s)&lt;br /&gt;
&lt;br /&gt;
AWK=$(which awk)&lt;br /&gt;
GREP=$(which grep)&lt;br /&gt;
if [[ &amp;quot;${OS}&amp;quot; == &amp;quot;SunOS&amp;quot; ]]; then&lt;br /&gt;
    AWK=/usr/xpg4/bin/awk&lt;br /&gt;
    GREP=/usr/xpg4/bin/grep&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
if [[ ! -r /etc/oratab ]]; then&lt;br /&gt;
    if [[ &amp;quot;${OS}&amp;quot; == &amp;quot;SunOS&amp;quot; ]]; then&lt;br /&gt;
        echo &amp;quot;oratab is not where we want it. Please run &amp;#039;ln -s /var/opt/oracle/oratab /etc/oratab&amp;#039; as root and retry&amp;quot; &amp;amp;&amp;amp; exit 1&lt;br /&gt;
    else&lt;br /&gt;
        echo &amp;quot;Either Oracle is not installed or database is running without an oratab&amp;quot; &amp;amp;&amp;amp; exit 1&lt;br /&gt;
    fi&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
# -------------------------&lt;br /&gt;
# get the arguments, if any&lt;br /&gt;
# -------------------------&lt;br /&gt;
unset VERBOSE&lt;br /&gt;
while getopts &amp;quot;vf:&amp;quot; flag&lt;br /&gt;
do&lt;br /&gt;
    case &amp;quot;$flag&amp;quot; in&lt;br /&gt;
    v) VERBOSE=1;;&lt;br /&gt;
    f) FILE2RUN=$OPTARG;;&lt;br /&gt;
    esac&lt;br /&gt;
done&lt;br /&gt;
shift $((OPTIND-1))&lt;br /&gt;
&lt;br /&gt;
if [[ -z ${FILE2RUN} ]]; then&lt;br /&gt;
    # no file, need an SQL supplied&lt;br /&gt;
    if [[ -z $1 ]]; then&lt;br /&gt;
        echo &amp;quot;Usage: $0 [-v] [-f &amp;lt;filename&amp;gt; | &amp;lt;quoted SQL command to be executed&amp;gt;]&amp;quot;&lt;br /&gt;
        echo &amp;quot;eg: $0 -f sessions.sql&amp;quot;&lt;br /&gt;
        echo &amp;quot;eg: $0 &amp;#039;alter system switch logfile;&amp;#039;&amp;quot;&lt;br /&gt;
        exit 1&lt;br /&gt;
    fi&lt;br /&gt;
    SQL=$1&lt;br /&gt;
elif [[ -s ${FILE2RUN} ]]; then&lt;br /&gt;
    # file supplied and exists&lt;br /&gt;
    SQL=&amp;quot;@${FILE2RUN}&amp;quot;&lt;br /&gt;
else&lt;br /&gt;
    # file supplied, does it exist&lt;br /&gt;
    echo &amp;quot;File ${FILE2RUN} is empty or does not exist&amp;quot;&lt;br /&gt;
    echo &amp;quot;Usage: $0 [-v] [-f &amp;lt;filename&amp;gt; | &amp;lt;quoted SQL command to be executed&amp;gt;]&amp;quot;&lt;br /&gt;
    echo &amp;quot;eg: $0 -f sessions.sql&amp;quot;&lt;br /&gt;
    echo &amp;quot;eg: $0 &amp;#039;alter system switch logfile;&amp;#039;&amp;quot;&lt;br /&gt;
    exit 1&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
export ORAENV_ASK=NO&lt;br /&gt;
&lt;br /&gt;
for db in $(${AWK} -F: &amp;#039;NF &amp;amp;&amp;amp; $1 !~/[#*]/ {print $1}&amp;#039;  /etc/oratab)&lt;br /&gt;
do&lt;br /&gt;
    if ( [[ $1 != &amp;quot;startup&amp;quot; ]] &amp;amp;&amp;amp; [[ $(ps -ef | ${GREP} -c -E [o]ra_pmon_${db}) -eq 0 ]] ); then&lt;br /&gt;
        [[ ! -z &amp;quot;$VERBOSE&amp;quot; ]] &amp;amp;&amp;amp; echo &amp;quot;$db is not running, skipping...&amp;quot;&lt;br /&gt;
        continue&lt;br /&gt;
    fi&lt;br /&gt;
    echo&lt;br /&gt;
    [[ ! -z &amp;quot;$VERBOSE&amp;quot; ]] &amp;amp;&amp;amp; echo &amp;quot;vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv&amp;quot;&lt;br /&gt;
    [[ ! -z &amp;quot;$VERBOSE&amp;quot; ]] &amp;amp;&amp;amp; echo $db&lt;br /&gt;
    ORACLE_SID=$db&lt;br /&gt;
    . oraenv &amp;gt;/dev/null&lt;br /&gt;
    sqlplus -s &amp;quot;/ as sysdba&amp;quot; &amp;lt;&amp;lt;EOSQL&lt;br /&gt;
define SID=$ORACLE_SID&lt;br /&gt;
col comp_name format a50&lt;br /&gt;
col value for a40&lt;br /&gt;
set linesize 1000&lt;br /&gt;
set pagesize 100&lt;br /&gt;
$SQL&lt;br /&gt;
EOSQL&lt;br /&gt;
    [[ ! -z &amp;quot;$VERBOSE&amp;quot; ]] &amp;amp;&amp;amp; echo &amp;quot;^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^&amp;quot;&lt;br /&gt;
done&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
all_db_do &amp;quot;create or replace directory data_pump_dir as &amp;#039;/oracle/export/&amp;amp;SID&amp;#039;;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
all_db_do &amp;quot;archive log list&amp;quot;&lt;br /&gt;
&lt;br /&gt;
all_db_do &amp;quot;shutdown immediate&amp;quot;&lt;br /&gt;
&lt;br /&gt;
all_db_do &amp;#039;alter system set log_archive_dest_1=&amp;quot;location=/oracle/arch/&amp;amp;SID&amp;quot; scope=both;&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Run an SQL command on behalf of another user===&lt;br /&gt;
It can be used to execute any sql command as a specified user provided this procedure is created in sys schema.&amp;lt;br /&amp;gt;&lt;br /&gt;
* not got this working properly yet *&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set serveroutput on&lt;br /&gt;
create or replace procedure run_sql_as_user ( p_schema_name in varchar2&lt;br /&gt;
                                            , p_sql         in varchar2&lt;br /&gt;
                                            ) is&lt;br /&gt;
    l_user_id dba_users.user_id%type;&lt;br /&gt;
    l_cursor  number;&lt;br /&gt;
    l_rc      number;&lt;br /&gt;
begin&lt;br /&gt;
    dbms_output.enable(null);&lt;br /&gt;
    begin&lt;br /&gt;
        select u.user_id&lt;br /&gt;
        into   l_user_id&lt;br /&gt;
        from   dba_users u&lt;br /&gt;
        where  u.username = p_schema_name;&lt;br /&gt;
    exception&lt;br /&gt;
    when no_data_found then&lt;br /&gt;
        raise_application_error (-20001, &amp;#039;Cannot find user &amp;#039;||p_schema_name);&lt;br /&gt;
    end;&lt;br /&gt;
    l_cursor := dbms_sys_sql.open_cursor;&lt;br /&gt;
    dbms_sys_sql.parse_as_user ( c             =&amp;gt; l_cursor&lt;br /&gt;
                               , statement     =&amp;gt; p_sql&lt;br /&gt;
                               , language_flag =&amp;gt; dbms_sql.native&lt;br /&gt;
                               , userid        =&amp;gt; l_user_id&lt;br /&gt;
    );&lt;br /&gt;
    l_rc := dbms_sys_sql.execute(l_cursor);&lt;br /&gt;
    dbms_sys_sql.close_cursor(l_cursor);&lt;br /&gt;
exception&lt;br /&gt;
when others then&lt;br /&gt;
    raise_application_error (-20001, &amp;#039;ERROR: &amp;#039;||sqlerrm);&lt;br /&gt;
end;&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Run a script on all databases listed in tnsnames.ora===&lt;br /&gt;
Can run an SQL command file on all SID/SERVICE found in a tnsnames.ora file. I use this from a client laptop having a global tns file on it.&amp;lt;br /&amp;gt;&lt;br /&gt;
This way it&amp;#039;s not necessary to copy the file onto every host before executing it. Any files created by the script will be created on the client.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/ksh&lt;br /&gt;
&lt;br /&gt;
TNSNAMES=&amp;quot;./tnsnames.ora&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[ ! -r &amp;quot;${TNSNAMES}&amp;quot; ]] &amp;amp;&amp;amp; echo &amp;quot;${TNSNAMES} is not accessible&amp;quot; &amp;amp;&amp;amp; exit 1&lt;br /&gt;
&lt;br /&gt;
SIDLIST=$(perl -ne &amp;#039;print &amp;quot;$1\n&amp;quot; if /(?:SID|SERVICE_NAME)\s*=\s*(\S+?)\)/&amp;#039; ${TNSNAMES}|sort|uniq|xargs)&lt;br /&gt;
for SID in ${SIDLIST}&lt;br /&gt;
do&lt;br /&gt;
    echo &amp;quot;Processing $SID&amp;quot;&lt;br /&gt;
    ls -al | grep &amp;quot;^d&amp;quot; | grep &amp;quot;\_${SID}&amp;quot; &amp;gt;/dev/null&lt;br /&gt;
    if [[ $? -ne 0 ]]; then&lt;br /&gt;
        echo &amp;#039;exit&amp;#039; | sqlplus system/password@${SID} @ReviewLite17.1.sql &amp;gt;/dev/null 2&amp;gt;&amp;amp;1&lt;br /&gt;
    else&lt;br /&gt;
        echo &amp;quot;directory already exists so must have done this SID&amp;quot;&lt;br /&gt;
    fi&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===List invalid objects===&lt;br /&gt;
 set lines 200&lt;br /&gt;
 set pages 200&lt;br /&gt;
 col obj format a40&lt;br /&gt;
 select owner||&amp;#039;.&amp;#039;||object_name obj&lt;br /&gt;
 ,      object_type&lt;br /&gt;
 from   dba_objects&lt;br /&gt;
 where  1=1&lt;br /&gt;
 and    status = &amp;#039;INVALID&amp;#039;;&lt;br /&gt;
===Recompile all invalid objects===&lt;br /&gt;
@?/rdbms/admin/utlrp.sql&lt;br /&gt;
===See how much space is left in the flash recovery area (FRA)===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select name&lt;br /&gt;
,      to_char (space_limit, &amp;#039;999,999,999,999&amp;#039;) as space_limit&lt;br /&gt;
,      to_char (space_limit - space_used + space_reclaimable&lt;br /&gt;
,               &amp;#039;999,999,999,999&amp;#039;)&lt;br /&gt;
           as space_available&lt;br /&gt;
,      round ( (space_used - space_reclaimable) / space_limit * 100, 1)&lt;br /&gt;
           as pct_full&lt;br /&gt;
from   v$recovery_file_dest;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# ==============================================&lt;br /&gt;
# Check FRA to see how much space is reclaimable&lt;br /&gt;
# ==============================================&lt;br /&gt;
fra_reclaim_check() {&lt;br /&gt;
&lt;br /&gt;
LOGFILE=${RMAN_LogDir}/${ORACLE_SID}_`date &amp;#039;+%Y%m&amp;#039;`_${V_SCRIPT}.log&lt;br /&gt;
sqlplus &amp;quot;/ as sysdba&amp;quot; &amp;lt;&amp;lt;EOSQL &amp;gt; /tmp/results.$$&lt;br /&gt;
set vefify off echo off heading off newpage none linesize 1000 echo off&lt;br /&gt;
select &amp;#039;Filesystem:&amp;#039;||name||&lt;br /&gt;
       &amp;#039;; Total(Gb):&amp;#039;||round((space_limit/1073741824),2) ||&lt;br /&gt;
       &amp;#039;; Reclaimable(Gb):&amp;#039;||round((space_reclaimable/1073741824),2) ||&lt;br /&gt;
       &amp;#039;; Reclaimable(%):&amp;#039;||round( ((space_reclaimable/1073741824)/(space_limit/1073741824)*100),2 )&lt;br /&gt;
from   v$recovery_file_dest&lt;br /&gt;
/&lt;br /&gt;
EOSQL&lt;br /&gt;
cat /tmp/results.$$ &amp;gt;&amp;gt; $LOGFILE&lt;br /&gt;
rm /tmp/results.$$&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===How far back can we flashback?===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
col time_now              for a25&lt;br /&gt;
col time_oldest_flashback for a25&lt;br /&gt;
select to_char(sysdate,&amp;#039;DD-MON-YY HH24:MI&amp;#039;)                    time_now&lt;br /&gt;
,      to_char(fdl.oldest_flashback_time, &amp;#039;DD-MON-YY HH24:MI&amp;#039;) time_oldest_flashback&lt;br /&gt;
,      round((sysdate-fdl.oldest_flashback_time)*24,1)         hours_flashback_possible&lt;br /&gt;
from   v$database d&lt;br /&gt;
,      v$flashback_database_log fdl&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===DBA privs tables===&lt;br /&gt;
 DBA_AQ_AGENT_PRIVS&lt;br /&gt;
 DBA_COL_PRIVS&lt;br /&gt;
 DBA_PRIV_AUDIT_OPTS&lt;br /&gt;
 DBA_REPGROUP_PRIVILEGES&lt;br /&gt;
 DBA_ROLE_PRIVS&lt;br /&gt;
 DBA_RSRC_CONSUMER_GROUP_PRIVS&lt;br /&gt;
 DBA_RSRC_MANAGER_SYSTEM_PRIVS&lt;br /&gt;
 DBA_SYS_PRIVS&lt;br /&gt;
 DBA_TAB_PRIVS&lt;br /&gt;
 DBA_WM_SYS_PRIVS&lt;br /&gt;
 DBA_WORKSPACE_PRIVS&lt;br /&gt;
&lt;br /&gt;
===Schedule a shell job===&lt;br /&gt;
 begin&lt;br /&gt;
     dbms_scheduler.create_program ( program_name   =&amp;gt; &amp;#039;myshelljob&amp;#039;&lt;br /&gt;
                                   , program_action =&amp;gt; &amp;#039;/home/oracle/scripts/shell.sh&amp;#039;&lt;br /&gt;
                                   , program_type   =&amp;gt; &amp;#039;EXECUTABLE&amp;#039;&lt;br /&gt;
                                   , comments       =&amp;gt; &amp;#039;Run a shell&amp;#039;&lt;br /&gt;
                                   , enabled        =&amp;gt; TRUE&lt;br /&gt;
                                   );&lt;br /&gt;
 end;&lt;br /&gt;
 /&lt;br /&gt;
===Start the job===&lt;br /&gt;
 begin&lt;br /&gt;
     dbms_sheduler.create_job ( job_name     =&amp;gt; &amp;#039;myshelljob&amp;#039;&lt;br /&gt;
                              , program_name =&amp;gt; &amp;#039;myshelljob&amp;#039;&lt;br /&gt;
                              , start_date   =&amp;gt;&lt;br /&gt;
                              );&lt;br /&gt;
 /&lt;br /&gt;
&lt;br /&gt;
===What statement is a user running?===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select a.sid&lt;br /&gt;
,      a.serial#&lt;br /&gt;
,      b.sql_text&lt;br /&gt;
from   v$session a&lt;br /&gt;
,      v$sqlarea b&lt;br /&gt;
where  a.sql_address = b.address&lt;br /&gt;
and    a.username    = &amp;#039;&amp;amp;username&amp;#039;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===See what statements all users are running===&lt;br /&gt;
Useful to see what is happening when process limit is reached&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 300 pages 1000&lt;br /&gt;
&lt;br /&gt;
col username for a10&lt;br /&gt;
col command for 999 head &amp;quot;CMD&amp;quot;&lt;br /&gt;
col lockwait for a10&lt;br /&gt;
col status for a8&lt;br /&gt;
col schemaname for a12&lt;br /&gt;
col osuser for a10&lt;br /&gt;
col process for a10&lt;br /&gt;
col program for a20&lt;br /&gt;
col machine for a10&lt;br /&gt;
col action for a10&lt;br /&gt;
col module for a10&lt;br /&gt;
col identifier for a10&lt;br /&gt;
col event for a27&lt;br /&gt;
col state for a8&lt;br /&gt;
col service_name for a10&lt;br /&gt;
col serial# for 999999&lt;br /&gt;
&lt;br /&gt;
select a.username&lt;br /&gt;
,      a.command&lt;br /&gt;
,      a.lockwait&lt;br /&gt;
,      a.status&lt;br /&gt;
,      a.schemaname&lt;br /&gt;
,      a.osuser&lt;br /&gt;
,      a.process&lt;br /&gt;
,      a.machine&lt;br /&gt;
,      a.program&lt;br /&gt;
,      a.type&lt;br /&gt;
--,      a.sql_exec_start&lt;br /&gt;
--,      a.plsql_object_id&lt;br /&gt;
--,      a.plsql_subprogram_id&lt;br /&gt;
--,      a.module&lt;br /&gt;
--,      a.action&lt;br /&gt;
,      a.logon_time&lt;br /&gt;
,      a.event&lt;br /&gt;
,      a.wait_time&lt;br /&gt;
,      a.seconds_in_wait&lt;br /&gt;
,      a.state&lt;br /&gt;
--,      a.service_name&lt;br /&gt;
,      a.serial#&lt;br /&gt;
,      b.sql_text&lt;br /&gt;
from   v$session a&lt;br /&gt;
,      v$sqlarea b&lt;br /&gt;
where  a.sql_address = b.address&lt;br /&gt;
order  by a.logon_time desc&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
set lines 80&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===A logminer session===&lt;br /&gt;
Mine all SQL statements in a 10 minute period&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sqlplus / as sysdba&lt;br /&gt;
alter session set nls_date_format = &amp;#039;DD-MON-YYYY HH24:MI:SS&amp;#039;;&lt;br /&gt;
execute dbms_logmnr.start_logmnr ( starttime =&amp;gt; &amp;#039;27-OCT-2009 11:05:00&amp;#039;&lt;br /&gt;
                                 , endtime   =&amp;gt; &amp;#039;27-OCT-2009 11:15:00&amp;#039;&lt;br /&gt;
                                 , options   =&amp;gt; dbms_logmnr.dict_from_online_catalog+dbms_logmnr.continuous_mine&lt;br /&gt;
                                 );&lt;br /&gt;
create table mycontents as select * from v$logmnr_contents;&lt;br /&gt;
execute dbms_logmnr.end_logmnr(); &lt;br /&gt;
&lt;br /&gt;
select * from mycontents;&lt;br /&gt;
&lt;br /&gt;
drop table mycontents;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Huge Pages===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
#&lt;br /&gt;
# hugepages_settings.sh&lt;br /&gt;
#&lt;br /&gt;
# Linux bash script to compute values for the&lt;br /&gt;
# recommended HugePages/HugeTLB configuration&lt;br /&gt;
#&lt;br /&gt;
# Note: This script does calculation for all shared memory&lt;br /&gt;
# segments available when the script is run, no matter it&lt;br /&gt;
# is an Oracle RDBMS shared memory segment or not.&lt;br /&gt;
# Check for the kernel version&lt;br /&gt;
KERN=`uname -r | awk -F. &amp;#039;{ printf(&amp;quot;%d.%d\n&amp;quot;,$1,$2); }&amp;#039;`&lt;br /&gt;
# Find out the HugePage size&lt;br /&gt;
HPG_SZ=`grep Hugepagesize /proc/meminfo | awk {&amp;#039;print $2&amp;#039;}`&lt;br /&gt;
# Start from 1 pages to be on the safe side and guarantee 1 free HugePage&lt;br /&gt;
NUM_PG=1&lt;br /&gt;
# Cumulative number of pages required to handle the running shared memory segments&lt;br /&gt;
for SEG_BYTES in `ipcs -m | awk {&amp;#039;print $5&amp;#039;} | grep &amp;quot;[0-9][0-9]*&amp;quot;`&lt;br /&gt;
do&lt;br /&gt;
   MIN_PG=`echo &amp;quot;$SEG_BYTES/($HPG_SZ*1024)&amp;quot; | bc -q`&lt;br /&gt;
   if [ $MIN_PG -gt 0 ]; then&lt;br /&gt;
      NUM_PG=`echo &amp;quot;$NUM_PG+$MIN_PG+1&amp;quot; | bc -q`&lt;br /&gt;
   fi&lt;br /&gt;
done&lt;br /&gt;
# Finish with results&lt;br /&gt;
case $KERN in&lt;br /&gt;
   &amp;#039;2.4&amp;#039;) HUGETLB_POOL=`echo &amp;quot;$NUM_PG*$HPG_SZ/1024&amp;quot; | bc -q`;&lt;br /&gt;
          echo &amp;quot;Recommended setting: vm.hugetlb_pool = $HUGETLB_POOL&amp;quot; ;;&lt;br /&gt;
   &amp;#039;2.6&amp;#039; | &amp;#039;3.8&amp;#039;) echo &amp;quot;Recommended setting: vm.nr_hugepages = $NUM_PG&amp;quot; ;;&lt;br /&gt;
    *) echo &amp;quot;Unrecognized kernel version $KERN. Exiting.&amp;quot; ;;&lt;br /&gt;
esac&lt;br /&gt;
# End&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Pretty longops listing===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 2000 pages 1000&lt;br /&gt;
col opname for a34 head &amp;quot;Job&amp;quot;&lt;br /&gt;
col message for a60&lt;br /&gt;
col perc_done for a10 head &amp;quot;Done&amp;quot;&lt;br /&gt;
col started for a18&lt;br /&gt;
col killer for a15&lt;br /&gt;
col mins_busy head &amp;quot;Mins busy&amp;quot;&lt;br /&gt;
col mins_left head &amp;quot;Mins left&amp;quot;&lt;br /&gt;
select sid||&amp;#039;,&amp;#039;||serial#                       killer&lt;br /&gt;
,      opname&lt;br /&gt;
,      message&lt;br /&gt;
,      round ((sofar/totalwork),4)*100||&amp;#039;%&amp;#039;    perc_done&lt;br /&gt;
,      to_char(start_time,&amp;#039;DD-MON-YY HH24:MI&amp;#039;) started&lt;br /&gt;
,      floor(elapsed_seconds/60)               mins_busy&lt;br /&gt;
,      ceil(time_remaining/60)                 mins_left&lt;br /&gt;
from   v$session_longops&lt;br /&gt;
where  1=1&lt;br /&gt;
and    sofar     != totalwork&lt;br /&gt;
and    totalwork != 0&lt;br /&gt;
and    opname    like &amp;#039;RMAN%&amp;#039;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select * from v$session where module=&amp;#039;Data Pump Worker&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or attach to the impdp job and it shows percentage done.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Get the SID from v$session_longops and plug it into v$session to check the SQL command details.&lt;br /&gt;
&lt;br /&gt;
Current Running SQLs&lt;br /&gt;
--------------------&lt;br /&gt;
set pages 1000 lines 2000&lt;br /&gt;
col program  format a40&lt;br /&gt;
col sql_text format a130&lt;br /&gt;
&lt;br /&gt;
select s.sid&lt;br /&gt;
,      s.status&lt;br /&gt;
,      s.last_call_et&lt;br /&gt;
,      s.program&lt;br /&gt;
,      sa.sql_id&lt;br /&gt;
,      sa.sql_text&lt;br /&gt;
from   v$session s&lt;br /&gt;
,      v$sqlarea sa&lt;br /&gt;
where  s.sql_id = sa.sql_id&lt;br /&gt;
and    s.sid = &amp;#039;&amp;amp;sid&amp;#039;&lt;br /&gt;
/ &lt;br /&gt;
&lt;br /&gt;
set pages 1000 lines 2000&lt;br /&gt;
col USERNAME for a10&lt;br /&gt;
col OSUSER   for a10&lt;br /&gt;
col MACHINE  for a10&lt;br /&gt;
&lt;br /&gt;
select s.sid&lt;br /&gt;
,      s.serial#&lt;br /&gt;
,      p.spid&lt;br /&gt;
,      s.username&lt;br /&gt;
,      s.osuser&lt;br /&gt;
,      s.status&lt;br /&gt;
,      s.process fg_pid&lt;br /&gt;
,      s.longon_time&lt;br /&gt;
,      s.machine&lt;br /&gt;
,      p.spid bg_pid&lt;br /&gt;
from   gv$session s&lt;br /&gt;
,      gv$process p&lt;br /&gt;
where  s.addr = p.addr&lt;br /&gt;
and    s.sid  = &amp;#039;&amp;amp;sid&amp;#039;&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
$ps -ef | grep &amp;lt;spid&amp;gt;&lt;br /&gt;
&lt;br /&gt;
set pages 1000 lines 2000&lt;br /&gt;
SELECT INST_ID&lt;br /&gt;
,      SID&lt;br /&gt;
,      SERIAL#&lt;br /&gt;
,      SQL_ID&lt;br /&gt;
,      USERNAME&lt;br /&gt;
,      PROGRAM&lt;br /&gt;
,      MACHINE&lt;br /&gt;
,      SERVICE_NAME&lt;br /&gt;
FROM   GV$SESSION&lt;br /&gt;
WHERE  SID IN (&amp;#039;&amp;lt;SID_NO.1&amp;gt;&amp;#039;,&amp;#039;&amp;lt;SID_NO.2&amp;gt;&amp;#039;)&lt;br /&gt;
/&lt;br /&gt;
Active Running SQLs&lt;br /&gt;
--------------------&lt;br /&gt;
set pages 1000 lines 2000&lt;br /&gt;
col SPID     for a10&lt;br /&gt;
col PROGRAM  for a15&lt;br /&gt;
col OSUSER   for a10&lt;br /&gt;
col ACTION   for a10&lt;br /&gt;
col EVENT    for a25&lt;br /&gt;
col SQL_TEXT for a25&lt;br /&gt;
col MACHINE  for a10&lt;br /&gt;
col P1TEXT   for a10 &lt;br /&gt;
col P2TEXT   for a10&lt;br /&gt;
col P3TEXT   for a10  &lt;br /&gt;
SELECT b.sid&lt;br /&gt;
,      b.serial#&lt;br /&gt;
,      a.spid&lt;br /&gt;
,      b.sql_id&lt;br /&gt;
,      b.program&lt;br /&gt;
,      b.osuser&lt;br /&gt;
,      b.machine&lt;br /&gt;
,      b.type&lt;br /&gt;
,      b.event&lt;br /&gt;
,      b.action&lt;br /&gt;
,      b.p1text&lt;br /&gt;
,      b.p2text&lt;br /&gt;
,      b.p3text&lt;br /&gt;
,      b.state&lt;br /&gt;
,      c.sql_text&lt;br /&gt;
,      b.logon_time&lt;br /&gt;
FROM   v$process a&lt;br /&gt;
,      v$session b&lt;br /&gt;
,      v$sqltext c&lt;br /&gt;
WHERE  a.addr           = b.paddr&lt;br /&gt;
AND    b.sql_hash_value = c.hash_value&lt;br /&gt;
AND    b.STATUS         = &amp;#039;ACTIVE&amp;#039;&lt;br /&gt;
AND    b.sid            = &amp;#039;&amp;amp;sid&amp;#039;&lt;br /&gt;
ORDER  BY a.spid&lt;br /&gt;
,      c.piece&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
OR - Use the below Query &lt;br /&gt;
&lt;br /&gt;
Longops.sql&lt;br /&gt;
----------- &lt;br /&gt;
set pages 50000 lines 32767&lt;br /&gt;
col OPNAME for a10&lt;br /&gt;
col SID form 9999&lt;br /&gt;
col SERIAL form 9999999&lt;br /&gt;
col PROGRAM for a10&lt;br /&gt;
col USERNAME for a10&lt;br /&gt;
col SQL_TEXT for a40&lt;br /&gt;
col START_TIME for a10&lt;br /&gt;
col LAST_UPDATE_TIME for a10&lt;br /&gt;
col TARGET for a25&lt;br /&gt;
col MESSAGE for a25&lt;br /&gt;
&lt;br /&gt;
alter session set nls_date_format = &amp;#039;DD-MM-YYYY HH24:MI:SS&amp;#039;;&lt;br /&gt;
&lt;br /&gt;
SELECT l.inst_id,l.sid, l.serial#, l.sql_id, l.opname, l.username, l.target, l.sofar, l.totalwork, l.start_time,l.last_update_time,round(l.time_remaining/60,2) &amp;quot;REMAIN MINS&amp;quot;, round(l.elapsed_seconds/60,2) &amp;quot;ELAPSED MINS&amp;quot;, round((l.time_remaining+l.elapsed_seconds)/60,2) &amp;quot;TOTAL MINS&amp;quot;, ROUND(l.SOFAR/l.TOTALWORK*100,2) &amp;quot;%_COMPLETE&amp;quot;, l.message,s.sql_text &lt;br /&gt;
FROM gv$session_longops l &lt;br /&gt;
LEFT OUTER JOIN v$sql s on s.hash_value=l.sql_hash_value and s.address=l.sql_address and s.child_number=0&lt;br /&gt;
WHERE l.OPNAME NOT LIKE &amp;#039;RMAN%&amp;#039; AND l.OPNAME NOT LIKE &amp;#039;%aggregate%&amp;#039; AND l.TOTALWORK != 0 AND l.sofar&amp;lt;&amp;gt;l.totalwork AND l.time_remaining &amp;gt; 0&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Apply the database patch after the ORACLE_HOME has been patched===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ORAENV_ASK=NO&lt;br /&gt;
export ORACLE_SID=$1&lt;br /&gt;
. oraenv&lt;br /&gt;
&lt;br /&gt;
sqlplus /nolog &amp;lt;&amp;lt;EOSQL&lt;br /&gt;
connect / as sysdba&lt;br /&gt;
startup&lt;br /&gt;
@?/rdbms/admin/catbundle.sql psu apply&lt;br /&gt;
@?/rdbms/admin/utlrp.sql&lt;br /&gt;
purge dba_recyclebin;&lt;br /&gt;
&lt;br /&gt;
prompt check patch apply...&lt;br /&gt;
set lines 150&lt;br /&gt;
col action_time for a50&lt;br /&gt;
col comp_name for a50&lt;br /&gt;
col comments for a50&lt;br /&gt;
&lt;br /&gt;
select action_time,action,comments from sys.registry\$history where trunc(action_time) = trunc(sysdate);&lt;br /&gt;
select comp_name,version,status,modified from dba_registry;&lt;br /&gt;
exit&lt;br /&gt;
EOSQL&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Show how much archivelog data is generated per day===&lt;br /&gt;
A companion script for &amp;#039;how many log switches in a day&amp;#039;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
col orderby noprint&lt;br /&gt;
select trunc(first_time) orderby&lt;br /&gt;
,      to_char(first_time,&amp;#039;DD-MON-YYYY&amp;#039;) &amp;quot;Date&amp;quot;&lt;br /&gt;
,      round(sum(bytes/1024/1024/1024),2) arch_logs_gigs&lt;br /&gt;
from (&lt;br /&gt;
    select unique (blocks * block_size) bytes,&lt;br /&gt;
    thread#,&lt;br /&gt;
    sequence#,&lt;br /&gt;
    resetlogs_change#,&lt;br /&gt;
    first_time&lt;br /&gt;
    from v$archived_log&lt;br /&gt;
)&lt;br /&gt;
group by trunc(first_time)&lt;br /&gt;
,      to_char(first_time, &amp;#039;DD-MON-YYYY&amp;#039;)&lt;br /&gt;
order by trunc(first_time) desc&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Abort a hanging database even when sysdba cannot connect===&lt;br /&gt;
Unable to connect to database with sqlplus / as sysdba because audit file cannot be created?&lt;br /&gt;
* [http://tech.e2sn.com/oracle/troubleshooting/hang/how-to-log-on-even-when-sysdba-can-t-do-so tech.e2sn.com]&lt;br /&gt;
* [http://blog.dbi-services.com/oracle-is-hanging-dont-forget-hanganalyze-and-systemstate/ blog.dbi-services.com]&lt;br /&gt;
Instead of just killing the pmon process, there is a kinder (and more useful) way to kill the database.&amp;lt;br /&amp;gt;&lt;br /&gt;
Use the hidden, undocumented &amp;#039;prelim&amp;#039; switch parameter to sqlplus to make a connection to the database without creating SGA session data structures.&amp;lt;br /&amp;gt;&lt;br /&gt;
It can be very useful for hang analysis so the possible cause can be found after the database has been restarted.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sqlplus -prelim / as sysdba&lt;br /&gt;
oradebug unlimit&lt;br /&gt;
oradebug hanganalyze 3&lt;br /&gt;
oradebug setmypid              -- or oradebug setorapname diag&lt;br /&gt;
oradebug dump ashdumpseconds 30&lt;br /&gt;
oradebug dump systemstate 10   -- or oradebug dump systemstate 266&lt;br /&gt;
oradebug tracefile_name&lt;br /&gt;
shutdown abort&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Lists Oracle session with kill session statement all ready to go===&lt;br /&gt;
disconnect attempts to kill the o/s processes too. kill doesn&amp;#039;t.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
col killer for a60&lt;br /&gt;
col osuser for a12&lt;br /&gt;
col logon  for a23&lt;br /&gt;
col spid   for a8&lt;br /&gt;
col username for a15&lt;br /&gt;
col program for a50&lt;br /&gt;
set lines 2000&lt;br /&gt;
select &amp;#039;alter system disconnect session &amp;#039;&amp;#039;&amp;#039;||s.sid||&amp;#039;,&amp;#039;||s.serial#||&amp;#039;&amp;#039;&amp;#039; immediate;&amp;#039; killer&lt;br /&gt;
,      s.inst_id&lt;br /&gt;
,      to_char(s.logon_time,&amp;#039;DD-MON-YY HH24:MI:SS&amp;#039;) logon&lt;br /&gt;
,      sci.osuser&lt;br /&gt;
,      p.spid&lt;br /&gt;
,      s.username&lt;br /&gt;
,      s.program&lt;br /&gt;
from   gv$session s&lt;br /&gt;
,      gv$session_connect_info sci&lt;br /&gt;
,      gv$process p&lt;br /&gt;
where  1=1&lt;br /&gt;
and    p.addr     = s.paddr&lt;br /&gt;
and    p.inst_id  = s.inst_id&lt;br /&gt;
and    s.sid      = sci.sid&lt;br /&gt;
and    s.serial#  = sci.serial#&lt;br /&gt;
and    s.type    != &amp;#039;BACKGROUND&amp;#039;&lt;br /&gt;
and    sci.osuser = &amp;#039;oraibm&amp;#039;&lt;br /&gt;
order  by s.logon_time desc&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
KILLER                                                          INST_ID LOGON                   OSUSER       SPID     USERNAME        PROGRAM&lt;br /&gt;
------------------------------------------------------------ ---------- ----------------------- ------------ -------- --------------- --------------------------------------------------&lt;br /&gt;
alter system disconnect session &amp;#039;490,33947&amp;#039; immediate;                1 23-JUN-16 13:30:53      oraibm       23205    SYS             sqlplus@benouerp07 (TNS V1-V3)&lt;br /&gt;
alter system disconnect session &amp;#039;490,33947&amp;#039; immediate;                1 23-JUN-16 13:30:53      oraibm       23205    SYS             sqlplus@benouerp07 (TNS V1-V3)&lt;br /&gt;
alter system disconnect session &amp;#039;490,33947&amp;#039; immediate;                1 23-JUN-16 13:30:53      oraibm       23205    SYS             sqlplus@benouerp07 (TNS V1-V3)&lt;br /&gt;
alter system disconnect session &amp;#039;490,33947&amp;#039; immediate;                1 23-JUN-16 13:30:53      oraibm       23205    SYS             sqlplus@benouerp07 (TNS V1-V3)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===How much space is being used by a guaranteed restore point?===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
show parameter recovery&lt;br /&gt;
set numwi 15&lt;br /&gt;
set lines 200&lt;br /&gt;
col name for a40&lt;br /&gt;
col time for a23&lt;br /&gt;
col gigs_limit head &amp;quot;Max (but check df -g also!)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
select name&lt;br /&gt;
,      time&lt;br /&gt;
,      round(storage_size/1024/1024/1024,2) gigs_used&lt;br /&gt;
from   v$restore_point&lt;br /&gt;
where  1=1&lt;br /&gt;
and    guarantee_flashback_database = &amp;#039;YES&amp;#039;&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
select * from v$flash_recovery_area_usage&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
select name&lt;br /&gt;
,      round(space_used/1024/1024/1024,2) gigs_used&lt;br /&gt;
,      round(space_limit/1024/1024/1024,2) gigs_limit&lt;br /&gt;
,      space_reclaimable&lt;br /&gt;
,      number_of_files&lt;br /&gt;
from v$recovery_file_dest&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Get statistics for LOB columns in a table===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select &lt;br /&gt;
  max(dbms_lob.getlength(lob_content)) max_len&lt;br /&gt;
, avg(dbms_lob.getlength(lob_content)) avg_len&lt;br /&gt;
, min(dbms_lob.getlength(lob_content)) min_len&lt;br /&gt;
, sum(case when dbms_lob.getlength(lob_content) &amp;lt;= 4000 then 1&lt;br /&gt;
else 0 end) &amp;quot;&amp;lt;4k&amp;quot;&lt;br /&gt;
, sum(case when dbms_lob.getlength(lob_content) &amp;gt; 4000 then 1&lt;br /&gt;
else 0 end) &amp;quot;&amp;gt;4k&amp;quot;&lt;br /&gt;
, sum(case when dbms_lob.getlength(lob_content) is null then 1 else&lt;br /&gt;
0 end) &amp;quot;is null&amp;quot;&lt;br /&gt;
from &amp;amp;tablename&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===badprivs.sql===&lt;br /&gt;
Check to see if any ordinary users have privileges / access / grants / rights they should not have&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select grantee, privilege, admin_option&lt;br /&gt;
from   sys.dba_sys_privs&lt;br /&gt;
where  (       privilege like &amp;#039;% ANY %&amp;#039;&lt;br /&gt;
        or     privilege in (&amp;#039;BECOME USER&amp;#039;, &amp;#039;UNLIMITED TABLESPACE&amp;#039;)&lt;br /&gt;
        or     admin_option = &amp;#039;YES&amp;#039;&lt;br /&gt;
       )&lt;br /&gt;
and    grantee not in (&amp;#039;SYS&amp;#039;, &amp;#039;SYSTEM&amp;#039;, &amp;#039;OUTLN&amp;#039;, &amp;#039;AQ_ADMINISTRATOR_ROLE&amp;#039;,&lt;br /&gt;
                      &amp;#039;DBA&amp;#039;, &amp;#039;EXP_FULL_DATABASE&amp;#039;, &amp;#039;IMP_FULL_DATABASE&amp;#039;,&lt;br /&gt;
                      &amp;#039;OEM_MONITOR&amp;#039;, &amp;#039;CTXSYS&amp;#039;, &amp;#039;DBSNMP&amp;#039;, &amp;#039;IFSSYS&amp;#039;,&lt;br /&gt;
                      &amp;#039;IFSSYS$CM&amp;#039;, &amp;#039;MDSYS&amp;#039;, &amp;#039;ORDPLUGINS&amp;#039;, &amp;#039;ORDSYS&amp;#039;,&lt;br /&gt;
                      &amp;#039;TIMESERIES_DBA&amp;#039;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Generate a list of tablespaces ready for a migration===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set echo off&lt;br /&gt;
set lines 300&lt;br /&gt;
set pages 0&lt;br /&gt;
Set headi off&lt;br /&gt;
set feedb off&lt;br /&gt;
set long 32000&lt;br /&gt;
&lt;br /&gt;
spool migration_create_target_tablespaces.sql&lt;br /&gt;
&lt;br /&gt;
exec dbms_metadata.set_transform_param(dbms_metadata.session_transform,&amp;#039;SQLTERMINATOR&amp;#039;,TRUE);&lt;br /&gt;
select DBMS_METADATA.GET_DDL(&amp;#039;TABLESPACE&amp;#039;,tablespace_name) from dba_tablespaces&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
spool off&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===List the privileges assigned to users on directories===&lt;br /&gt;
table_name is the name of the directory...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select grantor&lt;br /&gt;
,      grantee&lt;br /&gt;
,      table_schema&lt;br /&gt;
,      table_name&lt;br /&gt;
,      privilege&lt;br /&gt;
from   all_tab_privs&lt;br /&gt;
where  table_name = &amp;#039;DATA_PUMP_DIR&amp;#039;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===List the privileges assigned to users on packages/procedures===&lt;br /&gt;
table_name is the name of the package...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select grantor&lt;br /&gt;
,      grantee&lt;br /&gt;
,      table_schema&lt;br /&gt;
,      table_name&lt;br /&gt;
,      privilege&lt;br /&gt;
from   all_tab_privs&lt;br /&gt;
where  upper(table_name) like upper(&amp;#039;%UTL_FILE%&amp;#039;)&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===List the system privileges assigned to a user (used to copy user as or clone user as)===&lt;br /&gt;
Maybe this one is better [[Extract ddl with &amp;quot;dbms metadata.get ddl&amp;quot;]]&lt;br /&gt;
&lt;br /&gt;
 SELECT LPAD(&amp;#039; &amp;#039;, 2*level) || granted_role &amp;quot;USER PRIVS&amp;quot;&lt;br /&gt;
 FROM (&lt;br /&gt;
   SELECT NULL grantee,  username granted_role&lt;br /&gt;
   FROM dba_users&lt;br /&gt;
   WHERE username LIKE UPPER(&amp;#039;%&amp;amp;uname%&amp;#039;)&lt;br /&gt;
   UNION&lt;br /&gt;
   SELECT grantee, granted_role&lt;br /&gt;
   FROM dba_role_privs&lt;br /&gt;
   UNION&lt;br /&gt;
   SELECT grantee, privilege&lt;br /&gt;
   FROM dba_sys_privs)&lt;br /&gt;
 START WITH grantee IS NULL&lt;br /&gt;
 CONNECT BY grantee = prior granted_role;&lt;br /&gt;
&lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
 SELECT path&lt;br /&gt;
 FROM (&lt;br /&gt;
   SELECT grantee,&lt;br /&gt;
          sys_connect_by_path(privilege, &amp;#039;:&amp;#039;)||&amp;#039;:&amp;#039;||grantee path&lt;br /&gt;
   FROM (&lt;br /&gt;
     SELECT grantee, privilege, 0 role&lt;br /&gt;
     FROM dba_sys_privs&lt;br /&gt;
     UNION ALL&lt;br /&gt;
     SELECT grantee, granted_role, 1 role&lt;br /&gt;
     FROM dba_role_privs)&lt;br /&gt;
   CONNECT BY privilege=prior grantee&lt;br /&gt;
   START WITH role = 0)&lt;br /&gt;
 WHERE grantee IN (&lt;br /&gt;
    SELECT username&lt;br /&gt;
    FROM dba_users&lt;br /&gt;
    WHERE lock_date IS NULL&lt;br /&gt;
    AND password != &amp;#039;EXTERNAL&amp;#039;&lt;br /&gt;
    AND username != &amp;#039;SYS&amp;#039;)&lt;br /&gt;
 OR grantee=&amp;#039;PUBLIC&amp;#039;&lt;br /&gt;
&lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
for a migration from 10g...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set headi off&lt;br /&gt;
set feedb off&lt;br /&gt;
set long  9999999&lt;br /&gt;
set pages 0&lt;br /&gt;
set lines 300&lt;br /&gt;
&lt;br /&gt;
spool migration_create_target_users_grants.sql&lt;br /&gt;
&lt;br /&gt;
select dbms_metadata.get_ddl(&amp;#039;USER&amp;#039;, username) || &amp;#039;;&amp;#039; ddl&lt;br /&gt;
from dba_users&lt;br /&gt;
where  1=1&lt;br /&gt;
and    username like upper(&amp;#039;%&amp;amp;&amp;amp;USER_NAME%&amp;#039;)&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
select &amp;#039;grant &amp;#039;||privilege|| &amp;#039; to &amp;#039; || grantee || &amp;#039;;&amp;#039;&lt;br /&gt;
from   dba_sys_privs&lt;br /&gt;
where  1=1&lt;br /&gt;
and    grantee like upper(&amp;#039;%&amp;amp;&amp;amp;USER_NAME%&amp;#039;)&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
select &amp;#039;grant &amp;#039;||granted_role|| &amp;#039; to &amp;#039; || grantee || &amp;#039;;&amp;#039;&lt;br /&gt;
from   dba_role_privs&lt;br /&gt;
where  1=1&lt;br /&gt;
and    grantee like upper(&amp;#039;%&amp;amp;&amp;amp;USER_NAME%&amp;#039;)&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
spool off&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or for a migration on 11g...!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set head off&lt;br /&gt;
set pages 0&lt;br /&gt;
set long 9999999&lt;br /&gt;
col ddl for a1000&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
SELECT DBMS_METADATA.GET_DDL(&amp;#039;USER&amp;#039;, USERNAME) || &amp;#039;;&amp;#039; DDL&lt;br /&gt;
FROM DBA_USERS&lt;br /&gt;
where  1=1&lt;br /&gt;
and    default_tablespace not in (&amp;#039;SYSTEM&amp;#039;,&amp;#039;SYSAUX&amp;#039;)&lt;br /&gt;
and    upper(username) like &amp;#039;%&amp;#039;||upper(&amp;#039;&amp;amp;&amp;amp;username&amp;#039;)||&amp;#039;%&amp;#039;&lt;br /&gt;
UNION ALL&lt;br /&gt;
SELECT DBMS_METADATA.GET_GRANTED_DDL(&amp;#039;ROLE_GRANT&amp;#039;, USERNAME) || &amp;#039;;&amp;#039; DDL&lt;br /&gt;
FROM DBA_USERS&lt;br /&gt;
where  1=1&lt;br /&gt;
and    default_tablespace not in (&amp;#039;SYSTEM&amp;#039;,&amp;#039;SYSAUX&amp;#039;)&lt;br /&gt;
and    upper(username) like &amp;#039;%&amp;#039;||upper(&amp;#039;&amp;amp;&amp;amp;username&amp;#039;)||&amp;#039;%&amp;#039;&lt;br /&gt;
UNION ALL&lt;br /&gt;
SELECT DBMS_METADATA.GET_GRANTED_DDL(&amp;#039;SYSTEM_GRANT&amp;#039;, USERNAME) || &amp;#039;;&amp;#039; DDL&lt;br /&gt;
FROM DBA_USERS&lt;br /&gt;
where  1=1&lt;br /&gt;
and    default_tablespace not in (&amp;#039;SYSTEM&amp;#039;,&amp;#039;SYSAUX&amp;#039;)&lt;br /&gt;
and    upper(username) like &amp;#039;%&amp;#039;||upper(&amp;#039;&amp;amp;&amp;amp;username&amp;#039;)||&amp;#039;%&amp;#039;&lt;br /&gt;
UNION ALL&lt;br /&gt;
SELECT DBMS_METADATA.GET_GRANTED_DDL(&amp;#039;OBJECT_GRANT&amp;#039;, USERNAME) || &amp;#039;;&amp;#039; DDL&lt;br /&gt;
FROM DBA_USERS&lt;br /&gt;
where  1=1&lt;br /&gt;
and    default_tablespace not in (&amp;#039;SYSTEM&amp;#039;,&amp;#039;SYSAUX&amp;#039;)&lt;br /&gt;
and    upper(username) like &amp;#039;%&amp;#039;||upper(&amp;#039;&amp;amp;&amp;amp;username&amp;#039;)||&amp;#039;%&amp;#039;&lt;br /&gt;
&lt;br /&gt;
spool migration_create_users_grants.sql&lt;br /&gt;
/&lt;br /&gt;
spool off&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Move datafiles between filesystems===&lt;br /&gt;
* [https://blogs.oracle.com/alejandrovargas/moving-a-datafile-from-file-system-to-asm Moving a datafile from File System to ASM (does not have to be ASM!) - oracle.com]&lt;br /&gt;
* [https://docs.oracle.com/database/121/OSTMG/GUID-3B8D0956-0888-452D-A9E4-9FB8D98577E0.htm#OSTMG89997 Moving Data Files Between Oracle ASM (does not have to be ASM!) Using RMAN - oracle.com]&lt;br /&gt;
* [https://oracle-base.com/articles/misc/renaming-or-moving-oracle-files Moving a data file online between filesystems - oracle-base.com]&lt;br /&gt;
====Set the relevant datafile offline====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter database datafile 125 offline;&lt;br /&gt;
alter database datafile 126 offline;&lt;br /&gt;
alter database datafile 127 offline;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Rename the files on the filesystem using o/s commands====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter tablespace ts_thaler_data_offline;&lt;br /&gt;
&lt;br /&gt;
host mv &amp;#039;/cln/tst/ora_data1/clnt/data4/ts_thaler_data_113.dbf&amp;#039; &amp;#039;/cln/tst/ora_data1/clnt/data1/ts_thaler_data_113.dbf&amp;#039;&lt;br /&gt;
host mv &amp;#039;/cln/tst/ora_data1/clnt/data4/ts_thaler_data_114.dbf&amp;#039; &amp;#039;/cln/tst/ora_data1/clnt/data1/ts_thaler_data_114.dbf&amp;#039;&lt;br /&gt;
host mv &amp;#039;/cln/tst/ora_data1/clnt/data4/ts_thaler_data_115.dbf&amp;#039; &amp;#039;/cln/tst/ora_data1/clnt/data1/ts_thaler_data_115.dbf&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Run the relevant alter commands to inform the control files of the new locations====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter database move datafile &amp;#039;/cln/tst/ora_data1/clnt/data4/ts_thaler_data_113.dbf&amp;#039; to &amp;#039;/cln/tst/ora_data1/clnt/data1/ts_thaler_data_113.dbf&amp;#039;&lt;br /&gt;
alter database move datafile &amp;#039;/cln/tst/ora_data1/clnt/data4/ts_thaler_data_114.dbf&amp;#039; to &amp;#039;/cln/tst/ora_data1/clnt/data1/ts_thaler_data_114.dbf&amp;#039;&lt;br /&gt;
alter database move datafile &amp;#039;/cln/tst/ora_data1/clnt/data4/ts_thaler_data_115.dbf&amp;#039; to &amp;#039;/cln/tst/ora_data1/clnt/data1/ts_thaler_data_115.dbf&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Recover the datafiles====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
recover datafile 125;&lt;br /&gt;
recover datafile 126;&lt;br /&gt;
recover datafile 127;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Set the relevant datafile online====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter database datafile 125 online;&lt;br /&gt;
alter database datafile 126 online;&lt;br /&gt;
alter database datafile 127 online;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Check all is well with the datafiles by using an appropriate statement====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 2000 pages 100&lt;br /&gt;
select file_id, file_name, status, online_status from dba_data_files where tablespace_name = &amp;#039;TS_THALER_DATA&amp;#039; order by 2;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Rename a datafile on 12c====&lt;br /&gt;
If you&amp;#039;re lucky enough to be on 12c, it&amp;#039;s one command - no need to offline the datafile!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SQL&amp;gt; alter database move datafile &amp;#039;/oracle/ora_data2/prod/data4/ts_thaler_data_113.dbf&amp;#039; to &amp;#039;/oracle/ora_data2/prod/data3/ts_thaler_data_113.dbf&amp;#039;;&lt;br /&gt;
&lt;br /&gt;
Database altered.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Pass parameter/argument into perl one-liner script from shell===&lt;br /&gt;
Trick? Just use ARGV to pass them in...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
FREQ=$(perl -e &amp;#039;my @CAL=split(&amp;quot;;&amp;quot;,$ARGV[0]);shift @CAL;print $CAL[$ARGV[1]];&amp;#039; -- &amp;quot;$LINE&amp;quot; $offset)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
DUMP_DATE=`perl -MTime::Local -e &amp;#039;print(timelocal(0,$ARGV[0],$ARGV[1],$ARGV[2],$ARGV[3],$ARGV[4]))&amp;#039; -- $MI $HH $DD $MM $YYYY`&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or export the variable from shell and access it via the ENV hash&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
export db=ENDP1&lt;br /&gt;
perl -p -i -e &amp;#039;s!DSMI_LOG.+$!DSMI_LOG           /oracle/$ENV{db}/admin/tdpoerror_$ENV{db}!&amp;#039; ${db}/admin/tdpo.opt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Return epoch seconds in Perl===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
perl -e &amp;#039;print time();&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or to convert a specific day of the year to epoch seconds&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
use POSIX;&lt;br /&gt;
my $epochsecs = mktime(0,0,0, $jday, 0, $year-1900);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or for a specific date (careful though - month is 0-11 not 1-12!...&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
use Time::Local;&lt;br /&gt;
#                          SS MM HH DD MM YYYY&lt;br /&gt;
my $epochsecs = timelocal (30,10,19,03,04,2014);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or more long-winded but delimited by anything...&amp;lt;br /&amp;gt;&lt;br /&gt;
Supply the date/time in any delimited format. Eg. YYYY-MM-DD:HH:MI&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/usr/bin/perl -w&lt;br /&gt;
use Time::Local;&lt;br /&gt;
&lt;br /&gt;
sub date2epoch { &lt;br /&gt;
  my($s) = @_;&lt;br /&gt;
  my($year, $month, $day, $hour, $minute, $second);&lt;br /&gt;
&lt;br /&gt;
  if($s =~ m{^\s*(\d{1,4})\W*0*(\d{1,2})\W*0*(\d{1,2})\W*0*&lt;br /&gt;
                 (\d{0,2})\W*0*(\d{0,2})\W*0*(\d{0,2})}x) {&lt;br /&gt;
    $year = $1;  $month = $2;   $day = $3;&lt;br /&gt;
    $hour = $4;  $minute = $5;  $second = $6;&lt;br /&gt;
    $hour |= 0;  $minute |= 0;  $second |= 0;  # defaults.&lt;br /&gt;
    $year = ($year&amp;lt;100 ? ($year&amp;lt;70 ? 2000+$year : 1900+$year) : $year);&lt;br /&gt;
    return timelocal($second,$minute,$hour,$day,$month-1,$year);  &lt;br /&gt;
  }&lt;br /&gt;
  return -1;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Return epoch seconds in DOS/VBS/Windows===&lt;br /&gt;
Paste this code into epoch.vbs&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
function date2epoch(p_date)&lt;br /&gt;
    date2epoch = DateDiff(&amp;quot;s&amp;quot;, &amp;quot;01/01/1970 00:00:00&amp;quot;, p_date)&lt;br /&gt;
end function&lt;br /&gt;
&lt;br /&gt;
Wscript.Echo date2epoch(Now())&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
and call from a DOS box like this&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cscript //nologo epoch.vbs&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Return date from epoch seconds in Perl===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
perl -e &amp;#039;print scalar (localtime (1243269270))&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Return epoch seconds from julian day number in Perl===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
use POSIX;&lt;br /&gt;
my ($year, $jday) = (2012,60);&lt;br /&gt;
my $epochsecs = mktime(0,0,0, $jday, 0, $year-1900);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Extract specific pieces of a date from an epoch timestamp in Perl===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
use POSIX;&lt;br /&gt;
# return localtime into an array&lt;br /&gt;
my @tm = localtime $epochsecs;&lt;br /&gt;
&lt;br /&gt;
my $yyyymmdd = strftime &amp;quot;%Y%m%d&amp;quot;, @tm;&lt;br /&gt;
print $yyyymmdd.&amp;quot;\n&amp;quot;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Return epoch seconds in Shell (linux)===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
date -d &amp;quot;2014/04/03 18:34:30&amp;quot; &amp;quot;+%s&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Return date from epoch seconds in Shell (linux)===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
date -d @1396542870&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Return epoch seconds in PL/SQL===&lt;br /&gt;
You cannot just use sysdate as that is timezone sensitive... (epoch seconds are in UTC/GMT)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select round((cast(sys_extract_utc(systimestamp) as date) - to_date(&amp;#039;01-JAN-1970 00:00:00&amp;#039;,&amp;#039;DD-MON-YYYY HH24:MI:SS&amp;#039;))*24*60*60) from dual;&lt;br /&gt;
or&lt;br /&gt;
select round((vd.created - to_date(&amp;#039;01-JAN-1970 00:00:00&amp;#039;,&amp;#039;DD-MON-YYYY HH24:MI:SS&amp;#039;))*24*60*60)  created from v$database vd;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
How long has this instance been up (in minutes)?&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select round((cast(sys_extract_utc(systimestamp) as date) - startup_time)*24*60) up_mins from v$instance;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Return date from epoch seconds in SQL===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select to_char(to_date(&amp;#039;19700101&amp;#039;,&amp;#039;YYYYMMDD&amp;#039;) + ((&amp;amp;epoch)/24/60/60),&amp;#039;DD-MON-YYYY HH24:MI:SS&amp;#039;) utc_date from dual;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===A database overview using the sys.plato package===&lt;br /&gt;
 exec plato.help;&lt;br /&gt;
or&lt;br /&gt;
 exec plato.complete(&amp;#039;HTM&amp;#039;);&lt;br /&gt;
&lt;br /&gt;
===List datafiles for a tablespace===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select *&lt;br /&gt;
from   dba_data_files&lt;br /&gt;
where  1=1&lt;br /&gt;
and    tablespace_name =&amp;#039;&amp;amp;ts_name&amp;#039;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Show graph of available and free space in tablespaces===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
-- =============================================================================&lt;br /&gt;
-- File Name    : http://www.oracle-base.com/dba/monitoring/ts_free_space.sql&lt;br /&gt;
-- Author       : Tim Hall&lt;br /&gt;
-- Description  : Displays a list of tablespaces and their used/full status.&lt;br /&gt;
-- Requirements : Access to the DBA views.&lt;br /&gt;
-- Call Syntax  : @ts_free_space.sql&lt;br /&gt;
-- Last Modified: 13-OCT-2012 - Created. Based on ts_full.sql&lt;br /&gt;
--&lt;br /&gt;
-- Modification History&lt;br /&gt;
-- ====================&lt;br /&gt;
-- When      Who               What&lt;br /&gt;
-- ========= ================= =================================================&lt;br /&gt;
-- 13-NOV-13 Stuart Barkley    Added cols free_pct and used_pct&lt;br /&gt;
-- =============================================================================&lt;br /&gt;
SET PAGESIZE 140 lines 180&lt;br /&gt;
COLUMN used_pct FORMAT A11&lt;br /&gt;
COLUMN max_used_pct FORMAT A11&lt;br /&gt;
&lt;br /&gt;
    SELECT tablespace_name                                                                      tablespace_name&lt;br /&gt;
    ,      size_mb                                                                              size_mb&lt;br /&gt;
    ,      free_mb                                                                              free_mb&lt;br /&gt;
    ,      TRUNC((free_mb/size_mb) * 100)                                                       free_pct&lt;br /&gt;
    ,      RPAD(&amp;#039; &amp;#039;|| RPAD(&amp;#039;X&amp;#039;,ROUND((size_mb-free_mb)/size_mb*10,0), &amp;#039;X&amp;#039;),11,&amp;#039;-&amp;#039;)              used_pct&lt;br /&gt;
    ,      max_size_mb                                                                          max_size_mb&lt;br /&gt;
    ,      max_free_mb                                                                          max_free_mb&lt;br /&gt;
    ,      TRUNC((max_free_mb/max_size_mb) * 100)                                               max_free_pct&lt;br /&gt;
    ,      RPAD(&amp;#039; &amp;#039;|| RPAD(&amp;#039;X&amp;#039;,ROUND((max_size_mb-max_free_mb)/max_size_mb*10,0), &amp;#039;X&amp;#039;),11,&amp;#039;-&amp;#039;)  max_used_pct&lt;br /&gt;
    from   (&lt;br /&gt;
           select a.tablespace_name                                         tablespace_name&lt;br /&gt;
           ,      b.size_mb                                                 size_mb&lt;br /&gt;
           ,      a.free_mb                                                 free_mb&lt;br /&gt;
           ,      b.max_size_mb                                             max_size_mb&lt;br /&gt;
           ,      a.free_mb + (b.max_size_mb - b.size_mb)                   max_free_mb&lt;br /&gt;
           from   (&lt;br /&gt;
                  select tablespace_name                                    tablespace_name&lt;br /&gt;
                  ,      trunc(sum(bytes)/1024/1024)                        free_mb&lt;br /&gt;
                  from   dba_free_space&lt;br /&gt;
                  group  by tablespace_name&lt;br /&gt;
                  ) a&lt;br /&gt;
           ,      (&lt;br /&gt;
                  select tablespace_name                                    tablespace_name&lt;br /&gt;
                  ,        trunc(sum(bytes)/1024/1024)                      size_mb&lt;br /&gt;
                  ,        trunc(sum(greatest(bytes,maxbytes))/1024/1024)   max_size_mb&lt;br /&gt;
                  from   dba_data_files&lt;br /&gt;
                  group by tablespace_name&lt;br /&gt;
                  ) b&lt;br /&gt;
           ,      v$instance vi&lt;br /&gt;
           where  a.tablespace_name = b.tablespace_name&lt;br /&gt;
           )&lt;br /&gt;
    order  by tablespace_name;&lt;br /&gt;
&lt;br /&gt;
set lines 80&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Another method for calculating free space in tablespace  using segments===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select df.tablespace_name &amp;quot;Tablespace&amp;quot;&lt;br /&gt;
,      totalusedspace &amp;quot;Used MB&amp;quot;&lt;br /&gt;
,      (df.totalspace - tu.totalusedspace) &amp;quot;Free MB&amp;quot;&lt;br /&gt;
,      df.totalspace &amp;quot;Total MB&amp;quot;&lt;br /&gt;
,      round(100 * ( (df.totalspace - tu.totalusedspace)/ df.totalspace)) &amp;quot;Pct. Free&amp;quot;&lt;br /&gt;
from   (&lt;br /&gt;
       select tablespace_name&lt;br /&gt;
,      round(sum(bytes) / 1048576) totalspace&lt;br /&gt;
       from   dba_data_files&lt;br /&gt;
       group  by tablespace_name&lt;br /&gt;
       ) df&lt;br /&gt;
,      (&lt;br /&gt;
       select round(sum(bytes)/(1024*1024)) totalusedspace&lt;br /&gt;
       ,      tablespace_name&lt;br /&gt;
       from   dba_segments&lt;br /&gt;
       group  by tablespace_name&lt;br /&gt;
       ) tu&lt;br /&gt;
where  df.tablespace_name = tu.tablespace_name;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Work out maximum possible size of a datafile===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select round( (4*1024*1024*value) / (1024*1024*1024) ,2) maxfilesizeingigabytes from v$parameter where name=&amp;#039;db_block_size&amp;#039;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or, as tablespaces can have block sizes differing from that of the init.ora parameter...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select round( (4*1024*1024*block_size) / (1024*1024*1024) ,2) maxfilesizeingigabytes from dba_tablespaces where tablespace_name=&amp;#039;&amp;amp;tablespace_name&amp;#039;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Show size and maxsize at datafile level===&lt;br /&gt;
datafiles&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set pages 100 lines 200&lt;br /&gt;
col file_name for a60&lt;br /&gt;
select sum(bytes)/1024/1024      mbytes_alloc&lt;br /&gt;
,      sum(maxbytes)/1024/1024   mbytes_max&lt;br /&gt;
,      file_name&lt;br /&gt;
from   sys.dba_data_files&lt;br /&gt;
group  by file_name&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
tempfiles&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set pages 100 lines 200&lt;br /&gt;
col file_name for a60&lt;br /&gt;
select sum(bytes)/1024/1024      mbytes_alloc&lt;br /&gt;
,      sum(maxbytes)/1024/1024   mbytes_max&lt;br /&gt;
,      file_name&lt;br /&gt;
from   sys.dba_temp_files&lt;br /&gt;
group  by file_name&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Resize the online redo logfiles===&lt;br /&gt;
Found a more concise, smarter way of doing it [http://www.oracle-wiki.net/startdocshowtorecreateredogrps here] - oracle-wiki.net&amp;lt;br /&amp;gt;&lt;br /&gt;
Switching logs too often? Redolog files too small?&amp;lt;br /&amp;gt;&lt;br /&gt;
* Show current log groups&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 1000&lt;br /&gt;
col group_member for a60&lt;br /&gt;
select l.group#          group_number&lt;br /&gt;
,      (bytes/1024/1024) megs&lt;br /&gt;
,      l.status          group_status&lt;br /&gt;
,      f.member          group_member&lt;br /&gt;
,      l.archived        archived&lt;br /&gt;
,      f.type            file_type&lt;br /&gt;
from   v$log     l&lt;br /&gt;
,      v$logfile f&lt;br /&gt;
where  l.group# = f.group#&lt;br /&gt;
order  by l.group#&lt;br /&gt;
,      f.member&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Create additional (bigger) groups&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
define SID=TIBQFW&lt;br /&gt;
alter database add logfile group 6  &amp;#039;/oracle/&amp;amp;SID/oradata1/redo1.log&amp;#039; size 1G;&lt;br /&gt;
alter database add logfile group 7  &amp;#039;/oracle/&amp;amp;SID/oradata2/redo2.log&amp;#039; size 1G;&lt;br /&gt;
alter database add logfile group 8  &amp;#039;/oracle/&amp;amp;SID/oradata3/redo3.log&amp;#039; size 1G;&lt;br /&gt;
alter database add logfile group 9  &amp;#039;/oracle/&amp;amp;SID/oradata1/redo4.log&amp;#039; size 1G;&lt;br /&gt;
alter database add logfile group 10 &amp;#039;/oracle/&amp;amp;SID/oradata2/redo5.log&amp;#039; size 1G;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or if you use multiple members...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter database add logfile group 6 (&amp;#039;/oracle/&amp;amp;SID/oradata1/redo/redo01a.log&amp;#039;, &amp;#039;/oracle/&amp;amp;SID/oradata1/redo01b&amp;#039;) size 50M;&lt;br /&gt;
alter database add logfile group 7 (&amp;#039;/oracle/&amp;amp;SID/oradata1/redo/redo02a.log&amp;#039;, &amp;#039;/oracle/&amp;amp;SID/oradata1/redo02b&amp;#039;) size 50M;&lt;br /&gt;
alter database add logfile group 8 (&amp;#039;/oracle/&amp;amp;SID/oradata1/redo/redo03a.log&amp;#039;, &amp;#039;/oracle/&amp;amp;SID/oradata1/redo03b&amp;#039;) size 50M;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Switch archivelogs until the new ones are current and the old ones are inactive&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter system switch logfile;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
If the old logs are not yet inactive, checkpoint the database&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter system checkpoint;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Drop the old groups&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter database drop logfile group 1;&lt;br /&gt;
alter database drop logfile group 2;&lt;br /&gt;
alter database drop logfile group 3;&lt;br /&gt;
alter database drop logfile group 4;&lt;br /&gt;
alter database drop logfile group 5;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Increase the existing size of a datafile===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter database datafile &amp;#039;&amp;amp;full_path_of_datafile&amp;#039; resize &amp;amp;new_meg_size.M;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Increase the max size of a tempfile===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter database tempfile &amp;#039;/oracle/ENDP1/oradata90/temp01.dbf&amp;#039; autoextend on maxsize unlimited;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Find out what processes are using the temp tablespace===&lt;br /&gt;
Temporary tablespace is used for sorting query results. Find them with this.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SELECT b.tablespace,b.segfile#,b.segblk#,b.blocks,a.sid,a.serial#,&lt;br /&gt;
a.username,a.osuser, a.status&lt;br /&gt;
FROM v$session a,v$sort_usage b&lt;br /&gt;
WHERE a.saddr = b.session_addr;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Increase the maximum size of a datafile===&lt;br /&gt;
Although this can be set lower than existing size, try not to. It makes the reports look weird!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter database&lt;br /&gt;
      datafile &amp;#039;&amp;amp;full_path_of_datafile&amp;#039;&lt;br /&gt;
      autoextend on&lt;br /&gt;
      maxsize &amp;amp;new_meg_size.m;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Find schemas (users) with objects created outside their default tablespace===&lt;br /&gt;
Indexes could be a notable exception if they are created in an index tablespace&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 200&lt;br /&gt;
col owner           for a20&lt;br /&gt;
col segment_name    for a45&lt;br /&gt;
col tablespace_name for a32&lt;br /&gt;
select owner&lt;br /&gt;
,      segment_name&lt;br /&gt;
,      tablespace_name&lt;br /&gt;
from   dba_segments&lt;br /&gt;
where  exists (select username from dba_users where username = owner)&lt;br /&gt;
and    tablespace_name != (select default_tablespace from dba_users where username = owner)&lt;br /&gt;
and    owner = &amp;#039;&amp;amp;owner&amp;#039;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Add a datafile to a tablespace===&lt;br /&gt;
&amp;#039;unlimited&amp;#039; will default to the maximum datafile size for the current db_block_size&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter tablepace &amp;amp;tablespace_name&lt;br /&gt;
      add datafile &amp;#039;&amp;amp;full_path_of_datafile&amp;#039;&lt;br /&gt;
      size 100M&lt;br /&gt;
      autoextend on&lt;br /&gt;
      next 100M&lt;br /&gt;
      maxsize unlimited&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===List all datafiles with their size===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set pages 1000 lines 2000&lt;br /&gt;
col filetype for a15&lt;br /&gt;
col name for a60&lt;br /&gt;
break on report&lt;br /&gt;
compute sum of gig on report&lt;br /&gt;
&lt;br /&gt;
select filetype&lt;br /&gt;
,      name&lt;br /&gt;
,      gig&lt;br /&gt;
from   (&lt;br /&gt;
       select &amp;#039;datafile&amp;#039; filetype&lt;br /&gt;
       ,      name&lt;br /&gt;
       ,      bytes/1024/1024 gig&lt;br /&gt;
       from   v$datafile&lt;br /&gt;
       union all&lt;br /&gt;
       select &amp;#039;tempfile&amp;#039; filetype&lt;br /&gt;
       ,      name&lt;br /&gt;
       ,      bytes/1024/1024&lt;br /&gt;
       from   v$tempfile&lt;br /&gt;
       union all&lt;br /&gt;
       select &amp;#039;logfile&amp;#039; filetype&lt;br /&gt;
       ,      lf.member &amp;quot;name&amp;quot;&lt;br /&gt;
       ,      l.bytes/1024/1024&lt;br /&gt;
       from   v$logfile lf&lt;br /&gt;
       ,      v$log     l&lt;br /&gt;
       where  1=1&lt;br /&gt;
       and    lf.group# = l.group#&lt;br /&gt;
       ) used&lt;br /&gt;
,      (&lt;br /&gt;
       select sum(bytes)/1024/1024&lt;br /&gt;
       from   dba_free_space&lt;br /&gt;
       ) free&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Database size (How big is my database?)===&lt;br /&gt;
There are different interpretations of what constitutes the size of a database...&amp;lt;br /&amp;gt;&lt;br /&gt;
Is it the space allocated to the datafiles or only the space taken up by the data? Are tempfiles included? Are redo logs included? etc...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 132&lt;br /&gt;
col dbname for a9  heading &amp;quot;Database&amp;quot;&lt;br /&gt;
col dbsize for a15 heading &amp;quot;Size&amp;quot;&lt;br /&gt;
col dbused for a15 heading &amp;quot;Used space&amp;quot;&lt;br /&gt;
col dbfree for a15 heading &amp;quot;Free space&amp;quot;&lt;br /&gt;
with used_space as&lt;br /&gt;
(&lt;br /&gt;
select  bytes&lt;br /&gt;
from    v$datafile&lt;br /&gt;
union   all&lt;br /&gt;
select  bytes&lt;br /&gt;
from    v$tempfile&lt;br /&gt;
union   all&lt;br /&gt;
select  bytes&lt;br /&gt;
from    v$log&lt;br /&gt;
)&lt;br /&gt;
, free_space as&lt;br /&gt;
(&lt;br /&gt;
select sum(bytes) sum_bytes&lt;br /&gt;
from dba_free_space&lt;br /&gt;
)&lt;br /&gt;
select vd.name                                                                                            dbname&lt;br /&gt;
,      round(sum(used_space.bytes)/1024/1024/1024 ) || &amp;#039; GB&amp;#039;                                              dbsize&lt;br /&gt;
,      round(sum(used_space.bytes)/1024/1024/1024 ) - round(free_space.sum_bytes/1024/1024/1024) || &amp;#039; GB&amp;#039; dbused&lt;br /&gt;
,      round(free_space.sum_bytes/1024/1024/1024) || &amp;#039; GB&amp;#039;                                                dbfree&lt;br /&gt;
from   free_space&lt;br /&gt;
,      used_space&lt;br /&gt;
,      v$database vd&lt;br /&gt;
group  by vd.name&lt;br /&gt;
,      free_space.sum_bytes&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Drop datafile from temp tablespace===&lt;br /&gt;
Database is completely stuck because the temporary tablespace has grown to fill all available room.&amp;lt;br /&amp;gt;&lt;br /&gt;
Look around for at least some log files to delete in order to get connected (audit files, sqlnet logs, listener logs)&amp;lt;br /&amp;gt;&lt;br /&gt;
Once connected, change the default temporary tablespace to a small one so we can remove the original.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
create temporary tablespace temp2 tempfile &amp;#039;/oracle/RMANV12/oradata2/temp2.dbf&amp;#039; size 5M;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter database default temporary tablespace temp2;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
I found trying to drop the datafile like this didn&amp;#039;t work, just hung there (probably active tranactions)...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
drop tablespace temp including contents and datafiles;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
So did it like this...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter database tempfile &amp;#039;/oracle/RMANV12/oradata2/temp.dbf&amp;#039; drop including datafiles;&lt;br /&gt;
&lt;br /&gt;
Database altered.&lt;br /&gt;
&lt;br /&gt;
drop tablespace temp including contents and datafiles;&lt;br /&gt;
&lt;br /&gt;
Tablespace dropped.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
... an alternative would be to find the sessions using the temp space and kill them...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select sid, serial#, status from v$session where serial# in (select session_num from v$sort_usage);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Then to be neat and tidy, rename the temp2 tablespace back to temp.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
create temporary tablespace temp tempfile &amp;#039;/oracle/RMANV12/oradata2/temp.dbf&amp;#039; size 256M reuse autoextend on next 128M maxsize 1G;&lt;br /&gt;
alter database default temporary tablespace temp;&lt;br /&gt;
drop tablespace temp2 including contents and datafiles;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Although the last statement will not work until any transactions using it have been rolled back or committed.&lt;br /&gt;
&lt;br /&gt;
===List files that are in hot-backup mode===&lt;br /&gt;
 set lines 100&lt;br /&gt;
 set pages 100&lt;br /&gt;
 col name format a60&lt;br /&gt;
 &lt;br /&gt;
 select df.name&lt;br /&gt;
 ,      b.status&lt;br /&gt;
 ,      to_char(time, &amp;#039;hh24:mi:ss dd/mm/yyyy&amp;#039;) time&lt;br /&gt;
 from   v$datafile   df&lt;br /&gt;
 ,      v$backup     b&lt;br /&gt;
 where  1=1&lt;br /&gt;
 and    df.file# = b.file#&lt;br /&gt;
 and    b.status = &amp;#039;ACTIVE&amp;#039;&lt;br /&gt;
 order  by b.file#;&lt;br /&gt;
&lt;br /&gt;
===Waiting for snapshot control file enqueue===&lt;br /&gt;
Script to identify sessions causing RMAN to hang because of &amp;#039;waiting for snapshot control file enqueue&amp;#039; message&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 2000&lt;br /&gt;
col killer     for a70&lt;br /&gt;
col program    for a20&lt;br /&gt;
col module     for a20&lt;br /&gt;
col action     for a20&lt;br /&gt;
col logon_time for a20&lt;br /&gt;
&lt;br /&gt;
select &amp;#039;alter system disconnect session &amp;#039;&amp;#039;&amp;#039;||s.sid||&amp;#039;,&amp;#039;||s.serial#||&amp;#039;&amp;#039;&amp;#039; immediate;&amp;#039; killer&lt;br /&gt;
,      username&lt;br /&gt;
,      program&lt;br /&gt;
,      module&lt;br /&gt;
,      action&lt;br /&gt;
,      logon_time&lt;br /&gt;
from   v$session s&lt;br /&gt;
,      v$enqueue_lock l&lt;br /&gt;
where  l.sid  = s.sid&lt;br /&gt;
and    l.type = &amp;#039;CF&amp;#039;&lt;br /&gt;
and    l.id1  = 0&lt;br /&gt;
and    l.id2  = 2&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Info on blocking processes===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select s1.username || &amp;#039;@&amp;#039; || s1.machine&lt;br /&gt;
       || &amp;#039; ( SID=&amp;#039; || s1.sid || &amp;#039; )  is blocking &amp;#039;&lt;br /&gt;
       || s2.username || &amp;#039;@&amp;#039; || s2.machine || &amp;#039; ( SID=&amp;#039; || s2.sid || &amp;#039; ) &amp;#039;  blocking_status&lt;br /&gt;
from   v$lock l1&lt;br /&gt;
,      v$session s1&lt;br /&gt;
,      v$lock l2&lt;br /&gt;
,      v$session s2&lt;br /&gt;
where  s1.sid     = l1.sid&lt;br /&gt;
and    s2.sid     = l2.sid&lt;br /&gt;
and    l1.block   = 1&lt;br /&gt;
and    l2.request &amp;gt; 0&lt;br /&gt;
and    l1.id1     = l2.id1&lt;br /&gt;
and    l2.id2     = l2.id2&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
session doing the blocking&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select *&lt;br /&gt;
from  v$lock l1&lt;br /&gt;
where 1=1&lt;br /&gt;
and   block = 1 ;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
sessions being blocked&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select *&lt;br /&gt;
from   v$lock l1&lt;br /&gt;
where  1=1&lt;br /&gt;
and    id2 = 85203&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
info on session doing the blocking&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select row_wait_obj#, row_wait_file#, row_wait_block#, row_wait_row#&lt;br /&gt;
from   v$session&lt;br /&gt;
where  sid = 234&lt;br /&gt;
&lt;br /&gt;
select do.object_name&lt;br /&gt;
,      row_wait_obj#&lt;br /&gt;
,      row_wait_file#&lt;br /&gt;
,      row_wait_block#&lt;br /&gt;
,      row_wait_row#&lt;br /&gt;
,      dbms_rowid.rowid_create ( 1, ROW_WAIT_OBJ#, ROW_WAIT_FILE#, ROW_WAIT_BLOCK#, ROW_WAIT_ROW# ) row_id&lt;br /&gt;
from   v$session   s&lt;br /&gt;
,      dba_objects do&lt;br /&gt;
where  sid=234&lt;br /&gt;
and    s.ROW_WAIT_OBJ# = do.OBJECT_ID;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Show locked objects===&lt;br /&gt;
 set lines 100&lt;br /&gt;
 set pages 999&lt;br /&gt;
 col username   format a20&lt;br /&gt;
 col sess_id    format a10&lt;br /&gt;
 col object     format a25&lt;br /&gt;
 col mode_held  format a10&lt;br /&gt;
 select oracle_username||&amp;#039; (&amp;#039;||s.osuser||&amp;#039;)&amp;#039; username&lt;br /&gt;
 ,      s.sid||&amp;#039;,&amp;#039;||s.serial# sess_id&lt;br /&gt;
 ,      owner||&amp;#039;.&amp;#039;||object_name object&lt;br /&gt;
 ,      object_type&lt;br /&gt;
 ,      decode ( l.block&lt;br /&gt;
               , 0, &amp;#039;Not Blocking&amp;#039;&lt;br /&gt;
               , 1, &amp;#039;Blocking&amp;#039;&lt;br /&gt;
               , 2, &amp;#039;Global&amp;#039;&lt;br /&gt;
               ) status&lt;br /&gt;
 ,      decode ( v.locked_mode&lt;br /&gt;
               , 0, &amp;#039;None&amp;#039;&lt;br /&gt;
               , 1, &amp;#039;Null&amp;#039;&lt;br /&gt;
               , 2, &amp;#039;Row-S (SS)&amp;#039;&lt;br /&gt;
               , 3, &amp;#039;Row-X (SX)&amp;#039;&lt;br /&gt;
               , 4, &amp;#039;Share&amp;#039;&lt;br /&gt;
               , 5, &amp;#039;S/Row-X (SSX)&amp;#039;&lt;br /&gt;
               , 6, &amp;#039;Exclusive&amp;#039;, TO_CHAR(lmode)&lt;br /&gt;
               ) mode_held&lt;br /&gt;
 from   v$locked_object v&lt;br /&gt;
 ,      dba_objects d&lt;br /&gt;
 ,      v$lock l&lt;br /&gt;
 ,      v$session s&lt;br /&gt;
 where  1=1&lt;br /&gt;
 and    v.object_id = d.object_id&lt;br /&gt;
 and    v.object_id = l.id1&lt;br /&gt;
 and    v.session_id = s.sid&lt;br /&gt;
 order  by oracle_username&lt;br /&gt;
 ,	session_id;&lt;br /&gt;
&lt;br /&gt;
===Show which row is locked===&lt;br /&gt;
 select do.object_name&lt;br /&gt;
 ,      row_wait_obj#&lt;br /&gt;
 ,      row_wait_file#&lt;br /&gt;
 ,      row_wait_block#&lt;br /&gt;
 ,      row_wait_row#&lt;br /&gt;
 ,      dbms_rowid.rowid_create (1, ROW_WAIT_OBJ#, ROW_WAIT_FILE#, ROW_WAIT_BLOCK#, ROW_WAIT_ROW#)&lt;br /&gt;
 from   v$session   s&lt;br /&gt;
 ,      dba_objects do&lt;br /&gt;
 where  1=1&lt;br /&gt;
 and    s.ROW_WAIT_OBJ# = do.OBJECT_ID&lt;br /&gt;
 and    sid             = &amp;amp;sid;&lt;br /&gt;
&lt;br /&gt;
===Check what is audited on a database===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set pagesize 100&lt;br /&gt;
set linesize 256&lt;br /&gt;
select audit_option,success,failure from dba_stmt_audit_opts;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===How old is the oldest audit record?===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select extract (day from (systimestamp - min(ntimestamp#))) days_old from aud$;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Check what objects are being audited===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
tti col 60 &amp;#039;Object Audit Options (dba_obj_audit_opts)&amp;#039; skip col 50 &amp;#039;A=By Access, S=By Session. Left=on success, right=on failure&amp;#039; skip 2&lt;br /&gt;
set lines 1000 pages 100&lt;br /&gt;
col alt for a3 head &amp;quot;Alt|er&amp;quot;&lt;br /&gt;
col aud for a3 head &amp;quot;Aud|it&amp;quot;&lt;br /&gt;
col com for a3 head &amp;quot;Com|ent&amp;quot;&lt;br /&gt;
col del for a3 head &amp;quot;Del|ete&amp;quot;&lt;br /&gt;
col gra for a3 head &amp;quot;Gra|nt&amp;quot;&lt;br /&gt;
col ind for a3 head &amp;quot;Ind|ex&amp;quot;&lt;br /&gt;
col ins for a3 head &amp;quot;Ins|ert&amp;quot;&lt;br /&gt;
col loc for a3 head &amp;quot;Lo|ck&amp;quot;&lt;br /&gt;
col ren for a3 head &amp;quot;Ren|ame&amp;quot;&lt;br /&gt;
col sel for a3 head &amp;quot;Sel|ect&amp;quot;&lt;br /&gt;
col upd for a3 head &amp;quot;Upd|ate&amp;quot;&lt;br /&gt;
col ref for a3 head &amp;quot;Ref|rnc&amp;quot;&lt;br /&gt;
col exe for a3 head &amp;quot;Exe|cut&amp;quot;&lt;br /&gt;
col cre for a3 head &amp;quot;Cre|ate&amp;quot;&lt;br /&gt;
col rea for a3 head &amp;quot;Re|ad&amp;quot;&lt;br /&gt;
col wri for a3 head &amp;quot;Wri|te&amp;quot;&lt;br /&gt;
col fbk for a3 head &amp;quot;Fla|sh&amp;quot;&lt;br /&gt;
	&lt;br /&gt;
select *&lt;br /&gt;
from   dba_obj_audit_opts&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Procedure to delete old audit records===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select text from all_source where lower(name)=&amp;#039;purge_audit_trail&amp;#039;;&lt;br /&gt;
&lt;br /&gt;
TEXT&lt;br /&gt;
------------------------------------------------------------------------------------------------&lt;br /&gt;
PROCEDURE purge_audit_trail IS&lt;br /&gt;
BEGIN&lt;br /&gt;
-- set the last archive timestamp&lt;br /&gt;
DBMS_AUDIT_MGMT.SET_LAST_ARCHIVE_TIMESTAMP(&lt;br /&gt;
       audit_trail_type    =&amp;gt; DBMS_AUDIT_MGMT.AUDIT_TRAIL_AUD_STD,&lt;br /&gt;
       last_archive_time   =&amp;gt; systimestamp - interval &amp;#039;365&amp;#039; day,&lt;br /&gt;
       rac_instance_number =&amp;gt; null&lt;br /&gt;
                                          );&lt;br /&gt;
-- purge audit trail till last archive timestamp&lt;br /&gt;
DBMS_AUDIT_MGMT.CLEAN_AUDIT_TRAIL( audit_trail_type =&amp;gt; DBMS_AUDIT_MGMT.AUDIT_TRAIL_AUD_STD&lt;br /&gt;
, use_last_arch_timestamp =&amp;gt; TRUE);&lt;br /&gt;
&lt;br /&gt;
END purge_audit_trail;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Job setup to run the audit purge===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
BEGIN&lt;br /&gt;
sys.dbms_scheduler.create_job(&lt;br /&gt;
    job_name =&amp;gt; &amp;#039;&amp;quot;SYS&amp;quot;.&amp;quot;PURGE_AUDIT_TRAIL_JOB&amp;quot;&amp;#039;,&lt;br /&gt;
    job_type =&amp;gt; &amp;#039;STORED_PROCEDURE&amp;#039;,&lt;br /&gt;
    job_action =&amp;gt; &amp;#039;&amp;quot;SYS&amp;quot;.&amp;quot;PURGE_AUDIT_TRAIL&amp;quot;&amp;#039;,&lt;br /&gt;
    repeat_interval =&amp;gt; &amp;#039;FREQ=DAILY;BYHOUR=20;BYMINUTE=0;BYSECOND=0&amp;#039;,&lt;br /&gt;
    start_date =&amp;gt; to_timestamp_tz(&amp;#039;2012-02-22 Europe/Paris&amp;#039;, &amp;#039;YYYY-MM-DD TZR&amp;#039;),&lt;br /&gt;
    job_class =&amp;gt; &amp;#039;&amp;quot;DEFAULT_JOB_CLASS&amp;quot;&amp;#039;,&lt;br /&gt;
    comments =&amp;gt; &amp;#039;purge audit trails until last archive timestamp&amp;#039;,&lt;br /&gt;
    auto_drop =&amp;gt; FALSE,&lt;br /&gt;
    enabled =&amp;gt; FALSE&lt;br /&gt;
);&lt;br /&gt;
sys.dbms_scheduler.set_attribute( name =&amp;gt; &amp;#039;&amp;quot;SYS&amp;quot;.&amp;quot;PURGE_AUDIT_TRAIL_JOB&amp;quot;&amp;#039;, attribute =&amp;gt; &amp;#039;logging_level&amp;#039;, value =&amp;gt; DBMS_SCHEDULER.LOGGING_OFF);&lt;br /&gt;
sys.dbms_scheduler.set_attribute( name =&amp;gt; &amp;#039;&amp;quot;SYS&amp;quot;.&amp;quot;PURGE_AUDIT_TRAIL_JOB&amp;quot;&amp;#039;, attribute =&amp;gt; &amp;#039;job_weight&amp;#039;, value =&amp;gt; 1);&lt;br /&gt;
sys.dbms_scheduler.enable( &amp;#039;&amp;quot;SYS&amp;quot;.&amp;quot;PURGE_AUDIT_TRAIL_JOB&amp;quot;&amp;#039; );&lt;br /&gt;
END;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===A list of all SIDs in oratab that should restart after a server boot===&lt;br /&gt;
Using awk&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
awk -F: &amp;#039;$NF==&amp;quot;Y&amp;quot; &amp;amp;&amp;amp; $1 !~/[#]/ {print $1}&amp;#039;  /etc/oratab&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Using perl&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
perl -F: -ne &amp;#039;print &amp;quot;$1\n&amp;quot; if /(\w+):(.+):Y$/&amp;#039; /etc/oratab&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Move the admin directories to a new location===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
./all_db_do &amp;quot;alter system set audit_file_dest=&amp;#039;/oracle/&amp;amp;SID/admin/adump&amp;#039; scope=spfile;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
./all_db_do &amp;quot;shutdown immediate&amp;quot;&lt;br /&gt;
&lt;br /&gt;
for db in `awk -F: &amp;#039;NF &amp;amp;&amp;amp; $1 !~/[#*]/ {print $1}&amp;#039;  /etc/oratab`&lt;br /&gt;
do&lt;br /&gt;
    echo $db&lt;br /&gt;
    mkdir -p /oracle/${db}/admin&lt;br /&gt;
    echo &amp;quot;/oracle/${db}/admin created&amp;quot;&lt;br /&gt;
    mv /oracle/admin/${db}/adump /oracle/${db}/admin/&lt;br /&gt;
    mv /oracle/admin/${db}/dpdump /oracle/${db}/admin/&lt;br /&gt;
    echo &amp;quot;Moved /oracle/admin/${db}/adump to /oracle/${db}/admin/&amp;quot;&lt;br /&gt;
done&lt;br /&gt;
&lt;br /&gt;
./all_db_do startup&lt;br /&gt;
&lt;br /&gt;
./all_db_do &amp;quot;create pfile from spfile;&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Check if the Standby database is up-to-date with the primary database===&lt;br /&gt;
 select arch.thread# &amp;quot;Thread&amp;quot;&lt;br /&gt;
 ,      arch.sequence# &amp;quot;Last Sequence Received&amp;quot;&lt;br /&gt;
 ,      appl.sequence# &amp;quot;Last Sequence Applied&amp;quot;&lt;br /&gt;
 ,      (arch.sequence# - appl.sequence#) &amp;quot;Difference&amp;quot;&lt;br /&gt;
 from   (&lt;br /&gt;
        select thread#&lt;br /&gt;
        ,      sequence#&lt;br /&gt;
        from   v$archived_log&lt;br /&gt;
        where  1=1&lt;br /&gt;
        and    ( thread#,first_time ) in (&lt;br /&gt;
                                         select thread#, max(first_time)&lt;br /&gt;
                                         from   v$archived_log&lt;br /&gt;
                                         group  by thread#&lt;br /&gt;
                                         )&lt;br /&gt;
        ) arch&lt;br /&gt;
        ,&lt;br /&gt;
        (&lt;br /&gt;
        select thread#&lt;br /&gt;
        ,      sequence#&lt;br /&gt;
        from   v$log_history&lt;br /&gt;
        where  1=1&lt;br /&gt;
        and    ( thread#,first_time ) in ( select thread# ,max(first_time)&lt;br /&gt;
                                           from   v$log_history&lt;br /&gt;
                                           group  by thread#&lt;br /&gt;
                                          )&lt;br /&gt;
        ) appl&lt;br /&gt;
 where  1=1&lt;br /&gt;
 and    arch.thread# = appl.thread#&lt;br /&gt;
 order  by 1;&lt;br /&gt;
&lt;br /&gt;
===Check for gaps on the Standby database===&lt;br /&gt;
Run this on the standby&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select thread#, low_sequence#, high_sequence# from v$archive_gap;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or run this on the Primary to see the latest generated archive...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select thread#   &amp;quot;Thread&amp;quot;&lt;br /&gt;
,      sequence# &amp;quot;Last sequence generated&amp;quot;&lt;br /&gt;
from   v$archived_log&lt;br /&gt;
where  (thread#, first_time) in ( select thread#, max(first_time)&lt;br /&gt;
                                  from   v$archived_log&lt;br /&gt;
                                  group  by thread#&lt;br /&gt;
                                )&lt;br /&gt;
order  by 1&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
and run this on the standby to check for received but not yet applied logs (this could be normal if a lag has been set)...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select arch.thread# &amp;quot;Thread&amp;quot;&lt;br /&gt;
,      arch.sequence# &amp;quot;Last sequence received&amp;quot;&lt;br /&gt;
,      appl.sequence# &amp;quot;Last sequence applied&amp;quot;&lt;br /&gt;
,      (arch.sequence#-appl.sequence#) &amp;quot;Difference&amp;quot;&lt;br /&gt;
from   (&lt;br /&gt;
       select thread#&lt;br /&gt;
       ,      sequence#&lt;br /&gt;
       from   v$archived_log&lt;br /&gt;
       where  (thread#,first_time ) in (select thread#, max(first_time)&lt;br /&gt;
                                        from   v$archived_log&lt;br /&gt;
                                        group  by thread#&lt;br /&gt;
                                       )&lt;br /&gt;
       ) arch&lt;br /&gt;
,      (&lt;br /&gt;
       select thread#&lt;br /&gt;
       ,      sequence#&lt;br /&gt;
       from   v$log_history&lt;br /&gt;
       where  (thread#,first_time ) in (select thread#, max(first_time)&lt;br /&gt;
                                        from   v$log_history&lt;br /&gt;
                                        group  by thread#&lt;br /&gt;
                                       )&lt;br /&gt;
      ) appl&lt;br /&gt;
where arch.thread# = appl.thread#&lt;br /&gt;
order by 1&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Compare the results from Primary and Secondary to detect possible network problems or other errors in shipping.&lt;br /&gt;
&lt;br /&gt;
===Ignore case-sensitive passwords in 11g (deprecated in 12c)===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter system set SEC_CASE_SENSITIVE_LOGON = false scope=both&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===External table for the Alert log (pre 11g)===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Alert log (11g+)===&lt;br /&gt;
This reads the log.xml file (which contains the same information as alert.log)&amp;lt;br /&amp;gt;&lt;br /&gt;
Show the messages put in the alert log in the last 24 hours&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select substr(MESSAGE_TEXT, 1, 300) message_text&lt;br /&gt;
,      count(*) cnt&lt;br /&gt;
from   X$DBGALERTEXT&lt;br /&gt;
where  1=1&lt;br /&gt;
and    (MESSAGE_TEXT like &amp;#039;%ORA-%&amp;#039; or upper(MESSAGE_TEXT) like &amp;#039;%ERROR%&amp;#039;)&lt;br /&gt;
and    cast(ORIGINATING_TIMESTAMP as DATE) &amp;gt; sysdate - &amp;amp;days_ago/1440&lt;br /&gt;
group  by substr(MESSAGE_TEXT, 1, 300)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
There is also a fixed table X$DBGDIREXT which returns all file and directory names under [diagnostic_dest]/diag directory:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select lpad(&amp;#039; &amp;#039;,lvl,&amp;#039; &amp;#039;)||logical_file file_name&lt;br /&gt;
from   x$dbgdirext&lt;br /&gt;
where  rownum &amp;lt;=20;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Directory paths available in v$diag_info===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 2000&lt;br /&gt;
col name for a35&lt;br /&gt;
col value for a100 wrap&lt;br /&gt;
select * from v$diag_info;&lt;br /&gt;
&lt;br /&gt;
   INST_ID NAME                                VALUE                                                                                                    CON_ID&lt;br /&gt;
---------- ----------------------------------- ---------------------------------------------------------------------------------------------------- ----------&lt;br /&gt;
         1 Diag Enabled                        TRUE                                                                                                          0&lt;br /&gt;
         1 ADR Base                            /cln/prg/ora_bin2/app/oracle                                                                               0&lt;br /&gt;
         1 ADR Home                            /cln/prg/ora_bin2/app/oracle/diag/rdbms/bild/bild                                                          0&lt;br /&gt;
         1 Diag Trace                          /cln/prg/ora_bin2/app/oracle/diag/rdbms/bild/bild/trace                                                    0&lt;br /&gt;
         1 Diag Alert                          /cln/prg/ora_bin2/app/oracle/diag/rdbms/bild/bild/alert                                                    0&lt;br /&gt;
         1 Diag Incident                       /cln/prg/ora_bin2/app/oracle/diag/rdbms/bild/bild/incident                                                 0&lt;br /&gt;
         1 Diag Cdump                          /cln/prg/ora_bin2/app/oracle/diag/rdbms/bild/bild/cdump                                                    0&lt;br /&gt;
         1 Health Monitor                      /cln/prg/ora_bin2/app/oracle/diag/rdbms/bild/bild/hm                                                       0&lt;br /&gt;
         1 Default Trace File                  /cln/prg/ora_bin2/app/oracle/diag/rdbms/bild/bild/trace/bild_ora_44696768.trc                              0&lt;br /&gt;
         1 Active Problem Count                0                                                                                                             0&lt;br /&gt;
         1 Active Incident Count               0                                                                                                             0&lt;br /&gt;
&lt;br /&gt;
11 rows selected.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Find out the names of the active trace files for the running processes===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select pid, program, tracefile from v$process;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Request was to duplicate a large tablespace from production to test environment===&lt;br /&gt;
...but rather than copy the terabytes of data, create the destination tablespace with just the most recent months data&amp;lt;br /&amp;gt;&lt;br /&gt;
====See what the source data looks like====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
col table_owner    for a20&lt;br /&gt;
col table_name     for a30&lt;br /&gt;
col partition_name for a20&lt;br /&gt;
set pages 100 lines 1000&lt;br /&gt;
&lt;br /&gt;
select table_owner&lt;br /&gt;
,      table_name&lt;br /&gt;
,      partition_name&lt;br /&gt;
,      partition_position&lt;br /&gt;
,      tablespace_name&lt;br /&gt;
from   dba_tab_partitions&lt;br /&gt;
where  tablespace_name = &amp;#039;ADS_ARCHIVE&amp;#039;&lt;br /&gt;
order  by 1,2,3,4&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This query produces something like this...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
TABLE_OWNER          TABLE_NAME                     PARTITION_NAME       PARTITION_POSITION TABLESPACE_NAME                &lt;br /&gt;
-------------------- ------------------------------ -------------------- ------------------ ------------------------------ &lt;br /&gt;
ADS_ARCHIVE          BIL_DAY_INV_CTR_ARC            Y2017_Q1_M01_D01                      1 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          BIL_HIS_DETAIL_FAC_ARC         Y2016_Q2_M05_D04                      1 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          BIL_HIS_DETAIL_FAC_ARC         Y2016_Q2_M05_D09                      2 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          BIL_MTH_INV_CTR_ARC            Y2017_Q1_M01_D01                      1 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          FAH_DAY_CBA_BGAAP_ARC          Y2011_Q4_M12_D30                      1 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          FAH_DAY_CBA_BGAAP_ARC          Y2011_Q4_M12_D31                      2 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          FAH_DAY_CBA_IFRS_ARC           Y2011_Q4_M12_D30                      1 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          FAH_DAY_CBA_IFRS_ARC           Y2011_Q4_M12_D31                      2 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          FAH_DAY_MVT_BGAAP_ARC          Y2011_Q4_M12_D30                      1 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          FAH_DAY_MVT_BGAAP_ARC          Y2011_Q4_M12_D31                      2 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          FAH_DAY_MVT_BGAAP_ARC          Y2012_Q1_M03_D31                      3 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          FAH_DAY_MVT_BGAAP_ARC          Y2012_Q2_M04_D01                      4 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          FAH_DAY_MVT_BGAAP_ARC          Y2012_Q4_M10_D12                      5 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          FAH_DAY_MVT_BGAAP_ARC          Y2012_Q4_M10_D13                      6 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          FAH_DAY_MVT_BGAAP_ARC          Y2012_Q4_M10_D14                      7 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          FAH_DAY_MVT_BGAAP_ARC_TST      Y2011_Q4_M12_D30                      1 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          FAH_DAY_MVT_BGAAP_ARC_TST      Y2011_Q4_M12_D31                      2 ADS_ARCHIVE&lt;br /&gt;
...&lt;br /&gt;
ADS_ARCHIVE          SBP_HIS_LINES_ARC              P_LS                                  3 ADS_ARCHIVE                  &lt;br /&gt;
ADS_ARCHIVE          THA_DAY_INV_CTR_ARC            Y2011_Q4_M12_D30                      1 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          THA_DAY_INV_CTR_ARC            Y2011_Q4_M12_D31                      2 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          THA_INV_HEAVY_ARC              Y2011_Q4_M12_D30                      1 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          THA_INV_HEAVY_ARC              Y2011_Q4_M12_D31                      2 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          THA_INV_LIGHT_ARC              Y2011_Q4_M12_D30                      1 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          THA_INV_LIGHT_ARC              Y2012_Q4_M10_D12                      2 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          THA_INV_LIGHT_ARC              Y2012_Q4_M10_D13                      3 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          THA_INV_LIGHT_ARC              Y2012_Q4_M10_D15                      4 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          THA_INV_LIGHT_ARC              Y2012_Q4_M10_D16                      5 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          THA_INV_LIGHT_ARC              Y2012_Q4_M10_D17                      6 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          THA_INV_LIGHT_ARC              Y2012_Q4_M10_D18                      7 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          THA_INV_LIGHT_ARC              Y2012_Q4_M10_D19                      8 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          THA_INV_LIGHT_ARC              Y2012_Q4_M10_D20                      9 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          THA_INV_LIGHT_ARC              Y2012_Q4_M10_D21                     10 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          THA_INV_LIGHT_ARC              Y2012_Q4_M10_D22                     11 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          THA_INV_LIGHT_ARC              Y2012_Q4_M10_D23                     12 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          THA_INV_LIGHT_ARC              Y2012_Q4_M10_D24                     13 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          THA_MTH_INV_CTR_ARC            Y2011_Q4_M12_D30                      1 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          THA_MTH_INV_CTR_ARC            Y2011_Q4_M12_D31                      2 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          THA_MTH_INV_CTR_ARC            Y2013_Q2_M04_D30                      3 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          XBD01_TEMP_HIS_ARC             Y2012_Q4_M12_D31                      1 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          T_RPT_RECO_THA_INV_ACC_ARC     Y2011_Q4_M12_D30                      1 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          T_RPT_RECO_THA_INV_ACC_ARC     Y2011_Q4_M12_D31                      2 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          T_RPT_RECO_THA_INV_MTH_ARC     Y2011_Q4_M12_D30                      1 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          T_RPT_RECO_THA_INV_MTH_ARC     Y2011_Q4_M12_D31                      2 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          XBD01_TEMP_HIS_ARC             Y2012_Q4_M12_D31                      1 ADS_ARCHIVE&lt;br /&gt;
ADS_DBA              FAH_DAY_CBA_BGAAP              Y2016_Q3_M07_D12                   1657 ADS_ARCHIVE&lt;br /&gt;
ADS_DBA              FAH_DAY_CBA_BGAAP              Y2016_Q4_M12_D13                   1811 ADS_ARCHIVE&lt;br /&gt;
ADS_DBA              FAH_DAY_MVT_IFRS               Y2016_Q4_M10_D10                   1654 ADS_ARCHIVE&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Capture the tablespace metadata====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set long 1000000&lt;br /&gt;
select dbms_metadata.get_ddl ( &amp;#039;TABLESPACE&amp;#039;, &amp;#039;ADS_ARCHIVE&amp;#039;) from dual&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
produces...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
CREATE TABLESPACE &amp;quot;ADS_ARCHIVE&amp;quot; DATAFILE&lt;br /&gt;
  &amp;#039;/oracle/tst/ora_data3/adst/ads_archive01.dbf&amp;#039; SIZE 104857600&lt;br /&gt;
  AUTOEXTEND ON NEXT 104857600 MAXSIZE 32000M,&lt;br /&gt;
...&lt;br /&gt;
  &amp;#039;/oracle/tst/ora_data3/adst/ads_archive66.dbf&amp;#039; SIZE 104857600&lt;br /&gt;
  AUTOEXTEND ON NEXT 104857600 MAXSIZE 3200M,&lt;br /&gt;
  LOGGING ONLINE PERMANENT BLOCKSIZE 8192&lt;br /&gt;
  EXTENT MANAGEMENT LOCAL AUTOALLOCATE DEFAULT&lt;br /&gt;
 NOCOMPRESS  SEGMENT SPACE MANAGEMENT AUTO&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Capture the tablespace objects&amp;#039; metadata====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cat&amp;lt;&amp;lt;EOCAT &amp;gt;expdp_adst_ads_archive_metadata.par&lt;br /&gt;
userid=&amp;#039;/ as sysdba&amp;#039;&lt;br /&gt;
dumpfile=adst_ads_archive_metadata.dmp&lt;br /&gt;
logfile=expdp_adst_ads_archive_metadata.log&lt;br /&gt;
tablespaces=ADS_ARCHIVE&lt;br /&gt;
parallel=20&lt;br /&gt;
content=metadata_only&lt;br /&gt;
exclude=statistics&lt;br /&gt;
EOCAT&lt;br /&gt;
&lt;br /&gt;
expdp parfile=expdp_adst_ads_archive_metadata.par&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Find the partitions with data from the most recent month====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cat &amp;lt;&amp;lt;EOCAT&amp;gt;/tmp/adst_ads_archive_partitions.sql&lt;br /&gt;
set termo off echo off lines 1000 feedb off headi off newpa none trims on&lt;br /&gt;
spool /tmp/adst_ads_archive_partitions.lst&lt;br /&gt;
select table_owner||&amp;#039;.&amp;#039;||table_name||&amp;#039;:&amp;#039;||partition_name&lt;br /&gt;
from   dba_tab_partitions&lt;br /&gt;
where  tablespace_name = &amp;#039;ADS_ARCHIVE&amp;#039;&lt;br /&gt;
and    partition_name like &amp;#039;Y2017_Q1_M01%&amp;#039;&lt;br /&gt;
/&lt;br /&gt;
spool off&lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;@/tmp/adst_ads_archive_partitions.sql&amp;quot; | sqlplus / as sysdba&lt;br /&gt;
EOCAT&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
produces...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_CBA_BGAAP_ARC:Y2017_Q1_M01_D07&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_IFRS_ARC:Y2017_Q1_M02_D26&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_IFRS_ARC:Y2017_Q1_M02_D25&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_IFRS_ARC:Y2017_Q1_M02_D19&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_IFRS_ARC:Y2017_Q1_M02_D18&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_IFRS_ARC:Y2017_Q1_M02_D12&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_IFRS_ARC:Y2017_Q1_M02_D11&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_IFRS_ARC:Y2017_Q1_M02_D05&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_BGAAP_ARC:Y2017_Q1_M02_D26&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_BGAAP_ARC:Y2017_Q1_M02_D25&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_BGAAP_ARC:Y2017_Q1_M02_D19&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_BGAAP_ARC:Y2017_Q1_M02_D18&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_BGAAP_ARC:Y2017_Q1_M02_D12&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_BGAAP_ARC:Y2017_Q1_M02_D11&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_BGAAP_ARC:Y2017_Q1_M02_D05&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_BGAAP_ARC:Y2017_Q1_M02_D04&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_BGAAP_ARC:Y2017_Q1_M01_D29&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_BGAAP_ARC:Y2017_Q1_M01_D28&lt;br /&gt;
...&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_BGAAP_ARC:Y2017_Q1_M01_D22&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_BGAAP_ARC:Y2017_Q1_M01_D21&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_BGAAP_ARC:Y2017_Q1_M01_D15&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_BGAAP_ARC:Y2017_Q1_M01_D14&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_BGAAP_ARC:Y2017_Q1_M01_D08&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_BGAAP_ARC:Y2017_Q1_M01_D07&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_BGAAP_ARC:Y2017_Q1_M01_D01&lt;br /&gt;
ADS_ARCHIVE.BIL_MTH_INV_CTR_ARC:Y2017_Q1_M01_D01&lt;br /&gt;
ADS_ARCHIVE.BIL_DAY_INV_CTR_ARC:Y2017_Q1_M01_D01&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_IFRS_ARC:Y2017_Q1_M02_D04&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_IFRS_ARC:Y2017_Q1_M01_D29&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_IFRS_ARC:Y2017_Q1_M01_D28&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_IFRS_ARC:Y2017_Q1_M01_D22&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Export the data in these partitions====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cat&amp;lt;&amp;lt;EOCAT &amp;gt;expdp_adst_ads_archive_partitions.par&lt;br /&gt;
userid=&amp;#039;/ as sysdba&amp;#039;&lt;br /&gt;
dumpfile=adst_ads_archive_Y2017_%U.dmp&lt;br /&gt;
logfile=expdp_adst_ads_archive_Y2017.log&lt;br /&gt;
EOCAT&lt;br /&gt;
&lt;br /&gt;
cat /tmp/adst_ads_archive_partitions.lst | perl -p -i -e &amp;#039;s/^/tables=/&amp;#039;g &amp;gt;&amp;gt;expdp_adst_ads_archive_partitions.par&lt;br /&gt;
&lt;br /&gt;
cat&amp;lt;&amp;lt;EOCAT &amp;gt;&amp;gt;expdp_adst_ads_archive_partitions.par&lt;br /&gt;
parallel=20&lt;br /&gt;
exclude=statistics&lt;br /&gt;
EOCAT&lt;br /&gt;
&lt;br /&gt;
expdp parfile=expdp_adst_ads_archive_partitions.par&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Drop the old tablespace====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
drop tablespace ads_archive including contents and datafiles&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Recreate the tablepspace using the metadata capture above====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
create tablespace &amp;quot;ADS_ARCHIVE&amp;quot;&lt;br /&gt;
datafile &amp;#039;/oracle/tst/ora_data3/adst/ads_archive01.dbf&amp;#039; size 100M autoextend on next 50M maxsize unlimited&lt;br /&gt;
,        &amp;#039;/oracle/tst/ora_data3/adst/ads_archive02.dbf&amp;#039; size 100M autoextend on next 50M maxsize unlimited&lt;br /&gt;
,        &amp;#039;/oracle/tst/ora_data3/adst/ads_archive03.dbf&amp;#039; size 100M autoextend on next 50M maxsize unlimited&lt;br /&gt;
,        &amp;#039;/oracle/tst/ora_data3/adst/ads_archive04.dbf&amp;#039; size 100M autoextend on next 50M maxsize unlimited&lt;br /&gt;
,        &amp;#039;/oracle/tst/ora_data3/adst/ads_archive05.dbf&amp;#039; size 100M autoextend on next 50M maxsize unlimited&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Import the tablespace metadata====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cat&amp;lt;&amp;lt;EOCAT &amp;gt;impdp_adst_ads_archive_metadata.par&lt;br /&gt;
userid=&amp;#039;/ as sysdba&amp;#039;&lt;br /&gt;
dumpfile=adst_ads_archive_metadata.dmp&lt;br /&gt;
logfile=impdp_adst_ads_archive_metadata.log&lt;br /&gt;
EOCAT&lt;br /&gt;
&lt;br /&gt;
impdp parfile=impdp_adst_ads_archive_metadata.par&lt;br /&gt;
&lt;br /&gt;
select &amp;#039;alter index &amp;#039;|| owner||&amp;#039;.&amp;#039;||index_name||&amp;#039; rebuild online parallel 8;&amp;#039;&lt;br /&gt;
from   dba_indexes&lt;br /&gt;
where  status = &amp;#039;UNUSABLE&amp;#039;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Import the last month partition data====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cat&amp;lt;&amp;lt;EOCAT &amp;gt;impdp_adst_ads_archive_partitions.par&lt;br /&gt;
userid=&amp;#039;/ as sysdba&amp;#039;&lt;br /&gt;
dumpfile=adst_ads_archive_Y2017_%U.dmp&lt;br /&gt;
logfile=impdp_adst_ads_archive_Y2017.log&lt;br /&gt;
table_exists_action=append&lt;br /&gt;
parallel=20&lt;br /&gt;
EOCAT&lt;br /&gt;
&lt;br /&gt;
impdp parfile=impdp_adst_ads_archive_partitions.par&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Write to a TCP/IP socket from PL/SQL===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
declare&lt;br /&gt;
 bt_conn               utl_tcp.connection;&lt;br /&gt;
 retval                binary_integer;&lt;br /&gt;
 l_sequence            varchar2(30) := &amp;#039;Sequence Number 101021&amp;#039;;&lt;br /&gt;
begin&lt;br /&gt;
 bt_conn := utl_tcp.open_connection(remote_host =&amp;gt; &amp;#039;10.10.1.1&amp;#039;&lt;br /&gt;
                                   ,remote_port =&amp;gt; 5000&lt;br /&gt;
                                   ,tx_timeout =&amp;gt; 1&lt;br /&gt;
                                   )&lt;br /&gt;
 ;&lt;br /&gt;
 retval := utl_tcp.write_line(bt_conn,l_sequence)&lt;br /&gt;
 ;&lt;br /&gt;
 utl_tcp.flush(bt_conn)&lt;br /&gt;
 ;&lt;br /&gt;
 utl_tcp.close_connection(bt_conn)&lt;br /&gt;
 ;&lt;br /&gt;
exception&lt;br /&gt;
 when others then&lt;br /&gt;
  raise_application_error(-20101, sqlerrm)&lt;br /&gt;
  ; &lt;br /&gt;
  utl_tcp.close_connection(bt_conn)&lt;br /&gt;
  ;&lt;br /&gt;
end&lt;br /&gt;
;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
and read from it using netcat in another session&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
nc -lk 5000&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
produces&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Sequence Number 101021&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Execute a script as a different user===&lt;br /&gt;
Some things have to be done as the user and cannot be done as sys (eg. creating and dropping jobs or create and drop a database link)&amp;lt;br /&amp;gt;&lt;br /&gt;
It is possible to login as the user by saving, changing and resetting his password (using identified by values) but using dbms_sys_sql is another option&amp;lt;br /&amp;gt;&lt;br /&gt;
Create a PL/SQL procedure to drop a db link&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
create or replace procedure drop_dblink ( p_schema_name in varchar2&lt;br /&gt;
                                        , p_dblink      in varchar2&lt;br /&gt;
                                        ) is&lt;br /&gt;
    l_plsql   varchar2(1000);&lt;br /&gt;
    l_cur     number;&lt;br /&gt;
    l_uid     number;&lt;br /&gt;
    l_rc      number;&lt;br /&gt;
begin&lt;br /&gt;
    select  du.user_id&lt;br /&gt;
    into    l_uid&lt;br /&gt;
    from    dba_users du&lt;br /&gt;
    where   du.username = p_schema_name&lt;br /&gt;
    ;&lt;br /&gt;
    plsql := &amp;#039;drop database link &amp;quot;&amp;#039;||p_dblink||&amp;#039;&amp;quot;&amp;#039;;&lt;br /&gt;
    l_cur := sys.dbms_sys_sql.open_cursor;&lt;br /&gt;
    sys.dbms_sys_sql.parse_as_user(&lt;br /&gt;
        c             =&amp;gt; l_cur,&lt;br /&gt;
        statement     =&amp;gt; l_plsql,&lt;br /&gt;
        language_flag =&amp;gt; dbms_sql.native,&lt;br /&gt;
        userid        =&amp;gt; l_uid&lt;br /&gt;
    );&lt;br /&gt;
    l_rc := sys.dbms_sys_sql.execute(l_cur);&lt;br /&gt;
    sys.dbms_sys_sql.close_cursor(l_cur);&lt;br /&gt;
end;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Generate the calls to the procedure with the required parameters&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select &amp;#039;exec drop_dblink (&amp;#039;&amp;#039;&amp;#039;|| owner ||&amp;#039;&amp;#039;&amp;#039;&amp;#039;||&amp;#039;, &amp;#039;||&amp;#039;&amp;#039;&amp;#039;&amp;#039;||db_link||&amp;#039;&amp;#039;&amp;#039;&amp;#039;||&amp;#039;);&amp;#039;&lt;br /&gt;
from   dba_db_links&lt;br /&gt;
where  owner   != &amp;#039;PUBLIC&amp;#039;&lt;br /&gt;
and    db_link like &amp;#039;%FTST%&amp;#039;&lt;br /&gt;
or     db_link like &amp;#039;%HDEV%&amp;#039;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
and this reveals the lines to be executed&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
exec drop_dblink (&amp;#039;USER1&amp;#039;, &amp;#039;DBL_FTST.WORLD&amp;#039;);&lt;br /&gt;
exec drop_dblink (&amp;#039;USER1&amp;#039;, &amp;#039;DBL_HDEV.WORLD&amp;#039;);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Drop the procedure when finished with it&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
drop procedure drop_dblink;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
or do it as an anonymous block in one go...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
declare&lt;br /&gt;
    uid number;&lt;br /&gt;
    sqltext varchar2(1000) := &amp;#039;drop database link &amp;quot;&amp;amp;DB_LINK&amp;quot;&amp;#039;;&lt;br /&gt;
    myint integer;&lt;br /&gt;
begin&lt;br /&gt;
    select user_id into uid from dba_users where username = &amp;#039;&amp;amp;USERNAME&amp;#039;;&lt;br /&gt;
    myint:=sys.dbms_sys_sql.open_cursor();&lt;br /&gt;
    sys.dbms_sys_sql.parse_as_user(myint,sqltext,dbms_sql.native,UID);&lt;br /&gt;
    sys.dbms_sys_sql.close_cursor(myint);&lt;br /&gt;
end;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Handling single quote marks inside SQL statements===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SQL&amp;gt; SELECT &amp;#039;D&amp;#039;&amp;#039;COSTA&amp;#039; name FROM DUAL;&lt;br /&gt;
&lt;br /&gt;
NAME&lt;br /&gt;
-------&lt;br /&gt;
D&amp;#039;COSTA&lt;br /&gt;
&lt;br /&gt;
Alternatively, use the 10g+ quoting method:&lt;br /&gt;
&lt;br /&gt;
SQL&amp;gt; SELECT q&amp;#039;$D&amp;#039;COSTA$&amp;#039; NAME FROM DUAL;&lt;br /&gt;
&lt;br /&gt;
NAME&lt;br /&gt;
-------&lt;br /&gt;
D&amp;#039;COSTA&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Run a script on all databases in /etc/oratab===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
export ORAENV_ASK=NO&lt;br /&gt;
for db in `awk -F: &amp;#039;NF &amp;amp;&amp;amp; $1 !~/[#*]/ {print $1}&amp;#039;  /etc/oratab`&lt;br /&gt;
do&lt;br /&gt;
    echo $db&lt;br /&gt;
    ORACLE_SID=$db&lt;br /&gt;
    . oraenv&lt;br /&gt;
    sqlplus -V&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Schedule a cron job to run on the last day of each month===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
0 23 28-31 * * [ $(date -d +1day +%d) -eq 1 ] &amp;amp;&amp;amp; su - oracle -c &amp;quot;dsmc  arch -server=SO_U_`hostname`_ORX_M_SOL &amp;#039;/oracle/export/PV6/expdp_PV6_D_FULL_`date +\%Y\%m\%d`*&amp;#039;&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===How to tell if a year is a leap year or not - using cal instead of reinventing the wheel===&lt;br /&gt;
Test: Why is Julian day 0, 17th November 1858?&amp;lt;br /&amp;gt;&lt;br /&gt;
Pretty comprehensive answer: [http://h71000.www7.hp.com/wizard/wiz_2315.html here] and [http://mentalfloss.com/article/51370/why-our-calendars-skipped-11-days-1752 here]&amp;lt;br /&amp;gt;&lt;br /&gt;
Also attempts to answer the question why typing &amp;#039;cal 09 1752&amp;#039; on Unix systems looks so odd!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
function leap {&lt;br /&gt;
#  This function tells you if the year passed in as a parameter is a leap year or not...&lt;br /&gt;
if [[ $(cal 2 ${1:-$(date &amp;#039;+%Y&amp;#039;)} | egrep &amp;#039;\&amp;lt;[[:digit:]]{1,2}\&amp;gt;&amp;#039; | wc -w) -eq 29 ]]; then&lt;br /&gt;
    leap=&amp;#039;Y&amp;#039;&lt;br /&gt;
else&lt;br /&gt;
    leap=&amp;#039;N&amp;#039;&lt;br /&gt;
fi&lt;br /&gt;
echo ${leap}&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Reset an expired (and/or locked) user password to the same value===&lt;br /&gt;
Can be used to save user passwords for example in a test environment before destroying them with a copy of production.&amp;lt;br /&amp;gt;&lt;br /&gt;
Simple, quick and easy version. Run this then pick and choose the statements you want to run.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 200 pages 200&lt;br /&gt;
col user_list for a200 head &amp;quot;Expired User List&amp;quot;&lt;br /&gt;
&lt;br /&gt;
select &amp;#039;alter user &amp;#039; ||su.name||&amp;#039; identified by values&amp;#039;||&amp;#039;&amp;#039;&amp;#039;&amp;#039;||spare4||&amp;#039;;&amp;#039;||su.password||&amp;#039;&amp;#039;&amp;#039; account unlock;&amp;#039; user_list&lt;br /&gt;
from   sys.user$ su&lt;br /&gt;
,      dba_users du&lt;br /&gt;
where  1=1&lt;br /&gt;
and    su.name              = du.username&lt;br /&gt;
and    du.oracle_maintained = &amp;#039;N&amp;#039;&lt;br /&gt;
and    (account_status      like &amp;#039;EXPIRED%&amp;#039; or account_status like &amp;#039;%LOCKED&amp;#039;)&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
More industrialised version. Create a package.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
create or replace package dba_utils&lt;br /&gt;
as&lt;br /&gt;
    procedure reset_password ( p_userlist in varchar2 );&lt;br /&gt;
end dba_utils;&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
create or replace package body dba_utils&lt;br /&gt;
as&lt;br /&gt;
&lt;br /&gt;
procedure reset_password ( p_userlist in varchar2 )&lt;br /&gt;
is&lt;br /&gt;
    cursor c1 ( p_userlist in varchar2 ) is&lt;br /&gt;
    select username&lt;br /&gt;
    ,      regexp_substr ( dbms_metadata.get_ddl(&amp;#039;USER&amp;#039;, username), &amp;#039;&amp;#039;&amp;#039;[^&amp;#039;&amp;#039;]+&amp;#039;&amp;#039;&amp;#039; ) pwd&lt;br /&gt;
    from   dba_users&lt;br /&gt;
    where  1=1&lt;br /&gt;
    and    username in upper( p_userlist )&lt;br /&gt;
    ;&lt;br /&gt;
begin&lt;br /&gt;
    dbms_output.enable(null);&lt;br /&gt;
    for r1 in c1 ( p_userlist )&lt;br /&gt;
    loop&lt;br /&gt;
        begin&lt;br /&gt;
            execute immediate &amp;#039;alter user &amp;#039; || r1.username || &amp;#039; account unlock&amp;#039;;&lt;br /&gt;
            execute immediate &amp;#039;alter user &amp;#039; || r1.username || &amp;#039; identified by values &amp;#039; || r1.pwd;&lt;br /&gt;
        exception&lt;br /&gt;
        when others then&lt;br /&gt;
            dbms_output.put_line(&amp;#039;Unable to modify user &amp;#039; || r1.username);&lt;br /&gt;
        end;&lt;br /&gt;
    end loop;&lt;br /&gt;
end reset_password;&lt;br /&gt;
&lt;br /&gt;
end dba_utils;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Call it&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set serveroutput on&lt;br /&gt;
exec dba_utils.reset_password (&amp;#039;STUART&amp;#039;);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Latch, mutex and beyond===&lt;br /&gt;
A fine example of how to write scripts from SQL*Plus that interact with the shell underneath&amp;lt;br /&amp;gt;&lt;br /&gt;
Found [https://andreynikolaev.wordpress.com/demonstration-scripts/cursor_pin_s_contention-sql/ here at andreynikolaev.wordpress.com]&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/*&lt;br /&gt;
     This file is part of demos for &amp;quot;Mutex Internals&amp;quot;  seminar v.04.04.2011&lt;br /&gt;
     Andrey S. Nikolaev (Andrey.Nikolaev@rdtex.ru) &lt;br /&gt;
     https://andreynikolaev.wordpress.com &lt;br /&gt;
 &lt;br /&gt;
     &amp;quot;Cursor: pin S&amp;quot; contention testcase.&lt;br /&gt;
 &lt;br /&gt;
     The script spawn several sessions to induce &amp;quot;Cursor: pin S&amp;quot;, &lt;br /&gt;
     creates AWR snapshots and generates AWR report&lt;br /&gt;
 &lt;br /&gt;
     Beware: The script will restart the test database.&lt;br /&gt;
 &lt;br /&gt;
     usage: sqlplus /nolog @cursor_pin_s_contention.sql &amp;lt;parallelism&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
*/ &lt;br /&gt;
connect / as sysdba&lt;br /&gt;
startup force&lt;br /&gt;
set echo off&lt;br /&gt;
set define %&lt;br /&gt;
set verify off&lt;br /&gt;
set head off&lt;br /&gt;
set linesize 300&lt;br /&gt;
 &lt;br /&gt;
/* spawn parallel processes to create load on mutex */&lt;br /&gt;
spool one_thread.tmp&lt;br /&gt;
select &amp;#039;set verify off&amp;#039; from dual;&lt;br /&gt;
select &amp;#039;alter session set session_cached_cursors = 50;&amp;#039; from dual; &lt;br /&gt;
select &amp;#039;begin for i in 1..1000000 loop&amp;#039; from dual;&lt;br /&gt;
select &amp;#039;      execute immediate &amp;#039;&amp;#039;select 1 from dual where 1=2&amp;#039;&amp;#039;;&amp;#039; from dual;&lt;br /&gt;
select &amp;#039;end loop; end;&amp;#039;||chr(10)||&amp;#039;/&amp;#039; from dual;&lt;br /&gt;
spool off&lt;br /&gt;
 &lt;br /&gt;
/* sleep while AWR initialized */&lt;br /&gt;
host sleep 5&lt;br /&gt;
 &lt;br /&gt;
exec dbms_workload_repository.create_snapshot();&lt;br /&gt;
 &lt;br /&gt;
spool many_threads.tmp&lt;br /&gt;
select &amp;#039;host sqlplus &amp;quot;/ as sysdba&amp;quot; @one_thread.tmp &amp;amp;&amp;#039;&lt;br /&gt;
from dba_objects where rownum &amp;lt;= %1;&lt;br /&gt;
spool off&lt;br /&gt;
 &lt;br /&gt;
@many_threads.tmp&lt;br /&gt;
host sleep 50&lt;br /&gt;
set echo on&lt;br /&gt;
exec dbms_workload_repository.create_snapshot();&lt;br /&gt;
set markup html on&lt;br /&gt;
set head on&lt;br /&gt;
spool mutex_sleep_history.htm&lt;br /&gt;
select to_char(SLEEP_TIMESTAMP,&amp;#039;hh:mi:ss.ff&amp;#039;) SLEEP_TIMESTAMP,MUTEX_ADDR,MUTEX_IDENTIFIER,MUTEX_TYPE,&lt;br /&gt;
       GETS,SLEEPS,REQUESTING_SESSION,BLOCKING_SESSION,&lt;br /&gt;
       LOCATION,MUTEX_VALUE from x$mutex_sleep_history order by sleep_timestamp;&lt;br /&gt;
spool off&lt;br /&gt;
 &lt;br /&gt;
set define &amp;amp;&lt;br /&gt;
set markup html off&lt;br /&gt;
set echo off heading on underline on;&lt;br /&gt;
column inst_num  heading &amp;quot;Inst Num&amp;quot;  new_value inst_num  format 99999;&lt;br /&gt;
column inst_name heading &amp;quot;Instance&amp;quot;  new_value inst_name format a12;&lt;br /&gt;
column db_name   heading &amp;quot;DB Name&amp;quot;   new_value db_name   format a12;&lt;br /&gt;
column dbid      heading &amp;quot;DB Id&amp;quot;     new_value dbid      format 9999999999 just c;&lt;br /&gt;
select d.dbid            dbid&lt;br /&gt;
     , d.name            db_name&lt;br /&gt;
     , i.instance_number inst_num&lt;br /&gt;
     , i.instance_name   inst_name&lt;br /&gt;
  from v$database d,&lt;br /&gt;
       v$instance i;&lt;br /&gt;
define num_days=1;&lt;br /&gt;
define report_type=&amp;#039;html&amp;#039;;&lt;br /&gt;
col end_snap new_value end_snap;&lt;br /&gt;
col begin_snap new_value begin_snap;&lt;br /&gt;
select max(snap_id) end_snap from dba_hist_snapshot where dbid=&amp;amp;dbid;&lt;br /&gt;
select max(snap_id) begin_snap from dba_hist_snapshot where dbid=&amp;amp;dbid and snap_id &amp;lt; &amp;amp;end_snap;&lt;br /&gt;
define report_name=&amp;#039;awr_report.htm&amp;#039;;&lt;br /&gt;
@?/rdbms/admin/awrrpti&lt;br /&gt;
exit&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==shell==&lt;br /&gt;
[http://www.databasejournal.com/features/oracle/article.php/3869076/Alert-Log-Scraping-with-Oracles-ADRCI-Utility.htm Alert Log scraping with ADRCI]&lt;br /&gt;
&lt;br /&gt;
====Count the number of background processes for a particular SID====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SID=RAVJDE1&lt;br /&gt;
ps -ef|cut -c54-100|awk -v SID=$SID &amp;#039;$0 ~ /&amp;#039;$SID&amp;#039;$/ {print}&amp;#039;|wc -l&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or ...this will work with any OS (so long as the process is at the end of the &amp;lt;strong&amp;gt;ps -ef&amp;lt;/strong&amp;gt; or &amp;lt;strong&amp;gt;ps -aux&amp;lt;/strong&amp;gt; listing&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SID=RAVJDE1&lt;br /&gt;
ps -ef|awk -v SID=$SID -F_ &amp;#039;{ $NF ~ /&amp;#039;$SID&amp;#039;$/ {print} }&amp;#039;|wc -l&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Pick the columns you want in the ps listing&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ps -efo user,pid,ppid=MOM -o args&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Find Oracle errors in the most recent DataPump log files====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
00 09 * * * /home/tools/scripts/oracle/dosh &amp;#039;find /oracle/export -name &amp;quot;expdp*log&amp;quot; -mtime -1 -exec grep ORA- {} \; -ls&amp;#039; | mailx -s &amp;#039;Datapump errors for &amp;lt;customer&amp;gt;last night&amp;#039; stuart@domain.com&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Find the 10 largest directories on a particular filesystem====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
du -ag /oracle | sort -nr | head -n 10&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Find the 10 largest files on a particular mount point====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
find /home -size +1G -ls | sort -nr +6 | head -10&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
find /home -xdev -ls | sort -nr +6 | head -10&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Split a file in pieces using sed====&lt;br /&gt;
Using fixed line numbers&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sed -ne &amp;#039;1,12p&amp;#039; file &amp;gt; text.part1&lt;br /&gt;
sed -ne &amp;#039;13,$p&amp;#039; file &amp;gt; text.part2&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Using line with a /pattern/ on it&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sed -e &amp;#039;/hello/q&amp;#039; tt.dat | grep -v hello &amp;gt; text.part1&lt;br /&gt;
sed -n `sed -n &amp;#039;/hello/=&amp;#039; tt.dat`&amp;#039;,$p&amp;#039; tt.dat | grep -v hello &amp;gt; text.part2&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Split a file in pieces using Perl====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
perl -ne &amp;#039;print if 1 .. /marker line/&amp;#039; text.dat &amp;gt;text.part1&lt;br /&gt;
perl -ne &amp;#039;print if /marker line/ .. eof()&amp;#039; text.dat &amp;gt;text.part2&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Find and display RMAN errors in an RMAN log file====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sed -ne &amp;#039;/^RMAN-/,/^$/p&amp;#039;  RMAN_&amp;lt;SID&amp;gt;_&amp;lt;DATE&amp;gt;.log&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==cmd==&lt;br /&gt;
*[http://www.dba-oracle.com/t_scripts_windows_export.htm Database Export - from DBA Oracle (Burleson)]&lt;br /&gt;
==Perl==&lt;br /&gt;
===For all files in a directory, replace a keyword (SSIIDD) in a file with another (a parameter)===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
for i in `ls`&lt;br /&gt;
do&lt;br /&gt;
    perl -p -i -e &amp;#039;s/SSIIDD/&amp;#039;$SID&amp;#039;/g&amp;#039; $i&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Parse tnsnames.ora to get just the service names===&lt;br /&gt;
[[http://stackoverflow.com/questions/12605415/parsing-tnsnames-ora-with-regex-to-just-get-name from here]]&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
perl -ne &amp;#039;print if m/^([^#()\W ][a-zA-Z.]*(?:[.][a-zA-Z]*\s?=)?)/&amp;#039; $TNS_ADMIN/tnsnames.ora&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===and use that to check the listener status===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
for svc in `perl -ne &amp;#039;print if m/^([^#()\W ][a-zA-Z.]*(?:[.][a-zA-Z]*\s?=)?)/&amp;#039; $TNS_ADMIN/tnsnames.ora | sed -e &amp;#039;s/=//&amp;#039;` ;do&lt;br /&gt;
    tnsping $svc&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Stuart</name></author>	</entry>

	<entry>
		<id>https://mailnest.com/dbawiki/index.php?title=Handy_scripts&amp;diff=3371</id>
		<title>Handy scripts</title>
		<link rel="alternate" type="text/html" href="https://mailnest.com/dbawiki/index.php?title=Handy_scripts&amp;diff=3371"/>
				<updated>2018-11-21T11:55:17Z</updated>
		
		<summary type="html">&lt;p&gt;Stuart: /* External table for the Alert log (pre 11g) */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==SQL==&lt;br /&gt;
* [[Database Overview - from idevelopment]] [http://www.idevelopment.info/data/Oracle/DBA_scripts/Database_Administration/dba_snapshot_database_10g.sql online version]&lt;br /&gt;
* [[Extract ddl with &amp;quot;dbms metadata.get ddl&amp;quot;]]&lt;br /&gt;
* [http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:83012348058 Connecting as another user via proxy in SQL*Plus]&lt;br /&gt;
* [http://www.petefinnigan.com/tools.htm Password cracker and role and priv tools from Pete Finnigan]&lt;br /&gt;
* [http://www.oracle.com/technetwork/articles/sql/11g-pivot-097235.html Using pivot tables in SQL - XML and XLS (Excel) also)]&lt;br /&gt;
===List all instances running on a server===&lt;br /&gt;
Sounds simple enough and indeed pre 12.1, is was as easy as either&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ps -ef | grep [p]mon | awk -F_ &amp;#039;{print $NF}&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or this one is safer in case you have an underscore character in your SID name!!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SIDLIST=$(${PS} -ef | ${GREP} [o]ra_pmon | ${AWK} &amp;#039;{print $NF}&amp;#039; | sed -e &amp;#039;s/ora_pmon_//&amp;#039; | egrep -v &amp;#039;grep|///|sed|awk|ASM|^$&amp;#039;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
but now we have the added complication of CDB/PDB (container / pluggable databases) so a fair bit more work is needed!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/ksh&lt;br /&gt;
# ==============================================================================&lt;br /&gt;
# Name         : list_server_db&lt;br /&gt;
# Description  : List all running databases found on a server&lt;br /&gt;
#&lt;br /&gt;
# Parameters   : none&lt;br /&gt;
#&lt;br /&gt;
# Notes        : none&lt;br /&gt;
#&lt;br /&gt;
# Modification History&lt;br /&gt;
# ====================&lt;br /&gt;
# When      Who               What&lt;br /&gt;
# ========= ================= ==================================================&lt;br /&gt;
# 21-DEC-16 Stuart Barkley    Created&lt;br /&gt;
# ==============================================================================&lt;br /&gt;
for db in $(ps -ef | grep [p]mon|awk -F_ &amp;#039;{print $NF}&amp;#039;)&lt;br /&gt;
do&lt;br /&gt;
    export ORACLE_SID=${db}&lt;br /&gt;
    ORAENV_ASK=NO&lt;br /&gt;
    . oraenv &amp;gt;/dev/null 2&amp;gt;&amp;amp;1&lt;br /&gt;
    sqlplus -s / as sysdba&amp;lt;&amp;lt;EOSQL&lt;br /&gt;
set serveroutput on feed off pages 0 head off newpa none&lt;br /&gt;
declare&lt;br /&gt;
    e_col_not_found exception;&lt;br /&gt;
    e_not_mounted   exception;&lt;br /&gt;
    pragma          exception_init(e_not_mounted, -01507);&lt;br /&gt;
    pragma          exception_init(e_col_not_found, -904);&lt;br /&gt;
    l_db_name       varchar2(20);&lt;br /&gt;
    l_database_role varchar2(20);&lt;br /&gt;
    l_cdb           varchar2(20);&lt;br /&gt;
    l_status        varchar2(20);&lt;br /&gt;
    type varchar2_tab is table of varchar2(240) index by binary_integer;&lt;br /&gt;
    t_pdbs          varchar2_tab;&lt;br /&gt;
begin&lt;br /&gt;
    begin&lt;br /&gt;
        dbms_output.enable(null);&lt;br /&gt;
        execute immediate &amp;#039;select name, database_role, cdb from v\$database&amp;#039; into l_db_name, l_database_role, l_cdb;&lt;br /&gt;
        if l_cdb = &amp;#039;YES&amp;#039; then&lt;br /&gt;
            l_status := &amp;#039;CDB&amp;#039;;&lt;br /&gt;
            execute immediate &amp;#039;select name from v\$pdbs&amp;#039; bulk collect into t_pdbs;&lt;br /&gt;
            for i in nvl(t_pdbs.first,1) .. nvl(t_pdbs.last,0)&lt;br /&gt;
            loop&lt;br /&gt;
                dbms_output.put_line (t_pdbs(i)||&amp;#039;:PDB&amp;#039;);&lt;br /&gt;
            end loop;&lt;br /&gt;
        else&lt;br /&gt;
            l_status := &amp;#039;Independent&amp;#039;;  -- col CDB exists but this is not one&lt;br /&gt;
        end if;&lt;br /&gt;
        if l_database_role like &amp;#039;%STANDBY%&amp;#039; then&lt;br /&gt;
            l_status := &amp;#039;Standby&amp;#039;;&lt;br /&gt;
        end if;&lt;br /&gt;
    exception&lt;br /&gt;
    when e_not_mounted then&lt;br /&gt;
        l_status := &amp;#039;Not Mounted&amp;#039;;&lt;br /&gt;
    when e_col_not_found then&lt;br /&gt;
        l_status := &amp;#039;pre12&amp;#039;;&lt;br /&gt;
    end;&lt;br /&gt;
&lt;br /&gt;
    dbms_output.put_line (&amp;#039;${db}&amp;#039;||&amp;#039;:&amp;#039;||l_status);&lt;br /&gt;
&lt;br /&gt;
end;&lt;br /&gt;
/&lt;br /&gt;
EOSQL&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Run a command or script on all databases in tnsnames.ora===&lt;br /&gt;
Very handy if you have a global tnsnames.ora accessible to all clients.&amp;lt;br /&amp;gt;&lt;br /&gt;
So from a client install, this has access to all databases.&amp;lt;br /&amp;gt;&lt;br /&gt;
Any files created can be created on the client so no need to scp to all the machines to recover spool files etc.&amp;lt;br /&amp;gt;&lt;br /&gt;
Downside: Cannot connect as sysdba across tns so password will need to be known for whatever user is used.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/ksh&lt;br /&gt;
TNSNAMES=&amp;quot;./tnsnames.ora&amp;quot;&lt;br /&gt;
[[ ! -r &amp;quot;${TNSNAMES}&amp;quot; ]] &amp;amp;&amp;amp; echo &amp;quot;${TNSNAMES} is not accessible&amp;quot; &amp;amp;&amp;amp; exit 1&lt;br /&gt;
&lt;br /&gt;
SIDLIST=$(perl -ne &amp;#039;print &amp;quot;$1\n&amp;quot; if /(?:SID|SERVICE_NAME)\s*=\s*(\S+?)\)/&amp;#039; ${TNSNAMES}|sort|uniq|xargs)&lt;br /&gt;
for SID in ${SIDLIST}&lt;br /&gt;
do&lt;br /&gt;
    echo &amp;quot;Processing $SID&amp;quot;&lt;br /&gt;
    ls -al | grep &amp;quot;^d&amp;quot; | grep &amp;quot;\_${SID}&amp;quot; &amp;gt;/dev/null&lt;br /&gt;
    if [[ $? -ne 0 ]]; then&lt;br /&gt;
        echo &amp;#039;exit&amp;#039; | sqlplus system/xxxxxx@${SID} @ReviewLite17.1.sql &amp;gt;/dev/null 2&amp;gt;&amp;amp;1&lt;br /&gt;
    else&lt;br /&gt;
        echo &amp;quot;directory already exists so must have done this SID&amp;quot;&lt;br /&gt;
    fi&lt;br /&gt;
done&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Run a command or script on all databases in oratab===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/usr/bin/ksh&lt;br /&gt;
# ==============================================================================&lt;br /&gt;
# Name         : all_db_do&lt;br /&gt;
# Description  : Loops over all the databases in oratab and executes the&lt;br /&gt;
#                specified SQL command - be careful!&lt;br /&gt;
#&lt;br /&gt;
# Parameters   : -v flag for verbose&lt;br /&gt;
#                [-f &amp;lt;filename&amp;gt; | &amp;lt;quoted SQL command to be executed&amp;gt;]&lt;br /&gt;
#&lt;br /&gt;
# Example      : all_db_do &amp;#039;alter system switch logfile;&amp;#039;&lt;br /&gt;
#                all_db_do -f sessions.sql&lt;br /&gt;
#&lt;br /&gt;
# Notes        : none&lt;br /&gt;
#&lt;br /&gt;
# Modification History&lt;br /&gt;
# ====================&lt;br /&gt;
# When      Who               What&lt;br /&gt;
# ========= ================= ==================================================&lt;br /&gt;
# 14-JAN-13 Stuart Barkley    Created&lt;br /&gt;
# 25-FEB-13 Stuart Barkley    Adapt for Solaris&lt;br /&gt;
# 21-MAR-13 Stuart Barkley    Check db is running first&lt;br /&gt;
# 29-APR-13 Stuart Barkley    Added verbose flag processing&lt;br /&gt;
# 24-MAY-13 Stuart Barkley    Wrap / as sysdba in quotes for older versions&lt;br /&gt;
# 23-JUN-16 Stuart Barkley    Add -f to run a file containing sql&lt;br /&gt;
# ==============================================================================&lt;br /&gt;
&lt;br /&gt;
PROGNAME=$(basename $0)&lt;br /&gt;
OS=$(uname -s)&lt;br /&gt;
&lt;br /&gt;
AWK=$(which awk)&lt;br /&gt;
GREP=$(which grep)&lt;br /&gt;
if [[ &amp;quot;${OS}&amp;quot; == &amp;quot;SunOS&amp;quot; ]]; then&lt;br /&gt;
    AWK=/usr/xpg4/bin/awk&lt;br /&gt;
    GREP=/usr/xpg4/bin/grep&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
if [[ ! -r /etc/oratab ]]; then&lt;br /&gt;
    if [[ &amp;quot;${OS}&amp;quot; == &amp;quot;SunOS&amp;quot; ]]; then&lt;br /&gt;
        echo &amp;quot;oratab is not where we want it. Please run &amp;#039;ln -s /var/opt/oracle/oratab /etc/oratab&amp;#039; as root and retry&amp;quot; &amp;amp;&amp;amp; exit 1&lt;br /&gt;
    else&lt;br /&gt;
        echo &amp;quot;Either Oracle is not installed or database is running without an oratab&amp;quot; &amp;amp;&amp;amp; exit 1&lt;br /&gt;
    fi&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
# -------------------------&lt;br /&gt;
# get the arguments, if any&lt;br /&gt;
# -------------------------&lt;br /&gt;
unset VERBOSE&lt;br /&gt;
while getopts &amp;quot;vf:&amp;quot; flag&lt;br /&gt;
do&lt;br /&gt;
    case &amp;quot;$flag&amp;quot; in&lt;br /&gt;
    v) VERBOSE=1;;&lt;br /&gt;
    f) FILE2RUN=$OPTARG;;&lt;br /&gt;
    esac&lt;br /&gt;
done&lt;br /&gt;
shift $((OPTIND-1))&lt;br /&gt;
&lt;br /&gt;
if [[ -z ${FILE2RUN} ]]; then&lt;br /&gt;
    # no file, need an SQL supplied&lt;br /&gt;
    if [[ -z $1 ]]; then&lt;br /&gt;
        echo &amp;quot;Usage: $0 [-v] [-f &amp;lt;filename&amp;gt; | &amp;lt;quoted SQL command to be executed&amp;gt;]&amp;quot;&lt;br /&gt;
        echo &amp;quot;eg: $0 -f sessions.sql&amp;quot;&lt;br /&gt;
        echo &amp;quot;eg: $0 &amp;#039;alter system switch logfile;&amp;#039;&amp;quot;&lt;br /&gt;
        exit 1&lt;br /&gt;
    fi&lt;br /&gt;
    SQL=$1&lt;br /&gt;
elif [[ -s ${FILE2RUN} ]]; then&lt;br /&gt;
    # file supplied and exists&lt;br /&gt;
    SQL=&amp;quot;@${FILE2RUN}&amp;quot;&lt;br /&gt;
else&lt;br /&gt;
    # file supplied, does it exist&lt;br /&gt;
    echo &amp;quot;File ${FILE2RUN} is empty or does not exist&amp;quot;&lt;br /&gt;
    echo &amp;quot;Usage: $0 [-v] [-f &amp;lt;filename&amp;gt; | &amp;lt;quoted SQL command to be executed&amp;gt;]&amp;quot;&lt;br /&gt;
    echo &amp;quot;eg: $0 -f sessions.sql&amp;quot;&lt;br /&gt;
    echo &amp;quot;eg: $0 &amp;#039;alter system switch logfile;&amp;#039;&amp;quot;&lt;br /&gt;
    exit 1&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
export ORAENV_ASK=NO&lt;br /&gt;
&lt;br /&gt;
for db in $(${AWK} -F: &amp;#039;NF &amp;amp;&amp;amp; $1 !~/[#*]/ {print $1}&amp;#039;  /etc/oratab)&lt;br /&gt;
do&lt;br /&gt;
    if ( [[ $1 != &amp;quot;startup&amp;quot; ]] &amp;amp;&amp;amp; [[ $(ps -ef | ${GREP} -c -E [o]ra_pmon_${db}) -eq 0 ]] ); then&lt;br /&gt;
        [[ ! -z &amp;quot;$VERBOSE&amp;quot; ]] &amp;amp;&amp;amp; echo &amp;quot;$db is not running, skipping...&amp;quot;&lt;br /&gt;
        continue&lt;br /&gt;
    fi&lt;br /&gt;
    echo&lt;br /&gt;
    [[ ! -z &amp;quot;$VERBOSE&amp;quot; ]] &amp;amp;&amp;amp; echo &amp;quot;vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv&amp;quot;&lt;br /&gt;
    [[ ! -z &amp;quot;$VERBOSE&amp;quot; ]] &amp;amp;&amp;amp; echo $db&lt;br /&gt;
    ORACLE_SID=$db&lt;br /&gt;
    . oraenv &amp;gt;/dev/null&lt;br /&gt;
    sqlplus -s &amp;quot;/ as sysdba&amp;quot; &amp;lt;&amp;lt;EOSQL&lt;br /&gt;
define SID=$ORACLE_SID&lt;br /&gt;
col comp_name format a50&lt;br /&gt;
col value for a40&lt;br /&gt;
set linesize 1000&lt;br /&gt;
set pagesize 100&lt;br /&gt;
$SQL&lt;br /&gt;
EOSQL&lt;br /&gt;
    [[ ! -z &amp;quot;$VERBOSE&amp;quot; ]] &amp;amp;&amp;amp; echo &amp;quot;^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^&amp;quot;&lt;br /&gt;
done&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
all_db_do &amp;quot;create or replace directory data_pump_dir as &amp;#039;/oracle/export/&amp;amp;SID&amp;#039;;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
all_db_do &amp;quot;archive log list&amp;quot;&lt;br /&gt;
&lt;br /&gt;
all_db_do &amp;quot;shutdown immediate&amp;quot;&lt;br /&gt;
&lt;br /&gt;
all_db_do &amp;#039;alter system set log_archive_dest_1=&amp;quot;location=/oracle/arch/&amp;amp;SID&amp;quot; scope=both;&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Run an SQL command on behalf of another user===&lt;br /&gt;
It can be used to execute any sql command as a specified user provided this procedure is created in sys schema.&amp;lt;br /&amp;gt;&lt;br /&gt;
* not got this working properly yet *&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set serveroutput on&lt;br /&gt;
create or replace procedure run_sql_as_user ( p_schema_name in varchar2&lt;br /&gt;
                                            , p_sql         in varchar2&lt;br /&gt;
                                            ) is&lt;br /&gt;
    l_user_id dba_users.user_id%type;&lt;br /&gt;
    l_cursor  number;&lt;br /&gt;
    l_rc      number;&lt;br /&gt;
begin&lt;br /&gt;
    dbms_output.enable(null);&lt;br /&gt;
    begin&lt;br /&gt;
        select u.user_id&lt;br /&gt;
        into   l_user_id&lt;br /&gt;
        from   dba_users u&lt;br /&gt;
        where  u.username = p_schema_name;&lt;br /&gt;
    exception&lt;br /&gt;
    when no_data_found then&lt;br /&gt;
        raise_application_error (-20001, &amp;#039;Cannot find user &amp;#039;||p_schema_name);&lt;br /&gt;
    end;&lt;br /&gt;
    l_cursor := dbms_sys_sql.open_cursor;&lt;br /&gt;
    dbms_sys_sql.parse_as_user ( c             =&amp;gt; l_cursor&lt;br /&gt;
                               , statement     =&amp;gt; p_sql&lt;br /&gt;
                               , language_flag =&amp;gt; dbms_sql.native&lt;br /&gt;
                               , userid        =&amp;gt; l_user_id&lt;br /&gt;
    );&lt;br /&gt;
    l_rc := dbms_sys_sql.execute(l_cursor);&lt;br /&gt;
    dbms_sys_sql.close_cursor(l_cursor);&lt;br /&gt;
exception&lt;br /&gt;
when others then&lt;br /&gt;
    raise_application_error (-20001, &amp;#039;ERROR: &amp;#039;||sqlerrm);&lt;br /&gt;
end;&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Run a script on all databases listed in tnsnames.ora===&lt;br /&gt;
Can run an SQL command file on all SID/SERVICE found in a tnsnames.ora file. I use this from a client laptop having a global tns file on it.&amp;lt;br /&amp;gt;&lt;br /&gt;
This way it&amp;#039;s not necessary to copy the file onto every host before executing it. Any files created by the script will be created on the client.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/ksh&lt;br /&gt;
&lt;br /&gt;
TNSNAMES=&amp;quot;./tnsnames.ora&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[ ! -r &amp;quot;${TNSNAMES}&amp;quot; ]] &amp;amp;&amp;amp; echo &amp;quot;${TNSNAMES} is not accessible&amp;quot; &amp;amp;&amp;amp; exit 1&lt;br /&gt;
&lt;br /&gt;
SIDLIST=$(perl -ne &amp;#039;print &amp;quot;$1\n&amp;quot; if /(?:SID|SERVICE_NAME)\s*=\s*(\S+?)\)/&amp;#039; ${TNSNAMES}|sort|uniq|xargs)&lt;br /&gt;
for SID in ${SIDLIST}&lt;br /&gt;
do&lt;br /&gt;
    echo &amp;quot;Processing $SID&amp;quot;&lt;br /&gt;
    ls -al | grep &amp;quot;^d&amp;quot; | grep &amp;quot;\_${SID}&amp;quot; &amp;gt;/dev/null&lt;br /&gt;
    if [[ $? -ne 0 ]]; then&lt;br /&gt;
        echo &amp;#039;exit&amp;#039; | sqlplus system/password@${SID} @ReviewLite17.1.sql &amp;gt;/dev/null 2&amp;gt;&amp;amp;1&lt;br /&gt;
    else&lt;br /&gt;
        echo &amp;quot;directory already exists so must have done this SID&amp;quot;&lt;br /&gt;
    fi&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===List invalid objects===&lt;br /&gt;
 set lines 200&lt;br /&gt;
 set pages 200&lt;br /&gt;
 col obj format a40&lt;br /&gt;
 select owner||&amp;#039;.&amp;#039;||object_name obj&lt;br /&gt;
 ,      object_type&lt;br /&gt;
 from   dba_objects&lt;br /&gt;
 where  1=1&lt;br /&gt;
 and    status = &amp;#039;INVALID&amp;#039;;&lt;br /&gt;
===Recompile all invalid objects===&lt;br /&gt;
@?/rdbms/admin/utlrp.sql&lt;br /&gt;
===See how much space is left in the flash recovery area (FRA)===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select name&lt;br /&gt;
,      to_char (space_limit, &amp;#039;999,999,999,999&amp;#039;) as space_limit&lt;br /&gt;
,      to_char (space_limit - space_used + space_reclaimable&lt;br /&gt;
,               &amp;#039;999,999,999,999&amp;#039;)&lt;br /&gt;
           as space_available&lt;br /&gt;
,      round ( (space_used - space_reclaimable) / space_limit * 100, 1)&lt;br /&gt;
           as pct_full&lt;br /&gt;
from   v$recovery_file_dest;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# ==============================================&lt;br /&gt;
# Check FRA to see how much space is reclaimable&lt;br /&gt;
# ==============================================&lt;br /&gt;
fra_reclaim_check() {&lt;br /&gt;
&lt;br /&gt;
LOGFILE=${RMAN_LogDir}/${ORACLE_SID}_`date &amp;#039;+%Y%m&amp;#039;`_${V_SCRIPT}.log&lt;br /&gt;
sqlplus &amp;quot;/ as sysdba&amp;quot; &amp;lt;&amp;lt;EOSQL &amp;gt; /tmp/results.$$&lt;br /&gt;
set vefify off echo off heading off newpage none linesize 1000 echo off&lt;br /&gt;
select &amp;#039;Filesystem:&amp;#039;||name||&lt;br /&gt;
       &amp;#039;; Total(Gb):&amp;#039;||round((space_limit/1073741824),2) ||&lt;br /&gt;
       &amp;#039;; Reclaimable(Gb):&amp;#039;||round((space_reclaimable/1073741824),2) ||&lt;br /&gt;
       &amp;#039;; Reclaimable(%):&amp;#039;||round( ((space_reclaimable/1073741824)/(space_limit/1073741824)*100),2 )&lt;br /&gt;
from   v$recovery_file_dest&lt;br /&gt;
/&lt;br /&gt;
EOSQL&lt;br /&gt;
cat /tmp/results.$$ &amp;gt;&amp;gt; $LOGFILE&lt;br /&gt;
rm /tmp/results.$$&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===How far back can we flashback?===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
col time_now              for a25&lt;br /&gt;
col time_oldest_flashback for a25&lt;br /&gt;
select to_char(sysdate,&amp;#039;DD-MON-YY HH24:MI&amp;#039;)                    time_now&lt;br /&gt;
,      to_char(fdl.oldest_flashback_time, &amp;#039;DD-MON-YY HH24:MI&amp;#039;) time_oldest_flashback&lt;br /&gt;
,      round((sysdate-fdl.oldest_flashback_time)*24,1)         hours_flashback_possible&lt;br /&gt;
from   v$database d&lt;br /&gt;
,      v$flashback_database_log fdl&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===DBA privs tables===&lt;br /&gt;
 DBA_AQ_AGENT_PRIVS&lt;br /&gt;
 DBA_COL_PRIVS&lt;br /&gt;
 DBA_PRIV_AUDIT_OPTS&lt;br /&gt;
 DBA_REPGROUP_PRIVILEGES&lt;br /&gt;
 DBA_ROLE_PRIVS&lt;br /&gt;
 DBA_RSRC_CONSUMER_GROUP_PRIVS&lt;br /&gt;
 DBA_RSRC_MANAGER_SYSTEM_PRIVS&lt;br /&gt;
 DBA_SYS_PRIVS&lt;br /&gt;
 DBA_TAB_PRIVS&lt;br /&gt;
 DBA_WM_SYS_PRIVS&lt;br /&gt;
 DBA_WORKSPACE_PRIVS&lt;br /&gt;
&lt;br /&gt;
===Schedule a shell job===&lt;br /&gt;
 begin&lt;br /&gt;
     dbms_scheduler.create_program ( program_name   =&amp;gt; &amp;#039;myshelljob&amp;#039;&lt;br /&gt;
                                   , program_action =&amp;gt; &amp;#039;/home/oracle/scripts/shell.sh&amp;#039;&lt;br /&gt;
                                   , program_type   =&amp;gt; &amp;#039;EXECUTABLE&amp;#039;&lt;br /&gt;
                                   , comments       =&amp;gt; &amp;#039;Run a shell&amp;#039;&lt;br /&gt;
                                   , enabled        =&amp;gt; TRUE&lt;br /&gt;
                                   );&lt;br /&gt;
 end;&lt;br /&gt;
 /&lt;br /&gt;
===Start the job===&lt;br /&gt;
 begin&lt;br /&gt;
     dbms_sheduler.create_job ( job_name     =&amp;gt; &amp;#039;myshelljob&amp;#039;&lt;br /&gt;
                              , program_name =&amp;gt; &amp;#039;myshelljob&amp;#039;&lt;br /&gt;
                              , start_date   =&amp;gt;&lt;br /&gt;
                              );&lt;br /&gt;
 /&lt;br /&gt;
&lt;br /&gt;
===What statement is a user running?===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select a.sid&lt;br /&gt;
,      a.serial#&lt;br /&gt;
,      b.sql_text&lt;br /&gt;
from   v$session a&lt;br /&gt;
,      v$sqlarea b&lt;br /&gt;
where  a.sql_address = b.address&lt;br /&gt;
and    a.username    = &amp;#039;&amp;amp;username&amp;#039;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===See what statements all users are running===&lt;br /&gt;
Useful to see what is happening when process limit is reached&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 300 pages 1000&lt;br /&gt;
&lt;br /&gt;
col username for a10&lt;br /&gt;
col command for 999 head &amp;quot;CMD&amp;quot;&lt;br /&gt;
col lockwait for a10&lt;br /&gt;
col status for a8&lt;br /&gt;
col schemaname for a12&lt;br /&gt;
col osuser for a10&lt;br /&gt;
col process for a10&lt;br /&gt;
col program for a20&lt;br /&gt;
col machine for a10&lt;br /&gt;
col action for a10&lt;br /&gt;
col module for a10&lt;br /&gt;
col identifier for a10&lt;br /&gt;
col event for a27&lt;br /&gt;
col state for a8&lt;br /&gt;
col service_name for a10&lt;br /&gt;
col serial# for 999999&lt;br /&gt;
&lt;br /&gt;
select a.username&lt;br /&gt;
,      a.command&lt;br /&gt;
,      a.lockwait&lt;br /&gt;
,      a.status&lt;br /&gt;
,      a.schemaname&lt;br /&gt;
,      a.osuser&lt;br /&gt;
,      a.process&lt;br /&gt;
,      a.machine&lt;br /&gt;
,      a.program&lt;br /&gt;
,      a.type&lt;br /&gt;
--,      a.sql_exec_start&lt;br /&gt;
--,      a.plsql_object_id&lt;br /&gt;
--,      a.plsql_subprogram_id&lt;br /&gt;
--,      a.module&lt;br /&gt;
--,      a.action&lt;br /&gt;
,      a.logon_time&lt;br /&gt;
,      a.event&lt;br /&gt;
,      a.wait_time&lt;br /&gt;
,      a.seconds_in_wait&lt;br /&gt;
,      a.state&lt;br /&gt;
--,      a.service_name&lt;br /&gt;
,      a.serial#&lt;br /&gt;
,      b.sql_text&lt;br /&gt;
from   v$session a&lt;br /&gt;
,      v$sqlarea b&lt;br /&gt;
where  a.sql_address = b.address&lt;br /&gt;
order  by a.logon_time desc&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
set lines 80&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===A logminer session===&lt;br /&gt;
Mine all SQL statements in a 10 minute period&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sqlplus / as sysdba&lt;br /&gt;
alter session set nls_date_format = &amp;#039;DD-MON-YYYY HH24:MI:SS&amp;#039;;&lt;br /&gt;
execute dbms_logmnr.start_logmnr ( starttime =&amp;gt; &amp;#039;27-OCT-2009 11:05:00&amp;#039;&lt;br /&gt;
                                 , endtime   =&amp;gt; &amp;#039;27-OCT-2009 11:15:00&amp;#039;&lt;br /&gt;
                                 , options   =&amp;gt; dbms_logmnr.dict_from_online_catalog+dbms_logmnr.continuous_mine&lt;br /&gt;
                                 );&lt;br /&gt;
create table mycontents as select * from v$logmnr_contents;&lt;br /&gt;
execute dbms_logmnr.end_logmnr(); &lt;br /&gt;
&lt;br /&gt;
select * from mycontents;&lt;br /&gt;
&lt;br /&gt;
drop table mycontents;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Huge Pages===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
#&lt;br /&gt;
# hugepages_settings.sh&lt;br /&gt;
#&lt;br /&gt;
# Linux bash script to compute values for the&lt;br /&gt;
# recommended HugePages/HugeTLB configuration&lt;br /&gt;
#&lt;br /&gt;
# Note: This script does calculation for all shared memory&lt;br /&gt;
# segments available when the script is run, no matter it&lt;br /&gt;
# is an Oracle RDBMS shared memory segment or not.&lt;br /&gt;
# Check for the kernel version&lt;br /&gt;
KERN=`uname -r | awk -F. &amp;#039;{ printf(&amp;quot;%d.%d\n&amp;quot;,$1,$2); }&amp;#039;`&lt;br /&gt;
# Find out the HugePage size&lt;br /&gt;
HPG_SZ=`grep Hugepagesize /proc/meminfo | awk {&amp;#039;print $2&amp;#039;}`&lt;br /&gt;
# Start from 1 pages to be on the safe side and guarantee 1 free HugePage&lt;br /&gt;
NUM_PG=1&lt;br /&gt;
# Cumulative number of pages required to handle the running shared memory segments&lt;br /&gt;
for SEG_BYTES in `ipcs -m | awk {&amp;#039;print $5&amp;#039;} | grep &amp;quot;[0-9][0-9]*&amp;quot;`&lt;br /&gt;
do&lt;br /&gt;
   MIN_PG=`echo &amp;quot;$SEG_BYTES/($HPG_SZ*1024)&amp;quot; | bc -q`&lt;br /&gt;
   if [ $MIN_PG -gt 0 ]; then&lt;br /&gt;
      NUM_PG=`echo &amp;quot;$NUM_PG+$MIN_PG+1&amp;quot; | bc -q`&lt;br /&gt;
   fi&lt;br /&gt;
done&lt;br /&gt;
# Finish with results&lt;br /&gt;
case $KERN in&lt;br /&gt;
   &amp;#039;2.4&amp;#039;) HUGETLB_POOL=`echo &amp;quot;$NUM_PG*$HPG_SZ/1024&amp;quot; | bc -q`;&lt;br /&gt;
          echo &amp;quot;Recommended setting: vm.hugetlb_pool = $HUGETLB_POOL&amp;quot; ;;&lt;br /&gt;
   &amp;#039;2.6&amp;#039; | &amp;#039;3.8&amp;#039;) echo &amp;quot;Recommended setting: vm.nr_hugepages = $NUM_PG&amp;quot; ;;&lt;br /&gt;
    *) echo &amp;quot;Unrecognized kernel version $KERN. Exiting.&amp;quot; ;;&lt;br /&gt;
esac&lt;br /&gt;
# End&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Pretty longops listing===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 2000 pages 1000&lt;br /&gt;
col opname for a34 head &amp;quot;Job&amp;quot;&lt;br /&gt;
col message for a60&lt;br /&gt;
col perc_done for a10 head &amp;quot;Done&amp;quot;&lt;br /&gt;
col started for a18&lt;br /&gt;
col killer for a15&lt;br /&gt;
col mins_busy head &amp;quot;Mins busy&amp;quot;&lt;br /&gt;
col mins_left head &amp;quot;Mins left&amp;quot;&lt;br /&gt;
select sid||&amp;#039;,&amp;#039;||serial#                       killer&lt;br /&gt;
,      opname&lt;br /&gt;
,      message&lt;br /&gt;
,      round ((sofar/totalwork),4)*100||&amp;#039;%&amp;#039;    perc_done&lt;br /&gt;
,      to_char(start_time,&amp;#039;DD-MON-YY HH24:MI&amp;#039;) started&lt;br /&gt;
,      floor(elapsed_seconds/60)               mins_busy&lt;br /&gt;
,      ceil(time_remaining/60)                 mins_left&lt;br /&gt;
from   v$session_longops&lt;br /&gt;
where  1=1&lt;br /&gt;
and    sofar     != totalwork&lt;br /&gt;
and    totalwork != 0&lt;br /&gt;
and    opname    like &amp;#039;RMAN%&amp;#039;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select * from v$session where module=&amp;#039;Data Pump Worker&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or attach to the impdp job and it shows percentage done.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Get the SID from v$session_longops and plug it into v$session to check the SQL command details.&lt;br /&gt;
&lt;br /&gt;
Current Running SQLs&lt;br /&gt;
--------------------&lt;br /&gt;
set pages 1000 lines 2000&lt;br /&gt;
col program  format a40&lt;br /&gt;
col sql_text format a130&lt;br /&gt;
&lt;br /&gt;
select s.sid&lt;br /&gt;
,      s.status&lt;br /&gt;
,      s.last_call_et&lt;br /&gt;
,      s.program&lt;br /&gt;
,      sa.sql_id&lt;br /&gt;
,      sa.sql_text&lt;br /&gt;
from   v$session s&lt;br /&gt;
,      v$sqlarea sa&lt;br /&gt;
where  s.sql_id = sa.sql_id&lt;br /&gt;
and    s.sid = &amp;#039;&amp;amp;sid&amp;#039;&lt;br /&gt;
/ &lt;br /&gt;
&lt;br /&gt;
set pages 1000 lines 2000&lt;br /&gt;
col USERNAME for a10&lt;br /&gt;
col OSUSER   for a10&lt;br /&gt;
col MACHINE  for a10&lt;br /&gt;
&lt;br /&gt;
select s.sid&lt;br /&gt;
,      s.serial#&lt;br /&gt;
,      p.spid&lt;br /&gt;
,      s.username&lt;br /&gt;
,      s.osuser&lt;br /&gt;
,      s.status&lt;br /&gt;
,      s.process fg_pid&lt;br /&gt;
,      s.longon_time&lt;br /&gt;
,      s.machine&lt;br /&gt;
,      p.spid bg_pid&lt;br /&gt;
from   gv$session s&lt;br /&gt;
,      gv$process p&lt;br /&gt;
where  s.addr = p.addr&lt;br /&gt;
and    s.sid  = &amp;#039;&amp;amp;sid&amp;#039;&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
$ps -ef | grep &amp;lt;spid&amp;gt;&lt;br /&gt;
&lt;br /&gt;
set pages 1000 lines 2000&lt;br /&gt;
SELECT INST_ID&lt;br /&gt;
,      SID&lt;br /&gt;
,      SERIAL#&lt;br /&gt;
,      SQL_ID&lt;br /&gt;
,      USERNAME&lt;br /&gt;
,      PROGRAM&lt;br /&gt;
,      MACHINE&lt;br /&gt;
,      SERVICE_NAME&lt;br /&gt;
FROM   GV$SESSION&lt;br /&gt;
WHERE  SID IN (&amp;#039;&amp;lt;SID_NO.1&amp;gt;&amp;#039;,&amp;#039;&amp;lt;SID_NO.2&amp;gt;&amp;#039;)&lt;br /&gt;
/&lt;br /&gt;
Active Running SQLs&lt;br /&gt;
--------------------&lt;br /&gt;
set pages 1000 lines 2000&lt;br /&gt;
col SPID     for a10&lt;br /&gt;
col PROGRAM  for a15&lt;br /&gt;
col OSUSER   for a10&lt;br /&gt;
col ACTION   for a10&lt;br /&gt;
col EVENT    for a25&lt;br /&gt;
col SQL_TEXT for a25&lt;br /&gt;
col MACHINE  for a10&lt;br /&gt;
col P1TEXT   for a10 &lt;br /&gt;
col P2TEXT   for a10&lt;br /&gt;
col P3TEXT   for a10  &lt;br /&gt;
SELECT b.sid&lt;br /&gt;
,      b.serial#&lt;br /&gt;
,      a.spid&lt;br /&gt;
,      b.sql_id&lt;br /&gt;
,      b.program&lt;br /&gt;
,      b.osuser&lt;br /&gt;
,      b.machine&lt;br /&gt;
,      b.type&lt;br /&gt;
,      b.event&lt;br /&gt;
,      b.action&lt;br /&gt;
,      b.p1text&lt;br /&gt;
,      b.p2text&lt;br /&gt;
,      b.p3text&lt;br /&gt;
,      b.state&lt;br /&gt;
,      c.sql_text&lt;br /&gt;
,      b.logon_time&lt;br /&gt;
FROM   v$process a&lt;br /&gt;
,      v$session b&lt;br /&gt;
,      v$sqltext c&lt;br /&gt;
WHERE  a.addr           = b.paddr&lt;br /&gt;
AND    b.sql_hash_value = c.hash_value&lt;br /&gt;
AND    b.STATUS         = &amp;#039;ACTIVE&amp;#039;&lt;br /&gt;
AND    b.sid            = &amp;#039;&amp;amp;sid&amp;#039;&lt;br /&gt;
ORDER  BY a.spid&lt;br /&gt;
,      c.piece&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
OR - Use the below Query &lt;br /&gt;
&lt;br /&gt;
Longops.sql&lt;br /&gt;
----------- &lt;br /&gt;
set pages 50000 lines 32767&lt;br /&gt;
col OPNAME for a10&lt;br /&gt;
col SID form 9999&lt;br /&gt;
col SERIAL form 9999999&lt;br /&gt;
col PROGRAM for a10&lt;br /&gt;
col USERNAME for a10&lt;br /&gt;
col SQL_TEXT for a40&lt;br /&gt;
col START_TIME for a10&lt;br /&gt;
col LAST_UPDATE_TIME for a10&lt;br /&gt;
col TARGET for a25&lt;br /&gt;
col MESSAGE for a25&lt;br /&gt;
&lt;br /&gt;
alter session set nls_date_format = &amp;#039;DD-MM-YYYY HH24:MI:SS&amp;#039;;&lt;br /&gt;
&lt;br /&gt;
SELECT l.inst_id,l.sid, l.serial#, l.sql_id, l.opname, l.username, l.target, l.sofar, l.totalwork, l.start_time,l.last_update_time,round(l.time_remaining/60,2) &amp;quot;REMAIN MINS&amp;quot;, round(l.elapsed_seconds/60,2) &amp;quot;ELAPSED MINS&amp;quot;, round((l.time_remaining+l.elapsed_seconds)/60,2) &amp;quot;TOTAL MINS&amp;quot;, ROUND(l.SOFAR/l.TOTALWORK*100,2) &amp;quot;%_COMPLETE&amp;quot;, l.message,s.sql_text &lt;br /&gt;
FROM gv$session_longops l &lt;br /&gt;
LEFT OUTER JOIN v$sql s on s.hash_value=l.sql_hash_value and s.address=l.sql_address and s.child_number=0&lt;br /&gt;
WHERE l.OPNAME NOT LIKE &amp;#039;RMAN%&amp;#039; AND l.OPNAME NOT LIKE &amp;#039;%aggregate%&amp;#039; AND l.TOTALWORK != 0 AND l.sofar&amp;lt;&amp;gt;l.totalwork AND l.time_remaining &amp;gt; 0&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Apply the database patch after the ORACLE_HOME has been patched===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ORAENV_ASK=NO&lt;br /&gt;
export ORACLE_SID=$1&lt;br /&gt;
. oraenv&lt;br /&gt;
&lt;br /&gt;
sqlplus /nolog &amp;lt;&amp;lt;EOSQL&lt;br /&gt;
connect / as sysdba&lt;br /&gt;
startup&lt;br /&gt;
@?/rdbms/admin/catbundle.sql psu apply&lt;br /&gt;
@?/rdbms/admin/utlrp.sql&lt;br /&gt;
purge dba_recyclebin;&lt;br /&gt;
&lt;br /&gt;
prompt check patch apply...&lt;br /&gt;
set lines 150&lt;br /&gt;
col action_time for a50&lt;br /&gt;
col comp_name for a50&lt;br /&gt;
col comments for a50&lt;br /&gt;
&lt;br /&gt;
select action_time,action,comments from sys.registry\$history where trunc(action_time) = trunc(sysdate);&lt;br /&gt;
select comp_name,version,status,modified from dba_registry;&lt;br /&gt;
exit&lt;br /&gt;
EOSQL&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Show how much archivelog data is generated per day===&lt;br /&gt;
A companion script for &amp;#039;how many log switches in a day&amp;#039;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
col orderby noprint&lt;br /&gt;
select trunc(first_time) orderby&lt;br /&gt;
,      to_char(first_time,&amp;#039;DD-MON-YYYY&amp;#039;) &amp;quot;Date&amp;quot;&lt;br /&gt;
,      round(sum(bytes/1024/1024/1024),2) arch_logs_gigs&lt;br /&gt;
from (&lt;br /&gt;
    select unique (blocks * block_size) bytes,&lt;br /&gt;
    thread#,&lt;br /&gt;
    sequence#,&lt;br /&gt;
    resetlogs_change#,&lt;br /&gt;
    first_time&lt;br /&gt;
    from v$archived_log&lt;br /&gt;
)&lt;br /&gt;
group by trunc(first_time)&lt;br /&gt;
,      to_char(first_time, &amp;#039;DD-MON-YYYY&amp;#039;)&lt;br /&gt;
order by trunc(first_time) desc&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Abort a hanging database even when sysdba cannot connect===&lt;br /&gt;
Unable to connect to database with sqlplus / as sysdba because audit file cannot be created?&lt;br /&gt;
* [http://tech.e2sn.com/oracle/troubleshooting/hang/how-to-log-on-even-when-sysdba-can-t-do-so tech.e2sn.com]&lt;br /&gt;
* [http://blog.dbi-services.com/oracle-is-hanging-dont-forget-hanganalyze-and-systemstate/ blog.dbi-services.com]&lt;br /&gt;
Instead of just killing the pmon process, there is a kinder (and more useful) way to kill the database.&amp;lt;br /&amp;gt;&lt;br /&gt;
Use the hidden, undocumented &amp;#039;prelim&amp;#039; switch parameter to sqlplus to make a connection to the database without creating SGA session data structures.&amp;lt;br /&amp;gt;&lt;br /&gt;
It can be very useful for hang analysis so the possible cause can be found after the database has been restarted.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sqlplus -prelim / as sysdba&lt;br /&gt;
oradebug unlimit&lt;br /&gt;
oradebug hanganalyze 3&lt;br /&gt;
oradebug setmypid              -- or oradebug setorapname diag&lt;br /&gt;
oradebug dump ashdumpseconds 30&lt;br /&gt;
oradebug dump systemstate 10   -- or oradebug dump systemstate 266&lt;br /&gt;
oradebug tracefile_name&lt;br /&gt;
shutdown abort&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Lists Oracle session with kill session statement all ready to go===&lt;br /&gt;
disconnect attempts to kill the o/s processes too. kill doesn&amp;#039;t.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
col killer for a60&lt;br /&gt;
col osuser for a12&lt;br /&gt;
col logon  for a23&lt;br /&gt;
col spid   for a8&lt;br /&gt;
col username for a15&lt;br /&gt;
col program for a50&lt;br /&gt;
set lines 2000&lt;br /&gt;
select &amp;#039;alter system disconnect session &amp;#039;&amp;#039;&amp;#039;||s.sid||&amp;#039;,&amp;#039;||s.serial#||&amp;#039;&amp;#039;&amp;#039; immediate;&amp;#039; killer&lt;br /&gt;
,      s.inst_id&lt;br /&gt;
,      to_char(s.logon_time,&amp;#039;DD-MON-YY HH24:MI:SS&amp;#039;) logon&lt;br /&gt;
,      sci.osuser&lt;br /&gt;
,      p.spid&lt;br /&gt;
,      s.username&lt;br /&gt;
,      s.program&lt;br /&gt;
from   gv$session s&lt;br /&gt;
,      gv$session_connect_info sci&lt;br /&gt;
,      gv$process p&lt;br /&gt;
where  1=1&lt;br /&gt;
and    p.addr     = s.paddr&lt;br /&gt;
and    p.inst_id  = s.inst_id&lt;br /&gt;
and    s.sid      = sci.sid&lt;br /&gt;
and    s.serial#  = sci.serial#&lt;br /&gt;
and    s.type    != &amp;#039;BACKGROUND&amp;#039;&lt;br /&gt;
and    sci.osuser = &amp;#039;oraibm&amp;#039;&lt;br /&gt;
order  by s.logon_time desc&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
KILLER                                                          INST_ID LOGON                   OSUSER       SPID     USERNAME        PROGRAM&lt;br /&gt;
------------------------------------------------------------ ---------- ----------------------- ------------ -------- --------------- --------------------------------------------------&lt;br /&gt;
alter system disconnect session &amp;#039;490,33947&amp;#039; immediate;                1 23-JUN-16 13:30:53      oraibm       23205    SYS             sqlplus@benouerp07 (TNS V1-V3)&lt;br /&gt;
alter system disconnect session &amp;#039;490,33947&amp;#039; immediate;                1 23-JUN-16 13:30:53      oraibm       23205    SYS             sqlplus@benouerp07 (TNS V1-V3)&lt;br /&gt;
alter system disconnect session &amp;#039;490,33947&amp;#039; immediate;                1 23-JUN-16 13:30:53      oraibm       23205    SYS             sqlplus@benouerp07 (TNS V1-V3)&lt;br /&gt;
alter system disconnect session &amp;#039;490,33947&amp;#039; immediate;                1 23-JUN-16 13:30:53      oraibm       23205    SYS             sqlplus@benouerp07 (TNS V1-V3)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===How much space is being used by a guaranteed restore point?===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
show parameter recovery&lt;br /&gt;
set numwi 15&lt;br /&gt;
set lines 200&lt;br /&gt;
col name for a40&lt;br /&gt;
col time for a23&lt;br /&gt;
col gigs_limit head &amp;quot;Max (but check df -g also!)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
select name&lt;br /&gt;
,      time&lt;br /&gt;
,      round(storage_size/1024/1024/1024,2) gigs_used&lt;br /&gt;
from   v$restore_point&lt;br /&gt;
where  1=1&lt;br /&gt;
and    guarantee_flashback_database = &amp;#039;YES&amp;#039;&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
select * from v$flash_recovery_area_usage&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
select name&lt;br /&gt;
,      round(space_used/1024/1024/1024,2) gigs_used&lt;br /&gt;
,      round(space_limit/1024/1024/1024,2) gigs_limit&lt;br /&gt;
,      space_reclaimable&lt;br /&gt;
,      number_of_files&lt;br /&gt;
from v$recovery_file_dest&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Get statistics for LOB columns in a table===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select &lt;br /&gt;
  max(dbms_lob.getlength(lob_content)) max_len&lt;br /&gt;
, avg(dbms_lob.getlength(lob_content)) avg_len&lt;br /&gt;
, min(dbms_lob.getlength(lob_content)) min_len&lt;br /&gt;
, sum(case when dbms_lob.getlength(lob_content) &amp;lt;= 4000 then 1&lt;br /&gt;
else 0 end) &amp;quot;&amp;lt;4k&amp;quot;&lt;br /&gt;
, sum(case when dbms_lob.getlength(lob_content) &amp;gt; 4000 then 1&lt;br /&gt;
else 0 end) &amp;quot;&amp;gt;4k&amp;quot;&lt;br /&gt;
, sum(case when dbms_lob.getlength(lob_content) is null then 1 else&lt;br /&gt;
0 end) &amp;quot;is null&amp;quot;&lt;br /&gt;
from &amp;amp;tablename&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===badprivs.sql===&lt;br /&gt;
Check to see if any ordinary users have privileges / access / grants / rights they should not have&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select grantee, privilege, admin_option&lt;br /&gt;
from   sys.dba_sys_privs&lt;br /&gt;
where  (       privilege like &amp;#039;% ANY %&amp;#039;&lt;br /&gt;
        or     privilege in (&amp;#039;BECOME USER&amp;#039;, &amp;#039;UNLIMITED TABLESPACE&amp;#039;)&lt;br /&gt;
        or     admin_option = &amp;#039;YES&amp;#039;&lt;br /&gt;
       )&lt;br /&gt;
and    grantee not in (&amp;#039;SYS&amp;#039;, &amp;#039;SYSTEM&amp;#039;, &amp;#039;OUTLN&amp;#039;, &amp;#039;AQ_ADMINISTRATOR_ROLE&amp;#039;,&lt;br /&gt;
                      &amp;#039;DBA&amp;#039;, &amp;#039;EXP_FULL_DATABASE&amp;#039;, &amp;#039;IMP_FULL_DATABASE&amp;#039;,&lt;br /&gt;
                      &amp;#039;OEM_MONITOR&amp;#039;, &amp;#039;CTXSYS&amp;#039;, &amp;#039;DBSNMP&amp;#039;, &amp;#039;IFSSYS&amp;#039;,&lt;br /&gt;
                      &amp;#039;IFSSYS$CM&amp;#039;, &amp;#039;MDSYS&amp;#039;, &amp;#039;ORDPLUGINS&amp;#039;, &amp;#039;ORDSYS&amp;#039;,&lt;br /&gt;
                      &amp;#039;TIMESERIES_DBA&amp;#039;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Generate a list of tablespaces ready for a migration===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set echo off&lt;br /&gt;
set lines 300&lt;br /&gt;
set pages 0&lt;br /&gt;
Set headi off&lt;br /&gt;
set feedb off&lt;br /&gt;
set long 32000&lt;br /&gt;
&lt;br /&gt;
spool migration_create_target_tablespaces.sql&lt;br /&gt;
&lt;br /&gt;
exec dbms_metadata.set_transform_param(dbms_metadata.session_transform,&amp;#039;SQLTERMINATOR&amp;#039;,TRUE);&lt;br /&gt;
select DBMS_METADATA.GET_DDL(&amp;#039;TABLESPACE&amp;#039;,tablespace_name) from dba_tablespaces&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
spool off&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===List the privileges assigned to users on directories===&lt;br /&gt;
table_name is the name of the directory...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select grantor&lt;br /&gt;
,      grantee&lt;br /&gt;
,      table_schema&lt;br /&gt;
,      table_name&lt;br /&gt;
,      privilege&lt;br /&gt;
from   all_tab_privs&lt;br /&gt;
where  table_name = &amp;#039;DATA_PUMP_DIR&amp;#039;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===List the privileges assigned to users on packages/procedures===&lt;br /&gt;
table_name is the name of the package...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select grantor&lt;br /&gt;
,      grantee&lt;br /&gt;
,      table_schema&lt;br /&gt;
,      table_name&lt;br /&gt;
,      privilege&lt;br /&gt;
from   all_tab_privs&lt;br /&gt;
where  upper(table_name) like upper(&amp;#039;%UTL_FILE%&amp;#039;)&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===List the system privileges assigned to a user (used to copy user as or clone user as)===&lt;br /&gt;
Maybe this one is better [[Extract ddl with &amp;quot;dbms metadata.get ddl&amp;quot;]]&lt;br /&gt;
&lt;br /&gt;
 SELECT LPAD(&amp;#039; &amp;#039;, 2*level) || granted_role &amp;quot;USER PRIVS&amp;quot;&lt;br /&gt;
 FROM (&lt;br /&gt;
   SELECT NULL grantee,  username granted_role&lt;br /&gt;
   FROM dba_users&lt;br /&gt;
   WHERE username LIKE UPPER(&amp;#039;%&amp;amp;uname%&amp;#039;)&lt;br /&gt;
   UNION&lt;br /&gt;
   SELECT grantee, granted_role&lt;br /&gt;
   FROM dba_role_privs&lt;br /&gt;
   UNION&lt;br /&gt;
   SELECT grantee, privilege&lt;br /&gt;
   FROM dba_sys_privs)&lt;br /&gt;
 START WITH grantee IS NULL&lt;br /&gt;
 CONNECT BY grantee = prior granted_role;&lt;br /&gt;
&lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
 SELECT path&lt;br /&gt;
 FROM (&lt;br /&gt;
   SELECT grantee,&lt;br /&gt;
          sys_connect_by_path(privilege, &amp;#039;:&amp;#039;)||&amp;#039;:&amp;#039;||grantee path&lt;br /&gt;
   FROM (&lt;br /&gt;
     SELECT grantee, privilege, 0 role&lt;br /&gt;
     FROM dba_sys_privs&lt;br /&gt;
     UNION ALL&lt;br /&gt;
     SELECT grantee, granted_role, 1 role&lt;br /&gt;
     FROM dba_role_privs)&lt;br /&gt;
   CONNECT BY privilege=prior grantee&lt;br /&gt;
   START WITH role = 0)&lt;br /&gt;
 WHERE grantee IN (&lt;br /&gt;
    SELECT username&lt;br /&gt;
    FROM dba_users&lt;br /&gt;
    WHERE lock_date IS NULL&lt;br /&gt;
    AND password != &amp;#039;EXTERNAL&amp;#039;&lt;br /&gt;
    AND username != &amp;#039;SYS&amp;#039;)&lt;br /&gt;
 OR grantee=&amp;#039;PUBLIC&amp;#039;&lt;br /&gt;
&lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
for a migration from 10g...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set headi off&lt;br /&gt;
set feedb off&lt;br /&gt;
set long  9999999&lt;br /&gt;
set pages 0&lt;br /&gt;
set lines 300&lt;br /&gt;
&lt;br /&gt;
spool migration_create_target_users_grants.sql&lt;br /&gt;
&lt;br /&gt;
select dbms_metadata.get_ddl(&amp;#039;USER&amp;#039;, username) || &amp;#039;;&amp;#039; ddl&lt;br /&gt;
from dba_users&lt;br /&gt;
where  1=1&lt;br /&gt;
and    username like upper(&amp;#039;%&amp;amp;&amp;amp;USER_NAME%&amp;#039;)&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
select &amp;#039;grant &amp;#039;||privilege|| &amp;#039; to &amp;#039; || grantee || &amp;#039;;&amp;#039;&lt;br /&gt;
from   dba_sys_privs&lt;br /&gt;
where  1=1&lt;br /&gt;
and    grantee like upper(&amp;#039;%&amp;amp;&amp;amp;USER_NAME%&amp;#039;)&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
select &amp;#039;grant &amp;#039;||granted_role|| &amp;#039; to &amp;#039; || grantee || &amp;#039;;&amp;#039;&lt;br /&gt;
from   dba_role_privs&lt;br /&gt;
where  1=1&lt;br /&gt;
and    grantee like upper(&amp;#039;%&amp;amp;&amp;amp;USER_NAME%&amp;#039;)&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
spool off&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or for a migration on 11g...!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set head off&lt;br /&gt;
set pages 0&lt;br /&gt;
set long 9999999&lt;br /&gt;
col ddl for a1000&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
SELECT DBMS_METADATA.GET_DDL(&amp;#039;USER&amp;#039;, USERNAME) || &amp;#039;;&amp;#039; DDL&lt;br /&gt;
FROM DBA_USERS&lt;br /&gt;
where  1=1&lt;br /&gt;
and    default_tablespace not in (&amp;#039;SYSTEM&amp;#039;,&amp;#039;SYSAUX&amp;#039;)&lt;br /&gt;
and    upper(username) like &amp;#039;%&amp;#039;||upper(&amp;#039;&amp;amp;&amp;amp;username&amp;#039;)||&amp;#039;%&amp;#039;&lt;br /&gt;
UNION ALL&lt;br /&gt;
SELECT DBMS_METADATA.GET_GRANTED_DDL(&amp;#039;ROLE_GRANT&amp;#039;, USERNAME) || &amp;#039;;&amp;#039; DDL&lt;br /&gt;
FROM DBA_USERS&lt;br /&gt;
where  1=1&lt;br /&gt;
and    default_tablespace not in (&amp;#039;SYSTEM&amp;#039;,&amp;#039;SYSAUX&amp;#039;)&lt;br /&gt;
and    upper(username) like &amp;#039;%&amp;#039;||upper(&amp;#039;&amp;amp;&amp;amp;username&amp;#039;)||&amp;#039;%&amp;#039;&lt;br /&gt;
UNION ALL&lt;br /&gt;
SELECT DBMS_METADATA.GET_GRANTED_DDL(&amp;#039;SYSTEM_GRANT&amp;#039;, USERNAME) || &amp;#039;;&amp;#039; DDL&lt;br /&gt;
FROM DBA_USERS&lt;br /&gt;
where  1=1&lt;br /&gt;
and    default_tablespace not in (&amp;#039;SYSTEM&amp;#039;,&amp;#039;SYSAUX&amp;#039;)&lt;br /&gt;
and    upper(username) like &amp;#039;%&amp;#039;||upper(&amp;#039;&amp;amp;&amp;amp;username&amp;#039;)||&amp;#039;%&amp;#039;&lt;br /&gt;
UNION ALL&lt;br /&gt;
SELECT DBMS_METADATA.GET_GRANTED_DDL(&amp;#039;OBJECT_GRANT&amp;#039;, USERNAME) || &amp;#039;;&amp;#039; DDL&lt;br /&gt;
FROM DBA_USERS&lt;br /&gt;
where  1=1&lt;br /&gt;
and    default_tablespace not in (&amp;#039;SYSTEM&amp;#039;,&amp;#039;SYSAUX&amp;#039;)&lt;br /&gt;
and    upper(username) like &amp;#039;%&amp;#039;||upper(&amp;#039;&amp;amp;&amp;amp;username&amp;#039;)||&amp;#039;%&amp;#039;&lt;br /&gt;
&lt;br /&gt;
spool migration_create_users_grants.sql&lt;br /&gt;
/&lt;br /&gt;
spool off&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Move datafiles between filesystems===&lt;br /&gt;
* [https://blogs.oracle.com/alejandrovargas/moving-a-datafile-from-file-system-to-asm Moving a datafile from File System to ASM (does not have to be ASM!) - oracle.com]&lt;br /&gt;
* [https://docs.oracle.com/database/121/OSTMG/GUID-3B8D0956-0888-452D-A9E4-9FB8D98577E0.htm#OSTMG89997 Moving Data Files Between Oracle ASM (does not have to be ASM!) Using RMAN - oracle.com]&lt;br /&gt;
* [https://oracle-base.com/articles/misc/renaming-or-moving-oracle-files Moving a data file online between filesystems - oracle-base.com]&lt;br /&gt;
====Set the relevant datafile offline====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter database datafile 125 offline;&lt;br /&gt;
alter database datafile 126 offline;&lt;br /&gt;
alter database datafile 127 offline;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Rename the files on the filesystem using o/s commands====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter tablespace ts_thaler_data_offline;&lt;br /&gt;
&lt;br /&gt;
host mv &amp;#039;/cln/tst/ora_data1/clnt/data4/ts_thaler_data_113.dbf&amp;#039; &amp;#039;/cln/tst/ora_data1/clnt/data1/ts_thaler_data_113.dbf&amp;#039;&lt;br /&gt;
host mv &amp;#039;/cln/tst/ora_data1/clnt/data4/ts_thaler_data_114.dbf&amp;#039; &amp;#039;/cln/tst/ora_data1/clnt/data1/ts_thaler_data_114.dbf&amp;#039;&lt;br /&gt;
host mv &amp;#039;/cln/tst/ora_data1/clnt/data4/ts_thaler_data_115.dbf&amp;#039; &amp;#039;/cln/tst/ora_data1/clnt/data1/ts_thaler_data_115.dbf&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Run the relevant alter commands to inform the control files of the new locations====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter database move datafile &amp;#039;/cln/tst/ora_data1/clnt/data4/ts_thaler_data_113.dbf&amp;#039; to &amp;#039;/cln/tst/ora_data1/clnt/data1/ts_thaler_data_113.dbf&amp;#039;&lt;br /&gt;
alter database move datafile &amp;#039;/cln/tst/ora_data1/clnt/data4/ts_thaler_data_114.dbf&amp;#039; to &amp;#039;/cln/tst/ora_data1/clnt/data1/ts_thaler_data_114.dbf&amp;#039;&lt;br /&gt;
alter database move datafile &amp;#039;/cln/tst/ora_data1/clnt/data4/ts_thaler_data_115.dbf&amp;#039; to &amp;#039;/cln/tst/ora_data1/clnt/data1/ts_thaler_data_115.dbf&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Recover the datafiles====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
recover datafile 125;&lt;br /&gt;
recover datafile 126;&lt;br /&gt;
recover datafile 127;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Set the relevant datafile online====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter database datafile 125 online;&lt;br /&gt;
alter database datafile 126 online;&lt;br /&gt;
alter database datafile 127 online;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Check all is well with the datafiles by using an appropriate statement====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 2000 pages 100&lt;br /&gt;
select file_id, file_name, status, online_status from dba_data_files where tablespace_name = &amp;#039;TS_THALER_DATA&amp;#039; order by 2;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Rename a datafile on 12c====&lt;br /&gt;
If you&amp;#039;re lucky enough to be on 12c, it&amp;#039;s one command - no need to offline the datafile!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SQL&amp;gt; alter database move datafile &amp;#039;/oracle/ora_data2/prod/data4/ts_thaler_data_113.dbf&amp;#039; to &amp;#039;/oracle/ora_data2/prod/data3/ts_thaler_data_113.dbf&amp;#039;;&lt;br /&gt;
&lt;br /&gt;
Database altered.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Pass parameter/argument into perl one-liner script from shell===&lt;br /&gt;
Trick? Just use ARGV to pass them in...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
FREQ=$(perl -e &amp;#039;my @CAL=split(&amp;quot;;&amp;quot;,$ARGV[0]);shift @CAL;print $CAL[$ARGV[1]];&amp;#039; -- &amp;quot;$LINE&amp;quot; $offset)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
DUMP_DATE=`perl -MTime::Local -e &amp;#039;print(timelocal(0,$ARGV[0],$ARGV[1],$ARGV[2],$ARGV[3],$ARGV[4]))&amp;#039; -- $MI $HH $DD $MM $YYYY`&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or export the variable from shell and access it via the ENV hash&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
export db=ENDP1&lt;br /&gt;
perl -p -i -e &amp;#039;s!DSMI_LOG.+$!DSMI_LOG           /oracle/$ENV{db}/admin/tdpoerror_$ENV{db}!&amp;#039; ${db}/admin/tdpo.opt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Return epoch seconds in Perl===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
perl -e &amp;#039;print time();&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or to convert a specific day of the year to epoch seconds&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
use POSIX;&lt;br /&gt;
my $epochsecs = mktime(0,0,0, $jday, 0, $year-1900);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or for a specific date (careful though - month is 0-11 not 1-12!...&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
use Time::Local;&lt;br /&gt;
#                          SS MM HH DD MM YYYY&lt;br /&gt;
my $epochsecs = timelocal (30,10,19,03,04,2014);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or more long-winded but delimited by anything...&amp;lt;br /&amp;gt;&lt;br /&gt;
Supply the date/time in any delimited format. Eg. YYYY-MM-DD:HH:MI&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/usr/bin/perl -w&lt;br /&gt;
use Time::Local;&lt;br /&gt;
&lt;br /&gt;
sub date2epoch { &lt;br /&gt;
  my($s) = @_;&lt;br /&gt;
  my($year, $month, $day, $hour, $minute, $second);&lt;br /&gt;
&lt;br /&gt;
  if($s =~ m{^\s*(\d{1,4})\W*0*(\d{1,2})\W*0*(\d{1,2})\W*0*&lt;br /&gt;
                 (\d{0,2})\W*0*(\d{0,2})\W*0*(\d{0,2})}x) {&lt;br /&gt;
    $year = $1;  $month = $2;   $day = $3;&lt;br /&gt;
    $hour = $4;  $minute = $5;  $second = $6;&lt;br /&gt;
    $hour |= 0;  $minute |= 0;  $second |= 0;  # defaults.&lt;br /&gt;
    $year = ($year&amp;lt;100 ? ($year&amp;lt;70 ? 2000+$year : 1900+$year) : $year);&lt;br /&gt;
    return timelocal($second,$minute,$hour,$day,$month-1,$year);  &lt;br /&gt;
  }&lt;br /&gt;
  return -1;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Return epoch seconds in DOS/VBS/Windows===&lt;br /&gt;
Paste this code into epoch.vbs&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
function date2epoch(p_date)&lt;br /&gt;
    date2epoch = DateDiff(&amp;quot;s&amp;quot;, &amp;quot;01/01/1970 00:00:00&amp;quot;, p_date)&lt;br /&gt;
end function&lt;br /&gt;
&lt;br /&gt;
Wscript.Echo date2epoch(Now())&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
and call from a DOS box like this&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cscript //nologo epoch.vbs&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Return date from epoch seconds in Perl===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
perl -e &amp;#039;print scalar (localtime (1243269270))&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Return epoch seconds from julian day number in Perl===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
use POSIX;&lt;br /&gt;
my ($year, $jday) = (2012,60);&lt;br /&gt;
my $epochsecs = mktime(0,0,0, $jday, 0, $year-1900);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Extract specific pieces of a date from an epoch timestamp in Perl===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
use POSIX;&lt;br /&gt;
# return localtime into an array&lt;br /&gt;
my @tm = localtime $epochsecs;&lt;br /&gt;
&lt;br /&gt;
my $yyyymmdd = strftime &amp;quot;%Y%m%d&amp;quot;, @tm;&lt;br /&gt;
print $yyyymmdd.&amp;quot;\n&amp;quot;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Return epoch seconds in Shell (linux)===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
date -d &amp;quot;2014/04/03 18:34:30&amp;quot; &amp;quot;+%s&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Return date from epoch seconds in Shell (linux)===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
date -d @1396542870&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Return epoch seconds in PL/SQL===&lt;br /&gt;
You cannot just use sysdate as that is timezone sensitive... (epoch seconds are in UTC/GMT)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select round((cast(sys_extract_utc(systimestamp) as date) - to_date(&amp;#039;01-JAN-1970 00:00:00&amp;#039;,&amp;#039;DD-MON-YYYY HH24:MI:SS&amp;#039;))*24*60*60) from dual;&lt;br /&gt;
or&lt;br /&gt;
select round((vd.created - to_date(&amp;#039;01-JAN-1970 00:00:00&amp;#039;,&amp;#039;DD-MON-YYYY HH24:MI:SS&amp;#039;))*24*60*60)  created from v$database vd;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
How long has this instance been up (in minutes)?&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select round((cast(sys_extract_utc(systimestamp) as date) - startup_time)*24*60) up_mins from v$instance;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Return date from epoch seconds in SQL===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select to_char(to_date(&amp;#039;19700101&amp;#039;,&amp;#039;YYYYMMDD&amp;#039;) + ((&amp;amp;epoch)/24/60/60),&amp;#039;DD-MON-YYYY HH24:MI:SS&amp;#039;) utc_date from dual;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===A database overview using the sys.plato package===&lt;br /&gt;
 exec plato.help;&lt;br /&gt;
or&lt;br /&gt;
 exec plato.complete(&amp;#039;HTM&amp;#039;);&lt;br /&gt;
&lt;br /&gt;
===List datafiles for a tablespace===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select *&lt;br /&gt;
from   dba_data_files&lt;br /&gt;
where  1=1&lt;br /&gt;
and    tablespace_name =&amp;#039;&amp;amp;ts_name&amp;#039;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Show graph of available and free space in tablespaces===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
-- =============================================================================&lt;br /&gt;
-- File Name    : http://www.oracle-base.com/dba/monitoring/ts_free_space.sql&lt;br /&gt;
-- Author       : Tim Hall&lt;br /&gt;
-- Description  : Displays a list of tablespaces and their used/full status.&lt;br /&gt;
-- Requirements : Access to the DBA views.&lt;br /&gt;
-- Call Syntax  : @ts_free_space.sql&lt;br /&gt;
-- Last Modified: 13-OCT-2012 - Created. Based on ts_full.sql&lt;br /&gt;
--&lt;br /&gt;
-- Modification History&lt;br /&gt;
-- ====================&lt;br /&gt;
-- When      Who               What&lt;br /&gt;
-- ========= ================= =================================================&lt;br /&gt;
-- 13-NOV-13 Stuart Barkley    Added cols free_pct and used_pct&lt;br /&gt;
-- =============================================================================&lt;br /&gt;
SET PAGESIZE 140 lines 180&lt;br /&gt;
COLUMN used_pct FORMAT A11&lt;br /&gt;
COLUMN max_used_pct FORMAT A11&lt;br /&gt;
&lt;br /&gt;
    SELECT tablespace_name                                                                      tablespace_name&lt;br /&gt;
    ,      size_mb                                                                              size_mb&lt;br /&gt;
    ,      free_mb                                                                              free_mb&lt;br /&gt;
    ,      TRUNC((free_mb/size_mb) * 100)                                                       free_pct&lt;br /&gt;
    ,      RPAD(&amp;#039; &amp;#039;|| RPAD(&amp;#039;X&amp;#039;,ROUND((size_mb-free_mb)/size_mb*10,0), &amp;#039;X&amp;#039;),11,&amp;#039;-&amp;#039;)              used_pct&lt;br /&gt;
    ,      max_size_mb                                                                          max_size_mb&lt;br /&gt;
    ,      max_free_mb                                                                          max_free_mb&lt;br /&gt;
    ,      TRUNC((max_free_mb/max_size_mb) * 100)                                               max_free_pct&lt;br /&gt;
    ,      RPAD(&amp;#039; &amp;#039;|| RPAD(&amp;#039;X&amp;#039;,ROUND((max_size_mb-max_free_mb)/max_size_mb*10,0), &amp;#039;X&amp;#039;),11,&amp;#039;-&amp;#039;)  max_used_pct&lt;br /&gt;
    from   (&lt;br /&gt;
           select a.tablespace_name                                         tablespace_name&lt;br /&gt;
           ,      b.size_mb                                                 size_mb&lt;br /&gt;
           ,      a.free_mb                                                 free_mb&lt;br /&gt;
           ,      b.max_size_mb                                             max_size_mb&lt;br /&gt;
           ,      a.free_mb + (b.max_size_mb - b.size_mb)                   max_free_mb&lt;br /&gt;
           from   (&lt;br /&gt;
                  select tablespace_name                                    tablespace_name&lt;br /&gt;
                  ,      trunc(sum(bytes)/1024/1024)                        free_mb&lt;br /&gt;
                  from   dba_free_space&lt;br /&gt;
                  group  by tablespace_name&lt;br /&gt;
                  ) a&lt;br /&gt;
           ,      (&lt;br /&gt;
                  select tablespace_name                                    tablespace_name&lt;br /&gt;
                  ,        trunc(sum(bytes)/1024/1024)                      size_mb&lt;br /&gt;
                  ,        trunc(sum(greatest(bytes,maxbytes))/1024/1024)   max_size_mb&lt;br /&gt;
                  from   dba_data_files&lt;br /&gt;
                  group by tablespace_name&lt;br /&gt;
                  ) b&lt;br /&gt;
           ,      v$instance vi&lt;br /&gt;
           where  a.tablespace_name = b.tablespace_name&lt;br /&gt;
           )&lt;br /&gt;
    order  by tablespace_name;&lt;br /&gt;
&lt;br /&gt;
set lines 80&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Another method for calculating free space in tablespace  using segments===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select df.tablespace_name &amp;quot;Tablespace&amp;quot;&lt;br /&gt;
,      totalusedspace &amp;quot;Used MB&amp;quot;&lt;br /&gt;
,      (df.totalspace - tu.totalusedspace) &amp;quot;Free MB&amp;quot;&lt;br /&gt;
,      df.totalspace &amp;quot;Total MB&amp;quot;&lt;br /&gt;
,      round(100 * ( (df.totalspace - tu.totalusedspace)/ df.totalspace)) &amp;quot;Pct. Free&amp;quot;&lt;br /&gt;
from   (&lt;br /&gt;
       select tablespace_name&lt;br /&gt;
,      round(sum(bytes) / 1048576) totalspace&lt;br /&gt;
       from   dba_data_files&lt;br /&gt;
       group  by tablespace_name&lt;br /&gt;
       ) df&lt;br /&gt;
,      (&lt;br /&gt;
       select round(sum(bytes)/(1024*1024)) totalusedspace&lt;br /&gt;
       ,      tablespace_name&lt;br /&gt;
       from   dba_segments&lt;br /&gt;
       group  by tablespace_name&lt;br /&gt;
       ) tu&lt;br /&gt;
where  df.tablespace_name = tu.tablespace_name;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Work out maximum possible size of a datafile===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select round( (4*1024*1024*value) / (1024*1024*1024) ,2) maxfilesizeingigabytes from v$parameter where name=&amp;#039;db_block_size&amp;#039;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or, as tablespaces can have block sizes differing from that of the init.ora parameter...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select round( (4*1024*1024*block_size) / (1024*1024*1024) ,2) maxfilesizeingigabytes from dba_tablespaces where tablespace_name=&amp;#039;&amp;amp;tablespace_name&amp;#039;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Show size and maxsize at datafile level===&lt;br /&gt;
datafiles&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set pages 100 lines 200&lt;br /&gt;
col file_name for a60&lt;br /&gt;
select sum(bytes)/1024/1024      mbytes_alloc&lt;br /&gt;
,      sum(maxbytes)/1024/1024   mbytes_max&lt;br /&gt;
,      file_name&lt;br /&gt;
from   sys.dba_data_files&lt;br /&gt;
group  by file_name&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
tempfiles&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set pages 100 lines 200&lt;br /&gt;
col file_name for a60&lt;br /&gt;
select sum(bytes)/1024/1024      mbytes_alloc&lt;br /&gt;
,      sum(maxbytes)/1024/1024   mbytes_max&lt;br /&gt;
,      file_name&lt;br /&gt;
from   sys.dba_temp_files&lt;br /&gt;
group  by file_name&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Resize the online redo logfiles===&lt;br /&gt;
Found a more concise, smarter way of doing it [http://www.oracle-wiki.net/startdocshowtorecreateredogrps here] - oracle-wiki.net&amp;lt;br /&amp;gt;&lt;br /&gt;
Switching logs too often? Redolog files too small?&amp;lt;br /&amp;gt;&lt;br /&gt;
* Show current log groups&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 1000&lt;br /&gt;
col group_member for a60&lt;br /&gt;
select l.group#          group_number&lt;br /&gt;
,      (bytes/1024/1024) megs&lt;br /&gt;
,      l.status          group_status&lt;br /&gt;
,      f.member          group_member&lt;br /&gt;
,      l.archived        archived&lt;br /&gt;
,      f.type            file_type&lt;br /&gt;
from   v$log     l&lt;br /&gt;
,      v$logfile f&lt;br /&gt;
where  l.group# = f.group#&lt;br /&gt;
order  by l.group#&lt;br /&gt;
,      f.member&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Create additional (bigger) groups&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
define SID=TIBQFW&lt;br /&gt;
alter database add logfile group 6  &amp;#039;/oracle/&amp;amp;SID/oradata1/redo1.log&amp;#039; size 1G;&lt;br /&gt;
alter database add logfile group 7  &amp;#039;/oracle/&amp;amp;SID/oradata2/redo2.log&amp;#039; size 1G;&lt;br /&gt;
alter database add logfile group 8  &amp;#039;/oracle/&amp;amp;SID/oradata3/redo3.log&amp;#039; size 1G;&lt;br /&gt;
alter database add logfile group 9  &amp;#039;/oracle/&amp;amp;SID/oradata1/redo4.log&amp;#039; size 1G;&lt;br /&gt;
alter database add logfile group 10 &amp;#039;/oracle/&amp;amp;SID/oradata2/redo5.log&amp;#039; size 1G;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or if you use multiple members...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter database add logfile group 6 (&amp;#039;/oracle/&amp;amp;SID/oradata1/redo/redo01a.log&amp;#039;, &amp;#039;/oracle/&amp;amp;SID/oradata1/redo01b&amp;#039;) size 50M;&lt;br /&gt;
alter database add logfile group 7 (&amp;#039;/oracle/&amp;amp;SID/oradata1/redo/redo02a.log&amp;#039;, &amp;#039;/oracle/&amp;amp;SID/oradata1/redo02b&amp;#039;) size 50M;&lt;br /&gt;
alter database add logfile group 8 (&amp;#039;/oracle/&amp;amp;SID/oradata1/redo/redo03a.log&amp;#039;, &amp;#039;/oracle/&amp;amp;SID/oradata1/redo03b&amp;#039;) size 50M;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Switch archivelogs until the new ones are current and the old ones are inactive&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter system switch logfile;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
If the old logs are not yet inactive, checkpoint the database&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter system checkpoint;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Drop the old groups&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter database drop logfile group 1;&lt;br /&gt;
alter database drop logfile group 2;&lt;br /&gt;
alter database drop logfile group 3;&lt;br /&gt;
alter database drop logfile group 4;&lt;br /&gt;
alter database drop logfile group 5;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Increase the existing size of a datafile===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter database datafile &amp;#039;&amp;amp;full_path_of_datafile&amp;#039; resize &amp;amp;new_meg_size.M;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Increase the max size of a tempfile===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter database tempfile &amp;#039;/oracle/ENDP1/oradata90/temp01.dbf&amp;#039; autoextend on maxsize unlimited;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Find out what processes are using the temp tablespace===&lt;br /&gt;
Temporary tablespace is used for sorting query results. Find them with this.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SELECT b.tablespace,b.segfile#,b.segblk#,b.blocks,a.sid,a.serial#,&lt;br /&gt;
a.username,a.osuser, a.status&lt;br /&gt;
FROM v$session a,v$sort_usage b&lt;br /&gt;
WHERE a.saddr = b.session_addr;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Increase the maximum size of a datafile===&lt;br /&gt;
Although this can be set lower than existing size, try not to. It makes the reports look weird!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter database&lt;br /&gt;
      datafile &amp;#039;&amp;amp;full_path_of_datafile&amp;#039;&lt;br /&gt;
      autoextend on&lt;br /&gt;
      maxsize &amp;amp;new_meg_size.m;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Find schemas (users) with objects created outside their default tablespace===&lt;br /&gt;
Indexes could be a notable exception if they are created in an index tablespace&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 200&lt;br /&gt;
col owner           for a20&lt;br /&gt;
col segment_name    for a45&lt;br /&gt;
col tablespace_name for a32&lt;br /&gt;
select owner&lt;br /&gt;
,      segment_name&lt;br /&gt;
,      tablespace_name&lt;br /&gt;
from   dba_segments&lt;br /&gt;
where  exists (select username from dba_users where username = owner)&lt;br /&gt;
and    tablespace_name != (select default_tablespace from dba_users where username = owner)&lt;br /&gt;
and    owner = &amp;#039;&amp;amp;owner&amp;#039;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Add a datafile to a tablespace===&lt;br /&gt;
&amp;#039;unlimited&amp;#039; will default to the maximum datafile size for the current db_block_size&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter tablepace &amp;amp;tablespace_name&lt;br /&gt;
      add datafile &amp;#039;&amp;amp;full_path_of_datafile&amp;#039;&lt;br /&gt;
      size 100M&lt;br /&gt;
      autoextend on&lt;br /&gt;
      next 100M&lt;br /&gt;
      maxsize unlimited&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===List all datafiles with their size===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set pages 1000 lines 2000&lt;br /&gt;
col filetype for a15&lt;br /&gt;
col name for a60&lt;br /&gt;
break on report&lt;br /&gt;
compute sum of gig on report&lt;br /&gt;
&lt;br /&gt;
select filetype&lt;br /&gt;
,      name&lt;br /&gt;
,      gig&lt;br /&gt;
from   (&lt;br /&gt;
       select &amp;#039;datafile&amp;#039; filetype&lt;br /&gt;
       ,      name&lt;br /&gt;
       ,      bytes/1024/1024 gig&lt;br /&gt;
       from   v$datafile&lt;br /&gt;
       union all&lt;br /&gt;
       select &amp;#039;tempfile&amp;#039; filetype&lt;br /&gt;
       ,      name&lt;br /&gt;
       ,      bytes/1024/1024&lt;br /&gt;
       from   v$tempfile&lt;br /&gt;
       union all&lt;br /&gt;
       select &amp;#039;logfile&amp;#039; filetype&lt;br /&gt;
       ,      lf.member &amp;quot;name&amp;quot;&lt;br /&gt;
       ,      l.bytes/1024/1024&lt;br /&gt;
       from   v$logfile lf&lt;br /&gt;
       ,      v$log     l&lt;br /&gt;
       where  1=1&lt;br /&gt;
       and    lf.group# = l.group#&lt;br /&gt;
       ) used&lt;br /&gt;
,      (&lt;br /&gt;
       select sum(bytes)/1024/1024&lt;br /&gt;
       from   dba_free_space&lt;br /&gt;
       ) free&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Database size (How big is my database?)===&lt;br /&gt;
There are different interpretations of what constitutes the size of a database...&amp;lt;br /&amp;gt;&lt;br /&gt;
Is it the space allocated to the datafiles or only the space taken up by the data? Are tempfiles included? Are redo logs included? etc...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 132&lt;br /&gt;
col dbname for a9  heading &amp;quot;Database&amp;quot;&lt;br /&gt;
col dbsize for a15 heading &amp;quot;Size&amp;quot;&lt;br /&gt;
col dbused for a15 heading &amp;quot;Used space&amp;quot;&lt;br /&gt;
col dbfree for a15 heading &amp;quot;Free space&amp;quot;&lt;br /&gt;
with used_space as&lt;br /&gt;
(&lt;br /&gt;
select  bytes&lt;br /&gt;
from    v$datafile&lt;br /&gt;
union   all&lt;br /&gt;
select  bytes&lt;br /&gt;
from    v$tempfile&lt;br /&gt;
union   all&lt;br /&gt;
select  bytes&lt;br /&gt;
from    v$log&lt;br /&gt;
)&lt;br /&gt;
, free_space as&lt;br /&gt;
(&lt;br /&gt;
select sum(bytes) sum_bytes&lt;br /&gt;
from dba_free_space&lt;br /&gt;
)&lt;br /&gt;
select vd.name                                                                                            dbname&lt;br /&gt;
,      round(sum(used_space.bytes)/1024/1024/1024 ) || &amp;#039; GB&amp;#039;                                              dbsize&lt;br /&gt;
,      round(sum(used_space.bytes)/1024/1024/1024 ) - round(free_space.sum_bytes/1024/1024/1024) || &amp;#039; GB&amp;#039; dbused&lt;br /&gt;
,      round(free_space.sum_bytes/1024/1024/1024) || &amp;#039; GB&amp;#039;                                                dbfree&lt;br /&gt;
from   free_space&lt;br /&gt;
,      used_space&lt;br /&gt;
,      v$database vd&lt;br /&gt;
group  by vd.name&lt;br /&gt;
,      free_space.sum_bytes&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Drop datafile from temp tablespace===&lt;br /&gt;
Database is completely stuck because the temporary tablespace has grown to fill all available room.&amp;lt;br /&amp;gt;&lt;br /&gt;
Look around for at least some log files to delete in order to get connected (audit files, sqlnet logs, listener logs)&amp;lt;br /&amp;gt;&lt;br /&gt;
Once connected, change the default temporary tablespace to a small one so we can remove the original.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
create temporary tablespace temp2 tempfile &amp;#039;/oracle/RMANV12/oradata2/temp2.dbf&amp;#039; size 5M;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter database default temporary tablespace temp2;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
I found trying to drop the datafile like this didn&amp;#039;t work, just hung there (probably active tranactions)...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
drop tablespace temp including contents and datafiles;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
So did it like this...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter database tempfile &amp;#039;/oracle/RMANV12/oradata2/temp.dbf&amp;#039; drop including datafiles;&lt;br /&gt;
&lt;br /&gt;
Database altered.&lt;br /&gt;
&lt;br /&gt;
drop tablespace temp including contents and datafiles;&lt;br /&gt;
&lt;br /&gt;
Tablespace dropped.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
... an alternative would be to find the sessions using the temp space and kill them...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select sid, serial#, status from v$session where serial# in (select session_num from v$sort_usage);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Then to be neat and tidy, rename the temp2 tablespace back to temp.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
create temporary tablespace temp tempfile &amp;#039;/oracle/RMANV12/oradata2/temp.dbf&amp;#039; size 256M reuse autoextend on next 128M maxsize 1G;&lt;br /&gt;
alter database default temporary tablespace temp;&lt;br /&gt;
drop tablespace temp2 including contents and datafiles;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Although the last statement will not work until any transactions using it have been rolled back or committed.&lt;br /&gt;
&lt;br /&gt;
===List files that are in hot-backup mode===&lt;br /&gt;
 set lines 100&lt;br /&gt;
 set pages 100&lt;br /&gt;
 col name format a60&lt;br /&gt;
 &lt;br /&gt;
 select df.name&lt;br /&gt;
 ,      b.status&lt;br /&gt;
 ,      to_char(time, &amp;#039;hh24:mi:ss dd/mm/yyyy&amp;#039;) time&lt;br /&gt;
 from   v$datafile   df&lt;br /&gt;
 ,      v$backup     b&lt;br /&gt;
 where  1=1&lt;br /&gt;
 and    df.file# = b.file#&lt;br /&gt;
 and    b.status = &amp;#039;ACTIVE&amp;#039;&lt;br /&gt;
 order  by b.file#;&lt;br /&gt;
&lt;br /&gt;
===Waiting for snapshot control file enqueue===&lt;br /&gt;
Script to identify sessions causing RMAN to hang because of &amp;#039;waiting for snapshot control file enqueue&amp;#039; message&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 2000&lt;br /&gt;
col killer     for a70&lt;br /&gt;
col program    for a20&lt;br /&gt;
col module     for a20&lt;br /&gt;
col action     for a20&lt;br /&gt;
col logon_time for a20&lt;br /&gt;
&lt;br /&gt;
select &amp;#039;alter system disconnect session &amp;#039;&amp;#039;&amp;#039;||s.sid||&amp;#039;,&amp;#039;||s.serial#||&amp;#039;&amp;#039;&amp;#039; immediate;&amp;#039; killer&lt;br /&gt;
,      username&lt;br /&gt;
,      program&lt;br /&gt;
,      module&lt;br /&gt;
,      action&lt;br /&gt;
,      logon_time&lt;br /&gt;
from   v$session s&lt;br /&gt;
,      v$enqueue_lock l&lt;br /&gt;
where  l.sid  = s.sid&lt;br /&gt;
and    l.type = &amp;#039;CF&amp;#039;&lt;br /&gt;
and    l.id1  = 0&lt;br /&gt;
and    l.id2  = 2&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Info on blocking processes===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select s1.username || &amp;#039;@&amp;#039; || s1.machine&lt;br /&gt;
       || &amp;#039; ( SID=&amp;#039; || s1.sid || &amp;#039; )  is blocking &amp;#039;&lt;br /&gt;
       || s2.username || &amp;#039;@&amp;#039; || s2.machine || &amp;#039; ( SID=&amp;#039; || s2.sid || &amp;#039; ) &amp;#039;  blocking_status&lt;br /&gt;
from   v$lock l1&lt;br /&gt;
,      v$session s1&lt;br /&gt;
,      v$lock l2&lt;br /&gt;
,      v$session s2&lt;br /&gt;
where  s1.sid     = l1.sid&lt;br /&gt;
and    s2.sid     = l2.sid&lt;br /&gt;
and    l1.block   = 1&lt;br /&gt;
and    l2.request &amp;gt; 0&lt;br /&gt;
and    l1.id1     = l2.id1&lt;br /&gt;
and    l2.id2     = l2.id2&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
session doing the blocking&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select *&lt;br /&gt;
from  v$lock l1&lt;br /&gt;
where 1=1&lt;br /&gt;
and   block = 1 ;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
sessions being blocked&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select *&lt;br /&gt;
from   v$lock l1&lt;br /&gt;
where  1=1&lt;br /&gt;
and    id2 = 85203&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
info on session doing the blocking&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select row_wait_obj#, row_wait_file#, row_wait_block#, row_wait_row#&lt;br /&gt;
from   v$session&lt;br /&gt;
where  sid = 234&lt;br /&gt;
&lt;br /&gt;
select do.object_name&lt;br /&gt;
,      row_wait_obj#&lt;br /&gt;
,      row_wait_file#&lt;br /&gt;
,      row_wait_block#&lt;br /&gt;
,      row_wait_row#&lt;br /&gt;
,      dbms_rowid.rowid_create ( 1, ROW_WAIT_OBJ#, ROW_WAIT_FILE#, ROW_WAIT_BLOCK#, ROW_WAIT_ROW# ) row_id&lt;br /&gt;
from   v$session   s&lt;br /&gt;
,      dba_objects do&lt;br /&gt;
where  sid=234&lt;br /&gt;
and    s.ROW_WAIT_OBJ# = do.OBJECT_ID;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Show locked objects===&lt;br /&gt;
 set lines 100&lt;br /&gt;
 set pages 999&lt;br /&gt;
 col username   format a20&lt;br /&gt;
 col sess_id    format a10&lt;br /&gt;
 col object     format a25&lt;br /&gt;
 col mode_held  format a10&lt;br /&gt;
 select oracle_username||&amp;#039; (&amp;#039;||s.osuser||&amp;#039;)&amp;#039; username&lt;br /&gt;
 ,      s.sid||&amp;#039;,&amp;#039;||s.serial# sess_id&lt;br /&gt;
 ,      owner||&amp;#039;.&amp;#039;||object_name object&lt;br /&gt;
 ,      object_type&lt;br /&gt;
 ,      decode ( l.block&lt;br /&gt;
               , 0, &amp;#039;Not Blocking&amp;#039;&lt;br /&gt;
               , 1, &amp;#039;Blocking&amp;#039;&lt;br /&gt;
               , 2, &amp;#039;Global&amp;#039;&lt;br /&gt;
               ) status&lt;br /&gt;
 ,      decode ( v.locked_mode&lt;br /&gt;
               , 0, &amp;#039;None&amp;#039;&lt;br /&gt;
               , 1, &amp;#039;Null&amp;#039;&lt;br /&gt;
               , 2, &amp;#039;Row-S (SS)&amp;#039;&lt;br /&gt;
               , 3, &amp;#039;Row-X (SX)&amp;#039;&lt;br /&gt;
               , 4, &amp;#039;Share&amp;#039;&lt;br /&gt;
               , 5, &amp;#039;S/Row-X (SSX)&amp;#039;&lt;br /&gt;
               , 6, &amp;#039;Exclusive&amp;#039;, TO_CHAR(lmode)&lt;br /&gt;
               ) mode_held&lt;br /&gt;
 from   v$locked_object v&lt;br /&gt;
 ,      dba_objects d&lt;br /&gt;
 ,      v$lock l&lt;br /&gt;
 ,      v$session s&lt;br /&gt;
 where  1=1&lt;br /&gt;
 and    v.object_id = d.object_id&lt;br /&gt;
 and    v.object_id = l.id1&lt;br /&gt;
 and    v.session_id = s.sid&lt;br /&gt;
 order  by oracle_username&lt;br /&gt;
 ,	session_id;&lt;br /&gt;
&lt;br /&gt;
===Show which row is locked===&lt;br /&gt;
 select do.object_name&lt;br /&gt;
 ,      row_wait_obj#&lt;br /&gt;
 ,      row_wait_file#&lt;br /&gt;
 ,      row_wait_block#&lt;br /&gt;
 ,      row_wait_row#&lt;br /&gt;
 ,      dbms_rowid.rowid_create (1, ROW_WAIT_OBJ#, ROW_WAIT_FILE#, ROW_WAIT_BLOCK#, ROW_WAIT_ROW#)&lt;br /&gt;
 from   v$session   s&lt;br /&gt;
 ,      dba_objects do&lt;br /&gt;
 where  1=1&lt;br /&gt;
 and    s.ROW_WAIT_OBJ# = do.OBJECT_ID&lt;br /&gt;
 and    sid             = &amp;amp;sid;&lt;br /&gt;
&lt;br /&gt;
===Check what is audited on a database===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set pagesize 100&lt;br /&gt;
set linesize 256&lt;br /&gt;
select audit_option,success,failure from dba_stmt_audit_opts;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===How old is the oldest audit record?===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select extract (day from (systimestamp - min(ntimestamp#))) days_old from aud$;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Check what objects are being audited===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
tti col 60 &amp;#039;Object Audit Options (dba_obj_audit_opts)&amp;#039; skip col 50 &amp;#039;A=By Access, S=By Session. Left=on success, right=on failure&amp;#039; skip 2&lt;br /&gt;
set lines 1000 pages 100&lt;br /&gt;
col alt for a3 head &amp;quot;Alt|er&amp;quot;&lt;br /&gt;
col aud for a3 head &amp;quot;Aud|it&amp;quot;&lt;br /&gt;
col com for a3 head &amp;quot;Com|ent&amp;quot;&lt;br /&gt;
col del for a3 head &amp;quot;Del|ete&amp;quot;&lt;br /&gt;
col gra for a3 head &amp;quot;Gra|nt&amp;quot;&lt;br /&gt;
col ind for a3 head &amp;quot;Ind|ex&amp;quot;&lt;br /&gt;
col ins for a3 head &amp;quot;Ins|ert&amp;quot;&lt;br /&gt;
col loc for a3 head &amp;quot;Lo|ck&amp;quot;&lt;br /&gt;
col ren for a3 head &amp;quot;Ren|ame&amp;quot;&lt;br /&gt;
col sel for a3 head &amp;quot;Sel|ect&amp;quot;&lt;br /&gt;
col upd for a3 head &amp;quot;Upd|ate&amp;quot;&lt;br /&gt;
col ref for a3 head &amp;quot;Ref|rnc&amp;quot;&lt;br /&gt;
col exe for a3 head &amp;quot;Exe|cut&amp;quot;&lt;br /&gt;
col cre for a3 head &amp;quot;Cre|ate&amp;quot;&lt;br /&gt;
col rea for a3 head &amp;quot;Re|ad&amp;quot;&lt;br /&gt;
col wri for a3 head &amp;quot;Wri|te&amp;quot;&lt;br /&gt;
col fbk for a3 head &amp;quot;Fla|sh&amp;quot;&lt;br /&gt;
	&lt;br /&gt;
select *&lt;br /&gt;
from   dba_obj_audit_opts&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Procedure to delete old audit records===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select text from all_source where lower(name)=&amp;#039;purge_audit_trail&amp;#039;;&lt;br /&gt;
&lt;br /&gt;
TEXT&lt;br /&gt;
------------------------------------------------------------------------------------------------&lt;br /&gt;
PROCEDURE purge_audit_trail IS&lt;br /&gt;
BEGIN&lt;br /&gt;
-- set the last archive timestamp&lt;br /&gt;
DBMS_AUDIT_MGMT.SET_LAST_ARCHIVE_TIMESTAMP(&lt;br /&gt;
       audit_trail_type    =&amp;gt; DBMS_AUDIT_MGMT.AUDIT_TRAIL_AUD_STD,&lt;br /&gt;
       last_archive_time   =&amp;gt; systimestamp - interval &amp;#039;365&amp;#039; day,&lt;br /&gt;
       rac_instance_number =&amp;gt; null&lt;br /&gt;
                                          );&lt;br /&gt;
-- purge audit trail till last archive timestamp&lt;br /&gt;
DBMS_AUDIT_MGMT.CLEAN_AUDIT_TRAIL( audit_trail_type =&amp;gt; DBMS_AUDIT_MGMT.AUDIT_TRAIL_AUD_STD&lt;br /&gt;
, use_last_arch_timestamp =&amp;gt; TRUE);&lt;br /&gt;
&lt;br /&gt;
END purge_audit_trail;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Job setup to run the audit purge===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
BEGIN&lt;br /&gt;
sys.dbms_scheduler.create_job(&lt;br /&gt;
    job_name =&amp;gt; &amp;#039;&amp;quot;SYS&amp;quot;.&amp;quot;PURGE_AUDIT_TRAIL_JOB&amp;quot;&amp;#039;,&lt;br /&gt;
    job_type =&amp;gt; &amp;#039;STORED_PROCEDURE&amp;#039;,&lt;br /&gt;
    job_action =&amp;gt; &amp;#039;&amp;quot;SYS&amp;quot;.&amp;quot;PURGE_AUDIT_TRAIL&amp;quot;&amp;#039;,&lt;br /&gt;
    repeat_interval =&amp;gt; &amp;#039;FREQ=DAILY;BYHOUR=20;BYMINUTE=0;BYSECOND=0&amp;#039;,&lt;br /&gt;
    start_date =&amp;gt; to_timestamp_tz(&amp;#039;2012-02-22 Europe/Paris&amp;#039;, &amp;#039;YYYY-MM-DD TZR&amp;#039;),&lt;br /&gt;
    job_class =&amp;gt; &amp;#039;&amp;quot;DEFAULT_JOB_CLASS&amp;quot;&amp;#039;,&lt;br /&gt;
    comments =&amp;gt; &amp;#039;purge audit trails until last archive timestamp&amp;#039;,&lt;br /&gt;
    auto_drop =&amp;gt; FALSE,&lt;br /&gt;
    enabled =&amp;gt; FALSE&lt;br /&gt;
);&lt;br /&gt;
sys.dbms_scheduler.set_attribute( name =&amp;gt; &amp;#039;&amp;quot;SYS&amp;quot;.&amp;quot;PURGE_AUDIT_TRAIL_JOB&amp;quot;&amp;#039;, attribute =&amp;gt; &amp;#039;logging_level&amp;#039;, value =&amp;gt; DBMS_SCHEDULER.LOGGING_OFF);&lt;br /&gt;
sys.dbms_scheduler.set_attribute( name =&amp;gt; &amp;#039;&amp;quot;SYS&amp;quot;.&amp;quot;PURGE_AUDIT_TRAIL_JOB&amp;quot;&amp;#039;, attribute =&amp;gt; &amp;#039;job_weight&amp;#039;, value =&amp;gt; 1);&lt;br /&gt;
sys.dbms_scheduler.enable( &amp;#039;&amp;quot;SYS&amp;quot;.&amp;quot;PURGE_AUDIT_TRAIL_JOB&amp;quot;&amp;#039; );&lt;br /&gt;
END;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===A list of all SIDs in oratab that should restart after a server boot===&lt;br /&gt;
Using awk&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
awk -F: &amp;#039;$NF==&amp;quot;Y&amp;quot; &amp;amp;&amp;amp; $1 !~/[#]/ {print $1}&amp;#039;  /etc/oratab&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Using perl&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
perl -F: -ne &amp;#039;print &amp;quot;$1\n&amp;quot; if /(\w+):(.+):Y$/&amp;#039; /etc/oratab&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Move the admin directories to a new location===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
./all_db_do &amp;quot;alter system set audit_file_dest=&amp;#039;/oracle/&amp;amp;SID/admin/adump&amp;#039; scope=spfile;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
./all_db_do &amp;quot;shutdown immediate&amp;quot;&lt;br /&gt;
&lt;br /&gt;
for db in `awk -F: &amp;#039;NF &amp;amp;&amp;amp; $1 !~/[#*]/ {print $1}&amp;#039;  /etc/oratab`&lt;br /&gt;
do&lt;br /&gt;
    echo $db&lt;br /&gt;
    mkdir -p /oracle/${db}/admin&lt;br /&gt;
    echo &amp;quot;/oracle/${db}/admin created&amp;quot;&lt;br /&gt;
    mv /oracle/admin/${db}/adump /oracle/${db}/admin/&lt;br /&gt;
    mv /oracle/admin/${db}/dpdump /oracle/${db}/admin/&lt;br /&gt;
    echo &amp;quot;Moved /oracle/admin/${db}/adump to /oracle/${db}/admin/&amp;quot;&lt;br /&gt;
done&lt;br /&gt;
&lt;br /&gt;
./all_db_do startup&lt;br /&gt;
&lt;br /&gt;
./all_db_do &amp;quot;create pfile from spfile;&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Check if the Standby database is up-to-date with the primary database===&lt;br /&gt;
 select arch.thread# &amp;quot;Thread&amp;quot;&lt;br /&gt;
 ,      arch.sequence# &amp;quot;Last Sequence Received&amp;quot;&lt;br /&gt;
 ,      appl.sequence# &amp;quot;Last Sequence Applied&amp;quot;&lt;br /&gt;
 ,      (arch.sequence# - appl.sequence#) &amp;quot;Difference&amp;quot;&lt;br /&gt;
 from   (&lt;br /&gt;
        select thread#&lt;br /&gt;
        ,      sequence#&lt;br /&gt;
        from   v$archived_log&lt;br /&gt;
        where  1=1&lt;br /&gt;
        and    ( thread#,first_time ) in (&lt;br /&gt;
                                         select thread#, max(first_time)&lt;br /&gt;
                                         from   v$archived_log&lt;br /&gt;
                                         group  by thread#&lt;br /&gt;
                                         )&lt;br /&gt;
        ) arch&lt;br /&gt;
        ,&lt;br /&gt;
        (&lt;br /&gt;
        select thread#&lt;br /&gt;
        ,      sequence#&lt;br /&gt;
        from   v$log_history&lt;br /&gt;
        where  1=1&lt;br /&gt;
        and    ( thread#,first_time ) in ( select thread# ,max(first_time)&lt;br /&gt;
                                           from   v$log_history&lt;br /&gt;
                                           group  by thread#&lt;br /&gt;
                                          )&lt;br /&gt;
        ) appl&lt;br /&gt;
 where  1=1&lt;br /&gt;
 and    arch.thread# = appl.thread#&lt;br /&gt;
 order  by 1;&lt;br /&gt;
&lt;br /&gt;
===Check for gaps on the Standby database===&lt;br /&gt;
Run this on the standby&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select thread#, low_sequence#, high_sequence# from v$archive_gap;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or run this on the Primary to see the latest generated archive...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select thread#   &amp;quot;Thread&amp;quot;&lt;br /&gt;
,      sequence# &amp;quot;Last sequence generated&amp;quot;&lt;br /&gt;
from   v$archived_log&lt;br /&gt;
where  (thread#, first_time) in ( select thread#, max(first_time)&lt;br /&gt;
                                  from   v$archived_log&lt;br /&gt;
                                  group  by thread#&lt;br /&gt;
                                )&lt;br /&gt;
order  by 1&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
and run this on the standby to check for received but not yet applied logs (this could be normal if a lag has been set)...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select arch.thread# &amp;quot;Thread&amp;quot;&lt;br /&gt;
,      arch.sequence# &amp;quot;Last sequence received&amp;quot;&lt;br /&gt;
,      appl.sequence# &amp;quot;Last sequence applied&amp;quot;&lt;br /&gt;
,      (arch.sequence#-appl.sequence#) &amp;quot;Difference&amp;quot;&lt;br /&gt;
from   (&lt;br /&gt;
       select thread#&lt;br /&gt;
       ,      sequence#&lt;br /&gt;
       from   v$archived_log&lt;br /&gt;
       where  (thread#,first_time ) in (select thread#, max(first_time)&lt;br /&gt;
                                        from   v$archived_log&lt;br /&gt;
                                        group  by thread#&lt;br /&gt;
                                       )&lt;br /&gt;
       ) arch&lt;br /&gt;
,      (&lt;br /&gt;
       select thread#&lt;br /&gt;
       ,      sequence#&lt;br /&gt;
       from   v$log_history&lt;br /&gt;
       where  (thread#,first_time ) in (select thread#, max(first_time)&lt;br /&gt;
                                        from   v$log_history&lt;br /&gt;
                                        group  by thread#&lt;br /&gt;
                                       )&lt;br /&gt;
      ) appl&lt;br /&gt;
where arch.thread# = appl.thread#&lt;br /&gt;
order by 1&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Compare the results from Primary and Secondary to detect possible network problems or other errors in shipping.&lt;br /&gt;
&lt;br /&gt;
===Ignore case-sensitive passwords in 11g (deprecated in 12c)===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter system set SEC_CASE_SENSITIVE_LOGON = false scope=both&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===External table for the Alert log (pre 11g)===&lt;br /&gt;
&lt;br /&gt;
===Alert log (11g+)===&lt;br /&gt;
This reads the log.xml file (which contains the same information as alert.log)&amp;lt;br /&amp;gt;&lt;br /&gt;
Show the messages put in the alert log in the last 24 hours&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select substr(MESSAGE_TEXT, 1, 300) message_text&lt;br /&gt;
,      count(*) cnt&lt;br /&gt;
from   X$DBGALERTEXT&lt;br /&gt;
where  1=1&lt;br /&gt;
and    (MESSAGE_TEXT like &amp;#039;%ORA-%&amp;#039; or upper(MESSAGE_TEXT) like &amp;#039;%ERROR%&amp;#039;)&lt;br /&gt;
and    cast(ORIGINATING_TIMESTAMP as DATE) &amp;gt; sysdate - &amp;amp;days_ago/1440&lt;br /&gt;
group  by substr(MESSAGE_TEXT, 1, 300)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
There is also a fixed table X$DBGDIREXT which returns all file and directory names under [diagnostic_dest]/diag directory:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select lpad(&amp;#039; &amp;#039;,lvl,&amp;#039; &amp;#039;)||logical_file file_name&lt;br /&gt;
from   x$dbgdirext&lt;br /&gt;
where  rownum &amp;lt;=20;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Directory paths available in v$diag_info===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 2000&lt;br /&gt;
col name for a35&lt;br /&gt;
col value for a100 wrap&lt;br /&gt;
select * from v$diag_info;&lt;br /&gt;
&lt;br /&gt;
   INST_ID NAME                                VALUE                                                                                                    CON_ID&lt;br /&gt;
---------- ----------------------------------- ---------------------------------------------------------------------------------------------------- ----------&lt;br /&gt;
         1 Diag Enabled                        TRUE                                                                                                          0&lt;br /&gt;
         1 ADR Base                            /cln/prg/ora_bin2/app/oracle                                                                               0&lt;br /&gt;
         1 ADR Home                            /cln/prg/ora_bin2/app/oracle/diag/rdbms/bild/bild                                                          0&lt;br /&gt;
         1 Diag Trace                          /cln/prg/ora_bin2/app/oracle/diag/rdbms/bild/bild/trace                                                    0&lt;br /&gt;
         1 Diag Alert                          /cln/prg/ora_bin2/app/oracle/diag/rdbms/bild/bild/alert                                                    0&lt;br /&gt;
         1 Diag Incident                       /cln/prg/ora_bin2/app/oracle/diag/rdbms/bild/bild/incident                                                 0&lt;br /&gt;
         1 Diag Cdump                          /cln/prg/ora_bin2/app/oracle/diag/rdbms/bild/bild/cdump                                                    0&lt;br /&gt;
         1 Health Monitor                      /cln/prg/ora_bin2/app/oracle/diag/rdbms/bild/bild/hm                                                       0&lt;br /&gt;
         1 Default Trace File                  /cln/prg/ora_bin2/app/oracle/diag/rdbms/bild/bild/trace/bild_ora_44696768.trc                              0&lt;br /&gt;
         1 Active Problem Count                0                                                                                                             0&lt;br /&gt;
         1 Active Incident Count               0                                                                                                             0&lt;br /&gt;
&lt;br /&gt;
11 rows selected.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Find out the names of the active trace files for the running processes===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select pid, program, tracefile from v$process;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Request was to duplicate a large tablespace from production to test environment===&lt;br /&gt;
...but rather than copy the terabytes of data, create the destination tablespace with just the most recent months data&amp;lt;br /&amp;gt;&lt;br /&gt;
====See what the source data looks like====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
col table_owner    for a20&lt;br /&gt;
col table_name     for a30&lt;br /&gt;
col partition_name for a20&lt;br /&gt;
set pages 100 lines 1000&lt;br /&gt;
&lt;br /&gt;
select table_owner&lt;br /&gt;
,      table_name&lt;br /&gt;
,      partition_name&lt;br /&gt;
,      partition_position&lt;br /&gt;
,      tablespace_name&lt;br /&gt;
from   dba_tab_partitions&lt;br /&gt;
where  tablespace_name = &amp;#039;ADS_ARCHIVE&amp;#039;&lt;br /&gt;
order  by 1,2,3,4&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This query produces something like this...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
TABLE_OWNER          TABLE_NAME                     PARTITION_NAME       PARTITION_POSITION TABLESPACE_NAME                &lt;br /&gt;
-------------------- ------------------------------ -------------------- ------------------ ------------------------------ &lt;br /&gt;
ADS_ARCHIVE          BIL_DAY_INV_CTR_ARC            Y2017_Q1_M01_D01                      1 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          BIL_HIS_DETAIL_FAC_ARC         Y2016_Q2_M05_D04                      1 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          BIL_HIS_DETAIL_FAC_ARC         Y2016_Q2_M05_D09                      2 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          BIL_MTH_INV_CTR_ARC            Y2017_Q1_M01_D01                      1 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          FAH_DAY_CBA_BGAAP_ARC          Y2011_Q4_M12_D30                      1 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          FAH_DAY_CBA_BGAAP_ARC          Y2011_Q4_M12_D31                      2 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          FAH_DAY_CBA_IFRS_ARC           Y2011_Q4_M12_D30                      1 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          FAH_DAY_CBA_IFRS_ARC           Y2011_Q4_M12_D31                      2 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          FAH_DAY_MVT_BGAAP_ARC          Y2011_Q4_M12_D30                      1 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          FAH_DAY_MVT_BGAAP_ARC          Y2011_Q4_M12_D31                      2 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          FAH_DAY_MVT_BGAAP_ARC          Y2012_Q1_M03_D31                      3 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          FAH_DAY_MVT_BGAAP_ARC          Y2012_Q2_M04_D01                      4 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          FAH_DAY_MVT_BGAAP_ARC          Y2012_Q4_M10_D12                      5 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          FAH_DAY_MVT_BGAAP_ARC          Y2012_Q4_M10_D13                      6 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          FAH_DAY_MVT_BGAAP_ARC          Y2012_Q4_M10_D14                      7 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          FAH_DAY_MVT_BGAAP_ARC_TST      Y2011_Q4_M12_D30                      1 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          FAH_DAY_MVT_BGAAP_ARC_TST      Y2011_Q4_M12_D31                      2 ADS_ARCHIVE&lt;br /&gt;
...&lt;br /&gt;
ADS_ARCHIVE          SBP_HIS_LINES_ARC              P_LS                                  3 ADS_ARCHIVE                  &lt;br /&gt;
ADS_ARCHIVE          THA_DAY_INV_CTR_ARC            Y2011_Q4_M12_D30                      1 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          THA_DAY_INV_CTR_ARC            Y2011_Q4_M12_D31                      2 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          THA_INV_HEAVY_ARC              Y2011_Q4_M12_D30                      1 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          THA_INV_HEAVY_ARC              Y2011_Q4_M12_D31                      2 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          THA_INV_LIGHT_ARC              Y2011_Q4_M12_D30                      1 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          THA_INV_LIGHT_ARC              Y2012_Q4_M10_D12                      2 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          THA_INV_LIGHT_ARC              Y2012_Q4_M10_D13                      3 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          THA_INV_LIGHT_ARC              Y2012_Q4_M10_D15                      4 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          THA_INV_LIGHT_ARC              Y2012_Q4_M10_D16                      5 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          THA_INV_LIGHT_ARC              Y2012_Q4_M10_D17                      6 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          THA_INV_LIGHT_ARC              Y2012_Q4_M10_D18                      7 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          THA_INV_LIGHT_ARC              Y2012_Q4_M10_D19                      8 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          THA_INV_LIGHT_ARC              Y2012_Q4_M10_D20                      9 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          THA_INV_LIGHT_ARC              Y2012_Q4_M10_D21                     10 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          THA_INV_LIGHT_ARC              Y2012_Q4_M10_D22                     11 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          THA_INV_LIGHT_ARC              Y2012_Q4_M10_D23                     12 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          THA_INV_LIGHT_ARC              Y2012_Q4_M10_D24                     13 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          THA_MTH_INV_CTR_ARC            Y2011_Q4_M12_D30                      1 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          THA_MTH_INV_CTR_ARC            Y2011_Q4_M12_D31                      2 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          THA_MTH_INV_CTR_ARC            Y2013_Q2_M04_D30                      3 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          XBD01_TEMP_HIS_ARC             Y2012_Q4_M12_D31                      1 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          T_RPT_RECO_THA_INV_ACC_ARC     Y2011_Q4_M12_D30                      1 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          T_RPT_RECO_THA_INV_ACC_ARC     Y2011_Q4_M12_D31                      2 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          T_RPT_RECO_THA_INV_MTH_ARC     Y2011_Q4_M12_D30                      1 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          T_RPT_RECO_THA_INV_MTH_ARC     Y2011_Q4_M12_D31                      2 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          XBD01_TEMP_HIS_ARC             Y2012_Q4_M12_D31                      1 ADS_ARCHIVE&lt;br /&gt;
ADS_DBA              FAH_DAY_CBA_BGAAP              Y2016_Q3_M07_D12                   1657 ADS_ARCHIVE&lt;br /&gt;
ADS_DBA              FAH_DAY_CBA_BGAAP              Y2016_Q4_M12_D13                   1811 ADS_ARCHIVE&lt;br /&gt;
ADS_DBA              FAH_DAY_MVT_IFRS               Y2016_Q4_M10_D10                   1654 ADS_ARCHIVE&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Capture the tablespace metadata====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set long 1000000&lt;br /&gt;
select dbms_metadata.get_ddl ( &amp;#039;TABLESPACE&amp;#039;, &amp;#039;ADS_ARCHIVE&amp;#039;) from dual&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
produces...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
CREATE TABLESPACE &amp;quot;ADS_ARCHIVE&amp;quot; DATAFILE&lt;br /&gt;
  &amp;#039;/oracle/tst/ora_data3/adst/ads_archive01.dbf&amp;#039; SIZE 104857600&lt;br /&gt;
  AUTOEXTEND ON NEXT 104857600 MAXSIZE 32000M,&lt;br /&gt;
...&lt;br /&gt;
  &amp;#039;/oracle/tst/ora_data3/adst/ads_archive66.dbf&amp;#039; SIZE 104857600&lt;br /&gt;
  AUTOEXTEND ON NEXT 104857600 MAXSIZE 3200M,&lt;br /&gt;
  LOGGING ONLINE PERMANENT BLOCKSIZE 8192&lt;br /&gt;
  EXTENT MANAGEMENT LOCAL AUTOALLOCATE DEFAULT&lt;br /&gt;
 NOCOMPRESS  SEGMENT SPACE MANAGEMENT AUTO&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Capture the tablespace objects&amp;#039; metadata====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cat&amp;lt;&amp;lt;EOCAT &amp;gt;expdp_adst_ads_archive_metadata.par&lt;br /&gt;
userid=&amp;#039;/ as sysdba&amp;#039;&lt;br /&gt;
dumpfile=adst_ads_archive_metadata.dmp&lt;br /&gt;
logfile=expdp_adst_ads_archive_metadata.log&lt;br /&gt;
tablespaces=ADS_ARCHIVE&lt;br /&gt;
parallel=20&lt;br /&gt;
content=metadata_only&lt;br /&gt;
exclude=statistics&lt;br /&gt;
EOCAT&lt;br /&gt;
&lt;br /&gt;
expdp parfile=expdp_adst_ads_archive_metadata.par&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Find the partitions with data from the most recent month====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cat &amp;lt;&amp;lt;EOCAT&amp;gt;/tmp/adst_ads_archive_partitions.sql&lt;br /&gt;
set termo off echo off lines 1000 feedb off headi off newpa none trims on&lt;br /&gt;
spool /tmp/adst_ads_archive_partitions.lst&lt;br /&gt;
select table_owner||&amp;#039;.&amp;#039;||table_name||&amp;#039;:&amp;#039;||partition_name&lt;br /&gt;
from   dba_tab_partitions&lt;br /&gt;
where  tablespace_name = &amp;#039;ADS_ARCHIVE&amp;#039;&lt;br /&gt;
and    partition_name like &amp;#039;Y2017_Q1_M01%&amp;#039;&lt;br /&gt;
/&lt;br /&gt;
spool off&lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;@/tmp/adst_ads_archive_partitions.sql&amp;quot; | sqlplus / as sysdba&lt;br /&gt;
EOCAT&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
produces...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_CBA_BGAAP_ARC:Y2017_Q1_M01_D07&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_IFRS_ARC:Y2017_Q1_M02_D26&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_IFRS_ARC:Y2017_Q1_M02_D25&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_IFRS_ARC:Y2017_Q1_M02_D19&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_IFRS_ARC:Y2017_Q1_M02_D18&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_IFRS_ARC:Y2017_Q1_M02_D12&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_IFRS_ARC:Y2017_Q1_M02_D11&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_IFRS_ARC:Y2017_Q1_M02_D05&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_BGAAP_ARC:Y2017_Q1_M02_D26&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_BGAAP_ARC:Y2017_Q1_M02_D25&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_BGAAP_ARC:Y2017_Q1_M02_D19&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_BGAAP_ARC:Y2017_Q1_M02_D18&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_BGAAP_ARC:Y2017_Q1_M02_D12&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_BGAAP_ARC:Y2017_Q1_M02_D11&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_BGAAP_ARC:Y2017_Q1_M02_D05&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_BGAAP_ARC:Y2017_Q1_M02_D04&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_BGAAP_ARC:Y2017_Q1_M01_D29&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_BGAAP_ARC:Y2017_Q1_M01_D28&lt;br /&gt;
...&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_BGAAP_ARC:Y2017_Q1_M01_D22&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_BGAAP_ARC:Y2017_Q1_M01_D21&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_BGAAP_ARC:Y2017_Q1_M01_D15&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_BGAAP_ARC:Y2017_Q1_M01_D14&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_BGAAP_ARC:Y2017_Q1_M01_D08&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_BGAAP_ARC:Y2017_Q1_M01_D07&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_BGAAP_ARC:Y2017_Q1_M01_D01&lt;br /&gt;
ADS_ARCHIVE.BIL_MTH_INV_CTR_ARC:Y2017_Q1_M01_D01&lt;br /&gt;
ADS_ARCHIVE.BIL_DAY_INV_CTR_ARC:Y2017_Q1_M01_D01&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_IFRS_ARC:Y2017_Q1_M02_D04&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_IFRS_ARC:Y2017_Q1_M01_D29&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_IFRS_ARC:Y2017_Q1_M01_D28&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_IFRS_ARC:Y2017_Q1_M01_D22&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Export the data in these partitions====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cat&amp;lt;&amp;lt;EOCAT &amp;gt;expdp_adst_ads_archive_partitions.par&lt;br /&gt;
userid=&amp;#039;/ as sysdba&amp;#039;&lt;br /&gt;
dumpfile=adst_ads_archive_Y2017_%U.dmp&lt;br /&gt;
logfile=expdp_adst_ads_archive_Y2017.log&lt;br /&gt;
EOCAT&lt;br /&gt;
&lt;br /&gt;
cat /tmp/adst_ads_archive_partitions.lst | perl -p -i -e &amp;#039;s/^/tables=/&amp;#039;g &amp;gt;&amp;gt;expdp_adst_ads_archive_partitions.par&lt;br /&gt;
&lt;br /&gt;
cat&amp;lt;&amp;lt;EOCAT &amp;gt;&amp;gt;expdp_adst_ads_archive_partitions.par&lt;br /&gt;
parallel=20&lt;br /&gt;
exclude=statistics&lt;br /&gt;
EOCAT&lt;br /&gt;
&lt;br /&gt;
expdp parfile=expdp_adst_ads_archive_partitions.par&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Drop the old tablespace====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
drop tablespace ads_archive including contents and datafiles&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Recreate the tablepspace using the metadata capture above====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
create tablespace &amp;quot;ADS_ARCHIVE&amp;quot;&lt;br /&gt;
datafile &amp;#039;/oracle/tst/ora_data3/adst/ads_archive01.dbf&amp;#039; size 100M autoextend on next 50M maxsize unlimited&lt;br /&gt;
,        &amp;#039;/oracle/tst/ora_data3/adst/ads_archive02.dbf&amp;#039; size 100M autoextend on next 50M maxsize unlimited&lt;br /&gt;
,        &amp;#039;/oracle/tst/ora_data3/adst/ads_archive03.dbf&amp;#039; size 100M autoextend on next 50M maxsize unlimited&lt;br /&gt;
,        &amp;#039;/oracle/tst/ora_data3/adst/ads_archive04.dbf&amp;#039; size 100M autoextend on next 50M maxsize unlimited&lt;br /&gt;
,        &amp;#039;/oracle/tst/ora_data3/adst/ads_archive05.dbf&amp;#039; size 100M autoextend on next 50M maxsize unlimited&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Import the tablespace metadata====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cat&amp;lt;&amp;lt;EOCAT &amp;gt;impdp_adst_ads_archive_metadata.par&lt;br /&gt;
userid=&amp;#039;/ as sysdba&amp;#039;&lt;br /&gt;
dumpfile=adst_ads_archive_metadata.dmp&lt;br /&gt;
logfile=impdp_adst_ads_archive_metadata.log&lt;br /&gt;
EOCAT&lt;br /&gt;
&lt;br /&gt;
impdp parfile=impdp_adst_ads_archive_metadata.par&lt;br /&gt;
&lt;br /&gt;
select &amp;#039;alter index &amp;#039;|| owner||&amp;#039;.&amp;#039;||index_name||&amp;#039; rebuild online parallel 8;&amp;#039;&lt;br /&gt;
from   dba_indexes&lt;br /&gt;
where  status = &amp;#039;UNUSABLE&amp;#039;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Import the last month partition data====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cat&amp;lt;&amp;lt;EOCAT &amp;gt;impdp_adst_ads_archive_partitions.par&lt;br /&gt;
userid=&amp;#039;/ as sysdba&amp;#039;&lt;br /&gt;
dumpfile=adst_ads_archive_Y2017_%U.dmp&lt;br /&gt;
logfile=impdp_adst_ads_archive_Y2017.log&lt;br /&gt;
table_exists_action=append&lt;br /&gt;
parallel=20&lt;br /&gt;
EOCAT&lt;br /&gt;
&lt;br /&gt;
impdp parfile=impdp_adst_ads_archive_partitions.par&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Write to a TCP/IP socket from PL/SQL===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
declare&lt;br /&gt;
 bt_conn               utl_tcp.connection;&lt;br /&gt;
 retval                binary_integer;&lt;br /&gt;
 l_sequence            varchar2(30) := &amp;#039;Sequence Number 101021&amp;#039;;&lt;br /&gt;
begin&lt;br /&gt;
 bt_conn := utl_tcp.open_connection(remote_host =&amp;gt; &amp;#039;10.10.1.1&amp;#039;&lt;br /&gt;
                                   ,remote_port =&amp;gt; 5000&lt;br /&gt;
                                   ,tx_timeout =&amp;gt; 1&lt;br /&gt;
                                   )&lt;br /&gt;
 ;&lt;br /&gt;
 retval := utl_tcp.write_line(bt_conn,l_sequence)&lt;br /&gt;
 ;&lt;br /&gt;
 utl_tcp.flush(bt_conn)&lt;br /&gt;
 ;&lt;br /&gt;
 utl_tcp.close_connection(bt_conn)&lt;br /&gt;
 ;&lt;br /&gt;
exception&lt;br /&gt;
 when others then&lt;br /&gt;
  raise_application_error(-20101, sqlerrm)&lt;br /&gt;
  ; &lt;br /&gt;
  utl_tcp.close_connection(bt_conn)&lt;br /&gt;
  ;&lt;br /&gt;
end&lt;br /&gt;
;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
and read from it using netcat in another session&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
nc -lk 5000&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
produces&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Sequence Number 101021&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Execute a script as a different user===&lt;br /&gt;
Some things have to be done as the user and cannot be done as sys (eg. creating and dropping jobs or create and drop a database link)&amp;lt;br /&amp;gt;&lt;br /&gt;
It is possible to login as the user by saving, changing and resetting his password (using identified by values) but using dbms_sys_sql is another option&amp;lt;br /&amp;gt;&lt;br /&gt;
Create a PL/SQL procedure to drop a db link&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
create or replace procedure drop_dblink ( p_schema_name in varchar2&lt;br /&gt;
                                        , p_dblink      in varchar2&lt;br /&gt;
                                        ) is&lt;br /&gt;
    l_plsql   varchar2(1000);&lt;br /&gt;
    l_cur     number;&lt;br /&gt;
    l_uid     number;&lt;br /&gt;
    l_rc      number;&lt;br /&gt;
begin&lt;br /&gt;
    select  du.user_id&lt;br /&gt;
    into    l_uid&lt;br /&gt;
    from    dba_users du&lt;br /&gt;
    where   du.username = p_schema_name&lt;br /&gt;
    ;&lt;br /&gt;
    plsql := &amp;#039;drop database link &amp;quot;&amp;#039;||p_dblink||&amp;#039;&amp;quot;&amp;#039;;&lt;br /&gt;
    l_cur := sys.dbms_sys_sql.open_cursor;&lt;br /&gt;
    sys.dbms_sys_sql.parse_as_user(&lt;br /&gt;
        c             =&amp;gt; l_cur,&lt;br /&gt;
        statement     =&amp;gt; l_plsql,&lt;br /&gt;
        language_flag =&amp;gt; dbms_sql.native,&lt;br /&gt;
        userid        =&amp;gt; l_uid&lt;br /&gt;
    );&lt;br /&gt;
    l_rc := sys.dbms_sys_sql.execute(l_cur);&lt;br /&gt;
    sys.dbms_sys_sql.close_cursor(l_cur);&lt;br /&gt;
end;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Generate the calls to the procedure with the required parameters&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select &amp;#039;exec drop_dblink (&amp;#039;&amp;#039;&amp;#039;|| owner ||&amp;#039;&amp;#039;&amp;#039;&amp;#039;||&amp;#039;, &amp;#039;||&amp;#039;&amp;#039;&amp;#039;&amp;#039;||db_link||&amp;#039;&amp;#039;&amp;#039;&amp;#039;||&amp;#039;);&amp;#039;&lt;br /&gt;
from   dba_db_links&lt;br /&gt;
where  owner   != &amp;#039;PUBLIC&amp;#039;&lt;br /&gt;
and    db_link like &amp;#039;%FTST%&amp;#039;&lt;br /&gt;
or     db_link like &amp;#039;%HDEV%&amp;#039;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
and this reveals the lines to be executed&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
exec drop_dblink (&amp;#039;USER1&amp;#039;, &amp;#039;DBL_FTST.WORLD&amp;#039;);&lt;br /&gt;
exec drop_dblink (&amp;#039;USER1&amp;#039;, &amp;#039;DBL_HDEV.WORLD&amp;#039;);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Drop the procedure when finished with it&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
drop procedure drop_dblink;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
or do it as an anonymous block in one go...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
declare&lt;br /&gt;
    uid number;&lt;br /&gt;
    sqltext varchar2(1000) := &amp;#039;drop database link &amp;quot;&amp;amp;DB_LINK&amp;quot;&amp;#039;;&lt;br /&gt;
    myint integer;&lt;br /&gt;
begin&lt;br /&gt;
    select user_id into uid from dba_users where username = &amp;#039;&amp;amp;USERNAME&amp;#039;;&lt;br /&gt;
    myint:=sys.dbms_sys_sql.open_cursor();&lt;br /&gt;
    sys.dbms_sys_sql.parse_as_user(myint,sqltext,dbms_sql.native,UID);&lt;br /&gt;
    sys.dbms_sys_sql.close_cursor(myint);&lt;br /&gt;
end;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Handling single quote marks inside SQL statements===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SQL&amp;gt; SELECT &amp;#039;D&amp;#039;&amp;#039;COSTA&amp;#039; name FROM DUAL;&lt;br /&gt;
&lt;br /&gt;
NAME&lt;br /&gt;
-------&lt;br /&gt;
D&amp;#039;COSTA&lt;br /&gt;
&lt;br /&gt;
Alternatively, use the 10g+ quoting method:&lt;br /&gt;
&lt;br /&gt;
SQL&amp;gt; SELECT q&amp;#039;$D&amp;#039;COSTA$&amp;#039; NAME FROM DUAL;&lt;br /&gt;
&lt;br /&gt;
NAME&lt;br /&gt;
-------&lt;br /&gt;
D&amp;#039;COSTA&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Run a script on all databases in /etc/oratab===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
export ORAENV_ASK=NO&lt;br /&gt;
for db in `awk -F: &amp;#039;NF &amp;amp;&amp;amp; $1 !~/[#*]/ {print $1}&amp;#039;  /etc/oratab`&lt;br /&gt;
do&lt;br /&gt;
    echo $db&lt;br /&gt;
    ORACLE_SID=$db&lt;br /&gt;
    . oraenv&lt;br /&gt;
    sqlplus -V&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Schedule a cron job to run on the last day of each month===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
0 23 28-31 * * [ $(date -d +1day +%d) -eq 1 ] &amp;amp;&amp;amp; su - oracle -c &amp;quot;dsmc  arch -server=SO_U_`hostname`_ORX_M_SOL &amp;#039;/oracle/export/PV6/expdp_PV6_D_FULL_`date +\%Y\%m\%d`*&amp;#039;&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===How to tell if a year is a leap year or not - using cal instead of reinventing the wheel===&lt;br /&gt;
Test: Why is Julian day 0, 17th November 1858?&amp;lt;br /&amp;gt;&lt;br /&gt;
Pretty comprehensive answer: [http://h71000.www7.hp.com/wizard/wiz_2315.html here] and [http://mentalfloss.com/article/51370/why-our-calendars-skipped-11-days-1752 here]&amp;lt;br /&amp;gt;&lt;br /&gt;
Also attempts to answer the question why typing &amp;#039;cal 09 1752&amp;#039; on Unix systems looks so odd!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
function leap {&lt;br /&gt;
#  This function tells you if the year passed in as a parameter is a leap year or not...&lt;br /&gt;
if [[ $(cal 2 ${1:-$(date &amp;#039;+%Y&amp;#039;)} | egrep &amp;#039;\&amp;lt;[[:digit:]]{1,2}\&amp;gt;&amp;#039; | wc -w) -eq 29 ]]; then&lt;br /&gt;
    leap=&amp;#039;Y&amp;#039;&lt;br /&gt;
else&lt;br /&gt;
    leap=&amp;#039;N&amp;#039;&lt;br /&gt;
fi&lt;br /&gt;
echo ${leap}&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Reset an expired (and/or locked) user password to the same value===&lt;br /&gt;
Can be used to save user passwords for example in a test environment before destroying them with a copy of production.&amp;lt;br /&amp;gt;&lt;br /&gt;
Simple, quick and easy version. Run this then pick and choose the statements you want to run.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 200 pages 200&lt;br /&gt;
col user_list for a200 head &amp;quot;Expired User List&amp;quot;&lt;br /&gt;
&lt;br /&gt;
select &amp;#039;alter user &amp;#039; ||su.name||&amp;#039; identified by values&amp;#039;||&amp;#039;&amp;#039;&amp;#039;&amp;#039;||spare4||&amp;#039;;&amp;#039;||su.password||&amp;#039;&amp;#039;&amp;#039; account unlock;&amp;#039; user_list&lt;br /&gt;
from   sys.user$ su&lt;br /&gt;
,      dba_users du&lt;br /&gt;
where  1=1&lt;br /&gt;
and    su.name              = du.username&lt;br /&gt;
and    du.oracle_maintained = &amp;#039;N&amp;#039;&lt;br /&gt;
and    (account_status      like &amp;#039;EXPIRED%&amp;#039; or account_status like &amp;#039;%LOCKED&amp;#039;)&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
More industrialised version. Create a package.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
create or replace package dba_utils&lt;br /&gt;
as&lt;br /&gt;
    procedure reset_password ( p_userlist in varchar2 );&lt;br /&gt;
end dba_utils;&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
create or replace package body dba_utils&lt;br /&gt;
as&lt;br /&gt;
&lt;br /&gt;
procedure reset_password ( p_userlist in varchar2 )&lt;br /&gt;
is&lt;br /&gt;
    cursor c1 ( p_userlist in varchar2 ) is&lt;br /&gt;
    select username&lt;br /&gt;
    ,      regexp_substr ( dbms_metadata.get_ddl(&amp;#039;USER&amp;#039;, username), &amp;#039;&amp;#039;&amp;#039;[^&amp;#039;&amp;#039;]+&amp;#039;&amp;#039;&amp;#039; ) pwd&lt;br /&gt;
    from   dba_users&lt;br /&gt;
    where  1=1&lt;br /&gt;
    and    username in upper( p_userlist )&lt;br /&gt;
    ;&lt;br /&gt;
begin&lt;br /&gt;
    dbms_output.enable(null);&lt;br /&gt;
    for r1 in c1 ( p_userlist )&lt;br /&gt;
    loop&lt;br /&gt;
        begin&lt;br /&gt;
            execute immediate &amp;#039;alter user &amp;#039; || r1.username || &amp;#039; account unlock&amp;#039;;&lt;br /&gt;
            execute immediate &amp;#039;alter user &amp;#039; || r1.username || &amp;#039; identified by values &amp;#039; || r1.pwd;&lt;br /&gt;
        exception&lt;br /&gt;
        when others then&lt;br /&gt;
            dbms_output.put_line(&amp;#039;Unable to modify user &amp;#039; || r1.username);&lt;br /&gt;
        end;&lt;br /&gt;
    end loop;&lt;br /&gt;
end reset_password;&lt;br /&gt;
&lt;br /&gt;
end dba_utils;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Call it&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set serveroutput on&lt;br /&gt;
exec dba_utils.reset_password (&amp;#039;STUART&amp;#039;);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Latch, mutex and beyond===&lt;br /&gt;
A fine example of how to write scripts from SQL*Plus that interact with the shell underneath&amp;lt;br /&amp;gt;&lt;br /&gt;
Found [https://andreynikolaev.wordpress.com/demonstration-scripts/cursor_pin_s_contention-sql/ here at andreynikolaev.wordpress.com]&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/*&lt;br /&gt;
     This file is part of demos for &amp;quot;Mutex Internals&amp;quot;  seminar v.04.04.2011&lt;br /&gt;
     Andrey S. Nikolaev (Andrey.Nikolaev@rdtex.ru) &lt;br /&gt;
     https://andreynikolaev.wordpress.com &lt;br /&gt;
 &lt;br /&gt;
     &amp;quot;Cursor: pin S&amp;quot; contention testcase.&lt;br /&gt;
 &lt;br /&gt;
     The script spawn several sessions to induce &amp;quot;Cursor: pin S&amp;quot;, &lt;br /&gt;
     creates AWR snapshots and generates AWR report&lt;br /&gt;
 &lt;br /&gt;
     Beware: The script will restart the test database.&lt;br /&gt;
 &lt;br /&gt;
     usage: sqlplus /nolog @cursor_pin_s_contention.sql &amp;lt;parallelism&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
*/ &lt;br /&gt;
connect / as sysdba&lt;br /&gt;
startup force&lt;br /&gt;
set echo off&lt;br /&gt;
set define %&lt;br /&gt;
set verify off&lt;br /&gt;
set head off&lt;br /&gt;
set linesize 300&lt;br /&gt;
 &lt;br /&gt;
/* spawn parallel processes to create load on mutex */&lt;br /&gt;
spool one_thread.tmp&lt;br /&gt;
select &amp;#039;set verify off&amp;#039; from dual;&lt;br /&gt;
select &amp;#039;alter session set session_cached_cursors = 50;&amp;#039; from dual; &lt;br /&gt;
select &amp;#039;begin for i in 1..1000000 loop&amp;#039; from dual;&lt;br /&gt;
select &amp;#039;      execute immediate &amp;#039;&amp;#039;select 1 from dual where 1=2&amp;#039;&amp;#039;;&amp;#039; from dual;&lt;br /&gt;
select &amp;#039;end loop; end;&amp;#039;||chr(10)||&amp;#039;/&amp;#039; from dual;&lt;br /&gt;
spool off&lt;br /&gt;
 &lt;br /&gt;
/* sleep while AWR initialized */&lt;br /&gt;
host sleep 5&lt;br /&gt;
 &lt;br /&gt;
exec dbms_workload_repository.create_snapshot();&lt;br /&gt;
 &lt;br /&gt;
spool many_threads.tmp&lt;br /&gt;
select &amp;#039;host sqlplus &amp;quot;/ as sysdba&amp;quot; @one_thread.tmp &amp;amp;&amp;#039;&lt;br /&gt;
from dba_objects where rownum &amp;lt;= %1;&lt;br /&gt;
spool off&lt;br /&gt;
 &lt;br /&gt;
@many_threads.tmp&lt;br /&gt;
host sleep 50&lt;br /&gt;
set echo on&lt;br /&gt;
exec dbms_workload_repository.create_snapshot();&lt;br /&gt;
set markup html on&lt;br /&gt;
set head on&lt;br /&gt;
spool mutex_sleep_history.htm&lt;br /&gt;
select to_char(SLEEP_TIMESTAMP,&amp;#039;hh:mi:ss.ff&amp;#039;) SLEEP_TIMESTAMP,MUTEX_ADDR,MUTEX_IDENTIFIER,MUTEX_TYPE,&lt;br /&gt;
       GETS,SLEEPS,REQUESTING_SESSION,BLOCKING_SESSION,&lt;br /&gt;
       LOCATION,MUTEX_VALUE from x$mutex_sleep_history order by sleep_timestamp;&lt;br /&gt;
spool off&lt;br /&gt;
 &lt;br /&gt;
set define &amp;amp;&lt;br /&gt;
set markup html off&lt;br /&gt;
set echo off heading on underline on;&lt;br /&gt;
column inst_num  heading &amp;quot;Inst Num&amp;quot;  new_value inst_num  format 99999;&lt;br /&gt;
column inst_name heading &amp;quot;Instance&amp;quot;  new_value inst_name format a12;&lt;br /&gt;
column db_name   heading &amp;quot;DB Name&amp;quot;   new_value db_name   format a12;&lt;br /&gt;
column dbid      heading &amp;quot;DB Id&amp;quot;     new_value dbid      format 9999999999 just c;&lt;br /&gt;
select d.dbid            dbid&lt;br /&gt;
     , d.name            db_name&lt;br /&gt;
     , i.instance_number inst_num&lt;br /&gt;
     , i.instance_name   inst_name&lt;br /&gt;
  from v$database d,&lt;br /&gt;
       v$instance i;&lt;br /&gt;
define num_days=1;&lt;br /&gt;
define report_type=&amp;#039;html&amp;#039;;&lt;br /&gt;
col end_snap new_value end_snap;&lt;br /&gt;
col begin_snap new_value begin_snap;&lt;br /&gt;
select max(snap_id) end_snap from dba_hist_snapshot where dbid=&amp;amp;dbid;&lt;br /&gt;
select max(snap_id) begin_snap from dba_hist_snapshot where dbid=&amp;amp;dbid and snap_id &amp;lt; &amp;amp;end_snap;&lt;br /&gt;
define report_name=&amp;#039;awr_report.htm&amp;#039;;&lt;br /&gt;
@?/rdbms/admin/awrrpti&lt;br /&gt;
exit&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==shell==&lt;br /&gt;
[http://www.databasejournal.com/features/oracle/article.php/3869076/Alert-Log-Scraping-with-Oracles-ADRCI-Utility.htm Alert Log scraping with ADRCI]&lt;br /&gt;
&lt;br /&gt;
====Count the number of background processes for a particular SID====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SID=RAVJDE1&lt;br /&gt;
ps -ef|cut -c54-100|awk -v SID=$SID &amp;#039;$0 ~ /&amp;#039;$SID&amp;#039;$/ {print}&amp;#039;|wc -l&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or ...this will work with any OS (so long as the process is at the end of the &amp;lt;strong&amp;gt;ps -ef&amp;lt;/strong&amp;gt; or &amp;lt;strong&amp;gt;ps -aux&amp;lt;/strong&amp;gt; listing&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SID=RAVJDE1&lt;br /&gt;
ps -ef|awk -v SID=$SID -F_ &amp;#039;{ $NF ~ /&amp;#039;$SID&amp;#039;$/ {print} }&amp;#039;|wc -l&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Pick the columns you want in the ps listing&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ps -efo user,pid,ppid=MOM -o args&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Find Oracle errors in the most recent DataPump log files====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
00 09 * * * /home/tools/scripts/oracle/dosh &amp;#039;find /oracle/export -name &amp;quot;expdp*log&amp;quot; -mtime -1 -exec grep ORA- {} \; -ls&amp;#039; | mailx -s &amp;#039;Datapump errors for &amp;lt;customer&amp;gt;last night&amp;#039; stuart@domain.com&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Find the 10 largest directories on a particular filesystem====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
du -ag /oracle | sort -nr | head -n 10&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Find the 10 largest files on a particular mount point====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
find /home -size +1G -ls | sort -nr +6 | head -10&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
find /home -xdev -ls | sort -nr +6 | head -10&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Split a file in pieces using sed====&lt;br /&gt;
Using fixed line numbers&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sed -ne &amp;#039;1,12p&amp;#039; file &amp;gt; text.part1&lt;br /&gt;
sed -ne &amp;#039;13,$p&amp;#039; file &amp;gt; text.part2&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Using line with a /pattern/ on it&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sed -e &amp;#039;/hello/q&amp;#039; tt.dat | grep -v hello &amp;gt; text.part1&lt;br /&gt;
sed -n `sed -n &amp;#039;/hello/=&amp;#039; tt.dat`&amp;#039;,$p&amp;#039; tt.dat | grep -v hello &amp;gt; text.part2&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Split a file in pieces using Perl====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
perl -ne &amp;#039;print if 1 .. /marker line/&amp;#039; text.dat &amp;gt;text.part1&lt;br /&gt;
perl -ne &amp;#039;print if /marker line/ .. eof()&amp;#039; text.dat &amp;gt;text.part2&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Find and display RMAN errors in an RMAN log file====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sed -ne &amp;#039;/^RMAN-/,/^$/p&amp;#039;  RMAN_&amp;lt;SID&amp;gt;_&amp;lt;DATE&amp;gt;.log&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==cmd==&lt;br /&gt;
*[http://www.dba-oracle.com/t_scripts_windows_export.htm Database Export - from DBA Oracle (Burleson)]&lt;br /&gt;
==Perl==&lt;br /&gt;
===For all files in a directory, replace a keyword (SSIIDD) in a file with another (a parameter)===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
for i in `ls`&lt;br /&gt;
do&lt;br /&gt;
    perl -p -i -e &amp;#039;s/SSIIDD/&amp;#039;$SID&amp;#039;/g&amp;#039; $i&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Parse tnsnames.ora to get just the service names===&lt;br /&gt;
[[http://stackoverflow.com/questions/12605415/parsing-tnsnames-ora-with-regex-to-just-get-name from here]]&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
perl -ne &amp;#039;print if m/^([^#()\W ][a-zA-Z.]*(?:[.][a-zA-Z]*\s?=)?)/&amp;#039; $TNS_ADMIN/tnsnames.ora&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===and use that to check the listener status===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
for svc in `perl -ne &amp;#039;print if m/^([^#()\W ][a-zA-Z.]*(?:[.][a-zA-Z]*\s?=)?)/&amp;#039; $TNS_ADMIN/tnsnames.ora | sed -e &amp;#039;s/=//&amp;#039;` ;do&lt;br /&gt;
    tnsping $svc&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Stuart</name></author>	</entry>

	<entry>
		<id>https://mailnest.com/dbawiki/index.php?title=Handy_scripts&amp;diff=3370</id>
		<title>Handy scripts</title>
		<link rel="alternate" type="text/html" href="https://mailnest.com/dbawiki/index.php?title=Handy_scripts&amp;diff=3370"/>
				<updated>2018-11-21T11:54:37Z</updated>
		
		<summary type="html">&lt;p&gt;Stuart: /* Start the job */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==SQL==&lt;br /&gt;
* [[Database Overview - from idevelopment]] [http://www.idevelopment.info/data/Oracle/DBA_scripts/Database_Administration/dba_snapshot_database_10g.sql online version]&lt;br /&gt;
* [[Extract ddl with &amp;quot;dbms metadata.get ddl&amp;quot;]]&lt;br /&gt;
* [http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:83012348058 Connecting as another user via proxy in SQL*Plus]&lt;br /&gt;
* [http://www.petefinnigan.com/tools.htm Password cracker and role and priv tools from Pete Finnigan]&lt;br /&gt;
* [http://www.oracle.com/technetwork/articles/sql/11g-pivot-097235.html Using pivot tables in SQL - XML and XLS (Excel) also)]&lt;br /&gt;
===List all instances running on a server===&lt;br /&gt;
Sounds simple enough and indeed pre 12.1, is was as easy as either&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ps -ef | grep [p]mon | awk -F_ &amp;#039;{print $NF}&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or this one is safer in case you have an underscore character in your SID name!!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SIDLIST=$(${PS} -ef | ${GREP} [o]ra_pmon | ${AWK} &amp;#039;{print $NF}&amp;#039; | sed -e &amp;#039;s/ora_pmon_//&amp;#039; | egrep -v &amp;#039;grep|///|sed|awk|ASM|^$&amp;#039;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
but now we have the added complication of CDB/PDB (container / pluggable databases) so a fair bit more work is needed!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/ksh&lt;br /&gt;
# ==============================================================================&lt;br /&gt;
# Name         : list_server_db&lt;br /&gt;
# Description  : List all running databases found on a server&lt;br /&gt;
#&lt;br /&gt;
# Parameters   : none&lt;br /&gt;
#&lt;br /&gt;
# Notes        : none&lt;br /&gt;
#&lt;br /&gt;
# Modification History&lt;br /&gt;
# ====================&lt;br /&gt;
# When      Who               What&lt;br /&gt;
# ========= ================= ==================================================&lt;br /&gt;
# 21-DEC-16 Stuart Barkley    Created&lt;br /&gt;
# ==============================================================================&lt;br /&gt;
for db in $(ps -ef | grep [p]mon|awk -F_ &amp;#039;{print $NF}&amp;#039;)&lt;br /&gt;
do&lt;br /&gt;
    export ORACLE_SID=${db}&lt;br /&gt;
    ORAENV_ASK=NO&lt;br /&gt;
    . oraenv &amp;gt;/dev/null 2&amp;gt;&amp;amp;1&lt;br /&gt;
    sqlplus -s / as sysdba&amp;lt;&amp;lt;EOSQL&lt;br /&gt;
set serveroutput on feed off pages 0 head off newpa none&lt;br /&gt;
declare&lt;br /&gt;
    e_col_not_found exception;&lt;br /&gt;
    e_not_mounted   exception;&lt;br /&gt;
    pragma          exception_init(e_not_mounted, -01507);&lt;br /&gt;
    pragma          exception_init(e_col_not_found, -904);&lt;br /&gt;
    l_db_name       varchar2(20);&lt;br /&gt;
    l_database_role varchar2(20);&lt;br /&gt;
    l_cdb           varchar2(20);&lt;br /&gt;
    l_status        varchar2(20);&lt;br /&gt;
    type varchar2_tab is table of varchar2(240) index by binary_integer;&lt;br /&gt;
    t_pdbs          varchar2_tab;&lt;br /&gt;
begin&lt;br /&gt;
    begin&lt;br /&gt;
        dbms_output.enable(null);&lt;br /&gt;
        execute immediate &amp;#039;select name, database_role, cdb from v\$database&amp;#039; into l_db_name, l_database_role, l_cdb;&lt;br /&gt;
        if l_cdb = &amp;#039;YES&amp;#039; then&lt;br /&gt;
            l_status := &amp;#039;CDB&amp;#039;;&lt;br /&gt;
            execute immediate &amp;#039;select name from v\$pdbs&amp;#039; bulk collect into t_pdbs;&lt;br /&gt;
            for i in nvl(t_pdbs.first,1) .. nvl(t_pdbs.last,0)&lt;br /&gt;
            loop&lt;br /&gt;
                dbms_output.put_line (t_pdbs(i)||&amp;#039;:PDB&amp;#039;);&lt;br /&gt;
            end loop;&lt;br /&gt;
        else&lt;br /&gt;
            l_status := &amp;#039;Independent&amp;#039;;  -- col CDB exists but this is not one&lt;br /&gt;
        end if;&lt;br /&gt;
        if l_database_role like &amp;#039;%STANDBY%&amp;#039; then&lt;br /&gt;
            l_status := &amp;#039;Standby&amp;#039;;&lt;br /&gt;
        end if;&lt;br /&gt;
    exception&lt;br /&gt;
    when e_not_mounted then&lt;br /&gt;
        l_status := &amp;#039;Not Mounted&amp;#039;;&lt;br /&gt;
    when e_col_not_found then&lt;br /&gt;
        l_status := &amp;#039;pre12&amp;#039;;&lt;br /&gt;
    end;&lt;br /&gt;
&lt;br /&gt;
    dbms_output.put_line (&amp;#039;${db}&amp;#039;||&amp;#039;:&amp;#039;||l_status);&lt;br /&gt;
&lt;br /&gt;
end;&lt;br /&gt;
/&lt;br /&gt;
EOSQL&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Run a command or script on all databases in tnsnames.ora===&lt;br /&gt;
Very handy if you have a global tnsnames.ora accessible to all clients.&amp;lt;br /&amp;gt;&lt;br /&gt;
So from a client install, this has access to all databases.&amp;lt;br /&amp;gt;&lt;br /&gt;
Any files created can be created on the client so no need to scp to all the machines to recover spool files etc.&amp;lt;br /&amp;gt;&lt;br /&gt;
Downside: Cannot connect as sysdba across tns so password will need to be known for whatever user is used.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/ksh&lt;br /&gt;
TNSNAMES=&amp;quot;./tnsnames.ora&amp;quot;&lt;br /&gt;
[[ ! -r &amp;quot;${TNSNAMES}&amp;quot; ]] &amp;amp;&amp;amp; echo &amp;quot;${TNSNAMES} is not accessible&amp;quot; &amp;amp;&amp;amp; exit 1&lt;br /&gt;
&lt;br /&gt;
SIDLIST=$(perl -ne &amp;#039;print &amp;quot;$1\n&amp;quot; if /(?:SID|SERVICE_NAME)\s*=\s*(\S+?)\)/&amp;#039; ${TNSNAMES}|sort|uniq|xargs)&lt;br /&gt;
for SID in ${SIDLIST}&lt;br /&gt;
do&lt;br /&gt;
    echo &amp;quot;Processing $SID&amp;quot;&lt;br /&gt;
    ls -al | grep &amp;quot;^d&amp;quot; | grep &amp;quot;\_${SID}&amp;quot; &amp;gt;/dev/null&lt;br /&gt;
    if [[ $? -ne 0 ]]; then&lt;br /&gt;
        echo &amp;#039;exit&amp;#039; | sqlplus system/xxxxxx@${SID} @ReviewLite17.1.sql &amp;gt;/dev/null 2&amp;gt;&amp;amp;1&lt;br /&gt;
    else&lt;br /&gt;
        echo &amp;quot;directory already exists so must have done this SID&amp;quot;&lt;br /&gt;
    fi&lt;br /&gt;
done&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Run a command or script on all databases in oratab===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/usr/bin/ksh&lt;br /&gt;
# ==============================================================================&lt;br /&gt;
# Name         : all_db_do&lt;br /&gt;
# Description  : Loops over all the databases in oratab and executes the&lt;br /&gt;
#                specified SQL command - be careful!&lt;br /&gt;
#&lt;br /&gt;
# Parameters   : -v flag for verbose&lt;br /&gt;
#                [-f &amp;lt;filename&amp;gt; | &amp;lt;quoted SQL command to be executed&amp;gt;]&lt;br /&gt;
#&lt;br /&gt;
# Example      : all_db_do &amp;#039;alter system switch logfile;&amp;#039;&lt;br /&gt;
#                all_db_do -f sessions.sql&lt;br /&gt;
#&lt;br /&gt;
# Notes        : none&lt;br /&gt;
#&lt;br /&gt;
# Modification History&lt;br /&gt;
# ====================&lt;br /&gt;
# When      Who               What&lt;br /&gt;
# ========= ================= ==================================================&lt;br /&gt;
# 14-JAN-13 Stuart Barkley    Created&lt;br /&gt;
# 25-FEB-13 Stuart Barkley    Adapt for Solaris&lt;br /&gt;
# 21-MAR-13 Stuart Barkley    Check db is running first&lt;br /&gt;
# 29-APR-13 Stuart Barkley    Added verbose flag processing&lt;br /&gt;
# 24-MAY-13 Stuart Barkley    Wrap / as sysdba in quotes for older versions&lt;br /&gt;
# 23-JUN-16 Stuart Barkley    Add -f to run a file containing sql&lt;br /&gt;
# ==============================================================================&lt;br /&gt;
&lt;br /&gt;
PROGNAME=$(basename $0)&lt;br /&gt;
OS=$(uname -s)&lt;br /&gt;
&lt;br /&gt;
AWK=$(which awk)&lt;br /&gt;
GREP=$(which grep)&lt;br /&gt;
if [[ &amp;quot;${OS}&amp;quot; == &amp;quot;SunOS&amp;quot; ]]; then&lt;br /&gt;
    AWK=/usr/xpg4/bin/awk&lt;br /&gt;
    GREP=/usr/xpg4/bin/grep&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
if [[ ! -r /etc/oratab ]]; then&lt;br /&gt;
    if [[ &amp;quot;${OS}&amp;quot; == &amp;quot;SunOS&amp;quot; ]]; then&lt;br /&gt;
        echo &amp;quot;oratab is not where we want it. Please run &amp;#039;ln -s /var/opt/oracle/oratab /etc/oratab&amp;#039; as root and retry&amp;quot; &amp;amp;&amp;amp; exit 1&lt;br /&gt;
    else&lt;br /&gt;
        echo &amp;quot;Either Oracle is not installed or database is running without an oratab&amp;quot; &amp;amp;&amp;amp; exit 1&lt;br /&gt;
    fi&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
# -------------------------&lt;br /&gt;
# get the arguments, if any&lt;br /&gt;
# -------------------------&lt;br /&gt;
unset VERBOSE&lt;br /&gt;
while getopts &amp;quot;vf:&amp;quot; flag&lt;br /&gt;
do&lt;br /&gt;
    case &amp;quot;$flag&amp;quot; in&lt;br /&gt;
    v) VERBOSE=1;;&lt;br /&gt;
    f) FILE2RUN=$OPTARG;;&lt;br /&gt;
    esac&lt;br /&gt;
done&lt;br /&gt;
shift $((OPTIND-1))&lt;br /&gt;
&lt;br /&gt;
if [[ -z ${FILE2RUN} ]]; then&lt;br /&gt;
    # no file, need an SQL supplied&lt;br /&gt;
    if [[ -z $1 ]]; then&lt;br /&gt;
        echo &amp;quot;Usage: $0 [-v] [-f &amp;lt;filename&amp;gt; | &amp;lt;quoted SQL command to be executed&amp;gt;]&amp;quot;&lt;br /&gt;
        echo &amp;quot;eg: $0 -f sessions.sql&amp;quot;&lt;br /&gt;
        echo &amp;quot;eg: $0 &amp;#039;alter system switch logfile;&amp;#039;&amp;quot;&lt;br /&gt;
        exit 1&lt;br /&gt;
    fi&lt;br /&gt;
    SQL=$1&lt;br /&gt;
elif [[ -s ${FILE2RUN} ]]; then&lt;br /&gt;
    # file supplied and exists&lt;br /&gt;
    SQL=&amp;quot;@${FILE2RUN}&amp;quot;&lt;br /&gt;
else&lt;br /&gt;
    # file supplied, does it exist&lt;br /&gt;
    echo &amp;quot;File ${FILE2RUN} is empty or does not exist&amp;quot;&lt;br /&gt;
    echo &amp;quot;Usage: $0 [-v] [-f &amp;lt;filename&amp;gt; | &amp;lt;quoted SQL command to be executed&amp;gt;]&amp;quot;&lt;br /&gt;
    echo &amp;quot;eg: $0 -f sessions.sql&amp;quot;&lt;br /&gt;
    echo &amp;quot;eg: $0 &amp;#039;alter system switch logfile;&amp;#039;&amp;quot;&lt;br /&gt;
    exit 1&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
export ORAENV_ASK=NO&lt;br /&gt;
&lt;br /&gt;
for db in $(${AWK} -F: &amp;#039;NF &amp;amp;&amp;amp; $1 !~/[#*]/ {print $1}&amp;#039;  /etc/oratab)&lt;br /&gt;
do&lt;br /&gt;
    if ( [[ $1 != &amp;quot;startup&amp;quot; ]] &amp;amp;&amp;amp; [[ $(ps -ef | ${GREP} -c -E [o]ra_pmon_${db}) -eq 0 ]] ); then&lt;br /&gt;
        [[ ! -z &amp;quot;$VERBOSE&amp;quot; ]] &amp;amp;&amp;amp; echo &amp;quot;$db is not running, skipping...&amp;quot;&lt;br /&gt;
        continue&lt;br /&gt;
    fi&lt;br /&gt;
    echo&lt;br /&gt;
    [[ ! -z &amp;quot;$VERBOSE&amp;quot; ]] &amp;amp;&amp;amp; echo &amp;quot;vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv&amp;quot;&lt;br /&gt;
    [[ ! -z &amp;quot;$VERBOSE&amp;quot; ]] &amp;amp;&amp;amp; echo $db&lt;br /&gt;
    ORACLE_SID=$db&lt;br /&gt;
    . oraenv &amp;gt;/dev/null&lt;br /&gt;
    sqlplus -s &amp;quot;/ as sysdba&amp;quot; &amp;lt;&amp;lt;EOSQL&lt;br /&gt;
define SID=$ORACLE_SID&lt;br /&gt;
col comp_name format a50&lt;br /&gt;
col value for a40&lt;br /&gt;
set linesize 1000&lt;br /&gt;
set pagesize 100&lt;br /&gt;
$SQL&lt;br /&gt;
EOSQL&lt;br /&gt;
    [[ ! -z &amp;quot;$VERBOSE&amp;quot; ]] &amp;amp;&amp;amp; echo &amp;quot;^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^&amp;quot;&lt;br /&gt;
done&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
all_db_do &amp;quot;create or replace directory data_pump_dir as &amp;#039;/oracle/export/&amp;amp;SID&amp;#039;;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
all_db_do &amp;quot;archive log list&amp;quot;&lt;br /&gt;
&lt;br /&gt;
all_db_do &amp;quot;shutdown immediate&amp;quot;&lt;br /&gt;
&lt;br /&gt;
all_db_do &amp;#039;alter system set log_archive_dest_1=&amp;quot;location=/oracle/arch/&amp;amp;SID&amp;quot; scope=both;&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Run an SQL command on behalf of another user===&lt;br /&gt;
It can be used to execute any sql command as a specified user provided this procedure is created in sys schema.&amp;lt;br /&amp;gt;&lt;br /&gt;
* not got this working properly yet *&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set serveroutput on&lt;br /&gt;
create or replace procedure run_sql_as_user ( p_schema_name in varchar2&lt;br /&gt;
                                            , p_sql         in varchar2&lt;br /&gt;
                                            ) is&lt;br /&gt;
    l_user_id dba_users.user_id%type;&lt;br /&gt;
    l_cursor  number;&lt;br /&gt;
    l_rc      number;&lt;br /&gt;
begin&lt;br /&gt;
    dbms_output.enable(null);&lt;br /&gt;
    begin&lt;br /&gt;
        select u.user_id&lt;br /&gt;
        into   l_user_id&lt;br /&gt;
        from   dba_users u&lt;br /&gt;
        where  u.username = p_schema_name;&lt;br /&gt;
    exception&lt;br /&gt;
    when no_data_found then&lt;br /&gt;
        raise_application_error (-20001, &amp;#039;Cannot find user &amp;#039;||p_schema_name);&lt;br /&gt;
    end;&lt;br /&gt;
    l_cursor := dbms_sys_sql.open_cursor;&lt;br /&gt;
    dbms_sys_sql.parse_as_user ( c             =&amp;gt; l_cursor&lt;br /&gt;
                               , statement     =&amp;gt; p_sql&lt;br /&gt;
                               , language_flag =&amp;gt; dbms_sql.native&lt;br /&gt;
                               , userid        =&amp;gt; l_user_id&lt;br /&gt;
    );&lt;br /&gt;
    l_rc := dbms_sys_sql.execute(l_cursor);&lt;br /&gt;
    dbms_sys_sql.close_cursor(l_cursor);&lt;br /&gt;
exception&lt;br /&gt;
when others then&lt;br /&gt;
    raise_application_error (-20001, &amp;#039;ERROR: &amp;#039;||sqlerrm);&lt;br /&gt;
end;&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Run a script on all databases listed in tnsnames.ora===&lt;br /&gt;
Can run an SQL command file on all SID/SERVICE found in a tnsnames.ora file. I use this from a client laptop having a global tns file on it.&amp;lt;br /&amp;gt;&lt;br /&gt;
This way it&amp;#039;s not necessary to copy the file onto every host before executing it. Any files created by the script will be created on the client.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/ksh&lt;br /&gt;
&lt;br /&gt;
TNSNAMES=&amp;quot;./tnsnames.ora&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[ ! -r &amp;quot;${TNSNAMES}&amp;quot; ]] &amp;amp;&amp;amp; echo &amp;quot;${TNSNAMES} is not accessible&amp;quot; &amp;amp;&amp;amp; exit 1&lt;br /&gt;
&lt;br /&gt;
SIDLIST=$(perl -ne &amp;#039;print &amp;quot;$1\n&amp;quot; if /(?:SID|SERVICE_NAME)\s*=\s*(\S+?)\)/&amp;#039; ${TNSNAMES}|sort|uniq|xargs)&lt;br /&gt;
for SID in ${SIDLIST}&lt;br /&gt;
do&lt;br /&gt;
    echo &amp;quot;Processing $SID&amp;quot;&lt;br /&gt;
    ls -al | grep &amp;quot;^d&amp;quot; | grep &amp;quot;\_${SID}&amp;quot; &amp;gt;/dev/null&lt;br /&gt;
    if [[ $? -ne 0 ]]; then&lt;br /&gt;
        echo &amp;#039;exit&amp;#039; | sqlplus system/password@${SID} @ReviewLite17.1.sql &amp;gt;/dev/null 2&amp;gt;&amp;amp;1&lt;br /&gt;
    else&lt;br /&gt;
        echo &amp;quot;directory already exists so must have done this SID&amp;quot;&lt;br /&gt;
    fi&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===List invalid objects===&lt;br /&gt;
 set lines 200&lt;br /&gt;
 set pages 200&lt;br /&gt;
 col obj format a40&lt;br /&gt;
 select owner||&amp;#039;.&amp;#039;||object_name obj&lt;br /&gt;
 ,      object_type&lt;br /&gt;
 from   dba_objects&lt;br /&gt;
 where  1=1&lt;br /&gt;
 and    status = &amp;#039;INVALID&amp;#039;;&lt;br /&gt;
===Recompile all invalid objects===&lt;br /&gt;
@?/rdbms/admin/utlrp.sql&lt;br /&gt;
===See how much space is left in the flash recovery area (FRA)===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select name&lt;br /&gt;
,      to_char (space_limit, &amp;#039;999,999,999,999&amp;#039;) as space_limit&lt;br /&gt;
,      to_char (space_limit - space_used + space_reclaimable&lt;br /&gt;
,               &amp;#039;999,999,999,999&amp;#039;)&lt;br /&gt;
           as space_available&lt;br /&gt;
,      round ( (space_used - space_reclaimable) / space_limit * 100, 1)&lt;br /&gt;
           as pct_full&lt;br /&gt;
from   v$recovery_file_dest;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# ==============================================&lt;br /&gt;
# Check FRA to see how much space is reclaimable&lt;br /&gt;
# ==============================================&lt;br /&gt;
fra_reclaim_check() {&lt;br /&gt;
&lt;br /&gt;
LOGFILE=${RMAN_LogDir}/${ORACLE_SID}_`date &amp;#039;+%Y%m&amp;#039;`_${V_SCRIPT}.log&lt;br /&gt;
sqlplus &amp;quot;/ as sysdba&amp;quot; &amp;lt;&amp;lt;EOSQL &amp;gt; /tmp/results.$$&lt;br /&gt;
set vefify off echo off heading off newpage none linesize 1000 echo off&lt;br /&gt;
select &amp;#039;Filesystem:&amp;#039;||name||&lt;br /&gt;
       &amp;#039;; Total(Gb):&amp;#039;||round((space_limit/1073741824),2) ||&lt;br /&gt;
       &amp;#039;; Reclaimable(Gb):&amp;#039;||round((space_reclaimable/1073741824),2) ||&lt;br /&gt;
       &amp;#039;; Reclaimable(%):&amp;#039;||round( ((space_reclaimable/1073741824)/(space_limit/1073741824)*100),2 )&lt;br /&gt;
from   v$recovery_file_dest&lt;br /&gt;
/&lt;br /&gt;
EOSQL&lt;br /&gt;
cat /tmp/results.$$ &amp;gt;&amp;gt; $LOGFILE&lt;br /&gt;
rm /tmp/results.$$&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===How far back can we flashback?===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
col time_now              for a25&lt;br /&gt;
col time_oldest_flashback for a25&lt;br /&gt;
select to_char(sysdate,&amp;#039;DD-MON-YY HH24:MI&amp;#039;)                    time_now&lt;br /&gt;
,      to_char(fdl.oldest_flashback_time, &amp;#039;DD-MON-YY HH24:MI&amp;#039;) time_oldest_flashback&lt;br /&gt;
,      round((sysdate-fdl.oldest_flashback_time)*24,1)         hours_flashback_possible&lt;br /&gt;
from   v$database d&lt;br /&gt;
,      v$flashback_database_log fdl&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===DBA privs tables===&lt;br /&gt;
 DBA_AQ_AGENT_PRIVS&lt;br /&gt;
 DBA_COL_PRIVS&lt;br /&gt;
 DBA_PRIV_AUDIT_OPTS&lt;br /&gt;
 DBA_REPGROUP_PRIVILEGES&lt;br /&gt;
 DBA_ROLE_PRIVS&lt;br /&gt;
 DBA_RSRC_CONSUMER_GROUP_PRIVS&lt;br /&gt;
 DBA_RSRC_MANAGER_SYSTEM_PRIVS&lt;br /&gt;
 DBA_SYS_PRIVS&lt;br /&gt;
 DBA_TAB_PRIVS&lt;br /&gt;
 DBA_WM_SYS_PRIVS&lt;br /&gt;
 DBA_WORKSPACE_PRIVS&lt;br /&gt;
&lt;br /&gt;
===Schedule a shell job===&lt;br /&gt;
 begin&lt;br /&gt;
     dbms_scheduler.create_program ( program_name   =&amp;gt; &amp;#039;myshelljob&amp;#039;&lt;br /&gt;
                                   , program_action =&amp;gt; &amp;#039;/home/oracle/scripts/shell.sh&amp;#039;&lt;br /&gt;
                                   , program_type   =&amp;gt; &amp;#039;EXECUTABLE&amp;#039;&lt;br /&gt;
                                   , comments       =&amp;gt; &amp;#039;Run a shell&amp;#039;&lt;br /&gt;
                                   , enabled        =&amp;gt; TRUE&lt;br /&gt;
                                   );&lt;br /&gt;
 end;&lt;br /&gt;
 /&lt;br /&gt;
===Start the job===&lt;br /&gt;
 begin&lt;br /&gt;
     dbms_sheduler.create_job ( job_name     =&amp;gt; &amp;#039;myshelljob&amp;#039;&lt;br /&gt;
                              , program_name =&amp;gt; &amp;#039;myshelljob&amp;#039;&lt;br /&gt;
                              , start_date   =&amp;gt;&lt;br /&gt;
                              );&lt;br /&gt;
 /&lt;br /&gt;
&lt;br /&gt;
===What statement is a user running?===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select a.sid&lt;br /&gt;
,      a.serial#&lt;br /&gt;
,      b.sql_text&lt;br /&gt;
from   v$session a&lt;br /&gt;
,      v$sqlarea b&lt;br /&gt;
where  a.sql_address = b.address&lt;br /&gt;
and    a.username    = &amp;#039;&amp;amp;username&amp;#039;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===See what statements all users are running===&lt;br /&gt;
Useful to see what is happening when process limit is reached&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 300 pages 1000&lt;br /&gt;
&lt;br /&gt;
col username for a10&lt;br /&gt;
col command for 999 head &amp;quot;CMD&amp;quot;&lt;br /&gt;
col lockwait for a10&lt;br /&gt;
col status for a8&lt;br /&gt;
col schemaname for a12&lt;br /&gt;
col osuser for a10&lt;br /&gt;
col process for a10&lt;br /&gt;
col program for a20&lt;br /&gt;
col machine for a10&lt;br /&gt;
col action for a10&lt;br /&gt;
col module for a10&lt;br /&gt;
col identifier for a10&lt;br /&gt;
col event for a27&lt;br /&gt;
col state for a8&lt;br /&gt;
col service_name for a10&lt;br /&gt;
col serial# for 999999&lt;br /&gt;
&lt;br /&gt;
select a.username&lt;br /&gt;
,      a.command&lt;br /&gt;
,      a.lockwait&lt;br /&gt;
,      a.status&lt;br /&gt;
,      a.schemaname&lt;br /&gt;
,      a.osuser&lt;br /&gt;
,      a.process&lt;br /&gt;
,      a.machine&lt;br /&gt;
,      a.program&lt;br /&gt;
,      a.type&lt;br /&gt;
--,      a.sql_exec_start&lt;br /&gt;
--,      a.plsql_object_id&lt;br /&gt;
--,      a.plsql_subprogram_id&lt;br /&gt;
--,      a.module&lt;br /&gt;
--,      a.action&lt;br /&gt;
,      a.logon_time&lt;br /&gt;
,      a.event&lt;br /&gt;
,      a.wait_time&lt;br /&gt;
,      a.seconds_in_wait&lt;br /&gt;
,      a.state&lt;br /&gt;
--,      a.service_name&lt;br /&gt;
,      a.serial#&lt;br /&gt;
,      b.sql_text&lt;br /&gt;
from   v$session a&lt;br /&gt;
,      v$sqlarea b&lt;br /&gt;
where  a.sql_address = b.address&lt;br /&gt;
order  by a.logon_time desc&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
set lines 80&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===A logminer session===&lt;br /&gt;
Mine all SQL statements in a 10 minute period&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sqlplus / as sysdba&lt;br /&gt;
alter session set nls_date_format = &amp;#039;DD-MON-YYYY HH24:MI:SS&amp;#039;;&lt;br /&gt;
execute dbms_logmnr.start_logmnr ( starttime =&amp;gt; &amp;#039;27-OCT-2009 11:05:00&amp;#039;&lt;br /&gt;
                                 , endtime   =&amp;gt; &amp;#039;27-OCT-2009 11:15:00&amp;#039;&lt;br /&gt;
                                 , options   =&amp;gt; dbms_logmnr.dict_from_online_catalog+dbms_logmnr.continuous_mine&lt;br /&gt;
                                 );&lt;br /&gt;
create table mycontents as select * from v$logmnr_contents;&lt;br /&gt;
execute dbms_logmnr.end_logmnr(); &lt;br /&gt;
&lt;br /&gt;
select * from mycontents;&lt;br /&gt;
&lt;br /&gt;
drop table mycontents;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Huge Pages===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
#&lt;br /&gt;
# hugepages_settings.sh&lt;br /&gt;
#&lt;br /&gt;
# Linux bash script to compute values for the&lt;br /&gt;
# recommended HugePages/HugeTLB configuration&lt;br /&gt;
#&lt;br /&gt;
# Note: This script does calculation for all shared memory&lt;br /&gt;
# segments available when the script is run, no matter it&lt;br /&gt;
# is an Oracle RDBMS shared memory segment or not.&lt;br /&gt;
# Check for the kernel version&lt;br /&gt;
KERN=`uname -r | awk -F. &amp;#039;{ printf(&amp;quot;%d.%d\n&amp;quot;,$1,$2); }&amp;#039;`&lt;br /&gt;
# Find out the HugePage size&lt;br /&gt;
HPG_SZ=`grep Hugepagesize /proc/meminfo | awk {&amp;#039;print $2&amp;#039;}`&lt;br /&gt;
# Start from 1 pages to be on the safe side and guarantee 1 free HugePage&lt;br /&gt;
NUM_PG=1&lt;br /&gt;
# Cumulative number of pages required to handle the running shared memory segments&lt;br /&gt;
for SEG_BYTES in `ipcs -m | awk {&amp;#039;print $5&amp;#039;} | grep &amp;quot;[0-9][0-9]*&amp;quot;`&lt;br /&gt;
do&lt;br /&gt;
   MIN_PG=`echo &amp;quot;$SEG_BYTES/($HPG_SZ*1024)&amp;quot; | bc -q`&lt;br /&gt;
   if [ $MIN_PG -gt 0 ]; then&lt;br /&gt;
      NUM_PG=`echo &amp;quot;$NUM_PG+$MIN_PG+1&amp;quot; | bc -q`&lt;br /&gt;
   fi&lt;br /&gt;
done&lt;br /&gt;
# Finish with results&lt;br /&gt;
case $KERN in&lt;br /&gt;
   &amp;#039;2.4&amp;#039;) HUGETLB_POOL=`echo &amp;quot;$NUM_PG*$HPG_SZ/1024&amp;quot; | bc -q`;&lt;br /&gt;
          echo &amp;quot;Recommended setting: vm.hugetlb_pool = $HUGETLB_POOL&amp;quot; ;;&lt;br /&gt;
   &amp;#039;2.6&amp;#039; | &amp;#039;3.8&amp;#039;) echo &amp;quot;Recommended setting: vm.nr_hugepages = $NUM_PG&amp;quot; ;;&lt;br /&gt;
    *) echo &amp;quot;Unrecognized kernel version $KERN. Exiting.&amp;quot; ;;&lt;br /&gt;
esac&lt;br /&gt;
# End&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Pretty longops listing===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 2000 pages 1000&lt;br /&gt;
col opname for a34 head &amp;quot;Job&amp;quot;&lt;br /&gt;
col message for a60&lt;br /&gt;
col perc_done for a10 head &amp;quot;Done&amp;quot;&lt;br /&gt;
col started for a18&lt;br /&gt;
col killer for a15&lt;br /&gt;
col mins_busy head &amp;quot;Mins busy&amp;quot;&lt;br /&gt;
col mins_left head &amp;quot;Mins left&amp;quot;&lt;br /&gt;
select sid||&amp;#039;,&amp;#039;||serial#                       killer&lt;br /&gt;
,      opname&lt;br /&gt;
,      message&lt;br /&gt;
,      round ((sofar/totalwork),4)*100||&amp;#039;%&amp;#039;    perc_done&lt;br /&gt;
,      to_char(start_time,&amp;#039;DD-MON-YY HH24:MI&amp;#039;) started&lt;br /&gt;
,      floor(elapsed_seconds/60)               mins_busy&lt;br /&gt;
,      ceil(time_remaining/60)                 mins_left&lt;br /&gt;
from   v$session_longops&lt;br /&gt;
where  1=1&lt;br /&gt;
and    sofar     != totalwork&lt;br /&gt;
and    totalwork != 0&lt;br /&gt;
and    opname    like &amp;#039;RMAN%&amp;#039;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select * from v$session where module=&amp;#039;Data Pump Worker&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or attach to the impdp job and it shows percentage done.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Get the SID from v$session_longops and plug it into v$session to check the SQL command details.&lt;br /&gt;
&lt;br /&gt;
Current Running SQLs&lt;br /&gt;
--------------------&lt;br /&gt;
set pages 1000 lines 2000&lt;br /&gt;
col program  format a40&lt;br /&gt;
col sql_text format a130&lt;br /&gt;
&lt;br /&gt;
select s.sid&lt;br /&gt;
,      s.status&lt;br /&gt;
,      s.last_call_et&lt;br /&gt;
,      s.program&lt;br /&gt;
,      sa.sql_id&lt;br /&gt;
,      sa.sql_text&lt;br /&gt;
from   v$session s&lt;br /&gt;
,      v$sqlarea sa&lt;br /&gt;
where  s.sql_id = sa.sql_id&lt;br /&gt;
and    s.sid = &amp;#039;&amp;amp;sid&amp;#039;&lt;br /&gt;
/ &lt;br /&gt;
&lt;br /&gt;
set pages 1000 lines 2000&lt;br /&gt;
col USERNAME for a10&lt;br /&gt;
col OSUSER   for a10&lt;br /&gt;
col MACHINE  for a10&lt;br /&gt;
&lt;br /&gt;
select s.sid&lt;br /&gt;
,      s.serial#&lt;br /&gt;
,      p.spid&lt;br /&gt;
,      s.username&lt;br /&gt;
,      s.osuser&lt;br /&gt;
,      s.status&lt;br /&gt;
,      s.process fg_pid&lt;br /&gt;
,      s.longon_time&lt;br /&gt;
,      s.machine&lt;br /&gt;
,      p.spid bg_pid&lt;br /&gt;
from   gv$session s&lt;br /&gt;
,      gv$process p&lt;br /&gt;
where  s.addr = p.addr&lt;br /&gt;
and    s.sid  = &amp;#039;&amp;amp;sid&amp;#039;&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
$ps -ef | grep &amp;lt;spid&amp;gt;&lt;br /&gt;
&lt;br /&gt;
set pages 1000 lines 2000&lt;br /&gt;
SELECT INST_ID&lt;br /&gt;
,      SID&lt;br /&gt;
,      SERIAL#&lt;br /&gt;
,      SQL_ID&lt;br /&gt;
,      USERNAME&lt;br /&gt;
,      PROGRAM&lt;br /&gt;
,      MACHINE&lt;br /&gt;
,      SERVICE_NAME&lt;br /&gt;
FROM   GV$SESSION&lt;br /&gt;
WHERE  SID IN (&amp;#039;&amp;lt;SID_NO.1&amp;gt;&amp;#039;,&amp;#039;&amp;lt;SID_NO.2&amp;gt;&amp;#039;)&lt;br /&gt;
/&lt;br /&gt;
Active Running SQLs&lt;br /&gt;
--------------------&lt;br /&gt;
set pages 1000 lines 2000&lt;br /&gt;
col SPID     for a10&lt;br /&gt;
col PROGRAM  for a15&lt;br /&gt;
col OSUSER   for a10&lt;br /&gt;
col ACTION   for a10&lt;br /&gt;
col EVENT    for a25&lt;br /&gt;
col SQL_TEXT for a25&lt;br /&gt;
col MACHINE  for a10&lt;br /&gt;
col P1TEXT   for a10 &lt;br /&gt;
col P2TEXT   for a10&lt;br /&gt;
col P3TEXT   for a10  &lt;br /&gt;
SELECT b.sid&lt;br /&gt;
,      b.serial#&lt;br /&gt;
,      a.spid&lt;br /&gt;
,      b.sql_id&lt;br /&gt;
,      b.program&lt;br /&gt;
,      b.osuser&lt;br /&gt;
,      b.machine&lt;br /&gt;
,      b.type&lt;br /&gt;
,      b.event&lt;br /&gt;
,      b.action&lt;br /&gt;
,      b.p1text&lt;br /&gt;
,      b.p2text&lt;br /&gt;
,      b.p3text&lt;br /&gt;
,      b.state&lt;br /&gt;
,      c.sql_text&lt;br /&gt;
,      b.logon_time&lt;br /&gt;
FROM   v$process a&lt;br /&gt;
,      v$session b&lt;br /&gt;
,      v$sqltext c&lt;br /&gt;
WHERE  a.addr           = b.paddr&lt;br /&gt;
AND    b.sql_hash_value = c.hash_value&lt;br /&gt;
AND    b.STATUS         = &amp;#039;ACTIVE&amp;#039;&lt;br /&gt;
AND    b.sid            = &amp;#039;&amp;amp;sid&amp;#039;&lt;br /&gt;
ORDER  BY a.spid&lt;br /&gt;
,      c.piece&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
OR - Use the below Query &lt;br /&gt;
&lt;br /&gt;
Longops.sql&lt;br /&gt;
----------- &lt;br /&gt;
set pages 50000 lines 32767&lt;br /&gt;
col OPNAME for a10&lt;br /&gt;
col SID form 9999&lt;br /&gt;
col SERIAL form 9999999&lt;br /&gt;
col PROGRAM for a10&lt;br /&gt;
col USERNAME for a10&lt;br /&gt;
col SQL_TEXT for a40&lt;br /&gt;
col START_TIME for a10&lt;br /&gt;
col LAST_UPDATE_TIME for a10&lt;br /&gt;
col TARGET for a25&lt;br /&gt;
col MESSAGE for a25&lt;br /&gt;
&lt;br /&gt;
alter session set nls_date_format = &amp;#039;DD-MM-YYYY HH24:MI:SS&amp;#039;;&lt;br /&gt;
&lt;br /&gt;
SELECT l.inst_id,l.sid, l.serial#, l.sql_id, l.opname, l.username, l.target, l.sofar, l.totalwork, l.start_time,l.last_update_time,round(l.time_remaining/60,2) &amp;quot;REMAIN MINS&amp;quot;, round(l.elapsed_seconds/60,2) &amp;quot;ELAPSED MINS&amp;quot;, round((l.time_remaining+l.elapsed_seconds)/60,2) &amp;quot;TOTAL MINS&amp;quot;, ROUND(l.SOFAR/l.TOTALWORK*100,2) &amp;quot;%_COMPLETE&amp;quot;, l.message,s.sql_text &lt;br /&gt;
FROM gv$session_longops l &lt;br /&gt;
LEFT OUTER JOIN v$sql s on s.hash_value=l.sql_hash_value and s.address=l.sql_address and s.child_number=0&lt;br /&gt;
WHERE l.OPNAME NOT LIKE &amp;#039;RMAN%&amp;#039; AND l.OPNAME NOT LIKE &amp;#039;%aggregate%&amp;#039; AND l.TOTALWORK != 0 AND l.sofar&amp;lt;&amp;gt;l.totalwork AND l.time_remaining &amp;gt; 0&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Apply the database patch after the ORACLE_HOME has been patched===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ORAENV_ASK=NO&lt;br /&gt;
export ORACLE_SID=$1&lt;br /&gt;
. oraenv&lt;br /&gt;
&lt;br /&gt;
sqlplus /nolog &amp;lt;&amp;lt;EOSQL&lt;br /&gt;
connect / as sysdba&lt;br /&gt;
startup&lt;br /&gt;
@?/rdbms/admin/catbundle.sql psu apply&lt;br /&gt;
@?/rdbms/admin/utlrp.sql&lt;br /&gt;
purge dba_recyclebin;&lt;br /&gt;
&lt;br /&gt;
prompt check patch apply...&lt;br /&gt;
set lines 150&lt;br /&gt;
col action_time for a50&lt;br /&gt;
col comp_name for a50&lt;br /&gt;
col comments for a50&lt;br /&gt;
&lt;br /&gt;
select action_time,action,comments from sys.registry\$history where trunc(action_time) = trunc(sysdate);&lt;br /&gt;
select comp_name,version,status,modified from dba_registry;&lt;br /&gt;
exit&lt;br /&gt;
EOSQL&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Show how much archivelog data is generated per day===&lt;br /&gt;
A companion script for &amp;#039;how many log switches in a day&amp;#039;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
col orderby noprint&lt;br /&gt;
select trunc(first_time) orderby&lt;br /&gt;
,      to_char(first_time,&amp;#039;DD-MON-YYYY&amp;#039;) &amp;quot;Date&amp;quot;&lt;br /&gt;
,      round(sum(bytes/1024/1024/1024),2) arch_logs_gigs&lt;br /&gt;
from (&lt;br /&gt;
    select unique (blocks * block_size) bytes,&lt;br /&gt;
    thread#,&lt;br /&gt;
    sequence#,&lt;br /&gt;
    resetlogs_change#,&lt;br /&gt;
    first_time&lt;br /&gt;
    from v$archived_log&lt;br /&gt;
)&lt;br /&gt;
group by trunc(first_time)&lt;br /&gt;
,      to_char(first_time, &amp;#039;DD-MON-YYYY&amp;#039;)&lt;br /&gt;
order by trunc(first_time) desc&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Abort a hanging database even when sysdba cannot connect===&lt;br /&gt;
Unable to connect to database with sqlplus / as sysdba because audit file cannot be created?&lt;br /&gt;
* [http://tech.e2sn.com/oracle/troubleshooting/hang/how-to-log-on-even-when-sysdba-can-t-do-so tech.e2sn.com]&lt;br /&gt;
* [http://blog.dbi-services.com/oracle-is-hanging-dont-forget-hanganalyze-and-systemstate/ blog.dbi-services.com]&lt;br /&gt;
Instead of just killing the pmon process, there is a kinder (and more useful) way to kill the database.&amp;lt;br /&amp;gt;&lt;br /&gt;
Use the hidden, undocumented &amp;#039;prelim&amp;#039; switch parameter to sqlplus to make a connection to the database without creating SGA session data structures.&amp;lt;br /&amp;gt;&lt;br /&gt;
It can be very useful for hang analysis so the possible cause can be found after the database has been restarted.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sqlplus -prelim / as sysdba&lt;br /&gt;
oradebug unlimit&lt;br /&gt;
oradebug hanganalyze 3&lt;br /&gt;
oradebug setmypid              -- or oradebug setorapname diag&lt;br /&gt;
oradebug dump ashdumpseconds 30&lt;br /&gt;
oradebug dump systemstate 10   -- or oradebug dump systemstate 266&lt;br /&gt;
oradebug tracefile_name&lt;br /&gt;
shutdown abort&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Lists Oracle session with kill session statement all ready to go===&lt;br /&gt;
disconnect attempts to kill the o/s processes too. kill doesn&amp;#039;t.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
col killer for a60&lt;br /&gt;
col osuser for a12&lt;br /&gt;
col logon  for a23&lt;br /&gt;
col spid   for a8&lt;br /&gt;
col username for a15&lt;br /&gt;
col program for a50&lt;br /&gt;
set lines 2000&lt;br /&gt;
select &amp;#039;alter system disconnect session &amp;#039;&amp;#039;&amp;#039;||s.sid||&amp;#039;,&amp;#039;||s.serial#||&amp;#039;&amp;#039;&amp;#039; immediate;&amp;#039; killer&lt;br /&gt;
,      s.inst_id&lt;br /&gt;
,      to_char(s.logon_time,&amp;#039;DD-MON-YY HH24:MI:SS&amp;#039;) logon&lt;br /&gt;
,      sci.osuser&lt;br /&gt;
,      p.spid&lt;br /&gt;
,      s.username&lt;br /&gt;
,      s.program&lt;br /&gt;
from   gv$session s&lt;br /&gt;
,      gv$session_connect_info sci&lt;br /&gt;
,      gv$process p&lt;br /&gt;
where  1=1&lt;br /&gt;
and    p.addr     = s.paddr&lt;br /&gt;
and    p.inst_id  = s.inst_id&lt;br /&gt;
and    s.sid      = sci.sid&lt;br /&gt;
and    s.serial#  = sci.serial#&lt;br /&gt;
and    s.type    != &amp;#039;BACKGROUND&amp;#039;&lt;br /&gt;
and    sci.osuser = &amp;#039;oraibm&amp;#039;&lt;br /&gt;
order  by s.logon_time desc&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
KILLER                                                          INST_ID LOGON                   OSUSER       SPID     USERNAME        PROGRAM&lt;br /&gt;
------------------------------------------------------------ ---------- ----------------------- ------------ -------- --------------- --------------------------------------------------&lt;br /&gt;
alter system disconnect session &amp;#039;490,33947&amp;#039; immediate;                1 23-JUN-16 13:30:53      oraibm       23205    SYS             sqlplus@benouerp07 (TNS V1-V3)&lt;br /&gt;
alter system disconnect session &amp;#039;490,33947&amp;#039; immediate;                1 23-JUN-16 13:30:53      oraibm       23205    SYS             sqlplus@benouerp07 (TNS V1-V3)&lt;br /&gt;
alter system disconnect session &amp;#039;490,33947&amp;#039; immediate;                1 23-JUN-16 13:30:53      oraibm       23205    SYS             sqlplus@benouerp07 (TNS V1-V3)&lt;br /&gt;
alter system disconnect session &amp;#039;490,33947&amp;#039; immediate;                1 23-JUN-16 13:30:53      oraibm       23205    SYS             sqlplus@benouerp07 (TNS V1-V3)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===How much space is being used by a guaranteed restore point?===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
show parameter recovery&lt;br /&gt;
set numwi 15&lt;br /&gt;
set lines 200&lt;br /&gt;
col name for a40&lt;br /&gt;
col time for a23&lt;br /&gt;
col gigs_limit head &amp;quot;Max (but check df -g also!)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
select name&lt;br /&gt;
,      time&lt;br /&gt;
,      round(storage_size/1024/1024/1024,2) gigs_used&lt;br /&gt;
from   v$restore_point&lt;br /&gt;
where  1=1&lt;br /&gt;
and    guarantee_flashback_database = &amp;#039;YES&amp;#039;&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
select * from v$flash_recovery_area_usage&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
select name&lt;br /&gt;
,      round(space_used/1024/1024/1024,2) gigs_used&lt;br /&gt;
,      round(space_limit/1024/1024/1024,2) gigs_limit&lt;br /&gt;
,      space_reclaimable&lt;br /&gt;
,      number_of_files&lt;br /&gt;
from v$recovery_file_dest&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Get statistics for LOB columns in a table===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select &lt;br /&gt;
  max(dbms_lob.getlength(lob_content)) max_len&lt;br /&gt;
, avg(dbms_lob.getlength(lob_content)) avg_len&lt;br /&gt;
, min(dbms_lob.getlength(lob_content)) min_len&lt;br /&gt;
, sum(case when dbms_lob.getlength(lob_content) &amp;lt;= 4000 then 1&lt;br /&gt;
else 0 end) &amp;quot;&amp;lt;4k&amp;quot;&lt;br /&gt;
, sum(case when dbms_lob.getlength(lob_content) &amp;gt; 4000 then 1&lt;br /&gt;
else 0 end) &amp;quot;&amp;gt;4k&amp;quot;&lt;br /&gt;
, sum(case when dbms_lob.getlength(lob_content) is null then 1 else&lt;br /&gt;
0 end) &amp;quot;is null&amp;quot;&lt;br /&gt;
from &amp;amp;tablename&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===badprivs.sql===&lt;br /&gt;
Check to see if any ordinary users have privileges / access / grants / rights they should not have&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select grantee, privilege, admin_option&lt;br /&gt;
from   sys.dba_sys_privs&lt;br /&gt;
where  (       privilege like &amp;#039;% ANY %&amp;#039;&lt;br /&gt;
        or     privilege in (&amp;#039;BECOME USER&amp;#039;, &amp;#039;UNLIMITED TABLESPACE&amp;#039;)&lt;br /&gt;
        or     admin_option = &amp;#039;YES&amp;#039;&lt;br /&gt;
       )&lt;br /&gt;
and    grantee not in (&amp;#039;SYS&amp;#039;, &amp;#039;SYSTEM&amp;#039;, &amp;#039;OUTLN&amp;#039;, &amp;#039;AQ_ADMINISTRATOR_ROLE&amp;#039;,&lt;br /&gt;
                      &amp;#039;DBA&amp;#039;, &amp;#039;EXP_FULL_DATABASE&amp;#039;, &amp;#039;IMP_FULL_DATABASE&amp;#039;,&lt;br /&gt;
                      &amp;#039;OEM_MONITOR&amp;#039;, &amp;#039;CTXSYS&amp;#039;, &amp;#039;DBSNMP&amp;#039;, &amp;#039;IFSSYS&amp;#039;,&lt;br /&gt;
                      &amp;#039;IFSSYS$CM&amp;#039;, &amp;#039;MDSYS&amp;#039;, &amp;#039;ORDPLUGINS&amp;#039;, &amp;#039;ORDSYS&amp;#039;,&lt;br /&gt;
                      &amp;#039;TIMESERIES_DBA&amp;#039;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Generate a list of tablespaces ready for a migration===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set echo off&lt;br /&gt;
set lines 300&lt;br /&gt;
set pages 0&lt;br /&gt;
Set headi off&lt;br /&gt;
set feedb off&lt;br /&gt;
set long 32000&lt;br /&gt;
&lt;br /&gt;
spool migration_create_target_tablespaces.sql&lt;br /&gt;
&lt;br /&gt;
exec dbms_metadata.set_transform_param(dbms_metadata.session_transform,&amp;#039;SQLTERMINATOR&amp;#039;,TRUE);&lt;br /&gt;
select DBMS_METADATA.GET_DDL(&amp;#039;TABLESPACE&amp;#039;,tablespace_name) from dba_tablespaces&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
spool off&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===List the privileges assigned to users on directories===&lt;br /&gt;
table_name is the name of the directory...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select grantor&lt;br /&gt;
,      grantee&lt;br /&gt;
,      table_schema&lt;br /&gt;
,      table_name&lt;br /&gt;
,      privilege&lt;br /&gt;
from   all_tab_privs&lt;br /&gt;
where  table_name = &amp;#039;DATA_PUMP_DIR&amp;#039;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===List the privileges assigned to users on packages/procedures===&lt;br /&gt;
table_name is the name of the package...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select grantor&lt;br /&gt;
,      grantee&lt;br /&gt;
,      table_schema&lt;br /&gt;
,      table_name&lt;br /&gt;
,      privilege&lt;br /&gt;
from   all_tab_privs&lt;br /&gt;
where  upper(table_name) like upper(&amp;#039;%UTL_FILE%&amp;#039;)&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===List the system privileges assigned to a user (used to copy user as or clone user as)===&lt;br /&gt;
Maybe this one is better [[Extract ddl with &amp;quot;dbms metadata.get ddl&amp;quot;]]&lt;br /&gt;
&lt;br /&gt;
 SELECT LPAD(&amp;#039; &amp;#039;, 2*level) || granted_role &amp;quot;USER PRIVS&amp;quot;&lt;br /&gt;
 FROM (&lt;br /&gt;
   SELECT NULL grantee,  username granted_role&lt;br /&gt;
   FROM dba_users&lt;br /&gt;
   WHERE username LIKE UPPER(&amp;#039;%&amp;amp;uname%&amp;#039;)&lt;br /&gt;
   UNION&lt;br /&gt;
   SELECT grantee, granted_role&lt;br /&gt;
   FROM dba_role_privs&lt;br /&gt;
   UNION&lt;br /&gt;
   SELECT grantee, privilege&lt;br /&gt;
   FROM dba_sys_privs)&lt;br /&gt;
 START WITH grantee IS NULL&lt;br /&gt;
 CONNECT BY grantee = prior granted_role;&lt;br /&gt;
&lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
 SELECT path&lt;br /&gt;
 FROM (&lt;br /&gt;
   SELECT grantee,&lt;br /&gt;
          sys_connect_by_path(privilege, &amp;#039;:&amp;#039;)||&amp;#039;:&amp;#039;||grantee path&lt;br /&gt;
   FROM (&lt;br /&gt;
     SELECT grantee, privilege, 0 role&lt;br /&gt;
     FROM dba_sys_privs&lt;br /&gt;
     UNION ALL&lt;br /&gt;
     SELECT grantee, granted_role, 1 role&lt;br /&gt;
     FROM dba_role_privs)&lt;br /&gt;
   CONNECT BY privilege=prior grantee&lt;br /&gt;
   START WITH role = 0)&lt;br /&gt;
 WHERE grantee IN (&lt;br /&gt;
    SELECT username&lt;br /&gt;
    FROM dba_users&lt;br /&gt;
    WHERE lock_date IS NULL&lt;br /&gt;
    AND password != &amp;#039;EXTERNAL&amp;#039;&lt;br /&gt;
    AND username != &amp;#039;SYS&amp;#039;)&lt;br /&gt;
 OR grantee=&amp;#039;PUBLIC&amp;#039;&lt;br /&gt;
&lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
for a migration from 10g...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set headi off&lt;br /&gt;
set feedb off&lt;br /&gt;
set long  9999999&lt;br /&gt;
set pages 0&lt;br /&gt;
set lines 300&lt;br /&gt;
&lt;br /&gt;
spool migration_create_target_users_grants.sql&lt;br /&gt;
&lt;br /&gt;
select dbms_metadata.get_ddl(&amp;#039;USER&amp;#039;, username) || &amp;#039;;&amp;#039; ddl&lt;br /&gt;
from dba_users&lt;br /&gt;
where  1=1&lt;br /&gt;
and    username like upper(&amp;#039;%&amp;amp;&amp;amp;USER_NAME%&amp;#039;)&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
select &amp;#039;grant &amp;#039;||privilege|| &amp;#039; to &amp;#039; || grantee || &amp;#039;;&amp;#039;&lt;br /&gt;
from   dba_sys_privs&lt;br /&gt;
where  1=1&lt;br /&gt;
and    grantee like upper(&amp;#039;%&amp;amp;&amp;amp;USER_NAME%&amp;#039;)&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
select &amp;#039;grant &amp;#039;||granted_role|| &amp;#039; to &amp;#039; || grantee || &amp;#039;;&amp;#039;&lt;br /&gt;
from   dba_role_privs&lt;br /&gt;
where  1=1&lt;br /&gt;
and    grantee like upper(&amp;#039;%&amp;amp;&amp;amp;USER_NAME%&amp;#039;)&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
spool off&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or for a migration on 11g...!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set head off&lt;br /&gt;
set pages 0&lt;br /&gt;
set long 9999999&lt;br /&gt;
col ddl for a1000&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
SELECT DBMS_METADATA.GET_DDL(&amp;#039;USER&amp;#039;, USERNAME) || &amp;#039;;&amp;#039; DDL&lt;br /&gt;
FROM DBA_USERS&lt;br /&gt;
where  1=1&lt;br /&gt;
and    default_tablespace not in (&amp;#039;SYSTEM&amp;#039;,&amp;#039;SYSAUX&amp;#039;)&lt;br /&gt;
and    upper(username) like &amp;#039;%&amp;#039;||upper(&amp;#039;&amp;amp;&amp;amp;username&amp;#039;)||&amp;#039;%&amp;#039;&lt;br /&gt;
UNION ALL&lt;br /&gt;
SELECT DBMS_METADATA.GET_GRANTED_DDL(&amp;#039;ROLE_GRANT&amp;#039;, USERNAME) || &amp;#039;;&amp;#039; DDL&lt;br /&gt;
FROM DBA_USERS&lt;br /&gt;
where  1=1&lt;br /&gt;
and    default_tablespace not in (&amp;#039;SYSTEM&amp;#039;,&amp;#039;SYSAUX&amp;#039;)&lt;br /&gt;
and    upper(username) like &amp;#039;%&amp;#039;||upper(&amp;#039;&amp;amp;&amp;amp;username&amp;#039;)||&amp;#039;%&amp;#039;&lt;br /&gt;
UNION ALL&lt;br /&gt;
SELECT DBMS_METADATA.GET_GRANTED_DDL(&amp;#039;SYSTEM_GRANT&amp;#039;, USERNAME) || &amp;#039;;&amp;#039; DDL&lt;br /&gt;
FROM DBA_USERS&lt;br /&gt;
where  1=1&lt;br /&gt;
and    default_tablespace not in (&amp;#039;SYSTEM&amp;#039;,&amp;#039;SYSAUX&amp;#039;)&lt;br /&gt;
and    upper(username) like &amp;#039;%&amp;#039;||upper(&amp;#039;&amp;amp;&amp;amp;username&amp;#039;)||&amp;#039;%&amp;#039;&lt;br /&gt;
UNION ALL&lt;br /&gt;
SELECT DBMS_METADATA.GET_GRANTED_DDL(&amp;#039;OBJECT_GRANT&amp;#039;, USERNAME) || &amp;#039;;&amp;#039; DDL&lt;br /&gt;
FROM DBA_USERS&lt;br /&gt;
where  1=1&lt;br /&gt;
and    default_tablespace not in (&amp;#039;SYSTEM&amp;#039;,&amp;#039;SYSAUX&amp;#039;)&lt;br /&gt;
and    upper(username) like &amp;#039;%&amp;#039;||upper(&amp;#039;&amp;amp;&amp;amp;username&amp;#039;)||&amp;#039;%&amp;#039;&lt;br /&gt;
&lt;br /&gt;
spool migration_create_users_grants.sql&lt;br /&gt;
/&lt;br /&gt;
spool off&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Move datafiles between filesystems===&lt;br /&gt;
* [https://blogs.oracle.com/alejandrovargas/moving-a-datafile-from-file-system-to-asm Moving a datafile from File System to ASM (does not have to be ASM!) - oracle.com]&lt;br /&gt;
* [https://docs.oracle.com/database/121/OSTMG/GUID-3B8D0956-0888-452D-A9E4-9FB8D98577E0.htm#OSTMG89997 Moving Data Files Between Oracle ASM (does not have to be ASM!) Using RMAN - oracle.com]&lt;br /&gt;
* [https://oracle-base.com/articles/misc/renaming-or-moving-oracle-files Moving a data file online between filesystems - oracle-base.com]&lt;br /&gt;
====Set the relevant datafile offline====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter database datafile 125 offline;&lt;br /&gt;
alter database datafile 126 offline;&lt;br /&gt;
alter database datafile 127 offline;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Rename the files on the filesystem using o/s commands====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter tablespace ts_thaler_data_offline;&lt;br /&gt;
&lt;br /&gt;
host mv &amp;#039;/cln/tst/ora_data1/clnt/data4/ts_thaler_data_113.dbf&amp;#039; &amp;#039;/cln/tst/ora_data1/clnt/data1/ts_thaler_data_113.dbf&amp;#039;&lt;br /&gt;
host mv &amp;#039;/cln/tst/ora_data1/clnt/data4/ts_thaler_data_114.dbf&amp;#039; &amp;#039;/cln/tst/ora_data1/clnt/data1/ts_thaler_data_114.dbf&amp;#039;&lt;br /&gt;
host mv &amp;#039;/cln/tst/ora_data1/clnt/data4/ts_thaler_data_115.dbf&amp;#039; &amp;#039;/cln/tst/ora_data1/clnt/data1/ts_thaler_data_115.dbf&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Run the relevant alter commands to inform the control files of the new locations====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter database move datafile &amp;#039;/cln/tst/ora_data1/clnt/data4/ts_thaler_data_113.dbf&amp;#039; to &amp;#039;/cln/tst/ora_data1/clnt/data1/ts_thaler_data_113.dbf&amp;#039;&lt;br /&gt;
alter database move datafile &amp;#039;/cln/tst/ora_data1/clnt/data4/ts_thaler_data_114.dbf&amp;#039; to &amp;#039;/cln/tst/ora_data1/clnt/data1/ts_thaler_data_114.dbf&amp;#039;&lt;br /&gt;
alter database move datafile &amp;#039;/cln/tst/ora_data1/clnt/data4/ts_thaler_data_115.dbf&amp;#039; to &amp;#039;/cln/tst/ora_data1/clnt/data1/ts_thaler_data_115.dbf&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Recover the datafiles====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
recover datafile 125;&lt;br /&gt;
recover datafile 126;&lt;br /&gt;
recover datafile 127;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Set the relevant datafile online====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter database datafile 125 online;&lt;br /&gt;
alter database datafile 126 online;&lt;br /&gt;
alter database datafile 127 online;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Check all is well with the datafiles by using an appropriate statement====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 2000 pages 100&lt;br /&gt;
select file_id, file_name, status, online_status from dba_data_files where tablespace_name = &amp;#039;TS_THALER_DATA&amp;#039; order by 2;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Rename a datafile on 12c====&lt;br /&gt;
If you&amp;#039;re lucky enough to be on 12c, it&amp;#039;s one command - no need to offline the datafile!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SQL&amp;gt; alter database move datafile &amp;#039;/oracle/ora_data2/prod/data4/ts_thaler_data_113.dbf&amp;#039; to &amp;#039;/oracle/ora_data2/prod/data3/ts_thaler_data_113.dbf&amp;#039;;&lt;br /&gt;
&lt;br /&gt;
Database altered.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Pass parameter/argument into perl one-liner script from shell===&lt;br /&gt;
Trick? Just use ARGV to pass them in...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
FREQ=$(perl -e &amp;#039;my @CAL=split(&amp;quot;;&amp;quot;,$ARGV[0]);shift @CAL;print $CAL[$ARGV[1]];&amp;#039; -- &amp;quot;$LINE&amp;quot; $offset)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
DUMP_DATE=`perl -MTime::Local -e &amp;#039;print(timelocal(0,$ARGV[0],$ARGV[1],$ARGV[2],$ARGV[3],$ARGV[4]))&amp;#039; -- $MI $HH $DD $MM $YYYY`&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or export the variable from shell and access it via the ENV hash&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
export db=ENDP1&lt;br /&gt;
perl -p -i -e &amp;#039;s!DSMI_LOG.+$!DSMI_LOG           /oracle/$ENV{db}/admin/tdpoerror_$ENV{db}!&amp;#039; ${db}/admin/tdpo.opt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Return epoch seconds in Perl===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
perl -e &amp;#039;print time();&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or to convert a specific day of the year to epoch seconds&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
use POSIX;&lt;br /&gt;
my $epochsecs = mktime(0,0,0, $jday, 0, $year-1900);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or for a specific date (careful though - month is 0-11 not 1-12!...&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
use Time::Local;&lt;br /&gt;
#                          SS MM HH DD MM YYYY&lt;br /&gt;
my $epochsecs = timelocal (30,10,19,03,04,2014);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or more long-winded but delimited by anything...&amp;lt;br /&amp;gt;&lt;br /&gt;
Supply the date/time in any delimited format. Eg. YYYY-MM-DD:HH:MI&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/usr/bin/perl -w&lt;br /&gt;
use Time::Local;&lt;br /&gt;
&lt;br /&gt;
sub date2epoch { &lt;br /&gt;
  my($s) = @_;&lt;br /&gt;
  my($year, $month, $day, $hour, $minute, $second);&lt;br /&gt;
&lt;br /&gt;
  if($s =~ m{^\s*(\d{1,4})\W*0*(\d{1,2})\W*0*(\d{1,2})\W*0*&lt;br /&gt;
                 (\d{0,2})\W*0*(\d{0,2})\W*0*(\d{0,2})}x) {&lt;br /&gt;
    $year = $1;  $month = $2;   $day = $3;&lt;br /&gt;
    $hour = $4;  $minute = $5;  $second = $6;&lt;br /&gt;
    $hour |= 0;  $minute |= 0;  $second |= 0;  # defaults.&lt;br /&gt;
    $year = ($year&amp;lt;100 ? ($year&amp;lt;70 ? 2000+$year : 1900+$year) : $year);&lt;br /&gt;
    return timelocal($second,$minute,$hour,$day,$month-1,$year);  &lt;br /&gt;
  }&lt;br /&gt;
  return -1;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Return epoch seconds in DOS/VBS/Windows===&lt;br /&gt;
Paste this code into epoch.vbs&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
function date2epoch(p_date)&lt;br /&gt;
    date2epoch = DateDiff(&amp;quot;s&amp;quot;, &amp;quot;01/01/1970 00:00:00&amp;quot;, p_date)&lt;br /&gt;
end function&lt;br /&gt;
&lt;br /&gt;
Wscript.Echo date2epoch(Now())&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
and call from a DOS box like this&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cscript //nologo epoch.vbs&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Return date from epoch seconds in Perl===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
perl -e &amp;#039;print scalar (localtime (1243269270))&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Return epoch seconds from julian day number in Perl===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
use POSIX;&lt;br /&gt;
my ($year, $jday) = (2012,60);&lt;br /&gt;
my $epochsecs = mktime(0,0,0, $jday, 0, $year-1900);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Extract specific pieces of a date from an epoch timestamp in Perl===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
use POSIX;&lt;br /&gt;
# return localtime into an array&lt;br /&gt;
my @tm = localtime $epochsecs;&lt;br /&gt;
&lt;br /&gt;
my $yyyymmdd = strftime &amp;quot;%Y%m%d&amp;quot;, @tm;&lt;br /&gt;
print $yyyymmdd.&amp;quot;\n&amp;quot;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Return epoch seconds in Shell (linux)===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
date -d &amp;quot;2014/04/03 18:34:30&amp;quot; &amp;quot;+%s&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Return date from epoch seconds in Shell (linux)===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
date -d @1396542870&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Return epoch seconds in PL/SQL===&lt;br /&gt;
You cannot just use sysdate as that is timezone sensitive... (epoch seconds are in UTC/GMT)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select round((cast(sys_extract_utc(systimestamp) as date) - to_date(&amp;#039;01-JAN-1970 00:00:00&amp;#039;,&amp;#039;DD-MON-YYYY HH24:MI:SS&amp;#039;))*24*60*60) from dual;&lt;br /&gt;
or&lt;br /&gt;
select round((vd.created - to_date(&amp;#039;01-JAN-1970 00:00:00&amp;#039;,&amp;#039;DD-MON-YYYY HH24:MI:SS&amp;#039;))*24*60*60)  created from v$database vd;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
How long has this instance been up (in minutes)?&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select round((cast(sys_extract_utc(systimestamp) as date) - startup_time)*24*60) up_mins from v$instance;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Return date from epoch seconds in SQL===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select to_char(to_date(&amp;#039;19700101&amp;#039;,&amp;#039;YYYYMMDD&amp;#039;) + ((&amp;amp;epoch)/24/60/60),&amp;#039;DD-MON-YYYY HH24:MI:SS&amp;#039;) utc_date from dual;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===A database overview using the sys.plato package===&lt;br /&gt;
 exec plato.help;&lt;br /&gt;
or&lt;br /&gt;
 exec plato.complete(&amp;#039;HTM&amp;#039;);&lt;br /&gt;
&lt;br /&gt;
===List datafiles for a tablespace===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select *&lt;br /&gt;
from   dba_data_files&lt;br /&gt;
where  1=1&lt;br /&gt;
and    tablespace_name =&amp;#039;&amp;amp;ts_name&amp;#039;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Show graph of available and free space in tablespaces===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
-- =============================================================================&lt;br /&gt;
-- File Name    : http://www.oracle-base.com/dba/monitoring/ts_free_space.sql&lt;br /&gt;
-- Author       : Tim Hall&lt;br /&gt;
-- Description  : Displays a list of tablespaces and their used/full status.&lt;br /&gt;
-- Requirements : Access to the DBA views.&lt;br /&gt;
-- Call Syntax  : @ts_free_space.sql&lt;br /&gt;
-- Last Modified: 13-OCT-2012 - Created. Based on ts_full.sql&lt;br /&gt;
--&lt;br /&gt;
-- Modification History&lt;br /&gt;
-- ====================&lt;br /&gt;
-- When      Who               What&lt;br /&gt;
-- ========= ================= =================================================&lt;br /&gt;
-- 13-NOV-13 Stuart Barkley    Added cols free_pct and used_pct&lt;br /&gt;
-- =============================================================================&lt;br /&gt;
SET PAGESIZE 140 lines 180&lt;br /&gt;
COLUMN used_pct FORMAT A11&lt;br /&gt;
COLUMN max_used_pct FORMAT A11&lt;br /&gt;
&lt;br /&gt;
    SELECT tablespace_name                                                                      tablespace_name&lt;br /&gt;
    ,      size_mb                                                                              size_mb&lt;br /&gt;
    ,      free_mb                                                                              free_mb&lt;br /&gt;
    ,      TRUNC((free_mb/size_mb) * 100)                                                       free_pct&lt;br /&gt;
    ,      RPAD(&amp;#039; &amp;#039;|| RPAD(&amp;#039;X&amp;#039;,ROUND((size_mb-free_mb)/size_mb*10,0), &amp;#039;X&amp;#039;),11,&amp;#039;-&amp;#039;)              used_pct&lt;br /&gt;
    ,      max_size_mb                                                                          max_size_mb&lt;br /&gt;
    ,      max_free_mb                                                                          max_free_mb&lt;br /&gt;
    ,      TRUNC((max_free_mb/max_size_mb) * 100)                                               max_free_pct&lt;br /&gt;
    ,      RPAD(&amp;#039; &amp;#039;|| RPAD(&amp;#039;X&amp;#039;,ROUND((max_size_mb-max_free_mb)/max_size_mb*10,0), &amp;#039;X&amp;#039;),11,&amp;#039;-&amp;#039;)  max_used_pct&lt;br /&gt;
    from   (&lt;br /&gt;
           select a.tablespace_name                                         tablespace_name&lt;br /&gt;
           ,      b.size_mb                                                 size_mb&lt;br /&gt;
           ,      a.free_mb                                                 free_mb&lt;br /&gt;
           ,      b.max_size_mb                                             max_size_mb&lt;br /&gt;
           ,      a.free_mb + (b.max_size_mb - b.size_mb)                   max_free_mb&lt;br /&gt;
           from   (&lt;br /&gt;
                  select tablespace_name                                    tablespace_name&lt;br /&gt;
                  ,      trunc(sum(bytes)/1024/1024)                        free_mb&lt;br /&gt;
                  from   dba_free_space&lt;br /&gt;
                  group  by tablespace_name&lt;br /&gt;
                  ) a&lt;br /&gt;
           ,      (&lt;br /&gt;
                  select tablespace_name                                    tablespace_name&lt;br /&gt;
                  ,        trunc(sum(bytes)/1024/1024)                      size_mb&lt;br /&gt;
                  ,        trunc(sum(greatest(bytes,maxbytes))/1024/1024)   max_size_mb&lt;br /&gt;
                  from   dba_data_files&lt;br /&gt;
                  group by tablespace_name&lt;br /&gt;
                  ) b&lt;br /&gt;
           ,      v$instance vi&lt;br /&gt;
           where  a.tablespace_name = b.tablespace_name&lt;br /&gt;
           )&lt;br /&gt;
    order  by tablespace_name;&lt;br /&gt;
&lt;br /&gt;
set lines 80&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Another method for calculating free space in tablespace  using segments===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select df.tablespace_name &amp;quot;Tablespace&amp;quot;&lt;br /&gt;
,      totalusedspace &amp;quot;Used MB&amp;quot;&lt;br /&gt;
,      (df.totalspace - tu.totalusedspace) &amp;quot;Free MB&amp;quot;&lt;br /&gt;
,      df.totalspace &amp;quot;Total MB&amp;quot;&lt;br /&gt;
,      round(100 * ( (df.totalspace - tu.totalusedspace)/ df.totalspace)) &amp;quot;Pct. Free&amp;quot;&lt;br /&gt;
from   (&lt;br /&gt;
       select tablespace_name&lt;br /&gt;
,      round(sum(bytes) / 1048576) totalspace&lt;br /&gt;
       from   dba_data_files&lt;br /&gt;
       group  by tablespace_name&lt;br /&gt;
       ) df&lt;br /&gt;
,      (&lt;br /&gt;
       select round(sum(bytes)/(1024*1024)) totalusedspace&lt;br /&gt;
       ,      tablespace_name&lt;br /&gt;
       from   dba_segments&lt;br /&gt;
       group  by tablespace_name&lt;br /&gt;
       ) tu&lt;br /&gt;
where  df.tablespace_name = tu.tablespace_name;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Work out maximum possible size of a datafile===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select round( (4*1024*1024*value) / (1024*1024*1024) ,2) maxfilesizeingigabytes from v$parameter where name=&amp;#039;db_block_size&amp;#039;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or, as tablespaces can have block sizes differing from that of the init.ora parameter...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select round( (4*1024*1024*block_size) / (1024*1024*1024) ,2) maxfilesizeingigabytes from dba_tablespaces where tablespace_name=&amp;#039;&amp;amp;tablespace_name&amp;#039;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Show size and maxsize at datafile level===&lt;br /&gt;
datafiles&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set pages 100 lines 200&lt;br /&gt;
col file_name for a60&lt;br /&gt;
select sum(bytes)/1024/1024      mbytes_alloc&lt;br /&gt;
,      sum(maxbytes)/1024/1024   mbytes_max&lt;br /&gt;
,      file_name&lt;br /&gt;
from   sys.dba_data_files&lt;br /&gt;
group  by file_name&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
tempfiles&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set pages 100 lines 200&lt;br /&gt;
col file_name for a60&lt;br /&gt;
select sum(bytes)/1024/1024      mbytes_alloc&lt;br /&gt;
,      sum(maxbytes)/1024/1024   mbytes_max&lt;br /&gt;
,      file_name&lt;br /&gt;
from   sys.dba_temp_files&lt;br /&gt;
group  by file_name&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Resize the online redo logfiles===&lt;br /&gt;
Found a more concise, smarter way of doing it [http://www.oracle-wiki.net/startdocshowtorecreateredogrps here] - oracle-wiki.net&amp;lt;br /&amp;gt;&lt;br /&gt;
Switching logs too often? Redolog files too small?&amp;lt;br /&amp;gt;&lt;br /&gt;
* Show current log groups&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 1000&lt;br /&gt;
col group_member for a60&lt;br /&gt;
select l.group#          group_number&lt;br /&gt;
,      (bytes/1024/1024) megs&lt;br /&gt;
,      l.status          group_status&lt;br /&gt;
,      f.member          group_member&lt;br /&gt;
,      l.archived        archived&lt;br /&gt;
,      f.type            file_type&lt;br /&gt;
from   v$log     l&lt;br /&gt;
,      v$logfile f&lt;br /&gt;
where  l.group# = f.group#&lt;br /&gt;
order  by l.group#&lt;br /&gt;
,      f.member&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Create additional (bigger) groups&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
define SID=TIBQFW&lt;br /&gt;
alter database add logfile group 6  &amp;#039;/oracle/&amp;amp;SID/oradata1/redo1.log&amp;#039; size 1G;&lt;br /&gt;
alter database add logfile group 7  &amp;#039;/oracle/&amp;amp;SID/oradata2/redo2.log&amp;#039; size 1G;&lt;br /&gt;
alter database add logfile group 8  &amp;#039;/oracle/&amp;amp;SID/oradata3/redo3.log&amp;#039; size 1G;&lt;br /&gt;
alter database add logfile group 9  &amp;#039;/oracle/&amp;amp;SID/oradata1/redo4.log&amp;#039; size 1G;&lt;br /&gt;
alter database add logfile group 10 &amp;#039;/oracle/&amp;amp;SID/oradata2/redo5.log&amp;#039; size 1G;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or if you use multiple members...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter database add logfile group 6 (&amp;#039;/oracle/&amp;amp;SID/oradata1/redo/redo01a.log&amp;#039;, &amp;#039;/oracle/&amp;amp;SID/oradata1/redo01b&amp;#039;) size 50M;&lt;br /&gt;
alter database add logfile group 7 (&amp;#039;/oracle/&amp;amp;SID/oradata1/redo/redo02a.log&amp;#039;, &amp;#039;/oracle/&amp;amp;SID/oradata1/redo02b&amp;#039;) size 50M;&lt;br /&gt;
alter database add logfile group 8 (&amp;#039;/oracle/&amp;amp;SID/oradata1/redo/redo03a.log&amp;#039;, &amp;#039;/oracle/&amp;amp;SID/oradata1/redo03b&amp;#039;) size 50M;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Switch archivelogs until the new ones are current and the old ones are inactive&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter system switch logfile;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
If the old logs are not yet inactive, checkpoint the database&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter system checkpoint;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Drop the old groups&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter database drop logfile group 1;&lt;br /&gt;
alter database drop logfile group 2;&lt;br /&gt;
alter database drop logfile group 3;&lt;br /&gt;
alter database drop logfile group 4;&lt;br /&gt;
alter database drop logfile group 5;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Increase the existing size of a datafile===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter database datafile &amp;#039;&amp;amp;full_path_of_datafile&amp;#039; resize &amp;amp;new_meg_size.M;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Increase the max size of a tempfile===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter database tempfile &amp;#039;/oracle/ENDP1/oradata90/temp01.dbf&amp;#039; autoextend on maxsize unlimited;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Find out what processes are using the temp tablespace===&lt;br /&gt;
Temporary tablespace is used for sorting query results. Find them with this.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SELECT b.tablespace,b.segfile#,b.segblk#,b.blocks,a.sid,a.serial#,&lt;br /&gt;
a.username,a.osuser, a.status&lt;br /&gt;
FROM v$session a,v$sort_usage b&lt;br /&gt;
WHERE a.saddr = b.session_addr;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Increase the maximum size of a datafile===&lt;br /&gt;
Although this can be set lower than existing size, try not to. It makes the reports look weird!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter database&lt;br /&gt;
      datafile &amp;#039;&amp;amp;full_path_of_datafile&amp;#039;&lt;br /&gt;
      autoextend on&lt;br /&gt;
      maxsize &amp;amp;new_meg_size.m;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Find schemas (users) with objects created outside their default tablespace===&lt;br /&gt;
Indexes could be a notable exception if they are created in an index tablespace&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 200&lt;br /&gt;
col owner           for a20&lt;br /&gt;
col segment_name    for a45&lt;br /&gt;
col tablespace_name for a32&lt;br /&gt;
select owner&lt;br /&gt;
,      segment_name&lt;br /&gt;
,      tablespace_name&lt;br /&gt;
from   dba_segments&lt;br /&gt;
where  exists (select username from dba_users where username = owner)&lt;br /&gt;
and    tablespace_name != (select default_tablespace from dba_users where username = owner)&lt;br /&gt;
and    owner = &amp;#039;&amp;amp;owner&amp;#039;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Add a datafile to a tablespace===&lt;br /&gt;
&amp;#039;unlimited&amp;#039; will default to the maximum datafile size for the current db_block_size&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter tablepace &amp;amp;tablespace_name&lt;br /&gt;
      add datafile &amp;#039;&amp;amp;full_path_of_datafile&amp;#039;&lt;br /&gt;
      size 100M&lt;br /&gt;
      autoextend on&lt;br /&gt;
      next 100M&lt;br /&gt;
      maxsize unlimited&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===List all datafiles with their size===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set pages 1000 lines 2000&lt;br /&gt;
col filetype for a15&lt;br /&gt;
col name for a60&lt;br /&gt;
break on report&lt;br /&gt;
compute sum of gig on report&lt;br /&gt;
&lt;br /&gt;
select filetype&lt;br /&gt;
,      name&lt;br /&gt;
,      gig&lt;br /&gt;
from   (&lt;br /&gt;
       select &amp;#039;datafile&amp;#039; filetype&lt;br /&gt;
       ,      name&lt;br /&gt;
       ,      bytes/1024/1024 gig&lt;br /&gt;
       from   v$datafile&lt;br /&gt;
       union all&lt;br /&gt;
       select &amp;#039;tempfile&amp;#039; filetype&lt;br /&gt;
       ,      name&lt;br /&gt;
       ,      bytes/1024/1024&lt;br /&gt;
       from   v$tempfile&lt;br /&gt;
       union all&lt;br /&gt;
       select &amp;#039;logfile&amp;#039; filetype&lt;br /&gt;
       ,      lf.member &amp;quot;name&amp;quot;&lt;br /&gt;
       ,      l.bytes/1024/1024&lt;br /&gt;
       from   v$logfile lf&lt;br /&gt;
       ,      v$log     l&lt;br /&gt;
       where  1=1&lt;br /&gt;
       and    lf.group# = l.group#&lt;br /&gt;
       ) used&lt;br /&gt;
,      (&lt;br /&gt;
       select sum(bytes)/1024/1024&lt;br /&gt;
       from   dba_free_space&lt;br /&gt;
       ) free&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Database size (How big is my database?)===&lt;br /&gt;
There are different interpretations of what constitutes the size of a database...&amp;lt;br /&amp;gt;&lt;br /&gt;
Is it the space allocated to the datafiles or only the space taken up by the data? Are tempfiles included? Are redo logs included? etc...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 132&lt;br /&gt;
col dbname for a9  heading &amp;quot;Database&amp;quot;&lt;br /&gt;
col dbsize for a15 heading &amp;quot;Size&amp;quot;&lt;br /&gt;
col dbused for a15 heading &amp;quot;Used space&amp;quot;&lt;br /&gt;
col dbfree for a15 heading &amp;quot;Free space&amp;quot;&lt;br /&gt;
with used_space as&lt;br /&gt;
(&lt;br /&gt;
select  bytes&lt;br /&gt;
from    v$datafile&lt;br /&gt;
union   all&lt;br /&gt;
select  bytes&lt;br /&gt;
from    v$tempfile&lt;br /&gt;
union   all&lt;br /&gt;
select  bytes&lt;br /&gt;
from    v$log&lt;br /&gt;
)&lt;br /&gt;
, free_space as&lt;br /&gt;
(&lt;br /&gt;
select sum(bytes) sum_bytes&lt;br /&gt;
from dba_free_space&lt;br /&gt;
)&lt;br /&gt;
select vd.name                                                                                            dbname&lt;br /&gt;
,      round(sum(used_space.bytes)/1024/1024/1024 ) || &amp;#039; GB&amp;#039;                                              dbsize&lt;br /&gt;
,      round(sum(used_space.bytes)/1024/1024/1024 ) - round(free_space.sum_bytes/1024/1024/1024) || &amp;#039; GB&amp;#039; dbused&lt;br /&gt;
,      round(free_space.sum_bytes/1024/1024/1024) || &amp;#039; GB&amp;#039;                                                dbfree&lt;br /&gt;
from   free_space&lt;br /&gt;
,      used_space&lt;br /&gt;
,      v$database vd&lt;br /&gt;
group  by vd.name&lt;br /&gt;
,      free_space.sum_bytes&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Drop datafile from temp tablespace===&lt;br /&gt;
Database is completely stuck because the temporary tablespace has grown to fill all available room.&amp;lt;br /&amp;gt;&lt;br /&gt;
Look around for at least some log files to delete in order to get connected (audit files, sqlnet logs, listener logs)&amp;lt;br /&amp;gt;&lt;br /&gt;
Once connected, change the default temporary tablespace to a small one so we can remove the original.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
create temporary tablespace temp2 tempfile &amp;#039;/oracle/RMANV12/oradata2/temp2.dbf&amp;#039; size 5M;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter database default temporary tablespace temp2;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
I found trying to drop the datafile like this didn&amp;#039;t work, just hung there (probably active tranactions)...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
drop tablespace temp including contents and datafiles;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
So did it like this...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter database tempfile &amp;#039;/oracle/RMANV12/oradata2/temp.dbf&amp;#039; drop including datafiles;&lt;br /&gt;
&lt;br /&gt;
Database altered.&lt;br /&gt;
&lt;br /&gt;
drop tablespace temp including contents and datafiles;&lt;br /&gt;
&lt;br /&gt;
Tablespace dropped.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
... an alternative would be to find the sessions using the temp space and kill them...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select sid, serial#, status from v$session where serial# in (select session_num from v$sort_usage);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Then to be neat and tidy, rename the temp2 tablespace back to temp.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
create temporary tablespace temp tempfile &amp;#039;/oracle/RMANV12/oradata2/temp.dbf&amp;#039; size 256M reuse autoextend on next 128M maxsize 1G;&lt;br /&gt;
alter database default temporary tablespace temp;&lt;br /&gt;
drop tablespace temp2 including contents and datafiles;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Although the last statement will not work until any transactions using it have been rolled back or committed.&lt;br /&gt;
&lt;br /&gt;
===List files that are in hot-backup mode===&lt;br /&gt;
 set lines 100&lt;br /&gt;
 set pages 100&lt;br /&gt;
 col name format a60&lt;br /&gt;
 &lt;br /&gt;
 select df.name&lt;br /&gt;
 ,      b.status&lt;br /&gt;
 ,      to_char(time, &amp;#039;hh24:mi:ss dd/mm/yyyy&amp;#039;) time&lt;br /&gt;
 from   v$datafile   df&lt;br /&gt;
 ,      v$backup     b&lt;br /&gt;
 where  1=1&lt;br /&gt;
 and    df.file# = b.file#&lt;br /&gt;
 and    b.status = &amp;#039;ACTIVE&amp;#039;&lt;br /&gt;
 order  by b.file#;&lt;br /&gt;
&lt;br /&gt;
===Waiting for snapshot control file enqueue===&lt;br /&gt;
Script to identify sessions causing RMAN to hang because of &amp;#039;waiting for snapshot control file enqueue&amp;#039; message&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 2000&lt;br /&gt;
col killer     for a70&lt;br /&gt;
col program    for a20&lt;br /&gt;
col module     for a20&lt;br /&gt;
col action     for a20&lt;br /&gt;
col logon_time for a20&lt;br /&gt;
&lt;br /&gt;
select &amp;#039;alter system disconnect session &amp;#039;&amp;#039;&amp;#039;||s.sid||&amp;#039;,&amp;#039;||s.serial#||&amp;#039;&amp;#039;&amp;#039; immediate;&amp;#039; killer&lt;br /&gt;
,      username&lt;br /&gt;
,      program&lt;br /&gt;
,      module&lt;br /&gt;
,      action&lt;br /&gt;
,      logon_time&lt;br /&gt;
from   v$session s&lt;br /&gt;
,      v$enqueue_lock l&lt;br /&gt;
where  l.sid  = s.sid&lt;br /&gt;
and    l.type = &amp;#039;CF&amp;#039;&lt;br /&gt;
and    l.id1  = 0&lt;br /&gt;
and    l.id2  = 2&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Info on blocking processes===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select s1.username || &amp;#039;@&amp;#039; || s1.machine&lt;br /&gt;
       || &amp;#039; ( SID=&amp;#039; || s1.sid || &amp;#039; )  is blocking &amp;#039;&lt;br /&gt;
       || s2.username || &amp;#039;@&amp;#039; || s2.machine || &amp;#039; ( SID=&amp;#039; || s2.sid || &amp;#039; ) &amp;#039;  blocking_status&lt;br /&gt;
from   v$lock l1&lt;br /&gt;
,      v$session s1&lt;br /&gt;
,      v$lock l2&lt;br /&gt;
,      v$session s2&lt;br /&gt;
where  s1.sid     = l1.sid&lt;br /&gt;
and    s2.sid     = l2.sid&lt;br /&gt;
and    l1.block   = 1&lt;br /&gt;
and    l2.request &amp;gt; 0&lt;br /&gt;
and    l1.id1     = l2.id1&lt;br /&gt;
and    l2.id2     = l2.id2&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
session doing the blocking&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select *&lt;br /&gt;
from  v$lock l1&lt;br /&gt;
where 1=1&lt;br /&gt;
and   block = 1 ;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
sessions being blocked&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select *&lt;br /&gt;
from   v$lock l1&lt;br /&gt;
where  1=1&lt;br /&gt;
and    id2 = 85203&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
info on session doing the blocking&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select row_wait_obj#, row_wait_file#, row_wait_block#, row_wait_row#&lt;br /&gt;
from   v$session&lt;br /&gt;
where  sid = 234&lt;br /&gt;
&lt;br /&gt;
select do.object_name&lt;br /&gt;
,      row_wait_obj#&lt;br /&gt;
,      row_wait_file#&lt;br /&gt;
,      row_wait_block#&lt;br /&gt;
,      row_wait_row#&lt;br /&gt;
,      dbms_rowid.rowid_create ( 1, ROW_WAIT_OBJ#, ROW_WAIT_FILE#, ROW_WAIT_BLOCK#, ROW_WAIT_ROW# ) row_id&lt;br /&gt;
from   v$session   s&lt;br /&gt;
,      dba_objects do&lt;br /&gt;
where  sid=234&lt;br /&gt;
and    s.ROW_WAIT_OBJ# = do.OBJECT_ID;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Show locked objects===&lt;br /&gt;
 set lines 100&lt;br /&gt;
 set pages 999&lt;br /&gt;
 col username   format a20&lt;br /&gt;
 col sess_id    format a10&lt;br /&gt;
 col object     format a25&lt;br /&gt;
 col mode_held  format a10&lt;br /&gt;
 select oracle_username||&amp;#039; (&amp;#039;||s.osuser||&amp;#039;)&amp;#039; username&lt;br /&gt;
 ,      s.sid||&amp;#039;,&amp;#039;||s.serial# sess_id&lt;br /&gt;
 ,      owner||&amp;#039;.&amp;#039;||object_name object&lt;br /&gt;
 ,      object_type&lt;br /&gt;
 ,      decode ( l.block&lt;br /&gt;
               , 0, &amp;#039;Not Blocking&amp;#039;&lt;br /&gt;
               , 1, &amp;#039;Blocking&amp;#039;&lt;br /&gt;
               , 2, &amp;#039;Global&amp;#039;&lt;br /&gt;
               ) status&lt;br /&gt;
 ,      decode ( v.locked_mode&lt;br /&gt;
               , 0, &amp;#039;None&amp;#039;&lt;br /&gt;
               , 1, &amp;#039;Null&amp;#039;&lt;br /&gt;
               , 2, &amp;#039;Row-S (SS)&amp;#039;&lt;br /&gt;
               , 3, &amp;#039;Row-X (SX)&amp;#039;&lt;br /&gt;
               , 4, &amp;#039;Share&amp;#039;&lt;br /&gt;
               , 5, &amp;#039;S/Row-X (SSX)&amp;#039;&lt;br /&gt;
               , 6, &amp;#039;Exclusive&amp;#039;, TO_CHAR(lmode)&lt;br /&gt;
               ) mode_held&lt;br /&gt;
 from   v$locked_object v&lt;br /&gt;
 ,      dba_objects d&lt;br /&gt;
 ,      v$lock l&lt;br /&gt;
 ,      v$session s&lt;br /&gt;
 where  1=1&lt;br /&gt;
 and    v.object_id = d.object_id&lt;br /&gt;
 and    v.object_id = l.id1&lt;br /&gt;
 and    v.session_id = s.sid&lt;br /&gt;
 order  by oracle_username&lt;br /&gt;
 ,	session_id;&lt;br /&gt;
&lt;br /&gt;
===Show which row is locked===&lt;br /&gt;
 select do.object_name&lt;br /&gt;
 ,      row_wait_obj#&lt;br /&gt;
 ,      row_wait_file#&lt;br /&gt;
 ,      row_wait_block#&lt;br /&gt;
 ,      row_wait_row#&lt;br /&gt;
 ,      dbms_rowid.rowid_create (1, ROW_WAIT_OBJ#, ROW_WAIT_FILE#, ROW_WAIT_BLOCK#, ROW_WAIT_ROW#)&lt;br /&gt;
 from   v$session   s&lt;br /&gt;
 ,      dba_objects do&lt;br /&gt;
 where  1=1&lt;br /&gt;
 and    s.ROW_WAIT_OBJ# = do.OBJECT_ID&lt;br /&gt;
 and    sid             = &amp;amp;sid;&lt;br /&gt;
&lt;br /&gt;
===Check what is audited on a database===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set pagesize 100&lt;br /&gt;
set linesize 256&lt;br /&gt;
select audit_option,success,failure from dba_stmt_audit_opts;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===How old is the oldest audit record?===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select extract (day from (systimestamp - min(ntimestamp#))) days_old from aud$;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Check what objects are being audited===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
tti col 60 &amp;#039;Object Audit Options (dba_obj_audit_opts)&amp;#039; skip col 50 &amp;#039;A=By Access, S=By Session. Left=on success, right=on failure&amp;#039; skip 2&lt;br /&gt;
set lines 1000 pages 100&lt;br /&gt;
col alt for a3 head &amp;quot;Alt|er&amp;quot;&lt;br /&gt;
col aud for a3 head &amp;quot;Aud|it&amp;quot;&lt;br /&gt;
col com for a3 head &amp;quot;Com|ent&amp;quot;&lt;br /&gt;
col del for a3 head &amp;quot;Del|ete&amp;quot;&lt;br /&gt;
col gra for a3 head &amp;quot;Gra|nt&amp;quot;&lt;br /&gt;
col ind for a3 head &amp;quot;Ind|ex&amp;quot;&lt;br /&gt;
col ins for a3 head &amp;quot;Ins|ert&amp;quot;&lt;br /&gt;
col loc for a3 head &amp;quot;Lo|ck&amp;quot;&lt;br /&gt;
col ren for a3 head &amp;quot;Ren|ame&amp;quot;&lt;br /&gt;
col sel for a3 head &amp;quot;Sel|ect&amp;quot;&lt;br /&gt;
col upd for a3 head &amp;quot;Upd|ate&amp;quot;&lt;br /&gt;
col ref for a3 head &amp;quot;Ref|rnc&amp;quot;&lt;br /&gt;
col exe for a3 head &amp;quot;Exe|cut&amp;quot;&lt;br /&gt;
col cre for a3 head &amp;quot;Cre|ate&amp;quot;&lt;br /&gt;
col rea for a3 head &amp;quot;Re|ad&amp;quot;&lt;br /&gt;
col wri for a3 head &amp;quot;Wri|te&amp;quot;&lt;br /&gt;
col fbk for a3 head &amp;quot;Fla|sh&amp;quot;&lt;br /&gt;
	&lt;br /&gt;
select *&lt;br /&gt;
from   dba_obj_audit_opts&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Procedure to delete old audit records===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select text from all_source where lower(name)=&amp;#039;purge_audit_trail&amp;#039;;&lt;br /&gt;
&lt;br /&gt;
TEXT&lt;br /&gt;
------------------------------------------------------------------------------------------------&lt;br /&gt;
PROCEDURE purge_audit_trail IS&lt;br /&gt;
BEGIN&lt;br /&gt;
-- set the last archive timestamp&lt;br /&gt;
DBMS_AUDIT_MGMT.SET_LAST_ARCHIVE_TIMESTAMP(&lt;br /&gt;
       audit_trail_type    =&amp;gt; DBMS_AUDIT_MGMT.AUDIT_TRAIL_AUD_STD,&lt;br /&gt;
       last_archive_time   =&amp;gt; systimestamp - interval &amp;#039;365&amp;#039; day,&lt;br /&gt;
       rac_instance_number =&amp;gt; null&lt;br /&gt;
                                          );&lt;br /&gt;
-- purge audit trail till last archive timestamp&lt;br /&gt;
DBMS_AUDIT_MGMT.CLEAN_AUDIT_TRAIL( audit_trail_type =&amp;gt; DBMS_AUDIT_MGMT.AUDIT_TRAIL_AUD_STD&lt;br /&gt;
, use_last_arch_timestamp =&amp;gt; TRUE);&lt;br /&gt;
&lt;br /&gt;
END purge_audit_trail;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Job setup to run the audit purge===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
BEGIN&lt;br /&gt;
sys.dbms_scheduler.create_job(&lt;br /&gt;
    job_name =&amp;gt; &amp;#039;&amp;quot;SYS&amp;quot;.&amp;quot;PURGE_AUDIT_TRAIL_JOB&amp;quot;&amp;#039;,&lt;br /&gt;
    job_type =&amp;gt; &amp;#039;STORED_PROCEDURE&amp;#039;,&lt;br /&gt;
    job_action =&amp;gt; &amp;#039;&amp;quot;SYS&amp;quot;.&amp;quot;PURGE_AUDIT_TRAIL&amp;quot;&amp;#039;,&lt;br /&gt;
    repeat_interval =&amp;gt; &amp;#039;FREQ=DAILY;BYHOUR=20;BYMINUTE=0;BYSECOND=0&amp;#039;,&lt;br /&gt;
    start_date =&amp;gt; to_timestamp_tz(&amp;#039;2012-02-22 Europe/Paris&amp;#039;, &amp;#039;YYYY-MM-DD TZR&amp;#039;),&lt;br /&gt;
    job_class =&amp;gt; &amp;#039;&amp;quot;DEFAULT_JOB_CLASS&amp;quot;&amp;#039;,&lt;br /&gt;
    comments =&amp;gt; &amp;#039;purge audit trails until last archive timestamp&amp;#039;,&lt;br /&gt;
    auto_drop =&amp;gt; FALSE,&lt;br /&gt;
    enabled =&amp;gt; FALSE&lt;br /&gt;
);&lt;br /&gt;
sys.dbms_scheduler.set_attribute( name =&amp;gt; &amp;#039;&amp;quot;SYS&amp;quot;.&amp;quot;PURGE_AUDIT_TRAIL_JOB&amp;quot;&amp;#039;, attribute =&amp;gt; &amp;#039;logging_level&amp;#039;, value =&amp;gt; DBMS_SCHEDULER.LOGGING_OFF);&lt;br /&gt;
sys.dbms_scheduler.set_attribute( name =&amp;gt; &amp;#039;&amp;quot;SYS&amp;quot;.&amp;quot;PURGE_AUDIT_TRAIL_JOB&amp;quot;&amp;#039;, attribute =&amp;gt; &amp;#039;job_weight&amp;#039;, value =&amp;gt; 1);&lt;br /&gt;
sys.dbms_scheduler.enable( &amp;#039;&amp;quot;SYS&amp;quot;.&amp;quot;PURGE_AUDIT_TRAIL_JOB&amp;quot;&amp;#039; );&lt;br /&gt;
END;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===A list of all SIDs in oratab that should restart after a server boot===&lt;br /&gt;
Using awk&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
awk -F: &amp;#039;$NF==&amp;quot;Y&amp;quot; &amp;amp;&amp;amp; $1 !~/[#]/ {print $1}&amp;#039;  /etc/oratab&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Using perl&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
perl -F: -ne &amp;#039;print &amp;quot;$1\n&amp;quot; if /(\w+):(.+):Y$/&amp;#039; /etc/oratab&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Move the admin directories to a new location===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
./all_db_do &amp;quot;alter system set audit_file_dest=&amp;#039;/oracle/&amp;amp;SID/admin/adump&amp;#039; scope=spfile;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
./all_db_do &amp;quot;shutdown immediate&amp;quot;&lt;br /&gt;
&lt;br /&gt;
for db in `awk -F: &amp;#039;NF &amp;amp;&amp;amp; $1 !~/[#*]/ {print $1}&amp;#039;  /etc/oratab`&lt;br /&gt;
do&lt;br /&gt;
    echo $db&lt;br /&gt;
    mkdir -p /oracle/${db}/admin&lt;br /&gt;
    echo &amp;quot;/oracle/${db}/admin created&amp;quot;&lt;br /&gt;
    mv /oracle/admin/${db}/adump /oracle/${db}/admin/&lt;br /&gt;
    mv /oracle/admin/${db}/dpdump /oracle/${db}/admin/&lt;br /&gt;
    echo &amp;quot;Moved /oracle/admin/${db}/adump to /oracle/${db}/admin/&amp;quot;&lt;br /&gt;
done&lt;br /&gt;
&lt;br /&gt;
./all_db_do startup&lt;br /&gt;
&lt;br /&gt;
./all_db_do &amp;quot;create pfile from spfile;&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Check if the Standby database is up-to-date with the primary database===&lt;br /&gt;
 select arch.thread# &amp;quot;Thread&amp;quot;&lt;br /&gt;
 ,      arch.sequence# &amp;quot;Last Sequence Received&amp;quot;&lt;br /&gt;
 ,      appl.sequence# &amp;quot;Last Sequence Applied&amp;quot;&lt;br /&gt;
 ,      (arch.sequence# - appl.sequence#) &amp;quot;Difference&amp;quot;&lt;br /&gt;
 from   (&lt;br /&gt;
        select thread#&lt;br /&gt;
        ,      sequence#&lt;br /&gt;
        from   v$archived_log&lt;br /&gt;
        where  1=1&lt;br /&gt;
        and    ( thread#,first_time ) in (&lt;br /&gt;
                                         select thread#, max(first_time)&lt;br /&gt;
                                         from   v$archived_log&lt;br /&gt;
                                         group  by thread#&lt;br /&gt;
                                         )&lt;br /&gt;
        ) arch&lt;br /&gt;
        ,&lt;br /&gt;
        (&lt;br /&gt;
        select thread#&lt;br /&gt;
        ,      sequence#&lt;br /&gt;
        from   v$log_history&lt;br /&gt;
        where  1=1&lt;br /&gt;
        and    ( thread#,first_time ) in ( select thread# ,max(first_time)&lt;br /&gt;
                                           from   v$log_history&lt;br /&gt;
                                           group  by thread#&lt;br /&gt;
                                          )&lt;br /&gt;
        ) appl&lt;br /&gt;
 where  1=1&lt;br /&gt;
 and    arch.thread# = appl.thread#&lt;br /&gt;
 order  by 1;&lt;br /&gt;
&lt;br /&gt;
===Check for gaps on the Standby database===&lt;br /&gt;
Run this on the standby&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select thread#, low_sequence#, high_sequence# from v$archive_gap;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or run this on the Primary to see the latest generated archive...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select thread#   &amp;quot;Thread&amp;quot;&lt;br /&gt;
,      sequence# &amp;quot;Last sequence generated&amp;quot;&lt;br /&gt;
from   v$archived_log&lt;br /&gt;
where  (thread#, first_time) in ( select thread#, max(first_time)&lt;br /&gt;
                                  from   v$archived_log&lt;br /&gt;
                                  group  by thread#&lt;br /&gt;
                                )&lt;br /&gt;
order  by 1&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
and run this on the standby to check for received but not yet applied logs (this could be normal if a lag has been set)...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select arch.thread# &amp;quot;Thread&amp;quot;&lt;br /&gt;
,      arch.sequence# &amp;quot;Last sequence received&amp;quot;&lt;br /&gt;
,      appl.sequence# &amp;quot;Last sequence applied&amp;quot;&lt;br /&gt;
,      (arch.sequence#-appl.sequence#) &amp;quot;Difference&amp;quot;&lt;br /&gt;
from   (&lt;br /&gt;
       select thread#&lt;br /&gt;
       ,      sequence#&lt;br /&gt;
       from   v$archived_log&lt;br /&gt;
       where  (thread#,first_time ) in (select thread#, max(first_time)&lt;br /&gt;
                                        from   v$archived_log&lt;br /&gt;
                                        group  by thread#&lt;br /&gt;
                                       )&lt;br /&gt;
       ) arch&lt;br /&gt;
,      (&lt;br /&gt;
       select thread#&lt;br /&gt;
       ,      sequence#&lt;br /&gt;
       from   v$log_history&lt;br /&gt;
       where  (thread#,first_time ) in (select thread#, max(first_time)&lt;br /&gt;
                                        from   v$log_history&lt;br /&gt;
                                        group  by thread#&lt;br /&gt;
                                       )&lt;br /&gt;
      ) appl&lt;br /&gt;
where arch.thread# = appl.thread#&lt;br /&gt;
order by 1&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Compare the results from Primary and Secondary to detect possible network problems or other errors in shipping.&lt;br /&gt;
&lt;br /&gt;
===Ignore case-sensitive passwords in 11g (deprecated in 12c)===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter system set SEC_CASE_SENSITIVE_LOGON = false scope=both&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===External table for the Alert log (pre 11g)===&lt;br /&gt;
&lt;br /&gt;
 CREATE OR REPLACE DIRECTORY bdump AS &amp;#039;c:\oracle\product\diag dbms\orabase\orabase race\&amp;#039;;&lt;br /&gt;
 &lt;br /&gt;
 CREATE TABLE system.log_table (TEXT VARCHAR2(400))&lt;br /&gt;
 ORGANIZATION EXTERNAL (&lt;br /&gt;
 TYPE oracle_loader&lt;br /&gt;
 DEFAULT DIRECTORY bdump&lt;br /&gt;
 ACCESS PARAMETERS (&lt;br /&gt;
  RECORDS DELIMITED BY NEWLINE&lt;br /&gt;
  NOBADFILE NODISCARDFILE NOLOGFILE&lt;br /&gt;
  FIELDS TERMINATED BY &amp;#039;0x0A&amp;#039;&lt;br /&gt;
  MISSING FIELD VALUES ARE NULL)&lt;br /&gt;
 LOCATION (&amp;#039;alert_orabase.log&amp;#039;))&lt;br /&gt;
 REJECT LIMIT unlimited;&lt;br /&gt;
 &lt;br /&gt;
 SELECT * FROM system.log_table;&lt;br /&gt;
 &lt;br /&gt;
 CREATE OR REPLACE VIEW last_200_alerts AS&lt;br /&gt;
 WITH alert_log AS (&lt;br /&gt;
  SELECT rownum as lineno, text FROM system.log_table)&lt;br /&gt;
 SELECT text&lt;br /&gt;
 FROM alert_log&lt;br /&gt;
 WHERE lineno &amp;gt; (SELECT count(*)-200 FROM alert_log)&lt;br /&gt;
 ORDER BY lineno;&lt;br /&gt;
 &lt;br /&gt;
 SELECT * FROM last_200_alerts;&lt;br /&gt;
&lt;br /&gt;
===Alert log (11g+)===&lt;br /&gt;
This reads the log.xml file (which contains the same information as alert.log)&amp;lt;br /&amp;gt;&lt;br /&gt;
Show the messages put in the alert log in the last 24 hours&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select substr(MESSAGE_TEXT, 1, 300) message_text&lt;br /&gt;
,      count(*) cnt&lt;br /&gt;
from   X$DBGALERTEXT&lt;br /&gt;
where  1=1&lt;br /&gt;
and    (MESSAGE_TEXT like &amp;#039;%ORA-%&amp;#039; or upper(MESSAGE_TEXT) like &amp;#039;%ERROR%&amp;#039;)&lt;br /&gt;
and    cast(ORIGINATING_TIMESTAMP as DATE) &amp;gt; sysdate - &amp;amp;days_ago/1440&lt;br /&gt;
group  by substr(MESSAGE_TEXT, 1, 300)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
There is also a fixed table X$DBGDIREXT which returns all file and directory names under [diagnostic_dest]/diag directory:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select lpad(&amp;#039; &amp;#039;,lvl,&amp;#039; &amp;#039;)||logical_file file_name&lt;br /&gt;
from   x$dbgdirext&lt;br /&gt;
where  rownum &amp;lt;=20;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Directory paths available in v$diag_info===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 2000&lt;br /&gt;
col name for a35&lt;br /&gt;
col value for a100 wrap&lt;br /&gt;
select * from v$diag_info;&lt;br /&gt;
&lt;br /&gt;
   INST_ID NAME                                VALUE                                                                                                    CON_ID&lt;br /&gt;
---------- ----------------------------------- ---------------------------------------------------------------------------------------------------- ----------&lt;br /&gt;
         1 Diag Enabled                        TRUE                                                                                                          0&lt;br /&gt;
         1 ADR Base                            /cln/prg/ora_bin2/app/oracle                                                                               0&lt;br /&gt;
         1 ADR Home                            /cln/prg/ora_bin2/app/oracle/diag/rdbms/bild/bild                                                          0&lt;br /&gt;
         1 Diag Trace                          /cln/prg/ora_bin2/app/oracle/diag/rdbms/bild/bild/trace                                                    0&lt;br /&gt;
         1 Diag Alert                          /cln/prg/ora_bin2/app/oracle/diag/rdbms/bild/bild/alert                                                    0&lt;br /&gt;
         1 Diag Incident                       /cln/prg/ora_bin2/app/oracle/diag/rdbms/bild/bild/incident                                                 0&lt;br /&gt;
         1 Diag Cdump                          /cln/prg/ora_bin2/app/oracle/diag/rdbms/bild/bild/cdump                                                    0&lt;br /&gt;
         1 Health Monitor                      /cln/prg/ora_bin2/app/oracle/diag/rdbms/bild/bild/hm                                                       0&lt;br /&gt;
         1 Default Trace File                  /cln/prg/ora_bin2/app/oracle/diag/rdbms/bild/bild/trace/bild_ora_44696768.trc                              0&lt;br /&gt;
         1 Active Problem Count                0                                                                                                             0&lt;br /&gt;
         1 Active Incident Count               0                                                                                                             0&lt;br /&gt;
&lt;br /&gt;
11 rows selected.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Find out the names of the active trace files for the running processes===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select pid, program, tracefile from v$process;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Request was to duplicate a large tablespace from production to test environment===&lt;br /&gt;
...but rather than copy the terabytes of data, create the destination tablespace with just the most recent months data&amp;lt;br /&amp;gt;&lt;br /&gt;
====See what the source data looks like====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
col table_owner    for a20&lt;br /&gt;
col table_name     for a30&lt;br /&gt;
col partition_name for a20&lt;br /&gt;
set pages 100 lines 1000&lt;br /&gt;
&lt;br /&gt;
select table_owner&lt;br /&gt;
,      table_name&lt;br /&gt;
,      partition_name&lt;br /&gt;
,      partition_position&lt;br /&gt;
,      tablespace_name&lt;br /&gt;
from   dba_tab_partitions&lt;br /&gt;
where  tablespace_name = &amp;#039;ADS_ARCHIVE&amp;#039;&lt;br /&gt;
order  by 1,2,3,4&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This query produces something like this...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
TABLE_OWNER          TABLE_NAME                     PARTITION_NAME       PARTITION_POSITION TABLESPACE_NAME                &lt;br /&gt;
-------------------- ------------------------------ -------------------- ------------------ ------------------------------ &lt;br /&gt;
ADS_ARCHIVE          BIL_DAY_INV_CTR_ARC            Y2017_Q1_M01_D01                      1 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          BIL_HIS_DETAIL_FAC_ARC         Y2016_Q2_M05_D04                      1 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          BIL_HIS_DETAIL_FAC_ARC         Y2016_Q2_M05_D09                      2 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          BIL_MTH_INV_CTR_ARC            Y2017_Q1_M01_D01                      1 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          FAH_DAY_CBA_BGAAP_ARC          Y2011_Q4_M12_D30                      1 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          FAH_DAY_CBA_BGAAP_ARC          Y2011_Q4_M12_D31                      2 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          FAH_DAY_CBA_IFRS_ARC           Y2011_Q4_M12_D30                      1 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          FAH_DAY_CBA_IFRS_ARC           Y2011_Q4_M12_D31                      2 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          FAH_DAY_MVT_BGAAP_ARC          Y2011_Q4_M12_D30                      1 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          FAH_DAY_MVT_BGAAP_ARC          Y2011_Q4_M12_D31                      2 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          FAH_DAY_MVT_BGAAP_ARC          Y2012_Q1_M03_D31                      3 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          FAH_DAY_MVT_BGAAP_ARC          Y2012_Q2_M04_D01                      4 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          FAH_DAY_MVT_BGAAP_ARC          Y2012_Q4_M10_D12                      5 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          FAH_DAY_MVT_BGAAP_ARC          Y2012_Q4_M10_D13                      6 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          FAH_DAY_MVT_BGAAP_ARC          Y2012_Q4_M10_D14                      7 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          FAH_DAY_MVT_BGAAP_ARC_TST      Y2011_Q4_M12_D30                      1 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          FAH_DAY_MVT_BGAAP_ARC_TST      Y2011_Q4_M12_D31                      2 ADS_ARCHIVE&lt;br /&gt;
...&lt;br /&gt;
ADS_ARCHIVE          SBP_HIS_LINES_ARC              P_LS                                  3 ADS_ARCHIVE                  &lt;br /&gt;
ADS_ARCHIVE          THA_DAY_INV_CTR_ARC            Y2011_Q4_M12_D30                      1 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          THA_DAY_INV_CTR_ARC            Y2011_Q4_M12_D31                      2 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          THA_INV_HEAVY_ARC              Y2011_Q4_M12_D30                      1 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          THA_INV_HEAVY_ARC              Y2011_Q4_M12_D31                      2 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          THA_INV_LIGHT_ARC              Y2011_Q4_M12_D30                      1 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          THA_INV_LIGHT_ARC              Y2012_Q4_M10_D12                      2 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          THA_INV_LIGHT_ARC              Y2012_Q4_M10_D13                      3 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          THA_INV_LIGHT_ARC              Y2012_Q4_M10_D15                      4 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          THA_INV_LIGHT_ARC              Y2012_Q4_M10_D16                      5 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          THA_INV_LIGHT_ARC              Y2012_Q4_M10_D17                      6 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          THA_INV_LIGHT_ARC              Y2012_Q4_M10_D18                      7 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          THA_INV_LIGHT_ARC              Y2012_Q4_M10_D19                      8 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          THA_INV_LIGHT_ARC              Y2012_Q4_M10_D20                      9 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          THA_INV_LIGHT_ARC              Y2012_Q4_M10_D21                     10 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          THA_INV_LIGHT_ARC              Y2012_Q4_M10_D22                     11 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          THA_INV_LIGHT_ARC              Y2012_Q4_M10_D23                     12 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          THA_INV_LIGHT_ARC              Y2012_Q4_M10_D24                     13 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          THA_MTH_INV_CTR_ARC            Y2011_Q4_M12_D30                      1 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          THA_MTH_INV_CTR_ARC            Y2011_Q4_M12_D31                      2 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          THA_MTH_INV_CTR_ARC            Y2013_Q2_M04_D30                      3 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          XBD01_TEMP_HIS_ARC             Y2012_Q4_M12_D31                      1 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          T_RPT_RECO_THA_INV_ACC_ARC     Y2011_Q4_M12_D30                      1 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          T_RPT_RECO_THA_INV_ACC_ARC     Y2011_Q4_M12_D31                      2 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          T_RPT_RECO_THA_INV_MTH_ARC     Y2011_Q4_M12_D30                      1 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          T_RPT_RECO_THA_INV_MTH_ARC     Y2011_Q4_M12_D31                      2 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          XBD01_TEMP_HIS_ARC             Y2012_Q4_M12_D31                      1 ADS_ARCHIVE&lt;br /&gt;
ADS_DBA              FAH_DAY_CBA_BGAAP              Y2016_Q3_M07_D12                   1657 ADS_ARCHIVE&lt;br /&gt;
ADS_DBA              FAH_DAY_CBA_BGAAP              Y2016_Q4_M12_D13                   1811 ADS_ARCHIVE&lt;br /&gt;
ADS_DBA              FAH_DAY_MVT_IFRS               Y2016_Q4_M10_D10                   1654 ADS_ARCHIVE&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Capture the tablespace metadata====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set long 1000000&lt;br /&gt;
select dbms_metadata.get_ddl ( &amp;#039;TABLESPACE&amp;#039;, &amp;#039;ADS_ARCHIVE&amp;#039;) from dual&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
produces...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
CREATE TABLESPACE &amp;quot;ADS_ARCHIVE&amp;quot; DATAFILE&lt;br /&gt;
  &amp;#039;/oracle/tst/ora_data3/adst/ads_archive01.dbf&amp;#039; SIZE 104857600&lt;br /&gt;
  AUTOEXTEND ON NEXT 104857600 MAXSIZE 32000M,&lt;br /&gt;
...&lt;br /&gt;
  &amp;#039;/oracle/tst/ora_data3/adst/ads_archive66.dbf&amp;#039; SIZE 104857600&lt;br /&gt;
  AUTOEXTEND ON NEXT 104857600 MAXSIZE 3200M,&lt;br /&gt;
  LOGGING ONLINE PERMANENT BLOCKSIZE 8192&lt;br /&gt;
  EXTENT MANAGEMENT LOCAL AUTOALLOCATE DEFAULT&lt;br /&gt;
 NOCOMPRESS  SEGMENT SPACE MANAGEMENT AUTO&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Capture the tablespace objects&amp;#039; metadata====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cat&amp;lt;&amp;lt;EOCAT &amp;gt;expdp_adst_ads_archive_metadata.par&lt;br /&gt;
userid=&amp;#039;/ as sysdba&amp;#039;&lt;br /&gt;
dumpfile=adst_ads_archive_metadata.dmp&lt;br /&gt;
logfile=expdp_adst_ads_archive_metadata.log&lt;br /&gt;
tablespaces=ADS_ARCHIVE&lt;br /&gt;
parallel=20&lt;br /&gt;
content=metadata_only&lt;br /&gt;
exclude=statistics&lt;br /&gt;
EOCAT&lt;br /&gt;
&lt;br /&gt;
expdp parfile=expdp_adst_ads_archive_metadata.par&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Find the partitions with data from the most recent month====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cat &amp;lt;&amp;lt;EOCAT&amp;gt;/tmp/adst_ads_archive_partitions.sql&lt;br /&gt;
set termo off echo off lines 1000 feedb off headi off newpa none trims on&lt;br /&gt;
spool /tmp/adst_ads_archive_partitions.lst&lt;br /&gt;
select table_owner||&amp;#039;.&amp;#039;||table_name||&amp;#039;:&amp;#039;||partition_name&lt;br /&gt;
from   dba_tab_partitions&lt;br /&gt;
where  tablespace_name = &amp;#039;ADS_ARCHIVE&amp;#039;&lt;br /&gt;
and    partition_name like &amp;#039;Y2017_Q1_M01%&amp;#039;&lt;br /&gt;
/&lt;br /&gt;
spool off&lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;@/tmp/adst_ads_archive_partitions.sql&amp;quot; | sqlplus / as sysdba&lt;br /&gt;
EOCAT&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
produces...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_CBA_BGAAP_ARC:Y2017_Q1_M01_D07&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_IFRS_ARC:Y2017_Q1_M02_D26&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_IFRS_ARC:Y2017_Q1_M02_D25&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_IFRS_ARC:Y2017_Q1_M02_D19&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_IFRS_ARC:Y2017_Q1_M02_D18&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_IFRS_ARC:Y2017_Q1_M02_D12&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_IFRS_ARC:Y2017_Q1_M02_D11&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_IFRS_ARC:Y2017_Q1_M02_D05&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_BGAAP_ARC:Y2017_Q1_M02_D26&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_BGAAP_ARC:Y2017_Q1_M02_D25&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_BGAAP_ARC:Y2017_Q1_M02_D19&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_BGAAP_ARC:Y2017_Q1_M02_D18&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_BGAAP_ARC:Y2017_Q1_M02_D12&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_BGAAP_ARC:Y2017_Q1_M02_D11&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_BGAAP_ARC:Y2017_Q1_M02_D05&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_BGAAP_ARC:Y2017_Q1_M02_D04&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_BGAAP_ARC:Y2017_Q1_M01_D29&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_BGAAP_ARC:Y2017_Q1_M01_D28&lt;br /&gt;
...&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_BGAAP_ARC:Y2017_Q1_M01_D22&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_BGAAP_ARC:Y2017_Q1_M01_D21&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_BGAAP_ARC:Y2017_Q1_M01_D15&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_BGAAP_ARC:Y2017_Q1_M01_D14&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_BGAAP_ARC:Y2017_Q1_M01_D08&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_BGAAP_ARC:Y2017_Q1_M01_D07&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_BGAAP_ARC:Y2017_Q1_M01_D01&lt;br /&gt;
ADS_ARCHIVE.BIL_MTH_INV_CTR_ARC:Y2017_Q1_M01_D01&lt;br /&gt;
ADS_ARCHIVE.BIL_DAY_INV_CTR_ARC:Y2017_Q1_M01_D01&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_IFRS_ARC:Y2017_Q1_M02_D04&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_IFRS_ARC:Y2017_Q1_M01_D29&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_IFRS_ARC:Y2017_Q1_M01_D28&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_IFRS_ARC:Y2017_Q1_M01_D22&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Export the data in these partitions====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cat&amp;lt;&amp;lt;EOCAT &amp;gt;expdp_adst_ads_archive_partitions.par&lt;br /&gt;
userid=&amp;#039;/ as sysdba&amp;#039;&lt;br /&gt;
dumpfile=adst_ads_archive_Y2017_%U.dmp&lt;br /&gt;
logfile=expdp_adst_ads_archive_Y2017.log&lt;br /&gt;
EOCAT&lt;br /&gt;
&lt;br /&gt;
cat /tmp/adst_ads_archive_partitions.lst | perl -p -i -e &amp;#039;s/^/tables=/&amp;#039;g &amp;gt;&amp;gt;expdp_adst_ads_archive_partitions.par&lt;br /&gt;
&lt;br /&gt;
cat&amp;lt;&amp;lt;EOCAT &amp;gt;&amp;gt;expdp_adst_ads_archive_partitions.par&lt;br /&gt;
parallel=20&lt;br /&gt;
exclude=statistics&lt;br /&gt;
EOCAT&lt;br /&gt;
&lt;br /&gt;
expdp parfile=expdp_adst_ads_archive_partitions.par&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Drop the old tablespace====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
drop tablespace ads_archive including contents and datafiles&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Recreate the tablepspace using the metadata capture above====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
create tablespace &amp;quot;ADS_ARCHIVE&amp;quot;&lt;br /&gt;
datafile &amp;#039;/oracle/tst/ora_data3/adst/ads_archive01.dbf&amp;#039; size 100M autoextend on next 50M maxsize unlimited&lt;br /&gt;
,        &amp;#039;/oracle/tst/ora_data3/adst/ads_archive02.dbf&amp;#039; size 100M autoextend on next 50M maxsize unlimited&lt;br /&gt;
,        &amp;#039;/oracle/tst/ora_data3/adst/ads_archive03.dbf&amp;#039; size 100M autoextend on next 50M maxsize unlimited&lt;br /&gt;
,        &amp;#039;/oracle/tst/ora_data3/adst/ads_archive04.dbf&amp;#039; size 100M autoextend on next 50M maxsize unlimited&lt;br /&gt;
,        &amp;#039;/oracle/tst/ora_data3/adst/ads_archive05.dbf&amp;#039; size 100M autoextend on next 50M maxsize unlimited&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Import the tablespace metadata====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cat&amp;lt;&amp;lt;EOCAT &amp;gt;impdp_adst_ads_archive_metadata.par&lt;br /&gt;
userid=&amp;#039;/ as sysdba&amp;#039;&lt;br /&gt;
dumpfile=adst_ads_archive_metadata.dmp&lt;br /&gt;
logfile=impdp_adst_ads_archive_metadata.log&lt;br /&gt;
EOCAT&lt;br /&gt;
&lt;br /&gt;
impdp parfile=impdp_adst_ads_archive_metadata.par&lt;br /&gt;
&lt;br /&gt;
select &amp;#039;alter index &amp;#039;|| owner||&amp;#039;.&amp;#039;||index_name||&amp;#039; rebuild online parallel 8;&amp;#039;&lt;br /&gt;
from   dba_indexes&lt;br /&gt;
where  status = &amp;#039;UNUSABLE&amp;#039;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Import the last month partition data====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cat&amp;lt;&amp;lt;EOCAT &amp;gt;impdp_adst_ads_archive_partitions.par&lt;br /&gt;
userid=&amp;#039;/ as sysdba&amp;#039;&lt;br /&gt;
dumpfile=adst_ads_archive_Y2017_%U.dmp&lt;br /&gt;
logfile=impdp_adst_ads_archive_Y2017.log&lt;br /&gt;
table_exists_action=append&lt;br /&gt;
parallel=20&lt;br /&gt;
EOCAT&lt;br /&gt;
&lt;br /&gt;
impdp parfile=impdp_adst_ads_archive_partitions.par&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Write to a TCP/IP socket from PL/SQL===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
declare&lt;br /&gt;
 bt_conn               utl_tcp.connection;&lt;br /&gt;
 retval                binary_integer;&lt;br /&gt;
 l_sequence            varchar2(30) := &amp;#039;Sequence Number 101021&amp;#039;;&lt;br /&gt;
begin&lt;br /&gt;
 bt_conn := utl_tcp.open_connection(remote_host =&amp;gt; &amp;#039;10.10.1.1&amp;#039;&lt;br /&gt;
                                   ,remote_port =&amp;gt; 5000&lt;br /&gt;
                                   ,tx_timeout =&amp;gt; 1&lt;br /&gt;
                                   )&lt;br /&gt;
 ;&lt;br /&gt;
 retval := utl_tcp.write_line(bt_conn,l_sequence)&lt;br /&gt;
 ;&lt;br /&gt;
 utl_tcp.flush(bt_conn)&lt;br /&gt;
 ;&lt;br /&gt;
 utl_tcp.close_connection(bt_conn)&lt;br /&gt;
 ;&lt;br /&gt;
exception&lt;br /&gt;
 when others then&lt;br /&gt;
  raise_application_error(-20101, sqlerrm)&lt;br /&gt;
  ; &lt;br /&gt;
  utl_tcp.close_connection(bt_conn)&lt;br /&gt;
  ;&lt;br /&gt;
end&lt;br /&gt;
;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
and read from it using netcat in another session&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
nc -lk 5000&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
produces&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Sequence Number 101021&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Execute a script as a different user===&lt;br /&gt;
Some things have to be done as the user and cannot be done as sys (eg. creating and dropping jobs or create and drop a database link)&amp;lt;br /&amp;gt;&lt;br /&gt;
It is possible to login as the user by saving, changing and resetting his password (using identified by values) but using dbms_sys_sql is another option&amp;lt;br /&amp;gt;&lt;br /&gt;
Create a PL/SQL procedure to drop a db link&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
create or replace procedure drop_dblink ( p_schema_name in varchar2&lt;br /&gt;
                                        , p_dblink      in varchar2&lt;br /&gt;
                                        ) is&lt;br /&gt;
    l_plsql   varchar2(1000);&lt;br /&gt;
    l_cur     number;&lt;br /&gt;
    l_uid     number;&lt;br /&gt;
    l_rc      number;&lt;br /&gt;
begin&lt;br /&gt;
    select  du.user_id&lt;br /&gt;
    into    l_uid&lt;br /&gt;
    from    dba_users du&lt;br /&gt;
    where   du.username = p_schema_name&lt;br /&gt;
    ;&lt;br /&gt;
    plsql := &amp;#039;drop database link &amp;quot;&amp;#039;||p_dblink||&amp;#039;&amp;quot;&amp;#039;;&lt;br /&gt;
    l_cur := sys.dbms_sys_sql.open_cursor;&lt;br /&gt;
    sys.dbms_sys_sql.parse_as_user(&lt;br /&gt;
        c             =&amp;gt; l_cur,&lt;br /&gt;
        statement     =&amp;gt; l_plsql,&lt;br /&gt;
        language_flag =&amp;gt; dbms_sql.native,&lt;br /&gt;
        userid        =&amp;gt; l_uid&lt;br /&gt;
    );&lt;br /&gt;
    l_rc := sys.dbms_sys_sql.execute(l_cur);&lt;br /&gt;
    sys.dbms_sys_sql.close_cursor(l_cur);&lt;br /&gt;
end;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Generate the calls to the procedure with the required parameters&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select &amp;#039;exec drop_dblink (&amp;#039;&amp;#039;&amp;#039;|| owner ||&amp;#039;&amp;#039;&amp;#039;&amp;#039;||&amp;#039;, &amp;#039;||&amp;#039;&amp;#039;&amp;#039;&amp;#039;||db_link||&amp;#039;&amp;#039;&amp;#039;&amp;#039;||&amp;#039;);&amp;#039;&lt;br /&gt;
from   dba_db_links&lt;br /&gt;
where  owner   != &amp;#039;PUBLIC&amp;#039;&lt;br /&gt;
and    db_link like &amp;#039;%FTST%&amp;#039;&lt;br /&gt;
or     db_link like &amp;#039;%HDEV%&amp;#039;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
and this reveals the lines to be executed&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
exec drop_dblink (&amp;#039;USER1&amp;#039;, &amp;#039;DBL_FTST.WORLD&amp;#039;);&lt;br /&gt;
exec drop_dblink (&amp;#039;USER1&amp;#039;, &amp;#039;DBL_HDEV.WORLD&amp;#039;);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Drop the procedure when finished with it&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
drop procedure drop_dblink;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
or do it as an anonymous block in one go...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
declare&lt;br /&gt;
    uid number;&lt;br /&gt;
    sqltext varchar2(1000) := &amp;#039;drop database link &amp;quot;&amp;amp;DB_LINK&amp;quot;&amp;#039;;&lt;br /&gt;
    myint integer;&lt;br /&gt;
begin&lt;br /&gt;
    select user_id into uid from dba_users where username = &amp;#039;&amp;amp;USERNAME&amp;#039;;&lt;br /&gt;
    myint:=sys.dbms_sys_sql.open_cursor();&lt;br /&gt;
    sys.dbms_sys_sql.parse_as_user(myint,sqltext,dbms_sql.native,UID);&lt;br /&gt;
    sys.dbms_sys_sql.close_cursor(myint);&lt;br /&gt;
end;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Handling single quote marks inside SQL statements===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SQL&amp;gt; SELECT &amp;#039;D&amp;#039;&amp;#039;COSTA&amp;#039; name FROM DUAL;&lt;br /&gt;
&lt;br /&gt;
NAME&lt;br /&gt;
-------&lt;br /&gt;
D&amp;#039;COSTA&lt;br /&gt;
&lt;br /&gt;
Alternatively, use the 10g+ quoting method:&lt;br /&gt;
&lt;br /&gt;
SQL&amp;gt; SELECT q&amp;#039;$D&amp;#039;COSTA$&amp;#039; NAME FROM DUAL;&lt;br /&gt;
&lt;br /&gt;
NAME&lt;br /&gt;
-------&lt;br /&gt;
D&amp;#039;COSTA&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Run a script on all databases in /etc/oratab===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
export ORAENV_ASK=NO&lt;br /&gt;
for db in `awk -F: &amp;#039;NF &amp;amp;&amp;amp; $1 !~/[#*]/ {print $1}&amp;#039;  /etc/oratab`&lt;br /&gt;
do&lt;br /&gt;
    echo $db&lt;br /&gt;
    ORACLE_SID=$db&lt;br /&gt;
    . oraenv&lt;br /&gt;
    sqlplus -V&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Schedule a cron job to run on the last day of each month===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
0 23 28-31 * * [ $(date -d +1day +%d) -eq 1 ] &amp;amp;&amp;amp; su - oracle -c &amp;quot;dsmc  arch -server=SO_U_`hostname`_ORX_M_SOL &amp;#039;/oracle/export/PV6/expdp_PV6_D_FULL_`date +\%Y\%m\%d`*&amp;#039;&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===How to tell if a year is a leap year or not - using cal instead of reinventing the wheel===&lt;br /&gt;
Test: Why is Julian day 0, 17th November 1858?&amp;lt;br /&amp;gt;&lt;br /&gt;
Pretty comprehensive answer: [http://h71000.www7.hp.com/wizard/wiz_2315.html here] and [http://mentalfloss.com/article/51370/why-our-calendars-skipped-11-days-1752 here]&amp;lt;br /&amp;gt;&lt;br /&gt;
Also attempts to answer the question why typing &amp;#039;cal 09 1752&amp;#039; on Unix systems looks so odd!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
function leap {&lt;br /&gt;
#  This function tells you if the year passed in as a parameter is a leap year or not...&lt;br /&gt;
if [[ $(cal 2 ${1:-$(date &amp;#039;+%Y&amp;#039;)} | egrep &amp;#039;\&amp;lt;[[:digit:]]{1,2}\&amp;gt;&amp;#039; | wc -w) -eq 29 ]]; then&lt;br /&gt;
    leap=&amp;#039;Y&amp;#039;&lt;br /&gt;
else&lt;br /&gt;
    leap=&amp;#039;N&amp;#039;&lt;br /&gt;
fi&lt;br /&gt;
echo ${leap}&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Reset an expired (and/or locked) user password to the same value===&lt;br /&gt;
Can be used to save user passwords for example in a test environment before destroying them with a copy of production.&amp;lt;br /&amp;gt;&lt;br /&gt;
Simple, quick and easy version. Run this then pick and choose the statements you want to run.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 200 pages 200&lt;br /&gt;
col user_list for a200 head &amp;quot;Expired User List&amp;quot;&lt;br /&gt;
&lt;br /&gt;
select &amp;#039;alter user &amp;#039; ||su.name||&amp;#039; identified by values&amp;#039;||&amp;#039;&amp;#039;&amp;#039;&amp;#039;||spare4||&amp;#039;;&amp;#039;||su.password||&amp;#039;&amp;#039;&amp;#039; account unlock;&amp;#039; user_list&lt;br /&gt;
from   sys.user$ su&lt;br /&gt;
,      dba_users du&lt;br /&gt;
where  1=1&lt;br /&gt;
and    su.name              = du.username&lt;br /&gt;
and    du.oracle_maintained = &amp;#039;N&amp;#039;&lt;br /&gt;
and    (account_status      like &amp;#039;EXPIRED%&amp;#039; or account_status like &amp;#039;%LOCKED&amp;#039;)&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
More industrialised version. Create a package.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
create or replace package dba_utils&lt;br /&gt;
as&lt;br /&gt;
    procedure reset_password ( p_userlist in varchar2 );&lt;br /&gt;
end dba_utils;&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
create or replace package body dba_utils&lt;br /&gt;
as&lt;br /&gt;
&lt;br /&gt;
procedure reset_password ( p_userlist in varchar2 )&lt;br /&gt;
is&lt;br /&gt;
    cursor c1 ( p_userlist in varchar2 ) is&lt;br /&gt;
    select username&lt;br /&gt;
    ,      regexp_substr ( dbms_metadata.get_ddl(&amp;#039;USER&amp;#039;, username), &amp;#039;&amp;#039;&amp;#039;[^&amp;#039;&amp;#039;]+&amp;#039;&amp;#039;&amp;#039; ) pwd&lt;br /&gt;
    from   dba_users&lt;br /&gt;
    where  1=1&lt;br /&gt;
    and    username in upper( p_userlist )&lt;br /&gt;
    ;&lt;br /&gt;
begin&lt;br /&gt;
    dbms_output.enable(null);&lt;br /&gt;
    for r1 in c1 ( p_userlist )&lt;br /&gt;
    loop&lt;br /&gt;
        begin&lt;br /&gt;
            execute immediate &amp;#039;alter user &amp;#039; || r1.username || &amp;#039; account unlock&amp;#039;;&lt;br /&gt;
            execute immediate &amp;#039;alter user &amp;#039; || r1.username || &amp;#039; identified by values &amp;#039; || r1.pwd;&lt;br /&gt;
        exception&lt;br /&gt;
        when others then&lt;br /&gt;
            dbms_output.put_line(&amp;#039;Unable to modify user &amp;#039; || r1.username);&lt;br /&gt;
        end;&lt;br /&gt;
    end loop;&lt;br /&gt;
end reset_password;&lt;br /&gt;
&lt;br /&gt;
end dba_utils;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Call it&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set serveroutput on&lt;br /&gt;
exec dba_utils.reset_password (&amp;#039;STUART&amp;#039;);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Latch, mutex and beyond===&lt;br /&gt;
A fine example of how to write scripts from SQL*Plus that interact with the shell underneath&amp;lt;br /&amp;gt;&lt;br /&gt;
Found [https://andreynikolaev.wordpress.com/demonstration-scripts/cursor_pin_s_contention-sql/ here at andreynikolaev.wordpress.com]&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/*&lt;br /&gt;
     This file is part of demos for &amp;quot;Mutex Internals&amp;quot;  seminar v.04.04.2011&lt;br /&gt;
     Andrey S. Nikolaev (Andrey.Nikolaev@rdtex.ru) &lt;br /&gt;
     https://andreynikolaev.wordpress.com &lt;br /&gt;
 &lt;br /&gt;
     &amp;quot;Cursor: pin S&amp;quot; contention testcase.&lt;br /&gt;
 &lt;br /&gt;
     The script spawn several sessions to induce &amp;quot;Cursor: pin S&amp;quot;, &lt;br /&gt;
     creates AWR snapshots and generates AWR report&lt;br /&gt;
 &lt;br /&gt;
     Beware: The script will restart the test database.&lt;br /&gt;
 &lt;br /&gt;
     usage: sqlplus /nolog @cursor_pin_s_contention.sql &amp;lt;parallelism&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
*/ &lt;br /&gt;
connect / as sysdba&lt;br /&gt;
startup force&lt;br /&gt;
set echo off&lt;br /&gt;
set define %&lt;br /&gt;
set verify off&lt;br /&gt;
set head off&lt;br /&gt;
set linesize 300&lt;br /&gt;
 &lt;br /&gt;
/* spawn parallel processes to create load on mutex */&lt;br /&gt;
spool one_thread.tmp&lt;br /&gt;
select &amp;#039;set verify off&amp;#039; from dual;&lt;br /&gt;
select &amp;#039;alter session set session_cached_cursors = 50;&amp;#039; from dual; &lt;br /&gt;
select &amp;#039;begin for i in 1..1000000 loop&amp;#039; from dual;&lt;br /&gt;
select &amp;#039;      execute immediate &amp;#039;&amp;#039;select 1 from dual where 1=2&amp;#039;&amp;#039;;&amp;#039; from dual;&lt;br /&gt;
select &amp;#039;end loop; end;&amp;#039;||chr(10)||&amp;#039;/&amp;#039; from dual;&lt;br /&gt;
spool off&lt;br /&gt;
 &lt;br /&gt;
/* sleep while AWR initialized */&lt;br /&gt;
host sleep 5&lt;br /&gt;
 &lt;br /&gt;
exec dbms_workload_repository.create_snapshot();&lt;br /&gt;
 &lt;br /&gt;
spool many_threads.tmp&lt;br /&gt;
select &amp;#039;host sqlplus &amp;quot;/ as sysdba&amp;quot; @one_thread.tmp &amp;amp;&amp;#039;&lt;br /&gt;
from dba_objects where rownum &amp;lt;= %1;&lt;br /&gt;
spool off&lt;br /&gt;
 &lt;br /&gt;
@many_threads.tmp&lt;br /&gt;
host sleep 50&lt;br /&gt;
set echo on&lt;br /&gt;
exec dbms_workload_repository.create_snapshot();&lt;br /&gt;
set markup html on&lt;br /&gt;
set head on&lt;br /&gt;
spool mutex_sleep_history.htm&lt;br /&gt;
select to_char(SLEEP_TIMESTAMP,&amp;#039;hh:mi:ss.ff&amp;#039;) SLEEP_TIMESTAMP,MUTEX_ADDR,MUTEX_IDENTIFIER,MUTEX_TYPE,&lt;br /&gt;
       GETS,SLEEPS,REQUESTING_SESSION,BLOCKING_SESSION,&lt;br /&gt;
       LOCATION,MUTEX_VALUE from x$mutex_sleep_history order by sleep_timestamp;&lt;br /&gt;
spool off&lt;br /&gt;
 &lt;br /&gt;
set define &amp;amp;&lt;br /&gt;
set markup html off&lt;br /&gt;
set echo off heading on underline on;&lt;br /&gt;
column inst_num  heading &amp;quot;Inst Num&amp;quot;  new_value inst_num  format 99999;&lt;br /&gt;
column inst_name heading &amp;quot;Instance&amp;quot;  new_value inst_name format a12;&lt;br /&gt;
column db_name   heading &amp;quot;DB Name&amp;quot;   new_value db_name   format a12;&lt;br /&gt;
column dbid      heading &amp;quot;DB Id&amp;quot;     new_value dbid      format 9999999999 just c;&lt;br /&gt;
select d.dbid            dbid&lt;br /&gt;
     , d.name            db_name&lt;br /&gt;
     , i.instance_number inst_num&lt;br /&gt;
     , i.instance_name   inst_name&lt;br /&gt;
  from v$database d,&lt;br /&gt;
       v$instance i;&lt;br /&gt;
define num_days=1;&lt;br /&gt;
define report_type=&amp;#039;html&amp;#039;;&lt;br /&gt;
col end_snap new_value end_snap;&lt;br /&gt;
col begin_snap new_value begin_snap;&lt;br /&gt;
select max(snap_id) end_snap from dba_hist_snapshot where dbid=&amp;amp;dbid;&lt;br /&gt;
select max(snap_id) begin_snap from dba_hist_snapshot where dbid=&amp;amp;dbid and snap_id &amp;lt; &amp;amp;end_snap;&lt;br /&gt;
define report_name=&amp;#039;awr_report.htm&amp;#039;;&lt;br /&gt;
@?/rdbms/admin/awrrpti&lt;br /&gt;
exit&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==shell==&lt;br /&gt;
[http://www.databasejournal.com/features/oracle/article.php/3869076/Alert-Log-Scraping-with-Oracles-ADRCI-Utility.htm Alert Log scraping with ADRCI]&lt;br /&gt;
&lt;br /&gt;
====Count the number of background processes for a particular SID====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SID=RAVJDE1&lt;br /&gt;
ps -ef|cut -c54-100|awk -v SID=$SID &amp;#039;$0 ~ /&amp;#039;$SID&amp;#039;$/ {print}&amp;#039;|wc -l&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or ...this will work with any OS (so long as the process is at the end of the &amp;lt;strong&amp;gt;ps -ef&amp;lt;/strong&amp;gt; or &amp;lt;strong&amp;gt;ps -aux&amp;lt;/strong&amp;gt; listing&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SID=RAVJDE1&lt;br /&gt;
ps -ef|awk -v SID=$SID -F_ &amp;#039;{ $NF ~ /&amp;#039;$SID&amp;#039;$/ {print} }&amp;#039;|wc -l&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Pick the columns you want in the ps listing&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ps -efo user,pid,ppid=MOM -o args&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Find Oracle errors in the most recent DataPump log files====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
00 09 * * * /home/tools/scripts/oracle/dosh &amp;#039;find /oracle/export -name &amp;quot;expdp*log&amp;quot; -mtime -1 -exec grep ORA- {} \; -ls&amp;#039; | mailx -s &amp;#039;Datapump errors for &amp;lt;customer&amp;gt;last night&amp;#039; stuart@domain.com&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Find the 10 largest directories on a particular filesystem====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
du -ag /oracle | sort -nr | head -n 10&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Find the 10 largest files on a particular mount point====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
find /home -size +1G -ls | sort -nr +6 | head -10&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
find /home -xdev -ls | sort -nr +6 | head -10&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Split a file in pieces using sed====&lt;br /&gt;
Using fixed line numbers&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sed -ne &amp;#039;1,12p&amp;#039; file &amp;gt; text.part1&lt;br /&gt;
sed -ne &amp;#039;13,$p&amp;#039; file &amp;gt; text.part2&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Using line with a /pattern/ on it&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sed -e &amp;#039;/hello/q&amp;#039; tt.dat | grep -v hello &amp;gt; text.part1&lt;br /&gt;
sed -n `sed -n &amp;#039;/hello/=&amp;#039; tt.dat`&amp;#039;,$p&amp;#039; tt.dat | grep -v hello &amp;gt; text.part2&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Split a file in pieces using Perl====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
perl -ne &amp;#039;print if 1 .. /marker line/&amp;#039; text.dat &amp;gt;text.part1&lt;br /&gt;
perl -ne &amp;#039;print if /marker line/ .. eof()&amp;#039; text.dat &amp;gt;text.part2&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Find and display RMAN errors in an RMAN log file====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sed -ne &amp;#039;/^RMAN-/,/^$/p&amp;#039;  RMAN_&amp;lt;SID&amp;gt;_&amp;lt;DATE&amp;gt;.log&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==cmd==&lt;br /&gt;
*[http://www.dba-oracle.com/t_scripts_windows_export.htm Database Export - from DBA Oracle (Burleson)]&lt;br /&gt;
==Perl==&lt;br /&gt;
===For all files in a directory, replace a keyword (SSIIDD) in a file with another (a parameter)===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
for i in `ls`&lt;br /&gt;
do&lt;br /&gt;
    perl -p -i -e &amp;#039;s/SSIIDD/&amp;#039;$SID&amp;#039;/g&amp;#039; $i&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Parse tnsnames.ora to get just the service names===&lt;br /&gt;
[[http://stackoverflow.com/questions/12605415/parsing-tnsnames-ora-with-regex-to-just-get-name from here]]&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
perl -ne &amp;#039;print if m/^([^#()\W ][a-zA-Z.]*(?:[.][a-zA-Z]*\s?=)?)/&amp;#039; $TNS_ADMIN/tnsnames.ora&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===and use that to check the listener status===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
for svc in `perl -ne &amp;#039;print if m/^([^#()\W ][a-zA-Z.]*(?:[.][a-zA-Z]*\s?=)?)/&amp;#039; $TNS_ADMIN/tnsnames.ora | sed -e &amp;#039;s/=//&amp;#039;` ;do&lt;br /&gt;
    tnsping $svc&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Stuart</name></author>	</entry>

	<entry>
		<id>https://mailnest.com/dbawiki/index.php?title=Handy_scripts&amp;diff=3369</id>
		<title>Handy scripts</title>
		<link rel="alternate" type="text/html" href="https://mailnest.com/dbawiki/index.php?title=Handy_scripts&amp;diff=3369"/>
				<updated>2018-11-21T11:54:12Z</updated>
		
		<summary type="html">&lt;p&gt;Stuart: /* Start the job */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==SQL==&lt;br /&gt;
* [[Database Overview - from idevelopment]] [http://www.idevelopment.info/data/Oracle/DBA_scripts/Database_Administration/dba_snapshot_database_10g.sql online version]&lt;br /&gt;
* [[Extract ddl with &amp;quot;dbms metadata.get ddl&amp;quot;]]&lt;br /&gt;
* [http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:83012348058 Connecting as another user via proxy in SQL*Plus]&lt;br /&gt;
* [http://www.petefinnigan.com/tools.htm Password cracker and role and priv tools from Pete Finnigan]&lt;br /&gt;
* [http://www.oracle.com/technetwork/articles/sql/11g-pivot-097235.html Using pivot tables in SQL - XML and XLS (Excel) also)]&lt;br /&gt;
===List all instances running on a server===&lt;br /&gt;
Sounds simple enough and indeed pre 12.1, is was as easy as either&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ps -ef | grep [p]mon | awk -F_ &amp;#039;{print $NF}&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or this one is safer in case you have an underscore character in your SID name!!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SIDLIST=$(${PS} -ef | ${GREP} [o]ra_pmon | ${AWK} &amp;#039;{print $NF}&amp;#039; | sed -e &amp;#039;s/ora_pmon_//&amp;#039; | egrep -v &amp;#039;grep|///|sed|awk|ASM|^$&amp;#039;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
but now we have the added complication of CDB/PDB (container / pluggable databases) so a fair bit more work is needed!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/ksh&lt;br /&gt;
# ==============================================================================&lt;br /&gt;
# Name         : list_server_db&lt;br /&gt;
# Description  : List all running databases found on a server&lt;br /&gt;
#&lt;br /&gt;
# Parameters   : none&lt;br /&gt;
#&lt;br /&gt;
# Notes        : none&lt;br /&gt;
#&lt;br /&gt;
# Modification History&lt;br /&gt;
# ====================&lt;br /&gt;
# When      Who               What&lt;br /&gt;
# ========= ================= ==================================================&lt;br /&gt;
# 21-DEC-16 Stuart Barkley    Created&lt;br /&gt;
# ==============================================================================&lt;br /&gt;
for db in $(ps -ef | grep [p]mon|awk -F_ &amp;#039;{print $NF}&amp;#039;)&lt;br /&gt;
do&lt;br /&gt;
    export ORACLE_SID=${db}&lt;br /&gt;
    ORAENV_ASK=NO&lt;br /&gt;
    . oraenv &amp;gt;/dev/null 2&amp;gt;&amp;amp;1&lt;br /&gt;
    sqlplus -s / as sysdba&amp;lt;&amp;lt;EOSQL&lt;br /&gt;
set serveroutput on feed off pages 0 head off newpa none&lt;br /&gt;
declare&lt;br /&gt;
    e_col_not_found exception;&lt;br /&gt;
    e_not_mounted   exception;&lt;br /&gt;
    pragma          exception_init(e_not_mounted, -01507);&lt;br /&gt;
    pragma          exception_init(e_col_not_found, -904);&lt;br /&gt;
    l_db_name       varchar2(20);&lt;br /&gt;
    l_database_role varchar2(20);&lt;br /&gt;
    l_cdb           varchar2(20);&lt;br /&gt;
    l_status        varchar2(20);&lt;br /&gt;
    type varchar2_tab is table of varchar2(240) index by binary_integer;&lt;br /&gt;
    t_pdbs          varchar2_tab;&lt;br /&gt;
begin&lt;br /&gt;
    begin&lt;br /&gt;
        dbms_output.enable(null);&lt;br /&gt;
        execute immediate &amp;#039;select name, database_role, cdb from v\$database&amp;#039; into l_db_name, l_database_role, l_cdb;&lt;br /&gt;
        if l_cdb = &amp;#039;YES&amp;#039; then&lt;br /&gt;
            l_status := &amp;#039;CDB&amp;#039;;&lt;br /&gt;
            execute immediate &amp;#039;select name from v\$pdbs&amp;#039; bulk collect into t_pdbs;&lt;br /&gt;
            for i in nvl(t_pdbs.first,1) .. nvl(t_pdbs.last,0)&lt;br /&gt;
            loop&lt;br /&gt;
                dbms_output.put_line (t_pdbs(i)||&amp;#039;:PDB&amp;#039;);&lt;br /&gt;
            end loop;&lt;br /&gt;
        else&lt;br /&gt;
            l_status := &amp;#039;Independent&amp;#039;;  -- col CDB exists but this is not one&lt;br /&gt;
        end if;&lt;br /&gt;
        if l_database_role like &amp;#039;%STANDBY%&amp;#039; then&lt;br /&gt;
            l_status := &amp;#039;Standby&amp;#039;;&lt;br /&gt;
        end if;&lt;br /&gt;
    exception&lt;br /&gt;
    when e_not_mounted then&lt;br /&gt;
        l_status := &amp;#039;Not Mounted&amp;#039;;&lt;br /&gt;
    when e_col_not_found then&lt;br /&gt;
        l_status := &amp;#039;pre12&amp;#039;;&lt;br /&gt;
    end;&lt;br /&gt;
&lt;br /&gt;
    dbms_output.put_line (&amp;#039;${db}&amp;#039;||&amp;#039;:&amp;#039;||l_status);&lt;br /&gt;
&lt;br /&gt;
end;&lt;br /&gt;
/&lt;br /&gt;
EOSQL&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Run a command or script on all databases in tnsnames.ora===&lt;br /&gt;
Very handy if you have a global tnsnames.ora accessible to all clients.&amp;lt;br /&amp;gt;&lt;br /&gt;
So from a client install, this has access to all databases.&amp;lt;br /&amp;gt;&lt;br /&gt;
Any files created can be created on the client so no need to scp to all the machines to recover spool files etc.&amp;lt;br /&amp;gt;&lt;br /&gt;
Downside: Cannot connect as sysdba across tns so password will need to be known for whatever user is used.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/ksh&lt;br /&gt;
TNSNAMES=&amp;quot;./tnsnames.ora&amp;quot;&lt;br /&gt;
[[ ! -r &amp;quot;${TNSNAMES}&amp;quot; ]] &amp;amp;&amp;amp; echo &amp;quot;${TNSNAMES} is not accessible&amp;quot; &amp;amp;&amp;amp; exit 1&lt;br /&gt;
&lt;br /&gt;
SIDLIST=$(perl -ne &amp;#039;print &amp;quot;$1\n&amp;quot; if /(?:SID|SERVICE_NAME)\s*=\s*(\S+?)\)/&amp;#039; ${TNSNAMES}|sort|uniq|xargs)&lt;br /&gt;
for SID in ${SIDLIST}&lt;br /&gt;
do&lt;br /&gt;
    echo &amp;quot;Processing $SID&amp;quot;&lt;br /&gt;
    ls -al | grep &amp;quot;^d&amp;quot; | grep &amp;quot;\_${SID}&amp;quot; &amp;gt;/dev/null&lt;br /&gt;
    if [[ $? -ne 0 ]]; then&lt;br /&gt;
        echo &amp;#039;exit&amp;#039; | sqlplus system/xxxxxx@${SID} @ReviewLite17.1.sql &amp;gt;/dev/null 2&amp;gt;&amp;amp;1&lt;br /&gt;
    else&lt;br /&gt;
        echo &amp;quot;directory already exists so must have done this SID&amp;quot;&lt;br /&gt;
    fi&lt;br /&gt;
done&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Run a command or script on all databases in oratab===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/usr/bin/ksh&lt;br /&gt;
# ==============================================================================&lt;br /&gt;
# Name         : all_db_do&lt;br /&gt;
# Description  : Loops over all the databases in oratab and executes the&lt;br /&gt;
#                specified SQL command - be careful!&lt;br /&gt;
#&lt;br /&gt;
# Parameters   : -v flag for verbose&lt;br /&gt;
#                [-f &amp;lt;filename&amp;gt; | &amp;lt;quoted SQL command to be executed&amp;gt;]&lt;br /&gt;
#&lt;br /&gt;
# Example      : all_db_do &amp;#039;alter system switch logfile;&amp;#039;&lt;br /&gt;
#                all_db_do -f sessions.sql&lt;br /&gt;
#&lt;br /&gt;
# Notes        : none&lt;br /&gt;
#&lt;br /&gt;
# Modification History&lt;br /&gt;
# ====================&lt;br /&gt;
# When      Who               What&lt;br /&gt;
# ========= ================= ==================================================&lt;br /&gt;
# 14-JAN-13 Stuart Barkley    Created&lt;br /&gt;
# 25-FEB-13 Stuart Barkley    Adapt for Solaris&lt;br /&gt;
# 21-MAR-13 Stuart Barkley    Check db is running first&lt;br /&gt;
# 29-APR-13 Stuart Barkley    Added verbose flag processing&lt;br /&gt;
# 24-MAY-13 Stuart Barkley    Wrap / as sysdba in quotes for older versions&lt;br /&gt;
# 23-JUN-16 Stuart Barkley    Add -f to run a file containing sql&lt;br /&gt;
# ==============================================================================&lt;br /&gt;
&lt;br /&gt;
PROGNAME=$(basename $0)&lt;br /&gt;
OS=$(uname -s)&lt;br /&gt;
&lt;br /&gt;
AWK=$(which awk)&lt;br /&gt;
GREP=$(which grep)&lt;br /&gt;
if [[ &amp;quot;${OS}&amp;quot; == &amp;quot;SunOS&amp;quot; ]]; then&lt;br /&gt;
    AWK=/usr/xpg4/bin/awk&lt;br /&gt;
    GREP=/usr/xpg4/bin/grep&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
if [[ ! -r /etc/oratab ]]; then&lt;br /&gt;
    if [[ &amp;quot;${OS}&amp;quot; == &amp;quot;SunOS&amp;quot; ]]; then&lt;br /&gt;
        echo &amp;quot;oratab is not where we want it. Please run &amp;#039;ln -s /var/opt/oracle/oratab /etc/oratab&amp;#039; as root and retry&amp;quot; &amp;amp;&amp;amp; exit 1&lt;br /&gt;
    else&lt;br /&gt;
        echo &amp;quot;Either Oracle is not installed or database is running without an oratab&amp;quot; &amp;amp;&amp;amp; exit 1&lt;br /&gt;
    fi&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
# -------------------------&lt;br /&gt;
# get the arguments, if any&lt;br /&gt;
# -------------------------&lt;br /&gt;
unset VERBOSE&lt;br /&gt;
while getopts &amp;quot;vf:&amp;quot; flag&lt;br /&gt;
do&lt;br /&gt;
    case &amp;quot;$flag&amp;quot; in&lt;br /&gt;
    v) VERBOSE=1;;&lt;br /&gt;
    f) FILE2RUN=$OPTARG;;&lt;br /&gt;
    esac&lt;br /&gt;
done&lt;br /&gt;
shift $((OPTIND-1))&lt;br /&gt;
&lt;br /&gt;
if [[ -z ${FILE2RUN} ]]; then&lt;br /&gt;
    # no file, need an SQL supplied&lt;br /&gt;
    if [[ -z $1 ]]; then&lt;br /&gt;
        echo &amp;quot;Usage: $0 [-v] [-f &amp;lt;filename&amp;gt; | &amp;lt;quoted SQL command to be executed&amp;gt;]&amp;quot;&lt;br /&gt;
        echo &amp;quot;eg: $0 -f sessions.sql&amp;quot;&lt;br /&gt;
        echo &amp;quot;eg: $0 &amp;#039;alter system switch logfile;&amp;#039;&amp;quot;&lt;br /&gt;
        exit 1&lt;br /&gt;
    fi&lt;br /&gt;
    SQL=$1&lt;br /&gt;
elif [[ -s ${FILE2RUN} ]]; then&lt;br /&gt;
    # file supplied and exists&lt;br /&gt;
    SQL=&amp;quot;@${FILE2RUN}&amp;quot;&lt;br /&gt;
else&lt;br /&gt;
    # file supplied, does it exist&lt;br /&gt;
    echo &amp;quot;File ${FILE2RUN} is empty or does not exist&amp;quot;&lt;br /&gt;
    echo &amp;quot;Usage: $0 [-v] [-f &amp;lt;filename&amp;gt; | &amp;lt;quoted SQL command to be executed&amp;gt;]&amp;quot;&lt;br /&gt;
    echo &amp;quot;eg: $0 -f sessions.sql&amp;quot;&lt;br /&gt;
    echo &amp;quot;eg: $0 &amp;#039;alter system switch logfile;&amp;#039;&amp;quot;&lt;br /&gt;
    exit 1&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
export ORAENV_ASK=NO&lt;br /&gt;
&lt;br /&gt;
for db in $(${AWK} -F: &amp;#039;NF &amp;amp;&amp;amp; $1 !~/[#*]/ {print $1}&amp;#039;  /etc/oratab)&lt;br /&gt;
do&lt;br /&gt;
    if ( [[ $1 != &amp;quot;startup&amp;quot; ]] &amp;amp;&amp;amp; [[ $(ps -ef | ${GREP} -c -E [o]ra_pmon_${db}) -eq 0 ]] ); then&lt;br /&gt;
        [[ ! -z &amp;quot;$VERBOSE&amp;quot; ]] &amp;amp;&amp;amp; echo &amp;quot;$db is not running, skipping...&amp;quot;&lt;br /&gt;
        continue&lt;br /&gt;
    fi&lt;br /&gt;
    echo&lt;br /&gt;
    [[ ! -z &amp;quot;$VERBOSE&amp;quot; ]] &amp;amp;&amp;amp; echo &amp;quot;vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv&amp;quot;&lt;br /&gt;
    [[ ! -z &amp;quot;$VERBOSE&amp;quot; ]] &amp;amp;&amp;amp; echo $db&lt;br /&gt;
    ORACLE_SID=$db&lt;br /&gt;
    . oraenv &amp;gt;/dev/null&lt;br /&gt;
    sqlplus -s &amp;quot;/ as sysdba&amp;quot; &amp;lt;&amp;lt;EOSQL&lt;br /&gt;
define SID=$ORACLE_SID&lt;br /&gt;
col comp_name format a50&lt;br /&gt;
col value for a40&lt;br /&gt;
set linesize 1000&lt;br /&gt;
set pagesize 100&lt;br /&gt;
$SQL&lt;br /&gt;
EOSQL&lt;br /&gt;
    [[ ! -z &amp;quot;$VERBOSE&amp;quot; ]] &amp;amp;&amp;amp; echo &amp;quot;^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^&amp;quot;&lt;br /&gt;
done&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
all_db_do &amp;quot;create or replace directory data_pump_dir as &amp;#039;/oracle/export/&amp;amp;SID&amp;#039;;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
all_db_do &amp;quot;archive log list&amp;quot;&lt;br /&gt;
&lt;br /&gt;
all_db_do &amp;quot;shutdown immediate&amp;quot;&lt;br /&gt;
&lt;br /&gt;
all_db_do &amp;#039;alter system set log_archive_dest_1=&amp;quot;location=/oracle/arch/&amp;amp;SID&amp;quot; scope=both;&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Run an SQL command on behalf of another user===&lt;br /&gt;
It can be used to execute any sql command as a specified user provided this procedure is created in sys schema.&amp;lt;br /&amp;gt;&lt;br /&gt;
* not got this working properly yet *&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set serveroutput on&lt;br /&gt;
create or replace procedure run_sql_as_user ( p_schema_name in varchar2&lt;br /&gt;
                                            , p_sql         in varchar2&lt;br /&gt;
                                            ) is&lt;br /&gt;
    l_user_id dba_users.user_id%type;&lt;br /&gt;
    l_cursor  number;&lt;br /&gt;
    l_rc      number;&lt;br /&gt;
begin&lt;br /&gt;
    dbms_output.enable(null);&lt;br /&gt;
    begin&lt;br /&gt;
        select u.user_id&lt;br /&gt;
        into   l_user_id&lt;br /&gt;
        from   dba_users u&lt;br /&gt;
        where  u.username = p_schema_name;&lt;br /&gt;
    exception&lt;br /&gt;
    when no_data_found then&lt;br /&gt;
        raise_application_error (-20001, &amp;#039;Cannot find user &amp;#039;||p_schema_name);&lt;br /&gt;
    end;&lt;br /&gt;
    l_cursor := dbms_sys_sql.open_cursor;&lt;br /&gt;
    dbms_sys_sql.parse_as_user ( c             =&amp;gt; l_cursor&lt;br /&gt;
                               , statement     =&amp;gt; p_sql&lt;br /&gt;
                               , language_flag =&amp;gt; dbms_sql.native&lt;br /&gt;
                               , userid        =&amp;gt; l_user_id&lt;br /&gt;
    );&lt;br /&gt;
    l_rc := dbms_sys_sql.execute(l_cursor);&lt;br /&gt;
    dbms_sys_sql.close_cursor(l_cursor);&lt;br /&gt;
exception&lt;br /&gt;
when others then&lt;br /&gt;
    raise_application_error (-20001, &amp;#039;ERROR: &amp;#039;||sqlerrm);&lt;br /&gt;
end;&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Run a script on all databases listed in tnsnames.ora===&lt;br /&gt;
Can run an SQL command file on all SID/SERVICE found in a tnsnames.ora file. I use this from a client laptop having a global tns file on it.&amp;lt;br /&amp;gt;&lt;br /&gt;
This way it&amp;#039;s not necessary to copy the file onto every host before executing it. Any files created by the script will be created on the client.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/ksh&lt;br /&gt;
&lt;br /&gt;
TNSNAMES=&amp;quot;./tnsnames.ora&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[ ! -r &amp;quot;${TNSNAMES}&amp;quot; ]] &amp;amp;&amp;amp; echo &amp;quot;${TNSNAMES} is not accessible&amp;quot; &amp;amp;&amp;amp; exit 1&lt;br /&gt;
&lt;br /&gt;
SIDLIST=$(perl -ne &amp;#039;print &amp;quot;$1\n&amp;quot; if /(?:SID|SERVICE_NAME)\s*=\s*(\S+?)\)/&amp;#039; ${TNSNAMES}|sort|uniq|xargs)&lt;br /&gt;
for SID in ${SIDLIST}&lt;br /&gt;
do&lt;br /&gt;
    echo &amp;quot;Processing $SID&amp;quot;&lt;br /&gt;
    ls -al | grep &amp;quot;^d&amp;quot; | grep &amp;quot;\_${SID}&amp;quot; &amp;gt;/dev/null&lt;br /&gt;
    if [[ $? -ne 0 ]]; then&lt;br /&gt;
        echo &amp;#039;exit&amp;#039; | sqlplus system/password@${SID} @ReviewLite17.1.sql &amp;gt;/dev/null 2&amp;gt;&amp;amp;1&lt;br /&gt;
    else&lt;br /&gt;
        echo &amp;quot;directory already exists so must have done this SID&amp;quot;&lt;br /&gt;
    fi&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===List invalid objects===&lt;br /&gt;
 set lines 200&lt;br /&gt;
 set pages 200&lt;br /&gt;
 col obj format a40&lt;br /&gt;
 select owner||&amp;#039;.&amp;#039;||object_name obj&lt;br /&gt;
 ,      object_type&lt;br /&gt;
 from   dba_objects&lt;br /&gt;
 where  1=1&lt;br /&gt;
 and    status = &amp;#039;INVALID&amp;#039;;&lt;br /&gt;
===Recompile all invalid objects===&lt;br /&gt;
@?/rdbms/admin/utlrp.sql&lt;br /&gt;
===See how much space is left in the flash recovery area (FRA)===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select name&lt;br /&gt;
,      to_char (space_limit, &amp;#039;999,999,999,999&amp;#039;) as space_limit&lt;br /&gt;
,      to_char (space_limit - space_used + space_reclaimable&lt;br /&gt;
,               &amp;#039;999,999,999,999&amp;#039;)&lt;br /&gt;
           as space_available&lt;br /&gt;
,      round ( (space_used - space_reclaimable) / space_limit * 100, 1)&lt;br /&gt;
           as pct_full&lt;br /&gt;
from   v$recovery_file_dest;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# ==============================================&lt;br /&gt;
# Check FRA to see how much space is reclaimable&lt;br /&gt;
# ==============================================&lt;br /&gt;
fra_reclaim_check() {&lt;br /&gt;
&lt;br /&gt;
LOGFILE=${RMAN_LogDir}/${ORACLE_SID}_`date &amp;#039;+%Y%m&amp;#039;`_${V_SCRIPT}.log&lt;br /&gt;
sqlplus &amp;quot;/ as sysdba&amp;quot; &amp;lt;&amp;lt;EOSQL &amp;gt; /tmp/results.$$&lt;br /&gt;
set vefify off echo off heading off newpage none linesize 1000 echo off&lt;br /&gt;
select &amp;#039;Filesystem:&amp;#039;||name||&lt;br /&gt;
       &amp;#039;; Total(Gb):&amp;#039;||round((space_limit/1073741824),2) ||&lt;br /&gt;
       &amp;#039;; Reclaimable(Gb):&amp;#039;||round((space_reclaimable/1073741824),2) ||&lt;br /&gt;
       &amp;#039;; Reclaimable(%):&amp;#039;||round( ((space_reclaimable/1073741824)/(space_limit/1073741824)*100),2 )&lt;br /&gt;
from   v$recovery_file_dest&lt;br /&gt;
/&lt;br /&gt;
EOSQL&lt;br /&gt;
cat /tmp/results.$$ &amp;gt;&amp;gt; $LOGFILE&lt;br /&gt;
rm /tmp/results.$$&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===How far back can we flashback?===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
col time_now              for a25&lt;br /&gt;
col time_oldest_flashback for a25&lt;br /&gt;
select to_char(sysdate,&amp;#039;DD-MON-YY HH24:MI&amp;#039;)                    time_now&lt;br /&gt;
,      to_char(fdl.oldest_flashback_time, &amp;#039;DD-MON-YY HH24:MI&amp;#039;) time_oldest_flashback&lt;br /&gt;
,      round((sysdate-fdl.oldest_flashback_time)*24,1)         hours_flashback_possible&lt;br /&gt;
from   v$database d&lt;br /&gt;
,      v$flashback_database_log fdl&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===DBA privs tables===&lt;br /&gt;
 DBA_AQ_AGENT_PRIVS&lt;br /&gt;
 DBA_COL_PRIVS&lt;br /&gt;
 DBA_PRIV_AUDIT_OPTS&lt;br /&gt;
 DBA_REPGROUP_PRIVILEGES&lt;br /&gt;
 DBA_ROLE_PRIVS&lt;br /&gt;
 DBA_RSRC_CONSUMER_GROUP_PRIVS&lt;br /&gt;
 DBA_RSRC_MANAGER_SYSTEM_PRIVS&lt;br /&gt;
 DBA_SYS_PRIVS&lt;br /&gt;
 DBA_TAB_PRIVS&lt;br /&gt;
 DBA_WM_SYS_PRIVS&lt;br /&gt;
 DBA_WORKSPACE_PRIVS&lt;br /&gt;
&lt;br /&gt;
===Schedule a shell job===&lt;br /&gt;
 begin&lt;br /&gt;
     dbms_scheduler.create_program ( program_name   =&amp;gt; &amp;#039;myshelljob&amp;#039;&lt;br /&gt;
                                   , program_action =&amp;gt; &amp;#039;/home/oracle/scripts/shell.sh&amp;#039;&lt;br /&gt;
                                   , program_type   =&amp;gt; &amp;#039;EXECUTABLE&amp;#039;&lt;br /&gt;
                                   , comments       =&amp;gt; &amp;#039;Run a shell&amp;#039;&lt;br /&gt;
                                   , enabled        =&amp;gt; TRUE&lt;br /&gt;
                                   );&lt;br /&gt;
 end;&lt;br /&gt;
 /&lt;br /&gt;
===Start the job===&lt;br /&gt;
 begin&lt;br /&gt;
     dbms_sheduler.create_job ( job_name     =&amp;gt; &amp;#039;myshelljob&amp;#039;&lt;br /&gt;
                              , program_name =&amp;gt; &amp;#039;myshelljob&amp;#039;&lt;br /&gt;
                              , start_date   =&amp;gt;&lt;br /&gt;
                              );&lt;br /&gt;
 /&lt;br /&gt;
hello&lt;br /&gt;
&lt;br /&gt;
===What statement is a user running?===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select a.sid&lt;br /&gt;
,      a.serial#&lt;br /&gt;
,      b.sql_text&lt;br /&gt;
from   v$session a&lt;br /&gt;
,      v$sqlarea b&lt;br /&gt;
where  a.sql_address = b.address&lt;br /&gt;
and    a.username    = &amp;#039;&amp;amp;username&amp;#039;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===See what statements all users are running===&lt;br /&gt;
Useful to see what is happening when process limit is reached&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 300 pages 1000&lt;br /&gt;
&lt;br /&gt;
col username for a10&lt;br /&gt;
col command for 999 head &amp;quot;CMD&amp;quot;&lt;br /&gt;
col lockwait for a10&lt;br /&gt;
col status for a8&lt;br /&gt;
col schemaname for a12&lt;br /&gt;
col osuser for a10&lt;br /&gt;
col process for a10&lt;br /&gt;
col program for a20&lt;br /&gt;
col machine for a10&lt;br /&gt;
col action for a10&lt;br /&gt;
col module for a10&lt;br /&gt;
col identifier for a10&lt;br /&gt;
col event for a27&lt;br /&gt;
col state for a8&lt;br /&gt;
col service_name for a10&lt;br /&gt;
col serial# for 999999&lt;br /&gt;
&lt;br /&gt;
select a.username&lt;br /&gt;
,      a.command&lt;br /&gt;
,      a.lockwait&lt;br /&gt;
,      a.status&lt;br /&gt;
,      a.schemaname&lt;br /&gt;
,      a.osuser&lt;br /&gt;
,      a.process&lt;br /&gt;
,      a.machine&lt;br /&gt;
,      a.program&lt;br /&gt;
,      a.type&lt;br /&gt;
--,      a.sql_exec_start&lt;br /&gt;
--,      a.plsql_object_id&lt;br /&gt;
--,      a.plsql_subprogram_id&lt;br /&gt;
--,      a.module&lt;br /&gt;
--,      a.action&lt;br /&gt;
,      a.logon_time&lt;br /&gt;
,      a.event&lt;br /&gt;
,      a.wait_time&lt;br /&gt;
,      a.seconds_in_wait&lt;br /&gt;
,      a.state&lt;br /&gt;
--,      a.service_name&lt;br /&gt;
,      a.serial#&lt;br /&gt;
,      b.sql_text&lt;br /&gt;
from   v$session a&lt;br /&gt;
,      v$sqlarea b&lt;br /&gt;
where  a.sql_address = b.address&lt;br /&gt;
order  by a.logon_time desc&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
set lines 80&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===A logminer session===&lt;br /&gt;
Mine all SQL statements in a 10 minute period&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sqlplus / as sysdba&lt;br /&gt;
alter session set nls_date_format = &amp;#039;DD-MON-YYYY HH24:MI:SS&amp;#039;;&lt;br /&gt;
execute dbms_logmnr.start_logmnr ( starttime =&amp;gt; &amp;#039;27-OCT-2009 11:05:00&amp;#039;&lt;br /&gt;
                                 , endtime   =&amp;gt; &amp;#039;27-OCT-2009 11:15:00&amp;#039;&lt;br /&gt;
                                 , options   =&amp;gt; dbms_logmnr.dict_from_online_catalog+dbms_logmnr.continuous_mine&lt;br /&gt;
                                 );&lt;br /&gt;
create table mycontents as select * from v$logmnr_contents;&lt;br /&gt;
execute dbms_logmnr.end_logmnr(); &lt;br /&gt;
&lt;br /&gt;
select * from mycontents;&lt;br /&gt;
&lt;br /&gt;
drop table mycontents;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Huge Pages===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
#&lt;br /&gt;
# hugepages_settings.sh&lt;br /&gt;
#&lt;br /&gt;
# Linux bash script to compute values for the&lt;br /&gt;
# recommended HugePages/HugeTLB configuration&lt;br /&gt;
#&lt;br /&gt;
# Note: This script does calculation for all shared memory&lt;br /&gt;
# segments available when the script is run, no matter it&lt;br /&gt;
# is an Oracle RDBMS shared memory segment or not.&lt;br /&gt;
# Check for the kernel version&lt;br /&gt;
KERN=`uname -r | awk -F. &amp;#039;{ printf(&amp;quot;%d.%d\n&amp;quot;,$1,$2); }&amp;#039;`&lt;br /&gt;
# Find out the HugePage size&lt;br /&gt;
HPG_SZ=`grep Hugepagesize /proc/meminfo | awk {&amp;#039;print $2&amp;#039;}`&lt;br /&gt;
# Start from 1 pages to be on the safe side and guarantee 1 free HugePage&lt;br /&gt;
NUM_PG=1&lt;br /&gt;
# Cumulative number of pages required to handle the running shared memory segments&lt;br /&gt;
for SEG_BYTES in `ipcs -m | awk {&amp;#039;print $5&amp;#039;} | grep &amp;quot;[0-9][0-9]*&amp;quot;`&lt;br /&gt;
do&lt;br /&gt;
   MIN_PG=`echo &amp;quot;$SEG_BYTES/($HPG_SZ*1024)&amp;quot; | bc -q`&lt;br /&gt;
   if [ $MIN_PG -gt 0 ]; then&lt;br /&gt;
      NUM_PG=`echo &amp;quot;$NUM_PG+$MIN_PG+1&amp;quot; | bc -q`&lt;br /&gt;
   fi&lt;br /&gt;
done&lt;br /&gt;
# Finish with results&lt;br /&gt;
case $KERN in&lt;br /&gt;
   &amp;#039;2.4&amp;#039;) HUGETLB_POOL=`echo &amp;quot;$NUM_PG*$HPG_SZ/1024&amp;quot; | bc -q`;&lt;br /&gt;
          echo &amp;quot;Recommended setting: vm.hugetlb_pool = $HUGETLB_POOL&amp;quot; ;;&lt;br /&gt;
   &amp;#039;2.6&amp;#039; | &amp;#039;3.8&amp;#039;) echo &amp;quot;Recommended setting: vm.nr_hugepages = $NUM_PG&amp;quot; ;;&lt;br /&gt;
    *) echo &amp;quot;Unrecognized kernel version $KERN. Exiting.&amp;quot; ;;&lt;br /&gt;
esac&lt;br /&gt;
# End&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Pretty longops listing===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 2000 pages 1000&lt;br /&gt;
col opname for a34 head &amp;quot;Job&amp;quot;&lt;br /&gt;
col message for a60&lt;br /&gt;
col perc_done for a10 head &amp;quot;Done&amp;quot;&lt;br /&gt;
col started for a18&lt;br /&gt;
col killer for a15&lt;br /&gt;
col mins_busy head &amp;quot;Mins busy&amp;quot;&lt;br /&gt;
col mins_left head &amp;quot;Mins left&amp;quot;&lt;br /&gt;
select sid||&amp;#039;,&amp;#039;||serial#                       killer&lt;br /&gt;
,      opname&lt;br /&gt;
,      message&lt;br /&gt;
,      round ((sofar/totalwork),4)*100||&amp;#039;%&amp;#039;    perc_done&lt;br /&gt;
,      to_char(start_time,&amp;#039;DD-MON-YY HH24:MI&amp;#039;) started&lt;br /&gt;
,      floor(elapsed_seconds/60)               mins_busy&lt;br /&gt;
,      ceil(time_remaining/60)                 mins_left&lt;br /&gt;
from   v$session_longops&lt;br /&gt;
where  1=1&lt;br /&gt;
and    sofar     != totalwork&lt;br /&gt;
and    totalwork != 0&lt;br /&gt;
and    opname    like &amp;#039;RMAN%&amp;#039;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select * from v$session where module=&amp;#039;Data Pump Worker&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or attach to the impdp job and it shows percentage done.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Get the SID from v$session_longops and plug it into v$session to check the SQL command details.&lt;br /&gt;
&lt;br /&gt;
Current Running SQLs&lt;br /&gt;
--------------------&lt;br /&gt;
set pages 1000 lines 2000&lt;br /&gt;
col program  format a40&lt;br /&gt;
col sql_text format a130&lt;br /&gt;
&lt;br /&gt;
select s.sid&lt;br /&gt;
,      s.status&lt;br /&gt;
,      s.last_call_et&lt;br /&gt;
,      s.program&lt;br /&gt;
,      sa.sql_id&lt;br /&gt;
,      sa.sql_text&lt;br /&gt;
from   v$session s&lt;br /&gt;
,      v$sqlarea sa&lt;br /&gt;
where  s.sql_id = sa.sql_id&lt;br /&gt;
and    s.sid = &amp;#039;&amp;amp;sid&amp;#039;&lt;br /&gt;
/ &lt;br /&gt;
&lt;br /&gt;
set pages 1000 lines 2000&lt;br /&gt;
col USERNAME for a10&lt;br /&gt;
col OSUSER   for a10&lt;br /&gt;
col MACHINE  for a10&lt;br /&gt;
&lt;br /&gt;
select s.sid&lt;br /&gt;
,      s.serial#&lt;br /&gt;
,      p.spid&lt;br /&gt;
,      s.username&lt;br /&gt;
,      s.osuser&lt;br /&gt;
,      s.status&lt;br /&gt;
,      s.process fg_pid&lt;br /&gt;
,      s.longon_time&lt;br /&gt;
,      s.machine&lt;br /&gt;
,      p.spid bg_pid&lt;br /&gt;
from   gv$session s&lt;br /&gt;
,      gv$process p&lt;br /&gt;
where  s.addr = p.addr&lt;br /&gt;
and    s.sid  = &amp;#039;&amp;amp;sid&amp;#039;&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
$ps -ef | grep &amp;lt;spid&amp;gt;&lt;br /&gt;
&lt;br /&gt;
set pages 1000 lines 2000&lt;br /&gt;
SELECT INST_ID&lt;br /&gt;
,      SID&lt;br /&gt;
,      SERIAL#&lt;br /&gt;
,      SQL_ID&lt;br /&gt;
,      USERNAME&lt;br /&gt;
,      PROGRAM&lt;br /&gt;
,      MACHINE&lt;br /&gt;
,      SERVICE_NAME&lt;br /&gt;
FROM   GV$SESSION&lt;br /&gt;
WHERE  SID IN (&amp;#039;&amp;lt;SID_NO.1&amp;gt;&amp;#039;,&amp;#039;&amp;lt;SID_NO.2&amp;gt;&amp;#039;)&lt;br /&gt;
/&lt;br /&gt;
Active Running SQLs&lt;br /&gt;
--------------------&lt;br /&gt;
set pages 1000 lines 2000&lt;br /&gt;
col SPID     for a10&lt;br /&gt;
col PROGRAM  for a15&lt;br /&gt;
col OSUSER   for a10&lt;br /&gt;
col ACTION   for a10&lt;br /&gt;
col EVENT    for a25&lt;br /&gt;
col SQL_TEXT for a25&lt;br /&gt;
col MACHINE  for a10&lt;br /&gt;
col P1TEXT   for a10 &lt;br /&gt;
col P2TEXT   for a10&lt;br /&gt;
col P3TEXT   for a10  &lt;br /&gt;
SELECT b.sid&lt;br /&gt;
,      b.serial#&lt;br /&gt;
,      a.spid&lt;br /&gt;
,      b.sql_id&lt;br /&gt;
,      b.program&lt;br /&gt;
,      b.osuser&lt;br /&gt;
,      b.machine&lt;br /&gt;
,      b.type&lt;br /&gt;
,      b.event&lt;br /&gt;
,      b.action&lt;br /&gt;
,      b.p1text&lt;br /&gt;
,      b.p2text&lt;br /&gt;
,      b.p3text&lt;br /&gt;
,      b.state&lt;br /&gt;
,      c.sql_text&lt;br /&gt;
,      b.logon_time&lt;br /&gt;
FROM   v$process a&lt;br /&gt;
,      v$session b&lt;br /&gt;
,      v$sqltext c&lt;br /&gt;
WHERE  a.addr           = b.paddr&lt;br /&gt;
AND    b.sql_hash_value = c.hash_value&lt;br /&gt;
AND    b.STATUS         = &amp;#039;ACTIVE&amp;#039;&lt;br /&gt;
AND    b.sid            = &amp;#039;&amp;amp;sid&amp;#039;&lt;br /&gt;
ORDER  BY a.spid&lt;br /&gt;
,      c.piece&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
OR - Use the below Query &lt;br /&gt;
&lt;br /&gt;
Longops.sql&lt;br /&gt;
----------- &lt;br /&gt;
set pages 50000 lines 32767&lt;br /&gt;
col OPNAME for a10&lt;br /&gt;
col SID form 9999&lt;br /&gt;
col SERIAL form 9999999&lt;br /&gt;
col PROGRAM for a10&lt;br /&gt;
col USERNAME for a10&lt;br /&gt;
col SQL_TEXT for a40&lt;br /&gt;
col START_TIME for a10&lt;br /&gt;
col LAST_UPDATE_TIME for a10&lt;br /&gt;
col TARGET for a25&lt;br /&gt;
col MESSAGE for a25&lt;br /&gt;
&lt;br /&gt;
alter session set nls_date_format = &amp;#039;DD-MM-YYYY HH24:MI:SS&amp;#039;;&lt;br /&gt;
&lt;br /&gt;
SELECT l.inst_id,l.sid, l.serial#, l.sql_id, l.opname, l.username, l.target, l.sofar, l.totalwork, l.start_time,l.last_update_time,round(l.time_remaining/60,2) &amp;quot;REMAIN MINS&amp;quot;, round(l.elapsed_seconds/60,2) &amp;quot;ELAPSED MINS&amp;quot;, round((l.time_remaining+l.elapsed_seconds)/60,2) &amp;quot;TOTAL MINS&amp;quot;, ROUND(l.SOFAR/l.TOTALWORK*100,2) &amp;quot;%_COMPLETE&amp;quot;, l.message,s.sql_text &lt;br /&gt;
FROM gv$session_longops l &lt;br /&gt;
LEFT OUTER JOIN v$sql s on s.hash_value=l.sql_hash_value and s.address=l.sql_address and s.child_number=0&lt;br /&gt;
WHERE l.OPNAME NOT LIKE &amp;#039;RMAN%&amp;#039; AND l.OPNAME NOT LIKE &amp;#039;%aggregate%&amp;#039; AND l.TOTALWORK != 0 AND l.sofar&amp;lt;&amp;gt;l.totalwork AND l.time_remaining &amp;gt; 0&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Apply the database patch after the ORACLE_HOME has been patched===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ORAENV_ASK=NO&lt;br /&gt;
export ORACLE_SID=$1&lt;br /&gt;
. oraenv&lt;br /&gt;
&lt;br /&gt;
sqlplus /nolog &amp;lt;&amp;lt;EOSQL&lt;br /&gt;
connect / as sysdba&lt;br /&gt;
startup&lt;br /&gt;
@?/rdbms/admin/catbundle.sql psu apply&lt;br /&gt;
@?/rdbms/admin/utlrp.sql&lt;br /&gt;
purge dba_recyclebin;&lt;br /&gt;
&lt;br /&gt;
prompt check patch apply...&lt;br /&gt;
set lines 150&lt;br /&gt;
col action_time for a50&lt;br /&gt;
col comp_name for a50&lt;br /&gt;
col comments for a50&lt;br /&gt;
&lt;br /&gt;
select action_time,action,comments from sys.registry\$history where trunc(action_time) = trunc(sysdate);&lt;br /&gt;
select comp_name,version,status,modified from dba_registry;&lt;br /&gt;
exit&lt;br /&gt;
EOSQL&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Show how much archivelog data is generated per day===&lt;br /&gt;
A companion script for &amp;#039;how many log switches in a day&amp;#039;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
col orderby noprint&lt;br /&gt;
select trunc(first_time) orderby&lt;br /&gt;
,      to_char(first_time,&amp;#039;DD-MON-YYYY&amp;#039;) &amp;quot;Date&amp;quot;&lt;br /&gt;
,      round(sum(bytes/1024/1024/1024),2) arch_logs_gigs&lt;br /&gt;
from (&lt;br /&gt;
    select unique (blocks * block_size) bytes,&lt;br /&gt;
    thread#,&lt;br /&gt;
    sequence#,&lt;br /&gt;
    resetlogs_change#,&lt;br /&gt;
    first_time&lt;br /&gt;
    from v$archived_log&lt;br /&gt;
)&lt;br /&gt;
group by trunc(first_time)&lt;br /&gt;
,      to_char(first_time, &amp;#039;DD-MON-YYYY&amp;#039;)&lt;br /&gt;
order by trunc(first_time) desc&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Abort a hanging database even when sysdba cannot connect===&lt;br /&gt;
Unable to connect to database with sqlplus / as sysdba because audit file cannot be created?&lt;br /&gt;
* [http://tech.e2sn.com/oracle/troubleshooting/hang/how-to-log-on-even-when-sysdba-can-t-do-so tech.e2sn.com]&lt;br /&gt;
* [http://blog.dbi-services.com/oracle-is-hanging-dont-forget-hanganalyze-and-systemstate/ blog.dbi-services.com]&lt;br /&gt;
Instead of just killing the pmon process, there is a kinder (and more useful) way to kill the database.&amp;lt;br /&amp;gt;&lt;br /&gt;
Use the hidden, undocumented &amp;#039;prelim&amp;#039; switch parameter to sqlplus to make a connection to the database without creating SGA session data structures.&amp;lt;br /&amp;gt;&lt;br /&gt;
It can be very useful for hang analysis so the possible cause can be found after the database has been restarted.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sqlplus -prelim / as sysdba&lt;br /&gt;
oradebug unlimit&lt;br /&gt;
oradebug hanganalyze 3&lt;br /&gt;
oradebug setmypid              -- or oradebug setorapname diag&lt;br /&gt;
oradebug dump ashdumpseconds 30&lt;br /&gt;
oradebug dump systemstate 10   -- or oradebug dump systemstate 266&lt;br /&gt;
oradebug tracefile_name&lt;br /&gt;
shutdown abort&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Lists Oracle session with kill session statement all ready to go===&lt;br /&gt;
disconnect attempts to kill the o/s processes too. kill doesn&amp;#039;t.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
col killer for a60&lt;br /&gt;
col osuser for a12&lt;br /&gt;
col logon  for a23&lt;br /&gt;
col spid   for a8&lt;br /&gt;
col username for a15&lt;br /&gt;
col program for a50&lt;br /&gt;
set lines 2000&lt;br /&gt;
select &amp;#039;alter system disconnect session &amp;#039;&amp;#039;&amp;#039;||s.sid||&amp;#039;,&amp;#039;||s.serial#||&amp;#039;&amp;#039;&amp;#039; immediate;&amp;#039; killer&lt;br /&gt;
,      s.inst_id&lt;br /&gt;
,      to_char(s.logon_time,&amp;#039;DD-MON-YY HH24:MI:SS&amp;#039;) logon&lt;br /&gt;
,      sci.osuser&lt;br /&gt;
,      p.spid&lt;br /&gt;
,      s.username&lt;br /&gt;
,      s.program&lt;br /&gt;
from   gv$session s&lt;br /&gt;
,      gv$session_connect_info sci&lt;br /&gt;
,      gv$process p&lt;br /&gt;
where  1=1&lt;br /&gt;
and    p.addr     = s.paddr&lt;br /&gt;
and    p.inst_id  = s.inst_id&lt;br /&gt;
and    s.sid      = sci.sid&lt;br /&gt;
and    s.serial#  = sci.serial#&lt;br /&gt;
and    s.type    != &amp;#039;BACKGROUND&amp;#039;&lt;br /&gt;
and    sci.osuser = &amp;#039;oraibm&amp;#039;&lt;br /&gt;
order  by s.logon_time desc&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
KILLER                                                          INST_ID LOGON                   OSUSER       SPID     USERNAME        PROGRAM&lt;br /&gt;
------------------------------------------------------------ ---------- ----------------------- ------------ -------- --------------- --------------------------------------------------&lt;br /&gt;
alter system disconnect session &amp;#039;490,33947&amp;#039; immediate;                1 23-JUN-16 13:30:53      oraibm       23205    SYS             sqlplus@benouerp07 (TNS V1-V3)&lt;br /&gt;
alter system disconnect session &amp;#039;490,33947&amp;#039; immediate;                1 23-JUN-16 13:30:53      oraibm       23205    SYS             sqlplus@benouerp07 (TNS V1-V3)&lt;br /&gt;
alter system disconnect session &amp;#039;490,33947&amp;#039; immediate;                1 23-JUN-16 13:30:53      oraibm       23205    SYS             sqlplus@benouerp07 (TNS V1-V3)&lt;br /&gt;
alter system disconnect session &amp;#039;490,33947&amp;#039; immediate;                1 23-JUN-16 13:30:53      oraibm       23205    SYS             sqlplus@benouerp07 (TNS V1-V3)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===How much space is being used by a guaranteed restore point?===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
show parameter recovery&lt;br /&gt;
set numwi 15&lt;br /&gt;
set lines 200&lt;br /&gt;
col name for a40&lt;br /&gt;
col time for a23&lt;br /&gt;
col gigs_limit head &amp;quot;Max (but check df -g also!)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
select name&lt;br /&gt;
,      time&lt;br /&gt;
,      round(storage_size/1024/1024/1024,2) gigs_used&lt;br /&gt;
from   v$restore_point&lt;br /&gt;
where  1=1&lt;br /&gt;
and    guarantee_flashback_database = &amp;#039;YES&amp;#039;&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
select * from v$flash_recovery_area_usage&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
select name&lt;br /&gt;
,      round(space_used/1024/1024/1024,2) gigs_used&lt;br /&gt;
,      round(space_limit/1024/1024/1024,2) gigs_limit&lt;br /&gt;
,      space_reclaimable&lt;br /&gt;
,      number_of_files&lt;br /&gt;
from v$recovery_file_dest&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Get statistics for LOB columns in a table===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select &lt;br /&gt;
  max(dbms_lob.getlength(lob_content)) max_len&lt;br /&gt;
, avg(dbms_lob.getlength(lob_content)) avg_len&lt;br /&gt;
, min(dbms_lob.getlength(lob_content)) min_len&lt;br /&gt;
, sum(case when dbms_lob.getlength(lob_content) &amp;lt;= 4000 then 1&lt;br /&gt;
else 0 end) &amp;quot;&amp;lt;4k&amp;quot;&lt;br /&gt;
, sum(case when dbms_lob.getlength(lob_content) &amp;gt; 4000 then 1&lt;br /&gt;
else 0 end) &amp;quot;&amp;gt;4k&amp;quot;&lt;br /&gt;
, sum(case when dbms_lob.getlength(lob_content) is null then 1 else&lt;br /&gt;
0 end) &amp;quot;is null&amp;quot;&lt;br /&gt;
from &amp;amp;tablename&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===badprivs.sql===&lt;br /&gt;
Check to see if any ordinary users have privileges / access / grants / rights they should not have&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select grantee, privilege, admin_option&lt;br /&gt;
from   sys.dba_sys_privs&lt;br /&gt;
where  (       privilege like &amp;#039;% ANY %&amp;#039;&lt;br /&gt;
        or     privilege in (&amp;#039;BECOME USER&amp;#039;, &amp;#039;UNLIMITED TABLESPACE&amp;#039;)&lt;br /&gt;
        or     admin_option = &amp;#039;YES&amp;#039;&lt;br /&gt;
       )&lt;br /&gt;
and    grantee not in (&amp;#039;SYS&amp;#039;, &amp;#039;SYSTEM&amp;#039;, &amp;#039;OUTLN&amp;#039;, &amp;#039;AQ_ADMINISTRATOR_ROLE&amp;#039;,&lt;br /&gt;
                      &amp;#039;DBA&amp;#039;, &amp;#039;EXP_FULL_DATABASE&amp;#039;, &amp;#039;IMP_FULL_DATABASE&amp;#039;,&lt;br /&gt;
                      &amp;#039;OEM_MONITOR&amp;#039;, &amp;#039;CTXSYS&amp;#039;, &amp;#039;DBSNMP&amp;#039;, &amp;#039;IFSSYS&amp;#039;,&lt;br /&gt;
                      &amp;#039;IFSSYS$CM&amp;#039;, &amp;#039;MDSYS&amp;#039;, &amp;#039;ORDPLUGINS&amp;#039;, &amp;#039;ORDSYS&amp;#039;,&lt;br /&gt;
                      &amp;#039;TIMESERIES_DBA&amp;#039;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Generate a list of tablespaces ready for a migration===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set echo off&lt;br /&gt;
set lines 300&lt;br /&gt;
set pages 0&lt;br /&gt;
Set headi off&lt;br /&gt;
set feedb off&lt;br /&gt;
set long 32000&lt;br /&gt;
&lt;br /&gt;
spool migration_create_target_tablespaces.sql&lt;br /&gt;
&lt;br /&gt;
exec dbms_metadata.set_transform_param(dbms_metadata.session_transform,&amp;#039;SQLTERMINATOR&amp;#039;,TRUE);&lt;br /&gt;
select DBMS_METADATA.GET_DDL(&amp;#039;TABLESPACE&amp;#039;,tablespace_name) from dba_tablespaces&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
spool off&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===List the privileges assigned to users on directories===&lt;br /&gt;
table_name is the name of the directory...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select grantor&lt;br /&gt;
,      grantee&lt;br /&gt;
,      table_schema&lt;br /&gt;
,      table_name&lt;br /&gt;
,      privilege&lt;br /&gt;
from   all_tab_privs&lt;br /&gt;
where  table_name = &amp;#039;DATA_PUMP_DIR&amp;#039;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===List the privileges assigned to users on packages/procedures===&lt;br /&gt;
table_name is the name of the package...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select grantor&lt;br /&gt;
,      grantee&lt;br /&gt;
,      table_schema&lt;br /&gt;
,      table_name&lt;br /&gt;
,      privilege&lt;br /&gt;
from   all_tab_privs&lt;br /&gt;
where  upper(table_name) like upper(&amp;#039;%UTL_FILE%&amp;#039;)&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===List the system privileges assigned to a user (used to copy user as or clone user as)===&lt;br /&gt;
Maybe this one is better [[Extract ddl with &amp;quot;dbms metadata.get ddl&amp;quot;]]&lt;br /&gt;
&lt;br /&gt;
 SELECT LPAD(&amp;#039; &amp;#039;, 2*level) || granted_role &amp;quot;USER PRIVS&amp;quot;&lt;br /&gt;
 FROM (&lt;br /&gt;
   SELECT NULL grantee,  username granted_role&lt;br /&gt;
   FROM dba_users&lt;br /&gt;
   WHERE username LIKE UPPER(&amp;#039;%&amp;amp;uname%&amp;#039;)&lt;br /&gt;
   UNION&lt;br /&gt;
   SELECT grantee, granted_role&lt;br /&gt;
   FROM dba_role_privs&lt;br /&gt;
   UNION&lt;br /&gt;
   SELECT grantee, privilege&lt;br /&gt;
   FROM dba_sys_privs)&lt;br /&gt;
 START WITH grantee IS NULL&lt;br /&gt;
 CONNECT BY grantee = prior granted_role;&lt;br /&gt;
&lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
 SELECT path&lt;br /&gt;
 FROM (&lt;br /&gt;
   SELECT grantee,&lt;br /&gt;
          sys_connect_by_path(privilege, &amp;#039;:&amp;#039;)||&amp;#039;:&amp;#039;||grantee path&lt;br /&gt;
   FROM (&lt;br /&gt;
     SELECT grantee, privilege, 0 role&lt;br /&gt;
     FROM dba_sys_privs&lt;br /&gt;
     UNION ALL&lt;br /&gt;
     SELECT grantee, granted_role, 1 role&lt;br /&gt;
     FROM dba_role_privs)&lt;br /&gt;
   CONNECT BY privilege=prior grantee&lt;br /&gt;
   START WITH role = 0)&lt;br /&gt;
 WHERE grantee IN (&lt;br /&gt;
    SELECT username&lt;br /&gt;
    FROM dba_users&lt;br /&gt;
    WHERE lock_date IS NULL&lt;br /&gt;
    AND password != &amp;#039;EXTERNAL&amp;#039;&lt;br /&gt;
    AND username != &amp;#039;SYS&amp;#039;)&lt;br /&gt;
 OR grantee=&amp;#039;PUBLIC&amp;#039;&lt;br /&gt;
&lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
for a migration from 10g...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set headi off&lt;br /&gt;
set feedb off&lt;br /&gt;
set long  9999999&lt;br /&gt;
set pages 0&lt;br /&gt;
set lines 300&lt;br /&gt;
&lt;br /&gt;
spool migration_create_target_users_grants.sql&lt;br /&gt;
&lt;br /&gt;
select dbms_metadata.get_ddl(&amp;#039;USER&amp;#039;, username) || &amp;#039;;&amp;#039; ddl&lt;br /&gt;
from dba_users&lt;br /&gt;
where  1=1&lt;br /&gt;
and    username like upper(&amp;#039;%&amp;amp;&amp;amp;USER_NAME%&amp;#039;)&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
select &amp;#039;grant &amp;#039;||privilege|| &amp;#039; to &amp;#039; || grantee || &amp;#039;;&amp;#039;&lt;br /&gt;
from   dba_sys_privs&lt;br /&gt;
where  1=1&lt;br /&gt;
and    grantee like upper(&amp;#039;%&amp;amp;&amp;amp;USER_NAME%&amp;#039;)&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
select &amp;#039;grant &amp;#039;||granted_role|| &amp;#039; to &amp;#039; || grantee || &amp;#039;;&amp;#039;&lt;br /&gt;
from   dba_role_privs&lt;br /&gt;
where  1=1&lt;br /&gt;
and    grantee like upper(&amp;#039;%&amp;amp;&amp;amp;USER_NAME%&amp;#039;)&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
spool off&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or for a migration on 11g...!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set head off&lt;br /&gt;
set pages 0&lt;br /&gt;
set long 9999999&lt;br /&gt;
col ddl for a1000&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
SELECT DBMS_METADATA.GET_DDL(&amp;#039;USER&amp;#039;, USERNAME) || &amp;#039;;&amp;#039; DDL&lt;br /&gt;
FROM DBA_USERS&lt;br /&gt;
where  1=1&lt;br /&gt;
and    default_tablespace not in (&amp;#039;SYSTEM&amp;#039;,&amp;#039;SYSAUX&amp;#039;)&lt;br /&gt;
and    upper(username) like &amp;#039;%&amp;#039;||upper(&amp;#039;&amp;amp;&amp;amp;username&amp;#039;)||&amp;#039;%&amp;#039;&lt;br /&gt;
UNION ALL&lt;br /&gt;
SELECT DBMS_METADATA.GET_GRANTED_DDL(&amp;#039;ROLE_GRANT&amp;#039;, USERNAME) || &amp;#039;;&amp;#039; DDL&lt;br /&gt;
FROM DBA_USERS&lt;br /&gt;
where  1=1&lt;br /&gt;
and    default_tablespace not in (&amp;#039;SYSTEM&amp;#039;,&amp;#039;SYSAUX&amp;#039;)&lt;br /&gt;
and    upper(username) like &amp;#039;%&amp;#039;||upper(&amp;#039;&amp;amp;&amp;amp;username&amp;#039;)||&amp;#039;%&amp;#039;&lt;br /&gt;
UNION ALL&lt;br /&gt;
SELECT DBMS_METADATA.GET_GRANTED_DDL(&amp;#039;SYSTEM_GRANT&amp;#039;, USERNAME) || &amp;#039;;&amp;#039; DDL&lt;br /&gt;
FROM DBA_USERS&lt;br /&gt;
where  1=1&lt;br /&gt;
and    default_tablespace not in (&amp;#039;SYSTEM&amp;#039;,&amp;#039;SYSAUX&amp;#039;)&lt;br /&gt;
and    upper(username) like &amp;#039;%&amp;#039;||upper(&amp;#039;&amp;amp;&amp;amp;username&amp;#039;)||&amp;#039;%&amp;#039;&lt;br /&gt;
UNION ALL&lt;br /&gt;
SELECT DBMS_METADATA.GET_GRANTED_DDL(&amp;#039;OBJECT_GRANT&amp;#039;, USERNAME) || &amp;#039;;&amp;#039; DDL&lt;br /&gt;
FROM DBA_USERS&lt;br /&gt;
where  1=1&lt;br /&gt;
and    default_tablespace not in (&amp;#039;SYSTEM&amp;#039;,&amp;#039;SYSAUX&amp;#039;)&lt;br /&gt;
and    upper(username) like &amp;#039;%&amp;#039;||upper(&amp;#039;&amp;amp;&amp;amp;username&amp;#039;)||&amp;#039;%&amp;#039;&lt;br /&gt;
&lt;br /&gt;
spool migration_create_users_grants.sql&lt;br /&gt;
/&lt;br /&gt;
spool off&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Move datafiles between filesystems===&lt;br /&gt;
* [https://blogs.oracle.com/alejandrovargas/moving-a-datafile-from-file-system-to-asm Moving a datafile from File System to ASM (does not have to be ASM!) - oracle.com]&lt;br /&gt;
* [https://docs.oracle.com/database/121/OSTMG/GUID-3B8D0956-0888-452D-A9E4-9FB8D98577E0.htm#OSTMG89997 Moving Data Files Between Oracle ASM (does not have to be ASM!) Using RMAN - oracle.com]&lt;br /&gt;
* [https://oracle-base.com/articles/misc/renaming-or-moving-oracle-files Moving a data file online between filesystems - oracle-base.com]&lt;br /&gt;
====Set the relevant datafile offline====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter database datafile 125 offline;&lt;br /&gt;
alter database datafile 126 offline;&lt;br /&gt;
alter database datafile 127 offline;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Rename the files on the filesystem using o/s commands====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter tablespace ts_thaler_data_offline;&lt;br /&gt;
&lt;br /&gt;
host mv &amp;#039;/cln/tst/ora_data1/clnt/data4/ts_thaler_data_113.dbf&amp;#039; &amp;#039;/cln/tst/ora_data1/clnt/data1/ts_thaler_data_113.dbf&amp;#039;&lt;br /&gt;
host mv &amp;#039;/cln/tst/ora_data1/clnt/data4/ts_thaler_data_114.dbf&amp;#039; &amp;#039;/cln/tst/ora_data1/clnt/data1/ts_thaler_data_114.dbf&amp;#039;&lt;br /&gt;
host mv &amp;#039;/cln/tst/ora_data1/clnt/data4/ts_thaler_data_115.dbf&amp;#039; &amp;#039;/cln/tst/ora_data1/clnt/data1/ts_thaler_data_115.dbf&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Run the relevant alter commands to inform the control files of the new locations====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter database move datafile &amp;#039;/cln/tst/ora_data1/clnt/data4/ts_thaler_data_113.dbf&amp;#039; to &amp;#039;/cln/tst/ora_data1/clnt/data1/ts_thaler_data_113.dbf&amp;#039;&lt;br /&gt;
alter database move datafile &amp;#039;/cln/tst/ora_data1/clnt/data4/ts_thaler_data_114.dbf&amp;#039; to &amp;#039;/cln/tst/ora_data1/clnt/data1/ts_thaler_data_114.dbf&amp;#039;&lt;br /&gt;
alter database move datafile &amp;#039;/cln/tst/ora_data1/clnt/data4/ts_thaler_data_115.dbf&amp;#039; to &amp;#039;/cln/tst/ora_data1/clnt/data1/ts_thaler_data_115.dbf&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Recover the datafiles====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
recover datafile 125;&lt;br /&gt;
recover datafile 126;&lt;br /&gt;
recover datafile 127;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Set the relevant datafile online====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter database datafile 125 online;&lt;br /&gt;
alter database datafile 126 online;&lt;br /&gt;
alter database datafile 127 online;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Check all is well with the datafiles by using an appropriate statement====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 2000 pages 100&lt;br /&gt;
select file_id, file_name, status, online_status from dba_data_files where tablespace_name = &amp;#039;TS_THALER_DATA&amp;#039; order by 2;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Rename a datafile on 12c====&lt;br /&gt;
If you&amp;#039;re lucky enough to be on 12c, it&amp;#039;s one command - no need to offline the datafile!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SQL&amp;gt; alter database move datafile &amp;#039;/oracle/ora_data2/prod/data4/ts_thaler_data_113.dbf&amp;#039; to &amp;#039;/oracle/ora_data2/prod/data3/ts_thaler_data_113.dbf&amp;#039;;&lt;br /&gt;
&lt;br /&gt;
Database altered.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Pass parameter/argument into perl one-liner script from shell===&lt;br /&gt;
Trick? Just use ARGV to pass them in...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
FREQ=$(perl -e &amp;#039;my @CAL=split(&amp;quot;;&amp;quot;,$ARGV[0]);shift @CAL;print $CAL[$ARGV[1]];&amp;#039; -- &amp;quot;$LINE&amp;quot; $offset)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
DUMP_DATE=`perl -MTime::Local -e &amp;#039;print(timelocal(0,$ARGV[0],$ARGV[1],$ARGV[2],$ARGV[3],$ARGV[4]))&amp;#039; -- $MI $HH $DD $MM $YYYY`&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or export the variable from shell and access it via the ENV hash&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
export db=ENDP1&lt;br /&gt;
perl -p -i -e &amp;#039;s!DSMI_LOG.+$!DSMI_LOG           /oracle/$ENV{db}/admin/tdpoerror_$ENV{db}!&amp;#039; ${db}/admin/tdpo.opt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Return epoch seconds in Perl===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
perl -e &amp;#039;print time();&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or to convert a specific day of the year to epoch seconds&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
use POSIX;&lt;br /&gt;
my $epochsecs = mktime(0,0,0, $jday, 0, $year-1900);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or for a specific date (careful though - month is 0-11 not 1-12!...&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
use Time::Local;&lt;br /&gt;
#                          SS MM HH DD MM YYYY&lt;br /&gt;
my $epochsecs = timelocal (30,10,19,03,04,2014);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or more long-winded but delimited by anything...&amp;lt;br /&amp;gt;&lt;br /&gt;
Supply the date/time in any delimited format. Eg. YYYY-MM-DD:HH:MI&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/usr/bin/perl -w&lt;br /&gt;
use Time::Local;&lt;br /&gt;
&lt;br /&gt;
sub date2epoch { &lt;br /&gt;
  my($s) = @_;&lt;br /&gt;
  my($year, $month, $day, $hour, $minute, $second);&lt;br /&gt;
&lt;br /&gt;
  if($s =~ m{^\s*(\d{1,4})\W*0*(\d{1,2})\W*0*(\d{1,2})\W*0*&lt;br /&gt;
                 (\d{0,2})\W*0*(\d{0,2})\W*0*(\d{0,2})}x) {&lt;br /&gt;
    $year = $1;  $month = $2;   $day = $3;&lt;br /&gt;
    $hour = $4;  $minute = $5;  $second = $6;&lt;br /&gt;
    $hour |= 0;  $minute |= 0;  $second |= 0;  # defaults.&lt;br /&gt;
    $year = ($year&amp;lt;100 ? ($year&amp;lt;70 ? 2000+$year : 1900+$year) : $year);&lt;br /&gt;
    return timelocal($second,$minute,$hour,$day,$month-1,$year);  &lt;br /&gt;
  }&lt;br /&gt;
  return -1;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Return epoch seconds in DOS/VBS/Windows===&lt;br /&gt;
Paste this code into epoch.vbs&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
function date2epoch(p_date)&lt;br /&gt;
    date2epoch = DateDiff(&amp;quot;s&amp;quot;, &amp;quot;01/01/1970 00:00:00&amp;quot;, p_date)&lt;br /&gt;
end function&lt;br /&gt;
&lt;br /&gt;
Wscript.Echo date2epoch(Now())&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
and call from a DOS box like this&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cscript //nologo epoch.vbs&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Return date from epoch seconds in Perl===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
perl -e &amp;#039;print scalar (localtime (1243269270))&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Return epoch seconds from julian day number in Perl===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
use POSIX;&lt;br /&gt;
my ($year, $jday) = (2012,60);&lt;br /&gt;
my $epochsecs = mktime(0,0,0, $jday, 0, $year-1900);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Extract specific pieces of a date from an epoch timestamp in Perl===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
use POSIX;&lt;br /&gt;
# return localtime into an array&lt;br /&gt;
my @tm = localtime $epochsecs;&lt;br /&gt;
&lt;br /&gt;
my $yyyymmdd = strftime &amp;quot;%Y%m%d&amp;quot;, @tm;&lt;br /&gt;
print $yyyymmdd.&amp;quot;\n&amp;quot;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Return epoch seconds in Shell (linux)===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
date -d &amp;quot;2014/04/03 18:34:30&amp;quot; &amp;quot;+%s&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Return date from epoch seconds in Shell (linux)===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
date -d @1396542870&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Return epoch seconds in PL/SQL===&lt;br /&gt;
You cannot just use sysdate as that is timezone sensitive... (epoch seconds are in UTC/GMT)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select round((cast(sys_extract_utc(systimestamp) as date) - to_date(&amp;#039;01-JAN-1970 00:00:00&amp;#039;,&amp;#039;DD-MON-YYYY HH24:MI:SS&amp;#039;))*24*60*60) from dual;&lt;br /&gt;
or&lt;br /&gt;
select round((vd.created - to_date(&amp;#039;01-JAN-1970 00:00:00&amp;#039;,&amp;#039;DD-MON-YYYY HH24:MI:SS&amp;#039;))*24*60*60)  created from v$database vd;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
How long has this instance been up (in minutes)?&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select round((cast(sys_extract_utc(systimestamp) as date) - startup_time)*24*60) up_mins from v$instance;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Return date from epoch seconds in SQL===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select to_char(to_date(&amp;#039;19700101&amp;#039;,&amp;#039;YYYYMMDD&amp;#039;) + ((&amp;amp;epoch)/24/60/60),&amp;#039;DD-MON-YYYY HH24:MI:SS&amp;#039;) utc_date from dual;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===A database overview using the sys.plato package===&lt;br /&gt;
 exec plato.help;&lt;br /&gt;
or&lt;br /&gt;
 exec plato.complete(&amp;#039;HTM&amp;#039;);&lt;br /&gt;
&lt;br /&gt;
===List datafiles for a tablespace===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select *&lt;br /&gt;
from   dba_data_files&lt;br /&gt;
where  1=1&lt;br /&gt;
and    tablespace_name =&amp;#039;&amp;amp;ts_name&amp;#039;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Show graph of available and free space in tablespaces===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
-- =============================================================================&lt;br /&gt;
-- File Name    : http://www.oracle-base.com/dba/monitoring/ts_free_space.sql&lt;br /&gt;
-- Author       : Tim Hall&lt;br /&gt;
-- Description  : Displays a list of tablespaces and their used/full status.&lt;br /&gt;
-- Requirements : Access to the DBA views.&lt;br /&gt;
-- Call Syntax  : @ts_free_space.sql&lt;br /&gt;
-- Last Modified: 13-OCT-2012 - Created. Based on ts_full.sql&lt;br /&gt;
--&lt;br /&gt;
-- Modification History&lt;br /&gt;
-- ====================&lt;br /&gt;
-- When      Who               What&lt;br /&gt;
-- ========= ================= =================================================&lt;br /&gt;
-- 13-NOV-13 Stuart Barkley    Added cols free_pct and used_pct&lt;br /&gt;
-- =============================================================================&lt;br /&gt;
SET PAGESIZE 140 lines 180&lt;br /&gt;
COLUMN used_pct FORMAT A11&lt;br /&gt;
COLUMN max_used_pct FORMAT A11&lt;br /&gt;
&lt;br /&gt;
    SELECT tablespace_name                                                                      tablespace_name&lt;br /&gt;
    ,      size_mb                                                                              size_mb&lt;br /&gt;
    ,      free_mb                                                                              free_mb&lt;br /&gt;
    ,      TRUNC((free_mb/size_mb) * 100)                                                       free_pct&lt;br /&gt;
    ,      RPAD(&amp;#039; &amp;#039;|| RPAD(&amp;#039;X&amp;#039;,ROUND((size_mb-free_mb)/size_mb*10,0), &amp;#039;X&amp;#039;),11,&amp;#039;-&amp;#039;)              used_pct&lt;br /&gt;
    ,      max_size_mb                                                                          max_size_mb&lt;br /&gt;
    ,      max_free_mb                                                                          max_free_mb&lt;br /&gt;
    ,      TRUNC((max_free_mb/max_size_mb) * 100)                                               max_free_pct&lt;br /&gt;
    ,      RPAD(&amp;#039; &amp;#039;|| RPAD(&amp;#039;X&amp;#039;,ROUND((max_size_mb-max_free_mb)/max_size_mb*10,0), &amp;#039;X&amp;#039;),11,&amp;#039;-&amp;#039;)  max_used_pct&lt;br /&gt;
    from   (&lt;br /&gt;
           select a.tablespace_name                                         tablespace_name&lt;br /&gt;
           ,      b.size_mb                                                 size_mb&lt;br /&gt;
           ,      a.free_mb                                                 free_mb&lt;br /&gt;
           ,      b.max_size_mb                                             max_size_mb&lt;br /&gt;
           ,      a.free_mb + (b.max_size_mb - b.size_mb)                   max_free_mb&lt;br /&gt;
           from   (&lt;br /&gt;
                  select tablespace_name                                    tablespace_name&lt;br /&gt;
                  ,      trunc(sum(bytes)/1024/1024)                        free_mb&lt;br /&gt;
                  from   dba_free_space&lt;br /&gt;
                  group  by tablespace_name&lt;br /&gt;
                  ) a&lt;br /&gt;
           ,      (&lt;br /&gt;
                  select tablespace_name                                    tablespace_name&lt;br /&gt;
                  ,        trunc(sum(bytes)/1024/1024)                      size_mb&lt;br /&gt;
                  ,        trunc(sum(greatest(bytes,maxbytes))/1024/1024)   max_size_mb&lt;br /&gt;
                  from   dba_data_files&lt;br /&gt;
                  group by tablespace_name&lt;br /&gt;
                  ) b&lt;br /&gt;
           ,      v$instance vi&lt;br /&gt;
           where  a.tablespace_name = b.tablespace_name&lt;br /&gt;
           )&lt;br /&gt;
    order  by tablespace_name;&lt;br /&gt;
&lt;br /&gt;
set lines 80&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Another method for calculating free space in tablespace  using segments===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select df.tablespace_name &amp;quot;Tablespace&amp;quot;&lt;br /&gt;
,      totalusedspace &amp;quot;Used MB&amp;quot;&lt;br /&gt;
,      (df.totalspace - tu.totalusedspace) &amp;quot;Free MB&amp;quot;&lt;br /&gt;
,      df.totalspace &amp;quot;Total MB&amp;quot;&lt;br /&gt;
,      round(100 * ( (df.totalspace - tu.totalusedspace)/ df.totalspace)) &amp;quot;Pct. Free&amp;quot;&lt;br /&gt;
from   (&lt;br /&gt;
       select tablespace_name&lt;br /&gt;
,      round(sum(bytes) / 1048576) totalspace&lt;br /&gt;
       from   dba_data_files&lt;br /&gt;
       group  by tablespace_name&lt;br /&gt;
       ) df&lt;br /&gt;
,      (&lt;br /&gt;
       select round(sum(bytes)/(1024*1024)) totalusedspace&lt;br /&gt;
       ,      tablespace_name&lt;br /&gt;
       from   dba_segments&lt;br /&gt;
       group  by tablespace_name&lt;br /&gt;
       ) tu&lt;br /&gt;
where  df.tablespace_name = tu.tablespace_name;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Work out maximum possible size of a datafile===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select round( (4*1024*1024*value) / (1024*1024*1024) ,2) maxfilesizeingigabytes from v$parameter where name=&amp;#039;db_block_size&amp;#039;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or, as tablespaces can have block sizes differing from that of the init.ora parameter...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select round( (4*1024*1024*block_size) / (1024*1024*1024) ,2) maxfilesizeingigabytes from dba_tablespaces where tablespace_name=&amp;#039;&amp;amp;tablespace_name&amp;#039;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Show size and maxsize at datafile level===&lt;br /&gt;
datafiles&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set pages 100 lines 200&lt;br /&gt;
col file_name for a60&lt;br /&gt;
select sum(bytes)/1024/1024      mbytes_alloc&lt;br /&gt;
,      sum(maxbytes)/1024/1024   mbytes_max&lt;br /&gt;
,      file_name&lt;br /&gt;
from   sys.dba_data_files&lt;br /&gt;
group  by file_name&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
tempfiles&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set pages 100 lines 200&lt;br /&gt;
col file_name for a60&lt;br /&gt;
select sum(bytes)/1024/1024      mbytes_alloc&lt;br /&gt;
,      sum(maxbytes)/1024/1024   mbytes_max&lt;br /&gt;
,      file_name&lt;br /&gt;
from   sys.dba_temp_files&lt;br /&gt;
group  by file_name&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Resize the online redo logfiles===&lt;br /&gt;
Found a more concise, smarter way of doing it [http://www.oracle-wiki.net/startdocshowtorecreateredogrps here] - oracle-wiki.net&amp;lt;br /&amp;gt;&lt;br /&gt;
Switching logs too often? Redolog files too small?&amp;lt;br /&amp;gt;&lt;br /&gt;
* Show current log groups&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 1000&lt;br /&gt;
col group_member for a60&lt;br /&gt;
select l.group#          group_number&lt;br /&gt;
,      (bytes/1024/1024) megs&lt;br /&gt;
,      l.status          group_status&lt;br /&gt;
,      f.member          group_member&lt;br /&gt;
,      l.archived        archived&lt;br /&gt;
,      f.type            file_type&lt;br /&gt;
from   v$log     l&lt;br /&gt;
,      v$logfile f&lt;br /&gt;
where  l.group# = f.group#&lt;br /&gt;
order  by l.group#&lt;br /&gt;
,      f.member&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Create additional (bigger) groups&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
define SID=TIBQFW&lt;br /&gt;
alter database add logfile group 6  &amp;#039;/oracle/&amp;amp;SID/oradata1/redo1.log&amp;#039; size 1G;&lt;br /&gt;
alter database add logfile group 7  &amp;#039;/oracle/&amp;amp;SID/oradata2/redo2.log&amp;#039; size 1G;&lt;br /&gt;
alter database add logfile group 8  &amp;#039;/oracle/&amp;amp;SID/oradata3/redo3.log&amp;#039; size 1G;&lt;br /&gt;
alter database add logfile group 9  &amp;#039;/oracle/&amp;amp;SID/oradata1/redo4.log&amp;#039; size 1G;&lt;br /&gt;
alter database add logfile group 10 &amp;#039;/oracle/&amp;amp;SID/oradata2/redo5.log&amp;#039; size 1G;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or if you use multiple members...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter database add logfile group 6 (&amp;#039;/oracle/&amp;amp;SID/oradata1/redo/redo01a.log&amp;#039;, &amp;#039;/oracle/&amp;amp;SID/oradata1/redo01b&amp;#039;) size 50M;&lt;br /&gt;
alter database add logfile group 7 (&amp;#039;/oracle/&amp;amp;SID/oradata1/redo/redo02a.log&amp;#039;, &amp;#039;/oracle/&amp;amp;SID/oradata1/redo02b&amp;#039;) size 50M;&lt;br /&gt;
alter database add logfile group 8 (&amp;#039;/oracle/&amp;amp;SID/oradata1/redo/redo03a.log&amp;#039;, &amp;#039;/oracle/&amp;amp;SID/oradata1/redo03b&amp;#039;) size 50M;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Switch archivelogs until the new ones are current and the old ones are inactive&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter system switch logfile;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
If the old logs are not yet inactive, checkpoint the database&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter system checkpoint;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Drop the old groups&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter database drop logfile group 1;&lt;br /&gt;
alter database drop logfile group 2;&lt;br /&gt;
alter database drop logfile group 3;&lt;br /&gt;
alter database drop logfile group 4;&lt;br /&gt;
alter database drop logfile group 5;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Increase the existing size of a datafile===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter database datafile &amp;#039;&amp;amp;full_path_of_datafile&amp;#039; resize &amp;amp;new_meg_size.M;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Increase the max size of a tempfile===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter database tempfile &amp;#039;/oracle/ENDP1/oradata90/temp01.dbf&amp;#039; autoextend on maxsize unlimited;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Find out what processes are using the temp tablespace===&lt;br /&gt;
Temporary tablespace is used for sorting query results. Find them with this.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SELECT b.tablespace,b.segfile#,b.segblk#,b.blocks,a.sid,a.serial#,&lt;br /&gt;
a.username,a.osuser, a.status&lt;br /&gt;
FROM v$session a,v$sort_usage b&lt;br /&gt;
WHERE a.saddr = b.session_addr;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Increase the maximum size of a datafile===&lt;br /&gt;
Although this can be set lower than existing size, try not to. It makes the reports look weird!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter database&lt;br /&gt;
      datafile &amp;#039;&amp;amp;full_path_of_datafile&amp;#039;&lt;br /&gt;
      autoextend on&lt;br /&gt;
      maxsize &amp;amp;new_meg_size.m;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Find schemas (users) with objects created outside their default tablespace===&lt;br /&gt;
Indexes could be a notable exception if they are created in an index tablespace&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 200&lt;br /&gt;
col owner           for a20&lt;br /&gt;
col segment_name    for a45&lt;br /&gt;
col tablespace_name for a32&lt;br /&gt;
select owner&lt;br /&gt;
,      segment_name&lt;br /&gt;
,      tablespace_name&lt;br /&gt;
from   dba_segments&lt;br /&gt;
where  exists (select username from dba_users where username = owner)&lt;br /&gt;
and    tablespace_name != (select default_tablespace from dba_users where username = owner)&lt;br /&gt;
and    owner = &amp;#039;&amp;amp;owner&amp;#039;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Add a datafile to a tablespace===&lt;br /&gt;
&amp;#039;unlimited&amp;#039; will default to the maximum datafile size for the current db_block_size&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter tablepace &amp;amp;tablespace_name&lt;br /&gt;
      add datafile &amp;#039;&amp;amp;full_path_of_datafile&amp;#039;&lt;br /&gt;
      size 100M&lt;br /&gt;
      autoextend on&lt;br /&gt;
      next 100M&lt;br /&gt;
      maxsize unlimited&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===List all datafiles with their size===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set pages 1000 lines 2000&lt;br /&gt;
col filetype for a15&lt;br /&gt;
col name for a60&lt;br /&gt;
break on report&lt;br /&gt;
compute sum of gig on report&lt;br /&gt;
&lt;br /&gt;
select filetype&lt;br /&gt;
,      name&lt;br /&gt;
,      gig&lt;br /&gt;
from   (&lt;br /&gt;
       select &amp;#039;datafile&amp;#039; filetype&lt;br /&gt;
       ,      name&lt;br /&gt;
       ,      bytes/1024/1024 gig&lt;br /&gt;
       from   v$datafile&lt;br /&gt;
       union all&lt;br /&gt;
       select &amp;#039;tempfile&amp;#039; filetype&lt;br /&gt;
       ,      name&lt;br /&gt;
       ,      bytes/1024/1024&lt;br /&gt;
       from   v$tempfile&lt;br /&gt;
       union all&lt;br /&gt;
       select &amp;#039;logfile&amp;#039; filetype&lt;br /&gt;
       ,      lf.member &amp;quot;name&amp;quot;&lt;br /&gt;
       ,      l.bytes/1024/1024&lt;br /&gt;
       from   v$logfile lf&lt;br /&gt;
       ,      v$log     l&lt;br /&gt;
       where  1=1&lt;br /&gt;
       and    lf.group# = l.group#&lt;br /&gt;
       ) used&lt;br /&gt;
,      (&lt;br /&gt;
       select sum(bytes)/1024/1024&lt;br /&gt;
       from   dba_free_space&lt;br /&gt;
       ) free&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Database size (How big is my database?)===&lt;br /&gt;
There are different interpretations of what constitutes the size of a database...&amp;lt;br /&amp;gt;&lt;br /&gt;
Is it the space allocated to the datafiles or only the space taken up by the data? Are tempfiles included? Are redo logs included? etc...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 132&lt;br /&gt;
col dbname for a9  heading &amp;quot;Database&amp;quot;&lt;br /&gt;
col dbsize for a15 heading &amp;quot;Size&amp;quot;&lt;br /&gt;
col dbused for a15 heading &amp;quot;Used space&amp;quot;&lt;br /&gt;
col dbfree for a15 heading &amp;quot;Free space&amp;quot;&lt;br /&gt;
with used_space as&lt;br /&gt;
(&lt;br /&gt;
select  bytes&lt;br /&gt;
from    v$datafile&lt;br /&gt;
union   all&lt;br /&gt;
select  bytes&lt;br /&gt;
from    v$tempfile&lt;br /&gt;
union   all&lt;br /&gt;
select  bytes&lt;br /&gt;
from    v$log&lt;br /&gt;
)&lt;br /&gt;
, free_space as&lt;br /&gt;
(&lt;br /&gt;
select sum(bytes) sum_bytes&lt;br /&gt;
from dba_free_space&lt;br /&gt;
)&lt;br /&gt;
select vd.name                                                                                            dbname&lt;br /&gt;
,      round(sum(used_space.bytes)/1024/1024/1024 ) || &amp;#039; GB&amp;#039;                                              dbsize&lt;br /&gt;
,      round(sum(used_space.bytes)/1024/1024/1024 ) - round(free_space.sum_bytes/1024/1024/1024) || &amp;#039; GB&amp;#039; dbused&lt;br /&gt;
,      round(free_space.sum_bytes/1024/1024/1024) || &amp;#039; GB&amp;#039;                                                dbfree&lt;br /&gt;
from   free_space&lt;br /&gt;
,      used_space&lt;br /&gt;
,      v$database vd&lt;br /&gt;
group  by vd.name&lt;br /&gt;
,      free_space.sum_bytes&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Drop datafile from temp tablespace===&lt;br /&gt;
Database is completely stuck because the temporary tablespace has grown to fill all available room.&amp;lt;br /&amp;gt;&lt;br /&gt;
Look around for at least some log files to delete in order to get connected (audit files, sqlnet logs, listener logs)&amp;lt;br /&amp;gt;&lt;br /&gt;
Once connected, change the default temporary tablespace to a small one so we can remove the original.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
create temporary tablespace temp2 tempfile &amp;#039;/oracle/RMANV12/oradata2/temp2.dbf&amp;#039; size 5M;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter database default temporary tablespace temp2;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
I found trying to drop the datafile like this didn&amp;#039;t work, just hung there (probably active tranactions)...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
drop tablespace temp including contents and datafiles;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
So did it like this...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter database tempfile &amp;#039;/oracle/RMANV12/oradata2/temp.dbf&amp;#039; drop including datafiles;&lt;br /&gt;
&lt;br /&gt;
Database altered.&lt;br /&gt;
&lt;br /&gt;
drop tablespace temp including contents and datafiles;&lt;br /&gt;
&lt;br /&gt;
Tablespace dropped.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
... an alternative would be to find the sessions using the temp space and kill them...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select sid, serial#, status from v$session where serial# in (select session_num from v$sort_usage);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Then to be neat and tidy, rename the temp2 tablespace back to temp.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
create temporary tablespace temp tempfile &amp;#039;/oracle/RMANV12/oradata2/temp.dbf&amp;#039; size 256M reuse autoextend on next 128M maxsize 1G;&lt;br /&gt;
alter database default temporary tablespace temp;&lt;br /&gt;
drop tablespace temp2 including contents and datafiles;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Although the last statement will not work until any transactions using it have been rolled back or committed.&lt;br /&gt;
&lt;br /&gt;
===List files that are in hot-backup mode===&lt;br /&gt;
 set lines 100&lt;br /&gt;
 set pages 100&lt;br /&gt;
 col name format a60&lt;br /&gt;
 &lt;br /&gt;
 select df.name&lt;br /&gt;
 ,      b.status&lt;br /&gt;
 ,      to_char(time, &amp;#039;hh24:mi:ss dd/mm/yyyy&amp;#039;) time&lt;br /&gt;
 from   v$datafile   df&lt;br /&gt;
 ,      v$backup     b&lt;br /&gt;
 where  1=1&lt;br /&gt;
 and    df.file# = b.file#&lt;br /&gt;
 and    b.status = &amp;#039;ACTIVE&amp;#039;&lt;br /&gt;
 order  by b.file#;&lt;br /&gt;
&lt;br /&gt;
===Waiting for snapshot control file enqueue===&lt;br /&gt;
Script to identify sessions causing RMAN to hang because of &amp;#039;waiting for snapshot control file enqueue&amp;#039; message&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 2000&lt;br /&gt;
col killer     for a70&lt;br /&gt;
col program    for a20&lt;br /&gt;
col module     for a20&lt;br /&gt;
col action     for a20&lt;br /&gt;
col logon_time for a20&lt;br /&gt;
&lt;br /&gt;
select &amp;#039;alter system disconnect session &amp;#039;&amp;#039;&amp;#039;||s.sid||&amp;#039;,&amp;#039;||s.serial#||&amp;#039;&amp;#039;&amp;#039; immediate;&amp;#039; killer&lt;br /&gt;
,      username&lt;br /&gt;
,      program&lt;br /&gt;
,      module&lt;br /&gt;
,      action&lt;br /&gt;
,      logon_time&lt;br /&gt;
from   v$session s&lt;br /&gt;
,      v$enqueue_lock l&lt;br /&gt;
where  l.sid  = s.sid&lt;br /&gt;
and    l.type = &amp;#039;CF&amp;#039;&lt;br /&gt;
and    l.id1  = 0&lt;br /&gt;
and    l.id2  = 2&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Info on blocking processes===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select s1.username || &amp;#039;@&amp;#039; || s1.machine&lt;br /&gt;
       || &amp;#039; ( SID=&amp;#039; || s1.sid || &amp;#039; )  is blocking &amp;#039;&lt;br /&gt;
       || s2.username || &amp;#039;@&amp;#039; || s2.machine || &amp;#039; ( SID=&amp;#039; || s2.sid || &amp;#039; ) &amp;#039;  blocking_status&lt;br /&gt;
from   v$lock l1&lt;br /&gt;
,      v$session s1&lt;br /&gt;
,      v$lock l2&lt;br /&gt;
,      v$session s2&lt;br /&gt;
where  s1.sid     = l1.sid&lt;br /&gt;
and    s2.sid     = l2.sid&lt;br /&gt;
and    l1.block   = 1&lt;br /&gt;
and    l2.request &amp;gt; 0&lt;br /&gt;
and    l1.id1     = l2.id1&lt;br /&gt;
and    l2.id2     = l2.id2&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
session doing the blocking&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select *&lt;br /&gt;
from  v$lock l1&lt;br /&gt;
where 1=1&lt;br /&gt;
and   block = 1 ;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
sessions being blocked&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select *&lt;br /&gt;
from   v$lock l1&lt;br /&gt;
where  1=1&lt;br /&gt;
and    id2 = 85203&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
info on session doing the blocking&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select row_wait_obj#, row_wait_file#, row_wait_block#, row_wait_row#&lt;br /&gt;
from   v$session&lt;br /&gt;
where  sid = 234&lt;br /&gt;
&lt;br /&gt;
select do.object_name&lt;br /&gt;
,      row_wait_obj#&lt;br /&gt;
,      row_wait_file#&lt;br /&gt;
,      row_wait_block#&lt;br /&gt;
,      row_wait_row#&lt;br /&gt;
,      dbms_rowid.rowid_create ( 1, ROW_WAIT_OBJ#, ROW_WAIT_FILE#, ROW_WAIT_BLOCK#, ROW_WAIT_ROW# ) row_id&lt;br /&gt;
from   v$session   s&lt;br /&gt;
,      dba_objects do&lt;br /&gt;
where  sid=234&lt;br /&gt;
and    s.ROW_WAIT_OBJ# = do.OBJECT_ID;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Show locked objects===&lt;br /&gt;
 set lines 100&lt;br /&gt;
 set pages 999&lt;br /&gt;
 col username   format a20&lt;br /&gt;
 col sess_id    format a10&lt;br /&gt;
 col object     format a25&lt;br /&gt;
 col mode_held  format a10&lt;br /&gt;
 select oracle_username||&amp;#039; (&amp;#039;||s.osuser||&amp;#039;)&amp;#039; username&lt;br /&gt;
 ,      s.sid||&amp;#039;,&amp;#039;||s.serial# sess_id&lt;br /&gt;
 ,      owner||&amp;#039;.&amp;#039;||object_name object&lt;br /&gt;
 ,      object_type&lt;br /&gt;
 ,      decode ( l.block&lt;br /&gt;
               , 0, &amp;#039;Not Blocking&amp;#039;&lt;br /&gt;
               , 1, &amp;#039;Blocking&amp;#039;&lt;br /&gt;
               , 2, &amp;#039;Global&amp;#039;&lt;br /&gt;
               ) status&lt;br /&gt;
 ,      decode ( v.locked_mode&lt;br /&gt;
               , 0, &amp;#039;None&amp;#039;&lt;br /&gt;
               , 1, &amp;#039;Null&amp;#039;&lt;br /&gt;
               , 2, &amp;#039;Row-S (SS)&amp;#039;&lt;br /&gt;
               , 3, &amp;#039;Row-X (SX)&amp;#039;&lt;br /&gt;
               , 4, &amp;#039;Share&amp;#039;&lt;br /&gt;
               , 5, &amp;#039;S/Row-X (SSX)&amp;#039;&lt;br /&gt;
               , 6, &amp;#039;Exclusive&amp;#039;, TO_CHAR(lmode)&lt;br /&gt;
               ) mode_held&lt;br /&gt;
 from   v$locked_object v&lt;br /&gt;
 ,      dba_objects d&lt;br /&gt;
 ,      v$lock l&lt;br /&gt;
 ,      v$session s&lt;br /&gt;
 where  1=1&lt;br /&gt;
 and    v.object_id = d.object_id&lt;br /&gt;
 and    v.object_id = l.id1&lt;br /&gt;
 and    v.session_id = s.sid&lt;br /&gt;
 order  by oracle_username&lt;br /&gt;
 ,	session_id;&lt;br /&gt;
&lt;br /&gt;
===Show which row is locked===&lt;br /&gt;
 select do.object_name&lt;br /&gt;
 ,      row_wait_obj#&lt;br /&gt;
 ,      row_wait_file#&lt;br /&gt;
 ,      row_wait_block#&lt;br /&gt;
 ,      row_wait_row#&lt;br /&gt;
 ,      dbms_rowid.rowid_create (1, ROW_WAIT_OBJ#, ROW_WAIT_FILE#, ROW_WAIT_BLOCK#, ROW_WAIT_ROW#)&lt;br /&gt;
 from   v$session   s&lt;br /&gt;
 ,      dba_objects do&lt;br /&gt;
 where  1=1&lt;br /&gt;
 and    s.ROW_WAIT_OBJ# = do.OBJECT_ID&lt;br /&gt;
 and    sid             = &amp;amp;sid;&lt;br /&gt;
&lt;br /&gt;
===Check what is audited on a database===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set pagesize 100&lt;br /&gt;
set linesize 256&lt;br /&gt;
select audit_option,success,failure from dba_stmt_audit_opts;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===How old is the oldest audit record?===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select extract (day from (systimestamp - min(ntimestamp#))) days_old from aud$;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Check what objects are being audited===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
tti col 60 &amp;#039;Object Audit Options (dba_obj_audit_opts)&amp;#039; skip col 50 &amp;#039;A=By Access, S=By Session. Left=on success, right=on failure&amp;#039; skip 2&lt;br /&gt;
set lines 1000 pages 100&lt;br /&gt;
col alt for a3 head &amp;quot;Alt|er&amp;quot;&lt;br /&gt;
col aud for a3 head &amp;quot;Aud|it&amp;quot;&lt;br /&gt;
col com for a3 head &amp;quot;Com|ent&amp;quot;&lt;br /&gt;
col del for a3 head &amp;quot;Del|ete&amp;quot;&lt;br /&gt;
col gra for a3 head &amp;quot;Gra|nt&amp;quot;&lt;br /&gt;
col ind for a3 head &amp;quot;Ind|ex&amp;quot;&lt;br /&gt;
col ins for a3 head &amp;quot;Ins|ert&amp;quot;&lt;br /&gt;
col loc for a3 head &amp;quot;Lo|ck&amp;quot;&lt;br /&gt;
col ren for a3 head &amp;quot;Ren|ame&amp;quot;&lt;br /&gt;
col sel for a3 head &amp;quot;Sel|ect&amp;quot;&lt;br /&gt;
col upd for a3 head &amp;quot;Upd|ate&amp;quot;&lt;br /&gt;
col ref for a3 head &amp;quot;Ref|rnc&amp;quot;&lt;br /&gt;
col exe for a3 head &amp;quot;Exe|cut&amp;quot;&lt;br /&gt;
col cre for a3 head &amp;quot;Cre|ate&amp;quot;&lt;br /&gt;
col rea for a3 head &amp;quot;Re|ad&amp;quot;&lt;br /&gt;
col wri for a3 head &amp;quot;Wri|te&amp;quot;&lt;br /&gt;
col fbk for a3 head &amp;quot;Fla|sh&amp;quot;&lt;br /&gt;
	&lt;br /&gt;
select *&lt;br /&gt;
from   dba_obj_audit_opts&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Procedure to delete old audit records===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select text from all_source where lower(name)=&amp;#039;purge_audit_trail&amp;#039;;&lt;br /&gt;
&lt;br /&gt;
TEXT&lt;br /&gt;
------------------------------------------------------------------------------------------------&lt;br /&gt;
PROCEDURE purge_audit_trail IS&lt;br /&gt;
BEGIN&lt;br /&gt;
-- set the last archive timestamp&lt;br /&gt;
DBMS_AUDIT_MGMT.SET_LAST_ARCHIVE_TIMESTAMP(&lt;br /&gt;
       audit_trail_type    =&amp;gt; DBMS_AUDIT_MGMT.AUDIT_TRAIL_AUD_STD,&lt;br /&gt;
       last_archive_time   =&amp;gt; systimestamp - interval &amp;#039;365&amp;#039; day,&lt;br /&gt;
       rac_instance_number =&amp;gt; null&lt;br /&gt;
                                          );&lt;br /&gt;
-- purge audit trail till last archive timestamp&lt;br /&gt;
DBMS_AUDIT_MGMT.CLEAN_AUDIT_TRAIL( audit_trail_type =&amp;gt; DBMS_AUDIT_MGMT.AUDIT_TRAIL_AUD_STD&lt;br /&gt;
, use_last_arch_timestamp =&amp;gt; TRUE);&lt;br /&gt;
&lt;br /&gt;
END purge_audit_trail;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Job setup to run the audit purge===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
BEGIN&lt;br /&gt;
sys.dbms_scheduler.create_job(&lt;br /&gt;
    job_name =&amp;gt; &amp;#039;&amp;quot;SYS&amp;quot;.&amp;quot;PURGE_AUDIT_TRAIL_JOB&amp;quot;&amp;#039;,&lt;br /&gt;
    job_type =&amp;gt; &amp;#039;STORED_PROCEDURE&amp;#039;,&lt;br /&gt;
    job_action =&amp;gt; &amp;#039;&amp;quot;SYS&amp;quot;.&amp;quot;PURGE_AUDIT_TRAIL&amp;quot;&amp;#039;,&lt;br /&gt;
    repeat_interval =&amp;gt; &amp;#039;FREQ=DAILY;BYHOUR=20;BYMINUTE=0;BYSECOND=0&amp;#039;,&lt;br /&gt;
    start_date =&amp;gt; to_timestamp_tz(&amp;#039;2012-02-22 Europe/Paris&amp;#039;, &amp;#039;YYYY-MM-DD TZR&amp;#039;),&lt;br /&gt;
    job_class =&amp;gt; &amp;#039;&amp;quot;DEFAULT_JOB_CLASS&amp;quot;&amp;#039;,&lt;br /&gt;
    comments =&amp;gt; &amp;#039;purge audit trails until last archive timestamp&amp;#039;,&lt;br /&gt;
    auto_drop =&amp;gt; FALSE,&lt;br /&gt;
    enabled =&amp;gt; FALSE&lt;br /&gt;
);&lt;br /&gt;
sys.dbms_scheduler.set_attribute( name =&amp;gt; &amp;#039;&amp;quot;SYS&amp;quot;.&amp;quot;PURGE_AUDIT_TRAIL_JOB&amp;quot;&amp;#039;, attribute =&amp;gt; &amp;#039;logging_level&amp;#039;, value =&amp;gt; DBMS_SCHEDULER.LOGGING_OFF);&lt;br /&gt;
sys.dbms_scheduler.set_attribute( name =&amp;gt; &amp;#039;&amp;quot;SYS&amp;quot;.&amp;quot;PURGE_AUDIT_TRAIL_JOB&amp;quot;&amp;#039;, attribute =&amp;gt; &amp;#039;job_weight&amp;#039;, value =&amp;gt; 1);&lt;br /&gt;
sys.dbms_scheduler.enable( &amp;#039;&amp;quot;SYS&amp;quot;.&amp;quot;PURGE_AUDIT_TRAIL_JOB&amp;quot;&amp;#039; );&lt;br /&gt;
END;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===A list of all SIDs in oratab that should restart after a server boot===&lt;br /&gt;
Using awk&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
awk -F: &amp;#039;$NF==&amp;quot;Y&amp;quot; &amp;amp;&amp;amp; $1 !~/[#]/ {print $1}&amp;#039;  /etc/oratab&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Using perl&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
perl -F: -ne &amp;#039;print &amp;quot;$1\n&amp;quot; if /(\w+):(.+):Y$/&amp;#039; /etc/oratab&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Move the admin directories to a new location===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
./all_db_do &amp;quot;alter system set audit_file_dest=&amp;#039;/oracle/&amp;amp;SID/admin/adump&amp;#039; scope=spfile;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
./all_db_do &amp;quot;shutdown immediate&amp;quot;&lt;br /&gt;
&lt;br /&gt;
for db in `awk -F: &amp;#039;NF &amp;amp;&amp;amp; $1 !~/[#*]/ {print $1}&amp;#039;  /etc/oratab`&lt;br /&gt;
do&lt;br /&gt;
    echo $db&lt;br /&gt;
    mkdir -p /oracle/${db}/admin&lt;br /&gt;
    echo &amp;quot;/oracle/${db}/admin created&amp;quot;&lt;br /&gt;
    mv /oracle/admin/${db}/adump /oracle/${db}/admin/&lt;br /&gt;
    mv /oracle/admin/${db}/dpdump /oracle/${db}/admin/&lt;br /&gt;
    echo &amp;quot;Moved /oracle/admin/${db}/adump to /oracle/${db}/admin/&amp;quot;&lt;br /&gt;
done&lt;br /&gt;
&lt;br /&gt;
./all_db_do startup&lt;br /&gt;
&lt;br /&gt;
./all_db_do &amp;quot;create pfile from spfile;&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Check if the Standby database is up-to-date with the primary database===&lt;br /&gt;
 select arch.thread# &amp;quot;Thread&amp;quot;&lt;br /&gt;
 ,      arch.sequence# &amp;quot;Last Sequence Received&amp;quot;&lt;br /&gt;
 ,      appl.sequence# &amp;quot;Last Sequence Applied&amp;quot;&lt;br /&gt;
 ,      (arch.sequence# - appl.sequence#) &amp;quot;Difference&amp;quot;&lt;br /&gt;
 from   (&lt;br /&gt;
        select thread#&lt;br /&gt;
        ,      sequence#&lt;br /&gt;
        from   v$archived_log&lt;br /&gt;
        where  1=1&lt;br /&gt;
        and    ( thread#,first_time ) in (&lt;br /&gt;
                                         select thread#, max(first_time)&lt;br /&gt;
                                         from   v$archived_log&lt;br /&gt;
                                         group  by thread#&lt;br /&gt;
                                         )&lt;br /&gt;
        ) arch&lt;br /&gt;
        ,&lt;br /&gt;
        (&lt;br /&gt;
        select thread#&lt;br /&gt;
        ,      sequence#&lt;br /&gt;
        from   v$log_history&lt;br /&gt;
        where  1=1&lt;br /&gt;
        and    ( thread#,first_time ) in ( select thread# ,max(first_time)&lt;br /&gt;
                                           from   v$log_history&lt;br /&gt;
                                           group  by thread#&lt;br /&gt;
                                          )&lt;br /&gt;
        ) appl&lt;br /&gt;
 where  1=1&lt;br /&gt;
 and    arch.thread# = appl.thread#&lt;br /&gt;
 order  by 1;&lt;br /&gt;
&lt;br /&gt;
===Check for gaps on the Standby database===&lt;br /&gt;
Run this on the standby&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select thread#, low_sequence#, high_sequence# from v$archive_gap;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or run this on the Primary to see the latest generated archive...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select thread#   &amp;quot;Thread&amp;quot;&lt;br /&gt;
,      sequence# &amp;quot;Last sequence generated&amp;quot;&lt;br /&gt;
from   v$archived_log&lt;br /&gt;
where  (thread#, first_time) in ( select thread#, max(first_time)&lt;br /&gt;
                                  from   v$archived_log&lt;br /&gt;
                                  group  by thread#&lt;br /&gt;
                                )&lt;br /&gt;
order  by 1&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
and run this on the standby to check for received but not yet applied logs (this could be normal if a lag has been set)...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select arch.thread# &amp;quot;Thread&amp;quot;&lt;br /&gt;
,      arch.sequence# &amp;quot;Last sequence received&amp;quot;&lt;br /&gt;
,      appl.sequence# &amp;quot;Last sequence applied&amp;quot;&lt;br /&gt;
,      (arch.sequence#-appl.sequence#) &amp;quot;Difference&amp;quot;&lt;br /&gt;
from   (&lt;br /&gt;
       select thread#&lt;br /&gt;
       ,      sequence#&lt;br /&gt;
       from   v$archived_log&lt;br /&gt;
       where  (thread#,first_time ) in (select thread#, max(first_time)&lt;br /&gt;
                                        from   v$archived_log&lt;br /&gt;
                                        group  by thread#&lt;br /&gt;
                                       )&lt;br /&gt;
       ) arch&lt;br /&gt;
,      (&lt;br /&gt;
       select thread#&lt;br /&gt;
       ,      sequence#&lt;br /&gt;
       from   v$log_history&lt;br /&gt;
       where  (thread#,first_time ) in (select thread#, max(first_time)&lt;br /&gt;
                                        from   v$log_history&lt;br /&gt;
                                        group  by thread#&lt;br /&gt;
                                       )&lt;br /&gt;
      ) appl&lt;br /&gt;
where arch.thread# = appl.thread#&lt;br /&gt;
order by 1&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Compare the results from Primary and Secondary to detect possible network problems or other errors in shipping.&lt;br /&gt;
&lt;br /&gt;
===Ignore case-sensitive passwords in 11g (deprecated in 12c)===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter system set SEC_CASE_SENSITIVE_LOGON = false scope=both&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===External table for the Alert log (pre 11g)===&lt;br /&gt;
&lt;br /&gt;
 CREATE OR REPLACE DIRECTORY bdump AS &amp;#039;c:\oracle\product\diag dbms\orabase\orabase race\&amp;#039;;&lt;br /&gt;
 &lt;br /&gt;
 CREATE TABLE system.log_table (TEXT VARCHAR2(400))&lt;br /&gt;
 ORGANIZATION EXTERNAL (&lt;br /&gt;
 TYPE oracle_loader&lt;br /&gt;
 DEFAULT DIRECTORY bdump&lt;br /&gt;
 ACCESS PARAMETERS (&lt;br /&gt;
  RECORDS DELIMITED BY NEWLINE&lt;br /&gt;
  NOBADFILE NODISCARDFILE NOLOGFILE&lt;br /&gt;
  FIELDS TERMINATED BY &amp;#039;0x0A&amp;#039;&lt;br /&gt;
  MISSING FIELD VALUES ARE NULL)&lt;br /&gt;
 LOCATION (&amp;#039;alert_orabase.log&amp;#039;))&lt;br /&gt;
 REJECT LIMIT unlimited;&lt;br /&gt;
 &lt;br /&gt;
 SELECT * FROM system.log_table;&lt;br /&gt;
 &lt;br /&gt;
 CREATE OR REPLACE VIEW last_200_alerts AS&lt;br /&gt;
 WITH alert_log AS (&lt;br /&gt;
  SELECT rownum as lineno, text FROM system.log_table)&lt;br /&gt;
 SELECT text&lt;br /&gt;
 FROM alert_log&lt;br /&gt;
 WHERE lineno &amp;gt; (SELECT count(*)-200 FROM alert_log)&lt;br /&gt;
 ORDER BY lineno;&lt;br /&gt;
 &lt;br /&gt;
 SELECT * FROM last_200_alerts;&lt;br /&gt;
&lt;br /&gt;
===Alert log (11g+)===&lt;br /&gt;
This reads the log.xml file (which contains the same information as alert.log)&amp;lt;br /&amp;gt;&lt;br /&gt;
Show the messages put in the alert log in the last 24 hours&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select substr(MESSAGE_TEXT, 1, 300) message_text&lt;br /&gt;
,      count(*) cnt&lt;br /&gt;
from   X$DBGALERTEXT&lt;br /&gt;
where  1=1&lt;br /&gt;
and    (MESSAGE_TEXT like &amp;#039;%ORA-%&amp;#039; or upper(MESSAGE_TEXT) like &amp;#039;%ERROR%&amp;#039;)&lt;br /&gt;
and    cast(ORIGINATING_TIMESTAMP as DATE) &amp;gt; sysdate - &amp;amp;days_ago/1440&lt;br /&gt;
group  by substr(MESSAGE_TEXT, 1, 300)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
There is also a fixed table X$DBGDIREXT which returns all file and directory names under [diagnostic_dest]/diag directory:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select lpad(&amp;#039; &amp;#039;,lvl,&amp;#039; &amp;#039;)||logical_file file_name&lt;br /&gt;
from   x$dbgdirext&lt;br /&gt;
where  rownum &amp;lt;=20;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Directory paths available in v$diag_info===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 2000&lt;br /&gt;
col name for a35&lt;br /&gt;
col value for a100 wrap&lt;br /&gt;
select * from v$diag_info;&lt;br /&gt;
&lt;br /&gt;
   INST_ID NAME                                VALUE                                                                                                    CON_ID&lt;br /&gt;
---------- ----------------------------------- ---------------------------------------------------------------------------------------------------- ----------&lt;br /&gt;
         1 Diag Enabled                        TRUE                                                                                                          0&lt;br /&gt;
         1 ADR Base                            /cln/prg/ora_bin2/app/oracle                                                                               0&lt;br /&gt;
         1 ADR Home                            /cln/prg/ora_bin2/app/oracle/diag/rdbms/bild/bild                                                          0&lt;br /&gt;
         1 Diag Trace                          /cln/prg/ora_bin2/app/oracle/diag/rdbms/bild/bild/trace                                                    0&lt;br /&gt;
         1 Diag Alert                          /cln/prg/ora_bin2/app/oracle/diag/rdbms/bild/bild/alert                                                    0&lt;br /&gt;
         1 Diag Incident                       /cln/prg/ora_bin2/app/oracle/diag/rdbms/bild/bild/incident                                                 0&lt;br /&gt;
         1 Diag Cdump                          /cln/prg/ora_bin2/app/oracle/diag/rdbms/bild/bild/cdump                                                    0&lt;br /&gt;
         1 Health Monitor                      /cln/prg/ora_bin2/app/oracle/diag/rdbms/bild/bild/hm                                                       0&lt;br /&gt;
         1 Default Trace File                  /cln/prg/ora_bin2/app/oracle/diag/rdbms/bild/bild/trace/bild_ora_44696768.trc                              0&lt;br /&gt;
         1 Active Problem Count                0                                                                                                             0&lt;br /&gt;
         1 Active Incident Count               0                                                                                                             0&lt;br /&gt;
&lt;br /&gt;
11 rows selected.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Find out the names of the active trace files for the running processes===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select pid, program, tracefile from v$process;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Request was to duplicate a large tablespace from production to test environment===&lt;br /&gt;
...but rather than copy the terabytes of data, create the destination tablespace with just the most recent months data&amp;lt;br /&amp;gt;&lt;br /&gt;
====See what the source data looks like====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
col table_owner    for a20&lt;br /&gt;
col table_name     for a30&lt;br /&gt;
col partition_name for a20&lt;br /&gt;
set pages 100 lines 1000&lt;br /&gt;
&lt;br /&gt;
select table_owner&lt;br /&gt;
,      table_name&lt;br /&gt;
,      partition_name&lt;br /&gt;
,      partition_position&lt;br /&gt;
,      tablespace_name&lt;br /&gt;
from   dba_tab_partitions&lt;br /&gt;
where  tablespace_name = &amp;#039;ADS_ARCHIVE&amp;#039;&lt;br /&gt;
order  by 1,2,3,4&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This query produces something like this...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
TABLE_OWNER          TABLE_NAME                     PARTITION_NAME       PARTITION_POSITION TABLESPACE_NAME                &lt;br /&gt;
-------------------- ------------------------------ -------------------- ------------------ ------------------------------ &lt;br /&gt;
ADS_ARCHIVE          BIL_DAY_INV_CTR_ARC            Y2017_Q1_M01_D01                      1 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          BIL_HIS_DETAIL_FAC_ARC         Y2016_Q2_M05_D04                      1 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          BIL_HIS_DETAIL_FAC_ARC         Y2016_Q2_M05_D09                      2 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          BIL_MTH_INV_CTR_ARC            Y2017_Q1_M01_D01                      1 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          FAH_DAY_CBA_BGAAP_ARC          Y2011_Q4_M12_D30                      1 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          FAH_DAY_CBA_BGAAP_ARC          Y2011_Q4_M12_D31                      2 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          FAH_DAY_CBA_IFRS_ARC           Y2011_Q4_M12_D30                      1 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          FAH_DAY_CBA_IFRS_ARC           Y2011_Q4_M12_D31                      2 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          FAH_DAY_MVT_BGAAP_ARC          Y2011_Q4_M12_D30                      1 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          FAH_DAY_MVT_BGAAP_ARC          Y2011_Q4_M12_D31                      2 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          FAH_DAY_MVT_BGAAP_ARC          Y2012_Q1_M03_D31                      3 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          FAH_DAY_MVT_BGAAP_ARC          Y2012_Q2_M04_D01                      4 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          FAH_DAY_MVT_BGAAP_ARC          Y2012_Q4_M10_D12                      5 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          FAH_DAY_MVT_BGAAP_ARC          Y2012_Q4_M10_D13                      6 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          FAH_DAY_MVT_BGAAP_ARC          Y2012_Q4_M10_D14                      7 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          FAH_DAY_MVT_BGAAP_ARC_TST      Y2011_Q4_M12_D30                      1 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          FAH_DAY_MVT_BGAAP_ARC_TST      Y2011_Q4_M12_D31                      2 ADS_ARCHIVE&lt;br /&gt;
...&lt;br /&gt;
ADS_ARCHIVE          SBP_HIS_LINES_ARC              P_LS                                  3 ADS_ARCHIVE                  &lt;br /&gt;
ADS_ARCHIVE          THA_DAY_INV_CTR_ARC            Y2011_Q4_M12_D30                      1 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          THA_DAY_INV_CTR_ARC            Y2011_Q4_M12_D31                      2 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          THA_INV_HEAVY_ARC              Y2011_Q4_M12_D30                      1 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          THA_INV_HEAVY_ARC              Y2011_Q4_M12_D31                      2 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          THA_INV_LIGHT_ARC              Y2011_Q4_M12_D30                      1 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          THA_INV_LIGHT_ARC              Y2012_Q4_M10_D12                      2 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          THA_INV_LIGHT_ARC              Y2012_Q4_M10_D13                      3 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          THA_INV_LIGHT_ARC              Y2012_Q4_M10_D15                      4 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          THA_INV_LIGHT_ARC              Y2012_Q4_M10_D16                      5 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          THA_INV_LIGHT_ARC              Y2012_Q4_M10_D17                      6 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          THA_INV_LIGHT_ARC              Y2012_Q4_M10_D18                      7 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          THA_INV_LIGHT_ARC              Y2012_Q4_M10_D19                      8 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          THA_INV_LIGHT_ARC              Y2012_Q4_M10_D20                      9 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          THA_INV_LIGHT_ARC              Y2012_Q4_M10_D21                     10 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          THA_INV_LIGHT_ARC              Y2012_Q4_M10_D22                     11 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          THA_INV_LIGHT_ARC              Y2012_Q4_M10_D23                     12 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          THA_INV_LIGHT_ARC              Y2012_Q4_M10_D24                     13 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          THA_MTH_INV_CTR_ARC            Y2011_Q4_M12_D30                      1 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          THA_MTH_INV_CTR_ARC            Y2011_Q4_M12_D31                      2 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          THA_MTH_INV_CTR_ARC            Y2013_Q2_M04_D30                      3 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          XBD01_TEMP_HIS_ARC             Y2012_Q4_M12_D31                      1 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          T_RPT_RECO_THA_INV_ACC_ARC     Y2011_Q4_M12_D30                      1 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          T_RPT_RECO_THA_INV_ACC_ARC     Y2011_Q4_M12_D31                      2 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          T_RPT_RECO_THA_INV_MTH_ARC     Y2011_Q4_M12_D30                      1 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          T_RPT_RECO_THA_INV_MTH_ARC     Y2011_Q4_M12_D31                      2 ADS_ARCHIVE&lt;br /&gt;
ADS_ARCHIVE          XBD01_TEMP_HIS_ARC             Y2012_Q4_M12_D31                      1 ADS_ARCHIVE&lt;br /&gt;
ADS_DBA              FAH_DAY_CBA_BGAAP              Y2016_Q3_M07_D12                   1657 ADS_ARCHIVE&lt;br /&gt;
ADS_DBA              FAH_DAY_CBA_BGAAP              Y2016_Q4_M12_D13                   1811 ADS_ARCHIVE&lt;br /&gt;
ADS_DBA              FAH_DAY_MVT_IFRS               Y2016_Q4_M10_D10                   1654 ADS_ARCHIVE&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Capture the tablespace metadata====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set long 1000000&lt;br /&gt;
select dbms_metadata.get_ddl ( &amp;#039;TABLESPACE&amp;#039;, &amp;#039;ADS_ARCHIVE&amp;#039;) from dual&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
produces...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
CREATE TABLESPACE &amp;quot;ADS_ARCHIVE&amp;quot; DATAFILE&lt;br /&gt;
  &amp;#039;/oracle/tst/ora_data3/adst/ads_archive01.dbf&amp;#039; SIZE 104857600&lt;br /&gt;
  AUTOEXTEND ON NEXT 104857600 MAXSIZE 32000M,&lt;br /&gt;
...&lt;br /&gt;
  &amp;#039;/oracle/tst/ora_data3/adst/ads_archive66.dbf&amp;#039; SIZE 104857600&lt;br /&gt;
  AUTOEXTEND ON NEXT 104857600 MAXSIZE 3200M,&lt;br /&gt;
  LOGGING ONLINE PERMANENT BLOCKSIZE 8192&lt;br /&gt;
  EXTENT MANAGEMENT LOCAL AUTOALLOCATE DEFAULT&lt;br /&gt;
 NOCOMPRESS  SEGMENT SPACE MANAGEMENT AUTO&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Capture the tablespace objects&amp;#039; metadata====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cat&amp;lt;&amp;lt;EOCAT &amp;gt;expdp_adst_ads_archive_metadata.par&lt;br /&gt;
userid=&amp;#039;/ as sysdba&amp;#039;&lt;br /&gt;
dumpfile=adst_ads_archive_metadata.dmp&lt;br /&gt;
logfile=expdp_adst_ads_archive_metadata.log&lt;br /&gt;
tablespaces=ADS_ARCHIVE&lt;br /&gt;
parallel=20&lt;br /&gt;
content=metadata_only&lt;br /&gt;
exclude=statistics&lt;br /&gt;
EOCAT&lt;br /&gt;
&lt;br /&gt;
expdp parfile=expdp_adst_ads_archive_metadata.par&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Find the partitions with data from the most recent month====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cat &amp;lt;&amp;lt;EOCAT&amp;gt;/tmp/adst_ads_archive_partitions.sql&lt;br /&gt;
set termo off echo off lines 1000 feedb off headi off newpa none trims on&lt;br /&gt;
spool /tmp/adst_ads_archive_partitions.lst&lt;br /&gt;
select table_owner||&amp;#039;.&amp;#039;||table_name||&amp;#039;:&amp;#039;||partition_name&lt;br /&gt;
from   dba_tab_partitions&lt;br /&gt;
where  tablespace_name = &amp;#039;ADS_ARCHIVE&amp;#039;&lt;br /&gt;
and    partition_name like &amp;#039;Y2017_Q1_M01%&amp;#039;&lt;br /&gt;
/&lt;br /&gt;
spool off&lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;@/tmp/adst_ads_archive_partitions.sql&amp;quot; | sqlplus / as sysdba&lt;br /&gt;
EOCAT&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
produces...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_CBA_BGAAP_ARC:Y2017_Q1_M01_D07&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_IFRS_ARC:Y2017_Q1_M02_D26&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_IFRS_ARC:Y2017_Q1_M02_D25&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_IFRS_ARC:Y2017_Q1_M02_D19&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_IFRS_ARC:Y2017_Q1_M02_D18&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_IFRS_ARC:Y2017_Q1_M02_D12&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_IFRS_ARC:Y2017_Q1_M02_D11&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_IFRS_ARC:Y2017_Q1_M02_D05&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_BGAAP_ARC:Y2017_Q1_M02_D26&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_BGAAP_ARC:Y2017_Q1_M02_D25&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_BGAAP_ARC:Y2017_Q1_M02_D19&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_BGAAP_ARC:Y2017_Q1_M02_D18&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_BGAAP_ARC:Y2017_Q1_M02_D12&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_BGAAP_ARC:Y2017_Q1_M02_D11&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_BGAAP_ARC:Y2017_Q1_M02_D05&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_BGAAP_ARC:Y2017_Q1_M02_D04&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_BGAAP_ARC:Y2017_Q1_M01_D29&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_BGAAP_ARC:Y2017_Q1_M01_D28&lt;br /&gt;
...&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_BGAAP_ARC:Y2017_Q1_M01_D22&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_BGAAP_ARC:Y2017_Q1_M01_D21&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_BGAAP_ARC:Y2017_Q1_M01_D15&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_BGAAP_ARC:Y2017_Q1_M01_D14&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_BGAAP_ARC:Y2017_Q1_M01_D08&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_BGAAP_ARC:Y2017_Q1_M01_D07&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_BGAAP_ARC:Y2017_Q1_M01_D01&lt;br /&gt;
ADS_ARCHIVE.BIL_MTH_INV_CTR_ARC:Y2017_Q1_M01_D01&lt;br /&gt;
ADS_ARCHIVE.BIL_DAY_INV_CTR_ARC:Y2017_Q1_M01_D01&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_IFRS_ARC:Y2017_Q1_M02_D04&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_IFRS_ARC:Y2017_Q1_M01_D29&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_IFRS_ARC:Y2017_Q1_M01_D28&lt;br /&gt;
ADS_ARCHIVE.FAH_DAY_MVT_IFRS_ARC:Y2017_Q1_M01_D22&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Export the data in these partitions====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cat&amp;lt;&amp;lt;EOCAT &amp;gt;expdp_adst_ads_archive_partitions.par&lt;br /&gt;
userid=&amp;#039;/ as sysdba&amp;#039;&lt;br /&gt;
dumpfile=adst_ads_archive_Y2017_%U.dmp&lt;br /&gt;
logfile=expdp_adst_ads_archive_Y2017.log&lt;br /&gt;
EOCAT&lt;br /&gt;
&lt;br /&gt;
cat /tmp/adst_ads_archive_partitions.lst | perl -p -i -e &amp;#039;s/^/tables=/&amp;#039;g &amp;gt;&amp;gt;expdp_adst_ads_archive_partitions.par&lt;br /&gt;
&lt;br /&gt;
cat&amp;lt;&amp;lt;EOCAT &amp;gt;&amp;gt;expdp_adst_ads_archive_partitions.par&lt;br /&gt;
parallel=20&lt;br /&gt;
exclude=statistics&lt;br /&gt;
EOCAT&lt;br /&gt;
&lt;br /&gt;
expdp parfile=expdp_adst_ads_archive_partitions.par&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Drop the old tablespace====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
drop tablespace ads_archive including contents and datafiles&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Recreate the tablepspace using the metadata capture above====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
create tablespace &amp;quot;ADS_ARCHIVE&amp;quot;&lt;br /&gt;
datafile &amp;#039;/oracle/tst/ora_data3/adst/ads_archive01.dbf&amp;#039; size 100M autoextend on next 50M maxsize unlimited&lt;br /&gt;
,        &amp;#039;/oracle/tst/ora_data3/adst/ads_archive02.dbf&amp;#039; size 100M autoextend on next 50M maxsize unlimited&lt;br /&gt;
,        &amp;#039;/oracle/tst/ora_data3/adst/ads_archive03.dbf&amp;#039; size 100M autoextend on next 50M maxsize unlimited&lt;br /&gt;
,        &amp;#039;/oracle/tst/ora_data3/adst/ads_archive04.dbf&amp;#039; size 100M autoextend on next 50M maxsize unlimited&lt;br /&gt;
,        &amp;#039;/oracle/tst/ora_data3/adst/ads_archive05.dbf&amp;#039; size 100M autoextend on next 50M maxsize unlimited&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Import the tablespace metadata====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cat&amp;lt;&amp;lt;EOCAT &amp;gt;impdp_adst_ads_archive_metadata.par&lt;br /&gt;
userid=&amp;#039;/ as sysdba&amp;#039;&lt;br /&gt;
dumpfile=adst_ads_archive_metadata.dmp&lt;br /&gt;
logfile=impdp_adst_ads_archive_metadata.log&lt;br /&gt;
EOCAT&lt;br /&gt;
&lt;br /&gt;
impdp parfile=impdp_adst_ads_archive_metadata.par&lt;br /&gt;
&lt;br /&gt;
select &amp;#039;alter index &amp;#039;|| owner||&amp;#039;.&amp;#039;||index_name||&amp;#039; rebuild online parallel 8;&amp;#039;&lt;br /&gt;
from   dba_indexes&lt;br /&gt;
where  status = &amp;#039;UNUSABLE&amp;#039;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Import the last month partition data====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cat&amp;lt;&amp;lt;EOCAT &amp;gt;impdp_adst_ads_archive_partitions.par&lt;br /&gt;
userid=&amp;#039;/ as sysdba&amp;#039;&lt;br /&gt;
dumpfile=adst_ads_archive_Y2017_%U.dmp&lt;br /&gt;
logfile=impdp_adst_ads_archive_Y2017.log&lt;br /&gt;
table_exists_action=append&lt;br /&gt;
parallel=20&lt;br /&gt;
EOCAT&lt;br /&gt;
&lt;br /&gt;
impdp parfile=impdp_adst_ads_archive_partitions.par&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Write to a TCP/IP socket from PL/SQL===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
declare&lt;br /&gt;
 bt_conn               utl_tcp.connection;&lt;br /&gt;
 retval                binary_integer;&lt;br /&gt;
 l_sequence            varchar2(30) := &amp;#039;Sequence Number 101021&amp;#039;;&lt;br /&gt;
begin&lt;br /&gt;
 bt_conn := utl_tcp.open_connection(remote_host =&amp;gt; &amp;#039;10.10.1.1&amp;#039;&lt;br /&gt;
                                   ,remote_port =&amp;gt; 5000&lt;br /&gt;
                                   ,tx_timeout =&amp;gt; 1&lt;br /&gt;
                                   )&lt;br /&gt;
 ;&lt;br /&gt;
 retval := utl_tcp.write_line(bt_conn,l_sequence)&lt;br /&gt;
 ;&lt;br /&gt;
 utl_tcp.flush(bt_conn)&lt;br /&gt;
 ;&lt;br /&gt;
 utl_tcp.close_connection(bt_conn)&lt;br /&gt;
 ;&lt;br /&gt;
exception&lt;br /&gt;
 when others then&lt;br /&gt;
  raise_application_error(-20101, sqlerrm)&lt;br /&gt;
  ; &lt;br /&gt;
  utl_tcp.close_connection(bt_conn)&lt;br /&gt;
  ;&lt;br /&gt;
end&lt;br /&gt;
;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
and read from it using netcat in another session&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
nc -lk 5000&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
produces&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Sequence Number 101021&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Execute a script as a different user===&lt;br /&gt;
Some things have to be done as the user and cannot be done as sys (eg. creating and dropping jobs or create and drop a database link)&amp;lt;br /&amp;gt;&lt;br /&gt;
It is possible to login as the user by saving, changing and resetting his password (using identified by values) but using dbms_sys_sql is another option&amp;lt;br /&amp;gt;&lt;br /&gt;
Create a PL/SQL procedure to drop a db link&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
create or replace procedure drop_dblink ( p_schema_name in varchar2&lt;br /&gt;
                                        , p_dblink      in varchar2&lt;br /&gt;
                                        ) is&lt;br /&gt;
    l_plsql   varchar2(1000);&lt;br /&gt;
    l_cur     number;&lt;br /&gt;
    l_uid     number;&lt;br /&gt;
    l_rc      number;&lt;br /&gt;
begin&lt;br /&gt;
    select  du.user_id&lt;br /&gt;
    into    l_uid&lt;br /&gt;
    from    dba_users du&lt;br /&gt;
    where   du.username = p_schema_name&lt;br /&gt;
    ;&lt;br /&gt;
    plsql := &amp;#039;drop database link &amp;quot;&amp;#039;||p_dblink||&amp;#039;&amp;quot;&amp;#039;;&lt;br /&gt;
    l_cur := sys.dbms_sys_sql.open_cursor;&lt;br /&gt;
    sys.dbms_sys_sql.parse_as_user(&lt;br /&gt;
        c             =&amp;gt; l_cur,&lt;br /&gt;
        statement     =&amp;gt; l_plsql,&lt;br /&gt;
        language_flag =&amp;gt; dbms_sql.native,&lt;br /&gt;
        userid        =&amp;gt; l_uid&lt;br /&gt;
    );&lt;br /&gt;
    l_rc := sys.dbms_sys_sql.execute(l_cur);&lt;br /&gt;
    sys.dbms_sys_sql.close_cursor(l_cur);&lt;br /&gt;
end;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Generate the calls to the procedure with the required parameters&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select &amp;#039;exec drop_dblink (&amp;#039;&amp;#039;&amp;#039;|| owner ||&amp;#039;&amp;#039;&amp;#039;&amp;#039;||&amp;#039;, &amp;#039;||&amp;#039;&amp;#039;&amp;#039;&amp;#039;||db_link||&amp;#039;&amp;#039;&amp;#039;&amp;#039;||&amp;#039;);&amp;#039;&lt;br /&gt;
from   dba_db_links&lt;br /&gt;
where  owner   != &amp;#039;PUBLIC&amp;#039;&lt;br /&gt;
and    db_link like &amp;#039;%FTST%&amp;#039;&lt;br /&gt;
or     db_link like &amp;#039;%HDEV%&amp;#039;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
and this reveals the lines to be executed&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
exec drop_dblink (&amp;#039;USER1&amp;#039;, &amp;#039;DBL_FTST.WORLD&amp;#039;);&lt;br /&gt;
exec drop_dblink (&amp;#039;USER1&amp;#039;, &amp;#039;DBL_HDEV.WORLD&amp;#039;);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Drop the procedure when finished with it&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
drop procedure drop_dblink;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
or do it as an anonymous block in one go...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
declare&lt;br /&gt;
    uid number;&lt;br /&gt;
    sqltext varchar2(1000) := &amp;#039;drop database link &amp;quot;&amp;amp;DB_LINK&amp;quot;&amp;#039;;&lt;br /&gt;
    myint integer;&lt;br /&gt;
begin&lt;br /&gt;
    select user_id into uid from dba_users where username = &amp;#039;&amp;amp;USERNAME&amp;#039;;&lt;br /&gt;
    myint:=sys.dbms_sys_sql.open_cursor();&lt;br /&gt;
    sys.dbms_sys_sql.parse_as_user(myint,sqltext,dbms_sql.native,UID);&lt;br /&gt;
    sys.dbms_sys_sql.close_cursor(myint);&lt;br /&gt;
end;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Handling single quote marks inside SQL statements===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SQL&amp;gt; SELECT &amp;#039;D&amp;#039;&amp;#039;COSTA&amp;#039; name FROM DUAL;&lt;br /&gt;
&lt;br /&gt;
NAME&lt;br /&gt;
-------&lt;br /&gt;
D&amp;#039;COSTA&lt;br /&gt;
&lt;br /&gt;
Alternatively, use the 10g+ quoting method:&lt;br /&gt;
&lt;br /&gt;
SQL&amp;gt; SELECT q&amp;#039;$D&amp;#039;COSTA$&amp;#039; NAME FROM DUAL;&lt;br /&gt;
&lt;br /&gt;
NAME&lt;br /&gt;
-------&lt;br /&gt;
D&amp;#039;COSTA&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Run a script on all databases in /etc/oratab===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
export ORAENV_ASK=NO&lt;br /&gt;
for db in `awk -F: &amp;#039;NF &amp;amp;&amp;amp; $1 !~/[#*]/ {print $1}&amp;#039;  /etc/oratab`&lt;br /&gt;
do&lt;br /&gt;
    echo $db&lt;br /&gt;
    ORACLE_SID=$db&lt;br /&gt;
    . oraenv&lt;br /&gt;
    sqlplus -V&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Schedule a cron job to run on the last day of each month===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
0 23 28-31 * * [ $(date -d +1day +%d) -eq 1 ] &amp;amp;&amp;amp; su - oracle -c &amp;quot;dsmc  arch -server=SO_U_`hostname`_ORX_M_SOL &amp;#039;/oracle/export/PV6/expdp_PV6_D_FULL_`date +\%Y\%m\%d`*&amp;#039;&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===How to tell if a year is a leap year or not - using cal instead of reinventing the wheel===&lt;br /&gt;
Test: Why is Julian day 0, 17th November 1858?&amp;lt;br /&amp;gt;&lt;br /&gt;
Pretty comprehensive answer: [http://h71000.www7.hp.com/wizard/wiz_2315.html here] and [http://mentalfloss.com/article/51370/why-our-calendars-skipped-11-days-1752 here]&amp;lt;br /&amp;gt;&lt;br /&gt;
Also attempts to answer the question why typing &amp;#039;cal 09 1752&amp;#039; on Unix systems looks so odd!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
function leap {&lt;br /&gt;
#  This function tells you if the year passed in as a parameter is a leap year or not...&lt;br /&gt;
if [[ $(cal 2 ${1:-$(date &amp;#039;+%Y&amp;#039;)} | egrep &amp;#039;\&amp;lt;[[:digit:]]{1,2}\&amp;gt;&amp;#039; | wc -w) -eq 29 ]]; then&lt;br /&gt;
    leap=&amp;#039;Y&amp;#039;&lt;br /&gt;
else&lt;br /&gt;
    leap=&amp;#039;N&amp;#039;&lt;br /&gt;
fi&lt;br /&gt;
echo ${leap}&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Reset an expired (and/or locked) user password to the same value===&lt;br /&gt;
Can be used to save user passwords for example in a test environment before destroying them with a copy of production.&amp;lt;br /&amp;gt;&lt;br /&gt;
Simple, quick and easy version. Run this then pick and choose the statements you want to run.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 200 pages 200&lt;br /&gt;
col user_list for a200 head &amp;quot;Expired User List&amp;quot;&lt;br /&gt;
&lt;br /&gt;
select &amp;#039;alter user &amp;#039; ||su.name||&amp;#039; identified by values&amp;#039;||&amp;#039;&amp;#039;&amp;#039;&amp;#039;||spare4||&amp;#039;;&amp;#039;||su.password||&amp;#039;&amp;#039;&amp;#039; account unlock;&amp;#039; user_list&lt;br /&gt;
from   sys.user$ su&lt;br /&gt;
,      dba_users du&lt;br /&gt;
where  1=1&lt;br /&gt;
and    su.name              = du.username&lt;br /&gt;
and    du.oracle_maintained = &amp;#039;N&amp;#039;&lt;br /&gt;
and    (account_status      like &amp;#039;EXPIRED%&amp;#039; or account_status like &amp;#039;%LOCKED&amp;#039;)&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
More industrialised version. Create a package.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
create or replace package dba_utils&lt;br /&gt;
as&lt;br /&gt;
    procedure reset_password ( p_userlist in varchar2 );&lt;br /&gt;
end dba_utils;&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
create or replace package body dba_utils&lt;br /&gt;
as&lt;br /&gt;
&lt;br /&gt;
procedure reset_password ( p_userlist in varchar2 )&lt;br /&gt;
is&lt;br /&gt;
    cursor c1 ( p_userlist in varchar2 ) is&lt;br /&gt;
    select username&lt;br /&gt;
    ,      regexp_substr ( dbms_metadata.get_ddl(&amp;#039;USER&amp;#039;, username), &amp;#039;&amp;#039;&amp;#039;[^&amp;#039;&amp;#039;]+&amp;#039;&amp;#039;&amp;#039; ) pwd&lt;br /&gt;
    from   dba_users&lt;br /&gt;
    where  1=1&lt;br /&gt;
    and    username in upper( p_userlist )&lt;br /&gt;
    ;&lt;br /&gt;
begin&lt;br /&gt;
    dbms_output.enable(null);&lt;br /&gt;
    for r1 in c1 ( p_userlist )&lt;br /&gt;
    loop&lt;br /&gt;
        begin&lt;br /&gt;
            execute immediate &amp;#039;alter user &amp;#039; || r1.username || &amp;#039; account unlock&amp;#039;;&lt;br /&gt;
            execute immediate &amp;#039;alter user &amp;#039; || r1.username || &amp;#039; identified by values &amp;#039; || r1.pwd;&lt;br /&gt;
        exception&lt;br /&gt;
        when others then&lt;br /&gt;
            dbms_output.put_line(&amp;#039;Unable to modify user &amp;#039; || r1.username);&lt;br /&gt;
        end;&lt;br /&gt;
    end loop;&lt;br /&gt;
end reset_password;&lt;br /&gt;
&lt;br /&gt;
end dba_utils;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Call it&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set serveroutput on&lt;br /&gt;
exec dba_utils.reset_password (&amp;#039;STUART&amp;#039;);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Latch, mutex and beyond===&lt;br /&gt;
A fine example of how to write scripts from SQL*Plus that interact with the shell underneath&amp;lt;br /&amp;gt;&lt;br /&gt;
Found [https://andreynikolaev.wordpress.com/demonstration-scripts/cursor_pin_s_contention-sql/ here at andreynikolaev.wordpress.com]&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/*&lt;br /&gt;
     This file is part of demos for &amp;quot;Mutex Internals&amp;quot;  seminar v.04.04.2011&lt;br /&gt;
     Andrey S. Nikolaev (Andrey.Nikolaev@rdtex.ru) &lt;br /&gt;
     https://andreynikolaev.wordpress.com &lt;br /&gt;
 &lt;br /&gt;
     &amp;quot;Cursor: pin S&amp;quot; contention testcase.&lt;br /&gt;
 &lt;br /&gt;
     The script spawn several sessions to induce &amp;quot;Cursor: pin S&amp;quot;, &lt;br /&gt;
     creates AWR snapshots and generates AWR report&lt;br /&gt;
 &lt;br /&gt;
     Beware: The script will restart the test database.&lt;br /&gt;
 &lt;br /&gt;
     usage: sqlplus /nolog @cursor_pin_s_contention.sql &amp;lt;parallelism&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
*/ &lt;br /&gt;
connect / as sysdba&lt;br /&gt;
startup force&lt;br /&gt;
set echo off&lt;br /&gt;
set define %&lt;br /&gt;
set verify off&lt;br /&gt;
set head off&lt;br /&gt;
set linesize 300&lt;br /&gt;
 &lt;br /&gt;
/* spawn parallel processes to create load on mutex */&lt;br /&gt;
spool one_thread.tmp&lt;br /&gt;
select &amp;#039;set verify off&amp;#039; from dual;&lt;br /&gt;
select &amp;#039;alter session set session_cached_cursors = 50;&amp;#039; from dual; &lt;br /&gt;
select &amp;#039;begin for i in 1..1000000 loop&amp;#039; from dual;&lt;br /&gt;
select &amp;#039;      execute immediate &amp;#039;&amp;#039;select 1 from dual where 1=2&amp;#039;&amp;#039;;&amp;#039; from dual;&lt;br /&gt;
select &amp;#039;end loop; end;&amp;#039;||chr(10)||&amp;#039;/&amp;#039; from dual;&lt;br /&gt;
spool off&lt;br /&gt;
 &lt;br /&gt;
/* sleep while AWR initialized */&lt;br /&gt;
host sleep 5&lt;br /&gt;
 &lt;br /&gt;
exec dbms_workload_repository.create_snapshot();&lt;br /&gt;
 &lt;br /&gt;
spool many_threads.tmp&lt;br /&gt;
select &amp;#039;host sqlplus &amp;quot;/ as sysdba&amp;quot; @one_thread.tmp &amp;amp;&amp;#039;&lt;br /&gt;
from dba_objects where rownum &amp;lt;= %1;&lt;br /&gt;
spool off&lt;br /&gt;
 &lt;br /&gt;
@many_threads.tmp&lt;br /&gt;
host sleep 50&lt;br /&gt;
set echo on&lt;br /&gt;
exec dbms_workload_repository.create_snapshot();&lt;br /&gt;
set markup html on&lt;br /&gt;
set head on&lt;br /&gt;
spool mutex_sleep_history.htm&lt;br /&gt;
select to_char(SLEEP_TIMESTAMP,&amp;#039;hh:mi:ss.ff&amp;#039;) SLEEP_TIMESTAMP,MUTEX_ADDR,MUTEX_IDENTIFIER,MUTEX_TYPE,&lt;br /&gt;
       GETS,SLEEPS,REQUESTING_SESSION,BLOCKING_SESSION,&lt;br /&gt;
       LOCATION,MUTEX_VALUE from x$mutex_sleep_history order by sleep_timestamp;&lt;br /&gt;
spool off&lt;br /&gt;
 &lt;br /&gt;
set define &amp;amp;&lt;br /&gt;
set markup html off&lt;br /&gt;
set echo off heading on underline on;&lt;br /&gt;
column inst_num  heading &amp;quot;Inst Num&amp;quot;  new_value inst_num  format 99999;&lt;br /&gt;
column inst_name heading &amp;quot;Instance&amp;quot;  new_value inst_name format a12;&lt;br /&gt;
column db_name   heading &amp;quot;DB Name&amp;quot;   new_value db_name   format a12;&lt;br /&gt;
column dbid      heading &amp;quot;DB Id&amp;quot;     new_value dbid      format 9999999999 just c;&lt;br /&gt;
select d.dbid            dbid&lt;br /&gt;
     , d.name            db_name&lt;br /&gt;
     , i.instance_number inst_num&lt;br /&gt;
     , i.instance_name   inst_name&lt;br /&gt;
  from v$database d,&lt;br /&gt;
       v$instance i;&lt;br /&gt;
define num_days=1;&lt;br /&gt;
define report_type=&amp;#039;html&amp;#039;;&lt;br /&gt;
col end_snap new_value end_snap;&lt;br /&gt;
col begin_snap new_value begin_snap;&lt;br /&gt;
select max(snap_id) end_snap from dba_hist_snapshot where dbid=&amp;amp;dbid;&lt;br /&gt;
select max(snap_id) begin_snap from dba_hist_snapshot where dbid=&amp;amp;dbid and snap_id &amp;lt; &amp;amp;end_snap;&lt;br /&gt;
define report_name=&amp;#039;awr_report.htm&amp;#039;;&lt;br /&gt;
@?/rdbms/admin/awrrpti&lt;br /&gt;
exit&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==shell==&lt;br /&gt;
[http://www.databasejournal.com/features/oracle/article.php/3869076/Alert-Log-Scraping-with-Oracles-ADRCI-Utility.htm Alert Log scraping with ADRCI]&lt;br /&gt;
&lt;br /&gt;
====Count the number of background processes for a particular SID====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SID=RAVJDE1&lt;br /&gt;
ps -ef|cut -c54-100|awk -v SID=$SID &amp;#039;$0 ~ /&amp;#039;$SID&amp;#039;$/ {print}&amp;#039;|wc -l&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or ...this will work with any OS (so long as the process is at the end of the &amp;lt;strong&amp;gt;ps -ef&amp;lt;/strong&amp;gt; or &amp;lt;strong&amp;gt;ps -aux&amp;lt;/strong&amp;gt; listing&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SID=RAVJDE1&lt;br /&gt;
ps -ef|awk -v SID=$SID -F_ &amp;#039;{ $NF ~ /&amp;#039;$SID&amp;#039;$/ {print} }&amp;#039;|wc -l&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Pick the columns you want in the ps listing&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ps -efo user,pid,ppid=MOM -o args&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Find Oracle errors in the most recent DataPump log files====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
00 09 * * * /home/tools/scripts/oracle/dosh &amp;#039;find /oracle/export -name &amp;quot;expdp*log&amp;quot; -mtime -1 -exec grep ORA- {} \; -ls&amp;#039; | mailx -s &amp;#039;Datapump errors for &amp;lt;customer&amp;gt;last night&amp;#039; stuart@domain.com&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Find the 10 largest directories on a particular filesystem====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
du -ag /oracle | sort -nr | head -n 10&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Find the 10 largest files on a particular mount point====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
find /home -size +1G -ls | sort -nr +6 | head -10&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
find /home -xdev -ls | sort -nr +6 | head -10&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Split a file in pieces using sed====&lt;br /&gt;
Using fixed line numbers&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sed -ne &amp;#039;1,12p&amp;#039; file &amp;gt; text.part1&lt;br /&gt;
sed -ne &amp;#039;13,$p&amp;#039; file &amp;gt; text.part2&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Using line with a /pattern/ on it&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sed -e &amp;#039;/hello/q&amp;#039; tt.dat | grep -v hello &amp;gt; text.part1&lt;br /&gt;
sed -n `sed -n &amp;#039;/hello/=&amp;#039; tt.dat`&amp;#039;,$p&amp;#039; tt.dat | grep -v hello &amp;gt; text.part2&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Split a file in pieces using Perl====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
perl -ne &amp;#039;print if 1 .. /marker line/&amp;#039; text.dat &amp;gt;text.part1&lt;br /&gt;
perl -ne &amp;#039;print if /marker line/ .. eof()&amp;#039; text.dat &amp;gt;text.part2&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Find and display RMAN errors in an RMAN log file====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sed -ne &amp;#039;/^RMAN-/,/^$/p&amp;#039;  RMAN_&amp;lt;SID&amp;gt;_&amp;lt;DATE&amp;gt;.log&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==cmd==&lt;br /&gt;
*[http://www.dba-oracle.com/t_scripts_windows_export.htm Database Export - from DBA Oracle (Burleson)]&lt;br /&gt;
==Perl==&lt;br /&gt;
===For all files in a directory, replace a keyword (SSIIDD) in a file with another (a parameter)===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
for i in `ls`&lt;br /&gt;
do&lt;br /&gt;
    perl -p -i -e &amp;#039;s/SSIIDD/&amp;#039;$SID&amp;#039;/g&amp;#039; $i&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Parse tnsnames.ora to get just the service names===&lt;br /&gt;
[[http://stackoverflow.com/questions/12605415/parsing-tnsnames-ora-with-regex-to-just-get-name from here]]&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
perl -ne &amp;#039;print if m/^([^#()\W ][a-zA-Z.]*(?:[.][a-zA-Z]*\s?=)?)/&amp;#039; $TNS_ADMIN/tnsnames.ora&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===and use that to check the listener status===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
for svc in `perl -ne &amp;#039;print if m/^([^#()\W ][a-zA-Z.]*(?:[.][a-zA-Z]*\s?=)?)/&amp;#039; $TNS_ADMIN/tnsnames.ora | sed -e &amp;#039;s/=//&amp;#039;` ;do&lt;br /&gt;
    tnsping $svc&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Stuart</name></author>	</entry>

	<entry>
		<id>https://mailnest.com/dbawiki/index.php?title=Snippets&amp;diff=3368</id>
		<title>Snippets</title>
		<link rel="alternate" type="text/html" href="https://mailnest.com/dbawiki/index.php?title=Snippets&amp;diff=3368"/>
				<updated>2018-11-21T11:13:18Z</updated>
		
		<summary type="html">&lt;p&gt;Stuart: /* Simulating errors in alert log */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;===Protecting an Apache Web Server directory with htaccess===&lt;br /&gt;
* [https://davidwalsh.name/password-protect-directory-using-htaccess https://davidwalsh.name/password-protect-directory-using-htaccess]&lt;br /&gt;
* [http://www.htaccesstools.com/articles/password-protection/ http://www.htaccesstools.com/articles/password-protection/]&lt;br /&gt;
Two files are needed.&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;The .htaccess Code&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
AuthType Basic&lt;br /&gt;
AuthName &amp;quot;restricted area&amp;quot;&lt;br /&gt;
AuthUserFile /home/davidwalsh/html/protect-me-dir/.htpasswd&lt;br /&gt;
require valid-user&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;The .htpasswd Code&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
davidwalsh:daWHfZrDLB88.&lt;br /&gt;
rodstewart:roFulYxC2.8ws&lt;br /&gt;
cssexpert:csmnmq.M8T5ho&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Protecting a lighttpd directory with htaccess===&lt;br /&gt;
Generate an MD5 hash with the tools above and paste into this file&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
vi /etc/lighttpd/.htpasswd&lt;br /&gt;
stuart:3#$567890#$56789056789&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Check modules.conf file to ensure mod_auth and mod_rewrite are enabled&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
vi /etc/lighttpd/modules.conf&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Alter the lighttpd.conf file to allow the authentication&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#auth directives&lt;br /&gt;
auth.backend = &amp;quot;htpasswd&amp;quot;&lt;br /&gt;
auth.backend.htpasswd.userfile = &amp;quot;/etc/lighttpd/.htpasswd&amp;quot;&lt;br /&gt;
auth.debug = 1&lt;br /&gt;
$HTTP[&amp;quot;url&amp;quot;] =~ &amp;quot;^/cgi-bin&amp;quot; {&lt;br /&gt;
        auth.require = ( &amp;quot;&amp;quot; =&amp;gt;&lt;br /&gt;
        (&lt;br /&gt;
        &amp;quot;method&amp;quot; =&amp;gt; &amp;quot;basic&amp;quot;,&lt;br /&gt;
        &amp;quot;realm&amp;quot; =&amp;gt; &amp;quot;DbaHawk access&amp;quot;,&lt;br /&gt;
        &amp;quot;require&amp;quot; =&amp;gt; &amp;quot;valid-user&amp;quot;&lt;br /&gt;
        ) )&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Restart the lighttpd server&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
systemctl stop lighttpd&lt;br /&gt;
systemctl start lighttpd&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
I tried it with htdigest but could not get it to protest the directory!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#auth.backend = &amp;quot;htdigest&amp;quot;&lt;br /&gt;
#auth.backend.htdigest.userfile = &amp;quot;/etc/lighttpd/lighttpd.user.htdigest&amp;quot;&lt;br /&gt;
#auth.require = (&lt;br /&gt;
#    &amp;quot;/var/www/cgi-bin/&amp;quot; =&amp;gt; (&lt;br /&gt;
#    &amp;quot;method&amp;quot;  =&amp;gt; &amp;quot;basic&amp;quot;,&lt;br /&gt;
#    &amp;quot;realm&amp;quot;   =&amp;gt; &amp;quot;DbaHawk access&amp;quot;,&lt;br /&gt;
#    &amp;quot;require&amp;quot; =&amp;gt; &amp;quot;valid-user&amp;quot;&lt;br /&gt;
#    ),&lt;br /&gt;
#)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Rename a datafile if the filename contains junk / unprintable characters===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter tablespace ts_thaler_data offline;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Oracle have a document that describes a few ways of doing it in [https://support.oracle.com/rs?type=doc&amp;amp;id=824473.1 Note 824473.1]&lt;br /&gt;
If the filename contains control characters and cannot be selected in the normal way, use ls -ali to find the node number and then use find with -inum to rename (or move) the file&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ls -baltri&lt;br /&gt;
total 47474984&lt;br /&gt;
12409 -rw-r-----    1 oracle   oinstall 1073750016 Sep 26 13:56 ts_thaler_data_02\1776.dbf&lt;br /&gt;
12350 -rw-r-----    1 oracle   oinstall 5242888192 Sep 26 13:56 ts_thaler_data_01.dbf&lt;br /&gt;
&lt;br /&gt;
find . -inum 12409 -exec mv {} ts_thaler_data_06.dbf \;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Work out what the database thinks the name is and rename it there too! AskTom has a discussion on it [https://asktom.oracle.com/pls/apex/asktom.search?tag=rename-datafile-with-dummy-characters-after-dbf here]&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select substr(name,i,1),ascii(substr(name,i,1)) from ( select name from v$datafile where file# = 9), ( select rownum i from dual connect by level &amp;lt;= 50);&lt;br /&gt;
SUBS ASCII(SUBSTR(NAME,I,1))&lt;br /&gt;
---- -----------------------&lt;br /&gt;
t                        116&lt;br /&gt;
s                        115&lt;br /&gt;
_                         95&lt;br /&gt;
t                        116&lt;br /&gt;
h                        104&lt;br /&gt;
a                         97&lt;br /&gt;
l                        108&lt;br /&gt;
e                        101&lt;br /&gt;
r                        114&lt;br /&gt;
_                         95&lt;br /&gt;
d                        100&lt;br /&gt;
a                         97&lt;br /&gt;
t                        116&lt;br /&gt;
a                         97&lt;br /&gt;
_                         95&lt;br /&gt;
0                         48&lt;br /&gt;
2                         50&lt;br /&gt;
                         127&lt;br /&gt;
2                         50&lt;br /&gt;
.                         46&lt;br /&gt;
d                        100&lt;br /&gt;
b                         98&lt;br /&gt;
f                        102&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
You can see there&amp;#039;s a 127 just before the .dbf... this crept in a the backspace key was not working correctly.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set serveroutput on&lt;br /&gt;
declare&lt;br /&gt;
   fname1 varchar2(100);&lt;br /&gt;
   fname2 varchar2(100);&lt;br /&gt;
begin&lt;br /&gt;
  select name into fname1 from v$datafile where file# = 9;&lt;br /&gt;
  fname2 := replace(fname1,chr(127));&lt;br /&gt;
  &lt;br /&gt;
  dbms_output.put_line(&amp;#039;alter database rename file &amp;#039;&amp;#039;&amp;#039;||fname1||&amp;#039;&amp;#039;&amp;#039; to &amp;#039;&amp;#039;&amp;#039;||fname2||&amp;#039;&amp;#039;&amp;#039;&amp;#039;);&lt;br /&gt;
  execute immediate &amp;#039;alter database rename file &amp;#039;&amp;#039;&amp;#039;||fname1||&amp;#039;&amp;#039;&amp;#039; to &amp;#039;&amp;#039;&amp;#039;||fname2||&amp;#039;&amp;#039;&amp;#039;&amp;#039;;&lt;br /&gt;
end;&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
alter tablespace ts_thaler_data_online;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Generate creation of directory names from dba_directories===&lt;br /&gt;
Before deleting or dropping directories in the database, use this script to generate the create statements&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select &amp;#039;create or replace directory &amp;#039;||directory_name||&amp;#039; as &amp;#039;&amp;#039;&amp;#039;||directory_path||&amp;#039;&amp;#039;&amp;#039;;&amp;#039; from dba_directories;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Check if current (dot) directory is in PATH variable===&lt;br /&gt;
Using bareword comparison to check PATH variable&amp;lt;pre&amp;gt;&lt;br /&gt;
if [[ :$PATH: == *:&amp;quot;.&amp;quot;:* ]] ; then&lt;br /&gt;
    echo &amp;quot;in path&amp;quot;&lt;br /&gt;
else&lt;br /&gt;
    echo &amp;quot;not in path&amp;quot;&lt;br /&gt;
fi&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===tail a logfile from within the script you are writing it to===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#&lt;br /&gt;
# display logfile in real time&lt;br /&gt;
#&lt;br /&gt;
( tail -0f ${LOGFILE} ) &amp;amp;&lt;br /&gt;
tailPID=$!&lt;br /&gt;
&lt;br /&gt;
trap &amp;quot;kill $tailPID&amp;quot; 0 1 2 3 5 9 15&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Dump package, procedure etc. from dba_source in a way that it can be used to recreate it===&lt;br /&gt;
From [https://asktom.oracle.com/pls/apex/f?p=100:11:0::::P11_QUESTION_ID:454220160386 Ask Tom]&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 1000 pages 1000 feedb off verif off&lt;br /&gt;
select decode( type||&amp;#039;-&amp;#039;||to_char(line,&amp;#039;fm99999&amp;#039;), &amp;#039;PACKAGE BODY-1&amp;#039;, &amp;#039;/&amp;#039;||chr(10), null) ||&lt;br /&gt;
       decode(line,1,&amp;#039;create or replace &amp;#039;, &amp;#039;&amp;#039; ) ||&lt;br /&gt;
       text text&lt;br /&gt;
from   dba_source&lt;br /&gt;
where  owner = upper(&amp;#039;&amp;amp;owner&amp;#039;)&lt;br /&gt;
and    name  = upper(&amp;#039;&amp;amp;object_to_show&amp;#039;)&lt;br /&gt;
order  by type&lt;br /&gt;
,      line&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===A trick to exit out of SQL*Plus (using divide by zero) depending on answer to a question===&lt;br /&gt;
This example is taken from ReviewLite.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
-- Settings for customized functionality&lt;br /&gt;
define SCRIPT_OO=_OPTIONS_ONLY -- collect only options information&lt;br /&gt;
define SCRIPT_OO=&amp;#039;&amp;#039;            -- collect all information [default behavior]&lt;br /&gt;
&lt;br /&gt;
define SCRIPT_TS=_TIME_STAMP   -- include timestamp in names of the output directory and output files: YYYY.MM.DD.HH24.MI.SS; script does not prompt for license agreement&lt;br /&gt;
define SCRIPT_TS=&amp;#039;\home\oracle\options&amp;#039;            -- standard names for output directory and output files; script prompts for license agreement [default behavior]&lt;br /&gt;
&lt;br /&gt;
-- PROMT FOR LICENSE AGREEMENT ACCEPTANCE&lt;br /&gt;
DEFINE LANSWER=N&lt;br /&gt;
SET TERMOUT ON&lt;br /&gt;
ACCEPT &amp;amp;SCRIPT_TS LANSWER FORMAT A1 PROMPT &amp;#039;Accept License Agreement? (y\n): &amp;#039;&lt;br /&gt;
&lt;br /&gt;
-- FORCE &amp;quot;divisor is equal to zero&amp;quot; AND SQLERROR EXIT IF NOT ACCEPTED&lt;br /&gt;
-- WILL ALSO CONTINUE IF SCRIPT_TS SUBSTITUTION VARIABLE IS NOT NULL&lt;br /&gt;
SET TERMOUT OFF&lt;br /&gt;
WHENEVER SQLERROR EXIT&lt;br /&gt;
select 1/decode(&amp;#039; &amp;amp;LANSWER&amp;#039;, &amp;#039;Y&amp;#039;, null, &amp;#039;y&amp;#039;, null, decode(&amp;#039; &amp;amp;SCRIPT_TS&amp;#039;, null, 0, null)) as &amp;quot; &amp;quot; from dual;&lt;br /&gt;
WHENEVER SQLERROR CONTINUE&lt;br /&gt;
SET TERMOUT ON&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===How to uninstall optional components such as OWB, APEX, EM, OLAP, OWM from an Oracle database===&lt;br /&gt;
* [http://fast-dba.blogspot.be/2014/04/how-to-remove-unwanted-components-from.html fast-dba.blogspot.be]&lt;br /&gt;
&lt;br /&gt;
===Find unique indexes / primary index / key columns in a table===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
col owner       for a12&lt;br /&gt;
col table_name  for a32&lt;br /&gt;
col column_name for a32&lt;br /&gt;
col position    for 99&lt;br /&gt;
col status      for a10&lt;br /&gt;
set lines 1000 pages 100&lt;br /&gt;
&lt;br /&gt;
SELECT cons.owner&lt;br /&gt;
,      cols.table_name&lt;br /&gt;
,      cols.column_name&lt;br /&gt;
,      cols.position&lt;br /&gt;
,      cons.status&lt;br /&gt;
FROM   all_constraints  cons&lt;br /&gt;
,      all_cons_columns cols&lt;br /&gt;
WHERE  1=1&lt;br /&gt;
and    cols.owner           = &amp;#039;&amp;amp;TABLE_OWNER&amp;#039;&lt;br /&gt;
and    cols.table_name      = &amp;#039;&amp;amp;TABLE_NAME&amp;#039;&lt;br /&gt;
AND    cons.constraint_type = &amp;#039;P&amp;#039;&lt;br /&gt;
AND    cons.constraint_name = cols.constraint_name&lt;br /&gt;
AND    cons.owner           = cols.owner&lt;br /&gt;
ORDER  BY cols.table_name&lt;br /&gt;
,      cols.position&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Display the oracle instances running on the local server===&lt;br /&gt;
sed could be shorter but this one works cross-platform&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alias oenv=&amp;#039;ps -ef|grep pmon|grep -v grep|awk -F_ &amp;quot;{print \$NF}&amp;quot;|sort|uniq|sed -e &amp;quot;:a&amp;quot; -e &amp;quot;N&amp;quot; -e &amp;quot;\$!ba&amp;quot; -e &amp;quot;s/\n/ /g&amp;quot;&amp;#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Display which databases are scheduled for backup in cron===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
for i in `ps -ef | grep [o]ra_pmon | awk -F_ &amp;#039;{print $NF}&amp;#039;`; do&lt;br /&gt;
    crontab -l | grep $i | grep backup_export | awk &amp;#039;{print $2&amp;quot;:&amp;quot;$1&amp;quot; - &amp;quot;$17}&amp;#039;&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Trace SQL statements using autotrace and explain plan===&lt;br /&gt;
If the plustrace (plustrc.sql) role has been granted, explaining sql statements (without running the statement) is as easy as&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter session set sql_trace=true;&lt;br /&gt;
set autotrace traceonly explain&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Write to a trace log from PL/SQL===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
dbms_system.ksdwrt(1,&amp;#039;message sent to a trace file&amp;#039;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Invisible / hidden / virtual columns===&lt;br /&gt;
Article showing how to dump blocks also.&amp;lt;br /&amp;gt;&lt;br /&gt;
[https://www.oracle.com/technetwork/articles/database/invisible-columns-odb12c-2331522.html Tips and Tricks: Invisible Columns in Oracle Database 12c by Alex Zaballa, Oracle Ace and Daniel Da Meda (OCM)]&lt;br /&gt;
&lt;br /&gt;
===Write to the alert log from PL/SQL===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
dbms_system.ksdwrt(2,&amp;#039;message sent to the alert log&amp;#039;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Do distributed SQL transactions exist?===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select * from dba_2pc_pending;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
if yes, and to commit them...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select local_tran_id from dba_2pc_pending;&lt;br /&gt;
exec dbms_transaction.purge_lost_db_entry(&amp;#039;&amp;#039;);&lt;br /&gt;
commit;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Setup optional parameters and default values in an SQL*Plus script===&lt;br /&gt;
Some forgotten SQL*Plus tricks from the good old days and some new ones...&lt;br /&gt;
* [http://www.orafaq.com/wiki/SQL*Plus_FAQ#What_is_the_difference_between_.21_and_HOST.3F orafaq.com]&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set termout off&lt;br /&gt;
col p1 new_value 1&lt;br /&gt;
col p2 new_value 2&lt;br /&gt;
col p3 new_value 3&lt;br /&gt;
select null p1, null p2, null p3 from dual where  1=2;&lt;br /&gt;
select nvl(&amp;#039;&amp;amp;1&amp;#039;,&amp;#039;def1&amp;#039;) p1, nvl(&amp;#039;&amp;amp;2&amp;#039;,&amp;#039;def2&amp;#039;) p2, nvl(&amp;#039;&amp;amp;3&amp;#039;,&amp;#039;def3&amp;#039;) p3 from dual;&lt;br /&gt;
set termout on&lt;br /&gt;
prompt 1=&amp;quot;&amp;amp;1&amp;quot;&lt;br /&gt;
prompt 2=&amp;quot;&amp;amp;2&amp;quot;&lt;br /&gt;
prompt 3=&amp;quot;&amp;amp;3&amp;quot;&lt;br /&gt;
undef 1&lt;br /&gt;
undef 2&lt;br /&gt;
undef 3&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Display / show users with sysdba &amp;amp; sysoper privileges===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select * from v$pwfile_users;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Show path names of data files using instr===&lt;br /&gt;
Use to find the pathnames of all the filesystems/directories in which a database is housed.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select distinct substr(name,1,(instr(name,&amp;#039;/&amp;#039;,-1,1)-1)) path_name from v$datafile&lt;br /&gt;
union&lt;br /&gt;
select distinct substr(name,1,(instr(name,&amp;#039;/&amp;#039;,-1,1)-1)) path_name from v$tempfile&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Does a dataguard standby exist for this database?===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SELECT SUBSTR(value,INSTR(value,&amp;#039;=&amp;#039;,INSTR(UPPER(value),&amp;#039;SERVICE&amp;#039;))+1)&lt;br /&gt;
FROM   v$parameter&lt;br /&gt;
WHERE  name LIKE &amp;#039;log_archive_dest%&amp;#039; AND UPPER(value) LIKE &amp;#039;SERVICE%&amp;#039;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
gives something like this if found...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SUBSTR(VALUE,INSTR(VALUE,&amp;#039;=&amp;#039;,INSTR(UPPER(VALUE),&amp;#039;SERVICE&amp;#039;))+1)&lt;br /&gt;
--------------------------------------------------------------------------------&lt;br /&gt;
&amp;quot;jdbeop1_standby&amp;quot;, LGWR ASYNC NOAFFIRM delay=0 optional compression=disable m&lt;br /&gt;
ax_failure=0 max_connections=1 reopen=300 db_unique_name=&amp;quot;jdbeop1_standby&amp;quot; ne&lt;br /&gt;
t_timeout=60, valid_for=(all_logfiles,primary_role)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===List values for all init parameters in v$parameter (including default values for undocumented (hidden) parameters===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select i.ksppinm||&amp;#039;;&amp;#039;||sv.ksppstvl&lt;br /&gt;
from   x$ksppi  i&lt;br /&gt;
,      x$ksppsv sv&lt;br /&gt;
where  i.indx = sv.indx&lt;br /&gt;
order  by i.ksppinm;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Log file reports pipe errors===&lt;br /&gt;
Found these in the log file&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
solax005:root[/opt/IBM/ITM/logs]# tail solax005_or_RMANV11_col.out&lt;br /&gt;
CIR1880E (024955) Open Probe pipe error 2. Pipe=/opt/IBM/ITM/tmp/solax005_or_RMANV11/prb_RMANV11_kor_solax005_30024832_5346_pipe&lt;br /&gt;
CIR1880E (030938) Open Probe pipe error 2. Pipe=/opt/IBM/ITM/tmp/solax005_or_RMANV11/prb_RMANV11_kor_solax005_30030830_5406_pipe&lt;br /&gt;
CIR1880E (031923) Open Probe pipe error 2. Pipe=/opt/IBM/ITM/tmp/solax005_or_RMANV11/prb_RMANV11_kor_solax005_30031832_5434_pipe&lt;br /&gt;
CIR1880E (033934) Open Probe pipe error 2. Pipe=/opt/IBM/ITM/tmp/solax005_or_RMANV11/prb_RMANV11_kor_solax005_30033831_5495_pipe&lt;br /&gt;
CIR1880E (034918) Open Probe pipe error 2. Pipe=/opt/IBM/ITM/tmp/solax005_or_RMANV11/prb_RMANV11_kor_solax005_30034833_5521_pipe&lt;br /&gt;
CIR1880E (041927) Open Probe pipe error 2. Pipe=/opt/IBM/ITM/tmp/solax005_or_RMANV11/prb_RMANV11_kor_solax005_30041835_5610_pipe&lt;br /&gt;
CIR1880E (042931) Open Probe pipe error 2. Pipe=/opt/IBM/ITM/tmp/solax005_or_RMANV11/prb_RMANV11_kor_solax005_30042832_5642_pipe&lt;br /&gt;
CIR1880E (045928) Open Probe pipe error 2. Pipe=/opt/IBM/ITM/tmp/solax005_or_RMANV11/prb_RMANV11_kor_solax005_30045835_5730_pipe&lt;br /&gt;
CIR1880E (052927) Open Probe pipe error 2. Pipe=/opt/IBM/ITM/tmp/solax005_or_RMANV11/prb_RMANV11_kor_solax005_30052838_5819_pipe&lt;br /&gt;
CIR1880E (090929) Open Probe pipe error 2. Pipe=/opt/IBM/ITM/tmp/solax005_or_RMANV11/prb_RMANV11_kor_solax005_30090833_6487_pipe&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This could be due to a timeout on the pipe.&amp;lt;br /&amp;gt;&lt;br /&gt;
Increase parameters and restart agent. Add following lines to or.config:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
export COLL_WAIT_TIMEOUT=&amp;#039;200&amp;#039;&lt;br /&gt;
export WAIT_TIMEOUT=&amp;#039;200&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Find the most recent archived SCN number===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
col next_change# for 999999999999999&lt;br /&gt;
set numwidth 15&lt;br /&gt;
&lt;br /&gt;
select max(next_change#)&lt;br /&gt;
from   v$archived_log&lt;br /&gt;
where  (thread#, next_change#) in ( select thread#, max(next_change#)&lt;br /&gt;
                                    from   v$archived_log&lt;br /&gt;
                                    where  archived     = &amp;#039;YES&amp;#039;&lt;br /&gt;
                                    and    status       = &amp;#039;A&amp;#039;&lt;br /&gt;
                                    and    resetlogs_id = ( select resetlogs_id&lt;br /&gt;
                                                            from   v$database_incarnation&lt;br /&gt;
                                                            where  status = &amp;#039;CURRENT&amp;#039;&lt;br /&gt;
                                                          )&lt;br /&gt;
                                    group by thread#&lt;br /&gt;
                                  )&lt;br /&gt;
and    status = &amp;#039;A&amp;#039;&lt;br /&gt;
and    resetlogs_id = ( select resetlogs_id&lt;br /&gt;
                        from   v$database_incarnation&lt;br /&gt;
                        where  status = &amp;#039;CURRENT&amp;#039;&lt;br /&gt;
                      )&lt;br /&gt;
order  by next_change# asc;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Monitoring says database inactive===&lt;br /&gt;
* Check the candle user password has not expired in the database.&lt;br /&gt;
* There may be a clue in the log file. Check /opt/IBM/ITM/logs/`hostname`_or_${SID}_col.out&lt;br /&gt;
* Check limits for itmora account in /etc/security/limits. Should be same as oracle user.&lt;br /&gt;
* Check the config file. We had this issue when a new ORACLE_HOME was installed but the cfg file still had the old one in it.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
export ITM_HOME=/opt/IBM/ITM&lt;br /&gt;
cd $ITM_HOME/config&lt;br /&gt;
vi solax005_or_SRV2R.cfg&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#  IBM Tivoli Monitoring for Databases: Oracle Agent&lt;br /&gt;
#  Configuration file: solax005_or_SRV2R.cfg&lt;br /&gt;
#  Written by CandleDBconfig version: 1.4 on 31Jul13 13:39:41&lt;br /&gt;
&lt;br /&gt;
#  Note: this is a Korn-shell script that is &amp;quot;sourced&amp;quot; to create the&lt;br /&gt;
#  environment for a Monitoring Agent for Oracle.  It can be used to create&lt;br /&gt;
#  the environment to run the IBM-supplied database grant scripts.&lt;br /&gt;
&lt;br /&gt;
#  IBM does not recommend that you modify this file, but you can change the&lt;br /&gt;
#  data values or add new exported variables as long as the file is a valid ksh&lt;br /&gt;
#  script that executes with zero return code, and values remain quoted with &amp;quot;&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
#  Following environment variables are set for convenience in running grants.&lt;br /&gt;
   export ORACLE_SID=&amp;quot;SRV2R&amp;quot;&lt;br /&gt;
   export ORACLE_HOME=&amp;quot;/oracle/product/11.2.0.1&amp;quot;&lt;br /&gt;
   # IY92195  COLL_DISABLE_CURSORS setting&lt;br /&gt;
   export TNS_ADMIN=&amp;quot;/oracle/product/11.2.0.1/network/admin&amp;quot;&lt;br /&gt;
&lt;br /&gt;
#  Following variables are set for the setup scripts&lt;br /&gt;
   db_sid=&amp;quot;SRV2R&amp;quot;&lt;br /&gt;
   db_home=&amp;quot;/oracle/product/11.2.0.1&amp;quot;&lt;br /&gt;
   db_initfilename=&amp;quot;&amp;quot;&lt;br /&gt;
   db_login=&amp;quot;tivoli&amp;quot;&lt;br /&gt;
   db_password=&amp;quot;795D8822BC49477323815CD21C1E66E966E48EEE19C6A98056224D649B0FE316E6A11DC3F4E9BB5E226B65A8&amp;quot;&lt;br /&gt;
   db_ver=&amp;quot;11.x&amp;quot;&lt;br /&gt;
   db_type=&amp;quot;kor&amp;quot;&lt;br /&gt;
   db_tns=&amp;quot;/oracle/product/11.2.0.1/network/admin&amp;quot;&lt;br /&gt;
   db_extparms=&amp;quot;&amp;quot;&lt;br /&gt;
   db_hostname=&amp;quot;solax005&amp;quot;&lt;br /&gt;
   db_reason=&amp;quot;AIX_ps_ceww&amp;quot;&lt;br /&gt;
   db_pipedir=&amp;quot;&amp;quot;&lt;br /&gt;
   db_installstatus=&amp;quot;CONFIGSUCCESS&amp;quot;&lt;br /&gt;
&lt;br /&gt;
#  User-defined environment variables&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Solution:&amp;lt;br /&amp;gt;&lt;br /&gt;
* Change all occurrences of 11.2.0.1 to 11.2.0.3&lt;br /&gt;
* Restart agent&lt;br /&gt;
&lt;br /&gt;
===Alerts due to password expiring (or being changed in the database but not in ITM!)===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cd $ITM_HOME/logs&lt;br /&gt;
ls -altr | grep WM820T&lt;br /&gt;
tail -20 solax005_or_WM820T_col.out&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
CGN1521E (161614) Interval collection failed for cursor KORHART2&lt;br /&gt;
RCD0110S (161614) Invalid Oracle logon id (tivoli) or password given&lt;br /&gt;
 Please contact DBA to correct userid or password&lt;br /&gt;
CGN1521E (161614) Interval collection failed for cursor KORHART4&lt;br /&gt;
CGN1525E (161614) One or more interval cursors failed&lt;br /&gt;
RCD0110S (161714) Invalid Oracle logon id (tivoli) or password given&lt;br /&gt;
 Please contact DBA to correct userid or password&lt;br /&gt;
CGN1521E (161714) Interval collection failed for cursor KORHART2&lt;br /&gt;
RCD0110S (161714) Invalid Oracle logon id (tivoli) or password given&lt;br /&gt;
 Please contact DBA to correct userid or password&lt;br /&gt;
CGN1521E (161714) Interval collection failed for cursor KORHART4&lt;br /&gt;
CGN1525E (161714) One or more interval cursors failed&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Solution:&amp;lt;br /&amp;gt;&lt;br /&gt;
* Run agent reconfigure to setup the new password for the candle user (tivoli)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
export ITM_HOME=/opt/IBM/ITM&lt;br /&gt;
$ITM_HOME/bin/itmcmd config -A or&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Restart agent&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
export ITM_HOME=/opt/IBM/ITM&lt;br /&gt;
$ITM_HOME/smitools/scripts/StartAgent.sh restart or -o WM820T&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Many agents started with root user instead of itmora===&lt;br /&gt;
This can happen if the server is rebooted before the agents have been added to the itmora list using kdyedit / kciedit&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
export CANDLEHOME=/opt/IBM/ITM&lt;br /&gt;
export ITM_HOME=/opt/IBM/ITM&lt;br /&gt;
$ITM_HOME/smitools/scripts/kdyedit list&lt;br /&gt;
Type Runas      Inst                &lt;br /&gt;
or   root       AGPDEV              &lt;br /&gt;
or   root       BO1R                &lt;br /&gt;
or   root       DEV3                &lt;br /&gt;
or   root       EMREP               &lt;br /&gt;
or   root       ICR                 &lt;br /&gt;
or   itmora     MAPDEV              &lt;br /&gt;
or   itmora     MAPER               &lt;br /&gt;
or   itmora     PED                 &lt;br /&gt;
or   itmora     PER                 &lt;br /&gt;
or   itmora     RMANV11             &lt;br /&gt;
or   itmora     SRV2R               &lt;br /&gt;
or   itmora     WM820Q              &lt;br /&gt;
or   itmora     WM820T              &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ITM_HOME/smitools/scripts/kciedit list&lt;br /&gt;
Type Runas      Inst                &lt;br /&gt;
or   root       AGPDEV              &lt;br /&gt;
or   root       BO1R                &lt;br /&gt;
or   root       DEV3                &lt;br /&gt;
or   root       EMREP               &lt;br /&gt;
or   root       ICR                 &lt;br /&gt;
or   itmora     MAPDEV              &lt;br /&gt;
or   itmora     MAPER               &lt;br /&gt;
or   itmora     PED                 &lt;br /&gt;
or   itmora     PER                 &lt;br /&gt;
or   itmora     RMANV11             &lt;br /&gt;
or   itmora     SRV2R               &lt;br /&gt;
or   itmora     WM820Q              &lt;br /&gt;
or   itmora     WM820T              &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Solution: Add these instances to the itmora list&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
./kdyedit -t or -i AGPDEV -r itmora add&lt;br /&gt;
./kciedit -t or -i AGPDEV -r itmora add&lt;br /&gt;
...&lt;br /&gt;
./kdyedit -t or -i ICR -r itmora add&lt;br /&gt;
./kciedit -t or -i ICR -r itmora add&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ITM_HOME/smitools/scripts/kciedit list&lt;br /&gt;
Type Runas      Inst                &lt;br /&gt;
or   itmora     AGPDEV              &lt;br /&gt;
or   itmora     BO1R                &lt;br /&gt;
or   itmora     DEV3                &lt;br /&gt;
or   itmora     EMREP               &lt;br /&gt;
or   itmora     ICR                 &lt;br /&gt;
or   itmora     MAPDEV              &lt;br /&gt;
or   itmora     MAPER               &lt;br /&gt;
or   itmora     PED                 &lt;br /&gt;
or   itmora     PER                 &lt;br /&gt;
or   itmora     RMANV11             &lt;br /&gt;
or   itmora     SRV2R               &lt;br /&gt;
or   itmora     WM820Q              &lt;br /&gt;
or   itmora     WM820T              &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Kill any agents still running as root&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ps -ef |grep kor | grep root&lt;br /&gt;
kill -9 &amp;lt;process id&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Because these agents were owned by root, there will be permissions issues when trying to restart the agents with itmora so these need to be fixed before restarting the agents.&amp;lt;br /&amp;gt;&lt;br /&gt;
The simplest way of doing this is to run lockdown.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
export CANDLEHOME=/opt/IBM/ITM&lt;br /&gt;
$CANDLEHOME/smitools/scripts/lockdown.sh&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===See which processes are causing paging===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
svmon -Pt20 | perl -e &amp;#039;while(&amp;lt;&amp;gt;){print if($.==2||$&amp;amp;&amp;amp;&amp;amp;!$s++);$.=0 if(/^-+$/)}&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===How to return several variables from SQL*Plus back to Korn shell script===&lt;br /&gt;
Return multiple columns/elements from Oracle to shell script at the same time&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sqlplus -s sys/${SYS_PASSWORD}@${SID} as sysdba&amp;lt;&amp;lt;EOSQL | read SPACE_AFTER_INSTALL TOTAL_SPACE_AVAILABLE&lt;br /&gt;
set numwid 15 headi off newpa none feedb off&lt;br /&gt;
select sign(${SPACE_USED} + ${SPACE_AVAILABLE} - ${DATABASE_SIZE}), trim(${SPACE_USED} + ${SPACE_AVAILABLE})&lt;br /&gt;
from dual&lt;br /&gt;
/&lt;br /&gt;
EOSQL&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===How to get a shell environment variable from the operating system into the SQL or PL/SQL environment===&lt;br /&gt;
This has been bugging me for years. Something you would think simple... what is ORACLE_HOME? I know it&amp;#039;s a question mark at the SQL prompt but how to get it&amp;#039;s O/S value?&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
declare&lt;br /&gt;
    var1 varchar2(200);&lt;br /&gt;
begin&lt;br /&gt;
    dbms_system.get_env (&amp;#039;ORACLE_HOME&amp;#039;, var1);&lt;br /&gt;
    dbms_output.put_line (&amp;#039;ORACLE_HOME: &amp;#039;||var1);&lt;br /&gt;
end;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or in SQL*Plus&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
variable var1 varchar2(200);&lt;br /&gt;
exec dbms_system.get_env (&amp;#039;ORACLE_HOME&amp;#039;, :var1);&lt;br /&gt;
select :var1 from dual;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
That got me thinking... if this just gets stuff from the environment, it can fetch any exported variable?!?!&amp;lt;br /&amp;gt;&lt;br /&gt;
From the shell:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
export running_sids=`ps -ef | grep [p]mon | awk -F_ &amp;#039;{print $NF}&amp;#039;`&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
and now in SQL*Plus:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
variable sids varchar2(240);&lt;br /&gt;
exec dbms_system.get_env (&amp;#039;running_sids&amp;#039;, :sids);&lt;br /&gt;
select :sids from dual;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Wow!&lt;br /&gt;
&lt;br /&gt;
===How long/wide can a database name/sid be?===&lt;br /&gt;
Depends on where you look but taking the minimum here as &amp;quot;safe&amp;quot;, it should still be limited to 8 characters...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
col table_name for a30&lt;br /&gt;
col data_type  for a12&lt;br /&gt;
select table_name, data_type, data_length from dba_tab_columns where column_name = &amp;#039;DB_NAME&amp;#039;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This is 11gR2&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
TABLE_NAME                     DATA_TYPE    DATA_LENGTH&lt;br /&gt;
------------------------------ ------------ -----------&lt;br /&gt;
LOGMNRG_DICTIONARY$            VARCHAR2               9&lt;br /&gt;
SYS_FBA_CONTEXT_AUD            VARCHAR2             256&lt;br /&gt;
V_$LOGMNR_DICTIONARY           VARCHAR2               9&lt;br /&gt;
V_$LOGMNR_LOGS                 VARCHAR2               8&lt;br /&gt;
GV_$LOGMNR_DICTIONARY          VARCHAR2               9&lt;br /&gt;
GV_$LOGMNR_LOGS                VARCHAR2               8&lt;br /&gt;
V_$LOGMNR_LOGFILE              VARCHAR2               8&lt;br /&gt;
V_$LOGMNR_SESSION              VARCHAR2             128&lt;br /&gt;
GV_$LOGMNR_LOGFILE             VARCHAR2               8&lt;br /&gt;
GV_$LOGMNR_SESSION             VARCHAR2             128&lt;br /&gt;
GV_$ASM_CLIENT                 VARCHAR2               8&lt;br /&gt;
V_$ASM_CLIENT                  VARCHAR2               8&lt;br /&gt;
GV_$IOS_CLIENT                 VARCHAR2              64&lt;br /&gt;
V_$IOS_CLIENT                  VARCHAR2              64&lt;br /&gt;
DBA_PDB_HISTORY                VARCHAR2             128&lt;br /&gt;
CDB_PDB_HISTORY                VARCHAR2             128&lt;br /&gt;
SSCR_CAP$                      VARCHAR2            4000&lt;br /&gt;
SSCR_RES$                      VARCHAR2            4000&lt;br /&gt;
DBA_SSCR_CAPTURE               VARCHAR2            4000&lt;br /&gt;
CDB_SSCR_CAPTURE               VARCHAR2            4000&lt;br /&gt;
DBA_SSCR_RESTORE               VARCHAR2            4000&lt;br /&gt;
CDB_SSCR_RESTORE               VARCHAR2            4000&lt;br /&gt;
WRM$_DATABASE_INSTANCE         VARCHAR2               9&lt;br /&gt;
INT$DBA_HIST_DATABASE_INSTANCE VARCHAR2               9&lt;br /&gt;
DBA_HIST_DATABASE_INSTANCE     VARCHAR2               9&lt;br /&gt;
CDB_HIST_DATABASE_INSTANCE     VARCHAR2               9&lt;br /&gt;
LOGMNR_DICTIONARY$             VARCHAR2               9&lt;br /&gt;
&lt;br /&gt;
27 rows selected.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===What character set (characterset) was the database built with?===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
col name  for a40&lt;br /&gt;
col value for a60&lt;br /&gt;
select * from nls_database_parameters;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
col name   for a40&lt;br /&gt;
col value$ for a60&lt;br /&gt;
select name,value$ from props$ where name = &amp;#039;NLS_CHARACTERSET&amp;#039;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===How to find ORACLE_HOME from pmon process for a SID if there is no entry in oratab===&lt;br /&gt;
If database is created without dbca (datafile and controlfile copy), no entry will be automatically made in /etc/oratab.&amp;lt;br /&amp;gt;&lt;br /&gt;
So the problem is that you need to find out which of the ORACLE_HOMEs is being used by the running instances.&lt;br /&gt;
* Solaris, Linux&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ ps -ef | grep [p]mon&lt;br /&gt;
  oracle 10848     1   0 00:21:20 ?           2:11 ora_pmon_JDBEOP1&lt;br /&gt;
$ pwdx 10848&lt;br /&gt;
10848:  /oracle/JDBEOP1/product/11204/dbs&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* AIX&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ ps -ef | grep [p]mon&lt;br /&gt;
  oracle 13893878        1   0   Aug 12      -  7:53 ora_pmon_GOAQ1&lt;br /&gt;
$ ls -al /proc/13893878/cwd&lt;br /&gt;
lr-x------    2 oracle   dba               0 Aug 12 13:37  cwd -&amp;gt; /data/opt/app/product/11.2.0.4/db_1/dbs/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or&amp;lt;br /&amp;gt;&lt;br /&gt;
This command (ps eww) gives lots of information about the given process (pmon in this case). Tells you where the instance was started, whether it was started from SQL*Plus or RMAN, the http_proxy and loads more useful bits!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ps -ef | grep [p]mon | awk &amp;#039;{print $2}&amp;#039; | xargs -I {} ps eww {} | awk &amp;#039;{print $1 &amp;quot; &amp;quot; $5 &amp;quot; &amp;quot; $6 &amp;quot; &amp;quot; $0}&amp;#039; | sed &amp;#039;s/\(S*\) \(S*\) .*ORACLE_HOME/\1 \2/g&amp;#039; | cut -f1,2,3 -d&amp;quot; &amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Escape the underscore(_) or percent(%) character in an SQL statement===&lt;br /&gt;
The underscore matches any single character so to return data containing an underscore means having to use an escape character.&amp;lt;br /&amp;gt;&lt;br /&gt;
Here I use the backslash(\) so it is easy for Unix people to understand the mechanism.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select username from dba_users where username like &amp;#039;ENDUR\_DEV%&amp;#039; escape &amp;#039;\&amp;#039;; &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Validate, analyse and rebuild indexes===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set feedback off&lt;br /&gt;
set linesize 132&lt;br /&gt;
set serveroutput on&lt;br /&gt;
set trimspool on&lt;br /&gt;
&lt;br /&gt;
declare&lt;br /&gt;
    LOCKED exception;&lt;br /&gt;
    pragma exception_init (LOCKED, -54);&lt;br /&gt;
&lt;br /&gt;
    dbase         char(8);&lt;br /&gt;
    dbuser        varchar2(30);&lt;br /&gt;
    index_name    varchar(30);&lt;br /&gt;
    free_text     varchar2(50);&lt;br /&gt;
    pctused       number;&lt;br /&gt;
    height    number;&lt;br /&gt;
    index_mb      number;&lt;br /&gt;
    analyze_sql   varchar2(100);&lt;br /&gt;
    pct_used_sql  varchar2(150);&lt;br /&gt;
    rebuild_sql   varchar2(150);&lt;br /&gt;
 &lt;br /&gt;
    cursor c1 is&lt;br /&gt;
    select segment_name, bytes&lt;br /&gt;
    from   user_segments&lt;br /&gt;
    where  segment_type = &amp;#039;INDEX&amp;#039;&lt;br /&gt;
    and    segment_name like &amp;#039;DW%&amp;#039;&lt;br /&gt;
    and    segment_name not like &amp;#039;BIN%&amp;#039;&lt;br /&gt;
    and    bytes/1024   &amp;gt;= 1024&lt;br /&gt;
    order  by 2;&lt;br /&gt;
&lt;br /&gt;
-- validate the index&lt;br /&gt;
procedure validate_index (v_ind in varchar2) is&lt;br /&gt;
begin&lt;br /&gt;
    analyze_sql := &amp;#039;analyze index &amp;#039;||v_ind||&amp;#039; validate structure&amp;#039;;&lt;br /&gt;
    begin&lt;br /&gt;
        execute immediate analyze_sql;&lt;br /&gt;
    exception&lt;br /&gt;
    when LOCKED then&lt;br /&gt;
        dbms_output.put_line (v_ind||&amp;#039; locked - skipping&amp;#039;);&lt;br /&gt;
        pctused := 100;&lt;br /&gt;
        return;&lt;br /&gt;
    when others then&lt;br /&gt;
        dbms_output.put_line (analyze_sql);&lt;br /&gt;
        raise;&lt;br /&gt;
    end;&lt;br /&gt;
&lt;br /&gt;
    pct_used_sql := &amp;#039;select pct_used, round(blocks*8192/(1024*1024)), height from index_stats where name = &amp;#039;&amp;#039;&amp;#039;||v_ind||&amp;#039;&amp;#039;&amp;#039;&amp;#039;;&lt;br /&gt;
    execute immediate pct_used_sql into pctused, index_mb, height;&lt;br /&gt;
    if pctused is null then&lt;br /&gt;
        pctused := 0;&lt;br /&gt;
    end if;&lt;br /&gt;
    dbms_output.put_line (rpad(v_ind,35)||&amp;#039; (pct used &amp;#039;||pctused||&amp;#039;% size &amp;#039;||index_mb||&amp;#039;Mb height &amp;#039; || height ||&amp;#039;)&amp;#039;);&lt;br /&gt;
end validate_index;&lt;br /&gt;
 &lt;br /&gt;
-- execute SQL and trace if errors&lt;br /&gt;
procedure run_sql (v_sql in varchar2) is&lt;br /&gt;
begin&lt;br /&gt;
    execute immediate v_sql;&lt;br /&gt;
exception&lt;br /&gt;
when others then&lt;br /&gt;
    dbms_output.put_line (v_sql);&lt;br /&gt;
    raise;&lt;br /&gt;
end run_sql;&lt;br /&gt;
 &lt;br /&gt;
--&lt;br /&gt;
-- Script starts here&lt;br /&gt;
--&lt;br /&gt;
begin&lt;br /&gt;
    dbms_output.enable(1000000);&lt;br /&gt;
    -- Set up database name and schema&lt;br /&gt;
    -- select name into dbase  from v$database;&lt;br /&gt;
    select user into dbuser from dual;&lt;br /&gt;
    dbms_output.put_line(&amp;#039;============================================================================= *&amp;#039;);&lt;br /&gt;
    -- dbms_output.put_line(&amp;#039;* Indexes rebuild report for &amp;#039;||dbuser||&amp;#039; on &amp;#039;||dbase);&lt;br /&gt;
    dbms_output.put_line(&amp;#039;============================================================================= *&amp;#039;);&lt;br /&gt;
&lt;br /&gt;
    -- Loop around Indexes&lt;br /&gt;
    for x in c1 loop&lt;br /&gt;
        index_name := x.segment_name;&lt;br /&gt;
        validate_index (index_name );&lt;br /&gt;
        if pctused &amp;lt; 81 then&lt;br /&gt;
            if x.bytes/1024/1024 &amp;lt; 100 then&lt;br /&gt;
                rebuild_sql := &amp;#039;alter index &amp;#039;||x.segment_name||&amp;#039; rebuild online&amp;#039;;&lt;br /&gt;
            else&lt;br /&gt;
                rebuild_sql := &amp;#039;alter index &amp;#039;||x.segment_name||&amp;#039; coalesce&amp;#039;;&lt;br /&gt;
            end if;&lt;br /&gt;
            dbms_output.put_line (rebuild_sql);&lt;br /&gt;
            run_sql (rebuild_sql);&lt;br /&gt;
            validate_index (index_name);&lt;br /&gt;
        end if;&lt;br /&gt;
    end loop;&lt;br /&gt;
end;&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
set feed on&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Rebuild unusable indexes on a table===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select &amp;#039;alter index &amp;#039;||owner||&amp;#039;.&amp;#039;||index_name||&amp;#039; rebuild;&amp;#039;&lt;br /&gt;
from   dba_indexes&lt;br /&gt;
where  1=1&lt;br /&gt;
and    status    != &amp;#039;VALID&amp;#039;&lt;br /&gt;
and    owner     not in (&amp;#039;SYS&amp;#039;,&amp;#039;SYSTEM&amp;#039;)&lt;br /&gt;
--and    owner      = &amp;#039;WM822PP&amp;#039;&lt;br /&gt;
--and    table_name = &amp;#039;WF_PLANTS&amp;#039;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Pull the latest cfengine changes now instead of waiting for scheduled time===&lt;br /&gt;
For one host&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/opt/cfengine/bin/cfagent -ID dbaTime&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
On all hosts at the same time&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/home/ibmtools/scripts/oracle/dosh -c &amp;quot;/opt/cfengine/bin/cfagent -ID dbaTime&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Check status of datafiles without dba_data_files or v$datafile===&lt;br /&gt;
If the database is in mount mode, most tables are unavailable. This query uses the x$ (c based) tables and are always available&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set linesize 200;&lt;br /&gt;
set pagesize 100;&lt;br /&gt;
col inst_id for 9999999 heading &amp;#039;Instance #&amp;#039;&lt;br /&gt;
col file_nr for 9999999 heading &amp;#039;File #&amp;#039;&lt;br /&gt;
col file_name for A50 heading &amp;#039;File name&amp;#039;&lt;br /&gt;
col checkpoint_change_nr for 99999999999999 heading &amp;#039;Checkpoint #&amp;#039;&lt;br /&gt;
col checkpoint_change_time for A20 heading &amp;#039;Checkpoint time&amp;#039;&lt;br /&gt;
col last_change_nr for 99999999999999 heading &amp;#039;Last change #&amp;#039;&lt;br /&gt;
SELECT&lt;br /&gt;
      fe.inst_id,&lt;br /&gt;
      fe.fenum file_nr,&lt;br /&gt;
      fn.fnnam file_name,&lt;br /&gt;
      TO_NUMBER (fe.fecps) checkpoint_change_nr,&lt;br /&gt;
      fe.fecpt checkpoint_change_time,&lt;br /&gt;
      fe.fests last_change_nr,&lt;br /&gt;
      DECODE (&lt;br /&gt;
              fe.fetsn,&lt;br /&gt;
              0, DECODE (BITAND (fe.festa, 2), 0, &amp;#039;SYSOFF&amp;#039;, &amp;#039;SYSTEM&amp;#039;),&lt;br /&gt;
              DECODE (BITAND (fe.festa, 18),&lt;br /&gt;
                      0, &amp;#039;OFFLINE&amp;#039;,&lt;br /&gt;
                      2, &amp;#039;ONLINE&amp;#039;,&lt;br /&gt;
                      &amp;#039;RECOVER&amp;#039;)&lt;br /&gt;
      ) status&lt;br /&gt;
FROM x$kccfe fe,&lt;br /&gt;
     x$kccfn fn&lt;br /&gt;
WHERE    (   (fe.fepax != 65535 AND fe.fepax != 0 )&lt;br /&gt;
          OR (fe.fepax = 65535 OR fe.fepax = 0)&lt;br /&gt;
         )&lt;br /&gt;
     AND fn.fnfno = fe.fenum&lt;br /&gt;
     AND fe.fefnh = fn.fnnum&lt;br /&gt;
     AND fe.fedup != 0&lt;br /&gt;
     AND fn.fntyp = 4&lt;br /&gt;
     AND fn.fnnam IS NOT NULL&lt;br /&gt;
     AND BITAND (fn.fnflg, 4) != 4&lt;br /&gt;
ORDER BY fe.fenum&lt;br /&gt;
;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Check highest allocated extent in datafile (likely slow when having many extents)===&lt;br /&gt;
* Script to Detect Tablespace Fragmentation ( Doc ID 1020182.6 )&lt;br /&gt;
* How to shrink or reduce the datafile size by finding the high water mark (HWM) ( Doc ID 1600774.1 )&lt;br /&gt;
* How to find Objects Fragmented below High Water Mark ( Doc ID 337651.1 )&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
column file_name format a50;&lt;br /&gt;
column tablespace_name format a15;&lt;br /&gt;
column highwater format 9999999999;&lt;br /&gt;
set pagesize 9999&lt;br /&gt;
&lt;br /&gt;
select a.tablespace_name&lt;br /&gt;
,a.file_name&lt;br /&gt;
,(b.maximum+c.blocks-1)*d.db_block_size highwater&lt;br /&gt;
from dba_data_files a&lt;br /&gt;
,(select file_id,max(block_id) maximum&lt;br /&gt;
from dba_extents&lt;br /&gt;
group by file_id) b&lt;br /&gt;
,dba_extents c&lt;br /&gt;
,(select value db_block_size&lt;br /&gt;
from v$parameter&lt;br /&gt;
where name=&amp;#039;db_block_size&amp;#039;) d&lt;br /&gt;
where a.file_id = b.file_id&lt;br /&gt;
and c.file_id = b.file_id&lt;br /&gt;
and c.block_id = b.maximum&lt;br /&gt;
order by a.tablespace_name,a.file_name&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Runup to this was...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set markup html on spool on&lt;br /&gt;
spool db_info.html&lt;br /&gt;
set echo on&lt;br /&gt;
select * from dba_tablespaces where tablespace_name = &amp;#039;&amp;amp;&amp;amp;tablespace_name&amp;#039;;&lt;br /&gt;
select * from dba_data_files where tablespace_name = &amp;#039;&amp;amp;tablespace_name&amp;#039;;&lt;br /&gt;
select * from (select * from dba_extents where tablespace_name = &amp;#039;&amp;amp;tablespace_name&amp;#039; order by block_id desc) where rownum &amp;lt;301;&lt;br /&gt;
spool off&lt;br /&gt;
set markup html off&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select owner, segment_type, count(*) from dba_segments where tablesapce_name=&amp;#039;&amp;amp;tablespace_name&amp;#039; group by owner, segment_type;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
begin&lt;br /&gt;
for ii in (select owner, segment_name, segment_type from dba_segments where tablespace_name = &amp;#039;&amp;amp;tablespace_name&amp;#039; and segment_type like &amp;#039;TABLE%&amp;#039; and segment_name not like &amp;#039;%DATAPUMP%&amp;#039;)&lt;br /&gt;
loop&lt;br /&gt;
if ii.segment_type=&amp;#039;TABLE&amp;#039; then&lt;br /&gt;
begin&lt;br /&gt;
execute immediate(&amp;#039;alter table &amp;#039;||ii.owner||&amp;#039;.&amp;#039;||ii.segment_name||&amp;#039; enable row movement&amp;#039;);&lt;br /&gt;
execute immediate(&amp;#039;alter table &amp;#039;||ii.owner||&amp;#039;.&amp;#039;||ii.segment_name||&amp;#039; shrink space cascade&amp;#039;);&lt;br /&gt;
exception when others then&lt;br /&gt;
dbms_output.put_line(&amp;#039;FAILED 1: alter table &amp;#039;||ii.owner||&amp;#039;.&amp;#039;||ii.segment_name||&amp;#039; shrink space cascade : &amp;#039;||SQLERRM);&lt;br /&gt;
end;&lt;br /&gt;
end if;&lt;br /&gt;
end loop;&lt;br /&gt;
end;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Procedure to shrink space in tables and indexes===&lt;br /&gt;
* [http://www.oracle-wiki.net/startdocsreallifeshrinkexample Using the Oracle Shrink Command] - lots of good stuff at this site&lt;br /&gt;
Written by [https://asktom.oracle.com/pls/apex/f%3Fp%3D100:11:0::::P11_QUESTION_ID:5645095700346948864 Tom Kyte]&amp;lt;br /&amp;gt;&lt;br /&gt;
Depending on the Oracle version, this procedure may or may not work! It does not include the compact clause (neither does it re-analyse to prove it worked).&amp;lt;br /&amp;gt;&lt;br /&gt;
[http://www.oracle-wiki.net/startdocsreallifeshrinkexample Here] is a worked example that shows the complete process - oracle-wiki.net&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
create or replace procedure shrink_all&lt;br /&gt;
as&lt;br /&gt;
    l_sql        varchar2(4000);&lt;br /&gt;
    l_sql2       varchar2(4000);&lt;br /&gt;
    row_movement exception;&lt;br /&gt;
    pragma       exception_init( row_movement, -10636 );&lt;br /&gt;
begin&lt;br /&gt;
    for x in (select table_name&lt;br /&gt;
              ,      owner&lt;br /&gt;
              from   t&lt;br /&gt;
              where  sgm_space_management = &amp;#039;AUTO&amp;#039;)&lt;br /&gt;
    loop&lt;br /&gt;
        l_sql := &amp;#039;alter table &amp;quot;&amp;#039; || x.owner || &amp;#039;&amp;quot;.&amp;quot;&amp;#039; || x.table_name || &amp;#039;&amp;quot; shrink space&amp;#039;;&lt;br /&gt;
        dbms_output.put_line( l_sql );&lt;br /&gt;
&lt;br /&gt;
        begin&lt;br /&gt;
            execute immediate l_sql;&lt;br /&gt;
        exception&lt;br /&gt;
        when row_movement&lt;br /&gt;
        then&lt;br /&gt;
            dbms_output.put_line( &amp;#039;failed due to row movement...&amp;#039; );&lt;br /&gt;
            l_sql2 := &amp;#039;alter table &amp;quot;&amp;#039; || x.owner || &amp;#039;&amp;quot;.&amp;quot;&amp;#039; || x.table_name || &amp;#039;&amp;quot; enable row movement&amp;#039;;&lt;br /&gt;
            dbms_output.put_line( l_sql2 );&lt;br /&gt;
            execute immediate l_sql2;&lt;br /&gt;
            dbms_output.put_line( l_sql );&lt;br /&gt;
            execute immediate l_sql;&lt;br /&gt;
        end;&lt;br /&gt;
&lt;br /&gt;
        for y in (select owner&lt;br /&gt;
                  ,      index_name&lt;br /&gt;
                  from   dba_indexes&lt;br /&gt;
                  where  table_owner = x.owner&lt;br /&gt;
                  and    table_name  = x.table_name )&lt;br /&gt;
        loop&lt;br /&gt;
            l_sql := &amp;#039;alter index &amp;quot;&amp;#039; || y.owner || &amp;#039;&amp;quot;.&amp;quot;&amp;#039; || y.index_name || &amp;#039;&amp;quot; shrink space&amp;#039;;&lt;br /&gt;
            dbms_output.put_line( l_sql );&lt;br /&gt;
            execute immediate l_sql;&lt;br /&gt;
        end loop;&lt;br /&gt;
&lt;br /&gt;
    end loop;&lt;br /&gt;
end;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===How to delete/kill a distributed transaction===&lt;br /&gt;
From [http://www.pouwiel.com/?p=2204 pouwiel.com]&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SQL&amp;gt; SELECT LOCAL_TRAN_ID, GLOBAL_TRAN_ID,to_char(FAIL_TIME,&amp;#039;dd-mon-yyyy HH24:MI:SS&amp;#039;),STATE, MIXED FROM DBA_2PC_PENDING;&lt;br /&gt;
&lt;br /&gt;
LOCAL_TRAN_ID&lt;br /&gt;
----------------------&lt;br /&gt;
GLOBAL_TRAN_ID&lt;br /&gt;
--------------------------------------------------------------------------------&lt;br /&gt;
TO_CHAR(FAIL_TIME,&amp;#039;D STATE MIX&lt;br /&gt;
-------------------- ---------------- ---&lt;br /&gt;
8.19.321913&lt;br /&gt;
1463898948.0000013CDE8005110000000179F68840A089FFFEE644B640AED6B02438B2F39D9665F&lt;br /&gt;
AFB&lt;br /&gt;
15-feb-2013 16:37:41 prepared no&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
SQL&amp;gt; SELECT LOCAL_TRAN_ID, IN_OUT,INTERFACE, DATABASE FROM DBA_2PC_NEIGHBORS;&lt;br /&gt;
&lt;br /&gt;
LOCAL_TRAN_ID IN_ I&lt;br /&gt;
---------------------- --- -&lt;br /&gt;
DATABASE&lt;br /&gt;
--------------------------------------------------------------------------------&lt;br /&gt;
8.19.321913 in N&lt;br /&gt;
jdbc_11&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
SQL&amp;gt; rollback force &amp;#039;8.19.321913&amp;#039;;&lt;br /&gt;
&lt;br /&gt;
Rollback complete.&lt;br /&gt;
&lt;br /&gt;
SQL&amp;gt; execute dbms_transaction.purge_lost_db_entry(&amp;#039;8.19.321913&amp;#039;);&lt;br /&gt;
&lt;br /&gt;
PL/SQL procedure successfully completed.&lt;br /&gt;
&lt;br /&gt;
SQL&amp;gt; commit;&lt;br /&gt;
&lt;br /&gt;
Commit complete.&lt;br /&gt;
&lt;br /&gt;
SQL&amp;gt; SELECT LOCAL_TRAN_ID, GLOBAL_TRAN_ID,to_char(FAIL_TIME,&amp;#039;dd-mon-yyyy HH24:MI:SS&amp;#039;),STATE, MIXED FROM DBA_2PC_PENDING;&lt;br /&gt;
&lt;br /&gt;
no rows selected&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Be aware that the support document 159377.1 does not speak of the rollback force. If you don’t execute that particular command it will not work.&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORACLE_BASE is getting set to the same value as ORACLE_HOME when using . oraenv===&lt;br /&gt;
Permissions problem. Make sure the user has &amp;#039;&amp;#039;&amp;#039;write&amp;#039;&amp;#039;&amp;#039; access to oraclehomeproperties.xml file!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ls -al $ORACLE_HOME/inventory/ContentsXML/oraclehomeproperties.xml&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Change permissions as appropriate.&lt;br /&gt;
A different approach which should give the same end result would be to grant the orabase executable the setuid bit.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
chmod u+s $ORACLE_HOME/bin/orabase&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This allows any user to set the environment as the orabase executable will be run with the permissions of its owner.&lt;br /&gt;
===Move table partitions to a different tablespace===&lt;br /&gt;
Are you getting errors due to partitions belonging to a different tablespace and you want to drop the current tablepace?&amp;lt;br /&amp;gt;&lt;br /&gt;
ORA-14404: partitioned table contains partitions in a different tablespace&amp;lt;br /&amp;gt;&lt;br /&gt;
====Find tables with partitions in more than one tablespace====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 2000 pages 50&lt;br /&gt;
col table_owner for a30&lt;br /&gt;
col table_name for a30&lt;br /&gt;
select table_owner&lt;br /&gt;
 ,     table_name&lt;br /&gt;
,      count(*)&lt;br /&gt;
from   dba_tab_partitions&lt;br /&gt;
where  table_owner != &amp;#039;SYS&amp;#039;&lt;br /&gt;
group  by table_owner&lt;br /&gt;
,      table_name&lt;br /&gt;
having count(*) &amp;gt; 1&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
See which tables have partitions across multiple tablespaces...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 1000 pages 100&lt;br /&gt;
col table_name for a50&lt;br /&gt;
select distinct b.table_owner||&amp;#039;.&amp;#039;||b.table_name table_name&lt;br /&gt;
,      a.tablespace_name ts1&lt;br /&gt;
,      b.tablespace_name ts2&lt;br /&gt;
from   (&lt;br /&gt;
       select distinct tablespace_name&lt;br /&gt;
       ,      table_name&lt;br /&gt;
       ,      partition_name&lt;br /&gt;
       from   dba_tab_partitions&lt;br /&gt;
       )                  a&lt;br /&gt;
,      dba_tab_partitions b&lt;br /&gt;
where  a.table_name       = b.table_name&lt;br /&gt;
and    a.tablespace_name != b.tablespace_name&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Generate statements to move the partitions from one tablespace to another...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select &amp;#039;alter table &amp;#039;||b.table_owner||&amp;#039;.&amp;#039;||b.table_name||&amp;#039; move partition &amp;#039;||b.partition_name||&amp;#039; tablespace &amp;amp;NEW_TABLESPACE;&amp;#039;&lt;br /&gt;
from   (&lt;br /&gt;
       select distinct table_name&lt;br /&gt;
       ,      partition_name&lt;br /&gt;
       from   dba_tab_partitions&lt;br /&gt;
       where  tablespace_name = &amp;#039;&amp;amp;&amp;amp;OLD_TABLESPACE&amp;#039;&lt;br /&gt;
       )                  a&lt;br /&gt;
,      dba_tab_partitions b&lt;br /&gt;
where  a.table_name       = b.table_name&lt;br /&gt;
and    b.tablespace_name != &amp;#039;&amp;amp;OLD_TABLESPACE&amp;#039;&lt;br /&gt;
/&lt;br /&gt;
undef OLD_TABLESPACE&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====What&amp;#039;s left hanging around?====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
col SEGMENT_TYPE for a20&lt;br /&gt;
col OWNER for a20&lt;br /&gt;
col SEGMENT_NAME for a40&lt;br /&gt;
col PARTITION_NAME for a15&lt;br /&gt;
col TABLESPACE_NAME for a30&lt;br /&gt;
select segment_type&lt;br /&gt;
,      owner&lt;br /&gt;
,      segment_name&lt;br /&gt;
,      partition_name&lt;br /&gt;
,      tablespace_name&lt;br /&gt;
from   dba_segments&lt;br /&gt;
where  tablespace_name in (&amp;#039;TS_THALER_IOT_OLD&amp;#039;,&amp;#039;TS_THALER_CU&amp;#039;,&amp;#039;TS_THALER_BACKUP&amp;#039;,&amp;#039;TS_THALER_PART_OLD&amp;#039;)&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
select table_owner&lt;br /&gt;
,      table_name&lt;br /&gt;
from   dba_indexes&lt;br /&gt;
where  index_name = &amp;#039;&amp;amp;index_name&amp;#039;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===What edition is my database (Standard, Enterprise, XE...)?===&lt;br /&gt;
Only works from 12c :-(&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select edition from sys.registry$ where cid=&amp;#039;CATPROC&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Is database a CDB with PDBs?===&lt;br /&gt;
Needs a bit of work. Won&amp;#039;t work pre-12c obviously and also not on Standby databases if they are in MOUNT mode&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
for db in $(ps -ef | grep [p]mon|awk -F_ &amp;#039;{print $NF}&amp;#039;)&lt;br /&gt;
do&lt;br /&gt;
    export ORACLE_SID=${db}&lt;br /&gt;
    ORAENV_ASK=NO&lt;br /&gt;
    . oraenv &amp;gt;/dev/null 2&amp;gt;&amp;amp;1&lt;br /&gt;
    sqlplus -s / as sysdba&amp;lt;&amp;lt;&amp;#039;EOSQL&amp;#039;&lt;br /&gt;
set head off newpa none&lt;br /&gt;
select name&lt;br /&gt;
,      (select count(*) from v$pdbs) npdbs&lt;br /&gt;
from   v$database&lt;br /&gt;
/&lt;br /&gt;
EOSQL&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
version 2&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
function is_db_cdb return boolean&lt;br /&gt;
is&lt;br /&gt;
    b_is_cdb        boolean := false;&lt;br /&gt;
    l_is_cdb        varchar2(3) := &amp;#039;NO&amp;#039;;&lt;br /&gt;
    e_col_not_found exception;&lt;br /&gt;
    pragma          exception_init(e_col_not_found, -904);&lt;br /&gt;
begin&lt;br /&gt;
    begin&lt;br /&gt;
        execute immediate &amp;#039;select cdb from v$database&amp;#039; &lt;br /&gt;
        into l_is_cdb;&lt;br /&gt;
    exception&lt;br /&gt;
        when e_col_not_found then l_is_cdb := &amp;#039;NO&amp;#039;;  -- ORA-00904&lt;br /&gt;
    end;&lt;br /&gt;
&lt;br /&gt;
    if (l_is_cdb = &amp;#039;YES&amp;#039;) then&lt;br /&gt;
        return TRUE;&lt;br /&gt;
    else&lt;br /&gt;
        return FALSE;  -- either not a cdb or pre-12.1 database&lt;br /&gt;
    end if;&lt;br /&gt;
&lt;br /&gt;
end is_db_cdb;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===List triggers in the database===&lt;br /&gt;
This query specifically lists after login triggers &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select obj.con_id&lt;br /&gt;
,      pdb.name&lt;br /&gt;
,      obj.owner&lt;br /&gt;
,      obj.object_name&lt;br /&gt;
,      to_char(obj.created, &amp;#039;DD/MM/YYYY HH24:MI:SS&amp;#039;)       created_str&lt;br /&gt;
,      to_char(obj.last_ddl_time, &amp;#039;DD/MM/YYYY HH24:MI:SS&amp;#039;) last_ddl_str&lt;br /&gt;
from   cdb_objects   obj&lt;br /&gt;
join   cdb_triggers trgs&lt;br /&gt;
       on (   obj.con_id      = trgs.con_id&lt;br /&gt;
          and obj.owner       = trgs.owner&lt;br /&gt;
          and obj.object_name = trgs.trigger_name&lt;br /&gt;
          )&lt;br /&gt;
join   v$pdbs pdb&lt;br /&gt;
       on ( obj.con_id  = pdb.con_id )&lt;br /&gt;
where  trgs.trigger_type     = &amp;#039;AFTER EVENT&amp;#039;&lt;br /&gt;
and    trgs.triggering_event like &amp;#039;LOGON%&amp;#039;&lt;br /&gt;
and    trgs.status           = &amp;#039;ENABLED&amp;#039;&lt;br /&gt;
order  by object_name&lt;br /&gt;
,      obj.last_ddl_time&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===List the pluggable databases (PDB) in a container database (CDB)===&lt;br /&gt;
The network_name column shows what you should find in tnsnames.ora for this db connection&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select name,network_name,pdb from v$services;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select * from v$pdbs;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Start and stop a pluggable database===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter pluggable database pdb1 open;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter pluggable database pdb1 close immediate;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Swith to a pluggable database===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter session set container=pdb1;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Reopen pluggable databases at container startup===&lt;br /&gt;
By default pluggable databases in a container remain in a MOUNT state when the container starts up.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select name, open_mode from v$pdbs where name = &amp;#039;PDB1&amp;#039;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
To modify this, open it and save its state&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter pluggable database pdb1 open;&lt;br /&gt;
alter pluggable database pdb1 save state;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
To see a log of issues with pluggable databases&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select * from pdb_plug_in_violations where type = &amp;#039;ERROR&amp;#039; and status != &amp;#039;RESOLVED&amp;#039; and name = &amp;#039;PDB1&amp;#039;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===What is the current container id in a cdb?===&lt;br /&gt;
CDB$ROOT is container id 1. User containers start from 2.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select sys_context(&amp;#039;USERENV&amp;#039;,&amp;#039;CON_ID&amp;#039;) from dual&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===What is the current container name in a cdb?===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select sys_context(&amp;#039;USERENV&amp;#039;,&amp;#039;CON_NAME&amp;#039;) from dual&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or just&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
show con_name&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Switching Between Containers===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SQL&amp;gt; show con_name&lt;br /&gt;
&lt;br /&gt;
CON_NAME&lt;br /&gt;
------------------------------&lt;br /&gt;
CDB$ROOT&lt;br /&gt;
&lt;br /&gt;
SQL&amp;gt; alter session set container=tstklok;&lt;br /&gt;
&lt;br /&gt;
Session altered.&lt;br /&gt;
&lt;br /&gt;
SQL&amp;gt;  show con_name&lt;br /&gt;
&lt;br /&gt;
CON_NAME&lt;br /&gt;
------------------------------&lt;br /&gt;
TSTKLOK&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Direct connection to pluggable database===&lt;br /&gt;
These must be made using a service (defined in tnsnames.ora). Each pluggable database automatically registers a service with the listener (v$services).&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sqlplus appuser/apppwd@tstklok&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or using ezconnect&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SQL&amp;gt; conn appuser/apppwd@//localhost:1521/tstklok&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===What platform is the database running on?===&lt;br /&gt;
Could be useful for handling line endings...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select platform_name from v$database&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
if instr(db_platform, &amp;#039;WINDOWS&amp;#039;) != 0 then&lt;br /&gt;
    crlf := CHR(13) || CHR(10);       -- Windows gets the \r and \n&lt;br /&gt;
else&lt;br /&gt;
    crlf := CHR (10);                 -- Just \n for the rest of the world&lt;br /&gt;
end if;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Is the database 32 or 64 bit?===&lt;br /&gt;
If the answer is 1,7,10,15,16 or 17, then it is 32bit, everything else should be 64bit.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select platform_id from v$database&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===What features is my database using?===&lt;br /&gt;
Before converting to Standard Edition, check the features here - some may be Enterprise specific.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
col name for a45&lt;br /&gt;
col description for a85&lt;br /&gt;
set lines 2000&lt;br /&gt;
select name&lt;br /&gt;
,      detected_usages&lt;br /&gt;
,      description&lt;br /&gt;
from   dba_feature_usage_statistics&lt;br /&gt;
where  1=1&lt;br /&gt;
and    currently_used = &amp;#039;TRUE&amp;#039;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===How many redo log switches per hour?===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 100&lt;br /&gt;
col &amp;quot;YYYYMMDD HH24&amp;quot; for a14&lt;br /&gt;
select to_char(first_time,&amp;#039;yyyymmdd hh24&amp;#039;) &amp;quot;YYYYMMDD HH24&amp;quot;&lt;br /&gt;
,      count(1)                            num_switches&lt;br /&gt;
from   v$log_history&lt;br /&gt;
group  by to_char(first_time,&amp;#039;yyyymmdd hh24&amp;#039;)&lt;br /&gt;
order  by 1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or a bit fancier version...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rem *********************************************************** &lt;br /&gt;
rem&lt;br /&gt;
rem	File: log_history.sql &lt;br /&gt;
rem	Description: Log switch rates from v$log_history &lt;br /&gt;
rem   &lt;br /&gt;
rem	From &amp;#039;Oracle Performance Survival Guide&amp;#039; by Guy Harrison&lt;br /&gt;
rem		Chapter 21 Page 637&lt;br /&gt;
rem		ISBN: 978-0137011957&lt;br /&gt;
rem		See www.guyharrison.net for further information&lt;br /&gt;
rem  &lt;br /&gt;
rem		This work is in the public domain NSA &lt;br /&gt;
rem   &lt;br /&gt;
rem&lt;br /&gt;
rem ********************************************************* &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
col min_minutes format 9999.99 &lt;br /&gt;
col max_minutes format 9999.99 &lt;br /&gt;
col avg_minutes format 9999.99 &lt;br /&gt;
set pagesize 1000&lt;br /&gt;
set lines 70&lt;br /&gt;
set echo on &lt;br /&gt;
&lt;br /&gt;
WITH log_history AS&lt;br /&gt;
       (SELECT thread#, first_time,&lt;br /&gt;
               LAG(first_time) OVER (ORDER BY thread#, sequence#)&lt;br /&gt;
                  last_first_time,&lt;br /&gt;
               (first_time&lt;br /&gt;
                - LAG(first_time) OVER (ORDER BY thread#, sequence#))&lt;br /&gt;
                    * 24* 60   last_log_time_minutes,&lt;br /&gt;
               LAG(thread#) OVER (ORDER BY thread#, sequence#)&lt;br /&gt;
                   last_thread#&lt;br /&gt;
        FROM v$log_history)&lt;br /&gt;
SELECT ROUND(MIN(last_log_time_minutes), 2) min_minutes,&lt;br /&gt;
       ROUND(MAX(last_log_time_minutes), 2) max_minutes,&lt;br /&gt;
       ROUND(AVG(last_log_time_minutes), 2) avg_minutes&lt;br /&gt;
FROM log_history&lt;br /&gt;
WHERE     last_first_time IS NOT NULL&lt;br /&gt;
      AND last_thread# = thread#&lt;br /&gt;
      AND first_time &amp;gt; SYSDATE - 1; &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Show redo log groups/members===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
col instance       for a8&lt;br /&gt;
col thread         for 999&lt;br /&gt;
col groupno        for 999&lt;br /&gt;
col member         for a35&lt;br /&gt;
col redo_file_type for a15&lt;br /&gt;
col log_status     for a10&lt;br /&gt;
col logsize_m      for 99999&lt;br /&gt;
col archived       for a12&lt;br /&gt;
&lt;br /&gt;
SELECT i.instance_name   instance&lt;br /&gt;
,      i.thread#         thread&lt;br /&gt;
,      f.group#          groupno&lt;br /&gt;
,      f.member          member&lt;br /&gt;
,      f.type            redo_file_type&lt;br /&gt;
,      l.status          log_status&lt;br /&gt;
,      l.bytes/1024/1024 logsize_m&lt;br /&gt;
,      l.archived        archived&lt;br /&gt;
FROM   gv$logfile  f&lt;br /&gt;
,      gv$log      l&lt;br /&gt;
,      gv$instance i&lt;br /&gt;
WHERE  1=1&lt;br /&gt;
and    f.group#  = l.group#&lt;br /&gt;
AND    l.thread# = i.thread#&lt;br /&gt;
AND    i.inst_id = f.inst_id&lt;br /&gt;
AND    f.inst_id = l.inst_id&lt;br /&gt;
ORDER  BY i.instance_name&lt;br /&gt;
,      f.group#&lt;br /&gt;
,      f.member;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Korn shell timestamp function===&lt;br /&gt;
Example usage: echo &amp;quot;`ts`: Checking backup status&amp;quot;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
function ts {&lt;br /&gt;
    date +&amp;#039;%d-%b-%Y %H:%M:%S&amp;#039;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Drop a database===&lt;br /&gt;
Dropping a database including backups should be considered criminal in a production environment!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sqlplus / as sysdba&lt;br /&gt;
startup force mount exclusive restrict&lt;br /&gt;
exit&lt;br /&gt;
rman target /&lt;br /&gt;
drop database including backups noprompt;&lt;br /&gt;
exit&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
RMAN&amp;gt; connect target sys/pass@test&lt;br /&gt;
connected to target database: test (dbid=123456789)&lt;br /&gt;
&lt;br /&gt;
RMAN&amp;gt; startup force mount&lt;br /&gt;
RMAN&amp;gt; sql &amp;#039;alter system enable restricted session&amp;#039;;&lt;br /&gt;
RMAN&amp;gt; drop database including backups noprompt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Use sub-select or in-line views to update base tables===&lt;br /&gt;
Inline views can be used to update base table data&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
update&lt;br /&gt;
    (&lt;br /&gt;
    select p.list_price&lt;br /&gt;
    from   products           p&lt;br /&gt;
    ,      product_categories pc&lt;br /&gt;
    where  1=1&lt;br /&gt;
    and    p.category_id    = pc.category_id&lt;br /&gt;
    and    pc.category_name = &amp;#039;CPU&amp;#039;&lt;br /&gt;
    )&lt;br /&gt;
set list_price = list_price * 1.15; &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Use sub-select or in-line views to delete base table data===&lt;br /&gt;
A different way to delete rows in base tables, using Inline views or subselect&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
delete&lt;br /&gt;
    (&lt;br /&gt;
    select p.list_price&lt;br /&gt;
    from   products           p&lt;br /&gt;
    ,      product_categories pc&lt;br /&gt;
    where  1=1&lt;br /&gt;
    and    p.category_id    = pc.category_id&lt;br /&gt;
    and    pc.category_name = &amp;#039;CPU&amp;#039;&lt;br /&gt;
    )&lt;br /&gt;
where list_price &amp;lt; 1000; &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Mass update of files using perl inline script===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
for server in `cat /home/tools/etc/oracle/oracle_servers`; do&lt;br /&gt;
    ssh $server “perl -p -i -e &amp;#039;s/T01/D01/&amp;#039; /home/tools/scripts/rman/inclexcl.lst”&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===How to use vi-style editing in SQL*Plus===&lt;br /&gt;
These instructions are for Redhat but other versions will be very similar&lt;br /&gt;
* Download rlwrap from [http://dl.fedoraproject.org/pub/epel/5/x86_64/repoview/rlwrap.html] or [http://dl.fedoraproject.org/pub/epel/6/x86_64/repoview/rlwrap.html]&lt;br /&gt;
* sudo yum install rlwrap&lt;br /&gt;
* build a dictionary file for autocomplete on pressing Tab&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
vi $HOME/sql.dict&lt;br /&gt;
select&lt;br /&gt;
from&lt;br /&gt;
dba_users&lt;br /&gt;
dba_data_files&lt;br /&gt;
dba_tablespaces&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alias sysdba=&amp;#039;rlwrap -f $HOME/sql.dict sqlplus / as sysdba&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or for general command use...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alias sqlplus=&amp;#039;rlwrap -D2 -ic sqlplus&amp;#039;&lt;br /&gt;
alias dgmgrl=&amp;#039;rlwrap -D2 -ic dgmgrl&amp;#039;&lt;br /&gt;
alias rman=&amp;#039;rlwrap -D2 -ic rman&amp;#039;&lt;br /&gt;
alias asmcmd=&amp;#039;rlwrap -D2 -ic asmcmd&amp;#039;&lt;br /&gt;
alias lsnrctl=&amp;#039;rlwrap -D2 -ic lsnrctl&amp;#039;&lt;br /&gt;
alias adrci=&amp;#039;rlwrap -D2 -ic adrci&amp;#039;&lt;br /&gt;
alias impdp=&amp;#039;rlwrap -D2 -ic impdp&amp;#039;&lt;br /&gt;
alias expdp=&amp;#039;rlwrap -D2 -ic expdp&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Execute an SQL statement on all databases on all servers for a customer===&lt;br /&gt;
Run from customer&amp;#039;s management server&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
./dosh -c &amp;quot;su - oracle -c &amp;#039;/home/tools/scripts/oracle/all_db_do -v \&amp;quot;select username, account_status, profile from dba_users order by 3;\&amp;quot;&amp;#039;&amp;quot; &amp;gt;user_status.lst&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SCRIPTS_DIR=/home/tools/scripts/oracle&lt;br /&gt;
$SCRIPTS_DIR/dosh -c &amp;quot;su - oraibm -c \&amp;quot;$SCRIPTS_DIR/all_db_do &amp;#039;alter user ops\\\$oraibm profile oracle_system_user;&amp;#039;\&amp;quot;&amp;quot;&lt;br /&gt;
$SCRIPTS_DIR/dosh2 -c &amp;quot;su - oraibm -c \&amp;quot;$SCRIPTS_DIR/all_db_do &amp;#039;alter user ops$oraibm profile oracle_system_user;&amp;#039;\&amp;quot;&amp;quot;&lt;br /&gt;
$SCRIPTS_DIR/dosh2 -c &amp;quot;su - oraibm -c \&amp;quot;$SCRIPTS_DIR/all_db_do &amp;#039;alter system set control_file_record_keep_time=31;&amp;#039;\&amp;quot;&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Where is the alert log/alertlog?===&lt;br /&gt;
Older systems&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select value from v$parameter where name=&amp;#039;background_dump_dest&amp;#039;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Newer systems&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select value from v$diag_info where name=&amp;#039;Diag Trace&amp;#039;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Grant normal users access to the alertlog table (sys.x$dbgalertext)===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
create view x$dbgalertext_v as select * from x$dbgalertext;&lt;br /&gt;
grant select on x$dbgalertext_v to &amp;amp;&amp;amp;grantee;&lt;br /&gt;
create or replace synonym &amp;amp;grantee..x$dbgalertext for sys.x$dbgalertext_v;&lt;br /&gt;
undef grantee&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Search alert log for ORA-00600 and ORA-07445 errors===&lt;br /&gt;
Scan the database table version of the alertlog for errors without reporting what was already found.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select indx, message_text from x$dbgalertext where message_text like &amp;#039;%ORA-00600%&amp;#039; or message_text like &amp;#039;%ORA-07445%&amp;#039; and indx &amp;gt; &amp;amp;last_queried_indx order by indx desc;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Simulating errors in alert log===&lt;br /&gt;
Sometimes you need to inject error messages into the alertlog to test your monitoring system. This generates the entries in the alertlog and in x$dbgalertext table.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
exec sys.dbms_system.ksdwrt(2, &amp;#039;ORA-07445: Testing this error code for Zenoss, do not investigate.&amp;#039;);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This additionally creates a trace file.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
exec sys.dbms_system.ksdwrt(3, &amp;#039;ORA-00600: Testing this error code for Zenoss, do not investigate.&amp;#039;);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===tail the database alert log===&lt;br /&gt;
If an ADR error is displayed, then ORACLE_SID is probably not set&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alias alertlog=&amp;#039;adrci exec=&amp;quot;set home diag/rdbms/$(echo $ORACLE_SID | tr A-Z a-z)/$ORACLE_SID; show alert -tail -f&amp;quot;&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===What is my WAN ip address?===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
curl -A &amp;quot;Mozilla/4.0&amp;quot; http://checkip.dyndns.org/ 2&amp;gt;/dev/null | perl -ne &amp;#039;print $1 if /Current IP Address: (\d+\.\d+\.\d+\.\d+)/&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
curl -A &amp;quot;Mozilla/4.0&amp;quot; http://myip.dnsdynamic.org/ 2&amp;gt;/dev/null&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Wait for child pid to finish in background and report its status===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# submit a process to the background&lt;br /&gt;
export_schema1.ksh &amp;amp;&lt;br /&gt;
bgpid=$!&lt;br /&gt;
&lt;br /&gt;
while (ps -ef | grep $bgpid | grep -v grep); do&lt;br /&gt;
    # still running...&lt;br /&gt;
    sleep 600&lt;br /&gt;
done&lt;br /&gt;
&lt;br /&gt;
# should be finished&lt;br /&gt;
wait $bgpid&lt;br /&gt;
bgstatus=$?&lt;br /&gt;
echo background process ended with status $bgstatus&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/usr/bin/ksh&lt;br /&gt;
# submit a few processes to the background&lt;br /&gt;
# wait for them all to finish&lt;br /&gt;
# concat their logfiles&lt;br /&gt;
&lt;br /&gt;
(./sleeper.sh;echo &amp;quot;sleeper 1 finished&amp;quot;)&amp;gt;sleeper1.log &amp;amp;&lt;br /&gt;
PIDLIST=&amp;quot;$PIDLIST $!&amp;quot;&lt;br /&gt;
echo &amp;quot;PIDLIST is $PIDLIST ...&amp;quot;&lt;br /&gt;
sleep 5&lt;br /&gt;
&lt;br /&gt;
(./sleeper.sh;echo &amp;quot;sleeper 2 finished&amp;quot;)&amp;gt;sleeper2.log &amp;amp;&lt;br /&gt;
PIDLIST=&amp;quot;$PIDLIST $!&amp;quot;&lt;br /&gt;
echo &amp;quot;PIDLIST is $PIDLIST ...&amp;quot;&lt;br /&gt;
sleep 5&lt;br /&gt;
&lt;br /&gt;
(./sleeper.sh;echo &amp;quot;sleeper 3 finished&amp;quot;)&amp;gt;sleeper3.log &amp;amp;&lt;br /&gt;
PIDLIST=&amp;quot;$PIDLIST $!&amp;quot;&lt;br /&gt;
echo &amp;quot;PIDLIST is $PIDLIST ...&amp;quot;&lt;br /&gt;
sleep 5&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;Now 15 seconds later, we have 3 pids: $PIDLIST&amp;quot;&lt;br /&gt;
for PID in $PIDLIST; do&lt;br /&gt;
    wait $PID&lt;br /&gt;
    echo &amp;quot;$PID exited with status $?&amp;quot;&lt;br /&gt;
done&lt;br /&gt;
&lt;br /&gt;
# all jobs should have ended, concat their logs&lt;br /&gt;
cat sleeper*log &amp;gt; sleepers.log&lt;br /&gt;
cat sleepers.log&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Real world example&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/usr/bin/ksh&lt;br /&gt;
# ==============================================================================&lt;br /&gt;
# Name         : export_JDBEOP1.ksh&lt;br /&gt;
# Description  : Run export in pieces for performance reasons&lt;br /&gt;
#&lt;br /&gt;
# Parameters   : &lt;br /&gt;
#&lt;br /&gt;
# Notes        : Also decide whether to exclude PDARC schema or not&lt;br /&gt;
#                depending on what day it is&lt;br /&gt;
#&lt;br /&gt;
#&lt;br /&gt;
# Modification History&lt;br /&gt;
# ====================&lt;br /&gt;
# When      Who               What&lt;br /&gt;
# ========= ================= ==================================================&lt;br /&gt;
# 15-OCT-13 Stuart Barkley    Created&lt;br /&gt;
# ==============================================================================&lt;br /&gt;
&lt;br /&gt;
STARTTIME=`date &amp;#039;+%Y%m%d%H%M%S&amp;#039;`&lt;br /&gt;
DAYNO=`date +%u`&lt;br /&gt;
PROGNAME=`basename $0`&lt;br /&gt;
SCRIPTS_DIR=/home/tools/scripts/oracle&lt;br /&gt;
DATA_DIR=/oracle/JDBEOP1/admin/change&lt;br /&gt;
EXPORT_DIR=/oracle/export/JDBEOP1&lt;br /&gt;
&lt;br /&gt;
# marker so we can find our files later&lt;br /&gt;
MARKERFILE=/tmp/start_$PROGNAME_$$&lt;br /&gt;
touch $MARKERFILE&lt;br /&gt;
&lt;br /&gt;
$SCRIPTS_DIR/expdp_PARFILE.ksh -s JDBEOP1 -u PRODDTA -p 4 -k 2 -f $DATA_DIR/JDBEOP1_PRODDTA.parfile &amp;amp;&lt;br /&gt;
PIDLIST=&amp;quot;$PIDLIST $!&amp;quot;&lt;br /&gt;
echo &amp;quot;PIDLIST is $PIDLIST ...&amp;quot;&lt;br /&gt;
&lt;br /&gt;
$SCRIPTS_DIR/expdp_PARFILE.ksh -s JDBEOP1 -u PRODCTL -p 2 -k 2 -f $DATA_DIR/JDBEOP1_PRODCTL.parfile &amp;amp;&lt;br /&gt;
PIDLIST=&amp;quot;$PIDLIST $!&amp;quot;&lt;br /&gt;
echo &amp;quot;PIDLIST is $PIDLIST ...&amp;quot;&lt;br /&gt;
&lt;br /&gt;
$SCRIPTS_DIR/expdp_PARFILE.ksh -s JDBEOP1 -u NOPRODNOPDARC -p 4 -k 2 -f $DATA_DIR/JDBEOP1_NOPROD_NOPDARC.parfile &amp;amp;&lt;br /&gt;
PIDLIST=&amp;quot;$PIDLIST $!&amp;quot;&lt;br /&gt;
echo &amp;quot;PIDLIST is $PIDLIST ...&amp;quot;&lt;br /&gt;
&lt;br /&gt;
if [[ $DAYNO -eq 1 ]]; then&lt;br /&gt;
    $SCRIPTS_DIR/expdp_PARFILE.ksh -s JDBEOP1 -u NOPROD -p 4 -k 2 -f $DATA_DIR/JDBEOP1_NOPROD.parfile &amp;amp;&lt;br /&gt;
    PIDLIST=&amp;quot;$PIDLIST $!&amp;quot;&lt;br /&gt;
    echo &amp;quot;PIDLIST is $PIDLIST ...&amp;quot;&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
# now sit and wait for the exports to finish&lt;br /&gt;
for PID in $PIDLIST; do&lt;br /&gt;
    echo &amp;quot;waiting for pid $PID to finish&amp;quot;&lt;br /&gt;
    wait $PID&lt;br /&gt;
    echo &amp;quot;$PID exited with status $?&amp;quot;&lt;br /&gt;
done&lt;br /&gt;
&lt;br /&gt;
# collect all log files up into one&lt;br /&gt;
cd $EXPORT_DIR&lt;br /&gt;
for i in `find . -name &amp;quot;expdp_JDBEOP1*log&amp;quot; -newer $MARKERFILE`; do&lt;br /&gt;
    cat $i &amp;gt; expdp_JDBEOP1_D_FULL_${STARTTIME}.log&lt;br /&gt;
done&lt;br /&gt;
&lt;br /&gt;
rm $MARKLERFILE&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Create private DB link for a user without knowing his password===&lt;br /&gt;
* Inspired by [http://oradbatips.blogspot.co.uk/2010/01/tip-84-create-private-db-link-for-user.html oradbatips.blogspot.co.uk]&lt;br /&gt;
It uses a clever package, dbms_sys_sql.&amp;lt;br /&amp;gt;&lt;br /&gt;
Also useful for executing anything on behalf of another user.&amp;lt;br /&amp;gt;&lt;br /&gt;
Here is an example on how to create private database link for a user.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
create or replace procedure link_creator ( p_owner varchar2, p_dblink_name varchar2, p_username varchar2, p_password varchar2, p_address varchar2 ) as&lt;br /&gt;
    uid number;&lt;br /&gt;
    sqltext varchar2(1000) := &amp;#039;create [public] database link [link_name] connect to [username] identified by [password] using &amp;#039;&amp;#039;[address]&amp;#039;&amp;#039;&amp;#039;;&lt;br /&gt;
    myint integer;&lt;br /&gt;
begin&lt;br /&gt;
    if upper(p_owner) = &amp;#039;PUBLIC&amp;#039; then&lt;br /&gt;
        sqltext := replace(sqltext, &amp;#039;[public]&amp;#039;, &amp;#039;public&amp;#039;);&lt;br /&gt;
    else&lt;br /&gt;
        sqltext := replace(sqltext, &amp;#039;[public]&amp;#039;, &amp;#039;&amp;#039;);&lt;br /&gt;
    end if;&lt;br /&gt;
    sqltext := replace(sqltext, &amp;#039;[linkname]&amp;#039;, p_dblink_name);&lt;br /&gt;
    sqltext := replace(sqltext, &amp;#039;[username]&amp;#039;, p_username);&lt;br /&gt;
    sqltext := replace(sqltext, &amp;#039;[password]&amp;#039;, p_password);&lt;br /&gt;
    sqltext := replace(sqltext, &amp;#039;[address]&amp;#039;, p_address);&lt;br /&gt;
&lt;br /&gt;
    select user_id&lt;br /&gt;
    into   uid&lt;br /&gt;
    from   dba_users&lt;br /&gt;
    where  username = decode(upper(p_owner), &amp;#039;PUBLIC&amp;#039;, &amp;#039;SYS&amp;#039;, p_owner)&lt;br /&gt;
    ;&lt;br /&gt;
    myint:=sys.dbms_sys_sql.open_cursor();&lt;br /&gt;
    sys.dbms_sys_sql.parse_as_user ( myint, sqltext, dbms_sql.native, uid );&lt;br /&gt;
    sys.dbms_sys_sql.close_cursor(myint);&lt;br /&gt;
end;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Here we can generate SQL to rebuild the links for future use. Note the password is no longer stored in this column.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set pages 1000&lt;br /&gt;
select &amp;#039;begin link_creator ( &amp;#039;&amp;#039;&amp;#039;|| u.name ||&amp;#039;&amp;#039;&amp;#039;,&amp;#039;&amp;#039;&amp;#039;|| l.name ||&amp;#039;&amp;#039;&amp;#039;,&amp;#039;&amp;#039;&amp;#039;|| l.userid ||&amp;#039;&amp;#039;&amp;#039;,&amp;#039;&amp;#039;&amp;#039;|| l.password ||&amp;#039;&amp;#039;&amp;#039;,&amp;#039;&amp;#039;&amp;#039;|| l.host ||&amp;#039;&amp;#039;&amp;#039;); end;&amp;#039;|| chr(10) ||&amp;#039;/&amp;#039; link_text&lt;br /&gt;
from   sys.link$ l&lt;br /&gt;
,      sys.user$ u&lt;br /&gt;
where  l.owner# = u.user#&lt;br /&gt;
;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Another method to create a db_link from sys on behalf of a user is to create a procedure under that users name that does the db link creation====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
grant create database link to &amp;amp;&amp;amp;user;&lt;br /&gt;
&lt;br /&gt;
create or replace procedure &amp;amp;user..create_db_link as&lt;br /&gt;
begin&lt;br /&gt;
    execute immediate &amp;#039;create database link &amp;amp;link_name connect to &amp;amp;user identified by &amp;amp;users_password using &amp;#039;&amp;#039;&amp;amp;tns_connect_identifier&amp;#039;&amp;#039;&amp;#039;;&lt;br /&gt;
end create_db_link;&lt;br /&gt;
&lt;br /&gt;
exec &amp;amp;user..create_db_link;&lt;br /&gt;
&lt;br /&gt;
revoke create database link from &amp;amp;user;&lt;br /&gt;
&lt;br /&gt;
drop procedure &amp;amp;user..create_db_link;&lt;br /&gt;
undef user&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Create a comma separated list of columns from a select statement===&lt;br /&gt;
Method 1:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SELECT parent_id,&lt;br /&gt;
       RTRIM(XMLAGG(XMLELEMENT(e,child_id || &amp;#039;,&amp;#039;)).EXTRACT(&amp;#039;//text()&amp;#039;),&amp;#039;,&amp;#039;) AS &amp;quot;Children&amp;quot;&lt;br /&gt;
FROM   parentChildTable&lt;br /&gt;
WHERE  parent_id = 0&lt;br /&gt;
GROUP  BY parent_id&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SELECT parent_id,&lt;br /&gt;
       LISTAGG(child_id, &amp;#039;,&amp;#039;) WITHIN GROUP (ORDER BY child_id) AS &amp;quot;Children&amp;quot;&lt;br /&gt;
  FROM parentChildTable&lt;br /&gt;
 WHERE parent_id = 0&lt;br /&gt;
 GROUP BY parent_id&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Method 2 (undocumented and cannot therefore be relied on to continue working in the same manner):&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SELECT wmsys.wm_concat(&amp;lt;column_name&amp;gt;)&lt;br /&gt;
FROM &amp;lt;table_name&amp;gt;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Start an instant one-line webserver in current directory===&lt;br /&gt;
Need to quickly share/copy a file or read an html file on Linux? Start a web server!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
python -m SimpleHTTPServer 8000&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
and point your browser to http://localhost:8000&amp;lt;br /&amp;gt;&lt;br /&gt;
or&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
while true; do nc -l -p 80 -q 1 &amp;lt; index.html; done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Get SQL*Plus to generate HTML===&lt;br /&gt;
* [http://docs.oracle.com/cd/E11882_01/server.112/e16604/ch_seven.htm#CHDCECJG official guide]&lt;br /&gt;
One way to do it... use -m(arkup) option to specify:&amp;lt;br /&amp;gt;&lt;br /&gt;
html on/off - specifies whether to output html output or not&lt;br /&gt;
head - specify your own customised head contents&amp;lt;br /&amp;gt;&lt;br /&gt;
spool off - as a part of the -m tag means do not print the default &amp;amp;lt;html&amp;amp;gt;, &amp;amp;lt;head&amp;amp;gt; and &amp;amp;lt;body&amp;amp;gt; tags&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sqlplus -m &amp;quot;html on head &amp;#039;&amp;lt;link rel=&amp;quot;stylesheet&amp;quot; href=&amp;quot;/dbamon_golden.css&amp;quot; type=&amp;quot;text/css&amp;quot; /&amp;gt;&amp;#039; spool off&amp;quot; / as sysdba&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sqlplus / as sysdba&lt;br /&gt;
set markup html on head &amp;#039;&amp;lt;link rel=&amp;quot;stylesheet&amp;quot; href=&amp;quot;/dbamon_golden.css&amp;quot; type=&amp;quot;text/css&amp;quot; /&amp;gt;&amp;#039; body &amp;quot;&amp;quot; table &amp;quot;&amp;quot; spool off&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
besides html and head, you can also specify:&amp;lt;br /&amp;gt;&lt;br /&gt;
body - specify your own customised body attributes&amp;lt;br /&amp;gt;&lt;br /&gt;
table - override the default table options&amp;lt;br /&amp;gt;&lt;br /&gt;
entmap - turn on or off the html replacement characters (&amp;amp;lt, &amp;amp;gt, etc...)&amp;lt;br /&amp;gt;&lt;br /&gt;
preformat - uses the &amp;amp;lt;pre&amp;amp;gt; tag to format output exactly as required&amp;lt;br /&amp;gt;&lt;br /&gt;
* another little gem...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
----------------------------------------&lt;br /&gt;
-- get the last SQL*Plus output in HTML&lt;br /&gt;
-- after Tanel Poder&lt;br /&gt;
----------------------------------------&lt;br /&gt;
&lt;br /&gt;
set termout off&lt;br /&gt;
&lt;br /&gt;
set markup HTML ON HEAD &amp;quot; -&lt;br /&gt;
 -&lt;br /&gt;
&amp;quot; -&lt;br /&gt;
BODY &amp;quot;&amp;quot; -&lt;br /&gt;
TABLE &amp;quot;border=&amp;#039;1&amp;#039; align=&amp;#039;center&amp;#039; summary=&amp;#039;Script output&amp;#039;&amp;quot; -&lt;br /&gt;
SPOOL ON ENTMAP ON PREFORMAT OFF&lt;br /&gt;
&lt;br /&gt;
spool myoutput.html&lt;br /&gt;
&lt;br /&gt;
l&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
spool off&lt;br /&gt;
set markup html off spool off&lt;br /&gt;
host firefox myoutput.html&lt;br /&gt;
set termout on&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===HTML SELECT - Trigger JavaScript ONCHANGE event even when the option is not changed===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;select onchange=&amp;quot;jsFunction()&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;option value=&amp;quot;&amp;quot; disabled selected style=&amp;quot;display:none;&amp;quot;&amp;gt;Label&amp;lt;/option&amp;gt;&lt;br /&gt;
  &amp;lt;option value=&amp;quot;1&amp;quot;&amp;gt;1&amp;lt;/option&amp;gt;&lt;br /&gt;
  &amp;lt;option value=&amp;quot;2&amp;quot;&amp;gt;2&amp;lt;/option&amp;gt;&lt;br /&gt;
  &amp;lt;option value=&amp;quot;3&amp;quot;&amp;gt;3&amp;lt;/option&amp;gt;&lt;br /&gt;
&amp;lt;/select&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Display horizontal bar graph in HTML table data cell===&lt;br /&gt;
Using Perl&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
print (&amp;#039;&amp;lt;td class=&amp;quot;left&amp;quot;&amp;gt;&amp;#039; .&lt;br /&gt;
            &amp;#039;&amp;lt;div style=&amp;quot;background-color:#8097BE;width:&amp;quot;&amp;#039;,$allocpercused  ,&amp;#039;%;&amp;quot; /&amp;gt;&amp;#039; .&lt;br /&gt;
            &amp;#039;&amp;lt;div style=&amp;quot;background-color:red;    width:&amp;quot;&amp;#039;,$automaxpercused,&amp;#039;%;&amp;quot; /&amp;gt;&amp;#039; .&lt;br /&gt;
            $tspace .&lt;br /&gt;
       &amp;#039;&amp;lt;/td&amp;gt;&amp;#039;&lt;br /&gt;
);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Depending on which way around the divs are, you get different interpretations&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
print (&amp;quot;&amp;lt;td class=\&amp;quot;left\&amp;quot;&amp;gt;&amp;quot; .&lt;br /&gt;
            &amp;quot;&amp;lt;div style=\&amp;quot;border-right:2px solid red; width:&amp;quot;,($automaxpercused&amp;gt;99)?(100):($automaxpercused),&amp;quot;%;\&amp;quot; /&amp;gt;&amp;quot; .&lt;br /&gt;
            &amp;quot;&amp;lt;div style=\&amp;quot;background-color:#8097BE;width:&amp;quot;,$allocpercused  ,&amp;quot;%;\&amp;quot; /&amp;gt;&amp;quot; .&lt;br /&gt;
            $tspace .&lt;br /&gt;
       &amp;quot;&amp;lt;/td&amp;gt;&amp;quot;&lt;br /&gt;
);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====References====&lt;br /&gt;
* [http://stackoverflow.com/questions/5324996/comma-separated-list-as-a-result-of-select-statement-in-oracle stackoverflow.com]&lt;br /&gt;
* [http://www.salvis.com/blog/?p=207 A whole page showing how to do it in all versions back to 7!]&lt;/div&gt;</summary>
		<author><name>Stuart</name></author>	</entry>

	<entry>
		<id>https://mailnest.com/dbawiki/index.php?title=Snippets&amp;diff=3367</id>
		<title>Snippets</title>
		<link rel="alternate" type="text/html" href="https://mailnest.com/dbawiki/index.php?title=Snippets&amp;diff=3367"/>
				<updated>2018-11-21T11:12:43Z</updated>
		
		<summary type="html">&lt;p&gt;Stuart: /* Search alert log for ORA-00600 and ORA-07445 errors */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;===Protecting an Apache Web Server directory with htaccess===&lt;br /&gt;
* [https://davidwalsh.name/password-protect-directory-using-htaccess https://davidwalsh.name/password-protect-directory-using-htaccess]&lt;br /&gt;
* [http://www.htaccesstools.com/articles/password-protection/ http://www.htaccesstools.com/articles/password-protection/]&lt;br /&gt;
Two files are needed.&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;The .htaccess Code&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
AuthType Basic&lt;br /&gt;
AuthName &amp;quot;restricted area&amp;quot;&lt;br /&gt;
AuthUserFile /home/davidwalsh/html/protect-me-dir/.htpasswd&lt;br /&gt;
require valid-user&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;The .htpasswd Code&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
davidwalsh:daWHfZrDLB88.&lt;br /&gt;
rodstewart:roFulYxC2.8ws&lt;br /&gt;
cssexpert:csmnmq.M8T5ho&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Protecting a lighttpd directory with htaccess===&lt;br /&gt;
Generate an MD5 hash with the tools above and paste into this file&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
vi /etc/lighttpd/.htpasswd&lt;br /&gt;
stuart:3#$567890#$56789056789&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Check modules.conf file to ensure mod_auth and mod_rewrite are enabled&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
vi /etc/lighttpd/modules.conf&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Alter the lighttpd.conf file to allow the authentication&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#auth directives&lt;br /&gt;
auth.backend = &amp;quot;htpasswd&amp;quot;&lt;br /&gt;
auth.backend.htpasswd.userfile = &amp;quot;/etc/lighttpd/.htpasswd&amp;quot;&lt;br /&gt;
auth.debug = 1&lt;br /&gt;
$HTTP[&amp;quot;url&amp;quot;] =~ &amp;quot;^/cgi-bin&amp;quot; {&lt;br /&gt;
        auth.require = ( &amp;quot;&amp;quot; =&amp;gt;&lt;br /&gt;
        (&lt;br /&gt;
        &amp;quot;method&amp;quot; =&amp;gt; &amp;quot;basic&amp;quot;,&lt;br /&gt;
        &amp;quot;realm&amp;quot; =&amp;gt; &amp;quot;DbaHawk access&amp;quot;,&lt;br /&gt;
        &amp;quot;require&amp;quot; =&amp;gt; &amp;quot;valid-user&amp;quot;&lt;br /&gt;
        ) )&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Restart the lighttpd server&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
systemctl stop lighttpd&lt;br /&gt;
systemctl start lighttpd&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
I tried it with htdigest but could not get it to protest the directory!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#auth.backend = &amp;quot;htdigest&amp;quot;&lt;br /&gt;
#auth.backend.htdigest.userfile = &amp;quot;/etc/lighttpd/lighttpd.user.htdigest&amp;quot;&lt;br /&gt;
#auth.require = (&lt;br /&gt;
#    &amp;quot;/var/www/cgi-bin/&amp;quot; =&amp;gt; (&lt;br /&gt;
#    &amp;quot;method&amp;quot;  =&amp;gt; &amp;quot;basic&amp;quot;,&lt;br /&gt;
#    &amp;quot;realm&amp;quot;   =&amp;gt; &amp;quot;DbaHawk access&amp;quot;,&lt;br /&gt;
#    &amp;quot;require&amp;quot; =&amp;gt; &amp;quot;valid-user&amp;quot;&lt;br /&gt;
#    ),&lt;br /&gt;
#)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Rename a datafile if the filename contains junk / unprintable characters===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter tablespace ts_thaler_data offline;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Oracle have a document that describes a few ways of doing it in [https://support.oracle.com/rs?type=doc&amp;amp;id=824473.1 Note 824473.1]&lt;br /&gt;
If the filename contains control characters and cannot be selected in the normal way, use ls -ali to find the node number and then use find with -inum to rename (or move) the file&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ls -baltri&lt;br /&gt;
total 47474984&lt;br /&gt;
12409 -rw-r-----    1 oracle   oinstall 1073750016 Sep 26 13:56 ts_thaler_data_02\1776.dbf&lt;br /&gt;
12350 -rw-r-----    1 oracle   oinstall 5242888192 Sep 26 13:56 ts_thaler_data_01.dbf&lt;br /&gt;
&lt;br /&gt;
find . -inum 12409 -exec mv {} ts_thaler_data_06.dbf \;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Work out what the database thinks the name is and rename it there too! AskTom has a discussion on it [https://asktom.oracle.com/pls/apex/asktom.search?tag=rename-datafile-with-dummy-characters-after-dbf here]&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select substr(name,i,1),ascii(substr(name,i,1)) from ( select name from v$datafile where file# = 9), ( select rownum i from dual connect by level &amp;lt;= 50);&lt;br /&gt;
SUBS ASCII(SUBSTR(NAME,I,1))&lt;br /&gt;
---- -----------------------&lt;br /&gt;
t                        116&lt;br /&gt;
s                        115&lt;br /&gt;
_                         95&lt;br /&gt;
t                        116&lt;br /&gt;
h                        104&lt;br /&gt;
a                         97&lt;br /&gt;
l                        108&lt;br /&gt;
e                        101&lt;br /&gt;
r                        114&lt;br /&gt;
_                         95&lt;br /&gt;
d                        100&lt;br /&gt;
a                         97&lt;br /&gt;
t                        116&lt;br /&gt;
a                         97&lt;br /&gt;
_                         95&lt;br /&gt;
0                         48&lt;br /&gt;
2                         50&lt;br /&gt;
                         127&lt;br /&gt;
2                         50&lt;br /&gt;
.                         46&lt;br /&gt;
d                        100&lt;br /&gt;
b                         98&lt;br /&gt;
f                        102&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
You can see there&amp;#039;s a 127 just before the .dbf... this crept in a the backspace key was not working correctly.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set serveroutput on&lt;br /&gt;
declare&lt;br /&gt;
   fname1 varchar2(100);&lt;br /&gt;
   fname2 varchar2(100);&lt;br /&gt;
begin&lt;br /&gt;
  select name into fname1 from v$datafile where file# = 9;&lt;br /&gt;
  fname2 := replace(fname1,chr(127));&lt;br /&gt;
  &lt;br /&gt;
  dbms_output.put_line(&amp;#039;alter database rename file &amp;#039;&amp;#039;&amp;#039;||fname1||&amp;#039;&amp;#039;&amp;#039; to &amp;#039;&amp;#039;&amp;#039;||fname2||&amp;#039;&amp;#039;&amp;#039;&amp;#039;);&lt;br /&gt;
  execute immediate &amp;#039;alter database rename file &amp;#039;&amp;#039;&amp;#039;||fname1||&amp;#039;&amp;#039;&amp;#039; to &amp;#039;&amp;#039;&amp;#039;||fname2||&amp;#039;&amp;#039;&amp;#039;&amp;#039;;&lt;br /&gt;
end;&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
alter tablespace ts_thaler_data_online;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Generate creation of directory names from dba_directories===&lt;br /&gt;
Before deleting or dropping directories in the database, use this script to generate the create statements&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select &amp;#039;create or replace directory &amp;#039;||directory_name||&amp;#039; as &amp;#039;&amp;#039;&amp;#039;||directory_path||&amp;#039;&amp;#039;&amp;#039;;&amp;#039; from dba_directories;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Check if current (dot) directory is in PATH variable===&lt;br /&gt;
Using bareword comparison to check PATH variable&amp;lt;pre&amp;gt;&lt;br /&gt;
if [[ :$PATH: == *:&amp;quot;.&amp;quot;:* ]] ; then&lt;br /&gt;
    echo &amp;quot;in path&amp;quot;&lt;br /&gt;
else&lt;br /&gt;
    echo &amp;quot;not in path&amp;quot;&lt;br /&gt;
fi&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===tail a logfile from within the script you are writing it to===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#&lt;br /&gt;
# display logfile in real time&lt;br /&gt;
#&lt;br /&gt;
( tail -0f ${LOGFILE} ) &amp;amp;&lt;br /&gt;
tailPID=$!&lt;br /&gt;
&lt;br /&gt;
trap &amp;quot;kill $tailPID&amp;quot; 0 1 2 3 5 9 15&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Dump package, procedure etc. from dba_source in a way that it can be used to recreate it===&lt;br /&gt;
From [https://asktom.oracle.com/pls/apex/f?p=100:11:0::::P11_QUESTION_ID:454220160386 Ask Tom]&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 1000 pages 1000 feedb off verif off&lt;br /&gt;
select decode( type||&amp;#039;-&amp;#039;||to_char(line,&amp;#039;fm99999&amp;#039;), &amp;#039;PACKAGE BODY-1&amp;#039;, &amp;#039;/&amp;#039;||chr(10), null) ||&lt;br /&gt;
       decode(line,1,&amp;#039;create or replace &amp;#039;, &amp;#039;&amp;#039; ) ||&lt;br /&gt;
       text text&lt;br /&gt;
from   dba_source&lt;br /&gt;
where  owner = upper(&amp;#039;&amp;amp;owner&amp;#039;)&lt;br /&gt;
and    name  = upper(&amp;#039;&amp;amp;object_to_show&amp;#039;)&lt;br /&gt;
order  by type&lt;br /&gt;
,      line&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===A trick to exit out of SQL*Plus (using divide by zero) depending on answer to a question===&lt;br /&gt;
This example is taken from ReviewLite.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
-- Settings for customized functionality&lt;br /&gt;
define SCRIPT_OO=_OPTIONS_ONLY -- collect only options information&lt;br /&gt;
define SCRIPT_OO=&amp;#039;&amp;#039;            -- collect all information [default behavior]&lt;br /&gt;
&lt;br /&gt;
define SCRIPT_TS=_TIME_STAMP   -- include timestamp in names of the output directory and output files: YYYY.MM.DD.HH24.MI.SS; script does not prompt for license agreement&lt;br /&gt;
define SCRIPT_TS=&amp;#039;\home\oracle\options&amp;#039;            -- standard names for output directory and output files; script prompts for license agreement [default behavior]&lt;br /&gt;
&lt;br /&gt;
-- PROMT FOR LICENSE AGREEMENT ACCEPTANCE&lt;br /&gt;
DEFINE LANSWER=N&lt;br /&gt;
SET TERMOUT ON&lt;br /&gt;
ACCEPT &amp;amp;SCRIPT_TS LANSWER FORMAT A1 PROMPT &amp;#039;Accept License Agreement? (y\n): &amp;#039;&lt;br /&gt;
&lt;br /&gt;
-- FORCE &amp;quot;divisor is equal to zero&amp;quot; AND SQLERROR EXIT IF NOT ACCEPTED&lt;br /&gt;
-- WILL ALSO CONTINUE IF SCRIPT_TS SUBSTITUTION VARIABLE IS NOT NULL&lt;br /&gt;
SET TERMOUT OFF&lt;br /&gt;
WHENEVER SQLERROR EXIT&lt;br /&gt;
select 1/decode(&amp;#039; &amp;amp;LANSWER&amp;#039;, &amp;#039;Y&amp;#039;, null, &amp;#039;y&amp;#039;, null, decode(&amp;#039; &amp;amp;SCRIPT_TS&amp;#039;, null, 0, null)) as &amp;quot; &amp;quot; from dual;&lt;br /&gt;
WHENEVER SQLERROR CONTINUE&lt;br /&gt;
SET TERMOUT ON&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===How to uninstall optional components such as OWB, APEX, EM, OLAP, OWM from an Oracle database===&lt;br /&gt;
* [http://fast-dba.blogspot.be/2014/04/how-to-remove-unwanted-components-from.html fast-dba.blogspot.be]&lt;br /&gt;
&lt;br /&gt;
===Find unique indexes / primary index / key columns in a table===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
col owner       for a12&lt;br /&gt;
col table_name  for a32&lt;br /&gt;
col column_name for a32&lt;br /&gt;
col position    for 99&lt;br /&gt;
col status      for a10&lt;br /&gt;
set lines 1000 pages 100&lt;br /&gt;
&lt;br /&gt;
SELECT cons.owner&lt;br /&gt;
,      cols.table_name&lt;br /&gt;
,      cols.column_name&lt;br /&gt;
,      cols.position&lt;br /&gt;
,      cons.status&lt;br /&gt;
FROM   all_constraints  cons&lt;br /&gt;
,      all_cons_columns cols&lt;br /&gt;
WHERE  1=1&lt;br /&gt;
and    cols.owner           = &amp;#039;&amp;amp;TABLE_OWNER&amp;#039;&lt;br /&gt;
and    cols.table_name      = &amp;#039;&amp;amp;TABLE_NAME&amp;#039;&lt;br /&gt;
AND    cons.constraint_type = &amp;#039;P&amp;#039;&lt;br /&gt;
AND    cons.constraint_name = cols.constraint_name&lt;br /&gt;
AND    cons.owner           = cols.owner&lt;br /&gt;
ORDER  BY cols.table_name&lt;br /&gt;
,      cols.position&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Display the oracle instances running on the local server===&lt;br /&gt;
sed could be shorter but this one works cross-platform&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alias oenv=&amp;#039;ps -ef|grep pmon|grep -v grep|awk -F_ &amp;quot;{print \$NF}&amp;quot;|sort|uniq|sed -e &amp;quot;:a&amp;quot; -e &amp;quot;N&amp;quot; -e &amp;quot;\$!ba&amp;quot; -e &amp;quot;s/\n/ /g&amp;quot;&amp;#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Display which databases are scheduled for backup in cron===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
for i in `ps -ef | grep [o]ra_pmon | awk -F_ &amp;#039;{print $NF}&amp;#039;`; do&lt;br /&gt;
    crontab -l | grep $i | grep backup_export | awk &amp;#039;{print $2&amp;quot;:&amp;quot;$1&amp;quot; - &amp;quot;$17}&amp;#039;&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Trace SQL statements using autotrace and explain plan===&lt;br /&gt;
If the plustrace (plustrc.sql) role has been granted, explaining sql statements (without running the statement) is as easy as&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter session set sql_trace=true;&lt;br /&gt;
set autotrace traceonly explain&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Write to a trace log from PL/SQL===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
dbms_system.ksdwrt(1,&amp;#039;message sent to a trace file&amp;#039;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Invisible / hidden / virtual columns===&lt;br /&gt;
Article showing how to dump blocks also.&amp;lt;br /&amp;gt;&lt;br /&gt;
[https://www.oracle.com/technetwork/articles/database/invisible-columns-odb12c-2331522.html Tips and Tricks: Invisible Columns in Oracle Database 12c by Alex Zaballa, Oracle Ace and Daniel Da Meda (OCM)]&lt;br /&gt;
&lt;br /&gt;
===Write to the alert log from PL/SQL===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
dbms_system.ksdwrt(2,&amp;#039;message sent to the alert log&amp;#039;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Do distributed SQL transactions exist?===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select * from dba_2pc_pending;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
if yes, and to commit them...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select local_tran_id from dba_2pc_pending;&lt;br /&gt;
exec dbms_transaction.purge_lost_db_entry(&amp;#039;&amp;#039;);&lt;br /&gt;
commit;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Setup optional parameters and default values in an SQL*Plus script===&lt;br /&gt;
Some forgotten SQL*Plus tricks from the good old days and some new ones...&lt;br /&gt;
* [http://www.orafaq.com/wiki/SQL*Plus_FAQ#What_is_the_difference_between_.21_and_HOST.3F orafaq.com]&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set termout off&lt;br /&gt;
col p1 new_value 1&lt;br /&gt;
col p2 new_value 2&lt;br /&gt;
col p3 new_value 3&lt;br /&gt;
select null p1, null p2, null p3 from dual where  1=2;&lt;br /&gt;
select nvl(&amp;#039;&amp;amp;1&amp;#039;,&amp;#039;def1&amp;#039;) p1, nvl(&amp;#039;&amp;amp;2&amp;#039;,&amp;#039;def2&amp;#039;) p2, nvl(&amp;#039;&amp;amp;3&amp;#039;,&amp;#039;def3&amp;#039;) p3 from dual;&lt;br /&gt;
set termout on&lt;br /&gt;
prompt 1=&amp;quot;&amp;amp;1&amp;quot;&lt;br /&gt;
prompt 2=&amp;quot;&amp;amp;2&amp;quot;&lt;br /&gt;
prompt 3=&amp;quot;&amp;amp;3&amp;quot;&lt;br /&gt;
undef 1&lt;br /&gt;
undef 2&lt;br /&gt;
undef 3&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Display / show users with sysdba &amp;amp; sysoper privileges===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select * from v$pwfile_users;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Show path names of data files using instr===&lt;br /&gt;
Use to find the pathnames of all the filesystems/directories in which a database is housed.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select distinct substr(name,1,(instr(name,&amp;#039;/&amp;#039;,-1,1)-1)) path_name from v$datafile&lt;br /&gt;
union&lt;br /&gt;
select distinct substr(name,1,(instr(name,&amp;#039;/&amp;#039;,-1,1)-1)) path_name from v$tempfile&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Does a dataguard standby exist for this database?===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SELECT SUBSTR(value,INSTR(value,&amp;#039;=&amp;#039;,INSTR(UPPER(value),&amp;#039;SERVICE&amp;#039;))+1)&lt;br /&gt;
FROM   v$parameter&lt;br /&gt;
WHERE  name LIKE &amp;#039;log_archive_dest%&amp;#039; AND UPPER(value) LIKE &amp;#039;SERVICE%&amp;#039;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
gives something like this if found...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SUBSTR(VALUE,INSTR(VALUE,&amp;#039;=&amp;#039;,INSTR(UPPER(VALUE),&amp;#039;SERVICE&amp;#039;))+1)&lt;br /&gt;
--------------------------------------------------------------------------------&lt;br /&gt;
&amp;quot;jdbeop1_standby&amp;quot;, LGWR ASYNC NOAFFIRM delay=0 optional compression=disable m&lt;br /&gt;
ax_failure=0 max_connections=1 reopen=300 db_unique_name=&amp;quot;jdbeop1_standby&amp;quot; ne&lt;br /&gt;
t_timeout=60, valid_for=(all_logfiles,primary_role)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===List values for all init parameters in v$parameter (including default values for undocumented (hidden) parameters===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select i.ksppinm||&amp;#039;;&amp;#039;||sv.ksppstvl&lt;br /&gt;
from   x$ksppi  i&lt;br /&gt;
,      x$ksppsv sv&lt;br /&gt;
where  i.indx = sv.indx&lt;br /&gt;
order  by i.ksppinm;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Log file reports pipe errors===&lt;br /&gt;
Found these in the log file&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
solax005:root[/opt/IBM/ITM/logs]# tail solax005_or_RMANV11_col.out&lt;br /&gt;
CIR1880E (024955) Open Probe pipe error 2. Pipe=/opt/IBM/ITM/tmp/solax005_or_RMANV11/prb_RMANV11_kor_solax005_30024832_5346_pipe&lt;br /&gt;
CIR1880E (030938) Open Probe pipe error 2. Pipe=/opt/IBM/ITM/tmp/solax005_or_RMANV11/prb_RMANV11_kor_solax005_30030830_5406_pipe&lt;br /&gt;
CIR1880E (031923) Open Probe pipe error 2. Pipe=/opt/IBM/ITM/tmp/solax005_or_RMANV11/prb_RMANV11_kor_solax005_30031832_5434_pipe&lt;br /&gt;
CIR1880E (033934) Open Probe pipe error 2. Pipe=/opt/IBM/ITM/tmp/solax005_or_RMANV11/prb_RMANV11_kor_solax005_30033831_5495_pipe&lt;br /&gt;
CIR1880E (034918) Open Probe pipe error 2. Pipe=/opt/IBM/ITM/tmp/solax005_or_RMANV11/prb_RMANV11_kor_solax005_30034833_5521_pipe&lt;br /&gt;
CIR1880E (041927) Open Probe pipe error 2. Pipe=/opt/IBM/ITM/tmp/solax005_or_RMANV11/prb_RMANV11_kor_solax005_30041835_5610_pipe&lt;br /&gt;
CIR1880E (042931) Open Probe pipe error 2. Pipe=/opt/IBM/ITM/tmp/solax005_or_RMANV11/prb_RMANV11_kor_solax005_30042832_5642_pipe&lt;br /&gt;
CIR1880E (045928) Open Probe pipe error 2. Pipe=/opt/IBM/ITM/tmp/solax005_or_RMANV11/prb_RMANV11_kor_solax005_30045835_5730_pipe&lt;br /&gt;
CIR1880E (052927) Open Probe pipe error 2. Pipe=/opt/IBM/ITM/tmp/solax005_or_RMANV11/prb_RMANV11_kor_solax005_30052838_5819_pipe&lt;br /&gt;
CIR1880E (090929) Open Probe pipe error 2. Pipe=/opt/IBM/ITM/tmp/solax005_or_RMANV11/prb_RMANV11_kor_solax005_30090833_6487_pipe&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This could be due to a timeout on the pipe.&amp;lt;br /&amp;gt;&lt;br /&gt;
Increase parameters and restart agent. Add following lines to or.config:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
export COLL_WAIT_TIMEOUT=&amp;#039;200&amp;#039;&lt;br /&gt;
export WAIT_TIMEOUT=&amp;#039;200&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Find the most recent archived SCN number===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
col next_change# for 999999999999999&lt;br /&gt;
set numwidth 15&lt;br /&gt;
&lt;br /&gt;
select max(next_change#)&lt;br /&gt;
from   v$archived_log&lt;br /&gt;
where  (thread#, next_change#) in ( select thread#, max(next_change#)&lt;br /&gt;
                                    from   v$archived_log&lt;br /&gt;
                                    where  archived     = &amp;#039;YES&amp;#039;&lt;br /&gt;
                                    and    status       = &amp;#039;A&amp;#039;&lt;br /&gt;
                                    and    resetlogs_id = ( select resetlogs_id&lt;br /&gt;
                                                            from   v$database_incarnation&lt;br /&gt;
                                                            where  status = &amp;#039;CURRENT&amp;#039;&lt;br /&gt;
                                                          )&lt;br /&gt;
                                    group by thread#&lt;br /&gt;
                                  )&lt;br /&gt;
and    status = &amp;#039;A&amp;#039;&lt;br /&gt;
and    resetlogs_id = ( select resetlogs_id&lt;br /&gt;
                        from   v$database_incarnation&lt;br /&gt;
                        where  status = &amp;#039;CURRENT&amp;#039;&lt;br /&gt;
                      )&lt;br /&gt;
order  by next_change# asc;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Monitoring says database inactive===&lt;br /&gt;
* Check the candle user password has not expired in the database.&lt;br /&gt;
* There may be a clue in the log file. Check /opt/IBM/ITM/logs/`hostname`_or_${SID}_col.out&lt;br /&gt;
* Check limits for itmora account in /etc/security/limits. Should be same as oracle user.&lt;br /&gt;
* Check the config file. We had this issue when a new ORACLE_HOME was installed but the cfg file still had the old one in it.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
export ITM_HOME=/opt/IBM/ITM&lt;br /&gt;
cd $ITM_HOME/config&lt;br /&gt;
vi solax005_or_SRV2R.cfg&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#  IBM Tivoli Monitoring for Databases: Oracle Agent&lt;br /&gt;
#  Configuration file: solax005_or_SRV2R.cfg&lt;br /&gt;
#  Written by CandleDBconfig version: 1.4 on 31Jul13 13:39:41&lt;br /&gt;
&lt;br /&gt;
#  Note: this is a Korn-shell script that is &amp;quot;sourced&amp;quot; to create the&lt;br /&gt;
#  environment for a Monitoring Agent for Oracle.  It can be used to create&lt;br /&gt;
#  the environment to run the IBM-supplied database grant scripts.&lt;br /&gt;
&lt;br /&gt;
#  IBM does not recommend that you modify this file, but you can change the&lt;br /&gt;
#  data values or add new exported variables as long as the file is a valid ksh&lt;br /&gt;
#  script that executes with zero return code, and values remain quoted with &amp;quot;&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
#  Following environment variables are set for convenience in running grants.&lt;br /&gt;
   export ORACLE_SID=&amp;quot;SRV2R&amp;quot;&lt;br /&gt;
   export ORACLE_HOME=&amp;quot;/oracle/product/11.2.0.1&amp;quot;&lt;br /&gt;
   # IY92195  COLL_DISABLE_CURSORS setting&lt;br /&gt;
   export TNS_ADMIN=&amp;quot;/oracle/product/11.2.0.1/network/admin&amp;quot;&lt;br /&gt;
&lt;br /&gt;
#  Following variables are set for the setup scripts&lt;br /&gt;
   db_sid=&amp;quot;SRV2R&amp;quot;&lt;br /&gt;
   db_home=&amp;quot;/oracle/product/11.2.0.1&amp;quot;&lt;br /&gt;
   db_initfilename=&amp;quot;&amp;quot;&lt;br /&gt;
   db_login=&amp;quot;tivoli&amp;quot;&lt;br /&gt;
   db_password=&amp;quot;795D8822BC49477323815CD21C1E66E966E48EEE19C6A98056224D649B0FE316E6A11DC3F4E9BB5E226B65A8&amp;quot;&lt;br /&gt;
   db_ver=&amp;quot;11.x&amp;quot;&lt;br /&gt;
   db_type=&amp;quot;kor&amp;quot;&lt;br /&gt;
   db_tns=&amp;quot;/oracle/product/11.2.0.1/network/admin&amp;quot;&lt;br /&gt;
   db_extparms=&amp;quot;&amp;quot;&lt;br /&gt;
   db_hostname=&amp;quot;solax005&amp;quot;&lt;br /&gt;
   db_reason=&amp;quot;AIX_ps_ceww&amp;quot;&lt;br /&gt;
   db_pipedir=&amp;quot;&amp;quot;&lt;br /&gt;
   db_installstatus=&amp;quot;CONFIGSUCCESS&amp;quot;&lt;br /&gt;
&lt;br /&gt;
#  User-defined environment variables&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Solution:&amp;lt;br /&amp;gt;&lt;br /&gt;
* Change all occurrences of 11.2.0.1 to 11.2.0.3&lt;br /&gt;
* Restart agent&lt;br /&gt;
&lt;br /&gt;
===Alerts due to password expiring (or being changed in the database but not in ITM!)===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cd $ITM_HOME/logs&lt;br /&gt;
ls -altr | grep WM820T&lt;br /&gt;
tail -20 solax005_or_WM820T_col.out&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
CGN1521E (161614) Interval collection failed for cursor KORHART2&lt;br /&gt;
RCD0110S (161614) Invalid Oracle logon id (tivoli) or password given&lt;br /&gt;
 Please contact DBA to correct userid or password&lt;br /&gt;
CGN1521E (161614) Interval collection failed for cursor KORHART4&lt;br /&gt;
CGN1525E (161614) One or more interval cursors failed&lt;br /&gt;
RCD0110S (161714) Invalid Oracle logon id (tivoli) or password given&lt;br /&gt;
 Please contact DBA to correct userid or password&lt;br /&gt;
CGN1521E (161714) Interval collection failed for cursor KORHART2&lt;br /&gt;
RCD0110S (161714) Invalid Oracle logon id (tivoli) or password given&lt;br /&gt;
 Please contact DBA to correct userid or password&lt;br /&gt;
CGN1521E (161714) Interval collection failed for cursor KORHART4&lt;br /&gt;
CGN1525E (161714) One or more interval cursors failed&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Solution:&amp;lt;br /&amp;gt;&lt;br /&gt;
* Run agent reconfigure to setup the new password for the candle user (tivoli)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
export ITM_HOME=/opt/IBM/ITM&lt;br /&gt;
$ITM_HOME/bin/itmcmd config -A or&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Restart agent&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
export ITM_HOME=/opt/IBM/ITM&lt;br /&gt;
$ITM_HOME/smitools/scripts/StartAgent.sh restart or -o WM820T&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Many agents started with root user instead of itmora===&lt;br /&gt;
This can happen if the server is rebooted before the agents have been added to the itmora list using kdyedit / kciedit&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
export CANDLEHOME=/opt/IBM/ITM&lt;br /&gt;
export ITM_HOME=/opt/IBM/ITM&lt;br /&gt;
$ITM_HOME/smitools/scripts/kdyedit list&lt;br /&gt;
Type Runas      Inst                &lt;br /&gt;
or   root       AGPDEV              &lt;br /&gt;
or   root       BO1R                &lt;br /&gt;
or   root       DEV3                &lt;br /&gt;
or   root       EMREP               &lt;br /&gt;
or   root       ICR                 &lt;br /&gt;
or   itmora     MAPDEV              &lt;br /&gt;
or   itmora     MAPER               &lt;br /&gt;
or   itmora     PED                 &lt;br /&gt;
or   itmora     PER                 &lt;br /&gt;
or   itmora     RMANV11             &lt;br /&gt;
or   itmora     SRV2R               &lt;br /&gt;
or   itmora     WM820Q              &lt;br /&gt;
or   itmora     WM820T              &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ITM_HOME/smitools/scripts/kciedit list&lt;br /&gt;
Type Runas      Inst                &lt;br /&gt;
or   root       AGPDEV              &lt;br /&gt;
or   root       BO1R                &lt;br /&gt;
or   root       DEV3                &lt;br /&gt;
or   root       EMREP               &lt;br /&gt;
or   root       ICR                 &lt;br /&gt;
or   itmora     MAPDEV              &lt;br /&gt;
or   itmora     MAPER               &lt;br /&gt;
or   itmora     PED                 &lt;br /&gt;
or   itmora     PER                 &lt;br /&gt;
or   itmora     RMANV11             &lt;br /&gt;
or   itmora     SRV2R               &lt;br /&gt;
or   itmora     WM820Q              &lt;br /&gt;
or   itmora     WM820T              &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Solution: Add these instances to the itmora list&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
./kdyedit -t or -i AGPDEV -r itmora add&lt;br /&gt;
./kciedit -t or -i AGPDEV -r itmora add&lt;br /&gt;
...&lt;br /&gt;
./kdyedit -t or -i ICR -r itmora add&lt;br /&gt;
./kciedit -t or -i ICR -r itmora add&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ITM_HOME/smitools/scripts/kciedit list&lt;br /&gt;
Type Runas      Inst                &lt;br /&gt;
or   itmora     AGPDEV              &lt;br /&gt;
or   itmora     BO1R                &lt;br /&gt;
or   itmora     DEV3                &lt;br /&gt;
or   itmora     EMREP               &lt;br /&gt;
or   itmora     ICR                 &lt;br /&gt;
or   itmora     MAPDEV              &lt;br /&gt;
or   itmora     MAPER               &lt;br /&gt;
or   itmora     PED                 &lt;br /&gt;
or   itmora     PER                 &lt;br /&gt;
or   itmora     RMANV11             &lt;br /&gt;
or   itmora     SRV2R               &lt;br /&gt;
or   itmora     WM820Q              &lt;br /&gt;
or   itmora     WM820T              &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Kill any agents still running as root&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ps -ef |grep kor | grep root&lt;br /&gt;
kill -9 &amp;lt;process id&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Because these agents were owned by root, there will be permissions issues when trying to restart the agents with itmora so these need to be fixed before restarting the agents.&amp;lt;br /&amp;gt;&lt;br /&gt;
The simplest way of doing this is to run lockdown.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
export CANDLEHOME=/opt/IBM/ITM&lt;br /&gt;
$CANDLEHOME/smitools/scripts/lockdown.sh&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===See which processes are causing paging===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
svmon -Pt20 | perl -e &amp;#039;while(&amp;lt;&amp;gt;){print if($.==2||$&amp;amp;&amp;amp;&amp;amp;!$s++);$.=0 if(/^-+$/)}&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===How to return several variables from SQL*Plus back to Korn shell script===&lt;br /&gt;
Return multiple columns/elements from Oracle to shell script at the same time&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sqlplus -s sys/${SYS_PASSWORD}@${SID} as sysdba&amp;lt;&amp;lt;EOSQL | read SPACE_AFTER_INSTALL TOTAL_SPACE_AVAILABLE&lt;br /&gt;
set numwid 15 headi off newpa none feedb off&lt;br /&gt;
select sign(${SPACE_USED} + ${SPACE_AVAILABLE} - ${DATABASE_SIZE}), trim(${SPACE_USED} + ${SPACE_AVAILABLE})&lt;br /&gt;
from dual&lt;br /&gt;
/&lt;br /&gt;
EOSQL&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===How to get a shell environment variable from the operating system into the SQL or PL/SQL environment===&lt;br /&gt;
This has been bugging me for years. Something you would think simple... what is ORACLE_HOME? I know it&amp;#039;s a question mark at the SQL prompt but how to get it&amp;#039;s O/S value?&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
declare&lt;br /&gt;
    var1 varchar2(200);&lt;br /&gt;
begin&lt;br /&gt;
    dbms_system.get_env (&amp;#039;ORACLE_HOME&amp;#039;, var1);&lt;br /&gt;
    dbms_output.put_line (&amp;#039;ORACLE_HOME: &amp;#039;||var1);&lt;br /&gt;
end;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or in SQL*Plus&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
variable var1 varchar2(200);&lt;br /&gt;
exec dbms_system.get_env (&amp;#039;ORACLE_HOME&amp;#039;, :var1);&lt;br /&gt;
select :var1 from dual;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
That got me thinking... if this just gets stuff from the environment, it can fetch any exported variable?!?!&amp;lt;br /&amp;gt;&lt;br /&gt;
From the shell:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
export running_sids=`ps -ef | grep [p]mon | awk -F_ &amp;#039;{print $NF}&amp;#039;`&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
and now in SQL*Plus:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
variable sids varchar2(240);&lt;br /&gt;
exec dbms_system.get_env (&amp;#039;running_sids&amp;#039;, :sids);&lt;br /&gt;
select :sids from dual;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Wow!&lt;br /&gt;
&lt;br /&gt;
===How long/wide can a database name/sid be?===&lt;br /&gt;
Depends on where you look but taking the minimum here as &amp;quot;safe&amp;quot;, it should still be limited to 8 characters...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
col table_name for a30&lt;br /&gt;
col data_type  for a12&lt;br /&gt;
select table_name, data_type, data_length from dba_tab_columns where column_name = &amp;#039;DB_NAME&amp;#039;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This is 11gR2&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
TABLE_NAME                     DATA_TYPE    DATA_LENGTH&lt;br /&gt;
------------------------------ ------------ -----------&lt;br /&gt;
LOGMNRG_DICTIONARY$            VARCHAR2               9&lt;br /&gt;
SYS_FBA_CONTEXT_AUD            VARCHAR2             256&lt;br /&gt;
V_$LOGMNR_DICTIONARY           VARCHAR2               9&lt;br /&gt;
V_$LOGMNR_LOGS                 VARCHAR2               8&lt;br /&gt;
GV_$LOGMNR_DICTIONARY          VARCHAR2               9&lt;br /&gt;
GV_$LOGMNR_LOGS                VARCHAR2               8&lt;br /&gt;
V_$LOGMNR_LOGFILE              VARCHAR2               8&lt;br /&gt;
V_$LOGMNR_SESSION              VARCHAR2             128&lt;br /&gt;
GV_$LOGMNR_LOGFILE             VARCHAR2               8&lt;br /&gt;
GV_$LOGMNR_SESSION             VARCHAR2             128&lt;br /&gt;
GV_$ASM_CLIENT                 VARCHAR2               8&lt;br /&gt;
V_$ASM_CLIENT                  VARCHAR2               8&lt;br /&gt;
GV_$IOS_CLIENT                 VARCHAR2              64&lt;br /&gt;
V_$IOS_CLIENT                  VARCHAR2              64&lt;br /&gt;
DBA_PDB_HISTORY                VARCHAR2             128&lt;br /&gt;
CDB_PDB_HISTORY                VARCHAR2             128&lt;br /&gt;
SSCR_CAP$                      VARCHAR2            4000&lt;br /&gt;
SSCR_RES$                      VARCHAR2            4000&lt;br /&gt;
DBA_SSCR_CAPTURE               VARCHAR2            4000&lt;br /&gt;
CDB_SSCR_CAPTURE               VARCHAR2            4000&lt;br /&gt;
DBA_SSCR_RESTORE               VARCHAR2            4000&lt;br /&gt;
CDB_SSCR_RESTORE               VARCHAR2            4000&lt;br /&gt;
WRM$_DATABASE_INSTANCE         VARCHAR2               9&lt;br /&gt;
INT$DBA_HIST_DATABASE_INSTANCE VARCHAR2               9&lt;br /&gt;
DBA_HIST_DATABASE_INSTANCE     VARCHAR2               9&lt;br /&gt;
CDB_HIST_DATABASE_INSTANCE     VARCHAR2               9&lt;br /&gt;
LOGMNR_DICTIONARY$             VARCHAR2               9&lt;br /&gt;
&lt;br /&gt;
27 rows selected.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===What character set (characterset) was the database built with?===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
col name  for a40&lt;br /&gt;
col value for a60&lt;br /&gt;
select * from nls_database_parameters;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
col name   for a40&lt;br /&gt;
col value$ for a60&lt;br /&gt;
select name,value$ from props$ where name = &amp;#039;NLS_CHARACTERSET&amp;#039;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===How to find ORACLE_HOME from pmon process for a SID if there is no entry in oratab===&lt;br /&gt;
If database is created without dbca (datafile and controlfile copy), no entry will be automatically made in /etc/oratab.&amp;lt;br /&amp;gt;&lt;br /&gt;
So the problem is that you need to find out which of the ORACLE_HOMEs is being used by the running instances.&lt;br /&gt;
* Solaris, Linux&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ ps -ef | grep [p]mon&lt;br /&gt;
  oracle 10848     1   0 00:21:20 ?           2:11 ora_pmon_JDBEOP1&lt;br /&gt;
$ pwdx 10848&lt;br /&gt;
10848:  /oracle/JDBEOP1/product/11204/dbs&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* AIX&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ ps -ef | grep [p]mon&lt;br /&gt;
  oracle 13893878        1   0   Aug 12      -  7:53 ora_pmon_GOAQ1&lt;br /&gt;
$ ls -al /proc/13893878/cwd&lt;br /&gt;
lr-x------    2 oracle   dba               0 Aug 12 13:37  cwd -&amp;gt; /data/opt/app/product/11.2.0.4/db_1/dbs/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or&amp;lt;br /&amp;gt;&lt;br /&gt;
This command (ps eww) gives lots of information about the given process (pmon in this case). Tells you where the instance was started, whether it was started from SQL*Plus or RMAN, the http_proxy and loads more useful bits!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ps -ef | grep [p]mon | awk &amp;#039;{print $2}&amp;#039; | xargs -I {} ps eww {} | awk &amp;#039;{print $1 &amp;quot; &amp;quot; $5 &amp;quot; &amp;quot; $6 &amp;quot; &amp;quot; $0}&amp;#039; | sed &amp;#039;s/\(S*\) \(S*\) .*ORACLE_HOME/\1 \2/g&amp;#039; | cut -f1,2,3 -d&amp;quot; &amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Escape the underscore(_) or percent(%) character in an SQL statement===&lt;br /&gt;
The underscore matches any single character so to return data containing an underscore means having to use an escape character.&amp;lt;br /&amp;gt;&lt;br /&gt;
Here I use the backslash(\) so it is easy for Unix people to understand the mechanism.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select username from dba_users where username like &amp;#039;ENDUR\_DEV%&amp;#039; escape &amp;#039;\&amp;#039;; &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Validate, analyse and rebuild indexes===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set feedback off&lt;br /&gt;
set linesize 132&lt;br /&gt;
set serveroutput on&lt;br /&gt;
set trimspool on&lt;br /&gt;
&lt;br /&gt;
declare&lt;br /&gt;
    LOCKED exception;&lt;br /&gt;
    pragma exception_init (LOCKED, -54);&lt;br /&gt;
&lt;br /&gt;
    dbase         char(8);&lt;br /&gt;
    dbuser        varchar2(30);&lt;br /&gt;
    index_name    varchar(30);&lt;br /&gt;
    free_text     varchar2(50);&lt;br /&gt;
    pctused       number;&lt;br /&gt;
    height    number;&lt;br /&gt;
    index_mb      number;&lt;br /&gt;
    analyze_sql   varchar2(100);&lt;br /&gt;
    pct_used_sql  varchar2(150);&lt;br /&gt;
    rebuild_sql   varchar2(150);&lt;br /&gt;
 &lt;br /&gt;
    cursor c1 is&lt;br /&gt;
    select segment_name, bytes&lt;br /&gt;
    from   user_segments&lt;br /&gt;
    where  segment_type = &amp;#039;INDEX&amp;#039;&lt;br /&gt;
    and    segment_name like &amp;#039;DW%&amp;#039;&lt;br /&gt;
    and    segment_name not like &amp;#039;BIN%&amp;#039;&lt;br /&gt;
    and    bytes/1024   &amp;gt;= 1024&lt;br /&gt;
    order  by 2;&lt;br /&gt;
&lt;br /&gt;
-- validate the index&lt;br /&gt;
procedure validate_index (v_ind in varchar2) is&lt;br /&gt;
begin&lt;br /&gt;
    analyze_sql := &amp;#039;analyze index &amp;#039;||v_ind||&amp;#039; validate structure&amp;#039;;&lt;br /&gt;
    begin&lt;br /&gt;
        execute immediate analyze_sql;&lt;br /&gt;
    exception&lt;br /&gt;
    when LOCKED then&lt;br /&gt;
        dbms_output.put_line (v_ind||&amp;#039; locked - skipping&amp;#039;);&lt;br /&gt;
        pctused := 100;&lt;br /&gt;
        return;&lt;br /&gt;
    when others then&lt;br /&gt;
        dbms_output.put_line (analyze_sql);&lt;br /&gt;
        raise;&lt;br /&gt;
    end;&lt;br /&gt;
&lt;br /&gt;
    pct_used_sql := &amp;#039;select pct_used, round(blocks*8192/(1024*1024)), height from index_stats where name = &amp;#039;&amp;#039;&amp;#039;||v_ind||&amp;#039;&amp;#039;&amp;#039;&amp;#039;;&lt;br /&gt;
    execute immediate pct_used_sql into pctused, index_mb, height;&lt;br /&gt;
    if pctused is null then&lt;br /&gt;
        pctused := 0;&lt;br /&gt;
    end if;&lt;br /&gt;
    dbms_output.put_line (rpad(v_ind,35)||&amp;#039; (pct used &amp;#039;||pctused||&amp;#039;% size &amp;#039;||index_mb||&amp;#039;Mb height &amp;#039; || height ||&amp;#039;)&amp;#039;);&lt;br /&gt;
end validate_index;&lt;br /&gt;
 &lt;br /&gt;
-- execute SQL and trace if errors&lt;br /&gt;
procedure run_sql (v_sql in varchar2) is&lt;br /&gt;
begin&lt;br /&gt;
    execute immediate v_sql;&lt;br /&gt;
exception&lt;br /&gt;
when others then&lt;br /&gt;
    dbms_output.put_line (v_sql);&lt;br /&gt;
    raise;&lt;br /&gt;
end run_sql;&lt;br /&gt;
 &lt;br /&gt;
--&lt;br /&gt;
-- Script starts here&lt;br /&gt;
--&lt;br /&gt;
begin&lt;br /&gt;
    dbms_output.enable(1000000);&lt;br /&gt;
    -- Set up database name and schema&lt;br /&gt;
    -- select name into dbase  from v$database;&lt;br /&gt;
    select user into dbuser from dual;&lt;br /&gt;
    dbms_output.put_line(&amp;#039;============================================================================= *&amp;#039;);&lt;br /&gt;
    -- dbms_output.put_line(&amp;#039;* Indexes rebuild report for &amp;#039;||dbuser||&amp;#039; on &amp;#039;||dbase);&lt;br /&gt;
    dbms_output.put_line(&amp;#039;============================================================================= *&amp;#039;);&lt;br /&gt;
&lt;br /&gt;
    -- Loop around Indexes&lt;br /&gt;
    for x in c1 loop&lt;br /&gt;
        index_name := x.segment_name;&lt;br /&gt;
        validate_index (index_name );&lt;br /&gt;
        if pctused &amp;lt; 81 then&lt;br /&gt;
            if x.bytes/1024/1024 &amp;lt; 100 then&lt;br /&gt;
                rebuild_sql := &amp;#039;alter index &amp;#039;||x.segment_name||&amp;#039; rebuild online&amp;#039;;&lt;br /&gt;
            else&lt;br /&gt;
                rebuild_sql := &amp;#039;alter index &amp;#039;||x.segment_name||&amp;#039; coalesce&amp;#039;;&lt;br /&gt;
            end if;&lt;br /&gt;
            dbms_output.put_line (rebuild_sql);&lt;br /&gt;
            run_sql (rebuild_sql);&lt;br /&gt;
            validate_index (index_name);&lt;br /&gt;
        end if;&lt;br /&gt;
    end loop;&lt;br /&gt;
end;&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
set feed on&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Rebuild unusable indexes on a table===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select &amp;#039;alter index &amp;#039;||owner||&amp;#039;.&amp;#039;||index_name||&amp;#039; rebuild;&amp;#039;&lt;br /&gt;
from   dba_indexes&lt;br /&gt;
where  1=1&lt;br /&gt;
and    status    != &amp;#039;VALID&amp;#039;&lt;br /&gt;
and    owner     not in (&amp;#039;SYS&amp;#039;,&amp;#039;SYSTEM&amp;#039;)&lt;br /&gt;
--and    owner      = &amp;#039;WM822PP&amp;#039;&lt;br /&gt;
--and    table_name = &amp;#039;WF_PLANTS&amp;#039;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Pull the latest cfengine changes now instead of waiting for scheduled time===&lt;br /&gt;
For one host&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/opt/cfengine/bin/cfagent -ID dbaTime&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
On all hosts at the same time&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/home/ibmtools/scripts/oracle/dosh -c &amp;quot;/opt/cfengine/bin/cfagent -ID dbaTime&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Check status of datafiles without dba_data_files or v$datafile===&lt;br /&gt;
If the database is in mount mode, most tables are unavailable. This query uses the x$ (c based) tables and are always available&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set linesize 200;&lt;br /&gt;
set pagesize 100;&lt;br /&gt;
col inst_id for 9999999 heading &amp;#039;Instance #&amp;#039;&lt;br /&gt;
col file_nr for 9999999 heading &amp;#039;File #&amp;#039;&lt;br /&gt;
col file_name for A50 heading &amp;#039;File name&amp;#039;&lt;br /&gt;
col checkpoint_change_nr for 99999999999999 heading &amp;#039;Checkpoint #&amp;#039;&lt;br /&gt;
col checkpoint_change_time for A20 heading &amp;#039;Checkpoint time&amp;#039;&lt;br /&gt;
col last_change_nr for 99999999999999 heading &amp;#039;Last change #&amp;#039;&lt;br /&gt;
SELECT&lt;br /&gt;
      fe.inst_id,&lt;br /&gt;
      fe.fenum file_nr,&lt;br /&gt;
      fn.fnnam file_name,&lt;br /&gt;
      TO_NUMBER (fe.fecps) checkpoint_change_nr,&lt;br /&gt;
      fe.fecpt checkpoint_change_time,&lt;br /&gt;
      fe.fests last_change_nr,&lt;br /&gt;
      DECODE (&lt;br /&gt;
              fe.fetsn,&lt;br /&gt;
              0, DECODE (BITAND (fe.festa, 2), 0, &amp;#039;SYSOFF&amp;#039;, &amp;#039;SYSTEM&amp;#039;),&lt;br /&gt;
              DECODE (BITAND (fe.festa, 18),&lt;br /&gt;
                      0, &amp;#039;OFFLINE&amp;#039;,&lt;br /&gt;
                      2, &amp;#039;ONLINE&amp;#039;,&lt;br /&gt;
                      &amp;#039;RECOVER&amp;#039;)&lt;br /&gt;
      ) status&lt;br /&gt;
FROM x$kccfe fe,&lt;br /&gt;
     x$kccfn fn&lt;br /&gt;
WHERE    (   (fe.fepax != 65535 AND fe.fepax != 0 )&lt;br /&gt;
          OR (fe.fepax = 65535 OR fe.fepax = 0)&lt;br /&gt;
         )&lt;br /&gt;
     AND fn.fnfno = fe.fenum&lt;br /&gt;
     AND fe.fefnh = fn.fnnum&lt;br /&gt;
     AND fe.fedup != 0&lt;br /&gt;
     AND fn.fntyp = 4&lt;br /&gt;
     AND fn.fnnam IS NOT NULL&lt;br /&gt;
     AND BITAND (fn.fnflg, 4) != 4&lt;br /&gt;
ORDER BY fe.fenum&lt;br /&gt;
;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Check highest allocated extent in datafile (likely slow when having many extents)===&lt;br /&gt;
* Script to Detect Tablespace Fragmentation ( Doc ID 1020182.6 )&lt;br /&gt;
* How to shrink or reduce the datafile size by finding the high water mark (HWM) ( Doc ID 1600774.1 )&lt;br /&gt;
* How to find Objects Fragmented below High Water Mark ( Doc ID 337651.1 )&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
column file_name format a50;&lt;br /&gt;
column tablespace_name format a15;&lt;br /&gt;
column highwater format 9999999999;&lt;br /&gt;
set pagesize 9999&lt;br /&gt;
&lt;br /&gt;
select a.tablespace_name&lt;br /&gt;
,a.file_name&lt;br /&gt;
,(b.maximum+c.blocks-1)*d.db_block_size highwater&lt;br /&gt;
from dba_data_files a&lt;br /&gt;
,(select file_id,max(block_id) maximum&lt;br /&gt;
from dba_extents&lt;br /&gt;
group by file_id) b&lt;br /&gt;
,dba_extents c&lt;br /&gt;
,(select value db_block_size&lt;br /&gt;
from v$parameter&lt;br /&gt;
where name=&amp;#039;db_block_size&amp;#039;) d&lt;br /&gt;
where a.file_id = b.file_id&lt;br /&gt;
and c.file_id = b.file_id&lt;br /&gt;
and c.block_id = b.maximum&lt;br /&gt;
order by a.tablespace_name,a.file_name&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Runup to this was...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set markup html on spool on&lt;br /&gt;
spool db_info.html&lt;br /&gt;
set echo on&lt;br /&gt;
select * from dba_tablespaces where tablespace_name = &amp;#039;&amp;amp;&amp;amp;tablespace_name&amp;#039;;&lt;br /&gt;
select * from dba_data_files where tablespace_name = &amp;#039;&amp;amp;tablespace_name&amp;#039;;&lt;br /&gt;
select * from (select * from dba_extents where tablespace_name = &amp;#039;&amp;amp;tablespace_name&amp;#039; order by block_id desc) where rownum &amp;lt;301;&lt;br /&gt;
spool off&lt;br /&gt;
set markup html off&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select owner, segment_type, count(*) from dba_segments where tablesapce_name=&amp;#039;&amp;amp;tablespace_name&amp;#039; group by owner, segment_type;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
begin&lt;br /&gt;
for ii in (select owner, segment_name, segment_type from dba_segments where tablespace_name = &amp;#039;&amp;amp;tablespace_name&amp;#039; and segment_type like &amp;#039;TABLE%&amp;#039; and segment_name not like &amp;#039;%DATAPUMP%&amp;#039;)&lt;br /&gt;
loop&lt;br /&gt;
if ii.segment_type=&amp;#039;TABLE&amp;#039; then&lt;br /&gt;
begin&lt;br /&gt;
execute immediate(&amp;#039;alter table &amp;#039;||ii.owner||&amp;#039;.&amp;#039;||ii.segment_name||&amp;#039; enable row movement&amp;#039;);&lt;br /&gt;
execute immediate(&amp;#039;alter table &amp;#039;||ii.owner||&amp;#039;.&amp;#039;||ii.segment_name||&amp;#039; shrink space cascade&amp;#039;);&lt;br /&gt;
exception when others then&lt;br /&gt;
dbms_output.put_line(&amp;#039;FAILED 1: alter table &amp;#039;||ii.owner||&amp;#039;.&amp;#039;||ii.segment_name||&amp;#039; shrink space cascade : &amp;#039;||SQLERRM);&lt;br /&gt;
end;&lt;br /&gt;
end if;&lt;br /&gt;
end loop;&lt;br /&gt;
end;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Procedure to shrink space in tables and indexes===&lt;br /&gt;
* [http://www.oracle-wiki.net/startdocsreallifeshrinkexample Using the Oracle Shrink Command] - lots of good stuff at this site&lt;br /&gt;
Written by [https://asktom.oracle.com/pls/apex/f%3Fp%3D100:11:0::::P11_QUESTION_ID:5645095700346948864 Tom Kyte]&amp;lt;br /&amp;gt;&lt;br /&gt;
Depending on the Oracle version, this procedure may or may not work! It does not include the compact clause (neither does it re-analyse to prove it worked).&amp;lt;br /&amp;gt;&lt;br /&gt;
[http://www.oracle-wiki.net/startdocsreallifeshrinkexample Here] is a worked example that shows the complete process - oracle-wiki.net&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
create or replace procedure shrink_all&lt;br /&gt;
as&lt;br /&gt;
    l_sql        varchar2(4000);&lt;br /&gt;
    l_sql2       varchar2(4000);&lt;br /&gt;
    row_movement exception;&lt;br /&gt;
    pragma       exception_init( row_movement, -10636 );&lt;br /&gt;
begin&lt;br /&gt;
    for x in (select table_name&lt;br /&gt;
              ,      owner&lt;br /&gt;
              from   t&lt;br /&gt;
              where  sgm_space_management = &amp;#039;AUTO&amp;#039;)&lt;br /&gt;
    loop&lt;br /&gt;
        l_sql := &amp;#039;alter table &amp;quot;&amp;#039; || x.owner || &amp;#039;&amp;quot;.&amp;quot;&amp;#039; || x.table_name || &amp;#039;&amp;quot; shrink space&amp;#039;;&lt;br /&gt;
        dbms_output.put_line( l_sql );&lt;br /&gt;
&lt;br /&gt;
        begin&lt;br /&gt;
            execute immediate l_sql;&lt;br /&gt;
        exception&lt;br /&gt;
        when row_movement&lt;br /&gt;
        then&lt;br /&gt;
            dbms_output.put_line( &amp;#039;failed due to row movement...&amp;#039; );&lt;br /&gt;
            l_sql2 := &amp;#039;alter table &amp;quot;&amp;#039; || x.owner || &amp;#039;&amp;quot;.&amp;quot;&amp;#039; || x.table_name || &amp;#039;&amp;quot; enable row movement&amp;#039;;&lt;br /&gt;
            dbms_output.put_line( l_sql2 );&lt;br /&gt;
            execute immediate l_sql2;&lt;br /&gt;
            dbms_output.put_line( l_sql );&lt;br /&gt;
            execute immediate l_sql;&lt;br /&gt;
        end;&lt;br /&gt;
&lt;br /&gt;
        for y in (select owner&lt;br /&gt;
                  ,      index_name&lt;br /&gt;
                  from   dba_indexes&lt;br /&gt;
                  where  table_owner = x.owner&lt;br /&gt;
                  and    table_name  = x.table_name )&lt;br /&gt;
        loop&lt;br /&gt;
            l_sql := &amp;#039;alter index &amp;quot;&amp;#039; || y.owner || &amp;#039;&amp;quot;.&amp;quot;&amp;#039; || y.index_name || &amp;#039;&amp;quot; shrink space&amp;#039;;&lt;br /&gt;
            dbms_output.put_line( l_sql );&lt;br /&gt;
            execute immediate l_sql;&lt;br /&gt;
        end loop;&lt;br /&gt;
&lt;br /&gt;
    end loop;&lt;br /&gt;
end;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===How to delete/kill a distributed transaction===&lt;br /&gt;
From [http://www.pouwiel.com/?p=2204 pouwiel.com]&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SQL&amp;gt; SELECT LOCAL_TRAN_ID, GLOBAL_TRAN_ID,to_char(FAIL_TIME,&amp;#039;dd-mon-yyyy HH24:MI:SS&amp;#039;),STATE, MIXED FROM DBA_2PC_PENDING;&lt;br /&gt;
&lt;br /&gt;
LOCAL_TRAN_ID&lt;br /&gt;
----------------------&lt;br /&gt;
GLOBAL_TRAN_ID&lt;br /&gt;
--------------------------------------------------------------------------------&lt;br /&gt;
TO_CHAR(FAIL_TIME,&amp;#039;D STATE MIX&lt;br /&gt;
-------------------- ---------------- ---&lt;br /&gt;
8.19.321913&lt;br /&gt;
1463898948.0000013CDE8005110000000179F68840A089FFFEE644B640AED6B02438B2F39D9665F&lt;br /&gt;
AFB&lt;br /&gt;
15-feb-2013 16:37:41 prepared no&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
SQL&amp;gt; SELECT LOCAL_TRAN_ID, IN_OUT,INTERFACE, DATABASE FROM DBA_2PC_NEIGHBORS;&lt;br /&gt;
&lt;br /&gt;
LOCAL_TRAN_ID IN_ I&lt;br /&gt;
---------------------- --- -&lt;br /&gt;
DATABASE&lt;br /&gt;
--------------------------------------------------------------------------------&lt;br /&gt;
8.19.321913 in N&lt;br /&gt;
jdbc_11&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
SQL&amp;gt; rollback force &amp;#039;8.19.321913&amp;#039;;&lt;br /&gt;
&lt;br /&gt;
Rollback complete.&lt;br /&gt;
&lt;br /&gt;
SQL&amp;gt; execute dbms_transaction.purge_lost_db_entry(&amp;#039;8.19.321913&amp;#039;);&lt;br /&gt;
&lt;br /&gt;
PL/SQL procedure successfully completed.&lt;br /&gt;
&lt;br /&gt;
SQL&amp;gt; commit;&lt;br /&gt;
&lt;br /&gt;
Commit complete.&lt;br /&gt;
&lt;br /&gt;
SQL&amp;gt; SELECT LOCAL_TRAN_ID, GLOBAL_TRAN_ID,to_char(FAIL_TIME,&amp;#039;dd-mon-yyyy HH24:MI:SS&amp;#039;),STATE, MIXED FROM DBA_2PC_PENDING;&lt;br /&gt;
&lt;br /&gt;
no rows selected&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Be aware that the support document 159377.1 does not speak of the rollback force. If you don’t execute that particular command it will not work.&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORACLE_BASE is getting set to the same value as ORACLE_HOME when using . oraenv===&lt;br /&gt;
Permissions problem. Make sure the user has &amp;#039;&amp;#039;&amp;#039;write&amp;#039;&amp;#039;&amp;#039; access to oraclehomeproperties.xml file!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ls -al $ORACLE_HOME/inventory/ContentsXML/oraclehomeproperties.xml&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Change permissions as appropriate.&lt;br /&gt;
A different approach which should give the same end result would be to grant the orabase executable the setuid bit.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
chmod u+s $ORACLE_HOME/bin/orabase&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This allows any user to set the environment as the orabase executable will be run with the permissions of its owner.&lt;br /&gt;
===Move table partitions to a different tablespace===&lt;br /&gt;
Are you getting errors due to partitions belonging to a different tablespace and you want to drop the current tablepace?&amp;lt;br /&amp;gt;&lt;br /&gt;
ORA-14404: partitioned table contains partitions in a different tablespace&amp;lt;br /&amp;gt;&lt;br /&gt;
====Find tables with partitions in more than one tablespace====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 2000 pages 50&lt;br /&gt;
col table_owner for a30&lt;br /&gt;
col table_name for a30&lt;br /&gt;
select table_owner&lt;br /&gt;
 ,     table_name&lt;br /&gt;
,      count(*)&lt;br /&gt;
from   dba_tab_partitions&lt;br /&gt;
where  table_owner != &amp;#039;SYS&amp;#039;&lt;br /&gt;
group  by table_owner&lt;br /&gt;
,      table_name&lt;br /&gt;
having count(*) &amp;gt; 1&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
See which tables have partitions across multiple tablespaces...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 1000 pages 100&lt;br /&gt;
col table_name for a50&lt;br /&gt;
select distinct b.table_owner||&amp;#039;.&amp;#039;||b.table_name table_name&lt;br /&gt;
,      a.tablespace_name ts1&lt;br /&gt;
,      b.tablespace_name ts2&lt;br /&gt;
from   (&lt;br /&gt;
       select distinct tablespace_name&lt;br /&gt;
       ,      table_name&lt;br /&gt;
       ,      partition_name&lt;br /&gt;
       from   dba_tab_partitions&lt;br /&gt;
       )                  a&lt;br /&gt;
,      dba_tab_partitions b&lt;br /&gt;
where  a.table_name       = b.table_name&lt;br /&gt;
and    a.tablespace_name != b.tablespace_name&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Generate statements to move the partitions from one tablespace to another...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select &amp;#039;alter table &amp;#039;||b.table_owner||&amp;#039;.&amp;#039;||b.table_name||&amp;#039; move partition &amp;#039;||b.partition_name||&amp;#039; tablespace &amp;amp;NEW_TABLESPACE;&amp;#039;&lt;br /&gt;
from   (&lt;br /&gt;
       select distinct table_name&lt;br /&gt;
       ,      partition_name&lt;br /&gt;
       from   dba_tab_partitions&lt;br /&gt;
       where  tablespace_name = &amp;#039;&amp;amp;&amp;amp;OLD_TABLESPACE&amp;#039;&lt;br /&gt;
       )                  a&lt;br /&gt;
,      dba_tab_partitions b&lt;br /&gt;
where  a.table_name       = b.table_name&lt;br /&gt;
and    b.tablespace_name != &amp;#039;&amp;amp;OLD_TABLESPACE&amp;#039;&lt;br /&gt;
/&lt;br /&gt;
undef OLD_TABLESPACE&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====What&amp;#039;s left hanging around?====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
col SEGMENT_TYPE for a20&lt;br /&gt;
col OWNER for a20&lt;br /&gt;
col SEGMENT_NAME for a40&lt;br /&gt;
col PARTITION_NAME for a15&lt;br /&gt;
col TABLESPACE_NAME for a30&lt;br /&gt;
select segment_type&lt;br /&gt;
,      owner&lt;br /&gt;
,      segment_name&lt;br /&gt;
,      partition_name&lt;br /&gt;
,      tablespace_name&lt;br /&gt;
from   dba_segments&lt;br /&gt;
where  tablespace_name in (&amp;#039;TS_THALER_IOT_OLD&amp;#039;,&amp;#039;TS_THALER_CU&amp;#039;,&amp;#039;TS_THALER_BACKUP&amp;#039;,&amp;#039;TS_THALER_PART_OLD&amp;#039;)&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
select table_owner&lt;br /&gt;
,      table_name&lt;br /&gt;
from   dba_indexes&lt;br /&gt;
where  index_name = &amp;#039;&amp;amp;index_name&amp;#039;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===What edition is my database (Standard, Enterprise, XE...)?===&lt;br /&gt;
Only works from 12c :-(&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select edition from sys.registry$ where cid=&amp;#039;CATPROC&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Is database a CDB with PDBs?===&lt;br /&gt;
Needs a bit of work. Won&amp;#039;t work pre-12c obviously and also not on Standby databases if they are in MOUNT mode&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
for db in $(ps -ef | grep [p]mon|awk -F_ &amp;#039;{print $NF}&amp;#039;)&lt;br /&gt;
do&lt;br /&gt;
    export ORACLE_SID=${db}&lt;br /&gt;
    ORAENV_ASK=NO&lt;br /&gt;
    . oraenv &amp;gt;/dev/null 2&amp;gt;&amp;amp;1&lt;br /&gt;
    sqlplus -s / as sysdba&amp;lt;&amp;lt;&amp;#039;EOSQL&amp;#039;&lt;br /&gt;
set head off newpa none&lt;br /&gt;
select name&lt;br /&gt;
,      (select count(*) from v$pdbs) npdbs&lt;br /&gt;
from   v$database&lt;br /&gt;
/&lt;br /&gt;
EOSQL&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
version 2&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
function is_db_cdb return boolean&lt;br /&gt;
is&lt;br /&gt;
    b_is_cdb        boolean := false;&lt;br /&gt;
    l_is_cdb        varchar2(3) := &amp;#039;NO&amp;#039;;&lt;br /&gt;
    e_col_not_found exception;&lt;br /&gt;
    pragma          exception_init(e_col_not_found, -904);&lt;br /&gt;
begin&lt;br /&gt;
    begin&lt;br /&gt;
        execute immediate &amp;#039;select cdb from v$database&amp;#039; &lt;br /&gt;
        into l_is_cdb;&lt;br /&gt;
    exception&lt;br /&gt;
        when e_col_not_found then l_is_cdb := &amp;#039;NO&amp;#039;;  -- ORA-00904&lt;br /&gt;
    end;&lt;br /&gt;
&lt;br /&gt;
    if (l_is_cdb = &amp;#039;YES&amp;#039;) then&lt;br /&gt;
        return TRUE;&lt;br /&gt;
    else&lt;br /&gt;
        return FALSE;  -- either not a cdb or pre-12.1 database&lt;br /&gt;
    end if;&lt;br /&gt;
&lt;br /&gt;
end is_db_cdb;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===List triggers in the database===&lt;br /&gt;
This query specifically lists after login triggers &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select obj.con_id&lt;br /&gt;
,      pdb.name&lt;br /&gt;
,      obj.owner&lt;br /&gt;
,      obj.object_name&lt;br /&gt;
,      to_char(obj.created, &amp;#039;DD/MM/YYYY HH24:MI:SS&amp;#039;)       created_str&lt;br /&gt;
,      to_char(obj.last_ddl_time, &amp;#039;DD/MM/YYYY HH24:MI:SS&amp;#039;) last_ddl_str&lt;br /&gt;
from   cdb_objects   obj&lt;br /&gt;
join   cdb_triggers trgs&lt;br /&gt;
       on (   obj.con_id      = trgs.con_id&lt;br /&gt;
          and obj.owner       = trgs.owner&lt;br /&gt;
          and obj.object_name = trgs.trigger_name&lt;br /&gt;
          )&lt;br /&gt;
join   v$pdbs pdb&lt;br /&gt;
       on ( obj.con_id  = pdb.con_id )&lt;br /&gt;
where  trgs.trigger_type     = &amp;#039;AFTER EVENT&amp;#039;&lt;br /&gt;
and    trgs.triggering_event like &amp;#039;LOGON%&amp;#039;&lt;br /&gt;
and    trgs.status           = &amp;#039;ENABLED&amp;#039;&lt;br /&gt;
order  by object_name&lt;br /&gt;
,      obj.last_ddl_time&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===List the pluggable databases (PDB) in a container database (CDB)===&lt;br /&gt;
The network_name column shows what you should find in tnsnames.ora for this db connection&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select name,network_name,pdb from v$services;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select * from v$pdbs;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Start and stop a pluggable database===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter pluggable database pdb1 open;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter pluggable database pdb1 close immediate;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Swith to a pluggable database===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter session set container=pdb1;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Reopen pluggable databases at container startup===&lt;br /&gt;
By default pluggable databases in a container remain in a MOUNT state when the container starts up.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select name, open_mode from v$pdbs where name = &amp;#039;PDB1&amp;#039;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
To modify this, open it and save its state&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter pluggable database pdb1 open;&lt;br /&gt;
alter pluggable database pdb1 save state;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
To see a log of issues with pluggable databases&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select * from pdb_plug_in_violations where type = &amp;#039;ERROR&amp;#039; and status != &amp;#039;RESOLVED&amp;#039; and name = &amp;#039;PDB1&amp;#039;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===What is the current container id in a cdb?===&lt;br /&gt;
CDB$ROOT is container id 1. User containers start from 2.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select sys_context(&amp;#039;USERENV&amp;#039;,&amp;#039;CON_ID&amp;#039;) from dual&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===What is the current container name in a cdb?===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select sys_context(&amp;#039;USERENV&amp;#039;,&amp;#039;CON_NAME&amp;#039;) from dual&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or just&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
show con_name&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Switching Between Containers===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SQL&amp;gt; show con_name&lt;br /&gt;
&lt;br /&gt;
CON_NAME&lt;br /&gt;
------------------------------&lt;br /&gt;
CDB$ROOT&lt;br /&gt;
&lt;br /&gt;
SQL&amp;gt; alter session set container=tstklok;&lt;br /&gt;
&lt;br /&gt;
Session altered.&lt;br /&gt;
&lt;br /&gt;
SQL&amp;gt;  show con_name&lt;br /&gt;
&lt;br /&gt;
CON_NAME&lt;br /&gt;
------------------------------&lt;br /&gt;
TSTKLOK&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Direct connection to pluggable database===&lt;br /&gt;
These must be made using a service (defined in tnsnames.ora). Each pluggable database automatically registers a service with the listener (v$services).&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sqlplus appuser/apppwd@tstklok&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or using ezconnect&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SQL&amp;gt; conn appuser/apppwd@//localhost:1521/tstklok&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===What platform is the database running on?===&lt;br /&gt;
Could be useful for handling line endings...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select platform_name from v$database&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
if instr(db_platform, &amp;#039;WINDOWS&amp;#039;) != 0 then&lt;br /&gt;
    crlf := CHR(13) || CHR(10);       -- Windows gets the \r and \n&lt;br /&gt;
else&lt;br /&gt;
    crlf := CHR (10);                 -- Just \n for the rest of the world&lt;br /&gt;
end if;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Is the database 32 or 64 bit?===&lt;br /&gt;
If the answer is 1,7,10,15,16 or 17, then it is 32bit, everything else should be 64bit.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select platform_id from v$database&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===What features is my database using?===&lt;br /&gt;
Before converting to Standard Edition, check the features here - some may be Enterprise specific.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
col name for a45&lt;br /&gt;
col description for a85&lt;br /&gt;
set lines 2000&lt;br /&gt;
select name&lt;br /&gt;
,      detected_usages&lt;br /&gt;
,      description&lt;br /&gt;
from   dba_feature_usage_statistics&lt;br /&gt;
where  1=1&lt;br /&gt;
and    currently_used = &amp;#039;TRUE&amp;#039;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===How many redo log switches per hour?===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 100&lt;br /&gt;
col &amp;quot;YYYYMMDD HH24&amp;quot; for a14&lt;br /&gt;
select to_char(first_time,&amp;#039;yyyymmdd hh24&amp;#039;) &amp;quot;YYYYMMDD HH24&amp;quot;&lt;br /&gt;
,      count(1)                            num_switches&lt;br /&gt;
from   v$log_history&lt;br /&gt;
group  by to_char(first_time,&amp;#039;yyyymmdd hh24&amp;#039;)&lt;br /&gt;
order  by 1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or a bit fancier version...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rem *********************************************************** &lt;br /&gt;
rem&lt;br /&gt;
rem	File: log_history.sql &lt;br /&gt;
rem	Description: Log switch rates from v$log_history &lt;br /&gt;
rem   &lt;br /&gt;
rem	From &amp;#039;Oracle Performance Survival Guide&amp;#039; by Guy Harrison&lt;br /&gt;
rem		Chapter 21 Page 637&lt;br /&gt;
rem		ISBN: 978-0137011957&lt;br /&gt;
rem		See www.guyharrison.net for further information&lt;br /&gt;
rem  &lt;br /&gt;
rem		This work is in the public domain NSA &lt;br /&gt;
rem   &lt;br /&gt;
rem&lt;br /&gt;
rem ********************************************************* &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
col min_minutes format 9999.99 &lt;br /&gt;
col max_minutes format 9999.99 &lt;br /&gt;
col avg_minutes format 9999.99 &lt;br /&gt;
set pagesize 1000&lt;br /&gt;
set lines 70&lt;br /&gt;
set echo on &lt;br /&gt;
&lt;br /&gt;
WITH log_history AS&lt;br /&gt;
       (SELECT thread#, first_time,&lt;br /&gt;
               LAG(first_time) OVER (ORDER BY thread#, sequence#)&lt;br /&gt;
                  last_first_time,&lt;br /&gt;
               (first_time&lt;br /&gt;
                - LAG(first_time) OVER (ORDER BY thread#, sequence#))&lt;br /&gt;
                    * 24* 60   last_log_time_minutes,&lt;br /&gt;
               LAG(thread#) OVER (ORDER BY thread#, sequence#)&lt;br /&gt;
                   last_thread#&lt;br /&gt;
        FROM v$log_history)&lt;br /&gt;
SELECT ROUND(MIN(last_log_time_minutes), 2) min_minutes,&lt;br /&gt;
       ROUND(MAX(last_log_time_minutes), 2) max_minutes,&lt;br /&gt;
       ROUND(AVG(last_log_time_minutes), 2) avg_minutes&lt;br /&gt;
FROM log_history&lt;br /&gt;
WHERE     last_first_time IS NOT NULL&lt;br /&gt;
      AND last_thread# = thread#&lt;br /&gt;
      AND first_time &amp;gt; SYSDATE - 1; &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Show redo log groups/members===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
col instance       for a8&lt;br /&gt;
col thread         for 999&lt;br /&gt;
col groupno        for 999&lt;br /&gt;
col member         for a35&lt;br /&gt;
col redo_file_type for a15&lt;br /&gt;
col log_status     for a10&lt;br /&gt;
col logsize_m      for 99999&lt;br /&gt;
col archived       for a12&lt;br /&gt;
&lt;br /&gt;
SELECT i.instance_name   instance&lt;br /&gt;
,      i.thread#         thread&lt;br /&gt;
,      f.group#          groupno&lt;br /&gt;
,      f.member          member&lt;br /&gt;
,      f.type            redo_file_type&lt;br /&gt;
,      l.status          log_status&lt;br /&gt;
,      l.bytes/1024/1024 logsize_m&lt;br /&gt;
,      l.archived        archived&lt;br /&gt;
FROM   gv$logfile  f&lt;br /&gt;
,      gv$log      l&lt;br /&gt;
,      gv$instance i&lt;br /&gt;
WHERE  1=1&lt;br /&gt;
and    f.group#  = l.group#&lt;br /&gt;
AND    l.thread# = i.thread#&lt;br /&gt;
AND    i.inst_id = f.inst_id&lt;br /&gt;
AND    f.inst_id = l.inst_id&lt;br /&gt;
ORDER  BY i.instance_name&lt;br /&gt;
,      f.group#&lt;br /&gt;
,      f.member;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Korn shell timestamp function===&lt;br /&gt;
Example usage: echo &amp;quot;`ts`: Checking backup status&amp;quot;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
function ts {&lt;br /&gt;
    date +&amp;#039;%d-%b-%Y %H:%M:%S&amp;#039;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Drop a database===&lt;br /&gt;
Dropping a database including backups should be considered criminal in a production environment!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sqlplus / as sysdba&lt;br /&gt;
startup force mount exclusive restrict&lt;br /&gt;
exit&lt;br /&gt;
rman target /&lt;br /&gt;
drop database including backups noprompt;&lt;br /&gt;
exit&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
RMAN&amp;gt; connect target sys/pass@test&lt;br /&gt;
connected to target database: test (dbid=123456789)&lt;br /&gt;
&lt;br /&gt;
RMAN&amp;gt; startup force mount&lt;br /&gt;
RMAN&amp;gt; sql &amp;#039;alter system enable restricted session&amp;#039;;&lt;br /&gt;
RMAN&amp;gt; drop database including backups noprompt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Use sub-select or in-line views to update base tables===&lt;br /&gt;
Inline views can be used to update base table data&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
update&lt;br /&gt;
    (&lt;br /&gt;
    select p.list_price&lt;br /&gt;
    from   products           p&lt;br /&gt;
    ,      product_categories pc&lt;br /&gt;
    where  1=1&lt;br /&gt;
    and    p.category_id    = pc.category_id&lt;br /&gt;
    and    pc.category_name = &amp;#039;CPU&amp;#039;&lt;br /&gt;
    )&lt;br /&gt;
set list_price = list_price * 1.15; &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Use sub-select or in-line views to delete base table data===&lt;br /&gt;
A different way to delete rows in base tables, using Inline views or subselect&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
delete&lt;br /&gt;
    (&lt;br /&gt;
    select p.list_price&lt;br /&gt;
    from   products           p&lt;br /&gt;
    ,      product_categories pc&lt;br /&gt;
    where  1=1&lt;br /&gt;
    and    p.category_id    = pc.category_id&lt;br /&gt;
    and    pc.category_name = &amp;#039;CPU&amp;#039;&lt;br /&gt;
    )&lt;br /&gt;
where list_price &amp;lt; 1000; &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Mass update of files using perl inline script===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
for server in `cat /home/tools/etc/oracle/oracle_servers`; do&lt;br /&gt;
    ssh $server “perl -p -i -e &amp;#039;s/T01/D01/&amp;#039; /home/tools/scripts/rman/inclexcl.lst”&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===How to use vi-style editing in SQL*Plus===&lt;br /&gt;
These instructions are for Redhat but other versions will be very similar&lt;br /&gt;
* Download rlwrap from [http://dl.fedoraproject.org/pub/epel/5/x86_64/repoview/rlwrap.html] or [http://dl.fedoraproject.org/pub/epel/6/x86_64/repoview/rlwrap.html]&lt;br /&gt;
* sudo yum install rlwrap&lt;br /&gt;
* build a dictionary file for autocomplete on pressing Tab&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
vi $HOME/sql.dict&lt;br /&gt;
select&lt;br /&gt;
from&lt;br /&gt;
dba_users&lt;br /&gt;
dba_data_files&lt;br /&gt;
dba_tablespaces&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alias sysdba=&amp;#039;rlwrap -f $HOME/sql.dict sqlplus / as sysdba&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or for general command use...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alias sqlplus=&amp;#039;rlwrap -D2 -ic sqlplus&amp;#039;&lt;br /&gt;
alias dgmgrl=&amp;#039;rlwrap -D2 -ic dgmgrl&amp;#039;&lt;br /&gt;
alias rman=&amp;#039;rlwrap -D2 -ic rman&amp;#039;&lt;br /&gt;
alias asmcmd=&amp;#039;rlwrap -D2 -ic asmcmd&amp;#039;&lt;br /&gt;
alias lsnrctl=&amp;#039;rlwrap -D2 -ic lsnrctl&amp;#039;&lt;br /&gt;
alias adrci=&amp;#039;rlwrap -D2 -ic adrci&amp;#039;&lt;br /&gt;
alias impdp=&amp;#039;rlwrap -D2 -ic impdp&amp;#039;&lt;br /&gt;
alias expdp=&amp;#039;rlwrap -D2 -ic expdp&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Execute an SQL statement on all databases on all servers for a customer===&lt;br /&gt;
Run from customer&amp;#039;s management server&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
./dosh -c &amp;quot;su - oracle -c &amp;#039;/home/tools/scripts/oracle/all_db_do -v \&amp;quot;select username, account_status, profile from dba_users order by 3;\&amp;quot;&amp;#039;&amp;quot; &amp;gt;user_status.lst&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SCRIPTS_DIR=/home/tools/scripts/oracle&lt;br /&gt;
$SCRIPTS_DIR/dosh -c &amp;quot;su - oraibm -c \&amp;quot;$SCRIPTS_DIR/all_db_do &amp;#039;alter user ops\\\$oraibm profile oracle_system_user;&amp;#039;\&amp;quot;&amp;quot;&lt;br /&gt;
$SCRIPTS_DIR/dosh2 -c &amp;quot;su - oraibm -c \&amp;quot;$SCRIPTS_DIR/all_db_do &amp;#039;alter user ops$oraibm profile oracle_system_user;&amp;#039;\&amp;quot;&amp;quot;&lt;br /&gt;
$SCRIPTS_DIR/dosh2 -c &amp;quot;su - oraibm -c \&amp;quot;$SCRIPTS_DIR/all_db_do &amp;#039;alter system set control_file_record_keep_time=31;&amp;#039;\&amp;quot;&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Where is the alert log/alertlog?===&lt;br /&gt;
Older systems&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select value from v$parameter where name=&amp;#039;background_dump_dest&amp;#039;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Newer systems&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select value from v$diag_info where name=&amp;#039;Diag Trace&amp;#039;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Grant normal users access to the alertlog table (sys.x$dbgalertext)===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
create view x$dbgalertext_v as select * from x$dbgalertext;&lt;br /&gt;
grant select on x$dbgalertext_v to &amp;amp;&amp;amp;grantee;&lt;br /&gt;
create or replace synonym &amp;amp;grantee..x$dbgalertext for sys.x$dbgalertext_v;&lt;br /&gt;
undef grantee&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Search alert log for ORA-00600 and ORA-07445 errors===&lt;br /&gt;
Scan the database table version of the alertlog for errors without reporting what was already found.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select indx, message_text from x$dbgalertext where message_text like &amp;#039;%ORA-00600%&amp;#039; or message_text like &amp;#039;%ORA-07445%&amp;#039; and indx &amp;gt; &amp;amp;last_queried_indx order by indx desc;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Simulating errors in alert log===&lt;br /&gt;
Sometimes you need to inject error messages into the alertly to test your monitoring system. This generates the entries in the alertlog and in x$dbgalertext table.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
exec sys.dbms_system.ksdwrt(2, &amp;#039;ORA-07445: Testing this error code for Zenoss, do not investigate.&amp;#039;);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This additionally creates a trace file.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
exec sys.dbms_system.ksdwrt(3, &amp;#039;ORA-00600: Testing this error code for Zenoss, do not investigate.&amp;#039;);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===tail the database alert log===&lt;br /&gt;
If an ADR error is displayed, then ORACLE_SID is probably not set&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alias alertlog=&amp;#039;adrci exec=&amp;quot;set home diag/rdbms/$(echo $ORACLE_SID | tr A-Z a-z)/$ORACLE_SID; show alert -tail -f&amp;quot;&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===What is my WAN ip address?===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
curl -A &amp;quot;Mozilla/4.0&amp;quot; http://checkip.dyndns.org/ 2&amp;gt;/dev/null | perl -ne &amp;#039;print $1 if /Current IP Address: (\d+\.\d+\.\d+\.\d+)/&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
curl -A &amp;quot;Mozilla/4.0&amp;quot; http://myip.dnsdynamic.org/ 2&amp;gt;/dev/null&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Wait for child pid to finish in background and report its status===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# submit a process to the background&lt;br /&gt;
export_schema1.ksh &amp;amp;&lt;br /&gt;
bgpid=$!&lt;br /&gt;
&lt;br /&gt;
while (ps -ef | grep $bgpid | grep -v grep); do&lt;br /&gt;
    # still running...&lt;br /&gt;
    sleep 600&lt;br /&gt;
done&lt;br /&gt;
&lt;br /&gt;
# should be finished&lt;br /&gt;
wait $bgpid&lt;br /&gt;
bgstatus=$?&lt;br /&gt;
echo background process ended with status $bgstatus&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/usr/bin/ksh&lt;br /&gt;
# submit a few processes to the background&lt;br /&gt;
# wait for them all to finish&lt;br /&gt;
# concat their logfiles&lt;br /&gt;
&lt;br /&gt;
(./sleeper.sh;echo &amp;quot;sleeper 1 finished&amp;quot;)&amp;gt;sleeper1.log &amp;amp;&lt;br /&gt;
PIDLIST=&amp;quot;$PIDLIST $!&amp;quot;&lt;br /&gt;
echo &amp;quot;PIDLIST is $PIDLIST ...&amp;quot;&lt;br /&gt;
sleep 5&lt;br /&gt;
&lt;br /&gt;
(./sleeper.sh;echo &amp;quot;sleeper 2 finished&amp;quot;)&amp;gt;sleeper2.log &amp;amp;&lt;br /&gt;
PIDLIST=&amp;quot;$PIDLIST $!&amp;quot;&lt;br /&gt;
echo &amp;quot;PIDLIST is $PIDLIST ...&amp;quot;&lt;br /&gt;
sleep 5&lt;br /&gt;
&lt;br /&gt;
(./sleeper.sh;echo &amp;quot;sleeper 3 finished&amp;quot;)&amp;gt;sleeper3.log &amp;amp;&lt;br /&gt;
PIDLIST=&amp;quot;$PIDLIST $!&amp;quot;&lt;br /&gt;
echo &amp;quot;PIDLIST is $PIDLIST ...&amp;quot;&lt;br /&gt;
sleep 5&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;Now 15 seconds later, we have 3 pids: $PIDLIST&amp;quot;&lt;br /&gt;
for PID in $PIDLIST; do&lt;br /&gt;
    wait $PID&lt;br /&gt;
    echo &amp;quot;$PID exited with status $?&amp;quot;&lt;br /&gt;
done&lt;br /&gt;
&lt;br /&gt;
# all jobs should have ended, concat their logs&lt;br /&gt;
cat sleeper*log &amp;gt; sleepers.log&lt;br /&gt;
cat sleepers.log&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Real world example&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/usr/bin/ksh&lt;br /&gt;
# ==============================================================================&lt;br /&gt;
# Name         : export_JDBEOP1.ksh&lt;br /&gt;
# Description  : Run export in pieces for performance reasons&lt;br /&gt;
#&lt;br /&gt;
# Parameters   : &lt;br /&gt;
#&lt;br /&gt;
# Notes        : Also decide whether to exclude PDARC schema or not&lt;br /&gt;
#                depending on what day it is&lt;br /&gt;
#&lt;br /&gt;
#&lt;br /&gt;
# Modification History&lt;br /&gt;
# ====================&lt;br /&gt;
# When      Who               What&lt;br /&gt;
# ========= ================= ==================================================&lt;br /&gt;
# 15-OCT-13 Stuart Barkley    Created&lt;br /&gt;
# ==============================================================================&lt;br /&gt;
&lt;br /&gt;
STARTTIME=`date &amp;#039;+%Y%m%d%H%M%S&amp;#039;`&lt;br /&gt;
DAYNO=`date +%u`&lt;br /&gt;
PROGNAME=`basename $0`&lt;br /&gt;
SCRIPTS_DIR=/home/tools/scripts/oracle&lt;br /&gt;
DATA_DIR=/oracle/JDBEOP1/admin/change&lt;br /&gt;
EXPORT_DIR=/oracle/export/JDBEOP1&lt;br /&gt;
&lt;br /&gt;
# marker so we can find our files later&lt;br /&gt;
MARKERFILE=/tmp/start_$PROGNAME_$$&lt;br /&gt;
touch $MARKERFILE&lt;br /&gt;
&lt;br /&gt;
$SCRIPTS_DIR/expdp_PARFILE.ksh -s JDBEOP1 -u PRODDTA -p 4 -k 2 -f $DATA_DIR/JDBEOP1_PRODDTA.parfile &amp;amp;&lt;br /&gt;
PIDLIST=&amp;quot;$PIDLIST $!&amp;quot;&lt;br /&gt;
echo &amp;quot;PIDLIST is $PIDLIST ...&amp;quot;&lt;br /&gt;
&lt;br /&gt;
$SCRIPTS_DIR/expdp_PARFILE.ksh -s JDBEOP1 -u PRODCTL -p 2 -k 2 -f $DATA_DIR/JDBEOP1_PRODCTL.parfile &amp;amp;&lt;br /&gt;
PIDLIST=&amp;quot;$PIDLIST $!&amp;quot;&lt;br /&gt;
echo &amp;quot;PIDLIST is $PIDLIST ...&amp;quot;&lt;br /&gt;
&lt;br /&gt;
$SCRIPTS_DIR/expdp_PARFILE.ksh -s JDBEOP1 -u NOPRODNOPDARC -p 4 -k 2 -f $DATA_DIR/JDBEOP1_NOPROD_NOPDARC.parfile &amp;amp;&lt;br /&gt;
PIDLIST=&amp;quot;$PIDLIST $!&amp;quot;&lt;br /&gt;
echo &amp;quot;PIDLIST is $PIDLIST ...&amp;quot;&lt;br /&gt;
&lt;br /&gt;
if [[ $DAYNO -eq 1 ]]; then&lt;br /&gt;
    $SCRIPTS_DIR/expdp_PARFILE.ksh -s JDBEOP1 -u NOPROD -p 4 -k 2 -f $DATA_DIR/JDBEOP1_NOPROD.parfile &amp;amp;&lt;br /&gt;
    PIDLIST=&amp;quot;$PIDLIST $!&amp;quot;&lt;br /&gt;
    echo &amp;quot;PIDLIST is $PIDLIST ...&amp;quot;&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
# now sit and wait for the exports to finish&lt;br /&gt;
for PID in $PIDLIST; do&lt;br /&gt;
    echo &amp;quot;waiting for pid $PID to finish&amp;quot;&lt;br /&gt;
    wait $PID&lt;br /&gt;
    echo &amp;quot;$PID exited with status $?&amp;quot;&lt;br /&gt;
done&lt;br /&gt;
&lt;br /&gt;
# collect all log files up into one&lt;br /&gt;
cd $EXPORT_DIR&lt;br /&gt;
for i in `find . -name &amp;quot;expdp_JDBEOP1*log&amp;quot; -newer $MARKERFILE`; do&lt;br /&gt;
    cat $i &amp;gt; expdp_JDBEOP1_D_FULL_${STARTTIME}.log&lt;br /&gt;
done&lt;br /&gt;
&lt;br /&gt;
rm $MARKLERFILE&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Create private DB link for a user without knowing his password===&lt;br /&gt;
* Inspired by [http://oradbatips.blogspot.co.uk/2010/01/tip-84-create-private-db-link-for-user.html oradbatips.blogspot.co.uk]&lt;br /&gt;
It uses a clever package, dbms_sys_sql.&amp;lt;br /&amp;gt;&lt;br /&gt;
Also useful for executing anything on behalf of another user.&amp;lt;br /&amp;gt;&lt;br /&gt;
Here is an example on how to create private database link for a user.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
create or replace procedure link_creator ( p_owner varchar2, p_dblink_name varchar2, p_username varchar2, p_password varchar2, p_address varchar2 ) as&lt;br /&gt;
    uid number;&lt;br /&gt;
    sqltext varchar2(1000) := &amp;#039;create [public] database link [link_name] connect to [username] identified by [password] using &amp;#039;&amp;#039;[address]&amp;#039;&amp;#039;&amp;#039;;&lt;br /&gt;
    myint integer;&lt;br /&gt;
begin&lt;br /&gt;
    if upper(p_owner) = &amp;#039;PUBLIC&amp;#039; then&lt;br /&gt;
        sqltext := replace(sqltext, &amp;#039;[public]&amp;#039;, &amp;#039;public&amp;#039;);&lt;br /&gt;
    else&lt;br /&gt;
        sqltext := replace(sqltext, &amp;#039;[public]&amp;#039;, &amp;#039;&amp;#039;);&lt;br /&gt;
    end if;&lt;br /&gt;
    sqltext := replace(sqltext, &amp;#039;[linkname]&amp;#039;, p_dblink_name);&lt;br /&gt;
    sqltext := replace(sqltext, &amp;#039;[username]&amp;#039;, p_username);&lt;br /&gt;
    sqltext := replace(sqltext, &amp;#039;[password]&amp;#039;, p_password);&lt;br /&gt;
    sqltext := replace(sqltext, &amp;#039;[address]&amp;#039;, p_address);&lt;br /&gt;
&lt;br /&gt;
    select user_id&lt;br /&gt;
    into   uid&lt;br /&gt;
    from   dba_users&lt;br /&gt;
    where  username = decode(upper(p_owner), &amp;#039;PUBLIC&amp;#039;, &amp;#039;SYS&amp;#039;, p_owner)&lt;br /&gt;
    ;&lt;br /&gt;
    myint:=sys.dbms_sys_sql.open_cursor();&lt;br /&gt;
    sys.dbms_sys_sql.parse_as_user ( myint, sqltext, dbms_sql.native, uid );&lt;br /&gt;
    sys.dbms_sys_sql.close_cursor(myint);&lt;br /&gt;
end;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Here we can generate SQL to rebuild the links for future use. Note the password is no longer stored in this column.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set pages 1000&lt;br /&gt;
select &amp;#039;begin link_creator ( &amp;#039;&amp;#039;&amp;#039;|| u.name ||&amp;#039;&amp;#039;&amp;#039;,&amp;#039;&amp;#039;&amp;#039;|| l.name ||&amp;#039;&amp;#039;&amp;#039;,&amp;#039;&amp;#039;&amp;#039;|| l.userid ||&amp;#039;&amp;#039;&amp;#039;,&amp;#039;&amp;#039;&amp;#039;|| l.password ||&amp;#039;&amp;#039;&amp;#039;,&amp;#039;&amp;#039;&amp;#039;|| l.host ||&amp;#039;&amp;#039;&amp;#039;); end;&amp;#039;|| chr(10) ||&amp;#039;/&amp;#039; link_text&lt;br /&gt;
from   sys.link$ l&lt;br /&gt;
,      sys.user$ u&lt;br /&gt;
where  l.owner# = u.user#&lt;br /&gt;
;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Another method to create a db_link from sys on behalf of a user is to create a procedure under that users name that does the db link creation====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
grant create database link to &amp;amp;&amp;amp;user;&lt;br /&gt;
&lt;br /&gt;
create or replace procedure &amp;amp;user..create_db_link as&lt;br /&gt;
begin&lt;br /&gt;
    execute immediate &amp;#039;create database link &amp;amp;link_name connect to &amp;amp;user identified by &amp;amp;users_password using &amp;#039;&amp;#039;&amp;amp;tns_connect_identifier&amp;#039;&amp;#039;&amp;#039;;&lt;br /&gt;
end create_db_link;&lt;br /&gt;
&lt;br /&gt;
exec &amp;amp;user..create_db_link;&lt;br /&gt;
&lt;br /&gt;
revoke create database link from &amp;amp;user;&lt;br /&gt;
&lt;br /&gt;
drop procedure &amp;amp;user..create_db_link;&lt;br /&gt;
undef user&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Create a comma separated list of columns from a select statement===&lt;br /&gt;
Method 1:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SELECT parent_id,&lt;br /&gt;
       RTRIM(XMLAGG(XMLELEMENT(e,child_id || &amp;#039;,&amp;#039;)).EXTRACT(&amp;#039;//text()&amp;#039;),&amp;#039;,&amp;#039;) AS &amp;quot;Children&amp;quot;&lt;br /&gt;
FROM   parentChildTable&lt;br /&gt;
WHERE  parent_id = 0&lt;br /&gt;
GROUP  BY parent_id&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SELECT parent_id,&lt;br /&gt;
       LISTAGG(child_id, &amp;#039;,&amp;#039;) WITHIN GROUP (ORDER BY child_id) AS &amp;quot;Children&amp;quot;&lt;br /&gt;
  FROM parentChildTable&lt;br /&gt;
 WHERE parent_id = 0&lt;br /&gt;
 GROUP BY parent_id&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Method 2 (undocumented and cannot therefore be relied on to continue working in the same manner):&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SELECT wmsys.wm_concat(&amp;lt;column_name&amp;gt;)&lt;br /&gt;
FROM &amp;lt;table_name&amp;gt;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Start an instant one-line webserver in current directory===&lt;br /&gt;
Need to quickly share/copy a file or read an html file on Linux? Start a web server!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
python -m SimpleHTTPServer 8000&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
and point your browser to http://localhost:8000&amp;lt;br /&amp;gt;&lt;br /&gt;
or&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
while true; do nc -l -p 80 -q 1 &amp;lt; index.html; done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Get SQL*Plus to generate HTML===&lt;br /&gt;
* [http://docs.oracle.com/cd/E11882_01/server.112/e16604/ch_seven.htm#CHDCECJG official guide]&lt;br /&gt;
One way to do it... use -m(arkup) option to specify:&amp;lt;br /&amp;gt;&lt;br /&gt;
html on/off - specifies whether to output html output or not&lt;br /&gt;
head - specify your own customised head contents&amp;lt;br /&amp;gt;&lt;br /&gt;
spool off - as a part of the -m tag means do not print the default &amp;amp;lt;html&amp;amp;gt;, &amp;amp;lt;head&amp;amp;gt; and &amp;amp;lt;body&amp;amp;gt; tags&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sqlplus -m &amp;quot;html on head &amp;#039;&amp;lt;link rel=&amp;quot;stylesheet&amp;quot; href=&amp;quot;/dbamon_golden.css&amp;quot; type=&amp;quot;text/css&amp;quot; /&amp;gt;&amp;#039; spool off&amp;quot; / as sysdba&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sqlplus / as sysdba&lt;br /&gt;
set markup html on head &amp;#039;&amp;lt;link rel=&amp;quot;stylesheet&amp;quot; href=&amp;quot;/dbamon_golden.css&amp;quot; type=&amp;quot;text/css&amp;quot; /&amp;gt;&amp;#039; body &amp;quot;&amp;quot; table &amp;quot;&amp;quot; spool off&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
besides html and head, you can also specify:&amp;lt;br /&amp;gt;&lt;br /&gt;
body - specify your own customised body attributes&amp;lt;br /&amp;gt;&lt;br /&gt;
table - override the default table options&amp;lt;br /&amp;gt;&lt;br /&gt;
entmap - turn on or off the html replacement characters (&amp;amp;lt, &amp;amp;gt, etc...)&amp;lt;br /&amp;gt;&lt;br /&gt;
preformat - uses the &amp;amp;lt;pre&amp;amp;gt; tag to format output exactly as required&amp;lt;br /&amp;gt;&lt;br /&gt;
* another little gem...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
----------------------------------------&lt;br /&gt;
-- get the last SQL*Plus output in HTML&lt;br /&gt;
-- after Tanel Poder&lt;br /&gt;
----------------------------------------&lt;br /&gt;
&lt;br /&gt;
set termout off&lt;br /&gt;
&lt;br /&gt;
set markup HTML ON HEAD &amp;quot; -&lt;br /&gt;
 -&lt;br /&gt;
&amp;quot; -&lt;br /&gt;
BODY &amp;quot;&amp;quot; -&lt;br /&gt;
TABLE &amp;quot;border=&amp;#039;1&amp;#039; align=&amp;#039;center&amp;#039; summary=&amp;#039;Script output&amp;#039;&amp;quot; -&lt;br /&gt;
SPOOL ON ENTMAP ON PREFORMAT OFF&lt;br /&gt;
&lt;br /&gt;
spool myoutput.html&lt;br /&gt;
&lt;br /&gt;
l&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
spool off&lt;br /&gt;
set markup html off spool off&lt;br /&gt;
host firefox myoutput.html&lt;br /&gt;
set termout on&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===HTML SELECT - Trigger JavaScript ONCHANGE event even when the option is not changed===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;select onchange=&amp;quot;jsFunction()&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;option value=&amp;quot;&amp;quot; disabled selected style=&amp;quot;display:none;&amp;quot;&amp;gt;Label&amp;lt;/option&amp;gt;&lt;br /&gt;
  &amp;lt;option value=&amp;quot;1&amp;quot;&amp;gt;1&amp;lt;/option&amp;gt;&lt;br /&gt;
  &amp;lt;option value=&amp;quot;2&amp;quot;&amp;gt;2&amp;lt;/option&amp;gt;&lt;br /&gt;
  &amp;lt;option value=&amp;quot;3&amp;quot;&amp;gt;3&amp;lt;/option&amp;gt;&lt;br /&gt;
&amp;lt;/select&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Display horizontal bar graph in HTML table data cell===&lt;br /&gt;
Using Perl&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
print (&amp;#039;&amp;lt;td class=&amp;quot;left&amp;quot;&amp;gt;&amp;#039; .&lt;br /&gt;
            &amp;#039;&amp;lt;div style=&amp;quot;background-color:#8097BE;width:&amp;quot;&amp;#039;,$allocpercused  ,&amp;#039;%;&amp;quot; /&amp;gt;&amp;#039; .&lt;br /&gt;
            &amp;#039;&amp;lt;div style=&amp;quot;background-color:red;    width:&amp;quot;&amp;#039;,$automaxpercused,&amp;#039;%;&amp;quot; /&amp;gt;&amp;#039; .&lt;br /&gt;
            $tspace .&lt;br /&gt;
       &amp;#039;&amp;lt;/td&amp;gt;&amp;#039;&lt;br /&gt;
);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Depending on which way around the divs are, you get different interpretations&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
print (&amp;quot;&amp;lt;td class=\&amp;quot;left\&amp;quot;&amp;gt;&amp;quot; .&lt;br /&gt;
            &amp;quot;&amp;lt;div style=\&amp;quot;border-right:2px solid red; width:&amp;quot;,($automaxpercused&amp;gt;99)?(100):($automaxpercused),&amp;quot;%;\&amp;quot; /&amp;gt;&amp;quot; .&lt;br /&gt;
            &amp;quot;&amp;lt;div style=\&amp;quot;background-color:#8097BE;width:&amp;quot;,$allocpercused  ,&amp;quot;%;\&amp;quot; /&amp;gt;&amp;quot; .&lt;br /&gt;
            $tspace .&lt;br /&gt;
       &amp;quot;&amp;lt;/td&amp;gt;&amp;quot;&lt;br /&gt;
);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====References====&lt;br /&gt;
* [http://stackoverflow.com/questions/5324996/comma-separated-list-as-a-result-of-select-statement-in-oracle stackoverflow.com]&lt;br /&gt;
* [http://www.salvis.com/blog/?p=207 A whole page showing how to do it in all versions back to 7!]&lt;/div&gt;</summary>
		<author><name>Stuart</name></author>	</entry>

	<entry>
		<id>https://mailnest.com/dbawiki/index.php?title=Snippets&amp;diff=3366</id>
		<title>Snippets</title>
		<link rel="alternate" type="text/html" href="https://mailnest.com/dbawiki/index.php?title=Snippets&amp;diff=3366"/>
				<updated>2018-11-04T00:58:27Z</updated>
		
		<summary type="html">&lt;p&gt;Stuart: /* Invisible / hidden / virtual columns */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;===Protecting an Apache Web Server directory with htaccess===&lt;br /&gt;
* [https://davidwalsh.name/password-protect-directory-using-htaccess https://davidwalsh.name/password-protect-directory-using-htaccess]&lt;br /&gt;
* [http://www.htaccesstools.com/articles/password-protection/ http://www.htaccesstools.com/articles/password-protection/]&lt;br /&gt;
Two files are needed.&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;The .htaccess Code&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
AuthType Basic&lt;br /&gt;
AuthName &amp;quot;restricted area&amp;quot;&lt;br /&gt;
AuthUserFile /home/davidwalsh/html/protect-me-dir/.htpasswd&lt;br /&gt;
require valid-user&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;The .htpasswd Code&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
davidwalsh:daWHfZrDLB88.&lt;br /&gt;
rodstewart:roFulYxC2.8ws&lt;br /&gt;
cssexpert:csmnmq.M8T5ho&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Protecting a lighttpd directory with htaccess===&lt;br /&gt;
Generate an MD5 hash with the tools above and paste into this file&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
vi /etc/lighttpd/.htpasswd&lt;br /&gt;
stuart:3#$567890#$56789056789&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Check modules.conf file to ensure mod_auth and mod_rewrite are enabled&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
vi /etc/lighttpd/modules.conf&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Alter the lighttpd.conf file to allow the authentication&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#auth directives&lt;br /&gt;
auth.backend = &amp;quot;htpasswd&amp;quot;&lt;br /&gt;
auth.backend.htpasswd.userfile = &amp;quot;/etc/lighttpd/.htpasswd&amp;quot;&lt;br /&gt;
auth.debug = 1&lt;br /&gt;
$HTTP[&amp;quot;url&amp;quot;] =~ &amp;quot;^/cgi-bin&amp;quot; {&lt;br /&gt;
        auth.require = ( &amp;quot;&amp;quot; =&amp;gt;&lt;br /&gt;
        (&lt;br /&gt;
        &amp;quot;method&amp;quot; =&amp;gt; &amp;quot;basic&amp;quot;,&lt;br /&gt;
        &amp;quot;realm&amp;quot; =&amp;gt; &amp;quot;DbaHawk access&amp;quot;,&lt;br /&gt;
        &amp;quot;require&amp;quot; =&amp;gt; &amp;quot;valid-user&amp;quot;&lt;br /&gt;
        ) )&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Restart the lighttpd server&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
systemctl stop lighttpd&lt;br /&gt;
systemctl start lighttpd&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
I tried it with htdigest but could not get it to protest the directory!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#auth.backend = &amp;quot;htdigest&amp;quot;&lt;br /&gt;
#auth.backend.htdigest.userfile = &amp;quot;/etc/lighttpd/lighttpd.user.htdigest&amp;quot;&lt;br /&gt;
#auth.require = (&lt;br /&gt;
#    &amp;quot;/var/www/cgi-bin/&amp;quot; =&amp;gt; (&lt;br /&gt;
#    &amp;quot;method&amp;quot;  =&amp;gt; &amp;quot;basic&amp;quot;,&lt;br /&gt;
#    &amp;quot;realm&amp;quot;   =&amp;gt; &amp;quot;DbaHawk access&amp;quot;,&lt;br /&gt;
#    &amp;quot;require&amp;quot; =&amp;gt; &amp;quot;valid-user&amp;quot;&lt;br /&gt;
#    ),&lt;br /&gt;
#)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Rename a datafile if the filename contains junk / unprintable characters===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter tablespace ts_thaler_data offline;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Oracle have a document that describes a few ways of doing it in [https://support.oracle.com/rs?type=doc&amp;amp;id=824473.1 Note 824473.1]&lt;br /&gt;
If the filename contains control characters and cannot be selected in the normal way, use ls -ali to find the node number and then use find with -inum to rename (or move) the file&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ls -baltri&lt;br /&gt;
total 47474984&lt;br /&gt;
12409 -rw-r-----    1 oracle   oinstall 1073750016 Sep 26 13:56 ts_thaler_data_02\1776.dbf&lt;br /&gt;
12350 -rw-r-----    1 oracle   oinstall 5242888192 Sep 26 13:56 ts_thaler_data_01.dbf&lt;br /&gt;
&lt;br /&gt;
find . -inum 12409 -exec mv {} ts_thaler_data_06.dbf \;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Work out what the database thinks the name is and rename it there too! AskTom has a discussion on it [https://asktom.oracle.com/pls/apex/asktom.search?tag=rename-datafile-with-dummy-characters-after-dbf here]&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select substr(name,i,1),ascii(substr(name,i,1)) from ( select name from v$datafile where file# = 9), ( select rownum i from dual connect by level &amp;lt;= 50);&lt;br /&gt;
SUBS ASCII(SUBSTR(NAME,I,1))&lt;br /&gt;
---- -----------------------&lt;br /&gt;
t                        116&lt;br /&gt;
s                        115&lt;br /&gt;
_                         95&lt;br /&gt;
t                        116&lt;br /&gt;
h                        104&lt;br /&gt;
a                         97&lt;br /&gt;
l                        108&lt;br /&gt;
e                        101&lt;br /&gt;
r                        114&lt;br /&gt;
_                         95&lt;br /&gt;
d                        100&lt;br /&gt;
a                         97&lt;br /&gt;
t                        116&lt;br /&gt;
a                         97&lt;br /&gt;
_                         95&lt;br /&gt;
0                         48&lt;br /&gt;
2                         50&lt;br /&gt;
                         127&lt;br /&gt;
2                         50&lt;br /&gt;
.                         46&lt;br /&gt;
d                        100&lt;br /&gt;
b                         98&lt;br /&gt;
f                        102&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
You can see there&amp;#039;s a 127 just before the .dbf... this crept in a the backspace key was not working correctly.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set serveroutput on&lt;br /&gt;
declare&lt;br /&gt;
   fname1 varchar2(100);&lt;br /&gt;
   fname2 varchar2(100);&lt;br /&gt;
begin&lt;br /&gt;
  select name into fname1 from v$datafile where file# = 9;&lt;br /&gt;
  fname2 := replace(fname1,chr(127));&lt;br /&gt;
  &lt;br /&gt;
  dbms_output.put_line(&amp;#039;alter database rename file &amp;#039;&amp;#039;&amp;#039;||fname1||&amp;#039;&amp;#039;&amp;#039; to &amp;#039;&amp;#039;&amp;#039;||fname2||&amp;#039;&amp;#039;&amp;#039;&amp;#039;);&lt;br /&gt;
  execute immediate &amp;#039;alter database rename file &amp;#039;&amp;#039;&amp;#039;||fname1||&amp;#039;&amp;#039;&amp;#039; to &amp;#039;&amp;#039;&amp;#039;||fname2||&amp;#039;&amp;#039;&amp;#039;&amp;#039;;&lt;br /&gt;
end;&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
alter tablespace ts_thaler_data_online;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Generate creation of directory names from dba_directories===&lt;br /&gt;
Before deleting or dropping directories in the database, use this script to generate the create statements&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select &amp;#039;create or replace directory &amp;#039;||directory_name||&amp;#039; as &amp;#039;&amp;#039;&amp;#039;||directory_path||&amp;#039;&amp;#039;&amp;#039;;&amp;#039; from dba_directories;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Check if current (dot) directory is in PATH variable===&lt;br /&gt;
Using bareword comparison to check PATH variable&amp;lt;pre&amp;gt;&lt;br /&gt;
if [[ :$PATH: == *:&amp;quot;.&amp;quot;:* ]] ; then&lt;br /&gt;
    echo &amp;quot;in path&amp;quot;&lt;br /&gt;
else&lt;br /&gt;
    echo &amp;quot;not in path&amp;quot;&lt;br /&gt;
fi&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===tail a logfile from within the script you are writing it to===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#&lt;br /&gt;
# display logfile in real time&lt;br /&gt;
#&lt;br /&gt;
( tail -0f ${LOGFILE} ) &amp;amp;&lt;br /&gt;
tailPID=$!&lt;br /&gt;
&lt;br /&gt;
trap &amp;quot;kill $tailPID&amp;quot; 0 1 2 3 5 9 15&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Dump package, procedure etc. from dba_source in a way that it can be used to recreate it===&lt;br /&gt;
From [https://asktom.oracle.com/pls/apex/f?p=100:11:0::::P11_QUESTION_ID:454220160386 Ask Tom]&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 1000 pages 1000 feedb off verif off&lt;br /&gt;
select decode( type||&amp;#039;-&amp;#039;||to_char(line,&amp;#039;fm99999&amp;#039;), &amp;#039;PACKAGE BODY-1&amp;#039;, &amp;#039;/&amp;#039;||chr(10), null) ||&lt;br /&gt;
       decode(line,1,&amp;#039;create or replace &amp;#039;, &amp;#039;&amp;#039; ) ||&lt;br /&gt;
       text text&lt;br /&gt;
from   dba_source&lt;br /&gt;
where  owner = upper(&amp;#039;&amp;amp;owner&amp;#039;)&lt;br /&gt;
and    name  = upper(&amp;#039;&amp;amp;object_to_show&amp;#039;)&lt;br /&gt;
order  by type&lt;br /&gt;
,      line&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===A trick to exit out of SQL*Plus (using divide by zero) depending on answer to a question===&lt;br /&gt;
This example is taken from ReviewLite.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
-- Settings for customized functionality&lt;br /&gt;
define SCRIPT_OO=_OPTIONS_ONLY -- collect only options information&lt;br /&gt;
define SCRIPT_OO=&amp;#039;&amp;#039;            -- collect all information [default behavior]&lt;br /&gt;
&lt;br /&gt;
define SCRIPT_TS=_TIME_STAMP   -- include timestamp in names of the output directory and output files: YYYY.MM.DD.HH24.MI.SS; script does not prompt for license agreement&lt;br /&gt;
define SCRIPT_TS=&amp;#039;\home\oracle\options&amp;#039;            -- standard names for output directory and output files; script prompts for license agreement [default behavior]&lt;br /&gt;
&lt;br /&gt;
-- PROMT FOR LICENSE AGREEMENT ACCEPTANCE&lt;br /&gt;
DEFINE LANSWER=N&lt;br /&gt;
SET TERMOUT ON&lt;br /&gt;
ACCEPT &amp;amp;SCRIPT_TS LANSWER FORMAT A1 PROMPT &amp;#039;Accept License Agreement? (y\n): &amp;#039;&lt;br /&gt;
&lt;br /&gt;
-- FORCE &amp;quot;divisor is equal to zero&amp;quot; AND SQLERROR EXIT IF NOT ACCEPTED&lt;br /&gt;
-- WILL ALSO CONTINUE IF SCRIPT_TS SUBSTITUTION VARIABLE IS NOT NULL&lt;br /&gt;
SET TERMOUT OFF&lt;br /&gt;
WHENEVER SQLERROR EXIT&lt;br /&gt;
select 1/decode(&amp;#039; &amp;amp;LANSWER&amp;#039;, &amp;#039;Y&amp;#039;, null, &amp;#039;y&amp;#039;, null, decode(&amp;#039; &amp;amp;SCRIPT_TS&amp;#039;, null, 0, null)) as &amp;quot; &amp;quot; from dual;&lt;br /&gt;
WHENEVER SQLERROR CONTINUE&lt;br /&gt;
SET TERMOUT ON&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===How to uninstall optional components such as OWB, APEX, EM, OLAP, OWM from an Oracle database===&lt;br /&gt;
* [http://fast-dba.blogspot.be/2014/04/how-to-remove-unwanted-components-from.html fast-dba.blogspot.be]&lt;br /&gt;
&lt;br /&gt;
===Find unique indexes / primary index / key columns in a table===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
col owner       for a12&lt;br /&gt;
col table_name  for a32&lt;br /&gt;
col column_name for a32&lt;br /&gt;
col position    for 99&lt;br /&gt;
col status      for a10&lt;br /&gt;
set lines 1000 pages 100&lt;br /&gt;
&lt;br /&gt;
SELECT cons.owner&lt;br /&gt;
,      cols.table_name&lt;br /&gt;
,      cols.column_name&lt;br /&gt;
,      cols.position&lt;br /&gt;
,      cons.status&lt;br /&gt;
FROM   all_constraints  cons&lt;br /&gt;
,      all_cons_columns cols&lt;br /&gt;
WHERE  1=1&lt;br /&gt;
and    cols.owner           = &amp;#039;&amp;amp;TABLE_OWNER&amp;#039;&lt;br /&gt;
and    cols.table_name      = &amp;#039;&amp;amp;TABLE_NAME&amp;#039;&lt;br /&gt;
AND    cons.constraint_type = &amp;#039;P&amp;#039;&lt;br /&gt;
AND    cons.constraint_name = cols.constraint_name&lt;br /&gt;
AND    cons.owner           = cols.owner&lt;br /&gt;
ORDER  BY cols.table_name&lt;br /&gt;
,      cols.position&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Display the oracle instances running on the local server===&lt;br /&gt;
sed could be shorter but this one works cross-platform&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alias oenv=&amp;#039;ps -ef|grep pmon|grep -v grep|awk -F_ &amp;quot;{print \$NF}&amp;quot;|sort|uniq|sed -e &amp;quot;:a&amp;quot; -e &amp;quot;N&amp;quot; -e &amp;quot;\$!ba&amp;quot; -e &amp;quot;s/\n/ /g&amp;quot;&amp;#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Display which databases are scheduled for backup in cron===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
for i in `ps -ef | grep [o]ra_pmon | awk -F_ &amp;#039;{print $NF}&amp;#039;`; do&lt;br /&gt;
    crontab -l | grep $i | grep backup_export | awk &amp;#039;{print $2&amp;quot;:&amp;quot;$1&amp;quot; - &amp;quot;$17}&amp;#039;&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Trace SQL statements using autotrace and explain plan===&lt;br /&gt;
If the plustrace (plustrc.sql) role has been granted, explaining sql statements (without running the statement) is as easy as&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter session set sql_trace=true;&lt;br /&gt;
set autotrace traceonly explain&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Write to a trace log from PL/SQL===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
dbms_system.ksdwrt(1,&amp;#039;message sent to a trace file&amp;#039;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Invisible / hidden / virtual columns===&lt;br /&gt;
Article showing how to dump blocks also.&amp;lt;br /&amp;gt;&lt;br /&gt;
[https://www.oracle.com/technetwork/articles/database/invisible-columns-odb12c-2331522.html Tips and Tricks: Invisible Columns in Oracle Database 12c by Alex Zaballa, Oracle Ace and Daniel Da Meda (OCM)]&lt;br /&gt;
&lt;br /&gt;
===Write to the alert log from PL/SQL===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
dbms_system.ksdwrt(2,&amp;#039;message sent to the alert log&amp;#039;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Do distributed SQL transactions exist?===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select * from dba_2pc_pending;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
if yes, and to commit them...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select local_tran_id from dba_2pc_pending;&lt;br /&gt;
exec dbms_transaction.purge_lost_db_entry(&amp;#039;&amp;#039;);&lt;br /&gt;
commit;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Setup optional parameters and default values in an SQL*Plus script===&lt;br /&gt;
Some forgotten SQL*Plus tricks from the good old days and some new ones...&lt;br /&gt;
* [http://www.orafaq.com/wiki/SQL*Plus_FAQ#What_is_the_difference_between_.21_and_HOST.3F orafaq.com]&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set termout off&lt;br /&gt;
col p1 new_value 1&lt;br /&gt;
col p2 new_value 2&lt;br /&gt;
col p3 new_value 3&lt;br /&gt;
select null p1, null p2, null p3 from dual where  1=2;&lt;br /&gt;
select nvl(&amp;#039;&amp;amp;1&amp;#039;,&amp;#039;def1&amp;#039;) p1, nvl(&amp;#039;&amp;amp;2&amp;#039;,&amp;#039;def2&amp;#039;) p2, nvl(&amp;#039;&amp;amp;3&amp;#039;,&amp;#039;def3&amp;#039;) p3 from dual;&lt;br /&gt;
set termout on&lt;br /&gt;
prompt 1=&amp;quot;&amp;amp;1&amp;quot;&lt;br /&gt;
prompt 2=&amp;quot;&amp;amp;2&amp;quot;&lt;br /&gt;
prompt 3=&amp;quot;&amp;amp;3&amp;quot;&lt;br /&gt;
undef 1&lt;br /&gt;
undef 2&lt;br /&gt;
undef 3&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Display / show users with sysdba &amp;amp; sysoper privileges===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select * from v$pwfile_users;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Show path names of data files using instr===&lt;br /&gt;
Use to find the pathnames of all the filesystems/directories in which a database is housed.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select distinct substr(name,1,(instr(name,&amp;#039;/&amp;#039;,-1,1)-1)) path_name from v$datafile&lt;br /&gt;
union&lt;br /&gt;
select distinct substr(name,1,(instr(name,&amp;#039;/&amp;#039;,-1,1)-1)) path_name from v$tempfile&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Does a dataguard standby exist for this database?===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SELECT SUBSTR(value,INSTR(value,&amp;#039;=&amp;#039;,INSTR(UPPER(value),&amp;#039;SERVICE&amp;#039;))+1)&lt;br /&gt;
FROM   v$parameter&lt;br /&gt;
WHERE  name LIKE &amp;#039;log_archive_dest%&amp;#039; AND UPPER(value) LIKE &amp;#039;SERVICE%&amp;#039;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
gives something like this if found...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SUBSTR(VALUE,INSTR(VALUE,&amp;#039;=&amp;#039;,INSTR(UPPER(VALUE),&amp;#039;SERVICE&amp;#039;))+1)&lt;br /&gt;
--------------------------------------------------------------------------------&lt;br /&gt;
&amp;quot;jdbeop1_standby&amp;quot;, LGWR ASYNC NOAFFIRM delay=0 optional compression=disable m&lt;br /&gt;
ax_failure=0 max_connections=1 reopen=300 db_unique_name=&amp;quot;jdbeop1_standby&amp;quot; ne&lt;br /&gt;
t_timeout=60, valid_for=(all_logfiles,primary_role)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===List values for all init parameters in v$parameter (including default values for undocumented (hidden) parameters===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select i.ksppinm||&amp;#039;;&amp;#039;||sv.ksppstvl&lt;br /&gt;
from   x$ksppi  i&lt;br /&gt;
,      x$ksppsv sv&lt;br /&gt;
where  i.indx = sv.indx&lt;br /&gt;
order  by i.ksppinm;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Log file reports pipe errors===&lt;br /&gt;
Found these in the log file&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
solax005:root[/opt/IBM/ITM/logs]# tail solax005_or_RMANV11_col.out&lt;br /&gt;
CIR1880E (024955) Open Probe pipe error 2. Pipe=/opt/IBM/ITM/tmp/solax005_or_RMANV11/prb_RMANV11_kor_solax005_30024832_5346_pipe&lt;br /&gt;
CIR1880E (030938) Open Probe pipe error 2. Pipe=/opt/IBM/ITM/tmp/solax005_or_RMANV11/prb_RMANV11_kor_solax005_30030830_5406_pipe&lt;br /&gt;
CIR1880E (031923) Open Probe pipe error 2. Pipe=/opt/IBM/ITM/tmp/solax005_or_RMANV11/prb_RMANV11_kor_solax005_30031832_5434_pipe&lt;br /&gt;
CIR1880E (033934) Open Probe pipe error 2. Pipe=/opt/IBM/ITM/tmp/solax005_or_RMANV11/prb_RMANV11_kor_solax005_30033831_5495_pipe&lt;br /&gt;
CIR1880E (034918) Open Probe pipe error 2. Pipe=/opt/IBM/ITM/tmp/solax005_or_RMANV11/prb_RMANV11_kor_solax005_30034833_5521_pipe&lt;br /&gt;
CIR1880E (041927) Open Probe pipe error 2. Pipe=/opt/IBM/ITM/tmp/solax005_or_RMANV11/prb_RMANV11_kor_solax005_30041835_5610_pipe&lt;br /&gt;
CIR1880E (042931) Open Probe pipe error 2. Pipe=/opt/IBM/ITM/tmp/solax005_or_RMANV11/prb_RMANV11_kor_solax005_30042832_5642_pipe&lt;br /&gt;
CIR1880E (045928) Open Probe pipe error 2. Pipe=/opt/IBM/ITM/tmp/solax005_or_RMANV11/prb_RMANV11_kor_solax005_30045835_5730_pipe&lt;br /&gt;
CIR1880E (052927) Open Probe pipe error 2. Pipe=/opt/IBM/ITM/tmp/solax005_or_RMANV11/prb_RMANV11_kor_solax005_30052838_5819_pipe&lt;br /&gt;
CIR1880E (090929) Open Probe pipe error 2. Pipe=/opt/IBM/ITM/tmp/solax005_or_RMANV11/prb_RMANV11_kor_solax005_30090833_6487_pipe&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This could be due to a timeout on the pipe.&amp;lt;br /&amp;gt;&lt;br /&gt;
Increase parameters and restart agent. Add following lines to or.config:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
export COLL_WAIT_TIMEOUT=&amp;#039;200&amp;#039;&lt;br /&gt;
export WAIT_TIMEOUT=&amp;#039;200&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Find the most recent archived SCN number===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
col next_change# for 999999999999999&lt;br /&gt;
set numwidth 15&lt;br /&gt;
&lt;br /&gt;
select max(next_change#)&lt;br /&gt;
from   v$archived_log&lt;br /&gt;
where  (thread#, next_change#) in ( select thread#, max(next_change#)&lt;br /&gt;
                                    from   v$archived_log&lt;br /&gt;
                                    where  archived     = &amp;#039;YES&amp;#039;&lt;br /&gt;
                                    and    status       = &amp;#039;A&amp;#039;&lt;br /&gt;
                                    and    resetlogs_id = ( select resetlogs_id&lt;br /&gt;
                                                            from   v$database_incarnation&lt;br /&gt;
                                                            where  status = &amp;#039;CURRENT&amp;#039;&lt;br /&gt;
                                                          )&lt;br /&gt;
                                    group by thread#&lt;br /&gt;
                                  )&lt;br /&gt;
and    status = &amp;#039;A&amp;#039;&lt;br /&gt;
and    resetlogs_id = ( select resetlogs_id&lt;br /&gt;
                        from   v$database_incarnation&lt;br /&gt;
                        where  status = &amp;#039;CURRENT&amp;#039;&lt;br /&gt;
                      )&lt;br /&gt;
order  by next_change# asc;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Monitoring says database inactive===&lt;br /&gt;
* Check the candle user password has not expired in the database.&lt;br /&gt;
* There may be a clue in the log file. Check /opt/IBM/ITM/logs/`hostname`_or_${SID}_col.out&lt;br /&gt;
* Check limits for itmora account in /etc/security/limits. Should be same as oracle user.&lt;br /&gt;
* Check the config file. We had this issue when a new ORACLE_HOME was installed but the cfg file still had the old one in it.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
export ITM_HOME=/opt/IBM/ITM&lt;br /&gt;
cd $ITM_HOME/config&lt;br /&gt;
vi solax005_or_SRV2R.cfg&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#  IBM Tivoli Monitoring for Databases: Oracle Agent&lt;br /&gt;
#  Configuration file: solax005_or_SRV2R.cfg&lt;br /&gt;
#  Written by CandleDBconfig version: 1.4 on 31Jul13 13:39:41&lt;br /&gt;
&lt;br /&gt;
#  Note: this is a Korn-shell script that is &amp;quot;sourced&amp;quot; to create the&lt;br /&gt;
#  environment for a Monitoring Agent for Oracle.  It can be used to create&lt;br /&gt;
#  the environment to run the IBM-supplied database grant scripts.&lt;br /&gt;
&lt;br /&gt;
#  IBM does not recommend that you modify this file, but you can change the&lt;br /&gt;
#  data values or add new exported variables as long as the file is a valid ksh&lt;br /&gt;
#  script that executes with zero return code, and values remain quoted with &amp;quot;&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
#  Following environment variables are set for convenience in running grants.&lt;br /&gt;
   export ORACLE_SID=&amp;quot;SRV2R&amp;quot;&lt;br /&gt;
   export ORACLE_HOME=&amp;quot;/oracle/product/11.2.0.1&amp;quot;&lt;br /&gt;
   # IY92195  COLL_DISABLE_CURSORS setting&lt;br /&gt;
   export TNS_ADMIN=&amp;quot;/oracle/product/11.2.0.1/network/admin&amp;quot;&lt;br /&gt;
&lt;br /&gt;
#  Following variables are set for the setup scripts&lt;br /&gt;
   db_sid=&amp;quot;SRV2R&amp;quot;&lt;br /&gt;
   db_home=&amp;quot;/oracle/product/11.2.0.1&amp;quot;&lt;br /&gt;
   db_initfilename=&amp;quot;&amp;quot;&lt;br /&gt;
   db_login=&amp;quot;tivoli&amp;quot;&lt;br /&gt;
   db_password=&amp;quot;795D8822BC49477323815CD21C1E66E966E48EEE19C6A98056224D649B0FE316E6A11DC3F4E9BB5E226B65A8&amp;quot;&lt;br /&gt;
   db_ver=&amp;quot;11.x&amp;quot;&lt;br /&gt;
   db_type=&amp;quot;kor&amp;quot;&lt;br /&gt;
   db_tns=&amp;quot;/oracle/product/11.2.0.1/network/admin&amp;quot;&lt;br /&gt;
   db_extparms=&amp;quot;&amp;quot;&lt;br /&gt;
   db_hostname=&amp;quot;solax005&amp;quot;&lt;br /&gt;
   db_reason=&amp;quot;AIX_ps_ceww&amp;quot;&lt;br /&gt;
   db_pipedir=&amp;quot;&amp;quot;&lt;br /&gt;
   db_installstatus=&amp;quot;CONFIGSUCCESS&amp;quot;&lt;br /&gt;
&lt;br /&gt;
#  User-defined environment variables&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Solution:&amp;lt;br /&amp;gt;&lt;br /&gt;
* Change all occurrences of 11.2.0.1 to 11.2.0.3&lt;br /&gt;
* Restart agent&lt;br /&gt;
&lt;br /&gt;
===Alerts due to password expiring (or being changed in the database but not in ITM!)===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cd $ITM_HOME/logs&lt;br /&gt;
ls -altr | grep WM820T&lt;br /&gt;
tail -20 solax005_or_WM820T_col.out&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
CGN1521E (161614) Interval collection failed for cursor KORHART2&lt;br /&gt;
RCD0110S (161614) Invalid Oracle logon id (tivoli) or password given&lt;br /&gt;
 Please contact DBA to correct userid or password&lt;br /&gt;
CGN1521E (161614) Interval collection failed for cursor KORHART4&lt;br /&gt;
CGN1525E (161614) One or more interval cursors failed&lt;br /&gt;
RCD0110S (161714) Invalid Oracle logon id (tivoli) or password given&lt;br /&gt;
 Please contact DBA to correct userid or password&lt;br /&gt;
CGN1521E (161714) Interval collection failed for cursor KORHART2&lt;br /&gt;
RCD0110S (161714) Invalid Oracle logon id (tivoli) or password given&lt;br /&gt;
 Please contact DBA to correct userid or password&lt;br /&gt;
CGN1521E (161714) Interval collection failed for cursor KORHART4&lt;br /&gt;
CGN1525E (161714) One or more interval cursors failed&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Solution:&amp;lt;br /&amp;gt;&lt;br /&gt;
* Run agent reconfigure to setup the new password for the candle user (tivoli)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
export ITM_HOME=/opt/IBM/ITM&lt;br /&gt;
$ITM_HOME/bin/itmcmd config -A or&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Restart agent&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
export ITM_HOME=/opt/IBM/ITM&lt;br /&gt;
$ITM_HOME/smitools/scripts/StartAgent.sh restart or -o WM820T&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Many agents started with root user instead of itmora===&lt;br /&gt;
This can happen if the server is rebooted before the agents have been added to the itmora list using kdyedit / kciedit&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
export CANDLEHOME=/opt/IBM/ITM&lt;br /&gt;
export ITM_HOME=/opt/IBM/ITM&lt;br /&gt;
$ITM_HOME/smitools/scripts/kdyedit list&lt;br /&gt;
Type Runas      Inst                &lt;br /&gt;
or   root       AGPDEV              &lt;br /&gt;
or   root       BO1R                &lt;br /&gt;
or   root       DEV3                &lt;br /&gt;
or   root       EMREP               &lt;br /&gt;
or   root       ICR                 &lt;br /&gt;
or   itmora     MAPDEV              &lt;br /&gt;
or   itmora     MAPER               &lt;br /&gt;
or   itmora     PED                 &lt;br /&gt;
or   itmora     PER                 &lt;br /&gt;
or   itmora     RMANV11             &lt;br /&gt;
or   itmora     SRV2R               &lt;br /&gt;
or   itmora     WM820Q              &lt;br /&gt;
or   itmora     WM820T              &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ITM_HOME/smitools/scripts/kciedit list&lt;br /&gt;
Type Runas      Inst                &lt;br /&gt;
or   root       AGPDEV              &lt;br /&gt;
or   root       BO1R                &lt;br /&gt;
or   root       DEV3                &lt;br /&gt;
or   root       EMREP               &lt;br /&gt;
or   root       ICR                 &lt;br /&gt;
or   itmora     MAPDEV              &lt;br /&gt;
or   itmora     MAPER               &lt;br /&gt;
or   itmora     PED                 &lt;br /&gt;
or   itmora     PER                 &lt;br /&gt;
or   itmora     RMANV11             &lt;br /&gt;
or   itmora     SRV2R               &lt;br /&gt;
or   itmora     WM820Q              &lt;br /&gt;
or   itmora     WM820T              &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Solution: Add these instances to the itmora list&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
./kdyedit -t or -i AGPDEV -r itmora add&lt;br /&gt;
./kciedit -t or -i AGPDEV -r itmora add&lt;br /&gt;
...&lt;br /&gt;
./kdyedit -t or -i ICR -r itmora add&lt;br /&gt;
./kciedit -t or -i ICR -r itmora add&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ITM_HOME/smitools/scripts/kciedit list&lt;br /&gt;
Type Runas      Inst                &lt;br /&gt;
or   itmora     AGPDEV              &lt;br /&gt;
or   itmora     BO1R                &lt;br /&gt;
or   itmora     DEV3                &lt;br /&gt;
or   itmora     EMREP               &lt;br /&gt;
or   itmora     ICR                 &lt;br /&gt;
or   itmora     MAPDEV              &lt;br /&gt;
or   itmora     MAPER               &lt;br /&gt;
or   itmora     PED                 &lt;br /&gt;
or   itmora     PER                 &lt;br /&gt;
or   itmora     RMANV11             &lt;br /&gt;
or   itmora     SRV2R               &lt;br /&gt;
or   itmora     WM820Q              &lt;br /&gt;
or   itmora     WM820T              &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Kill any agents still running as root&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ps -ef |grep kor | grep root&lt;br /&gt;
kill -9 &amp;lt;process id&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Because these agents were owned by root, there will be permissions issues when trying to restart the agents with itmora so these need to be fixed before restarting the agents.&amp;lt;br /&amp;gt;&lt;br /&gt;
The simplest way of doing this is to run lockdown.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
export CANDLEHOME=/opt/IBM/ITM&lt;br /&gt;
$CANDLEHOME/smitools/scripts/lockdown.sh&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===See which processes are causing paging===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
svmon -Pt20 | perl -e &amp;#039;while(&amp;lt;&amp;gt;){print if($.==2||$&amp;amp;&amp;amp;&amp;amp;!$s++);$.=0 if(/^-+$/)}&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===How to return several variables from SQL*Plus back to Korn shell script===&lt;br /&gt;
Return multiple columns/elements from Oracle to shell script at the same time&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sqlplus -s sys/${SYS_PASSWORD}@${SID} as sysdba&amp;lt;&amp;lt;EOSQL | read SPACE_AFTER_INSTALL TOTAL_SPACE_AVAILABLE&lt;br /&gt;
set numwid 15 headi off newpa none feedb off&lt;br /&gt;
select sign(${SPACE_USED} + ${SPACE_AVAILABLE} - ${DATABASE_SIZE}), trim(${SPACE_USED} + ${SPACE_AVAILABLE})&lt;br /&gt;
from dual&lt;br /&gt;
/&lt;br /&gt;
EOSQL&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===How to get a shell environment variable from the operating system into the SQL or PL/SQL environment===&lt;br /&gt;
This has been bugging me for years. Something you would think simple... what is ORACLE_HOME? I know it&amp;#039;s a question mark at the SQL prompt but how to get it&amp;#039;s O/S value?&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
declare&lt;br /&gt;
    var1 varchar2(200);&lt;br /&gt;
begin&lt;br /&gt;
    dbms_system.get_env (&amp;#039;ORACLE_HOME&amp;#039;, var1);&lt;br /&gt;
    dbms_output.put_line (&amp;#039;ORACLE_HOME: &amp;#039;||var1);&lt;br /&gt;
end;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or in SQL*Plus&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
variable var1 varchar2(200);&lt;br /&gt;
exec dbms_system.get_env (&amp;#039;ORACLE_HOME&amp;#039;, :var1);&lt;br /&gt;
select :var1 from dual;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
That got me thinking... if this just gets stuff from the environment, it can fetch any exported variable?!?!&amp;lt;br /&amp;gt;&lt;br /&gt;
From the shell:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
export running_sids=`ps -ef | grep [p]mon | awk -F_ &amp;#039;{print $NF}&amp;#039;`&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
and now in SQL*Plus:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
variable sids varchar2(240);&lt;br /&gt;
exec dbms_system.get_env (&amp;#039;running_sids&amp;#039;, :sids);&lt;br /&gt;
select :sids from dual;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Wow!&lt;br /&gt;
&lt;br /&gt;
===How long/wide can a database name/sid be?===&lt;br /&gt;
Depends on where you look but taking the minimum here as &amp;quot;safe&amp;quot;, it should still be limited to 8 characters...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
col table_name for a30&lt;br /&gt;
col data_type  for a12&lt;br /&gt;
select table_name, data_type, data_length from dba_tab_columns where column_name = &amp;#039;DB_NAME&amp;#039;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This is 11gR2&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
TABLE_NAME                     DATA_TYPE    DATA_LENGTH&lt;br /&gt;
------------------------------ ------------ -----------&lt;br /&gt;
LOGMNRG_DICTIONARY$            VARCHAR2               9&lt;br /&gt;
SYS_FBA_CONTEXT_AUD            VARCHAR2             256&lt;br /&gt;
V_$LOGMNR_DICTIONARY           VARCHAR2               9&lt;br /&gt;
V_$LOGMNR_LOGS                 VARCHAR2               8&lt;br /&gt;
GV_$LOGMNR_DICTIONARY          VARCHAR2               9&lt;br /&gt;
GV_$LOGMNR_LOGS                VARCHAR2               8&lt;br /&gt;
V_$LOGMNR_LOGFILE              VARCHAR2               8&lt;br /&gt;
V_$LOGMNR_SESSION              VARCHAR2             128&lt;br /&gt;
GV_$LOGMNR_LOGFILE             VARCHAR2               8&lt;br /&gt;
GV_$LOGMNR_SESSION             VARCHAR2             128&lt;br /&gt;
GV_$ASM_CLIENT                 VARCHAR2               8&lt;br /&gt;
V_$ASM_CLIENT                  VARCHAR2               8&lt;br /&gt;
GV_$IOS_CLIENT                 VARCHAR2              64&lt;br /&gt;
V_$IOS_CLIENT                  VARCHAR2              64&lt;br /&gt;
DBA_PDB_HISTORY                VARCHAR2             128&lt;br /&gt;
CDB_PDB_HISTORY                VARCHAR2             128&lt;br /&gt;
SSCR_CAP$                      VARCHAR2            4000&lt;br /&gt;
SSCR_RES$                      VARCHAR2            4000&lt;br /&gt;
DBA_SSCR_CAPTURE               VARCHAR2            4000&lt;br /&gt;
CDB_SSCR_CAPTURE               VARCHAR2            4000&lt;br /&gt;
DBA_SSCR_RESTORE               VARCHAR2            4000&lt;br /&gt;
CDB_SSCR_RESTORE               VARCHAR2            4000&lt;br /&gt;
WRM$_DATABASE_INSTANCE         VARCHAR2               9&lt;br /&gt;
INT$DBA_HIST_DATABASE_INSTANCE VARCHAR2               9&lt;br /&gt;
DBA_HIST_DATABASE_INSTANCE     VARCHAR2               9&lt;br /&gt;
CDB_HIST_DATABASE_INSTANCE     VARCHAR2               9&lt;br /&gt;
LOGMNR_DICTIONARY$             VARCHAR2               9&lt;br /&gt;
&lt;br /&gt;
27 rows selected.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===What character set (characterset) was the database built with?===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
col name  for a40&lt;br /&gt;
col value for a60&lt;br /&gt;
select * from nls_database_parameters;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
col name   for a40&lt;br /&gt;
col value$ for a60&lt;br /&gt;
select name,value$ from props$ where name = &amp;#039;NLS_CHARACTERSET&amp;#039;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===How to find ORACLE_HOME from pmon process for a SID if there is no entry in oratab===&lt;br /&gt;
If database is created without dbca (datafile and controlfile copy), no entry will be automatically made in /etc/oratab.&amp;lt;br /&amp;gt;&lt;br /&gt;
So the problem is that you need to find out which of the ORACLE_HOMEs is being used by the running instances.&lt;br /&gt;
* Solaris, Linux&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ ps -ef | grep [p]mon&lt;br /&gt;
  oracle 10848     1   0 00:21:20 ?           2:11 ora_pmon_JDBEOP1&lt;br /&gt;
$ pwdx 10848&lt;br /&gt;
10848:  /oracle/JDBEOP1/product/11204/dbs&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* AIX&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ ps -ef | grep [p]mon&lt;br /&gt;
  oracle 13893878        1   0   Aug 12      -  7:53 ora_pmon_GOAQ1&lt;br /&gt;
$ ls -al /proc/13893878/cwd&lt;br /&gt;
lr-x------    2 oracle   dba               0 Aug 12 13:37  cwd -&amp;gt; /data/opt/app/product/11.2.0.4/db_1/dbs/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or&amp;lt;br /&amp;gt;&lt;br /&gt;
This command (ps eww) gives lots of information about the given process (pmon in this case). Tells you where the instance was started, whether it was started from SQL*Plus or RMAN, the http_proxy and loads more useful bits!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ps -ef | grep [p]mon | awk &amp;#039;{print $2}&amp;#039; | xargs -I {} ps eww {} | awk &amp;#039;{print $1 &amp;quot; &amp;quot; $5 &amp;quot; &amp;quot; $6 &amp;quot; &amp;quot; $0}&amp;#039; | sed &amp;#039;s/\(S*\) \(S*\) .*ORACLE_HOME/\1 \2/g&amp;#039; | cut -f1,2,3 -d&amp;quot; &amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Escape the underscore(_) or percent(%) character in an SQL statement===&lt;br /&gt;
The underscore matches any single character so to return data containing an underscore means having to use an escape character.&amp;lt;br /&amp;gt;&lt;br /&gt;
Here I use the backslash(\) so it is easy for Unix people to understand the mechanism.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select username from dba_users where username like &amp;#039;ENDUR\_DEV%&amp;#039; escape &amp;#039;\&amp;#039;; &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Validate, analyse and rebuild indexes===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set feedback off&lt;br /&gt;
set linesize 132&lt;br /&gt;
set serveroutput on&lt;br /&gt;
set trimspool on&lt;br /&gt;
&lt;br /&gt;
declare&lt;br /&gt;
    LOCKED exception;&lt;br /&gt;
    pragma exception_init (LOCKED, -54);&lt;br /&gt;
&lt;br /&gt;
    dbase         char(8);&lt;br /&gt;
    dbuser        varchar2(30);&lt;br /&gt;
    index_name    varchar(30);&lt;br /&gt;
    free_text     varchar2(50);&lt;br /&gt;
    pctused       number;&lt;br /&gt;
    height    number;&lt;br /&gt;
    index_mb      number;&lt;br /&gt;
    analyze_sql   varchar2(100);&lt;br /&gt;
    pct_used_sql  varchar2(150);&lt;br /&gt;
    rebuild_sql   varchar2(150);&lt;br /&gt;
 &lt;br /&gt;
    cursor c1 is&lt;br /&gt;
    select segment_name, bytes&lt;br /&gt;
    from   user_segments&lt;br /&gt;
    where  segment_type = &amp;#039;INDEX&amp;#039;&lt;br /&gt;
    and    segment_name like &amp;#039;DW%&amp;#039;&lt;br /&gt;
    and    segment_name not like &amp;#039;BIN%&amp;#039;&lt;br /&gt;
    and    bytes/1024   &amp;gt;= 1024&lt;br /&gt;
    order  by 2;&lt;br /&gt;
&lt;br /&gt;
-- validate the index&lt;br /&gt;
procedure validate_index (v_ind in varchar2) is&lt;br /&gt;
begin&lt;br /&gt;
    analyze_sql := &amp;#039;analyze index &amp;#039;||v_ind||&amp;#039; validate structure&amp;#039;;&lt;br /&gt;
    begin&lt;br /&gt;
        execute immediate analyze_sql;&lt;br /&gt;
    exception&lt;br /&gt;
    when LOCKED then&lt;br /&gt;
        dbms_output.put_line (v_ind||&amp;#039; locked - skipping&amp;#039;);&lt;br /&gt;
        pctused := 100;&lt;br /&gt;
        return;&lt;br /&gt;
    when others then&lt;br /&gt;
        dbms_output.put_line (analyze_sql);&lt;br /&gt;
        raise;&lt;br /&gt;
    end;&lt;br /&gt;
&lt;br /&gt;
    pct_used_sql := &amp;#039;select pct_used, round(blocks*8192/(1024*1024)), height from index_stats where name = &amp;#039;&amp;#039;&amp;#039;||v_ind||&amp;#039;&amp;#039;&amp;#039;&amp;#039;;&lt;br /&gt;
    execute immediate pct_used_sql into pctused, index_mb, height;&lt;br /&gt;
    if pctused is null then&lt;br /&gt;
        pctused := 0;&lt;br /&gt;
    end if;&lt;br /&gt;
    dbms_output.put_line (rpad(v_ind,35)||&amp;#039; (pct used &amp;#039;||pctused||&amp;#039;% size &amp;#039;||index_mb||&amp;#039;Mb height &amp;#039; || height ||&amp;#039;)&amp;#039;);&lt;br /&gt;
end validate_index;&lt;br /&gt;
 &lt;br /&gt;
-- execute SQL and trace if errors&lt;br /&gt;
procedure run_sql (v_sql in varchar2) is&lt;br /&gt;
begin&lt;br /&gt;
    execute immediate v_sql;&lt;br /&gt;
exception&lt;br /&gt;
when others then&lt;br /&gt;
    dbms_output.put_line (v_sql);&lt;br /&gt;
    raise;&lt;br /&gt;
end run_sql;&lt;br /&gt;
 &lt;br /&gt;
--&lt;br /&gt;
-- Script starts here&lt;br /&gt;
--&lt;br /&gt;
begin&lt;br /&gt;
    dbms_output.enable(1000000);&lt;br /&gt;
    -- Set up database name and schema&lt;br /&gt;
    -- select name into dbase  from v$database;&lt;br /&gt;
    select user into dbuser from dual;&lt;br /&gt;
    dbms_output.put_line(&amp;#039;============================================================================= *&amp;#039;);&lt;br /&gt;
    -- dbms_output.put_line(&amp;#039;* Indexes rebuild report for &amp;#039;||dbuser||&amp;#039; on &amp;#039;||dbase);&lt;br /&gt;
    dbms_output.put_line(&amp;#039;============================================================================= *&amp;#039;);&lt;br /&gt;
&lt;br /&gt;
    -- Loop around Indexes&lt;br /&gt;
    for x in c1 loop&lt;br /&gt;
        index_name := x.segment_name;&lt;br /&gt;
        validate_index (index_name );&lt;br /&gt;
        if pctused &amp;lt; 81 then&lt;br /&gt;
            if x.bytes/1024/1024 &amp;lt; 100 then&lt;br /&gt;
                rebuild_sql := &amp;#039;alter index &amp;#039;||x.segment_name||&amp;#039; rebuild online&amp;#039;;&lt;br /&gt;
            else&lt;br /&gt;
                rebuild_sql := &amp;#039;alter index &amp;#039;||x.segment_name||&amp;#039; coalesce&amp;#039;;&lt;br /&gt;
            end if;&lt;br /&gt;
            dbms_output.put_line (rebuild_sql);&lt;br /&gt;
            run_sql (rebuild_sql);&lt;br /&gt;
            validate_index (index_name);&lt;br /&gt;
        end if;&lt;br /&gt;
    end loop;&lt;br /&gt;
end;&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
set feed on&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Rebuild unusable indexes on a table===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select &amp;#039;alter index &amp;#039;||owner||&amp;#039;.&amp;#039;||index_name||&amp;#039; rebuild;&amp;#039;&lt;br /&gt;
from   dba_indexes&lt;br /&gt;
where  1=1&lt;br /&gt;
and    status    != &amp;#039;VALID&amp;#039;&lt;br /&gt;
and    owner     not in (&amp;#039;SYS&amp;#039;,&amp;#039;SYSTEM&amp;#039;)&lt;br /&gt;
--and    owner      = &amp;#039;WM822PP&amp;#039;&lt;br /&gt;
--and    table_name = &amp;#039;WF_PLANTS&amp;#039;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Pull the latest cfengine changes now instead of waiting for scheduled time===&lt;br /&gt;
For one host&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/opt/cfengine/bin/cfagent -ID dbaTime&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
On all hosts at the same time&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/home/ibmtools/scripts/oracle/dosh -c &amp;quot;/opt/cfengine/bin/cfagent -ID dbaTime&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Check status of datafiles without dba_data_files or v$datafile===&lt;br /&gt;
If the database is in mount mode, most tables are unavailable. This query uses the x$ (c based) tables and are always available&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set linesize 200;&lt;br /&gt;
set pagesize 100;&lt;br /&gt;
col inst_id for 9999999 heading &amp;#039;Instance #&amp;#039;&lt;br /&gt;
col file_nr for 9999999 heading &amp;#039;File #&amp;#039;&lt;br /&gt;
col file_name for A50 heading &amp;#039;File name&amp;#039;&lt;br /&gt;
col checkpoint_change_nr for 99999999999999 heading &amp;#039;Checkpoint #&amp;#039;&lt;br /&gt;
col checkpoint_change_time for A20 heading &amp;#039;Checkpoint time&amp;#039;&lt;br /&gt;
col last_change_nr for 99999999999999 heading &amp;#039;Last change #&amp;#039;&lt;br /&gt;
SELECT&lt;br /&gt;
      fe.inst_id,&lt;br /&gt;
      fe.fenum file_nr,&lt;br /&gt;
      fn.fnnam file_name,&lt;br /&gt;
      TO_NUMBER (fe.fecps) checkpoint_change_nr,&lt;br /&gt;
      fe.fecpt checkpoint_change_time,&lt;br /&gt;
      fe.fests last_change_nr,&lt;br /&gt;
      DECODE (&lt;br /&gt;
              fe.fetsn,&lt;br /&gt;
              0, DECODE (BITAND (fe.festa, 2), 0, &amp;#039;SYSOFF&amp;#039;, &amp;#039;SYSTEM&amp;#039;),&lt;br /&gt;
              DECODE (BITAND (fe.festa, 18),&lt;br /&gt;
                      0, &amp;#039;OFFLINE&amp;#039;,&lt;br /&gt;
                      2, &amp;#039;ONLINE&amp;#039;,&lt;br /&gt;
                      &amp;#039;RECOVER&amp;#039;)&lt;br /&gt;
      ) status&lt;br /&gt;
FROM x$kccfe fe,&lt;br /&gt;
     x$kccfn fn&lt;br /&gt;
WHERE    (   (fe.fepax != 65535 AND fe.fepax != 0 )&lt;br /&gt;
          OR (fe.fepax = 65535 OR fe.fepax = 0)&lt;br /&gt;
         )&lt;br /&gt;
     AND fn.fnfno = fe.fenum&lt;br /&gt;
     AND fe.fefnh = fn.fnnum&lt;br /&gt;
     AND fe.fedup != 0&lt;br /&gt;
     AND fn.fntyp = 4&lt;br /&gt;
     AND fn.fnnam IS NOT NULL&lt;br /&gt;
     AND BITAND (fn.fnflg, 4) != 4&lt;br /&gt;
ORDER BY fe.fenum&lt;br /&gt;
;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Check highest allocated extent in datafile (likely slow when having many extents)===&lt;br /&gt;
* Script to Detect Tablespace Fragmentation ( Doc ID 1020182.6 )&lt;br /&gt;
* How to shrink or reduce the datafile size by finding the high water mark (HWM) ( Doc ID 1600774.1 )&lt;br /&gt;
* How to find Objects Fragmented below High Water Mark ( Doc ID 337651.1 )&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
column file_name format a50;&lt;br /&gt;
column tablespace_name format a15;&lt;br /&gt;
column highwater format 9999999999;&lt;br /&gt;
set pagesize 9999&lt;br /&gt;
&lt;br /&gt;
select a.tablespace_name&lt;br /&gt;
,a.file_name&lt;br /&gt;
,(b.maximum+c.blocks-1)*d.db_block_size highwater&lt;br /&gt;
from dba_data_files a&lt;br /&gt;
,(select file_id,max(block_id) maximum&lt;br /&gt;
from dba_extents&lt;br /&gt;
group by file_id) b&lt;br /&gt;
,dba_extents c&lt;br /&gt;
,(select value db_block_size&lt;br /&gt;
from v$parameter&lt;br /&gt;
where name=&amp;#039;db_block_size&amp;#039;) d&lt;br /&gt;
where a.file_id = b.file_id&lt;br /&gt;
and c.file_id = b.file_id&lt;br /&gt;
and c.block_id = b.maximum&lt;br /&gt;
order by a.tablespace_name,a.file_name&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Runup to this was...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set markup html on spool on&lt;br /&gt;
spool db_info.html&lt;br /&gt;
set echo on&lt;br /&gt;
select * from dba_tablespaces where tablespace_name = &amp;#039;&amp;amp;&amp;amp;tablespace_name&amp;#039;;&lt;br /&gt;
select * from dba_data_files where tablespace_name = &amp;#039;&amp;amp;tablespace_name&amp;#039;;&lt;br /&gt;
select * from (select * from dba_extents where tablespace_name = &amp;#039;&amp;amp;tablespace_name&amp;#039; order by block_id desc) where rownum &amp;lt;301;&lt;br /&gt;
spool off&lt;br /&gt;
set markup html off&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select owner, segment_type, count(*) from dba_segments where tablesapce_name=&amp;#039;&amp;amp;tablespace_name&amp;#039; group by owner, segment_type;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
begin&lt;br /&gt;
for ii in (select owner, segment_name, segment_type from dba_segments where tablespace_name = &amp;#039;&amp;amp;tablespace_name&amp;#039; and segment_type like &amp;#039;TABLE%&amp;#039; and segment_name not like &amp;#039;%DATAPUMP%&amp;#039;)&lt;br /&gt;
loop&lt;br /&gt;
if ii.segment_type=&amp;#039;TABLE&amp;#039; then&lt;br /&gt;
begin&lt;br /&gt;
execute immediate(&amp;#039;alter table &amp;#039;||ii.owner||&amp;#039;.&amp;#039;||ii.segment_name||&amp;#039; enable row movement&amp;#039;);&lt;br /&gt;
execute immediate(&amp;#039;alter table &amp;#039;||ii.owner||&amp;#039;.&amp;#039;||ii.segment_name||&amp;#039; shrink space cascade&amp;#039;);&lt;br /&gt;
exception when others then&lt;br /&gt;
dbms_output.put_line(&amp;#039;FAILED 1: alter table &amp;#039;||ii.owner||&amp;#039;.&amp;#039;||ii.segment_name||&amp;#039; shrink space cascade : &amp;#039;||SQLERRM);&lt;br /&gt;
end;&lt;br /&gt;
end if;&lt;br /&gt;
end loop;&lt;br /&gt;
end;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Procedure to shrink space in tables and indexes===&lt;br /&gt;
* [http://www.oracle-wiki.net/startdocsreallifeshrinkexample Using the Oracle Shrink Command] - lots of good stuff at this site&lt;br /&gt;
Written by [https://asktom.oracle.com/pls/apex/f%3Fp%3D100:11:0::::P11_QUESTION_ID:5645095700346948864 Tom Kyte]&amp;lt;br /&amp;gt;&lt;br /&gt;
Depending on the Oracle version, this procedure may or may not work! It does not include the compact clause (neither does it re-analyse to prove it worked).&amp;lt;br /&amp;gt;&lt;br /&gt;
[http://www.oracle-wiki.net/startdocsreallifeshrinkexample Here] is a worked example that shows the complete process - oracle-wiki.net&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
create or replace procedure shrink_all&lt;br /&gt;
as&lt;br /&gt;
    l_sql        varchar2(4000);&lt;br /&gt;
    l_sql2       varchar2(4000);&lt;br /&gt;
    row_movement exception;&lt;br /&gt;
    pragma       exception_init( row_movement, -10636 );&lt;br /&gt;
begin&lt;br /&gt;
    for x in (select table_name&lt;br /&gt;
              ,      owner&lt;br /&gt;
              from   t&lt;br /&gt;
              where  sgm_space_management = &amp;#039;AUTO&amp;#039;)&lt;br /&gt;
    loop&lt;br /&gt;
        l_sql := &amp;#039;alter table &amp;quot;&amp;#039; || x.owner || &amp;#039;&amp;quot;.&amp;quot;&amp;#039; || x.table_name || &amp;#039;&amp;quot; shrink space&amp;#039;;&lt;br /&gt;
        dbms_output.put_line( l_sql );&lt;br /&gt;
&lt;br /&gt;
        begin&lt;br /&gt;
            execute immediate l_sql;&lt;br /&gt;
        exception&lt;br /&gt;
        when row_movement&lt;br /&gt;
        then&lt;br /&gt;
            dbms_output.put_line( &amp;#039;failed due to row movement...&amp;#039; );&lt;br /&gt;
            l_sql2 := &amp;#039;alter table &amp;quot;&amp;#039; || x.owner || &amp;#039;&amp;quot;.&amp;quot;&amp;#039; || x.table_name || &amp;#039;&amp;quot; enable row movement&amp;#039;;&lt;br /&gt;
            dbms_output.put_line( l_sql2 );&lt;br /&gt;
            execute immediate l_sql2;&lt;br /&gt;
            dbms_output.put_line( l_sql );&lt;br /&gt;
            execute immediate l_sql;&lt;br /&gt;
        end;&lt;br /&gt;
&lt;br /&gt;
        for y in (select owner&lt;br /&gt;
                  ,      index_name&lt;br /&gt;
                  from   dba_indexes&lt;br /&gt;
                  where  table_owner = x.owner&lt;br /&gt;
                  and    table_name  = x.table_name )&lt;br /&gt;
        loop&lt;br /&gt;
            l_sql := &amp;#039;alter index &amp;quot;&amp;#039; || y.owner || &amp;#039;&amp;quot;.&amp;quot;&amp;#039; || y.index_name || &amp;#039;&amp;quot; shrink space&amp;#039;;&lt;br /&gt;
            dbms_output.put_line( l_sql );&lt;br /&gt;
            execute immediate l_sql;&lt;br /&gt;
        end loop;&lt;br /&gt;
&lt;br /&gt;
    end loop;&lt;br /&gt;
end;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===How to delete/kill a distributed transaction===&lt;br /&gt;
From [http://www.pouwiel.com/?p=2204 pouwiel.com]&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SQL&amp;gt; SELECT LOCAL_TRAN_ID, GLOBAL_TRAN_ID,to_char(FAIL_TIME,&amp;#039;dd-mon-yyyy HH24:MI:SS&amp;#039;),STATE, MIXED FROM DBA_2PC_PENDING;&lt;br /&gt;
&lt;br /&gt;
LOCAL_TRAN_ID&lt;br /&gt;
----------------------&lt;br /&gt;
GLOBAL_TRAN_ID&lt;br /&gt;
--------------------------------------------------------------------------------&lt;br /&gt;
TO_CHAR(FAIL_TIME,&amp;#039;D STATE MIX&lt;br /&gt;
-------------------- ---------------- ---&lt;br /&gt;
8.19.321913&lt;br /&gt;
1463898948.0000013CDE8005110000000179F68840A089FFFEE644B640AED6B02438B2F39D9665F&lt;br /&gt;
AFB&lt;br /&gt;
15-feb-2013 16:37:41 prepared no&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
SQL&amp;gt; SELECT LOCAL_TRAN_ID, IN_OUT,INTERFACE, DATABASE FROM DBA_2PC_NEIGHBORS;&lt;br /&gt;
&lt;br /&gt;
LOCAL_TRAN_ID IN_ I&lt;br /&gt;
---------------------- --- -&lt;br /&gt;
DATABASE&lt;br /&gt;
--------------------------------------------------------------------------------&lt;br /&gt;
8.19.321913 in N&lt;br /&gt;
jdbc_11&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
SQL&amp;gt; rollback force &amp;#039;8.19.321913&amp;#039;;&lt;br /&gt;
&lt;br /&gt;
Rollback complete.&lt;br /&gt;
&lt;br /&gt;
SQL&amp;gt; execute dbms_transaction.purge_lost_db_entry(&amp;#039;8.19.321913&amp;#039;);&lt;br /&gt;
&lt;br /&gt;
PL/SQL procedure successfully completed.&lt;br /&gt;
&lt;br /&gt;
SQL&amp;gt; commit;&lt;br /&gt;
&lt;br /&gt;
Commit complete.&lt;br /&gt;
&lt;br /&gt;
SQL&amp;gt; SELECT LOCAL_TRAN_ID, GLOBAL_TRAN_ID,to_char(FAIL_TIME,&amp;#039;dd-mon-yyyy HH24:MI:SS&amp;#039;),STATE, MIXED FROM DBA_2PC_PENDING;&lt;br /&gt;
&lt;br /&gt;
no rows selected&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Be aware that the support document 159377.1 does not speak of the rollback force. If you don’t execute that particular command it will not work.&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORACLE_BASE is getting set to the same value as ORACLE_HOME when using . oraenv===&lt;br /&gt;
Permissions problem. Make sure the user has &amp;#039;&amp;#039;&amp;#039;write&amp;#039;&amp;#039;&amp;#039; access to oraclehomeproperties.xml file!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ls -al $ORACLE_HOME/inventory/ContentsXML/oraclehomeproperties.xml&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Change permissions as appropriate.&lt;br /&gt;
A different approach which should give the same end result would be to grant the orabase executable the setuid bit.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
chmod u+s $ORACLE_HOME/bin/orabase&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This allows any user to set the environment as the orabase executable will be run with the permissions of its owner.&lt;br /&gt;
===Move table partitions to a different tablespace===&lt;br /&gt;
Are you getting errors due to partitions belonging to a different tablespace and you want to drop the current tablepace?&amp;lt;br /&amp;gt;&lt;br /&gt;
ORA-14404: partitioned table contains partitions in a different tablespace&amp;lt;br /&amp;gt;&lt;br /&gt;
====Find tables with partitions in more than one tablespace====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 2000 pages 50&lt;br /&gt;
col table_owner for a30&lt;br /&gt;
col table_name for a30&lt;br /&gt;
select table_owner&lt;br /&gt;
 ,     table_name&lt;br /&gt;
,      count(*)&lt;br /&gt;
from   dba_tab_partitions&lt;br /&gt;
where  table_owner != &amp;#039;SYS&amp;#039;&lt;br /&gt;
group  by table_owner&lt;br /&gt;
,      table_name&lt;br /&gt;
having count(*) &amp;gt; 1&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
See which tables have partitions across multiple tablespaces...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 1000 pages 100&lt;br /&gt;
col table_name for a50&lt;br /&gt;
select distinct b.table_owner||&amp;#039;.&amp;#039;||b.table_name table_name&lt;br /&gt;
,      a.tablespace_name ts1&lt;br /&gt;
,      b.tablespace_name ts2&lt;br /&gt;
from   (&lt;br /&gt;
       select distinct tablespace_name&lt;br /&gt;
       ,      table_name&lt;br /&gt;
       ,      partition_name&lt;br /&gt;
       from   dba_tab_partitions&lt;br /&gt;
       )                  a&lt;br /&gt;
,      dba_tab_partitions b&lt;br /&gt;
where  a.table_name       = b.table_name&lt;br /&gt;
and    a.tablespace_name != b.tablespace_name&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Generate statements to move the partitions from one tablespace to another...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select &amp;#039;alter table &amp;#039;||b.table_owner||&amp;#039;.&amp;#039;||b.table_name||&amp;#039; move partition &amp;#039;||b.partition_name||&amp;#039; tablespace &amp;amp;NEW_TABLESPACE;&amp;#039;&lt;br /&gt;
from   (&lt;br /&gt;
       select distinct table_name&lt;br /&gt;
       ,      partition_name&lt;br /&gt;
       from   dba_tab_partitions&lt;br /&gt;
       where  tablespace_name = &amp;#039;&amp;amp;&amp;amp;OLD_TABLESPACE&amp;#039;&lt;br /&gt;
       )                  a&lt;br /&gt;
,      dba_tab_partitions b&lt;br /&gt;
where  a.table_name       = b.table_name&lt;br /&gt;
and    b.tablespace_name != &amp;#039;&amp;amp;OLD_TABLESPACE&amp;#039;&lt;br /&gt;
/&lt;br /&gt;
undef OLD_TABLESPACE&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====What&amp;#039;s left hanging around?====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
col SEGMENT_TYPE for a20&lt;br /&gt;
col OWNER for a20&lt;br /&gt;
col SEGMENT_NAME for a40&lt;br /&gt;
col PARTITION_NAME for a15&lt;br /&gt;
col TABLESPACE_NAME for a30&lt;br /&gt;
select segment_type&lt;br /&gt;
,      owner&lt;br /&gt;
,      segment_name&lt;br /&gt;
,      partition_name&lt;br /&gt;
,      tablespace_name&lt;br /&gt;
from   dba_segments&lt;br /&gt;
where  tablespace_name in (&amp;#039;TS_THALER_IOT_OLD&amp;#039;,&amp;#039;TS_THALER_CU&amp;#039;,&amp;#039;TS_THALER_BACKUP&amp;#039;,&amp;#039;TS_THALER_PART_OLD&amp;#039;)&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
select table_owner&lt;br /&gt;
,      table_name&lt;br /&gt;
from   dba_indexes&lt;br /&gt;
where  index_name = &amp;#039;&amp;amp;index_name&amp;#039;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===What edition is my database (Standard, Enterprise, XE...)?===&lt;br /&gt;
Only works from 12c :-(&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select edition from sys.registry$ where cid=&amp;#039;CATPROC&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Is database a CDB with PDBs?===&lt;br /&gt;
Needs a bit of work. Won&amp;#039;t work pre-12c obviously and also not on Standby databases if they are in MOUNT mode&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
for db in $(ps -ef | grep [p]mon|awk -F_ &amp;#039;{print $NF}&amp;#039;)&lt;br /&gt;
do&lt;br /&gt;
    export ORACLE_SID=${db}&lt;br /&gt;
    ORAENV_ASK=NO&lt;br /&gt;
    . oraenv &amp;gt;/dev/null 2&amp;gt;&amp;amp;1&lt;br /&gt;
    sqlplus -s / as sysdba&amp;lt;&amp;lt;&amp;#039;EOSQL&amp;#039;&lt;br /&gt;
set head off newpa none&lt;br /&gt;
select name&lt;br /&gt;
,      (select count(*) from v$pdbs) npdbs&lt;br /&gt;
from   v$database&lt;br /&gt;
/&lt;br /&gt;
EOSQL&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
version 2&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
function is_db_cdb return boolean&lt;br /&gt;
is&lt;br /&gt;
    b_is_cdb        boolean := false;&lt;br /&gt;
    l_is_cdb        varchar2(3) := &amp;#039;NO&amp;#039;;&lt;br /&gt;
    e_col_not_found exception;&lt;br /&gt;
    pragma          exception_init(e_col_not_found, -904);&lt;br /&gt;
begin&lt;br /&gt;
    begin&lt;br /&gt;
        execute immediate &amp;#039;select cdb from v$database&amp;#039; &lt;br /&gt;
        into l_is_cdb;&lt;br /&gt;
    exception&lt;br /&gt;
        when e_col_not_found then l_is_cdb := &amp;#039;NO&amp;#039;;  -- ORA-00904&lt;br /&gt;
    end;&lt;br /&gt;
&lt;br /&gt;
    if (l_is_cdb = &amp;#039;YES&amp;#039;) then&lt;br /&gt;
        return TRUE;&lt;br /&gt;
    else&lt;br /&gt;
        return FALSE;  -- either not a cdb or pre-12.1 database&lt;br /&gt;
    end if;&lt;br /&gt;
&lt;br /&gt;
end is_db_cdb;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===List triggers in the database===&lt;br /&gt;
This query specifically lists after login triggers &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select obj.con_id&lt;br /&gt;
,      pdb.name&lt;br /&gt;
,      obj.owner&lt;br /&gt;
,      obj.object_name&lt;br /&gt;
,      to_char(obj.created, &amp;#039;DD/MM/YYYY HH24:MI:SS&amp;#039;)       created_str&lt;br /&gt;
,      to_char(obj.last_ddl_time, &amp;#039;DD/MM/YYYY HH24:MI:SS&amp;#039;) last_ddl_str&lt;br /&gt;
from   cdb_objects   obj&lt;br /&gt;
join   cdb_triggers trgs&lt;br /&gt;
       on (   obj.con_id      = trgs.con_id&lt;br /&gt;
          and obj.owner       = trgs.owner&lt;br /&gt;
          and obj.object_name = trgs.trigger_name&lt;br /&gt;
          )&lt;br /&gt;
join   v$pdbs pdb&lt;br /&gt;
       on ( obj.con_id  = pdb.con_id )&lt;br /&gt;
where  trgs.trigger_type     = &amp;#039;AFTER EVENT&amp;#039;&lt;br /&gt;
and    trgs.triggering_event like &amp;#039;LOGON%&amp;#039;&lt;br /&gt;
and    trgs.status           = &amp;#039;ENABLED&amp;#039;&lt;br /&gt;
order  by object_name&lt;br /&gt;
,      obj.last_ddl_time&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===List the pluggable databases (PDB) in a container database (CDB)===&lt;br /&gt;
The network_name column shows what you should find in tnsnames.ora for this db connection&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select name,network_name,pdb from v$services;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select * from v$pdbs;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Start and stop a pluggable database===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter pluggable database pdb1 open;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter pluggable database pdb1 close immediate;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Swith to a pluggable database===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter session set container=pdb1;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Reopen pluggable databases at container startup===&lt;br /&gt;
By default pluggable databases in a container remain in a MOUNT state when the container starts up.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select name, open_mode from v$pdbs where name = &amp;#039;PDB1&amp;#039;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
To modify this, open it and save its state&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter pluggable database pdb1 open;&lt;br /&gt;
alter pluggable database pdb1 save state;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
To see a log of issues with pluggable databases&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select * from pdb_plug_in_violations where type = &amp;#039;ERROR&amp;#039; and status != &amp;#039;RESOLVED&amp;#039; and name = &amp;#039;PDB1&amp;#039;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===What is the current container id in a cdb?===&lt;br /&gt;
CDB$ROOT is container id 1. User containers start from 2.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select sys_context(&amp;#039;USERENV&amp;#039;,&amp;#039;CON_ID&amp;#039;) from dual&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===What is the current container name in a cdb?===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select sys_context(&amp;#039;USERENV&amp;#039;,&amp;#039;CON_NAME&amp;#039;) from dual&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or just&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
show con_name&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Switching Between Containers===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SQL&amp;gt; show con_name&lt;br /&gt;
&lt;br /&gt;
CON_NAME&lt;br /&gt;
------------------------------&lt;br /&gt;
CDB$ROOT&lt;br /&gt;
&lt;br /&gt;
SQL&amp;gt; alter session set container=tstklok;&lt;br /&gt;
&lt;br /&gt;
Session altered.&lt;br /&gt;
&lt;br /&gt;
SQL&amp;gt;  show con_name&lt;br /&gt;
&lt;br /&gt;
CON_NAME&lt;br /&gt;
------------------------------&lt;br /&gt;
TSTKLOK&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Direct connection to pluggable database===&lt;br /&gt;
These must be made using a service (defined in tnsnames.ora). Each pluggable database automatically registers a service with the listener (v$services).&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sqlplus appuser/apppwd@tstklok&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or using ezconnect&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SQL&amp;gt; conn appuser/apppwd@//localhost:1521/tstklok&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===What platform is the database running on?===&lt;br /&gt;
Could be useful for handling line endings...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select platform_name from v$database&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
if instr(db_platform, &amp;#039;WINDOWS&amp;#039;) != 0 then&lt;br /&gt;
    crlf := CHR(13) || CHR(10);       -- Windows gets the \r and \n&lt;br /&gt;
else&lt;br /&gt;
    crlf := CHR (10);                 -- Just \n for the rest of the world&lt;br /&gt;
end if;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Is the database 32 or 64 bit?===&lt;br /&gt;
If the answer is 1,7,10,15,16 or 17, then it is 32bit, everything else should be 64bit.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select platform_id from v$database&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===What features is my database using?===&lt;br /&gt;
Before converting to Standard Edition, check the features here - some may be Enterprise specific.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
col name for a45&lt;br /&gt;
col description for a85&lt;br /&gt;
set lines 2000&lt;br /&gt;
select name&lt;br /&gt;
,      detected_usages&lt;br /&gt;
,      description&lt;br /&gt;
from   dba_feature_usage_statistics&lt;br /&gt;
where  1=1&lt;br /&gt;
and    currently_used = &amp;#039;TRUE&amp;#039;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===How many redo log switches per hour?===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 100&lt;br /&gt;
col &amp;quot;YYYYMMDD HH24&amp;quot; for a14&lt;br /&gt;
select to_char(first_time,&amp;#039;yyyymmdd hh24&amp;#039;) &amp;quot;YYYYMMDD HH24&amp;quot;&lt;br /&gt;
,      count(1)                            num_switches&lt;br /&gt;
from   v$log_history&lt;br /&gt;
group  by to_char(first_time,&amp;#039;yyyymmdd hh24&amp;#039;)&lt;br /&gt;
order  by 1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or a bit fancier version...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rem *********************************************************** &lt;br /&gt;
rem&lt;br /&gt;
rem	File: log_history.sql &lt;br /&gt;
rem	Description: Log switch rates from v$log_history &lt;br /&gt;
rem   &lt;br /&gt;
rem	From &amp;#039;Oracle Performance Survival Guide&amp;#039; by Guy Harrison&lt;br /&gt;
rem		Chapter 21 Page 637&lt;br /&gt;
rem		ISBN: 978-0137011957&lt;br /&gt;
rem		See www.guyharrison.net for further information&lt;br /&gt;
rem  &lt;br /&gt;
rem		This work is in the public domain NSA &lt;br /&gt;
rem   &lt;br /&gt;
rem&lt;br /&gt;
rem ********************************************************* &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
col min_minutes format 9999.99 &lt;br /&gt;
col max_minutes format 9999.99 &lt;br /&gt;
col avg_minutes format 9999.99 &lt;br /&gt;
set pagesize 1000&lt;br /&gt;
set lines 70&lt;br /&gt;
set echo on &lt;br /&gt;
&lt;br /&gt;
WITH log_history AS&lt;br /&gt;
       (SELECT thread#, first_time,&lt;br /&gt;
               LAG(first_time) OVER (ORDER BY thread#, sequence#)&lt;br /&gt;
                  last_first_time,&lt;br /&gt;
               (first_time&lt;br /&gt;
                - LAG(first_time) OVER (ORDER BY thread#, sequence#))&lt;br /&gt;
                    * 24* 60   last_log_time_minutes,&lt;br /&gt;
               LAG(thread#) OVER (ORDER BY thread#, sequence#)&lt;br /&gt;
                   last_thread#&lt;br /&gt;
        FROM v$log_history)&lt;br /&gt;
SELECT ROUND(MIN(last_log_time_minutes), 2) min_minutes,&lt;br /&gt;
       ROUND(MAX(last_log_time_minutes), 2) max_minutes,&lt;br /&gt;
       ROUND(AVG(last_log_time_minutes), 2) avg_minutes&lt;br /&gt;
FROM log_history&lt;br /&gt;
WHERE     last_first_time IS NOT NULL&lt;br /&gt;
      AND last_thread# = thread#&lt;br /&gt;
      AND first_time &amp;gt; SYSDATE - 1; &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Show redo log groups/members===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
col instance       for a8&lt;br /&gt;
col thread         for 999&lt;br /&gt;
col groupno        for 999&lt;br /&gt;
col member         for a35&lt;br /&gt;
col redo_file_type for a15&lt;br /&gt;
col log_status     for a10&lt;br /&gt;
col logsize_m      for 99999&lt;br /&gt;
col archived       for a12&lt;br /&gt;
&lt;br /&gt;
SELECT i.instance_name   instance&lt;br /&gt;
,      i.thread#         thread&lt;br /&gt;
,      f.group#          groupno&lt;br /&gt;
,      f.member          member&lt;br /&gt;
,      f.type            redo_file_type&lt;br /&gt;
,      l.status          log_status&lt;br /&gt;
,      l.bytes/1024/1024 logsize_m&lt;br /&gt;
,      l.archived        archived&lt;br /&gt;
FROM   gv$logfile  f&lt;br /&gt;
,      gv$log      l&lt;br /&gt;
,      gv$instance i&lt;br /&gt;
WHERE  1=1&lt;br /&gt;
and    f.group#  = l.group#&lt;br /&gt;
AND    l.thread# = i.thread#&lt;br /&gt;
AND    i.inst_id = f.inst_id&lt;br /&gt;
AND    f.inst_id = l.inst_id&lt;br /&gt;
ORDER  BY i.instance_name&lt;br /&gt;
,      f.group#&lt;br /&gt;
,      f.member;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Korn shell timestamp function===&lt;br /&gt;
Example usage: echo &amp;quot;`ts`: Checking backup status&amp;quot;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
function ts {&lt;br /&gt;
    date +&amp;#039;%d-%b-%Y %H:%M:%S&amp;#039;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Drop a database===&lt;br /&gt;
Dropping a database including backups should be considered criminal in a production environment!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sqlplus / as sysdba&lt;br /&gt;
startup force mount exclusive restrict&lt;br /&gt;
exit&lt;br /&gt;
rman target /&lt;br /&gt;
drop database including backups noprompt;&lt;br /&gt;
exit&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
RMAN&amp;gt; connect target sys/pass@test&lt;br /&gt;
connected to target database: test (dbid=123456789)&lt;br /&gt;
&lt;br /&gt;
RMAN&amp;gt; startup force mount&lt;br /&gt;
RMAN&amp;gt; sql &amp;#039;alter system enable restricted session&amp;#039;;&lt;br /&gt;
RMAN&amp;gt; drop database including backups noprompt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Use sub-select or in-line views to update base tables===&lt;br /&gt;
Inline views can be used to update base table data&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
update&lt;br /&gt;
    (&lt;br /&gt;
    select p.list_price&lt;br /&gt;
    from   products           p&lt;br /&gt;
    ,      product_categories pc&lt;br /&gt;
    where  1=1&lt;br /&gt;
    and    p.category_id    = pc.category_id&lt;br /&gt;
    and    pc.category_name = &amp;#039;CPU&amp;#039;&lt;br /&gt;
    )&lt;br /&gt;
set list_price = list_price * 1.15; &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Use sub-select or in-line views to delete base table data===&lt;br /&gt;
A different way to delete rows in base tables, using Inline views or subselect&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
delete&lt;br /&gt;
    (&lt;br /&gt;
    select p.list_price&lt;br /&gt;
    from   products           p&lt;br /&gt;
    ,      product_categories pc&lt;br /&gt;
    where  1=1&lt;br /&gt;
    and    p.category_id    = pc.category_id&lt;br /&gt;
    and    pc.category_name = &amp;#039;CPU&amp;#039;&lt;br /&gt;
    )&lt;br /&gt;
where list_price &amp;lt; 1000; &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Mass update of files using perl inline script===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
for server in `cat /home/tools/etc/oracle/oracle_servers`; do&lt;br /&gt;
    ssh $server “perl -p -i -e &amp;#039;s/T01/D01/&amp;#039; /home/tools/scripts/rman/inclexcl.lst”&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===How to use vi-style editing in SQL*Plus===&lt;br /&gt;
These instructions are for Redhat but other versions will be very similar&lt;br /&gt;
* Download rlwrap from [http://dl.fedoraproject.org/pub/epel/5/x86_64/repoview/rlwrap.html] or [http://dl.fedoraproject.org/pub/epel/6/x86_64/repoview/rlwrap.html]&lt;br /&gt;
* sudo yum install rlwrap&lt;br /&gt;
* build a dictionary file for autocomplete on pressing Tab&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
vi $HOME/sql.dict&lt;br /&gt;
select&lt;br /&gt;
from&lt;br /&gt;
dba_users&lt;br /&gt;
dba_data_files&lt;br /&gt;
dba_tablespaces&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alias sysdba=&amp;#039;rlwrap -f $HOME/sql.dict sqlplus / as sysdba&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or for general command use...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alias sqlplus=&amp;#039;rlwrap -D2 -ic sqlplus&amp;#039;&lt;br /&gt;
alias dgmgrl=&amp;#039;rlwrap -D2 -ic dgmgrl&amp;#039;&lt;br /&gt;
alias rman=&amp;#039;rlwrap -D2 -ic rman&amp;#039;&lt;br /&gt;
alias asmcmd=&amp;#039;rlwrap -D2 -ic asmcmd&amp;#039;&lt;br /&gt;
alias lsnrctl=&amp;#039;rlwrap -D2 -ic lsnrctl&amp;#039;&lt;br /&gt;
alias adrci=&amp;#039;rlwrap -D2 -ic adrci&amp;#039;&lt;br /&gt;
alias impdp=&amp;#039;rlwrap -D2 -ic impdp&amp;#039;&lt;br /&gt;
alias expdp=&amp;#039;rlwrap -D2 -ic expdp&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Execute an SQL statement on all databases on all servers for a customer===&lt;br /&gt;
Run from customer&amp;#039;s management server&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
./dosh -c &amp;quot;su - oracle -c &amp;#039;/home/tools/scripts/oracle/all_db_do -v \&amp;quot;select username, account_status, profile from dba_users order by 3;\&amp;quot;&amp;#039;&amp;quot; &amp;gt;user_status.lst&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SCRIPTS_DIR=/home/tools/scripts/oracle&lt;br /&gt;
$SCRIPTS_DIR/dosh -c &amp;quot;su - oraibm -c \&amp;quot;$SCRIPTS_DIR/all_db_do &amp;#039;alter user ops\\\$oraibm profile oracle_system_user;&amp;#039;\&amp;quot;&amp;quot;&lt;br /&gt;
$SCRIPTS_DIR/dosh2 -c &amp;quot;su - oraibm -c \&amp;quot;$SCRIPTS_DIR/all_db_do &amp;#039;alter user ops$oraibm profile oracle_system_user;&amp;#039;\&amp;quot;&amp;quot;&lt;br /&gt;
$SCRIPTS_DIR/dosh2 -c &amp;quot;su - oraibm -c \&amp;quot;$SCRIPTS_DIR/all_db_do &amp;#039;alter system set control_file_record_keep_time=31;&amp;#039;\&amp;quot;&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Where is the alert log/alertlog?===&lt;br /&gt;
Older systems&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select value from v$parameter where name=&amp;#039;background_dump_dest&amp;#039;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Newer systems&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select value from v$diag_info where name=&amp;#039;Diag Trace&amp;#039;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Grant normal users access to the alertlog table (sys.x$dbgalertext)===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
create view x$dbgalertext_v as select * from x$dbgalertext;&lt;br /&gt;
grant select on x$dbgalertext_v to &amp;amp;&amp;amp;grantee;&lt;br /&gt;
create or replace synonym &amp;amp;grantee..x$dbgalertext for sys.x$dbgalertext_v;&lt;br /&gt;
undef grantee&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Search alert log for ORA-00600 and ORA-07445 errors===&lt;br /&gt;
Scan the database table version of the alertlog for errors without reporting what was already found.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select indx, message_text from x$dbgalertext where message_text like &amp;#039;%ORA-00600%&amp;#039; or message_text like &amp;#039;%ORA-07445%&amp;#039; and indx &amp;gt; &amp;amp;last_queried_indx order by indx desc;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===tail the database alert log===&lt;br /&gt;
If an ADR error is displayed, then ORACLE_SID is probably not set&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alias alertlog=&amp;#039;adrci exec=&amp;quot;set home diag/rdbms/$(echo $ORACLE_SID | tr A-Z a-z)/$ORACLE_SID; show alert -tail -f&amp;quot;&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===What is my WAN ip address?===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
curl -A &amp;quot;Mozilla/4.0&amp;quot; http://checkip.dyndns.org/ 2&amp;gt;/dev/null | perl -ne &amp;#039;print $1 if /Current IP Address: (\d+\.\d+\.\d+\.\d+)/&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
curl -A &amp;quot;Mozilla/4.0&amp;quot; http://myip.dnsdynamic.org/ 2&amp;gt;/dev/null&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Wait for child pid to finish in background and report its status===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# submit a process to the background&lt;br /&gt;
export_schema1.ksh &amp;amp;&lt;br /&gt;
bgpid=$!&lt;br /&gt;
&lt;br /&gt;
while (ps -ef | grep $bgpid | grep -v grep); do&lt;br /&gt;
    # still running...&lt;br /&gt;
    sleep 600&lt;br /&gt;
done&lt;br /&gt;
&lt;br /&gt;
# should be finished&lt;br /&gt;
wait $bgpid&lt;br /&gt;
bgstatus=$?&lt;br /&gt;
echo background process ended with status $bgstatus&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/usr/bin/ksh&lt;br /&gt;
# submit a few processes to the background&lt;br /&gt;
# wait for them all to finish&lt;br /&gt;
# concat their logfiles&lt;br /&gt;
&lt;br /&gt;
(./sleeper.sh;echo &amp;quot;sleeper 1 finished&amp;quot;)&amp;gt;sleeper1.log &amp;amp;&lt;br /&gt;
PIDLIST=&amp;quot;$PIDLIST $!&amp;quot;&lt;br /&gt;
echo &amp;quot;PIDLIST is $PIDLIST ...&amp;quot;&lt;br /&gt;
sleep 5&lt;br /&gt;
&lt;br /&gt;
(./sleeper.sh;echo &amp;quot;sleeper 2 finished&amp;quot;)&amp;gt;sleeper2.log &amp;amp;&lt;br /&gt;
PIDLIST=&amp;quot;$PIDLIST $!&amp;quot;&lt;br /&gt;
echo &amp;quot;PIDLIST is $PIDLIST ...&amp;quot;&lt;br /&gt;
sleep 5&lt;br /&gt;
&lt;br /&gt;
(./sleeper.sh;echo &amp;quot;sleeper 3 finished&amp;quot;)&amp;gt;sleeper3.log &amp;amp;&lt;br /&gt;
PIDLIST=&amp;quot;$PIDLIST $!&amp;quot;&lt;br /&gt;
echo &amp;quot;PIDLIST is $PIDLIST ...&amp;quot;&lt;br /&gt;
sleep 5&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;Now 15 seconds later, we have 3 pids: $PIDLIST&amp;quot;&lt;br /&gt;
for PID in $PIDLIST; do&lt;br /&gt;
    wait $PID&lt;br /&gt;
    echo &amp;quot;$PID exited with status $?&amp;quot;&lt;br /&gt;
done&lt;br /&gt;
&lt;br /&gt;
# all jobs should have ended, concat their logs&lt;br /&gt;
cat sleeper*log &amp;gt; sleepers.log&lt;br /&gt;
cat sleepers.log&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Real world example&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/usr/bin/ksh&lt;br /&gt;
# ==============================================================================&lt;br /&gt;
# Name         : export_JDBEOP1.ksh&lt;br /&gt;
# Description  : Run export in pieces for performance reasons&lt;br /&gt;
#&lt;br /&gt;
# Parameters   : &lt;br /&gt;
#&lt;br /&gt;
# Notes        : Also decide whether to exclude PDARC schema or not&lt;br /&gt;
#                depending on what day it is&lt;br /&gt;
#&lt;br /&gt;
#&lt;br /&gt;
# Modification History&lt;br /&gt;
# ====================&lt;br /&gt;
# When      Who               What&lt;br /&gt;
# ========= ================= ==================================================&lt;br /&gt;
# 15-OCT-13 Stuart Barkley    Created&lt;br /&gt;
# ==============================================================================&lt;br /&gt;
&lt;br /&gt;
STARTTIME=`date &amp;#039;+%Y%m%d%H%M%S&amp;#039;`&lt;br /&gt;
DAYNO=`date +%u`&lt;br /&gt;
PROGNAME=`basename $0`&lt;br /&gt;
SCRIPTS_DIR=/home/tools/scripts/oracle&lt;br /&gt;
DATA_DIR=/oracle/JDBEOP1/admin/change&lt;br /&gt;
EXPORT_DIR=/oracle/export/JDBEOP1&lt;br /&gt;
&lt;br /&gt;
# marker so we can find our files later&lt;br /&gt;
MARKERFILE=/tmp/start_$PROGNAME_$$&lt;br /&gt;
touch $MARKERFILE&lt;br /&gt;
&lt;br /&gt;
$SCRIPTS_DIR/expdp_PARFILE.ksh -s JDBEOP1 -u PRODDTA -p 4 -k 2 -f $DATA_DIR/JDBEOP1_PRODDTA.parfile &amp;amp;&lt;br /&gt;
PIDLIST=&amp;quot;$PIDLIST $!&amp;quot;&lt;br /&gt;
echo &amp;quot;PIDLIST is $PIDLIST ...&amp;quot;&lt;br /&gt;
&lt;br /&gt;
$SCRIPTS_DIR/expdp_PARFILE.ksh -s JDBEOP1 -u PRODCTL -p 2 -k 2 -f $DATA_DIR/JDBEOP1_PRODCTL.parfile &amp;amp;&lt;br /&gt;
PIDLIST=&amp;quot;$PIDLIST $!&amp;quot;&lt;br /&gt;
echo &amp;quot;PIDLIST is $PIDLIST ...&amp;quot;&lt;br /&gt;
&lt;br /&gt;
$SCRIPTS_DIR/expdp_PARFILE.ksh -s JDBEOP1 -u NOPRODNOPDARC -p 4 -k 2 -f $DATA_DIR/JDBEOP1_NOPROD_NOPDARC.parfile &amp;amp;&lt;br /&gt;
PIDLIST=&amp;quot;$PIDLIST $!&amp;quot;&lt;br /&gt;
echo &amp;quot;PIDLIST is $PIDLIST ...&amp;quot;&lt;br /&gt;
&lt;br /&gt;
if [[ $DAYNO -eq 1 ]]; then&lt;br /&gt;
    $SCRIPTS_DIR/expdp_PARFILE.ksh -s JDBEOP1 -u NOPROD -p 4 -k 2 -f $DATA_DIR/JDBEOP1_NOPROD.parfile &amp;amp;&lt;br /&gt;
    PIDLIST=&amp;quot;$PIDLIST $!&amp;quot;&lt;br /&gt;
    echo &amp;quot;PIDLIST is $PIDLIST ...&amp;quot;&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
# now sit and wait for the exports to finish&lt;br /&gt;
for PID in $PIDLIST; do&lt;br /&gt;
    echo &amp;quot;waiting for pid $PID to finish&amp;quot;&lt;br /&gt;
    wait $PID&lt;br /&gt;
    echo &amp;quot;$PID exited with status $?&amp;quot;&lt;br /&gt;
done&lt;br /&gt;
&lt;br /&gt;
# collect all log files up into one&lt;br /&gt;
cd $EXPORT_DIR&lt;br /&gt;
for i in `find . -name &amp;quot;expdp_JDBEOP1*log&amp;quot; -newer $MARKERFILE`; do&lt;br /&gt;
    cat $i &amp;gt; expdp_JDBEOP1_D_FULL_${STARTTIME}.log&lt;br /&gt;
done&lt;br /&gt;
&lt;br /&gt;
rm $MARKLERFILE&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Create private DB link for a user without knowing his password===&lt;br /&gt;
* Inspired by [http://oradbatips.blogspot.co.uk/2010/01/tip-84-create-private-db-link-for-user.html oradbatips.blogspot.co.uk]&lt;br /&gt;
It uses a clever package, dbms_sys_sql.&amp;lt;br /&amp;gt;&lt;br /&gt;
Also useful for executing anything on behalf of another user.&amp;lt;br /&amp;gt;&lt;br /&gt;
Here is an example on how to create private database link for a user.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
create or replace procedure link_creator ( p_owner varchar2, p_dblink_name varchar2, p_username varchar2, p_password varchar2, p_address varchar2 ) as&lt;br /&gt;
    uid number;&lt;br /&gt;
    sqltext varchar2(1000) := &amp;#039;create [public] database link [link_name] connect to [username] identified by [password] using &amp;#039;&amp;#039;[address]&amp;#039;&amp;#039;&amp;#039;;&lt;br /&gt;
    myint integer;&lt;br /&gt;
begin&lt;br /&gt;
    if upper(p_owner) = &amp;#039;PUBLIC&amp;#039; then&lt;br /&gt;
        sqltext := replace(sqltext, &amp;#039;[public]&amp;#039;, &amp;#039;public&amp;#039;);&lt;br /&gt;
    else&lt;br /&gt;
        sqltext := replace(sqltext, &amp;#039;[public]&amp;#039;, &amp;#039;&amp;#039;);&lt;br /&gt;
    end if;&lt;br /&gt;
    sqltext := replace(sqltext, &amp;#039;[linkname]&amp;#039;, p_dblink_name);&lt;br /&gt;
    sqltext := replace(sqltext, &amp;#039;[username]&amp;#039;, p_username);&lt;br /&gt;
    sqltext := replace(sqltext, &amp;#039;[password]&amp;#039;, p_password);&lt;br /&gt;
    sqltext := replace(sqltext, &amp;#039;[address]&amp;#039;, p_address);&lt;br /&gt;
&lt;br /&gt;
    select user_id&lt;br /&gt;
    into   uid&lt;br /&gt;
    from   dba_users&lt;br /&gt;
    where  username = decode(upper(p_owner), &amp;#039;PUBLIC&amp;#039;, &amp;#039;SYS&amp;#039;, p_owner)&lt;br /&gt;
    ;&lt;br /&gt;
    myint:=sys.dbms_sys_sql.open_cursor();&lt;br /&gt;
    sys.dbms_sys_sql.parse_as_user ( myint, sqltext, dbms_sql.native, uid );&lt;br /&gt;
    sys.dbms_sys_sql.close_cursor(myint);&lt;br /&gt;
end;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Here we can generate SQL to rebuild the links for future use. Note the password is no longer stored in this column.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set pages 1000&lt;br /&gt;
select &amp;#039;begin link_creator ( &amp;#039;&amp;#039;&amp;#039;|| u.name ||&amp;#039;&amp;#039;&amp;#039;,&amp;#039;&amp;#039;&amp;#039;|| l.name ||&amp;#039;&amp;#039;&amp;#039;,&amp;#039;&amp;#039;&amp;#039;|| l.userid ||&amp;#039;&amp;#039;&amp;#039;,&amp;#039;&amp;#039;&amp;#039;|| l.password ||&amp;#039;&amp;#039;&amp;#039;,&amp;#039;&amp;#039;&amp;#039;|| l.host ||&amp;#039;&amp;#039;&amp;#039;); end;&amp;#039;|| chr(10) ||&amp;#039;/&amp;#039; link_text&lt;br /&gt;
from   sys.link$ l&lt;br /&gt;
,      sys.user$ u&lt;br /&gt;
where  l.owner# = u.user#&lt;br /&gt;
;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Another method to create a db_link from sys on behalf of a user is to create a procedure under that users name that does the db link creation====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
grant create database link to &amp;amp;&amp;amp;user;&lt;br /&gt;
&lt;br /&gt;
create or replace procedure &amp;amp;user..create_db_link as&lt;br /&gt;
begin&lt;br /&gt;
    execute immediate &amp;#039;create database link &amp;amp;link_name connect to &amp;amp;user identified by &amp;amp;users_password using &amp;#039;&amp;#039;&amp;amp;tns_connect_identifier&amp;#039;&amp;#039;&amp;#039;;&lt;br /&gt;
end create_db_link;&lt;br /&gt;
&lt;br /&gt;
exec &amp;amp;user..create_db_link;&lt;br /&gt;
&lt;br /&gt;
revoke create database link from &amp;amp;user;&lt;br /&gt;
&lt;br /&gt;
drop procedure &amp;amp;user..create_db_link;&lt;br /&gt;
undef user&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Create a comma separated list of columns from a select statement===&lt;br /&gt;
Method 1:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SELECT parent_id,&lt;br /&gt;
       RTRIM(XMLAGG(XMLELEMENT(e,child_id || &amp;#039;,&amp;#039;)).EXTRACT(&amp;#039;//text()&amp;#039;),&amp;#039;,&amp;#039;) AS &amp;quot;Children&amp;quot;&lt;br /&gt;
FROM   parentChildTable&lt;br /&gt;
WHERE  parent_id = 0&lt;br /&gt;
GROUP  BY parent_id&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SELECT parent_id,&lt;br /&gt;
       LISTAGG(child_id, &amp;#039;,&amp;#039;) WITHIN GROUP (ORDER BY child_id) AS &amp;quot;Children&amp;quot;&lt;br /&gt;
  FROM parentChildTable&lt;br /&gt;
 WHERE parent_id = 0&lt;br /&gt;
 GROUP BY parent_id&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Method 2 (undocumented and cannot therefore be relied on to continue working in the same manner):&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SELECT wmsys.wm_concat(&amp;lt;column_name&amp;gt;)&lt;br /&gt;
FROM &amp;lt;table_name&amp;gt;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Start an instant one-line webserver in current directory===&lt;br /&gt;
Need to quickly share/copy a file or read an html file on Linux? Start a web server!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
python -m SimpleHTTPServer 8000&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
and point your browser to http://localhost:8000&amp;lt;br /&amp;gt;&lt;br /&gt;
or&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
while true; do nc -l -p 80 -q 1 &amp;lt; index.html; done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Get SQL*Plus to generate HTML===&lt;br /&gt;
* [http://docs.oracle.com/cd/E11882_01/server.112/e16604/ch_seven.htm#CHDCECJG official guide]&lt;br /&gt;
One way to do it... use -m(arkup) option to specify:&amp;lt;br /&amp;gt;&lt;br /&gt;
html on/off - specifies whether to output html output or not&lt;br /&gt;
head - specify your own customised head contents&amp;lt;br /&amp;gt;&lt;br /&gt;
spool off - as a part of the -m tag means do not print the default &amp;amp;lt;html&amp;amp;gt;, &amp;amp;lt;head&amp;amp;gt; and &amp;amp;lt;body&amp;amp;gt; tags&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sqlplus -m &amp;quot;html on head &amp;#039;&amp;lt;link rel=&amp;quot;stylesheet&amp;quot; href=&amp;quot;/dbamon_golden.css&amp;quot; type=&amp;quot;text/css&amp;quot; /&amp;gt;&amp;#039; spool off&amp;quot; / as sysdba&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sqlplus / as sysdba&lt;br /&gt;
set markup html on head &amp;#039;&amp;lt;link rel=&amp;quot;stylesheet&amp;quot; href=&amp;quot;/dbamon_golden.css&amp;quot; type=&amp;quot;text/css&amp;quot; /&amp;gt;&amp;#039; body &amp;quot;&amp;quot; table &amp;quot;&amp;quot; spool off&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
besides html and head, you can also specify:&amp;lt;br /&amp;gt;&lt;br /&gt;
body - specify your own customised body attributes&amp;lt;br /&amp;gt;&lt;br /&gt;
table - override the default table options&amp;lt;br /&amp;gt;&lt;br /&gt;
entmap - turn on or off the html replacement characters (&amp;amp;lt, &amp;amp;gt, etc...)&amp;lt;br /&amp;gt;&lt;br /&gt;
preformat - uses the &amp;amp;lt;pre&amp;amp;gt; tag to format output exactly as required&amp;lt;br /&amp;gt;&lt;br /&gt;
* another little gem...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
----------------------------------------&lt;br /&gt;
-- get the last SQL*Plus output in HTML&lt;br /&gt;
-- after Tanel Poder&lt;br /&gt;
----------------------------------------&lt;br /&gt;
&lt;br /&gt;
set termout off&lt;br /&gt;
&lt;br /&gt;
set markup HTML ON HEAD &amp;quot; -&lt;br /&gt;
 -&lt;br /&gt;
&amp;quot; -&lt;br /&gt;
BODY &amp;quot;&amp;quot; -&lt;br /&gt;
TABLE &amp;quot;border=&amp;#039;1&amp;#039; align=&amp;#039;center&amp;#039; summary=&amp;#039;Script output&amp;#039;&amp;quot; -&lt;br /&gt;
SPOOL ON ENTMAP ON PREFORMAT OFF&lt;br /&gt;
&lt;br /&gt;
spool myoutput.html&lt;br /&gt;
&lt;br /&gt;
l&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
spool off&lt;br /&gt;
set markup html off spool off&lt;br /&gt;
host firefox myoutput.html&lt;br /&gt;
set termout on&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===HTML SELECT - Trigger JavaScript ONCHANGE event even when the option is not changed===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;select onchange=&amp;quot;jsFunction()&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;option value=&amp;quot;&amp;quot; disabled selected style=&amp;quot;display:none;&amp;quot;&amp;gt;Label&amp;lt;/option&amp;gt;&lt;br /&gt;
  &amp;lt;option value=&amp;quot;1&amp;quot;&amp;gt;1&amp;lt;/option&amp;gt;&lt;br /&gt;
  &amp;lt;option value=&amp;quot;2&amp;quot;&amp;gt;2&amp;lt;/option&amp;gt;&lt;br /&gt;
  &amp;lt;option value=&amp;quot;3&amp;quot;&amp;gt;3&amp;lt;/option&amp;gt;&lt;br /&gt;
&amp;lt;/select&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Display horizontal bar graph in HTML table data cell===&lt;br /&gt;
Using Perl&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
print (&amp;#039;&amp;lt;td class=&amp;quot;left&amp;quot;&amp;gt;&amp;#039; .&lt;br /&gt;
            &amp;#039;&amp;lt;div style=&amp;quot;background-color:#8097BE;width:&amp;quot;&amp;#039;,$allocpercused  ,&amp;#039;%;&amp;quot; /&amp;gt;&amp;#039; .&lt;br /&gt;
            &amp;#039;&amp;lt;div style=&amp;quot;background-color:red;    width:&amp;quot;&amp;#039;,$automaxpercused,&amp;#039;%;&amp;quot; /&amp;gt;&amp;#039; .&lt;br /&gt;
            $tspace .&lt;br /&gt;
       &amp;#039;&amp;lt;/td&amp;gt;&amp;#039;&lt;br /&gt;
);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Depending on which way around the divs are, you get different interpretations&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
print (&amp;quot;&amp;lt;td class=\&amp;quot;left\&amp;quot;&amp;gt;&amp;quot; .&lt;br /&gt;
            &amp;quot;&amp;lt;div style=\&amp;quot;border-right:2px solid red; width:&amp;quot;,($automaxpercused&amp;gt;99)?(100):($automaxpercused),&amp;quot;%;\&amp;quot; /&amp;gt;&amp;quot; .&lt;br /&gt;
            &amp;quot;&amp;lt;div style=\&amp;quot;background-color:#8097BE;width:&amp;quot;,$allocpercused  ,&amp;quot;%;\&amp;quot; /&amp;gt;&amp;quot; .&lt;br /&gt;
            $tspace .&lt;br /&gt;
       &amp;quot;&amp;lt;/td&amp;gt;&amp;quot;&lt;br /&gt;
);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====References====&lt;br /&gt;
* [http://stackoverflow.com/questions/5324996/comma-separated-list-as-a-result-of-select-statement-in-oracle stackoverflow.com]&lt;br /&gt;
* [http://www.salvis.com/blog/?p=207 A whole page showing how to do it in all versions back to 7!]&lt;/div&gt;</summary>
		<author><name>Stuart</name></author>	</entry>

	<entry>
		<id>https://mailnest.com/dbawiki/index.php?title=Snippets&amp;diff=3365</id>
		<title>Snippets</title>
		<link rel="alternate" type="text/html" href="https://mailnest.com/dbawiki/index.php?title=Snippets&amp;diff=3365"/>
				<updated>2018-11-04T00:57:32Z</updated>
		
		<summary type="html">&lt;p&gt;Stuart: /* Write to a trace log from PL/SQL */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;===Protecting an Apache Web Server directory with htaccess===&lt;br /&gt;
* [https://davidwalsh.name/password-protect-directory-using-htaccess https://davidwalsh.name/password-protect-directory-using-htaccess]&lt;br /&gt;
* [http://www.htaccesstools.com/articles/password-protection/ http://www.htaccesstools.com/articles/password-protection/]&lt;br /&gt;
Two files are needed.&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;The .htaccess Code&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
AuthType Basic&lt;br /&gt;
AuthName &amp;quot;restricted area&amp;quot;&lt;br /&gt;
AuthUserFile /home/davidwalsh/html/protect-me-dir/.htpasswd&lt;br /&gt;
require valid-user&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;The .htpasswd Code&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
davidwalsh:daWHfZrDLB88.&lt;br /&gt;
rodstewart:roFulYxC2.8ws&lt;br /&gt;
cssexpert:csmnmq.M8T5ho&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Protecting a lighttpd directory with htaccess===&lt;br /&gt;
Generate an MD5 hash with the tools above and paste into this file&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
vi /etc/lighttpd/.htpasswd&lt;br /&gt;
stuart:3#$567890#$56789056789&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Check modules.conf file to ensure mod_auth and mod_rewrite are enabled&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
vi /etc/lighttpd/modules.conf&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Alter the lighttpd.conf file to allow the authentication&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#auth directives&lt;br /&gt;
auth.backend = &amp;quot;htpasswd&amp;quot;&lt;br /&gt;
auth.backend.htpasswd.userfile = &amp;quot;/etc/lighttpd/.htpasswd&amp;quot;&lt;br /&gt;
auth.debug = 1&lt;br /&gt;
$HTTP[&amp;quot;url&amp;quot;] =~ &amp;quot;^/cgi-bin&amp;quot; {&lt;br /&gt;
        auth.require = ( &amp;quot;&amp;quot; =&amp;gt;&lt;br /&gt;
        (&lt;br /&gt;
        &amp;quot;method&amp;quot; =&amp;gt; &amp;quot;basic&amp;quot;,&lt;br /&gt;
        &amp;quot;realm&amp;quot; =&amp;gt; &amp;quot;DbaHawk access&amp;quot;,&lt;br /&gt;
        &amp;quot;require&amp;quot; =&amp;gt; &amp;quot;valid-user&amp;quot;&lt;br /&gt;
        ) )&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Restart the lighttpd server&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
systemctl stop lighttpd&lt;br /&gt;
systemctl start lighttpd&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
I tried it with htdigest but could not get it to protest the directory!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#auth.backend = &amp;quot;htdigest&amp;quot;&lt;br /&gt;
#auth.backend.htdigest.userfile = &amp;quot;/etc/lighttpd/lighttpd.user.htdigest&amp;quot;&lt;br /&gt;
#auth.require = (&lt;br /&gt;
#    &amp;quot;/var/www/cgi-bin/&amp;quot; =&amp;gt; (&lt;br /&gt;
#    &amp;quot;method&amp;quot;  =&amp;gt; &amp;quot;basic&amp;quot;,&lt;br /&gt;
#    &amp;quot;realm&amp;quot;   =&amp;gt; &amp;quot;DbaHawk access&amp;quot;,&lt;br /&gt;
#    &amp;quot;require&amp;quot; =&amp;gt; &amp;quot;valid-user&amp;quot;&lt;br /&gt;
#    ),&lt;br /&gt;
#)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Rename a datafile if the filename contains junk / unprintable characters===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter tablespace ts_thaler_data offline;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Oracle have a document that describes a few ways of doing it in [https://support.oracle.com/rs?type=doc&amp;amp;id=824473.1 Note 824473.1]&lt;br /&gt;
If the filename contains control characters and cannot be selected in the normal way, use ls -ali to find the node number and then use find with -inum to rename (or move) the file&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ls -baltri&lt;br /&gt;
total 47474984&lt;br /&gt;
12409 -rw-r-----    1 oracle   oinstall 1073750016 Sep 26 13:56 ts_thaler_data_02\1776.dbf&lt;br /&gt;
12350 -rw-r-----    1 oracle   oinstall 5242888192 Sep 26 13:56 ts_thaler_data_01.dbf&lt;br /&gt;
&lt;br /&gt;
find . -inum 12409 -exec mv {} ts_thaler_data_06.dbf \;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Work out what the database thinks the name is and rename it there too! AskTom has a discussion on it [https://asktom.oracle.com/pls/apex/asktom.search?tag=rename-datafile-with-dummy-characters-after-dbf here]&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select substr(name,i,1),ascii(substr(name,i,1)) from ( select name from v$datafile where file# = 9), ( select rownum i from dual connect by level &amp;lt;= 50);&lt;br /&gt;
SUBS ASCII(SUBSTR(NAME,I,1))&lt;br /&gt;
---- -----------------------&lt;br /&gt;
t                        116&lt;br /&gt;
s                        115&lt;br /&gt;
_                         95&lt;br /&gt;
t                        116&lt;br /&gt;
h                        104&lt;br /&gt;
a                         97&lt;br /&gt;
l                        108&lt;br /&gt;
e                        101&lt;br /&gt;
r                        114&lt;br /&gt;
_                         95&lt;br /&gt;
d                        100&lt;br /&gt;
a                         97&lt;br /&gt;
t                        116&lt;br /&gt;
a                         97&lt;br /&gt;
_                         95&lt;br /&gt;
0                         48&lt;br /&gt;
2                         50&lt;br /&gt;
                         127&lt;br /&gt;
2                         50&lt;br /&gt;
.                         46&lt;br /&gt;
d                        100&lt;br /&gt;
b                         98&lt;br /&gt;
f                        102&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
You can see there&amp;#039;s a 127 just before the .dbf... this crept in a the backspace key was not working correctly.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set serveroutput on&lt;br /&gt;
declare&lt;br /&gt;
   fname1 varchar2(100);&lt;br /&gt;
   fname2 varchar2(100);&lt;br /&gt;
begin&lt;br /&gt;
  select name into fname1 from v$datafile where file# = 9;&lt;br /&gt;
  fname2 := replace(fname1,chr(127));&lt;br /&gt;
  &lt;br /&gt;
  dbms_output.put_line(&amp;#039;alter database rename file &amp;#039;&amp;#039;&amp;#039;||fname1||&amp;#039;&amp;#039;&amp;#039; to &amp;#039;&amp;#039;&amp;#039;||fname2||&amp;#039;&amp;#039;&amp;#039;&amp;#039;);&lt;br /&gt;
  execute immediate &amp;#039;alter database rename file &amp;#039;&amp;#039;&amp;#039;||fname1||&amp;#039;&amp;#039;&amp;#039; to &amp;#039;&amp;#039;&amp;#039;||fname2||&amp;#039;&amp;#039;&amp;#039;&amp;#039;;&lt;br /&gt;
end;&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
alter tablespace ts_thaler_data_online;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Generate creation of directory names from dba_directories===&lt;br /&gt;
Before deleting or dropping directories in the database, use this script to generate the create statements&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select &amp;#039;create or replace directory &amp;#039;||directory_name||&amp;#039; as &amp;#039;&amp;#039;&amp;#039;||directory_path||&amp;#039;&amp;#039;&amp;#039;;&amp;#039; from dba_directories;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Check if current (dot) directory is in PATH variable===&lt;br /&gt;
Using bareword comparison to check PATH variable&amp;lt;pre&amp;gt;&lt;br /&gt;
if [[ :$PATH: == *:&amp;quot;.&amp;quot;:* ]] ; then&lt;br /&gt;
    echo &amp;quot;in path&amp;quot;&lt;br /&gt;
else&lt;br /&gt;
    echo &amp;quot;not in path&amp;quot;&lt;br /&gt;
fi&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===tail a logfile from within the script you are writing it to===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#&lt;br /&gt;
# display logfile in real time&lt;br /&gt;
#&lt;br /&gt;
( tail -0f ${LOGFILE} ) &amp;amp;&lt;br /&gt;
tailPID=$!&lt;br /&gt;
&lt;br /&gt;
trap &amp;quot;kill $tailPID&amp;quot; 0 1 2 3 5 9 15&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Dump package, procedure etc. from dba_source in a way that it can be used to recreate it===&lt;br /&gt;
From [https://asktom.oracle.com/pls/apex/f?p=100:11:0::::P11_QUESTION_ID:454220160386 Ask Tom]&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 1000 pages 1000 feedb off verif off&lt;br /&gt;
select decode( type||&amp;#039;-&amp;#039;||to_char(line,&amp;#039;fm99999&amp;#039;), &amp;#039;PACKAGE BODY-1&amp;#039;, &amp;#039;/&amp;#039;||chr(10), null) ||&lt;br /&gt;
       decode(line,1,&amp;#039;create or replace &amp;#039;, &amp;#039;&amp;#039; ) ||&lt;br /&gt;
       text text&lt;br /&gt;
from   dba_source&lt;br /&gt;
where  owner = upper(&amp;#039;&amp;amp;owner&amp;#039;)&lt;br /&gt;
and    name  = upper(&amp;#039;&amp;amp;object_to_show&amp;#039;)&lt;br /&gt;
order  by type&lt;br /&gt;
,      line&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===A trick to exit out of SQL*Plus (using divide by zero) depending on answer to a question===&lt;br /&gt;
This example is taken from ReviewLite.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
-- Settings for customized functionality&lt;br /&gt;
define SCRIPT_OO=_OPTIONS_ONLY -- collect only options information&lt;br /&gt;
define SCRIPT_OO=&amp;#039;&amp;#039;            -- collect all information [default behavior]&lt;br /&gt;
&lt;br /&gt;
define SCRIPT_TS=_TIME_STAMP   -- include timestamp in names of the output directory and output files: YYYY.MM.DD.HH24.MI.SS; script does not prompt for license agreement&lt;br /&gt;
define SCRIPT_TS=&amp;#039;\home\oracle\options&amp;#039;            -- standard names for output directory and output files; script prompts for license agreement [default behavior]&lt;br /&gt;
&lt;br /&gt;
-- PROMT FOR LICENSE AGREEMENT ACCEPTANCE&lt;br /&gt;
DEFINE LANSWER=N&lt;br /&gt;
SET TERMOUT ON&lt;br /&gt;
ACCEPT &amp;amp;SCRIPT_TS LANSWER FORMAT A1 PROMPT &amp;#039;Accept License Agreement? (y\n): &amp;#039;&lt;br /&gt;
&lt;br /&gt;
-- FORCE &amp;quot;divisor is equal to zero&amp;quot; AND SQLERROR EXIT IF NOT ACCEPTED&lt;br /&gt;
-- WILL ALSO CONTINUE IF SCRIPT_TS SUBSTITUTION VARIABLE IS NOT NULL&lt;br /&gt;
SET TERMOUT OFF&lt;br /&gt;
WHENEVER SQLERROR EXIT&lt;br /&gt;
select 1/decode(&amp;#039; &amp;amp;LANSWER&amp;#039;, &amp;#039;Y&amp;#039;, null, &amp;#039;y&amp;#039;, null, decode(&amp;#039; &amp;amp;SCRIPT_TS&amp;#039;, null, 0, null)) as &amp;quot; &amp;quot; from dual;&lt;br /&gt;
WHENEVER SQLERROR CONTINUE&lt;br /&gt;
SET TERMOUT ON&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===How to uninstall optional components such as OWB, APEX, EM, OLAP, OWM from an Oracle database===&lt;br /&gt;
* [http://fast-dba.blogspot.be/2014/04/how-to-remove-unwanted-components-from.html fast-dba.blogspot.be]&lt;br /&gt;
&lt;br /&gt;
===Find unique indexes / primary index / key columns in a table===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
col owner       for a12&lt;br /&gt;
col table_name  for a32&lt;br /&gt;
col column_name for a32&lt;br /&gt;
col position    for 99&lt;br /&gt;
col status      for a10&lt;br /&gt;
set lines 1000 pages 100&lt;br /&gt;
&lt;br /&gt;
SELECT cons.owner&lt;br /&gt;
,      cols.table_name&lt;br /&gt;
,      cols.column_name&lt;br /&gt;
,      cols.position&lt;br /&gt;
,      cons.status&lt;br /&gt;
FROM   all_constraints  cons&lt;br /&gt;
,      all_cons_columns cols&lt;br /&gt;
WHERE  1=1&lt;br /&gt;
and    cols.owner           = &amp;#039;&amp;amp;TABLE_OWNER&amp;#039;&lt;br /&gt;
and    cols.table_name      = &amp;#039;&amp;amp;TABLE_NAME&amp;#039;&lt;br /&gt;
AND    cons.constraint_type = &amp;#039;P&amp;#039;&lt;br /&gt;
AND    cons.constraint_name = cols.constraint_name&lt;br /&gt;
AND    cons.owner           = cols.owner&lt;br /&gt;
ORDER  BY cols.table_name&lt;br /&gt;
,      cols.position&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Display the oracle instances running on the local server===&lt;br /&gt;
sed could be shorter but this one works cross-platform&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alias oenv=&amp;#039;ps -ef|grep pmon|grep -v grep|awk -F_ &amp;quot;{print \$NF}&amp;quot;|sort|uniq|sed -e &amp;quot;:a&amp;quot; -e &amp;quot;N&amp;quot; -e &amp;quot;\$!ba&amp;quot; -e &amp;quot;s/\n/ /g&amp;quot;&amp;#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Display which databases are scheduled for backup in cron===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
for i in `ps -ef | grep [o]ra_pmon | awk -F_ &amp;#039;{print $NF}&amp;#039;`; do&lt;br /&gt;
    crontab -l | grep $i | grep backup_export | awk &amp;#039;{print $2&amp;quot;:&amp;quot;$1&amp;quot; - &amp;quot;$17}&amp;#039;&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Trace SQL statements using autotrace and explain plan===&lt;br /&gt;
If the plustrace (plustrc.sql) role has been granted, explaining sql statements (without running the statement) is as easy as&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter session set sql_trace=true;&lt;br /&gt;
set autotrace traceonly explain&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Write to a trace log from PL/SQL===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
dbms_system.ksdwrt(1,&amp;#039;message sent to a trace file&amp;#039;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Invisible / hidden / virtual columns===&lt;br /&gt;
Article showing how to dump blocks also.&lt;br /&gt;
[https://www.oracle.com/technetwork/articles/database/invisible-columns-odb12c-2331522.html Alex Zaballa, Oracle Ace and Daniel Da Meda (OCM)]&lt;br /&gt;
&lt;br /&gt;
===Write to the alert log from PL/SQL===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
dbms_system.ksdwrt(2,&amp;#039;message sent to the alert log&amp;#039;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Do distributed SQL transactions exist?===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select * from dba_2pc_pending;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
if yes, and to commit them...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select local_tran_id from dba_2pc_pending;&lt;br /&gt;
exec dbms_transaction.purge_lost_db_entry(&amp;#039;&amp;#039;);&lt;br /&gt;
commit;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Setup optional parameters and default values in an SQL*Plus script===&lt;br /&gt;
Some forgotten SQL*Plus tricks from the good old days and some new ones...&lt;br /&gt;
* [http://www.orafaq.com/wiki/SQL*Plus_FAQ#What_is_the_difference_between_.21_and_HOST.3F orafaq.com]&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set termout off&lt;br /&gt;
col p1 new_value 1&lt;br /&gt;
col p2 new_value 2&lt;br /&gt;
col p3 new_value 3&lt;br /&gt;
select null p1, null p2, null p3 from dual where  1=2;&lt;br /&gt;
select nvl(&amp;#039;&amp;amp;1&amp;#039;,&amp;#039;def1&amp;#039;) p1, nvl(&amp;#039;&amp;amp;2&amp;#039;,&amp;#039;def2&amp;#039;) p2, nvl(&amp;#039;&amp;amp;3&amp;#039;,&amp;#039;def3&amp;#039;) p3 from dual;&lt;br /&gt;
set termout on&lt;br /&gt;
prompt 1=&amp;quot;&amp;amp;1&amp;quot;&lt;br /&gt;
prompt 2=&amp;quot;&amp;amp;2&amp;quot;&lt;br /&gt;
prompt 3=&amp;quot;&amp;amp;3&amp;quot;&lt;br /&gt;
undef 1&lt;br /&gt;
undef 2&lt;br /&gt;
undef 3&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Display / show users with sysdba &amp;amp; sysoper privileges===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select * from v$pwfile_users;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Show path names of data files using instr===&lt;br /&gt;
Use to find the pathnames of all the filesystems/directories in which a database is housed.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select distinct substr(name,1,(instr(name,&amp;#039;/&amp;#039;,-1,1)-1)) path_name from v$datafile&lt;br /&gt;
union&lt;br /&gt;
select distinct substr(name,1,(instr(name,&amp;#039;/&amp;#039;,-1,1)-1)) path_name from v$tempfile&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Does a dataguard standby exist for this database?===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SELECT SUBSTR(value,INSTR(value,&amp;#039;=&amp;#039;,INSTR(UPPER(value),&amp;#039;SERVICE&amp;#039;))+1)&lt;br /&gt;
FROM   v$parameter&lt;br /&gt;
WHERE  name LIKE &amp;#039;log_archive_dest%&amp;#039; AND UPPER(value) LIKE &amp;#039;SERVICE%&amp;#039;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
gives something like this if found...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SUBSTR(VALUE,INSTR(VALUE,&amp;#039;=&amp;#039;,INSTR(UPPER(VALUE),&amp;#039;SERVICE&amp;#039;))+1)&lt;br /&gt;
--------------------------------------------------------------------------------&lt;br /&gt;
&amp;quot;jdbeop1_standby&amp;quot;, LGWR ASYNC NOAFFIRM delay=0 optional compression=disable m&lt;br /&gt;
ax_failure=0 max_connections=1 reopen=300 db_unique_name=&amp;quot;jdbeop1_standby&amp;quot; ne&lt;br /&gt;
t_timeout=60, valid_for=(all_logfiles,primary_role)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===List values for all init parameters in v$parameter (including default values for undocumented (hidden) parameters===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select i.ksppinm||&amp;#039;;&amp;#039;||sv.ksppstvl&lt;br /&gt;
from   x$ksppi  i&lt;br /&gt;
,      x$ksppsv sv&lt;br /&gt;
where  i.indx = sv.indx&lt;br /&gt;
order  by i.ksppinm;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Log file reports pipe errors===&lt;br /&gt;
Found these in the log file&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
solax005:root[/opt/IBM/ITM/logs]# tail solax005_or_RMANV11_col.out&lt;br /&gt;
CIR1880E (024955) Open Probe pipe error 2. Pipe=/opt/IBM/ITM/tmp/solax005_or_RMANV11/prb_RMANV11_kor_solax005_30024832_5346_pipe&lt;br /&gt;
CIR1880E (030938) Open Probe pipe error 2. Pipe=/opt/IBM/ITM/tmp/solax005_or_RMANV11/prb_RMANV11_kor_solax005_30030830_5406_pipe&lt;br /&gt;
CIR1880E (031923) Open Probe pipe error 2. Pipe=/opt/IBM/ITM/tmp/solax005_or_RMANV11/prb_RMANV11_kor_solax005_30031832_5434_pipe&lt;br /&gt;
CIR1880E (033934) Open Probe pipe error 2. Pipe=/opt/IBM/ITM/tmp/solax005_or_RMANV11/prb_RMANV11_kor_solax005_30033831_5495_pipe&lt;br /&gt;
CIR1880E (034918) Open Probe pipe error 2. Pipe=/opt/IBM/ITM/tmp/solax005_or_RMANV11/prb_RMANV11_kor_solax005_30034833_5521_pipe&lt;br /&gt;
CIR1880E (041927) Open Probe pipe error 2. Pipe=/opt/IBM/ITM/tmp/solax005_or_RMANV11/prb_RMANV11_kor_solax005_30041835_5610_pipe&lt;br /&gt;
CIR1880E (042931) Open Probe pipe error 2. Pipe=/opt/IBM/ITM/tmp/solax005_or_RMANV11/prb_RMANV11_kor_solax005_30042832_5642_pipe&lt;br /&gt;
CIR1880E (045928) Open Probe pipe error 2. Pipe=/opt/IBM/ITM/tmp/solax005_or_RMANV11/prb_RMANV11_kor_solax005_30045835_5730_pipe&lt;br /&gt;
CIR1880E (052927) Open Probe pipe error 2. Pipe=/opt/IBM/ITM/tmp/solax005_or_RMANV11/prb_RMANV11_kor_solax005_30052838_5819_pipe&lt;br /&gt;
CIR1880E (090929) Open Probe pipe error 2. Pipe=/opt/IBM/ITM/tmp/solax005_or_RMANV11/prb_RMANV11_kor_solax005_30090833_6487_pipe&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This could be due to a timeout on the pipe.&amp;lt;br /&amp;gt;&lt;br /&gt;
Increase parameters and restart agent. Add following lines to or.config:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
export COLL_WAIT_TIMEOUT=&amp;#039;200&amp;#039;&lt;br /&gt;
export WAIT_TIMEOUT=&amp;#039;200&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Find the most recent archived SCN number===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
col next_change# for 999999999999999&lt;br /&gt;
set numwidth 15&lt;br /&gt;
&lt;br /&gt;
select max(next_change#)&lt;br /&gt;
from   v$archived_log&lt;br /&gt;
where  (thread#, next_change#) in ( select thread#, max(next_change#)&lt;br /&gt;
                                    from   v$archived_log&lt;br /&gt;
                                    where  archived     = &amp;#039;YES&amp;#039;&lt;br /&gt;
                                    and    status       = &amp;#039;A&amp;#039;&lt;br /&gt;
                                    and    resetlogs_id = ( select resetlogs_id&lt;br /&gt;
                                                            from   v$database_incarnation&lt;br /&gt;
                                                            where  status = &amp;#039;CURRENT&amp;#039;&lt;br /&gt;
                                                          )&lt;br /&gt;
                                    group by thread#&lt;br /&gt;
                                  )&lt;br /&gt;
and    status = &amp;#039;A&amp;#039;&lt;br /&gt;
and    resetlogs_id = ( select resetlogs_id&lt;br /&gt;
                        from   v$database_incarnation&lt;br /&gt;
                        where  status = &amp;#039;CURRENT&amp;#039;&lt;br /&gt;
                      )&lt;br /&gt;
order  by next_change# asc;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Monitoring says database inactive===&lt;br /&gt;
* Check the candle user password has not expired in the database.&lt;br /&gt;
* There may be a clue in the log file. Check /opt/IBM/ITM/logs/`hostname`_or_${SID}_col.out&lt;br /&gt;
* Check limits for itmora account in /etc/security/limits. Should be same as oracle user.&lt;br /&gt;
* Check the config file. We had this issue when a new ORACLE_HOME was installed but the cfg file still had the old one in it.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
export ITM_HOME=/opt/IBM/ITM&lt;br /&gt;
cd $ITM_HOME/config&lt;br /&gt;
vi solax005_or_SRV2R.cfg&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#  IBM Tivoli Monitoring for Databases: Oracle Agent&lt;br /&gt;
#  Configuration file: solax005_or_SRV2R.cfg&lt;br /&gt;
#  Written by CandleDBconfig version: 1.4 on 31Jul13 13:39:41&lt;br /&gt;
&lt;br /&gt;
#  Note: this is a Korn-shell script that is &amp;quot;sourced&amp;quot; to create the&lt;br /&gt;
#  environment for a Monitoring Agent for Oracle.  It can be used to create&lt;br /&gt;
#  the environment to run the IBM-supplied database grant scripts.&lt;br /&gt;
&lt;br /&gt;
#  IBM does not recommend that you modify this file, but you can change the&lt;br /&gt;
#  data values or add new exported variables as long as the file is a valid ksh&lt;br /&gt;
#  script that executes with zero return code, and values remain quoted with &amp;quot;&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
#  Following environment variables are set for convenience in running grants.&lt;br /&gt;
   export ORACLE_SID=&amp;quot;SRV2R&amp;quot;&lt;br /&gt;
   export ORACLE_HOME=&amp;quot;/oracle/product/11.2.0.1&amp;quot;&lt;br /&gt;
   # IY92195  COLL_DISABLE_CURSORS setting&lt;br /&gt;
   export TNS_ADMIN=&amp;quot;/oracle/product/11.2.0.1/network/admin&amp;quot;&lt;br /&gt;
&lt;br /&gt;
#  Following variables are set for the setup scripts&lt;br /&gt;
   db_sid=&amp;quot;SRV2R&amp;quot;&lt;br /&gt;
   db_home=&amp;quot;/oracle/product/11.2.0.1&amp;quot;&lt;br /&gt;
   db_initfilename=&amp;quot;&amp;quot;&lt;br /&gt;
   db_login=&amp;quot;tivoli&amp;quot;&lt;br /&gt;
   db_password=&amp;quot;795D8822BC49477323815CD21C1E66E966E48EEE19C6A98056224D649B0FE316E6A11DC3F4E9BB5E226B65A8&amp;quot;&lt;br /&gt;
   db_ver=&amp;quot;11.x&amp;quot;&lt;br /&gt;
   db_type=&amp;quot;kor&amp;quot;&lt;br /&gt;
   db_tns=&amp;quot;/oracle/product/11.2.0.1/network/admin&amp;quot;&lt;br /&gt;
   db_extparms=&amp;quot;&amp;quot;&lt;br /&gt;
   db_hostname=&amp;quot;solax005&amp;quot;&lt;br /&gt;
   db_reason=&amp;quot;AIX_ps_ceww&amp;quot;&lt;br /&gt;
   db_pipedir=&amp;quot;&amp;quot;&lt;br /&gt;
   db_installstatus=&amp;quot;CONFIGSUCCESS&amp;quot;&lt;br /&gt;
&lt;br /&gt;
#  User-defined environment variables&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Solution:&amp;lt;br /&amp;gt;&lt;br /&gt;
* Change all occurrences of 11.2.0.1 to 11.2.0.3&lt;br /&gt;
* Restart agent&lt;br /&gt;
&lt;br /&gt;
===Alerts due to password expiring (or being changed in the database but not in ITM!)===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cd $ITM_HOME/logs&lt;br /&gt;
ls -altr | grep WM820T&lt;br /&gt;
tail -20 solax005_or_WM820T_col.out&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
CGN1521E (161614) Interval collection failed for cursor KORHART2&lt;br /&gt;
RCD0110S (161614) Invalid Oracle logon id (tivoli) or password given&lt;br /&gt;
 Please contact DBA to correct userid or password&lt;br /&gt;
CGN1521E (161614) Interval collection failed for cursor KORHART4&lt;br /&gt;
CGN1525E (161614) One or more interval cursors failed&lt;br /&gt;
RCD0110S (161714) Invalid Oracle logon id (tivoli) or password given&lt;br /&gt;
 Please contact DBA to correct userid or password&lt;br /&gt;
CGN1521E (161714) Interval collection failed for cursor KORHART2&lt;br /&gt;
RCD0110S (161714) Invalid Oracle logon id (tivoli) or password given&lt;br /&gt;
 Please contact DBA to correct userid or password&lt;br /&gt;
CGN1521E (161714) Interval collection failed for cursor KORHART4&lt;br /&gt;
CGN1525E (161714) One or more interval cursors failed&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Solution:&amp;lt;br /&amp;gt;&lt;br /&gt;
* Run agent reconfigure to setup the new password for the candle user (tivoli)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
export ITM_HOME=/opt/IBM/ITM&lt;br /&gt;
$ITM_HOME/bin/itmcmd config -A or&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Restart agent&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
export ITM_HOME=/opt/IBM/ITM&lt;br /&gt;
$ITM_HOME/smitools/scripts/StartAgent.sh restart or -o WM820T&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Many agents started with root user instead of itmora===&lt;br /&gt;
This can happen if the server is rebooted before the agents have been added to the itmora list using kdyedit / kciedit&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
export CANDLEHOME=/opt/IBM/ITM&lt;br /&gt;
export ITM_HOME=/opt/IBM/ITM&lt;br /&gt;
$ITM_HOME/smitools/scripts/kdyedit list&lt;br /&gt;
Type Runas      Inst                &lt;br /&gt;
or   root       AGPDEV              &lt;br /&gt;
or   root       BO1R                &lt;br /&gt;
or   root       DEV3                &lt;br /&gt;
or   root       EMREP               &lt;br /&gt;
or   root       ICR                 &lt;br /&gt;
or   itmora     MAPDEV              &lt;br /&gt;
or   itmora     MAPER               &lt;br /&gt;
or   itmora     PED                 &lt;br /&gt;
or   itmora     PER                 &lt;br /&gt;
or   itmora     RMANV11             &lt;br /&gt;
or   itmora     SRV2R               &lt;br /&gt;
or   itmora     WM820Q              &lt;br /&gt;
or   itmora     WM820T              &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ITM_HOME/smitools/scripts/kciedit list&lt;br /&gt;
Type Runas      Inst                &lt;br /&gt;
or   root       AGPDEV              &lt;br /&gt;
or   root       BO1R                &lt;br /&gt;
or   root       DEV3                &lt;br /&gt;
or   root       EMREP               &lt;br /&gt;
or   root       ICR                 &lt;br /&gt;
or   itmora     MAPDEV              &lt;br /&gt;
or   itmora     MAPER               &lt;br /&gt;
or   itmora     PED                 &lt;br /&gt;
or   itmora     PER                 &lt;br /&gt;
or   itmora     RMANV11             &lt;br /&gt;
or   itmora     SRV2R               &lt;br /&gt;
or   itmora     WM820Q              &lt;br /&gt;
or   itmora     WM820T              &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Solution: Add these instances to the itmora list&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
./kdyedit -t or -i AGPDEV -r itmora add&lt;br /&gt;
./kciedit -t or -i AGPDEV -r itmora add&lt;br /&gt;
...&lt;br /&gt;
./kdyedit -t or -i ICR -r itmora add&lt;br /&gt;
./kciedit -t or -i ICR -r itmora add&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ITM_HOME/smitools/scripts/kciedit list&lt;br /&gt;
Type Runas      Inst                &lt;br /&gt;
or   itmora     AGPDEV              &lt;br /&gt;
or   itmora     BO1R                &lt;br /&gt;
or   itmora     DEV3                &lt;br /&gt;
or   itmora     EMREP               &lt;br /&gt;
or   itmora     ICR                 &lt;br /&gt;
or   itmora     MAPDEV              &lt;br /&gt;
or   itmora     MAPER               &lt;br /&gt;
or   itmora     PED                 &lt;br /&gt;
or   itmora     PER                 &lt;br /&gt;
or   itmora     RMANV11             &lt;br /&gt;
or   itmora     SRV2R               &lt;br /&gt;
or   itmora     WM820Q              &lt;br /&gt;
or   itmora     WM820T              &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Kill any agents still running as root&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ps -ef |grep kor | grep root&lt;br /&gt;
kill -9 &amp;lt;process id&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Because these agents were owned by root, there will be permissions issues when trying to restart the agents with itmora so these need to be fixed before restarting the agents.&amp;lt;br /&amp;gt;&lt;br /&gt;
The simplest way of doing this is to run lockdown.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
export CANDLEHOME=/opt/IBM/ITM&lt;br /&gt;
$CANDLEHOME/smitools/scripts/lockdown.sh&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===See which processes are causing paging===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
svmon -Pt20 | perl -e &amp;#039;while(&amp;lt;&amp;gt;){print if($.==2||$&amp;amp;&amp;amp;&amp;amp;!$s++);$.=0 if(/^-+$/)}&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===How to return several variables from SQL*Plus back to Korn shell script===&lt;br /&gt;
Return multiple columns/elements from Oracle to shell script at the same time&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sqlplus -s sys/${SYS_PASSWORD}@${SID} as sysdba&amp;lt;&amp;lt;EOSQL | read SPACE_AFTER_INSTALL TOTAL_SPACE_AVAILABLE&lt;br /&gt;
set numwid 15 headi off newpa none feedb off&lt;br /&gt;
select sign(${SPACE_USED} + ${SPACE_AVAILABLE} - ${DATABASE_SIZE}), trim(${SPACE_USED} + ${SPACE_AVAILABLE})&lt;br /&gt;
from dual&lt;br /&gt;
/&lt;br /&gt;
EOSQL&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===How to get a shell environment variable from the operating system into the SQL or PL/SQL environment===&lt;br /&gt;
This has been bugging me for years. Something you would think simple... what is ORACLE_HOME? I know it&amp;#039;s a question mark at the SQL prompt but how to get it&amp;#039;s O/S value?&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
declare&lt;br /&gt;
    var1 varchar2(200);&lt;br /&gt;
begin&lt;br /&gt;
    dbms_system.get_env (&amp;#039;ORACLE_HOME&amp;#039;, var1);&lt;br /&gt;
    dbms_output.put_line (&amp;#039;ORACLE_HOME: &amp;#039;||var1);&lt;br /&gt;
end;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or in SQL*Plus&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
variable var1 varchar2(200);&lt;br /&gt;
exec dbms_system.get_env (&amp;#039;ORACLE_HOME&amp;#039;, :var1);&lt;br /&gt;
select :var1 from dual;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
That got me thinking... if this just gets stuff from the environment, it can fetch any exported variable?!?!&amp;lt;br /&amp;gt;&lt;br /&gt;
From the shell:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
export running_sids=`ps -ef | grep [p]mon | awk -F_ &amp;#039;{print $NF}&amp;#039;`&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
and now in SQL*Plus:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
variable sids varchar2(240);&lt;br /&gt;
exec dbms_system.get_env (&amp;#039;running_sids&amp;#039;, :sids);&lt;br /&gt;
select :sids from dual;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Wow!&lt;br /&gt;
&lt;br /&gt;
===How long/wide can a database name/sid be?===&lt;br /&gt;
Depends on where you look but taking the minimum here as &amp;quot;safe&amp;quot;, it should still be limited to 8 characters...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
col table_name for a30&lt;br /&gt;
col data_type  for a12&lt;br /&gt;
select table_name, data_type, data_length from dba_tab_columns where column_name = &amp;#039;DB_NAME&amp;#039;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This is 11gR2&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
TABLE_NAME                     DATA_TYPE    DATA_LENGTH&lt;br /&gt;
------------------------------ ------------ -----------&lt;br /&gt;
LOGMNRG_DICTIONARY$            VARCHAR2               9&lt;br /&gt;
SYS_FBA_CONTEXT_AUD            VARCHAR2             256&lt;br /&gt;
V_$LOGMNR_DICTIONARY           VARCHAR2               9&lt;br /&gt;
V_$LOGMNR_LOGS                 VARCHAR2               8&lt;br /&gt;
GV_$LOGMNR_DICTIONARY          VARCHAR2               9&lt;br /&gt;
GV_$LOGMNR_LOGS                VARCHAR2               8&lt;br /&gt;
V_$LOGMNR_LOGFILE              VARCHAR2               8&lt;br /&gt;
V_$LOGMNR_SESSION              VARCHAR2             128&lt;br /&gt;
GV_$LOGMNR_LOGFILE             VARCHAR2               8&lt;br /&gt;
GV_$LOGMNR_SESSION             VARCHAR2             128&lt;br /&gt;
GV_$ASM_CLIENT                 VARCHAR2               8&lt;br /&gt;
V_$ASM_CLIENT                  VARCHAR2               8&lt;br /&gt;
GV_$IOS_CLIENT                 VARCHAR2              64&lt;br /&gt;
V_$IOS_CLIENT                  VARCHAR2              64&lt;br /&gt;
DBA_PDB_HISTORY                VARCHAR2             128&lt;br /&gt;
CDB_PDB_HISTORY                VARCHAR2             128&lt;br /&gt;
SSCR_CAP$                      VARCHAR2            4000&lt;br /&gt;
SSCR_RES$                      VARCHAR2            4000&lt;br /&gt;
DBA_SSCR_CAPTURE               VARCHAR2            4000&lt;br /&gt;
CDB_SSCR_CAPTURE               VARCHAR2            4000&lt;br /&gt;
DBA_SSCR_RESTORE               VARCHAR2            4000&lt;br /&gt;
CDB_SSCR_RESTORE               VARCHAR2            4000&lt;br /&gt;
WRM$_DATABASE_INSTANCE         VARCHAR2               9&lt;br /&gt;
INT$DBA_HIST_DATABASE_INSTANCE VARCHAR2               9&lt;br /&gt;
DBA_HIST_DATABASE_INSTANCE     VARCHAR2               9&lt;br /&gt;
CDB_HIST_DATABASE_INSTANCE     VARCHAR2               9&lt;br /&gt;
LOGMNR_DICTIONARY$             VARCHAR2               9&lt;br /&gt;
&lt;br /&gt;
27 rows selected.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===What character set (characterset) was the database built with?===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
col name  for a40&lt;br /&gt;
col value for a60&lt;br /&gt;
select * from nls_database_parameters;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
col name   for a40&lt;br /&gt;
col value$ for a60&lt;br /&gt;
select name,value$ from props$ where name = &amp;#039;NLS_CHARACTERSET&amp;#039;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===How to find ORACLE_HOME from pmon process for a SID if there is no entry in oratab===&lt;br /&gt;
If database is created without dbca (datafile and controlfile copy), no entry will be automatically made in /etc/oratab.&amp;lt;br /&amp;gt;&lt;br /&gt;
So the problem is that you need to find out which of the ORACLE_HOMEs is being used by the running instances.&lt;br /&gt;
* Solaris, Linux&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ ps -ef | grep [p]mon&lt;br /&gt;
  oracle 10848     1   0 00:21:20 ?           2:11 ora_pmon_JDBEOP1&lt;br /&gt;
$ pwdx 10848&lt;br /&gt;
10848:  /oracle/JDBEOP1/product/11204/dbs&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* AIX&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ ps -ef | grep [p]mon&lt;br /&gt;
  oracle 13893878        1   0   Aug 12      -  7:53 ora_pmon_GOAQ1&lt;br /&gt;
$ ls -al /proc/13893878/cwd&lt;br /&gt;
lr-x------    2 oracle   dba               0 Aug 12 13:37  cwd -&amp;gt; /data/opt/app/product/11.2.0.4/db_1/dbs/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or&amp;lt;br /&amp;gt;&lt;br /&gt;
This command (ps eww) gives lots of information about the given process (pmon in this case). Tells you where the instance was started, whether it was started from SQL*Plus or RMAN, the http_proxy and loads more useful bits!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ps -ef | grep [p]mon | awk &amp;#039;{print $2}&amp;#039; | xargs -I {} ps eww {} | awk &amp;#039;{print $1 &amp;quot; &amp;quot; $5 &amp;quot; &amp;quot; $6 &amp;quot; &amp;quot; $0}&amp;#039; | sed &amp;#039;s/\(S*\) \(S*\) .*ORACLE_HOME/\1 \2/g&amp;#039; | cut -f1,2,3 -d&amp;quot; &amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Escape the underscore(_) or percent(%) character in an SQL statement===&lt;br /&gt;
The underscore matches any single character so to return data containing an underscore means having to use an escape character.&amp;lt;br /&amp;gt;&lt;br /&gt;
Here I use the backslash(\) so it is easy for Unix people to understand the mechanism.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select username from dba_users where username like &amp;#039;ENDUR\_DEV%&amp;#039; escape &amp;#039;\&amp;#039;; &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Validate, analyse and rebuild indexes===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set feedback off&lt;br /&gt;
set linesize 132&lt;br /&gt;
set serveroutput on&lt;br /&gt;
set trimspool on&lt;br /&gt;
&lt;br /&gt;
declare&lt;br /&gt;
    LOCKED exception;&lt;br /&gt;
    pragma exception_init (LOCKED, -54);&lt;br /&gt;
&lt;br /&gt;
    dbase         char(8);&lt;br /&gt;
    dbuser        varchar2(30);&lt;br /&gt;
    index_name    varchar(30);&lt;br /&gt;
    free_text     varchar2(50);&lt;br /&gt;
    pctused       number;&lt;br /&gt;
    height    number;&lt;br /&gt;
    index_mb      number;&lt;br /&gt;
    analyze_sql   varchar2(100);&lt;br /&gt;
    pct_used_sql  varchar2(150);&lt;br /&gt;
    rebuild_sql   varchar2(150);&lt;br /&gt;
 &lt;br /&gt;
    cursor c1 is&lt;br /&gt;
    select segment_name, bytes&lt;br /&gt;
    from   user_segments&lt;br /&gt;
    where  segment_type = &amp;#039;INDEX&amp;#039;&lt;br /&gt;
    and    segment_name like &amp;#039;DW%&amp;#039;&lt;br /&gt;
    and    segment_name not like &amp;#039;BIN%&amp;#039;&lt;br /&gt;
    and    bytes/1024   &amp;gt;= 1024&lt;br /&gt;
    order  by 2;&lt;br /&gt;
&lt;br /&gt;
-- validate the index&lt;br /&gt;
procedure validate_index (v_ind in varchar2) is&lt;br /&gt;
begin&lt;br /&gt;
    analyze_sql := &amp;#039;analyze index &amp;#039;||v_ind||&amp;#039; validate structure&amp;#039;;&lt;br /&gt;
    begin&lt;br /&gt;
        execute immediate analyze_sql;&lt;br /&gt;
    exception&lt;br /&gt;
    when LOCKED then&lt;br /&gt;
        dbms_output.put_line (v_ind||&amp;#039; locked - skipping&amp;#039;);&lt;br /&gt;
        pctused := 100;&lt;br /&gt;
        return;&lt;br /&gt;
    when others then&lt;br /&gt;
        dbms_output.put_line (analyze_sql);&lt;br /&gt;
        raise;&lt;br /&gt;
    end;&lt;br /&gt;
&lt;br /&gt;
    pct_used_sql := &amp;#039;select pct_used, round(blocks*8192/(1024*1024)), height from index_stats where name = &amp;#039;&amp;#039;&amp;#039;||v_ind||&amp;#039;&amp;#039;&amp;#039;&amp;#039;;&lt;br /&gt;
    execute immediate pct_used_sql into pctused, index_mb, height;&lt;br /&gt;
    if pctused is null then&lt;br /&gt;
        pctused := 0;&lt;br /&gt;
    end if;&lt;br /&gt;
    dbms_output.put_line (rpad(v_ind,35)||&amp;#039; (pct used &amp;#039;||pctused||&amp;#039;% size &amp;#039;||index_mb||&amp;#039;Mb height &amp;#039; || height ||&amp;#039;)&amp;#039;);&lt;br /&gt;
end validate_index;&lt;br /&gt;
 &lt;br /&gt;
-- execute SQL and trace if errors&lt;br /&gt;
procedure run_sql (v_sql in varchar2) is&lt;br /&gt;
begin&lt;br /&gt;
    execute immediate v_sql;&lt;br /&gt;
exception&lt;br /&gt;
when others then&lt;br /&gt;
    dbms_output.put_line (v_sql);&lt;br /&gt;
    raise;&lt;br /&gt;
end run_sql;&lt;br /&gt;
 &lt;br /&gt;
--&lt;br /&gt;
-- Script starts here&lt;br /&gt;
--&lt;br /&gt;
begin&lt;br /&gt;
    dbms_output.enable(1000000);&lt;br /&gt;
    -- Set up database name and schema&lt;br /&gt;
    -- select name into dbase  from v$database;&lt;br /&gt;
    select user into dbuser from dual;&lt;br /&gt;
    dbms_output.put_line(&amp;#039;============================================================================= *&amp;#039;);&lt;br /&gt;
    -- dbms_output.put_line(&amp;#039;* Indexes rebuild report for &amp;#039;||dbuser||&amp;#039; on &amp;#039;||dbase);&lt;br /&gt;
    dbms_output.put_line(&amp;#039;============================================================================= *&amp;#039;);&lt;br /&gt;
&lt;br /&gt;
    -- Loop around Indexes&lt;br /&gt;
    for x in c1 loop&lt;br /&gt;
        index_name := x.segment_name;&lt;br /&gt;
        validate_index (index_name );&lt;br /&gt;
        if pctused &amp;lt; 81 then&lt;br /&gt;
            if x.bytes/1024/1024 &amp;lt; 100 then&lt;br /&gt;
                rebuild_sql := &amp;#039;alter index &amp;#039;||x.segment_name||&amp;#039; rebuild online&amp;#039;;&lt;br /&gt;
            else&lt;br /&gt;
                rebuild_sql := &amp;#039;alter index &amp;#039;||x.segment_name||&amp;#039; coalesce&amp;#039;;&lt;br /&gt;
            end if;&lt;br /&gt;
            dbms_output.put_line (rebuild_sql);&lt;br /&gt;
            run_sql (rebuild_sql);&lt;br /&gt;
            validate_index (index_name);&lt;br /&gt;
        end if;&lt;br /&gt;
    end loop;&lt;br /&gt;
end;&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
set feed on&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Rebuild unusable indexes on a table===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select &amp;#039;alter index &amp;#039;||owner||&amp;#039;.&amp;#039;||index_name||&amp;#039; rebuild;&amp;#039;&lt;br /&gt;
from   dba_indexes&lt;br /&gt;
where  1=1&lt;br /&gt;
and    status    != &amp;#039;VALID&amp;#039;&lt;br /&gt;
and    owner     not in (&amp;#039;SYS&amp;#039;,&amp;#039;SYSTEM&amp;#039;)&lt;br /&gt;
--and    owner      = &amp;#039;WM822PP&amp;#039;&lt;br /&gt;
--and    table_name = &amp;#039;WF_PLANTS&amp;#039;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Pull the latest cfengine changes now instead of waiting for scheduled time===&lt;br /&gt;
For one host&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/opt/cfengine/bin/cfagent -ID dbaTime&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
On all hosts at the same time&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/home/ibmtools/scripts/oracle/dosh -c &amp;quot;/opt/cfengine/bin/cfagent -ID dbaTime&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Check status of datafiles without dba_data_files or v$datafile===&lt;br /&gt;
If the database is in mount mode, most tables are unavailable. This query uses the x$ (c based) tables and are always available&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set linesize 200;&lt;br /&gt;
set pagesize 100;&lt;br /&gt;
col inst_id for 9999999 heading &amp;#039;Instance #&amp;#039;&lt;br /&gt;
col file_nr for 9999999 heading &amp;#039;File #&amp;#039;&lt;br /&gt;
col file_name for A50 heading &amp;#039;File name&amp;#039;&lt;br /&gt;
col checkpoint_change_nr for 99999999999999 heading &amp;#039;Checkpoint #&amp;#039;&lt;br /&gt;
col checkpoint_change_time for A20 heading &amp;#039;Checkpoint time&amp;#039;&lt;br /&gt;
col last_change_nr for 99999999999999 heading &amp;#039;Last change #&amp;#039;&lt;br /&gt;
SELECT&lt;br /&gt;
      fe.inst_id,&lt;br /&gt;
      fe.fenum file_nr,&lt;br /&gt;
      fn.fnnam file_name,&lt;br /&gt;
      TO_NUMBER (fe.fecps) checkpoint_change_nr,&lt;br /&gt;
      fe.fecpt checkpoint_change_time,&lt;br /&gt;
      fe.fests last_change_nr,&lt;br /&gt;
      DECODE (&lt;br /&gt;
              fe.fetsn,&lt;br /&gt;
              0, DECODE (BITAND (fe.festa, 2), 0, &amp;#039;SYSOFF&amp;#039;, &amp;#039;SYSTEM&amp;#039;),&lt;br /&gt;
              DECODE (BITAND (fe.festa, 18),&lt;br /&gt;
                      0, &amp;#039;OFFLINE&amp;#039;,&lt;br /&gt;
                      2, &amp;#039;ONLINE&amp;#039;,&lt;br /&gt;
                      &amp;#039;RECOVER&amp;#039;)&lt;br /&gt;
      ) status&lt;br /&gt;
FROM x$kccfe fe,&lt;br /&gt;
     x$kccfn fn&lt;br /&gt;
WHERE    (   (fe.fepax != 65535 AND fe.fepax != 0 )&lt;br /&gt;
          OR (fe.fepax = 65535 OR fe.fepax = 0)&lt;br /&gt;
         )&lt;br /&gt;
     AND fn.fnfno = fe.fenum&lt;br /&gt;
     AND fe.fefnh = fn.fnnum&lt;br /&gt;
     AND fe.fedup != 0&lt;br /&gt;
     AND fn.fntyp = 4&lt;br /&gt;
     AND fn.fnnam IS NOT NULL&lt;br /&gt;
     AND BITAND (fn.fnflg, 4) != 4&lt;br /&gt;
ORDER BY fe.fenum&lt;br /&gt;
;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Check highest allocated extent in datafile (likely slow when having many extents)===&lt;br /&gt;
* Script to Detect Tablespace Fragmentation ( Doc ID 1020182.6 )&lt;br /&gt;
* How to shrink or reduce the datafile size by finding the high water mark (HWM) ( Doc ID 1600774.1 )&lt;br /&gt;
* How to find Objects Fragmented below High Water Mark ( Doc ID 337651.1 )&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
column file_name format a50;&lt;br /&gt;
column tablespace_name format a15;&lt;br /&gt;
column highwater format 9999999999;&lt;br /&gt;
set pagesize 9999&lt;br /&gt;
&lt;br /&gt;
select a.tablespace_name&lt;br /&gt;
,a.file_name&lt;br /&gt;
,(b.maximum+c.blocks-1)*d.db_block_size highwater&lt;br /&gt;
from dba_data_files a&lt;br /&gt;
,(select file_id,max(block_id) maximum&lt;br /&gt;
from dba_extents&lt;br /&gt;
group by file_id) b&lt;br /&gt;
,dba_extents c&lt;br /&gt;
,(select value db_block_size&lt;br /&gt;
from v$parameter&lt;br /&gt;
where name=&amp;#039;db_block_size&amp;#039;) d&lt;br /&gt;
where a.file_id = b.file_id&lt;br /&gt;
and c.file_id = b.file_id&lt;br /&gt;
and c.block_id = b.maximum&lt;br /&gt;
order by a.tablespace_name,a.file_name&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Runup to this was...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set markup html on spool on&lt;br /&gt;
spool db_info.html&lt;br /&gt;
set echo on&lt;br /&gt;
select * from dba_tablespaces where tablespace_name = &amp;#039;&amp;amp;&amp;amp;tablespace_name&amp;#039;;&lt;br /&gt;
select * from dba_data_files where tablespace_name = &amp;#039;&amp;amp;tablespace_name&amp;#039;;&lt;br /&gt;
select * from (select * from dba_extents where tablespace_name = &amp;#039;&amp;amp;tablespace_name&amp;#039; order by block_id desc) where rownum &amp;lt;301;&lt;br /&gt;
spool off&lt;br /&gt;
set markup html off&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select owner, segment_type, count(*) from dba_segments where tablesapce_name=&amp;#039;&amp;amp;tablespace_name&amp;#039; group by owner, segment_type;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
begin&lt;br /&gt;
for ii in (select owner, segment_name, segment_type from dba_segments where tablespace_name = &amp;#039;&amp;amp;tablespace_name&amp;#039; and segment_type like &amp;#039;TABLE%&amp;#039; and segment_name not like &amp;#039;%DATAPUMP%&amp;#039;)&lt;br /&gt;
loop&lt;br /&gt;
if ii.segment_type=&amp;#039;TABLE&amp;#039; then&lt;br /&gt;
begin&lt;br /&gt;
execute immediate(&amp;#039;alter table &amp;#039;||ii.owner||&amp;#039;.&amp;#039;||ii.segment_name||&amp;#039; enable row movement&amp;#039;);&lt;br /&gt;
execute immediate(&amp;#039;alter table &amp;#039;||ii.owner||&amp;#039;.&amp;#039;||ii.segment_name||&amp;#039; shrink space cascade&amp;#039;);&lt;br /&gt;
exception when others then&lt;br /&gt;
dbms_output.put_line(&amp;#039;FAILED 1: alter table &amp;#039;||ii.owner||&amp;#039;.&amp;#039;||ii.segment_name||&amp;#039; shrink space cascade : &amp;#039;||SQLERRM);&lt;br /&gt;
end;&lt;br /&gt;
end if;&lt;br /&gt;
end loop;&lt;br /&gt;
end;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Procedure to shrink space in tables and indexes===&lt;br /&gt;
* [http://www.oracle-wiki.net/startdocsreallifeshrinkexample Using the Oracle Shrink Command] - lots of good stuff at this site&lt;br /&gt;
Written by [https://asktom.oracle.com/pls/apex/f%3Fp%3D100:11:0::::P11_QUESTION_ID:5645095700346948864 Tom Kyte]&amp;lt;br /&amp;gt;&lt;br /&gt;
Depending on the Oracle version, this procedure may or may not work! It does not include the compact clause (neither does it re-analyse to prove it worked).&amp;lt;br /&amp;gt;&lt;br /&gt;
[http://www.oracle-wiki.net/startdocsreallifeshrinkexample Here] is a worked example that shows the complete process - oracle-wiki.net&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
create or replace procedure shrink_all&lt;br /&gt;
as&lt;br /&gt;
    l_sql        varchar2(4000);&lt;br /&gt;
    l_sql2       varchar2(4000);&lt;br /&gt;
    row_movement exception;&lt;br /&gt;
    pragma       exception_init( row_movement, -10636 );&lt;br /&gt;
begin&lt;br /&gt;
    for x in (select table_name&lt;br /&gt;
              ,      owner&lt;br /&gt;
              from   t&lt;br /&gt;
              where  sgm_space_management = &amp;#039;AUTO&amp;#039;)&lt;br /&gt;
    loop&lt;br /&gt;
        l_sql := &amp;#039;alter table &amp;quot;&amp;#039; || x.owner || &amp;#039;&amp;quot;.&amp;quot;&amp;#039; || x.table_name || &amp;#039;&amp;quot; shrink space&amp;#039;;&lt;br /&gt;
        dbms_output.put_line( l_sql );&lt;br /&gt;
&lt;br /&gt;
        begin&lt;br /&gt;
            execute immediate l_sql;&lt;br /&gt;
        exception&lt;br /&gt;
        when row_movement&lt;br /&gt;
        then&lt;br /&gt;
            dbms_output.put_line( &amp;#039;failed due to row movement...&amp;#039; );&lt;br /&gt;
            l_sql2 := &amp;#039;alter table &amp;quot;&amp;#039; || x.owner || &amp;#039;&amp;quot;.&amp;quot;&amp;#039; || x.table_name || &amp;#039;&amp;quot; enable row movement&amp;#039;;&lt;br /&gt;
            dbms_output.put_line( l_sql2 );&lt;br /&gt;
            execute immediate l_sql2;&lt;br /&gt;
            dbms_output.put_line( l_sql );&lt;br /&gt;
            execute immediate l_sql;&lt;br /&gt;
        end;&lt;br /&gt;
&lt;br /&gt;
        for y in (select owner&lt;br /&gt;
                  ,      index_name&lt;br /&gt;
                  from   dba_indexes&lt;br /&gt;
                  where  table_owner = x.owner&lt;br /&gt;
                  and    table_name  = x.table_name )&lt;br /&gt;
        loop&lt;br /&gt;
            l_sql := &amp;#039;alter index &amp;quot;&amp;#039; || y.owner || &amp;#039;&amp;quot;.&amp;quot;&amp;#039; || y.index_name || &amp;#039;&amp;quot; shrink space&amp;#039;;&lt;br /&gt;
            dbms_output.put_line( l_sql );&lt;br /&gt;
            execute immediate l_sql;&lt;br /&gt;
        end loop;&lt;br /&gt;
&lt;br /&gt;
    end loop;&lt;br /&gt;
end;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===How to delete/kill a distributed transaction===&lt;br /&gt;
From [http://www.pouwiel.com/?p=2204 pouwiel.com]&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SQL&amp;gt; SELECT LOCAL_TRAN_ID, GLOBAL_TRAN_ID,to_char(FAIL_TIME,&amp;#039;dd-mon-yyyy HH24:MI:SS&amp;#039;),STATE, MIXED FROM DBA_2PC_PENDING;&lt;br /&gt;
&lt;br /&gt;
LOCAL_TRAN_ID&lt;br /&gt;
----------------------&lt;br /&gt;
GLOBAL_TRAN_ID&lt;br /&gt;
--------------------------------------------------------------------------------&lt;br /&gt;
TO_CHAR(FAIL_TIME,&amp;#039;D STATE MIX&lt;br /&gt;
-------------------- ---------------- ---&lt;br /&gt;
8.19.321913&lt;br /&gt;
1463898948.0000013CDE8005110000000179F68840A089FFFEE644B640AED6B02438B2F39D9665F&lt;br /&gt;
AFB&lt;br /&gt;
15-feb-2013 16:37:41 prepared no&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
SQL&amp;gt; SELECT LOCAL_TRAN_ID, IN_OUT,INTERFACE, DATABASE FROM DBA_2PC_NEIGHBORS;&lt;br /&gt;
&lt;br /&gt;
LOCAL_TRAN_ID IN_ I&lt;br /&gt;
---------------------- --- -&lt;br /&gt;
DATABASE&lt;br /&gt;
--------------------------------------------------------------------------------&lt;br /&gt;
8.19.321913 in N&lt;br /&gt;
jdbc_11&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
SQL&amp;gt; rollback force &amp;#039;8.19.321913&amp;#039;;&lt;br /&gt;
&lt;br /&gt;
Rollback complete.&lt;br /&gt;
&lt;br /&gt;
SQL&amp;gt; execute dbms_transaction.purge_lost_db_entry(&amp;#039;8.19.321913&amp;#039;);&lt;br /&gt;
&lt;br /&gt;
PL/SQL procedure successfully completed.&lt;br /&gt;
&lt;br /&gt;
SQL&amp;gt; commit;&lt;br /&gt;
&lt;br /&gt;
Commit complete.&lt;br /&gt;
&lt;br /&gt;
SQL&amp;gt; SELECT LOCAL_TRAN_ID, GLOBAL_TRAN_ID,to_char(FAIL_TIME,&amp;#039;dd-mon-yyyy HH24:MI:SS&amp;#039;),STATE, MIXED FROM DBA_2PC_PENDING;&lt;br /&gt;
&lt;br /&gt;
no rows selected&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Be aware that the support document 159377.1 does not speak of the rollback force. If you don’t execute that particular command it will not work.&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORACLE_BASE is getting set to the same value as ORACLE_HOME when using . oraenv===&lt;br /&gt;
Permissions problem. Make sure the user has &amp;#039;&amp;#039;&amp;#039;write&amp;#039;&amp;#039;&amp;#039; access to oraclehomeproperties.xml file!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ls -al $ORACLE_HOME/inventory/ContentsXML/oraclehomeproperties.xml&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Change permissions as appropriate.&lt;br /&gt;
A different approach which should give the same end result would be to grant the orabase executable the setuid bit.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
chmod u+s $ORACLE_HOME/bin/orabase&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This allows any user to set the environment as the orabase executable will be run with the permissions of its owner.&lt;br /&gt;
===Move table partitions to a different tablespace===&lt;br /&gt;
Are you getting errors due to partitions belonging to a different tablespace and you want to drop the current tablepace?&amp;lt;br /&amp;gt;&lt;br /&gt;
ORA-14404: partitioned table contains partitions in a different tablespace&amp;lt;br /&amp;gt;&lt;br /&gt;
====Find tables with partitions in more than one tablespace====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 2000 pages 50&lt;br /&gt;
col table_owner for a30&lt;br /&gt;
col table_name for a30&lt;br /&gt;
select table_owner&lt;br /&gt;
 ,     table_name&lt;br /&gt;
,      count(*)&lt;br /&gt;
from   dba_tab_partitions&lt;br /&gt;
where  table_owner != &amp;#039;SYS&amp;#039;&lt;br /&gt;
group  by table_owner&lt;br /&gt;
,      table_name&lt;br /&gt;
having count(*) &amp;gt; 1&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
See which tables have partitions across multiple tablespaces...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 1000 pages 100&lt;br /&gt;
col table_name for a50&lt;br /&gt;
select distinct b.table_owner||&amp;#039;.&amp;#039;||b.table_name table_name&lt;br /&gt;
,      a.tablespace_name ts1&lt;br /&gt;
,      b.tablespace_name ts2&lt;br /&gt;
from   (&lt;br /&gt;
       select distinct tablespace_name&lt;br /&gt;
       ,      table_name&lt;br /&gt;
       ,      partition_name&lt;br /&gt;
       from   dba_tab_partitions&lt;br /&gt;
       )                  a&lt;br /&gt;
,      dba_tab_partitions b&lt;br /&gt;
where  a.table_name       = b.table_name&lt;br /&gt;
and    a.tablespace_name != b.tablespace_name&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Generate statements to move the partitions from one tablespace to another...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select &amp;#039;alter table &amp;#039;||b.table_owner||&amp;#039;.&amp;#039;||b.table_name||&amp;#039; move partition &amp;#039;||b.partition_name||&amp;#039; tablespace &amp;amp;NEW_TABLESPACE;&amp;#039;&lt;br /&gt;
from   (&lt;br /&gt;
       select distinct table_name&lt;br /&gt;
       ,      partition_name&lt;br /&gt;
       from   dba_tab_partitions&lt;br /&gt;
       where  tablespace_name = &amp;#039;&amp;amp;&amp;amp;OLD_TABLESPACE&amp;#039;&lt;br /&gt;
       )                  a&lt;br /&gt;
,      dba_tab_partitions b&lt;br /&gt;
where  a.table_name       = b.table_name&lt;br /&gt;
and    b.tablespace_name != &amp;#039;&amp;amp;OLD_TABLESPACE&amp;#039;&lt;br /&gt;
/&lt;br /&gt;
undef OLD_TABLESPACE&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====What&amp;#039;s left hanging around?====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
col SEGMENT_TYPE for a20&lt;br /&gt;
col OWNER for a20&lt;br /&gt;
col SEGMENT_NAME for a40&lt;br /&gt;
col PARTITION_NAME for a15&lt;br /&gt;
col TABLESPACE_NAME for a30&lt;br /&gt;
select segment_type&lt;br /&gt;
,      owner&lt;br /&gt;
,      segment_name&lt;br /&gt;
,      partition_name&lt;br /&gt;
,      tablespace_name&lt;br /&gt;
from   dba_segments&lt;br /&gt;
where  tablespace_name in (&amp;#039;TS_THALER_IOT_OLD&amp;#039;,&amp;#039;TS_THALER_CU&amp;#039;,&amp;#039;TS_THALER_BACKUP&amp;#039;,&amp;#039;TS_THALER_PART_OLD&amp;#039;)&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
select table_owner&lt;br /&gt;
,      table_name&lt;br /&gt;
from   dba_indexes&lt;br /&gt;
where  index_name = &amp;#039;&amp;amp;index_name&amp;#039;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===What edition is my database (Standard, Enterprise, XE...)?===&lt;br /&gt;
Only works from 12c :-(&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select edition from sys.registry$ where cid=&amp;#039;CATPROC&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Is database a CDB with PDBs?===&lt;br /&gt;
Needs a bit of work. Won&amp;#039;t work pre-12c obviously and also not on Standby databases if they are in MOUNT mode&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
for db in $(ps -ef | grep [p]mon|awk -F_ &amp;#039;{print $NF}&amp;#039;)&lt;br /&gt;
do&lt;br /&gt;
    export ORACLE_SID=${db}&lt;br /&gt;
    ORAENV_ASK=NO&lt;br /&gt;
    . oraenv &amp;gt;/dev/null 2&amp;gt;&amp;amp;1&lt;br /&gt;
    sqlplus -s / as sysdba&amp;lt;&amp;lt;&amp;#039;EOSQL&amp;#039;&lt;br /&gt;
set head off newpa none&lt;br /&gt;
select name&lt;br /&gt;
,      (select count(*) from v$pdbs) npdbs&lt;br /&gt;
from   v$database&lt;br /&gt;
/&lt;br /&gt;
EOSQL&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
version 2&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
function is_db_cdb return boolean&lt;br /&gt;
is&lt;br /&gt;
    b_is_cdb        boolean := false;&lt;br /&gt;
    l_is_cdb        varchar2(3) := &amp;#039;NO&amp;#039;;&lt;br /&gt;
    e_col_not_found exception;&lt;br /&gt;
    pragma          exception_init(e_col_not_found, -904);&lt;br /&gt;
begin&lt;br /&gt;
    begin&lt;br /&gt;
        execute immediate &amp;#039;select cdb from v$database&amp;#039; &lt;br /&gt;
        into l_is_cdb;&lt;br /&gt;
    exception&lt;br /&gt;
        when e_col_not_found then l_is_cdb := &amp;#039;NO&amp;#039;;  -- ORA-00904&lt;br /&gt;
    end;&lt;br /&gt;
&lt;br /&gt;
    if (l_is_cdb = &amp;#039;YES&amp;#039;) then&lt;br /&gt;
        return TRUE;&lt;br /&gt;
    else&lt;br /&gt;
        return FALSE;  -- either not a cdb or pre-12.1 database&lt;br /&gt;
    end if;&lt;br /&gt;
&lt;br /&gt;
end is_db_cdb;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===List triggers in the database===&lt;br /&gt;
This query specifically lists after login triggers &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select obj.con_id&lt;br /&gt;
,      pdb.name&lt;br /&gt;
,      obj.owner&lt;br /&gt;
,      obj.object_name&lt;br /&gt;
,      to_char(obj.created, &amp;#039;DD/MM/YYYY HH24:MI:SS&amp;#039;)       created_str&lt;br /&gt;
,      to_char(obj.last_ddl_time, &amp;#039;DD/MM/YYYY HH24:MI:SS&amp;#039;) last_ddl_str&lt;br /&gt;
from   cdb_objects   obj&lt;br /&gt;
join   cdb_triggers trgs&lt;br /&gt;
       on (   obj.con_id      = trgs.con_id&lt;br /&gt;
          and obj.owner       = trgs.owner&lt;br /&gt;
          and obj.object_name = trgs.trigger_name&lt;br /&gt;
          )&lt;br /&gt;
join   v$pdbs pdb&lt;br /&gt;
       on ( obj.con_id  = pdb.con_id )&lt;br /&gt;
where  trgs.trigger_type     = &amp;#039;AFTER EVENT&amp;#039;&lt;br /&gt;
and    trgs.triggering_event like &amp;#039;LOGON%&amp;#039;&lt;br /&gt;
and    trgs.status           = &amp;#039;ENABLED&amp;#039;&lt;br /&gt;
order  by object_name&lt;br /&gt;
,      obj.last_ddl_time&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===List the pluggable databases (PDB) in a container database (CDB)===&lt;br /&gt;
The network_name column shows what you should find in tnsnames.ora for this db connection&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select name,network_name,pdb from v$services;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select * from v$pdbs;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Start and stop a pluggable database===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter pluggable database pdb1 open;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter pluggable database pdb1 close immediate;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Swith to a pluggable database===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter session set container=pdb1;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Reopen pluggable databases at container startup===&lt;br /&gt;
By default pluggable databases in a container remain in a MOUNT state when the container starts up.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select name, open_mode from v$pdbs where name = &amp;#039;PDB1&amp;#039;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
To modify this, open it and save its state&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter pluggable database pdb1 open;&lt;br /&gt;
alter pluggable database pdb1 save state;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
To see a log of issues with pluggable databases&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select * from pdb_plug_in_violations where type = &amp;#039;ERROR&amp;#039; and status != &amp;#039;RESOLVED&amp;#039; and name = &amp;#039;PDB1&amp;#039;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===What is the current container id in a cdb?===&lt;br /&gt;
CDB$ROOT is container id 1. User containers start from 2.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select sys_context(&amp;#039;USERENV&amp;#039;,&amp;#039;CON_ID&amp;#039;) from dual&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===What is the current container name in a cdb?===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select sys_context(&amp;#039;USERENV&amp;#039;,&amp;#039;CON_NAME&amp;#039;) from dual&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or just&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
show con_name&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Switching Between Containers===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SQL&amp;gt; show con_name&lt;br /&gt;
&lt;br /&gt;
CON_NAME&lt;br /&gt;
------------------------------&lt;br /&gt;
CDB$ROOT&lt;br /&gt;
&lt;br /&gt;
SQL&amp;gt; alter session set container=tstklok;&lt;br /&gt;
&lt;br /&gt;
Session altered.&lt;br /&gt;
&lt;br /&gt;
SQL&amp;gt;  show con_name&lt;br /&gt;
&lt;br /&gt;
CON_NAME&lt;br /&gt;
------------------------------&lt;br /&gt;
TSTKLOK&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Direct connection to pluggable database===&lt;br /&gt;
These must be made using a service (defined in tnsnames.ora). Each pluggable database automatically registers a service with the listener (v$services).&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sqlplus appuser/apppwd@tstklok&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or using ezconnect&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SQL&amp;gt; conn appuser/apppwd@//localhost:1521/tstklok&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===What platform is the database running on?===&lt;br /&gt;
Could be useful for handling line endings...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select platform_name from v$database&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
if instr(db_platform, &amp;#039;WINDOWS&amp;#039;) != 0 then&lt;br /&gt;
    crlf := CHR(13) || CHR(10);       -- Windows gets the \r and \n&lt;br /&gt;
else&lt;br /&gt;
    crlf := CHR (10);                 -- Just \n for the rest of the world&lt;br /&gt;
end if;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Is the database 32 or 64 bit?===&lt;br /&gt;
If the answer is 1,7,10,15,16 or 17, then it is 32bit, everything else should be 64bit.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select platform_id from v$database&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===What features is my database using?===&lt;br /&gt;
Before converting to Standard Edition, check the features here - some may be Enterprise specific.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
col name for a45&lt;br /&gt;
col description for a85&lt;br /&gt;
set lines 2000&lt;br /&gt;
select name&lt;br /&gt;
,      detected_usages&lt;br /&gt;
,      description&lt;br /&gt;
from   dba_feature_usage_statistics&lt;br /&gt;
where  1=1&lt;br /&gt;
and    currently_used = &amp;#039;TRUE&amp;#039;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===How many redo log switches per hour?===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 100&lt;br /&gt;
col &amp;quot;YYYYMMDD HH24&amp;quot; for a14&lt;br /&gt;
select to_char(first_time,&amp;#039;yyyymmdd hh24&amp;#039;) &amp;quot;YYYYMMDD HH24&amp;quot;&lt;br /&gt;
,      count(1)                            num_switches&lt;br /&gt;
from   v$log_history&lt;br /&gt;
group  by to_char(first_time,&amp;#039;yyyymmdd hh24&amp;#039;)&lt;br /&gt;
order  by 1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or a bit fancier version...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rem *********************************************************** &lt;br /&gt;
rem&lt;br /&gt;
rem	File: log_history.sql &lt;br /&gt;
rem	Description: Log switch rates from v$log_history &lt;br /&gt;
rem   &lt;br /&gt;
rem	From &amp;#039;Oracle Performance Survival Guide&amp;#039; by Guy Harrison&lt;br /&gt;
rem		Chapter 21 Page 637&lt;br /&gt;
rem		ISBN: 978-0137011957&lt;br /&gt;
rem		See www.guyharrison.net for further information&lt;br /&gt;
rem  &lt;br /&gt;
rem		This work is in the public domain NSA &lt;br /&gt;
rem   &lt;br /&gt;
rem&lt;br /&gt;
rem ********************************************************* &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
col min_minutes format 9999.99 &lt;br /&gt;
col max_minutes format 9999.99 &lt;br /&gt;
col avg_minutes format 9999.99 &lt;br /&gt;
set pagesize 1000&lt;br /&gt;
set lines 70&lt;br /&gt;
set echo on &lt;br /&gt;
&lt;br /&gt;
WITH log_history AS&lt;br /&gt;
       (SELECT thread#, first_time,&lt;br /&gt;
               LAG(first_time) OVER (ORDER BY thread#, sequence#)&lt;br /&gt;
                  last_first_time,&lt;br /&gt;
               (first_time&lt;br /&gt;
                - LAG(first_time) OVER (ORDER BY thread#, sequence#))&lt;br /&gt;
                    * 24* 60   last_log_time_minutes,&lt;br /&gt;
               LAG(thread#) OVER (ORDER BY thread#, sequence#)&lt;br /&gt;
                   last_thread#&lt;br /&gt;
        FROM v$log_history)&lt;br /&gt;
SELECT ROUND(MIN(last_log_time_minutes), 2) min_minutes,&lt;br /&gt;
       ROUND(MAX(last_log_time_minutes), 2) max_minutes,&lt;br /&gt;
       ROUND(AVG(last_log_time_minutes), 2) avg_minutes&lt;br /&gt;
FROM log_history&lt;br /&gt;
WHERE     last_first_time IS NOT NULL&lt;br /&gt;
      AND last_thread# = thread#&lt;br /&gt;
      AND first_time &amp;gt; SYSDATE - 1; &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Show redo log groups/members===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
col instance       for a8&lt;br /&gt;
col thread         for 999&lt;br /&gt;
col groupno        for 999&lt;br /&gt;
col member         for a35&lt;br /&gt;
col redo_file_type for a15&lt;br /&gt;
col log_status     for a10&lt;br /&gt;
col logsize_m      for 99999&lt;br /&gt;
col archived       for a12&lt;br /&gt;
&lt;br /&gt;
SELECT i.instance_name   instance&lt;br /&gt;
,      i.thread#         thread&lt;br /&gt;
,      f.group#          groupno&lt;br /&gt;
,      f.member          member&lt;br /&gt;
,      f.type            redo_file_type&lt;br /&gt;
,      l.status          log_status&lt;br /&gt;
,      l.bytes/1024/1024 logsize_m&lt;br /&gt;
,      l.archived        archived&lt;br /&gt;
FROM   gv$logfile  f&lt;br /&gt;
,      gv$log      l&lt;br /&gt;
,      gv$instance i&lt;br /&gt;
WHERE  1=1&lt;br /&gt;
and    f.group#  = l.group#&lt;br /&gt;
AND    l.thread# = i.thread#&lt;br /&gt;
AND    i.inst_id = f.inst_id&lt;br /&gt;
AND    f.inst_id = l.inst_id&lt;br /&gt;
ORDER  BY i.instance_name&lt;br /&gt;
,      f.group#&lt;br /&gt;
,      f.member;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Korn shell timestamp function===&lt;br /&gt;
Example usage: echo &amp;quot;`ts`: Checking backup status&amp;quot;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
function ts {&lt;br /&gt;
    date +&amp;#039;%d-%b-%Y %H:%M:%S&amp;#039;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Drop a database===&lt;br /&gt;
Dropping a database including backups should be considered criminal in a production environment!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sqlplus / as sysdba&lt;br /&gt;
startup force mount exclusive restrict&lt;br /&gt;
exit&lt;br /&gt;
rman target /&lt;br /&gt;
drop database including backups noprompt;&lt;br /&gt;
exit&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
RMAN&amp;gt; connect target sys/pass@test&lt;br /&gt;
connected to target database: test (dbid=123456789)&lt;br /&gt;
&lt;br /&gt;
RMAN&amp;gt; startup force mount&lt;br /&gt;
RMAN&amp;gt; sql &amp;#039;alter system enable restricted session&amp;#039;;&lt;br /&gt;
RMAN&amp;gt; drop database including backups noprompt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Use sub-select or in-line views to update base tables===&lt;br /&gt;
Inline views can be used to update base table data&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
update&lt;br /&gt;
    (&lt;br /&gt;
    select p.list_price&lt;br /&gt;
    from   products           p&lt;br /&gt;
    ,      product_categories pc&lt;br /&gt;
    where  1=1&lt;br /&gt;
    and    p.category_id    = pc.category_id&lt;br /&gt;
    and    pc.category_name = &amp;#039;CPU&amp;#039;&lt;br /&gt;
    )&lt;br /&gt;
set list_price = list_price * 1.15; &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Use sub-select or in-line views to delete base table data===&lt;br /&gt;
A different way to delete rows in base tables, using Inline views or subselect&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
delete&lt;br /&gt;
    (&lt;br /&gt;
    select p.list_price&lt;br /&gt;
    from   products           p&lt;br /&gt;
    ,      product_categories pc&lt;br /&gt;
    where  1=1&lt;br /&gt;
    and    p.category_id    = pc.category_id&lt;br /&gt;
    and    pc.category_name = &amp;#039;CPU&amp;#039;&lt;br /&gt;
    )&lt;br /&gt;
where list_price &amp;lt; 1000; &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Mass update of files using perl inline script===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
for server in `cat /home/tools/etc/oracle/oracle_servers`; do&lt;br /&gt;
    ssh $server “perl -p -i -e &amp;#039;s/T01/D01/&amp;#039; /home/tools/scripts/rman/inclexcl.lst”&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===How to use vi-style editing in SQL*Plus===&lt;br /&gt;
These instructions are for Redhat but other versions will be very similar&lt;br /&gt;
* Download rlwrap from [http://dl.fedoraproject.org/pub/epel/5/x86_64/repoview/rlwrap.html] or [http://dl.fedoraproject.org/pub/epel/6/x86_64/repoview/rlwrap.html]&lt;br /&gt;
* sudo yum install rlwrap&lt;br /&gt;
* build a dictionary file for autocomplete on pressing Tab&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
vi $HOME/sql.dict&lt;br /&gt;
select&lt;br /&gt;
from&lt;br /&gt;
dba_users&lt;br /&gt;
dba_data_files&lt;br /&gt;
dba_tablespaces&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alias sysdba=&amp;#039;rlwrap -f $HOME/sql.dict sqlplus / as sysdba&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or for general command use...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alias sqlplus=&amp;#039;rlwrap -D2 -ic sqlplus&amp;#039;&lt;br /&gt;
alias dgmgrl=&amp;#039;rlwrap -D2 -ic dgmgrl&amp;#039;&lt;br /&gt;
alias rman=&amp;#039;rlwrap -D2 -ic rman&amp;#039;&lt;br /&gt;
alias asmcmd=&amp;#039;rlwrap -D2 -ic asmcmd&amp;#039;&lt;br /&gt;
alias lsnrctl=&amp;#039;rlwrap -D2 -ic lsnrctl&amp;#039;&lt;br /&gt;
alias adrci=&amp;#039;rlwrap -D2 -ic adrci&amp;#039;&lt;br /&gt;
alias impdp=&amp;#039;rlwrap -D2 -ic impdp&amp;#039;&lt;br /&gt;
alias expdp=&amp;#039;rlwrap -D2 -ic expdp&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Execute an SQL statement on all databases on all servers for a customer===&lt;br /&gt;
Run from customer&amp;#039;s management server&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
./dosh -c &amp;quot;su - oracle -c &amp;#039;/home/tools/scripts/oracle/all_db_do -v \&amp;quot;select username, account_status, profile from dba_users order by 3;\&amp;quot;&amp;#039;&amp;quot; &amp;gt;user_status.lst&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SCRIPTS_DIR=/home/tools/scripts/oracle&lt;br /&gt;
$SCRIPTS_DIR/dosh -c &amp;quot;su - oraibm -c \&amp;quot;$SCRIPTS_DIR/all_db_do &amp;#039;alter user ops\\\$oraibm profile oracle_system_user;&amp;#039;\&amp;quot;&amp;quot;&lt;br /&gt;
$SCRIPTS_DIR/dosh2 -c &amp;quot;su - oraibm -c \&amp;quot;$SCRIPTS_DIR/all_db_do &amp;#039;alter user ops$oraibm profile oracle_system_user;&amp;#039;\&amp;quot;&amp;quot;&lt;br /&gt;
$SCRIPTS_DIR/dosh2 -c &amp;quot;su - oraibm -c \&amp;quot;$SCRIPTS_DIR/all_db_do &amp;#039;alter system set control_file_record_keep_time=31;&amp;#039;\&amp;quot;&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Where is the alert log/alertlog?===&lt;br /&gt;
Older systems&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select value from v$parameter where name=&amp;#039;background_dump_dest&amp;#039;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Newer systems&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select value from v$diag_info where name=&amp;#039;Diag Trace&amp;#039;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Grant normal users access to the alertlog table (sys.x$dbgalertext)===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
create view x$dbgalertext_v as select * from x$dbgalertext;&lt;br /&gt;
grant select on x$dbgalertext_v to &amp;amp;&amp;amp;grantee;&lt;br /&gt;
create or replace synonym &amp;amp;grantee..x$dbgalertext for sys.x$dbgalertext_v;&lt;br /&gt;
undef grantee&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Search alert log for ORA-00600 and ORA-07445 errors===&lt;br /&gt;
Scan the database table version of the alertlog for errors without reporting what was already found.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select indx, message_text from x$dbgalertext where message_text like &amp;#039;%ORA-00600%&amp;#039; or message_text like &amp;#039;%ORA-07445%&amp;#039; and indx &amp;gt; &amp;amp;last_queried_indx order by indx desc;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===tail the database alert log===&lt;br /&gt;
If an ADR error is displayed, then ORACLE_SID is probably not set&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alias alertlog=&amp;#039;adrci exec=&amp;quot;set home diag/rdbms/$(echo $ORACLE_SID | tr A-Z a-z)/$ORACLE_SID; show alert -tail -f&amp;quot;&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===What is my WAN ip address?===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
curl -A &amp;quot;Mozilla/4.0&amp;quot; http://checkip.dyndns.org/ 2&amp;gt;/dev/null | perl -ne &amp;#039;print $1 if /Current IP Address: (\d+\.\d+\.\d+\.\d+)/&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
curl -A &amp;quot;Mozilla/4.0&amp;quot; http://myip.dnsdynamic.org/ 2&amp;gt;/dev/null&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Wait for child pid to finish in background and report its status===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# submit a process to the background&lt;br /&gt;
export_schema1.ksh &amp;amp;&lt;br /&gt;
bgpid=$!&lt;br /&gt;
&lt;br /&gt;
while (ps -ef | grep $bgpid | grep -v grep); do&lt;br /&gt;
    # still running...&lt;br /&gt;
    sleep 600&lt;br /&gt;
done&lt;br /&gt;
&lt;br /&gt;
# should be finished&lt;br /&gt;
wait $bgpid&lt;br /&gt;
bgstatus=$?&lt;br /&gt;
echo background process ended with status $bgstatus&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/usr/bin/ksh&lt;br /&gt;
# submit a few processes to the background&lt;br /&gt;
# wait for them all to finish&lt;br /&gt;
# concat their logfiles&lt;br /&gt;
&lt;br /&gt;
(./sleeper.sh;echo &amp;quot;sleeper 1 finished&amp;quot;)&amp;gt;sleeper1.log &amp;amp;&lt;br /&gt;
PIDLIST=&amp;quot;$PIDLIST $!&amp;quot;&lt;br /&gt;
echo &amp;quot;PIDLIST is $PIDLIST ...&amp;quot;&lt;br /&gt;
sleep 5&lt;br /&gt;
&lt;br /&gt;
(./sleeper.sh;echo &amp;quot;sleeper 2 finished&amp;quot;)&amp;gt;sleeper2.log &amp;amp;&lt;br /&gt;
PIDLIST=&amp;quot;$PIDLIST $!&amp;quot;&lt;br /&gt;
echo &amp;quot;PIDLIST is $PIDLIST ...&amp;quot;&lt;br /&gt;
sleep 5&lt;br /&gt;
&lt;br /&gt;
(./sleeper.sh;echo &amp;quot;sleeper 3 finished&amp;quot;)&amp;gt;sleeper3.log &amp;amp;&lt;br /&gt;
PIDLIST=&amp;quot;$PIDLIST $!&amp;quot;&lt;br /&gt;
echo &amp;quot;PIDLIST is $PIDLIST ...&amp;quot;&lt;br /&gt;
sleep 5&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;Now 15 seconds later, we have 3 pids: $PIDLIST&amp;quot;&lt;br /&gt;
for PID in $PIDLIST; do&lt;br /&gt;
    wait $PID&lt;br /&gt;
    echo &amp;quot;$PID exited with status $?&amp;quot;&lt;br /&gt;
done&lt;br /&gt;
&lt;br /&gt;
# all jobs should have ended, concat their logs&lt;br /&gt;
cat sleeper*log &amp;gt; sleepers.log&lt;br /&gt;
cat sleepers.log&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Real world example&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/usr/bin/ksh&lt;br /&gt;
# ==============================================================================&lt;br /&gt;
# Name         : export_JDBEOP1.ksh&lt;br /&gt;
# Description  : Run export in pieces for performance reasons&lt;br /&gt;
#&lt;br /&gt;
# Parameters   : &lt;br /&gt;
#&lt;br /&gt;
# Notes        : Also decide whether to exclude PDARC schema or not&lt;br /&gt;
#                depending on what day it is&lt;br /&gt;
#&lt;br /&gt;
#&lt;br /&gt;
# Modification History&lt;br /&gt;
# ====================&lt;br /&gt;
# When      Who               What&lt;br /&gt;
# ========= ================= ==================================================&lt;br /&gt;
# 15-OCT-13 Stuart Barkley    Created&lt;br /&gt;
# ==============================================================================&lt;br /&gt;
&lt;br /&gt;
STARTTIME=`date &amp;#039;+%Y%m%d%H%M%S&amp;#039;`&lt;br /&gt;
DAYNO=`date +%u`&lt;br /&gt;
PROGNAME=`basename $0`&lt;br /&gt;
SCRIPTS_DIR=/home/tools/scripts/oracle&lt;br /&gt;
DATA_DIR=/oracle/JDBEOP1/admin/change&lt;br /&gt;
EXPORT_DIR=/oracle/export/JDBEOP1&lt;br /&gt;
&lt;br /&gt;
# marker so we can find our files later&lt;br /&gt;
MARKERFILE=/tmp/start_$PROGNAME_$$&lt;br /&gt;
touch $MARKERFILE&lt;br /&gt;
&lt;br /&gt;
$SCRIPTS_DIR/expdp_PARFILE.ksh -s JDBEOP1 -u PRODDTA -p 4 -k 2 -f $DATA_DIR/JDBEOP1_PRODDTA.parfile &amp;amp;&lt;br /&gt;
PIDLIST=&amp;quot;$PIDLIST $!&amp;quot;&lt;br /&gt;
echo &amp;quot;PIDLIST is $PIDLIST ...&amp;quot;&lt;br /&gt;
&lt;br /&gt;
$SCRIPTS_DIR/expdp_PARFILE.ksh -s JDBEOP1 -u PRODCTL -p 2 -k 2 -f $DATA_DIR/JDBEOP1_PRODCTL.parfile &amp;amp;&lt;br /&gt;
PIDLIST=&amp;quot;$PIDLIST $!&amp;quot;&lt;br /&gt;
echo &amp;quot;PIDLIST is $PIDLIST ...&amp;quot;&lt;br /&gt;
&lt;br /&gt;
$SCRIPTS_DIR/expdp_PARFILE.ksh -s JDBEOP1 -u NOPRODNOPDARC -p 4 -k 2 -f $DATA_DIR/JDBEOP1_NOPROD_NOPDARC.parfile &amp;amp;&lt;br /&gt;
PIDLIST=&amp;quot;$PIDLIST $!&amp;quot;&lt;br /&gt;
echo &amp;quot;PIDLIST is $PIDLIST ...&amp;quot;&lt;br /&gt;
&lt;br /&gt;
if [[ $DAYNO -eq 1 ]]; then&lt;br /&gt;
    $SCRIPTS_DIR/expdp_PARFILE.ksh -s JDBEOP1 -u NOPROD -p 4 -k 2 -f $DATA_DIR/JDBEOP1_NOPROD.parfile &amp;amp;&lt;br /&gt;
    PIDLIST=&amp;quot;$PIDLIST $!&amp;quot;&lt;br /&gt;
    echo &amp;quot;PIDLIST is $PIDLIST ...&amp;quot;&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
# now sit and wait for the exports to finish&lt;br /&gt;
for PID in $PIDLIST; do&lt;br /&gt;
    echo &amp;quot;waiting for pid $PID to finish&amp;quot;&lt;br /&gt;
    wait $PID&lt;br /&gt;
    echo &amp;quot;$PID exited with status $?&amp;quot;&lt;br /&gt;
done&lt;br /&gt;
&lt;br /&gt;
# collect all log files up into one&lt;br /&gt;
cd $EXPORT_DIR&lt;br /&gt;
for i in `find . -name &amp;quot;expdp_JDBEOP1*log&amp;quot; -newer $MARKERFILE`; do&lt;br /&gt;
    cat $i &amp;gt; expdp_JDBEOP1_D_FULL_${STARTTIME}.log&lt;br /&gt;
done&lt;br /&gt;
&lt;br /&gt;
rm $MARKLERFILE&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Create private DB link for a user without knowing his password===&lt;br /&gt;
* Inspired by [http://oradbatips.blogspot.co.uk/2010/01/tip-84-create-private-db-link-for-user.html oradbatips.blogspot.co.uk]&lt;br /&gt;
It uses a clever package, dbms_sys_sql.&amp;lt;br /&amp;gt;&lt;br /&gt;
Also useful for executing anything on behalf of another user.&amp;lt;br /&amp;gt;&lt;br /&gt;
Here is an example on how to create private database link for a user.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
create or replace procedure link_creator ( p_owner varchar2, p_dblink_name varchar2, p_username varchar2, p_password varchar2, p_address varchar2 ) as&lt;br /&gt;
    uid number;&lt;br /&gt;
    sqltext varchar2(1000) := &amp;#039;create [public] database link [link_name] connect to [username] identified by [password] using &amp;#039;&amp;#039;[address]&amp;#039;&amp;#039;&amp;#039;;&lt;br /&gt;
    myint integer;&lt;br /&gt;
begin&lt;br /&gt;
    if upper(p_owner) = &amp;#039;PUBLIC&amp;#039; then&lt;br /&gt;
        sqltext := replace(sqltext, &amp;#039;[public]&amp;#039;, &amp;#039;public&amp;#039;);&lt;br /&gt;
    else&lt;br /&gt;
        sqltext := replace(sqltext, &amp;#039;[public]&amp;#039;, &amp;#039;&amp;#039;);&lt;br /&gt;
    end if;&lt;br /&gt;
    sqltext := replace(sqltext, &amp;#039;[linkname]&amp;#039;, p_dblink_name);&lt;br /&gt;
    sqltext := replace(sqltext, &amp;#039;[username]&amp;#039;, p_username);&lt;br /&gt;
    sqltext := replace(sqltext, &amp;#039;[password]&amp;#039;, p_password);&lt;br /&gt;
    sqltext := replace(sqltext, &amp;#039;[address]&amp;#039;, p_address);&lt;br /&gt;
&lt;br /&gt;
    select user_id&lt;br /&gt;
    into   uid&lt;br /&gt;
    from   dba_users&lt;br /&gt;
    where  username = decode(upper(p_owner), &amp;#039;PUBLIC&amp;#039;, &amp;#039;SYS&amp;#039;, p_owner)&lt;br /&gt;
    ;&lt;br /&gt;
    myint:=sys.dbms_sys_sql.open_cursor();&lt;br /&gt;
    sys.dbms_sys_sql.parse_as_user ( myint, sqltext, dbms_sql.native, uid );&lt;br /&gt;
    sys.dbms_sys_sql.close_cursor(myint);&lt;br /&gt;
end;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Here we can generate SQL to rebuild the links for future use. Note the password is no longer stored in this column.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set pages 1000&lt;br /&gt;
select &amp;#039;begin link_creator ( &amp;#039;&amp;#039;&amp;#039;|| u.name ||&amp;#039;&amp;#039;&amp;#039;,&amp;#039;&amp;#039;&amp;#039;|| l.name ||&amp;#039;&amp;#039;&amp;#039;,&amp;#039;&amp;#039;&amp;#039;|| l.userid ||&amp;#039;&amp;#039;&amp;#039;,&amp;#039;&amp;#039;&amp;#039;|| l.password ||&amp;#039;&amp;#039;&amp;#039;,&amp;#039;&amp;#039;&amp;#039;|| l.host ||&amp;#039;&amp;#039;&amp;#039;); end;&amp;#039;|| chr(10) ||&amp;#039;/&amp;#039; link_text&lt;br /&gt;
from   sys.link$ l&lt;br /&gt;
,      sys.user$ u&lt;br /&gt;
where  l.owner# = u.user#&lt;br /&gt;
;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Another method to create a db_link from sys on behalf of a user is to create a procedure under that users name that does the db link creation====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
grant create database link to &amp;amp;&amp;amp;user;&lt;br /&gt;
&lt;br /&gt;
create or replace procedure &amp;amp;user..create_db_link as&lt;br /&gt;
begin&lt;br /&gt;
    execute immediate &amp;#039;create database link &amp;amp;link_name connect to &amp;amp;user identified by &amp;amp;users_password using &amp;#039;&amp;#039;&amp;amp;tns_connect_identifier&amp;#039;&amp;#039;&amp;#039;;&lt;br /&gt;
end create_db_link;&lt;br /&gt;
&lt;br /&gt;
exec &amp;amp;user..create_db_link;&lt;br /&gt;
&lt;br /&gt;
revoke create database link from &amp;amp;user;&lt;br /&gt;
&lt;br /&gt;
drop procedure &amp;amp;user..create_db_link;&lt;br /&gt;
undef user&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Create a comma separated list of columns from a select statement===&lt;br /&gt;
Method 1:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SELECT parent_id,&lt;br /&gt;
       RTRIM(XMLAGG(XMLELEMENT(e,child_id || &amp;#039;,&amp;#039;)).EXTRACT(&amp;#039;//text()&amp;#039;),&amp;#039;,&amp;#039;) AS &amp;quot;Children&amp;quot;&lt;br /&gt;
FROM   parentChildTable&lt;br /&gt;
WHERE  parent_id = 0&lt;br /&gt;
GROUP  BY parent_id&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SELECT parent_id,&lt;br /&gt;
       LISTAGG(child_id, &amp;#039;,&amp;#039;) WITHIN GROUP (ORDER BY child_id) AS &amp;quot;Children&amp;quot;&lt;br /&gt;
  FROM parentChildTable&lt;br /&gt;
 WHERE parent_id = 0&lt;br /&gt;
 GROUP BY parent_id&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Method 2 (undocumented and cannot therefore be relied on to continue working in the same manner):&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SELECT wmsys.wm_concat(&amp;lt;column_name&amp;gt;)&lt;br /&gt;
FROM &amp;lt;table_name&amp;gt;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Start an instant one-line webserver in current directory===&lt;br /&gt;
Need to quickly share/copy a file or read an html file on Linux? Start a web server!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
python -m SimpleHTTPServer 8000&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
and point your browser to http://localhost:8000&amp;lt;br /&amp;gt;&lt;br /&gt;
or&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
while true; do nc -l -p 80 -q 1 &amp;lt; index.html; done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Get SQL*Plus to generate HTML===&lt;br /&gt;
* [http://docs.oracle.com/cd/E11882_01/server.112/e16604/ch_seven.htm#CHDCECJG official guide]&lt;br /&gt;
One way to do it... use -m(arkup) option to specify:&amp;lt;br /&amp;gt;&lt;br /&gt;
html on/off - specifies whether to output html output or not&lt;br /&gt;
head - specify your own customised head contents&amp;lt;br /&amp;gt;&lt;br /&gt;
spool off - as a part of the -m tag means do not print the default &amp;amp;lt;html&amp;amp;gt;, &amp;amp;lt;head&amp;amp;gt; and &amp;amp;lt;body&amp;amp;gt; tags&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sqlplus -m &amp;quot;html on head &amp;#039;&amp;lt;link rel=&amp;quot;stylesheet&amp;quot; href=&amp;quot;/dbamon_golden.css&amp;quot; type=&amp;quot;text/css&amp;quot; /&amp;gt;&amp;#039; spool off&amp;quot; / as sysdba&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sqlplus / as sysdba&lt;br /&gt;
set markup html on head &amp;#039;&amp;lt;link rel=&amp;quot;stylesheet&amp;quot; href=&amp;quot;/dbamon_golden.css&amp;quot; type=&amp;quot;text/css&amp;quot; /&amp;gt;&amp;#039; body &amp;quot;&amp;quot; table &amp;quot;&amp;quot; spool off&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
besides html and head, you can also specify:&amp;lt;br /&amp;gt;&lt;br /&gt;
body - specify your own customised body attributes&amp;lt;br /&amp;gt;&lt;br /&gt;
table - override the default table options&amp;lt;br /&amp;gt;&lt;br /&gt;
entmap - turn on or off the html replacement characters (&amp;amp;lt, &amp;amp;gt, etc...)&amp;lt;br /&amp;gt;&lt;br /&gt;
preformat - uses the &amp;amp;lt;pre&amp;amp;gt; tag to format output exactly as required&amp;lt;br /&amp;gt;&lt;br /&gt;
* another little gem...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
----------------------------------------&lt;br /&gt;
-- get the last SQL*Plus output in HTML&lt;br /&gt;
-- after Tanel Poder&lt;br /&gt;
----------------------------------------&lt;br /&gt;
&lt;br /&gt;
set termout off&lt;br /&gt;
&lt;br /&gt;
set markup HTML ON HEAD &amp;quot; -&lt;br /&gt;
 -&lt;br /&gt;
&amp;quot; -&lt;br /&gt;
BODY &amp;quot;&amp;quot; -&lt;br /&gt;
TABLE &amp;quot;border=&amp;#039;1&amp;#039; align=&amp;#039;center&amp;#039; summary=&amp;#039;Script output&amp;#039;&amp;quot; -&lt;br /&gt;
SPOOL ON ENTMAP ON PREFORMAT OFF&lt;br /&gt;
&lt;br /&gt;
spool myoutput.html&lt;br /&gt;
&lt;br /&gt;
l&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
spool off&lt;br /&gt;
set markup html off spool off&lt;br /&gt;
host firefox myoutput.html&lt;br /&gt;
set termout on&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===HTML SELECT - Trigger JavaScript ONCHANGE event even when the option is not changed===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;select onchange=&amp;quot;jsFunction()&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;option value=&amp;quot;&amp;quot; disabled selected style=&amp;quot;display:none;&amp;quot;&amp;gt;Label&amp;lt;/option&amp;gt;&lt;br /&gt;
  &amp;lt;option value=&amp;quot;1&amp;quot;&amp;gt;1&amp;lt;/option&amp;gt;&lt;br /&gt;
  &amp;lt;option value=&amp;quot;2&amp;quot;&amp;gt;2&amp;lt;/option&amp;gt;&lt;br /&gt;
  &amp;lt;option value=&amp;quot;3&amp;quot;&amp;gt;3&amp;lt;/option&amp;gt;&lt;br /&gt;
&amp;lt;/select&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Display horizontal bar graph in HTML table data cell===&lt;br /&gt;
Using Perl&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
print (&amp;#039;&amp;lt;td class=&amp;quot;left&amp;quot;&amp;gt;&amp;#039; .&lt;br /&gt;
            &amp;#039;&amp;lt;div style=&amp;quot;background-color:#8097BE;width:&amp;quot;&amp;#039;,$allocpercused  ,&amp;#039;%;&amp;quot; /&amp;gt;&amp;#039; .&lt;br /&gt;
            &amp;#039;&amp;lt;div style=&amp;quot;background-color:red;    width:&amp;quot;&amp;#039;,$automaxpercused,&amp;#039;%;&amp;quot; /&amp;gt;&amp;#039; .&lt;br /&gt;
            $tspace .&lt;br /&gt;
       &amp;#039;&amp;lt;/td&amp;gt;&amp;#039;&lt;br /&gt;
);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Depending on which way around the divs are, you get different interpretations&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
print (&amp;quot;&amp;lt;td class=\&amp;quot;left\&amp;quot;&amp;gt;&amp;quot; .&lt;br /&gt;
            &amp;quot;&amp;lt;div style=\&amp;quot;border-right:2px solid red; width:&amp;quot;,($automaxpercused&amp;gt;99)?(100):($automaxpercused),&amp;quot;%;\&amp;quot; /&amp;gt;&amp;quot; .&lt;br /&gt;
            &amp;quot;&amp;lt;div style=\&amp;quot;background-color:#8097BE;width:&amp;quot;,$allocpercused  ,&amp;quot;%;\&amp;quot; /&amp;gt;&amp;quot; .&lt;br /&gt;
            $tspace .&lt;br /&gt;
       &amp;quot;&amp;lt;/td&amp;gt;&amp;quot;&lt;br /&gt;
);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====References====&lt;br /&gt;
* [http://stackoverflow.com/questions/5324996/comma-separated-list-as-a-result-of-select-statement-in-oracle stackoverflow.com]&lt;br /&gt;
* [http://www.salvis.com/blog/?p=207 A whole page showing how to do it in all versions back to 7!]&lt;/div&gt;</summary>
		<author><name>Stuart</name></author>	</entry>

	<entry>
		<id>https://mailnest.com/dbawiki/index.php?title=Oracle_errors&amp;diff=3364</id>
		<title>Oracle errors</title>
		<link rel="alternate" type="text/html" href="https://mailnest.com/dbawiki/index.php?title=Oracle_errors&amp;diff=3364"/>
				<updated>2018-11-03T17:33:38Z</updated>
		
		<summary type="html">&lt;p&gt;Stuart: /* ORA-14097: column type or size mismatch in ALTER TABLE EXCHANGE PARTITION */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;===ORA-00600===&lt;br /&gt;
[https://support.oracle.com/epmos/faces/DocContentDisplay?_afrLoop=397490397952859&amp;amp;id=1092832.1&amp;amp;_afrWindowMode=0&amp;amp;_adf.ctrl-state=184vwc6g3y_4 Master Note for Diagnosing ORA-600 (Doc ID 1092832.1)]&lt;br /&gt;
===ORA-19051: Cannot use fast path insert for this XMLType table===&lt;br /&gt;
Think LD_LIBRARY_PATH on Linux or LIBPATH on AIX.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Export: Release 11.2.0.4.0 - Production on Thu Jun 1 06:41:55 2017&lt;br /&gt;
&lt;br /&gt;
Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.&lt;br /&gt;
&lt;br /&gt;
Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production&lt;br /&gt;
With the Partitioning, OLAP, Data Mining and Real Application Testing options&lt;br /&gt;
Starting &amp;quot;DWH_EXPORT&amp;quot;.&amp;quot;SYS_EXPORT_TABLE_03&amp;quot;:  dwh_export/******** parfile=cadis_foto_export_credit_dba.par&lt;br /&gt;
Estimate in progress using BLOCKS method...&lt;br /&gt;
Processing object type TABLE_EXPORT/TABLE/TABLE_DATA&lt;br /&gt;
Total estimation using BLOCKS method: 64.08 GB&lt;br /&gt;
ORA-39126: Worker unexpected fatal error in KUPW$WORKER.FETCH_XML_OBJECTS []&lt;br /&gt;
ORA-19051: Cannot use fast path insert for this XMLType table&lt;br /&gt;
&lt;br /&gt;
ORA-06512: at &amp;quot;SYS.DBMS_SYS_ERROR&amp;quot;, line 86&lt;br /&gt;
ORA-06512: at &amp;quot;SYS.KUPW$WORKER&amp;quot;, line 9710&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Problem====&lt;br /&gt;
When the 11g DB was started, LD_LIBRARY_PATH and LIBPATH were still pointing to paths in the 10g Home.&lt;br /&gt;
====Solution====&lt;br /&gt;
There may have been some odd values setup in LD_LIBRARY_PATH before the call to oraenv (if oraenv was indeed called!)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
unset LD_LIBRARY_PATH LIBPATH&lt;br /&gt;
export ORACLE_SID=&amp;lt;correct 11g SID&amp;gt;&lt;br /&gt;
. oraenv&lt;br /&gt;
echo $LD_LIBRARY_PATH&lt;br /&gt;
echo $LIBPATH&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
They should now be correct.&lt;br /&gt;
&lt;br /&gt;
===ORA-27092: size of file exceeds file size limit of the process===&lt;br /&gt;
Think ulimit...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Cause: an attempt was made to open a file that exceeds the process&amp;#039;s file size limit (ulimit), additional information shows the current limit (logical blocks) and the size of the file (logical blocks)&lt;br /&gt;
Action: increase the processes file size limit (ulimit) and retry&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
truncate table pibadm.test_ph&lt;br /&gt;
                      *&lt;br /&gt;
Error at line 1 :&lt;br /&gt;
ORA-00604: error ocurred at recursive SQL level 1&lt;br /&gt;
ORA-01116: error in opening database file 2&lt;br /&gt;
ORA-01110: datafile 2 : &amp;#039;/opt/u01/data/PIBQA/UNDO_01.dbf&amp;#039;&lt;br /&gt;
ORA-27092: size of file exceeds file size limit of the process&lt;br /&gt;
Additional information: 262143&lt;br /&gt;
Additional information: 2621441&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Check the fs_size limit for this user in /etc/security/limits&amp;lt;br /&amp;gt;&lt;br /&gt;
Compare this with another user, say oracle. Probably -1 (unlimited)&lt;br /&gt;
&lt;br /&gt;
===SP2-1503: Unable to initialize Oracle call interface===&lt;br /&gt;
When trying to login to the database via SQL*Plus, these messages a displayed&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
hn5118 /home/oracle $sqlplus / as sysdba&lt;br /&gt;
SP2-1503: Unable to initialize Oracle call interface&lt;br /&gt;
SP2-0152: ORACLE may not be functioning properly&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Seems to be a problem unique to AIX (in this case).&amp;lt;br /&amp;gt;&lt;br /&gt;
Check to see what the LIBPATH variable is. It may still contain a path to an old ORACLE_HOME...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
hn5118 /home/oracle $env|grep LIBPATH&lt;br /&gt;
LIBPATH=/oracle/exp/ora_bin1/app/oracle/product/10.2.0/db_1/lib:/oracle/exp/ora_bin1/app/oracle/product/10.2.0/db_1/lib&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Disco! Unset it and rerun.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
hn5118 /home/oracle $unset LIBPATH&lt;br /&gt;
&lt;br /&gt;
hn5118 /home/oracle $sqlplus / as sysdba&lt;br /&gt;
&lt;br /&gt;
SQL*Plus: Release 12.1.0.2.0 Production on Wed Jul 12 17:17:54 2017&lt;br /&gt;
&lt;br /&gt;
Copyright (c) 1982, 2014, Oracle.  All rights reserved.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Connected to:&lt;br /&gt;
Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production&lt;br /&gt;
With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options&lt;br /&gt;
&lt;br /&gt;
SQL&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===UDE-31623: operation generated ORACLE error 31623===&lt;br /&gt;
When using Data pump, get following errors almost immediately:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
UDE-31623: operation generated ORACLE error 31623&lt;br /&gt;
ORA-31623: a job is not attached to this session via the specified handle&lt;br /&gt;
ORA-06512: at &amp;quot;SYS.DBMS_DATAPUMP&amp;quot;, line 3326&lt;br /&gt;
ORA-06512: at &amp;quot;SYS.DBMS_DATAPUMP&amp;quot;, line 4551&lt;br /&gt;
ORA-06512: at line 1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Solution 1:&amp;#039;&amp;#039;&amp;#039;&amp;lt;br /&amp;gt;&lt;br /&gt;
In one case, I simplified the parameter file that was used. Maybe related to Streams Pool size, who knows?!&amp;lt;br /&amp;gt;&lt;br /&gt;
I removed these 2 lines and the export started working:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
compression_algorithm=medium&lt;br /&gt;
logtime=all&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Solution 2:&amp;#039;&amp;#039;&amp;#039;&amp;lt;br /&amp;gt;&lt;br /&gt;
There is a note about this on Metalink, 1080775.1 which suggests that Streams Pool Size needs setting.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
For this DataPump error, you will need to configure the database with some Streams Pool.&lt;br /&gt;
&lt;br /&gt;
Perform the following query to find out how much STREAMS_POOL_SIZE has been allocated&lt;br /&gt;
&lt;br /&gt;
 select * from v$sgainfo;&lt;br /&gt;
 ...&lt;br /&gt;
 Streams Pool Size                               0 Yes&lt;br /&gt;
&lt;br /&gt;
Data Pump now uses Advanced Queuing (AQ) internally, so it can handle job stops/starts/re-starts.  However, AQ using the Streams Pool, where the database currently has the STREAMS_POOL_SIZE set to ZERO.&lt;br /&gt;
&lt;br /&gt;
Manually set the STREAMS_POOL_SIZE (using ALTER SYSTEM or by changing the value in the the PFILE/SPFILE), re-start the database and re-attempt the Data Pump Export.&lt;br /&gt;
&lt;br /&gt;
Alternately, turn on Automatic Shared Memory management (ASMM) by setting SGA_TARGET or MEMORY_TARGET.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
From Oracle Documentation&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Setting the Size Of the Buffer Cache In a Streams Environment&lt;br /&gt;
&lt;br /&gt;
Oracle Data Pump uses Streams functionality to communicate between processes.&lt;br /&gt;
If the SGA_TARGET initialization parameter is set, then the STREAMS_POOL_SIZE initialization parameter is automatically set to a reasonable value.&lt;br /&gt;
If the SGA_TARGET initialization parameter is not set and the STREAMS_POOL_SIZE initialization parameter is not defined,&lt;br /&gt;
then the size of the streams pool automatically defaults to 10% of the size of the shared pool.&lt;br /&gt;
&lt;br /&gt;
When the streams pool is created, the required SGA memory is taken from memory allocated to the buffer cache,&lt;br /&gt;
reducing the size of the cache to less than what was specified by the DB_CACHE_SIZE initialization parameter.&lt;br /&gt;
This means that if the buffer cache was configured with only the minimal required SGA, then Data Pump operations may not work properly.&lt;br /&gt;
A minimum size of 10M is recommended for STREAMS_POOL_SIZE in order to ensure successful Data Pump operations.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORA-00020: maximum number of processes (150) exceeded===&lt;br /&gt;
Check the current resource limits with:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 300&lt;br /&gt;
select * from v$resource_limit;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Unfortunately this limit cannot be increased without a restart.&amp;lt;br /&amp;gt;&lt;br /&gt;
It may be a necessary to increase the limit with&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter system set processes=500 scope=spfile;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
followed by a shutdown/startup&amp;lt;br /&amp;gt;&lt;br /&gt;
Or it may be some user is running away with the limit.&amp;lt;br /&amp;gt;&lt;br /&gt;
Check to see who is running what with:&lt;br /&gt;
[[http://www.mailnest.com/dbawiki/index.php/Handy_scripts#See_what_statements_all_users_are_running See_what_statements_all_users_are_running]]&lt;br /&gt;
===ORA-01555: snapshot too old: rollback segment number nn with name &amp;quot;xxx&amp;quot; too small===&lt;br /&gt;
* [http://dfitzjarrell.wordpress.com/2008/02/22/the-dreaded-ora-01555/ Good explanation of why it happens]&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
====Problem====&lt;br /&gt;
A long running transaction has run out of space to store its read-consistent image&lt;br /&gt;
&lt;br /&gt;
====Solution 1====&lt;br /&gt;
If it&amp;#039;s a one-off, maybe leave it alone. It may have been a user leaving a session open overnight without committing or rolling back.&lt;br /&gt;
&lt;br /&gt;
====Solution 2====&lt;br /&gt;
Make sure there&amp;#039;s enough space to allow the transaction to finish.&lt;br /&gt;
&lt;br /&gt;
====Things to check====&lt;br /&gt;
How much undo did the biggest transaction take?&lt;br /&gt;
What is the undo retention parameter set to?&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 200&lt;br /&gt;
col name        for a30&lt;br /&gt;
col description for a50&lt;br /&gt;
col value       for a20&lt;br /&gt;
col maxquerylen for 999999&lt;br /&gt;
select p.name&lt;br /&gt;
,      p.description&lt;br /&gt;
,      p.value&lt;br /&gt;
,      max(u.maxquerylen) maxquerylen&lt;br /&gt;
from   v$parameter p&lt;br /&gt;
,      v$undostat  u&lt;br /&gt;
where  1=1&lt;br /&gt;
and    p.name = &amp;#039;undo_retention&amp;#039;&lt;br /&gt;
group  by p.name&lt;br /&gt;
,      p.description&lt;br /&gt;
,      p.value;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Set the retention to about 20% bigger than the maxquerylen.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select &amp;#039;alter system set undo_retention=&amp;#039;||round(1.2*max(maxquerylen))||&amp;#039; scope=both;&amp;#039; &amp;quot;Run this&amp;quot; from v$undostat;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
and set the undo retention guarantee (being aware of the consequences)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select tablespace_name&lt;br /&gt;
,      retention&lt;br /&gt;
from   dba_tablespaces;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter tablespace &amp;amp;undo_ts_name retention guarantee;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Optimise Oracle UNDO Parameters===&lt;br /&gt;
&lt;br /&gt;
The ideal undo_retention would be enough to hold rollback for the longest transaction that happened so far (can&amp;#039;t see into the future)&amp;lt;br /&amp;gt;&lt;br /&gt;
So current undo_retention = current value of undo / (db_block_size * undo blocks per sec)&amp;lt;br /&amp;gt;&lt;br /&gt;
* Undo Blocks per Second&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SELECT MAX(undoblks/((end_time-begin_time)*3600*24)) &amp;quot;UNDO_BLOCKS_PER_SEC&amp;quot;&lt;br /&gt;
FROM   v$undostat;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Optimal Undo Retention&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
col actual for 9999999999.99 heading &amp;quot;ACTUAL UNDO SIZE [MByte]&amp;quot;&lt;br /&gt;
col retent for 9999999999    heading &amp;quot;UNDO RETENTION [Sec]&amp;quot;&lt;br /&gt;
col needed for 9999999999.99 heading &amp;quot;NEEDED UNDO SIZE [Secs]&amp;quot;&lt;br /&gt;
&lt;br /&gt;
SELECT d.undo_size/(1024*1024) actual,&lt;br /&gt;
       to_number(SUBSTR(e.value,1,25)) retent,&lt;br /&gt;
       ROUND((d.undo_size / (to_number(f.value) *&lt;br /&gt;
       g.undo_block_per_sec))) needed&lt;br /&gt;
  FROM (&lt;br /&gt;
       SELECT SUM(a.bytes) undo_size&lt;br /&gt;
          FROM v$datafile a,&lt;br /&gt;
               v$tablespace b,&lt;br /&gt;
               dba_tablespaces c&lt;br /&gt;
         WHERE c.contents = &amp;#039;UNDO&amp;#039;&lt;br /&gt;
           AND c.status = &amp;#039;ONLINE&amp;#039;&lt;br /&gt;
           AND b.name = c.tablespace_name&lt;br /&gt;
           AND a.ts# = b.ts#&lt;br /&gt;
       ) d,&lt;br /&gt;
       v$parameter e,&lt;br /&gt;
       v$parameter f,&lt;br /&gt;
       (&lt;br /&gt;
       SELECT MAX(undoblks/((end_time-begin_time)*3600*24))&lt;br /&gt;
              undo_block_per_sec&lt;br /&gt;
         FROM v$undostat&lt;br /&gt;
       ) g&lt;br /&gt;
WHERE e.name = &amp;#039;undo_retention&amp;#039;&lt;br /&gt;
  AND f.name = &amp;#039;db_block_size&amp;#039;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Calculate Needed UNDO Size for given Database Activity&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
col actual for 9999999999.99 heading &amp;quot;ACTUAL UNDO SIZE [MByte]&amp;quot;&lt;br /&gt;
col retent for 9999999999    heading &amp;quot;UNDO RETENTION [Sec]&amp;quot;&lt;br /&gt;
col needed for 9999999999.99 heading &amp;quot;NEEDED UNDO SIZE [MByte]&amp;quot;&lt;br /&gt;
&lt;br /&gt;
SELECT d.undo_size/(1024*1024) actual&lt;br /&gt;
,      to_number(SUBSTR(e.value,1,25)) retent&lt;br /&gt;
,      (TO_NUMBER(e.value) * TO_NUMBER(f.value) *&lt;br /&gt;
       g.undo_block_per_sec) / (1024*1024)  needed&lt;br /&gt;
  FROM (&lt;br /&gt;
       SELECT SUM(a.bytes) undo_size&lt;br /&gt;
         FROM v$datafile a,&lt;br /&gt;
              v$tablespace b,&lt;br /&gt;
              dba_tablespaces c&lt;br /&gt;
        WHERE c.contents = &amp;#039;UNDO&amp;#039;&lt;br /&gt;
          AND c.status = &amp;#039;ONLINE&amp;#039;&lt;br /&gt;
          AND b.name = c.tablespace_name&lt;br /&gt;
          AND a.ts# = b.ts#&lt;br /&gt;
       ) d,&lt;br /&gt;
      v$parameter e,&lt;br /&gt;
       v$parameter f,&lt;br /&gt;
       (&lt;br /&gt;
       SELECT MAX(undoblks/((end_time-begin_time)*3600*24))&lt;br /&gt;
         undo_block_per_sec&lt;br /&gt;
         FROM v$undostat&lt;br /&gt;
       ) g&lt;br /&gt;
 WHERE e.name = &amp;#039;undo_retention&amp;#039;&lt;br /&gt;
  AND f.name = &amp;#039;db_block_size&amp;#039;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
It might be that the Export still fails with ORA-01555 even though retention seems long enough.&amp;lt;br /&amp;gt;&lt;br /&gt;
Are you running an export with the flashback_time parameter? If so, the undo_retention should be longer than the total export running time!&amp;lt;br /&amp;gt;&lt;br /&gt;
===Check LOB undo retention===&lt;br /&gt;
The retention settings for LOBS is different for the rest of the database.&amp;lt;br /&amp;gt;&lt;br /&gt;
When you change the UNDO_RETENTION parameter, the LOB segment’s retention value is NOT modified.&amp;lt;br /&amp;gt;&lt;br /&gt;
If you query the RETENTION column of the DBA_LOBS view, you will notice the old UNDO_RETENTION value still remains after you have modified the UNDO_RETENTION parameter.&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SQL&amp;gt; show parameter undo_&lt;br /&gt;
&lt;br /&gt;
NAME                                 TYPE        VALUE&lt;br /&gt;
------------------------------------ ----------- ------------------------------&lt;br /&gt;
undo_management                      string      AUTO&lt;br /&gt;
undo_retention                       integer     36000&lt;br /&gt;
undo_tablespace                      string      UNDOTBS1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SQL&amp;gt; desc SITEADMIN.AUDIT_LOG_MESSAGE&lt;br /&gt;
 Name                                      Null?    Type&lt;br /&gt;
 ----------------------------------------- -------- ----------------------------&lt;br /&gt;
 AUDIT_LOG_MESSAGE_ID                      NOT NULL NUMBER&lt;br /&gt;
 AUDIT_LOG_ID                              NOT NULL NUMBER&lt;br /&gt;
 SEQUENCE                                           NUMBER&lt;br /&gt;
 MESSAGE                                            CLOB&lt;br /&gt;
 CREATE_DATE                                        TIMESTAMP(6)&lt;br /&gt;
 COMPONENT_ID                                       VARCHAR2(50 CHAR)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 300&lt;br /&gt;
col column_name for a32&lt;br /&gt;
select table_name,column_name, pctversion,retention from dba_lobs where owner=&amp;#039;&amp;amp;table_owner&amp;#039;;&lt;br /&gt;
&lt;br /&gt;
TABLE_NAME                COLUMN_NAME                    PCTVERSION  RETENTION&lt;br /&gt;
------------------------- ------------------------------ ---------- ----------&lt;br /&gt;
EMAIL_STORE               CONTENT                                 0&lt;br /&gt;
EMAIL_STORE_ATTACHEMENT   ATTACHEMENT                             0&lt;br /&gt;
TRACKING                  ORIGINAL_MESSAGE                                 900&lt;br /&gt;
TRACKING                  MESSAGE                                          900&lt;br /&gt;
TRACKING                  SIEBEL_MESSAGE                                   900&lt;br /&gt;
WISE_WMS_LOG              WISE_WMS_XML                                     900&lt;br /&gt;
ATTACHMENT                ORIGINAL_MESSAGE                                 900&lt;br /&gt;
PLAN_TABLE                OTHER_XML                                        900&lt;br /&gt;
AUDIT_LOG_MESSAGE         MESSAGE                                          900&lt;br /&gt;
EXCEPTIONS                STACK_TRACE                                      900&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
To change the LOB segment’s RETENTION value to match the new UNDO_RETENTION value, do the following:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ALTER TABLE my_table MODIFY LOB (lob_column) (PCTVERSION 20);&lt;br /&gt;
ALTER TABLE my_table MODIFY LOB (lob_column) (RETENTION);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
By momentarily changing the LOB to use PCTVERSION and then back to RETENTION, the new value of UNDO_RETENTION will be used.&amp;lt;br /&amp;gt;&lt;br /&gt;
You need to do this for all LOB segments that you intend to modify.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select &amp;#039;ALTER TABLE &amp;#039;||owner||&amp;#039;.&amp;#039;||table_name||&amp;#039; MODIFY LOB (&amp;#039;||column_name||&amp;#039;) (PCTVERSION 20);&amp;#039; from dba_lobs where owner=&amp;#039;TIBCO&amp;#039;&lt;br /&gt;
&lt;br /&gt;
select &amp;#039;ALTER TABLE &amp;#039;||owner||&amp;#039;.&amp;#039;||table_name||&amp;#039; MODIFY LOB (&amp;#039;||column_name||&amp;#039;) (RETENTION);&amp;#039;     from dba_lobs where owner=&amp;#039;TIBCO&amp;#039;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
There is a table DBA_LOBS that displays information about all the LOB columns in the database, but it doesn&amp;#039;t actually store any LOB data, just metadata. The actual LOB segments in the database have system-generated names that take the form SYS_LOB*identifier*$$.&lt;br /&gt;
For example if you identify a segment named SYS_LOBidentifier$$ that is consuming space, you can find out what column of what table that LOB column maps to using the DBA_LOBS table:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 1000&lt;br /&gt;
col owner       for a20&lt;br /&gt;
col table_name  for a32&lt;br /&gt;
col column_name for a32&lt;br /&gt;
select owner&lt;br /&gt;
,      table_name&lt;br /&gt;
,      column_name&lt;br /&gt;
from   dba_lobs&lt;br /&gt;
where  1=1&lt;br /&gt;
and    segment_name = &amp;#039;SYS_LOB&amp;lt;&amp;lt;identifier&amp;gt;&amp;gt;$$&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====The Undo Advisor PL/SQL Interface====&lt;br /&gt;
You can activate the Undo Advisor by creating an undo advisor task through the advisor framework.&amp;lt;br /&amp;gt;&lt;br /&gt;
The following example creates an undo advisor task to evaluate the undo tablespace. The name of the advisor is &amp;#039;Undo Advisor&amp;#039;.&amp;lt;br /&amp;gt;&lt;br /&gt;
The analysis is based on Automatic Workload Repository snapshots, which you must specify by setting parameters START_SNAPSHOT and END_SNAPSHOT.&amp;lt;br /&amp;gt;&lt;br /&gt;
In the following example, the START_SNAPSHOT is &amp;quot;1&amp;quot; and END_SNAPSHOT is &amp;quot;2&amp;quot;.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
DECLARE&lt;br /&gt;
   tid    NUMBER;&lt;br /&gt;
   tname  VARCHAR2(30);&lt;br /&gt;
   oid    NUMBER;&lt;br /&gt;
BEGIN&lt;br /&gt;
   DBMS_ADVISOR.CREATE_TASK(&amp;#039;Undo Advisor&amp;#039;, tid, tname, &amp;#039;Undo Advisor Task&amp;#039;);&lt;br /&gt;
   DBMS_ADVISOR.CREATE_OBJECT(tname, &amp;#039;UNDO_TBS&amp;#039;, null, null, null, &amp;#039;null&amp;#039;, oid);&lt;br /&gt;
   DBMS_ADVISOR.SET_TASK_PARAMETER(tname, &amp;#039;TARGET_OBJECTS&amp;#039;, oid);&lt;br /&gt;
   DBMS_ADVISOR.SET_TASK_PARAMETER(tname, &amp;#039;START_SNAPSHOT&amp;#039;, 1);&lt;br /&gt;
   DBMS_ADVISOR.SET_TASK_PARAMETER(tname, &amp;#039;END_SNAPSHOT&amp;#039;, 2);&lt;br /&gt;
   DBMS_ADVISOR.SET_TASK_PARAMETER(tname, &amp;#039;INSTANCE&amp;#039;, 1);&lt;br /&gt;
   DBMS_ADVISOR.execute_task(tname);&lt;br /&gt;
        END;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
After you have created the advisor task, you can view the output and recommendations in the Automatic Database Diagnostic Monitor in Enterprise Manager.&amp;lt;br /&amp;gt;&lt;br /&gt;
This information is also available in the DBA_ADVISOR_* data dictionary views (DBA_ADVISOR_TASKS, DBA_ADVISOR_OBJECTS, DBA_ADVISOR_FINDINGS, DBA_ADVISOR_RECOMMENDATIONS, and so on).&lt;br /&gt;
====References====&lt;br /&gt;
* [http://www.akadia.com/services/ora_optimize_undo.html akadia.com]&lt;br /&gt;
* [http://dfitzjarrell.wordpress.com/2008/02/22/the-dreaded-ora-01555/ the dreaded ora-01555]&lt;br /&gt;
* [http://docs.oracle.com/cd/B28359_01/server.111/b28310/undo004.htm#ADMIN11469 docs.oracle.com]&lt;br /&gt;
&lt;br /&gt;
===Error 6 initializing SQL*Plus===&lt;br /&gt;
Using sqlplus or rman under Cygwin, ORACLE_HOME still needs to be windows format!&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Message file sp1&amp;lt;lang&amp;gt;.msb not found&lt;br /&gt;
SP2-0750 :You may need to set ORACLE_HOME to your Oracle software directory&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
so...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
export ORACLE_SID=KITRYD&lt;br /&gt;
ORAENV_ASK=NO&lt;br /&gt;
. oraenv&lt;br /&gt;
[[ &amp;quot;`uname`&amp;quot; == CYGWIN* ]] &amp;amp;&amp;amp; ORACLE_HOME=`cygpath -w ${ORACLE_HOME}`&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===ORA-2002: error while writing to audit trail===&lt;br /&gt;
Check the space left in the audit tablespace with:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select sum(bytes)/1024/1024 mb from dba_free_space where tablespace_name =&amp;#039;AUDIT_DT&amp;#039;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
If plenty of space, it can be due to Oracle clearing out the recyclebin at the same time.&amp;lt;br /&amp;gt;&lt;br /&gt;
If not, extend the datafile...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select * from dba_data_files where tablespace_name =&amp;#039;AUDIT_DT&amp;#039;;&lt;br /&gt;
alter database datafile 6 resize 30G;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
If that is not possible, clean out some audit data or add a datafile.&lt;br /&gt;
&lt;br /&gt;
===ORA-00449: background process &amp;#039;CKPT&amp;#039; unexpectedly terminated with error 7446===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SQL&amp;gt; startup nomount pfile=&amp;quot;/oracle/TRSCRP1/admin/initTRSCRP1.ora&amp;quot;&lt;br /&gt;
ORA-00449: background process &amp;#039;CKPT&amp;#039; unexpectedly terminated with error 7446&lt;br /&gt;
ORA-07446: sdnfy: bad value &amp;#039;&amp;#039; for parameter .&lt;br /&gt;
SQL&amp;gt; exit&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Solution&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SQL&amp;gt; mkdir /oracle/TRSCRP1/admin/bdump /oracle/TRSCRP1/admin/cdump&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORA-00845: MEMORY_TARGET not supported on this system===&lt;br /&gt;
* Reference: [http://arjudba.blogspot.be/2009/01/ora-00845-memorytarget-not-supported-on.html arjudba.blogspot.be]&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Problem Description&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SQL&amp;gt; STARTUP&lt;br /&gt;
ORA-00845: MEMORY_TARGET not supported on this system&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Cause&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
* Starting from Oracle 11g the automatic memory management feature is now defined with parameter MEMORY_TARGET and MEMMORY_MAX_TARGET.&lt;br /&gt;
* On linux file system the shared memory need to be mounted on /dev/shm directory on the operating system.&lt;br /&gt;
* And the size of /dev/shm needs to be greater than MEMORY_TARGET or MEMMORY_MAX_TARGET.&lt;br /&gt;
* The AMM (Automatic Memory Management) now in 11g manages both SGA and PGA together by MMAN process.&lt;br /&gt;
* The MEMORY_TARGET parameter in 11g comes for (SGA_TARGET+PGA_AGGREGATE_TARGET) which was in 10g.&lt;br /&gt;
* And MEMORY_MAX_TARGET parameter in 11g comes instead of SGA_MAX_TARGET parameter which was in 10g.&lt;br /&gt;
* The ORA-00845:can arises for the following two reasons on linux system.&lt;br /&gt;
1)If the shared memory which is mapped to /dev/shm directory is less than the size of MEMORY_TARGET or MEMORY_MAX_TARGET or&lt;br /&gt;
2)If the shared memory is not mapped to /dev/shm directory.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Solution&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Make sure /dev/shm is properly mounted. You can see it by,&lt;br /&gt;
#df -h or #df -k command.&lt;br /&gt;
The output should be similar to:&lt;br /&gt;
&lt;br /&gt;
$ df -k&lt;br /&gt;
Filesystem            Size  Used Avail Use% Mounted on&lt;br /&gt;
...&lt;br /&gt;
shmfs                 1G    512M 512M  50% /dev/shm&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
We see here for /dev/shm we have assigned 1G memory. Now if you set MEMORY_TARGET more than 1G then above ORA-845 will arise. For example if you have MEMORY_TARGET or MEMORY_MAX_TARGET set to 12G then you can mount shared memory to 13g like below.&lt;br /&gt;
As a root user,&lt;br /&gt;
# mount -t tmpfs shmfs -o size=13g /dev/shm&lt;br /&gt;
In order to make the settings persistence so that it will affect after restarting machine add an entry in /etc/fstab similar to the following:&lt;br /&gt;
&lt;br /&gt;
shmfs /dev/shm tmpfs size=13g 0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORA-24247: network access denied by access control list (ACL)===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Cause: No access control list (ACL) has been assigned to the target host or the privilege necessary to access the target host has not been granted to the user in the access control list.&lt;br /&gt;
&lt;br /&gt;
Action: Ensure that an access control list (ACL) has been assigned to the target host and the privilege necessary to access the target host has been granted to the user.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Your application will encounter an ORA-24247 error if it relies on one of the network packages and no proper ACL has been created. For the use of the following packages it is mandatory to have an ACL for the application user in place in 11g:&lt;br /&gt;
*UTL_TCP&lt;br /&gt;
*UTL_SMTP&lt;br /&gt;
*UTL_MAIL&lt;br /&gt;
*UTL_HTTP&lt;br /&gt;
*UTL_INADDR&lt;br /&gt;
Here is a very good explanation of how to setup the necessary ACLs: [[http://blog.whitehorses.nl/2010/03/17/oracle-11g-access-control-list-and-ora-24247/ whitehorses.nl]]&lt;br /&gt;
&lt;br /&gt;
===ORA-00600: internal error code, arguments: [qmx: no ref]===&lt;br /&gt;
Search &amp;quot;Master Note for Oracle XML Database (XDB) Install / Deinstall (Doc ID 1292089.1)&amp;quot; for more info.&lt;br /&gt;
====Problem:====&lt;br /&gt;
Sometimes one or more of the following errors can be encountered when installing or upgrading XDB, configuring APEX, running an Export, or selecting from xdb.xdb$resource or sys.dba_network_acls:&amp;lt;br /&amp;gt;&lt;br /&gt;
* ORA-31159: XML DB is in an invalid state&lt;br /&gt;
* ORA-00600: internal error code, arguments: [unable to load XDB library]&lt;br /&gt;
* ORA-00600: internal error code, arguments: [qmx: no ref]&lt;br /&gt;
* ORA-00600: internal error code, arguments: [qmtGetColumnInfo1]&lt;br /&gt;
* ORA-00600: internal error code, arguments: [qmtb_init_len]&lt;br /&gt;
* ORA-00600: internal error code, arguments: [qmtGetBaseType]&lt;br /&gt;
* ORA-00600: internal error code, arguments: [psdnop-1], [600]&lt;br /&gt;
* ORA-00600: internal error code, arguments: [qmtInit1]&lt;br /&gt;
* ORA-07445: exception encountered: core dump [_memcpy()+224] [SIGSEGV] [Address not mapped to object]&lt;br /&gt;
* ORA-19051 Cannot Use Fast Path Insert For This XMLType Table&lt;br /&gt;
* ORA-31011: XML parsing failed&lt;br /&gt;
Errors of this sort generally occur when the init routines for the internal XDB functions are run in an invalid environment causing memory corruption.&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
This can happen if the database was ever started with the LD_LIBRARY_PATH (LIBPATH for AIX or SHLIB_PATH for HP) pointing to the wrong $ORACLE_HOME/lib directory rather than to the correct location for the instance.&amp;lt;br /&amp;gt;&lt;br /&gt;
The LD_LIBRARY_PATH/LIBPATH/SHLIB_PATH environment variable is used to resolve the location of the shared library &amp;quot;libxdb.so (libxdb.sl on HP)&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
====Solution:====&lt;br /&gt;
* Stop Listener&lt;br /&gt;
* Stop database&lt;br /&gt;
* Ensure $ORACLE_HOME/lib is at the start of LD_LIBRARY_PATH / LIBPATH / SHLIB_PATH&lt;br /&gt;
* If AIX, run /usr/sbin/slibclean as root&lt;br /&gt;
* Start database&lt;br /&gt;
* Start listener&lt;br /&gt;
&lt;br /&gt;
===ORA-00201: control file version nn.nn.nn.nn incompatible with ORACLE version===&lt;br /&gt;
Trying to restore a database after complete failure&amp;lt;br /&amp;gt;&lt;br /&gt;
first step is to startup the database in nomount mode and restore the controlfile - succeeded.&amp;lt;br /&amp;gt;&lt;br /&gt;
second step, startup the database in mount mode ready for database restore...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SQL*Plus: Release 10.2.0.3.0 - Production on Wed Aug 19 18:16:47 2015&lt;br /&gt;
&lt;br /&gt;
Copyright (c) 1982, 2006, Oracle.  All Rights Reserved.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Connected to:&lt;br /&gt;
Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - 64bit Production&lt;br /&gt;
With the Partitioning, OLAP and Data Mining options&lt;br /&gt;
&lt;br /&gt;
SYS@CODWHP1&amp;gt; startup mount&lt;br /&gt;
ORACLE instance started.&lt;br /&gt;
&lt;br /&gt;
Total System Global Area  260046848 bytes&lt;br /&gt;
Fixed Size                  2029296 bytes&lt;br /&gt;
Variable Size             113248528 bytes&lt;br /&gt;
Database Buffers          134217728 bytes&lt;br /&gt;
Redo Buffers               10551296 bytes&lt;br /&gt;
ORA-00201: control file version 10.2.0.0.0 incompatible with ORACLE version 10.2.0.3.0&lt;br /&gt;
ORA-00202: control file: &amp;#039;/oracle/CODWHP1/product/10203/dbs/cntrlCODWHP1.dbf&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The problem was there was no compatible parameter in the simple init file I used to start up the instance.&amp;lt;br /&amp;gt;&lt;br /&gt;
Adding compatible parameter to init file to be same version (10.2.0.3) allowed the db to mount.&lt;br /&gt;
&lt;br /&gt;
===TNS-00525: Insufficient privilege for operation===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
lsnrctl start LISTENER_UCLID55V&lt;br /&gt;
&lt;br /&gt;
LSNRCTL for IBM/AIX RISC System/6000: Version 11.2.0.3.0 - Production on 26-MAR-2015 13:36:14&lt;br /&gt;
&lt;br /&gt;
Copyright (c) 1991, 2011, Oracle.  All rights reserved.&lt;br /&gt;
&lt;br /&gt;
Starting /oracle/product/11.2.0.3/bin/tnslsnr: please wait...&lt;br /&gt;
&lt;br /&gt;
TNSLSNR for IBM/AIX RISC System/6000: Version 11.2.0.3.0 - Production&lt;br /&gt;
System parameter file is /oracle/product/11.2.0.3/network/admin/listener.ora&lt;br /&gt;
Log messages written to /oracle/product/diag/tnslsnr/solax082/listener_uclid55v/alert/log.xml&lt;br /&gt;
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=150.251.114.238)(PORT=1525)))&lt;br /&gt;
Error listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC1525)))&lt;br /&gt;
TNS-12555: TNS:permission denied&lt;br /&gt;
 TNS-12560: TNS:protocol adapter error&lt;br /&gt;
  TNS-00525: Insufficient privilege for operation&lt;br /&gt;
   IBM/AIX RISC System/6000 Error: 1: Not owner&lt;br /&gt;
&lt;br /&gt;
Listener failed to start. See the error message(s) above...&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This would suggest the user attempting to start the listener has no access to either the Oracle binaries or the TNS listener/tnsnames files.&amp;lt;br /&amp;gt;&lt;br /&gt;
But... checkout the /tmp/.oracle directory :-)&amp;lt;br /&amp;gt;&lt;br /&gt;
That hidden gem shows who started the listener last time. Delete the relevant entry and try again!&amp;lt;br /&amp;gt;&lt;br /&gt;
To start from a clean sheet, stop all listeners, delete this directory and restart the listeners.&lt;br /&gt;
&lt;br /&gt;
===ORA-12003: materialized view or zonemap &amp;quot;KPK&amp;quot;.&amp;quot;EVD01_NEW&amp;quot; does not exist===&lt;br /&gt;
Here&amp;#039;s one you shouldn&amp;#039;t see very often.&amp;lt;br /&amp;gt;&lt;br /&gt;
Trying to drop a tablespace but prevented from doing so because a materialized view has referential contraints on a table in this tablespace.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SQL&amp;gt; drop tablespace TS_THALER_PART_OLD including contents and datafiles cascade constraints;&lt;br /&gt;
drop tablespace TS_THALER_PART_OLD including contents and datafiles cascade constraints&lt;br /&gt;
*&lt;br /&gt;
ERROR at line 1:&lt;br /&gt;
ORA-00604: error occurred at recursive SQL level 1&lt;br /&gt;
ORA-12083: must use DROP MATERIALIZED VIEW to drop &amp;quot;KPK&amp;quot;.&amp;quot;EVD01_NEW&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Ok, nice of Oracle to tell us what we have to do. Simple enough. Let&amp;#039;s drop the materialized view.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SQL&amp;gt; DROP MATERIALIZED VIEW &amp;quot;KPK&amp;quot;.&amp;quot;EVD01_NEW&amp;quot;;&lt;br /&gt;
DROP MATERIALIZED VIEW &amp;quot;KPK&amp;quot;.&amp;quot;EVD01_NEW&amp;quot;&lt;br /&gt;
*&lt;br /&gt;
ERROR at line 1:&lt;br /&gt;
ORA-12003: materialized view or zonemap &amp;quot;KPK&amp;quot;.&amp;quot;EVD01_NEW&amp;quot; does not exist&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Aah. Not so obvious then.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
desc &amp;quot;KPK&amp;quot;.&amp;quot;EVD01_NEW&amp;quot;&lt;br /&gt;
 Name                                      Null?    Type&lt;br /&gt;
 ----------------------------------------- -------- ----------------------------&lt;br /&gt;
 DATMAJ                                             VARCHAR2(8 CHAR)&lt;br /&gt;
 HEUMAJ                                             VARCHAR2(8 CHAR)&lt;br /&gt;
 PGMMAJ                                             VARCHAR2(6 CHAR)&lt;br /&gt;
 NATOPN                                             VARCHAR2(6 CHAR)&lt;br /&gt;
 REFEXN                                             VARCHAR2(50 CHAR)&lt;br /&gt;
 SWIOLN                                             VARCHAR2(1 CHAR)&lt;br /&gt;
 STAEVT                                             VARCHAR2(4 CHAR)&lt;br /&gt;
 REFEVT                                             VARCHAR2(16 CHAR)&lt;br /&gt;
 NUMIDT                                             VARCHAR2(30 CHAR)&lt;br /&gt;
 ORIEVT                                             VARCHAR2(10 CHAR)&lt;br /&gt;
 REFLOG                                             VARCHAR2(16 CHAR)&lt;br /&gt;
 MSGEVT_CPL                                         VARCHAR2(1500 CHAR)&lt;br /&gt;
 REFOPN                                             VARCHAR2(16 CHAR)&lt;br /&gt;
 DATEVT                                             VARCHAR2(8 CHAR)&lt;br /&gt;
 MSGEVT_FIL_1                                       VARCHAR2(2000 CHAR)&lt;br /&gt;
 MSGEVT_FIL_2                                       VARCHAR2(2000 CHAR)&lt;br /&gt;
 MSGEVT_SPE                                         VARCHAR2(200 CHAR)&lt;br /&gt;
 DATEFF                                             VARCHAR2(8 CHAR)&lt;br /&gt;
 TMSTMP                                             VARCHAR2(15 CHAR)&lt;br /&gt;
 VEREVT                                             VARCHAR2(3 CHAR)&lt;br /&gt;
 MSGEVT_FIL_3                                       VARCHAR2(2000 CHAR)&lt;br /&gt;
 MSGEVT_FIL_4                                       VARCHAR2(2000 CHAR)&lt;br /&gt;
 TYPEVT                                             VARCHAR2(5 CHAR)&lt;br /&gt;
 SBP_CODAPP                                         VARCHAR2(10 CHAR)&lt;br /&gt;
 SBP_REFINT                                         VARCHAR2(36 CHAR)&lt;br /&gt;
 SBP_TYPACT                                         VARCHAR2(2 CHAR)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
It exists... but as a table.&amp;lt;br /&amp;gt;&lt;br /&gt;
Something has gone wrong in the database somewhere. As it turns out after some deeper investigation, this database is a copy of production but &amp;quot;with modifications&amp;quot;.&amp;lt;br /&amp;gt;&lt;br /&gt;
After the cloning process, a schema needed renaming. Oracle have a procedure for this but it is very long-winded and time-consuming. It uses export and import with transportable tablespaces to do the remap of the schema.&amp;lt;br /&amp;gt;&lt;br /&gt;
An unsupported workaround to rename schema is to simply update the username in sys.user$ and restart the database.&amp;lt;br /&amp;gt;&lt;br /&gt;
This works for the most part but now we see a consequence of that action.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
col owner      for a30&lt;br /&gt;
col mview_name for a30&lt;br /&gt;
select owner&lt;br /&gt;
,      mview_name&lt;br /&gt;
from   dba_mviews&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
OWNER                          MVIEW_NAME&lt;br /&gt;
------------------------------ ------------------------------&lt;br /&gt;
EPK                            EVD01_NEW&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Ahaa, there&amp;#039;s the materialized view but the owner is different from the one described by the database error message above. This one is the owner as it was on production.&amp;lt;br /&amp;gt;&lt;br /&gt;
This means the owner of materialized views has been denormalised for some reason. Reading the (complex) view text of dba_mviews, we see the owner column is based on sys.snap$.sowner&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
col sowner for a20&lt;br /&gt;
col vname  for a20&lt;br /&gt;
col tname  for a20&lt;br /&gt;
select sowner&lt;br /&gt;
,      vname&lt;br /&gt;
,      tname&lt;br /&gt;
from   sys.snap$&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
SOWNER               VNAME                TNAME&lt;br /&gt;
-------------------- -------------------- --------------------&lt;br /&gt;
EPK                  EVD01_NEW            EVD01_NEW&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
For future reference when updating the username in sys.user$, update the snapshot owner in this table as well!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
update sys.snap$&lt;br /&gt;
set    sowner = &amp;#039;KPK&amp;#039;&lt;br /&gt;
where  sowner = &amp;#039;EPK&amp;#039;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Try again&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
DROP MATERIALIZED VIEW &amp;quot;KPK&amp;quot;.&amp;quot;EVD01_NEW&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
Materialized view dropped.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
yep, and the tablespace?&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
drop tablespace TS_THALER_PART_OLD including contents and datafiles cascade constraints;&lt;br /&gt;
&lt;br /&gt;
Tablespace dropped.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORA-12162: TNS:net service name is incorrectly specified===&lt;br /&gt;
Probably nothing to do with TNS. Check your ORACLE_SID is set correctly!&lt;br /&gt;
&lt;br /&gt;
===ORA-00054: resource busy and acquire with NOWAIT specified===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SELECT O.OBJECT_NAME, S.SID, S.SERIAL#, P.SPID, S.PROGRAM,S.USERNAME,&lt;br /&gt;
S.MACHINE,S.PORT , S.LOGON_TIME,SQ.SQL_FULLTEXT &lt;br /&gt;
FROM V$LOCKED_OBJECT L, DBA_OBJECTS O, V$SESSION S, &lt;br /&gt;
V$PROCESS P, V$SQL SQ &lt;br /&gt;
WHERE L.OBJECT_ID = O.OBJECT_ID &lt;br /&gt;
AND L.SESSION_ID = S.SID AND S.PADDR = P.ADDR &lt;br /&gt;
AND S.SQL_ADDRESS = SQ.ADDRESS;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select object_name, s.sid, s.serial#, p.spid &lt;br /&gt;
from v$locked_object l, dba_objects o, v$session s, v$process p&lt;br /&gt;
where l.object_id = o.object_id and l.session_id = s.sid and s.paddr = p.addr;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
then&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter system kill session &amp;#039;sid,serial#&amp;#039;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORA-12518: TNS:listener could not hand off client connection===&lt;br /&gt;
The database you are trying to connect to is probably on its knees. Check server memory is not exhausted.&lt;br /&gt;
&lt;br /&gt;
===ORA-12520: TNS:listener could not find available handler for requested type of server===&lt;br /&gt;
Strangely this could be related to number of processes being exhausted.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
show parameter processes&lt;br /&gt;
alter system set processes=350 scope=spfile;&lt;br /&gt;
shutdown immediate&lt;br /&gt;
startup&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORA-12541: TNS: no listener===&lt;br /&gt;
Either very basic - start the listener!&amp;lt;br /&amp;gt;&lt;br /&gt;
or, as in our case - not so obvious.&amp;lt;br /&amp;gt;&lt;br /&gt;
We use virtual IP addresses so that the IP address stays the same after failover to standby.&amp;lt;br /&amp;gt;&lt;br /&gt;
Due to some confused configuration, we got the network adapter on two different servers to have the same IP address.&amp;lt;br /&amp;gt;&lt;br /&gt;
Stop the IP address on the bad server (assign another one) and all is fine again.&lt;br /&gt;
===ORA-12514: TNS:listener does not currently know of service===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
lsnrctl status &amp;lt;listener_name&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Been altering tnsnames.ora or listener.ora?&lt;br /&gt;
* Check the local_listener parameter&lt;br /&gt;
Try resetting it to itself. Strange but if you are not using port 1521, this can work wonders!&amp;lt;br /&amp;gt;&lt;br /&gt;
Assuming listener is called LISTENER_WM9T:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter system set local_listener=LISTENER_WM9T scope=both;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Try and connect with the service name or directly with&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sqlplus &amp;#039;sys/*******&amp;#039;@&amp;lt;host&amp;gt;:&amp;lt;port&amp;gt;/&amp;lt;SID&amp;gt; as sysdba&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Excellent description of how Oracle TNS listeners work and a checklist on how to fix this error&amp;lt;br /&amp;gt;&lt;br /&gt;
* [[http://edstevensdba.wordpress.com/2011/03/19/ora-12514/ TNS — Ed Stevens]]&lt;br /&gt;
&lt;br /&gt;
===ORA-12547: TNS lost contact===&lt;br /&gt;
&lt;br /&gt;
If&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sqlplus &amp;lt;user&amp;gt;/&amp;lt;pass&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
fails with above error, try&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sqlplus &amp;lt;user&amp;gt;/&amp;lt;pass&amp;gt;@&amp;lt;db connection&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
If this works, it is most probably a permissions error.&amp;lt;br /&amp;gt;&lt;br /&gt;
Re-run the&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ORACLE_HOME/root.sh&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
script that was run as part of the original installation. This will reset the permissions on some important files.&lt;br /&gt;
===ORA-02374: conversion error loading table &amp;quot;BLENGADM&amp;quot;.&amp;quot;ZZ_EVTCTA&amp;quot;===&lt;br /&gt;
This is typical of importing data with Datapump when the tables in the source database were created with &amp;quot;byte&amp;quot; semantics and the destination is &amp;quot;char&amp;quot; semantics.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ORA-02374: conversion error loading table &amp;quot;BLENGADM&amp;quot;.&amp;quot;ZZ_EVTCTA&amp;quot;&lt;br /&gt;
ORA-12899: value too large for column NOMCTA (actual: 257, maximum: 256)&lt;br /&gt;
&lt;br /&gt;
ORA-02372: data for row: NOMCTA : 0X&amp;#039;4C6976726574206427E9706172676E65202020202020202020&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Problem====&lt;br /&gt;
The root cause is the nls_length_semantics of the table columns being BYTE where one character is assigned one byte. But after conversion in a multi-byte database, one character is larger than one byte (could be 2, 3 or 4) and no longer fits.&lt;br /&gt;
====Solution====&lt;br /&gt;
* import the metadata&lt;br /&gt;
Run the impdp command with content=metadata_only. This will create all the tables (still in their original form) but not the data.&lt;br /&gt;
* alter the BYTE columns in the affected tables to CHAR semantics&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select column_name&lt;br /&gt;
,      char_used&lt;br /&gt;
,      data_length&lt;br /&gt;
,      data_type &lt;br /&gt;
from   user_tab_columns &lt;br /&gt;
where  table_name = &amp;#039;T&amp;#039;&lt;br /&gt;
and    char_used = &amp;#039;B&amp;#039;;&lt;br /&gt;
COLUMN_NAME  C DATA_LENGTH DATA_TYPE&lt;br /&gt;
------------ - ----------- ---------&lt;br /&gt;
X            B           1 VARCHAR2&lt;br /&gt;
SQL&amp;gt; alter table t modify x varchar2(1 char);&lt;br /&gt;
Table altered.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Import the data&lt;br /&gt;
Rerun the impdp ensuring table_exists_action is not REPLACE (use truncate or append). This now imports the data into the modified tables.&lt;br /&gt;
====This script does the donkey work of altering table column semantics from byte to char====&lt;br /&gt;
The author of this script is unknown but he/she deserves a medal. It saves countless hours of work and is so well written.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/*&lt;br /&gt;
  The script converts all the VARCHAR2 columns in the user&amp;#039;s schema&lt;br /&gt;
  to CHAR length semantics. Known to work on 10.2.0.4 and later.&lt;br /&gt;
  &lt;br /&gt;
  Script must be executed against the database without any other client&lt;br /&gt;
  and/or application connections to the affected schema.&lt;br /&gt;
  &lt;br /&gt;
  Oracle does not support CHAR semantics for the built-in schemas,&lt;br /&gt;
  like SYS, SYSTEM or SYSMAN, so the script will throw an error,&lt;br /&gt;
  if attempt to run it against any one of them.&lt;br /&gt;
  &lt;br /&gt;
  Upon completion database objects that have dependencies on tables&lt;br /&gt;
  being modified will be invalidated. Oracle usually re-compiles invalidated&lt;br /&gt;
  objects on the first access. Alternatively, a DBA can execute UTLPRP script&lt;br /&gt;
  to recompile all invalid objects in the entire database.&lt;br /&gt;
  &lt;br /&gt;
  Upon completion, please make sure that NLS_LENGTH_SEMANTICS instance parameter&lt;br /&gt;
  is set to CHAR to ensure further upgradability of the schema.&lt;br /&gt;
*/&lt;br /&gt;
set serveroutput on size unlimited format wrap&lt;br /&gt;
declare&lt;br /&gt;
  type sql_list_t is table of varchar2(32767) index by pls_integer;&lt;br /&gt;
  type idx_list_t is table of user_indexes.index_name%type index by pls_integer;&lt;br /&gt;
  type col_list_t is table of user_tab_columns%rowtype index by pls_integer;&lt;br /&gt;
  --&lt;br /&gt;
  lv_col_cnt   pls_integer := 0;&lt;br /&gt;
  lv_idx_cnt   pls_integer := 0;&lt;br /&gt;
  lv_char_set  pls_integer := 0; &lt;br /&gt;
  lv_user      user_users.username%type;&lt;br /&gt;
  lv_sql_stmt  varchar2(32767);&lt;br /&gt;
  lv_byte_cols col_list_t;&lt;br /&gt;
  lv_idx_names idx_list_t;&lt;br /&gt;
  lv_idx_ddls  sql_list_t;&lt;br /&gt;
  --&lt;br /&gt;
  procedure run_sql_stmt&lt;br /&gt;
  (&lt;br /&gt;
   p_sql_stmt in varchar2&lt;br /&gt;
  )&lt;br /&gt;
  as&lt;br /&gt;
  begin&lt;br /&gt;
    execute immediate p_sql_stmt;&lt;br /&gt;
  exception&lt;br /&gt;
    when others&lt;br /&gt;
    then&lt;br /&gt;
      raise_application_error(-20202, &amp;#039;Failed statement [&amp;#039; || p_sql_stmt || dbms_utility.format_error_backtrace() || &amp;#039;]&amp;#039;, true);&lt;br /&gt;
  end;&lt;br /&gt;
begin&lt;br /&gt;
  --&lt;br /&gt;
  lv_user := user();&lt;br /&gt;
  if lv_user in (&amp;#039;SYS&amp;#039;, &amp;#039;SYSTEM&amp;#039;, &amp;#039;SYSMAN&amp;#039;)&lt;br /&gt;
  then&lt;br /&gt;
    raise_application_error(-20202, &amp;#039;This script cannot be executed against Oracle built-in schema [&amp;#039; || lv_user || &amp;#039;].&amp;#039;);&lt;br /&gt;
  end if;&lt;br /&gt;
  --&lt;br /&gt;
  select&lt;br /&gt;
         *&lt;br /&gt;
         bulk collect into lv_byte_cols&lt;br /&gt;
  from&lt;br /&gt;
         user_tab_columns uc&lt;br /&gt;
  where&lt;br /&gt;
         uc.char_used = &amp;#039;B&amp;#039;&lt;br /&gt;
         and&lt;br /&gt;
         substr(uc.table_name, 1, 4) != &amp;#039;BIN$&amp;#039;&lt;br /&gt;
         and&lt;br /&gt;
         not exists&lt;br /&gt;
         (&lt;br /&gt;
          select 1&lt;br /&gt;
          from   user_views uv&lt;br /&gt;
          where  uv.view_name = uc.table_name&lt;br /&gt;
         )&lt;br /&gt;
  ;&lt;br /&gt;
  --&lt;br /&gt;
  lv_col_cnt := lv_byte_cols.count();&lt;br /&gt;
  --&lt;br /&gt;
  dbms_output.enable();&lt;br /&gt;
  --&lt;br /&gt;
  if lv_col_cnt &amp;gt; 0&lt;br /&gt;
  then&lt;br /&gt;
    for idx_rw in&lt;br /&gt;
    (&lt;br /&gt;
     select index_name &lt;br /&gt;
     from   user_indexes&lt;br /&gt;
     where  index_type = &amp;#039;FUNCTION-BASED NORMAL&amp;#039;&lt;br /&gt;
    )&lt;br /&gt;
    loop&lt;br /&gt;
      lv_idx_cnt := lv_idx_cnt + 1;&lt;br /&gt;
      lv_idx_names(lv_idx_cnt) := idx_rw.index_name;&lt;br /&gt;
      lv_idx_ddls(lv_idx_cnt) := replace&lt;br /&gt;
                                 (&lt;br /&gt;
                                  dbms_metadata.get_ddl&lt;br /&gt;
                                  (&lt;br /&gt;
                                   object_type =&amp;gt; &amp;#039;INDEX&amp;#039;,&lt;br /&gt;
                                   name        =&amp;gt; idx_rw.index_name&lt;br /&gt;
                                  )&lt;br /&gt;
                                  ,&lt;br /&gt;
                                  &amp;#039;;&amp;#039;&lt;br /&gt;
                                 );&lt;br /&gt;
      lv_sql_stmt := &amp;#039;drop index &amp;#039; || idx_rw.index_name;&lt;br /&gt;
      run_sql_stmt(lv_sql_stmt);&lt;br /&gt;
      dbms_output.put_line(&amp;#039;Dropped function-based index: &amp;#039; || idx_rw.index_name);&lt;br /&gt;
      dbms_output.put_line(&amp;#039;In case of script failure, restore the index by running the DDL statement below:&amp;#039;);&lt;br /&gt;
      dbms_output.put_line(lv_idx_ddls(lv_idx_cnt) || &amp;#039;;&amp;#039;);&lt;br /&gt;
    end loop;&lt;br /&gt;
    --&lt;br /&gt;
    for i in 1..lv_col_cnt&lt;br /&gt;
    loop&lt;br /&gt;
      lv_sql_stmt :=  &amp;#039;alter table &amp;#039; || lv_byte_cols(i).table_name || &amp;#039; modify (&amp;#039; ||&lt;br /&gt;
                      lv_byte_cols(i).column_name || &amp;#039; &amp;#039; || lv_byte_cols(i).data_type ||&lt;br /&gt;
                      &amp;#039;(&amp;#039; || lv_byte_cols(i).char_length || &amp;#039; char))&amp;#039;;&lt;br /&gt;
      run_sql_stmt(lv_sql_stmt);&lt;br /&gt;
    end loop;&lt;br /&gt;
    --&lt;br /&gt;
    dbms_output.new_line();&lt;br /&gt;
    for i in 1..lv_idx_cnt&lt;br /&gt;
    loop&lt;br /&gt;
      run_sql_stmt(lv_idx_ddls(i));&lt;br /&gt;
      dbms_output.put_line(&amp;#039;Recreated function-based index: &amp;#039; || lv_idx_names(i));&lt;br /&gt;
    end loop;&lt;br /&gt;
    --&lt;br /&gt;
    dbms_output.new_line();&lt;br /&gt;
    dbms_output.put_line&lt;br /&gt;
    (&lt;br /&gt;
     &amp;#039;Updated length semantics to CHAR for &amp;#039; || lv_col_cnt || &amp;#039; column&amp;#039; ||&lt;br /&gt;
     case when lv_col_cnt &amp;gt; 1&lt;br /&gt;
          then &amp;#039;s&amp;#039;&lt;br /&gt;
     end ||&lt;br /&gt;
     &amp;#039; in the schema [&amp;#039; || lv_user || &amp;#039;].&amp;#039;&lt;br /&gt;
    );&lt;br /&gt;
  else&lt;br /&gt;
    dbms_output.put_line(&amp;#039;No columns with BYTE length semantics were found in the schema [&amp;#039; || lv_user || &amp;#039;].&amp;#039;);&lt;br /&gt;
  end if;&lt;br /&gt;
  --&lt;br /&gt;
  select count(*) into lv_char_set&lt;br /&gt;
  from   nls_session_parameters&lt;br /&gt;
  where  parameter = &amp;#039;NLS_LENGTH_SEMANTICS&amp;#039;&lt;br /&gt;
         and&lt;br /&gt;
         value = &amp;#039;CHAR&amp;#039;&lt;br /&gt;
  ;&lt;br /&gt;
  --&lt;br /&gt;
  if lv_char_set = 0&lt;br /&gt;
  then&lt;br /&gt;
    dbms_output.put_line(&amp;#039;WARNING: Do not forget to change instance parameter NLS_LENGTH_SEMANTICS to CHAR and restart the database.&amp;#039;);&lt;br /&gt;
  end if;&lt;br /&gt;
end;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORA-14097: column type or size mismatch in ALTER TABLE EXCHANGE PARTITION===&lt;br /&gt;
Also can be &amp;lt;tt&amp;gt;ORA-54033: column to be modified is used in a virtual column expression&amp;lt;/tt&amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;
Nothing especially to do with partitions - just any ddl operation that affects the table.&amp;lt;br /&amp;gt;&lt;br /&gt;
Hidden columns do not normally show up in a desc unless colinvisible is on&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set colinvisible on&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
But these sneaky system-generated ones don&amp;#039;t show up even with that setting on!  You need to show them with this:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set pages 50 lines 1000&lt;br /&gt;
col column_name for a40&lt;br /&gt;
col data_default for a40&lt;br /&gt;
select column_id&lt;br /&gt;
,      column_name&lt;br /&gt;
,      data_default&lt;br /&gt;
,      user_generated&lt;br /&gt;
,      hidden_column&lt;br /&gt;
,      virtual_column&lt;br /&gt;
,      identity_column&lt;br /&gt;
from   dba_tab_cols&lt;br /&gt;
where  owner      = upper(&amp;#039;&amp;amp;owner.&amp;#039;)&lt;br /&gt;
and    table_name = upper(&amp;#039;&amp;amp;table_name.&amp;#039;)&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
INTERNAL_COLUMN_ID COLUMN_NAME                                        DATA_DEFAULT                                       HIDDEN_COLUM VIRTUAL_COLU&lt;br /&gt;
------------------ -------------------------------------------------- -------------------------------------------------- ------------ ------------&lt;br /&gt;
                35 MONLOT_REC_CDR                                     &amp;#039;0&amp;#039;                                                NO           NO&lt;br /&gt;
                34 MONLOT_REC_DBT                                     &amp;#039;0&amp;#039;                                                NO           NO&lt;br /&gt;
                33 MONLOT_CAL_CDR                                     &amp;#039;0&amp;#039;                                                NO           NO&lt;br /&gt;
                32 MONLOT_CAL_DBT                                     &amp;#039;0&amp;#039;                                                NO           NO&lt;br /&gt;
                31 MONMVT_CPT                                         &amp;#039;0&amp;#039;                                                NO           NO&lt;br /&gt;
                30 SENNOT                                             &amp;#039; &amp;#039;                                                NO           NO&lt;br /&gt;
                29 NUMSEQ                                                                                                NO           NO&lt;br /&gt;
                28 NOMFIC                                                                                                NO           NO&lt;br /&gt;
                27 TOTCPT_REC                                                                                            NO           NO&lt;br /&gt;
                26 TOTCPT_CAL                                                                                            NO           NO&lt;br /&gt;
                25 MONLOT_REC                                                                                            NO           NO&lt;br /&gt;
                24 MONLOT_CAL                                                                                            NO           NO&lt;br /&gt;
                23 NBRELE_REC                                                                                            NO           NO&lt;br /&gt;
                22 NBRELE_CAL                                                                                            NO           NO&lt;br /&gt;
                21 NUMCPT_GLO                                                                                            NO           NO&lt;br /&gt;
                20 DEVLOT                                                                                                NO           NO&lt;br /&gt;
                19 CODERR                                                                                                NO           NO&lt;br /&gt;
                18 CANLOT                                                                                                NO           NO&lt;br /&gt;
                17 REFTEX                                                                                                NO           NO&lt;br /&gt;
                16 REFEXN                                                                                                NO           NO&lt;br /&gt;
                15 ETTLOT                                                                                                NO           NO&lt;br /&gt;
                14 TYPLOT                                                                                                NO           NO&lt;br /&gt;
                13 DATEXC                                                                                                NO           NO&lt;br /&gt;
                12 STALOT                                                                                                NO           NO&lt;br /&gt;
                11 REFLOT                                                                                                NO           NO&lt;br /&gt;
                10 USRAUT                                                                                                NO           NO&lt;br /&gt;
                 9 HEUAUT                                                                                                NO           NO&lt;br /&gt;
                 8 DATAUT                                                                                                NO           NO&lt;br /&gt;
                 7 PGMMAJ                                                                                                NO           NO&lt;br /&gt;
                 6 USRMAJ                                                                                                NO           NO&lt;br /&gt;
                 5 HEUMAJ                                                                                                NO           NO&lt;br /&gt;
                 4 DATMAJ                                                                                                NO           NO&lt;br /&gt;
                 3 DATCRT                                                                                                NO           NO&lt;br /&gt;
                 2 REFMAJ                                                                                                NO           NO&lt;br /&gt;
                 1 NUMVER                                                                                                NO           NO&lt;br /&gt;
                36 SYS_STS#KR2WNV5L070XKV1L5H7REH                     SYS_OP_COMBINED_HASH(&amp;quot;NOMFIC&amp;quot;,&amp;quot;NUMSEQ&amp;quot;)            YES          YES&lt;br /&gt;
&lt;br /&gt;
36 rows selected.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
That last row means extended statistics have been generated for 2 columns in this table.&amp;lt;br /&amp;gt;&lt;br /&gt;
You can see this because the name begins with SYS_STS. If it begins with SYS_&amp;lt;something else&amp;gt; then it is not extended statistics.&amp;lt;br /&amp;gt;&lt;br /&gt;
It may be an unused column. Original [https://dba.stackexchange.com/questions/196248/what-is-the-sys-c00054-140314103403-column-in-my-regular-oracle-table here]&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
create table t1 as select * from dba_roles;&lt;br /&gt;
&lt;br /&gt;
Table created.&lt;br /&gt;
&lt;br /&gt;
desc t1&lt;br /&gt;
 Name                                      Null?    Type&lt;br /&gt;
 ----------------------------------------- -------- ----------------------------&lt;br /&gt;
 ROLE                                      NOT NULL VARCHAR2(30)&lt;br /&gt;
 PASSWORD_REQUIRED                                  VARCHAR2(8)&lt;br /&gt;
 AUTHENTICATION_TYPE                                VARCHAR2(11)&lt;br /&gt;
&lt;br /&gt;
alter table t1 set unused (AUTHENTICATION_TYPE);&lt;br /&gt;
&lt;br /&gt;
Table altered.&lt;br /&gt;
&lt;br /&gt;
desc t1&lt;br /&gt;
 Name                                      Null?    Type&lt;br /&gt;
 ----------------------------------------- -------- ----------------------------&lt;br /&gt;
 ROLE                                      NOT NULL VARCHAR2(30)&lt;br /&gt;
 PASSWORD_REQUIRED                                  VARCHAR2(8)&lt;br /&gt;
&lt;br /&gt;
select column_name from dba_tab_cols where owner = &amp;#039;&amp;amp;owner.&amp;#039; and table_name = &amp;#039;&amp;amp;table_name.&amp;#039;;&lt;br /&gt;
&lt;br /&gt;
COLUMN_NAME&lt;br /&gt;
------------------------------&lt;br /&gt;
SYS_C00003_18012517:25:39$&lt;br /&gt;
PASSWORD_REQUIRED&lt;br /&gt;
ROLE&lt;br /&gt;
&lt;br /&gt;
SQL&amp;gt; alter table t1 drop unused columns;&lt;br /&gt;
&lt;br /&gt;
Table altered.&lt;br /&gt;
&lt;br /&gt;
select column_name from dba_tab_cols where owner = &amp;#039;&amp;amp;owner.&amp;#039; and table_name = &amp;#039;&amp;amp;table_name.&amp;#039;;&lt;br /&gt;
&lt;br /&gt;
COLUMN_NAME&lt;br /&gt;
------------------------------&lt;br /&gt;
PASSWORD_REQUIRED&lt;br /&gt;
ROLE&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Solution====&lt;br /&gt;
Drop the extended stats, do what you need to do and recreate the extended stats.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
PROCEDURE DROP_EXTENDED_STATS&lt;br /&gt;
 Argument Name                  Type                    In/Out Default?&lt;br /&gt;
 ------------------------------ ----------------------- ------ --------&lt;br /&gt;
 OWNNAME                        VARCHAR2                IN&lt;br /&gt;
 TABNAME                        VARCHAR2                IN&lt;br /&gt;
 EXTENSION                      VARCHAR2                IN&lt;br /&gt;
&lt;br /&gt;
exec dbms_stats.drop_extended_stats ( &amp;#039;KPK&amp;#039;, &amp;#039;XND40&amp;#039;, &amp;#039;(&amp;quot;NOMFIC&amp;quot;,&amp;quot;NUMSEQ&amp;quot;)&amp;#039; );&lt;br /&gt;
&lt;br /&gt;
create table kpk.xnd40_new as select * from kpk.xnd40 where 1=2;&lt;br /&gt;
&lt;br /&gt;
Table created.&lt;br /&gt;
&lt;br /&gt;
select dbms_stats.create_extended_stats ( &amp;#039;KPK&amp;#039;, &amp;#039;XND40&amp;#039;, &amp;#039;(&amp;quot;NOMFIC&amp;quot;,&amp;quot;NUMSEQ&amp;quot;)&amp;#039; ) from   dual;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The stats columns can also be seen in their own table&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 1000 pages 100&lt;br /&gt;
col owner for a6&lt;br /&gt;
col table_name for a20&lt;br /&gt;
col extension_name  for a40&lt;br /&gt;
col extension  for a50&lt;br /&gt;
select owner, table_name, extension_name, extension, creator, droppable from dba_stat_extensions where owner = upper(&amp;#039;&amp;amp;&amp;amp;owner.&amp;#039;) and table_name = upper(&amp;#039;&amp;amp;&amp;amp;table_name.&amp;#039;) and extension_name LIKE &amp;#039;SYS_STS%&amp;#039;;&lt;br /&gt;
&lt;br /&gt;
OWNER TABLE_NAME           EXTENSION_NAME                           EXTENSION                                          CREATOR                  DROPPABLE&lt;br /&gt;
----- -------------------- ---------------------------------------- -------------------------------------------------- ------------------------ ------------&lt;br /&gt;
KPK   XMD01                SYS_STSOA4UXZDBW7MIV5OOR8VOHHK           (&amp;quot;DATCRT&amp;quot;,&amp;quot;CODJRN&amp;quot;)                                SYSTEM                   YES&lt;br /&gt;
KPK   XDD02                SYS_STSFJCZYRZBCQL820ADIR0Y4RZ           (&amp;quot;REFMSG&amp;quot;,&amp;quot;CPTTIT&amp;quot;,&amp;quot;TYPMSG&amp;quot;)                       SYSTEM                   YES&lt;br /&gt;
KPK   XCD09                SYS_STS2OIO647GN0_UV$XO583KKKJ           (&amp;quot;DATCRT&amp;quot;,&amp;quot;HEUMAJ&amp;quot;,&amp;quot;STAMOD&amp;quot;)                       SYSTEM                   YES&lt;br /&gt;
KPK   XCD09                SYS_STS_BRDODC6DJG_HXK0#O9BOYF           (&amp;quot;STAMOD&amp;quot;,&amp;quot;CODMOD&amp;quot;)                                SYSTEM                   YES&lt;br /&gt;
KPK   XCD09                SYS_STS2#DY5U$WQG6COVHB##H2ESK           (&amp;quot;DATMAJ&amp;quot;,&amp;quot;STAMOD&amp;quot;,&amp;quot;CODMOD&amp;quot;)                       SYSTEM                   YES&lt;br /&gt;
KPK   XCD09                SYS_STSO7#D3DI5R8_VAF$WJ32D8MT           (&amp;quot;STAMOD&amp;quot;,&amp;quot;KEYREF_1&amp;quot;)                              SYSTEM                   YES&lt;br /&gt;
KPK   XCD09                SYS_STS4FRY10M34S2L$0FDM1N4B18           (&amp;quot;STAMOD&amp;quot;,&amp;quot;IDTMOD&amp;quot;)                                SYSTEM                   YES&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORA-14404: partitioned table contains partitions in a different tablespace===&lt;br /&gt;
As part of an RMAN duplicate with a skip tablespace, this error is produced&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Reenabling controlfile options for auxiliary database&lt;br /&gt;
Executing: alter database enable block change tracking using file &amp;#039;/oracle/acc/ora_data3/adsa1/bct_adsp_do_not_delete.f&amp;#039;&lt;br /&gt;
&lt;br /&gt;
contents of Memory Script:&lt;br /&gt;
{&lt;br /&gt;
   Alter clone database open resetlogs;&lt;br /&gt;
}&lt;br /&gt;
executing Memory Script&lt;br /&gt;
&lt;br /&gt;
database opened&lt;br /&gt;
Dropping offline and skipped tablespaces&lt;br /&gt;
Executing: drop tablespace &amp;quot;ADS_ARCHIVE&amp;quot; including contents cascade constraints&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-03002: failure of Duplicate Db command at 10/16/2017 23:46:12&lt;br /&gt;
RMAN-05501: aborting duplication of target database&lt;br /&gt;
RMAN-06136: ORACLE error from auxiliary database: ORA-14404: partitioned table contains partitions in a different tablespace&lt;br /&gt;
&lt;br /&gt;
Recovery Manager complete.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
and when attempting to backup the database, we get errors&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
RMAN-06169: could not read file header for datafile 188 error reason 1&lt;br /&gt;
RMAN-06169: could not read file header for datafile 189 error reason 1&lt;br /&gt;
RMAN-06169: could not read file header for datafile 190 error reason 1&lt;br /&gt;
RMAN-06169: could not read file header for datafile 191 error reason 1&lt;br /&gt;
RMAN-06169: could not read file header for datafile 14 error reason 1&lt;br /&gt;
released channel: t1&lt;br /&gt;
released channel: t2&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-03002: failure of backup plus archivelog command at 10/17/2017 15:08:40&lt;br /&gt;
RMAN-06056: could not access datafile 14&lt;br /&gt;
&lt;br /&gt;
Recovery Manager complete.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Problem====&lt;br /&gt;
Tables in the tablespace have partitions in another tablespace so this one cannot be dropped.&amp;lt;br /&amp;gt;&lt;br /&gt;
Check which table partitions are in which tablespaces&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 200&lt;br /&gt;
set pagesize 200&lt;br /&gt;
col table_name for a14&lt;br /&gt;
col table_owner for a14&lt;br /&gt;
col partition_name for a14&lt;br /&gt;
select table_owner&lt;br /&gt;
,      table_name&lt;br /&gt;
,      partition_name&lt;br /&gt;
,      tablespace_name&lt;br /&gt;
from   dba_tab_partitions&lt;br /&gt;
where  (table_owner, table_name) in&lt;br /&gt;
       (&lt;br /&gt;
       select table_owner&lt;br /&gt;
       ,      table_name&lt;br /&gt;
       from   dba_tab_partitions x&lt;br /&gt;
       where  x.tablespace_name = &amp;#039;&amp;amp;&amp;amp;TABLESPACE_TO_DROP&amp;#039;&lt;br /&gt;
       and    exists ( select *&lt;br /&gt;
                       from   dba_tab_partitions y&lt;br /&gt;
                       where  x.table_owner = y.table_owner&lt;br /&gt;
                       and    x.table_name  = y.table_name&lt;br /&gt;
                       and    y.tablespace_name not in (&amp;#039;&amp;amp;TABLESPACE_TO_DROP&amp;#039;)&lt;br /&gt;
                       group  by table_owner&lt;br /&gt;
                       ,      table_name&lt;br /&gt;
                     )&lt;br /&gt;
        )&lt;br /&gt;
order by 1,2,partition_position&lt;br /&gt;
/&lt;br /&gt;
undef TABLESPACE_TO_DROP&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
TABLE_OWNER    TABLE_NAME     PARTITION_NAME TABLESPACE_NAME&lt;br /&gt;
-------------- -------------- -------------- ------------------------------&lt;br /&gt;
KPK            XND20          P0910          TS_THALER_PART_OLD&lt;br /&gt;
KPK            XND20          P1112          TS_THALER_PART_OLD&lt;br /&gt;
KPK            XND20          P13            TS_THALER_PART_OLD&lt;br /&gt;
KPK            XND20          P14            TS_THALER_PART_OLD&lt;br /&gt;
KPK            XND20          P15            TS_THALER_PART_OLD&lt;br /&gt;
KPK            XND20          P16            TS_THALER_DATA&lt;br /&gt;
KPK            XND20          P17            TS_THALER_DATA&lt;br /&gt;
KPK            XND20          P18            TS_THALER_DATA&lt;br /&gt;
KPK            XND20          PMAX           TS_THALER_DATA&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Solution====&lt;br /&gt;
If the intention is to keep all the tables then run this query to generate statements to move the relevant tables out of this tablespace&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select &amp;#039;alter table &amp;#039;||b.table_owner||&amp;#039;.&amp;#039;||b.table_name||&amp;#039; move partition &amp;#039;||b.partition_name||&amp;#039; tablespace &amp;amp;NEW_TABLESPACE;&amp;#039;&lt;br /&gt;
from   (&lt;br /&gt;
       select distinct table_name&lt;br /&gt;
       ,      partition_name&lt;br /&gt;
       from   dba_tab_partitions&lt;br /&gt;
       where  tablespace_name = &amp;#039;&amp;amp;&amp;amp;TABLESPACE_NAME&amp;#039;&lt;br /&gt;
       )                  a&lt;br /&gt;
,      dba_tab_partitions b&lt;br /&gt;
where  a.table_name       = b.table_name&lt;br /&gt;
and    b.tablespace_name != &amp;#039;&amp;amp;TABLESPACE_NAME&amp;#039;&lt;br /&gt;
/&lt;br /&gt;
undef TABLESPACE_NAME&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
If however, the intention is to drop the tablespace anyway, the tables need to be dropped before the tablespace can be dropped.&amp;lt;br /&amp;gt;&lt;br /&gt;
But ...tables with partitions in different tablespaces cannot be dropped. The partitions need to be dropped first!&amp;lt;br /&amp;gt;&lt;br /&gt;
Run the following query to generate statements to drop all the &amp;#039;problem&amp;#039; tables. When these have gone, the tablespace can be dropped.&lt;br /&gt;
* drop table partitions&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
spool /tmp/drop_table_partitions.sql&lt;br /&gt;
sqlplus / as sysdba&amp;lt;&amp;lt;EOSQL&lt;br /&gt;
set headi off newpa none feedb off trims on echo off&lt;br /&gt;
select &amp;#039;alter table &amp;#039;||table_owner||&amp;#039;.&amp;#039;||table_name||&amp;#039; drop partition &amp;#039;||partition_name||&amp;#039;;&amp;#039;&lt;br /&gt;
from   dba_tab_partitions&lt;br /&gt;
where  tablespace_name = &amp;#039;$TABLESPACE_NAME&amp;#039;&lt;br /&gt;
/&lt;br /&gt;
spool off&lt;br /&gt;
EOSQL&lt;br /&gt;
echo &amp;quot;@/tmp/drop_table_partitions.sql&amp;quot; | sqlplus / as sysdba&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* drop tables&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sqlplus / as sysdba&amp;lt;&amp;lt;EOSQL&lt;br /&gt;
select &amp;#039;drop table &amp;#039;||table_owner||&amp;#039;.&amp;#039;||table_name||&amp;#039;;&amp;#039;&lt;br /&gt;
from   dba_tab_partitions&lt;br /&gt;
where  tablespace_name = &amp;#039;$TABLESPACE_NAME&amp;#039;&lt;br /&gt;
spool /tmp/drop_tables.sql&lt;br /&gt;
/&lt;br /&gt;
spool off&lt;br /&gt;
EOSQL&lt;br /&gt;
echo &amp;quot;@/tmp/drop_tables.sql&amp;quot; | sqlplus / as sysdba&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* drop tablespace&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
drop tablespace ads_archive including contents and datafiles&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Find all table partitions in tablespaces with missing datafiles====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 1000 pages 100&lt;br /&gt;
col owner for a10&lt;br /&gt;
col segment_name for a40&lt;br /&gt;
col segment_type for a25&lt;br /&gt;
col partition_name for a20&lt;br /&gt;
col tablespace_name for a25&lt;br /&gt;
select owner&lt;br /&gt;
,      segment_name&lt;br /&gt;
,      segment_type&lt;br /&gt;
,      partition_name&lt;br /&gt;
,      tablespace_name&lt;br /&gt;
from   dba_segments&lt;br /&gt;
where  segment_type in (&amp;#039;TABLE PARTITION&amp;#039;, &amp;#039;TABLE SUBPARTITION&amp;#039;)&lt;br /&gt;
and    tablespace_name in (&lt;br /&gt;
                          select tablespace_name&lt;br /&gt;
                          from   dba_data_files&lt;br /&gt;
                          where  file_name like &amp;#039;%MISSING%&amp;#039;&lt;br /&gt;
                          )&lt;br /&gt;
order  by 1, 2, decode (segment_type, &amp;#039;TABLE SUBPARTITION&amp;#039;, 1, 2),4&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Use exchange partition to alter metadata of the tablespaces without moving the actual data====&lt;br /&gt;
* [https://community.oracle.com/message/2166242#2166242 this] is an explanation of what you are looking for!&amp;lt;br /&amp;gt;&lt;br /&gt;
This is a way of doing the exchange with a neat PL/SQL procedure. It might not do what you want though so understand it before running it!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set serveroutput on size unlimited&lt;br /&gt;
DECLARE&lt;br /&gt;
  dummy_table                   VARCHAR2 (128);&lt;br /&gt;
  cmd                           VARCHAR2 (2048);&lt;br /&gt;
  currowner                     dba_part_tables.owner%TYPE;&lt;br /&gt;
  currtable                     dba_part_tables.table_name%TYPE;&lt;br /&gt;
  l_subpartitioning_type        dba_part_tables.subpartitioning_type%TYPE;&lt;br /&gt;
  l_def_subpartition_count      dba_part_tables.def_subpartition_count%TYPE;&lt;br /&gt;
  l_subpartitioning_key_count   dba_part_tables.subpartitioning_key_count%TYPE;&lt;br /&gt;
  l_curr_qual_table             VARCHAR2 (128);&lt;br /&gt;
&lt;br /&gt;
  PROCEDURE execsql (p_sql IN VARCHAR2)&lt;br /&gt;
  IS&lt;br /&gt;
  BEGIN&lt;br /&gt;
    DBMS_OUTPUT.put_line (p_sql); &lt;br /&gt;
    EXECUTE IMMEDIATE p_sql;&lt;br /&gt;
  END;&lt;br /&gt;
 &lt;br /&gt;
  PROCEDURE force_drop_table (p_table_name IN VARCHAR2)&lt;br /&gt;
  IS&lt;br /&gt;
  BEGIN&lt;br /&gt;
    execsql (&amp;#039;drop table &amp;#039; || p_table_name || &amp;#039; purge&amp;#039;);&lt;br /&gt;
  EXCEPTION&lt;br /&gt;
    WHEN OTHERS&lt;br /&gt;
    THEN&lt;br /&gt;
      NULL;&lt;br /&gt;
  END;&lt;br /&gt;
 &lt;br /&gt;
  PROCEDURE exchange_partition (p_from_table       IN VARCHAR2,&lt;br /&gt;
                                p_from_partition   IN VARCHAR2,&lt;br /&gt;
                                p_to_table         IN VARCHAR2)&lt;br /&gt;
  IS&lt;br /&gt;
  BEGIN&lt;br /&gt;
    execsql (&lt;br /&gt;
         &amp;#039;alter table &amp;#039;&lt;br /&gt;
      || p_from_table&lt;br /&gt;
      || &amp;#039; exchange partition &amp;#039;&lt;br /&gt;
      || p_from_partition&lt;br /&gt;
      || &amp;#039; with table &amp;#039;&lt;br /&gt;
      || p_to_table&lt;br /&gt;
      || &amp;#039; excluding indexes&amp;#039;);&lt;br /&gt;
  END;&lt;br /&gt;
 &lt;br /&gt;
  PROCEDURE drop_partition (p_table IN VARCHAR2, p_partition IN VARCHAR2)&lt;br /&gt;
  IS&lt;br /&gt;
  BEGIN&lt;br /&gt;
    execsql (&amp;#039;alter table &amp;#039; || p_table || &amp;#039; drop partition &amp;#039; || p_partition);&lt;br /&gt;
  END;&lt;br /&gt;
BEGIN&lt;br /&gt;
  currowner := &amp;#039;.&amp;#039;;&lt;br /&gt;
  currtable := &amp;#039;.&amp;#039;;&lt;br /&gt;
 &lt;br /&gt;
  FOR asegment&lt;br /&gt;
    IN (  SELECT owner,&lt;br /&gt;
                 segment_name,&lt;br /&gt;
                 segment_type,&lt;br /&gt;
                 partition_name&lt;br /&gt;
            FROM dba_segments&lt;br /&gt;
           WHERE     segment_type IN (&amp;#039;TABLE PARTITION&amp;#039;, &amp;#039;TABLE SUBPARTITION&amp;#039;)&lt;br /&gt;
                 AND tablespace_name IN (SELECT tablespace_name&lt;br /&gt;
                                           FROM dba_data_files&lt;br /&gt;
                                          WHERE file_name LIKE &amp;#039;%MISSING%&amp;#039;)&lt;br /&gt;
        ORDER BY 1,&lt;br /&gt;
                 2,&lt;br /&gt;
                 DECODE (segment_type, &amp;#039;TABLE SUBPARTITION&amp;#039;, 1, 2),&lt;br /&gt;
                 4)&lt;br /&gt;
  LOOP&lt;br /&gt;
    BEGIN&lt;br /&gt;
      IF currowner &amp;lt;&amp;gt; asegment.owner OR currtable &amp;lt;&amp;gt; asegment.segment_name&lt;br /&gt;
      THEN&lt;br /&gt;
        currowner := asegment.owner;&lt;br /&gt;
        currtable := asegment.segment_name;&lt;br /&gt;
        l_curr_qual_table := asegment.owner || &amp;#039;.&amp;#039; || asegment.segment_name;&lt;br /&gt;
        dummy_table := asegment.owner || &amp;#039;.TBR_EXCHANGE_DUMMY&amp;#039;;&lt;br /&gt;
 &lt;br /&gt;
        force_drop_table (dummy_table);&lt;br /&gt;
 &lt;br /&gt;
        IF asegment.segment_type = &amp;#039;TABLE SUBPARTITION&amp;#039;&lt;br /&gt;
        THEN&lt;br /&gt;
          cmd := &amp;#039;create table &amp;#039; || dummy_table || &amp;#039; partition by &amp;#039;;&lt;br /&gt;
 &lt;br /&gt;
          SELECT subpartitioning_type,&lt;br /&gt;
                 def_subpartition_count,&lt;br /&gt;
                 subpartitioning_key_count&lt;br /&gt;
            INTO l_subpartitioning_type,&lt;br /&gt;
                 l_def_subpartition_count,&lt;br /&gt;
                 l_subpartitioning_key_count&lt;br /&gt;
            FROM dba_part_tables&lt;br /&gt;
           WHERE     owner = asegment.owner&lt;br /&gt;
                 AND table_name = asegment.segment_name;&lt;br /&gt;
 &lt;br /&gt;
          cmd := cmd || l_subpartitioning_type || &amp;#039;(&amp;#039;;&lt;br /&gt;
 &lt;br /&gt;
          FOR asubpartkey&lt;br /&gt;
            IN (  SELECT column_position, column_name&lt;br /&gt;
                    FROM dba_subpart_key_columns&lt;br /&gt;
                   WHERE     owner = asegment.owner&lt;br /&gt;
                         AND name = asegment.segment_name&lt;br /&gt;
                         AND object_type = &amp;#039;TABLE&amp;#039;&lt;br /&gt;
                ORDER BY column_position)&lt;br /&gt;
          LOOP&lt;br /&gt;
            IF asubpartkey.column_position &amp;gt; 1&lt;br /&gt;
            THEN&lt;br /&gt;
              cmd := cmd || &amp;#039;,&amp;#039;;&lt;br /&gt;
            END IF;&lt;br /&gt;
 &lt;br /&gt;
            cmd := cmd || asubpartkey.column_name;&lt;br /&gt;
          END LOOP;&lt;br /&gt;
 &lt;br /&gt;
          cmd := cmd || &amp;#039;) partitions (&amp;#039;;&lt;br /&gt;
 &lt;br /&gt;
          FOR partnr IN 1 .. l_def_subpartition_count&lt;br /&gt;
          LOOP&lt;br /&gt;
            IF partnr &amp;gt; 1&lt;br /&gt;
            THEN&lt;br /&gt;
              cmd := cmd || &amp;#039;,&amp;#039;;&lt;br /&gt;
            END IF;&lt;br /&gt;
 &lt;br /&gt;
            cmd := cmd || &amp;#039;partition p&amp;#039; || partnr;&lt;br /&gt;
          END LOOP;&lt;br /&gt;
 &lt;br /&gt;
          cmd :=&lt;br /&gt;
            cmd || &amp;#039;) as select * from &amp;#039; || l_curr_qual_table || &amp;#039; where 1=0&amp;#039;;&lt;br /&gt;
          execsql (cmd);&lt;br /&gt;
        ELSE&lt;br /&gt;
          execsql (&lt;br /&gt;
               &amp;#039;create table &amp;#039;&lt;br /&gt;
            || dummy_table&lt;br /&gt;
            || &amp;#039; as select * from &amp;#039;&lt;br /&gt;
            || l_curr_qual_table&lt;br /&gt;
            || &amp;#039; where 1=0&amp;#039;);&lt;br /&gt;
        END IF;&lt;br /&gt;
      END IF;&lt;br /&gt;
 &lt;br /&gt;
      exchange_partition (l_curr_qual_table,&lt;br /&gt;
                          asegment.partition_name,&lt;br /&gt;
                          dummy_table);&lt;br /&gt;
 &lt;br /&gt;
      drop_partition (l_curr_qual_table, asegment.partition_name);&lt;br /&gt;
    EXCEPTION&lt;br /&gt;
      WHEN OTHERS&lt;br /&gt;
      THEN&lt;br /&gt;
        DBMS_OUTPUT.put_line (&lt;br /&gt;
          asegment.owner || &amp;#039;.&amp;#039; || asegment.segment_name || &amp;#039; &amp;#039; || SQLERRM);&lt;br /&gt;
    END;&lt;br /&gt;
  END LOOP;&lt;br /&gt;
 &lt;br /&gt;
  IF dummy_table IS NOT NULL&lt;br /&gt;
  THEN&lt;br /&gt;
    force_drop_table (dummy_table);&lt;br /&gt;
  END IF;&lt;br /&gt;
 &lt;br /&gt;
  FOR atablespace IN (  SELECT DISTINCT tablespace_name&lt;br /&gt;
                          FROM dba_data_files&lt;br /&gt;
                         WHERE file_name LIKE &amp;#039;%MISSING%&amp;#039;&lt;br /&gt;
                      ORDER BY 1)&lt;br /&gt;
  LOOP&lt;br /&gt;
    execsql (&lt;br /&gt;
         &amp;#039;drop tablespace &amp;#039;&lt;br /&gt;
      || atablespace.tablespace_name&lt;br /&gt;
      || &amp;#039; including contents and datafiles&amp;#039;);&lt;br /&gt;
  END LOOP;&lt;br /&gt;
END;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Workaround====&lt;br /&gt;
While working on the solution, a backup can be made using the &amp;quot;skip inaccessible&amp;quot; option. Put this in an rman cmdfile...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
connect catalog rmanusr/rmanpwd@rmancat&lt;br /&gt;
connect target sys/syspwd@adsa1&lt;br /&gt;
run {&lt;br /&gt;
allocate channel t1 type &amp;#039;sbt_tape&amp;#039; parms &amp;#039;ENV=(NSR_SERVER=hn6000.company.be,NSR_CLIENT=hn491,NSR_DATA_VOLUME_POOL=DD1DAILY,NSR_END_ERROR_IGNORE=TRUE)&amp;#039;;&lt;br /&gt;
allocate channel t2 type &amp;#039;sbt_tape&amp;#039; parms &amp;#039;ENV=(NSR_SERVER=hn6000.company.be,NSR_CLIENT=hn491,NSR_DATA_VOLUME_POOL=DD1DAILY,NSR_END_ERROR_IGNORE=TRUE)&amp;#039;;&lt;br /&gt;
configure retention policy to recovery window of 28 days;&lt;br /&gt;
configure controlfile autobackup on;&lt;br /&gt;
crosscheck archivelog all;&lt;br /&gt;
SQL &amp;#039;ALTER SYSTEM SWITCH LOGFILE&amp;#039;;&lt;br /&gt;
SQL &amp;#039;CREATE PFILE FROM SPFILE&amp;#039;;&lt;br /&gt;
backup filesperset 1 format &amp;#039;dbfull_%d_%I_%t_%s_%p&amp;#039; full database plus archivelog skip inaccessible delete all input;&lt;br /&gt;
backup current controlfile;&lt;br /&gt;
release channel t1;&lt;br /&gt;
release channel t2;&lt;br /&gt;
}&lt;br /&gt;
exit&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Another way of deleting the offending objects====&lt;br /&gt;
Taken from [http://www.dbarj.com.br/en/2015/01/resume-oracle-duplicate-database-failed-recovery-datafiles/ Recover from a failed RMAN duplicate]&amp;lt;br /&amp;gt;&lt;br /&gt;
Need to check it before running it blindly!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
set echo off feed off termo off trims on pages 0 newpa none lines 2000 headi off long 32000&lt;br /&gt;
col val for a1000&lt;br /&gt;
spool destroy_offending_objects.sql&lt;br /&gt;
&lt;br /&gt;
select to_clob (&amp;#039;alter table &amp;#039;|| table_name||&amp;#039; drop constraint &amp;#039;||constraint_name||&amp;#039;;&amp;#039;) Val&lt;br /&gt;
from user_constraints where constraint_type in (&amp;#039;R&amp;#039;,&amp;#039;P&amp;#039;) and table_name in (select distinct table_name from user_tab_partitions)&lt;br /&gt;
union all&lt;br /&gt;
select to_clob (&amp;#039;drop index &amp;#039;||index_name||&amp;#039;;&amp;#039;) Val from user_indexes where table_name in (select distinct table_name from user_tab_partitions)&lt;br /&gt;
union all&lt;br /&gt;
select to_clob (&amp;#039;alter table &amp;#039;||table_name|| &amp;#039; drop partition &amp;#039;||partition_name||&amp;#039;;&amp;#039;) from dba_tab_partitions&lt;br /&gt;
where tablespace_name in (select tablespace_name from dba_data_files where file_name like &amp;#039;%MISSING%&amp;#039;)&lt;br /&gt;
union all&lt;br /&gt;
Select case&lt;br /&gt;
when instr (VAl, &amp;#039;PARTITION&amp;#039;) = 0 Then&lt;br /&gt;
substr (Val,1,InStr (Val,&amp;#039;)&amp;#039;)+1)||&amp;#039;;&amp;#039;&lt;br /&gt;
else&lt;br /&gt;
substr (Val,1,InStr (Val,&amp;#039;)&amp;#039;)+1)||&amp;#039; local;&amp;#039;&lt;br /&gt;
End val&lt;br /&gt;
from&lt;br /&gt;
(select dbms_metadata.get_ddl (&amp;#039;INDEX&amp;#039;, index_name,&amp;#039;TEST&amp;#039;) Val from user_indexes where table_name in (select distinct table_name from user_tab_partitions))&lt;br /&gt;
union all&lt;br /&gt;
Select Val&lt;br /&gt;
from&lt;br /&gt;
(select dbms_metadata.get_dependent_ddl (&amp;#039;REF_CONSTRAINT&amp;#039;, table_name,&amp;#039;TEST&amp;#039;) Val&lt;br /&gt;
from user_tables where table_name in (select distinct table_name from user_tab_partitions join user_constraints using ( table_name)&lt;br /&gt;
where constraint_type=&amp;#039;R&amp;#039;))&lt;br /&gt;
union all&lt;br /&gt;
select Val&lt;br /&gt;
from&lt;br /&gt;
(select dbms_metadata.get_ddl (&amp;#039;CONSTRAINT&amp;#039;, constraint_name,&amp;#039;TEST&amp;#039;) Val&lt;br /&gt;
from user_constraints&lt;br /&gt;
where constraint_type=&amp;#039;P&amp;#039; and table_name in (select distinct table_name from user_tab_partitions)&lt;br /&gt;
)&lt;br /&gt;
union all&lt;br /&gt;
select to_clob (val)&lt;br /&gt;
from (select distinct &amp;#039;drop tablespace &amp;#039;||tablespace_name|| &amp;#039; including contents and datafiles;&amp;#039; val&lt;br /&gt;
from dba_tab_partitions&lt;br /&gt;
where tablespace_name in (select tablespace_name from dba_data_files where file_name like &amp;#039;%MISSING%&amp;#039;)&lt;br /&gt;
);&lt;br /&gt;
&lt;br /&gt;
spoo off&lt;br /&gt;
&lt;br /&gt;
@destroy_offending_objects&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORA-28112: failed to execute policy function===&lt;br /&gt;
when exporting or importing using [[Data Pump]]&amp;lt; /br&amp;gt;&lt;br /&gt;
During expdp is accompanied by &amp;quot;&amp;#039;&amp;#039;&amp;#039;ORA-31693: Table data object &amp;quot;SYSMAN&amp;quot;.&amp;quot;MGMT_IP_REPORT_DEF&amp;quot; failed to load/unload and is being skipped due to error:&amp;#039;&amp;#039;&amp;#039;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
===Reason===&lt;br /&gt;
This happens due to audit policies being defined on the table but the policy function is defined in another schema.&lt;br /&gt;
&lt;br /&gt;
===Solution===&lt;br /&gt;
Either drop the policy after importing the table with:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
begin&lt;br /&gt;
    for rec in (select * from dba_audit_policies where object_schema = &amp;#039;SYSMAN&amp;#039;) loop&lt;br /&gt;
        dbms_fga.drop_policy(object_schema =&amp;gt; rec.object_schema,&lt;br /&gt;
                             object_name =&amp;gt; rec.object_name,&lt;br /&gt;
                             policy_name =&amp;gt; rec.policy_name);  &lt;br /&gt;
    end loop;&lt;br /&gt;
end;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or exclude the policies during export by adding this to the .par file:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
exclude=FGA_POLICY&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or even better, give the necessary grants to the exporting user...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
grant exempt access policy to impexpusr;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The sysdba role has this automatically.&lt;br /&gt;
===ORA-17629: Cannot connect to the remote database server===&lt;br /&gt;
Active duplication fails to connect even though dns connection exists in tnsnames.ora&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
Problem:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
DUPLICATE TARGET DATABASE FROM ACTIVE DATABASE DORECOVER NOFILENAMECHECK;&lt;br /&gt;
&lt;br /&gt;
RMAN-03002: failure of Duplicate Db command at 05/27/2015 12:52:24&lt;br /&gt;
RMAN-05501: aborting duplication of target database&lt;br /&gt;
RMAN-03015: error occurred in stored script Memory Script&lt;br /&gt;
RMAN-03009: failure of backup command on ORA_DISK_1 channel at 05/27/2015 12:52:23&lt;br /&gt;
ORA-17629: Cannot connect to the remote database server&lt;br /&gt;
ORA-17627: ORA-12154: TNS:could not resolve the connect identifier specified&lt;br /&gt;
&lt;br /&gt;
ORA-17629: Cannot connect to the remote database server&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
Solution:&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
Update the tnsnames.ora of both destination &amp;#039;&amp;#039;&amp;#039;and&amp;#039;&amp;#039;&amp;#039; source ORACLE_HOMEs!&lt;br /&gt;
&lt;br /&gt;
===ORA-01950: no privileges on tablespace &amp;#039;SYSAUX&amp;#039;===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
26-JUN-15 03:12:27.545: &amp;gt;&amp;gt;&amp;gt; ORA-31642: the following SQL statement fails: &lt;br /&gt;
BEGIN &amp;quot;SYS&amp;quot;.&amp;quot;DBMS_RULE_EXP_RULES&amp;quot;.SCHEMA_CALLOUT(:1,0,1,&amp;#039;12.01.00.02.00&amp;#039;); END;&lt;br /&gt;
ORA-01950: no privileges on tablespace &amp;#039;SYSAUX&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Cause:&amp;#039;&amp;#039;&amp;#039;&amp;lt;br /&amp;gt;&lt;br /&gt;
In this case, it seems SYSMAN has no rights to create objects in the SYSAUX tablespace&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Solution:&amp;#039;&amp;#039;&amp;#039;&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter user SYSMAN quota unlimited on sysaux;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
More information [https://support.oracle.com/epmos/faces/SearchDocDisplay?_adf.ctrl-state=bov7jp5pq_4&amp;amp;_afrLoop=547371065896716#SYMPTOM here]&lt;br /&gt;
&lt;br /&gt;
===ORA-39080: failed to create queues &amp;quot;KUPC$C_1_20150616165037&amp;quot; and &amp;quot;KUPC$S_1_20150616165037&amp;quot; for Data Pump job===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
expdp /&lt;br /&gt;
&lt;br /&gt;
Export: Release 11.2.0.4.0 - Production on Tue Jun 16 16:50:36 2015&lt;br /&gt;
&lt;br /&gt;
Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.&lt;br /&gt;
&lt;br /&gt;
Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production&lt;br /&gt;
With the Partitioning, OLAP, Data Mining and Real Application Testing options&lt;br /&gt;
ORA-31626: job does not exist&lt;br /&gt;
ORA-31637: cannot create job SYS_EXPORT_SCHEMA_01 for user OPS$ORAIBM&lt;br /&gt;
ORA-06512: at &amp;quot;SYS.DBMS_SYS_ERROR&amp;quot;, line 95&lt;br /&gt;
ORA-06512: at &amp;quot;SYS.KUPV$FT_INT&amp;quot;, line 798&lt;br /&gt;
[[ORA-39080: failed to create queues &amp;quot;KUPC$C_1_20150616165037&amp;quot; and &amp;quot;KUPC$S_1_20150616165037&amp;quot; for Data Pump job]]&lt;br /&gt;
ORA-06512: at &amp;quot;SYS.DBMS_SYS_ERROR&amp;quot;, line 95&lt;br /&gt;
ORA-06512: at &amp;quot;SYS.KUPC$QUE_INT&amp;quot;, line 1534&lt;br /&gt;
ORA-24002: QUEUE_TABLE SYS.AQ$KUPC$DATAPUMP_QUETAB_1 does not exist&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Cause:====&lt;br /&gt;
Possibly some or all of OLAP module has got itself deinstalled.&lt;br /&gt;
====Solution:====&lt;br /&gt;
Try:&lt;br /&gt;
* Recompiling invalid objects. @?/rdbms/admin/utlrp&lt;br /&gt;
* Reinstalling DBMS_CUBE packages by (re)running catproc.sql. @?/rdbms/admin/catproc followed by @?/rdbms/admin/utlrp&lt;br /&gt;
* Reinstalling OLAP. @?/olap/admin/olap.sql SYSAUX TEMP; But see Metalink note ID 296187.1 for full instructions.&lt;br /&gt;
* Check metalink for bugs. See ID 345198.1 and possibly ID 453796.1&lt;br /&gt;
===ORA-14063: Unusable index exists on unique/primary constraint key===&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;ORA-39083: Object type CONSTRAINT failed to create with error:&amp;#039;&amp;#039;&amp;#039;&amp;lt;br /&amp;gt;&lt;br /&gt;
During an import datapump (impdp), import failed because indexes were in error before the tables were exported. This causes the import of rows to be skipped.&amp;lt;br /&amp;gt;&lt;br /&gt;
If the export cannot be done again (having compiled the indexes), then the metadata can be imported and the indexes compiled before importing the data.&lt;br /&gt;
* Import the metadata&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cat&amp;lt;&amp;lt;EOCAT &amp;gt;impdp_adst_ads_archive_metadata.par&lt;br /&gt;
userid=&amp;#039;/ as sysdba&amp;#039;&lt;br /&gt;
dumpfile=adst_ads_archive.dmp&lt;br /&gt;
logfile=impdp_adst_ads_archive_metadata.log&lt;br /&gt;
content=metadata_only&lt;br /&gt;
EOCAT&lt;br /&gt;
&lt;br /&gt;
impdp parfile=impdp_adst_ads_archive_metadata.par&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Find the bad indexes and recompile them&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select &amp;#039;alter index &amp;#039;|| owner||&amp;#039;.&amp;#039;||index_name||&amp;#039; rebuild online parallel 8;&amp;#039;&lt;br /&gt;
from   dba_indexes&lt;br /&gt;
where  status = &amp;#039;UNUSABLE&amp;#039;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Import the data&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cat&amp;lt;&amp;lt;EOCAT &amp;gt;impdp_adst_ads_archive_data.par&lt;br /&gt;
userid=&amp;#039;/ as sysdba&amp;#039;&lt;br /&gt;
dumpfile=adst_ads_archive.dmp&lt;br /&gt;
logfile=impdp_adst_ads_archive_data.log&lt;br /&gt;
table_exists_action=append&lt;br /&gt;
content=data_only&lt;br /&gt;
EOCAT&lt;br /&gt;
&lt;br /&gt;
impdp parfile=impdp_adst_ads_archive_data.par&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORA-09925: Unable to create audit trail file===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SQL&amp;gt; startup nomount pfile=&amp;quot;/oracle/TRSCRP1/admin/initTRSCRP1.ora&amp;quot;&lt;br /&gt;
ORA-09925: Unable to create audit trail file&lt;br /&gt;
SVR4 Error: 2: No such file or directory&lt;br /&gt;
Additional information: 9925&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
connected to auxiliary database (not started)&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-03002: failure of Duplicate Db command at 08/29/2017 15:53:09&lt;br /&gt;
RMAN-05501: aborting duplication of target database&lt;br /&gt;
RMAN-03015: error occurred in stored script Memory Script&lt;br /&gt;
RMAN-04014: startup failed: ORA-09925: Unable to create audit trail file&lt;br /&gt;
IBM AIX RISC System/6000 Error: 2: No such file or directory&lt;br /&gt;
Additional information: 9925&lt;br /&gt;
&lt;br /&gt;
Recovery Manager complete.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Problem====&lt;br /&gt;
This will be almost certainly one of two issues. Either the directory is not writable by the id that started the instance or the directory just does not exist.&lt;br /&gt;
====Solution====&lt;br /&gt;
Note there can be a difference between what you see when you type:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
show parameter audit&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
and when you type:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
strings -a $ORACLE_HOME/dbs/spfile${ORACLE_SID}.ora | grep -i audit&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
due to someone doing an &amp;quot;alter system&amp;quot; without the &amp;quot;scope=spfile&amp;quot; or &amp;quot;scope=both&amp;quot;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SQL&amp;gt; host ls -al /oracle/TRSCRP1/admin/adump&lt;br /&gt;
SQL&amp;gt; host mkdir /oracle/TRSCRP1/admin/adump&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===ORA-09925: Unable to create audit trail file===&lt;br /&gt;
When starting SQL*Plus with no db processes running (expecting to see &amp;quot;Connected to an idle instance&amp;quot;), we get this:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ERROR:&lt;br /&gt;
ORA-09925: Unable to create audit trail file&lt;br /&gt;
IBM AIX RISC System/6000 Error: 2: No such file or directory&lt;br /&gt;
Additional information: 9925&lt;br /&gt;
ORA-01075: you are currently logged on&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Filesystem permissions are fine&lt;br /&gt;
* &amp;#039;strings spfile&amp;lt;SID&amp;gt;.ora | grep audit&amp;#039; shows the correct directory&lt;br /&gt;
* Running on AIX&lt;br /&gt;
AIX is the clue here... need to check for semaphores and locked shared memory objects&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
(0) UCLID55D oraibm@solax082:/oracle/product/11.2.0.3/bin&amp;gt; sysresv&lt;br /&gt;
&lt;br /&gt;
IPC Resources for ORACLE_SID &amp;quot;UCLID55D&amp;quot; :&lt;br /&gt;
Shared Memory:&lt;br /&gt;
ID              KEY&lt;br /&gt;
8388640         0xffffffff&lt;br /&gt;
579862561       0xffffffff&lt;br /&gt;
384827426       0x326f32e8&lt;br /&gt;
&lt;br /&gt;
Semaphores:&lt;br /&gt;
ID              KEY&lt;br /&gt;
167772287       0xf09f4914&lt;br /&gt;
Oracle Instance alive for sid &amp;quot;UCLID55D&amp;quot;&lt;br /&gt;
&lt;br /&gt;
(0) UCLID55D oraibm@solax082:/oracle/product/11.2.0.3/bin&amp;gt; ipcrm -m 8388640&lt;br /&gt;
(0) UCLID55D oraibm@solax082:/oracle/product/11.2.0.3/bin&amp;gt; ipcrm -m 579862561&lt;br /&gt;
(0) UCLID55D oraibm@solax082:/oracle/product/11.2.0.3/bin&amp;gt; ipcrm -m 384827426&lt;br /&gt;
&lt;br /&gt;
(0) UCLID55D oraibm@solax082:/oracle/product/11.2.0.3/bin&amp;gt; ipcrm -s 167772287&lt;br /&gt;
&lt;br /&gt;
(0) UCLID55D oraibm@solax082:/oracle/product/11.2.0.3/bin&amp;gt; sysresv&lt;br /&gt;
&lt;br /&gt;
IPC Resources for ORACLE_SID &amp;quot;UCLID55D&amp;quot; :&lt;br /&gt;
Shared Memory&lt;br /&gt;
ID              KEY&lt;br /&gt;
No shared memory segments used&lt;br /&gt;
Semaphores:&lt;br /&gt;
ID              KEY&lt;br /&gt;
No semaphore resources used&lt;br /&gt;
Oracle Instance not alive for sid &amp;quot;UCLID55D&amp;quot;&lt;br /&gt;
&lt;br /&gt;
(0) UCLID55D oraibm@solax082:/oracle/product/11.2.0.3/bin&amp;gt; ps -ef | grep UCLID55D&lt;br /&gt;
oraibm 3326 23776 0 14:12:05 pts/1 0:00 grep UCLID55D &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===RMAN-06023: no backup or copy of datafile 1 found to restore===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-03002: failure of Duplicate Db command at 05/16/2018 16:08:13&lt;br /&gt;
RMAN-05501: aborting duplication of target database&lt;br /&gt;
RMAN-05556: not all datafiles have backups that can be recovered to SCN 278250901080&lt;br /&gt;
RMAN-03015: error occurred in stored script Memory Script&lt;br /&gt;
RMAN-06026: some targets not found - aborting restore&lt;br /&gt;
RMAN-06023: no backup or copy of datafile 7 found to restore&lt;br /&gt;
RMAN-06023: no backup or copy of datafile 6 found to restore&lt;br /&gt;
RMAN-06023: no backup or copy of datafile 5 found to restore&lt;br /&gt;
RMAN-06023: no backup or copy of datafile 4 found to restore&lt;br /&gt;
RMAN-06023: no backup or copy of datafile 3 found to restore&lt;br /&gt;
RMAN-06023: no backup or copy of datafile 2 found to restore&lt;br /&gt;
RMAN-06023: no backup or copy of datafile 1 found to restore&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Seems pretty straightforward? SCN was set too early for the retention period. But no, not this time.&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
RMAN&amp;gt; list backup of datafile 1;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
List of Backup Sets&lt;br /&gt;
===================&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
BS Key  Type LV Size       Device Type Elapsed Time Completion Time&lt;br /&gt;
------- ---- -- ---------- ----------- ------------ -------------------&lt;br /&gt;
110170340 Incr 0  132.90G    SBT_TAPE    00:18:32     2018-05-14 01:19:40&lt;br /&gt;
        BP Key: 110170345   Status: AVAILABLE  Compressed: NO  Tag: WEEKLY_FULL&lt;br /&gt;
        Handle: 24639762_REPORTA_07t2r3uk_1_1   Media: V_17152809_77191330&lt;br /&gt;
  List of Datafiles in backup set 110170340&lt;br /&gt;
  File LV Type Ckp SCN    Ckp Time            Name&lt;br /&gt;
  ---- -- ---- ---------- ------------------- ----&lt;br /&gt;
  1    0  Incr 277998128991 2018-05-14 01:01:08 /cln/acc/ora_data3/reporta/system01.dbf&lt;br /&gt;
&lt;br /&gt;
BS Key  Type LV Size       Device Type Elapsed Time Completion Time&lt;br /&gt;
------- ---- -- ---------- ----------- ------------ -------------------&lt;br /&gt;
110355808 Incr 1  204.00M    SBT_TAPE    00:05:13     2018-05-15 01:06:22&lt;br /&gt;
        BP Key: 110355813   Status: AVAILABLE  Compressed: NO  Tag: DAILY_INCREMENTAL&lt;br /&gt;
        Handle: 24661053_REPORTA_3ft2toal_1_1   Media: V_17173010_77253424&lt;br /&gt;
  List of Datafiles in backup set 110355808&lt;br /&gt;
  File LV Type Ckp SCN    Ckp Time            Name&lt;br /&gt;
  ---- -- ---- ---------- ------------------- ----&lt;br /&gt;
  1    1  Incr 278044267395 2018-05-15 01:01:09 /cln/acc/ora_data3/reporta/system01.dbf&lt;br /&gt;
&lt;br /&gt;
BS Key  Type LV Size       Device Type Elapsed Time Completion Time&lt;br /&gt;
------- ---- -- ---------- ----------- ------------ -------------------&lt;br /&gt;
110543802 Incr 1  237.00M    SBT_TAPE    00:05:51     2018-05-16 01:07:40&lt;br /&gt;
        BP Key: 110543807   Status: AVAILABLE  Compressed: NO  Tag: DAILY_INCREMENTAL&lt;br /&gt;
        Handle: 24681602_REPORTA_6nt30cnt_1_1   Media: V_17133646_77315270&lt;br /&gt;
  List of Datafiles in backup set 110543802&lt;br /&gt;
  File LV Type Ckp SCN    Ckp Time            Name&lt;br /&gt;
  ---- -- ---- ---------- ------------------- ----&lt;br /&gt;
  1    1  Incr 278286445856 2018-05-16 01:01:50 /cln/acc/ora_data3/reporta/system01.dbf&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
SCN was only 12 hours ago with a retention of 28 days! The backup piece dated 2018-05-15 01:06:22 is clearly available and on the device type set_tape.&amp;lt;br /&amp;gt;&lt;br /&gt;
The trick here was to look back through the logs and look more closely at what the file restore message was saying...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
channel t0: starting datafile backup set restore&lt;br /&gt;
channel t0: specifying datafile(s) to restore from backup set&lt;br /&gt;
channel t0: restoring datafile 00001 to /cln/acc/ora_data3/reporta/system01.dbf             &amp;lt; &amp;lt; &amp;lt; ==============&lt;br /&gt;
channel t0: reading from backup piece dbfull_REPORTA_738887052_967580186_116_1&lt;br /&gt;
channel t2: ORA-19870: error while restoring backup piece dbfull_REPORTA_738887052_967579750_113_1&lt;br /&gt;
ORA-19507: failed to retrieve sequential file, handle=&amp;quot;dbfull_REPORTA_738887052_967579750_113_1&amp;quot;, parms=&amp;quot;&amp;quot;&lt;br /&gt;
ORA-27029: skgfrtrv: sbtrestore returned error&lt;br /&gt;
ORA-19511: non RMAN, but media manager or vendor specific failure, error text:&lt;br /&gt;
   CreateOraObject20: Job[0] thread[55116090]: Restore: GetBackupInfo() for Archive File[dbfull_REPORTA_738887052_967579750_113_1] failed.&lt;br /&gt;
ORA-0651&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
It was not the fact that it could not find the data on tape, it was that it could not save the file to the location indicated!!&lt;br /&gt;
In the RMAN DUPLICATE script, I had all the file paths redirected (a mixture of convert parameters and spfile set) to a /restore filesystem.&amp;lt;br /&amp;gt;&lt;br /&gt;
But I forgot one!&amp;lt;br /&amp;gt;&lt;br /&gt;
A handy thing to do is to search out the file paths with this to see if something is still wrong:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cd $ORACLE_HOME/dbs&lt;br /&gt;
strings -a spfile${ORACLE_SID}.ora | grep dest&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This should show any paths still not getting caught by the DUPLICATE script.&lt;br /&gt;
&lt;br /&gt;
===RMAN-06136: ORACLE error from auxiliary database: ORA-06502: PL/SQL: numeric or value error===&lt;br /&gt;
When cloning a database, the duplicate fails with this error.&lt;br /&gt;
====Problem====&lt;br /&gt;
This duplicate had no target connection but did have a catalog and auxiliary connection.&lt;br /&gt;
In the catalog (which was the catalog where the target was registerd), there was also an entry in that catalog with the same name as the auxiliary - left over from the days when these 2 instances were Primary and Standby in a Dataguard configuration.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
Datafile 414 skipped by request&lt;br /&gt;
Datafile 415 skipped by request&lt;br /&gt;
Datafile 419 skipped by request&lt;br /&gt;
Datafile 420 skipped by request&lt;br /&gt;
Datafile 421 skipped by request&lt;br /&gt;
&lt;br /&gt;
DBGSQL:     AUXILIARY&amp;gt; begin :ofname := sys.dbms_backup_restore.convertFileName( fname   =&amp;gt;   :ifname, ftype   =&amp;gt;   :iftype, osftype =&amp;gt;   TRUE); end;&lt;br /&gt;
DBGSQL:        sqlcode = 6502&lt;br /&gt;
DBGSQL:         B :ofname = NULL&lt;br /&gt;
DBGSQL:         B :ifname =&lt;br /&gt;
DBGSQL:         B :iftype = 2&lt;br /&gt;
restarting auxiliary database without server parameter file&lt;br /&gt;
Oracle instance started&lt;br /&gt;
&lt;br /&gt;
Total System Global Area   32068440064 bytes&lt;br /&gt;
&lt;br /&gt;
Fixed Size                     2262200 bytes&lt;br /&gt;
Variable Size              16978545480 bytes&lt;br /&gt;
Database Buffers           15032385536 bytes&lt;br /&gt;
Redo Buffers                  55246848 bytes&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-03002: failure of Duplicate Db command at 10/04/2017 14:50:29&lt;br /&gt;
RMAN-05501: aborting duplication of target database&lt;br /&gt;
RMAN-06136: ORACLE error from auxiliary database: ORA-06502: PL/SQL: numeric or value error&lt;br /&gt;
&lt;br /&gt;
Recovery Manager complete.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Solution====&lt;br /&gt;
Connect to the catalog and unregister the name of the auxiliary database. It shouldn&amp;#039;t be there anyway.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rman catalog rmanusr/rmanpwd@rmancat&lt;br /&gt;
&lt;br /&gt;
Recovery Manager: Release 11.2.0.4.0 - Production on Wed Oct 4 15:00:00 2017&lt;br /&gt;
&lt;br /&gt;
Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.&lt;br /&gt;
&lt;br /&gt;
connected to recovery catalog database&lt;br /&gt;
&lt;br /&gt;
RMAN&amp;gt; set dbid 4260753020;&lt;br /&gt;
&lt;br /&gt;
executing command: SET DBID&lt;br /&gt;
database name is &amp;quot;LBK&amp;quot; and DBID is 4260753020&lt;br /&gt;
&lt;br /&gt;
RMAN&amp;gt; list db_unique_name of database;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
List of Databases&lt;br /&gt;
DB Key  DB Name  DB ID            Database Role    Db_unique_name&lt;br /&gt;
------- ------- ----------------- ---------------  ------------------&lt;br /&gt;
13301587 LBK      4260753020       PRIMARY          LBK&lt;br /&gt;
13301587 LBK      4260753020       STANDBY          ACC_PERF&lt;br /&gt;
13301587 LBK      4260753020       STANDBY          LBKRO&lt;br /&gt;
&lt;br /&gt;
RMAN&amp;gt; unregister db_unique_name &amp;#039;ACC_PERF&amp;#039;;&lt;br /&gt;
&lt;br /&gt;
database db_unique_name is &amp;quot;ACC_PERF&amp;quot;, db_name is &amp;quot;LBK&amp;quot; and DBID is 4260753020&lt;br /&gt;
&lt;br /&gt;
Want to unregister the database with target db_unique_name (enter YES or NO)? YES&lt;br /&gt;
database with db_unique_name ACC_PERF unregistered from the recovery catalog&lt;br /&gt;
&lt;br /&gt;
RMAN&amp;gt; exit&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORA-39181: Only partial table data may be exported due to fine grain access control on &amp;quot;owner&amp;quot;.&amp;quot;&amp;lt;table_name&amp;gt;&amp;quot;===&lt;br /&gt;
&lt;br /&gt;
===Reason===&lt;br /&gt;
This happens when applications are designed with fine-grained access.&lt;br /&gt;
===Solution===&lt;br /&gt;
Grant the necessary privileges to the exporting user...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
grant exempt access policy to ops$oraibm;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORA-04030: out of process memory when trying to allocate 2520 bytes===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
expdp problem (ORA-04030: out of process memory when trying to allocate 2520 bytes (pga heap,koh-kghu call heap))&lt;br /&gt;
&lt;br /&gt;
select value from v$pgastat where name=&amp;#039;maximum PGA allocated&amp;#039;;&lt;br /&gt;
&lt;br /&gt;
SHOW PARAMETER TARGET&lt;br /&gt;
&lt;br /&gt;
ORA-04030: out of process memory when trying to allocate 2520 bytes (pga heap,koh-kghu call heap)&lt;br /&gt;
&lt;br /&gt;
alter system reset pga_aggregate_target scope=spfile;&lt;br /&gt;
&lt;br /&gt;
show sga&lt;br /&gt;
&lt;br /&gt;
select * from v$pgastat;&lt;br /&gt;
&lt;br /&gt;
show parameter process&lt;br /&gt;
&lt;br /&gt;
select sum(value)/1024/1024 Mb&lt;br /&gt;
from   v$sesstat s, v$statname n&lt;br /&gt;
where  1=1&lt;br /&gt;
and    n.STATISTIC# = s.STATISTIC#&lt;br /&gt;
and    name = &amp;#039;session pga memory&amp;#039;&lt;br /&gt;
&lt;br /&gt;
show parameter WORKAREA&lt;br /&gt;
&lt;br /&gt;
select value from v$pgastat where name=&amp;#039;maximum PGA allocated&amp;#039;;&lt;br /&gt;
&lt;br /&gt;
alter system set memory_max_target=10G scope=spfile;&lt;br /&gt;
&lt;br /&gt;
alter system set memory_target=3G scope=both;&lt;br /&gt;
&lt;br /&gt;
select * from v$memory_target_advice order by memory_size;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORA-04031: unable to allocate 32 bytes of shared memory (&amp;quot;shared pool&amp;quot;,&amp;quot;select name,online$,contents...&amp;quot;,&amp;quot;KGLH0^e5705bfc&amp;quot;,&amp;quot;kglHeapInitialize:temp&amp;quot;)===&lt;br /&gt;
* [https://blogs.oracle.com/db/entry/ora-4031_troubleshooting ORA-4031 Troubleshooting]&lt;br /&gt;
* [https://support.oracle.com/epmos/faces/DocumentDisplay?_afrLoop=89215376348478&amp;amp;id=396940.1&amp;amp;_afrWindowMode=0&amp;amp;_adf.ctrl-state=u1z0xcppg_4 Troubleshooting and Diagnosing ORA-4031 Error - (Doc ID 396940.1)]&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ORA-04031: unable to allocate  bytes of shared memory (&amp;quot;&amp;quot;,&amp;quot;&amp;quot;,&amp;quot;&amp;quot;,&amp;quot;&amp;quot;) &lt;br /&gt;
ORA-04031: unable to allocate 32 bytes of shared memory (&amp;quot;shared pool&amp;quot;,&amp;quot;select name,online$,contents...&amp;quot;,&amp;quot;KGLH0^e5705bfc&amp;quot;,&amp;quot;kglHeapInitialize:temp&amp;quot;) &lt;br /&gt;
Incident details in: /oracle/diag/rdbms/mape/MAPE/incident/incdir_86754/MAPE_dm00_14221536_i86754.trc &lt;br /&gt;
Wed Jul 31 20:42:50 2013 &lt;br /&gt;
Dumping diagnostic data in directory=[cdmp_20130731204250], requested by (instance=1, osid=14221536 (DM00)), summary=[incident=86753]. &lt;br /&gt;
Wed Jul 31 20:42:51 2013 &lt;br /&gt;
Sweep [inc][86754]: completed &lt;br /&gt;
Sweep [inc][86753]: completed &lt;br /&gt;
Sweep [inc2][86753]: completed &lt;br /&gt;
Wed Jul 31 20:42:57 2013 &lt;br /&gt;
Use ADRCI or Support Workbench to package the incident. &lt;br /&gt;
See Note 411.1 at My Oracle Support for error and packaging details. &lt;br /&gt;
Dumping diagnostic data in directory=[cdmp_20130731204257], requested by (instance=1, osid=14221536 (DM00)), summary=[incident=86754]. &lt;br /&gt;
Wed Jul 31 20:43:35 2013 &lt;br /&gt;
Errors in file /oracle/diag/rdbms/mape/MAPE/trace/MAPE_dw02_40567024.trc  (incident=82993): &lt;br /&gt;
ORA-04031: unable to allocate 32 bytes of shared memory (&amp;quot;shared pool&amp;quot;,&amp;quot;select order#,columns,types ...&amp;quot;,&amp;quot;KGLH0^470434f8&amp;quot;,&amp;quot;kglHeapInitialize:temp&amp;quot;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Database had already crashed so nothing to do but:&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
(0) MAPE ora@x025:/home/ora&amp;gt; sqlplus / as sysdba&lt;br /&gt;
&lt;br /&gt;
SQL*Plus: Release 11.2.0.3.0 Production on Fri Aug 2 14:26:20 2013&lt;br /&gt;
&lt;br /&gt;
Copyright (c) 1982, 2011, Oracle.  All rights reserved.&lt;br /&gt;
&lt;br /&gt;
Connected.&lt;br /&gt;
SYS@MAPE&amp;gt; alter system flush shared_pool;&lt;br /&gt;
alter system flush shared_pool&lt;br /&gt;
*&lt;br /&gt;
ERROR at line 1:&lt;br /&gt;
ORA-01012: not logged on&lt;br /&gt;
Process ID: 0&lt;br /&gt;
Session ID: 0 Serial number: 0&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
SYS@MAPE&amp;gt; shutdown abort&lt;br /&gt;
ORACLE instance shut down.&lt;br /&gt;
SYS@MAPE&amp;gt; startup&lt;br /&gt;
ORACLE instance started.&lt;br /&gt;
&lt;br /&gt;
Total System Global Area  734892032 bytes&lt;br /&gt;
Fixed Size                  2225128 bytes&lt;br /&gt;
Variable Size             398461976 bytes&lt;br /&gt;
Database Buffers          318767104 bytes&lt;br /&gt;
Redo Buffers               15437824 bytes&lt;br /&gt;
Database mounted.&lt;br /&gt;
Database opened.&lt;br /&gt;
&lt;br /&gt;
SYS@MAPE&amp;gt; show parameter pool&lt;br /&gt;
&lt;br /&gt;
NAME                                 TYPE                           VALUE&lt;br /&gt;
------------------------------------ ------------------------------ ------------------------------&lt;br /&gt;
buffer_pool_keep                     string&lt;br /&gt;
buffer_pool_recycle                  string&lt;br /&gt;
global_context_pool_size             string&lt;br /&gt;
java_pool_size                       big integer                    0&lt;br /&gt;
large_pool_size                      big integer                    0&lt;br /&gt;
olap_page_pool_size                  big integer                    0&lt;br /&gt;
shared_pool_reserved_size            big integer                    18M&lt;br /&gt;
shared_pool_size                     big integer                    208M&lt;br /&gt;
streams_pool_size                    big integer                    0&lt;br /&gt;
SYS@MAPE&amp;gt; show sga&lt;br /&gt;
&lt;br /&gt;
Total System Global Area  734892032 bytes&lt;br /&gt;
Fixed Size                  2225128 bytes&lt;br /&gt;
Variable Size             385879064 bytes&lt;br /&gt;
Database Buffers          331350016 bytes&lt;br /&gt;
Redo Buffers               15437824 bytes&lt;br /&gt;
SYS@MAPE&amp;gt; exit&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
but for reference, the causes could well be the applications running on the database are not using bind variables...&amp;lt;br /&amp;gt;&lt;br /&gt;
From [http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:528893984337 asktom.oracle.com]&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
Just to give you a tiny idea of how huge of a difference this &lt;br /&gt;
can make performance wise, you only need to run a very small &lt;br /&gt;
test:&lt;br /&gt;
&lt;br /&gt;
tkyte@TKYTE816&amp;gt; alter system flush shared_pool;&lt;br /&gt;
System altered.&lt;br /&gt;
&lt;br /&gt;
tkyte@TKYTE816&amp;gt; declare&lt;br /&gt;
  2      type rc is ref cursor;&lt;br /&gt;
  3      l_rc rc;&lt;br /&gt;
  4      l_dummy all_objects.object_name%type;&lt;br /&gt;
  5      l_start number default dbms_utility.get_time;&lt;br /&gt;
  6  begin&lt;br /&gt;
  7      for i in 1 .. 1000&lt;br /&gt;
  8      loop&lt;br /&gt;
  9          open l_rc for&lt;br /&gt;
 10          &amp;#039;select object_name&lt;br /&gt;
 11             from all_objects&lt;br /&gt;
 12            where object_id = &amp;#039; || i;&lt;br /&gt;
 13          fetch l_rc into l_dummy;&lt;br /&gt;
 14          close l_rc;&lt;br /&gt;
 15      end loop;&lt;br /&gt;
 16      dbms_output.put_line&lt;br /&gt;
 17      ( round( (dbms_utility.get_time-l_start)/100, 2 ) ||&lt;br /&gt;
 18        &amp;#039; seconds...&amp;#039; );&lt;br /&gt;
 19  end;&lt;br /&gt;
 20  /&lt;br /&gt;
14.86 seconds...&lt;br /&gt;
&lt;br /&gt;
PL/SQL procedure successfully completed.&lt;br /&gt;
&lt;br /&gt;
tkyte@TKYTE816&amp;gt; declare&lt;br /&gt;
  2      type rc is ref cursor;&lt;br /&gt;
  3      l_rc rc;&lt;br /&gt;
  4      l_dummy all_objects.object_name%type;&lt;br /&gt;
  5      l_start number default dbms_utility.get_time;&lt;br /&gt;
  6  begin&lt;br /&gt;
  7      for i in 1 .. 1000&lt;br /&gt;
  8      loop&lt;br /&gt;
  9          open l_rc for&lt;br /&gt;
 10          &amp;#039;select object_name&lt;br /&gt;
 11             from all_objects&lt;br /&gt;
 12            where object_id = :x&amp;#039;&lt;br /&gt;
 13          using i;&lt;br /&gt;
 14          fetch l_rc into l_dummy;&lt;br /&gt;
 15          close l_rc;&lt;br /&gt;
 16      end loop;&lt;br /&gt;
 17      dbms_output.put_line&lt;br /&gt;
 18      ( round( (dbms_utility.get_time-l_start)/100, 2 ) ||&lt;br /&gt;
 19        &amp;#039; seconds...&amp;#039; );&lt;br /&gt;
 20  end;&lt;br /&gt;
 21  /&lt;br /&gt;
1.27 seconds...&lt;br /&gt;
&lt;br /&gt;
PL/SQL procedure successfully completed.&lt;br /&gt;
&lt;br /&gt;
That is pretty dramatic.  The fact is that not only does this &lt;br /&gt;
execute much faster (we spent more time PARSING our queries then &lt;br /&gt;
actually EXECUTING them!) it will let more users use your system &lt;br /&gt;
simultaneously.&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
and from [http://asktom.oracle.com/pls/asktom/f?p=100:11:::::P11_QUESTION_ID:1163635055580 linked question]&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
Lbrary cache latch contention is typically caused by NOT using bind variables.  It is due &lt;br /&gt;
to excessive parsing of statements.&lt;br /&gt;
&lt;br /&gt;
One way to see if this might be the case in your situation is to run a script like:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
create table t1 as select sql_text from v$sqlarea;&lt;br /&gt;
&lt;br /&gt;
alter table t1 add sql_text_wo_constants varchar2(1000);&lt;br /&gt;
&lt;br /&gt;
create or replace function &lt;br /&gt;
remove_constants( p_query in varchar2 ) return varchar2&lt;br /&gt;
as&lt;br /&gt;
    l_query long;&lt;br /&gt;
    l_char  varchar2(1);&lt;br /&gt;
    l_in_quotes boolean default FALSE;&lt;br /&gt;
begin&lt;br /&gt;
    for i in 1 .. length( p_query )&lt;br /&gt;
    loop&lt;br /&gt;
        l_char := substr(p_query,i,1);&lt;br /&gt;
        if ( l_char = &amp;#039;&amp;#039;&amp;#039;&amp;#039; and l_in_quotes )&lt;br /&gt;
        then&lt;br /&gt;
            l_in_quotes := FALSE;&lt;br /&gt;
        elsif ( l_char = &amp;#039;&amp;#039;&amp;#039;&amp;#039; and NOT l_in_quotes )&lt;br /&gt;
        then&lt;br /&gt;
            l_in_quotes := TRUE;&lt;br /&gt;
            l_query := l_query || &amp;#039;&amp;#039;&amp;#039;#&amp;#039;;&lt;br /&gt;
        end if;&lt;br /&gt;
        if ( NOT l_in_quotes ) then&lt;br /&gt;
            l_query := l_query || l_char;&lt;br /&gt;
        end if;&lt;br /&gt;
    end loop;&lt;br /&gt;
    l_query := translate( l_query, &amp;#039;0123456789&amp;#039;, &amp;#039;@@@@@@@@@@&amp;#039; );&lt;br /&gt;
    for i in 0 .. 8 loop&lt;br /&gt;
        l_query := replace( l_query, lpad(&amp;#039;@&amp;#039;,10-i,&amp;#039;@&amp;#039;), &amp;#039;@&amp;#039; );&lt;br /&gt;
        l_query := replace( l_query, lpad(&amp;#039; &amp;#039;,10-i,&amp;#039; &amp;#039;), &amp;#039; &amp;#039; );&lt;br /&gt;
    end loop;&lt;br /&gt;
    return upper(l_query);&lt;br /&gt;
end;&lt;br /&gt;
/&lt;br /&gt;
update t1 set sql_text_wo_constants = remove_constants(sql_text);&lt;br /&gt;
&lt;br /&gt;
select sql_text_wo_constants, count(*)&lt;br /&gt;
  from t1&lt;br /&gt;
 group by sql_text_wo_constants&lt;br /&gt;
having count(*) &amp;gt; 100&lt;br /&gt;
 order by 2&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The output of that last query will show you statements that are identical in the shared &lt;br /&gt;
pool after all numbers and character string constants have been removed.  These &lt;br /&gt;
statements -- and more importantly their counts -- are the potential bottlenecks.  In &lt;br /&gt;
addition to causing the contention, they will be HUGE cpu consumers.  &lt;br /&gt;
&lt;br /&gt;
If you discover your applications do not use bind variables -- you must have this &lt;br /&gt;
corrected.  You&amp;#039;ll never have a good hit ratio if everyone submits &amp;quot;unique&amp;quot; sql.  Your &lt;br /&gt;
shared pool will never be used right and you&amp;#039;ll be using excessive CPU (90% of the time &lt;br /&gt;
it takes to process &amp;quot;insert into t values ( 1 )&amp;quot; is parsing.  If you use &amp;quot;insert into t &lt;br /&gt;
values ( :x )&amp;quot;, and bind the value of 1 -- then the next person that runs that insert &lt;br /&gt;
will benefit from your work and run that much faster. &lt;br /&gt;
...&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Advice from Oracle concerning a concrete (12c) example of unable to allocate 52824 bytes of shared memory (&amp;quot;shared pool&amp;quot;,...====&lt;br /&gt;
This was from a ticket raised for a Data Pump export that consistently failed with:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Processing object type SCHEMA_EXPORT/TABLE/PROCACT_INSTANCE&lt;br /&gt;
Processing object type SCHEMA_EXPORT/TABLE/TABLE&lt;br /&gt;
ORA-39014: One or more workers have prematurely exited.&lt;br /&gt;
ORA-39029: worker 1 with process name &amp;quot;DW00&amp;quot; prematurely terminated&lt;br /&gt;
ORA-31671: Worker process DW00 had an unhandled exception.&lt;br /&gt;
ORA-04031: unable to allocate 52824 bytes of shared memory (&amp;quot;shared pool&amp;quot;,&amp;quot;unknown object&amp;quot;,&amp;quot;KTSL subheap&amp;quot;,&amp;quot;ktsl_load_disp-2&amp;quot;)&lt;br /&gt;
ORA-06512: at &amp;quot;SYS.KUPW$WORKER&amp;quot;, line 2122&lt;br /&gt;
ORA-06512: at line 2&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
The error ORA-4031 on the shared pool can indicate one of two things:&lt;br /&gt;
- insufficient space for the shared pool (so insufficient memory in SGA at that time)&lt;br /&gt;
OR&lt;br /&gt;
- although there is enough memory, it is fragmented and no contiguous chunk can be allocated to satisfy the latest memory request.&lt;br /&gt;
&lt;br /&gt;
Each SGA has a little fragmentation of course because of the operations taking place, so in your case the fragmentation is represented by the 18M of free memory, which exists in uncontiguous chunks.&lt;br /&gt;
This means that the root cause of the error is insufficient contiguous memory to allocate 12312 bytes of shared memory.&lt;br /&gt;
&lt;br /&gt;
ACTION PLAN&lt;br /&gt;
==============&lt;br /&gt;
1. We see memory_target=2000M. This is too little to support a 12c database, even when it has little activity.&lt;br /&gt;
As you may know 1.7G for the SGA was acceptable when speaking of 32bit OSs where it was hardly possible to make use of more than that.&lt;br /&gt;
Since you have a 64 bit system, the addressable memory is virtually unlimited.&lt;br /&gt;
Furthermore, by using AMM (memory_target&amp;gt;0) this memory is divided between the SGA and the PGA (the user processes) which in fact, depending on the number of connections, can limit the SGA even more.&lt;br /&gt;
So the first recommendation is to increase the value of memory_target to 4G for example. There is no ideal value, but this would be a reasonable starting value for tuning.&lt;br /&gt;
&lt;br /&gt;
You can do further tuning of the memory using the view V$MEMORY_TARGET_ADVICE.&lt;br /&gt;
The view V$MEMORY_TARGET_ADVICE provides tuning advice for the MEMORY_TARGET initialization parameter:&lt;br /&gt;
SQL&amp;gt; SELECT * FROM v$memory_target_advice ORDER BY memory_size;&lt;br /&gt;
&lt;br /&gt;
The dynamic performance view V$MEMORY_DYNAMIC_COMPONENTS shows the current sizes of all dynamically tuned memory components, including the total sizes of the SGA and instance PGA.&lt;br /&gt;
&lt;br /&gt;
You can also use V$MEMORY_RESIZE_OPS which has a circular history buffer of the last 800 memory resize requests.&lt;br /&gt;
&lt;br /&gt;
2. Since the AMM (you have memory_target&amp;gt;0) is used, then make sure to set:&lt;br /&gt;
 _shared_pool_reserved_pct to 10 or 15 to ensure that when the Shared Pool grows or shrinks automatically, the Reserved Area will change as well.&lt;br /&gt;
&lt;br /&gt;
SQL&amp;gt; alter system set &amp;quot;_shared_pool_reserved_pct&amp;quot;=15 scope=spfile;&lt;br /&gt;
--restart the instance&lt;br /&gt;
&lt;br /&gt;
FYI: By default, Oracle configures a small Reserved Pool (or Reserved Area) inside the Shared Pool.&lt;br /&gt;
This memory can be used for operations such as PL/SQL and trigger compilation or for temporary space while loading Java objects.&lt;br /&gt;
After the memory allocated from the Reserved Pool is freed, it returns to the Reserved Pool.&lt;br /&gt;
5% of the Shared Pool is set aside as the Reserved Pool to handle allocations of memory higher than defined by the hidden parameter _shared_pool_reserved_pct.&lt;br /&gt;
In some application environments, 5% is too small.&lt;br /&gt;
&lt;br /&gt;
3. Set shared_pool_size=500M or even more. This will represent a minimum amount of memory that will always be available to the shared pool.&lt;br /&gt;
If more memory is needed at any moment, if it is available, it will be allocated to the shared pool over the 500M.&lt;br /&gt;
&lt;br /&gt;
Implement the above steps, monitor the database and let us know the result,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORA-00392: log 1 of thread 1 is being cleared, operation not allowed===&lt;br /&gt;
After performing an active duplication, this happened when trying to open the database.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SQL&amp;gt; alter database open resetlogs&lt;br /&gt;
alter database open resetlogs&lt;br /&gt;
*&lt;br /&gt;
ERROR at line 1:&lt;br /&gt;
ORA-00392: log 1 of thread 1 is being cleared, operation not allowed&lt;br /&gt;
ORA-00312: online log 1 thread 1: &amp;#039;/oracle/oradata/testdb/redo/redo01.log&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SQL&amp;gt; select group#,thread#,status from v$log;&lt;br /&gt;
 &lt;br /&gt;
GROUP#   THREAD#   STATUS&lt;br /&gt;
-------  --------- ----------------&lt;br /&gt;
1        1         CLEARING_CURRENT&lt;br /&gt;
2        1         STALE&lt;br /&gt;
3        1         STALE&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Check the alert log! Always a good idea to get extra info. In here we find the answer&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ORA-00344: unable to re-create online log&lt;br /&gt;
&amp;#039;/oracle/oradata/testdb/redo/redo01.log&amp;#039;&lt;br /&gt;
ORA-27040: file create error, unable to create file&lt;br /&gt;
Linux-x86_64 Error: 2: No such file or directory&lt;br /&gt;
Additional information: 1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
So the clue is that the file cannot be created at the operating system level.&amp;lt;br /&amp;gt;&lt;br /&gt;
Doing a &amp;lt;code&amp;gt;df -k /oracle/oradata/testdb/redo&amp;lt;/code&amp;gt; shows us that the filesystem was created too small for the destination database.&amp;lt;br /&amp;gt;&lt;br /&gt;
In this case, we do not want the redolog directory to be as big as on the source db as there will be almost no movement on the destination.&amp;lt;br /&amp;gt;&lt;br /&gt;
I should have specified the LOGFILE parameter in the DUPLICATE clause to setup new, smaller redolog files.&amp;lt;br /&amp;gt;&lt;br /&gt;
As this duplicate takes over 12 hours, I didn&amp;#039;t want to do it again so I created symbolic links in the redolog directory pointing out to a larger filesystem with more space.&amp;lt;br /&amp;gt;&lt;br /&gt;
This allowed the creation of the redolog files. They can then be resized once the database has been opened.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cd /oracle/oradata/testdb/redo&lt;br /&gt;
ln -s /tmp/redo01.log redo01.log&lt;br /&gt;
ln -s /tmp/redo02.log redo02.log&lt;br /&gt;
ln -s /tmp/redo03.log redo03.log&lt;br /&gt;
&lt;br /&gt;
SQL&amp;gt; alter database open resetlogs&lt;br /&gt;
Database opened.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===RMAN-04004: error from recovery catalog database: ORA-01017: invalid username/password; logon denied===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
oracle@host:/export/home/ora&amp;gt; rman target / catalog catowner/catpass@catdb&lt;br /&gt;
&lt;br /&gt;
Recovery Manager: Release 11.2.0.2.0 - Production on Thu Jun 12 16:51:03 2014&lt;br /&gt;
&lt;br /&gt;
Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.&lt;br /&gt;
&lt;br /&gt;
connected to target database: XXXXRAP1 (DBID=3557010742)&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-00554: initialization of internal recovery manager package failed&lt;br /&gt;
RMAN-04004: error from recovery catalog database: ORA-01017: invalid username/password; logon denied&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This is normally very straight-forward and self-explanatory.&amp;lt;br /&amp;gt;&lt;br /&gt;
The puzzle here is that a connection from SQL*Plus works!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sqlplus catowner/catpass@catdb&lt;br /&gt;
&lt;br /&gt;
SQL*Plus: Release 11.2.0.2.0 Production on Thu Jun 12 16:53:18 2014&lt;br /&gt;
&lt;br /&gt;
Copyright (c) 1982, 2010, Oracle.  All rights reserved.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Connected to:&lt;br /&gt;
Oracle Database 12c Enterprise Edition Release 12.1.0.1.0 - 64bit Production&lt;br /&gt;
With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options&lt;br /&gt;
SQL&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Eventually worked out that the rman binary in the databases ORACLE_HOME on the source machine needed relinking!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cd $ORACLE_HOME/rdbms/lib&lt;br /&gt;
make -f ins_rdbms.mk irman &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORA-00230: operation disallowed: snapshot control file enqueue unavailable===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
waiting for snapshot control file enqueue&lt;br /&gt;
waiting for snapshot control file enqueue&lt;br /&gt;
waiting for snapshot control file enqueue&lt;br /&gt;
waiting for snapshot control file enqueue&lt;br /&gt;
cannot make a snapshot control file&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-03008: error while performing automatic resync of recovery catalog&lt;br /&gt;
ORA-00230: operation disallowed: snapshot control file enqueue unavailable&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
From the doc...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
When RMAN needs to back up or resynchronize from the control file, it first creates a snapshot or consistent image of the control file.&lt;br /&gt;
If one RMAN job is already backing up the control file while another needs to create a new snapshot control file, then you may see the following message:&lt;br /&gt;
&lt;br /&gt;
waiting for snapshot controlfile enqueue&lt;br /&gt;
&lt;br /&gt;
Under normal circumstances, a job that must wait for the control file enqueue waits for a brief interval and then successfully obtains the enqueue.&lt;br /&gt;
RMAN makes up to five attempts to get the enqueue and then fails the job.&lt;br /&gt;
The conflict is usually caused when two jobs are both backing up the control file, and the job that first starts backing up the control file waits for service from the media manager.&lt;br /&gt;
&lt;br /&gt;
To determine which job is holding the conflicting enqueue:&lt;br /&gt;
&lt;br /&gt;
    After you see the first message stating &amp;quot;RMAN-08512: waiting for snapshot controlfile enqueue&amp;quot;, start a new SQL*Plus session on the target database:&lt;br /&gt;
&lt;br /&gt;
    % sqlplus &amp;#039;SYS/oracle@trgt AS SYSDBA&amp;#039;&lt;br /&gt;
&lt;br /&gt;
    Execute the following query to determine which job is causing the wait:&lt;br /&gt;
&lt;br /&gt;
    SELECT s.SID, USERNAME AS &amp;quot;User&amp;quot;, PROGRAM, MODULE, &lt;br /&gt;
           ACTION, LOGON_TIME &amp;quot;Logon&amp;quot;, l.* &lt;br /&gt;
    FROM V$SESSION s, V$ENQUEUE_LOCK l&lt;br /&gt;
    WHERE l.SID = s.SID&lt;br /&gt;
    AND l.TYPE = &amp;#039;CF&amp;#039;&lt;br /&gt;
    AND l.ID1 = 0&lt;br /&gt;
    AND l.ID2 = 2;&lt;br /&gt;
&lt;br /&gt;
    You should see output similar to the following (the output in this example has been truncated):&lt;br /&gt;
&lt;br /&gt;
    SID User Program              Module                    Action           Logon&lt;br /&gt;
    --- ---- -------------------- ------------------------- ---------------- ---------&lt;br /&gt;
      9 SYS  rman@h13 (TNS V1-V3) backup full datafile: c1  0000210 STARTED  21-JUN-01&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
After you have determined which job is creating the enqueue, you can do one of the following:&lt;br /&gt;
&lt;br /&gt;
    Wait until the job creating the enqueue completes&lt;br /&gt;
    Cancel the current job and restart it after the job creating the enqueue completes&lt;br /&gt;
    Cancel the job creating the enqueue&lt;br /&gt;
&lt;br /&gt;
Commonly, enqueue situations occur when a job is writing to a tape drive, but the tape drive is waiting for a new cassette to be inserted.&lt;br /&gt;
If you start a new job in this situation, then you will probably receive the enqueue message because the first job cannot complete until the new tape is loaded.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or more directly...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 2000&lt;br /&gt;
col killer     for a70&lt;br /&gt;
col program    for a20&lt;br /&gt;
col module     for a20&lt;br /&gt;
col action     for a20&lt;br /&gt;
col logon_time for a20&lt;br /&gt;
select &amp;#039;alter system disconnect session &amp;#039;&amp;#039;&amp;#039;||s.sid||&amp;#039;,&amp;#039;||s.serial#||&amp;#039;&amp;#039;&amp;#039; immediate;&amp;#039; killer&lt;br /&gt;
,      username&lt;br /&gt;
,      program&lt;br /&gt;
,      module&lt;br /&gt;
,      action&lt;br /&gt;
,      logon_time&lt;br /&gt;
from   v$session s&lt;br /&gt;
,      v$enqueue_lock l&lt;br /&gt;
where  l.sid  = s.sid&lt;br /&gt;
and    l.type = &amp;#039;cf&amp;#039;&lt;br /&gt;
and    l.id1  = 0&lt;br /&gt;
and    l.id2  = 2&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORA-19511: non RMAN, but media manager or vendor specific failure, error text:===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-03002: failure of Duplicate Db command at 05/01/2018 14:23:09&lt;br /&gt;
RMAN-05501: aborting duplication of target database&lt;br /&gt;
RMAN-03015: error occurred in stored script Memory Script&lt;br /&gt;
ORA-27191: sbtinfo2 returned error&lt;br /&gt;
Additional information: 3586&lt;br /&gt;
ORA-19511: non RMAN, but media manager or vendor specific failure, error text:&lt;br /&gt;
   Unable to connect to NetWorker server &amp;#039;hn6000.cln.be&amp;#039; because &amp;#039;Authentication error; why = Invalid client credential&amp;#039;. (2:10:79)&lt;br /&gt;
&lt;br /&gt;
Recovery Manager complete.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
If this happens, check to see if the nsr daemon is running...&amp;lt;br /&amp;gt;&lt;br /&gt;
Good system:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/home/oracle&amp;gt; ps -ef | grep nsr&lt;br /&gt;
    root  5701836        1   0   Mar 16      - 13:18 /bin/nsrexecd&lt;br /&gt;
  oracle 18809292 22741502   0 15:03:58  pts/0  0:00 grep nsr&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Bad system:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 /home/oracle&amp;gt; ps -ef | grep nsr&lt;br /&gt;
  oracle 14745986 15139292   0 15:03:29  pts/2  0:00 grep nsr&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORA-19554: error allocating device, device type: SBT_TAPE, device name:===&lt;br /&gt;
If using Cygwin...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-03002: failure of backup command at 05/19/2015 12:25:47&lt;br /&gt;
ORA-19554: error allocating device, device type: SBT_TAPE, device name:&lt;br /&gt;
ORA-27000: skgfqsbi: failed to initialize storage subsystem (SBT) layer&lt;br /&gt;
OSD-02534: Message 2534 not found;  product=RDBMS; facility=SOSD&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Check the tdpo.opt file is where you think it is!&lt;br /&gt;
* Check the path to the opt file looks like this (needs to be Windows format):&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
CONFIGURE CHANNEL DEVICE TYPE &amp;#039;SBT_TAPE&amp;#039; FORMAT   &amp;#039;LOG_%d_t%t_s%s_u%U&amp;#039; PARMS  &amp;#039;ENV=(TDPO_OPTFILE=E:\oracle\KITRYD\admin\tdpo.opt)&amp;#039;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Check the content of the opt file is Windows format paths!&lt;br /&gt;
&lt;br /&gt;
===RMAN-20033: control file SEQUENCE# too low===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-03008: error while performing automatic resync of recovery catalog&lt;br /&gt;
===RMAN-20033: control file SEQUENCE# too low===&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
From [https://forums.oracle.com/forums/thread.jspa?threadID=1115969 forums.oracle.com]&amp;lt;br /&amp;gt;&lt;br /&gt;
This error generally happens if an archivelog backup happens while the RMAN database backup is running and if controlfile autobackup is configured.&amp;lt;br /&amp;gt;&lt;br /&gt;
The database backup is usually successful and it is just the controlfile backup that fails.&lt;br /&gt;
===ORA-27302: failure occurred at: slgpn===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
RMAN-03009: failure of Control File and SPFILE Autobackup command on c1 channel at 06/28/2011 18:59:38&lt;br /&gt;
ORA-19715: invalid format %b for generated name&lt;br /&gt;
ORA-27302: failure occurred at: slgpn&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Problem====&lt;br /&gt;
When doing a &amp;quot;&amp;lt;tt&amp;gt;backup as copy database&amp;lt;/tt&amp;gt;&amp;quot;, got these errors after 145 of 147 datafiles had been backed up!&lt;br /&gt;
&lt;br /&gt;
====Investigation====&lt;br /&gt;
I had read [https://oracleedge.wordpress.com/2011/06/29/oracle-rman-03009-ora-19715-ora-27302/ elsewhere] that this could be something to do with the format of the autobackup of the control file so I changed the format as suggested and reran the backup.&amp;lt;br /&amp;gt;&lt;br /&gt;
No luck. It ended exactly the same way after 145 files. I decided to compare the original list of datafiles with those that had been backed up in order to track down the 2 failures. Maybe I could see something odd with them.&amp;lt;br /&amp;gt;&lt;br /&gt;
Sure enough, these 2 files were different... there was a space at the &amp;#039;&amp;#039;&amp;#039;end&amp;#039;&amp;#039;&amp;#039; of the filenames :-)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select &amp;#039;x&amp;#039;||file_name||&amp;#039;x&amp;#039;&lt;br /&gt;
from   dba_data_files&lt;br /&gt;
where  file_name like &amp;#039;% %&amp;#039;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Solution====&lt;br /&gt;
Run the backup of the other 2 datafiles with a different format that did not rely on the filename.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
run {&lt;br /&gt;
    allocate channel c1 device type disk format &amp;#039;/path/to/datafiles/%U&amp;#039;;&lt;br /&gt;
    backup as copy datafile 170;&lt;br /&gt;
    backup as copy datafile 171;&lt;br /&gt;
    backup as copy current controlfile;&lt;br /&gt;
    release channel c1;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The other 145 datafiles were backed up with a format of &amp;#039;/path/to/datafiles/%b&amp;#039; which preserves the filenames so all that needs to be done is rename the other 2 after the backup finishes.&amp;lt;br /&amp;gt;&lt;br /&gt;
If they are going to be used in a restore scenario, they should be renamed in the controlfile also.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter database rename file &amp;#039;/path/to/datafiles/filename_with_a_space_at_end &amp;#039; to &amp;#039;/path/to/datafiles/filename_without_a_space&amp;#039;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===RMAN errors after crosscheck backup and delete noprompt obsolete and delete noprompt expired backup===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
RMAN-06207: WARNING: 3921 objects could not be deleted for SBT_TAPE channel(s) due&lt;br /&gt;
RMAN-06208:          to mismatched status.  Use CROSSCHECK command to fix status&lt;br /&gt;
RMAN-06210: List of Mismatched objects&lt;br /&gt;
RMAN-06211: ==========================&lt;br /&gt;
RMAN-06212:   Object Type   Filename/Handle&lt;br /&gt;
RMAN-06213: --------------- ---------------------------------------------------&lt;br /&gt;
RMAN-06214: Backup Piece    DB_SID_t20140316_s263889_umhp3bpa7_1_1&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Use the FORCE option with the DELETE command&amp;lt;br /&amp;gt;&lt;br /&gt;
The FORCE command tells RMAN to clean the information out of the catalog regardless of whether it can find it on the media or not.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
delete force noprompt expired backup;&lt;br /&gt;
delete force noprompt obsolete;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===RMAN-06004: ORACLE error from recovery catalog database: RMAN-20003: target database incarnation not found in recovery catalog===&lt;br /&gt;
====Problem:====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-03002: failure of Duplicate Db command at 12/05/2017 11:11:15&lt;br /&gt;
RMAN-05501: aborting duplication of target database&lt;br /&gt;
RMAN-03015: error occurred in stored script Memory Script&lt;br /&gt;
RMAN-06004: ORACLE error from recovery catalog database: RMAN-20003: target database incarnation not found in recovery catalog&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Solution:====&lt;br /&gt;
Strangely, this means, in my particular case, that block change tracking is turned on in the target databse and needs turning off in the auxiliary while the DUPLICATE is running.&amp;lt;br /&amp;gt;&lt;br /&gt;
It must be done while the auxiliary is in mount mode and restoring the datafiles (before recovery starts)&amp;lt;br /&amp;gt;&lt;br /&gt;
It is reported to be a bug fixed in 11.1 but somehow, we&amp;#039;re still (sometimes) getting it in 12.1.0.2.&lt;br /&gt;
&lt;br /&gt;
===RMAN-06059: expected archived log not found, loss of archived log compromises recoverability===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
RMAN-06059: expected archived log not found, loss of archived log compromises recoverability&lt;br /&gt;
ORA-19625: error identifying file &amp;lt;filename&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This error can come from the fact that the database files (more likely archivelogs) are being deleted by the operating system so RMAN has no clue of their whereabouts.&amp;lt;br /&amp;gt;&lt;br /&gt;
Possibly result of a database duplication and the catalog has not updated properly?&amp;lt;br /&amp;gt;&lt;br /&gt;
====Solution====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
crosscheck archivelog all;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
And then maybe take a backup to be on the safe side.&lt;br /&gt;
&lt;br /&gt;
===RMAN-05537: DUPLICATE without TARGET connection when auxiliary instance is started with spfile cannot use SPFILE clause===&lt;br /&gt;
====Problem:====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-03002: failure of Duplicate Db command at 12/05/2017 14:17:49&lt;br /&gt;
RMAN-05501: aborting duplication of target database&lt;br /&gt;
RMAN-05537: DUPLICATE without TARGET connection when auxiliary instance is started with spfile cannot use SPFILE clause&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Usually happens after restarting a failed RMAN DUPLICATE database. The spfile has been regenerated on the auxiliary to a level where it has too much detail in it.&lt;br /&gt;
====Solution:====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ cd $ORACLE_HOME/dbs&lt;br /&gt;
$ ls -altr *dwh_perf*&lt;br /&gt;
-rw-r-----    1 oracle   oinstall   17645568 Aug  3 13:34 snapcf_dwh_perf.f&lt;br /&gt;
-rw-r-----    1 oracle   oinstall       7680 Nov  4 09:22 orapwdwh_perf&lt;br /&gt;
-rw-r--r--    1 oracle   oinstall        104 Dec  5 09:34 initdwh_perf.ora&lt;br /&gt;
-rw-r-----    1 oracle   oinstall       6656 Dec  5 11:11 spfiledwh_perf.ora&lt;br /&gt;
-rw-rw----    1 oracle   oinstall       1544 Dec  5 14:18 hc_dwh_perf.dat&lt;br /&gt;
$ mv hc_dwh_perf.dat hc_dwh_perf.dat.old&lt;br /&gt;
$ mv spfiledwh_perf.ora spfiledwh_perf.ora.old&lt;br /&gt;
$ cat initdwh_perf.ora&lt;br /&gt;
sga_max_size=&amp;#039;6G&amp;#039;&lt;br /&gt;
sga_target=&amp;#039;6G&amp;#039;&lt;br /&gt;
compatible=&amp;#039;12.0.0&amp;#039;&lt;br /&gt;
db_files=&amp;#039;500&amp;#039;&lt;br /&gt;
&lt;br /&gt;
# Instance name&lt;br /&gt;
db_name=dwh_perf&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Re-run the DUPLICATE. It should zoom past the already recovered datafiles.&lt;br /&gt;
&lt;br /&gt;
===PSDRPC returns significant error 1013===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
archived log thread=1 sequence=195008&lt;br /&gt;
channel t2: reading from backup piece arclog_LBK_4260753020_946042770_479194_1&lt;br /&gt;
channel t0: piece handle=arclog_LBK_4260753020_946042770_479192_1 tag=TAG20170607T133757&lt;br /&gt;
channel t0: restored backup piece 1&lt;br /&gt;
channel t0: restore complete, elapsed time: 00:00:35&lt;br /&gt;
archived log file name=/xxxxxx/acc/ora_bin2/app/oracle/product/11.2.0.4/dbhome_1/dbs/arch1_195006_815790039.dbf thread=1 sequence=195006&lt;br /&gt;
PSDRPC returns significant error 1013.&lt;br /&gt;
PSDRPC returns significant error 1013.&lt;br /&gt;
released channel: t0&lt;br /&gt;
released channel: t1&lt;br /&gt;
released channel: t2&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-03002: failure of Duplicate Db command at 06/09/2017 15:15:04&lt;br /&gt;
RMAN-05501: aborting duplication of target database&lt;br /&gt;
RMAN-03015: error occurred in stored script Memory Script&lt;br /&gt;
RMAN-11003: failure during parse/execution of SQL statement: alter database recover logfile &amp;#039;/xxxxxx/acc/ora_bin2/app/oracle/product/11.2.0.4/dbhome_1/dbs/arch1_195006_815790039.dbf&amp;#039;&lt;br /&gt;
ORA-10877: error signaled in parallel recovery slave&lt;br /&gt;
&lt;br /&gt;
Recovery Manager complete.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Action====&lt;br /&gt;
Check the alert log on the auxiliary instance.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ORA-279 signalled during: alter database recover logfile &amp;#039;/xxxxxx/acc/ora_bin2/app/oracle/product/11.2.0.4/dbhome_1/dbs/arch1_195005_815790039.dbf&amp;#039;...&lt;br /&gt;
alter database recover logfile &amp;#039;/xxxxxx/acc/ora_bin2/app/oracle/product/11.2.0.4/dbhome_1/dbs/arch1_195006_815790039.dbf&amp;#039;&lt;br /&gt;
Media Recovery Log /xxxxxx/acc/ora_bin2/app/oracle/product/11.2.0.4/dbhome_1/dbs/arch1_195006_815790039.dbf&lt;br /&gt;
Fri Jun 09 07:30:30 2017&lt;br /&gt;
Errors with log /xxxxxx/acc/ora_bin2/app/oracle/product/11.2.0.4/dbhome_1/dbs/arch1_195006_815790039.dbf&lt;br /&gt;
Recovery interrupted!&lt;br /&gt;
Recovered data files to a consistent state at change 238029030495&lt;br /&gt;
Media Recovery failed with error 19755&lt;br /&gt;
Errors in file /xxxxxx/acc/ora_bin2/app/oracle/diag/rdbms/lbkro/lbkro/trace/lbkro_pr00_13108374.trc:&lt;br /&gt;
ORA-00283: recovery session canceled due to errors&lt;br /&gt;
===&amp;gt;ORA-19755: could not open change tracking file&lt;br /&gt;
===&amp;gt;ORA-19750: change tracking file: &amp;#039;/xxxxxx/exp/ora_data2/lbk/data/bct_lbk_do_not_delete.f&lt;br /&gt;
===&amp;gt;ORA-27037: unable to obtain file status&lt;br /&gt;
===&amp;gt;IBM AIX RISC System/6000 Error: 2: No such file or directory&lt;br /&gt;
Additional information: 3&lt;br /&gt;
Fri Jun 09 07:30:36 2017&lt;br /&gt;
ORA-10877 signalled during: alter database recover logfile &amp;#039;/xxxxxx/acc/ora_bin2/app/oracle/product/11.2.0.4/dbhome_1/dbs/arch1_195006_815790039.dbf&amp;#039;...&lt;br /&gt;
Fri Jun 09 14:04:57 2017&lt;br /&gt;
alter database recover logfile &amp;#039;/xxxxxx/acc/ora_bin2/app/oracle/product/11.2.0.4/dbhome_1/dbs/arch1_195006_815790039.dbf&amp;#039;&lt;br /&gt;
Media Recovery Log /xxxxxx/acc/ora_bin2/app/oracle/product/11.2.0.4/dbhome_1/dbs/arch1_195006_815790039.dbf&lt;br /&gt;
Media Recovery failed with error 1112&lt;br /&gt;
ORA-283 signalled during: alter database recover logfile &amp;#039;/xxxxxx/acc/ora_bin2/app/oracle/product/11.2.0.4/dbhome_1/dbs/arch1_195006_815790039.dbf&amp;#039;...&lt;br /&gt;
Fri Jun 09 14:31:20 2017&lt;br /&gt;
Shutting down instance (immediate)&lt;br /&gt;
Shutting down instance: further logons disabled&lt;br /&gt;
Stopping background process MMNL&lt;br /&gt;
Stopping background process MMON&lt;br /&gt;
License high water mark = 49&lt;br /&gt;
ALTER DATABASE CLOSE NORMAL&lt;br /&gt;
ORA-1109 signalled during: ALTER DATABASE CLOSE NORMAL...&lt;br /&gt;
ALTER DATABASE DISMOUNT&lt;br /&gt;
Shutting down archive processes&lt;br /&gt;
Archiving is disabled&lt;br /&gt;
Completed: ALTER DATABASE DISMOUNT&lt;br /&gt;
ARCH: Archival disabled due to shutdown: 1089&lt;br /&gt;
Shutting down archive processes&lt;br /&gt;
Archiving is disabled&lt;br /&gt;
ARCH: Archival disabled due to shutdown: 1089&lt;br /&gt;
Shutting down archive processes&lt;br /&gt;
Archiving is disabled&lt;br /&gt;
Fri Jun 09 14:31:24 2017&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This is a known bug. it is fixed in 11.2.0.3 but... this customer does not apply patches!&lt;br /&gt;
&lt;br /&gt;
====Solution====&lt;br /&gt;
While the DUPLICATE is running (and in MOUNT mode), log on to the auxiliary instance and disable block change tracking.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter database disable block change tracking;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
A documented workaround is to set db_filename_convert parameter in the DUPLICATE clause of the run block but I tried this and it failed again.&amp;lt;br /&amp;gt;&lt;br /&gt;
The obvious solution is to patch the database but...&lt;br /&gt;
&lt;br /&gt;
===Database trigger to capture ORA errors===&lt;br /&gt;
From [http://ora-ssn.blogspot.be/2011/10/trigger-on-database-to-capture-ora.html ora-ssn.blogspot.be]&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
CREATE TABLE stats$error_log (&lt;br /&gt;
        err_dt          TIMESTAMP,&lt;br /&gt;
        db_user         VARCHAR2(30),&lt;br /&gt;
        msg_stack       VARCHAR2(2000),&lt;br /&gt;
        sqltxt          VARCHAR2(1000))&lt;br /&gt;
tablespace users;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Now, create a trigger on the database server.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
CREATE OR REPLACE TRIGGER log_server_errors&lt;br /&gt;
  AFTER SERVERERROR&lt;br /&gt;
  ON DATABASE&lt;br /&gt;
DECLARE&lt;br /&gt;
          v_sqltext VARCHAR2(1000);&lt;br /&gt;
          nl_sqltext ora_name_list_t;&lt;br /&gt;
  BEGIN&lt;br /&gt;
          -- Capture entire error text&lt;br /&gt;
          FOR i IN 1 .. ora_sql_txt(nl_sqltext) LOOP&lt;br /&gt;
            v_sqltext := v_sqltext || nl_sqltext(i);&lt;br /&gt;
          END LOOP;&lt;br /&gt;
          INSERT INTO STATS$ERROR_LOG&lt;br /&gt;
          (err_dt, db_user, msg_stack, sqltxt)&lt;br /&gt;
          VALUES&lt;br /&gt;
          (systimestamp,&lt;br /&gt;
           sys.login_user,&lt;br /&gt;
           dbms_utility.format_error_stack, v_sqltext);&lt;br /&gt;
  END log_server_errors;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORA-19809: limit exceeded for recovery files===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-03009: failure of backup command on ORA_DISK_1 channel at 07/15/2013 10:10:59&lt;br /&gt;
ORA-19809: limit exceeded for recovery files&lt;br /&gt;
ORA-19804: cannot reclaim 274716160 bytes disk space from 1468006400 limit&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    ORA-19809: limit exceeded for recovery files&lt;br /&gt;
    Cause: The limit for recovery files specified by the db_recovery_file_dest_size was exceeded.&lt;br /&gt;
&lt;br /&gt;
    Action: The error is accompanied by 19804. See message 19804 for further details&lt;br /&gt;
&lt;br /&gt;
    ORA-19804: cannot reclaim string bytes disk space from string limit&lt;br /&gt;
    Cause: Oracle cannot reclaim disk space of specified bytes from the DB_RECOVERY_FILE_DEST_SIZE limit.&lt;br /&gt;
&lt;br /&gt;
    Action: There are five possible solutions:&lt;br /&gt;
       1) Take frequent backup of recovery area using RMAN.&lt;br /&gt;
       2) Consider changing RMAN retention policy.&lt;br /&gt;
       3) Consider changing RMAN archivelog deletion policy.&lt;br /&gt;
       4) Add disk space and increase DB_RECOVERY_FILE_DEST_SIZE.&lt;br /&gt;
       5) Delete files from recovery area using RMAN.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The solution here is to increase the value of db_recovery_file_dest_size but it might also indicate a problem with tapes if the archivelogs are being backed up to tape via tdpo.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SYS@DN7&amp;gt; alter system set db_recovery_file_dest_size=4000M scope=both;&lt;br /&gt;
&lt;br /&gt;
System altered.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Looking into int further, saw RMAN parameters missing...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
CONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF 14 DAYS;&lt;br /&gt;
CONFIGURE BACKUP OPTIMIZATION OFF;&lt;br /&gt;
CONFIGURE DEFAULT DEVICE TYPE TO &amp;#039;SBT_TAPE&amp;#039;;&lt;br /&gt;
CONFIGURE CONTROLFILE AUTOBACKUP ON;&lt;br /&gt;
CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE &amp;#039;SBT_TAPE&amp;#039; TO &amp;#039;LOG_%d_controlfile_%F.rman&amp;#039;;&lt;br /&gt;
CONFIGURE DEVICE TYPE &amp;#039;SBT_TAPE&amp;#039; PARALLELISM 1 BACKUP TYPE TO BACKUPSET;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===RMAN-00554: initialization of internal recovery manager package failed===&lt;br /&gt;
Getting this error after migrating a database from one machine to another and attaching to a nice new version 12c catalog on the new server&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Recovery Manager: Release 11.2.0.2.0 - Production on Sat Jun 21 13:16:24 2014&lt;br /&gt;
&lt;br /&gt;
Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.&lt;br /&gt;
&lt;br /&gt;
connected to target database: SPMSUPP1 (DBID=3026014394)&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-00554: initialization of internal recovery manager package failed&lt;br /&gt;
RMAN-04004: error from recovery catalog database: ORA-01017: invalid username/password; logon denied&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
We cannot connect to the catalog via rman but there is no problem if connecting via SQL*Plus!&amp;lt;br /&amp;gt;&lt;br /&gt;
Solution: relink the rman executable.&lt;br /&gt;
===Using AIX commands genld, genkld and slibclean to avoid library file locking errors (libjox) (Doc ID 739963.1)===&lt;br /&gt;
* [https://support.oracle.com/epmos/faces/DocumentDisplay?_afrLoop=206851390914720&amp;amp;id=739963.1&amp;amp;_afrWindowMode=0&amp;amp;_adf.ctrl-state=e0pq23tou_4 Metalink]&lt;br /&gt;
When installing interim (one-off) patches, CPU patches or patchsets, you may encounter some errors with regards to files being locked or oui/opatch being unable to copy files&amp;lt;br /&amp;gt;&lt;br /&gt;
even though the databases, listeners and all other Oracle processes associated with the ORACLE_HOME to be patched were stopped.&amp;lt;br /&amp;gt;&lt;br /&gt;
This could be as result of a process which requires termination or an additional file needing to be unloaded from the system cache.&amp;lt;br /&amp;gt;&lt;br /&gt;
Run following commands to clean up...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
genld -l | grep &amp;lt;ORACLE_HOME&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
If genld returns data then a currently executing process has something open in the ORACLE_HOME directory, therefore terminate the process as required/recommended.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
genkld | grep &amp;lt;ORACLE_HOME&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
If the genkld command  returns a  list of shared objects currently loaded onto the OS system cache then please remove the entries from the OS system cache by running the slibclean command as root user:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/usr/sbin/slibclean&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===ORA-20011: Approximate NDV failed: ORA-29913: error in executing ODCIEXTTABLEOPEN callout===&lt;br /&gt;
This seems to be related to orphaned Datapump tables. Generally seems to be a problem when stats jobs are running during the night (dbms_stats)&amp;lt;br /&amp;gt;&lt;br /&gt;
* Check no datapump jobs are running&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select * from dba_datapump_jobs;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Find orphaned tables&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 2000&lt;br /&gt;
select owner&lt;br /&gt;
,      object_name&lt;br /&gt;
,      object_type&lt;br /&gt;
,      status&lt;br /&gt;
,      to_char(created,&amp;#039;dd-mon-yyyy hh24:mi:ss&amp;#039;) created&lt;br /&gt;
,      to_char(last_ddl_time,&amp;#039;dd-mon-yyyy hh24:mi:ss&amp;#039;) last_ddl_time&lt;br /&gt;
from   dba_objects&lt;br /&gt;
where  1=1&lt;br /&gt;
and    object_name like &amp;#039;ET$%&amp;#039;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Check that  any rows seen are actually external tables&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select owner&lt;br /&gt;
,      table_name&lt;br /&gt;
,      default_directory_name&lt;br /&gt;
,      access_type&lt;br /&gt;
from   dba_external_tables&lt;br /&gt;
order  by 1,2&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Drop the tables if they are not currently being used (no datapump jobs running)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
drop table &amp;amp;&amp;amp;owner..&amp;amp;table_name;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===ORA-01547: warning: RECOVER succeeded but OPEN RESETLOGS would get error below===&lt;br /&gt;
Database is restored and now we want to recover it but we see this...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Starting recover at 24-JUL-15 11:26:19&lt;br /&gt;
&lt;br /&gt;
starting media recovery&lt;br /&gt;
&lt;br /&gt;
unable to find archive log&lt;br /&gt;
archive log thread=1 sequence=69763&lt;br /&gt;
Oracle Error: &lt;br /&gt;
ORA-01547: warning: RECOVER succeeded but OPEN RESETLOGS would get error below&lt;br /&gt;
ORA-01194: file 1 needs more recovery to be consistent&lt;br /&gt;
ORA-01110: data file 1: &amp;#039;/oracle/TRSCRP1/oradata2/system01.dbf&amp;#039;&lt;br /&gt;
&lt;br /&gt;
released channel: c1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This means that although we have restored the database, we are still missing information to complete the recovery. This information is contained in the archived redo logs which must also be restored (from tape if they are no longer on disk)&amp;lt;br /&amp;gt;&lt;br /&gt;
We can see here that we need an archive log with sequence number 69763. But what is the file called and where should it be restored to?&amp;lt;br /&amp;gt;&lt;br /&gt;
For this we can go to SQL*Plus and get the database to tell us&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
recover database using backup controlfile until cancel;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
and cancel straight away.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ORA-00279: change 13796376414661 generated at 07/14/2015 13:20:07 needed for&lt;br /&gt;
thread 1&lt;br /&gt;
ORA-00289: suggestion : /oracle/TRSCRP1/archive/arch_TRSCRP1_1_69763.arc&lt;br /&gt;
ORA-00280: change 13796376414661 for thread 1 is in sequence #69763&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Specify log: {&amp;lt;RET&amp;gt;=suggested | filename | AUTO | CANCEL}&lt;br /&gt;
cancel&lt;br /&gt;
ORA-01547: warning: RECOVER succeeded but OPEN RESETLOGS would get error below&lt;br /&gt;
ORA-01194: file 1 needs more recovery to be consistent&lt;br /&gt;
ORA-01110: data file 1: &amp;#039;/oracle/TRSCRP1/oradata2/system01.dbf&amp;#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
ORA-01112: media recovery not started&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Now we see that we need to find a file called arch_TRSCRP1_1_69763.arc and put it in the directory /oracle/TRSCRP1/archive.&amp;lt;br /&amp;gt;&lt;br /&gt;
This will continue up until the time specified for the recover so restore a whole bunch of them.&amp;lt;br /&amp;gt;&lt;br /&gt;
Repeat the &amp;quot;recover database using backup controlfile until cancel;&amp;quot; command and type AUTO or Enter until you&amp;#039;ve got to where you need to be.&amp;lt;br /&amp;gt;&lt;br /&gt;
Type CANCEL when point is reached and&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter database open resetlogs;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Stuart</name></author>	</entry>

	<entry>
		<id>https://mailnest.com/dbawiki/index.php?title=Oracle_errors&amp;diff=3363</id>
		<title>Oracle errors</title>
		<link rel="alternate" type="text/html" href="https://mailnest.com/dbawiki/index.php?title=Oracle_errors&amp;diff=3363"/>
				<updated>2018-11-03T17:26:31Z</updated>
		
		<summary type="html">&lt;p&gt;Stuart: /* ORA-14097: column type or size mismatch in ALTER TABLE EXCHANGE PARTITION */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;===ORA-00600===&lt;br /&gt;
[https://support.oracle.com/epmos/faces/DocContentDisplay?_afrLoop=397490397952859&amp;amp;id=1092832.1&amp;amp;_afrWindowMode=0&amp;amp;_adf.ctrl-state=184vwc6g3y_4 Master Note for Diagnosing ORA-600 (Doc ID 1092832.1)]&lt;br /&gt;
===ORA-19051: Cannot use fast path insert for this XMLType table===&lt;br /&gt;
Think LD_LIBRARY_PATH on Linux or LIBPATH on AIX.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Export: Release 11.2.0.4.0 - Production on Thu Jun 1 06:41:55 2017&lt;br /&gt;
&lt;br /&gt;
Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.&lt;br /&gt;
&lt;br /&gt;
Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production&lt;br /&gt;
With the Partitioning, OLAP, Data Mining and Real Application Testing options&lt;br /&gt;
Starting &amp;quot;DWH_EXPORT&amp;quot;.&amp;quot;SYS_EXPORT_TABLE_03&amp;quot;:  dwh_export/******** parfile=cadis_foto_export_credit_dba.par&lt;br /&gt;
Estimate in progress using BLOCKS method...&lt;br /&gt;
Processing object type TABLE_EXPORT/TABLE/TABLE_DATA&lt;br /&gt;
Total estimation using BLOCKS method: 64.08 GB&lt;br /&gt;
ORA-39126: Worker unexpected fatal error in KUPW$WORKER.FETCH_XML_OBJECTS []&lt;br /&gt;
ORA-19051: Cannot use fast path insert for this XMLType table&lt;br /&gt;
&lt;br /&gt;
ORA-06512: at &amp;quot;SYS.DBMS_SYS_ERROR&amp;quot;, line 86&lt;br /&gt;
ORA-06512: at &amp;quot;SYS.KUPW$WORKER&amp;quot;, line 9710&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Problem====&lt;br /&gt;
When the 11g DB was started, LD_LIBRARY_PATH and LIBPATH were still pointing to paths in the 10g Home.&lt;br /&gt;
====Solution====&lt;br /&gt;
There may have been some odd values setup in LD_LIBRARY_PATH before the call to oraenv (if oraenv was indeed called!)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
unset LD_LIBRARY_PATH LIBPATH&lt;br /&gt;
export ORACLE_SID=&amp;lt;correct 11g SID&amp;gt;&lt;br /&gt;
. oraenv&lt;br /&gt;
echo $LD_LIBRARY_PATH&lt;br /&gt;
echo $LIBPATH&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
They should now be correct.&lt;br /&gt;
&lt;br /&gt;
===ORA-27092: size of file exceeds file size limit of the process===&lt;br /&gt;
Think ulimit...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Cause: an attempt was made to open a file that exceeds the process&amp;#039;s file size limit (ulimit), additional information shows the current limit (logical blocks) and the size of the file (logical blocks)&lt;br /&gt;
Action: increase the processes file size limit (ulimit) and retry&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
truncate table pibadm.test_ph&lt;br /&gt;
                      *&lt;br /&gt;
Error at line 1 :&lt;br /&gt;
ORA-00604: error ocurred at recursive SQL level 1&lt;br /&gt;
ORA-01116: error in opening database file 2&lt;br /&gt;
ORA-01110: datafile 2 : &amp;#039;/opt/u01/data/PIBQA/UNDO_01.dbf&amp;#039;&lt;br /&gt;
ORA-27092: size of file exceeds file size limit of the process&lt;br /&gt;
Additional information: 262143&lt;br /&gt;
Additional information: 2621441&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Check the fs_size limit for this user in /etc/security/limits&amp;lt;br /&amp;gt;&lt;br /&gt;
Compare this with another user, say oracle. Probably -1 (unlimited)&lt;br /&gt;
&lt;br /&gt;
===SP2-1503: Unable to initialize Oracle call interface===&lt;br /&gt;
When trying to login to the database via SQL*Plus, these messages a displayed&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
hn5118 /home/oracle $sqlplus / as sysdba&lt;br /&gt;
SP2-1503: Unable to initialize Oracle call interface&lt;br /&gt;
SP2-0152: ORACLE may not be functioning properly&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Seems to be a problem unique to AIX (in this case).&amp;lt;br /&amp;gt;&lt;br /&gt;
Check to see what the LIBPATH variable is. It may still contain a path to an old ORACLE_HOME...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
hn5118 /home/oracle $env|grep LIBPATH&lt;br /&gt;
LIBPATH=/oracle/exp/ora_bin1/app/oracle/product/10.2.0/db_1/lib:/oracle/exp/ora_bin1/app/oracle/product/10.2.0/db_1/lib&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Disco! Unset it and rerun.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
hn5118 /home/oracle $unset LIBPATH&lt;br /&gt;
&lt;br /&gt;
hn5118 /home/oracle $sqlplus / as sysdba&lt;br /&gt;
&lt;br /&gt;
SQL*Plus: Release 12.1.0.2.0 Production on Wed Jul 12 17:17:54 2017&lt;br /&gt;
&lt;br /&gt;
Copyright (c) 1982, 2014, Oracle.  All rights reserved.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Connected to:&lt;br /&gt;
Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production&lt;br /&gt;
With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options&lt;br /&gt;
&lt;br /&gt;
SQL&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===UDE-31623: operation generated ORACLE error 31623===&lt;br /&gt;
When using Data pump, get following errors almost immediately:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
UDE-31623: operation generated ORACLE error 31623&lt;br /&gt;
ORA-31623: a job is not attached to this session via the specified handle&lt;br /&gt;
ORA-06512: at &amp;quot;SYS.DBMS_DATAPUMP&amp;quot;, line 3326&lt;br /&gt;
ORA-06512: at &amp;quot;SYS.DBMS_DATAPUMP&amp;quot;, line 4551&lt;br /&gt;
ORA-06512: at line 1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Solution 1:&amp;#039;&amp;#039;&amp;#039;&amp;lt;br /&amp;gt;&lt;br /&gt;
In one case, I simplified the parameter file that was used. Maybe related to Streams Pool size, who knows?!&amp;lt;br /&amp;gt;&lt;br /&gt;
I removed these 2 lines and the export started working:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
compression_algorithm=medium&lt;br /&gt;
logtime=all&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Solution 2:&amp;#039;&amp;#039;&amp;#039;&amp;lt;br /&amp;gt;&lt;br /&gt;
There is a note about this on Metalink, 1080775.1 which suggests that Streams Pool Size needs setting.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
For this DataPump error, you will need to configure the database with some Streams Pool.&lt;br /&gt;
&lt;br /&gt;
Perform the following query to find out how much STREAMS_POOL_SIZE has been allocated&lt;br /&gt;
&lt;br /&gt;
 select * from v$sgainfo;&lt;br /&gt;
 ...&lt;br /&gt;
 Streams Pool Size                               0 Yes&lt;br /&gt;
&lt;br /&gt;
Data Pump now uses Advanced Queuing (AQ) internally, so it can handle job stops/starts/re-starts.  However, AQ using the Streams Pool, where the database currently has the STREAMS_POOL_SIZE set to ZERO.&lt;br /&gt;
&lt;br /&gt;
Manually set the STREAMS_POOL_SIZE (using ALTER SYSTEM or by changing the value in the the PFILE/SPFILE), re-start the database and re-attempt the Data Pump Export.&lt;br /&gt;
&lt;br /&gt;
Alternately, turn on Automatic Shared Memory management (ASMM) by setting SGA_TARGET or MEMORY_TARGET.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
From Oracle Documentation&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Setting the Size Of the Buffer Cache In a Streams Environment&lt;br /&gt;
&lt;br /&gt;
Oracle Data Pump uses Streams functionality to communicate between processes.&lt;br /&gt;
If the SGA_TARGET initialization parameter is set, then the STREAMS_POOL_SIZE initialization parameter is automatically set to a reasonable value.&lt;br /&gt;
If the SGA_TARGET initialization parameter is not set and the STREAMS_POOL_SIZE initialization parameter is not defined,&lt;br /&gt;
then the size of the streams pool automatically defaults to 10% of the size of the shared pool.&lt;br /&gt;
&lt;br /&gt;
When the streams pool is created, the required SGA memory is taken from memory allocated to the buffer cache,&lt;br /&gt;
reducing the size of the cache to less than what was specified by the DB_CACHE_SIZE initialization parameter.&lt;br /&gt;
This means that if the buffer cache was configured with only the minimal required SGA, then Data Pump operations may not work properly.&lt;br /&gt;
A minimum size of 10M is recommended for STREAMS_POOL_SIZE in order to ensure successful Data Pump operations.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORA-00020: maximum number of processes (150) exceeded===&lt;br /&gt;
Check the current resource limits with:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 300&lt;br /&gt;
select * from v$resource_limit;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Unfortunately this limit cannot be increased without a restart.&amp;lt;br /&amp;gt;&lt;br /&gt;
It may be a necessary to increase the limit with&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter system set processes=500 scope=spfile;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
followed by a shutdown/startup&amp;lt;br /&amp;gt;&lt;br /&gt;
Or it may be some user is running away with the limit.&amp;lt;br /&amp;gt;&lt;br /&gt;
Check to see who is running what with:&lt;br /&gt;
[[http://www.mailnest.com/dbawiki/index.php/Handy_scripts#See_what_statements_all_users_are_running See_what_statements_all_users_are_running]]&lt;br /&gt;
===ORA-01555: snapshot too old: rollback segment number nn with name &amp;quot;xxx&amp;quot; too small===&lt;br /&gt;
* [http://dfitzjarrell.wordpress.com/2008/02/22/the-dreaded-ora-01555/ Good explanation of why it happens]&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
====Problem====&lt;br /&gt;
A long running transaction has run out of space to store its read-consistent image&lt;br /&gt;
&lt;br /&gt;
====Solution 1====&lt;br /&gt;
If it&amp;#039;s a one-off, maybe leave it alone. It may have been a user leaving a session open overnight without committing or rolling back.&lt;br /&gt;
&lt;br /&gt;
====Solution 2====&lt;br /&gt;
Make sure there&amp;#039;s enough space to allow the transaction to finish.&lt;br /&gt;
&lt;br /&gt;
====Things to check====&lt;br /&gt;
How much undo did the biggest transaction take?&lt;br /&gt;
What is the undo retention parameter set to?&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 200&lt;br /&gt;
col name        for a30&lt;br /&gt;
col description for a50&lt;br /&gt;
col value       for a20&lt;br /&gt;
col maxquerylen for 999999&lt;br /&gt;
select p.name&lt;br /&gt;
,      p.description&lt;br /&gt;
,      p.value&lt;br /&gt;
,      max(u.maxquerylen) maxquerylen&lt;br /&gt;
from   v$parameter p&lt;br /&gt;
,      v$undostat  u&lt;br /&gt;
where  1=1&lt;br /&gt;
and    p.name = &amp;#039;undo_retention&amp;#039;&lt;br /&gt;
group  by p.name&lt;br /&gt;
,      p.description&lt;br /&gt;
,      p.value;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Set the retention to about 20% bigger than the maxquerylen.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select &amp;#039;alter system set undo_retention=&amp;#039;||round(1.2*max(maxquerylen))||&amp;#039; scope=both;&amp;#039; &amp;quot;Run this&amp;quot; from v$undostat;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
and set the undo retention guarantee (being aware of the consequences)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select tablespace_name&lt;br /&gt;
,      retention&lt;br /&gt;
from   dba_tablespaces;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter tablespace &amp;amp;undo_ts_name retention guarantee;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Optimise Oracle UNDO Parameters===&lt;br /&gt;
&lt;br /&gt;
The ideal undo_retention would be enough to hold rollback for the longest transaction that happened so far (can&amp;#039;t see into the future)&amp;lt;br /&amp;gt;&lt;br /&gt;
So current undo_retention = current value of undo / (db_block_size * undo blocks per sec)&amp;lt;br /&amp;gt;&lt;br /&gt;
* Undo Blocks per Second&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SELECT MAX(undoblks/((end_time-begin_time)*3600*24)) &amp;quot;UNDO_BLOCKS_PER_SEC&amp;quot;&lt;br /&gt;
FROM   v$undostat;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Optimal Undo Retention&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
col actual for 9999999999.99 heading &amp;quot;ACTUAL UNDO SIZE [MByte]&amp;quot;&lt;br /&gt;
col retent for 9999999999    heading &amp;quot;UNDO RETENTION [Sec]&amp;quot;&lt;br /&gt;
col needed for 9999999999.99 heading &amp;quot;NEEDED UNDO SIZE [Secs]&amp;quot;&lt;br /&gt;
&lt;br /&gt;
SELECT d.undo_size/(1024*1024) actual,&lt;br /&gt;
       to_number(SUBSTR(e.value,1,25)) retent,&lt;br /&gt;
       ROUND((d.undo_size / (to_number(f.value) *&lt;br /&gt;
       g.undo_block_per_sec))) needed&lt;br /&gt;
  FROM (&lt;br /&gt;
       SELECT SUM(a.bytes) undo_size&lt;br /&gt;
          FROM v$datafile a,&lt;br /&gt;
               v$tablespace b,&lt;br /&gt;
               dba_tablespaces c&lt;br /&gt;
         WHERE c.contents = &amp;#039;UNDO&amp;#039;&lt;br /&gt;
           AND c.status = &amp;#039;ONLINE&amp;#039;&lt;br /&gt;
           AND b.name = c.tablespace_name&lt;br /&gt;
           AND a.ts# = b.ts#&lt;br /&gt;
       ) d,&lt;br /&gt;
       v$parameter e,&lt;br /&gt;
       v$parameter f,&lt;br /&gt;
       (&lt;br /&gt;
       SELECT MAX(undoblks/((end_time-begin_time)*3600*24))&lt;br /&gt;
              undo_block_per_sec&lt;br /&gt;
         FROM v$undostat&lt;br /&gt;
       ) g&lt;br /&gt;
WHERE e.name = &amp;#039;undo_retention&amp;#039;&lt;br /&gt;
  AND f.name = &amp;#039;db_block_size&amp;#039;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Calculate Needed UNDO Size for given Database Activity&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
col actual for 9999999999.99 heading &amp;quot;ACTUAL UNDO SIZE [MByte]&amp;quot;&lt;br /&gt;
col retent for 9999999999    heading &amp;quot;UNDO RETENTION [Sec]&amp;quot;&lt;br /&gt;
col needed for 9999999999.99 heading &amp;quot;NEEDED UNDO SIZE [MByte]&amp;quot;&lt;br /&gt;
&lt;br /&gt;
SELECT d.undo_size/(1024*1024) actual&lt;br /&gt;
,      to_number(SUBSTR(e.value,1,25)) retent&lt;br /&gt;
,      (TO_NUMBER(e.value) * TO_NUMBER(f.value) *&lt;br /&gt;
       g.undo_block_per_sec) / (1024*1024)  needed&lt;br /&gt;
  FROM (&lt;br /&gt;
       SELECT SUM(a.bytes) undo_size&lt;br /&gt;
         FROM v$datafile a,&lt;br /&gt;
              v$tablespace b,&lt;br /&gt;
              dba_tablespaces c&lt;br /&gt;
        WHERE c.contents = &amp;#039;UNDO&amp;#039;&lt;br /&gt;
          AND c.status = &amp;#039;ONLINE&amp;#039;&lt;br /&gt;
          AND b.name = c.tablespace_name&lt;br /&gt;
          AND a.ts# = b.ts#&lt;br /&gt;
       ) d,&lt;br /&gt;
      v$parameter e,&lt;br /&gt;
       v$parameter f,&lt;br /&gt;
       (&lt;br /&gt;
       SELECT MAX(undoblks/((end_time-begin_time)*3600*24))&lt;br /&gt;
         undo_block_per_sec&lt;br /&gt;
         FROM v$undostat&lt;br /&gt;
       ) g&lt;br /&gt;
 WHERE e.name = &amp;#039;undo_retention&amp;#039;&lt;br /&gt;
  AND f.name = &amp;#039;db_block_size&amp;#039;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
It might be that the Export still fails with ORA-01555 even though retention seems long enough.&amp;lt;br /&amp;gt;&lt;br /&gt;
Are you running an export with the flashback_time parameter? If so, the undo_retention should be longer than the total export running time!&amp;lt;br /&amp;gt;&lt;br /&gt;
===Check LOB undo retention===&lt;br /&gt;
The retention settings for LOBS is different for the rest of the database.&amp;lt;br /&amp;gt;&lt;br /&gt;
When you change the UNDO_RETENTION parameter, the LOB segment’s retention value is NOT modified.&amp;lt;br /&amp;gt;&lt;br /&gt;
If you query the RETENTION column of the DBA_LOBS view, you will notice the old UNDO_RETENTION value still remains after you have modified the UNDO_RETENTION parameter.&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SQL&amp;gt; show parameter undo_&lt;br /&gt;
&lt;br /&gt;
NAME                                 TYPE        VALUE&lt;br /&gt;
------------------------------------ ----------- ------------------------------&lt;br /&gt;
undo_management                      string      AUTO&lt;br /&gt;
undo_retention                       integer     36000&lt;br /&gt;
undo_tablespace                      string      UNDOTBS1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SQL&amp;gt; desc SITEADMIN.AUDIT_LOG_MESSAGE&lt;br /&gt;
 Name                                      Null?    Type&lt;br /&gt;
 ----------------------------------------- -------- ----------------------------&lt;br /&gt;
 AUDIT_LOG_MESSAGE_ID                      NOT NULL NUMBER&lt;br /&gt;
 AUDIT_LOG_ID                              NOT NULL NUMBER&lt;br /&gt;
 SEQUENCE                                           NUMBER&lt;br /&gt;
 MESSAGE                                            CLOB&lt;br /&gt;
 CREATE_DATE                                        TIMESTAMP(6)&lt;br /&gt;
 COMPONENT_ID                                       VARCHAR2(50 CHAR)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 300&lt;br /&gt;
col column_name for a32&lt;br /&gt;
select table_name,column_name, pctversion,retention from dba_lobs where owner=&amp;#039;&amp;amp;table_owner&amp;#039;;&lt;br /&gt;
&lt;br /&gt;
TABLE_NAME                COLUMN_NAME                    PCTVERSION  RETENTION&lt;br /&gt;
------------------------- ------------------------------ ---------- ----------&lt;br /&gt;
EMAIL_STORE               CONTENT                                 0&lt;br /&gt;
EMAIL_STORE_ATTACHEMENT   ATTACHEMENT                             0&lt;br /&gt;
TRACKING                  ORIGINAL_MESSAGE                                 900&lt;br /&gt;
TRACKING                  MESSAGE                                          900&lt;br /&gt;
TRACKING                  SIEBEL_MESSAGE                                   900&lt;br /&gt;
WISE_WMS_LOG              WISE_WMS_XML                                     900&lt;br /&gt;
ATTACHMENT                ORIGINAL_MESSAGE                                 900&lt;br /&gt;
PLAN_TABLE                OTHER_XML                                        900&lt;br /&gt;
AUDIT_LOG_MESSAGE         MESSAGE                                          900&lt;br /&gt;
EXCEPTIONS                STACK_TRACE                                      900&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
To change the LOB segment’s RETENTION value to match the new UNDO_RETENTION value, do the following:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ALTER TABLE my_table MODIFY LOB (lob_column) (PCTVERSION 20);&lt;br /&gt;
ALTER TABLE my_table MODIFY LOB (lob_column) (RETENTION);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
By momentarily changing the LOB to use PCTVERSION and then back to RETENTION, the new value of UNDO_RETENTION will be used.&amp;lt;br /&amp;gt;&lt;br /&gt;
You need to do this for all LOB segments that you intend to modify.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select &amp;#039;ALTER TABLE &amp;#039;||owner||&amp;#039;.&amp;#039;||table_name||&amp;#039; MODIFY LOB (&amp;#039;||column_name||&amp;#039;) (PCTVERSION 20);&amp;#039; from dba_lobs where owner=&amp;#039;TIBCO&amp;#039;&lt;br /&gt;
&lt;br /&gt;
select &amp;#039;ALTER TABLE &amp;#039;||owner||&amp;#039;.&amp;#039;||table_name||&amp;#039; MODIFY LOB (&amp;#039;||column_name||&amp;#039;) (RETENTION);&amp;#039;     from dba_lobs where owner=&amp;#039;TIBCO&amp;#039;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
There is a table DBA_LOBS that displays information about all the LOB columns in the database, but it doesn&amp;#039;t actually store any LOB data, just metadata. The actual LOB segments in the database have system-generated names that take the form SYS_LOB*identifier*$$.&lt;br /&gt;
For example if you identify a segment named SYS_LOBidentifier$$ that is consuming space, you can find out what column of what table that LOB column maps to using the DBA_LOBS table:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 1000&lt;br /&gt;
col owner       for a20&lt;br /&gt;
col table_name  for a32&lt;br /&gt;
col column_name for a32&lt;br /&gt;
select owner&lt;br /&gt;
,      table_name&lt;br /&gt;
,      column_name&lt;br /&gt;
from   dba_lobs&lt;br /&gt;
where  1=1&lt;br /&gt;
and    segment_name = &amp;#039;SYS_LOB&amp;lt;&amp;lt;identifier&amp;gt;&amp;gt;$$&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====The Undo Advisor PL/SQL Interface====&lt;br /&gt;
You can activate the Undo Advisor by creating an undo advisor task through the advisor framework.&amp;lt;br /&amp;gt;&lt;br /&gt;
The following example creates an undo advisor task to evaluate the undo tablespace. The name of the advisor is &amp;#039;Undo Advisor&amp;#039;.&amp;lt;br /&amp;gt;&lt;br /&gt;
The analysis is based on Automatic Workload Repository snapshots, which you must specify by setting parameters START_SNAPSHOT and END_SNAPSHOT.&amp;lt;br /&amp;gt;&lt;br /&gt;
In the following example, the START_SNAPSHOT is &amp;quot;1&amp;quot; and END_SNAPSHOT is &amp;quot;2&amp;quot;.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
DECLARE&lt;br /&gt;
   tid    NUMBER;&lt;br /&gt;
   tname  VARCHAR2(30);&lt;br /&gt;
   oid    NUMBER;&lt;br /&gt;
BEGIN&lt;br /&gt;
   DBMS_ADVISOR.CREATE_TASK(&amp;#039;Undo Advisor&amp;#039;, tid, tname, &amp;#039;Undo Advisor Task&amp;#039;);&lt;br /&gt;
   DBMS_ADVISOR.CREATE_OBJECT(tname, &amp;#039;UNDO_TBS&amp;#039;, null, null, null, &amp;#039;null&amp;#039;, oid);&lt;br /&gt;
   DBMS_ADVISOR.SET_TASK_PARAMETER(tname, &amp;#039;TARGET_OBJECTS&amp;#039;, oid);&lt;br /&gt;
   DBMS_ADVISOR.SET_TASK_PARAMETER(tname, &amp;#039;START_SNAPSHOT&amp;#039;, 1);&lt;br /&gt;
   DBMS_ADVISOR.SET_TASK_PARAMETER(tname, &amp;#039;END_SNAPSHOT&amp;#039;, 2);&lt;br /&gt;
   DBMS_ADVISOR.SET_TASK_PARAMETER(tname, &amp;#039;INSTANCE&amp;#039;, 1);&lt;br /&gt;
   DBMS_ADVISOR.execute_task(tname);&lt;br /&gt;
        END;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
After you have created the advisor task, you can view the output and recommendations in the Automatic Database Diagnostic Monitor in Enterprise Manager.&amp;lt;br /&amp;gt;&lt;br /&gt;
This information is also available in the DBA_ADVISOR_* data dictionary views (DBA_ADVISOR_TASKS, DBA_ADVISOR_OBJECTS, DBA_ADVISOR_FINDINGS, DBA_ADVISOR_RECOMMENDATIONS, and so on).&lt;br /&gt;
====References====&lt;br /&gt;
* [http://www.akadia.com/services/ora_optimize_undo.html akadia.com]&lt;br /&gt;
* [http://dfitzjarrell.wordpress.com/2008/02/22/the-dreaded-ora-01555/ the dreaded ora-01555]&lt;br /&gt;
* [http://docs.oracle.com/cd/B28359_01/server.111/b28310/undo004.htm#ADMIN11469 docs.oracle.com]&lt;br /&gt;
&lt;br /&gt;
===Error 6 initializing SQL*Plus===&lt;br /&gt;
Using sqlplus or rman under Cygwin, ORACLE_HOME still needs to be windows format!&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Message file sp1&amp;lt;lang&amp;gt;.msb not found&lt;br /&gt;
SP2-0750 :You may need to set ORACLE_HOME to your Oracle software directory&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
so...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
export ORACLE_SID=KITRYD&lt;br /&gt;
ORAENV_ASK=NO&lt;br /&gt;
. oraenv&lt;br /&gt;
[[ &amp;quot;`uname`&amp;quot; == CYGWIN* ]] &amp;amp;&amp;amp; ORACLE_HOME=`cygpath -w ${ORACLE_HOME}`&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===ORA-2002: error while writing to audit trail===&lt;br /&gt;
Check the space left in the audit tablespace with:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select sum(bytes)/1024/1024 mb from dba_free_space where tablespace_name =&amp;#039;AUDIT_DT&amp;#039;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
If plenty of space, it can be due to Oracle clearing out the recyclebin at the same time.&amp;lt;br /&amp;gt;&lt;br /&gt;
If not, extend the datafile...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select * from dba_data_files where tablespace_name =&amp;#039;AUDIT_DT&amp;#039;;&lt;br /&gt;
alter database datafile 6 resize 30G;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
If that is not possible, clean out some audit data or add a datafile.&lt;br /&gt;
&lt;br /&gt;
===ORA-00449: background process &amp;#039;CKPT&amp;#039; unexpectedly terminated with error 7446===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SQL&amp;gt; startup nomount pfile=&amp;quot;/oracle/TRSCRP1/admin/initTRSCRP1.ora&amp;quot;&lt;br /&gt;
ORA-00449: background process &amp;#039;CKPT&amp;#039; unexpectedly terminated with error 7446&lt;br /&gt;
ORA-07446: sdnfy: bad value &amp;#039;&amp;#039; for parameter .&lt;br /&gt;
SQL&amp;gt; exit&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Solution&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SQL&amp;gt; mkdir /oracle/TRSCRP1/admin/bdump /oracle/TRSCRP1/admin/cdump&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORA-00845: MEMORY_TARGET not supported on this system===&lt;br /&gt;
* Reference: [http://arjudba.blogspot.be/2009/01/ora-00845-memorytarget-not-supported-on.html arjudba.blogspot.be]&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Problem Description&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SQL&amp;gt; STARTUP&lt;br /&gt;
ORA-00845: MEMORY_TARGET not supported on this system&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Cause&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
* Starting from Oracle 11g the automatic memory management feature is now defined with parameter MEMORY_TARGET and MEMMORY_MAX_TARGET.&lt;br /&gt;
* On linux file system the shared memory need to be mounted on /dev/shm directory on the operating system.&lt;br /&gt;
* And the size of /dev/shm needs to be greater than MEMORY_TARGET or MEMMORY_MAX_TARGET.&lt;br /&gt;
* The AMM (Automatic Memory Management) now in 11g manages both SGA and PGA together by MMAN process.&lt;br /&gt;
* The MEMORY_TARGET parameter in 11g comes for (SGA_TARGET+PGA_AGGREGATE_TARGET) which was in 10g.&lt;br /&gt;
* And MEMORY_MAX_TARGET parameter in 11g comes instead of SGA_MAX_TARGET parameter which was in 10g.&lt;br /&gt;
* The ORA-00845:can arises for the following two reasons on linux system.&lt;br /&gt;
1)If the shared memory which is mapped to /dev/shm directory is less than the size of MEMORY_TARGET or MEMORY_MAX_TARGET or&lt;br /&gt;
2)If the shared memory is not mapped to /dev/shm directory.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Solution&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Make sure /dev/shm is properly mounted. You can see it by,&lt;br /&gt;
#df -h or #df -k command.&lt;br /&gt;
The output should be similar to:&lt;br /&gt;
&lt;br /&gt;
$ df -k&lt;br /&gt;
Filesystem            Size  Used Avail Use% Mounted on&lt;br /&gt;
...&lt;br /&gt;
shmfs                 1G    512M 512M  50% /dev/shm&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
We see here for /dev/shm we have assigned 1G memory. Now if you set MEMORY_TARGET more than 1G then above ORA-845 will arise. For example if you have MEMORY_TARGET or MEMORY_MAX_TARGET set to 12G then you can mount shared memory to 13g like below.&lt;br /&gt;
As a root user,&lt;br /&gt;
# mount -t tmpfs shmfs -o size=13g /dev/shm&lt;br /&gt;
In order to make the settings persistence so that it will affect after restarting machine add an entry in /etc/fstab similar to the following:&lt;br /&gt;
&lt;br /&gt;
shmfs /dev/shm tmpfs size=13g 0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORA-24247: network access denied by access control list (ACL)===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Cause: No access control list (ACL) has been assigned to the target host or the privilege necessary to access the target host has not been granted to the user in the access control list.&lt;br /&gt;
&lt;br /&gt;
Action: Ensure that an access control list (ACL) has been assigned to the target host and the privilege necessary to access the target host has been granted to the user.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Your application will encounter an ORA-24247 error if it relies on one of the network packages and no proper ACL has been created. For the use of the following packages it is mandatory to have an ACL for the application user in place in 11g:&lt;br /&gt;
*UTL_TCP&lt;br /&gt;
*UTL_SMTP&lt;br /&gt;
*UTL_MAIL&lt;br /&gt;
*UTL_HTTP&lt;br /&gt;
*UTL_INADDR&lt;br /&gt;
Here is a very good explanation of how to setup the necessary ACLs: [[http://blog.whitehorses.nl/2010/03/17/oracle-11g-access-control-list-and-ora-24247/ whitehorses.nl]]&lt;br /&gt;
&lt;br /&gt;
===ORA-00600: internal error code, arguments: [qmx: no ref]===&lt;br /&gt;
Search &amp;quot;Master Note for Oracle XML Database (XDB) Install / Deinstall (Doc ID 1292089.1)&amp;quot; for more info.&lt;br /&gt;
====Problem:====&lt;br /&gt;
Sometimes one or more of the following errors can be encountered when installing or upgrading XDB, configuring APEX, running an Export, or selecting from xdb.xdb$resource or sys.dba_network_acls:&amp;lt;br /&amp;gt;&lt;br /&gt;
* ORA-31159: XML DB is in an invalid state&lt;br /&gt;
* ORA-00600: internal error code, arguments: [unable to load XDB library]&lt;br /&gt;
* ORA-00600: internal error code, arguments: [qmx: no ref]&lt;br /&gt;
* ORA-00600: internal error code, arguments: [qmtGetColumnInfo1]&lt;br /&gt;
* ORA-00600: internal error code, arguments: [qmtb_init_len]&lt;br /&gt;
* ORA-00600: internal error code, arguments: [qmtGetBaseType]&lt;br /&gt;
* ORA-00600: internal error code, arguments: [psdnop-1], [600]&lt;br /&gt;
* ORA-00600: internal error code, arguments: [qmtInit1]&lt;br /&gt;
* ORA-07445: exception encountered: core dump [_memcpy()+224] [SIGSEGV] [Address not mapped to object]&lt;br /&gt;
* ORA-19051 Cannot Use Fast Path Insert For This XMLType Table&lt;br /&gt;
* ORA-31011: XML parsing failed&lt;br /&gt;
Errors of this sort generally occur when the init routines for the internal XDB functions are run in an invalid environment causing memory corruption.&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
This can happen if the database was ever started with the LD_LIBRARY_PATH (LIBPATH for AIX or SHLIB_PATH for HP) pointing to the wrong $ORACLE_HOME/lib directory rather than to the correct location for the instance.&amp;lt;br /&amp;gt;&lt;br /&gt;
The LD_LIBRARY_PATH/LIBPATH/SHLIB_PATH environment variable is used to resolve the location of the shared library &amp;quot;libxdb.so (libxdb.sl on HP)&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
====Solution:====&lt;br /&gt;
* Stop Listener&lt;br /&gt;
* Stop database&lt;br /&gt;
* Ensure $ORACLE_HOME/lib is at the start of LD_LIBRARY_PATH / LIBPATH / SHLIB_PATH&lt;br /&gt;
* If AIX, run /usr/sbin/slibclean as root&lt;br /&gt;
* Start database&lt;br /&gt;
* Start listener&lt;br /&gt;
&lt;br /&gt;
===ORA-00201: control file version nn.nn.nn.nn incompatible with ORACLE version===&lt;br /&gt;
Trying to restore a database after complete failure&amp;lt;br /&amp;gt;&lt;br /&gt;
first step is to startup the database in nomount mode and restore the controlfile - succeeded.&amp;lt;br /&amp;gt;&lt;br /&gt;
second step, startup the database in mount mode ready for database restore...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SQL*Plus: Release 10.2.0.3.0 - Production on Wed Aug 19 18:16:47 2015&lt;br /&gt;
&lt;br /&gt;
Copyright (c) 1982, 2006, Oracle.  All Rights Reserved.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Connected to:&lt;br /&gt;
Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - 64bit Production&lt;br /&gt;
With the Partitioning, OLAP and Data Mining options&lt;br /&gt;
&lt;br /&gt;
SYS@CODWHP1&amp;gt; startup mount&lt;br /&gt;
ORACLE instance started.&lt;br /&gt;
&lt;br /&gt;
Total System Global Area  260046848 bytes&lt;br /&gt;
Fixed Size                  2029296 bytes&lt;br /&gt;
Variable Size             113248528 bytes&lt;br /&gt;
Database Buffers          134217728 bytes&lt;br /&gt;
Redo Buffers               10551296 bytes&lt;br /&gt;
ORA-00201: control file version 10.2.0.0.0 incompatible with ORACLE version 10.2.0.3.0&lt;br /&gt;
ORA-00202: control file: &amp;#039;/oracle/CODWHP1/product/10203/dbs/cntrlCODWHP1.dbf&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The problem was there was no compatible parameter in the simple init file I used to start up the instance.&amp;lt;br /&amp;gt;&lt;br /&gt;
Adding compatible parameter to init file to be same version (10.2.0.3) allowed the db to mount.&lt;br /&gt;
&lt;br /&gt;
===TNS-00525: Insufficient privilege for operation===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
lsnrctl start LISTENER_UCLID55V&lt;br /&gt;
&lt;br /&gt;
LSNRCTL for IBM/AIX RISC System/6000: Version 11.2.0.3.0 - Production on 26-MAR-2015 13:36:14&lt;br /&gt;
&lt;br /&gt;
Copyright (c) 1991, 2011, Oracle.  All rights reserved.&lt;br /&gt;
&lt;br /&gt;
Starting /oracle/product/11.2.0.3/bin/tnslsnr: please wait...&lt;br /&gt;
&lt;br /&gt;
TNSLSNR for IBM/AIX RISC System/6000: Version 11.2.0.3.0 - Production&lt;br /&gt;
System parameter file is /oracle/product/11.2.0.3/network/admin/listener.ora&lt;br /&gt;
Log messages written to /oracle/product/diag/tnslsnr/solax082/listener_uclid55v/alert/log.xml&lt;br /&gt;
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=150.251.114.238)(PORT=1525)))&lt;br /&gt;
Error listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC1525)))&lt;br /&gt;
TNS-12555: TNS:permission denied&lt;br /&gt;
 TNS-12560: TNS:protocol adapter error&lt;br /&gt;
  TNS-00525: Insufficient privilege for operation&lt;br /&gt;
   IBM/AIX RISC System/6000 Error: 1: Not owner&lt;br /&gt;
&lt;br /&gt;
Listener failed to start. See the error message(s) above...&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This would suggest the user attempting to start the listener has no access to either the Oracle binaries or the TNS listener/tnsnames files.&amp;lt;br /&amp;gt;&lt;br /&gt;
But... checkout the /tmp/.oracle directory :-)&amp;lt;br /&amp;gt;&lt;br /&gt;
That hidden gem shows who started the listener last time. Delete the relevant entry and try again!&amp;lt;br /&amp;gt;&lt;br /&gt;
To start from a clean sheet, stop all listeners, delete this directory and restart the listeners.&lt;br /&gt;
&lt;br /&gt;
===ORA-12003: materialized view or zonemap &amp;quot;KPK&amp;quot;.&amp;quot;EVD01_NEW&amp;quot; does not exist===&lt;br /&gt;
Here&amp;#039;s one you shouldn&amp;#039;t see very often.&amp;lt;br /&amp;gt;&lt;br /&gt;
Trying to drop a tablespace but prevented from doing so because a materialized view has referential contraints on a table in this tablespace.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SQL&amp;gt; drop tablespace TS_THALER_PART_OLD including contents and datafiles cascade constraints;&lt;br /&gt;
drop tablespace TS_THALER_PART_OLD including contents and datafiles cascade constraints&lt;br /&gt;
*&lt;br /&gt;
ERROR at line 1:&lt;br /&gt;
ORA-00604: error occurred at recursive SQL level 1&lt;br /&gt;
ORA-12083: must use DROP MATERIALIZED VIEW to drop &amp;quot;KPK&amp;quot;.&amp;quot;EVD01_NEW&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Ok, nice of Oracle to tell us what we have to do. Simple enough. Let&amp;#039;s drop the materialized view.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SQL&amp;gt; DROP MATERIALIZED VIEW &amp;quot;KPK&amp;quot;.&amp;quot;EVD01_NEW&amp;quot;;&lt;br /&gt;
DROP MATERIALIZED VIEW &amp;quot;KPK&amp;quot;.&amp;quot;EVD01_NEW&amp;quot;&lt;br /&gt;
*&lt;br /&gt;
ERROR at line 1:&lt;br /&gt;
ORA-12003: materialized view or zonemap &amp;quot;KPK&amp;quot;.&amp;quot;EVD01_NEW&amp;quot; does not exist&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Aah. Not so obvious then.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
desc &amp;quot;KPK&amp;quot;.&amp;quot;EVD01_NEW&amp;quot;&lt;br /&gt;
 Name                                      Null?    Type&lt;br /&gt;
 ----------------------------------------- -------- ----------------------------&lt;br /&gt;
 DATMAJ                                             VARCHAR2(8 CHAR)&lt;br /&gt;
 HEUMAJ                                             VARCHAR2(8 CHAR)&lt;br /&gt;
 PGMMAJ                                             VARCHAR2(6 CHAR)&lt;br /&gt;
 NATOPN                                             VARCHAR2(6 CHAR)&lt;br /&gt;
 REFEXN                                             VARCHAR2(50 CHAR)&lt;br /&gt;
 SWIOLN                                             VARCHAR2(1 CHAR)&lt;br /&gt;
 STAEVT                                             VARCHAR2(4 CHAR)&lt;br /&gt;
 REFEVT                                             VARCHAR2(16 CHAR)&lt;br /&gt;
 NUMIDT                                             VARCHAR2(30 CHAR)&lt;br /&gt;
 ORIEVT                                             VARCHAR2(10 CHAR)&lt;br /&gt;
 REFLOG                                             VARCHAR2(16 CHAR)&lt;br /&gt;
 MSGEVT_CPL                                         VARCHAR2(1500 CHAR)&lt;br /&gt;
 REFOPN                                             VARCHAR2(16 CHAR)&lt;br /&gt;
 DATEVT                                             VARCHAR2(8 CHAR)&lt;br /&gt;
 MSGEVT_FIL_1                                       VARCHAR2(2000 CHAR)&lt;br /&gt;
 MSGEVT_FIL_2                                       VARCHAR2(2000 CHAR)&lt;br /&gt;
 MSGEVT_SPE                                         VARCHAR2(200 CHAR)&lt;br /&gt;
 DATEFF                                             VARCHAR2(8 CHAR)&lt;br /&gt;
 TMSTMP                                             VARCHAR2(15 CHAR)&lt;br /&gt;
 VEREVT                                             VARCHAR2(3 CHAR)&lt;br /&gt;
 MSGEVT_FIL_3                                       VARCHAR2(2000 CHAR)&lt;br /&gt;
 MSGEVT_FIL_4                                       VARCHAR2(2000 CHAR)&lt;br /&gt;
 TYPEVT                                             VARCHAR2(5 CHAR)&lt;br /&gt;
 SBP_CODAPP                                         VARCHAR2(10 CHAR)&lt;br /&gt;
 SBP_REFINT                                         VARCHAR2(36 CHAR)&lt;br /&gt;
 SBP_TYPACT                                         VARCHAR2(2 CHAR)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
It exists... but as a table.&amp;lt;br /&amp;gt;&lt;br /&gt;
Something has gone wrong in the database somewhere. As it turns out after some deeper investigation, this database is a copy of production but &amp;quot;with modifications&amp;quot;.&amp;lt;br /&amp;gt;&lt;br /&gt;
After the cloning process, a schema needed renaming. Oracle have a procedure for this but it is very long-winded and time-consuming. It uses export and import with transportable tablespaces to do the remap of the schema.&amp;lt;br /&amp;gt;&lt;br /&gt;
An unsupported workaround to rename schema is to simply update the username in sys.user$ and restart the database.&amp;lt;br /&amp;gt;&lt;br /&gt;
This works for the most part but now we see a consequence of that action.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
col owner      for a30&lt;br /&gt;
col mview_name for a30&lt;br /&gt;
select owner&lt;br /&gt;
,      mview_name&lt;br /&gt;
from   dba_mviews&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
OWNER                          MVIEW_NAME&lt;br /&gt;
------------------------------ ------------------------------&lt;br /&gt;
EPK                            EVD01_NEW&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Ahaa, there&amp;#039;s the materialized view but the owner is different from the one described by the database error message above. This one is the owner as it was on production.&amp;lt;br /&amp;gt;&lt;br /&gt;
This means the owner of materialized views has been denormalised for some reason. Reading the (complex) view text of dba_mviews, we see the owner column is based on sys.snap$.sowner&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
col sowner for a20&lt;br /&gt;
col vname  for a20&lt;br /&gt;
col tname  for a20&lt;br /&gt;
select sowner&lt;br /&gt;
,      vname&lt;br /&gt;
,      tname&lt;br /&gt;
from   sys.snap$&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
SOWNER               VNAME                TNAME&lt;br /&gt;
-------------------- -------------------- --------------------&lt;br /&gt;
EPK                  EVD01_NEW            EVD01_NEW&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
For future reference when updating the username in sys.user$, update the snapshot owner in this table as well!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
update sys.snap$&lt;br /&gt;
set    sowner = &amp;#039;KPK&amp;#039;&lt;br /&gt;
where  sowner = &amp;#039;EPK&amp;#039;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Try again&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
DROP MATERIALIZED VIEW &amp;quot;KPK&amp;quot;.&amp;quot;EVD01_NEW&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
Materialized view dropped.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
yep, and the tablespace?&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
drop tablespace TS_THALER_PART_OLD including contents and datafiles cascade constraints;&lt;br /&gt;
&lt;br /&gt;
Tablespace dropped.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORA-12162: TNS:net service name is incorrectly specified===&lt;br /&gt;
Probably nothing to do with TNS. Check your ORACLE_SID is set correctly!&lt;br /&gt;
&lt;br /&gt;
===ORA-00054: resource busy and acquire with NOWAIT specified===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SELECT O.OBJECT_NAME, S.SID, S.SERIAL#, P.SPID, S.PROGRAM,S.USERNAME,&lt;br /&gt;
S.MACHINE,S.PORT , S.LOGON_TIME,SQ.SQL_FULLTEXT &lt;br /&gt;
FROM V$LOCKED_OBJECT L, DBA_OBJECTS O, V$SESSION S, &lt;br /&gt;
V$PROCESS P, V$SQL SQ &lt;br /&gt;
WHERE L.OBJECT_ID = O.OBJECT_ID &lt;br /&gt;
AND L.SESSION_ID = S.SID AND S.PADDR = P.ADDR &lt;br /&gt;
AND S.SQL_ADDRESS = SQ.ADDRESS;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select object_name, s.sid, s.serial#, p.spid &lt;br /&gt;
from v$locked_object l, dba_objects o, v$session s, v$process p&lt;br /&gt;
where l.object_id = o.object_id and l.session_id = s.sid and s.paddr = p.addr;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
then&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter system kill session &amp;#039;sid,serial#&amp;#039;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORA-12518: TNS:listener could not hand off client connection===&lt;br /&gt;
The database you are trying to connect to is probably on its knees. Check server memory is not exhausted.&lt;br /&gt;
&lt;br /&gt;
===ORA-12520: TNS:listener could not find available handler for requested type of server===&lt;br /&gt;
Strangely this could be related to number of processes being exhausted.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
show parameter processes&lt;br /&gt;
alter system set processes=350 scope=spfile;&lt;br /&gt;
shutdown immediate&lt;br /&gt;
startup&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORA-12541: TNS: no listener===&lt;br /&gt;
Either very basic - start the listener!&amp;lt;br /&amp;gt;&lt;br /&gt;
or, as in our case - not so obvious.&amp;lt;br /&amp;gt;&lt;br /&gt;
We use virtual IP addresses so that the IP address stays the same after failover to standby.&amp;lt;br /&amp;gt;&lt;br /&gt;
Due to some confused configuration, we got the network adapter on two different servers to have the same IP address.&amp;lt;br /&amp;gt;&lt;br /&gt;
Stop the IP address on the bad server (assign another one) and all is fine again.&lt;br /&gt;
===ORA-12514: TNS:listener does not currently know of service===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
lsnrctl status &amp;lt;listener_name&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Been altering tnsnames.ora or listener.ora?&lt;br /&gt;
* Check the local_listener parameter&lt;br /&gt;
Try resetting it to itself. Strange but if you are not using port 1521, this can work wonders!&amp;lt;br /&amp;gt;&lt;br /&gt;
Assuming listener is called LISTENER_WM9T:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter system set local_listener=LISTENER_WM9T scope=both;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Try and connect with the service name or directly with&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sqlplus &amp;#039;sys/*******&amp;#039;@&amp;lt;host&amp;gt;:&amp;lt;port&amp;gt;/&amp;lt;SID&amp;gt; as sysdba&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Excellent description of how Oracle TNS listeners work and a checklist on how to fix this error&amp;lt;br /&amp;gt;&lt;br /&gt;
* [[http://edstevensdba.wordpress.com/2011/03/19/ora-12514/ TNS — Ed Stevens]]&lt;br /&gt;
&lt;br /&gt;
===ORA-12547: TNS lost contact===&lt;br /&gt;
&lt;br /&gt;
If&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sqlplus &amp;lt;user&amp;gt;/&amp;lt;pass&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
fails with above error, try&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sqlplus &amp;lt;user&amp;gt;/&amp;lt;pass&amp;gt;@&amp;lt;db connection&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
If this works, it is most probably a permissions error.&amp;lt;br /&amp;gt;&lt;br /&gt;
Re-run the&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ORACLE_HOME/root.sh&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
script that was run as part of the original installation. This will reset the permissions on some important files.&lt;br /&gt;
===ORA-02374: conversion error loading table &amp;quot;BLENGADM&amp;quot;.&amp;quot;ZZ_EVTCTA&amp;quot;===&lt;br /&gt;
This is typical of importing data with Datapump when the tables in the source database were created with &amp;quot;byte&amp;quot; semantics and the destination is &amp;quot;char&amp;quot; semantics.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ORA-02374: conversion error loading table &amp;quot;BLENGADM&amp;quot;.&amp;quot;ZZ_EVTCTA&amp;quot;&lt;br /&gt;
ORA-12899: value too large for column NOMCTA (actual: 257, maximum: 256)&lt;br /&gt;
&lt;br /&gt;
ORA-02372: data for row: NOMCTA : 0X&amp;#039;4C6976726574206427E9706172676E65202020202020202020&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Problem====&lt;br /&gt;
The root cause is the nls_length_semantics of the table columns being BYTE where one character is assigned one byte. But after conversion in a multi-byte database, one character is larger than one byte (could be 2, 3 or 4) and no longer fits.&lt;br /&gt;
====Solution====&lt;br /&gt;
* import the metadata&lt;br /&gt;
Run the impdp command with content=metadata_only. This will create all the tables (still in their original form) but not the data.&lt;br /&gt;
* alter the BYTE columns in the affected tables to CHAR semantics&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select column_name&lt;br /&gt;
,      char_used&lt;br /&gt;
,      data_length&lt;br /&gt;
,      data_type &lt;br /&gt;
from   user_tab_columns &lt;br /&gt;
where  table_name = &amp;#039;T&amp;#039;&lt;br /&gt;
and    char_used = &amp;#039;B&amp;#039;;&lt;br /&gt;
COLUMN_NAME  C DATA_LENGTH DATA_TYPE&lt;br /&gt;
------------ - ----------- ---------&lt;br /&gt;
X            B           1 VARCHAR2&lt;br /&gt;
SQL&amp;gt; alter table t modify x varchar2(1 char);&lt;br /&gt;
Table altered.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Import the data&lt;br /&gt;
Rerun the impdp ensuring table_exists_action is not REPLACE (use truncate or append). This now imports the data into the modified tables.&lt;br /&gt;
====This script does the donkey work of altering table column semantics from byte to char====&lt;br /&gt;
The author of this script is unknown but he/she deserves a medal. It saves countless hours of work and is so well written.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/*&lt;br /&gt;
  The script converts all the VARCHAR2 columns in the user&amp;#039;s schema&lt;br /&gt;
  to CHAR length semantics. Known to work on 10.2.0.4 and later.&lt;br /&gt;
  &lt;br /&gt;
  Script must be executed against the database without any other client&lt;br /&gt;
  and/or application connections to the affected schema.&lt;br /&gt;
  &lt;br /&gt;
  Oracle does not support CHAR semantics for the built-in schemas,&lt;br /&gt;
  like SYS, SYSTEM or SYSMAN, so the script will throw an error,&lt;br /&gt;
  if attempt to run it against any one of them.&lt;br /&gt;
  &lt;br /&gt;
  Upon completion database objects that have dependencies on tables&lt;br /&gt;
  being modified will be invalidated. Oracle usually re-compiles invalidated&lt;br /&gt;
  objects on the first access. Alternatively, a DBA can execute UTLPRP script&lt;br /&gt;
  to recompile all invalid objects in the entire database.&lt;br /&gt;
  &lt;br /&gt;
  Upon completion, please make sure that NLS_LENGTH_SEMANTICS instance parameter&lt;br /&gt;
  is set to CHAR to ensure further upgradability of the schema.&lt;br /&gt;
*/&lt;br /&gt;
set serveroutput on size unlimited format wrap&lt;br /&gt;
declare&lt;br /&gt;
  type sql_list_t is table of varchar2(32767) index by pls_integer;&lt;br /&gt;
  type idx_list_t is table of user_indexes.index_name%type index by pls_integer;&lt;br /&gt;
  type col_list_t is table of user_tab_columns%rowtype index by pls_integer;&lt;br /&gt;
  --&lt;br /&gt;
  lv_col_cnt   pls_integer := 0;&lt;br /&gt;
  lv_idx_cnt   pls_integer := 0;&lt;br /&gt;
  lv_char_set  pls_integer := 0; &lt;br /&gt;
  lv_user      user_users.username%type;&lt;br /&gt;
  lv_sql_stmt  varchar2(32767);&lt;br /&gt;
  lv_byte_cols col_list_t;&lt;br /&gt;
  lv_idx_names idx_list_t;&lt;br /&gt;
  lv_idx_ddls  sql_list_t;&lt;br /&gt;
  --&lt;br /&gt;
  procedure run_sql_stmt&lt;br /&gt;
  (&lt;br /&gt;
   p_sql_stmt in varchar2&lt;br /&gt;
  )&lt;br /&gt;
  as&lt;br /&gt;
  begin&lt;br /&gt;
    execute immediate p_sql_stmt;&lt;br /&gt;
  exception&lt;br /&gt;
    when others&lt;br /&gt;
    then&lt;br /&gt;
      raise_application_error(-20202, &amp;#039;Failed statement [&amp;#039; || p_sql_stmt || dbms_utility.format_error_backtrace() || &amp;#039;]&amp;#039;, true);&lt;br /&gt;
  end;&lt;br /&gt;
begin&lt;br /&gt;
  --&lt;br /&gt;
  lv_user := user();&lt;br /&gt;
  if lv_user in (&amp;#039;SYS&amp;#039;, &amp;#039;SYSTEM&amp;#039;, &amp;#039;SYSMAN&amp;#039;)&lt;br /&gt;
  then&lt;br /&gt;
    raise_application_error(-20202, &amp;#039;This script cannot be executed against Oracle built-in schema [&amp;#039; || lv_user || &amp;#039;].&amp;#039;);&lt;br /&gt;
  end if;&lt;br /&gt;
  --&lt;br /&gt;
  select&lt;br /&gt;
         *&lt;br /&gt;
         bulk collect into lv_byte_cols&lt;br /&gt;
  from&lt;br /&gt;
         user_tab_columns uc&lt;br /&gt;
  where&lt;br /&gt;
         uc.char_used = &amp;#039;B&amp;#039;&lt;br /&gt;
         and&lt;br /&gt;
         substr(uc.table_name, 1, 4) != &amp;#039;BIN$&amp;#039;&lt;br /&gt;
         and&lt;br /&gt;
         not exists&lt;br /&gt;
         (&lt;br /&gt;
          select 1&lt;br /&gt;
          from   user_views uv&lt;br /&gt;
          where  uv.view_name = uc.table_name&lt;br /&gt;
         )&lt;br /&gt;
  ;&lt;br /&gt;
  --&lt;br /&gt;
  lv_col_cnt := lv_byte_cols.count();&lt;br /&gt;
  --&lt;br /&gt;
  dbms_output.enable();&lt;br /&gt;
  --&lt;br /&gt;
  if lv_col_cnt &amp;gt; 0&lt;br /&gt;
  then&lt;br /&gt;
    for idx_rw in&lt;br /&gt;
    (&lt;br /&gt;
     select index_name &lt;br /&gt;
     from   user_indexes&lt;br /&gt;
     where  index_type = &amp;#039;FUNCTION-BASED NORMAL&amp;#039;&lt;br /&gt;
    )&lt;br /&gt;
    loop&lt;br /&gt;
      lv_idx_cnt := lv_idx_cnt + 1;&lt;br /&gt;
      lv_idx_names(lv_idx_cnt) := idx_rw.index_name;&lt;br /&gt;
      lv_idx_ddls(lv_idx_cnt) := replace&lt;br /&gt;
                                 (&lt;br /&gt;
                                  dbms_metadata.get_ddl&lt;br /&gt;
                                  (&lt;br /&gt;
                                   object_type =&amp;gt; &amp;#039;INDEX&amp;#039;,&lt;br /&gt;
                                   name        =&amp;gt; idx_rw.index_name&lt;br /&gt;
                                  )&lt;br /&gt;
                                  ,&lt;br /&gt;
                                  &amp;#039;;&amp;#039;&lt;br /&gt;
                                 );&lt;br /&gt;
      lv_sql_stmt := &amp;#039;drop index &amp;#039; || idx_rw.index_name;&lt;br /&gt;
      run_sql_stmt(lv_sql_stmt);&lt;br /&gt;
      dbms_output.put_line(&amp;#039;Dropped function-based index: &amp;#039; || idx_rw.index_name);&lt;br /&gt;
      dbms_output.put_line(&amp;#039;In case of script failure, restore the index by running the DDL statement below:&amp;#039;);&lt;br /&gt;
      dbms_output.put_line(lv_idx_ddls(lv_idx_cnt) || &amp;#039;;&amp;#039;);&lt;br /&gt;
    end loop;&lt;br /&gt;
    --&lt;br /&gt;
    for i in 1..lv_col_cnt&lt;br /&gt;
    loop&lt;br /&gt;
      lv_sql_stmt :=  &amp;#039;alter table &amp;#039; || lv_byte_cols(i).table_name || &amp;#039; modify (&amp;#039; ||&lt;br /&gt;
                      lv_byte_cols(i).column_name || &amp;#039; &amp;#039; || lv_byte_cols(i).data_type ||&lt;br /&gt;
                      &amp;#039;(&amp;#039; || lv_byte_cols(i).char_length || &amp;#039; char))&amp;#039;;&lt;br /&gt;
      run_sql_stmt(lv_sql_stmt);&lt;br /&gt;
    end loop;&lt;br /&gt;
    --&lt;br /&gt;
    dbms_output.new_line();&lt;br /&gt;
    for i in 1..lv_idx_cnt&lt;br /&gt;
    loop&lt;br /&gt;
      run_sql_stmt(lv_idx_ddls(i));&lt;br /&gt;
      dbms_output.put_line(&amp;#039;Recreated function-based index: &amp;#039; || lv_idx_names(i));&lt;br /&gt;
    end loop;&lt;br /&gt;
    --&lt;br /&gt;
    dbms_output.new_line();&lt;br /&gt;
    dbms_output.put_line&lt;br /&gt;
    (&lt;br /&gt;
     &amp;#039;Updated length semantics to CHAR for &amp;#039; || lv_col_cnt || &amp;#039; column&amp;#039; ||&lt;br /&gt;
     case when lv_col_cnt &amp;gt; 1&lt;br /&gt;
          then &amp;#039;s&amp;#039;&lt;br /&gt;
     end ||&lt;br /&gt;
     &amp;#039; in the schema [&amp;#039; || lv_user || &amp;#039;].&amp;#039;&lt;br /&gt;
    );&lt;br /&gt;
  else&lt;br /&gt;
    dbms_output.put_line(&amp;#039;No columns with BYTE length semantics were found in the schema [&amp;#039; || lv_user || &amp;#039;].&amp;#039;);&lt;br /&gt;
  end if;&lt;br /&gt;
  --&lt;br /&gt;
  select count(*) into lv_char_set&lt;br /&gt;
  from   nls_session_parameters&lt;br /&gt;
  where  parameter = &amp;#039;NLS_LENGTH_SEMANTICS&amp;#039;&lt;br /&gt;
         and&lt;br /&gt;
         value = &amp;#039;CHAR&amp;#039;&lt;br /&gt;
  ;&lt;br /&gt;
  --&lt;br /&gt;
  if lv_char_set = 0&lt;br /&gt;
  then&lt;br /&gt;
    dbms_output.put_line(&amp;#039;WARNING: Do not forget to change instance parameter NLS_LENGTH_SEMANTICS to CHAR and restart the database.&amp;#039;);&lt;br /&gt;
  end if;&lt;br /&gt;
end;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORA-14097: column type or size mismatch in ALTER TABLE EXCHANGE PARTITION===&lt;br /&gt;
Also can be &amp;lt;tt&amp;gt;ORA-54033: column to be modified is used in a virtual column expression&amp;lt;/tt&amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;
Nothing especially to do with partitions - just any ddl operation that affects the table.&amp;lt;br /&amp;gt;&lt;br /&gt;
Hidden columns do not normally show up in a desc unless colinvisible is on&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set colinvisible on&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
But these sneaky system-generated ones don&amp;#039;t show up even with that setting on!  You need to show them with this:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set pages 50 lines 1000&lt;br /&gt;
col column_name for a40&lt;br /&gt;
col data_default for a40&lt;br /&gt;
select internal_column_id, column_name, data_default, hidden_column, virtual_column from dba_tab_cols where owner = upper(&amp;#039;&amp;amp;owner.&amp;#039;) and table_name =upper(&amp;#039;&amp;amp;table_name.&amp;#039;);&lt;br /&gt;
&lt;br /&gt;
INTERNAL_COLUMN_ID COLUMN_NAME                                        DATA_DEFAULT                                       HIDDEN_COLUM VIRTUAL_COLU&lt;br /&gt;
------------------ -------------------------------------------------- -------------------------------------------------- ------------ ------------&lt;br /&gt;
                35 MONLOT_REC_CDR                                     &amp;#039;0&amp;#039;                                                NO           NO&lt;br /&gt;
                34 MONLOT_REC_DBT                                     &amp;#039;0&amp;#039;                                                NO           NO&lt;br /&gt;
                33 MONLOT_CAL_CDR                                     &amp;#039;0&amp;#039;                                                NO           NO&lt;br /&gt;
                32 MONLOT_CAL_DBT                                     &amp;#039;0&amp;#039;                                                NO           NO&lt;br /&gt;
                31 MONMVT_CPT                                         &amp;#039;0&amp;#039;                                                NO           NO&lt;br /&gt;
                30 SENNOT                                             &amp;#039; &amp;#039;                                                NO           NO&lt;br /&gt;
                29 NUMSEQ                                                                                                NO           NO&lt;br /&gt;
                28 NOMFIC                                                                                                NO           NO&lt;br /&gt;
                27 TOTCPT_REC                                                                                            NO           NO&lt;br /&gt;
                26 TOTCPT_CAL                                                                                            NO           NO&lt;br /&gt;
                25 MONLOT_REC                                                                                            NO           NO&lt;br /&gt;
                24 MONLOT_CAL                                                                                            NO           NO&lt;br /&gt;
                23 NBRELE_REC                                                                                            NO           NO&lt;br /&gt;
                22 NBRELE_CAL                                                                                            NO           NO&lt;br /&gt;
                21 NUMCPT_GLO                                                                                            NO           NO&lt;br /&gt;
                20 DEVLOT                                                                                                NO           NO&lt;br /&gt;
                19 CODERR                                                                                                NO           NO&lt;br /&gt;
                18 CANLOT                                                                                                NO           NO&lt;br /&gt;
                17 REFTEX                                                                                                NO           NO&lt;br /&gt;
                16 REFEXN                                                                                                NO           NO&lt;br /&gt;
                15 ETTLOT                                                                                                NO           NO&lt;br /&gt;
                14 TYPLOT                                                                                                NO           NO&lt;br /&gt;
                13 DATEXC                                                                                                NO           NO&lt;br /&gt;
                12 STALOT                                                                                                NO           NO&lt;br /&gt;
                11 REFLOT                                                                                                NO           NO&lt;br /&gt;
                10 USRAUT                                                                                                NO           NO&lt;br /&gt;
                 9 HEUAUT                                                                                                NO           NO&lt;br /&gt;
                 8 DATAUT                                                                                                NO           NO&lt;br /&gt;
                 7 PGMMAJ                                                                                                NO           NO&lt;br /&gt;
                 6 USRMAJ                                                                                                NO           NO&lt;br /&gt;
                 5 HEUMAJ                                                                                                NO           NO&lt;br /&gt;
                 4 DATMAJ                                                                                                NO           NO&lt;br /&gt;
                 3 DATCRT                                                                                                NO           NO&lt;br /&gt;
                 2 REFMAJ                                                                                                NO           NO&lt;br /&gt;
                 1 NUMVER                                                                                                NO           NO&lt;br /&gt;
                36 SYS_STS#KR2WNV5L070XKV1L5H7REH                     SYS_OP_COMBINED_HASH(&amp;quot;NOMFIC&amp;quot;,&amp;quot;NUMSEQ&amp;quot;)            YES          YES&lt;br /&gt;
&lt;br /&gt;
36 rows selected.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
That last row means extended statistics have been generated for 2 columns in this table.&amp;lt;br /&amp;gt;&lt;br /&gt;
You can see this because the name begins with SYS_STS. If it begins with SYS_&amp;lt;something else&amp;gt; then it is not extended statistics.&amp;lt;br /&amp;gt;&lt;br /&gt;
It may be an unused column. Original [https://dba.stackexchange.com/questions/196248/what-is-the-sys-c00054-140314103403-column-in-my-regular-oracle-table here]&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
create table t1 as select * from dba_roles;&lt;br /&gt;
&lt;br /&gt;
Table created.&lt;br /&gt;
&lt;br /&gt;
desc t1&lt;br /&gt;
 Name                                      Null?    Type&lt;br /&gt;
 ----------------------------------------- -------- ----------------------------&lt;br /&gt;
 ROLE                                      NOT NULL VARCHAR2(30)&lt;br /&gt;
 PASSWORD_REQUIRED                                  VARCHAR2(8)&lt;br /&gt;
 AUTHENTICATION_TYPE                                VARCHAR2(11)&lt;br /&gt;
&lt;br /&gt;
alter table t1 set unused (AUTHENTICATION_TYPE);&lt;br /&gt;
&lt;br /&gt;
Table altered.&lt;br /&gt;
&lt;br /&gt;
desc t1&lt;br /&gt;
 Name                                      Null?    Type&lt;br /&gt;
 ----------------------------------------- -------- ----------------------------&lt;br /&gt;
 ROLE                                      NOT NULL VARCHAR2(30)&lt;br /&gt;
 PASSWORD_REQUIRED                                  VARCHAR2(8)&lt;br /&gt;
&lt;br /&gt;
select column_name from dba_tab_cols where owner = &amp;#039;&amp;amp;owner.&amp;#039; and table_name = &amp;#039;&amp;amp;table_name.&amp;#039;;&lt;br /&gt;
&lt;br /&gt;
COLUMN_NAME&lt;br /&gt;
------------------------------&lt;br /&gt;
SYS_C00003_18012517:25:39$&lt;br /&gt;
PASSWORD_REQUIRED&lt;br /&gt;
ROLE&lt;br /&gt;
&lt;br /&gt;
SQL&amp;gt; alter table t1 drop unused columns;&lt;br /&gt;
&lt;br /&gt;
Table altered.&lt;br /&gt;
&lt;br /&gt;
select column_name from dba_tab_cols where owner = &amp;#039;&amp;amp;owner.&amp;#039; and table_name = &amp;#039;&amp;amp;table_name.&amp;#039;;&lt;br /&gt;
&lt;br /&gt;
COLUMN_NAME&lt;br /&gt;
------------------------------&lt;br /&gt;
PASSWORD_REQUIRED&lt;br /&gt;
ROLE&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Solution====&lt;br /&gt;
Drop the extended stats, do what you need to do and recreate the extended stats.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
PROCEDURE DROP_EXTENDED_STATS&lt;br /&gt;
 Argument Name                  Type                    In/Out Default?&lt;br /&gt;
 ------------------------------ ----------------------- ------ --------&lt;br /&gt;
 OWNNAME                        VARCHAR2                IN&lt;br /&gt;
 TABNAME                        VARCHAR2                IN&lt;br /&gt;
 EXTENSION                      VARCHAR2                IN&lt;br /&gt;
&lt;br /&gt;
exec dbms_stats.drop_extended_stats ( &amp;#039;KPK&amp;#039;, &amp;#039;XND40&amp;#039;, &amp;#039;(&amp;quot;NOMFIC&amp;quot;,&amp;quot;NUMSEQ&amp;quot;)&amp;#039; );&lt;br /&gt;
&lt;br /&gt;
create table kpk.xnd40_new as select * from kpk.xnd40 where 1=2;&lt;br /&gt;
&lt;br /&gt;
Table created.&lt;br /&gt;
&lt;br /&gt;
select dbms_stats.create_extended_stats ( &amp;#039;KPK&amp;#039;, &amp;#039;XND40&amp;#039;, &amp;#039;(&amp;quot;NOMFIC&amp;quot;,&amp;quot;NUMSEQ&amp;quot;)&amp;#039; ) from   dual;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The stats columns can also be seen in their own table&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 1000 pages 100&lt;br /&gt;
col owner for a6&lt;br /&gt;
col table_name for a20&lt;br /&gt;
col extension_name  for a40&lt;br /&gt;
col extension  for a50&lt;br /&gt;
select owner, table_name, extension_name, extension, creator, droppable from dba_stat_extensions where owner = upper(&amp;#039;&amp;amp;&amp;amp;owner.&amp;#039;) and table_name = upper(&amp;#039;&amp;amp;&amp;amp;table_name.&amp;#039;) and extension_name LIKE &amp;#039;SYS_STS%&amp;#039;;&lt;br /&gt;
&lt;br /&gt;
OWNER TABLE_NAME           EXTENSION_NAME                           EXTENSION                                          CREATOR                  DROPPABLE&lt;br /&gt;
----- -------------------- ---------------------------------------- -------------------------------------------------- ------------------------ ------------&lt;br /&gt;
KPK   XMD01                SYS_STSOA4UXZDBW7MIV5OOR8VOHHK           (&amp;quot;DATCRT&amp;quot;,&amp;quot;CODJRN&amp;quot;)                                SYSTEM                   YES&lt;br /&gt;
KPK   XDD02                SYS_STSFJCZYRZBCQL820ADIR0Y4RZ           (&amp;quot;REFMSG&amp;quot;,&amp;quot;CPTTIT&amp;quot;,&amp;quot;TYPMSG&amp;quot;)                       SYSTEM                   YES&lt;br /&gt;
KPK   XCD09                SYS_STS2OIO647GN0_UV$XO583KKKJ           (&amp;quot;DATCRT&amp;quot;,&amp;quot;HEUMAJ&amp;quot;,&amp;quot;STAMOD&amp;quot;)                       SYSTEM                   YES&lt;br /&gt;
KPK   XCD09                SYS_STS_BRDODC6DJG_HXK0#O9BOYF           (&amp;quot;STAMOD&amp;quot;,&amp;quot;CODMOD&amp;quot;)                                SYSTEM                   YES&lt;br /&gt;
KPK   XCD09                SYS_STS2#DY5U$WQG6COVHB##H2ESK           (&amp;quot;DATMAJ&amp;quot;,&amp;quot;STAMOD&amp;quot;,&amp;quot;CODMOD&amp;quot;)                       SYSTEM                   YES&lt;br /&gt;
KPK   XCD09                SYS_STSO7#D3DI5R8_VAF$WJ32D8MT           (&amp;quot;STAMOD&amp;quot;,&amp;quot;KEYREF_1&amp;quot;)                              SYSTEM                   YES&lt;br /&gt;
KPK   XCD09                SYS_STS4FRY10M34S2L$0FDM1N4B18           (&amp;quot;STAMOD&amp;quot;,&amp;quot;IDTMOD&amp;quot;)                                SYSTEM                   YES&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORA-14404: partitioned table contains partitions in a different tablespace===&lt;br /&gt;
As part of an RMAN duplicate with a skip tablespace, this error is produced&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Reenabling controlfile options for auxiliary database&lt;br /&gt;
Executing: alter database enable block change tracking using file &amp;#039;/oracle/acc/ora_data3/adsa1/bct_adsp_do_not_delete.f&amp;#039;&lt;br /&gt;
&lt;br /&gt;
contents of Memory Script:&lt;br /&gt;
{&lt;br /&gt;
   Alter clone database open resetlogs;&lt;br /&gt;
}&lt;br /&gt;
executing Memory Script&lt;br /&gt;
&lt;br /&gt;
database opened&lt;br /&gt;
Dropping offline and skipped tablespaces&lt;br /&gt;
Executing: drop tablespace &amp;quot;ADS_ARCHIVE&amp;quot; including contents cascade constraints&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-03002: failure of Duplicate Db command at 10/16/2017 23:46:12&lt;br /&gt;
RMAN-05501: aborting duplication of target database&lt;br /&gt;
RMAN-06136: ORACLE error from auxiliary database: ORA-14404: partitioned table contains partitions in a different tablespace&lt;br /&gt;
&lt;br /&gt;
Recovery Manager complete.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
and when attempting to backup the database, we get errors&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
RMAN-06169: could not read file header for datafile 188 error reason 1&lt;br /&gt;
RMAN-06169: could not read file header for datafile 189 error reason 1&lt;br /&gt;
RMAN-06169: could not read file header for datafile 190 error reason 1&lt;br /&gt;
RMAN-06169: could not read file header for datafile 191 error reason 1&lt;br /&gt;
RMAN-06169: could not read file header for datafile 14 error reason 1&lt;br /&gt;
released channel: t1&lt;br /&gt;
released channel: t2&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-03002: failure of backup plus archivelog command at 10/17/2017 15:08:40&lt;br /&gt;
RMAN-06056: could not access datafile 14&lt;br /&gt;
&lt;br /&gt;
Recovery Manager complete.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Problem====&lt;br /&gt;
Tables in the tablespace have partitions in another tablespace so this one cannot be dropped.&amp;lt;br /&amp;gt;&lt;br /&gt;
Check which table partitions are in which tablespaces&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 200&lt;br /&gt;
set pagesize 200&lt;br /&gt;
col table_name for a14&lt;br /&gt;
col table_owner for a14&lt;br /&gt;
col partition_name for a14&lt;br /&gt;
select table_owner&lt;br /&gt;
,      table_name&lt;br /&gt;
,      partition_name&lt;br /&gt;
,      tablespace_name&lt;br /&gt;
from   dba_tab_partitions&lt;br /&gt;
where  (table_owner, table_name) in&lt;br /&gt;
       (&lt;br /&gt;
       select table_owner&lt;br /&gt;
       ,      table_name&lt;br /&gt;
       from   dba_tab_partitions x&lt;br /&gt;
       where  x.tablespace_name = &amp;#039;&amp;amp;&amp;amp;TABLESPACE_TO_DROP&amp;#039;&lt;br /&gt;
       and    exists ( select *&lt;br /&gt;
                       from   dba_tab_partitions y&lt;br /&gt;
                       where  x.table_owner = y.table_owner&lt;br /&gt;
                       and    x.table_name  = y.table_name&lt;br /&gt;
                       and    y.tablespace_name not in (&amp;#039;&amp;amp;TABLESPACE_TO_DROP&amp;#039;)&lt;br /&gt;
                       group  by table_owner&lt;br /&gt;
                       ,      table_name&lt;br /&gt;
                     )&lt;br /&gt;
        )&lt;br /&gt;
order by 1,2,partition_position&lt;br /&gt;
/&lt;br /&gt;
undef TABLESPACE_TO_DROP&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
TABLE_OWNER    TABLE_NAME     PARTITION_NAME TABLESPACE_NAME&lt;br /&gt;
-------------- -------------- -------------- ------------------------------&lt;br /&gt;
KPK            XND20          P0910          TS_THALER_PART_OLD&lt;br /&gt;
KPK            XND20          P1112          TS_THALER_PART_OLD&lt;br /&gt;
KPK            XND20          P13            TS_THALER_PART_OLD&lt;br /&gt;
KPK            XND20          P14            TS_THALER_PART_OLD&lt;br /&gt;
KPK            XND20          P15            TS_THALER_PART_OLD&lt;br /&gt;
KPK            XND20          P16            TS_THALER_DATA&lt;br /&gt;
KPK            XND20          P17            TS_THALER_DATA&lt;br /&gt;
KPK            XND20          P18            TS_THALER_DATA&lt;br /&gt;
KPK            XND20          PMAX           TS_THALER_DATA&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Solution====&lt;br /&gt;
If the intention is to keep all the tables then run this query to generate statements to move the relevant tables out of this tablespace&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select &amp;#039;alter table &amp;#039;||b.table_owner||&amp;#039;.&amp;#039;||b.table_name||&amp;#039; move partition &amp;#039;||b.partition_name||&amp;#039; tablespace &amp;amp;NEW_TABLESPACE;&amp;#039;&lt;br /&gt;
from   (&lt;br /&gt;
       select distinct table_name&lt;br /&gt;
       ,      partition_name&lt;br /&gt;
       from   dba_tab_partitions&lt;br /&gt;
       where  tablespace_name = &amp;#039;&amp;amp;&amp;amp;TABLESPACE_NAME&amp;#039;&lt;br /&gt;
       )                  a&lt;br /&gt;
,      dba_tab_partitions b&lt;br /&gt;
where  a.table_name       = b.table_name&lt;br /&gt;
and    b.tablespace_name != &amp;#039;&amp;amp;TABLESPACE_NAME&amp;#039;&lt;br /&gt;
/&lt;br /&gt;
undef TABLESPACE_NAME&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
If however, the intention is to drop the tablespace anyway, the tables need to be dropped before the tablespace can be dropped.&amp;lt;br /&amp;gt;&lt;br /&gt;
But ...tables with partitions in different tablespaces cannot be dropped. The partitions need to be dropped first!&amp;lt;br /&amp;gt;&lt;br /&gt;
Run the following query to generate statements to drop all the &amp;#039;problem&amp;#039; tables. When these have gone, the tablespace can be dropped.&lt;br /&gt;
* drop table partitions&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
spool /tmp/drop_table_partitions.sql&lt;br /&gt;
sqlplus / as sysdba&amp;lt;&amp;lt;EOSQL&lt;br /&gt;
set headi off newpa none feedb off trims on echo off&lt;br /&gt;
select &amp;#039;alter table &amp;#039;||table_owner||&amp;#039;.&amp;#039;||table_name||&amp;#039; drop partition &amp;#039;||partition_name||&amp;#039;;&amp;#039;&lt;br /&gt;
from   dba_tab_partitions&lt;br /&gt;
where  tablespace_name = &amp;#039;$TABLESPACE_NAME&amp;#039;&lt;br /&gt;
/&lt;br /&gt;
spool off&lt;br /&gt;
EOSQL&lt;br /&gt;
echo &amp;quot;@/tmp/drop_table_partitions.sql&amp;quot; | sqlplus / as sysdba&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* drop tables&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sqlplus / as sysdba&amp;lt;&amp;lt;EOSQL&lt;br /&gt;
select &amp;#039;drop table &amp;#039;||table_owner||&amp;#039;.&amp;#039;||table_name||&amp;#039;;&amp;#039;&lt;br /&gt;
from   dba_tab_partitions&lt;br /&gt;
where  tablespace_name = &amp;#039;$TABLESPACE_NAME&amp;#039;&lt;br /&gt;
spool /tmp/drop_tables.sql&lt;br /&gt;
/&lt;br /&gt;
spool off&lt;br /&gt;
EOSQL&lt;br /&gt;
echo &amp;quot;@/tmp/drop_tables.sql&amp;quot; | sqlplus / as sysdba&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* drop tablespace&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
drop tablespace ads_archive including contents and datafiles&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Find all table partitions in tablespaces with missing datafiles====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 1000 pages 100&lt;br /&gt;
col owner for a10&lt;br /&gt;
col segment_name for a40&lt;br /&gt;
col segment_type for a25&lt;br /&gt;
col partition_name for a20&lt;br /&gt;
col tablespace_name for a25&lt;br /&gt;
select owner&lt;br /&gt;
,      segment_name&lt;br /&gt;
,      segment_type&lt;br /&gt;
,      partition_name&lt;br /&gt;
,      tablespace_name&lt;br /&gt;
from   dba_segments&lt;br /&gt;
where  segment_type in (&amp;#039;TABLE PARTITION&amp;#039;, &amp;#039;TABLE SUBPARTITION&amp;#039;)&lt;br /&gt;
and    tablespace_name in (&lt;br /&gt;
                          select tablespace_name&lt;br /&gt;
                          from   dba_data_files&lt;br /&gt;
                          where  file_name like &amp;#039;%MISSING%&amp;#039;&lt;br /&gt;
                          )&lt;br /&gt;
order  by 1, 2, decode (segment_type, &amp;#039;TABLE SUBPARTITION&amp;#039;, 1, 2),4&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Use exchange partition to alter metadata of the tablespaces without moving the actual data====&lt;br /&gt;
* [https://community.oracle.com/message/2166242#2166242 this] is an explanation of what you are looking for!&amp;lt;br /&amp;gt;&lt;br /&gt;
This is a way of doing the exchange with a neat PL/SQL procedure. It might not do what you want though so understand it before running it!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set serveroutput on size unlimited&lt;br /&gt;
DECLARE&lt;br /&gt;
  dummy_table                   VARCHAR2 (128);&lt;br /&gt;
  cmd                           VARCHAR2 (2048);&lt;br /&gt;
  currowner                     dba_part_tables.owner%TYPE;&lt;br /&gt;
  currtable                     dba_part_tables.table_name%TYPE;&lt;br /&gt;
  l_subpartitioning_type        dba_part_tables.subpartitioning_type%TYPE;&lt;br /&gt;
  l_def_subpartition_count      dba_part_tables.def_subpartition_count%TYPE;&lt;br /&gt;
  l_subpartitioning_key_count   dba_part_tables.subpartitioning_key_count%TYPE;&lt;br /&gt;
  l_curr_qual_table             VARCHAR2 (128);&lt;br /&gt;
&lt;br /&gt;
  PROCEDURE execsql (p_sql IN VARCHAR2)&lt;br /&gt;
  IS&lt;br /&gt;
  BEGIN&lt;br /&gt;
    DBMS_OUTPUT.put_line (p_sql); &lt;br /&gt;
    EXECUTE IMMEDIATE p_sql;&lt;br /&gt;
  END;&lt;br /&gt;
 &lt;br /&gt;
  PROCEDURE force_drop_table (p_table_name IN VARCHAR2)&lt;br /&gt;
  IS&lt;br /&gt;
  BEGIN&lt;br /&gt;
    execsql (&amp;#039;drop table &amp;#039; || p_table_name || &amp;#039; purge&amp;#039;);&lt;br /&gt;
  EXCEPTION&lt;br /&gt;
    WHEN OTHERS&lt;br /&gt;
    THEN&lt;br /&gt;
      NULL;&lt;br /&gt;
  END;&lt;br /&gt;
 &lt;br /&gt;
  PROCEDURE exchange_partition (p_from_table       IN VARCHAR2,&lt;br /&gt;
                                p_from_partition   IN VARCHAR2,&lt;br /&gt;
                                p_to_table         IN VARCHAR2)&lt;br /&gt;
  IS&lt;br /&gt;
  BEGIN&lt;br /&gt;
    execsql (&lt;br /&gt;
         &amp;#039;alter table &amp;#039;&lt;br /&gt;
      || p_from_table&lt;br /&gt;
      || &amp;#039; exchange partition &amp;#039;&lt;br /&gt;
      || p_from_partition&lt;br /&gt;
      || &amp;#039; with table &amp;#039;&lt;br /&gt;
      || p_to_table&lt;br /&gt;
      || &amp;#039; excluding indexes&amp;#039;);&lt;br /&gt;
  END;&lt;br /&gt;
 &lt;br /&gt;
  PROCEDURE drop_partition (p_table IN VARCHAR2, p_partition IN VARCHAR2)&lt;br /&gt;
  IS&lt;br /&gt;
  BEGIN&lt;br /&gt;
    execsql (&amp;#039;alter table &amp;#039; || p_table || &amp;#039; drop partition &amp;#039; || p_partition);&lt;br /&gt;
  END;&lt;br /&gt;
BEGIN&lt;br /&gt;
  currowner := &amp;#039;.&amp;#039;;&lt;br /&gt;
  currtable := &amp;#039;.&amp;#039;;&lt;br /&gt;
 &lt;br /&gt;
  FOR asegment&lt;br /&gt;
    IN (  SELECT owner,&lt;br /&gt;
                 segment_name,&lt;br /&gt;
                 segment_type,&lt;br /&gt;
                 partition_name&lt;br /&gt;
            FROM dba_segments&lt;br /&gt;
           WHERE     segment_type IN (&amp;#039;TABLE PARTITION&amp;#039;, &amp;#039;TABLE SUBPARTITION&amp;#039;)&lt;br /&gt;
                 AND tablespace_name IN (SELECT tablespace_name&lt;br /&gt;
                                           FROM dba_data_files&lt;br /&gt;
                                          WHERE file_name LIKE &amp;#039;%MISSING%&amp;#039;)&lt;br /&gt;
        ORDER BY 1,&lt;br /&gt;
                 2,&lt;br /&gt;
                 DECODE (segment_type, &amp;#039;TABLE SUBPARTITION&amp;#039;, 1, 2),&lt;br /&gt;
                 4)&lt;br /&gt;
  LOOP&lt;br /&gt;
    BEGIN&lt;br /&gt;
      IF currowner &amp;lt;&amp;gt; asegment.owner OR currtable &amp;lt;&amp;gt; asegment.segment_name&lt;br /&gt;
      THEN&lt;br /&gt;
        currowner := asegment.owner;&lt;br /&gt;
        currtable := asegment.segment_name;&lt;br /&gt;
        l_curr_qual_table := asegment.owner || &amp;#039;.&amp;#039; || asegment.segment_name;&lt;br /&gt;
        dummy_table := asegment.owner || &amp;#039;.TBR_EXCHANGE_DUMMY&amp;#039;;&lt;br /&gt;
 &lt;br /&gt;
        force_drop_table (dummy_table);&lt;br /&gt;
 &lt;br /&gt;
        IF asegment.segment_type = &amp;#039;TABLE SUBPARTITION&amp;#039;&lt;br /&gt;
        THEN&lt;br /&gt;
          cmd := &amp;#039;create table &amp;#039; || dummy_table || &amp;#039; partition by &amp;#039;;&lt;br /&gt;
 &lt;br /&gt;
          SELECT subpartitioning_type,&lt;br /&gt;
                 def_subpartition_count,&lt;br /&gt;
                 subpartitioning_key_count&lt;br /&gt;
            INTO l_subpartitioning_type,&lt;br /&gt;
                 l_def_subpartition_count,&lt;br /&gt;
                 l_subpartitioning_key_count&lt;br /&gt;
            FROM dba_part_tables&lt;br /&gt;
           WHERE     owner = asegment.owner&lt;br /&gt;
                 AND table_name = asegment.segment_name;&lt;br /&gt;
 &lt;br /&gt;
          cmd := cmd || l_subpartitioning_type || &amp;#039;(&amp;#039;;&lt;br /&gt;
 &lt;br /&gt;
          FOR asubpartkey&lt;br /&gt;
            IN (  SELECT column_position, column_name&lt;br /&gt;
                    FROM dba_subpart_key_columns&lt;br /&gt;
                   WHERE     owner = asegment.owner&lt;br /&gt;
                         AND name = asegment.segment_name&lt;br /&gt;
                         AND object_type = &amp;#039;TABLE&amp;#039;&lt;br /&gt;
                ORDER BY column_position)&lt;br /&gt;
          LOOP&lt;br /&gt;
            IF asubpartkey.column_position &amp;gt; 1&lt;br /&gt;
            THEN&lt;br /&gt;
              cmd := cmd || &amp;#039;,&amp;#039;;&lt;br /&gt;
            END IF;&lt;br /&gt;
 &lt;br /&gt;
            cmd := cmd || asubpartkey.column_name;&lt;br /&gt;
          END LOOP;&lt;br /&gt;
 &lt;br /&gt;
          cmd := cmd || &amp;#039;) partitions (&amp;#039;;&lt;br /&gt;
 &lt;br /&gt;
          FOR partnr IN 1 .. l_def_subpartition_count&lt;br /&gt;
          LOOP&lt;br /&gt;
            IF partnr &amp;gt; 1&lt;br /&gt;
            THEN&lt;br /&gt;
              cmd := cmd || &amp;#039;,&amp;#039;;&lt;br /&gt;
            END IF;&lt;br /&gt;
 &lt;br /&gt;
            cmd := cmd || &amp;#039;partition p&amp;#039; || partnr;&lt;br /&gt;
          END LOOP;&lt;br /&gt;
 &lt;br /&gt;
          cmd :=&lt;br /&gt;
            cmd || &amp;#039;) as select * from &amp;#039; || l_curr_qual_table || &amp;#039; where 1=0&amp;#039;;&lt;br /&gt;
          execsql (cmd);&lt;br /&gt;
        ELSE&lt;br /&gt;
          execsql (&lt;br /&gt;
               &amp;#039;create table &amp;#039;&lt;br /&gt;
            || dummy_table&lt;br /&gt;
            || &amp;#039; as select * from &amp;#039;&lt;br /&gt;
            || l_curr_qual_table&lt;br /&gt;
            || &amp;#039; where 1=0&amp;#039;);&lt;br /&gt;
        END IF;&lt;br /&gt;
      END IF;&lt;br /&gt;
 &lt;br /&gt;
      exchange_partition (l_curr_qual_table,&lt;br /&gt;
                          asegment.partition_name,&lt;br /&gt;
                          dummy_table);&lt;br /&gt;
 &lt;br /&gt;
      drop_partition (l_curr_qual_table, asegment.partition_name);&lt;br /&gt;
    EXCEPTION&lt;br /&gt;
      WHEN OTHERS&lt;br /&gt;
      THEN&lt;br /&gt;
        DBMS_OUTPUT.put_line (&lt;br /&gt;
          asegment.owner || &amp;#039;.&amp;#039; || asegment.segment_name || &amp;#039; &amp;#039; || SQLERRM);&lt;br /&gt;
    END;&lt;br /&gt;
  END LOOP;&lt;br /&gt;
 &lt;br /&gt;
  IF dummy_table IS NOT NULL&lt;br /&gt;
  THEN&lt;br /&gt;
    force_drop_table (dummy_table);&lt;br /&gt;
  END IF;&lt;br /&gt;
 &lt;br /&gt;
  FOR atablespace IN (  SELECT DISTINCT tablespace_name&lt;br /&gt;
                          FROM dba_data_files&lt;br /&gt;
                         WHERE file_name LIKE &amp;#039;%MISSING%&amp;#039;&lt;br /&gt;
                      ORDER BY 1)&lt;br /&gt;
  LOOP&lt;br /&gt;
    execsql (&lt;br /&gt;
         &amp;#039;drop tablespace &amp;#039;&lt;br /&gt;
      || atablespace.tablespace_name&lt;br /&gt;
      || &amp;#039; including contents and datafiles&amp;#039;);&lt;br /&gt;
  END LOOP;&lt;br /&gt;
END;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Workaround====&lt;br /&gt;
While working on the solution, a backup can be made using the &amp;quot;skip inaccessible&amp;quot; option. Put this in an rman cmdfile...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
connect catalog rmanusr/rmanpwd@rmancat&lt;br /&gt;
connect target sys/syspwd@adsa1&lt;br /&gt;
run {&lt;br /&gt;
allocate channel t1 type &amp;#039;sbt_tape&amp;#039; parms &amp;#039;ENV=(NSR_SERVER=hn6000.company.be,NSR_CLIENT=hn491,NSR_DATA_VOLUME_POOL=DD1DAILY,NSR_END_ERROR_IGNORE=TRUE)&amp;#039;;&lt;br /&gt;
allocate channel t2 type &amp;#039;sbt_tape&amp;#039; parms &amp;#039;ENV=(NSR_SERVER=hn6000.company.be,NSR_CLIENT=hn491,NSR_DATA_VOLUME_POOL=DD1DAILY,NSR_END_ERROR_IGNORE=TRUE)&amp;#039;;&lt;br /&gt;
configure retention policy to recovery window of 28 days;&lt;br /&gt;
configure controlfile autobackup on;&lt;br /&gt;
crosscheck archivelog all;&lt;br /&gt;
SQL &amp;#039;ALTER SYSTEM SWITCH LOGFILE&amp;#039;;&lt;br /&gt;
SQL &amp;#039;CREATE PFILE FROM SPFILE&amp;#039;;&lt;br /&gt;
backup filesperset 1 format &amp;#039;dbfull_%d_%I_%t_%s_%p&amp;#039; full database plus archivelog skip inaccessible delete all input;&lt;br /&gt;
backup current controlfile;&lt;br /&gt;
release channel t1;&lt;br /&gt;
release channel t2;&lt;br /&gt;
}&lt;br /&gt;
exit&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Another way of deleting the offending objects====&lt;br /&gt;
Taken from [http://www.dbarj.com.br/en/2015/01/resume-oracle-duplicate-database-failed-recovery-datafiles/ Recover from a failed RMAN duplicate]&amp;lt;br /&amp;gt;&lt;br /&gt;
Need to check it before running it blindly!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
set echo off feed off termo off trims on pages 0 newpa none lines 2000 headi off long 32000&lt;br /&gt;
col val for a1000&lt;br /&gt;
spool destroy_offending_objects.sql&lt;br /&gt;
&lt;br /&gt;
select to_clob (&amp;#039;alter table &amp;#039;|| table_name||&amp;#039; drop constraint &amp;#039;||constraint_name||&amp;#039;;&amp;#039;) Val&lt;br /&gt;
from user_constraints where constraint_type in (&amp;#039;R&amp;#039;,&amp;#039;P&amp;#039;) and table_name in (select distinct table_name from user_tab_partitions)&lt;br /&gt;
union all&lt;br /&gt;
select to_clob (&amp;#039;drop index &amp;#039;||index_name||&amp;#039;;&amp;#039;) Val from user_indexes where table_name in (select distinct table_name from user_tab_partitions)&lt;br /&gt;
union all&lt;br /&gt;
select to_clob (&amp;#039;alter table &amp;#039;||table_name|| &amp;#039; drop partition &amp;#039;||partition_name||&amp;#039;;&amp;#039;) from dba_tab_partitions&lt;br /&gt;
where tablespace_name in (select tablespace_name from dba_data_files where file_name like &amp;#039;%MISSING%&amp;#039;)&lt;br /&gt;
union all&lt;br /&gt;
Select case&lt;br /&gt;
when instr (VAl, &amp;#039;PARTITION&amp;#039;) = 0 Then&lt;br /&gt;
substr (Val,1,InStr (Val,&amp;#039;)&amp;#039;)+1)||&amp;#039;;&amp;#039;&lt;br /&gt;
else&lt;br /&gt;
substr (Val,1,InStr (Val,&amp;#039;)&amp;#039;)+1)||&amp;#039; local;&amp;#039;&lt;br /&gt;
End val&lt;br /&gt;
from&lt;br /&gt;
(select dbms_metadata.get_ddl (&amp;#039;INDEX&amp;#039;, index_name,&amp;#039;TEST&amp;#039;) Val from user_indexes where table_name in (select distinct table_name from user_tab_partitions))&lt;br /&gt;
union all&lt;br /&gt;
Select Val&lt;br /&gt;
from&lt;br /&gt;
(select dbms_metadata.get_dependent_ddl (&amp;#039;REF_CONSTRAINT&amp;#039;, table_name,&amp;#039;TEST&amp;#039;) Val&lt;br /&gt;
from user_tables where table_name in (select distinct table_name from user_tab_partitions join user_constraints using ( table_name)&lt;br /&gt;
where constraint_type=&amp;#039;R&amp;#039;))&lt;br /&gt;
union all&lt;br /&gt;
select Val&lt;br /&gt;
from&lt;br /&gt;
(select dbms_metadata.get_ddl (&amp;#039;CONSTRAINT&amp;#039;, constraint_name,&amp;#039;TEST&amp;#039;) Val&lt;br /&gt;
from user_constraints&lt;br /&gt;
where constraint_type=&amp;#039;P&amp;#039; and table_name in (select distinct table_name from user_tab_partitions)&lt;br /&gt;
)&lt;br /&gt;
union all&lt;br /&gt;
select to_clob (val)&lt;br /&gt;
from (select distinct &amp;#039;drop tablespace &amp;#039;||tablespace_name|| &amp;#039; including contents and datafiles;&amp;#039; val&lt;br /&gt;
from dba_tab_partitions&lt;br /&gt;
where tablespace_name in (select tablespace_name from dba_data_files where file_name like &amp;#039;%MISSING%&amp;#039;)&lt;br /&gt;
);&lt;br /&gt;
&lt;br /&gt;
spoo off&lt;br /&gt;
&lt;br /&gt;
@destroy_offending_objects&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORA-28112: failed to execute policy function===&lt;br /&gt;
when exporting or importing using [[Data Pump]]&amp;lt; /br&amp;gt;&lt;br /&gt;
During expdp is accompanied by &amp;quot;&amp;#039;&amp;#039;&amp;#039;ORA-31693: Table data object &amp;quot;SYSMAN&amp;quot;.&amp;quot;MGMT_IP_REPORT_DEF&amp;quot; failed to load/unload and is being skipped due to error:&amp;#039;&amp;#039;&amp;#039;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
===Reason===&lt;br /&gt;
This happens due to audit policies being defined on the table but the policy function is defined in another schema.&lt;br /&gt;
&lt;br /&gt;
===Solution===&lt;br /&gt;
Either drop the policy after importing the table with:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
begin&lt;br /&gt;
    for rec in (select * from dba_audit_policies where object_schema = &amp;#039;SYSMAN&amp;#039;) loop&lt;br /&gt;
        dbms_fga.drop_policy(object_schema =&amp;gt; rec.object_schema,&lt;br /&gt;
                             object_name =&amp;gt; rec.object_name,&lt;br /&gt;
                             policy_name =&amp;gt; rec.policy_name);  &lt;br /&gt;
    end loop;&lt;br /&gt;
end;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or exclude the policies during export by adding this to the .par file:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
exclude=FGA_POLICY&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or even better, give the necessary grants to the exporting user...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
grant exempt access policy to impexpusr;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The sysdba role has this automatically.&lt;br /&gt;
===ORA-17629: Cannot connect to the remote database server===&lt;br /&gt;
Active duplication fails to connect even though dns connection exists in tnsnames.ora&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
Problem:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
DUPLICATE TARGET DATABASE FROM ACTIVE DATABASE DORECOVER NOFILENAMECHECK;&lt;br /&gt;
&lt;br /&gt;
RMAN-03002: failure of Duplicate Db command at 05/27/2015 12:52:24&lt;br /&gt;
RMAN-05501: aborting duplication of target database&lt;br /&gt;
RMAN-03015: error occurred in stored script Memory Script&lt;br /&gt;
RMAN-03009: failure of backup command on ORA_DISK_1 channel at 05/27/2015 12:52:23&lt;br /&gt;
ORA-17629: Cannot connect to the remote database server&lt;br /&gt;
ORA-17627: ORA-12154: TNS:could not resolve the connect identifier specified&lt;br /&gt;
&lt;br /&gt;
ORA-17629: Cannot connect to the remote database server&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
Solution:&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
Update the tnsnames.ora of both destination &amp;#039;&amp;#039;&amp;#039;and&amp;#039;&amp;#039;&amp;#039; source ORACLE_HOMEs!&lt;br /&gt;
&lt;br /&gt;
===ORA-01950: no privileges on tablespace &amp;#039;SYSAUX&amp;#039;===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
26-JUN-15 03:12:27.545: &amp;gt;&amp;gt;&amp;gt; ORA-31642: the following SQL statement fails: &lt;br /&gt;
BEGIN &amp;quot;SYS&amp;quot;.&amp;quot;DBMS_RULE_EXP_RULES&amp;quot;.SCHEMA_CALLOUT(:1,0,1,&amp;#039;12.01.00.02.00&amp;#039;); END;&lt;br /&gt;
ORA-01950: no privileges on tablespace &amp;#039;SYSAUX&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Cause:&amp;#039;&amp;#039;&amp;#039;&amp;lt;br /&amp;gt;&lt;br /&gt;
In this case, it seems SYSMAN has no rights to create objects in the SYSAUX tablespace&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Solution:&amp;#039;&amp;#039;&amp;#039;&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter user SYSMAN quota unlimited on sysaux;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
More information [https://support.oracle.com/epmos/faces/SearchDocDisplay?_adf.ctrl-state=bov7jp5pq_4&amp;amp;_afrLoop=547371065896716#SYMPTOM here]&lt;br /&gt;
&lt;br /&gt;
===ORA-39080: failed to create queues &amp;quot;KUPC$C_1_20150616165037&amp;quot; and &amp;quot;KUPC$S_1_20150616165037&amp;quot; for Data Pump job===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
expdp /&lt;br /&gt;
&lt;br /&gt;
Export: Release 11.2.0.4.0 - Production on Tue Jun 16 16:50:36 2015&lt;br /&gt;
&lt;br /&gt;
Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.&lt;br /&gt;
&lt;br /&gt;
Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production&lt;br /&gt;
With the Partitioning, OLAP, Data Mining and Real Application Testing options&lt;br /&gt;
ORA-31626: job does not exist&lt;br /&gt;
ORA-31637: cannot create job SYS_EXPORT_SCHEMA_01 for user OPS$ORAIBM&lt;br /&gt;
ORA-06512: at &amp;quot;SYS.DBMS_SYS_ERROR&amp;quot;, line 95&lt;br /&gt;
ORA-06512: at &amp;quot;SYS.KUPV$FT_INT&amp;quot;, line 798&lt;br /&gt;
[[ORA-39080: failed to create queues &amp;quot;KUPC$C_1_20150616165037&amp;quot; and &amp;quot;KUPC$S_1_20150616165037&amp;quot; for Data Pump job]]&lt;br /&gt;
ORA-06512: at &amp;quot;SYS.DBMS_SYS_ERROR&amp;quot;, line 95&lt;br /&gt;
ORA-06512: at &amp;quot;SYS.KUPC$QUE_INT&amp;quot;, line 1534&lt;br /&gt;
ORA-24002: QUEUE_TABLE SYS.AQ$KUPC$DATAPUMP_QUETAB_1 does not exist&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Cause:====&lt;br /&gt;
Possibly some or all of OLAP module has got itself deinstalled.&lt;br /&gt;
====Solution:====&lt;br /&gt;
Try:&lt;br /&gt;
* Recompiling invalid objects. @?/rdbms/admin/utlrp&lt;br /&gt;
* Reinstalling DBMS_CUBE packages by (re)running catproc.sql. @?/rdbms/admin/catproc followed by @?/rdbms/admin/utlrp&lt;br /&gt;
* Reinstalling OLAP. @?/olap/admin/olap.sql SYSAUX TEMP; But see Metalink note ID 296187.1 for full instructions.&lt;br /&gt;
* Check metalink for bugs. See ID 345198.1 and possibly ID 453796.1&lt;br /&gt;
===ORA-14063: Unusable index exists on unique/primary constraint key===&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;ORA-39083: Object type CONSTRAINT failed to create with error:&amp;#039;&amp;#039;&amp;#039;&amp;lt;br /&amp;gt;&lt;br /&gt;
During an import datapump (impdp), import failed because indexes were in error before the tables were exported. This causes the import of rows to be skipped.&amp;lt;br /&amp;gt;&lt;br /&gt;
If the export cannot be done again (having compiled the indexes), then the metadata can be imported and the indexes compiled before importing the data.&lt;br /&gt;
* Import the metadata&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cat&amp;lt;&amp;lt;EOCAT &amp;gt;impdp_adst_ads_archive_metadata.par&lt;br /&gt;
userid=&amp;#039;/ as sysdba&amp;#039;&lt;br /&gt;
dumpfile=adst_ads_archive.dmp&lt;br /&gt;
logfile=impdp_adst_ads_archive_metadata.log&lt;br /&gt;
content=metadata_only&lt;br /&gt;
EOCAT&lt;br /&gt;
&lt;br /&gt;
impdp parfile=impdp_adst_ads_archive_metadata.par&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Find the bad indexes and recompile them&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select &amp;#039;alter index &amp;#039;|| owner||&amp;#039;.&amp;#039;||index_name||&amp;#039; rebuild online parallel 8;&amp;#039;&lt;br /&gt;
from   dba_indexes&lt;br /&gt;
where  status = &amp;#039;UNUSABLE&amp;#039;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Import the data&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cat&amp;lt;&amp;lt;EOCAT &amp;gt;impdp_adst_ads_archive_data.par&lt;br /&gt;
userid=&amp;#039;/ as sysdba&amp;#039;&lt;br /&gt;
dumpfile=adst_ads_archive.dmp&lt;br /&gt;
logfile=impdp_adst_ads_archive_data.log&lt;br /&gt;
table_exists_action=append&lt;br /&gt;
content=data_only&lt;br /&gt;
EOCAT&lt;br /&gt;
&lt;br /&gt;
impdp parfile=impdp_adst_ads_archive_data.par&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORA-09925: Unable to create audit trail file===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SQL&amp;gt; startup nomount pfile=&amp;quot;/oracle/TRSCRP1/admin/initTRSCRP1.ora&amp;quot;&lt;br /&gt;
ORA-09925: Unable to create audit trail file&lt;br /&gt;
SVR4 Error: 2: No such file or directory&lt;br /&gt;
Additional information: 9925&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
connected to auxiliary database (not started)&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-03002: failure of Duplicate Db command at 08/29/2017 15:53:09&lt;br /&gt;
RMAN-05501: aborting duplication of target database&lt;br /&gt;
RMAN-03015: error occurred in stored script Memory Script&lt;br /&gt;
RMAN-04014: startup failed: ORA-09925: Unable to create audit trail file&lt;br /&gt;
IBM AIX RISC System/6000 Error: 2: No such file or directory&lt;br /&gt;
Additional information: 9925&lt;br /&gt;
&lt;br /&gt;
Recovery Manager complete.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Problem====&lt;br /&gt;
This will be almost certainly one of two issues. Either the directory is not writable by the id that started the instance or the directory just does not exist.&lt;br /&gt;
====Solution====&lt;br /&gt;
Note there can be a difference between what you see when you type:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
show parameter audit&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
and when you type:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
strings -a $ORACLE_HOME/dbs/spfile${ORACLE_SID}.ora | grep -i audit&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
due to someone doing an &amp;quot;alter system&amp;quot; without the &amp;quot;scope=spfile&amp;quot; or &amp;quot;scope=both&amp;quot;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SQL&amp;gt; host ls -al /oracle/TRSCRP1/admin/adump&lt;br /&gt;
SQL&amp;gt; host mkdir /oracle/TRSCRP1/admin/adump&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===ORA-09925: Unable to create audit trail file===&lt;br /&gt;
When starting SQL*Plus with no db processes running (expecting to see &amp;quot;Connected to an idle instance&amp;quot;), we get this:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ERROR:&lt;br /&gt;
ORA-09925: Unable to create audit trail file&lt;br /&gt;
IBM AIX RISC System/6000 Error: 2: No such file or directory&lt;br /&gt;
Additional information: 9925&lt;br /&gt;
ORA-01075: you are currently logged on&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Filesystem permissions are fine&lt;br /&gt;
* &amp;#039;strings spfile&amp;lt;SID&amp;gt;.ora | grep audit&amp;#039; shows the correct directory&lt;br /&gt;
* Running on AIX&lt;br /&gt;
AIX is the clue here... need to check for semaphores and locked shared memory objects&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
(0) UCLID55D oraibm@solax082:/oracle/product/11.2.0.3/bin&amp;gt; sysresv&lt;br /&gt;
&lt;br /&gt;
IPC Resources for ORACLE_SID &amp;quot;UCLID55D&amp;quot; :&lt;br /&gt;
Shared Memory:&lt;br /&gt;
ID              KEY&lt;br /&gt;
8388640         0xffffffff&lt;br /&gt;
579862561       0xffffffff&lt;br /&gt;
384827426       0x326f32e8&lt;br /&gt;
&lt;br /&gt;
Semaphores:&lt;br /&gt;
ID              KEY&lt;br /&gt;
167772287       0xf09f4914&lt;br /&gt;
Oracle Instance alive for sid &amp;quot;UCLID55D&amp;quot;&lt;br /&gt;
&lt;br /&gt;
(0) UCLID55D oraibm@solax082:/oracle/product/11.2.0.3/bin&amp;gt; ipcrm -m 8388640&lt;br /&gt;
(0) UCLID55D oraibm@solax082:/oracle/product/11.2.0.3/bin&amp;gt; ipcrm -m 579862561&lt;br /&gt;
(0) UCLID55D oraibm@solax082:/oracle/product/11.2.0.3/bin&amp;gt; ipcrm -m 384827426&lt;br /&gt;
&lt;br /&gt;
(0) UCLID55D oraibm@solax082:/oracle/product/11.2.0.3/bin&amp;gt; ipcrm -s 167772287&lt;br /&gt;
&lt;br /&gt;
(0) UCLID55D oraibm@solax082:/oracle/product/11.2.0.3/bin&amp;gt; sysresv&lt;br /&gt;
&lt;br /&gt;
IPC Resources for ORACLE_SID &amp;quot;UCLID55D&amp;quot; :&lt;br /&gt;
Shared Memory&lt;br /&gt;
ID              KEY&lt;br /&gt;
No shared memory segments used&lt;br /&gt;
Semaphores:&lt;br /&gt;
ID              KEY&lt;br /&gt;
No semaphore resources used&lt;br /&gt;
Oracle Instance not alive for sid &amp;quot;UCLID55D&amp;quot;&lt;br /&gt;
&lt;br /&gt;
(0) UCLID55D oraibm@solax082:/oracle/product/11.2.0.3/bin&amp;gt; ps -ef | grep UCLID55D&lt;br /&gt;
oraibm 3326 23776 0 14:12:05 pts/1 0:00 grep UCLID55D &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===RMAN-06023: no backup or copy of datafile 1 found to restore===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-03002: failure of Duplicate Db command at 05/16/2018 16:08:13&lt;br /&gt;
RMAN-05501: aborting duplication of target database&lt;br /&gt;
RMAN-05556: not all datafiles have backups that can be recovered to SCN 278250901080&lt;br /&gt;
RMAN-03015: error occurred in stored script Memory Script&lt;br /&gt;
RMAN-06026: some targets not found - aborting restore&lt;br /&gt;
RMAN-06023: no backup or copy of datafile 7 found to restore&lt;br /&gt;
RMAN-06023: no backup or copy of datafile 6 found to restore&lt;br /&gt;
RMAN-06023: no backup or copy of datafile 5 found to restore&lt;br /&gt;
RMAN-06023: no backup or copy of datafile 4 found to restore&lt;br /&gt;
RMAN-06023: no backup or copy of datafile 3 found to restore&lt;br /&gt;
RMAN-06023: no backup or copy of datafile 2 found to restore&lt;br /&gt;
RMAN-06023: no backup or copy of datafile 1 found to restore&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Seems pretty straightforward? SCN was set too early for the retention period. But no, not this time.&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
RMAN&amp;gt; list backup of datafile 1;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
List of Backup Sets&lt;br /&gt;
===================&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
BS Key  Type LV Size       Device Type Elapsed Time Completion Time&lt;br /&gt;
------- ---- -- ---------- ----------- ------------ -------------------&lt;br /&gt;
110170340 Incr 0  132.90G    SBT_TAPE    00:18:32     2018-05-14 01:19:40&lt;br /&gt;
        BP Key: 110170345   Status: AVAILABLE  Compressed: NO  Tag: WEEKLY_FULL&lt;br /&gt;
        Handle: 24639762_REPORTA_07t2r3uk_1_1   Media: V_17152809_77191330&lt;br /&gt;
  List of Datafiles in backup set 110170340&lt;br /&gt;
  File LV Type Ckp SCN    Ckp Time            Name&lt;br /&gt;
  ---- -- ---- ---------- ------------------- ----&lt;br /&gt;
  1    0  Incr 277998128991 2018-05-14 01:01:08 /cln/acc/ora_data3/reporta/system01.dbf&lt;br /&gt;
&lt;br /&gt;
BS Key  Type LV Size       Device Type Elapsed Time Completion Time&lt;br /&gt;
------- ---- -- ---------- ----------- ------------ -------------------&lt;br /&gt;
110355808 Incr 1  204.00M    SBT_TAPE    00:05:13     2018-05-15 01:06:22&lt;br /&gt;
        BP Key: 110355813   Status: AVAILABLE  Compressed: NO  Tag: DAILY_INCREMENTAL&lt;br /&gt;
        Handle: 24661053_REPORTA_3ft2toal_1_1   Media: V_17173010_77253424&lt;br /&gt;
  List of Datafiles in backup set 110355808&lt;br /&gt;
  File LV Type Ckp SCN    Ckp Time            Name&lt;br /&gt;
  ---- -- ---- ---------- ------------------- ----&lt;br /&gt;
  1    1  Incr 278044267395 2018-05-15 01:01:09 /cln/acc/ora_data3/reporta/system01.dbf&lt;br /&gt;
&lt;br /&gt;
BS Key  Type LV Size       Device Type Elapsed Time Completion Time&lt;br /&gt;
------- ---- -- ---------- ----------- ------------ -------------------&lt;br /&gt;
110543802 Incr 1  237.00M    SBT_TAPE    00:05:51     2018-05-16 01:07:40&lt;br /&gt;
        BP Key: 110543807   Status: AVAILABLE  Compressed: NO  Tag: DAILY_INCREMENTAL&lt;br /&gt;
        Handle: 24681602_REPORTA_6nt30cnt_1_1   Media: V_17133646_77315270&lt;br /&gt;
  List of Datafiles in backup set 110543802&lt;br /&gt;
  File LV Type Ckp SCN    Ckp Time            Name&lt;br /&gt;
  ---- -- ---- ---------- ------------------- ----&lt;br /&gt;
  1    1  Incr 278286445856 2018-05-16 01:01:50 /cln/acc/ora_data3/reporta/system01.dbf&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
SCN was only 12 hours ago with a retention of 28 days! The backup piece dated 2018-05-15 01:06:22 is clearly available and on the device type set_tape.&amp;lt;br /&amp;gt;&lt;br /&gt;
The trick here was to look back through the logs and look more closely at what the file restore message was saying...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
channel t0: starting datafile backup set restore&lt;br /&gt;
channel t0: specifying datafile(s) to restore from backup set&lt;br /&gt;
channel t0: restoring datafile 00001 to /cln/acc/ora_data3/reporta/system01.dbf             &amp;lt; &amp;lt; &amp;lt; ==============&lt;br /&gt;
channel t0: reading from backup piece dbfull_REPORTA_738887052_967580186_116_1&lt;br /&gt;
channel t2: ORA-19870: error while restoring backup piece dbfull_REPORTA_738887052_967579750_113_1&lt;br /&gt;
ORA-19507: failed to retrieve sequential file, handle=&amp;quot;dbfull_REPORTA_738887052_967579750_113_1&amp;quot;, parms=&amp;quot;&amp;quot;&lt;br /&gt;
ORA-27029: skgfrtrv: sbtrestore returned error&lt;br /&gt;
ORA-19511: non RMAN, but media manager or vendor specific failure, error text:&lt;br /&gt;
   CreateOraObject20: Job[0] thread[55116090]: Restore: GetBackupInfo() for Archive File[dbfull_REPORTA_738887052_967579750_113_1] failed.&lt;br /&gt;
ORA-0651&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
It was not the fact that it could not find the data on tape, it was that it could not save the file to the location indicated!!&lt;br /&gt;
In the RMAN DUPLICATE script, I had all the file paths redirected (a mixture of convert parameters and spfile set) to a /restore filesystem.&amp;lt;br /&amp;gt;&lt;br /&gt;
But I forgot one!&amp;lt;br /&amp;gt;&lt;br /&gt;
A handy thing to do is to search out the file paths with this to see if something is still wrong:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cd $ORACLE_HOME/dbs&lt;br /&gt;
strings -a spfile${ORACLE_SID}.ora | grep dest&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This should show any paths still not getting caught by the DUPLICATE script.&lt;br /&gt;
&lt;br /&gt;
===RMAN-06136: ORACLE error from auxiliary database: ORA-06502: PL/SQL: numeric or value error===&lt;br /&gt;
When cloning a database, the duplicate fails with this error.&lt;br /&gt;
====Problem====&lt;br /&gt;
This duplicate had no target connection but did have a catalog and auxiliary connection.&lt;br /&gt;
In the catalog (which was the catalog where the target was registerd), there was also an entry in that catalog with the same name as the auxiliary - left over from the days when these 2 instances were Primary and Standby in a Dataguard configuration.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
Datafile 414 skipped by request&lt;br /&gt;
Datafile 415 skipped by request&lt;br /&gt;
Datafile 419 skipped by request&lt;br /&gt;
Datafile 420 skipped by request&lt;br /&gt;
Datafile 421 skipped by request&lt;br /&gt;
&lt;br /&gt;
DBGSQL:     AUXILIARY&amp;gt; begin :ofname := sys.dbms_backup_restore.convertFileName( fname   =&amp;gt;   :ifname, ftype   =&amp;gt;   :iftype, osftype =&amp;gt;   TRUE); end;&lt;br /&gt;
DBGSQL:        sqlcode = 6502&lt;br /&gt;
DBGSQL:         B :ofname = NULL&lt;br /&gt;
DBGSQL:         B :ifname =&lt;br /&gt;
DBGSQL:         B :iftype = 2&lt;br /&gt;
restarting auxiliary database without server parameter file&lt;br /&gt;
Oracle instance started&lt;br /&gt;
&lt;br /&gt;
Total System Global Area   32068440064 bytes&lt;br /&gt;
&lt;br /&gt;
Fixed Size                     2262200 bytes&lt;br /&gt;
Variable Size              16978545480 bytes&lt;br /&gt;
Database Buffers           15032385536 bytes&lt;br /&gt;
Redo Buffers                  55246848 bytes&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-03002: failure of Duplicate Db command at 10/04/2017 14:50:29&lt;br /&gt;
RMAN-05501: aborting duplication of target database&lt;br /&gt;
RMAN-06136: ORACLE error from auxiliary database: ORA-06502: PL/SQL: numeric or value error&lt;br /&gt;
&lt;br /&gt;
Recovery Manager complete.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Solution====&lt;br /&gt;
Connect to the catalog and unregister the name of the auxiliary database. It shouldn&amp;#039;t be there anyway.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rman catalog rmanusr/rmanpwd@rmancat&lt;br /&gt;
&lt;br /&gt;
Recovery Manager: Release 11.2.0.4.0 - Production on Wed Oct 4 15:00:00 2017&lt;br /&gt;
&lt;br /&gt;
Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.&lt;br /&gt;
&lt;br /&gt;
connected to recovery catalog database&lt;br /&gt;
&lt;br /&gt;
RMAN&amp;gt; set dbid 4260753020;&lt;br /&gt;
&lt;br /&gt;
executing command: SET DBID&lt;br /&gt;
database name is &amp;quot;LBK&amp;quot; and DBID is 4260753020&lt;br /&gt;
&lt;br /&gt;
RMAN&amp;gt; list db_unique_name of database;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
List of Databases&lt;br /&gt;
DB Key  DB Name  DB ID            Database Role    Db_unique_name&lt;br /&gt;
------- ------- ----------------- ---------------  ------------------&lt;br /&gt;
13301587 LBK      4260753020       PRIMARY          LBK&lt;br /&gt;
13301587 LBK      4260753020       STANDBY          ACC_PERF&lt;br /&gt;
13301587 LBK      4260753020       STANDBY          LBKRO&lt;br /&gt;
&lt;br /&gt;
RMAN&amp;gt; unregister db_unique_name &amp;#039;ACC_PERF&amp;#039;;&lt;br /&gt;
&lt;br /&gt;
database db_unique_name is &amp;quot;ACC_PERF&amp;quot;, db_name is &amp;quot;LBK&amp;quot; and DBID is 4260753020&lt;br /&gt;
&lt;br /&gt;
Want to unregister the database with target db_unique_name (enter YES or NO)? YES&lt;br /&gt;
database with db_unique_name ACC_PERF unregistered from the recovery catalog&lt;br /&gt;
&lt;br /&gt;
RMAN&amp;gt; exit&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORA-39181: Only partial table data may be exported due to fine grain access control on &amp;quot;owner&amp;quot;.&amp;quot;&amp;lt;table_name&amp;gt;&amp;quot;===&lt;br /&gt;
&lt;br /&gt;
===Reason===&lt;br /&gt;
This happens when applications are designed with fine-grained access.&lt;br /&gt;
===Solution===&lt;br /&gt;
Grant the necessary privileges to the exporting user...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
grant exempt access policy to ops$oraibm;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORA-04030: out of process memory when trying to allocate 2520 bytes===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
expdp problem (ORA-04030: out of process memory when trying to allocate 2520 bytes (pga heap,koh-kghu call heap))&lt;br /&gt;
&lt;br /&gt;
select value from v$pgastat where name=&amp;#039;maximum PGA allocated&amp;#039;;&lt;br /&gt;
&lt;br /&gt;
SHOW PARAMETER TARGET&lt;br /&gt;
&lt;br /&gt;
ORA-04030: out of process memory when trying to allocate 2520 bytes (pga heap,koh-kghu call heap)&lt;br /&gt;
&lt;br /&gt;
alter system reset pga_aggregate_target scope=spfile;&lt;br /&gt;
&lt;br /&gt;
show sga&lt;br /&gt;
&lt;br /&gt;
select * from v$pgastat;&lt;br /&gt;
&lt;br /&gt;
show parameter process&lt;br /&gt;
&lt;br /&gt;
select sum(value)/1024/1024 Mb&lt;br /&gt;
from   v$sesstat s, v$statname n&lt;br /&gt;
where  1=1&lt;br /&gt;
and    n.STATISTIC# = s.STATISTIC#&lt;br /&gt;
and    name = &amp;#039;session pga memory&amp;#039;&lt;br /&gt;
&lt;br /&gt;
show parameter WORKAREA&lt;br /&gt;
&lt;br /&gt;
select value from v$pgastat where name=&amp;#039;maximum PGA allocated&amp;#039;;&lt;br /&gt;
&lt;br /&gt;
alter system set memory_max_target=10G scope=spfile;&lt;br /&gt;
&lt;br /&gt;
alter system set memory_target=3G scope=both;&lt;br /&gt;
&lt;br /&gt;
select * from v$memory_target_advice order by memory_size;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORA-04031: unable to allocate 32 bytes of shared memory (&amp;quot;shared pool&amp;quot;,&amp;quot;select name,online$,contents...&amp;quot;,&amp;quot;KGLH0^e5705bfc&amp;quot;,&amp;quot;kglHeapInitialize:temp&amp;quot;)===&lt;br /&gt;
* [https://blogs.oracle.com/db/entry/ora-4031_troubleshooting ORA-4031 Troubleshooting]&lt;br /&gt;
* [https://support.oracle.com/epmos/faces/DocumentDisplay?_afrLoop=89215376348478&amp;amp;id=396940.1&amp;amp;_afrWindowMode=0&amp;amp;_adf.ctrl-state=u1z0xcppg_4 Troubleshooting and Diagnosing ORA-4031 Error - (Doc ID 396940.1)]&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ORA-04031: unable to allocate  bytes of shared memory (&amp;quot;&amp;quot;,&amp;quot;&amp;quot;,&amp;quot;&amp;quot;,&amp;quot;&amp;quot;) &lt;br /&gt;
ORA-04031: unable to allocate 32 bytes of shared memory (&amp;quot;shared pool&amp;quot;,&amp;quot;select name,online$,contents...&amp;quot;,&amp;quot;KGLH0^e5705bfc&amp;quot;,&amp;quot;kglHeapInitialize:temp&amp;quot;) &lt;br /&gt;
Incident details in: /oracle/diag/rdbms/mape/MAPE/incident/incdir_86754/MAPE_dm00_14221536_i86754.trc &lt;br /&gt;
Wed Jul 31 20:42:50 2013 &lt;br /&gt;
Dumping diagnostic data in directory=[cdmp_20130731204250], requested by (instance=1, osid=14221536 (DM00)), summary=[incident=86753]. &lt;br /&gt;
Wed Jul 31 20:42:51 2013 &lt;br /&gt;
Sweep [inc][86754]: completed &lt;br /&gt;
Sweep [inc][86753]: completed &lt;br /&gt;
Sweep [inc2][86753]: completed &lt;br /&gt;
Wed Jul 31 20:42:57 2013 &lt;br /&gt;
Use ADRCI or Support Workbench to package the incident. &lt;br /&gt;
See Note 411.1 at My Oracle Support for error and packaging details. &lt;br /&gt;
Dumping diagnostic data in directory=[cdmp_20130731204257], requested by (instance=1, osid=14221536 (DM00)), summary=[incident=86754]. &lt;br /&gt;
Wed Jul 31 20:43:35 2013 &lt;br /&gt;
Errors in file /oracle/diag/rdbms/mape/MAPE/trace/MAPE_dw02_40567024.trc  (incident=82993): &lt;br /&gt;
ORA-04031: unable to allocate 32 bytes of shared memory (&amp;quot;shared pool&amp;quot;,&amp;quot;select order#,columns,types ...&amp;quot;,&amp;quot;KGLH0^470434f8&amp;quot;,&amp;quot;kglHeapInitialize:temp&amp;quot;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Database had already crashed so nothing to do but:&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
(0) MAPE ora@x025:/home/ora&amp;gt; sqlplus / as sysdba&lt;br /&gt;
&lt;br /&gt;
SQL*Plus: Release 11.2.0.3.0 Production on Fri Aug 2 14:26:20 2013&lt;br /&gt;
&lt;br /&gt;
Copyright (c) 1982, 2011, Oracle.  All rights reserved.&lt;br /&gt;
&lt;br /&gt;
Connected.&lt;br /&gt;
SYS@MAPE&amp;gt; alter system flush shared_pool;&lt;br /&gt;
alter system flush shared_pool&lt;br /&gt;
*&lt;br /&gt;
ERROR at line 1:&lt;br /&gt;
ORA-01012: not logged on&lt;br /&gt;
Process ID: 0&lt;br /&gt;
Session ID: 0 Serial number: 0&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
SYS@MAPE&amp;gt; shutdown abort&lt;br /&gt;
ORACLE instance shut down.&lt;br /&gt;
SYS@MAPE&amp;gt; startup&lt;br /&gt;
ORACLE instance started.&lt;br /&gt;
&lt;br /&gt;
Total System Global Area  734892032 bytes&lt;br /&gt;
Fixed Size                  2225128 bytes&lt;br /&gt;
Variable Size             398461976 bytes&lt;br /&gt;
Database Buffers          318767104 bytes&lt;br /&gt;
Redo Buffers               15437824 bytes&lt;br /&gt;
Database mounted.&lt;br /&gt;
Database opened.&lt;br /&gt;
&lt;br /&gt;
SYS@MAPE&amp;gt; show parameter pool&lt;br /&gt;
&lt;br /&gt;
NAME                                 TYPE                           VALUE&lt;br /&gt;
------------------------------------ ------------------------------ ------------------------------&lt;br /&gt;
buffer_pool_keep                     string&lt;br /&gt;
buffer_pool_recycle                  string&lt;br /&gt;
global_context_pool_size             string&lt;br /&gt;
java_pool_size                       big integer                    0&lt;br /&gt;
large_pool_size                      big integer                    0&lt;br /&gt;
olap_page_pool_size                  big integer                    0&lt;br /&gt;
shared_pool_reserved_size            big integer                    18M&lt;br /&gt;
shared_pool_size                     big integer                    208M&lt;br /&gt;
streams_pool_size                    big integer                    0&lt;br /&gt;
SYS@MAPE&amp;gt; show sga&lt;br /&gt;
&lt;br /&gt;
Total System Global Area  734892032 bytes&lt;br /&gt;
Fixed Size                  2225128 bytes&lt;br /&gt;
Variable Size             385879064 bytes&lt;br /&gt;
Database Buffers          331350016 bytes&lt;br /&gt;
Redo Buffers               15437824 bytes&lt;br /&gt;
SYS@MAPE&amp;gt; exit&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
but for reference, the causes could well be the applications running on the database are not using bind variables...&amp;lt;br /&amp;gt;&lt;br /&gt;
From [http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:528893984337 asktom.oracle.com]&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
Just to give you a tiny idea of how huge of a difference this &lt;br /&gt;
can make performance wise, you only need to run a very small &lt;br /&gt;
test:&lt;br /&gt;
&lt;br /&gt;
tkyte@TKYTE816&amp;gt; alter system flush shared_pool;&lt;br /&gt;
System altered.&lt;br /&gt;
&lt;br /&gt;
tkyte@TKYTE816&amp;gt; declare&lt;br /&gt;
  2      type rc is ref cursor;&lt;br /&gt;
  3      l_rc rc;&lt;br /&gt;
  4      l_dummy all_objects.object_name%type;&lt;br /&gt;
  5      l_start number default dbms_utility.get_time;&lt;br /&gt;
  6  begin&lt;br /&gt;
  7      for i in 1 .. 1000&lt;br /&gt;
  8      loop&lt;br /&gt;
  9          open l_rc for&lt;br /&gt;
 10          &amp;#039;select object_name&lt;br /&gt;
 11             from all_objects&lt;br /&gt;
 12            where object_id = &amp;#039; || i;&lt;br /&gt;
 13          fetch l_rc into l_dummy;&lt;br /&gt;
 14          close l_rc;&lt;br /&gt;
 15      end loop;&lt;br /&gt;
 16      dbms_output.put_line&lt;br /&gt;
 17      ( round( (dbms_utility.get_time-l_start)/100, 2 ) ||&lt;br /&gt;
 18        &amp;#039; seconds...&amp;#039; );&lt;br /&gt;
 19  end;&lt;br /&gt;
 20  /&lt;br /&gt;
14.86 seconds...&lt;br /&gt;
&lt;br /&gt;
PL/SQL procedure successfully completed.&lt;br /&gt;
&lt;br /&gt;
tkyte@TKYTE816&amp;gt; declare&lt;br /&gt;
  2      type rc is ref cursor;&lt;br /&gt;
  3      l_rc rc;&lt;br /&gt;
  4      l_dummy all_objects.object_name%type;&lt;br /&gt;
  5      l_start number default dbms_utility.get_time;&lt;br /&gt;
  6  begin&lt;br /&gt;
  7      for i in 1 .. 1000&lt;br /&gt;
  8      loop&lt;br /&gt;
  9          open l_rc for&lt;br /&gt;
 10          &amp;#039;select object_name&lt;br /&gt;
 11             from all_objects&lt;br /&gt;
 12            where object_id = :x&amp;#039;&lt;br /&gt;
 13          using i;&lt;br /&gt;
 14          fetch l_rc into l_dummy;&lt;br /&gt;
 15          close l_rc;&lt;br /&gt;
 16      end loop;&lt;br /&gt;
 17      dbms_output.put_line&lt;br /&gt;
 18      ( round( (dbms_utility.get_time-l_start)/100, 2 ) ||&lt;br /&gt;
 19        &amp;#039; seconds...&amp;#039; );&lt;br /&gt;
 20  end;&lt;br /&gt;
 21  /&lt;br /&gt;
1.27 seconds...&lt;br /&gt;
&lt;br /&gt;
PL/SQL procedure successfully completed.&lt;br /&gt;
&lt;br /&gt;
That is pretty dramatic.  The fact is that not only does this &lt;br /&gt;
execute much faster (we spent more time PARSING our queries then &lt;br /&gt;
actually EXECUTING them!) it will let more users use your system &lt;br /&gt;
simultaneously.&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
and from [http://asktom.oracle.com/pls/asktom/f?p=100:11:::::P11_QUESTION_ID:1163635055580 linked question]&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
Lbrary cache latch contention is typically caused by NOT using bind variables.  It is due &lt;br /&gt;
to excessive parsing of statements.&lt;br /&gt;
&lt;br /&gt;
One way to see if this might be the case in your situation is to run a script like:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
create table t1 as select sql_text from v$sqlarea;&lt;br /&gt;
&lt;br /&gt;
alter table t1 add sql_text_wo_constants varchar2(1000);&lt;br /&gt;
&lt;br /&gt;
create or replace function &lt;br /&gt;
remove_constants( p_query in varchar2 ) return varchar2&lt;br /&gt;
as&lt;br /&gt;
    l_query long;&lt;br /&gt;
    l_char  varchar2(1);&lt;br /&gt;
    l_in_quotes boolean default FALSE;&lt;br /&gt;
begin&lt;br /&gt;
    for i in 1 .. length( p_query )&lt;br /&gt;
    loop&lt;br /&gt;
        l_char := substr(p_query,i,1);&lt;br /&gt;
        if ( l_char = &amp;#039;&amp;#039;&amp;#039;&amp;#039; and l_in_quotes )&lt;br /&gt;
        then&lt;br /&gt;
            l_in_quotes := FALSE;&lt;br /&gt;
        elsif ( l_char = &amp;#039;&amp;#039;&amp;#039;&amp;#039; and NOT l_in_quotes )&lt;br /&gt;
        then&lt;br /&gt;
            l_in_quotes := TRUE;&lt;br /&gt;
            l_query := l_query || &amp;#039;&amp;#039;&amp;#039;#&amp;#039;;&lt;br /&gt;
        end if;&lt;br /&gt;
        if ( NOT l_in_quotes ) then&lt;br /&gt;
            l_query := l_query || l_char;&lt;br /&gt;
        end if;&lt;br /&gt;
    end loop;&lt;br /&gt;
    l_query := translate( l_query, &amp;#039;0123456789&amp;#039;, &amp;#039;@@@@@@@@@@&amp;#039; );&lt;br /&gt;
    for i in 0 .. 8 loop&lt;br /&gt;
        l_query := replace( l_query, lpad(&amp;#039;@&amp;#039;,10-i,&amp;#039;@&amp;#039;), &amp;#039;@&amp;#039; );&lt;br /&gt;
        l_query := replace( l_query, lpad(&amp;#039; &amp;#039;,10-i,&amp;#039; &amp;#039;), &amp;#039; &amp;#039; );&lt;br /&gt;
    end loop;&lt;br /&gt;
    return upper(l_query);&lt;br /&gt;
end;&lt;br /&gt;
/&lt;br /&gt;
update t1 set sql_text_wo_constants = remove_constants(sql_text);&lt;br /&gt;
&lt;br /&gt;
select sql_text_wo_constants, count(*)&lt;br /&gt;
  from t1&lt;br /&gt;
 group by sql_text_wo_constants&lt;br /&gt;
having count(*) &amp;gt; 100&lt;br /&gt;
 order by 2&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The output of that last query will show you statements that are identical in the shared &lt;br /&gt;
pool after all numbers and character string constants have been removed.  These &lt;br /&gt;
statements -- and more importantly their counts -- are the potential bottlenecks.  In &lt;br /&gt;
addition to causing the contention, they will be HUGE cpu consumers.  &lt;br /&gt;
&lt;br /&gt;
If you discover your applications do not use bind variables -- you must have this &lt;br /&gt;
corrected.  You&amp;#039;ll never have a good hit ratio if everyone submits &amp;quot;unique&amp;quot; sql.  Your &lt;br /&gt;
shared pool will never be used right and you&amp;#039;ll be using excessive CPU (90% of the time &lt;br /&gt;
it takes to process &amp;quot;insert into t values ( 1 )&amp;quot; is parsing.  If you use &amp;quot;insert into t &lt;br /&gt;
values ( :x )&amp;quot;, and bind the value of 1 -- then the next person that runs that insert &lt;br /&gt;
will benefit from your work and run that much faster. &lt;br /&gt;
...&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Advice from Oracle concerning a concrete (12c) example of unable to allocate 52824 bytes of shared memory (&amp;quot;shared pool&amp;quot;,...====&lt;br /&gt;
This was from a ticket raised for a Data Pump export that consistently failed with:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Processing object type SCHEMA_EXPORT/TABLE/PROCACT_INSTANCE&lt;br /&gt;
Processing object type SCHEMA_EXPORT/TABLE/TABLE&lt;br /&gt;
ORA-39014: One or more workers have prematurely exited.&lt;br /&gt;
ORA-39029: worker 1 with process name &amp;quot;DW00&amp;quot; prematurely terminated&lt;br /&gt;
ORA-31671: Worker process DW00 had an unhandled exception.&lt;br /&gt;
ORA-04031: unable to allocate 52824 bytes of shared memory (&amp;quot;shared pool&amp;quot;,&amp;quot;unknown object&amp;quot;,&amp;quot;KTSL subheap&amp;quot;,&amp;quot;ktsl_load_disp-2&amp;quot;)&lt;br /&gt;
ORA-06512: at &amp;quot;SYS.KUPW$WORKER&amp;quot;, line 2122&lt;br /&gt;
ORA-06512: at line 2&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
The error ORA-4031 on the shared pool can indicate one of two things:&lt;br /&gt;
- insufficient space for the shared pool (so insufficient memory in SGA at that time)&lt;br /&gt;
OR&lt;br /&gt;
- although there is enough memory, it is fragmented and no contiguous chunk can be allocated to satisfy the latest memory request.&lt;br /&gt;
&lt;br /&gt;
Each SGA has a little fragmentation of course because of the operations taking place, so in your case the fragmentation is represented by the 18M of free memory, which exists in uncontiguous chunks.&lt;br /&gt;
This means that the root cause of the error is insufficient contiguous memory to allocate 12312 bytes of shared memory.&lt;br /&gt;
&lt;br /&gt;
ACTION PLAN&lt;br /&gt;
==============&lt;br /&gt;
1. We see memory_target=2000M. This is too little to support a 12c database, even when it has little activity.&lt;br /&gt;
As you may know 1.7G for the SGA was acceptable when speaking of 32bit OSs where it was hardly possible to make use of more than that.&lt;br /&gt;
Since you have a 64 bit system, the addressable memory is virtually unlimited.&lt;br /&gt;
Furthermore, by using AMM (memory_target&amp;gt;0) this memory is divided between the SGA and the PGA (the user processes) which in fact, depending on the number of connections, can limit the SGA even more.&lt;br /&gt;
So the first recommendation is to increase the value of memory_target to 4G for example. There is no ideal value, but this would be a reasonable starting value for tuning.&lt;br /&gt;
&lt;br /&gt;
You can do further tuning of the memory using the view V$MEMORY_TARGET_ADVICE.&lt;br /&gt;
The view V$MEMORY_TARGET_ADVICE provides tuning advice for the MEMORY_TARGET initialization parameter:&lt;br /&gt;
SQL&amp;gt; SELECT * FROM v$memory_target_advice ORDER BY memory_size;&lt;br /&gt;
&lt;br /&gt;
The dynamic performance view V$MEMORY_DYNAMIC_COMPONENTS shows the current sizes of all dynamically tuned memory components, including the total sizes of the SGA and instance PGA.&lt;br /&gt;
&lt;br /&gt;
You can also use V$MEMORY_RESIZE_OPS which has a circular history buffer of the last 800 memory resize requests.&lt;br /&gt;
&lt;br /&gt;
2. Since the AMM (you have memory_target&amp;gt;0) is used, then make sure to set:&lt;br /&gt;
 _shared_pool_reserved_pct to 10 or 15 to ensure that when the Shared Pool grows or shrinks automatically, the Reserved Area will change as well.&lt;br /&gt;
&lt;br /&gt;
SQL&amp;gt; alter system set &amp;quot;_shared_pool_reserved_pct&amp;quot;=15 scope=spfile;&lt;br /&gt;
--restart the instance&lt;br /&gt;
&lt;br /&gt;
FYI: By default, Oracle configures a small Reserved Pool (or Reserved Area) inside the Shared Pool.&lt;br /&gt;
This memory can be used for operations such as PL/SQL and trigger compilation or for temporary space while loading Java objects.&lt;br /&gt;
After the memory allocated from the Reserved Pool is freed, it returns to the Reserved Pool.&lt;br /&gt;
5% of the Shared Pool is set aside as the Reserved Pool to handle allocations of memory higher than defined by the hidden parameter _shared_pool_reserved_pct.&lt;br /&gt;
In some application environments, 5% is too small.&lt;br /&gt;
&lt;br /&gt;
3. Set shared_pool_size=500M or even more. This will represent a minimum amount of memory that will always be available to the shared pool.&lt;br /&gt;
If more memory is needed at any moment, if it is available, it will be allocated to the shared pool over the 500M.&lt;br /&gt;
&lt;br /&gt;
Implement the above steps, monitor the database and let us know the result,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORA-00392: log 1 of thread 1 is being cleared, operation not allowed===&lt;br /&gt;
After performing an active duplication, this happened when trying to open the database.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SQL&amp;gt; alter database open resetlogs&lt;br /&gt;
alter database open resetlogs&lt;br /&gt;
*&lt;br /&gt;
ERROR at line 1:&lt;br /&gt;
ORA-00392: log 1 of thread 1 is being cleared, operation not allowed&lt;br /&gt;
ORA-00312: online log 1 thread 1: &amp;#039;/oracle/oradata/testdb/redo/redo01.log&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SQL&amp;gt; select group#,thread#,status from v$log;&lt;br /&gt;
 &lt;br /&gt;
GROUP#   THREAD#   STATUS&lt;br /&gt;
-------  --------- ----------------&lt;br /&gt;
1        1         CLEARING_CURRENT&lt;br /&gt;
2        1         STALE&lt;br /&gt;
3        1         STALE&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Check the alert log! Always a good idea to get extra info. In here we find the answer&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ORA-00344: unable to re-create online log&lt;br /&gt;
&amp;#039;/oracle/oradata/testdb/redo/redo01.log&amp;#039;&lt;br /&gt;
ORA-27040: file create error, unable to create file&lt;br /&gt;
Linux-x86_64 Error: 2: No such file or directory&lt;br /&gt;
Additional information: 1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
So the clue is that the file cannot be created at the operating system level.&amp;lt;br /&amp;gt;&lt;br /&gt;
Doing a &amp;lt;code&amp;gt;df -k /oracle/oradata/testdb/redo&amp;lt;/code&amp;gt; shows us that the filesystem was created too small for the destination database.&amp;lt;br /&amp;gt;&lt;br /&gt;
In this case, we do not want the redolog directory to be as big as on the source db as there will be almost no movement on the destination.&amp;lt;br /&amp;gt;&lt;br /&gt;
I should have specified the LOGFILE parameter in the DUPLICATE clause to setup new, smaller redolog files.&amp;lt;br /&amp;gt;&lt;br /&gt;
As this duplicate takes over 12 hours, I didn&amp;#039;t want to do it again so I created symbolic links in the redolog directory pointing out to a larger filesystem with more space.&amp;lt;br /&amp;gt;&lt;br /&gt;
This allowed the creation of the redolog files. They can then be resized once the database has been opened.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cd /oracle/oradata/testdb/redo&lt;br /&gt;
ln -s /tmp/redo01.log redo01.log&lt;br /&gt;
ln -s /tmp/redo02.log redo02.log&lt;br /&gt;
ln -s /tmp/redo03.log redo03.log&lt;br /&gt;
&lt;br /&gt;
SQL&amp;gt; alter database open resetlogs&lt;br /&gt;
Database opened.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===RMAN-04004: error from recovery catalog database: ORA-01017: invalid username/password; logon denied===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
oracle@host:/export/home/ora&amp;gt; rman target / catalog catowner/catpass@catdb&lt;br /&gt;
&lt;br /&gt;
Recovery Manager: Release 11.2.0.2.0 - Production on Thu Jun 12 16:51:03 2014&lt;br /&gt;
&lt;br /&gt;
Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.&lt;br /&gt;
&lt;br /&gt;
connected to target database: XXXXRAP1 (DBID=3557010742)&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-00554: initialization of internal recovery manager package failed&lt;br /&gt;
RMAN-04004: error from recovery catalog database: ORA-01017: invalid username/password; logon denied&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This is normally very straight-forward and self-explanatory.&amp;lt;br /&amp;gt;&lt;br /&gt;
The puzzle here is that a connection from SQL*Plus works!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sqlplus catowner/catpass@catdb&lt;br /&gt;
&lt;br /&gt;
SQL*Plus: Release 11.2.0.2.0 Production on Thu Jun 12 16:53:18 2014&lt;br /&gt;
&lt;br /&gt;
Copyright (c) 1982, 2010, Oracle.  All rights reserved.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Connected to:&lt;br /&gt;
Oracle Database 12c Enterprise Edition Release 12.1.0.1.0 - 64bit Production&lt;br /&gt;
With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options&lt;br /&gt;
SQL&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Eventually worked out that the rman binary in the databases ORACLE_HOME on the source machine needed relinking!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cd $ORACLE_HOME/rdbms/lib&lt;br /&gt;
make -f ins_rdbms.mk irman &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORA-00230: operation disallowed: snapshot control file enqueue unavailable===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
waiting for snapshot control file enqueue&lt;br /&gt;
waiting for snapshot control file enqueue&lt;br /&gt;
waiting for snapshot control file enqueue&lt;br /&gt;
waiting for snapshot control file enqueue&lt;br /&gt;
cannot make a snapshot control file&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-03008: error while performing automatic resync of recovery catalog&lt;br /&gt;
ORA-00230: operation disallowed: snapshot control file enqueue unavailable&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
From the doc...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
When RMAN needs to back up or resynchronize from the control file, it first creates a snapshot or consistent image of the control file.&lt;br /&gt;
If one RMAN job is already backing up the control file while another needs to create a new snapshot control file, then you may see the following message:&lt;br /&gt;
&lt;br /&gt;
waiting for snapshot controlfile enqueue&lt;br /&gt;
&lt;br /&gt;
Under normal circumstances, a job that must wait for the control file enqueue waits for a brief interval and then successfully obtains the enqueue.&lt;br /&gt;
RMAN makes up to five attempts to get the enqueue and then fails the job.&lt;br /&gt;
The conflict is usually caused when two jobs are both backing up the control file, and the job that first starts backing up the control file waits for service from the media manager.&lt;br /&gt;
&lt;br /&gt;
To determine which job is holding the conflicting enqueue:&lt;br /&gt;
&lt;br /&gt;
    After you see the first message stating &amp;quot;RMAN-08512: waiting for snapshot controlfile enqueue&amp;quot;, start a new SQL*Plus session on the target database:&lt;br /&gt;
&lt;br /&gt;
    % sqlplus &amp;#039;SYS/oracle@trgt AS SYSDBA&amp;#039;&lt;br /&gt;
&lt;br /&gt;
    Execute the following query to determine which job is causing the wait:&lt;br /&gt;
&lt;br /&gt;
    SELECT s.SID, USERNAME AS &amp;quot;User&amp;quot;, PROGRAM, MODULE, &lt;br /&gt;
           ACTION, LOGON_TIME &amp;quot;Logon&amp;quot;, l.* &lt;br /&gt;
    FROM V$SESSION s, V$ENQUEUE_LOCK l&lt;br /&gt;
    WHERE l.SID = s.SID&lt;br /&gt;
    AND l.TYPE = &amp;#039;CF&amp;#039;&lt;br /&gt;
    AND l.ID1 = 0&lt;br /&gt;
    AND l.ID2 = 2;&lt;br /&gt;
&lt;br /&gt;
    You should see output similar to the following (the output in this example has been truncated):&lt;br /&gt;
&lt;br /&gt;
    SID User Program              Module                    Action           Logon&lt;br /&gt;
    --- ---- -------------------- ------------------------- ---------------- ---------&lt;br /&gt;
      9 SYS  rman@h13 (TNS V1-V3) backup full datafile: c1  0000210 STARTED  21-JUN-01&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
After you have determined which job is creating the enqueue, you can do one of the following:&lt;br /&gt;
&lt;br /&gt;
    Wait until the job creating the enqueue completes&lt;br /&gt;
    Cancel the current job and restart it after the job creating the enqueue completes&lt;br /&gt;
    Cancel the job creating the enqueue&lt;br /&gt;
&lt;br /&gt;
Commonly, enqueue situations occur when a job is writing to a tape drive, but the tape drive is waiting for a new cassette to be inserted.&lt;br /&gt;
If you start a new job in this situation, then you will probably receive the enqueue message because the first job cannot complete until the new tape is loaded.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or more directly...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 2000&lt;br /&gt;
col killer     for a70&lt;br /&gt;
col program    for a20&lt;br /&gt;
col module     for a20&lt;br /&gt;
col action     for a20&lt;br /&gt;
col logon_time for a20&lt;br /&gt;
select &amp;#039;alter system disconnect session &amp;#039;&amp;#039;&amp;#039;||s.sid||&amp;#039;,&amp;#039;||s.serial#||&amp;#039;&amp;#039;&amp;#039; immediate;&amp;#039; killer&lt;br /&gt;
,      username&lt;br /&gt;
,      program&lt;br /&gt;
,      module&lt;br /&gt;
,      action&lt;br /&gt;
,      logon_time&lt;br /&gt;
from   v$session s&lt;br /&gt;
,      v$enqueue_lock l&lt;br /&gt;
where  l.sid  = s.sid&lt;br /&gt;
and    l.type = &amp;#039;cf&amp;#039;&lt;br /&gt;
and    l.id1  = 0&lt;br /&gt;
and    l.id2  = 2&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORA-19511: non RMAN, but media manager or vendor specific failure, error text:===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-03002: failure of Duplicate Db command at 05/01/2018 14:23:09&lt;br /&gt;
RMAN-05501: aborting duplication of target database&lt;br /&gt;
RMAN-03015: error occurred in stored script Memory Script&lt;br /&gt;
ORA-27191: sbtinfo2 returned error&lt;br /&gt;
Additional information: 3586&lt;br /&gt;
ORA-19511: non RMAN, but media manager or vendor specific failure, error text:&lt;br /&gt;
   Unable to connect to NetWorker server &amp;#039;hn6000.cln.be&amp;#039; because &amp;#039;Authentication error; why = Invalid client credential&amp;#039;. (2:10:79)&lt;br /&gt;
&lt;br /&gt;
Recovery Manager complete.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
If this happens, check to see if the nsr daemon is running...&amp;lt;br /&amp;gt;&lt;br /&gt;
Good system:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/home/oracle&amp;gt; ps -ef | grep nsr&lt;br /&gt;
    root  5701836        1   0   Mar 16      - 13:18 /bin/nsrexecd&lt;br /&gt;
  oracle 18809292 22741502   0 15:03:58  pts/0  0:00 grep nsr&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Bad system:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 /home/oracle&amp;gt; ps -ef | grep nsr&lt;br /&gt;
  oracle 14745986 15139292   0 15:03:29  pts/2  0:00 grep nsr&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORA-19554: error allocating device, device type: SBT_TAPE, device name:===&lt;br /&gt;
If using Cygwin...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-03002: failure of backup command at 05/19/2015 12:25:47&lt;br /&gt;
ORA-19554: error allocating device, device type: SBT_TAPE, device name:&lt;br /&gt;
ORA-27000: skgfqsbi: failed to initialize storage subsystem (SBT) layer&lt;br /&gt;
OSD-02534: Message 2534 not found;  product=RDBMS; facility=SOSD&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Check the tdpo.opt file is where you think it is!&lt;br /&gt;
* Check the path to the opt file looks like this (needs to be Windows format):&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
CONFIGURE CHANNEL DEVICE TYPE &amp;#039;SBT_TAPE&amp;#039; FORMAT   &amp;#039;LOG_%d_t%t_s%s_u%U&amp;#039; PARMS  &amp;#039;ENV=(TDPO_OPTFILE=E:\oracle\KITRYD\admin\tdpo.opt)&amp;#039;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Check the content of the opt file is Windows format paths!&lt;br /&gt;
&lt;br /&gt;
===RMAN-20033: control file SEQUENCE# too low===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-03008: error while performing automatic resync of recovery catalog&lt;br /&gt;
===RMAN-20033: control file SEQUENCE# too low===&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
From [https://forums.oracle.com/forums/thread.jspa?threadID=1115969 forums.oracle.com]&amp;lt;br /&amp;gt;&lt;br /&gt;
This error generally happens if an archivelog backup happens while the RMAN database backup is running and if controlfile autobackup is configured.&amp;lt;br /&amp;gt;&lt;br /&gt;
The database backup is usually successful and it is just the controlfile backup that fails.&lt;br /&gt;
===ORA-27302: failure occurred at: slgpn===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
RMAN-03009: failure of Control File and SPFILE Autobackup command on c1 channel at 06/28/2011 18:59:38&lt;br /&gt;
ORA-19715: invalid format %b for generated name&lt;br /&gt;
ORA-27302: failure occurred at: slgpn&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Problem====&lt;br /&gt;
When doing a &amp;quot;&amp;lt;tt&amp;gt;backup as copy database&amp;lt;/tt&amp;gt;&amp;quot;, got these errors after 145 of 147 datafiles had been backed up!&lt;br /&gt;
&lt;br /&gt;
====Investigation====&lt;br /&gt;
I had read [https://oracleedge.wordpress.com/2011/06/29/oracle-rman-03009-ora-19715-ora-27302/ elsewhere] that this could be something to do with the format of the autobackup of the control file so I changed the format as suggested and reran the backup.&amp;lt;br /&amp;gt;&lt;br /&gt;
No luck. It ended exactly the same way after 145 files. I decided to compare the original list of datafiles with those that had been backed up in order to track down the 2 failures. Maybe I could see something odd with them.&amp;lt;br /&amp;gt;&lt;br /&gt;
Sure enough, these 2 files were different... there was a space at the &amp;#039;&amp;#039;&amp;#039;end&amp;#039;&amp;#039;&amp;#039; of the filenames :-)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select &amp;#039;x&amp;#039;||file_name||&amp;#039;x&amp;#039;&lt;br /&gt;
from   dba_data_files&lt;br /&gt;
where  file_name like &amp;#039;% %&amp;#039;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Solution====&lt;br /&gt;
Run the backup of the other 2 datafiles with a different format that did not rely on the filename.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
run {&lt;br /&gt;
    allocate channel c1 device type disk format &amp;#039;/path/to/datafiles/%U&amp;#039;;&lt;br /&gt;
    backup as copy datafile 170;&lt;br /&gt;
    backup as copy datafile 171;&lt;br /&gt;
    backup as copy current controlfile;&lt;br /&gt;
    release channel c1;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The other 145 datafiles were backed up with a format of &amp;#039;/path/to/datafiles/%b&amp;#039; which preserves the filenames so all that needs to be done is rename the other 2 after the backup finishes.&amp;lt;br /&amp;gt;&lt;br /&gt;
If they are going to be used in a restore scenario, they should be renamed in the controlfile also.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter database rename file &amp;#039;/path/to/datafiles/filename_with_a_space_at_end &amp;#039; to &amp;#039;/path/to/datafiles/filename_without_a_space&amp;#039;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===RMAN errors after crosscheck backup and delete noprompt obsolete and delete noprompt expired backup===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
RMAN-06207: WARNING: 3921 objects could not be deleted for SBT_TAPE channel(s) due&lt;br /&gt;
RMAN-06208:          to mismatched status.  Use CROSSCHECK command to fix status&lt;br /&gt;
RMAN-06210: List of Mismatched objects&lt;br /&gt;
RMAN-06211: ==========================&lt;br /&gt;
RMAN-06212:   Object Type   Filename/Handle&lt;br /&gt;
RMAN-06213: --------------- ---------------------------------------------------&lt;br /&gt;
RMAN-06214: Backup Piece    DB_SID_t20140316_s263889_umhp3bpa7_1_1&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Use the FORCE option with the DELETE command&amp;lt;br /&amp;gt;&lt;br /&gt;
The FORCE command tells RMAN to clean the information out of the catalog regardless of whether it can find it on the media or not.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
delete force noprompt expired backup;&lt;br /&gt;
delete force noprompt obsolete;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===RMAN-06004: ORACLE error from recovery catalog database: RMAN-20003: target database incarnation not found in recovery catalog===&lt;br /&gt;
====Problem:====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-03002: failure of Duplicate Db command at 12/05/2017 11:11:15&lt;br /&gt;
RMAN-05501: aborting duplication of target database&lt;br /&gt;
RMAN-03015: error occurred in stored script Memory Script&lt;br /&gt;
RMAN-06004: ORACLE error from recovery catalog database: RMAN-20003: target database incarnation not found in recovery catalog&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Solution:====&lt;br /&gt;
Strangely, this means, in my particular case, that block change tracking is turned on in the target databse and needs turning off in the auxiliary while the DUPLICATE is running.&amp;lt;br /&amp;gt;&lt;br /&gt;
It must be done while the auxiliary is in mount mode and restoring the datafiles (before recovery starts)&amp;lt;br /&amp;gt;&lt;br /&gt;
It is reported to be a bug fixed in 11.1 but somehow, we&amp;#039;re still (sometimes) getting it in 12.1.0.2.&lt;br /&gt;
&lt;br /&gt;
===RMAN-06059: expected archived log not found, loss of archived log compromises recoverability===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
RMAN-06059: expected archived log not found, loss of archived log compromises recoverability&lt;br /&gt;
ORA-19625: error identifying file &amp;lt;filename&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This error can come from the fact that the database files (more likely archivelogs) are being deleted by the operating system so RMAN has no clue of their whereabouts.&amp;lt;br /&amp;gt;&lt;br /&gt;
Possibly result of a database duplication and the catalog has not updated properly?&amp;lt;br /&amp;gt;&lt;br /&gt;
====Solution====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
crosscheck archivelog all;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
And then maybe take a backup to be on the safe side.&lt;br /&gt;
&lt;br /&gt;
===RMAN-05537: DUPLICATE without TARGET connection when auxiliary instance is started with spfile cannot use SPFILE clause===&lt;br /&gt;
====Problem:====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-03002: failure of Duplicate Db command at 12/05/2017 14:17:49&lt;br /&gt;
RMAN-05501: aborting duplication of target database&lt;br /&gt;
RMAN-05537: DUPLICATE without TARGET connection when auxiliary instance is started with spfile cannot use SPFILE clause&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Usually happens after restarting a failed RMAN DUPLICATE database. The spfile has been regenerated on the auxiliary to a level where it has too much detail in it.&lt;br /&gt;
====Solution:====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ cd $ORACLE_HOME/dbs&lt;br /&gt;
$ ls -altr *dwh_perf*&lt;br /&gt;
-rw-r-----    1 oracle   oinstall   17645568 Aug  3 13:34 snapcf_dwh_perf.f&lt;br /&gt;
-rw-r-----    1 oracle   oinstall       7680 Nov  4 09:22 orapwdwh_perf&lt;br /&gt;
-rw-r--r--    1 oracle   oinstall        104 Dec  5 09:34 initdwh_perf.ora&lt;br /&gt;
-rw-r-----    1 oracle   oinstall       6656 Dec  5 11:11 spfiledwh_perf.ora&lt;br /&gt;
-rw-rw----    1 oracle   oinstall       1544 Dec  5 14:18 hc_dwh_perf.dat&lt;br /&gt;
$ mv hc_dwh_perf.dat hc_dwh_perf.dat.old&lt;br /&gt;
$ mv spfiledwh_perf.ora spfiledwh_perf.ora.old&lt;br /&gt;
$ cat initdwh_perf.ora&lt;br /&gt;
sga_max_size=&amp;#039;6G&amp;#039;&lt;br /&gt;
sga_target=&amp;#039;6G&amp;#039;&lt;br /&gt;
compatible=&amp;#039;12.0.0&amp;#039;&lt;br /&gt;
db_files=&amp;#039;500&amp;#039;&lt;br /&gt;
&lt;br /&gt;
# Instance name&lt;br /&gt;
db_name=dwh_perf&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Re-run the DUPLICATE. It should zoom past the already recovered datafiles.&lt;br /&gt;
&lt;br /&gt;
===PSDRPC returns significant error 1013===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
archived log thread=1 sequence=195008&lt;br /&gt;
channel t2: reading from backup piece arclog_LBK_4260753020_946042770_479194_1&lt;br /&gt;
channel t0: piece handle=arclog_LBK_4260753020_946042770_479192_1 tag=TAG20170607T133757&lt;br /&gt;
channel t0: restored backup piece 1&lt;br /&gt;
channel t0: restore complete, elapsed time: 00:00:35&lt;br /&gt;
archived log file name=/xxxxxx/acc/ora_bin2/app/oracle/product/11.2.0.4/dbhome_1/dbs/arch1_195006_815790039.dbf thread=1 sequence=195006&lt;br /&gt;
PSDRPC returns significant error 1013.&lt;br /&gt;
PSDRPC returns significant error 1013.&lt;br /&gt;
released channel: t0&lt;br /&gt;
released channel: t1&lt;br /&gt;
released channel: t2&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-03002: failure of Duplicate Db command at 06/09/2017 15:15:04&lt;br /&gt;
RMAN-05501: aborting duplication of target database&lt;br /&gt;
RMAN-03015: error occurred in stored script Memory Script&lt;br /&gt;
RMAN-11003: failure during parse/execution of SQL statement: alter database recover logfile &amp;#039;/xxxxxx/acc/ora_bin2/app/oracle/product/11.2.0.4/dbhome_1/dbs/arch1_195006_815790039.dbf&amp;#039;&lt;br /&gt;
ORA-10877: error signaled in parallel recovery slave&lt;br /&gt;
&lt;br /&gt;
Recovery Manager complete.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Action====&lt;br /&gt;
Check the alert log on the auxiliary instance.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ORA-279 signalled during: alter database recover logfile &amp;#039;/xxxxxx/acc/ora_bin2/app/oracle/product/11.2.0.4/dbhome_1/dbs/arch1_195005_815790039.dbf&amp;#039;...&lt;br /&gt;
alter database recover logfile &amp;#039;/xxxxxx/acc/ora_bin2/app/oracle/product/11.2.0.4/dbhome_1/dbs/arch1_195006_815790039.dbf&amp;#039;&lt;br /&gt;
Media Recovery Log /xxxxxx/acc/ora_bin2/app/oracle/product/11.2.0.4/dbhome_1/dbs/arch1_195006_815790039.dbf&lt;br /&gt;
Fri Jun 09 07:30:30 2017&lt;br /&gt;
Errors with log /xxxxxx/acc/ora_bin2/app/oracle/product/11.2.0.4/dbhome_1/dbs/arch1_195006_815790039.dbf&lt;br /&gt;
Recovery interrupted!&lt;br /&gt;
Recovered data files to a consistent state at change 238029030495&lt;br /&gt;
Media Recovery failed with error 19755&lt;br /&gt;
Errors in file /xxxxxx/acc/ora_bin2/app/oracle/diag/rdbms/lbkro/lbkro/trace/lbkro_pr00_13108374.trc:&lt;br /&gt;
ORA-00283: recovery session canceled due to errors&lt;br /&gt;
===&amp;gt;ORA-19755: could not open change tracking file&lt;br /&gt;
===&amp;gt;ORA-19750: change tracking file: &amp;#039;/xxxxxx/exp/ora_data2/lbk/data/bct_lbk_do_not_delete.f&lt;br /&gt;
===&amp;gt;ORA-27037: unable to obtain file status&lt;br /&gt;
===&amp;gt;IBM AIX RISC System/6000 Error: 2: No such file or directory&lt;br /&gt;
Additional information: 3&lt;br /&gt;
Fri Jun 09 07:30:36 2017&lt;br /&gt;
ORA-10877 signalled during: alter database recover logfile &amp;#039;/xxxxxx/acc/ora_bin2/app/oracle/product/11.2.0.4/dbhome_1/dbs/arch1_195006_815790039.dbf&amp;#039;...&lt;br /&gt;
Fri Jun 09 14:04:57 2017&lt;br /&gt;
alter database recover logfile &amp;#039;/xxxxxx/acc/ora_bin2/app/oracle/product/11.2.0.4/dbhome_1/dbs/arch1_195006_815790039.dbf&amp;#039;&lt;br /&gt;
Media Recovery Log /xxxxxx/acc/ora_bin2/app/oracle/product/11.2.0.4/dbhome_1/dbs/arch1_195006_815790039.dbf&lt;br /&gt;
Media Recovery failed with error 1112&lt;br /&gt;
ORA-283 signalled during: alter database recover logfile &amp;#039;/xxxxxx/acc/ora_bin2/app/oracle/product/11.2.0.4/dbhome_1/dbs/arch1_195006_815790039.dbf&amp;#039;...&lt;br /&gt;
Fri Jun 09 14:31:20 2017&lt;br /&gt;
Shutting down instance (immediate)&lt;br /&gt;
Shutting down instance: further logons disabled&lt;br /&gt;
Stopping background process MMNL&lt;br /&gt;
Stopping background process MMON&lt;br /&gt;
License high water mark = 49&lt;br /&gt;
ALTER DATABASE CLOSE NORMAL&lt;br /&gt;
ORA-1109 signalled during: ALTER DATABASE CLOSE NORMAL...&lt;br /&gt;
ALTER DATABASE DISMOUNT&lt;br /&gt;
Shutting down archive processes&lt;br /&gt;
Archiving is disabled&lt;br /&gt;
Completed: ALTER DATABASE DISMOUNT&lt;br /&gt;
ARCH: Archival disabled due to shutdown: 1089&lt;br /&gt;
Shutting down archive processes&lt;br /&gt;
Archiving is disabled&lt;br /&gt;
ARCH: Archival disabled due to shutdown: 1089&lt;br /&gt;
Shutting down archive processes&lt;br /&gt;
Archiving is disabled&lt;br /&gt;
Fri Jun 09 14:31:24 2017&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This is a known bug. it is fixed in 11.2.0.3 but... this customer does not apply patches!&lt;br /&gt;
&lt;br /&gt;
====Solution====&lt;br /&gt;
While the DUPLICATE is running (and in MOUNT mode), log on to the auxiliary instance and disable block change tracking.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter database disable block change tracking;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
A documented workaround is to set db_filename_convert parameter in the DUPLICATE clause of the run block but I tried this and it failed again.&amp;lt;br /&amp;gt;&lt;br /&gt;
The obvious solution is to patch the database but...&lt;br /&gt;
&lt;br /&gt;
===Database trigger to capture ORA errors===&lt;br /&gt;
From [http://ora-ssn.blogspot.be/2011/10/trigger-on-database-to-capture-ora.html ora-ssn.blogspot.be]&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
CREATE TABLE stats$error_log (&lt;br /&gt;
        err_dt          TIMESTAMP,&lt;br /&gt;
        db_user         VARCHAR2(30),&lt;br /&gt;
        msg_stack       VARCHAR2(2000),&lt;br /&gt;
        sqltxt          VARCHAR2(1000))&lt;br /&gt;
tablespace users;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Now, create a trigger on the database server.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
CREATE OR REPLACE TRIGGER log_server_errors&lt;br /&gt;
  AFTER SERVERERROR&lt;br /&gt;
  ON DATABASE&lt;br /&gt;
DECLARE&lt;br /&gt;
          v_sqltext VARCHAR2(1000);&lt;br /&gt;
          nl_sqltext ora_name_list_t;&lt;br /&gt;
  BEGIN&lt;br /&gt;
          -- Capture entire error text&lt;br /&gt;
          FOR i IN 1 .. ora_sql_txt(nl_sqltext) LOOP&lt;br /&gt;
            v_sqltext := v_sqltext || nl_sqltext(i);&lt;br /&gt;
          END LOOP;&lt;br /&gt;
          INSERT INTO STATS$ERROR_LOG&lt;br /&gt;
          (err_dt, db_user, msg_stack, sqltxt)&lt;br /&gt;
          VALUES&lt;br /&gt;
          (systimestamp,&lt;br /&gt;
           sys.login_user,&lt;br /&gt;
           dbms_utility.format_error_stack, v_sqltext);&lt;br /&gt;
  END log_server_errors;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORA-19809: limit exceeded for recovery files===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-03009: failure of backup command on ORA_DISK_1 channel at 07/15/2013 10:10:59&lt;br /&gt;
ORA-19809: limit exceeded for recovery files&lt;br /&gt;
ORA-19804: cannot reclaim 274716160 bytes disk space from 1468006400 limit&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    ORA-19809: limit exceeded for recovery files&lt;br /&gt;
    Cause: The limit for recovery files specified by the db_recovery_file_dest_size was exceeded.&lt;br /&gt;
&lt;br /&gt;
    Action: The error is accompanied by 19804. See message 19804 for further details&lt;br /&gt;
&lt;br /&gt;
    ORA-19804: cannot reclaim string bytes disk space from string limit&lt;br /&gt;
    Cause: Oracle cannot reclaim disk space of specified bytes from the DB_RECOVERY_FILE_DEST_SIZE limit.&lt;br /&gt;
&lt;br /&gt;
    Action: There are five possible solutions:&lt;br /&gt;
       1) Take frequent backup of recovery area using RMAN.&lt;br /&gt;
       2) Consider changing RMAN retention policy.&lt;br /&gt;
       3) Consider changing RMAN archivelog deletion policy.&lt;br /&gt;
       4) Add disk space and increase DB_RECOVERY_FILE_DEST_SIZE.&lt;br /&gt;
       5) Delete files from recovery area using RMAN.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The solution here is to increase the value of db_recovery_file_dest_size but it might also indicate a problem with tapes if the archivelogs are being backed up to tape via tdpo.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SYS@DN7&amp;gt; alter system set db_recovery_file_dest_size=4000M scope=both;&lt;br /&gt;
&lt;br /&gt;
System altered.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Looking into int further, saw RMAN parameters missing...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
CONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF 14 DAYS;&lt;br /&gt;
CONFIGURE BACKUP OPTIMIZATION OFF;&lt;br /&gt;
CONFIGURE DEFAULT DEVICE TYPE TO &amp;#039;SBT_TAPE&amp;#039;;&lt;br /&gt;
CONFIGURE CONTROLFILE AUTOBACKUP ON;&lt;br /&gt;
CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE &amp;#039;SBT_TAPE&amp;#039; TO &amp;#039;LOG_%d_controlfile_%F.rman&amp;#039;;&lt;br /&gt;
CONFIGURE DEVICE TYPE &amp;#039;SBT_TAPE&amp;#039; PARALLELISM 1 BACKUP TYPE TO BACKUPSET;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===RMAN-00554: initialization of internal recovery manager package failed===&lt;br /&gt;
Getting this error after migrating a database from one machine to another and attaching to a nice new version 12c catalog on the new server&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Recovery Manager: Release 11.2.0.2.0 - Production on Sat Jun 21 13:16:24 2014&lt;br /&gt;
&lt;br /&gt;
Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.&lt;br /&gt;
&lt;br /&gt;
connected to target database: SPMSUPP1 (DBID=3026014394)&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-00554: initialization of internal recovery manager package failed&lt;br /&gt;
RMAN-04004: error from recovery catalog database: ORA-01017: invalid username/password; logon denied&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
We cannot connect to the catalog via rman but there is no problem if connecting via SQL*Plus!&amp;lt;br /&amp;gt;&lt;br /&gt;
Solution: relink the rman executable.&lt;br /&gt;
===Using AIX commands genld, genkld and slibclean to avoid library file locking errors (libjox) (Doc ID 739963.1)===&lt;br /&gt;
* [https://support.oracle.com/epmos/faces/DocumentDisplay?_afrLoop=206851390914720&amp;amp;id=739963.1&amp;amp;_afrWindowMode=0&amp;amp;_adf.ctrl-state=e0pq23tou_4 Metalink]&lt;br /&gt;
When installing interim (one-off) patches, CPU patches or patchsets, you may encounter some errors with regards to files being locked or oui/opatch being unable to copy files&amp;lt;br /&amp;gt;&lt;br /&gt;
even though the databases, listeners and all other Oracle processes associated with the ORACLE_HOME to be patched were stopped.&amp;lt;br /&amp;gt;&lt;br /&gt;
This could be as result of a process which requires termination or an additional file needing to be unloaded from the system cache.&amp;lt;br /&amp;gt;&lt;br /&gt;
Run following commands to clean up...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
genld -l | grep &amp;lt;ORACLE_HOME&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
If genld returns data then a currently executing process has something open in the ORACLE_HOME directory, therefore terminate the process as required/recommended.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
genkld | grep &amp;lt;ORACLE_HOME&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
If the genkld command  returns a  list of shared objects currently loaded onto the OS system cache then please remove the entries from the OS system cache by running the slibclean command as root user:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/usr/sbin/slibclean&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===ORA-20011: Approximate NDV failed: ORA-29913: error in executing ODCIEXTTABLEOPEN callout===&lt;br /&gt;
This seems to be related to orphaned Datapump tables. Generally seems to be a problem when stats jobs are running during the night (dbms_stats)&amp;lt;br /&amp;gt;&lt;br /&gt;
* Check no datapump jobs are running&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select * from dba_datapump_jobs;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Find orphaned tables&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 2000&lt;br /&gt;
select owner&lt;br /&gt;
,      object_name&lt;br /&gt;
,      object_type&lt;br /&gt;
,      status&lt;br /&gt;
,      to_char(created,&amp;#039;dd-mon-yyyy hh24:mi:ss&amp;#039;) created&lt;br /&gt;
,      to_char(last_ddl_time,&amp;#039;dd-mon-yyyy hh24:mi:ss&amp;#039;) last_ddl_time&lt;br /&gt;
from   dba_objects&lt;br /&gt;
where  1=1&lt;br /&gt;
and    object_name like &amp;#039;ET$%&amp;#039;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Check that  any rows seen are actually external tables&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select owner&lt;br /&gt;
,      table_name&lt;br /&gt;
,      default_directory_name&lt;br /&gt;
,      access_type&lt;br /&gt;
from   dba_external_tables&lt;br /&gt;
order  by 1,2&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Drop the tables if they are not currently being used (no datapump jobs running)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
drop table &amp;amp;&amp;amp;owner..&amp;amp;table_name;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===ORA-01547: warning: RECOVER succeeded but OPEN RESETLOGS would get error below===&lt;br /&gt;
Database is restored and now we want to recover it but we see this...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Starting recover at 24-JUL-15 11:26:19&lt;br /&gt;
&lt;br /&gt;
starting media recovery&lt;br /&gt;
&lt;br /&gt;
unable to find archive log&lt;br /&gt;
archive log thread=1 sequence=69763&lt;br /&gt;
Oracle Error: &lt;br /&gt;
ORA-01547: warning: RECOVER succeeded but OPEN RESETLOGS would get error below&lt;br /&gt;
ORA-01194: file 1 needs more recovery to be consistent&lt;br /&gt;
ORA-01110: data file 1: &amp;#039;/oracle/TRSCRP1/oradata2/system01.dbf&amp;#039;&lt;br /&gt;
&lt;br /&gt;
released channel: c1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This means that although we have restored the database, we are still missing information to complete the recovery. This information is contained in the archived redo logs which must also be restored (from tape if they are no longer on disk)&amp;lt;br /&amp;gt;&lt;br /&gt;
We can see here that we need an archive log with sequence number 69763. But what is the file called and where should it be restored to?&amp;lt;br /&amp;gt;&lt;br /&gt;
For this we can go to SQL*Plus and get the database to tell us&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
recover database using backup controlfile until cancel;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
and cancel straight away.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ORA-00279: change 13796376414661 generated at 07/14/2015 13:20:07 needed for&lt;br /&gt;
thread 1&lt;br /&gt;
ORA-00289: suggestion : /oracle/TRSCRP1/archive/arch_TRSCRP1_1_69763.arc&lt;br /&gt;
ORA-00280: change 13796376414661 for thread 1 is in sequence #69763&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Specify log: {&amp;lt;RET&amp;gt;=suggested | filename | AUTO | CANCEL}&lt;br /&gt;
cancel&lt;br /&gt;
ORA-01547: warning: RECOVER succeeded but OPEN RESETLOGS would get error below&lt;br /&gt;
ORA-01194: file 1 needs more recovery to be consistent&lt;br /&gt;
ORA-01110: data file 1: &amp;#039;/oracle/TRSCRP1/oradata2/system01.dbf&amp;#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
ORA-01112: media recovery not started&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Now we see that we need to find a file called arch_TRSCRP1_1_69763.arc and put it in the directory /oracle/TRSCRP1/archive.&amp;lt;br /&amp;gt;&lt;br /&gt;
This will continue up until the time specified for the recover so restore a whole bunch of them.&amp;lt;br /&amp;gt;&lt;br /&gt;
Repeat the &amp;quot;recover database using backup controlfile until cancel;&amp;quot; command and type AUTO or Enter until you&amp;#039;ve got to where you need to be.&amp;lt;br /&amp;gt;&lt;br /&gt;
Type CANCEL when point is reached and&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter database open resetlogs;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Stuart</name></author>	</entry>

	<entry>
		<id>https://mailnest.com/dbawiki/index.php?title=Oracle_errors&amp;diff=3362</id>
		<title>Oracle errors</title>
		<link rel="alternate" type="text/html" href="https://mailnest.com/dbawiki/index.php?title=Oracle_errors&amp;diff=3362"/>
				<updated>2018-11-03T16:56:29Z</updated>
		
		<summary type="html">&lt;p&gt;Stuart: /* Use exchange partition to alter metadata of the tablespaces without moving the actual data */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;===ORA-00600===&lt;br /&gt;
[https://support.oracle.com/epmos/faces/DocContentDisplay?_afrLoop=397490397952859&amp;amp;id=1092832.1&amp;amp;_afrWindowMode=0&amp;amp;_adf.ctrl-state=184vwc6g3y_4 Master Note for Diagnosing ORA-600 (Doc ID 1092832.1)]&lt;br /&gt;
===ORA-19051: Cannot use fast path insert for this XMLType table===&lt;br /&gt;
Think LD_LIBRARY_PATH on Linux or LIBPATH on AIX.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Export: Release 11.2.0.4.0 - Production on Thu Jun 1 06:41:55 2017&lt;br /&gt;
&lt;br /&gt;
Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.&lt;br /&gt;
&lt;br /&gt;
Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production&lt;br /&gt;
With the Partitioning, OLAP, Data Mining and Real Application Testing options&lt;br /&gt;
Starting &amp;quot;DWH_EXPORT&amp;quot;.&amp;quot;SYS_EXPORT_TABLE_03&amp;quot;:  dwh_export/******** parfile=cadis_foto_export_credit_dba.par&lt;br /&gt;
Estimate in progress using BLOCKS method...&lt;br /&gt;
Processing object type TABLE_EXPORT/TABLE/TABLE_DATA&lt;br /&gt;
Total estimation using BLOCKS method: 64.08 GB&lt;br /&gt;
ORA-39126: Worker unexpected fatal error in KUPW$WORKER.FETCH_XML_OBJECTS []&lt;br /&gt;
ORA-19051: Cannot use fast path insert for this XMLType table&lt;br /&gt;
&lt;br /&gt;
ORA-06512: at &amp;quot;SYS.DBMS_SYS_ERROR&amp;quot;, line 86&lt;br /&gt;
ORA-06512: at &amp;quot;SYS.KUPW$WORKER&amp;quot;, line 9710&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Problem====&lt;br /&gt;
When the 11g DB was started, LD_LIBRARY_PATH and LIBPATH were still pointing to paths in the 10g Home.&lt;br /&gt;
====Solution====&lt;br /&gt;
There may have been some odd values setup in LD_LIBRARY_PATH before the call to oraenv (if oraenv was indeed called!)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
unset LD_LIBRARY_PATH LIBPATH&lt;br /&gt;
export ORACLE_SID=&amp;lt;correct 11g SID&amp;gt;&lt;br /&gt;
. oraenv&lt;br /&gt;
echo $LD_LIBRARY_PATH&lt;br /&gt;
echo $LIBPATH&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
They should now be correct.&lt;br /&gt;
&lt;br /&gt;
===ORA-27092: size of file exceeds file size limit of the process===&lt;br /&gt;
Think ulimit...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Cause: an attempt was made to open a file that exceeds the process&amp;#039;s file size limit (ulimit), additional information shows the current limit (logical blocks) and the size of the file (logical blocks)&lt;br /&gt;
Action: increase the processes file size limit (ulimit) and retry&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
truncate table pibadm.test_ph&lt;br /&gt;
                      *&lt;br /&gt;
Error at line 1 :&lt;br /&gt;
ORA-00604: error ocurred at recursive SQL level 1&lt;br /&gt;
ORA-01116: error in opening database file 2&lt;br /&gt;
ORA-01110: datafile 2 : &amp;#039;/opt/u01/data/PIBQA/UNDO_01.dbf&amp;#039;&lt;br /&gt;
ORA-27092: size of file exceeds file size limit of the process&lt;br /&gt;
Additional information: 262143&lt;br /&gt;
Additional information: 2621441&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Check the fs_size limit for this user in /etc/security/limits&amp;lt;br /&amp;gt;&lt;br /&gt;
Compare this with another user, say oracle. Probably -1 (unlimited)&lt;br /&gt;
&lt;br /&gt;
===SP2-1503: Unable to initialize Oracle call interface===&lt;br /&gt;
When trying to login to the database via SQL*Plus, these messages a displayed&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
hn5118 /home/oracle $sqlplus / as sysdba&lt;br /&gt;
SP2-1503: Unable to initialize Oracle call interface&lt;br /&gt;
SP2-0152: ORACLE may not be functioning properly&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Seems to be a problem unique to AIX (in this case).&amp;lt;br /&amp;gt;&lt;br /&gt;
Check to see what the LIBPATH variable is. It may still contain a path to an old ORACLE_HOME...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
hn5118 /home/oracle $env|grep LIBPATH&lt;br /&gt;
LIBPATH=/oracle/exp/ora_bin1/app/oracle/product/10.2.0/db_1/lib:/oracle/exp/ora_bin1/app/oracle/product/10.2.0/db_1/lib&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Disco! Unset it and rerun.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
hn5118 /home/oracle $unset LIBPATH&lt;br /&gt;
&lt;br /&gt;
hn5118 /home/oracle $sqlplus / as sysdba&lt;br /&gt;
&lt;br /&gt;
SQL*Plus: Release 12.1.0.2.0 Production on Wed Jul 12 17:17:54 2017&lt;br /&gt;
&lt;br /&gt;
Copyright (c) 1982, 2014, Oracle.  All rights reserved.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Connected to:&lt;br /&gt;
Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production&lt;br /&gt;
With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options&lt;br /&gt;
&lt;br /&gt;
SQL&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===UDE-31623: operation generated ORACLE error 31623===&lt;br /&gt;
When using Data pump, get following errors almost immediately:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
UDE-31623: operation generated ORACLE error 31623&lt;br /&gt;
ORA-31623: a job is not attached to this session via the specified handle&lt;br /&gt;
ORA-06512: at &amp;quot;SYS.DBMS_DATAPUMP&amp;quot;, line 3326&lt;br /&gt;
ORA-06512: at &amp;quot;SYS.DBMS_DATAPUMP&amp;quot;, line 4551&lt;br /&gt;
ORA-06512: at line 1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Solution 1:&amp;#039;&amp;#039;&amp;#039;&amp;lt;br /&amp;gt;&lt;br /&gt;
In one case, I simplified the parameter file that was used. Maybe related to Streams Pool size, who knows?!&amp;lt;br /&amp;gt;&lt;br /&gt;
I removed these 2 lines and the export started working:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
compression_algorithm=medium&lt;br /&gt;
logtime=all&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Solution 2:&amp;#039;&amp;#039;&amp;#039;&amp;lt;br /&amp;gt;&lt;br /&gt;
There is a note about this on Metalink, 1080775.1 which suggests that Streams Pool Size needs setting.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
For this DataPump error, you will need to configure the database with some Streams Pool.&lt;br /&gt;
&lt;br /&gt;
Perform the following query to find out how much STREAMS_POOL_SIZE has been allocated&lt;br /&gt;
&lt;br /&gt;
 select * from v$sgainfo;&lt;br /&gt;
 ...&lt;br /&gt;
 Streams Pool Size                               0 Yes&lt;br /&gt;
&lt;br /&gt;
Data Pump now uses Advanced Queuing (AQ) internally, so it can handle job stops/starts/re-starts.  However, AQ using the Streams Pool, where the database currently has the STREAMS_POOL_SIZE set to ZERO.&lt;br /&gt;
&lt;br /&gt;
Manually set the STREAMS_POOL_SIZE (using ALTER SYSTEM or by changing the value in the the PFILE/SPFILE), re-start the database and re-attempt the Data Pump Export.&lt;br /&gt;
&lt;br /&gt;
Alternately, turn on Automatic Shared Memory management (ASMM) by setting SGA_TARGET or MEMORY_TARGET.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
From Oracle Documentation&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Setting the Size Of the Buffer Cache In a Streams Environment&lt;br /&gt;
&lt;br /&gt;
Oracle Data Pump uses Streams functionality to communicate between processes.&lt;br /&gt;
If the SGA_TARGET initialization parameter is set, then the STREAMS_POOL_SIZE initialization parameter is automatically set to a reasonable value.&lt;br /&gt;
If the SGA_TARGET initialization parameter is not set and the STREAMS_POOL_SIZE initialization parameter is not defined,&lt;br /&gt;
then the size of the streams pool automatically defaults to 10% of the size of the shared pool.&lt;br /&gt;
&lt;br /&gt;
When the streams pool is created, the required SGA memory is taken from memory allocated to the buffer cache,&lt;br /&gt;
reducing the size of the cache to less than what was specified by the DB_CACHE_SIZE initialization parameter.&lt;br /&gt;
This means that if the buffer cache was configured with only the minimal required SGA, then Data Pump operations may not work properly.&lt;br /&gt;
A minimum size of 10M is recommended for STREAMS_POOL_SIZE in order to ensure successful Data Pump operations.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORA-00020: maximum number of processes (150) exceeded===&lt;br /&gt;
Check the current resource limits with:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 300&lt;br /&gt;
select * from v$resource_limit;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Unfortunately this limit cannot be increased without a restart.&amp;lt;br /&amp;gt;&lt;br /&gt;
It may be a necessary to increase the limit with&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter system set processes=500 scope=spfile;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
followed by a shutdown/startup&amp;lt;br /&amp;gt;&lt;br /&gt;
Or it may be some user is running away with the limit.&amp;lt;br /&amp;gt;&lt;br /&gt;
Check to see who is running what with:&lt;br /&gt;
[[http://www.mailnest.com/dbawiki/index.php/Handy_scripts#See_what_statements_all_users_are_running See_what_statements_all_users_are_running]]&lt;br /&gt;
===ORA-01555: snapshot too old: rollback segment number nn with name &amp;quot;xxx&amp;quot; too small===&lt;br /&gt;
* [http://dfitzjarrell.wordpress.com/2008/02/22/the-dreaded-ora-01555/ Good explanation of why it happens]&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
====Problem====&lt;br /&gt;
A long running transaction has run out of space to store its read-consistent image&lt;br /&gt;
&lt;br /&gt;
====Solution 1====&lt;br /&gt;
If it&amp;#039;s a one-off, maybe leave it alone. It may have been a user leaving a session open overnight without committing or rolling back.&lt;br /&gt;
&lt;br /&gt;
====Solution 2====&lt;br /&gt;
Make sure there&amp;#039;s enough space to allow the transaction to finish.&lt;br /&gt;
&lt;br /&gt;
====Things to check====&lt;br /&gt;
How much undo did the biggest transaction take?&lt;br /&gt;
What is the undo retention parameter set to?&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 200&lt;br /&gt;
col name        for a30&lt;br /&gt;
col description for a50&lt;br /&gt;
col value       for a20&lt;br /&gt;
col maxquerylen for 999999&lt;br /&gt;
select p.name&lt;br /&gt;
,      p.description&lt;br /&gt;
,      p.value&lt;br /&gt;
,      max(u.maxquerylen) maxquerylen&lt;br /&gt;
from   v$parameter p&lt;br /&gt;
,      v$undostat  u&lt;br /&gt;
where  1=1&lt;br /&gt;
and    p.name = &amp;#039;undo_retention&amp;#039;&lt;br /&gt;
group  by p.name&lt;br /&gt;
,      p.description&lt;br /&gt;
,      p.value;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Set the retention to about 20% bigger than the maxquerylen.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select &amp;#039;alter system set undo_retention=&amp;#039;||round(1.2*max(maxquerylen))||&amp;#039; scope=both;&amp;#039; &amp;quot;Run this&amp;quot; from v$undostat;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
and set the undo retention guarantee (being aware of the consequences)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select tablespace_name&lt;br /&gt;
,      retention&lt;br /&gt;
from   dba_tablespaces;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter tablespace &amp;amp;undo_ts_name retention guarantee;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Optimise Oracle UNDO Parameters===&lt;br /&gt;
&lt;br /&gt;
The ideal undo_retention would be enough to hold rollback for the longest transaction that happened so far (can&amp;#039;t see into the future)&amp;lt;br /&amp;gt;&lt;br /&gt;
So current undo_retention = current value of undo / (db_block_size * undo blocks per sec)&amp;lt;br /&amp;gt;&lt;br /&gt;
* Undo Blocks per Second&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SELECT MAX(undoblks/((end_time-begin_time)*3600*24)) &amp;quot;UNDO_BLOCKS_PER_SEC&amp;quot;&lt;br /&gt;
FROM   v$undostat;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Optimal Undo Retention&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
col actual for 9999999999.99 heading &amp;quot;ACTUAL UNDO SIZE [MByte]&amp;quot;&lt;br /&gt;
col retent for 9999999999    heading &amp;quot;UNDO RETENTION [Sec]&amp;quot;&lt;br /&gt;
col needed for 9999999999.99 heading &amp;quot;NEEDED UNDO SIZE [Secs]&amp;quot;&lt;br /&gt;
&lt;br /&gt;
SELECT d.undo_size/(1024*1024) actual,&lt;br /&gt;
       to_number(SUBSTR(e.value,1,25)) retent,&lt;br /&gt;
       ROUND((d.undo_size / (to_number(f.value) *&lt;br /&gt;
       g.undo_block_per_sec))) needed&lt;br /&gt;
  FROM (&lt;br /&gt;
       SELECT SUM(a.bytes) undo_size&lt;br /&gt;
          FROM v$datafile a,&lt;br /&gt;
               v$tablespace b,&lt;br /&gt;
               dba_tablespaces c&lt;br /&gt;
         WHERE c.contents = &amp;#039;UNDO&amp;#039;&lt;br /&gt;
           AND c.status = &amp;#039;ONLINE&amp;#039;&lt;br /&gt;
           AND b.name = c.tablespace_name&lt;br /&gt;
           AND a.ts# = b.ts#&lt;br /&gt;
       ) d,&lt;br /&gt;
       v$parameter e,&lt;br /&gt;
       v$parameter f,&lt;br /&gt;
       (&lt;br /&gt;
       SELECT MAX(undoblks/((end_time-begin_time)*3600*24))&lt;br /&gt;
              undo_block_per_sec&lt;br /&gt;
         FROM v$undostat&lt;br /&gt;
       ) g&lt;br /&gt;
WHERE e.name = &amp;#039;undo_retention&amp;#039;&lt;br /&gt;
  AND f.name = &amp;#039;db_block_size&amp;#039;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Calculate Needed UNDO Size for given Database Activity&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
col actual for 9999999999.99 heading &amp;quot;ACTUAL UNDO SIZE [MByte]&amp;quot;&lt;br /&gt;
col retent for 9999999999    heading &amp;quot;UNDO RETENTION [Sec]&amp;quot;&lt;br /&gt;
col needed for 9999999999.99 heading &amp;quot;NEEDED UNDO SIZE [MByte]&amp;quot;&lt;br /&gt;
&lt;br /&gt;
SELECT d.undo_size/(1024*1024) actual&lt;br /&gt;
,      to_number(SUBSTR(e.value,1,25)) retent&lt;br /&gt;
,      (TO_NUMBER(e.value) * TO_NUMBER(f.value) *&lt;br /&gt;
       g.undo_block_per_sec) / (1024*1024)  needed&lt;br /&gt;
  FROM (&lt;br /&gt;
       SELECT SUM(a.bytes) undo_size&lt;br /&gt;
         FROM v$datafile a,&lt;br /&gt;
              v$tablespace b,&lt;br /&gt;
              dba_tablespaces c&lt;br /&gt;
        WHERE c.contents = &amp;#039;UNDO&amp;#039;&lt;br /&gt;
          AND c.status = &amp;#039;ONLINE&amp;#039;&lt;br /&gt;
          AND b.name = c.tablespace_name&lt;br /&gt;
          AND a.ts# = b.ts#&lt;br /&gt;
       ) d,&lt;br /&gt;
      v$parameter e,&lt;br /&gt;
       v$parameter f,&lt;br /&gt;
       (&lt;br /&gt;
       SELECT MAX(undoblks/((end_time-begin_time)*3600*24))&lt;br /&gt;
         undo_block_per_sec&lt;br /&gt;
         FROM v$undostat&lt;br /&gt;
       ) g&lt;br /&gt;
 WHERE e.name = &amp;#039;undo_retention&amp;#039;&lt;br /&gt;
  AND f.name = &amp;#039;db_block_size&amp;#039;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
It might be that the Export still fails with ORA-01555 even though retention seems long enough.&amp;lt;br /&amp;gt;&lt;br /&gt;
Are you running an export with the flashback_time parameter? If so, the undo_retention should be longer than the total export running time!&amp;lt;br /&amp;gt;&lt;br /&gt;
===Check LOB undo retention===&lt;br /&gt;
The retention settings for LOBS is different for the rest of the database.&amp;lt;br /&amp;gt;&lt;br /&gt;
When you change the UNDO_RETENTION parameter, the LOB segment’s retention value is NOT modified.&amp;lt;br /&amp;gt;&lt;br /&gt;
If you query the RETENTION column of the DBA_LOBS view, you will notice the old UNDO_RETENTION value still remains after you have modified the UNDO_RETENTION parameter.&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SQL&amp;gt; show parameter undo_&lt;br /&gt;
&lt;br /&gt;
NAME                                 TYPE        VALUE&lt;br /&gt;
------------------------------------ ----------- ------------------------------&lt;br /&gt;
undo_management                      string      AUTO&lt;br /&gt;
undo_retention                       integer     36000&lt;br /&gt;
undo_tablespace                      string      UNDOTBS1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SQL&amp;gt; desc SITEADMIN.AUDIT_LOG_MESSAGE&lt;br /&gt;
 Name                                      Null?    Type&lt;br /&gt;
 ----------------------------------------- -------- ----------------------------&lt;br /&gt;
 AUDIT_LOG_MESSAGE_ID                      NOT NULL NUMBER&lt;br /&gt;
 AUDIT_LOG_ID                              NOT NULL NUMBER&lt;br /&gt;
 SEQUENCE                                           NUMBER&lt;br /&gt;
 MESSAGE                                            CLOB&lt;br /&gt;
 CREATE_DATE                                        TIMESTAMP(6)&lt;br /&gt;
 COMPONENT_ID                                       VARCHAR2(50 CHAR)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 300&lt;br /&gt;
col column_name for a32&lt;br /&gt;
select table_name,column_name, pctversion,retention from dba_lobs where owner=&amp;#039;&amp;amp;table_owner&amp;#039;;&lt;br /&gt;
&lt;br /&gt;
TABLE_NAME                COLUMN_NAME                    PCTVERSION  RETENTION&lt;br /&gt;
------------------------- ------------------------------ ---------- ----------&lt;br /&gt;
EMAIL_STORE               CONTENT                                 0&lt;br /&gt;
EMAIL_STORE_ATTACHEMENT   ATTACHEMENT                             0&lt;br /&gt;
TRACKING                  ORIGINAL_MESSAGE                                 900&lt;br /&gt;
TRACKING                  MESSAGE                                          900&lt;br /&gt;
TRACKING                  SIEBEL_MESSAGE                                   900&lt;br /&gt;
WISE_WMS_LOG              WISE_WMS_XML                                     900&lt;br /&gt;
ATTACHMENT                ORIGINAL_MESSAGE                                 900&lt;br /&gt;
PLAN_TABLE                OTHER_XML                                        900&lt;br /&gt;
AUDIT_LOG_MESSAGE         MESSAGE                                          900&lt;br /&gt;
EXCEPTIONS                STACK_TRACE                                      900&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
To change the LOB segment’s RETENTION value to match the new UNDO_RETENTION value, do the following:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ALTER TABLE my_table MODIFY LOB (lob_column) (PCTVERSION 20);&lt;br /&gt;
ALTER TABLE my_table MODIFY LOB (lob_column) (RETENTION);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
By momentarily changing the LOB to use PCTVERSION and then back to RETENTION, the new value of UNDO_RETENTION will be used.&amp;lt;br /&amp;gt;&lt;br /&gt;
You need to do this for all LOB segments that you intend to modify.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select &amp;#039;ALTER TABLE &amp;#039;||owner||&amp;#039;.&amp;#039;||table_name||&amp;#039; MODIFY LOB (&amp;#039;||column_name||&amp;#039;) (PCTVERSION 20);&amp;#039; from dba_lobs where owner=&amp;#039;TIBCO&amp;#039;&lt;br /&gt;
&lt;br /&gt;
select &amp;#039;ALTER TABLE &amp;#039;||owner||&amp;#039;.&amp;#039;||table_name||&amp;#039; MODIFY LOB (&amp;#039;||column_name||&amp;#039;) (RETENTION);&amp;#039;     from dba_lobs where owner=&amp;#039;TIBCO&amp;#039;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
There is a table DBA_LOBS that displays information about all the LOB columns in the database, but it doesn&amp;#039;t actually store any LOB data, just metadata. The actual LOB segments in the database have system-generated names that take the form SYS_LOB*identifier*$$.&lt;br /&gt;
For example if you identify a segment named SYS_LOBidentifier$$ that is consuming space, you can find out what column of what table that LOB column maps to using the DBA_LOBS table:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 1000&lt;br /&gt;
col owner       for a20&lt;br /&gt;
col table_name  for a32&lt;br /&gt;
col column_name for a32&lt;br /&gt;
select owner&lt;br /&gt;
,      table_name&lt;br /&gt;
,      column_name&lt;br /&gt;
from   dba_lobs&lt;br /&gt;
where  1=1&lt;br /&gt;
and    segment_name = &amp;#039;SYS_LOB&amp;lt;&amp;lt;identifier&amp;gt;&amp;gt;$$&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====The Undo Advisor PL/SQL Interface====&lt;br /&gt;
You can activate the Undo Advisor by creating an undo advisor task through the advisor framework.&amp;lt;br /&amp;gt;&lt;br /&gt;
The following example creates an undo advisor task to evaluate the undo tablespace. The name of the advisor is &amp;#039;Undo Advisor&amp;#039;.&amp;lt;br /&amp;gt;&lt;br /&gt;
The analysis is based on Automatic Workload Repository snapshots, which you must specify by setting parameters START_SNAPSHOT and END_SNAPSHOT.&amp;lt;br /&amp;gt;&lt;br /&gt;
In the following example, the START_SNAPSHOT is &amp;quot;1&amp;quot; and END_SNAPSHOT is &amp;quot;2&amp;quot;.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
DECLARE&lt;br /&gt;
   tid    NUMBER;&lt;br /&gt;
   tname  VARCHAR2(30);&lt;br /&gt;
   oid    NUMBER;&lt;br /&gt;
BEGIN&lt;br /&gt;
   DBMS_ADVISOR.CREATE_TASK(&amp;#039;Undo Advisor&amp;#039;, tid, tname, &amp;#039;Undo Advisor Task&amp;#039;);&lt;br /&gt;
   DBMS_ADVISOR.CREATE_OBJECT(tname, &amp;#039;UNDO_TBS&amp;#039;, null, null, null, &amp;#039;null&amp;#039;, oid);&lt;br /&gt;
   DBMS_ADVISOR.SET_TASK_PARAMETER(tname, &amp;#039;TARGET_OBJECTS&amp;#039;, oid);&lt;br /&gt;
   DBMS_ADVISOR.SET_TASK_PARAMETER(tname, &amp;#039;START_SNAPSHOT&amp;#039;, 1);&lt;br /&gt;
   DBMS_ADVISOR.SET_TASK_PARAMETER(tname, &amp;#039;END_SNAPSHOT&amp;#039;, 2);&lt;br /&gt;
   DBMS_ADVISOR.SET_TASK_PARAMETER(tname, &amp;#039;INSTANCE&amp;#039;, 1);&lt;br /&gt;
   DBMS_ADVISOR.execute_task(tname);&lt;br /&gt;
        END;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
After you have created the advisor task, you can view the output and recommendations in the Automatic Database Diagnostic Monitor in Enterprise Manager.&amp;lt;br /&amp;gt;&lt;br /&gt;
This information is also available in the DBA_ADVISOR_* data dictionary views (DBA_ADVISOR_TASKS, DBA_ADVISOR_OBJECTS, DBA_ADVISOR_FINDINGS, DBA_ADVISOR_RECOMMENDATIONS, and so on).&lt;br /&gt;
====References====&lt;br /&gt;
* [http://www.akadia.com/services/ora_optimize_undo.html akadia.com]&lt;br /&gt;
* [http://dfitzjarrell.wordpress.com/2008/02/22/the-dreaded-ora-01555/ the dreaded ora-01555]&lt;br /&gt;
* [http://docs.oracle.com/cd/B28359_01/server.111/b28310/undo004.htm#ADMIN11469 docs.oracle.com]&lt;br /&gt;
&lt;br /&gt;
===Error 6 initializing SQL*Plus===&lt;br /&gt;
Using sqlplus or rman under Cygwin, ORACLE_HOME still needs to be windows format!&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Message file sp1&amp;lt;lang&amp;gt;.msb not found&lt;br /&gt;
SP2-0750 :You may need to set ORACLE_HOME to your Oracle software directory&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
so...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
export ORACLE_SID=KITRYD&lt;br /&gt;
ORAENV_ASK=NO&lt;br /&gt;
. oraenv&lt;br /&gt;
[[ &amp;quot;`uname`&amp;quot; == CYGWIN* ]] &amp;amp;&amp;amp; ORACLE_HOME=`cygpath -w ${ORACLE_HOME}`&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===ORA-2002: error while writing to audit trail===&lt;br /&gt;
Check the space left in the audit tablespace with:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select sum(bytes)/1024/1024 mb from dba_free_space where tablespace_name =&amp;#039;AUDIT_DT&amp;#039;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
If plenty of space, it can be due to Oracle clearing out the recyclebin at the same time.&amp;lt;br /&amp;gt;&lt;br /&gt;
If not, extend the datafile...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select * from dba_data_files where tablespace_name =&amp;#039;AUDIT_DT&amp;#039;;&lt;br /&gt;
alter database datafile 6 resize 30G;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
If that is not possible, clean out some audit data or add a datafile.&lt;br /&gt;
&lt;br /&gt;
===ORA-00449: background process &amp;#039;CKPT&amp;#039; unexpectedly terminated with error 7446===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SQL&amp;gt; startup nomount pfile=&amp;quot;/oracle/TRSCRP1/admin/initTRSCRP1.ora&amp;quot;&lt;br /&gt;
ORA-00449: background process &amp;#039;CKPT&amp;#039; unexpectedly terminated with error 7446&lt;br /&gt;
ORA-07446: sdnfy: bad value &amp;#039;&amp;#039; for parameter .&lt;br /&gt;
SQL&amp;gt; exit&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Solution&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SQL&amp;gt; mkdir /oracle/TRSCRP1/admin/bdump /oracle/TRSCRP1/admin/cdump&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORA-00845: MEMORY_TARGET not supported on this system===&lt;br /&gt;
* Reference: [http://arjudba.blogspot.be/2009/01/ora-00845-memorytarget-not-supported-on.html arjudba.blogspot.be]&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Problem Description&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SQL&amp;gt; STARTUP&lt;br /&gt;
ORA-00845: MEMORY_TARGET not supported on this system&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Cause&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
* Starting from Oracle 11g the automatic memory management feature is now defined with parameter MEMORY_TARGET and MEMMORY_MAX_TARGET.&lt;br /&gt;
* On linux file system the shared memory need to be mounted on /dev/shm directory on the operating system.&lt;br /&gt;
* And the size of /dev/shm needs to be greater than MEMORY_TARGET or MEMMORY_MAX_TARGET.&lt;br /&gt;
* The AMM (Automatic Memory Management) now in 11g manages both SGA and PGA together by MMAN process.&lt;br /&gt;
* The MEMORY_TARGET parameter in 11g comes for (SGA_TARGET+PGA_AGGREGATE_TARGET) which was in 10g.&lt;br /&gt;
* And MEMORY_MAX_TARGET parameter in 11g comes instead of SGA_MAX_TARGET parameter which was in 10g.&lt;br /&gt;
* The ORA-00845:can arises for the following two reasons on linux system.&lt;br /&gt;
1)If the shared memory which is mapped to /dev/shm directory is less than the size of MEMORY_TARGET or MEMORY_MAX_TARGET or&lt;br /&gt;
2)If the shared memory is not mapped to /dev/shm directory.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Solution&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Make sure /dev/shm is properly mounted. You can see it by,&lt;br /&gt;
#df -h or #df -k command.&lt;br /&gt;
The output should be similar to:&lt;br /&gt;
&lt;br /&gt;
$ df -k&lt;br /&gt;
Filesystem            Size  Used Avail Use% Mounted on&lt;br /&gt;
...&lt;br /&gt;
shmfs                 1G    512M 512M  50% /dev/shm&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
We see here for /dev/shm we have assigned 1G memory. Now if you set MEMORY_TARGET more than 1G then above ORA-845 will arise. For example if you have MEMORY_TARGET or MEMORY_MAX_TARGET set to 12G then you can mount shared memory to 13g like below.&lt;br /&gt;
As a root user,&lt;br /&gt;
# mount -t tmpfs shmfs -o size=13g /dev/shm&lt;br /&gt;
In order to make the settings persistence so that it will affect after restarting machine add an entry in /etc/fstab similar to the following:&lt;br /&gt;
&lt;br /&gt;
shmfs /dev/shm tmpfs size=13g 0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORA-24247: network access denied by access control list (ACL)===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Cause: No access control list (ACL) has been assigned to the target host or the privilege necessary to access the target host has not been granted to the user in the access control list.&lt;br /&gt;
&lt;br /&gt;
Action: Ensure that an access control list (ACL) has been assigned to the target host and the privilege necessary to access the target host has been granted to the user.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Your application will encounter an ORA-24247 error if it relies on one of the network packages and no proper ACL has been created. For the use of the following packages it is mandatory to have an ACL for the application user in place in 11g:&lt;br /&gt;
*UTL_TCP&lt;br /&gt;
*UTL_SMTP&lt;br /&gt;
*UTL_MAIL&lt;br /&gt;
*UTL_HTTP&lt;br /&gt;
*UTL_INADDR&lt;br /&gt;
Here is a very good explanation of how to setup the necessary ACLs: [[http://blog.whitehorses.nl/2010/03/17/oracle-11g-access-control-list-and-ora-24247/ whitehorses.nl]]&lt;br /&gt;
&lt;br /&gt;
===ORA-00600: internal error code, arguments: [qmx: no ref]===&lt;br /&gt;
Search &amp;quot;Master Note for Oracle XML Database (XDB) Install / Deinstall (Doc ID 1292089.1)&amp;quot; for more info.&lt;br /&gt;
====Problem:====&lt;br /&gt;
Sometimes one or more of the following errors can be encountered when installing or upgrading XDB, configuring APEX, running an Export, or selecting from xdb.xdb$resource or sys.dba_network_acls:&amp;lt;br /&amp;gt;&lt;br /&gt;
* ORA-31159: XML DB is in an invalid state&lt;br /&gt;
* ORA-00600: internal error code, arguments: [unable to load XDB library]&lt;br /&gt;
* ORA-00600: internal error code, arguments: [qmx: no ref]&lt;br /&gt;
* ORA-00600: internal error code, arguments: [qmtGetColumnInfo1]&lt;br /&gt;
* ORA-00600: internal error code, arguments: [qmtb_init_len]&lt;br /&gt;
* ORA-00600: internal error code, arguments: [qmtGetBaseType]&lt;br /&gt;
* ORA-00600: internal error code, arguments: [psdnop-1], [600]&lt;br /&gt;
* ORA-00600: internal error code, arguments: [qmtInit1]&lt;br /&gt;
* ORA-07445: exception encountered: core dump [_memcpy()+224] [SIGSEGV] [Address not mapped to object]&lt;br /&gt;
* ORA-19051 Cannot Use Fast Path Insert For This XMLType Table&lt;br /&gt;
* ORA-31011: XML parsing failed&lt;br /&gt;
Errors of this sort generally occur when the init routines for the internal XDB functions are run in an invalid environment causing memory corruption.&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
This can happen if the database was ever started with the LD_LIBRARY_PATH (LIBPATH for AIX or SHLIB_PATH for HP) pointing to the wrong $ORACLE_HOME/lib directory rather than to the correct location for the instance.&amp;lt;br /&amp;gt;&lt;br /&gt;
The LD_LIBRARY_PATH/LIBPATH/SHLIB_PATH environment variable is used to resolve the location of the shared library &amp;quot;libxdb.so (libxdb.sl on HP)&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
====Solution:====&lt;br /&gt;
* Stop Listener&lt;br /&gt;
* Stop database&lt;br /&gt;
* Ensure $ORACLE_HOME/lib is at the start of LD_LIBRARY_PATH / LIBPATH / SHLIB_PATH&lt;br /&gt;
* If AIX, run /usr/sbin/slibclean as root&lt;br /&gt;
* Start database&lt;br /&gt;
* Start listener&lt;br /&gt;
&lt;br /&gt;
===ORA-00201: control file version nn.nn.nn.nn incompatible with ORACLE version===&lt;br /&gt;
Trying to restore a database after complete failure&amp;lt;br /&amp;gt;&lt;br /&gt;
first step is to startup the database in nomount mode and restore the controlfile - succeeded.&amp;lt;br /&amp;gt;&lt;br /&gt;
second step, startup the database in mount mode ready for database restore...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SQL*Plus: Release 10.2.0.3.0 - Production on Wed Aug 19 18:16:47 2015&lt;br /&gt;
&lt;br /&gt;
Copyright (c) 1982, 2006, Oracle.  All Rights Reserved.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Connected to:&lt;br /&gt;
Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - 64bit Production&lt;br /&gt;
With the Partitioning, OLAP and Data Mining options&lt;br /&gt;
&lt;br /&gt;
SYS@CODWHP1&amp;gt; startup mount&lt;br /&gt;
ORACLE instance started.&lt;br /&gt;
&lt;br /&gt;
Total System Global Area  260046848 bytes&lt;br /&gt;
Fixed Size                  2029296 bytes&lt;br /&gt;
Variable Size             113248528 bytes&lt;br /&gt;
Database Buffers          134217728 bytes&lt;br /&gt;
Redo Buffers               10551296 bytes&lt;br /&gt;
ORA-00201: control file version 10.2.0.0.0 incompatible with ORACLE version 10.2.0.3.0&lt;br /&gt;
ORA-00202: control file: &amp;#039;/oracle/CODWHP1/product/10203/dbs/cntrlCODWHP1.dbf&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The problem was there was no compatible parameter in the simple init file I used to start up the instance.&amp;lt;br /&amp;gt;&lt;br /&gt;
Adding compatible parameter to init file to be same version (10.2.0.3) allowed the db to mount.&lt;br /&gt;
&lt;br /&gt;
===TNS-00525: Insufficient privilege for operation===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
lsnrctl start LISTENER_UCLID55V&lt;br /&gt;
&lt;br /&gt;
LSNRCTL for IBM/AIX RISC System/6000: Version 11.2.0.3.0 - Production on 26-MAR-2015 13:36:14&lt;br /&gt;
&lt;br /&gt;
Copyright (c) 1991, 2011, Oracle.  All rights reserved.&lt;br /&gt;
&lt;br /&gt;
Starting /oracle/product/11.2.0.3/bin/tnslsnr: please wait...&lt;br /&gt;
&lt;br /&gt;
TNSLSNR for IBM/AIX RISC System/6000: Version 11.2.0.3.0 - Production&lt;br /&gt;
System parameter file is /oracle/product/11.2.0.3/network/admin/listener.ora&lt;br /&gt;
Log messages written to /oracle/product/diag/tnslsnr/solax082/listener_uclid55v/alert/log.xml&lt;br /&gt;
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=150.251.114.238)(PORT=1525)))&lt;br /&gt;
Error listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC1525)))&lt;br /&gt;
TNS-12555: TNS:permission denied&lt;br /&gt;
 TNS-12560: TNS:protocol adapter error&lt;br /&gt;
  TNS-00525: Insufficient privilege for operation&lt;br /&gt;
   IBM/AIX RISC System/6000 Error: 1: Not owner&lt;br /&gt;
&lt;br /&gt;
Listener failed to start. See the error message(s) above...&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This would suggest the user attempting to start the listener has no access to either the Oracle binaries or the TNS listener/tnsnames files.&amp;lt;br /&amp;gt;&lt;br /&gt;
But... checkout the /tmp/.oracle directory :-)&amp;lt;br /&amp;gt;&lt;br /&gt;
That hidden gem shows who started the listener last time. Delete the relevant entry and try again!&amp;lt;br /&amp;gt;&lt;br /&gt;
To start from a clean sheet, stop all listeners, delete this directory and restart the listeners.&lt;br /&gt;
&lt;br /&gt;
===ORA-12003: materialized view or zonemap &amp;quot;KPK&amp;quot;.&amp;quot;EVD01_NEW&amp;quot; does not exist===&lt;br /&gt;
Here&amp;#039;s one you shouldn&amp;#039;t see very often.&amp;lt;br /&amp;gt;&lt;br /&gt;
Trying to drop a tablespace but prevented from doing so because a materialized view has referential contraints on a table in this tablespace.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SQL&amp;gt; drop tablespace TS_THALER_PART_OLD including contents and datafiles cascade constraints;&lt;br /&gt;
drop tablespace TS_THALER_PART_OLD including contents and datafiles cascade constraints&lt;br /&gt;
*&lt;br /&gt;
ERROR at line 1:&lt;br /&gt;
ORA-00604: error occurred at recursive SQL level 1&lt;br /&gt;
ORA-12083: must use DROP MATERIALIZED VIEW to drop &amp;quot;KPK&amp;quot;.&amp;quot;EVD01_NEW&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Ok, nice of Oracle to tell us what we have to do. Simple enough. Let&amp;#039;s drop the materialized view.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SQL&amp;gt; DROP MATERIALIZED VIEW &amp;quot;KPK&amp;quot;.&amp;quot;EVD01_NEW&amp;quot;;&lt;br /&gt;
DROP MATERIALIZED VIEW &amp;quot;KPK&amp;quot;.&amp;quot;EVD01_NEW&amp;quot;&lt;br /&gt;
*&lt;br /&gt;
ERROR at line 1:&lt;br /&gt;
ORA-12003: materialized view or zonemap &amp;quot;KPK&amp;quot;.&amp;quot;EVD01_NEW&amp;quot; does not exist&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Aah. Not so obvious then.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
desc &amp;quot;KPK&amp;quot;.&amp;quot;EVD01_NEW&amp;quot;&lt;br /&gt;
 Name                                      Null?    Type&lt;br /&gt;
 ----------------------------------------- -------- ----------------------------&lt;br /&gt;
 DATMAJ                                             VARCHAR2(8 CHAR)&lt;br /&gt;
 HEUMAJ                                             VARCHAR2(8 CHAR)&lt;br /&gt;
 PGMMAJ                                             VARCHAR2(6 CHAR)&lt;br /&gt;
 NATOPN                                             VARCHAR2(6 CHAR)&lt;br /&gt;
 REFEXN                                             VARCHAR2(50 CHAR)&lt;br /&gt;
 SWIOLN                                             VARCHAR2(1 CHAR)&lt;br /&gt;
 STAEVT                                             VARCHAR2(4 CHAR)&lt;br /&gt;
 REFEVT                                             VARCHAR2(16 CHAR)&lt;br /&gt;
 NUMIDT                                             VARCHAR2(30 CHAR)&lt;br /&gt;
 ORIEVT                                             VARCHAR2(10 CHAR)&lt;br /&gt;
 REFLOG                                             VARCHAR2(16 CHAR)&lt;br /&gt;
 MSGEVT_CPL                                         VARCHAR2(1500 CHAR)&lt;br /&gt;
 REFOPN                                             VARCHAR2(16 CHAR)&lt;br /&gt;
 DATEVT                                             VARCHAR2(8 CHAR)&lt;br /&gt;
 MSGEVT_FIL_1                                       VARCHAR2(2000 CHAR)&lt;br /&gt;
 MSGEVT_FIL_2                                       VARCHAR2(2000 CHAR)&lt;br /&gt;
 MSGEVT_SPE                                         VARCHAR2(200 CHAR)&lt;br /&gt;
 DATEFF                                             VARCHAR2(8 CHAR)&lt;br /&gt;
 TMSTMP                                             VARCHAR2(15 CHAR)&lt;br /&gt;
 VEREVT                                             VARCHAR2(3 CHAR)&lt;br /&gt;
 MSGEVT_FIL_3                                       VARCHAR2(2000 CHAR)&lt;br /&gt;
 MSGEVT_FIL_4                                       VARCHAR2(2000 CHAR)&lt;br /&gt;
 TYPEVT                                             VARCHAR2(5 CHAR)&lt;br /&gt;
 SBP_CODAPP                                         VARCHAR2(10 CHAR)&lt;br /&gt;
 SBP_REFINT                                         VARCHAR2(36 CHAR)&lt;br /&gt;
 SBP_TYPACT                                         VARCHAR2(2 CHAR)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
It exists... but as a table.&amp;lt;br /&amp;gt;&lt;br /&gt;
Something has gone wrong in the database somewhere. As it turns out after some deeper investigation, this database is a copy of production but &amp;quot;with modifications&amp;quot;.&amp;lt;br /&amp;gt;&lt;br /&gt;
After the cloning process, a schema needed renaming. Oracle have a procedure for this but it is very long-winded and time-consuming. It uses export and import with transportable tablespaces to do the remap of the schema.&amp;lt;br /&amp;gt;&lt;br /&gt;
An unsupported workaround to rename schema is to simply update the username in sys.user$ and restart the database.&amp;lt;br /&amp;gt;&lt;br /&gt;
This works for the most part but now we see a consequence of that action.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
col owner      for a30&lt;br /&gt;
col mview_name for a30&lt;br /&gt;
select owner&lt;br /&gt;
,      mview_name&lt;br /&gt;
from   dba_mviews&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
OWNER                          MVIEW_NAME&lt;br /&gt;
------------------------------ ------------------------------&lt;br /&gt;
EPK                            EVD01_NEW&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Ahaa, there&amp;#039;s the materialized view but the owner is different from the one described by the database error message above. This one is the owner as it was on production.&amp;lt;br /&amp;gt;&lt;br /&gt;
This means the owner of materialized views has been denormalised for some reason. Reading the (complex) view text of dba_mviews, we see the owner column is based on sys.snap$.sowner&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
col sowner for a20&lt;br /&gt;
col vname  for a20&lt;br /&gt;
col tname  for a20&lt;br /&gt;
select sowner&lt;br /&gt;
,      vname&lt;br /&gt;
,      tname&lt;br /&gt;
from   sys.snap$&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
SOWNER               VNAME                TNAME&lt;br /&gt;
-------------------- -------------------- --------------------&lt;br /&gt;
EPK                  EVD01_NEW            EVD01_NEW&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
For future reference when updating the username in sys.user$, update the snapshot owner in this table as well!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
update sys.snap$&lt;br /&gt;
set    sowner = &amp;#039;KPK&amp;#039;&lt;br /&gt;
where  sowner = &amp;#039;EPK&amp;#039;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Try again&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
DROP MATERIALIZED VIEW &amp;quot;KPK&amp;quot;.&amp;quot;EVD01_NEW&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
Materialized view dropped.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
yep, and the tablespace?&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
drop tablespace TS_THALER_PART_OLD including contents and datafiles cascade constraints;&lt;br /&gt;
&lt;br /&gt;
Tablespace dropped.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORA-12162: TNS:net service name is incorrectly specified===&lt;br /&gt;
Probably nothing to do with TNS. Check your ORACLE_SID is set correctly!&lt;br /&gt;
&lt;br /&gt;
===ORA-00054: resource busy and acquire with NOWAIT specified===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SELECT O.OBJECT_NAME, S.SID, S.SERIAL#, P.SPID, S.PROGRAM,S.USERNAME,&lt;br /&gt;
S.MACHINE,S.PORT , S.LOGON_TIME,SQ.SQL_FULLTEXT &lt;br /&gt;
FROM V$LOCKED_OBJECT L, DBA_OBJECTS O, V$SESSION S, &lt;br /&gt;
V$PROCESS P, V$SQL SQ &lt;br /&gt;
WHERE L.OBJECT_ID = O.OBJECT_ID &lt;br /&gt;
AND L.SESSION_ID = S.SID AND S.PADDR = P.ADDR &lt;br /&gt;
AND S.SQL_ADDRESS = SQ.ADDRESS;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select object_name, s.sid, s.serial#, p.spid &lt;br /&gt;
from v$locked_object l, dba_objects o, v$session s, v$process p&lt;br /&gt;
where l.object_id = o.object_id and l.session_id = s.sid and s.paddr = p.addr;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
then&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter system kill session &amp;#039;sid,serial#&amp;#039;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORA-12518: TNS:listener could not hand off client connection===&lt;br /&gt;
The database you are trying to connect to is probably on its knees. Check server memory is not exhausted.&lt;br /&gt;
&lt;br /&gt;
===ORA-12520: TNS:listener could not find available handler for requested type of server===&lt;br /&gt;
Strangely this could be related to number of processes being exhausted.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
show parameter processes&lt;br /&gt;
alter system set processes=350 scope=spfile;&lt;br /&gt;
shutdown immediate&lt;br /&gt;
startup&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORA-12541: TNS: no listener===&lt;br /&gt;
Either very basic - start the listener!&amp;lt;br /&amp;gt;&lt;br /&gt;
or, as in our case - not so obvious.&amp;lt;br /&amp;gt;&lt;br /&gt;
We use virtual IP addresses so that the IP address stays the same after failover to standby.&amp;lt;br /&amp;gt;&lt;br /&gt;
Due to some confused configuration, we got the network adapter on two different servers to have the same IP address.&amp;lt;br /&amp;gt;&lt;br /&gt;
Stop the IP address on the bad server (assign another one) and all is fine again.&lt;br /&gt;
===ORA-12514: TNS:listener does not currently know of service===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
lsnrctl status &amp;lt;listener_name&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Been altering tnsnames.ora or listener.ora?&lt;br /&gt;
* Check the local_listener parameter&lt;br /&gt;
Try resetting it to itself. Strange but if you are not using port 1521, this can work wonders!&amp;lt;br /&amp;gt;&lt;br /&gt;
Assuming listener is called LISTENER_WM9T:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter system set local_listener=LISTENER_WM9T scope=both;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Try and connect with the service name or directly with&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sqlplus &amp;#039;sys/*******&amp;#039;@&amp;lt;host&amp;gt;:&amp;lt;port&amp;gt;/&amp;lt;SID&amp;gt; as sysdba&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Excellent description of how Oracle TNS listeners work and a checklist on how to fix this error&amp;lt;br /&amp;gt;&lt;br /&gt;
* [[http://edstevensdba.wordpress.com/2011/03/19/ora-12514/ TNS — Ed Stevens]]&lt;br /&gt;
&lt;br /&gt;
===ORA-12547: TNS lost contact===&lt;br /&gt;
&lt;br /&gt;
If&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sqlplus &amp;lt;user&amp;gt;/&amp;lt;pass&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
fails with above error, try&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sqlplus &amp;lt;user&amp;gt;/&amp;lt;pass&amp;gt;@&amp;lt;db connection&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
If this works, it is most probably a permissions error.&amp;lt;br /&amp;gt;&lt;br /&gt;
Re-run the&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ORACLE_HOME/root.sh&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
script that was run as part of the original installation. This will reset the permissions on some important files.&lt;br /&gt;
===ORA-02374: conversion error loading table &amp;quot;BLENGADM&amp;quot;.&amp;quot;ZZ_EVTCTA&amp;quot;===&lt;br /&gt;
This is typical of importing data with Datapump when the tables in the source database were created with &amp;quot;byte&amp;quot; semantics and the destination is &amp;quot;char&amp;quot; semantics.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ORA-02374: conversion error loading table &amp;quot;BLENGADM&amp;quot;.&amp;quot;ZZ_EVTCTA&amp;quot;&lt;br /&gt;
ORA-12899: value too large for column NOMCTA (actual: 257, maximum: 256)&lt;br /&gt;
&lt;br /&gt;
ORA-02372: data for row: NOMCTA : 0X&amp;#039;4C6976726574206427E9706172676E65202020202020202020&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Problem====&lt;br /&gt;
The root cause is the nls_length_semantics of the table columns being BYTE where one character is assigned one byte. But after conversion in a multi-byte database, one character is larger than one byte (could be 2, 3 or 4) and no longer fits.&lt;br /&gt;
====Solution====&lt;br /&gt;
* import the metadata&lt;br /&gt;
Run the impdp command with content=metadata_only. This will create all the tables (still in their original form) but not the data.&lt;br /&gt;
* alter the BYTE columns in the affected tables to CHAR semantics&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select column_name&lt;br /&gt;
,      char_used&lt;br /&gt;
,      data_length&lt;br /&gt;
,      data_type &lt;br /&gt;
from   user_tab_columns &lt;br /&gt;
where  table_name = &amp;#039;T&amp;#039;&lt;br /&gt;
and    char_used = &amp;#039;B&amp;#039;;&lt;br /&gt;
COLUMN_NAME  C DATA_LENGTH DATA_TYPE&lt;br /&gt;
------------ - ----------- ---------&lt;br /&gt;
X            B           1 VARCHAR2&lt;br /&gt;
SQL&amp;gt; alter table t modify x varchar2(1 char);&lt;br /&gt;
Table altered.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Import the data&lt;br /&gt;
Rerun the impdp ensuring table_exists_action is not REPLACE (use truncate or append). This now imports the data into the modified tables.&lt;br /&gt;
====This script does the donkey work of altering table column semantics from byte to char====&lt;br /&gt;
The author of this script is unknown but he/she deserves a medal. It saves countless hours of work and is so well written.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/*&lt;br /&gt;
  The script converts all the VARCHAR2 columns in the user&amp;#039;s schema&lt;br /&gt;
  to CHAR length semantics. Known to work on 10.2.0.4 and later.&lt;br /&gt;
  &lt;br /&gt;
  Script must be executed against the database without any other client&lt;br /&gt;
  and/or application connections to the affected schema.&lt;br /&gt;
  &lt;br /&gt;
  Oracle does not support CHAR semantics for the built-in schemas,&lt;br /&gt;
  like SYS, SYSTEM or SYSMAN, so the script will throw an error,&lt;br /&gt;
  if attempt to run it against any one of them.&lt;br /&gt;
  &lt;br /&gt;
  Upon completion database objects that have dependencies on tables&lt;br /&gt;
  being modified will be invalidated. Oracle usually re-compiles invalidated&lt;br /&gt;
  objects on the first access. Alternatively, a DBA can execute UTLPRP script&lt;br /&gt;
  to recompile all invalid objects in the entire database.&lt;br /&gt;
  &lt;br /&gt;
  Upon completion, please make sure that NLS_LENGTH_SEMANTICS instance parameter&lt;br /&gt;
  is set to CHAR to ensure further upgradability of the schema.&lt;br /&gt;
*/&lt;br /&gt;
set serveroutput on size unlimited format wrap&lt;br /&gt;
declare&lt;br /&gt;
  type sql_list_t is table of varchar2(32767) index by pls_integer;&lt;br /&gt;
  type idx_list_t is table of user_indexes.index_name%type index by pls_integer;&lt;br /&gt;
  type col_list_t is table of user_tab_columns%rowtype index by pls_integer;&lt;br /&gt;
  --&lt;br /&gt;
  lv_col_cnt   pls_integer := 0;&lt;br /&gt;
  lv_idx_cnt   pls_integer := 0;&lt;br /&gt;
  lv_char_set  pls_integer := 0; &lt;br /&gt;
  lv_user      user_users.username%type;&lt;br /&gt;
  lv_sql_stmt  varchar2(32767);&lt;br /&gt;
  lv_byte_cols col_list_t;&lt;br /&gt;
  lv_idx_names idx_list_t;&lt;br /&gt;
  lv_idx_ddls  sql_list_t;&lt;br /&gt;
  --&lt;br /&gt;
  procedure run_sql_stmt&lt;br /&gt;
  (&lt;br /&gt;
   p_sql_stmt in varchar2&lt;br /&gt;
  )&lt;br /&gt;
  as&lt;br /&gt;
  begin&lt;br /&gt;
    execute immediate p_sql_stmt;&lt;br /&gt;
  exception&lt;br /&gt;
    when others&lt;br /&gt;
    then&lt;br /&gt;
      raise_application_error(-20202, &amp;#039;Failed statement [&amp;#039; || p_sql_stmt || dbms_utility.format_error_backtrace() || &amp;#039;]&amp;#039;, true);&lt;br /&gt;
  end;&lt;br /&gt;
begin&lt;br /&gt;
  --&lt;br /&gt;
  lv_user := user();&lt;br /&gt;
  if lv_user in (&amp;#039;SYS&amp;#039;, &amp;#039;SYSTEM&amp;#039;, &amp;#039;SYSMAN&amp;#039;)&lt;br /&gt;
  then&lt;br /&gt;
    raise_application_error(-20202, &amp;#039;This script cannot be executed against Oracle built-in schema [&amp;#039; || lv_user || &amp;#039;].&amp;#039;);&lt;br /&gt;
  end if;&lt;br /&gt;
  --&lt;br /&gt;
  select&lt;br /&gt;
         *&lt;br /&gt;
         bulk collect into lv_byte_cols&lt;br /&gt;
  from&lt;br /&gt;
         user_tab_columns uc&lt;br /&gt;
  where&lt;br /&gt;
         uc.char_used = &amp;#039;B&amp;#039;&lt;br /&gt;
         and&lt;br /&gt;
         substr(uc.table_name, 1, 4) != &amp;#039;BIN$&amp;#039;&lt;br /&gt;
         and&lt;br /&gt;
         not exists&lt;br /&gt;
         (&lt;br /&gt;
          select 1&lt;br /&gt;
          from   user_views uv&lt;br /&gt;
          where  uv.view_name = uc.table_name&lt;br /&gt;
         )&lt;br /&gt;
  ;&lt;br /&gt;
  --&lt;br /&gt;
  lv_col_cnt := lv_byte_cols.count();&lt;br /&gt;
  --&lt;br /&gt;
  dbms_output.enable();&lt;br /&gt;
  --&lt;br /&gt;
  if lv_col_cnt &amp;gt; 0&lt;br /&gt;
  then&lt;br /&gt;
    for idx_rw in&lt;br /&gt;
    (&lt;br /&gt;
     select index_name &lt;br /&gt;
     from   user_indexes&lt;br /&gt;
     where  index_type = &amp;#039;FUNCTION-BASED NORMAL&amp;#039;&lt;br /&gt;
    )&lt;br /&gt;
    loop&lt;br /&gt;
      lv_idx_cnt := lv_idx_cnt + 1;&lt;br /&gt;
      lv_idx_names(lv_idx_cnt) := idx_rw.index_name;&lt;br /&gt;
      lv_idx_ddls(lv_idx_cnt) := replace&lt;br /&gt;
                                 (&lt;br /&gt;
                                  dbms_metadata.get_ddl&lt;br /&gt;
                                  (&lt;br /&gt;
                                   object_type =&amp;gt; &amp;#039;INDEX&amp;#039;,&lt;br /&gt;
                                   name        =&amp;gt; idx_rw.index_name&lt;br /&gt;
                                  )&lt;br /&gt;
                                  ,&lt;br /&gt;
                                  &amp;#039;;&amp;#039;&lt;br /&gt;
                                 );&lt;br /&gt;
      lv_sql_stmt := &amp;#039;drop index &amp;#039; || idx_rw.index_name;&lt;br /&gt;
      run_sql_stmt(lv_sql_stmt);&lt;br /&gt;
      dbms_output.put_line(&amp;#039;Dropped function-based index: &amp;#039; || idx_rw.index_name);&lt;br /&gt;
      dbms_output.put_line(&amp;#039;In case of script failure, restore the index by running the DDL statement below:&amp;#039;);&lt;br /&gt;
      dbms_output.put_line(lv_idx_ddls(lv_idx_cnt) || &amp;#039;;&amp;#039;);&lt;br /&gt;
    end loop;&lt;br /&gt;
    --&lt;br /&gt;
    for i in 1..lv_col_cnt&lt;br /&gt;
    loop&lt;br /&gt;
      lv_sql_stmt :=  &amp;#039;alter table &amp;#039; || lv_byte_cols(i).table_name || &amp;#039; modify (&amp;#039; ||&lt;br /&gt;
                      lv_byte_cols(i).column_name || &amp;#039; &amp;#039; || lv_byte_cols(i).data_type ||&lt;br /&gt;
                      &amp;#039;(&amp;#039; || lv_byte_cols(i).char_length || &amp;#039; char))&amp;#039;;&lt;br /&gt;
      run_sql_stmt(lv_sql_stmt);&lt;br /&gt;
    end loop;&lt;br /&gt;
    --&lt;br /&gt;
    dbms_output.new_line();&lt;br /&gt;
    for i in 1..lv_idx_cnt&lt;br /&gt;
    loop&lt;br /&gt;
      run_sql_stmt(lv_idx_ddls(i));&lt;br /&gt;
      dbms_output.put_line(&amp;#039;Recreated function-based index: &amp;#039; || lv_idx_names(i));&lt;br /&gt;
    end loop;&lt;br /&gt;
    --&lt;br /&gt;
    dbms_output.new_line();&lt;br /&gt;
    dbms_output.put_line&lt;br /&gt;
    (&lt;br /&gt;
     &amp;#039;Updated length semantics to CHAR for &amp;#039; || lv_col_cnt || &amp;#039; column&amp;#039; ||&lt;br /&gt;
     case when lv_col_cnt &amp;gt; 1&lt;br /&gt;
          then &amp;#039;s&amp;#039;&lt;br /&gt;
     end ||&lt;br /&gt;
     &amp;#039; in the schema [&amp;#039; || lv_user || &amp;#039;].&amp;#039;&lt;br /&gt;
    );&lt;br /&gt;
  else&lt;br /&gt;
    dbms_output.put_line(&amp;#039;No columns with BYTE length semantics were found in the schema [&amp;#039; || lv_user || &amp;#039;].&amp;#039;);&lt;br /&gt;
  end if;&lt;br /&gt;
  --&lt;br /&gt;
  select count(*) into lv_char_set&lt;br /&gt;
  from   nls_session_parameters&lt;br /&gt;
  where  parameter = &amp;#039;NLS_LENGTH_SEMANTICS&amp;#039;&lt;br /&gt;
         and&lt;br /&gt;
         value = &amp;#039;CHAR&amp;#039;&lt;br /&gt;
  ;&lt;br /&gt;
  --&lt;br /&gt;
  if lv_char_set = 0&lt;br /&gt;
  then&lt;br /&gt;
    dbms_output.put_line(&amp;#039;WARNING: Do not forget to change instance parameter NLS_LENGTH_SEMANTICS to CHAR and restart the database.&amp;#039;);&lt;br /&gt;
  end if;&lt;br /&gt;
end;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORA-14097: column type or size mismatch in ALTER TABLE EXCHANGE PARTITION===&lt;br /&gt;
Also can be &amp;lt;tt&amp;gt;ORA-54033: column to be modified is used in a virtual column expression&amp;lt;/tt&amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;
Nothing especially to do with partitions - just any ddl operation that affects the table.&amp;lt;br /&amp;gt;&lt;br /&gt;
Hidden columns do not normally show up in a desc unless colinvisible is on&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set colinvisible on&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
But these sneaky system-generated ones don&amp;#039;t show up even with that setting on!  You need to show them with this:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set pages 50 lines 1000&lt;br /&gt;
col column_name for a40&lt;br /&gt;
col data_default for a40&lt;br /&gt;
select internal_column_id, column_name, data_default, hidden_column, virtual_column from dba_tab_cols where table_name =&amp;#039;XND40&amp;#039;;&lt;br /&gt;
&lt;br /&gt;
INTERNAL_COLUMN_ID COLUMN_NAME                                        DATA_DEFAULT                                       HIDDEN_COLUM VIRTUAL_COLU&lt;br /&gt;
------------------ -------------------------------------------------- -------------------------------------------------- ------------ ------------&lt;br /&gt;
                35 MONLOT_REC_CDR                                     &amp;#039;0&amp;#039;                                                NO           NO&lt;br /&gt;
                34 MONLOT_REC_DBT                                     &amp;#039;0&amp;#039;                                                NO           NO&lt;br /&gt;
                33 MONLOT_CAL_CDR                                     &amp;#039;0&amp;#039;                                                NO           NO&lt;br /&gt;
                32 MONLOT_CAL_DBT                                     &amp;#039;0&amp;#039;                                                NO           NO&lt;br /&gt;
                31 MONMVT_CPT                                         &amp;#039;0&amp;#039;                                                NO           NO&lt;br /&gt;
                30 SENNOT                                             &amp;#039; &amp;#039;                                                NO           NO&lt;br /&gt;
                29 NUMSEQ                                                                                                NO           NO&lt;br /&gt;
                28 NOMFIC                                                                                                NO           NO&lt;br /&gt;
                27 TOTCPT_REC                                                                                            NO           NO&lt;br /&gt;
                26 TOTCPT_CAL                                                                                            NO           NO&lt;br /&gt;
                25 MONLOT_REC                                                                                            NO           NO&lt;br /&gt;
                24 MONLOT_CAL                                                                                            NO           NO&lt;br /&gt;
                23 NBRELE_REC                                                                                            NO           NO&lt;br /&gt;
                22 NBRELE_CAL                                                                                            NO           NO&lt;br /&gt;
                21 NUMCPT_GLO                                                                                            NO           NO&lt;br /&gt;
                20 DEVLOT                                                                                                NO           NO&lt;br /&gt;
                19 CODERR                                                                                                NO           NO&lt;br /&gt;
                18 CANLOT                                                                                                NO           NO&lt;br /&gt;
                17 REFTEX                                                                                                NO           NO&lt;br /&gt;
                16 REFEXN                                                                                                NO           NO&lt;br /&gt;
                15 ETTLOT                                                                                                NO           NO&lt;br /&gt;
                14 TYPLOT                                                                                                NO           NO&lt;br /&gt;
                13 DATEXC                                                                                                NO           NO&lt;br /&gt;
                12 STALOT                                                                                                NO           NO&lt;br /&gt;
                11 REFLOT                                                                                                NO           NO&lt;br /&gt;
                10 USRAUT                                                                                                NO           NO&lt;br /&gt;
                 9 HEUAUT                                                                                                NO           NO&lt;br /&gt;
                 8 DATAUT                                                                                                NO           NO&lt;br /&gt;
                 7 PGMMAJ                                                                                                NO           NO&lt;br /&gt;
                 6 USRMAJ                                                                                                NO           NO&lt;br /&gt;
                 5 HEUMAJ                                                                                                NO           NO&lt;br /&gt;
                 4 DATMAJ                                                                                                NO           NO&lt;br /&gt;
                 3 DATCRT                                                                                                NO           NO&lt;br /&gt;
                 2 REFMAJ                                                                                                NO           NO&lt;br /&gt;
                 1 NUMVER                                                                                                NO           NO&lt;br /&gt;
                36 SYS_STS#KR2WNV5L070XKV1L5H7REH                     SYS_OP_COMBINED_HASH(&amp;quot;NOMFIC&amp;quot;,&amp;quot;NUMSEQ&amp;quot;)            YES          YES&lt;br /&gt;
&lt;br /&gt;
36 rows selected.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
That last row means extended statistics have been generated for 2 columns in this table.&amp;lt;br /&amp;gt;&lt;br /&gt;
You can see this because the name begins with SYS_STS. If it begins with SYS_&amp;lt;something else&amp;gt; then it is not extended statistics.&amp;lt;br /&amp;gt;&lt;br /&gt;
It may be an unused column. Original [https://dba.stackexchange.com/questions/196248/what-is-the-sys-c00054-140314103403-column-in-my-regular-oracle-table here]&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
create table t1 as select * from dba_roles;&lt;br /&gt;
&lt;br /&gt;
Table created.&lt;br /&gt;
&lt;br /&gt;
desc t1&lt;br /&gt;
 Name                                      Null?    Type&lt;br /&gt;
 ----------------------------------------- -------- ----------------------------&lt;br /&gt;
 ROLE                                      NOT NULL VARCHAR2(30)&lt;br /&gt;
 PASSWORD_REQUIRED                                  VARCHAR2(8)&lt;br /&gt;
 AUTHENTICATION_TYPE                                VARCHAR2(11)&lt;br /&gt;
&lt;br /&gt;
alter table t1 set unused (AUTHENTICATION_TYPE);&lt;br /&gt;
&lt;br /&gt;
Table altered.&lt;br /&gt;
&lt;br /&gt;
desc t1&lt;br /&gt;
 Name                                      Null?    Type&lt;br /&gt;
 ----------------------------------------- -------- ----------------------------&lt;br /&gt;
 ROLE                                      NOT NULL VARCHAR2(30)&lt;br /&gt;
 PASSWORD_REQUIRED                                  VARCHAR2(8)&lt;br /&gt;
&lt;br /&gt;
select column_name from dba_tab_cols where owner = &amp;#039;&amp;amp;owner.&amp;#039; and table_name = &amp;#039;&amp;amp;table_name.&amp;#039;;&lt;br /&gt;
&lt;br /&gt;
COLUMN_NAME&lt;br /&gt;
------------------------------&lt;br /&gt;
SYS_C00003_18012517:25:39$&lt;br /&gt;
PASSWORD_REQUIRED&lt;br /&gt;
ROLE&lt;br /&gt;
&lt;br /&gt;
SQL&amp;gt; alter table t1 drop unused columns;&lt;br /&gt;
&lt;br /&gt;
Table altered.&lt;br /&gt;
&lt;br /&gt;
select column_name from dba_tab_cols where owner = &amp;#039;&amp;amp;owner.&amp;#039; and table_name = &amp;#039;&amp;amp;table_name.&amp;#039;;&lt;br /&gt;
&lt;br /&gt;
COLUMN_NAME&lt;br /&gt;
------------------------------&lt;br /&gt;
PASSWORD_REQUIRED&lt;br /&gt;
ROLE&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Solution====&lt;br /&gt;
Drop the extended stats, do what you need to do and recreate the extended stats.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
PROCEDURE DROP_EXTENDED_STATS&lt;br /&gt;
 Argument Name                  Type                    In/Out Default?&lt;br /&gt;
 ------------------------------ ----------------------- ------ --------&lt;br /&gt;
 OWNNAME                        VARCHAR2                IN&lt;br /&gt;
 TABNAME                        VARCHAR2                IN&lt;br /&gt;
 EXTENSION                      VARCHAR2                IN&lt;br /&gt;
&lt;br /&gt;
exec dbms_stats.drop_extended_stats ( &amp;#039;KPK&amp;#039;, &amp;#039;XND40&amp;#039;, &amp;#039;(&amp;quot;NOMFIC&amp;quot;,&amp;quot;NUMSEQ&amp;quot;)&amp;#039; );&lt;br /&gt;
&lt;br /&gt;
create table kpk.xnd40_new as select * from kpk.xnd40 where 1=2;&lt;br /&gt;
&lt;br /&gt;
Table created.&lt;br /&gt;
&lt;br /&gt;
select dbms_stats.create_extended_stats ( &amp;#039;KPK&amp;#039;, &amp;#039;XND40&amp;#039;, &amp;#039;(&amp;quot;NOMFIC&amp;quot;,&amp;quot;NUMSEQ&amp;quot;)&amp;#039; ) from   dual;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The stats columns can also be seen in their own table&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 1000 pages 100&lt;br /&gt;
col owner for a6&lt;br /&gt;
col table_name for a20&lt;br /&gt;
col extension_name  for a40&lt;br /&gt;
col extension  for a50&lt;br /&gt;
select owner, table_name, extension_name, extension, creator, droppable from dba_stat_extensions where owner = upper(&amp;#039;&amp;amp;&amp;amp;owner.&amp;#039;) and table_name = upper(&amp;#039;&amp;amp;&amp;amp;table_name.&amp;#039;) and extension_name LIKE &amp;#039;SYS_STS%&amp;#039;;&lt;br /&gt;
&lt;br /&gt;
OWNER TABLE_NAME           EXTENSION_NAME                           EXTENSION                                          CREATOR                  DROPPABLE&lt;br /&gt;
----- -------------------- ---------------------------------------- -------------------------------------------------- ------------------------ ------------&lt;br /&gt;
KPK   XMD01                SYS_STSOA4UXZDBW7MIV5OOR8VOHHK           (&amp;quot;DATCRT&amp;quot;,&amp;quot;CODJRN&amp;quot;)                                SYSTEM                   YES&lt;br /&gt;
KPK   XDD02                SYS_STSFJCZYRZBCQL820ADIR0Y4RZ           (&amp;quot;REFMSG&amp;quot;,&amp;quot;CPTTIT&amp;quot;,&amp;quot;TYPMSG&amp;quot;)                       SYSTEM                   YES&lt;br /&gt;
KPK   XCD09                SYS_STS2OIO647GN0_UV$XO583KKKJ           (&amp;quot;DATCRT&amp;quot;,&amp;quot;HEUMAJ&amp;quot;,&amp;quot;STAMOD&amp;quot;)                       SYSTEM                   YES&lt;br /&gt;
KPK   XCD09                SYS_STS_BRDODC6DJG_HXK0#O9BOYF           (&amp;quot;STAMOD&amp;quot;,&amp;quot;CODMOD&amp;quot;)                                SYSTEM                   YES&lt;br /&gt;
KPK   XCD09                SYS_STS2#DY5U$WQG6COVHB##H2ESK           (&amp;quot;DATMAJ&amp;quot;,&amp;quot;STAMOD&amp;quot;,&amp;quot;CODMOD&amp;quot;)                       SYSTEM                   YES&lt;br /&gt;
KPK   XCD09                SYS_STSO7#D3DI5R8_VAF$WJ32D8MT           (&amp;quot;STAMOD&amp;quot;,&amp;quot;KEYREF_1&amp;quot;)                              SYSTEM                   YES&lt;br /&gt;
KPK   XCD09                SYS_STS4FRY10M34S2L$0FDM1N4B18           (&amp;quot;STAMOD&amp;quot;,&amp;quot;IDTMOD&amp;quot;)                                SYSTEM                   YES&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORA-14404: partitioned table contains partitions in a different tablespace===&lt;br /&gt;
As part of an RMAN duplicate with a skip tablespace, this error is produced&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Reenabling controlfile options for auxiliary database&lt;br /&gt;
Executing: alter database enable block change tracking using file &amp;#039;/oracle/acc/ora_data3/adsa1/bct_adsp_do_not_delete.f&amp;#039;&lt;br /&gt;
&lt;br /&gt;
contents of Memory Script:&lt;br /&gt;
{&lt;br /&gt;
   Alter clone database open resetlogs;&lt;br /&gt;
}&lt;br /&gt;
executing Memory Script&lt;br /&gt;
&lt;br /&gt;
database opened&lt;br /&gt;
Dropping offline and skipped tablespaces&lt;br /&gt;
Executing: drop tablespace &amp;quot;ADS_ARCHIVE&amp;quot; including contents cascade constraints&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-03002: failure of Duplicate Db command at 10/16/2017 23:46:12&lt;br /&gt;
RMAN-05501: aborting duplication of target database&lt;br /&gt;
RMAN-06136: ORACLE error from auxiliary database: ORA-14404: partitioned table contains partitions in a different tablespace&lt;br /&gt;
&lt;br /&gt;
Recovery Manager complete.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
and when attempting to backup the database, we get errors&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
RMAN-06169: could not read file header for datafile 188 error reason 1&lt;br /&gt;
RMAN-06169: could not read file header for datafile 189 error reason 1&lt;br /&gt;
RMAN-06169: could not read file header for datafile 190 error reason 1&lt;br /&gt;
RMAN-06169: could not read file header for datafile 191 error reason 1&lt;br /&gt;
RMAN-06169: could not read file header for datafile 14 error reason 1&lt;br /&gt;
released channel: t1&lt;br /&gt;
released channel: t2&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-03002: failure of backup plus archivelog command at 10/17/2017 15:08:40&lt;br /&gt;
RMAN-06056: could not access datafile 14&lt;br /&gt;
&lt;br /&gt;
Recovery Manager complete.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Problem====&lt;br /&gt;
Tables in the tablespace have partitions in another tablespace so this one cannot be dropped.&amp;lt;br /&amp;gt;&lt;br /&gt;
Check which table partitions are in which tablespaces&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 200&lt;br /&gt;
set pagesize 200&lt;br /&gt;
col table_name for a14&lt;br /&gt;
col table_owner for a14&lt;br /&gt;
col partition_name for a14&lt;br /&gt;
select table_owner&lt;br /&gt;
,      table_name&lt;br /&gt;
,      partition_name&lt;br /&gt;
,      tablespace_name&lt;br /&gt;
from   dba_tab_partitions&lt;br /&gt;
where  (table_owner, table_name) in&lt;br /&gt;
       (&lt;br /&gt;
       select table_owner&lt;br /&gt;
       ,      table_name&lt;br /&gt;
       from   dba_tab_partitions x&lt;br /&gt;
       where  x.tablespace_name = &amp;#039;&amp;amp;&amp;amp;TABLESPACE_TO_DROP&amp;#039;&lt;br /&gt;
       and    exists ( select *&lt;br /&gt;
                       from   dba_tab_partitions y&lt;br /&gt;
                       where  x.table_owner = y.table_owner&lt;br /&gt;
                       and    x.table_name  = y.table_name&lt;br /&gt;
                       and    y.tablespace_name not in (&amp;#039;&amp;amp;TABLESPACE_TO_DROP&amp;#039;)&lt;br /&gt;
                       group  by table_owner&lt;br /&gt;
                       ,      table_name&lt;br /&gt;
                     )&lt;br /&gt;
        )&lt;br /&gt;
order by 1,2,partition_position&lt;br /&gt;
/&lt;br /&gt;
undef TABLESPACE_TO_DROP&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
TABLE_OWNER    TABLE_NAME     PARTITION_NAME TABLESPACE_NAME&lt;br /&gt;
-------------- -------------- -------------- ------------------------------&lt;br /&gt;
KPK            XND20          P0910          TS_THALER_PART_OLD&lt;br /&gt;
KPK            XND20          P1112          TS_THALER_PART_OLD&lt;br /&gt;
KPK            XND20          P13            TS_THALER_PART_OLD&lt;br /&gt;
KPK            XND20          P14            TS_THALER_PART_OLD&lt;br /&gt;
KPK            XND20          P15            TS_THALER_PART_OLD&lt;br /&gt;
KPK            XND20          P16            TS_THALER_DATA&lt;br /&gt;
KPK            XND20          P17            TS_THALER_DATA&lt;br /&gt;
KPK            XND20          P18            TS_THALER_DATA&lt;br /&gt;
KPK            XND20          PMAX           TS_THALER_DATA&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Solution====&lt;br /&gt;
If the intention is to keep all the tables then run this query to generate statements to move the relevant tables out of this tablespace&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select &amp;#039;alter table &amp;#039;||b.table_owner||&amp;#039;.&amp;#039;||b.table_name||&amp;#039; move partition &amp;#039;||b.partition_name||&amp;#039; tablespace &amp;amp;NEW_TABLESPACE;&amp;#039;&lt;br /&gt;
from   (&lt;br /&gt;
       select distinct table_name&lt;br /&gt;
       ,      partition_name&lt;br /&gt;
       from   dba_tab_partitions&lt;br /&gt;
       where  tablespace_name = &amp;#039;&amp;amp;&amp;amp;TABLESPACE_NAME&amp;#039;&lt;br /&gt;
       )                  a&lt;br /&gt;
,      dba_tab_partitions b&lt;br /&gt;
where  a.table_name       = b.table_name&lt;br /&gt;
and    b.tablespace_name != &amp;#039;&amp;amp;TABLESPACE_NAME&amp;#039;&lt;br /&gt;
/&lt;br /&gt;
undef TABLESPACE_NAME&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
If however, the intention is to drop the tablespace anyway, the tables need to be dropped before the tablespace can be dropped.&amp;lt;br /&amp;gt;&lt;br /&gt;
But ...tables with partitions in different tablespaces cannot be dropped. The partitions need to be dropped first!&amp;lt;br /&amp;gt;&lt;br /&gt;
Run the following query to generate statements to drop all the &amp;#039;problem&amp;#039; tables. When these have gone, the tablespace can be dropped.&lt;br /&gt;
* drop table partitions&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
spool /tmp/drop_table_partitions.sql&lt;br /&gt;
sqlplus / as sysdba&amp;lt;&amp;lt;EOSQL&lt;br /&gt;
set headi off newpa none feedb off trims on echo off&lt;br /&gt;
select &amp;#039;alter table &amp;#039;||table_owner||&amp;#039;.&amp;#039;||table_name||&amp;#039; drop partition &amp;#039;||partition_name||&amp;#039;;&amp;#039;&lt;br /&gt;
from   dba_tab_partitions&lt;br /&gt;
where  tablespace_name = &amp;#039;$TABLESPACE_NAME&amp;#039;&lt;br /&gt;
/&lt;br /&gt;
spool off&lt;br /&gt;
EOSQL&lt;br /&gt;
echo &amp;quot;@/tmp/drop_table_partitions.sql&amp;quot; | sqlplus / as sysdba&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* drop tables&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sqlplus / as sysdba&amp;lt;&amp;lt;EOSQL&lt;br /&gt;
select &amp;#039;drop table &amp;#039;||table_owner||&amp;#039;.&amp;#039;||table_name||&amp;#039;;&amp;#039;&lt;br /&gt;
from   dba_tab_partitions&lt;br /&gt;
where  tablespace_name = &amp;#039;$TABLESPACE_NAME&amp;#039;&lt;br /&gt;
spool /tmp/drop_tables.sql&lt;br /&gt;
/&lt;br /&gt;
spool off&lt;br /&gt;
EOSQL&lt;br /&gt;
echo &amp;quot;@/tmp/drop_tables.sql&amp;quot; | sqlplus / as sysdba&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* drop tablespace&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
drop tablespace ads_archive including contents and datafiles&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Find all table partitions in tablespaces with missing datafiles====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 1000 pages 100&lt;br /&gt;
col owner for a10&lt;br /&gt;
col segment_name for a40&lt;br /&gt;
col segment_type for a25&lt;br /&gt;
col partition_name for a20&lt;br /&gt;
col tablespace_name for a25&lt;br /&gt;
select owner&lt;br /&gt;
,      segment_name&lt;br /&gt;
,      segment_type&lt;br /&gt;
,      partition_name&lt;br /&gt;
,      tablespace_name&lt;br /&gt;
from   dba_segments&lt;br /&gt;
where  segment_type in (&amp;#039;TABLE PARTITION&amp;#039;, &amp;#039;TABLE SUBPARTITION&amp;#039;)&lt;br /&gt;
and    tablespace_name in (&lt;br /&gt;
                          select tablespace_name&lt;br /&gt;
                          from   dba_data_files&lt;br /&gt;
                          where  file_name like &amp;#039;%MISSING%&amp;#039;&lt;br /&gt;
                          )&lt;br /&gt;
order  by 1, 2, decode (segment_type, &amp;#039;TABLE SUBPARTITION&amp;#039;, 1, 2),4&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Use exchange partition to alter metadata of the tablespaces without moving the actual data====&lt;br /&gt;
* [https://community.oracle.com/message/2166242#2166242 this] is an explanation of what you are looking for!&amp;lt;br /&amp;gt;&lt;br /&gt;
This is a way of doing the exchange with a neat PL/SQL procedure. It might not do what you want though so understand it before running it!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set serveroutput on size unlimited&lt;br /&gt;
DECLARE&lt;br /&gt;
  dummy_table                   VARCHAR2 (128);&lt;br /&gt;
  cmd                           VARCHAR2 (2048);&lt;br /&gt;
  currowner                     dba_part_tables.owner%TYPE;&lt;br /&gt;
  currtable                     dba_part_tables.table_name%TYPE;&lt;br /&gt;
  l_subpartitioning_type        dba_part_tables.subpartitioning_type%TYPE;&lt;br /&gt;
  l_def_subpartition_count      dba_part_tables.def_subpartition_count%TYPE;&lt;br /&gt;
  l_subpartitioning_key_count   dba_part_tables.subpartitioning_key_count%TYPE;&lt;br /&gt;
  l_curr_qual_table             VARCHAR2 (128);&lt;br /&gt;
&lt;br /&gt;
  PROCEDURE execsql (p_sql IN VARCHAR2)&lt;br /&gt;
  IS&lt;br /&gt;
  BEGIN&lt;br /&gt;
    DBMS_OUTPUT.put_line (p_sql); &lt;br /&gt;
    EXECUTE IMMEDIATE p_sql;&lt;br /&gt;
  END;&lt;br /&gt;
 &lt;br /&gt;
  PROCEDURE force_drop_table (p_table_name IN VARCHAR2)&lt;br /&gt;
  IS&lt;br /&gt;
  BEGIN&lt;br /&gt;
    execsql (&amp;#039;drop table &amp;#039; || p_table_name || &amp;#039; purge&amp;#039;);&lt;br /&gt;
  EXCEPTION&lt;br /&gt;
    WHEN OTHERS&lt;br /&gt;
    THEN&lt;br /&gt;
      NULL;&lt;br /&gt;
  END;&lt;br /&gt;
 &lt;br /&gt;
  PROCEDURE exchange_partition (p_from_table       IN VARCHAR2,&lt;br /&gt;
                                p_from_partition   IN VARCHAR2,&lt;br /&gt;
                                p_to_table         IN VARCHAR2)&lt;br /&gt;
  IS&lt;br /&gt;
  BEGIN&lt;br /&gt;
    execsql (&lt;br /&gt;
         &amp;#039;alter table &amp;#039;&lt;br /&gt;
      || p_from_table&lt;br /&gt;
      || &amp;#039; exchange partition &amp;#039;&lt;br /&gt;
      || p_from_partition&lt;br /&gt;
      || &amp;#039; with table &amp;#039;&lt;br /&gt;
      || p_to_table&lt;br /&gt;
      || &amp;#039; excluding indexes&amp;#039;);&lt;br /&gt;
  END;&lt;br /&gt;
 &lt;br /&gt;
  PROCEDURE drop_partition (p_table IN VARCHAR2, p_partition IN VARCHAR2)&lt;br /&gt;
  IS&lt;br /&gt;
  BEGIN&lt;br /&gt;
    execsql (&amp;#039;alter table &amp;#039; || p_table || &amp;#039; drop partition &amp;#039; || p_partition);&lt;br /&gt;
  END;&lt;br /&gt;
BEGIN&lt;br /&gt;
  currowner := &amp;#039;.&amp;#039;;&lt;br /&gt;
  currtable := &amp;#039;.&amp;#039;;&lt;br /&gt;
 &lt;br /&gt;
  FOR asegment&lt;br /&gt;
    IN (  SELECT owner,&lt;br /&gt;
                 segment_name,&lt;br /&gt;
                 segment_type,&lt;br /&gt;
                 partition_name&lt;br /&gt;
            FROM dba_segments&lt;br /&gt;
           WHERE     segment_type IN (&amp;#039;TABLE PARTITION&amp;#039;, &amp;#039;TABLE SUBPARTITION&amp;#039;)&lt;br /&gt;
                 AND tablespace_name IN (SELECT tablespace_name&lt;br /&gt;
                                           FROM dba_data_files&lt;br /&gt;
                                          WHERE file_name LIKE &amp;#039;%MISSING%&amp;#039;)&lt;br /&gt;
        ORDER BY 1,&lt;br /&gt;
                 2,&lt;br /&gt;
                 DECODE (segment_type, &amp;#039;TABLE SUBPARTITION&amp;#039;, 1, 2),&lt;br /&gt;
                 4)&lt;br /&gt;
  LOOP&lt;br /&gt;
    BEGIN&lt;br /&gt;
      IF currowner &amp;lt;&amp;gt; asegment.owner OR currtable &amp;lt;&amp;gt; asegment.segment_name&lt;br /&gt;
      THEN&lt;br /&gt;
        currowner := asegment.owner;&lt;br /&gt;
        currtable := asegment.segment_name;&lt;br /&gt;
        l_curr_qual_table := asegment.owner || &amp;#039;.&amp;#039; || asegment.segment_name;&lt;br /&gt;
        dummy_table := asegment.owner || &amp;#039;.TBR_EXCHANGE_DUMMY&amp;#039;;&lt;br /&gt;
 &lt;br /&gt;
        force_drop_table (dummy_table);&lt;br /&gt;
 &lt;br /&gt;
        IF asegment.segment_type = &amp;#039;TABLE SUBPARTITION&amp;#039;&lt;br /&gt;
        THEN&lt;br /&gt;
          cmd := &amp;#039;create table &amp;#039; || dummy_table || &amp;#039; partition by &amp;#039;;&lt;br /&gt;
 &lt;br /&gt;
          SELECT subpartitioning_type,&lt;br /&gt;
                 def_subpartition_count,&lt;br /&gt;
                 subpartitioning_key_count&lt;br /&gt;
            INTO l_subpartitioning_type,&lt;br /&gt;
                 l_def_subpartition_count,&lt;br /&gt;
                 l_subpartitioning_key_count&lt;br /&gt;
            FROM dba_part_tables&lt;br /&gt;
           WHERE     owner = asegment.owner&lt;br /&gt;
                 AND table_name = asegment.segment_name;&lt;br /&gt;
 &lt;br /&gt;
          cmd := cmd || l_subpartitioning_type || &amp;#039;(&amp;#039;;&lt;br /&gt;
 &lt;br /&gt;
          FOR asubpartkey&lt;br /&gt;
            IN (  SELECT column_position, column_name&lt;br /&gt;
                    FROM dba_subpart_key_columns&lt;br /&gt;
                   WHERE     owner = asegment.owner&lt;br /&gt;
                         AND name = asegment.segment_name&lt;br /&gt;
                         AND object_type = &amp;#039;TABLE&amp;#039;&lt;br /&gt;
                ORDER BY column_position)&lt;br /&gt;
          LOOP&lt;br /&gt;
            IF asubpartkey.column_position &amp;gt; 1&lt;br /&gt;
            THEN&lt;br /&gt;
              cmd := cmd || &amp;#039;,&amp;#039;;&lt;br /&gt;
            END IF;&lt;br /&gt;
 &lt;br /&gt;
            cmd := cmd || asubpartkey.column_name;&lt;br /&gt;
          END LOOP;&lt;br /&gt;
 &lt;br /&gt;
          cmd := cmd || &amp;#039;) partitions (&amp;#039;;&lt;br /&gt;
 &lt;br /&gt;
          FOR partnr IN 1 .. l_def_subpartition_count&lt;br /&gt;
          LOOP&lt;br /&gt;
            IF partnr &amp;gt; 1&lt;br /&gt;
            THEN&lt;br /&gt;
              cmd := cmd || &amp;#039;,&amp;#039;;&lt;br /&gt;
            END IF;&lt;br /&gt;
 &lt;br /&gt;
            cmd := cmd || &amp;#039;partition p&amp;#039; || partnr;&lt;br /&gt;
          END LOOP;&lt;br /&gt;
 &lt;br /&gt;
          cmd :=&lt;br /&gt;
            cmd || &amp;#039;) as select * from &amp;#039; || l_curr_qual_table || &amp;#039; where 1=0&amp;#039;;&lt;br /&gt;
          execsql (cmd);&lt;br /&gt;
        ELSE&lt;br /&gt;
          execsql (&lt;br /&gt;
               &amp;#039;create table &amp;#039;&lt;br /&gt;
            || dummy_table&lt;br /&gt;
            || &amp;#039; as select * from &amp;#039;&lt;br /&gt;
            || l_curr_qual_table&lt;br /&gt;
            || &amp;#039; where 1=0&amp;#039;);&lt;br /&gt;
        END IF;&lt;br /&gt;
      END IF;&lt;br /&gt;
 &lt;br /&gt;
      exchange_partition (l_curr_qual_table,&lt;br /&gt;
                          asegment.partition_name,&lt;br /&gt;
                          dummy_table);&lt;br /&gt;
 &lt;br /&gt;
      drop_partition (l_curr_qual_table, asegment.partition_name);&lt;br /&gt;
    EXCEPTION&lt;br /&gt;
      WHEN OTHERS&lt;br /&gt;
      THEN&lt;br /&gt;
        DBMS_OUTPUT.put_line (&lt;br /&gt;
          asegment.owner || &amp;#039;.&amp;#039; || asegment.segment_name || &amp;#039; &amp;#039; || SQLERRM);&lt;br /&gt;
    END;&lt;br /&gt;
  END LOOP;&lt;br /&gt;
 &lt;br /&gt;
  IF dummy_table IS NOT NULL&lt;br /&gt;
  THEN&lt;br /&gt;
    force_drop_table (dummy_table);&lt;br /&gt;
  END IF;&lt;br /&gt;
 &lt;br /&gt;
  FOR atablespace IN (  SELECT DISTINCT tablespace_name&lt;br /&gt;
                          FROM dba_data_files&lt;br /&gt;
                         WHERE file_name LIKE &amp;#039;%MISSING%&amp;#039;&lt;br /&gt;
                      ORDER BY 1)&lt;br /&gt;
  LOOP&lt;br /&gt;
    execsql (&lt;br /&gt;
         &amp;#039;drop tablespace &amp;#039;&lt;br /&gt;
      || atablespace.tablespace_name&lt;br /&gt;
      || &amp;#039; including contents and datafiles&amp;#039;);&lt;br /&gt;
  END LOOP;&lt;br /&gt;
END;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Workaround====&lt;br /&gt;
While working on the solution, a backup can be made using the &amp;quot;skip inaccessible&amp;quot; option. Put this in an rman cmdfile...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
connect catalog rmanusr/rmanpwd@rmancat&lt;br /&gt;
connect target sys/syspwd@adsa1&lt;br /&gt;
run {&lt;br /&gt;
allocate channel t1 type &amp;#039;sbt_tape&amp;#039; parms &amp;#039;ENV=(NSR_SERVER=hn6000.company.be,NSR_CLIENT=hn491,NSR_DATA_VOLUME_POOL=DD1DAILY,NSR_END_ERROR_IGNORE=TRUE)&amp;#039;;&lt;br /&gt;
allocate channel t2 type &amp;#039;sbt_tape&amp;#039; parms &amp;#039;ENV=(NSR_SERVER=hn6000.company.be,NSR_CLIENT=hn491,NSR_DATA_VOLUME_POOL=DD1DAILY,NSR_END_ERROR_IGNORE=TRUE)&amp;#039;;&lt;br /&gt;
configure retention policy to recovery window of 28 days;&lt;br /&gt;
configure controlfile autobackup on;&lt;br /&gt;
crosscheck archivelog all;&lt;br /&gt;
SQL &amp;#039;ALTER SYSTEM SWITCH LOGFILE&amp;#039;;&lt;br /&gt;
SQL &amp;#039;CREATE PFILE FROM SPFILE&amp;#039;;&lt;br /&gt;
backup filesperset 1 format &amp;#039;dbfull_%d_%I_%t_%s_%p&amp;#039; full database plus archivelog skip inaccessible delete all input;&lt;br /&gt;
backup current controlfile;&lt;br /&gt;
release channel t1;&lt;br /&gt;
release channel t2;&lt;br /&gt;
}&lt;br /&gt;
exit&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Another way of deleting the offending objects====&lt;br /&gt;
Taken from [http://www.dbarj.com.br/en/2015/01/resume-oracle-duplicate-database-failed-recovery-datafiles/ Recover from a failed RMAN duplicate]&amp;lt;br /&amp;gt;&lt;br /&gt;
Need to check it before running it blindly!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
set echo off feed off termo off trims on pages 0 newpa none lines 2000 headi off long 32000&lt;br /&gt;
col val for a1000&lt;br /&gt;
spool destroy_offending_objects.sql&lt;br /&gt;
&lt;br /&gt;
select to_clob (&amp;#039;alter table &amp;#039;|| table_name||&amp;#039; drop constraint &amp;#039;||constraint_name||&amp;#039;;&amp;#039;) Val&lt;br /&gt;
from user_constraints where constraint_type in (&amp;#039;R&amp;#039;,&amp;#039;P&amp;#039;) and table_name in (select distinct table_name from user_tab_partitions)&lt;br /&gt;
union all&lt;br /&gt;
select to_clob (&amp;#039;drop index &amp;#039;||index_name||&amp;#039;;&amp;#039;) Val from user_indexes where table_name in (select distinct table_name from user_tab_partitions)&lt;br /&gt;
union all&lt;br /&gt;
select to_clob (&amp;#039;alter table &amp;#039;||table_name|| &amp;#039; drop partition &amp;#039;||partition_name||&amp;#039;;&amp;#039;) from dba_tab_partitions&lt;br /&gt;
where tablespace_name in (select tablespace_name from dba_data_files where file_name like &amp;#039;%MISSING%&amp;#039;)&lt;br /&gt;
union all&lt;br /&gt;
Select case&lt;br /&gt;
when instr (VAl, &amp;#039;PARTITION&amp;#039;) = 0 Then&lt;br /&gt;
substr (Val,1,InStr (Val,&amp;#039;)&amp;#039;)+1)||&amp;#039;;&amp;#039;&lt;br /&gt;
else&lt;br /&gt;
substr (Val,1,InStr (Val,&amp;#039;)&amp;#039;)+1)||&amp;#039; local;&amp;#039;&lt;br /&gt;
End val&lt;br /&gt;
from&lt;br /&gt;
(select dbms_metadata.get_ddl (&amp;#039;INDEX&amp;#039;, index_name,&amp;#039;TEST&amp;#039;) Val from user_indexes where table_name in (select distinct table_name from user_tab_partitions))&lt;br /&gt;
union all&lt;br /&gt;
Select Val&lt;br /&gt;
from&lt;br /&gt;
(select dbms_metadata.get_dependent_ddl (&amp;#039;REF_CONSTRAINT&amp;#039;, table_name,&amp;#039;TEST&amp;#039;) Val&lt;br /&gt;
from user_tables where table_name in (select distinct table_name from user_tab_partitions join user_constraints using ( table_name)&lt;br /&gt;
where constraint_type=&amp;#039;R&amp;#039;))&lt;br /&gt;
union all&lt;br /&gt;
select Val&lt;br /&gt;
from&lt;br /&gt;
(select dbms_metadata.get_ddl (&amp;#039;CONSTRAINT&amp;#039;, constraint_name,&amp;#039;TEST&amp;#039;) Val&lt;br /&gt;
from user_constraints&lt;br /&gt;
where constraint_type=&amp;#039;P&amp;#039; and table_name in (select distinct table_name from user_tab_partitions)&lt;br /&gt;
)&lt;br /&gt;
union all&lt;br /&gt;
select to_clob (val)&lt;br /&gt;
from (select distinct &amp;#039;drop tablespace &amp;#039;||tablespace_name|| &amp;#039; including contents and datafiles;&amp;#039; val&lt;br /&gt;
from dba_tab_partitions&lt;br /&gt;
where tablespace_name in (select tablespace_name from dba_data_files where file_name like &amp;#039;%MISSING%&amp;#039;)&lt;br /&gt;
);&lt;br /&gt;
&lt;br /&gt;
spoo off&lt;br /&gt;
&lt;br /&gt;
@destroy_offending_objects&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORA-28112: failed to execute policy function===&lt;br /&gt;
when exporting or importing using [[Data Pump]]&amp;lt; /br&amp;gt;&lt;br /&gt;
During expdp is accompanied by &amp;quot;&amp;#039;&amp;#039;&amp;#039;ORA-31693: Table data object &amp;quot;SYSMAN&amp;quot;.&amp;quot;MGMT_IP_REPORT_DEF&amp;quot; failed to load/unload and is being skipped due to error:&amp;#039;&amp;#039;&amp;#039;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
===Reason===&lt;br /&gt;
This happens due to audit policies being defined on the table but the policy function is defined in another schema.&lt;br /&gt;
&lt;br /&gt;
===Solution===&lt;br /&gt;
Either drop the policy after importing the table with:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
begin&lt;br /&gt;
    for rec in (select * from dba_audit_policies where object_schema = &amp;#039;SYSMAN&amp;#039;) loop&lt;br /&gt;
        dbms_fga.drop_policy(object_schema =&amp;gt; rec.object_schema,&lt;br /&gt;
                             object_name =&amp;gt; rec.object_name,&lt;br /&gt;
                             policy_name =&amp;gt; rec.policy_name);  &lt;br /&gt;
    end loop;&lt;br /&gt;
end;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or exclude the policies during export by adding this to the .par file:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
exclude=FGA_POLICY&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or even better, give the necessary grants to the exporting user...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
grant exempt access policy to impexpusr;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The sysdba role has this automatically.&lt;br /&gt;
===ORA-17629: Cannot connect to the remote database server===&lt;br /&gt;
Active duplication fails to connect even though dns connection exists in tnsnames.ora&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
Problem:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
DUPLICATE TARGET DATABASE FROM ACTIVE DATABASE DORECOVER NOFILENAMECHECK;&lt;br /&gt;
&lt;br /&gt;
RMAN-03002: failure of Duplicate Db command at 05/27/2015 12:52:24&lt;br /&gt;
RMAN-05501: aborting duplication of target database&lt;br /&gt;
RMAN-03015: error occurred in stored script Memory Script&lt;br /&gt;
RMAN-03009: failure of backup command on ORA_DISK_1 channel at 05/27/2015 12:52:23&lt;br /&gt;
ORA-17629: Cannot connect to the remote database server&lt;br /&gt;
ORA-17627: ORA-12154: TNS:could not resolve the connect identifier specified&lt;br /&gt;
&lt;br /&gt;
ORA-17629: Cannot connect to the remote database server&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
Solution:&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
Update the tnsnames.ora of both destination &amp;#039;&amp;#039;&amp;#039;and&amp;#039;&amp;#039;&amp;#039; source ORACLE_HOMEs!&lt;br /&gt;
&lt;br /&gt;
===ORA-01950: no privileges on tablespace &amp;#039;SYSAUX&amp;#039;===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
26-JUN-15 03:12:27.545: &amp;gt;&amp;gt;&amp;gt; ORA-31642: the following SQL statement fails: &lt;br /&gt;
BEGIN &amp;quot;SYS&amp;quot;.&amp;quot;DBMS_RULE_EXP_RULES&amp;quot;.SCHEMA_CALLOUT(:1,0,1,&amp;#039;12.01.00.02.00&amp;#039;); END;&lt;br /&gt;
ORA-01950: no privileges on tablespace &amp;#039;SYSAUX&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Cause:&amp;#039;&amp;#039;&amp;#039;&amp;lt;br /&amp;gt;&lt;br /&gt;
In this case, it seems SYSMAN has no rights to create objects in the SYSAUX tablespace&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Solution:&amp;#039;&amp;#039;&amp;#039;&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter user SYSMAN quota unlimited on sysaux;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
More information [https://support.oracle.com/epmos/faces/SearchDocDisplay?_adf.ctrl-state=bov7jp5pq_4&amp;amp;_afrLoop=547371065896716#SYMPTOM here]&lt;br /&gt;
&lt;br /&gt;
===ORA-39080: failed to create queues &amp;quot;KUPC$C_1_20150616165037&amp;quot; and &amp;quot;KUPC$S_1_20150616165037&amp;quot; for Data Pump job===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
expdp /&lt;br /&gt;
&lt;br /&gt;
Export: Release 11.2.0.4.0 - Production on Tue Jun 16 16:50:36 2015&lt;br /&gt;
&lt;br /&gt;
Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.&lt;br /&gt;
&lt;br /&gt;
Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production&lt;br /&gt;
With the Partitioning, OLAP, Data Mining and Real Application Testing options&lt;br /&gt;
ORA-31626: job does not exist&lt;br /&gt;
ORA-31637: cannot create job SYS_EXPORT_SCHEMA_01 for user OPS$ORAIBM&lt;br /&gt;
ORA-06512: at &amp;quot;SYS.DBMS_SYS_ERROR&amp;quot;, line 95&lt;br /&gt;
ORA-06512: at &amp;quot;SYS.KUPV$FT_INT&amp;quot;, line 798&lt;br /&gt;
[[ORA-39080: failed to create queues &amp;quot;KUPC$C_1_20150616165037&amp;quot; and &amp;quot;KUPC$S_1_20150616165037&amp;quot; for Data Pump job]]&lt;br /&gt;
ORA-06512: at &amp;quot;SYS.DBMS_SYS_ERROR&amp;quot;, line 95&lt;br /&gt;
ORA-06512: at &amp;quot;SYS.KUPC$QUE_INT&amp;quot;, line 1534&lt;br /&gt;
ORA-24002: QUEUE_TABLE SYS.AQ$KUPC$DATAPUMP_QUETAB_1 does not exist&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Cause:====&lt;br /&gt;
Possibly some or all of OLAP module has got itself deinstalled.&lt;br /&gt;
====Solution:====&lt;br /&gt;
Try:&lt;br /&gt;
* Recompiling invalid objects. @?/rdbms/admin/utlrp&lt;br /&gt;
* Reinstalling DBMS_CUBE packages by (re)running catproc.sql. @?/rdbms/admin/catproc followed by @?/rdbms/admin/utlrp&lt;br /&gt;
* Reinstalling OLAP. @?/olap/admin/olap.sql SYSAUX TEMP; But see Metalink note ID 296187.1 for full instructions.&lt;br /&gt;
* Check metalink for bugs. See ID 345198.1 and possibly ID 453796.1&lt;br /&gt;
===ORA-14063: Unusable index exists on unique/primary constraint key===&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;ORA-39083: Object type CONSTRAINT failed to create with error:&amp;#039;&amp;#039;&amp;#039;&amp;lt;br /&amp;gt;&lt;br /&gt;
During an import datapump (impdp), import failed because indexes were in error before the tables were exported. This causes the import of rows to be skipped.&amp;lt;br /&amp;gt;&lt;br /&gt;
If the export cannot be done again (having compiled the indexes), then the metadata can be imported and the indexes compiled before importing the data.&lt;br /&gt;
* Import the metadata&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cat&amp;lt;&amp;lt;EOCAT &amp;gt;impdp_adst_ads_archive_metadata.par&lt;br /&gt;
userid=&amp;#039;/ as sysdba&amp;#039;&lt;br /&gt;
dumpfile=adst_ads_archive.dmp&lt;br /&gt;
logfile=impdp_adst_ads_archive_metadata.log&lt;br /&gt;
content=metadata_only&lt;br /&gt;
EOCAT&lt;br /&gt;
&lt;br /&gt;
impdp parfile=impdp_adst_ads_archive_metadata.par&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Find the bad indexes and recompile them&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select &amp;#039;alter index &amp;#039;|| owner||&amp;#039;.&amp;#039;||index_name||&amp;#039; rebuild online parallel 8;&amp;#039;&lt;br /&gt;
from   dba_indexes&lt;br /&gt;
where  status = &amp;#039;UNUSABLE&amp;#039;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Import the data&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cat&amp;lt;&amp;lt;EOCAT &amp;gt;impdp_adst_ads_archive_data.par&lt;br /&gt;
userid=&amp;#039;/ as sysdba&amp;#039;&lt;br /&gt;
dumpfile=adst_ads_archive.dmp&lt;br /&gt;
logfile=impdp_adst_ads_archive_data.log&lt;br /&gt;
table_exists_action=append&lt;br /&gt;
content=data_only&lt;br /&gt;
EOCAT&lt;br /&gt;
&lt;br /&gt;
impdp parfile=impdp_adst_ads_archive_data.par&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORA-09925: Unable to create audit trail file===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SQL&amp;gt; startup nomount pfile=&amp;quot;/oracle/TRSCRP1/admin/initTRSCRP1.ora&amp;quot;&lt;br /&gt;
ORA-09925: Unable to create audit trail file&lt;br /&gt;
SVR4 Error: 2: No such file or directory&lt;br /&gt;
Additional information: 9925&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
connected to auxiliary database (not started)&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-03002: failure of Duplicate Db command at 08/29/2017 15:53:09&lt;br /&gt;
RMAN-05501: aborting duplication of target database&lt;br /&gt;
RMAN-03015: error occurred in stored script Memory Script&lt;br /&gt;
RMAN-04014: startup failed: ORA-09925: Unable to create audit trail file&lt;br /&gt;
IBM AIX RISC System/6000 Error: 2: No such file or directory&lt;br /&gt;
Additional information: 9925&lt;br /&gt;
&lt;br /&gt;
Recovery Manager complete.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Problem====&lt;br /&gt;
This will be almost certainly one of two issues. Either the directory is not writable by the id that started the instance or the directory just does not exist.&lt;br /&gt;
====Solution====&lt;br /&gt;
Note there can be a difference between what you see when you type:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
show parameter audit&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
and when you type:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
strings -a $ORACLE_HOME/dbs/spfile${ORACLE_SID}.ora | grep -i audit&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
due to someone doing an &amp;quot;alter system&amp;quot; without the &amp;quot;scope=spfile&amp;quot; or &amp;quot;scope=both&amp;quot;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SQL&amp;gt; host ls -al /oracle/TRSCRP1/admin/adump&lt;br /&gt;
SQL&amp;gt; host mkdir /oracle/TRSCRP1/admin/adump&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===ORA-09925: Unable to create audit trail file===&lt;br /&gt;
When starting SQL*Plus with no db processes running (expecting to see &amp;quot;Connected to an idle instance&amp;quot;), we get this:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ERROR:&lt;br /&gt;
ORA-09925: Unable to create audit trail file&lt;br /&gt;
IBM AIX RISC System/6000 Error: 2: No such file or directory&lt;br /&gt;
Additional information: 9925&lt;br /&gt;
ORA-01075: you are currently logged on&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Filesystem permissions are fine&lt;br /&gt;
* &amp;#039;strings spfile&amp;lt;SID&amp;gt;.ora | grep audit&amp;#039; shows the correct directory&lt;br /&gt;
* Running on AIX&lt;br /&gt;
AIX is the clue here... need to check for semaphores and locked shared memory objects&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
(0) UCLID55D oraibm@solax082:/oracle/product/11.2.0.3/bin&amp;gt; sysresv&lt;br /&gt;
&lt;br /&gt;
IPC Resources for ORACLE_SID &amp;quot;UCLID55D&amp;quot; :&lt;br /&gt;
Shared Memory:&lt;br /&gt;
ID              KEY&lt;br /&gt;
8388640         0xffffffff&lt;br /&gt;
579862561       0xffffffff&lt;br /&gt;
384827426       0x326f32e8&lt;br /&gt;
&lt;br /&gt;
Semaphores:&lt;br /&gt;
ID              KEY&lt;br /&gt;
167772287       0xf09f4914&lt;br /&gt;
Oracle Instance alive for sid &amp;quot;UCLID55D&amp;quot;&lt;br /&gt;
&lt;br /&gt;
(0) UCLID55D oraibm@solax082:/oracle/product/11.2.0.3/bin&amp;gt; ipcrm -m 8388640&lt;br /&gt;
(0) UCLID55D oraibm@solax082:/oracle/product/11.2.0.3/bin&amp;gt; ipcrm -m 579862561&lt;br /&gt;
(0) UCLID55D oraibm@solax082:/oracle/product/11.2.0.3/bin&amp;gt; ipcrm -m 384827426&lt;br /&gt;
&lt;br /&gt;
(0) UCLID55D oraibm@solax082:/oracle/product/11.2.0.3/bin&amp;gt; ipcrm -s 167772287&lt;br /&gt;
&lt;br /&gt;
(0) UCLID55D oraibm@solax082:/oracle/product/11.2.0.3/bin&amp;gt; sysresv&lt;br /&gt;
&lt;br /&gt;
IPC Resources for ORACLE_SID &amp;quot;UCLID55D&amp;quot; :&lt;br /&gt;
Shared Memory&lt;br /&gt;
ID              KEY&lt;br /&gt;
No shared memory segments used&lt;br /&gt;
Semaphores:&lt;br /&gt;
ID              KEY&lt;br /&gt;
No semaphore resources used&lt;br /&gt;
Oracle Instance not alive for sid &amp;quot;UCLID55D&amp;quot;&lt;br /&gt;
&lt;br /&gt;
(0) UCLID55D oraibm@solax082:/oracle/product/11.2.0.3/bin&amp;gt; ps -ef | grep UCLID55D&lt;br /&gt;
oraibm 3326 23776 0 14:12:05 pts/1 0:00 grep UCLID55D &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===RMAN-06023: no backup or copy of datafile 1 found to restore===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-03002: failure of Duplicate Db command at 05/16/2018 16:08:13&lt;br /&gt;
RMAN-05501: aborting duplication of target database&lt;br /&gt;
RMAN-05556: not all datafiles have backups that can be recovered to SCN 278250901080&lt;br /&gt;
RMAN-03015: error occurred in stored script Memory Script&lt;br /&gt;
RMAN-06026: some targets not found - aborting restore&lt;br /&gt;
RMAN-06023: no backup or copy of datafile 7 found to restore&lt;br /&gt;
RMAN-06023: no backup or copy of datafile 6 found to restore&lt;br /&gt;
RMAN-06023: no backup or copy of datafile 5 found to restore&lt;br /&gt;
RMAN-06023: no backup or copy of datafile 4 found to restore&lt;br /&gt;
RMAN-06023: no backup or copy of datafile 3 found to restore&lt;br /&gt;
RMAN-06023: no backup or copy of datafile 2 found to restore&lt;br /&gt;
RMAN-06023: no backup or copy of datafile 1 found to restore&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Seems pretty straightforward? SCN was set too early for the retention period. But no, not this time.&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
RMAN&amp;gt; list backup of datafile 1;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
List of Backup Sets&lt;br /&gt;
===================&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
BS Key  Type LV Size       Device Type Elapsed Time Completion Time&lt;br /&gt;
------- ---- -- ---------- ----------- ------------ -------------------&lt;br /&gt;
110170340 Incr 0  132.90G    SBT_TAPE    00:18:32     2018-05-14 01:19:40&lt;br /&gt;
        BP Key: 110170345   Status: AVAILABLE  Compressed: NO  Tag: WEEKLY_FULL&lt;br /&gt;
        Handle: 24639762_REPORTA_07t2r3uk_1_1   Media: V_17152809_77191330&lt;br /&gt;
  List of Datafiles in backup set 110170340&lt;br /&gt;
  File LV Type Ckp SCN    Ckp Time            Name&lt;br /&gt;
  ---- -- ---- ---------- ------------------- ----&lt;br /&gt;
  1    0  Incr 277998128991 2018-05-14 01:01:08 /cln/acc/ora_data3/reporta/system01.dbf&lt;br /&gt;
&lt;br /&gt;
BS Key  Type LV Size       Device Type Elapsed Time Completion Time&lt;br /&gt;
------- ---- -- ---------- ----------- ------------ -------------------&lt;br /&gt;
110355808 Incr 1  204.00M    SBT_TAPE    00:05:13     2018-05-15 01:06:22&lt;br /&gt;
        BP Key: 110355813   Status: AVAILABLE  Compressed: NO  Tag: DAILY_INCREMENTAL&lt;br /&gt;
        Handle: 24661053_REPORTA_3ft2toal_1_1   Media: V_17173010_77253424&lt;br /&gt;
  List of Datafiles in backup set 110355808&lt;br /&gt;
  File LV Type Ckp SCN    Ckp Time            Name&lt;br /&gt;
  ---- -- ---- ---------- ------------------- ----&lt;br /&gt;
  1    1  Incr 278044267395 2018-05-15 01:01:09 /cln/acc/ora_data3/reporta/system01.dbf&lt;br /&gt;
&lt;br /&gt;
BS Key  Type LV Size       Device Type Elapsed Time Completion Time&lt;br /&gt;
------- ---- -- ---------- ----------- ------------ -------------------&lt;br /&gt;
110543802 Incr 1  237.00M    SBT_TAPE    00:05:51     2018-05-16 01:07:40&lt;br /&gt;
        BP Key: 110543807   Status: AVAILABLE  Compressed: NO  Tag: DAILY_INCREMENTAL&lt;br /&gt;
        Handle: 24681602_REPORTA_6nt30cnt_1_1   Media: V_17133646_77315270&lt;br /&gt;
  List of Datafiles in backup set 110543802&lt;br /&gt;
  File LV Type Ckp SCN    Ckp Time            Name&lt;br /&gt;
  ---- -- ---- ---------- ------------------- ----&lt;br /&gt;
  1    1  Incr 278286445856 2018-05-16 01:01:50 /cln/acc/ora_data3/reporta/system01.dbf&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
SCN was only 12 hours ago with a retention of 28 days! The backup piece dated 2018-05-15 01:06:22 is clearly available and on the device type set_tape.&amp;lt;br /&amp;gt;&lt;br /&gt;
The trick here was to look back through the logs and look more closely at what the file restore message was saying...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
channel t0: starting datafile backup set restore&lt;br /&gt;
channel t0: specifying datafile(s) to restore from backup set&lt;br /&gt;
channel t0: restoring datafile 00001 to /cln/acc/ora_data3/reporta/system01.dbf             &amp;lt; &amp;lt; &amp;lt; ==============&lt;br /&gt;
channel t0: reading from backup piece dbfull_REPORTA_738887052_967580186_116_1&lt;br /&gt;
channel t2: ORA-19870: error while restoring backup piece dbfull_REPORTA_738887052_967579750_113_1&lt;br /&gt;
ORA-19507: failed to retrieve sequential file, handle=&amp;quot;dbfull_REPORTA_738887052_967579750_113_1&amp;quot;, parms=&amp;quot;&amp;quot;&lt;br /&gt;
ORA-27029: skgfrtrv: sbtrestore returned error&lt;br /&gt;
ORA-19511: non RMAN, but media manager or vendor specific failure, error text:&lt;br /&gt;
   CreateOraObject20: Job[0] thread[55116090]: Restore: GetBackupInfo() for Archive File[dbfull_REPORTA_738887052_967579750_113_1] failed.&lt;br /&gt;
ORA-0651&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
It was not the fact that it could not find the data on tape, it was that it could not save the file to the location indicated!!&lt;br /&gt;
In the RMAN DUPLICATE script, I had all the file paths redirected (a mixture of convert parameters and spfile set) to a /restore filesystem.&amp;lt;br /&amp;gt;&lt;br /&gt;
But I forgot one!&amp;lt;br /&amp;gt;&lt;br /&gt;
A handy thing to do is to search out the file paths with this to see if something is still wrong:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cd $ORACLE_HOME/dbs&lt;br /&gt;
strings -a spfile${ORACLE_SID}.ora | grep dest&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This should show any paths still not getting caught by the DUPLICATE script.&lt;br /&gt;
&lt;br /&gt;
===RMAN-06136: ORACLE error from auxiliary database: ORA-06502: PL/SQL: numeric or value error===&lt;br /&gt;
When cloning a database, the duplicate fails with this error.&lt;br /&gt;
====Problem====&lt;br /&gt;
This duplicate had no target connection but did have a catalog and auxiliary connection.&lt;br /&gt;
In the catalog (which was the catalog where the target was registerd), there was also an entry in that catalog with the same name as the auxiliary - left over from the days when these 2 instances were Primary and Standby in a Dataguard configuration.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
Datafile 414 skipped by request&lt;br /&gt;
Datafile 415 skipped by request&lt;br /&gt;
Datafile 419 skipped by request&lt;br /&gt;
Datafile 420 skipped by request&lt;br /&gt;
Datafile 421 skipped by request&lt;br /&gt;
&lt;br /&gt;
DBGSQL:     AUXILIARY&amp;gt; begin :ofname := sys.dbms_backup_restore.convertFileName( fname   =&amp;gt;   :ifname, ftype   =&amp;gt;   :iftype, osftype =&amp;gt;   TRUE); end;&lt;br /&gt;
DBGSQL:        sqlcode = 6502&lt;br /&gt;
DBGSQL:         B :ofname = NULL&lt;br /&gt;
DBGSQL:         B :ifname =&lt;br /&gt;
DBGSQL:         B :iftype = 2&lt;br /&gt;
restarting auxiliary database without server parameter file&lt;br /&gt;
Oracle instance started&lt;br /&gt;
&lt;br /&gt;
Total System Global Area   32068440064 bytes&lt;br /&gt;
&lt;br /&gt;
Fixed Size                     2262200 bytes&lt;br /&gt;
Variable Size              16978545480 bytes&lt;br /&gt;
Database Buffers           15032385536 bytes&lt;br /&gt;
Redo Buffers                  55246848 bytes&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-03002: failure of Duplicate Db command at 10/04/2017 14:50:29&lt;br /&gt;
RMAN-05501: aborting duplication of target database&lt;br /&gt;
RMAN-06136: ORACLE error from auxiliary database: ORA-06502: PL/SQL: numeric or value error&lt;br /&gt;
&lt;br /&gt;
Recovery Manager complete.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Solution====&lt;br /&gt;
Connect to the catalog and unregister the name of the auxiliary database. It shouldn&amp;#039;t be there anyway.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rman catalog rmanusr/rmanpwd@rmancat&lt;br /&gt;
&lt;br /&gt;
Recovery Manager: Release 11.2.0.4.0 - Production on Wed Oct 4 15:00:00 2017&lt;br /&gt;
&lt;br /&gt;
Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.&lt;br /&gt;
&lt;br /&gt;
connected to recovery catalog database&lt;br /&gt;
&lt;br /&gt;
RMAN&amp;gt; set dbid 4260753020;&lt;br /&gt;
&lt;br /&gt;
executing command: SET DBID&lt;br /&gt;
database name is &amp;quot;LBK&amp;quot; and DBID is 4260753020&lt;br /&gt;
&lt;br /&gt;
RMAN&amp;gt; list db_unique_name of database;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
List of Databases&lt;br /&gt;
DB Key  DB Name  DB ID            Database Role    Db_unique_name&lt;br /&gt;
------- ------- ----------------- ---------------  ------------------&lt;br /&gt;
13301587 LBK      4260753020       PRIMARY          LBK&lt;br /&gt;
13301587 LBK      4260753020       STANDBY          ACC_PERF&lt;br /&gt;
13301587 LBK      4260753020       STANDBY          LBKRO&lt;br /&gt;
&lt;br /&gt;
RMAN&amp;gt; unregister db_unique_name &amp;#039;ACC_PERF&amp;#039;;&lt;br /&gt;
&lt;br /&gt;
database db_unique_name is &amp;quot;ACC_PERF&amp;quot;, db_name is &amp;quot;LBK&amp;quot; and DBID is 4260753020&lt;br /&gt;
&lt;br /&gt;
Want to unregister the database with target db_unique_name (enter YES or NO)? YES&lt;br /&gt;
database with db_unique_name ACC_PERF unregistered from the recovery catalog&lt;br /&gt;
&lt;br /&gt;
RMAN&amp;gt; exit&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORA-39181: Only partial table data may be exported due to fine grain access control on &amp;quot;owner&amp;quot;.&amp;quot;&amp;lt;table_name&amp;gt;&amp;quot;===&lt;br /&gt;
&lt;br /&gt;
===Reason===&lt;br /&gt;
This happens when applications are designed with fine-grained access.&lt;br /&gt;
===Solution===&lt;br /&gt;
Grant the necessary privileges to the exporting user...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
grant exempt access policy to ops$oraibm;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORA-04030: out of process memory when trying to allocate 2520 bytes===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
expdp problem (ORA-04030: out of process memory when trying to allocate 2520 bytes (pga heap,koh-kghu call heap))&lt;br /&gt;
&lt;br /&gt;
select value from v$pgastat where name=&amp;#039;maximum PGA allocated&amp;#039;;&lt;br /&gt;
&lt;br /&gt;
SHOW PARAMETER TARGET&lt;br /&gt;
&lt;br /&gt;
ORA-04030: out of process memory when trying to allocate 2520 bytes (pga heap,koh-kghu call heap)&lt;br /&gt;
&lt;br /&gt;
alter system reset pga_aggregate_target scope=spfile;&lt;br /&gt;
&lt;br /&gt;
show sga&lt;br /&gt;
&lt;br /&gt;
select * from v$pgastat;&lt;br /&gt;
&lt;br /&gt;
show parameter process&lt;br /&gt;
&lt;br /&gt;
select sum(value)/1024/1024 Mb&lt;br /&gt;
from   v$sesstat s, v$statname n&lt;br /&gt;
where  1=1&lt;br /&gt;
and    n.STATISTIC# = s.STATISTIC#&lt;br /&gt;
and    name = &amp;#039;session pga memory&amp;#039;&lt;br /&gt;
&lt;br /&gt;
show parameter WORKAREA&lt;br /&gt;
&lt;br /&gt;
select value from v$pgastat where name=&amp;#039;maximum PGA allocated&amp;#039;;&lt;br /&gt;
&lt;br /&gt;
alter system set memory_max_target=10G scope=spfile;&lt;br /&gt;
&lt;br /&gt;
alter system set memory_target=3G scope=both;&lt;br /&gt;
&lt;br /&gt;
select * from v$memory_target_advice order by memory_size;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORA-04031: unable to allocate 32 bytes of shared memory (&amp;quot;shared pool&amp;quot;,&amp;quot;select name,online$,contents...&amp;quot;,&amp;quot;KGLH0^e5705bfc&amp;quot;,&amp;quot;kglHeapInitialize:temp&amp;quot;)===&lt;br /&gt;
* [https://blogs.oracle.com/db/entry/ora-4031_troubleshooting ORA-4031 Troubleshooting]&lt;br /&gt;
* [https://support.oracle.com/epmos/faces/DocumentDisplay?_afrLoop=89215376348478&amp;amp;id=396940.1&amp;amp;_afrWindowMode=0&amp;amp;_adf.ctrl-state=u1z0xcppg_4 Troubleshooting and Diagnosing ORA-4031 Error - (Doc ID 396940.1)]&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ORA-04031: unable to allocate  bytes of shared memory (&amp;quot;&amp;quot;,&amp;quot;&amp;quot;,&amp;quot;&amp;quot;,&amp;quot;&amp;quot;) &lt;br /&gt;
ORA-04031: unable to allocate 32 bytes of shared memory (&amp;quot;shared pool&amp;quot;,&amp;quot;select name,online$,contents...&amp;quot;,&amp;quot;KGLH0^e5705bfc&amp;quot;,&amp;quot;kglHeapInitialize:temp&amp;quot;) &lt;br /&gt;
Incident details in: /oracle/diag/rdbms/mape/MAPE/incident/incdir_86754/MAPE_dm00_14221536_i86754.trc &lt;br /&gt;
Wed Jul 31 20:42:50 2013 &lt;br /&gt;
Dumping diagnostic data in directory=[cdmp_20130731204250], requested by (instance=1, osid=14221536 (DM00)), summary=[incident=86753]. &lt;br /&gt;
Wed Jul 31 20:42:51 2013 &lt;br /&gt;
Sweep [inc][86754]: completed &lt;br /&gt;
Sweep [inc][86753]: completed &lt;br /&gt;
Sweep [inc2][86753]: completed &lt;br /&gt;
Wed Jul 31 20:42:57 2013 &lt;br /&gt;
Use ADRCI or Support Workbench to package the incident. &lt;br /&gt;
See Note 411.1 at My Oracle Support for error and packaging details. &lt;br /&gt;
Dumping diagnostic data in directory=[cdmp_20130731204257], requested by (instance=1, osid=14221536 (DM00)), summary=[incident=86754]. &lt;br /&gt;
Wed Jul 31 20:43:35 2013 &lt;br /&gt;
Errors in file /oracle/diag/rdbms/mape/MAPE/trace/MAPE_dw02_40567024.trc  (incident=82993): &lt;br /&gt;
ORA-04031: unable to allocate 32 bytes of shared memory (&amp;quot;shared pool&amp;quot;,&amp;quot;select order#,columns,types ...&amp;quot;,&amp;quot;KGLH0^470434f8&amp;quot;,&amp;quot;kglHeapInitialize:temp&amp;quot;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Database had already crashed so nothing to do but:&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
(0) MAPE ora@x025:/home/ora&amp;gt; sqlplus / as sysdba&lt;br /&gt;
&lt;br /&gt;
SQL*Plus: Release 11.2.0.3.0 Production on Fri Aug 2 14:26:20 2013&lt;br /&gt;
&lt;br /&gt;
Copyright (c) 1982, 2011, Oracle.  All rights reserved.&lt;br /&gt;
&lt;br /&gt;
Connected.&lt;br /&gt;
SYS@MAPE&amp;gt; alter system flush shared_pool;&lt;br /&gt;
alter system flush shared_pool&lt;br /&gt;
*&lt;br /&gt;
ERROR at line 1:&lt;br /&gt;
ORA-01012: not logged on&lt;br /&gt;
Process ID: 0&lt;br /&gt;
Session ID: 0 Serial number: 0&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
SYS@MAPE&amp;gt; shutdown abort&lt;br /&gt;
ORACLE instance shut down.&lt;br /&gt;
SYS@MAPE&amp;gt; startup&lt;br /&gt;
ORACLE instance started.&lt;br /&gt;
&lt;br /&gt;
Total System Global Area  734892032 bytes&lt;br /&gt;
Fixed Size                  2225128 bytes&lt;br /&gt;
Variable Size             398461976 bytes&lt;br /&gt;
Database Buffers          318767104 bytes&lt;br /&gt;
Redo Buffers               15437824 bytes&lt;br /&gt;
Database mounted.&lt;br /&gt;
Database opened.&lt;br /&gt;
&lt;br /&gt;
SYS@MAPE&amp;gt; show parameter pool&lt;br /&gt;
&lt;br /&gt;
NAME                                 TYPE                           VALUE&lt;br /&gt;
------------------------------------ ------------------------------ ------------------------------&lt;br /&gt;
buffer_pool_keep                     string&lt;br /&gt;
buffer_pool_recycle                  string&lt;br /&gt;
global_context_pool_size             string&lt;br /&gt;
java_pool_size                       big integer                    0&lt;br /&gt;
large_pool_size                      big integer                    0&lt;br /&gt;
olap_page_pool_size                  big integer                    0&lt;br /&gt;
shared_pool_reserved_size            big integer                    18M&lt;br /&gt;
shared_pool_size                     big integer                    208M&lt;br /&gt;
streams_pool_size                    big integer                    0&lt;br /&gt;
SYS@MAPE&amp;gt; show sga&lt;br /&gt;
&lt;br /&gt;
Total System Global Area  734892032 bytes&lt;br /&gt;
Fixed Size                  2225128 bytes&lt;br /&gt;
Variable Size             385879064 bytes&lt;br /&gt;
Database Buffers          331350016 bytes&lt;br /&gt;
Redo Buffers               15437824 bytes&lt;br /&gt;
SYS@MAPE&amp;gt; exit&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
but for reference, the causes could well be the applications running on the database are not using bind variables...&amp;lt;br /&amp;gt;&lt;br /&gt;
From [http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:528893984337 asktom.oracle.com]&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
Just to give you a tiny idea of how huge of a difference this &lt;br /&gt;
can make performance wise, you only need to run a very small &lt;br /&gt;
test:&lt;br /&gt;
&lt;br /&gt;
tkyte@TKYTE816&amp;gt; alter system flush shared_pool;&lt;br /&gt;
System altered.&lt;br /&gt;
&lt;br /&gt;
tkyte@TKYTE816&amp;gt; declare&lt;br /&gt;
  2      type rc is ref cursor;&lt;br /&gt;
  3      l_rc rc;&lt;br /&gt;
  4      l_dummy all_objects.object_name%type;&lt;br /&gt;
  5      l_start number default dbms_utility.get_time;&lt;br /&gt;
  6  begin&lt;br /&gt;
  7      for i in 1 .. 1000&lt;br /&gt;
  8      loop&lt;br /&gt;
  9          open l_rc for&lt;br /&gt;
 10          &amp;#039;select object_name&lt;br /&gt;
 11             from all_objects&lt;br /&gt;
 12            where object_id = &amp;#039; || i;&lt;br /&gt;
 13          fetch l_rc into l_dummy;&lt;br /&gt;
 14          close l_rc;&lt;br /&gt;
 15      end loop;&lt;br /&gt;
 16      dbms_output.put_line&lt;br /&gt;
 17      ( round( (dbms_utility.get_time-l_start)/100, 2 ) ||&lt;br /&gt;
 18        &amp;#039; seconds...&amp;#039; );&lt;br /&gt;
 19  end;&lt;br /&gt;
 20  /&lt;br /&gt;
14.86 seconds...&lt;br /&gt;
&lt;br /&gt;
PL/SQL procedure successfully completed.&lt;br /&gt;
&lt;br /&gt;
tkyte@TKYTE816&amp;gt; declare&lt;br /&gt;
  2      type rc is ref cursor;&lt;br /&gt;
  3      l_rc rc;&lt;br /&gt;
  4      l_dummy all_objects.object_name%type;&lt;br /&gt;
  5      l_start number default dbms_utility.get_time;&lt;br /&gt;
  6  begin&lt;br /&gt;
  7      for i in 1 .. 1000&lt;br /&gt;
  8      loop&lt;br /&gt;
  9          open l_rc for&lt;br /&gt;
 10          &amp;#039;select object_name&lt;br /&gt;
 11             from all_objects&lt;br /&gt;
 12            where object_id = :x&amp;#039;&lt;br /&gt;
 13          using i;&lt;br /&gt;
 14          fetch l_rc into l_dummy;&lt;br /&gt;
 15          close l_rc;&lt;br /&gt;
 16      end loop;&lt;br /&gt;
 17      dbms_output.put_line&lt;br /&gt;
 18      ( round( (dbms_utility.get_time-l_start)/100, 2 ) ||&lt;br /&gt;
 19        &amp;#039; seconds...&amp;#039; );&lt;br /&gt;
 20  end;&lt;br /&gt;
 21  /&lt;br /&gt;
1.27 seconds...&lt;br /&gt;
&lt;br /&gt;
PL/SQL procedure successfully completed.&lt;br /&gt;
&lt;br /&gt;
That is pretty dramatic.  The fact is that not only does this &lt;br /&gt;
execute much faster (we spent more time PARSING our queries then &lt;br /&gt;
actually EXECUTING them!) it will let more users use your system &lt;br /&gt;
simultaneously.&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
and from [http://asktom.oracle.com/pls/asktom/f?p=100:11:::::P11_QUESTION_ID:1163635055580 linked question]&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
Lbrary cache latch contention is typically caused by NOT using bind variables.  It is due &lt;br /&gt;
to excessive parsing of statements.&lt;br /&gt;
&lt;br /&gt;
One way to see if this might be the case in your situation is to run a script like:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
create table t1 as select sql_text from v$sqlarea;&lt;br /&gt;
&lt;br /&gt;
alter table t1 add sql_text_wo_constants varchar2(1000);&lt;br /&gt;
&lt;br /&gt;
create or replace function &lt;br /&gt;
remove_constants( p_query in varchar2 ) return varchar2&lt;br /&gt;
as&lt;br /&gt;
    l_query long;&lt;br /&gt;
    l_char  varchar2(1);&lt;br /&gt;
    l_in_quotes boolean default FALSE;&lt;br /&gt;
begin&lt;br /&gt;
    for i in 1 .. length( p_query )&lt;br /&gt;
    loop&lt;br /&gt;
        l_char := substr(p_query,i,1);&lt;br /&gt;
        if ( l_char = &amp;#039;&amp;#039;&amp;#039;&amp;#039; and l_in_quotes )&lt;br /&gt;
        then&lt;br /&gt;
            l_in_quotes := FALSE;&lt;br /&gt;
        elsif ( l_char = &amp;#039;&amp;#039;&amp;#039;&amp;#039; and NOT l_in_quotes )&lt;br /&gt;
        then&lt;br /&gt;
            l_in_quotes := TRUE;&lt;br /&gt;
            l_query := l_query || &amp;#039;&amp;#039;&amp;#039;#&amp;#039;;&lt;br /&gt;
        end if;&lt;br /&gt;
        if ( NOT l_in_quotes ) then&lt;br /&gt;
            l_query := l_query || l_char;&lt;br /&gt;
        end if;&lt;br /&gt;
    end loop;&lt;br /&gt;
    l_query := translate( l_query, &amp;#039;0123456789&amp;#039;, &amp;#039;@@@@@@@@@@&amp;#039; );&lt;br /&gt;
    for i in 0 .. 8 loop&lt;br /&gt;
        l_query := replace( l_query, lpad(&amp;#039;@&amp;#039;,10-i,&amp;#039;@&amp;#039;), &amp;#039;@&amp;#039; );&lt;br /&gt;
        l_query := replace( l_query, lpad(&amp;#039; &amp;#039;,10-i,&amp;#039; &amp;#039;), &amp;#039; &amp;#039; );&lt;br /&gt;
    end loop;&lt;br /&gt;
    return upper(l_query);&lt;br /&gt;
end;&lt;br /&gt;
/&lt;br /&gt;
update t1 set sql_text_wo_constants = remove_constants(sql_text);&lt;br /&gt;
&lt;br /&gt;
select sql_text_wo_constants, count(*)&lt;br /&gt;
  from t1&lt;br /&gt;
 group by sql_text_wo_constants&lt;br /&gt;
having count(*) &amp;gt; 100&lt;br /&gt;
 order by 2&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The output of that last query will show you statements that are identical in the shared &lt;br /&gt;
pool after all numbers and character string constants have been removed.  These &lt;br /&gt;
statements -- and more importantly their counts -- are the potential bottlenecks.  In &lt;br /&gt;
addition to causing the contention, they will be HUGE cpu consumers.  &lt;br /&gt;
&lt;br /&gt;
If you discover your applications do not use bind variables -- you must have this &lt;br /&gt;
corrected.  You&amp;#039;ll never have a good hit ratio if everyone submits &amp;quot;unique&amp;quot; sql.  Your &lt;br /&gt;
shared pool will never be used right and you&amp;#039;ll be using excessive CPU (90% of the time &lt;br /&gt;
it takes to process &amp;quot;insert into t values ( 1 )&amp;quot; is parsing.  If you use &amp;quot;insert into t &lt;br /&gt;
values ( :x )&amp;quot;, and bind the value of 1 -- then the next person that runs that insert &lt;br /&gt;
will benefit from your work and run that much faster. &lt;br /&gt;
...&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Advice from Oracle concerning a concrete (12c) example of unable to allocate 52824 bytes of shared memory (&amp;quot;shared pool&amp;quot;,...====&lt;br /&gt;
This was from a ticket raised for a Data Pump export that consistently failed with:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Processing object type SCHEMA_EXPORT/TABLE/PROCACT_INSTANCE&lt;br /&gt;
Processing object type SCHEMA_EXPORT/TABLE/TABLE&lt;br /&gt;
ORA-39014: One or more workers have prematurely exited.&lt;br /&gt;
ORA-39029: worker 1 with process name &amp;quot;DW00&amp;quot; prematurely terminated&lt;br /&gt;
ORA-31671: Worker process DW00 had an unhandled exception.&lt;br /&gt;
ORA-04031: unable to allocate 52824 bytes of shared memory (&amp;quot;shared pool&amp;quot;,&amp;quot;unknown object&amp;quot;,&amp;quot;KTSL subheap&amp;quot;,&amp;quot;ktsl_load_disp-2&amp;quot;)&lt;br /&gt;
ORA-06512: at &amp;quot;SYS.KUPW$WORKER&amp;quot;, line 2122&lt;br /&gt;
ORA-06512: at line 2&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
The error ORA-4031 on the shared pool can indicate one of two things:&lt;br /&gt;
- insufficient space for the shared pool (so insufficient memory in SGA at that time)&lt;br /&gt;
OR&lt;br /&gt;
- although there is enough memory, it is fragmented and no contiguous chunk can be allocated to satisfy the latest memory request.&lt;br /&gt;
&lt;br /&gt;
Each SGA has a little fragmentation of course because of the operations taking place, so in your case the fragmentation is represented by the 18M of free memory, which exists in uncontiguous chunks.&lt;br /&gt;
This means that the root cause of the error is insufficient contiguous memory to allocate 12312 bytes of shared memory.&lt;br /&gt;
&lt;br /&gt;
ACTION PLAN&lt;br /&gt;
==============&lt;br /&gt;
1. We see memory_target=2000M. This is too little to support a 12c database, even when it has little activity.&lt;br /&gt;
As you may know 1.7G for the SGA was acceptable when speaking of 32bit OSs where it was hardly possible to make use of more than that.&lt;br /&gt;
Since you have a 64 bit system, the addressable memory is virtually unlimited.&lt;br /&gt;
Furthermore, by using AMM (memory_target&amp;gt;0) this memory is divided between the SGA and the PGA (the user processes) which in fact, depending on the number of connections, can limit the SGA even more.&lt;br /&gt;
So the first recommendation is to increase the value of memory_target to 4G for example. There is no ideal value, but this would be a reasonable starting value for tuning.&lt;br /&gt;
&lt;br /&gt;
You can do further tuning of the memory using the view V$MEMORY_TARGET_ADVICE.&lt;br /&gt;
The view V$MEMORY_TARGET_ADVICE provides tuning advice for the MEMORY_TARGET initialization parameter:&lt;br /&gt;
SQL&amp;gt; SELECT * FROM v$memory_target_advice ORDER BY memory_size;&lt;br /&gt;
&lt;br /&gt;
The dynamic performance view V$MEMORY_DYNAMIC_COMPONENTS shows the current sizes of all dynamically tuned memory components, including the total sizes of the SGA and instance PGA.&lt;br /&gt;
&lt;br /&gt;
You can also use V$MEMORY_RESIZE_OPS which has a circular history buffer of the last 800 memory resize requests.&lt;br /&gt;
&lt;br /&gt;
2. Since the AMM (you have memory_target&amp;gt;0) is used, then make sure to set:&lt;br /&gt;
 _shared_pool_reserved_pct to 10 or 15 to ensure that when the Shared Pool grows or shrinks automatically, the Reserved Area will change as well.&lt;br /&gt;
&lt;br /&gt;
SQL&amp;gt; alter system set &amp;quot;_shared_pool_reserved_pct&amp;quot;=15 scope=spfile;&lt;br /&gt;
--restart the instance&lt;br /&gt;
&lt;br /&gt;
FYI: By default, Oracle configures a small Reserved Pool (or Reserved Area) inside the Shared Pool.&lt;br /&gt;
This memory can be used for operations such as PL/SQL and trigger compilation or for temporary space while loading Java objects.&lt;br /&gt;
After the memory allocated from the Reserved Pool is freed, it returns to the Reserved Pool.&lt;br /&gt;
5% of the Shared Pool is set aside as the Reserved Pool to handle allocations of memory higher than defined by the hidden parameter _shared_pool_reserved_pct.&lt;br /&gt;
In some application environments, 5% is too small.&lt;br /&gt;
&lt;br /&gt;
3. Set shared_pool_size=500M or even more. This will represent a minimum amount of memory that will always be available to the shared pool.&lt;br /&gt;
If more memory is needed at any moment, if it is available, it will be allocated to the shared pool over the 500M.&lt;br /&gt;
&lt;br /&gt;
Implement the above steps, monitor the database and let us know the result,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORA-00392: log 1 of thread 1 is being cleared, operation not allowed===&lt;br /&gt;
After performing an active duplication, this happened when trying to open the database.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SQL&amp;gt; alter database open resetlogs&lt;br /&gt;
alter database open resetlogs&lt;br /&gt;
*&lt;br /&gt;
ERROR at line 1:&lt;br /&gt;
ORA-00392: log 1 of thread 1 is being cleared, operation not allowed&lt;br /&gt;
ORA-00312: online log 1 thread 1: &amp;#039;/oracle/oradata/testdb/redo/redo01.log&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SQL&amp;gt; select group#,thread#,status from v$log;&lt;br /&gt;
 &lt;br /&gt;
GROUP#   THREAD#   STATUS&lt;br /&gt;
-------  --------- ----------------&lt;br /&gt;
1        1         CLEARING_CURRENT&lt;br /&gt;
2        1         STALE&lt;br /&gt;
3        1         STALE&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Check the alert log! Always a good idea to get extra info. In here we find the answer&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ORA-00344: unable to re-create online log&lt;br /&gt;
&amp;#039;/oracle/oradata/testdb/redo/redo01.log&amp;#039;&lt;br /&gt;
ORA-27040: file create error, unable to create file&lt;br /&gt;
Linux-x86_64 Error: 2: No such file or directory&lt;br /&gt;
Additional information: 1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
So the clue is that the file cannot be created at the operating system level.&amp;lt;br /&amp;gt;&lt;br /&gt;
Doing a &amp;lt;code&amp;gt;df -k /oracle/oradata/testdb/redo&amp;lt;/code&amp;gt; shows us that the filesystem was created too small for the destination database.&amp;lt;br /&amp;gt;&lt;br /&gt;
In this case, we do not want the redolog directory to be as big as on the source db as there will be almost no movement on the destination.&amp;lt;br /&amp;gt;&lt;br /&gt;
I should have specified the LOGFILE parameter in the DUPLICATE clause to setup new, smaller redolog files.&amp;lt;br /&amp;gt;&lt;br /&gt;
As this duplicate takes over 12 hours, I didn&amp;#039;t want to do it again so I created symbolic links in the redolog directory pointing out to a larger filesystem with more space.&amp;lt;br /&amp;gt;&lt;br /&gt;
This allowed the creation of the redolog files. They can then be resized once the database has been opened.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cd /oracle/oradata/testdb/redo&lt;br /&gt;
ln -s /tmp/redo01.log redo01.log&lt;br /&gt;
ln -s /tmp/redo02.log redo02.log&lt;br /&gt;
ln -s /tmp/redo03.log redo03.log&lt;br /&gt;
&lt;br /&gt;
SQL&amp;gt; alter database open resetlogs&lt;br /&gt;
Database opened.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===RMAN-04004: error from recovery catalog database: ORA-01017: invalid username/password; logon denied===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
oracle@host:/export/home/ora&amp;gt; rman target / catalog catowner/catpass@catdb&lt;br /&gt;
&lt;br /&gt;
Recovery Manager: Release 11.2.0.2.0 - Production on Thu Jun 12 16:51:03 2014&lt;br /&gt;
&lt;br /&gt;
Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.&lt;br /&gt;
&lt;br /&gt;
connected to target database: XXXXRAP1 (DBID=3557010742)&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-00554: initialization of internal recovery manager package failed&lt;br /&gt;
RMAN-04004: error from recovery catalog database: ORA-01017: invalid username/password; logon denied&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This is normally very straight-forward and self-explanatory.&amp;lt;br /&amp;gt;&lt;br /&gt;
The puzzle here is that a connection from SQL*Plus works!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sqlplus catowner/catpass@catdb&lt;br /&gt;
&lt;br /&gt;
SQL*Plus: Release 11.2.0.2.0 Production on Thu Jun 12 16:53:18 2014&lt;br /&gt;
&lt;br /&gt;
Copyright (c) 1982, 2010, Oracle.  All rights reserved.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Connected to:&lt;br /&gt;
Oracle Database 12c Enterprise Edition Release 12.1.0.1.0 - 64bit Production&lt;br /&gt;
With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options&lt;br /&gt;
SQL&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Eventually worked out that the rman binary in the databases ORACLE_HOME on the source machine needed relinking!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cd $ORACLE_HOME/rdbms/lib&lt;br /&gt;
make -f ins_rdbms.mk irman &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORA-00230: operation disallowed: snapshot control file enqueue unavailable===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
waiting for snapshot control file enqueue&lt;br /&gt;
waiting for snapshot control file enqueue&lt;br /&gt;
waiting for snapshot control file enqueue&lt;br /&gt;
waiting for snapshot control file enqueue&lt;br /&gt;
cannot make a snapshot control file&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-03008: error while performing automatic resync of recovery catalog&lt;br /&gt;
ORA-00230: operation disallowed: snapshot control file enqueue unavailable&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
From the doc...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
When RMAN needs to back up or resynchronize from the control file, it first creates a snapshot or consistent image of the control file.&lt;br /&gt;
If one RMAN job is already backing up the control file while another needs to create a new snapshot control file, then you may see the following message:&lt;br /&gt;
&lt;br /&gt;
waiting for snapshot controlfile enqueue&lt;br /&gt;
&lt;br /&gt;
Under normal circumstances, a job that must wait for the control file enqueue waits for a brief interval and then successfully obtains the enqueue.&lt;br /&gt;
RMAN makes up to five attempts to get the enqueue and then fails the job.&lt;br /&gt;
The conflict is usually caused when two jobs are both backing up the control file, and the job that first starts backing up the control file waits for service from the media manager.&lt;br /&gt;
&lt;br /&gt;
To determine which job is holding the conflicting enqueue:&lt;br /&gt;
&lt;br /&gt;
    After you see the first message stating &amp;quot;RMAN-08512: waiting for snapshot controlfile enqueue&amp;quot;, start a new SQL*Plus session on the target database:&lt;br /&gt;
&lt;br /&gt;
    % sqlplus &amp;#039;SYS/oracle@trgt AS SYSDBA&amp;#039;&lt;br /&gt;
&lt;br /&gt;
    Execute the following query to determine which job is causing the wait:&lt;br /&gt;
&lt;br /&gt;
    SELECT s.SID, USERNAME AS &amp;quot;User&amp;quot;, PROGRAM, MODULE, &lt;br /&gt;
           ACTION, LOGON_TIME &amp;quot;Logon&amp;quot;, l.* &lt;br /&gt;
    FROM V$SESSION s, V$ENQUEUE_LOCK l&lt;br /&gt;
    WHERE l.SID = s.SID&lt;br /&gt;
    AND l.TYPE = &amp;#039;CF&amp;#039;&lt;br /&gt;
    AND l.ID1 = 0&lt;br /&gt;
    AND l.ID2 = 2;&lt;br /&gt;
&lt;br /&gt;
    You should see output similar to the following (the output in this example has been truncated):&lt;br /&gt;
&lt;br /&gt;
    SID User Program              Module                    Action           Logon&lt;br /&gt;
    --- ---- -------------------- ------------------------- ---------------- ---------&lt;br /&gt;
      9 SYS  rman@h13 (TNS V1-V3) backup full datafile: c1  0000210 STARTED  21-JUN-01&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
After you have determined which job is creating the enqueue, you can do one of the following:&lt;br /&gt;
&lt;br /&gt;
    Wait until the job creating the enqueue completes&lt;br /&gt;
    Cancel the current job and restart it after the job creating the enqueue completes&lt;br /&gt;
    Cancel the job creating the enqueue&lt;br /&gt;
&lt;br /&gt;
Commonly, enqueue situations occur when a job is writing to a tape drive, but the tape drive is waiting for a new cassette to be inserted.&lt;br /&gt;
If you start a new job in this situation, then you will probably receive the enqueue message because the first job cannot complete until the new tape is loaded.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or more directly...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 2000&lt;br /&gt;
col killer     for a70&lt;br /&gt;
col program    for a20&lt;br /&gt;
col module     for a20&lt;br /&gt;
col action     for a20&lt;br /&gt;
col logon_time for a20&lt;br /&gt;
select &amp;#039;alter system disconnect session &amp;#039;&amp;#039;&amp;#039;||s.sid||&amp;#039;,&amp;#039;||s.serial#||&amp;#039;&amp;#039;&amp;#039; immediate;&amp;#039; killer&lt;br /&gt;
,      username&lt;br /&gt;
,      program&lt;br /&gt;
,      module&lt;br /&gt;
,      action&lt;br /&gt;
,      logon_time&lt;br /&gt;
from   v$session s&lt;br /&gt;
,      v$enqueue_lock l&lt;br /&gt;
where  l.sid  = s.sid&lt;br /&gt;
and    l.type = &amp;#039;cf&amp;#039;&lt;br /&gt;
and    l.id1  = 0&lt;br /&gt;
and    l.id2  = 2&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORA-19511: non RMAN, but media manager or vendor specific failure, error text:===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-03002: failure of Duplicate Db command at 05/01/2018 14:23:09&lt;br /&gt;
RMAN-05501: aborting duplication of target database&lt;br /&gt;
RMAN-03015: error occurred in stored script Memory Script&lt;br /&gt;
ORA-27191: sbtinfo2 returned error&lt;br /&gt;
Additional information: 3586&lt;br /&gt;
ORA-19511: non RMAN, but media manager or vendor specific failure, error text:&lt;br /&gt;
   Unable to connect to NetWorker server &amp;#039;hn6000.cln.be&amp;#039; because &amp;#039;Authentication error; why = Invalid client credential&amp;#039;. (2:10:79)&lt;br /&gt;
&lt;br /&gt;
Recovery Manager complete.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
If this happens, check to see if the nsr daemon is running...&amp;lt;br /&amp;gt;&lt;br /&gt;
Good system:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/home/oracle&amp;gt; ps -ef | grep nsr&lt;br /&gt;
    root  5701836        1   0   Mar 16      - 13:18 /bin/nsrexecd&lt;br /&gt;
  oracle 18809292 22741502   0 15:03:58  pts/0  0:00 grep nsr&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Bad system:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 /home/oracle&amp;gt; ps -ef | grep nsr&lt;br /&gt;
  oracle 14745986 15139292   0 15:03:29  pts/2  0:00 grep nsr&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORA-19554: error allocating device, device type: SBT_TAPE, device name:===&lt;br /&gt;
If using Cygwin...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-03002: failure of backup command at 05/19/2015 12:25:47&lt;br /&gt;
ORA-19554: error allocating device, device type: SBT_TAPE, device name:&lt;br /&gt;
ORA-27000: skgfqsbi: failed to initialize storage subsystem (SBT) layer&lt;br /&gt;
OSD-02534: Message 2534 not found;  product=RDBMS; facility=SOSD&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Check the tdpo.opt file is where you think it is!&lt;br /&gt;
* Check the path to the opt file looks like this (needs to be Windows format):&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
CONFIGURE CHANNEL DEVICE TYPE &amp;#039;SBT_TAPE&amp;#039; FORMAT   &amp;#039;LOG_%d_t%t_s%s_u%U&amp;#039; PARMS  &amp;#039;ENV=(TDPO_OPTFILE=E:\oracle\KITRYD\admin\tdpo.opt)&amp;#039;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Check the content of the opt file is Windows format paths!&lt;br /&gt;
&lt;br /&gt;
===RMAN-20033: control file SEQUENCE# too low===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-03008: error while performing automatic resync of recovery catalog&lt;br /&gt;
===RMAN-20033: control file SEQUENCE# too low===&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
From [https://forums.oracle.com/forums/thread.jspa?threadID=1115969 forums.oracle.com]&amp;lt;br /&amp;gt;&lt;br /&gt;
This error generally happens if an archivelog backup happens while the RMAN database backup is running and if controlfile autobackup is configured.&amp;lt;br /&amp;gt;&lt;br /&gt;
The database backup is usually successful and it is just the controlfile backup that fails.&lt;br /&gt;
===ORA-27302: failure occurred at: slgpn===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
RMAN-03009: failure of Control File and SPFILE Autobackup command on c1 channel at 06/28/2011 18:59:38&lt;br /&gt;
ORA-19715: invalid format %b for generated name&lt;br /&gt;
ORA-27302: failure occurred at: slgpn&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Problem====&lt;br /&gt;
When doing a &amp;quot;&amp;lt;tt&amp;gt;backup as copy database&amp;lt;/tt&amp;gt;&amp;quot;, got these errors after 145 of 147 datafiles had been backed up!&lt;br /&gt;
&lt;br /&gt;
====Investigation====&lt;br /&gt;
I had read [https://oracleedge.wordpress.com/2011/06/29/oracle-rman-03009-ora-19715-ora-27302/ elsewhere] that this could be something to do with the format of the autobackup of the control file so I changed the format as suggested and reran the backup.&amp;lt;br /&amp;gt;&lt;br /&gt;
No luck. It ended exactly the same way after 145 files. I decided to compare the original list of datafiles with those that had been backed up in order to track down the 2 failures. Maybe I could see something odd with them.&amp;lt;br /&amp;gt;&lt;br /&gt;
Sure enough, these 2 files were different... there was a space at the &amp;#039;&amp;#039;&amp;#039;end&amp;#039;&amp;#039;&amp;#039; of the filenames :-)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select &amp;#039;x&amp;#039;||file_name||&amp;#039;x&amp;#039;&lt;br /&gt;
from   dba_data_files&lt;br /&gt;
where  file_name like &amp;#039;% %&amp;#039;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Solution====&lt;br /&gt;
Run the backup of the other 2 datafiles with a different format that did not rely on the filename.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
run {&lt;br /&gt;
    allocate channel c1 device type disk format &amp;#039;/path/to/datafiles/%U&amp;#039;;&lt;br /&gt;
    backup as copy datafile 170;&lt;br /&gt;
    backup as copy datafile 171;&lt;br /&gt;
    backup as copy current controlfile;&lt;br /&gt;
    release channel c1;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The other 145 datafiles were backed up with a format of &amp;#039;/path/to/datafiles/%b&amp;#039; which preserves the filenames so all that needs to be done is rename the other 2 after the backup finishes.&amp;lt;br /&amp;gt;&lt;br /&gt;
If they are going to be used in a restore scenario, they should be renamed in the controlfile also.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter database rename file &amp;#039;/path/to/datafiles/filename_with_a_space_at_end &amp;#039; to &amp;#039;/path/to/datafiles/filename_without_a_space&amp;#039;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===RMAN errors after crosscheck backup and delete noprompt obsolete and delete noprompt expired backup===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
RMAN-06207: WARNING: 3921 objects could not be deleted for SBT_TAPE channel(s) due&lt;br /&gt;
RMAN-06208:          to mismatched status.  Use CROSSCHECK command to fix status&lt;br /&gt;
RMAN-06210: List of Mismatched objects&lt;br /&gt;
RMAN-06211: ==========================&lt;br /&gt;
RMAN-06212:   Object Type   Filename/Handle&lt;br /&gt;
RMAN-06213: --------------- ---------------------------------------------------&lt;br /&gt;
RMAN-06214: Backup Piece    DB_SID_t20140316_s263889_umhp3bpa7_1_1&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Use the FORCE option with the DELETE command&amp;lt;br /&amp;gt;&lt;br /&gt;
The FORCE command tells RMAN to clean the information out of the catalog regardless of whether it can find it on the media or not.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
delete force noprompt expired backup;&lt;br /&gt;
delete force noprompt obsolete;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===RMAN-06004: ORACLE error from recovery catalog database: RMAN-20003: target database incarnation not found in recovery catalog===&lt;br /&gt;
====Problem:====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-03002: failure of Duplicate Db command at 12/05/2017 11:11:15&lt;br /&gt;
RMAN-05501: aborting duplication of target database&lt;br /&gt;
RMAN-03015: error occurred in stored script Memory Script&lt;br /&gt;
RMAN-06004: ORACLE error from recovery catalog database: RMAN-20003: target database incarnation not found in recovery catalog&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Solution:====&lt;br /&gt;
Strangely, this means, in my particular case, that block change tracking is turned on in the target databse and needs turning off in the auxiliary while the DUPLICATE is running.&amp;lt;br /&amp;gt;&lt;br /&gt;
It must be done while the auxiliary is in mount mode and restoring the datafiles (before recovery starts)&amp;lt;br /&amp;gt;&lt;br /&gt;
It is reported to be a bug fixed in 11.1 but somehow, we&amp;#039;re still (sometimes) getting it in 12.1.0.2.&lt;br /&gt;
&lt;br /&gt;
===RMAN-06059: expected archived log not found, loss of archived log compromises recoverability===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
RMAN-06059: expected archived log not found, loss of archived log compromises recoverability&lt;br /&gt;
ORA-19625: error identifying file &amp;lt;filename&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This error can come from the fact that the database files (more likely archivelogs) are being deleted by the operating system so RMAN has no clue of their whereabouts.&amp;lt;br /&amp;gt;&lt;br /&gt;
Possibly result of a database duplication and the catalog has not updated properly?&amp;lt;br /&amp;gt;&lt;br /&gt;
====Solution====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
crosscheck archivelog all;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
And then maybe take a backup to be on the safe side.&lt;br /&gt;
&lt;br /&gt;
===RMAN-05537: DUPLICATE without TARGET connection when auxiliary instance is started with spfile cannot use SPFILE clause===&lt;br /&gt;
====Problem:====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-03002: failure of Duplicate Db command at 12/05/2017 14:17:49&lt;br /&gt;
RMAN-05501: aborting duplication of target database&lt;br /&gt;
RMAN-05537: DUPLICATE without TARGET connection when auxiliary instance is started with spfile cannot use SPFILE clause&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Usually happens after restarting a failed RMAN DUPLICATE database. The spfile has been regenerated on the auxiliary to a level where it has too much detail in it.&lt;br /&gt;
====Solution:====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ cd $ORACLE_HOME/dbs&lt;br /&gt;
$ ls -altr *dwh_perf*&lt;br /&gt;
-rw-r-----    1 oracle   oinstall   17645568 Aug  3 13:34 snapcf_dwh_perf.f&lt;br /&gt;
-rw-r-----    1 oracle   oinstall       7680 Nov  4 09:22 orapwdwh_perf&lt;br /&gt;
-rw-r--r--    1 oracle   oinstall        104 Dec  5 09:34 initdwh_perf.ora&lt;br /&gt;
-rw-r-----    1 oracle   oinstall       6656 Dec  5 11:11 spfiledwh_perf.ora&lt;br /&gt;
-rw-rw----    1 oracle   oinstall       1544 Dec  5 14:18 hc_dwh_perf.dat&lt;br /&gt;
$ mv hc_dwh_perf.dat hc_dwh_perf.dat.old&lt;br /&gt;
$ mv spfiledwh_perf.ora spfiledwh_perf.ora.old&lt;br /&gt;
$ cat initdwh_perf.ora&lt;br /&gt;
sga_max_size=&amp;#039;6G&amp;#039;&lt;br /&gt;
sga_target=&amp;#039;6G&amp;#039;&lt;br /&gt;
compatible=&amp;#039;12.0.0&amp;#039;&lt;br /&gt;
db_files=&amp;#039;500&amp;#039;&lt;br /&gt;
&lt;br /&gt;
# Instance name&lt;br /&gt;
db_name=dwh_perf&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Re-run the DUPLICATE. It should zoom past the already recovered datafiles.&lt;br /&gt;
&lt;br /&gt;
===PSDRPC returns significant error 1013===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
archived log thread=1 sequence=195008&lt;br /&gt;
channel t2: reading from backup piece arclog_LBK_4260753020_946042770_479194_1&lt;br /&gt;
channel t0: piece handle=arclog_LBK_4260753020_946042770_479192_1 tag=TAG20170607T133757&lt;br /&gt;
channel t0: restored backup piece 1&lt;br /&gt;
channel t0: restore complete, elapsed time: 00:00:35&lt;br /&gt;
archived log file name=/xxxxxx/acc/ora_bin2/app/oracle/product/11.2.0.4/dbhome_1/dbs/arch1_195006_815790039.dbf thread=1 sequence=195006&lt;br /&gt;
PSDRPC returns significant error 1013.&lt;br /&gt;
PSDRPC returns significant error 1013.&lt;br /&gt;
released channel: t0&lt;br /&gt;
released channel: t1&lt;br /&gt;
released channel: t2&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-03002: failure of Duplicate Db command at 06/09/2017 15:15:04&lt;br /&gt;
RMAN-05501: aborting duplication of target database&lt;br /&gt;
RMAN-03015: error occurred in stored script Memory Script&lt;br /&gt;
RMAN-11003: failure during parse/execution of SQL statement: alter database recover logfile &amp;#039;/xxxxxx/acc/ora_bin2/app/oracle/product/11.2.0.4/dbhome_1/dbs/arch1_195006_815790039.dbf&amp;#039;&lt;br /&gt;
ORA-10877: error signaled in parallel recovery slave&lt;br /&gt;
&lt;br /&gt;
Recovery Manager complete.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Action====&lt;br /&gt;
Check the alert log on the auxiliary instance.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ORA-279 signalled during: alter database recover logfile &amp;#039;/xxxxxx/acc/ora_bin2/app/oracle/product/11.2.0.4/dbhome_1/dbs/arch1_195005_815790039.dbf&amp;#039;...&lt;br /&gt;
alter database recover logfile &amp;#039;/xxxxxx/acc/ora_bin2/app/oracle/product/11.2.0.4/dbhome_1/dbs/arch1_195006_815790039.dbf&amp;#039;&lt;br /&gt;
Media Recovery Log /xxxxxx/acc/ora_bin2/app/oracle/product/11.2.0.4/dbhome_1/dbs/arch1_195006_815790039.dbf&lt;br /&gt;
Fri Jun 09 07:30:30 2017&lt;br /&gt;
Errors with log /xxxxxx/acc/ora_bin2/app/oracle/product/11.2.0.4/dbhome_1/dbs/arch1_195006_815790039.dbf&lt;br /&gt;
Recovery interrupted!&lt;br /&gt;
Recovered data files to a consistent state at change 238029030495&lt;br /&gt;
Media Recovery failed with error 19755&lt;br /&gt;
Errors in file /xxxxxx/acc/ora_bin2/app/oracle/diag/rdbms/lbkro/lbkro/trace/lbkro_pr00_13108374.trc:&lt;br /&gt;
ORA-00283: recovery session canceled due to errors&lt;br /&gt;
===&amp;gt;ORA-19755: could not open change tracking file&lt;br /&gt;
===&amp;gt;ORA-19750: change tracking file: &amp;#039;/xxxxxx/exp/ora_data2/lbk/data/bct_lbk_do_not_delete.f&lt;br /&gt;
===&amp;gt;ORA-27037: unable to obtain file status&lt;br /&gt;
===&amp;gt;IBM AIX RISC System/6000 Error: 2: No such file or directory&lt;br /&gt;
Additional information: 3&lt;br /&gt;
Fri Jun 09 07:30:36 2017&lt;br /&gt;
ORA-10877 signalled during: alter database recover logfile &amp;#039;/xxxxxx/acc/ora_bin2/app/oracle/product/11.2.0.4/dbhome_1/dbs/arch1_195006_815790039.dbf&amp;#039;...&lt;br /&gt;
Fri Jun 09 14:04:57 2017&lt;br /&gt;
alter database recover logfile &amp;#039;/xxxxxx/acc/ora_bin2/app/oracle/product/11.2.0.4/dbhome_1/dbs/arch1_195006_815790039.dbf&amp;#039;&lt;br /&gt;
Media Recovery Log /xxxxxx/acc/ora_bin2/app/oracle/product/11.2.0.4/dbhome_1/dbs/arch1_195006_815790039.dbf&lt;br /&gt;
Media Recovery failed with error 1112&lt;br /&gt;
ORA-283 signalled during: alter database recover logfile &amp;#039;/xxxxxx/acc/ora_bin2/app/oracle/product/11.2.0.4/dbhome_1/dbs/arch1_195006_815790039.dbf&amp;#039;...&lt;br /&gt;
Fri Jun 09 14:31:20 2017&lt;br /&gt;
Shutting down instance (immediate)&lt;br /&gt;
Shutting down instance: further logons disabled&lt;br /&gt;
Stopping background process MMNL&lt;br /&gt;
Stopping background process MMON&lt;br /&gt;
License high water mark = 49&lt;br /&gt;
ALTER DATABASE CLOSE NORMAL&lt;br /&gt;
ORA-1109 signalled during: ALTER DATABASE CLOSE NORMAL...&lt;br /&gt;
ALTER DATABASE DISMOUNT&lt;br /&gt;
Shutting down archive processes&lt;br /&gt;
Archiving is disabled&lt;br /&gt;
Completed: ALTER DATABASE DISMOUNT&lt;br /&gt;
ARCH: Archival disabled due to shutdown: 1089&lt;br /&gt;
Shutting down archive processes&lt;br /&gt;
Archiving is disabled&lt;br /&gt;
ARCH: Archival disabled due to shutdown: 1089&lt;br /&gt;
Shutting down archive processes&lt;br /&gt;
Archiving is disabled&lt;br /&gt;
Fri Jun 09 14:31:24 2017&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This is a known bug. it is fixed in 11.2.0.3 but... this customer does not apply patches!&lt;br /&gt;
&lt;br /&gt;
====Solution====&lt;br /&gt;
While the DUPLICATE is running (and in MOUNT mode), log on to the auxiliary instance and disable block change tracking.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter database disable block change tracking;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
A documented workaround is to set db_filename_convert parameter in the DUPLICATE clause of the run block but I tried this and it failed again.&amp;lt;br /&amp;gt;&lt;br /&gt;
The obvious solution is to patch the database but...&lt;br /&gt;
&lt;br /&gt;
===Database trigger to capture ORA errors===&lt;br /&gt;
From [http://ora-ssn.blogspot.be/2011/10/trigger-on-database-to-capture-ora.html ora-ssn.blogspot.be]&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
CREATE TABLE stats$error_log (&lt;br /&gt;
        err_dt          TIMESTAMP,&lt;br /&gt;
        db_user         VARCHAR2(30),&lt;br /&gt;
        msg_stack       VARCHAR2(2000),&lt;br /&gt;
        sqltxt          VARCHAR2(1000))&lt;br /&gt;
tablespace users;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Now, create a trigger on the database server.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
CREATE OR REPLACE TRIGGER log_server_errors&lt;br /&gt;
  AFTER SERVERERROR&lt;br /&gt;
  ON DATABASE&lt;br /&gt;
DECLARE&lt;br /&gt;
          v_sqltext VARCHAR2(1000);&lt;br /&gt;
          nl_sqltext ora_name_list_t;&lt;br /&gt;
  BEGIN&lt;br /&gt;
          -- Capture entire error text&lt;br /&gt;
          FOR i IN 1 .. ora_sql_txt(nl_sqltext) LOOP&lt;br /&gt;
            v_sqltext := v_sqltext || nl_sqltext(i);&lt;br /&gt;
          END LOOP;&lt;br /&gt;
          INSERT INTO STATS$ERROR_LOG&lt;br /&gt;
          (err_dt, db_user, msg_stack, sqltxt)&lt;br /&gt;
          VALUES&lt;br /&gt;
          (systimestamp,&lt;br /&gt;
           sys.login_user,&lt;br /&gt;
           dbms_utility.format_error_stack, v_sqltext);&lt;br /&gt;
  END log_server_errors;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORA-19809: limit exceeded for recovery files===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-03009: failure of backup command on ORA_DISK_1 channel at 07/15/2013 10:10:59&lt;br /&gt;
ORA-19809: limit exceeded for recovery files&lt;br /&gt;
ORA-19804: cannot reclaim 274716160 bytes disk space from 1468006400 limit&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    ORA-19809: limit exceeded for recovery files&lt;br /&gt;
    Cause: The limit for recovery files specified by the db_recovery_file_dest_size was exceeded.&lt;br /&gt;
&lt;br /&gt;
    Action: The error is accompanied by 19804. See message 19804 for further details&lt;br /&gt;
&lt;br /&gt;
    ORA-19804: cannot reclaim string bytes disk space from string limit&lt;br /&gt;
    Cause: Oracle cannot reclaim disk space of specified bytes from the DB_RECOVERY_FILE_DEST_SIZE limit.&lt;br /&gt;
&lt;br /&gt;
    Action: There are five possible solutions:&lt;br /&gt;
       1) Take frequent backup of recovery area using RMAN.&lt;br /&gt;
       2) Consider changing RMAN retention policy.&lt;br /&gt;
       3) Consider changing RMAN archivelog deletion policy.&lt;br /&gt;
       4) Add disk space and increase DB_RECOVERY_FILE_DEST_SIZE.&lt;br /&gt;
       5) Delete files from recovery area using RMAN.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The solution here is to increase the value of db_recovery_file_dest_size but it might also indicate a problem with tapes if the archivelogs are being backed up to tape via tdpo.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SYS@DN7&amp;gt; alter system set db_recovery_file_dest_size=4000M scope=both;&lt;br /&gt;
&lt;br /&gt;
System altered.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Looking into int further, saw RMAN parameters missing...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
CONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF 14 DAYS;&lt;br /&gt;
CONFIGURE BACKUP OPTIMIZATION OFF;&lt;br /&gt;
CONFIGURE DEFAULT DEVICE TYPE TO &amp;#039;SBT_TAPE&amp;#039;;&lt;br /&gt;
CONFIGURE CONTROLFILE AUTOBACKUP ON;&lt;br /&gt;
CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE &amp;#039;SBT_TAPE&amp;#039; TO &amp;#039;LOG_%d_controlfile_%F.rman&amp;#039;;&lt;br /&gt;
CONFIGURE DEVICE TYPE &amp;#039;SBT_TAPE&amp;#039; PARALLELISM 1 BACKUP TYPE TO BACKUPSET;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===RMAN-00554: initialization of internal recovery manager package failed===&lt;br /&gt;
Getting this error after migrating a database from one machine to another and attaching to a nice new version 12c catalog on the new server&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Recovery Manager: Release 11.2.0.2.0 - Production on Sat Jun 21 13:16:24 2014&lt;br /&gt;
&lt;br /&gt;
Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.&lt;br /&gt;
&lt;br /&gt;
connected to target database: SPMSUPP1 (DBID=3026014394)&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-00554: initialization of internal recovery manager package failed&lt;br /&gt;
RMAN-04004: error from recovery catalog database: ORA-01017: invalid username/password; logon denied&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
We cannot connect to the catalog via rman but there is no problem if connecting via SQL*Plus!&amp;lt;br /&amp;gt;&lt;br /&gt;
Solution: relink the rman executable.&lt;br /&gt;
===Using AIX commands genld, genkld and slibclean to avoid library file locking errors (libjox) (Doc ID 739963.1)===&lt;br /&gt;
* [https://support.oracle.com/epmos/faces/DocumentDisplay?_afrLoop=206851390914720&amp;amp;id=739963.1&amp;amp;_afrWindowMode=0&amp;amp;_adf.ctrl-state=e0pq23tou_4 Metalink]&lt;br /&gt;
When installing interim (one-off) patches, CPU patches or patchsets, you may encounter some errors with regards to files being locked or oui/opatch being unable to copy files&amp;lt;br /&amp;gt;&lt;br /&gt;
even though the databases, listeners and all other Oracle processes associated with the ORACLE_HOME to be patched were stopped.&amp;lt;br /&amp;gt;&lt;br /&gt;
This could be as result of a process which requires termination or an additional file needing to be unloaded from the system cache.&amp;lt;br /&amp;gt;&lt;br /&gt;
Run following commands to clean up...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
genld -l | grep &amp;lt;ORACLE_HOME&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
If genld returns data then a currently executing process has something open in the ORACLE_HOME directory, therefore terminate the process as required/recommended.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
genkld | grep &amp;lt;ORACLE_HOME&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
If the genkld command  returns a  list of shared objects currently loaded onto the OS system cache then please remove the entries from the OS system cache by running the slibclean command as root user:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/usr/sbin/slibclean&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===ORA-20011: Approximate NDV failed: ORA-29913: error in executing ODCIEXTTABLEOPEN callout===&lt;br /&gt;
This seems to be related to orphaned Datapump tables. Generally seems to be a problem when stats jobs are running during the night (dbms_stats)&amp;lt;br /&amp;gt;&lt;br /&gt;
* Check no datapump jobs are running&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select * from dba_datapump_jobs;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Find orphaned tables&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 2000&lt;br /&gt;
select owner&lt;br /&gt;
,      object_name&lt;br /&gt;
,      object_type&lt;br /&gt;
,      status&lt;br /&gt;
,      to_char(created,&amp;#039;dd-mon-yyyy hh24:mi:ss&amp;#039;) created&lt;br /&gt;
,      to_char(last_ddl_time,&amp;#039;dd-mon-yyyy hh24:mi:ss&amp;#039;) last_ddl_time&lt;br /&gt;
from   dba_objects&lt;br /&gt;
where  1=1&lt;br /&gt;
and    object_name like &amp;#039;ET$%&amp;#039;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Check that  any rows seen are actually external tables&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select owner&lt;br /&gt;
,      table_name&lt;br /&gt;
,      default_directory_name&lt;br /&gt;
,      access_type&lt;br /&gt;
from   dba_external_tables&lt;br /&gt;
order  by 1,2&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Drop the tables if they are not currently being used (no datapump jobs running)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
drop table &amp;amp;&amp;amp;owner..&amp;amp;table_name;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===ORA-01547: warning: RECOVER succeeded but OPEN RESETLOGS would get error below===&lt;br /&gt;
Database is restored and now we want to recover it but we see this...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Starting recover at 24-JUL-15 11:26:19&lt;br /&gt;
&lt;br /&gt;
starting media recovery&lt;br /&gt;
&lt;br /&gt;
unable to find archive log&lt;br /&gt;
archive log thread=1 sequence=69763&lt;br /&gt;
Oracle Error: &lt;br /&gt;
ORA-01547: warning: RECOVER succeeded but OPEN RESETLOGS would get error below&lt;br /&gt;
ORA-01194: file 1 needs more recovery to be consistent&lt;br /&gt;
ORA-01110: data file 1: &amp;#039;/oracle/TRSCRP1/oradata2/system01.dbf&amp;#039;&lt;br /&gt;
&lt;br /&gt;
released channel: c1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This means that although we have restored the database, we are still missing information to complete the recovery. This information is contained in the archived redo logs which must also be restored (from tape if they are no longer on disk)&amp;lt;br /&amp;gt;&lt;br /&gt;
We can see here that we need an archive log with sequence number 69763. But what is the file called and where should it be restored to?&amp;lt;br /&amp;gt;&lt;br /&gt;
For this we can go to SQL*Plus and get the database to tell us&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
recover database using backup controlfile until cancel;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
and cancel straight away.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ORA-00279: change 13796376414661 generated at 07/14/2015 13:20:07 needed for&lt;br /&gt;
thread 1&lt;br /&gt;
ORA-00289: suggestion : /oracle/TRSCRP1/archive/arch_TRSCRP1_1_69763.arc&lt;br /&gt;
ORA-00280: change 13796376414661 for thread 1 is in sequence #69763&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Specify log: {&amp;lt;RET&amp;gt;=suggested | filename | AUTO | CANCEL}&lt;br /&gt;
cancel&lt;br /&gt;
ORA-01547: warning: RECOVER succeeded but OPEN RESETLOGS would get error below&lt;br /&gt;
ORA-01194: file 1 needs more recovery to be consistent&lt;br /&gt;
ORA-01110: data file 1: &amp;#039;/oracle/TRSCRP1/oradata2/system01.dbf&amp;#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
ORA-01112: media recovery not started&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Now we see that we need to find a file called arch_TRSCRP1_1_69763.arc and put it in the directory /oracle/TRSCRP1/archive.&amp;lt;br /&amp;gt;&lt;br /&gt;
This will continue up until the time specified for the recover so restore a whole bunch of them.&amp;lt;br /&amp;gt;&lt;br /&gt;
Repeat the &amp;quot;recover database using backup controlfile until cancel;&amp;quot; command and type AUTO or Enter until you&amp;#039;ve got to where you need to be.&amp;lt;br /&amp;gt;&lt;br /&gt;
Type CANCEL when point is reached and&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter database open resetlogs;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Stuart</name></author>	</entry>

	<entry>
		<id>https://mailnest.com/dbawiki/index.php?title=Oracle_errors&amp;diff=3361</id>
		<title>Oracle errors</title>
		<link rel="alternate" type="text/html" href="https://mailnest.com/dbawiki/index.php?title=Oracle_errors&amp;diff=3361"/>
				<updated>2018-11-03T16:55:37Z</updated>
		
		<summary type="html">&lt;p&gt;Stuart: /* Use exchange partition to alter metadata of the tablespaces without moving the actual data */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;===ORA-00600===&lt;br /&gt;
[https://support.oracle.com/epmos/faces/DocContentDisplay?_afrLoop=397490397952859&amp;amp;id=1092832.1&amp;amp;_afrWindowMode=0&amp;amp;_adf.ctrl-state=184vwc6g3y_4 Master Note for Diagnosing ORA-600 (Doc ID 1092832.1)]&lt;br /&gt;
===ORA-19051: Cannot use fast path insert for this XMLType table===&lt;br /&gt;
Think LD_LIBRARY_PATH on Linux or LIBPATH on AIX.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Export: Release 11.2.0.4.0 - Production on Thu Jun 1 06:41:55 2017&lt;br /&gt;
&lt;br /&gt;
Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.&lt;br /&gt;
&lt;br /&gt;
Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production&lt;br /&gt;
With the Partitioning, OLAP, Data Mining and Real Application Testing options&lt;br /&gt;
Starting &amp;quot;DWH_EXPORT&amp;quot;.&amp;quot;SYS_EXPORT_TABLE_03&amp;quot;:  dwh_export/******** parfile=cadis_foto_export_credit_dba.par&lt;br /&gt;
Estimate in progress using BLOCKS method...&lt;br /&gt;
Processing object type TABLE_EXPORT/TABLE/TABLE_DATA&lt;br /&gt;
Total estimation using BLOCKS method: 64.08 GB&lt;br /&gt;
ORA-39126: Worker unexpected fatal error in KUPW$WORKER.FETCH_XML_OBJECTS []&lt;br /&gt;
ORA-19051: Cannot use fast path insert for this XMLType table&lt;br /&gt;
&lt;br /&gt;
ORA-06512: at &amp;quot;SYS.DBMS_SYS_ERROR&amp;quot;, line 86&lt;br /&gt;
ORA-06512: at &amp;quot;SYS.KUPW$WORKER&amp;quot;, line 9710&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Problem====&lt;br /&gt;
When the 11g DB was started, LD_LIBRARY_PATH and LIBPATH were still pointing to paths in the 10g Home.&lt;br /&gt;
====Solution====&lt;br /&gt;
There may have been some odd values setup in LD_LIBRARY_PATH before the call to oraenv (if oraenv was indeed called!)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
unset LD_LIBRARY_PATH LIBPATH&lt;br /&gt;
export ORACLE_SID=&amp;lt;correct 11g SID&amp;gt;&lt;br /&gt;
. oraenv&lt;br /&gt;
echo $LD_LIBRARY_PATH&lt;br /&gt;
echo $LIBPATH&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
They should now be correct.&lt;br /&gt;
&lt;br /&gt;
===ORA-27092: size of file exceeds file size limit of the process===&lt;br /&gt;
Think ulimit...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Cause: an attempt was made to open a file that exceeds the process&amp;#039;s file size limit (ulimit), additional information shows the current limit (logical blocks) and the size of the file (logical blocks)&lt;br /&gt;
Action: increase the processes file size limit (ulimit) and retry&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
truncate table pibadm.test_ph&lt;br /&gt;
                      *&lt;br /&gt;
Error at line 1 :&lt;br /&gt;
ORA-00604: error ocurred at recursive SQL level 1&lt;br /&gt;
ORA-01116: error in opening database file 2&lt;br /&gt;
ORA-01110: datafile 2 : &amp;#039;/opt/u01/data/PIBQA/UNDO_01.dbf&amp;#039;&lt;br /&gt;
ORA-27092: size of file exceeds file size limit of the process&lt;br /&gt;
Additional information: 262143&lt;br /&gt;
Additional information: 2621441&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Check the fs_size limit for this user in /etc/security/limits&amp;lt;br /&amp;gt;&lt;br /&gt;
Compare this with another user, say oracle. Probably -1 (unlimited)&lt;br /&gt;
&lt;br /&gt;
===SP2-1503: Unable to initialize Oracle call interface===&lt;br /&gt;
When trying to login to the database via SQL*Plus, these messages a displayed&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
hn5118 /home/oracle $sqlplus / as sysdba&lt;br /&gt;
SP2-1503: Unable to initialize Oracle call interface&lt;br /&gt;
SP2-0152: ORACLE may not be functioning properly&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Seems to be a problem unique to AIX (in this case).&amp;lt;br /&amp;gt;&lt;br /&gt;
Check to see what the LIBPATH variable is. It may still contain a path to an old ORACLE_HOME...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
hn5118 /home/oracle $env|grep LIBPATH&lt;br /&gt;
LIBPATH=/oracle/exp/ora_bin1/app/oracle/product/10.2.0/db_1/lib:/oracle/exp/ora_bin1/app/oracle/product/10.2.0/db_1/lib&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Disco! Unset it and rerun.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
hn5118 /home/oracle $unset LIBPATH&lt;br /&gt;
&lt;br /&gt;
hn5118 /home/oracle $sqlplus / as sysdba&lt;br /&gt;
&lt;br /&gt;
SQL*Plus: Release 12.1.0.2.0 Production on Wed Jul 12 17:17:54 2017&lt;br /&gt;
&lt;br /&gt;
Copyright (c) 1982, 2014, Oracle.  All rights reserved.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Connected to:&lt;br /&gt;
Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production&lt;br /&gt;
With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options&lt;br /&gt;
&lt;br /&gt;
SQL&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===UDE-31623: operation generated ORACLE error 31623===&lt;br /&gt;
When using Data pump, get following errors almost immediately:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
UDE-31623: operation generated ORACLE error 31623&lt;br /&gt;
ORA-31623: a job is not attached to this session via the specified handle&lt;br /&gt;
ORA-06512: at &amp;quot;SYS.DBMS_DATAPUMP&amp;quot;, line 3326&lt;br /&gt;
ORA-06512: at &amp;quot;SYS.DBMS_DATAPUMP&amp;quot;, line 4551&lt;br /&gt;
ORA-06512: at line 1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Solution 1:&amp;#039;&amp;#039;&amp;#039;&amp;lt;br /&amp;gt;&lt;br /&gt;
In one case, I simplified the parameter file that was used. Maybe related to Streams Pool size, who knows?!&amp;lt;br /&amp;gt;&lt;br /&gt;
I removed these 2 lines and the export started working:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
compression_algorithm=medium&lt;br /&gt;
logtime=all&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Solution 2:&amp;#039;&amp;#039;&amp;#039;&amp;lt;br /&amp;gt;&lt;br /&gt;
There is a note about this on Metalink, 1080775.1 which suggests that Streams Pool Size needs setting.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
For this DataPump error, you will need to configure the database with some Streams Pool.&lt;br /&gt;
&lt;br /&gt;
Perform the following query to find out how much STREAMS_POOL_SIZE has been allocated&lt;br /&gt;
&lt;br /&gt;
 select * from v$sgainfo;&lt;br /&gt;
 ...&lt;br /&gt;
 Streams Pool Size                               0 Yes&lt;br /&gt;
&lt;br /&gt;
Data Pump now uses Advanced Queuing (AQ) internally, so it can handle job stops/starts/re-starts.  However, AQ using the Streams Pool, where the database currently has the STREAMS_POOL_SIZE set to ZERO.&lt;br /&gt;
&lt;br /&gt;
Manually set the STREAMS_POOL_SIZE (using ALTER SYSTEM or by changing the value in the the PFILE/SPFILE), re-start the database and re-attempt the Data Pump Export.&lt;br /&gt;
&lt;br /&gt;
Alternately, turn on Automatic Shared Memory management (ASMM) by setting SGA_TARGET or MEMORY_TARGET.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
From Oracle Documentation&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Setting the Size Of the Buffer Cache In a Streams Environment&lt;br /&gt;
&lt;br /&gt;
Oracle Data Pump uses Streams functionality to communicate between processes.&lt;br /&gt;
If the SGA_TARGET initialization parameter is set, then the STREAMS_POOL_SIZE initialization parameter is automatically set to a reasonable value.&lt;br /&gt;
If the SGA_TARGET initialization parameter is not set and the STREAMS_POOL_SIZE initialization parameter is not defined,&lt;br /&gt;
then the size of the streams pool automatically defaults to 10% of the size of the shared pool.&lt;br /&gt;
&lt;br /&gt;
When the streams pool is created, the required SGA memory is taken from memory allocated to the buffer cache,&lt;br /&gt;
reducing the size of the cache to less than what was specified by the DB_CACHE_SIZE initialization parameter.&lt;br /&gt;
This means that if the buffer cache was configured with only the minimal required SGA, then Data Pump operations may not work properly.&lt;br /&gt;
A minimum size of 10M is recommended for STREAMS_POOL_SIZE in order to ensure successful Data Pump operations.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORA-00020: maximum number of processes (150) exceeded===&lt;br /&gt;
Check the current resource limits with:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 300&lt;br /&gt;
select * from v$resource_limit;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Unfortunately this limit cannot be increased without a restart.&amp;lt;br /&amp;gt;&lt;br /&gt;
It may be a necessary to increase the limit with&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter system set processes=500 scope=spfile;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
followed by a shutdown/startup&amp;lt;br /&amp;gt;&lt;br /&gt;
Or it may be some user is running away with the limit.&amp;lt;br /&amp;gt;&lt;br /&gt;
Check to see who is running what with:&lt;br /&gt;
[[http://www.mailnest.com/dbawiki/index.php/Handy_scripts#See_what_statements_all_users_are_running See_what_statements_all_users_are_running]]&lt;br /&gt;
===ORA-01555: snapshot too old: rollback segment number nn with name &amp;quot;xxx&amp;quot; too small===&lt;br /&gt;
* [http://dfitzjarrell.wordpress.com/2008/02/22/the-dreaded-ora-01555/ Good explanation of why it happens]&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
====Problem====&lt;br /&gt;
A long running transaction has run out of space to store its read-consistent image&lt;br /&gt;
&lt;br /&gt;
====Solution 1====&lt;br /&gt;
If it&amp;#039;s a one-off, maybe leave it alone. It may have been a user leaving a session open overnight without committing or rolling back.&lt;br /&gt;
&lt;br /&gt;
====Solution 2====&lt;br /&gt;
Make sure there&amp;#039;s enough space to allow the transaction to finish.&lt;br /&gt;
&lt;br /&gt;
====Things to check====&lt;br /&gt;
How much undo did the biggest transaction take?&lt;br /&gt;
What is the undo retention parameter set to?&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 200&lt;br /&gt;
col name        for a30&lt;br /&gt;
col description for a50&lt;br /&gt;
col value       for a20&lt;br /&gt;
col maxquerylen for 999999&lt;br /&gt;
select p.name&lt;br /&gt;
,      p.description&lt;br /&gt;
,      p.value&lt;br /&gt;
,      max(u.maxquerylen) maxquerylen&lt;br /&gt;
from   v$parameter p&lt;br /&gt;
,      v$undostat  u&lt;br /&gt;
where  1=1&lt;br /&gt;
and    p.name = &amp;#039;undo_retention&amp;#039;&lt;br /&gt;
group  by p.name&lt;br /&gt;
,      p.description&lt;br /&gt;
,      p.value;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Set the retention to about 20% bigger than the maxquerylen.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select &amp;#039;alter system set undo_retention=&amp;#039;||round(1.2*max(maxquerylen))||&amp;#039; scope=both;&amp;#039; &amp;quot;Run this&amp;quot; from v$undostat;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
and set the undo retention guarantee (being aware of the consequences)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select tablespace_name&lt;br /&gt;
,      retention&lt;br /&gt;
from   dba_tablespaces;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter tablespace &amp;amp;undo_ts_name retention guarantee;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Optimise Oracle UNDO Parameters===&lt;br /&gt;
&lt;br /&gt;
The ideal undo_retention would be enough to hold rollback for the longest transaction that happened so far (can&amp;#039;t see into the future)&amp;lt;br /&amp;gt;&lt;br /&gt;
So current undo_retention = current value of undo / (db_block_size * undo blocks per sec)&amp;lt;br /&amp;gt;&lt;br /&gt;
* Undo Blocks per Second&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SELECT MAX(undoblks/((end_time-begin_time)*3600*24)) &amp;quot;UNDO_BLOCKS_PER_SEC&amp;quot;&lt;br /&gt;
FROM   v$undostat;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Optimal Undo Retention&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
col actual for 9999999999.99 heading &amp;quot;ACTUAL UNDO SIZE [MByte]&amp;quot;&lt;br /&gt;
col retent for 9999999999    heading &amp;quot;UNDO RETENTION [Sec]&amp;quot;&lt;br /&gt;
col needed for 9999999999.99 heading &amp;quot;NEEDED UNDO SIZE [Secs]&amp;quot;&lt;br /&gt;
&lt;br /&gt;
SELECT d.undo_size/(1024*1024) actual,&lt;br /&gt;
       to_number(SUBSTR(e.value,1,25)) retent,&lt;br /&gt;
       ROUND((d.undo_size / (to_number(f.value) *&lt;br /&gt;
       g.undo_block_per_sec))) needed&lt;br /&gt;
  FROM (&lt;br /&gt;
       SELECT SUM(a.bytes) undo_size&lt;br /&gt;
          FROM v$datafile a,&lt;br /&gt;
               v$tablespace b,&lt;br /&gt;
               dba_tablespaces c&lt;br /&gt;
         WHERE c.contents = &amp;#039;UNDO&amp;#039;&lt;br /&gt;
           AND c.status = &amp;#039;ONLINE&amp;#039;&lt;br /&gt;
           AND b.name = c.tablespace_name&lt;br /&gt;
           AND a.ts# = b.ts#&lt;br /&gt;
       ) d,&lt;br /&gt;
       v$parameter e,&lt;br /&gt;
       v$parameter f,&lt;br /&gt;
       (&lt;br /&gt;
       SELECT MAX(undoblks/((end_time-begin_time)*3600*24))&lt;br /&gt;
              undo_block_per_sec&lt;br /&gt;
         FROM v$undostat&lt;br /&gt;
       ) g&lt;br /&gt;
WHERE e.name = &amp;#039;undo_retention&amp;#039;&lt;br /&gt;
  AND f.name = &amp;#039;db_block_size&amp;#039;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Calculate Needed UNDO Size for given Database Activity&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
col actual for 9999999999.99 heading &amp;quot;ACTUAL UNDO SIZE [MByte]&amp;quot;&lt;br /&gt;
col retent for 9999999999    heading &amp;quot;UNDO RETENTION [Sec]&amp;quot;&lt;br /&gt;
col needed for 9999999999.99 heading &amp;quot;NEEDED UNDO SIZE [MByte]&amp;quot;&lt;br /&gt;
&lt;br /&gt;
SELECT d.undo_size/(1024*1024) actual&lt;br /&gt;
,      to_number(SUBSTR(e.value,1,25)) retent&lt;br /&gt;
,      (TO_NUMBER(e.value) * TO_NUMBER(f.value) *&lt;br /&gt;
       g.undo_block_per_sec) / (1024*1024)  needed&lt;br /&gt;
  FROM (&lt;br /&gt;
       SELECT SUM(a.bytes) undo_size&lt;br /&gt;
         FROM v$datafile a,&lt;br /&gt;
              v$tablespace b,&lt;br /&gt;
              dba_tablespaces c&lt;br /&gt;
        WHERE c.contents = &amp;#039;UNDO&amp;#039;&lt;br /&gt;
          AND c.status = &amp;#039;ONLINE&amp;#039;&lt;br /&gt;
          AND b.name = c.tablespace_name&lt;br /&gt;
          AND a.ts# = b.ts#&lt;br /&gt;
       ) d,&lt;br /&gt;
      v$parameter e,&lt;br /&gt;
       v$parameter f,&lt;br /&gt;
       (&lt;br /&gt;
       SELECT MAX(undoblks/((end_time-begin_time)*3600*24))&lt;br /&gt;
         undo_block_per_sec&lt;br /&gt;
         FROM v$undostat&lt;br /&gt;
       ) g&lt;br /&gt;
 WHERE e.name = &amp;#039;undo_retention&amp;#039;&lt;br /&gt;
  AND f.name = &amp;#039;db_block_size&amp;#039;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
It might be that the Export still fails with ORA-01555 even though retention seems long enough.&amp;lt;br /&amp;gt;&lt;br /&gt;
Are you running an export with the flashback_time parameter? If so, the undo_retention should be longer than the total export running time!&amp;lt;br /&amp;gt;&lt;br /&gt;
===Check LOB undo retention===&lt;br /&gt;
The retention settings for LOBS is different for the rest of the database.&amp;lt;br /&amp;gt;&lt;br /&gt;
When you change the UNDO_RETENTION parameter, the LOB segment’s retention value is NOT modified.&amp;lt;br /&amp;gt;&lt;br /&gt;
If you query the RETENTION column of the DBA_LOBS view, you will notice the old UNDO_RETENTION value still remains after you have modified the UNDO_RETENTION parameter.&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SQL&amp;gt; show parameter undo_&lt;br /&gt;
&lt;br /&gt;
NAME                                 TYPE        VALUE&lt;br /&gt;
------------------------------------ ----------- ------------------------------&lt;br /&gt;
undo_management                      string      AUTO&lt;br /&gt;
undo_retention                       integer     36000&lt;br /&gt;
undo_tablespace                      string      UNDOTBS1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SQL&amp;gt; desc SITEADMIN.AUDIT_LOG_MESSAGE&lt;br /&gt;
 Name                                      Null?    Type&lt;br /&gt;
 ----------------------------------------- -------- ----------------------------&lt;br /&gt;
 AUDIT_LOG_MESSAGE_ID                      NOT NULL NUMBER&lt;br /&gt;
 AUDIT_LOG_ID                              NOT NULL NUMBER&lt;br /&gt;
 SEQUENCE                                           NUMBER&lt;br /&gt;
 MESSAGE                                            CLOB&lt;br /&gt;
 CREATE_DATE                                        TIMESTAMP(6)&lt;br /&gt;
 COMPONENT_ID                                       VARCHAR2(50 CHAR)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 300&lt;br /&gt;
col column_name for a32&lt;br /&gt;
select table_name,column_name, pctversion,retention from dba_lobs where owner=&amp;#039;&amp;amp;table_owner&amp;#039;;&lt;br /&gt;
&lt;br /&gt;
TABLE_NAME                COLUMN_NAME                    PCTVERSION  RETENTION&lt;br /&gt;
------------------------- ------------------------------ ---------- ----------&lt;br /&gt;
EMAIL_STORE               CONTENT                                 0&lt;br /&gt;
EMAIL_STORE_ATTACHEMENT   ATTACHEMENT                             0&lt;br /&gt;
TRACKING                  ORIGINAL_MESSAGE                                 900&lt;br /&gt;
TRACKING                  MESSAGE                                          900&lt;br /&gt;
TRACKING                  SIEBEL_MESSAGE                                   900&lt;br /&gt;
WISE_WMS_LOG              WISE_WMS_XML                                     900&lt;br /&gt;
ATTACHMENT                ORIGINAL_MESSAGE                                 900&lt;br /&gt;
PLAN_TABLE                OTHER_XML                                        900&lt;br /&gt;
AUDIT_LOG_MESSAGE         MESSAGE                                          900&lt;br /&gt;
EXCEPTIONS                STACK_TRACE                                      900&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
To change the LOB segment’s RETENTION value to match the new UNDO_RETENTION value, do the following:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ALTER TABLE my_table MODIFY LOB (lob_column) (PCTVERSION 20);&lt;br /&gt;
ALTER TABLE my_table MODIFY LOB (lob_column) (RETENTION);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
By momentarily changing the LOB to use PCTVERSION and then back to RETENTION, the new value of UNDO_RETENTION will be used.&amp;lt;br /&amp;gt;&lt;br /&gt;
You need to do this for all LOB segments that you intend to modify.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select &amp;#039;ALTER TABLE &amp;#039;||owner||&amp;#039;.&amp;#039;||table_name||&amp;#039; MODIFY LOB (&amp;#039;||column_name||&amp;#039;) (PCTVERSION 20);&amp;#039; from dba_lobs where owner=&amp;#039;TIBCO&amp;#039;&lt;br /&gt;
&lt;br /&gt;
select &amp;#039;ALTER TABLE &amp;#039;||owner||&amp;#039;.&amp;#039;||table_name||&amp;#039; MODIFY LOB (&amp;#039;||column_name||&amp;#039;) (RETENTION);&amp;#039;     from dba_lobs where owner=&amp;#039;TIBCO&amp;#039;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
There is a table DBA_LOBS that displays information about all the LOB columns in the database, but it doesn&amp;#039;t actually store any LOB data, just metadata. The actual LOB segments in the database have system-generated names that take the form SYS_LOB*identifier*$$.&lt;br /&gt;
For example if you identify a segment named SYS_LOBidentifier$$ that is consuming space, you can find out what column of what table that LOB column maps to using the DBA_LOBS table:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 1000&lt;br /&gt;
col owner       for a20&lt;br /&gt;
col table_name  for a32&lt;br /&gt;
col column_name for a32&lt;br /&gt;
select owner&lt;br /&gt;
,      table_name&lt;br /&gt;
,      column_name&lt;br /&gt;
from   dba_lobs&lt;br /&gt;
where  1=1&lt;br /&gt;
and    segment_name = &amp;#039;SYS_LOB&amp;lt;&amp;lt;identifier&amp;gt;&amp;gt;$$&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====The Undo Advisor PL/SQL Interface====&lt;br /&gt;
You can activate the Undo Advisor by creating an undo advisor task through the advisor framework.&amp;lt;br /&amp;gt;&lt;br /&gt;
The following example creates an undo advisor task to evaluate the undo tablespace. The name of the advisor is &amp;#039;Undo Advisor&amp;#039;.&amp;lt;br /&amp;gt;&lt;br /&gt;
The analysis is based on Automatic Workload Repository snapshots, which you must specify by setting parameters START_SNAPSHOT and END_SNAPSHOT.&amp;lt;br /&amp;gt;&lt;br /&gt;
In the following example, the START_SNAPSHOT is &amp;quot;1&amp;quot; and END_SNAPSHOT is &amp;quot;2&amp;quot;.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
DECLARE&lt;br /&gt;
   tid    NUMBER;&lt;br /&gt;
   tname  VARCHAR2(30);&lt;br /&gt;
   oid    NUMBER;&lt;br /&gt;
BEGIN&lt;br /&gt;
   DBMS_ADVISOR.CREATE_TASK(&amp;#039;Undo Advisor&amp;#039;, tid, tname, &amp;#039;Undo Advisor Task&amp;#039;);&lt;br /&gt;
   DBMS_ADVISOR.CREATE_OBJECT(tname, &amp;#039;UNDO_TBS&amp;#039;, null, null, null, &amp;#039;null&amp;#039;, oid);&lt;br /&gt;
   DBMS_ADVISOR.SET_TASK_PARAMETER(tname, &amp;#039;TARGET_OBJECTS&amp;#039;, oid);&lt;br /&gt;
   DBMS_ADVISOR.SET_TASK_PARAMETER(tname, &amp;#039;START_SNAPSHOT&amp;#039;, 1);&lt;br /&gt;
   DBMS_ADVISOR.SET_TASK_PARAMETER(tname, &amp;#039;END_SNAPSHOT&amp;#039;, 2);&lt;br /&gt;
   DBMS_ADVISOR.SET_TASK_PARAMETER(tname, &amp;#039;INSTANCE&amp;#039;, 1);&lt;br /&gt;
   DBMS_ADVISOR.execute_task(tname);&lt;br /&gt;
        END;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
After you have created the advisor task, you can view the output and recommendations in the Automatic Database Diagnostic Monitor in Enterprise Manager.&amp;lt;br /&amp;gt;&lt;br /&gt;
This information is also available in the DBA_ADVISOR_* data dictionary views (DBA_ADVISOR_TASKS, DBA_ADVISOR_OBJECTS, DBA_ADVISOR_FINDINGS, DBA_ADVISOR_RECOMMENDATIONS, and so on).&lt;br /&gt;
====References====&lt;br /&gt;
* [http://www.akadia.com/services/ora_optimize_undo.html akadia.com]&lt;br /&gt;
* [http://dfitzjarrell.wordpress.com/2008/02/22/the-dreaded-ora-01555/ the dreaded ora-01555]&lt;br /&gt;
* [http://docs.oracle.com/cd/B28359_01/server.111/b28310/undo004.htm#ADMIN11469 docs.oracle.com]&lt;br /&gt;
&lt;br /&gt;
===Error 6 initializing SQL*Plus===&lt;br /&gt;
Using sqlplus or rman under Cygwin, ORACLE_HOME still needs to be windows format!&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Message file sp1&amp;lt;lang&amp;gt;.msb not found&lt;br /&gt;
SP2-0750 :You may need to set ORACLE_HOME to your Oracle software directory&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
so...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
export ORACLE_SID=KITRYD&lt;br /&gt;
ORAENV_ASK=NO&lt;br /&gt;
. oraenv&lt;br /&gt;
[[ &amp;quot;`uname`&amp;quot; == CYGWIN* ]] &amp;amp;&amp;amp; ORACLE_HOME=`cygpath -w ${ORACLE_HOME}`&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===ORA-2002: error while writing to audit trail===&lt;br /&gt;
Check the space left in the audit tablespace with:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select sum(bytes)/1024/1024 mb from dba_free_space where tablespace_name =&amp;#039;AUDIT_DT&amp;#039;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
If plenty of space, it can be due to Oracle clearing out the recyclebin at the same time.&amp;lt;br /&amp;gt;&lt;br /&gt;
If not, extend the datafile...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select * from dba_data_files where tablespace_name =&amp;#039;AUDIT_DT&amp;#039;;&lt;br /&gt;
alter database datafile 6 resize 30G;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
If that is not possible, clean out some audit data or add a datafile.&lt;br /&gt;
&lt;br /&gt;
===ORA-00449: background process &amp;#039;CKPT&amp;#039; unexpectedly terminated with error 7446===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SQL&amp;gt; startup nomount pfile=&amp;quot;/oracle/TRSCRP1/admin/initTRSCRP1.ora&amp;quot;&lt;br /&gt;
ORA-00449: background process &amp;#039;CKPT&amp;#039; unexpectedly terminated with error 7446&lt;br /&gt;
ORA-07446: sdnfy: bad value &amp;#039;&amp;#039; for parameter .&lt;br /&gt;
SQL&amp;gt; exit&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Solution&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SQL&amp;gt; mkdir /oracle/TRSCRP1/admin/bdump /oracle/TRSCRP1/admin/cdump&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORA-00845: MEMORY_TARGET not supported on this system===&lt;br /&gt;
* Reference: [http://arjudba.blogspot.be/2009/01/ora-00845-memorytarget-not-supported-on.html arjudba.blogspot.be]&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Problem Description&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SQL&amp;gt; STARTUP&lt;br /&gt;
ORA-00845: MEMORY_TARGET not supported on this system&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Cause&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
* Starting from Oracle 11g the automatic memory management feature is now defined with parameter MEMORY_TARGET and MEMMORY_MAX_TARGET.&lt;br /&gt;
* On linux file system the shared memory need to be mounted on /dev/shm directory on the operating system.&lt;br /&gt;
* And the size of /dev/shm needs to be greater than MEMORY_TARGET or MEMMORY_MAX_TARGET.&lt;br /&gt;
* The AMM (Automatic Memory Management) now in 11g manages both SGA and PGA together by MMAN process.&lt;br /&gt;
* The MEMORY_TARGET parameter in 11g comes for (SGA_TARGET+PGA_AGGREGATE_TARGET) which was in 10g.&lt;br /&gt;
* And MEMORY_MAX_TARGET parameter in 11g comes instead of SGA_MAX_TARGET parameter which was in 10g.&lt;br /&gt;
* The ORA-00845:can arises for the following two reasons on linux system.&lt;br /&gt;
1)If the shared memory which is mapped to /dev/shm directory is less than the size of MEMORY_TARGET or MEMORY_MAX_TARGET or&lt;br /&gt;
2)If the shared memory is not mapped to /dev/shm directory.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Solution&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Make sure /dev/shm is properly mounted. You can see it by,&lt;br /&gt;
#df -h or #df -k command.&lt;br /&gt;
The output should be similar to:&lt;br /&gt;
&lt;br /&gt;
$ df -k&lt;br /&gt;
Filesystem            Size  Used Avail Use% Mounted on&lt;br /&gt;
...&lt;br /&gt;
shmfs                 1G    512M 512M  50% /dev/shm&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
We see here for /dev/shm we have assigned 1G memory. Now if you set MEMORY_TARGET more than 1G then above ORA-845 will arise. For example if you have MEMORY_TARGET or MEMORY_MAX_TARGET set to 12G then you can mount shared memory to 13g like below.&lt;br /&gt;
As a root user,&lt;br /&gt;
# mount -t tmpfs shmfs -o size=13g /dev/shm&lt;br /&gt;
In order to make the settings persistence so that it will affect after restarting machine add an entry in /etc/fstab similar to the following:&lt;br /&gt;
&lt;br /&gt;
shmfs /dev/shm tmpfs size=13g 0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORA-24247: network access denied by access control list (ACL)===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Cause: No access control list (ACL) has been assigned to the target host or the privilege necessary to access the target host has not been granted to the user in the access control list.&lt;br /&gt;
&lt;br /&gt;
Action: Ensure that an access control list (ACL) has been assigned to the target host and the privilege necessary to access the target host has been granted to the user.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Your application will encounter an ORA-24247 error if it relies on one of the network packages and no proper ACL has been created. For the use of the following packages it is mandatory to have an ACL for the application user in place in 11g:&lt;br /&gt;
*UTL_TCP&lt;br /&gt;
*UTL_SMTP&lt;br /&gt;
*UTL_MAIL&lt;br /&gt;
*UTL_HTTP&lt;br /&gt;
*UTL_INADDR&lt;br /&gt;
Here is a very good explanation of how to setup the necessary ACLs: [[http://blog.whitehorses.nl/2010/03/17/oracle-11g-access-control-list-and-ora-24247/ whitehorses.nl]]&lt;br /&gt;
&lt;br /&gt;
===ORA-00600: internal error code, arguments: [qmx: no ref]===&lt;br /&gt;
Search &amp;quot;Master Note for Oracle XML Database (XDB) Install / Deinstall (Doc ID 1292089.1)&amp;quot; for more info.&lt;br /&gt;
====Problem:====&lt;br /&gt;
Sometimes one or more of the following errors can be encountered when installing or upgrading XDB, configuring APEX, running an Export, or selecting from xdb.xdb$resource or sys.dba_network_acls:&amp;lt;br /&amp;gt;&lt;br /&gt;
* ORA-31159: XML DB is in an invalid state&lt;br /&gt;
* ORA-00600: internal error code, arguments: [unable to load XDB library]&lt;br /&gt;
* ORA-00600: internal error code, arguments: [qmx: no ref]&lt;br /&gt;
* ORA-00600: internal error code, arguments: [qmtGetColumnInfo1]&lt;br /&gt;
* ORA-00600: internal error code, arguments: [qmtb_init_len]&lt;br /&gt;
* ORA-00600: internal error code, arguments: [qmtGetBaseType]&lt;br /&gt;
* ORA-00600: internal error code, arguments: [psdnop-1], [600]&lt;br /&gt;
* ORA-00600: internal error code, arguments: [qmtInit1]&lt;br /&gt;
* ORA-07445: exception encountered: core dump [_memcpy()+224] [SIGSEGV] [Address not mapped to object]&lt;br /&gt;
* ORA-19051 Cannot Use Fast Path Insert For This XMLType Table&lt;br /&gt;
* ORA-31011: XML parsing failed&lt;br /&gt;
Errors of this sort generally occur when the init routines for the internal XDB functions are run in an invalid environment causing memory corruption.&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
This can happen if the database was ever started with the LD_LIBRARY_PATH (LIBPATH for AIX or SHLIB_PATH for HP) pointing to the wrong $ORACLE_HOME/lib directory rather than to the correct location for the instance.&amp;lt;br /&amp;gt;&lt;br /&gt;
The LD_LIBRARY_PATH/LIBPATH/SHLIB_PATH environment variable is used to resolve the location of the shared library &amp;quot;libxdb.so (libxdb.sl on HP)&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
====Solution:====&lt;br /&gt;
* Stop Listener&lt;br /&gt;
* Stop database&lt;br /&gt;
* Ensure $ORACLE_HOME/lib is at the start of LD_LIBRARY_PATH / LIBPATH / SHLIB_PATH&lt;br /&gt;
* If AIX, run /usr/sbin/slibclean as root&lt;br /&gt;
* Start database&lt;br /&gt;
* Start listener&lt;br /&gt;
&lt;br /&gt;
===ORA-00201: control file version nn.nn.nn.nn incompatible with ORACLE version===&lt;br /&gt;
Trying to restore a database after complete failure&amp;lt;br /&amp;gt;&lt;br /&gt;
first step is to startup the database in nomount mode and restore the controlfile - succeeded.&amp;lt;br /&amp;gt;&lt;br /&gt;
second step, startup the database in mount mode ready for database restore...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SQL*Plus: Release 10.2.0.3.0 - Production on Wed Aug 19 18:16:47 2015&lt;br /&gt;
&lt;br /&gt;
Copyright (c) 1982, 2006, Oracle.  All Rights Reserved.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Connected to:&lt;br /&gt;
Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - 64bit Production&lt;br /&gt;
With the Partitioning, OLAP and Data Mining options&lt;br /&gt;
&lt;br /&gt;
SYS@CODWHP1&amp;gt; startup mount&lt;br /&gt;
ORACLE instance started.&lt;br /&gt;
&lt;br /&gt;
Total System Global Area  260046848 bytes&lt;br /&gt;
Fixed Size                  2029296 bytes&lt;br /&gt;
Variable Size             113248528 bytes&lt;br /&gt;
Database Buffers          134217728 bytes&lt;br /&gt;
Redo Buffers               10551296 bytes&lt;br /&gt;
ORA-00201: control file version 10.2.0.0.0 incompatible with ORACLE version 10.2.0.3.0&lt;br /&gt;
ORA-00202: control file: &amp;#039;/oracle/CODWHP1/product/10203/dbs/cntrlCODWHP1.dbf&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The problem was there was no compatible parameter in the simple init file I used to start up the instance.&amp;lt;br /&amp;gt;&lt;br /&gt;
Adding compatible parameter to init file to be same version (10.2.0.3) allowed the db to mount.&lt;br /&gt;
&lt;br /&gt;
===TNS-00525: Insufficient privilege for operation===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
lsnrctl start LISTENER_UCLID55V&lt;br /&gt;
&lt;br /&gt;
LSNRCTL for IBM/AIX RISC System/6000: Version 11.2.0.3.0 - Production on 26-MAR-2015 13:36:14&lt;br /&gt;
&lt;br /&gt;
Copyright (c) 1991, 2011, Oracle.  All rights reserved.&lt;br /&gt;
&lt;br /&gt;
Starting /oracle/product/11.2.0.3/bin/tnslsnr: please wait...&lt;br /&gt;
&lt;br /&gt;
TNSLSNR for IBM/AIX RISC System/6000: Version 11.2.0.3.0 - Production&lt;br /&gt;
System parameter file is /oracle/product/11.2.0.3/network/admin/listener.ora&lt;br /&gt;
Log messages written to /oracle/product/diag/tnslsnr/solax082/listener_uclid55v/alert/log.xml&lt;br /&gt;
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=150.251.114.238)(PORT=1525)))&lt;br /&gt;
Error listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC1525)))&lt;br /&gt;
TNS-12555: TNS:permission denied&lt;br /&gt;
 TNS-12560: TNS:protocol adapter error&lt;br /&gt;
  TNS-00525: Insufficient privilege for operation&lt;br /&gt;
   IBM/AIX RISC System/6000 Error: 1: Not owner&lt;br /&gt;
&lt;br /&gt;
Listener failed to start. See the error message(s) above...&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This would suggest the user attempting to start the listener has no access to either the Oracle binaries or the TNS listener/tnsnames files.&amp;lt;br /&amp;gt;&lt;br /&gt;
But... checkout the /tmp/.oracle directory :-)&amp;lt;br /&amp;gt;&lt;br /&gt;
That hidden gem shows who started the listener last time. Delete the relevant entry and try again!&amp;lt;br /&amp;gt;&lt;br /&gt;
To start from a clean sheet, stop all listeners, delete this directory and restart the listeners.&lt;br /&gt;
&lt;br /&gt;
===ORA-12003: materialized view or zonemap &amp;quot;KPK&amp;quot;.&amp;quot;EVD01_NEW&amp;quot; does not exist===&lt;br /&gt;
Here&amp;#039;s one you shouldn&amp;#039;t see very often.&amp;lt;br /&amp;gt;&lt;br /&gt;
Trying to drop a tablespace but prevented from doing so because a materialized view has referential contraints on a table in this tablespace.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SQL&amp;gt; drop tablespace TS_THALER_PART_OLD including contents and datafiles cascade constraints;&lt;br /&gt;
drop tablespace TS_THALER_PART_OLD including contents and datafiles cascade constraints&lt;br /&gt;
*&lt;br /&gt;
ERROR at line 1:&lt;br /&gt;
ORA-00604: error occurred at recursive SQL level 1&lt;br /&gt;
ORA-12083: must use DROP MATERIALIZED VIEW to drop &amp;quot;KPK&amp;quot;.&amp;quot;EVD01_NEW&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Ok, nice of Oracle to tell us what we have to do. Simple enough. Let&amp;#039;s drop the materialized view.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SQL&amp;gt; DROP MATERIALIZED VIEW &amp;quot;KPK&amp;quot;.&amp;quot;EVD01_NEW&amp;quot;;&lt;br /&gt;
DROP MATERIALIZED VIEW &amp;quot;KPK&amp;quot;.&amp;quot;EVD01_NEW&amp;quot;&lt;br /&gt;
*&lt;br /&gt;
ERROR at line 1:&lt;br /&gt;
ORA-12003: materialized view or zonemap &amp;quot;KPK&amp;quot;.&amp;quot;EVD01_NEW&amp;quot; does not exist&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Aah. Not so obvious then.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
desc &amp;quot;KPK&amp;quot;.&amp;quot;EVD01_NEW&amp;quot;&lt;br /&gt;
 Name                                      Null?    Type&lt;br /&gt;
 ----------------------------------------- -------- ----------------------------&lt;br /&gt;
 DATMAJ                                             VARCHAR2(8 CHAR)&lt;br /&gt;
 HEUMAJ                                             VARCHAR2(8 CHAR)&lt;br /&gt;
 PGMMAJ                                             VARCHAR2(6 CHAR)&lt;br /&gt;
 NATOPN                                             VARCHAR2(6 CHAR)&lt;br /&gt;
 REFEXN                                             VARCHAR2(50 CHAR)&lt;br /&gt;
 SWIOLN                                             VARCHAR2(1 CHAR)&lt;br /&gt;
 STAEVT                                             VARCHAR2(4 CHAR)&lt;br /&gt;
 REFEVT                                             VARCHAR2(16 CHAR)&lt;br /&gt;
 NUMIDT                                             VARCHAR2(30 CHAR)&lt;br /&gt;
 ORIEVT                                             VARCHAR2(10 CHAR)&lt;br /&gt;
 REFLOG                                             VARCHAR2(16 CHAR)&lt;br /&gt;
 MSGEVT_CPL                                         VARCHAR2(1500 CHAR)&lt;br /&gt;
 REFOPN                                             VARCHAR2(16 CHAR)&lt;br /&gt;
 DATEVT                                             VARCHAR2(8 CHAR)&lt;br /&gt;
 MSGEVT_FIL_1                                       VARCHAR2(2000 CHAR)&lt;br /&gt;
 MSGEVT_FIL_2                                       VARCHAR2(2000 CHAR)&lt;br /&gt;
 MSGEVT_SPE                                         VARCHAR2(200 CHAR)&lt;br /&gt;
 DATEFF                                             VARCHAR2(8 CHAR)&lt;br /&gt;
 TMSTMP                                             VARCHAR2(15 CHAR)&lt;br /&gt;
 VEREVT                                             VARCHAR2(3 CHAR)&lt;br /&gt;
 MSGEVT_FIL_3                                       VARCHAR2(2000 CHAR)&lt;br /&gt;
 MSGEVT_FIL_4                                       VARCHAR2(2000 CHAR)&lt;br /&gt;
 TYPEVT                                             VARCHAR2(5 CHAR)&lt;br /&gt;
 SBP_CODAPP                                         VARCHAR2(10 CHAR)&lt;br /&gt;
 SBP_REFINT                                         VARCHAR2(36 CHAR)&lt;br /&gt;
 SBP_TYPACT                                         VARCHAR2(2 CHAR)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
It exists... but as a table.&amp;lt;br /&amp;gt;&lt;br /&gt;
Something has gone wrong in the database somewhere. As it turns out after some deeper investigation, this database is a copy of production but &amp;quot;with modifications&amp;quot;.&amp;lt;br /&amp;gt;&lt;br /&gt;
After the cloning process, a schema needed renaming. Oracle have a procedure for this but it is very long-winded and time-consuming. It uses export and import with transportable tablespaces to do the remap of the schema.&amp;lt;br /&amp;gt;&lt;br /&gt;
An unsupported workaround to rename schema is to simply update the username in sys.user$ and restart the database.&amp;lt;br /&amp;gt;&lt;br /&gt;
This works for the most part but now we see a consequence of that action.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
col owner      for a30&lt;br /&gt;
col mview_name for a30&lt;br /&gt;
select owner&lt;br /&gt;
,      mview_name&lt;br /&gt;
from   dba_mviews&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
OWNER                          MVIEW_NAME&lt;br /&gt;
------------------------------ ------------------------------&lt;br /&gt;
EPK                            EVD01_NEW&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Ahaa, there&amp;#039;s the materialized view but the owner is different from the one described by the database error message above. This one is the owner as it was on production.&amp;lt;br /&amp;gt;&lt;br /&gt;
This means the owner of materialized views has been denormalised for some reason. Reading the (complex) view text of dba_mviews, we see the owner column is based on sys.snap$.sowner&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
col sowner for a20&lt;br /&gt;
col vname  for a20&lt;br /&gt;
col tname  for a20&lt;br /&gt;
select sowner&lt;br /&gt;
,      vname&lt;br /&gt;
,      tname&lt;br /&gt;
from   sys.snap$&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
SOWNER               VNAME                TNAME&lt;br /&gt;
-------------------- -------------------- --------------------&lt;br /&gt;
EPK                  EVD01_NEW            EVD01_NEW&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
For future reference when updating the username in sys.user$, update the snapshot owner in this table as well!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
update sys.snap$&lt;br /&gt;
set    sowner = &amp;#039;KPK&amp;#039;&lt;br /&gt;
where  sowner = &amp;#039;EPK&amp;#039;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Try again&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
DROP MATERIALIZED VIEW &amp;quot;KPK&amp;quot;.&amp;quot;EVD01_NEW&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
Materialized view dropped.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
yep, and the tablespace?&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
drop tablespace TS_THALER_PART_OLD including contents and datafiles cascade constraints;&lt;br /&gt;
&lt;br /&gt;
Tablespace dropped.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORA-12162: TNS:net service name is incorrectly specified===&lt;br /&gt;
Probably nothing to do with TNS. Check your ORACLE_SID is set correctly!&lt;br /&gt;
&lt;br /&gt;
===ORA-00054: resource busy and acquire with NOWAIT specified===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SELECT O.OBJECT_NAME, S.SID, S.SERIAL#, P.SPID, S.PROGRAM,S.USERNAME,&lt;br /&gt;
S.MACHINE,S.PORT , S.LOGON_TIME,SQ.SQL_FULLTEXT &lt;br /&gt;
FROM V$LOCKED_OBJECT L, DBA_OBJECTS O, V$SESSION S, &lt;br /&gt;
V$PROCESS P, V$SQL SQ &lt;br /&gt;
WHERE L.OBJECT_ID = O.OBJECT_ID &lt;br /&gt;
AND L.SESSION_ID = S.SID AND S.PADDR = P.ADDR &lt;br /&gt;
AND S.SQL_ADDRESS = SQ.ADDRESS;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select object_name, s.sid, s.serial#, p.spid &lt;br /&gt;
from v$locked_object l, dba_objects o, v$session s, v$process p&lt;br /&gt;
where l.object_id = o.object_id and l.session_id = s.sid and s.paddr = p.addr;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
then&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter system kill session &amp;#039;sid,serial#&amp;#039;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORA-12518: TNS:listener could not hand off client connection===&lt;br /&gt;
The database you are trying to connect to is probably on its knees. Check server memory is not exhausted.&lt;br /&gt;
&lt;br /&gt;
===ORA-12520: TNS:listener could not find available handler for requested type of server===&lt;br /&gt;
Strangely this could be related to number of processes being exhausted.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
show parameter processes&lt;br /&gt;
alter system set processes=350 scope=spfile;&lt;br /&gt;
shutdown immediate&lt;br /&gt;
startup&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORA-12541: TNS: no listener===&lt;br /&gt;
Either very basic - start the listener!&amp;lt;br /&amp;gt;&lt;br /&gt;
or, as in our case - not so obvious.&amp;lt;br /&amp;gt;&lt;br /&gt;
We use virtual IP addresses so that the IP address stays the same after failover to standby.&amp;lt;br /&amp;gt;&lt;br /&gt;
Due to some confused configuration, we got the network adapter on two different servers to have the same IP address.&amp;lt;br /&amp;gt;&lt;br /&gt;
Stop the IP address on the bad server (assign another one) and all is fine again.&lt;br /&gt;
===ORA-12514: TNS:listener does not currently know of service===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
lsnrctl status &amp;lt;listener_name&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Been altering tnsnames.ora or listener.ora?&lt;br /&gt;
* Check the local_listener parameter&lt;br /&gt;
Try resetting it to itself. Strange but if you are not using port 1521, this can work wonders!&amp;lt;br /&amp;gt;&lt;br /&gt;
Assuming listener is called LISTENER_WM9T:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter system set local_listener=LISTENER_WM9T scope=both;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Try and connect with the service name or directly with&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sqlplus &amp;#039;sys/*******&amp;#039;@&amp;lt;host&amp;gt;:&amp;lt;port&amp;gt;/&amp;lt;SID&amp;gt; as sysdba&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Excellent description of how Oracle TNS listeners work and a checklist on how to fix this error&amp;lt;br /&amp;gt;&lt;br /&gt;
* [[http://edstevensdba.wordpress.com/2011/03/19/ora-12514/ TNS — Ed Stevens]]&lt;br /&gt;
&lt;br /&gt;
===ORA-12547: TNS lost contact===&lt;br /&gt;
&lt;br /&gt;
If&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sqlplus &amp;lt;user&amp;gt;/&amp;lt;pass&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
fails with above error, try&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sqlplus &amp;lt;user&amp;gt;/&amp;lt;pass&amp;gt;@&amp;lt;db connection&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
If this works, it is most probably a permissions error.&amp;lt;br /&amp;gt;&lt;br /&gt;
Re-run the&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ORACLE_HOME/root.sh&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
script that was run as part of the original installation. This will reset the permissions on some important files.&lt;br /&gt;
===ORA-02374: conversion error loading table &amp;quot;BLENGADM&amp;quot;.&amp;quot;ZZ_EVTCTA&amp;quot;===&lt;br /&gt;
This is typical of importing data with Datapump when the tables in the source database were created with &amp;quot;byte&amp;quot; semantics and the destination is &amp;quot;char&amp;quot; semantics.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ORA-02374: conversion error loading table &amp;quot;BLENGADM&amp;quot;.&amp;quot;ZZ_EVTCTA&amp;quot;&lt;br /&gt;
ORA-12899: value too large for column NOMCTA (actual: 257, maximum: 256)&lt;br /&gt;
&lt;br /&gt;
ORA-02372: data for row: NOMCTA : 0X&amp;#039;4C6976726574206427E9706172676E65202020202020202020&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Problem====&lt;br /&gt;
The root cause is the nls_length_semantics of the table columns being BYTE where one character is assigned one byte. But after conversion in a multi-byte database, one character is larger than one byte (could be 2, 3 or 4) and no longer fits.&lt;br /&gt;
====Solution====&lt;br /&gt;
* import the metadata&lt;br /&gt;
Run the impdp command with content=metadata_only. This will create all the tables (still in their original form) but not the data.&lt;br /&gt;
* alter the BYTE columns in the affected tables to CHAR semantics&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select column_name&lt;br /&gt;
,      char_used&lt;br /&gt;
,      data_length&lt;br /&gt;
,      data_type &lt;br /&gt;
from   user_tab_columns &lt;br /&gt;
where  table_name = &amp;#039;T&amp;#039;&lt;br /&gt;
and    char_used = &amp;#039;B&amp;#039;;&lt;br /&gt;
COLUMN_NAME  C DATA_LENGTH DATA_TYPE&lt;br /&gt;
------------ - ----------- ---------&lt;br /&gt;
X            B           1 VARCHAR2&lt;br /&gt;
SQL&amp;gt; alter table t modify x varchar2(1 char);&lt;br /&gt;
Table altered.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Import the data&lt;br /&gt;
Rerun the impdp ensuring table_exists_action is not REPLACE (use truncate or append). This now imports the data into the modified tables.&lt;br /&gt;
====This script does the donkey work of altering table column semantics from byte to char====&lt;br /&gt;
The author of this script is unknown but he/she deserves a medal. It saves countless hours of work and is so well written.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/*&lt;br /&gt;
  The script converts all the VARCHAR2 columns in the user&amp;#039;s schema&lt;br /&gt;
  to CHAR length semantics. Known to work on 10.2.0.4 and later.&lt;br /&gt;
  &lt;br /&gt;
  Script must be executed against the database without any other client&lt;br /&gt;
  and/or application connections to the affected schema.&lt;br /&gt;
  &lt;br /&gt;
  Oracle does not support CHAR semantics for the built-in schemas,&lt;br /&gt;
  like SYS, SYSTEM or SYSMAN, so the script will throw an error,&lt;br /&gt;
  if attempt to run it against any one of them.&lt;br /&gt;
  &lt;br /&gt;
  Upon completion database objects that have dependencies on tables&lt;br /&gt;
  being modified will be invalidated. Oracle usually re-compiles invalidated&lt;br /&gt;
  objects on the first access. Alternatively, a DBA can execute UTLPRP script&lt;br /&gt;
  to recompile all invalid objects in the entire database.&lt;br /&gt;
  &lt;br /&gt;
  Upon completion, please make sure that NLS_LENGTH_SEMANTICS instance parameter&lt;br /&gt;
  is set to CHAR to ensure further upgradability of the schema.&lt;br /&gt;
*/&lt;br /&gt;
set serveroutput on size unlimited format wrap&lt;br /&gt;
declare&lt;br /&gt;
  type sql_list_t is table of varchar2(32767) index by pls_integer;&lt;br /&gt;
  type idx_list_t is table of user_indexes.index_name%type index by pls_integer;&lt;br /&gt;
  type col_list_t is table of user_tab_columns%rowtype index by pls_integer;&lt;br /&gt;
  --&lt;br /&gt;
  lv_col_cnt   pls_integer := 0;&lt;br /&gt;
  lv_idx_cnt   pls_integer := 0;&lt;br /&gt;
  lv_char_set  pls_integer := 0; &lt;br /&gt;
  lv_user      user_users.username%type;&lt;br /&gt;
  lv_sql_stmt  varchar2(32767);&lt;br /&gt;
  lv_byte_cols col_list_t;&lt;br /&gt;
  lv_idx_names idx_list_t;&lt;br /&gt;
  lv_idx_ddls  sql_list_t;&lt;br /&gt;
  --&lt;br /&gt;
  procedure run_sql_stmt&lt;br /&gt;
  (&lt;br /&gt;
   p_sql_stmt in varchar2&lt;br /&gt;
  )&lt;br /&gt;
  as&lt;br /&gt;
  begin&lt;br /&gt;
    execute immediate p_sql_stmt;&lt;br /&gt;
  exception&lt;br /&gt;
    when others&lt;br /&gt;
    then&lt;br /&gt;
      raise_application_error(-20202, &amp;#039;Failed statement [&amp;#039; || p_sql_stmt || dbms_utility.format_error_backtrace() || &amp;#039;]&amp;#039;, true);&lt;br /&gt;
  end;&lt;br /&gt;
begin&lt;br /&gt;
  --&lt;br /&gt;
  lv_user := user();&lt;br /&gt;
  if lv_user in (&amp;#039;SYS&amp;#039;, &amp;#039;SYSTEM&amp;#039;, &amp;#039;SYSMAN&amp;#039;)&lt;br /&gt;
  then&lt;br /&gt;
    raise_application_error(-20202, &amp;#039;This script cannot be executed against Oracle built-in schema [&amp;#039; || lv_user || &amp;#039;].&amp;#039;);&lt;br /&gt;
  end if;&lt;br /&gt;
  --&lt;br /&gt;
  select&lt;br /&gt;
         *&lt;br /&gt;
         bulk collect into lv_byte_cols&lt;br /&gt;
  from&lt;br /&gt;
         user_tab_columns uc&lt;br /&gt;
  where&lt;br /&gt;
         uc.char_used = &amp;#039;B&amp;#039;&lt;br /&gt;
         and&lt;br /&gt;
         substr(uc.table_name, 1, 4) != &amp;#039;BIN$&amp;#039;&lt;br /&gt;
         and&lt;br /&gt;
         not exists&lt;br /&gt;
         (&lt;br /&gt;
          select 1&lt;br /&gt;
          from   user_views uv&lt;br /&gt;
          where  uv.view_name = uc.table_name&lt;br /&gt;
         )&lt;br /&gt;
  ;&lt;br /&gt;
  --&lt;br /&gt;
  lv_col_cnt := lv_byte_cols.count();&lt;br /&gt;
  --&lt;br /&gt;
  dbms_output.enable();&lt;br /&gt;
  --&lt;br /&gt;
  if lv_col_cnt &amp;gt; 0&lt;br /&gt;
  then&lt;br /&gt;
    for idx_rw in&lt;br /&gt;
    (&lt;br /&gt;
     select index_name &lt;br /&gt;
     from   user_indexes&lt;br /&gt;
     where  index_type = &amp;#039;FUNCTION-BASED NORMAL&amp;#039;&lt;br /&gt;
    )&lt;br /&gt;
    loop&lt;br /&gt;
      lv_idx_cnt := lv_idx_cnt + 1;&lt;br /&gt;
      lv_idx_names(lv_idx_cnt) := idx_rw.index_name;&lt;br /&gt;
      lv_idx_ddls(lv_idx_cnt) := replace&lt;br /&gt;
                                 (&lt;br /&gt;
                                  dbms_metadata.get_ddl&lt;br /&gt;
                                  (&lt;br /&gt;
                                   object_type =&amp;gt; &amp;#039;INDEX&amp;#039;,&lt;br /&gt;
                                   name        =&amp;gt; idx_rw.index_name&lt;br /&gt;
                                  )&lt;br /&gt;
                                  ,&lt;br /&gt;
                                  &amp;#039;;&amp;#039;&lt;br /&gt;
                                 );&lt;br /&gt;
      lv_sql_stmt := &amp;#039;drop index &amp;#039; || idx_rw.index_name;&lt;br /&gt;
      run_sql_stmt(lv_sql_stmt);&lt;br /&gt;
      dbms_output.put_line(&amp;#039;Dropped function-based index: &amp;#039; || idx_rw.index_name);&lt;br /&gt;
      dbms_output.put_line(&amp;#039;In case of script failure, restore the index by running the DDL statement below:&amp;#039;);&lt;br /&gt;
      dbms_output.put_line(lv_idx_ddls(lv_idx_cnt) || &amp;#039;;&amp;#039;);&lt;br /&gt;
    end loop;&lt;br /&gt;
    --&lt;br /&gt;
    for i in 1..lv_col_cnt&lt;br /&gt;
    loop&lt;br /&gt;
      lv_sql_stmt :=  &amp;#039;alter table &amp;#039; || lv_byte_cols(i).table_name || &amp;#039; modify (&amp;#039; ||&lt;br /&gt;
                      lv_byte_cols(i).column_name || &amp;#039; &amp;#039; || lv_byte_cols(i).data_type ||&lt;br /&gt;
                      &amp;#039;(&amp;#039; || lv_byte_cols(i).char_length || &amp;#039; char))&amp;#039;;&lt;br /&gt;
      run_sql_stmt(lv_sql_stmt);&lt;br /&gt;
    end loop;&lt;br /&gt;
    --&lt;br /&gt;
    dbms_output.new_line();&lt;br /&gt;
    for i in 1..lv_idx_cnt&lt;br /&gt;
    loop&lt;br /&gt;
      run_sql_stmt(lv_idx_ddls(i));&lt;br /&gt;
      dbms_output.put_line(&amp;#039;Recreated function-based index: &amp;#039; || lv_idx_names(i));&lt;br /&gt;
    end loop;&lt;br /&gt;
    --&lt;br /&gt;
    dbms_output.new_line();&lt;br /&gt;
    dbms_output.put_line&lt;br /&gt;
    (&lt;br /&gt;
     &amp;#039;Updated length semantics to CHAR for &amp;#039; || lv_col_cnt || &amp;#039; column&amp;#039; ||&lt;br /&gt;
     case when lv_col_cnt &amp;gt; 1&lt;br /&gt;
          then &amp;#039;s&amp;#039;&lt;br /&gt;
     end ||&lt;br /&gt;
     &amp;#039; in the schema [&amp;#039; || lv_user || &amp;#039;].&amp;#039;&lt;br /&gt;
    );&lt;br /&gt;
  else&lt;br /&gt;
    dbms_output.put_line(&amp;#039;No columns with BYTE length semantics were found in the schema [&amp;#039; || lv_user || &amp;#039;].&amp;#039;);&lt;br /&gt;
  end if;&lt;br /&gt;
  --&lt;br /&gt;
  select count(*) into lv_char_set&lt;br /&gt;
  from   nls_session_parameters&lt;br /&gt;
  where  parameter = &amp;#039;NLS_LENGTH_SEMANTICS&amp;#039;&lt;br /&gt;
         and&lt;br /&gt;
         value = &amp;#039;CHAR&amp;#039;&lt;br /&gt;
  ;&lt;br /&gt;
  --&lt;br /&gt;
  if lv_char_set = 0&lt;br /&gt;
  then&lt;br /&gt;
    dbms_output.put_line(&amp;#039;WARNING: Do not forget to change instance parameter NLS_LENGTH_SEMANTICS to CHAR and restart the database.&amp;#039;);&lt;br /&gt;
  end if;&lt;br /&gt;
end;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORA-14097: column type or size mismatch in ALTER TABLE EXCHANGE PARTITION===&lt;br /&gt;
Also can be &amp;lt;tt&amp;gt;ORA-54033: column to be modified is used in a virtual column expression&amp;lt;/tt&amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;
Nothing especially to do with partitions - just any ddl operation that affects the table.&amp;lt;br /&amp;gt;&lt;br /&gt;
Hidden columns do not normally show up in a desc unless colinvisible is on&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set colinvisible on&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
But these sneaky system-generated ones don&amp;#039;t show up even with that setting on!  You need to show them with this:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set pages 50 lines 1000&lt;br /&gt;
col column_name for a40&lt;br /&gt;
col data_default for a40&lt;br /&gt;
select internal_column_id, column_name, data_default, hidden_column, virtual_column from dba_tab_cols where table_name =&amp;#039;XND40&amp;#039;;&lt;br /&gt;
&lt;br /&gt;
INTERNAL_COLUMN_ID COLUMN_NAME                                        DATA_DEFAULT                                       HIDDEN_COLUM VIRTUAL_COLU&lt;br /&gt;
------------------ -------------------------------------------------- -------------------------------------------------- ------------ ------------&lt;br /&gt;
                35 MONLOT_REC_CDR                                     &amp;#039;0&amp;#039;                                                NO           NO&lt;br /&gt;
                34 MONLOT_REC_DBT                                     &amp;#039;0&amp;#039;                                                NO           NO&lt;br /&gt;
                33 MONLOT_CAL_CDR                                     &amp;#039;0&amp;#039;                                                NO           NO&lt;br /&gt;
                32 MONLOT_CAL_DBT                                     &amp;#039;0&amp;#039;                                                NO           NO&lt;br /&gt;
                31 MONMVT_CPT                                         &amp;#039;0&amp;#039;                                                NO           NO&lt;br /&gt;
                30 SENNOT                                             &amp;#039; &amp;#039;                                                NO           NO&lt;br /&gt;
                29 NUMSEQ                                                                                                NO           NO&lt;br /&gt;
                28 NOMFIC                                                                                                NO           NO&lt;br /&gt;
                27 TOTCPT_REC                                                                                            NO           NO&lt;br /&gt;
                26 TOTCPT_CAL                                                                                            NO           NO&lt;br /&gt;
                25 MONLOT_REC                                                                                            NO           NO&lt;br /&gt;
                24 MONLOT_CAL                                                                                            NO           NO&lt;br /&gt;
                23 NBRELE_REC                                                                                            NO           NO&lt;br /&gt;
                22 NBRELE_CAL                                                                                            NO           NO&lt;br /&gt;
                21 NUMCPT_GLO                                                                                            NO           NO&lt;br /&gt;
                20 DEVLOT                                                                                                NO           NO&lt;br /&gt;
                19 CODERR                                                                                                NO           NO&lt;br /&gt;
                18 CANLOT                                                                                                NO           NO&lt;br /&gt;
                17 REFTEX                                                                                                NO           NO&lt;br /&gt;
                16 REFEXN                                                                                                NO           NO&lt;br /&gt;
                15 ETTLOT                                                                                                NO           NO&lt;br /&gt;
                14 TYPLOT                                                                                                NO           NO&lt;br /&gt;
                13 DATEXC                                                                                                NO           NO&lt;br /&gt;
                12 STALOT                                                                                                NO           NO&lt;br /&gt;
                11 REFLOT                                                                                                NO           NO&lt;br /&gt;
                10 USRAUT                                                                                                NO           NO&lt;br /&gt;
                 9 HEUAUT                                                                                                NO           NO&lt;br /&gt;
                 8 DATAUT                                                                                                NO           NO&lt;br /&gt;
                 7 PGMMAJ                                                                                                NO           NO&lt;br /&gt;
                 6 USRMAJ                                                                                                NO           NO&lt;br /&gt;
                 5 HEUMAJ                                                                                                NO           NO&lt;br /&gt;
                 4 DATMAJ                                                                                                NO           NO&lt;br /&gt;
                 3 DATCRT                                                                                                NO           NO&lt;br /&gt;
                 2 REFMAJ                                                                                                NO           NO&lt;br /&gt;
                 1 NUMVER                                                                                                NO           NO&lt;br /&gt;
                36 SYS_STS#KR2WNV5L070XKV1L5H7REH                     SYS_OP_COMBINED_HASH(&amp;quot;NOMFIC&amp;quot;,&amp;quot;NUMSEQ&amp;quot;)            YES          YES&lt;br /&gt;
&lt;br /&gt;
36 rows selected.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
That last row means extended statistics have been generated for 2 columns in this table.&amp;lt;br /&amp;gt;&lt;br /&gt;
You can see this because the name begins with SYS_STS. If it begins with SYS_&amp;lt;something else&amp;gt; then it is not extended statistics.&amp;lt;br /&amp;gt;&lt;br /&gt;
It may be an unused column. Original [https://dba.stackexchange.com/questions/196248/what-is-the-sys-c00054-140314103403-column-in-my-regular-oracle-table here]&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
create table t1 as select * from dba_roles;&lt;br /&gt;
&lt;br /&gt;
Table created.&lt;br /&gt;
&lt;br /&gt;
desc t1&lt;br /&gt;
 Name                                      Null?    Type&lt;br /&gt;
 ----------------------------------------- -------- ----------------------------&lt;br /&gt;
 ROLE                                      NOT NULL VARCHAR2(30)&lt;br /&gt;
 PASSWORD_REQUIRED                                  VARCHAR2(8)&lt;br /&gt;
 AUTHENTICATION_TYPE                                VARCHAR2(11)&lt;br /&gt;
&lt;br /&gt;
alter table t1 set unused (AUTHENTICATION_TYPE);&lt;br /&gt;
&lt;br /&gt;
Table altered.&lt;br /&gt;
&lt;br /&gt;
desc t1&lt;br /&gt;
 Name                                      Null?    Type&lt;br /&gt;
 ----------------------------------------- -------- ----------------------------&lt;br /&gt;
 ROLE                                      NOT NULL VARCHAR2(30)&lt;br /&gt;
 PASSWORD_REQUIRED                                  VARCHAR2(8)&lt;br /&gt;
&lt;br /&gt;
select column_name from dba_tab_cols where owner = &amp;#039;&amp;amp;owner.&amp;#039; and table_name = &amp;#039;&amp;amp;table_name.&amp;#039;;&lt;br /&gt;
&lt;br /&gt;
COLUMN_NAME&lt;br /&gt;
------------------------------&lt;br /&gt;
SYS_C00003_18012517:25:39$&lt;br /&gt;
PASSWORD_REQUIRED&lt;br /&gt;
ROLE&lt;br /&gt;
&lt;br /&gt;
SQL&amp;gt; alter table t1 drop unused columns;&lt;br /&gt;
&lt;br /&gt;
Table altered.&lt;br /&gt;
&lt;br /&gt;
select column_name from dba_tab_cols where owner = &amp;#039;&amp;amp;owner.&amp;#039; and table_name = &amp;#039;&amp;amp;table_name.&amp;#039;;&lt;br /&gt;
&lt;br /&gt;
COLUMN_NAME&lt;br /&gt;
------------------------------&lt;br /&gt;
PASSWORD_REQUIRED&lt;br /&gt;
ROLE&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Solution====&lt;br /&gt;
Drop the extended stats, do what you need to do and recreate the extended stats.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
PROCEDURE DROP_EXTENDED_STATS&lt;br /&gt;
 Argument Name                  Type                    In/Out Default?&lt;br /&gt;
 ------------------------------ ----------------------- ------ --------&lt;br /&gt;
 OWNNAME                        VARCHAR2                IN&lt;br /&gt;
 TABNAME                        VARCHAR2                IN&lt;br /&gt;
 EXTENSION                      VARCHAR2                IN&lt;br /&gt;
&lt;br /&gt;
exec dbms_stats.drop_extended_stats ( &amp;#039;KPK&amp;#039;, &amp;#039;XND40&amp;#039;, &amp;#039;(&amp;quot;NOMFIC&amp;quot;,&amp;quot;NUMSEQ&amp;quot;)&amp;#039; );&lt;br /&gt;
&lt;br /&gt;
create table kpk.xnd40_new as select * from kpk.xnd40 where 1=2;&lt;br /&gt;
&lt;br /&gt;
Table created.&lt;br /&gt;
&lt;br /&gt;
select dbms_stats.create_extended_stats ( &amp;#039;KPK&amp;#039;, &amp;#039;XND40&amp;#039;, &amp;#039;(&amp;quot;NOMFIC&amp;quot;,&amp;quot;NUMSEQ&amp;quot;)&amp;#039; ) from   dual;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The stats columns can also be seen in their own table&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 1000 pages 100&lt;br /&gt;
col owner for a6&lt;br /&gt;
col table_name for a20&lt;br /&gt;
col extension_name  for a40&lt;br /&gt;
col extension  for a50&lt;br /&gt;
select owner, table_name, extension_name, extension, creator, droppable from dba_stat_extensions where owner = upper(&amp;#039;&amp;amp;&amp;amp;owner.&amp;#039;) and table_name = upper(&amp;#039;&amp;amp;&amp;amp;table_name.&amp;#039;) and extension_name LIKE &amp;#039;SYS_STS%&amp;#039;;&lt;br /&gt;
&lt;br /&gt;
OWNER TABLE_NAME           EXTENSION_NAME                           EXTENSION                                          CREATOR                  DROPPABLE&lt;br /&gt;
----- -------------------- ---------------------------------------- -------------------------------------------------- ------------------------ ------------&lt;br /&gt;
KPK   XMD01                SYS_STSOA4UXZDBW7MIV5OOR8VOHHK           (&amp;quot;DATCRT&amp;quot;,&amp;quot;CODJRN&amp;quot;)                                SYSTEM                   YES&lt;br /&gt;
KPK   XDD02                SYS_STSFJCZYRZBCQL820ADIR0Y4RZ           (&amp;quot;REFMSG&amp;quot;,&amp;quot;CPTTIT&amp;quot;,&amp;quot;TYPMSG&amp;quot;)                       SYSTEM                   YES&lt;br /&gt;
KPK   XCD09                SYS_STS2OIO647GN0_UV$XO583KKKJ           (&amp;quot;DATCRT&amp;quot;,&amp;quot;HEUMAJ&amp;quot;,&amp;quot;STAMOD&amp;quot;)                       SYSTEM                   YES&lt;br /&gt;
KPK   XCD09                SYS_STS_BRDODC6DJG_HXK0#O9BOYF           (&amp;quot;STAMOD&amp;quot;,&amp;quot;CODMOD&amp;quot;)                                SYSTEM                   YES&lt;br /&gt;
KPK   XCD09                SYS_STS2#DY5U$WQG6COVHB##H2ESK           (&amp;quot;DATMAJ&amp;quot;,&amp;quot;STAMOD&amp;quot;,&amp;quot;CODMOD&amp;quot;)                       SYSTEM                   YES&lt;br /&gt;
KPK   XCD09                SYS_STSO7#D3DI5R8_VAF$WJ32D8MT           (&amp;quot;STAMOD&amp;quot;,&amp;quot;KEYREF_1&amp;quot;)                              SYSTEM                   YES&lt;br /&gt;
KPK   XCD09                SYS_STS4FRY10M34S2L$0FDM1N4B18           (&amp;quot;STAMOD&amp;quot;,&amp;quot;IDTMOD&amp;quot;)                                SYSTEM                   YES&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORA-14404: partitioned table contains partitions in a different tablespace===&lt;br /&gt;
As part of an RMAN duplicate with a skip tablespace, this error is produced&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Reenabling controlfile options for auxiliary database&lt;br /&gt;
Executing: alter database enable block change tracking using file &amp;#039;/oracle/acc/ora_data3/adsa1/bct_adsp_do_not_delete.f&amp;#039;&lt;br /&gt;
&lt;br /&gt;
contents of Memory Script:&lt;br /&gt;
{&lt;br /&gt;
   Alter clone database open resetlogs;&lt;br /&gt;
}&lt;br /&gt;
executing Memory Script&lt;br /&gt;
&lt;br /&gt;
database opened&lt;br /&gt;
Dropping offline and skipped tablespaces&lt;br /&gt;
Executing: drop tablespace &amp;quot;ADS_ARCHIVE&amp;quot; including contents cascade constraints&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-03002: failure of Duplicate Db command at 10/16/2017 23:46:12&lt;br /&gt;
RMAN-05501: aborting duplication of target database&lt;br /&gt;
RMAN-06136: ORACLE error from auxiliary database: ORA-14404: partitioned table contains partitions in a different tablespace&lt;br /&gt;
&lt;br /&gt;
Recovery Manager complete.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
and when attempting to backup the database, we get errors&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
RMAN-06169: could not read file header for datafile 188 error reason 1&lt;br /&gt;
RMAN-06169: could not read file header for datafile 189 error reason 1&lt;br /&gt;
RMAN-06169: could not read file header for datafile 190 error reason 1&lt;br /&gt;
RMAN-06169: could not read file header for datafile 191 error reason 1&lt;br /&gt;
RMAN-06169: could not read file header for datafile 14 error reason 1&lt;br /&gt;
released channel: t1&lt;br /&gt;
released channel: t2&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-03002: failure of backup plus archivelog command at 10/17/2017 15:08:40&lt;br /&gt;
RMAN-06056: could not access datafile 14&lt;br /&gt;
&lt;br /&gt;
Recovery Manager complete.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Problem====&lt;br /&gt;
Tables in the tablespace have partitions in another tablespace so this one cannot be dropped.&amp;lt;br /&amp;gt;&lt;br /&gt;
Check which table partitions are in which tablespaces&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 200&lt;br /&gt;
set pagesize 200&lt;br /&gt;
col table_name for a14&lt;br /&gt;
col table_owner for a14&lt;br /&gt;
col partition_name for a14&lt;br /&gt;
select table_owner&lt;br /&gt;
,      table_name&lt;br /&gt;
,      partition_name&lt;br /&gt;
,      tablespace_name&lt;br /&gt;
from   dba_tab_partitions&lt;br /&gt;
where  (table_owner, table_name) in&lt;br /&gt;
       (&lt;br /&gt;
       select table_owner&lt;br /&gt;
       ,      table_name&lt;br /&gt;
       from   dba_tab_partitions x&lt;br /&gt;
       where  x.tablespace_name = &amp;#039;&amp;amp;&amp;amp;TABLESPACE_TO_DROP&amp;#039;&lt;br /&gt;
       and    exists ( select *&lt;br /&gt;
                       from   dba_tab_partitions y&lt;br /&gt;
                       where  x.table_owner = y.table_owner&lt;br /&gt;
                       and    x.table_name  = y.table_name&lt;br /&gt;
                       and    y.tablespace_name not in (&amp;#039;&amp;amp;TABLESPACE_TO_DROP&amp;#039;)&lt;br /&gt;
                       group  by table_owner&lt;br /&gt;
                       ,      table_name&lt;br /&gt;
                     )&lt;br /&gt;
        )&lt;br /&gt;
order by 1,2,partition_position&lt;br /&gt;
/&lt;br /&gt;
undef TABLESPACE_TO_DROP&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
TABLE_OWNER    TABLE_NAME     PARTITION_NAME TABLESPACE_NAME&lt;br /&gt;
-------------- -------------- -------------- ------------------------------&lt;br /&gt;
KPK            XND20          P0910          TS_THALER_PART_OLD&lt;br /&gt;
KPK            XND20          P1112          TS_THALER_PART_OLD&lt;br /&gt;
KPK            XND20          P13            TS_THALER_PART_OLD&lt;br /&gt;
KPK            XND20          P14            TS_THALER_PART_OLD&lt;br /&gt;
KPK            XND20          P15            TS_THALER_PART_OLD&lt;br /&gt;
KPK            XND20          P16            TS_THALER_DATA&lt;br /&gt;
KPK            XND20          P17            TS_THALER_DATA&lt;br /&gt;
KPK            XND20          P18            TS_THALER_DATA&lt;br /&gt;
KPK            XND20          PMAX           TS_THALER_DATA&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Solution====&lt;br /&gt;
If the intention is to keep all the tables then run this query to generate statements to move the relevant tables out of this tablespace&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select &amp;#039;alter table &amp;#039;||b.table_owner||&amp;#039;.&amp;#039;||b.table_name||&amp;#039; move partition &amp;#039;||b.partition_name||&amp;#039; tablespace &amp;amp;NEW_TABLESPACE;&amp;#039;&lt;br /&gt;
from   (&lt;br /&gt;
       select distinct table_name&lt;br /&gt;
       ,      partition_name&lt;br /&gt;
       from   dba_tab_partitions&lt;br /&gt;
       where  tablespace_name = &amp;#039;&amp;amp;&amp;amp;TABLESPACE_NAME&amp;#039;&lt;br /&gt;
       )                  a&lt;br /&gt;
,      dba_tab_partitions b&lt;br /&gt;
where  a.table_name       = b.table_name&lt;br /&gt;
and    b.tablespace_name != &amp;#039;&amp;amp;TABLESPACE_NAME&amp;#039;&lt;br /&gt;
/&lt;br /&gt;
undef TABLESPACE_NAME&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
If however, the intention is to drop the tablespace anyway, the tables need to be dropped before the tablespace can be dropped.&amp;lt;br /&amp;gt;&lt;br /&gt;
But ...tables with partitions in different tablespaces cannot be dropped. The partitions need to be dropped first!&amp;lt;br /&amp;gt;&lt;br /&gt;
Run the following query to generate statements to drop all the &amp;#039;problem&amp;#039; tables. When these have gone, the tablespace can be dropped.&lt;br /&gt;
* drop table partitions&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
spool /tmp/drop_table_partitions.sql&lt;br /&gt;
sqlplus / as sysdba&amp;lt;&amp;lt;EOSQL&lt;br /&gt;
set headi off newpa none feedb off trims on echo off&lt;br /&gt;
select &amp;#039;alter table &amp;#039;||table_owner||&amp;#039;.&amp;#039;||table_name||&amp;#039; drop partition &amp;#039;||partition_name||&amp;#039;;&amp;#039;&lt;br /&gt;
from   dba_tab_partitions&lt;br /&gt;
where  tablespace_name = &amp;#039;$TABLESPACE_NAME&amp;#039;&lt;br /&gt;
/&lt;br /&gt;
spool off&lt;br /&gt;
EOSQL&lt;br /&gt;
echo &amp;quot;@/tmp/drop_table_partitions.sql&amp;quot; | sqlplus / as sysdba&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* drop tables&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sqlplus / as sysdba&amp;lt;&amp;lt;EOSQL&lt;br /&gt;
select &amp;#039;drop table &amp;#039;||table_owner||&amp;#039;.&amp;#039;||table_name||&amp;#039;;&amp;#039;&lt;br /&gt;
from   dba_tab_partitions&lt;br /&gt;
where  tablespace_name = &amp;#039;$TABLESPACE_NAME&amp;#039;&lt;br /&gt;
spool /tmp/drop_tables.sql&lt;br /&gt;
/&lt;br /&gt;
spool off&lt;br /&gt;
EOSQL&lt;br /&gt;
echo &amp;quot;@/tmp/drop_tables.sql&amp;quot; | sqlplus / as sysdba&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* drop tablespace&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
drop tablespace ads_archive including contents and datafiles&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Find all table partitions in tablespaces with missing datafiles====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 1000 pages 100&lt;br /&gt;
col owner for a10&lt;br /&gt;
col segment_name for a40&lt;br /&gt;
col segment_type for a25&lt;br /&gt;
col partition_name for a20&lt;br /&gt;
col tablespace_name for a25&lt;br /&gt;
select owner&lt;br /&gt;
,      segment_name&lt;br /&gt;
,      segment_type&lt;br /&gt;
,      partition_name&lt;br /&gt;
,      tablespace_name&lt;br /&gt;
from   dba_segments&lt;br /&gt;
where  segment_type in (&amp;#039;TABLE PARTITION&amp;#039;, &amp;#039;TABLE SUBPARTITION&amp;#039;)&lt;br /&gt;
and    tablespace_name in (&lt;br /&gt;
                          select tablespace_name&lt;br /&gt;
                          from   dba_data_files&lt;br /&gt;
                          where  file_name like &amp;#039;%MISSING%&amp;#039;&lt;br /&gt;
                          )&lt;br /&gt;
order  by 1, 2, decode (segment_type, &amp;#039;TABLE SUBPARTITION&amp;#039;, 1, 2),4&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Use exchange partition to alter metadata of the tablespaces without moving the actual data====&lt;br /&gt;
* [https://community.oracle.com/message/2166242#2166242 this] is an explanation of what you are looking for!&amp;lt;br /&amp;gt;&lt;br /&gt;
This is a way of doing the exchange with a neat PL/SQL procedure.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set serveroutput on size unlimited&lt;br /&gt;
DECLARE&lt;br /&gt;
  dummy_table                   VARCHAR2 (128);&lt;br /&gt;
  cmd                           VARCHAR2 (2048);&lt;br /&gt;
  currowner                     dba_part_tables.owner%TYPE;&lt;br /&gt;
  currtable                     dba_part_tables.table_name%TYPE;&lt;br /&gt;
  l_subpartitioning_type        dba_part_tables.subpartitioning_type%TYPE;&lt;br /&gt;
  l_def_subpartition_count      dba_part_tables.def_subpartition_count%TYPE;&lt;br /&gt;
  l_subpartitioning_key_count   dba_part_tables.subpartitioning_key_count%TYPE;&lt;br /&gt;
  l_curr_qual_table             VARCHAR2 (128);&lt;br /&gt;
&lt;br /&gt;
  PROCEDURE execsql (p_sql IN VARCHAR2)&lt;br /&gt;
  IS&lt;br /&gt;
  BEGIN&lt;br /&gt;
    DBMS_OUTPUT.put_line (p_sql); &lt;br /&gt;
    EXECUTE IMMEDIATE p_sql;&lt;br /&gt;
  END;&lt;br /&gt;
 &lt;br /&gt;
  PROCEDURE force_drop_table (p_table_name IN VARCHAR2)&lt;br /&gt;
  IS&lt;br /&gt;
  BEGIN&lt;br /&gt;
    execsql (&amp;#039;drop table &amp;#039; || p_table_name || &amp;#039; purge&amp;#039;);&lt;br /&gt;
  EXCEPTION&lt;br /&gt;
    WHEN OTHERS&lt;br /&gt;
    THEN&lt;br /&gt;
      NULL;&lt;br /&gt;
  END;&lt;br /&gt;
 &lt;br /&gt;
  PROCEDURE exchange_partition (p_from_table       IN VARCHAR2,&lt;br /&gt;
                                p_from_partition   IN VARCHAR2,&lt;br /&gt;
                                p_to_table         IN VARCHAR2)&lt;br /&gt;
  IS&lt;br /&gt;
  BEGIN&lt;br /&gt;
    execsql (&lt;br /&gt;
         &amp;#039;alter table &amp;#039;&lt;br /&gt;
      || p_from_table&lt;br /&gt;
      || &amp;#039; exchange partition &amp;#039;&lt;br /&gt;
      || p_from_partition&lt;br /&gt;
      || &amp;#039; with table &amp;#039;&lt;br /&gt;
      || p_to_table&lt;br /&gt;
      || &amp;#039; excluding indexes&amp;#039;);&lt;br /&gt;
  END;&lt;br /&gt;
 &lt;br /&gt;
  PROCEDURE drop_partition (p_table IN VARCHAR2, p_partition IN VARCHAR2)&lt;br /&gt;
  IS&lt;br /&gt;
  BEGIN&lt;br /&gt;
    execsql (&amp;#039;alter table &amp;#039; || p_table || &amp;#039; drop partition &amp;#039; || p_partition);&lt;br /&gt;
  END;&lt;br /&gt;
BEGIN&lt;br /&gt;
  currowner := &amp;#039;.&amp;#039;;&lt;br /&gt;
  currtable := &amp;#039;.&amp;#039;;&lt;br /&gt;
 &lt;br /&gt;
  FOR asegment&lt;br /&gt;
    IN (  SELECT owner,&lt;br /&gt;
                 segment_name,&lt;br /&gt;
                 segment_type,&lt;br /&gt;
                 partition_name&lt;br /&gt;
            FROM dba_segments&lt;br /&gt;
           WHERE     segment_type IN (&amp;#039;TABLE PARTITION&amp;#039;, &amp;#039;TABLE SUBPARTITION&amp;#039;)&lt;br /&gt;
                 AND tablespace_name IN (SELECT tablespace_name&lt;br /&gt;
                                           FROM dba_data_files&lt;br /&gt;
                                          WHERE file_name LIKE &amp;#039;%MISSING%&amp;#039;)&lt;br /&gt;
        ORDER BY 1,&lt;br /&gt;
                 2,&lt;br /&gt;
                 DECODE (segment_type, &amp;#039;TABLE SUBPARTITION&amp;#039;, 1, 2),&lt;br /&gt;
                 4)&lt;br /&gt;
  LOOP&lt;br /&gt;
    BEGIN&lt;br /&gt;
      IF currowner &amp;lt;&amp;gt; asegment.owner OR currtable &amp;lt;&amp;gt; asegment.segment_name&lt;br /&gt;
      THEN&lt;br /&gt;
        currowner := asegment.owner;&lt;br /&gt;
        currtable := asegment.segment_name;&lt;br /&gt;
        l_curr_qual_table := asegment.owner || &amp;#039;.&amp;#039; || asegment.segment_name;&lt;br /&gt;
        dummy_table := asegment.owner || &amp;#039;.TBR_EXCHANGE_DUMMY&amp;#039;;&lt;br /&gt;
 &lt;br /&gt;
        force_drop_table (dummy_table);&lt;br /&gt;
 &lt;br /&gt;
        IF asegment.segment_type = &amp;#039;TABLE SUBPARTITION&amp;#039;&lt;br /&gt;
        THEN&lt;br /&gt;
          cmd := &amp;#039;create table &amp;#039; || dummy_table || &amp;#039; partition by &amp;#039;;&lt;br /&gt;
 &lt;br /&gt;
          SELECT subpartitioning_type,&lt;br /&gt;
                 def_subpartition_count,&lt;br /&gt;
                 subpartitioning_key_count&lt;br /&gt;
            INTO l_subpartitioning_type,&lt;br /&gt;
                 l_def_subpartition_count,&lt;br /&gt;
                 l_subpartitioning_key_count&lt;br /&gt;
            FROM dba_part_tables&lt;br /&gt;
           WHERE     owner = asegment.owner&lt;br /&gt;
                 AND table_name = asegment.segment_name;&lt;br /&gt;
 &lt;br /&gt;
          cmd := cmd || l_subpartitioning_type || &amp;#039;(&amp;#039;;&lt;br /&gt;
 &lt;br /&gt;
          FOR asubpartkey&lt;br /&gt;
            IN (  SELECT column_position, column_name&lt;br /&gt;
                    FROM dba_subpart_key_columns&lt;br /&gt;
                   WHERE     owner = asegment.owner&lt;br /&gt;
                         AND name = asegment.segment_name&lt;br /&gt;
                         AND object_type = &amp;#039;TABLE&amp;#039;&lt;br /&gt;
                ORDER BY column_position)&lt;br /&gt;
          LOOP&lt;br /&gt;
            IF asubpartkey.column_position &amp;gt; 1&lt;br /&gt;
            THEN&lt;br /&gt;
              cmd := cmd || &amp;#039;,&amp;#039;;&lt;br /&gt;
            END IF;&lt;br /&gt;
 &lt;br /&gt;
            cmd := cmd || asubpartkey.column_name;&lt;br /&gt;
          END LOOP;&lt;br /&gt;
 &lt;br /&gt;
          cmd := cmd || &amp;#039;) partitions (&amp;#039;;&lt;br /&gt;
 &lt;br /&gt;
          FOR partnr IN 1 .. l_def_subpartition_count&lt;br /&gt;
          LOOP&lt;br /&gt;
            IF partnr &amp;gt; 1&lt;br /&gt;
            THEN&lt;br /&gt;
              cmd := cmd || &amp;#039;,&amp;#039;;&lt;br /&gt;
            END IF;&lt;br /&gt;
 &lt;br /&gt;
            cmd := cmd || &amp;#039;partition p&amp;#039; || partnr;&lt;br /&gt;
          END LOOP;&lt;br /&gt;
 &lt;br /&gt;
          cmd :=&lt;br /&gt;
            cmd || &amp;#039;) as select * from &amp;#039; || l_curr_qual_table || &amp;#039; where 1=0&amp;#039;;&lt;br /&gt;
          execsql (cmd);&lt;br /&gt;
        ELSE&lt;br /&gt;
          execsql (&lt;br /&gt;
               &amp;#039;create table &amp;#039;&lt;br /&gt;
            || dummy_table&lt;br /&gt;
            || &amp;#039; as select * from &amp;#039;&lt;br /&gt;
            || l_curr_qual_table&lt;br /&gt;
            || &amp;#039; where 1=0&amp;#039;);&lt;br /&gt;
        END IF;&lt;br /&gt;
      END IF;&lt;br /&gt;
 &lt;br /&gt;
      exchange_partition (l_curr_qual_table,&lt;br /&gt;
                          asegment.partition_name,&lt;br /&gt;
                          dummy_table);&lt;br /&gt;
 &lt;br /&gt;
      drop_partition (l_curr_qual_table, asegment.partition_name);&lt;br /&gt;
    EXCEPTION&lt;br /&gt;
      WHEN OTHERS&lt;br /&gt;
      THEN&lt;br /&gt;
        DBMS_OUTPUT.put_line (&lt;br /&gt;
          asegment.owner || &amp;#039;.&amp;#039; || asegment.segment_name || &amp;#039; &amp;#039; || SQLERRM);&lt;br /&gt;
    END;&lt;br /&gt;
  END LOOP;&lt;br /&gt;
 &lt;br /&gt;
  IF dummy_table IS NOT NULL&lt;br /&gt;
  THEN&lt;br /&gt;
    force_drop_table (dummy_table);&lt;br /&gt;
  END IF;&lt;br /&gt;
 &lt;br /&gt;
  FOR atablespace IN (  SELECT DISTINCT tablespace_name&lt;br /&gt;
                          FROM dba_data_files&lt;br /&gt;
                         WHERE file_name LIKE &amp;#039;%MISSING%&amp;#039;&lt;br /&gt;
                      ORDER BY 1)&lt;br /&gt;
  LOOP&lt;br /&gt;
    execsql (&lt;br /&gt;
         &amp;#039;drop tablespace &amp;#039;&lt;br /&gt;
      || atablespace.tablespace_name&lt;br /&gt;
      || &amp;#039; including contents and datafiles&amp;#039;);&lt;br /&gt;
  END LOOP;&lt;br /&gt;
END;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Workaround====&lt;br /&gt;
While working on the solution, a backup can be made using the &amp;quot;skip inaccessible&amp;quot; option. Put this in an rman cmdfile...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
connect catalog rmanusr/rmanpwd@rmancat&lt;br /&gt;
connect target sys/syspwd@adsa1&lt;br /&gt;
run {&lt;br /&gt;
allocate channel t1 type &amp;#039;sbt_tape&amp;#039; parms &amp;#039;ENV=(NSR_SERVER=hn6000.company.be,NSR_CLIENT=hn491,NSR_DATA_VOLUME_POOL=DD1DAILY,NSR_END_ERROR_IGNORE=TRUE)&amp;#039;;&lt;br /&gt;
allocate channel t2 type &amp;#039;sbt_tape&amp;#039; parms &amp;#039;ENV=(NSR_SERVER=hn6000.company.be,NSR_CLIENT=hn491,NSR_DATA_VOLUME_POOL=DD1DAILY,NSR_END_ERROR_IGNORE=TRUE)&amp;#039;;&lt;br /&gt;
configure retention policy to recovery window of 28 days;&lt;br /&gt;
configure controlfile autobackup on;&lt;br /&gt;
crosscheck archivelog all;&lt;br /&gt;
SQL &amp;#039;ALTER SYSTEM SWITCH LOGFILE&amp;#039;;&lt;br /&gt;
SQL &amp;#039;CREATE PFILE FROM SPFILE&amp;#039;;&lt;br /&gt;
backup filesperset 1 format &amp;#039;dbfull_%d_%I_%t_%s_%p&amp;#039; full database plus archivelog skip inaccessible delete all input;&lt;br /&gt;
backup current controlfile;&lt;br /&gt;
release channel t1;&lt;br /&gt;
release channel t2;&lt;br /&gt;
}&lt;br /&gt;
exit&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Another way of deleting the offending objects====&lt;br /&gt;
Taken from [http://www.dbarj.com.br/en/2015/01/resume-oracle-duplicate-database-failed-recovery-datafiles/ Recover from a failed RMAN duplicate]&amp;lt;br /&amp;gt;&lt;br /&gt;
Need to check it before running it blindly!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
set echo off feed off termo off trims on pages 0 newpa none lines 2000 headi off long 32000&lt;br /&gt;
col val for a1000&lt;br /&gt;
spool destroy_offending_objects.sql&lt;br /&gt;
&lt;br /&gt;
select to_clob (&amp;#039;alter table &amp;#039;|| table_name||&amp;#039; drop constraint &amp;#039;||constraint_name||&amp;#039;;&amp;#039;) Val&lt;br /&gt;
from user_constraints where constraint_type in (&amp;#039;R&amp;#039;,&amp;#039;P&amp;#039;) and table_name in (select distinct table_name from user_tab_partitions)&lt;br /&gt;
union all&lt;br /&gt;
select to_clob (&amp;#039;drop index &amp;#039;||index_name||&amp;#039;;&amp;#039;) Val from user_indexes where table_name in (select distinct table_name from user_tab_partitions)&lt;br /&gt;
union all&lt;br /&gt;
select to_clob (&amp;#039;alter table &amp;#039;||table_name|| &amp;#039; drop partition &amp;#039;||partition_name||&amp;#039;;&amp;#039;) from dba_tab_partitions&lt;br /&gt;
where tablespace_name in (select tablespace_name from dba_data_files where file_name like &amp;#039;%MISSING%&amp;#039;)&lt;br /&gt;
union all&lt;br /&gt;
Select case&lt;br /&gt;
when instr (VAl, &amp;#039;PARTITION&amp;#039;) = 0 Then&lt;br /&gt;
substr (Val,1,InStr (Val,&amp;#039;)&amp;#039;)+1)||&amp;#039;;&amp;#039;&lt;br /&gt;
else&lt;br /&gt;
substr (Val,1,InStr (Val,&amp;#039;)&amp;#039;)+1)||&amp;#039; local;&amp;#039;&lt;br /&gt;
End val&lt;br /&gt;
from&lt;br /&gt;
(select dbms_metadata.get_ddl (&amp;#039;INDEX&amp;#039;, index_name,&amp;#039;TEST&amp;#039;) Val from user_indexes where table_name in (select distinct table_name from user_tab_partitions))&lt;br /&gt;
union all&lt;br /&gt;
Select Val&lt;br /&gt;
from&lt;br /&gt;
(select dbms_metadata.get_dependent_ddl (&amp;#039;REF_CONSTRAINT&amp;#039;, table_name,&amp;#039;TEST&amp;#039;) Val&lt;br /&gt;
from user_tables where table_name in (select distinct table_name from user_tab_partitions join user_constraints using ( table_name)&lt;br /&gt;
where constraint_type=&amp;#039;R&amp;#039;))&lt;br /&gt;
union all&lt;br /&gt;
select Val&lt;br /&gt;
from&lt;br /&gt;
(select dbms_metadata.get_ddl (&amp;#039;CONSTRAINT&amp;#039;, constraint_name,&amp;#039;TEST&amp;#039;) Val&lt;br /&gt;
from user_constraints&lt;br /&gt;
where constraint_type=&amp;#039;P&amp;#039; and table_name in (select distinct table_name from user_tab_partitions)&lt;br /&gt;
)&lt;br /&gt;
union all&lt;br /&gt;
select to_clob (val)&lt;br /&gt;
from (select distinct &amp;#039;drop tablespace &amp;#039;||tablespace_name|| &amp;#039; including contents and datafiles;&amp;#039; val&lt;br /&gt;
from dba_tab_partitions&lt;br /&gt;
where tablespace_name in (select tablespace_name from dba_data_files where file_name like &amp;#039;%MISSING%&amp;#039;)&lt;br /&gt;
);&lt;br /&gt;
&lt;br /&gt;
spoo off&lt;br /&gt;
&lt;br /&gt;
@destroy_offending_objects&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORA-28112: failed to execute policy function===&lt;br /&gt;
when exporting or importing using [[Data Pump]]&amp;lt; /br&amp;gt;&lt;br /&gt;
During expdp is accompanied by &amp;quot;&amp;#039;&amp;#039;&amp;#039;ORA-31693: Table data object &amp;quot;SYSMAN&amp;quot;.&amp;quot;MGMT_IP_REPORT_DEF&amp;quot; failed to load/unload and is being skipped due to error:&amp;#039;&amp;#039;&amp;#039;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
===Reason===&lt;br /&gt;
This happens due to audit policies being defined on the table but the policy function is defined in another schema.&lt;br /&gt;
&lt;br /&gt;
===Solution===&lt;br /&gt;
Either drop the policy after importing the table with:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
begin&lt;br /&gt;
    for rec in (select * from dba_audit_policies where object_schema = &amp;#039;SYSMAN&amp;#039;) loop&lt;br /&gt;
        dbms_fga.drop_policy(object_schema =&amp;gt; rec.object_schema,&lt;br /&gt;
                             object_name =&amp;gt; rec.object_name,&lt;br /&gt;
                             policy_name =&amp;gt; rec.policy_name);  &lt;br /&gt;
    end loop;&lt;br /&gt;
end;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or exclude the policies during export by adding this to the .par file:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
exclude=FGA_POLICY&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or even better, give the necessary grants to the exporting user...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
grant exempt access policy to impexpusr;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The sysdba role has this automatically.&lt;br /&gt;
===ORA-17629: Cannot connect to the remote database server===&lt;br /&gt;
Active duplication fails to connect even though dns connection exists in tnsnames.ora&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
Problem:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
DUPLICATE TARGET DATABASE FROM ACTIVE DATABASE DORECOVER NOFILENAMECHECK;&lt;br /&gt;
&lt;br /&gt;
RMAN-03002: failure of Duplicate Db command at 05/27/2015 12:52:24&lt;br /&gt;
RMAN-05501: aborting duplication of target database&lt;br /&gt;
RMAN-03015: error occurred in stored script Memory Script&lt;br /&gt;
RMAN-03009: failure of backup command on ORA_DISK_1 channel at 05/27/2015 12:52:23&lt;br /&gt;
ORA-17629: Cannot connect to the remote database server&lt;br /&gt;
ORA-17627: ORA-12154: TNS:could not resolve the connect identifier specified&lt;br /&gt;
&lt;br /&gt;
ORA-17629: Cannot connect to the remote database server&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
Solution:&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
Update the tnsnames.ora of both destination &amp;#039;&amp;#039;&amp;#039;and&amp;#039;&amp;#039;&amp;#039; source ORACLE_HOMEs!&lt;br /&gt;
&lt;br /&gt;
===ORA-01950: no privileges on tablespace &amp;#039;SYSAUX&amp;#039;===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
26-JUN-15 03:12:27.545: &amp;gt;&amp;gt;&amp;gt; ORA-31642: the following SQL statement fails: &lt;br /&gt;
BEGIN &amp;quot;SYS&amp;quot;.&amp;quot;DBMS_RULE_EXP_RULES&amp;quot;.SCHEMA_CALLOUT(:1,0,1,&amp;#039;12.01.00.02.00&amp;#039;); END;&lt;br /&gt;
ORA-01950: no privileges on tablespace &amp;#039;SYSAUX&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Cause:&amp;#039;&amp;#039;&amp;#039;&amp;lt;br /&amp;gt;&lt;br /&gt;
In this case, it seems SYSMAN has no rights to create objects in the SYSAUX tablespace&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Solution:&amp;#039;&amp;#039;&amp;#039;&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter user SYSMAN quota unlimited on sysaux;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
More information [https://support.oracle.com/epmos/faces/SearchDocDisplay?_adf.ctrl-state=bov7jp5pq_4&amp;amp;_afrLoop=547371065896716#SYMPTOM here]&lt;br /&gt;
&lt;br /&gt;
===ORA-39080: failed to create queues &amp;quot;KUPC$C_1_20150616165037&amp;quot; and &amp;quot;KUPC$S_1_20150616165037&amp;quot; for Data Pump job===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
expdp /&lt;br /&gt;
&lt;br /&gt;
Export: Release 11.2.0.4.0 - Production on Tue Jun 16 16:50:36 2015&lt;br /&gt;
&lt;br /&gt;
Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.&lt;br /&gt;
&lt;br /&gt;
Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production&lt;br /&gt;
With the Partitioning, OLAP, Data Mining and Real Application Testing options&lt;br /&gt;
ORA-31626: job does not exist&lt;br /&gt;
ORA-31637: cannot create job SYS_EXPORT_SCHEMA_01 for user OPS$ORAIBM&lt;br /&gt;
ORA-06512: at &amp;quot;SYS.DBMS_SYS_ERROR&amp;quot;, line 95&lt;br /&gt;
ORA-06512: at &amp;quot;SYS.KUPV$FT_INT&amp;quot;, line 798&lt;br /&gt;
[[ORA-39080: failed to create queues &amp;quot;KUPC$C_1_20150616165037&amp;quot; and &amp;quot;KUPC$S_1_20150616165037&amp;quot; for Data Pump job]]&lt;br /&gt;
ORA-06512: at &amp;quot;SYS.DBMS_SYS_ERROR&amp;quot;, line 95&lt;br /&gt;
ORA-06512: at &amp;quot;SYS.KUPC$QUE_INT&amp;quot;, line 1534&lt;br /&gt;
ORA-24002: QUEUE_TABLE SYS.AQ$KUPC$DATAPUMP_QUETAB_1 does not exist&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Cause:====&lt;br /&gt;
Possibly some or all of OLAP module has got itself deinstalled.&lt;br /&gt;
====Solution:====&lt;br /&gt;
Try:&lt;br /&gt;
* Recompiling invalid objects. @?/rdbms/admin/utlrp&lt;br /&gt;
* Reinstalling DBMS_CUBE packages by (re)running catproc.sql. @?/rdbms/admin/catproc followed by @?/rdbms/admin/utlrp&lt;br /&gt;
* Reinstalling OLAP. @?/olap/admin/olap.sql SYSAUX TEMP; But see Metalink note ID 296187.1 for full instructions.&lt;br /&gt;
* Check metalink for bugs. See ID 345198.1 and possibly ID 453796.1&lt;br /&gt;
===ORA-14063: Unusable index exists on unique/primary constraint key===&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;ORA-39083: Object type CONSTRAINT failed to create with error:&amp;#039;&amp;#039;&amp;#039;&amp;lt;br /&amp;gt;&lt;br /&gt;
During an import datapump (impdp), import failed because indexes were in error before the tables were exported. This causes the import of rows to be skipped.&amp;lt;br /&amp;gt;&lt;br /&gt;
If the export cannot be done again (having compiled the indexes), then the metadata can be imported and the indexes compiled before importing the data.&lt;br /&gt;
* Import the metadata&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cat&amp;lt;&amp;lt;EOCAT &amp;gt;impdp_adst_ads_archive_metadata.par&lt;br /&gt;
userid=&amp;#039;/ as sysdba&amp;#039;&lt;br /&gt;
dumpfile=adst_ads_archive.dmp&lt;br /&gt;
logfile=impdp_adst_ads_archive_metadata.log&lt;br /&gt;
content=metadata_only&lt;br /&gt;
EOCAT&lt;br /&gt;
&lt;br /&gt;
impdp parfile=impdp_adst_ads_archive_metadata.par&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Find the bad indexes and recompile them&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select &amp;#039;alter index &amp;#039;|| owner||&amp;#039;.&amp;#039;||index_name||&amp;#039; rebuild online parallel 8;&amp;#039;&lt;br /&gt;
from   dba_indexes&lt;br /&gt;
where  status = &amp;#039;UNUSABLE&amp;#039;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Import the data&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cat&amp;lt;&amp;lt;EOCAT &amp;gt;impdp_adst_ads_archive_data.par&lt;br /&gt;
userid=&amp;#039;/ as sysdba&amp;#039;&lt;br /&gt;
dumpfile=adst_ads_archive.dmp&lt;br /&gt;
logfile=impdp_adst_ads_archive_data.log&lt;br /&gt;
table_exists_action=append&lt;br /&gt;
content=data_only&lt;br /&gt;
EOCAT&lt;br /&gt;
&lt;br /&gt;
impdp parfile=impdp_adst_ads_archive_data.par&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORA-09925: Unable to create audit trail file===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SQL&amp;gt; startup nomount pfile=&amp;quot;/oracle/TRSCRP1/admin/initTRSCRP1.ora&amp;quot;&lt;br /&gt;
ORA-09925: Unable to create audit trail file&lt;br /&gt;
SVR4 Error: 2: No such file or directory&lt;br /&gt;
Additional information: 9925&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
connected to auxiliary database (not started)&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-03002: failure of Duplicate Db command at 08/29/2017 15:53:09&lt;br /&gt;
RMAN-05501: aborting duplication of target database&lt;br /&gt;
RMAN-03015: error occurred in stored script Memory Script&lt;br /&gt;
RMAN-04014: startup failed: ORA-09925: Unable to create audit trail file&lt;br /&gt;
IBM AIX RISC System/6000 Error: 2: No such file or directory&lt;br /&gt;
Additional information: 9925&lt;br /&gt;
&lt;br /&gt;
Recovery Manager complete.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Problem====&lt;br /&gt;
This will be almost certainly one of two issues. Either the directory is not writable by the id that started the instance or the directory just does not exist.&lt;br /&gt;
====Solution====&lt;br /&gt;
Note there can be a difference between what you see when you type:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
show parameter audit&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
and when you type:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
strings -a $ORACLE_HOME/dbs/spfile${ORACLE_SID}.ora | grep -i audit&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
due to someone doing an &amp;quot;alter system&amp;quot; without the &amp;quot;scope=spfile&amp;quot; or &amp;quot;scope=both&amp;quot;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SQL&amp;gt; host ls -al /oracle/TRSCRP1/admin/adump&lt;br /&gt;
SQL&amp;gt; host mkdir /oracle/TRSCRP1/admin/adump&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===ORA-09925: Unable to create audit trail file===&lt;br /&gt;
When starting SQL*Plus with no db processes running (expecting to see &amp;quot;Connected to an idle instance&amp;quot;), we get this:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ERROR:&lt;br /&gt;
ORA-09925: Unable to create audit trail file&lt;br /&gt;
IBM AIX RISC System/6000 Error: 2: No such file or directory&lt;br /&gt;
Additional information: 9925&lt;br /&gt;
ORA-01075: you are currently logged on&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Filesystem permissions are fine&lt;br /&gt;
* &amp;#039;strings spfile&amp;lt;SID&amp;gt;.ora | grep audit&amp;#039; shows the correct directory&lt;br /&gt;
* Running on AIX&lt;br /&gt;
AIX is the clue here... need to check for semaphores and locked shared memory objects&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
(0) UCLID55D oraibm@solax082:/oracle/product/11.2.0.3/bin&amp;gt; sysresv&lt;br /&gt;
&lt;br /&gt;
IPC Resources for ORACLE_SID &amp;quot;UCLID55D&amp;quot; :&lt;br /&gt;
Shared Memory:&lt;br /&gt;
ID              KEY&lt;br /&gt;
8388640         0xffffffff&lt;br /&gt;
579862561       0xffffffff&lt;br /&gt;
384827426       0x326f32e8&lt;br /&gt;
&lt;br /&gt;
Semaphores:&lt;br /&gt;
ID              KEY&lt;br /&gt;
167772287       0xf09f4914&lt;br /&gt;
Oracle Instance alive for sid &amp;quot;UCLID55D&amp;quot;&lt;br /&gt;
&lt;br /&gt;
(0) UCLID55D oraibm@solax082:/oracle/product/11.2.0.3/bin&amp;gt; ipcrm -m 8388640&lt;br /&gt;
(0) UCLID55D oraibm@solax082:/oracle/product/11.2.0.3/bin&amp;gt; ipcrm -m 579862561&lt;br /&gt;
(0) UCLID55D oraibm@solax082:/oracle/product/11.2.0.3/bin&amp;gt; ipcrm -m 384827426&lt;br /&gt;
&lt;br /&gt;
(0) UCLID55D oraibm@solax082:/oracle/product/11.2.0.3/bin&amp;gt; ipcrm -s 167772287&lt;br /&gt;
&lt;br /&gt;
(0) UCLID55D oraibm@solax082:/oracle/product/11.2.0.3/bin&amp;gt; sysresv&lt;br /&gt;
&lt;br /&gt;
IPC Resources for ORACLE_SID &amp;quot;UCLID55D&amp;quot; :&lt;br /&gt;
Shared Memory&lt;br /&gt;
ID              KEY&lt;br /&gt;
No shared memory segments used&lt;br /&gt;
Semaphores:&lt;br /&gt;
ID              KEY&lt;br /&gt;
No semaphore resources used&lt;br /&gt;
Oracle Instance not alive for sid &amp;quot;UCLID55D&amp;quot;&lt;br /&gt;
&lt;br /&gt;
(0) UCLID55D oraibm@solax082:/oracle/product/11.2.0.3/bin&amp;gt; ps -ef | grep UCLID55D&lt;br /&gt;
oraibm 3326 23776 0 14:12:05 pts/1 0:00 grep UCLID55D &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===RMAN-06023: no backup or copy of datafile 1 found to restore===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-03002: failure of Duplicate Db command at 05/16/2018 16:08:13&lt;br /&gt;
RMAN-05501: aborting duplication of target database&lt;br /&gt;
RMAN-05556: not all datafiles have backups that can be recovered to SCN 278250901080&lt;br /&gt;
RMAN-03015: error occurred in stored script Memory Script&lt;br /&gt;
RMAN-06026: some targets not found - aborting restore&lt;br /&gt;
RMAN-06023: no backup or copy of datafile 7 found to restore&lt;br /&gt;
RMAN-06023: no backup or copy of datafile 6 found to restore&lt;br /&gt;
RMAN-06023: no backup or copy of datafile 5 found to restore&lt;br /&gt;
RMAN-06023: no backup or copy of datafile 4 found to restore&lt;br /&gt;
RMAN-06023: no backup or copy of datafile 3 found to restore&lt;br /&gt;
RMAN-06023: no backup or copy of datafile 2 found to restore&lt;br /&gt;
RMAN-06023: no backup or copy of datafile 1 found to restore&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Seems pretty straightforward? SCN was set too early for the retention period. But no, not this time.&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
RMAN&amp;gt; list backup of datafile 1;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
List of Backup Sets&lt;br /&gt;
===================&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
BS Key  Type LV Size       Device Type Elapsed Time Completion Time&lt;br /&gt;
------- ---- -- ---------- ----------- ------------ -------------------&lt;br /&gt;
110170340 Incr 0  132.90G    SBT_TAPE    00:18:32     2018-05-14 01:19:40&lt;br /&gt;
        BP Key: 110170345   Status: AVAILABLE  Compressed: NO  Tag: WEEKLY_FULL&lt;br /&gt;
        Handle: 24639762_REPORTA_07t2r3uk_1_1   Media: V_17152809_77191330&lt;br /&gt;
  List of Datafiles in backup set 110170340&lt;br /&gt;
  File LV Type Ckp SCN    Ckp Time            Name&lt;br /&gt;
  ---- -- ---- ---------- ------------------- ----&lt;br /&gt;
  1    0  Incr 277998128991 2018-05-14 01:01:08 /cln/acc/ora_data3/reporta/system01.dbf&lt;br /&gt;
&lt;br /&gt;
BS Key  Type LV Size       Device Type Elapsed Time Completion Time&lt;br /&gt;
------- ---- -- ---------- ----------- ------------ -------------------&lt;br /&gt;
110355808 Incr 1  204.00M    SBT_TAPE    00:05:13     2018-05-15 01:06:22&lt;br /&gt;
        BP Key: 110355813   Status: AVAILABLE  Compressed: NO  Tag: DAILY_INCREMENTAL&lt;br /&gt;
        Handle: 24661053_REPORTA_3ft2toal_1_1   Media: V_17173010_77253424&lt;br /&gt;
  List of Datafiles in backup set 110355808&lt;br /&gt;
  File LV Type Ckp SCN    Ckp Time            Name&lt;br /&gt;
  ---- -- ---- ---------- ------------------- ----&lt;br /&gt;
  1    1  Incr 278044267395 2018-05-15 01:01:09 /cln/acc/ora_data3/reporta/system01.dbf&lt;br /&gt;
&lt;br /&gt;
BS Key  Type LV Size       Device Type Elapsed Time Completion Time&lt;br /&gt;
------- ---- -- ---------- ----------- ------------ -------------------&lt;br /&gt;
110543802 Incr 1  237.00M    SBT_TAPE    00:05:51     2018-05-16 01:07:40&lt;br /&gt;
        BP Key: 110543807   Status: AVAILABLE  Compressed: NO  Tag: DAILY_INCREMENTAL&lt;br /&gt;
        Handle: 24681602_REPORTA_6nt30cnt_1_1   Media: V_17133646_77315270&lt;br /&gt;
  List of Datafiles in backup set 110543802&lt;br /&gt;
  File LV Type Ckp SCN    Ckp Time            Name&lt;br /&gt;
  ---- -- ---- ---------- ------------------- ----&lt;br /&gt;
  1    1  Incr 278286445856 2018-05-16 01:01:50 /cln/acc/ora_data3/reporta/system01.dbf&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
SCN was only 12 hours ago with a retention of 28 days! The backup piece dated 2018-05-15 01:06:22 is clearly available and on the device type set_tape.&amp;lt;br /&amp;gt;&lt;br /&gt;
The trick here was to look back through the logs and look more closely at what the file restore message was saying...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
channel t0: starting datafile backup set restore&lt;br /&gt;
channel t0: specifying datafile(s) to restore from backup set&lt;br /&gt;
channel t0: restoring datafile 00001 to /cln/acc/ora_data3/reporta/system01.dbf             &amp;lt; &amp;lt; &amp;lt; ==============&lt;br /&gt;
channel t0: reading from backup piece dbfull_REPORTA_738887052_967580186_116_1&lt;br /&gt;
channel t2: ORA-19870: error while restoring backup piece dbfull_REPORTA_738887052_967579750_113_1&lt;br /&gt;
ORA-19507: failed to retrieve sequential file, handle=&amp;quot;dbfull_REPORTA_738887052_967579750_113_1&amp;quot;, parms=&amp;quot;&amp;quot;&lt;br /&gt;
ORA-27029: skgfrtrv: sbtrestore returned error&lt;br /&gt;
ORA-19511: non RMAN, but media manager or vendor specific failure, error text:&lt;br /&gt;
   CreateOraObject20: Job[0] thread[55116090]: Restore: GetBackupInfo() for Archive File[dbfull_REPORTA_738887052_967579750_113_1] failed.&lt;br /&gt;
ORA-0651&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
It was not the fact that it could not find the data on tape, it was that it could not save the file to the location indicated!!&lt;br /&gt;
In the RMAN DUPLICATE script, I had all the file paths redirected (a mixture of convert parameters and spfile set) to a /restore filesystem.&amp;lt;br /&amp;gt;&lt;br /&gt;
But I forgot one!&amp;lt;br /&amp;gt;&lt;br /&gt;
A handy thing to do is to search out the file paths with this to see if something is still wrong:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cd $ORACLE_HOME/dbs&lt;br /&gt;
strings -a spfile${ORACLE_SID}.ora | grep dest&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This should show any paths still not getting caught by the DUPLICATE script.&lt;br /&gt;
&lt;br /&gt;
===RMAN-06136: ORACLE error from auxiliary database: ORA-06502: PL/SQL: numeric or value error===&lt;br /&gt;
When cloning a database, the duplicate fails with this error.&lt;br /&gt;
====Problem====&lt;br /&gt;
This duplicate had no target connection but did have a catalog and auxiliary connection.&lt;br /&gt;
In the catalog (which was the catalog where the target was registerd), there was also an entry in that catalog with the same name as the auxiliary - left over from the days when these 2 instances were Primary and Standby in a Dataguard configuration.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
Datafile 414 skipped by request&lt;br /&gt;
Datafile 415 skipped by request&lt;br /&gt;
Datafile 419 skipped by request&lt;br /&gt;
Datafile 420 skipped by request&lt;br /&gt;
Datafile 421 skipped by request&lt;br /&gt;
&lt;br /&gt;
DBGSQL:     AUXILIARY&amp;gt; begin :ofname := sys.dbms_backup_restore.convertFileName( fname   =&amp;gt;   :ifname, ftype   =&amp;gt;   :iftype, osftype =&amp;gt;   TRUE); end;&lt;br /&gt;
DBGSQL:        sqlcode = 6502&lt;br /&gt;
DBGSQL:         B :ofname = NULL&lt;br /&gt;
DBGSQL:         B :ifname =&lt;br /&gt;
DBGSQL:         B :iftype = 2&lt;br /&gt;
restarting auxiliary database without server parameter file&lt;br /&gt;
Oracle instance started&lt;br /&gt;
&lt;br /&gt;
Total System Global Area   32068440064 bytes&lt;br /&gt;
&lt;br /&gt;
Fixed Size                     2262200 bytes&lt;br /&gt;
Variable Size              16978545480 bytes&lt;br /&gt;
Database Buffers           15032385536 bytes&lt;br /&gt;
Redo Buffers                  55246848 bytes&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-03002: failure of Duplicate Db command at 10/04/2017 14:50:29&lt;br /&gt;
RMAN-05501: aborting duplication of target database&lt;br /&gt;
RMAN-06136: ORACLE error from auxiliary database: ORA-06502: PL/SQL: numeric or value error&lt;br /&gt;
&lt;br /&gt;
Recovery Manager complete.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Solution====&lt;br /&gt;
Connect to the catalog and unregister the name of the auxiliary database. It shouldn&amp;#039;t be there anyway.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rman catalog rmanusr/rmanpwd@rmancat&lt;br /&gt;
&lt;br /&gt;
Recovery Manager: Release 11.2.0.4.0 - Production on Wed Oct 4 15:00:00 2017&lt;br /&gt;
&lt;br /&gt;
Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.&lt;br /&gt;
&lt;br /&gt;
connected to recovery catalog database&lt;br /&gt;
&lt;br /&gt;
RMAN&amp;gt; set dbid 4260753020;&lt;br /&gt;
&lt;br /&gt;
executing command: SET DBID&lt;br /&gt;
database name is &amp;quot;LBK&amp;quot; and DBID is 4260753020&lt;br /&gt;
&lt;br /&gt;
RMAN&amp;gt; list db_unique_name of database;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
List of Databases&lt;br /&gt;
DB Key  DB Name  DB ID            Database Role    Db_unique_name&lt;br /&gt;
------- ------- ----------------- ---------------  ------------------&lt;br /&gt;
13301587 LBK      4260753020       PRIMARY          LBK&lt;br /&gt;
13301587 LBK      4260753020       STANDBY          ACC_PERF&lt;br /&gt;
13301587 LBK      4260753020       STANDBY          LBKRO&lt;br /&gt;
&lt;br /&gt;
RMAN&amp;gt; unregister db_unique_name &amp;#039;ACC_PERF&amp;#039;;&lt;br /&gt;
&lt;br /&gt;
database db_unique_name is &amp;quot;ACC_PERF&amp;quot;, db_name is &amp;quot;LBK&amp;quot; and DBID is 4260753020&lt;br /&gt;
&lt;br /&gt;
Want to unregister the database with target db_unique_name (enter YES or NO)? YES&lt;br /&gt;
database with db_unique_name ACC_PERF unregistered from the recovery catalog&lt;br /&gt;
&lt;br /&gt;
RMAN&amp;gt; exit&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORA-39181: Only partial table data may be exported due to fine grain access control on &amp;quot;owner&amp;quot;.&amp;quot;&amp;lt;table_name&amp;gt;&amp;quot;===&lt;br /&gt;
&lt;br /&gt;
===Reason===&lt;br /&gt;
This happens when applications are designed with fine-grained access.&lt;br /&gt;
===Solution===&lt;br /&gt;
Grant the necessary privileges to the exporting user...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
grant exempt access policy to ops$oraibm;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORA-04030: out of process memory when trying to allocate 2520 bytes===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
expdp problem (ORA-04030: out of process memory when trying to allocate 2520 bytes (pga heap,koh-kghu call heap))&lt;br /&gt;
&lt;br /&gt;
select value from v$pgastat where name=&amp;#039;maximum PGA allocated&amp;#039;;&lt;br /&gt;
&lt;br /&gt;
SHOW PARAMETER TARGET&lt;br /&gt;
&lt;br /&gt;
ORA-04030: out of process memory when trying to allocate 2520 bytes (pga heap,koh-kghu call heap)&lt;br /&gt;
&lt;br /&gt;
alter system reset pga_aggregate_target scope=spfile;&lt;br /&gt;
&lt;br /&gt;
show sga&lt;br /&gt;
&lt;br /&gt;
select * from v$pgastat;&lt;br /&gt;
&lt;br /&gt;
show parameter process&lt;br /&gt;
&lt;br /&gt;
select sum(value)/1024/1024 Mb&lt;br /&gt;
from   v$sesstat s, v$statname n&lt;br /&gt;
where  1=1&lt;br /&gt;
and    n.STATISTIC# = s.STATISTIC#&lt;br /&gt;
and    name = &amp;#039;session pga memory&amp;#039;&lt;br /&gt;
&lt;br /&gt;
show parameter WORKAREA&lt;br /&gt;
&lt;br /&gt;
select value from v$pgastat where name=&amp;#039;maximum PGA allocated&amp;#039;;&lt;br /&gt;
&lt;br /&gt;
alter system set memory_max_target=10G scope=spfile;&lt;br /&gt;
&lt;br /&gt;
alter system set memory_target=3G scope=both;&lt;br /&gt;
&lt;br /&gt;
select * from v$memory_target_advice order by memory_size;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORA-04031: unable to allocate 32 bytes of shared memory (&amp;quot;shared pool&amp;quot;,&amp;quot;select name,online$,contents...&amp;quot;,&amp;quot;KGLH0^e5705bfc&amp;quot;,&amp;quot;kglHeapInitialize:temp&amp;quot;)===&lt;br /&gt;
* [https://blogs.oracle.com/db/entry/ora-4031_troubleshooting ORA-4031 Troubleshooting]&lt;br /&gt;
* [https://support.oracle.com/epmos/faces/DocumentDisplay?_afrLoop=89215376348478&amp;amp;id=396940.1&amp;amp;_afrWindowMode=0&amp;amp;_adf.ctrl-state=u1z0xcppg_4 Troubleshooting and Diagnosing ORA-4031 Error - (Doc ID 396940.1)]&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ORA-04031: unable to allocate  bytes of shared memory (&amp;quot;&amp;quot;,&amp;quot;&amp;quot;,&amp;quot;&amp;quot;,&amp;quot;&amp;quot;) &lt;br /&gt;
ORA-04031: unable to allocate 32 bytes of shared memory (&amp;quot;shared pool&amp;quot;,&amp;quot;select name,online$,contents...&amp;quot;,&amp;quot;KGLH0^e5705bfc&amp;quot;,&amp;quot;kglHeapInitialize:temp&amp;quot;) &lt;br /&gt;
Incident details in: /oracle/diag/rdbms/mape/MAPE/incident/incdir_86754/MAPE_dm00_14221536_i86754.trc &lt;br /&gt;
Wed Jul 31 20:42:50 2013 &lt;br /&gt;
Dumping diagnostic data in directory=[cdmp_20130731204250], requested by (instance=1, osid=14221536 (DM00)), summary=[incident=86753]. &lt;br /&gt;
Wed Jul 31 20:42:51 2013 &lt;br /&gt;
Sweep [inc][86754]: completed &lt;br /&gt;
Sweep [inc][86753]: completed &lt;br /&gt;
Sweep [inc2][86753]: completed &lt;br /&gt;
Wed Jul 31 20:42:57 2013 &lt;br /&gt;
Use ADRCI or Support Workbench to package the incident. &lt;br /&gt;
See Note 411.1 at My Oracle Support for error and packaging details. &lt;br /&gt;
Dumping diagnostic data in directory=[cdmp_20130731204257], requested by (instance=1, osid=14221536 (DM00)), summary=[incident=86754]. &lt;br /&gt;
Wed Jul 31 20:43:35 2013 &lt;br /&gt;
Errors in file /oracle/diag/rdbms/mape/MAPE/trace/MAPE_dw02_40567024.trc  (incident=82993): &lt;br /&gt;
ORA-04031: unable to allocate 32 bytes of shared memory (&amp;quot;shared pool&amp;quot;,&amp;quot;select order#,columns,types ...&amp;quot;,&amp;quot;KGLH0^470434f8&amp;quot;,&amp;quot;kglHeapInitialize:temp&amp;quot;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Database had already crashed so nothing to do but:&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
(0) MAPE ora@x025:/home/ora&amp;gt; sqlplus / as sysdba&lt;br /&gt;
&lt;br /&gt;
SQL*Plus: Release 11.2.0.3.0 Production on Fri Aug 2 14:26:20 2013&lt;br /&gt;
&lt;br /&gt;
Copyright (c) 1982, 2011, Oracle.  All rights reserved.&lt;br /&gt;
&lt;br /&gt;
Connected.&lt;br /&gt;
SYS@MAPE&amp;gt; alter system flush shared_pool;&lt;br /&gt;
alter system flush shared_pool&lt;br /&gt;
*&lt;br /&gt;
ERROR at line 1:&lt;br /&gt;
ORA-01012: not logged on&lt;br /&gt;
Process ID: 0&lt;br /&gt;
Session ID: 0 Serial number: 0&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
SYS@MAPE&amp;gt; shutdown abort&lt;br /&gt;
ORACLE instance shut down.&lt;br /&gt;
SYS@MAPE&amp;gt; startup&lt;br /&gt;
ORACLE instance started.&lt;br /&gt;
&lt;br /&gt;
Total System Global Area  734892032 bytes&lt;br /&gt;
Fixed Size                  2225128 bytes&lt;br /&gt;
Variable Size             398461976 bytes&lt;br /&gt;
Database Buffers          318767104 bytes&lt;br /&gt;
Redo Buffers               15437824 bytes&lt;br /&gt;
Database mounted.&lt;br /&gt;
Database opened.&lt;br /&gt;
&lt;br /&gt;
SYS@MAPE&amp;gt; show parameter pool&lt;br /&gt;
&lt;br /&gt;
NAME                                 TYPE                           VALUE&lt;br /&gt;
------------------------------------ ------------------------------ ------------------------------&lt;br /&gt;
buffer_pool_keep                     string&lt;br /&gt;
buffer_pool_recycle                  string&lt;br /&gt;
global_context_pool_size             string&lt;br /&gt;
java_pool_size                       big integer                    0&lt;br /&gt;
large_pool_size                      big integer                    0&lt;br /&gt;
olap_page_pool_size                  big integer                    0&lt;br /&gt;
shared_pool_reserved_size            big integer                    18M&lt;br /&gt;
shared_pool_size                     big integer                    208M&lt;br /&gt;
streams_pool_size                    big integer                    0&lt;br /&gt;
SYS@MAPE&amp;gt; show sga&lt;br /&gt;
&lt;br /&gt;
Total System Global Area  734892032 bytes&lt;br /&gt;
Fixed Size                  2225128 bytes&lt;br /&gt;
Variable Size             385879064 bytes&lt;br /&gt;
Database Buffers          331350016 bytes&lt;br /&gt;
Redo Buffers               15437824 bytes&lt;br /&gt;
SYS@MAPE&amp;gt; exit&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
but for reference, the causes could well be the applications running on the database are not using bind variables...&amp;lt;br /&amp;gt;&lt;br /&gt;
From [http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:528893984337 asktom.oracle.com]&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
Just to give you a tiny idea of how huge of a difference this &lt;br /&gt;
can make performance wise, you only need to run a very small &lt;br /&gt;
test:&lt;br /&gt;
&lt;br /&gt;
tkyte@TKYTE816&amp;gt; alter system flush shared_pool;&lt;br /&gt;
System altered.&lt;br /&gt;
&lt;br /&gt;
tkyte@TKYTE816&amp;gt; declare&lt;br /&gt;
  2      type rc is ref cursor;&lt;br /&gt;
  3      l_rc rc;&lt;br /&gt;
  4      l_dummy all_objects.object_name%type;&lt;br /&gt;
  5      l_start number default dbms_utility.get_time;&lt;br /&gt;
  6  begin&lt;br /&gt;
  7      for i in 1 .. 1000&lt;br /&gt;
  8      loop&lt;br /&gt;
  9          open l_rc for&lt;br /&gt;
 10          &amp;#039;select object_name&lt;br /&gt;
 11             from all_objects&lt;br /&gt;
 12            where object_id = &amp;#039; || i;&lt;br /&gt;
 13          fetch l_rc into l_dummy;&lt;br /&gt;
 14          close l_rc;&lt;br /&gt;
 15      end loop;&lt;br /&gt;
 16      dbms_output.put_line&lt;br /&gt;
 17      ( round( (dbms_utility.get_time-l_start)/100, 2 ) ||&lt;br /&gt;
 18        &amp;#039; seconds...&amp;#039; );&lt;br /&gt;
 19  end;&lt;br /&gt;
 20  /&lt;br /&gt;
14.86 seconds...&lt;br /&gt;
&lt;br /&gt;
PL/SQL procedure successfully completed.&lt;br /&gt;
&lt;br /&gt;
tkyte@TKYTE816&amp;gt; declare&lt;br /&gt;
  2      type rc is ref cursor;&lt;br /&gt;
  3      l_rc rc;&lt;br /&gt;
  4      l_dummy all_objects.object_name%type;&lt;br /&gt;
  5      l_start number default dbms_utility.get_time;&lt;br /&gt;
  6  begin&lt;br /&gt;
  7      for i in 1 .. 1000&lt;br /&gt;
  8      loop&lt;br /&gt;
  9          open l_rc for&lt;br /&gt;
 10          &amp;#039;select object_name&lt;br /&gt;
 11             from all_objects&lt;br /&gt;
 12            where object_id = :x&amp;#039;&lt;br /&gt;
 13          using i;&lt;br /&gt;
 14          fetch l_rc into l_dummy;&lt;br /&gt;
 15          close l_rc;&lt;br /&gt;
 16      end loop;&lt;br /&gt;
 17      dbms_output.put_line&lt;br /&gt;
 18      ( round( (dbms_utility.get_time-l_start)/100, 2 ) ||&lt;br /&gt;
 19        &amp;#039; seconds...&amp;#039; );&lt;br /&gt;
 20  end;&lt;br /&gt;
 21  /&lt;br /&gt;
1.27 seconds...&lt;br /&gt;
&lt;br /&gt;
PL/SQL procedure successfully completed.&lt;br /&gt;
&lt;br /&gt;
That is pretty dramatic.  The fact is that not only does this &lt;br /&gt;
execute much faster (we spent more time PARSING our queries then &lt;br /&gt;
actually EXECUTING them!) it will let more users use your system &lt;br /&gt;
simultaneously.&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
and from [http://asktom.oracle.com/pls/asktom/f?p=100:11:::::P11_QUESTION_ID:1163635055580 linked question]&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
Lbrary cache latch contention is typically caused by NOT using bind variables.  It is due &lt;br /&gt;
to excessive parsing of statements.&lt;br /&gt;
&lt;br /&gt;
One way to see if this might be the case in your situation is to run a script like:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
create table t1 as select sql_text from v$sqlarea;&lt;br /&gt;
&lt;br /&gt;
alter table t1 add sql_text_wo_constants varchar2(1000);&lt;br /&gt;
&lt;br /&gt;
create or replace function &lt;br /&gt;
remove_constants( p_query in varchar2 ) return varchar2&lt;br /&gt;
as&lt;br /&gt;
    l_query long;&lt;br /&gt;
    l_char  varchar2(1);&lt;br /&gt;
    l_in_quotes boolean default FALSE;&lt;br /&gt;
begin&lt;br /&gt;
    for i in 1 .. length( p_query )&lt;br /&gt;
    loop&lt;br /&gt;
        l_char := substr(p_query,i,1);&lt;br /&gt;
        if ( l_char = &amp;#039;&amp;#039;&amp;#039;&amp;#039; and l_in_quotes )&lt;br /&gt;
        then&lt;br /&gt;
            l_in_quotes := FALSE;&lt;br /&gt;
        elsif ( l_char = &amp;#039;&amp;#039;&amp;#039;&amp;#039; and NOT l_in_quotes )&lt;br /&gt;
        then&lt;br /&gt;
            l_in_quotes := TRUE;&lt;br /&gt;
            l_query := l_query || &amp;#039;&amp;#039;&amp;#039;#&amp;#039;;&lt;br /&gt;
        end if;&lt;br /&gt;
        if ( NOT l_in_quotes ) then&lt;br /&gt;
            l_query := l_query || l_char;&lt;br /&gt;
        end if;&lt;br /&gt;
    end loop;&lt;br /&gt;
    l_query := translate( l_query, &amp;#039;0123456789&amp;#039;, &amp;#039;@@@@@@@@@@&amp;#039; );&lt;br /&gt;
    for i in 0 .. 8 loop&lt;br /&gt;
        l_query := replace( l_query, lpad(&amp;#039;@&amp;#039;,10-i,&amp;#039;@&amp;#039;), &amp;#039;@&amp;#039; );&lt;br /&gt;
        l_query := replace( l_query, lpad(&amp;#039; &amp;#039;,10-i,&amp;#039; &amp;#039;), &amp;#039; &amp;#039; );&lt;br /&gt;
    end loop;&lt;br /&gt;
    return upper(l_query);&lt;br /&gt;
end;&lt;br /&gt;
/&lt;br /&gt;
update t1 set sql_text_wo_constants = remove_constants(sql_text);&lt;br /&gt;
&lt;br /&gt;
select sql_text_wo_constants, count(*)&lt;br /&gt;
  from t1&lt;br /&gt;
 group by sql_text_wo_constants&lt;br /&gt;
having count(*) &amp;gt; 100&lt;br /&gt;
 order by 2&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The output of that last query will show you statements that are identical in the shared &lt;br /&gt;
pool after all numbers and character string constants have been removed.  These &lt;br /&gt;
statements -- and more importantly their counts -- are the potential bottlenecks.  In &lt;br /&gt;
addition to causing the contention, they will be HUGE cpu consumers.  &lt;br /&gt;
&lt;br /&gt;
If you discover your applications do not use bind variables -- you must have this &lt;br /&gt;
corrected.  You&amp;#039;ll never have a good hit ratio if everyone submits &amp;quot;unique&amp;quot; sql.  Your &lt;br /&gt;
shared pool will never be used right and you&amp;#039;ll be using excessive CPU (90% of the time &lt;br /&gt;
it takes to process &amp;quot;insert into t values ( 1 )&amp;quot; is parsing.  If you use &amp;quot;insert into t &lt;br /&gt;
values ( :x )&amp;quot;, and bind the value of 1 -- then the next person that runs that insert &lt;br /&gt;
will benefit from your work and run that much faster. &lt;br /&gt;
...&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Advice from Oracle concerning a concrete (12c) example of unable to allocate 52824 bytes of shared memory (&amp;quot;shared pool&amp;quot;,...====&lt;br /&gt;
This was from a ticket raised for a Data Pump export that consistently failed with:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Processing object type SCHEMA_EXPORT/TABLE/PROCACT_INSTANCE&lt;br /&gt;
Processing object type SCHEMA_EXPORT/TABLE/TABLE&lt;br /&gt;
ORA-39014: One or more workers have prematurely exited.&lt;br /&gt;
ORA-39029: worker 1 with process name &amp;quot;DW00&amp;quot; prematurely terminated&lt;br /&gt;
ORA-31671: Worker process DW00 had an unhandled exception.&lt;br /&gt;
ORA-04031: unable to allocate 52824 bytes of shared memory (&amp;quot;shared pool&amp;quot;,&amp;quot;unknown object&amp;quot;,&amp;quot;KTSL subheap&amp;quot;,&amp;quot;ktsl_load_disp-2&amp;quot;)&lt;br /&gt;
ORA-06512: at &amp;quot;SYS.KUPW$WORKER&amp;quot;, line 2122&lt;br /&gt;
ORA-06512: at line 2&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
The error ORA-4031 on the shared pool can indicate one of two things:&lt;br /&gt;
- insufficient space for the shared pool (so insufficient memory in SGA at that time)&lt;br /&gt;
OR&lt;br /&gt;
- although there is enough memory, it is fragmented and no contiguous chunk can be allocated to satisfy the latest memory request.&lt;br /&gt;
&lt;br /&gt;
Each SGA has a little fragmentation of course because of the operations taking place, so in your case the fragmentation is represented by the 18M of free memory, which exists in uncontiguous chunks.&lt;br /&gt;
This means that the root cause of the error is insufficient contiguous memory to allocate 12312 bytes of shared memory.&lt;br /&gt;
&lt;br /&gt;
ACTION PLAN&lt;br /&gt;
==============&lt;br /&gt;
1. We see memory_target=2000M. This is too little to support a 12c database, even when it has little activity.&lt;br /&gt;
As you may know 1.7G for the SGA was acceptable when speaking of 32bit OSs where it was hardly possible to make use of more than that.&lt;br /&gt;
Since you have a 64 bit system, the addressable memory is virtually unlimited.&lt;br /&gt;
Furthermore, by using AMM (memory_target&amp;gt;0) this memory is divided between the SGA and the PGA (the user processes) which in fact, depending on the number of connections, can limit the SGA even more.&lt;br /&gt;
So the first recommendation is to increase the value of memory_target to 4G for example. There is no ideal value, but this would be a reasonable starting value for tuning.&lt;br /&gt;
&lt;br /&gt;
You can do further tuning of the memory using the view V$MEMORY_TARGET_ADVICE.&lt;br /&gt;
The view V$MEMORY_TARGET_ADVICE provides tuning advice for the MEMORY_TARGET initialization parameter:&lt;br /&gt;
SQL&amp;gt; SELECT * FROM v$memory_target_advice ORDER BY memory_size;&lt;br /&gt;
&lt;br /&gt;
The dynamic performance view V$MEMORY_DYNAMIC_COMPONENTS shows the current sizes of all dynamically tuned memory components, including the total sizes of the SGA and instance PGA.&lt;br /&gt;
&lt;br /&gt;
You can also use V$MEMORY_RESIZE_OPS which has a circular history buffer of the last 800 memory resize requests.&lt;br /&gt;
&lt;br /&gt;
2. Since the AMM (you have memory_target&amp;gt;0) is used, then make sure to set:&lt;br /&gt;
 _shared_pool_reserved_pct to 10 or 15 to ensure that when the Shared Pool grows or shrinks automatically, the Reserved Area will change as well.&lt;br /&gt;
&lt;br /&gt;
SQL&amp;gt; alter system set &amp;quot;_shared_pool_reserved_pct&amp;quot;=15 scope=spfile;&lt;br /&gt;
--restart the instance&lt;br /&gt;
&lt;br /&gt;
FYI: By default, Oracle configures a small Reserved Pool (or Reserved Area) inside the Shared Pool.&lt;br /&gt;
This memory can be used for operations such as PL/SQL and trigger compilation or for temporary space while loading Java objects.&lt;br /&gt;
After the memory allocated from the Reserved Pool is freed, it returns to the Reserved Pool.&lt;br /&gt;
5% of the Shared Pool is set aside as the Reserved Pool to handle allocations of memory higher than defined by the hidden parameter _shared_pool_reserved_pct.&lt;br /&gt;
In some application environments, 5% is too small.&lt;br /&gt;
&lt;br /&gt;
3. Set shared_pool_size=500M or even more. This will represent a minimum amount of memory that will always be available to the shared pool.&lt;br /&gt;
If more memory is needed at any moment, if it is available, it will be allocated to the shared pool over the 500M.&lt;br /&gt;
&lt;br /&gt;
Implement the above steps, monitor the database and let us know the result,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORA-00392: log 1 of thread 1 is being cleared, operation not allowed===&lt;br /&gt;
After performing an active duplication, this happened when trying to open the database.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SQL&amp;gt; alter database open resetlogs&lt;br /&gt;
alter database open resetlogs&lt;br /&gt;
*&lt;br /&gt;
ERROR at line 1:&lt;br /&gt;
ORA-00392: log 1 of thread 1 is being cleared, operation not allowed&lt;br /&gt;
ORA-00312: online log 1 thread 1: &amp;#039;/oracle/oradata/testdb/redo/redo01.log&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SQL&amp;gt; select group#,thread#,status from v$log;&lt;br /&gt;
 &lt;br /&gt;
GROUP#   THREAD#   STATUS&lt;br /&gt;
-------  --------- ----------------&lt;br /&gt;
1        1         CLEARING_CURRENT&lt;br /&gt;
2        1         STALE&lt;br /&gt;
3        1         STALE&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Check the alert log! Always a good idea to get extra info. In here we find the answer&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ORA-00344: unable to re-create online log&lt;br /&gt;
&amp;#039;/oracle/oradata/testdb/redo/redo01.log&amp;#039;&lt;br /&gt;
ORA-27040: file create error, unable to create file&lt;br /&gt;
Linux-x86_64 Error: 2: No such file or directory&lt;br /&gt;
Additional information: 1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
So the clue is that the file cannot be created at the operating system level.&amp;lt;br /&amp;gt;&lt;br /&gt;
Doing a &amp;lt;code&amp;gt;df -k /oracle/oradata/testdb/redo&amp;lt;/code&amp;gt; shows us that the filesystem was created too small for the destination database.&amp;lt;br /&amp;gt;&lt;br /&gt;
In this case, we do not want the redolog directory to be as big as on the source db as there will be almost no movement on the destination.&amp;lt;br /&amp;gt;&lt;br /&gt;
I should have specified the LOGFILE parameter in the DUPLICATE clause to setup new, smaller redolog files.&amp;lt;br /&amp;gt;&lt;br /&gt;
As this duplicate takes over 12 hours, I didn&amp;#039;t want to do it again so I created symbolic links in the redolog directory pointing out to a larger filesystem with more space.&amp;lt;br /&amp;gt;&lt;br /&gt;
This allowed the creation of the redolog files. They can then be resized once the database has been opened.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cd /oracle/oradata/testdb/redo&lt;br /&gt;
ln -s /tmp/redo01.log redo01.log&lt;br /&gt;
ln -s /tmp/redo02.log redo02.log&lt;br /&gt;
ln -s /tmp/redo03.log redo03.log&lt;br /&gt;
&lt;br /&gt;
SQL&amp;gt; alter database open resetlogs&lt;br /&gt;
Database opened.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===RMAN-04004: error from recovery catalog database: ORA-01017: invalid username/password; logon denied===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
oracle@host:/export/home/ora&amp;gt; rman target / catalog catowner/catpass@catdb&lt;br /&gt;
&lt;br /&gt;
Recovery Manager: Release 11.2.0.2.0 - Production on Thu Jun 12 16:51:03 2014&lt;br /&gt;
&lt;br /&gt;
Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.&lt;br /&gt;
&lt;br /&gt;
connected to target database: XXXXRAP1 (DBID=3557010742)&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-00554: initialization of internal recovery manager package failed&lt;br /&gt;
RMAN-04004: error from recovery catalog database: ORA-01017: invalid username/password; logon denied&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This is normally very straight-forward and self-explanatory.&amp;lt;br /&amp;gt;&lt;br /&gt;
The puzzle here is that a connection from SQL*Plus works!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sqlplus catowner/catpass@catdb&lt;br /&gt;
&lt;br /&gt;
SQL*Plus: Release 11.2.0.2.0 Production on Thu Jun 12 16:53:18 2014&lt;br /&gt;
&lt;br /&gt;
Copyright (c) 1982, 2010, Oracle.  All rights reserved.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Connected to:&lt;br /&gt;
Oracle Database 12c Enterprise Edition Release 12.1.0.1.0 - 64bit Production&lt;br /&gt;
With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options&lt;br /&gt;
SQL&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Eventually worked out that the rman binary in the databases ORACLE_HOME on the source machine needed relinking!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cd $ORACLE_HOME/rdbms/lib&lt;br /&gt;
make -f ins_rdbms.mk irman &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORA-00230: operation disallowed: snapshot control file enqueue unavailable===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
waiting for snapshot control file enqueue&lt;br /&gt;
waiting for snapshot control file enqueue&lt;br /&gt;
waiting for snapshot control file enqueue&lt;br /&gt;
waiting for snapshot control file enqueue&lt;br /&gt;
cannot make a snapshot control file&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-03008: error while performing automatic resync of recovery catalog&lt;br /&gt;
ORA-00230: operation disallowed: snapshot control file enqueue unavailable&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
From the doc...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
When RMAN needs to back up or resynchronize from the control file, it first creates a snapshot or consistent image of the control file.&lt;br /&gt;
If one RMAN job is already backing up the control file while another needs to create a new snapshot control file, then you may see the following message:&lt;br /&gt;
&lt;br /&gt;
waiting for snapshot controlfile enqueue&lt;br /&gt;
&lt;br /&gt;
Under normal circumstances, a job that must wait for the control file enqueue waits for a brief interval and then successfully obtains the enqueue.&lt;br /&gt;
RMAN makes up to five attempts to get the enqueue and then fails the job.&lt;br /&gt;
The conflict is usually caused when two jobs are both backing up the control file, and the job that first starts backing up the control file waits for service from the media manager.&lt;br /&gt;
&lt;br /&gt;
To determine which job is holding the conflicting enqueue:&lt;br /&gt;
&lt;br /&gt;
    After you see the first message stating &amp;quot;RMAN-08512: waiting for snapshot controlfile enqueue&amp;quot;, start a new SQL*Plus session on the target database:&lt;br /&gt;
&lt;br /&gt;
    % sqlplus &amp;#039;SYS/oracle@trgt AS SYSDBA&amp;#039;&lt;br /&gt;
&lt;br /&gt;
    Execute the following query to determine which job is causing the wait:&lt;br /&gt;
&lt;br /&gt;
    SELECT s.SID, USERNAME AS &amp;quot;User&amp;quot;, PROGRAM, MODULE, &lt;br /&gt;
           ACTION, LOGON_TIME &amp;quot;Logon&amp;quot;, l.* &lt;br /&gt;
    FROM V$SESSION s, V$ENQUEUE_LOCK l&lt;br /&gt;
    WHERE l.SID = s.SID&lt;br /&gt;
    AND l.TYPE = &amp;#039;CF&amp;#039;&lt;br /&gt;
    AND l.ID1 = 0&lt;br /&gt;
    AND l.ID2 = 2;&lt;br /&gt;
&lt;br /&gt;
    You should see output similar to the following (the output in this example has been truncated):&lt;br /&gt;
&lt;br /&gt;
    SID User Program              Module                    Action           Logon&lt;br /&gt;
    --- ---- -------------------- ------------------------- ---------------- ---------&lt;br /&gt;
      9 SYS  rman@h13 (TNS V1-V3) backup full datafile: c1  0000210 STARTED  21-JUN-01&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
After you have determined which job is creating the enqueue, you can do one of the following:&lt;br /&gt;
&lt;br /&gt;
    Wait until the job creating the enqueue completes&lt;br /&gt;
    Cancel the current job and restart it after the job creating the enqueue completes&lt;br /&gt;
    Cancel the job creating the enqueue&lt;br /&gt;
&lt;br /&gt;
Commonly, enqueue situations occur when a job is writing to a tape drive, but the tape drive is waiting for a new cassette to be inserted.&lt;br /&gt;
If you start a new job in this situation, then you will probably receive the enqueue message because the first job cannot complete until the new tape is loaded.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or more directly...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 2000&lt;br /&gt;
col killer     for a70&lt;br /&gt;
col program    for a20&lt;br /&gt;
col module     for a20&lt;br /&gt;
col action     for a20&lt;br /&gt;
col logon_time for a20&lt;br /&gt;
select &amp;#039;alter system disconnect session &amp;#039;&amp;#039;&amp;#039;||s.sid||&amp;#039;,&amp;#039;||s.serial#||&amp;#039;&amp;#039;&amp;#039; immediate;&amp;#039; killer&lt;br /&gt;
,      username&lt;br /&gt;
,      program&lt;br /&gt;
,      module&lt;br /&gt;
,      action&lt;br /&gt;
,      logon_time&lt;br /&gt;
from   v$session s&lt;br /&gt;
,      v$enqueue_lock l&lt;br /&gt;
where  l.sid  = s.sid&lt;br /&gt;
and    l.type = &amp;#039;cf&amp;#039;&lt;br /&gt;
and    l.id1  = 0&lt;br /&gt;
and    l.id2  = 2&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORA-19511: non RMAN, but media manager or vendor specific failure, error text:===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-03002: failure of Duplicate Db command at 05/01/2018 14:23:09&lt;br /&gt;
RMAN-05501: aborting duplication of target database&lt;br /&gt;
RMAN-03015: error occurred in stored script Memory Script&lt;br /&gt;
ORA-27191: sbtinfo2 returned error&lt;br /&gt;
Additional information: 3586&lt;br /&gt;
ORA-19511: non RMAN, but media manager or vendor specific failure, error text:&lt;br /&gt;
   Unable to connect to NetWorker server &amp;#039;hn6000.cln.be&amp;#039; because &amp;#039;Authentication error; why = Invalid client credential&amp;#039;. (2:10:79)&lt;br /&gt;
&lt;br /&gt;
Recovery Manager complete.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
If this happens, check to see if the nsr daemon is running...&amp;lt;br /&amp;gt;&lt;br /&gt;
Good system:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/home/oracle&amp;gt; ps -ef | grep nsr&lt;br /&gt;
    root  5701836        1   0   Mar 16      - 13:18 /bin/nsrexecd&lt;br /&gt;
  oracle 18809292 22741502   0 15:03:58  pts/0  0:00 grep nsr&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Bad system:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 /home/oracle&amp;gt; ps -ef | grep nsr&lt;br /&gt;
  oracle 14745986 15139292   0 15:03:29  pts/2  0:00 grep nsr&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORA-19554: error allocating device, device type: SBT_TAPE, device name:===&lt;br /&gt;
If using Cygwin...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-03002: failure of backup command at 05/19/2015 12:25:47&lt;br /&gt;
ORA-19554: error allocating device, device type: SBT_TAPE, device name:&lt;br /&gt;
ORA-27000: skgfqsbi: failed to initialize storage subsystem (SBT) layer&lt;br /&gt;
OSD-02534: Message 2534 not found;  product=RDBMS; facility=SOSD&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Check the tdpo.opt file is where you think it is!&lt;br /&gt;
* Check the path to the opt file looks like this (needs to be Windows format):&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
CONFIGURE CHANNEL DEVICE TYPE &amp;#039;SBT_TAPE&amp;#039; FORMAT   &amp;#039;LOG_%d_t%t_s%s_u%U&amp;#039; PARMS  &amp;#039;ENV=(TDPO_OPTFILE=E:\oracle\KITRYD\admin\tdpo.opt)&amp;#039;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Check the content of the opt file is Windows format paths!&lt;br /&gt;
&lt;br /&gt;
===RMAN-20033: control file SEQUENCE# too low===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-03008: error while performing automatic resync of recovery catalog&lt;br /&gt;
===RMAN-20033: control file SEQUENCE# too low===&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
From [https://forums.oracle.com/forums/thread.jspa?threadID=1115969 forums.oracle.com]&amp;lt;br /&amp;gt;&lt;br /&gt;
This error generally happens if an archivelog backup happens while the RMAN database backup is running and if controlfile autobackup is configured.&amp;lt;br /&amp;gt;&lt;br /&gt;
The database backup is usually successful and it is just the controlfile backup that fails.&lt;br /&gt;
===ORA-27302: failure occurred at: slgpn===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
RMAN-03009: failure of Control File and SPFILE Autobackup command on c1 channel at 06/28/2011 18:59:38&lt;br /&gt;
ORA-19715: invalid format %b for generated name&lt;br /&gt;
ORA-27302: failure occurred at: slgpn&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Problem====&lt;br /&gt;
When doing a &amp;quot;&amp;lt;tt&amp;gt;backup as copy database&amp;lt;/tt&amp;gt;&amp;quot;, got these errors after 145 of 147 datafiles had been backed up!&lt;br /&gt;
&lt;br /&gt;
====Investigation====&lt;br /&gt;
I had read [https://oracleedge.wordpress.com/2011/06/29/oracle-rman-03009-ora-19715-ora-27302/ elsewhere] that this could be something to do with the format of the autobackup of the control file so I changed the format as suggested and reran the backup.&amp;lt;br /&amp;gt;&lt;br /&gt;
No luck. It ended exactly the same way after 145 files. I decided to compare the original list of datafiles with those that had been backed up in order to track down the 2 failures. Maybe I could see something odd with them.&amp;lt;br /&amp;gt;&lt;br /&gt;
Sure enough, these 2 files were different... there was a space at the &amp;#039;&amp;#039;&amp;#039;end&amp;#039;&amp;#039;&amp;#039; of the filenames :-)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select &amp;#039;x&amp;#039;||file_name||&amp;#039;x&amp;#039;&lt;br /&gt;
from   dba_data_files&lt;br /&gt;
where  file_name like &amp;#039;% %&amp;#039;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Solution====&lt;br /&gt;
Run the backup of the other 2 datafiles with a different format that did not rely on the filename.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
run {&lt;br /&gt;
    allocate channel c1 device type disk format &amp;#039;/path/to/datafiles/%U&amp;#039;;&lt;br /&gt;
    backup as copy datafile 170;&lt;br /&gt;
    backup as copy datafile 171;&lt;br /&gt;
    backup as copy current controlfile;&lt;br /&gt;
    release channel c1;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The other 145 datafiles were backed up with a format of &amp;#039;/path/to/datafiles/%b&amp;#039; which preserves the filenames so all that needs to be done is rename the other 2 after the backup finishes.&amp;lt;br /&amp;gt;&lt;br /&gt;
If they are going to be used in a restore scenario, they should be renamed in the controlfile also.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter database rename file &amp;#039;/path/to/datafiles/filename_with_a_space_at_end &amp;#039; to &amp;#039;/path/to/datafiles/filename_without_a_space&amp;#039;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===RMAN errors after crosscheck backup and delete noprompt obsolete and delete noprompt expired backup===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
RMAN-06207: WARNING: 3921 objects could not be deleted for SBT_TAPE channel(s) due&lt;br /&gt;
RMAN-06208:          to mismatched status.  Use CROSSCHECK command to fix status&lt;br /&gt;
RMAN-06210: List of Mismatched objects&lt;br /&gt;
RMAN-06211: ==========================&lt;br /&gt;
RMAN-06212:   Object Type   Filename/Handle&lt;br /&gt;
RMAN-06213: --------------- ---------------------------------------------------&lt;br /&gt;
RMAN-06214: Backup Piece    DB_SID_t20140316_s263889_umhp3bpa7_1_1&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Use the FORCE option with the DELETE command&amp;lt;br /&amp;gt;&lt;br /&gt;
The FORCE command tells RMAN to clean the information out of the catalog regardless of whether it can find it on the media or not.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
delete force noprompt expired backup;&lt;br /&gt;
delete force noprompt obsolete;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===RMAN-06004: ORACLE error from recovery catalog database: RMAN-20003: target database incarnation not found in recovery catalog===&lt;br /&gt;
====Problem:====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-03002: failure of Duplicate Db command at 12/05/2017 11:11:15&lt;br /&gt;
RMAN-05501: aborting duplication of target database&lt;br /&gt;
RMAN-03015: error occurred in stored script Memory Script&lt;br /&gt;
RMAN-06004: ORACLE error from recovery catalog database: RMAN-20003: target database incarnation not found in recovery catalog&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Solution:====&lt;br /&gt;
Strangely, this means, in my particular case, that block change tracking is turned on in the target databse and needs turning off in the auxiliary while the DUPLICATE is running.&amp;lt;br /&amp;gt;&lt;br /&gt;
It must be done while the auxiliary is in mount mode and restoring the datafiles (before recovery starts)&amp;lt;br /&amp;gt;&lt;br /&gt;
It is reported to be a bug fixed in 11.1 but somehow, we&amp;#039;re still (sometimes) getting it in 12.1.0.2.&lt;br /&gt;
&lt;br /&gt;
===RMAN-06059: expected archived log not found, loss of archived log compromises recoverability===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
RMAN-06059: expected archived log not found, loss of archived log compromises recoverability&lt;br /&gt;
ORA-19625: error identifying file &amp;lt;filename&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This error can come from the fact that the database files (more likely archivelogs) are being deleted by the operating system so RMAN has no clue of their whereabouts.&amp;lt;br /&amp;gt;&lt;br /&gt;
Possibly result of a database duplication and the catalog has not updated properly?&amp;lt;br /&amp;gt;&lt;br /&gt;
====Solution====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
crosscheck archivelog all;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
And then maybe take a backup to be on the safe side.&lt;br /&gt;
&lt;br /&gt;
===RMAN-05537: DUPLICATE without TARGET connection when auxiliary instance is started with spfile cannot use SPFILE clause===&lt;br /&gt;
====Problem:====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-03002: failure of Duplicate Db command at 12/05/2017 14:17:49&lt;br /&gt;
RMAN-05501: aborting duplication of target database&lt;br /&gt;
RMAN-05537: DUPLICATE without TARGET connection when auxiliary instance is started with spfile cannot use SPFILE clause&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Usually happens after restarting a failed RMAN DUPLICATE database. The spfile has been regenerated on the auxiliary to a level where it has too much detail in it.&lt;br /&gt;
====Solution:====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ cd $ORACLE_HOME/dbs&lt;br /&gt;
$ ls -altr *dwh_perf*&lt;br /&gt;
-rw-r-----    1 oracle   oinstall   17645568 Aug  3 13:34 snapcf_dwh_perf.f&lt;br /&gt;
-rw-r-----    1 oracle   oinstall       7680 Nov  4 09:22 orapwdwh_perf&lt;br /&gt;
-rw-r--r--    1 oracle   oinstall        104 Dec  5 09:34 initdwh_perf.ora&lt;br /&gt;
-rw-r-----    1 oracle   oinstall       6656 Dec  5 11:11 spfiledwh_perf.ora&lt;br /&gt;
-rw-rw----    1 oracle   oinstall       1544 Dec  5 14:18 hc_dwh_perf.dat&lt;br /&gt;
$ mv hc_dwh_perf.dat hc_dwh_perf.dat.old&lt;br /&gt;
$ mv spfiledwh_perf.ora spfiledwh_perf.ora.old&lt;br /&gt;
$ cat initdwh_perf.ora&lt;br /&gt;
sga_max_size=&amp;#039;6G&amp;#039;&lt;br /&gt;
sga_target=&amp;#039;6G&amp;#039;&lt;br /&gt;
compatible=&amp;#039;12.0.0&amp;#039;&lt;br /&gt;
db_files=&amp;#039;500&amp;#039;&lt;br /&gt;
&lt;br /&gt;
# Instance name&lt;br /&gt;
db_name=dwh_perf&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Re-run the DUPLICATE. It should zoom past the already recovered datafiles.&lt;br /&gt;
&lt;br /&gt;
===PSDRPC returns significant error 1013===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
archived log thread=1 sequence=195008&lt;br /&gt;
channel t2: reading from backup piece arclog_LBK_4260753020_946042770_479194_1&lt;br /&gt;
channel t0: piece handle=arclog_LBK_4260753020_946042770_479192_1 tag=TAG20170607T133757&lt;br /&gt;
channel t0: restored backup piece 1&lt;br /&gt;
channel t0: restore complete, elapsed time: 00:00:35&lt;br /&gt;
archived log file name=/xxxxxx/acc/ora_bin2/app/oracle/product/11.2.0.4/dbhome_1/dbs/arch1_195006_815790039.dbf thread=1 sequence=195006&lt;br /&gt;
PSDRPC returns significant error 1013.&lt;br /&gt;
PSDRPC returns significant error 1013.&lt;br /&gt;
released channel: t0&lt;br /&gt;
released channel: t1&lt;br /&gt;
released channel: t2&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-03002: failure of Duplicate Db command at 06/09/2017 15:15:04&lt;br /&gt;
RMAN-05501: aborting duplication of target database&lt;br /&gt;
RMAN-03015: error occurred in stored script Memory Script&lt;br /&gt;
RMAN-11003: failure during parse/execution of SQL statement: alter database recover logfile &amp;#039;/xxxxxx/acc/ora_bin2/app/oracle/product/11.2.0.4/dbhome_1/dbs/arch1_195006_815790039.dbf&amp;#039;&lt;br /&gt;
ORA-10877: error signaled in parallel recovery slave&lt;br /&gt;
&lt;br /&gt;
Recovery Manager complete.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Action====&lt;br /&gt;
Check the alert log on the auxiliary instance.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ORA-279 signalled during: alter database recover logfile &amp;#039;/xxxxxx/acc/ora_bin2/app/oracle/product/11.2.0.4/dbhome_1/dbs/arch1_195005_815790039.dbf&amp;#039;...&lt;br /&gt;
alter database recover logfile &amp;#039;/xxxxxx/acc/ora_bin2/app/oracle/product/11.2.0.4/dbhome_1/dbs/arch1_195006_815790039.dbf&amp;#039;&lt;br /&gt;
Media Recovery Log /xxxxxx/acc/ora_bin2/app/oracle/product/11.2.0.4/dbhome_1/dbs/arch1_195006_815790039.dbf&lt;br /&gt;
Fri Jun 09 07:30:30 2017&lt;br /&gt;
Errors with log /xxxxxx/acc/ora_bin2/app/oracle/product/11.2.0.4/dbhome_1/dbs/arch1_195006_815790039.dbf&lt;br /&gt;
Recovery interrupted!&lt;br /&gt;
Recovered data files to a consistent state at change 238029030495&lt;br /&gt;
Media Recovery failed with error 19755&lt;br /&gt;
Errors in file /xxxxxx/acc/ora_bin2/app/oracle/diag/rdbms/lbkro/lbkro/trace/lbkro_pr00_13108374.trc:&lt;br /&gt;
ORA-00283: recovery session canceled due to errors&lt;br /&gt;
===&amp;gt;ORA-19755: could not open change tracking file&lt;br /&gt;
===&amp;gt;ORA-19750: change tracking file: &amp;#039;/xxxxxx/exp/ora_data2/lbk/data/bct_lbk_do_not_delete.f&lt;br /&gt;
===&amp;gt;ORA-27037: unable to obtain file status&lt;br /&gt;
===&amp;gt;IBM AIX RISC System/6000 Error: 2: No such file or directory&lt;br /&gt;
Additional information: 3&lt;br /&gt;
Fri Jun 09 07:30:36 2017&lt;br /&gt;
ORA-10877 signalled during: alter database recover logfile &amp;#039;/xxxxxx/acc/ora_bin2/app/oracle/product/11.2.0.4/dbhome_1/dbs/arch1_195006_815790039.dbf&amp;#039;...&lt;br /&gt;
Fri Jun 09 14:04:57 2017&lt;br /&gt;
alter database recover logfile &amp;#039;/xxxxxx/acc/ora_bin2/app/oracle/product/11.2.0.4/dbhome_1/dbs/arch1_195006_815790039.dbf&amp;#039;&lt;br /&gt;
Media Recovery Log /xxxxxx/acc/ora_bin2/app/oracle/product/11.2.0.4/dbhome_1/dbs/arch1_195006_815790039.dbf&lt;br /&gt;
Media Recovery failed with error 1112&lt;br /&gt;
ORA-283 signalled during: alter database recover logfile &amp;#039;/xxxxxx/acc/ora_bin2/app/oracle/product/11.2.0.4/dbhome_1/dbs/arch1_195006_815790039.dbf&amp;#039;...&lt;br /&gt;
Fri Jun 09 14:31:20 2017&lt;br /&gt;
Shutting down instance (immediate)&lt;br /&gt;
Shutting down instance: further logons disabled&lt;br /&gt;
Stopping background process MMNL&lt;br /&gt;
Stopping background process MMON&lt;br /&gt;
License high water mark = 49&lt;br /&gt;
ALTER DATABASE CLOSE NORMAL&lt;br /&gt;
ORA-1109 signalled during: ALTER DATABASE CLOSE NORMAL...&lt;br /&gt;
ALTER DATABASE DISMOUNT&lt;br /&gt;
Shutting down archive processes&lt;br /&gt;
Archiving is disabled&lt;br /&gt;
Completed: ALTER DATABASE DISMOUNT&lt;br /&gt;
ARCH: Archival disabled due to shutdown: 1089&lt;br /&gt;
Shutting down archive processes&lt;br /&gt;
Archiving is disabled&lt;br /&gt;
ARCH: Archival disabled due to shutdown: 1089&lt;br /&gt;
Shutting down archive processes&lt;br /&gt;
Archiving is disabled&lt;br /&gt;
Fri Jun 09 14:31:24 2017&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This is a known bug. it is fixed in 11.2.0.3 but... this customer does not apply patches!&lt;br /&gt;
&lt;br /&gt;
====Solution====&lt;br /&gt;
While the DUPLICATE is running (and in MOUNT mode), log on to the auxiliary instance and disable block change tracking.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter database disable block change tracking;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
A documented workaround is to set db_filename_convert parameter in the DUPLICATE clause of the run block but I tried this and it failed again.&amp;lt;br /&amp;gt;&lt;br /&gt;
The obvious solution is to patch the database but...&lt;br /&gt;
&lt;br /&gt;
===Database trigger to capture ORA errors===&lt;br /&gt;
From [http://ora-ssn.blogspot.be/2011/10/trigger-on-database-to-capture-ora.html ora-ssn.blogspot.be]&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
CREATE TABLE stats$error_log (&lt;br /&gt;
        err_dt          TIMESTAMP,&lt;br /&gt;
        db_user         VARCHAR2(30),&lt;br /&gt;
        msg_stack       VARCHAR2(2000),&lt;br /&gt;
        sqltxt          VARCHAR2(1000))&lt;br /&gt;
tablespace users;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Now, create a trigger on the database server.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
CREATE OR REPLACE TRIGGER log_server_errors&lt;br /&gt;
  AFTER SERVERERROR&lt;br /&gt;
  ON DATABASE&lt;br /&gt;
DECLARE&lt;br /&gt;
          v_sqltext VARCHAR2(1000);&lt;br /&gt;
          nl_sqltext ora_name_list_t;&lt;br /&gt;
  BEGIN&lt;br /&gt;
          -- Capture entire error text&lt;br /&gt;
          FOR i IN 1 .. ora_sql_txt(nl_sqltext) LOOP&lt;br /&gt;
            v_sqltext := v_sqltext || nl_sqltext(i);&lt;br /&gt;
          END LOOP;&lt;br /&gt;
          INSERT INTO STATS$ERROR_LOG&lt;br /&gt;
          (err_dt, db_user, msg_stack, sqltxt)&lt;br /&gt;
          VALUES&lt;br /&gt;
          (systimestamp,&lt;br /&gt;
           sys.login_user,&lt;br /&gt;
           dbms_utility.format_error_stack, v_sqltext);&lt;br /&gt;
  END log_server_errors;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORA-19809: limit exceeded for recovery files===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-03009: failure of backup command on ORA_DISK_1 channel at 07/15/2013 10:10:59&lt;br /&gt;
ORA-19809: limit exceeded for recovery files&lt;br /&gt;
ORA-19804: cannot reclaim 274716160 bytes disk space from 1468006400 limit&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    ORA-19809: limit exceeded for recovery files&lt;br /&gt;
    Cause: The limit for recovery files specified by the db_recovery_file_dest_size was exceeded.&lt;br /&gt;
&lt;br /&gt;
    Action: The error is accompanied by 19804. See message 19804 for further details&lt;br /&gt;
&lt;br /&gt;
    ORA-19804: cannot reclaim string bytes disk space from string limit&lt;br /&gt;
    Cause: Oracle cannot reclaim disk space of specified bytes from the DB_RECOVERY_FILE_DEST_SIZE limit.&lt;br /&gt;
&lt;br /&gt;
    Action: There are five possible solutions:&lt;br /&gt;
       1) Take frequent backup of recovery area using RMAN.&lt;br /&gt;
       2) Consider changing RMAN retention policy.&lt;br /&gt;
       3) Consider changing RMAN archivelog deletion policy.&lt;br /&gt;
       4) Add disk space and increase DB_RECOVERY_FILE_DEST_SIZE.&lt;br /&gt;
       5) Delete files from recovery area using RMAN.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The solution here is to increase the value of db_recovery_file_dest_size but it might also indicate a problem with tapes if the archivelogs are being backed up to tape via tdpo.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SYS@DN7&amp;gt; alter system set db_recovery_file_dest_size=4000M scope=both;&lt;br /&gt;
&lt;br /&gt;
System altered.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Looking into int further, saw RMAN parameters missing...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
CONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF 14 DAYS;&lt;br /&gt;
CONFIGURE BACKUP OPTIMIZATION OFF;&lt;br /&gt;
CONFIGURE DEFAULT DEVICE TYPE TO &amp;#039;SBT_TAPE&amp;#039;;&lt;br /&gt;
CONFIGURE CONTROLFILE AUTOBACKUP ON;&lt;br /&gt;
CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE &amp;#039;SBT_TAPE&amp;#039; TO &amp;#039;LOG_%d_controlfile_%F.rman&amp;#039;;&lt;br /&gt;
CONFIGURE DEVICE TYPE &amp;#039;SBT_TAPE&amp;#039; PARALLELISM 1 BACKUP TYPE TO BACKUPSET;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===RMAN-00554: initialization of internal recovery manager package failed===&lt;br /&gt;
Getting this error after migrating a database from one machine to another and attaching to a nice new version 12c catalog on the new server&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Recovery Manager: Release 11.2.0.2.0 - Production on Sat Jun 21 13:16:24 2014&lt;br /&gt;
&lt;br /&gt;
Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.&lt;br /&gt;
&lt;br /&gt;
connected to target database: SPMSUPP1 (DBID=3026014394)&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-00554: initialization of internal recovery manager package failed&lt;br /&gt;
RMAN-04004: error from recovery catalog database: ORA-01017: invalid username/password; logon denied&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
We cannot connect to the catalog via rman but there is no problem if connecting via SQL*Plus!&amp;lt;br /&amp;gt;&lt;br /&gt;
Solution: relink the rman executable.&lt;br /&gt;
===Using AIX commands genld, genkld and slibclean to avoid library file locking errors (libjox) (Doc ID 739963.1)===&lt;br /&gt;
* [https://support.oracle.com/epmos/faces/DocumentDisplay?_afrLoop=206851390914720&amp;amp;id=739963.1&amp;amp;_afrWindowMode=0&amp;amp;_adf.ctrl-state=e0pq23tou_4 Metalink]&lt;br /&gt;
When installing interim (one-off) patches, CPU patches or patchsets, you may encounter some errors with regards to files being locked or oui/opatch being unable to copy files&amp;lt;br /&amp;gt;&lt;br /&gt;
even though the databases, listeners and all other Oracle processes associated with the ORACLE_HOME to be patched were stopped.&amp;lt;br /&amp;gt;&lt;br /&gt;
This could be as result of a process which requires termination or an additional file needing to be unloaded from the system cache.&amp;lt;br /&amp;gt;&lt;br /&gt;
Run following commands to clean up...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
genld -l | grep &amp;lt;ORACLE_HOME&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
If genld returns data then a currently executing process has something open in the ORACLE_HOME directory, therefore terminate the process as required/recommended.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
genkld | grep &amp;lt;ORACLE_HOME&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
If the genkld command  returns a  list of shared objects currently loaded onto the OS system cache then please remove the entries from the OS system cache by running the slibclean command as root user:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/usr/sbin/slibclean&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===ORA-20011: Approximate NDV failed: ORA-29913: error in executing ODCIEXTTABLEOPEN callout===&lt;br /&gt;
This seems to be related to orphaned Datapump tables. Generally seems to be a problem when stats jobs are running during the night (dbms_stats)&amp;lt;br /&amp;gt;&lt;br /&gt;
* Check no datapump jobs are running&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select * from dba_datapump_jobs;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Find orphaned tables&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 2000&lt;br /&gt;
select owner&lt;br /&gt;
,      object_name&lt;br /&gt;
,      object_type&lt;br /&gt;
,      status&lt;br /&gt;
,      to_char(created,&amp;#039;dd-mon-yyyy hh24:mi:ss&amp;#039;) created&lt;br /&gt;
,      to_char(last_ddl_time,&amp;#039;dd-mon-yyyy hh24:mi:ss&amp;#039;) last_ddl_time&lt;br /&gt;
from   dba_objects&lt;br /&gt;
where  1=1&lt;br /&gt;
and    object_name like &amp;#039;ET$%&amp;#039;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Check that  any rows seen are actually external tables&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select owner&lt;br /&gt;
,      table_name&lt;br /&gt;
,      default_directory_name&lt;br /&gt;
,      access_type&lt;br /&gt;
from   dba_external_tables&lt;br /&gt;
order  by 1,2&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Drop the tables if they are not currently being used (no datapump jobs running)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
drop table &amp;amp;&amp;amp;owner..&amp;amp;table_name;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===ORA-01547: warning: RECOVER succeeded but OPEN RESETLOGS would get error below===&lt;br /&gt;
Database is restored and now we want to recover it but we see this...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Starting recover at 24-JUL-15 11:26:19&lt;br /&gt;
&lt;br /&gt;
starting media recovery&lt;br /&gt;
&lt;br /&gt;
unable to find archive log&lt;br /&gt;
archive log thread=1 sequence=69763&lt;br /&gt;
Oracle Error: &lt;br /&gt;
ORA-01547: warning: RECOVER succeeded but OPEN RESETLOGS would get error below&lt;br /&gt;
ORA-01194: file 1 needs more recovery to be consistent&lt;br /&gt;
ORA-01110: data file 1: &amp;#039;/oracle/TRSCRP1/oradata2/system01.dbf&amp;#039;&lt;br /&gt;
&lt;br /&gt;
released channel: c1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This means that although we have restored the database, we are still missing information to complete the recovery. This information is contained in the archived redo logs which must also be restored (from tape if they are no longer on disk)&amp;lt;br /&amp;gt;&lt;br /&gt;
We can see here that we need an archive log with sequence number 69763. But what is the file called and where should it be restored to?&amp;lt;br /&amp;gt;&lt;br /&gt;
For this we can go to SQL*Plus and get the database to tell us&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
recover database using backup controlfile until cancel;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
and cancel straight away.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ORA-00279: change 13796376414661 generated at 07/14/2015 13:20:07 needed for&lt;br /&gt;
thread 1&lt;br /&gt;
ORA-00289: suggestion : /oracle/TRSCRP1/archive/arch_TRSCRP1_1_69763.arc&lt;br /&gt;
ORA-00280: change 13796376414661 for thread 1 is in sequence #69763&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Specify log: {&amp;lt;RET&amp;gt;=suggested | filename | AUTO | CANCEL}&lt;br /&gt;
cancel&lt;br /&gt;
ORA-01547: warning: RECOVER succeeded but OPEN RESETLOGS would get error below&lt;br /&gt;
ORA-01194: file 1 needs more recovery to be consistent&lt;br /&gt;
ORA-01110: data file 1: &amp;#039;/oracle/TRSCRP1/oradata2/system01.dbf&amp;#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
ORA-01112: media recovery not started&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Now we see that we need to find a file called arch_TRSCRP1_1_69763.arc and put it in the directory /oracle/TRSCRP1/archive.&amp;lt;br /&amp;gt;&lt;br /&gt;
This will continue up until the time specified for the recover so restore a whole bunch of them.&amp;lt;br /&amp;gt;&lt;br /&gt;
Repeat the &amp;quot;recover database using backup controlfile until cancel;&amp;quot; command and type AUTO or Enter until you&amp;#039;ve got to where you need to be.&amp;lt;br /&amp;gt;&lt;br /&gt;
Type CANCEL when point is reached and&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter database open resetlogs;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Stuart</name></author>	</entry>

	<entry>
		<id>https://mailnest.com/dbawiki/index.php?title=Oracle_errors&amp;diff=3360</id>
		<title>Oracle errors</title>
		<link rel="alternate" type="text/html" href="https://mailnest.com/dbawiki/index.php?title=Oracle_errors&amp;diff=3360"/>
				<updated>2018-11-03T16:33:40Z</updated>
		
		<summary type="html">&lt;p&gt;Stuart: /* ORA-14097: column type or size mismatch in ALTER TABLE EXCHANGE PARTITION */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;===ORA-00600===&lt;br /&gt;
[https://support.oracle.com/epmos/faces/DocContentDisplay?_afrLoop=397490397952859&amp;amp;id=1092832.1&amp;amp;_afrWindowMode=0&amp;amp;_adf.ctrl-state=184vwc6g3y_4 Master Note for Diagnosing ORA-600 (Doc ID 1092832.1)]&lt;br /&gt;
===ORA-19051: Cannot use fast path insert for this XMLType table===&lt;br /&gt;
Think LD_LIBRARY_PATH on Linux or LIBPATH on AIX.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Export: Release 11.2.0.4.0 - Production on Thu Jun 1 06:41:55 2017&lt;br /&gt;
&lt;br /&gt;
Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.&lt;br /&gt;
&lt;br /&gt;
Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production&lt;br /&gt;
With the Partitioning, OLAP, Data Mining and Real Application Testing options&lt;br /&gt;
Starting &amp;quot;DWH_EXPORT&amp;quot;.&amp;quot;SYS_EXPORT_TABLE_03&amp;quot;:  dwh_export/******** parfile=cadis_foto_export_credit_dba.par&lt;br /&gt;
Estimate in progress using BLOCKS method...&lt;br /&gt;
Processing object type TABLE_EXPORT/TABLE/TABLE_DATA&lt;br /&gt;
Total estimation using BLOCKS method: 64.08 GB&lt;br /&gt;
ORA-39126: Worker unexpected fatal error in KUPW$WORKER.FETCH_XML_OBJECTS []&lt;br /&gt;
ORA-19051: Cannot use fast path insert for this XMLType table&lt;br /&gt;
&lt;br /&gt;
ORA-06512: at &amp;quot;SYS.DBMS_SYS_ERROR&amp;quot;, line 86&lt;br /&gt;
ORA-06512: at &amp;quot;SYS.KUPW$WORKER&amp;quot;, line 9710&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Problem====&lt;br /&gt;
When the 11g DB was started, LD_LIBRARY_PATH and LIBPATH were still pointing to paths in the 10g Home.&lt;br /&gt;
====Solution====&lt;br /&gt;
There may have been some odd values setup in LD_LIBRARY_PATH before the call to oraenv (if oraenv was indeed called!)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
unset LD_LIBRARY_PATH LIBPATH&lt;br /&gt;
export ORACLE_SID=&amp;lt;correct 11g SID&amp;gt;&lt;br /&gt;
. oraenv&lt;br /&gt;
echo $LD_LIBRARY_PATH&lt;br /&gt;
echo $LIBPATH&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
They should now be correct.&lt;br /&gt;
&lt;br /&gt;
===ORA-27092: size of file exceeds file size limit of the process===&lt;br /&gt;
Think ulimit...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Cause: an attempt was made to open a file that exceeds the process&amp;#039;s file size limit (ulimit), additional information shows the current limit (logical blocks) and the size of the file (logical blocks)&lt;br /&gt;
Action: increase the processes file size limit (ulimit) and retry&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
truncate table pibadm.test_ph&lt;br /&gt;
                      *&lt;br /&gt;
Error at line 1 :&lt;br /&gt;
ORA-00604: error ocurred at recursive SQL level 1&lt;br /&gt;
ORA-01116: error in opening database file 2&lt;br /&gt;
ORA-01110: datafile 2 : &amp;#039;/opt/u01/data/PIBQA/UNDO_01.dbf&amp;#039;&lt;br /&gt;
ORA-27092: size of file exceeds file size limit of the process&lt;br /&gt;
Additional information: 262143&lt;br /&gt;
Additional information: 2621441&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Check the fs_size limit for this user in /etc/security/limits&amp;lt;br /&amp;gt;&lt;br /&gt;
Compare this with another user, say oracle. Probably -1 (unlimited)&lt;br /&gt;
&lt;br /&gt;
===SP2-1503: Unable to initialize Oracle call interface===&lt;br /&gt;
When trying to login to the database via SQL*Plus, these messages a displayed&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
hn5118 /home/oracle $sqlplus / as sysdba&lt;br /&gt;
SP2-1503: Unable to initialize Oracle call interface&lt;br /&gt;
SP2-0152: ORACLE may not be functioning properly&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Seems to be a problem unique to AIX (in this case).&amp;lt;br /&amp;gt;&lt;br /&gt;
Check to see what the LIBPATH variable is. It may still contain a path to an old ORACLE_HOME...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
hn5118 /home/oracle $env|grep LIBPATH&lt;br /&gt;
LIBPATH=/oracle/exp/ora_bin1/app/oracle/product/10.2.0/db_1/lib:/oracle/exp/ora_bin1/app/oracle/product/10.2.0/db_1/lib&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Disco! Unset it and rerun.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
hn5118 /home/oracle $unset LIBPATH&lt;br /&gt;
&lt;br /&gt;
hn5118 /home/oracle $sqlplus / as sysdba&lt;br /&gt;
&lt;br /&gt;
SQL*Plus: Release 12.1.0.2.0 Production on Wed Jul 12 17:17:54 2017&lt;br /&gt;
&lt;br /&gt;
Copyright (c) 1982, 2014, Oracle.  All rights reserved.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Connected to:&lt;br /&gt;
Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production&lt;br /&gt;
With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options&lt;br /&gt;
&lt;br /&gt;
SQL&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===UDE-31623: operation generated ORACLE error 31623===&lt;br /&gt;
When using Data pump, get following errors almost immediately:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
UDE-31623: operation generated ORACLE error 31623&lt;br /&gt;
ORA-31623: a job is not attached to this session via the specified handle&lt;br /&gt;
ORA-06512: at &amp;quot;SYS.DBMS_DATAPUMP&amp;quot;, line 3326&lt;br /&gt;
ORA-06512: at &amp;quot;SYS.DBMS_DATAPUMP&amp;quot;, line 4551&lt;br /&gt;
ORA-06512: at line 1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Solution 1:&amp;#039;&amp;#039;&amp;#039;&amp;lt;br /&amp;gt;&lt;br /&gt;
In one case, I simplified the parameter file that was used. Maybe related to Streams Pool size, who knows?!&amp;lt;br /&amp;gt;&lt;br /&gt;
I removed these 2 lines and the export started working:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
compression_algorithm=medium&lt;br /&gt;
logtime=all&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Solution 2:&amp;#039;&amp;#039;&amp;#039;&amp;lt;br /&amp;gt;&lt;br /&gt;
There is a note about this on Metalink, 1080775.1 which suggests that Streams Pool Size needs setting.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
For this DataPump error, you will need to configure the database with some Streams Pool.&lt;br /&gt;
&lt;br /&gt;
Perform the following query to find out how much STREAMS_POOL_SIZE has been allocated&lt;br /&gt;
&lt;br /&gt;
 select * from v$sgainfo;&lt;br /&gt;
 ...&lt;br /&gt;
 Streams Pool Size                               0 Yes&lt;br /&gt;
&lt;br /&gt;
Data Pump now uses Advanced Queuing (AQ) internally, so it can handle job stops/starts/re-starts.  However, AQ using the Streams Pool, where the database currently has the STREAMS_POOL_SIZE set to ZERO.&lt;br /&gt;
&lt;br /&gt;
Manually set the STREAMS_POOL_SIZE (using ALTER SYSTEM or by changing the value in the the PFILE/SPFILE), re-start the database and re-attempt the Data Pump Export.&lt;br /&gt;
&lt;br /&gt;
Alternately, turn on Automatic Shared Memory management (ASMM) by setting SGA_TARGET or MEMORY_TARGET.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
From Oracle Documentation&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Setting the Size Of the Buffer Cache In a Streams Environment&lt;br /&gt;
&lt;br /&gt;
Oracle Data Pump uses Streams functionality to communicate between processes.&lt;br /&gt;
If the SGA_TARGET initialization parameter is set, then the STREAMS_POOL_SIZE initialization parameter is automatically set to a reasonable value.&lt;br /&gt;
If the SGA_TARGET initialization parameter is not set and the STREAMS_POOL_SIZE initialization parameter is not defined,&lt;br /&gt;
then the size of the streams pool automatically defaults to 10% of the size of the shared pool.&lt;br /&gt;
&lt;br /&gt;
When the streams pool is created, the required SGA memory is taken from memory allocated to the buffer cache,&lt;br /&gt;
reducing the size of the cache to less than what was specified by the DB_CACHE_SIZE initialization parameter.&lt;br /&gt;
This means that if the buffer cache was configured with only the minimal required SGA, then Data Pump operations may not work properly.&lt;br /&gt;
A minimum size of 10M is recommended for STREAMS_POOL_SIZE in order to ensure successful Data Pump operations.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORA-00020: maximum number of processes (150) exceeded===&lt;br /&gt;
Check the current resource limits with:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 300&lt;br /&gt;
select * from v$resource_limit;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Unfortunately this limit cannot be increased without a restart.&amp;lt;br /&amp;gt;&lt;br /&gt;
It may be a necessary to increase the limit with&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter system set processes=500 scope=spfile;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
followed by a shutdown/startup&amp;lt;br /&amp;gt;&lt;br /&gt;
Or it may be some user is running away with the limit.&amp;lt;br /&amp;gt;&lt;br /&gt;
Check to see who is running what with:&lt;br /&gt;
[[http://www.mailnest.com/dbawiki/index.php/Handy_scripts#See_what_statements_all_users_are_running See_what_statements_all_users_are_running]]&lt;br /&gt;
===ORA-01555: snapshot too old: rollback segment number nn with name &amp;quot;xxx&amp;quot; too small===&lt;br /&gt;
* [http://dfitzjarrell.wordpress.com/2008/02/22/the-dreaded-ora-01555/ Good explanation of why it happens]&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
====Problem====&lt;br /&gt;
A long running transaction has run out of space to store its read-consistent image&lt;br /&gt;
&lt;br /&gt;
====Solution 1====&lt;br /&gt;
If it&amp;#039;s a one-off, maybe leave it alone. It may have been a user leaving a session open overnight without committing or rolling back.&lt;br /&gt;
&lt;br /&gt;
====Solution 2====&lt;br /&gt;
Make sure there&amp;#039;s enough space to allow the transaction to finish.&lt;br /&gt;
&lt;br /&gt;
====Things to check====&lt;br /&gt;
How much undo did the biggest transaction take?&lt;br /&gt;
What is the undo retention parameter set to?&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 200&lt;br /&gt;
col name        for a30&lt;br /&gt;
col description for a50&lt;br /&gt;
col value       for a20&lt;br /&gt;
col maxquerylen for 999999&lt;br /&gt;
select p.name&lt;br /&gt;
,      p.description&lt;br /&gt;
,      p.value&lt;br /&gt;
,      max(u.maxquerylen) maxquerylen&lt;br /&gt;
from   v$parameter p&lt;br /&gt;
,      v$undostat  u&lt;br /&gt;
where  1=1&lt;br /&gt;
and    p.name = &amp;#039;undo_retention&amp;#039;&lt;br /&gt;
group  by p.name&lt;br /&gt;
,      p.description&lt;br /&gt;
,      p.value;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Set the retention to about 20% bigger than the maxquerylen.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select &amp;#039;alter system set undo_retention=&amp;#039;||round(1.2*max(maxquerylen))||&amp;#039; scope=both;&amp;#039; &amp;quot;Run this&amp;quot; from v$undostat;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
and set the undo retention guarantee (being aware of the consequences)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select tablespace_name&lt;br /&gt;
,      retention&lt;br /&gt;
from   dba_tablespaces;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter tablespace &amp;amp;undo_ts_name retention guarantee;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Optimise Oracle UNDO Parameters===&lt;br /&gt;
&lt;br /&gt;
The ideal undo_retention would be enough to hold rollback for the longest transaction that happened so far (can&amp;#039;t see into the future)&amp;lt;br /&amp;gt;&lt;br /&gt;
So current undo_retention = current value of undo / (db_block_size * undo blocks per sec)&amp;lt;br /&amp;gt;&lt;br /&gt;
* Undo Blocks per Second&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SELECT MAX(undoblks/((end_time-begin_time)*3600*24)) &amp;quot;UNDO_BLOCKS_PER_SEC&amp;quot;&lt;br /&gt;
FROM   v$undostat;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Optimal Undo Retention&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
col actual for 9999999999.99 heading &amp;quot;ACTUAL UNDO SIZE [MByte]&amp;quot;&lt;br /&gt;
col retent for 9999999999    heading &amp;quot;UNDO RETENTION [Sec]&amp;quot;&lt;br /&gt;
col needed for 9999999999.99 heading &amp;quot;NEEDED UNDO SIZE [Secs]&amp;quot;&lt;br /&gt;
&lt;br /&gt;
SELECT d.undo_size/(1024*1024) actual,&lt;br /&gt;
       to_number(SUBSTR(e.value,1,25)) retent,&lt;br /&gt;
       ROUND((d.undo_size / (to_number(f.value) *&lt;br /&gt;
       g.undo_block_per_sec))) needed&lt;br /&gt;
  FROM (&lt;br /&gt;
       SELECT SUM(a.bytes) undo_size&lt;br /&gt;
          FROM v$datafile a,&lt;br /&gt;
               v$tablespace b,&lt;br /&gt;
               dba_tablespaces c&lt;br /&gt;
         WHERE c.contents = &amp;#039;UNDO&amp;#039;&lt;br /&gt;
           AND c.status = &amp;#039;ONLINE&amp;#039;&lt;br /&gt;
           AND b.name = c.tablespace_name&lt;br /&gt;
           AND a.ts# = b.ts#&lt;br /&gt;
       ) d,&lt;br /&gt;
       v$parameter e,&lt;br /&gt;
       v$parameter f,&lt;br /&gt;
       (&lt;br /&gt;
       SELECT MAX(undoblks/((end_time-begin_time)*3600*24))&lt;br /&gt;
              undo_block_per_sec&lt;br /&gt;
         FROM v$undostat&lt;br /&gt;
       ) g&lt;br /&gt;
WHERE e.name = &amp;#039;undo_retention&amp;#039;&lt;br /&gt;
  AND f.name = &amp;#039;db_block_size&amp;#039;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Calculate Needed UNDO Size for given Database Activity&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
col actual for 9999999999.99 heading &amp;quot;ACTUAL UNDO SIZE [MByte]&amp;quot;&lt;br /&gt;
col retent for 9999999999    heading &amp;quot;UNDO RETENTION [Sec]&amp;quot;&lt;br /&gt;
col needed for 9999999999.99 heading &amp;quot;NEEDED UNDO SIZE [MByte]&amp;quot;&lt;br /&gt;
&lt;br /&gt;
SELECT d.undo_size/(1024*1024) actual&lt;br /&gt;
,      to_number(SUBSTR(e.value,1,25)) retent&lt;br /&gt;
,      (TO_NUMBER(e.value) * TO_NUMBER(f.value) *&lt;br /&gt;
       g.undo_block_per_sec) / (1024*1024)  needed&lt;br /&gt;
  FROM (&lt;br /&gt;
       SELECT SUM(a.bytes) undo_size&lt;br /&gt;
         FROM v$datafile a,&lt;br /&gt;
              v$tablespace b,&lt;br /&gt;
              dba_tablespaces c&lt;br /&gt;
        WHERE c.contents = &amp;#039;UNDO&amp;#039;&lt;br /&gt;
          AND c.status = &amp;#039;ONLINE&amp;#039;&lt;br /&gt;
          AND b.name = c.tablespace_name&lt;br /&gt;
          AND a.ts# = b.ts#&lt;br /&gt;
       ) d,&lt;br /&gt;
      v$parameter e,&lt;br /&gt;
       v$parameter f,&lt;br /&gt;
       (&lt;br /&gt;
       SELECT MAX(undoblks/((end_time-begin_time)*3600*24))&lt;br /&gt;
         undo_block_per_sec&lt;br /&gt;
         FROM v$undostat&lt;br /&gt;
       ) g&lt;br /&gt;
 WHERE e.name = &amp;#039;undo_retention&amp;#039;&lt;br /&gt;
  AND f.name = &amp;#039;db_block_size&amp;#039;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
It might be that the Export still fails with ORA-01555 even though retention seems long enough.&amp;lt;br /&amp;gt;&lt;br /&gt;
Are you running an export with the flashback_time parameter? If so, the undo_retention should be longer than the total export running time!&amp;lt;br /&amp;gt;&lt;br /&gt;
===Check LOB undo retention===&lt;br /&gt;
The retention settings for LOBS is different for the rest of the database.&amp;lt;br /&amp;gt;&lt;br /&gt;
When you change the UNDO_RETENTION parameter, the LOB segment’s retention value is NOT modified.&amp;lt;br /&amp;gt;&lt;br /&gt;
If you query the RETENTION column of the DBA_LOBS view, you will notice the old UNDO_RETENTION value still remains after you have modified the UNDO_RETENTION parameter.&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SQL&amp;gt; show parameter undo_&lt;br /&gt;
&lt;br /&gt;
NAME                                 TYPE        VALUE&lt;br /&gt;
------------------------------------ ----------- ------------------------------&lt;br /&gt;
undo_management                      string      AUTO&lt;br /&gt;
undo_retention                       integer     36000&lt;br /&gt;
undo_tablespace                      string      UNDOTBS1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SQL&amp;gt; desc SITEADMIN.AUDIT_LOG_MESSAGE&lt;br /&gt;
 Name                                      Null?    Type&lt;br /&gt;
 ----------------------------------------- -------- ----------------------------&lt;br /&gt;
 AUDIT_LOG_MESSAGE_ID                      NOT NULL NUMBER&lt;br /&gt;
 AUDIT_LOG_ID                              NOT NULL NUMBER&lt;br /&gt;
 SEQUENCE                                           NUMBER&lt;br /&gt;
 MESSAGE                                            CLOB&lt;br /&gt;
 CREATE_DATE                                        TIMESTAMP(6)&lt;br /&gt;
 COMPONENT_ID                                       VARCHAR2(50 CHAR)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 300&lt;br /&gt;
col column_name for a32&lt;br /&gt;
select table_name,column_name, pctversion,retention from dba_lobs where owner=&amp;#039;&amp;amp;table_owner&amp;#039;;&lt;br /&gt;
&lt;br /&gt;
TABLE_NAME                COLUMN_NAME                    PCTVERSION  RETENTION&lt;br /&gt;
------------------------- ------------------------------ ---------- ----------&lt;br /&gt;
EMAIL_STORE               CONTENT                                 0&lt;br /&gt;
EMAIL_STORE_ATTACHEMENT   ATTACHEMENT                             0&lt;br /&gt;
TRACKING                  ORIGINAL_MESSAGE                                 900&lt;br /&gt;
TRACKING                  MESSAGE                                          900&lt;br /&gt;
TRACKING                  SIEBEL_MESSAGE                                   900&lt;br /&gt;
WISE_WMS_LOG              WISE_WMS_XML                                     900&lt;br /&gt;
ATTACHMENT                ORIGINAL_MESSAGE                                 900&lt;br /&gt;
PLAN_TABLE                OTHER_XML                                        900&lt;br /&gt;
AUDIT_LOG_MESSAGE         MESSAGE                                          900&lt;br /&gt;
EXCEPTIONS                STACK_TRACE                                      900&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
To change the LOB segment’s RETENTION value to match the new UNDO_RETENTION value, do the following:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ALTER TABLE my_table MODIFY LOB (lob_column) (PCTVERSION 20);&lt;br /&gt;
ALTER TABLE my_table MODIFY LOB (lob_column) (RETENTION);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
By momentarily changing the LOB to use PCTVERSION and then back to RETENTION, the new value of UNDO_RETENTION will be used.&amp;lt;br /&amp;gt;&lt;br /&gt;
You need to do this for all LOB segments that you intend to modify.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select &amp;#039;ALTER TABLE &amp;#039;||owner||&amp;#039;.&amp;#039;||table_name||&amp;#039; MODIFY LOB (&amp;#039;||column_name||&amp;#039;) (PCTVERSION 20);&amp;#039; from dba_lobs where owner=&amp;#039;TIBCO&amp;#039;&lt;br /&gt;
&lt;br /&gt;
select &amp;#039;ALTER TABLE &amp;#039;||owner||&amp;#039;.&amp;#039;||table_name||&amp;#039; MODIFY LOB (&amp;#039;||column_name||&amp;#039;) (RETENTION);&amp;#039;     from dba_lobs where owner=&amp;#039;TIBCO&amp;#039;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
There is a table DBA_LOBS that displays information about all the LOB columns in the database, but it doesn&amp;#039;t actually store any LOB data, just metadata. The actual LOB segments in the database have system-generated names that take the form SYS_LOB*identifier*$$.&lt;br /&gt;
For example if you identify a segment named SYS_LOBidentifier$$ that is consuming space, you can find out what column of what table that LOB column maps to using the DBA_LOBS table:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 1000&lt;br /&gt;
col owner       for a20&lt;br /&gt;
col table_name  for a32&lt;br /&gt;
col column_name for a32&lt;br /&gt;
select owner&lt;br /&gt;
,      table_name&lt;br /&gt;
,      column_name&lt;br /&gt;
from   dba_lobs&lt;br /&gt;
where  1=1&lt;br /&gt;
and    segment_name = &amp;#039;SYS_LOB&amp;lt;&amp;lt;identifier&amp;gt;&amp;gt;$$&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====The Undo Advisor PL/SQL Interface====&lt;br /&gt;
You can activate the Undo Advisor by creating an undo advisor task through the advisor framework.&amp;lt;br /&amp;gt;&lt;br /&gt;
The following example creates an undo advisor task to evaluate the undo tablespace. The name of the advisor is &amp;#039;Undo Advisor&amp;#039;.&amp;lt;br /&amp;gt;&lt;br /&gt;
The analysis is based on Automatic Workload Repository snapshots, which you must specify by setting parameters START_SNAPSHOT and END_SNAPSHOT.&amp;lt;br /&amp;gt;&lt;br /&gt;
In the following example, the START_SNAPSHOT is &amp;quot;1&amp;quot; and END_SNAPSHOT is &amp;quot;2&amp;quot;.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
DECLARE&lt;br /&gt;
   tid    NUMBER;&lt;br /&gt;
   tname  VARCHAR2(30);&lt;br /&gt;
   oid    NUMBER;&lt;br /&gt;
BEGIN&lt;br /&gt;
   DBMS_ADVISOR.CREATE_TASK(&amp;#039;Undo Advisor&amp;#039;, tid, tname, &amp;#039;Undo Advisor Task&amp;#039;);&lt;br /&gt;
   DBMS_ADVISOR.CREATE_OBJECT(tname, &amp;#039;UNDO_TBS&amp;#039;, null, null, null, &amp;#039;null&amp;#039;, oid);&lt;br /&gt;
   DBMS_ADVISOR.SET_TASK_PARAMETER(tname, &amp;#039;TARGET_OBJECTS&amp;#039;, oid);&lt;br /&gt;
   DBMS_ADVISOR.SET_TASK_PARAMETER(tname, &amp;#039;START_SNAPSHOT&amp;#039;, 1);&lt;br /&gt;
   DBMS_ADVISOR.SET_TASK_PARAMETER(tname, &amp;#039;END_SNAPSHOT&amp;#039;, 2);&lt;br /&gt;
   DBMS_ADVISOR.SET_TASK_PARAMETER(tname, &amp;#039;INSTANCE&amp;#039;, 1);&lt;br /&gt;
   DBMS_ADVISOR.execute_task(tname);&lt;br /&gt;
        END;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
After you have created the advisor task, you can view the output and recommendations in the Automatic Database Diagnostic Monitor in Enterprise Manager.&amp;lt;br /&amp;gt;&lt;br /&gt;
This information is also available in the DBA_ADVISOR_* data dictionary views (DBA_ADVISOR_TASKS, DBA_ADVISOR_OBJECTS, DBA_ADVISOR_FINDINGS, DBA_ADVISOR_RECOMMENDATIONS, and so on).&lt;br /&gt;
====References====&lt;br /&gt;
* [http://www.akadia.com/services/ora_optimize_undo.html akadia.com]&lt;br /&gt;
* [http://dfitzjarrell.wordpress.com/2008/02/22/the-dreaded-ora-01555/ the dreaded ora-01555]&lt;br /&gt;
* [http://docs.oracle.com/cd/B28359_01/server.111/b28310/undo004.htm#ADMIN11469 docs.oracle.com]&lt;br /&gt;
&lt;br /&gt;
===Error 6 initializing SQL*Plus===&lt;br /&gt;
Using sqlplus or rman under Cygwin, ORACLE_HOME still needs to be windows format!&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Message file sp1&amp;lt;lang&amp;gt;.msb not found&lt;br /&gt;
SP2-0750 :You may need to set ORACLE_HOME to your Oracle software directory&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
so...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
export ORACLE_SID=KITRYD&lt;br /&gt;
ORAENV_ASK=NO&lt;br /&gt;
. oraenv&lt;br /&gt;
[[ &amp;quot;`uname`&amp;quot; == CYGWIN* ]] &amp;amp;&amp;amp; ORACLE_HOME=`cygpath -w ${ORACLE_HOME}`&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===ORA-2002: error while writing to audit trail===&lt;br /&gt;
Check the space left in the audit tablespace with:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select sum(bytes)/1024/1024 mb from dba_free_space where tablespace_name =&amp;#039;AUDIT_DT&amp;#039;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
If plenty of space, it can be due to Oracle clearing out the recyclebin at the same time.&amp;lt;br /&amp;gt;&lt;br /&gt;
If not, extend the datafile...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select * from dba_data_files where tablespace_name =&amp;#039;AUDIT_DT&amp;#039;;&lt;br /&gt;
alter database datafile 6 resize 30G;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
If that is not possible, clean out some audit data or add a datafile.&lt;br /&gt;
&lt;br /&gt;
===ORA-00449: background process &amp;#039;CKPT&amp;#039; unexpectedly terminated with error 7446===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SQL&amp;gt; startup nomount pfile=&amp;quot;/oracle/TRSCRP1/admin/initTRSCRP1.ora&amp;quot;&lt;br /&gt;
ORA-00449: background process &amp;#039;CKPT&amp;#039; unexpectedly terminated with error 7446&lt;br /&gt;
ORA-07446: sdnfy: bad value &amp;#039;&amp;#039; for parameter .&lt;br /&gt;
SQL&amp;gt; exit&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Solution&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SQL&amp;gt; mkdir /oracle/TRSCRP1/admin/bdump /oracle/TRSCRP1/admin/cdump&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORA-00845: MEMORY_TARGET not supported on this system===&lt;br /&gt;
* Reference: [http://arjudba.blogspot.be/2009/01/ora-00845-memorytarget-not-supported-on.html arjudba.blogspot.be]&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Problem Description&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SQL&amp;gt; STARTUP&lt;br /&gt;
ORA-00845: MEMORY_TARGET not supported on this system&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Cause&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
* Starting from Oracle 11g the automatic memory management feature is now defined with parameter MEMORY_TARGET and MEMMORY_MAX_TARGET.&lt;br /&gt;
* On linux file system the shared memory need to be mounted on /dev/shm directory on the operating system.&lt;br /&gt;
* And the size of /dev/shm needs to be greater than MEMORY_TARGET or MEMMORY_MAX_TARGET.&lt;br /&gt;
* The AMM (Automatic Memory Management) now in 11g manages both SGA and PGA together by MMAN process.&lt;br /&gt;
* The MEMORY_TARGET parameter in 11g comes for (SGA_TARGET+PGA_AGGREGATE_TARGET) which was in 10g.&lt;br /&gt;
* And MEMORY_MAX_TARGET parameter in 11g comes instead of SGA_MAX_TARGET parameter which was in 10g.&lt;br /&gt;
* The ORA-00845:can arises for the following two reasons on linux system.&lt;br /&gt;
1)If the shared memory which is mapped to /dev/shm directory is less than the size of MEMORY_TARGET or MEMORY_MAX_TARGET or&lt;br /&gt;
2)If the shared memory is not mapped to /dev/shm directory.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Solution&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Make sure /dev/shm is properly mounted. You can see it by,&lt;br /&gt;
#df -h or #df -k command.&lt;br /&gt;
The output should be similar to:&lt;br /&gt;
&lt;br /&gt;
$ df -k&lt;br /&gt;
Filesystem            Size  Used Avail Use% Mounted on&lt;br /&gt;
...&lt;br /&gt;
shmfs                 1G    512M 512M  50% /dev/shm&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
We see here for /dev/shm we have assigned 1G memory. Now if you set MEMORY_TARGET more than 1G then above ORA-845 will arise. For example if you have MEMORY_TARGET or MEMORY_MAX_TARGET set to 12G then you can mount shared memory to 13g like below.&lt;br /&gt;
As a root user,&lt;br /&gt;
# mount -t tmpfs shmfs -o size=13g /dev/shm&lt;br /&gt;
In order to make the settings persistence so that it will affect after restarting machine add an entry in /etc/fstab similar to the following:&lt;br /&gt;
&lt;br /&gt;
shmfs /dev/shm tmpfs size=13g 0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORA-24247: network access denied by access control list (ACL)===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Cause: No access control list (ACL) has been assigned to the target host or the privilege necessary to access the target host has not been granted to the user in the access control list.&lt;br /&gt;
&lt;br /&gt;
Action: Ensure that an access control list (ACL) has been assigned to the target host and the privilege necessary to access the target host has been granted to the user.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Your application will encounter an ORA-24247 error if it relies on one of the network packages and no proper ACL has been created. For the use of the following packages it is mandatory to have an ACL for the application user in place in 11g:&lt;br /&gt;
*UTL_TCP&lt;br /&gt;
*UTL_SMTP&lt;br /&gt;
*UTL_MAIL&lt;br /&gt;
*UTL_HTTP&lt;br /&gt;
*UTL_INADDR&lt;br /&gt;
Here is a very good explanation of how to setup the necessary ACLs: [[http://blog.whitehorses.nl/2010/03/17/oracle-11g-access-control-list-and-ora-24247/ whitehorses.nl]]&lt;br /&gt;
&lt;br /&gt;
===ORA-00600: internal error code, arguments: [qmx: no ref]===&lt;br /&gt;
Search &amp;quot;Master Note for Oracle XML Database (XDB) Install / Deinstall (Doc ID 1292089.1)&amp;quot; for more info.&lt;br /&gt;
====Problem:====&lt;br /&gt;
Sometimes one or more of the following errors can be encountered when installing or upgrading XDB, configuring APEX, running an Export, or selecting from xdb.xdb$resource or sys.dba_network_acls:&amp;lt;br /&amp;gt;&lt;br /&gt;
* ORA-31159: XML DB is in an invalid state&lt;br /&gt;
* ORA-00600: internal error code, arguments: [unable to load XDB library]&lt;br /&gt;
* ORA-00600: internal error code, arguments: [qmx: no ref]&lt;br /&gt;
* ORA-00600: internal error code, arguments: [qmtGetColumnInfo1]&lt;br /&gt;
* ORA-00600: internal error code, arguments: [qmtb_init_len]&lt;br /&gt;
* ORA-00600: internal error code, arguments: [qmtGetBaseType]&lt;br /&gt;
* ORA-00600: internal error code, arguments: [psdnop-1], [600]&lt;br /&gt;
* ORA-00600: internal error code, arguments: [qmtInit1]&lt;br /&gt;
* ORA-07445: exception encountered: core dump [_memcpy()+224] [SIGSEGV] [Address not mapped to object]&lt;br /&gt;
* ORA-19051 Cannot Use Fast Path Insert For This XMLType Table&lt;br /&gt;
* ORA-31011: XML parsing failed&lt;br /&gt;
Errors of this sort generally occur when the init routines for the internal XDB functions are run in an invalid environment causing memory corruption.&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
This can happen if the database was ever started with the LD_LIBRARY_PATH (LIBPATH for AIX or SHLIB_PATH for HP) pointing to the wrong $ORACLE_HOME/lib directory rather than to the correct location for the instance.&amp;lt;br /&amp;gt;&lt;br /&gt;
The LD_LIBRARY_PATH/LIBPATH/SHLIB_PATH environment variable is used to resolve the location of the shared library &amp;quot;libxdb.so (libxdb.sl on HP)&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
====Solution:====&lt;br /&gt;
* Stop Listener&lt;br /&gt;
* Stop database&lt;br /&gt;
* Ensure $ORACLE_HOME/lib is at the start of LD_LIBRARY_PATH / LIBPATH / SHLIB_PATH&lt;br /&gt;
* If AIX, run /usr/sbin/slibclean as root&lt;br /&gt;
* Start database&lt;br /&gt;
* Start listener&lt;br /&gt;
&lt;br /&gt;
===ORA-00201: control file version nn.nn.nn.nn incompatible with ORACLE version===&lt;br /&gt;
Trying to restore a database after complete failure&amp;lt;br /&amp;gt;&lt;br /&gt;
first step is to startup the database in nomount mode and restore the controlfile - succeeded.&amp;lt;br /&amp;gt;&lt;br /&gt;
second step, startup the database in mount mode ready for database restore...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SQL*Plus: Release 10.2.0.3.0 - Production on Wed Aug 19 18:16:47 2015&lt;br /&gt;
&lt;br /&gt;
Copyright (c) 1982, 2006, Oracle.  All Rights Reserved.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Connected to:&lt;br /&gt;
Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - 64bit Production&lt;br /&gt;
With the Partitioning, OLAP and Data Mining options&lt;br /&gt;
&lt;br /&gt;
SYS@CODWHP1&amp;gt; startup mount&lt;br /&gt;
ORACLE instance started.&lt;br /&gt;
&lt;br /&gt;
Total System Global Area  260046848 bytes&lt;br /&gt;
Fixed Size                  2029296 bytes&lt;br /&gt;
Variable Size             113248528 bytes&lt;br /&gt;
Database Buffers          134217728 bytes&lt;br /&gt;
Redo Buffers               10551296 bytes&lt;br /&gt;
ORA-00201: control file version 10.2.0.0.0 incompatible with ORACLE version 10.2.0.3.0&lt;br /&gt;
ORA-00202: control file: &amp;#039;/oracle/CODWHP1/product/10203/dbs/cntrlCODWHP1.dbf&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The problem was there was no compatible parameter in the simple init file I used to start up the instance.&amp;lt;br /&amp;gt;&lt;br /&gt;
Adding compatible parameter to init file to be same version (10.2.0.3) allowed the db to mount.&lt;br /&gt;
&lt;br /&gt;
===TNS-00525: Insufficient privilege for operation===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
lsnrctl start LISTENER_UCLID55V&lt;br /&gt;
&lt;br /&gt;
LSNRCTL for IBM/AIX RISC System/6000: Version 11.2.0.3.0 - Production on 26-MAR-2015 13:36:14&lt;br /&gt;
&lt;br /&gt;
Copyright (c) 1991, 2011, Oracle.  All rights reserved.&lt;br /&gt;
&lt;br /&gt;
Starting /oracle/product/11.2.0.3/bin/tnslsnr: please wait...&lt;br /&gt;
&lt;br /&gt;
TNSLSNR for IBM/AIX RISC System/6000: Version 11.2.0.3.0 - Production&lt;br /&gt;
System parameter file is /oracle/product/11.2.0.3/network/admin/listener.ora&lt;br /&gt;
Log messages written to /oracle/product/diag/tnslsnr/solax082/listener_uclid55v/alert/log.xml&lt;br /&gt;
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=150.251.114.238)(PORT=1525)))&lt;br /&gt;
Error listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC1525)))&lt;br /&gt;
TNS-12555: TNS:permission denied&lt;br /&gt;
 TNS-12560: TNS:protocol adapter error&lt;br /&gt;
  TNS-00525: Insufficient privilege for operation&lt;br /&gt;
   IBM/AIX RISC System/6000 Error: 1: Not owner&lt;br /&gt;
&lt;br /&gt;
Listener failed to start. See the error message(s) above...&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This would suggest the user attempting to start the listener has no access to either the Oracle binaries or the TNS listener/tnsnames files.&amp;lt;br /&amp;gt;&lt;br /&gt;
But... checkout the /tmp/.oracle directory :-)&amp;lt;br /&amp;gt;&lt;br /&gt;
That hidden gem shows who started the listener last time. Delete the relevant entry and try again!&amp;lt;br /&amp;gt;&lt;br /&gt;
To start from a clean sheet, stop all listeners, delete this directory and restart the listeners.&lt;br /&gt;
&lt;br /&gt;
===ORA-12003: materialized view or zonemap &amp;quot;KPK&amp;quot;.&amp;quot;EVD01_NEW&amp;quot; does not exist===&lt;br /&gt;
Here&amp;#039;s one you shouldn&amp;#039;t see very often.&amp;lt;br /&amp;gt;&lt;br /&gt;
Trying to drop a tablespace but prevented from doing so because a materialized view has referential contraints on a table in this tablespace.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SQL&amp;gt; drop tablespace TS_THALER_PART_OLD including contents and datafiles cascade constraints;&lt;br /&gt;
drop tablespace TS_THALER_PART_OLD including contents and datafiles cascade constraints&lt;br /&gt;
*&lt;br /&gt;
ERROR at line 1:&lt;br /&gt;
ORA-00604: error occurred at recursive SQL level 1&lt;br /&gt;
ORA-12083: must use DROP MATERIALIZED VIEW to drop &amp;quot;KPK&amp;quot;.&amp;quot;EVD01_NEW&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Ok, nice of Oracle to tell us what we have to do. Simple enough. Let&amp;#039;s drop the materialized view.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SQL&amp;gt; DROP MATERIALIZED VIEW &amp;quot;KPK&amp;quot;.&amp;quot;EVD01_NEW&amp;quot;;&lt;br /&gt;
DROP MATERIALIZED VIEW &amp;quot;KPK&amp;quot;.&amp;quot;EVD01_NEW&amp;quot;&lt;br /&gt;
*&lt;br /&gt;
ERROR at line 1:&lt;br /&gt;
ORA-12003: materialized view or zonemap &amp;quot;KPK&amp;quot;.&amp;quot;EVD01_NEW&amp;quot; does not exist&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Aah. Not so obvious then.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
desc &amp;quot;KPK&amp;quot;.&amp;quot;EVD01_NEW&amp;quot;&lt;br /&gt;
 Name                                      Null?    Type&lt;br /&gt;
 ----------------------------------------- -------- ----------------------------&lt;br /&gt;
 DATMAJ                                             VARCHAR2(8 CHAR)&lt;br /&gt;
 HEUMAJ                                             VARCHAR2(8 CHAR)&lt;br /&gt;
 PGMMAJ                                             VARCHAR2(6 CHAR)&lt;br /&gt;
 NATOPN                                             VARCHAR2(6 CHAR)&lt;br /&gt;
 REFEXN                                             VARCHAR2(50 CHAR)&lt;br /&gt;
 SWIOLN                                             VARCHAR2(1 CHAR)&lt;br /&gt;
 STAEVT                                             VARCHAR2(4 CHAR)&lt;br /&gt;
 REFEVT                                             VARCHAR2(16 CHAR)&lt;br /&gt;
 NUMIDT                                             VARCHAR2(30 CHAR)&lt;br /&gt;
 ORIEVT                                             VARCHAR2(10 CHAR)&lt;br /&gt;
 REFLOG                                             VARCHAR2(16 CHAR)&lt;br /&gt;
 MSGEVT_CPL                                         VARCHAR2(1500 CHAR)&lt;br /&gt;
 REFOPN                                             VARCHAR2(16 CHAR)&lt;br /&gt;
 DATEVT                                             VARCHAR2(8 CHAR)&lt;br /&gt;
 MSGEVT_FIL_1                                       VARCHAR2(2000 CHAR)&lt;br /&gt;
 MSGEVT_FIL_2                                       VARCHAR2(2000 CHAR)&lt;br /&gt;
 MSGEVT_SPE                                         VARCHAR2(200 CHAR)&lt;br /&gt;
 DATEFF                                             VARCHAR2(8 CHAR)&lt;br /&gt;
 TMSTMP                                             VARCHAR2(15 CHAR)&lt;br /&gt;
 VEREVT                                             VARCHAR2(3 CHAR)&lt;br /&gt;
 MSGEVT_FIL_3                                       VARCHAR2(2000 CHAR)&lt;br /&gt;
 MSGEVT_FIL_4                                       VARCHAR2(2000 CHAR)&lt;br /&gt;
 TYPEVT                                             VARCHAR2(5 CHAR)&lt;br /&gt;
 SBP_CODAPP                                         VARCHAR2(10 CHAR)&lt;br /&gt;
 SBP_REFINT                                         VARCHAR2(36 CHAR)&lt;br /&gt;
 SBP_TYPACT                                         VARCHAR2(2 CHAR)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
It exists... but as a table.&amp;lt;br /&amp;gt;&lt;br /&gt;
Something has gone wrong in the database somewhere. As it turns out after some deeper investigation, this database is a copy of production but &amp;quot;with modifications&amp;quot;.&amp;lt;br /&amp;gt;&lt;br /&gt;
After the cloning process, a schema needed renaming. Oracle have a procedure for this but it is very long-winded and time-consuming. It uses export and import with transportable tablespaces to do the remap of the schema.&amp;lt;br /&amp;gt;&lt;br /&gt;
An unsupported workaround to rename schema is to simply update the username in sys.user$ and restart the database.&amp;lt;br /&amp;gt;&lt;br /&gt;
This works for the most part but now we see a consequence of that action.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
col owner      for a30&lt;br /&gt;
col mview_name for a30&lt;br /&gt;
select owner&lt;br /&gt;
,      mview_name&lt;br /&gt;
from   dba_mviews&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
OWNER                          MVIEW_NAME&lt;br /&gt;
------------------------------ ------------------------------&lt;br /&gt;
EPK                            EVD01_NEW&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Ahaa, there&amp;#039;s the materialized view but the owner is different from the one described by the database error message above. This one is the owner as it was on production.&amp;lt;br /&amp;gt;&lt;br /&gt;
This means the owner of materialized views has been denormalised for some reason. Reading the (complex) view text of dba_mviews, we see the owner column is based on sys.snap$.sowner&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
col sowner for a20&lt;br /&gt;
col vname  for a20&lt;br /&gt;
col tname  for a20&lt;br /&gt;
select sowner&lt;br /&gt;
,      vname&lt;br /&gt;
,      tname&lt;br /&gt;
from   sys.snap$&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
SOWNER               VNAME                TNAME&lt;br /&gt;
-------------------- -------------------- --------------------&lt;br /&gt;
EPK                  EVD01_NEW            EVD01_NEW&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
For future reference when updating the username in sys.user$, update the snapshot owner in this table as well!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
update sys.snap$&lt;br /&gt;
set    sowner = &amp;#039;KPK&amp;#039;&lt;br /&gt;
where  sowner = &amp;#039;EPK&amp;#039;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Try again&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
DROP MATERIALIZED VIEW &amp;quot;KPK&amp;quot;.&amp;quot;EVD01_NEW&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
Materialized view dropped.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
yep, and the tablespace?&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
drop tablespace TS_THALER_PART_OLD including contents and datafiles cascade constraints;&lt;br /&gt;
&lt;br /&gt;
Tablespace dropped.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORA-12162: TNS:net service name is incorrectly specified===&lt;br /&gt;
Probably nothing to do with TNS. Check your ORACLE_SID is set correctly!&lt;br /&gt;
&lt;br /&gt;
===ORA-00054: resource busy and acquire with NOWAIT specified===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SELECT O.OBJECT_NAME, S.SID, S.SERIAL#, P.SPID, S.PROGRAM,S.USERNAME,&lt;br /&gt;
S.MACHINE,S.PORT , S.LOGON_TIME,SQ.SQL_FULLTEXT &lt;br /&gt;
FROM V$LOCKED_OBJECT L, DBA_OBJECTS O, V$SESSION S, &lt;br /&gt;
V$PROCESS P, V$SQL SQ &lt;br /&gt;
WHERE L.OBJECT_ID = O.OBJECT_ID &lt;br /&gt;
AND L.SESSION_ID = S.SID AND S.PADDR = P.ADDR &lt;br /&gt;
AND S.SQL_ADDRESS = SQ.ADDRESS;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select object_name, s.sid, s.serial#, p.spid &lt;br /&gt;
from v$locked_object l, dba_objects o, v$session s, v$process p&lt;br /&gt;
where l.object_id = o.object_id and l.session_id = s.sid and s.paddr = p.addr;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
then&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter system kill session &amp;#039;sid,serial#&amp;#039;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORA-12518: TNS:listener could not hand off client connection===&lt;br /&gt;
The database you are trying to connect to is probably on its knees. Check server memory is not exhausted.&lt;br /&gt;
&lt;br /&gt;
===ORA-12520: TNS:listener could not find available handler for requested type of server===&lt;br /&gt;
Strangely this could be related to number of processes being exhausted.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
show parameter processes&lt;br /&gt;
alter system set processes=350 scope=spfile;&lt;br /&gt;
shutdown immediate&lt;br /&gt;
startup&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORA-12541: TNS: no listener===&lt;br /&gt;
Either very basic - start the listener!&amp;lt;br /&amp;gt;&lt;br /&gt;
or, as in our case - not so obvious.&amp;lt;br /&amp;gt;&lt;br /&gt;
We use virtual IP addresses so that the IP address stays the same after failover to standby.&amp;lt;br /&amp;gt;&lt;br /&gt;
Due to some confused configuration, we got the network adapter on two different servers to have the same IP address.&amp;lt;br /&amp;gt;&lt;br /&gt;
Stop the IP address on the bad server (assign another one) and all is fine again.&lt;br /&gt;
===ORA-12514: TNS:listener does not currently know of service===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
lsnrctl status &amp;lt;listener_name&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Been altering tnsnames.ora or listener.ora?&lt;br /&gt;
* Check the local_listener parameter&lt;br /&gt;
Try resetting it to itself. Strange but if you are not using port 1521, this can work wonders!&amp;lt;br /&amp;gt;&lt;br /&gt;
Assuming listener is called LISTENER_WM9T:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter system set local_listener=LISTENER_WM9T scope=both;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Try and connect with the service name or directly with&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sqlplus &amp;#039;sys/*******&amp;#039;@&amp;lt;host&amp;gt;:&amp;lt;port&amp;gt;/&amp;lt;SID&amp;gt; as sysdba&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Excellent description of how Oracle TNS listeners work and a checklist on how to fix this error&amp;lt;br /&amp;gt;&lt;br /&gt;
* [[http://edstevensdba.wordpress.com/2011/03/19/ora-12514/ TNS — Ed Stevens]]&lt;br /&gt;
&lt;br /&gt;
===ORA-12547: TNS lost contact===&lt;br /&gt;
&lt;br /&gt;
If&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sqlplus &amp;lt;user&amp;gt;/&amp;lt;pass&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
fails with above error, try&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sqlplus &amp;lt;user&amp;gt;/&amp;lt;pass&amp;gt;@&amp;lt;db connection&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
If this works, it is most probably a permissions error.&amp;lt;br /&amp;gt;&lt;br /&gt;
Re-run the&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ORACLE_HOME/root.sh&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
script that was run as part of the original installation. This will reset the permissions on some important files.&lt;br /&gt;
===ORA-02374: conversion error loading table &amp;quot;BLENGADM&amp;quot;.&amp;quot;ZZ_EVTCTA&amp;quot;===&lt;br /&gt;
This is typical of importing data with Datapump when the tables in the source database were created with &amp;quot;byte&amp;quot; semantics and the destination is &amp;quot;char&amp;quot; semantics.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ORA-02374: conversion error loading table &amp;quot;BLENGADM&amp;quot;.&amp;quot;ZZ_EVTCTA&amp;quot;&lt;br /&gt;
ORA-12899: value too large for column NOMCTA (actual: 257, maximum: 256)&lt;br /&gt;
&lt;br /&gt;
ORA-02372: data for row: NOMCTA : 0X&amp;#039;4C6976726574206427E9706172676E65202020202020202020&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Problem====&lt;br /&gt;
The root cause is the nls_length_semantics of the table columns being BYTE where one character is assigned one byte. But after conversion in a multi-byte database, one character is larger than one byte (could be 2, 3 or 4) and no longer fits.&lt;br /&gt;
====Solution====&lt;br /&gt;
* import the metadata&lt;br /&gt;
Run the impdp command with content=metadata_only. This will create all the tables (still in their original form) but not the data.&lt;br /&gt;
* alter the BYTE columns in the affected tables to CHAR semantics&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select column_name&lt;br /&gt;
,      char_used&lt;br /&gt;
,      data_length&lt;br /&gt;
,      data_type &lt;br /&gt;
from   user_tab_columns &lt;br /&gt;
where  table_name = &amp;#039;T&amp;#039;&lt;br /&gt;
and    char_used = &amp;#039;B&amp;#039;;&lt;br /&gt;
COLUMN_NAME  C DATA_LENGTH DATA_TYPE&lt;br /&gt;
------------ - ----------- ---------&lt;br /&gt;
X            B           1 VARCHAR2&lt;br /&gt;
SQL&amp;gt; alter table t modify x varchar2(1 char);&lt;br /&gt;
Table altered.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Import the data&lt;br /&gt;
Rerun the impdp ensuring table_exists_action is not REPLACE (use truncate or append). This now imports the data into the modified tables.&lt;br /&gt;
====This script does the donkey work of altering table column semantics from byte to char====&lt;br /&gt;
The author of this script is unknown but he/she deserves a medal. It saves countless hours of work and is so well written.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/*&lt;br /&gt;
  The script converts all the VARCHAR2 columns in the user&amp;#039;s schema&lt;br /&gt;
  to CHAR length semantics. Known to work on 10.2.0.4 and later.&lt;br /&gt;
  &lt;br /&gt;
  Script must be executed against the database without any other client&lt;br /&gt;
  and/or application connections to the affected schema.&lt;br /&gt;
  &lt;br /&gt;
  Oracle does not support CHAR semantics for the built-in schemas,&lt;br /&gt;
  like SYS, SYSTEM or SYSMAN, so the script will throw an error,&lt;br /&gt;
  if attempt to run it against any one of them.&lt;br /&gt;
  &lt;br /&gt;
  Upon completion database objects that have dependencies on tables&lt;br /&gt;
  being modified will be invalidated. Oracle usually re-compiles invalidated&lt;br /&gt;
  objects on the first access. Alternatively, a DBA can execute UTLPRP script&lt;br /&gt;
  to recompile all invalid objects in the entire database.&lt;br /&gt;
  &lt;br /&gt;
  Upon completion, please make sure that NLS_LENGTH_SEMANTICS instance parameter&lt;br /&gt;
  is set to CHAR to ensure further upgradability of the schema.&lt;br /&gt;
*/&lt;br /&gt;
set serveroutput on size unlimited format wrap&lt;br /&gt;
declare&lt;br /&gt;
  type sql_list_t is table of varchar2(32767) index by pls_integer;&lt;br /&gt;
  type idx_list_t is table of user_indexes.index_name%type index by pls_integer;&lt;br /&gt;
  type col_list_t is table of user_tab_columns%rowtype index by pls_integer;&lt;br /&gt;
  --&lt;br /&gt;
  lv_col_cnt   pls_integer := 0;&lt;br /&gt;
  lv_idx_cnt   pls_integer := 0;&lt;br /&gt;
  lv_char_set  pls_integer := 0; &lt;br /&gt;
  lv_user      user_users.username%type;&lt;br /&gt;
  lv_sql_stmt  varchar2(32767);&lt;br /&gt;
  lv_byte_cols col_list_t;&lt;br /&gt;
  lv_idx_names idx_list_t;&lt;br /&gt;
  lv_idx_ddls  sql_list_t;&lt;br /&gt;
  --&lt;br /&gt;
  procedure run_sql_stmt&lt;br /&gt;
  (&lt;br /&gt;
   p_sql_stmt in varchar2&lt;br /&gt;
  )&lt;br /&gt;
  as&lt;br /&gt;
  begin&lt;br /&gt;
    execute immediate p_sql_stmt;&lt;br /&gt;
  exception&lt;br /&gt;
    when others&lt;br /&gt;
    then&lt;br /&gt;
      raise_application_error(-20202, &amp;#039;Failed statement [&amp;#039; || p_sql_stmt || dbms_utility.format_error_backtrace() || &amp;#039;]&amp;#039;, true);&lt;br /&gt;
  end;&lt;br /&gt;
begin&lt;br /&gt;
  --&lt;br /&gt;
  lv_user := user();&lt;br /&gt;
  if lv_user in (&amp;#039;SYS&amp;#039;, &amp;#039;SYSTEM&amp;#039;, &amp;#039;SYSMAN&amp;#039;)&lt;br /&gt;
  then&lt;br /&gt;
    raise_application_error(-20202, &amp;#039;This script cannot be executed against Oracle built-in schema [&amp;#039; || lv_user || &amp;#039;].&amp;#039;);&lt;br /&gt;
  end if;&lt;br /&gt;
  --&lt;br /&gt;
  select&lt;br /&gt;
         *&lt;br /&gt;
         bulk collect into lv_byte_cols&lt;br /&gt;
  from&lt;br /&gt;
         user_tab_columns uc&lt;br /&gt;
  where&lt;br /&gt;
         uc.char_used = &amp;#039;B&amp;#039;&lt;br /&gt;
         and&lt;br /&gt;
         substr(uc.table_name, 1, 4) != &amp;#039;BIN$&amp;#039;&lt;br /&gt;
         and&lt;br /&gt;
         not exists&lt;br /&gt;
         (&lt;br /&gt;
          select 1&lt;br /&gt;
          from   user_views uv&lt;br /&gt;
          where  uv.view_name = uc.table_name&lt;br /&gt;
         )&lt;br /&gt;
  ;&lt;br /&gt;
  --&lt;br /&gt;
  lv_col_cnt := lv_byte_cols.count();&lt;br /&gt;
  --&lt;br /&gt;
  dbms_output.enable();&lt;br /&gt;
  --&lt;br /&gt;
  if lv_col_cnt &amp;gt; 0&lt;br /&gt;
  then&lt;br /&gt;
    for idx_rw in&lt;br /&gt;
    (&lt;br /&gt;
     select index_name &lt;br /&gt;
     from   user_indexes&lt;br /&gt;
     where  index_type = &amp;#039;FUNCTION-BASED NORMAL&amp;#039;&lt;br /&gt;
    )&lt;br /&gt;
    loop&lt;br /&gt;
      lv_idx_cnt := lv_idx_cnt + 1;&lt;br /&gt;
      lv_idx_names(lv_idx_cnt) := idx_rw.index_name;&lt;br /&gt;
      lv_idx_ddls(lv_idx_cnt) := replace&lt;br /&gt;
                                 (&lt;br /&gt;
                                  dbms_metadata.get_ddl&lt;br /&gt;
                                  (&lt;br /&gt;
                                   object_type =&amp;gt; &amp;#039;INDEX&amp;#039;,&lt;br /&gt;
                                   name        =&amp;gt; idx_rw.index_name&lt;br /&gt;
                                  )&lt;br /&gt;
                                  ,&lt;br /&gt;
                                  &amp;#039;;&amp;#039;&lt;br /&gt;
                                 );&lt;br /&gt;
      lv_sql_stmt := &amp;#039;drop index &amp;#039; || idx_rw.index_name;&lt;br /&gt;
      run_sql_stmt(lv_sql_stmt);&lt;br /&gt;
      dbms_output.put_line(&amp;#039;Dropped function-based index: &amp;#039; || idx_rw.index_name);&lt;br /&gt;
      dbms_output.put_line(&amp;#039;In case of script failure, restore the index by running the DDL statement below:&amp;#039;);&lt;br /&gt;
      dbms_output.put_line(lv_idx_ddls(lv_idx_cnt) || &amp;#039;;&amp;#039;);&lt;br /&gt;
    end loop;&lt;br /&gt;
    --&lt;br /&gt;
    for i in 1..lv_col_cnt&lt;br /&gt;
    loop&lt;br /&gt;
      lv_sql_stmt :=  &amp;#039;alter table &amp;#039; || lv_byte_cols(i).table_name || &amp;#039; modify (&amp;#039; ||&lt;br /&gt;
                      lv_byte_cols(i).column_name || &amp;#039; &amp;#039; || lv_byte_cols(i).data_type ||&lt;br /&gt;
                      &amp;#039;(&amp;#039; || lv_byte_cols(i).char_length || &amp;#039; char))&amp;#039;;&lt;br /&gt;
      run_sql_stmt(lv_sql_stmt);&lt;br /&gt;
    end loop;&lt;br /&gt;
    --&lt;br /&gt;
    dbms_output.new_line();&lt;br /&gt;
    for i in 1..lv_idx_cnt&lt;br /&gt;
    loop&lt;br /&gt;
      run_sql_stmt(lv_idx_ddls(i));&lt;br /&gt;
      dbms_output.put_line(&amp;#039;Recreated function-based index: &amp;#039; || lv_idx_names(i));&lt;br /&gt;
    end loop;&lt;br /&gt;
    --&lt;br /&gt;
    dbms_output.new_line();&lt;br /&gt;
    dbms_output.put_line&lt;br /&gt;
    (&lt;br /&gt;
     &amp;#039;Updated length semantics to CHAR for &amp;#039; || lv_col_cnt || &amp;#039; column&amp;#039; ||&lt;br /&gt;
     case when lv_col_cnt &amp;gt; 1&lt;br /&gt;
          then &amp;#039;s&amp;#039;&lt;br /&gt;
     end ||&lt;br /&gt;
     &amp;#039; in the schema [&amp;#039; || lv_user || &amp;#039;].&amp;#039;&lt;br /&gt;
    );&lt;br /&gt;
  else&lt;br /&gt;
    dbms_output.put_line(&amp;#039;No columns with BYTE length semantics were found in the schema [&amp;#039; || lv_user || &amp;#039;].&amp;#039;);&lt;br /&gt;
  end if;&lt;br /&gt;
  --&lt;br /&gt;
  select count(*) into lv_char_set&lt;br /&gt;
  from   nls_session_parameters&lt;br /&gt;
  where  parameter = &amp;#039;NLS_LENGTH_SEMANTICS&amp;#039;&lt;br /&gt;
         and&lt;br /&gt;
         value = &amp;#039;CHAR&amp;#039;&lt;br /&gt;
  ;&lt;br /&gt;
  --&lt;br /&gt;
  if lv_char_set = 0&lt;br /&gt;
  then&lt;br /&gt;
    dbms_output.put_line(&amp;#039;WARNING: Do not forget to change instance parameter NLS_LENGTH_SEMANTICS to CHAR and restart the database.&amp;#039;);&lt;br /&gt;
  end if;&lt;br /&gt;
end;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORA-14097: column type or size mismatch in ALTER TABLE EXCHANGE PARTITION===&lt;br /&gt;
Also can be &amp;lt;tt&amp;gt;ORA-54033: column to be modified is used in a virtual column expression&amp;lt;/tt&amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;
Nothing especially to do with partitions - just any ddl operation that affects the table.&amp;lt;br /&amp;gt;&lt;br /&gt;
Hidden columns do not normally show up in a desc unless colinvisible is on&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set colinvisible on&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
But these sneaky system-generated ones don&amp;#039;t show up even with that setting on!  You need to show them with this:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set pages 50 lines 1000&lt;br /&gt;
col column_name for a40&lt;br /&gt;
col data_default for a40&lt;br /&gt;
select internal_column_id, column_name, data_default, hidden_column, virtual_column from dba_tab_cols where table_name =&amp;#039;XND40&amp;#039;;&lt;br /&gt;
&lt;br /&gt;
INTERNAL_COLUMN_ID COLUMN_NAME                                        DATA_DEFAULT                                       HIDDEN_COLUM VIRTUAL_COLU&lt;br /&gt;
------------------ -------------------------------------------------- -------------------------------------------------- ------------ ------------&lt;br /&gt;
                35 MONLOT_REC_CDR                                     &amp;#039;0&amp;#039;                                                NO           NO&lt;br /&gt;
                34 MONLOT_REC_DBT                                     &amp;#039;0&amp;#039;                                                NO           NO&lt;br /&gt;
                33 MONLOT_CAL_CDR                                     &amp;#039;0&amp;#039;                                                NO           NO&lt;br /&gt;
                32 MONLOT_CAL_DBT                                     &amp;#039;0&amp;#039;                                                NO           NO&lt;br /&gt;
                31 MONMVT_CPT                                         &amp;#039;0&amp;#039;                                                NO           NO&lt;br /&gt;
                30 SENNOT                                             &amp;#039; &amp;#039;                                                NO           NO&lt;br /&gt;
                29 NUMSEQ                                                                                                NO           NO&lt;br /&gt;
                28 NOMFIC                                                                                                NO           NO&lt;br /&gt;
                27 TOTCPT_REC                                                                                            NO           NO&lt;br /&gt;
                26 TOTCPT_CAL                                                                                            NO           NO&lt;br /&gt;
                25 MONLOT_REC                                                                                            NO           NO&lt;br /&gt;
                24 MONLOT_CAL                                                                                            NO           NO&lt;br /&gt;
                23 NBRELE_REC                                                                                            NO           NO&lt;br /&gt;
                22 NBRELE_CAL                                                                                            NO           NO&lt;br /&gt;
                21 NUMCPT_GLO                                                                                            NO           NO&lt;br /&gt;
                20 DEVLOT                                                                                                NO           NO&lt;br /&gt;
                19 CODERR                                                                                                NO           NO&lt;br /&gt;
                18 CANLOT                                                                                                NO           NO&lt;br /&gt;
                17 REFTEX                                                                                                NO           NO&lt;br /&gt;
                16 REFEXN                                                                                                NO           NO&lt;br /&gt;
                15 ETTLOT                                                                                                NO           NO&lt;br /&gt;
                14 TYPLOT                                                                                                NO           NO&lt;br /&gt;
                13 DATEXC                                                                                                NO           NO&lt;br /&gt;
                12 STALOT                                                                                                NO           NO&lt;br /&gt;
                11 REFLOT                                                                                                NO           NO&lt;br /&gt;
                10 USRAUT                                                                                                NO           NO&lt;br /&gt;
                 9 HEUAUT                                                                                                NO           NO&lt;br /&gt;
                 8 DATAUT                                                                                                NO           NO&lt;br /&gt;
                 7 PGMMAJ                                                                                                NO           NO&lt;br /&gt;
                 6 USRMAJ                                                                                                NO           NO&lt;br /&gt;
                 5 HEUMAJ                                                                                                NO           NO&lt;br /&gt;
                 4 DATMAJ                                                                                                NO           NO&lt;br /&gt;
                 3 DATCRT                                                                                                NO           NO&lt;br /&gt;
                 2 REFMAJ                                                                                                NO           NO&lt;br /&gt;
                 1 NUMVER                                                                                                NO           NO&lt;br /&gt;
                36 SYS_STS#KR2WNV5L070XKV1L5H7REH                     SYS_OP_COMBINED_HASH(&amp;quot;NOMFIC&amp;quot;,&amp;quot;NUMSEQ&amp;quot;)            YES          YES&lt;br /&gt;
&lt;br /&gt;
36 rows selected.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
That last row means extended statistics have been generated for 2 columns in this table.&amp;lt;br /&amp;gt;&lt;br /&gt;
You can see this because the name begins with SYS_STS. If it begins with SYS_&amp;lt;something else&amp;gt; then it is not extended statistics.&amp;lt;br /&amp;gt;&lt;br /&gt;
It may be an unused column. Original [https://dba.stackexchange.com/questions/196248/what-is-the-sys-c00054-140314103403-column-in-my-regular-oracle-table here]&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
create table t1 as select * from dba_roles;&lt;br /&gt;
&lt;br /&gt;
Table created.&lt;br /&gt;
&lt;br /&gt;
desc t1&lt;br /&gt;
 Name                                      Null?    Type&lt;br /&gt;
 ----------------------------------------- -------- ----------------------------&lt;br /&gt;
 ROLE                                      NOT NULL VARCHAR2(30)&lt;br /&gt;
 PASSWORD_REQUIRED                                  VARCHAR2(8)&lt;br /&gt;
 AUTHENTICATION_TYPE                                VARCHAR2(11)&lt;br /&gt;
&lt;br /&gt;
alter table t1 set unused (AUTHENTICATION_TYPE);&lt;br /&gt;
&lt;br /&gt;
Table altered.&lt;br /&gt;
&lt;br /&gt;
desc t1&lt;br /&gt;
 Name                                      Null?    Type&lt;br /&gt;
 ----------------------------------------- -------- ----------------------------&lt;br /&gt;
 ROLE                                      NOT NULL VARCHAR2(30)&lt;br /&gt;
 PASSWORD_REQUIRED                                  VARCHAR2(8)&lt;br /&gt;
&lt;br /&gt;
select column_name from dba_tab_cols where owner = &amp;#039;&amp;amp;owner.&amp;#039; and table_name = &amp;#039;&amp;amp;table_name.&amp;#039;;&lt;br /&gt;
&lt;br /&gt;
COLUMN_NAME&lt;br /&gt;
------------------------------&lt;br /&gt;
SYS_C00003_18012517:25:39$&lt;br /&gt;
PASSWORD_REQUIRED&lt;br /&gt;
ROLE&lt;br /&gt;
&lt;br /&gt;
SQL&amp;gt; alter table t1 drop unused columns;&lt;br /&gt;
&lt;br /&gt;
Table altered.&lt;br /&gt;
&lt;br /&gt;
select column_name from dba_tab_cols where owner = &amp;#039;&amp;amp;owner.&amp;#039; and table_name = &amp;#039;&amp;amp;table_name.&amp;#039;;&lt;br /&gt;
&lt;br /&gt;
COLUMN_NAME&lt;br /&gt;
------------------------------&lt;br /&gt;
PASSWORD_REQUIRED&lt;br /&gt;
ROLE&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Solution====&lt;br /&gt;
Drop the extended stats, do what you need to do and recreate the extended stats.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
PROCEDURE DROP_EXTENDED_STATS&lt;br /&gt;
 Argument Name                  Type                    In/Out Default?&lt;br /&gt;
 ------------------------------ ----------------------- ------ --------&lt;br /&gt;
 OWNNAME                        VARCHAR2                IN&lt;br /&gt;
 TABNAME                        VARCHAR2                IN&lt;br /&gt;
 EXTENSION                      VARCHAR2                IN&lt;br /&gt;
&lt;br /&gt;
exec dbms_stats.drop_extended_stats ( &amp;#039;KPK&amp;#039;, &amp;#039;XND40&amp;#039;, &amp;#039;(&amp;quot;NOMFIC&amp;quot;,&amp;quot;NUMSEQ&amp;quot;)&amp;#039; );&lt;br /&gt;
&lt;br /&gt;
create table kpk.xnd40_new as select * from kpk.xnd40 where 1=2;&lt;br /&gt;
&lt;br /&gt;
Table created.&lt;br /&gt;
&lt;br /&gt;
select dbms_stats.create_extended_stats ( &amp;#039;KPK&amp;#039;, &amp;#039;XND40&amp;#039;, &amp;#039;(&amp;quot;NOMFIC&amp;quot;,&amp;quot;NUMSEQ&amp;quot;)&amp;#039; ) from   dual;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The stats columns can also be seen in their own table&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 1000 pages 100&lt;br /&gt;
col owner for a6&lt;br /&gt;
col table_name for a20&lt;br /&gt;
col extension_name  for a40&lt;br /&gt;
col extension  for a50&lt;br /&gt;
select owner, table_name, extension_name, extension, creator, droppable from dba_stat_extensions where owner = upper(&amp;#039;&amp;amp;&amp;amp;owner.&amp;#039;) and table_name = upper(&amp;#039;&amp;amp;&amp;amp;table_name.&amp;#039;) and extension_name LIKE &amp;#039;SYS_STS%&amp;#039;;&lt;br /&gt;
&lt;br /&gt;
OWNER TABLE_NAME           EXTENSION_NAME                           EXTENSION                                          CREATOR                  DROPPABLE&lt;br /&gt;
----- -------------------- ---------------------------------------- -------------------------------------------------- ------------------------ ------------&lt;br /&gt;
KPK   XMD01                SYS_STSOA4UXZDBW7MIV5OOR8VOHHK           (&amp;quot;DATCRT&amp;quot;,&amp;quot;CODJRN&amp;quot;)                                SYSTEM                   YES&lt;br /&gt;
KPK   XDD02                SYS_STSFJCZYRZBCQL820ADIR0Y4RZ           (&amp;quot;REFMSG&amp;quot;,&amp;quot;CPTTIT&amp;quot;,&amp;quot;TYPMSG&amp;quot;)                       SYSTEM                   YES&lt;br /&gt;
KPK   XCD09                SYS_STS2OIO647GN0_UV$XO583KKKJ           (&amp;quot;DATCRT&amp;quot;,&amp;quot;HEUMAJ&amp;quot;,&amp;quot;STAMOD&amp;quot;)                       SYSTEM                   YES&lt;br /&gt;
KPK   XCD09                SYS_STS_BRDODC6DJG_HXK0#O9BOYF           (&amp;quot;STAMOD&amp;quot;,&amp;quot;CODMOD&amp;quot;)                                SYSTEM                   YES&lt;br /&gt;
KPK   XCD09                SYS_STS2#DY5U$WQG6COVHB##H2ESK           (&amp;quot;DATMAJ&amp;quot;,&amp;quot;STAMOD&amp;quot;,&amp;quot;CODMOD&amp;quot;)                       SYSTEM                   YES&lt;br /&gt;
KPK   XCD09                SYS_STSO7#D3DI5R8_VAF$WJ32D8MT           (&amp;quot;STAMOD&amp;quot;,&amp;quot;KEYREF_1&amp;quot;)                              SYSTEM                   YES&lt;br /&gt;
KPK   XCD09                SYS_STS4FRY10M34S2L$0FDM1N4B18           (&amp;quot;STAMOD&amp;quot;,&amp;quot;IDTMOD&amp;quot;)                                SYSTEM                   YES&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORA-14404: partitioned table contains partitions in a different tablespace===&lt;br /&gt;
As part of an RMAN duplicate with a skip tablespace, this error is produced&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Reenabling controlfile options for auxiliary database&lt;br /&gt;
Executing: alter database enable block change tracking using file &amp;#039;/oracle/acc/ora_data3/adsa1/bct_adsp_do_not_delete.f&amp;#039;&lt;br /&gt;
&lt;br /&gt;
contents of Memory Script:&lt;br /&gt;
{&lt;br /&gt;
   Alter clone database open resetlogs;&lt;br /&gt;
}&lt;br /&gt;
executing Memory Script&lt;br /&gt;
&lt;br /&gt;
database opened&lt;br /&gt;
Dropping offline and skipped tablespaces&lt;br /&gt;
Executing: drop tablespace &amp;quot;ADS_ARCHIVE&amp;quot; including contents cascade constraints&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-03002: failure of Duplicate Db command at 10/16/2017 23:46:12&lt;br /&gt;
RMAN-05501: aborting duplication of target database&lt;br /&gt;
RMAN-06136: ORACLE error from auxiliary database: ORA-14404: partitioned table contains partitions in a different tablespace&lt;br /&gt;
&lt;br /&gt;
Recovery Manager complete.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
and when attempting to backup the database, we get errors&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
RMAN-06169: could not read file header for datafile 188 error reason 1&lt;br /&gt;
RMAN-06169: could not read file header for datafile 189 error reason 1&lt;br /&gt;
RMAN-06169: could not read file header for datafile 190 error reason 1&lt;br /&gt;
RMAN-06169: could not read file header for datafile 191 error reason 1&lt;br /&gt;
RMAN-06169: could not read file header for datafile 14 error reason 1&lt;br /&gt;
released channel: t1&lt;br /&gt;
released channel: t2&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-03002: failure of backup plus archivelog command at 10/17/2017 15:08:40&lt;br /&gt;
RMAN-06056: could not access datafile 14&lt;br /&gt;
&lt;br /&gt;
Recovery Manager complete.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Problem====&lt;br /&gt;
Tables in the tablespace have partitions in another tablespace so this one cannot be dropped.&amp;lt;br /&amp;gt;&lt;br /&gt;
Check which table partitions are in which tablespaces&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 200&lt;br /&gt;
set pagesize 200&lt;br /&gt;
col table_name for a14&lt;br /&gt;
col table_owner for a14&lt;br /&gt;
col partition_name for a14&lt;br /&gt;
select table_owner&lt;br /&gt;
,      table_name&lt;br /&gt;
,      partition_name&lt;br /&gt;
,      tablespace_name&lt;br /&gt;
from   dba_tab_partitions&lt;br /&gt;
where  (table_owner, table_name) in&lt;br /&gt;
       (&lt;br /&gt;
       select table_owner&lt;br /&gt;
       ,      table_name&lt;br /&gt;
       from   dba_tab_partitions x&lt;br /&gt;
       where  x.tablespace_name = &amp;#039;&amp;amp;&amp;amp;TABLESPACE_TO_DROP&amp;#039;&lt;br /&gt;
       and    exists ( select *&lt;br /&gt;
                       from   dba_tab_partitions y&lt;br /&gt;
                       where  x.table_owner = y.table_owner&lt;br /&gt;
                       and    x.table_name  = y.table_name&lt;br /&gt;
                       and    y.tablespace_name not in (&amp;#039;&amp;amp;TABLESPACE_TO_DROP&amp;#039;)&lt;br /&gt;
                       group  by table_owner&lt;br /&gt;
                       ,      table_name&lt;br /&gt;
                     )&lt;br /&gt;
        )&lt;br /&gt;
order by 1,2,partition_position&lt;br /&gt;
/&lt;br /&gt;
undef TABLESPACE_TO_DROP&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
TABLE_OWNER    TABLE_NAME     PARTITION_NAME TABLESPACE_NAME&lt;br /&gt;
-------------- -------------- -------------- ------------------------------&lt;br /&gt;
KPK            XND20          P0910          TS_THALER_PART_OLD&lt;br /&gt;
KPK            XND20          P1112          TS_THALER_PART_OLD&lt;br /&gt;
KPK            XND20          P13            TS_THALER_PART_OLD&lt;br /&gt;
KPK            XND20          P14            TS_THALER_PART_OLD&lt;br /&gt;
KPK            XND20          P15            TS_THALER_PART_OLD&lt;br /&gt;
KPK            XND20          P16            TS_THALER_DATA&lt;br /&gt;
KPK            XND20          P17            TS_THALER_DATA&lt;br /&gt;
KPK            XND20          P18            TS_THALER_DATA&lt;br /&gt;
KPK            XND20          PMAX           TS_THALER_DATA&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Solution====&lt;br /&gt;
If the intention is to keep all the tables then run this query to generate statements to move the relevant tables out of this tablespace&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select &amp;#039;alter table &amp;#039;||b.table_owner||&amp;#039;.&amp;#039;||b.table_name||&amp;#039; move partition &amp;#039;||b.partition_name||&amp;#039; tablespace &amp;amp;NEW_TABLESPACE;&amp;#039;&lt;br /&gt;
from   (&lt;br /&gt;
       select distinct table_name&lt;br /&gt;
       ,      partition_name&lt;br /&gt;
       from   dba_tab_partitions&lt;br /&gt;
       where  tablespace_name = &amp;#039;&amp;amp;&amp;amp;TABLESPACE_NAME&amp;#039;&lt;br /&gt;
       )                  a&lt;br /&gt;
,      dba_tab_partitions b&lt;br /&gt;
where  a.table_name       = b.table_name&lt;br /&gt;
and    b.tablespace_name != &amp;#039;&amp;amp;TABLESPACE_NAME&amp;#039;&lt;br /&gt;
/&lt;br /&gt;
undef TABLESPACE_NAME&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
If however, the intention is to drop the tablespace anyway, the tables need to be dropped before the tablespace can be dropped.&amp;lt;br /&amp;gt;&lt;br /&gt;
But ...tables with partitions in different tablespaces cannot be dropped. The partitions need to be dropped first!&amp;lt;br /&amp;gt;&lt;br /&gt;
Run the following query to generate statements to drop all the &amp;#039;problem&amp;#039; tables. When these have gone, the tablespace can be dropped.&lt;br /&gt;
* drop table partitions&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
spool /tmp/drop_table_partitions.sql&lt;br /&gt;
sqlplus / as sysdba&amp;lt;&amp;lt;EOSQL&lt;br /&gt;
set headi off newpa none feedb off trims on echo off&lt;br /&gt;
select &amp;#039;alter table &amp;#039;||table_owner||&amp;#039;.&amp;#039;||table_name||&amp;#039; drop partition &amp;#039;||partition_name||&amp;#039;;&amp;#039;&lt;br /&gt;
from   dba_tab_partitions&lt;br /&gt;
where  tablespace_name = &amp;#039;$TABLESPACE_NAME&amp;#039;&lt;br /&gt;
/&lt;br /&gt;
spool off&lt;br /&gt;
EOSQL&lt;br /&gt;
echo &amp;quot;@/tmp/drop_table_partitions.sql&amp;quot; | sqlplus / as sysdba&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* drop tables&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sqlplus / as sysdba&amp;lt;&amp;lt;EOSQL&lt;br /&gt;
select &amp;#039;drop table &amp;#039;||table_owner||&amp;#039;.&amp;#039;||table_name||&amp;#039;;&amp;#039;&lt;br /&gt;
from   dba_tab_partitions&lt;br /&gt;
where  tablespace_name = &amp;#039;$TABLESPACE_NAME&amp;#039;&lt;br /&gt;
spool /tmp/drop_tables.sql&lt;br /&gt;
/&lt;br /&gt;
spool off&lt;br /&gt;
EOSQL&lt;br /&gt;
echo &amp;quot;@/tmp/drop_tables.sql&amp;quot; | sqlplus / as sysdba&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* drop tablespace&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
drop tablespace ads_archive including contents and datafiles&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Find all table partitions in tablespaces with missing datafiles====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 1000 pages 100&lt;br /&gt;
col owner for a10&lt;br /&gt;
col segment_name for a40&lt;br /&gt;
col segment_type for a25&lt;br /&gt;
col partition_name for a20&lt;br /&gt;
col tablespace_name for a25&lt;br /&gt;
select owner&lt;br /&gt;
,      segment_name&lt;br /&gt;
,      segment_type&lt;br /&gt;
,      partition_name&lt;br /&gt;
,      tablespace_name&lt;br /&gt;
from   dba_segments&lt;br /&gt;
where  segment_type in (&amp;#039;TABLE PARTITION&amp;#039;, &amp;#039;TABLE SUBPARTITION&amp;#039;)&lt;br /&gt;
and    tablespace_name in (&lt;br /&gt;
                          select tablespace_name&lt;br /&gt;
                          from   dba_data_files&lt;br /&gt;
                          where  file_name like &amp;#039;%MISSING%&amp;#039;&lt;br /&gt;
                          )&lt;br /&gt;
order  by 1, 2, decode (segment_type, &amp;#039;TABLE SUBPARTITION&amp;#039;, 1, 2),4&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Use exchange partition to alter metadata of the tablespaces without moving the actual data====&lt;br /&gt;
* [https://community.oracle.com/thread/581401?start=15&amp;amp;tstart=0 this] is what you are looking for!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Workaround====&lt;br /&gt;
While working on the solution, a backup can be made using the &amp;quot;skip inaccessible&amp;quot; option. Put this in an rman cmdfile...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
connect catalog rmanusr/rmanpwd@rmancat&lt;br /&gt;
connect target sys/syspwd@adsa1&lt;br /&gt;
run {&lt;br /&gt;
allocate channel t1 type &amp;#039;sbt_tape&amp;#039; parms &amp;#039;ENV=(NSR_SERVER=hn6000.company.be,NSR_CLIENT=hn491,NSR_DATA_VOLUME_POOL=DD1DAILY,NSR_END_ERROR_IGNORE=TRUE)&amp;#039;;&lt;br /&gt;
allocate channel t2 type &amp;#039;sbt_tape&amp;#039; parms &amp;#039;ENV=(NSR_SERVER=hn6000.company.be,NSR_CLIENT=hn491,NSR_DATA_VOLUME_POOL=DD1DAILY,NSR_END_ERROR_IGNORE=TRUE)&amp;#039;;&lt;br /&gt;
configure retention policy to recovery window of 28 days;&lt;br /&gt;
configure controlfile autobackup on;&lt;br /&gt;
crosscheck archivelog all;&lt;br /&gt;
SQL &amp;#039;ALTER SYSTEM SWITCH LOGFILE&amp;#039;;&lt;br /&gt;
SQL &amp;#039;CREATE PFILE FROM SPFILE&amp;#039;;&lt;br /&gt;
backup filesperset 1 format &amp;#039;dbfull_%d_%I_%t_%s_%p&amp;#039; full database plus archivelog skip inaccessible delete all input;&lt;br /&gt;
backup current controlfile;&lt;br /&gt;
release channel t1;&lt;br /&gt;
release channel t2;&lt;br /&gt;
}&lt;br /&gt;
exit&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Another way of deleting the offending objects====&lt;br /&gt;
Taken from [http://www.dbarj.com.br/en/2015/01/resume-oracle-duplicate-database-failed-recovery-datafiles/ Recover from a failed RMAN duplicate]&amp;lt;br /&amp;gt;&lt;br /&gt;
Need to check it before running it blindly!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
set echo off feed off termo off trims on pages 0 newpa none lines 2000 headi off long 32000&lt;br /&gt;
col val for a1000&lt;br /&gt;
spool destroy_offending_objects.sql&lt;br /&gt;
&lt;br /&gt;
select to_clob (&amp;#039;alter table &amp;#039;|| table_name||&amp;#039; drop constraint &amp;#039;||constraint_name||&amp;#039;;&amp;#039;) Val&lt;br /&gt;
from user_constraints where constraint_type in (&amp;#039;R&amp;#039;,&amp;#039;P&amp;#039;) and table_name in (select distinct table_name from user_tab_partitions)&lt;br /&gt;
union all&lt;br /&gt;
select to_clob (&amp;#039;drop index &amp;#039;||index_name||&amp;#039;;&amp;#039;) Val from user_indexes where table_name in (select distinct table_name from user_tab_partitions)&lt;br /&gt;
union all&lt;br /&gt;
select to_clob (&amp;#039;alter table &amp;#039;||table_name|| &amp;#039; drop partition &amp;#039;||partition_name||&amp;#039;;&amp;#039;) from dba_tab_partitions&lt;br /&gt;
where tablespace_name in (select tablespace_name from dba_data_files where file_name like &amp;#039;%MISSING%&amp;#039;)&lt;br /&gt;
union all&lt;br /&gt;
Select case&lt;br /&gt;
when instr (VAl, &amp;#039;PARTITION&amp;#039;) = 0 Then&lt;br /&gt;
substr (Val,1,InStr (Val,&amp;#039;)&amp;#039;)+1)||&amp;#039;;&amp;#039;&lt;br /&gt;
else&lt;br /&gt;
substr (Val,1,InStr (Val,&amp;#039;)&amp;#039;)+1)||&amp;#039; local;&amp;#039;&lt;br /&gt;
End val&lt;br /&gt;
from&lt;br /&gt;
(select dbms_metadata.get_ddl (&amp;#039;INDEX&amp;#039;, index_name,&amp;#039;TEST&amp;#039;) Val from user_indexes where table_name in (select distinct table_name from user_tab_partitions))&lt;br /&gt;
union all&lt;br /&gt;
Select Val&lt;br /&gt;
from&lt;br /&gt;
(select dbms_metadata.get_dependent_ddl (&amp;#039;REF_CONSTRAINT&amp;#039;, table_name,&amp;#039;TEST&amp;#039;) Val&lt;br /&gt;
from user_tables where table_name in (select distinct table_name from user_tab_partitions join user_constraints using ( table_name)&lt;br /&gt;
where constraint_type=&amp;#039;R&amp;#039;))&lt;br /&gt;
union all&lt;br /&gt;
select Val&lt;br /&gt;
from&lt;br /&gt;
(select dbms_metadata.get_ddl (&amp;#039;CONSTRAINT&amp;#039;, constraint_name,&amp;#039;TEST&amp;#039;) Val&lt;br /&gt;
from user_constraints&lt;br /&gt;
where constraint_type=&amp;#039;P&amp;#039; and table_name in (select distinct table_name from user_tab_partitions)&lt;br /&gt;
)&lt;br /&gt;
union all&lt;br /&gt;
select to_clob (val)&lt;br /&gt;
from (select distinct &amp;#039;drop tablespace &amp;#039;||tablespace_name|| &amp;#039; including contents and datafiles;&amp;#039; val&lt;br /&gt;
from dba_tab_partitions&lt;br /&gt;
where tablespace_name in (select tablespace_name from dba_data_files where file_name like &amp;#039;%MISSING%&amp;#039;)&lt;br /&gt;
);&lt;br /&gt;
&lt;br /&gt;
spoo off&lt;br /&gt;
&lt;br /&gt;
@destroy_offending_objects&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORA-28112: failed to execute policy function===&lt;br /&gt;
when exporting or importing using [[Data Pump]]&amp;lt; /br&amp;gt;&lt;br /&gt;
During expdp is accompanied by &amp;quot;&amp;#039;&amp;#039;&amp;#039;ORA-31693: Table data object &amp;quot;SYSMAN&amp;quot;.&amp;quot;MGMT_IP_REPORT_DEF&amp;quot; failed to load/unload and is being skipped due to error:&amp;#039;&amp;#039;&amp;#039;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
===Reason===&lt;br /&gt;
This happens due to audit policies being defined on the table but the policy function is defined in another schema.&lt;br /&gt;
&lt;br /&gt;
===Solution===&lt;br /&gt;
Either drop the policy after importing the table with:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
begin&lt;br /&gt;
    for rec in (select * from dba_audit_policies where object_schema = &amp;#039;SYSMAN&amp;#039;) loop&lt;br /&gt;
        dbms_fga.drop_policy(object_schema =&amp;gt; rec.object_schema,&lt;br /&gt;
                             object_name =&amp;gt; rec.object_name,&lt;br /&gt;
                             policy_name =&amp;gt; rec.policy_name);  &lt;br /&gt;
    end loop;&lt;br /&gt;
end;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or exclude the policies during export by adding this to the .par file:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
exclude=FGA_POLICY&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or even better, give the necessary grants to the exporting user...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
grant exempt access policy to impexpusr;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The sysdba role has this automatically.&lt;br /&gt;
===ORA-17629: Cannot connect to the remote database server===&lt;br /&gt;
Active duplication fails to connect even though dns connection exists in tnsnames.ora&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
Problem:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
DUPLICATE TARGET DATABASE FROM ACTIVE DATABASE DORECOVER NOFILENAMECHECK;&lt;br /&gt;
&lt;br /&gt;
RMAN-03002: failure of Duplicate Db command at 05/27/2015 12:52:24&lt;br /&gt;
RMAN-05501: aborting duplication of target database&lt;br /&gt;
RMAN-03015: error occurred in stored script Memory Script&lt;br /&gt;
RMAN-03009: failure of backup command on ORA_DISK_1 channel at 05/27/2015 12:52:23&lt;br /&gt;
ORA-17629: Cannot connect to the remote database server&lt;br /&gt;
ORA-17627: ORA-12154: TNS:could not resolve the connect identifier specified&lt;br /&gt;
&lt;br /&gt;
ORA-17629: Cannot connect to the remote database server&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
Solution:&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
Update the tnsnames.ora of both destination &amp;#039;&amp;#039;&amp;#039;and&amp;#039;&amp;#039;&amp;#039; source ORACLE_HOMEs!&lt;br /&gt;
&lt;br /&gt;
===ORA-01950: no privileges on tablespace &amp;#039;SYSAUX&amp;#039;===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
26-JUN-15 03:12:27.545: &amp;gt;&amp;gt;&amp;gt; ORA-31642: the following SQL statement fails: &lt;br /&gt;
BEGIN &amp;quot;SYS&amp;quot;.&amp;quot;DBMS_RULE_EXP_RULES&amp;quot;.SCHEMA_CALLOUT(:1,0,1,&amp;#039;12.01.00.02.00&amp;#039;); END;&lt;br /&gt;
ORA-01950: no privileges on tablespace &amp;#039;SYSAUX&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Cause:&amp;#039;&amp;#039;&amp;#039;&amp;lt;br /&amp;gt;&lt;br /&gt;
In this case, it seems SYSMAN has no rights to create objects in the SYSAUX tablespace&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Solution:&amp;#039;&amp;#039;&amp;#039;&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter user SYSMAN quota unlimited on sysaux;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
More information [https://support.oracle.com/epmos/faces/SearchDocDisplay?_adf.ctrl-state=bov7jp5pq_4&amp;amp;_afrLoop=547371065896716#SYMPTOM here]&lt;br /&gt;
&lt;br /&gt;
===ORA-39080: failed to create queues &amp;quot;KUPC$C_1_20150616165037&amp;quot; and &amp;quot;KUPC$S_1_20150616165037&amp;quot; for Data Pump job===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
expdp /&lt;br /&gt;
&lt;br /&gt;
Export: Release 11.2.0.4.0 - Production on Tue Jun 16 16:50:36 2015&lt;br /&gt;
&lt;br /&gt;
Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.&lt;br /&gt;
&lt;br /&gt;
Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production&lt;br /&gt;
With the Partitioning, OLAP, Data Mining and Real Application Testing options&lt;br /&gt;
ORA-31626: job does not exist&lt;br /&gt;
ORA-31637: cannot create job SYS_EXPORT_SCHEMA_01 for user OPS$ORAIBM&lt;br /&gt;
ORA-06512: at &amp;quot;SYS.DBMS_SYS_ERROR&amp;quot;, line 95&lt;br /&gt;
ORA-06512: at &amp;quot;SYS.KUPV$FT_INT&amp;quot;, line 798&lt;br /&gt;
[[ORA-39080: failed to create queues &amp;quot;KUPC$C_1_20150616165037&amp;quot; and &amp;quot;KUPC$S_1_20150616165037&amp;quot; for Data Pump job]]&lt;br /&gt;
ORA-06512: at &amp;quot;SYS.DBMS_SYS_ERROR&amp;quot;, line 95&lt;br /&gt;
ORA-06512: at &amp;quot;SYS.KUPC$QUE_INT&amp;quot;, line 1534&lt;br /&gt;
ORA-24002: QUEUE_TABLE SYS.AQ$KUPC$DATAPUMP_QUETAB_1 does not exist&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Cause:====&lt;br /&gt;
Possibly some or all of OLAP module has got itself deinstalled.&lt;br /&gt;
====Solution:====&lt;br /&gt;
Try:&lt;br /&gt;
* Recompiling invalid objects. @?/rdbms/admin/utlrp&lt;br /&gt;
* Reinstalling DBMS_CUBE packages by (re)running catproc.sql. @?/rdbms/admin/catproc followed by @?/rdbms/admin/utlrp&lt;br /&gt;
* Reinstalling OLAP. @?/olap/admin/olap.sql SYSAUX TEMP; But see Metalink note ID 296187.1 for full instructions.&lt;br /&gt;
* Check metalink for bugs. See ID 345198.1 and possibly ID 453796.1&lt;br /&gt;
===ORA-14063: Unusable index exists on unique/primary constraint key===&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;ORA-39083: Object type CONSTRAINT failed to create with error:&amp;#039;&amp;#039;&amp;#039;&amp;lt;br /&amp;gt;&lt;br /&gt;
During an import datapump (impdp), import failed because indexes were in error before the tables were exported. This causes the import of rows to be skipped.&amp;lt;br /&amp;gt;&lt;br /&gt;
If the export cannot be done again (having compiled the indexes), then the metadata can be imported and the indexes compiled before importing the data.&lt;br /&gt;
* Import the metadata&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cat&amp;lt;&amp;lt;EOCAT &amp;gt;impdp_adst_ads_archive_metadata.par&lt;br /&gt;
userid=&amp;#039;/ as sysdba&amp;#039;&lt;br /&gt;
dumpfile=adst_ads_archive.dmp&lt;br /&gt;
logfile=impdp_adst_ads_archive_metadata.log&lt;br /&gt;
content=metadata_only&lt;br /&gt;
EOCAT&lt;br /&gt;
&lt;br /&gt;
impdp parfile=impdp_adst_ads_archive_metadata.par&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Find the bad indexes and recompile them&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select &amp;#039;alter index &amp;#039;|| owner||&amp;#039;.&amp;#039;||index_name||&amp;#039; rebuild online parallel 8;&amp;#039;&lt;br /&gt;
from   dba_indexes&lt;br /&gt;
where  status = &amp;#039;UNUSABLE&amp;#039;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Import the data&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cat&amp;lt;&amp;lt;EOCAT &amp;gt;impdp_adst_ads_archive_data.par&lt;br /&gt;
userid=&amp;#039;/ as sysdba&amp;#039;&lt;br /&gt;
dumpfile=adst_ads_archive.dmp&lt;br /&gt;
logfile=impdp_adst_ads_archive_data.log&lt;br /&gt;
table_exists_action=append&lt;br /&gt;
content=data_only&lt;br /&gt;
EOCAT&lt;br /&gt;
&lt;br /&gt;
impdp parfile=impdp_adst_ads_archive_data.par&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORA-09925: Unable to create audit trail file===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SQL&amp;gt; startup nomount pfile=&amp;quot;/oracle/TRSCRP1/admin/initTRSCRP1.ora&amp;quot;&lt;br /&gt;
ORA-09925: Unable to create audit trail file&lt;br /&gt;
SVR4 Error: 2: No such file or directory&lt;br /&gt;
Additional information: 9925&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
connected to auxiliary database (not started)&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-03002: failure of Duplicate Db command at 08/29/2017 15:53:09&lt;br /&gt;
RMAN-05501: aborting duplication of target database&lt;br /&gt;
RMAN-03015: error occurred in stored script Memory Script&lt;br /&gt;
RMAN-04014: startup failed: ORA-09925: Unable to create audit trail file&lt;br /&gt;
IBM AIX RISC System/6000 Error: 2: No such file or directory&lt;br /&gt;
Additional information: 9925&lt;br /&gt;
&lt;br /&gt;
Recovery Manager complete.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Problem====&lt;br /&gt;
This will be almost certainly one of two issues. Either the directory is not writable by the id that started the instance or the directory just does not exist.&lt;br /&gt;
====Solution====&lt;br /&gt;
Note there can be a difference between what you see when you type:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
show parameter audit&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
and when you type:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
strings -a $ORACLE_HOME/dbs/spfile${ORACLE_SID}.ora | grep -i audit&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
due to someone doing an &amp;quot;alter system&amp;quot; without the &amp;quot;scope=spfile&amp;quot; or &amp;quot;scope=both&amp;quot;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SQL&amp;gt; host ls -al /oracle/TRSCRP1/admin/adump&lt;br /&gt;
SQL&amp;gt; host mkdir /oracle/TRSCRP1/admin/adump&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===ORA-09925: Unable to create audit trail file===&lt;br /&gt;
When starting SQL*Plus with no db processes running (expecting to see &amp;quot;Connected to an idle instance&amp;quot;), we get this:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ERROR:&lt;br /&gt;
ORA-09925: Unable to create audit trail file&lt;br /&gt;
IBM AIX RISC System/6000 Error: 2: No such file or directory&lt;br /&gt;
Additional information: 9925&lt;br /&gt;
ORA-01075: you are currently logged on&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Filesystem permissions are fine&lt;br /&gt;
* &amp;#039;strings spfile&amp;lt;SID&amp;gt;.ora | grep audit&amp;#039; shows the correct directory&lt;br /&gt;
* Running on AIX&lt;br /&gt;
AIX is the clue here... need to check for semaphores and locked shared memory objects&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
(0) UCLID55D oraibm@solax082:/oracle/product/11.2.0.3/bin&amp;gt; sysresv&lt;br /&gt;
&lt;br /&gt;
IPC Resources for ORACLE_SID &amp;quot;UCLID55D&amp;quot; :&lt;br /&gt;
Shared Memory:&lt;br /&gt;
ID              KEY&lt;br /&gt;
8388640         0xffffffff&lt;br /&gt;
579862561       0xffffffff&lt;br /&gt;
384827426       0x326f32e8&lt;br /&gt;
&lt;br /&gt;
Semaphores:&lt;br /&gt;
ID              KEY&lt;br /&gt;
167772287       0xf09f4914&lt;br /&gt;
Oracle Instance alive for sid &amp;quot;UCLID55D&amp;quot;&lt;br /&gt;
&lt;br /&gt;
(0) UCLID55D oraibm@solax082:/oracle/product/11.2.0.3/bin&amp;gt; ipcrm -m 8388640&lt;br /&gt;
(0) UCLID55D oraibm@solax082:/oracle/product/11.2.0.3/bin&amp;gt; ipcrm -m 579862561&lt;br /&gt;
(0) UCLID55D oraibm@solax082:/oracle/product/11.2.0.3/bin&amp;gt; ipcrm -m 384827426&lt;br /&gt;
&lt;br /&gt;
(0) UCLID55D oraibm@solax082:/oracle/product/11.2.0.3/bin&amp;gt; ipcrm -s 167772287&lt;br /&gt;
&lt;br /&gt;
(0) UCLID55D oraibm@solax082:/oracle/product/11.2.0.3/bin&amp;gt; sysresv&lt;br /&gt;
&lt;br /&gt;
IPC Resources for ORACLE_SID &amp;quot;UCLID55D&amp;quot; :&lt;br /&gt;
Shared Memory&lt;br /&gt;
ID              KEY&lt;br /&gt;
No shared memory segments used&lt;br /&gt;
Semaphores:&lt;br /&gt;
ID              KEY&lt;br /&gt;
No semaphore resources used&lt;br /&gt;
Oracle Instance not alive for sid &amp;quot;UCLID55D&amp;quot;&lt;br /&gt;
&lt;br /&gt;
(0) UCLID55D oraibm@solax082:/oracle/product/11.2.0.3/bin&amp;gt; ps -ef | grep UCLID55D&lt;br /&gt;
oraibm 3326 23776 0 14:12:05 pts/1 0:00 grep UCLID55D &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===RMAN-06023: no backup or copy of datafile 1 found to restore===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-03002: failure of Duplicate Db command at 05/16/2018 16:08:13&lt;br /&gt;
RMAN-05501: aborting duplication of target database&lt;br /&gt;
RMAN-05556: not all datafiles have backups that can be recovered to SCN 278250901080&lt;br /&gt;
RMAN-03015: error occurred in stored script Memory Script&lt;br /&gt;
RMAN-06026: some targets not found - aborting restore&lt;br /&gt;
RMAN-06023: no backup or copy of datafile 7 found to restore&lt;br /&gt;
RMAN-06023: no backup or copy of datafile 6 found to restore&lt;br /&gt;
RMAN-06023: no backup or copy of datafile 5 found to restore&lt;br /&gt;
RMAN-06023: no backup or copy of datafile 4 found to restore&lt;br /&gt;
RMAN-06023: no backup or copy of datafile 3 found to restore&lt;br /&gt;
RMAN-06023: no backup or copy of datafile 2 found to restore&lt;br /&gt;
RMAN-06023: no backup or copy of datafile 1 found to restore&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Seems pretty straightforward? SCN was set too early for the retention period. But no, not this time.&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
RMAN&amp;gt; list backup of datafile 1;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
List of Backup Sets&lt;br /&gt;
===================&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
BS Key  Type LV Size       Device Type Elapsed Time Completion Time&lt;br /&gt;
------- ---- -- ---------- ----------- ------------ -------------------&lt;br /&gt;
110170340 Incr 0  132.90G    SBT_TAPE    00:18:32     2018-05-14 01:19:40&lt;br /&gt;
        BP Key: 110170345   Status: AVAILABLE  Compressed: NO  Tag: WEEKLY_FULL&lt;br /&gt;
        Handle: 24639762_REPORTA_07t2r3uk_1_1   Media: V_17152809_77191330&lt;br /&gt;
  List of Datafiles in backup set 110170340&lt;br /&gt;
  File LV Type Ckp SCN    Ckp Time            Name&lt;br /&gt;
  ---- -- ---- ---------- ------------------- ----&lt;br /&gt;
  1    0  Incr 277998128991 2018-05-14 01:01:08 /cln/acc/ora_data3/reporta/system01.dbf&lt;br /&gt;
&lt;br /&gt;
BS Key  Type LV Size       Device Type Elapsed Time Completion Time&lt;br /&gt;
------- ---- -- ---------- ----------- ------------ -------------------&lt;br /&gt;
110355808 Incr 1  204.00M    SBT_TAPE    00:05:13     2018-05-15 01:06:22&lt;br /&gt;
        BP Key: 110355813   Status: AVAILABLE  Compressed: NO  Tag: DAILY_INCREMENTAL&lt;br /&gt;
        Handle: 24661053_REPORTA_3ft2toal_1_1   Media: V_17173010_77253424&lt;br /&gt;
  List of Datafiles in backup set 110355808&lt;br /&gt;
  File LV Type Ckp SCN    Ckp Time            Name&lt;br /&gt;
  ---- -- ---- ---------- ------------------- ----&lt;br /&gt;
  1    1  Incr 278044267395 2018-05-15 01:01:09 /cln/acc/ora_data3/reporta/system01.dbf&lt;br /&gt;
&lt;br /&gt;
BS Key  Type LV Size       Device Type Elapsed Time Completion Time&lt;br /&gt;
------- ---- -- ---------- ----------- ------------ -------------------&lt;br /&gt;
110543802 Incr 1  237.00M    SBT_TAPE    00:05:51     2018-05-16 01:07:40&lt;br /&gt;
        BP Key: 110543807   Status: AVAILABLE  Compressed: NO  Tag: DAILY_INCREMENTAL&lt;br /&gt;
        Handle: 24681602_REPORTA_6nt30cnt_1_1   Media: V_17133646_77315270&lt;br /&gt;
  List of Datafiles in backup set 110543802&lt;br /&gt;
  File LV Type Ckp SCN    Ckp Time            Name&lt;br /&gt;
  ---- -- ---- ---------- ------------------- ----&lt;br /&gt;
  1    1  Incr 278286445856 2018-05-16 01:01:50 /cln/acc/ora_data3/reporta/system01.dbf&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
SCN was only 12 hours ago with a retention of 28 days! The backup piece dated 2018-05-15 01:06:22 is clearly available and on the device type set_tape.&amp;lt;br /&amp;gt;&lt;br /&gt;
The trick here was to look back through the logs and look more closely at what the file restore message was saying...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
channel t0: starting datafile backup set restore&lt;br /&gt;
channel t0: specifying datafile(s) to restore from backup set&lt;br /&gt;
channel t0: restoring datafile 00001 to /cln/acc/ora_data3/reporta/system01.dbf             &amp;lt; &amp;lt; &amp;lt; ==============&lt;br /&gt;
channel t0: reading from backup piece dbfull_REPORTA_738887052_967580186_116_1&lt;br /&gt;
channel t2: ORA-19870: error while restoring backup piece dbfull_REPORTA_738887052_967579750_113_1&lt;br /&gt;
ORA-19507: failed to retrieve sequential file, handle=&amp;quot;dbfull_REPORTA_738887052_967579750_113_1&amp;quot;, parms=&amp;quot;&amp;quot;&lt;br /&gt;
ORA-27029: skgfrtrv: sbtrestore returned error&lt;br /&gt;
ORA-19511: non RMAN, but media manager or vendor specific failure, error text:&lt;br /&gt;
   CreateOraObject20: Job[0] thread[55116090]: Restore: GetBackupInfo() for Archive File[dbfull_REPORTA_738887052_967579750_113_1] failed.&lt;br /&gt;
ORA-0651&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
It was not the fact that it could not find the data on tape, it was that it could not save the file to the location indicated!!&lt;br /&gt;
In the RMAN DUPLICATE script, I had all the file paths redirected (a mixture of convert parameters and spfile set) to a /restore filesystem.&amp;lt;br /&amp;gt;&lt;br /&gt;
But I forgot one!&amp;lt;br /&amp;gt;&lt;br /&gt;
A handy thing to do is to search out the file paths with this to see if something is still wrong:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cd $ORACLE_HOME/dbs&lt;br /&gt;
strings -a spfile${ORACLE_SID}.ora | grep dest&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This should show any paths still not getting caught by the DUPLICATE script.&lt;br /&gt;
&lt;br /&gt;
===RMAN-06136: ORACLE error from auxiliary database: ORA-06502: PL/SQL: numeric or value error===&lt;br /&gt;
When cloning a database, the duplicate fails with this error.&lt;br /&gt;
====Problem====&lt;br /&gt;
This duplicate had no target connection but did have a catalog and auxiliary connection.&lt;br /&gt;
In the catalog (which was the catalog where the target was registerd), there was also an entry in that catalog with the same name as the auxiliary - left over from the days when these 2 instances were Primary and Standby in a Dataguard configuration.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
Datafile 414 skipped by request&lt;br /&gt;
Datafile 415 skipped by request&lt;br /&gt;
Datafile 419 skipped by request&lt;br /&gt;
Datafile 420 skipped by request&lt;br /&gt;
Datafile 421 skipped by request&lt;br /&gt;
&lt;br /&gt;
DBGSQL:     AUXILIARY&amp;gt; begin :ofname := sys.dbms_backup_restore.convertFileName( fname   =&amp;gt;   :ifname, ftype   =&amp;gt;   :iftype, osftype =&amp;gt;   TRUE); end;&lt;br /&gt;
DBGSQL:        sqlcode = 6502&lt;br /&gt;
DBGSQL:         B :ofname = NULL&lt;br /&gt;
DBGSQL:         B :ifname =&lt;br /&gt;
DBGSQL:         B :iftype = 2&lt;br /&gt;
restarting auxiliary database without server parameter file&lt;br /&gt;
Oracle instance started&lt;br /&gt;
&lt;br /&gt;
Total System Global Area   32068440064 bytes&lt;br /&gt;
&lt;br /&gt;
Fixed Size                     2262200 bytes&lt;br /&gt;
Variable Size              16978545480 bytes&lt;br /&gt;
Database Buffers           15032385536 bytes&lt;br /&gt;
Redo Buffers                  55246848 bytes&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-03002: failure of Duplicate Db command at 10/04/2017 14:50:29&lt;br /&gt;
RMAN-05501: aborting duplication of target database&lt;br /&gt;
RMAN-06136: ORACLE error from auxiliary database: ORA-06502: PL/SQL: numeric or value error&lt;br /&gt;
&lt;br /&gt;
Recovery Manager complete.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Solution====&lt;br /&gt;
Connect to the catalog and unregister the name of the auxiliary database. It shouldn&amp;#039;t be there anyway.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rman catalog rmanusr/rmanpwd@rmancat&lt;br /&gt;
&lt;br /&gt;
Recovery Manager: Release 11.2.0.4.0 - Production on Wed Oct 4 15:00:00 2017&lt;br /&gt;
&lt;br /&gt;
Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.&lt;br /&gt;
&lt;br /&gt;
connected to recovery catalog database&lt;br /&gt;
&lt;br /&gt;
RMAN&amp;gt; set dbid 4260753020;&lt;br /&gt;
&lt;br /&gt;
executing command: SET DBID&lt;br /&gt;
database name is &amp;quot;LBK&amp;quot; and DBID is 4260753020&lt;br /&gt;
&lt;br /&gt;
RMAN&amp;gt; list db_unique_name of database;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
List of Databases&lt;br /&gt;
DB Key  DB Name  DB ID            Database Role    Db_unique_name&lt;br /&gt;
------- ------- ----------------- ---------------  ------------------&lt;br /&gt;
13301587 LBK      4260753020       PRIMARY          LBK&lt;br /&gt;
13301587 LBK      4260753020       STANDBY          ACC_PERF&lt;br /&gt;
13301587 LBK      4260753020       STANDBY          LBKRO&lt;br /&gt;
&lt;br /&gt;
RMAN&amp;gt; unregister db_unique_name &amp;#039;ACC_PERF&amp;#039;;&lt;br /&gt;
&lt;br /&gt;
database db_unique_name is &amp;quot;ACC_PERF&amp;quot;, db_name is &amp;quot;LBK&amp;quot; and DBID is 4260753020&lt;br /&gt;
&lt;br /&gt;
Want to unregister the database with target db_unique_name (enter YES or NO)? YES&lt;br /&gt;
database with db_unique_name ACC_PERF unregistered from the recovery catalog&lt;br /&gt;
&lt;br /&gt;
RMAN&amp;gt; exit&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORA-39181: Only partial table data may be exported due to fine grain access control on &amp;quot;owner&amp;quot;.&amp;quot;&amp;lt;table_name&amp;gt;&amp;quot;===&lt;br /&gt;
&lt;br /&gt;
===Reason===&lt;br /&gt;
This happens when applications are designed with fine-grained access.&lt;br /&gt;
===Solution===&lt;br /&gt;
Grant the necessary privileges to the exporting user...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
grant exempt access policy to ops$oraibm;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORA-04030: out of process memory when trying to allocate 2520 bytes===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
expdp problem (ORA-04030: out of process memory when trying to allocate 2520 bytes (pga heap,koh-kghu call heap))&lt;br /&gt;
&lt;br /&gt;
select value from v$pgastat where name=&amp;#039;maximum PGA allocated&amp;#039;;&lt;br /&gt;
&lt;br /&gt;
SHOW PARAMETER TARGET&lt;br /&gt;
&lt;br /&gt;
ORA-04030: out of process memory when trying to allocate 2520 bytes (pga heap,koh-kghu call heap)&lt;br /&gt;
&lt;br /&gt;
alter system reset pga_aggregate_target scope=spfile;&lt;br /&gt;
&lt;br /&gt;
show sga&lt;br /&gt;
&lt;br /&gt;
select * from v$pgastat;&lt;br /&gt;
&lt;br /&gt;
show parameter process&lt;br /&gt;
&lt;br /&gt;
select sum(value)/1024/1024 Mb&lt;br /&gt;
from   v$sesstat s, v$statname n&lt;br /&gt;
where  1=1&lt;br /&gt;
and    n.STATISTIC# = s.STATISTIC#&lt;br /&gt;
and    name = &amp;#039;session pga memory&amp;#039;&lt;br /&gt;
&lt;br /&gt;
show parameter WORKAREA&lt;br /&gt;
&lt;br /&gt;
select value from v$pgastat where name=&amp;#039;maximum PGA allocated&amp;#039;;&lt;br /&gt;
&lt;br /&gt;
alter system set memory_max_target=10G scope=spfile;&lt;br /&gt;
&lt;br /&gt;
alter system set memory_target=3G scope=both;&lt;br /&gt;
&lt;br /&gt;
select * from v$memory_target_advice order by memory_size;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORA-04031: unable to allocate 32 bytes of shared memory (&amp;quot;shared pool&amp;quot;,&amp;quot;select name,online$,contents...&amp;quot;,&amp;quot;KGLH0^e5705bfc&amp;quot;,&amp;quot;kglHeapInitialize:temp&amp;quot;)===&lt;br /&gt;
* [https://blogs.oracle.com/db/entry/ora-4031_troubleshooting ORA-4031 Troubleshooting]&lt;br /&gt;
* [https://support.oracle.com/epmos/faces/DocumentDisplay?_afrLoop=89215376348478&amp;amp;id=396940.1&amp;amp;_afrWindowMode=0&amp;amp;_adf.ctrl-state=u1z0xcppg_4 Troubleshooting and Diagnosing ORA-4031 Error - (Doc ID 396940.1)]&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ORA-04031: unable to allocate  bytes of shared memory (&amp;quot;&amp;quot;,&amp;quot;&amp;quot;,&amp;quot;&amp;quot;,&amp;quot;&amp;quot;) &lt;br /&gt;
ORA-04031: unable to allocate 32 bytes of shared memory (&amp;quot;shared pool&amp;quot;,&amp;quot;select name,online$,contents...&amp;quot;,&amp;quot;KGLH0^e5705bfc&amp;quot;,&amp;quot;kglHeapInitialize:temp&amp;quot;) &lt;br /&gt;
Incident details in: /oracle/diag/rdbms/mape/MAPE/incident/incdir_86754/MAPE_dm00_14221536_i86754.trc &lt;br /&gt;
Wed Jul 31 20:42:50 2013 &lt;br /&gt;
Dumping diagnostic data in directory=[cdmp_20130731204250], requested by (instance=1, osid=14221536 (DM00)), summary=[incident=86753]. &lt;br /&gt;
Wed Jul 31 20:42:51 2013 &lt;br /&gt;
Sweep [inc][86754]: completed &lt;br /&gt;
Sweep [inc][86753]: completed &lt;br /&gt;
Sweep [inc2][86753]: completed &lt;br /&gt;
Wed Jul 31 20:42:57 2013 &lt;br /&gt;
Use ADRCI or Support Workbench to package the incident. &lt;br /&gt;
See Note 411.1 at My Oracle Support for error and packaging details. &lt;br /&gt;
Dumping diagnostic data in directory=[cdmp_20130731204257], requested by (instance=1, osid=14221536 (DM00)), summary=[incident=86754]. &lt;br /&gt;
Wed Jul 31 20:43:35 2013 &lt;br /&gt;
Errors in file /oracle/diag/rdbms/mape/MAPE/trace/MAPE_dw02_40567024.trc  (incident=82993): &lt;br /&gt;
ORA-04031: unable to allocate 32 bytes of shared memory (&amp;quot;shared pool&amp;quot;,&amp;quot;select order#,columns,types ...&amp;quot;,&amp;quot;KGLH0^470434f8&amp;quot;,&amp;quot;kglHeapInitialize:temp&amp;quot;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Database had already crashed so nothing to do but:&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
(0) MAPE ora@x025:/home/ora&amp;gt; sqlplus / as sysdba&lt;br /&gt;
&lt;br /&gt;
SQL*Plus: Release 11.2.0.3.0 Production on Fri Aug 2 14:26:20 2013&lt;br /&gt;
&lt;br /&gt;
Copyright (c) 1982, 2011, Oracle.  All rights reserved.&lt;br /&gt;
&lt;br /&gt;
Connected.&lt;br /&gt;
SYS@MAPE&amp;gt; alter system flush shared_pool;&lt;br /&gt;
alter system flush shared_pool&lt;br /&gt;
*&lt;br /&gt;
ERROR at line 1:&lt;br /&gt;
ORA-01012: not logged on&lt;br /&gt;
Process ID: 0&lt;br /&gt;
Session ID: 0 Serial number: 0&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
SYS@MAPE&amp;gt; shutdown abort&lt;br /&gt;
ORACLE instance shut down.&lt;br /&gt;
SYS@MAPE&amp;gt; startup&lt;br /&gt;
ORACLE instance started.&lt;br /&gt;
&lt;br /&gt;
Total System Global Area  734892032 bytes&lt;br /&gt;
Fixed Size                  2225128 bytes&lt;br /&gt;
Variable Size             398461976 bytes&lt;br /&gt;
Database Buffers          318767104 bytes&lt;br /&gt;
Redo Buffers               15437824 bytes&lt;br /&gt;
Database mounted.&lt;br /&gt;
Database opened.&lt;br /&gt;
&lt;br /&gt;
SYS@MAPE&amp;gt; show parameter pool&lt;br /&gt;
&lt;br /&gt;
NAME                                 TYPE                           VALUE&lt;br /&gt;
------------------------------------ ------------------------------ ------------------------------&lt;br /&gt;
buffer_pool_keep                     string&lt;br /&gt;
buffer_pool_recycle                  string&lt;br /&gt;
global_context_pool_size             string&lt;br /&gt;
java_pool_size                       big integer                    0&lt;br /&gt;
large_pool_size                      big integer                    0&lt;br /&gt;
olap_page_pool_size                  big integer                    0&lt;br /&gt;
shared_pool_reserved_size            big integer                    18M&lt;br /&gt;
shared_pool_size                     big integer                    208M&lt;br /&gt;
streams_pool_size                    big integer                    0&lt;br /&gt;
SYS@MAPE&amp;gt; show sga&lt;br /&gt;
&lt;br /&gt;
Total System Global Area  734892032 bytes&lt;br /&gt;
Fixed Size                  2225128 bytes&lt;br /&gt;
Variable Size             385879064 bytes&lt;br /&gt;
Database Buffers          331350016 bytes&lt;br /&gt;
Redo Buffers               15437824 bytes&lt;br /&gt;
SYS@MAPE&amp;gt; exit&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
but for reference, the causes could well be the applications running on the database are not using bind variables...&amp;lt;br /&amp;gt;&lt;br /&gt;
From [http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:528893984337 asktom.oracle.com]&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
Just to give you a tiny idea of how huge of a difference this &lt;br /&gt;
can make performance wise, you only need to run a very small &lt;br /&gt;
test:&lt;br /&gt;
&lt;br /&gt;
tkyte@TKYTE816&amp;gt; alter system flush shared_pool;&lt;br /&gt;
System altered.&lt;br /&gt;
&lt;br /&gt;
tkyte@TKYTE816&amp;gt; declare&lt;br /&gt;
  2      type rc is ref cursor;&lt;br /&gt;
  3      l_rc rc;&lt;br /&gt;
  4      l_dummy all_objects.object_name%type;&lt;br /&gt;
  5      l_start number default dbms_utility.get_time;&lt;br /&gt;
  6  begin&lt;br /&gt;
  7      for i in 1 .. 1000&lt;br /&gt;
  8      loop&lt;br /&gt;
  9          open l_rc for&lt;br /&gt;
 10          &amp;#039;select object_name&lt;br /&gt;
 11             from all_objects&lt;br /&gt;
 12            where object_id = &amp;#039; || i;&lt;br /&gt;
 13          fetch l_rc into l_dummy;&lt;br /&gt;
 14          close l_rc;&lt;br /&gt;
 15      end loop;&lt;br /&gt;
 16      dbms_output.put_line&lt;br /&gt;
 17      ( round( (dbms_utility.get_time-l_start)/100, 2 ) ||&lt;br /&gt;
 18        &amp;#039; seconds...&amp;#039; );&lt;br /&gt;
 19  end;&lt;br /&gt;
 20  /&lt;br /&gt;
14.86 seconds...&lt;br /&gt;
&lt;br /&gt;
PL/SQL procedure successfully completed.&lt;br /&gt;
&lt;br /&gt;
tkyte@TKYTE816&amp;gt; declare&lt;br /&gt;
  2      type rc is ref cursor;&lt;br /&gt;
  3      l_rc rc;&lt;br /&gt;
  4      l_dummy all_objects.object_name%type;&lt;br /&gt;
  5      l_start number default dbms_utility.get_time;&lt;br /&gt;
  6  begin&lt;br /&gt;
  7      for i in 1 .. 1000&lt;br /&gt;
  8      loop&lt;br /&gt;
  9          open l_rc for&lt;br /&gt;
 10          &amp;#039;select object_name&lt;br /&gt;
 11             from all_objects&lt;br /&gt;
 12            where object_id = :x&amp;#039;&lt;br /&gt;
 13          using i;&lt;br /&gt;
 14          fetch l_rc into l_dummy;&lt;br /&gt;
 15          close l_rc;&lt;br /&gt;
 16      end loop;&lt;br /&gt;
 17      dbms_output.put_line&lt;br /&gt;
 18      ( round( (dbms_utility.get_time-l_start)/100, 2 ) ||&lt;br /&gt;
 19        &amp;#039; seconds...&amp;#039; );&lt;br /&gt;
 20  end;&lt;br /&gt;
 21  /&lt;br /&gt;
1.27 seconds...&lt;br /&gt;
&lt;br /&gt;
PL/SQL procedure successfully completed.&lt;br /&gt;
&lt;br /&gt;
That is pretty dramatic.  The fact is that not only does this &lt;br /&gt;
execute much faster (we spent more time PARSING our queries then &lt;br /&gt;
actually EXECUTING them!) it will let more users use your system &lt;br /&gt;
simultaneously.&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
and from [http://asktom.oracle.com/pls/asktom/f?p=100:11:::::P11_QUESTION_ID:1163635055580 linked question]&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
Lbrary cache latch contention is typically caused by NOT using bind variables.  It is due &lt;br /&gt;
to excessive parsing of statements.&lt;br /&gt;
&lt;br /&gt;
One way to see if this might be the case in your situation is to run a script like:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
create table t1 as select sql_text from v$sqlarea;&lt;br /&gt;
&lt;br /&gt;
alter table t1 add sql_text_wo_constants varchar2(1000);&lt;br /&gt;
&lt;br /&gt;
create or replace function &lt;br /&gt;
remove_constants( p_query in varchar2 ) return varchar2&lt;br /&gt;
as&lt;br /&gt;
    l_query long;&lt;br /&gt;
    l_char  varchar2(1);&lt;br /&gt;
    l_in_quotes boolean default FALSE;&lt;br /&gt;
begin&lt;br /&gt;
    for i in 1 .. length( p_query )&lt;br /&gt;
    loop&lt;br /&gt;
        l_char := substr(p_query,i,1);&lt;br /&gt;
        if ( l_char = &amp;#039;&amp;#039;&amp;#039;&amp;#039; and l_in_quotes )&lt;br /&gt;
        then&lt;br /&gt;
            l_in_quotes := FALSE;&lt;br /&gt;
        elsif ( l_char = &amp;#039;&amp;#039;&amp;#039;&amp;#039; and NOT l_in_quotes )&lt;br /&gt;
        then&lt;br /&gt;
            l_in_quotes := TRUE;&lt;br /&gt;
            l_query := l_query || &amp;#039;&amp;#039;&amp;#039;#&amp;#039;;&lt;br /&gt;
        end if;&lt;br /&gt;
        if ( NOT l_in_quotes ) then&lt;br /&gt;
            l_query := l_query || l_char;&lt;br /&gt;
        end if;&lt;br /&gt;
    end loop;&lt;br /&gt;
    l_query := translate( l_query, &amp;#039;0123456789&amp;#039;, &amp;#039;@@@@@@@@@@&amp;#039; );&lt;br /&gt;
    for i in 0 .. 8 loop&lt;br /&gt;
        l_query := replace( l_query, lpad(&amp;#039;@&amp;#039;,10-i,&amp;#039;@&amp;#039;), &amp;#039;@&amp;#039; );&lt;br /&gt;
        l_query := replace( l_query, lpad(&amp;#039; &amp;#039;,10-i,&amp;#039; &amp;#039;), &amp;#039; &amp;#039; );&lt;br /&gt;
    end loop;&lt;br /&gt;
    return upper(l_query);&lt;br /&gt;
end;&lt;br /&gt;
/&lt;br /&gt;
update t1 set sql_text_wo_constants = remove_constants(sql_text);&lt;br /&gt;
&lt;br /&gt;
select sql_text_wo_constants, count(*)&lt;br /&gt;
  from t1&lt;br /&gt;
 group by sql_text_wo_constants&lt;br /&gt;
having count(*) &amp;gt; 100&lt;br /&gt;
 order by 2&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The output of that last query will show you statements that are identical in the shared &lt;br /&gt;
pool after all numbers and character string constants have been removed.  These &lt;br /&gt;
statements -- and more importantly their counts -- are the potential bottlenecks.  In &lt;br /&gt;
addition to causing the contention, they will be HUGE cpu consumers.  &lt;br /&gt;
&lt;br /&gt;
If you discover your applications do not use bind variables -- you must have this &lt;br /&gt;
corrected.  You&amp;#039;ll never have a good hit ratio if everyone submits &amp;quot;unique&amp;quot; sql.  Your &lt;br /&gt;
shared pool will never be used right and you&amp;#039;ll be using excessive CPU (90% of the time &lt;br /&gt;
it takes to process &amp;quot;insert into t values ( 1 )&amp;quot; is parsing.  If you use &amp;quot;insert into t &lt;br /&gt;
values ( :x )&amp;quot;, and bind the value of 1 -- then the next person that runs that insert &lt;br /&gt;
will benefit from your work and run that much faster. &lt;br /&gt;
...&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Advice from Oracle concerning a concrete (12c) example of unable to allocate 52824 bytes of shared memory (&amp;quot;shared pool&amp;quot;,...====&lt;br /&gt;
This was from a ticket raised for a Data Pump export that consistently failed with:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Processing object type SCHEMA_EXPORT/TABLE/PROCACT_INSTANCE&lt;br /&gt;
Processing object type SCHEMA_EXPORT/TABLE/TABLE&lt;br /&gt;
ORA-39014: One or more workers have prematurely exited.&lt;br /&gt;
ORA-39029: worker 1 with process name &amp;quot;DW00&amp;quot; prematurely terminated&lt;br /&gt;
ORA-31671: Worker process DW00 had an unhandled exception.&lt;br /&gt;
ORA-04031: unable to allocate 52824 bytes of shared memory (&amp;quot;shared pool&amp;quot;,&amp;quot;unknown object&amp;quot;,&amp;quot;KTSL subheap&amp;quot;,&amp;quot;ktsl_load_disp-2&amp;quot;)&lt;br /&gt;
ORA-06512: at &amp;quot;SYS.KUPW$WORKER&amp;quot;, line 2122&lt;br /&gt;
ORA-06512: at line 2&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
The error ORA-4031 on the shared pool can indicate one of two things:&lt;br /&gt;
- insufficient space for the shared pool (so insufficient memory in SGA at that time)&lt;br /&gt;
OR&lt;br /&gt;
- although there is enough memory, it is fragmented and no contiguous chunk can be allocated to satisfy the latest memory request.&lt;br /&gt;
&lt;br /&gt;
Each SGA has a little fragmentation of course because of the operations taking place, so in your case the fragmentation is represented by the 18M of free memory, which exists in uncontiguous chunks.&lt;br /&gt;
This means that the root cause of the error is insufficient contiguous memory to allocate 12312 bytes of shared memory.&lt;br /&gt;
&lt;br /&gt;
ACTION PLAN&lt;br /&gt;
==============&lt;br /&gt;
1. We see memory_target=2000M. This is too little to support a 12c database, even when it has little activity.&lt;br /&gt;
As you may know 1.7G for the SGA was acceptable when speaking of 32bit OSs where it was hardly possible to make use of more than that.&lt;br /&gt;
Since you have a 64 bit system, the addressable memory is virtually unlimited.&lt;br /&gt;
Furthermore, by using AMM (memory_target&amp;gt;0) this memory is divided between the SGA and the PGA (the user processes) which in fact, depending on the number of connections, can limit the SGA even more.&lt;br /&gt;
So the first recommendation is to increase the value of memory_target to 4G for example. There is no ideal value, but this would be a reasonable starting value for tuning.&lt;br /&gt;
&lt;br /&gt;
You can do further tuning of the memory using the view V$MEMORY_TARGET_ADVICE.&lt;br /&gt;
The view V$MEMORY_TARGET_ADVICE provides tuning advice for the MEMORY_TARGET initialization parameter:&lt;br /&gt;
SQL&amp;gt; SELECT * FROM v$memory_target_advice ORDER BY memory_size;&lt;br /&gt;
&lt;br /&gt;
The dynamic performance view V$MEMORY_DYNAMIC_COMPONENTS shows the current sizes of all dynamically tuned memory components, including the total sizes of the SGA and instance PGA.&lt;br /&gt;
&lt;br /&gt;
You can also use V$MEMORY_RESIZE_OPS which has a circular history buffer of the last 800 memory resize requests.&lt;br /&gt;
&lt;br /&gt;
2. Since the AMM (you have memory_target&amp;gt;0) is used, then make sure to set:&lt;br /&gt;
 _shared_pool_reserved_pct to 10 or 15 to ensure that when the Shared Pool grows or shrinks automatically, the Reserved Area will change as well.&lt;br /&gt;
&lt;br /&gt;
SQL&amp;gt; alter system set &amp;quot;_shared_pool_reserved_pct&amp;quot;=15 scope=spfile;&lt;br /&gt;
--restart the instance&lt;br /&gt;
&lt;br /&gt;
FYI: By default, Oracle configures a small Reserved Pool (or Reserved Area) inside the Shared Pool.&lt;br /&gt;
This memory can be used for operations such as PL/SQL and trigger compilation or for temporary space while loading Java objects.&lt;br /&gt;
After the memory allocated from the Reserved Pool is freed, it returns to the Reserved Pool.&lt;br /&gt;
5% of the Shared Pool is set aside as the Reserved Pool to handle allocations of memory higher than defined by the hidden parameter _shared_pool_reserved_pct.&lt;br /&gt;
In some application environments, 5% is too small.&lt;br /&gt;
&lt;br /&gt;
3. Set shared_pool_size=500M or even more. This will represent a minimum amount of memory that will always be available to the shared pool.&lt;br /&gt;
If more memory is needed at any moment, if it is available, it will be allocated to the shared pool over the 500M.&lt;br /&gt;
&lt;br /&gt;
Implement the above steps, monitor the database and let us know the result,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORA-00392: log 1 of thread 1 is being cleared, operation not allowed===&lt;br /&gt;
After performing an active duplication, this happened when trying to open the database.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SQL&amp;gt; alter database open resetlogs&lt;br /&gt;
alter database open resetlogs&lt;br /&gt;
*&lt;br /&gt;
ERROR at line 1:&lt;br /&gt;
ORA-00392: log 1 of thread 1 is being cleared, operation not allowed&lt;br /&gt;
ORA-00312: online log 1 thread 1: &amp;#039;/oracle/oradata/testdb/redo/redo01.log&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SQL&amp;gt; select group#,thread#,status from v$log;&lt;br /&gt;
 &lt;br /&gt;
GROUP#   THREAD#   STATUS&lt;br /&gt;
-------  --------- ----------------&lt;br /&gt;
1        1         CLEARING_CURRENT&lt;br /&gt;
2        1         STALE&lt;br /&gt;
3        1         STALE&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Check the alert log! Always a good idea to get extra info. In here we find the answer&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ORA-00344: unable to re-create online log&lt;br /&gt;
&amp;#039;/oracle/oradata/testdb/redo/redo01.log&amp;#039;&lt;br /&gt;
ORA-27040: file create error, unable to create file&lt;br /&gt;
Linux-x86_64 Error: 2: No such file or directory&lt;br /&gt;
Additional information: 1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
So the clue is that the file cannot be created at the operating system level.&amp;lt;br /&amp;gt;&lt;br /&gt;
Doing a &amp;lt;code&amp;gt;df -k /oracle/oradata/testdb/redo&amp;lt;/code&amp;gt; shows us that the filesystem was created too small for the destination database.&amp;lt;br /&amp;gt;&lt;br /&gt;
In this case, we do not want the redolog directory to be as big as on the source db as there will be almost no movement on the destination.&amp;lt;br /&amp;gt;&lt;br /&gt;
I should have specified the LOGFILE parameter in the DUPLICATE clause to setup new, smaller redolog files.&amp;lt;br /&amp;gt;&lt;br /&gt;
As this duplicate takes over 12 hours, I didn&amp;#039;t want to do it again so I created symbolic links in the redolog directory pointing out to a larger filesystem with more space.&amp;lt;br /&amp;gt;&lt;br /&gt;
This allowed the creation of the redolog files. They can then be resized once the database has been opened.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cd /oracle/oradata/testdb/redo&lt;br /&gt;
ln -s /tmp/redo01.log redo01.log&lt;br /&gt;
ln -s /tmp/redo02.log redo02.log&lt;br /&gt;
ln -s /tmp/redo03.log redo03.log&lt;br /&gt;
&lt;br /&gt;
SQL&amp;gt; alter database open resetlogs&lt;br /&gt;
Database opened.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===RMAN-04004: error from recovery catalog database: ORA-01017: invalid username/password; logon denied===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
oracle@host:/export/home/ora&amp;gt; rman target / catalog catowner/catpass@catdb&lt;br /&gt;
&lt;br /&gt;
Recovery Manager: Release 11.2.0.2.0 - Production on Thu Jun 12 16:51:03 2014&lt;br /&gt;
&lt;br /&gt;
Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.&lt;br /&gt;
&lt;br /&gt;
connected to target database: XXXXRAP1 (DBID=3557010742)&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-00554: initialization of internal recovery manager package failed&lt;br /&gt;
RMAN-04004: error from recovery catalog database: ORA-01017: invalid username/password; logon denied&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This is normally very straight-forward and self-explanatory.&amp;lt;br /&amp;gt;&lt;br /&gt;
The puzzle here is that a connection from SQL*Plus works!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sqlplus catowner/catpass@catdb&lt;br /&gt;
&lt;br /&gt;
SQL*Plus: Release 11.2.0.2.0 Production on Thu Jun 12 16:53:18 2014&lt;br /&gt;
&lt;br /&gt;
Copyright (c) 1982, 2010, Oracle.  All rights reserved.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Connected to:&lt;br /&gt;
Oracle Database 12c Enterprise Edition Release 12.1.0.1.0 - 64bit Production&lt;br /&gt;
With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options&lt;br /&gt;
SQL&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Eventually worked out that the rman binary in the databases ORACLE_HOME on the source machine needed relinking!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cd $ORACLE_HOME/rdbms/lib&lt;br /&gt;
make -f ins_rdbms.mk irman &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORA-00230: operation disallowed: snapshot control file enqueue unavailable===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
waiting for snapshot control file enqueue&lt;br /&gt;
waiting for snapshot control file enqueue&lt;br /&gt;
waiting for snapshot control file enqueue&lt;br /&gt;
waiting for snapshot control file enqueue&lt;br /&gt;
cannot make a snapshot control file&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-03008: error while performing automatic resync of recovery catalog&lt;br /&gt;
ORA-00230: operation disallowed: snapshot control file enqueue unavailable&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
From the doc...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
When RMAN needs to back up or resynchronize from the control file, it first creates a snapshot or consistent image of the control file.&lt;br /&gt;
If one RMAN job is already backing up the control file while another needs to create a new snapshot control file, then you may see the following message:&lt;br /&gt;
&lt;br /&gt;
waiting for snapshot controlfile enqueue&lt;br /&gt;
&lt;br /&gt;
Under normal circumstances, a job that must wait for the control file enqueue waits for a brief interval and then successfully obtains the enqueue.&lt;br /&gt;
RMAN makes up to five attempts to get the enqueue and then fails the job.&lt;br /&gt;
The conflict is usually caused when two jobs are both backing up the control file, and the job that first starts backing up the control file waits for service from the media manager.&lt;br /&gt;
&lt;br /&gt;
To determine which job is holding the conflicting enqueue:&lt;br /&gt;
&lt;br /&gt;
    After you see the first message stating &amp;quot;RMAN-08512: waiting for snapshot controlfile enqueue&amp;quot;, start a new SQL*Plus session on the target database:&lt;br /&gt;
&lt;br /&gt;
    % sqlplus &amp;#039;SYS/oracle@trgt AS SYSDBA&amp;#039;&lt;br /&gt;
&lt;br /&gt;
    Execute the following query to determine which job is causing the wait:&lt;br /&gt;
&lt;br /&gt;
    SELECT s.SID, USERNAME AS &amp;quot;User&amp;quot;, PROGRAM, MODULE, &lt;br /&gt;
           ACTION, LOGON_TIME &amp;quot;Logon&amp;quot;, l.* &lt;br /&gt;
    FROM V$SESSION s, V$ENQUEUE_LOCK l&lt;br /&gt;
    WHERE l.SID = s.SID&lt;br /&gt;
    AND l.TYPE = &amp;#039;CF&amp;#039;&lt;br /&gt;
    AND l.ID1 = 0&lt;br /&gt;
    AND l.ID2 = 2;&lt;br /&gt;
&lt;br /&gt;
    You should see output similar to the following (the output in this example has been truncated):&lt;br /&gt;
&lt;br /&gt;
    SID User Program              Module                    Action           Logon&lt;br /&gt;
    --- ---- -------------------- ------------------------- ---------------- ---------&lt;br /&gt;
      9 SYS  rman@h13 (TNS V1-V3) backup full datafile: c1  0000210 STARTED  21-JUN-01&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
After you have determined which job is creating the enqueue, you can do one of the following:&lt;br /&gt;
&lt;br /&gt;
    Wait until the job creating the enqueue completes&lt;br /&gt;
    Cancel the current job and restart it after the job creating the enqueue completes&lt;br /&gt;
    Cancel the job creating the enqueue&lt;br /&gt;
&lt;br /&gt;
Commonly, enqueue situations occur when a job is writing to a tape drive, but the tape drive is waiting for a new cassette to be inserted.&lt;br /&gt;
If you start a new job in this situation, then you will probably receive the enqueue message because the first job cannot complete until the new tape is loaded.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or more directly...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 2000&lt;br /&gt;
col killer     for a70&lt;br /&gt;
col program    for a20&lt;br /&gt;
col module     for a20&lt;br /&gt;
col action     for a20&lt;br /&gt;
col logon_time for a20&lt;br /&gt;
select &amp;#039;alter system disconnect session &amp;#039;&amp;#039;&amp;#039;||s.sid||&amp;#039;,&amp;#039;||s.serial#||&amp;#039;&amp;#039;&amp;#039; immediate;&amp;#039; killer&lt;br /&gt;
,      username&lt;br /&gt;
,      program&lt;br /&gt;
,      module&lt;br /&gt;
,      action&lt;br /&gt;
,      logon_time&lt;br /&gt;
from   v$session s&lt;br /&gt;
,      v$enqueue_lock l&lt;br /&gt;
where  l.sid  = s.sid&lt;br /&gt;
and    l.type = &amp;#039;cf&amp;#039;&lt;br /&gt;
and    l.id1  = 0&lt;br /&gt;
and    l.id2  = 2&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORA-19511: non RMAN, but media manager or vendor specific failure, error text:===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-03002: failure of Duplicate Db command at 05/01/2018 14:23:09&lt;br /&gt;
RMAN-05501: aborting duplication of target database&lt;br /&gt;
RMAN-03015: error occurred in stored script Memory Script&lt;br /&gt;
ORA-27191: sbtinfo2 returned error&lt;br /&gt;
Additional information: 3586&lt;br /&gt;
ORA-19511: non RMAN, but media manager or vendor specific failure, error text:&lt;br /&gt;
   Unable to connect to NetWorker server &amp;#039;hn6000.cln.be&amp;#039; because &amp;#039;Authentication error; why = Invalid client credential&amp;#039;. (2:10:79)&lt;br /&gt;
&lt;br /&gt;
Recovery Manager complete.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
If this happens, check to see if the nsr daemon is running...&amp;lt;br /&amp;gt;&lt;br /&gt;
Good system:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/home/oracle&amp;gt; ps -ef | grep nsr&lt;br /&gt;
    root  5701836        1   0   Mar 16      - 13:18 /bin/nsrexecd&lt;br /&gt;
  oracle 18809292 22741502   0 15:03:58  pts/0  0:00 grep nsr&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Bad system:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 /home/oracle&amp;gt; ps -ef | grep nsr&lt;br /&gt;
  oracle 14745986 15139292   0 15:03:29  pts/2  0:00 grep nsr&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORA-19554: error allocating device, device type: SBT_TAPE, device name:===&lt;br /&gt;
If using Cygwin...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-03002: failure of backup command at 05/19/2015 12:25:47&lt;br /&gt;
ORA-19554: error allocating device, device type: SBT_TAPE, device name:&lt;br /&gt;
ORA-27000: skgfqsbi: failed to initialize storage subsystem (SBT) layer&lt;br /&gt;
OSD-02534: Message 2534 not found;  product=RDBMS; facility=SOSD&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Check the tdpo.opt file is where you think it is!&lt;br /&gt;
* Check the path to the opt file looks like this (needs to be Windows format):&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
CONFIGURE CHANNEL DEVICE TYPE &amp;#039;SBT_TAPE&amp;#039; FORMAT   &amp;#039;LOG_%d_t%t_s%s_u%U&amp;#039; PARMS  &amp;#039;ENV=(TDPO_OPTFILE=E:\oracle\KITRYD\admin\tdpo.opt)&amp;#039;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Check the content of the opt file is Windows format paths!&lt;br /&gt;
&lt;br /&gt;
===RMAN-20033: control file SEQUENCE# too low===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-03008: error while performing automatic resync of recovery catalog&lt;br /&gt;
===RMAN-20033: control file SEQUENCE# too low===&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
From [https://forums.oracle.com/forums/thread.jspa?threadID=1115969 forums.oracle.com]&amp;lt;br /&amp;gt;&lt;br /&gt;
This error generally happens if an archivelog backup happens while the RMAN database backup is running and if controlfile autobackup is configured.&amp;lt;br /&amp;gt;&lt;br /&gt;
The database backup is usually successful and it is just the controlfile backup that fails.&lt;br /&gt;
===ORA-27302: failure occurred at: slgpn===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
RMAN-03009: failure of Control File and SPFILE Autobackup command on c1 channel at 06/28/2011 18:59:38&lt;br /&gt;
ORA-19715: invalid format %b for generated name&lt;br /&gt;
ORA-27302: failure occurred at: slgpn&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Problem====&lt;br /&gt;
When doing a &amp;quot;&amp;lt;tt&amp;gt;backup as copy database&amp;lt;/tt&amp;gt;&amp;quot;, got these errors after 145 of 147 datafiles had been backed up!&lt;br /&gt;
&lt;br /&gt;
====Investigation====&lt;br /&gt;
I had read [https://oracleedge.wordpress.com/2011/06/29/oracle-rman-03009-ora-19715-ora-27302/ elsewhere] that this could be something to do with the format of the autobackup of the control file so I changed the format as suggested and reran the backup.&amp;lt;br /&amp;gt;&lt;br /&gt;
No luck. It ended exactly the same way after 145 files. I decided to compare the original list of datafiles with those that had been backed up in order to track down the 2 failures. Maybe I could see something odd with them.&amp;lt;br /&amp;gt;&lt;br /&gt;
Sure enough, these 2 files were different... there was a space at the &amp;#039;&amp;#039;&amp;#039;end&amp;#039;&amp;#039;&amp;#039; of the filenames :-)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select &amp;#039;x&amp;#039;||file_name||&amp;#039;x&amp;#039;&lt;br /&gt;
from   dba_data_files&lt;br /&gt;
where  file_name like &amp;#039;% %&amp;#039;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Solution====&lt;br /&gt;
Run the backup of the other 2 datafiles with a different format that did not rely on the filename.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
run {&lt;br /&gt;
    allocate channel c1 device type disk format &amp;#039;/path/to/datafiles/%U&amp;#039;;&lt;br /&gt;
    backup as copy datafile 170;&lt;br /&gt;
    backup as copy datafile 171;&lt;br /&gt;
    backup as copy current controlfile;&lt;br /&gt;
    release channel c1;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The other 145 datafiles were backed up with a format of &amp;#039;/path/to/datafiles/%b&amp;#039; which preserves the filenames so all that needs to be done is rename the other 2 after the backup finishes.&amp;lt;br /&amp;gt;&lt;br /&gt;
If they are going to be used in a restore scenario, they should be renamed in the controlfile also.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter database rename file &amp;#039;/path/to/datafiles/filename_with_a_space_at_end &amp;#039; to &amp;#039;/path/to/datafiles/filename_without_a_space&amp;#039;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===RMAN errors after crosscheck backup and delete noprompt obsolete and delete noprompt expired backup===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
RMAN-06207: WARNING: 3921 objects could not be deleted for SBT_TAPE channel(s) due&lt;br /&gt;
RMAN-06208:          to mismatched status.  Use CROSSCHECK command to fix status&lt;br /&gt;
RMAN-06210: List of Mismatched objects&lt;br /&gt;
RMAN-06211: ==========================&lt;br /&gt;
RMAN-06212:   Object Type   Filename/Handle&lt;br /&gt;
RMAN-06213: --------------- ---------------------------------------------------&lt;br /&gt;
RMAN-06214: Backup Piece    DB_SID_t20140316_s263889_umhp3bpa7_1_1&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Use the FORCE option with the DELETE command&amp;lt;br /&amp;gt;&lt;br /&gt;
The FORCE command tells RMAN to clean the information out of the catalog regardless of whether it can find it on the media or not.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
delete force noprompt expired backup;&lt;br /&gt;
delete force noprompt obsolete;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===RMAN-06004: ORACLE error from recovery catalog database: RMAN-20003: target database incarnation not found in recovery catalog===&lt;br /&gt;
====Problem:====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-03002: failure of Duplicate Db command at 12/05/2017 11:11:15&lt;br /&gt;
RMAN-05501: aborting duplication of target database&lt;br /&gt;
RMAN-03015: error occurred in stored script Memory Script&lt;br /&gt;
RMAN-06004: ORACLE error from recovery catalog database: RMAN-20003: target database incarnation not found in recovery catalog&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Solution:====&lt;br /&gt;
Strangely, this means, in my particular case, that block change tracking is turned on in the target databse and needs turning off in the auxiliary while the DUPLICATE is running.&amp;lt;br /&amp;gt;&lt;br /&gt;
It must be done while the auxiliary is in mount mode and restoring the datafiles (before recovery starts)&amp;lt;br /&amp;gt;&lt;br /&gt;
It is reported to be a bug fixed in 11.1 but somehow, we&amp;#039;re still (sometimes) getting it in 12.1.0.2.&lt;br /&gt;
&lt;br /&gt;
===RMAN-06059: expected archived log not found, loss of archived log compromises recoverability===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
RMAN-06059: expected archived log not found, loss of archived log compromises recoverability&lt;br /&gt;
ORA-19625: error identifying file &amp;lt;filename&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This error can come from the fact that the database files (more likely archivelogs) are being deleted by the operating system so RMAN has no clue of their whereabouts.&amp;lt;br /&amp;gt;&lt;br /&gt;
Possibly result of a database duplication and the catalog has not updated properly?&amp;lt;br /&amp;gt;&lt;br /&gt;
====Solution====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
crosscheck archivelog all;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
And then maybe take a backup to be on the safe side.&lt;br /&gt;
&lt;br /&gt;
===RMAN-05537: DUPLICATE without TARGET connection when auxiliary instance is started with spfile cannot use SPFILE clause===&lt;br /&gt;
====Problem:====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-03002: failure of Duplicate Db command at 12/05/2017 14:17:49&lt;br /&gt;
RMAN-05501: aborting duplication of target database&lt;br /&gt;
RMAN-05537: DUPLICATE without TARGET connection when auxiliary instance is started with spfile cannot use SPFILE clause&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Usually happens after restarting a failed RMAN DUPLICATE database. The spfile has been regenerated on the auxiliary to a level where it has too much detail in it.&lt;br /&gt;
====Solution:====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ cd $ORACLE_HOME/dbs&lt;br /&gt;
$ ls -altr *dwh_perf*&lt;br /&gt;
-rw-r-----    1 oracle   oinstall   17645568 Aug  3 13:34 snapcf_dwh_perf.f&lt;br /&gt;
-rw-r-----    1 oracle   oinstall       7680 Nov  4 09:22 orapwdwh_perf&lt;br /&gt;
-rw-r--r--    1 oracle   oinstall        104 Dec  5 09:34 initdwh_perf.ora&lt;br /&gt;
-rw-r-----    1 oracle   oinstall       6656 Dec  5 11:11 spfiledwh_perf.ora&lt;br /&gt;
-rw-rw----    1 oracle   oinstall       1544 Dec  5 14:18 hc_dwh_perf.dat&lt;br /&gt;
$ mv hc_dwh_perf.dat hc_dwh_perf.dat.old&lt;br /&gt;
$ mv spfiledwh_perf.ora spfiledwh_perf.ora.old&lt;br /&gt;
$ cat initdwh_perf.ora&lt;br /&gt;
sga_max_size=&amp;#039;6G&amp;#039;&lt;br /&gt;
sga_target=&amp;#039;6G&amp;#039;&lt;br /&gt;
compatible=&amp;#039;12.0.0&amp;#039;&lt;br /&gt;
db_files=&amp;#039;500&amp;#039;&lt;br /&gt;
&lt;br /&gt;
# Instance name&lt;br /&gt;
db_name=dwh_perf&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Re-run the DUPLICATE. It should zoom past the already recovered datafiles.&lt;br /&gt;
&lt;br /&gt;
===PSDRPC returns significant error 1013===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
archived log thread=1 sequence=195008&lt;br /&gt;
channel t2: reading from backup piece arclog_LBK_4260753020_946042770_479194_1&lt;br /&gt;
channel t0: piece handle=arclog_LBK_4260753020_946042770_479192_1 tag=TAG20170607T133757&lt;br /&gt;
channel t0: restored backup piece 1&lt;br /&gt;
channel t0: restore complete, elapsed time: 00:00:35&lt;br /&gt;
archived log file name=/xxxxxx/acc/ora_bin2/app/oracle/product/11.2.0.4/dbhome_1/dbs/arch1_195006_815790039.dbf thread=1 sequence=195006&lt;br /&gt;
PSDRPC returns significant error 1013.&lt;br /&gt;
PSDRPC returns significant error 1013.&lt;br /&gt;
released channel: t0&lt;br /&gt;
released channel: t1&lt;br /&gt;
released channel: t2&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-03002: failure of Duplicate Db command at 06/09/2017 15:15:04&lt;br /&gt;
RMAN-05501: aborting duplication of target database&lt;br /&gt;
RMAN-03015: error occurred in stored script Memory Script&lt;br /&gt;
RMAN-11003: failure during parse/execution of SQL statement: alter database recover logfile &amp;#039;/xxxxxx/acc/ora_bin2/app/oracle/product/11.2.0.4/dbhome_1/dbs/arch1_195006_815790039.dbf&amp;#039;&lt;br /&gt;
ORA-10877: error signaled in parallel recovery slave&lt;br /&gt;
&lt;br /&gt;
Recovery Manager complete.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Action====&lt;br /&gt;
Check the alert log on the auxiliary instance.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ORA-279 signalled during: alter database recover logfile &amp;#039;/xxxxxx/acc/ora_bin2/app/oracle/product/11.2.0.4/dbhome_1/dbs/arch1_195005_815790039.dbf&amp;#039;...&lt;br /&gt;
alter database recover logfile &amp;#039;/xxxxxx/acc/ora_bin2/app/oracle/product/11.2.0.4/dbhome_1/dbs/arch1_195006_815790039.dbf&amp;#039;&lt;br /&gt;
Media Recovery Log /xxxxxx/acc/ora_bin2/app/oracle/product/11.2.0.4/dbhome_1/dbs/arch1_195006_815790039.dbf&lt;br /&gt;
Fri Jun 09 07:30:30 2017&lt;br /&gt;
Errors with log /xxxxxx/acc/ora_bin2/app/oracle/product/11.2.0.4/dbhome_1/dbs/arch1_195006_815790039.dbf&lt;br /&gt;
Recovery interrupted!&lt;br /&gt;
Recovered data files to a consistent state at change 238029030495&lt;br /&gt;
Media Recovery failed with error 19755&lt;br /&gt;
Errors in file /xxxxxx/acc/ora_bin2/app/oracle/diag/rdbms/lbkro/lbkro/trace/lbkro_pr00_13108374.trc:&lt;br /&gt;
ORA-00283: recovery session canceled due to errors&lt;br /&gt;
===&amp;gt;ORA-19755: could not open change tracking file&lt;br /&gt;
===&amp;gt;ORA-19750: change tracking file: &amp;#039;/xxxxxx/exp/ora_data2/lbk/data/bct_lbk_do_not_delete.f&lt;br /&gt;
===&amp;gt;ORA-27037: unable to obtain file status&lt;br /&gt;
===&amp;gt;IBM AIX RISC System/6000 Error: 2: No such file or directory&lt;br /&gt;
Additional information: 3&lt;br /&gt;
Fri Jun 09 07:30:36 2017&lt;br /&gt;
ORA-10877 signalled during: alter database recover logfile &amp;#039;/xxxxxx/acc/ora_bin2/app/oracle/product/11.2.0.4/dbhome_1/dbs/arch1_195006_815790039.dbf&amp;#039;...&lt;br /&gt;
Fri Jun 09 14:04:57 2017&lt;br /&gt;
alter database recover logfile &amp;#039;/xxxxxx/acc/ora_bin2/app/oracle/product/11.2.0.4/dbhome_1/dbs/arch1_195006_815790039.dbf&amp;#039;&lt;br /&gt;
Media Recovery Log /xxxxxx/acc/ora_bin2/app/oracle/product/11.2.0.4/dbhome_1/dbs/arch1_195006_815790039.dbf&lt;br /&gt;
Media Recovery failed with error 1112&lt;br /&gt;
ORA-283 signalled during: alter database recover logfile &amp;#039;/xxxxxx/acc/ora_bin2/app/oracle/product/11.2.0.4/dbhome_1/dbs/arch1_195006_815790039.dbf&amp;#039;...&lt;br /&gt;
Fri Jun 09 14:31:20 2017&lt;br /&gt;
Shutting down instance (immediate)&lt;br /&gt;
Shutting down instance: further logons disabled&lt;br /&gt;
Stopping background process MMNL&lt;br /&gt;
Stopping background process MMON&lt;br /&gt;
License high water mark = 49&lt;br /&gt;
ALTER DATABASE CLOSE NORMAL&lt;br /&gt;
ORA-1109 signalled during: ALTER DATABASE CLOSE NORMAL...&lt;br /&gt;
ALTER DATABASE DISMOUNT&lt;br /&gt;
Shutting down archive processes&lt;br /&gt;
Archiving is disabled&lt;br /&gt;
Completed: ALTER DATABASE DISMOUNT&lt;br /&gt;
ARCH: Archival disabled due to shutdown: 1089&lt;br /&gt;
Shutting down archive processes&lt;br /&gt;
Archiving is disabled&lt;br /&gt;
ARCH: Archival disabled due to shutdown: 1089&lt;br /&gt;
Shutting down archive processes&lt;br /&gt;
Archiving is disabled&lt;br /&gt;
Fri Jun 09 14:31:24 2017&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This is a known bug. it is fixed in 11.2.0.3 but... this customer does not apply patches!&lt;br /&gt;
&lt;br /&gt;
====Solution====&lt;br /&gt;
While the DUPLICATE is running (and in MOUNT mode), log on to the auxiliary instance and disable block change tracking.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter database disable block change tracking;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
A documented workaround is to set db_filename_convert parameter in the DUPLICATE clause of the run block but I tried this and it failed again.&amp;lt;br /&amp;gt;&lt;br /&gt;
The obvious solution is to patch the database but...&lt;br /&gt;
&lt;br /&gt;
===Database trigger to capture ORA errors===&lt;br /&gt;
From [http://ora-ssn.blogspot.be/2011/10/trigger-on-database-to-capture-ora.html ora-ssn.blogspot.be]&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
CREATE TABLE stats$error_log (&lt;br /&gt;
        err_dt          TIMESTAMP,&lt;br /&gt;
        db_user         VARCHAR2(30),&lt;br /&gt;
        msg_stack       VARCHAR2(2000),&lt;br /&gt;
        sqltxt          VARCHAR2(1000))&lt;br /&gt;
tablespace users;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Now, create a trigger on the database server.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
CREATE OR REPLACE TRIGGER log_server_errors&lt;br /&gt;
  AFTER SERVERERROR&lt;br /&gt;
  ON DATABASE&lt;br /&gt;
DECLARE&lt;br /&gt;
          v_sqltext VARCHAR2(1000);&lt;br /&gt;
          nl_sqltext ora_name_list_t;&lt;br /&gt;
  BEGIN&lt;br /&gt;
          -- Capture entire error text&lt;br /&gt;
          FOR i IN 1 .. ora_sql_txt(nl_sqltext) LOOP&lt;br /&gt;
            v_sqltext := v_sqltext || nl_sqltext(i);&lt;br /&gt;
          END LOOP;&lt;br /&gt;
          INSERT INTO STATS$ERROR_LOG&lt;br /&gt;
          (err_dt, db_user, msg_stack, sqltxt)&lt;br /&gt;
          VALUES&lt;br /&gt;
          (systimestamp,&lt;br /&gt;
           sys.login_user,&lt;br /&gt;
           dbms_utility.format_error_stack, v_sqltext);&lt;br /&gt;
  END log_server_errors;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORA-19809: limit exceeded for recovery files===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-03009: failure of backup command on ORA_DISK_1 channel at 07/15/2013 10:10:59&lt;br /&gt;
ORA-19809: limit exceeded for recovery files&lt;br /&gt;
ORA-19804: cannot reclaim 274716160 bytes disk space from 1468006400 limit&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    ORA-19809: limit exceeded for recovery files&lt;br /&gt;
    Cause: The limit for recovery files specified by the db_recovery_file_dest_size was exceeded.&lt;br /&gt;
&lt;br /&gt;
    Action: The error is accompanied by 19804. See message 19804 for further details&lt;br /&gt;
&lt;br /&gt;
    ORA-19804: cannot reclaim string bytes disk space from string limit&lt;br /&gt;
    Cause: Oracle cannot reclaim disk space of specified bytes from the DB_RECOVERY_FILE_DEST_SIZE limit.&lt;br /&gt;
&lt;br /&gt;
    Action: There are five possible solutions:&lt;br /&gt;
       1) Take frequent backup of recovery area using RMAN.&lt;br /&gt;
       2) Consider changing RMAN retention policy.&lt;br /&gt;
       3) Consider changing RMAN archivelog deletion policy.&lt;br /&gt;
       4) Add disk space and increase DB_RECOVERY_FILE_DEST_SIZE.&lt;br /&gt;
       5) Delete files from recovery area using RMAN.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The solution here is to increase the value of db_recovery_file_dest_size but it might also indicate a problem with tapes if the archivelogs are being backed up to tape via tdpo.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SYS@DN7&amp;gt; alter system set db_recovery_file_dest_size=4000M scope=both;&lt;br /&gt;
&lt;br /&gt;
System altered.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Looking into int further, saw RMAN parameters missing...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
CONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF 14 DAYS;&lt;br /&gt;
CONFIGURE BACKUP OPTIMIZATION OFF;&lt;br /&gt;
CONFIGURE DEFAULT DEVICE TYPE TO &amp;#039;SBT_TAPE&amp;#039;;&lt;br /&gt;
CONFIGURE CONTROLFILE AUTOBACKUP ON;&lt;br /&gt;
CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE &amp;#039;SBT_TAPE&amp;#039; TO &amp;#039;LOG_%d_controlfile_%F.rman&amp;#039;;&lt;br /&gt;
CONFIGURE DEVICE TYPE &amp;#039;SBT_TAPE&amp;#039; PARALLELISM 1 BACKUP TYPE TO BACKUPSET;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===RMAN-00554: initialization of internal recovery manager package failed===&lt;br /&gt;
Getting this error after migrating a database from one machine to another and attaching to a nice new version 12c catalog on the new server&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Recovery Manager: Release 11.2.0.2.0 - Production on Sat Jun 21 13:16:24 2014&lt;br /&gt;
&lt;br /&gt;
Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.&lt;br /&gt;
&lt;br /&gt;
connected to target database: SPMSUPP1 (DBID=3026014394)&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-00554: initialization of internal recovery manager package failed&lt;br /&gt;
RMAN-04004: error from recovery catalog database: ORA-01017: invalid username/password; logon denied&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
We cannot connect to the catalog via rman but there is no problem if connecting via SQL*Plus!&amp;lt;br /&amp;gt;&lt;br /&gt;
Solution: relink the rman executable.&lt;br /&gt;
===Using AIX commands genld, genkld and slibclean to avoid library file locking errors (libjox) (Doc ID 739963.1)===&lt;br /&gt;
* [https://support.oracle.com/epmos/faces/DocumentDisplay?_afrLoop=206851390914720&amp;amp;id=739963.1&amp;amp;_afrWindowMode=0&amp;amp;_adf.ctrl-state=e0pq23tou_4 Metalink]&lt;br /&gt;
When installing interim (one-off) patches, CPU patches or patchsets, you may encounter some errors with regards to files being locked or oui/opatch being unable to copy files&amp;lt;br /&amp;gt;&lt;br /&gt;
even though the databases, listeners and all other Oracle processes associated with the ORACLE_HOME to be patched were stopped.&amp;lt;br /&amp;gt;&lt;br /&gt;
This could be as result of a process which requires termination or an additional file needing to be unloaded from the system cache.&amp;lt;br /&amp;gt;&lt;br /&gt;
Run following commands to clean up...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
genld -l | grep &amp;lt;ORACLE_HOME&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
If genld returns data then a currently executing process has something open in the ORACLE_HOME directory, therefore terminate the process as required/recommended.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
genkld | grep &amp;lt;ORACLE_HOME&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
If the genkld command  returns a  list of shared objects currently loaded onto the OS system cache then please remove the entries from the OS system cache by running the slibclean command as root user:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/usr/sbin/slibclean&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===ORA-20011: Approximate NDV failed: ORA-29913: error in executing ODCIEXTTABLEOPEN callout===&lt;br /&gt;
This seems to be related to orphaned Datapump tables. Generally seems to be a problem when stats jobs are running during the night (dbms_stats)&amp;lt;br /&amp;gt;&lt;br /&gt;
* Check no datapump jobs are running&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select * from dba_datapump_jobs;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Find orphaned tables&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 2000&lt;br /&gt;
select owner&lt;br /&gt;
,      object_name&lt;br /&gt;
,      object_type&lt;br /&gt;
,      status&lt;br /&gt;
,      to_char(created,&amp;#039;dd-mon-yyyy hh24:mi:ss&amp;#039;) created&lt;br /&gt;
,      to_char(last_ddl_time,&amp;#039;dd-mon-yyyy hh24:mi:ss&amp;#039;) last_ddl_time&lt;br /&gt;
from   dba_objects&lt;br /&gt;
where  1=1&lt;br /&gt;
and    object_name like &amp;#039;ET$%&amp;#039;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Check that  any rows seen are actually external tables&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select owner&lt;br /&gt;
,      table_name&lt;br /&gt;
,      default_directory_name&lt;br /&gt;
,      access_type&lt;br /&gt;
from   dba_external_tables&lt;br /&gt;
order  by 1,2&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Drop the tables if they are not currently being used (no datapump jobs running)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
drop table &amp;amp;&amp;amp;owner..&amp;amp;table_name;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===ORA-01547: warning: RECOVER succeeded but OPEN RESETLOGS would get error below===&lt;br /&gt;
Database is restored and now we want to recover it but we see this...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Starting recover at 24-JUL-15 11:26:19&lt;br /&gt;
&lt;br /&gt;
starting media recovery&lt;br /&gt;
&lt;br /&gt;
unable to find archive log&lt;br /&gt;
archive log thread=1 sequence=69763&lt;br /&gt;
Oracle Error: &lt;br /&gt;
ORA-01547: warning: RECOVER succeeded but OPEN RESETLOGS would get error below&lt;br /&gt;
ORA-01194: file 1 needs more recovery to be consistent&lt;br /&gt;
ORA-01110: data file 1: &amp;#039;/oracle/TRSCRP1/oradata2/system01.dbf&amp;#039;&lt;br /&gt;
&lt;br /&gt;
released channel: c1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This means that although we have restored the database, we are still missing information to complete the recovery. This information is contained in the archived redo logs which must also be restored (from tape if they are no longer on disk)&amp;lt;br /&amp;gt;&lt;br /&gt;
We can see here that we need an archive log with sequence number 69763. But what is the file called and where should it be restored to?&amp;lt;br /&amp;gt;&lt;br /&gt;
For this we can go to SQL*Plus and get the database to tell us&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
recover database using backup controlfile until cancel;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
and cancel straight away.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ORA-00279: change 13796376414661 generated at 07/14/2015 13:20:07 needed for&lt;br /&gt;
thread 1&lt;br /&gt;
ORA-00289: suggestion : /oracle/TRSCRP1/archive/arch_TRSCRP1_1_69763.arc&lt;br /&gt;
ORA-00280: change 13796376414661 for thread 1 is in sequence #69763&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Specify log: {&amp;lt;RET&amp;gt;=suggested | filename | AUTO | CANCEL}&lt;br /&gt;
cancel&lt;br /&gt;
ORA-01547: warning: RECOVER succeeded but OPEN RESETLOGS would get error below&lt;br /&gt;
ORA-01194: file 1 needs more recovery to be consistent&lt;br /&gt;
ORA-01110: data file 1: &amp;#039;/oracle/TRSCRP1/oradata2/system01.dbf&amp;#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
ORA-01112: media recovery not started&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Now we see that we need to find a file called arch_TRSCRP1_1_69763.arc and put it in the directory /oracle/TRSCRP1/archive.&amp;lt;br /&amp;gt;&lt;br /&gt;
This will continue up until the time specified for the recover so restore a whole bunch of them.&amp;lt;br /&amp;gt;&lt;br /&gt;
Repeat the &amp;quot;recover database using backup controlfile until cancel;&amp;quot; command and type AUTO or Enter until you&amp;#039;ve got to where you need to be.&amp;lt;br /&amp;gt;&lt;br /&gt;
Type CANCEL when point is reached and&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter database open resetlogs;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Stuart</name></author>	</entry>

	<entry>
		<id>https://mailnest.com/dbawiki/index.php?title=Oracle_errors&amp;diff=3359</id>
		<title>Oracle errors</title>
		<link rel="alternate" type="text/html" href="https://mailnest.com/dbawiki/index.php?title=Oracle_errors&amp;diff=3359"/>
				<updated>2018-11-03T16:21:25Z</updated>
		
		<summary type="html">&lt;p&gt;Stuart: /* Solution */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;===ORA-00600===&lt;br /&gt;
[https://support.oracle.com/epmos/faces/DocContentDisplay?_afrLoop=397490397952859&amp;amp;id=1092832.1&amp;amp;_afrWindowMode=0&amp;amp;_adf.ctrl-state=184vwc6g3y_4 Master Note for Diagnosing ORA-600 (Doc ID 1092832.1)]&lt;br /&gt;
===ORA-19051: Cannot use fast path insert for this XMLType table===&lt;br /&gt;
Think LD_LIBRARY_PATH on Linux or LIBPATH on AIX.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Export: Release 11.2.0.4.0 - Production on Thu Jun 1 06:41:55 2017&lt;br /&gt;
&lt;br /&gt;
Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.&lt;br /&gt;
&lt;br /&gt;
Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production&lt;br /&gt;
With the Partitioning, OLAP, Data Mining and Real Application Testing options&lt;br /&gt;
Starting &amp;quot;DWH_EXPORT&amp;quot;.&amp;quot;SYS_EXPORT_TABLE_03&amp;quot;:  dwh_export/******** parfile=cadis_foto_export_credit_dba.par&lt;br /&gt;
Estimate in progress using BLOCKS method...&lt;br /&gt;
Processing object type TABLE_EXPORT/TABLE/TABLE_DATA&lt;br /&gt;
Total estimation using BLOCKS method: 64.08 GB&lt;br /&gt;
ORA-39126: Worker unexpected fatal error in KUPW$WORKER.FETCH_XML_OBJECTS []&lt;br /&gt;
ORA-19051: Cannot use fast path insert for this XMLType table&lt;br /&gt;
&lt;br /&gt;
ORA-06512: at &amp;quot;SYS.DBMS_SYS_ERROR&amp;quot;, line 86&lt;br /&gt;
ORA-06512: at &amp;quot;SYS.KUPW$WORKER&amp;quot;, line 9710&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Problem====&lt;br /&gt;
When the 11g DB was started, LD_LIBRARY_PATH and LIBPATH were still pointing to paths in the 10g Home.&lt;br /&gt;
====Solution====&lt;br /&gt;
There may have been some odd values setup in LD_LIBRARY_PATH before the call to oraenv (if oraenv was indeed called!)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
unset LD_LIBRARY_PATH LIBPATH&lt;br /&gt;
export ORACLE_SID=&amp;lt;correct 11g SID&amp;gt;&lt;br /&gt;
. oraenv&lt;br /&gt;
echo $LD_LIBRARY_PATH&lt;br /&gt;
echo $LIBPATH&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
They should now be correct.&lt;br /&gt;
&lt;br /&gt;
===ORA-27092: size of file exceeds file size limit of the process===&lt;br /&gt;
Think ulimit...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Cause: an attempt was made to open a file that exceeds the process&amp;#039;s file size limit (ulimit), additional information shows the current limit (logical blocks) and the size of the file (logical blocks)&lt;br /&gt;
Action: increase the processes file size limit (ulimit) and retry&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
truncate table pibadm.test_ph&lt;br /&gt;
                      *&lt;br /&gt;
Error at line 1 :&lt;br /&gt;
ORA-00604: error ocurred at recursive SQL level 1&lt;br /&gt;
ORA-01116: error in opening database file 2&lt;br /&gt;
ORA-01110: datafile 2 : &amp;#039;/opt/u01/data/PIBQA/UNDO_01.dbf&amp;#039;&lt;br /&gt;
ORA-27092: size of file exceeds file size limit of the process&lt;br /&gt;
Additional information: 262143&lt;br /&gt;
Additional information: 2621441&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Check the fs_size limit for this user in /etc/security/limits&amp;lt;br /&amp;gt;&lt;br /&gt;
Compare this with another user, say oracle. Probably -1 (unlimited)&lt;br /&gt;
&lt;br /&gt;
===SP2-1503: Unable to initialize Oracle call interface===&lt;br /&gt;
When trying to login to the database via SQL*Plus, these messages a displayed&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
hn5118 /home/oracle $sqlplus / as sysdba&lt;br /&gt;
SP2-1503: Unable to initialize Oracle call interface&lt;br /&gt;
SP2-0152: ORACLE may not be functioning properly&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Seems to be a problem unique to AIX (in this case).&amp;lt;br /&amp;gt;&lt;br /&gt;
Check to see what the LIBPATH variable is. It may still contain a path to an old ORACLE_HOME...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
hn5118 /home/oracle $env|grep LIBPATH&lt;br /&gt;
LIBPATH=/oracle/exp/ora_bin1/app/oracle/product/10.2.0/db_1/lib:/oracle/exp/ora_bin1/app/oracle/product/10.2.0/db_1/lib&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Disco! Unset it and rerun.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
hn5118 /home/oracle $unset LIBPATH&lt;br /&gt;
&lt;br /&gt;
hn5118 /home/oracle $sqlplus / as sysdba&lt;br /&gt;
&lt;br /&gt;
SQL*Plus: Release 12.1.0.2.0 Production on Wed Jul 12 17:17:54 2017&lt;br /&gt;
&lt;br /&gt;
Copyright (c) 1982, 2014, Oracle.  All rights reserved.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Connected to:&lt;br /&gt;
Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production&lt;br /&gt;
With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options&lt;br /&gt;
&lt;br /&gt;
SQL&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===UDE-31623: operation generated ORACLE error 31623===&lt;br /&gt;
When using Data pump, get following errors almost immediately:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
UDE-31623: operation generated ORACLE error 31623&lt;br /&gt;
ORA-31623: a job is not attached to this session via the specified handle&lt;br /&gt;
ORA-06512: at &amp;quot;SYS.DBMS_DATAPUMP&amp;quot;, line 3326&lt;br /&gt;
ORA-06512: at &amp;quot;SYS.DBMS_DATAPUMP&amp;quot;, line 4551&lt;br /&gt;
ORA-06512: at line 1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Solution 1:&amp;#039;&amp;#039;&amp;#039;&amp;lt;br /&amp;gt;&lt;br /&gt;
In one case, I simplified the parameter file that was used. Maybe related to Streams Pool size, who knows?!&amp;lt;br /&amp;gt;&lt;br /&gt;
I removed these 2 lines and the export started working:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
compression_algorithm=medium&lt;br /&gt;
logtime=all&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Solution 2:&amp;#039;&amp;#039;&amp;#039;&amp;lt;br /&amp;gt;&lt;br /&gt;
There is a note about this on Metalink, 1080775.1 which suggests that Streams Pool Size needs setting.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
For this DataPump error, you will need to configure the database with some Streams Pool.&lt;br /&gt;
&lt;br /&gt;
Perform the following query to find out how much STREAMS_POOL_SIZE has been allocated&lt;br /&gt;
&lt;br /&gt;
 select * from v$sgainfo;&lt;br /&gt;
 ...&lt;br /&gt;
 Streams Pool Size                               0 Yes&lt;br /&gt;
&lt;br /&gt;
Data Pump now uses Advanced Queuing (AQ) internally, so it can handle job stops/starts/re-starts.  However, AQ using the Streams Pool, where the database currently has the STREAMS_POOL_SIZE set to ZERO.&lt;br /&gt;
&lt;br /&gt;
Manually set the STREAMS_POOL_SIZE (using ALTER SYSTEM or by changing the value in the the PFILE/SPFILE), re-start the database and re-attempt the Data Pump Export.&lt;br /&gt;
&lt;br /&gt;
Alternately, turn on Automatic Shared Memory management (ASMM) by setting SGA_TARGET or MEMORY_TARGET.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
From Oracle Documentation&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Setting the Size Of the Buffer Cache In a Streams Environment&lt;br /&gt;
&lt;br /&gt;
Oracle Data Pump uses Streams functionality to communicate between processes.&lt;br /&gt;
If the SGA_TARGET initialization parameter is set, then the STREAMS_POOL_SIZE initialization parameter is automatically set to a reasonable value.&lt;br /&gt;
If the SGA_TARGET initialization parameter is not set and the STREAMS_POOL_SIZE initialization parameter is not defined,&lt;br /&gt;
then the size of the streams pool automatically defaults to 10% of the size of the shared pool.&lt;br /&gt;
&lt;br /&gt;
When the streams pool is created, the required SGA memory is taken from memory allocated to the buffer cache,&lt;br /&gt;
reducing the size of the cache to less than what was specified by the DB_CACHE_SIZE initialization parameter.&lt;br /&gt;
This means that if the buffer cache was configured with only the minimal required SGA, then Data Pump operations may not work properly.&lt;br /&gt;
A minimum size of 10M is recommended for STREAMS_POOL_SIZE in order to ensure successful Data Pump operations.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORA-00020: maximum number of processes (150) exceeded===&lt;br /&gt;
Check the current resource limits with:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 300&lt;br /&gt;
select * from v$resource_limit;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Unfortunately this limit cannot be increased without a restart.&amp;lt;br /&amp;gt;&lt;br /&gt;
It may be a necessary to increase the limit with&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter system set processes=500 scope=spfile;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
followed by a shutdown/startup&amp;lt;br /&amp;gt;&lt;br /&gt;
Or it may be some user is running away with the limit.&amp;lt;br /&amp;gt;&lt;br /&gt;
Check to see who is running what with:&lt;br /&gt;
[[http://www.mailnest.com/dbawiki/index.php/Handy_scripts#See_what_statements_all_users_are_running See_what_statements_all_users_are_running]]&lt;br /&gt;
===ORA-01555: snapshot too old: rollback segment number nn with name &amp;quot;xxx&amp;quot; too small===&lt;br /&gt;
* [http://dfitzjarrell.wordpress.com/2008/02/22/the-dreaded-ora-01555/ Good explanation of why it happens]&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
====Problem====&lt;br /&gt;
A long running transaction has run out of space to store its read-consistent image&lt;br /&gt;
&lt;br /&gt;
====Solution 1====&lt;br /&gt;
If it&amp;#039;s a one-off, maybe leave it alone. It may have been a user leaving a session open overnight without committing or rolling back.&lt;br /&gt;
&lt;br /&gt;
====Solution 2====&lt;br /&gt;
Make sure there&amp;#039;s enough space to allow the transaction to finish.&lt;br /&gt;
&lt;br /&gt;
====Things to check====&lt;br /&gt;
How much undo did the biggest transaction take?&lt;br /&gt;
What is the undo retention parameter set to?&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 200&lt;br /&gt;
col name        for a30&lt;br /&gt;
col description for a50&lt;br /&gt;
col value       for a20&lt;br /&gt;
col maxquerylen for 999999&lt;br /&gt;
select p.name&lt;br /&gt;
,      p.description&lt;br /&gt;
,      p.value&lt;br /&gt;
,      max(u.maxquerylen) maxquerylen&lt;br /&gt;
from   v$parameter p&lt;br /&gt;
,      v$undostat  u&lt;br /&gt;
where  1=1&lt;br /&gt;
and    p.name = &amp;#039;undo_retention&amp;#039;&lt;br /&gt;
group  by p.name&lt;br /&gt;
,      p.description&lt;br /&gt;
,      p.value;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Set the retention to about 20% bigger than the maxquerylen.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select &amp;#039;alter system set undo_retention=&amp;#039;||round(1.2*max(maxquerylen))||&amp;#039; scope=both;&amp;#039; &amp;quot;Run this&amp;quot; from v$undostat;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
and set the undo retention guarantee (being aware of the consequences)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select tablespace_name&lt;br /&gt;
,      retention&lt;br /&gt;
from   dba_tablespaces;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter tablespace &amp;amp;undo_ts_name retention guarantee;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Optimise Oracle UNDO Parameters===&lt;br /&gt;
&lt;br /&gt;
The ideal undo_retention would be enough to hold rollback for the longest transaction that happened so far (can&amp;#039;t see into the future)&amp;lt;br /&amp;gt;&lt;br /&gt;
So current undo_retention = current value of undo / (db_block_size * undo blocks per sec)&amp;lt;br /&amp;gt;&lt;br /&gt;
* Undo Blocks per Second&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SELECT MAX(undoblks/((end_time-begin_time)*3600*24)) &amp;quot;UNDO_BLOCKS_PER_SEC&amp;quot;&lt;br /&gt;
FROM   v$undostat;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Optimal Undo Retention&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
col actual for 9999999999.99 heading &amp;quot;ACTUAL UNDO SIZE [MByte]&amp;quot;&lt;br /&gt;
col retent for 9999999999    heading &amp;quot;UNDO RETENTION [Sec]&amp;quot;&lt;br /&gt;
col needed for 9999999999.99 heading &amp;quot;NEEDED UNDO SIZE [Secs]&amp;quot;&lt;br /&gt;
&lt;br /&gt;
SELECT d.undo_size/(1024*1024) actual,&lt;br /&gt;
       to_number(SUBSTR(e.value,1,25)) retent,&lt;br /&gt;
       ROUND((d.undo_size / (to_number(f.value) *&lt;br /&gt;
       g.undo_block_per_sec))) needed&lt;br /&gt;
  FROM (&lt;br /&gt;
       SELECT SUM(a.bytes) undo_size&lt;br /&gt;
          FROM v$datafile a,&lt;br /&gt;
               v$tablespace b,&lt;br /&gt;
               dba_tablespaces c&lt;br /&gt;
         WHERE c.contents = &amp;#039;UNDO&amp;#039;&lt;br /&gt;
           AND c.status = &amp;#039;ONLINE&amp;#039;&lt;br /&gt;
           AND b.name = c.tablespace_name&lt;br /&gt;
           AND a.ts# = b.ts#&lt;br /&gt;
       ) d,&lt;br /&gt;
       v$parameter e,&lt;br /&gt;
       v$parameter f,&lt;br /&gt;
       (&lt;br /&gt;
       SELECT MAX(undoblks/((end_time-begin_time)*3600*24))&lt;br /&gt;
              undo_block_per_sec&lt;br /&gt;
         FROM v$undostat&lt;br /&gt;
       ) g&lt;br /&gt;
WHERE e.name = &amp;#039;undo_retention&amp;#039;&lt;br /&gt;
  AND f.name = &amp;#039;db_block_size&amp;#039;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Calculate Needed UNDO Size for given Database Activity&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
col actual for 9999999999.99 heading &amp;quot;ACTUAL UNDO SIZE [MByte]&amp;quot;&lt;br /&gt;
col retent for 9999999999    heading &amp;quot;UNDO RETENTION [Sec]&amp;quot;&lt;br /&gt;
col needed for 9999999999.99 heading &amp;quot;NEEDED UNDO SIZE [MByte]&amp;quot;&lt;br /&gt;
&lt;br /&gt;
SELECT d.undo_size/(1024*1024) actual&lt;br /&gt;
,      to_number(SUBSTR(e.value,1,25)) retent&lt;br /&gt;
,      (TO_NUMBER(e.value) * TO_NUMBER(f.value) *&lt;br /&gt;
       g.undo_block_per_sec) / (1024*1024)  needed&lt;br /&gt;
  FROM (&lt;br /&gt;
       SELECT SUM(a.bytes) undo_size&lt;br /&gt;
         FROM v$datafile a,&lt;br /&gt;
              v$tablespace b,&lt;br /&gt;
              dba_tablespaces c&lt;br /&gt;
        WHERE c.contents = &amp;#039;UNDO&amp;#039;&lt;br /&gt;
          AND c.status = &amp;#039;ONLINE&amp;#039;&lt;br /&gt;
          AND b.name = c.tablespace_name&lt;br /&gt;
          AND a.ts# = b.ts#&lt;br /&gt;
       ) d,&lt;br /&gt;
      v$parameter e,&lt;br /&gt;
       v$parameter f,&lt;br /&gt;
       (&lt;br /&gt;
       SELECT MAX(undoblks/((end_time-begin_time)*3600*24))&lt;br /&gt;
         undo_block_per_sec&lt;br /&gt;
         FROM v$undostat&lt;br /&gt;
       ) g&lt;br /&gt;
 WHERE e.name = &amp;#039;undo_retention&amp;#039;&lt;br /&gt;
  AND f.name = &amp;#039;db_block_size&amp;#039;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
It might be that the Export still fails with ORA-01555 even though retention seems long enough.&amp;lt;br /&amp;gt;&lt;br /&gt;
Are you running an export with the flashback_time parameter? If so, the undo_retention should be longer than the total export running time!&amp;lt;br /&amp;gt;&lt;br /&gt;
===Check LOB undo retention===&lt;br /&gt;
The retention settings for LOBS is different for the rest of the database.&amp;lt;br /&amp;gt;&lt;br /&gt;
When you change the UNDO_RETENTION parameter, the LOB segment’s retention value is NOT modified.&amp;lt;br /&amp;gt;&lt;br /&gt;
If you query the RETENTION column of the DBA_LOBS view, you will notice the old UNDO_RETENTION value still remains after you have modified the UNDO_RETENTION parameter.&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SQL&amp;gt; show parameter undo_&lt;br /&gt;
&lt;br /&gt;
NAME                                 TYPE        VALUE&lt;br /&gt;
------------------------------------ ----------- ------------------------------&lt;br /&gt;
undo_management                      string      AUTO&lt;br /&gt;
undo_retention                       integer     36000&lt;br /&gt;
undo_tablespace                      string      UNDOTBS1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SQL&amp;gt; desc SITEADMIN.AUDIT_LOG_MESSAGE&lt;br /&gt;
 Name                                      Null?    Type&lt;br /&gt;
 ----------------------------------------- -------- ----------------------------&lt;br /&gt;
 AUDIT_LOG_MESSAGE_ID                      NOT NULL NUMBER&lt;br /&gt;
 AUDIT_LOG_ID                              NOT NULL NUMBER&lt;br /&gt;
 SEQUENCE                                           NUMBER&lt;br /&gt;
 MESSAGE                                            CLOB&lt;br /&gt;
 CREATE_DATE                                        TIMESTAMP(6)&lt;br /&gt;
 COMPONENT_ID                                       VARCHAR2(50 CHAR)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 300&lt;br /&gt;
col column_name for a32&lt;br /&gt;
select table_name,column_name, pctversion,retention from dba_lobs where owner=&amp;#039;&amp;amp;table_owner&amp;#039;;&lt;br /&gt;
&lt;br /&gt;
TABLE_NAME                COLUMN_NAME                    PCTVERSION  RETENTION&lt;br /&gt;
------------------------- ------------------------------ ---------- ----------&lt;br /&gt;
EMAIL_STORE               CONTENT                                 0&lt;br /&gt;
EMAIL_STORE_ATTACHEMENT   ATTACHEMENT                             0&lt;br /&gt;
TRACKING                  ORIGINAL_MESSAGE                                 900&lt;br /&gt;
TRACKING                  MESSAGE                                          900&lt;br /&gt;
TRACKING                  SIEBEL_MESSAGE                                   900&lt;br /&gt;
WISE_WMS_LOG              WISE_WMS_XML                                     900&lt;br /&gt;
ATTACHMENT                ORIGINAL_MESSAGE                                 900&lt;br /&gt;
PLAN_TABLE                OTHER_XML                                        900&lt;br /&gt;
AUDIT_LOG_MESSAGE         MESSAGE                                          900&lt;br /&gt;
EXCEPTIONS                STACK_TRACE                                      900&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
To change the LOB segment’s RETENTION value to match the new UNDO_RETENTION value, do the following:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ALTER TABLE my_table MODIFY LOB (lob_column) (PCTVERSION 20);&lt;br /&gt;
ALTER TABLE my_table MODIFY LOB (lob_column) (RETENTION);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
By momentarily changing the LOB to use PCTVERSION and then back to RETENTION, the new value of UNDO_RETENTION will be used.&amp;lt;br /&amp;gt;&lt;br /&gt;
You need to do this for all LOB segments that you intend to modify.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select &amp;#039;ALTER TABLE &amp;#039;||owner||&amp;#039;.&amp;#039;||table_name||&amp;#039; MODIFY LOB (&amp;#039;||column_name||&amp;#039;) (PCTVERSION 20);&amp;#039; from dba_lobs where owner=&amp;#039;TIBCO&amp;#039;&lt;br /&gt;
&lt;br /&gt;
select &amp;#039;ALTER TABLE &amp;#039;||owner||&amp;#039;.&amp;#039;||table_name||&amp;#039; MODIFY LOB (&amp;#039;||column_name||&amp;#039;) (RETENTION);&amp;#039;     from dba_lobs where owner=&amp;#039;TIBCO&amp;#039;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
There is a table DBA_LOBS that displays information about all the LOB columns in the database, but it doesn&amp;#039;t actually store any LOB data, just metadata. The actual LOB segments in the database have system-generated names that take the form SYS_LOB*identifier*$$.&lt;br /&gt;
For example if you identify a segment named SYS_LOBidentifier$$ that is consuming space, you can find out what column of what table that LOB column maps to using the DBA_LOBS table:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 1000&lt;br /&gt;
col owner       for a20&lt;br /&gt;
col table_name  for a32&lt;br /&gt;
col column_name for a32&lt;br /&gt;
select owner&lt;br /&gt;
,      table_name&lt;br /&gt;
,      column_name&lt;br /&gt;
from   dba_lobs&lt;br /&gt;
where  1=1&lt;br /&gt;
and    segment_name = &amp;#039;SYS_LOB&amp;lt;&amp;lt;identifier&amp;gt;&amp;gt;$$&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====The Undo Advisor PL/SQL Interface====&lt;br /&gt;
You can activate the Undo Advisor by creating an undo advisor task through the advisor framework.&amp;lt;br /&amp;gt;&lt;br /&gt;
The following example creates an undo advisor task to evaluate the undo tablespace. The name of the advisor is &amp;#039;Undo Advisor&amp;#039;.&amp;lt;br /&amp;gt;&lt;br /&gt;
The analysis is based on Automatic Workload Repository snapshots, which you must specify by setting parameters START_SNAPSHOT and END_SNAPSHOT.&amp;lt;br /&amp;gt;&lt;br /&gt;
In the following example, the START_SNAPSHOT is &amp;quot;1&amp;quot; and END_SNAPSHOT is &amp;quot;2&amp;quot;.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
DECLARE&lt;br /&gt;
   tid    NUMBER;&lt;br /&gt;
   tname  VARCHAR2(30);&lt;br /&gt;
   oid    NUMBER;&lt;br /&gt;
BEGIN&lt;br /&gt;
   DBMS_ADVISOR.CREATE_TASK(&amp;#039;Undo Advisor&amp;#039;, tid, tname, &amp;#039;Undo Advisor Task&amp;#039;);&lt;br /&gt;
   DBMS_ADVISOR.CREATE_OBJECT(tname, &amp;#039;UNDO_TBS&amp;#039;, null, null, null, &amp;#039;null&amp;#039;, oid);&lt;br /&gt;
   DBMS_ADVISOR.SET_TASK_PARAMETER(tname, &amp;#039;TARGET_OBJECTS&amp;#039;, oid);&lt;br /&gt;
   DBMS_ADVISOR.SET_TASK_PARAMETER(tname, &amp;#039;START_SNAPSHOT&amp;#039;, 1);&lt;br /&gt;
   DBMS_ADVISOR.SET_TASK_PARAMETER(tname, &amp;#039;END_SNAPSHOT&amp;#039;, 2);&lt;br /&gt;
   DBMS_ADVISOR.SET_TASK_PARAMETER(tname, &amp;#039;INSTANCE&amp;#039;, 1);&lt;br /&gt;
   DBMS_ADVISOR.execute_task(tname);&lt;br /&gt;
        END;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
After you have created the advisor task, you can view the output and recommendations in the Automatic Database Diagnostic Monitor in Enterprise Manager.&amp;lt;br /&amp;gt;&lt;br /&gt;
This information is also available in the DBA_ADVISOR_* data dictionary views (DBA_ADVISOR_TASKS, DBA_ADVISOR_OBJECTS, DBA_ADVISOR_FINDINGS, DBA_ADVISOR_RECOMMENDATIONS, and so on).&lt;br /&gt;
====References====&lt;br /&gt;
* [http://www.akadia.com/services/ora_optimize_undo.html akadia.com]&lt;br /&gt;
* [http://dfitzjarrell.wordpress.com/2008/02/22/the-dreaded-ora-01555/ the dreaded ora-01555]&lt;br /&gt;
* [http://docs.oracle.com/cd/B28359_01/server.111/b28310/undo004.htm#ADMIN11469 docs.oracle.com]&lt;br /&gt;
&lt;br /&gt;
===Error 6 initializing SQL*Plus===&lt;br /&gt;
Using sqlplus or rman under Cygwin, ORACLE_HOME still needs to be windows format!&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Message file sp1&amp;lt;lang&amp;gt;.msb not found&lt;br /&gt;
SP2-0750 :You may need to set ORACLE_HOME to your Oracle software directory&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
so...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
export ORACLE_SID=KITRYD&lt;br /&gt;
ORAENV_ASK=NO&lt;br /&gt;
. oraenv&lt;br /&gt;
[[ &amp;quot;`uname`&amp;quot; == CYGWIN* ]] &amp;amp;&amp;amp; ORACLE_HOME=`cygpath -w ${ORACLE_HOME}`&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===ORA-2002: error while writing to audit trail===&lt;br /&gt;
Check the space left in the audit tablespace with:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select sum(bytes)/1024/1024 mb from dba_free_space where tablespace_name =&amp;#039;AUDIT_DT&amp;#039;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
If plenty of space, it can be due to Oracle clearing out the recyclebin at the same time.&amp;lt;br /&amp;gt;&lt;br /&gt;
If not, extend the datafile...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select * from dba_data_files where tablespace_name =&amp;#039;AUDIT_DT&amp;#039;;&lt;br /&gt;
alter database datafile 6 resize 30G;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
If that is not possible, clean out some audit data or add a datafile.&lt;br /&gt;
&lt;br /&gt;
===ORA-00449: background process &amp;#039;CKPT&amp;#039; unexpectedly terminated with error 7446===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SQL&amp;gt; startup nomount pfile=&amp;quot;/oracle/TRSCRP1/admin/initTRSCRP1.ora&amp;quot;&lt;br /&gt;
ORA-00449: background process &amp;#039;CKPT&amp;#039; unexpectedly terminated with error 7446&lt;br /&gt;
ORA-07446: sdnfy: bad value &amp;#039;&amp;#039; for parameter .&lt;br /&gt;
SQL&amp;gt; exit&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Solution&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SQL&amp;gt; mkdir /oracle/TRSCRP1/admin/bdump /oracle/TRSCRP1/admin/cdump&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORA-00845: MEMORY_TARGET not supported on this system===&lt;br /&gt;
* Reference: [http://arjudba.blogspot.be/2009/01/ora-00845-memorytarget-not-supported-on.html arjudba.blogspot.be]&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Problem Description&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SQL&amp;gt; STARTUP&lt;br /&gt;
ORA-00845: MEMORY_TARGET not supported on this system&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Cause&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
* Starting from Oracle 11g the automatic memory management feature is now defined with parameter MEMORY_TARGET and MEMMORY_MAX_TARGET.&lt;br /&gt;
* On linux file system the shared memory need to be mounted on /dev/shm directory on the operating system.&lt;br /&gt;
* And the size of /dev/shm needs to be greater than MEMORY_TARGET or MEMMORY_MAX_TARGET.&lt;br /&gt;
* The AMM (Automatic Memory Management) now in 11g manages both SGA and PGA together by MMAN process.&lt;br /&gt;
* The MEMORY_TARGET parameter in 11g comes for (SGA_TARGET+PGA_AGGREGATE_TARGET) which was in 10g.&lt;br /&gt;
* And MEMORY_MAX_TARGET parameter in 11g comes instead of SGA_MAX_TARGET parameter which was in 10g.&lt;br /&gt;
* The ORA-00845:can arises for the following two reasons on linux system.&lt;br /&gt;
1)If the shared memory which is mapped to /dev/shm directory is less than the size of MEMORY_TARGET or MEMORY_MAX_TARGET or&lt;br /&gt;
2)If the shared memory is not mapped to /dev/shm directory.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Solution&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Make sure /dev/shm is properly mounted. You can see it by,&lt;br /&gt;
#df -h or #df -k command.&lt;br /&gt;
The output should be similar to:&lt;br /&gt;
&lt;br /&gt;
$ df -k&lt;br /&gt;
Filesystem            Size  Used Avail Use% Mounted on&lt;br /&gt;
...&lt;br /&gt;
shmfs                 1G    512M 512M  50% /dev/shm&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
We see here for /dev/shm we have assigned 1G memory. Now if you set MEMORY_TARGET more than 1G then above ORA-845 will arise. For example if you have MEMORY_TARGET or MEMORY_MAX_TARGET set to 12G then you can mount shared memory to 13g like below.&lt;br /&gt;
As a root user,&lt;br /&gt;
# mount -t tmpfs shmfs -o size=13g /dev/shm&lt;br /&gt;
In order to make the settings persistence so that it will affect after restarting machine add an entry in /etc/fstab similar to the following:&lt;br /&gt;
&lt;br /&gt;
shmfs /dev/shm tmpfs size=13g 0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORA-24247: network access denied by access control list (ACL)===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Cause: No access control list (ACL) has been assigned to the target host or the privilege necessary to access the target host has not been granted to the user in the access control list.&lt;br /&gt;
&lt;br /&gt;
Action: Ensure that an access control list (ACL) has been assigned to the target host and the privilege necessary to access the target host has been granted to the user.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Your application will encounter an ORA-24247 error if it relies on one of the network packages and no proper ACL has been created. For the use of the following packages it is mandatory to have an ACL for the application user in place in 11g:&lt;br /&gt;
*UTL_TCP&lt;br /&gt;
*UTL_SMTP&lt;br /&gt;
*UTL_MAIL&lt;br /&gt;
*UTL_HTTP&lt;br /&gt;
*UTL_INADDR&lt;br /&gt;
Here is a very good explanation of how to setup the necessary ACLs: [[http://blog.whitehorses.nl/2010/03/17/oracle-11g-access-control-list-and-ora-24247/ whitehorses.nl]]&lt;br /&gt;
&lt;br /&gt;
===ORA-00600: internal error code, arguments: [qmx: no ref]===&lt;br /&gt;
Search &amp;quot;Master Note for Oracle XML Database (XDB) Install / Deinstall (Doc ID 1292089.1)&amp;quot; for more info.&lt;br /&gt;
====Problem:====&lt;br /&gt;
Sometimes one or more of the following errors can be encountered when installing or upgrading XDB, configuring APEX, running an Export, or selecting from xdb.xdb$resource or sys.dba_network_acls:&amp;lt;br /&amp;gt;&lt;br /&gt;
* ORA-31159: XML DB is in an invalid state&lt;br /&gt;
* ORA-00600: internal error code, arguments: [unable to load XDB library]&lt;br /&gt;
* ORA-00600: internal error code, arguments: [qmx: no ref]&lt;br /&gt;
* ORA-00600: internal error code, arguments: [qmtGetColumnInfo1]&lt;br /&gt;
* ORA-00600: internal error code, arguments: [qmtb_init_len]&lt;br /&gt;
* ORA-00600: internal error code, arguments: [qmtGetBaseType]&lt;br /&gt;
* ORA-00600: internal error code, arguments: [psdnop-1], [600]&lt;br /&gt;
* ORA-00600: internal error code, arguments: [qmtInit1]&lt;br /&gt;
* ORA-07445: exception encountered: core dump [_memcpy()+224] [SIGSEGV] [Address not mapped to object]&lt;br /&gt;
* ORA-19051 Cannot Use Fast Path Insert For This XMLType Table&lt;br /&gt;
* ORA-31011: XML parsing failed&lt;br /&gt;
Errors of this sort generally occur when the init routines for the internal XDB functions are run in an invalid environment causing memory corruption.&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
This can happen if the database was ever started with the LD_LIBRARY_PATH (LIBPATH for AIX or SHLIB_PATH for HP) pointing to the wrong $ORACLE_HOME/lib directory rather than to the correct location for the instance.&amp;lt;br /&amp;gt;&lt;br /&gt;
The LD_LIBRARY_PATH/LIBPATH/SHLIB_PATH environment variable is used to resolve the location of the shared library &amp;quot;libxdb.so (libxdb.sl on HP)&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
====Solution:====&lt;br /&gt;
* Stop Listener&lt;br /&gt;
* Stop database&lt;br /&gt;
* Ensure $ORACLE_HOME/lib is at the start of LD_LIBRARY_PATH / LIBPATH / SHLIB_PATH&lt;br /&gt;
* If AIX, run /usr/sbin/slibclean as root&lt;br /&gt;
* Start database&lt;br /&gt;
* Start listener&lt;br /&gt;
&lt;br /&gt;
===ORA-00201: control file version nn.nn.nn.nn incompatible with ORACLE version===&lt;br /&gt;
Trying to restore a database after complete failure&amp;lt;br /&amp;gt;&lt;br /&gt;
first step is to startup the database in nomount mode and restore the controlfile - succeeded.&amp;lt;br /&amp;gt;&lt;br /&gt;
second step, startup the database in mount mode ready for database restore...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SQL*Plus: Release 10.2.0.3.0 - Production on Wed Aug 19 18:16:47 2015&lt;br /&gt;
&lt;br /&gt;
Copyright (c) 1982, 2006, Oracle.  All Rights Reserved.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Connected to:&lt;br /&gt;
Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - 64bit Production&lt;br /&gt;
With the Partitioning, OLAP and Data Mining options&lt;br /&gt;
&lt;br /&gt;
SYS@CODWHP1&amp;gt; startup mount&lt;br /&gt;
ORACLE instance started.&lt;br /&gt;
&lt;br /&gt;
Total System Global Area  260046848 bytes&lt;br /&gt;
Fixed Size                  2029296 bytes&lt;br /&gt;
Variable Size             113248528 bytes&lt;br /&gt;
Database Buffers          134217728 bytes&lt;br /&gt;
Redo Buffers               10551296 bytes&lt;br /&gt;
ORA-00201: control file version 10.2.0.0.0 incompatible with ORACLE version 10.2.0.3.0&lt;br /&gt;
ORA-00202: control file: &amp;#039;/oracle/CODWHP1/product/10203/dbs/cntrlCODWHP1.dbf&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The problem was there was no compatible parameter in the simple init file I used to start up the instance.&amp;lt;br /&amp;gt;&lt;br /&gt;
Adding compatible parameter to init file to be same version (10.2.0.3) allowed the db to mount.&lt;br /&gt;
&lt;br /&gt;
===TNS-00525: Insufficient privilege for operation===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
lsnrctl start LISTENER_UCLID55V&lt;br /&gt;
&lt;br /&gt;
LSNRCTL for IBM/AIX RISC System/6000: Version 11.2.0.3.0 - Production on 26-MAR-2015 13:36:14&lt;br /&gt;
&lt;br /&gt;
Copyright (c) 1991, 2011, Oracle.  All rights reserved.&lt;br /&gt;
&lt;br /&gt;
Starting /oracle/product/11.2.0.3/bin/tnslsnr: please wait...&lt;br /&gt;
&lt;br /&gt;
TNSLSNR for IBM/AIX RISC System/6000: Version 11.2.0.3.0 - Production&lt;br /&gt;
System parameter file is /oracle/product/11.2.0.3/network/admin/listener.ora&lt;br /&gt;
Log messages written to /oracle/product/diag/tnslsnr/solax082/listener_uclid55v/alert/log.xml&lt;br /&gt;
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=150.251.114.238)(PORT=1525)))&lt;br /&gt;
Error listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC1525)))&lt;br /&gt;
TNS-12555: TNS:permission denied&lt;br /&gt;
 TNS-12560: TNS:protocol adapter error&lt;br /&gt;
  TNS-00525: Insufficient privilege for operation&lt;br /&gt;
   IBM/AIX RISC System/6000 Error: 1: Not owner&lt;br /&gt;
&lt;br /&gt;
Listener failed to start. See the error message(s) above...&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This would suggest the user attempting to start the listener has no access to either the Oracle binaries or the TNS listener/tnsnames files.&amp;lt;br /&amp;gt;&lt;br /&gt;
But... checkout the /tmp/.oracle directory :-)&amp;lt;br /&amp;gt;&lt;br /&gt;
That hidden gem shows who started the listener last time. Delete the relevant entry and try again!&amp;lt;br /&amp;gt;&lt;br /&gt;
To start from a clean sheet, stop all listeners, delete this directory and restart the listeners.&lt;br /&gt;
&lt;br /&gt;
===ORA-12003: materialized view or zonemap &amp;quot;KPK&amp;quot;.&amp;quot;EVD01_NEW&amp;quot; does not exist===&lt;br /&gt;
Here&amp;#039;s one you shouldn&amp;#039;t see very often.&amp;lt;br /&amp;gt;&lt;br /&gt;
Trying to drop a tablespace but prevented from doing so because a materialized view has referential contraints on a table in this tablespace.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SQL&amp;gt; drop tablespace TS_THALER_PART_OLD including contents and datafiles cascade constraints;&lt;br /&gt;
drop tablespace TS_THALER_PART_OLD including contents and datafiles cascade constraints&lt;br /&gt;
*&lt;br /&gt;
ERROR at line 1:&lt;br /&gt;
ORA-00604: error occurred at recursive SQL level 1&lt;br /&gt;
ORA-12083: must use DROP MATERIALIZED VIEW to drop &amp;quot;KPK&amp;quot;.&amp;quot;EVD01_NEW&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Ok, nice of Oracle to tell us what we have to do. Simple enough. Let&amp;#039;s drop the materialized view.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SQL&amp;gt; DROP MATERIALIZED VIEW &amp;quot;KPK&amp;quot;.&amp;quot;EVD01_NEW&amp;quot;;&lt;br /&gt;
DROP MATERIALIZED VIEW &amp;quot;KPK&amp;quot;.&amp;quot;EVD01_NEW&amp;quot;&lt;br /&gt;
*&lt;br /&gt;
ERROR at line 1:&lt;br /&gt;
ORA-12003: materialized view or zonemap &amp;quot;KPK&amp;quot;.&amp;quot;EVD01_NEW&amp;quot; does not exist&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Aah. Not so obvious then.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
desc &amp;quot;KPK&amp;quot;.&amp;quot;EVD01_NEW&amp;quot;&lt;br /&gt;
 Name                                      Null?    Type&lt;br /&gt;
 ----------------------------------------- -------- ----------------------------&lt;br /&gt;
 DATMAJ                                             VARCHAR2(8 CHAR)&lt;br /&gt;
 HEUMAJ                                             VARCHAR2(8 CHAR)&lt;br /&gt;
 PGMMAJ                                             VARCHAR2(6 CHAR)&lt;br /&gt;
 NATOPN                                             VARCHAR2(6 CHAR)&lt;br /&gt;
 REFEXN                                             VARCHAR2(50 CHAR)&lt;br /&gt;
 SWIOLN                                             VARCHAR2(1 CHAR)&lt;br /&gt;
 STAEVT                                             VARCHAR2(4 CHAR)&lt;br /&gt;
 REFEVT                                             VARCHAR2(16 CHAR)&lt;br /&gt;
 NUMIDT                                             VARCHAR2(30 CHAR)&lt;br /&gt;
 ORIEVT                                             VARCHAR2(10 CHAR)&lt;br /&gt;
 REFLOG                                             VARCHAR2(16 CHAR)&lt;br /&gt;
 MSGEVT_CPL                                         VARCHAR2(1500 CHAR)&lt;br /&gt;
 REFOPN                                             VARCHAR2(16 CHAR)&lt;br /&gt;
 DATEVT                                             VARCHAR2(8 CHAR)&lt;br /&gt;
 MSGEVT_FIL_1                                       VARCHAR2(2000 CHAR)&lt;br /&gt;
 MSGEVT_FIL_2                                       VARCHAR2(2000 CHAR)&lt;br /&gt;
 MSGEVT_SPE                                         VARCHAR2(200 CHAR)&lt;br /&gt;
 DATEFF                                             VARCHAR2(8 CHAR)&lt;br /&gt;
 TMSTMP                                             VARCHAR2(15 CHAR)&lt;br /&gt;
 VEREVT                                             VARCHAR2(3 CHAR)&lt;br /&gt;
 MSGEVT_FIL_3                                       VARCHAR2(2000 CHAR)&lt;br /&gt;
 MSGEVT_FIL_4                                       VARCHAR2(2000 CHAR)&lt;br /&gt;
 TYPEVT                                             VARCHAR2(5 CHAR)&lt;br /&gt;
 SBP_CODAPP                                         VARCHAR2(10 CHAR)&lt;br /&gt;
 SBP_REFINT                                         VARCHAR2(36 CHAR)&lt;br /&gt;
 SBP_TYPACT                                         VARCHAR2(2 CHAR)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
It exists... but as a table.&amp;lt;br /&amp;gt;&lt;br /&gt;
Something has gone wrong in the database somewhere. As it turns out after some deeper investigation, this database is a copy of production but &amp;quot;with modifications&amp;quot;.&amp;lt;br /&amp;gt;&lt;br /&gt;
After the cloning process, a schema needed renaming. Oracle have a procedure for this but it is very long-winded and time-consuming. It uses export and import with transportable tablespaces to do the remap of the schema.&amp;lt;br /&amp;gt;&lt;br /&gt;
An unsupported workaround to rename schema is to simply update the username in sys.user$ and restart the database.&amp;lt;br /&amp;gt;&lt;br /&gt;
This works for the most part but now we see a consequence of that action.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
col owner      for a30&lt;br /&gt;
col mview_name for a30&lt;br /&gt;
select owner&lt;br /&gt;
,      mview_name&lt;br /&gt;
from   dba_mviews&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
OWNER                          MVIEW_NAME&lt;br /&gt;
------------------------------ ------------------------------&lt;br /&gt;
EPK                            EVD01_NEW&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Ahaa, there&amp;#039;s the materialized view but the owner is different from the one described by the database error message above. This one is the owner as it was on production.&amp;lt;br /&amp;gt;&lt;br /&gt;
This means the owner of materialized views has been denormalised for some reason. Reading the (complex) view text of dba_mviews, we see the owner column is based on sys.snap$.sowner&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
col sowner for a20&lt;br /&gt;
col vname  for a20&lt;br /&gt;
col tname  for a20&lt;br /&gt;
select sowner&lt;br /&gt;
,      vname&lt;br /&gt;
,      tname&lt;br /&gt;
from   sys.snap$&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
SOWNER               VNAME                TNAME&lt;br /&gt;
-------------------- -------------------- --------------------&lt;br /&gt;
EPK                  EVD01_NEW            EVD01_NEW&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
For future reference when updating the username in sys.user$, update the snapshot owner in this table as well!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
update sys.snap$&lt;br /&gt;
set    sowner = &amp;#039;KPK&amp;#039;&lt;br /&gt;
where  sowner = &amp;#039;EPK&amp;#039;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Try again&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
DROP MATERIALIZED VIEW &amp;quot;KPK&amp;quot;.&amp;quot;EVD01_NEW&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
Materialized view dropped.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
yep, and the tablespace?&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
drop tablespace TS_THALER_PART_OLD including contents and datafiles cascade constraints;&lt;br /&gt;
&lt;br /&gt;
Tablespace dropped.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORA-12162: TNS:net service name is incorrectly specified===&lt;br /&gt;
Probably nothing to do with TNS. Check your ORACLE_SID is set correctly!&lt;br /&gt;
&lt;br /&gt;
===ORA-00054: resource busy and acquire with NOWAIT specified===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SELECT O.OBJECT_NAME, S.SID, S.SERIAL#, P.SPID, S.PROGRAM,S.USERNAME,&lt;br /&gt;
S.MACHINE,S.PORT , S.LOGON_TIME,SQ.SQL_FULLTEXT &lt;br /&gt;
FROM V$LOCKED_OBJECT L, DBA_OBJECTS O, V$SESSION S, &lt;br /&gt;
V$PROCESS P, V$SQL SQ &lt;br /&gt;
WHERE L.OBJECT_ID = O.OBJECT_ID &lt;br /&gt;
AND L.SESSION_ID = S.SID AND S.PADDR = P.ADDR &lt;br /&gt;
AND S.SQL_ADDRESS = SQ.ADDRESS;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select object_name, s.sid, s.serial#, p.spid &lt;br /&gt;
from v$locked_object l, dba_objects o, v$session s, v$process p&lt;br /&gt;
where l.object_id = o.object_id and l.session_id = s.sid and s.paddr = p.addr;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
then&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter system kill session &amp;#039;sid,serial#&amp;#039;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORA-12518: TNS:listener could not hand off client connection===&lt;br /&gt;
The database you are trying to connect to is probably on its knees. Check server memory is not exhausted.&lt;br /&gt;
&lt;br /&gt;
===ORA-12520: TNS:listener could not find available handler for requested type of server===&lt;br /&gt;
Strangely this could be related to number of processes being exhausted.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
show parameter processes&lt;br /&gt;
alter system set processes=350 scope=spfile;&lt;br /&gt;
shutdown immediate&lt;br /&gt;
startup&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORA-12541: TNS: no listener===&lt;br /&gt;
Either very basic - start the listener!&amp;lt;br /&amp;gt;&lt;br /&gt;
or, as in our case - not so obvious.&amp;lt;br /&amp;gt;&lt;br /&gt;
We use virtual IP addresses so that the IP address stays the same after failover to standby.&amp;lt;br /&amp;gt;&lt;br /&gt;
Due to some confused configuration, we got the network adapter on two different servers to have the same IP address.&amp;lt;br /&amp;gt;&lt;br /&gt;
Stop the IP address on the bad server (assign another one) and all is fine again.&lt;br /&gt;
===ORA-12514: TNS:listener does not currently know of service===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
lsnrctl status &amp;lt;listener_name&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Been altering tnsnames.ora or listener.ora?&lt;br /&gt;
* Check the local_listener parameter&lt;br /&gt;
Try resetting it to itself. Strange but if you are not using port 1521, this can work wonders!&amp;lt;br /&amp;gt;&lt;br /&gt;
Assuming listener is called LISTENER_WM9T:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter system set local_listener=LISTENER_WM9T scope=both;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Try and connect with the service name or directly with&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sqlplus &amp;#039;sys/*******&amp;#039;@&amp;lt;host&amp;gt;:&amp;lt;port&amp;gt;/&amp;lt;SID&amp;gt; as sysdba&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Excellent description of how Oracle TNS listeners work and a checklist on how to fix this error&amp;lt;br /&amp;gt;&lt;br /&gt;
* [[http://edstevensdba.wordpress.com/2011/03/19/ora-12514/ TNS — Ed Stevens]]&lt;br /&gt;
&lt;br /&gt;
===ORA-12547: TNS lost contact===&lt;br /&gt;
&lt;br /&gt;
If&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sqlplus &amp;lt;user&amp;gt;/&amp;lt;pass&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
fails with above error, try&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sqlplus &amp;lt;user&amp;gt;/&amp;lt;pass&amp;gt;@&amp;lt;db connection&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
If this works, it is most probably a permissions error.&amp;lt;br /&amp;gt;&lt;br /&gt;
Re-run the&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ORACLE_HOME/root.sh&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
script that was run as part of the original installation. This will reset the permissions on some important files.&lt;br /&gt;
===ORA-02374: conversion error loading table &amp;quot;BLENGADM&amp;quot;.&amp;quot;ZZ_EVTCTA&amp;quot;===&lt;br /&gt;
This is typical of importing data with Datapump when the tables in the source database were created with &amp;quot;byte&amp;quot; semantics and the destination is &amp;quot;char&amp;quot; semantics.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ORA-02374: conversion error loading table &amp;quot;BLENGADM&amp;quot;.&amp;quot;ZZ_EVTCTA&amp;quot;&lt;br /&gt;
ORA-12899: value too large for column NOMCTA (actual: 257, maximum: 256)&lt;br /&gt;
&lt;br /&gt;
ORA-02372: data for row: NOMCTA : 0X&amp;#039;4C6976726574206427E9706172676E65202020202020202020&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Problem====&lt;br /&gt;
The root cause is the nls_length_semantics of the table columns being BYTE where one character is assigned one byte. But after conversion in a multi-byte database, one character is larger than one byte (could be 2, 3 or 4) and no longer fits.&lt;br /&gt;
====Solution====&lt;br /&gt;
* import the metadata&lt;br /&gt;
Run the impdp command with content=metadata_only. This will create all the tables (still in their original form) but not the data.&lt;br /&gt;
* alter the BYTE columns in the affected tables to CHAR semantics&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select column_name&lt;br /&gt;
,      char_used&lt;br /&gt;
,      data_length&lt;br /&gt;
,      data_type &lt;br /&gt;
from   user_tab_columns &lt;br /&gt;
where  table_name = &amp;#039;T&amp;#039;&lt;br /&gt;
and    char_used = &amp;#039;B&amp;#039;;&lt;br /&gt;
COLUMN_NAME  C DATA_LENGTH DATA_TYPE&lt;br /&gt;
------------ - ----------- ---------&lt;br /&gt;
X            B           1 VARCHAR2&lt;br /&gt;
SQL&amp;gt; alter table t modify x varchar2(1 char);&lt;br /&gt;
Table altered.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Import the data&lt;br /&gt;
Rerun the impdp ensuring table_exists_action is not REPLACE (use truncate or append). This now imports the data into the modified tables.&lt;br /&gt;
====This script does the donkey work of altering table column semantics from byte to char====&lt;br /&gt;
The author of this script is unknown but he/she deserves a medal. It saves countless hours of work and is so well written.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/*&lt;br /&gt;
  The script converts all the VARCHAR2 columns in the user&amp;#039;s schema&lt;br /&gt;
  to CHAR length semantics. Known to work on 10.2.0.4 and later.&lt;br /&gt;
  &lt;br /&gt;
  Script must be executed against the database without any other client&lt;br /&gt;
  and/or application connections to the affected schema.&lt;br /&gt;
  &lt;br /&gt;
  Oracle does not support CHAR semantics for the built-in schemas,&lt;br /&gt;
  like SYS, SYSTEM or SYSMAN, so the script will throw an error,&lt;br /&gt;
  if attempt to run it against any one of them.&lt;br /&gt;
  &lt;br /&gt;
  Upon completion database objects that have dependencies on tables&lt;br /&gt;
  being modified will be invalidated. Oracle usually re-compiles invalidated&lt;br /&gt;
  objects on the first access. Alternatively, a DBA can execute UTLPRP script&lt;br /&gt;
  to recompile all invalid objects in the entire database.&lt;br /&gt;
  &lt;br /&gt;
  Upon completion, please make sure that NLS_LENGTH_SEMANTICS instance parameter&lt;br /&gt;
  is set to CHAR to ensure further upgradability of the schema.&lt;br /&gt;
*/&lt;br /&gt;
set serveroutput on size unlimited format wrap&lt;br /&gt;
declare&lt;br /&gt;
  type sql_list_t is table of varchar2(32767) index by pls_integer;&lt;br /&gt;
  type idx_list_t is table of user_indexes.index_name%type index by pls_integer;&lt;br /&gt;
  type col_list_t is table of user_tab_columns%rowtype index by pls_integer;&lt;br /&gt;
  --&lt;br /&gt;
  lv_col_cnt   pls_integer := 0;&lt;br /&gt;
  lv_idx_cnt   pls_integer := 0;&lt;br /&gt;
  lv_char_set  pls_integer := 0; &lt;br /&gt;
  lv_user      user_users.username%type;&lt;br /&gt;
  lv_sql_stmt  varchar2(32767);&lt;br /&gt;
  lv_byte_cols col_list_t;&lt;br /&gt;
  lv_idx_names idx_list_t;&lt;br /&gt;
  lv_idx_ddls  sql_list_t;&lt;br /&gt;
  --&lt;br /&gt;
  procedure run_sql_stmt&lt;br /&gt;
  (&lt;br /&gt;
   p_sql_stmt in varchar2&lt;br /&gt;
  )&lt;br /&gt;
  as&lt;br /&gt;
  begin&lt;br /&gt;
    execute immediate p_sql_stmt;&lt;br /&gt;
  exception&lt;br /&gt;
    when others&lt;br /&gt;
    then&lt;br /&gt;
      raise_application_error(-20202, &amp;#039;Failed statement [&amp;#039; || p_sql_stmt || dbms_utility.format_error_backtrace() || &amp;#039;]&amp;#039;, true);&lt;br /&gt;
  end;&lt;br /&gt;
begin&lt;br /&gt;
  --&lt;br /&gt;
  lv_user := user();&lt;br /&gt;
  if lv_user in (&amp;#039;SYS&amp;#039;, &amp;#039;SYSTEM&amp;#039;, &amp;#039;SYSMAN&amp;#039;)&lt;br /&gt;
  then&lt;br /&gt;
    raise_application_error(-20202, &amp;#039;This script cannot be executed against Oracle built-in schema [&amp;#039; || lv_user || &amp;#039;].&amp;#039;);&lt;br /&gt;
  end if;&lt;br /&gt;
  --&lt;br /&gt;
  select&lt;br /&gt;
         *&lt;br /&gt;
         bulk collect into lv_byte_cols&lt;br /&gt;
  from&lt;br /&gt;
         user_tab_columns uc&lt;br /&gt;
  where&lt;br /&gt;
         uc.char_used = &amp;#039;B&amp;#039;&lt;br /&gt;
         and&lt;br /&gt;
         substr(uc.table_name, 1, 4) != &amp;#039;BIN$&amp;#039;&lt;br /&gt;
         and&lt;br /&gt;
         not exists&lt;br /&gt;
         (&lt;br /&gt;
          select 1&lt;br /&gt;
          from   user_views uv&lt;br /&gt;
          where  uv.view_name = uc.table_name&lt;br /&gt;
         )&lt;br /&gt;
  ;&lt;br /&gt;
  --&lt;br /&gt;
  lv_col_cnt := lv_byte_cols.count();&lt;br /&gt;
  --&lt;br /&gt;
  dbms_output.enable();&lt;br /&gt;
  --&lt;br /&gt;
  if lv_col_cnt &amp;gt; 0&lt;br /&gt;
  then&lt;br /&gt;
    for idx_rw in&lt;br /&gt;
    (&lt;br /&gt;
     select index_name &lt;br /&gt;
     from   user_indexes&lt;br /&gt;
     where  index_type = &amp;#039;FUNCTION-BASED NORMAL&amp;#039;&lt;br /&gt;
    )&lt;br /&gt;
    loop&lt;br /&gt;
      lv_idx_cnt := lv_idx_cnt + 1;&lt;br /&gt;
      lv_idx_names(lv_idx_cnt) := idx_rw.index_name;&lt;br /&gt;
      lv_idx_ddls(lv_idx_cnt) := replace&lt;br /&gt;
                                 (&lt;br /&gt;
                                  dbms_metadata.get_ddl&lt;br /&gt;
                                  (&lt;br /&gt;
                                   object_type =&amp;gt; &amp;#039;INDEX&amp;#039;,&lt;br /&gt;
                                   name        =&amp;gt; idx_rw.index_name&lt;br /&gt;
                                  )&lt;br /&gt;
                                  ,&lt;br /&gt;
                                  &amp;#039;;&amp;#039;&lt;br /&gt;
                                 );&lt;br /&gt;
      lv_sql_stmt := &amp;#039;drop index &amp;#039; || idx_rw.index_name;&lt;br /&gt;
      run_sql_stmt(lv_sql_stmt);&lt;br /&gt;
      dbms_output.put_line(&amp;#039;Dropped function-based index: &amp;#039; || idx_rw.index_name);&lt;br /&gt;
      dbms_output.put_line(&amp;#039;In case of script failure, restore the index by running the DDL statement below:&amp;#039;);&lt;br /&gt;
      dbms_output.put_line(lv_idx_ddls(lv_idx_cnt) || &amp;#039;;&amp;#039;);&lt;br /&gt;
    end loop;&lt;br /&gt;
    --&lt;br /&gt;
    for i in 1..lv_col_cnt&lt;br /&gt;
    loop&lt;br /&gt;
      lv_sql_stmt :=  &amp;#039;alter table &amp;#039; || lv_byte_cols(i).table_name || &amp;#039; modify (&amp;#039; ||&lt;br /&gt;
                      lv_byte_cols(i).column_name || &amp;#039; &amp;#039; || lv_byte_cols(i).data_type ||&lt;br /&gt;
                      &amp;#039;(&amp;#039; || lv_byte_cols(i).char_length || &amp;#039; char))&amp;#039;;&lt;br /&gt;
      run_sql_stmt(lv_sql_stmt);&lt;br /&gt;
    end loop;&lt;br /&gt;
    --&lt;br /&gt;
    dbms_output.new_line();&lt;br /&gt;
    for i in 1..lv_idx_cnt&lt;br /&gt;
    loop&lt;br /&gt;
      run_sql_stmt(lv_idx_ddls(i));&lt;br /&gt;
      dbms_output.put_line(&amp;#039;Recreated function-based index: &amp;#039; || lv_idx_names(i));&lt;br /&gt;
    end loop;&lt;br /&gt;
    --&lt;br /&gt;
    dbms_output.new_line();&lt;br /&gt;
    dbms_output.put_line&lt;br /&gt;
    (&lt;br /&gt;
     &amp;#039;Updated length semantics to CHAR for &amp;#039; || lv_col_cnt || &amp;#039; column&amp;#039; ||&lt;br /&gt;
     case when lv_col_cnt &amp;gt; 1&lt;br /&gt;
          then &amp;#039;s&amp;#039;&lt;br /&gt;
     end ||&lt;br /&gt;
     &amp;#039; in the schema [&amp;#039; || lv_user || &amp;#039;].&amp;#039;&lt;br /&gt;
    );&lt;br /&gt;
  else&lt;br /&gt;
    dbms_output.put_line(&amp;#039;No columns with BYTE length semantics were found in the schema [&amp;#039; || lv_user || &amp;#039;].&amp;#039;);&lt;br /&gt;
  end if;&lt;br /&gt;
  --&lt;br /&gt;
  select count(*) into lv_char_set&lt;br /&gt;
  from   nls_session_parameters&lt;br /&gt;
  where  parameter = &amp;#039;NLS_LENGTH_SEMANTICS&amp;#039;&lt;br /&gt;
         and&lt;br /&gt;
         value = &amp;#039;CHAR&amp;#039;&lt;br /&gt;
  ;&lt;br /&gt;
  --&lt;br /&gt;
  if lv_char_set = 0&lt;br /&gt;
  then&lt;br /&gt;
    dbms_output.put_line(&amp;#039;WARNING: Do not forget to change instance parameter NLS_LENGTH_SEMANTICS to CHAR and restart the database.&amp;#039;);&lt;br /&gt;
  end if;&lt;br /&gt;
end;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORA-14097: column type or size mismatch in ALTER TABLE EXCHANGE PARTITION===&lt;br /&gt;
Also can be &amp;lt;tt&amp;gt;ORA-54033: column to be modified is used in a virtual column expression&amp;lt;/tt&amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;
Nothing especially to do with partitions - just any ddl operation that affects the table.&amp;lt;br /&amp;gt;&lt;br /&gt;
Hidden columns do not normally show up in a desc unless colinvisible is on&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set colinvisible on&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
But these sneaky system-generated ones don&amp;#039;t show up even with that setting on!  You need to show them with this:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set pages 50 lines 1000&lt;br /&gt;
col column_name for a40&lt;br /&gt;
col data_default for a40&lt;br /&gt;
select internal_column_id, column_name, data_default, hidden_column, virtual_column from dba_tab_cols where table_name =&amp;#039;XND40&amp;#039;;&lt;br /&gt;
&lt;br /&gt;
INTERNAL_COLUMN_ID COLUMN_NAME                                        DATA_DEFAULT                                       HIDDEN_COLUM VIRTUAL_COLU&lt;br /&gt;
------------------ -------------------------------------------------- -------------------------------------------------- ------------ ------------&lt;br /&gt;
                35 MONLOT_REC_CDR                                     &amp;#039;0&amp;#039;                                                NO           NO&lt;br /&gt;
                34 MONLOT_REC_DBT                                     &amp;#039;0&amp;#039;                                                NO           NO&lt;br /&gt;
                33 MONLOT_CAL_CDR                                     &amp;#039;0&amp;#039;                                                NO           NO&lt;br /&gt;
                32 MONLOT_CAL_DBT                                     &amp;#039;0&amp;#039;                                                NO           NO&lt;br /&gt;
                31 MONMVT_CPT                                         &amp;#039;0&amp;#039;                                                NO           NO&lt;br /&gt;
                30 SENNOT                                             &amp;#039; &amp;#039;                                                NO           NO&lt;br /&gt;
                29 NUMSEQ                                                                                                NO           NO&lt;br /&gt;
                28 NOMFIC                                                                                                NO           NO&lt;br /&gt;
                27 TOTCPT_REC                                                                                            NO           NO&lt;br /&gt;
                26 TOTCPT_CAL                                                                                            NO           NO&lt;br /&gt;
                25 MONLOT_REC                                                                                            NO           NO&lt;br /&gt;
                24 MONLOT_CAL                                                                                            NO           NO&lt;br /&gt;
                23 NBRELE_REC                                                                                            NO           NO&lt;br /&gt;
                22 NBRELE_CAL                                                                                            NO           NO&lt;br /&gt;
                21 NUMCPT_GLO                                                                                            NO           NO&lt;br /&gt;
                20 DEVLOT                                                                                                NO           NO&lt;br /&gt;
                19 CODERR                                                                                                NO           NO&lt;br /&gt;
                18 CANLOT                                                                                                NO           NO&lt;br /&gt;
                17 REFTEX                                                                                                NO           NO&lt;br /&gt;
                16 REFEXN                                                                                                NO           NO&lt;br /&gt;
                15 ETTLOT                                                                                                NO           NO&lt;br /&gt;
                14 TYPLOT                                                                                                NO           NO&lt;br /&gt;
                13 DATEXC                                                                                                NO           NO&lt;br /&gt;
                12 STALOT                                                                                                NO           NO&lt;br /&gt;
                11 REFLOT                                                                                                NO           NO&lt;br /&gt;
                10 USRAUT                                                                                                NO           NO&lt;br /&gt;
                 9 HEUAUT                                                                                                NO           NO&lt;br /&gt;
                 8 DATAUT                                                                                                NO           NO&lt;br /&gt;
                 7 PGMMAJ                                                                                                NO           NO&lt;br /&gt;
                 6 USRMAJ                                                                                                NO           NO&lt;br /&gt;
                 5 HEUMAJ                                                                                                NO           NO&lt;br /&gt;
                 4 DATMAJ                                                                                                NO           NO&lt;br /&gt;
                 3 DATCRT                                                                                                NO           NO&lt;br /&gt;
                 2 REFMAJ                                                                                                NO           NO&lt;br /&gt;
                 1 NUMVER                                                                                                NO           NO&lt;br /&gt;
                36 SYS_STS#KR2WNV5L070XKV1L5H7REH                     SYS_OP_COMBINED_HASH(&amp;quot;NOMFIC&amp;quot;,&amp;quot;NUMSEQ&amp;quot;)            YES          YES&lt;br /&gt;
&lt;br /&gt;
36 rows selected.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
That last row means extended statistics have been generated for 2 columns in this table.&amp;lt;br /&amp;gt;&lt;br /&gt;
You can see this because the name begins with SYS_STS. If it begins with SYS_&amp;lt;something else&amp;gt; then it is not extended statistics.&amp;lt;br /&amp;gt;&lt;br /&gt;
It may be an unused column. Original [https://dba.stackexchange.com/questions/196248/what-is-the-sys-c00054-140314103403-column-in-my-regular-oracle-table here]&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SQL&amp;gt; create table t1 as select * from dba_roles;&lt;br /&gt;
&lt;br /&gt;
Table created.&lt;br /&gt;
&lt;br /&gt;
SQL&amp;gt; desc t1&lt;br /&gt;
 Name                                      Null?    Type&lt;br /&gt;
 ----------------------------------------- -------- ----------------------------&lt;br /&gt;
 ROLE                                      NOT NULL VARCHAR2(30)&lt;br /&gt;
 PASSWORD_REQUIRED                                  VARCHAR2(8)&lt;br /&gt;
 AUTHENTICATION_TYPE                                VARCHAR2(11)&lt;br /&gt;
&lt;br /&gt;
SQL&amp;gt; alter table t1 set unused (AUTHENTICATION_TYPE);&lt;br /&gt;
&lt;br /&gt;
Table altered.&lt;br /&gt;
&lt;br /&gt;
SQL&amp;gt; desc t1&lt;br /&gt;
 Name                                      Null?    Type&lt;br /&gt;
 ----------------------------------------- -------- ----------------------------&lt;br /&gt;
 ROLE                                      NOT NULL VARCHAR2(30)&lt;br /&gt;
 PASSWORD_REQUIRED                                  VARCHAR2(8)&lt;br /&gt;
&lt;br /&gt;
SQL&amp;gt; select column_name from user_tab_cols where table_name = &amp;#039;T1&amp;#039;;&lt;br /&gt;
&lt;br /&gt;
COLUMN_NAME&lt;br /&gt;
------------------------------&lt;br /&gt;
SYS_C00003_18012517:25:39$&lt;br /&gt;
PASSWORD_REQUIRED&lt;br /&gt;
ROLE&lt;br /&gt;
&lt;br /&gt;
SQL&amp;gt; alter table t1 drop unused columns;&lt;br /&gt;
&lt;br /&gt;
Table altered.&lt;br /&gt;
&lt;br /&gt;
SQL&amp;gt; select column_name from user_tab_cols where table_name = &amp;#039;T1&amp;#039;;&lt;br /&gt;
&lt;br /&gt;
COLUMN_NAME&lt;br /&gt;
------------------------------&lt;br /&gt;
PASSWORD_REQUIRED&lt;br /&gt;
ROLE&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Solution====&lt;br /&gt;
Drop the extended stats, do what you need to do and recreate the extended stats.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
PROCEDURE DROP_EXTENDED_STATS&lt;br /&gt;
 Argument Name                  Type                    In/Out Default?&lt;br /&gt;
 ------------------------------ ----------------------- ------ --------&lt;br /&gt;
 OWNNAME                        VARCHAR2                IN&lt;br /&gt;
 TABNAME                        VARCHAR2                IN&lt;br /&gt;
 EXTENSION                      VARCHAR2                IN&lt;br /&gt;
&lt;br /&gt;
exec dbms_stats.drop_extended_stats ( &amp;#039;KPK&amp;#039;, &amp;#039;XND40&amp;#039;, &amp;#039;(&amp;quot;NOMFIC&amp;quot;,&amp;quot;NUMSEQ&amp;quot;)&amp;#039; );&lt;br /&gt;
&lt;br /&gt;
create table kpk.xnd40_new as select * from kpk.xnd40 where 1=2;&lt;br /&gt;
&lt;br /&gt;
Table created.&lt;br /&gt;
&lt;br /&gt;
select dbms_stats.create_extended_stats ( &amp;#039;KPK&amp;#039;, &amp;#039;XND40&amp;#039;, &amp;#039;(&amp;quot;NOMFIC&amp;quot;,&amp;quot;NUMSEQ&amp;quot;)&amp;#039; ) from   dual;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The stats columns can also be seen in their own table&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 1000 pages 100&lt;br /&gt;
col owner for a6&lt;br /&gt;
col table_name for a20&lt;br /&gt;
col extension_name  for a40&lt;br /&gt;
col extension  for a50&lt;br /&gt;
select owner, table_name, extension_name, extension, creator, droppable from dba_stat_extensions where owner = upper(&amp;#039;&amp;amp;&amp;amp;owner.&amp;#039;) and table_name = upper(&amp;#039;&amp;amp;&amp;amp;table_name.&amp;#039;) and extension_name LIKE &amp;#039;SYS_STS%&amp;#039;;&lt;br /&gt;
&lt;br /&gt;
OWNER TABLE_NAME           EXTENSION_NAME                           EXTENSION                                          CREATOR                  DROPPABLE&lt;br /&gt;
----- -------------------- ---------------------------------------- -------------------------------------------------- ------------------------ ------------&lt;br /&gt;
KPK   XMD01                SYS_STSOA4UXZDBW7MIV5OOR8VOHHK           (&amp;quot;DATCRT&amp;quot;,&amp;quot;CODJRN&amp;quot;)                                SYSTEM                   YES&lt;br /&gt;
KPK   XDD02                SYS_STSFJCZYRZBCQL820ADIR0Y4RZ           (&amp;quot;REFMSG&amp;quot;,&amp;quot;CPTTIT&amp;quot;,&amp;quot;TYPMSG&amp;quot;)                       SYSTEM                   YES&lt;br /&gt;
KPK   XCD09                SYS_STS2OIO647GN0_UV$XO583KKKJ           (&amp;quot;DATCRT&amp;quot;,&amp;quot;HEUMAJ&amp;quot;,&amp;quot;STAMOD&amp;quot;)                       SYSTEM                   YES&lt;br /&gt;
KPK   XCD09                SYS_STS_BRDODC6DJG_HXK0#O9BOYF           (&amp;quot;STAMOD&amp;quot;,&amp;quot;CODMOD&amp;quot;)                                SYSTEM                   YES&lt;br /&gt;
KPK   XCD09                SYS_STS2#DY5U$WQG6COVHB##H2ESK           (&amp;quot;DATMAJ&amp;quot;,&amp;quot;STAMOD&amp;quot;,&amp;quot;CODMOD&amp;quot;)                       SYSTEM                   YES&lt;br /&gt;
KPK   XCD09                SYS_STSO7#D3DI5R8_VAF$WJ32D8MT           (&amp;quot;STAMOD&amp;quot;,&amp;quot;KEYREF_1&amp;quot;)                              SYSTEM                   YES&lt;br /&gt;
KPK   XCD09                SYS_STS4FRY10M34S2L$0FDM1N4B18           (&amp;quot;STAMOD&amp;quot;,&amp;quot;IDTMOD&amp;quot;)                                SYSTEM                   YES&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORA-14404: partitioned table contains partitions in a different tablespace===&lt;br /&gt;
As part of an RMAN duplicate with a skip tablespace, this error is produced&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Reenabling controlfile options for auxiliary database&lt;br /&gt;
Executing: alter database enable block change tracking using file &amp;#039;/oracle/acc/ora_data3/adsa1/bct_adsp_do_not_delete.f&amp;#039;&lt;br /&gt;
&lt;br /&gt;
contents of Memory Script:&lt;br /&gt;
{&lt;br /&gt;
   Alter clone database open resetlogs;&lt;br /&gt;
}&lt;br /&gt;
executing Memory Script&lt;br /&gt;
&lt;br /&gt;
database opened&lt;br /&gt;
Dropping offline and skipped tablespaces&lt;br /&gt;
Executing: drop tablespace &amp;quot;ADS_ARCHIVE&amp;quot; including contents cascade constraints&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-03002: failure of Duplicate Db command at 10/16/2017 23:46:12&lt;br /&gt;
RMAN-05501: aborting duplication of target database&lt;br /&gt;
RMAN-06136: ORACLE error from auxiliary database: ORA-14404: partitioned table contains partitions in a different tablespace&lt;br /&gt;
&lt;br /&gt;
Recovery Manager complete.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
and when attempting to backup the database, we get errors&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
RMAN-06169: could not read file header for datafile 188 error reason 1&lt;br /&gt;
RMAN-06169: could not read file header for datafile 189 error reason 1&lt;br /&gt;
RMAN-06169: could not read file header for datafile 190 error reason 1&lt;br /&gt;
RMAN-06169: could not read file header for datafile 191 error reason 1&lt;br /&gt;
RMAN-06169: could not read file header for datafile 14 error reason 1&lt;br /&gt;
released channel: t1&lt;br /&gt;
released channel: t2&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-03002: failure of backup plus archivelog command at 10/17/2017 15:08:40&lt;br /&gt;
RMAN-06056: could not access datafile 14&lt;br /&gt;
&lt;br /&gt;
Recovery Manager complete.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Problem====&lt;br /&gt;
Tables in the tablespace have partitions in another tablespace so this one cannot be dropped.&amp;lt;br /&amp;gt;&lt;br /&gt;
Check which table partitions are in which tablespaces&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 200&lt;br /&gt;
set pagesize 200&lt;br /&gt;
col table_name for a14&lt;br /&gt;
col table_owner for a14&lt;br /&gt;
col partition_name for a14&lt;br /&gt;
select table_owner&lt;br /&gt;
,      table_name&lt;br /&gt;
,      partition_name&lt;br /&gt;
,      tablespace_name&lt;br /&gt;
from   dba_tab_partitions&lt;br /&gt;
where  (table_owner, table_name) in&lt;br /&gt;
       (&lt;br /&gt;
       select table_owner&lt;br /&gt;
       ,      table_name&lt;br /&gt;
       from   dba_tab_partitions x&lt;br /&gt;
       where  x.tablespace_name = &amp;#039;&amp;amp;&amp;amp;TABLESPACE_TO_DROP&amp;#039;&lt;br /&gt;
       and    exists ( select *&lt;br /&gt;
                       from   dba_tab_partitions y&lt;br /&gt;
                       where  x.table_owner = y.table_owner&lt;br /&gt;
                       and    x.table_name  = y.table_name&lt;br /&gt;
                       and    y.tablespace_name not in (&amp;#039;&amp;amp;TABLESPACE_TO_DROP&amp;#039;)&lt;br /&gt;
                       group  by table_owner&lt;br /&gt;
                       ,      table_name&lt;br /&gt;
                     )&lt;br /&gt;
        )&lt;br /&gt;
order by 1,2,partition_position&lt;br /&gt;
/&lt;br /&gt;
undef TABLESPACE_TO_DROP&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
TABLE_OWNER    TABLE_NAME     PARTITION_NAME TABLESPACE_NAME&lt;br /&gt;
-------------- -------------- -------------- ------------------------------&lt;br /&gt;
KPK            XND20          P0910          TS_THALER_PART_OLD&lt;br /&gt;
KPK            XND20          P1112          TS_THALER_PART_OLD&lt;br /&gt;
KPK            XND20          P13            TS_THALER_PART_OLD&lt;br /&gt;
KPK            XND20          P14            TS_THALER_PART_OLD&lt;br /&gt;
KPK            XND20          P15            TS_THALER_PART_OLD&lt;br /&gt;
KPK            XND20          P16            TS_THALER_DATA&lt;br /&gt;
KPK            XND20          P17            TS_THALER_DATA&lt;br /&gt;
KPK            XND20          P18            TS_THALER_DATA&lt;br /&gt;
KPK            XND20          PMAX           TS_THALER_DATA&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Solution====&lt;br /&gt;
If the intention is to keep all the tables then run this query to generate statements to move the relevant tables out of this tablespace&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select &amp;#039;alter table &amp;#039;||b.table_owner||&amp;#039;.&amp;#039;||b.table_name||&amp;#039; move partition &amp;#039;||b.partition_name||&amp;#039; tablespace &amp;amp;NEW_TABLESPACE;&amp;#039;&lt;br /&gt;
from   (&lt;br /&gt;
       select distinct table_name&lt;br /&gt;
       ,      partition_name&lt;br /&gt;
       from   dba_tab_partitions&lt;br /&gt;
       where  tablespace_name = &amp;#039;&amp;amp;&amp;amp;TABLESPACE_NAME&amp;#039;&lt;br /&gt;
       )                  a&lt;br /&gt;
,      dba_tab_partitions b&lt;br /&gt;
where  a.table_name       = b.table_name&lt;br /&gt;
and    b.tablespace_name != &amp;#039;&amp;amp;TABLESPACE_NAME&amp;#039;&lt;br /&gt;
/&lt;br /&gt;
undef TABLESPACE_NAME&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
If however, the intention is to drop the tablespace anyway, the tables need to be dropped before the tablespace can be dropped.&amp;lt;br /&amp;gt;&lt;br /&gt;
But ...tables with partitions in different tablespaces cannot be dropped. The partitions need to be dropped first!&amp;lt;br /&amp;gt;&lt;br /&gt;
Run the following query to generate statements to drop all the &amp;#039;problem&amp;#039; tables. When these have gone, the tablespace can be dropped.&lt;br /&gt;
* drop table partitions&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
spool /tmp/drop_table_partitions.sql&lt;br /&gt;
sqlplus / as sysdba&amp;lt;&amp;lt;EOSQL&lt;br /&gt;
set headi off newpa none feedb off trims on echo off&lt;br /&gt;
select &amp;#039;alter table &amp;#039;||table_owner||&amp;#039;.&amp;#039;||table_name||&amp;#039; drop partition &amp;#039;||partition_name||&amp;#039;;&amp;#039;&lt;br /&gt;
from   dba_tab_partitions&lt;br /&gt;
where  tablespace_name = &amp;#039;$TABLESPACE_NAME&amp;#039;&lt;br /&gt;
/&lt;br /&gt;
spool off&lt;br /&gt;
EOSQL&lt;br /&gt;
echo &amp;quot;@/tmp/drop_table_partitions.sql&amp;quot; | sqlplus / as sysdba&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* drop tables&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sqlplus / as sysdba&amp;lt;&amp;lt;EOSQL&lt;br /&gt;
select &amp;#039;drop table &amp;#039;||table_owner||&amp;#039;.&amp;#039;||table_name||&amp;#039;;&amp;#039;&lt;br /&gt;
from   dba_tab_partitions&lt;br /&gt;
where  tablespace_name = &amp;#039;$TABLESPACE_NAME&amp;#039;&lt;br /&gt;
spool /tmp/drop_tables.sql&lt;br /&gt;
/&lt;br /&gt;
spool off&lt;br /&gt;
EOSQL&lt;br /&gt;
echo &amp;quot;@/tmp/drop_tables.sql&amp;quot; | sqlplus / as sysdba&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* drop tablespace&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
drop tablespace ads_archive including contents and datafiles&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Find all table partitions in tablespaces with missing datafiles====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 1000 pages 100&lt;br /&gt;
col owner for a10&lt;br /&gt;
col segment_name for a40&lt;br /&gt;
col segment_type for a25&lt;br /&gt;
col partition_name for a20&lt;br /&gt;
col tablespace_name for a25&lt;br /&gt;
select owner&lt;br /&gt;
,      segment_name&lt;br /&gt;
,      segment_type&lt;br /&gt;
,      partition_name&lt;br /&gt;
,      tablespace_name&lt;br /&gt;
from   dba_segments&lt;br /&gt;
where  segment_type in (&amp;#039;TABLE PARTITION&amp;#039;, &amp;#039;TABLE SUBPARTITION&amp;#039;)&lt;br /&gt;
and    tablespace_name in (&lt;br /&gt;
                          select tablespace_name&lt;br /&gt;
                          from   dba_data_files&lt;br /&gt;
                          where  file_name like &amp;#039;%MISSING%&amp;#039;&lt;br /&gt;
                          )&lt;br /&gt;
order  by 1, 2, decode (segment_type, &amp;#039;TABLE SUBPARTITION&amp;#039;, 1, 2),4&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Use exchange partition to alter metadata of the tablespaces without moving the actual data====&lt;br /&gt;
* [https://community.oracle.com/thread/581401?start=15&amp;amp;tstart=0 this] is what you are looking for!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Workaround====&lt;br /&gt;
While working on the solution, a backup can be made using the &amp;quot;skip inaccessible&amp;quot; option. Put this in an rman cmdfile...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
connect catalog rmanusr/rmanpwd@rmancat&lt;br /&gt;
connect target sys/syspwd@adsa1&lt;br /&gt;
run {&lt;br /&gt;
allocate channel t1 type &amp;#039;sbt_tape&amp;#039; parms &amp;#039;ENV=(NSR_SERVER=hn6000.company.be,NSR_CLIENT=hn491,NSR_DATA_VOLUME_POOL=DD1DAILY,NSR_END_ERROR_IGNORE=TRUE)&amp;#039;;&lt;br /&gt;
allocate channel t2 type &amp;#039;sbt_tape&amp;#039; parms &amp;#039;ENV=(NSR_SERVER=hn6000.company.be,NSR_CLIENT=hn491,NSR_DATA_VOLUME_POOL=DD1DAILY,NSR_END_ERROR_IGNORE=TRUE)&amp;#039;;&lt;br /&gt;
configure retention policy to recovery window of 28 days;&lt;br /&gt;
configure controlfile autobackup on;&lt;br /&gt;
crosscheck archivelog all;&lt;br /&gt;
SQL &amp;#039;ALTER SYSTEM SWITCH LOGFILE&amp;#039;;&lt;br /&gt;
SQL &amp;#039;CREATE PFILE FROM SPFILE&amp;#039;;&lt;br /&gt;
backup filesperset 1 format &amp;#039;dbfull_%d_%I_%t_%s_%p&amp;#039; full database plus archivelog skip inaccessible delete all input;&lt;br /&gt;
backup current controlfile;&lt;br /&gt;
release channel t1;&lt;br /&gt;
release channel t2;&lt;br /&gt;
}&lt;br /&gt;
exit&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Another way of deleting the offending objects====&lt;br /&gt;
Taken from [http://www.dbarj.com.br/en/2015/01/resume-oracle-duplicate-database-failed-recovery-datafiles/ Recover from a failed RMAN duplicate]&amp;lt;br /&amp;gt;&lt;br /&gt;
Need to check it before running it blindly!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
set echo off feed off termo off trims on pages 0 newpa none lines 2000 headi off long 32000&lt;br /&gt;
col val for a1000&lt;br /&gt;
spool destroy_offending_objects.sql&lt;br /&gt;
&lt;br /&gt;
select to_clob (&amp;#039;alter table &amp;#039;|| table_name||&amp;#039; drop constraint &amp;#039;||constraint_name||&amp;#039;;&amp;#039;) Val&lt;br /&gt;
from user_constraints where constraint_type in (&amp;#039;R&amp;#039;,&amp;#039;P&amp;#039;) and table_name in (select distinct table_name from user_tab_partitions)&lt;br /&gt;
union all&lt;br /&gt;
select to_clob (&amp;#039;drop index &amp;#039;||index_name||&amp;#039;;&amp;#039;) Val from user_indexes where table_name in (select distinct table_name from user_tab_partitions)&lt;br /&gt;
union all&lt;br /&gt;
select to_clob (&amp;#039;alter table &amp;#039;||table_name|| &amp;#039; drop partition &amp;#039;||partition_name||&amp;#039;;&amp;#039;) from dba_tab_partitions&lt;br /&gt;
where tablespace_name in (select tablespace_name from dba_data_files where file_name like &amp;#039;%MISSING%&amp;#039;)&lt;br /&gt;
union all&lt;br /&gt;
Select case&lt;br /&gt;
when instr (VAl, &amp;#039;PARTITION&amp;#039;) = 0 Then&lt;br /&gt;
substr (Val,1,InStr (Val,&amp;#039;)&amp;#039;)+1)||&amp;#039;;&amp;#039;&lt;br /&gt;
else&lt;br /&gt;
substr (Val,1,InStr (Val,&amp;#039;)&amp;#039;)+1)||&amp;#039; local;&amp;#039;&lt;br /&gt;
End val&lt;br /&gt;
from&lt;br /&gt;
(select dbms_metadata.get_ddl (&amp;#039;INDEX&amp;#039;, index_name,&amp;#039;TEST&amp;#039;) Val from user_indexes where table_name in (select distinct table_name from user_tab_partitions))&lt;br /&gt;
union all&lt;br /&gt;
Select Val&lt;br /&gt;
from&lt;br /&gt;
(select dbms_metadata.get_dependent_ddl (&amp;#039;REF_CONSTRAINT&amp;#039;, table_name,&amp;#039;TEST&amp;#039;) Val&lt;br /&gt;
from user_tables where table_name in (select distinct table_name from user_tab_partitions join user_constraints using ( table_name)&lt;br /&gt;
where constraint_type=&amp;#039;R&amp;#039;))&lt;br /&gt;
union all&lt;br /&gt;
select Val&lt;br /&gt;
from&lt;br /&gt;
(select dbms_metadata.get_ddl (&amp;#039;CONSTRAINT&amp;#039;, constraint_name,&amp;#039;TEST&amp;#039;) Val&lt;br /&gt;
from user_constraints&lt;br /&gt;
where constraint_type=&amp;#039;P&amp;#039; and table_name in (select distinct table_name from user_tab_partitions)&lt;br /&gt;
)&lt;br /&gt;
union all&lt;br /&gt;
select to_clob (val)&lt;br /&gt;
from (select distinct &amp;#039;drop tablespace &amp;#039;||tablespace_name|| &amp;#039; including contents and datafiles;&amp;#039; val&lt;br /&gt;
from dba_tab_partitions&lt;br /&gt;
where tablespace_name in (select tablespace_name from dba_data_files where file_name like &amp;#039;%MISSING%&amp;#039;)&lt;br /&gt;
);&lt;br /&gt;
&lt;br /&gt;
spoo off&lt;br /&gt;
&lt;br /&gt;
@destroy_offending_objects&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORA-28112: failed to execute policy function===&lt;br /&gt;
when exporting or importing using [[Data Pump]]&amp;lt; /br&amp;gt;&lt;br /&gt;
During expdp is accompanied by &amp;quot;&amp;#039;&amp;#039;&amp;#039;ORA-31693: Table data object &amp;quot;SYSMAN&amp;quot;.&amp;quot;MGMT_IP_REPORT_DEF&amp;quot; failed to load/unload and is being skipped due to error:&amp;#039;&amp;#039;&amp;#039;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
===Reason===&lt;br /&gt;
This happens due to audit policies being defined on the table but the policy function is defined in another schema.&lt;br /&gt;
&lt;br /&gt;
===Solution===&lt;br /&gt;
Either drop the policy after importing the table with:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
begin&lt;br /&gt;
    for rec in (select * from dba_audit_policies where object_schema = &amp;#039;SYSMAN&amp;#039;) loop&lt;br /&gt;
        dbms_fga.drop_policy(object_schema =&amp;gt; rec.object_schema,&lt;br /&gt;
                             object_name =&amp;gt; rec.object_name,&lt;br /&gt;
                             policy_name =&amp;gt; rec.policy_name);  &lt;br /&gt;
    end loop;&lt;br /&gt;
end;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or exclude the policies during export by adding this to the .par file:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
exclude=FGA_POLICY&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or even better, give the necessary grants to the exporting user...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
grant exempt access policy to impexpusr;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The sysdba role has this automatically.&lt;br /&gt;
===ORA-17629: Cannot connect to the remote database server===&lt;br /&gt;
Active duplication fails to connect even though dns connection exists in tnsnames.ora&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
Problem:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
DUPLICATE TARGET DATABASE FROM ACTIVE DATABASE DORECOVER NOFILENAMECHECK;&lt;br /&gt;
&lt;br /&gt;
RMAN-03002: failure of Duplicate Db command at 05/27/2015 12:52:24&lt;br /&gt;
RMAN-05501: aborting duplication of target database&lt;br /&gt;
RMAN-03015: error occurred in stored script Memory Script&lt;br /&gt;
RMAN-03009: failure of backup command on ORA_DISK_1 channel at 05/27/2015 12:52:23&lt;br /&gt;
ORA-17629: Cannot connect to the remote database server&lt;br /&gt;
ORA-17627: ORA-12154: TNS:could not resolve the connect identifier specified&lt;br /&gt;
&lt;br /&gt;
ORA-17629: Cannot connect to the remote database server&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
Solution:&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
Update the tnsnames.ora of both destination &amp;#039;&amp;#039;&amp;#039;and&amp;#039;&amp;#039;&amp;#039; source ORACLE_HOMEs!&lt;br /&gt;
&lt;br /&gt;
===ORA-01950: no privileges on tablespace &amp;#039;SYSAUX&amp;#039;===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
26-JUN-15 03:12:27.545: &amp;gt;&amp;gt;&amp;gt; ORA-31642: the following SQL statement fails: &lt;br /&gt;
BEGIN &amp;quot;SYS&amp;quot;.&amp;quot;DBMS_RULE_EXP_RULES&amp;quot;.SCHEMA_CALLOUT(:1,0,1,&amp;#039;12.01.00.02.00&amp;#039;); END;&lt;br /&gt;
ORA-01950: no privileges on tablespace &amp;#039;SYSAUX&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Cause:&amp;#039;&amp;#039;&amp;#039;&amp;lt;br /&amp;gt;&lt;br /&gt;
In this case, it seems SYSMAN has no rights to create objects in the SYSAUX tablespace&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Solution:&amp;#039;&amp;#039;&amp;#039;&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter user SYSMAN quota unlimited on sysaux;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
More information [https://support.oracle.com/epmos/faces/SearchDocDisplay?_adf.ctrl-state=bov7jp5pq_4&amp;amp;_afrLoop=547371065896716#SYMPTOM here]&lt;br /&gt;
&lt;br /&gt;
===ORA-39080: failed to create queues &amp;quot;KUPC$C_1_20150616165037&amp;quot; and &amp;quot;KUPC$S_1_20150616165037&amp;quot; for Data Pump job===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
expdp /&lt;br /&gt;
&lt;br /&gt;
Export: Release 11.2.0.4.0 - Production on Tue Jun 16 16:50:36 2015&lt;br /&gt;
&lt;br /&gt;
Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.&lt;br /&gt;
&lt;br /&gt;
Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production&lt;br /&gt;
With the Partitioning, OLAP, Data Mining and Real Application Testing options&lt;br /&gt;
ORA-31626: job does not exist&lt;br /&gt;
ORA-31637: cannot create job SYS_EXPORT_SCHEMA_01 for user OPS$ORAIBM&lt;br /&gt;
ORA-06512: at &amp;quot;SYS.DBMS_SYS_ERROR&amp;quot;, line 95&lt;br /&gt;
ORA-06512: at &amp;quot;SYS.KUPV$FT_INT&amp;quot;, line 798&lt;br /&gt;
[[ORA-39080: failed to create queues &amp;quot;KUPC$C_1_20150616165037&amp;quot; and &amp;quot;KUPC$S_1_20150616165037&amp;quot; for Data Pump job]]&lt;br /&gt;
ORA-06512: at &amp;quot;SYS.DBMS_SYS_ERROR&amp;quot;, line 95&lt;br /&gt;
ORA-06512: at &amp;quot;SYS.KUPC$QUE_INT&amp;quot;, line 1534&lt;br /&gt;
ORA-24002: QUEUE_TABLE SYS.AQ$KUPC$DATAPUMP_QUETAB_1 does not exist&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Cause:====&lt;br /&gt;
Possibly some or all of OLAP module has got itself deinstalled.&lt;br /&gt;
====Solution:====&lt;br /&gt;
Try:&lt;br /&gt;
* Recompiling invalid objects. @?/rdbms/admin/utlrp&lt;br /&gt;
* Reinstalling DBMS_CUBE packages by (re)running catproc.sql. @?/rdbms/admin/catproc followed by @?/rdbms/admin/utlrp&lt;br /&gt;
* Reinstalling OLAP. @?/olap/admin/olap.sql SYSAUX TEMP; But see Metalink note ID 296187.1 for full instructions.&lt;br /&gt;
* Check metalink for bugs. See ID 345198.1 and possibly ID 453796.1&lt;br /&gt;
===ORA-14063: Unusable index exists on unique/primary constraint key===&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;ORA-39083: Object type CONSTRAINT failed to create with error:&amp;#039;&amp;#039;&amp;#039;&amp;lt;br /&amp;gt;&lt;br /&gt;
During an import datapump (impdp), import failed because indexes were in error before the tables were exported. This causes the import of rows to be skipped.&amp;lt;br /&amp;gt;&lt;br /&gt;
If the export cannot be done again (having compiled the indexes), then the metadata can be imported and the indexes compiled before importing the data.&lt;br /&gt;
* Import the metadata&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cat&amp;lt;&amp;lt;EOCAT &amp;gt;impdp_adst_ads_archive_metadata.par&lt;br /&gt;
userid=&amp;#039;/ as sysdba&amp;#039;&lt;br /&gt;
dumpfile=adst_ads_archive.dmp&lt;br /&gt;
logfile=impdp_adst_ads_archive_metadata.log&lt;br /&gt;
content=metadata_only&lt;br /&gt;
EOCAT&lt;br /&gt;
&lt;br /&gt;
impdp parfile=impdp_adst_ads_archive_metadata.par&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Find the bad indexes and recompile them&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select &amp;#039;alter index &amp;#039;|| owner||&amp;#039;.&amp;#039;||index_name||&amp;#039; rebuild online parallel 8;&amp;#039;&lt;br /&gt;
from   dba_indexes&lt;br /&gt;
where  status = &amp;#039;UNUSABLE&amp;#039;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Import the data&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cat&amp;lt;&amp;lt;EOCAT &amp;gt;impdp_adst_ads_archive_data.par&lt;br /&gt;
userid=&amp;#039;/ as sysdba&amp;#039;&lt;br /&gt;
dumpfile=adst_ads_archive.dmp&lt;br /&gt;
logfile=impdp_adst_ads_archive_data.log&lt;br /&gt;
table_exists_action=append&lt;br /&gt;
content=data_only&lt;br /&gt;
EOCAT&lt;br /&gt;
&lt;br /&gt;
impdp parfile=impdp_adst_ads_archive_data.par&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORA-09925: Unable to create audit trail file===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SQL&amp;gt; startup nomount pfile=&amp;quot;/oracle/TRSCRP1/admin/initTRSCRP1.ora&amp;quot;&lt;br /&gt;
ORA-09925: Unable to create audit trail file&lt;br /&gt;
SVR4 Error: 2: No such file or directory&lt;br /&gt;
Additional information: 9925&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
connected to auxiliary database (not started)&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-03002: failure of Duplicate Db command at 08/29/2017 15:53:09&lt;br /&gt;
RMAN-05501: aborting duplication of target database&lt;br /&gt;
RMAN-03015: error occurred in stored script Memory Script&lt;br /&gt;
RMAN-04014: startup failed: ORA-09925: Unable to create audit trail file&lt;br /&gt;
IBM AIX RISC System/6000 Error: 2: No such file or directory&lt;br /&gt;
Additional information: 9925&lt;br /&gt;
&lt;br /&gt;
Recovery Manager complete.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Problem====&lt;br /&gt;
This will be almost certainly one of two issues. Either the directory is not writable by the id that started the instance or the directory just does not exist.&lt;br /&gt;
====Solution====&lt;br /&gt;
Note there can be a difference between what you see when you type:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
show parameter audit&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
and when you type:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
strings -a $ORACLE_HOME/dbs/spfile${ORACLE_SID}.ora | grep -i audit&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
due to someone doing an &amp;quot;alter system&amp;quot; without the &amp;quot;scope=spfile&amp;quot; or &amp;quot;scope=both&amp;quot;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SQL&amp;gt; host ls -al /oracle/TRSCRP1/admin/adump&lt;br /&gt;
SQL&amp;gt; host mkdir /oracle/TRSCRP1/admin/adump&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===ORA-09925: Unable to create audit trail file===&lt;br /&gt;
When starting SQL*Plus with no db processes running (expecting to see &amp;quot;Connected to an idle instance&amp;quot;), we get this:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ERROR:&lt;br /&gt;
ORA-09925: Unable to create audit trail file&lt;br /&gt;
IBM AIX RISC System/6000 Error: 2: No such file or directory&lt;br /&gt;
Additional information: 9925&lt;br /&gt;
ORA-01075: you are currently logged on&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Filesystem permissions are fine&lt;br /&gt;
* &amp;#039;strings spfile&amp;lt;SID&amp;gt;.ora | grep audit&amp;#039; shows the correct directory&lt;br /&gt;
* Running on AIX&lt;br /&gt;
AIX is the clue here... need to check for semaphores and locked shared memory objects&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
(0) UCLID55D oraibm@solax082:/oracle/product/11.2.0.3/bin&amp;gt; sysresv&lt;br /&gt;
&lt;br /&gt;
IPC Resources for ORACLE_SID &amp;quot;UCLID55D&amp;quot; :&lt;br /&gt;
Shared Memory:&lt;br /&gt;
ID              KEY&lt;br /&gt;
8388640         0xffffffff&lt;br /&gt;
579862561       0xffffffff&lt;br /&gt;
384827426       0x326f32e8&lt;br /&gt;
&lt;br /&gt;
Semaphores:&lt;br /&gt;
ID              KEY&lt;br /&gt;
167772287       0xf09f4914&lt;br /&gt;
Oracle Instance alive for sid &amp;quot;UCLID55D&amp;quot;&lt;br /&gt;
&lt;br /&gt;
(0) UCLID55D oraibm@solax082:/oracle/product/11.2.0.3/bin&amp;gt; ipcrm -m 8388640&lt;br /&gt;
(0) UCLID55D oraibm@solax082:/oracle/product/11.2.0.3/bin&amp;gt; ipcrm -m 579862561&lt;br /&gt;
(0) UCLID55D oraibm@solax082:/oracle/product/11.2.0.3/bin&amp;gt; ipcrm -m 384827426&lt;br /&gt;
&lt;br /&gt;
(0) UCLID55D oraibm@solax082:/oracle/product/11.2.0.3/bin&amp;gt; ipcrm -s 167772287&lt;br /&gt;
&lt;br /&gt;
(0) UCLID55D oraibm@solax082:/oracle/product/11.2.0.3/bin&amp;gt; sysresv&lt;br /&gt;
&lt;br /&gt;
IPC Resources for ORACLE_SID &amp;quot;UCLID55D&amp;quot; :&lt;br /&gt;
Shared Memory&lt;br /&gt;
ID              KEY&lt;br /&gt;
No shared memory segments used&lt;br /&gt;
Semaphores:&lt;br /&gt;
ID              KEY&lt;br /&gt;
No semaphore resources used&lt;br /&gt;
Oracle Instance not alive for sid &amp;quot;UCLID55D&amp;quot;&lt;br /&gt;
&lt;br /&gt;
(0) UCLID55D oraibm@solax082:/oracle/product/11.2.0.3/bin&amp;gt; ps -ef | grep UCLID55D&lt;br /&gt;
oraibm 3326 23776 0 14:12:05 pts/1 0:00 grep UCLID55D &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===RMAN-06023: no backup or copy of datafile 1 found to restore===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-03002: failure of Duplicate Db command at 05/16/2018 16:08:13&lt;br /&gt;
RMAN-05501: aborting duplication of target database&lt;br /&gt;
RMAN-05556: not all datafiles have backups that can be recovered to SCN 278250901080&lt;br /&gt;
RMAN-03015: error occurred in stored script Memory Script&lt;br /&gt;
RMAN-06026: some targets not found - aborting restore&lt;br /&gt;
RMAN-06023: no backup or copy of datafile 7 found to restore&lt;br /&gt;
RMAN-06023: no backup or copy of datafile 6 found to restore&lt;br /&gt;
RMAN-06023: no backup or copy of datafile 5 found to restore&lt;br /&gt;
RMAN-06023: no backup or copy of datafile 4 found to restore&lt;br /&gt;
RMAN-06023: no backup or copy of datafile 3 found to restore&lt;br /&gt;
RMAN-06023: no backup or copy of datafile 2 found to restore&lt;br /&gt;
RMAN-06023: no backup or copy of datafile 1 found to restore&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Seems pretty straightforward? SCN was set too early for the retention period. But no, not this time.&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
RMAN&amp;gt; list backup of datafile 1;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
List of Backup Sets&lt;br /&gt;
===================&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
BS Key  Type LV Size       Device Type Elapsed Time Completion Time&lt;br /&gt;
------- ---- -- ---------- ----------- ------------ -------------------&lt;br /&gt;
110170340 Incr 0  132.90G    SBT_TAPE    00:18:32     2018-05-14 01:19:40&lt;br /&gt;
        BP Key: 110170345   Status: AVAILABLE  Compressed: NO  Tag: WEEKLY_FULL&lt;br /&gt;
        Handle: 24639762_REPORTA_07t2r3uk_1_1   Media: V_17152809_77191330&lt;br /&gt;
  List of Datafiles in backup set 110170340&lt;br /&gt;
  File LV Type Ckp SCN    Ckp Time            Name&lt;br /&gt;
  ---- -- ---- ---------- ------------------- ----&lt;br /&gt;
  1    0  Incr 277998128991 2018-05-14 01:01:08 /cln/acc/ora_data3/reporta/system01.dbf&lt;br /&gt;
&lt;br /&gt;
BS Key  Type LV Size       Device Type Elapsed Time Completion Time&lt;br /&gt;
------- ---- -- ---------- ----------- ------------ -------------------&lt;br /&gt;
110355808 Incr 1  204.00M    SBT_TAPE    00:05:13     2018-05-15 01:06:22&lt;br /&gt;
        BP Key: 110355813   Status: AVAILABLE  Compressed: NO  Tag: DAILY_INCREMENTAL&lt;br /&gt;
        Handle: 24661053_REPORTA_3ft2toal_1_1   Media: V_17173010_77253424&lt;br /&gt;
  List of Datafiles in backup set 110355808&lt;br /&gt;
  File LV Type Ckp SCN    Ckp Time            Name&lt;br /&gt;
  ---- -- ---- ---------- ------------------- ----&lt;br /&gt;
  1    1  Incr 278044267395 2018-05-15 01:01:09 /cln/acc/ora_data3/reporta/system01.dbf&lt;br /&gt;
&lt;br /&gt;
BS Key  Type LV Size       Device Type Elapsed Time Completion Time&lt;br /&gt;
------- ---- -- ---------- ----------- ------------ -------------------&lt;br /&gt;
110543802 Incr 1  237.00M    SBT_TAPE    00:05:51     2018-05-16 01:07:40&lt;br /&gt;
        BP Key: 110543807   Status: AVAILABLE  Compressed: NO  Tag: DAILY_INCREMENTAL&lt;br /&gt;
        Handle: 24681602_REPORTA_6nt30cnt_1_1   Media: V_17133646_77315270&lt;br /&gt;
  List of Datafiles in backup set 110543802&lt;br /&gt;
  File LV Type Ckp SCN    Ckp Time            Name&lt;br /&gt;
  ---- -- ---- ---------- ------------------- ----&lt;br /&gt;
  1    1  Incr 278286445856 2018-05-16 01:01:50 /cln/acc/ora_data3/reporta/system01.dbf&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
SCN was only 12 hours ago with a retention of 28 days! The backup piece dated 2018-05-15 01:06:22 is clearly available and on the device type set_tape.&amp;lt;br /&amp;gt;&lt;br /&gt;
The trick here was to look back through the logs and look more closely at what the file restore message was saying...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
channel t0: starting datafile backup set restore&lt;br /&gt;
channel t0: specifying datafile(s) to restore from backup set&lt;br /&gt;
channel t0: restoring datafile 00001 to /cln/acc/ora_data3/reporta/system01.dbf             &amp;lt; &amp;lt; &amp;lt; ==============&lt;br /&gt;
channel t0: reading from backup piece dbfull_REPORTA_738887052_967580186_116_1&lt;br /&gt;
channel t2: ORA-19870: error while restoring backup piece dbfull_REPORTA_738887052_967579750_113_1&lt;br /&gt;
ORA-19507: failed to retrieve sequential file, handle=&amp;quot;dbfull_REPORTA_738887052_967579750_113_1&amp;quot;, parms=&amp;quot;&amp;quot;&lt;br /&gt;
ORA-27029: skgfrtrv: sbtrestore returned error&lt;br /&gt;
ORA-19511: non RMAN, but media manager or vendor specific failure, error text:&lt;br /&gt;
   CreateOraObject20: Job[0] thread[55116090]: Restore: GetBackupInfo() for Archive File[dbfull_REPORTA_738887052_967579750_113_1] failed.&lt;br /&gt;
ORA-0651&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
It was not the fact that it could not find the data on tape, it was that it could not save the file to the location indicated!!&lt;br /&gt;
In the RMAN DUPLICATE script, I had all the file paths redirected (a mixture of convert parameters and spfile set) to a /restore filesystem.&amp;lt;br /&amp;gt;&lt;br /&gt;
But I forgot one!&amp;lt;br /&amp;gt;&lt;br /&gt;
A handy thing to do is to search out the file paths with this to see if something is still wrong:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cd $ORACLE_HOME/dbs&lt;br /&gt;
strings -a spfile${ORACLE_SID}.ora | grep dest&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This should show any paths still not getting caught by the DUPLICATE script.&lt;br /&gt;
&lt;br /&gt;
===RMAN-06136: ORACLE error from auxiliary database: ORA-06502: PL/SQL: numeric or value error===&lt;br /&gt;
When cloning a database, the duplicate fails with this error.&lt;br /&gt;
====Problem====&lt;br /&gt;
This duplicate had no target connection but did have a catalog and auxiliary connection.&lt;br /&gt;
In the catalog (which was the catalog where the target was registerd), there was also an entry in that catalog with the same name as the auxiliary - left over from the days when these 2 instances were Primary and Standby in a Dataguard configuration.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
Datafile 414 skipped by request&lt;br /&gt;
Datafile 415 skipped by request&lt;br /&gt;
Datafile 419 skipped by request&lt;br /&gt;
Datafile 420 skipped by request&lt;br /&gt;
Datafile 421 skipped by request&lt;br /&gt;
&lt;br /&gt;
DBGSQL:     AUXILIARY&amp;gt; begin :ofname := sys.dbms_backup_restore.convertFileName( fname   =&amp;gt;   :ifname, ftype   =&amp;gt;   :iftype, osftype =&amp;gt;   TRUE); end;&lt;br /&gt;
DBGSQL:        sqlcode = 6502&lt;br /&gt;
DBGSQL:         B :ofname = NULL&lt;br /&gt;
DBGSQL:         B :ifname =&lt;br /&gt;
DBGSQL:         B :iftype = 2&lt;br /&gt;
restarting auxiliary database without server parameter file&lt;br /&gt;
Oracle instance started&lt;br /&gt;
&lt;br /&gt;
Total System Global Area   32068440064 bytes&lt;br /&gt;
&lt;br /&gt;
Fixed Size                     2262200 bytes&lt;br /&gt;
Variable Size              16978545480 bytes&lt;br /&gt;
Database Buffers           15032385536 bytes&lt;br /&gt;
Redo Buffers                  55246848 bytes&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-03002: failure of Duplicate Db command at 10/04/2017 14:50:29&lt;br /&gt;
RMAN-05501: aborting duplication of target database&lt;br /&gt;
RMAN-06136: ORACLE error from auxiliary database: ORA-06502: PL/SQL: numeric or value error&lt;br /&gt;
&lt;br /&gt;
Recovery Manager complete.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Solution====&lt;br /&gt;
Connect to the catalog and unregister the name of the auxiliary database. It shouldn&amp;#039;t be there anyway.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rman catalog rmanusr/rmanpwd@rmancat&lt;br /&gt;
&lt;br /&gt;
Recovery Manager: Release 11.2.0.4.0 - Production on Wed Oct 4 15:00:00 2017&lt;br /&gt;
&lt;br /&gt;
Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.&lt;br /&gt;
&lt;br /&gt;
connected to recovery catalog database&lt;br /&gt;
&lt;br /&gt;
RMAN&amp;gt; set dbid 4260753020;&lt;br /&gt;
&lt;br /&gt;
executing command: SET DBID&lt;br /&gt;
database name is &amp;quot;LBK&amp;quot; and DBID is 4260753020&lt;br /&gt;
&lt;br /&gt;
RMAN&amp;gt; list db_unique_name of database;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
List of Databases&lt;br /&gt;
DB Key  DB Name  DB ID            Database Role    Db_unique_name&lt;br /&gt;
------- ------- ----------------- ---------------  ------------------&lt;br /&gt;
13301587 LBK      4260753020       PRIMARY          LBK&lt;br /&gt;
13301587 LBK      4260753020       STANDBY          ACC_PERF&lt;br /&gt;
13301587 LBK      4260753020       STANDBY          LBKRO&lt;br /&gt;
&lt;br /&gt;
RMAN&amp;gt; unregister db_unique_name &amp;#039;ACC_PERF&amp;#039;;&lt;br /&gt;
&lt;br /&gt;
database db_unique_name is &amp;quot;ACC_PERF&amp;quot;, db_name is &amp;quot;LBK&amp;quot; and DBID is 4260753020&lt;br /&gt;
&lt;br /&gt;
Want to unregister the database with target db_unique_name (enter YES or NO)? YES&lt;br /&gt;
database with db_unique_name ACC_PERF unregistered from the recovery catalog&lt;br /&gt;
&lt;br /&gt;
RMAN&amp;gt; exit&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORA-39181: Only partial table data may be exported due to fine grain access control on &amp;quot;owner&amp;quot;.&amp;quot;&amp;lt;table_name&amp;gt;&amp;quot;===&lt;br /&gt;
&lt;br /&gt;
===Reason===&lt;br /&gt;
This happens when applications are designed with fine-grained access.&lt;br /&gt;
===Solution===&lt;br /&gt;
Grant the necessary privileges to the exporting user...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
grant exempt access policy to ops$oraibm;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORA-04030: out of process memory when trying to allocate 2520 bytes===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
expdp problem (ORA-04030: out of process memory when trying to allocate 2520 bytes (pga heap,koh-kghu call heap))&lt;br /&gt;
&lt;br /&gt;
select value from v$pgastat where name=&amp;#039;maximum PGA allocated&amp;#039;;&lt;br /&gt;
&lt;br /&gt;
SHOW PARAMETER TARGET&lt;br /&gt;
&lt;br /&gt;
ORA-04030: out of process memory when trying to allocate 2520 bytes (pga heap,koh-kghu call heap)&lt;br /&gt;
&lt;br /&gt;
alter system reset pga_aggregate_target scope=spfile;&lt;br /&gt;
&lt;br /&gt;
show sga&lt;br /&gt;
&lt;br /&gt;
select * from v$pgastat;&lt;br /&gt;
&lt;br /&gt;
show parameter process&lt;br /&gt;
&lt;br /&gt;
select sum(value)/1024/1024 Mb&lt;br /&gt;
from   v$sesstat s, v$statname n&lt;br /&gt;
where  1=1&lt;br /&gt;
and    n.STATISTIC# = s.STATISTIC#&lt;br /&gt;
and    name = &amp;#039;session pga memory&amp;#039;&lt;br /&gt;
&lt;br /&gt;
show parameter WORKAREA&lt;br /&gt;
&lt;br /&gt;
select value from v$pgastat where name=&amp;#039;maximum PGA allocated&amp;#039;;&lt;br /&gt;
&lt;br /&gt;
alter system set memory_max_target=10G scope=spfile;&lt;br /&gt;
&lt;br /&gt;
alter system set memory_target=3G scope=both;&lt;br /&gt;
&lt;br /&gt;
select * from v$memory_target_advice order by memory_size;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORA-04031: unable to allocate 32 bytes of shared memory (&amp;quot;shared pool&amp;quot;,&amp;quot;select name,online$,contents...&amp;quot;,&amp;quot;KGLH0^e5705bfc&amp;quot;,&amp;quot;kglHeapInitialize:temp&amp;quot;)===&lt;br /&gt;
* [https://blogs.oracle.com/db/entry/ora-4031_troubleshooting ORA-4031 Troubleshooting]&lt;br /&gt;
* [https://support.oracle.com/epmos/faces/DocumentDisplay?_afrLoop=89215376348478&amp;amp;id=396940.1&amp;amp;_afrWindowMode=0&amp;amp;_adf.ctrl-state=u1z0xcppg_4 Troubleshooting and Diagnosing ORA-4031 Error - (Doc ID 396940.1)]&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ORA-04031: unable to allocate  bytes of shared memory (&amp;quot;&amp;quot;,&amp;quot;&amp;quot;,&amp;quot;&amp;quot;,&amp;quot;&amp;quot;) &lt;br /&gt;
ORA-04031: unable to allocate 32 bytes of shared memory (&amp;quot;shared pool&amp;quot;,&amp;quot;select name,online$,contents...&amp;quot;,&amp;quot;KGLH0^e5705bfc&amp;quot;,&amp;quot;kglHeapInitialize:temp&amp;quot;) &lt;br /&gt;
Incident details in: /oracle/diag/rdbms/mape/MAPE/incident/incdir_86754/MAPE_dm00_14221536_i86754.trc &lt;br /&gt;
Wed Jul 31 20:42:50 2013 &lt;br /&gt;
Dumping diagnostic data in directory=[cdmp_20130731204250], requested by (instance=1, osid=14221536 (DM00)), summary=[incident=86753]. &lt;br /&gt;
Wed Jul 31 20:42:51 2013 &lt;br /&gt;
Sweep [inc][86754]: completed &lt;br /&gt;
Sweep [inc][86753]: completed &lt;br /&gt;
Sweep [inc2][86753]: completed &lt;br /&gt;
Wed Jul 31 20:42:57 2013 &lt;br /&gt;
Use ADRCI or Support Workbench to package the incident. &lt;br /&gt;
See Note 411.1 at My Oracle Support for error and packaging details. &lt;br /&gt;
Dumping diagnostic data in directory=[cdmp_20130731204257], requested by (instance=1, osid=14221536 (DM00)), summary=[incident=86754]. &lt;br /&gt;
Wed Jul 31 20:43:35 2013 &lt;br /&gt;
Errors in file /oracle/diag/rdbms/mape/MAPE/trace/MAPE_dw02_40567024.trc  (incident=82993): &lt;br /&gt;
ORA-04031: unable to allocate 32 bytes of shared memory (&amp;quot;shared pool&amp;quot;,&amp;quot;select order#,columns,types ...&amp;quot;,&amp;quot;KGLH0^470434f8&amp;quot;,&amp;quot;kglHeapInitialize:temp&amp;quot;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Database had already crashed so nothing to do but:&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
(0) MAPE ora@x025:/home/ora&amp;gt; sqlplus / as sysdba&lt;br /&gt;
&lt;br /&gt;
SQL*Plus: Release 11.2.0.3.0 Production on Fri Aug 2 14:26:20 2013&lt;br /&gt;
&lt;br /&gt;
Copyright (c) 1982, 2011, Oracle.  All rights reserved.&lt;br /&gt;
&lt;br /&gt;
Connected.&lt;br /&gt;
SYS@MAPE&amp;gt; alter system flush shared_pool;&lt;br /&gt;
alter system flush shared_pool&lt;br /&gt;
*&lt;br /&gt;
ERROR at line 1:&lt;br /&gt;
ORA-01012: not logged on&lt;br /&gt;
Process ID: 0&lt;br /&gt;
Session ID: 0 Serial number: 0&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
SYS@MAPE&amp;gt; shutdown abort&lt;br /&gt;
ORACLE instance shut down.&lt;br /&gt;
SYS@MAPE&amp;gt; startup&lt;br /&gt;
ORACLE instance started.&lt;br /&gt;
&lt;br /&gt;
Total System Global Area  734892032 bytes&lt;br /&gt;
Fixed Size                  2225128 bytes&lt;br /&gt;
Variable Size             398461976 bytes&lt;br /&gt;
Database Buffers          318767104 bytes&lt;br /&gt;
Redo Buffers               15437824 bytes&lt;br /&gt;
Database mounted.&lt;br /&gt;
Database opened.&lt;br /&gt;
&lt;br /&gt;
SYS@MAPE&amp;gt; show parameter pool&lt;br /&gt;
&lt;br /&gt;
NAME                                 TYPE                           VALUE&lt;br /&gt;
------------------------------------ ------------------------------ ------------------------------&lt;br /&gt;
buffer_pool_keep                     string&lt;br /&gt;
buffer_pool_recycle                  string&lt;br /&gt;
global_context_pool_size             string&lt;br /&gt;
java_pool_size                       big integer                    0&lt;br /&gt;
large_pool_size                      big integer                    0&lt;br /&gt;
olap_page_pool_size                  big integer                    0&lt;br /&gt;
shared_pool_reserved_size            big integer                    18M&lt;br /&gt;
shared_pool_size                     big integer                    208M&lt;br /&gt;
streams_pool_size                    big integer                    0&lt;br /&gt;
SYS@MAPE&amp;gt; show sga&lt;br /&gt;
&lt;br /&gt;
Total System Global Area  734892032 bytes&lt;br /&gt;
Fixed Size                  2225128 bytes&lt;br /&gt;
Variable Size             385879064 bytes&lt;br /&gt;
Database Buffers          331350016 bytes&lt;br /&gt;
Redo Buffers               15437824 bytes&lt;br /&gt;
SYS@MAPE&amp;gt; exit&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
but for reference, the causes could well be the applications running on the database are not using bind variables...&amp;lt;br /&amp;gt;&lt;br /&gt;
From [http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:528893984337 asktom.oracle.com]&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
Just to give you a tiny idea of how huge of a difference this &lt;br /&gt;
can make performance wise, you only need to run a very small &lt;br /&gt;
test:&lt;br /&gt;
&lt;br /&gt;
tkyte@TKYTE816&amp;gt; alter system flush shared_pool;&lt;br /&gt;
System altered.&lt;br /&gt;
&lt;br /&gt;
tkyte@TKYTE816&amp;gt; declare&lt;br /&gt;
  2      type rc is ref cursor;&lt;br /&gt;
  3      l_rc rc;&lt;br /&gt;
  4      l_dummy all_objects.object_name%type;&lt;br /&gt;
  5      l_start number default dbms_utility.get_time;&lt;br /&gt;
  6  begin&lt;br /&gt;
  7      for i in 1 .. 1000&lt;br /&gt;
  8      loop&lt;br /&gt;
  9          open l_rc for&lt;br /&gt;
 10          &amp;#039;select object_name&lt;br /&gt;
 11             from all_objects&lt;br /&gt;
 12            where object_id = &amp;#039; || i;&lt;br /&gt;
 13          fetch l_rc into l_dummy;&lt;br /&gt;
 14          close l_rc;&lt;br /&gt;
 15      end loop;&lt;br /&gt;
 16      dbms_output.put_line&lt;br /&gt;
 17      ( round( (dbms_utility.get_time-l_start)/100, 2 ) ||&lt;br /&gt;
 18        &amp;#039; seconds...&amp;#039; );&lt;br /&gt;
 19  end;&lt;br /&gt;
 20  /&lt;br /&gt;
14.86 seconds...&lt;br /&gt;
&lt;br /&gt;
PL/SQL procedure successfully completed.&lt;br /&gt;
&lt;br /&gt;
tkyte@TKYTE816&amp;gt; declare&lt;br /&gt;
  2      type rc is ref cursor;&lt;br /&gt;
  3      l_rc rc;&lt;br /&gt;
  4      l_dummy all_objects.object_name%type;&lt;br /&gt;
  5      l_start number default dbms_utility.get_time;&lt;br /&gt;
  6  begin&lt;br /&gt;
  7      for i in 1 .. 1000&lt;br /&gt;
  8      loop&lt;br /&gt;
  9          open l_rc for&lt;br /&gt;
 10          &amp;#039;select object_name&lt;br /&gt;
 11             from all_objects&lt;br /&gt;
 12            where object_id = :x&amp;#039;&lt;br /&gt;
 13          using i;&lt;br /&gt;
 14          fetch l_rc into l_dummy;&lt;br /&gt;
 15          close l_rc;&lt;br /&gt;
 16      end loop;&lt;br /&gt;
 17      dbms_output.put_line&lt;br /&gt;
 18      ( round( (dbms_utility.get_time-l_start)/100, 2 ) ||&lt;br /&gt;
 19        &amp;#039; seconds...&amp;#039; );&lt;br /&gt;
 20  end;&lt;br /&gt;
 21  /&lt;br /&gt;
1.27 seconds...&lt;br /&gt;
&lt;br /&gt;
PL/SQL procedure successfully completed.&lt;br /&gt;
&lt;br /&gt;
That is pretty dramatic.  The fact is that not only does this &lt;br /&gt;
execute much faster (we spent more time PARSING our queries then &lt;br /&gt;
actually EXECUTING them!) it will let more users use your system &lt;br /&gt;
simultaneously.&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
and from [http://asktom.oracle.com/pls/asktom/f?p=100:11:::::P11_QUESTION_ID:1163635055580 linked question]&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
Lbrary cache latch contention is typically caused by NOT using bind variables.  It is due &lt;br /&gt;
to excessive parsing of statements.&lt;br /&gt;
&lt;br /&gt;
One way to see if this might be the case in your situation is to run a script like:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
create table t1 as select sql_text from v$sqlarea;&lt;br /&gt;
&lt;br /&gt;
alter table t1 add sql_text_wo_constants varchar2(1000);&lt;br /&gt;
&lt;br /&gt;
create or replace function &lt;br /&gt;
remove_constants( p_query in varchar2 ) return varchar2&lt;br /&gt;
as&lt;br /&gt;
    l_query long;&lt;br /&gt;
    l_char  varchar2(1);&lt;br /&gt;
    l_in_quotes boolean default FALSE;&lt;br /&gt;
begin&lt;br /&gt;
    for i in 1 .. length( p_query )&lt;br /&gt;
    loop&lt;br /&gt;
        l_char := substr(p_query,i,1);&lt;br /&gt;
        if ( l_char = &amp;#039;&amp;#039;&amp;#039;&amp;#039; and l_in_quotes )&lt;br /&gt;
        then&lt;br /&gt;
            l_in_quotes := FALSE;&lt;br /&gt;
        elsif ( l_char = &amp;#039;&amp;#039;&amp;#039;&amp;#039; and NOT l_in_quotes )&lt;br /&gt;
        then&lt;br /&gt;
            l_in_quotes := TRUE;&lt;br /&gt;
            l_query := l_query || &amp;#039;&amp;#039;&amp;#039;#&amp;#039;;&lt;br /&gt;
        end if;&lt;br /&gt;
        if ( NOT l_in_quotes ) then&lt;br /&gt;
            l_query := l_query || l_char;&lt;br /&gt;
        end if;&lt;br /&gt;
    end loop;&lt;br /&gt;
    l_query := translate( l_query, &amp;#039;0123456789&amp;#039;, &amp;#039;@@@@@@@@@@&amp;#039; );&lt;br /&gt;
    for i in 0 .. 8 loop&lt;br /&gt;
        l_query := replace( l_query, lpad(&amp;#039;@&amp;#039;,10-i,&amp;#039;@&amp;#039;), &amp;#039;@&amp;#039; );&lt;br /&gt;
        l_query := replace( l_query, lpad(&amp;#039; &amp;#039;,10-i,&amp;#039; &amp;#039;), &amp;#039; &amp;#039; );&lt;br /&gt;
    end loop;&lt;br /&gt;
    return upper(l_query);&lt;br /&gt;
end;&lt;br /&gt;
/&lt;br /&gt;
update t1 set sql_text_wo_constants = remove_constants(sql_text);&lt;br /&gt;
&lt;br /&gt;
select sql_text_wo_constants, count(*)&lt;br /&gt;
  from t1&lt;br /&gt;
 group by sql_text_wo_constants&lt;br /&gt;
having count(*) &amp;gt; 100&lt;br /&gt;
 order by 2&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The output of that last query will show you statements that are identical in the shared &lt;br /&gt;
pool after all numbers and character string constants have been removed.  These &lt;br /&gt;
statements -- and more importantly their counts -- are the potential bottlenecks.  In &lt;br /&gt;
addition to causing the contention, they will be HUGE cpu consumers.  &lt;br /&gt;
&lt;br /&gt;
If you discover your applications do not use bind variables -- you must have this &lt;br /&gt;
corrected.  You&amp;#039;ll never have a good hit ratio if everyone submits &amp;quot;unique&amp;quot; sql.  Your &lt;br /&gt;
shared pool will never be used right and you&amp;#039;ll be using excessive CPU (90% of the time &lt;br /&gt;
it takes to process &amp;quot;insert into t values ( 1 )&amp;quot; is parsing.  If you use &amp;quot;insert into t &lt;br /&gt;
values ( :x )&amp;quot;, and bind the value of 1 -- then the next person that runs that insert &lt;br /&gt;
will benefit from your work and run that much faster. &lt;br /&gt;
...&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Advice from Oracle concerning a concrete (12c) example of unable to allocate 52824 bytes of shared memory (&amp;quot;shared pool&amp;quot;,...====&lt;br /&gt;
This was from a ticket raised for a Data Pump export that consistently failed with:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Processing object type SCHEMA_EXPORT/TABLE/PROCACT_INSTANCE&lt;br /&gt;
Processing object type SCHEMA_EXPORT/TABLE/TABLE&lt;br /&gt;
ORA-39014: One or more workers have prematurely exited.&lt;br /&gt;
ORA-39029: worker 1 with process name &amp;quot;DW00&amp;quot; prematurely terminated&lt;br /&gt;
ORA-31671: Worker process DW00 had an unhandled exception.&lt;br /&gt;
ORA-04031: unable to allocate 52824 bytes of shared memory (&amp;quot;shared pool&amp;quot;,&amp;quot;unknown object&amp;quot;,&amp;quot;KTSL subheap&amp;quot;,&amp;quot;ktsl_load_disp-2&amp;quot;)&lt;br /&gt;
ORA-06512: at &amp;quot;SYS.KUPW$WORKER&amp;quot;, line 2122&lt;br /&gt;
ORA-06512: at line 2&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
The error ORA-4031 on the shared pool can indicate one of two things:&lt;br /&gt;
- insufficient space for the shared pool (so insufficient memory in SGA at that time)&lt;br /&gt;
OR&lt;br /&gt;
- although there is enough memory, it is fragmented and no contiguous chunk can be allocated to satisfy the latest memory request.&lt;br /&gt;
&lt;br /&gt;
Each SGA has a little fragmentation of course because of the operations taking place, so in your case the fragmentation is represented by the 18M of free memory, which exists in uncontiguous chunks.&lt;br /&gt;
This means that the root cause of the error is insufficient contiguous memory to allocate 12312 bytes of shared memory.&lt;br /&gt;
&lt;br /&gt;
ACTION PLAN&lt;br /&gt;
==============&lt;br /&gt;
1. We see memory_target=2000M. This is too little to support a 12c database, even when it has little activity.&lt;br /&gt;
As you may know 1.7G for the SGA was acceptable when speaking of 32bit OSs where it was hardly possible to make use of more than that.&lt;br /&gt;
Since you have a 64 bit system, the addressable memory is virtually unlimited.&lt;br /&gt;
Furthermore, by using AMM (memory_target&amp;gt;0) this memory is divided between the SGA and the PGA (the user processes) which in fact, depending on the number of connections, can limit the SGA even more.&lt;br /&gt;
So the first recommendation is to increase the value of memory_target to 4G for example. There is no ideal value, but this would be a reasonable starting value for tuning.&lt;br /&gt;
&lt;br /&gt;
You can do further tuning of the memory using the view V$MEMORY_TARGET_ADVICE.&lt;br /&gt;
The view V$MEMORY_TARGET_ADVICE provides tuning advice for the MEMORY_TARGET initialization parameter:&lt;br /&gt;
SQL&amp;gt; SELECT * FROM v$memory_target_advice ORDER BY memory_size;&lt;br /&gt;
&lt;br /&gt;
The dynamic performance view V$MEMORY_DYNAMIC_COMPONENTS shows the current sizes of all dynamically tuned memory components, including the total sizes of the SGA and instance PGA.&lt;br /&gt;
&lt;br /&gt;
You can also use V$MEMORY_RESIZE_OPS which has a circular history buffer of the last 800 memory resize requests.&lt;br /&gt;
&lt;br /&gt;
2. Since the AMM (you have memory_target&amp;gt;0) is used, then make sure to set:&lt;br /&gt;
 _shared_pool_reserved_pct to 10 or 15 to ensure that when the Shared Pool grows or shrinks automatically, the Reserved Area will change as well.&lt;br /&gt;
&lt;br /&gt;
SQL&amp;gt; alter system set &amp;quot;_shared_pool_reserved_pct&amp;quot;=15 scope=spfile;&lt;br /&gt;
--restart the instance&lt;br /&gt;
&lt;br /&gt;
FYI: By default, Oracle configures a small Reserved Pool (or Reserved Area) inside the Shared Pool.&lt;br /&gt;
This memory can be used for operations such as PL/SQL and trigger compilation or for temporary space while loading Java objects.&lt;br /&gt;
After the memory allocated from the Reserved Pool is freed, it returns to the Reserved Pool.&lt;br /&gt;
5% of the Shared Pool is set aside as the Reserved Pool to handle allocations of memory higher than defined by the hidden parameter _shared_pool_reserved_pct.&lt;br /&gt;
In some application environments, 5% is too small.&lt;br /&gt;
&lt;br /&gt;
3. Set shared_pool_size=500M or even more. This will represent a minimum amount of memory that will always be available to the shared pool.&lt;br /&gt;
If more memory is needed at any moment, if it is available, it will be allocated to the shared pool over the 500M.&lt;br /&gt;
&lt;br /&gt;
Implement the above steps, monitor the database and let us know the result,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORA-00392: log 1 of thread 1 is being cleared, operation not allowed===&lt;br /&gt;
After performing an active duplication, this happened when trying to open the database.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SQL&amp;gt; alter database open resetlogs&lt;br /&gt;
alter database open resetlogs&lt;br /&gt;
*&lt;br /&gt;
ERROR at line 1:&lt;br /&gt;
ORA-00392: log 1 of thread 1 is being cleared, operation not allowed&lt;br /&gt;
ORA-00312: online log 1 thread 1: &amp;#039;/oracle/oradata/testdb/redo/redo01.log&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SQL&amp;gt; select group#,thread#,status from v$log;&lt;br /&gt;
 &lt;br /&gt;
GROUP#   THREAD#   STATUS&lt;br /&gt;
-------  --------- ----------------&lt;br /&gt;
1        1         CLEARING_CURRENT&lt;br /&gt;
2        1         STALE&lt;br /&gt;
3        1         STALE&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Check the alert log! Always a good idea to get extra info. In here we find the answer&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ORA-00344: unable to re-create online log&lt;br /&gt;
&amp;#039;/oracle/oradata/testdb/redo/redo01.log&amp;#039;&lt;br /&gt;
ORA-27040: file create error, unable to create file&lt;br /&gt;
Linux-x86_64 Error: 2: No such file or directory&lt;br /&gt;
Additional information: 1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
So the clue is that the file cannot be created at the operating system level.&amp;lt;br /&amp;gt;&lt;br /&gt;
Doing a &amp;lt;code&amp;gt;df -k /oracle/oradata/testdb/redo&amp;lt;/code&amp;gt; shows us that the filesystem was created too small for the destination database.&amp;lt;br /&amp;gt;&lt;br /&gt;
In this case, we do not want the redolog directory to be as big as on the source db as there will be almost no movement on the destination.&amp;lt;br /&amp;gt;&lt;br /&gt;
I should have specified the LOGFILE parameter in the DUPLICATE clause to setup new, smaller redolog files.&amp;lt;br /&amp;gt;&lt;br /&gt;
As this duplicate takes over 12 hours, I didn&amp;#039;t want to do it again so I created symbolic links in the redolog directory pointing out to a larger filesystem with more space.&amp;lt;br /&amp;gt;&lt;br /&gt;
This allowed the creation of the redolog files. They can then be resized once the database has been opened.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cd /oracle/oradata/testdb/redo&lt;br /&gt;
ln -s /tmp/redo01.log redo01.log&lt;br /&gt;
ln -s /tmp/redo02.log redo02.log&lt;br /&gt;
ln -s /tmp/redo03.log redo03.log&lt;br /&gt;
&lt;br /&gt;
SQL&amp;gt; alter database open resetlogs&lt;br /&gt;
Database opened.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===RMAN-04004: error from recovery catalog database: ORA-01017: invalid username/password; logon denied===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
oracle@host:/export/home/ora&amp;gt; rman target / catalog catowner/catpass@catdb&lt;br /&gt;
&lt;br /&gt;
Recovery Manager: Release 11.2.0.2.0 - Production on Thu Jun 12 16:51:03 2014&lt;br /&gt;
&lt;br /&gt;
Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.&lt;br /&gt;
&lt;br /&gt;
connected to target database: XXXXRAP1 (DBID=3557010742)&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-00554: initialization of internal recovery manager package failed&lt;br /&gt;
RMAN-04004: error from recovery catalog database: ORA-01017: invalid username/password; logon denied&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This is normally very straight-forward and self-explanatory.&amp;lt;br /&amp;gt;&lt;br /&gt;
The puzzle here is that a connection from SQL*Plus works!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sqlplus catowner/catpass@catdb&lt;br /&gt;
&lt;br /&gt;
SQL*Plus: Release 11.2.0.2.0 Production on Thu Jun 12 16:53:18 2014&lt;br /&gt;
&lt;br /&gt;
Copyright (c) 1982, 2010, Oracle.  All rights reserved.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Connected to:&lt;br /&gt;
Oracle Database 12c Enterprise Edition Release 12.1.0.1.0 - 64bit Production&lt;br /&gt;
With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options&lt;br /&gt;
SQL&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Eventually worked out that the rman binary in the databases ORACLE_HOME on the source machine needed relinking!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cd $ORACLE_HOME/rdbms/lib&lt;br /&gt;
make -f ins_rdbms.mk irman &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORA-00230: operation disallowed: snapshot control file enqueue unavailable===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
waiting for snapshot control file enqueue&lt;br /&gt;
waiting for snapshot control file enqueue&lt;br /&gt;
waiting for snapshot control file enqueue&lt;br /&gt;
waiting for snapshot control file enqueue&lt;br /&gt;
cannot make a snapshot control file&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-03008: error while performing automatic resync of recovery catalog&lt;br /&gt;
ORA-00230: operation disallowed: snapshot control file enqueue unavailable&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
From the doc...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
When RMAN needs to back up or resynchronize from the control file, it first creates a snapshot or consistent image of the control file.&lt;br /&gt;
If one RMAN job is already backing up the control file while another needs to create a new snapshot control file, then you may see the following message:&lt;br /&gt;
&lt;br /&gt;
waiting for snapshot controlfile enqueue&lt;br /&gt;
&lt;br /&gt;
Under normal circumstances, a job that must wait for the control file enqueue waits for a brief interval and then successfully obtains the enqueue.&lt;br /&gt;
RMAN makes up to five attempts to get the enqueue and then fails the job.&lt;br /&gt;
The conflict is usually caused when two jobs are both backing up the control file, and the job that first starts backing up the control file waits for service from the media manager.&lt;br /&gt;
&lt;br /&gt;
To determine which job is holding the conflicting enqueue:&lt;br /&gt;
&lt;br /&gt;
    After you see the first message stating &amp;quot;RMAN-08512: waiting for snapshot controlfile enqueue&amp;quot;, start a new SQL*Plus session on the target database:&lt;br /&gt;
&lt;br /&gt;
    % sqlplus &amp;#039;SYS/oracle@trgt AS SYSDBA&amp;#039;&lt;br /&gt;
&lt;br /&gt;
    Execute the following query to determine which job is causing the wait:&lt;br /&gt;
&lt;br /&gt;
    SELECT s.SID, USERNAME AS &amp;quot;User&amp;quot;, PROGRAM, MODULE, &lt;br /&gt;
           ACTION, LOGON_TIME &amp;quot;Logon&amp;quot;, l.* &lt;br /&gt;
    FROM V$SESSION s, V$ENQUEUE_LOCK l&lt;br /&gt;
    WHERE l.SID = s.SID&lt;br /&gt;
    AND l.TYPE = &amp;#039;CF&amp;#039;&lt;br /&gt;
    AND l.ID1 = 0&lt;br /&gt;
    AND l.ID2 = 2;&lt;br /&gt;
&lt;br /&gt;
    You should see output similar to the following (the output in this example has been truncated):&lt;br /&gt;
&lt;br /&gt;
    SID User Program              Module                    Action           Logon&lt;br /&gt;
    --- ---- -------------------- ------------------------- ---------------- ---------&lt;br /&gt;
      9 SYS  rman@h13 (TNS V1-V3) backup full datafile: c1  0000210 STARTED  21-JUN-01&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
After you have determined which job is creating the enqueue, you can do one of the following:&lt;br /&gt;
&lt;br /&gt;
    Wait until the job creating the enqueue completes&lt;br /&gt;
    Cancel the current job and restart it after the job creating the enqueue completes&lt;br /&gt;
    Cancel the job creating the enqueue&lt;br /&gt;
&lt;br /&gt;
Commonly, enqueue situations occur when a job is writing to a tape drive, but the tape drive is waiting for a new cassette to be inserted.&lt;br /&gt;
If you start a new job in this situation, then you will probably receive the enqueue message because the first job cannot complete until the new tape is loaded.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or more directly...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 2000&lt;br /&gt;
col killer     for a70&lt;br /&gt;
col program    for a20&lt;br /&gt;
col module     for a20&lt;br /&gt;
col action     for a20&lt;br /&gt;
col logon_time for a20&lt;br /&gt;
select &amp;#039;alter system disconnect session &amp;#039;&amp;#039;&amp;#039;||s.sid||&amp;#039;,&amp;#039;||s.serial#||&amp;#039;&amp;#039;&amp;#039; immediate;&amp;#039; killer&lt;br /&gt;
,      username&lt;br /&gt;
,      program&lt;br /&gt;
,      module&lt;br /&gt;
,      action&lt;br /&gt;
,      logon_time&lt;br /&gt;
from   v$session s&lt;br /&gt;
,      v$enqueue_lock l&lt;br /&gt;
where  l.sid  = s.sid&lt;br /&gt;
and    l.type = &amp;#039;cf&amp;#039;&lt;br /&gt;
and    l.id1  = 0&lt;br /&gt;
and    l.id2  = 2&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORA-19511: non RMAN, but media manager or vendor specific failure, error text:===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-03002: failure of Duplicate Db command at 05/01/2018 14:23:09&lt;br /&gt;
RMAN-05501: aborting duplication of target database&lt;br /&gt;
RMAN-03015: error occurred in stored script Memory Script&lt;br /&gt;
ORA-27191: sbtinfo2 returned error&lt;br /&gt;
Additional information: 3586&lt;br /&gt;
ORA-19511: non RMAN, but media manager or vendor specific failure, error text:&lt;br /&gt;
   Unable to connect to NetWorker server &amp;#039;hn6000.cln.be&amp;#039; because &amp;#039;Authentication error; why = Invalid client credential&amp;#039;. (2:10:79)&lt;br /&gt;
&lt;br /&gt;
Recovery Manager complete.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
If this happens, check to see if the nsr daemon is running...&amp;lt;br /&amp;gt;&lt;br /&gt;
Good system:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/home/oracle&amp;gt; ps -ef | grep nsr&lt;br /&gt;
    root  5701836        1   0   Mar 16      - 13:18 /bin/nsrexecd&lt;br /&gt;
  oracle 18809292 22741502   0 15:03:58  pts/0  0:00 grep nsr&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Bad system:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 /home/oracle&amp;gt; ps -ef | grep nsr&lt;br /&gt;
  oracle 14745986 15139292   0 15:03:29  pts/2  0:00 grep nsr&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORA-19554: error allocating device, device type: SBT_TAPE, device name:===&lt;br /&gt;
If using Cygwin...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-03002: failure of backup command at 05/19/2015 12:25:47&lt;br /&gt;
ORA-19554: error allocating device, device type: SBT_TAPE, device name:&lt;br /&gt;
ORA-27000: skgfqsbi: failed to initialize storage subsystem (SBT) layer&lt;br /&gt;
OSD-02534: Message 2534 not found;  product=RDBMS; facility=SOSD&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Check the tdpo.opt file is where you think it is!&lt;br /&gt;
* Check the path to the opt file looks like this (needs to be Windows format):&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
CONFIGURE CHANNEL DEVICE TYPE &amp;#039;SBT_TAPE&amp;#039; FORMAT   &amp;#039;LOG_%d_t%t_s%s_u%U&amp;#039; PARMS  &amp;#039;ENV=(TDPO_OPTFILE=E:\oracle\KITRYD\admin\tdpo.opt)&amp;#039;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Check the content of the opt file is Windows format paths!&lt;br /&gt;
&lt;br /&gt;
===RMAN-20033: control file SEQUENCE# too low===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-03008: error while performing automatic resync of recovery catalog&lt;br /&gt;
===RMAN-20033: control file SEQUENCE# too low===&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
From [https://forums.oracle.com/forums/thread.jspa?threadID=1115969 forums.oracle.com]&amp;lt;br /&amp;gt;&lt;br /&gt;
This error generally happens if an archivelog backup happens while the RMAN database backup is running and if controlfile autobackup is configured.&amp;lt;br /&amp;gt;&lt;br /&gt;
The database backup is usually successful and it is just the controlfile backup that fails.&lt;br /&gt;
===ORA-27302: failure occurred at: slgpn===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
RMAN-03009: failure of Control File and SPFILE Autobackup command on c1 channel at 06/28/2011 18:59:38&lt;br /&gt;
ORA-19715: invalid format %b for generated name&lt;br /&gt;
ORA-27302: failure occurred at: slgpn&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Problem====&lt;br /&gt;
When doing a &amp;quot;&amp;lt;tt&amp;gt;backup as copy database&amp;lt;/tt&amp;gt;&amp;quot;, got these errors after 145 of 147 datafiles had been backed up!&lt;br /&gt;
&lt;br /&gt;
====Investigation====&lt;br /&gt;
I had read [https://oracleedge.wordpress.com/2011/06/29/oracle-rman-03009-ora-19715-ora-27302/ elsewhere] that this could be something to do with the format of the autobackup of the control file so I changed the format as suggested and reran the backup.&amp;lt;br /&amp;gt;&lt;br /&gt;
No luck. It ended exactly the same way after 145 files. I decided to compare the original list of datafiles with those that had been backed up in order to track down the 2 failures. Maybe I could see something odd with them.&amp;lt;br /&amp;gt;&lt;br /&gt;
Sure enough, these 2 files were different... there was a space at the &amp;#039;&amp;#039;&amp;#039;end&amp;#039;&amp;#039;&amp;#039; of the filenames :-)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select &amp;#039;x&amp;#039;||file_name||&amp;#039;x&amp;#039;&lt;br /&gt;
from   dba_data_files&lt;br /&gt;
where  file_name like &amp;#039;% %&amp;#039;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Solution====&lt;br /&gt;
Run the backup of the other 2 datafiles with a different format that did not rely on the filename.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
run {&lt;br /&gt;
    allocate channel c1 device type disk format &amp;#039;/path/to/datafiles/%U&amp;#039;;&lt;br /&gt;
    backup as copy datafile 170;&lt;br /&gt;
    backup as copy datafile 171;&lt;br /&gt;
    backup as copy current controlfile;&lt;br /&gt;
    release channel c1;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The other 145 datafiles were backed up with a format of &amp;#039;/path/to/datafiles/%b&amp;#039; which preserves the filenames so all that needs to be done is rename the other 2 after the backup finishes.&amp;lt;br /&amp;gt;&lt;br /&gt;
If they are going to be used in a restore scenario, they should be renamed in the controlfile also.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter database rename file &amp;#039;/path/to/datafiles/filename_with_a_space_at_end &amp;#039; to &amp;#039;/path/to/datafiles/filename_without_a_space&amp;#039;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===RMAN errors after crosscheck backup and delete noprompt obsolete and delete noprompt expired backup===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
RMAN-06207: WARNING: 3921 objects could not be deleted for SBT_TAPE channel(s) due&lt;br /&gt;
RMAN-06208:          to mismatched status.  Use CROSSCHECK command to fix status&lt;br /&gt;
RMAN-06210: List of Mismatched objects&lt;br /&gt;
RMAN-06211: ==========================&lt;br /&gt;
RMAN-06212:   Object Type   Filename/Handle&lt;br /&gt;
RMAN-06213: --------------- ---------------------------------------------------&lt;br /&gt;
RMAN-06214: Backup Piece    DB_SID_t20140316_s263889_umhp3bpa7_1_1&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Use the FORCE option with the DELETE command&amp;lt;br /&amp;gt;&lt;br /&gt;
The FORCE command tells RMAN to clean the information out of the catalog regardless of whether it can find it on the media or not.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
delete force noprompt expired backup;&lt;br /&gt;
delete force noprompt obsolete;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===RMAN-06004: ORACLE error from recovery catalog database: RMAN-20003: target database incarnation not found in recovery catalog===&lt;br /&gt;
====Problem:====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-03002: failure of Duplicate Db command at 12/05/2017 11:11:15&lt;br /&gt;
RMAN-05501: aborting duplication of target database&lt;br /&gt;
RMAN-03015: error occurred in stored script Memory Script&lt;br /&gt;
RMAN-06004: ORACLE error from recovery catalog database: RMAN-20003: target database incarnation not found in recovery catalog&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Solution:====&lt;br /&gt;
Strangely, this means, in my particular case, that block change tracking is turned on in the target databse and needs turning off in the auxiliary while the DUPLICATE is running.&amp;lt;br /&amp;gt;&lt;br /&gt;
It must be done while the auxiliary is in mount mode and restoring the datafiles (before recovery starts)&amp;lt;br /&amp;gt;&lt;br /&gt;
It is reported to be a bug fixed in 11.1 but somehow, we&amp;#039;re still (sometimes) getting it in 12.1.0.2.&lt;br /&gt;
&lt;br /&gt;
===RMAN-06059: expected archived log not found, loss of archived log compromises recoverability===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
RMAN-06059: expected archived log not found, loss of archived log compromises recoverability&lt;br /&gt;
ORA-19625: error identifying file &amp;lt;filename&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This error can come from the fact that the database files (more likely archivelogs) are being deleted by the operating system so RMAN has no clue of their whereabouts.&amp;lt;br /&amp;gt;&lt;br /&gt;
Possibly result of a database duplication and the catalog has not updated properly?&amp;lt;br /&amp;gt;&lt;br /&gt;
====Solution====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
crosscheck archivelog all;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
And then maybe take a backup to be on the safe side.&lt;br /&gt;
&lt;br /&gt;
===RMAN-05537: DUPLICATE without TARGET connection when auxiliary instance is started with spfile cannot use SPFILE clause===&lt;br /&gt;
====Problem:====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-03002: failure of Duplicate Db command at 12/05/2017 14:17:49&lt;br /&gt;
RMAN-05501: aborting duplication of target database&lt;br /&gt;
RMAN-05537: DUPLICATE without TARGET connection when auxiliary instance is started with spfile cannot use SPFILE clause&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Usually happens after restarting a failed RMAN DUPLICATE database. The spfile has been regenerated on the auxiliary to a level where it has too much detail in it.&lt;br /&gt;
====Solution:====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ cd $ORACLE_HOME/dbs&lt;br /&gt;
$ ls -altr *dwh_perf*&lt;br /&gt;
-rw-r-----    1 oracle   oinstall   17645568 Aug  3 13:34 snapcf_dwh_perf.f&lt;br /&gt;
-rw-r-----    1 oracle   oinstall       7680 Nov  4 09:22 orapwdwh_perf&lt;br /&gt;
-rw-r--r--    1 oracle   oinstall        104 Dec  5 09:34 initdwh_perf.ora&lt;br /&gt;
-rw-r-----    1 oracle   oinstall       6656 Dec  5 11:11 spfiledwh_perf.ora&lt;br /&gt;
-rw-rw----    1 oracle   oinstall       1544 Dec  5 14:18 hc_dwh_perf.dat&lt;br /&gt;
$ mv hc_dwh_perf.dat hc_dwh_perf.dat.old&lt;br /&gt;
$ mv spfiledwh_perf.ora spfiledwh_perf.ora.old&lt;br /&gt;
$ cat initdwh_perf.ora&lt;br /&gt;
sga_max_size=&amp;#039;6G&amp;#039;&lt;br /&gt;
sga_target=&amp;#039;6G&amp;#039;&lt;br /&gt;
compatible=&amp;#039;12.0.0&amp;#039;&lt;br /&gt;
db_files=&amp;#039;500&amp;#039;&lt;br /&gt;
&lt;br /&gt;
# Instance name&lt;br /&gt;
db_name=dwh_perf&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Re-run the DUPLICATE. It should zoom past the already recovered datafiles.&lt;br /&gt;
&lt;br /&gt;
===PSDRPC returns significant error 1013===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
archived log thread=1 sequence=195008&lt;br /&gt;
channel t2: reading from backup piece arclog_LBK_4260753020_946042770_479194_1&lt;br /&gt;
channel t0: piece handle=arclog_LBK_4260753020_946042770_479192_1 tag=TAG20170607T133757&lt;br /&gt;
channel t0: restored backup piece 1&lt;br /&gt;
channel t0: restore complete, elapsed time: 00:00:35&lt;br /&gt;
archived log file name=/xxxxxx/acc/ora_bin2/app/oracle/product/11.2.0.4/dbhome_1/dbs/arch1_195006_815790039.dbf thread=1 sequence=195006&lt;br /&gt;
PSDRPC returns significant error 1013.&lt;br /&gt;
PSDRPC returns significant error 1013.&lt;br /&gt;
released channel: t0&lt;br /&gt;
released channel: t1&lt;br /&gt;
released channel: t2&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-03002: failure of Duplicate Db command at 06/09/2017 15:15:04&lt;br /&gt;
RMAN-05501: aborting duplication of target database&lt;br /&gt;
RMAN-03015: error occurred in stored script Memory Script&lt;br /&gt;
RMAN-11003: failure during parse/execution of SQL statement: alter database recover logfile &amp;#039;/xxxxxx/acc/ora_bin2/app/oracle/product/11.2.0.4/dbhome_1/dbs/arch1_195006_815790039.dbf&amp;#039;&lt;br /&gt;
ORA-10877: error signaled in parallel recovery slave&lt;br /&gt;
&lt;br /&gt;
Recovery Manager complete.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Action====&lt;br /&gt;
Check the alert log on the auxiliary instance.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ORA-279 signalled during: alter database recover logfile &amp;#039;/xxxxxx/acc/ora_bin2/app/oracle/product/11.2.0.4/dbhome_1/dbs/arch1_195005_815790039.dbf&amp;#039;...&lt;br /&gt;
alter database recover logfile &amp;#039;/xxxxxx/acc/ora_bin2/app/oracle/product/11.2.0.4/dbhome_1/dbs/arch1_195006_815790039.dbf&amp;#039;&lt;br /&gt;
Media Recovery Log /xxxxxx/acc/ora_bin2/app/oracle/product/11.2.0.4/dbhome_1/dbs/arch1_195006_815790039.dbf&lt;br /&gt;
Fri Jun 09 07:30:30 2017&lt;br /&gt;
Errors with log /xxxxxx/acc/ora_bin2/app/oracle/product/11.2.0.4/dbhome_1/dbs/arch1_195006_815790039.dbf&lt;br /&gt;
Recovery interrupted!&lt;br /&gt;
Recovered data files to a consistent state at change 238029030495&lt;br /&gt;
Media Recovery failed with error 19755&lt;br /&gt;
Errors in file /xxxxxx/acc/ora_bin2/app/oracle/diag/rdbms/lbkro/lbkro/trace/lbkro_pr00_13108374.trc:&lt;br /&gt;
ORA-00283: recovery session canceled due to errors&lt;br /&gt;
===&amp;gt;ORA-19755: could not open change tracking file&lt;br /&gt;
===&amp;gt;ORA-19750: change tracking file: &amp;#039;/xxxxxx/exp/ora_data2/lbk/data/bct_lbk_do_not_delete.f&lt;br /&gt;
===&amp;gt;ORA-27037: unable to obtain file status&lt;br /&gt;
===&amp;gt;IBM AIX RISC System/6000 Error: 2: No such file or directory&lt;br /&gt;
Additional information: 3&lt;br /&gt;
Fri Jun 09 07:30:36 2017&lt;br /&gt;
ORA-10877 signalled during: alter database recover logfile &amp;#039;/xxxxxx/acc/ora_bin2/app/oracle/product/11.2.0.4/dbhome_1/dbs/arch1_195006_815790039.dbf&amp;#039;...&lt;br /&gt;
Fri Jun 09 14:04:57 2017&lt;br /&gt;
alter database recover logfile &amp;#039;/xxxxxx/acc/ora_bin2/app/oracle/product/11.2.0.4/dbhome_1/dbs/arch1_195006_815790039.dbf&amp;#039;&lt;br /&gt;
Media Recovery Log /xxxxxx/acc/ora_bin2/app/oracle/product/11.2.0.4/dbhome_1/dbs/arch1_195006_815790039.dbf&lt;br /&gt;
Media Recovery failed with error 1112&lt;br /&gt;
ORA-283 signalled during: alter database recover logfile &amp;#039;/xxxxxx/acc/ora_bin2/app/oracle/product/11.2.0.4/dbhome_1/dbs/arch1_195006_815790039.dbf&amp;#039;...&lt;br /&gt;
Fri Jun 09 14:31:20 2017&lt;br /&gt;
Shutting down instance (immediate)&lt;br /&gt;
Shutting down instance: further logons disabled&lt;br /&gt;
Stopping background process MMNL&lt;br /&gt;
Stopping background process MMON&lt;br /&gt;
License high water mark = 49&lt;br /&gt;
ALTER DATABASE CLOSE NORMAL&lt;br /&gt;
ORA-1109 signalled during: ALTER DATABASE CLOSE NORMAL...&lt;br /&gt;
ALTER DATABASE DISMOUNT&lt;br /&gt;
Shutting down archive processes&lt;br /&gt;
Archiving is disabled&lt;br /&gt;
Completed: ALTER DATABASE DISMOUNT&lt;br /&gt;
ARCH: Archival disabled due to shutdown: 1089&lt;br /&gt;
Shutting down archive processes&lt;br /&gt;
Archiving is disabled&lt;br /&gt;
ARCH: Archival disabled due to shutdown: 1089&lt;br /&gt;
Shutting down archive processes&lt;br /&gt;
Archiving is disabled&lt;br /&gt;
Fri Jun 09 14:31:24 2017&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This is a known bug. it is fixed in 11.2.0.3 but... this customer does not apply patches!&lt;br /&gt;
&lt;br /&gt;
====Solution====&lt;br /&gt;
While the DUPLICATE is running (and in MOUNT mode), log on to the auxiliary instance and disable block change tracking.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter database disable block change tracking;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
A documented workaround is to set db_filename_convert parameter in the DUPLICATE clause of the run block but I tried this and it failed again.&amp;lt;br /&amp;gt;&lt;br /&gt;
The obvious solution is to patch the database but...&lt;br /&gt;
&lt;br /&gt;
===Database trigger to capture ORA errors===&lt;br /&gt;
From [http://ora-ssn.blogspot.be/2011/10/trigger-on-database-to-capture-ora.html ora-ssn.blogspot.be]&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
CREATE TABLE stats$error_log (&lt;br /&gt;
        err_dt          TIMESTAMP,&lt;br /&gt;
        db_user         VARCHAR2(30),&lt;br /&gt;
        msg_stack       VARCHAR2(2000),&lt;br /&gt;
        sqltxt          VARCHAR2(1000))&lt;br /&gt;
tablespace users;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Now, create a trigger on the database server.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
CREATE OR REPLACE TRIGGER log_server_errors&lt;br /&gt;
  AFTER SERVERERROR&lt;br /&gt;
  ON DATABASE&lt;br /&gt;
DECLARE&lt;br /&gt;
          v_sqltext VARCHAR2(1000);&lt;br /&gt;
          nl_sqltext ora_name_list_t;&lt;br /&gt;
  BEGIN&lt;br /&gt;
          -- Capture entire error text&lt;br /&gt;
          FOR i IN 1 .. ora_sql_txt(nl_sqltext) LOOP&lt;br /&gt;
            v_sqltext := v_sqltext || nl_sqltext(i);&lt;br /&gt;
          END LOOP;&lt;br /&gt;
          INSERT INTO STATS$ERROR_LOG&lt;br /&gt;
          (err_dt, db_user, msg_stack, sqltxt)&lt;br /&gt;
          VALUES&lt;br /&gt;
          (systimestamp,&lt;br /&gt;
           sys.login_user,&lt;br /&gt;
           dbms_utility.format_error_stack, v_sqltext);&lt;br /&gt;
  END log_server_errors;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORA-19809: limit exceeded for recovery files===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-03009: failure of backup command on ORA_DISK_1 channel at 07/15/2013 10:10:59&lt;br /&gt;
ORA-19809: limit exceeded for recovery files&lt;br /&gt;
ORA-19804: cannot reclaim 274716160 bytes disk space from 1468006400 limit&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    ORA-19809: limit exceeded for recovery files&lt;br /&gt;
    Cause: The limit for recovery files specified by the db_recovery_file_dest_size was exceeded.&lt;br /&gt;
&lt;br /&gt;
    Action: The error is accompanied by 19804. See message 19804 for further details&lt;br /&gt;
&lt;br /&gt;
    ORA-19804: cannot reclaim string bytes disk space from string limit&lt;br /&gt;
    Cause: Oracle cannot reclaim disk space of specified bytes from the DB_RECOVERY_FILE_DEST_SIZE limit.&lt;br /&gt;
&lt;br /&gt;
    Action: There are five possible solutions:&lt;br /&gt;
       1) Take frequent backup of recovery area using RMAN.&lt;br /&gt;
       2) Consider changing RMAN retention policy.&lt;br /&gt;
       3) Consider changing RMAN archivelog deletion policy.&lt;br /&gt;
       4) Add disk space and increase DB_RECOVERY_FILE_DEST_SIZE.&lt;br /&gt;
       5) Delete files from recovery area using RMAN.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The solution here is to increase the value of db_recovery_file_dest_size but it might also indicate a problem with tapes if the archivelogs are being backed up to tape via tdpo.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SYS@DN7&amp;gt; alter system set db_recovery_file_dest_size=4000M scope=both;&lt;br /&gt;
&lt;br /&gt;
System altered.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Looking into int further, saw RMAN parameters missing...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
CONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF 14 DAYS;&lt;br /&gt;
CONFIGURE BACKUP OPTIMIZATION OFF;&lt;br /&gt;
CONFIGURE DEFAULT DEVICE TYPE TO &amp;#039;SBT_TAPE&amp;#039;;&lt;br /&gt;
CONFIGURE CONTROLFILE AUTOBACKUP ON;&lt;br /&gt;
CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE &amp;#039;SBT_TAPE&amp;#039; TO &amp;#039;LOG_%d_controlfile_%F.rman&amp;#039;;&lt;br /&gt;
CONFIGURE DEVICE TYPE &amp;#039;SBT_TAPE&amp;#039; PARALLELISM 1 BACKUP TYPE TO BACKUPSET;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===RMAN-00554: initialization of internal recovery manager package failed===&lt;br /&gt;
Getting this error after migrating a database from one machine to another and attaching to a nice new version 12c catalog on the new server&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Recovery Manager: Release 11.2.0.2.0 - Production on Sat Jun 21 13:16:24 2014&lt;br /&gt;
&lt;br /&gt;
Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.&lt;br /&gt;
&lt;br /&gt;
connected to target database: SPMSUPP1 (DBID=3026014394)&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-00554: initialization of internal recovery manager package failed&lt;br /&gt;
RMAN-04004: error from recovery catalog database: ORA-01017: invalid username/password; logon denied&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
We cannot connect to the catalog via rman but there is no problem if connecting via SQL*Plus!&amp;lt;br /&amp;gt;&lt;br /&gt;
Solution: relink the rman executable.&lt;br /&gt;
===Using AIX commands genld, genkld and slibclean to avoid library file locking errors (libjox) (Doc ID 739963.1)===&lt;br /&gt;
* [https://support.oracle.com/epmos/faces/DocumentDisplay?_afrLoop=206851390914720&amp;amp;id=739963.1&amp;amp;_afrWindowMode=0&amp;amp;_adf.ctrl-state=e0pq23tou_4 Metalink]&lt;br /&gt;
When installing interim (one-off) patches, CPU patches or patchsets, you may encounter some errors with regards to files being locked or oui/opatch being unable to copy files&amp;lt;br /&amp;gt;&lt;br /&gt;
even though the databases, listeners and all other Oracle processes associated with the ORACLE_HOME to be patched were stopped.&amp;lt;br /&amp;gt;&lt;br /&gt;
This could be as result of a process which requires termination or an additional file needing to be unloaded from the system cache.&amp;lt;br /&amp;gt;&lt;br /&gt;
Run following commands to clean up...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
genld -l | grep &amp;lt;ORACLE_HOME&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
If genld returns data then a currently executing process has something open in the ORACLE_HOME directory, therefore terminate the process as required/recommended.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
genkld | grep &amp;lt;ORACLE_HOME&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
If the genkld command  returns a  list of shared objects currently loaded onto the OS system cache then please remove the entries from the OS system cache by running the slibclean command as root user:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/usr/sbin/slibclean&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===ORA-20011: Approximate NDV failed: ORA-29913: error in executing ODCIEXTTABLEOPEN callout===&lt;br /&gt;
This seems to be related to orphaned Datapump tables. Generally seems to be a problem when stats jobs are running during the night (dbms_stats)&amp;lt;br /&amp;gt;&lt;br /&gt;
* Check no datapump jobs are running&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select * from dba_datapump_jobs;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Find orphaned tables&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 2000&lt;br /&gt;
select owner&lt;br /&gt;
,      object_name&lt;br /&gt;
,      object_type&lt;br /&gt;
,      status&lt;br /&gt;
,      to_char(created,&amp;#039;dd-mon-yyyy hh24:mi:ss&amp;#039;) created&lt;br /&gt;
,      to_char(last_ddl_time,&amp;#039;dd-mon-yyyy hh24:mi:ss&amp;#039;) last_ddl_time&lt;br /&gt;
from   dba_objects&lt;br /&gt;
where  1=1&lt;br /&gt;
and    object_name like &amp;#039;ET$%&amp;#039;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Check that  any rows seen are actually external tables&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select owner&lt;br /&gt;
,      table_name&lt;br /&gt;
,      default_directory_name&lt;br /&gt;
,      access_type&lt;br /&gt;
from   dba_external_tables&lt;br /&gt;
order  by 1,2&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Drop the tables if they are not currently being used (no datapump jobs running)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
drop table &amp;amp;&amp;amp;owner..&amp;amp;table_name;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===ORA-01547: warning: RECOVER succeeded but OPEN RESETLOGS would get error below===&lt;br /&gt;
Database is restored and now we want to recover it but we see this...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Starting recover at 24-JUL-15 11:26:19&lt;br /&gt;
&lt;br /&gt;
starting media recovery&lt;br /&gt;
&lt;br /&gt;
unable to find archive log&lt;br /&gt;
archive log thread=1 sequence=69763&lt;br /&gt;
Oracle Error: &lt;br /&gt;
ORA-01547: warning: RECOVER succeeded but OPEN RESETLOGS would get error below&lt;br /&gt;
ORA-01194: file 1 needs more recovery to be consistent&lt;br /&gt;
ORA-01110: data file 1: &amp;#039;/oracle/TRSCRP1/oradata2/system01.dbf&amp;#039;&lt;br /&gt;
&lt;br /&gt;
released channel: c1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This means that although we have restored the database, we are still missing information to complete the recovery. This information is contained in the archived redo logs which must also be restored (from tape if they are no longer on disk)&amp;lt;br /&amp;gt;&lt;br /&gt;
We can see here that we need an archive log with sequence number 69763. But what is the file called and where should it be restored to?&amp;lt;br /&amp;gt;&lt;br /&gt;
For this we can go to SQL*Plus and get the database to tell us&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
recover database using backup controlfile until cancel;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
and cancel straight away.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ORA-00279: change 13796376414661 generated at 07/14/2015 13:20:07 needed for&lt;br /&gt;
thread 1&lt;br /&gt;
ORA-00289: suggestion : /oracle/TRSCRP1/archive/arch_TRSCRP1_1_69763.arc&lt;br /&gt;
ORA-00280: change 13796376414661 for thread 1 is in sequence #69763&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Specify log: {&amp;lt;RET&amp;gt;=suggested | filename | AUTO | CANCEL}&lt;br /&gt;
cancel&lt;br /&gt;
ORA-01547: warning: RECOVER succeeded but OPEN RESETLOGS would get error below&lt;br /&gt;
ORA-01194: file 1 needs more recovery to be consistent&lt;br /&gt;
ORA-01110: data file 1: &amp;#039;/oracle/TRSCRP1/oradata2/system01.dbf&amp;#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
ORA-01112: media recovery not started&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Now we see that we need to find a file called arch_TRSCRP1_1_69763.arc and put it in the directory /oracle/TRSCRP1/archive.&amp;lt;br /&amp;gt;&lt;br /&gt;
This will continue up until the time specified for the recover so restore a whole bunch of them.&amp;lt;br /&amp;gt;&lt;br /&gt;
Repeat the &amp;quot;recover database using backup controlfile until cancel;&amp;quot; command and type AUTO or Enter until you&amp;#039;ve got to where you need to be.&amp;lt;br /&amp;gt;&lt;br /&gt;
Type CANCEL when point is reached and&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter database open resetlogs;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Stuart</name></author>	</entry>

	<entry>
		<id>https://mailnest.com/dbawiki/index.php?title=Oracle_errors&amp;diff=3358</id>
		<title>Oracle errors</title>
		<link rel="alternate" type="text/html" href="https://mailnest.com/dbawiki/index.php?title=Oracle_errors&amp;diff=3358"/>
				<updated>2018-11-03T14:08:07Z</updated>
		
		<summary type="html">&lt;p&gt;Stuart: /* Solution */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;===ORA-00600===&lt;br /&gt;
[https://support.oracle.com/epmos/faces/DocContentDisplay?_afrLoop=397490397952859&amp;amp;id=1092832.1&amp;amp;_afrWindowMode=0&amp;amp;_adf.ctrl-state=184vwc6g3y_4 Master Note for Diagnosing ORA-600 (Doc ID 1092832.1)]&lt;br /&gt;
===ORA-19051: Cannot use fast path insert for this XMLType table===&lt;br /&gt;
Think LD_LIBRARY_PATH on Linux or LIBPATH on AIX.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Export: Release 11.2.0.4.0 - Production on Thu Jun 1 06:41:55 2017&lt;br /&gt;
&lt;br /&gt;
Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.&lt;br /&gt;
&lt;br /&gt;
Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production&lt;br /&gt;
With the Partitioning, OLAP, Data Mining and Real Application Testing options&lt;br /&gt;
Starting &amp;quot;DWH_EXPORT&amp;quot;.&amp;quot;SYS_EXPORT_TABLE_03&amp;quot;:  dwh_export/******** parfile=cadis_foto_export_credit_dba.par&lt;br /&gt;
Estimate in progress using BLOCKS method...&lt;br /&gt;
Processing object type TABLE_EXPORT/TABLE/TABLE_DATA&lt;br /&gt;
Total estimation using BLOCKS method: 64.08 GB&lt;br /&gt;
ORA-39126: Worker unexpected fatal error in KUPW$WORKER.FETCH_XML_OBJECTS []&lt;br /&gt;
ORA-19051: Cannot use fast path insert for this XMLType table&lt;br /&gt;
&lt;br /&gt;
ORA-06512: at &amp;quot;SYS.DBMS_SYS_ERROR&amp;quot;, line 86&lt;br /&gt;
ORA-06512: at &amp;quot;SYS.KUPW$WORKER&amp;quot;, line 9710&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Problem====&lt;br /&gt;
When the 11g DB was started, LD_LIBRARY_PATH and LIBPATH were still pointing to paths in the 10g Home.&lt;br /&gt;
====Solution====&lt;br /&gt;
There may have been some odd values setup in LD_LIBRARY_PATH before the call to oraenv (if oraenv was indeed called!)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
unset LD_LIBRARY_PATH LIBPATH&lt;br /&gt;
export ORACLE_SID=&amp;lt;correct 11g SID&amp;gt;&lt;br /&gt;
. oraenv&lt;br /&gt;
echo $LD_LIBRARY_PATH&lt;br /&gt;
echo $LIBPATH&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
They should now be correct.&lt;br /&gt;
&lt;br /&gt;
===ORA-27092: size of file exceeds file size limit of the process===&lt;br /&gt;
Think ulimit...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Cause: an attempt was made to open a file that exceeds the process&amp;#039;s file size limit (ulimit), additional information shows the current limit (logical blocks) and the size of the file (logical blocks)&lt;br /&gt;
Action: increase the processes file size limit (ulimit) and retry&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
truncate table pibadm.test_ph&lt;br /&gt;
                      *&lt;br /&gt;
Error at line 1 :&lt;br /&gt;
ORA-00604: error ocurred at recursive SQL level 1&lt;br /&gt;
ORA-01116: error in opening database file 2&lt;br /&gt;
ORA-01110: datafile 2 : &amp;#039;/opt/u01/data/PIBQA/UNDO_01.dbf&amp;#039;&lt;br /&gt;
ORA-27092: size of file exceeds file size limit of the process&lt;br /&gt;
Additional information: 262143&lt;br /&gt;
Additional information: 2621441&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Check the fs_size limit for this user in /etc/security/limits&amp;lt;br /&amp;gt;&lt;br /&gt;
Compare this with another user, say oracle. Probably -1 (unlimited)&lt;br /&gt;
&lt;br /&gt;
===SP2-1503: Unable to initialize Oracle call interface===&lt;br /&gt;
When trying to login to the database via SQL*Plus, these messages a displayed&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
hn5118 /home/oracle $sqlplus / as sysdba&lt;br /&gt;
SP2-1503: Unable to initialize Oracle call interface&lt;br /&gt;
SP2-0152: ORACLE may not be functioning properly&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Seems to be a problem unique to AIX (in this case).&amp;lt;br /&amp;gt;&lt;br /&gt;
Check to see what the LIBPATH variable is. It may still contain a path to an old ORACLE_HOME...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
hn5118 /home/oracle $env|grep LIBPATH&lt;br /&gt;
LIBPATH=/oracle/exp/ora_bin1/app/oracle/product/10.2.0/db_1/lib:/oracle/exp/ora_bin1/app/oracle/product/10.2.0/db_1/lib&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Disco! Unset it and rerun.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
hn5118 /home/oracle $unset LIBPATH&lt;br /&gt;
&lt;br /&gt;
hn5118 /home/oracle $sqlplus / as sysdba&lt;br /&gt;
&lt;br /&gt;
SQL*Plus: Release 12.1.0.2.0 Production on Wed Jul 12 17:17:54 2017&lt;br /&gt;
&lt;br /&gt;
Copyright (c) 1982, 2014, Oracle.  All rights reserved.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Connected to:&lt;br /&gt;
Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production&lt;br /&gt;
With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options&lt;br /&gt;
&lt;br /&gt;
SQL&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===UDE-31623: operation generated ORACLE error 31623===&lt;br /&gt;
When using Data pump, get following errors almost immediately:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
UDE-31623: operation generated ORACLE error 31623&lt;br /&gt;
ORA-31623: a job is not attached to this session via the specified handle&lt;br /&gt;
ORA-06512: at &amp;quot;SYS.DBMS_DATAPUMP&amp;quot;, line 3326&lt;br /&gt;
ORA-06512: at &amp;quot;SYS.DBMS_DATAPUMP&amp;quot;, line 4551&lt;br /&gt;
ORA-06512: at line 1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Solution 1:&amp;#039;&amp;#039;&amp;#039;&amp;lt;br /&amp;gt;&lt;br /&gt;
In one case, I simplified the parameter file that was used. Maybe related to Streams Pool size, who knows?!&amp;lt;br /&amp;gt;&lt;br /&gt;
I removed these 2 lines and the export started working:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
compression_algorithm=medium&lt;br /&gt;
logtime=all&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Solution 2:&amp;#039;&amp;#039;&amp;#039;&amp;lt;br /&amp;gt;&lt;br /&gt;
There is a note about this on Metalink, 1080775.1 which suggests that Streams Pool Size needs setting.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
For this DataPump error, you will need to configure the database with some Streams Pool.&lt;br /&gt;
&lt;br /&gt;
Perform the following query to find out how much STREAMS_POOL_SIZE has been allocated&lt;br /&gt;
&lt;br /&gt;
 select * from v$sgainfo;&lt;br /&gt;
 ...&lt;br /&gt;
 Streams Pool Size                               0 Yes&lt;br /&gt;
&lt;br /&gt;
Data Pump now uses Advanced Queuing (AQ) internally, so it can handle job stops/starts/re-starts.  However, AQ using the Streams Pool, where the database currently has the STREAMS_POOL_SIZE set to ZERO.&lt;br /&gt;
&lt;br /&gt;
Manually set the STREAMS_POOL_SIZE (using ALTER SYSTEM or by changing the value in the the PFILE/SPFILE), re-start the database and re-attempt the Data Pump Export.&lt;br /&gt;
&lt;br /&gt;
Alternately, turn on Automatic Shared Memory management (ASMM) by setting SGA_TARGET or MEMORY_TARGET.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
From Oracle Documentation&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Setting the Size Of the Buffer Cache In a Streams Environment&lt;br /&gt;
&lt;br /&gt;
Oracle Data Pump uses Streams functionality to communicate between processes.&lt;br /&gt;
If the SGA_TARGET initialization parameter is set, then the STREAMS_POOL_SIZE initialization parameter is automatically set to a reasonable value.&lt;br /&gt;
If the SGA_TARGET initialization parameter is not set and the STREAMS_POOL_SIZE initialization parameter is not defined,&lt;br /&gt;
then the size of the streams pool automatically defaults to 10% of the size of the shared pool.&lt;br /&gt;
&lt;br /&gt;
When the streams pool is created, the required SGA memory is taken from memory allocated to the buffer cache,&lt;br /&gt;
reducing the size of the cache to less than what was specified by the DB_CACHE_SIZE initialization parameter.&lt;br /&gt;
This means that if the buffer cache was configured with only the minimal required SGA, then Data Pump operations may not work properly.&lt;br /&gt;
A minimum size of 10M is recommended for STREAMS_POOL_SIZE in order to ensure successful Data Pump operations.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORA-00020: maximum number of processes (150) exceeded===&lt;br /&gt;
Check the current resource limits with:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 300&lt;br /&gt;
select * from v$resource_limit;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Unfortunately this limit cannot be increased without a restart.&amp;lt;br /&amp;gt;&lt;br /&gt;
It may be a necessary to increase the limit with&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter system set processes=500 scope=spfile;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
followed by a shutdown/startup&amp;lt;br /&amp;gt;&lt;br /&gt;
Or it may be some user is running away with the limit.&amp;lt;br /&amp;gt;&lt;br /&gt;
Check to see who is running what with:&lt;br /&gt;
[[http://www.mailnest.com/dbawiki/index.php/Handy_scripts#See_what_statements_all_users_are_running See_what_statements_all_users_are_running]]&lt;br /&gt;
===ORA-01555: snapshot too old: rollback segment number nn with name &amp;quot;xxx&amp;quot; too small===&lt;br /&gt;
* [http://dfitzjarrell.wordpress.com/2008/02/22/the-dreaded-ora-01555/ Good explanation of why it happens]&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
====Problem====&lt;br /&gt;
A long running transaction has run out of space to store its read-consistent image&lt;br /&gt;
&lt;br /&gt;
====Solution 1====&lt;br /&gt;
If it&amp;#039;s a one-off, maybe leave it alone. It may have been a user leaving a session open overnight without committing or rolling back.&lt;br /&gt;
&lt;br /&gt;
====Solution 2====&lt;br /&gt;
Make sure there&amp;#039;s enough space to allow the transaction to finish.&lt;br /&gt;
&lt;br /&gt;
====Things to check====&lt;br /&gt;
How much undo did the biggest transaction take?&lt;br /&gt;
What is the undo retention parameter set to?&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 200&lt;br /&gt;
col name        for a30&lt;br /&gt;
col description for a50&lt;br /&gt;
col value       for a20&lt;br /&gt;
col maxquerylen for 999999&lt;br /&gt;
select p.name&lt;br /&gt;
,      p.description&lt;br /&gt;
,      p.value&lt;br /&gt;
,      max(u.maxquerylen) maxquerylen&lt;br /&gt;
from   v$parameter p&lt;br /&gt;
,      v$undostat  u&lt;br /&gt;
where  1=1&lt;br /&gt;
and    p.name = &amp;#039;undo_retention&amp;#039;&lt;br /&gt;
group  by p.name&lt;br /&gt;
,      p.description&lt;br /&gt;
,      p.value;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Set the retention to about 20% bigger than the maxquerylen.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select &amp;#039;alter system set undo_retention=&amp;#039;||round(1.2*max(maxquerylen))||&amp;#039; scope=both;&amp;#039; &amp;quot;Run this&amp;quot; from v$undostat;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
and set the undo retention guarantee (being aware of the consequences)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select tablespace_name&lt;br /&gt;
,      retention&lt;br /&gt;
from   dba_tablespaces;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter tablespace &amp;amp;undo_ts_name retention guarantee;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Optimise Oracle UNDO Parameters===&lt;br /&gt;
&lt;br /&gt;
The ideal undo_retention would be enough to hold rollback for the longest transaction that happened so far (can&amp;#039;t see into the future)&amp;lt;br /&amp;gt;&lt;br /&gt;
So current undo_retention = current value of undo / (db_block_size * undo blocks per sec)&amp;lt;br /&amp;gt;&lt;br /&gt;
* Undo Blocks per Second&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SELECT MAX(undoblks/((end_time-begin_time)*3600*24)) &amp;quot;UNDO_BLOCKS_PER_SEC&amp;quot;&lt;br /&gt;
FROM   v$undostat;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Optimal Undo Retention&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
col actual for 9999999999.99 heading &amp;quot;ACTUAL UNDO SIZE [MByte]&amp;quot;&lt;br /&gt;
col retent for 9999999999    heading &amp;quot;UNDO RETENTION [Sec]&amp;quot;&lt;br /&gt;
col needed for 9999999999.99 heading &amp;quot;NEEDED UNDO SIZE [Secs]&amp;quot;&lt;br /&gt;
&lt;br /&gt;
SELECT d.undo_size/(1024*1024) actual,&lt;br /&gt;
       to_number(SUBSTR(e.value,1,25)) retent,&lt;br /&gt;
       ROUND((d.undo_size / (to_number(f.value) *&lt;br /&gt;
       g.undo_block_per_sec))) needed&lt;br /&gt;
  FROM (&lt;br /&gt;
       SELECT SUM(a.bytes) undo_size&lt;br /&gt;
          FROM v$datafile a,&lt;br /&gt;
               v$tablespace b,&lt;br /&gt;
               dba_tablespaces c&lt;br /&gt;
         WHERE c.contents = &amp;#039;UNDO&amp;#039;&lt;br /&gt;
           AND c.status = &amp;#039;ONLINE&amp;#039;&lt;br /&gt;
           AND b.name = c.tablespace_name&lt;br /&gt;
           AND a.ts# = b.ts#&lt;br /&gt;
       ) d,&lt;br /&gt;
       v$parameter e,&lt;br /&gt;
       v$parameter f,&lt;br /&gt;
       (&lt;br /&gt;
       SELECT MAX(undoblks/((end_time-begin_time)*3600*24))&lt;br /&gt;
              undo_block_per_sec&lt;br /&gt;
         FROM v$undostat&lt;br /&gt;
       ) g&lt;br /&gt;
WHERE e.name = &amp;#039;undo_retention&amp;#039;&lt;br /&gt;
  AND f.name = &amp;#039;db_block_size&amp;#039;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Calculate Needed UNDO Size for given Database Activity&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
col actual for 9999999999.99 heading &amp;quot;ACTUAL UNDO SIZE [MByte]&amp;quot;&lt;br /&gt;
col retent for 9999999999    heading &amp;quot;UNDO RETENTION [Sec]&amp;quot;&lt;br /&gt;
col needed for 9999999999.99 heading &amp;quot;NEEDED UNDO SIZE [MByte]&amp;quot;&lt;br /&gt;
&lt;br /&gt;
SELECT d.undo_size/(1024*1024) actual&lt;br /&gt;
,      to_number(SUBSTR(e.value,1,25)) retent&lt;br /&gt;
,      (TO_NUMBER(e.value) * TO_NUMBER(f.value) *&lt;br /&gt;
       g.undo_block_per_sec) / (1024*1024)  needed&lt;br /&gt;
  FROM (&lt;br /&gt;
       SELECT SUM(a.bytes) undo_size&lt;br /&gt;
         FROM v$datafile a,&lt;br /&gt;
              v$tablespace b,&lt;br /&gt;
              dba_tablespaces c&lt;br /&gt;
        WHERE c.contents = &amp;#039;UNDO&amp;#039;&lt;br /&gt;
          AND c.status = &amp;#039;ONLINE&amp;#039;&lt;br /&gt;
          AND b.name = c.tablespace_name&lt;br /&gt;
          AND a.ts# = b.ts#&lt;br /&gt;
       ) d,&lt;br /&gt;
      v$parameter e,&lt;br /&gt;
       v$parameter f,&lt;br /&gt;
       (&lt;br /&gt;
       SELECT MAX(undoblks/((end_time-begin_time)*3600*24))&lt;br /&gt;
         undo_block_per_sec&lt;br /&gt;
         FROM v$undostat&lt;br /&gt;
       ) g&lt;br /&gt;
 WHERE e.name = &amp;#039;undo_retention&amp;#039;&lt;br /&gt;
  AND f.name = &amp;#039;db_block_size&amp;#039;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
It might be that the Export still fails with ORA-01555 even though retention seems long enough.&amp;lt;br /&amp;gt;&lt;br /&gt;
Are you running an export with the flashback_time parameter? If so, the undo_retention should be longer than the total export running time!&amp;lt;br /&amp;gt;&lt;br /&gt;
===Check LOB undo retention===&lt;br /&gt;
The retention settings for LOBS is different for the rest of the database.&amp;lt;br /&amp;gt;&lt;br /&gt;
When you change the UNDO_RETENTION parameter, the LOB segment’s retention value is NOT modified.&amp;lt;br /&amp;gt;&lt;br /&gt;
If you query the RETENTION column of the DBA_LOBS view, you will notice the old UNDO_RETENTION value still remains after you have modified the UNDO_RETENTION parameter.&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SQL&amp;gt; show parameter undo_&lt;br /&gt;
&lt;br /&gt;
NAME                                 TYPE        VALUE&lt;br /&gt;
------------------------------------ ----------- ------------------------------&lt;br /&gt;
undo_management                      string      AUTO&lt;br /&gt;
undo_retention                       integer     36000&lt;br /&gt;
undo_tablespace                      string      UNDOTBS1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SQL&amp;gt; desc SITEADMIN.AUDIT_LOG_MESSAGE&lt;br /&gt;
 Name                                      Null?    Type&lt;br /&gt;
 ----------------------------------------- -------- ----------------------------&lt;br /&gt;
 AUDIT_LOG_MESSAGE_ID                      NOT NULL NUMBER&lt;br /&gt;
 AUDIT_LOG_ID                              NOT NULL NUMBER&lt;br /&gt;
 SEQUENCE                                           NUMBER&lt;br /&gt;
 MESSAGE                                            CLOB&lt;br /&gt;
 CREATE_DATE                                        TIMESTAMP(6)&lt;br /&gt;
 COMPONENT_ID                                       VARCHAR2(50 CHAR)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 300&lt;br /&gt;
col column_name for a32&lt;br /&gt;
select table_name,column_name, pctversion,retention from dba_lobs where owner=&amp;#039;&amp;amp;table_owner&amp;#039;;&lt;br /&gt;
&lt;br /&gt;
TABLE_NAME                COLUMN_NAME                    PCTVERSION  RETENTION&lt;br /&gt;
------------------------- ------------------------------ ---------- ----------&lt;br /&gt;
EMAIL_STORE               CONTENT                                 0&lt;br /&gt;
EMAIL_STORE_ATTACHEMENT   ATTACHEMENT                             0&lt;br /&gt;
TRACKING                  ORIGINAL_MESSAGE                                 900&lt;br /&gt;
TRACKING                  MESSAGE                                          900&lt;br /&gt;
TRACKING                  SIEBEL_MESSAGE                                   900&lt;br /&gt;
WISE_WMS_LOG              WISE_WMS_XML                                     900&lt;br /&gt;
ATTACHMENT                ORIGINAL_MESSAGE                                 900&lt;br /&gt;
PLAN_TABLE                OTHER_XML                                        900&lt;br /&gt;
AUDIT_LOG_MESSAGE         MESSAGE                                          900&lt;br /&gt;
EXCEPTIONS                STACK_TRACE                                      900&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
To change the LOB segment’s RETENTION value to match the new UNDO_RETENTION value, do the following:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ALTER TABLE my_table MODIFY LOB (lob_column) (PCTVERSION 20);&lt;br /&gt;
ALTER TABLE my_table MODIFY LOB (lob_column) (RETENTION);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
By momentarily changing the LOB to use PCTVERSION and then back to RETENTION, the new value of UNDO_RETENTION will be used.&amp;lt;br /&amp;gt;&lt;br /&gt;
You need to do this for all LOB segments that you intend to modify.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select &amp;#039;ALTER TABLE &amp;#039;||owner||&amp;#039;.&amp;#039;||table_name||&amp;#039; MODIFY LOB (&amp;#039;||column_name||&amp;#039;) (PCTVERSION 20);&amp;#039; from dba_lobs where owner=&amp;#039;TIBCO&amp;#039;&lt;br /&gt;
&lt;br /&gt;
select &amp;#039;ALTER TABLE &amp;#039;||owner||&amp;#039;.&amp;#039;||table_name||&amp;#039; MODIFY LOB (&amp;#039;||column_name||&amp;#039;) (RETENTION);&amp;#039;     from dba_lobs where owner=&amp;#039;TIBCO&amp;#039;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
There is a table DBA_LOBS that displays information about all the LOB columns in the database, but it doesn&amp;#039;t actually store any LOB data, just metadata. The actual LOB segments in the database have system-generated names that take the form SYS_LOB*identifier*$$.&lt;br /&gt;
For example if you identify a segment named SYS_LOBidentifier$$ that is consuming space, you can find out what column of what table that LOB column maps to using the DBA_LOBS table:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 1000&lt;br /&gt;
col owner       for a20&lt;br /&gt;
col table_name  for a32&lt;br /&gt;
col column_name for a32&lt;br /&gt;
select owner&lt;br /&gt;
,      table_name&lt;br /&gt;
,      column_name&lt;br /&gt;
from   dba_lobs&lt;br /&gt;
where  1=1&lt;br /&gt;
and    segment_name = &amp;#039;SYS_LOB&amp;lt;&amp;lt;identifier&amp;gt;&amp;gt;$$&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====The Undo Advisor PL/SQL Interface====&lt;br /&gt;
You can activate the Undo Advisor by creating an undo advisor task through the advisor framework.&amp;lt;br /&amp;gt;&lt;br /&gt;
The following example creates an undo advisor task to evaluate the undo tablespace. The name of the advisor is &amp;#039;Undo Advisor&amp;#039;.&amp;lt;br /&amp;gt;&lt;br /&gt;
The analysis is based on Automatic Workload Repository snapshots, which you must specify by setting parameters START_SNAPSHOT and END_SNAPSHOT.&amp;lt;br /&amp;gt;&lt;br /&gt;
In the following example, the START_SNAPSHOT is &amp;quot;1&amp;quot; and END_SNAPSHOT is &amp;quot;2&amp;quot;.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
DECLARE&lt;br /&gt;
   tid    NUMBER;&lt;br /&gt;
   tname  VARCHAR2(30);&lt;br /&gt;
   oid    NUMBER;&lt;br /&gt;
BEGIN&lt;br /&gt;
   DBMS_ADVISOR.CREATE_TASK(&amp;#039;Undo Advisor&amp;#039;, tid, tname, &amp;#039;Undo Advisor Task&amp;#039;);&lt;br /&gt;
   DBMS_ADVISOR.CREATE_OBJECT(tname, &amp;#039;UNDO_TBS&amp;#039;, null, null, null, &amp;#039;null&amp;#039;, oid);&lt;br /&gt;
   DBMS_ADVISOR.SET_TASK_PARAMETER(tname, &amp;#039;TARGET_OBJECTS&amp;#039;, oid);&lt;br /&gt;
   DBMS_ADVISOR.SET_TASK_PARAMETER(tname, &amp;#039;START_SNAPSHOT&amp;#039;, 1);&lt;br /&gt;
   DBMS_ADVISOR.SET_TASK_PARAMETER(tname, &amp;#039;END_SNAPSHOT&amp;#039;, 2);&lt;br /&gt;
   DBMS_ADVISOR.SET_TASK_PARAMETER(tname, &amp;#039;INSTANCE&amp;#039;, 1);&lt;br /&gt;
   DBMS_ADVISOR.execute_task(tname);&lt;br /&gt;
        END;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
After you have created the advisor task, you can view the output and recommendations in the Automatic Database Diagnostic Monitor in Enterprise Manager.&amp;lt;br /&amp;gt;&lt;br /&gt;
This information is also available in the DBA_ADVISOR_* data dictionary views (DBA_ADVISOR_TASKS, DBA_ADVISOR_OBJECTS, DBA_ADVISOR_FINDINGS, DBA_ADVISOR_RECOMMENDATIONS, and so on).&lt;br /&gt;
====References====&lt;br /&gt;
* [http://www.akadia.com/services/ora_optimize_undo.html akadia.com]&lt;br /&gt;
* [http://dfitzjarrell.wordpress.com/2008/02/22/the-dreaded-ora-01555/ the dreaded ora-01555]&lt;br /&gt;
* [http://docs.oracle.com/cd/B28359_01/server.111/b28310/undo004.htm#ADMIN11469 docs.oracle.com]&lt;br /&gt;
&lt;br /&gt;
===Error 6 initializing SQL*Plus===&lt;br /&gt;
Using sqlplus or rman under Cygwin, ORACLE_HOME still needs to be windows format!&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Message file sp1&amp;lt;lang&amp;gt;.msb not found&lt;br /&gt;
SP2-0750 :You may need to set ORACLE_HOME to your Oracle software directory&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
so...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
export ORACLE_SID=KITRYD&lt;br /&gt;
ORAENV_ASK=NO&lt;br /&gt;
. oraenv&lt;br /&gt;
[[ &amp;quot;`uname`&amp;quot; == CYGWIN* ]] &amp;amp;&amp;amp; ORACLE_HOME=`cygpath -w ${ORACLE_HOME}`&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===ORA-2002: error while writing to audit trail===&lt;br /&gt;
Check the space left in the audit tablespace with:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select sum(bytes)/1024/1024 mb from dba_free_space where tablespace_name =&amp;#039;AUDIT_DT&amp;#039;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
If plenty of space, it can be due to Oracle clearing out the recyclebin at the same time.&amp;lt;br /&amp;gt;&lt;br /&gt;
If not, extend the datafile...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select * from dba_data_files where tablespace_name =&amp;#039;AUDIT_DT&amp;#039;;&lt;br /&gt;
alter database datafile 6 resize 30G;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
If that is not possible, clean out some audit data or add a datafile.&lt;br /&gt;
&lt;br /&gt;
===ORA-00449: background process &amp;#039;CKPT&amp;#039; unexpectedly terminated with error 7446===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SQL&amp;gt; startup nomount pfile=&amp;quot;/oracle/TRSCRP1/admin/initTRSCRP1.ora&amp;quot;&lt;br /&gt;
ORA-00449: background process &amp;#039;CKPT&amp;#039; unexpectedly terminated with error 7446&lt;br /&gt;
ORA-07446: sdnfy: bad value &amp;#039;&amp;#039; for parameter .&lt;br /&gt;
SQL&amp;gt; exit&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Solution&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SQL&amp;gt; mkdir /oracle/TRSCRP1/admin/bdump /oracle/TRSCRP1/admin/cdump&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORA-00845: MEMORY_TARGET not supported on this system===&lt;br /&gt;
* Reference: [http://arjudba.blogspot.be/2009/01/ora-00845-memorytarget-not-supported-on.html arjudba.blogspot.be]&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Problem Description&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SQL&amp;gt; STARTUP&lt;br /&gt;
ORA-00845: MEMORY_TARGET not supported on this system&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Cause&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
* Starting from Oracle 11g the automatic memory management feature is now defined with parameter MEMORY_TARGET and MEMMORY_MAX_TARGET.&lt;br /&gt;
* On linux file system the shared memory need to be mounted on /dev/shm directory on the operating system.&lt;br /&gt;
* And the size of /dev/shm needs to be greater than MEMORY_TARGET or MEMMORY_MAX_TARGET.&lt;br /&gt;
* The AMM (Automatic Memory Management) now in 11g manages both SGA and PGA together by MMAN process.&lt;br /&gt;
* The MEMORY_TARGET parameter in 11g comes for (SGA_TARGET+PGA_AGGREGATE_TARGET) which was in 10g.&lt;br /&gt;
* And MEMORY_MAX_TARGET parameter in 11g comes instead of SGA_MAX_TARGET parameter which was in 10g.&lt;br /&gt;
* The ORA-00845:can arises for the following two reasons on linux system.&lt;br /&gt;
1)If the shared memory which is mapped to /dev/shm directory is less than the size of MEMORY_TARGET or MEMORY_MAX_TARGET or&lt;br /&gt;
2)If the shared memory is not mapped to /dev/shm directory.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Solution&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Make sure /dev/shm is properly mounted. You can see it by,&lt;br /&gt;
#df -h or #df -k command.&lt;br /&gt;
The output should be similar to:&lt;br /&gt;
&lt;br /&gt;
$ df -k&lt;br /&gt;
Filesystem            Size  Used Avail Use% Mounted on&lt;br /&gt;
...&lt;br /&gt;
shmfs                 1G    512M 512M  50% /dev/shm&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
We see here for /dev/shm we have assigned 1G memory. Now if you set MEMORY_TARGET more than 1G then above ORA-845 will arise. For example if you have MEMORY_TARGET or MEMORY_MAX_TARGET set to 12G then you can mount shared memory to 13g like below.&lt;br /&gt;
As a root user,&lt;br /&gt;
# mount -t tmpfs shmfs -o size=13g /dev/shm&lt;br /&gt;
In order to make the settings persistence so that it will affect after restarting machine add an entry in /etc/fstab similar to the following:&lt;br /&gt;
&lt;br /&gt;
shmfs /dev/shm tmpfs size=13g 0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORA-24247: network access denied by access control list (ACL)===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Cause: No access control list (ACL) has been assigned to the target host or the privilege necessary to access the target host has not been granted to the user in the access control list.&lt;br /&gt;
&lt;br /&gt;
Action: Ensure that an access control list (ACL) has been assigned to the target host and the privilege necessary to access the target host has been granted to the user.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Your application will encounter an ORA-24247 error if it relies on one of the network packages and no proper ACL has been created. For the use of the following packages it is mandatory to have an ACL for the application user in place in 11g:&lt;br /&gt;
*UTL_TCP&lt;br /&gt;
*UTL_SMTP&lt;br /&gt;
*UTL_MAIL&lt;br /&gt;
*UTL_HTTP&lt;br /&gt;
*UTL_INADDR&lt;br /&gt;
Here is a very good explanation of how to setup the necessary ACLs: [[http://blog.whitehorses.nl/2010/03/17/oracle-11g-access-control-list-and-ora-24247/ whitehorses.nl]]&lt;br /&gt;
&lt;br /&gt;
===ORA-00600: internal error code, arguments: [qmx: no ref]===&lt;br /&gt;
Search &amp;quot;Master Note for Oracle XML Database (XDB) Install / Deinstall (Doc ID 1292089.1)&amp;quot; for more info.&lt;br /&gt;
====Problem:====&lt;br /&gt;
Sometimes one or more of the following errors can be encountered when installing or upgrading XDB, configuring APEX, running an Export, or selecting from xdb.xdb$resource or sys.dba_network_acls:&amp;lt;br /&amp;gt;&lt;br /&gt;
* ORA-31159: XML DB is in an invalid state&lt;br /&gt;
* ORA-00600: internal error code, arguments: [unable to load XDB library]&lt;br /&gt;
* ORA-00600: internal error code, arguments: [qmx: no ref]&lt;br /&gt;
* ORA-00600: internal error code, arguments: [qmtGetColumnInfo1]&lt;br /&gt;
* ORA-00600: internal error code, arguments: [qmtb_init_len]&lt;br /&gt;
* ORA-00600: internal error code, arguments: [qmtGetBaseType]&lt;br /&gt;
* ORA-00600: internal error code, arguments: [psdnop-1], [600]&lt;br /&gt;
* ORA-00600: internal error code, arguments: [qmtInit1]&lt;br /&gt;
* ORA-07445: exception encountered: core dump [_memcpy()+224] [SIGSEGV] [Address not mapped to object]&lt;br /&gt;
* ORA-19051 Cannot Use Fast Path Insert For This XMLType Table&lt;br /&gt;
* ORA-31011: XML parsing failed&lt;br /&gt;
Errors of this sort generally occur when the init routines for the internal XDB functions are run in an invalid environment causing memory corruption.&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
This can happen if the database was ever started with the LD_LIBRARY_PATH (LIBPATH for AIX or SHLIB_PATH for HP) pointing to the wrong $ORACLE_HOME/lib directory rather than to the correct location for the instance.&amp;lt;br /&amp;gt;&lt;br /&gt;
The LD_LIBRARY_PATH/LIBPATH/SHLIB_PATH environment variable is used to resolve the location of the shared library &amp;quot;libxdb.so (libxdb.sl on HP)&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
====Solution:====&lt;br /&gt;
* Stop Listener&lt;br /&gt;
* Stop database&lt;br /&gt;
* Ensure $ORACLE_HOME/lib is at the start of LD_LIBRARY_PATH / LIBPATH / SHLIB_PATH&lt;br /&gt;
* If AIX, run /usr/sbin/slibclean as root&lt;br /&gt;
* Start database&lt;br /&gt;
* Start listener&lt;br /&gt;
&lt;br /&gt;
===ORA-00201: control file version nn.nn.nn.nn incompatible with ORACLE version===&lt;br /&gt;
Trying to restore a database after complete failure&amp;lt;br /&amp;gt;&lt;br /&gt;
first step is to startup the database in nomount mode and restore the controlfile - succeeded.&amp;lt;br /&amp;gt;&lt;br /&gt;
second step, startup the database in mount mode ready for database restore...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SQL*Plus: Release 10.2.0.3.0 - Production on Wed Aug 19 18:16:47 2015&lt;br /&gt;
&lt;br /&gt;
Copyright (c) 1982, 2006, Oracle.  All Rights Reserved.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Connected to:&lt;br /&gt;
Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - 64bit Production&lt;br /&gt;
With the Partitioning, OLAP and Data Mining options&lt;br /&gt;
&lt;br /&gt;
SYS@CODWHP1&amp;gt; startup mount&lt;br /&gt;
ORACLE instance started.&lt;br /&gt;
&lt;br /&gt;
Total System Global Area  260046848 bytes&lt;br /&gt;
Fixed Size                  2029296 bytes&lt;br /&gt;
Variable Size             113248528 bytes&lt;br /&gt;
Database Buffers          134217728 bytes&lt;br /&gt;
Redo Buffers               10551296 bytes&lt;br /&gt;
ORA-00201: control file version 10.2.0.0.0 incompatible with ORACLE version 10.2.0.3.0&lt;br /&gt;
ORA-00202: control file: &amp;#039;/oracle/CODWHP1/product/10203/dbs/cntrlCODWHP1.dbf&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The problem was there was no compatible parameter in the simple init file I used to start up the instance.&amp;lt;br /&amp;gt;&lt;br /&gt;
Adding compatible parameter to init file to be same version (10.2.0.3) allowed the db to mount.&lt;br /&gt;
&lt;br /&gt;
===TNS-00525: Insufficient privilege for operation===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
lsnrctl start LISTENER_UCLID55V&lt;br /&gt;
&lt;br /&gt;
LSNRCTL for IBM/AIX RISC System/6000: Version 11.2.0.3.0 - Production on 26-MAR-2015 13:36:14&lt;br /&gt;
&lt;br /&gt;
Copyright (c) 1991, 2011, Oracle.  All rights reserved.&lt;br /&gt;
&lt;br /&gt;
Starting /oracle/product/11.2.0.3/bin/tnslsnr: please wait...&lt;br /&gt;
&lt;br /&gt;
TNSLSNR for IBM/AIX RISC System/6000: Version 11.2.0.3.0 - Production&lt;br /&gt;
System parameter file is /oracle/product/11.2.0.3/network/admin/listener.ora&lt;br /&gt;
Log messages written to /oracle/product/diag/tnslsnr/solax082/listener_uclid55v/alert/log.xml&lt;br /&gt;
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=150.251.114.238)(PORT=1525)))&lt;br /&gt;
Error listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC1525)))&lt;br /&gt;
TNS-12555: TNS:permission denied&lt;br /&gt;
 TNS-12560: TNS:protocol adapter error&lt;br /&gt;
  TNS-00525: Insufficient privilege for operation&lt;br /&gt;
   IBM/AIX RISC System/6000 Error: 1: Not owner&lt;br /&gt;
&lt;br /&gt;
Listener failed to start. See the error message(s) above...&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This would suggest the user attempting to start the listener has no access to either the Oracle binaries or the TNS listener/tnsnames files.&amp;lt;br /&amp;gt;&lt;br /&gt;
But... checkout the /tmp/.oracle directory :-)&amp;lt;br /&amp;gt;&lt;br /&gt;
That hidden gem shows who started the listener last time. Delete the relevant entry and try again!&amp;lt;br /&amp;gt;&lt;br /&gt;
To start from a clean sheet, stop all listeners, delete this directory and restart the listeners.&lt;br /&gt;
&lt;br /&gt;
===ORA-12003: materialized view or zonemap &amp;quot;KPK&amp;quot;.&amp;quot;EVD01_NEW&amp;quot; does not exist===&lt;br /&gt;
Here&amp;#039;s one you shouldn&amp;#039;t see very often.&amp;lt;br /&amp;gt;&lt;br /&gt;
Trying to drop a tablespace but prevented from doing so because a materialized view has referential contraints on a table in this tablespace.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SQL&amp;gt; drop tablespace TS_THALER_PART_OLD including contents and datafiles cascade constraints;&lt;br /&gt;
drop tablespace TS_THALER_PART_OLD including contents and datafiles cascade constraints&lt;br /&gt;
*&lt;br /&gt;
ERROR at line 1:&lt;br /&gt;
ORA-00604: error occurred at recursive SQL level 1&lt;br /&gt;
ORA-12083: must use DROP MATERIALIZED VIEW to drop &amp;quot;KPK&amp;quot;.&amp;quot;EVD01_NEW&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Ok, nice of Oracle to tell us what we have to do. Simple enough. Let&amp;#039;s drop the materialized view.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SQL&amp;gt; DROP MATERIALIZED VIEW &amp;quot;KPK&amp;quot;.&amp;quot;EVD01_NEW&amp;quot;;&lt;br /&gt;
DROP MATERIALIZED VIEW &amp;quot;KPK&amp;quot;.&amp;quot;EVD01_NEW&amp;quot;&lt;br /&gt;
*&lt;br /&gt;
ERROR at line 1:&lt;br /&gt;
ORA-12003: materialized view or zonemap &amp;quot;KPK&amp;quot;.&amp;quot;EVD01_NEW&amp;quot; does not exist&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Aah. Not so obvious then.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
desc &amp;quot;KPK&amp;quot;.&amp;quot;EVD01_NEW&amp;quot;&lt;br /&gt;
 Name                                      Null?    Type&lt;br /&gt;
 ----------------------------------------- -------- ----------------------------&lt;br /&gt;
 DATMAJ                                             VARCHAR2(8 CHAR)&lt;br /&gt;
 HEUMAJ                                             VARCHAR2(8 CHAR)&lt;br /&gt;
 PGMMAJ                                             VARCHAR2(6 CHAR)&lt;br /&gt;
 NATOPN                                             VARCHAR2(6 CHAR)&lt;br /&gt;
 REFEXN                                             VARCHAR2(50 CHAR)&lt;br /&gt;
 SWIOLN                                             VARCHAR2(1 CHAR)&lt;br /&gt;
 STAEVT                                             VARCHAR2(4 CHAR)&lt;br /&gt;
 REFEVT                                             VARCHAR2(16 CHAR)&lt;br /&gt;
 NUMIDT                                             VARCHAR2(30 CHAR)&lt;br /&gt;
 ORIEVT                                             VARCHAR2(10 CHAR)&lt;br /&gt;
 REFLOG                                             VARCHAR2(16 CHAR)&lt;br /&gt;
 MSGEVT_CPL                                         VARCHAR2(1500 CHAR)&lt;br /&gt;
 REFOPN                                             VARCHAR2(16 CHAR)&lt;br /&gt;
 DATEVT                                             VARCHAR2(8 CHAR)&lt;br /&gt;
 MSGEVT_FIL_1                                       VARCHAR2(2000 CHAR)&lt;br /&gt;
 MSGEVT_FIL_2                                       VARCHAR2(2000 CHAR)&lt;br /&gt;
 MSGEVT_SPE                                         VARCHAR2(200 CHAR)&lt;br /&gt;
 DATEFF                                             VARCHAR2(8 CHAR)&lt;br /&gt;
 TMSTMP                                             VARCHAR2(15 CHAR)&lt;br /&gt;
 VEREVT                                             VARCHAR2(3 CHAR)&lt;br /&gt;
 MSGEVT_FIL_3                                       VARCHAR2(2000 CHAR)&lt;br /&gt;
 MSGEVT_FIL_4                                       VARCHAR2(2000 CHAR)&lt;br /&gt;
 TYPEVT                                             VARCHAR2(5 CHAR)&lt;br /&gt;
 SBP_CODAPP                                         VARCHAR2(10 CHAR)&lt;br /&gt;
 SBP_REFINT                                         VARCHAR2(36 CHAR)&lt;br /&gt;
 SBP_TYPACT                                         VARCHAR2(2 CHAR)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
It exists... but as a table.&amp;lt;br /&amp;gt;&lt;br /&gt;
Something has gone wrong in the database somewhere. As it turns out after some deeper investigation, this database is a copy of production but &amp;quot;with modifications&amp;quot;.&amp;lt;br /&amp;gt;&lt;br /&gt;
After the cloning process, a schema needed renaming. Oracle have a procedure for this but it is very long-winded and time-consuming. It uses export and import with transportable tablespaces to do the remap of the schema.&amp;lt;br /&amp;gt;&lt;br /&gt;
An unsupported workaround to rename schema is to simply update the username in sys.user$ and restart the database.&amp;lt;br /&amp;gt;&lt;br /&gt;
This works for the most part but now we see a consequence of that action.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
col owner      for a30&lt;br /&gt;
col mview_name for a30&lt;br /&gt;
select owner&lt;br /&gt;
,      mview_name&lt;br /&gt;
from   dba_mviews&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
OWNER                          MVIEW_NAME&lt;br /&gt;
------------------------------ ------------------------------&lt;br /&gt;
EPK                            EVD01_NEW&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Ahaa, there&amp;#039;s the materialized view but the owner is different from the one described by the database error message above. This one is the owner as it was on production.&amp;lt;br /&amp;gt;&lt;br /&gt;
This means the owner of materialized views has been denormalised for some reason. Reading the (complex) view text of dba_mviews, we see the owner column is based on sys.snap$.sowner&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
col sowner for a20&lt;br /&gt;
col vname  for a20&lt;br /&gt;
col tname  for a20&lt;br /&gt;
select sowner&lt;br /&gt;
,      vname&lt;br /&gt;
,      tname&lt;br /&gt;
from   sys.snap$&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
SOWNER               VNAME                TNAME&lt;br /&gt;
-------------------- -------------------- --------------------&lt;br /&gt;
EPK                  EVD01_NEW            EVD01_NEW&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
For future reference when updating the username in sys.user$, update the snapshot owner in this table as well!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
update sys.snap$&lt;br /&gt;
set    sowner = &amp;#039;KPK&amp;#039;&lt;br /&gt;
where  sowner = &amp;#039;EPK&amp;#039;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Try again&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
DROP MATERIALIZED VIEW &amp;quot;KPK&amp;quot;.&amp;quot;EVD01_NEW&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
Materialized view dropped.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
yep, and the tablespace?&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
drop tablespace TS_THALER_PART_OLD including contents and datafiles cascade constraints;&lt;br /&gt;
&lt;br /&gt;
Tablespace dropped.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORA-12162: TNS:net service name is incorrectly specified===&lt;br /&gt;
Probably nothing to do with TNS. Check your ORACLE_SID is set correctly!&lt;br /&gt;
&lt;br /&gt;
===ORA-00054: resource busy and acquire with NOWAIT specified===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SELECT O.OBJECT_NAME, S.SID, S.SERIAL#, P.SPID, S.PROGRAM,S.USERNAME,&lt;br /&gt;
S.MACHINE,S.PORT , S.LOGON_TIME,SQ.SQL_FULLTEXT &lt;br /&gt;
FROM V$LOCKED_OBJECT L, DBA_OBJECTS O, V$SESSION S, &lt;br /&gt;
V$PROCESS P, V$SQL SQ &lt;br /&gt;
WHERE L.OBJECT_ID = O.OBJECT_ID &lt;br /&gt;
AND L.SESSION_ID = S.SID AND S.PADDR = P.ADDR &lt;br /&gt;
AND S.SQL_ADDRESS = SQ.ADDRESS;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select object_name, s.sid, s.serial#, p.spid &lt;br /&gt;
from v$locked_object l, dba_objects o, v$session s, v$process p&lt;br /&gt;
where l.object_id = o.object_id and l.session_id = s.sid and s.paddr = p.addr;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
then&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter system kill session &amp;#039;sid,serial#&amp;#039;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORA-12518: TNS:listener could not hand off client connection===&lt;br /&gt;
The database you are trying to connect to is probably on its knees. Check server memory is not exhausted.&lt;br /&gt;
&lt;br /&gt;
===ORA-12520: TNS:listener could not find available handler for requested type of server===&lt;br /&gt;
Strangely this could be related to number of processes being exhausted.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
show parameter processes&lt;br /&gt;
alter system set processes=350 scope=spfile;&lt;br /&gt;
shutdown immediate&lt;br /&gt;
startup&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORA-12541: TNS: no listener===&lt;br /&gt;
Either very basic - start the listener!&amp;lt;br /&amp;gt;&lt;br /&gt;
or, as in our case - not so obvious.&amp;lt;br /&amp;gt;&lt;br /&gt;
We use virtual IP addresses so that the IP address stays the same after failover to standby.&amp;lt;br /&amp;gt;&lt;br /&gt;
Due to some confused configuration, we got the network adapter on two different servers to have the same IP address.&amp;lt;br /&amp;gt;&lt;br /&gt;
Stop the IP address on the bad server (assign another one) and all is fine again.&lt;br /&gt;
===ORA-12514: TNS:listener does not currently know of service===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
lsnrctl status &amp;lt;listener_name&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Been altering tnsnames.ora or listener.ora?&lt;br /&gt;
* Check the local_listener parameter&lt;br /&gt;
Try resetting it to itself. Strange but if you are not using port 1521, this can work wonders!&amp;lt;br /&amp;gt;&lt;br /&gt;
Assuming listener is called LISTENER_WM9T:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter system set local_listener=LISTENER_WM9T scope=both;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Try and connect with the service name or directly with&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sqlplus &amp;#039;sys/*******&amp;#039;@&amp;lt;host&amp;gt;:&amp;lt;port&amp;gt;/&amp;lt;SID&amp;gt; as sysdba&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Excellent description of how Oracle TNS listeners work and a checklist on how to fix this error&amp;lt;br /&amp;gt;&lt;br /&gt;
* [[http://edstevensdba.wordpress.com/2011/03/19/ora-12514/ TNS — Ed Stevens]]&lt;br /&gt;
&lt;br /&gt;
===ORA-12547: TNS lost contact===&lt;br /&gt;
&lt;br /&gt;
If&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sqlplus &amp;lt;user&amp;gt;/&amp;lt;pass&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
fails with above error, try&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sqlplus &amp;lt;user&amp;gt;/&amp;lt;pass&amp;gt;@&amp;lt;db connection&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
If this works, it is most probably a permissions error.&amp;lt;br /&amp;gt;&lt;br /&gt;
Re-run the&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ORACLE_HOME/root.sh&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
script that was run as part of the original installation. This will reset the permissions on some important files.&lt;br /&gt;
===ORA-02374: conversion error loading table &amp;quot;BLENGADM&amp;quot;.&amp;quot;ZZ_EVTCTA&amp;quot;===&lt;br /&gt;
This is typical of importing data with Datapump when the tables in the source database were created with &amp;quot;byte&amp;quot; semantics and the destination is &amp;quot;char&amp;quot; semantics.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ORA-02374: conversion error loading table &amp;quot;BLENGADM&amp;quot;.&amp;quot;ZZ_EVTCTA&amp;quot;&lt;br /&gt;
ORA-12899: value too large for column NOMCTA (actual: 257, maximum: 256)&lt;br /&gt;
&lt;br /&gt;
ORA-02372: data for row: NOMCTA : 0X&amp;#039;4C6976726574206427E9706172676E65202020202020202020&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Problem====&lt;br /&gt;
The root cause is the nls_length_semantics of the table columns being BYTE where one character is assigned one byte. But after conversion in a multi-byte database, one character is larger than one byte (could be 2, 3 or 4) and no longer fits.&lt;br /&gt;
====Solution====&lt;br /&gt;
* import the metadata&lt;br /&gt;
Run the impdp command with content=metadata_only. This will create all the tables (still in their original form) but not the data.&lt;br /&gt;
* alter the BYTE columns in the affected tables to CHAR semantics&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select column_name&lt;br /&gt;
,      char_used&lt;br /&gt;
,      data_length&lt;br /&gt;
,      data_type &lt;br /&gt;
from   user_tab_columns &lt;br /&gt;
where  table_name = &amp;#039;T&amp;#039;&lt;br /&gt;
and    char_used = &amp;#039;B&amp;#039;;&lt;br /&gt;
COLUMN_NAME  C DATA_LENGTH DATA_TYPE&lt;br /&gt;
------------ - ----------- ---------&lt;br /&gt;
X            B           1 VARCHAR2&lt;br /&gt;
SQL&amp;gt; alter table t modify x varchar2(1 char);&lt;br /&gt;
Table altered.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Import the data&lt;br /&gt;
Rerun the impdp ensuring table_exists_action is not REPLACE (use truncate or append). This now imports the data into the modified tables.&lt;br /&gt;
====This script does the donkey work of altering table column semantics from byte to char====&lt;br /&gt;
The author of this script is unknown but he/she deserves a medal. It saves countless hours of work and is so well written.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/*&lt;br /&gt;
  The script converts all the VARCHAR2 columns in the user&amp;#039;s schema&lt;br /&gt;
  to CHAR length semantics. Known to work on 10.2.0.4 and later.&lt;br /&gt;
  &lt;br /&gt;
  Script must be executed against the database without any other client&lt;br /&gt;
  and/or application connections to the affected schema.&lt;br /&gt;
  &lt;br /&gt;
  Oracle does not support CHAR semantics for the built-in schemas,&lt;br /&gt;
  like SYS, SYSTEM or SYSMAN, so the script will throw an error,&lt;br /&gt;
  if attempt to run it against any one of them.&lt;br /&gt;
  &lt;br /&gt;
  Upon completion database objects that have dependencies on tables&lt;br /&gt;
  being modified will be invalidated. Oracle usually re-compiles invalidated&lt;br /&gt;
  objects on the first access. Alternatively, a DBA can execute UTLPRP script&lt;br /&gt;
  to recompile all invalid objects in the entire database.&lt;br /&gt;
  &lt;br /&gt;
  Upon completion, please make sure that NLS_LENGTH_SEMANTICS instance parameter&lt;br /&gt;
  is set to CHAR to ensure further upgradability of the schema.&lt;br /&gt;
*/&lt;br /&gt;
set serveroutput on size unlimited format wrap&lt;br /&gt;
declare&lt;br /&gt;
  type sql_list_t is table of varchar2(32767) index by pls_integer;&lt;br /&gt;
  type idx_list_t is table of user_indexes.index_name%type index by pls_integer;&lt;br /&gt;
  type col_list_t is table of user_tab_columns%rowtype index by pls_integer;&lt;br /&gt;
  --&lt;br /&gt;
  lv_col_cnt   pls_integer := 0;&lt;br /&gt;
  lv_idx_cnt   pls_integer := 0;&lt;br /&gt;
  lv_char_set  pls_integer := 0; &lt;br /&gt;
  lv_user      user_users.username%type;&lt;br /&gt;
  lv_sql_stmt  varchar2(32767);&lt;br /&gt;
  lv_byte_cols col_list_t;&lt;br /&gt;
  lv_idx_names idx_list_t;&lt;br /&gt;
  lv_idx_ddls  sql_list_t;&lt;br /&gt;
  --&lt;br /&gt;
  procedure run_sql_stmt&lt;br /&gt;
  (&lt;br /&gt;
   p_sql_stmt in varchar2&lt;br /&gt;
  )&lt;br /&gt;
  as&lt;br /&gt;
  begin&lt;br /&gt;
    execute immediate p_sql_stmt;&lt;br /&gt;
  exception&lt;br /&gt;
    when others&lt;br /&gt;
    then&lt;br /&gt;
      raise_application_error(-20202, &amp;#039;Failed statement [&amp;#039; || p_sql_stmt || dbms_utility.format_error_backtrace() || &amp;#039;]&amp;#039;, true);&lt;br /&gt;
  end;&lt;br /&gt;
begin&lt;br /&gt;
  --&lt;br /&gt;
  lv_user := user();&lt;br /&gt;
  if lv_user in (&amp;#039;SYS&amp;#039;, &amp;#039;SYSTEM&amp;#039;, &amp;#039;SYSMAN&amp;#039;)&lt;br /&gt;
  then&lt;br /&gt;
    raise_application_error(-20202, &amp;#039;This script cannot be executed against Oracle built-in schema [&amp;#039; || lv_user || &amp;#039;].&amp;#039;);&lt;br /&gt;
  end if;&lt;br /&gt;
  --&lt;br /&gt;
  select&lt;br /&gt;
         *&lt;br /&gt;
         bulk collect into lv_byte_cols&lt;br /&gt;
  from&lt;br /&gt;
         user_tab_columns uc&lt;br /&gt;
  where&lt;br /&gt;
         uc.char_used = &amp;#039;B&amp;#039;&lt;br /&gt;
         and&lt;br /&gt;
         substr(uc.table_name, 1, 4) != &amp;#039;BIN$&amp;#039;&lt;br /&gt;
         and&lt;br /&gt;
         not exists&lt;br /&gt;
         (&lt;br /&gt;
          select 1&lt;br /&gt;
          from   user_views uv&lt;br /&gt;
          where  uv.view_name = uc.table_name&lt;br /&gt;
         )&lt;br /&gt;
  ;&lt;br /&gt;
  --&lt;br /&gt;
  lv_col_cnt := lv_byte_cols.count();&lt;br /&gt;
  --&lt;br /&gt;
  dbms_output.enable();&lt;br /&gt;
  --&lt;br /&gt;
  if lv_col_cnt &amp;gt; 0&lt;br /&gt;
  then&lt;br /&gt;
    for idx_rw in&lt;br /&gt;
    (&lt;br /&gt;
     select index_name &lt;br /&gt;
     from   user_indexes&lt;br /&gt;
     where  index_type = &amp;#039;FUNCTION-BASED NORMAL&amp;#039;&lt;br /&gt;
    )&lt;br /&gt;
    loop&lt;br /&gt;
      lv_idx_cnt := lv_idx_cnt + 1;&lt;br /&gt;
      lv_idx_names(lv_idx_cnt) := idx_rw.index_name;&lt;br /&gt;
      lv_idx_ddls(lv_idx_cnt) := replace&lt;br /&gt;
                                 (&lt;br /&gt;
                                  dbms_metadata.get_ddl&lt;br /&gt;
                                  (&lt;br /&gt;
                                   object_type =&amp;gt; &amp;#039;INDEX&amp;#039;,&lt;br /&gt;
                                   name        =&amp;gt; idx_rw.index_name&lt;br /&gt;
                                  )&lt;br /&gt;
                                  ,&lt;br /&gt;
                                  &amp;#039;;&amp;#039;&lt;br /&gt;
                                 );&lt;br /&gt;
      lv_sql_stmt := &amp;#039;drop index &amp;#039; || idx_rw.index_name;&lt;br /&gt;
      run_sql_stmt(lv_sql_stmt);&lt;br /&gt;
      dbms_output.put_line(&amp;#039;Dropped function-based index: &amp;#039; || idx_rw.index_name);&lt;br /&gt;
      dbms_output.put_line(&amp;#039;In case of script failure, restore the index by running the DDL statement below:&amp;#039;);&lt;br /&gt;
      dbms_output.put_line(lv_idx_ddls(lv_idx_cnt) || &amp;#039;;&amp;#039;);&lt;br /&gt;
    end loop;&lt;br /&gt;
    --&lt;br /&gt;
    for i in 1..lv_col_cnt&lt;br /&gt;
    loop&lt;br /&gt;
      lv_sql_stmt :=  &amp;#039;alter table &amp;#039; || lv_byte_cols(i).table_name || &amp;#039; modify (&amp;#039; ||&lt;br /&gt;
                      lv_byte_cols(i).column_name || &amp;#039; &amp;#039; || lv_byte_cols(i).data_type ||&lt;br /&gt;
                      &amp;#039;(&amp;#039; || lv_byte_cols(i).char_length || &amp;#039; char))&amp;#039;;&lt;br /&gt;
      run_sql_stmt(lv_sql_stmt);&lt;br /&gt;
    end loop;&lt;br /&gt;
    --&lt;br /&gt;
    dbms_output.new_line();&lt;br /&gt;
    for i in 1..lv_idx_cnt&lt;br /&gt;
    loop&lt;br /&gt;
      run_sql_stmt(lv_idx_ddls(i));&lt;br /&gt;
      dbms_output.put_line(&amp;#039;Recreated function-based index: &amp;#039; || lv_idx_names(i));&lt;br /&gt;
    end loop;&lt;br /&gt;
    --&lt;br /&gt;
    dbms_output.new_line();&lt;br /&gt;
    dbms_output.put_line&lt;br /&gt;
    (&lt;br /&gt;
     &amp;#039;Updated length semantics to CHAR for &amp;#039; || lv_col_cnt || &amp;#039; column&amp;#039; ||&lt;br /&gt;
     case when lv_col_cnt &amp;gt; 1&lt;br /&gt;
          then &amp;#039;s&amp;#039;&lt;br /&gt;
     end ||&lt;br /&gt;
     &amp;#039; in the schema [&amp;#039; || lv_user || &amp;#039;].&amp;#039;&lt;br /&gt;
    );&lt;br /&gt;
  else&lt;br /&gt;
    dbms_output.put_line(&amp;#039;No columns with BYTE length semantics were found in the schema [&amp;#039; || lv_user || &amp;#039;].&amp;#039;);&lt;br /&gt;
  end if;&lt;br /&gt;
  --&lt;br /&gt;
  select count(*) into lv_char_set&lt;br /&gt;
  from   nls_session_parameters&lt;br /&gt;
  where  parameter = &amp;#039;NLS_LENGTH_SEMANTICS&amp;#039;&lt;br /&gt;
         and&lt;br /&gt;
         value = &amp;#039;CHAR&amp;#039;&lt;br /&gt;
  ;&lt;br /&gt;
  --&lt;br /&gt;
  if lv_char_set = 0&lt;br /&gt;
  then&lt;br /&gt;
    dbms_output.put_line(&amp;#039;WARNING: Do not forget to change instance parameter NLS_LENGTH_SEMANTICS to CHAR and restart the database.&amp;#039;);&lt;br /&gt;
  end if;&lt;br /&gt;
end;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORA-14097: column type or size mismatch in ALTER TABLE EXCHANGE PARTITION===&lt;br /&gt;
Also can be &amp;lt;tt&amp;gt;ORA-54033: column to be modified is used in a virtual column expression&amp;lt;/tt&amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;
Nothing especially to do with partitions - just any ddl operation that affects the table.&amp;lt;br /&amp;gt;&lt;br /&gt;
Hidden columns do not normally show up in a desc unless colinvisible is on&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set colinvisible on&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
But these sneaky system-generated ones don&amp;#039;t show up even with that setting on!  You need to show them with this:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set pages 50 lines 1000&lt;br /&gt;
col column_name for a40&lt;br /&gt;
col data_default for a40&lt;br /&gt;
select internal_column_id, column_name, data_default, hidden_column, virtual_column from dba_tab_cols where table_name =&amp;#039;XND40&amp;#039;;&lt;br /&gt;
&lt;br /&gt;
INTERNAL_COLUMN_ID COLUMN_NAME                                        DATA_DEFAULT                                       HIDDEN_COLUM VIRTUAL_COLU&lt;br /&gt;
------------------ -------------------------------------------------- -------------------------------------------------- ------------ ------------&lt;br /&gt;
                35 MONLOT_REC_CDR                                     &amp;#039;0&amp;#039;                                                NO           NO&lt;br /&gt;
                34 MONLOT_REC_DBT                                     &amp;#039;0&amp;#039;                                                NO           NO&lt;br /&gt;
                33 MONLOT_CAL_CDR                                     &amp;#039;0&amp;#039;                                                NO           NO&lt;br /&gt;
                32 MONLOT_CAL_DBT                                     &amp;#039;0&amp;#039;                                                NO           NO&lt;br /&gt;
                31 MONMVT_CPT                                         &amp;#039;0&amp;#039;                                                NO           NO&lt;br /&gt;
                30 SENNOT                                             &amp;#039; &amp;#039;                                                NO           NO&lt;br /&gt;
                29 NUMSEQ                                                                                                NO           NO&lt;br /&gt;
                28 NOMFIC                                                                                                NO           NO&lt;br /&gt;
                27 TOTCPT_REC                                                                                            NO           NO&lt;br /&gt;
                26 TOTCPT_CAL                                                                                            NO           NO&lt;br /&gt;
                25 MONLOT_REC                                                                                            NO           NO&lt;br /&gt;
                24 MONLOT_CAL                                                                                            NO           NO&lt;br /&gt;
                23 NBRELE_REC                                                                                            NO           NO&lt;br /&gt;
                22 NBRELE_CAL                                                                                            NO           NO&lt;br /&gt;
                21 NUMCPT_GLO                                                                                            NO           NO&lt;br /&gt;
                20 DEVLOT                                                                                                NO           NO&lt;br /&gt;
                19 CODERR                                                                                                NO           NO&lt;br /&gt;
                18 CANLOT                                                                                                NO           NO&lt;br /&gt;
                17 REFTEX                                                                                                NO           NO&lt;br /&gt;
                16 REFEXN                                                                                                NO           NO&lt;br /&gt;
                15 ETTLOT                                                                                                NO           NO&lt;br /&gt;
                14 TYPLOT                                                                                                NO           NO&lt;br /&gt;
                13 DATEXC                                                                                                NO           NO&lt;br /&gt;
                12 STALOT                                                                                                NO           NO&lt;br /&gt;
                11 REFLOT                                                                                                NO           NO&lt;br /&gt;
                10 USRAUT                                                                                                NO           NO&lt;br /&gt;
                 9 HEUAUT                                                                                                NO           NO&lt;br /&gt;
                 8 DATAUT                                                                                                NO           NO&lt;br /&gt;
                 7 PGMMAJ                                                                                                NO           NO&lt;br /&gt;
                 6 USRMAJ                                                                                                NO           NO&lt;br /&gt;
                 5 HEUMAJ                                                                                                NO           NO&lt;br /&gt;
                 4 DATMAJ                                                                                                NO           NO&lt;br /&gt;
                 3 DATCRT                                                                                                NO           NO&lt;br /&gt;
                 2 REFMAJ                                                                                                NO           NO&lt;br /&gt;
                 1 NUMVER                                                                                                NO           NO&lt;br /&gt;
                36 SYS_STS#KR2WNV5L070XKV1L5H7REH                     SYS_OP_COMBINED_HASH(&amp;quot;NOMFIC&amp;quot;,&amp;quot;NUMSEQ&amp;quot;)            YES          YES&lt;br /&gt;
&lt;br /&gt;
36 rows selected.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
That last row means extended statistics have been generated for 2 columns in this table.&amp;lt;br /&amp;gt;&lt;br /&gt;
====Solution====&lt;br /&gt;
Drop the extended stats, do what you need to do and recreate the extended stats.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
PROCEDURE DROP_EXTENDED_STATS&lt;br /&gt;
 Argument Name                  Type                    In/Out Default?&lt;br /&gt;
 ------------------------------ ----------------------- ------ --------&lt;br /&gt;
 OWNNAME                        VARCHAR2                IN&lt;br /&gt;
 TABNAME                        VARCHAR2                IN&lt;br /&gt;
 EXTENSION                      VARCHAR2                IN&lt;br /&gt;
&lt;br /&gt;
exec dbms_stats.drop_extended_stats ( &amp;#039;KPK&amp;#039;, &amp;#039;XND40&amp;#039;, &amp;#039;(&amp;quot;NOMFIC&amp;quot;,&amp;quot;NUMSEQ&amp;quot;)&amp;#039; );&lt;br /&gt;
&lt;br /&gt;
create table kpk.xnd40_new as select * from kpk.xnd40 where 1=2;&lt;br /&gt;
&lt;br /&gt;
Table created.&lt;br /&gt;
&lt;br /&gt;
select dbms_stats.create_extended_stats ( &amp;#039;KPK&amp;#039;, &amp;#039;XND40&amp;#039;, &amp;#039;(&amp;quot;NOMFIC&amp;quot;,&amp;quot;NUMSEQ&amp;quot;)&amp;#039; ) from   dual;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The stats columns can also be seen in their own table&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 1000 pages 100&lt;br /&gt;
col owner for a6&lt;br /&gt;
col table_name for a20&lt;br /&gt;
col extension_name  for a40&lt;br /&gt;
col extension  for a50&lt;br /&gt;
select owner, table_name, extension_name, extension, creator, droppable from dba_stat_extensions where owner = upper(&amp;#039;&amp;amp;&amp;amp;owner.&amp;#039;) and table_name = upper(&amp;#039;&amp;amp;&amp;amp;table_name.&amp;#039;) and extension_name LIKE &amp;#039;SYS_STS%&amp;#039;;&lt;br /&gt;
&lt;br /&gt;
OWNER TABLE_NAME           EXTENSION_NAME                           EXTENSION                                          CREATOR                  DROPPABLE&lt;br /&gt;
----- -------------------- ---------------------------------------- -------------------------------------------------- ------------------------ ------------&lt;br /&gt;
KPK   XMD01                SYS_STSOA4UXZDBW7MIV5OOR8VOHHK           (&amp;quot;DATCRT&amp;quot;,&amp;quot;CODJRN&amp;quot;)                                SYSTEM                   YES&lt;br /&gt;
KPK   XDD02                SYS_STSFJCZYRZBCQL820ADIR0Y4RZ           (&amp;quot;REFMSG&amp;quot;,&amp;quot;CPTTIT&amp;quot;,&amp;quot;TYPMSG&amp;quot;)                       SYSTEM                   YES&lt;br /&gt;
KPK   XCD09                SYS_STS2OIO647GN0_UV$XO583KKKJ           (&amp;quot;DATCRT&amp;quot;,&amp;quot;HEUMAJ&amp;quot;,&amp;quot;STAMOD&amp;quot;)                       SYSTEM                   YES&lt;br /&gt;
KPK   XCD09                SYS_STS_BRDODC6DJG_HXK0#O9BOYF           (&amp;quot;STAMOD&amp;quot;,&amp;quot;CODMOD&amp;quot;)                                SYSTEM                   YES&lt;br /&gt;
KPK   XCD09                SYS_STS2#DY5U$WQG6COVHB##H2ESK           (&amp;quot;DATMAJ&amp;quot;,&amp;quot;STAMOD&amp;quot;,&amp;quot;CODMOD&amp;quot;)                       SYSTEM                   YES&lt;br /&gt;
KPK   XCD09                SYS_STSO7#D3DI5R8_VAF$WJ32D8MT           (&amp;quot;STAMOD&amp;quot;,&amp;quot;KEYREF_1&amp;quot;)                              SYSTEM                   YES&lt;br /&gt;
KPK   XCD09                SYS_STS4FRY10M34S2L$0FDM1N4B18           (&amp;quot;STAMOD&amp;quot;,&amp;quot;IDTMOD&amp;quot;)                                SYSTEM                   YES&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORA-14404: partitioned table contains partitions in a different tablespace===&lt;br /&gt;
As part of an RMAN duplicate with a skip tablespace, this error is produced&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Reenabling controlfile options for auxiliary database&lt;br /&gt;
Executing: alter database enable block change tracking using file &amp;#039;/oracle/acc/ora_data3/adsa1/bct_adsp_do_not_delete.f&amp;#039;&lt;br /&gt;
&lt;br /&gt;
contents of Memory Script:&lt;br /&gt;
{&lt;br /&gt;
   Alter clone database open resetlogs;&lt;br /&gt;
}&lt;br /&gt;
executing Memory Script&lt;br /&gt;
&lt;br /&gt;
database opened&lt;br /&gt;
Dropping offline and skipped tablespaces&lt;br /&gt;
Executing: drop tablespace &amp;quot;ADS_ARCHIVE&amp;quot; including contents cascade constraints&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-03002: failure of Duplicate Db command at 10/16/2017 23:46:12&lt;br /&gt;
RMAN-05501: aborting duplication of target database&lt;br /&gt;
RMAN-06136: ORACLE error from auxiliary database: ORA-14404: partitioned table contains partitions in a different tablespace&lt;br /&gt;
&lt;br /&gt;
Recovery Manager complete.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
and when attempting to backup the database, we get errors&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
RMAN-06169: could not read file header for datafile 188 error reason 1&lt;br /&gt;
RMAN-06169: could not read file header for datafile 189 error reason 1&lt;br /&gt;
RMAN-06169: could not read file header for datafile 190 error reason 1&lt;br /&gt;
RMAN-06169: could not read file header for datafile 191 error reason 1&lt;br /&gt;
RMAN-06169: could not read file header for datafile 14 error reason 1&lt;br /&gt;
released channel: t1&lt;br /&gt;
released channel: t2&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-03002: failure of backup plus archivelog command at 10/17/2017 15:08:40&lt;br /&gt;
RMAN-06056: could not access datafile 14&lt;br /&gt;
&lt;br /&gt;
Recovery Manager complete.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Problem====&lt;br /&gt;
Tables in the tablespace have partitions in another tablespace so this one cannot be dropped.&amp;lt;br /&amp;gt;&lt;br /&gt;
Check which table partitions are in which tablespaces&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 200&lt;br /&gt;
set pagesize 200&lt;br /&gt;
col table_name for a14&lt;br /&gt;
col table_owner for a14&lt;br /&gt;
col partition_name for a14&lt;br /&gt;
select table_owner&lt;br /&gt;
,      table_name&lt;br /&gt;
,      partition_name&lt;br /&gt;
,      tablespace_name&lt;br /&gt;
from   dba_tab_partitions&lt;br /&gt;
where  (table_owner, table_name) in&lt;br /&gt;
       (&lt;br /&gt;
       select table_owner&lt;br /&gt;
       ,      table_name&lt;br /&gt;
       from   dba_tab_partitions x&lt;br /&gt;
       where  x.tablespace_name = &amp;#039;&amp;amp;&amp;amp;TABLESPACE_TO_DROP&amp;#039;&lt;br /&gt;
       and    exists ( select *&lt;br /&gt;
                       from   dba_tab_partitions y&lt;br /&gt;
                       where  x.table_owner = y.table_owner&lt;br /&gt;
                       and    x.table_name  = y.table_name&lt;br /&gt;
                       and    y.tablespace_name not in (&amp;#039;&amp;amp;TABLESPACE_TO_DROP&amp;#039;)&lt;br /&gt;
                       group  by table_owner&lt;br /&gt;
                       ,      table_name&lt;br /&gt;
                     )&lt;br /&gt;
        )&lt;br /&gt;
order by 1,2,partition_position&lt;br /&gt;
/&lt;br /&gt;
undef TABLESPACE_TO_DROP&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
TABLE_OWNER    TABLE_NAME     PARTITION_NAME TABLESPACE_NAME&lt;br /&gt;
-------------- -------------- -------------- ------------------------------&lt;br /&gt;
KPK            XND20          P0910          TS_THALER_PART_OLD&lt;br /&gt;
KPK            XND20          P1112          TS_THALER_PART_OLD&lt;br /&gt;
KPK            XND20          P13            TS_THALER_PART_OLD&lt;br /&gt;
KPK            XND20          P14            TS_THALER_PART_OLD&lt;br /&gt;
KPK            XND20          P15            TS_THALER_PART_OLD&lt;br /&gt;
KPK            XND20          P16            TS_THALER_DATA&lt;br /&gt;
KPK            XND20          P17            TS_THALER_DATA&lt;br /&gt;
KPK            XND20          P18            TS_THALER_DATA&lt;br /&gt;
KPK            XND20          PMAX           TS_THALER_DATA&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Solution====&lt;br /&gt;
If the intention is to keep all the tables then run this query to generate statements to move the relevant tables out of this tablespace&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select &amp;#039;alter table &amp;#039;||b.table_owner||&amp;#039;.&amp;#039;||b.table_name||&amp;#039; move partition &amp;#039;||b.partition_name||&amp;#039; tablespace &amp;amp;NEW_TABLESPACE;&amp;#039;&lt;br /&gt;
from   (&lt;br /&gt;
       select distinct table_name&lt;br /&gt;
       ,      partition_name&lt;br /&gt;
       from   dba_tab_partitions&lt;br /&gt;
       where  tablespace_name = &amp;#039;&amp;amp;&amp;amp;TABLESPACE_NAME&amp;#039;&lt;br /&gt;
       )                  a&lt;br /&gt;
,      dba_tab_partitions b&lt;br /&gt;
where  a.table_name       = b.table_name&lt;br /&gt;
and    b.tablespace_name != &amp;#039;&amp;amp;TABLESPACE_NAME&amp;#039;&lt;br /&gt;
/&lt;br /&gt;
undef TABLESPACE_NAME&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
If however, the intention is to drop the tablespace anyway, the tables need to be dropped before the tablespace can be dropped.&amp;lt;br /&amp;gt;&lt;br /&gt;
But ...tables with partitions in different tablespaces cannot be dropped. The partitions need to be dropped first!&amp;lt;br /&amp;gt;&lt;br /&gt;
Run the following query to generate statements to drop all the &amp;#039;problem&amp;#039; tables. When these have gone, the tablespace can be dropped.&lt;br /&gt;
* drop table partitions&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
spool /tmp/drop_table_partitions.sql&lt;br /&gt;
sqlplus / as sysdba&amp;lt;&amp;lt;EOSQL&lt;br /&gt;
set headi off newpa none feedb off trims on echo off&lt;br /&gt;
select &amp;#039;alter table &amp;#039;||table_owner||&amp;#039;.&amp;#039;||table_name||&amp;#039; drop partition &amp;#039;||partition_name||&amp;#039;;&amp;#039;&lt;br /&gt;
from   dba_tab_partitions&lt;br /&gt;
where  tablespace_name = &amp;#039;$TABLESPACE_NAME&amp;#039;&lt;br /&gt;
/&lt;br /&gt;
spool off&lt;br /&gt;
EOSQL&lt;br /&gt;
echo &amp;quot;@/tmp/drop_table_partitions.sql&amp;quot; | sqlplus / as sysdba&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* drop tables&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sqlplus / as sysdba&amp;lt;&amp;lt;EOSQL&lt;br /&gt;
select &amp;#039;drop table &amp;#039;||table_owner||&amp;#039;.&amp;#039;||table_name||&amp;#039;;&amp;#039;&lt;br /&gt;
from   dba_tab_partitions&lt;br /&gt;
where  tablespace_name = &amp;#039;$TABLESPACE_NAME&amp;#039;&lt;br /&gt;
spool /tmp/drop_tables.sql&lt;br /&gt;
/&lt;br /&gt;
spool off&lt;br /&gt;
EOSQL&lt;br /&gt;
echo &amp;quot;@/tmp/drop_tables.sql&amp;quot; | sqlplus / as sysdba&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* drop tablespace&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
drop tablespace ads_archive including contents and datafiles&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Find all table partitions in tablespaces with missing datafiles====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 1000 pages 100&lt;br /&gt;
col owner for a10&lt;br /&gt;
col segment_name for a40&lt;br /&gt;
col segment_type for a25&lt;br /&gt;
col partition_name for a20&lt;br /&gt;
col tablespace_name for a25&lt;br /&gt;
select owner&lt;br /&gt;
,      segment_name&lt;br /&gt;
,      segment_type&lt;br /&gt;
,      partition_name&lt;br /&gt;
,      tablespace_name&lt;br /&gt;
from   dba_segments&lt;br /&gt;
where  segment_type in (&amp;#039;TABLE PARTITION&amp;#039;, &amp;#039;TABLE SUBPARTITION&amp;#039;)&lt;br /&gt;
and    tablespace_name in (&lt;br /&gt;
                          select tablespace_name&lt;br /&gt;
                          from   dba_data_files&lt;br /&gt;
                          where  file_name like &amp;#039;%MISSING%&amp;#039;&lt;br /&gt;
                          )&lt;br /&gt;
order  by 1, 2, decode (segment_type, &amp;#039;TABLE SUBPARTITION&amp;#039;, 1, 2),4&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Use exchange partition to alter metadata of the tablespaces without moving the actual data====&lt;br /&gt;
* [https://community.oracle.com/thread/581401?start=15&amp;amp;tstart=0 this] is what you are looking for!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Workaround====&lt;br /&gt;
While working on the solution, a backup can be made using the &amp;quot;skip inaccessible&amp;quot; option. Put this in an rman cmdfile...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
connect catalog rmanusr/rmanpwd@rmancat&lt;br /&gt;
connect target sys/syspwd@adsa1&lt;br /&gt;
run {&lt;br /&gt;
allocate channel t1 type &amp;#039;sbt_tape&amp;#039; parms &amp;#039;ENV=(NSR_SERVER=hn6000.company.be,NSR_CLIENT=hn491,NSR_DATA_VOLUME_POOL=DD1DAILY,NSR_END_ERROR_IGNORE=TRUE)&amp;#039;;&lt;br /&gt;
allocate channel t2 type &amp;#039;sbt_tape&amp;#039; parms &amp;#039;ENV=(NSR_SERVER=hn6000.company.be,NSR_CLIENT=hn491,NSR_DATA_VOLUME_POOL=DD1DAILY,NSR_END_ERROR_IGNORE=TRUE)&amp;#039;;&lt;br /&gt;
configure retention policy to recovery window of 28 days;&lt;br /&gt;
configure controlfile autobackup on;&lt;br /&gt;
crosscheck archivelog all;&lt;br /&gt;
SQL &amp;#039;ALTER SYSTEM SWITCH LOGFILE&amp;#039;;&lt;br /&gt;
SQL &amp;#039;CREATE PFILE FROM SPFILE&amp;#039;;&lt;br /&gt;
backup filesperset 1 format &amp;#039;dbfull_%d_%I_%t_%s_%p&amp;#039; full database plus archivelog skip inaccessible delete all input;&lt;br /&gt;
backup current controlfile;&lt;br /&gt;
release channel t1;&lt;br /&gt;
release channel t2;&lt;br /&gt;
}&lt;br /&gt;
exit&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Another way of deleting the offending objects====&lt;br /&gt;
Taken from [http://www.dbarj.com.br/en/2015/01/resume-oracle-duplicate-database-failed-recovery-datafiles/ Recover from a failed RMAN duplicate]&amp;lt;br /&amp;gt;&lt;br /&gt;
Need to check it before running it blindly!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
set echo off feed off termo off trims on pages 0 newpa none lines 2000 headi off long 32000&lt;br /&gt;
col val for a1000&lt;br /&gt;
spool destroy_offending_objects.sql&lt;br /&gt;
&lt;br /&gt;
select to_clob (&amp;#039;alter table &amp;#039;|| table_name||&amp;#039; drop constraint &amp;#039;||constraint_name||&amp;#039;;&amp;#039;) Val&lt;br /&gt;
from user_constraints where constraint_type in (&amp;#039;R&amp;#039;,&amp;#039;P&amp;#039;) and table_name in (select distinct table_name from user_tab_partitions)&lt;br /&gt;
union all&lt;br /&gt;
select to_clob (&amp;#039;drop index &amp;#039;||index_name||&amp;#039;;&amp;#039;) Val from user_indexes where table_name in (select distinct table_name from user_tab_partitions)&lt;br /&gt;
union all&lt;br /&gt;
select to_clob (&amp;#039;alter table &amp;#039;||table_name|| &amp;#039; drop partition &amp;#039;||partition_name||&amp;#039;;&amp;#039;) from dba_tab_partitions&lt;br /&gt;
where tablespace_name in (select tablespace_name from dba_data_files where file_name like &amp;#039;%MISSING%&amp;#039;)&lt;br /&gt;
union all&lt;br /&gt;
Select case&lt;br /&gt;
when instr (VAl, &amp;#039;PARTITION&amp;#039;) = 0 Then&lt;br /&gt;
substr (Val,1,InStr (Val,&amp;#039;)&amp;#039;)+1)||&amp;#039;;&amp;#039;&lt;br /&gt;
else&lt;br /&gt;
substr (Val,1,InStr (Val,&amp;#039;)&amp;#039;)+1)||&amp;#039; local;&amp;#039;&lt;br /&gt;
End val&lt;br /&gt;
from&lt;br /&gt;
(select dbms_metadata.get_ddl (&amp;#039;INDEX&amp;#039;, index_name,&amp;#039;TEST&amp;#039;) Val from user_indexes where table_name in (select distinct table_name from user_tab_partitions))&lt;br /&gt;
union all&lt;br /&gt;
Select Val&lt;br /&gt;
from&lt;br /&gt;
(select dbms_metadata.get_dependent_ddl (&amp;#039;REF_CONSTRAINT&amp;#039;, table_name,&amp;#039;TEST&amp;#039;) Val&lt;br /&gt;
from user_tables where table_name in (select distinct table_name from user_tab_partitions join user_constraints using ( table_name)&lt;br /&gt;
where constraint_type=&amp;#039;R&amp;#039;))&lt;br /&gt;
union all&lt;br /&gt;
select Val&lt;br /&gt;
from&lt;br /&gt;
(select dbms_metadata.get_ddl (&amp;#039;CONSTRAINT&amp;#039;, constraint_name,&amp;#039;TEST&amp;#039;) Val&lt;br /&gt;
from user_constraints&lt;br /&gt;
where constraint_type=&amp;#039;P&amp;#039; and table_name in (select distinct table_name from user_tab_partitions)&lt;br /&gt;
)&lt;br /&gt;
union all&lt;br /&gt;
select to_clob (val)&lt;br /&gt;
from (select distinct &amp;#039;drop tablespace &amp;#039;||tablespace_name|| &amp;#039; including contents and datafiles;&amp;#039; val&lt;br /&gt;
from dba_tab_partitions&lt;br /&gt;
where tablespace_name in (select tablespace_name from dba_data_files where file_name like &amp;#039;%MISSING%&amp;#039;)&lt;br /&gt;
);&lt;br /&gt;
&lt;br /&gt;
spoo off&lt;br /&gt;
&lt;br /&gt;
@destroy_offending_objects&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORA-28112: failed to execute policy function===&lt;br /&gt;
when exporting or importing using [[Data Pump]]&amp;lt; /br&amp;gt;&lt;br /&gt;
During expdp is accompanied by &amp;quot;&amp;#039;&amp;#039;&amp;#039;ORA-31693: Table data object &amp;quot;SYSMAN&amp;quot;.&amp;quot;MGMT_IP_REPORT_DEF&amp;quot; failed to load/unload and is being skipped due to error:&amp;#039;&amp;#039;&amp;#039;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
===Reason===&lt;br /&gt;
This happens due to audit policies being defined on the table but the policy function is defined in another schema.&lt;br /&gt;
&lt;br /&gt;
===Solution===&lt;br /&gt;
Either drop the policy after importing the table with:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
begin&lt;br /&gt;
    for rec in (select * from dba_audit_policies where object_schema = &amp;#039;SYSMAN&amp;#039;) loop&lt;br /&gt;
        dbms_fga.drop_policy(object_schema =&amp;gt; rec.object_schema,&lt;br /&gt;
                             object_name =&amp;gt; rec.object_name,&lt;br /&gt;
                             policy_name =&amp;gt; rec.policy_name);  &lt;br /&gt;
    end loop;&lt;br /&gt;
end;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or exclude the policies during export by adding this to the .par file:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
exclude=FGA_POLICY&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or even better, give the necessary grants to the exporting user...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
grant exempt access policy to impexpusr;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The sysdba role has this automatically.&lt;br /&gt;
===ORA-17629: Cannot connect to the remote database server===&lt;br /&gt;
Active duplication fails to connect even though dns connection exists in tnsnames.ora&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
Problem:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
DUPLICATE TARGET DATABASE FROM ACTIVE DATABASE DORECOVER NOFILENAMECHECK;&lt;br /&gt;
&lt;br /&gt;
RMAN-03002: failure of Duplicate Db command at 05/27/2015 12:52:24&lt;br /&gt;
RMAN-05501: aborting duplication of target database&lt;br /&gt;
RMAN-03015: error occurred in stored script Memory Script&lt;br /&gt;
RMAN-03009: failure of backup command on ORA_DISK_1 channel at 05/27/2015 12:52:23&lt;br /&gt;
ORA-17629: Cannot connect to the remote database server&lt;br /&gt;
ORA-17627: ORA-12154: TNS:could not resolve the connect identifier specified&lt;br /&gt;
&lt;br /&gt;
ORA-17629: Cannot connect to the remote database server&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
Solution:&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
Update the tnsnames.ora of both destination &amp;#039;&amp;#039;&amp;#039;and&amp;#039;&amp;#039;&amp;#039; source ORACLE_HOMEs!&lt;br /&gt;
&lt;br /&gt;
===ORA-01950: no privileges on tablespace &amp;#039;SYSAUX&amp;#039;===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
26-JUN-15 03:12:27.545: &amp;gt;&amp;gt;&amp;gt; ORA-31642: the following SQL statement fails: &lt;br /&gt;
BEGIN &amp;quot;SYS&amp;quot;.&amp;quot;DBMS_RULE_EXP_RULES&amp;quot;.SCHEMA_CALLOUT(:1,0,1,&amp;#039;12.01.00.02.00&amp;#039;); END;&lt;br /&gt;
ORA-01950: no privileges on tablespace &amp;#039;SYSAUX&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Cause:&amp;#039;&amp;#039;&amp;#039;&amp;lt;br /&amp;gt;&lt;br /&gt;
In this case, it seems SYSMAN has no rights to create objects in the SYSAUX tablespace&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Solution:&amp;#039;&amp;#039;&amp;#039;&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter user SYSMAN quota unlimited on sysaux;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
More information [https://support.oracle.com/epmos/faces/SearchDocDisplay?_adf.ctrl-state=bov7jp5pq_4&amp;amp;_afrLoop=547371065896716#SYMPTOM here]&lt;br /&gt;
&lt;br /&gt;
===ORA-39080: failed to create queues &amp;quot;KUPC$C_1_20150616165037&amp;quot; and &amp;quot;KUPC$S_1_20150616165037&amp;quot; for Data Pump job===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
expdp /&lt;br /&gt;
&lt;br /&gt;
Export: Release 11.2.0.4.0 - Production on Tue Jun 16 16:50:36 2015&lt;br /&gt;
&lt;br /&gt;
Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.&lt;br /&gt;
&lt;br /&gt;
Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production&lt;br /&gt;
With the Partitioning, OLAP, Data Mining and Real Application Testing options&lt;br /&gt;
ORA-31626: job does not exist&lt;br /&gt;
ORA-31637: cannot create job SYS_EXPORT_SCHEMA_01 for user OPS$ORAIBM&lt;br /&gt;
ORA-06512: at &amp;quot;SYS.DBMS_SYS_ERROR&amp;quot;, line 95&lt;br /&gt;
ORA-06512: at &amp;quot;SYS.KUPV$FT_INT&amp;quot;, line 798&lt;br /&gt;
[[ORA-39080: failed to create queues &amp;quot;KUPC$C_1_20150616165037&amp;quot; and &amp;quot;KUPC$S_1_20150616165037&amp;quot; for Data Pump job]]&lt;br /&gt;
ORA-06512: at &amp;quot;SYS.DBMS_SYS_ERROR&amp;quot;, line 95&lt;br /&gt;
ORA-06512: at &amp;quot;SYS.KUPC$QUE_INT&amp;quot;, line 1534&lt;br /&gt;
ORA-24002: QUEUE_TABLE SYS.AQ$KUPC$DATAPUMP_QUETAB_1 does not exist&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Cause:====&lt;br /&gt;
Possibly some or all of OLAP module has got itself deinstalled.&lt;br /&gt;
====Solution:====&lt;br /&gt;
Try:&lt;br /&gt;
* Recompiling invalid objects. @?/rdbms/admin/utlrp&lt;br /&gt;
* Reinstalling DBMS_CUBE packages by (re)running catproc.sql. @?/rdbms/admin/catproc followed by @?/rdbms/admin/utlrp&lt;br /&gt;
* Reinstalling OLAP. @?/olap/admin/olap.sql SYSAUX TEMP; But see Metalink note ID 296187.1 for full instructions.&lt;br /&gt;
* Check metalink for bugs. See ID 345198.1 and possibly ID 453796.1&lt;br /&gt;
===ORA-14063: Unusable index exists on unique/primary constraint key===&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;ORA-39083: Object type CONSTRAINT failed to create with error:&amp;#039;&amp;#039;&amp;#039;&amp;lt;br /&amp;gt;&lt;br /&gt;
During an import datapump (impdp), import failed because indexes were in error before the tables were exported. This causes the import of rows to be skipped.&amp;lt;br /&amp;gt;&lt;br /&gt;
If the export cannot be done again (having compiled the indexes), then the metadata can be imported and the indexes compiled before importing the data.&lt;br /&gt;
* Import the metadata&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cat&amp;lt;&amp;lt;EOCAT &amp;gt;impdp_adst_ads_archive_metadata.par&lt;br /&gt;
userid=&amp;#039;/ as sysdba&amp;#039;&lt;br /&gt;
dumpfile=adst_ads_archive.dmp&lt;br /&gt;
logfile=impdp_adst_ads_archive_metadata.log&lt;br /&gt;
content=metadata_only&lt;br /&gt;
EOCAT&lt;br /&gt;
&lt;br /&gt;
impdp parfile=impdp_adst_ads_archive_metadata.par&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Find the bad indexes and recompile them&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select &amp;#039;alter index &amp;#039;|| owner||&amp;#039;.&amp;#039;||index_name||&amp;#039; rebuild online parallel 8;&amp;#039;&lt;br /&gt;
from   dba_indexes&lt;br /&gt;
where  status = &amp;#039;UNUSABLE&amp;#039;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Import the data&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cat&amp;lt;&amp;lt;EOCAT &amp;gt;impdp_adst_ads_archive_data.par&lt;br /&gt;
userid=&amp;#039;/ as sysdba&amp;#039;&lt;br /&gt;
dumpfile=adst_ads_archive.dmp&lt;br /&gt;
logfile=impdp_adst_ads_archive_data.log&lt;br /&gt;
table_exists_action=append&lt;br /&gt;
content=data_only&lt;br /&gt;
EOCAT&lt;br /&gt;
&lt;br /&gt;
impdp parfile=impdp_adst_ads_archive_data.par&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORA-09925: Unable to create audit trail file===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SQL&amp;gt; startup nomount pfile=&amp;quot;/oracle/TRSCRP1/admin/initTRSCRP1.ora&amp;quot;&lt;br /&gt;
ORA-09925: Unable to create audit trail file&lt;br /&gt;
SVR4 Error: 2: No such file or directory&lt;br /&gt;
Additional information: 9925&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
connected to auxiliary database (not started)&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-03002: failure of Duplicate Db command at 08/29/2017 15:53:09&lt;br /&gt;
RMAN-05501: aborting duplication of target database&lt;br /&gt;
RMAN-03015: error occurred in stored script Memory Script&lt;br /&gt;
RMAN-04014: startup failed: ORA-09925: Unable to create audit trail file&lt;br /&gt;
IBM AIX RISC System/6000 Error: 2: No such file or directory&lt;br /&gt;
Additional information: 9925&lt;br /&gt;
&lt;br /&gt;
Recovery Manager complete.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Problem====&lt;br /&gt;
This will be almost certainly one of two issues. Either the directory is not writable by the id that started the instance or the directory just does not exist.&lt;br /&gt;
====Solution====&lt;br /&gt;
Note there can be a difference between what you see when you type:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
show parameter audit&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
and when you type:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
strings -a $ORACLE_HOME/dbs/spfile${ORACLE_SID}.ora | grep -i audit&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
due to someone doing an &amp;quot;alter system&amp;quot; without the &amp;quot;scope=spfile&amp;quot; or &amp;quot;scope=both&amp;quot;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SQL&amp;gt; host ls -al /oracle/TRSCRP1/admin/adump&lt;br /&gt;
SQL&amp;gt; host mkdir /oracle/TRSCRP1/admin/adump&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===ORA-09925: Unable to create audit trail file===&lt;br /&gt;
When starting SQL*Plus with no db processes running (expecting to see &amp;quot;Connected to an idle instance&amp;quot;), we get this:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ERROR:&lt;br /&gt;
ORA-09925: Unable to create audit trail file&lt;br /&gt;
IBM AIX RISC System/6000 Error: 2: No such file or directory&lt;br /&gt;
Additional information: 9925&lt;br /&gt;
ORA-01075: you are currently logged on&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Filesystem permissions are fine&lt;br /&gt;
* &amp;#039;strings spfile&amp;lt;SID&amp;gt;.ora | grep audit&amp;#039; shows the correct directory&lt;br /&gt;
* Running on AIX&lt;br /&gt;
AIX is the clue here... need to check for semaphores and locked shared memory objects&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
(0) UCLID55D oraibm@solax082:/oracle/product/11.2.0.3/bin&amp;gt; sysresv&lt;br /&gt;
&lt;br /&gt;
IPC Resources for ORACLE_SID &amp;quot;UCLID55D&amp;quot; :&lt;br /&gt;
Shared Memory:&lt;br /&gt;
ID              KEY&lt;br /&gt;
8388640         0xffffffff&lt;br /&gt;
579862561       0xffffffff&lt;br /&gt;
384827426       0x326f32e8&lt;br /&gt;
&lt;br /&gt;
Semaphores:&lt;br /&gt;
ID              KEY&lt;br /&gt;
167772287       0xf09f4914&lt;br /&gt;
Oracle Instance alive for sid &amp;quot;UCLID55D&amp;quot;&lt;br /&gt;
&lt;br /&gt;
(0) UCLID55D oraibm@solax082:/oracle/product/11.2.0.3/bin&amp;gt; ipcrm -m 8388640&lt;br /&gt;
(0) UCLID55D oraibm@solax082:/oracle/product/11.2.0.3/bin&amp;gt; ipcrm -m 579862561&lt;br /&gt;
(0) UCLID55D oraibm@solax082:/oracle/product/11.2.0.3/bin&amp;gt; ipcrm -m 384827426&lt;br /&gt;
&lt;br /&gt;
(0) UCLID55D oraibm@solax082:/oracle/product/11.2.0.3/bin&amp;gt; ipcrm -s 167772287&lt;br /&gt;
&lt;br /&gt;
(0) UCLID55D oraibm@solax082:/oracle/product/11.2.0.3/bin&amp;gt; sysresv&lt;br /&gt;
&lt;br /&gt;
IPC Resources for ORACLE_SID &amp;quot;UCLID55D&amp;quot; :&lt;br /&gt;
Shared Memory&lt;br /&gt;
ID              KEY&lt;br /&gt;
No shared memory segments used&lt;br /&gt;
Semaphores:&lt;br /&gt;
ID              KEY&lt;br /&gt;
No semaphore resources used&lt;br /&gt;
Oracle Instance not alive for sid &amp;quot;UCLID55D&amp;quot;&lt;br /&gt;
&lt;br /&gt;
(0) UCLID55D oraibm@solax082:/oracle/product/11.2.0.3/bin&amp;gt; ps -ef | grep UCLID55D&lt;br /&gt;
oraibm 3326 23776 0 14:12:05 pts/1 0:00 grep UCLID55D &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===RMAN-06023: no backup or copy of datafile 1 found to restore===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-03002: failure of Duplicate Db command at 05/16/2018 16:08:13&lt;br /&gt;
RMAN-05501: aborting duplication of target database&lt;br /&gt;
RMAN-05556: not all datafiles have backups that can be recovered to SCN 278250901080&lt;br /&gt;
RMAN-03015: error occurred in stored script Memory Script&lt;br /&gt;
RMAN-06026: some targets not found - aborting restore&lt;br /&gt;
RMAN-06023: no backup or copy of datafile 7 found to restore&lt;br /&gt;
RMAN-06023: no backup or copy of datafile 6 found to restore&lt;br /&gt;
RMAN-06023: no backup or copy of datafile 5 found to restore&lt;br /&gt;
RMAN-06023: no backup or copy of datafile 4 found to restore&lt;br /&gt;
RMAN-06023: no backup or copy of datafile 3 found to restore&lt;br /&gt;
RMAN-06023: no backup or copy of datafile 2 found to restore&lt;br /&gt;
RMAN-06023: no backup or copy of datafile 1 found to restore&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Seems pretty straightforward? SCN was set too early for the retention period. But no, not this time.&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
RMAN&amp;gt; list backup of datafile 1;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
List of Backup Sets&lt;br /&gt;
===================&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
BS Key  Type LV Size       Device Type Elapsed Time Completion Time&lt;br /&gt;
------- ---- -- ---------- ----------- ------------ -------------------&lt;br /&gt;
110170340 Incr 0  132.90G    SBT_TAPE    00:18:32     2018-05-14 01:19:40&lt;br /&gt;
        BP Key: 110170345   Status: AVAILABLE  Compressed: NO  Tag: WEEKLY_FULL&lt;br /&gt;
        Handle: 24639762_REPORTA_07t2r3uk_1_1   Media: V_17152809_77191330&lt;br /&gt;
  List of Datafiles in backup set 110170340&lt;br /&gt;
  File LV Type Ckp SCN    Ckp Time            Name&lt;br /&gt;
  ---- -- ---- ---------- ------------------- ----&lt;br /&gt;
  1    0  Incr 277998128991 2018-05-14 01:01:08 /cln/acc/ora_data3/reporta/system01.dbf&lt;br /&gt;
&lt;br /&gt;
BS Key  Type LV Size       Device Type Elapsed Time Completion Time&lt;br /&gt;
------- ---- -- ---------- ----------- ------------ -------------------&lt;br /&gt;
110355808 Incr 1  204.00M    SBT_TAPE    00:05:13     2018-05-15 01:06:22&lt;br /&gt;
        BP Key: 110355813   Status: AVAILABLE  Compressed: NO  Tag: DAILY_INCREMENTAL&lt;br /&gt;
        Handle: 24661053_REPORTA_3ft2toal_1_1   Media: V_17173010_77253424&lt;br /&gt;
  List of Datafiles in backup set 110355808&lt;br /&gt;
  File LV Type Ckp SCN    Ckp Time            Name&lt;br /&gt;
  ---- -- ---- ---------- ------------------- ----&lt;br /&gt;
  1    1  Incr 278044267395 2018-05-15 01:01:09 /cln/acc/ora_data3/reporta/system01.dbf&lt;br /&gt;
&lt;br /&gt;
BS Key  Type LV Size       Device Type Elapsed Time Completion Time&lt;br /&gt;
------- ---- -- ---------- ----------- ------------ -------------------&lt;br /&gt;
110543802 Incr 1  237.00M    SBT_TAPE    00:05:51     2018-05-16 01:07:40&lt;br /&gt;
        BP Key: 110543807   Status: AVAILABLE  Compressed: NO  Tag: DAILY_INCREMENTAL&lt;br /&gt;
        Handle: 24681602_REPORTA_6nt30cnt_1_1   Media: V_17133646_77315270&lt;br /&gt;
  List of Datafiles in backup set 110543802&lt;br /&gt;
  File LV Type Ckp SCN    Ckp Time            Name&lt;br /&gt;
  ---- -- ---- ---------- ------------------- ----&lt;br /&gt;
  1    1  Incr 278286445856 2018-05-16 01:01:50 /cln/acc/ora_data3/reporta/system01.dbf&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
SCN was only 12 hours ago with a retention of 28 days! The backup piece dated 2018-05-15 01:06:22 is clearly available and on the device type set_tape.&amp;lt;br /&amp;gt;&lt;br /&gt;
The trick here was to look back through the logs and look more closely at what the file restore message was saying...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
channel t0: starting datafile backup set restore&lt;br /&gt;
channel t0: specifying datafile(s) to restore from backup set&lt;br /&gt;
channel t0: restoring datafile 00001 to /cln/acc/ora_data3/reporta/system01.dbf             &amp;lt; &amp;lt; &amp;lt; ==============&lt;br /&gt;
channel t0: reading from backup piece dbfull_REPORTA_738887052_967580186_116_1&lt;br /&gt;
channel t2: ORA-19870: error while restoring backup piece dbfull_REPORTA_738887052_967579750_113_1&lt;br /&gt;
ORA-19507: failed to retrieve sequential file, handle=&amp;quot;dbfull_REPORTA_738887052_967579750_113_1&amp;quot;, parms=&amp;quot;&amp;quot;&lt;br /&gt;
ORA-27029: skgfrtrv: sbtrestore returned error&lt;br /&gt;
ORA-19511: non RMAN, but media manager or vendor specific failure, error text:&lt;br /&gt;
   CreateOraObject20: Job[0] thread[55116090]: Restore: GetBackupInfo() for Archive File[dbfull_REPORTA_738887052_967579750_113_1] failed.&lt;br /&gt;
ORA-0651&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
It was not the fact that it could not find the data on tape, it was that it could not save the file to the location indicated!!&lt;br /&gt;
In the RMAN DUPLICATE script, I had all the file paths redirected (a mixture of convert parameters and spfile set) to a /restore filesystem.&amp;lt;br /&amp;gt;&lt;br /&gt;
But I forgot one!&amp;lt;br /&amp;gt;&lt;br /&gt;
A handy thing to do is to search out the file paths with this to see if something is still wrong:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cd $ORACLE_HOME/dbs&lt;br /&gt;
strings -a spfile${ORACLE_SID}.ora | grep dest&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This should show any paths still not getting caught by the DUPLICATE script.&lt;br /&gt;
&lt;br /&gt;
===RMAN-06136: ORACLE error from auxiliary database: ORA-06502: PL/SQL: numeric or value error===&lt;br /&gt;
When cloning a database, the duplicate fails with this error.&lt;br /&gt;
====Problem====&lt;br /&gt;
This duplicate had no target connection but did have a catalog and auxiliary connection.&lt;br /&gt;
In the catalog (which was the catalog where the target was registerd), there was also an entry in that catalog with the same name as the auxiliary - left over from the days when these 2 instances were Primary and Standby in a Dataguard configuration.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
Datafile 414 skipped by request&lt;br /&gt;
Datafile 415 skipped by request&lt;br /&gt;
Datafile 419 skipped by request&lt;br /&gt;
Datafile 420 skipped by request&lt;br /&gt;
Datafile 421 skipped by request&lt;br /&gt;
&lt;br /&gt;
DBGSQL:     AUXILIARY&amp;gt; begin :ofname := sys.dbms_backup_restore.convertFileName( fname   =&amp;gt;   :ifname, ftype   =&amp;gt;   :iftype, osftype =&amp;gt;   TRUE); end;&lt;br /&gt;
DBGSQL:        sqlcode = 6502&lt;br /&gt;
DBGSQL:         B :ofname = NULL&lt;br /&gt;
DBGSQL:         B :ifname =&lt;br /&gt;
DBGSQL:         B :iftype = 2&lt;br /&gt;
restarting auxiliary database without server parameter file&lt;br /&gt;
Oracle instance started&lt;br /&gt;
&lt;br /&gt;
Total System Global Area   32068440064 bytes&lt;br /&gt;
&lt;br /&gt;
Fixed Size                     2262200 bytes&lt;br /&gt;
Variable Size              16978545480 bytes&lt;br /&gt;
Database Buffers           15032385536 bytes&lt;br /&gt;
Redo Buffers                  55246848 bytes&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-03002: failure of Duplicate Db command at 10/04/2017 14:50:29&lt;br /&gt;
RMAN-05501: aborting duplication of target database&lt;br /&gt;
RMAN-06136: ORACLE error from auxiliary database: ORA-06502: PL/SQL: numeric or value error&lt;br /&gt;
&lt;br /&gt;
Recovery Manager complete.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Solution====&lt;br /&gt;
Connect to the catalog and unregister the name of the auxiliary database. It shouldn&amp;#039;t be there anyway.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rman catalog rmanusr/rmanpwd@rmancat&lt;br /&gt;
&lt;br /&gt;
Recovery Manager: Release 11.2.0.4.0 - Production on Wed Oct 4 15:00:00 2017&lt;br /&gt;
&lt;br /&gt;
Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.&lt;br /&gt;
&lt;br /&gt;
connected to recovery catalog database&lt;br /&gt;
&lt;br /&gt;
RMAN&amp;gt; set dbid 4260753020;&lt;br /&gt;
&lt;br /&gt;
executing command: SET DBID&lt;br /&gt;
database name is &amp;quot;LBK&amp;quot; and DBID is 4260753020&lt;br /&gt;
&lt;br /&gt;
RMAN&amp;gt; list db_unique_name of database;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
List of Databases&lt;br /&gt;
DB Key  DB Name  DB ID            Database Role    Db_unique_name&lt;br /&gt;
------- ------- ----------------- ---------------  ------------------&lt;br /&gt;
13301587 LBK      4260753020       PRIMARY          LBK&lt;br /&gt;
13301587 LBK      4260753020       STANDBY          ACC_PERF&lt;br /&gt;
13301587 LBK      4260753020       STANDBY          LBKRO&lt;br /&gt;
&lt;br /&gt;
RMAN&amp;gt; unregister db_unique_name &amp;#039;ACC_PERF&amp;#039;;&lt;br /&gt;
&lt;br /&gt;
database db_unique_name is &amp;quot;ACC_PERF&amp;quot;, db_name is &amp;quot;LBK&amp;quot; and DBID is 4260753020&lt;br /&gt;
&lt;br /&gt;
Want to unregister the database with target db_unique_name (enter YES or NO)? YES&lt;br /&gt;
database with db_unique_name ACC_PERF unregistered from the recovery catalog&lt;br /&gt;
&lt;br /&gt;
RMAN&amp;gt; exit&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORA-39181: Only partial table data may be exported due to fine grain access control on &amp;quot;owner&amp;quot;.&amp;quot;&amp;lt;table_name&amp;gt;&amp;quot;===&lt;br /&gt;
&lt;br /&gt;
===Reason===&lt;br /&gt;
This happens when applications are designed with fine-grained access.&lt;br /&gt;
===Solution===&lt;br /&gt;
Grant the necessary privileges to the exporting user...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
grant exempt access policy to ops$oraibm;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORA-04030: out of process memory when trying to allocate 2520 bytes===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
expdp problem (ORA-04030: out of process memory when trying to allocate 2520 bytes (pga heap,koh-kghu call heap))&lt;br /&gt;
&lt;br /&gt;
select value from v$pgastat where name=&amp;#039;maximum PGA allocated&amp;#039;;&lt;br /&gt;
&lt;br /&gt;
SHOW PARAMETER TARGET&lt;br /&gt;
&lt;br /&gt;
ORA-04030: out of process memory when trying to allocate 2520 bytes (pga heap,koh-kghu call heap)&lt;br /&gt;
&lt;br /&gt;
alter system reset pga_aggregate_target scope=spfile;&lt;br /&gt;
&lt;br /&gt;
show sga&lt;br /&gt;
&lt;br /&gt;
select * from v$pgastat;&lt;br /&gt;
&lt;br /&gt;
show parameter process&lt;br /&gt;
&lt;br /&gt;
select sum(value)/1024/1024 Mb&lt;br /&gt;
from   v$sesstat s, v$statname n&lt;br /&gt;
where  1=1&lt;br /&gt;
and    n.STATISTIC# = s.STATISTIC#&lt;br /&gt;
and    name = &amp;#039;session pga memory&amp;#039;&lt;br /&gt;
&lt;br /&gt;
show parameter WORKAREA&lt;br /&gt;
&lt;br /&gt;
select value from v$pgastat where name=&amp;#039;maximum PGA allocated&amp;#039;;&lt;br /&gt;
&lt;br /&gt;
alter system set memory_max_target=10G scope=spfile;&lt;br /&gt;
&lt;br /&gt;
alter system set memory_target=3G scope=both;&lt;br /&gt;
&lt;br /&gt;
select * from v$memory_target_advice order by memory_size;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORA-04031: unable to allocate 32 bytes of shared memory (&amp;quot;shared pool&amp;quot;,&amp;quot;select name,online$,contents...&amp;quot;,&amp;quot;KGLH0^e5705bfc&amp;quot;,&amp;quot;kglHeapInitialize:temp&amp;quot;)===&lt;br /&gt;
* [https://blogs.oracle.com/db/entry/ora-4031_troubleshooting ORA-4031 Troubleshooting]&lt;br /&gt;
* [https://support.oracle.com/epmos/faces/DocumentDisplay?_afrLoop=89215376348478&amp;amp;id=396940.1&amp;amp;_afrWindowMode=0&amp;amp;_adf.ctrl-state=u1z0xcppg_4 Troubleshooting and Diagnosing ORA-4031 Error - (Doc ID 396940.1)]&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ORA-04031: unable to allocate  bytes of shared memory (&amp;quot;&amp;quot;,&amp;quot;&amp;quot;,&amp;quot;&amp;quot;,&amp;quot;&amp;quot;) &lt;br /&gt;
ORA-04031: unable to allocate 32 bytes of shared memory (&amp;quot;shared pool&amp;quot;,&amp;quot;select name,online$,contents...&amp;quot;,&amp;quot;KGLH0^e5705bfc&amp;quot;,&amp;quot;kglHeapInitialize:temp&amp;quot;) &lt;br /&gt;
Incident details in: /oracle/diag/rdbms/mape/MAPE/incident/incdir_86754/MAPE_dm00_14221536_i86754.trc &lt;br /&gt;
Wed Jul 31 20:42:50 2013 &lt;br /&gt;
Dumping diagnostic data in directory=[cdmp_20130731204250], requested by (instance=1, osid=14221536 (DM00)), summary=[incident=86753]. &lt;br /&gt;
Wed Jul 31 20:42:51 2013 &lt;br /&gt;
Sweep [inc][86754]: completed &lt;br /&gt;
Sweep [inc][86753]: completed &lt;br /&gt;
Sweep [inc2][86753]: completed &lt;br /&gt;
Wed Jul 31 20:42:57 2013 &lt;br /&gt;
Use ADRCI or Support Workbench to package the incident. &lt;br /&gt;
See Note 411.1 at My Oracle Support for error and packaging details. &lt;br /&gt;
Dumping diagnostic data in directory=[cdmp_20130731204257], requested by (instance=1, osid=14221536 (DM00)), summary=[incident=86754]. &lt;br /&gt;
Wed Jul 31 20:43:35 2013 &lt;br /&gt;
Errors in file /oracle/diag/rdbms/mape/MAPE/trace/MAPE_dw02_40567024.trc  (incident=82993): &lt;br /&gt;
ORA-04031: unable to allocate 32 bytes of shared memory (&amp;quot;shared pool&amp;quot;,&amp;quot;select order#,columns,types ...&amp;quot;,&amp;quot;KGLH0^470434f8&amp;quot;,&amp;quot;kglHeapInitialize:temp&amp;quot;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Database had already crashed so nothing to do but:&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
(0) MAPE ora@x025:/home/ora&amp;gt; sqlplus / as sysdba&lt;br /&gt;
&lt;br /&gt;
SQL*Plus: Release 11.2.0.3.0 Production on Fri Aug 2 14:26:20 2013&lt;br /&gt;
&lt;br /&gt;
Copyright (c) 1982, 2011, Oracle.  All rights reserved.&lt;br /&gt;
&lt;br /&gt;
Connected.&lt;br /&gt;
SYS@MAPE&amp;gt; alter system flush shared_pool;&lt;br /&gt;
alter system flush shared_pool&lt;br /&gt;
*&lt;br /&gt;
ERROR at line 1:&lt;br /&gt;
ORA-01012: not logged on&lt;br /&gt;
Process ID: 0&lt;br /&gt;
Session ID: 0 Serial number: 0&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
SYS@MAPE&amp;gt; shutdown abort&lt;br /&gt;
ORACLE instance shut down.&lt;br /&gt;
SYS@MAPE&amp;gt; startup&lt;br /&gt;
ORACLE instance started.&lt;br /&gt;
&lt;br /&gt;
Total System Global Area  734892032 bytes&lt;br /&gt;
Fixed Size                  2225128 bytes&lt;br /&gt;
Variable Size             398461976 bytes&lt;br /&gt;
Database Buffers          318767104 bytes&lt;br /&gt;
Redo Buffers               15437824 bytes&lt;br /&gt;
Database mounted.&lt;br /&gt;
Database opened.&lt;br /&gt;
&lt;br /&gt;
SYS@MAPE&amp;gt; show parameter pool&lt;br /&gt;
&lt;br /&gt;
NAME                                 TYPE                           VALUE&lt;br /&gt;
------------------------------------ ------------------------------ ------------------------------&lt;br /&gt;
buffer_pool_keep                     string&lt;br /&gt;
buffer_pool_recycle                  string&lt;br /&gt;
global_context_pool_size             string&lt;br /&gt;
java_pool_size                       big integer                    0&lt;br /&gt;
large_pool_size                      big integer                    0&lt;br /&gt;
olap_page_pool_size                  big integer                    0&lt;br /&gt;
shared_pool_reserved_size            big integer                    18M&lt;br /&gt;
shared_pool_size                     big integer                    208M&lt;br /&gt;
streams_pool_size                    big integer                    0&lt;br /&gt;
SYS@MAPE&amp;gt; show sga&lt;br /&gt;
&lt;br /&gt;
Total System Global Area  734892032 bytes&lt;br /&gt;
Fixed Size                  2225128 bytes&lt;br /&gt;
Variable Size             385879064 bytes&lt;br /&gt;
Database Buffers          331350016 bytes&lt;br /&gt;
Redo Buffers               15437824 bytes&lt;br /&gt;
SYS@MAPE&amp;gt; exit&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
but for reference, the causes could well be the applications running on the database are not using bind variables...&amp;lt;br /&amp;gt;&lt;br /&gt;
From [http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:528893984337 asktom.oracle.com]&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
Just to give you a tiny idea of how huge of a difference this &lt;br /&gt;
can make performance wise, you only need to run a very small &lt;br /&gt;
test:&lt;br /&gt;
&lt;br /&gt;
tkyte@TKYTE816&amp;gt; alter system flush shared_pool;&lt;br /&gt;
System altered.&lt;br /&gt;
&lt;br /&gt;
tkyte@TKYTE816&amp;gt; declare&lt;br /&gt;
  2      type rc is ref cursor;&lt;br /&gt;
  3      l_rc rc;&lt;br /&gt;
  4      l_dummy all_objects.object_name%type;&lt;br /&gt;
  5      l_start number default dbms_utility.get_time;&lt;br /&gt;
  6  begin&lt;br /&gt;
  7      for i in 1 .. 1000&lt;br /&gt;
  8      loop&lt;br /&gt;
  9          open l_rc for&lt;br /&gt;
 10          &amp;#039;select object_name&lt;br /&gt;
 11             from all_objects&lt;br /&gt;
 12            where object_id = &amp;#039; || i;&lt;br /&gt;
 13          fetch l_rc into l_dummy;&lt;br /&gt;
 14          close l_rc;&lt;br /&gt;
 15      end loop;&lt;br /&gt;
 16      dbms_output.put_line&lt;br /&gt;
 17      ( round( (dbms_utility.get_time-l_start)/100, 2 ) ||&lt;br /&gt;
 18        &amp;#039; seconds...&amp;#039; );&lt;br /&gt;
 19  end;&lt;br /&gt;
 20  /&lt;br /&gt;
14.86 seconds...&lt;br /&gt;
&lt;br /&gt;
PL/SQL procedure successfully completed.&lt;br /&gt;
&lt;br /&gt;
tkyte@TKYTE816&amp;gt; declare&lt;br /&gt;
  2      type rc is ref cursor;&lt;br /&gt;
  3      l_rc rc;&lt;br /&gt;
  4      l_dummy all_objects.object_name%type;&lt;br /&gt;
  5      l_start number default dbms_utility.get_time;&lt;br /&gt;
  6  begin&lt;br /&gt;
  7      for i in 1 .. 1000&lt;br /&gt;
  8      loop&lt;br /&gt;
  9          open l_rc for&lt;br /&gt;
 10          &amp;#039;select object_name&lt;br /&gt;
 11             from all_objects&lt;br /&gt;
 12            where object_id = :x&amp;#039;&lt;br /&gt;
 13          using i;&lt;br /&gt;
 14          fetch l_rc into l_dummy;&lt;br /&gt;
 15          close l_rc;&lt;br /&gt;
 16      end loop;&lt;br /&gt;
 17      dbms_output.put_line&lt;br /&gt;
 18      ( round( (dbms_utility.get_time-l_start)/100, 2 ) ||&lt;br /&gt;
 19        &amp;#039; seconds...&amp;#039; );&lt;br /&gt;
 20  end;&lt;br /&gt;
 21  /&lt;br /&gt;
1.27 seconds...&lt;br /&gt;
&lt;br /&gt;
PL/SQL procedure successfully completed.&lt;br /&gt;
&lt;br /&gt;
That is pretty dramatic.  The fact is that not only does this &lt;br /&gt;
execute much faster (we spent more time PARSING our queries then &lt;br /&gt;
actually EXECUTING them!) it will let more users use your system &lt;br /&gt;
simultaneously.&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
and from [http://asktom.oracle.com/pls/asktom/f?p=100:11:::::P11_QUESTION_ID:1163635055580 linked question]&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
Lbrary cache latch contention is typically caused by NOT using bind variables.  It is due &lt;br /&gt;
to excessive parsing of statements.&lt;br /&gt;
&lt;br /&gt;
One way to see if this might be the case in your situation is to run a script like:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
create table t1 as select sql_text from v$sqlarea;&lt;br /&gt;
&lt;br /&gt;
alter table t1 add sql_text_wo_constants varchar2(1000);&lt;br /&gt;
&lt;br /&gt;
create or replace function &lt;br /&gt;
remove_constants( p_query in varchar2 ) return varchar2&lt;br /&gt;
as&lt;br /&gt;
    l_query long;&lt;br /&gt;
    l_char  varchar2(1);&lt;br /&gt;
    l_in_quotes boolean default FALSE;&lt;br /&gt;
begin&lt;br /&gt;
    for i in 1 .. length( p_query )&lt;br /&gt;
    loop&lt;br /&gt;
        l_char := substr(p_query,i,1);&lt;br /&gt;
        if ( l_char = &amp;#039;&amp;#039;&amp;#039;&amp;#039; and l_in_quotes )&lt;br /&gt;
        then&lt;br /&gt;
            l_in_quotes := FALSE;&lt;br /&gt;
        elsif ( l_char = &amp;#039;&amp;#039;&amp;#039;&amp;#039; and NOT l_in_quotes )&lt;br /&gt;
        then&lt;br /&gt;
            l_in_quotes := TRUE;&lt;br /&gt;
            l_query := l_query || &amp;#039;&amp;#039;&amp;#039;#&amp;#039;;&lt;br /&gt;
        end if;&lt;br /&gt;
        if ( NOT l_in_quotes ) then&lt;br /&gt;
            l_query := l_query || l_char;&lt;br /&gt;
        end if;&lt;br /&gt;
    end loop;&lt;br /&gt;
    l_query := translate( l_query, &amp;#039;0123456789&amp;#039;, &amp;#039;@@@@@@@@@@&amp;#039; );&lt;br /&gt;
    for i in 0 .. 8 loop&lt;br /&gt;
        l_query := replace( l_query, lpad(&amp;#039;@&amp;#039;,10-i,&amp;#039;@&amp;#039;), &amp;#039;@&amp;#039; );&lt;br /&gt;
        l_query := replace( l_query, lpad(&amp;#039; &amp;#039;,10-i,&amp;#039; &amp;#039;), &amp;#039; &amp;#039; );&lt;br /&gt;
    end loop;&lt;br /&gt;
    return upper(l_query);&lt;br /&gt;
end;&lt;br /&gt;
/&lt;br /&gt;
update t1 set sql_text_wo_constants = remove_constants(sql_text);&lt;br /&gt;
&lt;br /&gt;
select sql_text_wo_constants, count(*)&lt;br /&gt;
  from t1&lt;br /&gt;
 group by sql_text_wo_constants&lt;br /&gt;
having count(*) &amp;gt; 100&lt;br /&gt;
 order by 2&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The output of that last query will show you statements that are identical in the shared &lt;br /&gt;
pool after all numbers and character string constants have been removed.  These &lt;br /&gt;
statements -- and more importantly their counts -- are the potential bottlenecks.  In &lt;br /&gt;
addition to causing the contention, they will be HUGE cpu consumers.  &lt;br /&gt;
&lt;br /&gt;
If you discover your applications do not use bind variables -- you must have this &lt;br /&gt;
corrected.  You&amp;#039;ll never have a good hit ratio if everyone submits &amp;quot;unique&amp;quot; sql.  Your &lt;br /&gt;
shared pool will never be used right and you&amp;#039;ll be using excessive CPU (90% of the time &lt;br /&gt;
it takes to process &amp;quot;insert into t values ( 1 )&amp;quot; is parsing.  If you use &amp;quot;insert into t &lt;br /&gt;
values ( :x )&amp;quot;, and bind the value of 1 -- then the next person that runs that insert &lt;br /&gt;
will benefit from your work and run that much faster. &lt;br /&gt;
...&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Advice from Oracle concerning a concrete (12c) example of unable to allocate 52824 bytes of shared memory (&amp;quot;shared pool&amp;quot;,...====&lt;br /&gt;
This was from a ticket raised for a Data Pump export that consistently failed with:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Processing object type SCHEMA_EXPORT/TABLE/PROCACT_INSTANCE&lt;br /&gt;
Processing object type SCHEMA_EXPORT/TABLE/TABLE&lt;br /&gt;
ORA-39014: One or more workers have prematurely exited.&lt;br /&gt;
ORA-39029: worker 1 with process name &amp;quot;DW00&amp;quot; prematurely terminated&lt;br /&gt;
ORA-31671: Worker process DW00 had an unhandled exception.&lt;br /&gt;
ORA-04031: unable to allocate 52824 bytes of shared memory (&amp;quot;shared pool&amp;quot;,&amp;quot;unknown object&amp;quot;,&amp;quot;KTSL subheap&amp;quot;,&amp;quot;ktsl_load_disp-2&amp;quot;)&lt;br /&gt;
ORA-06512: at &amp;quot;SYS.KUPW$WORKER&amp;quot;, line 2122&lt;br /&gt;
ORA-06512: at line 2&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
The error ORA-4031 on the shared pool can indicate one of two things:&lt;br /&gt;
- insufficient space for the shared pool (so insufficient memory in SGA at that time)&lt;br /&gt;
OR&lt;br /&gt;
- although there is enough memory, it is fragmented and no contiguous chunk can be allocated to satisfy the latest memory request.&lt;br /&gt;
&lt;br /&gt;
Each SGA has a little fragmentation of course because of the operations taking place, so in your case the fragmentation is represented by the 18M of free memory, which exists in uncontiguous chunks.&lt;br /&gt;
This means that the root cause of the error is insufficient contiguous memory to allocate 12312 bytes of shared memory.&lt;br /&gt;
&lt;br /&gt;
ACTION PLAN&lt;br /&gt;
==============&lt;br /&gt;
1. We see memory_target=2000M. This is too little to support a 12c database, even when it has little activity.&lt;br /&gt;
As you may know 1.7G for the SGA was acceptable when speaking of 32bit OSs where it was hardly possible to make use of more than that.&lt;br /&gt;
Since you have a 64 bit system, the addressable memory is virtually unlimited.&lt;br /&gt;
Furthermore, by using AMM (memory_target&amp;gt;0) this memory is divided between the SGA and the PGA (the user processes) which in fact, depending on the number of connections, can limit the SGA even more.&lt;br /&gt;
So the first recommendation is to increase the value of memory_target to 4G for example. There is no ideal value, but this would be a reasonable starting value for tuning.&lt;br /&gt;
&lt;br /&gt;
You can do further tuning of the memory using the view V$MEMORY_TARGET_ADVICE.&lt;br /&gt;
The view V$MEMORY_TARGET_ADVICE provides tuning advice for the MEMORY_TARGET initialization parameter:&lt;br /&gt;
SQL&amp;gt; SELECT * FROM v$memory_target_advice ORDER BY memory_size;&lt;br /&gt;
&lt;br /&gt;
The dynamic performance view V$MEMORY_DYNAMIC_COMPONENTS shows the current sizes of all dynamically tuned memory components, including the total sizes of the SGA and instance PGA.&lt;br /&gt;
&lt;br /&gt;
You can also use V$MEMORY_RESIZE_OPS which has a circular history buffer of the last 800 memory resize requests.&lt;br /&gt;
&lt;br /&gt;
2. Since the AMM (you have memory_target&amp;gt;0) is used, then make sure to set:&lt;br /&gt;
 _shared_pool_reserved_pct to 10 or 15 to ensure that when the Shared Pool grows or shrinks automatically, the Reserved Area will change as well.&lt;br /&gt;
&lt;br /&gt;
SQL&amp;gt; alter system set &amp;quot;_shared_pool_reserved_pct&amp;quot;=15 scope=spfile;&lt;br /&gt;
--restart the instance&lt;br /&gt;
&lt;br /&gt;
FYI: By default, Oracle configures a small Reserved Pool (or Reserved Area) inside the Shared Pool.&lt;br /&gt;
This memory can be used for operations such as PL/SQL and trigger compilation or for temporary space while loading Java objects.&lt;br /&gt;
After the memory allocated from the Reserved Pool is freed, it returns to the Reserved Pool.&lt;br /&gt;
5% of the Shared Pool is set aside as the Reserved Pool to handle allocations of memory higher than defined by the hidden parameter _shared_pool_reserved_pct.&lt;br /&gt;
In some application environments, 5% is too small.&lt;br /&gt;
&lt;br /&gt;
3. Set shared_pool_size=500M or even more. This will represent a minimum amount of memory that will always be available to the shared pool.&lt;br /&gt;
If more memory is needed at any moment, if it is available, it will be allocated to the shared pool over the 500M.&lt;br /&gt;
&lt;br /&gt;
Implement the above steps, monitor the database and let us know the result,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORA-00392: log 1 of thread 1 is being cleared, operation not allowed===&lt;br /&gt;
After performing an active duplication, this happened when trying to open the database.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SQL&amp;gt; alter database open resetlogs&lt;br /&gt;
alter database open resetlogs&lt;br /&gt;
*&lt;br /&gt;
ERROR at line 1:&lt;br /&gt;
ORA-00392: log 1 of thread 1 is being cleared, operation not allowed&lt;br /&gt;
ORA-00312: online log 1 thread 1: &amp;#039;/oracle/oradata/testdb/redo/redo01.log&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SQL&amp;gt; select group#,thread#,status from v$log;&lt;br /&gt;
 &lt;br /&gt;
GROUP#   THREAD#   STATUS&lt;br /&gt;
-------  --------- ----------------&lt;br /&gt;
1        1         CLEARING_CURRENT&lt;br /&gt;
2        1         STALE&lt;br /&gt;
3        1         STALE&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Check the alert log! Always a good idea to get extra info. In here we find the answer&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ORA-00344: unable to re-create online log&lt;br /&gt;
&amp;#039;/oracle/oradata/testdb/redo/redo01.log&amp;#039;&lt;br /&gt;
ORA-27040: file create error, unable to create file&lt;br /&gt;
Linux-x86_64 Error: 2: No such file or directory&lt;br /&gt;
Additional information: 1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
So the clue is that the file cannot be created at the operating system level.&amp;lt;br /&amp;gt;&lt;br /&gt;
Doing a &amp;lt;code&amp;gt;df -k /oracle/oradata/testdb/redo&amp;lt;/code&amp;gt; shows us that the filesystem was created too small for the destination database.&amp;lt;br /&amp;gt;&lt;br /&gt;
In this case, we do not want the redolog directory to be as big as on the source db as there will be almost no movement on the destination.&amp;lt;br /&amp;gt;&lt;br /&gt;
I should have specified the LOGFILE parameter in the DUPLICATE clause to setup new, smaller redolog files.&amp;lt;br /&amp;gt;&lt;br /&gt;
As this duplicate takes over 12 hours, I didn&amp;#039;t want to do it again so I created symbolic links in the redolog directory pointing out to a larger filesystem with more space.&amp;lt;br /&amp;gt;&lt;br /&gt;
This allowed the creation of the redolog files. They can then be resized once the database has been opened.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cd /oracle/oradata/testdb/redo&lt;br /&gt;
ln -s /tmp/redo01.log redo01.log&lt;br /&gt;
ln -s /tmp/redo02.log redo02.log&lt;br /&gt;
ln -s /tmp/redo03.log redo03.log&lt;br /&gt;
&lt;br /&gt;
SQL&amp;gt; alter database open resetlogs&lt;br /&gt;
Database opened.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===RMAN-04004: error from recovery catalog database: ORA-01017: invalid username/password; logon denied===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
oracle@host:/export/home/ora&amp;gt; rman target / catalog catowner/catpass@catdb&lt;br /&gt;
&lt;br /&gt;
Recovery Manager: Release 11.2.0.2.0 - Production on Thu Jun 12 16:51:03 2014&lt;br /&gt;
&lt;br /&gt;
Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.&lt;br /&gt;
&lt;br /&gt;
connected to target database: XXXXRAP1 (DBID=3557010742)&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-00554: initialization of internal recovery manager package failed&lt;br /&gt;
RMAN-04004: error from recovery catalog database: ORA-01017: invalid username/password; logon denied&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This is normally very straight-forward and self-explanatory.&amp;lt;br /&amp;gt;&lt;br /&gt;
The puzzle here is that a connection from SQL*Plus works!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sqlplus catowner/catpass@catdb&lt;br /&gt;
&lt;br /&gt;
SQL*Plus: Release 11.2.0.2.0 Production on Thu Jun 12 16:53:18 2014&lt;br /&gt;
&lt;br /&gt;
Copyright (c) 1982, 2010, Oracle.  All rights reserved.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Connected to:&lt;br /&gt;
Oracle Database 12c Enterprise Edition Release 12.1.0.1.0 - 64bit Production&lt;br /&gt;
With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options&lt;br /&gt;
SQL&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Eventually worked out that the rman binary in the databases ORACLE_HOME on the source machine needed relinking!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cd $ORACLE_HOME/rdbms/lib&lt;br /&gt;
make -f ins_rdbms.mk irman &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORA-00230: operation disallowed: snapshot control file enqueue unavailable===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
waiting for snapshot control file enqueue&lt;br /&gt;
waiting for snapshot control file enqueue&lt;br /&gt;
waiting for snapshot control file enqueue&lt;br /&gt;
waiting for snapshot control file enqueue&lt;br /&gt;
cannot make a snapshot control file&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-03008: error while performing automatic resync of recovery catalog&lt;br /&gt;
ORA-00230: operation disallowed: snapshot control file enqueue unavailable&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
From the doc...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
When RMAN needs to back up or resynchronize from the control file, it first creates a snapshot or consistent image of the control file.&lt;br /&gt;
If one RMAN job is already backing up the control file while another needs to create a new snapshot control file, then you may see the following message:&lt;br /&gt;
&lt;br /&gt;
waiting for snapshot controlfile enqueue&lt;br /&gt;
&lt;br /&gt;
Under normal circumstances, a job that must wait for the control file enqueue waits for a brief interval and then successfully obtains the enqueue.&lt;br /&gt;
RMAN makes up to five attempts to get the enqueue and then fails the job.&lt;br /&gt;
The conflict is usually caused when two jobs are both backing up the control file, and the job that first starts backing up the control file waits for service from the media manager.&lt;br /&gt;
&lt;br /&gt;
To determine which job is holding the conflicting enqueue:&lt;br /&gt;
&lt;br /&gt;
    After you see the first message stating &amp;quot;RMAN-08512: waiting for snapshot controlfile enqueue&amp;quot;, start a new SQL*Plus session on the target database:&lt;br /&gt;
&lt;br /&gt;
    % sqlplus &amp;#039;SYS/oracle@trgt AS SYSDBA&amp;#039;&lt;br /&gt;
&lt;br /&gt;
    Execute the following query to determine which job is causing the wait:&lt;br /&gt;
&lt;br /&gt;
    SELECT s.SID, USERNAME AS &amp;quot;User&amp;quot;, PROGRAM, MODULE, &lt;br /&gt;
           ACTION, LOGON_TIME &amp;quot;Logon&amp;quot;, l.* &lt;br /&gt;
    FROM V$SESSION s, V$ENQUEUE_LOCK l&lt;br /&gt;
    WHERE l.SID = s.SID&lt;br /&gt;
    AND l.TYPE = &amp;#039;CF&amp;#039;&lt;br /&gt;
    AND l.ID1 = 0&lt;br /&gt;
    AND l.ID2 = 2;&lt;br /&gt;
&lt;br /&gt;
    You should see output similar to the following (the output in this example has been truncated):&lt;br /&gt;
&lt;br /&gt;
    SID User Program              Module                    Action           Logon&lt;br /&gt;
    --- ---- -------------------- ------------------------- ---------------- ---------&lt;br /&gt;
      9 SYS  rman@h13 (TNS V1-V3) backup full datafile: c1  0000210 STARTED  21-JUN-01&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
After you have determined which job is creating the enqueue, you can do one of the following:&lt;br /&gt;
&lt;br /&gt;
    Wait until the job creating the enqueue completes&lt;br /&gt;
    Cancel the current job and restart it after the job creating the enqueue completes&lt;br /&gt;
    Cancel the job creating the enqueue&lt;br /&gt;
&lt;br /&gt;
Commonly, enqueue situations occur when a job is writing to a tape drive, but the tape drive is waiting for a new cassette to be inserted.&lt;br /&gt;
If you start a new job in this situation, then you will probably receive the enqueue message because the first job cannot complete until the new tape is loaded.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or more directly...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 2000&lt;br /&gt;
col killer     for a70&lt;br /&gt;
col program    for a20&lt;br /&gt;
col module     for a20&lt;br /&gt;
col action     for a20&lt;br /&gt;
col logon_time for a20&lt;br /&gt;
select &amp;#039;alter system disconnect session &amp;#039;&amp;#039;&amp;#039;||s.sid||&amp;#039;,&amp;#039;||s.serial#||&amp;#039;&amp;#039;&amp;#039; immediate;&amp;#039; killer&lt;br /&gt;
,      username&lt;br /&gt;
,      program&lt;br /&gt;
,      module&lt;br /&gt;
,      action&lt;br /&gt;
,      logon_time&lt;br /&gt;
from   v$session s&lt;br /&gt;
,      v$enqueue_lock l&lt;br /&gt;
where  l.sid  = s.sid&lt;br /&gt;
and    l.type = &amp;#039;cf&amp;#039;&lt;br /&gt;
and    l.id1  = 0&lt;br /&gt;
and    l.id2  = 2&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORA-19511: non RMAN, but media manager or vendor specific failure, error text:===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-03002: failure of Duplicate Db command at 05/01/2018 14:23:09&lt;br /&gt;
RMAN-05501: aborting duplication of target database&lt;br /&gt;
RMAN-03015: error occurred in stored script Memory Script&lt;br /&gt;
ORA-27191: sbtinfo2 returned error&lt;br /&gt;
Additional information: 3586&lt;br /&gt;
ORA-19511: non RMAN, but media manager or vendor specific failure, error text:&lt;br /&gt;
   Unable to connect to NetWorker server &amp;#039;hn6000.cln.be&amp;#039; because &amp;#039;Authentication error; why = Invalid client credential&amp;#039;. (2:10:79)&lt;br /&gt;
&lt;br /&gt;
Recovery Manager complete.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
If this happens, check to see if the nsr daemon is running...&amp;lt;br /&amp;gt;&lt;br /&gt;
Good system:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/home/oracle&amp;gt; ps -ef | grep nsr&lt;br /&gt;
    root  5701836        1   0   Mar 16      - 13:18 /bin/nsrexecd&lt;br /&gt;
  oracle 18809292 22741502   0 15:03:58  pts/0  0:00 grep nsr&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Bad system:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 /home/oracle&amp;gt; ps -ef | grep nsr&lt;br /&gt;
  oracle 14745986 15139292   0 15:03:29  pts/2  0:00 grep nsr&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORA-19554: error allocating device, device type: SBT_TAPE, device name:===&lt;br /&gt;
If using Cygwin...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-03002: failure of backup command at 05/19/2015 12:25:47&lt;br /&gt;
ORA-19554: error allocating device, device type: SBT_TAPE, device name:&lt;br /&gt;
ORA-27000: skgfqsbi: failed to initialize storage subsystem (SBT) layer&lt;br /&gt;
OSD-02534: Message 2534 not found;  product=RDBMS; facility=SOSD&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Check the tdpo.opt file is where you think it is!&lt;br /&gt;
* Check the path to the opt file looks like this (needs to be Windows format):&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
CONFIGURE CHANNEL DEVICE TYPE &amp;#039;SBT_TAPE&amp;#039; FORMAT   &amp;#039;LOG_%d_t%t_s%s_u%U&amp;#039; PARMS  &amp;#039;ENV=(TDPO_OPTFILE=E:\oracle\KITRYD\admin\tdpo.opt)&amp;#039;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Check the content of the opt file is Windows format paths!&lt;br /&gt;
&lt;br /&gt;
===RMAN-20033: control file SEQUENCE# too low===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-03008: error while performing automatic resync of recovery catalog&lt;br /&gt;
===RMAN-20033: control file SEQUENCE# too low===&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
From [https://forums.oracle.com/forums/thread.jspa?threadID=1115969 forums.oracle.com]&amp;lt;br /&amp;gt;&lt;br /&gt;
This error generally happens if an archivelog backup happens while the RMAN database backup is running and if controlfile autobackup is configured.&amp;lt;br /&amp;gt;&lt;br /&gt;
The database backup is usually successful and it is just the controlfile backup that fails.&lt;br /&gt;
===ORA-27302: failure occurred at: slgpn===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
RMAN-03009: failure of Control File and SPFILE Autobackup command on c1 channel at 06/28/2011 18:59:38&lt;br /&gt;
ORA-19715: invalid format %b for generated name&lt;br /&gt;
ORA-27302: failure occurred at: slgpn&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Problem====&lt;br /&gt;
When doing a &amp;quot;&amp;lt;tt&amp;gt;backup as copy database&amp;lt;/tt&amp;gt;&amp;quot;, got these errors after 145 of 147 datafiles had been backed up!&lt;br /&gt;
&lt;br /&gt;
====Investigation====&lt;br /&gt;
I had read [https://oracleedge.wordpress.com/2011/06/29/oracle-rman-03009-ora-19715-ora-27302/ elsewhere] that this could be something to do with the format of the autobackup of the control file so I changed the format as suggested and reran the backup.&amp;lt;br /&amp;gt;&lt;br /&gt;
No luck. It ended exactly the same way after 145 files. I decided to compare the original list of datafiles with those that had been backed up in order to track down the 2 failures. Maybe I could see something odd with them.&amp;lt;br /&amp;gt;&lt;br /&gt;
Sure enough, these 2 files were different... there was a space at the &amp;#039;&amp;#039;&amp;#039;end&amp;#039;&amp;#039;&amp;#039; of the filenames :-)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select &amp;#039;x&amp;#039;||file_name||&amp;#039;x&amp;#039;&lt;br /&gt;
from   dba_data_files&lt;br /&gt;
where  file_name like &amp;#039;% %&amp;#039;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Solution====&lt;br /&gt;
Run the backup of the other 2 datafiles with a different format that did not rely on the filename.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
run {&lt;br /&gt;
    allocate channel c1 device type disk format &amp;#039;/path/to/datafiles/%U&amp;#039;;&lt;br /&gt;
    backup as copy datafile 170;&lt;br /&gt;
    backup as copy datafile 171;&lt;br /&gt;
    backup as copy current controlfile;&lt;br /&gt;
    release channel c1;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The other 145 datafiles were backed up with a format of &amp;#039;/path/to/datafiles/%b&amp;#039; which preserves the filenames so all that needs to be done is rename the other 2 after the backup finishes.&amp;lt;br /&amp;gt;&lt;br /&gt;
If they are going to be used in a restore scenario, they should be renamed in the controlfile also.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter database rename file &amp;#039;/path/to/datafiles/filename_with_a_space_at_end &amp;#039; to &amp;#039;/path/to/datafiles/filename_without_a_space&amp;#039;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===RMAN errors after crosscheck backup and delete noprompt obsolete and delete noprompt expired backup===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
RMAN-06207: WARNING: 3921 objects could not be deleted for SBT_TAPE channel(s) due&lt;br /&gt;
RMAN-06208:          to mismatched status.  Use CROSSCHECK command to fix status&lt;br /&gt;
RMAN-06210: List of Mismatched objects&lt;br /&gt;
RMAN-06211: ==========================&lt;br /&gt;
RMAN-06212:   Object Type   Filename/Handle&lt;br /&gt;
RMAN-06213: --------------- ---------------------------------------------------&lt;br /&gt;
RMAN-06214: Backup Piece    DB_SID_t20140316_s263889_umhp3bpa7_1_1&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Use the FORCE option with the DELETE command&amp;lt;br /&amp;gt;&lt;br /&gt;
The FORCE command tells RMAN to clean the information out of the catalog regardless of whether it can find it on the media or not.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
delete force noprompt expired backup;&lt;br /&gt;
delete force noprompt obsolete;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===RMAN-06004: ORACLE error from recovery catalog database: RMAN-20003: target database incarnation not found in recovery catalog===&lt;br /&gt;
====Problem:====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-03002: failure of Duplicate Db command at 12/05/2017 11:11:15&lt;br /&gt;
RMAN-05501: aborting duplication of target database&lt;br /&gt;
RMAN-03015: error occurred in stored script Memory Script&lt;br /&gt;
RMAN-06004: ORACLE error from recovery catalog database: RMAN-20003: target database incarnation not found in recovery catalog&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Solution:====&lt;br /&gt;
Strangely, this means, in my particular case, that block change tracking is turned on in the target databse and needs turning off in the auxiliary while the DUPLICATE is running.&amp;lt;br /&amp;gt;&lt;br /&gt;
It must be done while the auxiliary is in mount mode and restoring the datafiles (before recovery starts)&amp;lt;br /&amp;gt;&lt;br /&gt;
It is reported to be a bug fixed in 11.1 but somehow, we&amp;#039;re still (sometimes) getting it in 12.1.0.2.&lt;br /&gt;
&lt;br /&gt;
===RMAN-06059: expected archived log not found, loss of archived log compromises recoverability===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
RMAN-06059: expected archived log not found, loss of archived log compromises recoverability&lt;br /&gt;
ORA-19625: error identifying file &amp;lt;filename&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This error can come from the fact that the database files (more likely archivelogs) are being deleted by the operating system so RMAN has no clue of their whereabouts.&amp;lt;br /&amp;gt;&lt;br /&gt;
Possibly result of a database duplication and the catalog has not updated properly?&amp;lt;br /&amp;gt;&lt;br /&gt;
====Solution====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
crosscheck archivelog all;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
And then maybe take a backup to be on the safe side.&lt;br /&gt;
&lt;br /&gt;
===RMAN-05537: DUPLICATE without TARGET connection when auxiliary instance is started with spfile cannot use SPFILE clause===&lt;br /&gt;
====Problem:====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-03002: failure of Duplicate Db command at 12/05/2017 14:17:49&lt;br /&gt;
RMAN-05501: aborting duplication of target database&lt;br /&gt;
RMAN-05537: DUPLICATE without TARGET connection when auxiliary instance is started with spfile cannot use SPFILE clause&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Usually happens after restarting a failed RMAN DUPLICATE database. The spfile has been regenerated on the auxiliary to a level where it has too much detail in it.&lt;br /&gt;
====Solution:====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ cd $ORACLE_HOME/dbs&lt;br /&gt;
$ ls -altr *dwh_perf*&lt;br /&gt;
-rw-r-----    1 oracle   oinstall   17645568 Aug  3 13:34 snapcf_dwh_perf.f&lt;br /&gt;
-rw-r-----    1 oracle   oinstall       7680 Nov  4 09:22 orapwdwh_perf&lt;br /&gt;
-rw-r--r--    1 oracle   oinstall        104 Dec  5 09:34 initdwh_perf.ora&lt;br /&gt;
-rw-r-----    1 oracle   oinstall       6656 Dec  5 11:11 spfiledwh_perf.ora&lt;br /&gt;
-rw-rw----    1 oracle   oinstall       1544 Dec  5 14:18 hc_dwh_perf.dat&lt;br /&gt;
$ mv hc_dwh_perf.dat hc_dwh_perf.dat.old&lt;br /&gt;
$ mv spfiledwh_perf.ora spfiledwh_perf.ora.old&lt;br /&gt;
$ cat initdwh_perf.ora&lt;br /&gt;
sga_max_size=&amp;#039;6G&amp;#039;&lt;br /&gt;
sga_target=&amp;#039;6G&amp;#039;&lt;br /&gt;
compatible=&amp;#039;12.0.0&amp;#039;&lt;br /&gt;
db_files=&amp;#039;500&amp;#039;&lt;br /&gt;
&lt;br /&gt;
# Instance name&lt;br /&gt;
db_name=dwh_perf&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Re-run the DUPLICATE. It should zoom past the already recovered datafiles.&lt;br /&gt;
&lt;br /&gt;
===PSDRPC returns significant error 1013===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
archived log thread=1 sequence=195008&lt;br /&gt;
channel t2: reading from backup piece arclog_LBK_4260753020_946042770_479194_1&lt;br /&gt;
channel t0: piece handle=arclog_LBK_4260753020_946042770_479192_1 tag=TAG20170607T133757&lt;br /&gt;
channel t0: restored backup piece 1&lt;br /&gt;
channel t0: restore complete, elapsed time: 00:00:35&lt;br /&gt;
archived log file name=/xxxxxx/acc/ora_bin2/app/oracle/product/11.2.0.4/dbhome_1/dbs/arch1_195006_815790039.dbf thread=1 sequence=195006&lt;br /&gt;
PSDRPC returns significant error 1013.&lt;br /&gt;
PSDRPC returns significant error 1013.&lt;br /&gt;
released channel: t0&lt;br /&gt;
released channel: t1&lt;br /&gt;
released channel: t2&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-03002: failure of Duplicate Db command at 06/09/2017 15:15:04&lt;br /&gt;
RMAN-05501: aborting duplication of target database&lt;br /&gt;
RMAN-03015: error occurred in stored script Memory Script&lt;br /&gt;
RMAN-11003: failure during parse/execution of SQL statement: alter database recover logfile &amp;#039;/xxxxxx/acc/ora_bin2/app/oracle/product/11.2.0.4/dbhome_1/dbs/arch1_195006_815790039.dbf&amp;#039;&lt;br /&gt;
ORA-10877: error signaled in parallel recovery slave&lt;br /&gt;
&lt;br /&gt;
Recovery Manager complete.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Action====&lt;br /&gt;
Check the alert log on the auxiliary instance.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ORA-279 signalled during: alter database recover logfile &amp;#039;/xxxxxx/acc/ora_bin2/app/oracle/product/11.2.0.4/dbhome_1/dbs/arch1_195005_815790039.dbf&amp;#039;...&lt;br /&gt;
alter database recover logfile &amp;#039;/xxxxxx/acc/ora_bin2/app/oracle/product/11.2.0.4/dbhome_1/dbs/arch1_195006_815790039.dbf&amp;#039;&lt;br /&gt;
Media Recovery Log /xxxxxx/acc/ora_bin2/app/oracle/product/11.2.0.4/dbhome_1/dbs/arch1_195006_815790039.dbf&lt;br /&gt;
Fri Jun 09 07:30:30 2017&lt;br /&gt;
Errors with log /xxxxxx/acc/ora_bin2/app/oracle/product/11.2.0.4/dbhome_1/dbs/arch1_195006_815790039.dbf&lt;br /&gt;
Recovery interrupted!&lt;br /&gt;
Recovered data files to a consistent state at change 238029030495&lt;br /&gt;
Media Recovery failed with error 19755&lt;br /&gt;
Errors in file /xxxxxx/acc/ora_bin2/app/oracle/diag/rdbms/lbkro/lbkro/trace/lbkro_pr00_13108374.trc:&lt;br /&gt;
ORA-00283: recovery session canceled due to errors&lt;br /&gt;
===&amp;gt;ORA-19755: could not open change tracking file&lt;br /&gt;
===&amp;gt;ORA-19750: change tracking file: &amp;#039;/xxxxxx/exp/ora_data2/lbk/data/bct_lbk_do_not_delete.f&lt;br /&gt;
===&amp;gt;ORA-27037: unable to obtain file status&lt;br /&gt;
===&amp;gt;IBM AIX RISC System/6000 Error: 2: No such file or directory&lt;br /&gt;
Additional information: 3&lt;br /&gt;
Fri Jun 09 07:30:36 2017&lt;br /&gt;
ORA-10877 signalled during: alter database recover logfile &amp;#039;/xxxxxx/acc/ora_bin2/app/oracle/product/11.2.0.4/dbhome_1/dbs/arch1_195006_815790039.dbf&amp;#039;...&lt;br /&gt;
Fri Jun 09 14:04:57 2017&lt;br /&gt;
alter database recover logfile &amp;#039;/xxxxxx/acc/ora_bin2/app/oracle/product/11.2.0.4/dbhome_1/dbs/arch1_195006_815790039.dbf&amp;#039;&lt;br /&gt;
Media Recovery Log /xxxxxx/acc/ora_bin2/app/oracle/product/11.2.0.4/dbhome_1/dbs/arch1_195006_815790039.dbf&lt;br /&gt;
Media Recovery failed with error 1112&lt;br /&gt;
ORA-283 signalled during: alter database recover logfile &amp;#039;/xxxxxx/acc/ora_bin2/app/oracle/product/11.2.0.4/dbhome_1/dbs/arch1_195006_815790039.dbf&amp;#039;...&lt;br /&gt;
Fri Jun 09 14:31:20 2017&lt;br /&gt;
Shutting down instance (immediate)&lt;br /&gt;
Shutting down instance: further logons disabled&lt;br /&gt;
Stopping background process MMNL&lt;br /&gt;
Stopping background process MMON&lt;br /&gt;
License high water mark = 49&lt;br /&gt;
ALTER DATABASE CLOSE NORMAL&lt;br /&gt;
ORA-1109 signalled during: ALTER DATABASE CLOSE NORMAL...&lt;br /&gt;
ALTER DATABASE DISMOUNT&lt;br /&gt;
Shutting down archive processes&lt;br /&gt;
Archiving is disabled&lt;br /&gt;
Completed: ALTER DATABASE DISMOUNT&lt;br /&gt;
ARCH: Archival disabled due to shutdown: 1089&lt;br /&gt;
Shutting down archive processes&lt;br /&gt;
Archiving is disabled&lt;br /&gt;
ARCH: Archival disabled due to shutdown: 1089&lt;br /&gt;
Shutting down archive processes&lt;br /&gt;
Archiving is disabled&lt;br /&gt;
Fri Jun 09 14:31:24 2017&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This is a known bug. it is fixed in 11.2.0.3 but... this customer does not apply patches!&lt;br /&gt;
&lt;br /&gt;
====Solution====&lt;br /&gt;
While the DUPLICATE is running (and in MOUNT mode), log on to the auxiliary instance and disable block change tracking.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter database disable block change tracking;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
A documented workaround is to set db_filename_convert parameter in the DUPLICATE clause of the run block but I tried this and it failed again.&amp;lt;br /&amp;gt;&lt;br /&gt;
The obvious solution is to patch the database but...&lt;br /&gt;
&lt;br /&gt;
===Database trigger to capture ORA errors===&lt;br /&gt;
From [http://ora-ssn.blogspot.be/2011/10/trigger-on-database-to-capture-ora.html ora-ssn.blogspot.be]&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
CREATE TABLE stats$error_log (&lt;br /&gt;
        err_dt          TIMESTAMP,&lt;br /&gt;
        db_user         VARCHAR2(30),&lt;br /&gt;
        msg_stack       VARCHAR2(2000),&lt;br /&gt;
        sqltxt          VARCHAR2(1000))&lt;br /&gt;
tablespace users;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Now, create a trigger on the database server.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
CREATE OR REPLACE TRIGGER log_server_errors&lt;br /&gt;
  AFTER SERVERERROR&lt;br /&gt;
  ON DATABASE&lt;br /&gt;
DECLARE&lt;br /&gt;
          v_sqltext VARCHAR2(1000);&lt;br /&gt;
          nl_sqltext ora_name_list_t;&lt;br /&gt;
  BEGIN&lt;br /&gt;
          -- Capture entire error text&lt;br /&gt;
          FOR i IN 1 .. ora_sql_txt(nl_sqltext) LOOP&lt;br /&gt;
            v_sqltext := v_sqltext || nl_sqltext(i);&lt;br /&gt;
          END LOOP;&lt;br /&gt;
          INSERT INTO STATS$ERROR_LOG&lt;br /&gt;
          (err_dt, db_user, msg_stack, sqltxt)&lt;br /&gt;
          VALUES&lt;br /&gt;
          (systimestamp,&lt;br /&gt;
           sys.login_user,&lt;br /&gt;
           dbms_utility.format_error_stack, v_sqltext);&lt;br /&gt;
  END log_server_errors;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORA-19809: limit exceeded for recovery files===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-03009: failure of backup command on ORA_DISK_1 channel at 07/15/2013 10:10:59&lt;br /&gt;
ORA-19809: limit exceeded for recovery files&lt;br /&gt;
ORA-19804: cannot reclaim 274716160 bytes disk space from 1468006400 limit&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    ORA-19809: limit exceeded for recovery files&lt;br /&gt;
    Cause: The limit for recovery files specified by the db_recovery_file_dest_size was exceeded.&lt;br /&gt;
&lt;br /&gt;
    Action: The error is accompanied by 19804. See message 19804 for further details&lt;br /&gt;
&lt;br /&gt;
    ORA-19804: cannot reclaim string bytes disk space from string limit&lt;br /&gt;
    Cause: Oracle cannot reclaim disk space of specified bytes from the DB_RECOVERY_FILE_DEST_SIZE limit.&lt;br /&gt;
&lt;br /&gt;
    Action: There are five possible solutions:&lt;br /&gt;
       1) Take frequent backup of recovery area using RMAN.&lt;br /&gt;
       2) Consider changing RMAN retention policy.&lt;br /&gt;
       3) Consider changing RMAN archivelog deletion policy.&lt;br /&gt;
       4) Add disk space and increase DB_RECOVERY_FILE_DEST_SIZE.&lt;br /&gt;
       5) Delete files from recovery area using RMAN.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The solution here is to increase the value of db_recovery_file_dest_size but it might also indicate a problem with tapes if the archivelogs are being backed up to tape via tdpo.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SYS@DN7&amp;gt; alter system set db_recovery_file_dest_size=4000M scope=both;&lt;br /&gt;
&lt;br /&gt;
System altered.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Looking into int further, saw RMAN parameters missing...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
CONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF 14 DAYS;&lt;br /&gt;
CONFIGURE BACKUP OPTIMIZATION OFF;&lt;br /&gt;
CONFIGURE DEFAULT DEVICE TYPE TO &amp;#039;SBT_TAPE&amp;#039;;&lt;br /&gt;
CONFIGURE CONTROLFILE AUTOBACKUP ON;&lt;br /&gt;
CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE &amp;#039;SBT_TAPE&amp;#039; TO &amp;#039;LOG_%d_controlfile_%F.rman&amp;#039;;&lt;br /&gt;
CONFIGURE DEVICE TYPE &amp;#039;SBT_TAPE&amp;#039; PARALLELISM 1 BACKUP TYPE TO BACKUPSET;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===RMAN-00554: initialization of internal recovery manager package failed===&lt;br /&gt;
Getting this error after migrating a database from one machine to another and attaching to a nice new version 12c catalog on the new server&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Recovery Manager: Release 11.2.0.2.0 - Production on Sat Jun 21 13:16:24 2014&lt;br /&gt;
&lt;br /&gt;
Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.&lt;br /&gt;
&lt;br /&gt;
connected to target database: SPMSUPP1 (DBID=3026014394)&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-00554: initialization of internal recovery manager package failed&lt;br /&gt;
RMAN-04004: error from recovery catalog database: ORA-01017: invalid username/password; logon denied&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
We cannot connect to the catalog via rman but there is no problem if connecting via SQL*Plus!&amp;lt;br /&amp;gt;&lt;br /&gt;
Solution: relink the rman executable.&lt;br /&gt;
===Using AIX commands genld, genkld and slibclean to avoid library file locking errors (libjox) (Doc ID 739963.1)===&lt;br /&gt;
* [https://support.oracle.com/epmos/faces/DocumentDisplay?_afrLoop=206851390914720&amp;amp;id=739963.1&amp;amp;_afrWindowMode=0&amp;amp;_adf.ctrl-state=e0pq23tou_4 Metalink]&lt;br /&gt;
When installing interim (one-off) patches, CPU patches or patchsets, you may encounter some errors with regards to files being locked or oui/opatch being unable to copy files&amp;lt;br /&amp;gt;&lt;br /&gt;
even though the databases, listeners and all other Oracle processes associated with the ORACLE_HOME to be patched were stopped.&amp;lt;br /&amp;gt;&lt;br /&gt;
This could be as result of a process which requires termination or an additional file needing to be unloaded from the system cache.&amp;lt;br /&amp;gt;&lt;br /&gt;
Run following commands to clean up...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
genld -l | grep &amp;lt;ORACLE_HOME&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
If genld returns data then a currently executing process has something open in the ORACLE_HOME directory, therefore terminate the process as required/recommended.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
genkld | grep &amp;lt;ORACLE_HOME&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
If the genkld command  returns a  list of shared objects currently loaded onto the OS system cache then please remove the entries from the OS system cache by running the slibclean command as root user:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/usr/sbin/slibclean&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===ORA-20011: Approximate NDV failed: ORA-29913: error in executing ODCIEXTTABLEOPEN callout===&lt;br /&gt;
This seems to be related to orphaned Datapump tables. Generally seems to be a problem when stats jobs are running during the night (dbms_stats)&amp;lt;br /&amp;gt;&lt;br /&gt;
* Check no datapump jobs are running&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select * from dba_datapump_jobs;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Find orphaned tables&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 2000&lt;br /&gt;
select owner&lt;br /&gt;
,      object_name&lt;br /&gt;
,      object_type&lt;br /&gt;
,      status&lt;br /&gt;
,      to_char(created,&amp;#039;dd-mon-yyyy hh24:mi:ss&amp;#039;) created&lt;br /&gt;
,      to_char(last_ddl_time,&amp;#039;dd-mon-yyyy hh24:mi:ss&amp;#039;) last_ddl_time&lt;br /&gt;
from   dba_objects&lt;br /&gt;
where  1=1&lt;br /&gt;
and    object_name like &amp;#039;ET$%&amp;#039;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Check that  any rows seen are actually external tables&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select owner&lt;br /&gt;
,      table_name&lt;br /&gt;
,      default_directory_name&lt;br /&gt;
,      access_type&lt;br /&gt;
from   dba_external_tables&lt;br /&gt;
order  by 1,2&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Drop the tables if they are not currently being used (no datapump jobs running)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
drop table &amp;amp;&amp;amp;owner..&amp;amp;table_name;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===ORA-01547: warning: RECOVER succeeded but OPEN RESETLOGS would get error below===&lt;br /&gt;
Database is restored and now we want to recover it but we see this...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Starting recover at 24-JUL-15 11:26:19&lt;br /&gt;
&lt;br /&gt;
starting media recovery&lt;br /&gt;
&lt;br /&gt;
unable to find archive log&lt;br /&gt;
archive log thread=1 sequence=69763&lt;br /&gt;
Oracle Error: &lt;br /&gt;
ORA-01547: warning: RECOVER succeeded but OPEN RESETLOGS would get error below&lt;br /&gt;
ORA-01194: file 1 needs more recovery to be consistent&lt;br /&gt;
ORA-01110: data file 1: &amp;#039;/oracle/TRSCRP1/oradata2/system01.dbf&amp;#039;&lt;br /&gt;
&lt;br /&gt;
released channel: c1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This means that although we have restored the database, we are still missing information to complete the recovery. This information is contained in the archived redo logs which must also be restored (from tape if they are no longer on disk)&amp;lt;br /&amp;gt;&lt;br /&gt;
We can see here that we need an archive log with sequence number 69763. But what is the file called and where should it be restored to?&amp;lt;br /&amp;gt;&lt;br /&gt;
For this we can go to SQL*Plus and get the database to tell us&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
recover database using backup controlfile until cancel;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
and cancel straight away.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ORA-00279: change 13796376414661 generated at 07/14/2015 13:20:07 needed for&lt;br /&gt;
thread 1&lt;br /&gt;
ORA-00289: suggestion : /oracle/TRSCRP1/archive/arch_TRSCRP1_1_69763.arc&lt;br /&gt;
ORA-00280: change 13796376414661 for thread 1 is in sequence #69763&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Specify log: {&amp;lt;RET&amp;gt;=suggested | filename | AUTO | CANCEL}&lt;br /&gt;
cancel&lt;br /&gt;
ORA-01547: warning: RECOVER succeeded but OPEN RESETLOGS would get error below&lt;br /&gt;
ORA-01194: file 1 needs more recovery to be consistent&lt;br /&gt;
ORA-01110: data file 1: &amp;#039;/oracle/TRSCRP1/oradata2/system01.dbf&amp;#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
ORA-01112: media recovery not started&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Now we see that we need to find a file called arch_TRSCRP1_1_69763.arc and put it in the directory /oracle/TRSCRP1/archive.&amp;lt;br /&amp;gt;&lt;br /&gt;
This will continue up until the time specified for the recover so restore a whole bunch of them.&amp;lt;br /&amp;gt;&lt;br /&gt;
Repeat the &amp;quot;recover database using backup controlfile until cancel;&amp;quot; command and type AUTO or Enter until you&amp;#039;ve got to where you need to be.&amp;lt;br /&amp;gt;&lt;br /&gt;
Type CANCEL when point is reached and&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter database open resetlogs;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Stuart</name></author>	</entry>

	<entry>
		<id>https://mailnest.com/dbawiki/index.php?title=Oracle_errors&amp;diff=3357</id>
		<title>Oracle errors</title>
		<link rel="alternate" type="text/html" href="https://mailnest.com/dbawiki/index.php?title=Oracle_errors&amp;diff=3357"/>
				<updated>2018-11-03T13:59:16Z</updated>
		
		<summary type="html">&lt;p&gt;Stuart: /* Solution */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;===ORA-00600===&lt;br /&gt;
[https://support.oracle.com/epmos/faces/DocContentDisplay?_afrLoop=397490397952859&amp;amp;id=1092832.1&amp;amp;_afrWindowMode=0&amp;amp;_adf.ctrl-state=184vwc6g3y_4 Master Note for Diagnosing ORA-600 (Doc ID 1092832.1)]&lt;br /&gt;
===ORA-19051: Cannot use fast path insert for this XMLType table===&lt;br /&gt;
Think LD_LIBRARY_PATH on Linux or LIBPATH on AIX.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Export: Release 11.2.0.4.0 - Production on Thu Jun 1 06:41:55 2017&lt;br /&gt;
&lt;br /&gt;
Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.&lt;br /&gt;
&lt;br /&gt;
Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production&lt;br /&gt;
With the Partitioning, OLAP, Data Mining and Real Application Testing options&lt;br /&gt;
Starting &amp;quot;DWH_EXPORT&amp;quot;.&amp;quot;SYS_EXPORT_TABLE_03&amp;quot;:  dwh_export/******** parfile=cadis_foto_export_credit_dba.par&lt;br /&gt;
Estimate in progress using BLOCKS method...&lt;br /&gt;
Processing object type TABLE_EXPORT/TABLE/TABLE_DATA&lt;br /&gt;
Total estimation using BLOCKS method: 64.08 GB&lt;br /&gt;
ORA-39126: Worker unexpected fatal error in KUPW$WORKER.FETCH_XML_OBJECTS []&lt;br /&gt;
ORA-19051: Cannot use fast path insert for this XMLType table&lt;br /&gt;
&lt;br /&gt;
ORA-06512: at &amp;quot;SYS.DBMS_SYS_ERROR&amp;quot;, line 86&lt;br /&gt;
ORA-06512: at &amp;quot;SYS.KUPW$WORKER&amp;quot;, line 9710&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Problem====&lt;br /&gt;
When the 11g DB was started, LD_LIBRARY_PATH and LIBPATH were still pointing to paths in the 10g Home.&lt;br /&gt;
====Solution====&lt;br /&gt;
There may have been some odd values setup in LD_LIBRARY_PATH before the call to oraenv (if oraenv was indeed called!)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
unset LD_LIBRARY_PATH LIBPATH&lt;br /&gt;
export ORACLE_SID=&amp;lt;correct 11g SID&amp;gt;&lt;br /&gt;
. oraenv&lt;br /&gt;
echo $LD_LIBRARY_PATH&lt;br /&gt;
echo $LIBPATH&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
They should now be correct.&lt;br /&gt;
&lt;br /&gt;
===ORA-27092: size of file exceeds file size limit of the process===&lt;br /&gt;
Think ulimit...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Cause: an attempt was made to open a file that exceeds the process&amp;#039;s file size limit (ulimit), additional information shows the current limit (logical blocks) and the size of the file (logical blocks)&lt;br /&gt;
Action: increase the processes file size limit (ulimit) and retry&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
truncate table pibadm.test_ph&lt;br /&gt;
                      *&lt;br /&gt;
Error at line 1 :&lt;br /&gt;
ORA-00604: error ocurred at recursive SQL level 1&lt;br /&gt;
ORA-01116: error in opening database file 2&lt;br /&gt;
ORA-01110: datafile 2 : &amp;#039;/opt/u01/data/PIBQA/UNDO_01.dbf&amp;#039;&lt;br /&gt;
ORA-27092: size of file exceeds file size limit of the process&lt;br /&gt;
Additional information: 262143&lt;br /&gt;
Additional information: 2621441&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Check the fs_size limit for this user in /etc/security/limits&amp;lt;br /&amp;gt;&lt;br /&gt;
Compare this with another user, say oracle. Probably -1 (unlimited)&lt;br /&gt;
&lt;br /&gt;
===SP2-1503: Unable to initialize Oracle call interface===&lt;br /&gt;
When trying to login to the database via SQL*Plus, these messages a displayed&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
hn5118 /home/oracle $sqlplus / as sysdba&lt;br /&gt;
SP2-1503: Unable to initialize Oracle call interface&lt;br /&gt;
SP2-0152: ORACLE may not be functioning properly&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Seems to be a problem unique to AIX (in this case).&amp;lt;br /&amp;gt;&lt;br /&gt;
Check to see what the LIBPATH variable is. It may still contain a path to an old ORACLE_HOME...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
hn5118 /home/oracle $env|grep LIBPATH&lt;br /&gt;
LIBPATH=/oracle/exp/ora_bin1/app/oracle/product/10.2.0/db_1/lib:/oracle/exp/ora_bin1/app/oracle/product/10.2.0/db_1/lib&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Disco! Unset it and rerun.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
hn5118 /home/oracle $unset LIBPATH&lt;br /&gt;
&lt;br /&gt;
hn5118 /home/oracle $sqlplus / as sysdba&lt;br /&gt;
&lt;br /&gt;
SQL*Plus: Release 12.1.0.2.0 Production on Wed Jul 12 17:17:54 2017&lt;br /&gt;
&lt;br /&gt;
Copyright (c) 1982, 2014, Oracle.  All rights reserved.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Connected to:&lt;br /&gt;
Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production&lt;br /&gt;
With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options&lt;br /&gt;
&lt;br /&gt;
SQL&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===UDE-31623: operation generated ORACLE error 31623===&lt;br /&gt;
When using Data pump, get following errors almost immediately:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
UDE-31623: operation generated ORACLE error 31623&lt;br /&gt;
ORA-31623: a job is not attached to this session via the specified handle&lt;br /&gt;
ORA-06512: at &amp;quot;SYS.DBMS_DATAPUMP&amp;quot;, line 3326&lt;br /&gt;
ORA-06512: at &amp;quot;SYS.DBMS_DATAPUMP&amp;quot;, line 4551&lt;br /&gt;
ORA-06512: at line 1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Solution 1:&amp;#039;&amp;#039;&amp;#039;&amp;lt;br /&amp;gt;&lt;br /&gt;
In one case, I simplified the parameter file that was used. Maybe related to Streams Pool size, who knows?!&amp;lt;br /&amp;gt;&lt;br /&gt;
I removed these 2 lines and the export started working:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
compression_algorithm=medium&lt;br /&gt;
logtime=all&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Solution 2:&amp;#039;&amp;#039;&amp;#039;&amp;lt;br /&amp;gt;&lt;br /&gt;
There is a note about this on Metalink, 1080775.1 which suggests that Streams Pool Size needs setting.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
For this DataPump error, you will need to configure the database with some Streams Pool.&lt;br /&gt;
&lt;br /&gt;
Perform the following query to find out how much STREAMS_POOL_SIZE has been allocated&lt;br /&gt;
&lt;br /&gt;
 select * from v$sgainfo;&lt;br /&gt;
 ...&lt;br /&gt;
 Streams Pool Size                               0 Yes&lt;br /&gt;
&lt;br /&gt;
Data Pump now uses Advanced Queuing (AQ) internally, so it can handle job stops/starts/re-starts.  However, AQ using the Streams Pool, where the database currently has the STREAMS_POOL_SIZE set to ZERO.&lt;br /&gt;
&lt;br /&gt;
Manually set the STREAMS_POOL_SIZE (using ALTER SYSTEM or by changing the value in the the PFILE/SPFILE), re-start the database and re-attempt the Data Pump Export.&lt;br /&gt;
&lt;br /&gt;
Alternately, turn on Automatic Shared Memory management (ASMM) by setting SGA_TARGET or MEMORY_TARGET.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
From Oracle Documentation&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Setting the Size Of the Buffer Cache In a Streams Environment&lt;br /&gt;
&lt;br /&gt;
Oracle Data Pump uses Streams functionality to communicate between processes.&lt;br /&gt;
If the SGA_TARGET initialization parameter is set, then the STREAMS_POOL_SIZE initialization parameter is automatically set to a reasonable value.&lt;br /&gt;
If the SGA_TARGET initialization parameter is not set and the STREAMS_POOL_SIZE initialization parameter is not defined,&lt;br /&gt;
then the size of the streams pool automatically defaults to 10% of the size of the shared pool.&lt;br /&gt;
&lt;br /&gt;
When the streams pool is created, the required SGA memory is taken from memory allocated to the buffer cache,&lt;br /&gt;
reducing the size of the cache to less than what was specified by the DB_CACHE_SIZE initialization parameter.&lt;br /&gt;
This means that if the buffer cache was configured with only the minimal required SGA, then Data Pump operations may not work properly.&lt;br /&gt;
A minimum size of 10M is recommended for STREAMS_POOL_SIZE in order to ensure successful Data Pump operations.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORA-00020: maximum number of processes (150) exceeded===&lt;br /&gt;
Check the current resource limits with:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 300&lt;br /&gt;
select * from v$resource_limit;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Unfortunately this limit cannot be increased without a restart.&amp;lt;br /&amp;gt;&lt;br /&gt;
It may be a necessary to increase the limit with&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter system set processes=500 scope=spfile;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
followed by a shutdown/startup&amp;lt;br /&amp;gt;&lt;br /&gt;
Or it may be some user is running away with the limit.&amp;lt;br /&amp;gt;&lt;br /&gt;
Check to see who is running what with:&lt;br /&gt;
[[http://www.mailnest.com/dbawiki/index.php/Handy_scripts#See_what_statements_all_users_are_running See_what_statements_all_users_are_running]]&lt;br /&gt;
===ORA-01555: snapshot too old: rollback segment number nn with name &amp;quot;xxx&amp;quot; too small===&lt;br /&gt;
* [http://dfitzjarrell.wordpress.com/2008/02/22/the-dreaded-ora-01555/ Good explanation of why it happens]&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
====Problem====&lt;br /&gt;
A long running transaction has run out of space to store its read-consistent image&lt;br /&gt;
&lt;br /&gt;
====Solution 1====&lt;br /&gt;
If it&amp;#039;s a one-off, maybe leave it alone. It may have been a user leaving a session open overnight without committing or rolling back.&lt;br /&gt;
&lt;br /&gt;
====Solution 2====&lt;br /&gt;
Make sure there&amp;#039;s enough space to allow the transaction to finish.&lt;br /&gt;
&lt;br /&gt;
====Things to check====&lt;br /&gt;
How much undo did the biggest transaction take?&lt;br /&gt;
What is the undo retention parameter set to?&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 200&lt;br /&gt;
col name        for a30&lt;br /&gt;
col description for a50&lt;br /&gt;
col value       for a20&lt;br /&gt;
col maxquerylen for 999999&lt;br /&gt;
select p.name&lt;br /&gt;
,      p.description&lt;br /&gt;
,      p.value&lt;br /&gt;
,      max(u.maxquerylen) maxquerylen&lt;br /&gt;
from   v$parameter p&lt;br /&gt;
,      v$undostat  u&lt;br /&gt;
where  1=1&lt;br /&gt;
and    p.name = &amp;#039;undo_retention&amp;#039;&lt;br /&gt;
group  by p.name&lt;br /&gt;
,      p.description&lt;br /&gt;
,      p.value;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Set the retention to about 20% bigger than the maxquerylen.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select &amp;#039;alter system set undo_retention=&amp;#039;||round(1.2*max(maxquerylen))||&amp;#039; scope=both;&amp;#039; &amp;quot;Run this&amp;quot; from v$undostat;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
and set the undo retention guarantee (being aware of the consequences)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select tablespace_name&lt;br /&gt;
,      retention&lt;br /&gt;
from   dba_tablespaces;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter tablespace &amp;amp;undo_ts_name retention guarantee;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Optimise Oracle UNDO Parameters===&lt;br /&gt;
&lt;br /&gt;
The ideal undo_retention would be enough to hold rollback for the longest transaction that happened so far (can&amp;#039;t see into the future)&amp;lt;br /&amp;gt;&lt;br /&gt;
So current undo_retention = current value of undo / (db_block_size * undo blocks per sec)&amp;lt;br /&amp;gt;&lt;br /&gt;
* Undo Blocks per Second&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SELECT MAX(undoblks/((end_time-begin_time)*3600*24)) &amp;quot;UNDO_BLOCKS_PER_SEC&amp;quot;&lt;br /&gt;
FROM   v$undostat;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Optimal Undo Retention&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
col actual for 9999999999.99 heading &amp;quot;ACTUAL UNDO SIZE [MByte]&amp;quot;&lt;br /&gt;
col retent for 9999999999    heading &amp;quot;UNDO RETENTION [Sec]&amp;quot;&lt;br /&gt;
col needed for 9999999999.99 heading &amp;quot;NEEDED UNDO SIZE [Secs]&amp;quot;&lt;br /&gt;
&lt;br /&gt;
SELECT d.undo_size/(1024*1024) actual,&lt;br /&gt;
       to_number(SUBSTR(e.value,1,25)) retent,&lt;br /&gt;
       ROUND((d.undo_size / (to_number(f.value) *&lt;br /&gt;
       g.undo_block_per_sec))) needed&lt;br /&gt;
  FROM (&lt;br /&gt;
       SELECT SUM(a.bytes) undo_size&lt;br /&gt;
          FROM v$datafile a,&lt;br /&gt;
               v$tablespace b,&lt;br /&gt;
               dba_tablespaces c&lt;br /&gt;
         WHERE c.contents = &amp;#039;UNDO&amp;#039;&lt;br /&gt;
           AND c.status = &amp;#039;ONLINE&amp;#039;&lt;br /&gt;
           AND b.name = c.tablespace_name&lt;br /&gt;
           AND a.ts# = b.ts#&lt;br /&gt;
       ) d,&lt;br /&gt;
       v$parameter e,&lt;br /&gt;
       v$parameter f,&lt;br /&gt;
       (&lt;br /&gt;
       SELECT MAX(undoblks/((end_time-begin_time)*3600*24))&lt;br /&gt;
              undo_block_per_sec&lt;br /&gt;
         FROM v$undostat&lt;br /&gt;
       ) g&lt;br /&gt;
WHERE e.name = &amp;#039;undo_retention&amp;#039;&lt;br /&gt;
  AND f.name = &amp;#039;db_block_size&amp;#039;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Calculate Needed UNDO Size for given Database Activity&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
col actual for 9999999999.99 heading &amp;quot;ACTUAL UNDO SIZE [MByte]&amp;quot;&lt;br /&gt;
col retent for 9999999999    heading &amp;quot;UNDO RETENTION [Sec]&amp;quot;&lt;br /&gt;
col needed for 9999999999.99 heading &amp;quot;NEEDED UNDO SIZE [MByte]&amp;quot;&lt;br /&gt;
&lt;br /&gt;
SELECT d.undo_size/(1024*1024) actual&lt;br /&gt;
,      to_number(SUBSTR(e.value,1,25)) retent&lt;br /&gt;
,      (TO_NUMBER(e.value) * TO_NUMBER(f.value) *&lt;br /&gt;
       g.undo_block_per_sec) / (1024*1024)  needed&lt;br /&gt;
  FROM (&lt;br /&gt;
       SELECT SUM(a.bytes) undo_size&lt;br /&gt;
         FROM v$datafile a,&lt;br /&gt;
              v$tablespace b,&lt;br /&gt;
              dba_tablespaces c&lt;br /&gt;
        WHERE c.contents = &amp;#039;UNDO&amp;#039;&lt;br /&gt;
          AND c.status = &amp;#039;ONLINE&amp;#039;&lt;br /&gt;
          AND b.name = c.tablespace_name&lt;br /&gt;
          AND a.ts# = b.ts#&lt;br /&gt;
       ) d,&lt;br /&gt;
      v$parameter e,&lt;br /&gt;
       v$parameter f,&lt;br /&gt;
       (&lt;br /&gt;
       SELECT MAX(undoblks/((end_time-begin_time)*3600*24))&lt;br /&gt;
         undo_block_per_sec&lt;br /&gt;
         FROM v$undostat&lt;br /&gt;
       ) g&lt;br /&gt;
 WHERE e.name = &amp;#039;undo_retention&amp;#039;&lt;br /&gt;
  AND f.name = &amp;#039;db_block_size&amp;#039;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
It might be that the Export still fails with ORA-01555 even though retention seems long enough.&amp;lt;br /&amp;gt;&lt;br /&gt;
Are you running an export with the flashback_time parameter? If so, the undo_retention should be longer than the total export running time!&amp;lt;br /&amp;gt;&lt;br /&gt;
===Check LOB undo retention===&lt;br /&gt;
The retention settings for LOBS is different for the rest of the database.&amp;lt;br /&amp;gt;&lt;br /&gt;
When you change the UNDO_RETENTION parameter, the LOB segment’s retention value is NOT modified.&amp;lt;br /&amp;gt;&lt;br /&gt;
If you query the RETENTION column of the DBA_LOBS view, you will notice the old UNDO_RETENTION value still remains after you have modified the UNDO_RETENTION parameter.&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SQL&amp;gt; show parameter undo_&lt;br /&gt;
&lt;br /&gt;
NAME                                 TYPE        VALUE&lt;br /&gt;
------------------------------------ ----------- ------------------------------&lt;br /&gt;
undo_management                      string      AUTO&lt;br /&gt;
undo_retention                       integer     36000&lt;br /&gt;
undo_tablespace                      string      UNDOTBS1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SQL&amp;gt; desc SITEADMIN.AUDIT_LOG_MESSAGE&lt;br /&gt;
 Name                                      Null?    Type&lt;br /&gt;
 ----------------------------------------- -------- ----------------------------&lt;br /&gt;
 AUDIT_LOG_MESSAGE_ID                      NOT NULL NUMBER&lt;br /&gt;
 AUDIT_LOG_ID                              NOT NULL NUMBER&lt;br /&gt;
 SEQUENCE                                           NUMBER&lt;br /&gt;
 MESSAGE                                            CLOB&lt;br /&gt;
 CREATE_DATE                                        TIMESTAMP(6)&lt;br /&gt;
 COMPONENT_ID                                       VARCHAR2(50 CHAR)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 300&lt;br /&gt;
col column_name for a32&lt;br /&gt;
select table_name,column_name, pctversion,retention from dba_lobs where owner=&amp;#039;&amp;amp;table_owner&amp;#039;;&lt;br /&gt;
&lt;br /&gt;
TABLE_NAME                COLUMN_NAME                    PCTVERSION  RETENTION&lt;br /&gt;
------------------------- ------------------------------ ---------- ----------&lt;br /&gt;
EMAIL_STORE               CONTENT                                 0&lt;br /&gt;
EMAIL_STORE_ATTACHEMENT   ATTACHEMENT                             0&lt;br /&gt;
TRACKING                  ORIGINAL_MESSAGE                                 900&lt;br /&gt;
TRACKING                  MESSAGE                                          900&lt;br /&gt;
TRACKING                  SIEBEL_MESSAGE                                   900&lt;br /&gt;
WISE_WMS_LOG              WISE_WMS_XML                                     900&lt;br /&gt;
ATTACHMENT                ORIGINAL_MESSAGE                                 900&lt;br /&gt;
PLAN_TABLE                OTHER_XML                                        900&lt;br /&gt;
AUDIT_LOG_MESSAGE         MESSAGE                                          900&lt;br /&gt;
EXCEPTIONS                STACK_TRACE                                      900&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
To change the LOB segment’s RETENTION value to match the new UNDO_RETENTION value, do the following:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ALTER TABLE my_table MODIFY LOB (lob_column) (PCTVERSION 20);&lt;br /&gt;
ALTER TABLE my_table MODIFY LOB (lob_column) (RETENTION);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
By momentarily changing the LOB to use PCTVERSION and then back to RETENTION, the new value of UNDO_RETENTION will be used.&amp;lt;br /&amp;gt;&lt;br /&gt;
You need to do this for all LOB segments that you intend to modify.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select &amp;#039;ALTER TABLE &amp;#039;||owner||&amp;#039;.&amp;#039;||table_name||&amp;#039; MODIFY LOB (&amp;#039;||column_name||&amp;#039;) (PCTVERSION 20);&amp;#039; from dba_lobs where owner=&amp;#039;TIBCO&amp;#039;&lt;br /&gt;
&lt;br /&gt;
select &amp;#039;ALTER TABLE &amp;#039;||owner||&amp;#039;.&amp;#039;||table_name||&amp;#039; MODIFY LOB (&amp;#039;||column_name||&amp;#039;) (RETENTION);&amp;#039;     from dba_lobs where owner=&amp;#039;TIBCO&amp;#039;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
There is a table DBA_LOBS that displays information about all the LOB columns in the database, but it doesn&amp;#039;t actually store any LOB data, just metadata. The actual LOB segments in the database have system-generated names that take the form SYS_LOB*identifier*$$.&lt;br /&gt;
For example if you identify a segment named SYS_LOBidentifier$$ that is consuming space, you can find out what column of what table that LOB column maps to using the DBA_LOBS table:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 1000&lt;br /&gt;
col owner       for a20&lt;br /&gt;
col table_name  for a32&lt;br /&gt;
col column_name for a32&lt;br /&gt;
select owner&lt;br /&gt;
,      table_name&lt;br /&gt;
,      column_name&lt;br /&gt;
from   dba_lobs&lt;br /&gt;
where  1=1&lt;br /&gt;
and    segment_name = &amp;#039;SYS_LOB&amp;lt;&amp;lt;identifier&amp;gt;&amp;gt;$$&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====The Undo Advisor PL/SQL Interface====&lt;br /&gt;
You can activate the Undo Advisor by creating an undo advisor task through the advisor framework.&amp;lt;br /&amp;gt;&lt;br /&gt;
The following example creates an undo advisor task to evaluate the undo tablespace. The name of the advisor is &amp;#039;Undo Advisor&amp;#039;.&amp;lt;br /&amp;gt;&lt;br /&gt;
The analysis is based on Automatic Workload Repository snapshots, which you must specify by setting parameters START_SNAPSHOT and END_SNAPSHOT.&amp;lt;br /&amp;gt;&lt;br /&gt;
In the following example, the START_SNAPSHOT is &amp;quot;1&amp;quot; and END_SNAPSHOT is &amp;quot;2&amp;quot;.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
DECLARE&lt;br /&gt;
   tid    NUMBER;&lt;br /&gt;
   tname  VARCHAR2(30);&lt;br /&gt;
   oid    NUMBER;&lt;br /&gt;
BEGIN&lt;br /&gt;
   DBMS_ADVISOR.CREATE_TASK(&amp;#039;Undo Advisor&amp;#039;, tid, tname, &amp;#039;Undo Advisor Task&amp;#039;);&lt;br /&gt;
   DBMS_ADVISOR.CREATE_OBJECT(tname, &amp;#039;UNDO_TBS&amp;#039;, null, null, null, &amp;#039;null&amp;#039;, oid);&lt;br /&gt;
   DBMS_ADVISOR.SET_TASK_PARAMETER(tname, &amp;#039;TARGET_OBJECTS&amp;#039;, oid);&lt;br /&gt;
   DBMS_ADVISOR.SET_TASK_PARAMETER(tname, &amp;#039;START_SNAPSHOT&amp;#039;, 1);&lt;br /&gt;
   DBMS_ADVISOR.SET_TASK_PARAMETER(tname, &amp;#039;END_SNAPSHOT&amp;#039;, 2);&lt;br /&gt;
   DBMS_ADVISOR.SET_TASK_PARAMETER(tname, &amp;#039;INSTANCE&amp;#039;, 1);&lt;br /&gt;
   DBMS_ADVISOR.execute_task(tname);&lt;br /&gt;
        END;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
After you have created the advisor task, you can view the output and recommendations in the Automatic Database Diagnostic Monitor in Enterprise Manager.&amp;lt;br /&amp;gt;&lt;br /&gt;
This information is also available in the DBA_ADVISOR_* data dictionary views (DBA_ADVISOR_TASKS, DBA_ADVISOR_OBJECTS, DBA_ADVISOR_FINDINGS, DBA_ADVISOR_RECOMMENDATIONS, and so on).&lt;br /&gt;
====References====&lt;br /&gt;
* [http://www.akadia.com/services/ora_optimize_undo.html akadia.com]&lt;br /&gt;
* [http://dfitzjarrell.wordpress.com/2008/02/22/the-dreaded-ora-01555/ the dreaded ora-01555]&lt;br /&gt;
* [http://docs.oracle.com/cd/B28359_01/server.111/b28310/undo004.htm#ADMIN11469 docs.oracle.com]&lt;br /&gt;
&lt;br /&gt;
===Error 6 initializing SQL*Plus===&lt;br /&gt;
Using sqlplus or rman under Cygwin, ORACLE_HOME still needs to be windows format!&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Message file sp1&amp;lt;lang&amp;gt;.msb not found&lt;br /&gt;
SP2-0750 :You may need to set ORACLE_HOME to your Oracle software directory&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
so...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
export ORACLE_SID=KITRYD&lt;br /&gt;
ORAENV_ASK=NO&lt;br /&gt;
. oraenv&lt;br /&gt;
[[ &amp;quot;`uname`&amp;quot; == CYGWIN* ]] &amp;amp;&amp;amp; ORACLE_HOME=`cygpath -w ${ORACLE_HOME}`&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===ORA-2002: error while writing to audit trail===&lt;br /&gt;
Check the space left in the audit tablespace with:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select sum(bytes)/1024/1024 mb from dba_free_space where tablespace_name =&amp;#039;AUDIT_DT&amp;#039;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
If plenty of space, it can be due to Oracle clearing out the recyclebin at the same time.&amp;lt;br /&amp;gt;&lt;br /&gt;
If not, extend the datafile...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select * from dba_data_files where tablespace_name =&amp;#039;AUDIT_DT&amp;#039;;&lt;br /&gt;
alter database datafile 6 resize 30G;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
If that is not possible, clean out some audit data or add a datafile.&lt;br /&gt;
&lt;br /&gt;
===ORA-00449: background process &amp;#039;CKPT&amp;#039; unexpectedly terminated with error 7446===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SQL&amp;gt; startup nomount pfile=&amp;quot;/oracle/TRSCRP1/admin/initTRSCRP1.ora&amp;quot;&lt;br /&gt;
ORA-00449: background process &amp;#039;CKPT&amp;#039; unexpectedly terminated with error 7446&lt;br /&gt;
ORA-07446: sdnfy: bad value &amp;#039;&amp;#039; for parameter .&lt;br /&gt;
SQL&amp;gt; exit&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Solution&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SQL&amp;gt; mkdir /oracle/TRSCRP1/admin/bdump /oracle/TRSCRP1/admin/cdump&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORA-00845: MEMORY_TARGET not supported on this system===&lt;br /&gt;
* Reference: [http://arjudba.blogspot.be/2009/01/ora-00845-memorytarget-not-supported-on.html arjudba.blogspot.be]&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Problem Description&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SQL&amp;gt; STARTUP&lt;br /&gt;
ORA-00845: MEMORY_TARGET not supported on this system&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Cause&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
* Starting from Oracle 11g the automatic memory management feature is now defined with parameter MEMORY_TARGET and MEMMORY_MAX_TARGET.&lt;br /&gt;
* On linux file system the shared memory need to be mounted on /dev/shm directory on the operating system.&lt;br /&gt;
* And the size of /dev/shm needs to be greater than MEMORY_TARGET or MEMMORY_MAX_TARGET.&lt;br /&gt;
* The AMM (Automatic Memory Management) now in 11g manages both SGA and PGA together by MMAN process.&lt;br /&gt;
* The MEMORY_TARGET parameter in 11g comes for (SGA_TARGET+PGA_AGGREGATE_TARGET) which was in 10g.&lt;br /&gt;
* And MEMORY_MAX_TARGET parameter in 11g comes instead of SGA_MAX_TARGET parameter which was in 10g.&lt;br /&gt;
* The ORA-00845:can arises for the following two reasons on linux system.&lt;br /&gt;
1)If the shared memory which is mapped to /dev/shm directory is less than the size of MEMORY_TARGET or MEMORY_MAX_TARGET or&lt;br /&gt;
2)If the shared memory is not mapped to /dev/shm directory.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Solution&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Make sure /dev/shm is properly mounted. You can see it by,&lt;br /&gt;
#df -h or #df -k command.&lt;br /&gt;
The output should be similar to:&lt;br /&gt;
&lt;br /&gt;
$ df -k&lt;br /&gt;
Filesystem            Size  Used Avail Use% Mounted on&lt;br /&gt;
...&lt;br /&gt;
shmfs                 1G    512M 512M  50% /dev/shm&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
We see here for /dev/shm we have assigned 1G memory. Now if you set MEMORY_TARGET more than 1G then above ORA-845 will arise. For example if you have MEMORY_TARGET or MEMORY_MAX_TARGET set to 12G then you can mount shared memory to 13g like below.&lt;br /&gt;
As a root user,&lt;br /&gt;
# mount -t tmpfs shmfs -o size=13g /dev/shm&lt;br /&gt;
In order to make the settings persistence so that it will affect after restarting machine add an entry in /etc/fstab similar to the following:&lt;br /&gt;
&lt;br /&gt;
shmfs /dev/shm tmpfs size=13g 0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORA-24247: network access denied by access control list (ACL)===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Cause: No access control list (ACL) has been assigned to the target host or the privilege necessary to access the target host has not been granted to the user in the access control list.&lt;br /&gt;
&lt;br /&gt;
Action: Ensure that an access control list (ACL) has been assigned to the target host and the privilege necessary to access the target host has been granted to the user.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Your application will encounter an ORA-24247 error if it relies on one of the network packages and no proper ACL has been created. For the use of the following packages it is mandatory to have an ACL for the application user in place in 11g:&lt;br /&gt;
*UTL_TCP&lt;br /&gt;
*UTL_SMTP&lt;br /&gt;
*UTL_MAIL&lt;br /&gt;
*UTL_HTTP&lt;br /&gt;
*UTL_INADDR&lt;br /&gt;
Here is a very good explanation of how to setup the necessary ACLs: [[http://blog.whitehorses.nl/2010/03/17/oracle-11g-access-control-list-and-ora-24247/ whitehorses.nl]]&lt;br /&gt;
&lt;br /&gt;
===ORA-00600: internal error code, arguments: [qmx: no ref]===&lt;br /&gt;
Search &amp;quot;Master Note for Oracle XML Database (XDB) Install / Deinstall (Doc ID 1292089.1)&amp;quot; for more info.&lt;br /&gt;
====Problem:====&lt;br /&gt;
Sometimes one or more of the following errors can be encountered when installing or upgrading XDB, configuring APEX, running an Export, or selecting from xdb.xdb$resource or sys.dba_network_acls:&amp;lt;br /&amp;gt;&lt;br /&gt;
* ORA-31159: XML DB is in an invalid state&lt;br /&gt;
* ORA-00600: internal error code, arguments: [unable to load XDB library]&lt;br /&gt;
* ORA-00600: internal error code, arguments: [qmx: no ref]&lt;br /&gt;
* ORA-00600: internal error code, arguments: [qmtGetColumnInfo1]&lt;br /&gt;
* ORA-00600: internal error code, arguments: [qmtb_init_len]&lt;br /&gt;
* ORA-00600: internal error code, arguments: [qmtGetBaseType]&lt;br /&gt;
* ORA-00600: internal error code, arguments: [psdnop-1], [600]&lt;br /&gt;
* ORA-00600: internal error code, arguments: [qmtInit1]&lt;br /&gt;
* ORA-07445: exception encountered: core dump [_memcpy()+224] [SIGSEGV] [Address not mapped to object]&lt;br /&gt;
* ORA-19051 Cannot Use Fast Path Insert For This XMLType Table&lt;br /&gt;
* ORA-31011: XML parsing failed&lt;br /&gt;
Errors of this sort generally occur when the init routines for the internal XDB functions are run in an invalid environment causing memory corruption.&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
This can happen if the database was ever started with the LD_LIBRARY_PATH (LIBPATH for AIX or SHLIB_PATH for HP) pointing to the wrong $ORACLE_HOME/lib directory rather than to the correct location for the instance.&amp;lt;br /&amp;gt;&lt;br /&gt;
The LD_LIBRARY_PATH/LIBPATH/SHLIB_PATH environment variable is used to resolve the location of the shared library &amp;quot;libxdb.so (libxdb.sl on HP)&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
====Solution:====&lt;br /&gt;
* Stop Listener&lt;br /&gt;
* Stop database&lt;br /&gt;
* Ensure $ORACLE_HOME/lib is at the start of LD_LIBRARY_PATH / LIBPATH / SHLIB_PATH&lt;br /&gt;
* If AIX, run /usr/sbin/slibclean as root&lt;br /&gt;
* Start database&lt;br /&gt;
* Start listener&lt;br /&gt;
&lt;br /&gt;
===ORA-00201: control file version nn.nn.nn.nn incompatible with ORACLE version===&lt;br /&gt;
Trying to restore a database after complete failure&amp;lt;br /&amp;gt;&lt;br /&gt;
first step is to startup the database in nomount mode and restore the controlfile - succeeded.&amp;lt;br /&amp;gt;&lt;br /&gt;
second step, startup the database in mount mode ready for database restore...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SQL*Plus: Release 10.2.0.3.0 - Production on Wed Aug 19 18:16:47 2015&lt;br /&gt;
&lt;br /&gt;
Copyright (c) 1982, 2006, Oracle.  All Rights Reserved.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Connected to:&lt;br /&gt;
Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - 64bit Production&lt;br /&gt;
With the Partitioning, OLAP and Data Mining options&lt;br /&gt;
&lt;br /&gt;
SYS@CODWHP1&amp;gt; startup mount&lt;br /&gt;
ORACLE instance started.&lt;br /&gt;
&lt;br /&gt;
Total System Global Area  260046848 bytes&lt;br /&gt;
Fixed Size                  2029296 bytes&lt;br /&gt;
Variable Size             113248528 bytes&lt;br /&gt;
Database Buffers          134217728 bytes&lt;br /&gt;
Redo Buffers               10551296 bytes&lt;br /&gt;
ORA-00201: control file version 10.2.0.0.0 incompatible with ORACLE version 10.2.0.3.0&lt;br /&gt;
ORA-00202: control file: &amp;#039;/oracle/CODWHP1/product/10203/dbs/cntrlCODWHP1.dbf&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The problem was there was no compatible parameter in the simple init file I used to start up the instance.&amp;lt;br /&amp;gt;&lt;br /&gt;
Adding compatible parameter to init file to be same version (10.2.0.3) allowed the db to mount.&lt;br /&gt;
&lt;br /&gt;
===TNS-00525: Insufficient privilege for operation===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
lsnrctl start LISTENER_UCLID55V&lt;br /&gt;
&lt;br /&gt;
LSNRCTL for IBM/AIX RISC System/6000: Version 11.2.0.3.0 - Production on 26-MAR-2015 13:36:14&lt;br /&gt;
&lt;br /&gt;
Copyright (c) 1991, 2011, Oracle.  All rights reserved.&lt;br /&gt;
&lt;br /&gt;
Starting /oracle/product/11.2.0.3/bin/tnslsnr: please wait...&lt;br /&gt;
&lt;br /&gt;
TNSLSNR for IBM/AIX RISC System/6000: Version 11.2.0.3.0 - Production&lt;br /&gt;
System parameter file is /oracle/product/11.2.0.3/network/admin/listener.ora&lt;br /&gt;
Log messages written to /oracle/product/diag/tnslsnr/solax082/listener_uclid55v/alert/log.xml&lt;br /&gt;
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=150.251.114.238)(PORT=1525)))&lt;br /&gt;
Error listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC1525)))&lt;br /&gt;
TNS-12555: TNS:permission denied&lt;br /&gt;
 TNS-12560: TNS:protocol adapter error&lt;br /&gt;
  TNS-00525: Insufficient privilege for operation&lt;br /&gt;
   IBM/AIX RISC System/6000 Error: 1: Not owner&lt;br /&gt;
&lt;br /&gt;
Listener failed to start. See the error message(s) above...&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This would suggest the user attempting to start the listener has no access to either the Oracle binaries or the TNS listener/tnsnames files.&amp;lt;br /&amp;gt;&lt;br /&gt;
But... checkout the /tmp/.oracle directory :-)&amp;lt;br /&amp;gt;&lt;br /&gt;
That hidden gem shows who started the listener last time. Delete the relevant entry and try again!&amp;lt;br /&amp;gt;&lt;br /&gt;
To start from a clean sheet, stop all listeners, delete this directory and restart the listeners.&lt;br /&gt;
&lt;br /&gt;
===ORA-12003: materialized view or zonemap &amp;quot;KPK&amp;quot;.&amp;quot;EVD01_NEW&amp;quot; does not exist===&lt;br /&gt;
Here&amp;#039;s one you shouldn&amp;#039;t see very often.&amp;lt;br /&amp;gt;&lt;br /&gt;
Trying to drop a tablespace but prevented from doing so because a materialized view has referential contraints on a table in this tablespace.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SQL&amp;gt; drop tablespace TS_THALER_PART_OLD including contents and datafiles cascade constraints;&lt;br /&gt;
drop tablespace TS_THALER_PART_OLD including contents and datafiles cascade constraints&lt;br /&gt;
*&lt;br /&gt;
ERROR at line 1:&lt;br /&gt;
ORA-00604: error occurred at recursive SQL level 1&lt;br /&gt;
ORA-12083: must use DROP MATERIALIZED VIEW to drop &amp;quot;KPK&amp;quot;.&amp;quot;EVD01_NEW&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Ok, nice of Oracle to tell us what we have to do. Simple enough. Let&amp;#039;s drop the materialized view.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SQL&amp;gt; DROP MATERIALIZED VIEW &amp;quot;KPK&amp;quot;.&amp;quot;EVD01_NEW&amp;quot;;&lt;br /&gt;
DROP MATERIALIZED VIEW &amp;quot;KPK&amp;quot;.&amp;quot;EVD01_NEW&amp;quot;&lt;br /&gt;
*&lt;br /&gt;
ERROR at line 1:&lt;br /&gt;
ORA-12003: materialized view or zonemap &amp;quot;KPK&amp;quot;.&amp;quot;EVD01_NEW&amp;quot; does not exist&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Aah. Not so obvious then.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
desc &amp;quot;KPK&amp;quot;.&amp;quot;EVD01_NEW&amp;quot;&lt;br /&gt;
 Name                                      Null?    Type&lt;br /&gt;
 ----------------------------------------- -------- ----------------------------&lt;br /&gt;
 DATMAJ                                             VARCHAR2(8 CHAR)&lt;br /&gt;
 HEUMAJ                                             VARCHAR2(8 CHAR)&lt;br /&gt;
 PGMMAJ                                             VARCHAR2(6 CHAR)&lt;br /&gt;
 NATOPN                                             VARCHAR2(6 CHAR)&lt;br /&gt;
 REFEXN                                             VARCHAR2(50 CHAR)&lt;br /&gt;
 SWIOLN                                             VARCHAR2(1 CHAR)&lt;br /&gt;
 STAEVT                                             VARCHAR2(4 CHAR)&lt;br /&gt;
 REFEVT                                             VARCHAR2(16 CHAR)&lt;br /&gt;
 NUMIDT                                             VARCHAR2(30 CHAR)&lt;br /&gt;
 ORIEVT                                             VARCHAR2(10 CHAR)&lt;br /&gt;
 REFLOG                                             VARCHAR2(16 CHAR)&lt;br /&gt;
 MSGEVT_CPL                                         VARCHAR2(1500 CHAR)&lt;br /&gt;
 REFOPN                                             VARCHAR2(16 CHAR)&lt;br /&gt;
 DATEVT                                             VARCHAR2(8 CHAR)&lt;br /&gt;
 MSGEVT_FIL_1                                       VARCHAR2(2000 CHAR)&lt;br /&gt;
 MSGEVT_FIL_2                                       VARCHAR2(2000 CHAR)&lt;br /&gt;
 MSGEVT_SPE                                         VARCHAR2(200 CHAR)&lt;br /&gt;
 DATEFF                                             VARCHAR2(8 CHAR)&lt;br /&gt;
 TMSTMP                                             VARCHAR2(15 CHAR)&lt;br /&gt;
 VEREVT                                             VARCHAR2(3 CHAR)&lt;br /&gt;
 MSGEVT_FIL_3                                       VARCHAR2(2000 CHAR)&lt;br /&gt;
 MSGEVT_FIL_4                                       VARCHAR2(2000 CHAR)&lt;br /&gt;
 TYPEVT                                             VARCHAR2(5 CHAR)&lt;br /&gt;
 SBP_CODAPP                                         VARCHAR2(10 CHAR)&lt;br /&gt;
 SBP_REFINT                                         VARCHAR2(36 CHAR)&lt;br /&gt;
 SBP_TYPACT                                         VARCHAR2(2 CHAR)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
It exists... but as a table.&amp;lt;br /&amp;gt;&lt;br /&gt;
Something has gone wrong in the database somewhere. As it turns out after some deeper investigation, this database is a copy of production but &amp;quot;with modifications&amp;quot;.&amp;lt;br /&amp;gt;&lt;br /&gt;
After the cloning process, a schema needed renaming. Oracle have a procedure for this but it is very long-winded and time-consuming. It uses export and import with transportable tablespaces to do the remap of the schema.&amp;lt;br /&amp;gt;&lt;br /&gt;
An unsupported workaround to rename schema is to simply update the username in sys.user$ and restart the database.&amp;lt;br /&amp;gt;&lt;br /&gt;
This works for the most part but now we see a consequence of that action.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
col owner      for a30&lt;br /&gt;
col mview_name for a30&lt;br /&gt;
select owner&lt;br /&gt;
,      mview_name&lt;br /&gt;
from   dba_mviews&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
OWNER                          MVIEW_NAME&lt;br /&gt;
------------------------------ ------------------------------&lt;br /&gt;
EPK                            EVD01_NEW&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Ahaa, there&amp;#039;s the materialized view but the owner is different from the one described by the database error message above. This one is the owner as it was on production.&amp;lt;br /&amp;gt;&lt;br /&gt;
This means the owner of materialized views has been denormalised for some reason. Reading the (complex) view text of dba_mviews, we see the owner column is based on sys.snap$.sowner&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
col sowner for a20&lt;br /&gt;
col vname  for a20&lt;br /&gt;
col tname  for a20&lt;br /&gt;
select sowner&lt;br /&gt;
,      vname&lt;br /&gt;
,      tname&lt;br /&gt;
from   sys.snap$&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
SOWNER               VNAME                TNAME&lt;br /&gt;
-------------------- -------------------- --------------------&lt;br /&gt;
EPK                  EVD01_NEW            EVD01_NEW&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
For future reference when updating the username in sys.user$, update the snapshot owner in this table as well!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
update sys.snap$&lt;br /&gt;
set    sowner = &amp;#039;KPK&amp;#039;&lt;br /&gt;
where  sowner = &amp;#039;EPK&amp;#039;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Try again&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
DROP MATERIALIZED VIEW &amp;quot;KPK&amp;quot;.&amp;quot;EVD01_NEW&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
Materialized view dropped.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
yep, and the tablespace?&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
drop tablespace TS_THALER_PART_OLD including contents and datafiles cascade constraints;&lt;br /&gt;
&lt;br /&gt;
Tablespace dropped.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORA-12162: TNS:net service name is incorrectly specified===&lt;br /&gt;
Probably nothing to do with TNS. Check your ORACLE_SID is set correctly!&lt;br /&gt;
&lt;br /&gt;
===ORA-00054: resource busy and acquire with NOWAIT specified===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SELECT O.OBJECT_NAME, S.SID, S.SERIAL#, P.SPID, S.PROGRAM,S.USERNAME,&lt;br /&gt;
S.MACHINE,S.PORT , S.LOGON_TIME,SQ.SQL_FULLTEXT &lt;br /&gt;
FROM V$LOCKED_OBJECT L, DBA_OBJECTS O, V$SESSION S, &lt;br /&gt;
V$PROCESS P, V$SQL SQ &lt;br /&gt;
WHERE L.OBJECT_ID = O.OBJECT_ID &lt;br /&gt;
AND L.SESSION_ID = S.SID AND S.PADDR = P.ADDR &lt;br /&gt;
AND S.SQL_ADDRESS = SQ.ADDRESS;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select object_name, s.sid, s.serial#, p.spid &lt;br /&gt;
from v$locked_object l, dba_objects o, v$session s, v$process p&lt;br /&gt;
where l.object_id = o.object_id and l.session_id = s.sid and s.paddr = p.addr;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
then&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter system kill session &amp;#039;sid,serial#&amp;#039;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORA-12518: TNS:listener could not hand off client connection===&lt;br /&gt;
The database you are trying to connect to is probably on its knees. Check server memory is not exhausted.&lt;br /&gt;
&lt;br /&gt;
===ORA-12520: TNS:listener could not find available handler for requested type of server===&lt;br /&gt;
Strangely this could be related to number of processes being exhausted.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
show parameter processes&lt;br /&gt;
alter system set processes=350 scope=spfile;&lt;br /&gt;
shutdown immediate&lt;br /&gt;
startup&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORA-12541: TNS: no listener===&lt;br /&gt;
Either very basic - start the listener!&amp;lt;br /&amp;gt;&lt;br /&gt;
or, as in our case - not so obvious.&amp;lt;br /&amp;gt;&lt;br /&gt;
We use virtual IP addresses so that the IP address stays the same after failover to standby.&amp;lt;br /&amp;gt;&lt;br /&gt;
Due to some confused configuration, we got the network adapter on two different servers to have the same IP address.&amp;lt;br /&amp;gt;&lt;br /&gt;
Stop the IP address on the bad server (assign another one) and all is fine again.&lt;br /&gt;
===ORA-12514: TNS:listener does not currently know of service===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
lsnrctl status &amp;lt;listener_name&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Been altering tnsnames.ora or listener.ora?&lt;br /&gt;
* Check the local_listener parameter&lt;br /&gt;
Try resetting it to itself. Strange but if you are not using port 1521, this can work wonders!&amp;lt;br /&amp;gt;&lt;br /&gt;
Assuming listener is called LISTENER_WM9T:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter system set local_listener=LISTENER_WM9T scope=both;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Try and connect with the service name or directly with&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sqlplus &amp;#039;sys/*******&amp;#039;@&amp;lt;host&amp;gt;:&amp;lt;port&amp;gt;/&amp;lt;SID&amp;gt; as sysdba&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Excellent description of how Oracle TNS listeners work and a checklist on how to fix this error&amp;lt;br /&amp;gt;&lt;br /&gt;
* [[http://edstevensdba.wordpress.com/2011/03/19/ora-12514/ TNS — Ed Stevens]]&lt;br /&gt;
&lt;br /&gt;
===ORA-12547: TNS lost contact===&lt;br /&gt;
&lt;br /&gt;
If&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sqlplus &amp;lt;user&amp;gt;/&amp;lt;pass&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
fails with above error, try&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sqlplus &amp;lt;user&amp;gt;/&amp;lt;pass&amp;gt;@&amp;lt;db connection&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
If this works, it is most probably a permissions error.&amp;lt;br /&amp;gt;&lt;br /&gt;
Re-run the&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ORACLE_HOME/root.sh&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
script that was run as part of the original installation. This will reset the permissions on some important files.&lt;br /&gt;
===ORA-02374: conversion error loading table &amp;quot;BLENGADM&amp;quot;.&amp;quot;ZZ_EVTCTA&amp;quot;===&lt;br /&gt;
This is typical of importing data with Datapump when the tables in the source database were created with &amp;quot;byte&amp;quot; semantics and the destination is &amp;quot;char&amp;quot; semantics.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ORA-02374: conversion error loading table &amp;quot;BLENGADM&amp;quot;.&amp;quot;ZZ_EVTCTA&amp;quot;&lt;br /&gt;
ORA-12899: value too large for column NOMCTA (actual: 257, maximum: 256)&lt;br /&gt;
&lt;br /&gt;
ORA-02372: data for row: NOMCTA : 0X&amp;#039;4C6976726574206427E9706172676E65202020202020202020&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Problem====&lt;br /&gt;
The root cause is the nls_length_semantics of the table columns being BYTE where one character is assigned one byte. But after conversion in a multi-byte database, one character is larger than one byte (could be 2, 3 or 4) and no longer fits.&lt;br /&gt;
====Solution====&lt;br /&gt;
* import the metadata&lt;br /&gt;
Run the impdp command with content=metadata_only. This will create all the tables (still in their original form) but not the data.&lt;br /&gt;
* alter the BYTE columns in the affected tables to CHAR semantics&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select column_name&lt;br /&gt;
,      char_used&lt;br /&gt;
,      data_length&lt;br /&gt;
,      data_type &lt;br /&gt;
from   user_tab_columns &lt;br /&gt;
where  table_name = &amp;#039;T&amp;#039;&lt;br /&gt;
and    char_used = &amp;#039;B&amp;#039;;&lt;br /&gt;
COLUMN_NAME  C DATA_LENGTH DATA_TYPE&lt;br /&gt;
------------ - ----------- ---------&lt;br /&gt;
X            B           1 VARCHAR2&lt;br /&gt;
SQL&amp;gt; alter table t modify x varchar2(1 char);&lt;br /&gt;
Table altered.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Import the data&lt;br /&gt;
Rerun the impdp ensuring table_exists_action is not REPLACE (use truncate or append). This now imports the data into the modified tables.&lt;br /&gt;
====This script does the donkey work of altering table column semantics from byte to char====&lt;br /&gt;
The author of this script is unknown but he/she deserves a medal. It saves countless hours of work and is so well written.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/*&lt;br /&gt;
  The script converts all the VARCHAR2 columns in the user&amp;#039;s schema&lt;br /&gt;
  to CHAR length semantics. Known to work on 10.2.0.4 and later.&lt;br /&gt;
  &lt;br /&gt;
  Script must be executed against the database without any other client&lt;br /&gt;
  and/or application connections to the affected schema.&lt;br /&gt;
  &lt;br /&gt;
  Oracle does not support CHAR semantics for the built-in schemas,&lt;br /&gt;
  like SYS, SYSTEM or SYSMAN, so the script will throw an error,&lt;br /&gt;
  if attempt to run it against any one of them.&lt;br /&gt;
  &lt;br /&gt;
  Upon completion database objects that have dependencies on tables&lt;br /&gt;
  being modified will be invalidated. Oracle usually re-compiles invalidated&lt;br /&gt;
  objects on the first access. Alternatively, a DBA can execute UTLPRP script&lt;br /&gt;
  to recompile all invalid objects in the entire database.&lt;br /&gt;
  &lt;br /&gt;
  Upon completion, please make sure that NLS_LENGTH_SEMANTICS instance parameter&lt;br /&gt;
  is set to CHAR to ensure further upgradability of the schema.&lt;br /&gt;
*/&lt;br /&gt;
set serveroutput on size unlimited format wrap&lt;br /&gt;
declare&lt;br /&gt;
  type sql_list_t is table of varchar2(32767) index by pls_integer;&lt;br /&gt;
  type idx_list_t is table of user_indexes.index_name%type index by pls_integer;&lt;br /&gt;
  type col_list_t is table of user_tab_columns%rowtype index by pls_integer;&lt;br /&gt;
  --&lt;br /&gt;
  lv_col_cnt   pls_integer := 0;&lt;br /&gt;
  lv_idx_cnt   pls_integer := 0;&lt;br /&gt;
  lv_char_set  pls_integer := 0; &lt;br /&gt;
  lv_user      user_users.username%type;&lt;br /&gt;
  lv_sql_stmt  varchar2(32767);&lt;br /&gt;
  lv_byte_cols col_list_t;&lt;br /&gt;
  lv_idx_names idx_list_t;&lt;br /&gt;
  lv_idx_ddls  sql_list_t;&lt;br /&gt;
  --&lt;br /&gt;
  procedure run_sql_stmt&lt;br /&gt;
  (&lt;br /&gt;
   p_sql_stmt in varchar2&lt;br /&gt;
  )&lt;br /&gt;
  as&lt;br /&gt;
  begin&lt;br /&gt;
    execute immediate p_sql_stmt;&lt;br /&gt;
  exception&lt;br /&gt;
    when others&lt;br /&gt;
    then&lt;br /&gt;
      raise_application_error(-20202, &amp;#039;Failed statement [&amp;#039; || p_sql_stmt || dbms_utility.format_error_backtrace() || &amp;#039;]&amp;#039;, true);&lt;br /&gt;
  end;&lt;br /&gt;
begin&lt;br /&gt;
  --&lt;br /&gt;
  lv_user := user();&lt;br /&gt;
  if lv_user in (&amp;#039;SYS&amp;#039;, &amp;#039;SYSTEM&amp;#039;, &amp;#039;SYSMAN&amp;#039;)&lt;br /&gt;
  then&lt;br /&gt;
    raise_application_error(-20202, &amp;#039;This script cannot be executed against Oracle built-in schema [&amp;#039; || lv_user || &amp;#039;].&amp;#039;);&lt;br /&gt;
  end if;&lt;br /&gt;
  --&lt;br /&gt;
  select&lt;br /&gt;
         *&lt;br /&gt;
         bulk collect into lv_byte_cols&lt;br /&gt;
  from&lt;br /&gt;
         user_tab_columns uc&lt;br /&gt;
  where&lt;br /&gt;
         uc.char_used = &amp;#039;B&amp;#039;&lt;br /&gt;
         and&lt;br /&gt;
         substr(uc.table_name, 1, 4) != &amp;#039;BIN$&amp;#039;&lt;br /&gt;
         and&lt;br /&gt;
         not exists&lt;br /&gt;
         (&lt;br /&gt;
          select 1&lt;br /&gt;
          from   user_views uv&lt;br /&gt;
          where  uv.view_name = uc.table_name&lt;br /&gt;
         )&lt;br /&gt;
  ;&lt;br /&gt;
  --&lt;br /&gt;
  lv_col_cnt := lv_byte_cols.count();&lt;br /&gt;
  --&lt;br /&gt;
  dbms_output.enable();&lt;br /&gt;
  --&lt;br /&gt;
  if lv_col_cnt &amp;gt; 0&lt;br /&gt;
  then&lt;br /&gt;
    for idx_rw in&lt;br /&gt;
    (&lt;br /&gt;
     select index_name &lt;br /&gt;
     from   user_indexes&lt;br /&gt;
     where  index_type = &amp;#039;FUNCTION-BASED NORMAL&amp;#039;&lt;br /&gt;
    )&lt;br /&gt;
    loop&lt;br /&gt;
      lv_idx_cnt := lv_idx_cnt + 1;&lt;br /&gt;
      lv_idx_names(lv_idx_cnt) := idx_rw.index_name;&lt;br /&gt;
      lv_idx_ddls(lv_idx_cnt) := replace&lt;br /&gt;
                                 (&lt;br /&gt;
                                  dbms_metadata.get_ddl&lt;br /&gt;
                                  (&lt;br /&gt;
                                   object_type =&amp;gt; &amp;#039;INDEX&amp;#039;,&lt;br /&gt;
                                   name        =&amp;gt; idx_rw.index_name&lt;br /&gt;
                                  )&lt;br /&gt;
                                  ,&lt;br /&gt;
                                  &amp;#039;;&amp;#039;&lt;br /&gt;
                                 );&lt;br /&gt;
      lv_sql_stmt := &amp;#039;drop index &amp;#039; || idx_rw.index_name;&lt;br /&gt;
      run_sql_stmt(lv_sql_stmt);&lt;br /&gt;
      dbms_output.put_line(&amp;#039;Dropped function-based index: &amp;#039; || idx_rw.index_name);&lt;br /&gt;
      dbms_output.put_line(&amp;#039;In case of script failure, restore the index by running the DDL statement below:&amp;#039;);&lt;br /&gt;
      dbms_output.put_line(lv_idx_ddls(lv_idx_cnt) || &amp;#039;;&amp;#039;);&lt;br /&gt;
    end loop;&lt;br /&gt;
    --&lt;br /&gt;
    for i in 1..lv_col_cnt&lt;br /&gt;
    loop&lt;br /&gt;
      lv_sql_stmt :=  &amp;#039;alter table &amp;#039; || lv_byte_cols(i).table_name || &amp;#039; modify (&amp;#039; ||&lt;br /&gt;
                      lv_byte_cols(i).column_name || &amp;#039; &amp;#039; || lv_byte_cols(i).data_type ||&lt;br /&gt;
                      &amp;#039;(&amp;#039; || lv_byte_cols(i).char_length || &amp;#039; char))&amp;#039;;&lt;br /&gt;
      run_sql_stmt(lv_sql_stmt);&lt;br /&gt;
    end loop;&lt;br /&gt;
    --&lt;br /&gt;
    dbms_output.new_line();&lt;br /&gt;
    for i in 1..lv_idx_cnt&lt;br /&gt;
    loop&lt;br /&gt;
      run_sql_stmt(lv_idx_ddls(i));&lt;br /&gt;
      dbms_output.put_line(&amp;#039;Recreated function-based index: &amp;#039; || lv_idx_names(i));&lt;br /&gt;
    end loop;&lt;br /&gt;
    --&lt;br /&gt;
    dbms_output.new_line();&lt;br /&gt;
    dbms_output.put_line&lt;br /&gt;
    (&lt;br /&gt;
     &amp;#039;Updated length semantics to CHAR for &amp;#039; || lv_col_cnt || &amp;#039; column&amp;#039; ||&lt;br /&gt;
     case when lv_col_cnt &amp;gt; 1&lt;br /&gt;
          then &amp;#039;s&amp;#039;&lt;br /&gt;
     end ||&lt;br /&gt;
     &amp;#039; in the schema [&amp;#039; || lv_user || &amp;#039;].&amp;#039;&lt;br /&gt;
    );&lt;br /&gt;
  else&lt;br /&gt;
    dbms_output.put_line(&amp;#039;No columns with BYTE length semantics were found in the schema [&amp;#039; || lv_user || &amp;#039;].&amp;#039;);&lt;br /&gt;
  end if;&lt;br /&gt;
  --&lt;br /&gt;
  select count(*) into lv_char_set&lt;br /&gt;
  from   nls_session_parameters&lt;br /&gt;
  where  parameter = &amp;#039;NLS_LENGTH_SEMANTICS&amp;#039;&lt;br /&gt;
         and&lt;br /&gt;
         value = &amp;#039;CHAR&amp;#039;&lt;br /&gt;
  ;&lt;br /&gt;
  --&lt;br /&gt;
  if lv_char_set = 0&lt;br /&gt;
  then&lt;br /&gt;
    dbms_output.put_line(&amp;#039;WARNING: Do not forget to change instance parameter NLS_LENGTH_SEMANTICS to CHAR and restart the database.&amp;#039;);&lt;br /&gt;
  end if;&lt;br /&gt;
end;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORA-14097: column type or size mismatch in ALTER TABLE EXCHANGE PARTITION===&lt;br /&gt;
Also can be &amp;lt;tt&amp;gt;ORA-54033: column to be modified is used in a virtual column expression&amp;lt;/tt&amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;
Nothing especially to do with partitions - just any ddl operation that affects the table.&amp;lt;br /&amp;gt;&lt;br /&gt;
Hidden columns do not normally show up in a desc unless colinvisible is on&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set colinvisible on&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
But these sneaky system-generated ones don&amp;#039;t show up even with that setting on!  You need to show them with this:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set pages 50 lines 1000&lt;br /&gt;
col column_name for a40&lt;br /&gt;
col data_default for a40&lt;br /&gt;
select internal_column_id, column_name, data_default, hidden_column, virtual_column from dba_tab_cols where table_name =&amp;#039;XND40&amp;#039;;&lt;br /&gt;
&lt;br /&gt;
INTERNAL_COLUMN_ID COLUMN_NAME                                        DATA_DEFAULT                                       HIDDEN_COLUM VIRTUAL_COLU&lt;br /&gt;
------------------ -------------------------------------------------- -------------------------------------------------- ------------ ------------&lt;br /&gt;
                35 MONLOT_REC_CDR                                     &amp;#039;0&amp;#039;                                                NO           NO&lt;br /&gt;
                34 MONLOT_REC_DBT                                     &amp;#039;0&amp;#039;                                                NO           NO&lt;br /&gt;
                33 MONLOT_CAL_CDR                                     &amp;#039;0&amp;#039;                                                NO           NO&lt;br /&gt;
                32 MONLOT_CAL_DBT                                     &amp;#039;0&amp;#039;                                                NO           NO&lt;br /&gt;
                31 MONMVT_CPT                                         &amp;#039;0&amp;#039;                                                NO           NO&lt;br /&gt;
                30 SENNOT                                             &amp;#039; &amp;#039;                                                NO           NO&lt;br /&gt;
                29 NUMSEQ                                                                                                NO           NO&lt;br /&gt;
                28 NOMFIC                                                                                                NO           NO&lt;br /&gt;
                27 TOTCPT_REC                                                                                            NO           NO&lt;br /&gt;
                26 TOTCPT_CAL                                                                                            NO           NO&lt;br /&gt;
                25 MONLOT_REC                                                                                            NO           NO&lt;br /&gt;
                24 MONLOT_CAL                                                                                            NO           NO&lt;br /&gt;
                23 NBRELE_REC                                                                                            NO           NO&lt;br /&gt;
                22 NBRELE_CAL                                                                                            NO           NO&lt;br /&gt;
                21 NUMCPT_GLO                                                                                            NO           NO&lt;br /&gt;
                20 DEVLOT                                                                                                NO           NO&lt;br /&gt;
                19 CODERR                                                                                                NO           NO&lt;br /&gt;
                18 CANLOT                                                                                                NO           NO&lt;br /&gt;
                17 REFTEX                                                                                                NO           NO&lt;br /&gt;
                16 REFEXN                                                                                                NO           NO&lt;br /&gt;
                15 ETTLOT                                                                                                NO           NO&lt;br /&gt;
                14 TYPLOT                                                                                                NO           NO&lt;br /&gt;
                13 DATEXC                                                                                                NO           NO&lt;br /&gt;
                12 STALOT                                                                                                NO           NO&lt;br /&gt;
                11 REFLOT                                                                                                NO           NO&lt;br /&gt;
                10 USRAUT                                                                                                NO           NO&lt;br /&gt;
                 9 HEUAUT                                                                                                NO           NO&lt;br /&gt;
                 8 DATAUT                                                                                                NO           NO&lt;br /&gt;
                 7 PGMMAJ                                                                                                NO           NO&lt;br /&gt;
                 6 USRMAJ                                                                                                NO           NO&lt;br /&gt;
                 5 HEUMAJ                                                                                                NO           NO&lt;br /&gt;
                 4 DATMAJ                                                                                                NO           NO&lt;br /&gt;
                 3 DATCRT                                                                                                NO           NO&lt;br /&gt;
                 2 REFMAJ                                                                                                NO           NO&lt;br /&gt;
                 1 NUMVER                                                                                                NO           NO&lt;br /&gt;
                36 SYS_STS#KR2WNV5L070XKV1L5H7REH                     SYS_OP_COMBINED_HASH(&amp;quot;NOMFIC&amp;quot;,&amp;quot;NUMSEQ&amp;quot;)            YES          YES&lt;br /&gt;
&lt;br /&gt;
36 rows selected.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
That last row means extended statistics have been generated for 2 columns in this table.&amp;lt;br /&amp;gt;&lt;br /&gt;
====Solution====&lt;br /&gt;
Drop the extended stats, do what you need to do and recreate the extended stats.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
PROCEDURE DROP_EXTENDED_STATS&lt;br /&gt;
 Argument Name                  Type                    In/Out Default?&lt;br /&gt;
 ------------------------------ ----------------------- ------ --------&lt;br /&gt;
 OWNNAME                        VARCHAR2                IN&lt;br /&gt;
 TABNAME                        VARCHAR2                IN&lt;br /&gt;
 EXTENSION                      VARCHAR2                IN&lt;br /&gt;
&lt;br /&gt;
exec dbms_stats.drop_extended_stats ( &amp;#039;KPK&amp;#039;, &amp;#039;XND40&amp;#039;, &amp;#039;(&amp;quot;NOMFIC&amp;quot;,&amp;quot;NUMSEQ&amp;quot;)&amp;#039; );&lt;br /&gt;
&lt;br /&gt;
create table kpk.xnd40_new as select * from kpk.xnd40 where 1=2;&lt;br /&gt;
&lt;br /&gt;
Table created.&lt;br /&gt;
&lt;br /&gt;
select dbms_stats.create_extended_stats ( &amp;#039;KPK&amp;#039;, &amp;#039;XND40&amp;#039;, &amp;#039;(&amp;quot;NOMFIC&amp;quot;,&amp;quot;NUMSEQ&amp;quot;)&amp;#039; ) from   dual;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The stats columns can also be seen in their own table&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select extension_name, extension from dba_stat_extensions where table_name = upper(&amp;#039;&amp;amp;&amp;amp;table_name.&amp;#039;) and extension_name LIKE &amp;#039;SYS_STS%&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORA-14404: partitioned table contains partitions in a different tablespace===&lt;br /&gt;
As part of an RMAN duplicate with a skip tablespace, this error is produced&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Reenabling controlfile options for auxiliary database&lt;br /&gt;
Executing: alter database enable block change tracking using file &amp;#039;/oracle/acc/ora_data3/adsa1/bct_adsp_do_not_delete.f&amp;#039;&lt;br /&gt;
&lt;br /&gt;
contents of Memory Script:&lt;br /&gt;
{&lt;br /&gt;
   Alter clone database open resetlogs;&lt;br /&gt;
}&lt;br /&gt;
executing Memory Script&lt;br /&gt;
&lt;br /&gt;
database opened&lt;br /&gt;
Dropping offline and skipped tablespaces&lt;br /&gt;
Executing: drop tablespace &amp;quot;ADS_ARCHIVE&amp;quot; including contents cascade constraints&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-03002: failure of Duplicate Db command at 10/16/2017 23:46:12&lt;br /&gt;
RMAN-05501: aborting duplication of target database&lt;br /&gt;
RMAN-06136: ORACLE error from auxiliary database: ORA-14404: partitioned table contains partitions in a different tablespace&lt;br /&gt;
&lt;br /&gt;
Recovery Manager complete.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
and when attempting to backup the database, we get errors&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
RMAN-06169: could not read file header for datafile 188 error reason 1&lt;br /&gt;
RMAN-06169: could not read file header for datafile 189 error reason 1&lt;br /&gt;
RMAN-06169: could not read file header for datafile 190 error reason 1&lt;br /&gt;
RMAN-06169: could not read file header for datafile 191 error reason 1&lt;br /&gt;
RMAN-06169: could not read file header for datafile 14 error reason 1&lt;br /&gt;
released channel: t1&lt;br /&gt;
released channel: t2&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-03002: failure of backup plus archivelog command at 10/17/2017 15:08:40&lt;br /&gt;
RMAN-06056: could not access datafile 14&lt;br /&gt;
&lt;br /&gt;
Recovery Manager complete.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Problem====&lt;br /&gt;
Tables in the tablespace have partitions in another tablespace so this one cannot be dropped.&amp;lt;br /&amp;gt;&lt;br /&gt;
Check which table partitions are in which tablespaces&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 200&lt;br /&gt;
set pagesize 200&lt;br /&gt;
col table_name for a14&lt;br /&gt;
col table_owner for a14&lt;br /&gt;
col partition_name for a14&lt;br /&gt;
select table_owner&lt;br /&gt;
,      table_name&lt;br /&gt;
,      partition_name&lt;br /&gt;
,      tablespace_name&lt;br /&gt;
from   dba_tab_partitions&lt;br /&gt;
where  (table_owner, table_name) in&lt;br /&gt;
       (&lt;br /&gt;
       select table_owner&lt;br /&gt;
       ,      table_name&lt;br /&gt;
       from   dba_tab_partitions x&lt;br /&gt;
       where  x.tablespace_name = &amp;#039;&amp;amp;&amp;amp;TABLESPACE_TO_DROP&amp;#039;&lt;br /&gt;
       and    exists ( select *&lt;br /&gt;
                       from   dba_tab_partitions y&lt;br /&gt;
                       where  x.table_owner = y.table_owner&lt;br /&gt;
                       and    x.table_name  = y.table_name&lt;br /&gt;
                       and    y.tablespace_name not in (&amp;#039;&amp;amp;TABLESPACE_TO_DROP&amp;#039;)&lt;br /&gt;
                       group  by table_owner&lt;br /&gt;
                       ,      table_name&lt;br /&gt;
                     )&lt;br /&gt;
        )&lt;br /&gt;
order by 1,2,partition_position&lt;br /&gt;
/&lt;br /&gt;
undef TABLESPACE_TO_DROP&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
TABLE_OWNER    TABLE_NAME     PARTITION_NAME TABLESPACE_NAME&lt;br /&gt;
-------------- -------------- -------------- ------------------------------&lt;br /&gt;
KPK            XND20          P0910          TS_THALER_PART_OLD&lt;br /&gt;
KPK            XND20          P1112          TS_THALER_PART_OLD&lt;br /&gt;
KPK            XND20          P13            TS_THALER_PART_OLD&lt;br /&gt;
KPK            XND20          P14            TS_THALER_PART_OLD&lt;br /&gt;
KPK            XND20          P15            TS_THALER_PART_OLD&lt;br /&gt;
KPK            XND20          P16            TS_THALER_DATA&lt;br /&gt;
KPK            XND20          P17            TS_THALER_DATA&lt;br /&gt;
KPK            XND20          P18            TS_THALER_DATA&lt;br /&gt;
KPK            XND20          PMAX           TS_THALER_DATA&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Solution====&lt;br /&gt;
If the intention is to keep all the tables then run this query to generate statements to move the relevant tables out of this tablespace&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select &amp;#039;alter table &amp;#039;||b.table_owner||&amp;#039;.&amp;#039;||b.table_name||&amp;#039; move partition &amp;#039;||b.partition_name||&amp;#039; tablespace &amp;amp;NEW_TABLESPACE;&amp;#039;&lt;br /&gt;
from   (&lt;br /&gt;
       select distinct table_name&lt;br /&gt;
       ,      partition_name&lt;br /&gt;
       from   dba_tab_partitions&lt;br /&gt;
       where  tablespace_name = &amp;#039;&amp;amp;&amp;amp;TABLESPACE_NAME&amp;#039;&lt;br /&gt;
       )                  a&lt;br /&gt;
,      dba_tab_partitions b&lt;br /&gt;
where  a.table_name       = b.table_name&lt;br /&gt;
and    b.tablespace_name != &amp;#039;&amp;amp;TABLESPACE_NAME&amp;#039;&lt;br /&gt;
/&lt;br /&gt;
undef TABLESPACE_NAME&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
If however, the intention is to drop the tablespace anyway, the tables need to be dropped before the tablespace can be dropped.&amp;lt;br /&amp;gt;&lt;br /&gt;
But ...tables with partitions in different tablespaces cannot be dropped. The partitions need to be dropped first!&amp;lt;br /&amp;gt;&lt;br /&gt;
Run the following query to generate statements to drop all the &amp;#039;problem&amp;#039; tables. When these have gone, the tablespace can be dropped.&lt;br /&gt;
* drop table partitions&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
spool /tmp/drop_table_partitions.sql&lt;br /&gt;
sqlplus / as sysdba&amp;lt;&amp;lt;EOSQL&lt;br /&gt;
set headi off newpa none feedb off trims on echo off&lt;br /&gt;
select &amp;#039;alter table &amp;#039;||table_owner||&amp;#039;.&amp;#039;||table_name||&amp;#039; drop partition &amp;#039;||partition_name||&amp;#039;;&amp;#039;&lt;br /&gt;
from   dba_tab_partitions&lt;br /&gt;
where  tablespace_name = &amp;#039;$TABLESPACE_NAME&amp;#039;&lt;br /&gt;
/&lt;br /&gt;
spool off&lt;br /&gt;
EOSQL&lt;br /&gt;
echo &amp;quot;@/tmp/drop_table_partitions.sql&amp;quot; | sqlplus / as sysdba&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* drop tables&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sqlplus / as sysdba&amp;lt;&amp;lt;EOSQL&lt;br /&gt;
select &amp;#039;drop table &amp;#039;||table_owner||&amp;#039;.&amp;#039;||table_name||&amp;#039;;&amp;#039;&lt;br /&gt;
from   dba_tab_partitions&lt;br /&gt;
where  tablespace_name = &amp;#039;$TABLESPACE_NAME&amp;#039;&lt;br /&gt;
spool /tmp/drop_tables.sql&lt;br /&gt;
/&lt;br /&gt;
spool off&lt;br /&gt;
EOSQL&lt;br /&gt;
echo &amp;quot;@/tmp/drop_tables.sql&amp;quot; | sqlplus / as sysdba&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* drop tablespace&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
drop tablespace ads_archive including contents and datafiles&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Find all table partitions in tablespaces with missing datafiles====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 1000 pages 100&lt;br /&gt;
col owner for a10&lt;br /&gt;
col segment_name for a40&lt;br /&gt;
col segment_type for a25&lt;br /&gt;
col partition_name for a20&lt;br /&gt;
col tablespace_name for a25&lt;br /&gt;
select owner&lt;br /&gt;
,      segment_name&lt;br /&gt;
,      segment_type&lt;br /&gt;
,      partition_name&lt;br /&gt;
,      tablespace_name&lt;br /&gt;
from   dba_segments&lt;br /&gt;
where  segment_type in (&amp;#039;TABLE PARTITION&amp;#039;, &amp;#039;TABLE SUBPARTITION&amp;#039;)&lt;br /&gt;
and    tablespace_name in (&lt;br /&gt;
                          select tablespace_name&lt;br /&gt;
                          from   dba_data_files&lt;br /&gt;
                          where  file_name like &amp;#039;%MISSING%&amp;#039;&lt;br /&gt;
                          )&lt;br /&gt;
order  by 1, 2, decode (segment_type, &amp;#039;TABLE SUBPARTITION&amp;#039;, 1, 2),4&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Use exchange partition to alter metadata of the tablespaces without moving the actual data====&lt;br /&gt;
* [https://community.oracle.com/thread/581401?start=15&amp;amp;tstart=0 this] is what you are looking for!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Workaround====&lt;br /&gt;
While working on the solution, a backup can be made using the &amp;quot;skip inaccessible&amp;quot; option. Put this in an rman cmdfile...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
connect catalog rmanusr/rmanpwd@rmancat&lt;br /&gt;
connect target sys/syspwd@adsa1&lt;br /&gt;
run {&lt;br /&gt;
allocate channel t1 type &amp;#039;sbt_tape&amp;#039; parms &amp;#039;ENV=(NSR_SERVER=hn6000.company.be,NSR_CLIENT=hn491,NSR_DATA_VOLUME_POOL=DD1DAILY,NSR_END_ERROR_IGNORE=TRUE)&amp;#039;;&lt;br /&gt;
allocate channel t2 type &amp;#039;sbt_tape&amp;#039; parms &amp;#039;ENV=(NSR_SERVER=hn6000.company.be,NSR_CLIENT=hn491,NSR_DATA_VOLUME_POOL=DD1DAILY,NSR_END_ERROR_IGNORE=TRUE)&amp;#039;;&lt;br /&gt;
configure retention policy to recovery window of 28 days;&lt;br /&gt;
configure controlfile autobackup on;&lt;br /&gt;
crosscheck archivelog all;&lt;br /&gt;
SQL &amp;#039;ALTER SYSTEM SWITCH LOGFILE&amp;#039;;&lt;br /&gt;
SQL &amp;#039;CREATE PFILE FROM SPFILE&amp;#039;;&lt;br /&gt;
backup filesperset 1 format &amp;#039;dbfull_%d_%I_%t_%s_%p&amp;#039; full database plus archivelog skip inaccessible delete all input;&lt;br /&gt;
backup current controlfile;&lt;br /&gt;
release channel t1;&lt;br /&gt;
release channel t2;&lt;br /&gt;
}&lt;br /&gt;
exit&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Another way of deleting the offending objects====&lt;br /&gt;
Taken from [http://www.dbarj.com.br/en/2015/01/resume-oracle-duplicate-database-failed-recovery-datafiles/ Recover from a failed RMAN duplicate]&amp;lt;br /&amp;gt;&lt;br /&gt;
Need to check it before running it blindly!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
set echo off feed off termo off trims on pages 0 newpa none lines 2000 headi off long 32000&lt;br /&gt;
col val for a1000&lt;br /&gt;
spool destroy_offending_objects.sql&lt;br /&gt;
&lt;br /&gt;
select to_clob (&amp;#039;alter table &amp;#039;|| table_name||&amp;#039; drop constraint &amp;#039;||constraint_name||&amp;#039;;&amp;#039;) Val&lt;br /&gt;
from user_constraints where constraint_type in (&amp;#039;R&amp;#039;,&amp;#039;P&amp;#039;) and table_name in (select distinct table_name from user_tab_partitions)&lt;br /&gt;
union all&lt;br /&gt;
select to_clob (&amp;#039;drop index &amp;#039;||index_name||&amp;#039;;&amp;#039;) Val from user_indexes where table_name in (select distinct table_name from user_tab_partitions)&lt;br /&gt;
union all&lt;br /&gt;
select to_clob (&amp;#039;alter table &amp;#039;||table_name|| &amp;#039; drop partition &amp;#039;||partition_name||&amp;#039;;&amp;#039;) from dba_tab_partitions&lt;br /&gt;
where tablespace_name in (select tablespace_name from dba_data_files where file_name like &amp;#039;%MISSING%&amp;#039;)&lt;br /&gt;
union all&lt;br /&gt;
Select case&lt;br /&gt;
when instr (VAl, &amp;#039;PARTITION&amp;#039;) = 0 Then&lt;br /&gt;
substr (Val,1,InStr (Val,&amp;#039;)&amp;#039;)+1)||&amp;#039;;&amp;#039;&lt;br /&gt;
else&lt;br /&gt;
substr (Val,1,InStr (Val,&amp;#039;)&amp;#039;)+1)||&amp;#039; local;&amp;#039;&lt;br /&gt;
End val&lt;br /&gt;
from&lt;br /&gt;
(select dbms_metadata.get_ddl (&amp;#039;INDEX&amp;#039;, index_name,&amp;#039;TEST&amp;#039;) Val from user_indexes where table_name in (select distinct table_name from user_tab_partitions))&lt;br /&gt;
union all&lt;br /&gt;
Select Val&lt;br /&gt;
from&lt;br /&gt;
(select dbms_metadata.get_dependent_ddl (&amp;#039;REF_CONSTRAINT&amp;#039;, table_name,&amp;#039;TEST&amp;#039;) Val&lt;br /&gt;
from user_tables where table_name in (select distinct table_name from user_tab_partitions join user_constraints using ( table_name)&lt;br /&gt;
where constraint_type=&amp;#039;R&amp;#039;))&lt;br /&gt;
union all&lt;br /&gt;
select Val&lt;br /&gt;
from&lt;br /&gt;
(select dbms_metadata.get_ddl (&amp;#039;CONSTRAINT&amp;#039;, constraint_name,&amp;#039;TEST&amp;#039;) Val&lt;br /&gt;
from user_constraints&lt;br /&gt;
where constraint_type=&amp;#039;P&amp;#039; and table_name in (select distinct table_name from user_tab_partitions)&lt;br /&gt;
)&lt;br /&gt;
union all&lt;br /&gt;
select to_clob (val)&lt;br /&gt;
from (select distinct &amp;#039;drop tablespace &amp;#039;||tablespace_name|| &amp;#039; including contents and datafiles;&amp;#039; val&lt;br /&gt;
from dba_tab_partitions&lt;br /&gt;
where tablespace_name in (select tablespace_name from dba_data_files where file_name like &amp;#039;%MISSING%&amp;#039;)&lt;br /&gt;
);&lt;br /&gt;
&lt;br /&gt;
spoo off&lt;br /&gt;
&lt;br /&gt;
@destroy_offending_objects&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORA-28112: failed to execute policy function===&lt;br /&gt;
when exporting or importing using [[Data Pump]]&amp;lt; /br&amp;gt;&lt;br /&gt;
During expdp is accompanied by &amp;quot;&amp;#039;&amp;#039;&amp;#039;ORA-31693: Table data object &amp;quot;SYSMAN&amp;quot;.&amp;quot;MGMT_IP_REPORT_DEF&amp;quot; failed to load/unload and is being skipped due to error:&amp;#039;&amp;#039;&amp;#039;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
===Reason===&lt;br /&gt;
This happens due to audit policies being defined on the table but the policy function is defined in another schema.&lt;br /&gt;
&lt;br /&gt;
===Solution===&lt;br /&gt;
Either drop the policy after importing the table with:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
begin&lt;br /&gt;
    for rec in (select * from dba_audit_policies where object_schema = &amp;#039;SYSMAN&amp;#039;) loop&lt;br /&gt;
        dbms_fga.drop_policy(object_schema =&amp;gt; rec.object_schema,&lt;br /&gt;
                             object_name =&amp;gt; rec.object_name,&lt;br /&gt;
                             policy_name =&amp;gt; rec.policy_name);  &lt;br /&gt;
    end loop;&lt;br /&gt;
end;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or exclude the policies during export by adding this to the .par file:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
exclude=FGA_POLICY&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or even better, give the necessary grants to the exporting user...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
grant exempt access policy to impexpusr;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The sysdba role has this automatically.&lt;br /&gt;
===ORA-17629: Cannot connect to the remote database server===&lt;br /&gt;
Active duplication fails to connect even though dns connection exists in tnsnames.ora&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
Problem:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
DUPLICATE TARGET DATABASE FROM ACTIVE DATABASE DORECOVER NOFILENAMECHECK;&lt;br /&gt;
&lt;br /&gt;
RMAN-03002: failure of Duplicate Db command at 05/27/2015 12:52:24&lt;br /&gt;
RMAN-05501: aborting duplication of target database&lt;br /&gt;
RMAN-03015: error occurred in stored script Memory Script&lt;br /&gt;
RMAN-03009: failure of backup command on ORA_DISK_1 channel at 05/27/2015 12:52:23&lt;br /&gt;
ORA-17629: Cannot connect to the remote database server&lt;br /&gt;
ORA-17627: ORA-12154: TNS:could not resolve the connect identifier specified&lt;br /&gt;
&lt;br /&gt;
ORA-17629: Cannot connect to the remote database server&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
Solution:&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
Update the tnsnames.ora of both destination &amp;#039;&amp;#039;&amp;#039;and&amp;#039;&amp;#039;&amp;#039; source ORACLE_HOMEs!&lt;br /&gt;
&lt;br /&gt;
===ORA-01950: no privileges on tablespace &amp;#039;SYSAUX&amp;#039;===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
26-JUN-15 03:12:27.545: &amp;gt;&amp;gt;&amp;gt; ORA-31642: the following SQL statement fails: &lt;br /&gt;
BEGIN &amp;quot;SYS&amp;quot;.&amp;quot;DBMS_RULE_EXP_RULES&amp;quot;.SCHEMA_CALLOUT(:1,0,1,&amp;#039;12.01.00.02.00&amp;#039;); END;&lt;br /&gt;
ORA-01950: no privileges on tablespace &amp;#039;SYSAUX&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Cause:&amp;#039;&amp;#039;&amp;#039;&amp;lt;br /&amp;gt;&lt;br /&gt;
In this case, it seems SYSMAN has no rights to create objects in the SYSAUX tablespace&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Solution:&amp;#039;&amp;#039;&amp;#039;&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter user SYSMAN quota unlimited on sysaux;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
More information [https://support.oracle.com/epmos/faces/SearchDocDisplay?_adf.ctrl-state=bov7jp5pq_4&amp;amp;_afrLoop=547371065896716#SYMPTOM here]&lt;br /&gt;
&lt;br /&gt;
===ORA-39080: failed to create queues &amp;quot;KUPC$C_1_20150616165037&amp;quot; and &amp;quot;KUPC$S_1_20150616165037&amp;quot; for Data Pump job===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
expdp /&lt;br /&gt;
&lt;br /&gt;
Export: Release 11.2.0.4.0 - Production on Tue Jun 16 16:50:36 2015&lt;br /&gt;
&lt;br /&gt;
Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.&lt;br /&gt;
&lt;br /&gt;
Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production&lt;br /&gt;
With the Partitioning, OLAP, Data Mining and Real Application Testing options&lt;br /&gt;
ORA-31626: job does not exist&lt;br /&gt;
ORA-31637: cannot create job SYS_EXPORT_SCHEMA_01 for user OPS$ORAIBM&lt;br /&gt;
ORA-06512: at &amp;quot;SYS.DBMS_SYS_ERROR&amp;quot;, line 95&lt;br /&gt;
ORA-06512: at &amp;quot;SYS.KUPV$FT_INT&amp;quot;, line 798&lt;br /&gt;
[[ORA-39080: failed to create queues &amp;quot;KUPC$C_1_20150616165037&amp;quot; and &amp;quot;KUPC$S_1_20150616165037&amp;quot; for Data Pump job]]&lt;br /&gt;
ORA-06512: at &amp;quot;SYS.DBMS_SYS_ERROR&amp;quot;, line 95&lt;br /&gt;
ORA-06512: at &amp;quot;SYS.KUPC$QUE_INT&amp;quot;, line 1534&lt;br /&gt;
ORA-24002: QUEUE_TABLE SYS.AQ$KUPC$DATAPUMP_QUETAB_1 does not exist&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Cause:====&lt;br /&gt;
Possibly some or all of OLAP module has got itself deinstalled.&lt;br /&gt;
====Solution:====&lt;br /&gt;
Try:&lt;br /&gt;
* Recompiling invalid objects. @?/rdbms/admin/utlrp&lt;br /&gt;
* Reinstalling DBMS_CUBE packages by (re)running catproc.sql. @?/rdbms/admin/catproc followed by @?/rdbms/admin/utlrp&lt;br /&gt;
* Reinstalling OLAP. @?/olap/admin/olap.sql SYSAUX TEMP; But see Metalink note ID 296187.1 for full instructions.&lt;br /&gt;
* Check metalink for bugs. See ID 345198.1 and possibly ID 453796.1&lt;br /&gt;
===ORA-14063: Unusable index exists on unique/primary constraint key===&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;ORA-39083: Object type CONSTRAINT failed to create with error:&amp;#039;&amp;#039;&amp;#039;&amp;lt;br /&amp;gt;&lt;br /&gt;
During an import datapump (impdp), import failed because indexes were in error before the tables were exported. This causes the import of rows to be skipped.&amp;lt;br /&amp;gt;&lt;br /&gt;
If the export cannot be done again (having compiled the indexes), then the metadata can be imported and the indexes compiled before importing the data.&lt;br /&gt;
* Import the metadata&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cat&amp;lt;&amp;lt;EOCAT &amp;gt;impdp_adst_ads_archive_metadata.par&lt;br /&gt;
userid=&amp;#039;/ as sysdba&amp;#039;&lt;br /&gt;
dumpfile=adst_ads_archive.dmp&lt;br /&gt;
logfile=impdp_adst_ads_archive_metadata.log&lt;br /&gt;
content=metadata_only&lt;br /&gt;
EOCAT&lt;br /&gt;
&lt;br /&gt;
impdp parfile=impdp_adst_ads_archive_metadata.par&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Find the bad indexes and recompile them&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select &amp;#039;alter index &amp;#039;|| owner||&amp;#039;.&amp;#039;||index_name||&amp;#039; rebuild online parallel 8;&amp;#039;&lt;br /&gt;
from   dba_indexes&lt;br /&gt;
where  status = &amp;#039;UNUSABLE&amp;#039;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Import the data&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cat&amp;lt;&amp;lt;EOCAT &amp;gt;impdp_adst_ads_archive_data.par&lt;br /&gt;
userid=&amp;#039;/ as sysdba&amp;#039;&lt;br /&gt;
dumpfile=adst_ads_archive.dmp&lt;br /&gt;
logfile=impdp_adst_ads_archive_data.log&lt;br /&gt;
table_exists_action=append&lt;br /&gt;
content=data_only&lt;br /&gt;
EOCAT&lt;br /&gt;
&lt;br /&gt;
impdp parfile=impdp_adst_ads_archive_data.par&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORA-09925: Unable to create audit trail file===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SQL&amp;gt; startup nomount pfile=&amp;quot;/oracle/TRSCRP1/admin/initTRSCRP1.ora&amp;quot;&lt;br /&gt;
ORA-09925: Unable to create audit trail file&lt;br /&gt;
SVR4 Error: 2: No such file or directory&lt;br /&gt;
Additional information: 9925&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
connected to auxiliary database (not started)&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-03002: failure of Duplicate Db command at 08/29/2017 15:53:09&lt;br /&gt;
RMAN-05501: aborting duplication of target database&lt;br /&gt;
RMAN-03015: error occurred in stored script Memory Script&lt;br /&gt;
RMAN-04014: startup failed: ORA-09925: Unable to create audit trail file&lt;br /&gt;
IBM AIX RISC System/6000 Error: 2: No such file or directory&lt;br /&gt;
Additional information: 9925&lt;br /&gt;
&lt;br /&gt;
Recovery Manager complete.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Problem====&lt;br /&gt;
This will be almost certainly one of two issues. Either the directory is not writable by the id that started the instance or the directory just does not exist.&lt;br /&gt;
====Solution====&lt;br /&gt;
Note there can be a difference between what you see when you type:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
show parameter audit&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
and when you type:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
strings -a $ORACLE_HOME/dbs/spfile${ORACLE_SID}.ora | grep -i audit&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
due to someone doing an &amp;quot;alter system&amp;quot; without the &amp;quot;scope=spfile&amp;quot; or &amp;quot;scope=both&amp;quot;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SQL&amp;gt; host ls -al /oracle/TRSCRP1/admin/adump&lt;br /&gt;
SQL&amp;gt; host mkdir /oracle/TRSCRP1/admin/adump&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===ORA-09925: Unable to create audit trail file===&lt;br /&gt;
When starting SQL*Plus with no db processes running (expecting to see &amp;quot;Connected to an idle instance&amp;quot;), we get this:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ERROR:&lt;br /&gt;
ORA-09925: Unable to create audit trail file&lt;br /&gt;
IBM AIX RISC System/6000 Error: 2: No such file or directory&lt;br /&gt;
Additional information: 9925&lt;br /&gt;
ORA-01075: you are currently logged on&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Filesystem permissions are fine&lt;br /&gt;
* &amp;#039;strings spfile&amp;lt;SID&amp;gt;.ora | grep audit&amp;#039; shows the correct directory&lt;br /&gt;
* Running on AIX&lt;br /&gt;
AIX is the clue here... need to check for semaphores and locked shared memory objects&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
(0) UCLID55D oraibm@solax082:/oracle/product/11.2.0.3/bin&amp;gt; sysresv&lt;br /&gt;
&lt;br /&gt;
IPC Resources for ORACLE_SID &amp;quot;UCLID55D&amp;quot; :&lt;br /&gt;
Shared Memory:&lt;br /&gt;
ID              KEY&lt;br /&gt;
8388640         0xffffffff&lt;br /&gt;
579862561       0xffffffff&lt;br /&gt;
384827426       0x326f32e8&lt;br /&gt;
&lt;br /&gt;
Semaphores:&lt;br /&gt;
ID              KEY&lt;br /&gt;
167772287       0xf09f4914&lt;br /&gt;
Oracle Instance alive for sid &amp;quot;UCLID55D&amp;quot;&lt;br /&gt;
&lt;br /&gt;
(0) UCLID55D oraibm@solax082:/oracle/product/11.2.0.3/bin&amp;gt; ipcrm -m 8388640&lt;br /&gt;
(0) UCLID55D oraibm@solax082:/oracle/product/11.2.0.3/bin&amp;gt; ipcrm -m 579862561&lt;br /&gt;
(0) UCLID55D oraibm@solax082:/oracle/product/11.2.0.3/bin&amp;gt; ipcrm -m 384827426&lt;br /&gt;
&lt;br /&gt;
(0) UCLID55D oraibm@solax082:/oracle/product/11.2.0.3/bin&amp;gt; ipcrm -s 167772287&lt;br /&gt;
&lt;br /&gt;
(0) UCLID55D oraibm@solax082:/oracle/product/11.2.0.3/bin&amp;gt; sysresv&lt;br /&gt;
&lt;br /&gt;
IPC Resources for ORACLE_SID &amp;quot;UCLID55D&amp;quot; :&lt;br /&gt;
Shared Memory&lt;br /&gt;
ID              KEY&lt;br /&gt;
No shared memory segments used&lt;br /&gt;
Semaphores:&lt;br /&gt;
ID              KEY&lt;br /&gt;
No semaphore resources used&lt;br /&gt;
Oracle Instance not alive for sid &amp;quot;UCLID55D&amp;quot;&lt;br /&gt;
&lt;br /&gt;
(0) UCLID55D oraibm@solax082:/oracle/product/11.2.0.3/bin&amp;gt; ps -ef | grep UCLID55D&lt;br /&gt;
oraibm 3326 23776 0 14:12:05 pts/1 0:00 grep UCLID55D &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===RMAN-06023: no backup or copy of datafile 1 found to restore===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-03002: failure of Duplicate Db command at 05/16/2018 16:08:13&lt;br /&gt;
RMAN-05501: aborting duplication of target database&lt;br /&gt;
RMAN-05556: not all datafiles have backups that can be recovered to SCN 278250901080&lt;br /&gt;
RMAN-03015: error occurred in stored script Memory Script&lt;br /&gt;
RMAN-06026: some targets not found - aborting restore&lt;br /&gt;
RMAN-06023: no backup or copy of datafile 7 found to restore&lt;br /&gt;
RMAN-06023: no backup or copy of datafile 6 found to restore&lt;br /&gt;
RMAN-06023: no backup or copy of datafile 5 found to restore&lt;br /&gt;
RMAN-06023: no backup or copy of datafile 4 found to restore&lt;br /&gt;
RMAN-06023: no backup or copy of datafile 3 found to restore&lt;br /&gt;
RMAN-06023: no backup or copy of datafile 2 found to restore&lt;br /&gt;
RMAN-06023: no backup or copy of datafile 1 found to restore&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Seems pretty straightforward? SCN was set too early for the retention period. But no, not this time.&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
RMAN&amp;gt; list backup of datafile 1;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
List of Backup Sets&lt;br /&gt;
===================&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
BS Key  Type LV Size       Device Type Elapsed Time Completion Time&lt;br /&gt;
------- ---- -- ---------- ----------- ------------ -------------------&lt;br /&gt;
110170340 Incr 0  132.90G    SBT_TAPE    00:18:32     2018-05-14 01:19:40&lt;br /&gt;
        BP Key: 110170345   Status: AVAILABLE  Compressed: NO  Tag: WEEKLY_FULL&lt;br /&gt;
        Handle: 24639762_REPORTA_07t2r3uk_1_1   Media: V_17152809_77191330&lt;br /&gt;
  List of Datafiles in backup set 110170340&lt;br /&gt;
  File LV Type Ckp SCN    Ckp Time            Name&lt;br /&gt;
  ---- -- ---- ---------- ------------------- ----&lt;br /&gt;
  1    0  Incr 277998128991 2018-05-14 01:01:08 /cln/acc/ora_data3/reporta/system01.dbf&lt;br /&gt;
&lt;br /&gt;
BS Key  Type LV Size       Device Type Elapsed Time Completion Time&lt;br /&gt;
------- ---- -- ---------- ----------- ------------ -------------------&lt;br /&gt;
110355808 Incr 1  204.00M    SBT_TAPE    00:05:13     2018-05-15 01:06:22&lt;br /&gt;
        BP Key: 110355813   Status: AVAILABLE  Compressed: NO  Tag: DAILY_INCREMENTAL&lt;br /&gt;
        Handle: 24661053_REPORTA_3ft2toal_1_1   Media: V_17173010_77253424&lt;br /&gt;
  List of Datafiles in backup set 110355808&lt;br /&gt;
  File LV Type Ckp SCN    Ckp Time            Name&lt;br /&gt;
  ---- -- ---- ---------- ------------------- ----&lt;br /&gt;
  1    1  Incr 278044267395 2018-05-15 01:01:09 /cln/acc/ora_data3/reporta/system01.dbf&lt;br /&gt;
&lt;br /&gt;
BS Key  Type LV Size       Device Type Elapsed Time Completion Time&lt;br /&gt;
------- ---- -- ---------- ----------- ------------ -------------------&lt;br /&gt;
110543802 Incr 1  237.00M    SBT_TAPE    00:05:51     2018-05-16 01:07:40&lt;br /&gt;
        BP Key: 110543807   Status: AVAILABLE  Compressed: NO  Tag: DAILY_INCREMENTAL&lt;br /&gt;
        Handle: 24681602_REPORTA_6nt30cnt_1_1   Media: V_17133646_77315270&lt;br /&gt;
  List of Datafiles in backup set 110543802&lt;br /&gt;
  File LV Type Ckp SCN    Ckp Time            Name&lt;br /&gt;
  ---- -- ---- ---------- ------------------- ----&lt;br /&gt;
  1    1  Incr 278286445856 2018-05-16 01:01:50 /cln/acc/ora_data3/reporta/system01.dbf&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
SCN was only 12 hours ago with a retention of 28 days! The backup piece dated 2018-05-15 01:06:22 is clearly available and on the device type set_tape.&amp;lt;br /&amp;gt;&lt;br /&gt;
The trick here was to look back through the logs and look more closely at what the file restore message was saying...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
channel t0: starting datafile backup set restore&lt;br /&gt;
channel t0: specifying datafile(s) to restore from backup set&lt;br /&gt;
channel t0: restoring datafile 00001 to /cln/acc/ora_data3/reporta/system01.dbf             &amp;lt; &amp;lt; &amp;lt; ==============&lt;br /&gt;
channel t0: reading from backup piece dbfull_REPORTA_738887052_967580186_116_1&lt;br /&gt;
channel t2: ORA-19870: error while restoring backup piece dbfull_REPORTA_738887052_967579750_113_1&lt;br /&gt;
ORA-19507: failed to retrieve sequential file, handle=&amp;quot;dbfull_REPORTA_738887052_967579750_113_1&amp;quot;, parms=&amp;quot;&amp;quot;&lt;br /&gt;
ORA-27029: skgfrtrv: sbtrestore returned error&lt;br /&gt;
ORA-19511: non RMAN, but media manager or vendor specific failure, error text:&lt;br /&gt;
   CreateOraObject20: Job[0] thread[55116090]: Restore: GetBackupInfo() for Archive File[dbfull_REPORTA_738887052_967579750_113_1] failed.&lt;br /&gt;
ORA-0651&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
It was not the fact that it could not find the data on tape, it was that it could not save the file to the location indicated!!&lt;br /&gt;
In the RMAN DUPLICATE script, I had all the file paths redirected (a mixture of convert parameters and spfile set) to a /restore filesystem.&amp;lt;br /&amp;gt;&lt;br /&gt;
But I forgot one!&amp;lt;br /&amp;gt;&lt;br /&gt;
A handy thing to do is to search out the file paths with this to see if something is still wrong:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cd $ORACLE_HOME/dbs&lt;br /&gt;
strings -a spfile${ORACLE_SID}.ora | grep dest&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This should show any paths still not getting caught by the DUPLICATE script.&lt;br /&gt;
&lt;br /&gt;
===RMAN-06136: ORACLE error from auxiliary database: ORA-06502: PL/SQL: numeric or value error===&lt;br /&gt;
When cloning a database, the duplicate fails with this error.&lt;br /&gt;
====Problem====&lt;br /&gt;
This duplicate had no target connection but did have a catalog and auxiliary connection.&lt;br /&gt;
In the catalog (which was the catalog where the target was registerd), there was also an entry in that catalog with the same name as the auxiliary - left over from the days when these 2 instances were Primary and Standby in a Dataguard configuration.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
Datafile 414 skipped by request&lt;br /&gt;
Datafile 415 skipped by request&lt;br /&gt;
Datafile 419 skipped by request&lt;br /&gt;
Datafile 420 skipped by request&lt;br /&gt;
Datafile 421 skipped by request&lt;br /&gt;
&lt;br /&gt;
DBGSQL:     AUXILIARY&amp;gt; begin :ofname := sys.dbms_backup_restore.convertFileName( fname   =&amp;gt;   :ifname, ftype   =&amp;gt;   :iftype, osftype =&amp;gt;   TRUE); end;&lt;br /&gt;
DBGSQL:        sqlcode = 6502&lt;br /&gt;
DBGSQL:         B :ofname = NULL&lt;br /&gt;
DBGSQL:         B :ifname =&lt;br /&gt;
DBGSQL:         B :iftype = 2&lt;br /&gt;
restarting auxiliary database without server parameter file&lt;br /&gt;
Oracle instance started&lt;br /&gt;
&lt;br /&gt;
Total System Global Area   32068440064 bytes&lt;br /&gt;
&lt;br /&gt;
Fixed Size                     2262200 bytes&lt;br /&gt;
Variable Size              16978545480 bytes&lt;br /&gt;
Database Buffers           15032385536 bytes&lt;br /&gt;
Redo Buffers                  55246848 bytes&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-03002: failure of Duplicate Db command at 10/04/2017 14:50:29&lt;br /&gt;
RMAN-05501: aborting duplication of target database&lt;br /&gt;
RMAN-06136: ORACLE error from auxiliary database: ORA-06502: PL/SQL: numeric or value error&lt;br /&gt;
&lt;br /&gt;
Recovery Manager complete.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Solution====&lt;br /&gt;
Connect to the catalog and unregister the name of the auxiliary database. It shouldn&amp;#039;t be there anyway.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rman catalog rmanusr/rmanpwd@rmancat&lt;br /&gt;
&lt;br /&gt;
Recovery Manager: Release 11.2.0.4.0 - Production on Wed Oct 4 15:00:00 2017&lt;br /&gt;
&lt;br /&gt;
Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.&lt;br /&gt;
&lt;br /&gt;
connected to recovery catalog database&lt;br /&gt;
&lt;br /&gt;
RMAN&amp;gt; set dbid 4260753020;&lt;br /&gt;
&lt;br /&gt;
executing command: SET DBID&lt;br /&gt;
database name is &amp;quot;LBK&amp;quot; and DBID is 4260753020&lt;br /&gt;
&lt;br /&gt;
RMAN&amp;gt; list db_unique_name of database;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
List of Databases&lt;br /&gt;
DB Key  DB Name  DB ID            Database Role    Db_unique_name&lt;br /&gt;
------- ------- ----------------- ---------------  ------------------&lt;br /&gt;
13301587 LBK      4260753020       PRIMARY          LBK&lt;br /&gt;
13301587 LBK      4260753020       STANDBY          ACC_PERF&lt;br /&gt;
13301587 LBK      4260753020       STANDBY          LBKRO&lt;br /&gt;
&lt;br /&gt;
RMAN&amp;gt; unregister db_unique_name &amp;#039;ACC_PERF&amp;#039;;&lt;br /&gt;
&lt;br /&gt;
database db_unique_name is &amp;quot;ACC_PERF&amp;quot;, db_name is &amp;quot;LBK&amp;quot; and DBID is 4260753020&lt;br /&gt;
&lt;br /&gt;
Want to unregister the database with target db_unique_name (enter YES or NO)? YES&lt;br /&gt;
database with db_unique_name ACC_PERF unregistered from the recovery catalog&lt;br /&gt;
&lt;br /&gt;
RMAN&amp;gt; exit&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORA-39181: Only partial table data may be exported due to fine grain access control on &amp;quot;owner&amp;quot;.&amp;quot;&amp;lt;table_name&amp;gt;&amp;quot;===&lt;br /&gt;
&lt;br /&gt;
===Reason===&lt;br /&gt;
This happens when applications are designed with fine-grained access.&lt;br /&gt;
===Solution===&lt;br /&gt;
Grant the necessary privileges to the exporting user...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
grant exempt access policy to ops$oraibm;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORA-04030: out of process memory when trying to allocate 2520 bytes===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
expdp problem (ORA-04030: out of process memory when trying to allocate 2520 bytes (pga heap,koh-kghu call heap))&lt;br /&gt;
&lt;br /&gt;
select value from v$pgastat where name=&amp;#039;maximum PGA allocated&amp;#039;;&lt;br /&gt;
&lt;br /&gt;
SHOW PARAMETER TARGET&lt;br /&gt;
&lt;br /&gt;
ORA-04030: out of process memory when trying to allocate 2520 bytes (pga heap,koh-kghu call heap)&lt;br /&gt;
&lt;br /&gt;
alter system reset pga_aggregate_target scope=spfile;&lt;br /&gt;
&lt;br /&gt;
show sga&lt;br /&gt;
&lt;br /&gt;
select * from v$pgastat;&lt;br /&gt;
&lt;br /&gt;
show parameter process&lt;br /&gt;
&lt;br /&gt;
select sum(value)/1024/1024 Mb&lt;br /&gt;
from   v$sesstat s, v$statname n&lt;br /&gt;
where  1=1&lt;br /&gt;
and    n.STATISTIC# = s.STATISTIC#&lt;br /&gt;
and    name = &amp;#039;session pga memory&amp;#039;&lt;br /&gt;
&lt;br /&gt;
show parameter WORKAREA&lt;br /&gt;
&lt;br /&gt;
select value from v$pgastat where name=&amp;#039;maximum PGA allocated&amp;#039;;&lt;br /&gt;
&lt;br /&gt;
alter system set memory_max_target=10G scope=spfile;&lt;br /&gt;
&lt;br /&gt;
alter system set memory_target=3G scope=both;&lt;br /&gt;
&lt;br /&gt;
select * from v$memory_target_advice order by memory_size;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORA-04031: unable to allocate 32 bytes of shared memory (&amp;quot;shared pool&amp;quot;,&amp;quot;select name,online$,contents...&amp;quot;,&amp;quot;KGLH0^e5705bfc&amp;quot;,&amp;quot;kglHeapInitialize:temp&amp;quot;)===&lt;br /&gt;
* [https://blogs.oracle.com/db/entry/ora-4031_troubleshooting ORA-4031 Troubleshooting]&lt;br /&gt;
* [https://support.oracle.com/epmos/faces/DocumentDisplay?_afrLoop=89215376348478&amp;amp;id=396940.1&amp;amp;_afrWindowMode=0&amp;amp;_adf.ctrl-state=u1z0xcppg_4 Troubleshooting and Diagnosing ORA-4031 Error - (Doc ID 396940.1)]&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ORA-04031: unable to allocate  bytes of shared memory (&amp;quot;&amp;quot;,&amp;quot;&amp;quot;,&amp;quot;&amp;quot;,&amp;quot;&amp;quot;) &lt;br /&gt;
ORA-04031: unable to allocate 32 bytes of shared memory (&amp;quot;shared pool&amp;quot;,&amp;quot;select name,online$,contents...&amp;quot;,&amp;quot;KGLH0^e5705bfc&amp;quot;,&amp;quot;kglHeapInitialize:temp&amp;quot;) &lt;br /&gt;
Incident details in: /oracle/diag/rdbms/mape/MAPE/incident/incdir_86754/MAPE_dm00_14221536_i86754.trc &lt;br /&gt;
Wed Jul 31 20:42:50 2013 &lt;br /&gt;
Dumping diagnostic data in directory=[cdmp_20130731204250], requested by (instance=1, osid=14221536 (DM00)), summary=[incident=86753]. &lt;br /&gt;
Wed Jul 31 20:42:51 2013 &lt;br /&gt;
Sweep [inc][86754]: completed &lt;br /&gt;
Sweep [inc][86753]: completed &lt;br /&gt;
Sweep [inc2][86753]: completed &lt;br /&gt;
Wed Jul 31 20:42:57 2013 &lt;br /&gt;
Use ADRCI or Support Workbench to package the incident. &lt;br /&gt;
See Note 411.1 at My Oracle Support for error and packaging details. &lt;br /&gt;
Dumping diagnostic data in directory=[cdmp_20130731204257], requested by (instance=1, osid=14221536 (DM00)), summary=[incident=86754]. &lt;br /&gt;
Wed Jul 31 20:43:35 2013 &lt;br /&gt;
Errors in file /oracle/diag/rdbms/mape/MAPE/trace/MAPE_dw02_40567024.trc  (incident=82993): &lt;br /&gt;
ORA-04031: unable to allocate 32 bytes of shared memory (&amp;quot;shared pool&amp;quot;,&amp;quot;select order#,columns,types ...&amp;quot;,&amp;quot;KGLH0^470434f8&amp;quot;,&amp;quot;kglHeapInitialize:temp&amp;quot;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Database had already crashed so nothing to do but:&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
(0) MAPE ora@x025:/home/ora&amp;gt; sqlplus / as sysdba&lt;br /&gt;
&lt;br /&gt;
SQL*Plus: Release 11.2.0.3.0 Production on Fri Aug 2 14:26:20 2013&lt;br /&gt;
&lt;br /&gt;
Copyright (c) 1982, 2011, Oracle.  All rights reserved.&lt;br /&gt;
&lt;br /&gt;
Connected.&lt;br /&gt;
SYS@MAPE&amp;gt; alter system flush shared_pool;&lt;br /&gt;
alter system flush shared_pool&lt;br /&gt;
*&lt;br /&gt;
ERROR at line 1:&lt;br /&gt;
ORA-01012: not logged on&lt;br /&gt;
Process ID: 0&lt;br /&gt;
Session ID: 0 Serial number: 0&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
SYS@MAPE&amp;gt; shutdown abort&lt;br /&gt;
ORACLE instance shut down.&lt;br /&gt;
SYS@MAPE&amp;gt; startup&lt;br /&gt;
ORACLE instance started.&lt;br /&gt;
&lt;br /&gt;
Total System Global Area  734892032 bytes&lt;br /&gt;
Fixed Size                  2225128 bytes&lt;br /&gt;
Variable Size             398461976 bytes&lt;br /&gt;
Database Buffers          318767104 bytes&lt;br /&gt;
Redo Buffers               15437824 bytes&lt;br /&gt;
Database mounted.&lt;br /&gt;
Database opened.&lt;br /&gt;
&lt;br /&gt;
SYS@MAPE&amp;gt; show parameter pool&lt;br /&gt;
&lt;br /&gt;
NAME                                 TYPE                           VALUE&lt;br /&gt;
------------------------------------ ------------------------------ ------------------------------&lt;br /&gt;
buffer_pool_keep                     string&lt;br /&gt;
buffer_pool_recycle                  string&lt;br /&gt;
global_context_pool_size             string&lt;br /&gt;
java_pool_size                       big integer                    0&lt;br /&gt;
large_pool_size                      big integer                    0&lt;br /&gt;
olap_page_pool_size                  big integer                    0&lt;br /&gt;
shared_pool_reserved_size            big integer                    18M&lt;br /&gt;
shared_pool_size                     big integer                    208M&lt;br /&gt;
streams_pool_size                    big integer                    0&lt;br /&gt;
SYS@MAPE&amp;gt; show sga&lt;br /&gt;
&lt;br /&gt;
Total System Global Area  734892032 bytes&lt;br /&gt;
Fixed Size                  2225128 bytes&lt;br /&gt;
Variable Size             385879064 bytes&lt;br /&gt;
Database Buffers          331350016 bytes&lt;br /&gt;
Redo Buffers               15437824 bytes&lt;br /&gt;
SYS@MAPE&amp;gt; exit&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
but for reference, the causes could well be the applications running on the database are not using bind variables...&amp;lt;br /&amp;gt;&lt;br /&gt;
From [http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:528893984337 asktom.oracle.com]&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
Just to give you a tiny idea of how huge of a difference this &lt;br /&gt;
can make performance wise, you only need to run a very small &lt;br /&gt;
test:&lt;br /&gt;
&lt;br /&gt;
tkyte@TKYTE816&amp;gt; alter system flush shared_pool;&lt;br /&gt;
System altered.&lt;br /&gt;
&lt;br /&gt;
tkyte@TKYTE816&amp;gt; declare&lt;br /&gt;
  2      type rc is ref cursor;&lt;br /&gt;
  3      l_rc rc;&lt;br /&gt;
  4      l_dummy all_objects.object_name%type;&lt;br /&gt;
  5      l_start number default dbms_utility.get_time;&lt;br /&gt;
  6  begin&lt;br /&gt;
  7      for i in 1 .. 1000&lt;br /&gt;
  8      loop&lt;br /&gt;
  9          open l_rc for&lt;br /&gt;
 10          &amp;#039;select object_name&lt;br /&gt;
 11             from all_objects&lt;br /&gt;
 12            where object_id = &amp;#039; || i;&lt;br /&gt;
 13          fetch l_rc into l_dummy;&lt;br /&gt;
 14          close l_rc;&lt;br /&gt;
 15      end loop;&lt;br /&gt;
 16      dbms_output.put_line&lt;br /&gt;
 17      ( round( (dbms_utility.get_time-l_start)/100, 2 ) ||&lt;br /&gt;
 18        &amp;#039; seconds...&amp;#039; );&lt;br /&gt;
 19  end;&lt;br /&gt;
 20  /&lt;br /&gt;
14.86 seconds...&lt;br /&gt;
&lt;br /&gt;
PL/SQL procedure successfully completed.&lt;br /&gt;
&lt;br /&gt;
tkyte@TKYTE816&amp;gt; declare&lt;br /&gt;
  2      type rc is ref cursor;&lt;br /&gt;
  3      l_rc rc;&lt;br /&gt;
  4      l_dummy all_objects.object_name%type;&lt;br /&gt;
  5      l_start number default dbms_utility.get_time;&lt;br /&gt;
  6  begin&lt;br /&gt;
  7      for i in 1 .. 1000&lt;br /&gt;
  8      loop&lt;br /&gt;
  9          open l_rc for&lt;br /&gt;
 10          &amp;#039;select object_name&lt;br /&gt;
 11             from all_objects&lt;br /&gt;
 12            where object_id = :x&amp;#039;&lt;br /&gt;
 13          using i;&lt;br /&gt;
 14          fetch l_rc into l_dummy;&lt;br /&gt;
 15          close l_rc;&lt;br /&gt;
 16      end loop;&lt;br /&gt;
 17      dbms_output.put_line&lt;br /&gt;
 18      ( round( (dbms_utility.get_time-l_start)/100, 2 ) ||&lt;br /&gt;
 19        &amp;#039; seconds...&amp;#039; );&lt;br /&gt;
 20  end;&lt;br /&gt;
 21  /&lt;br /&gt;
1.27 seconds...&lt;br /&gt;
&lt;br /&gt;
PL/SQL procedure successfully completed.&lt;br /&gt;
&lt;br /&gt;
That is pretty dramatic.  The fact is that not only does this &lt;br /&gt;
execute much faster (we spent more time PARSING our queries then &lt;br /&gt;
actually EXECUTING them!) it will let more users use your system &lt;br /&gt;
simultaneously.&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
and from [http://asktom.oracle.com/pls/asktom/f?p=100:11:::::P11_QUESTION_ID:1163635055580 linked question]&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
Lbrary cache latch contention is typically caused by NOT using bind variables.  It is due &lt;br /&gt;
to excessive parsing of statements.&lt;br /&gt;
&lt;br /&gt;
One way to see if this might be the case in your situation is to run a script like:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
create table t1 as select sql_text from v$sqlarea;&lt;br /&gt;
&lt;br /&gt;
alter table t1 add sql_text_wo_constants varchar2(1000);&lt;br /&gt;
&lt;br /&gt;
create or replace function &lt;br /&gt;
remove_constants( p_query in varchar2 ) return varchar2&lt;br /&gt;
as&lt;br /&gt;
    l_query long;&lt;br /&gt;
    l_char  varchar2(1);&lt;br /&gt;
    l_in_quotes boolean default FALSE;&lt;br /&gt;
begin&lt;br /&gt;
    for i in 1 .. length( p_query )&lt;br /&gt;
    loop&lt;br /&gt;
        l_char := substr(p_query,i,1);&lt;br /&gt;
        if ( l_char = &amp;#039;&amp;#039;&amp;#039;&amp;#039; and l_in_quotes )&lt;br /&gt;
        then&lt;br /&gt;
            l_in_quotes := FALSE;&lt;br /&gt;
        elsif ( l_char = &amp;#039;&amp;#039;&amp;#039;&amp;#039; and NOT l_in_quotes )&lt;br /&gt;
        then&lt;br /&gt;
            l_in_quotes := TRUE;&lt;br /&gt;
            l_query := l_query || &amp;#039;&amp;#039;&amp;#039;#&amp;#039;;&lt;br /&gt;
        end if;&lt;br /&gt;
        if ( NOT l_in_quotes ) then&lt;br /&gt;
            l_query := l_query || l_char;&lt;br /&gt;
        end if;&lt;br /&gt;
    end loop;&lt;br /&gt;
    l_query := translate( l_query, &amp;#039;0123456789&amp;#039;, &amp;#039;@@@@@@@@@@&amp;#039; );&lt;br /&gt;
    for i in 0 .. 8 loop&lt;br /&gt;
        l_query := replace( l_query, lpad(&amp;#039;@&amp;#039;,10-i,&amp;#039;@&amp;#039;), &amp;#039;@&amp;#039; );&lt;br /&gt;
        l_query := replace( l_query, lpad(&amp;#039; &amp;#039;,10-i,&amp;#039; &amp;#039;), &amp;#039; &amp;#039; );&lt;br /&gt;
    end loop;&lt;br /&gt;
    return upper(l_query);&lt;br /&gt;
end;&lt;br /&gt;
/&lt;br /&gt;
update t1 set sql_text_wo_constants = remove_constants(sql_text);&lt;br /&gt;
&lt;br /&gt;
select sql_text_wo_constants, count(*)&lt;br /&gt;
  from t1&lt;br /&gt;
 group by sql_text_wo_constants&lt;br /&gt;
having count(*) &amp;gt; 100&lt;br /&gt;
 order by 2&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The output of that last query will show you statements that are identical in the shared &lt;br /&gt;
pool after all numbers and character string constants have been removed.  These &lt;br /&gt;
statements -- and more importantly their counts -- are the potential bottlenecks.  In &lt;br /&gt;
addition to causing the contention, they will be HUGE cpu consumers.  &lt;br /&gt;
&lt;br /&gt;
If you discover your applications do not use bind variables -- you must have this &lt;br /&gt;
corrected.  You&amp;#039;ll never have a good hit ratio if everyone submits &amp;quot;unique&amp;quot; sql.  Your &lt;br /&gt;
shared pool will never be used right and you&amp;#039;ll be using excessive CPU (90% of the time &lt;br /&gt;
it takes to process &amp;quot;insert into t values ( 1 )&amp;quot; is parsing.  If you use &amp;quot;insert into t &lt;br /&gt;
values ( :x )&amp;quot;, and bind the value of 1 -- then the next person that runs that insert &lt;br /&gt;
will benefit from your work and run that much faster. &lt;br /&gt;
...&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Advice from Oracle concerning a concrete (12c) example of unable to allocate 52824 bytes of shared memory (&amp;quot;shared pool&amp;quot;,...====&lt;br /&gt;
This was from a ticket raised for a Data Pump export that consistently failed with:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Processing object type SCHEMA_EXPORT/TABLE/PROCACT_INSTANCE&lt;br /&gt;
Processing object type SCHEMA_EXPORT/TABLE/TABLE&lt;br /&gt;
ORA-39014: One or more workers have prematurely exited.&lt;br /&gt;
ORA-39029: worker 1 with process name &amp;quot;DW00&amp;quot; prematurely terminated&lt;br /&gt;
ORA-31671: Worker process DW00 had an unhandled exception.&lt;br /&gt;
ORA-04031: unable to allocate 52824 bytes of shared memory (&amp;quot;shared pool&amp;quot;,&amp;quot;unknown object&amp;quot;,&amp;quot;KTSL subheap&amp;quot;,&amp;quot;ktsl_load_disp-2&amp;quot;)&lt;br /&gt;
ORA-06512: at &amp;quot;SYS.KUPW$WORKER&amp;quot;, line 2122&lt;br /&gt;
ORA-06512: at line 2&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
The error ORA-4031 on the shared pool can indicate one of two things:&lt;br /&gt;
- insufficient space for the shared pool (so insufficient memory in SGA at that time)&lt;br /&gt;
OR&lt;br /&gt;
- although there is enough memory, it is fragmented and no contiguous chunk can be allocated to satisfy the latest memory request.&lt;br /&gt;
&lt;br /&gt;
Each SGA has a little fragmentation of course because of the operations taking place, so in your case the fragmentation is represented by the 18M of free memory, which exists in uncontiguous chunks.&lt;br /&gt;
This means that the root cause of the error is insufficient contiguous memory to allocate 12312 bytes of shared memory.&lt;br /&gt;
&lt;br /&gt;
ACTION PLAN&lt;br /&gt;
==============&lt;br /&gt;
1. We see memory_target=2000M. This is too little to support a 12c database, even when it has little activity.&lt;br /&gt;
As you may know 1.7G for the SGA was acceptable when speaking of 32bit OSs where it was hardly possible to make use of more than that.&lt;br /&gt;
Since you have a 64 bit system, the addressable memory is virtually unlimited.&lt;br /&gt;
Furthermore, by using AMM (memory_target&amp;gt;0) this memory is divided between the SGA and the PGA (the user processes) which in fact, depending on the number of connections, can limit the SGA even more.&lt;br /&gt;
So the first recommendation is to increase the value of memory_target to 4G for example. There is no ideal value, but this would be a reasonable starting value for tuning.&lt;br /&gt;
&lt;br /&gt;
You can do further tuning of the memory using the view V$MEMORY_TARGET_ADVICE.&lt;br /&gt;
The view V$MEMORY_TARGET_ADVICE provides tuning advice for the MEMORY_TARGET initialization parameter:&lt;br /&gt;
SQL&amp;gt; SELECT * FROM v$memory_target_advice ORDER BY memory_size;&lt;br /&gt;
&lt;br /&gt;
The dynamic performance view V$MEMORY_DYNAMIC_COMPONENTS shows the current sizes of all dynamically tuned memory components, including the total sizes of the SGA and instance PGA.&lt;br /&gt;
&lt;br /&gt;
You can also use V$MEMORY_RESIZE_OPS which has a circular history buffer of the last 800 memory resize requests.&lt;br /&gt;
&lt;br /&gt;
2. Since the AMM (you have memory_target&amp;gt;0) is used, then make sure to set:&lt;br /&gt;
 _shared_pool_reserved_pct to 10 or 15 to ensure that when the Shared Pool grows or shrinks automatically, the Reserved Area will change as well.&lt;br /&gt;
&lt;br /&gt;
SQL&amp;gt; alter system set &amp;quot;_shared_pool_reserved_pct&amp;quot;=15 scope=spfile;&lt;br /&gt;
--restart the instance&lt;br /&gt;
&lt;br /&gt;
FYI: By default, Oracle configures a small Reserved Pool (or Reserved Area) inside the Shared Pool.&lt;br /&gt;
This memory can be used for operations such as PL/SQL and trigger compilation or for temporary space while loading Java objects.&lt;br /&gt;
After the memory allocated from the Reserved Pool is freed, it returns to the Reserved Pool.&lt;br /&gt;
5% of the Shared Pool is set aside as the Reserved Pool to handle allocations of memory higher than defined by the hidden parameter _shared_pool_reserved_pct.&lt;br /&gt;
In some application environments, 5% is too small.&lt;br /&gt;
&lt;br /&gt;
3. Set shared_pool_size=500M or even more. This will represent a minimum amount of memory that will always be available to the shared pool.&lt;br /&gt;
If more memory is needed at any moment, if it is available, it will be allocated to the shared pool over the 500M.&lt;br /&gt;
&lt;br /&gt;
Implement the above steps, monitor the database and let us know the result,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORA-00392: log 1 of thread 1 is being cleared, operation not allowed===&lt;br /&gt;
After performing an active duplication, this happened when trying to open the database.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SQL&amp;gt; alter database open resetlogs&lt;br /&gt;
alter database open resetlogs&lt;br /&gt;
*&lt;br /&gt;
ERROR at line 1:&lt;br /&gt;
ORA-00392: log 1 of thread 1 is being cleared, operation not allowed&lt;br /&gt;
ORA-00312: online log 1 thread 1: &amp;#039;/oracle/oradata/testdb/redo/redo01.log&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SQL&amp;gt; select group#,thread#,status from v$log;&lt;br /&gt;
 &lt;br /&gt;
GROUP#   THREAD#   STATUS&lt;br /&gt;
-------  --------- ----------------&lt;br /&gt;
1        1         CLEARING_CURRENT&lt;br /&gt;
2        1         STALE&lt;br /&gt;
3        1         STALE&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Check the alert log! Always a good idea to get extra info. In here we find the answer&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ORA-00344: unable to re-create online log&lt;br /&gt;
&amp;#039;/oracle/oradata/testdb/redo/redo01.log&amp;#039;&lt;br /&gt;
ORA-27040: file create error, unable to create file&lt;br /&gt;
Linux-x86_64 Error: 2: No such file or directory&lt;br /&gt;
Additional information: 1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
So the clue is that the file cannot be created at the operating system level.&amp;lt;br /&amp;gt;&lt;br /&gt;
Doing a &amp;lt;code&amp;gt;df -k /oracle/oradata/testdb/redo&amp;lt;/code&amp;gt; shows us that the filesystem was created too small for the destination database.&amp;lt;br /&amp;gt;&lt;br /&gt;
In this case, we do not want the redolog directory to be as big as on the source db as there will be almost no movement on the destination.&amp;lt;br /&amp;gt;&lt;br /&gt;
I should have specified the LOGFILE parameter in the DUPLICATE clause to setup new, smaller redolog files.&amp;lt;br /&amp;gt;&lt;br /&gt;
As this duplicate takes over 12 hours, I didn&amp;#039;t want to do it again so I created symbolic links in the redolog directory pointing out to a larger filesystem with more space.&amp;lt;br /&amp;gt;&lt;br /&gt;
This allowed the creation of the redolog files. They can then be resized once the database has been opened.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cd /oracle/oradata/testdb/redo&lt;br /&gt;
ln -s /tmp/redo01.log redo01.log&lt;br /&gt;
ln -s /tmp/redo02.log redo02.log&lt;br /&gt;
ln -s /tmp/redo03.log redo03.log&lt;br /&gt;
&lt;br /&gt;
SQL&amp;gt; alter database open resetlogs&lt;br /&gt;
Database opened.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===RMAN-04004: error from recovery catalog database: ORA-01017: invalid username/password; logon denied===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
oracle@host:/export/home/ora&amp;gt; rman target / catalog catowner/catpass@catdb&lt;br /&gt;
&lt;br /&gt;
Recovery Manager: Release 11.2.0.2.0 - Production on Thu Jun 12 16:51:03 2014&lt;br /&gt;
&lt;br /&gt;
Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.&lt;br /&gt;
&lt;br /&gt;
connected to target database: XXXXRAP1 (DBID=3557010742)&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-00554: initialization of internal recovery manager package failed&lt;br /&gt;
RMAN-04004: error from recovery catalog database: ORA-01017: invalid username/password; logon denied&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This is normally very straight-forward and self-explanatory.&amp;lt;br /&amp;gt;&lt;br /&gt;
The puzzle here is that a connection from SQL*Plus works!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sqlplus catowner/catpass@catdb&lt;br /&gt;
&lt;br /&gt;
SQL*Plus: Release 11.2.0.2.0 Production on Thu Jun 12 16:53:18 2014&lt;br /&gt;
&lt;br /&gt;
Copyright (c) 1982, 2010, Oracle.  All rights reserved.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Connected to:&lt;br /&gt;
Oracle Database 12c Enterprise Edition Release 12.1.0.1.0 - 64bit Production&lt;br /&gt;
With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options&lt;br /&gt;
SQL&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Eventually worked out that the rman binary in the databases ORACLE_HOME on the source machine needed relinking!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cd $ORACLE_HOME/rdbms/lib&lt;br /&gt;
make -f ins_rdbms.mk irman &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORA-00230: operation disallowed: snapshot control file enqueue unavailable===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
waiting for snapshot control file enqueue&lt;br /&gt;
waiting for snapshot control file enqueue&lt;br /&gt;
waiting for snapshot control file enqueue&lt;br /&gt;
waiting for snapshot control file enqueue&lt;br /&gt;
cannot make a snapshot control file&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-03008: error while performing automatic resync of recovery catalog&lt;br /&gt;
ORA-00230: operation disallowed: snapshot control file enqueue unavailable&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
From the doc...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
When RMAN needs to back up or resynchronize from the control file, it first creates a snapshot or consistent image of the control file.&lt;br /&gt;
If one RMAN job is already backing up the control file while another needs to create a new snapshot control file, then you may see the following message:&lt;br /&gt;
&lt;br /&gt;
waiting for snapshot controlfile enqueue&lt;br /&gt;
&lt;br /&gt;
Under normal circumstances, a job that must wait for the control file enqueue waits for a brief interval and then successfully obtains the enqueue.&lt;br /&gt;
RMAN makes up to five attempts to get the enqueue and then fails the job.&lt;br /&gt;
The conflict is usually caused when two jobs are both backing up the control file, and the job that first starts backing up the control file waits for service from the media manager.&lt;br /&gt;
&lt;br /&gt;
To determine which job is holding the conflicting enqueue:&lt;br /&gt;
&lt;br /&gt;
    After you see the first message stating &amp;quot;RMAN-08512: waiting for snapshot controlfile enqueue&amp;quot;, start a new SQL*Plus session on the target database:&lt;br /&gt;
&lt;br /&gt;
    % sqlplus &amp;#039;SYS/oracle@trgt AS SYSDBA&amp;#039;&lt;br /&gt;
&lt;br /&gt;
    Execute the following query to determine which job is causing the wait:&lt;br /&gt;
&lt;br /&gt;
    SELECT s.SID, USERNAME AS &amp;quot;User&amp;quot;, PROGRAM, MODULE, &lt;br /&gt;
           ACTION, LOGON_TIME &amp;quot;Logon&amp;quot;, l.* &lt;br /&gt;
    FROM V$SESSION s, V$ENQUEUE_LOCK l&lt;br /&gt;
    WHERE l.SID = s.SID&lt;br /&gt;
    AND l.TYPE = &amp;#039;CF&amp;#039;&lt;br /&gt;
    AND l.ID1 = 0&lt;br /&gt;
    AND l.ID2 = 2;&lt;br /&gt;
&lt;br /&gt;
    You should see output similar to the following (the output in this example has been truncated):&lt;br /&gt;
&lt;br /&gt;
    SID User Program              Module                    Action           Logon&lt;br /&gt;
    --- ---- -------------------- ------------------------- ---------------- ---------&lt;br /&gt;
      9 SYS  rman@h13 (TNS V1-V3) backup full datafile: c1  0000210 STARTED  21-JUN-01&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
After you have determined which job is creating the enqueue, you can do one of the following:&lt;br /&gt;
&lt;br /&gt;
    Wait until the job creating the enqueue completes&lt;br /&gt;
    Cancel the current job and restart it after the job creating the enqueue completes&lt;br /&gt;
    Cancel the job creating the enqueue&lt;br /&gt;
&lt;br /&gt;
Commonly, enqueue situations occur when a job is writing to a tape drive, but the tape drive is waiting for a new cassette to be inserted.&lt;br /&gt;
If you start a new job in this situation, then you will probably receive the enqueue message because the first job cannot complete until the new tape is loaded.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or more directly...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 2000&lt;br /&gt;
col killer     for a70&lt;br /&gt;
col program    for a20&lt;br /&gt;
col module     for a20&lt;br /&gt;
col action     for a20&lt;br /&gt;
col logon_time for a20&lt;br /&gt;
select &amp;#039;alter system disconnect session &amp;#039;&amp;#039;&amp;#039;||s.sid||&amp;#039;,&amp;#039;||s.serial#||&amp;#039;&amp;#039;&amp;#039; immediate;&amp;#039; killer&lt;br /&gt;
,      username&lt;br /&gt;
,      program&lt;br /&gt;
,      module&lt;br /&gt;
,      action&lt;br /&gt;
,      logon_time&lt;br /&gt;
from   v$session s&lt;br /&gt;
,      v$enqueue_lock l&lt;br /&gt;
where  l.sid  = s.sid&lt;br /&gt;
and    l.type = &amp;#039;cf&amp;#039;&lt;br /&gt;
and    l.id1  = 0&lt;br /&gt;
and    l.id2  = 2&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORA-19511: non RMAN, but media manager or vendor specific failure, error text:===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-03002: failure of Duplicate Db command at 05/01/2018 14:23:09&lt;br /&gt;
RMAN-05501: aborting duplication of target database&lt;br /&gt;
RMAN-03015: error occurred in stored script Memory Script&lt;br /&gt;
ORA-27191: sbtinfo2 returned error&lt;br /&gt;
Additional information: 3586&lt;br /&gt;
ORA-19511: non RMAN, but media manager or vendor specific failure, error text:&lt;br /&gt;
   Unable to connect to NetWorker server &amp;#039;hn6000.cln.be&amp;#039; because &amp;#039;Authentication error; why = Invalid client credential&amp;#039;. (2:10:79)&lt;br /&gt;
&lt;br /&gt;
Recovery Manager complete.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
If this happens, check to see if the nsr daemon is running...&amp;lt;br /&amp;gt;&lt;br /&gt;
Good system:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/home/oracle&amp;gt; ps -ef | grep nsr&lt;br /&gt;
    root  5701836        1   0   Mar 16      - 13:18 /bin/nsrexecd&lt;br /&gt;
  oracle 18809292 22741502   0 15:03:58  pts/0  0:00 grep nsr&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Bad system:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 /home/oracle&amp;gt; ps -ef | grep nsr&lt;br /&gt;
  oracle 14745986 15139292   0 15:03:29  pts/2  0:00 grep nsr&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORA-19554: error allocating device, device type: SBT_TAPE, device name:===&lt;br /&gt;
If using Cygwin...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-03002: failure of backup command at 05/19/2015 12:25:47&lt;br /&gt;
ORA-19554: error allocating device, device type: SBT_TAPE, device name:&lt;br /&gt;
ORA-27000: skgfqsbi: failed to initialize storage subsystem (SBT) layer&lt;br /&gt;
OSD-02534: Message 2534 not found;  product=RDBMS; facility=SOSD&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Check the tdpo.opt file is where you think it is!&lt;br /&gt;
* Check the path to the opt file looks like this (needs to be Windows format):&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
CONFIGURE CHANNEL DEVICE TYPE &amp;#039;SBT_TAPE&amp;#039; FORMAT   &amp;#039;LOG_%d_t%t_s%s_u%U&amp;#039; PARMS  &amp;#039;ENV=(TDPO_OPTFILE=E:\oracle\KITRYD\admin\tdpo.opt)&amp;#039;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Check the content of the opt file is Windows format paths!&lt;br /&gt;
&lt;br /&gt;
===RMAN-20033: control file SEQUENCE# too low===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-03008: error while performing automatic resync of recovery catalog&lt;br /&gt;
===RMAN-20033: control file SEQUENCE# too low===&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
From [https://forums.oracle.com/forums/thread.jspa?threadID=1115969 forums.oracle.com]&amp;lt;br /&amp;gt;&lt;br /&gt;
This error generally happens if an archivelog backup happens while the RMAN database backup is running and if controlfile autobackup is configured.&amp;lt;br /&amp;gt;&lt;br /&gt;
The database backup is usually successful and it is just the controlfile backup that fails.&lt;br /&gt;
===ORA-27302: failure occurred at: slgpn===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
RMAN-03009: failure of Control File and SPFILE Autobackup command on c1 channel at 06/28/2011 18:59:38&lt;br /&gt;
ORA-19715: invalid format %b for generated name&lt;br /&gt;
ORA-27302: failure occurred at: slgpn&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Problem====&lt;br /&gt;
When doing a &amp;quot;&amp;lt;tt&amp;gt;backup as copy database&amp;lt;/tt&amp;gt;&amp;quot;, got these errors after 145 of 147 datafiles had been backed up!&lt;br /&gt;
&lt;br /&gt;
====Investigation====&lt;br /&gt;
I had read [https://oracleedge.wordpress.com/2011/06/29/oracle-rman-03009-ora-19715-ora-27302/ elsewhere] that this could be something to do with the format of the autobackup of the control file so I changed the format as suggested and reran the backup.&amp;lt;br /&amp;gt;&lt;br /&gt;
No luck. It ended exactly the same way after 145 files. I decided to compare the original list of datafiles with those that had been backed up in order to track down the 2 failures. Maybe I could see something odd with them.&amp;lt;br /&amp;gt;&lt;br /&gt;
Sure enough, these 2 files were different... there was a space at the &amp;#039;&amp;#039;&amp;#039;end&amp;#039;&amp;#039;&amp;#039; of the filenames :-)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select &amp;#039;x&amp;#039;||file_name||&amp;#039;x&amp;#039;&lt;br /&gt;
from   dba_data_files&lt;br /&gt;
where  file_name like &amp;#039;% %&amp;#039;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Solution====&lt;br /&gt;
Run the backup of the other 2 datafiles with a different format that did not rely on the filename.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
run {&lt;br /&gt;
    allocate channel c1 device type disk format &amp;#039;/path/to/datafiles/%U&amp;#039;;&lt;br /&gt;
    backup as copy datafile 170;&lt;br /&gt;
    backup as copy datafile 171;&lt;br /&gt;
    backup as copy current controlfile;&lt;br /&gt;
    release channel c1;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The other 145 datafiles were backed up with a format of &amp;#039;/path/to/datafiles/%b&amp;#039; which preserves the filenames so all that needs to be done is rename the other 2 after the backup finishes.&amp;lt;br /&amp;gt;&lt;br /&gt;
If they are going to be used in a restore scenario, they should be renamed in the controlfile also.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter database rename file &amp;#039;/path/to/datafiles/filename_with_a_space_at_end &amp;#039; to &amp;#039;/path/to/datafiles/filename_without_a_space&amp;#039;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===RMAN errors after crosscheck backup and delete noprompt obsolete and delete noprompt expired backup===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
RMAN-06207: WARNING: 3921 objects could not be deleted for SBT_TAPE channel(s) due&lt;br /&gt;
RMAN-06208:          to mismatched status.  Use CROSSCHECK command to fix status&lt;br /&gt;
RMAN-06210: List of Mismatched objects&lt;br /&gt;
RMAN-06211: ==========================&lt;br /&gt;
RMAN-06212:   Object Type   Filename/Handle&lt;br /&gt;
RMAN-06213: --------------- ---------------------------------------------------&lt;br /&gt;
RMAN-06214: Backup Piece    DB_SID_t20140316_s263889_umhp3bpa7_1_1&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Use the FORCE option with the DELETE command&amp;lt;br /&amp;gt;&lt;br /&gt;
The FORCE command tells RMAN to clean the information out of the catalog regardless of whether it can find it on the media or not.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
delete force noprompt expired backup;&lt;br /&gt;
delete force noprompt obsolete;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===RMAN-06004: ORACLE error from recovery catalog database: RMAN-20003: target database incarnation not found in recovery catalog===&lt;br /&gt;
====Problem:====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-03002: failure of Duplicate Db command at 12/05/2017 11:11:15&lt;br /&gt;
RMAN-05501: aborting duplication of target database&lt;br /&gt;
RMAN-03015: error occurred in stored script Memory Script&lt;br /&gt;
RMAN-06004: ORACLE error from recovery catalog database: RMAN-20003: target database incarnation not found in recovery catalog&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Solution:====&lt;br /&gt;
Strangely, this means, in my particular case, that block change tracking is turned on in the target databse and needs turning off in the auxiliary while the DUPLICATE is running.&amp;lt;br /&amp;gt;&lt;br /&gt;
It must be done while the auxiliary is in mount mode and restoring the datafiles (before recovery starts)&amp;lt;br /&amp;gt;&lt;br /&gt;
It is reported to be a bug fixed in 11.1 but somehow, we&amp;#039;re still (sometimes) getting it in 12.1.0.2.&lt;br /&gt;
&lt;br /&gt;
===RMAN-06059: expected archived log not found, loss of archived log compromises recoverability===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
RMAN-06059: expected archived log not found, loss of archived log compromises recoverability&lt;br /&gt;
ORA-19625: error identifying file &amp;lt;filename&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This error can come from the fact that the database files (more likely archivelogs) are being deleted by the operating system so RMAN has no clue of their whereabouts.&amp;lt;br /&amp;gt;&lt;br /&gt;
Possibly result of a database duplication and the catalog has not updated properly?&amp;lt;br /&amp;gt;&lt;br /&gt;
====Solution====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
crosscheck archivelog all;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
And then maybe take a backup to be on the safe side.&lt;br /&gt;
&lt;br /&gt;
===RMAN-05537: DUPLICATE without TARGET connection when auxiliary instance is started with spfile cannot use SPFILE clause===&lt;br /&gt;
====Problem:====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-03002: failure of Duplicate Db command at 12/05/2017 14:17:49&lt;br /&gt;
RMAN-05501: aborting duplication of target database&lt;br /&gt;
RMAN-05537: DUPLICATE without TARGET connection when auxiliary instance is started with spfile cannot use SPFILE clause&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Usually happens after restarting a failed RMAN DUPLICATE database. The spfile has been regenerated on the auxiliary to a level where it has too much detail in it.&lt;br /&gt;
====Solution:====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ cd $ORACLE_HOME/dbs&lt;br /&gt;
$ ls -altr *dwh_perf*&lt;br /&gt;
-rw-r-----    1 oracle   oinstall   17645568 Aug  3 13:34 snapcf_dwh_perf.f&lt;br /&gt;
-rw-r-----    1 oracle   oinstall       7680 Nov  4 09:22 orapwdwh_perf&lt;br /&gt;
-rw-r--r--    1 oracle   oinstall        104 Dec  5 09:34 initdwh_perf.ora&lt;br /&gt;
-rw-r-----    1 oracle   oinstall       6656 Dec  5 11:11 spfiledwh_perf.ora&lt;br /&gt;
-rw-rw----    1 oracle   oinstall       1544 Dec  5 14:18 hc_dwh_perf.dat&lt;br /&gt;
$ mv hc_dwh_perf.dat hc_dwh_perf.dat.old&lt;br /&gt;
$ mv spfiledwh_perf.ora spfiledwh_perf.ora.old&lt;br /&gt;
$ cat initdwh_perf.ora&lt;br /&gt;
sga_max_size=&amp;#039;6G&amp;#039;&lt;br /&gt;
sga_target=&amp;#039;6G&amp;#039;&lt;br /&gt;
compatible=&amp;#039;12.0.0&amp;#039;&lt;br /&gt;
db_files=&amp;#039;500&amp;#039;&lt;br /&gt;
&lt;br /&gt;
# Instance name&lt;br /&gt;
db_name=dwh_perf&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Re-run the DUPLICATE. It should zoom past the already recovered datafiles.&lt;br /&gt;
&lt;br /&gt;
===PSDRPC returns significant error 1013===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
archived log thread=1 sequence=195008&lt;br /&gt;
channel t2: reading from backup piece arclog_LBK_4260753020_946042770_479194_1&lt;br /&gt;
channel t0: piece handle=arclog_LBK_4260753020_946042770_479192_1 tag=TAG20170607T133757&lt;br /&gt;
channel t0: restored backup piece 1&lt;br /&gt;
channel t0: restore complete, elapsed time: 00:00:35&lt;br /&gt;
archived log file name=/xxxxxx/acc/ora_bin2/app/oracle/product/11.2.0.4/dbhome_1/dbs/arch1_195006_815790039.dbf thread=1 sequence=195006&lt;br /&gt;
PSDRPC returns significant error 1013.&lt;br /&gt;
PSDRPC returns significant error 1013.&lt;br /&gt;
released channel: t0&lt;br /&gt;
released channel: t1&lt;br /&gt;
released channel: t2&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-03002: failure of Duplicate Db command at 06/09/2017 15:15:04&lt;br /&gt;
RMAN-05501: aborting duplication of target database&lt;br /&gt;
RMAN-03015: error occurred in stored script Memory Script&lt;br /&gt;
RMAN-11003: failure during parse/execution of SQL statement: alter database recover logfile &amp;#039;/xxxxxx/acc/ora_bin2/app/oracle/product/11.2.0.4/dbhome_1/dbs/arch1_195006_815790039.dbf&amp;#039;&lt;br /&gt;
ORA-10877: error signaled in parallel recovery slave&lt;br /&gt;
&lt;br /&gt;
Recovery Manager complete.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Action====&lt;br /&gt;
Check the alert log on the auxiliary instance.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ORA-279 signalled during: alter database recover logfile &amp;#039;/xxxxxx/acc/ora_bin2/app/oracle/product/11.2.0.4/dbhome_1/dbs/arch1_195005_815790039.dbf&amp;#039;...&lt;br /&gt;
alter database recover logfile &amp;#039;/xxxxxx/acc/ora_bin2/app/oracle/product/11.2.0.4/dbhome_1/dbs/arch1_195006_815790039.dbf&amp;#039;&lt;br /&gt;
Media Recovery Log /xxxxxx/acc/ora_bin2/app/oracle/product/11.2.0.4/dbhome_1/dbs/arch1_195006_815790039.dbf&lt;br /&gt;
Fri Jun 09 07:30:30 2017&lt;br /&gt;
Errors with log /xxxxxx/acc/ora_bin2/app/oracle/product/11.2.0.4/dbhome_1/dbs/arch1_195006_815790039.dbf&lt;br /&gt;
Recovery interrupted!&lt;br /&gt;
Recovered data files to a consistent state at change 238029030495&lt;br /&gt;
Media Recovery failed with error 19755&lt;br /&gt;
Errors in file /xxxxxx/acc/ora_bin2/app/oracle/diag/rdbms/lbkro/lbkro/trace/lbkro_pr00_13108374.trc:&lt;br /&gt;
ORA-00283: recovery session canceled due to errors&lt;br /&gt;
===&amp;gt;ORA-19755: could not open change tracking file&lt;br /&gt;
===&amp;gt;ORA-19750: change tracking file: &amp;#039;/xxxxxx/exp/ora_data2/lbk/data/bct_lbk_do_not_delete.f&lt;br /&gt;
===&amp;gt;ORA-27037: unable to obtain file status&lt;br /&gt;
===&amp;gt;IBM AIX RISC System/6000 Error: 2: No such file or directory&lt;br /&gt;
Additional information: 3&lt;br /&gt;
Fri Jun 09 07:30:36 2017&lt;br /&gt;
ORA-10877 signalled during: alter database recover logfile &amp;#039;/xxxxxx/acc/ora_bin2/app/oracle/product/11.2.0.4/dbhome_1/dbs/arch1_195006_815790039.dbf&amp;#039;...&lt;br /&gt;
Fri Jun 09 14:04:57 2017&lt;br /&gt;
alter database recover logfile &amp;#039;/xxxxxx/acc/ora_bin2/app/oracle/product/11.2.0.4/dbhome_1/dbs/arch1_195006_815790039.dbf&amp;#039;&lt;br /&gt;
Media Recovery Log /xxxxxx/acc/ora_bin2/app/oracle/product/11.2.0.4/dbhome_1/dbs/arch1_195006_815790039.dbf&lt;br /&gt;
Media Recovery failed with error 1112&lt;br /&gt;
ORA-283 signalled during: alter database recover logfile &amp;#039;/xxxxxx/acc/ora_bin2/app/oracle/product/11.2.0.4/dbhome_1/dbs/arch1_195006_815790039.dbf&amp;#039;...&lt;br /&gt;
Fri Jun 09 14:31:20 2017&lt;br /&gt;
Shutting down instance (immediate)&lt;br /&gt;
Shutting down instance: further logons disabled&lt;br /&gt;
Stopping background process MMNL&lt;br /&gt;
Stopping background process MMON&lt;br /&gt;
License high water mark = 49&lt;br /&gt;
ALTER DATABASE CLOSE NORMAL&lt;br /&gt;
ORA-1109 signalled during: ALTER DATABASE CLOSE NORMAL...&lt;br /&gt;
ALTER DATABASE DISMOUNT&lt;br /&gt;
Shutting down archive processes&lt;br /&gt;
Archiving is disabled&lt;br /&gt;
Completed: ALTER DATABASE DISMOUNT&lt;br /&gt;
ARCH: Archival disabled due to shutdown: 1089&lt;br /&gt;
Shutting down archive processes&lt;br /&gt;
Archiving is disabled&lt;br /&gt;
ARCH: Archival disabled due to shutdown: 1089&lt;br /&gt;
Shutting down archive processes&lt;br /&gt;
Archiving is disabled&lt;br /&gt;
Fri Jun 09 14:31:24 2017&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This is a known bug. it is fixed in 11.2.0.3 but... this customer does not apply patches!&lt;br /&gt;
&lt;br /&gt;
====Solution====&lt;br /&gt;
While the DUPLICATE is running (and in MOUNT mode), log on to the auxiliary instance and disable block change tracking.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter database disable block change tracking;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
A documented workaround is to set db_filename_convert parameter in the DUPLICATE clause of the run block but I tried this and it failed again.&amp;lt;br /&amp;gt;&lt;br /&gt;
The obvious solution is to patch the database but...&lt;br /&gt;
&lt;br /&gt;
===Database trigger to capture ORA errors===&lt;br /&gt;
From [http://ora-ssn.blogspot.be/2011/10/trigger-on-database-to-capture-ora.html ora-ssn.blogspot.be]&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
CREATE TABLE stats$error_log (&lt;br /&gt;
        err_dt          TIMESTAMP,&lt;br /&gt;
        db_user         VARCHAR2(30),&lt;br /&gt;
        msg_stack       VARCHAR2(2000),&lt;br /&gt;
        sqltxt          VARCHAR2(1000))&lt;br /&gt;
tablespace users;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Now, create a trigger on the database server.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
CREATE OR REPLACE TRIGGER log_server_errors&lt;br /&gt;
  AFTER SERVERERROR&lt;br /&gt;
  ON DATABASE&lt;br /&gt;
DECLARE&lt;br /&gt;
          v_sqltext VARCHAR2(1000);&lt;br /&gt;
          nl_sqltext ora_name_list_t;&lt;br /&gt;
  BEGIN&lt;br /&gt;
          -- Capture entire error text&lt;br /&gt;
          FOR i IN 1 .. ora_sql_txt(nl_sqltext) LOOP&lt;br /&gt;
            v_sqltext := v_sqltext || nl_sqltext(i);&lt;br /&gt;
          END LOOP;&lt;br /&gt;
          INSERT INTO STATS$ERROR_LOG&lt;br /&gt;
          (err_dt, db_user, msg_stack, sqltxt)&lt;br /&gt;
          VALUES&lt;br /&gt;
          (systimestamp,&lt;br /&gt;
           sys.login_user,&lt;br /&gt;
           dbms_utility.format_error_stack, v_sqltext);&lt;br /&gt;
  END log_server_errors;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORA-19809: limit exceeded for recovery files===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-03009: failure of backup command on ORA_DISK_1 channel at 07/15/2013 10:10:59&lt;br /&gt;
ORA-19809: limit exceeded for recovery files&lt;br /&gt;
ORA-19804: cannot reclaim 274716160 bytes disk space from 1468006400 limit&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    ORA-19809: limit exceeded for recovery files&lt;br /&gt;
    Cause: The limit for recovery files specified by the db_recovery_file_dest_size was exceeded.&lt;br /&gt;
&lt;br /&gt;
    Action: The error is accompanied by 19804. See message 19804 for further details&lt;br /&gt;
&lt;br /&gt;
    ORA-19804: cannot reclaim string bytes disk space from string limit&lt;br /&gt;
    Cause: Oracle cannot reclaim disk space of specified bytes from the DB_RECOVERY_FILE_DEST_SIZE limit.&lt;br /&gt;
&lt;br /&gt;
    Action: There are five possible solutions:&lt;br /&gt;
       1) Take frequent backup of recovery area using RMAN.&lt;br /&gt;
       2) Consider changing RMAN retention policy.&lt;br /&gt;
       3) Consider changing RMAN archivelog deletion policy.&lt;br /&gt;
       4) Add disk space and increase DB_RECOVERY_FILE_DEST_SIZE.&lt;br /&gt;
       5) Delete files from recovery area using RMAN.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The solution here is to increase the value of db_recovery_file_dest_size but it might also indicate a problem with tapes if the archivelogs are being backed up to tape via tdpo.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SYS@DN7&amp;gt; alter system set db_recovery_file_dest_size=4000M scope=both;&lt;br /&gt;
&lt;br /&gt;
System altered.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Looking into int further, saw RMAN parameters missing...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
CONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF 14 DAYS;&lt;br /&gt;
CONFIGURE BACKUP OPTIMIZATION OFF;&lt;br /&gt;
CONFIGURE DEFAULT DEVICE TYPE TO &amp;#039;SBT_TAPE&amp;#039;;&lt;br /&gt;
CONFIGURE CONTROLFILE AUTOBACKUP ON;&lt;br /&gt;
CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE &amp;#039;SBT_TAPE&amp;#039; TO &amp;#039;LOG_%d_controlfile_%F.rman&amp;#039;;&lt;br /&gt;
CONFIGURE DEVICE TYPE &amp;#039;SBT_TAPE&amp;#039; PARALLELISM 1 BACKUP TYPE TO BACKUPSET;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===RMAN-00554: initialization of internal recovery manager package failed===&lt;br /&gt;
Getting this error after migrating a database from one machine to another and attaching to a nice new version 12c catalog on the new server&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Recovery Manager: Release 11.2.0.2.0 - Production on Sat Jun 21 13:16:24 2014&lt;br /&gt;
&lt;br /&gt;
Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.&lt;br /&gt;
&lt;br /&gt;
connected to target database: SPMSUPP1 (DBID=3026014394)&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-00554: initialization of internal recovery manager package failed&lt;br /&gt;
RMAN-04004: error from recovery catalog database: ORA-01017: invalid username/password; logon denied&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
We cannot connect to the catalog via rman but there is no problem if connecting via SQL*Plus!&amp;lt;br /&amp;gt;&lt;br /&gt;
Solution: relink the rman executable.&lt;br /&gt;
===Using AIX commands genld, genkld and slibclean to avoid library file locking errors (libjox) (Doc ID 739963.1)===&lt;br /&gt;
* [https://support.oracle.com/epmos/faces/DocumentDisplay?_afrLoop=206851390914720&amp;amp;id=739963.1&amp;amp;_afrWindowMode=0&amp;amp;_adf.ctrl-state=e0pq23tou_4 Metalink]&lt;br /&gt;
When installing interim (one-off) patches, CPU patches or patchsets, you may encounter some errors with regards to files being locked or oui/opatch being unable to copy files&amp;lt;br /&amp;gt;&lt;br /&gt;
even though the databases, listeners and all other Oracle processes associated with the ORACLE_HOME to be patched were stopped.&amp;lt;br /&amp;gt;&lt;br /&gt;
This could be as result of a process which requires termination or an additional file needing to be unloaded from the system cache.&amp;lt;br /&amp;gt;&lt;br /&gt;
Run following commands to clean up...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
genld -l | grep &amp;lt;ORACLE_HOME&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
If genld returns data then a currently executing process has something open in the ORACLE_HOME directory, therefore terminate the process as required/recommended.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
genkld | grep &amp;lt;ORACLE_HOME&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
If the genkld command  returns a  list of shared objects currently loaded onto the OS system cache then please remove the entries from the OS system cache by running the slibclean command as root user:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/usr/sbin/slibclean&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===ORA-20011: Approximate NDV failed: ORA-29913: error in executing ODCIEXTTABLEOPEN callout===&lt;br /&gt;
This seems to be related to orphaned Datapump tables. Generally seems to be a problem when stats jobs are running during the night (dbms_stats)&amp;lt;br /&amp;gt;&lt;br /&gt;
* Check no datapump jobs are running&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select * from dba_datapump_jobs;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Find orphaned tables&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 2000&lt;br /&gt;
select owner&lt;br /&gt;
,      object_name&lt;br /&gt;
,      object_type&lt;br /&gt;
,      status&lt;br /&gt;
,      to_char(created,&amp;#039;dd-mon-yyyy hh24:mi:ss&amp;#039;) created&lt;br /&gt;
,      to_char(last_ddl_time,&amp;#039;dd-mon-yyyy hh24:mi:ss&amp;#039;) last_ddl_time&lt;br /&gt;
from   dba_objects&lt;br /&gt;
where  1=1&lt;br /&gt;
and    object_name like &amp;#039;ET$%&amp;#039;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Check that  any rows seen are actually external tables&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select owner&lt;br /&gt;
,      table_name&lt;br /&gt;
,      default_directory_name&lt;br /&gt;
,      access_type&lt;br /&gt;
from   dba_external_tables&lt;br /&gt;
order  by 1,2&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Drop the tables if they are not currently being used (no datapump jobs running)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
drop table &amp;amp;&amp;amp;owner..&amp;amp;table_name;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===ORA-01547: warning: RECOVER succeeded but OPEN RESETLOGS would get error below===&lt;br /&gt;
Database is restored and now we want to recover it but we see this...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Starting recover at 24-JUL-15 11:26:19&lt;br /&gt;
&lt;br /&gt;
starting media recovery&lt;br /&gt;
&lt;br /&gt;
unable to find archive log&lt;br /&gt;
archive log thread=1 sequence=69763&lt;br /&gt;
Oracle Error: &lt;br /&gt;
ORA-01547: warning: RECOVER succeeded but OPEN RESETLOGS would get error below&lt;br /&gt;
ORA-01194: file 1 needs more recovery to be consistent&lt;br /&gt;
ORA-01110: data file 1: &amp;#039;/oracle/TRSCRP1/oradata2/system01.dbf&amp;#039;&lt;br /&gt;
&lt;br /&gt;
released channel: c1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This means that although we have restored the database, we are still missing information to complete the recovery. This information is contained in the archived redo logs which must also be restored (from tape if they are no longer on disk)&amp;lt;br /&amp;gt;&lt;br /&gt;
We can see here that we need an archive log with sequence number 69763. But what is the file called and where should it be restored to?&amp;lt;br /&amp;gt;&lt;br /&gt;
For this we can go to SQL*Plus and get the database to tell us&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
recover database using backup controlfile until cancel;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
and cancel straight away.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ORA-00279: change 13796376414661 generated at 07/14/2015 13:20:07 needed for&lt;br /&gt;
thread 1&lt;br /&gt;
ORA-00289: suggestion : /oracle/TRSCRP1/archive/arch_TRSCRP1_1_69763.arc&lt;br /&gt;
ORA-00280: change 13796376414661 for thread 1 is in sequence #69763&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Specify log: {&amp;lt;RET&amp;gt;=suggested | filename | AUTO | CANCEL}&lt;br /&gt;
cancel&lt;br /&gt;
ORA-01547: warning: RECOVER succeeded but OPEN RESETLOGS would get error below&lt;br /&gt;
ORA-01194: file 1 needs more recovery to be consistent&lt;br /&gt;
ORA-01110: data file 1: &amp;#039;/oracle/TRSCRP1/oradata2/system01.dbf&amp;#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
ORA-01112: media recovery not started&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Now we see that we need to find a file called arch_TRSCRP1_1_69763.arc and put it in the directory /oracle/TRSCRP1/archive.&amp;lt;br /&amp;gt;&lt;br /&gt;
This will continue up until the time specified for the recover so restore a whole bunch of them.&amp;lt;br /&amp;gt;&lt;br /&gt;
Repeat the &amp;quot;recover database using backup controlfile until cancel;&amp;quot; command and type AUTO or Enter until you&amp;#039;ve got to where you need to be.&amp;lt;br /&amp;gt;&lt;br /&gt;
Type CANCEL when point is reached and&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter database open resetlogs;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Stuart</name></author>	</entry>

	<entry>
		<id>https://mailnest.com/dbawiki/index.php?title=Oracle_errors&amp;diff=3356</id>
		<title>Oracle errors</title>
		<link rel="alternate" type="text/html" href="https://mailnest.com/dbawiki/index.php?title=Oracle_errors&amp;diff=3356"/>
				<updated>2018-11-03T13:19:51Z</updated>
		
		<summary type="html">&lt;p&gt;Stuart: /* ORA-14097: column type or size mismatch in ALTER TABLE EXCHANGE PARTITION */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;===ORA-00600===&lt;br /&gt;
[https://support.oracle.com/epmos/faces/DocContentDisplay?_afrLoop=397490397952859&amp;amp;id=1092832.1&amp;amp;_afrWindowMode=0&amp;amp;_adf.ctrl-state=184vwc6g3y_4 Master Note for Diagnosing ORA-600 (Doc ID 1092832.1)]&lt;br /&gt;
===ORA-19051: Cannot use fast path insert for this XMLType table===&lt;br /&gt;
Think LD_LIBRARY_PATH on Linux or LIBPATH on AIX.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Export: Release 11.2.0.4.0 - Production on Thu Jun 1 06:41:55 2017&lt;br /&gt;
&lt;br /&gt;
Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.&lt;br /&gt;
&lt;br /&gt;
Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production&lt;br /&gt;
With the Partitioning, OLAP, Data Mining and Real Application Testing options&lt;br /&gt;
Starting &amp;quot;DWH_EXPORT&amp;quot;.&amp;quot;SYS_EXPORT_TABLE_03&amp;quot;:  dwh_export/******** parfile=cadis_foto_export_credit_dba.par&lt;br /&gt;
Estimate in progress using BLOCKS method...&lt;br /&gt;
Processing object type TABLE_EXPORT/TABLE/TABLE_DATA&lt;br /&gt;
Total estimation using BLOCKS method: 64.08 GB&lt;br /&gt;
ORA-39126: Worker unexpected fatal error in KUPW$WORKER.FETCH_XML_OBJECTS []&lt;br /&gt;
ORA-19051: Cannot use fast path insert for this XMLType table&lt;br /&gt;
&lt;br /&gt;
ORA-06512: at &amp;quot;SYS.DBMS_SYS_ERROR&amp;quot;, line 86&lt;br /&gt;
ORA-06512: at &amp;quot;SYS.KUPW$WORKER&amp;quot;, line 9710&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Problem====&lt;br /&gt;
When the 11g DB was started, LD_LIBRARY_PATH and LIBPATH were still pointing to paths in the 10g Home.&lt;br /&gt;
====Solution====&lt;br /&gt;
There may have been some odd values setup in LD_LIBRARY_PATH before the call to oraenv (if oraenv was indeed called!)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
unset LD_LIBRARY_PATH LIBPATH&lt;br /&gt;
export ORACLE_SID=&amp;lt;correct 11g SID&amp;gt;&lt;br /&gt;
. oraenv&lt;br /&gt;
echo $LD_LIBRARY_PATH&lt;br /&gt;
echo $LIBPATH&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
They should now be correct.&lt;br /&gt;
&lt;br /&gt;
===ORA-27092: size of file exceeds file size limit of the process===&lt;br /&gt;
Think ulimit...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Cause: an attempt was made to open a file that exceeds the process&amp;#039;s file size limit (ulimit), additional information shows the current limit (logical blocks) and the size of the file (logical blocks)&lt;br /&gt;
Action: increase the processes file size limit (ulimit) and retry&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
truncate table pibadm.test_ph&lt;br /&gt;
                      *&lt;br /&gt;
Error at line 1 :&lt;br /&gt;
ORA-00604: error ocurred at recursive SQL level 1&lt;br /&gt;
ORA-01116: error in opening database file 2&lt;br /&gt;
ORA-01110: datafile 2 : &amp;#039;/opt/u01/data/PIBQA/UNDO_01.dbf&amp;#039;&lt;br /&gt;
ORA-27092: size of file exceeds file size limit of the process&lt;br /&gt;
Additional information: 262143&lt;br /&gt;
Additional information: 2621441&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Check the fs_size limit for this user in /etc/security/limits&amp;lt;br /&amp;gt;&lt;br /&gt;
Compare this with another user, say oracle. Probably -1 (unlimited)&lt;br /&gt;
&lt;br /&gt;
===SP2-1503: Unable to initialize Oracle call interface===&lt;br /&gt;
When trying to login to the database via SQL*Plus, these messages a displayed&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
hn5118 /home/oracle $sqlplus / as sysdba&lt;br /&gt;
SP2-1503: Unable to initialize Oracle call interface&lt;br /&gt;
SP2-0152: ORACLE may not be functioning properly&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Seems to be a problem unique to AIX (in this case).&amp;lt;br /&amp;gt;&lt;br /&gt;
Check to see what the LIBPATH variable is. It may still contain a path to an old ORACLE_HOME...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
hn5118 /home/oracle $env|grep LIBPATH&lt;br /&gt;
LIBPATH=/oracle/exp/ora_bin1/app/oracle/product/10.2.0/db_1/lib:/oracle/exp/ora_bin1/app/oracle/product/10.2.0/db_1/lib&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Disco! Unset it and rerun.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
hn5118 /home/oracle $unset LIBPATH&lt;br /&gt;
&lt;br /&gt;
hn5118 /home/oracle $sqlplus / as sysdba&lt;br /&gt;
&lt;br /&gt;
SQL*Plus: Release 12.1.0.2.0 Production on Wed Jul 12 17:17:54 2017&lt;br /&gt;
&lt;br /&gt;
Copyright (c) 1982, 2014, Oracle.  All rights reserved.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Connected to:&lt;br /&gt;
Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production&lt;br /&gt;
With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options&lt;br /&gt;
&lt;br /&gt;
SQL&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===UDE-31623: operation generated ORACLE error 31623===&lt;br /&gt;
When using Data pump, get following errors almost immediately:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
UDE-31623: operation generated ORACLE error 31623&lt;br /&gt;
ORA-31623: a job is not attached to this session via the specified handle&lt;br /&gt;
ORA-06512: at &amp;quot;SYS.DBMS_DATAPUMP&amp;quot;, line 3326&lt;br /&gt;
ORA-06512: at &amp;quot;SYS.DBMS_DATAPUMP&amp;quot;, line 4551&lt;br /&gt;
ORA-06512: at line 1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Solution 1:&amp;#039;&amp;#039;&amp;#039;&amp;lt;br /&amp;gt;&lt;br /&gt;
In one case, I simplified the parameter file that was used. Maybe related to Streams Pool size, who knows?!&amp;lt;br /&amp;gt;&lt;br /&gt;
I removed these 2 lines and the export started working:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
compression_algorithm=medium&lt;br /&gt;
logtime=all&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Solution 2:&amp;#039;&amp;#039;&amp;#039;&amp;lt;br /&amp;gt;&lt;br /&gt;
There is a note about this on Metalink, 1080775.1 which suggests that Streams Pool Size needs setting.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
For this DataPump error, you will need to configure the database with some Streams Pool.&lt;br /&gt;
&lt;br /&gt;
Perform the following query to find out how much STREAMS_POOL_SIZE has been allocated&lt;br /&gt;
&lt;br /&gt;
 select * from v$sgainfo;&lt;br /&gt;
 ...&lt;br /&gt;
 Streams Pool Size                               0 Yes&lt;br /&gt;
&lt;br /&gt;
Data Pump now uses Advanced Queuing (AQ) internally, so it can handle job stops/starts/re-starts.  However, AQ using the Streams Pool, where the database currently has the STREAMS_POOL_SIZE set to ZERO.&lt;br /&gt;
&lt;br /&gt;
Manually set the STREAMS_POOL_SIZE (using ALTER SYSTEM or by changing the value in the the PFILE/SPFILE), re-start the database and re-attempt the Data Pump Export.&lt;br /&gt;
&lt;br /&gt;
Alternately, turn on Automatic Shared Memory management (ASMM) by setting SGA_TARGET or MEMORY_TARGET.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
From Oracle Documentation&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Setting the Size Of the Buffer Cache In a Streams Environment&lt;br /&gt;
&lt;br /&gt;
Oracle Data Pump uses Streams functionality to communicate between processes.&lt;br /&gt;
If the SGA_TARGET initialization parameter is set, then the STREAMS_POOL_SIZE initialization parameter is automatically set to a reasonable value.&lt;br /&gt;
If the SGA_TARGET initialization parameter is not set and the STREAMS_POOL_SIZE initialization parameter is not defined,&lt;br /&gt;
then the size of the streams pool automatically defaults to 10% of the size of the shared pool.&lt;br /&gt;
&lt;br /&gt;
When the streams pool is created, the required SGA memory is taken from memory allocated to the buffer cache,&lt;br /&gt;
reducing the size of the cache to less than what was specified by the DB_CACHE_SIZE initialization parameter.&lt;br /&gt;
This means that if the buffer cache was configured with only the minimal required SGA, then Data Pump operations may not work properly.&lt;br /&gt;
A minimum size of 10M is recommended for STREAMS_POOL_SIZE in order to ensure successful Data Pump operations.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORA-00020: maximum number of processes (150) exceeded===&lt;br /&gt;
Check the current resource limits with:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 300&lt;br /&gt;
select * from v$resource_limit;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Unfortunately this limit cannot be increased without a restart.&amp;lt;br /&amp;gt;&lt;br /&gt;
It may be a necessary to increase the limit with&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter system set processes=500 scope=spfile;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
followed by a shutdown/startup&amp;lt;br /&amp;gt;&lt;br /&gt;
Or it may be some user is running away with the limit.&amp;lt;br /&amp;gt;&lt;br /&gt;
Check to see who is running what with:&lt;br /&gt;
[[http://www.mailnest.com/dbawiki/index.php/Handy_scripts#See_what_statements_all_users_are_running See_what_statements_all_users_are_running]]&lt;br /&gt;
===ORA-01555: snapshot too old: rollback segment number nn with name &amp;quot;xxx&amp;quot; too small===&lt;br /&gt;
* [http://dfitzjarrell.wordpress.com/2008/02/22/the-dreaded-ora-01555/ Good explanation of why it happens]&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
====Problem====&lt;br /&gt;
A long running transaction has run out of space to store its read-consistent image&lt;br /&gt;
&lt;br /&gt;
====Solution 1====&lt;br /&gt;
If it&amp;#039;s a one-off, maybe leave it alone. It may have been a user leaving a session open overnight without committing or rolling back.&lt;br /&gt;
&lt;br /&gt;
====Solution 2====&lt;br /&gt;
Make sure there&amp;#039;s enough space to allow the transaction to finish.&lt;br /&gt;
&lt;br /&gt;
====Things to check====&lt;br /&gt;
How much undo did the biggest transaction take?&lt;br /&gt;
What is the undo retention parameter set to?&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 200&lt;br /&gt;
col name        for a30&lt;br /&gt;
col description for a50&lt;br /&gt;
col value       for a20&lt;br /&gt;
col maxquerylen for 999999&lt;br /&gt;
select p.name&lt;br /&gt;
,      p.description&lt;br /&gt;
,      p.value&lt;br /&gt;
,      max(u.maxquerylen) maxquerylen&lt;br /&gt;
from   v$parameter p&lt;br /&gt;
,      v$undostat  u&lt;br /&gt;
where  1=1&lt;br /&gt;
and    p.name = &amp;#039;undo_retention&amp;#039;&lt;br /&gt;
group  by p.name&lt;br /&gt;
,      p.description&lt;br /&gt;
,      p.value;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Set the retention to about 20% bigger than the maxquerylen.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select &amp;#039;alter system set undo_retention=&amp;#039;||round(1.2*max(maxquerylen))||&amp;#039; scope=both;&amp;#039; &amp;quot;Run this&amp;quot; from v$undostat;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
and set the undo retention guarantee (being aware of the consequences)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select tablespace_name&lt;br /&gt;
,      retention&lt;br /&gt;
from   dba_tablespaces;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter tablespace &amp;amp;undo_ts_name retention guarantee;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Optimise Oracle UNDO Parameters===&lt;br /&gt;
&lt;br /&gt;
The ideal undo_retention would be enough to hold rollback for the longest transaction that happened so far (can&amp;#039;t see into the future)&amp;lt;br /&amp;gt;&lt;br /&gt;
So current undo_retention = current value of undo / (db_block_size * undo blocks per sec)&amp;lt;br /&amp;gt;&lt;br /&gt;
* Undo Blocks per Second&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SELECT MAX(undoblks/((end_time-begin_time)*3600*24)) &amp;quot;UNDO_BLOCKS_PER_SEC&amp;quot;&lt;br /&gt;
FROM   v$undostat;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Optimal Undo Retention&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
col actual for 9999999999.99 heading &amp;quot;ACTUAL UNDO SIZE [MByte]&amp;quot;&lt;br /&gt;
col retent for 9999999999    heading &amp;quot;UNDO RETENTION [Sec]&amp;quot;&lt;br /&gt;
col needed for 9999999999.99 heading &amp;quot;NEEDED UNDO SIZE [Secs]&amp;quot;&lt;br /&gt;
&lt;br /&gt;
SELECT d.undo_size/(1024*1024) actual,&lt;br /&gt;
       to_number(SUBSTR(e.value,1,25)) retent,&lt;br /&gt;
       ROUND((d.undo_size / (to_number(f.value) *&lt;br /&gt;
       g.undo_block_per_sec))) needed&lt;br /&gt;
  FROM (&lt;br /&gt;
       SELECT SUM(a.bytes) undo_size&lt;br /&gt;
          FROM v$datafile a,&lt;br /&gt;
               v$tablespace b,&lt;br /&gt;
               dba_tablespaces c&lt;br /&gt;
         WHERE c.contents = &amp;#039;UNDO&amp;#039;&lt;br /&gt;
           AND c.status = &amp;#039;ONLINE&amp;#039;&lt;br /&gt;
           AND b.name = c.tablespace_name&lt;br /&gt;
           AND a.ts# = b.ts#&lt;br /&gt;
       ) d,&lt;br /&gt;
       v$parameter e,&lt;br /&gt;
       v$parameter f,&lt;br /&gt;
       (&lt;br /&gt;
       SELECT MAX(undoblks/((end_time-begin_time)*3600*24))&lt;br /&gt;
              undo_block_per_sec&lt;br /&gt;
         FROM v$undostat&lt;br /&gt;
       ) g&lt;br /&gt;
WHERE e.name = &amp;#039;undo_retention&amp;#039;&lt;br /&gt;
  AND f.name = &amp;#039;db_block_size&amp;#039;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Calculate Needed UNDO Size for given Database Activity&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
col actual for 9999999999.99 heading &amp;quot;ACTUAL UNDO SIZE [MByte]&amp;quot;&lt;br /&gt;
col retent for 9999999999    heading &amp;quot;UNDO RETENTION [Sec]&amp;quot;&lt;br /&gt;
col needed for 9999999999.99 heading &amp;quot;NEEDED UNDO SIZE [MByte]&amp;quot;&lt;br /&gt;
&lt;br /&gt;
SELECT d.undo_size/(1024*1024) actual&lt;br /&gt;
,      to_number(SUBSTR(e.value,1,25)) retent&lt;br /&gt;
,      (TO_NUMBER(e.value) * TO_NUMBER(f.value) *&lt;br /&gt;
       g.undo_block_per_sec) / (1024*1024)  needed&lt;br /&gt;
  FROM (&lt;br /&gt;
       SELECT SUM(a.bytes) undo_size&lt;br /&gt;
         FROM v$datafile a,&lt;br /&gt;
              v$tablespace b,&lt;br /&gt;
              dba_tablespaces c&lt;br /&gt;
        WHERE c.contents = &amp;#039;UNDO&amp;#039;&lt;br /&gt;
          AND c.status = &amp;#039;ONLINE&amp;#039;&lt;br /&gt;
          AND b.name = c.tablespace_name&lt;br /&gt;
          AND a.ts# = b.ts#&lt;br /&gt;
       ) d,&lt;br /&gt;
      v$parameter e,&lt;br /&gt;
       v$parameter f,&lt;br /&gt;
       (&lt;br /&gt;
       SELECT MAX(undoblks/((end_time-begin_time)*3600*24))&lt;br /&gt;
         undo_block_per_sec&lt;br /&gt;
         FROM v$undostat&lt;br /&gt;
       ) g&lt;br /&gt;
 WHERE e.name = &amp;#039;undo_retention&amp;#039;&lt;br /&gt;
  AND f.name = &amp;#039;db_block_size&amp;#039;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
It might be that the Export still fails with ORA-01555 even though retention seems long enough.&amp;lt;br /&amp;gt;&lt;br /&gt;
Are you running an export with the flashback_time parameter? If so, the undo_retention should be longer than the total export running time!&amp;lt;br /&amp;gt;&lt;br /&gt;
===Check LOB undo retention===&lt;br /&gt;
The retention settings for LOBS is different for the rest of the database.&amp;lt;br /&amp;gt;&lt;br /&gt;
When you change the UNDO_RETENTION parameter, the LOB segment’s retention value is NOT modified.&amp;lt;br /&amp;gt;&lt;br /&gt;
If you query the RETENTION column of the DBA_LOBS view, you will notice the old UNDO_RETENTION value still remains after you have modified the UNDO_RETENTION parameter.&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SQL&amp;gt; show parameter undo_&lt;br /&gt;
&lt;br /&gt;
NAME                                 TYPE        VALUE&lt;br /&gt;
------------------------------------ ----------- ------------------------------&lt;br /&gt;
undo_management                      string      AUTO&lt;br /&gt;
undo_retention                       integer     36000&lt;br /&gt;
undo_tablespace                      string      UNDOTBS1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SQL&amp;gt; desc SITEADMIN.AUDIT_LOG_MESSAGE&lt;br /&gt;
 Name                                      Null?    Type&lt;br /&gt;
 ----------------------------------------- -------- ----------------------------&lt;br /&gt;
 AUDIT_LOG_MESSAGE_ID                      NOT NULL NUMBER&lt;br /&gt;
 AUDIT_LOG_ID                              NOT NULL NUMBER&lt;br /&gt;
 SEQUENCE                                           NUMBER&lt;br /&gt;
 MESSAGE                                            CLOB&lt;br /&gt;
 CREATE_DATE                                        TIMESTAMP(6)&lt;br /&gt;
 COMPONENT_ID                                       VARCHAR2(50 CHAR)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 300&lt;br /&gt;
col column_name for a32&lt;br /&gt;
select table_name,column_name, pctversion,retention from dba_lobs where owner=&amp;#039;&amp;amp;table_owner&amp;#039;;&lt;br /&gt;
&lt;br /&gt;
TABLE_NAME                COLUMN_NAME                    PCTVERSION  RETENTION&lt;br /&gt;
------------------------- ------------------------------ ---------- ----------&lt;br /&gt;
EMAIL_STORE               CONTENT                                 0&lt;br /&gt;
EMAIL_STORE_ATTACHEMENT   ATTACHEMENT                             0&lt;br /&gt;
TRACKING                  ORIGINAL_MESSAGE                                 900&lt;br /&gt;
TRACKING                  MESSAGE                                          900&lt;br /&gt;
TRACKING                  SIEBEL_MESSAGE                                   900&lt;br /&gt;
WISE_WMS_LOG              WISE_WMS_XML                                     900&lt;br /&gt;
ATTACHMENT                ORIGINAL_MESSAGE                                 900&lt;br /&gt;
PLAN_TABLE                OTHER_XML                                        900&lt;br /&gt;
AUDIT_LOG_MESSAGE         MESSAGE                                          900&lt;br /&gt;
EXCEPTIONS                STACK_TRACE                                      900&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
To change the LOB segment’s RETENTION value to match the new UNDO_RETENTION value, do the following:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ALTER TABLE my_table MODIFY LOB (lob_column) (PCTVERSION 20);&lt;br /&gt;
ALTER TABLE my_table MODIFY LOB (lob_column) (RETENTION);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
By momentarily changing the LOB to use PCTVERSION and then back to RETENTION, the new value of UNDO_RETENTION will be used.&amp;lt;br /&amp;gt;&lt;br /&gt;
You need to do this for all LOB segments that you intend to modify.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select &amp;#039;ALTER TABLE &amp;#039;||owner||&amp;#039;.&amp;#039;||table_name||&amp;#039; MODIFY LOB (&amp;#039;||column_name||&amp;#039;) (PCTVERSION 20);&amp;#039; from dba_lobs where owner=&amp;#039;TIBCO&amp;#039;&lt;br /&gt;
&lt;br /&gt;
select &amp;#039;ALTER TABLE &amp;#039;||owner||&amp;#039;.&amp;#039;||table_name||&amp;#039; MODIFY LOB (&amp;#039;||column_name||&amp;#039;) (RETENTION);&amp;#039;     from dba_lobs where owner=&amp;#039;TIBCO&amp;#039;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
There is a table DBA_LOBS that displays information about all the LOB columns in the database, but it doesn&amp;#039;t actually store any LOB data, just metadata. The actual LOB segments in the database have system-generated names that take the form SYS_LOB*identifier*$$.&lt;br /&gt;
For example if you identify a segment named SYS_LOBidentifier$$ that is consuming space, you can find out what column of what table that LOB column maps to using the DBA_LOBS table:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 1000&lt;br /&gt;
col owner       for a20&lt;br /&gt;
col table_name  for a32&lt;br /&gt;
col column_name for a32&lt;br /&gt;
select owner&lt;br /&gt;
,      table_name&lt;br /&gt;
,      column_name&lt;br /&gt;
from   dba_lobs&lt;br /&gt;
where  1=1&lt;br /&gt;
and    segment_name = &amp;#039;SYS_LOB&amp;lt;&amp;lt;identifier&amp;gt;&amp;gt;$$&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====The Undo Advisor PL/SQL Interface====&lt;br /&gt;
You can activate the Undo Advisor by creating an undo advisor task through the advisor framework.&amp;lt;br /&amp;gt;&lt;br /&gt;
The following example creates an undo advisor task to evaluate the undo tablespace. The name of the advisor is &amp;#039;Undo Advisor&amp;#039;.&amp;lt;br /&amp;gt;&lt;br /&gt;
The analysis is based on Automatic Workload Repository snapshots, which you must specify by setting parameters START_SNAPSHOT and END_SNAPSHOT.&amp;lt;br /&amp;gt;&lt;br /&gt;
In the following example, the START_SNAPSHOT is &amp;quot;1&amp;quot; and END_SNAPSHOT is &amp;quot;2&amp;quot;.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
DECLARE&lt;br /&gt;
   tid    NUMBER;&lt;br /&gt;
   tname  VARCHAR2(30);&lt;br /&gt;
   oid    NUMBER;&lt;br /&gt;
BEGIN&lt;br /&gt;
   DBMS_ADVISOR.CREATE_TASK(&amp;#039;Undo Advisor&amp;#039;, tid, tname, &amp;#039;Undo Advisor Task&amp;#039;);&lt;br /&gt;
   DBMS_ADVISOR.CREATE_OBJECT(tname, &amp;#039;UNDO_TBS&amp;#039;, null, null, null, &amp;#039;null&amp;#039;, oid);&lt;br /&gt;
   DBMS_ADVISOR.SET_TASK_PARAMETER(tname, &amp;#039;TARGET_OBJECTS&amp;#039;, oid);&lt;br /&gt;
   DBMS_ADVISOR.SET_TASK_PARAMETER(tname, &amp;#039;START_SNAPSHOT&amp;#039;, 1);&lt;br /&gt;
   DBMS_ADVISOR.SET_TASK_PARAMETER(tname, &amp;#039;END_SNAPSHOT&amp;#039;, 2);&lt;br /&gt;
   DBMS_ADVISOR.SET_TASK_PARAMETER(tname, &amp;#039;INSTANCE&amp;#039;, 1);&lt;br /&gt;
   DBMS_ADVISOR.execute_task(tname);&lt;br /&gt;
        END;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
After you have created the advisor task, you can view the output and recommendations in the Automatic Database Diagnostic Monitor in Enterprise Manager.&amp;lt;br /&amp;gt;&lt;br /&gt;
This information is also available in the DBA_ADVISOR_* data dictionary views (DBA_ADVISOR_TASKS, DBA_ADVISOR_OBJECTS, DBA_ADVISOR_FINDINGS, DBA_ADVISOR_RECOMMENDATIONS, and so on).&lt;br /&gt;
====References====&lt;br /&gt;
* [http://www.akadia.com/services/ora_optimize_undo.html akadia.com]&lt;br /&gt;
* [http://dfitzjarrell.wordpress.com/2008/02/22/the-dreaded-ora-01555/ the dreaded ora-01555]&lt;br /&gt;
* [http://docs.oracle.com/cd/B28359_01/server.111/b28310/undo004.htm#ADMIN11469 docs.oracle.com]&lt;br /&gt;
&lt;br /&gt;
===Error 6 initializing SQL*Plus===&lt;br /&gt;
Using sqlplus or rman under Cygwin, ORACLE_HOME still needs to be windows format!&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Message file sp1&amp;lt;lang&amp;gt;.msb not found&lt;br /&gt;
SP2-0750 :You may need to set ORACLE_HOME to your Oracle software directory&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
so...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
export ORACLE_SID=KITRYD&lt;br /&gt;
ORAENV_ASK=NO&lt;br /&gt;
. oraenv&lt;br /&gt;
[[ &amp;quot;`uname`&amp;quot; == CYGWIN* ]] &amp;amp;&amp;amp; ORACLE_HOME=`cygpath -w ${ORACLE_HOME}`&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===ORA-2002: error while writing to audit trail===&lt;br /&gt;
Check the space left in the audit tablespace with:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select sum(bytes)/1024/1024 mb from dba_free_space where tablespace_name =&amp;#039;AUDIT_DT&amp;#039;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
If plenty of space, it can be due to Oracle clearing out the recyclebin at the same time.&amp;lt;br /&amp;gt;&lt;br /&gt;
If not, extend the datafile...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select * from dba_data_files where tablespace_name =&amp;#039;AUDIT_DT&amp;#039;;&lt;br /&gt;
alter database datafile 6 resize 30G;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
If that is not possible, clean out some audit data or add a datafile.&lt;br /&gt;
&lt;br /&gt;
===ORA-00449: background process &amp;#039;CKPT&amp;#039; unexpectedly terminated with error 7446===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SQL&amp;gt; startup nomount pfile=&amp;quot;/oracle/TRSCRP1/admin/initTRSCRP1.ora&amp;quot;&lt;br /&gt;
ORA-00449: background process &amp;#039;CKPT&amp;#039; unexpectedly terminated with error 7446&lt;br /&gt;
ORA-07446: sdnfy: bad value &amp;#039;&amp;#039; for parameter .&lt;br /&gt;
SQL&amp;gt; exit&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Solution&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SQL&amp;gt; mkdir /oracle/TRSCRP1/admin/bdump /oracle/TRSCRP1/admin/cdump&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORA-00845: MEMORY_TARGET not supported on this system===&lt;br /&gt;
* Reference: [http://arjudba.blogspot.be/2009/01/ora-00845-memorytarget-not-supported-on.html arjudba.blogspot.be]&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Problem Description&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SQL&amp;gt; STARTUP&lt;br /&gt;
ORA-00845: MEMORY_TARGET not supported on this system&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Cause&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
* Starting from Oracle 11g the automatic memory management feature is now defined with parameter MEMORY_TARGET and MEMMORY_MAX_TARGET.&lt;br /&gt;
* On linux file system the shared memory need to be mounted on /dev/shm directory on the operating system.&lt;br /&gt;
* And the size of /dev/shm needs to be greater than MEMORY_TARGET or MEMMORY_MAX_TARGET.&lt;br /&gt;
* The AMM (Automatic Memory Management) now in 11g manages both SGA and PGA together by MMAN process.&lt;br /&gt;
* The MEMORY_TARGET parameter in 11g comes for (SGA_TARGET+PGA_AGGREGATE_TARGET) which was in 10g.&lt;br /&gt;
* And MEMORY_MAX_TARGET parameter in 11g comes instead of SGA_MAX_TARGET parameter which was in 10g.&lt;br /&gt;
* The ORA-00845:can arises for the following two reasons on linux system.&lt;br /&gt;
1)If the shared memory which is mapped to /dev/shm directory is less than the size of MEMORY_TARGET or MEMORY_MAX_TARGET or&lt;br /&gt;
2)If the shared memory is not mapped to /dev/shm directory.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Solution&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Make sure /dev/shm is properly mounted. You can see it by,&lt;br /&gt;
#df -h or #df -k command.&lt;br /&gt;
The output should be similar to:&lt;br /&gt;
&lt;br /&gt;
$ df -k&lt;br /&gt;
Filesystem            Size  Used Avail Use% Mounted on&lt;br /&gt;
...&lt;br /&gt;
shmfs                 1G    512M 512M  50% /dev/shm&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
We see here for /dev/shm we have assigned 1G memory. Now if you set MEMORY_TARGET more than 1G then above ORA-845 will arise. For example if you have MEMORY_TARGET or MEMORY_MAX_TARGET set to 12G then you can mount shared memory to 13g like below.&lt;br /&gt;
As a root user,&lt;br /&gt;
# mount -t tmpfs shmfs -o size=13g /dev/shm&lt;br /&gt;
In order to make the settings persistence so that it will affect after restarting machine add an entry in /etc/fstab similar to the following:&lt;br /&gt;
&lt;br /&gt;
shmfs /dev/shm tmpfs size=13g 0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORA-24247: network access denied by access control list (ACL)===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Cause: No access control list (ACL) has been assigned to the target host or the privilege necessary to access the target host has not been granted to the user in the access control list.&lt;br /&gt;
&lt;br /&gt;
Action: Ensure that an access control list (ACL) has been assigned to the target host and the privilege necessary to access the target host has been granted to the user.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Your application will encounter an ORA-24247 error if it relies on one of the network packages and no proper ACL has been created. For the use of the following packages it is mandatory to have an ACL for the application user in place in 11g:&lt;br /&gt;
*UTL_TCP&lt;br /&gt;
*UTL_SMTP&lt;br /&gt;
*UTL_MAIL&lt;br /&gt;
*UTL_HTTP&lt;br /&gt;
*UTL_INADDR&lt;br /&gt;
Here is a very good explanation of how to setup the necessary ACLs: [[http://blog.whitehorses.nl/2010/03/17/oracle-11g-access-control-list-and-ora-24247/ whitehorses.nl]]&lt;br /&gt;
&lt;br /&gt;
===ORA-00600: internal error code, arguments: [qmx: no ref]===&lt;br /&gt;
Search &amp;quot;Master Note for Oracle XML Database (XDB) Install / Deinstall (Doc ID 1292089.1)&amp;quot; for more info.&lt;br /&gt;
====Problem:====&lt;br /&gt;
Sometimes one or more of the following errors can be encountered when installing or upgrading XDB, configuring APEX, running an Export, or selecting from xdb.xdb$resource or sys.dba_network_acls:&amp;lt;br /&amp;gt;&lt;br /&gt;
* ORA-31159: XML DB is in an invalid state&lt;br /&gt;
* ORA-00600: internal error code, arguments: [unable to load XDB library]&lt;br /&gt;
* ORA-00600: internal error code, arguments: [qmx: no ref]&lt;br /&gt;
* ORA-00600: internal error code, arguments: [qmtGetColumnInfo1]&lt;br /&gt;
* ORA-00600: internal error code, arguments: [qmtb_init_len]&lt;br /&gt;
* ORA-00600: internal error code, arguments: [qmtGetBaseType]&lt;br /&gt;
* ORA-00600: internal error code, arguments: [psdnop-1], [600]&lt;br /&gt;
* ORA-00600: internal error code, arguments: [qmtInit1]&lt;br /&gt;
* ORA-07445: exception encountered: core dump [_memcpy()+224] [SIGSEGV] [Address not mapped to object]&lt;br /&gt;
* ORA-19051 Cannot Use Fast Path Insert For This XMLType Table&lt;br /&gt;
* ORA-31011: XML parsing failed&lt;br /&gt;
Errors of this sort generally occur when the init routines for the internal XDB functions are run in an invalid environment causing memory corruption.&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
This can happen if the database was ever started with the LD_LIBRARY_PATH (LIBPATH for AIX or SHLIB_PATH for HP) pointing to the wrong $ORACLE_HOME/lib directory rather than to the correct location for the instance.&amp;lt;br /&amp;gt;&lt;br /&gt;
The LD_LIBRARY_PATH/LIBPATH/SHLIB_PATH environment variable is used to resolve the location of the shared library &amp;quot;libxdb.so (libxdb.sl on HP)&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
====Solution:====&lt;br /&gt;
* Stop Listener&lt;br /&gt;
* Stop database&lt;br /&gt;
* Ensure $ORACLE_HOME/lib is at the start of LD_LIBRARY_PATH / LIBPATH / SHLIB_PATH&lt;br /&gt;
* If AIX, run /usr/sbin/slibclean as root&lt;br /&gt;
* Start database&lt;br /&gt;
* Start listener&lt;br /&gt;
&lt;br /&gt;
===ORA-00201: control file version nn.nn.nn.nn incompatible with ORACLE version===&lt;br /&gt;
Trying to restore a database after complete failure&amp;lt;br /&amp;gt;&lt;br /&gt;
first step is to startup the database in nomount mode and restore the controlfile - succeeded.&amp;lt;br /&amp;gt;&lt;br /&gt;
second step, startup the database in mount mode ready for database restore...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SQL*Plus: Release 10.2.0.3.0 - Production on Wed Aug 19 18:16:47 2015&lt;br /&gt;
&lt;br /&gt;
Copyright (c) 1982, 2006, Oracle.  All Rights Reserved.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Connected to:&lt;br /&gt;
Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - 64bit Production&lt;br /&gt;
With the Partitioning, OLAP and Data Mining options&lt;br /&gt;
&lt;br /&gt;
SYS@CODWHP1&amp;gt; startup mount&lt;br /&gt;
ORACLE instance started.&lt;br /&gt;
&lt;br /&gt;
Total System Global Area  260046848 bytes&lt;br /&gt;
Fixed Size                  2029296 bytes&lt;br /&gt;
Variable Size             113248528 bytes&lt;br /&gt;
Database Buffers          134217728 bytes&lt;br /&gt;
Redo Buffers               10551296 bytes&lt;br /&gt;
ORA-00201: control file version 10.2.0.0.0 incompatible with ORACLE version 10.2.0.3.0&lt;br /&gt;
ORA-00202: control file: &amp;#039;/oracle/CODWHP1/product/10203/dbs/cntrlCODWHP1.dbf&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The problem was there was no compatible parameter in the simple init file I used to start up the instance.&amp;lt;br /&amp;gt;&lt;br /&gt;
Adding compatible parameter to init file to be same version (10.2.0.3) allowed the db to mount.&lt;br /&gt;
&lt;br /&gt;
===TNS-00525: Insufficient privilege for operation===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
lsnrctl start LISTENER_UCLID55V&lt;br /&gt;
&lt;br /&gt;
LSNRCTL for IBM/AIX RISC System/6000: Version 11.2.0.3.0 - Production on 26-MAR-2015 13:36:14&lt;br /&gt;
&lt;br /&gt;
Copyright (c) 1991, 2011, Oracle.  All rights reserved.&lt;br /&gt;
&lt;br /&gt;
Starting /oracle/product/11.2.0.3/bin/tnslsnr: please wait...&lt;br /&gt;
&lt;br /&gt;
TNSLSNR for IBM/AIX RISC System/6000: Version 11.2.0.3.0 - Production&lt;br /&gt;
System parameter file is /oracle/product/11.2.0.3/network/admin/listener.ora&lt;br /&gt;
Log messages written to /oracle/product/diag/tnslsnr/solax082/listener_uclid55v/alert/log.xml&lt;br /&gt;
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=150.251.114.238)(PORT=1525)))&lt;br /&gt;
Error listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC1525)))&lt;br /&gt;
TNS-12555: TNS:permission denied&lt;br /&gt;
 TNS-12560: TNS:protocol adapter error&lt;br /&gt;
  TNS-00525: Insufficient privilege for operation&lt;br /&gt;
   IBM/AIX RISC System/6000 Error: 1: Not owner&lt;br /&gt;
&lt;br /&gt;
Listener failed to start. See the error message(s) above...&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This would suggest the user attempting to start the listener has no access to either the Oracle binaries or the TNS listener/tnsnames files.&amp;lt;br /&amp;gt;&lt;br /&gt;
But... checkout the /tmp/.oracle directory :-)&amp;lt;br /&amp;gt;&lt;br /&gt;
That hidden gem shows who started the listener last time. Delete the relevant entry and try again!&amp;lt;br /&amp;gt;&lt;br /&gt;
To start from a clean sheet, stop all listeners, delete this directory and restart the listeners.&lt;br /&gt;
&lt;br /&gt;
===ORA-12003: materialized view or zonemap &amp;quot;KPK&amp;quot;.&amp;quot;EVD01_NEW&amp;quot; does not exist===&lt;br /&gt;
Here&amp;#039;s one you shouldn&amp;#039;t see very often.&amp;lt;br /&amp;gt;&lt;br /&gt;
Trying to drop a tablespace but prevented from doing so because a materialized view has referential contraints on a table in this tablespace.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SQL&amp;gt; drop tablespace TS_THALER_PART_OLD including contents and datafiles cascade constraints;&lt;br /&gt;
drop tablespace TS_THALER_PART_OLD including contents and datafiles cascade constraints&lt;br /&gt;
*&lt;br /&gt;
ERROR at line 1:&lt;br /&gt;
ORA-00604: error occurred at recursive SQL level 1&lt;br /&gt;
ORA-12083: must use DROP MATERIALIZED VIEW to drop &amp;quot;KPK&amp;quot;.&amp;quot;EVD01_NEW&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Ok, nice of Oracle to tell us what we have to do. Simple enough. Let&amp;#039;s drop the materialized view.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SQL&amp;gt; DROP MATERIALIZED VIEW &amp;quot;KPK&amp;quot;.&amp;quot;EVD01_NEW&amp;quot;;&lt;br /&gt;
DROP MATERIALIZED VIEW &amp;quot;KPK&amp;quot;.&amp;quot;EVD01_NEW&amp;quot;&lt;br /&gt;
*&lt;br /&gt;
ERROR at line 1:&lt;br /&gt;
ORA-12003: materialized view or zonemap &amp;quot;KPK&amp;quot;.&amp;quot;EVD01_NEW&amp;quot; does not exist&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Aah. Not so obvious then.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
desc &amp;quot;KPK&amp;quot;.&amp;quot;EVD01_NEW&amp;quot;&lt;br /&gt;
 Name                                      Null?    Type&lt;br /&gt;
 ----------------------------------------- -------- ----------------------------&lt;br /&gt;
 DATMAJ                                             VARCHAR2(8 CHAR)&lt;br /&gt;
 HEUMAJ                                             VARCHAR2(8 CHAR)&lt;br /&gt;
 PGMMAJ                                             VARCHAR2(6 CHAR)&lt;br /&gt;
 NATOPN                                             VARCHAR2(6 CHAR)&lt;br /&gt;
 REFEXN                                             VARCHAR2(50 CHAR)&lt;br /&gt;
 SWIOLN                                             VARCHAR2(1 CHAR)&lt;br /&gt;
 STAEVT                                             VARCHAR2(4 CHAR)&lt;br /&gt;
 REFEVT                                             VARCHAR2(16 CHAR)&lt;br /&gt;
 NUMIDT                                             VARCHAR2(30 CHAR)&lt;br /&gt;
 ORIEVT                                             VARCHAR2(10 CHAR)&lt;br /&gt;
 REFLOG                                             VARCHAR2(16 CHAR)&lt;br /&gt;
 MSGEVT_CPL                                         VARCHAR2(1500 CHAR)&lt;br /&gt;
 REFOPN                                             VARCHAR2(16 CHAR)&lt;br /&gt;
 DATEVT                                             VARCHAR2(8 CHAR)&lt;br /&gt;
 MSGEVT_FIL_1                                       VARCHAR2(2000 CHAR)&lt;br /&gt;
 MSGEVT_FIL_2                                       VARCHAR2(2000 CHAR)&lt;br /&gt;
 MSGEVT_SPE                                         VARCHAR2(200 CHAR)&lt;br /&gt;
 DATEFF                                             VARCHAR2(8 CHAR)&lt;br /&gt;
 TMSTMP                                             VARCHAR2(15 CHAR)&lt;br /&gt;
 VEREVT                                             VARCHAR2(3 CHAR)&lt;br /&gt;
 MSGEVT_FIL_3                                       VARCHAR2(2000 CHAR)&lt;br /&gt;
 MSGEVT_FIL_4                                       VARCHAR2(2000 CHAR)&lt;br /&gt;
 TYPEVT                                             VARCHAR2(5 CHAR)&lt;br /&gt;
 SBP_CODAPP                                         VARCHAR2(10 CHAR)&lt;br /&gt;
 SBP_REFINT                                         VARCHAR2(36 CHAR)&lt;br /&gt;
 SBP_TYPACT                                         VARCHAR2(2 CHAR)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
It exists... but as a table.&amp;lt;br /&amp;gt;&lt;br /&gt;
Something has gone wrong in the database somewhere. As it turns out after some deeper investigation, this database is a copy of production but &amp;quot;with modifications&amp;quot;.&amp;lt;br /&amp;gt;&lt;br /&gt;
After the cloning process, a schema needed renaming. Oracle have a procedure for this but it is very long-winded and time-consuming. It uses export and import with transportable tablespaces to do the remap of the schema.&amp;lt;br /&amp;gt;&lt;br /&gt;
An unsupported workaround to rename schema is to simply update the username in sys.user$ and restart the database.&amp;lt;br /&amp;gt;&lt;br /&gt;
This works for the most part but now we see a consequence of that action.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
col owner      for a30&lt;br /&gt;
col mview_name for a30&lt;br /&gt;
select owner&lt;br /&gt;
,      mview_name&lt;br /&gt;
from   dba_mviews&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
OWNER                          MVIEW_NAME&lt;br /&gt;
------------------------------ ------------------------------&lt;br /&gt;
EPK                            EVD01_NEW&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Ahaa, there&amp;#039;s the materialized view but the owner is different from the one described by the database error message above. This one is the owner as it was on production.&amp;lt;br /&amp;gt;&lt;br /&gt;
This means the owner of materialized views has been denormalised for some reason. Reading the (complex) view text of dba_mviews, we see the owner column is based on sys.snap$.sowner&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
col sowner for a20&lt;br /&gt;
col vname  for a20&lt;br /&gt;
col tname  for a20&lt;br /&gt;
select sowner&lt;br /&gt;
,      vname&lt;br /&gt;
,      tname&lt;br /&gt;
from   sys.snap$&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
SOWNER               VNAME                TNAME&lt;br /&gt;
-------------------- -------------------- --------------------&lt;br /&gt;
EPK                  EVD01_NEW            EVD01_NEW&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
For future reference when updating the username in sys.user$, update the snapshot owner in this table as well!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
update sys.snap$&lt;br /&gt;
set    sowner = &amp;#039;KPK&amp;#039;&lt;br /&gt;
where  sowner = &amp;#039;EPK&amp;#039;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Try again&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
DROP MATERIALIZED VIEW &amp;quot;KPK&amp;quot;.&amp;quot;EVD01_NEW&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
Materialized view dropped.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
yep, and the tablespace?&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
drop tablespace TS_THALER_PART_OLD including contents and datafiles cascade constraints;&lt;br /&gt;
&lt;br /&gt;
Tablespace dropped.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORA-12162: TNS:net service name is incorrectly specified===&lt;br /&gt;
Probably nothing to do with TNS. Check your ORACLE_SID is set correctly!&lt;br /&gt;
&lt;br /&gt;
===ORA-00054: resource busy and acquire with NOWAIT specified===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SELECT O.OBJECT_NAME, S.SID, S.SERIAL#, P.SPID, S.PROGRAM,S.USERNAME,&lt;br /&gt;
S.MACHINE,S.PORT , S.LOGON_TIME,SQ.SQL_FULLTEXT &lt;br /&gt;
FROM V$LOCKED_OBJECT L, DBA_OBJECTS O, V$SESSION S, &lt;br /&gt;
V$PROCESS P, V$SQL SQ &lt;br /&gt;
WHERE L.OBJECT_ID = O.OBJECT_ID &lt;br /&gt;
AND L.SESSION_ID = S.SID AND S.PADDR = P.ADDR &lt;br /&gt;
AND S.SQL_ADDRESS = SQ.ADDRESS;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select object_name, s.sid, s.serial#, p.spid &lt;br /&gt;
from v$locked_object l, dba_objects o, v$session s, v$process p&lt;br /&gt;
where l.object_id = o.object_id and l.session_id = s.sid and s.paddr = p.addr;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
then&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter system kill session &amp;#039;sid,serial#&amp;#039;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORA-12518: TNS:listener could not hand off client connection===&lt;br /&gt;
The database you are trying to connect to is probably on its knees. Check server memory is not exhausted.&lt;br /&gt;
&lt;br /&gt;
===ORA-12520: TNS:listener could not find available handler for requested type of server===&lt;br /&gt;
Strangely this could be related to number of processes being exhausted.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
show parameter processes&lt;br /&gt;
alter system set processes=350 scope=spfile;&lt;br /&gt;
shutdown immediate&lt;br /&gt;
startup&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORA-12541: TNS: no listener===&lt;br /&gt;
Either very basic - start the listener!&amp;lt;br /&amp;gt;&lt;br /&gt;
or, as in our case - not so obvious.&amp;lt;br /&amp;gt;&lt;br /&gt;
We use virtual IP addresses so that the IP address stays the same after failover to standby.&amp;lt;br /&amp;gt;&lt;br /&gt;
Due to some confused configuration, we got the network adapter on two different servers to have the same IP address.&amp;lt;br /&amp;gt;&lt;br /&gt;
Stop the IP address on the bad server (assign another one) and all is fine again.&lt;br /&gt;
===ORA-12514: TNS:listener does not currently know of service===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
lsnrctl status &amp;lt;listener_name&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Been altering tnsnames.ora or listener.ora?&lt;br /&gt;
* Check the local_listener parameter&lt;br /&gt;
Try resetting it to itself. Strange but if you are not using port 1521, this can work wonders!&amp;lt;br /&amp;gt;&lt;br /&gt;
Assuming listener is called LISTENER_WM9T:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter system set local_listener=LISTENER_WM9T scope=both;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Try and connect with the service name or directly with&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sqlplus &amp;#039;sys/*******&amp;#039;@&amp;lt;host&amp;gt;:&amp;lt;port&amp;gt;/&amp;lt;SID&amp;gt; as sysdba&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Excellent description of how Oracle TNS listeners work and a checklist on how to fix this error&amp;lt;br /&amp;gt;&lt;br /&gt;
* [[http://edstevensdba.wordpress.com/2011/03/19/ora-12514/ TNS — Ed Stevens]]&lt;br /&gt;
&lt;br /&gt;
===ORA-12547: TNS lost contact===&lt;br /&gt;
&lt;br /&gt;
If&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sqlplus &amp;lt;user&amp;gt;/&amp;lt;pass&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
fails with above error, try&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sqlplus &amp;lt;user&amp;gt;/&amp;lt;pass&amp;gt;@&amp;lt;db connection&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
If this works, it is most probably a permissions error.&amp;lt;br /&amp;gt;&lt;br /&gt;
Re-run the&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ORACLE_HOME/root.sh&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
script that was run as part of the original installation. This will reset the permissions on some important files.&lt;br /&gt;
===ORA-02374: conversion error loading table &amp;quot;BLENGADM&amp;quot;.&amp;quot;ZZ_EVTCTA&amp;quot;===&lt;br /&gt;
This is typical of importing data with Datapump when the tables in the source database were created with &amp;quot;byte&amp;quot; semantics and the destination is &amp;quot;char&amp;quot; semantics.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ORA-02374: conversion error loading table &amp;quot;BLENGADM&amp;quot;.&amp;quot;ZZ_EVTCTA&amp;quot;&lt;br /&gt;
ORA-12899: value too large for column NOMCTA (actual: 257, maximum: 256)&lt;br /&gt;
&lt;br /&gt;
ORA-02372: data for row: NOMCTA : 0X&amp;#039;4C6976726574206427E9706172676E65202020202020202020&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Problem====&lt;br /&gt;
The root cause is the nls_length_semantics of the table columns being BYTE where one character is assigned one byte. But after conversion in a multi-byte database, one character is larger than one byte (could be 2, 3 or 4) and no longer fits.&lt;br /&gt;
====Solution====&lt;br /&gt;
* import the metadata&lt;br /&gt;
Run the impdp command with content=metadata_only. This will create all the tables (still in their original form) but not the data.&lt;br /&gt;
* alter the BYTE columns in the affected tables to CHAR semantics&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select column_name&lt;br /&gt;
,      char_used&lt;br /&gt;
,      data_length&lt;br /&gt;
,      data_type &lt;br /&gt;
from   user_tab_columns &lt;br /&gt;
where  table_name = &amp;#039;T&amp;#039;&lt;br /&gt;
and    char_used = &amp;#039;B&amp;#039;;&lt;br /&gt;
COLUMN_NAME  C DATA_LENGTH DATA_TYPE&lt;br /&gt;
------------ - ----------- ---------&lt;br /&gt;
X            B           1 VARCHAR2&lt;br /&gt;
SQL&amp;gt; alter table t modify x varchar2(1 char);&lt;br /&gt;
Table altered.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Import the data&lt;br /&gt;
Rerun the impdp ensuring table_exists_action is not REPLACE (use truncate or append). This now imports the data into the modified tables.&lt;br /&gt;
====This script does the donkey work of altering table column semantics from byte to char====&lt;br /&gt;
The author of this script is unknown but he/she deserves a medal. It saves countless hours of work and is so well written.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/*&lt;br /&gt;
  The script converts all the VARCHAR2 columns in the user&amp;#039;s schema&lt;br /&gt;
  to CHAR length semantics. Known to work on 10.2.0.4 and later.&lt;br /&gt;
  &lt;br /&gt;
  Script must be executed against the database without any other client&lt;br /&gt;
  and/or application connections to the affected schema.&lt;br /&gt;
  &lt;br /&gt;
  Oracle does not support CHAR semantics for the built-in schemas,&lt;br /&gt;
  like SYS, SYSTEM or SYSMAN, so the script will throw an error,&lt;br /&gt;
  if attempt to run it against any one of them.&lt;br /&gt;
  &lt;br /&gt;
  Upon completion database objects that have dependencies on tables&lt;br /&gt;
  being modified will be invalidated. Oracle usually re-compiles invalidated&lt;br /&gt;
  objects on the first access. Alternatively, a DBA can execute UTLPRP script&lt;br /&gt;
  to recompile all invalid objects in the entire database.&lt;br /&gt;
  &lt;br /&gt;
  Upon completion, please make sure that NLS_LENGTH_SEMANTICS instance parameter&lt;br /&gt;
  is set to CHAR to ensure further upgradability of the schema.&lt;br /&gt;
*/&lt;br /&gt;
set serveroutput on size unlimited format wrap&lt;br /&gt;
declare&lt;br /&gt;
  type sql_list_t is table of varchar2(32767) index by pls_integer;&lt;br /&gt;
  type idx_list_t is table of user_indexes.index_name%type index by pls_integer;&lt;br /&gt;
  type col_list_t is table of user_tab_columns%rowtype index by pls_integer;&lt;br /&gt;
  --&lt;br /&gt;
  lv_col_cnt   pls_integer := 0;&lt;br /&gt;
  lv_idx_cnt   pls_integer := 0;&lt;br /&gt;
  lv_char_set  pls_integer := 0; &lt;br /&gt;
  lv_user      user_users.username%type;&lt;br /&gt;
  lv_sql_stmt  varchar2(32767);&lt;br /&gt;
  lv_byte_cols col_list_t;&lt;br /&gt;
  lv_idx_names idx_list_t;&lt;br /&gt;
  lv_idx_ddls  sql_list_t;&lt;br /&gt;
  --&lt;br /&gt;
  procedure run_sql_stmt&lt;br /&gt;
  (&lt;br /&gt;
   p_sql_stmt in varchar2&lt;br /&gt;
  )&lt;br /&gt;
  as&lt;br /&gt;
  begin&lt;br /&gt;
    execute immediate p_sql_stmt;&lt;br /&gt;
  exception&lt;br /&gt;
    when others&lt;br /&gt;
    then&lt;br /&gt;
      raise_application_error(-20202, &amp;#039;Failed statement [&amp;#039; || p_sql_stmt || dbms_utility.format_error_backtrace() || &amp;#039;]&amp;#039;, true);&lt;br /&gt;
  end;&lt;br /&gt;
begin&lt;br /&gt;
  --&lt;br /&gt;
  lv_user := user();&lt;br /&gt;
  if lv_user in (&amp;#039;SYS&amp;#039;, &amp;#039;SYSTEM&amp;#039;, &amp;#039;SYSMAN&amp;#039;)&lt;br /&gt;
  then&lt;br /&gt;
    raise_application_error(-20202, &amp;#039;This script cannot be executed against Oracle built-in schema [&amp;#039; || lv_user || &amp;#039;].&amp;#039;);&lt;br /&gt;
  end if;&lt;br /&gt;
  --&lt;br /&gt;
  select&lt;br /&gt;
         *&lt;br /&gt;
         bulk collect into lv_byte_cols&lt;br /&gt;
  from&lt;br /&gt;
         user_tab_columns uc&lt;br /&gt;
  where&lt;br /&gt;
         uc.char_used = &amp;#039;B&amp;#039;&lt;br /&gt;
         and&lt;br /&gt;
         substr(uc.table_name, 1, 4) != &amp;#039;BIN$&amp;#039;&lt;br /&gt;
         and&lt;br /&gt;
         not exists&lt;br /&gt;
         (&lt;br /&gt;
          select 1&lt;br /&gt;
          from   user_views uv&lt;br /&gt;
          where  uv.view_name = uc.table_name&lt;br /&gt;
         )&lt;br /&gt;
  ;&lt;br /&gt;
  --&lt;br /&gt;
  lv_col_cnt := lv_byte_cols.count();&lt;br /&gt;
  --&lt;br /&gt;
  dbms_output.enable();&lt;br /&gt;
  --&lt;br /&gt;
  if lv_col_cnt &amp;gt; 0&lt;br /&gt;
  then&lt;br /&gt;
    for idx_rw in&lt;br /&gt;
    (&lt;br /&gt;
     select index_name &lt;br /&gt;
     from   user_indexes&lt;br /&gt;
     where  index_type = &amp;#039;FUNCTION-BASED NORMAL&amp;#039;&lt;br /&gt;
    )&lt;br /&gt;
    loop&lt;br /&gt;
      lv_idx_cnt := lv_idx_cnt + 1;&lt;br /&gt;
      lv_idx_names(lv_idx_cnt) := idx_rw.index_name;&lt;br /&gt;
      lv_idx_ddls(lv_idx_cnt) := replace&lt;br /&gt;
                                 (&lt;br /&gt;
                                  dbms_metadata.get_ddl&lt;br /&gt;
                                  (&lt;br /&gt;
                                   object_type =&amp;gt; &amp;#039;INDEX&amp;#039;,&lt;br /&gt;
                                   name        =&amp;gt; idx_rw.index_name&lt;br /&gt;
                                  )&lt;br /&gt;
                                  ,&lt;br /&gt;
                                  &amp;#039;;&amp;#039;&lt;br /&gt;
                                 );&lt;br /&gt;
      lv_sql_stmt := &amp;#039;drop index &amp;#039; || idx_rw.index_name;&lt;br /&gt;
      run_sql_stmt(lv_sql_stmt);&lt;br /&gt;
      dbms_output.put_line(&amp;#039;Dropped function-based index: &amp;#039; || idx_rw.index_name);&lt;br /&gt;
      dbms_output.put_line(&amp;#039;In case of script failure, restore the index by running the DDL statement below:&amp;#039;);&lt;br /&gt;
      dbms_output.put_line(lv_idx_ddls(lv_idx_cnt) || &amp;#039;;&amp;#039;);&lt;br /&gt;
    end loop;&lt;br /&gt;
    --&lt;br /&gt;
    for i in 1..lv_col_cnt&lt;br /&gt;
    loop&lt;br /&gt;
      lv_sql_stmt :=  &amp;#039;alter table &amp;#039; || lv_byte_cols(i).table_name || &amp;#039; modify (&amp;#039; ||&lt;br /&gt;
                      lv_byte_cols(i).column_name || &amp;#039; &amp;#039; || lv_byte_cols(i).data_type ||&lt;br /&gt;
                      &amp;#039;(&amp;#039; || lv_byte_cols(i).char_length || &amp;#039; char))&amp;#039;;&lt;br /&gt;
      run_sql_stmt(lv_sql_stmt);&lt;br /&gt;
    end loop;&lt;br /&gt;
    --&lt;br /&gt;
    dbms_output.new_line();&lt;br /&gt;
    for i in 1..lv_idx_cnt&lt;br /&gt;
    loop&lt;br /&gt;
      run_sql_stmt(lv_idx_ddls(i));&lt;br /&gt;
      dbms_output.put_line(&amp;#039;Recreated function-based index: &amp;#039; || lv_idx_names(i));&lt;br /&gt;
    end loop;&lt;br /&gt;
    --&lt;br /&gt;
    dbms_output.new_line();&lt;br /&gt;
    dbms_output.put_line&lt;br /&gt;
    (&lt;br /&gt;
     &amp;#039;Updated length semantics to CHAR for &amp;#039; || lv_col_cnt || &amp;#039; column&amp;#039; ||&lt;br /&gt;
     case when lv_col_cnt &amp;gt; 1&lt;br /&gt;
          then &amp;#039;s&amp;#039;&lt;br /&gt;
     end ||&lt;br /&gt;
     &amp;#039; in the schema [&amp;#039; || lv_user || &amp;#039;].&amp;#039;&lt;br /&gt;
    );&lt;br /&gt;
  else&lt;br /&gt;
    dbms_output.put_line(&amp;#039;No columns with BYTE length semantics were found in the schema [&amp;#039; || lv_user || &amp;#039;].&amp;#039;);&lt;br /&gt;
  end if;&lt;br /&gt;
  --&lt;br /&gt;
  select count(*) into lv_char_set&lt;br /&gt;
  from   nls_session_parameters&lt;br /&gt;
  where  parameter = &amp;#039;NLS_LENGTH_SEMANTICS&amp;#039;&lt;br /&gt;
         and&lt;br /&gt;
         value = &amp;#039;CHAR&amp;#039;&lt;br /&gt;
  ;&lt;br /&gt;
  --&lt;br /&gt;
  if lv_char_set = 0&lt;br /&gt;
  then&lt;br /&gt;
    dbms_output.put_line(&amp;#039;WARNING: Do not forget to change instance parameter NLS_LENGTH_SEMANTICS to CHAR and restart the database.&amp;#039;);&lt;br /&gt;
  end if;&lt;br /&gt;
end;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORA-14097: column type or size mismatch in ALTER TABLE EXCHANGE PARTITION===&lt;br /&gt;
Also can be &amp;lt;tt&amp;gt;ORA-54033: column to be modified is used in a virtual column expression&amp;lt;/tt&amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;
Nothing especially to do with partitions - just any ddl operation that affects the table.&amp;lt;br /&amp;gt;&lt;br /&gt;
Hidden columns do not normally show up in a desc unless colinvisible is on&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set colinvisible on&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
But these sneaky system-generated ones don&amp;#039;t show up even with that setting on!  You need to show them with this:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set pages 50 lines 1000&lt;br /&gt;
col column_name for a40&lt;br /&gt;
col data_default for a40&lt;br /&gt;
select internal_column_id, column_name, data_default, hidden_column, virtual_column from dba_tab_cols where table_name =&amp;#039;XND40&amp;#039;;&lt;br /&gt;
&lt;br /&gt;
INTERNAL_COLUMN_ID COLUMN_NAME                                        DATA_DEFAULT                                       HIDDEN_COLUM VIRTUAL_COLU&lt;br /&gt;
------------------ -------------------------------------------------- -------------------------------------------------- ------------ ------------&lt;br /&gt;
                35 MONLOT_REC_CDR                                     &amp;#039;0&amp;#039;                                                NO           NO&lt;br /&gt;
                34 MONLOT_REC_DBT                                     &amp;#039;0&amp;#039;                                                NO           NO&lt;br /&gt;
                33 MONLOT_CAL_CDR                                     &amp;#039;0&amp;#039;                                                NO           NO&lt;br /&gt;
                32 MONLOT_CAL_DBT                                     &amp;#039;0&amp;#039;                                                NO           NO&lt;br /&gt;
                31 MONMVT_CPT                                         &amp;#039;0&amp;#039;                                                NO           NO&lt;br /&gt;
                30 SENNOT                                             &amp;#039; &amp;#039;                                                NO           NO&lt;br /&gt;
                29 NUMSEQ                                                                                                NO           NO&lt;br /&gt;
                28 NOMFIC                                                                                                NO           NO&lt;br /&gt;
                27 TOTCPT_REC                                                                                            NO           NO&lt;br /&gt;
                26 TOTCPT_CAL                                                                                            NO           NO&lt;br /&gt;
                25 MONLOT_REC                                                                                            NO           NO&lt;br /&gt;
                24 MONLOT_CAL                                                                                            NO           NO&lt;br /&gt;
                23 NBRELE_REC                                                                                            NO           NO&lt;br /&gt;
                22 NBRELE_CAL                                                                                            NO           NO&lt;br /&gt;
                21 NUMCPT_GLO                                                                                            NO           NO&lt;br /&gt;
                20 DEVLOT                                                                                                NO           NO&lt;br /&gt;
                19 CODERR                                                                                                NO           NO&lt;br /&gt;
                18 CANLOT                                                                                                NO           NO&lt;br /&gt;
                17 REFTEX                                                                                                NO           NO&lt;br /&gt;
                16 REFEXN                                                                                                NO           NO&lt;br /&gt;
                15 ETTLOT                                                                                                NO           NO&lt;br /&gt;
                14 TYPLOT                                                                                                NO           NO&lt;br /&gt;
                13 DATEXC                                                                                                NO           NO&lt;br /&gt;
                12 STALOT                                                                                                NO           NO&lt;br /&gt;
                11 REFLOT                                                                                                NO           NO&lt;br /&gt;
                10 USRAUT                                                                                                NO           NO&lt;br /&gt;
                 9 HEUAUT                                                                                                NO           NO&lt;br /&gt;
                 8 DATAUT                                                                                                NO           NO&lt;br /&gt;
                 7 PGMMAJ                                                                                                NO           NO&lt;br /&gt;
                 6 USRMAJ                                                                                                NO           NO&lt;br /&gt;
                 5 HEUMAJ                                                                                                NO           NO&lt;br /&gt;
                 4 DATMAJ                                                                                                NO           NO&lt;br /&gt;
                 3 DATCRT                                                                                                NO           NO&lt;br /&gt;
                 2 REFMAJ                                                                                                NO           NO&lt;br /&gt;
                 1 NUMVER                                                                                                NO           NO&lt;br /&gt;
                36 SYS_STS#KR2WNV5L070XKV1L5H7REH                     SYS_OP_COMBINED_HASH(&amp;quot;NOMFIC&amp;quot;,&amp;quot;NUMSEQ&amp;quot;)            YES          YES&lt;br /&gt;
&lt;br /&gt;
36 rows selected.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
That last row means extended statistics have been generated for 2 columns in this table.&amp;lt;br /&amp;gt;&lt;br /&gt;
====Solution====&lt;br /&gt;
Drop the extended stats, do what you need to do and recreate the extended stats.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
PROCEDURE DROP_EXTENDED_STATS&lt;br /&gt;
 Argument Name                  Type                    In/Out Default?&lt;br /&gt;
 ------------------------------ ----------------------- ------ --------&lt;br /&gt;
 OWNNAME                        VARCHAR2                IN&lt;br /&gt;
 TABNAME                        VARCHAR2                IN&lt;br /&gt;
 EXTENSION                      VARCHAR2                IN&lt;br /&gt;
&lt;br /&gt;
exec dbms_stats.drop_extended_stats ( &amp;#039;KPK&amp;#039;, &amp;#039;XND40&amp;#039;, &amp;#039;(&amp;quot;NOMFIC&amp;quot;,&amp;quot;NUMSEQ&amp;quot;)&amp;#039; );&lt;br /&gt;
&lt;br /&gt;
create table kpk.xnd40_new as select * from kpk.xnd40 where 1=2;&lt;br /&gt;
&lt;br /&gt;
Table created.&lt;br /&gt;
&lt;br /&gt;
select dbms_stats.create_extended_stats ( &amp;#039;KPK&amp;#039;, &amp;#039;XND40&amp;#039;, &amp;#039;(&amp;quot;NOMFIC&amp;quot;,&amp;quot;NUMSEQ&amp;quot;)&amp;#039; ) from   dual;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORA-14404: partitioned table contains partitions in a different tablespace===&lt;br /&gt;
As part of an RMAN duplicate with a skip tablespace, this error is produced&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Reenabling controlfile options for auxiliary database&lt;br /&gt;
Executing: alter database enable block change tracking using file &amp;#039;/oracle/acc/ora_data3/adsa1/bct_adsp_do_not_delete.f&amp;#039;&lt;br /&gt;
&lt;br /&gt;
contents of Memory Script:&lt;br /&gt;
{&lt;br /&gt;
   Alter clone database open resetlogs;&lt;br /&gt;
}&lt;br /&gt;
executing Memory Script&lt;br /&gt;
&lt;br /&gt;
database opened&lt;br /&gt;
Dropping offline and skipped tablespaces&lt;br /&gt;
Executing: drop tablespace &amp;quot;ADS_ARCHIVE&amp;quot; including contents cascade constraints&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-03002: failure of Duplicate Db command at 10/16/2017 23:46:12&lt;br /&gt;
RMAN-05501: aborting duplication of target database&lt;br /&gt;
RMAN-06136: ORACLE error from auxiliary database: ORA-14404: partitioned table contains partitions in a different tablespace&lt;br /&gt;
&lt;br /&gt;
Recovery Manager complete.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
and when attempting to backup the database, we get errors&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
RMAN-06169: could not read file header for datafile 188 error reason 1&lt;br /&gt;
RMAN-06169: could not read file header for datafile 189 error reason 1&lt;br /&gt;
RMAN-06169: could not read file header for datafile 190 error reason 1&lt;br /&gt;
RMAN-06169: could not read file header for datafile 191 error reason 1&lt;br /&gt;
RMAN-06169: could not read file header for datafile 14 error reason 1&lt;br /&gt;
released channel: t1&lt;br /&gt;
released channel: t2&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-03002: failure of backup plus archivelog command at 10/17/2017 15:08:40&lt;br /&gt;
RMAN-06056: could not access datafile 14&lt;br /&gt;
&lt;br /&gt;
Recovery Manager complete.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Problem====&lt;br /&gt;
Tables in the tablespace have partitions in another tablespace so this one cannot be dropped.&amp;lt;br /&amp;gt;&lt;br /&gt;
Check which table partitions are in which tablespaces&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 200&lt;br /&gt;
set pagesize 200&lt;br /&gt;
col table_name for a14&lt;br /&gt;
col table_owner for a14&lt;br /&gt;
col partition_name for a14&lt;br /&gt;
select table_owner&lt;br /&gt;
,      table_name&lt;br /&gt;
,      partition_name&lt;br /&gt;
,      tablespace_name&lt;br /&gt;
from   dba_tab_partitions&lt;br /&gt;
where  (table_owner, table_name) in&lt;br /&gt;
       (&lt;br /&gt;
       select table_owner&lt;br /&gt;
       ,      table_name&lt;br /&gt;
       from   dba_tab_partitions x&lt;br /&gt;
       where  x.tablespace_name = &amp;#039;&amp;amp;&amp;amp;TABLESPACE_TO_DROP&amp;#039;&lt;br /&gt;
       and    exists ( select *&lt;br /&gt;
                       from   dba_tab_partitions y&lt;br /&gt;
                       where  x.table_owner = y.table_owner&lt;br /&gt;
                       and    x.table_name  = y.table_name&lt;br /&gt;
                       and    y.tablespace_name not in (&amp;#039;&amp;amp;TABLESPACE_TO_DROP&amp;#039;)&lt;br /&gt;
                       group  by table_owner&lt;br /&gt;
                       ,      table_name&lt;br /&gt;
                     )&lt;br /&gt;
        )&lt;br /&gt;
order by 1,2,partition_position&lt;br /&gt;
/&lt;br /&gt;
undef TABLESPACE_TO_DROP&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
TABLE_OWNER    TABLE_NAME     PARTITION_NAME TABLESPACE_NAME&lt;br /&gt;
-------------- -------------- -------------- ------------------------------&lt;br /&gt;
KPK            XND20          P0910          TS_THALER_PART_OLD&lt;br /&gt;
KPK            XND20          P1112          TS_THALER_PART_OLD&lt;br /&gt;
KPK            XND20          P13            TS_THALER_PART_OLD&lt;br /&gt;
KPK            XND20          P14            TS_THALER_PART_OLD&lt;br /&gt;
KPK            XND20          P15            TS_THALER_PART_OLD&lt;br /&gt;
KPK            XND20          P16            TS_THALER_DATA&lt;br /&gt;
KPK            XND20          P17            TS_THALER_DATA&lt;br /&gt;
KPK            XND20          P18            TS_THALER_DATA&lt;br /&gt;
KPK            XND20          PMAX           TS_THALER_DATA&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Solution====&lt;br /&gt;
If the intention is to keep all the tables then run this query to generate statements to move the relevant tables out of this tablespace&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select &amp;#039;alter table &amp;#039;||b.table_owner||&amp;#039;.&amp;#039;||b.table_name||&amp;#039; move partition &amp;#039;||b.partition_name||&amp;#039; tablespace &amp;amp;NEW_TABLESPACE;&amp;#039;&lt;br /&gt;
from   (&lt;br /&gt;
       select distinct table_name&lt;br /&gt;
       ,      partition_name&lt;br /&gt;
       from   dba_tab_partitions&lt;br /&gt;
       where  tablespace_name = &amp;#039;&amp;amp;&amp;amp;TABLESPACE_NAME&amp;#039;&lt;br /&gt;
       )                  a&lt;br /&gt;
,      dba_tab_partitions b&lt;br /&gt;
where  a.table_name       = b.table_name&lt;br /&gt;
and    b.tablespace_name != &amp;#039;&amp;amp;TABLESPACE_NAME&amp;#039;&lt;br /&gt;
/&lt;br /&gt;
undef TABLESPACE_NAME&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
If however, the intention is to drop the tablespace anyway, the tables need to be dropped before the tablespace can be dropped.&amp;lt;br /&amp;gt;&lt;br /&gt;
But ...tables with partitions in different tablespaces cannot be dropped. The partitions need to be dropped first!&amp;lt;br /&amp;gt;&lt;br /&gt;
Run the following query to generate statements to drop all the &amp;#039;problem&amp;#039; tables. When these have gone, the tablespace can be dropped.&lt;br /&gt;
* drop table partitions&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
spool /tmp/drop_table_partitions.sql&lt;br /&gt;
sqlplus / as sysdba&amp;lt;&amp;lt;EOSQL&lt;br /&gt;
set headi off newpa none feedb off trims on echo off&lt;br /&gt;
select &amp;#039;alter table &amp;#039;||table_owner||&amp;#039;.&amp;#039;||table_name||&amp;#039; drop partition &amp;#039;||partition_name||&amp;#039;;&amp;#039;&lt;br /&gt;
from   dba_tab_partitions&lt;br /&gt;
where  tablespace_name = &amp;#039;$TABLESPACE_NAME&amp;#039;&lt;br /&gt;
/&lt;br /&gt;
spool off&lt;br /&gt;
EOSQL&lt;br /&gt;
echo &amp;quot;@/tmp/drop_table_partitions.sql&amp;quot; | sqlplus / as sysdba&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* drop tables&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sqlplus / as sysdba&amp;lt;&amp;lt;EOSQL&lt;br /&gt;
select &amp;#039;drop table &amp;#039;||table_owner||&amp;#039;.&amp;#039;||table_name||&amp;#039;;&amp;#039;&lt;br /&gt;
from   dba_tab_partitions&lt;br /&gt;
where  tablespace_name = &amp;#039;$TABLESPACE_NAME&amp;#039;&lt;br /&gt;
spool /tmp/drop_tables.sql&lt;br /&gt;
/&lt;br /&gt;
spool off&lt;br /&gt;
EOSQL&lt;br /&gt;
echo &amp;quot;@/tmp/drop_tables.sql&amp;quot; | sqlplus / as sysdba&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* drop tablespace&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
drop tablespace ads_archive including contents and datafiles&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Find all table partitions in tablespaces with missing datafiles====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 1000 pages 100&lt;br /&gt;
col owner for a10&lt;br /&gt;
col segment_name for a40&lt;br /&gt;
col segment_type for a25&lt;br /&gt;
col partition_name for a20&lt;br /&gt;
col tablespace_name for a25&lt;br /&gt;
select owner&lt;br /&gt;
,      segment_name&lt;br /&gt;
,      segment_type&lt;br /&gt;
,      partition_name&lt;br /&gt;
,      tablespace_name&lt;br /&gt;
from   dba_segments&lt;br /&gt;
where  segment_type in (&amp;#039;TABLE PARTITION&amp;#039;, &amp;#039;TABLE SUBPARTITION&amp;#039;)&lt;br /&gt;
and    tablespace_name in (&lt;br /&gt;
                          select tablespace_name&lt;br /&gt;
                          from   dba_data_files&lt;br /&gt;
                          where  file_name like &amp;#039;%MISSING%&amp;#039;&lt;br /&gt;
                          )&lt;br /&gt;
order  by 1, 2, decode (segment_type, &amp;#039;TABLE SUBPARTITION&amp;#039;, 1, 2),4&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Use exchange partition to alter metadata of the tablespaces without moving the actual data====&lt;br /&gt;
* [https://community.oracle.com/thread/581401?start=15&amp;amp;tstart=0 this] is what you are looking for!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Workaround====&lt;br /&gt;
While working on the solution, a backup can be made using the &amp;quot;skip inaccessible&amp;quot; option. Put this in an rman cmdfile...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
connect catalog rmanusr/rmanpwd@rmancat&lt;br /&gt;
connect target sys/syspwd@adsa1&lt;br /&gt;
run {&lt;br /&gt;
allocate channel t1 type &amp;#039;sbt_tape&amp;#039; parms &amp;#039;ENV=(NSR_SERVER=hn6000.company.be,NSR_CLIENT=hn491,NSR_DATA_VOLUME_POOL=DD1DAILY,NSR_END_ERROR_IGNORE=TRUE)&amp;#039;;&lt;br /&gt;
allocate channel t2 type &amp;#039;sbt_tape&amp;#039; parms &amp;#039;ENV=(NSR_SERVER=hn6000.company.be,NSR_CLIENT=hn491,NSR_DATA_VOLUME_POOL=DD1DAILY,NSR_END_ERROR_IGNORE=TRUE)&amp;#039;;&lt;br /&gt;
configure retention policy to recovery window of 28 days;&lt;br /&gt;
configure controlfile autobackup on;&lt;br /&gt;
crosscheck archivelog all;&lt;br /&gt;
SQL &amp;#039;ALTER SYSTEM SWITCH LOGFILE&amp;#039;;&lt;br /&gt;
SQL &amp;#039;CREATE PFILE FROM SPFILE&amp;#039;;&lt;br /&gt;
backup filesperset 1 format &amp;#039;dbfull_%d_%I_%t_%s_%p&amp;#039; full database plus archivelog skip inaccessible delete all input;&lt;br /&gt;
backup current controlfile;&lt;br /&gt;
release channel t1;&lt;br /&gt;
release channel t2;&lt;br /&gt;
}&lt;br /&gt;
exit&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Another way of deleting the offending objects====&lt;br /&gt;
Taken from [http://www.dbarj.com.br/en/2015/01/resume-oracle-duplicate-database-failed-recovery-datafiles/ Recover from a failed RMAN duplicate]&amp;lt;br /&amp;gt;&lt;br /&gt;
Need to check it before running it blindly!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
set echo off feed off termo off trims on pages 0 newpa none lines 2000 headi off long 32000&lt;br /&gt;
col val for a1000&lt;br /&gt;
spool destroy_offending_objects.sql&lt;br /&gt;
&lt;br /&gt;
select to_clob (&amp;#039;alter table &amp;#039;|| table_name||&amp;#039; drop constraint &amp;#039;||constraint_name||&amp;#039;;&amp;#039;) Val&lt;br /&gt;
from user_constraints where constraint_type in (&amp;#039;R&amp;#039;,&amp;#039;P&amp;#039;) and table_name in (select distinct table_name from user_tab_partitions)&lt;br /&gt;
union all&lt;br /&gt;
select to_clob (&amp;#039;drop index &amp;#039;||index_name||&amp;#039;;&amp;#039;) Val from user_indexes where table_name in (select distinct table_name from user_tab_partitions)&lt;br /&gt;
union all&lt;br /&gt;
select to_clob (&amp;#039;alter table &amp;#039;||table_name|| &amp;#039; drop partition &amp;#039;||partition_name||&amp;#039;;&amp;#039;) from dba_tab_partitions&lt;br /&gt;
where tablespace_name in (select tablespace_name from dba_data_files where file_name like &amp;#039;%MISSING%&amp;#039;)&lt;br /&gt;
union all&lt;br /&gt;
Select case&lt;br /&gt;
when instr (VAl, &amp;#039;PARTITION&amp;#039;) = 0 Then&lt;br /&gt;
substr (Val,1,InStr (Val,&amp;#039;)&amp;#039;)+1)||&amp;#039;;&amp;#039;&lt;br /&gt;
else&lt;br /&gt;
substr (Val,1,InStr (Val,&amp;#039;)&amp;#039;)+1)||&amp;#039; local;&amp;#039;&lt;br /&gt;
End val&lt;br /&gt;
from&lt;br /&gt;
(select dbms_metadata.get_ddl (&amp;#039;INDEX&amp;#039;, index_name,&amp;#039;TEST&amp;#039;) Val from user_indexes where table_name in (select distinct table_name from user_tab_partitions))&lt;br /&gt;
union all&lt;br /&gt;
Select Val&lt;br /&gt;
from&lt;br /&gt;
(select dbms_metadata.get_dependent_ddl (&amp;#039;REF_CONSTRAINT&amp;#039;, table_name,&amp;#039;TEST&amp;#039;) Val&lt;br /&gt;
from user_tables where table_name in (select distinct table_name from user_tab_partitions join user_constraints using ( table_name)&lt;br /&gt;
where constraint_type=&amp;#039;R&amp;#039;))&lt;br /&gt;
union all&lt;br /&gt;
select Val&lt;br /&gt;
from&lt;br /&gt;
(select dbms_metadata.get_ddl (&amp;#039;CONSTRAINT&amp;#039;, constraint_name,&amp;#039;TEST&amp;#039;) Val&lt;br /&gt;
from user_constraints&lt;br /&gt;
where constraint_type=&amp;#039;P&amp;#039; and table_name in (select distinct table_name from user_tab_partitions)&lt;br /&gt;
)&lt;br /&gt;
union all&lt;br /&gt;
select to_clob (val)&lt;br /&gt;
from (select distinct &amp;#039;drop tablespace &amp;#039;||tablespace_name|| &amp;#039; including contents and datafiles;&amp;#039; val&lt;br /&gt;
from dba_tab_partitions&lt;br /&gt;
where tablespace_name in (select tablespace_name from dba_data_files where file_name like &amp;#039;%MISSING%&amp;#039;)&lt;br /&gt;
);&lt;br /&gt;
&lt;br /&gt;
spoo off&lt;br /&gt;
&lt;br /&gt;
@destroy_offending_objects&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORA-28112: failed to execute policy function===&lt;br /&gt;
when exporting or importing using [[Data Pump]]&amp;lt; /br&amp;gt;&lt;br /&gt;
During expdp is accompanied by &amp;quot;&amp;#039;&amp;#039;&amp;#039;ORA-31693: Table data object &amp;quot;SYSMAN&amp;quot;.&amp;quot;MGMT_IP_REPORT_DEF&amp;quot; failed to load/unload and is being skipped due to error:&amp;#039;&amp;#039;&amp;#039;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
===Reason===&lt;br /&gt;
This happens due to audit policies being defined on the table but the policy function is defined in another schema.&lt;br /&gt;
&lt;br /&gt;
===Solution===&lt;br /&gt;
Either drop the policy after importing the table with:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
begin&lt;br /&gt;
    for rec in (select * from dba_audit_policies where object_schema = &amp;#039;SYSMAN&amp;#039;) loop&lt;br /&gt;
        dbms_fga.drop_policy(object_schema =&amp;gt; rec.object_schema,&lt;br /&gt;
                             object_name =&amp;gt; rec.object_name,&lt;br /&gt;
                             policy_name =&amp;gt; rec.policy_name);  &lt;br /&gt;
    end loop;&lt;br /&gt;
end;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or exclude the policies during export by adding this to the .par file:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
exclude=FGA_POLICY&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or even better, give the necessary grants to the exporting user...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
grant exempt access policy to impexpusr;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The sysdba role has this automatically.&lt;br /&gt;
===ORA-17629: Cannot connect to the remote database server===&lt;br /&gt;
Active duplication fails to connect even though dns connection exists in tnsnames.ora&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
Problem:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
DUPLICATE TARGET DATABASE FROM ACTIVE DATABASE DORECOVER NOFILENAMECHECK;&lt;br /&gt;
&lt;br /&gt;
RMAN-03002: failure of Duplicate Db command at 05/27/2015 12:52:24&lt;br /&gt;
RMAN-05501: aborting duplication of target database&lt;br /&gt;
RMAN-03015: error occurred in stored script Memory Script&lt;br /&gt;
RMAN-03009: failure of backup command on ORA_DISK_1 channel at 05/27/2015 12:52:23&lt;br /&gt;
ORA-17629: Cannot connect to the remote database server&lt;br /&gt;
ORA-17627: ORA-12154: TNS:could not resolve the connect identifier specified&lt;br /&gt;
&lt;br /&gt;
ORA-17629: Cannot connect to the remote database server&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
Solution:&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
Update the tnsnames.ora of both destination &amp;#039;&amp;#039;&amp;#039;and&amp;#039;&amp;#039;&amp;#039; source ORACLE_HOMEs!&lt;br /&gt;
&lt;br /&gt;
===ORA-01950: no privileges on tablespace &amp;#039;SYSAUX&amp;#039;===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
26-JUN-15 03:12:27.545: &amp;gt;&amp;gt;&amp;gt; ORA-31642: the following SQL statement fails: &lt;br /&gt;
BEGIN &amp;quot;SYS&amp;quot;.&amp;quot;DBMS_RULE_EXP_RULES&amp;quot;.SCHEMA_CALLOUT(:1,0,1,&amp;#039;12.01.00.02.00&amp;#039;); END;&lt;br /&gt;
ORA-01950: no privileges on tablespace &amp;#039;SYSAUX&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Cause:&amp;#039;&amp;#039;&amp;#039;&amp;lt;br /&amp;gt;&lt;br /&gt;
In this case, it seems SYSMAN has no rights to create objects in the SYSAUX tablespace&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Solution:&amp;#039;&amp;#039;&amp;#039;&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter user SYSMAN quota unlimited on sysaux;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
More information [https://support.oracle.com/epmos/faces/SearchDocDisplay?_adf.ctrl-state=bov7jp5pq_4&amp;amp;_afrLoop=547371065896716#SYMPTOM here]&lt;br /&gt;
&lt;br /&gt;
===ORA-39080: failed to create queues &amp;quot;KUPC$C_1_20150616165037&amp;quot; and &amp;quot;KUPC$S_1_20150616165037&amp;quot; for Data Pump job===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
expdp /&lt;br /&gt;
&lt;br /&gt;
Export: Release 11.2.0.4.0 - Production on Tue Jun 16 16:50:36 2015&lt;br /&gt;
&lt;br /&gt;
Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.&lt;br /&gt;
&lt;br /&gt;
Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production&lt;br /&gt;
With the Partitioning, OLAP, Data Mining and Real Application Testing options&lt;br /&gt;
ORA-31626: job does not exist&lt;br /&gt;
ORA-31637: cannot create job SYS_EXPORT_SCHEMA_01 for user OPS$ORAIBM&lt;br /&gt;
ORA-06512: at &amp;quot;SYS.DBMS_SYS_ERROR&amp;quot;, line 95&lt;br /&gt;
ORA-06512: at &amp;quot;SYS.KUPV$FT_INT&amp;quot;, line 798&lt;br /&gt;
[[ORA-39080: failed to create queues &amp;quot;KUPC$C_1_20150616165037&amp;quot; and &amp;quot;KUPC$S_1_20150616165037&amp;quot; for Data Pump job]]&lt;br /&gt;
ORA-06512: at &amp;quot;SYS.DBMS_SYS_ERROR&amp;quot;, line 95&lt;br /&gt;
ORA-06512: at &amp;quot;SYS.KUPC$QUE_INT&amp;quot;, line 1534&lt;br /&gt;
ORA-24002: QUEUE_TABLE SYS.AQ$KUPC$DATAPUMP_QUETAB_1 does not exist&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Cause:====&lt;br /&gt;
Possibly some or all of OLAP module has got itself deinstalled.&lt;br /&gt;
====Solution:====&lt;br /&gt;
Try:&lt;br /&gt;
* Recompiling invalid objects. @?/rdbms/admin/utlrp&lt;br /&gt;
* Reinstalling DBMS_CUBE packages by (re)running catproc.sql. @?/rdbms/admin/catproc followed by @?/rdbms/admin/utlrp&lt;br /&gt;
* Reinstalling OLAP. @?/olap/admin/olap.sql SYSAUX TEMP; But see Metalink note ID 296187.1 for full instructions.&lt;br /&gt;
* Check metalink for bugs. See ID 345198.1 and possibly ID 453796.1&lt;br /&gt;
===ORA-14063: Unusable index exists on unique/primary constraint key===&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;ORA-39083: Object type CONSTRAINT failed to create with error:&amp;#039;&amp;#039;&amp;#039;&amp;lt;br /&amp;gt;&lt;br /&gt;
During an import datapump (impdp), import failed because indexes were in error before the tables were exported. This causes the import of rows to be skipped.&amp;lt;br /&amp;gt;&lt;br /&gt;
If the export cannot be done again (having compiled the indexes), then the metadata can be imported and the indexes compiled before importing the data.&lt;br /&gt;
* Import the metadata&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cat&amp;lt;&amp;lt;EOCAT &amp;gt;impdp_adst_ads_archive_metadata.par&lt;br /&gt;
userid=&amp;#039;/ as sysdba&amp;#039;&lt;br /&gt;
dumpfile=adst_ads_archive.dmp&lt;br /&gt;
logfile=impdp_adst_ads_archive_metadata.log&lt;br /&gt;
content=metadata_only&lt;br /&gt;
EOCAT&lt;br /&gt;
&lt;br /&gt;
impdp parfile=impdp_adst_ads_archive_metadata.par&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Find the bad indexes and recompile them&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select &amp;#039;alter index &amp;#039;|| owner||&amp;#039;.&amp;#039;||index_name||&amp;#039; rebuild online parallel 8;&amp;#039;&lt;br /&gt;
from   dba_indexes&lt;br /&gt;
where  status = &amp;#039;UNUSABLE&amp;#039;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Import the data&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cat&amp;lt;&amp;lt;EOCAT &amp;gt;impdp_adst_ads_archive_data.par&lt;br /&gt;
userid=&amp;#039;/ as sysdba&amp;#039;&lt;br /&gt;
dumpfile=adst_ads_archive.dmp&lt;br /&gt;
logfile=impdp_adst_ads_archive_data.log&lt;br /&gt;
table_exists_action=append&lt;br /&gt;
content=data_only&lt;br /&gt;
EOCAT&lt;br /&gt;
&lt;br /&gt;
impdp parfile=impdp_adst_ads_archive_data.par&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORA-09925: Unable to create audit trail file===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SQL&amp;gt; startup nomount pfile=&amp;quot;/oracle/TRSCRP1/admin/initTRSCRP1.ora&amp;quot;&lt;br /&gt;
ORA-09925: Unable to create audit trail file&lt;br /&gt;
SVR4 Error: 2: No such file or directory&lt;br /&gt;
Additional information: 9925&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
connected to auxiliary database (not started)&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-03002: failure of Duplicate Db command at 08/29/2017 15:53:09&lt;br /&gt;
RMAN-05501: aborting duplication of target database&lt;br /&gt;
RMAN-03015: error occurred in stored script Memory Script&lt;br /&gt;
RMAN-04014: startup failed: ORA-09925: Unable to create audit trail file&lt;br /&gt;
IBM AIX RISC System/6000 Error: 2: No such file or directory&lt;br /&gt;
Additional information: 9925&lt;br /&gt;
&lt;br /&gt;
Recovery Manager complete.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Problem====&lt;br /&gt;
This will be almost certainly one of two issues. Either the directory is not writable by the id that started the instance or the directory just does not exist.&lt;br /&gt;
====Solution====&lt;br /&gt;
Note there can be a difference between what you see when you type:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
show parameter audit&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
and when you type:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
strings -a $ORACLE_HOME/dbs/spfile${ORACLE_SID}.ora | grep -i audit&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
due to someone doing an &amp;quot;alter system&amp;quot; without the &amp;quot;scope=spfile&amp;quot; or &amp;quot;scope=both&amp;quot;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SQL&amp;gt; host ls -al /oracle/TRSCRP1/admin/adump&lt;br /&gt;
SQL&amp;gt; host mkdir /oracle/TRSCRP1/admin/adump&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===ORA-09925: Unable to create audit trail file===&lt;br /&gt;
When starting SQL*Plus with no db processes running (expecting to see &amp;quot;Connected to an idle instance&amp;quot;), we get this:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ERROR:&lt;br /&gt;
ORA-09925: Unable to create audit trail file&lt;br /&gt;
IBM AIX RISC System/6000 Error: 2: No such file or directory&lt;br /&gt;
Additional information: 9925&lt;br /&gt;
ORA-01075: you are currently logged on&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Filesystem permissions are fine&lt;br /&gt;
* &amp;#039;strings spfile&amp;lt;SID&amp;gt;.ora | grep audit&amp;#039; shows the correct directory&lt;br /&gt;
* Running on AIX&lt;br /&gt;
AIX is the clue here... need to check for semaphores and locked shared memory objects&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
(0) UCLID55D oraibm@solax082:/oracle/product/11.2.0.3/bin&amp;gt; sysresv&lt;br /&gt;
&lt;br /&gt;
IPC Resources for ORACLE_SID &amp;quot;UCLID55D&amp;quot; :&lt;br /&gt;
Shared Memory:&lt;br /&gt;
ID              KEY&lt;br /&gt;
8388640         0xffffffff&lt;br /&gt;
579862561       0xffffffff&lt;br /&gt;
384827426       0x326f32e8&lt;br /&gt;
&lt;br /&gt;
Semaphores:&lt;br /&gt;
ID              KEY&lt;br /&gt;
167772287       0xf09f4914&lt;br /&gt;
Oracle Instance alive for sid &amp;quot;UCLID55D&amp;quot;&lt;br /&gt;
&lt;br /&gt;
(0) UCLID55D oraibm@solax082:/oracle/product/11.2.0.3/bin&amp;gt; ipcrm -m 8388640&lt;br /&gt;
(0) UCLID55D oraibm@solax082:/oracle/product/11.2.0.3/bin&amp;gt; ipcrm -m 579862561&lt;br /&gt;
(0) UCLID55D oraibm@solax082:/oracle/product/11.2.0.3/bin&amp;gt; ipcrm -m 384827426&lt;br /&gt;
&lt;br /&gt;
(0) UCLID55D oraibm@solax082:/oracle/product/11.2.0.3/bin&amp;gt; ipcrm -s 167772287&lt;br /&gt;
&lt;br /&gt;
(0) UCLID55D oraibm@solax082:/oracle/product/11.2.0.3/bin&amp;gt; sysresv&lt;br /&gt;
&lt;br /&gt;
IPC Resources for ORACLE_SID &amp;quot;UCLID55D&amp;quot; :&lt;br /&gt;
Shared Memory&lt;br /&gt;
ID              KEY&lt;br /&gt;
No shared memory segments used&lt;br /&gt;
Semaphores:&lt;br /&gt;
ID              KEY&lt;br /&gt;
No semaphore resources used&lt;br /&gt;
Oracle Instance not alive for sid &amp;quot;UCLID55D&amp;quot;&lt;br /&gt;
&lt;br /&gt;
(0) UCLID55D oraibm@solax082:/oracle/product/11.2.0.3/bin&amp;gt; ps -ef | grep UCLID55D&lt;br /&gt;
oraibm 3326 23776 0 14:12:05 pts/1 0:00 grep UCLID55D &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===RMAN-06023: no backup or copy of datafile 1 found to restore===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-03002: failure of Duplicate Db command at 05/16/2018 16:08:13&lt;br /&gt;
RMAN-05501: aborting duplication of target database&lt;br /&gt;
RMAN-05556: not all datafiles have backups that can be recovered to SCN 278250901080&lt;br /&gt;
RMAN-03015: error occurred in stored script Memory Script&lt;br /&gt;
RMAN-06026: some targets not found - aborting restore&lt;br /&gt;
RMAN-06023: no backup or copy of datafile 7 found to restore&lt;br /&gt;
RMAN-06023: no backup or copy of datafile 6 found to restore&lt;br /&gt;
RMAN-06023: no backup or copy of datafile 5 found to restore&lt;br /&gt;
RMAN-06023: no backup or copy of datafile 4 found to restore&lt;br /&gt;
RMAN-06023: no backup or copy of datafile 3 found to restore&lt;br /&gt;
RMAN-06023: no backup or copy of datafile 2 found to restore&lt;br /&gt;
RMAN-06023: no backup or copy of datafile 1 found to restore&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Seems pretty straightforward? SCN was set too early for the retention period. But no, not this time.&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
RMAN&amp;gt; list backup of datafile 1;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
List of Backup Sets&lt;br /&gt;
===================&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
BS Key  Type LV Size       Device Type Elapsed Time Completion Time&lt;br /&gt;
------- ---- -- ---------- ----------- ------------ -------------------&lt;br /&gt;
110170340 Incr 0  132.90G    SBT_TAPE    00:18:32     2018-05-14 01:19:40&lt;br /&gt;
        BP Key: 110170345   Status: AVAILABLE  Compressed: NO  Tag: WEEKLY_FULL&lt;br /&gt;
        Handle: 24639762_REPORTA_07t2r3uk_1_1   Media: V_17152809_77191330&lt;br /&gt;
  List of Datafiles in backup set 110170340&lt;br /&gt;
  File LV Type Ckp SCN    Ckp Time            Name&lt;br /&gt;
  ---- -- ---- ---------- ------------------- ----&lt;br /&gt;
  1    0  Incr 277998128991 2018-05-14 01:01:08 /cln/acc/ora_data3/reporta/system01.dbf&lt;br /&gt;
&lt;br /&gt;
BS Key  Type LV Size       Device Type Elapsed Time Completion Time&lt;br /&gt;
------- ---- -- ---------- ----------- ------------ -------------------&lt;br /&gt;
110355808 Incr 1  204.00M    SBT_TAPE    00:05:13     2018-05-15 01:06:22&lt;br /&gt;
        BP Key: 110355813   Status: AVAILABLE  Compressed: NO  Tag: DAILY_INCREMENTAL&lt;br /&gt;
        Handle: 24661053_REPORTA_3ft2toal_1_1   Media: V_17173010_77253424&lt;br /&gt;
  List of Datafiles in backup set 110355808&lt;br /&gt;
  File LV Type Ckp SCN    Ckp Time            Name&lt;br /&gt;
  ---- -- ---- ---------- ------------------- ----&lt;br /&gt;
  1    1  Incr 278044267395 2018-05-15 01:01:09 /cln/acc/ora_data3/reporta/system01.dbf&lt;br /&gt;
&lt;br /&gt;
BS Key  Type LV Size       Device Type Elapsed Time Completion Time&lt;br /&gt;
------- ---- -- ---------- ----------- ------------ -------------------&lt;br /&gt;
110543802 Incr 1  237.00M    SBT_TAPE    00:05:51     2018-05-16 01:07:40&lt;br /&gt;
        BP Key: 110543807   Status: AVAILABLE  Compressed: NO  Tag: DAILY_INCREMENTAL&lt;br /&gt;
        Handle: 24681602_REPORTA_6nt30cnt_1_1   Media: V_17133646_77315270&lt;br /&gt;
  List of Datafiles in backup set 110543802&lt;br /&gt;
  File LV Type Ckp SCN    Ckp Time            Name&lt;br /&gt;
  ---- -- ---- ---------- ------------------- ----&lt;br /&gt;
  1    1  Incr 278286445856 2018-05-16 01:01:50 /cln/acc/ora_data3/reporta/system01.dbf&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
SCN was only 12 hours ago with a retention of 28 days! The backup piece dated 2018-05-15 01:06:22 is clearly available and on the device type set_tape.&amp;lt;br /&amp;gt;&lt;br /&gt;
The trick here was to look back through the logs and look more closely at what the file restore message was saying...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
channel t0: starting datafile backup set restore&lt;br /&gt;
channel t0: specifying datafile(s) to restore from backup set&lt;br /&gt;
channel t0: restoring datafile 00001 to /cln/acc/ora_data3/reporta/system01.dbf             &amp;lt; &amp;lt; &amp;lt; ==============&lt;br /&gt;
channel t0: reading from backup piece dbfull_REPORTA_738887052_967580186_116_1&lt;br /&gt;
channel t2: ORA-19870: error while restoring backup piece dbfull_REPORTA_738887052_967579750_113_1&lt;br /&gt;
ORA-19507: failed to retrieve sequential file, handle=&amp;quot;dbfull_REPORTA_738887052_967579750_113_1&amp;quot;, parms=&amp;quot;&amp;quot;&lt;br /&gt;
ORA-27029: skgfrtrv: sbtrestore returned error&lt;br /&gt;
ORA-19511: non RMAN, but media manager or vendor specific failure, error text:&lt;br /&gt;
   CreateOraObject20: Job[0] thread[55116090]: Restore: GetBackupInfo() for Archive File[dbfull_REPORTA_738887052_967579750_113_1] failed.&lt;br /&gt;
ORA-0651&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
It was not the fact that it could not find the data on tape, it was that it could not save the file to the location indicated!!&lt;br /&gt;
In the RMAN DUPLICATE script, I had all the file paths redirected (a mixture of convert parameters and spfile set) to a /restore filesystem.&amp;lt;br /&amp;gt;&lt;br /&gt;
But I forgot one!&amp;lt;br /&amp;gt;&lt;br /&gt;
A handy thing to do is to search out the file paths with this to see if something is still wrong:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cd $ORACLE_HOME/dbs&lt;br /&gt;
strings -a spfile${ORACLE_SID}.ora | grep dest&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This should show any paths still not getting caught by the DUPLICATE script.&lt;br /&gt;
&lt;br /&gt;
===RMAN-06136: ORACLE error from auxiliary database: ORA-06502: PL/SQL: numeric or value error===&lt;br /&gt;
When cloning a database, the duplicate fails with this error.&lt;br /&gt;
====Problem====&lt;br /&gt;
This duplicate had no target connection but did have a catalog and auxiliary connection.&lt;br /&gt;
In the catalog (which was the catalog where the target was registerd), there was also an entry in that catalog with the same name as the auxiliary - left over from the days when these 2 instances were Primary and Standby in a Dataguard configuration.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
Datafile 414 skipped by request&lt;br /&gt;
Datafile 415 skipped by request&lt;br /&gt;
Datafile 419 skipped by request&lt;br /&gt;
Datafile 420 skipped by request&lt;br /&gt;
Datafile 421 skipped by request&lt;br /&gt;
&lt;br /&gt;
DBGSQL:     AUXILIARY&amp;gt; begin :ofname := sys.dbms_backup_restore.convertFileName( fname   =&amp;gt;   :ifname, ftype   =&amp;gt;   :iftype, osftype =&amp;gt;   TRUE); end;&lt;br /&gt;
DBGSQL:        sqlcode = 6502&lt;br /&gt;
DBGSQL:         B :ofname = NULL&lt;br /&gt;
DBGSQL:         B :ifname =&lt;br /&gt;
DBGSQL:         B :iftype = 2&lt;br /&gt;
restarting auxiliary database without server parameter file&lt;br /&gt;
Oracle instance started&lt;br /&gt;
&lt;br /&gt;
Total System Global Area   32068440064 bytes&lt;br /&gt;
&lt;br /&gt;
Fixed Size                     2262200 bytes&lt;br /&gt;
Variable Size              16978545480 bytes&lt;br /&gt;
Database Buffers           15032385536 bytes&lt;br /&gt;
Redo Buffers                  55246848 bytes&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-03002: failure of Duplicate Db command at 10/04/2017 14:50:29&lt;br /&gt;
RMAN-05501: aborting duplication of target database&lt;br /&gt;
RMAN-06136: ORACLE error from auxiliary database: ORA-06502: PL/SQL: numeric or value error&lt;br /&gt;
&lt;br /&gt;
Recovery Manager complete.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Solution====&lt;br /&gt;
Connect to the catalog and unregister the name of the auxiliary database. It shouldn&amp;#039;t be there anyway.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rman catalog rmanusr/rmanpwd@rmancat&lt;br /&gt;
&lt;br /&gt;
Recovery Manager: Release 11.2.0.4.0 - Production on Wed Oct 4 15:00:00 2017&lt;br /&gt;
&lt;br /&gt;
Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.&lt;br /&gt;
&lt;br /&gt;
connected to recovery catalog database&lt;br /&gt;
&lt;br /&gt;
RMAN&amp;gt; set dbid 4260753020;&lt;br /&gt;
&lt;br /&gt;
executing command: SET DBID&lt;br /&gt;
database name is &amp;quot;LBK&amp;quot; and DBID is 4260753020&lt;br /&gt;
&lt;br /&gt;
RMAN&amp;gt; list db_unique_name of database;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
List of Databases&lt;br /&gt;
DB Key  DB Name  DB ID            Database Role    Db_unique_name&lt;br /&gt;
------- ------- ----------------- ---------------  ------------------&lt;br /&gt;
13301587 LBK      4260753020       PRIMARY          LBK&lt;br /&gt;
13301587 LBK      4260753020       STANDBY          ACC_PERF&lt;br /&gt;
13301587 LBK      4260753020       STANDBY          LBKRO&lt;br /&gt;
&lt;br /&gt;
RMAN&amp;gt; unregister db_unique_name &amp;#039;ACC_PERF&amp;#039;;&lt;br /&gt;
&lt;br /&gt;
database db_unique_name is &amp;quot;ACC_PERF&amp;quot;, db_name is &amp;quot;LBK&amp;quot; and DBID is 4260753020&lt;br /&gt;
&lt;br /&gt;
Want to unregister the database with target db_unique_name (enter YES or NO)? YES&lt;br /&gt;
database with db_unique_name ACC_PERF unregistered from the recovery catalog&lt;br /&gt;
&lt;br /&gt;
RMAN&amp;gt; exit&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORA-39181: Only partial table data may be exported due to fine grain access control on &amp;quot;owner&amp;quot;.&amp;quot;&amp;lt;table_name&amp;gt;&amp;quot;===&lt;br /&gt;
&lt;br /&gt;
===Reason===&lt;br /&gt;
This happens when applications are designed with fine-grained access.&lt;br /&gt;
===Solution===&lt;br /&gt;
Grant the necessary privileges to the exporting user...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
grant exempt access policy to ops$oraibm;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORA-04030: out of process memory when trying to allocate 2520 bytes===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
expdp problem (ORA-04030: out of process memory when trying to allocate 2520 bytes (pga heap,koh-kghu call heap))&lt;br /&gt;
&lt;br /&gt;
select value from v$pgastat where name=&amp;#039;maximum PGA allocated&amp;#039;;&lt;br /&gt;
&lt;br /&gt;
SHOW PARAMETER TARGET&lt;br /&gt;
&lt;br /&gt;
ORA-04030: out of process memory when trying to allocate 2520 bytes (pga heap,koh-kghu call heap)&lt;br /&gt;
&lt;br /&gt;
alter system reset pga_aggregate_target scope=spfile;&lt;br /&gt;
&lt;br /&gt;
show sga&lt;br /&gt;
&lt;br /&gt;
select * from v$pgastat;&lt;br /&gt;
&lt;br /&gt;
show parameter process&lt;br /&gt;
&lt;br /&gt;
select sum(value)/1024/1024 Mb&lt;br /&gt;
from   v$sesstat s, v$statname n&lt;br /&gt;
where  1=1&lt;br /&gt;
and    n.STATISTIC# = s.STATISTIC#&lt;br /&gt;
and    name = &amp;#039;session pga memory&amp;#039;&lt;br /&gt;
&lt;br /&gt;
show parameter WORKAREA&lt;br /&gt;
&lt;br /&gt;
select value from v$pgastat where name=&amp;#039;maximum PGA allocated&amp;#039;;&lt;br /&gt;
&lt;br /&gt;
alter system set memory_max_target=10G scope=spfile;&lt;br /&gt;
&lt;br /&gt;
alter system set memory_target=3G scope=both;&lt;br /&gt;
&lt;br /&gt;
select * from v$memory_target_advice order by memory_size;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORA-04031: unable to allocate 32 bytes of shared memory (&amp;quot;shared pool&amp;quot;,&amp;quot;select name,online$,contents...&amp;quot;,&amp;quot;KGLH0^e5705bfc&amp;quot;,&amp;quot;kglHeapInitialize:temp&amp;quot;)===&lt;br /&gt;
* [https://blogs.oracle.com/db/entry/ora-4031_troubleshooting ORA-4031 Troubleshooting]&lt;br /&gt;
* [https://support.oracle.com/epmos/faces/DocumentDisplay?_afrLoop=89215376348478&amp;amp;id=396940.1&amp;amp;_afrWindowMode=0&amp;amp;_adf.ctrl-state=u1z0xcppg_4 Troubleshooting and Diagnosing ORA-4031 Error - (Doc ID 396940.1)]&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ORA-04031: unable to allocate  bytes of shared memory (&amp;quot;&amp;quot;,&amp;quot;&amp;quot;,&amp;quot;&amp;quot;,&amp;quot;&amp;quot;) &lt;br /&gt;
ORA-04031: unable to allocate 32 bytes of shared memory (&amp;quot;shared pool&amp;quot;,&amp;quot;select name,online$,contents...&amp;quot;,&amp;quot;KGLH0^e5705bfc&amp;quot;,&amp;quot;kglHeapInitialize:temp&amp;quot;) &lt;br /&gt;
Incident details in: /oracle/diag/rdbms/mape/MAPE/incident/incdir_86754/MAPE_dm00_14221536_i86754.trc &lt;br /&gt;
Wed Jul 31 20:42:50 2013 &lt;br /&gt;
Dumping diagnostic data in directory=[cdmp_20130731204250], requested by (instance=1, osid=14221536 (DM00)), summary=[incident=86753]. &lt;br /&gt;
Wed Jul 31 20:42:51 2013 &lt;br /&gt;
Sweep [inc][86754]: completed &lt;br /&gt;
Sweep [inc][86753]: completed &lt;br /&gt;
Sweep [inc2][86753]: completed &lt;br /&gt;
Wed Jul 31 20:42:57 2013 &lt;br /&gt;
Use ADRCI or Support Workbench to package the incident. &lt;br /&gt;
See Note 411.1 at My Oracle Support for error and packaging details. &lt;br /&gt;
Dumping diagnostic data in directory=[cdmp_20130731204257], requested by (instance=1, osid=14221536 (DM00)), summary=[incident=86754]. &lt;br /&gt;
Wed Jul 31 20:43:35 2013 &lt;br /&gt;
Errors in file /oracle/diag/rdbms/mape/MAPE/trace/MAPE_dw02_40567024.trc  (incident=82993): &lt;br /&gt;
ORA-04031: unable to allocate 32 bytes of shared memory (&amp;quot;shared pool&amp;quot;,&amp;quot;select order#,columns,types ...&amp;quot;,&amp;quot;KGLH0^470434f8&amp;quot;,&amp;quot;kglHeapInitialize:temp&amp;quot;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Database had already crashed so nothing to do but:&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
(0) MAPE ora@x025:/home/ora&amp;gt; sqlplus / as sysdba&lt;br /&gt;
&lt;br /&gt;
SQL*Plus: Release 11.2.0.3.0 Production on Fri Aug 2 14:26:20 2013&lt;br /&gt;
&lt;br /&gt;
Copyright (c) 1982, 2011, Oracle.  All rights reserved.&lt;br /&gt;
&lt;br /&gt;
Connected.&lt;br /&gt;
SYS@MAPE&amp;gt; alter system flush shared_pool;&lt;br /&gt;
alter system flush shared_pool&lt;br /&gt;
*&lt;br /&gt;
ERROR at line 1:&lt;br /&gt;
ORA-01012: not logged on&lt;br /&gt;
Process ID: 0&lt;br /&gt;
Session ID: 0 Serial number: 0&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
SYS@MAPE&amp;gt; shutdown abort&lt;br /&gt;
ORACLE instance shut down.&lt;br /&gt;
SYS@MAPE&amp;gt; startup&lt;br /&gt;
ORACLE instance started.&lt;br /&gt;
&lt;br /&gt;
Total System Global Area  734892032 bytes&lt;br /&gt;
Fixed Size                  2225128 bytes&lt;br /&gt;
Variable Size             398461976 bytes&lt;br /&gt;
Database Buffers          318767104 bytes&lt;br /&gt;
Redo Buffers               15437824 bytes&lt;br /&gt;
Database mounted.&lt;br /&gt;
Database opened.&lt;br /&gt;
&lt;br /&gt;
SYS@MAPE&amp;gt; show parameter pool&lt;br /&gt;
&lt;br /&gt;
NAME                                 TYPE                           VALUE&lt;br /&gt;
------------------------------------ ------------------------------ ------------------------------&lt;br /&gt;
buffer_pool_keep                     string&lt;br /&gt;
buffer_pool_recycle                  string&lt;br /&gt;
global_context_pool_size             string&lt;br /&gt;
java_pool_size                       big integer                    0&lt;br /&gt;
large_pool_size                      big integer                    0&lt;br /&gt;
olap_page_pool_size                  big integer                    0&lt;br /&gt;
shared_pool_reserved_size            big integer                    18M&lt;br /&gt;
shared_pool_size                     big integer                    208M&lt;br /&gt;
streams_pool_size                    big integer                    0&lt;br /&gt;
SYS@MAPE&amp;gt; show sga&lt;br /&gt;
&lt;br /&gt;
Total System Global Area  734892032 bytes&lt;br /&gt;
Fixed Size                  2225128 bytes&lt;br /&gt;
Variable Size             385879064 bytes&lt;br /&gt;
Database Buffers          331350016 bytes&lt;br /&gt;
Redo Buffers               15437824 bytes&lt;br /&gt;
SYS@MAPE&amp;gt; exit&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
but for reference, the causes could well be the applications running on the database are not using bind variables...&amp;lt;br /&amp;gt;&lt;br /&gt;
From [http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:528893984337 asktom.oracle.com]&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
Just to give you a tiny idea of how huge of a difference this &lt;br /&gt;
can make performance wise, you only need to run a very small &lt;br /&gt;
test:&lt;br /&gt;
&lt;br /&gt;
tkyte@TKYTE816&amp;gt; alter system flush shared_pool;&lt;br /&gt;
System altered.&lt;br /&gt;
&lt;br /&gt;
tkyte@TKYTE816&amp;gt; declare&lt;br /&gt;
  2      type rc is ref cursor;&lt;br /&gt;
  3      l_rc rc;&lt;br /&gt;
  4      l_dummy all_objects.object_name%type;&lt;br /&gt;
  5      l_start number default dbms_utility.get_time;&lt;br /&gt;
  6  begin&lt;br /&gt;
  7      for i in 1 .. 1000&lt;br /&gt;
  8      loop&lt;br /&gt;
  9          open l_rc for&lt;br /&gt;
 10          &amp;#039;select object_name&lt;br /&gt;
 11             from all_objects&lt;br /&gt;
 12            where object_id = &amp;#039; || i;&lt;br /&gt;
 13          fetch l_rc into l_dummy;&lt;br /&gt;
 14          close l_rc;&lt;br /&gt;
 15      end loop;&lt;br /&gt;
 16      dbms_output.put_line&lt;br /&gt;
 17      ( round( (dbms_utility.get_time-l_start)/100, 2 ) ||&lt;br /&gt;
 18        &amp;#039; seconds...&amp;#039; );&lt;br /&gt;
 19  end;&lt;br /&gt;
 20  /&lt;br /&gt;
14.86 seconds...&lt;br /&gt;
&lt;br /&gt;
PL/SQL procedure successfully completed.&lt;br /&gt;
&lt;br /&gt;
tkyte@TKYTE816&amp;gt; declare&lt;br /&gt;
  2      type rc is ref cursor;&lt;br /&gt;
  3      l_rc rc;&lt;br /&gt;
  4      l_dummy all_objects.object_name%type;&lt;br /&gt;
  5      l_start number default dbms_utility.get_time;&lt;br /&gt;
  6  begin&lt;br /&gt;
  7      for i in 1 .. 1000&lt;br /&gt;
  8      loop&lt;br /&gt;
  9          open l_rc for&lt;br /&gt;
 10          &amp;#039;select object_name&lt;br /&gt;
 11             from all_objects&lt;br /&gt;
 12            where object_id = :x&amp;#039;&lt;br /&gt;
 13          using i;&lt;br /&gt;
 14          fetch l_rc into l_dummy;&lt;br /&gt;
 15          close l_rc;&lt;br /&gt;
 16      end loop;&lt;br /&gt;
 17      dbms_output.put_line&lt;br /&gt;
 18      ( round( (dbms_utility.get_time-l_start)/100, 2 ) ||&lt;br /&gt;
 19        &amp;#039; seconds...&amp;#039; );&lt;br /&gt;
 20  end;&lt;br /&gt;
 21  /&lt;br /&gt;
1.27 seconds...&lt;br /&gt;
&lt;br /&gt;
PL/SQL procedure successfully completed.&lt;br /&gt;
&lt;br /&gt;
That is pretty dramatic.  The fact is that not only does this &lt;br /&gt;
execute much faster (we spent more time PARSING our queries then &lt;br /&gt;
actually EXECUTING them!) it will let more users use your system &lt;br /&gt;
simultaneously.&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
and from [http://asktom.oracle.com/pls/asktom/f?p=100:11:::::P11_QUESTION_ID:1163635055580 linked question]&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
Lbrary cache latch contention is typically caused by NOT using bind variables.  It is due &lt;br /&gt;
to excessive parsing of statements.&lt;br /&gt;
&lt;br /&gt;
One way to see if this might be the case in your situation is to run a script like:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
create table t1 as select sql_text from v$sqlarea;&lt;br /&gt;
&lt;br /&gt;
alter table t1 add sql_text_wo_constants varchar2(1000);&lt;br /&gt;
&lt;br /&gt;
create or replace function &lt;br /&gt;
remove_constants( p_query in varchar2 ) return varchar2&lt;br /&gt;
as&lt;br /&gt;
    l_query long;&lt;br /&gt;
    l_char  varchar2(1);&lt;br /&gt;
    l_in_quotes boolean default FALSE;&lt;br /&gt;
begin&lt;br /&gt;
    for i in 1 .. length( p_query )&lt;br /&gt;
    loop&lt;br /&gt;
        l_char := substr(p_query,i,1);&lt;br /&gt;
        if ( l_char = &amp;#039;&amp;#039;&amp;#039;&amp;#039; and l_in_quotes )&lt;br /&gt;
        then&lt;br /&gt;
            l_in_quotes := FALSE;&lt;br /&gt;
        elsif ( l_char = &amp;#039;&amp;#039;&amp;#039;&amp;#039; and NOT l_in_quotes )&lt;br /&gt;
        then&lt;br /&gt;
            l_in_quotes := TRUE;&lt;br /&gt;
            l_query := l_query || &amp;#039;&amp;#039;&amp;#039;#&amp;#039;;&lt;br /&gt;
        end if;&lt;br /&gt;
        if ( NOT l_in_quotes ) then&lt;br /&gt;
            l_query := l_query || l_char;&lt;br /&gt;
        end if;&lt;br /&gt;
    end loop;&lt;br /&gt;
    l_query := translate( l_query, &amp;#039;0123456789&amp;#039;, &amp;#039;@@@@@@@@@@&amp;#039; );&lt;br /&gt;
    for i in 0 .. 8 loop&lt;br /&gt;
        l_query := replace( l_query, lpad(&amp;#039;@&amp;#039;,10-i,&amp;#039;@&amp;#039;), &amp;#039;@&amp;#039; );&lt;br /&gt;
        l_query := replace( l_query, lpad(&amp;#039; &amp;#039;,10-i,&amp;#039; &amp;#039;), &amp;#039; &amp;#039; );&lt;br /&gt;
    end loop;&lt;br /&gt;
    return upper(l_query);&lt;br /&gt;
end;&lt;br /&gt;
/&lt;br /&gt;
update t1 set sql_text_wo_constants = remove_constants(sql_text);&lt;br /&gt;
&lt;br /&gt;
select sql_text_wo_constants, count(*)&lt;br /&gt;
  from t1&lt;br /&gt;
 group by sql_text_wo_constants&lt;br /&gt;
having count(*) &amp;gt; 100&lt;br /&gt;
 order by 2&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The output of that last query will show you statements that are identical in the shared &lt;br /&gt;
pool after all numbers and character string constants have been removed.  These &lt;br /&gt;
statements -- and more importantly their counts -- are the potential bottlenecks.  In &lt;br /&gt;
addition to causing the contention, they will be HUGE cpu consumers.  &lt;br /&gt;
&lt;br /&gt;
If you discover your applications do not use bind variables -- you must have this &lt;br /&gt;
corrected.  You&amp;#039;ll never have a good hit ratio if everyone submits &amp;quot;unique&amp;quot; sql.  Your &lt;br /&gt;
shared pool will never be used right and you&amp;#039;ll be using excessive CPU (90% of the time &lt;br /&gt;
it takes to process &amp;quot;insert into t values ( 1 )&amp;quot; is parsing.  If you use &amp;quot;insert into t &lt;br /&gt;
values ( :x )&amp;quot;, and bind the value of 1 -- then the next person that runs that insert &lt;br /&gt;
will benefit from your work and run that much faster. &lt;br /&gt;
...&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Advice from Oracle concerning a concrete (12c) example of unable to allocate 52824 bytes of shared memory (&amp;quot;shared pool&amp;quot;,...====&lt;br /&gt;
This was from a ticket raised for a Data Pump export that consistently failed with:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Processing object type SCHEMA_EXPORT/TABLE/PROCACT_INSTANCE&lt;br /&gt;
Processing object type SCHEMA_EXPORT/TABLE/TABLE&lt;br /&gt;
ORA-39014: One or more workers have prematurely exited.&lt;br /&gt;
ORA-39029: worker 1 with process name &amp;quot;DW00&amp;quot; prematurely terminated&lt;br /&gt;
ORA-31671: Worker process DW00 had an unhandled exception.&lt;br /&gt;
ORA-04031: unable to allocate 52824 bytes of shared memory (&amp;quot;shared pool&amp;quot;,&amp;quot;unknown object&amp;quot;,&amp;quot;KTSL subheap&amp;quot;,&amp;quot;ktsl_load_disp-2&amp;quot;)&lt;br /&gt;
ORA-06512: at &amp;quot;SYS.KUPW$WORKER&amp;quot;, line 2122&lt;br /&gt;
ORA-06512: at line 2&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
The error ORA-4031 on the shared pool can indicate one of two things:&lt;br /&gt;
- insufficient space for the shared pool (so insufficient memory in SGA at that time)&lt;br /&gt;
OR&lt;br /&gt;
- although there is enough memory, it is fragmented and no contiguous chunk can be allocated to satisfy the latest memory request.&lt;br /&gt;
&lt;br /&gt;
Each SGA has a little fragmentation of course because of the operations taking place, so in your case the fragmentation is represented by the 18M of free memory, which exists in uncontiguous chunks.&lt;br /&gt;
This means that the root cause of the error is insufficient contiguous memory to allocate 12312 bytes of shared memory.&lt;br /&gt;
&lt;br /&gt;
ACTION PLAN&lt;br /&gt;
==============&lt;br /&gt;
1. We see memory_target=2000M. This is too little to support a 12c database, even when it has little activity.&lt;br /&gt;
As you may know 1.7G for the SGA was acceptable when speaking of 32bit OSs where it was hardly possible to make use of more than that.&lt;br /&gt;
Since you have a 64 bit system, the addressable memory is virtually unlimited.&lt;br /&gt;
Furthermore, by using AMM (memory_target&amp;gt;0) this memory is divided between the SGA and the PGA (the user processes) which in fact, depending on the number of connections, can limit the SGA even more.&lt;br /&gt;
So the first recommendation is to increase the value of memory_target to 4G for example. There is no ideal value, but this would be a reasonable starting value for tuning.&lt;br /&gt;
&lt;br /&gt;
You can do further tuning of the memory using the view V$MEMORY_TARGET_ADVICE.&lt;br /&gt;
The view V$MEMORY_TARGET_ADVICE provides tuning advice for the MEMORY_TARGET initialization parameter:&lt;br /&gt;
SQL&amp;gt; SELECT * FROM v$memory_target_advice ORDER BY memory_size;&lt;br /&gt;
&lt;br /&gt;
The dynamic performance view V$MEMORY_DYNAMIC_COMPONENTS shows the current sizes of all dynamically tuned memory components, including the total sizes of the SGA and instance PGA.&lt;br /&gt;
&lt;br /&gt;
You can also use V$MEMORY_RESIZE_OPS which has a circular history buffer of the last 800 memory resize requests.&lt;br /&gt;
&lt;br /&gt;
2. Since the AMM (you have memory_target&amp;gt;0) is used, then make sure to set:&lt;br /&gt;
 _shared_pool_reserved_pct to 10 or 15 to ensure that when the Shared Pool grows or shrinks automatically, the Reserved Area will change as well.&lt;br /&gt;
&lt;br /&gt;
SQL&amp;gt; alter system set &amp;quot;_shared_pool_reserved_pct&amp;quot;=15 scope=spfile;&lt;br /&gt;
--restart the instance&lt;br /&gt;
&lt;br /&gt;
FYI: By default, Oracle configures a small Reserved Pool (or Reserved Area) inside the Shared Pool.&lt;br /&gt;
This memory can be used for operations such as PL/SQL and trigger compilation or for temporary space while loading Java objects.&lt;br /&gt;
After the memory allocated from the Reserved Pool is freed, it returns to the Reserved Pool.&lt;br /&gt;
5% of the Shared Pool is set aside as the Reserved Pool to handle allocations of memory higher than defined by the hidden parameter _shared_pool_reserved_pct.&lt;br /&gt;
In some application environments, 5% is too small.&lt;br /&gt;
&lt;br /&gt;
3. Set shared_pool_size=500M or even more. This will represent a minimum amount of memory that will always be available to the shared pool.&lt;br /&gt;
If more memory is needed at any moment, if it is available, it will be allocated to the shared pool over the 500M.&lt;br /&gt;
&lt;br /&gt;
Implement the above steps, monitor the database and let us know the result,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORA-00392: log 1 of thread 1 is being cleared, operation not allowed===&lt;br /&gt;
After performing an active duplication, this happened when trying to open the database.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SQL&amp;gt; alter database open resetlogs&lt;br /&gt;
alter database open resetlogs&lt;br /&gt;
*&lt;br /&gt;
ERROR at line 1:&lt;br /&gt;
ORA-00392: log 1 of thread 1 is being cleared, operation not allowed&lt;br /&gt;
ORA-00312: online log 1 thread 1: &amp;#039;/oracle/oradata/testdb/redo/redo01.log&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SQL&amp;gt; select group#,thread#,status from v$log;&lt;br /&gt;
 &lt;br /&gt;
GROUP#   THREAD#   STATUS&lt;br /&gt;
-------  --------- ----------------&lt;br /&gt;
1        1         CLEARING_CURRENT&lt;br /&gt;
2        1         STALE&lt;br /&gt;
3        1         STALE&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Check the alert log! Always a good idea to get extra info. In here we find the answer&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ORA-00344: unable to re-create online log&lt;br /&gt;
&amp;#039;/oracle/oradata/testdb/redo/redo01.log&amp;#039;&lt;br /&gt;
ORA-27040: file create error, unable to create file&lt;br /&gt;
Linux-x86_64 Error: 2: No such file or directory&lt;br /&gt;
Additional information: 1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
So the clue is that the file cannot be created at the operating system level.&amp;lt;br /&amp;gt;&lt;br /&gt;
Doing a &amp;lt;code&amp;gt;df -k /oracle/oradata/testdb/redo&amp;lt;/code&amp;gt; shows us that the filesystem was created too small for the destination database.&amp;lt;br /&amp;gt;&lt;br /&gt;
In this case, we do not want the redolog directory to be as big as on the source db as there will be almost no movement on the destination.&amp;lt;br /&amp;gt;&lt;br /&gt;
I should have specified the LOGFILE parameter in the DUPLICATE clause to setup new, smaller redolog files.&amp;lt;br /&amp;gt;&lt;br /&gt;
As this duplicate takes over 12 hours, I didn&amp;#039;t want to do it again so I created symbolic links in the redolog directory pointing out to a larger filesystem with more space.&amp;lt;br /&amp;gt;&lt;br /&gt;
This allowed the creation of the redolog files. They can then be resized once the database has been opened.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cd /oracle/oradata/testdb/redo&lt;br /&gt;
ln -s /tmp/redo01.log redo01.log&lt;br /&gt;
ln -s /tmp/redo02.log redo02.log&lt;br /&gt;
ln -s /tmp/redo03.log redo03.log&lt;br /&gt;
&lt;br /&gt;
SQL&amp;gt; alter database open resetlogs&lt;br /&gt;
Database opened.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===RMAN-04004: error from recovery catalog database: ORA-01017: invalid username/password; logon denied===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
oracle@host:/export/home/ora&amp;gt; rman target / catalog catowner/catpass@catdb&lt;br /&gt;
&lt;br /&gt;
Recovery Manager: Release 11.2.0.2.0 - Production on Thu Jun 12 16:51:03 2014&lt;br /&gt;
&lt;br /&gt;
Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.&lt;br /&gt;
&lt;br /&gt;
connected to target database: XXXXRAP1 (DBID=3557010742)&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-00554: initialization of internal recovery manager package failed&lt;br /&gt;
RMAN-04004: error from recovery catalog database: ORA-01017: invalid username/password; logon denied&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This is normally very straight-forward and self-explanatory.&amp;lt;br /&amp;gt;&lt;br /&gt;
The puzzle here is that a connection from SQL*Plus works!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sqlplus catowner/catpass@catdb&lt;br /&gt;
&lt;br /&gt;
SQL*Plus: Release 11.2.0.2.0 Production on Thu Jun 12 16:53:18 2014&lt;br /&gt;
&lt;br /&gt;
Copyright (c) 1982, 2010, Oracle.  All rights reserved.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Connected to:&lt;br /&gt;
Oracle Database 12c Enterprise Edition Release 12.1.0.1.0 - 64bit Production&lt;br /&gt;
With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options&lt;br /&gt;
SQL&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Eventually worked out that the rman binary in the databases ORACLE_HOME on the source machine needed relinking!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cd $ORACLE_HOME/rdbms/lib&lt;br /&gt;
make -f ins_rdbms.mk irman &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORA-00230: operation disallowed: snapshot control file enqueue unavailable===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
waiting for snapshot control file enqueue&lt;br /&gt;
waiting for snapshot control file enqueue&lt;br /&gt;
waiting for snapshot control file enqueue&lt;br /&gt;
waiting for snapshot control file enqueue&lt;br /&gt;
cannot make a snapshot control file&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-03008: error while performing automatic resync of recovery catalog&lt;br /&gt;
ORA-00230: operation disallowed: snapshot control file enqueue unavailable&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
From the doc...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
When RMAN needs to back up or resynchronize from the control file, it first creates a snapshot or consistent image of the control file.&lt;br /&gt;
If one RMAN job is already backing up the control file while another needs to create a new snapshot control file, then you may see the following message:&lt;br /&gt;
&lt;br /&gt;
waiting for snapshot controlfile enqueue&lt;br /&gt;
&lt;br /&gt;
Under normal circumstances, a job that must wait for the control file enqueue waits for a brief interval and then successfully obtains the enqueue.&lt;br /&gt;
RMAN makes up to five attempts to get the enqueue and then fails the job.&lt;br /&gt;
The conflict is usually caused when two jobs are both backing up the control file, and the job that first starts backing up the control file waits for service from the media manager.&lt;br /&gt;
&lt;br /&gt;
To determine which job is holding the conflicting enqueue:&lt;br /&gt;
&lt;br /&gt;
    After you see the first message stating &amp;quot;RMAN-08512: waiting for snapshot controlfile enqueue&amp;quot;, start a new SQL*Plus session on the target database:&lt;br /&gt;
&lt;br /&gt;
    % sqlplus &amp;#039;SYS/oracle@trgt AS SYSDBA&amp;#039;&lt;br /&gt;
&lt;br /&gt;
    Execute the following query to determine which job is causing the wait:&lt;br /&gt;
&lt;br /&gt;
    SELECT s.SID, USERNAME AS &amp;quot;User&amp;quot;, PROGRAM, MODULE, &lt;br /&gt;
           ACTION, LOGON_TIME &amp;quot;Logon&amp;quot;, l.* &lt;br /&gt;
    FROM V$SESSION s, V$ENQUEUE_LOCK l&lt;br /&gt;
    WHERE l.SID = s.SID&lt;br /&gt;
    AND l.TYPE = &amp;#039;CF&amp;#039;&lt;br /&gt;
    AND l.ID1 = 0&lt;br /&gt;
    AND l.ID2 = 2;&lt;br /&gt;
&lt;br /&gt;
    You should see output similar to the following (the output in this example has been truncated):&lt;br /&gt;
&lt;br /&gt;
    SID User Program              Module                    Action           Logon&lt;br /&gt;
    --- ---- -------------------- ------------------------- ---------------- ---------&lt;br /&gt;
      9 SYS  rman@h13 (TNS V1-V3) backup full datafile: c1  0000210 STARTED  21-JUN-01&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
After you have determined which job is creating the enqueue, you can do one of the following:&lt;br /&gt;
&lt;br /&gt;
    Wait until the job creating the enqueue completes&lt;br /&gt;
    Cancel the current job and restart it after the job creating the enqueue completes&lt;br /&gt;
    Cancel the job creating the enqueue&lt;br /&gt;
&lt;br /&gt;
Commonly, enqueue situations occur when a job is writing to a tape drive, but the tape drive is waiting for a new cassette to be inserted.&lt;br /&gt;
If you start a new job in this situation, then you will probably receive the enqueue message because the first job cannot complete until the new tape is loaded.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or more directly...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 2000&lt;br /&gt;
col killer     for a70&lt;br /&gt;
col program    for a20&lt;br /&gt;
col module     for a20&lt;br /&gt;
col action     for a20&lt;br /&gt;
col logon_time for a20&lt;br /&gt;
select &amp;#039;alter system disconnect session &amp;#039;&amp;#039;&amp;#039;||s.sid||&amp;#039;,&amp;#039;||s.serial#||&amp;#039;&amp;#039;&amp;#039; immediate;&amp;#039; killer&lt;br /&gt;
,      username&lt;br /&gt;
,      program&lt;br /&gt;
,      module&lt;br /&gt;
,      action&lt;br /&gt;
,      logon_time&lt;br /&gt;
from   v$session s&lt;br /&gt;
,      v$enqueue_lock l&lt;br /&gt;
where  l.sid  = s.sid&lt;br /&gt;
and    l.type = &amp;#039;cf&amp;#039;&lt;br /&gt;
and    l.id1  = 0&lt;br /&gt;
and    l.id2  = 2&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORA-19511: non RMAN, but media manager or vendor specific failure, error text:===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-03002: failure of Duplicate Db command at 05/01/2018 14:23:09&lt;br /&gt;
RMAN-05501: aborting duplication of target database&lt;br /&gt;
RMAN-03015: error occurred in stored script Memory Script&lt;br /&gt;
ORA-27191: sbtinfo2 returned error&lt;br /&gt;
Additional information: 3586&lt;br /&gt;
ORA-19511: non RMAN, but media manager or vendor specific failure, error text:&lt;br /&gt;
   Unable to connect to NetWorker server &amp;#039;hn6000.cln.be&amp;#039; because &amp;#039;Authentication error; why = Invalid client credential&amp;#039;. (2:10:79)&lt;br /&gt;
&lt;br /&gt;
Recovery Manager complete.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
If this happens, check to see if the nsr daemon is running...&amp;lt;br /&amp;gt;&lt;br /&gt;
Good system:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/home/oracle&amp;gt; ps -ef | grep nsr&lt;br /&gt;
    root  5701836        1   0   Mar 16      - 13:18 /bin/nsrexecd&lt;br /&gt;
  oracle 18809292 22741502   0 15:03:58  pts/0  0:00 grep nsr&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Bad system:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 /home/oracle&amp;gt; ps -ef | grep nsr&lt;br /&gt;
  oracle 14745986 15139292   0 15:03:29  pts/2  0:00 grep nsr&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORA-19554: error allocating device, device type: SBT_TAPE, device name:===&lt;br /&gt;
If using Cygwin...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-03002: failure of backup command at 05/19/2015 12:25:47&lt;br /&gt;
ORA-19554: error allocating device, device type: SBT_TAPE, device name:&lt;br /&gt;
ORA-27000: skgfqsbi: failed to initialize storage subsystem (SBT) layer&lt;br /&gt;
OSD-02534: Message 2534 not found;  product=RDBMS; facility=SOSD&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Check the tdpo.opt file is where you think it is!&lt;br /&gt;
* Check the path to the opt file looks like this (needs to be Windows format):&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
CONFIGURE CHANNEL DEVICE TYPE &amp;#039;SBT_TAPE&amp;#039; FORMAT   &amp;#039;LOG_%d_t%t_s%s_u%U&amp;#039; PARMS  &amp;#039;ENV=(TDPO_OPTFILE=E:\oracle\KITRYD\admin\tdpo.opt)&amp;#039;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Check the content of the opt file is Windows format paths!&lt;br /&gt;
&lt;br /&gt;
===RMAN-20033: control file SEQUENCE# too low===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-03008: error while performing automatic resync of recovery catalog&lt;br /&gt;
===RMAN-20033: control file SEQUENCE# too low===&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
From [https://forums.oracle.com/forums/thread.jspa?threadID=1115969 forums.oracle.com]&amp;lt;br /&amp;gt;&lt;br /&gt;
This error generally happens if an archivelog backup happens while the RMAN database backup is running and if controlfile autobackup is configured.&amp;lt;br /&amp;gt;&lt;br /&gt;
The database backup is usually successful and it is just the controlfile backup that fails.&lt;br /&gt;
===ORA-27302: failure occurred at: slgpn===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
RMAN-03009: failure of Control File and SPFILE Autobackup command on c1 channel at 06/28/2011 18:59:38&lt;br /&gt;
ORA-19715: invalid format %b for generated name&lt;br /&gt;
ORA-27302: failure occurred at: slgpn&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Problem====&lt;br /&gt;
When doing a &amp;quot;&amp;lt;tt&amp;gt;backup as copy database&amp;lt;/tt&amp;gt;&amp;quot;, got these errors after 145 of 147 datafiles had been backed up!&lt;br /&gt;
&lt;br /&gt;
====Investigation====&lt;br /&gt;
I had read [https://oracleedge.wordpress.com/2011/06/29/oracle-rman-03009-ora-19715-ora-27302/ elsewhere] that this could be something to do with the format of the autobackup of the control file so I changed the format as suggested and reran the backup.&amp;lt;br /&amp;gt;&lt;br /&gt;
No luck. It ended exactly the same way after 145 files. I decided to compare the original list of datafiles with those that had been backed up in order to track down the 2 failures. Maybe I could see something odd with them.&amp;lt;br /&amp;gt;&lt;br /&gt;
Sure enough, these 2 files were different... there was a space at the &amp;#039;&amp;#039;&amp;#039;end&amp;#039;&amp;#039;&amp;#039; of the filenames :-)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select &amp;#039;x&amp;#039;||file_name||&amp;#039;x&amp;#039;&lt;br /&gt;
from   dba_data_files&lt;br /&gt;
where  file_name like &amp;#039;% %&amp;#039;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Solution====&lt;br /&gt;
Run the backup of the other 2 datafiles with a different format that did not rely on the filename.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
run {&lt;br /&gt;
    allocate channel c1 device type disk format &amp;#039;/path/to/datafiles/%U&amp;#039;;&lt;br /&gt;
    backup as copy datafile 170;&lt;br /&gt;
    backup as copy datafile 171;&lt;br /&gt;
    backup as copy current controlfile;&lt;br /&gt;
    release channel c1;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The other 145 datafiles were backed up with a format of &amp;#039;/path/to/datafiles/%b&amp;#039; which preserves the filenames so all that needs to be done is rename the other 2 after the backup finishes.&amp;lt;br /&amp;gt;&lt;br /&gt;
If they are going to be used in a restore scenario, they should be renamed in the controlfile also.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter database rename file &amp;#039;/path/to/datafiles/filename_with_a_space_at_end &amp;#039; to &amp;#039;/path/to/datafiles/filename_without_a_space&amp;#039;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===RMAN errors after crosscheck backup and delete noprompt obsolete and delete noprompt expired backup===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
RMAN-06207: WARNING: 3921 objects could not be deleted for SBT_TAPE channel(s) due&lt;br /&gt;
RMAN-06208:          to mismatched status.  Use CROSSCHECK command to fix status&lt;br /&gt;
RMAN-06210: List of Mismatched objects&lt;br /&gt;
RMAN-06211: ==========================&lt;br /&gt;
RMAN-06212:   Object Type   Filename/Handle&lt;br /&gt;
RMAN-06213: --------------- ---------------------------------------------------&lt;br /&gt;
RMAN-06214: Backup Piece    DB_SID_t20140316_s263889_umhp3bpa7_1_1&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Use the FORCE option with the DELETE command&amp;lt;br /&amp;gt;&lt;br /&gt;
The FORCE command tells RMAN to clean the information out of the catalog regardless of whether it can find it on the media or not.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
delete force noprompt expired backup;&lt;br /&gt;
delete force noprompt obsolete;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===RMAN-06004: ORACLE error from recovery catalog database: RMAN-20003: target database incarnation not found in recovery catalog===&lt;br /&gt;
====Problem:====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-03002: failure of Duplicate Db command at 12/05/2017 11:11:15&lt;br /&gt;
RMAN-05501: aborting duplication of target database&lt;br /&gt;
RMAN-03015: error occurred in stored script Memory Script&lt;br /&gt;
RMAN-06004: ORACLE error from recovery catalog database: RMAN-20003: target database incarnation not found in recovery catalog&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Solution:====&lt;br /&gt;
Strangely, this means, in my particular case, that block change tracking is turned on in the target databse and needs turning off in the auxiliary while the DUPLICATE is running.&amp;lt;br /&amp;gt;&lt;br /&gt;
It must be done while the auxiliary is in mount mode and restoring the datafiles (before recovery starts)&amp;lt;br /&amp;gt;&lt;br /&gt;
It is reported to be a bug fixed in 11.1 but somehow, we&amp;#039;re still (sometimes) getting it in 12.1.0.2.&lt;br /&gt;
&lt;br /&gt;
===RMAN-06059: expected archived log not found, loss of archived log compromises recoverability===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
RMAN-06059: expected archived log not found, loss of archived log compromises recoverability&lt;br /&gt;
ORA-19625: error identifying file &amp;lt;filename&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This error can come from the fact that the database files (more likely archivelogs) are being deleted by the operating system so RMAN has no clue of their whereabouts.&amp;lt;br /&amp;gt;&lt;br /&gt;
Possibly result of a database duplication and the catalog has not updated properly?&amp;lt;br /&amp;gt;&lt;br /&gt;
====Solution====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
crosscheck archivelog all;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
And then maybe take a backup to be on the safe side.&lt;br /&gt;
&lt;br /&gt;
===RMAN-05537: DUPLICATE without TARGET connection when auxiliary instance is started with spfile cannot use SPFILE clause===&lt;br /&gt;
====Problem:====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-03002: failure of Duplicate Db command at 12/05/2017 14:17:49&lt;br /&gt;
RMAN-05501: aborting duplication of target database&lt;br /&gt;
RMAN-05537: DUPLICATE without TARGET connection when auxiliary instance is started with spfile cannot use SPFILE clause&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Usually happens after restarting a failed RMAN DUPLICATE database. The spfile has been regenerated on the auxiliary to a level where it has too much detail in it.&lt;br /&gt;
====Solution:====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ cd $ORACLE_HOME/dbs&lt;br /&gt;
$ ls -altr *dwh_perf*&lt;br /&gt;
-rw-r-----    1 oracle   oinstall   17645568 Aug  3 13:34 snapcf_dwh_perf.f&lt;br /&gt;
-rw-r-----    1 oracle   oinstall       7680 Nov  4 09:22 orapwdwh_perf&lt;br /&gt;
-rw-r--r--    1 oracle   oinstall        104 Dec  5 09:34 initdwh_perf.ora&lt;br /&gt;
-rw-r-----    1 oracle   oinstall       6656 Dec  5 11:11 spfiledwh_perf.ora&lt;br /&gt;
-rw-rw----    1 oracle   oinstall       1544 Dec  5 14:18 hc_dwh_perf.dat&lt;br /&gt;
$ mv hc_dwh_perf.dat hc_dwh_perf.dat.old&lt;br /&gt;
$ mv spfiledwh_perf.ora spfiledwh_perf.ora.old&lt;br /&gt;
$ cat initdwh_perf.ora&lt;br /&gt;
sga_max_size=&amp;#039;6G&amp;#039;&lt;br /&gt;
sga_target=&amp;#039;6G&amp;#039;&lt;br /&gt;
compatible=&amp;#039;12.0.0&amp;#039;&lt;br /&gt;
db_files=&amp;#039;500&amp;#039;&lt;br /&gt;
&lt;br /&gt;
# Instance name&lt;br /&gt;
db_name=dwh_perf&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Re-run the DUPLICATE. It should zoom past the already recovered datafiles.&lt;br /&gt;
&lt;br /&gt;
===PSDRPC returns significant error 1013===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
archived log thread=1 sequence=195008&lt;br /&gt;
channel t2: reading from backup piece arclog_LBK_4260753020_946042770_479194_1&lt;br /&gt;
channel t0: piece handle=arclog_LBK_4260753020_946042770_479192_1 tag=TAG20170607T133757&lt;br /&gt;
channel t0: restored backup piece 1&lt;br /&gt;
channel t0: restore complete, elapsed time: 00:00:35&lt;br /&gt;
archived log file name=/xxxxxx/acc/ora_bin2/app/oracle/product/11.2.0.4/dbhome_1/dbs/arch1_195006_815790039.dbf thread=1 sequence=195006&lt;br /&gt;
PSDRPC returns significant error 1013.&lt;br /&gt;
PSDRPC returns significant error 1013.&lt;br /&gt;
released channel: t0&lt;br /&gt;
released channel: t1&lt;br /&gt;
released channel: t2&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-03002: failure of Duplicate Db command at 06/09/2017 15:15:04&lt;br /&gt;
RMAN-05501: aborting duplication of target database&lt;br /&gt;
RMAN-03015: error occurred in stored script Memory Script&lt;br /&gt;
RMAN-11003: failure during parse/execution of SQL statement: alter database recover logfile &amp;#039;/xxxxxx/acc/ora_bin2/app/oracle/product/11.2.0.4/dbhome_1/dbs/arch1_195006_815790039.dbf&amp;#039;&lt;br /&gt;
ORA-10877: error signaled in parallel recovery slave&lt;br /&gt;
&lt;br /&gt;
Recovery Manager complete.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Action====&lt;br /&gt;
Check the alert log on the auxiliary instance.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ORA-279 signalled during: alter database recover logfile &amp;#039;/xxxxxx/acc/ora_bin2/app/oracle/product/11.2.0.4/dbhome_1/dbs/arch1_195005_815790039.dbf&amp;#039;...&lt;br /&gt;
alter database recover logfile &amp;#039;/xxxxxx/acc/ora_bin2/app/oracle/product/11.2.0.4/dbhome_1/dbs/arch1_195006_815790039.dbf&amp;#039;&lt;br /&gt;
Media Recovery Log /xxxxxx/acc/ora_bin2/app/oracle/product/11.2.0.4/dbhome_1/dbs/arch1_195006_815790039.dbf&lt;br /&gt;
Fri Jun 09 07:30:30 2017&lt;br /&gt;
Errors with log /xxxxxx/acc/ora_bin2/app/oracle/product/11.2.0.4/dbhome_1/dbs/arch1_195006_815790039.dbf&lt;br /&gt;
Recovery interrupted!&lt;br /&gt;
Recovered data files to a consistent state at change 238029030495&lt;br /&gt;
Media Recovery failed with error 19755&lt;br /&gt;
Errors in file /xxxxxx/acc/ora_bin2/app/oracle/diag/rdbms/lbkro/lbkro/trace/lbkro_pr00_13108374.trc:&lt;br /&gt;
ORA-00283: recovery session canceled due to errors&lt;br /&gt;
===&amp;gt;ORA-19755: could not open change tracking file&lt;br /&gt;
===&amp;gt;ORA-19750: change tracking file: &amp;#039;/xxxxxx/exp/ora_data2/lbk/data/bct_lbk_do_not_delete.f&lt;br /&gt;
===&amp;gt;ORA-27037: unable to obtain file status&lt;br /&gt;
===&amp;gt;IBM AIX RISC System/6000 Error: 2: No such file or directory&lt;br /&gt;
Additional information: 3&lt;br /&gt;
Fri Jun 09 07:30:36 2017&lt;br /&gt;
ORA-10877 signalled during: alter database recover logfile &amp;#039;/xxxxxx/acc/ora_bin2/app/oracle/product/11.2.0.4/dbhome_1/dbs/arch1_195006_815790039.dbf&amp;#039;...&lt;br /&gt;
Fri Jun 09 14:04:57 2017&lt;br /&gt;
alter database recover logfile &amp;#039;/xxxxxx/acc/ora_bin2/app/oracle/product/11.2.0.4/dbhome_1/dbs/arch1_195006_815790039.dbf&amp;#039;&lt;br /&gt;
Media Recovery Log /xxxxxx/acc/ora_bin2/app/oracle/product/11.2.0.4/dbhome_1/dbs/arch1_195006_815790039.dbf&lt;br /&gt;
Media Recovery failed with error 1112&lt;br /&gt;
ORA-283 signalled during: alter database recover logfile &amp;#039;/xxxxxx/acc/ora_bin2/app/oracle/product/11.2.0.4/dbhome_1/dbs/arch1_195006_815790039.dbf&amp;#039;...&lt;br /&gt;
Fri Jun 09 14:31:20 2017&lt;br /&gt;
Shutting down instance (immediate)&lt;br /&gt;
Shutting down instance: further logons disabled&lt;br /&gt;
Stopping background process MMNL&lt;br /&gt;
Stopping background process MMON&lt;br /&gt;
License high water mark = 49&lt;br /&gt;
ALTER DATABASE CLOSE NORMAL&lt;br /&gt;
ORA-1109 signalled during: ALTER DATABASE CLOSE NORMAL...&lt;br /&gt;
ALTER DATABASE DISMOUNT&lt;br /&gt;
Shutting down archive processes&lt;br /&gt;
Archiving is disabled&lt;br /&gt;
Completed: ALTER DATABASE DISMOUNT&lt;br /&gt;
ARCH: Archival disabled due to shutdown: 1089&lt;br /&gt;
Shutting down archive processes&lt;br /&gt;
Archiving is disabled&lt;br /&gt;
ARCH: Archival disabled due to shutdown: 1089&lt;br /&gt;
Shutting down archive processes&lt;br /&gt;
Archiving is disabled&lt;br /&gt;
Fri Jun 09 14:31:24 2017&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This is a known bug. it is fixed in 11.2.0.3 but... this customer does not apply patches!&lt;br /&gt;
&lt;br /&gt;
====Solution====&lt;br /&gt;
While the DUPLICATE is running (and in MOUNT mode), log on to the auxiliary instance and disable block change tracking.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter database disable block change tracking;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
A documented workaround is to set db_filename_convert parameter in the DUPLICATE clause of the run block but I tried this and it failed again.&amp;lt;br /&amp;gt;&lt;br /&gt;
The obvious solution is to patch the database but...&lt;br /&gt;
&lt;br /&gt;
===Database trigger to capture ORA errors===&lt;br /&gt;
From [http://ora-ssn.blogspot.be/2011/10/trigger-on-database-to-capture-ora.html ora-ssn.blogspot.be]&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
CREATE TABLE stats$error_log (&lt;br /&gt;
        err_dt          TIMESTAMP,&lt;br /&gt;
        db_user         VARCHAR2(30),&lt;br /&gt;
        msg_stack       VARCHAR2(2000),&lt;br /&gt;
        sqltxt          VARCHAR2(1000))&lt;br /&gt;
tablespace users;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Now, create a trigger on the database server.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
CREATE OR REPLACE TRIGGER log_server_errors&lt;br /&gt;
  AFTER SERVERERROR&lt;br /&gt;
  ON DATABASE&lt;br /&gt;
DECLARE&lt;br /&gt;
          v_sqltext VARCHAR2(1000);&lt;br /&gt;
          nl_sqltext ora_name_list_t;&lt;br /&gt;
  BEGIN&lt;br /&gt;
          -- Capture entire error text&lt;br /&gt;
          FOR i IN 1 .. ora_sql_txt(nl_sqltext) LOOP&lt;br /&gt;
            v_sqltext := v_sqltext || nl_sqltext(i);&lt;br /&gt;
          END LOOP;&lt;br /&gt;
          INSERT INTO STATS$ERROR_LOG&lt;br /&gt;
          (err_dt, db_user, msg_stack, sqltxt)&lt;br /&gt;
          VALUES&lt;br /&gt;
          (systimestamp,&lt;br /&gt;
           sys.login_user,&lt;br /&gt;
           dbms_utility.format_error_stack, v_sqltext);&lt;br /&gt;
  END log_server_errors;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORA-19809: limit exceeded for recovery files===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-03009: failure of backup command on ORA_DISK_1 channel at 07/15/2013 10:10:59&lt;br /&gt;
ORA-19809: limit exceeded for recovery files&lt;br /&gt;
ORA-19804: cannot reclaim 274716160 bytes disk space from 1468006400 limit&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    ORA-19809: limit exceeded for recovery files&lt;br /&gt;
    Cause: The limit for recovery files specified by the db_recovery_file_dest_size was exceeded.&lt;br /&gt;
&lt;br /&gt;
    Action: The error is accompanied by 19804. See message 19804 for further details&lt;br /&gt;
&lt;br /&gt;
    ORA-19804: cannot reclaim string bytes disk space from string limit&lt;br /&gt;
    Cause: Oracle cannot reclaim disk space of specified bytes from the DB_RECOVERY_FILE_DEST_SIZE limit.&lt;br /&gt;
&lt;br /&gt;
    Action: There are five possible solutions:&lt;br /&gt;
       1) Take frequent backup of recovery area using RMAN.&lt;br /&gt;
       2) Consider changing RMAN retention policy.&lt;br /&gt;
       3) Consider changing RMAN archivelog deletion policy.&lt;br /&gt;
       4) Add disk space and increase DB_RECOVERY_FILE_DEST_SIZE.&lt;br /&gt;
       5) Delete files from recovery area using RMAN.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The solution here is to increase the value of db_recovery_file_dest_size but it might also indicate a problem with tapes if the archivelogs are being backed up to tape via tdpo.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SYS@DN7&amp;gt; alter system set db_recovery_file_dest_size=4000M scope=both;&lt;br /&gt;
&lt;br /&gt;
System altered.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Looking into int further, saw RMAN parameters missing...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
CONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF 14 DAYS;&lt;br /&gt;
CONFIGURE BACKUP OPTIMIZATION OFF;&lt;br /&gt;
CONFIGURE DEFAULT DEVICE TYPE TO &amp;#039;SBT_TAPE&amp;#039;;&lt;br /&gt;
CONFIGURE CONTROLFILE AUTOBACKUP ON;&lt;br /&gt;
CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE &amp;#039;SBT_TAPE&amp;#039; TO &amp;#039;LOG_%d_controlfile_%F.rman&amp;#039;;&lt;br /&gt;
CONFIGURE DEVICE TYPE &amp;#039;SBT_TAPE&amp;#039; PARALLELISM 1 BACKUP TYPE TO BACKUPSET;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===RMAN-00554: initialization of internal recovery manager package failed===&lt;br /&gt;
Getting this error after migrating a database from one machine to another and attaching to a nice new version 12c catalog on the new server&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Recovery Manager: Release 11.2.0.2.0 - Production on Sat Jun 21 13:16:24 2014&lt;br /&gt;
&lt;br /&gt;
Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.&lt;br /&gt;
&lt;br /&gt;
connected to target database: SPMSUPP1 (DBID=3026014394)&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-00554: initialization of internal recovery manager package failed&lt;br /&gt;
RMAN-04004: error from recovery catalog database: ORA-01017: invalid username/password; logon denied&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
We cannot connect to the catalog via rman but there is no problem if connecting via SQL*Plus!&amp;lt;br /&amp;gt;&lt;br /&gt;
Solution: relink the rman executable.&lt;br /&gt;
===Using AIX commands genld, genkld and slibclean to avoid library file locking errors (libjox) (Doc ID 739963.1)===&lt;br /&gt;
* [https://support.oracle.com/epmos/faces/DocumentDisplay?_afrLoop=206851390914720&amp;amp;id=739963.1&amp;amp;_afrWindowMode=0&amp;amp;_adf.ctrl-state=e0pq23tou_4 Metalink]&lt;br /&gt;
When installing interim (one-off) patches, CPU patches or patchsets, you may encounter some errors with regards to files being locked or oui/opatch being unable to copy files&amp;lt;br /&amp;gt;&lt;br /&gt;
even though the databases, listeners and all other Oracle processes associated with the ORACLE_HOME to be patched were stopped.&amp;lt;br /&amp;gt;&lt;br /&gt;
This could be as result of a process which requires termination or an additional file needing to be unloaded from the system cache.&amp;lt;br /&amp;gt;&lt;br /&gt;
Run following commands to clean up...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
genld -l | grep &amp;lt;ORACLE_HOME&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
If genld returns data then a currently executing process has something open in the ORACLE_HOME directory, therefore terminate the process as required/recommended.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
genkld | grep &amp;lt;ORACLE_HOME&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
If the genkld command  returns a  list of shared objects currently loaded onto the OS system cache then please remove the entries from the OS system cache by running the slibclean command as root user:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/usr/sbin/slibclean&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===ORA-20011: Approximate NDV failed: ORA-29913: error in executing ODCIEXTTABLEOPEN callout===&lt;br /&gt;
This seems to be related to orphaned Datapump tables. Generally seems to be a problem when stats jobs are running during the night (dbms_stats)&amp;lt;br /&amp;gt;&lt;br /&gt;
* Check no datapump jobs are running&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select * from dba_datapump_jobs;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Find orphaned tables&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 2000&lt;br /&gt;
select owner&lt;br /&gt;
,      object_name&lt;br /&gt;
,      object_type&lt;br /&gt;
,      status&lt;br /&gt;
,      to_char(created,&amp;#039;dd-mon-yyyy hh24:mi:ss&amp;#039;) created&lt;br /&gt;
,      to_char(last_ddl_time,&amp;#039;dd-mon-yyyy hh24:mi:ss&amp;#039;) last_ddl_time&lt;br /&gt;
from   dba_objects&lt;br /&gt;
where  1=1&lt;br /&gt;
and    object_name like &amp;#039;ET$%&amp;#039;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Check that  any rows seen are actually external tables&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select owner&lt;br /&gt;
,      table_name&lt;br /&gt;
,      default_directory_name&lt;br /&gt;
,      access_type&lt;br /&gt;
from   dba_external_tables&lt;br /&gt;
order  by 1,2&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Drop the tables if they are not currently being used (no datapump jobs running)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
drop table &amp;amp;&amp;amp;owner..&amp;amp;table_name;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===ORA-01547: warning: RECOVER succeeded but OPEN RESETLOGS would get error below===&lt;br /&gt;
Database is restored and now we want to recover it but we see this...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Starting recover at 24-JUL-15 11:26:19&lt;br /&gt;
&lt;br /&gt;
starting media recovery&lt;br /&gt;
&lt;br /&gt;
unable to find archive log&lt;br /&gt;
archive log thread=1 sequence=69763&lt;br /&gt;
Oracle Error: &lt;br /&gt;
ORA-01547: warning: RECOVER succeeded but OPEN RESETLOGS would get error below&lt;br /&gt;
ORA-01194: file 1 needs more recovery to be consistent&lt;br /&gt;
ORA-01110: data file 1: &amp;#039;/oracle/TRSCRP1/oradata2/system01.dbf&amp;#039;&lt;br /&gt;
&lt;br /&gt;
released channel: c1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This means that although we have restored the database, we are still missing information to complete the recovery. This information is contained in the archived redo logs which must also be restored (from tape if they are no longer on disk)&amp;lt;br /&amp;gt;&lt;br /&gt;
We can see here that we need an archive log with sequence number 69763. But what is the file called and where should it be restored to?&amp;lt;br /&amp;gt;&lt;br /&gt;
For this we can go to SQL*Plus and get the database to tell us&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
recover database using backup controlfile until cancel;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
and cancel straight away.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ORA-00279: change 13796376414661 generated at 07/14/2015 13:20:07 needed for&lt;br /&gt;
thread 1&lt;br /&gt;
ORA-00289: suggestion : /oracle/TRSCRP1/archive/arch_TRSCRP1_1_69763.arc&lt;br /&gt;
ORA-00280: change 13796376414661 for thread 1 is in sequence #69763&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Specify log: {&amp;lt;RET&amp;gt;=suggested | filename | AUTO | CANCEL}&lt;br /&gt;
cancel&lt;br /&gt;
ORA-01547: warning: RECOVER succeeded but OPEN RESETLOGS would get error below&lt;br /&gt;
ORA-01194: file 1 needs more recovery to be consistent&lt;br /&gt;
ORA-01110: data file 1: &amp;#039;/oracle/TRSCRP1/oradata2/system01.dbf&amp;#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
ORA-01112: media recovery not started&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Now we see that we need to find a file called arch_TRSCRP1_1_69763.arc and put it in the directory /oracle/TRSCRP1/archive.&amp;lt;br /&amp;gt;&lt;br /&gt;
This will continue up until the time specified for the recover so restore a whole bunch of them.&amp;lt;br /&amp;gt;&lt;br /&gt;
Repeat the &amp;quot;recover database using backup controlfile until cancel;&amp;quot; command and type AUTO or Enter until you&amp;#039;ve got to where you need to be.&amp;lt;br /&amp;gt;&lt;br /&gt;
Type CANCEL when point is reached and&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter database open resetlogs;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Stuart</name></author>	</entry>

	<entry>
		<id>https://mailnest.com/dbawiki/index.php?title=Oracle_errors&amp;diff=3355</id>
		<title>Oracle errors</title>
		<link rel="alternate" type="text/html" href="https://mailnest.com/dbawiki/index.php?title=Oracle_errors&amp;diff=3355"/>
				<updated>2018-11-03T13:19:34Z</updated>
		
		<summary type="html">&lt;p&gt;Stuart: /* ORA-14097: column type or size mismatch in ALTER TABLE EXCHANGE PARTITION */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;===ORA-00600===&lt;br /&gt;
[https://support.oracle.com/epmos/faces/DocContentDisplay?_afrLoop=397490397952859&amp;amp;id=1092832.1&amp;amp;_afrWindowMode=0&amp;amp;_adf.ctrl-state=184vwc6g3y_4 Master Note for Diagnosing ORA-600 (Doc ID 1092832.1)]&lt;br /&gt;
===ORA-19051: Cannot use fast path insert for this XMLType table===&lt;br /&gt;
Think LD_LIBRARY_PATH on Linux or LIBPATH on AIX.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Export: Release 11.2.0.4.0 - Production on Thu Jun 1 06:41:55 2017&lt;br /&gt;
&lt;br /&gt;
Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.&lt;br /&gt;
&lt;br /&gt;
Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production&lt;br /&gt;
With the Partitioning, OLAP, Data Mining and Real Application Testing options&lt;br /&gt;
Starting &amp;quot;DWH_EXPORT&amp;quot;.&amp;quot;SYS_EXPORT_TABLE_03&amp;quot;:  dwh_export/******** parfile=cadis_foto_export_credit_dba.par&lt;br /&gt;
Estimate in progress using BLOCKS method...&lt;br /&gt;
Processing object type TABLE_EXPORT/TABLE/TABLE_DATA&lt;br /&gt;
Total estimation using BLOCKS method: 64.08 GB&lt;br /&gt;
ORA-39126: Worker unexpected fatal error in KUPW$WORKER.FETCH_XML_OBJECTS []&lt;br /&gt;
ORA-19051: Cannot use fast path insert for this XMLType table&lt;br /&gt;
&lt;br /&gt;
ORA-06512: at &amp;quot;SYS.DBMS_SYS_ERROR&amp;quot;, line 86&lt;br /&gt;
ORA-06512: at &amp;quot;SYS.KUPW$WORKER&amp;quot;, line 9710&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Problem====&lt;br /&gt;
When the 11g DB was started, LD_LIBRARY_PATH and LIBPATH were still pointing to paths in the 10g Home.&lt;br /&gt;
====Solution====&lt;br /&gt;
There may have been some odd values setup in LD_LIBRARY_PATH before the call to oraenv (if oraenv was indeed called!)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
unset LD_LIBRARY_PATH LIBPATH&lt;br /&gt;
export ORACLE_SID=&amp;lt;correct 11g SID&amp;gt;&lt;br /&gt;
. oraenv&lt;br /&gt;
echo $LD_LIBRARY_PATH&lt;br /&gt;
echo $LIBPATH&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
They should now be correct.&lt;br /&gt;
&lt;br /&gt;
===ORA-27092: size of file exceeds file size limit of the process===&lt;br /&gt;
Think ulimit...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Cause: an attempt was made to open a file that exceeds the process&amp;#039;s file size limit (ulimit), additional information shows the current limit (logical blocks) and the size of the file (logical blocks)&lt;br /&gt;
Action: increase the processes file size limit (ulimit) and retry&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
truncate table pibadm.test_ph&lt;br /&gt;
                      *&lt;br /&gt;
Error at line 1 :&lt;br /&gt;
ORA-00604: error ocurred at recursive SQL level 1&lt;br /&gt;
ORA-01116: error in opening database file 2&lt;br /&gt;
ORA-01110: datafile 2 : &amp;#039;/opt/u01/data/PIBQA/UNDO_01.dbf&amp;#039;&lt;br /&gt;
ORA-27092: size of file exceeds file size limit of the process&lt;br /&gt;
Additional information: 262143&lt;br /&gt;
Additional information: 2621441&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Check the fs_size limit for this user in /etc/security/limits&amp;lt;br /&amp;gt;&lt;br /&gt;
Compare this with another user, say oracle. Probably -1 (unlimited)&lt;br /&gt;
&lt;br /&gt;
===SP2-1503: Unable to initialize Oracle call interface===&lt;br /&gt;
When trying to login to the database via SQL*Plus, these messages a displayed&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
hn5118 /home/oracle $sqlplus / as sysdba&lt;br /&gt;
SP2-1503: Unable to initialize Oracle call interface&lt;br /&gt;
SP2-0152: ORACLE may not be functioning properly&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Seems to be a problem unique to AIX (in this case).&amp;lt;br /&amp;gt;&lt;br /&gt;
Check to see what the LIBPATH variable is. It may still contain a path to an old ORACLE_HOME...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
hn5118 /home/oracle $env|grep LIBPATH&lt;br /&gt;
LIBPATH=/oracle/exp/ora_bin1/app/oracle/product/10.2.0/db_1/lib:/oracle/exp/ora_bin1/app/oracle/product/10.2.0/db_1/lib&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Disco! Unset it and rerun.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
hn5118 /home/oracle $unset LIBPATH&lt;br /&gt;
&lt;br /&gt;
hn5118 /home/oracle $sqlplus / as sysdba&lt;br /&gt;
&lt;br /&gt;
SQL*Plus: Release 12.1.0.2.0 Production on Wed Jul 12 17:17:54 2017&lt;br /&gt;
&lt;br /&gt;
Copyright (c) 1982, 2014, Oracle.  All rights reserved.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Connected to:&lt;br /&gt;
Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production&lt;br /&gt;
With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options&lt;br /&gt;
&lt;br /&gt;
SQL&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===UDE-31623: operation generated ORACLE error 31623===&lt;br /&gt;
When using Data pump, get following errors almost immediately:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
UDE-31623: operation generated ORACLE error 31623&lt;br /&gt;
ORA-31623: a job is not attached to this session via the specified handle&lt;br /&gt;
ORA-06512: at &amp;quot;SYS.DBMS_DATAPUMP&amp;quot;, line 3326&lt;br /&gt;
ORA-06512: at &amp;quot;SYS.DBMS_DATAPUMP&amp;quot;, line 4551&lt;br /&gt;
ORA-06512: at line 1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Solution 1:&amp;#039;&amp;#039;&amp;#039;&amp;lt;br /&amp;gt;&lt;br /&gt;
In one case, I simplified the parameter file that was used. Maybe related to Streams Pool size, who knows?!&amp;lt;br /&amp;gt;&lt;br /&gt;
I removed these 2 lines and the export started working:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
compression_algorithm=medium&lt;br /&gt;
logtime=all&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Solution 2:&amp;#039;&amp;#039;&amp;#039;&amp;lt;br /&amp;gt;&lt;br /&gt;
There is a note about this on Metalink, 1080775.1 which suggests that Streams Pool Size needs setting.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
For this DataPump error, you will need to configure the database with some Streams Pool.&lt;br /&gt;
&lt;br /&gt;
Perform the following query to find out how much STREAMS_POOL_SIZE has been allocated&lt;br /&gt;
&lt;br /&gt;
 select * from v$sgainfo;&lt;br /&gt;
 ...&lt;br /&gt;
 Streams Pool Size                               0 Yes&lt;br /&gt;
&lt;br /&gt;
Data Pump now uses Advanced Queuing (AQ) internally, so it can handle job stops/starts/re-starts.  However, AQ using the Streams Pool, where the database currently has the STREAMS_POOL_SIZE set to ZERO.&lt;br /&gt;
&lt;br /&gt;
Manually set the STREAMS_POOL_SIZE (using ALTER SYSTEM or by changing the value in the the PFILE/SPFILE), re-start the database and re-attempt the Data Pump Export.&lt;br /&gt;
&lt;br /&gt;
Alternately, turn on Automatic Shared Memory management (ASMM) by setting SGA_TARGET or MEMORY_TARGET.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
From Oracle Documentation&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Setting the Size Of the Buffer Cache In a Streams Environment&lt;br /&gt;
&lt;br /&gt;
Oracle Data Pump uses Streams functionality to communicate between processes.&lt;br /&gt;
If the SGA_TARGET initialization parameter is set, then the STREAMS_POOL_SIZE initialization parameter is automatically set to a reasonable value.&lt;br /&gt;
If the SGA_TARGET initialization parameter is not set and the STREAMS_POOL_SIZE initialization parameter is not defined,&lt;br /&gt;
then the size of the streams pool automatically defaults to 10% of the size of the shared pool.&lt;br /&gt;
&lt;br /&gt;
When the streams pool is created, the required SGA memory is taken from memory allocated to the buffer cache,&lt;br /&gt;
reducing the size of the cache to less than what was specified by the DB_CACHE_SIZE initialization parameter.&lt;br /&gt;
This means that if the buffer cache was configured with only the minimal required SGA, then Data Pump operations may not work properly.&lt;br /&gt;
A minimum size of 10M is recommended for STREAMS_POOL_SIZE in order to ensure successful Data Pump operations.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORA-00020: maximum number of processes (150) exceeded===&lt;br /&gt;
Check the current resource limits with:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 300&lt;br /&gt;
select * from v$resource_limit;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Unfortunately this limit cannot be increased without a restart.&amp;lt;br /&amp;gt;&lt;br /&gt;
It may be a necessary to increase the limit with&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter system set processes=500 scope=spfile;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
followed by a shutdown/startup&amp;lt;br /&amp;gt;&lt;br /&gt;
Or it may be some user is running away with the limit.&amp;lt;br /&amp;gt;&lt;br /&gt;
Check to see who is running what with:&lt;br /&gt;
[[http://www.mailnest.com/dbawiki/index.php/Handy_scripts#See_what_statements_all_users_are_running See_what_statements_all_users_are_running]]&lt;br /&gt;
===ORA-01555: snapshot too old: rollback segment number nn with name &amp;quot;xxx&amp;quot; too small===&lt;br /&gt;
* [http://dfitzjarrell.wordpress.com/2008/02/22/the-dreaded-ora-01555/ Good explanation of why it happens]&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
====Problem====&lt;br /&gt;
A long running transaction has run out of space to store its read-consistent image&lt;br /&gt;
&lt;br /&gt;
====Solution 1====&lt;br /&gt;
If it&amp;#039;s a one-off, maybe leave it alone. It may have been a user leaving a session open overnight without committing or rolling back.&lt;br /&gt;
&lt;br /&gt;
====Solution 2====&lt;br /&gt;
Make sure there&amp;#039;s enough space to allow the transaction to finish.&lt;br /&gt;
&lt;br /&gt;
====Things to check====&lt;br /&gt;
How much undo did the biggest transaction take?&lt;br /&gt;
What is the undo retention parameter set to?&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 200&lt;br /&gt;
col name        for a30&lt;br /&gt;
col description for a50&lt;br /&gt;
col value       for a20&lt;br /&gt;
col maxquerylen for 999999&lt;br /&gt;
select p.name&lt;br /&gt;
,      p.description&lt;br /&gt;
,      p.value&lt;br /&gt;
,      max(u.maxquerylen) maxquerylen&lt;br /&gt;
from   v$parameter p&lt;br /&gt;
,      v$undostat  u&lt;br /&gt;
where  1=1&lt;br /&gt;
and    p.name = &amp;#039;undo_retention&amp;#039;&lt;br /&gt;
group  by p.name&lt;br /&gt;
,      p.description&lt;br /&gt;
,      p.value;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Set the retention to about 20% bigger than the maxquerylen.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select &amp;#039;alter system set undo_retention=&amp;#039;||round(1.2*max(maxquerylen))||&amp;#039; scope=both;&amp;#039; &amp;quot;Run this&amp;quot; from v$undostat;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
and set the undo retention guarantee (being aware of the consequences)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select tablespace_name&lt;br /&gt;
,      retention&lt;br /&gt;
from   dba_tablespaces;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter tablespace &amp;amp;undo_ts_name retention guarantee;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Optimise Oracle UNDO Parameters===&lt;br /&gt;
&lt;br /&gt;
The ideal undo_retention would be enough to hold rollback for the longest transaction that happened so far (can&amp;#039;t see into the future)&amp;lt;br /&amp;gt;&lt;br /&gt;
So current undo_retention = current value of undo / (db_block_size * undo blocks per sec)&amp;lt;br /&amp;gt;&lt;br /&gt;
* Undo Blocks per Second&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SELECT MAX(undoblks/((end_time-begin_time)*3600*24)) &amp;quot;UNDO_BLOCKS_PER_SEC&amp;quot;&lt;br /&gt;
FROM   v$undostat;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Optimal Undo Retention&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
col actual for 9999999999.99 heading &amp;quot;ACTUAL UNDO SIZE [MByte]&amp;quot;&lt;br /&gt;
col retent for 9999999999    heading &amp;quot;UNDO RETENTION [Sec]&amp;quot;&lt;br /&gt;
col needed for 9999999999.99 heading &amp;quot;NEEDED UNDO SIZE [Secs]&amp;quot;&lt;br /&gt;
&lt;br /&gt;
SELECT d.undo_size/(1024*1024) actual,&lt;br /&gt;
       to_number(SUBSTR(e.value,1,25)) retent,&lt;br /&gt;
       ROUND((d.undo_size / (to_number(f.value) *&lt;br /&gt;
       g.undo_block_per_sec))) needed&lt;br /&gt;
  FROM (&lt;br /&gt;
       SELECT SUM(a.bytes) undo_size&lt;br /&gt;
          FROM v$datafile a,&lt;br /&gt;
               v$tablespace b,&lt;br /&gt;
               dba_tablespaces c&lt;br /&gt;
         WHERE c.contents = &amp;#039;UNDO&amp;#039;&lt;br /&gt;
           AND c.status = &amp;#039;ONLINE&amp;#039;&lt;br /&gt;
           AND b.name = c.tablespace_name&lt;br /&gt;
           AND a.ts# = b.ts#&lt;br /&gt;
       ) d,&lt;br /&gt;
       v$parameter e,&lt;br /&gt;
       v$parameter f,&lt;br /&gt;
       (&lt;br /&gt;
       SELECT MAX(undoblks/((end_time-begin_time)*3600*24))&lt;br /&gt;
              undo_block_per_sec&lt;br /&gt;
         FROM v$undostat&lt;br /&gt;
       ) g&lt;br /&gt;
WHERE e.name = &amp;#039;undo_retention&amp;#039;&lt;br /&gt;
  AND f.name = &amp;#039;db_block_size&amp;#039;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Calculate Needed UNDO Size for given Database Activity&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
col actual for 9999999999.99 heading &amp;quot;ACTUAL UNDO SIZE [MByte]&amp;quot;&lt;br /&gt;
col retent for 9999999999    heading &amp;quot;UNDO RETENTION [Sec]&amp;quot;&lt;br /&gt;
col needed for 9999999999.99 heading &amp;quot;NEEDED UNDO SIZE [MByte]&amp;quot;&lt;br /&gt;
&lt;br /&gt;
SELECT d.undo_size/(1024*1024) actual&lt;br /&gt;
,      to_number(SUBSTR(e.value,1,25)) retent&lt;br /&gt;
,      (TO_NUMBER(e.value) * TO_NUMBER(f.value) *&lt;br /&gt;
       g.undo_block_per_sec) / (1024*1024)  needed&lt;br /&gt;
  FROM (&lt;br /&gt;
       SELECT SUM(a.bytes) undo_size&lt;br /&gt;
         FROM v$datafile a,&lt;br /&gt;
              v$tablespace b,&lt;br /&gt;
              dba_tablespaces c&lt;br /&gt;
        WHERE c.contents = &amp;#039;UNDO&amp;#039;&lt;br /&gt;
          AND c.status = &amp;#039;ONLINE&amp;#039;&lt;br /&gt;
          AND b.name = c.tablespace_name&lt;br /&gt;
          AND a.ts# = b.ts#&lt;br /&gt;
       ) d,&lt;br /&gt;
      v$parameter e,&lt;br /&gt;
       v$parameter f,&lt;br /&gt;
       (&lt;br /&gt;
       SELECT MAX(undoblks/((end_time-begin_time)*3600*24))&lt;br /&gt;
         undo_block_per_sec&lt;br /&gt;
         FROM v$undostat&lt;br /&gt;
       ) g&lt;br /&gt;
 WHERE e.name = &amp;#039;undo_retention&amp;#039;&lt;br /&gt;
  AND f.name = &amp;#039;db_block_size&amp;#039;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
It might be that the Export still fails with ORA-01555 even though retention seems long enough.&amp;lt;br /&amp;gt;&lt;br /&gt;
Are you running an export with the flashback_time parameter? If so, the undo_retention should be longer than the total export running time!&amp;lt;br /&amp;gt;&lt;br /&gt;
===Check LOB undo retention===&lt;br /&gt;
The retention settings for LOBS is different for the rest of the database.&amp;lt;br /&amp;gt;&lt;br /&gt;
When you change the UNDO_RETENTION parameter, the LOB segment’s retention value is NOT modified.&amp;lt;br /&amp;gt;&lt;br /&gt;
If you query the RETENTION column of the DBA_LOBS view, you will notice the old UNDO_RETENTION value still remains after you have modified the UNDO_RETENTION parameter.&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SQL&amp;gt; show parameter undo_&lt;br /&gt;
&lt;br /&gt;
NAME                                 TYPE        VALUE&lt;br /&gt;
------------------------------------ ----------- ------------------------------&lt;br /&gt;
undo_management                      string      AUTO&lt;br /&gt;
undo_retention                       integer     36000&lt;br /&gt;
undo_tablespace                      string      UNDOTBS1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SQL&amp;gt; desc SITEADMIN.AUDIT_LOG_MESSAGE&lt;br /&gt;
 Name                                      Null?    Type&lt;br /&gt;
 ----------------------------------------- -------- ----------------------------&lt;br /&gt;
 AUDIT_LOG_MESSAGE_ID                      NOT NULL NUMBER&lt;br /&gt;
 AUDIT_LOG_ID                              NOT NULL NUMBER&lt;br /&gt;
 SEQUENCE                                           NUMBER&lt;br /&gt;
 MESSAGE                                            CLOB&lt;br /&gt;
 CREATE_DATE                                        TIMESTAMP(6)&lt;br /&gt;
 COMPONENT_ID                                       VARCHAR2(50 CHAR)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 300&lt;br /&gt;
col column_name for a32&lt;br /&gt;
select table_name,column_name, pctversion,retention from dba_lobs where owner=&amp;#039;&amp;amp;table_owner&amp;#039;;&lt;br /&gt;
&lt;br /&gt;
TABLE_NAME                COLUMN_NAME                    PCTVERSION  RETENTION&lt;br /&gt;
------------------------- ------------------------------ ---------- ----------&lt;br /&gt;
EMAIL_STORE               CONTENT                                 0&lt;br /&gt;
EMAIL_STORE_ATTACHEMENT   ATTACHEMENT                             0&lt;br /&gt;
TRACKING                  ORIGINAL_MESSAGE                                 900&lt;br /&gt;
TRACKING                  MESSAGE                                          900&lt;br /&gt;
TRACKING                  SIEBEL_MESSAGE                                   900&lt;br /&gt;
WISE_WMS_LOG              WISE_WMS_XML                                     900&lt;br /&gt;
ATTACHMENT                ORIGINAL_MESSAGE                                 900&lt;br /&gt;
PLAN_TABLE                OTHER_XML                                        900&lt;br /&gt;
AUDIT_LOG_MESSAGE         MESSAGE                                          900&lt;br /&gt;
EXCEPTIONS                STACK_TRACE                                      900&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
To change the LOB segment’s RETENTION value to match the new UNDO_RETENTION value, do the following:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ALTER TABLE my_table MODIFY LOB (lob_column) (PCTVERSION 20);&lt;br /&gt;
ALTER TABLE my_table MODIFY LOB (lob_column) (RETENTION);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
By momentarily changing the LOB to use PCTVERSION and then back to RETENTION, the new value of UNDO_RETENTION will be used.&amp;lt;br /&amp;gt;&lt;br /&gt;
You need to do this for all LOB segments that you intend to modify.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select &amp;#039;ALTER TABLE &amp;#039;||owner||&amp;#039;.&amp;#039;||table_name||&amp;#039; MODIFY LOB (&amp;#039;||column_name||&amp;#039;) (PCTVERSION 20);&amp;#039; from dba_lobs where owner=&amp;#039;TIBCO&amp;#039;&lt;br /&gt;
&lt;br /&gt;
select &amp;#039;ALTER TABLE &amp;#039;||owner||&amp;#039;.&amp;#039;||table_name||&amp;#039; MODIFY LOB (&amp;#039;||column_name||&amp;#039;) (RETENTION);&amp;#039;     from dba_lobs where owner=&amp;#039;TIBCO&amp;#039;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
There is a table DBA_LOBS that displays information about all the LOB columns in the database, but it doesn&amp;#039;t actually store any LOB data, just metadata. The actual LOB segments in the database have system-generated names that take the form SYS_LOB*identifier*$$.&lt;br /&gt;
For example if you identify a segment named SYS_LOBidentifier$$ that is consuming space, you can find out what column of what table that LOB column maps to using the DBA_LOBS table:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 1000&lt;br /&gt;
col owner       for a20&lt;br /&gt;
col table_name  for a32&lt;br /&gt;
col column_name for a32&lt;br /&gt;
select owner&lt;br /&gt;
,      table_name&lt;br /&gt;
,      column_name&lt;br /&gt;
from   dba_lobs&lt;br /&gt;
where  1=1&lt;br /&gt;
and    segment_name = &amp;#039;SYS_LOB&amp;lt;&amp;lt;identifier&amp;gt;&amp;gt;$$&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====The Undo Advisor PL/SQL Interface====&lt;br /&gt;
You can activate the Undo Advisor by creating an undo advisor task through the advisor framework.&amp;lt;br /&amp;gt;&lt;br /&gt;
The following example creates an undo advisor task to evaluate the undo tablespace. The name of the advisor is &amp;#039;Undo Advisor&amp;#039;.&amp;lt;br /&amp;gt;&lt;br /&gt;
The analysis is based on Automatic Workload Repository snapshots, which you must specify by setting parameters START_SNAPSHOT and END_SNAPSHOT.&amp;lt;br /&amp;gt;&lt;br /&gt;
In the following example, the START_SNAPSHOT is &amp;quot;1&amp;quot; and END_SNAPSHOT is &amp;quot;2&amp;quot;.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
DECLARE&lt;br /&gt;
   tid    NUMBER;&lt;br /&gt;
   tname  VARCHAR2(30);&lt;br /&gt;
   oid    NUMBER;&lt;br /&gt;
BEGIN&lt;br /&gt;
   DBMS_ADVISOR.CREATE_TASK(&amp;#039;Undo Advisor&amp;#039;, tid, tname, &amp;#039;Undo Advisor Task&amp;#039;);&lt;br /&gt;
   DBMS_ADVISOR.CREATE_OBJECT(tname, &amp;#039;UNDO_TBS&amp;#039;, null, null, null, &amp;#039;null&amp;#039;, oid);&lt;br /&gt;
   DBMS_ADVISOR.SET_TASK_PARAMETER(tname, &amp;#039;TARGET_OBJECTS&amp;#039;, oid);&lt;br /&gt;
   DBMS_ADVISOR.SET_TASK_PARAMETER(tname, &amp;#039;START_SNAPSHOT&amp;#039;, 1);&lt;br /&gt;
   DBMS_ADVISOR.SET_TASK_PARAMETER(tname, &amp;#039;END_SNAPSHOT&amp;#039;, 2);&lt;br /&gt;
   DBMS_ADVISOR.SET_TASK_PARAMETER(tname, &amp;#039;INSTANCE&amp;#039;, 1);&lt;br /&gt;
   DBMS_ADVISOR.execute_task(tname);&lt;br /&gt;
        END;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
After you have created the advisor task, you can view the output and recommendations in the Automatic Database Diagnostic Monitor in Enterprise Manager.&amp;lt;br /&amp;gt;&lt;br /&gt;
This information is also available in the DBA_ADVISOR_* data dictionary views (DBA_ADVISOR_TASKS, DBA_ADVISOR_OBJECTS, DBA_ADVISOR_FINDINGS, DBA_ADVISOR_RECOMMENDATIONS, and so on).&lt;br /&gt;
====References====&lt;br /&gt;
* [http://www.akadia.com/services/ora_optimize_undo.html akadia.com]&lt;br /&gt;
* [http://dfitzjarrell.wordpress.com/2008/02/22/the-dreaded-ora-01555/ the dreaded ora-01555]&lt;br /&gt;
* [http://docs.oracle.com/cd/B28359_01/server.111/b28310/undo004.htm#ADMIN11469 docs.oracle.com]&lt;br /&gt;
&lt;br /&gt;
===Error 6 initializing SQL*Plus===&lt;br /&gt;
Using sqlplus or rman under Cygwin, ORACLE_HOME still needs to be windows format!&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Message file sp1&amp;lt;lang&amp;gt;.msb not found&lt;br /&gt;
SP2-0750 :You may need to set ORACLE_HOME to your Oracle software directory&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
so...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
export ORACLE_SID=KITRYD&lt;br /&gt;
ORAENV_ASK=NO&lt;br /&gt;
. oraenv&lt;br /&gt;
[[ &amp;quot;`uname`&amp;quot; == CYGWIN* ]] &amp;amp;&amp;amp; ORACLE_HOME=`cygpath -w ${ORACLE_HOME}`&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===ORA-2002: error while writing to audit trail===&lt;br /&gt;
Check the space left in the audit tablespace with:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select sum(bytes)/1024/1024 mb from dba_free_space where tablespace_name =&amp;#039;AUDIT_DT&amp;#039;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
If plenty of space, it can be due to Oracle clearing out the recyclebin at the same time.&amp;lt;br /&amp;gt;&lt;br /&gt;
If not, extend the datafile...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select * from dba_data_files where tablespace_name =&amp;#039;AUDIT_DT&amp;#039;;&lt;br /&gt;
alter database datafile 6 resize 30G;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
If that is not possible, clean out some audit data or add a datafile.&lt;br /&gt;
&lt;br /&gt;
===ORA-00449: background process &amp;#039;CKPT&amp;#039; unexpectedly terminated with error 7446===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SQL&amp;gt; startup nomount pfile=&amp;quot;/oracle/TRSCRP1/admin/initTRSCRP1.ora&amp;quot;&lt;br /&gt;
ORA-00449: background process &amp;#039;CKPT&amp;#039; unexpectedly terminated with error 7446&lt;br /&gt;
ORA-07446: sdnfy: bad value &amp;#039;&amp;#039; for parameter .&lt;br /&gt;
SQL&amp;gt; exit&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Solution&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SQL&amp;gt; mkdir /oracle/TRSCRP1/admin/bdump /oracle/TRSCRP1/admin/cdump&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORA-00845: MEMORY_TARGET not supported on this system===&lt;br /&gt;
* Reference: [http://arjudba.blogspot.be/2009/01/ora-00845-memorytarget-not-supported-on.html arjudba.blogspot.be]&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Problem Description&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SQL&amp;gt; STARTUP&lt;br /&gt;
ORA-00845: MEMORY_TARGET not supported on this system&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Cause&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
* Starting from Oracle 11g the automatic memory management feature is now defined with parameter MEMORY_TARGET and MEMMORY_MAX_TARGET.&lt;br /&gt;
* On linux file system the shared memory need to be mounted on /dev/shm directory on the operating system.&lt;br /&gt;
* And the size of /dev/shm needs to be greater than MEMORY_TARGET or MEMMORY_MAX_TARGET.&lt;br /&gt;
* The AMM (Automatic Memory Management) now in 11g manages both SGA and PGA together by MMAN process.&lt;br /&gt;
* The MEMORY_TARGET parameter in 11g comes for (SGA_TARGET+PGA_AGGREGATE_TARGET) which was in 10g.&lt;br /&gt;
* And MEMORY_MAX_TARGET parameter in 11g comes instead of SGA_MAX_TARGET parameter which was in 10g.&lt;br /&gt;
* The ORA-00845:can arises for the following two reasons on linux system.&lt;br /&gt;
1)If the shared memory which is mapped to /dev/shm directory is less than the size of MEMORY_TARGET or MEMORY_MAX_TARGET or&lt;br /&gt;
2)If the shared memory is not mapped to /dev/shm directory.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Solution&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Make sure /dev/shm is properly mounted. You can see it by,&lt;br /&gt;
#df -h or #df -k command.&lt;br /&gt;
The output should be similar to:&lt;br /&gt;
&lt;br /&gt;
$ df -k&lt;br /&gt;
Filesystem            Size  Used Avail Use% Mounted on&lt;br /&gt;
...&lt;br /&gt;
shmfs                 1G    512M 512M  50% /dev/shm&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
We see here for /dev/shm we have assigned 1G memory. Now if you set MEMORY_TARGET more than 1G then above ORA-845 will arise. For example if you have MEMORY_TARGET or MEMORY_MAX_TARGET set to 12G then you can mount shared memory to 13g like below.&lt;br /&gt;
As a root user,&lt;br /&gt;
# mount -t tmpfs shmfs -o size=13g /dev/shm&lt;br /&gt;
In order to make the settings persistence so that it will affect after restarting machine add an entry in /etc/fstab similar to the following:&lt;br /&gt;
&lt;br /&gt;
shmfs /dev/shm tmpfs size=13g 0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORA-24247: network access denied by access control list (ACL)===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Cause: No access control list (ACL) has been assigned to the target host or the privilege necessary to access the target host has not been granted to the user in the access control list.&lt;br /&gt;
&lt;br /&gt;
Action: Ensure that an access control list (ACL) has been assigned to the target host and the privilege necessary to access the target host has been granted to the user.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Your application will encounter an ORA-24247 error if it relies on one of the network packages and no proper ACL has been created. For the use of the following packages it is mandatory to have an ACL for the application user in place in 11g:&lt;br /&gt;
*UTL_TCP&lt;br /&gt;
*UTL_SMTP&lt;br /&gt;
*UTL_MAIL&lt;br /&gt;
*UTL_HTTP&lt;br /&gt;
*UTL_INADDR&lt;br /&gt;
Here is a very good explanation of how to setup the necessary ACLs: [[http://blog.whitehorses.nl/2010/03/17/oracle-11g-access-control-list-and-ora-24247/ whitehorses.nl]]&lt;br /&gt;
&lt;br /&gt;
===ORA-00600: internal error code, arguments: [qmx: no ref]===&lt;br /&gt;
Search &amp;quot;Master Note for Oracle XML Database (XDB) Install / Deinstall (Doc ID 1292089.1)&amp;quot; for more info.&lt;br /&gt;
====Problem:====&lt;br /&gt;
Sometimes one or more of the following errors can be encountered when installing or upgrading XDB, configuring APEX, running an Export, or selecting from xdb.xdb$resource or sys.dba_network_acls:&amp;lt;br /&amp;gt;&lt;br /&gt;
* ORA-31159: XML DB is in an invalid state&lt;br /&gt;
* ORA-00600: internal error code, arguments: [unable to load XDB library]&lt;br /&gt;
* ORA-00600: internal error code, arguments: [qmx: no ref]&lt;br /&gt;
* ORA-00600: internal error code, arguments: [qmtGetColumnInfo1]&lt;br /&gt;
* ORA-00600: internal error code, arguments: [qmtb_init_len]&lt;br /&gt;
* ORA-00600: internal error code, arguments: [qmtGetBaseType]&lt;br /&gt;
* ORA-00600: internal error code, arguments: [psdnop-1], [600]&lt;br /&gt;
* ORA-00600: internal error code, arguments: [qmtInit1]&lt;br /&gt;
* ORA-07445: exception encountered: core dump [_memcpy()+224] [SIGSEGV] [Address not mapped to object]&lt;br /&gt;
* ORA-19051 Cannot Use Fast Path Insert For This XMLType Table&lt;br /&gt;
* ORA-31011: XML parsing failed&lt;br /&gt;
Errors of this sort generally occur when the init routines for the internal XDB functions are run in an invalid environment causing memory corruption.&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
This can happen if the database was ever started with the LD_LIBRARY_PATH (LIBPATH for AIX or SHLIB_PATH for HP) pointing to the wrong $ORACLE_HOME/lib directory rather than to the correct location for the instance.&amp;lt;br /&amp;gt;&lt;br /&gt;
The LD_LIBRARY_PATH/LIBPATH/SHLIB_PATH environment variable is used to resolve the location of the shared library &amp;quot;libxdb.so (libxdb.sl on HP)&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
====Solution:====&lt;br /&gt;
* Stop Listener&lt;br /&gt;
* Stop database&lt;br /&gt;
* Ensure $ORACLE_HOME/lib is at the start of LD_LIBRARY_PATH / LIBPATH / SHLIB_PATH&lt;br /&gt;
* If AIX, run /usr/sbin/slibclean as root&lt;br /&gt;
* Start database&lt;br /&gt;
* Start listener&lt;br /&gt;
&lt;br /&gt;
===ORA-00201: control file version nn.nn.nn.nn incompatible with ORACLE version===&lt;br /&gt;
Trying to restore a database after complete failure&amp;lt;br /&amp;gt;&lt;br /&gt;
first step is to startup the database in nomount mode and restore the controlfile - succeeded.&amp;lt;br /&amp;gt;&lt;br /&gt;
second step, startup the database in mount mode ready for database restore...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SQL*Plus: Release 10.2.0.3.0 - Production on Wed Aug 19 18:16:47 2015&lt;br /&gt;
&lt;br /&gt;
Copyright (c) 1982, 2006, Oracle.  All Rights Reserved.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Connected to:&lt;br /&gt;
Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - 64bit Production&lt;br /&gt;
With the Partitioning, OLAP and Data Mining options&lt;br /&gt;
&lt;br /&gt;
SYS@CODWHP1&amp;gt; startup mount&lt;br /&gt;
ORACLE instance started.&lt;br /&gt;
&lt;br /&gt;
Total System Global Area  260046848 bytes&lt;br /&gt;
Fixed Size                  2029296 bytes&lt;br /&gt;
Variable Size             113248528 bytes&lt;br /&gt;
Database Buffers          134217728 bytes&lt;br /&gt;
Redo Buffers               10551296 bytes&lt;br /&gt;
ORA-00201: control file version 10.2.0.0.0 incompatible with ORACLE version 10.2.0.3.0&lt;br /&gt;
ORA-00202: control file: &amp;#039;/oracle/CODWHP1/product/10203/dbs/cntrlCODWHP1.dbf&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The problem was there was no compatible parameter in the simple init file I used to start up the instance.&amp;lt;br /&amp;gt;&lt;br /&gt;
Adding compatible parameter to init file to be same version (10.2.0.3) allowed the db to mount.&lt;br /&gt;
&lt;br /&gt;
===TNS-00525: Insufficient privilege for operation===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
lsnrctl start LISTENER_UCLID55V&lt;br /&gt;
&lt;br /&gt;
LSNRCTL for IBM/AIX RISC System/6000: Version 11.2.0.3.0 - Production on 26-MAR-2015 13:36:14&lt;br /&gt;
&lt;br /&gt;
Copyright (c) 1991, 2011, Oracle.  All rights reserved.&lt;br /&gt;
&lt;br /&gt;
Starting /oracle/product/11.2.0.3/bin/tnslsnr: please wait...&lt;br /&gt;
&lt;br /&gt;
TNSLSNR for IBM/AIX RISC System/6000: Version 11.2.0.3.0 - Production&lt;br /&gt;
System parameter file is /oracle/product/11.2.0.3/network/admin/listener.ora&lt;br /&gt;
Log messages written to /oracle/product/diag/tnslsnr/solax082/listener_uclid55v/alert/log.xml&lt;br /&gt;
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=150.251.114.238)(PORT=1525)))&lt;br /&gt;
Error listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC1525)))&lt;br /&gt;
TNS-12555: TNS:permission denied&lt;br /&gt;
 TNS-12560: TNS:protocol adapter error&lt;br /&gt;
  TNS-00525: Insufficient privilege for operation&lt;br /&gt;
   IBM/AIX RISC System/6000 Error: 1: Not owner&lt;br /&gt;
&lt;br /&gt;
Listener failed to start. See the error message(s) above...&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This would suggest the user attempting to start the listener has no access to either the Oracle binaries or the TNS listener/tnsnames files.&amp;lt;br /&amp;gt;&lt;br /&gt;
But... checkout the /tmp/.oracle directory :-)&amp;lt;br /&amp;gt;&lt;br /&gt;
That hidden gem shows who started the listener last time. Delete the relevant entry and try again!&amp;lt;br /&amp;gt;&lt;br /&gt;
To start from a clean sheet, stop all listeners, delete this directory and restart the listeners.&lt;br /&gt;
&lt;br /&gt;
===ORA-12003: materialized view or zonemap &amp;quot;KPK&amp;quot;.&amp;quot;EVD01_NEW&amp;quot; does not exist===&lt;br /&gt;
Here&amp;#039;s one you shouldn&amp;#039;t see very often.&amp;lt;br /&amp;gt;&lt;br /&gt;
Trying to drop a tablespace but prevented from doing so because a materialized view has referential contraints on a table in this tablespace.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SQL&amp;gt; drop tablespace TS_THALER_PART_OLD including contents and datafiles cascade constraints;&lt;br /&gt;
drop tablespace TS_THALER_PART_OLD including contents and datafiles cascade constraints&lt;br /&gt;
*&lt;br /&gt;
ERROR at line 1:&lt;br /&gt;
ORA-00604: error occurred at recursive SQL level 1&lt;br /&gt;
ORA-12083: must use DROP MATERIALIZED VIEW to drop &amp;quot;KPK&amp;quot;.&amp;quot;EVD01_NEW&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Ok, nice of Oracle to tell us what we have to do. Simple enough. Let&amp;#039;s drop the materialized view.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SQL&amp;gt; DROP MATERIALIZED VIEW &amp;quot;KPK&amp;quot;.&amp;quot;EVD01_NEW&amp;quot;;&lt;br /&gt;
DROP MATERIALIZED VIEW &amp;quot;KPK&amp;quot;.&amp;quot;EVD01_NEW&amp;quot;&lt;br /&gt;
*&lt;br /&gt;
ERROR at line 1:&lt;br /&gt;
ORA-12003: materialized view or zonemap &amp;quot;KPK&amp;quot;.&amp;quot;EVD01_NEW&amp;quot; does not exist&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Aah. Not so obvious then.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
desc &amp;quot;KPK&amp;quot;.&amp;quot;EVD01_NEW&amp;quot;&lt;br /&gt;
 Name                                      Null?    Type&lt;br /&gt;
 ----------------------------------------- -------- ----------------------------&lt;br /&gt;
 DATMAJ                                             VARCHAR2(8 CHAR)&lt;br /&gt;
 HEUMAJ                                             VARCHAR2(8 CHAR)&lt;br /&gt;
 PGMMAJ                                             VARCHAR2(6 CHAR)&lt;br /&gt;
 NATOPN                                             VARCHAR2(6 CHAR)&lt;br /&gt;
 REFEXN                                             VARCHAR2(50 CHAR)&lt;br /&gt;
 SWIOLN                                             VARCHAR2(1 CHAR)&lt;br /&gt;
 STAEVT                                             VARCHAR2(4 CHAR)&lt;br /&gt;
 REFEVT                                             VARCHAR2(16 CHAR)&lt;br /&gt;
 NUMIDT                                             VARCHAR2(30 CHAR)&lt;br /&gt;
 ORIEVT                                             VARCHAR2(10 CHAR)&lt;br /&gt;
 REFLOG                                             VARCHAR2(16 CHAR)&lt;br /&gt;
 MSGEVT_CPL                                         VARCHAR2(1500 CHAR)&lt;br /&gt;
 REFOPN                                             VARCHAR2(16 CHAR)&lt;br /&gt;
 DATEVT                                             VARCHAR2(8 CHAR)&lt;br /&gt;
 MSGEVT_FIL_1                                       VARCHAR2(2000 CHAR)&lt;br /&gt;
 MSGEVT_FIL_2                                       VARCHAR2(2000 CHAR)&lt;br /&gt;
 MSGEVT_SPE                                         VARCHAR2(200 CHAR)&lt;br /&gt;
 DATEFF                                             VARCHAR2(8 CHAR)&lt;br /&gt;
 TMSTMP                                             VARCHAR2(15 CHAR)&lt;br /&gt;
 VEREVT                                             VARCHAR2(3 CHAR)&lt;br /&gt;
 MSGEVT_FIL_3                                       VARCHAR2(2000 CHAR)&lt;br /&gt;
 MSGEVT_FIL_4                                       VARCHAR2(2000 CHAR)&lt;br /&gt;
 TYPEVT                                             VARCHAR2(5 CHAR)&lt;br /&gt;
 SBP_CODAPP                                         VARCHAR2(10 CHAR)&lt;br /&gt;
 SBP_REFINT                                         VARCHAR2(36 CHAR)&lt;br /&gt;
 SBP_TYPACT                                         VARCHAR2(2 CHAR)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
It exists... but as a table.&amp;lt;br /&amp;gt;&lt;br /&gt;
Something has gone wrong in the database somewhere. As it turns out after some deeper investigation, this database is a copy of production but &amp;quot;with modifications&amp;quot;.&amp;lt;br /&amp;gt;&lt;br /&gt;
After the cloning process, a schema needed renaming. Oracle have a procedure for this but it is very long-winded and time-consuming. It uses export and import with transportable tablespaces to do the remap of the schema.&amp;lt;br /&amp;gt;&lt;br /&gt;
An unsupported workaround to rename schema is to simply update the username in sys.user$ and restart the database.&amp;lt;br /&amp;gt;&lt;br /&gt;
This works for the most part but now we see a consequence of that action.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
col owner      for a30&lt;br /&gt;
col mview_name for a30&lt;br /&gt;
select owner&lt;br /&gt;
,      mview_name&lt;br /&gt;
from   dba_mviews&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
OWNER                          MVIEW_NAME&lt;br /&gt;
------------------------------ ------------------------------&lt;br /&gt;
EPK                            EVD01_NEW&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Ahaa, there&amp;#039;s the materialized view but the owner is different from the one described by the database error message above. This one is the owner as it was on production.&amp;lt;br /&amp;gt;&lt;br /&gt;
This means the owner of materialized views has been denormalised for some reason. Reading the (complex) view text of dba_mviews, we see the owner column is based on sys.snap$.sowner&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
col sowner for a20&lt;br /&gt;
col vname  for a20&lt;br /&gt;
col tname  for a20&lt;br /&gt;
select sowner&lt;br /&gt;
,      vname&lt;br /&gt;
,      tname&lt;br /&gt;
from   sys.snap$&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
SOWNER               VNAME                TNAME&lt;br /&gt;
-------------------- -------------------- --------------------&lt;br /&gt;
EPK                  EVD01_NEW            EVD01_NEW&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
For future reference when updating the username in sys.user$, update the snapshot owner in this table as well!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
update sys.snap$&lt;br /&gt;
set    sowner = &amp;#039;KPK&amp;#039;&lt;br /&gt;
where  sowner = &amp;#039;EPK&amp;#039;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Try again&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
DROP MATERIALIZED VIEW &amp;quot;KPK&amp;quot;.&amp;quot;EVD01_NEW&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
Materialized view dropped.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
yep, and the tablespace?&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
drop tablespace TS_THALER_PART_OLD including contents and datafiles cascade constraints;&lt;br /&gt;
&lt;br /&gt;
Tablespace dropped.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORA-12162: TNS:net service name is incorrectly specified===&lt;br /&gt;
Probably nothing to do with TNS. Check your ORACLE_SID is set correctly!&lt;br /&gt;
&lt;br /&gt;
===ORA-00054: resource busy and acquire with NOWAIT specified===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SELECT O.OBJECT_NAME, S.SID, S.SERIAL#, P.SPID, S.PROGRAM,S.USERNAME,&lt;br /&gt;
S.MACHINE,S.PORT , S.LOGON_TIME,SQ.SQL_FULLTEXT &lt;br /&gt;
FROM V$LOCKED_OBJECT L, DBA_OBJECTS O, V$SESSION S, &lt;br /&gt;
V$PROCESS P, V$SQL SQ &lt;br /&gt;
WHERE L.OBJECT_ID = O.OBJECT_ID &lt;br /&gt;
AND L.SESSION_ID = S.SID AND S.PADDR = P.ADDR &lt;br /&gt;
AND S.SQL_ADDRESS = SQ.ADDRESS;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select object_name, s.sid, s.serial#, p.spid &lt;br /&gt;
from v$locked_object l, dba_objects o, v$session s, v$process p&lt;br /&gt;
where l.object_id = o.object_id and l.session_id = s.sid and s.paddr = p.addr;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
then&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter system kill session &amp;#039;sid,serial#&amp;#039;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORA-12518: TNS:listener could not hand off client connection===&lt;br /&gt;
The database you are trying to connect to is probably on its knees. Check server memory is not exhausted.&lt;br /&gt;
&lt;br /&gt;
===ORA-12520: TNS:listener could not find available handler for requested type of server===&lt;br /&gt;
Strangely this could be related to number of processes being exhausted.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
show parameter processes&lt;br /&gt;
alter system set processes=350 scope=spfile;&lt;br /&gt;
shutdown immediate&lt;br /&gt;
startup&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORA-12541: TNS: no listener===&lt;br /&gt;
Either very basic - start the listener!&amp;lt;br /&amp;gt;&lt;br /&gt;
or, as in our case - not so obvious.&amp;lt;br /&amp;gt;&lt;br /&gt;
We use virtual IP addresses so that the IP address stays the same after failover to standby.&amp;lt;br /&amp;gt;&lt;br /&gt;
Due to some confused configuration, we got the network adapter on two different servers to have the same IP address.&amp;lt;br /&amp;gt;&lt;br /&gt;
Stop the IP address on the bad server (assign another one) and all is fine again.&lt;br /&gt;
===ORA-12514: TNS:listener does not currently know of service===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
lsnrctl status &amp;lt;listener_name&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Been altering tnsnames.ora or listener.ora?&lt;br /&gt;
* Check the local_listener parameter&lt;br /&gt;
Try resetting it to itself. Strange but if you are not using port 1521, this can work wonders!&amp;lt;br /&amp;gt;&lt;br /&gt;
Assuming listener is called LISTENER_WM9T:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter system set local_listener=LISTENER_WM9T scope=both;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Try and connect with the service name or directly with&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sqlplus &amp;#039;sys/*******&amp;#039;@&amp;lt;host&amp;gt;:&amp;lt;port&amp;gt;/&amp;lt;SID&amp;gt; as sysdba&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Excellent description of how Oracle TNS listeners work and a checklist on how to fix this error&amp;lt;br /&amp;gt;&lt;br /&gt;
* [[http://edstevensdba.wordpress.com/2011/03/19/ora-12514/ TNS — Ed Stevens]]&lt;br /&gt;
&lt;br /&gt;
===ORA-12547: TNS lost contact===&lt;br /&gt;
&lt;br /&gt;
If&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sqlplus &amp;lt;user&amp;gt;/&amp;lt;pass&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
fails with above error, try&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sqlplus &amp;lt;user&amp;gt;/&amp;lt;pass&amp;gt;@&amp;lt;db connection&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
If this works, it is most probably a permissions error.&amp;lt;br /&amp;gt;&lt;br /&gt;
Re-run the&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ORACLE_HOME/root.sh&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
script that was run as part of the original installation. This will reset the permissions on some important files.&lt;br /&gt;
===ORA-02374: conversion error loading table &amp;quot;BLENGADM&amp;quot;.&amp;quot;ZZ_EVTCTA&amp;quot;===&lt;br /&gt;
This is typical of importing data with Datapump when the tables in the source database were created with &amp;quot;byte&amp;quot; semantics and the destination is &amp;quot;char&amp;quot; semantics.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ORA-02374: conversion error loading table &amp;quot;BLENGADM&amp;quot;.&amp;quot;ZZ_EVTCTA&amp;quot;&lt;br /&gt;
ORA-12899: value too large for column NOMCTA (actual: 257, maximum: 256)&lt;br /&gt;
&lt;br /&gt;
ORA-02372: data for row: NOMCTA : 0X&amp;#039;4C6976726574206427E9706172676E65202020202020202020&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Problem====&lt;br /&gt;
The root cause is the nls_length_semantics of the table columns being BYTE where one character is assigned one byte. But after conversion in a multi-byte database, one character is larger than one byte (could be 2, 3 or 4) and no longer fits.&lt;br /&gt;
====Solution====&lt;br /&gt;
* import the metadata&lt;br /&gt;
Run the impdp command with content=metadata_only. This will create all the tables (still in their original form) but not the data.&lt;br /&gt;
* alter the BYTE columns in the affected tables to CHAR semantics&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select column_name&lt;br /&gt;
,      char_used&lt;br /&gt;
,      data_length&lt;br /&gt;
,      data_type &lt;br /&gt;
from   user_tab_columns &lt;br /&gt;
where  table_name = &amp;#039;T&amp;#039;&lt;br /&gt;
and    char_used = &amp;#039;B&amp;#039;;&lt;br /&gt;
COLUMN_NAME  C DATA_LENGTH DATA_TYPE&lt;br /&gt;
------------ - ----------- ---------&lt;br /&gt;
X            B           1 VARCHAR2&lt;br /&gt;
SQL&amp;gt; alter table t modify x varchar2(1 char);&lt;br /&gt;
Table altered.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Import the data&lt;br /&gt;
Rerun the impdp ensuring table_exists_action is not REPLACE (use truncate or append). This now imports the data into the modified tables.&lt;br /&gt;
====This script does the donkey work of altering table column semantics from byte to char====&lt;br /&gt;
The author of this script is unknown but he/she deserves a medal. It saves countless hours of work and is so well written.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/*&lt;br /&gt;
  The script converts all the VARCHAR2 columns in the user&amp;#039;s schema&lt;br /&gt;
  to CHAR length semantics. Known to work on 10.2.0.4 and later.&lt;br /&gt;
  &lt;br /&gt;
  Script must be executed against the database without any other client&lt;br /&gt;
  and/or application connections to the affected schema.&lt;br /&gt;
  &lt;br /&gt;
  Oracle does not support CHAR semantics for the built-in schemas,&lt;br /&gt;
  like SYS, SYSTEM or SYSMAN, so the script will throw an error,&lt;br /&gt;
  if attempt to run it against any one of them.&lt;br /&gt;
  &lt;br /&gt;
  Upon completion database objects that have dependencies on tables&lt;br /&gt;
  being modified will be invalidated. Oracle usually re-compiles invalidated&lt;br /&gt;
  objects on the first access. Alternatively, a DBA can execute UTLPRP script&lt;br /&gt;
  to recompile all invalid objects in the entire database.&lt;br /&gt;
  &lt;br /&gt;
  Upon completion, please make sure that NLS_LENGTH_SEMANTICS instance parameter&lt;br /&gt;
  is set to CHAR to ensure further upgradability of the schema.&lt;br /&gt;
*/&lt;br /&gt;
set serveroutput on size unlimited format wrap&lt;br /&gt;
declare&lt;br /&gt;
  type sql_list_t is table of varchar2(32767) index by pls_integer;&lt;br /&gt;
  type idx_list_t is table of user_indexes.index_name%type index by pls_integer;&lt;br /&gt;
  type col_list_t is table of user_tab_columns%rowtype index by pls_integer;&lt;br /&gt;
  --&lt;br /&gt;
  lv_col_cnt   pls_integer := 0;&lt;br /&gt;
  lv_idx_cnt   pls_integer := 0;&lt;br /&gt;
  lv_char_set  pls_integer := 0; &lt;br /&gt;
  lv_user      user_users.username%type;&lt;br /&gt;
  lv_sql_stmt  varchar2(32767);&lt;br /&gt;
  lv_byte_cols col_list_t;&lt;br /&gt;
  lv_idx_names idx_list_t;&lt;br /&gt;
  lv_idx_ddls  sql_list_t;&lt;br /&gt;
  --&lt;br /&gt;
  procedure run_sql_stmt&lt;br /&gt;
  (&lt;br /&gt;
   p_sql_stmt in varchar2&lt;br /&gt;
  )&lt;br /&gt;
  as&lt;br /&gt;
  begin&lt;br /&gt;
    execute immediate p_sql_stmt;&lt;br /&gt;
  exception&lt;br /&gt;
    when others&lt;br /&gt;
    then&lt;br /&gt;
      raise_application_error(-20202, &amp;#039;Failed statement [&amp;#039; || p_sql_stmt || dbms_utility.format_error_backtrace() || &amp;#039;]&amp;#039;, true);&lt;br /&gt;
  end;&lt;br /&gt;
begin&lt;br /&gt;
  --&lt;br /&gt;
  lv_user := user();&lt;br /&gt;
  if lv_user in (&amp;#039;SYS&amp;#039;, &amp;#039;SYSTEM&amp;#039;, &amp;#039;SYSMAN&amp;#039;)&lt;br /&gt;
  then&lt;br /&gt;
    raise_application_error(-20202, &amp;#039;This script cannot be executed against Oracle built-in schema [&amp;#039; || lv_user || &amp;#039;].&amp;#039;);&lt;br /&gt;
  end if;&lt;br /&gt;
  --&lt;br /&gt;
  select&lt;br /&gt;
         *&lt;br /&gt;
         bulk collect into lv_byte_cols&lt;br /&gt;
  from&lt;br /&gt;
         user_tab_columns uc&lt;br /&gt;
  where&lt;br /&gt;
         uc.char_used = &amp;#039;B&amp;#039;&lt;br /&gt;
         and&lt;br /&gt;
         substr(uc.table_name, 1, 4) != &amp;#039;BIN$&amp;#039;&lt;br /&gt;
         and&lt;br /&gt;
         not exists&lt;br /&gt;
         (&lt;br /&gt;
          select 1&lt;br /&gt;
          from   user_views uv&lt;br /&gt;
          where  uv.view_name = uc.table_name&lt;br /&gt;
         )&lt;br /&gt;
  ;&lt;br /&gt;
  --&lt;br /&gt;
  lv_col_cnt := lv_byte_cols.count();&lt;br /&gt;
  --&lt;br /&gt;
  dbms_output.enable();&lt;br /&gt;
  --&lt;br /&gt;
  if lv_col_cnt &amp;gt; 0&lt;br /&gt;
  then&lt;br /&gt;
    for idx_rw in&lt;br /&gt;
    (&lt;br /&gt;
     select index_name &lt;br /&gt;
     from   user_indexes&lt;br /&gt;
     where  index_type = &amp;#039;FUNCTION-BASED NORMAL&amp;#039;&lt;br /&gt;
    )&lt;br /&gt;
    loop&lt;br /&gt;
      lv_idx_cnt := lv_idx_cnt + 1;&lt;br /&gt;
      lv_idx_names(lv_idx_cnt) := idx_rw.index_name;&lt;br /&gt;
      lv_idx_ddls(lv_idx_cnt) := replace&lt;br /&gt;
                                 (&lt;br /&gt;
                                  dbms_metadata.get_ddl&lt;br /&gt;
                                  (&lt;br /&gt;
                                   object_type =&amp;gt; &amp;#039;INDEX&amp;#039;,&lt;br /&gt;
                                   name        =&amp;gt; idx_rw.index_name&lt;br /&gt;
                                  )&lt;br /&gt;
                                  ,&lt;br /&gt;
                                  &amp;#039;;&amp;#039;&lt;br /&gt;
                                 );&lt;br /&gt;
      lv_sql_stmt := &amp;#039;drop index &amp;#039; || idx_rw.index_name;&lt;br /&gt;
      run_sql_stmt(lv_sql_stmt);&lt;br /&gt;
      dbms_output.put_line(&amp;#039;Dropped function-based index: &amp;#039; || idx_rw.index_name);&lt;br /&gt;
      dbms_output.put_line(&amp;#039;In case of script failure, restore the index by running the DDL statement below:&amp;#039;);&lt;br /&gt;
      dbms_output.put_line(lv_idx_ddls(lv_idx_cnt) || &amp;#039;;&amp;#039;);&lt;br /&gt;
    end loop;&lt;br /&gt;
    --&lt;br /&gt;
    for i in 1..lv_col_cnt&lt;br /&gt;
    loop&lt;br /&gt;
      lv_sql_stmt :=  &amp;#039;alter table &amp;#039; || lv_byte_cols(i).table_name || &amp;#039; modify (&amp;#039; ||&lt;br /&gt;
                      lv_byte_cols(i).column_name || &amp;#039; &amp;#039; || lv_byte_cols(i).data_type ||&lt;br /&gt;
                      &amp;#039;(&amp;#039; || lv_byte_cols(i).char_length || &amp;#039; char))&amp;#039;;&lt;br /&gt;
      run_sql_stmt(lv_sql_stmt);&lt;br /&gt;
    end loop;&lt;br /&gt;
    --&lt;br /&gt;
    dbms_output.new_line();&lt;br /&gt;
    for i in 1..lv_idx_cnt&lt;br /&gt;
    loop&lt;br /&gt;
      run_sql_stmt(lv_idx_ddls(i));&lt;br /&gt;
      dbms_output.put_line(&amp;#039;Recreated function-based index: &amp;#039; || lv_idx_names(i));&lt;br /&gt;
    end loop;&lt;br /&gt;
    --&lt;br /&gt;
    dbms_output.new_line();&lt;br /&gt;
    dbms_output.put_line&lt;br /&gt;
    (&lt;br /&gt;
     &amp;#039;Updated length semantics to CHAR for &amp;#039; || lv_col_cnt || &amp;#039; column&amp;#039; ||&lt;br /&gt;
     case when lv_col_cnt &amp;gt; 1&lt;br /&gt;
          then &amp;#039;s&amp;#039;&lt;br /&gt;
     end ||&lt;br /&gt;
     &amp;#039; in the schema [&amp;#039; || lv_user || &amp;#039;].&amp;#039;&lt;br /&gt;
    );&lt;br /&gt;
  else&lt;br /&gt;
    dbms_output.put_line(&amp;#039;No columns with BYTE length semantics were found in the schema [&amp;#039; || lv_user || &amp;#039;].&amp;#039;);&lt;br /&gt;
  end if;&lt;br /&gt;
  --&lt;br /&gt;
  select count(*) into lv_char_set&lt;br /&gt;
  from   nls_session_parameters&lt;br /&gt;
  where  parameter = &amp;#039;NLS_LENGTH_SEMANTICS&amp;#039;&lt;br /&gt;
         and&lt;br /&gt;
         value = &amp;#039;CHAR&amp;#039;&lt;br /&gt;
  ;&lt;br /&gt;
  --&lt;br /&gt;
  if lv_char_set = 0&lt;br /&gt;
  then&lt;br /&gt;
    dbms_output.put_line(&amp;#039;WARNING: Do not forget to change instance parameter NLS_LENGTH_SEMANTICS to CHAR and restart the database.&amp;#039;);&lt;br /&gt;
  end if;&lt;br /&gt;
end;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORA-14097: column type or size mismatch in ALTER TABLE EXCHANGE PARTITION===&lt;br /&gt;
Also can be ORA-54033: column to be modified is used in a virtual column expression&amp;lt;br /&amp;gt;&lt;br /&gt;
Nothing especially to do with partitions - just any ddl operation that affects the table.&amp;lt;br /&amp;gt;&lt;br /&gt;
Hidden columns do not normally show up in a desc unless colinvisible is on&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set colinvisible on&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
But these sneaky system-generated ones don&amp;#039;t show up even with that setting on!  You need to show them with this:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set pages 50 lines 1000&lt;br /&gt;
col column_name for a40&lt;br /&gt;
col data_default for a40&lt;br /&gt;
select internal_column_id, column_name, data_default, hidden_column, virtual_column from dba_tab_cols where table_name =&amp;#039;XND40&amp;#039;;&lt;br /&gt;
&lt;br /&gt;
INTERNAL_COLUMN_ID COLUMN_NAME                                        DATA_DEFAULT                                       HIDDEN_COLUM VIRTUAL_COLU&lt;br /&gt;
------------------ -------------------------------------------------- -------------------------------------------------- ------------ ------------&lt;br /&gt;
                35 MONLOT_REC_CDR                                     &amp;#039;0&amp;#039;                                                NO           NO&lt;br /&gt;
                34 MONLOT_REC_DBT                                     &amp;#039;0&amp;#039;                                                NO           NO&lt;br /&gt;
                33 MONLOT_CAL_CDR                                     &amp;#039;0&amp;#039;                                                NO           NO&lt;br /&gt;
                32 MONLOT_CAL_DBT                                     &amp;#039;0&amp;#039;                                                NO           NO&lt;br /&gt;
                31 MONMVT_CPT                                         &amp;#039;0&amp;#039;                                                NO           NO&lt;br /&gt;
                30 SENNOT                                             &amp;#039; &amp;#039;                                                NO           NO&lt;br /&gt;
                29 NUMSEQ                                                                                                NO           NO&lt;br /&gt;
                28 NOMFIC                                                                                                NO           NO&lt;br /&gt;
                27 TOTCPT_REC                                                                                            NO           NO&lt;br /&gt;
                26 TOTCPT_CAL                                                                                            NO           NO&lt;br /&gt;
                25 MONLOT_REC                                                                                            NO           NO&lt;br /&gt;
                24 MONLOT_CAL                                                                                            NO           NO&lt;br /&gt;
                23 NBRELE_REC                                                                                            NO           NO&lt;br /&gt;
                22 NBRELE_CAL                                                                                            NO           NO&lt;br /&gt;
                21 NUMCPT_GLO                                                                                            NO           NO&lt;br /&gt;
                20 DEVLOT                                                                                                NO           NO&lt;br /&gt;
                19 CODERR                                                                                                NO           NO&lt;br /&gt;
                18 CANLOT                                                                                                NO           NO&lt;br /&gt;
                17 REFTEX                                                                                                NO           NO&lt;br /&gt;
                16 REFEXN                                                                                                NO           NO&lt;br /&gt;
                15 ETTLOT                                                                                                NO           NO&lt;br /&gt;
                14 TYPLOT                                                                                                NO           NO&lt;br /&gt;
                13 DATEXC                                                                                                NO           NO&lt;br /&gt;
                12 STALOT                                                                                                NO           NO&lt;br /&gt;
                11 REFLOT                                                                                                NO           NO&lt;br /&gt;
                10 USRAUT                                                                                                NO           NO&lt;br /&gt;
                 9 HEUAUT                                                                                                NO           NO&lt;br /&gt;
                 8 DATAUT                                                                                                NO           NO&lt;br /&gt;
                 7 PGMMAJ                                                                                                NO           NO&lt;br /&gt;
                 6 USRMAJ                                                                                                NO           NO&lt;br /&gt;
                 5 HEUMAJ                                                                                                NO           NO&lt;br /&gt;
                 4 DATMAJ                                                                                                NO           NO&lt;br /&gt;
                 3 DATCRT                                                                                                NO           NO&lt;br /&gt;
                 2 REFMAJ                                                                                                NO           NO&lt;br /&gt;
                 1 NUMVER                                                                                                NO           NO&lt;br /&gt;
                36 SYS_STS#KR2WNV5L070XKV1L5H7REH                     SYS_OP_COMBINED_HASH(&amp;quot;NOMFIC&amp;quot;,&amp;quot;NUMSEQ&amp;quot;)            YES          YES&lt;br /&gt;
&lt;br /&gt;
36 rows selected.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
That last row means extended statistics have been generated for 2 columns in this table.&amp;lt;br /&amp;gt;&lt;br /&gt;
====Solution====&lt;br /&gt;
Drop the extended stats, do what you need to do and recreate the extended stats.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
PROCEDURE DROP_EXTENDED_STATS&lt;br /&gt;
 Argument Name                  Type                    In/Out Default?&lt;br /&gt;
 ------------------------------ ----------------------- ------ --------&lt;br /&gt;
 OWNNAME                        VARCHAR2                IN&lt;br /&gt;
 TABNAME                        VARCHAR2                IN&lt;br /&gt;
 EXTENSION                      VARCHAR2                IN&lt;br /&gt;
&lt;br /&gt;
exec dbms_stats.drop_extended_stats ( &amp;#039;KPK&amp;#039;, &amp;#039;XND40&amp;#039;, &amp;#039;(&amp;quot;NOMFIC&amp;quot;,&amp;quot;NUMSEQ&amp;quot;)&amp;#039; );&lt;br /&gt;
&lt;br /&gt;
create table kpk.xnd40_new as select * from kpk.xnd40 where 1=2;&lt;br /&gt;
&lt;br /&gt;
Table created.&lt;br /&gt;
&lt;br /&gt;
select dbms_stats.create_extended_stats ( &amp;#039;KPK&amp;#039;, &amp;#039;XND40&amp;#039;, &amp;#039;(&amp;quot;NOMFIC&amp;quot;,&amp;quot;NUMSEQ&amp;quot;)&amp;#039; ) from   dual;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORA-14404: partitioned table contains partitions in a different tablespace===&lt;br /&gt;
As part of an RMAN duplicate with a skip tablespace, this error is produced&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Reenabling controlfile options for auxiliary database&lt;br /&gt;
Executing: alter database enable block change tracking using file &amp;#039;/oracle/acc/ora_data3/adsa1/bct_adsp_do_not_delete.f&amp;#039;&lt;br /&gt;
&lt;br /&gt;
contents of Memory Script:&lt;br /&gt;
{&lt;br /&gt;
   Alter clone database open resetlogs;&lt;br /&gt;
}&lt;br /&gt;
executing Memory Script&lt;br /&gt;
&lt;br /&gt;
database opened&lt;br /&gt;
Dropping offline and skipped tablespaces&lt;br /&gt;
Executing: drop tablespace &amp;quot;ADS_ARCHIVE&amp;quot; including contents cascade constraints&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-03002: failure of Duplicate Db command at 10/16/2017 23:46:12&lt;br /&gt;
RMAN-05501: aborting duplication of target database&lt;br /&gt;
RMAN-06136: ORACLE error from auxiliary database: ORA-14404: partitioned table contains partitions in a different tablespace&lt;br /&gt;
&lt;br /&gt;
Recovery Manager complete.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
and when attempting to backup the database, we get errors&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
RMAN-06169: could not read file header for datafile 188 error reason 1&lt;br /&gt;
RMAN-06169: could not read file header for datafile 189 error reason 1&lt;br /&gt;
RMAN-06169: could not read file header for datafile 190 error reason 1&lt;br /&gt;
RMAN-06169: could not read file header for datafile 191 error reason 1&lt;br /&gt;
RMAN-06169: could not read file header for datafile 14 error reason 1&lt;br /&gt;
released channel: t1&lt;br /&gt;
released channel: t2&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-03002: failure of backup plus archivelog command at 10/17/2017 15:08:40&lt;br /&gt;
RMAN-06056: could not access datafile 14&lt;br /&gt;
&lt;br /&gt;
Recovery Manager complete.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Problem====&lt;br /&gt;
Tables in the tablespace have partitions in another tablespace so this one cannot be dropped.&amp;lt;br /&amp;gt;&lt;br /&gt;
Check which table partitions are in which tablespaces&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 200&lt;br /&gt;
set pagesize 200&lt;br /&gt;
col table_name for a14&lt;br /&gt;
col table_owner for a14&lt;br /&gt;
col partition_name for a14&lt;br /&gt;
select table_owner&lt;br /&gt;
,      table_name&lt;br /&gt;
,      partition_name&lt;br /&gt;
,      tablespace_name&lt;br /&gt;
from   dba_tab_partitions&lt;br /&gt;
where  (table_owner, table_name) in&lt;br /&gt;
       (&lt;br /&gt;
       select table_owner&lt;br /&gt;
       ,      table_name&lt;br /&gt;
       from   dba_tab_partitions x&lt;br /&gt;
       where  x.tablespace_name = &amp;#039;&amp;amp;&amp;amp;TABLESPACE_TO_DROP&amp;#039;&lt;br /&gt;
       and    exists ( select *&lt;br /&gt;
                       from   dba_tab_partitions y&lt;br /&gt;
                       where  x.table_owner = y.table_owner&lt;br /&gt;
                       and    x.table_name  = y.table_name&lt;br /&gt;
                       and    y.tablespace_name not in (&amp;#039;&amp;amp;TABLESPACE_TO_DROP&amp;#039;)&lt;br /&gt;
                       group  by table_owner&lt;br /&gt;
                       ,      table_name&lt;br /&gt;
                     )&lt;br /&gt;
        )&lt;br /&gt;
order by 1,2,partition_position&lt;br /&gt;
/&lt;br /&gt;
undef TABLESPACE_TO_DROP&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
TABLE_OWNER    TABLE_NAME     PARTITION_NAME TABLESPACE_NAME&lt;br /&gt;
-------------- -------------- -------------- ------------------------------&lt;br /&gt;
KPK            XND20          P0910          TS_THALER_PART_OLD&lt;br /&gt;
KPK            XND20          P1112          TS_THALER_PART_OLD&lt;br /&gt;
KPK            XND20          P13            TS_THALER_PART_OLD&lt;br /&gt;
KPK            XND20          P14            TS_THALER_PART_OLD&lt;br /&gt;
KPK            XND20          P15            TS_THALER_PART_OLD&lt;br /&gt;
KPK            XND20          P16            TS_THALER_DATA&lt;br /&gt;
KPK            XND20          P17            TS_THALER_DATA&lt;br /&gt;
KPK            XND20          P18            TS_THALER_DATA&lt;br /&gt;
KPK            XND20          PMAX           TS_THALER_DATA&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Solution====&lt;br /&gt;
If the intention is to keep all the tables then run this query to generate statements to move the relevant tables out of this tablespace&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select &amp;#039;alter table &amp;#039;||b.table_owner||&amp;#039;.&amp;#039;||b.table_name||&amp;#039; move partition &amp;#039;||b.partition_name||&amp;#039; tablespace &amp;amp;NEW_TABLESPACE;&amp;#039;&lt;br /&gt;
from   (&lt;br /&gt;
       select distinct table_name&lt;br /&gt;
       ,      partition_name&lt;br /&gt;
       from   dba_tab_partitions&lt;br /&gt;
       where  tablespace_name = &amp;#039;&amp;amp;&amp;amp;TABLESPACE_NAME&amp;#039;&lt;br /&gt;
       )                  a&lt;br /&gt;
,      dba_tab_partitions b&lt;br /&gt;
where  a.table_name       = b.table_name&lt;br /&gt;
and    b.tablespace_name != &amp;#039;&amp;amp;TABLESPACE_NAME&amp;#039;&lt;br /&gt;
/&lt;br /&gt;
undef TABLESPACE_NAME&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
If however, the intention is to drop the tablespace anyway, the tables need to be dropped before the tablespace can be dropped.&amp;lt;br /&amp;gt;&lt;br /&gt;
But ...tables with partitions in different tablespaces cannot be dropped. The partitions need to be dropped first!&amp;lt;br /&amp;gt;&lt;br /&gt;
Run the following query to generate statements to drop all the &amp;#039;problem&amp;#039; tables. When these have gone, the tablespace can be dropped.&lt;br /&gt;
* drop table partitions&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
spool /tmp/drop_table_partitions.sql&lt;br /&gt;
sqlplus / as sysdba&amp;lt;&amp;lt;EOSQL&lt;br /&gt;
set headi off newpa none feedb off trims on echo off&lt;br /&gt;
select &amp;#039;alter table &amp;#039;||table_owner||&amp;#039;.&amp;#039;||table_name||&amp;#039; drop partition &amp;#039;||partition_name||&amp;#039;;&amp;#039;&lt;br /&gt;
from   dba_tab_partitions&lt;br /&gt;
where  tablespace_name = &amp;#039;$TABLESPACE_NAME&amp;#039;&lt;br /&gt;
/&lt;br /&gt;
spool off&lt;br /&gt;
EOSQL&lt;br /&gt;
echo &amp;quot;@/tmp/drop_table_partitions.sql&amp;quot; | sqlplus / as sysdba&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* drop tables&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sqlplus / as sysdba&amp;lt;&amp;lt;EOSQL&lt;br /&gt;
select &amp;#039;drop table &amp;#039;||table_owner||&amp;#039;.&amp;#039;||table_name||&amp;#039;;&amp;#039;&lt;br /&gt;
from   dba_tab_partitions&lt;br /&gt;
where  tablespace_name = &amp;#039;$TABLESPACE_NAME&amp;#039;&lt;br /&gt;
spool /tmp/drop_tables.sql&lt;br /&gt;
/&lt;br /&gt;
spool off&lt;br /&gt;
EOSQL&lt;br /&gt;
echo &amp;quot;@/tmp/drop_tables.sql&amp;quot; | sqlplus / as sysdba&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* drop tablespace&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
drop tablespace ads_archive including contents and datafiles&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Find all table partitions in tablespaces with missing datafiles====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 1000 pages 100&lt;br /&gt;
col owner for a10&lt;br /&gt;
col segment_name for a40&lt;br /&gt;
col segment_type for a25&lt;br /&gt;
col partition_name for a20&lt;br /&gt;
col tablespace_name for a25&lt;br /&gt;
select owner&lt;br /&gt;
,      segment_name&lt;br /&gt;
,      segment_type&lt;br /&gt;
,      partition_name&lt;br /&gt;
,      tablespace_name&lt;br /&gt;
from   dba_segments&lt;br /&gt;
where  segment_type in (&amp;#039;TABLE PARTITION&amp;#039;, &amp;#039;TABLE SUBPARTITION&amp;#039;)&lt;br /&gt;
and    tablespace_name in (&lt;br /&gt;
                          select tablespace_name&lt;br /&gt;
                          from   dba_data_files&lt;br /&gt;
                          where  file_name like &amp;#039;%MISSING%&amp;#039;&lt;br /&gt;
                          )&lt;br /&gt;
order  by 1, 2, decode (segment_type, &amp;#039;TABLE SUBPARTITION&amp;#039;, 1, 2),4&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Use exchange partition to alter metadata of the tablespaces without moving the actual data====&lt;br /&gt;
* [https://community.oracle.com/thread/581401?start=15&amp;amp;tstart=0 this] is what you are looking for!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Workaround====&lt;br /&gt;
While working on the solution, a backup can be made using the &amp;quot;skip inaccessible&amp;quot; option. Put this in an rman cmdfile...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
connect catalog rmanusr/rmanpwd@rmancat&lt;br /&gt;
connect target sys/syspwd@adsa1&lt;br /&gt;
run {&lt;br /&gt;
allocate channel t1 type &amp;#039;sbt_tape&amp;#039; parms &amp;#039;ENV=(NSR_SERVER=hn6000.company.be,NSR_CLIENT=hn491,NSR_DATA_VOLUME_POOL=DD1DAILY,NSR_END_ERROR_IGNORE=TRUE)&amp;#039;;&lt;br /&gt;
allocate channel t2 type &amp;#039;sbt_tape&amp;#039; parms &amp;#039;ENV=(NSR_SERVER=hn6000.company.be,NSR_CLIENT=hn491,NSR_DATA_VOLUME_POOL=DD1DAILY,NSR_END_ERROR_IGNORE=TRUE)&amp;#039;;&lt;br /&gt;
configure retention policy to recovery window of 28 days;&lt;br /&gt;
configure controlfile autobackup on;&lt;br /&gt;
crosscheck archivelog all;&lt;br /&gt;
SQL &amp;#039;ALTER SYSTEM SWITCH LOGFILE&amp;#039;;&lt;br /&gt;
SQL &amp;#039;CREATE PFILE FROM SPFILE&amp;#039;;&lt;br /&gt;
backup filesperset 1 format &amp;#039;dbfull_%d_%I_%t_%s_%p&amp;#039; full database plus archivelog skip inaccessible delete all input;&lt;br /&gt;
backup current controlfile;&lt;br /&gt;
release channel t1;&lt;br /&gt;
release channel t2;&lt;br /&gt;
}&lt;br /&gt;
exit&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Another way of deleting the offending objects====&lt;br /&gt;
Taken from [http://www.dbarj.com.br/en/2015/01/resume-oracle-duplicate-database-failed-recovery-datafiles/ Recover from a failed RMAN duplicate]&amp;lt;br /&amp;gt;&lt;br /&gt;
Need to check it before running it blindly!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
set echo off feed off termo off trims on pages 0 newpa none lines 2000 headi off long 32000&lt;br /&gt;
col val for a1000&lt;br /&gt;
spool destroy_offending_objects.sql&lt;br /&gt;
&lt;br /&gt;
select to_clob (&amp;#039;alter table &amp;#039;|| table_name||&amp;#039; drop constraint &amp;#039;||constraint_name||&amp;#039;;&amp;#039;) Val&lt;br /&gt;
from user_constraints where constraint_type in (&amp;#039;R&amp;#039;,&amp;#039;P&amp;#039;) and table_name in (select distinct table_name from user_tab_partitions)&lt;br /&gt;
union all&lt;br /&gt;
select to_clob (&amp;#039;drop index &amp;#039;||index_name||&amp;#039;;&amp;#039;) Val from user_indexes where table_name in (select distinct table_name from user_tab_partitions)&lt;br /&gt;
union all&lt;br /&gt;
select to_clob (&amp;#039;alter table &amp;#039;||table_name|| &amp;#039; drop partition &amp;#039;||partition_name||&amp;#039;;&amp;#039;) from dba_tab_partitions&lt;br /&gt;
where tablespace_name in (select tablespace_name from dba_data_files where file_name like &amp;#039;%MISSING%&amp;#039;)&lt;br /&gt;
union all&lt;br /&gt;
Select case&lt;br /&gt;
when instr (VAl, &amp;#039;PARTITION&amp;#039;) = 0 Then&lt;br /&gt;
substr (Val,1,InStr (Val,&amp;#039;)&amp;#039;)+1)||&amp;#039;;&amp;#039;&lt;br /&gt;
else&lt;br /&gt;
substr (Val,1,InStr (Val,&amp;#039;)&amp;#039;)+1)||&amp;#039; local;&amp;#039;&lt;br /&gt;
End val&lt;br /&gt;
from&lt;br /&gt;
(select dbms_metadata.get_ddl (&amp;#039;INDEX&amp;#039;, index_name,&amp;#039;TEST&amp;#039;) Val from user_indexes where table_name in (select distinct table_name from user_tab_partitions))&lt;br /&gt;
union all&lt;br /&gt;
Select Val&lt;br /&gt;
from&lt;br /&gt;
(select dbms_metadata.get_dependent_ddl (&amp;#039;REF_CONSTRAINT&amp;#039;, table_name,&amp;#039;TEST&amp;#039;) Val&lt;br /&gt;
from user_tables where table_name in (select distinct table_name from user_tab_partitions join user_constraints using ( table_name)&lt;br /&gt;
where constraint_type=&amp;#039;R&amp;#039;))&lt;br /&gt;
union all&lt;br /&gt;
select Val&lt;br /&gt;
from&lt;br /&gt;
(select dbms_metadata.get_ddl (&amp;#039;CONSTRAINT&amp;#039;, constraint_name,&amp;#039;TEST&amp;#039;) Val&lt;br /&gt;
from user_constraints&lt;br /&gt;
where constraint_type=&amp;#039;P&amp;#039; and table_name in (select distinct table_name from user_tab_partitions)&lt;br /&gt;
)&lt;br /&gt;
union all&lt;br /&gt;
select to_clob (val)&lt;br /&gt;
from (select distinct &amp;#039;drop tablespace &amp;#039;||tablespace_name|| &amp;#039; including contents and datafiles;&amp;#039; val&lt;br /&gt;
from dba_tab_partitions&lt;br /&gt;
where tablespace_name in (select tablespace_name from dba_data_files where file_name like &amp;#039;%MISSING%&amp;#039;)&lt;br /&gt;
);&lt;br /&gt;
&lt;br /&gt;
spoo off&lt;br /&gt;
&lt;br /&gt;
@destroy_offending_objects&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORA-28112: failed to execute policy function===&lt;br /&gt;
when exporting or importing using [[Data Pump]]&amp;lt; /br&amp;gt;&lt;br /&gt;
During expdp is accompanied by &amp;quot;&amp;#039;&amp;#039;&amp;#039;ORA-31693: Table data object &amp;quot;SYSMAN&amp;quot;.&amp;quot;MGMT_IP_REPORT_DEF&amp;quot; failed to load/unload and is being skipped due to error:&amp;#039;&amp;#039;&amp;#039;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
===Reason===&lt;br /&gt;
This happens due to audit policies being defined on the table but the policy function is defined in another schema.&lt;br /&gt;
&lt;br /&gt;
===Solution===&lt;br /&gt;
Either drop the policy after importing the table with:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
begin&lt;br /&gt;
    for rec in (select * from dba_audit_policies where object_schema = &amp;#039;SYSMAN&amp;#039;) loop&lt;br /&gt;
        dbms_fga.drop_policy(object_schema =&amp;gt; rec.object_schema,&lt;br /&gt;
                             object_name =&amp;gt; rec.object_name,&lt;br /&gt;
                             policy_name =&amp;gt; rec.policy_name);  &lt;br /&gt;
    end loop;&lt;br /&gt;
end;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or exclude the policies during export by adding this to the .par file:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
exclude=FGA_POLICY&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or even better, give the necessary grants to the exporting user...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
grant exempt access policy to impexpusr;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The sysdba role has this automatically.&lt;br /&gt;
===ORA-17629: Cannot connect to the remote database server===&lt;br /&gt;
Active duplication fails to connect even though dns connection exists in tnsnames.ora&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
Problem:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
DUPLICATE TARGET DATABASE FROM ACTIVE DATABASE DORECOVER NOFILENAMECHECK;&lt;br /&gt;
&lt;br /&gt;
RMAN-03002: failure of Duplicate Db command at 05/27/2015 12:52:24&lt;br /&gt;
RMAN-05501: aborting duplication of target database&lt;br /&gt;
RMAN-03015: error occurred in stored script Memory Script&lt;br /&gt;
RMAN-03009: failure of backup command on ORA_DISK_1 channel at 05/27/2015 12:52:23&lt;br /&gt;
ORA-17629: Cannot connect to the remote database server&lt;br /&gt;
ORA-17627: ORA-12154: TNS:could not resolve the connect identifier specified&lt;br /&gt;
&lt;br /&gt;
ORA-17629: Cannot connect to the remote database server&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
Solution:&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
Update the tnsnames.ora of both destination &amp;#039;&amp;#039;&amp;#039;and&amp;#039;&amp;#039;&amp;#039; source ORACLE_HOMEs!&lt;br /&gt;
&lt;br /&gt;
===ORA-01950: no privileges on tablespace &amp;#039;SYSAUX&amp;#039;===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
26-JUN-15 03:12:27.545: &amp;gt;&amp;gt;&amp;gt; ORA-31642: the following SQL statement fails: &lt;br /&gt;
BEGIN &amp;quot;SYS&amp;quot;.&amp;quot;DBMS_RULE_EXP_RULES&amp;quot;.SCHEMA_CALLOUT(:1,0,1,&amp;#039;12.01.00.02.00&amp;#039;); END;&lt;br /&gt;
ORA-01950: no privileges on tablespace &amp;#039;SYSAUX&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Cause:&amp;#039;&amp;#039;&amp;#039;&amp;lt;br /&amp;gt;&lt;br /&gt;
In this case, it seems SYSMAN has no rights to create objects in the SYSAUX tablespace&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Solution:&amp;#039;&amp;#039;&amp;#039;&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter user SYSMAN quota unlimited on sysaux;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
More information [https://support.oracle.com/epmos/faces/SearchDocDisplay?_adf.ctrl-state=bov7jp5pq_4&amp;amp;_afrLoop=547371065896716#SYMPTOM here]&lt;br /&gt;
&lt;br /&gt;
===ORA-39080: failed to create queues &amp;quot;KUPC$C_1_20150616165037&amp;quot; and &amp;quot;KUPC$S_1_20150616165037&amp;quot; for Data Pump job===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
expdp /&lt;br /&gt;
&lt;br /&gt;
Export: Release 11.2.0.4.0 - Production on Tue Jun 16 16:50:36 2015&lt;br /&gt;
&lt;br /&gt;
Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.&lt;br /&gt;
&lt;br /&gt;
Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production&lt;br /&gt;
With the Partitioning, OLAP, Data Mining and Real Application Testing options&lt;br /&gt;
ORA-31626: job does not exist&lt;br /&gt;
ORA-31637: cannot create job SYS_EXPORT_SCHEMA_01 for user OPS$ORAIBM&lt;br /&gt;
ORA-06512: at &amp;quot;SYS.DBMS_SYS_ERROR&amp;quot;, line 95&lt;br /&gt;
ORA-06512: at &amp;quot;SYS.KUPV$FT_INT&amp;quot;, line 798&lt;br /&gt;
[[ORA-39080: failed to create queues &amp;quot;KUPC$C_1_20150616165037&amp;quot; and &amp;quot;KUPC$S_1_20150616165037&amp;quot; for Data Pump job]]&lt;br /&gt;
ORA-06512: at &amp;quot;SYS.DBMS_SYS_ERROR&amp;quot;, line 95&lt;br /&gt;
ORA-06512: at &amp;quot;SYS.KUPC$QUE_INT&amp;quot;, line 1534&lt;br /&gt;
ORA-24002: QUEUE_TABLE SYS.AQ$KUPC$DATAPUMP_QUETAB_1 does not exist&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Cause:====&lt;br /&gt;
Possibly some or all of OLAP module has got itself deinstalled.&lt;br /&gt;
====Solution:====&lt;br /&gt;
Try:&lt;br /&gt;
* Recompiling invalid objects. @?/rdbms/admin/utlrp&lt;br /&gt;
* Reinstalling DBMS_CUBE packages by (re)running catproc.sql. @?/rdbms/admin/catproc followed by @?/rdbms/admin/utlrp&lt;br /&gt;
* Reinstalling OLAP. @?/olap/admin/olap.sql SYSAUX TEMP; But see Metalink note ID 296187.1 for full instructions.&lt;br /&gt;
* Check metalink for bugs. See ID 345198.1 and possibly ID 453796.1&lt;br /&gt;
===ORA-14063: Unusable index exists on unique/primary constraint key===&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;ORA-39083: Object type CONSTRAINT failed to create with error:&amp;#039;&amp;#039;&amp;#039;&amp;lt;br /&amp;gt;&lt;br /&gt;
During an import datapump (impdp), import failed because indexes were in error before the tables were exported. This causes the import of rows to be skipped.&amp;lt;br /&amp;gt;&lt;br /&gt;
If the export cannot be done again (having compiled the indexes), then the metadata can be imported and the indexes compiled before importing the data.&lt;br /&gt;
* Import the metadata&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cat&amp;lt;&amp;lt;EOCAT &amp;gt;impdp_adst_ads_archive_metadata.par&lt;br /&gt;
userid=&amp;#039;/ as sysdba&amp;#039;&lt;br /&gt;
dumpfile=adst_ads_archive.dmp&lt;br /&gt;
logfile=impdp_adst_ads_archive_metadata.log&lt;br /&gt;
content=metadata_only&lt;br /&gt;
EOCAT&lt;br /&gt;
&lt;br /&gt;
impdp parfile=impdp_adst_ads_archive_metadata.par&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Find the bad indexes and recompile them&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select &amp;#039;alter index &amp;#039;|| owner||&amp;#039;.&amp;#039;||index_name||&amp;#039; rebuild online parallel 8;&amp;#039;&lt;br /&gt;
from   dba_indexes&lt;br /&gt;
where  status = &amp;#039;UNUSABLE&amp;#039;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Import the data&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cat&amp;lt;&amp;lt;EOCAT &amp;gt;impdp_adst_ads_archive_data.par&lt;br /&gt;
userid=&amp;#039;/ as sysdba&amp;#039;&lt;br /&gt;
dumpfile=adst_ads_archive.dmp&lt;br /&gt;
logfile=impdp_adst_ads_archive_data.log&lt;br /&gt;
table_exists_action=append&lt;br /&gt;
content=data_only&lt;br /&gt;
EOCAT&lt;br /&gt;
&lt;br /&gt;
impdp parfile=impdp_adst_ads_archive_data.par&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORA-09925: Unable to create audit trail file===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SQL&amp;gt; startup nomount pfile=&amp;quot;/oracle/TRSCRP1/admin/initTRSCRP1.ora&amp;quot;&lt;br /&gt;
ORA-09925: Unable to create audit trail file&lt;br /&gt;
SVR4 Error: 2: No such file or directory&lt;br /&gt;
Additional information: 9925&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
connected to auxiliary database (not started)&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-03002: failure of Duplicate Db command at 08/29/2017 15:53:09&lt;br /&gt;
RMAN-05501: aborting duplication of target database&lt;br /&gt;
RMAN-03015: error occurred in stored script Memory Script&lt;br /&gt;
RMAN-04014: startup failed: ORA-09925: Unable to create audit trail file&lt;br /&gt;
IBM AIX RISC System/6000 Error: 2: No such file or directory&lt;br /&gt;
Additional information: 9925&lt;br /&gt;
&lt;br /&gt;
Recovery Manager complete.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Problem====&lt;br /&gt;
This will be almost certainly one of two issues. Either the directory is not writable by the id that started the instance or the directory just does not exist.&lt;br /&gt;
====Solution====&lt;br /&gt;
Note there can be a difference between what you see when you type:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
show parameter audit&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
and when you type:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
strings -a $ORACLE_HOME/dbs/spfile${ORACLE_SID}.ora | grep -i audit&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
due to someone doing an &amp;quot;alter system&amp;quot; without the &amp;quot;scope=spfile&amp;quot; or &amp;quot;scope=both&amp;quot;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SQL&amp;gt; host ls -al /oracle/TRSCRP1/admin/adump&lt;br /&gt;
SQL&amp;gt; host mkdir /oracle/TRSCRP1/admin/adump&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===ORA-09925: Unable to create audit trail file===&lt;br /&gt;
When starting SQL*Plus with no db processes running (expecting to see &amp;quot;Connected to an idle instance&amp;quot;), we get this:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ERROR:&lt;br /&gt;
ORA-09925: Unable to create audit trail file&lt;br /&gt;
IBM AIX RISC System/6000 Error: 2: No such file or directory&lt;br /&gt;
Additional information: 9925&lt;br /&gt;
ORA-01075: you are currently logged on&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Filesystem permissions are fine&lt;br /&gt;
* &amp;#039;strings spfile&amp;lt;SID&amp;gt;.ora | grep audit&amp;#039; shows the correct directory&lt;br /&gt;
* Running on AIX&lt;br /&gt;
AIX is the clue here... need to check for semaphores and locked shared memory objects&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
(0) UCLID55D oraibm@solax082:/oracle/product/11.2.0.3/bin&amp;gt; sysresv&lt;br /&gt;
&lt;br /&gt;
IPC Resources for ORACLE_SID &amp;quot;UCLID55D&amp;quot; :&lt;br /&gt;
Shared Memory:&lt;br /&gt;
ID              KEY&lt;br /&gt;
8388640         0xffffffff&lt;br /&gt;
579862561       0xffffffff&lt;br /&gt;
384827426       0x326f32e8&lt;br /&gt;
&lt;br /&gt;
Semaphores:&lt;br /&gt;
ID              KEY&lt;br /&gt;
167772287       0xf09f4914&lt;br /&gt;
Oracle Instance alive for sid &amp;quot;UCLID55D&amp;quot;&lt;br /&gt;
&lt;br /&gt;
(0) UCLID55D oraibm@solax082:/oracle/product/11.2.0.3/bin&amp;gt; ipcrm -m 8388640&lt;br /&gt;
(0) UCLID55D oraibm@solax082:/oracle/product/11.2.0.3/bin&amp;gt; ipcrm -m 579862561&lt;br /&gt;
(0) UCLID55D oraibm@solax082:/oracle/product/11.2.0.3/bin&amp;gt; ipcrm -m 384827426&lt;br /&gt;
&lt;br /&gt;
(0) UCLID55D oraibm@solax082:/oracle/product/11.2.0.3/bin&amp;gt; ipcrm -s 167772287&lt;br /&gt;
&lt;br /&gt;
(0) UCLID55D oraibm@solax082:/oracle/product/11.2.0.3/bin&amp;gt; sysresv&lt;br /&gt;
&lt;br /&gt;
IPC Resources for ORACLE_SID &amp;quot;UCLID55D&amp;quot; :&lt;br /&gt;
Shared Memory&lt;br /&gt;
ID              KEY&lt;br /&gt;
No shared memory segments used&lt;br /&gt;
Semaphores:&lt;br /&gt;
ID              KEY&lt;br /&gt;
No semaphore resources used&lt;br /&gt;
Oracle Instance not alive for sid &amp;quot;UCLID55D&amp;quot;&lt;br /&gt;
&lt;br /&gt;
(0) UCLID55D oraibm@solax082:/oracle/product/11.2.0.3/bin&amp;gt; ps -ef | grep UCLID55D&lt;br /&gt;
oraibm 3326 23776 0 14:12:05 pts/1 0:00 grep UCLID55D &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===RMAN-06023: no backup or copy of datafile 1 found to restore===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-03002: failure of Duplicate Db command at 05/16/2018 16:08:13&lt;br /&gt;
RMAN-05501: aborting duplication of target database&lt;br /&gt;
RMAN-05556: not all datafiles have backups that can be recovered to SCN 278250901080&lt;br /&gt;
RMAN-03015: error occurred in stored script Memory Script&lt;br /&gt;
RMAN-06026: some targets not found - aborting restore&lt;br /&gt;
RMAN-06023: no backup or copy of datafile 7 found to restore&lt;br /&gt;
RMAN-06023: no backup or copy of datafile 6 found to restore&lt;br /&gt;
RMAN-06023: no backup or copy of datafile 5 found to restore&lt;br /&gt;
RMAN-06023: no backup or copy of datafile 4 found to restore&lt;br /&gt;
RMAN-06023: no backup or copy of datafile 3 found to restore&lt;br /&gt;
RMAN-06023: no backup or copy of datafile 2 found to restore&lt;br /&gt;
RMAN-06023: no backup or copy of datafile 1 found to restore&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Seems pretty straightforward? SCN was set too early for the retention period. But no, not this time.&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
RMAN&amp;gt; list backup of datafile 1;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
List of Backup Sets&lt;br /&gt;
===================&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
BS Key  Type LV Size       Device Type Elapsed Time Completion Time&lt;br /&gt;
------- ---- -- ---------- ----------- ------------ -------------------&lt;br /&gt;
110170340 Incr 0  132.90G    SBT_TAPE    00:18:32     2018-05-14 01:19:40&lt;br /&gt;
        BP Key: 110170345   Status: AVAILABLE  Compressed: NO  Tag: WEEKLY_FULL&lt;br /&gt;
        Handle: 24639762_REPORTA_07t2r3uk_1_1   Media: V_17152809_77191330&lt;br /&gt;
  List of Datafiles in backup set 110170340&lt;br /&gt;
  File LV Type Ckp SCN    Ckp Time            Name&lt;br /&gt;
  ---- -- ---- ---------- ------------------- ----&lt;br /&gt;
  1    0  Incr 277998128991 2018-05-14 01:01:08 /cln/acc/ora_data3/reporta/system01.dbf&lt;br /&gt;
&lt;br /&gt;
BS Key  Type LV Size       Device Type Elapsed Time Completion Time&lt;br /&gt;
------- ---- -- ---------- ----------- ------------ -------------------&lt;br /&gt;
110355808 Incr 1  204.00M    SBT_TAPE    00:05:13     2018-05-15 01:06:22&lt;br /&gt;
        BP Key: 110355813   Status: AVAILABLE  Compressed: NO  Tag: DAILY_INCREMENTAL&lt;br /&gt;
        Handle: 24661053_REPORTA_3ft2toal_1_1   Media: V_17173010_77253424&lt;br /&gt;
  List of Datafiles in backup set 110355808&lt;br /&gt;
  File LV Type Ckp SCN    Ckp Time            Name&lt;br /&gt;
  ---- -- ---- ---------- ------------------- ----&lt;br /&gt;
  1    1  Incr 278044267395 2018-05-15 01:01:09 /cln/acc/ora_data3/reporta/system01.dbf&lt;br /&gt;
&lt;br /&gt;
BS Key  Type LV Size       Device Type Elapsed Time Completion Time&lt;br /&gt;
------- ---- -- ---------- ----------- ------------ -------------------&lt;br /&gt;
110543802 Incr 1  237.00M    SBT_TAPE    00:05:51     2018-05-16 01:07:40&lt;br /&gt;
        BP Key: 110543807   Status: AVAILABLE  Compressed: NO  Tag: DAILY_INCREMENTAL&lt;br /&gt;
        Handle: 24681602_REPORTA_6nt30cnt_1_1   Media: V_17133646_77315270&lt;br /&gt;
  List of Datafiles in backup set 110543802&lt;br /&gt;
  File LV Type Ckp SCN    Ckp Time            Name&lt;br /&gt;
  ---- -- ---- ---------- ------------------- ----&lt;br /&gt;
  1    1  Incr 278286445856 2018-05-16 01:01:50 /cln/acc/ora_data3/reporta/system01.dbf&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
SCN was only 12 hours ago with a retention of 28 days! The backup piece dated 2018-05-15 01:06:22 is clearly available and on the device type set_tape.&amp;lt;br /&amp;gt;&lt;br /&gt;
The trick here was to look back through the logs and look more closely at what the file restore message was saying...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
channel t0: starting datafile backup set restore&lt;br /&gt;
channel t0: specifying datafile(s) to restore from backup set&lt;br /&gt;
channel t0: restoring datafile 00001 to /cln/acc/ora_data3/reporta/system01.dbf             &amp;lt; &amp;lt; &amp;lt; ==============&lt;br /&gt;
channel t0: reading from backup piece dbfull_REPORTA_738887052_967580186_116_1&lt;br /&gt;
channel t2: ORA-19870: error while restoring backup piece dbfull_REPORTA_738887052_967579750_113_1&lt;br /&gt;
ORA-19507: failed to retrieve sequential file, handle=&amp;quot;dbfull_REPORTA_738887052_967579750_113_1&amp;quot;, parms=&amp;quot;&amp;quot;&lt;br /&gt;
ORA-27029: skgfrtrv: sbtrestore returned error&lt;br /&gt;
ORA-19511: non RMAN, but media manager or vendor specific failure, error text:&lt;br /&gt;
   CreateOraObject20: Job[0] thread[55116090]: Restore: GetBackupInfo() for Archive File[dbfull_REPORTA_738887052_967579750_113_1] failed.&lt;br /&gt;
ORA-0651&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
It was not the fact that it could not find the data on tape, it was that it could not save the file to the location indicated!!&lt;br /&gt;
In the RMAN DUPLICATE script, I had all the file paths redirected (a mixture of convert parameters and spfile set) to a /restore filesystem.&amp;lt;br /&amp;gt;&lt;br /&gt;
But I forgot one!&amp;lt;br /&amp;gt;&lt;br /&gt;
A handy thing to do is to search out the file paths with this to see if something is still wrong:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cd $ORACLE_HOME/dbs&lt;br /&gt;
strings -a spfile${ORACLE_SID}.ora | grep dest&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This should show any paths still not getting caught by the DUPLICATE script.&lt;br /&gt;
&lt;br /&gt;
===RMAN-06136: ORACLE error from auxiliary database: ORA-06502: PL/SQL: numeric or value error===&lt;br /&gt;
When cloning a database, the duplicate fails with this error.&lt;br /&gt;
====Problem====&lt;br /&gt;
This duplicate had no target connection but did have a catalog and auxiliary connection.&lt;br /&gt;
In the catalog (which was the catalog where the target was registerd), there was also an entry in that catalog with the same name as the auxiliary - left over from the days when these 2 instances were Primary and Standby in a Dataguard configuration.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
Datafile 414 skipped by request&lt;br /&gt;
Datafile 415 skipped by request&lt;br /&gt;
Datafile 419 skipped by request&lt;br /&gt;
Datafile 420 skipped by request&lt;br /&gt;
Datafile 421 skipped by request&lt;br /&gt;
&lt;br /&gt;
DBGSQL:     AUXILIARY&amp;gt; begin :ofname := sys.dbms_backup_restore.convertFileName( fname   =&amp;gt;   :ifname, ftype   =&amp;gt;   :iftype, osftype =&amp;gt;   TRUE); end;&lt;br /&gt;
DBGSQL:        sqlcode = 6502&lt;br /&gt;
DBGSQL:         B :ofname = NULL&lt;br /&gt;
DBGSQL:         B :ifname =&lt;br /&gt;
DBGSQL:         B :iftype = 2&lt;br /&gt;
restarting auxiliary database without server parameter file&lt;br /&gt;
Oracle instance started&lt;br /&gt;
&lt;br /&gt;
Total System Global Area   32068440064 bytes&lt;br /&gt;
&lt;br /&gt;
Fixed Size                     2262200 bytes&lt;br /&gt;
Variable Size              16978545480 bytes&lt;br /&gt;
Database Buffers           15032385536 bytes&lt;br /&gt;
Redo Buffers                  55246848 bytes&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-03002: failure of Duplicate Db command at 10/04/2017 14:50:29&lt;br /&gt;
RMAN-05501: aborting duplication of target database&lt;br /&gt;
RMAN-06136: ORACLE error from auxiliary database: ORA-06502: PL/SQL: numeric or value error&lt;br /&gt;
&lt;br /&gt;
Recovery Manager complete.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Solution====&lt;br /&gt;
Connect to the catalog and unregister the name of the auxiliary database. It shouldn&amp;#039;t be there anyway.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rman catalog rmanusr/rmanpwd@rmancat&lt;br /&gt;
&lt;br /&gt;
Recovery Manager: Release 11.2.0.4.0 - Production on Wed Oct 4 15:00:00 2017&lt;br /&gt;
&lt;br /&gt;
Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.&lt;br /&gt;
&lt;br /&gt;
connected to recovery catalog database&lt;br /&gt;
&lt;br /&gt;
RMAN&amp;gt; set dbid 4260753020;&lt;br /&gt;
&lt;br /&gt;
executing command: SET DBID&lt;br /&gt;
database name is &amp;quot;LBK&amp;quot; and DBID is 4260753020&lt;br /&gt;
&lt;br /&gt;
RMAN&amp;gt; list db_unique_name of database;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
List of Databases&lt;br /&gt;
DB Key  DB Name  DB ID            Database Role    Db_unique_name&lt;br /&gt;
------- ------- ----------------- ---------------  ------------------&lt;br /&gt;
13301587 LBK      4260753020       PRIMARY          LBK&lt;br /&gt;
13301587 LBK      4260753020       STANDBY          ACC_PERF&lt;br /&gt;
13301587 LBK      4260753020       STANDBY          LBKRO&lt;br /&gt;
&lt;br /&gt;
RMAN&amp;gt; unregister db_unique_name &amp;#039;ACC_PERF&amp;#039;;&lt;br /&gt;
&lt;br /&gt;
database db_unique_name is &amp;quot;ACC_PERF&amp;quot;, db_name is &amp;quot;LBK&amp;quot; and DBID is 4260753020&lt;br /&gt;
&lt;br /&gt;
Want to unregister the database with target db_unique_name (enter YES or NO)? YES&lt;br /&gt;
database with db_unique_name ACC_PERF unregistered from the recovery catalog&lt;br /&gt;
&lt;br /&gt;
RMAN&amp;gt; exit&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORA-39181: Only partial table data may be exported due to fine grain access control on &amp;quot;owner&amp;quot;.&amp;quot;&amp;lt;table_name&amp;gt;&amp;quot;===&lt;br /&gt;
&lt;br /&gt;
===Reason===&lt;br /&gt;
This happens when applications are designed with fine-grained access.&lt;br /&gt;
===Solution===&lt;br /&gt;
Grant the necessary privileges to the exporting user...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
grant exempt access policy to ops$oraibm;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORA-04030: out of process memory when trying to allocate 2520 bytes===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
expdp problem (ORA-04030: out of process memory when trying to allocate 2520 bytes (pga heap,koh-kghu call heap))&lt;br /&gt;
&lt;br /&gt;
select value from v$pgastat where name=&amp;#039;maximum PGA allocated&amp;#039;;&lt;br /&gt;
&lt;br /&gt;
SHOW PARAMETER TARGET&lt;br /&gt;
&lt;br /&gt;
ORA-04030: out of process memory when trying to allocate 2520 bytes (pga heap,koh-kghu call heap)&lt;br /&gt;
&lt;br /&gt;
alter system reset pga_aggregate_target scope=spfile;&lt;br /&gt;
&lt;br /&gt;
show sga&lt;br /&gt;
&lt;br /&gt;
select * from v$pgastat;&lt;br /&gt;
&lt;br /&gt;
show parameter process&lt;br /&gt;
&lt;br /&gt;
select sum(value)/1024/1024 Mb&lt;br /&gt;
from   v$sesstat s, v$statname n&lt;br /&gt;
where  1=1&lt;br /&gt;
and    n.STATISTIC# = s.STATISTIC#&lt;br /&gt;
and    name = &amp;#039;session pga memory&amp;#039;&lt;br /&gt;
&lt;br /&gt;
show parameter WORKAREA&lt;br /&gt;
&lt;br /&gt;
select value from v$pgastat where name=&amp;#039;maximum PGA allocated&amp;#039;;&lt;br /&gt;
&lt;br /&gt;
alter system set memory_max_target=10G scope=spfile;&lt;br /&gt;
&lt;br /&gt;
alter system set memory_target=3G scope=both;&lt;br /&gt;
&lt;br /&gt;
select * from v$memory_target_advice order by memory_size;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORA-04031: unable to allocate 32 bytes of shared memory (&amp;quot;shared pool&amp;quot;,&amp;quot;select name,online$,contents...&amp;quot;,&amp;quot;KGLH0^e5705bfc&amp;quot;,&amp;quot;kglHeapInitialize:temp&amp;quot;)===&lt;br /&gt;
* [https://blogs.oracle.com/db/entry/ora-4031_troubleshooting ORA-4031 Troubleshooting]&lt;br /&gt;
* [https://support.oracle.com/epmos/faces/DocumentDisplay?_afrLoop=89215376348478&amp;amp;id=396940.1&amp;amp;_afrWindowMode=0&amp;amp;_adf.ctrl-state=u1z0xcppg_4 Troubleshooting and Diagnosing ORA-4031 Error - (Doc ID 396940.1)]&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ORA-04031: unable to allocate  bytes of shared memory (&amp;quot;&amp;quot;,&amp;quot;&amp;quot;,&amp;quot;&amp;quot;,&amp;quot;&amp;quot;) &lt;br /&gt;
ORA-04031: unable to allocate 32 bytes of shared memory (&amp;quot;shared pool&amp;quot;,&amp;quot;select name,online$,contents...&amp;quot;,&amp;quot;KGLH0^e5705bfc&amp;quot;,&amp;quot;kglHeapInitialize:temp&amp;quot;) &lt;br /&gt;
Incident details in: /oracle/diag/rdbms/mape/MAPE/incident/incdir_86754/MAPE_dm00_14221536_i86754.trc &lt;br /&gt;
Wed Jul 31 20:42:50 2013 &lt;br /&gt;
Dumping diagnostic data in directory=[cdmp_20130731204250], requested by (instance=1, osid=14221536 (DM00)), summary=[incident=86753]. &lt;br /&gt;
Wed Jul 31 20:42:51 2013 &lt;br /&gt;
Sweep [inc][86754]: completed &lt;br /&gt;
Sweep [inc][86753]: completed &lt;br /&gt;
Sweep [inc2][86753]: completed &lt;br /&gt;
Wed Jul 31 20:42:57 2013 &lt;br /&gt;
Use ADRCI or Support Workbench to package the incident. &lt;br /&gt;
See Note 411.1 at My Oracle Support for error and packaging details. &lt;br /&gt;
Dumping diagnostic data in directory=[cdmp_20130731204257], requested by (instance=1, osid=14221536 (DM00)), summary=[incident=86754]. &lt;br /&gt;
Wed Jul 31 20:43:35 2013 &lt;br /&gt;
Errors in file /oracle/diag/rdbms/mape/MAPE/trace/MAPE_dw02_40567024.trc  (incident=82993): &lt;br /&gt;
ORA-04031: unable to allocate 32 bytes of shared memory (&amp;quot;shared pool&amp;quot;,&amp;quot;select order#,columns,types ...&amp;quot;,&amp;quot;KGLH0^470434f8&amp;quot;,&amp;quot;kglHeapInitialize:temp&amp;quot;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Database had already crashed so nothing to do but:&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
(0) MAPE ora@x025:/home/ora&amp;gt; sqlplus / as sysdba&lt;br /&gt;
&lt;br /&gt;
SQL*Plus: Release 11.2.0.3.0 Production on Fri Aug 2 14:26:20 2013&lt;br /&gt;
&lt;br /&gt;
Copyright (c) 1982, 2011, Oracle.  All rights reserved.&lt;br /&gt;
&lt;br /&gt;
Connected.&lt;br /&gt;
SYS@MAPE&amp;gt; alter system flush shared_pool;&lt;br /&gt;
alter system flush shared_pool&lt;br /&gt;
*&lt;br /&gt;
ERROR at line 1:&lt;br /&gt;
ORA-01012: not logged on&lt;br /&gt;
Process ID: 0&lt;br /&gt;
Session ID: 0 Serial number: 0&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
SYS@MAPE&amp;gt; shutdown abort&lt;br /&gt;
ORACLE instance shut down.&lt;br /&gt;
SYS@MAPE&amp;gt; startup&lt;br /&gt;
ORACLE instance started.&lt;br /&gt;
&lt;br /&gt;
Total System Global Area  734892032 bytes&lt;br /&gt;
Fixed Size                  2225128 bytes&lt;br /&gt;
Variable Size             398461976 bytes&lt;br /&gt;
Database Buffers          318767104 bytes&lt;br /&gt;
Redo Buffers               15437824 bytes&lt;br /&gt;
Database mounted.&lt;br /&gt;
Database opened.&lt;br /&gt;
&lt;br /&gt;
SYS@MAPE&amp;gt; show parameter pool&lt;br /&gt;
&lt;br /&gt;
NAME                                 TYPE                           VALUE&lt;br /&gt;
------------------------------------ ------------------------------ ------------------------------&lt;br /&gt;
buffer_pool_keep                     string&lt;br /&gt;
buffer_pool_recycle                  string&lt;br /&gt;
global_context_pool_size             string&lt;br /&gt;
java_pool_size                       big integer                    0&lt;br /&gt;
large_pool_size                      big integer                    0&lt;br /&gt;
olap_page_pool_size                  big integer                    0&lt;br /&gt;
shared_pool_reserved_size            big integer                    18M&lt;br /&gt;
shared_pool_size                     big integer                    208M&lt;br /&gt;
streams_pool_size                    big integer                    0&lt;br /&gt;
SYS@MAPE&amp;gt; show sga&lt;br /&gt;
&lt;br /&gt;
Total System Global Area  734892032 bytes&lt;br /&gt;
Fixed Size                  2225128 bytes&lt;br /&gt;
Variable Size             385879064 bytes&lt;br /&gt;
Database Buffers          331350016 bytes&lt;br /&gt;
Redo Buffers               15437824 bytes&lt;br /&gt;
SYS@MAPE&amp;gt; exit&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
but for reference, the causes could well be the applications running on the database are not using bind variables...&amp;lt;br /&amp;gt;&lt;br /&gt;
From [http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:528893984337 asktom.oracle.com]&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
Just to give you a tiny idea of how huge of a difference this &lt;br /&gt;
can make performance wise, you only need to run a very small &lt;br /&gt;
test:&lt;br /&gt;
&lt;br /&gt;
tkyte@TKYTE816&amp;gt; alter system flush shared_pool;&lt;br /&gt;
System altered.&lt;br /&gt;
&lt;br /&gt;
tkyte@TKYTE816&amp;gt; declare&lt;br /&gt;
  2      type rc is ref cursor;&lt;br /&gt;
  3      l_rc rc;&lt;br /&gt;
  4      l_dummy all_objects.object_name%type;&lt;br /&gt;
  5      l_start number default dbms_utility.get_time;&lt;br /&gt;
  6  begin&lt;br /&gt;
  7      for i in 1 .. 1000&lt;br /&gt;
  8      loop&lt;br /&gt;
  9          open l_rc for&lt;br /&gt;
 10          &amp;#039;select object_name&lt;br /&gt;
 11             from all_objects&lt;br /&gt;
 12            where object_id = &amp;#039; || i;&lt;br /&gt;
 13          fetch l_rc into l_dummy;&lt;br /&gt;
 14          close l_rc;&lt;br /&gt;
 15      end loop;&lt;br /&gt;
 16      dbms_output.put_line&lt;br /&gt;
 17      ( round( (dbms_utility.get_time-l_start)/100, 2 ) ||&lt;br /&gt;
 18        &amp;#039; seconds...&amp;#039; );&lt;br /&gt;
 19  end;&lt;br /&gt;
 20  /&lt;br /&gt;
14.86 seconds...&lt;br /&gt;
&lt;br /&gt;
PL/SQL procedure successfully completed.&lt;br /&gt;
&lt;br /&gt;
tkyte@TKYTE816&amp;gt; declare&lt;br /&gt;
  2      type rc is ref cursor;&lt;br /&gt;
  3      l_rc rc;&lt;br /&gt;
  4      l_dummy all_objects.object_name%type;&lt;br /&gt;
  5      l_start number default dbms_utility.get_time;&lt;br /&gt;
  6  begin&lt;br /&gt;
  7      for i in 1 .. 1000&lt;br /&gt;
  8      loop&lt;br /&gt;
  9          open l_rc for&lt;br /&gt;
 10          &amp;#039;select object_name&lt;br /&gt;
 11             from all_objects&lt;br /&gt;
 12            where object_id = :x&amp;#039;&lt;br /&gt;
 13          using i;&lt;br /&gt;
 14          fetch l_rc into l_dummy;&lt;br /&gt;
 15          close l_rc;&lt;br /&gt;
 16      end loop;&lt;br /&gt;
 17      dbms_output.put_line&lt;br /&gt;
 18      ( round( (dbms_utility.get_time-l_start)/100, 2 ) ||&lt;br /&gt;
 19        &amp;#039; seconds...&amp;#039; );&lt;br /&gt;
 20  end;&lt;br /&gt;
 21  /&lt;br /&gt;
1.27 seconds...&lt;br /&gt;
&lt;br /&gt;
PL/SQL procedure successfully completed.&lt;br /&gt;
&lt;br /&gt;
That is pretty dramatic.  The fact is that not only does this &lt;br /&gt;
execute much faster (we spent more time PARSING our queries then &lt;br /&gt;
actually EXECUTING them!) it will let more users use your system &lt;br /&gt;
simultaneously.&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
and from [http://asktom.oracle.com/pls/asktom/f?p=100:11:::::P11_QUESTION_ID:1163635055580 linked question]&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
Lbrary cache latch contention is typically caused by NOT using bind variables.  It is due &lt;br /&gt;
to excessive parsing of statements.&lt;br /&gt;
&lt;br /&gt;
One way to see if this might be the case in your situation is to run a script like:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
create table t1 as select sql_text from v$sqlarea;&lt;br /&gt;
&lt;br /&gt;
alter table t1 add sql_text_wo_constants varchar2(1000);&lt;br /&gt;
&lt;br /&gt;
create or replace function &lt;br /&gt;
remove_constants( p_query in varchar2 ) return varchar2&lt;br /&gt;
as&lt;br /&gt;
    l_query long;&lt;br /&gt;
    l_char  varchar2(1);&lt;br /&gt;
    l_in_quotes boolean default FALSE;&lt;br /&gt;
begin&lt;br /&gt;
    for i in 1 .. length( p_query )&lt;br /&gt;
    loop&lt;br /&gt;
        l_char := substr(p_query,i,1);&lt;br /&gt;
        if ( l_char = &amp;#039;&amp;#039;&amp;#039;&amp;#039; and l_in_quotes )&lt;br /&gt;
        then&lt;br /&gt;
            l_in_quotes := FALSE;&lt;br /&gt;
        elsif ( l_char = &amp;#039;&amp;#039;&amp;#039;&amp;#039; and NOT l_in_quotes )&lt;br /&gt;
        then&lt;br /&gt;
            l_in_quotes := TRUE;&lt;br /&gt;
            l_query := l_query || &amp;#039;&amp;#039;&amp;#039;#&amp;#039;;&lt;br /&gt;
        end if;&lt;br /&gt;
        if ( NOT l_in_quotes ) then&lt;br /&gt;
            l_query := l_query || l_char;&lt;br /&gt;
        end if;&lt;br /&gt;
    end loop;&lt;br /&gt;
    l_query := translate( l_query, &amp;#039;0123456789&amp;#039;, &amp;#039;@@@@@@@@@@&amp;#039; );&lt;br /&gt;
    for i in 0 .. 8 loop&lt;br /&gt;
        l_query := replace( l_query, lpad(&amp;#039;@&amp;#039;,10-i,&amp;#039;@&amp;#039;), &amp;#039;@&amp;#039; );&lt;br /&gt;
        l_query := replace( l_query, lpad(&amp;#039; &amp;#039;,10-i,&amp;#039; &amp;#039;), &amp;#039; &amp;#039; );&lt;br /&gt;
    end loop;&lt;br /&gt;
    return upper(l_query);&lt;br /&gt;
end;&lt;br /&gt;
/&lt;br /&gt;
update t1 set sql_text_wo_constants = remove_constants(sql_text);&lt;br /&gt;
&lt;br /&gt;
select sql_text_wo_constants, count(*)&lt;br /&gt;
  from t1&lt;br /&gt;
 group by sql_text_wo_constants&lt;br /&gt;
having count(*) &amp;gt; 100&lt;br /&gt;
 order by 2&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The output of that last query will show you statements that are identical in the shared &lt;br /&gt;
pool after all numbers and character string constants have been removed.  These &lt;br /&gt;
statements -- and more importantly their counts -- are the potential bottlenecks.  In &lt;br /&gt;
addition to causing the contention, they will be HUGE cpu consumers.  &lt;br /&gt;
&lt;br /&gt;
If you discover your applications do not use bind variables -- you must have this &lt;br /&gt;
corrected.  You&amp;#039;ll never have a good hit ratio if everyone submits &amp;quot;unique&amp;quot; sql.  Your &lt;br /&gt;
shared pool will never be used right and you&amp;#039;ll be using excessive CPU (90% of the time &lt;br /&gt;
it takes to process &amp;quot;insert into t values ( 1 )&amp;quot; is parsing.  If you use &amp;quot;insert into t &lt;br /&gt;
values ( :x )&amp;quot;, and bind the value of 1 -- then the next person that runs that insert &lt;br /&gt;
will benefit from your work and run that much faster. &lt;br /&gt;
...&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Advice from Oracle concerning a concrete (12c) example of unable to allocate 52824 bytes of shared memory (&amp;quot;shared pool&amp;quot;,...====&lt;br /&gt;
This was from a ticket raised for a Data Pump export that consistently failed with:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Processing object type SCHEMA_EXPORT/TABLE/PROCACT_INSTANCE&lt;br /&gt;
Processing object type SCHEMA_EXPORT/TABLE/TABLE&lt;br /&gt;
ORA-39014: One or more workers have prematurely exited.&lt;br /&gt;
ORA-39029: worker 1 with process name &amp;quot;DW00&amp;quot; prematurely terminated&lt;br /&gt;
ORA-31671: Worker process DW00 had an unhandled exception.&lt;br /&gt;
ORA-04031: unable to allocate 52824 bytes of shared memory (&amp;quot;shared pool&amp;quot;,&amp;quot;unknown object&amp;quot;,&amp;quot;KTSL subheap&amp;quot;,&amp;quot;ktsl_load_disp-2&amp;quot;)&lt;br /&gt;
ORA-06512: at &amp;quot;SYS.KUPW$WORKER&amp;quot;, line 2122&lt;br /&gt;
ORA-06512: at line 2&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
The error ORA-4031 on the shared pool can indicate one of two things:&lt;br /&gt;
- insufficient space for the shared pool (so insufficient memory in SGA at that time)&lt;br /&gt;
OR&lt;br /&gt;
- although there is enough memory, it is fragmented and no contiguous chunk can be allocated to satisfy the latest memory request.&lt;br /&gt;
&lt;br /&gt;
Each SGA has a little fragmentation of course because of the operations taking place, so in your case the fragmentation is represented by the 18M of free memory, which exists in uncontiguous chunks.&lt;br /&gt;
This means that the root cause of the error is insufficient contiguous memory to allocate 12312 bytes of shared memory.&lt;br /&gt;
&lt;br /&gt;
ACTION PLAN&lt;br /&gt;
==============&lt;br /&gt;
1. We see memory_target=2000M. This is too little to support a 12c database, even when it has little activity.&lt;br /&gt;
As you may know 1.7G for the SGA was acceptable when speaking of 32bit OSs where it was hardly possible to make use of more than that.&lt;br /&gt;
Since you have a 64 bit system, the addressable memory is virtually unlimited.&lt;br /&gt;
Furthermore, by using AMM (memory_target&amp;gt;0) this memory is divided between the SGA and the PGA (the user processes) which in fact, depending on the number of connections, can limit the SGA even more.&lt;br /&gt;
So the first recommendation is to increase the value of memory_target to 4G for example. There is no ideal value, but this would be a reasonable starting value for tuning.&lt;br /&gt;
&lt;br /&gt;
You can do further tuning of the memory using the view V$MEMORY_TARGET_ADVICE.&lt;br /&gt;
The view V$MEMORY_TARGET_ADVICE provides tuning advice for the MEMORY_TARGET initialization parameter:&lt;br /&gt;
SQL&amp;gt; SELECT * FROM v$memory_target_advice ORDER BY memory_size;&lt;br /&gt;
&lt;br /&gt;
The dynamic performance view V$MEMORY_DYNAMIC_COMPONENTS shows the current sizes of all dynamically tuned memory components, including the total sizes of the SGA and instance PGA.&lt;br /&gt;
&lt;br /&gt;
You can also use V$MEMORY_RESIZE_OPS which has a circular history buffer of the last 800 memory resize requests.&lt;br /&gt;
&lt;br /&gt;
2. Since the AMM (you have memory_target&amp;gt;0) is used, then make sure to set:&lt;br /&gt;
 _shared_pool_reserved_pct to 10 or 15 to ensure that when the Shared Pool grows or shrinks automatically, the Reserved Area will change as well.&lt;br /&gt;
&lt;br /&gt;
SQL&amp;gt; alter system set &amp;quot;_shared_pool_reserved_pct&amp;quot;=15 scope=spfile;&lt;br /&gt;
--restart the instance&lt;br /&gt;
&lt;br /&gt;
FYI: By default, Oracle configures a small Reserved Pool (or Reserved Area) inside the Shared Pool.&lt;br /&gt;
This memory can be used for operations such as PL/SQL and trigger compilation or for temporary space while loading Java objects.&lt;br /&gt;
After the memory allocated from the Reserved Pool is freed, it returns to the Reserved Pool.&lt;br /&gt;
5% of the Shared Pool is set aside as the Reserved Pool to handle allocations of memory higher than defined by the hidden parameter _shared_pool_reserved_pct.&lt;br /&gt;
In some application environments, 5% is too small.&lt;br /&gt;
&lt;br /&gt;
3. Set shared_pool_size=500M or even more. This will represent a minimum amount of memory that will always be available to the shared pool.&lt;br /&gt;
If more memory is needed at any moment, if it is available, it will be allocated to the shared pool over the 500M.&lt;br /&gt;
&lt;br /&gt;
Implement the above steps, monitor the database and let us know the result,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORA-00392: log 1 of thread 1 is being cleared, operation not allowed===&lt;br /&gt;
After performing an active duplication, this happened when trying to open the database.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SQL&amp;gt; alter database open resetlogs&lt;br /&gt;
alter database open resetlogs&lt;br /&gt;
*&lt;br /&gt;
ERROR at line 1:&lt;br /&gt;
ORA-00392: log 1 of thread 1 is being cleared, operation not allowed&lt;br /&gt;
ORA-00312: online log 1 thread 1: &amp;#039;/oracle/oradata/testdb/redo/redo01.log&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SQL&amp;gt; select group#,thread#,status from v$log;&lt;br /&gt;
 &lt;br /&gt;
GROUP#   THREAD#   STATUS&lt;br /&gt;
-------  --------- ----------------&lt;br /&gt;
1        1         CLEARING_CURRENT&lt;br /&gt;
2        1         STALE&lt;br /&gt;
3        1         STALE&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Check the alert log! Always a good idea to get extra info. In here we find the answer&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ORA-00344: unable to re-create online log&lt;br /&gt;
&amp;#039;/oracle/oradata/testdb/redo/redo01.log&amp;#039;&lt;br /&gt;
ORA-27040: file create error, unable to create file&lt;br /&gt;
Linux-x86_64 Error: 2: No such file or directory&lt;br /&gt;
Additional information: 1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
So the clue is that the file cannot be created at the operating system level.&amp;lt;br /&amp;gt;&lt;br /&gt;
Doing a &amp;lt;code&amp;gt;df -k /oracle/oradata/testdb/redo&amp;lt;/code&amp;gt; shows us that the filesystem was created too small for the destination database.&amp;lt;br /&amp;gt;&lt;br /&gt;
In this case, we do not want the redolog directory to be as big as on the source db as there will be almost no movement on the destination.&amp;lt;br /&amp;gt;&lt;br /&gt;
I should have specified the LOGFILE parameter in the DUPLICATE clause to setup new, smaller redolog files.&amp;lt;br /&amp;gt;&lt;br /&gt;
As this duplicate takes over 12 hours, I didn&amp;#039;t want to do it again so I created symbolic links in the redolog directory pointing out to a larger filesystem with more space.&amp;lt;br /&amp;gt;&lt;br /&gt;
This allowed the creation of the redolog files. They can then be resized once the database has been opened.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cd /oracle/oradata/testdb/redo&lt;br /&gt;
ln -s /tmp/redo01.log redo01.log&lt;br /&gt;
ln -s /tmp/redo02.log redo02.log&lt;br /&gt;
ln -s /tmp/redo03.log redo03.log&lt;br /&gt;
&lt;br /&gt;
SQL&amp;gt; alter database open resetlogs&lt;br /&gt;
Database opened.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===RMAN-04004: error from recovery catalog database: ORA-01017: invalid username/password; logon denied===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
oracle@host:/export/home/ora&amp;gt; rman target / catalog catowner/catpass@catdb&lt;br /&gt;
&lt;br /&gt;
Recovery Manager: Release 11.2.0.2.0 - Production on Thu Jun 12 16:51:03 2014&lt;br /&gt;
&lt;br /&gt;
Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.&lt;br /&gt;
&lt;br /&gt;
connected to target database: XXXXRAP1 (DBID=3557010742)&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-00554: initialization of internal recovery manager package failed&lt;br /&gt;
RMAN-04004: error from recovery catalog database: ORA-01017: invalid username/password; logon denied&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This is normally very straight-forward and self-explanatory.&amp;lt;br /&amp;gt;&lt;br /&gt;
The puzzle here is that a connection from SQL*Plus works!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sqlplus catowner/catpass@catdb&lt;br /&gt;
&lt;br /&gt;
SQL*Plus: Release 11.2.0.2.0 Production on Thu Jun 12 16:53:18 2014&lt;br /&gt;
&lt;br /&gt;
Copyright (c) 1982, 2010, Oracle.  All rights reserved.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Connected to:&lt;br /&gt;
Oracle Database 12c Enterprise Edition Release 12.1.0.1.0 - 64bit Production&lt;br /&gt;
With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options&lt;br /&gt;
SQL&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Eventually worked out that the rman binary in the databases ORACLE_HOME on the source machine needed relinking!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cd $ORACLE_HOME/rdbms/lib&lt;br /&gt;
make -f ins_rdbms.mk irman &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORA-00230: operation disallowed: snapshot control file enqueue unavailable===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
waiting for snapshot control file enqueue&lt;br /&gt;
waiting for snapshot control file enqueue&lt;br /&gt;
waiting for snapshot control file enqueue&lt;br /&gt;
waiting for snapshot control file enqueue&lt;br /&gt;
cannot make a snapshot control file&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-03008: error while performing automatic resync of recovery catalog&lt;br /&gt;
ORA-00230: operation disallowed: snapshot control file enqueue unavailable&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
From the doc...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
When RMAN needs to back up or resynchronize from the control file, it first creates a snapshot or consistent image of the control file.&lt;br /&gt;
If one RMAN job is already backing up the control file while another needs to create a new snapshot control file, then you may see the following message:&lt;br /&gt;
&lt;br /&gt;
waiting for snapshot controlfile enqueue&lt;br /&gt;
&lt;br /&gt;
Under normal circumstances, a job that must wait for the control file enqueue waits for a brief interval and then successfully obtains the enqueue.&lt;br /&gt;
RMAN makes up to five attempts to get the enqueue and then fails the job.&lt;br /&gt;
The conflict is usually caused when two jobs are both backing up the control file, and the job that first starts backing up the control file waits for service from the media manager.&lt;br /&gt;
&lt;br /&gt;
To determine which job is holding the conflicting enqueue:&lt;br /&gt;
&lt;br /&gt;
    After you see the first message stating &amp;quot;RMAN-08512: waiting for snapshot controlfile enqueue&amp;quot;, start a new SQL*Plus session on the target database:&lt;br /&gt;
&lt;br /&gt;
    % sqlplus &amp;#039;SYS/oracle@trgt AS SYSDBA&amp;#039;&lt;br /&gt;
&lt;br /&gt;
    Execute the following query to determine which job is causing the wait:&lt;br /&gt;
&lt;br /&gt;
    SELECT s.SID, USERNAME AS &amp;quot;User&amp;quot;, PROGRAM, MODULE, &lt;br /&gt;
           ACTION, LOGON_TIME &amp;quot;Logon&amp;quot;, l.* &lt;br /&gt;
    FROM V$SESSION s, V$ENQUEUE_LOCK l&lt;br /&gt;
    WHERE l.SID = s.SID&lt;br /&gt;
    AND l.TYPE = &amp;#039;CF&amp;#039;&lt;br /&gt;
    AND l.ID1 = 0&lt;br /&gt;
    AND l.ID2 = 2;&lt;br /&gt;
&lt;br /&gt;
    You should see output similar to the following (the output in this example has been truncated):&lt;br /&gt;
&lt;br /&gt;
    SID User Program              Module                    Action           Logon&lt;br /&gt;
    --- ---- -------------------- ------------------------- ---------------- ---------&lt;br /&gt;
      9 SYS  rman@h13 (TNS V1-V3) backup full datafile: c1  0000210 STARTED  21-JUN-01&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
After you have determined which job is creating the enqueue, you can do one of the following:&lt;br /&gt;
&lt;br /&gt;
    Wait until the job creating the enqueue completes&lt;br /&gt;
    Cancel the current job and restart it after the job creating the enqueue completes&lt;br /&gt;
    Cancel the job creating the enqueue&lt;br /&gt;
&lt;br /&gt;
Commonly, enqueue situations occur when a job is writing to a tape drive, but the tape drive is waiting for a new cassette to be inserted.&lt;br /&gt;
If you start a new job in this situation, then you will probably receive the enqueue message because the first job cannot complete until the new tape is loaded.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or more directly...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 2000&lt;br /&gt;
col killer     for a70&lt;br /&gt;
col program    for a20&lt;br /&gt;
col module     for a20&lt;br /&gt;
col action     for a20&lt;br /&gt;
col logon_time for a20&lt;br /&gt;
select &amp;#039;alter system disconnect session &amp;#039;&amp;#039;&amp;#039;||s.sid||&amp;#039;,&amp;#039;||s.serial#||&amp;#039;&amp;#039;&amp;#039; immediate;&amp;#039; killer&lt;br /&gt;
,      username&lt;br /&gt;
,      program&lt;br /&gt;
,      module&lt;br /&gt;
,      action&lt;br /&gt;
,      logon_time&lt;br /&gt;
from   v$session s&lt;br /&gt;
,      v$enqueue_lock l&lt;br /&gt;
where  l.sid  = s.sid&lt;br /&gt;
and    l.type = &amp;#039;cf&amp;#039;&lt;br /&gt;
and    l.id1  = 0&lt;br /&gt;
and    l.id2  = 2&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORA-19511: non RMAN, but media manager or vendor specific failure, error text:===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-03002: failure of Duplicate Db command at 05/01/2018 14:23:09&lt;br /&gt;
RMAN-05501: aborting duplication of target database&lt;br /&gt;
RMAN-03015: error occurred in stored script Memory Script&lt;br /&gt;
ORA-27191: sbtinfo2 returned error&lt;br /&gt;
Additional information: 3586&lt;br /&gt;
ORA-19511: non RMAN, but media manager or vendor specific failure, error text:&lt;br /&gt;
   Unable to connect to NetWorker server &amp;#039;hn6000.cln.be&amp;#039; because &amp;#039;Authentication error; why = Invalid client credential&amp;#039;. (2:10:79)&lt;br /&gt;
&lt;br /&gt;
Recovery Manager complete.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
If this happens, check to see if the nsr daemon is running...&amp;lt;br /&amp;gt;&lt;br /&gt;
Good system:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/home/oracle&amp;gt; ps -ef | grep nsr&lt;br /&gt;
    root  5701836        1   0   Mar 16      - 13:18 /bin/nsrexecd&lt;br /&gt;
  oracle 18809292 22741502   0 15:03:58  pts/0  0:00 grep nsr&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Bad system:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 /home/oracle&amp;gt; ps -ef | grep nsr&lt;br /&gt;
  oracle 14745986 15139292   0 15:03:29  pts/2  0:00 grep nsr&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORA-19554: error allocating device, device type: SBT_TAPE, device name:===&lt;br /&gt;
If using Cygwin...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-03002: failure of backup command at 05/19/2015 12:25:47&lt;br /&gt;
ORA-19554: error allocating device, device type: SBT_TAPE, device name:&lt;br /&gt;
ORA-27000: skgfqsbi: failed to initialize storage subsystem (SBT) layer&lt;br /&gt;
OSD-02534: Message 2534 not found;  product=RDBMS; facility=SOSD&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Check the tdpo.opt file is where you think it is!&lt;br /&gt;
* Check the path to the opt file looks like this (needs to be Windows format):&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
CONFIGURE CHANNEL DEVICE TYPE &amp;#039;SBT_TAPE&amp;#039; FORMAT   &amp;#039;LOG_%d_t%t_s%s_u%U&amp;#039; PARMS  &amp;#039;ENV=(TDPO_OPTFILE=E:\oracle\KITRYD\admin\tdpo.opt)&amp;#039;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Check the content of the opt file is Windows format paths!&lt;br /&gt;
&lt;br /&gt;
===RMAN-20033: control file SEQUENCE# too low===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-03008: error while performing automatic resync of recovery catalog&lt;br /&gt;
===RMAN-20033: control file SEQUENCE# too low===&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
From [https://forums.oracle.com/forums/thread.jspa?threadID=1115969 forums.oracle.com]&amp;lt;br /&amp;gt;&lt;br /&gt;
This error generally happens if an archivelog backup happens while the RMAN database backup is running and if controlfile autobackup is configured.&amp;lt;br /&amp;gt;&lt;br /&gt;
The database backup is usually successful and it is just the controlfile backup that fails.&lt;br /&gt;
===ORA-27302: failure occurred at: slgpn===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
RMAN-03009: failure of Control File and SPFILE Autobackup command on c1 channel at 06/28/2011 18:59:38&lt;br /&gt;
ORA-19715: invalid format %b for generated name&lt;br /&gt;
ORA-27302: failure occurred at: slgpn&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Problem====&lt;br /&gt;
When doing a &amp;quot;&amp;lt;tt&amp;gt;backup as copy database&amp;lt;/tt&amp;gt;&amp;quot;, got these errors after 145 of 147 datafiles had been backed up!&lt;br /&gt;
&lt;br /&gt;
====Investigation====&lt;br /&gt;
I had read [https://oracleedge.wordpress.com/2011/06/29/oracle-rman-03009-ora-19715-ora-27302/ elsewhere] that this could be something to do with the format of the autobackup of the control file so I changed the format as suggested and reran the backup.&amp;lt;br /&amp;gt;&lt;br /&gt;
No luck. It ended exactly the same way after 145 files. I decided to compare the original list of datafiles with those that had been backed up in order to track down the 2 failures. Maybe I could see something odd with them.&amp;lt;br /&amp;gt;&lt;br /&gt;
Sure enough, these 2 files were different... there was a space at the &amp;#039;&amp;#039;&amp;#039;end&amp;#039;&amp;#039;&amp;#039; of the filenames :-)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select &amp;#039;x&amp;#039;||file_name||&amp;#039;x&amp;#039;&lt;br /&gt;
from   dba_data_files&lt;br /&gt;
where  file_name like &amp;#039;% %&amp;#039;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Solution====&lt;br /&gt;
Run the backup of the other 2 datafiles with a different format that did not rely on the filename.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
run {&lt;br /&gt;
    allocate channel c1 device type disk format &amp;#039;/path/to/datafiles/%U&amp;#039;;&lt;br /&gt;
    backup as copy datafile 170;&lt;br /&gt;
    backup as copy datafile 171;&lt;br /&gt;
    backup as copy current controlfile;&lt;br /&gt;
    release channel c1;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The other 145 datafiles were backed up with a format of &amp;#039;/path/to/datafiles/%b&amp;#039; which preserves the filenames so all that needs to be done is rename the other 2 after the backup finishes.&amp;lt;br /&amp;gt;&lt;br /&gt;
If they are going to be used in a restore scenario, they should be renamed in the controlfile also.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter database rename file &amp;#039;/path/to/datafiles/filename_with_a_space_at_end &amp;#039; to &amp;#039;/path/to/datafiles/filename_without_a_space&amp;#039;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===RMAN errors after crosscheck backup and delete noprompt obsolete and delete noprompt expired backup===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
RMAN-06207: WARNING: 3921 objects could not be deleted for SBT_TAPE channel(s) due&lt;br /&gt;
RMAN-06208:          to mismatched status.  Use CROSSCHECK command to fix status&lt;br /&gt;
RMAN-06210: List of Mismatched objects&lt;br /&gt;
RMAN-06211: ==========================&lt;br /&gt;
RMAN-06212:   Object Type   Filename/Handle&lt;br /&gt;
RMAN-06213: --------------- ---------------------------------------------------&lt;br /&gt;
RMAN-06214: Backup Piece    DB_SID_t20140316_s263889_umhp3bpa7_1_1&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Use the FORCE option with the DELETE command&amp;lt;br /&amp;gt;&lt;br /&gt;
The FORCE command tells RMAN to clean the information out of the catalog regardless of whether it can find it on the media or not.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
delete force noprompt expired backup;&lt;br /&gt;
delete force noprompt obsolete;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===RMAN-06004: ORACLE error from recovery catalog database: RMAN-20003: target database incarnation not found in recovery catalog===&lt;br /&gt;
====Problem:====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-03002: failure of Duplicate Db command at 12/05/2017 11:11:15&lt;br /&gt;
RMAN-05501: aborting duplication of target database&lt;br /&gt;
RMAN-03015: error occurred in stored script Memory Script&lt;br /&gt;
RMAN-06004: ORACLE error from recovery catalog database: RMAN-20003: target database incarnation not found in recovery catalog&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Solution:====&lt;br /&gt;
Strangely, this means, in my particular case, that block change tracking is turned on in the target databse and needs turning off in the auxiliary while the DUPLICATE is running.&amp;lt;br /&amp;gt;&lt;br /&gt;
It must be done while the auxiliary is in mount mode and restoring the datafiles (before recovery starts)&amp;lt;br /&amp;gt;&lt;br /&gt;
It is reported to be a bug fixed in 11.1 but somehow, we&amp;#039;re still (sometimes) getting it in 12.1.0.2.&lt;br /&gt;
&lt;br /&gt;
===RMAN-06059: expected archived log not found, loss of archived log compromises recoverability===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
RMAN-06059: expected archived log not found, loss of archived log compromises recoverability&lt;br /&gt;
ORA-19625: error identifying file &amp;lt;filename&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This error can come from the fact that the database files (more likely archivelogs) are being deleted by the operating system so RMAN has no clue of their whereabouts.&amp;lt;br /&amp;gt;&lt;br /&gt;
Possibly result of a database duplication and the catalog has not updated properly?&amp;lt;br /&amp;gt;&lt;br /&gt;
====Solution====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
crosscheck archivelog all;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
And then maybe take a backup to be on the safe side.&lt;br /&gt;
&lt;br /&gt;
===RMAN-05537: DUPLICATE without TARGET connection when auxiliary instance is started with spfile cannot use SPFILE clause===&lt;br /&gt;
====Problem:====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-03002: failure of Duplicate Db command at 12/05/2017 14:17:49&lt;br /&gt;
RMAN-05501: aborting duplication of target database&lt;br /&gt;
RMAN-05537: DUPLICATE without TARGET connection when auxiliary instance is started with spfile cannot use SPFILE clause&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Usually happens after restarting a failed RMAN DUPLICATE database. The spfile has been regenerated on the auxiliary to a level where it has too much detail in it.&lt;br /&gt;
====Solution:====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ cd $ORACLE_HOME/dbs&lt;br /&gt;
$ ls -altr *dwh_perf*&lt;br /&gt;
-rw-r-----    1 oracle   oinstall   17645568 Aug  3 13:34 snapcf_dwh_perf.f&lt;br /&gt;
-rw-r-----    1 oracle   oinstall       7680 Nov  4 09:22 orapwdwh_perf&lt;br /&gt;
-rw-r--r--    1 oracle   oinstall        104 Dec  5 09:34 initdwh_perf.ora&lt;br /&gt;
-rw-r-----    1 oracle   oinstall       6656 Dec  5 11:11 spfiledwh_perf.ora&lt;br /&gt;
-rw-rw----    1 oracle   oinstall       1544 Dec  5 14:18 hc_dwh_perf.dat&lt;br /&gt;
$ mv hc_dwh_perf.dat hc_dwh_perf.dat.old&lt;br /&gt;
$ mv spfiledwh_perf.ora spfiledwh_perf.ora.old&lt;br /&gt;
$ cat initdwh_perf.ora&lt;br /&gt;
sga_max_size=&amp;#039;6G&amp;#039;&lt;br /&gt;
sga_target=&amp;#039;6G&amp;#039;&lt;br /&gt;
compatible=&amp;#039;12.0.0&amp;#039;&lt;br /&gt;
db_files=&amp;#039;500&amp;#039;&lt;br /&gt;
&lt;br /&gt;
# Instance name&lt;br /&gt;
db_name=dwh_perf&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Re-run the DUPLICATE. It should zoom past the already recovered datafiles.&lt;br /&gt;
&lt;br /&gt;
===PSDRPC returns significant error 1013===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
archived log thread=1 sequence=195008&lt;br /&gt;
channel t2: reading from backup piece arclog_LBK_4260753020_946042770_479194_1&lt;br /&gt;
channel t0: piece handle=arclog_LBK_4260753020_946042770_479192_1 tag=TAG20170607T133757&lt;br /&gt;
channel t0: restored backup piece 1&lt;br /&gt;
channel t0: restore complete, elapsed time: 00:00:35&lt;br /&gt;
archived log file name=/xxxxxx/acc/ora_bin2/app/oracle/product/11.2.0.4/dbhome_1/dbs/arch1_195006_815790039.dbf thread=1 sequence=195006&lt;br /&gt;
PSDRPC returns significant error 1013.&lt;br /&gt;
PSDRPC returns significant error 1013.&lt;br /&gt;
released channel: t0&lt;br /&gt;
released channel: t1&lt;br /&gt;
released channel: t2&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-03002: failure of Duplicate Db command at 06/09/2017 15:15:04&lt;br /&gt;
RMAN-05501: aborting duplication of target database&lt;br /&gt;
RMAN-03015: error occurred in stored script Memory Script&lt;br /&gt;
RMAN-11003: failure during parse/execution of SQL statement: alter database recover logfile &amp;#039;/xxxxxx/acc/ora_bin2/app/oracle/product/11.2.0.4/dbhome_1/dbs/arch1_195006_815790039.dbf&amp;#039;&lt;br /&gt;
ORA-10877: error signaled in parallel recovery slave&lt;br /&gt;
&lt;br /&gt;
Recovery Manager complete.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Action====&lt;br /&gt;
Check the alert log on the auxiliary instance.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ORA-279 signalled during: alter database recover logfile &amp;#039;/xxxxxx/acc/ora_bin2/app/oracle/product/11.2.0.4/dbhome_1/dbs/arch1_195005_815790039.dbf&amp;#039;...&lt;br /&gt;
alter database recover logfile &amp;#039;/xxxxxx/acc/ora_bin2/app/oracle/product/11.2.0.4/dbhome_1/dbs/arch1_195006_815790039.dbf&amp;#039;&lt;br /&gt;
Media Recovery Log /xxxxxx/acc/ora_bin2/app/oracle/product/11.2.0.4/dbhome_1/dbs/arch1_195006_815790039.dbf&lt;br /&gt;
Fri Jun 09 07:30:30 2017&lt;br /&gt;
Errors with log /xxxxxx/acc/ora_bin2/app/oracle/product/11.2.0.4/dbhome_1/dbs/arch1_195006_815790039.dbf&lt;br /&gt;
Recovery interrupted!&lt;br /&gt;
Recovered data files to a consistent state at change 238029030495&lt;br /&gt;
Media Recovery failed with error 19755&lt;br /&gt;
Errors in file /xxxxxx/acc/ora_bin2/app/oracle/diag/rdbms/lbkro/lbkro/trace/lbkro_pr00_13108374.trc:&lt;br /&gt;
ORA-00283: recovery session canceled due to errors&lt;br /&gt;
===&amp;gt;ORA-19755: could not open change tracking file&lt;br /&gt;
===&amp;gt;ORA-19750: change tracking file: &amp;#039;/xxxxxx/exp/ora_data2/lbk/data/bct_lbk_do_not_delete.f&lt;br /&gt;
===&amp;gt;ORA-27037: unable to obtain file status&lt;br /&gt;
===&amp;gt;IBM AIX RISC System/6000 Error: 2: No such file or directory&lt;br /&gt;
Additional information: 3&lt;br /&gt;
Fri Jun 09 07:30:36 2017&lt;br /&gt;
ORA-10877 signalled during: alter database recover logfile &amp;#039;/xxxxxx/acc/ora_bin2/app/oracle/product/11.2.0.4/dbhome_1/dbs/arch1_195006_815790039.dbf&amp;#039;...&lt;br /&gt;
Fri Jun 09 14:04:57 2017&lt;br /&gt;
alter database recover logfile &amp;#039;/xxxxxx/acc/ora_bin2/app/oracle/product/11.2.0.4/dbhome_1/dbs/arch1_195006_815790039.dbf&amp;#039;&lt;br /&gt;
Media Recovery Log /xxxxxx/acc/ora_bin2/app/oracle/product/11.2.0.4/dbhome_1/dbs/arch1_195006_815790039.dbf&lt;br /&gt;
Media Recovery failed with error 1112&lt;br /&gt;
ORA-283 signalled during: alter database recover logfile &amp;#039;/xxxxxx/acc/ora_bin2/app/oracle/product/11.2.0.4/dbhome_1/dbs/arch1_195006_815790039.dbf&amp;#039;...&lt;br /&gt;
Fri Jun 09 14:31:20 2017&lt;br /&gt;
Shutting down instance (immediate)&lt;br /&gt;
Shutting down instance: further logons disabled&lt;br /&gt;
Stopping background process MMNL&lt;br /&gt;
Stopping background process MMON&lt;br /&gt;
License high water mark = 49&lt;br /&gt;
ALTER DATABASE CLOSE NORMAL&lt;br /&gt;
ORA-1109 signalled during: ALTER DATABASE CLOSE NORMAL...&lt;br /&gt;
ALTER DATABASE DISMOUNT&lt;br /&gt;
Shutting down archive processes&lt;br /&gt;
Archiving is disabled&lt;br /&gt;
Completed: ALTER DATABASE DISMOUNT&lt;br /&gt;
ARCH: Archival disabled due to shutdown: 1089&lt;br /&gt;
Shutting down archive processes&lt;br /&gt;
Archiving is disabled&lt;br /&gt;
ARCH: Archival disabled due to shutdown: 1089&lt;br /&gt;
Shutting down archive processes&lt;br /&gt;
Archiving is disabled&lt;br /&gt;
Fri Jun 09 14:31:24 2017&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This is a known bug. it is fixed in 11.2.0.3 but... this customer does not apply patches!&lt;br /&gt;
&lt;br /&gt;
====Solution====&lt;br /&gt;
While the DUPLICATE is running (and in MOUNT mode), log on to the auxiliary instance and disable block change tracking.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter database disable block change tracking;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
A documented workaround is to set db_filename_convert parameter in the DUPLICATE clause of the run block but I tried this and it failed again.&amp;lt;br /&amp;gt;&lt;br /&gt;
The obvious solution is to patch the database but...&lt;br /&gt;
&lt;br /&gt;
===Database trigger to capture ORA errors===&lt;br /&gt;
From [http://ora-ssn.blogspot.be/2011/10/trigger-on-database-to-capture-ora.html ora-ssn.blogspot.be]&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
CREATE TABLE stats$error_log (&lt;br /&gt;
        err_dt          TIMESTAMP,&lt;br /&gt;
        db_user         VARCHAR2(30),&lt;br /&gt;
        msg_stack       VARCHAR2(2000),&lt;br /&gt;
        sqltxt          VARCHAR2(1000))&lt;br /&gt;
tablespace users;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Now, create a trigger on the database server.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
CREATE OR REPLACE TRIGGER log_server_errors&lt;br /&gt;
  AFTER SERVERERROR&lt;br /&gt;
  ON DATABASE&lt;br /&gt;
DECLARE&lt;br /&gt;
          v_sqltext VARCHAR2(1000);&lt;br /&gt;
          nl_sqltext ora_name_list_t;&lt;br /&gt;
  BEGIN&lt;br /&gt;
          -- Capture entire error text&lt;br /&gt;
          FOR i IN 1 .. ora_sql_txt(nl_sqltext) LOOP&lt;br /&gt;
            v_sqltext := v_sqltext || nl_sqltext(i);&lt;br /&gt;
          END LOOP;&lt;br /&gt;
          INSERT INTO STATS$ERROR_LOG&lt;br /&gt;
          (err_dt, db_user, msg_stack, sqltxt)&lt;br /&gt;
          VALUES&lt;br /&gt;
          (systimestamp,&lt;br /&gt;
           sys.login_user,&lt;br /&gt;
           dbms_utility.format_error_stack, v_sqltext);&lt;br /&gt;
  END log_server_errors;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORA-19809: limit exceeded for recovery files===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-03009: failure of backup command on ORA_DISK_1 channel at 07/15/2013 10:10:59&lt;br /&gt;
ORA-19809: limit exceeded for recovery files&lt;br /&gt;
ORA-19804: cannot reclaim 274716160 bytes disk space from 1468006400 limit&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    ORA-19809: limit exceeded for recovery files&lt;br /&gt;
    Cause: The limit for recovery files specified by the db_recovery_file_dest_size was exceeded.&lt;br /&gt;
&lt;br /&gt;
    Action: The error is accompanied by 19804. See message 19804 for further details&lt;br /&gt;
&lt;br /&gt;
    ORA-19804: cannot reclaim string bytes disk space from string limit&lt;br /&gt;
    Cause: Oracle cannot reclaim disk space of specified bytes from the DB_RECOVERY_FILE_DEST_SIZE limit.&lt;br /&gt;
&lt;br /&gt;
    Action: There are five possible solutions:&lt;br /&gt;
       1) Take frequent backup of recovery area using RMAN.&lt;br /&gt;
       2) Consider changing RMAN retention policy.&lt;br /&gt;
       3) Consider changing RMAN archivelog deletion policy.&lt;br /&gt;
       4) Add disk space and increase DB_RECOVERY_FILE_DEST_SIZE.&lt;br /&gt;
       5) Delete files from recovery area using RMAN.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The solution here is to increase the value of db_recovery_file_dest_size but it might also indicate a problem with tapes if the archivelogs are being backed up to tape via tdpo.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SYS@DN7&amp;gt; alter system set db_recovery_file_dest_size=4000M scope=both;&lt;br /&gt;
&lt;br /&gt;
System altered.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Looking into int further, saw RMAN parameters missing...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
CONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF 14 DAYS;&lt;br /&gt;
CONFIGURE BACKUP OPTIMIZATION OFF;&lt;br /&gt;
CONFIGURE DEFAULT DEVICE TYPE TO &amp;#039;SBT_TAPE&amp;#039;;&lt;br /&gt;
CONFIGURE CONTROLFILE AUTOBACKUP ON;&lt;br /&gt;
CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE &amp;#039;SBT_TAPE&amp;#039; TO &amp;#039;LOG_%d_controlfile_%F.rman&amp;#039;;&lt;br /&gt;
CONFIGURE DEVICE TYPE &amp;#039;SBT_TAPE&amp;#039; PARALLELISM 1 BACKUP TYPE TO BACKUPSET;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===RMAN-00554: initialization of internal recovery manager package failed===&lt;br /&gt;
Getting this error after migrating a database from one machine to another and attaching to a nice new version 12c catalog on the new server&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Recovery Manager: Release 11.2.0.2.0 - Production on Sat Jun 21 13:16:24 2014&lt;br /&gt;
&lt;br /&gt;
Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.&lt;br /&gt;
&lt;br /&gt;
connected to target database: SPMSUPP1 (DBID=3026014394)&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-00554: initialization of internal recovery manager package failed&lt;br /&gt;
RMAN-04004: error from recovery catalog database: ORA-01017: invalid username/password; logon denied&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
We cannot connect to the catalog via rman but there is no problem if connecting via SQL*Plus!&amp;lt;br /&amp;gt;&lt;br /&gt;
Solution: relink the rman executable.&lt;br /&gt;
===Using AIX commands genld, genkld and slibclean to avoid library file locking errors (libjox) (Doc ID 739963.1)===&lt;br /&gt;
* [https://support.oracle.com/epmos/faces/DocumentDisplay?_afrLoop=206851390914720&amp;amp;id=739963.1&amp;amp;_afrWindowMode=0&amp;amp;_adf.ctrl-state=e0pq23tou_4 Metalink]&lt;br /&gt;
When installing interim (one-off) patches, CPU patches or patchsets, you may encounter some errors with regards to files being locked or oui/opatch being unable to copy files&amp;lt;br /&amp;gt;&lt;br /&gt;
even though the databases, listeners and all other Oracle processes associated with the ORACLE_HOME to be patched were stopped.&amp;lt;br /&amp;gt;&lt;br /&gt;
This could be as result of a process which requires termination or an additional file needing to be unloaded from the system cache.&amp;lt;br /&amp;gt;&lt;br /&gt;
Run following commands to clean up...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
genld -l | grep &amp;lt;ORACLE_HOME&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
If genld returns data then a currently executing process has something open in the ORACLE_HOME directory, therefore terminate the process as required/recommended.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
genkld | grep &amp;lt;ORACLE_HOME&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
If the genkld command  returns a  list of shared objects currently loaded onto the OS system cache then please remove the entries from the OS system cache by running the slibclean command as root user:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/usr/sbin/slibclean&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===ORA-20011: Approximate NDV failed: ORA-29913: error in executing ODCIEXTTABLEOPEN callout===&lt;br /&gt;
This seems to be related to orphaned Datapump tables. Generally seems to be a problem when stats jobs are running during the night (dbms_stats)&amp;lt;br /&amp;gt;&lt;br /&gt;
* Check no datapump jobs are running&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select * from dba_datapump_jobs;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Find orphaned tables&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 2000&lt;br /&gt;
select owner&lt;br /&gt;
,      object_name&lt;br /&gt;
,      object_type&lt;br /&gt;
,      status&lt;br /&gt;
,      to_char(created,&amp;#039;dd-mon-yyyy hh24:mi:ss&amp;#039;) created&lt;br /&gt;
,      to_char(last_ddl_time,&amp;#039;dd-mon-yyyy hh24:mi:ss&amp;#039;) last_ddl_time&lt;br /&gt;
from   dba_objects&lt;br /&gt;
where  1=1&lt;br /&gt;
and    object_name like &amp;#039;ET$%&amp;#039;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Check that  any rows seen are actually external tables&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select owner&lt;br /&gt;
,      table_name&lt;br /&gt;
,      default_directory_name&lt;br /&gt;
,      access_type&lt;br /&gt;
from   dba_external_tables&lt;br /&gt;
order  by 1,2&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Drop the tables if they are not currently being used (no datapump jobs running)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
drop table &amp;amp;&amp;amp;owner..&amp;amp;table_name;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===ORA-01547: warning: RECOVER succeeded but OPEN RESETLOGS would get error below===&lt;br /&gt;
Database is restored and now we want to recover it but we see this...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Starting recover at 24-JUL-15 11:26:19&lt;br /&gt;
&lt;br /&gt;
starting media recovery&lt;br /&gt;
&lt;br /&gt;
unable to find archive log&lt;br /&gt;
archive log thread=1 sequence=69763&lt;br /&gt;
Oracle Error: &lt;br /&gt;
ORA-01547: warning: RECOVER succeeded but OPEN RESETLOGS would get error below&lt;br /&gt;
ORA-01194: file 1 needs more recovery to be consistent&lt;br /&gt;
ORA-01110: data file 1: &amp;#039;/oracle/TRSCRP1/oradata2/system01.dbf&amp;#039;&lt;br /&gt;
&lt;br /&gt;
released channel: c1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This means that although we have restored the database, we are still missing information to complete the recovery. This information is contained in the archived redo logs which must also be restored (from tape if they are no longer on disk)&amp;lt;br /&amp;gt;&lt;br /&gt;
We can see here that we need an archive log with sequence number 69763. But what is the file called and where should it be restored to?&amp;lt;br /&amp;gt;&lt;br /&gt;
For this we can go to SQL*Plus and get the database to tell us&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
recover database using backup controlfile until cancel;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
and cancel straight away.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ORA-00279: change 13796376414661 generated at 07/14/2015 13:20:07 needed for&lt;br /&gt;
thread 1&lt;br /&gt;
ORA-00289: suggestion : /oracle/TRSCRP1/archive/arch_TRSCRP1_1_69763.arc&lt;br /&gt;
ORA-00280: change 13796376414661 for thread 1 is in sequence #69763&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Specify log: {&amp;lt;RET&amp;gt;=suggested | filename | AUTO | CANCEL}&lt;br /&gt;
cancel&lt;br /&gt;
ORA-01547: warning: RECOVER succeeded but OPEN RESETLOGS would get error below&lt;br /&gt;
ORA-01194: file 1 needs more recovery to be consistent&lt;br /&gt;
ORA-01110: data file 1: &amp;#039;/oracle/TRSCRP1/oradata2/system01.dbf&amp;#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
ORA-01112: media recovery not started&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Now we see that we need to find a file called arch_TRSCRP1_1_69763.arc and put it in the directory /oracle/TRSCRP1/archive.&amp;lt;br /&amp;gt;&lt;br /&gt;
This will continue up until the time specified for the recover so restore a whole bunch of them.&amp;lt;br /&amp;gt;&lt;br /&gt;
Repeat the &amp;quot;recover database using backup controlfile until cancel;&amp;quot; command and type AUTO or Enter until you&amp;#039;ve got to where you need to be.&amp;lt;br /&amp;gt;&lt;br /&gt;
Type CANCEL when point is reached and&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter database open resetlogs;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Stuart</name></author>	</entry>

	<entry>
		<id>https://mailnest.com/dbawiki/index.php?title=Oracle_errors&amp;diff=3354</id>
		<title>Oracle errors</title>
		<link rel="alternate" type="text/html" href="https://mailnest.com/dbawiki/index.php?title=Oracle_errors&amp;diff=3354"/>
				<updated>2018-11-03T13:17:05Z</updated>
		
		<summary type="html">&lt;p&gt;Stuart: /* Solution */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;===ORA-00600===&lt;br /&gt;
[https://support.oracle.com/epmos/faces/DocContentDisplay?_afrLoop=397490397952859&amp;amp;id=1092832.1&amp;amp;_afrWindowMode=0&amp;amp;_adf.ctrl-state=184vwc6g3y_4 Master Note for Diagnosing ORA-600 (Doc ID 1092832.1)]&lt;br /&gt;
===ORA-19051: Cannot use fast path insert for this XMLType table===&lt;br /&gt;
Think LD_LIBRARY_PATH on Linux or LIBPATH on AIX.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Export: Release 11.2.0.4.0 - Production on Thu Jun 1 06:41:55 2017&lt;br /&gt;
&lt;br /&gt;
Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.&lt;br /&gt;
&lt;br /&gt;
Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production&lt;br /&gt;
With the Partitioning, OLAP, Data Mining and Real Application Testing options&lt;br /&gt;
Starting &amp;quot;DWH_EXPORT&amp;quot;.&amp;quot;SYS_EXPORT_TABLE_03&amp;quot;:  dwh_export/******** parfile=cadis_foto_export_credit_dba.par&lt;br /&gt;
Estimate in progress using BLOCKS method...&lt;br /&gt;
Processing object type TABLE_EXPORT/TABLE/TABLE_DATA&lt;br /&gt;
Total estimation using BLOCKS method: 64.08 GB&lt;br /&gt;
ORA-39126: Worker unexpected fatal error in KUPW$WORKER.FETCH_XML_OBJECTS []&lt;br /&gt;
ORA-19051: Cannot use fast path insert for this XMLType table&lt;br /&gt;
&lt;br /&gt;
ORA-06512: at &amp;quot;SYS.DBMS_SYS_ERROR&amp;quot;, line 86&lt;br /&gt;
ORA-06512: at &amp;quot;SYS.KUPW$WORKER&amp;quot;, line 9710&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Problem====&lt;br /&gt;
When the 11g DB was started, LD_LIBRARY_PATH and LIBPATH were still pointing to paths in the 10g Home.&lt;br /&gt;
====Solution====&lt;br /&gt;
There may have been some odd values setup in LD_LIBRARY_PATH before the call to oraenv (if oraenv was indeed called!)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
unset LD_LIBRARY_PATH LIBPATH&lt;br /&gt;
export ORACLE_SID=&amp;lt;correct 11g SID&amp;gt;&lt;br /&gt;
. oraenv&lt;br /&gt;
echo $LD_LIBRARY_PATH&lt;br /&gt;
echo $LIBPATH&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
They should now be correct.&lt;br /&gt;
&lt;br /&gt;
===ORA-27092: size of file exceeds file size limit of the process===&lt;br /&gt;
Think ulimit...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Cause: an attempt was made to open a file that exceeds the process&amp;#039;s file size limit (ulimit), additional information shows the current limit (logical blocks) and the size of the file (logical blocks)&lt;br /&gt;
Action: increase the processes file size limit (ulimit) and retry&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
truncate table pibadm.test_ph&lt;br /&gt;
                      *&lt;br /&gt;
Error at line 1 :&lt;br /&gt;
ORA-00604: error ocurred at recursive SQL level 1&lt;br /&gt;
ORA-01116: error in opening database file 2&lt;br /&gt;
ORA-01110: datafile 2 : &amp;#039;/opt/u01/data/PIBQA/UNDO_01.dbf&amp;#039;&lt;br /&gt;
ORA-27092: size of file exceeds file size limit of the process&lt;br /&gt;
Additional information: 262143&lt;br /&gt;
Additional information: 2621441&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Check the fs_size limit for this user in /etc/security/limits&amp;lt;br /&amp;gt;&lt;br /&gt;
Compare this with another user, say oracle. Probably -1 (unlimited)&lt;br /&gt;
&lt;br /&gt;
===SP2-1503: Unable to initialize Oracle call interface===&lt;br /&gt;
When trying to login to the database via SQL*Plus, these messages a displayed&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
hn5118 /home/oracle $sqlplus / as sysdba&lt;br /&gt;
SP2-1503: Unable to initialize Oracle call interface&lt;br /&gt;
SP2-0152: ORACLE may not be functioning properly&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Seems to be a problem unique to AIX (in this case).&amp;lt;br /&amp;gt;&lt;br /&gt;
Check to see what the LIBPATH variable is. It may still contain a path to an old ORACLE_HOME...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
hn5118 /home/oracle $env|grep LIBPATH&lt;br /&gt;
LIBPATH=/oracle/exp/ora_bin1/app/oracle/product/10.2.0/db_1/lib:/oracle/exp/ora_bin1/app/oracle/product/10.2.0/db_1/lib&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Disco! Unset it and rerun.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
hn5118 /home/oracle $unset LIBPATH&lt;br /&gt;
&lt;br /&gt;
hn5118 /home/oracle $sqlplus / as sysdba&lt;br /&gt;
&lt;br /&gt;
SQL*Plus: Release 12.1.0.2.0 Production on Wed Jul 12 17:17:54 2017&lt;br /&gt;
&lt;br /&gt;
Copyright (c) 1982, 2014, Oracle.  All rights reserved.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Connected to:&lt;br /&gt;
Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production&lt;br /&gt;
With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options&lt;br /&gt;
&lt;br /&gt;
SQL&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===UDE-31623: operation generated ORACLE error 31623===&lt;br /&gt;
When using Data pump, get following errors almost immediately:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
UDE-31623: operation generated ORACLE error 31623&lt;br /&gt;
ORA-31623: a job is not attached to this session via the specified handle&lt;br /&gt;
ORA-06512: at &amp;quot;SYS.DBMS_DATAPUMP&amp;quot;, line 3326&lt;br /&gt;
ORA-06512: at &amp;quot;SYS.DBMS_DATAPUMP&amp;quot;, line 4551&lt;br /&gt;
ORA-06512: at line 1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Solution 1:&amp;#039;&amp;#039;&amp;#039;&amp;lt;br /&amp;gt;&lt;br /&gt;
In one case, I simplified the parameter file that was used. Maybe related to Streams Pool size, who knows?!&amp;lt;br /&amp;gt;&lt;br /&gt;
I removed these 2 lines and the export started working:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
compression_algorithm=medium&lt;br /&gt;
logtime=all&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Solution 2:&amp;#039;&amp;#039;&amp;#039;&amp;lt;br /&amp;gt;&lt;br /&gt;
There is a note about this on Metalink, 1080775.1 which suggests that Streams Pool Size needs setting.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
For this DataPump error, you will need to configure the database with some Streams Pool.&lt;br /&gt;
&lt;br /&gt;
Perform the following query to find out how much STREAMS_POOL_SIZE has been allocated&lt;br /&gt;
&lt;br /&gt;
 select * from v$sgainfo;&lt;br /&gt;
 ...&lt;br /&gt;
 Streams Pool Size                               0 Yes&lt;br /&gt;
&lt;br /&gt;
Data Pump now uses Advanced Queuing (AQ) internally, so it can handle job stops/starts/re-starts.  However, AQ using the Streams Pool, where the database currently has the STREAMS_POOL_SIZE set to ZERO.&lt;br /&gt;
&lt;br /&gt;
Manually set the STREAMS_POOL_SIZE (using ALTER SYSTEM or by changing the value in the the PFILE/SPFILE), re-start the database and re-attempt the Data Pump Export.&lt;br /&gt;
&lt;br /&gt;
Alternately, turn on Automatic Shared Memory management (ASMM) by setting SGA_TARGET or MEMORY_TARGET.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
From Oracle Documentation&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Setting the Size Of the Buffer Cache In a Streams Environment&lt;br /&gt;
&lt;br /&gt;
Oracle Data Pump uses Streams functionality to communicate between processes.&lt;br /&gt;
If the SGA_TARGET initialization parameter is set, then the STREAMS_POOL_SIZE initialization parameter is automatically set to a reasonable value.&lt;br /&gt;
If the SGA_TARGET initialization parameter is not set and the STREAMS_POOL_SIZE initialization parameter is not defined,&lt;br /&gt;
then the size of the streams pool automatically defaults to 10% of the size of the shared pool.&lt;br /&gt;
&lt;br /&gt;
When the streams pool is created, the required SGA memory is taken from memory allocated to the buffer cache,&lt;br /&gt;
reducing the size of the cache to less than what was specified by the DB_CACHE_SIZE initialization parameter.&lt;br /&gt;
This means that if the buffer cache was configured with only the minimal required SGA, then Data Pump operations may not work properly.&lt;br /&gt;
A minimum size of 10M is recommended for STREAMS_POOL_SIZE in order to ensure successful Data Pump operations.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORA-00020: maximum number of processes (150) exceeded===&lt;br /&gt;
Check the current resource limits with:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 300&lt;br /&gt;
select * from v$resource_limit;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Unfortunately this limit cannot be increased without a restart.&amp;lt;br /&amp;gt;&lt;br /&gt;
It may be a necessary to increase the limit with&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter system set processes=500 scope=spfile;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
followed by a shutdown/startup&amp;lt;br /&amp;gt;&lt;br /&gt;
Or it may be some user is running away with the limit.&amp;lt;br /&amp;gt;&lt;br /&gt;
Check to see who is running what with:&lt;br /&gt;
[[http://www.mailnest.com/dbawiki/index.php/Handy_scripts#See_what_statements_all_users_are_running See_what_statements_all_users_are_running]]&lt;br /&gt;
===ORA-01555: snapshot too old: rollback segment number nn with name &amp;quot;xxx&amp;quot; too small===&lt;br /&gt;
* [http://dfitzjarrell.wordpress.com/2008/02/22/the-dreaded-ora-01555/ Good explanation of why it happens]&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
====Problem====&lt;br /&gt;
A long running transaction has run out of space to store its read-consistent image&lt;br /&gt;
&lt;br /&gt;
====Solution 1====&lt;br /&gt;
If it&amp;#039;s a one-off, maybe leave it alone. It may have been a user leaving a session open overnight without committing or rolling back.&lt;br /&gt;
&lt;br /&gt;
====Solution 2====&lt;br /&gt;
Make sure there&amp;#039;s enough space to allow the transaction to finish.&lt;br /&gt;
&lt;br /&gt;
====Things to check====&lt;br /&gt;
How much undo did the biggest transaction take?&lt;br /&gt;
What is the undo retention parameter set to?&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 200&lt;br /&gt;
col name        for a30&lt;br /&gt;
col description for a50&lt;br /&gt;
col value       for a20&lt;br /&gt;
col maxquerylen for 999999&lt;br /&gt;
select p.name&lt;br /&gt;
,      p.description&lt;br /&gt;
,      p.value&lt;br /&gt;
,      max(u.maxquerylen) maxquerylen&lt;br /&gt;
from   v$parameter p&lt;br /&gt;
,      v$undostat  u&lt;br /&gt;
where  1=1&lt;br /&gt;
and    p.name = &amp;#039;undo_retention&amp;#039;&lt;br /&gt;
group  by p.name&lt;br /&gt;
,      p.description&lt;br /&gt;
,      p.value;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Set the retention to about 20% bigger than the maxquerylen.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select &amp;#039;alter system set undo_retention=&amp;#039;||round(1.2*max(maxquerylen))||&amp;#039; scope=both;&amp;#039; &amp;quot;Run this&amp;quot; from v$undostat;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
and set the undo retention guarantee (being aware of the consequences)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select tablespace_name&lt;br /&gt;
,      retention&lt;br /&gt;
from   dba_tablespaces;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter tablespace &amp;amp;undo_ts_name retention guarantee;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Optimise Oracle UNDO Parameters===&lt;br /&gt;
&lt;br /&gt;
The ideal undo_retention would be enough to hold rollback for the longest transaction that happened so far (can&amp;#039;t see into the future)&amp;lt;br /&amp;gt;&lt;br /&gt;
So current undo_retention = current value of undo / (db_block_size * undo blocks per sec)&amp;lt;br /&amp;gt;&lt;br /&gt;
* Undo Blocks per Second&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SELECT MAX(undoblks/((end_time-begin_time)*3600*24)) &amp;quot;UNDO_BLOCKS_PER_SEC&amp;quot;&lt;br /&gt;
FROM   v$undostat;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Optimal Undo Retention&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
col actual for 9999999999.99 heading &amp;quot;ACTUAL UNDO SIZE [MByte]&amp;quot;&lt;br /&gt;
col retent for 9999999999    heading &amp;quot;UNDO RETENTION [Sec]&amp;quot;&lt;br /&gt;
col needed for 9999999999.99 heading &amp;quot;NEEDED UNDO SIZE [Secs]&amp;quot;&lt;br /&gt;
&lt;br /&gt;
SELECT d.undo_size/(1024*1024) actual,&lt;br /&gt;
       to_number(SUBSTR(e.value,1,25)) retent,&lt;br /&gt;
       ROUND((d.undo_size / (to_number(f.value) *&lt;br /&gt;
       g.undo_block_per_sec))) needed&lt;br /&gt;
  FROM (&lt;br /&gt;
       SELECT SUM(a.bytes) undo_size&lt;br /&gt;
          FROM v$datafile a,&lt;br /&gt;
               v$tablespace b,&lt;br /&gt;
               dba_tablespaces c&lt;br /&gt;
         WHERE c.contents = &amp;#039;UNDO&amp;#039;&lt;br /&gt;
           AND c.status = &amp;#039;ONLINE&amp;#039;&lt;br /&gt;
           AND b.name = c.tablespace_name&lt;br /&gt;
           AND a.ts# = b.ts#&lt;br /&gt;
       ) d,&lt;br /&gt;
       v$parameter e,&lt;br /&gt;
       v$parameter f,&lt;br /&gt;
       (&lt;br /&gt;
       SELECT MAX(undoblks/((end_time-begin_time)*3600*24))&lt;br /&gt;
              undo_block_per_sec&lt;br /&gt;
         FROM v$undostat&lt;br /&gt;
       ) g&lt;br /&gt;
WHERE e.name = &amp;#039;undo_retention&amp;#039;&lt;br /&gt;
  AND f.name = &amp;#039;db_block_size&amp;#039;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Calculate Needed UNDO Size for given Database Activity&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
col actual for 9999999999.99 heading &amp;quot;ACTUAL UNDO SIZE [MByte]&amp;quot;&lt;br /&gt;
col retent for 9999999999    heading &amp;quot;UNDO RETENTION [Sec]&amp;quot;&lt;br /&gt;
col needed for 9999999999.99 heading &amp;quot;NEEDED UNDO SIZE [MByte]&amp;quot;&lt;br /&gt;
&lt;br /&gt;
SELECT d.undo_size/(1024*1024) actual&lt;br /&gt;
,      to_number(SUBSTR(e.value,1,25)) retent&lt;br /&gt;
,      (TO_NUMBER(e.value) * TO_NUMBER(f.value) *&lt;br /&gt;
       g.undo_block_per_sec) / (1024*1024)  needed&lt;br /&gt;
  FROM (&lt;br /&gt;
       SELECT SUM(a.bytes) undo_size&lt;br /&gt;
         FROM v$datafile a,&lt;br /&gt;
              v$tablespace b,&lt;br /&gt;
              dba_tablespaces c&lt;br /&gt;
        WHERE c.contents = &amp;#039;UNDO&amp;#039;&lt;br /&gt;
          AND c.status = &amp;#039;ONLINE&amp;#039;&lt;br /&gt;
          AND b.name = c.tablespace_name&lt;br /&gt;
          AND a.ts# = b.ts#&lt;br /&gt;
       ) d,&lt;br /&gt;
      v$parameter e,&lt;br /&gt;
       v$parameter f,&lt;br /&gt;
       (&lt;br /&gt;
       SELECT MAX(undoblks/((end_time-begin_time)*3600*24))&lt;br /&gt;
         undo_block_per_sec&lt;br /&gt;
         FROM v$undostat&lt;br /&gt;
       ) g&lt;br /&gt;
 WHERE e.name = &amp;#039;undo_retention&amp;#039;&lt;br /&gt;
  AND f.name = &amp;#039;db_block_size&amp;#039;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
It might be that the Export still fails with ORA-01555 even though retention seems long enough.&amp;lt;br /&amp;gt;&lt;br /&gt;
Are you running an export with the flashback_time parameter? If so, the undo_retention should be longer than the total export running time!&amp;lt;br /&amp;gt;&lt;br /&gt;
===Check LOB undo retention===&lt;br /&gt;
The retention settings for LOBS is different for the rest of the database.&amp;lt;br /&amp;gt;&lt;br /&gt;
When you change the UNDO_RETENTION parameter, the LOB segment’s retention value is NOT modified.&amp;lt;br /&amp;gt;&lt;br /&gt;
If you query the RETENTION column of the DBA_LOBS view, you will notice the old UNDO_RETENTION value still remains after you have modified the UNDO_RETENTION parameter.&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SQL&amp;gt; show parameter undo_&lt;br /&gt;
&lt;br /&gt;
NAME                                 TYPE        VALUE&lt;br /&gt;
------------------------------------ ----------- ------------------------------&lt;br /&gt;
undo_management                      string      AUTO&lt;br /&gt;
undo_retention                       integer     36000&lt;br /&gt;
undo_tablespace                      string      UNDOTBS1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SQL&amp;gt; desc SITEADMIN.AUDIT_LOG_MESSAGE&lt;br /&gt;
 Name                                      Null?    Type&lt;br /&gt;
 ----------------------------------------- -------- ----------------------------&lt;br /&gt;
 AUDIT_LOG_MESSAGE_ID                      NOT NULL NUMBER&lt;br /&gt;
 AUDIT_LOG_ID                              NOT NULL NUMBER&lt;br /&gt;
 SEQUENCE                                           NUMBER&lt;br /&gt;
 MESSAGE                                            CLOB&lt;br /&gt;
 CREATE_DATE                                        TIMESTAMP(6)&lt;br /&gt;
 COMPONENT_ID                                       VARCHAR2(50 CHAR)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 300&lt;br /&gt;
col column_name for a32&lt;br /&gt;
select table_name,column_name, pctversion,retention from dba_lobs where owner=&amp;#039;&amp;amp;table_owner&amp;#039;;&lt;br /&gt;
&lt;br /&gt;
TABLE_NAME                COLUMN_NAME                    PCTVERSION  RETENTION&lt;br /&gt;
------------------------- ------------------------------ ---------- ----------&lt;br /&gt;
EMAIL_STORE               CONTENT                                 0&lt;br /&gt;
EMAIL_STORE_ATTACHEMENT   ATTACHEMENT                             0&lt;br /&gt;
TRACKING                  ORIGINAL_MESSAGE                                 900&lt;br /&gt;
TRACKING                  MESSAGE                                          900&lt;br /&gt;
TRACKING                  SIEBEL_MESSAGE                                   900&lt;br /&gt;
WISE_WMS_LOG              WISE_WMS_XML                                     900&lt;br /&gt;
ATTACHMENT                ORIGINAL_MESSAGE                                 900&lt;br /&gt;
PLAN_TABLE                OTHER_XML                                        900&lt;br /&gt;
AUDIT_LOG_MESSAGE         MESSAGE                                          900&lt;br /&gt;
EXCEPTIONS                STACK_TRACE                                      900&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
To change the LOB segment’s RETENTION value to match the new UNDO_RETENTION value, do the following:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ALTER TABLE my_table MODIFY LOB (lob_column) (PCTVERSION 20);&lt;br /&gt;
ALTER TABLE my_table MODIFY LOB (lob_column) (RETENTION);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
By momentarily changing the LOB to use PCTVERSION and then back to RETENTION, the new value of UNDO_RETENTION will be used.&amp;lt;br /&amp;gt;&lt;br /&gt;
You need to do this for all LOB segments that you intend to modify.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select &amp;#039;ALTER TABLE &amp;#039;||owner||&amp;#039;.&amp;#039;||table_name||&amp;#039; MODIFY LOB (&amp;#039;||column_name||&amp;#039;) (PCTVERSION 20);&amp;#039; from dba_lobs where owner=&amp;#039;TIBCO&amp;#039;&lt;br /&gt;
&lt;br /&gt;
select &amp;#039;ALTER TABLE &amp;#039;||owner||&amp;#039;.&amp;#039;||table_name||&amp;#039; MODIFY LOB (&amp;#039;||column_name||&amp;#039;) (RETENTION);&amp;#039;     from dba_lobs where owner=&amp;#039;TIBCO&amp;#039;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
There is a table DBA_LOBS that displays information about all the LOB columns in the database, but it doesn&amp;#039;t actually store any LOB data, just metadata. The actual LOB segments in the database have system-generated names that take the form SYS_LOB*identifier*$$.&lt;br /&gt;
For example if you identify a segment named SYS_LOBidentifier$$ that is consuming space, you can find out what column of what table that LOB column maps to using the DBA_LOBS table:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 1000&lt;br /&gt;
col owner       for a20&lt;br /&gt;
col table_name  for a32&lt;br /&gt;
col column_name for a32&lt;br /&gt;
select owner&lt;br /&gt;
,      table_name&lt;br /&gt;
,      column_name&lt;br /&gt;
from   dba_lobs&lt;br /&gt;
where  1=1&lt;br /&gt;
and    segment_name = &amp;#039;SYS_LOB&amp;lt;&amp;lt;identifier&amp;gt;&amp;gt;$$&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====The Undo Advisor PL/SQL Interface====&lt;br /&gt;
You can activate the Undo Advisor by creating an undo advisor task through the advisor framework.&amp;lt;br /&amp;gt;&lt;br /&gt;
The following example creates an undo advisor task to evaluate the undo tablespace. The name of the advisor is &amp;#039;Undo Advisor&amp;#039;.&amp;lt;br /&amp;gt;&lt;br /&gt;
The analysis is based on Automatic Workload Repository snapshots, which you must specify by setting parameters START_SNAPSHOT and END_SNAPSHOT.&amp;lt;br /&amp;gt;&lt;br /&gt;
In the following example, the START_SNAPSHOT is &amp;quot;1&amp;quot; and END_SNAPSHOT is &amp;quot;2&amp;quot;.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
DECLARE&lt;br /&gt;
   tid    NUMBER;&lt;br /&gt;
   tname  VARCHAR2(30);&lt;br /&gt;
   oid    NUMBER;&lt;br /&gt;
BEGIN&lt;br /&gt;
   DBMS_ADVISOR.CREATE_TASK(&amp;#039;Undo Advisor&amp;#039;, tid, tname, &amp;#039;Undo Advisor Task&amp;#039;);&lt;br /&gt;
   DBMS_ADVISOR.CREATE_OBJECT(tname, &amp;#039;UNDO_TBS&amp;#039;, null, null, null, &amp;#039;null&amp;#039;, oid);&lt;br /&gt;
   DBMS_ADVISOR.SET_TASK_PARAMETER(tname, &amp;#039;TARGET_OBJECTS&amp;#039;, oid);&lt;br /&gt;
   DBMS_ADVISOR.SET_TASK_PARAMETER(tname, &amp;#039;START_SNAPSHOT&amp;#039;, 1);&lt;br /&gt;
   DBMS_ADVISOR.SET_TASK_PARAMETER(tname, &amp;#039;END_SNAPSHOT&amp;#039;, 2);&lt;br /&gt;
   DBMS_ADVISOR.SET_TASK_PARAMETER(tname, &amp;#039;INSTANCE&amp;#039;, 1);&lt;br /&gt;
   DBMS_ADVISOR.execute_task(tname);&lt;br /&gt;
        END;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
After you have created the advisor task, you can view the output and recommendations in the Automatic Database Diagnostic Monitor in Enterprise Manager.&amp;lt;br /&amp;gt;&lt;br /&gt;
This information is also available in the DBA_ADVISOR_* data dictionary views (DBA_ADVISOR_TASKS, DBA_ADVISOR_OBJECTS, DBA_ADVISOR_FINDINGS, DBA_ADVISOR_RECOMMENDATIONS, and so on).&lt;br /&gt;
====References====&lt;br /&gt;
* [http://www.akadia.com/services/ora_optimize_undo.html akadia.com]&lt;br /&gt;
* [http://dfitzjarrell.wordpress.com/2008/02/22/the-dreaded-ora-01555/ the dreaded ora-01555]&lt;br /&gt;
* [http://docs.oracle.com/cd/B28359_01/server.111/b28310/undo004.htm#ADMIN11469 docs.oracle.com]&lt;br /&gt;
&lt;br /&gt;
===Error 6 initializing SQL*Plus===&lt;br /&gt;
Using sqlplus or rman under Cygwin, ORACLE_HOME still needs to be windows format!&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Message file sp1&amp;lt;lang&amp;gt;.msb not found&lt;br /&gt;
SP2-0750 :You may need to set ORACLE_HOME to your Oracle software directory&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
so...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
export ORACLE_SID=KITRYD&lt;br /&gt;
ORAENV_ASK=NO&lt;br /&gt;
. oraenv&lt;br /&gt;
[[ &amp;quot;`uname`&amp;quot; == CYGWIN* ]] &amp;amp;&amp;amp; ORACLE_HOME=`cygpath -w ${ORACLE_HOME}`&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===ORA-2002: error while writing to audit trail===&lt;br /&gt;
Check the space left in the audit tablespace with:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select sum(bytes)/1024/1024 mb from dba_free_space where tablespace_name =&amp;#039;AUDIT_DT&amp;#039;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
If plenty of space, it can be due to Oracle clearing out the recyclebin at the same time.&amp;lt;br /&amp;gt;&lt;br /&gt;
If not, extend the datafile...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select * from dba_data_files where tablespace_name =&amp;#039;AUDIT_DT&amp;#039;;&lt;br /&gt;
alter database datafile 6 resize 30G;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
If that is not possible, clean out some audit data or add a datafile.&lt;br /&gt;
&lt;br /&gt;
===ORA-00449: background process &amp;#039;CKPT&amp;#039; unexpectedly terminated with error 7446===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SQL&amp;gt; startup nomount pfile=&amp;quot;/oracle/TRSCRP1/admin/initTRSCRP1.ora&amp;quot;&lt;br /&gt;
ORA-00449: background process &amp;#039;CKPT&amp;#039; unexpectedly terminated with error 7446&lt;br /&gt;
ORA-07446: sdnfy: bad value &amp;#039;&amp;#039; for parameter .&lt;br /&gt;
SQL&amp;gt; exit&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Solution&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SQL&amp;gt; mkdir /oracle/TRSCRP1/admin/bdump /oracle/TRSCRP1/admin/cdump&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORA-00845: MEMORY_TARGET not supported on this system===&lt;br /&gt;
* Reference: [http://arjudba.blogspot.be/2009/01/ora-00845-memorytarget-not-supported-on.html arjudba.blogspot.be]&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Problem Description&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SQL&amp;gt; STARTUP&lt;br /&gt;
ORA-00845: MEMORY_TARGET not supported on this system&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Cause&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
* Starting from Oracle 11g the automatic memory management feature is now defined with parameter MEMORY_TARGET and MEMMORY_MAX_TARGET.&lt;br /&gt;
* On linux file system the shared memory need to be mounted on /dev/shm directory on the operating system.&lt;br /&gt;
* And the size of /dev/shm needs to be greater than MEMORY_TARGET or MEMMORY_MAX_TARGET.&lt;br /&gt;
* The AMM (Automatic Memory Management) now in 11g manages both SGA and PGA together by MMAN process.&lt;br /&gt;
* The MEMORY_TARGET parameter in 11g comes for (SGA_TARGET+PGA_AGGREGATE_TARGET) which was in 10g.&lt;br /&gt;
* And MEMORY_MAX_TARGET parameter in 11g comes instead of SGA_MAX_TARGET parameter which was in 10g.&lt;br /&gt;
* The ORA-00845:can arises for the following two reasons on linux system.&lt;br /&gt;
1)If the shared memory which is mapped to /dev/shm directory is less than the size of MEMORY_TARGET or MEMORY_MAX_TARGET or&lt;br /&gt;
2)If the shared memory is not mapped to /dev/shm directory.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Solution&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Make sure /dev/shm is properly mounted. You can see it by,&lt;br /&gt;
#df -h or #df -k command.&lt;br /&gt;
The output should be similar to:&lt;br /&gt;
&lt;br /&gt;
$ df -k&lt;br /&gt;
Filesystem            Size  Used Avail Use% Mounted on&lt;br /&gt;
...&lt;br /&gt;
shmfs                 1G    512M 512M  50% /dev/shm&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
We see here for /dev/shm we have assigned 1G memory. Now if you set MEMORY_TARGET more than 1G then above ORA-845 will arise. For example if you have MEMORY_TARGET or MEMORY_MAX_TARGET set to 12G then you can mount shared memory to 13g like below.&lt;br /&gt;
As a root user,&lt;br /&gt;
# mount -t tmpfs shmfs -o size=13g /dev/shm&lt;br /&gt;
In order to make the settings persistence so that it will affect after restarting machine add an entry in /etc/fstab similar to the following:&lt;br /&gt;
&lt;br /&gt;
shmfs /dev/shm tmpfs size=13g 0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORA-24247: network access denied by access control list (ACL)===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Cause: No access control list (ACL) has been assigned to the target host or the privilege necessary to access the target host has not been granted to the user in the access control list.&lt;br /&gt;
&lt;br /&gt;
Action: Ensure that an access control list (ACL) has been assigned to the target host and the privilege necessary to access the target host has been granted to the user.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Your application will encounter an ORA-24247 error if it relies on one of the network packages and no proper ACL has been created. For the use of the following packages it is mandatory to have an ACL for the application user in place in 11g:&lt;br /&gt;
*UTL_TCP&lt;br /&gt;
*UTL_SMTP&lt;br /&gt;
*UTL_MAIL&lt;br /&gt;
*UTL_HTTP&lt;br /&gt;
*UTL_INADDR&lt;br /&gt;
Here is a very good explanation of how to setup the necessary ACLs: [[http://blog.whitehorses.nl/2010/03/17/oracle-11g-access-control-list-and-ora-24247/ whitehorses.nl]]&lt;br /&gt;
&lt;br /&gt;
===ORA-00600: internal error code, arguments: [qmx: no ref]===&lt;br /&gt;
Search &amp;quot;Master Note for Oracle XML Database (XDB) Install / Deinstall (Doc ID 1292089.1)&amp;quot; for more info.&lt;br /&gt;
====Problem:====&lt;br /&gt;
Sometimes one or more of the following errors can be encountered when installing or upgrading XDB, configuring APEX, running an Export, or selecting from xdb.xdb$resource or sys.dba_network_acls:&amp;lt;br /&amp;gt;&lt;br /&gt;
* ORA-31159: XML DB is in an invalid state&lt;br /&gt;
* ORA-00600: internal error code, arguments: [unable to load XDB library]&lt;br /&gt;
* ORA-00600: internal error code, arguments: [qmx: no ref]&lt;br /&gt;
* ORA-00600: internal error code, arguments: [qmtGetColumnInfo1]&lt;br /&gt;
* ORA-00600: internal error code, arguments: [qmtb_init_len]&lt;br /&gt;
* ORA-00600: internal error code, arguments: [qmtGetBaseType]&lt;br /&gt;
* ORA-00600: internal error code, arguments: [psdnop-1], [600]&lt;br /&gt;
* ORA-00600: internal error code, arguments: [qmtInit1]&lt;br /&gt;
* ORA-07445: exception encountered: core dump [_memcpy()+224] [SIGSEGV] [Address not mapped to object]&lt;br /&gt;
* ORA-19051 Cannot Use Fast Path Insert For This XMLType Table&lt;br /&gt;
* ORA-31011: XML parsing failed&lt;br /&gt;
Errors of this sort generally occur when the init routines for the internal XDB functions are run in an invalid environment causing memory corruption.&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
This can happen if the database was ever started with the LD_LIBRARY_PATH (LIBPATH for AIX or SHLIB_PATH for HP) pointing to the wrong $ORACLE_HOME/lib directory rather than to the correct location for the instance.&amp;lt;br /&amp;gt;&lt;br /&gt;
The LD_LIBRARY_PATH/LIBPATH/SHLIB_PATH environment variable is used to resolve the location of the shared library &amp;quot;libxdb.so (libxdb.sl on HP)&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
====Solution:====&lt;br /&gt;
* Stop Listener&lt;br /&gt;
* Stop database&lt;br /&gt;
* Ensure $ORACLE_HOME/lib is at the start of LD_LIBRARY_PATH / LIBPATH / SHLIB_PATH&lt;br /&gt;
* If AIX, run /usr/sbin/slibclean as root&lt;br /&gt;
* Start database&lt;br /&gt;
* Start listener&lt;br /&gt;
&lt;br /&gt;
===ORA-00201: control file version nn.nn.nn.nn incompatible with ORACLE version===&lt;br /&gt;
Trying to restore a database after complete failure&amp;lt;br /&amp;gt;&lt;br /&gt;
first step is to startup the database in nomount mode and restore the controlfile - succeeded.&amp;lt;br /&amp;gt;&lt;br /&gt;
second step, startup the database in mount mode ready for database restore...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SQL*Plus: Release 10.2.0.3.0 - Production on Wed Aug 19 18:16:47 2015&lt;br /&gt;
&lt;br /&gt;
Copyright (c) 1982, 2006, Oracle.  All Rights Reserved.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Connected to:&lt;br /&gt;
Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - 64bit Production&lt;br /&gt;
With the Partitioning, OLAP and Data Mining options&lt;br /&gt;
&lt;br /&gt;
SYS@CODWHP1&amp;gt; startup mount&lt;br /&gt;
ORACLE instance started.&lt;br /&gt;
&lt;br /&gt;
Total System Global Area  260046848 bytes&lt;br /&gt;
Fixed Size                  2029296 bytes&lt;br /&gt;
Variable Size             113248528 bytes&lt;br /&gt;
Database Buffers          134217728 bytes&lt;br /&gt;
Redo Buffers               10551296 bytes&lt;br /&gt;
ORA-00201: control file version 10.2.0.0.0 incompatible with ORACLE version 10.2.0.3.0&lt;br /&gt;
ORA-00202: control file: &amp;#039;/oracle/CODWHP1/product/10203/dbs/cntrlCODWHP1.dbf&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The problem was there was no compatible parameter in the simple init file I used to start up the instance.&amp;lt;br /&amp;gt;&lt;br /&gt;
Adding compatible parameter to init file to be same version (10.2.0.3) allowed the db to mount.&lt;br /&gt;
&lt;br /&gt;
===TNS-00525: Insufficient privilege for operation===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
lsnrctl start LISTENER_UCLID55V&lt;br /&gt;
&lt;br /&gt;
LSNRCTL for IBM/AIX RISC System/6000: Version 11.2.0.3.0 - Production on 26-MAR-2015 13:36:14&lt;br /&gt;
&lt;br /&gt;
Copyright (c) 1991, 2011, Oracle.  All rights reserved.&lt;br /&gt;
&lt;br /&gt;
Starting /oracle/product/11.2.0.3/bin/tnslsnr: please wait...&lt;br /&gt;
&lt;br /&gt;
TNSLSNR for IBM/AIX RISC System/6000: Version 11.2.0.3.0 - Production&lt;br /&gt;
System parameter file is /oracle/product/11.2.0.3/network/admin/listener.ora&lt;br /&gt;
Log messages written to /oracle/product/diag/tnslsnr/solax082/listener_uclid55v/alert/log.xml&lt;br /&gt;
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=150.251.114.238)(PORT=1525)))&lt;br /&gt;
Error listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC1525)))&lt;br /&gt;
TNS-12555: TNS:permission denied&lt;br /&gt;
 TNS-12560: TNS:protocol adapter error&lt;br /&gt;
  TNS-00525: Insufficient privilege for operation&lt;br /&gt;
   IBM/AIX RISC System/6000 Error: 1: Not owner&lt;br /&gt;
&lt;br /&gt;
Listener failed to start. See the error message(s) above...&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This would suggest the user attempting to start the listener has no access to either the Oracle binaries or the TNS listener/tnsnames files.&amp;lt;br /&amp;gt;&lt;br /&gt;
But... checkout the /tmp/.oracle directory :-)&amp;lt;br /&amp;gt;&lt;br /&gt;
That hidden gem shows who started the listener last time. Delete the relevant entry and try again!&amp;lt;br /&amp;gt;&lt;br /&gt;
To start from a clean sheet, stop all listeners, delete this directory and restart the listeners.&lt;br /&gt;
&lt;br /&gt;
===ORA-12003: materialized view or zonemap &amp;quot;KPK&amp;quot;.&amp;quot;EVD01_NEW&amp;quot; does not exist===&lt;br /&gt;
Here&amp;#039;s one you shouldn&amp;#039;t see very often.&amp;lt;br /&amp;gt;&lt;br /&gt;
Trying to drop a tablespace but prevented from doing so because a materialized view has referential contraints on a table in this tablespace.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SQL&amp;gt; drop tablespace TS_THALER_PART_OLD including contents and datafiles cascade constraints;&lt;br /&gt;
drop tablespace TS_THALER_PART_OLD including contents and datafiles cascade constraints&lt;br /&gt;
*&lt;br /&gt;
ERROR at line 1:&lt;br /&gt;
ORA-00604: error occurred at recursive SQL level 1&lt;br /&gt;
ORA-12083: must use DROP MATERIALIZED VIEW to drop &amp;quot;KPK&amp;quot;.&amp;quot;EVD01_NEW&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Ok, nice of Oracle to tell us what we have to do. Simple enough. Let&amp;#039;s drop the materialized view.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SQL&amp;gt; DROP MATERIALIZED VIEW &amp;quot;KPK&amp;quot;.&amp;quot;EVD01_NEW&amp;quot;;&lt;br /&gt;
DROP MATERIALIZED VIEW &amp;quot;KPK&amp;quot;.&amp;quot;EVD01_NEW&amp;quot;&lt;br /&gt;
*&lt;br /&gt;
ERROR at line 1:&lt;br /&gt;
ORA-12003: materialized view or zonemap &amp;quot;KPK&amp;quot;.&amp;quot;EVD01_NEW&amp;quot; does not exist&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Aah. Not so obvious then.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
desc &amp;quot;KPK&amp;quot;.&amp;quot;EVD01_NEW&amp;quot;&lt;br /&gt;
 Name                                      Null?    Type&lt;br /&gt;
 ----------------------------------------- -------- ----------------------------&lt;br /&gt;
 DATMAJ                                             VARCHAR2(8 CHAR)&lt;br /&gt;
 HEUMAJ                                             VARCHAR2(8 CHAR)&lt;br /&gt;
 PGMMAJ                                             VARCHAR2(6 CHAR)&lt;br /&gt;
 NATOPN                                             VARCHAR2(6 CHAR)&lt;br /&gt;
 REFEXN                                             VARCHAR2(50 CHAR)&lt;br /&gt;
 SWIOLN                                             VARCHAR2(1 CHAR)&lt;br /&gt;
 STAEVT                                             VARCHAR2(4 CHAR)&lt;br /&gt;
 REFEVT                                             VARCHAR2(16 CHAR)&lt;br /&gt;
 NUMIDT                                             VARCHAR2(30 CHAR)&lt;br /&gt;
 ORIEVT                                             VARCHAR2(10 CHAR)&lt;br /&gt;
 REFLOG                                             VARCHAR2(16 CHAR)&lt;br /&gt;
 MSGEVT_CPL                                         VARCHAR2(1500 CHAR)&lt;br /&gt;
 REFOPN                                             VARCHAR2(16 CHAR)&lt;br /&gt;
 DATEVT                                             VARCHAR2(8 CHAR)&lt;br /&gt;
 MSGEVT_FIL_1                                       VARCHAR2(2000 CHAR)&lt;br /&gt;
 MSGEVT_FIL_2                                       VARCHAR2(2000 CHAR)&lt;br /&gt;
 MSGEVT_SPE                                         VARCHAR2(200 CHAR)&lt;br /&gt;
 DATEFF                                             VARCHAR2(8 CHAR)&lt;br /&gt;
 TMSTMP                                             VARCHAR2(15 CHAR)&lt;br /&gt;
 VEREVT                                             VARCHAR2(3 CHAR)&lt;br /&gt;
 MSGEVT_FIL_3                                       VARCHAR2(2000 CHAR)&lt;br /&gt;
 MSGEVT_FIL_4                                       VARCHAR2(2000 CHAR)&lt;br /&gt;
 TYPEVT                                             VARCHAR2(5 CHAR)&lt;br /&gt;
 SBP_CODAPP                                         VARCHAR2(10 CHAR)&lt;br /&gt;
 SBP_REFINT                                         VARCHAR2(36 CHAR)&lt;br /&gt;
 SBP_TYPACT                                         VARCHAR2(2 CHAR)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
It exists... but as a table.&amp;lt;br /&amp;gt;&lt;br /&gt;
Something has gone wrong in the database somewhere. As it turns out after some deeper investigation, this database is a copy of production but &amp;quot;with modifications&amp;quot;.&amp;lt;br /&amp;gt;&lt;br /&gt;
After the cloning process, a schema needed renaming. Oracle have a procedure for this but it is very long-winded and time-consuming. It uses export and import with transportable tablespaces to do the remap of the schema.&amp;lt;br /&amp;gt;&lt;br /&gt;
An unsupported workaround to rename schema is to simply update the username in sys.user$ and restart the database.&amp;lt;br /&amp;gt;&lt;br /&gt;
This works for the most part but now we see a consequence of that action.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
col owner      for a30&lt;br /&gt;
col mview_name for a30&lt;br /&gt;
select owner&lt;br /&gt;
,      mview_name&lt;br /&gt;
from   dba_mviews&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
OWNER                          MVIEW_NAME&lt;br /&gt;
------------------------------ ------------------------------&lt;br /&gt;
EPK                            EVD01_NEW&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Ahaa, there&amp;#039;s the materialized view but the owner is different from the one described by the database error message above. This one is the owner as it was on production.&amp;lt;br /&amp;gt;&lt;br /&gt;
This means the owner of materialized views has been denormalised for some reason. Reading the (complex) view text of dba_mviews, we see the owner column is based on sys.snap$.sowner&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
col sowner for a20&lt;br /&gt;
col vname  for a20&lt;br /&gt;
col tname  for a20&lt;br /&gt;
select sowner&lt;br /&gt;
,      vname&lt;br /&gt;
,      tname&lt;br /&gt;
from   sys.snap$&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
SOWNER               VNAME                TNAME&lt;br /&gt;
-------------------- -------------------- --------------------&lt;br /&gt;
EPK                  EVD01_NEW            EVD01_NEW&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
For future reference when updating the username in sys.user$, update the snapshot owner in this table as well!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
update sys.snap$&lt;br /&gt;
set    sowner = &amp;#039;KPK&amp;#039;&lt;br /&gt;
where  sowner = &amp;#039;EPK&amp;#039;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Try again&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
DROP MATERIALIZED VIEW &amp;quot;KPK&amp;quot;.&amp;quot;EVD01_NEW&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
Materialized view dropped.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
yep, and the tablespace?&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
drop tablespace TS_THALER_PART_OLD including contents and datafiles cascade constraints;&lt;br /&gt;
&lt;br /&gt;
Tablespace dropped.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORA-12162: TNS:net service name is incorrectly specified===&lt;br /&gt;
Probably nothing to do with TNS. Check your ORACLE_SID is set correctly!&lt;br /&gt;
&lt;br /&gt;
===ORA-00054: resource busy and acquire with NOWAIT specified===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SELECT O.OBJECT_NAME, S.SID, S.SERIAL#, P.SPID, S.PROGRAM,S.USERNAME,&lt;br /&gt;
S.MACHINE,S.PORT , S.LOGON_TIME,SQ.SQL_FULLTEXT &lt;br /&gt;
FROM V$LOCKED_OBJECT L, DBA_OBJECTS O, V$SESSION S, &lt;br /&gt;
V$PROCESS P, V$SQL SQ &lt;br /&gt;
WHERE L.OBJECT_ID = O.OBJECT_ID &lt;br /&gt;
AND L.SESSION_ID = S.SID AND S.PADDR = P.ADDR &lt;br /&gt;
AND S.SQL_ADDRESS = SQ.ADDRESS;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select object_name, s.sid, s.serial#, p.spid &lt;br /&gt;
from v$locked_object l, dba_objects o, v$session s, v$process p&lt;br /&gt;
where l.object_id = o.object_id and l.session_id = s.sid and s.paddr = p.addr;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
then&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter system kill session &amp;#039;sid,serial#&amp;#039;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORA-12518: TNS:listener could not hand off client connection===&lt;br /&gt;
The database you are trying to connect to is probably on its knees. Check server memory is not exhausted.&lt;br /&gt;
&lt;br /&gt;
===ORA-12520: TNS:listener could not find available handler for requested type of server===&lt;br /&gt;
Strangely this could be related to number of processes being exhausted.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
show parameter processes&lt;br /&gt;
alter system set processes=350 scope=spfile;&lt;br /&gt;
shutdown immediate&lt;br /&gt;
startup&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORA-12541: TNS: no listener===&lt;br /&gt;
Either very basic - start the listener!&amp;lt;br /&amp;gt;&lt;br /&gt;
or, as in our case - not so obvious.&amp;lt;br /&amp;gt;&lt;br /&gt;
We use virtual IP addresses so that the IP address stays the same after failover to standby.&amp;lt;br /&amp;gt;&lt;br /&gt;
Due to some confused configuration, we got the network adapter on two different servers to have the same IP address.&amp;lt;br /&amp;gt;&lt;br /&gt;
Stop the IP address on the bad server (assign another one) and all is fine again.&lt;br /&gt;
===ORA-12514: TNS:listener does not currently know of service===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
lsnrctl status &amp;lt;listener_name&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Been altering tnsnames.ora or listener.ora?&lt;br /&gt;
* Check the local_listener parameter&lt;br /&gt;
Try resetting it to itself. Strange but if you are not using port 1521, this can work wonders!&amp;lt;br /&amp;gt;&lt;br /&gt;
Assuming listener is called LISTENER_WM9T:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter system set local_listener=LISTENER_WM9T scope=both;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Try and connect with the service name or directly with&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sqlplus &amp;#039;sys/*******&amp;#039;@&amp;lt;host&amp;gt;:&amp;lt;port&amp;gt;/&amp;lt;SID&amp;gt; as sysdba&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Excellent description of how Oracle TNS listeners work and a checklist on how to fix this error&amp;lt;br /&amp;gt;&lt;br /&gt;
* [[http://edstevensdba.wordpress.com/2011/03/19/ora-12514/ TNS — Ed Stevens]]&lt;br /&gt;
&lt;br /&gt;
===ORA-12547: TNS lost contact===&lt;br /&gt;
&lt;br /&gt;
If&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sqlplus &amp;lt;user&amp;gt;/&amp;lt;pass&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
fails with above error, try&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sqlplus &amp;lt;user&amp;gt;/&amp;lt;pass&amp;gt;@&amp;lt;db connection&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
If this works, it is most probably a permissions error.&amp;lt;br /&amp;gt;&lt;br /&gt;
Re-run the&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ORACLE_HOME/root.sh&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
script that was run as part of the original installation. This will reset the permissions on some important files.&lt;br /&gt;
===ORA-02374: conversion error loading table &amp;quot;BLENGADM&amp;quot;.&amp;quot;ZZ_EVTCTA&amp;quot;===&lt;br /&gt;
This is typical of importing data with Datapump when the tables in the source database were created with &amp;quot;byte&amp;quot; semantics and the destination is &amp;quot;char&amp;quot; semantics.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ORA-02374: conversion error loading table &amp;quot;BLENGADM&amp;quot;.&amp;quot;ZZ_EVTCTA&amp;quot;&lt;br /&gt;
ORA-12899: value too large for column NOMCTA (actual: 257, maximum: 256)&lt;br /&gt;
&lt;br /&gt;
ORA-02372: data for row: NOMCTA : 0X&amp;#039;4C6976726574206427E9706172676E65202020202020202020&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Problem====&lt;br /&gt;
The root cause is the nls_length_semantics of the table columns being BYTE where one character is assigned one byte. But after conversion in a multi-byte database, one character is larger than one byte (could be 2, 3 or 4) and no longer fits.&lt;br /&gt;
====Solution====&lt;br /&gt;
* import the metadata&lt;br /&gt;
Run the impdp command with content=metadata_only. This will create all the tables (still in their original form) but not the data.&lt;br /&gt;
* alter the BYTE columns in the affected tables to CHAR semantics&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select column_name&lt;br /&gt;
,      char_used&lt;br /&gt;
,      data_length&lt;br /&gt;
,      data_type &lt;br /&gt;
from   user_tab_columns &lt;br /&gt;
where  table_name = &amp;#039;T&amp;#039;&lt;br /&gt;
and    char_used = &amp;#039;B&amp;#039;;&lt;br /&gt;
COLUMN_NAME  C DATA_LENGTH DATA_TYPE&lt;br /&gt;
------------ - ----------- ---------&lt;br /&gt;
X            B           1 VARCHAR2&lt;br /&gt;
SQL&amp;gt; alter table t modify x varchar2(1 char);&lt;br /&gt;
Table altered.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Import the data&lt;br /&gt;
Rerun the impdp ensuring table_exists_action is not REPLACE (use truncate or append). This now imports the data into the modified tables.&lt;br /&gt;
====This script does the donkey work of altering table column semantics from byte to char====&lt;br /&gt;
The author of this script is unknown but he/she deserves a medal. It saves countless hours of work and is so well written.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/*&lt;br /&gt;
  The script converts all the VARCHAR2 columns in the user&amp;#039;s schema&lt;br /&gt;
  to CHAR length semantics. Known to work on 10.2.0.4 and later.&lt;br /&gt;
  &lt;br /&gt;
  Script must be executed against the database without any other client&lt;br /&gt;
  and/or application connections to the affected schema.&lt;br /&gt;
  &lt;br /&gt;
  Oracle does not support CHAR semantics for the built-in schemas,&lt;br /&gt;
  like SYS, SYSTEM or SYSMAN, so the script will throw an error,&lt;br /&gt;
  if attempt to run it against any one of them.&lt;br /&gt;
  &lt;br /&gt;
  Upon completion database objects that have dependencies on tables&lt;br /&gt;
  being modified will be invalidated. Oracle usually re-compiles invalidated&lt;br /&gt;
  objects on the first access. Alternatively, a DBA can execute UTLPRP script&lt;br /&gt;
  to recompile all invalid objects in the entire database.&lt;br /&gt;
  &lt;br /&gt;
  Upon completion, please make sure that NLS_LENGTH_SEMANTICS instance parameter&lt;br /&gt;
  is set to CHAR to ensure further upgradability of the schema.&lt;br /&gt;
*/&lt;br /&gt;
set serveroutput on size unlimited format wrap&lt;br /&gt;
declare&lt;br /&gt;
  type sql_list_t is table of varchar2(32767) index by pls_integer;&lt;br /&gt;
  type idx_list_t is table of user_indexes.index_name%type index by pls_integer;&lt;br /&gt;
  type col_list_t is table of user_tab_columns%rowtype index by pls_integer;&lt;br /&gt;
  --&lt;br /&gt;
  lv_col_cnt   pls_integer := 0;&lt;br /&gt;
  lv_idx_cnt   pls_integer := 0;&lt;br /&gt;
  lv_char_set  pls_integer := 0; &lt;br /&gt;
  lv_user      user_users.username%type;&lt;br /&gt;
  lv_sql_stmt  varchar2(32767);&lt;br /&gt;
  lv_byte_cols col_list_t;&lt;br /&gt;
  lv_idx_names idx_list_t;&lt;br /&gt;
  lv_idx_ddls  sql_list_t;&lt;br /&gt;
  --&lt;br /&gt;
  procedure run_sql_stmt&lt;br /&gt;
  (&lt;br /&gt;
   p_sql_stmt in varchar2&lt;br /&gt;
  )&lt;br /&gt;
  as&lt;br /&gt;
  begin&lt;br /&gt;
    execute immediate p_sql_stmt;&lt;br /&gt;
  exception&lt;br /&gt;
    when others&lt;br /&gt;
    then&lt;br /&gt;
      raise_application_error(-20202, &amp;#039;Failed statement [&amp;#039; || p_sql_stmt || dbms_utility.format_error_backtrace() || &amp;#039;]&amp;#039;, true);&lt;br /&gt;
  end;&lt;br /&gt;
begin&lt;br /&gt;
  --&lt;br /&gt;
  lv_user := user();&lt;br /&gt;
  if lv_user in (&amp;#039;SYS&amp;#039;, &amp;#039;SYSTEM&amp;#039;, &amp;#039;SYSMAN&amp;#039;)&lt;br /&gt;
  then&lt;br /&gt;
    raise_application_error(-20202, &amp;#039;This script cannot be executed against Oracle built-in schema [&amp;#039; || lv_user || &amp;#039;].&amp;#039;);&lt;br /&gt;
  end if;&lt;br /&gt;
  --&lt;br /&gt;
  select&lt;br /&gt;
         *&lt;br /&gt;
         bulk collect into lv_byte_cols&lt;br /&gt;
  from&lt;br /&gt;
         user_tab_columns uc&lt;br /&gt;
  where&lt;br /&gt;
         uc.char_used = &amp;#039;B&amp;#039;&lt;br /&gt;
         and&lt;br /&gt;
         substr(uc.table_name, 1, 4) != &amp;#039;BIN$&amp;#039;&lt;br /&gt;
         and&lt;br /&gt;
         not exists&lt;br /&gt;
         (&lt;br /&gt;
          select 1&lt;br /&gt;
          from   user_views uv&lt;br /&gt;
          where  uv.view_name = uc.table_name&lt;br /&gt;
         )&lt;br /&gt;
  ;&lt;br /&gt;
  --&lt;br /&gt;
  lv_col_cnt := lv_byte_cols.count();&lt;br /&gt;
  --&lt;br /&gt;
  dbms_output.enable();&lt;br /&gt;
  --&lt;br /&gt;
  if lv_col_cnt &amp;gt; 0&lt;br /&gt;
  then&lt;br /&gt;
    for idx_rw in&lt;br /&gt;
    (&lt;br /&gt;
     select index_name &lt;br /&gt;
     from   user_indexes&lt;br /&gt;
     where  index_type = &amp;#039;FUNCTION-BASED NORMAL&amp;#039;&lt;br /&gt;
    )&lt;br /&gt;
    loop&lt;br /&gt;
      lv_idx_cnt := lv_idx_cnt + 1;&lt;br /&gt;
      lv_idx_names(lv_idx_cnt) := idx_rw.index_name;&lt;br /&gt;
      lv_idx_ddls(lv_idx_cnt) := replace&lt;br /&gt;
                                 (&lt;br /&gt;
                                  dbms_metadata.get_ddl&lt;br /&gt;
                                  (&lt;br /&gt;
                                   object_type =&amp;gt; &amp;#039;INDEX&amp;#039;,&lt;br /&gt;
                                   name        =&amp;gt; idx_rw.index_name&lt;br /&gt;
                                  )&lt;br /&gt;
                                  ,&lt;br /&gt;
                                  &amp;#039;;&amp;#039;&lt;br /&gt;
                                 );&lt;br /&gt;
      lv_sql_stmt := &amp;#039;drop index &amp;#039; || idx_rw.index_name;&lt;br /&gt;
      run_sql_stmt(lv_sql_stmt);&lt;br /&gt;
      dbms_output.put_line(&amp;#039;Dropped function-based index: &amp;#039; || idx_rw.index_name);&lt;br /&gt;
      dbms_output.put_line(&amp;#039;In case of script failure, restore the index by running the DDL statement below:&amp;#039;);&lt;br /&gt;
      dbms_output.put_line(lv_idx_ddls(lv_idx_cnt) || &amp;#039;;&amp;#039;);&lt;br /&gt;
    end loop;&lt;br /&gt;
    --&lt;br /&gt;
    for i in 1..lv_col_cnt&lt;br /&gt;
    loop&lt;br /&gt;
      lv_sql_stmt :=  &amp;#039;alter table &amp;#039; || lv_byte_cols(i).table_name || &amp;#039; modify (&amp;#039; ||&lt;br /&gt;
                      lv_byte_cols(i).column_name || &amp;#039; &amp;#039; || lv_byte_cols(i).data_type ||&lt;br /&gt;
                      &amp;#039;(&amp;#039; || lv_byte_cols(i).char_length || &amp;#039; char))&amp;#039;;&lt;br /&gt;
      run_sql_stmt(lv_sql_stmt);&lt;br /&gt;
    end loop;&lt;br /&gt;
    --&lt;br /&gt;
    dbms_output.new_line();&lt;br /&gt;
    for i in 1..lv_idx_cnt&lt;br /&gt;
    loop&lt;br /&gt;
      run_sql_stmt(lv_idx_ddls(i));&lt;br /&gt;
      dbms_output.put_line(&amp;#039;Recreated function-based index: &amp;#039; || lv_idx_names(i));&lt;br /&gt;
    end loop;&lt;br /&gt;
    --&lt;br /&gt;
    dbms_output.new_line();&lt;br /&gt;
    dbms_output.put_line&lt;br /&gt;
    (&lt;br /&gt;
     &amp;#039;Updated length semantics to CHAR for &amp;#039; || lv_col_cnt || &amp;#039; column&amp;#039; ||&lt;br /&gt;
     case when lv_col_cnt &amp;gt; 1&lt;br /&gt;
          then &amp;#039;s&amp;#039;&lt;br /&gt;
     end ||&lt;br /&gt;
     &amp;#039; in the schema [&amp;#039; || lv_user || &amp;#039;].&amp;#039;&lt;br /&gt;
    );&lt;br /&gt;
  else&lt;br /&gt;
    dbms_output.put_line(&amp;#039;No columns with BYTE length semantics were found in the schema [&amp;#039; || lv_user || &amp;#039;].&amp;#039;);&lt;br /&gt;
  end if;&lt;br /&gt;
  --&lt;br /&gt;
  select count(*) into lv_char_set&lt;br /&gt;
  from   nls_session_parameters&lt;br /&gt;
  where  parameter = &amp;#039;NLS_LENGTH_SEMANTICS&amp;#039;&lt;br /&gt;
         and&lt;br /&gt;
         value = &amp;#039;CHAR&amp;#039;&lt;br /&gt;
  ;&lt;br /&gt;
  --&lt;br /&gt;
  if lv_char_set = 0&lt;br /&gt;
  then&lt;br /&gt;
    dbms_output.put_line(&amp;#039;WARNING: Do not forget to change instance parameter NLS_LENGTH_SEMANTICS to CHAR and restart the database.&amp;#039;);&lt;br /&gt;
  end if;&lt;br /&gt;
end;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORA-14097: column type or size mismatch in ALTER TABLE EXCHANGE PARTITION===&lt;br /&gt;
Nothing especially to do with partitions - just any ddl operation that affects the table as a whole (as that touches the offending hidden column).&amp;lt;br /&amp;gt;&lt;br /&gt;
Hidden columns do not normally show up in a desc unless colinvisible is on&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set colinvisible on&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
But these sneaky system-generated ones don&amp;#039;t show up even with that setting on!  You need to show them with this:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set pages 50 lines 1000&lt;br /&gt;
col column_name for a40&lt;br /&gt;
col data_default for a40&lt;br /&gt;
select internal_column_id, column_name, data_default, hidden_column, virtual_column from dba_tab_cols where table_name =&amp;#039;XND40&amp;#039;;&lt;br /&gt;
&lt;br /&gt;
INTERNAL_COLUMN_ID COLUMN_NAME                                        DATA_DEFAULT                                       HIDDEN_COLUM VIRTUAL_COLU&lt;br /&gt;
------------------ -------------------------------------------------- -------------------------------------------------- ------------ ------------&lt;br /&gt;
                35 MONLOT_REC_CDR                                     &amp;#039;0&amp;#039;                                                NO           NO&lt;br /&gt;
                34 MONLOT_REC_DBT                                     &amp;#039;0&amp;#039;                                                NO           NO&lt;br /&gt;
                33 MONLOT_CAL_CDR                                     &amp;#039;0&amp;#039;                                                NO           NO&lt;br /&gt;
                32 MONLOT_CAL_DBT                                     &amp;#039;0&amp;#039;                                                NO           NO&lt;br /&gt;
                31 MONMVT_CPT                                         &amp;#039;0&amp;#039;                                                NO           NO&lt;br /&gt;
                30 SENNOT                                             &amp;#039; &amp;#039;                                                NO           NO&lt;br /&gt;
                29 NUMSEQ                                                                                                NO           NO&lt;br /&gt;
                28 NOMFIC                                                                                                NO           NO&lt;br /&gt;
                27 TOTCPT_REC                                                                                            NO           NO&lt;br /&gt;
                26 TOTCPT_CAL                                                                                            NO           NO&lt;br /&gt;
                25 MONLOT_REC                                                                                            NO           NO&lt;br /&gt;
                24 MONLOT_CAL                                                                                            NO           NO&lt;br /&gt;
                23 NBRELE_REC                                                                                            NO           NO&lt;br /&gt;
                22 NBRELE_CAL                                                                                            NO           NO&lt;br /&gt;
                21 NUMCPT_GLO                                                                                            NO           NO&lt;br /&gt;
                20 DEVLOT                                                                                                NO           NO&lt;br /&gt;
                19 CODERR                                                                                                NO           NO&lt;br /&gt;
                18 CANLOT                                                                                                NO           NO&lt;br /&gt;
                17 REFTEX                                                                                                NO           NO&lt;br /&gt;
                16 REFEXN                                                                                                NO           NO&lt;br /&gt;
                15 ETTLOT                                                                                                NO           NO&lt;br /&gt;
                14 TYPLOT                                                                                                NO           NO&lt;br /&gt;
                13 DATEXC                                                                                                NO           NO&lt;br /&gt;
                12 STALOT                                                                                                NO           NO&lt;br /&gt;
                11 REFLOT                                                                                                NO           NO&lt;br /&gt;
                10 USRAUT                                                                                                NO           NO&lt;br /&gt;
                 9 HEUAUT                                                                                                NO           NO&lt;br /&gt;
                 8 DATAUT                                                                                                NO           NO&lt;br /&gt;
                 7 PGMMAJ                                                                                                NO           NO&lt;br /&gt;
                 6 USRMAJ                                                                                                NO           NO&lt;br /&gt;
                 5 HEUMAJ                                                                                                NO           NO&lt;br /&gt;
                 4 DATMAJ                                                                                                NO           NO&lt;br /&gt;
                 3 DATCRT                                                                                                NO           NO&lt;br /&gt;
                 2 REFMAJ                                                                                                NO           NO&lt;br /&gt;
                 1 NUMVER                                                                                                NO           NO&lt;br /&gt;
                36 SYS_STS#KR2WNV5L070XKV1L5H7REH                     SYS_OP_COMBINED_HASH(&amp;quot;NOMFIC&amp;quot;,&amp;quot;NUMSEQ&amp;quot;)            YES          YES&lt;br /&gt;
&lt;br /&gt;
36 rows selected.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
That last row means extended statistics have been generated for 2 columns in this table.&amp;lt;br /&amp;gt;&lt;br /&gt;
====Solution====&lt;br /&gt;
Drop the extended stats, do what you need to do and recreate the extended stats.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
PROCEDURE DROP_EXTENDED_STATS&lt;br /&gt;
 Argument Name                  Type                    In/Out Default?&lt;br /&gt;
 ------------------------------ ----------------------- ------ --------&lt;br /&gt;
 OWNNAME                        VARCHAR2                IN&lt;br /&gt;
 TABNAME                        VARCHAR2                IN&lt;br /&gt;
 EXTENSION                      VARCHAR2                IN&lt;br /&gt;
&lt;br /&gt;
exec dbms_stats.drop_extended_stats ( &amp;#039;KPK&amp;#039;, &amp;#039;XND40&amp;#039;, &amp;#039;(&amp;quot;NOMFIC&amp;quot;,&amp;quot;NUMSEQ&amp;quot;)&amp;#039; );&lt;br /&gt;
&lt;br /&gt;
create table kpk.xnd40_new as select * from kpk.xnd40 where 1=2;&lt;br /&gt;
&lt;br /&gt;
Table created.&lt;br /&gt;
&lt;br /&gt;
select dbms_stats.create_extended_stats ( &amp;#039;KPK&amp;#039;, &amp;#039;XND40&amp;#039;, &amp;#039;(&amp;quot;NOMFIC&amp;quot;,&amp;quot;NUMSEQ&amp;quot;)&amp;#039; ) from   dual;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORA-14404: partitioned table contains partitions in a different tablespace===&lt;br /&gt;
As part of an RMAN duplicate with a skip tablespace, this error is produced&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Reenabling controlfile options for auxiliary database&lt;br /&gt;
Executing: alter database enable block change tracking using file &amp;#039;/oracle/acc/ora_data3/adsa1/bct_adsp_do_not_delete.f&amp;#039;&lt;br /&gt;
&lt;br /&gt;
contents of Memory Script:&lt;br /&gt;
{&lt;br /&gt;
   Alter clone database open resetlogs;&lt;br /&gt;
}&lt;br /&gt;
executing Memory Script&lt;br /&gt;
&lt;br /&gt;
database opened&lt;br /&gt;
Dropping offline and skipped tablespaces&lt;br /&gt;
Executing: drop tablespace &amp;quot;ADS_ARCHIVE&amp;quot; including contents cascade constraints&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-03002: failure of Duplicate Db command at 10/16/2017 23:46:12&lt;br /&gt;
RMAN-05501: aborting duplication of target database&lt;br /&gt;
RMAN-06136: ORACLE error from auxiliary database: ORA-14404: partitioned table contains partitions in a different tablespace&lt;br /&gt;
&lt;br /&gt;
Recovery Manager complete.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
and when attempting to backup the database, we get errors&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
RMAN-06169: could not read file header for datafile 188 error reason 1&lt;br /&gt;
RMAN-06169: could not read file header for datafile 189 error reason 1&lt;br /&gt;
RMAN-06169: could not read file header for datafile 190 error reason 1&lt;br /&gt;
RMAN-06169: could not read file header for datafile 191 error reason 1&lt;br /&gt;
RMAN-06169: could not read file header for datafile 14 error reason 1&lt;br /&gt;
released channel: t1&lt;br /&gt;
released channel: t2&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-03002: failure of backup plus archivelog command at 10/17/2017 15:08:40&lt;br /&gt;
RMAN-06056: could not access datafile 14&lt;br /&gt;
&lt;br /&gt;
Recovery Manager complete.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Problem====&lt;br /&gt;
Tables in the tablespace have partitions in another tablespace so this one cannot be dropped.&amp;lt;br /&amp;gt;&lt;br /&gt;
Check which table partitions are in which tablespaces&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 200&lt;br /&gt;
set pagesize 200&lt;br /&gt;
col table_name for a14&lt;br /&gt;
col table_owner for a14&lt;br /&gt;
col partition_name for a14&lt;br /&gt;
select table_owner&lt;br /&gt;
,      table_name&lt;br /&gt;
,      partition_name&lt;br /&gt;
,      tablespace_name&lt;br /&gt;
from   dba_tab_partitions&lt;br /&gt;
where  (table_owner, table_name) in&lt;br /&gt;
       (&lt;br /&gt;
       select table_owner&lt;br /&gt;
       ,      table_name&lt;br /&gt;
       from   dba_tab_partitions x&lt;br /&gt;
       where  x.tablespace_name = &amp;#039;&amp;amp;&amp;amp;TABLESPACE_TO_DROP&amp;#039;&lt;br /&gt;
       and    exists ( select *&lt;br /&gt;
                       from   dba_tab_partitions y&lt;br /&gt;
                       where  x.table_owner = y.table_owner&lt;br /&gt;
                       and    x.table_name  = y.table_name&lt;br /&gt;
                       and    y.tablespace_name not in (&amp;#039;&amp;amp;TABLESPACE_TO_DROP&amp;#039;)&lt;br /&gt;
                       group  by table_owner&lt;br /&gt;
                       ,      table_name&lt;br /&gt;
                     )&lt;br /&gt;
        )&lt;br /&gt;
order by 1,2,partition_position&lt;br /&gt;
/&lt;br /&gt;
undef TABLESPACE_TO_DROP&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
TABLE_OWNER    TABLE_NAME     PARTITION_NAME TABLESPACE_NAME&lt;br /&gt;
-------------- -------------- -------------- ------------------------------&lt;br /&gt;
KPK            XND20          P0910          TS_THALER_PART_OLD&lt;br /&gt;
KPK            XND20          P1112          TS_THALER_PART_OLD&lt;br /&gt;
KPK            XND20          P13            TS_THALER_PART_OLD&lt;br /&gt;
KPK            XND20          P14            TS_THALER_PART_OLD&lt;br /&gt;
KPK            XND20          P15            TS_THALER_PART_OLD&lt;br /&gt;
KPK            XND20          P16            TS_THALER_DATA&lt;br /&gt;
KPK            XND20          P17            TS_THALER_DATA&lt;br /&gt;
KPK            XND20          P18            TS_THALER_DATA&lt;br /&gt;
KPK            XND20          PMAX           TS_THALER_DATA&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Solution====&lt;br /&gt;
If the intention is to keep all the tables then run this query to generate statements to move the relevant tables out of this tablespace&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select &amp;#039;alter table &amp;#039;||b.table_owner||&amp;#039;.&amp;#039;||b.table_name||&amp;#039; move partition &amp;#039;||b.partition_name||&amp;#039; tablespace &amp;amp;NEW_TABLESPACE;&amp;#039;&lt;br /&gt;
from   (&lt;br /&gt;
       select distinct table_name&lt;br /&gt;
       ,      partition_name&lt;br /&gt;
       from   dba_tab_partitions&lt;br /&gt;
       where  tablespace_name = &amp;#039;&amp;amp;&amp;amp;TABLESPACE_NAME&amp;#039;&lt;br /&gt;
       )                  a&lt;br /&gt;
,      dba_tab_partitions b&lt;br /&gt;
where  a.table_name       = b.table_name&lt;br /&gt;
and    b.tablespace_name != &amp;#039;&amp;amp;TABLESPACE_NAME&amp;#039;&lt;br /&gt;
/&lt;br /&gt;
undef TABLESPACE_NAME&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
If however, the intention is to drop the tablespace anyway, the tables need to be dropped before the tablespace can be dropped.&amp;lt;br /&amp;gt;&lt;br /&gt;
But ...tables with partitions in different tablespaces cannot be dropped. The partitions need to be dropped first!&amp;lt;br /&amp;gt;&lt;br /&gt;
Run the following query to generate statements to drop all the &amp;#039;problem&amp;#039; tables. When these have gone, the tablespace can be dropped.&lt;br /&gt;
* drop table partitions&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
spool /tmp/drop_table_partitions.sql&lt;br /&gt;
sqlplus / as sysdba&amp;lt;&amp;lt;EOSQL&lt;br /&gt;
set headi off newpa none feedb off trims on echo off&lt;br /&gt;
select &amp;#039;alter table &amp;#039;||table_owner||&amp;#039;.&amp;#039;||table_name||&amp;#039; drop partition &amp;#039;||partition_name||&amp;#039;;&amp;#039;&lt;br /&gt;
from   dba_tab_partitions&lt;br /&gt;
where  tablespace_name = &amp;#039;$TABLESPACE_NAME&amp;#039;&lt;br /&gt;
/&lt;br /&gt;
spool off&lt;br /&gt;
EOSQL&lt;br /&gt;
echo &amp;quot;@/tmp/drop_table_partitions.sql&amp;quot; | sqlplus / as sysdba&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* drop tables&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sqlplus / as sysdba&amp;lt;&amp;lt;EOSQL&lt;br /&gt;
select &amp;#039;drop table &amp;#039;||table_owner||&amp;#039;.&amp;#039;||table_name||&amp;#039;;&amp;#039;&lt;br /&gt;
from   dba_tab_partitions&lt;br /&gt;
where  tablespace_name = &amp;#039;$TABLESPACE_NAME&amp;#039;&lt;br /&gt;
spool /tmp/drop_tables.sql&lt;br /&gt;
/&lt;br /&gt;
spool off&lt;br /&gt;
EOSQL&lt;br /&gt;
echo &amp;quot;@/tmp/drop_tables.sql&amp;quot; | sqlplus / as sysdba&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* drop tablespace&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
drop tablespace ads_archive including contents and datafiles&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Find all table partitions in tablespaces with missing datafiles====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 1000 pages 100&lt;br /&gt;
col owner for a10&lt;br /&gt;
col segment_name for a40&lt;br /&gt;
col segment_type for a25&lt;br /&gt;
col partition_name for a20&lt;br /&gt;
col tablespace_name for a25&lt;br /&gt;
select owner&lt;br /&gt;
,      segment_name&lt;br /&gt;
,      segment_type&lt;br /&gt;
,      partition_name&lt;br /&gt;
,      tablespace_name&lt;br /&gt;
from   dba_segments&lt;br /&gt;
where  segment_type in (&amp;#039;TABLE PARTITION&amp;#039;, &amp;#039;TABLE SUBPARTITION&amp;#039;)&lt;br /&gt;
and    tablespace_name in (&lt;br /&gt;
                          select tablespace_name&lt;br /&gt;
                          from   dba_data_files&lt;br /&gt;
                          where  file_name like &amp;#039;%MISSING%&amp;#039;&lt;br /&gt;
                          )&lt;br /&gt;
order  by 1, 2, decode (segment_type, &amp;#039;TABLE SUBPARTITION&amp;#039;, 1, 2),4&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Use exchange partition to alter metadata of the tablespaces without moving the actual data====&lt;br /&gt;
* [https://community.oracle.com/thread/581401?start=15&amp;amp;tstart=0 this] is what you are looking for!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Workaround====&lt;br /&gt;
While working on the solution, a backup can be made using the &amp;quot;skip inaccessible&amp;quot; option. Put this in an rman cmdfile...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
connect catalog rmanusr/rmanpwd@rmancat&lt;br /&gt;
connect target sys/syspwd@adsa1&lt;br /&gt;
run {&lt;br /&gt;
allocate channel t1 type &amp;#039;sbt_tape&amp;#039; parms &amp;#039;ENV=(NSR_SERVER=hn6000.company.be,NSR_CLIENT=hn491,NSR_DATA_VOLUME_POOL=DD1DAILY,NSR_END_ERROR_IGNORE=TRUE)&amp;#039;;&lt;br /&gt;
allocate channel t2 type &amp;#039;sbt_tape&amp;#039; parms &amp;#039;ENV=(NSR_SERVER=hn6000.company.be,NSR_CLIENT=hn491,NSR_DATA_VOLUME_POOL=DD1DAILY,NSR_END_ERROR_IGNORE=TRUE)&amp;#039;;&lt;br /&gt;
configure retention policy to recovery window of 28 days;&lt;br /&gt;
configure controlfile autobackup on;&lt;br /&gt;
crosscheck archivelog all;&lt;br /&gt;
SQL &amp;#039;ALTER SYSTEM SWITCH LOGFILE&amp;#039;;&lt;br /&gt;
SQL &amp;#039;CREATE PFILE FROM SPFILE&amp;#039;;&lt;br /&gt;
backup filesperset 1 format &amp;#039;dbfull_%d_%I_%t_%s_%p&amp;#039; full database plus archivelog skip inaccessible delete all input;&lt;br /&gt;
backup current controlfile;&lt;br /&gt;
release channel t1;&lt;br /&gt;
release channel t2;&lt;br /&gt;
}&lt;br /&gt;
exit&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Another way of deleting the offending objects====&lt;br /&gt;
Taken from [http://www.dbarj.com.br/en/2015/01/resume-oracle-duplicate-database-failed-recovery-datafiles/ Recover from a failed RMAN duplicate]&amp;lt;br /&amp;gt;&lt;br /&gt;
Need to check it before running it blindly!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
set echo off feed off termo off trims on pages 0 newpa none lines 2000 headi off long 32000&lt;br /&gt;
col val for a1000&lt;br /&gt;
spool destroy_offending_objects.sql&lt;br /&gt;
&lt;br /&gt;
select to_clob (&amp;#039;alter table &amp;#039;|| table_name||&amp;#039; drop constraint &amp;#039;||constraint_name||&amp;#039;;&amp;#039;) Val&lt;br /&gt;
from user_constraints where constraint_type in (&amp;#039;R&amp;#039;,&amp;#039;P&amp;#039;) and table_name in (select distinct table_name from user_tab_partitions)&lt;br /&gt;
union all&lt;br /&gt;
select to_clob (&amp;#039;drop index &amp;#039;||index_name||&amp;#039;;&amp;#039;) Val from user_indexes where table_name in (select distinct table_name from user_tab_partitions)&lt;br /&gt;
union all&lt;br /&gt;
select to_clob (&amp;#039;alter table &amp;#039;||table_name|| &amp;#039; drop partition &amp;#039;||partition_name||&amp;#039;;&amp;#039;) from dba_tab_partitions&lt;br /&gt;
where tablespace_name in (select tablespace_name from dba_data_files where file_name like &amp;#039;%MISSING%&amp;#039;)&lt;br /&gt;
union all&lt;br /&gt;
Select case&lt;br /&gt;
when instr (VAl, &amp;#039;PARTITION&amp;#039;) = 0 Then&lt;br /&gt;
substr (Val,1,InStr (Val,&amp;#039;)&amp;#039;)+1)||&amp;#039;;&amp;#039;&lt;br /&gt;
else&lt;br /&gt;
substr (Val,1,InStr (Val,&amp;#039;)&amp;#039;)+1)||&amp;#039; local;&amp;#039;&lt;br /&gt;
End val&lt;br /&gt;
from&lt;br /&gt;
(select dbms_metadata.get_ddl (&amp;#039;INDEX&amp;#039;, index_name,&amp;#039;TEST&amp;#039;) Val from user_indexes where table_name in (select distinct table_name from user_tab_partitions))&lt;br /&gt;
union all&lt;br /&gt;
Select Val&lt;br /&gt;
from&lt;br /&gt;
(select dbms_metadata.get_dependent_ddl (&amp;#039;REF_CONSTRAINT&amp;#039;, table_name,&amp;#039;TEST&amp;#039;) Val&lt;br /&gt;
from user_tables where table_name in (select distinct table_name from user_tab_partitions join user_constraints using ( table_name)&lt;br /&gt;
where constraint_type=&amp;#039;R&amp;#039;))&lt;br /&gt;
union all&lt;br /&gt;
select Val&lt;br /&gt;
from&lt;br /&gt;
(select dbms_metadata.get_ddl (&amp;#039;CONSTRAINT&amp;#039;, constraint_name,&amp;#039;TEST&amp;#039;) Val&lt;br /&gt;
from user_constraints&lt;br /&gt;
where constraint_type=&amp;#039;P&amp;#039; and table_name in (select distinct table_name from user_tab_partitions)&lt;br /&gt;
)&lt;br /&gt;
union all&lt;br /&gt;
select to_clob (val)&lt;br /&gt;
from (select distinct &amp;#039;drop tablespace &amp;#039;||tablespace_name|| &amp;#039; including contents and datafiles;&amp;#039; val&lt;br /&gt;
from dba_tab_partitions&lt;br /&gt;
where tablespace_name in (select tablespace_name from dba_data_files where file_name like &amp;#039;%MISSING%&amp;#039;)&lt;br /&gt;
);&lt;br /&gt;
&lt;br /&gt;
spoo off&lt;br /&gt;
&lt;br /&gt;
@destroy_offending_objects&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORA-28112: failed to execute policy function===&lt;br /&gt;
when exporting or importing using [[Data Pump]]&amp;lt; /br&amp;gt;&lt;br /&gt;
During expdp is accompanied by &amp;quot;&amp;#039;&amp;#039;&amp;#039;ORA-31693: Table data object &amp;quot;SYSMAN&amp;quot;.&amp;quot;MGMT_IP_REPORT_DEF&amp;quot; failed to load/unload and is being skipped due to error:&amp;#039;&amp;#039;&amp;#039;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
===Reason===&lt;br /&gt;
This happens due to audit policies being defined on the table but the policy function is defined in another schema.&lt;br /&gt;
&lt;br /&gt;
===Solution===&lt;br /&gt;
Either drop the policy after importing the table with:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
begin&lt;br /&gt;
    for rec in (select * from dba_audit_policies where object_schema = &amp;#039;SYSMAN&amp;#039;) loop&lt;br /&gt;
        dbms_fga.drop_policy(object_schema =&amp;gt; rec.object_schema,&lt;br /&gt;
                             object_name =&amp;gt; rec.object_name,&lt;br /&gt;
                             policy_name =&amp;gt; rec.policy_name);  &lt;br /&gt;
    end loop;&lt;br /&gt;
end;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or exclude the policies during export by adding this to the .par file:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
exclude=FGA_POLICY&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or even better, give the necessary grants to the exporting user...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
grant exempt access policy to impexpusr;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The sysdba role has this automatically.&lt;br /&gt;
===ORA-17629: Cannot connect to the remote database server===&lt;br /&gt;
Active duplication fails to connect even though dns connection exists in tnsnames.ora&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
Problem:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
DUPLICATE TARGET DATABASE FROM ACTIVE DATABASE DORECOVER NOFILENAMECHECK;&lt;br /&gt;
&lt;br /&gt;
RMAN-03002: failure of Duplicate Db command at 05/27/2015 12:52:24&lt;br /&gt;
RMAN-05501: aborting duplication of target database&lt;br /&gt;
RMAN-03015: error occurred in stored script Memory Script&lt;br /&gt;
RMAN-03009: failure of backup command on ORA_DISK_1 channel at 05/27/2015 12:52:23&lt;br /&gt;
ORA-17629: Cannot connect to the remote database server&lt;br /&gt;
ORA-17627: ORA-12154: TNS:could not resolve the connect identifier specified&lt;br /&gt;
&lt;br /&gt;
ORA-17629: Cannot connect to the remote database server&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
Solution:&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
Update the tnsnames.ora of both destination &amp;#039;&amp;#039;&amp;#039;and&amp;#039;&amp;#039;&amp;#039; source ORACLE_HOMEs!&lt;br /&gt;
&lt;br /&gt;
===ORA-01950: no privileges on tablespace &amp;#039;SYSAUX&amp;#039;===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
26-JUN-15 03:12:27.545: &amp;gt;&amp;gt;&amp;gt; ORA-31642: the following SQL statement fails: &lt;br /&gt;
BEGIN &amp;quot;SYS&amp;quot;.&amp;quot;DBMS_RULE_EXP_RULES&amp;quot;.SCHEMA_CALLOUT(:1,0,1,&amp;#039;12.01.00.02.00&amp;#039;); END;&lt;br /&gt;
ORA-01950: no privileges on tablespace &amp;#039;SYSAUX&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Cause:&amp;#039;&amp;#039;&amp;#039;&amp;lt;br /&amp;gt;&lt;br /&gt;
In this case, it seems SYSMAN has no rights to create objects in the SYSAUX tablespace&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Solution:&amp;#039;&amp;#039;&amp;#039;&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter user SYSMAN quota unlimited on sysaux;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
More information [https://support.oracle.com/epmos/faces/SearchDocDisplay?_adf.ctrl-state=bov7jp5pq_4&amp;amp;_afrLoop=547371065896716#SYMPTOM here]&lt;br /&gt;
&lt;br /&gt;
===ORA-39080: failed to create queues &amp;quot;KUPC$C_1_20150616165037&amp;quot; and &amp;quot;KUPC$S_1_20150616165037&amp;quot; for Data Pump job===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
expdp /&lt;br /&gt;
&lt;br /&gt;
Export: Release 11.2.0.4.0 - Production on Tue Jun 16 16:50:36 2015&lt;br /&gt;
&lt;br /&gt;
Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.&lt;br /&gt;
&lt;br /&gt;
Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production&lt;br /&gt;
With the Partitioning, OLAP, Data Mining and Real Application Testing options&lt;br /&gt;
ORA-31626: job does not exist&lt;br /&gt;
ORA-31637: cannot create job SYS_EXPORT_SCHEMA_01 for user OPS$ORAIBM&lt;br /&gt;
ORA-06512: at &amp;quot;SYS.DBMS_SYS_ERROR&amp;quot;, line 95&lt;br /&gt;
ORA-06512: at &amp;quot;SYS.KUPV$FT_INT&amp;quot;, line 798&lt;br /&gt;
[[ORA-39080: failed to create queues &amp;quot;KUPC$C_1_20150616165037&amp;quot; and &amp;quot;KUPC$S_1_20150616165037&amp;quot; for Data Pump job]]&lt;br /&gt;
ORA-06512: at &amp;quot;SYS.DBMS_SYS_ERROR&amp;quot;, line 95&lt;br /&gt;
ORA-06512: at &amp;quot;SYS.KUPC$QUE_INT&amp;quot;, line 1534&lt;br /&gt;
ORA-24002: QUEUE_TABLE SYS.AQ$KUPC$DATAPUMP_QUETAB_1 does not exist&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Cause:====&lt;br /&gt;
Possibly some or all of OLAP module has got itself deinstalled.&lt;br /&gt;
====Solution:====&lt;br /&gt;
Try:&lt;br /&gt;
* Recompiling invalid objects. @?/rdbms/admin/utlrp&lt;br /&gt;
* Reinstalling DBMS_CUBE packages by (re)running catproc.sql. @?/rdbms/admin/catproc followed by @?/rdbms/admin/utlrp&lt;br /&gt;
* Reinstalling OLAP. @?/olap/admin/olap.sql SYSAUX TEMP; But see Metalink note ID 296187.1 for full instructions.&lt;br /&gt;
* Check metalink for bugs. See ID 345198.1 and possibly ID 453796.1&lt;br /&gt;
===ORA-14063: Unusable index exists on unique/primary constraint key===&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;ORA-39083: Object type CONSTRAINT failed to create with error:&amp;#039;&amp;#039;&amp;#039;&amp;lt;br /&amp;gt;&lt;br /&gt;
During an import datapump (impdp), import failed because indexes were in error before the tables were exported. This causes the import of rows to be skipped.&amp;lt;br /&amp;gt;&lt;br /&gt;
If the export cannot be done again (having compiled the indexes), then the metadata can be imported and the indexes compiled before importing the data.&lt;br /&gt;
* Import the metadata&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cat&amp;lt;&amp;lt;EOCAT &amp;gt;impdp_adst_ads_archive_metadata.par&lt;br /&gt;
userid=&amp;#039;/ as sysdba&amp;#039;&lt;br /&gt;
dumpfile=adst_ads_archive.dmp&lt;br /&gt;
logfile=impdp_adst_ads_archive_metadata.log&lt;br /&gt;
content=metadata_only&lt;br /&gt;
EOCAT&lt;br /&gt;
&lt;br /&gt;
impdp parfile=impdp_adst_ads_archive_metadata.par&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Find the bad indexes and recompile them&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select &amp;#039;alter index &amp;#039;|| owner||&amp;#039;.&amp;#039;||index_name||&amp;#039; rebuild online parallel 8;&amp;#039;&lt;br /&gt;
from   dba_indexes&lt;br /&gt;
where  status = &amp;#039;UNUSABLE&amp;#039;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Import the data&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cat&amp;lt;&amp;lt;EOCAT &amp;gt;impdp_adst_ads_archive_data.par&lt;br /&gt;
userid=&amp;#039;/ as sysdba&amp;#039;&lt;br /&gt;
dumpfile=adst_ads_archive.dmp&lt;br /&gt;
logfile=impdp_adst_ads_archive_data.log&lt;br /&gt;
table_exists_action=append&lt;br /&gt;
content=data_only&lt;br /&gt;
EOCAT&lt;br /&gt;
&lt;br /&gt;
impdp parfile=impdp_adst_ads_archive_data.par&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORA-09925: Unable to create audit trail file===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SQL&amp;gt; startup nomount pfile=&amp;quot;/oracle/TRSCRP1/admin/initTRSCRP1.ora&amp;quot;&lt;br /&gt;
ORA-09925: Unable to create audit trail file&lt;br /&gt;
SVR4 Error: 2: No such file or directory&lt;br /&gt;
Additional information: 9925&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
connected to auxiliary database (not started)&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-03002: failure of Duplicate Db command at 08/29/2017 15:53:09&lt;br /&gt;
RMAN-05501: aborting duplication of target database&lt;br /&gt;
RMAN-03015: error occurred in stored script Memory Script&lt;br /&gt;
RMAN-04014: startup failed: ORA-09925: Unable to create audit trail file&lt;br /&gt;
IBM AIX RISC System/6000 Error: 2: No such file or directory&lt;br /&gt;
Additional information: 9925&lt;br /&gt;
&lt;br /&gt;
Recovery Manager complete.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Problem====&lt;br /&gt;
This will be almost certainly one of two issues. Either the directory is not writable by the id that started the instance or the directory just does not exist.&lt;br /&gt;
====Solution====&lt;br /&gt;
Note there can be a difference between what you see when you type:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
show parameter audit&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
and when you type:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
strings -a $ORACLE_HOME/dbs/spfile${ORACLE_SID}.ora | grep -i audit&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
due to someone doing an &amp;quot;alter system&amp;quot; without the &amp;quot;scope=spfile&amp;quot; or &amp;quot;scope=both&amp;quot;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SQL&amp;gt; host ls -al /oracle/TRSCRP1/admin/adump&lt;br /&gt;
SQL&amp;gt; host mkdir /oracle/TRSCRP1/admin/adump&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===ORA-09925: Unable to create audit trail file===&lt;br /&gt;
When starting SQL*Plus with no db processes running (expecting to see &amp;quot;Connected to an idle instance&amp;quot;), we get this:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ERROR:&lt;br /&gt;
ORA-09925: Unable to create audit trail file&lt;br /&gt;
IBM AIX RISC System/6000 Error: 2: No such file or directory&lt;br /&gt;
Additional information: 9925&lt;br /&gt;
ORA-01075: you are currently logged on&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Filesystem permissions are fine&lt;br /&gt;
* &amp;#039;strings spfile&amp;lt;SID&amp;gt;.ora | grep audit&amp;#039; shows the correct directory&lt;br /&gt;
* Running on AIX&lt;br /&gt;
AIX is the clue here... need to check for semaphores and locked shared memory objects&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
(0) UCLID55D oraibm@solax082:/oracle/product/11.2.0.3/bin&amp;gt; sysresv&lt;br /&gt;
&lt;br /&gt;
IPC Resources for ORACLE_SID &amp;quot;UCLID55D&amp;quot; :&lt;br /&gt;
Shared Memory:&lt;br /&gt;
ID              KEY&lt;br /&gt;
8388640         0xffffffff&lt;br /&gt;
579862561       0xffffffff&lt;br /&gt;
384827426       0x326f32e8&lt;br /&gt;
&lt;br /&gt;
Semaphores:&lt;br /&gt;
ID              KEY&lt;br /&gt;
167772287       0xf09f4914&lt;br /&gt;
Oracle Instance alive for sid &amp;quot;UCLID55D&amp;quot;&lt;br /&gt;
&lt;br /&gt;
(0) UCLID55D oraibm@solax082:/oracle/product/11.2.0.3/bin&amp;gt; ipcrm -m 8388640&lt;br /&gt;
(0) UCLID55D oraibm@solax082:/oracle/product/11.2.0.3/bin&amp;gt; ipcrm -m 579862561&lt;br /&gt;
(0) UCLID55D oraibm@solax082:/oracle/product/11.2.0.3/bin&amp;gt; ipcrm -m 384827426&lt;br /&gt;
&lt;br /&gt;
(0) UCLID55D oraibm@solax082:/oracle/product/11.2.0.3/bin&amp;gt; ipcrm -s 167772287&lt;br /&gt;
&lt;br /&gt;
(0) UCLID55D oraibm@solax082:/oracle/product/11.2.0.3/bin&amp;gt; sysresv&lt;br /&gt;
&lt;br /&gt;
IPC Resources for ORACLE_SID &amp;quot;UCLID55D&amp;quot; :&lt;br /&gt;
Shared Memory&lt;br /&gt;
ID              KEY&lt;br /&gt;
No shared memory segments used&lt;br /&gt;
Semaphores:&lt;br /&gt;
ID              KEY&lt;br /&gt;
No semaphore resources used&lt;br /&gt;
Oracle Instance not alive for sid &amp;quot;UCLID55D&amp;quot;&lt;br /&gt;
&lt;br /&gt;
(0) UCLID55D oraibm@solax082:/oracle/product/11.2.0.3/bin&amp;gt; ps -ef | grep UCLID55D&lt;br /&gt;
oraibm 3326 23776 0 14:12:05 pts/1 0:00 grep UCLID55D &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===RMAN-06023: no backup or copy of datafile 1 found to restore===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-03002: failure of Duplicate Db command at 05/16/2018 16:08:13&lt;br /&gt;
RMAN-05501: aborting duplication of target database&lt;br /&gt;
RMAN-05556: not all datafiles have backups that can be recovered to SCN 278250901080&lt;br /&gt;
RMAN-03015: error occurred in stored script Memory Script&lt;br /&gt;
RMAN-06026: some targets not found - aborting restore&lt;br /&gt;
RMAN-06023: no backup or copy of datafile 7 found to restore&lt;br /&gt;
RMAN-06023: no backup or copy of datafile 6 found to restore&lt;br /&gt;
RMAN-06023: no backup or copy of datafile 5 found to restore&lt;br /&gt;
RMAN-06023: no backup or copy of datafile 4 found to restore&lt;br /&gt;
RMAN-06023: no backup or copy of datafile 3 found to restore&lt;br /&gt;
RMAN-06023: no backup or copy of datafile 2 found to restore&lt;br /&gt;
RMAN-06023: no backup or copy of datafile 1 found to restore&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Seems pretty straightforward? SCN was set too early for the retention period. But no, not this time.&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
RMAN&amp;gt; list backup of datafile 1;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
List of Backup Sets&lt;br /&gt;
===================&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
BS Key  Type LV Size       Device Type Elapsed Time Completion Time&lt;br /&gt;
------- ---- -- ---------- ----------- ------------ -------------------&lt;br /&gt;
110170340 Incr 0  132.90G    SBT_TAPE    00:18:32     2018-05-14 01:19:40&lt;br /&gt;
        BP Key: 110170345   Status: AVAILABLE  Compressed: NO  Tag: WEEKLY_FULL&lt;br /&gt;
        Handle: 24639762_REPORTA_07t2r3uk_1_1   Media: V_17152809_77191330&lt;br /&gt;
  List of Datafiles in backup set 110170340&lt;br /&gt;
  File LV Type Ckp SCN    Ckp Time            Name&lt;br /&gt;
  ---- -- ---- ---------- ------------------- ----&lt;br /&gt;
  1    0  Incr 277998128991 2018-05-14 01:01:08 /cln/acc/ora_data3/reporta/system01.dbf&lt;br /&gt;
&lt;br /&gt;
BS Key  Type LV Size       Device Type Elapsed Time Completion Time&lt;br /&gt;
------- ---- -- ---------- ----------- ------------ -------------------&lt;br /&gt;
110355808 Incr 1  204.00M    SBT_TAPE    00:05:13     2018-05-15 01:06:22&lt;br /&gt;
        BP Key: 110355813   Status: AVAILABLE  Compressed: NO  Tag: DAILY_INCREMENTAL&lt;br /&gt;
        Handle: 24661053_REPORTA_3ft2toal_1_1   Media: V_17173010_77253424&lt;br /&gt;
  List of Datafiles in backup set 110355808&lt;br /&gt;
  File LV Type Ckp SCN    Ckp Time            Name&lt;br /&gt;
  ---- -- ---- ---------- ------------------- ----&lt;br /&gt;
  1    1  Incr 278044267395 2018-05-15 01:01:09 /cln/acc/ora_data3/reporta/system01.dbf&lt;br /&gt;
&lt;br /&gt;
BS Key  Type LV Size       Device Type Elapsed Time Completion Time&lt;br /&gt;
------- ---- -- ---------- ----------- ------------ -------------------&lt;br /&gt;
110543802 Incr 1  237.00M    SBT_TAPE    00:05:51     2018-05-16 01:07:40&lt;br /&gt;
        BP Key: 110543807   Status: AVAILABLE  Compressed: NO  Tag: DAILY_INCREMENTAL&lt;br /&gt;
        Handle: 24681602_REPORTA_6nt30cnt_1_1   Media: V_17133646_77315270&lt;br /&gt;
  List of Datafiles in backup set 110543802&lt;br /&gt;
  File LV Type Ckp SCN    Ckp Time            Name&lt;br /&gt;
  ---- -- ---- ---------- ------------------- ----&lt;br /&gt;
  1    1  Incr 278286445856 2018-05-16 01:01:50 /cln/acc/ora_data3/reporta/system01.dbf&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
SCN was only 12 hours ago with a retention of 28 days! The backup piece dated 2018-05-15 01:06:22 is clearly available and on the device type set_tape.&amp;lt;br /&amp;gt;&lt;br /&gt;
The trick here was to look back through the logs and look more closely at what the file restore message was saying...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
channel t0: starting datafile backup set restore&lt;br /&gt;
channel t0: specifying datafile(s) to restore from backup set&lt;br /&gt;
channel t0: restoring datafile 00001 to /cln/acc/ora_data3/reporta/system01.dbf             &amp;lt; &amp;lt; &amp;lt; ==============&lt;br /&gt;
channel t0: reading from backup piece dbfull_REPORTA_738887052_967580186_116_1&lt;br /&gt;
channel t2: ORA-19870: error while restoring backup piece dbfull_REPORTA_738887052_967579750_113_1&lt;br /&gt;
ORA-19507: failed to retrieve sequential file, handle=&amp;quot;dbfull_REPORTA_738887052_967579750_113_1&amp;quot;, parms=&amp;quot;&amp;quot;&lt;br /&gt;
ORA-27029: skgfrtrv: sbtrestore returned error&lt;br /&gt;
ORA-19511: non RMAN, but media manager or vendor specific failure, error text:&lt;br /&gt;
   CreateOraObject20: Job[0] thread[55116090]: Restore: GetBackupInfo() for Archive File[dbfull_REPORTA_738887052_967579750_113_1] failed.&lt;br /&gt;
ORA-0651&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
It was not the fact that it could not find the data on tape, it was that it could not save the file to the location indicated!!&lt;br /&gt;
In the RMAN DUPLICATE script, I had all the file paths redirected (a mixture of convert parameters and spfile set) to a /restore filesystem.&amp;lt;br /&amp;gt;&lt;br /&gt;
But I forgot one!&amp;lt;br /&amp;gt;&lt;br /&gt;
A handy thing to do is to search out the file paths with this to see if something is still wrong:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cd $ORACLE_HOME/dbs&lt;br /&gt;
strings -a spfile${ORACLE_SID}.ora | grep dest&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This should show any paths still not getting caught by the DUPLICATE script.&lt;br /&gt;
&lt;br /&gt;
===RMAN-06136: ORACLE error from auxiliary database: ORA-06502: PL/SQL: numeric or value error===&lt;br /&gt;
When cloning a database, the duplicate fails with this error.&lt;br /&gt;
====Problem====&lt;br /&gt;
This duplicate had no target connection but did have a catalog and auxiliary connection.&lt;br /&gt;
In the catalog (which was the catalog where the target was registerd), there was also an entry in that catalog with the same name as the auxiliary - left over from the days when these 2 instances were Primary and Standby in a Dataguard configuration.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
Datafile 414 skipped by request&lt;br /&gt;
Datafile 415 skipped by request&lt;br /&gt;
Datafile 419 skipped by request&lt;br /&gt;
Datafile 420 skipped by request&lt;br /&gt;
Datafile 421 skipped by request&lt;br /&gt;
&lt;br /&gt;
DBGSQL:     AUXILIARY&amp;gt; begin :ofname := sys.dbms_backup_restore.convertFileName( fname   =&amp;gt;   :ifname, ftype   =&amp;gt;   :iftype, osftype =&amp;gt;   TRUE); end;&lt;br /&gt;
DBGSQL:        sqlcode = 6502&lt;br /&gt;
DBGSQL:         B :ofname = NULL&lt;br /&gt;
DBGSQL:         B :ifname =&lt;br /&gt;
DBGSQL:         B :iftype = 2&lt;br /&gt;
restarting auxiliary database without server parameter file&lt;br /&gt;
Oracle instance started&lt;br /&gt;
&lt;br /&gt;
Total System Global Area   32068440064 bytes&lt;br /&gt;
&lt;br /&gt;
Fixed Size                     2262200 bytes&lt;br /&gt;
Variable Size              16978545480 bytes&lt;br /&gt;
Database Buffers           15032385536 bytes&lt;br /&gt;
Redo Buffers                  55246848 bytes&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-03002: failure of Duplicate Db command at 10/04/2017 14:50:29&lt;br /&gt;
RMAN-05501: aborting duplication of target database&lt;br /&gt;
RMAN-06136: ORACLE error from auxiliary database: ORA-06502: PL/SQL: numeric or value error&lt;br /&gt;
&lt;br /&gt;
Recovery Manager complete.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Solution====&lt;br /&gt;
Connect to the catalog and unregister the name of the auxiliary database. It shouldn&amp;#039;t be there anyway.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rman catalog rmanusr/rmanpwd@rmancat&lt;br /&gt;
&lt;br /&gt;
Recovery Manager: Release 11.2.0.4.0 - Production on Wed Oct 4 15:00:00 2017&lt;br /&gt;
&lt;br /&gt;
Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.&lt;br /&gt;
&lt;br /&gt;
connected to recovery catalog database&lt;br /&gt;
&lt;br /&gt;
RMAN&amp;gt; set dbid 4260753020;&lt;br /&gt;
&lt;br /&gt;
executing command: SET DBID&lt;br /&gt;
database name is &amp;quot;LBK&amp;quot; and DBID is 4260753020&lt;br /&gt;
&lt;br /&gt;
RMAN&amp;gt; list db_unique_name of database;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
List of Databases&lt;br /&gt;
DB Key  DB Name  DB ID            Database Role    Db_unique_name&lt;br /&gt;
------- ------- ----------------- ---------------  ------------------&lt;br /&gt;
13301587 LBK      4260753020       PRIMARY          LBK&lt;br /&gt;
13301587 LBK      4260753020       STANDBY          ACC_PERF&lt;br /&gt;
13301587 LBK      4260753020       STANDBY          LBKRO&lt;br /&gt;
&lt;br /&gt;
RMAN&amp;gt; unregister db_unique_name &amp;#039;ACC_PERF&amp;#039;;&lt;br /&gt;
&lt;br /&gt;
database db_unique_name is &amp;quot;ACC_PERF&amp;quot;, db_name is &amp;quot;LBK&amp;quot; and DBID is 4260753020&lt;br /&gt;
&lt;br /&gt;
Want to unregister the database with target db_unique_name (enter YES or NO)? YES&lt;br /&gt;
database with db_unique_name ACC_PERF unregistered from the recovery catalog&lt;br /&gt;
&lt;br /&gt;
RMAN&amp;gt; exit&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORA-39181: Only partial table data may be exported due to fine grain access control on &amp;quot;owner&amp;quot;.&amp;quot;&amp;lt;table_name&amp;gt;&amp;quot;===&lt;br /&gt;
&lt;br /&gt;
===Reason===&lt;br /&gt;
This happens when applications are designed with fine-grained access.&lt;br /&gt;
===Solution===&lt;br /&gt;
Grant the necessary privileges to the exporting user...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
grant exempt access policy to ops$oraibm;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORA-04030: out of process memory when trying to allocate 2520 bytes===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
expdp problem (ORA-04030: out of process memory when trying to allocate 2520 bytes (pga heap,koh-kghu call heap))&lt;br /&gt;
&lt;br /&gt;
select value from v$pgastat where name=&amp;#039;maximum PGA allocated&amp;#039;;&lt;br /&gt;
&lt;br /&gt;
SHOW PARAMETER TARGET&lt;br /&gt;
&lt;br /&gt;
ORA-04030: out of process memory when trying to allocate 2520 bytes (pga heap,koh-kghu call heap)&lt;br /&gt;
&lt;br /&gt;
alter system reset pga_aggregate_target scope=spfile;&lt;br /&gt;
&lt;br /&gt;
show sga&lt;br /&gt;
&lt;br /&gt;
select * from v$pgastat;&lt;br /&gt;
&lt;br /&gt;
show parameter process&lt;br /&gt;
&lt;br /&gt;
select sum(value)/1024/1024 Mb&lt;br /&gt;
from   v$sesstat s, v$statname n&lt;br /&gt;
where  1=1&lt;br /&gt;
and    n.STATISTIC# = s.STATISTIC#&lt;br /&gt;
and    name = &amp;#039;session pga memory&amp;#039;&lt;br /&gt;
&lt;br /&gt;
show parameter WORKAREA&lt;br /&gt;
&lt;br /&gt;
select value from v$pgastat where name=&amp;#039;maximum PGA allocated&amp;#039;;&lt;br /&gt;
&lt;br /&gt;
alter system set memory_max_target=10G scope=spfile;&lt;br /&gt;
&lt;br /&gt;
alter system set memory_target=3G scope=both;&lt;br /&gt;
&lt;br /&gt;
select * from v$memory_target_advice order by memory_size;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORA-04031: unable to allocate 32 bytes of shared memory (&amp;quot;shared pool&amp;quot;,&amp;quot;select name,online$,contents...&amp;quot;,&amp;quot;KGLH0^e5705bfc&amp;quot;,&amp;quot;kglHeapInitialize:temp&amp;quot;)===&lt;br /&gt;
* [https://blogs.oracle.com/db/entry/ora-4031_troubleshooting ORA-4031 Troubleshooting]&lt;br /&gt;
* [https://support.oracle.com/epmos/faces/DocumentDisplay?_afrLoop=89215376348478&amp;amp;id=396940.1&amp;amp;_afrWindowMode=0&amp;amp;_adf.ctrl-state=u1z0xcppg_4 Troubleshooting and Diagnosing ORA-4031 Error - (Doc ID 396940.1)]&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ORA-04031: unable to allocate  bytes of shared memory (&amp;quot;&amp;quot;,&amp;quot;&amp;quot;,&amp;quot;&amp;quot;,&amp;quot;&amp;quot;) &lt;br /&gt;
ORA-04031: unable to allocate 32 bytes of shared memory (&amp;quot;shared pool&amp;quot;,&amp;quot;select name,online$,contents...&amp;quot;,&amp;quot;KGLH0^e5705bfc&amp;quot;,&amp;quot;kglHeapInitialize:temp&amp;quot;) &lt;br /&gt;
Incident details in: /oracle/diag/rdbms/mape/MAPE/incident/incdir_86754/MAPE_dm00_14221536_i86754.trc &lt;br /&gt;
Wed Jul 31 20:42:50 2013 &lt;br /&gt;
Dumping diagnostic data in directory=[cdmp_20130731204250], requested by (instance=1, osid=14221536 (DM00)), summary=[incident=86753]. &lt;br /&gt;
Wed Jul 31 20:42:51 2013 &lt;br /&gt;
Sweep [inc][86754]: completed &lt;br /&gt;
Sweep [inc][86753]: completed &lt;br /&gt;
Sweep [inc2][86753]: completed &lt;br /&gt;
Wed Jul 31 20:42:57 2013 &lt;br /&gt;
Use ADRCI or Support Workbench to package the incident. &lt;br /&gt;
See Note 411.1 at My Oracle Support for error and packaging details. &lt;br /&gt;
Dumping diagnostic data in directory=[cdmp_20130731204257], requested by (instance=1, osid=14221536 (DM00)), summary=[incident=86754]. &lt;br /&gt;
Wed Jul 31 20:43:35 2013 &lt;br /&gt;
Errors in file /oracle/diag/rdbms/mape/MAPE/trace/MAPE_dw02_40567024.trc  (incident=82993): &lt;br /&gt;
ORA-04031: unable to allocate 32 bytes of shared memory (&amp;quot;shared pool&amp;quot;,&amp;quot;select order#,columns,types ...&amp;quot;,&amp;quot;KGLH0^470434f8&amp;quot;,&amp;quot;kglHeapInitialize:temp&amp;quot;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Database had already crashed so nothing to do but:&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
(0) MAPE ora@x025:/home/ora&amp;gt; sqlplus / as sysdba&lt;br /&gt;
&lt;br /&gt;
SQL*Plus: Release 11.2.0.3.0 Production on Fri Aug 2 14:26:20 2013&lt;br /&gt;
&lt;br /&gt;
Copyright (c) 1982, 2011, Oracle.  All rights reserved.&lt;br /&gt;
&lt;br /&gt;
Connected.&lt;br /&gt;
SYS@MAPE&amp;gt; alter system flush shared_pool;&lt;br /&gt;
alter system flush shared_pool&lt;br /&gt;
*&lt;br /&gt;
ERROR at line 1:&lt;br /&gt;
ORA-01012: not logged on&lt;br /&gt;
Process ID: 0&lt;br /&gt;
Session ID: 0 Serial number: 0&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
SYS@MAPE&amp;gt; shutdown abort&lt;br /&gt;
ORACLE instance shut down.&lt;br /&gt;
SYS@MAPE&amp;gt; startup&lt;br /&gt;
ORACLE instance started.&lt;br /&gt;
&lt;br /&gt;
Total System Global Area  734892032 bytes&lt;br /&gt;
Fixed Size                  2225128 bytes&lt;br /&gt;
Variable Size             398461976 bytes&lt;br /&gt;
Database Buffers          318767104 bytes&lt;br /&gt;
Redo Buffers               15437824 bytes&lt;br /&gt;
Database mounted.&lt;br /&gt;
Database opened.&lt;br /&gt;
&lt;br /&gt;
SYS@MAPE&amp;gt; show parameter pool&lt;br /&gt;
&lt;br /&gt;
NAME                                 TYPE                           VALUE&lt;br /&gt;
------------------------------------ ------------------------------ ------------------------------&lt;br /&gt;
buffer_pool_keep                     string&lt;br /&gt;
buffer_pool_recycle                  string&lt;br /&gt;
global_context_pool_size             string&lt;br /&gt;
java_pool_size                       big integer                    0&lt;br /&gt;
large_pool_size                      big integer                    0&lt;br /&gt;
olap_page_pool_size                  big integer                    0&lt;br /&gt;
shared_pool_reserved_size            big integer                    18M&lt;br /&gt;
shared_pool_size                     big integer                    208M&lt;br /&gt;
streams_pool_size                    big integer                    0&lt;br /&gt;
SYS@MAPE&amp;gt; show sga&lt;br /&gt;
&lt;br /&gt;
Total System Global Area  734892032 bytes&lt;br /&gt;
Fixed Size                  2225128 bytes&lt;br /&gt;
Variable Size             385879064 bytes&lt;br /&gt;
Database Buffers          331350016 bytes&lt;br /&gt;
Redo Buffers               15437824 bytes&lt;br /&gt;
SYS@MAPE&amp;gt; exit&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
but for reference, the causes could well be the applications running on the database are not using bind variables...&amp;lt;br /&amp;gt;&lt;br /&gt;
From [http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:528893984337 asktom.oracle.com]&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
Just to give you a tiny idea of how huge of a difference this &lt;br /&gt;
can make performance wise, you only need to run a very small &lt;br /&gt;
test:&lt;br /&gt;
&lt;br /&gt;
tkyte@TKYTE816&amp;gt; alter system flush shared_pool;&lt;br /&gt;
System altered.&lt;br /&gt;
&lt;br /&gt;
tkyte@TKYTE816&amp;gt; declare&lt;br /&gt;
  2      type rc is ref cursor;&lt;br /&gt;
  3      l_rc rc;&lt;br /&gt;
  4      l_dummy all_objects.object_name%type;&lt;br /&gt;
  5      l_start number default dbms_utility.get_time;&lt;br /&gt;
  6  begin&lt;br /&gt;
  7      for i in 1 .. 1000&lt;br /&gt;
  8      loop&lt;br /&gt;
  9          open l_rc for&lt;br /&gt;
 10          &amp;#039;select object_name&lt;br /&gt;
 11             from all_objects&lt;br /&gt;
 12            where object_id = &amp;#039; || i;&lt;br /&gt;
 13          fetch l_rc into l_dummy;&lt;br /&gt;
 14          close l_rc;&lt;br /&gt;
 15      end loop;&lt;br /&gt;
 16      dbms_output.put_line&lt;br /&gt;
 17      ( round( (dbms_utility.get_time-l_start)/100, 2 ) ||&lt;br /&gt;
 18        &amp;#039; seconds...&amp;#039; );&lt;br /&gt;
 19  end;&lt;br /&gt;
 20  /&lt;br /&gt;
14.86 seconds...&lt;br /&gt;
&lt;br /&gt;
PL/SQL procedure successfully completed.&lt;br /&gt;
&lt;br /&gt;
tkyte@TKYTE816&amp;gt; declare&lt;br /&gt;
  2      type rc is ref cursor;&lt;br /&gt;
  3      l_rc rc;&lt;br /&gt;
  4      l_dummy all_objects.object_name%type;&lt;br /&gt;
  5      l_start number default dbms_utility.get_time;&lt;br /&gt;
  6  begin&lt;br /&gt;
  7      for i in 1 .. 1000&lt;br /&gt;
  8      loop&lt;br /&gt;
  9          open l_rc for&lt;br /&gt;
 10          &amp;#039;select object_name&lt;br /&gt;
 11             from all_objects&lt;br /&gt;
 12            where object_id = :x&amp;#039;&lt;br /&gt;
 13          using i;&lt;br /&gt;
 14          fetch l_rc into l_dummy;&lt;br /&gt;
 15          close l_rc;&lt;br /&gt;
 16      end loop;&lt;br /&gt;
 17      dbms_output.put_line&lt;br /&gt;
 18      ( round( (dbms_utility.get_time-l_start)/100, 2 ) ||&lt;br /&gt;
 19        &amp;#039; seconds...&amp;#039; );&lt;br /&gt;
 20  end;&lt;br /&gt;
 21  /&lt;br /&gt;
1.27 seconds...&lt;br /&gt;
&lt;br /&gt;
PL/SQL procedure successfully completed.&lt;br /&gt;
&lt;br /&gt;
That is pretty dramatic.  The fact is that not only does this &lt;br /&gt;
execute much faster (we spent more time PARSING our queries then &lt;br /&gt;
actually EXECUTING them!) it will let more users use your system &lt;br /&gt;
simultaneously.&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
and from [http://asktom.oracle.com/pls/asktom/f?p=100:11:::::P11_QUESTION_ID:1163635055580 linked question]&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
Lbrary cache latch contention is typically caused by NOT using bind variables.  It is due &lt;br /&gt;
to excessive parsing of statements.&lt;br /&gt;
&lt;br /&gt;
One way to see if this might be the case in your situation is to run a script like:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
create table t1 as select sql_text from v$sqlarea;&lt;br /&gt;
&lt;br /&gt;
alter table t1 add sql_text_wo_constants varchar2(1000);&lt;br /&gt;
&lt;br /&gt;
create or replace function &lt;br /&gt;
remove_constants( p_query in varchar2 ) return varchar2&lt;br /&gt;
as&lt;br /&gt;
    l_query long;&lt;br /&gt;
    l_char  varchar2(1);&lt;br /&gt;
    l_in_quotes boolean default FALSE;&lt;br /&gt;
begin&lt;br /&gt;
    for i in 1 .. length( p_query )&lt;br /&gt;
    loop&lt;br /&gt;
        l_char := substr(p_query,i,1);&lt;br /&gt;
        if ( l_char = &amp;#039;&amp;#039;&amp;#039;&amp;#039; and l_in_quotes )&lt;br /&gt;
        then&lt;br /&gt;
            l_in_quotes := FALSE;&lt;br /&gt;
        elsif ( l_char = &amp;#039;&amp;#039;&amp;#039;&amp;#039; and NOT l_in_quotes )&lt;br /&gt;
        then&lt;br /&gt;
            l_in_quotes := TRUE;&lt;br /&gt;
            l_query := l_query || &amp;#039;&amp;#039;&amp;#039;#&amp;#039;;&lt;br /&gt;
        end if;&lt;br /&gt;
        if ( NOT l_in_quotes ) then&lt;br /&gt;
            l_query := l_query || l_char;&lt;br /&gt;
        end if;&lt;br /&gt;
    end loop;&lt;br /&gt;
    l_query := translate( l_query, &amp;#039;0123456789&amp;#039;, &amp;#039;@@@@@@@@@@&amp;#039; );&lt;br /&gt;
    for i in 0 .. 8 loop&lt;br /&gt;
        l_query := replace( l_query, lpad(&amp;#039;@&amp;#039;,10-i,&amp;#039;@&amp;#039;), &amp;#039;@&amp;#039; );&lt;br /&gt;
        l_query := replace( l_query, lpad(&amp;#039; &amp;#039;,10-i,&amp;#039; &amp;#039;), &amp;#039; &amp;#039; );&lt;br /&gt;
    end loop;&lt;br /&gt;
    return upper(l_query);&lt;br /&gt;
end;&lt;br /&gt;
/&lt;br /&gt;
update t1 set sql_text_wo_constants = remove_constants(sql_text);&lt;br /&gt;
&lt;br /&gt;
select sql_text_wo_constants, count(*)&lt;br /&gt;
  from t1&lt;br /&gt;
 group by sql_text_wo_constants&lt;br /&gt;
having count(*) &amp;gt; 100&lt;br /&gt;
 order by 2&lt;br /&gt;
/&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The output of that last query will show you statements that are identical in the shared &lt;br /&gt;
pool after all numbers and character string constants have been removed.  These &lt;br /&gt;
statements -- and more importantly their counts -- are the potential bottlenecks.  In &lt;br /&gt;
addition to causing the contention, they will be HUGE cpu consumers.  &lt;br /&gt;
&lt;br /&gt;
If you discover your applications do not use bind variables -- you must have this &lt;br /&gt;
corrected.  You&amp;#039;ll never have a good hit ratio if everyone submits &amp;quot;unique&amp;quot; sql.  Your &lt;br /&gt;
shared pool will never be used right and you&amp;#039;ll be using excessive CPU (90% of the time &lt;br /&gt;
it takes to process &amp;quot;insert into t values ( 1 )&amp;quot; is parsing.  If you use &amp;quot;insert into t &lt;br /&gt;
values ( :x )&amp;quot;, and bind the value of 1 -- then the next person that runs that insert &lt;br /&gt;
will benefit from your work and run that much faster. &lt;br /&gt;
...&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Advice from Oracle concerning a concrete (12c) example of unable to allocate 52824 bytes of shared memory (&amp;quot;shared pool&amp;quot;,...====&lt;br /&gt;
This was from a ticket raised for a Data Pump export that consistently failed with:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Processing object type SCHEMA_EXPORT/TABLE/PROCACT_INSTANCE&lt;br /&gt;
Processing object type SCHEMA_EXPORT/TABLE/TABLE&lt;br /&gt;
ORA-39014: One or more workers have prematurely exited.&lt;br /&gt;
ORA-39029: worker 1 with process name &amp;quot;DW00&amp;quot; prematurely terminated&lt;br /&gt;
ORA-31671: Worker process DW00 had an unhandled exception.&lt;br /&gt;
ORA-04031: unable to allocate 52824 bytes of shared memory (&amp;quot;shared pool&amp;quot;,&amp;quot;unknown object&amp;quot;,&amp;quot;KTSL subheap&amp;quot;,&amp;quot;ktsl_load_disp-2&amp;quot;)&lt;br /&gt;
ORA-06512: at &amp;quot;SYS.KUPW$WORKER&amp;quot;, line 2122&lt;br /&gt;
ORA-06512: at line 2&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
The error ORA-4031 on the shared pool can indicate one of two things:&lt;br /&gt;
- insufficient space for the shared pool (so insufficient memory in SGA at that time)&lt;br /&gt;
OR&lt;br /&gt;
- although there is enough memory, it is fragmented and no contiguous chunk can be allocated to satisfy the latest memory request.&lt;br /&gt;
&lt;br /&gt;
Each SGA has a little fragmentation of course because of the operations taking place, so in your case the fragmentation is represented by the 18M of free memory, which exists in uncontiguous chunks.&lt;br /&gt;
This means that the root cause of the error is insufficient contiguous memory to allocate 12312 bytes of shared memory.&lt;br /&gt;
&lt;br /&gt;
ACTION PLAN&lt;br /&gt;
==============&lt;br /&gt;
1. We see memory_target=2000M. This is too little to support a 12c database, even when it has little activity.&lt;br /&gt;
As you may know 1.7G for the SGA was acceptable when speaking of 32bit OSs where it was hardly possible to make use of more than that.&lt;br /&gt;
Since you have a 64 bit system, the addressable memory is virtually unlimited.&lt;br /&gt;
Furthermore, by using AMM (memory_target&amp;gt;0) this memory is divided between the SGA and the PGA (the user processes) which in fact, depending on the number of connections, can limit the SGA even more.&lt;br /&gt;
So the first recommendation is to increase the value of memory_target to 4G for example. There is no ideal value, but this would be a reasonable starting value for tuning.&lt;br /&gt;
&lt;br /&gt;
You can do further tuning of the memory using the view V$MEMORY_TARGET_ADVICE.&lt;br /&gt;
The view V$MEMORY_TARGET_ADVICE provides tuning advice for the MEMORY_TARGET initialization parameter:&lt;br /&gt;
SQL&amp;gt; SELECT * FROM v$memory_target_advice ORDER BY memory_size;&lt;br /&gt;
&lt;br /&gt;
The dynamic performance view V$MEMORY_DYNAMIC_COMPONENTS shows the current sizes of all dynamically tuned memory components, including the total sizes of the SGA and instance PGA.&lt;br /&gt;
&lt;br /&gt;
You can also use V$MEMORY_RESIZE_OPS which has a circular history buffer of the last 800 memory resize requests.&lt;br /&gt;
&lt;br /&gt;
2. Since the AMM (you have memory_target&amp;gt;0) is used, then make sure to set:&lt;br /&gt;
 _shared_pool_reserved_pct to 10 or 15 to ensure that when the Shared Pool grows or shrinks automatically, the Reserved Area will change as well.&lt;br /&gt;
&lt;br /&gt;
SQL&amp;gt; alter system set &amp;quot;_shared_pool_reserved_pct&amp;quot;=15 scope=spfile;&lt;br /&gt;
--restart the instance&lt;br /&gt;
&lt;br /&gt;
FYI: By default, Oracle configures a small Reserved Pool (or Reserved Area) inside the Shared Pool.&lt;br /&gt;
This memory can be used for operations such as PL/SQL and trigger compilation or for temporary space while loading Java objects.&lt;br /&gt;
After the memory allocated from the Reserved Pool is freed, it returns to the Reserved Pool.&lt;br /&gt;
5% of the Shared Pool is set aside as the Reserved Pool to handle allocations of memory higher than defined by the hidden parameter _shared_pool_reserved_pct.&lt;br /&gt;
In some application environments, 5% is too small.&lt;br /&gt;
&lt;br /&gt;
3. Set shared_pool_size=500M or even more. This will represent a minimum amount of memory that will always be available to the shared pool.&lt;br /&gt;
If more memory is needed at any moment, if it is available, it will be allocated to the shared pool over the 500M.&lt;br /&gt;
&lt;br /&gt;
Implement the above steps, monitor the database and let us know the result,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORA-00392: log 1 of thread 1 is being cleared, operation not allowed===&lt;br /&gt;
After performing an active duplication, this happened when trying to open the database.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SQL&amp;gt; alter database open resetlogs&lt;br /&gt;
alter database open resetlogs&lt;br /&gt;
*&lt;br /&gt;
ERROR at line 1:&lt;br /&gt;
ORA-00392: log 1 of thread 1 is being cleared, operation not allowed&lt;br /&gt;
ORA-00312: online log 1 thread 1: &amp;#039;/oracle/oradata/testdb/redo/redo01.log&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SQL&amp;gt; select group#,thread#,status from v$log;&lt;br /&gt;
 &lt;br /&gt;
GROUP#   THREAD#   STATUS&lt;br /&gt;
-------  --------- ----------------&lt;br /&gt;
1        1         CLEARING_CURRENT&lt;br /&gt;
2        1         STALE&lt;br /&gt;
3        1         STALE&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Check the alert log! Always a good idea to get extra info. In here we find the answer&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ORA-00344: unable to re-create online log&lt;br /&gt;
&amp;#039;/oracle/oradata/testdb/redo/redo01.log&amp;#039;&lt;br /&gt;
ORA-27040: file create error, unable to create file&lt;br /&gt;
Linux-x86_64 Error: 2: No such file or directory&lt;br /&gt;
Additional information: 1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
So the clue is that the file cannot be created at the operating system level.&amp;lt;br /&amp;gt;&lt;br /&gt;
Doing a &amp;lt;code&amp;gt;df -k /oracle/oradata/testdb/redo&amp;lt;/code&amp;gt; shows us that the filesystem was created too small for the destination database.&amp;lt;br /&amp;gt;&lt;br /&gt;
In this case, we do not want the redolog directory to be as big as on the source db as there will be almost no movement on the destination.&amp;lt;br /&amp;gt;&lt;br /&gt;
I should have specified the LOGFILE parameter in the DUPLICATE clause to setup new, smaller redolog files.&amp;lt;br /&amp;gt;&lt;br /&gt;
As this duplicate takes over 12 hours, I didn&amp;#039;t want to do it again so I created symbolic links in the redolog directory pointing out to a larger filesystem with more space.&amp;lt;br /&amp;gt;&lt;br /&gt;
This allowed the creation of the redolog files. They can then be resized once the database has been opened.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cd /oracle/oradata/testdb/redo&lt;br /&gt;
ln -s /tmp/redo01.log redo01.log&lt;br /&gt;
ln -s /tmp/redo02.log redo02.log&lt;br /&gt;
ln -s /tmp/redo03.log redo03.log&lt;br /&gt;
&lt;br /&gt;
SQL&amp;gt; alter database open resetlogs&lt;br /&gt;
Database opened.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===RMAN-04004: error from recovery catalog database: ORA-01017: invalid username/password; logon denied===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
oracle@host:/export/home/ora&amp;gt; rman target / catalog catowner/catpass@catdb&lt;br /&gt;
&lt;br /&gt;
Recovery Manager: Release 11.2.0.2.0 - Production on Thu Jun 12 16:51:03 2014&lt;br /&gt;
&lt;br /&gt;
Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.&lt;br /&gt;
&lt;br /&gt;
connected to target database: XXXXRAP1 (DBID=3557010742)&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-00554: initialization of internal recovery manager package failed&lt;br /&gt;
RMAN-04004: error from recovery catalog database: ORA-01017: invalid username/password; logon denied&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This is normally very straight-forward and self-explanatory.&amp;lt;br /&amp;gt;&lt;br /&gt;
The puzzle here is that a connection from SQL*Plus works!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sqlplus catowner/catpass@catdb&lt;br /&gt;
&lt;br /&gt;
SQL*Plus: Release 11.2.0.2.0 Production on Thu Jun 12 16:53:18 2014&lt;br /&gt;
&lt;br /&gt;
Copyright (c) 1982, 2010, Oracle.  All rights reserved.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Connected to:&lt;br /&gt;
Oracle Database 12c Enterprise Edition Release 12.1.0.1.0 - 64bit Production&lt;br /&gt;
With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options&lt;br /&gt;
SQL&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Eventually worked out that the rman binary in the databases ORACLE_HOME on the source machine needed relinking!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cd $ORACLE_HOME/rdbms/lib&lt;br /&gt;
make -f ins_rdbms.mk irman &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORA-00230: operation disallowed: snapshot control file enqueue unavailable===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
waiting for snapshot control file enqueue&lt;br /&gt;
waiting for snapshot control file enqueue&lt;br /&gt;
waiting for snapshot control file enqueue&lt;br /&gt;
waiting for snapshot control file enqueue&lt;br /&gt;
cannot make a snapshot control file&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-03008: error while performing automatic resync of recovery catalog&lt;br /&gt;
ORA-00230: operation disallowed: snapshot control file enqueue unavailable&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
From the doc...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
When RMAN needs to back up or resynchronize from the control file, it first creates a snapshot or consistent image of the control file.&lt;br /&gt;
If one RMAN job is already backing up the control file while another needs to create a new snapshot control file, then you may see the following message:&lt;br /&gt;
&lt;br /&gt;
waiting for snapshot controlfile enqueue&lt;br /&gt;
&lt;br /&gt;
Under normal circumstances, a job that must wait for the control file enqueue waits for a brief interval and then successfully obtains the enqueue.&lt;br /&gt;
RMAN makes up to five attempts to get the enqueue and then fails the job.&lt;br /&gt;
The conflict is usually caused when two jobs are both backing up the control file, and the job that first starts backing up the control file waits for service from the media manager.&lt;br /&gt;
&lt;br /&gt;
To determine which job is holding the conflicting enqueue:&lt;br /&gt;
&lt;br /&gt;
    After you see the first message stating &amp;quot;RMAN-08512: waiting for snapshot controlfile enqueue&amp;quot;, start a new SQL*Plus session on the target database:&lt;br /&gt;
&lt;br /&gt;
    % sqlplus &amp;#039;SYS/oracle@trgt AS SYSDBA&amp;#039;&lt;br /&gt;
&lt;br /&gt;
    Execute the following query to determine which job is causing the wait:&lt;br /&gt;
&lt;br /&gt;
    SELECT s.SID, USERNAME AS &amp;quot;User&amp;quot;, PROGRAM, MODULE, &lt;br /&gt;
           ACTION, LOGON_TIME &amp;quot;Logon&amp;quot;, l.* &lt;br /&gt;
    FROM V$SESSION s, V$ENQUEUE_LOCK l&lt;br /&gt;
    WHERE l.SID = s.SID&lt;br /&gt;
    AND l.TYPE = &amp;#039;CF&amp;#039;&lt;br /&gt;
    AND l.ID1 = 0&lt;br /&gt;
    AND l.ID2 = 2;&lt;br /&gt;
&lt;br /&gt;
    You should see output similar to the following (the output in this example has been truncated):&lt;br /&gt;
&lt;br /&gt;
    SID User Program              Module                    Action           Logon&lt;br /&gt;
    --- ---- -------------------- ------------------------- ---------------- ---------&lt;br /&gt;
      9 SYS  rman@h13 (TNS V1-V3) backup full datafile: c1  0000210 STARTED  21-JUN-01&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
After you have determined which job is creating the enqueue, you can do one of the following:&lt;br /&gt;
&lt;br /&gt;
    Wait until the job creating the enqueue completes&lt;br /&gt;
    Cancel the current job and restart it after the job creating the enqueue completes&lt;br /&gt;
    Cancel the job creating the enqueue&lt;br /&gt;
&lt;br /&gt;
Commonly, enqueue situations occur when a job is writing to a tape drive, but the tape drive is waiting for a new cassette to be inserted.&lt;br /&gt;
If you start a new job in this situation, then you will probably receive the enqueue message because the first job cannot complete until the new tape is loaded.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or more directly...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 2000&lt;br /&gt;
col killer     for a70&lt;br /&gt;
col program    for a20&lt;br /&gt;
col module     for a20&lt;br /&gt;
col action     for a20&lt;br /&gt;
col logon_time for a20&lt;br /&gt;
select &amp;#039;alter system disconnect session &amp;#039;&amp;#039;&amp;#039;||s.sid||&amp;#039;,&amp;#039;||s.serial#||&amp;#039;&amp;#039;&amp;#039; immediate;&amp;#039; killer&lt;br /&gt;
,      username&lt;br /&gt;
,      program&lt;br /&gt;
,      module&lt;br /&gt;
,      action&lt;br /&gt;
,      logon_time&lt;br /&gt;
from   v$session s&lt;br /&gt;
,      v$enqueue_lock l&lt;br /&gt;
where  l.sid  = s.sid&lt;br /&gt;
and    l.type = &amp;#039;cf&amp;#039;&lt;br /&gt;
and    l.id1  = 0&lt;br /&gt;
and    l.id2  = 2&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORA-19511: non RMAN, but media manager or vendor specific failure, error text:===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-03002: failure of Duplicate Db command at 05/01/2018 14:23:09&lt;br /&gt;
RMAN-05501: aborting duplication of target database&lt;br /&gt;
RMAN-03015: error occurred in stored script Memory Script&lt;br /&gt;
ORA-27191: sbtinfo2 returned error&lt;br /&gt;
Additional information: 3586&lt;br /&gt;
ORA-19511: non RMAN, but media manager or vendor specific failure, error text:&lt;br /&gt;
   Unable to connect to NetWorker server &amp;#039;hn6000.cln.be&amp;#039; because &amp;#039;Authentication error; why = Invalid client credential&amp;#039;. (2:10:79)&lt;br /&gt;
&lt;br /&gt;
Recovery Manager complete.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
If this happens, check to see if the nsr daemon is running...&amp;lt;br /&amp;gt;&lt;br /&gt;
Good system:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/home/oracle&amp;gt; ps -ef | grep nsr&lt;br /&gt;
    root  5701836        1   0   Mar 16      - 13:18 /bin/nsrexecd&lt;br /&gt;
  oracle 18809292 22741502   0 15:03:58  pts/0  0:00 grep nsr&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Bad system:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 /home/oracle&amp;gt; ps -ef | grep nsr&lt;br /&gt;
  oracle 14745986 15139292   0 15:03:29  pts/2  0:00 grep nsr&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORA-19554: error allocating device, device type: SBT_TAPE, device name:===&lt;br /&gt;
If using Cygwin...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-03002: failure of backup command at 05/19/2015 12:25:47&lt;br /&gt;
ORA-19554: error allocating device, device type: SBT_TAPE, device name:&lt;br /&gt;
ORA-27000: skgfqsbi: failed to initialize storage subsystem (SBT) layer&lt;br /&gt;
OSD-02534: Message 2534 not found;  product=RDBMS; facility=SOSD&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Check the tdpo.opt file is where you think it is!&lt;br /&gt;
* Check the path to the opt file looks like this (needs to be Windows format):&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
CONFIGURE CHANNEL DEVICE TYPE &amp;#039;SBT_TAPE&amp;#039; FORMAT   &amp;#039;LOG_%d_t%t_s%s_u%U&amp;#039; PARMS  &amp;#039;ENV=(TDPO_OPTFILE=E:\oracle\KITRYD\admin\tdpo.opt)&amp;#039;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Check the content of the opt file is Windows format paths!&lt;br /&gt;
&lt;br /&gt;
===RMAN-20033: control file SEQUENCE# too low===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-03008: error while performing automatic resync of recovery catalog&lt;br /&gt;
===RMAN-20033: control file SEQUENCE# too low===&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
From [https://forums.oracle.com/forums/thread.jspa?threadID=1115969 forums.oracle.com]&amp;lt;br /&amp;gt;&lt;br /&gt;
This error generally happens if an archivelog backup happens while the RMAN database backup is running and if controlfile autobackup is configured.&amp;lt;br /&amp;gt;&lt;br /&gt;
The database backup is usually successful and it is just the controlfile backup that fails.&lt;br /&gt;
===ORA-27302: failure occurred at: slgpn===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
RMAN-03009: failure of Control File and SPFILE Autobackup command on c1 channel at 06/28/2011 18:59:38&lt;br /&gt;
ORA-19715: invalid format %b for generated name&lt;br /&gt;
ORA-27302: failure occurred at: slgpn&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Problem====&lt;br /&gt;
When doing a &amp;quot;&amp;lt;tt&amp;gt;backup as copy database&amp;lt;/tt&amp;gt;&amp;quot;, got these errors after 145 of 147 datafiles had been backed up!&lt;br /&gt;
&lt;br /&gt;
====Investigation====&lt;br /&gt;
I had read [https://oracleedge.wordpress.com/2011/06/29/oracle-rman-03009-ora-19715-ora-27302/ elsewhere] that this could be something to do with the format of the autobackup of the control file so I changed the format as suggested and reran the backup.&amp;lt;br /&amp;gt;&lt;br /&gt;
No luck. It ended exactly the same way after 145 files. I decided to compare the original list of datafiles with those that had been backed up in order to track down the 2 failures. Maybe I could see something odd with them.&amp;lt;br /&amp;gt;&lt;br /&gt;
Sure enough, these 2 files were different... there was a space at the &amp;#039;&amp;#039;&amp;#039;end&amp;#039;&amp;#039;&amp;#039; of the filenames :-)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select &amp;#039;x&amp;#039;||file_name||&amp;#039;x&amp;#039;&lt;br /&gt;
from   dba_data_files&lt;br /&gt;
where  file_name like &amp;#039;% %&amp;#039;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Solution====&lt;br /&gt;
Run the backup of the other 2 datafiles with a different format that did not rely on the filename.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
run {&lt;br /&gt;
    allocate channel c1 device type disk format &amp;#039;/path/to/datafiles/%U&amp;#039;;&lt;br /&gt;
    backup as copy datafile 170;&lt;br /&gt;
    backup as copy datafile 171;&lt;br /&gt;
    backup as copy current controlfile;&lt;br /&gt;
    release channel c1;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The other 145 datafiles were backed up with a format of &amp;#039;/path/to/datafiles/%b&amp;#039; which preserves the filenames so all that needs to be done is rename the other 2 after the backup finishes.&amp;lt;br /&amp;gt;&lt;br /&gt;
If they are going to be used in a restore scenario, they should be renamed in the controlfile also.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter database rename file &amp;#039;/path/to/datafiles/filename_with_a_space_at_end &amp;#039; to &amp;#039;/path/to/datafiles/filename_without_a_space&amp;#039;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===RMAN errors after crosscheck backup and delete noprompt obsolete and delete noprompt expired backup===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
RMAN-06207: WARNING: 3921 objects could not be deleted for SBT_TAPE channel(s) due&lt;br /&gt;
RMAN-06208:          to mismatched status.  Use CROSSCHECK command to fix status&lt;br /&gt;
RMAN-06210: List of Mismatched objects&lt;br /&gt;
RMAN-06211: ==========================&lt;br /&gt;
RMAN-06212:   Object Type   Filename/Handle&lt;br /&gt;
RMAN-06213: --------------- ---------------------------------------------------&lt;br /&gt;
RMAN-06214: Backup Piece    DB_SID_t20140316_s263889_umhp3bpa7_1_1&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Use the FORCE option with the DELETE command&amp;lt;br /&amp;gt;&lt;br /&gt;
The FORCE command tells RMAN to clean the information out of the catalog regardless of whether it can find it on the media or not.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
delete force noprompt expired backup;&lt;br /&gt;
delete force noprompt obsolete;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===RMAN-06004: ORACLE error from recovery catalog database: RMAN-20003: target database incarnation not found in recovery catalog===&lt;br /&gt;
====Problem:====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-03002: failure of Duplicate Db command at 12/05/2017 11:11:15&lt;br /&gt;
RMAN-05501: aborting duplication of target database&lt;br /&gt;
RMAN-03015: error occurred in stored script Memory Script&lt;br /&gt;
RMAN-06004: ORACLE error from recovery catalog database: RMAN-20003: target database incarnation not found in recovery catalog&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Solution:====&lt;br /&gt;
Strangely, this means, in my particular case, that block change tracking is turned on in the target databse and needs turning off in the auxiliary while the DUPLICATE is running.&amp;lt;br /&amp;gt;&lt;br /&gt;
It must be done while the auxiliary is in mount mode and restoring the datafiles (before recovery starts)&amp;lt;br /&amp;gt;&lt;br /&gt;
It is reported to be a bug fixed in 11.1 but somehow, we&amp;#039;re still (sometimes) getting it in 12.1.0.2.&lt;br /&gt;
&lt;br /&gt;
===RMAN-06059: expected archived log not found, loss of archived log compromises recoverability===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
RMAN-06059: expected archived log not found, loss of archived log compromises recoverability&lt;br /&gt;
ORA-19625: error identifying file &amp;lt;filename&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This error can come from the fact that the database files (more likely archivelogs) are being deleted by the operating system so RMAN has no clue of their whereabouts.&amp;lt;br /&amp;gt;&lt;br /&gt;
Possibly result of a database duplication and the catalog has not updated properly?&amp;lt;br /&amp;gt;&lt;br /&gt;
====Solution====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
crosscheck archivelog all;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
And then maybe take a backup to be on the safe side.&lt;br /&gt;
&lt;br /&gt;
===RMAN-05537: DUPLICATE without TARGET connection when auxiliary instance is started with spfile cannot use SPFILE clause===&lt;br /&gt;
====Problem:====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-03002: failure of Duplicate Db command at 12/05/2017 14:17:49&lt;br /&gt;
RMAN-05501: aborting duplication of target database&lt;br /&gt;
RMAN-05537: DUPLICATE without TARGET connection when auxiliary instance is started with spfile cannot use SPFILE clause&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Usually happens after restarting a failed RMAN DUPLICATE database. The spfile has been regenerated on the auxiliary to a level where it has too much detail in it.&lt;br /&gt;
====Solution:====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ cd $ORACLE_HOME/dbs&lt;br /&gt;
$ ls -altr *dwh_perf*&lt;br /&gt;
-rw-r-----    1 oracle   oinstall   17645568 Aug  3 13:34 snapcf_dwh_perf.f&lt;br /&gt;
-rw-r-----    1 oracle   oinstall       7680 Nov  4 09:22 orapwdwh_perf&lt;br /&gt;
-rw-r--r--    1 oracle   oinstall        104 Dec  5 09:34 initdwh_perf.ora&lt;br /&gt;
-rw-r-----    1 oracle   oinstall       6656 Dec  5 11:11 spfiledwh_perf.ora&lt;br /&gt;
-rw-rw----    1 oracle   oinstall       1544 Dec  5 14:18 hc_dwh_perf.dat&lt;br /&gt;
$ mv hc_dwh_perf.dat hc_dwh_perf.dat.old&lt;br /&gt;
$ mv spfiledwh_perf.ora spfiledwh_perf.ora.old&lt;br /&gt;
$ cat initdwh_perf.ora&lt;br /&gt;
sga_max_size=&amp;#039;6G&amp;#039;&lt;br /&gt;
sga_target=&amp;#039;6G&amp;#039;&lt;br /&gt;
compatible=&amp;#039;12.0.0&amp;#039;&lt;br /&gt;
db_files=&amp;#039;500&amp;#039;&lt;br /&gt;
&lt;br /&gt;
# Instance name&lt;br /&gt;
db_name=dwh_perf&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Re-run the DUPLICATE. It should zoom past the already recovered datafiles.&lt;br /&gt;
&lt;br /&gt;
===PSDRPC returns significant error 1013===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
archived log thread=1 sequence=195008&lt;br /&gt;
channel t2: reading from backup piece arclog_LBK_4260753020_946042770_479194_1&lt;br /&gt;
channel t0: piece handle=arclog_LBK_4260753020_946042770_479192_1 tag=TAG20170607T133757&lt;br /&gt;
channel t0: restored backup piece 1&lt;br /&gt;
channel t0: restore complete, elapsed time: 00:00:35&lt;br /&gt;
archived log file name=/xxxxxx/acc/ora_bin2/app/oracle/product/11.2.0.4/dbhome_1/dbs/arch1_195006_815790039.dbf thread=1 sequence=195006&lt;br /&gt;
PSDRPC returns significant error 1013.&lt;br /&gt;
PSDRPC returns significant error 1013.&lt;br /&gt;
released channel: t0&lt;br /&gt;
released channel: t1&lt;br /&gt;
released channel: t2&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-03002: failure of Duplicate Db command at 06/09/2017 15:15:04&lt;br /&gt;
RMAN-05501: aborting duplication of target database&lt;br /&gt;
RMAN-03015: error occurred in stored script Memory Script&lt;br /&gt;
RMAN-11003: failure during parse/execution of SQL statement: alter database recover logfile &amp;#039;/xxxxxx/acc/ora_bin2/app/oracle/product/11.2.0.4/dbhome_1/dbs/arch1_195006_815790039.dbf&amp;#039;&lt;br /&gt;
ORA-10877: error signaled in parallel recovery slave&lt;br /&gt;
&lt;br /&gt;
Recovery Manager complete.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Action====&lt;br /&gt;
Check the alert log on the auxiliary instance.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ORA-279 signalled during: alter database recover logfile &amp;#039;/xxxxxx/acc/ora_bin2/app/oracle/product/11.2.0.4/dbhome_1/dbs/arch1_195005_815790039.dbf&amp;#039;...&lt;br /&gt;
alter database recover logfile &amp;#039;/xxxxxx/acc/ora_bin2/app/oracle/product/11.2.0.4/dbhome_1/dbs/arch1_195006_815790039.dbf&amp;#039;&lt;br /&gt;
Media Recovery Log /xxxxxx/acc/ora_bin2/app/oracle/product/11.2.0.4/dbhome_1/dbs/arch1_195006_815790039.dbf&lt;br /&gt;
Fri Jun 09 07:30:30 2017&lt;br /&gt;
Errors with log /xxxxxx/acc/ora_bin2/app/oracle/product/11.2.0.4/dbhome_1/dbs/arch1_195006_815790039.dbf&lt;br /&gt;
Recovery interrupted!&lt;br /&gt;
Recovered data files to a consistent state at change 238029030495&lt;br /&gt;
Media Recovery failed with error 19755&lt;br /&gt;
Errors in file /xxxxxx/acc/ora_bin2/app/oracle/diag/rdbms/lbkro/lbkro/trace/lbkro_pr00_13108374.trc:&lt;br /&gt;
ORA-00283: recovery session canceled due to errors&lt;br /&gt;
===&amp;gt;ORA-19755: could not open change tracking file&lt;br /&gt;
===&amp;gt;ORA-19750: change tracking file: &amp;#039;/xxxxxx/exp/ora_data2/lbk/data/bct_lbk_do_not_delete.f&lt;br /&gt;
===&amp;gt;ORA-27037: unable to obtain file status&lt;br /&gt;
===&amp;gt;IBM AIX RISC System/6000 Error: 2: No such file or directory&lt;br /&gt;
Additional information: 3&lt;br /&gt;
Fri Jun 09 07:30:36 2017&lt;br /&gt;
ORA-10877 signalled during: alter database recover logfile &amp;#039;/xxxxxx/acc/ora_bin2/app/oracle/product/11.2.0.4/dbhome_1/dbs/arch1_195006_815790039.dbf&amp;#039;...&lt;br /&gt;
Fri Jun 09 14:04:57 2017&lt;br /&gt;
alter database recover logfile &amp;#039;/xxxxxx/acc/ora_bin2/app/oracle/product/11.2.0.4/dbhome_1/dbs/arch1_195006_815790039.dbf&amp;#039;&lt;br /&gt;
Media Recovery Log /xxxxxx/acc/ora_bin2/app/oracle/product/11.2.0.4/dbhome_1/dbs/arch1_195006_815790039.dbf&lt;br /&gt;
Media Recovery failed with error 1112&lt;br /&gt;
ORA-283 signalled during: alter database recover logfile &amp;#039;/xxxxxx/acc/ora_bin2/app/oracle/product/11.2.0.4/dbhome_1/dbs/arch1_195006_815790039.dbf&amp;#039;...&lt;br /&gt;
Fri Jun 09 14:31:20 2017&lt;br /&gt;
Shutting down instance (immediate)&lt;br /&gt;
Shutting down instance: further logons disabled&lt;br /&gt;
Stopping background process MMNL&lt;br /&gt;
Stopping background process MMON&lt;br /&gt;
License high water mark = 49&lt;br /&gt;
ALTER DATABASE CLOSE NORMAL&lt;br /&gt;
ORA-1109 signalled during: ALTER DATABASE CLOSE NORMAL...&lt;br /&gt;
ALTER DATABASE DISMOUNT&lt;br /&gt;
Shutting down archive processes&lt;br /&gt;
Archiving is disabled&lt;br /&gt;
Completed: ALTER DATABASE DISMOUNT&lt;br /&gt;
ARCH: Archival disabled due to shutdown: 1089&lt;br /&gt;
Shutting down archive processes&lt;br /&gt;
Archiving is disabled&lt;br /&gt;
ARCH: Archival disabled due to shutdown: 1089&lt;br /&gt;
Shutting down archive processes&lt;br /&gt;
Archiving is disabled&lt;br /&gt;
Fri Jun 09 14:31:24 2017&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This is a known bug. it is fixed in 11.2.0.3 but... this customer does not apply patches!&lt;br /&gt;
&lt;br /&gt;
====Solution====&lt;br /&gt;
While the DUPLICATE is running (and in MOUNT mode), log on to the auxiliary instance and disable block change tracking.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter database disable block change tracking;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
A documented workaround is to set db_filename_convert parameter in the DUPLICATE clause of the run block but I tried this and it failed again.&amp;lt;br /&amp;gt;&lt;br /&gt;
The obvious solution is to patch the database but...&lt;br /&gt;
&lt;br /&gt;
===Database trigger to capture ORA errors===&lt;br /&gt;
From [http://ora-ssn.blogspot.be/2011/10/trigger-on-database-to-capture-ora.html ora-ssn.blogspot.be]&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
CREATE TABLE stats$error_log (&lt;br /&gt;
        err_dt          TIMESTAMP,&lt;br /&gt;
        db_user         VARCHAR2(30),&lt;br /&gt;
        msg_stack       VARCHAR2(2000),&lt;br /&gt;
        sqltxt          VARCHAR2(1000))&lt;br /&gt;
tablespace users;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Now, create a trigger on the database server.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
CREATE OR REPLACE TRIGGER log_server_errors&lt;br /&gt;
  AFTER SERVERERROR&lt;br /&gt;
  ON DATABASE&lt;br /&gt;
DECLARE&lt;br /&gt;
          v_sqltext VARCHAR2(1000);&lt;br /&gt;
          nl_sqltext ora_name_list_t;&lt;br /&gt;
  BEGIN&lt;br /&gt;
          -- Capture entire error text&lt;br /&gt;
          FOR i IN 1 .. ora_sql_txt(nl_sqltext) LOOP&lt;br /&gt;
            v_sqltext := v_sqltext || nl_sqltext(i);&lt;br /&gt;
          END LOOP;&lt;br /&gt;
          INSERT INTO STATS$ERROR_LOG&lt;br /&gt;
          (err_dt, db_user, msg_stack, sqltxt)&lt;br /&gt;
          VALUES&lt;br /&gt;
          (systimestamp,&lt;br /&gt;
           sys.login_user,&lt;br /&gt;
           dbms_utility.format_error_stack, v_sqltext);&lt;br /&gt;
  END log_server_errors;&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ORA-19809: limit exceeded for recovery files===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-03009: failure of backup command on ORA_DISK_1 channel at 07/15/2013 10:10:59&lt;br /&gt;
ORA-19809: limit exceeded for recovery files&lt;br /&gt;
ORA-19804: cannot reclaim 274716160 bytes disk space from 1468006400 limit&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    ORA-19809: limit exceeded for recovery files&lt;br /&gt;
    Cause: The limit for recovery files specified by the db_recovery_file_dest_size was exceeded.&lt;br /&gt;
&lt;br /&gt;
    Action: The error is accompanied by 19804. See message 19804 for further details&lt;br /&gt;
&lt;br /&gt;
    ORA-19804: cannot reclaim string bytes disk space from string limit&lt;br /&gt;
    Cause: Oracle cannot reclaim disk space of specified bytes from the DB_RECOVERY_FILE_DEST_SIZE limit.&lt;br /&gt;
&lt;br /&gt;
    Action: There are five possible solutions:&lt;br /&gt;
       1) Take frequent backup of recovery area using RMAN.&lt;br /&gt;
       2) Consider changing RMAN retention policy.&lt;br /&gt;
       3) Consider changing RMAN archivelog deletion policy.&lt;br /&gt;
       4) Add disk space and increase DB_RECOVERY_FILE_DEST_SIZE.&lt;br /&gt;
       5) Delete files from recovery area using RMAN.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The solution here is to increase the value of db_recovery_file_dest_size but it might also indicate a problem with tapes if the archivelogs are being backed up to tape via tdpo.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SYS@DN7&amp;gt; alter system set db_recovery_file_dest_size=4000M scope=both;&lt;br /&gt;
&lt;br /&gt;
System altered.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Looking into int further, saw RMAN parameters missing...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
CONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF 14 DAYS;&lt;br /&gt;
CONFIGURE BACKUP OPTIMIZATION OFF;&lt;br /&gt;
CONFIGURE DEFAULT DEVICE TYPE TO &amp;#039;SBT_TAPE&amp;#039;;&lt;br /&gt;
CONFIGURE CONTROLFILE AUTOBACKUP ON;&lt;br /&gt;
CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE &amp;#039;SBT_TAPE&amp;#039; TO &amp;#039;LOG_%d_controlfile_%F.rman&amp;#039;;&lt;br /&gt;
CONFIGURE DEVICE TYPE &amp;#039;SBT_TAPE&amp;#039; PARALLELISM 1 BACKUP TYPE TO BACKUPSET;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===RMAN-00554: initialization of internal recovery manager package failed===&lt;br /&gt;
Getting this error after migrating a database from one machine to another and attaching to a nice new version 12c catalog on the new server&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Recovery Manager: Release 11.2.0.2.0 - Production on Sat Jun 21 13:16:24 2014&lt;br /&gt;
&lt;br /&gt;
Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.&lt;br /&gt;
&lt;br /&gt;
connected to target database: SPMSUPP1 (DBID=3026014394)&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============&lt;br /&gt;
RMAN-00571: ===========================================================&lt;br /&gt;
RMAN-00554: initialization of internal recovery manager package failed&lt;br /&gt;
RMAN-04004: error from recovery catalog database: ORA-01017: invalid username/password; logon denied&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
We cannot connect to the catalog via rman but there is no problem if connecting via SQL*Plus!&amp;lt;br /&amp;gt;&lt;br /&gt;
Solution: relink the rman executable.&lt;br /&gt;
===Using AIX commands genld, genkld and slibclean to avoid library file locking errors (libjox) (Doc ID 739963.1)===&lt;br /&gt;
* [https://support.oracle.com/epmos/faces/DocumentDisplay?_afrLoop=206851390914720&amp;amp;id=739963.1&amp;amp;_afrWindowMode=0&amp;amp;_adf.ctrl-state=e0pq23tou_4 Metalink]&lt;br /&gt;
When installing interim (one-off) patches, CPU patches or patchsets, you may encounter some errors with regards to files being locked or oui/opatch being unable to copy files&amp;lt;br /&amp;gt;&lt;br /&gt;
even though the databases, listeners and all other Oracle processes associated with the ORACLE_HOME to be patched were stopped.&amp;lt;br /&amp;gt;&lt;br /&gt;
This could be as result of a process which requires termination or an additional file needing to be unloaded from the system cache.&amp;lt;br /&amp;gt;&lt;br /&gt;
Run following commands to clean up...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
genld -l | grep &amp;lt;ORACLE_HOME&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
If genld returns data then a currently executing process has something open in the ORACLE_HOME directory, therefore terminate the process as required/recommended.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
genkld | grep &amp;lt;ORACLE_HOME&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
If the genkld command  returns a  list of shared objects currently loaded onto the OS system cache then please remove the entries from the OS system cache by running the slibclean command as root user:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/usr/sbin/slibclean&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===ORA-20011: Approximate NDV failed: ORA-29913: error in executing ODCIEXTTABLEOPEN callout===&lt;br /&gt;
This seems to be related to orphaned Datapump tables. Generally seems to be a problem when stats jobs are running during the night (dbms_stats)&amp;lt;br /&amp;gt;&lt;br /&gt;
* Check no datapump jobs are running&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select * from dba_datapump_jobs;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Find orphaned tables&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set lines 2000&lt;br /&gt;
select owner&lt;br /&gt;
,      object_name&lt;br /&gt;
,      object_type&lt;br /&gt;
,      status&lt;br /&gt;
,      to_char(created,&amp;#039;dd-mon-yyyy hh24:mi:ss&amp;#039;) created&lt;br /&gt;
,      to_char(last_ddl_time,&amp;#039;dd-mon-yyyy hh24:mi:ss&amp;#039;) last_ddl_time&lt;br /&gt;
from   dba_objects&lt;br /&gt;
where  1=1&lt;br /&gt;
and    object_name like &amp;#039;ET$%&amp;#039;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Check that  any rows seen are actually external tables&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select owner&lt;br /&gt;
,      table_name&lt;br /&gt;
,      default_directory_name&lt;br /&gt;
,      access_type&lt;br /&gt;
from   dba_external_tables&lt;br /&gt;
order  by 1,2&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Drop the tables if they are not currently being used (no datapump jobs running)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
drop table &amp;amp;&amp;amp;owner..&amp;amp;table_name;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===ORA-01547: warning: RECOVER succeeded but OPEN RESETLOGS would get error below===&lt;br /&gt;
Database is restored and now we want to recover it but we see this...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Starting recover at 24-JUL-15 11:26:19&lt;br /&gt;
&lt;br /&gt;
starting media recovery&lt;br /&gt;
&lt;br /&gt;
unable to find archive log&lt;br /&gt;
archive log thread=1 sequence=69763&lt;br /&gt;
Oracle Error: &lt;br /&gt;
ORA-01547: warning: RECOVER succeeded but OPEN RESETLOGS would get error below&lt;br /&gt;
ORA-01194: file 1 needs more recovery to be consistent&lt;br /&gt;
ORA-01110: data file 1: &amp;#039;/oracle/TRSCRP1/oradata2/system01.dbf&amp;#039;&lt;br /&gt;
&lt;br /&gt;
released channel: c1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This means that although we have restored the database, we are still missing information to complete the recovery. This information is contained in the archived redo logs which must also be restored (from tape if they are no longer on disk)&amp;lt;br /&amp;gt;&lt;br /&gt;
We can see here that we need an archive log with sequence number 69763. But what is the file called and where should it be restored to?&amp;lt;br /&amp;gt;&lt;br /&gt;
For this we can go to SQL*Plus and get the database to tell us&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
recover database using backup controlfile until cancel;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
and cancel straight away.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ORA-00279: change 13796376414661 generated at 07/14/2015 13:20:07 needed for&lt;br /&gt;
thread 1&lt;br /&gt;
ORA-00289: suggestion : /oracle/TRSCRP1/archive/arch_TRSCRP1_1_69763.arc&lt;br /&gt;
ORA-00280: change 13796376414661 for thread 1 is in sequence #69763&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Specify log: {&amp;lt;RET&amp;gt;=suggested | filename | AUTO | CANCEL}&lt;br /&gt;
cancel&lt;br /&gt;
ORA-01547: warning: RECOVER succeeded but OPEN RESETLOGS would get error below&lt;br /&gt;
ORA-01194: file 1 needs more recovery to be consistent&lt;br /&gt;
ORA-01110: data file 1: &amp;#039;/oracle/TRSCRP1/oradata2/system01.dbf&amp;#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
ORA-01112: media recovery not started&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Now we see that we need to find a file called arch_TRSCRP1_1_69763.arc and put it in the directory /oracle/TRSCRP1/archive.&amp;lt;br /&amp;gt;&lt;br /&gt;
This will continue up until the time specified for the recover so restore a whole bunch of them.&amp;lt;br /&amp;gt;&lt;br /&gt;
Repeat the &amp;quot;recover database using backup controlfile until cancel;&amp;quot; command and type AUTO or Enter until you&amp;#039;ve got to where you need to be.&amp;lt;br /&amp;gt;&lt;br /&gt;
Type CANCEL when point is reached and&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alter database open resetlogs;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Stuart</name></author>	</entry>

	</feed>