Tuesday, February 18, 2020

RMAN Duplicate from Active Database - ASM to Non-ASM filesystem

RMAN Duplicate from Active Database - ASM to Non-ASM



copy password file from source  to target 
================================================

scp orapwindia oracle@192.168.1.112:/u01/app/oracle/product/11.2.0/dbhome_1/dbs/orapwhrprd

Source LISTENER
===================

[oracle@localhost ~]$ cat /u01/app/grid/product/18.0.0/grid_home/network/admin/listener.ora
# listener.ora Network Configuration File: /u01/app/grid/product/18.0.0/grid_home/network/admin/listener.ora
# Generated by Oracle configuration tools.

#Backup file is  /u01/app/grid/product/18.0.0/grid_home/srvm/admin/listener.ora.bak.localhost line added by Agent

VALID_NODE_CHECKING_REGISTRATION_LISTENER = ON

LISTENER =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.108)(PORT = 1521))
  )

ADR_BASE_LISTENER = /u01/app/grid

ENABLE_GLOBAL_DYNAMIC_ENDPOINT_LISTENER = ON

[oracle@localhost ~]$



Source tnsnames.ora
======================

[oracle@localhost admin]$ cat tnsnames.ora
# tnsnames.ora Network Configuration File: /u01/app/oracle/product/11.2.0/dbhome_1/network/admin/tnsnames.ora
# Generated by Oracle configuration tools.

INDIA =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.108)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = india)
    )
  )


HRPRD =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.112)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVICE_NAME = hrprd)
    )
  )

[oracle@localhost admin]$




Target listener
======================

[oracle@localhost pfile]$ cat /u01/app/oracle/product/11.2.0/dbhome_1/network/admin/listener.ora
# listener.ora Network Configuration File: /u01/app/oracle/product/11.2.0/dbhome_1/network/admin/listener.ora
# Generated by Oracle configuration tools.

LISTENER =
  (DESCRIPTION_LIST =
    (DESCRIPTION =
      (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
      (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.112)(PORT = 1521))
    )
  )

SID_LIST_LISTENER =
  (SID_LIST =
    (SID_DESC =
      (GLOBAL_DBNAME = hrprd)
      (ORACLE_HOME = /u01/app/oracle/product/11.2.0/dbhome_1)
      (SID_NAME = hrprd)
    )
  )
ADR_BASE_LISTENER = /u01/app/oracle

[oracle@localhost pfile]$


target TNsnames.ora
=======================

[oracle@localhost admin]$ cat tnsnames.ora
# tnsnames.ora Network Configuration File: /u01/app/oracle/product/11.2.0/dbhome_1/network/admin/tnsnames.ora
# Generated by Oracle configuration tools.

HRPRD =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.112)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVICE_NAME = hrprd)
    )
  )




INDIA =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.108)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = india)
    )
  )



[oracle@localhost admin]$



target init file 
===================


[oracle@localhost pfile]$ cat inithrprd.ora
db_name=hrprd
[oracle@localhost pfile]$

set local listener on target 
===================================

alter system set local_listener='(ADDRESS = (PROTOCOL=TCP)(HOST=192.168.1.108)(PORT=1521))' scope=both;

create directory on target 
===============================


mkdir -p /u01/app/oracle/admin/hrprd/adump
mkdir -p /u01/app/oracle/fast_recovery_area/hrprd
mkdir -p /u01/app/oracle/oradata/hrprd
mkdir -p /u01/app/oracle/oradata/hrprd

start the target database
=================================

startup nomount pfile=/u01/app/oracle/admin/hrprd/pfile/inithrprd.ora


connect with rman on target
=============================


rman target sys/sys@india auxiliary sys/sys@hrprd




check source file location 
================================

select name from v$datafile
  union all
  select name from v$tempfile
  union all
  select name from v$controlfile
  union all
  select member from v$logfile;


Active dupliacte command
=================================

run
{
         
         DUPLICATE TARGET DATABASE TO "hrprd"
         FROM ACTIVE DATABASE
         DB_FILE_NAME_CONVERT '+DATA1/india/datafile','/u01/app/oracle/oradata/hrprd','+DATA1/india/tempfile','/u01/app/oracle/oradata/hrprd'
         SPFILE
         SET LOG_FILE_NAME_CONVERT '+DATA1/india/onlinelog','/u01/app/oracle/oradata/hrprd'
         SET AUDIT_FILE_DEST '/u01/app/oracle/admin/hrprd/adump'
         SET CONTROL_FILES '/u01/app/oracle/oradata/hrprd/control01.ctl'
         SET DB_RECOVERY_FILE_DEST '/u01/app/oracle/fast_recovery_area/hrprd'
         SET DB_CREATE_FILE_DEST '/u01/app/oracle/oradata/hrprd'
SET db_create_online_log_dest_1 '/u01/app/oracle/oradata/hrprd'
         SET DIAGNOSTIC_DEST '/u01/app/oracle/diag';
}




