Quantcast
Channel: Doyensys Allappsdba Blog..
Viewing all 1640 articles
Browse latest View live

Query to find the blocking session in time interval.

$
0
0
Please use the below query to get the output.

set lines 170
set pages 10000
col event format a40
col sample_time format a40
select to_char(sample_time,'DD-MON-YY HH24:MI:SS'),SESSION_ID,SESSION_SERIAL#,SQL_ID,BLOCKING_SESSION,BLOCKING_SESSION_SERIAL#,BLOCKING_SESSION_STATUS,EVENT from dba_hist_active_sess_history where to_char(sample_time,'DD-MON-YY HH12:MI:SS') between '22-DEC-17 00:05 AM' and '22-DEC-17 09:10 AM' and event like '%enq:%' and BLOCKING_SESSION is not null order by 1 ;


Query to find out the sql which used high CPU.

$
0
0
Please use the below.

set lines 500;
set pages 500;
set long 1000000;
SELECT X.SQL_ID, X.CPU_TIME, X.EXECUTIONS, T.SQL_TEXT
FROM
   DBA_HIST_SQLTEXT T,
   (
      SELECT
         S.SQL_ID SQL_ID,
         SUM(S.CPU_TIME_DELTA/1000000) CPU_TIME,
         SUM(S.EXECUTIONS_DELTA) EXECUTIONS
      FROM
         DBA_HIST_SQLSTAT S,
         DBA_HIST_SNAPSHOT P
      WHERE
         S.SNAP_ID = P.SNAP_ID AND
         P.BEGIN_INTERVAL_TIME >= TO_DATE('&beginTime', 'MM/DD/YYYY HH24:MI') AND
         P.END_INTERVAL_TIME <= TO_DATE('&endTime', 'MM/DD/YYYY HH24:MI')
      GROUP BY S.SQL_ID
   ) X
WHERE T.SQL_ID = X.SQL_ID
ORDER BY X.CPU_TIME DESC;

Article 2

$
0
0
                                            \ Query to check the object timeout in the database. 


Query
--------

select /*+ ordered */ w1.sid waiting_session,
h1.sid holding_session,
w.kgllktype lock_or_pin,
w.kgllkhdl address,
decode(h.kgllkmod, 0, 'None', 1, 'Null', 2, 'Share', 3, 'Exclusive',
'Unknown') mode_held, 
decode(w.kgllkreq, 0, 'None', 1, 'Null', 2, 'Share', 3, 'Exclusive',
'Unknown') mode_requested
from dba_kgllock w, dba_kgllock h, v$session w1, v$session h1
where
(((h.kgllkmod != 0) and (h.kgllkmod != 1)
and ((h.kgllkreq = 0) or (h.kgllkreq = 1)))
and
(((w.kgllkmod = 0) or (w.kgllkmod= 1))
and ((w.kgllkreq != 0) and (w.kgllkreq != 1))))
and w.kgllktype = h.kgllktype
and w.kgllkhdl = h.kgllkhdl
and w.kgllkuse = w1.saddr
and h.kgllkuse = h1.saddr
/

Article 1

$
0
0
                                         Query to check Stale statistics


---Using Anonymous PL/SQL block


SQL> SET SERVEROUTPUT ON
  DECLARE
ObjList dbms_stats.ObjectTab;
BEGIN
dbms_stats.gather_database_stats(objlist=>ObjList, options=>’LIST STALE’);
FOR i in ObjList.FIRST..ObjList.LAST
LOOP
dbms_output.put_line(ObjList(i).ownname || ‘.’ || ObjList(i).ObjName || ‘ ‘ || ObjList(i).ObjType || ‘ ‘ || ObjList(i).partname);
END LOOP;
END;
/


Oracle 10g Onwards.

col TABLE_NAME for a30
col PARTITION_NAME for a20
col SUBPARTITION_NAME for a20
select OWNER,TABLE_NAME,PARTITION_NAME,SUBPARTITION_NAME,NUM_ROWS,LAST_ANALYZED from dba_TAB_STATISTICS where STALE_STATS='YES';


Article 0

$
0
0
                                            ADOP patch cycle is point to PROD. 


Adop patch cycle pointing to PROD host from UAT instance.


Enter the APPS password:
Enter the SYSTEM password:
Enter the WLSADMIN password:

Validating credentials.

Initializing.
    Run Edition context  : /u02/prod/fs1/inst/apps/PROD_erptest/appl/admin/PROD_erptest.xml
    Patch edition context: /u02/prod/fs2/inst/apps/PROD_erptest/appl/admin/PROD_erptest.xml
Reading driver file (up to 50000000 bytes).
    Patch file system free space: 602.71 GB

Validating system setup.
    Node registry is valid.
    [WARNING]   ETCC: The following required database fixes have not been applied to node erptest:
                  19908836
                  20627866
                  21106027
                  21321429
                  21813400
                  21864513
                  21904072
                  22024071
                  22496904
                Refer to My Oracle Support Knowledge Document 1594274.1 for instructions.

Checking for existing adop sessions.
    Continuing with existing session [Session ID: 11].
    [UNEXPECTED]Master node for the current patching cycle is erpapp1erpapp1.
    [UNEXPECTED]Options such as "allnodes=yes" or "allnodes=no action=db" must be run from the master node.
    [UNEXPECTED]Unrecoverable error occurred. Exiting current adop session.


[STATEMENT] Please run adopscanlog utility, using the command

"adopscanlog -latest=yes"

to get the list of the log files along with snippet of the error message corresponding to each log file.


adop exiting with status = 2 (Fail)


Solution
-----------

login to apps user and perform the following tasks.

SQL> create table apps.ad_adop_sessions_bkp as select * from apps.ad_adop_sessions;

Table created.

SQL> update apps.ad_adop_sessions set NODE_NAME='target_node' where node_name='source_node';

9 rows updated.

SQL> commit;

Commit complete.

SQL>

Abort the patch session and restart:

