Search This Blog

Total Pageviews

Monday, 31 July 2023

How to Install Oracle database 23c rpm on Linux Step by Step?

How to Install Oracle database 23c rpm on Linux Step by Step?



Oracle 23ai download 
https://www.oracle.com/database/free/get-started/

============================ Check Os !!
cat /etc/os-release
NAME="Oracle Linux Server"
VERSION="8.8"
ID="ol"
ID_LIKE="fedora"
VARIANT="Server"
VARIANT_ID="server"
VERSION_ID="8.8"
PLATFORM_ID="platform:el8"
PRETTY_NAME="Oracle Linux Server 8.8"
ANSI_COLOR="0;31"
CPE_NAME="cpe:/o:oracle:linux:8:8:server"
HOME_URL="https://linux.oracle.com/"
BUG_REPORT_URL="https://github.com/oracle/oracle-linux"

ORACLE_BUGZILLA_PRODUCT="Oracle Linux 8"
ORACLE_BUGZILLA_PRODUCT_VERSION=8.8
ORACLE_SUPPORT_PRODUCT="Oracle Linux"
ORACLE_SUPPORT_PRODUCT_VERSION=8.8




===


Set below value!! for SELinux 

cat /etc/selinux/config

# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#     enforcing - SELinux security policy is enforced.
#     permissive - SELinux prints warnings instead of enforcing.
#     disabled - No SELinux policy is loaded.
# SELINUXTYPE= can take one of these three values:
#     targeted - Targeted processes are protected,
#     minimum - Modification of targeted policy. Only selected processes are protected.
#     mls - Multi Level Security protection.


SELINUX=permissive
SELINUXTYPE=targeted

====
download pre rpm !!!

[root@oracle21 ~]# curl -L -o oracle-database-preinstall-23c-1.0-0.5.el8.x86_64.rpm https://yum.oracle.com/repo/OracleLinux/OL8/developer/x86_64/getPackage/oracle-database-preinstall-23c-1.0-0.5.el8.x86_64.rpm
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 30688  100 30688    0     0   134k      0 --:--:-- --:--:-- --:--:--  134k




dnf -y localinstall oracle-database-preinstall-23c-1.0-0.5.el8.x86_64.rpm 


dnf -y localinstall oracle-database-preinstall-23c-1.0-0.5.el8.x86_64.rpm

Last metadata expiration check: 1:49:55 ago on Mon 31 Jul 2023 12:03:43 PM BST.
Dependencies resolved.
=====================================================================================================================================================================================================================
 Package                                                         Architecture                            Version                                            Repository                                          Size
=====================================================================================================================================================================================================================
Installing:
 oracle-database-preinstall-23c                                  x86_64                                  1.0-0.5.el8                                        @commandline                                        30 k
Installing dependencies:
 compat-openssl10                                                x86_64                                  1:1.0.2o-4.el8_6                                   ol8_appstream                                      1.1 M
 libnsl                                                          x86_64                                  2.28-225.0.3.el8                                   ol8_baseos_latest                                  108 k

Transaction Summary
=====================================================================================================================================================================================================================
Install  3 Packages

Total size: 1.3 M
Total download size: 1.2 M
Installed size: 3.1 M
Downloading Packages:
(1/2): libnsl-2.28-225.0.3.el8.x86_64.rpm                                                                                                                                            661 kB/s | 108 kB     00:00
(2/2): compat-openssl10-1.0.2o-4.el8_6.x86_64.rpm                                                                                                                                    2.7 MB/s | 1.1 MB     00:00
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                                                                                2.8 MB/s | 1.2 MB     00:00
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                                                                                                                                             1/1
  Installing       : compat-openssl10-1:1.0.2o-4.el8_6.x86_64                                                                                                                                                    1/3
  Running scriptlet: compat-openssl10-1:1.0.2o-4.el8_6.x86_64                                                                                                                                                    1/3
/sbin/ldconfig: /etc/ld.so.conf.d/kernel-5.4.17-2011.1.2.el8uek.x86_64.conf:6: hwcap directive ignored

  Installing       : libnsl-2.28-225.0.3.el8.x86_64                                                                                                                                                              2/3
  Installing       : oracle-database-preinstall-23c-1.0-0.5.el8.x86_64                                                                                                                                           3/3
  Running scriptlet: oracle-database-preinstall-23c-1.0-0.5.el8.x86_64                                                                                                                                           3/3
/sbin/ldconfig: /etc/ld.so.conf.d/kernel-5.4.17-2011.1.2.el8uek.x86_64.conf:6: hwcap directive ignored

  Verifying        : libnsl-2.28-225.0.3.el8.x86_64                                                                                                                                                              1/3
  Verifying        : compat-openssl10-1:1.0.2o-4.el8_6.x86_64                                                                                                                                                    2/3
  Verifying        : oracle-database-preinstall-23c-1.0-0.5.el8.x86_64                                                                                                                                           3/3

Installed:
  compat-openssl10-1:1.0.2o-4.el8_6.x86_64                               libnsl-2.28-225.0.3.el8.x86_64                               oracle-database-preinstall-23c-1.0-0.5.el8.x86_64

Complete!
[root@oracle21 ~]#


Check below rpm

yum install sysstat compat-openssl10 glibc-devel ksh libnsl make
Last metadata expiration check: 1:52:04 ago on Mon 31 Jul 2023 12:03:43 PM BST.
Package sysstat-11.7.3-9.0.1.el8.x86_64 is already installed.
Package compat-openssl10-1:1.0.2o-4.el8_6.x86_64 is already installed.
Package glibc-devel-2.28-225.0.3.el8.x86_64 is already installed.
Package ksh-20120801-257.0.1.el8.x86_64 is already installed.
Package libnsl-2.28-225.0.3.el8.x86_64 is already installed.
Package make-1:4.2.1-11.el8.x86_64 is already installed.
Dependencies resolved.
Nothing to do.
Complete!
[root@oracle21 ~]#

=========================

dnf -y localinstall /root/oracle-database-free-23c-1.0-1.el8.x86_64.rpm

Last metadata expiration check: 1:56:39 ago on Mon 31 Jul 2023 12:03:43 PM BST.
Dependencies resolved.
=====================================================================================================================================================================================================================
 Package                                                        Architecture                                 Version                                        Repository                                          Size
=====================================================================================================================================================================================================================
Installing:
 oracle-database-free-23c                                       x86_64                                       1.0-1                                          @commandline                                       1.6 G

Transaction Summary
=====================================================================================================================================================================================================================
Install  1 Package

Total size: 1.6 G
Installed size: 5.2 G
Downloading Packages:
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                                                                                                                                             1/1
  Running scriptlet: oracle-database-free-23c-1.0-1.x86_64                                                                                                                                                       1/1
  Installing       : oracle-database-free-23c-1.0-1.x86_64                                                                                                                                                       1/1
  Running scriptlet: oracle-database-free-23c-1.0-1.x86_64                                                                                                                                                       1/1
[INFO] Executing post installation scripts...
[INFO] Oracle home installed successfully and ready to be configured.
To configure Oracle Database Free, optionally modify the parameters in '/etc/sysconfig/oracle-free-23c.conf' and then run '/etc/init.d/oracle-free-23c configure' as root.

/sbin/ldconfig: /etc/ld.so.conf.d/kernel-5.4.17-2011.1.2.el8uek.x86_64.conf:6: hwcap directive ignored

  Verifying        : oracle-database-free-23c-1.0-1.x86_64                                                                                                                                                       1/1

Installed:
  oracle-database-free-23c-1.0-1.x86_64

Complete!
[root@oracle21 ~]#
[root@oracle21 ~]#


[root@oracle21 ~]# ls -ltr /etc/init.d/oracle-free-23c
-r-xr-xr-x. 1 root root 19880 Mar 26 06:02 /etc/init.d/oracle-free-23c
[root@oracle21 ~]# cat /etc/init.d/oracle-free-23c


[root@oracle21 ~]# ls -ltr /opt/oracle/product/23c/dbhomeFree/
total 72
-rw-r--r--.  1 oracle oinstall  852 Aug 18  2015 env.ora
-rw-r--r--.  1 oracle oinstall 2927 Jul 20  2020 schagent.conf
-rwxr-x---.  1 oracle oinstall 1991 Jan 19  2022 runInstaller
-rw-r--r--.  1 oracle oinstall  878 Jul 15  2022 ss_oracle.sdo.acl
-rwx------.  1 oracle oinstall  519 Mar 26 06:01 root.sh
-rwxrwxr-x.  1 oracle oinstall 5780 Mar 26 06:02 LICENSE


=======
create Quick database !!!!

# export DB_PASSWORD=sys

# (echo "${DB_PASSWORD}"; echo "${DB_PASSWORD}";) | /etc/init.d/oracle-free-23c configure



[root@oracle21 ~]# export DB_PASSWORD=sys
[root@oracle21 ~]# (echo "${DB_PASSWORD}"; echo "${DB_PASSWORD}";) | /etc/init.d/oracle-free-23c configure
Specify a password to be used for database accounts. Oracle recommends that the password entered should be at least 8 characters in length, contain at least 1 uppercase character, 1 lower case character and 1 digit [0-9]. Note that the same password will be used for SYS, SYSTEM and PDBADMIN accounts:
Confirm the password:
Configuring Oracle Listener.


========


[root@oracle21 ~]# ps -ef|grep -i smon
oracle    153252       1  0 14:26 ?        00:00:00 db_smon_FREE
root      153755  150622  0 14:31 pts/2    00:00:00 grep --color=auto -i smon
[root@oracle21 ~]# su - oracle
[oracle@oracle21 ~]$ cat /etc/oratab
#



# This file is used by ORACLE utilities.  It is created by root.sh
# and updated by either Database Configuration Assistant while creating
# a database or ASM Configuration Assistant while creating ASM instance.

# A colon, ':', is used as the field terminator.  A new line terminates
# the entry.  Lines beginning with a pound sign, '#', are comments.
#
# Entries are of the form:
#   $ORACLE_SID:$ORACLE_HOME::
#
# The first and second fields are the system identifier and home
# directory of the database respectively.  The third field indicates
# to the dbstart utility that the database should , "Y", or should not,
# "N", be brought up at system boot time.
#
# Multiple entries with the same $ORACLE_SID are not allowed.
#
#
FREE:/opt/oracle/product/23c/dbhomeFree:N
[oracle@oracle21 ~]$