Duplicate log 
================

RMAN> run
{

         DUPLICATE TARGET DATABASE TO "hrprd"
         FROM ACTIVE DATABASE
         DB_FILE_NAME_CONVERT '+DATA1/india/datafile','/u01/app/oracle/oradata/hrprd','+DATA1/india/tempfile','/u01/app/oracle/oradata/hrprd'
         SPFILE
         SET LOG_FILE_NAME_CONVERT '+DATA1/india/onlinelog','/u01/app/oracle/oradata/hrprd'
         SET AUDIT_FILE_DEST '/u01/app/oracle/admin/hrprd/adump'
         SET CONTROL_FILES '/u01/app/oracle/oradata/hrprd/control01.ctl'
         SET DB_RECOVERY_FILE_DEST '/u01/app/oracle/fast_recovery_area/hrprd'
         SET DB_CREATE_FILE_DEST '/u01/app/oracle/oradata/hrprd'
                 SET db_create_online_log_dest_1 '/u01/app/oracle/oradata/hrprd'
2> 3> 4> 5> 6> 7> 8> 9> 10> 11> 12> 13> 14>          SET DIAGNOSTIC_DEST '/u01/app/oracle/diag';
}
15>
Starting Duplicate Db at 18-FEB-20
using target database control file instead of recovery catalog
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: SID=19 device type=DISK

contents of Memory Script:
{
   backup as copy reuse
   targetfile  '+DATA1/india/spfileindia.ora' auxiliary format
 '/u01/app/oracle/product/11.2.0/dbhome_1/dbs/spfilehrprd.ora'   ;
   sql clone "alter system set spfile= ''/u01/app/oracle/product/11.2.0/dbhome_1/dbs/spfilehrprd.ora''";
}
executing Memory Script

Starting backup at 18-FEB-20
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=48 device type=DISK
Finished backup at 18-FEB-20

sql statement: alter system set spfile= ''/u01/app/oracle/product/11.2.0/dbhome_1/dbs/spfilehrprd.ora''