$ adop phase=abort
$ adop phase=cleanup cleanup_mode=full

Windows perl script for Oracle Home

$
0
0
#!/usr/local/bin/perl



use Win32::Registry;

usage() if $#ARGV == -1;

my $Reg = "SOFTWARE\\Oracle\\ALL_HOMES";
my ($hakey, @key_list, $key);

$HKEY_LOCAL_MACHINE->Open($Reg,$hakey)|| die $!;
$hakey ->GetKeys(\@key_list);
$hakey->Close();
foreach $key (@key_list)
{
        #print "$key\n";
        &getpath("$Reg\\$key");
        setpath() if $found eq "TRUE";
}
notfound() if $found eq "FALSE";

sub notfound
{
 print "Sorry Oracle Home not found\n";
}

sub setpath
{
  $_ = $ENV{'PATH'};
  $newpath = $orapath."\\bin;";
  my @items = split /;/;
  $foundinpath = "FALSE";
  for ($i = 0; $i <= $#items; $i++)
  {
          if (uc($items[$i]) ne uc($orapath."\\bin"))
          {
           if ($i < $#items)
           {$newpath = $newpath.$items[$i].";";};
          }
          if (uc($items[$i]) eq uc($orapath."\\bin"))
          {
            $foundinpath = "TRUE";
          }
  }
if ($foundinpath eq "TRUE") {$newpath=$newpath.$items[$#items];};
#$ENV{'Path'} = $newpath;
print "set PATH=$newpath\n";
print "set ORACLE_HOME=$orapath";
exit ( 0 );
}

sub getpath
{
use Win32::Registry;
my %RegType = (
            0 => 'REG_0',
            1 => 'REG_SZ',
            2 => 'REG_EXPAND_SZ',
            3 => 'REG_BINARY',
            4 => 'REG_DWORD',
            5 => 'REG_DWORD_BIG_ENDIAN',
            6 => 'REG_LINK',
            7 => 'REG_MULTI_SZ',
            8 => 'REG_RESOURCE_LIST',
            9 => 'REG_FULL_RESOURCE_DESCRIPTION',
            10 => 'REG_RESSOURCE_REQUIREMENT_MAP');

my $Register = $_[0];
my $RegType, $RegValue, $RegKey, $value;
my %values;

$HKEY_LOCAL_MACHINE->Open($Register,$hkey)|| die $!;

$hkey->GetValues(\%values);
$found = "FALSE";

foreach $value (keys(%values))
    {
    $RegType     = $values{$value}->[1];
    $RegValue     = $values{$value}->[2];
    $RegKey     = $values{$value}->[0];
    next if ($RegType eq '');  #do not print default value if not assigned
    $RegKey     = 'Default' if ($RegKey eq '');    #name the default key
        if (uc($RegKey) eq uc("NAME"))
        {
        if (uc($RegValue) eq uc($ARGV[0])) {$found = "TRUE";};
        }
        if ($RegKey eq "PATH" and $found eq "TRUE")
        {
        $orapath = $RegValue;
        #print uc("$RegValue\n");
        };
    }
$hkey->Close();
}

sub usage {
  print STDERR <<EOM;
Usage: orasel.pl oracle_home
Example `orasel.pl ora920'
EOM
  exit( 0 );
}

alert_log_perl

$
0
0
#!/usr/local/bin/perl -w

# Description : This is the program to analyze the alert log
#               file and print out diagnostics.

format top =
                 LOG SWITCH REPORT
                 +++++++++++++++++
 Time                                    Sequence
 __________________                      _____________
.
format STDOUT =
@<<<<<<<<<<<<<<<<<<                      @<<<<<<<<<<<<
substr("$TEST",3,13), $SEQ[$#$SEQ]
.
if ( ! $ENV{"ALERT"} ) {
  print "Set enviornment variable ALERT to Alert Log file location ! \n";
  exit(1);
}

open (FH,$ENV{"ALERT"});
while (<FH>) {
    if (/Mon|Tue|Wed|Thu|Fri|Sat|Sun/) {
       $TEST = $_;
       next;
    }
    # This is global variable , Global because we use it in format statement
    # Convert Input line into array and print last element which is sequence number
    # $var[$#$var] is like $NF in awk
    @SEQ = split / /;
    write if /Thread.*advanced/;
}
close(FH);

Oracle alert log monitor

$
0
0
#!/usr/local/bin/perl -w

#  trlogmon.p - Oracle alert log monitor


=head1 NAME

trlogmon - Oracle alert log monitor

=head1 SYNOPSIS

trlogmon.p [-sleep <seconds>]

=head1 DESCRIPTION

Monitors the Oracle instance alert log for problems (i.e. ORA-00600, block
corruption errors, etc).

The log file is monitored in a manner similar to the B<UNIX tail(1)> command,
using the '-f' switch.  This is done by resetting the error flag on the file
when EOF is encountered.

Problems are extracted via the use of B<regexes> to find the interesting lines
in the alert log.

=head1  SEE ALSO

=over 4

=item 1

tail(1)

=item 2

The Perl Cookbook, ISBN 1-56592-243-3, Recipe #8.5, B<Tailing a Growing File>

=back 4

=head1 AUTHOR

Ron Reidy  rereidy@uswest.net

=cut

use strict;
use Carp;

use DBI;
use File::Basename;
use FileHandle;
use Getopt::Long;
use Net::SMTP;
use POSIX qw/uname/;

use vars qw/$dbh $scr $sleep_time/;

$scr = basename($0, '');

GetOptions('sleep:i', \$sleep_time);
$sleep_time = 60 if (!defined $sleep_time);

my $computer_name = (uname())[1];

$dbh = DBI->connect('dbi:Oracle:', 'wf_monitor', 'wf_monitor',
            {RaiseError => 0, PrintError => 0, AutoCommit => 0}) ||
       die "$scr: connect error on $computer_name [$DBI::errstr]";

my $alert_log = get_alert();
$dbh->disconnect;

my $alert_fh = new FileHandle $alert_log, "r";
die "$scr: cannot open \"$alert_log\" on $computer_name [$!]" if (!defined $alert_fh);

my @group;
my $starting = 0;

for (;;)
{
  while (<$alert_fh>)
  {
    # get a date tag for today
    my $today = localtime;
    $today =~ m/^(\S+\s+\S+\s+\d+)  # word (like Wed) followed by Mon and Day
        \s+\d+:\d+:\d+\s+   # the time - ignored
        (\d+)               # the year
           /x;

    my $today_date_tag = $1 . '' .$2;

    # make a date tag for the current line read
    my $log_date_tag;
    if (m/^(\S+\s+\S+\s+\d+)  # word (like Wed) followed by Mon and Day
          \s+\d+:\d+:\d+\s+   # the time - ignored
      (\d+)               # the year
     /x)
    {
      $log_date_tag = $1 . '' . $2 if (defined $1 && defined $2);

      next if ($today_date_tag ne $log_date_tag);

      if ($starting == 1)
      {
        if (check_group(\@group, "ORA\-"))
    {
      eval
      {
        my $smtp = Net::SMTP->new($::config->{email}->{SMTPHost});
        if (!defined $smtp)
        {
          die "$scr: cannot create Net::SMTP object on $computer_name [$!]";
        }

        if ($smtp->mail(localhost))
        $smtp->to("xyz@email.com"))
        {
          $smtp->data();
          $smtp->data("\nAlert log errors for $ENV{ORACLE_SID}:\n");
          $smtp->data(@group);
          $smtp->data("\n\n");
        }
        else
        {
          die "$scr: SMTP error for mail() or to() on $computer_name - " . $smtp->message;
            }

        $smtp->quit();

      };

      print STDERR "$@\n" if $@;

    }

        $#group = -1;
    $starting = 0;
      }

      $starting = 1;
      push @group, $_;
    }
    else
    {
      push @group, $_ if ($starting == 1);
    }
  }

  sleep $sleep_time;
  $alert_fh->clearerr();

}

exit 0;

END
{
  $dbh->disconnect if (defined $dbh);
  undef $alert_fh if (defined $alert_fh);
}

#
# check_group - check the group of lines for errors
#
sub check_group
{
  my $group_list = shift;
  my $_regex = shift;

  my $found = 0;

  foreach (@$group_list)
  {
    if (m/$_regex/)
    {
      $found = 1;
      last;
    }
  }

  return $found;

}  # end of check_group

#
# get_alert_log - get the location of the alert log from the RDBMS
#
sub get_alert
{
  my $sth = $dbh->prepare(q{
    SELECT value
    FROM   v$parameter
    WHERE  name = 'background_dump_dest'}) ||
      die "$scr: prepare error on $computer_name [$DBI::errstr]";

  $sth->execute;
  my $row = $sth->fetchrow_hashref;
  $sth->finish;

  return $row->{VALUE} . "/alert_" . $ENV{ORACLE_SID} . ".log";

}  # end of get_alert

Oracle Log Switch Analyzer

$
0
0
#!/usr/bin/perl -w


#
# Here's a little tool I put together to give you an idea of how often
# log switches are occurring on a database.
#
# This helps to pinpoint times of high activity.
#
# e.g.
#
#   lsa -filename alert_mydb.log -ignore 3600
#
#   lsa -instance mydb -ignore 1800
#
#   lsa -help
#
#
##########################################################################

use strict;
use Getopt::Long;
use Date::Manip;

my($result) = Getopt::Long::GetOptions(
        "instance:s",
        "lines-per-page:i" ,
        "filename:s",
        "ignore:i",
        "help",
        "debug!"
);


$main::opt_help = $main::opt_help;
if (
        ( ! $main::opt_instance && ! $main::opt_filename ) ||
        ( $main::opt_instance && $main::opt_filename ) ||
        $main::opt_help  )
{
        &usage;
        exit 1;
}

my $logFile;
if ( $main::opt_filename ) { $logFile = $main::opt_filename }
else {

        if ( ! defined $ENV{ORACLE_HOME} ) { die "Please set ORACLE_HOME\n" }
        my @o = split(/\//, $ENV{ORACLE_HOME});
        my $oracleBase = $o[1];
        $logFile = "/${oracleBase}/admin/${main::opt_instance}/bdump/alert_${main::opt_instance}.log" ;
}

open( LOG,$logFile ) || die " unable to open logfile $logFile - $!\n";

# set lines per page if sent
$= = $main::opt_lines_per_page if defined( $main::opt_lines_per_page );

# flush output
$| = 1;

my $lookForDate=0;
my ($newDate, $oldDate);
my ($newDateStr, $oldDateStr);
my $deltaStr = undef;
my $printDate = undef;

my $totalLogSwitchTime = undef;
my $totalLogSwitches = undef;
my $dateDelta = undef;

my $debug = undef;

$main::opt_debug = $main::opt_debug;
if ( $main::opt_debug ) { $debug = 1 }
else { $debug = 0}

my $ignoreTime = undef;
$ignoreTime = $main::opt_ignore if defined( $main::opt_ignore );

my @logSwitches ;

my $optionStr='';

$optionStr = "Instance=" . $main::opt_instance if $main::opt_instance;
$optionStr = "File=" . $main::opt_filename if $main::opt_filename;
$optionStr .= "  Ignore=$main::opt_ignore" if $main::opt_ignore;

$optionStr = 'Options: ' . $optionStr if $optionStr;

print STDERR "Working...";

while(<LOG>) {

        chomp;

        /Thread.*advanced/ &&do { $lookForDate = 1 };

        if ( $lookForDate ) {

                my $date = Date::Manip::ParseDate($_);
                $printDate = $_;

                if ( $date ) {

                        if ( defined( $newDate )) { $oldDate = $newDate; $oldDateStr = $newDateStr };
                        $newDate = $date;
                        $newDateStr = $_;

                        if ( defined( $newDate ) && defined( $oldDate ) ) {

                                my $err;
                                $dateDelta = Date::Manip::DateCalc($oldDate,$newDate,\$err,1);
                                my $weekDeltaStr = Date::Manip::Delta_Format($dateDelta,0,"%wv");
                                my $dayDeltaStr = Date::Manip::Delta_Format($dateDelta,0,"%dv");
                                my $hourDeltaStr = Date::Manip::Delta_Format($dateDelta,0,"%hv");
                                my $minuteDeltaStr = Date::Manip::Delta_Format($dateDelta,0,"%mv");
                                my $secondDeltaStr = Date::Manip::Delta_Format($dateDelta,0,"%sv");
                                $deltaStr =
                                        substr('00' . $weekDeltaStr,-2,2) . ':' .
                                        substr('00' . $dayDeltaStr,-2,2) . ':' .
                                        substr('00' . $hourDeltaStr,-2,2) . ':' .
                                        substr('00' . $minuteDeltaStr,-2,2) . ':' .
                                        substr('00' . $secondDeltaStr,-2,2) ;

                                #write;

                                print STDERR '.' if ! $debug;

                                my $currentLogSwitchTime =
                                        ($weekDeltaStr * 7 * 24 * 3600 ) +
                                        ($dayDeltaStr * 24 * 3600 ) +
                                        ($hourDeltaStr * 3600 ) +
                                        ($minuteDeltaStr * 60 ) +
                                        $secondDeltaStr;


                                $totalLogSwitchTime += $currentLogSwitchTime;
                                $totalLogSwitches++;
                                push(@logSwitches,[$printDate,$deltaStr]);

                                if ( $ignoreTime && ( $currentLogSwitchTime >= $ignoreTime ) ) {
                                        $totalLogSwitchTime -= $currentLogSwitchTime;
                                        $totalLogSwitches--;
                                        pop(@logSwitches);
                                }

                                $lookForDate = 0;

                        }

                        if ( $debug ) {
                                print STDERR "\tOLD DATE:  $oldDateStr\n";
                                print STDERR "\tNEW DATE:  $newDateStr\n";
                                print STDERR "\tDELTA:     $dateDelta\n";
                                print STDERR "\tDELTA STR: $deltaStr\n";
                                print STDERR "\t------------------\n";
                        }

                }
        }

}

print STDERR "\n\n";

my $el;
for $el ( 0 .. $#logSwitches ) {
        #print "EL: $el\n";
        #print "Date : $logSwitches[$el]->[0]\n";
        #print "Delta: $logSwitches[$el]->[1]\n";
        #print "----------------\n";
        write;
}

print "\n\n";


my $avgLogSwitchSeconds = int($totalLogSwitchTime / $totalLogSwitches);
my $avgLogSwitchMinutes = int( ($totalLogSwitchTime / $totalLogSwitches) / 60 );

print "Total Logswitches:         $totalLogSwitches\n";
print "Avg Log Switch Frequency:  $avgLogSwitchMinutes Minutes and ",  $avgLogSwitchSeconds%60, " Seconds\n\n";


format top =

     Log Switch Frequency

@<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
$optionStr

                          Elapsed Time
Logswitch                 WW:DD:HH:MM:SS
------------------------  --------------
.

format STDOUT =
@<<<<<<<<<<<<<<<<<<<<<<<  @<<<<<<<<<<<<<<
$logSwitches[$el]->[0], $logSwitches[$el]->[1]
.

sub usage {
        print <<EOF

lsa - Log Switch Analyzer
   lsa will read your alert.log file, or a specified file.
   either the -filename or -instance option must be specified.
   options are:

        instance       - which Oracle instance
        filename       - filename to read log switch info
        lines-per-page - how many lines per page to print
                    default is 60
        ignore         - ignore log switches where elapsed
                    time is N seconds.  Useful to target
                    only peak periods of activity in
                    the alert log.


EOF
}

TNS_NAME_PERL

$
0
0
#! /usr/local/bin/perl

# ----------------------------------------------------------------------------
#  Read an Oracle TNSNAMES.ORA file and load the definitions into a list
#  of Oracle Name Servers. This is similar to executing the LOAD_TNSNAMES
#  command, available from Oracle8i, on all Name Servers.
#
#  Usage: ./namesload.pl | namesctl


$TNSNAMES = "./tnsnames.ora";
@NAMESERVERS = (oranamesrvr0,oranamesrvr1,oranamesrvr2);

foreach $NS (@NAMESERVERS) {
        print "\nset server " . $NS . "\n\n";
        &register_name_servers;
        &load_tnsnames;
}
print "\n\nexit\n";
exit;

#--------------------------------------------------------------------------
sub register_name_servers {
   #
   # Register all NameServers. The defualt port is 1575.
   #
   print "register oranamesrvr0.world -t ORACLE_NAMESERVER -d " .
        "(ADDRESS=(PROTOCOL=TCP)(HOST=oranamesrvr0)(PORT=1575))\n\n";
   print "register oranamesrvr1.world -t ORACLE_NAMESERVER -d " .
        "(ADDRESS=(PROTOCOL=TCP)(HOST=oranamesrvr1)(PORT=1575))\n\n";
   print "register oranamesrvr2.world -t ORACLE_NAMESERVER -d " .
                "(ADDRESS=(PROTOCOL=TCP)(HOST=oranamesrvr2)(PORT=1575))\n";
}

#--------------------------------------------------------------------------
sub load_tnsnames {
   #
   # Read the TNSNAMES.ORA file and generate NAMESCTL register commands
   #
   $service = "";
   open(FIL, $TNSNAMES);
   while (<FIL>) {
        if ( substr($_, 0, 1) eq '#' ) {
                # Ignore comments...
        } elsif ( substr($_, 0, 1) eq '' || substr($_, 1, 1) eq '\t' ) {
                s/ //g; s/\n//g;
                $body = $body . $_;
        } else {
           if ( $service ne "" ) {
              print "\n\nREGISTER ".$service." -t ORACLE_DATABASE -d ".$body;
           }
           $service = substr($_, 0, index($_, ''));
           $body    = '';
        }
   }
   print "\n\nREGISTER ".$service." -t ORACLE_DATABASE -d ".$body;
   close(FIL);
}

#EOF

Cloninig scripts

$
0
0
#!/bin/ksh
##  Script to auto clone DOYENSYS RMANDuplicate

/bin/mailx -s "RPT:-DOYEN CLONING PROCESS Started at :-`date` " $NOTIFY_LIST <$LOGFILE
NOTIFY_LIST="gangai.nathan@doyensys.com
LOGFILE=/export/home/oracle/CLONE/DOYEN/logs/DOYEN_CLONE.txt
LOGFILE1=/export/home/oracle/CLONE/DOYEN/logs/rman_clone.txt
echo "Start of DOYEN CLONE  CREATION  at `date +%D-%T`">$LOGFILE
echo "Beginning Maintenance Window for OEM DOYEN  at `date +%D-%T`">>$LOGFILE
. /orahome/env/oracle_Agent12C_env
cd $ORACLE_HOME/bin
./emctl start blackout DOYEN_CLONE DOYEN
echo "Ending Maintenance Window for OEM DOYEN  at `date +%D-%T`">>$LOGFILE

# ENV file
. /orahome/env/oracle_Atltrg_11g_env

# Stopping Listeners For preparation of Cloning
echo "Stopping LISTENER DOYEN PROCESS  at `date +%D-%T`">>$LOGFILE
sh -x /export/home/oracle/oraprocs/DOYEN/stop_listener.sh
cat /export/home/oracle/oraprocs/DOYEN/logs/stop_ATLTRG_LISTENER.txt >>$LOGFILE
echo "Stopping LISTENER DOYEN PROCESS  at `date +%D-%T`">>$LOGFILE

echo "Beginning Dropping Database DOYEN  at `date +%D-%T`">>$LOGFILE
${ORACLE_HOME}/bin/sqlplus -s "/ as sysdba"<<-EOF >>$LOGFILE
shutdown immediate;
startup nomount;
alter database mount exclusive;
alter system enable restricted session;
drop database;
EOF
echo "Finished Dropping Database  DOYEN at `date +%D-%T`">>$LOGFILE

echo " Starting DB in nomount state ">>$LOGFILE
echo "Beginning Starting Database DOYEN in MOUNT STATE  at `date +%D-%T`">>$LOGFILE
${ORACLE_HOME}/bin/sqlplus -s "/ as sysdba"<<-EOF >>$LOGFILE
startup nomount pfile='/orahome/app/oracle/product/11204/DOYEN/dbs/initATLTRG.ora';
create spfile from pfile='/orahome/app/oracle/product/11204/DOYEN/dbs/initATLTRG.ora';
EOF
echo "End of Starting Database ATLLTRG in MOUNT STATE  at `date +%D-%T`">>$LOGFILE

# Starting CLONE Listeners For preparation of Cloning
echo "Starting LISTENER DOYEN PROCESS  at `date +%D-%T`">>$LOGFILE
sh -x /u01/home/oracle/CLONE/DOYENSYS/start_listener_CLONE.sh
cat /u01/home/oracle/CLONE/DOYENSYS/logs/start_ATLTRG_LISTENER.txt >>$LOGFILE
echo "Starting LISTENER DOYEN PROCESS  at `date +%D-%T`">>$LOGFILE


echo " Starting RMAN CLONE PROCESS at `date +%D-%T`">>$LOGFILE
$ORACLE_HOME/bin/rman target /@ATLPROD_DD_RESTORE auxiliary / CMDFILE /u01/home/oracle/CLONE/DOYENSYS/SQL/rman_clone.sql LOG $LOGFILE1
echo " Starting RMAN CLONE PROCESS END at `date +%D-%T`">>$LOGFILE
echo " LOGS FOR RMAN CLONE DUMP "
echo "===================================================="
echo "===================================================="
cat /u01/home/oracle/CLONE/DOYENSYS/logs/rman_clone.txt >>$LOGFILE
echo "===================================================="
echo "===================================================="
echo " LOGS FOR RMAN CLONE DUMP "

echo " Starting DB in nomount state at `date +%D-%T` ">>$LOGFILE
echo "Beginning Starting Database DOYEN in FOR PFILE CREATION at `date +%D-%T`">>$LOGFILE
${ORACLE_HOME}/bin/sqlplus -s "/ as sysdba"<<-EOF >>$LOGFILE
shutdown immediate;
startup mount;
alter database noarchivelog;
alter database open;
EOF
echo "End of Starting Database ATLLTRG in OPEN STATE  at `date +%D-%T`">>$LOGFILE

# Starting Listeners After Cloning
echo "Starting LISTENER DOYEN PROCESS  at `date +%D-%T`">>$LOGFILE
sh -x /u01/home/oracle/CLONE/DOYENSYS/start_listener.sh
cat /u01/home/oracle/CLONE/DOYENSYS/logs/start_ATLTRG_LISTENER.txt >>$LOGFILE
echo "Starting LISTENER DOYEN PROCESS Ended at `date +%D-%T`">>$LOGFILE

echo "Starting of POST CLONE Database ACTIVITY at `date +%D-%T`">>$LOGFILE
${ORACLE_HOME}/bin/sqlplus -s "/ as sysdba"<<-EOF >>$LOGFILE
PROMPT DROPPING THE PUBLIC SYNONYNMS
@/u01/home/oracle/CLONE/DOYENSYS/SQL/post_clone.sql
@/u01/home/oracle/CLONE/DOYENSYS/SQL/list.sql
EOF

echo " Starting of POST CLONE Database ACTIVITY :- Dropping Private DB Links at `date +%D-%T`">>$LOGFILE
sh -x /u01/home/oracle/CLONE/DOYENSYS/drop_dblink.sh /u01/home/oracle/CLONE/DOYENSYS/SQL/list.log
cat /u01/home/oracle/CLONE/DOYENSYS/logs/drop_dblink_unixscript.txt >> $LOGFILE
echo " Starting of POST CLONE Database ACTIVITY Finished :- Dropping Private DB Links at `date +%D-%T`">>$LOGFILE

echo "Starting of POST CLONE1 Database ACTIVITY at `date +%D-%T`">>$LOGFILE
${ORACLE_HOME}/bin/sqlplus -s "/ as sysdba"<<-EOF >>$LOGFILE
PROMPT DROPPING THE PUBLIC SYNONYNMS
@/export/home/oracle/CLONE/DOYEN/SQL/post_clone1.sql
EOF

echo "LOGS for POST CLONE Database ACTIVITY at `date +%D-%T`">>$LOGFILE
cat /u01/home/oracle/CLONE/DOYENSYS/logs/drop_dblink.txt >>$LOGFILE
cat /u01/home/oracle/CLONE/DOYENSYS/logs/post_clone.txt >>$LOGFILE
echo "LOGS for POST CLONE Database ACTIVITY Ended at `date +%D-%T`">>$LOGFILE

# Stopping CLONE Listeners For preparation of Cloning
echo "Stopping LISTENER DOYEN PROCESS  at `date +%D-%T`">>$LOGFILE
sh -x /u01/home/oracle/CLONE/DOYENSYS/stop_listener_CLONE.sh
cat /u01/home/oracle/CLONE/DOYENSYS/logs/stop_ATLTRG_LISTENER.txt >>$LOGFILE
echo "Stopping LISTENER DOYEN PROCESS Ended at `date +%D-%T`">>$LOGFILE
echo "End of ATLLTRG CREATION  at `date +%D-%T`">>$LOGFILE

echo "Beginning Stopping Maintenance Window for OEM DOYEN  at `date +%D-%T`">>$LOGFILE
. /orahome/env/oracle_Agent12C_env
cd $ORACLE_HOME/bin
./emctl stop blackout DOYEN_CLONE
echo "Ending Maintenance Window for OEM DOYEN  at `date +%D-%T`">>$LOGFILE

/bin/mailx -s "RPT:-DOYEN CLONING PROCESS Ended at :-`date` " $NOTIFY_LIST <$LOGFILE

set `date`
cp $LOGFILE $LOGFILE.$2$3$4

ASMCMD copy command fails with ORA 15046

$
0
0
Error:

ORA-15046: ASM file name '+DGEXTBK/prod/datafile/tbsext.256.628847401' is not in single-file creation form

ASMCMD> cp +DGEXT/orcl/datafile/tbsext.256.628847401 +DGEXTBK/prod/datafile/tbsext.257.628847401

source +DGEXT/orcl/datafile/tbsext.256.628847401
target +DGEXTBK/prod/datafile/tbsext.257.628847401
ASMCMD-08015: can not create file->'+DGEXTBK/prod/datafile/tbsext.257.628847401'
ORA-15056: additional error message
ORA-17502: ksfdcre:4 Failed to create file +DGEXTBK/prod/datafile/tbsext.257.628847401
ORA-15046: ASM file name '+DGEXTBK/prod/datafile/tbsext.257.628847401' is not in single-file creation form
ORA-06512: at "SYS.X$DBMS_DISKGROUP", line 142
ORA-06512: at line 3 (DBD ERROR: OCIStmtExecute)
ASMCMD-08016: copy source->'+DGEXT/orcl/datafile/tbsext.256.628847401' and target->'+DGEXTBK/prod/datafile/tbsext.257.628847401' failed

Solution:

Checking Metalink Note # 452158.1 I saw that the ASMCMD  cp command fails because the ASM file name was not in a form that can be used to create an single file. File name should not contain the file number/incarnation.

The cp command failed because the ASM file name was not in a form that can be used to create an single file.File name should not contain the file number/incarnation


ASMCMD> cp +DGEXT/orcl/datafile/tbsext.256.628847401 +DGEXTBK/prod/datafile/tbsext 
source +DGEXT/orcl/datafile/tbsext.256.628847401 
target +DGEXTBK/prod/datafile/tbsext 
copying file(s)...file, +DGEXTBK/prod/datafile/tbsext, copy committed.

Removing an instance and database binaries in RAC setup

$
0
0
Remove RAC Database Instance(s)

From RAC1,
            
        $dbca

                select Instance_management->delete_instance->select database(prod) give sys/manager-
[oracle@rac1 ~]$ srvctl config database -d prod 

Remove RAC Database Software

In this step, the Oracle RAC database software will be removed from the node that will be deleted. Additionally, the inventories of the remaining nodes will be updated to reflect the removal of the node’s Oracle RAC database software home, etc.

Any listener running on "rac3" will need to be stopped.

[oracle@rac3 ~]$ srvctl disable listener -n rac3  
[oracle@rac3 ~]$ srvctl stop listener -n rac3

Update inventory on "rac3"  

[oracle@rac3 ~]$ . rdbms
[oracle@rac3 ~]$ cd $ORACLE_HOME/oui/bin
[oracle@rac3 bin]$ ./runInstaller -updateNodeList ORACLE_HOME=$ORACLE_HOME "CLUSTER_NODES={rac3}"
                               -local  

Remove the RAC Database(RDBMS_HOME)Software from "rac3"

[oracle@rac3 ~]$ . rdbms
[oracle@rac3 ~]$ cd $ORACLE_HOME/deinstall  
[oracle@rac3 deinstall]$ ./deinstall -local  

Note:Make sure to specify the "-local" flag as not to remove more than just the local node’s software, etc.
Update inventories/node list on the remaining nodes.

 Update inventories list on the remaining nodes.

[oracle@rac1 ~]$ . rdbms
[oracle@rac1 ~]$ cd $ORACLE_HOME/oui/bin  

[oracle@rac1 bin]$ ./runInstaller -updateNodeList ORACLE_HOME=$ORACLE_HOME  "CLUSTER_NODES={rac1,rac2}"  

Removing GRID binaries in RAC environment

$
0
0
Removing Clusterware binaries(GRID_HOME) from RAC3

Disable the Clusterware on "rac3" as root

[root@rac3 ~]# /u01/app/11.2.0/grid/crs/install/rootcrs.pl -deconfig -force  

Delete "rac3" node from Clusterware configuration (on a remaining node)

[root@rac1 ~]# /u01/app/11.2.0/grid/bin/crsctl delete node -n rac3  

Update inventory on "rac3"

[oracle@rac3 ~]$ . grid.env
[oracle@rac3 ~]$ cd $ORACLE_HOME/oui/bin
[oracle@rac3 bin]$ ./runInstaller -updateNodeList ORACLE_HOME=$ORACLE_HOME  "CLUSTER_NODES={rac3}" CRS=TRUE -local  

Remove the Clusterware Software from "rac3"

[oracle@rac3 ~]$ . grid.env
[oracle@rac3 ~]$ cd $ORACLE_HOME/deinstall  
[oracle@rac3 deinstall]$ ./deinstall -local  

Note:Make sure to specify the "-local" flag as not to remove more than just the local node’s software, etc.
The script will provide commands to be run as "root", in another window.

Update inventories/node list on the remaining nodes.

[oracle@rac1 ~]$ . grid.env
[oracle@rac1 ~]$ cd $ORACLE_HOME/oui/bin  
[oracle@rac1 bin]$ ./runInstaller -updateNodeList ORACLE_HOME=$ORACLE_HOME  "CLUSTER_NODES={rac1,rac2}" CRS=TRUE 

Confirm that the node has been properly removed via.


[oracle@rac1 ~]$ cluvfy stage -post nodedel -n rac3

To restore a failed patch in opatch apply

$
0
0

Restoring Oracle Homes

Every time you apply a patch, you make changes to your inventory. Sometimes that change may corrupt the inventory. You can use the restore.sh or restore.bat script that comes with OPatch to remove any changes that were made to the inventory after the patch application.
When you apply a patch, OPatch creates a snapshot of your inventory and stores it in $ORACLE_HOME/.patch_storage/<patch-id_timestamp> directory. OPatch 10.2 supports maintaining versions of patches. You can have two or more different versions of the same patch (with the same patch ID). This version information is stored in the OPatch metadata.
If your inventory is corrupted, you need to perform the following steps to return the application to its last known good state:
  1. Ensure that the environment variable ORACLE_HOME is set properly.
  2. Navigate to the $ORACLE_HOME/.patch_storage/<patch-id_timestamp> directory and execute the restore command:
    For UNIX:
    $ORACLE_HOME/.patch_storage/<patch-id_timestamp>/restore.sh

No need of ocm.rsp file for Grid Patching

$
0
0

OPatch 12c: emocmrsp missing from OPatch/ocm/bin


So far while applying PSU or one off patches, we use to pass -ocmrf parameter.  I could not think of a scenario where we are going to expose database servers to external world.

Before applying latest PSU, I downloaded latest opatch p6880880_122010_AIX64-5L.zip from metalink. Post unzip, I wanted to create ocm.rsp. But when checked, OPatch/ocm/bin was empty. Binary emocmrsp was missing.

OPatch/ocm/bin>ls -ltra
total 0

As per Metalink Doc ID 2161861.1

This enhancement to OPatch exists in 12.2.0.1.5 release and later. The option -ocmrf is used to provide OPatch the OCM responses during a silent install. Since OCM is no longer packaged with OPatch, the -ocmrf is no longer needed on the command line.

As per Metalink Doc ID 1591616.1

Note: as latest opatch doesn’t contain OCM anymore, the option “-ocmrf” is unnecessary if latest opatch is being used, refer to the following for details:
note 2161861.1 – OPatch: Behavior Changes starting in OPatch 12.2.0.1.5 and 11.2.0.3.14 releases

So this is expected behavior.

Simply use following CLI for applying the patch

# opatchauto apply <UNZIPPED_PATCH_LOCATION>/24412235

Managing tracefiles using ADRCI

$
0
0
Managing and purging tracefiles:
Now to the management of tracefiles. You may notice that 11g creates lots of tracefiles that need to be purged from time to time. In fact, this is done automatically, but you may want to change the default purge policy:
adrci> show tracefile -rt

 01-JUN-11 10:31:48  diag/rdbms/orcl/orcl/trace/orcl_mmon_2106.trc
 01-JUN-11 09:43:43  diag/rdbms/orcl/orcl/trace/orcl_ckpt_2100.trc
 01-JUN-11 09:22:13  diag/rdbms/orcl/orcl/trace/alert_orcl.log
 01-JUN-11 09:22:11  diag/rdbms/orcl/orcl/trace/orcl_diag_2088.trc
 01-JUN-11 09:22:10  diag/rdbms/orcl/orcl/trace/orcl_ora_2299.trc
 01-JUN-11 09:22:10  diag/rdbms/orcl/orcl/incident/incdir_6201/orcl_ora_2299_i6201.trc
 01-JUN-11 09:18:47  diag/rdbms/orcl/orcl/trace/orcl_ora_2236.trc
 01-JUN-11 09:18:47  diag/rdbms/orcl/orcl/incident/incdir_6153/orcl_ora_2236_i6153.trc
 01-JUN-11 09:17:19  diag/rdbms/orcl/orcl/trace/orcl_dbrm_2090.trc

adrci> show control

ADR Home = /u01/app/oracle/diag/rdbms/orcl/orcl:
*************************************************************************
ADRID                SHORTP_POLICY        LONGP_POLICY         LAST_MOD_TIME                            LAST_AUTOPRG_TIME                        LAST_MANUPRG_TIME                        ADRDIR_VERSION       ADRSCHM_VERSION      ADRSCHMV_SUMMARY     ADRALERT_VERSION     CREATE_TIME                              
-------------------- -------------------- -------------------- ---------------------------------------- ---------------------------------------- ---------------------------------------- -------------------- -------------------- -------------------- -------------------- ----------------------------------------
1335663986           720                  8760                 2011-05-27 10:16:46.997118 +02:00                                                                                          1                    2                    80                   1                    2011-05-27 10:16:46.997118 +02:00       
1 rows fetched

The ordinary tracefiles will stay for 30 days (720 hours), while files like incident files stay one year (8760 hours) by default. We can change that policy with for example:


adrci> set control (SHORTP_POLICY = 360)   

adrci> set control (LONGP_POLICY = 4380)   

adrci> show control
ADR Home = /u01/app/oracle/diag/rdbms/orcl/orcl:
*************************************************************************
ADRID                SHORTP_POLICY        LONGP_POLICY         LAST_MOD_TIME                            LAST_AUTOPRG_TIME                        LAST_MANUPRG_TIME                        ADRDIR_VERSION       ADRSCHM_VERSION      ADRSCHMV_SUMMARY     ADRALERT_VERSION     CREATE_TIME
-------------------- -------------------- -------------------- ---------------------------------------- ---------------------------------------- ---------------------------------------- -------------------- -------------------- -------------------- -------------------- ----------------------------------------
1335663986           360                  4380                 2011-06-01 11:42:17.208064 +02:00                                                                                          1                    2                    80                   1                    2011-05-27 10:16:46.997118 +02:00
1 rows fetched



Also, we may want to purge tracefiles manually. Following command will manually purge all tracefiles older than 2 days (2880 minutes):
adrci> purge -age 2880 -type trace

Script to get the bind Variable for a given sql statement

$
0
0
SETPAUSEON
SETPAUSE'Press Return to Continue'
SETPAGESIZE60
SETLINESIZE300

COLUMNsql_textFORMATA120
COLUMNsql_idFORMATA13
COLUMNbind_nameFORMATA10
COLUMNbind_valueFORMATA26

SELECT
sql_id,
t.sql_textsql_text,
b.namebind_name,
b.value_stringbind_value
FROM
v$sqlt
JOIN
v$sql_bind_capturebusing(sql_id)
WHERE
b.value_stringisnotnull
AND
sql_id='&sqlid'
/

Steps to create trigger to trace a user session

$
0
0
CREATEORREPLACETRIGGERUSER_TRACE_TRG
AFTERLOGONONDATABASE
BEGIN
IFUSER = '&USER_ID'
THEN
executeimmediate'alter session set events ''10046 trace name context forever,
    level 12''';
ENDIF;
EXCEPTION
WHENOTHERSTHEN
NULL;
END;
/

Script to get the details about Index Fragmentation

$
0
0
ACCEPTMySchemaPROMPT'Enter schema to be analysed: '

settermoff
setfeedbackoff

droptableanalyze_strut_commands

createtableanalyze_strut_commands(
line_idnumber,
sql_textvarchar2(2000));

droptablefrag_stats_all

createtablefrag_stats_allas
select *
fromindex_stats
where1 = 2;

settermon
promptcreatingvalidationscripts ...
settermoff

declare
cursorind_curIS
selectowner
,
index_name
fromdba_indexeswhereowner=upper('&&MySchema')
orderbyowner
,
index_name;

l_sql_textvarchar2(500);
l_curr_line_idnumber(38) := NULL;

begin
declare
functionwrite_out(
p_line_idINNUMBER,
p_sql_textINVARCHAR2)returnNUMBER
is
l_line_idnumber(38) := null;
begin
insertintoanalyze_strut_commands
values(p_line_id,p_sql_text);
commit;
l_line_id := p_line_id + 1;
return(l_line_id);
endwrite_out;
begin
l_curr_line_id := write_out(1,'-- start');
forind_recinind_curLOOP
--
-- Firs get the prompts

--
l_sql_text := 'prompt ... processing index '||

ind_rec.owner||
'.'||
ind_rec.index_name||
' ...';
l_curr_line_id := write_out(l_curr_line_id,l_sql_text);
--
-- Second get the analyze commands

--
l_sql_text := 'analyze index '||

ind_rec.owner||
'.'||
ind_rec.index_name||
' validate structure;';
l_curr_line_id := write_out(l_curr_line_id,l_sql_text);
--
-- Third get the current statistics before it gets overwritten

--
l_sql_text := 'insert into frag_stats_all select * from index_stats;';

l_curr_line_id := write_out(l_curr_line_id,l_sql_text);
endloop;
--
-- commit the whole thing

--
l_curr_line_id := write_out(l_curr_line_id,'commit;');

end;
end;
/

setpages0
colsql_textformata132

selectsql_textfromanalyze_strut_commands
orderbyline_id

spoolind.tmp
/
spooloff

settermon
promptrunningvalidationscripts ...

@
ind.tmp

droptableanalyze_strut_commands
/

!
rmind.tmp

setpauseon;
pausePressanykeytoreviewtheresults
setpauseoff

SETVERIFYOFF
SETFEEDBACKOFF

COLnameHEA'Index Name'FORa30
COLdel_lf_rowsHEAd'Deleted|Leaf Rows'FOR99999999
COLlf_rows_usedHEA'Used|Leaf Rows'FOR99999999
COLratioHEAd'% Deleted|Leaf Rows'FOR999.99999

SETVERIFYON
SETFEEDBACKON

SELECT
name, del_lf_rows, lf_rows - del_lf_rowslf_rows_used,
DECODE(lf_rows,0,0,TO_CHAR(del_lf_rows / (lf_rows)*100,'999.99999'))ratio
FROM
frag_stats_all
ORDERBY
4
/
Viewing all 1640 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>