[oracle@oracle21 ~]$ sqlplus / as sysdba

SQL*Plus: Release 23.0.0.0.0 - Developer-Release on Mon Jul 31 14:32:31 2023
Version 23.2.0.0.0

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


Connected to:
Oracle Database 23c Free, Release 23.0.0.0.0 - Developer-Release
Version 23.2.0.0.0

SQL> show pdbs

    CON_ID CON_NAME                       OPEN MODE  RESTRICTED
---------- ------------------------------ ---------- ----------
         2 PDB$SEED                       READ ONLY  NO
         3 FREEPDB1                       READ WRITE NO
SQL>


===


set profile 


 su - oracle

[oracle@dbdocs ~]$ vi .bash_profile
# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
        . ~/.bashrc
fi

umask 022
ORACLE_SID=FREE
ORACLE_BASE=/opt/oracle
ORACLE_HOME=$ORACLE_BASE/product/23c/dbhomeFree
LD_LIBRARY_PATH=$ORACLE_HOME/lib
TMP=/tmp
TMPDIR=/tmp
PATH=$PATH:$ORACLE_HOME/bin:$ORACLE_HOME/OPatch
export ORACLE_SID ORACLE_BASE ORACLE_HOME LD_LIBRARY_PATH TMP TMPDIR PATH




SQL> !echo $ORACLE_BASE
/opt/oracle

SQL> !echo $ORACLE_HOME
/opt/oracle/product/23c/dbhomeFree



[root@oracle21 ~]# su - oracle
[oracle@oracle21 ~]$ sqlplus / as sysdba

SQL*Plus: Release 23.0.0.0.0 - Developer-Release on Mon Jul 31 15:02:53 2023
Version 23.2.0.0.0

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


Connected to:
Oracle Database 23c Free, Release 23.0.0.0.0 - Developer-Release
Version 23.2.0.0.0



SQL> Disconnected from Oracle Database 23c Free, Release 23.0.0.0.0 - Developer-Release
Version 23.2.0.0.0




 lsnrctl status

LSNRCTL for Linux: Version 23.0.0.0.0 - Developer-Release on 31-JUL-2023 15:09:14

Copyright (c) 1991, 2023, Oracle.  All rights reserved.

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=DESKTOP-9U3H4SE)(PORT=1521)))
STATUS of the LISTENER
------------------------
Alias                     LISTENER
Version                   TNSLSNR for Linux: Version 23.0.0.0.0 - Developer-Release
Start Date                31-JUL-2023 14:12:06
Uptime                    0 days 0 hr. 57 min. 7 sec
Trace Level               off
Security                  ON: Local OS Authentication
SNMP                      OFF
Default Service           FREE
Listener Parameter File   /opt/oracle/product/23c/dbhomeFree/network/admin/listener.ora
Listener Log File         /opt/oracle/diag/tnslsnr/oracle21/listener/alert/log.xml
Listening Endpoints Summary...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=oracle21)(PORT=1521)))
  (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))
Services Summary...
Service "01c963f8fcc157c8e0655cf8e99edab2" has 1 instance(s).
  Instance "FREE", status READY, has 1 handler(s) for this service...
Service "FREE" has 1 instance(s).
  Instance "FREE", status READY, has 1 handler(s) for this service...
Service "FREEXDB" has 1 instance(s).
  Instance "FREE", status READY, has 1 handler(s) for this service...
Service "freepdb1" has 1 instance(s). ----<<<<<<<<<<<<<<<<<<<<<<     pdb!!!!!
  Instance "FREE", status READY, has 1 handler(s) for this service...
The command completed successfully
[oracle@oracle21 admin]$


pwd
/opt/oracle/product/23c/dbhomeFree/network/admin

[oracle@oracle21 admin]$ ls -ltr
total 16
-rw-r--r--. 1 oracle oinstall 1866 May 19  2021 shrept.lst
drwxr-xr-x. 2 oracle oinstall   64 Jul 31 14:05 samples
-rw-r-----. 1 oracle oinstall  190 Jul 31 14:12 sqlnet.ora
-rw-r-----. 1 oracle oinstall  371 Jul 31 14:12 listener.ora
-rw-r-----. 1 oracle oinstall  415 Jul 31 14:18 tnsnames.ora
[oracle@oracle21 admin]$ cat tnsnames.ora
# tnsnames.ora Network Configuration File: /opt/oracle/product/23c/dbhomeFree/network/admin/tnsnames.ora
# Generated by Oracle configuration tools.

FREE =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = DESKTOP-9U3H4SE)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = FREE)
    )
  )

LISTENER_FREE =
  (ADDRESS = (PROTOCOL = TCP)(HOST = DESKTOP-9U3H4SE)(PORT = 1521))




-rw-r-----. 1 oracle oinstall  371 Jul 31 14:12 listener.ora
-rw-r-----. 1 oracle oinstall  415 Jul 31 14:18 tnsnames.ora
[oracle@oracle21 admin]$ cat listener.ora
# listener.ora Network Configuration File: /opt/oracle/product/23c/dbhomeFree/network/admin/listener.ora
# Generated by Oracle configuration tools.

DEFAULT_SERVICE_LISTENER = FREE