contents of Memory Script:
{
   sql clone "alter system set  db_name =
 ''HRPRD'' comment=
 ''duplicate'' scope=spfile";
   sql clone "alter system set  LOG_FILE_NAME_CONVERT =
 ''+DATA1/india/onlinelog'', ''/u01/app/oracle/oradata/hrprd'' comment=
 '''' scope=spfile";
   sql clone "alter system set  AUDIT_FILE_DEST =
 ''/u01/app/oracle/admin/hrprd/adump'' comment=
 '''' scope=spfile";
   sql clone "alter system set  CONTROL_FILES =
 ''/u01/app/oracle/oradata/hrprd/control01.ctl'' comment=
 '''' scope=spfile";
   sql clone "alter system set  db_recovery_file_dest =
 ''/u01/app/oracle/fast_recovery_area/hrprd'' comment=
 '''' scope=spfile";
   sql clone "alter system set  DB_CREATE_FILE_DEST =
 ''/u01/app/oracle/oradata/hrprd'' comment=
 '''' scope=spfile";
   sql clone "alter system set  db_create_online_log_dest_1 =
 ''/u01/app/oracle/oradata/hrprd'' comment=
 '''' scope=spfile";
   sql clone "alter system set  DIAGNOSTIC_DEST =
 ''/u01/app/oracle/diag'' comment=
 '''' scope=spfile";
   shutdown clone immediate;
   startup clone nomount;
}
executing Memory Script

sql statement: alter system set  db_name =  ''HRPRD'' comment= ''duplicate'' scope=spfile

sql statement: alter system set  LOG_FILE_NAME_CONVERT =  ''+DATA1/india/onlinelog'', ''/u01/app/oracle/oradata/hrprd'' comment= '''' scope=spfile

sql statement: alter system set  AUDIT_FILE_DEST =  ''/u01/app/oracle/admin/hrprd/adump'' comment= '''' scope=spfile

sql statement: alter system set  CONTROL_FILES =  ''/u01/app/oracle/oradata/hrprd/control01.ctl'' comment= '''' scope=spfile

sql statement: alter system set  db_recovery_file_dest =  ''/u01/app/oracle/fast_recovery_area/hrprd'' comment= '''' scope=spfile

sql statement: alter system set  DB_CREATE_FILE_DEST =  ''/u01/app/oracle/oradata/hrprd'' comment= '''' scope=spfile

sql statement: alter system set  db_create_online_log_dest_1 =  ''/u01/app/oracle/oradata/hrprd'' comment= '''' scope=spfile

sql statement: alter system set  DIAGNOSTIC_DEST =  ''/u01/app/oracle/diag'' comment= '''' scope=spfile

Oracle instance shut down

connected to auxiliary database (not started)
Oracle instance started

Total System Global Area    2371719168 bytes

Fixed Size                     2255512 bytes
Variable Size                587203944 bytes
Database Buffers            1778384896 bytes
Redo Buffers                   3874816 bytes

contents of Memory Script:
{
   sql clone "alter system set  db_name =
 ''INDIA'' comment=
 ''Modified by RMAN duplicate'' scope=spfile";
   sql clone "alter system set  db_unique_name =
 ''HRPRD'' comment=
 ''Modified by RMAN duplicate'' scope=spfile";
   shutdown clone immediate;
   startup clone force nomount
   backup as copy current controlfile auxiliary format  '/u01/app/oracle/oradata/hrprd/control01.ctl';
   alter clone database mount;
}
executing Memory Script

sql statement: alter system set  db_name =  ''INDIA'' comment= ''Modified by RMAN duplicate'' scope=spfile

sql statement: alter system set  db_unique_name =  ''HRPRD'' comment= ''Modified by RMAN duplicate'' scope=spfile

Oracle instance shut down

Oracle instance started

Total System Global Area    2371719168 bytes

Fixed Size                     2255512 bytes
Variable Size                587203944 bytes
Database Buffers            1778384896 bytes
Redo Buffers                   3874816 bytes

Starting backup at 18-FEB-20
using channel ORA_DISK_1
channel ORA_DISK_1: starting datafile copy
copying current control file
output file name=/u01/app/oracle/product/11.2.0/dbhome_1/dbs/snapcf_india.f tag=TAG20200218T215741 RECID=3 STAMP=1032731861
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:01
Finished backup at 18-FEB-20

database mounted

contents of Memory Script:
{
   set newname for datafile  1 to
 "/u01/app/oracle/oradata/hrprd/system.256.1030296291";
   set newname for datafile  2 to
 "/u01/app/oracle/oradata/hrprd/sysaux.257.1030296291";
   set newname for datafile  3 to
 "/u01/app/oracle/oradata/hrprd/undotbs1.258.1030296291";
   set newname for datafile  4 to
 "/u01/app/oracle/oradata/hrprd/users.259.1030296291";
   set newname for datafile  5 to
 "/u01/app/oracle/oradata/hrprd/example.269.1030296381";
   set newname for datafile  6 to
 "/u01/app/oracle/oradata/hrprd/test.271.1030297077";
   backup as copy reuse
   datafile  1 auxiliary format
 "/u01/app/oracle/oradata/hrprd/system.256.1030296291"   datafile
 2 auxiliary format
 "/u01/app/oracle/oradata/hrprd/sysaux.257.1030296291"   datafile
 3 auxiliary format
 "/u01/app/oracle/oradata/hrprd/undotbs1.258.1030296291"   datafile
 4 auxiliary format
 "/u01/app/oracle/oradata/hrprd/users.259.1030296291"   datafile
 5 auxiliary format
 "/u01/app/oracle/oradata/hrprd/example.269.1030296381"   datafile
 6 auxiliary format
 "/u01/app/oracle/oradata/hrprd/test.271.1030297077"   ;
   sql 'alter system archive log current';
}
executing Memory Script

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

Starting backup at 18-FEB-20
using channel ORA_DISK_1
channel ORA_DISK_1: starting datafile copy
input datafile file number=00001 name=+DATA1/india/datafile/system.256.1030296291
output file name=/u01/app/oracle/oradata/hrprd/system.256.1030296291 tag=TAG20200218T215747
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:45
channel ORA_DISK_1: starting datafile copy
input datafile file number=00002 name=+DATA1/india/datafile/sysaux.257.1030296291
output file name=/u01/app/oracle/oradata/hrprd/sysaux.257.1030296291 tag=TAG20200218T215747
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:35
channel ORA_DISK_1: starting datafile copy
input datafile file number=00005 name=+DATA1/india/datafile/example.269.1030296381
output file name=/u01/app/oracle/oradata/hrprd/example.269.1030296381 tag=TAG20200218T215747
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:15
channel ORA_DISK_1: starting datafile copy
input datafile file number=00003 name=+DATA1/india/datafile/undotbs1.258.1030296291
output file name=/u01/app/oracle/oradata/hrprd/undotbs1.258.1030296291 tag=TAG20200218T215747
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:07
channel ORA_DISK_1: starting datafile copy
input datafile file number=00006 name=+DATA1/india/datafile/test.271.1030297077
output file name=/u01/app/oracle/oradata/hrprd/test.271.1030297077 tag=TAG20200218T215747
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:03
channel ORA_DISK_1: starting datafile copy
input datafile file number=00004 name=+DATA1/india/datafile/users.259.1030296291
output file name=/u01/app/oracle/oradata/hrprd/users.259.1030296291 tag=TAG20200218T215747
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:01
Finished backup at 18-FEB-20

sql statement: alter system archive log current

contents of Memory Script:
{
   backup as copy reuse
   archivelog like  "+DATA1/india/archivelog/2020_02_18/thread_1_seq_18.274.1032731975" auxiliary format
 "/u01/app/oracle/fast_recovery_area/hrprd/HRPRD/archivelog/2020_02_18/o1_mf_1_18_%u_.arc"   ;
   catalog clone recovery area;
   switch clone datafile all;
}
executing Memory Script

Starting backup at 18-FEB-20
using channel ORA_DISK_1
channel ORA_DISK_1: starting archived log copy
input archived log thread=1 sequence=18 RECID=3 STAMP=1032731974
output file name=/u01/app/oracle/fast_recovery_area/hrprd/HRPRD/archivelog/2020_02_18/o1_mf_1_18_09uosfa7_.arc RECID=0 STAMP=0
channel ORA_DISK_1: archived log copy complete, elapsed time: 00:00:01
Finished backup at 18-FEB-20

searching for all files in the recovery area

List of Files Unknown to the Database
=====================================
File Name: /u01/app/oracle/fast_recovery_area/hrprd/HRPRD/archivelog/2020_02_18/o1_mf_1_18_09uosfa7_.arc
cataloging files...
cataloging done

List of Cataloged Files
=======================
File Name: /u01/app/oracle/fast_recovery_area/hrprd/HRPRD/archivelog/2020_02_18/o1_mf_1_18_09uosfa7_.arc

datafile 1 switched to datafile copy
input datafile copy RECID=3 STAMP=1032731977 file name=/u01/app/oracle/oradata/hrprd/system.256.1030296291
datafile 2 switched to datafile copy
input datafile copy RECID=4 STAMP=1032731977 file name=/u01/app/oracle/oradata/hrprd/sysaux.257.1030296291
datafile 3 switched to datafile copy
input datafile copy RECID=5 STAMP=1032731977 file name=/u01/app/oracle/oradata/hrprd/undotbs1.258.1030296291
datafile 4 switched to datafile copy
input datafile copy RECID=6 STAMP=1032731977 file name=/u01/app/oracle/oradata/hrprd/users.259.1030296291
datafile 5 switched to datafile copy
input datafile copy RECID=7 STAMP=1032731977 file name=/u01/app/oracle/oradata/hrprd/example.269.1030296381
datafile 6 switched to datafile copy
input datafile copy RECID=8 STAMP=1032731977 file name=/u01/app/oracle/oradata/hrprd/test.271.1030297077

contents of Memory Script:
{
   set until scn  1260829;
   recover
   clone database
    delete archivelog
   ;
}
executing Memory Script

executing command: SET until clause

Starting recover at 18-FEB-20
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: SID=18 device type=DISK

starting media recovery

archived log for thread 1 with sequence 18 is already on disk as file /u01/app/oracle/fast_recovery_area/hrprd/HRPRD/archivelog/2020_02_18/o1_mf_1_18_09uosfa7_.arc
archived log file name=/u01/app/oracle/fast_recovery_area/hrprd/HRPRD/archivelog/2020_02_18/o1_mf_1_18_09uosfa7_.arc thread=1 sequence=18
media recovery complete, elapsed time: 00:00:01
Finished recover at 18-FEB-20
Oracle instance started

Total System Global Area    2371719168 bytes

Fixed Size                     2255512 bytes
Variable Size                587203944 bytes
Database Buffers            1778384896 bytes
Redo Buffers                   3874816 bytes

contents of Memory Script:
{
   sql clone "alter system set  db_name =
 ''HRPRD'' comment=
 ''Reset to original value by RMAN'' scope=spfile";
   sql clone "alter system reset  db_unique_name scope=spfile";
   shutdown clone immediate;
   startup clone nomount;
}
executing Memory Script

sql statement: alter system set  db_name =  ''HRPRD'' comment= ''Reset to original value by RMAN'' scope=spfile

sql statement: alter system reset  db_unique_name scope=spfile

Oracle instance shut down

connected to auxiliary database (not started)
Oracle instance started

Total System Global Area    2371719168 bytes

Fixed Size                     2255512 bytes
Variable Size                587203944 bytes
Database Buffers            1778384896 bytes
Redo Buffers                   3874816 bytes
sql statement: CREATE CONTROLFILE REUSE SET DATABASE "HRPRD" RESETLOGS ARCHIVELOG
  MAXLOGFILES     16
  MAXLOGMEMBERS      3
  MAXDATAFILES      100
  MAXINSTANCES     8
  MAXLOGHISTORY      292
 LOGFILE
  GROUP   1 ( '/u01/app/oracle/oradata/hrprd/group_1.262.1030296357', '/u01/app/oracle/oradata/hrprd/group_1.263.1030296359' ) SIZE 50 M  REUSE,
  GROUP   2 ( '/u01/app/oracle/oradata/hrprd/group_2.264.1030296361', '/u01/app/oracle/oradata/hrprd/group_2.265.1030296363' ) SIZE 50 M  REUSE,
  GROUP   3 ( '/u01/app/oracle/oradata/hrprd/group_3.266.1030296363', '/u01/app/oracle/oradata/hrprd/group_3.267.1030296365' ) SIZE 50 M  REUSE
 DATAFILE
  '/u01/app/oracle/oradata/hrprd/system.256.1030296291'
 CHARACTER SET AL32UTF8


contents of Memory Script:
{
   set newname for tempfile  1 to
 "/u01/app/oracle/oradata/hrprd/temp.268.1030296373";
   switch clone tempfile all;
   catalog clone datafilecopy  "/u01/app/oracle/oradata/hrprd/sysaux.257.1030296291",
 "/u01/app/oracle/oradata/hrprd/undotbs1.258.1030296291",
 "/u01/app/oracle/oradata/hrprd/users.259.1030296291",
 "/u01/app/oracle/oradata/hrprd/example.269.1030296381",
 "/u01/app/oracle/oradata/hrprd/test.271.1030297077";
   switch clone datafile all;
}
executing Memory Script

executing command: SET NEWNAME

renamed tempfile 1 to /u01/app/oracle/oradata/hrprd/temp.268.1030296373 in control file

cataloged datafile copy
datafile copy file name=/u01/app/oracle/oradata/hrprd/sysaux.257.1030296291 RECID=1 STAMP=1032731992
cataloged datafile copy
datafile copy file name=/u01/app/oracle/oradata/hrprd/undotbs1.258.1030296291 RECID=2 STAMP=1032731992
cataloged datafile copy
datafile copy file name=/u01/app/oracle/oradata/hrprd/users.259.1030296291 RECID=3 STAMP=1032731992
cataloged datafile copy
datafile copy file name=/u01/app/oracle/oradata/hrprd/example.269.1030296381 RECID=4 STAMP=1032731992
cataloged datafile copy
datafile copy file name=/u01/app/oracle/oradata/hrprd/test.271.1030297077 RECID=5 STAMP=1032731992

datafile 2 switched to datafile copy
input datafile copy RECID=1 STAMP=1032731992 file name=/u01/app/oracle/oradata/hrprd/sysaux.257.1030296291
datafile 3 switched to datafile copy
input datafile copy RECID=2 STAMP=1032731992 file name=/u01/app/oracle/oradata/hrprd/undotbs1.258.1030296291
datafile 4 switched to datafile copy
input datafile copy RECID=3 STAMP=1032731992 file name=/u01/app/oracle/oradata/hrprd/users.259.1030296291
datafile 5 switched to datafile copy
input datafile copy RECID=4 STAMP=1032731992 file name=/u01/app/oracle/oradata/hrprd/example.269.1030296381
datafile 6 switched to datafile copy
input datafile copy RECID=5 STAMP=1032731992 file name=/u01/app/oracle/oradata/hrprd/test.271.1030297077

contents of Memory Script:
{
   Alter clone database open resetlogs;
}
executing Memory Script

database opened
Finished Duplicate Db at 18-FEB-20

RMAN>

RMAN>

RMAN>

[oracle@localhost admin]$ !sq
sqlplus "/as sysdba"

SQL*Plus: Release 11.2.0.4.0 Production on Tue Feb 18 22:11:26 2020

Copyright (c) 1982, 2013, Oracle.  All rights reserved.


Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL> select name ,open_mode from v$database;

NAME      OPEN_MODE
--------- --------------------
HRPRD     READ WRITE


Thursday, January 30, 2020

Load bulk data using Oracle Stored Procedure bulk INSERT example using loop



Oracle Stored Procedure bulk INSERT example using loop


SQL> create table t ( x int, y varchar2(500) );

Table created.

Elapsed: 00:00:00.08
SQL> begin
    for i in 1 .. 100000
    loop
        insert into t values ( i, 'xxxxxxxxxxxxx' );
    end loop;
    commit;
end;
/  2    3    4    5    6    7    8

PL/SQL procedure successfully completed.

Elapsed: 00:00:03.70
SQL>

Wednesday, January 29, 2020

Oracle 11.2.0.4 installation on Linux RHEL 7.7 on AWS EC2 encounters error in invoking target 'agent nmhs' of makefile

Oracle 11.2.0.4 installation on Linux RHEL 7.7 on AWS encounters error in invoking target 'agent nmhs' of makefile


1. Edit the ins_emagent.mk

2. Change the below:



$(SYSMANBIN)emdctl:

        $(MK_EMAGENT_NMECTL)

to

$(SYSMANBIN)emdctl:

        $(MK_EMAGENT_NMECTL) -lnnz11

3. Retry the installation again.

Friday, January 3, 2020

Slow SQL Query troubleshoot steps


Use below step to troubleshoot slow sql query


Tablespace free space 
==============================

set lines 200
set pages 5000
column "Tablespace" format a50
column "Used MB"    format 99,999,999
column "Free MB"    format 99,999,999
column "Total MB"   format 99,999,999
select
  fs.tablespace_name                          "Tablespace",
  (df.totalspace - fs.freespace)              "Used MB",
  fs.freespace                                "Free MB",
  df.totalspace                               "Total MB",
  round(100 * (fs.freespace / df.totalspace)) "Pct. Free"
from
  (select
     tablespace_name,
     round(sum(bytes) / 1048576) TotalSpace
  from
     dba_data_files
  group by
     tablespace_name
  ) df,
  (select
     tablespace_name,
     round(sum(bytes) / 1048576) FreeSpace
  from
     dba_free_space
  group by
     tablespace_name
  ) fs
where
  df.tablespace_name = fs.tablespace_name order by 5;


Temp tablespace usages report 
======================================

SELECT 
   A.tablespace_name tablespace, 
   D.gb_total,
   SUM (A.used_blocks * D.block_size) / 1024 / 1024/1024 gb_used,
   D.gb_total - SUM (A.used_blocks * D.block_size) / 1024 / 1024/1024 gb_free
FROM 
   v$sort_segment A,
(
SELECT 
   B.name, 
   C.block_size, 
   SUM (C.bytes) / 1024 / 1024 /1024 gb_total
FROM 
   v$tablespace B, 
   v$tempfile C
WHERE 
   B.ts#= C.ts#
GROUP BY 
   B.name, 
   C.block_size
) D
WHERE 
   A.tablespace_name = D.name
GROUP by 
   A.tablespace_name, 
   D.gb_total
/

it will give you queries currently running for more than 60 seconds
 =============================================================================

select s.username,s.sid,s.serial#,s.last_call_et/60 mins_running,q.sql_text from v$session s 
join v$sqltext_with_newlines q
on s.sql_address = q.address
 where status='ACTIVE'
and type <>'BACKGROUND'
and last_call_et> 60
order by sid,serial#,q.piece

How to Identify SID Based on OS PID in Oracle
===================================================

col sid format 99999
col username format a20
col osuser format a15
select p.spid,s.sid, s.serial#,s.username, s.osuser
from gv$session s, gv$process p
where s.paddr= p.addr
and p.spid='&spid'
order by p.spid;

query completion percent :
===================================
COLUMN percent FORMAT 999.99 

SELECT sid, to_char(start_time,'hh24:mi:ss') stime, 
message,( sofar/totalwork)* 100 percent 
FROM v$session_longops
WHERE sofar/totalwork < 1
/


Query1 : using :  SYS_CONTEXT('USERENV','IP_ADDRESS')
=============================================================

SELECT DECODE(TRUNC(SYSDATE - LOGON_TIME), 0, NULL, TRUNC(SYSDATE - LOGON_TIME) || ' Days' || ' + ') ||
TO_CHAR(TO_DATE(TRUNC(MOD(SYSDATE-LOGON_TIME,1) * 86400), 'SSSSS'), 'HH24:MI:SS') LOGON,
v$session.SID, v$session.SERIAL#, v$process.SPID spid, v$session.process CLPRID,
v$session.USERNAME, STATUS, OSUSER, MACHINE, 
SYS_CONTEXT('USERENV','IP_ADDRESS') IP, 
v$session.PROGRAM, MODULE, action, SQL_HASH_VALUE,
'alter system kill session ' || '''' || v$session.SID || ', ' || v$session.SERIAL# || '''' || ' immediate;' kill_sql
FROM v$session, v$process
WHERE v$session.paddr = v$process.addr
ORDER BY logon_time ASC;


Query2: using  UTL_INADDR.GET_HOST_ADDRESS (SUBSTR(machine,INSTR(machine,'')+1)) IP
=========================================================================================

SELECT DECODE(TRUNC(SYSDATE - LOGON_TIME), 0, NULL, TRUNC(SYSDATE - LOGON_TIME) || ' Days' || ' + ') ||
TO_CHAR(TO_DATE(TRUNC(MOD(SYSDATE-LOGON_TIME,1) * 86400), 'SSSSS'), 'HH24:MI:SS') LOGON,
v$session.SID, v$session.SERIAL#, v$process.SPID spid, v$session.process CLPRID,
v$session.USERNAME, STATUS, OSUSER, MACHINE, 
UTL_INADDR.GET_HOST_ADDRESS (SUBSTR(machine,INSTR(machine,'')+1)) IP, 
v$session.PROGRAM, MODULE, action, SQL_HASH_VALUE,
'alter system kill session ' || '''' || v$session.SID || ', ' || v$session.SERIAL# || '''' || ' immediate;' kill_sql
FROM v$session, v$process
WHERE v$session.paddr = v$process.addr
ORDER BY logon_time ASC;


Check for any stale statistics.
=========================================

set lines 200 pages 500
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';



Check any invalid index/Partition
=======================================

col TABLE_NAME for a30
select owner,index_name,TABLE_NAME,NUM_ROWS,LAST_ANALYZED,STATUS from dba_indexes where status not in ('VALID','N/A');

select INDEX_OWNER,INDEX_NAME,PARTITION_NAME,SUBPARTITION_COUNT,LAST_ANALYZED,STATUS from dba_ind_partitions where status <> 'USABLE';


Check free memory shared pool area. Check too much hard parsing.
======================================================================

select * from (select SQL_ID,PARSING_SCHEMA_NAME, count(1) from v$sql group by SQL_ID,PARSING_SCHEMA_NAME order by  3 desc,2) where rownum<=10;

 Wait/ Blocking analysis.
 ============================


SELECT sid, serial#, blocking_session_status, blocking_session
FROM   v$session
WHERE  blocking_session IS NOT NULL;

-- Display the resource or event the session is waiting for more than 1 minutes

SELECT sid, serial#, event, (seconds_in_wait/1000000) seconds_in_wait
FROM   v$session
where (seconds_in_wait/1000000) > 60
ORDER BY sid;

select sid,seq#,event,state,SECONDS_IN_WAIT from v$session_wait where SECONDS_IN_WAIT > 60;

--Monitor Top Waiting Event Using Active Session History (ASH)

SELECT h.event,
SUM(h.wait_time + h.time_waited) "Total Wait Time (ms)"
FROM v$active_session_history h, v$sqlarea SQL, dba_users u, v$event_name e
WHERE h.sample_time BETWEEN sysdate - 1/24 AND sysdate --event in the last hour
AND h.sql_id = SQL.sql_id
AND h.user_id = u.user_id
AND h.event# = e.event#
GROUP BY h.event
ORDER BY SUM(h.wait_time + h.time_waited) DESC;


Tuning SQL using 
========================

@?/rdbms/admin/sqltrpt


AWR various Report.
=========================

@?/rdbms/admin/awrsqrpt.sql --> awr report for only single sql_id
@?/rdbms/admin/awrrpt.sql   --> Traditional awr report for instance.

RAC Related awr Report

@?/rdbms/admin/awrgrpt.sql -- AWR Global Report (RAC) (global report)
@?/rdbms/admin/awrrpti.sql -- Workload Repository Report Instance (RAC)


Long running jobs 
===========================


 SELECT SID, SERIAL#,OPNAME, CONTEXT, SOFAR, TOTALWORK,ROUND(SOFAR/TOTALWORK*100,2) "%_COMPLETE" FROM V$SESSION_LONGOPS WHERE OPNAME NOT LIKE '%aggregate%' AND TOTALWORK != 0 AND SOFAR <> TOTALWORK;



Check the sessions by username
================================================== 

column box format a30
column spid format a10
column username format a30 
column program format a30
column os_user format a20
col LOGON_TIME for a20  

select b.inst_id,b.sid,b.serial#,a.spid, substr(b.machine,1,30) box,to_char (b.logon_time, 'dd-mon-yyyy hh24:mi:ss') logon_time,
 substr(b.username,1,30) username,
 substr(b.osuser,1,20) os_user,
 substr(b.program,1,30) program,status,b.last_call_et AS last_call_et_secs,b.sql_id 
 from gv$session b,gv$process a 
 where b.paddr = a.addr 
 and a.inst_id = b.inst_id  
 and type='USER' and b.username='&username'
-- and b.status='ACTIVE'
-- and b.status='INACTIVE'
 order by logon_time;


Check the sessions by SID
==================================================
column box format a30
column spid format a10
column username format a30 
column program format a30
column os_user format a20
col LOGON_TIME for a20  

select b.inst_id,b.sid,b.serial#,a.spid, substr(b.machine,1,30) box,to_char (b.logon_time, 'dd-mon-yyyy hh24:mi:ss') logon_time,
 substr(b.username,1,30) username,
 substr(b.osuser,1,20) os_user,
 substr(b.program,1,30) program,status,b.last_call_et AS last_call_et_secs,b.sql_id 
 from gv$session b,gv$process a 
 where b.paddr = a.addr 
 and a.inst_id = b.inst_id  
 and type='USER' and b.SID='&SID'
-- and b.status='ACTIVE'
-- and b.status='INACTIVE'
 order by logon_time;


SQL response time 
=========================

select to_char(begin_time,'hh24:mi') time, round( value * 10, 2) "Response Time (ms)"
     from v$sysmetric
     where metric_name='SQL Service Response Time'
 
Completion Time remianing 
==============================

SELECT s.inst_id,
       s.sid,
       s.serial#,
       sl.qcsid,
       s.username,
       s.module,
       sl.opname,
       sl.time_remaining/60 time_remaining
FROM   gv$session s,
       gv$session_longops sl
WHERE  s.sid     = sl.sid
AND    s.inst_id = sl.inst_id
AND    s.serial# = sl.serial#
and sl.totalwork<>sl.sofar;


Blocking info
======================

col blocking_status for a100 
 select s1.inst_id,s2.inst_id,s1.username || '@' || s1.machine
 || ' ( SID=' || s1.sid || ' )  is blocking '
 || s2.username || '@' || s2.machine || ' ( SID=' || s2.sid || ' ) ' AS blocking_status
  from gv$lock l1, gv$session s1, gv$lock l2, gv$session s2
  where s1.sid=l1.sid and s2.sid=l2.sid and s1.inst_id=l1.inst_id and s2.inst_id=l2.inst_id
  and l1.BLOCK=1 and l2.request > 0
  and l1.id1 = l2.id1
  and l2.id2 = l2.id2
order by s1.inst_id;

 check active sql running in server 
========================================= 
   
   
 set echo off  linesize 200  pages 1000  head on  feedback on
 col username format a30
 col start_time format a15
 col curr_time format a15
 col osuser format a10
 col opname format a35
 col target format a25
 col tremain format 999999.99
 col elamin format 999999.99
 select a.sid,substr(b.username,1,10) username,substr(b.osuser,1,10) osuser,to_char(a.start_time,'dd-mon:hh24:mi:ss') start_time,
 to_char(sysdate,'dd-mon:hh24:mi:ss') curr_time,a.opname,a.target,a.totalwork,a.sofar,(a.elapsed_Seconds)/60 elamin,
 a.time_remaining/60 tremain
 from v$session_longops a,
 v$session b
 where a.totalwork<>a.sofar
 and a.sid=b.sid
 order by 3
 /




select *
  from v$sqlarea sqlarea, v$session sesion
 where sesion.sql_hash_value = sqlarea.hash_value
   and sesion.sql_address    = sqlarea.address
   and sesion.username is not null
   and sesion.sid='&sid'