LISTENER =
  (DESCRIPTION_LIST =
    (DESCRIPTION =
      (ADDRESS = (PROTOCOL = TCP)(HOST = DESKTOP-9U3H4SE)(PORT = 1521))
      (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
    )
  )




[oracle@oracle21 ~]$ sqlplus sys/sys@//localhost:1521/freepdb1 as sysdba

SQL*Plus: Release 23.0.0.0.0 - Developer-Release on Mon Jul 31 15:05:18 2023
Version 23.2.0.0.0

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


Connected to:
Oracle Database 23c Free, Release 23.0.0.0.0 - Developer-Release
Version 23.2.0.0.0

SQL>

======

How to rename a Pluggable Database?



show pdbs

    CON_ID CON_NAME                       OPEN MODE  RESTRICTED
---------- ------------------------------ ---------- ----------
         3 FREEPDB1                       READ WRITE NO


col FILE_NAME for a50
select FILE_ID,FILE_NAME from dba_data_files;


   FILE_ID FILE_NAME
---------- --------------------------------------------------
        12 /opt/oracle/oradata/FREE/FREEPDB1/system01.dbf
        13 /opt/oracle/oradata/FREE/FREEPDB1/sysaux01.dbf
        14 /opt/oracle/oradata/FREE/FREEPDB1/undotbs01.dbf
        15 /opt/oracle/oradata/FREE/FREEPDB1/users01.dbf



SQL> show pdbs

    CON_ID CON_NAME                       OPEN MODE  RESTRICTED
---------- ------------------------------ ---------- ----------
         2 PDB$SEED                       READ ONLY  NO
         3 FREEPDB1                       READ WRITE NO


alter pluggable database FREEPDB1 close immediate;

Pluggable database altered.

SQL> show pdbs

    CON_ID CON_NAME                       OPEN MODE  RESTRICTED
---------- ------------------------------ ---------- ----------
         2 PDB$SEED                       READ ONLY  NO
         3 FREEPDB1                       MOUNTED



 alter pluggable database FREEPDB1 open restricted;



SQL> show pdbs

    CON_ID CON_NAME                       OPEN MODE  RESTRICTED
---------- ------------------------------ ---------- ----------
         2 PDB$SEED                       READ ONLY  NO
         3 FREEPDB1                       READ WRITE YES
SQL>


connect FREEPDB1 as sysdba

SQL>
connect FREEPDB1 as sysdba
Enter password:
Connected.



alter pluggable database FREEPDB1 rename global_name to anuj;

SQL>

alter pluggable database FREEPDB1 rename global_name to anuj;
Pluggable database altered.


show pdbs

    CON_ID CON_NAME                       OPEN MODE  RESTRICTED
---------- ------------------------------ ---------- ----------
         2 PDB$SEED                       READ ONLY  NO
         3 ANUJ                           READ WRITE YES




SQL> alter session set container=ANUJ ;

Session altered.


col FILE_NAME for a50
select FILE_ID,FILE_NAME from dba_data_files;SQL> SQL>

   FILE_ID FILE_NAME
---------- --------------------------------------------------
        12 /opt/oracle/oradata/FREE/FREEPDB1/system01.dbf
        13 /opt/oracle/oradata/FREE/FREEPDB1/sysaux01.dbf
        14 /opt/oracle/oradata/FREE/FREEPDB1/undotbs01.dbf
        15 /opt/oracle/oradata/FREE/FREEPDB1/users01.dbf


All the fils are in same location !!!!



mkdir /u02/oradata/CDB2/hugo

SQL> ALTER DATABASE MOVE DATAFILE '/opt/oracle/oradata/FREE/FREEPDB1/system01.dbf' TO '/opt/oracle/oradata/FREE/ANUJ/system01.dbf';


ALTER DATABASE MOVE DATAFILE '/opt/oracle/oradata/FREE/FREEPDB1/system01.dbf' TO '/opt/oracle/oradata/FREE/ANUJ/system01.dbf'
*
ERROR at line 1:
ORA-00439: feature not enabled: online move datafile




SQL> show pdbs

    CON_ID CON_NAME                       OPEN MODE  RESTRICTED
---------- ------------------------------ ---------- ----------
         3 ANUJ                           READ WRITE YES
SQL> shutdown immediate ;
Pluggable Database closed.


SQL> startup;
Pluggable Database opened.
SQL> show pdbs

    CON_ID CON_NAME                       OPEN MODE  RESTRICTED
---------- ------------------------------ ---------- ----------
         3 ANUJ                           READ WRITE NO
SQL>




SQL>  !oerr ora 439
00439, 00000, "feature not enabled: %s"
// *Cause:  The specified feature was not enabled.
// *Action: Do not attempt to use this feature.



SQL> Disconnected from Oracle Database 23c Free, Release 23.0.0.0.0 - Developer-Release
Version 23.2.0.0.0
[oracle@oracle21 ~]$ sqlplus / as sysdba

SQL*Plus: Release 23.0.0.0.0 - Developer-Release on Mon Jul 31 18:47:41 2023
Version 23.2.0.0.0

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


Connected to:
Oracle Database 23c Free, Release 23.0.0.0.0 - Developer-Release   <<<<< This feature in not enabled .
Version 23.2.0.0.0

Friday, 28 July 2023

sqlplus output in html

sqlplus output in html 



sqlplus -S -M "HTML ON TABLE 'BORDER="2"'" '/ as sysdba' @/home/oracle/DBA/dd.sql > dd.html
echo "Database Size -- " | mailx -s "Database Size" -a dd.html anuj@xxxx.com


This will send the email with attachment 

Thursday, 27 July 2023

Oracle IO from ASH

Oracle active session report (ASH report ) for IO .. 


Oracle IO from ASH 

from https://github.com/khailey-zz/ashmasters/blob/master/io.sql






define minutes=15  ---<<<<<<min

set linesize 300 pagesize 300 


prompt db file s
col block_type for a18
col objn for a40
col obj for a30
col otype for a15
col event for a15
col blockn for 999999
col p3 for 999
col p1 for 9999999999999
select
       substr(event,0,15) event,
       ash.p1,
       ash.p2,
       ash.p3 p3, 
     CURRENT_OBJ#||' '||o.object_name objn,
       nvl(o.object_name,CURRENT_OBJ#) obj,
       o.object_type otype,
       --CURRENT_FILE# filen,
       --CURRENT_BLOCK# blockn, 
       ash.SQL_ID
       --,blocking_session bsid
from gv$active_session_history ash,
      all_objects o
where 1=1
and event like 'db file s%'
   and o.object_id (+)= ash.CURRENT_OBJ#
   and sample_time > sysdate - &minutes/(60*24)
Order by sample_time
/
        



col block_type for a18
col objn for a25
col otype for a15
col event for a25
col p3 for 999
col fn for 999
col sid for 9999999
col qsid for 9999
col BLOCKN for 99999999999
col kill for a18
select
'''' || ash.SESSION_ID || ',' || ash.session_serial# ||',@'|| ash.inst_id||'''' kill,
   --    session_id sid,
substr(event,0,15) event,
       QC_SESSION_ID qsid,
       --event,
       --ash.p1,
       --ash.p2,
       ash.p3,
       CURRENT_OBJ#||' '||o.object_name objn,
       o.object_type otype,
       CURRENT_FILE# fn,
       CURRENT_BLOCK# blockn,
       ash.SQL_ID
from gv$active_session_history ash,
      all_objects o
where event like 'direct path read'
   and o.object_id (+)= ash.CURRENT_OBJ#
and sample_time > sysdate - &minutes/(60*24)
Order by sample_time
/


https://github.com/khailey-zz/ashmasters/blob/master/io_pqo.sql

select
'''' || ash.SESSION_ID || ',' || ash.session_serial# ||',@'|| ash.inst_id||'''' kill,
       ash.SQL_ID,
       QC_SESSION_ID qsid,
       count(*) cnt,
       count (distinct session_id) deg,
       nvl(o.object_name,to_char(CURRENT_OBJ#))  obj,
       o.object_type otype,
       decode(session_state, 'WAITING',event,'CPU') event
from   gv$active_session_history ash,
        all_objects o
where  o.object_id (+)= ash.CURRENT_OBJ#
   and qc_session_id is not null
and sample_time > sysdate - &minutes/(60*24)
group by '''' || ash.SESSION_ID || ',' || ash.session_serial# ||',@'|| ash.inst_id||'''',qc_session_id, sql_id, o.object_name,
         o.object_type, CURRENT_OBJ#, event, session_state
Order by qc_session_id, sql_id
/




col block_type for a18
col objn for a35
col otype for a15
col event for a25
col kill for a18
select
'''' || ash.SESSION_ID || ',' || ash.session_serial# ||',@'|| ash.inst_id||'''' kill,
       event,
       ash.p3,
       CURRENT_OBJ#||' '||o.object_name objn,
       o.object_type otype,
       CURRENT_FILE# filen,
       CURRENT_BLOCK# blockn,
       ash.SQL_ID
from gv$active_session_history ash,
      all_objects o
where event like 'db file scattered read'
   and o.object_id (+)= ash.CURRENT_OBJ#
and sample_time > sysdate - &minutes/(60*24)
Order by sample_time
/


col block_type for a18
col objn for a35
col otype for a15
col event for a25
select
'''' || ash.SESSION_ID || ',' || ash.session_serial# ||',@'|| ash.inst_id||'''' kill,
       event,
       ash.p3,
       CURRENT_OBJ#||' '||o.object_name objn,
       o.object_type otype,
       CURRENT_FILE# filen,
       CURRENT_BLOCK# blockn,
       ash.SQL_ID
from gv$active_session_history ash,
      all_objects o
where event like 'db file sequential read'
   and o.object_id (+)= ash.CURRENT_OBJ#
and sample_time > sysdate - &minutes/(60*24)
Order by sample_time
/



col AAS      for  99.999
col SQL_ID   for  A13
col CNT	     for  9999
col PCT      for  999
col OBJ      for  A35
col SUB_OBJ  for  A10
col OTYPE    for  A10
col EVENT    for  A10
col FILE#    for  999
col TABLESPACE_NAME  for A15
col CONTENTS for A15

break on sql_id on aas

col f_minutes new_value v_minutes
select &minutes f_minutes from dual;
--select &v_minutes from dual;

select
       round(sum(cnt) over ( partition by io.sql_id order by sql_id ) / (&v_minutes*60),2) aas,
       io.sql_id,
       io.cnt cnt,
       100*cnt/sum(cnt) over ( partition by io.sql_id order by sql_id ) pct,
       o.object_name obj,
       o.subobject_name sub_obj,
       o.object_type otype,
       substr(io.event,8,10) event,
       io.p1 file#,
       f.tablespace_name tablespace_name,
       tbs.contents
from 
(
  select
        sql_id,
	event,
        count(*) cnt,
        count(*) / (&v_minutes*60) aas,
        CURRENT_OBJ# ,
        ash.p1
   from v$active_session_history ash
   where ( event like 'db file s%' or event like 'direct%' )
      and sample_time > sysdate - &v_minutes/(60*24)
   group by 
       CURRENT_OBJ#, 
       event,
       ash.p1,
       sql_id
) io,
   dba_data_files f
   ,all_objects o
   , dba_tablespaces tbs
where
   f.file_id = io.p1
   and o.object_id (+)= io.CURRENT_OBJ#
   and tbs.tablespace_name= f.tablespace_name 
Order by aas, sql_id, cnt
/




col block_type for a18
col objn for a35
col otype for a15
col event for a15
col blockn for 999999
col aas for 999999
col delta for a15
col delta for 999.9999
col mnt for a17
col mxt for a17
col cnt for 99999
/*
*/
select
       count(*) cnt,
       cast(max(sample_time) as date) - cast(min(sample_time) as date) delta, 
       to_char(cast(min(sample_time) as date),'DD/YY/MM HH24:mi:ss') mnt, 
       to_char(cast(max(sample_time) as date),'DD/YY/MM HH24:mi:ss') mxt,
       substr(event,0,15) event, 
       CURRENT_OBJ#||' '||o.object_name objn,
       o.object_type otype
from gv$active_session_history ash,
      all_objects o
where ( event like 'db file s%' or event like 'direct%' )
      and o.object_id (+)= ash.CURRENT_OBJ#
   and sample_time > sysdate - &minutes/(60*24)
   --and rownum < 10
group by 
       substr(event,0,15) , 
       CURRENT_OBJ#, o.object_name ,
       o.object_type 
Order by cnt 
/




col block_type for a18
col obj for a20
col otype for a15
col event for a15
col blockn for 999999
col f_minutes new_value v_minutes
col p1 for 9999
col tablespace_name for a15
col aas for 99.999
select &minutes f_minutes from dual;
select
       io.cnt cnt,
       io.aas aas,
       io.event event,
       substr(io.obj,1,20) obj,
       io.p1 p1,
       f.tablespace_name tablespace_name
from 
(
  select
        count(*) cnt,
        round(count(*)/(&v_minutes*60),2) aas,
        substr(event,0,15) event, 
        nvl(o.object_name,decode(CURRENT_OBJ#,-1,0,CURRENT_OBJ#)) obj,
        ash.p1, 
        o.object_type otype
   from gv$active_session_history ash,
        all_objects o
   where ( event like 'db file s%' or event like 'direct%' )
      and o.object_id (+)= ash.CURRENT_OBJ#
      and sample_time > sysdate - &v_minutes/(60*24)
   group by 
       substr(event,0,15) , 
       CURRENT_OBJ#, o.object_name ,
       o.object_type ,
       ash.p1
) io,
  dba_data_files f
where
   f.file_id = io.p1
Order by io.cnt
/


===
define minutes=15
set linesize 300 pagesize 300
col AAS      for  99.999
col SQL_ID   for  A13
col CNT	     for  9999
col PCT      for  999
col OBJ      for  A30
col SUB_OBJ  for  A10
col OTYPE    for  A10
col EVENT    for  A30
col FILE#    for  999999
col TABLESPACE_NAME  for A15
col CONTENTS for A15

break on sql_id on aas

col f_minutes new_value v_minutes
select &minutes f_minutes from dual;
--select &v_minutes from dual;

select
       --round(sum(cnt) over ( partition by io.sql_id order by sql_id ) / (&v_minutes*60),4) aas,
       sum(cnt) over ( partition by io.sql_id order by sql_id ) / (&v_minutes*60) aas,
       io.sql_id,
       io.cnt cnt,
       100*cnt/sum(cnt) over ( partition by io.sql_id order by sql_id ) pct,
       o.object_name obj,
       o.subobject_name sub_obj,
       o.object_type otype,
       io.event event,
       io.p1 file#,
       f.tablespace_name tablespace_name,
       tbs.contents
from 
(
  select
        sql_id,
	event,
        count(*) cnt,
        count(*) / (&v_minutes*60) aas,
        CURRENT_OBJ# ,
        ash.p1
   from gv$active_session_history ash
   where 1=1
and ( event like 'db file s%' or event like 'direct%' )
      and sample_time > sysdate - &v_minutes/(60*24)
   group by 
       CURRENT_OBJ#, 
       event,
       ash.p1,
       sql_id
) io,
   dba_data_files f   ,all_objects o   , dba_tablespaces tbs
where
   f.file_id = io.p1
   and o.object_id (+)= io.CURRENT_OBJ#
   and tbs.tablespace_name= f.tablespace_name 
Order by aas, sql_id, cnt
/

====

define minutes=15
col block_type for a18
col objn for a25
col otype for a15
col event for a15
col blockn for 999999

col TABLESPACE_NAME for a30
select 
       tf.cnt,
       tf.event,
       f.tablespace_name 
from (
      select
              count(*) cnt,
              substr(event,0,15) event, 
              ash.p1 p1
       from   gv$active_session_history ash
       where ( event like 'db file s%' or event like 'direct%' )
              and sample_time > sysdate - &minutes/(60*24)
       group by
              substr(event,0,15) , 
              ash.p1
      ) tf,
        dba_data_files f
where
    f.file_id = tf.p1
Order by tf.cnt
/





for tablespace .. 



define minutes=15
set linesize 300 pagesize 300
col AAS      for  99.999
col SQL_ID   for  A13
col CNT	     for  9999
col PCT      for  999
col OBJ      for  A30
col SUB_OBJ  for  A10
col OTYPE    for  A10
col EVENT    for  A30
col FILE#    for  999999
col TABLESPACE_NAME  for A15
col CONTENTS for A15

break on sql_id on aas

col f_minutes new_value v_minutes
select &minutes f_minutes from dual;
--select &v_minutes from dual;

select
       --round(sum(cnt) over ( partition by io.sql_id order by sql_id ) / (&v_minutes*60),4) aas,
       sum(cnt) over ( partition by io.sql_id order by sql_id ) / (&v_minutes*60) aas,
       io.sql_id,
       io.cnt cnt,
       100*cnt/sum(cnt) over ( partition by io.sql_id order by sql_id ) pct,
       o.object_name obj,
       o.subobject_name sub_obj,
       o.object_type otype,
       io.event event,
       io.p1 file#,
       f.tablespace_name tablespace_name,
       tbs.contents
from 
(
  select
        sql_id,
	event,
        count(*) cnt,
        count(*) / (&v_minutes*60) aas,
        CURRENT_OBJ# ,
        ash.p1
   from gv$active_session_history ash
   where 1=1
and ( event like 'db file s%' or event like 'direct%' )
      and sample_time > sysdate - &v_minutes/(60*24)
   group by 
       CURRENT_OBJ#, 
       event,
       ash.p1,
       sql_id
) io,
   dba_data_files f   ,all_objects o   , dba_tablespaces tbs
where
   f.file_id = io.p1
   and o.object_id (+)= io.CURRENT_OBJ#
   and tbs.tablespace_name= f.tablespace_name 
Order by aas, sql_id, cnt
/


Wednesday, 26 July 2023

How to Move Lob Segment to another Tablespace

 

How to Move Lob Segment to another Tablespace?

SQL> desc SCHEDULER$_JOB_OUTPUT Name Null? Type ----------------------------------------- -------- ---------------------------- LOG_ID NUMBER ERRORS BLOB OUTPUT BLOB set linesize 300 col OWNER for a20 col TABLE_NAME for a30 col SEGMENT_NAME for a30 select e.owner,l.table_name,l.segment_name,e.TABLESPACE_NAME,l.TABLESPACE_NAME Lob_tablespace from dba_extents e, dba_lobs l where e.owner = l.owner and e.segment_name = l.segment_name and e.segment_type = 'LOBSEGMENT' --and l.segment_name like 'SYS_LOB0000008917C00003$$' and TABLE_NAME='SCHEDULER$_JOB_OUTPUT' ; OWNER TABLE_NAME SEGMENT_NAME TABLESPACE_NAME LOB_TABLESPACE -------------------- ------------------------------ ------------------------------ ------------------------------ ------------------------------ SYS SCHEDULER$_JOB_OUTPUT SYS_LOB0000008919C00002$$ SYSAUX SYSAUX SYS SCHEDULER$_JOB_OUTPUT SYS_LOB0000008919C00003$$ SYSAUX SYSAUX alter table sys.SCHEDULER$_JOB_OUTPUT move lob(ERRORS) store as (tablespace USERS) parallel 16 update indexes; alter table sys.SCHEDULER$_JOB_OUTPUT move lob(ERRORS) store as (tablespace USERS) parallel 16 update indexes; Table altered. alter table sys.SCHEDULER$_JOB_OUTPUT move lob(OUTPUT) store as (tablespace USERS) parallel 16 update indexes; Table altered. OWNER TABLE_NAME SEGMENT_NAME TABLESPACE_NAME LOB_TABLESPACE -------------------- ------------------------------ ------------------------------ ------------------------------ ------------------------------ SYS SCHEDULER$_JOB_OUTPUT SYS_LOB0000008919C00002$$ USERS USERS SYS SCHEDULER$_JOB_OUTPUT SYS_LOB0000008919C00003$$ USERS USERS alter table sys.SCHEDULER$_JOB_OUTPUT move lob(OUTPUT) store as (tablespace SYSAUX) parallel 16 update indexes; Table altered. alter table sys.SCHEDULER$_JOB_OUTPUT move lob(ERRORS) store as (tablespace SYSAUX) parallel 16 update indexes; Table altered. OWNER TABLE_NAME SEGMENT_NAME TABLESPACE_NAME LOB_TABLESPACE -------------------- ------------------------------ ------------------------------ ------------------------------ ------------------------------ SYS SCHEDULER$_JOB_OUTPUT SYS_LOB0000008919C00002$$ SYSAUX SYSAUX SYS SCHEDULER$_JOB_OUTPUT SYS_LOB0000008919C00003$$ SYSAUX SYSAUX COL SEGMENT_NAME FORMAT A30 COL OWNER FORMAT A10 COL TABLESPACE_NAME FORMAT A10 COL SEGMENT_TYPE FORMAT A30 SELECT * FROM (SELECT SEGMENT_NAME,OWNER,TABLESPACE_NAME,BYTES/1024/1024/1024 "SIZE(GB)",SEGMENT_TYPE FROM DBA_SEGMENTS WHERE TABLESPACE_NAME='SYSAUX' ORDER BY BYTES DESC) WHERE ROWNUM<=10; col owner for a15 col segment_name for a40 select * from (select owner,segment_name||'~'||partition_name segment_name,segment_type,bytes/(1024*1024*1024) size_G from dba_segments where 1=1 and OWNER='SYS' ORDER BY BLOCKS desc ) where rownum < 11;

Sunday, 23 July 2023

ORA-19906: recovery target incarnation changed during recovery



ORA-19906: recovery target incarnation changed during recovery


http://anuj-singh.blogspot.com/2021/10/rman-restore-database.html


RMAN>
run{
set until scn 2128193160;
restore database;
recover database;
alter database open resetlogs;
}

archived log for thread 1 with sequence 20 is already on disk as file +DATA/IBRAC/ARCHIVELOG/2023_07_23/thread_1_seq_20.3994.1142903177
archived log for thread 2 with sequence 10 is already on disk as file +DATA/IBRAC/ARCHIVELOG/2023_07_23/thread_2_seq_10.3993.1142903179
archived log file name=+DATA/IBRAC/ARCHIVELOG/2023_07_23/thread_1_seq_20.3994.1142903177 thread=1 sequence=20
archived log file name=+DATA/IBRAC/ARCHIVELOG/2023_07_23/thread_2_seq_10.3993.1142903179 thread=2 sequence=10
archived log file name=+DATA/IBRAC/ARCHIVELOG/2023_07_23/thread_1_seq_21.3978.1142919207 thread=1 sequence=21
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of recover command at 07/23/2023 05:50:15
ORA-00283: recovery session canceled due to errors
RMAN-11003: failure during parse/execution of SQL statement: alter database recover logfile '+DATA/IBRAC/ARCHIVELOG/2023_07_23/thread_1_seq_21.3978.1142919207'
ORA-00283: recovery session canceled due to errors
ORA-19906: recovery target incarnation changed during recovery





select * from v$database_incarnation where RESETLOGS_CHANGE# in (select max(RESETLOGS_CHANGE#) from v$database_incarnation where RESETLOGS_CHANGE#< 2128193160 ) ;


INCARNATION# RESETLOGS_CHANGE# RESETLOGS_TIME   PRIOR_RESETLOGS_CHANGE#
------------ ----------------- ---------------- -----------------------
PRIOR_RESETLOGS_ STATUS  RESETLOGS_ID PRIOR_INCARNATION#
---------------- ------- ------------ ------------------
FLASHBACK_DATABASE_ALLOWED     CON_ID
-------------------------- ----------
           8        2111276714 23-07-2023 05:33              2103430857
21-07-2023 13:03 CURRENT   1142919207                  7
NO                                  0

-
RMAN>
reset database to incarnation 8;
RMAN>

database reset to incarnation 8



2128193159+1

run{
set until scn 2128193160;
restore database;
recover database;
alter database open resetlogs;
}



RMAN>
select * from v$database_incarnation where RESETLOGS_CHANGE# in (select max(RESETLOGS_CHANGE#) from v$database_incarnation where RESETLOGS_CHANGE#< 2128193160 ) ;
RMAN>

INCARNATION# RESETLOGS_CHANGE# RESETLOGS_TIME   PRIOR_RESETLOGS_CHANGE#
------------ ----------------- ---------------- -----------------------
PRIOR_RESETLOGS_ STATUS  RESETLOGS_ID PRIOR_INCARNATION#
---------------- ------- ------------ ------------------
FLASHBACK_DATABASE_ALLOWED     CON_ID
-------------------------- ----------
           8        2111276714 23-07-2023 05:33              2103430857
21-07-2023 13:03 CURRENT   1142919207                  7
NO                                  0

===================================================================================
Change incarnation based on scn no !!!!!
================================================================================
RMAN>
reset database to incarnation 8;
RMAN>

database reset to incarnation 8

RMAN>
run{
set until scn 2128193160;
restore database;
recover database;
alter database open resetlogs;
}

RMAN> 2> 3> 4> 5> 6>
executing command: SET until clause

Starting restore at 23-07-2023 06:00:33
using channel ORA_DISK_1

channel ORA_DISK_1: starting datafile backup set restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_DISK_1: restoring datafile 00001 to +DATA/ibrac/system01.dbf
channel ORA_DISK_1: restoring datafile 00002 to +DATA/ibrac/apex_data01.dbf
channel ORA_DISK_1: restoring datafile 00003 to +DATA/ibrac/sysaux01.dbf
channel ORA_DISK_1: restoring datafile 00004 to +DATA/ibrac/undotbs01.dbf
channel ORA_DISK_1: restoring datafile 00005 to +DATA/ibrac/undotbs02.dbf
channel ORA_DISK_1: restoring datafile 00007 to +DATA/ibrac/users01.dbf
channel ORA_DISK_1: restoring datafile 00008 to +DATA/ibrac/test_data01.dbf
channel ORA_DISK_1: restoring datafile 00009 to +DATA/ibrac/test_data_ind_01.dbf
channel ORA_DISK_1: restoring datafile 00010 to +DATA/IBRAC/DATAFILE/lobtest.4701.1142772675
channel ORA_DISK_1: restoring datafile 00011 to +DATA/IBRAC/DATAFILE/test_uniform.4019.1142772751
channel ORA_DISK_1: restoring datafile 00012 to +DATA/IBRAC/DATAFILE/test.4018.1142772743
channel ORA_DISK_1: restoring datafile 00013 to +DATA/IBRAC/DATAFILE/test1.4020.1142772751
channel ORA_DISK_1: restoring datafile 00014 to +DATA/IBRAC/DATAFILE/test1.4024.1142772751
channel ORA_DISK_1: restoring datafile 00015 to +DATA/IBRAC/DATAFILE/bigtabs.4014.1142772677
channel ORA_DISK_1: reading from backup piece /dumps/IBRAC/20230721_ibrac1_1734_1_1142746455

channel ORA_DISK_1: piece handle=/dumps/IBRAC/20230721_ibrac1_1734_1_1142746455 tag=TAG20230721T053414
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:07:06
Finished restore at 23-07-2023 06:07:40

Starting recover at 23-07-2023 06:07:40
using channel ORA_DISK_1

starting media recovery

archived log for thread 1 with sequence 1677 is already on disk as file +DATA/IBRAC/ARCHIVELOG/2023_07_23/thread_1_seq_1677.3988.1142919161
archived log for thread 2 with sequence 1701 is already on disk as file +DATA/IBRAC/ARCHIVELOG/2023_07_23/thread_2_seq_1701.3987.1142919161
archived log for thread 1 with sequence 1 is already on disk as file +DATA/IBRAC/ARCHIVELOG/2023_07_23/thread_1_seq_1.3981.1142919163
archived log for thread 1 with sequence 2 is already on disk as file +DATA/IBRAC/ARCHIVELOG/2023_07_23/thread_1_seq_2.3979.1142919163
archived log for thread 1 with sequence 3 is already on disk as file +DATA/IBRAC/ARCHIVELOG/2023_07_23/thread_1_seq_3.3986.1142919163
archived log for thread 1 with sequence 4 is already on disk as file +DATA/IBRAC/ARCHIVELOG/2023_07_23/thread_1_seq_4.3985.1142919163
archived log for thread 1 with sequence 5 is already on disk as file +DATA/IBRAC/ARCHIVELOG/2023_07_23/thread_1_seq_5.3983.1142919163
archived log for thread 1 with sequence 6 is already on disk as file +DATA/IBRAC/ARCHIVELOG/2023_07_22/thread_1_seq_6.4012.1142842377
archived log for thread 2 with sequence 1 is already on disk as file +DATA/IBRAC/ARCHIVELOG/2023_07_23/thread_2_seq_1.3980.1142919163
archived log for thread 2 with sequence 2 is already on disk as file +DATA/IBRAC/ARCHIVELOG/2023_07_23/thread_2_seq_2.3982.1142919163
archived log for thread 2 with sequence 3 is already on disk as file +DATA/IBRAC/ARCHIVELOG/2023_07_23/thread_2_seq_3.3984.1142919163
archived log for thread 2 with sequence 4 is already on disk as file +DATA/IBRAC/ARCHIVELOG/2023_07_22/thread_2_seq_4.4713.1142844169
archived log for thread 1 with sequence 1 is already on disk as file +DATA/IBRAC/ONLINELOG/group_1.273.1142773385
archived log for thread 2 with sequence 1 is already on disk as file +DATA/IBRAC/ONLINELOG/group_3.270.1142773383
archived log file name=+DATA/IBRAC/ARCHIVELOG/2023_07_23/thread_1_seq_1677.3988.1142919161 thread=1 sequence=1677
archived log file name=+DATA/IBRAC/ARCHIVELOG/2023_07_23/thread_2_seq_1701.3987.1142919161 thread=2 sequence=1701
archived log file name=+DATA/IBRAC/ARCHIVELOG/2023_07_23/thread_2_seq_1.3980.1142919163 thread=2 sequence=1
archived log file name=+DATA/IBRAC/ARCHIVELOG/2023_07_23/thread_1_seq_1.3981.1142919163 thread=1 sequence=1
archived log file name=+DATA/IBRAC/ARCHIVELOG/2023_07_23/thread_1_seq_2.3979.1142919163 thread=1 sequence=2
archived log file name=+DATA/IBRAC/ARCHIVELOG/2023_07_23/thread_2_seq_2.3982.1142919163 thread=2 sequence=2
archived log file name=+DATA/IBRAC/ARCHIVELOG/2023_07_23/thread_1_seq_3.3986.1142919163 thread=1 sequence=3
archived log file name=+DATA/IBRAC/ARCHIVELOG/2023_07_23/thread_1_seq_4.3985.1142919163 thread=1 sequence=4
archived log file name=+DATA/IBRAC/ARCHIVELOG/2023_07_23/thread_2_seq_3.3984.1142919163 thread=2 sequence=3
archived log file name=+DATA/IBRAC/ARCHIVELOG/2023_07_23/thread_1_seq_5.3983.1142919163 thread=1 sequence=5
archived log file name=+DATA/IBRAC/ARCHIVELOG/2023_07_22/thread_1_seq_6.4012.1142842377 thread=1 sequence=6
archived log file name=+DATA/IBRAC/ARCHIVELOG/2023_07_22/thread_2_seq_4.4713.1142844169 thread=2 sequence=4
archived log file name=+DATA/IBRAC/ONLINELOG/group_1.273.1142773385 thread=1 sequence=1
archived log file name=+DATA/IBRAC/ONLINELOG/group_3.270.1142773383 thread=2 sequence=1
Finished recover at 23-07-2023 06:07:53

Statement processed



SQL> startup pfile='/tmp/pfileIBRAC23.ora';
ORACLE instance started.

Total System Global Area 4294967296 bytes
Fixed Size                  8628936 bytes
Variable Size            1660945720 bytes
Database Buffers         2617245696 bytes
Redo Buffers                8146944 bytes
Database mounted.
Database opened.


col FILE_NAME for a30
select * from dba_temp_files where tablespace_name like 'TEMP%';SQL> SQL>

FILE_NAME                         FILE_ID TABLESPACE_NAME
------------------------------ ---------- ------------------------------
     BYTES     BLOCKS STATUS  RELATIVE_FNO AUT   MAXBYTES  MAXBLOCKS
---------- ---------- ------- ------------ --- ---------- ----------
INCREMENT_BY USER_BYTES USER_BLOCKS SHARED           INST_ID
------------ ---------- ----------- ------------- ----------
+DATA/ibrac/temp01.dbf                  1 TEMP
  30408704       3712 ONLINE             1 YES 3.4360E+10    4194302
          80   29360128        3584 SHARED



create spfile='+DATA/IBRAC/spfileIBRAC23.ora' from pfile='/tmp/pfileIBRAC23.ora';

srvctl modify database -d ibrac -spfile +DATA/IBRAC/spfileIBRAC23.ora


1018  07/23/23 07:26:28\ srvctl modify database -d ibrac -spfile +DATA/IBRAC/spfileIBRAC23.ora

[oracle@ibrac01:/tmp] $srvctl status database -d ibrac -v
Instance ibrac1 is not running on node ibrac01
Instance ibrac2 is not running on node ibrac02
[oracle@ibrac01:/tmp] $srvctl start database -d ibrac

[oracle@ibrac01:/tmp] $srvctl status database -d ibrac -v
Instance ibrac1 is running on node ibrac01. Instance status: Open.
Instance ibrac2 is running on node ibrac02. Instance status: Open.
[oracle@ibrac01:/tmp] $


Tuesday, 18 July 2023

Oracle initialization parameter changes from AWR

Oracle initialization parameter changes
Oracle initialization parameter changes

Oracle initialization parameter changes

  Oracle initialization parameter changes


VARIABLE BgnSnap NUMBER
VARIABLE EndSnap NUMBER
VARIABLE DID NUMBER
VARIABLE INST_NUMBER number
exec select max(snap_id) -24 into :BgnSnap from dba_hist_snapshot ;
exec select max(snap_id) into :EndSnap from dba_hist_snapshot ;
exec select DBID into :DID from v$database;
exec select INSTANCE_NUMBER into :INST_NUMBER from v$instance ;




set linesize 300 pagesiz 300
col NAME for a45
col BVAL for a20
col EVAL for a20
select e.parameter_name             name
         , b.value                      bval
         , decode(b.value, e.value, NULL, e.value) eval
      from dba_hist_parameter b
         , dba_hist_parameter e
     where b.snap_id(+)         = :BgnSnap
       and e.snap_id            = :EndSnap
       and b.dbid(+)            = :DID 
       and e.dbid               = :DID 
       and b.instance_number(+) = 1
       and e.instance_number    = 1
       and b.parameter_hash(+)  = e.parameter_hash
       and (   nvl(b.isdefault, 'X')   = 'FALSE'
            or nvl(b.ismodified,'X')  != 'FALSE'
            or     e.ismodified       != 'FALSE'
            or nvl(e.value,0)         != nvl(b.value,0)
           )
       and e.parameter_name not like '\_\_%' escape '\'
     order by e.parameter_name;
	 
	 
	 

Monday, 17 July 2023

ORACLE event to Sql ....


ORACLE event to Sql ....






VARIABLE BgnSnap NUMBER
VARIABLE EndSnap NUMBER
VARIABLE DID NUMBER
VARIABLE INST_NUMBER number
VARIABLE x VARCHAR2(30)
exec select max(snap_id) -1 into :BgnSnap from dba_hist_snapshot ;
exec select max(snap_id) into :EndSnap from dba_hist_snapshot ;
exec select DBID into :DID from v$database;
exec select INSTANCE_NUMBER into :INST_NUMBER from v$instance ;



col "Begin Snap" for a27                                                                 
col "End Snap" for a27   
col Event for a25 
col "Wait Class" for a15
select case wait_rank when 1 then inst_id end "Inst Num",
 case wait_rank when 1 then snap_id end "Snap Id",
 case wait_rank when 1 then begin_snap end "Begin Snap",
 case wait_rank when 1 then end_snap end "End Snap",
 event_name "Event",
 total_waits "Waits",
 time_waited "Time(s)",
 round((time_waited/total_waits)*1000) "Avg wait(ms)",
 round((time_waited/db_time)*100, 2) "% DB time",
 substr(wait_class, 1, 15) "Wait Class"
from (
select
  inst_id,
  snap_id, to_char(begin_snap, 'DD-MM-YY hh24:mi:ss') begin_snap,
  to_char(end_snap, 'hh24:mi:ss') end_snap,
  event_name,
  wait_class,
  total_waits,
  time_waited,
  dense_rank() over (partition by inst_id, snap_id order by time_waited desc)-1 wait_rank,
  max(time_waited) over (partition by inst_id, snap_id) db_time
from (
select
  s.instance_number inst_id,
  s.snap_id,
  s.begin_interval_time begin_snap,
  s.end_interval_time end_snap,
  event_name,
  wait_class,
  total_waits-lag(total_waits, 1, total_waits) over
   (partition by s.startup_time, s.instance_number, stats.event_name order by s.snap_id) total_waits,
  time_waited-lag(time_waited, 1, time_waited) over
   (partition by s.startup_time, s.instance_number, stats.event_name order by s.snap_id) time_waited,
  min(s.snap_id) over (partition by s.startup_time, s.instance_number, stats.event_name) min_snap_id
from (
 select dbid, instance_number, snap_id, event_name, wait_class, total_waits_fg total_waits, round(time_waited_micro_fg/1000000, 2) time_waited
  from dba_hist_system_event
  where wait_class not in ('Idle', 'System I/O')
 union all
 select dbid, instance_number, snap_id, stat_name event_name, null wait_class, null total_waits, round(value/1000000, 2) time_waited
  from dba_hist_sys_time_model
  where stat_name in ('DB CPU', 'DB time')
) stats, dba_hist_snapshot s
 where stats.instance_number=s.instance_number
  and stats.snap_id=s.snap_id
  and stats.dbid=s.dbid
  and s.instance_number = :INST_NUMBER
  and stats.snap_id between :BgnSnap and :EndSnap
  and stats.dbid = :DID 
) where snap_id > min_snap_id and nvl(total_waits,1) > 0
) where event_name!='DB time' and wait_rank <= 5
order by inst_id, snap_id;







VARIABLE BgnSnap NUMBER
VARIABLE EndSnap NUMBER
VARIABLE DID NUMBER
VARIABLE INST_NUMBER number
exec select max(snap_id) -24 into :BgnSnap from dba_hist_snapshot ;
exec select max(snap_id) into :EndSnap from dba_hist_snapshot ;


set lines 1000  pages 1000
select wait_class_id, wait_class, count(*) cnt
from dba_hist_active_sess_history
where snap_id between :BgnSnap and :EndSnap
group by wait_class_id, wait_class
order by 3;


select event_id, event, count(*) cnt from dba_hist_active_sess_history
where snap_id between :BgnSnap and :EndSnap and wait_class_id=3386400367  ---<<<< from above 
group by event_id, event
order by 3;


select sql_id, count(*) cnt from dba_hist_active_sess_history
where snap_id between :BgnSnap and :EndSnap
and event_id in ( 1328744198 )  --- from above 
group by sql_id
-- having count(*)> 100
order by 2




col sql_count for a30
with topsql as (
	select distinct sql_id, count(sql_id) over (partition by sql_id ) sql_id_count
	from dba_hist_active_sess_history h
	join dba_hist_snapshot s on s.snap_id = h.snap_id
		and s.dbid = h.dbid
		and s.instance_number = h.instance_number
	where s.begin_interval_time >= systimestamp - interval '1' day
	order by 2 desc
)
select sql_id ||','|| sql_id_count sql_count
from topsql
where rownum <= 100
/


SQL_COUNT
------------------------------
1rn43zb7tm2jg,7943
1zh2ms1aymubn,5902
720143cwrpuju,5510
87a333ujtm7q3,5243
9783wcf3s3634,3367
cmcuudhryjkkk,2378
cdmqjc2dtv99z,1638
9wr7pd23cxbb6,1629




select sql_text from gv$sql where sql_id='1456sjks32zqrb3';


==

define 3="TIMESTAMP'2023-07-20 02:10:00'" 
define 4="TIMESTAMP'2023-07-20 02:30:00'"


set linesize 500 pagesize 300
col WHAT for a45
col OBJ for a30
col EVENT for a35


select * from (
SELECT
    COUNT(*) count1,
   sql_id,
    event,
    session_state,
    sql_plan_operation
    || ' '
    || sql_plan_options AS what,
    CASE
        WHEN wait_class IN(
            'Application',
            'Cluster',
            'Concurrency',
            'User I/O'
        )THEN object_name
        ELSE 'undef'
    END AS obj
FROM
    gv$active_session_history ash,
    dba_objects o
WHERE
    ash.current_obj# = o.object_id
    --AND sql_id = '4ws10ggwp4npf'
--  AND sample_time BETWEEN &3 AND &4
AND sample_time >sysdate -1
GROUP BY
    sql_id,
    event,
    session_state,
    sql_plan_operation
    || ' '
    || sql_plan_options,
    CASE
        WHEN wait_class IN(
            'Application',
            'Cluster',
            'Concurrency',
            'User I/O'
        )THEN object_name
        ELSE 'undef'
    END
ORDER BY 1 desc
--and having  COUNT(*)>10
)
where 1=1
and COUNT1>10
;
===

define 3="TIMESTAMP'2023-07-20 02:10:00'" 
define 4="TIMESTAMP'2023-07-20 02:30:00'"


alter session set nls_date_format='dd-mm-yyyy hh24:mi';
select min(sample_time) from V$ACTIVE_SESSION_HISTORY

-- top events
select 
/*+PARALLEL(8)*/ event,count(*) from DBA_HIST_ACTIVE_SESS_HISTORY 
where 1=1
-- and sample_time> sysdate-1/24 
 AND sample_time BETWEEN &3 AND &4
and user_id>0
group by event
order by count(*) desc;


-- top sql
select /*+PARALLEL(8)*/ sql_id,count(*) from DBA_HIST_ACTIVE_SESS_HISTORY 
where 1=1
-- and sample_time> sysdate-1/24 
 AND sample_time BETWEEN &3 AND &4
group by sql_id
order by count(*) desc;


-- see specific samples
select /*+PARALLEL(8)*/ sample_time,user_id,sql_id,event from DBA_HIST_ACTIVE_SESS_HISTORY
where 1=1
-- and sample_time> sysdate-1/24 
 AND sample_time BETWEEN &3 AND &4
--and user_id>0
--and session_id=371
order by sample_time;

-- look for hot buffers
select p1,p2,p3,count(*) from DBA_HIST_ACTIVE_SESS_HISTORY
where 1=1
-- and sample_time> sysdate-1/24 
 AND sample_time BETWEEN &3 AND &4
and user_id>0
and event='buffer busy waits'
group by p1,p2,p3 
order by count(*)



SELECT SEGMENT_NAME, SEGMENT_TYPE FROM DBA_EXTENTS            
                WHERE FILE_ID = 1  AND 231928 BETWEEN BLOCK_ID AND                  
                      BLOCK_ID + BLOCKS - 1;  
					  
					  
					  

-- top SQL waiting for a specific events
select /*+PARALLEL(8)*/ sql_id,count(*) from DBA_HIST_ACTIVE_SESS_HISTORY
where 1=1
-- and sample_time> sysdate-1/24 
 AND sample_time BETWEEN &3 AND &4
and user_id>0
and event  is null
group by sql_id 
order by count(*)

-- top programs waiting for a specific events
select /*+PARALLEL(8)*/ program,count(*) from DBA_HIST_ACTIVE_SESS_HISTORY
where 1=1
-- and sample_time> sysdate-1/24 
 AND sample_time BETWEEN &3 AND &4
and user_id>0
and event='buffer busy waits'
group by program
order by count(*)
/


-- top users waiting for a specific events
select user_id,count(*) from DBA_HIST_ACTIVE_SESS_HISTORY
where 1=1
-- and sample_time> sysdate-1/24 
 AND sample_time BETWEEN &3 AND &4
and user_id>0
and event='buffer busy waits'
group by user_id
order by count(*)   ;

-- Everyone waiting for specific event
select /*+PARALLEL(8)*/ sample_time,user_id,sql_id,event,p1,blocking_session from gV$ACTIVE_SESSION_HISTORY
where 1=1
-- and sample_time> sysdate-1/24 
 AND sample_time BETWEEN &3 AND &4
and  event like 'library%'

;

-- Who is waiting for specific event the most:
select /*+PARALLEL(8)*/ SESSION_ID,user_id,sql_id,round(sample_time,'hh'),count(*) from V$ACTIVE_SESSION_HISTORY
where event like 'log file sync'
AND sample_time BETWEEN &3 AND &4
group by  SESSION_ID,user_id,sql_id,round(sample_time,'hh')
order by count(*) desc





select /*+PARALLEL(8)*/ event,count(*) from DBA_HIST_ACTIVE_SESS_HISTORY
where 1=1
-- and sample_time> sysdate-1/24 
 AND sample_time BETWEEN &3 AND &4
and user_id>0
group by event
order by count(*) desc


select /*+PARALLEL(8)*/ to_char(trunc(sample_time, 'hh24') + round((cast(sample_time as date)- trunc(cast(sample_time as date), 'hh24'))*60*24/5)*5/60/24, 'dd/mm/yyyy hh24:mi'),count(*) from DBA_HIST_ACTIVE_SESS_HISTORY
where 1=1
-- and sample_time> sysdate-1/24 
 AND sample_time BETWEEN &3 AND &4
--and user_id=209
and event='buffer busy waits'
group by to_char(trunc(sample_time, 'hh24') + round((cast(sample_time as date)- trunc(cast(sample_time as date), 'hh24'))*60*24/5)*5/60/24, 'dd/mm/yyyy hh24:mi')
order by count(*)


select sql_id,count(*) from gV$ACTIVE_SESSION_HISTORY
where 1=1
-- and sample_time> sysdate-1/24 
 AND sample_time BETWEEN &3 AND &4
and user_id>0
group by sql_id
order by count(*) desc

select * from dba_views where view_name like 'DBA_HIST%'

select /*+PARALLEL(8)*/ sh.sample_time,sh.SESSION_ID,user_id,sh.sql_id,event,p1,blocking_session,PROGRAM,sql_text
from DBA_HIST_ACTIVE_SESS_HISTORY sh
left outer join  DBA_HIST_SQLTEXT  sq on sq.sql_id=sh.sql_id 
where 1=1 
-- and sample_time> sysdate-1/24 
 AND sample_time BETWEEN &3 AND &4
--and user_id=61
and sh.sql_id='cdmqjc2dtv99z'
order by sample_time
/




select trunc(sample_time),
sum(case when INSTANCE_NUMBER=1 then 1 else 0 end) inst1,
sum(case when INSTANCE_NUMBER=2 then 1 else 0 end) inst2
from DBA_HIST_ACTIVE_SESS_HISTORY sh
where 1=1 
and user_id=61
group by trunc(sample_time)
order by trunc(sample_time)
;

set long 5000
select SQL_TEXT from DBA_HIST_SQLTEXT where sql_id='cdmqjc2dtv99z'
--and dbms_lob.instr(sql_text, 'GLOBAL',1,1) > 0
;



define 3="TIMESTAMP'2023-07-20 07:10:00'" 
define 4="TIMESTAMP'2023-07-20 07:30:00'"

COL wait_class FOR a15
COL event FOR a35
COL time_range  HEAD "WAIT_TIM_BUCKET_US+" FOR A26 JUST RIGHT
COL avg_wait_us HEAD "AVG_WAIT_IN_BKT_US" FOR 9,999,999,999
COL pct_event FOR a9
COL pct_event_vis FOR a13
COL pct_total_vis FOR a13
COL pct_total FOR a9

BREAK ON event      SKIP 1 NODUPLICATES ON state ON wait_class

-- TODO: ignore latest sample (0 waits)

SELECT /* (hint disabled) LEADING(@"SEL$4" "S"@"SEL$4" "A"@"SEL$4") USE_HASH(@"SEL$4" "A"@"SEL$4") PARALLEL(8)*/
    session_state state
  , wait_class
  , event
  , ROUND(AVG(time_waited)) avg_wait_us
  , LPAD(REPLACE(TO_CHAR(POWER(2,TRUNC(LOG(2,CASE WHEN time_waited < 1 THEN NULL ELSE time_waited END))),'9,999,999,999')||' ..'||TO_CHAR(POWER(2,TRUNC(LOG(2,CASE WHEN time_waited < 1 THEN NULL ELSE time_waited END)))*2, '9,999,999,999'), ' ',''), 26) time_range
  , COUNT(*) samples
  , LPAD(TO_CHAR(TO_NUMBER(ROUND(RATIO_TO_REPORT(COUNT(*)) OVER (PARTITION BY session_state, wait_class, event) * 100, 1), 999.9))||' %',8) pct_event
  , '|'||RPAD( NVL( LPAD('#', ROUND(RATIO_TO_REPORT(COUNT(*)) OVER (PARTITION BY session_state, wait_class, event) * 10), '#'), ' '), 10,' ')||'|' pct_event_vis
  , LPAD(TO_CHAR(TO_NUMBER(ROUND(RATIO_TO_REPORT(COUNT(*)) OVER () * 100, 1), 999.9))||' %',8) pct_total 
  , '|'||RPAD( NVL( LPAD('#', ROUND(RATIO_TO_REPORT(COUNT(*)) OVER () * 10), '#'), ' '), 10,' ')||'|' pct_total_vis
FROM
    gv$active_session_history
WHERE
    1=1
AND sample_time BETWEEN &3 AND &4
--AND sample_time BETWEEN sysdate-1/24 AND sysdate
--AND sample_time BETWEEN TIMESTAMP'2012-04-29 19:30:00' AND TIMESTAMP'2012-04-29 19:30:59'
--AND (REGEXP_LIKE(wait_class, '&1') OR REGEXP_LIKE(event, '&1'))
GROUP BY
    session_state
  , wait_class
  , event
  , POWER(2,TRUNC(LOG(2,CASE WHEN time_waited < 1 THEN NULL ELSE time_waited END)))
ORDER BY
    session_state
  , wait_class
  , event
  , time_range NULLS FIRST
  , samples DESC
/



STATE   WAIT_CLASS      EVENT                               AVG_WAIT_IN_BKT_US        WAIT_TIM_BUCKET_US+    SAMPLES PCT_EVENT PCT_EVENT_VIS PCT_TOTAL PCT_TOTAL_VIS
------- --------------- ----------------------------------- ------------------ -------------------------- ---------- --------- ------------- --------- -------------
ON CPU                                                                       0                         ..       9979    100 %  |##########|    26.7 %  |###    |

WAITING Commit          log file sync                                        0                         ..         52     .9 %  |          |  .1 %  |   |
                                                                         3,780               2,048..4,096         76    1.3 %  |          |  .2 %  |   |
                                                                         6,529               4,096..8,192       2361     41 %  |####      | 6.3 %  |#    




--desc DBA_HIST_ACTIVE_SESS_HISTORY 

--EXEC DBMS_MONITOR.session_trace_enable(session_id =>1234, serial_num=>1234, waits=>TRUE, binds=>FALSE);

select sample_time,user_id,sql_id,event,p1,blocking_session from gV$ACTIVE_SESSION_HISTORY
where event like 'library%'
AND sample_time BETWEEN &3 AND &4
/

===


set linesize 600
select 
sql_id,
plan_hash_value,
END_INTERVAL_TIME,
executions_delta,
ELAPSED_TIME_DELTA/(nonzeroexecutions*1000) "Elapsed Average ms",
CPU_TIME_DELTA/(nonzeroexecutions*1000) "CPU Average ms",
IOWAIT_DELTA/(nonzeroexecutions*1000) "IO Average ms",
CLWAIT_DELTA/(nonzeroexecutions*1000) "Cluster Average ms",
APWAIT_DELTA/(nonzeroexecutions*1000) "Application Average ms",
CCWAIT_DELTA/(nonzeroexecutions*1000) "Concurrency Average ms",
BUFFER_GETS_DELTA/nonzeroexecutions "Average buffer gets",
DISK_READS_DELTA/nonzeroexecutions "Average disk reads",
trunc(PHYSICAL_WRITE_BYTES_DELTA/(1024*1024*nonzeroexecutions)) "Average disk write megabytes",
ROWS_PROCESSED_DELTA/nonzeroexecutions "Average rows processed"
from
(select 
ss.snap_id,
ss.sql_id,
ss.plan_hash_value,
sn.END_INTERVAL_TIME,
ss.executions_delta,
case ss.executions_delta when 0 then 1 else ss.executions_delta end nonzeroexecutions,
ELAPSED_TIME_DELTA,
CPU_TIME_DELTA,
IOWAIT_DELTA,
CLWAIT_DELTA,
APWAIT_DELTA,
CCWAIT_DELTA,
BUFFER_GETS_DELTA,
DISK_READS_DELTA,
PHYSICAL_WRITE_BYTES_DELTA,
ROWS_PROCESSED_DELTA
from DBA_HIST_SQLSTAT ss,DBA_HIST_SNAPSHOT sn
where 1=1
and ss.sql_id = '01gmsncqrjrfr'
and ss.snap_id=sn.snap_id
and ss.INSTANCE_NUMBER=sn.INSTANCE_NUMBER)
where ELAPSED_TIME_DELTA > 0
order by snap_id,sql_id
;





VARIABLE BgnSnap NUMBER
VARIABLE EndSnap NUMBER
VARIABLE DID NUMBER
VARIABLE INST_NUMBER number
exec select max(snap_id) -24 into :BgnSnap from dba_hist_snapshot ;
exec select max(snap_id) into :EndSnap from dba_hist_snapshot ;


set linesize 500 pagesize 200
column_object_name format a31 
column owner format a15 
column "%TOT%" format a6 
column SQL_TEXT format a80 wrap on 

select distinct sub.parsing_schema_name,replace(replace(replace(DBMS_LOB.SUBSTR(DHST.sql_text,4000,1),chr(10),' '),chr(9),' '),' ',' ') SQL_TEXT, 
sub.EXECUTIONS,round((sub.EXECUTIONS/sub2.EXECUTIONS_TOTAL)*100)||'%' "%TOT%", 
sub.DISK_READS,round((sub.DISK_READS/sub2.DISK_READS_TOTAL)*100)||'%' "%TOT%", 
sub.BUFFER_GETS,round((sub.BUFFER_GETS/sub2.BUFFER_GETS_TOTAL)*100)||'%' "%TOT%", 
sub.ELAPSED_TIME,round((sub.ELAPSED_TIME/sub2.ELAPSED_TIME_TOTAL)*100)||'%' "%TOT%", 
sub.IOWAIT,sub.ROWS_PROCESSED, 
sub.SEC_PER_EXEC "SEC/EXE", 
round((sub.EXECUTIONS/sub2.EXECUTIONS_TOTAL)*100)+round((sub.DISK_READS/sub2.DISK_READS_TOTAL)*100)+round((sub.BUFFER_GETS/sub2.BUFFER_GETS_TOTAL)*100)+round((sub.ELAPSED_TIME/sub2.ELAPSED_TIME_TOTAL)*100) RANK 
from DBA_HIST_SQLTEXT DHST, 
( 
select distinct 
SQL_ID, 
PARSING_SCHEMA_NAME, 
round(sum(EXECUTIONS_DELTA)) as EXECUTIONS, 
round(sum(PARSE_CALLS_DELTA)) as PARSE_CALLS, 
round(sum(DISK_READS_DELTA)) as DISK_READS, 
round(sum(BUFFER_GETS_DELTA)) as BUFFER_GETS, 
round(sum(ROWS_PROCESSED_DELTA)) as ROWS_PROCESSED, 
round(sum(CPU_TIME_DELTA/1000000)) as CPU_TIME, 
round(sum(ELAPSED_TIME_DELTA/1000000)) ELAPSED_TIME, 
round(sum(IOWAIT_DELTA)/1000000) as IOWAIT, 
sum(ELAPSED_TIME_DELTA/1000000)/decode(sum(EXECUTIONS_DELTA),0,1,sum(EXECUTIONS_DELTA)) SEC_PER_EXEC 
from 
dba_hist_snapshot 
natural join 
dba_hist_sqlstat DHS 
natural join 
dba_hist_sql_plan DHSP 
where 
snap_id between :BgnSnap and :EndSnap
and parsing_schema_name not in ('SYS','SYSTEM','SPOT','TOAD','OUTLN','TSMSYS','DBSNMP','ORACLE_OCM','WMSYS','EXFSYS','ORDSYS','ORDPLUGINS','SI_INFORMTN_SCHEMA','MDSYS','OPS$ORACLE','XDB','ANONYMOUS','OLAPSYS','DMSYS','BACKUP') 
and object_owner not in ('SYS','SYSTEM','SPOT','TOAD','OUTLN','TSMSYS','DBSNMP','ORACLE_OCM','WMSYS','EXFSYS','ORDSYS','ORDPLUGINS','SI_INFORMTN_SCHEMA','MDSYS','OPS$ORACLE','XDB','ANONYMOUS','OLAPSYS','DMSYS','BACKUP') 
group by SQL_ID,PARSING_SCHEMA_NAME 
) sub, 
( 
select decode(round(sum(EXECUTIONS_DELTA)),0,1,round(sum(EXECUTIONS_DELTA))) as EXECUTIONS_TOTAL, 
decode(round(sum(DISK_READS_DELTA)),0,1,round(sum(DISK_READS_DELTA))) as DISK_READS_TOTAL, 
decode(round(sum(BUFFER_GETS_DELTA)),0,1,round(sum(BUFFER_GETS_DELTA))) as BUFFER_GETS_TOTAL, 
decode(round(sum(ELAPSED_TIME_DELTA/1000000)),0,1,round(sum(ELAPSED_TIME_DELTA/1000000))) as ELAPSED_TIME_TOTAL 
from 
dba_hist_snapshot 
natural join 
dba_hist_sqlstat DHS 
natural join 
dba_hist_sql_plan DHSP 
where 
snap_id between :BgnSnap and :EndSnap
and parsing_schema_name not in ('SYS','SYSTEM','SPOT','TOAD','OUTLN','TSMSYS','DBSNMP','ORACLE_OCM','WMSYS','EXFSYS','ORDSYS','ORDPLUGINS','SI_INFORMTN_SCHEMA','MDSYS','OPS$ORACLE','XDB','ANONYMOUS','OLAPSYS','DMSYS','BACKUP') 
and object_owner not in ('SYS','SYSTEM','SPOT','TOAD','OUTLN','TSMSYS','DBSNMP','ORACLE_OCM','WMSYS','EXFSYS','ORDSYS','ORDPLUGINS','SI_INFORMTN_SCHEMA','MDSYS','OPS$ORACLE','XDB','ANONYMOUS','OLAPSYS','DMSYS','BACKUP') 
) sub2 
where DHST.sql_id = sub.sql_id 
order by RANK Desc 
/





VARIABLE BgnSnap NUMBER
VARIABLE EndSnap NUMBER
VARIABLE DID NUMBER
VARIABLE INST_NUMBER number
exec select max(snap_id) -24 into :BgnSnap from dba_hist_snapshot ;
exec select max(snap_id) into :EndSnap from dba_hist_snapshot ;



set linesize 180
set pagesize 9999
column sql_id format a15
column num_versions format 999999
column sql_text format a70
column cpu_seconds format 999999999.99
column cpus_taken format 999.99
column pct_db_cpu alias "% DB CPU" format 99.99
column executions format 999999999999
 
with btime as (select begin_interval_time time from dba_hist_snapshot where snap_id = :BgnSnap),
 etime as (select end_interval_time time from dba_hist_snapshot where snap_id = :EndSnap),
 diff as (select (select time from etime) - (select time from btime) diff from dual),
 elapsed as (select 24*60*60*extract(day from diff) + 60*60*extract(hour from diff)+60*extract(minute from diff)+extract(second from diff) seconds from diff),
 osstat as (select value num_cpus from DBA_HIST_OSSTAT where snap_id = :EndSnap and stat_name= 'NUM_CPUS')
select i2.*
from
(    select inline.sql_id,
             num_versions,
             inline.cpu/1e6 cpu_seconds,
             (100*(case total.cpu when 0 then null else inline.cpu/total.cpu end)) pct_db_cpu,
             executions,
             inline.cpu/1e6/elapsed.seconds cpus_taken,
             dbms_lob.substr(replace(replace(sql_text, chr(10), ' '), chr(13)), 200) sql_text
    from
        elapsed,
        osstat,
    (       select decode(force_matching_signature, 0, dbms_lob.substr(replace(replace(sql_text, chr(10), ' '), chr(13)), 100), force_matching_signature) signature, min(st.sql_id) sql_id, sum(cpu_time_delta) cpu, count(distinct st.sql_id) num_versions, sum(executions_delta) executions
            from dba_hist_sqlstat st,
                    dba_hist_sqltext txt
            where st.sql_id = txt.sql_id
            and snap_id between :BgnSnap and :EndSnap
            group by decode(force_matching_signature, 0, dbms_lob.substr(replace(replace(sql_text, chr(10), ' '), chr(13)), 100), force_matching_signature)
    ) inline,
    (select sum(cpu) cpu from (select snap_id, (value-lag(value) over (partition by stat_name order by snap_id)) cpu from dba_hist_SYS_TIME_MODEL where stat_name = 'DB CPU' ) 
	where snap_id between :BgnSnap and :EndSnap) total,
    dba_hist_sqltext txt
    where inline.sql_id = txt.sql_id
) i2
order by cpu_seconds desc;

Thursday, 13 July 2023

How do I find my own session's serial# ?



How do I find my own session's serial# ?


My session 
col USERNAME  for a20
col event          for a30
select sid, serial#, username ,sql_id,event from v$session   where sid = ( select sid from v$mystat where rownum = 1);

===
set echo off feedback off heading on timi off pages 1000 lines 500 VERIFY OFF

col event          for a30
col wait_class     for a30
col waits          for 999,999,999
col time_waited_cs for 999,999,999
col avg_wait_cs    for 990.999
col USERNAME  for a20
select 
s.sid, s.serial#, s.CON_ID,s.username ,s.sql_id,
e.event,
       e.wait_class,
       sum(e.total_waits)  as waits,
       sum(e.time_waited)  as time_waited_cs,
       avg(e.average_wait) as avg_wait_cs
  from V$session_event e,v$session s
 where 1=1
and e.sid = sys_context('USERENV', 'SID')
   and e.wait_class <> 'Idle'
and e.sid=s.sid
 group by s.sid, s.serial#, s.CON_ID,s.username ,s.sql_id,e.event, e.wait_class
-- having sum(e.time_waited) > 0
 order by 4 desc
/

       SID    SERIAL#     CON_ID USERNAME             SQL_ID        EVENT                          WAIT_CLASS                            WAITS TIME_WAITED_CS AVG_WAIT_CS
__________ __________ __________ ____________________ _____________ ______________________________ ______________________________ ____________ ______________ ___________
       366      38442          0 SYS                  7kmh07qmcutq2 Disk file operations I/O       User I/O                                 24                   0       0.010
       366      38442          0 SYS                  7kmh07qmcutq2 SQL*Net break/reset to client  Application                              14                   0       0.000
       366      38442          0 SYS                  7kmh07qmcutq2 SQL*Net message to client      Network                                  26                   0       0.000
       366      38442          0 SYS                  7kmh07qmcutq2 control file sequential read   System I/O                                7                   1       0.070
       366      38442          0 SYS                  7kmh07qmcutq2 events in waitclass Other      Other                                   146                   7       0.050
SQL>

Tuesday, 4 July 2023

Oracle metadata for FUNCTION


Oracle metadata for FUNCTION




set linesize 300 pagesize 300

col USERNAME for a20 
col PASSWORD_LIFE_TIME for a20

SET LONG 10000 LONGCHUNKSIZE 10000 PAGESIZE 0 LINESIZE 1000 FEEDBACK OFF VERIFY OFF TRIMSPOOL ON
with x as 
(
  SELECT owner, object_name, object_type
    FROM dba_objects
  WHERE 1=1
-- and owner LIKE 'SYS'
    AND object_type IN ('PROCEDURE',  'FUNCTION')
and object_name in ('ORA12C_STRONG_VERIFY_FUNCTION','ORA_COMPLEXITY_CHECK')
)
SELECT  DBMS_METADATA.get_ddl (x.object_type, x.object_name, x.owner) as ddlcode FROM x;


Oracle DBA

anuj blog Archive