Search This Blog

Total Pageviews

Sunday, 23 February 2025

How to export PDB tables with out password with sys user ?

 How to export PDB tables with out password with sys user ?
========================================================================================



export ORACLE_PDB_SID=ANUJGP
expdp \'/ as sysdba\' schemas=ANUJ NOLOGFILE=y ESTIMATE_ONLY=y include=TABLE:"IN('JOB_LIST_143')"




Export: Release 19.0.0.0.0 - Production on Sun Feb 23 15:17:50 2025
Version 19.16.0.0.0

Copyright (c) 1982, 2019, Oracle and/or its affiliates.  All rights reserved.

Connected to: Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
FLASHBACK automatically enabled to preserve database integrity.
Starting "SYS"."SYS_EXPORT_SCHEMA_01":  "/******** AS SYSDBA" schemas=ANUJ NOLOGFILE=y ESTIMATE_ONLY=y include=TABLE:IN('JOB_LIST_143')
Estimate in progress using BLOCKS method...
Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA
.  estimated "ANUJ"."JOB_LIST_143"                      192 KB
Total estimation using BLOCKS method: 192 KB
Job "SYS"."SYS_EXPORT_SCHEMA_01" successfully completed at Sun Feb 23 15:18:09 2025 elapsed 0 00:00:18


******************************************

export ORACLE_PDB_SID=ANUJGP
expdp \'/ as sysdba\' schemas=ANUJ directory=ORACLE_BASE  dumpfile=JOB_LIST1.dmp logfile=JOB_LIST1.log include=TABLE:"IN('LIST_143')" compression=all ESTIMATE=STATISTICS metrics=Y JOB_NAME=JOB_LISTEXP



 expdp \'/ as sysdba\' schemas=ANUJ directory=ORACLE_BASE  dumpfile=JOB_LIST1.dmp logfile=JOB_LIST1.log include=TABLE:"IN('LIST_143')" compression=all ESTIMATE=STATISTICS metrics=Y JOB_NAME=JOB_LISTEXP

Export: Release 19.0.0.0.0 - Production on Sun Feb 23 15:34:49 2025
Version 19.16.0.0.0

Copyright (c) 1982, 2019, Oracle and/or its affiliates.  All rights reserved.

Connected to: Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
FLASHBACK automatically enabled to preserve database integrity.
Starting "SYS"."JOB_LISTEXP":  "/******** AS SYSDBA" schemas=ANUJ directory=ORACLE_BASE dumpfile=JOB_LIST1.dmp logfile=JOB_LIST1.log include=TABLE:IN('LIST_143') compression=all ESTIMATE=STATISTICS metrics=Y JOB_NAME=JOB_LISTEXP
W-1 Startup took 0 seconds
W-1 Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA
W-1 .  estimated "ANUJ"."LIST_143"                    5.481 KB
W-1 Processing object type SCHEMA_EXPORT/TABLE/INDEX/STATISTICS/INDEX_STATISTICS
W-1      Completed 2 INDEX_STATISTICS objects in 0 seconds
W-1 Processing object type SCHEMA_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS
W-1      Completed 1 TABLE_STATISTICS objects in 0 seconds
W-1 Processing object type SCHEMA_EXPORT/TABLE/PROCACT_INSTANCE
W-1      Completed 1 PROCACT_INSTANCE objects in 0 seconds
W-1 Processing object type SCHEMA_EXPORT/TABLE/TABLE
W-1      Completed 1 TABLE objects in 0 seconds
W-1 Processing object type SCHEMA_EXPORT/TABLE/INDEX/INDEX
W-1      Completed 1 INDEX objects in 1 seconds
W-1 Processing object type SCHEMA_EXPORT/TABLE/CONSTRAINT/CONSTRAINT
W-1      Completed 1 CONSTRAINT objects in 1 seconds
W-1 . . exported "ANUJ"."LIST_143"                    4.820 KB       1 rows in 0 seconds using direct_path
W-1      Completed 1 SCHEMA_EXPORT/TABLE/TABLE_DATA objects in 0 seconds
W-1 Master table "SYS"."JOB_LISTEXP" successfully loaded/unloaded
******************************************************************************
Dump file set for SYS.JOB_LISTEXP is:
  /u01/app/oracle/JOB_LIST1.dmp
Job "SYS"."JOB_LISTEXP" successfully completed at Sun Feb 23 15:36:15 2025 elapsed 0 00:01:25




How to export and import Unified Audit Trail from > Oracle 18c



How to export and import Unified Audit Trail from  > Oracle 18c
==================================================================

Via old method 
exp \"/ as sysdba\" file=expaudtable.dmp log=expaudtable.log tables=sys.aud$


https://anuj-singh.blogspot.com/2016/11/oracle-datapump-dir-grant-info.html

expdp \"/ as sysdba\" full=y directory=ORACLE_BASE  logfile=unified_audit_trail.dmp.log dumpfile=unified_audit_trail.dmp INCLUDE=AUDIT_TRAILS

Export: Release 19.0.0.0.0 - Production on Sun Feb 23 14:03:48 2025
Version 19.16.0.0.0

Copyright (c) 1982, 2019, Oracle and/or its affiliates.  All rights reserved.

Connected to: Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production




Warning: Oracle Data Pump operations are not typically needed when connected to the root or seed of a container database.

FLASHBACK automatically enabled to preserve database integrity.
Starting "SYS"."SYS_EXPORT_FULL_01":  "/******** AS SYSDBA" full=y directory=ORACLE_BASE logfile=unified_audit_trail.dmp.log dumpfile=unified_audit_trail.dmp INCLUDE=AUDIT_TRAILS

Processing object type DATABASE_EXPORT/EARLY_OPTIONS/VIEWS_AS_TABLES/TABLE_DATA
Processing object type DATABASE_EXPORT/NORMAL_OPTIONS/TABLE_DATA
Processing object type DATABASE_EXPORT/NORMAL_OPTIONS/VIEWS_AS_TABLES/TABLE_DATA
Processing object type DATABASE_EXPORT/PRE_SYSTEM_IMPCALLOUT/MARKER
Processing object type DATABASE_EXPORT/PRE_INSTANCE_IMPCALLOUT/MARKER
Processing object type DATABASE_EXPORT/EARLY_OPTIONS/VIEWS_AS_TABLES/TABLE
Processing object type DATABASE_EXPORT/EARLY_POST_INSTANCE_IMPCALLOUT/MARKER
Processing object type DATABASE_EXPORT/NORMAL_OPTIONS/TABLE
Processing object type DATABASE_EXPORT/NORMAL_OPTIONS/VIEWS_AS_TABLES/TABLE
Processing object type DATABASE_EXPORT/NORMAL_POST_INSTANCE_IMPCALLOUT/MARKER
Processing object type DATABASE_EXPORT/FINAL_POST_INSTANCE_IMPCALLOUT/MARKER
Processing object type DATABASE_EXPORT/POST_SYSTEM_IMPCALLOUT/MARKER
. . exported "SYS"."KU$_USER_MAPPING_VIEW"               6.078 KB      36 rows
. . exported "AUDSYS"."AUD$UNIFIED":"SYS_P5177"          204.5 MB  664247 rows
. . exported "AUDSYS"."AUD$UNIFIED":"SYS_P5986"          106.6 MB  350671 rows
. . exported "AUDSYS"."AUD$UNIFIED":"SYS_P5831"          84.63 MB  275667 rows
. . exported "AUDSYS"."AUD$UNIFIED":"SYS_P5347"          40.27 MB  124343 rows
. . exported "AUDSYS"."AUD$UNIFIED":"SYS_P5513"          30.60 MB   95274 rows
. . exported "AUDSYS"."AUD$UNIFIED":"SYS_P181"           41.19 MB   31632 rows
. . exported "AUDSYS"."AUD$UNIFIED":"SYS_P6152"          26.15 MB   85764 rows
. . exported "AUDSYS"."AUD$UNIFIED":"SYS_P5665"          24.40 MB   77046 rows
. . exported "AUDSYS"."AUD$UNIFIED":"SYS_P3069"          3.388 MB    7075 rows
. . exported "AUDSYS"."AUD$UNIFIED":"SYS_P457"           8.178 MB    3558 rows
. . exported "AUDSYS"."AUD$UNIFIED":"SYS_P3256"          1.510 MB    3023 rows
. . exported "AUDSYS"."AUD$UNIFIED":"SYS_P4655"          1.249 MB    2205 rows
. . exported "AUDSYS"."AUD$UNIFIED":"SYS_P5002"          1.159 MB    3171 rows
. . exported "AUDSYS"."AUD$UNIFIED":"SYS_P3966"          1.178 MB    2198 rows
. . exported "AUDSYS"."AUD$UNIFIED":"SYS_P4151"          813.7 KB    1985 rows
. . exported "AUDSYS"."AUD$UNIFIED":"SYS_P4325"          714.2 KB    1261 rows
. . exported "AUDSYS"."AUD$UNIFIED":"SYS_P4836"          507.6 KB     869 rows
. . exported "AUDSYS"."AUD$UNIFIED":"SYS_P3796"          483.1 KB     854 rows
. . exported "AUDSYS"."AUD$UNIFIED":"SYS_P2745"          646.2 KB     434 rows
. . exported "AUDSYS"."AUD$UNIFIED":"SYS_P4485"          293.0 KB     462 rows
. . exported "AUDSYS"."AUD$UNIFIED":"SYS_P3630"          218.0 KB     352 rows
. . exported "AUDSYS"."AUD$UNIFIED":"SYS_P3454"          115.6 KB     149 rows
. . exported "AUDSYS"."AUD$UNIFIED":"SYS_P2499"          109.2 KB     105 rows
. . exported "AUDSYS"."AUD$UNIFIED":"SYS_P2912"          84.62 KB      70 rows
. . exported "AUDSYS"."AUD$UNIFIED":"SYS_P1987"          67.64 KB      42 rows
. . exported "AUDSYS"."AUD$UNIFIED":"SYS_P1335"          65.55 KB      32 rows
. . exported "AUDSYS"."AUD$UNIFIED":"SYS_P2227"          59.61 KB      19 rows
. . exported "AUDSYS"."AUD$UNIFIED":"SYS_P1130"          51.52 KB       2 rows
. . exported "SYS"."DAM_CLEANUP_JOBS$"                   7.242 KB       1 rows
. . exported "SYS"."DAM_CONFIG_PARAM$"                   6.585 KB      18 rows
. . exported "AUDSYS"."AUD$UNIFIED":"AUD_UNIFIED_P0"         0 KB       0 rows
. . exported "SYS"."AUD$"                                    0 KB       0 rows
. . exported "SYS"."DAM_CLEANUP_EVENTS$"                     0 KB       0 rows
. . exported "SYS"."AUDTAB$TBS$FOR_EXPORT"               5.953 KB       2 rows
. . exported "SYS"."FGA_LOG$FOR_EXPORT"                      0 KB       0 rows
Master table "SYS"."SYS_EXPORT_FULL_01" successfully loaded/unloaded
******************************************************************************
Dump file set for SYS.SYS_EXPORT_FULL_01 is:
  /u01/app/oracle/unified_audit_trail.dmp
Job "SYS"."SYS_EXPORT_FULL_01" successfully completed at Sun Feb 23 14:07:13 2025 elapsed 0 00:03:18



 ls -lthr /u01/app/oracle/unified_audit_trail.dmp
-rw-r----- 1 oracle asmadmin 581M Feb 23 14:07 /u01/app/oracle/unified_audit_trail.dmp





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

with datapump api 



declare
l_datapump_handle NUMBER; -- Data Pump job handle
l_datapump_dir VARCHAR2(20) := 'ORACLE_BASE'; -- Data Pump Directory
l_status varchar2(200); -- Data Pump Status
begin
l_datapump_handle := dbms_datapump.open(operation => 'EXPORT', -- operation = EXPORT, IMPORT, SQL_FILE
job_mode =>'FULL', -- job_mode = FULL, SCHEMA, TABLE, TABLESPACE, TRANSPORTABLE
job_name => 'AUD FULL EXPORT JOB RUN 002', -- job_name = NULL (default) or: job name (max 30 chars)
version => 'latest'); -- version = COMPATIBLE (default), LATEST (dbversion), a value (11.0.0 or 12)
dbms_datapump.add_file(handle => l_datapump_handle,filename => 'exp_FULL_AUD_%U.dmp',directory => l_datapump_dir);
dbms_datapump.add_file(handle => l_datapump_handle,filename => 'exp_FULL_AUD.log' ,directory => l_datapump_dir ,filetype => DBMS_DATAPUMP.ku$_file_type_log_file);
dbms_datapump.metadata_filter(handle => l_datapump_handle, name => 'EXCLUDE_PATH_EXPR', value => 'IN(''AUDIT_TRAILS'')');
dbms_datapump.set_parameter(l_datapump_handle,'CLIENT_COMMAND','Full Consistent Data Pump Export of AUD Schema HR with PARALLEL 8');
dbms_datapump.set_parameter(l_datapump_handle,'FLASHBACK_TIME','SYSTIMESTAMP');
dbms_datapump.set_parallel(l_datapump_handle,8); -----<<< parallel 
dbms_datapump.start_job(handle => l_datapump_handle);
dbms_datapump.wait_for_job(handle => l_datapump_handle,
job_state => l_status );
dbms_output.put_line( l_status );
end;
/



-rw-r--r--   1 oracle asmadmin         0 Feb 23 14:14 exp_FULL_AUD.log
-rw-r-----   1 oracle asmadmin     16384 Feb 23 14:15 exp_FULL_AUD_07.dmp
-rw-r-----   1 oracle asmadmin     36864 Feb 23 14:15 exp_FULL_AUD_03.dmp
-rw-r-----   1 oracle asmadmin     57344 Feb 23 14:16 exp_FULL_AUD_02.dmp
-rw-r-----   1 oracle asmadmin     20480 Feb 23 14:16 exp_FULL_AUD_04.dmp
-rw-r-----   1 oracle asmadmin     28672 Feb 23 14:16 exp_FULL_AUD_01.dmp
-rw-r-----   1 oracle asmadmin     24576 Feb 23 14:16 exp_FULL_AUD_06.dmp
-rw-r-----   1 oracle asmadmin     16384 Feb 23 14:16 exp_FULL_AUD_05.dmp


Wednesday, 12 February 2025

Oracle 23ai sqlplus ping command



tns file !!!!

cat /opt/oracle/product/23ai/dbhomeFree/network/admin/tnsnames.ora
# tnsnames.ora Network Configuration File: /opt/oracle/product/23ai/dbhomeFree/network/admin/tnsnames.ora
# Generated by Oracle configuration tools.

FREE =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = FREE)
    )
  )

LISTENER_FREE =
  (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))


FREEPDB1 =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = FREEPDB1)
    )
  )



===

https://www.oracle.com/ie/a/otn/docs/database/oracle-net-23ai-new-features.pdf

on 23ai  !!!!!

sqlplus -v

SQL*Plus: Release 23.0.0.0.0 - for Oracle Cloud and Engineered Systems
Version 23.5.0.24.07





 new sqlplus ping command 

sqlplus -help

Saturday, 8 February 2025

DBMS_SERVICE for Single Instance Databases and status

http://anuj-singh.blogspot.com/2024/12/how-to-create-oracle-database-services.html



edit tnsnames.ora

cd $ORACLE_HOME/network/admin

anujv =
 (DESCRIPTION =
 (ADDRESS_LIST =
 (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.85.129)(PORT = 1521)))
 (CONNECT_DATA =
 (SERVICE_NAME = anuj)
 )
  )


to Create service 

BEGIN
  DBMS_SERVICE.create_service(
    service_name => 'ANUJ',
    network_name => 'ANUJ'
  );
END;
/

====

BEGIN
  DBMS_SERVICE.start_service(
    service_name => 'ANUJ'
  );
END;
/


COLUMN name FORMAT A30
COLUMN network_name FORMAT A30

SELECT name,
       network_name
FROM   dba_services
ORDER BY 1;


COLUMN name FORMAT A30
COLUMN network_name FORMAT A30



SELECT name,
       network_name
FROM   v$active_services
ORDER BY 1;



check the status from both view ..

COLUMN name FORMAT A30
COLUMN network_name FORMAT A30

SELECT 'ACTIVE' name,
       network_name
FROM   v$active_services
where 1=1
and NETWORK_NAME is not null
union all
SELECT 'DBA***' name,
       network_name
FROM   dba_services
where 1=1
and NETWORK_NAME is not null
order by 2
;

=====

lsnrctl services |grep -i -A3 ANUJ




sqlplus vihaan1/vihaan1@192.168.85.129:1521/anujv



set linesize 300 pagesize 300 
col USERNAME for a20
col MACHINE for a20
col for MACHINE for a20
col PROGRAM for a35
col SERVICE_NAME for a20
col OSUSER for a25

SELECT service_name, inst_id, count(*), username, machine, program, osuser
FROM gv$session
WHERE 1=1
-- and service_name NOT IN ('SYS$BACKGROUND','SYS$USERS')
--AND inst_id=1
GROUP BY service_name, inst_id, username, machine, program, osuser
ORDER BY service_name, inst_id, username, machine, program;


BEGIN
  DBMS_SERVICE.disconnect_session(
   service_name      => 'ANUJ',
   disconnect_option => DBMS_SERVICE.immediate
  );
END;
/

Friday, 31 January 2025

Stale Statistics sql



----  check_stale_stats.sql

-- - - - - - - - - - - - - - - - - - - - - - - - - Script begins here - - - - - - - - - - - - - - - - - - - - - - - - - -
--  NAME:  CHECK_STALE_STATS.SQL
--   Execute as SYS as sysdba
-- ---------------------------------------------------------------------------------------------------------------- 
-- AUTHOR:  
--    Raja Ganesh - Oracle Support Services - DataServer Group
--    Copyright 2008, Oracle Corporation      
-- ----------------------------------------------------------------------------------------------------------------- 
-- PURPOSE: 
-- This script is an automated way to deal with stale statistics 
-- operations that are required to be done as part of manual 
-- upgrade OR when reported by DBUA.
-- 
-- This script will work in both Windows and Unix platforms from database 
-- version 9.2 or higher.
-- ------------------------------------------------------------------------------------------------------------------ 
-- DISCLAIMER: 
--    This script is provided for educational purposes only. It is NOT  
--    supported by Oracle World Wide Technical Support. 
--    The script has been tested and appears to work as intended. 
--    You should always run new scripts on a test instance initially. 
-- -------------------------------------------------------------------------------------------------------------------
-- VERSION HISTORY
-- V1 sdixon : added 12.1.0' and added 19c as well to supported versions
--


SET FEEDBACK OFF
SET LINESIZE 250
SET SERVEROUTPUT ON

DECLARE
-- Variables declared
P_OTAB DBMS_STATS.OBJECTTAB;
MCOUNT NUMBER := 0;
P_VERSION VARCHAR2(10);
-- Cursor defined
CURSOR c1
IS
SELECT distinct schema
FROM dba_registry
ORDER by 1;

-- Beginning of the anonymous block
BEGIN
-- Verifying version from v$instance
SELECT version INTO p_version FROM v$instance;
DBMS_OUTPUT.PUT_LINE(chr(13));
-- Defining Loop 1 for listing schema which have stale stats
FOR x in c1 
  LOOP
	DBMS_STATS.GATHER_SCHEMA_STATS(OWNNAME=>x.schema,OPTIONS=>'LIST STALE',OBJLIST=>p_otab);

-- Defining Loop 2 to find number of objects containing stale stats
	FOR i in 1 .. p_otab.count
	  LOOP
		IF p_otab(i).objname NOT LIKE 'SYS_%' 
			AND p_otab(i).objname NOT IN ('CLU$','COL_USAGE$','FET$','INDPART$',
										  'MON_MODS$','TABPART$','HISTGRM$',
										  'MON_MODS_ALL$',
										  'HIST_HEAD$','IN $','TAB$',
										  'WRI$_OPTSTAT_OPR','PUIU$DATA',
										  'XDB$NLOCKS_CHILD_NAME_IDX',
										  'XDB$NLOCKS_PARENT_OID_IDX',
										  'XDB$NLOCKS_RAWTOKEN_IDX', 'XDB$SCHEMA_URL',
										  'XDBHI_IDX', 'XDB_PK_H_LINK')
		THEN
-- Incrementing count for  each object found with statle stats
			mcount := mcount + 1;
		END IF;
-- End of Loop 2
	  END LOOP;

-- Displays no stale statistics, if coun  is 0
		IF mcount!=0 
			THEN
-- Displays Schema with stale stats if count is greater than 0
				DBMS_OUTPUT.PUT_LINE(chr(13));
				DBMS_OUTPUT.PUT_LINE('-------------------------------------------------------------------------------------------------------');
				DBMS_OUTPUT.PUT_LINE('-- '|| x.schema || ' schema contains stale statistics use the following to gather the statistics '||'--');
				DBMS_OUTPUT.PUT_LINE('-------------------------------------------------------------------------------------------------------');
				
-- Displays Command to be executed if schema with stale statistics is found depending on the version.
		  IF SUBSTR(p_version,1,5) in ('8.1.7','9.0.1','9.2.0') 
			THEN
				DBMS_OUTPUT.PUT_LINE(chr(13));
				DBMS_OUTPUT.PUT_LINE('EXEC DBMS_STATS.GATHER_SCHEMA_STATS('''||x.schema||''',OPTIONS=>'''||'GATHER STALE'||''', ESTIMATE_PERCENT  => DBMS_STATS.AUTO_SAMPLE_SIZE, METHOD_OPT => '''||'FOR ALL COLUMNS SIZE AUTO'||''', CASCADE => TRUE);');
		  ELSIF SUBSTR(p_version,1,6) in ('10.1.0','10.2.0','11.1.0','11.2.0','12.1.0','12.2.0','19.2.0') 
			THEN
				DBMS_OUTPUT.PUT_LINE(chr(13));
				DBMS_OUTPUT.PUT_LINE('EXEC DBMS_STATS.GATHER_DICTIONARY_STATS('''||x.schema||''',OPTIONS=>'''||'GATHER STALE'||''', ESTIMATE_PERCENT  => DBMS_STATS.AUTO_SAMPLE_SIZE, METHOD_OPT => '''||'FOR ALL COLUMNS SIZE AUTO'||''', CASCADE => TRUE);');
		  ELSE
				DBMS_OUTPUT.PUT_LINE(chr(13));
				DBMS_OUTPUT.PUT_LINE('Version is '||p_version);
		  END IF;
		ELSE
				DBMS_OUTPUT.PUT_LINE('-- There are no stale statistics in '|| x.schema || ' schema.');
				DBMS_OUTPUT.PUT_LINE(chr(13));
		END IF;
-- Reset count to 0.
			mcount := 0;
-- End of Loop 1
  END LOOP;
END;
/

SET FEEDBACK ON

-- - - - - - - - - - - - - - - - - - - - - - - - - Script ends here - - - - - - - - - - - - - - - - - - - - - - - - - -

Sunday, 26 January 2025

Oracle tnsping and connection testing

tnsping '(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(Host=127.0.0.1)(Port=1521))(CONNECT_DATA=(SID=oem)))' 10


tnsping '(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(Host=127.0.0.1)(Port=1521))(CONNECT_DATA=(SID=oem)(SERVICE_NAME= empdbrepos)))' 10

tnsping '(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(Host=192.168.1.197)(Port=1521))(CONNECT_DATA=(SERVICE_NAME= empdbrepos)))' 10


=======
tnsping '(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(Host=192.168.1.197)(Port=1521))(CONNECT_DATA=(SID=oem)(SERVICE_NAME= empdbrepos)))' 10

TNS Ping Utility for Linux: Version 19.0.0.0.0 - Production on 26-JAN-2025 11:49:54

Copyright (c) 1997, 2024, Oracle.  All rights reserved.

Attempting to contact (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(Host=192.168.1.197)(Port=1521))(CONNECT_DATA=(SID=oem)(SERVICE_NAME= empdbrepos)))
OK (0 msec)
OK (0 msec)
OK (10 msec)
OK (0 msec)
OK (0 msec)
OK (0 msec)
OK (0 msec)
OK (0 msec)
OK (0 msec)
OK (0 msec)
=========


connection test via sqlplus 


for i in {1..2} ; do sqlplus -L -s sys/sys@//192.168.1.197/empdbrepos as sysdba <<< 'select name,open_mode,instance_name from v$instance , v$database;'; done


for i in {1..2} ; do sqlplus -L -s sys/sys@//192.168.1.197/empdbrepos as sysdba <<< 'select DUMMY from dual;'; done

D
-
X


D
-
X


=====

SQL> grant dba to anuj identified by vihaan123 ;


Grant succeeded.


sqlplus 'anuj/vihaan123@(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(Host=127.0.0.1)(Port=1521))(CONNECT_DATA=(SID=oem)(SERVICE_NAME= empdbrepos)))'


[oracle@ORAOEM admin]$ sqlplus 'anuj/vihaan123@empdbrepos'


======

while true do for i in {1..2} ; do sqlplus -L -s sys/sys@//192.168.1.197/empdbrepos as sysdba <<< 'select name,open_mode,instance_name from v$instance , v$database;'; done done



while true
do
  for i in {1..2} ; do sqlplus -L -s sys/sys@//192.168.1.197/empdbrepos as sysdba <<< 'select name,open_mode,instance_name from v$instance , v$database;'; done
  sleep 5
done

unix while loop




while true
do
echo Filesystem           Size  Used Avail Use% Mounted on
  df -Ph | grep home
  sleep 4
df -k | grep home
done


=====================================
output 


Filesystem Size Used Avail Use% Mounted on
/dev/mapper/cl-home   96G   42G   55G  44% /home
/dev/mapper/cl-home 100298908 43191548  57107360  44% /home
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/cl-home   96G   42G   55G  44% /home
/dev/mapper/cl-home 100298908 43191552  57107356  44% /home
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/cl-home   96G   42G   55G  44% /home
/dev/mapper/cl-home 100298908 43191552  57107356  44% /home

Tuesday, 21 January 2025

Oracle oracle-database-preinstall-19c-1.0-2.el8.x86_64.rpm on centos 8

 
[root@localhost yum.repos.d]# lsb_release -a
LSB Version:    :core-4.1-amd64:core-4.1-noarch
Distributor ID: CentOS
Description:    CentOS Linux release 8.5.2111
Release:        8.5.2111
Codename:       n/a


curl -o oracle-database-preinstall-19c-1.0-2.el8.x86_64.rpm https://yum.oracle.com/repo/OracleLinux/OL8/appstream/x86_64/getPackage/oracle-database-preinstall-19c-1.0-2.el8.x86_64.rpm



[root@localhost yum.repos.d]# dnf -y localinstall oracle-database-preinstall-19c-1.0-2.el8.x86_64.rpm
CentOS Linux 8 - AppStream                                                                                                                                                     0.0  B/s |   0  B     00:00
Errors during downloading metadata for repository 'appstream':
  - Curl error (6): Couldn't resolve host name for http://mirrorlist.centos.org/?release=8&arch=x86_64&repo=AppStream&infra=stock [Could not resolve host: mirrorlist.centos.org]
Error: Failed to download metadata for repo 'appstream': Cannot prepare internal mirrorlist: Curl error (6): Couldn't resolve host name for http://mirrorlist.centos.org/?release=8&arch=x86_64&repo=AppStream&infra=stock [Could not resolve host: mirrorlist.centos.org]

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

[root@localhost yum.repos.d]# cd /etc/yum.repos.d/
[root@localhost yum.repos.d]# sed -i 's/mirrorlist/#mirrorlist/g' /etc/yum.repos.d/CentOS-*
[root@localhost yum.repos.d]# sed -i 's|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g' /etc/yum.repos.d/CentOS-*

===
[root@localhost yum.repos.d]# dnf -y localinstall oracle-database-preinstall-19c-1.0-2.el8.x86_64.rpm
CentOS Linux 8 - AppStream                                                                                                                                                     4.6 MB/s | 8.4 MB     00:01
CentOS Linux 8 - BaseOS                                                                                                                                                        3.3 MB/s | 4.6 MB     00:01
CentOS Linux 8 - Extras                                                                                                                                                        3.2 kB/s | 1.5 kB     00:00
Dependencies resolved.
===============================================================================================================================================================================================================
 Package                                                     Architecture                        Version                                                       Repository                                 Size
===============================================================================================================================================================================================================
Installing:
 oracle-database-preinstall-19c                              x86_64                              1.0-2.el8                                                     @commandline                               31 k
Installing dependencies:
 glibc-devel                                                 x86_64                              2.28-164.el8                                                  baseos                                    1.0 M
 glibc-headers                                               x86_64                              2.28-164.el8                                                  baseos                                    480 k
 kernel-headers                                              x86_64                              4.18.0-348.7.1.el8_5                                          baseos                                    8.3 M
 ksh                                                         x86_64                              20120801-254.el8                                              appstream                                 926 k
 libXxf86dga                                                 x86_64                              1.1.5-1.el8                                                   appstream                                  26 k
 libaio-devel                                                x86_64                              0.3.112-1.el8                                                 baseos                                     19 k
 libdmx                                                      x86_64                              1.1.4-3.el8                                                   appstream                                  22 k
 libnsl                                                      x86_64                              2.28-164.el8                                                  baseos                                    103 k
 libstdc++-devel                                             x86_64                              8.5.0-4.el8_5                                                 appstream                                 2.0 M
 libxcrypt-devel                                             x86_64                              4.1.1-6.el8                                                   baseos                                     25 k
 lm_sensors-libs                                             x86_64                              3.4.0-23.20180522git70f7e08.el8                               baseos                                     59 k
 make                                                        x86_64                              1:4.2.1-10.el8                                                baseos                                    498 k
 sysstat                                                     x86_64                              11.7.3-6.el8                                                  appstream                                 425 k
 xorg-x11-utils                                              x86_64                              7.5-28.el8                                                    appstream                                 136 k

Transaction Summary
===============================================================================================================================================================================================================
Install  15 Packages

Total size: 14 M
Total download size: 14 M
Installed size: 26 M
Downloading Packages:
(1/14): libXxf86dga-1.1.5-1.el8.x86_64.rpm                                                                                                                                      51 kB/s |  26 kB     00:00
(2/14): libdmx-1.1.4-3.el8.x86_64.rpm                                                                                                                                           42 kB/s |  22 kB     00:00
(3/14): sysstat-11.7.3-6.el8.x86_64.rpm                                                                                                                                        4.4 MB/s | 425 kB     00:00
(4/14): libstdc++-devel-8.5.0-4.el8_5.x86_64.rpm                                                                                                                                12 MB/s | 2.0 MB     00:00
(5/14): xorg-x11-utils-7.5-28.el8.x86_64.rpm                                                                                                                                   1.7 MB/s | 136 kB     00:00
(6/14): glibc-headers-2.28-164.el8.x86_64.rpm                                                                                                                                  5.9 MB/s | 480 kB     00:00
(7/14): glibc-devel-2.28-164.el8.x86_64.rpm                                                                                                                                    8.4 MB/s | 1.0 MB     00:00
(8/14): kernel-headers-4.18.0-348.7.1.el8_5.x86_64.rpm                                                                                                                          18 MB/s | 8.3 MB     00:00
(9/14): libnsl-2.28-164.el8.x86_64.rpm                                                                                                                                         3.1 MB/s | 103 kB     00:00
(10/14): libxcrypt-devel-4.1.1-6.el8.x86_64.rpm                                                                                                                                993 kB/s |  25 kB     00:00
(11/14): libaio-devel-0.3.112-1.el8.x86_64.rpm                                                                                                                                  27 kB/s |  19 kB     00:00
(12/14): make-4.2.1-10.el8.x86_64.rpm                                                                                                                                          8.2 MB/s | 498 kB     00:00
(13/14): ksh-20120801-254.el8.x86_64.rpm                                                                                                                                       554 kB/s | 926 kB     00:01
(14/14): lm_sensors-libs-3.4.0-23.20180522git70f7e08.el8.x86_64.rpm                                                                                                             88 kB/s |  59 kB     00:00
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                                                                          7.1 MB/s |  14 MB     00:01
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                                                                                                                                       1/1
  Installing       : make-1:4.2.1-10.el8.x86_64                                                                                                                                                           1/15
  Running scriptlet: make-1:4.2.1-10.el8.x86_64                                                                                                                                                           1/15
  Installing       : lm_sensors-libs-3.4.0-23.20180522git70f7e08.el8.x86_64                                                                                                                               2/15
  Running scriptlet: lm_sensors-libs-3.4.0-23.20180522git70f7e08.el8.x86_64                                                                                                                               2/15
  Installing       : sysstat-11.7.3-6.el8.x86_64                                                                                                                                                          3/15
  Running scriptlet: sysstat-11.7.3-6.el8.x86_64                                                                                                                                                          3/15
  Installing       : libnsl-2.28-164.el8.x86_64                                                                                                                                                           4/15
  Installing       : libaio-devel-0.3.112-1.el8.x86_64                                                                                                                                                    5/15
  Installing       : kernel-headers-4.18.0-348.7.1.el8_5.x86_64                                                                                                                                           6/15
  Running scriptlet: glibc-headers-2.28-164.el8.x86_64                                                                                                                                                    7/15
  Installing       : glibc-headers-2.28-164.el8.x86_64                                                                                                                                                    7/15
  Installing       : libxcrypt-devel-4.1.1-6.el8.x86_64                                                                                                                                                   8/15
  Installing       : glibc-devel-2.28-164.el8.x86_64                                                                                                                                                      9/15
  Running scriptlet: glibc-devel-2.28-164.el8.x86_64                                                                                                                                                      9/15
  Installing       : libstdc++-devel-8.5.0-4.el8_5.x86_64                                                                                                                                                10/15
  Installing       : libdmx-1.1.4-3.el8.x86_64                                                                                                                                                           11/15
  Installing       : libXxf86dga-1.1.5-1.el8.x86_64                                                                                                                                                      12/15
  Installing       : xorg-x11-utils-7.5-28.el8.x86_64                                                                                                                                                    13/15
  Installing       : ksh-20120801-254.el8.x86_64                                                                                                                                                         14/15
  Running scriptlet: ksh-20120801-254.el8.x86_64                                                                                                                                                         14/15
  Running scriptlet: oracle-database-preinstall-19c-1.0-2.el8.x86_64                                                                                                                                     15/15
  Installing       : oracle-database-preinstall-19c-1.0-2.el8.x86_64                                                                                                                                     15/15
  Running scriptlet: oracle-database-preinstall-19c-1.0-2.el8.x86_64                                                                                                                                     15/15
Failed to reload daemon: Access denied
warning: %transfiletriggerin(systemd-239-51.el8_5.2.x86_64) scriptlet failed, exit status 1

Error in  scriptlet in rpm package oracle-database-preinstall-19c
  Verifying        : ksh-20120801-254.el8.x86_64                                                                                                                                                          1/15
  Verifying        : libXxf86dga-1.1.5-1.el8.x86_64                                                                                                                                                       2/15
  Verifying        : libdmx-1.1.4-3.el8.x86_64                                                                                                                                                            3/15
  Verifying        : libstdc++-devel-8.5.0-4.el8_5.x86_64                                                                                                                                                 4/15
  Verifying        : sysstat-11.7.3-6.el8.x86_64                                                                                                                                                          5/15
  Verifying        : xorg-x11-utils-7.5-28.el8.x86_64                                                                                                                                                     6/15
  Verifying        : glibc-devel-2.28-164.el8.x86_64                                                                                                                                                      7/15
  Verifying        : glibc-headers-2.28-164.el8.x86_64                                                                                                                                                    8/15
  Verifying        : kernel-headers-4.18.0-348.7.1.el8_5.x86_64                                                                                                                                           9/15
  Verifying        : libaio-devel-0.3.112-1.el8.x86_64                                                                                                                                                   10/15
  Verifying        : libnsl-2.28-164.el8.x86_64                                                                                                                                                          11/15
  Verifying        : libxcrypt-devel-4.1.1-6.el8.x86_64                                                                                                                                                  12/15
  Verifying        : lm_sensors-libs-3.4.0-23.20180522git70f7e08.el8.x86_64                                                                                                                              13/15
  Verifying        : make-1:4.2.1-10.el8.x86_64                                                                                                                                                          14/15
  Verifying        : oracle-database-preinstall-19c-1.0-2.el8.x86_64                                                                                                                                     15/15

Installed:
  glibc-devel-2.28-164.el8.x86_64                           glibc-headers-2.28-164.el8.x86_64            kernel-headers-4.18.0-348.7.1.el8_5.x86_64                       ksh-20120801-254.el8.x86_64
  libXxf86dga-1.1.5-1.el8.x86_64                            libaio-devel-0.3.112-1.el8.x86_64            libdmx-1.1.4-3.el8.x86_64                                        libnsl-2.28-164.el8.x86_64
  libstdc++-devel-8.5.0-4.el8_5.x86_64                      libxcrypt-devel-4.1.1-6.el8.x86_64           lm_sensors-libs-3.4.0-23.20180522git70f7e08.el8.x86_64           make-1:4.2.1-10.el8.x86_64
  oracle-database-preinstall-19c-1.0-2.el8.x86_64           sysstat-11.7.3-6.el8.x86_64                  xorg-x11-utils-7.5-28.el8.x86_64

Complete!
[root@localhost yum.repos.d]#
===



Wednesday, 8 January 2025

dbupgdiag script ---- @dbupgdiag.sql


---   @dbupgdiag.sql


-- - - - - - - - - - - - - - Script begins here - - - - - - - - - - - - - - 
--  NAME:  DBUPGDIAG.SQL  
--  Version: 1.2
--  Executed as SYS as sysdba
-- ------------------------------------------------------------------------ 
-- AUTHOR:  
--    Raja Ganesh and Agrim Pandit - Oracle Support Services - DataServer Group
--    Copyright 2008, Oracle Corporation      
-- ------------------------------------------------------------------------ 
-- PURPOSE: 
-- This script is intended to provide a user friendly output to diagonise 
-- the status of the database before (or) after upgrade. The script will 
-- create a file called db_upg_diag__.log in your local 
-- working directory. This does not make any DDL / DML modifications.
-- 
-- This script will work in both Windows and Unix platforms from database 
-- version 9.2 or higher.
-- ------------------------------------------------------------------------ 
-- DISCLAIMER: 
--    This script is provided for educational purposes only. It is NOT  
--    supported by Oracle World Wide Technical Support. 
--    The script has been tested and appears to work as intended. 
--    You should always run new scripts on a test instance initially. 
-- ------------------------------------------------------------------------ 
--
-- 
col TODAY	NEW_VALUE	_DATE	
col VERSION NEW_VALUE _VERSION
set termout off
select to_char(SYSDATE,'fmMonth DD, YYYY') TODAY from DUAL;
select version from v$instance;
set termout on
set echo off
set feedback off
set head off
set verify off
Prompt
PROMPT Enter location for Spooled output:
Prompt
DEFINE log_path = &1
column timecol new_value timestamp
column spool_extension new_value suffix
SELECT to_char(sysdate,'dd_Mon_yyyy_hhmi') timecol,'.log' spool_extension FROM 
sys.dual;
column output new_value dbname
SELECT value || '_' output FROM v$parameter WHERE name = 'db_name';
spool &log_path/db_upg_diag_&&dbname&×tamp&&suffix
set linesize 150
set pages 100
set trim on
set trims on
col Compatible for a35
col comp_id for a12
col comp_name for a40
col org_version for a11
col prv_version for a11
col owner for a12
col object_name for a40
col object_type for a40
col Wordsize for a25
col Metadata for a8
col 'Initial DB Creation Info' for a35
col 'Total Invalid JAVA objects' for a45
col 'Role' for a30
col 'User Existence' for a27
col "JAVAVM TESTING" for a15
Prompt
Prompt
set feedback off head off
select LPAD('*** Start of LogFile ***',50) from dual;
select LPAD('Oracle Database Upgrade Diagnostic Utility',44)||
       LPAD(TO_CHAR(SYSDATE, 'MM-DD-YYYY HH24:MI:SS'),26) from dual;
Prompt
Prompt ===============
Prompt Hostname
Prompt ===============
select host_name from v$instance;
Prompt
Prompt ===============
Prompt Database Name
Prompt ===============
select name from v$database;
Prompt
Prompt ===============
Prompt Database Uptime
Prompt ===============
SELECT to_char(startup_time, 'HH24:MI DD-MON-YY') "Startup Time" 
FROM v$instance;
Prompt
Prompt =================
Prompt Database Wordsize
Prompt =================
SELECT distinct('This is a ' || (length(addr)*4) || '-bit database') "WordSize" 
FROM v$process;
Prompt
Prompt ================
Prompt Software Version
Prompt ================
SELECT * FROM v$version;
Prompt
Prompt =============
Prompt Compatibility
Prompt =============
SELECT 'Compatibility is set as '||value Compatible 
FROM v$parameter WHERE name ='compatible';
Prompt
Prompt ================
Prompt Archive Log Mode
Prompt ================
Prompt
archive log list
Prompt
Prompt ================
Prompt Auditing Check
Prompt ================
Prompt
set head on
show parameter audit
Prompt
Prompt ================
Prompt Cluster Check
Prompt ================
show parameter cluster_database
Prompt
DOC
################################################################

 If CLUSTER_DATABASE is set to TRUE, change it to FALSE before
 upgrading the database 

################################################################
#
Prompt
Prompt ===========================================
Prompt Tablespace and the owner of the aud$ table  ( IF Oracle Label Security and Oracle Database Vault are installed then aud$ will be in SYSTEM.AUD$)
Prompt ===========================================
select owner,tablespace_name from dba_extents where segment_name='AUD$' group by owner,tablespace_name;
Prompt
Prompt ============================================================================
Prompt count of records in the sys.aud$ table where dbid is null- Standard Auditing
Prompt ============================================================================
Prompt
set head off
select count(*) as Records  from sys.aud$ where dbid is null;
Prompt
Prompt
Prompt ============================================================================================
Prompt count of records in the system.aud$ when dbid is null, Std Auditing with OLS or DV installed
Prompt ============================================================================================
set head off
select count(*) from system.aud$ where dbid is null;
Prompt
Prompt
Prompt =============================================================================
Prompt count of records in the sys.fga_log$ when dbid is null, Fine Grained Auditing
Prompt =============================================================================
set head off
select count(*) from sys.fga_log$ where dbid is null;
Prompt
Prompt
prompt
Prompt ==========================================
Prompt Oracle Label Security is installed or not 
Prompt ==========================================
set head off
SELECT case count(schema)
WHEN 0 THEN 'Oracle Label Security is NOT installed at database level'
ELSE 'Oracle Label Security is installed '
END  "Oracle Label Security Check"
FROM dba_registry
WHERE schema='LBACSYS';
Prompt
Prompt ================
Prompt Number of AQ Records in Message Queue Tables
Prompt ================
Prompt
SET SERVEROUTPUT ON SIZE 100000
declare
   V_COUNT NUMBER;
     cursor c1 is
         select owner,queue_table from dba_queue_tables where owner in ('SYS', 'SYSTEM', 'SYSMAN', 'DBSNMP','WMSYS');
 begin
    for c in c1
     loop
        execute immediate 'select count(1) from ' || c.owner || '.'  || c.queue_table into v_count;
        dbms_output.put_line(c.owner || ' - ' || c.queue_table  || ' - ' || v_count);
     end loop;
 END;
/
Prompt
Prompt ================
Prompt Time Zone version 
Prompt ================
Prompt
SELECT version from v$timezone_file;
Prompt
Prompt ================
Prompt Local Listener
Prompt ================
Prompt
select substr(value,1,50) "Local Listener" from v$parameter where name='local_listener';
Prompt
Prompt ================
Prompt Default and Temporary Tablespaces By User
Prompt ================
Prompt
set head on
COLUMN USERNAME FORMAT A28
COLUMN TEMPORARY_TABLESPACE FORMAT A22
COLUMN DEFAULT_TABLESPACE FORMAT A22
SELECT username, temporary_tablespace,default_tablespace FROM DBA_USERS;
Prompt
Prompt
Prompt ================
Prompt Component Status
Prompt ================
Prompt
SET SERVEROUTPUT ON;
DECLARE

ORG_VERSION varchar2(12);
PRV_VERSION varchar2(12);
P_VERSION VARCHAR2(10);

BEGIN 

SELECT version INTO p_version 
FROM registry$ WHERE cid='CATPROC' ;

IF SUBSTR(p_version,1,5) = '9.2.0' THEN

DBMS_OUTPUT.PUT_LINE(RPAD('Comp ID', 8) ||RPAD('Component',35)|| 
   RPAD('Status',10) ||RPAD('Version', 15));

DBMS_OUTPUT.PUT_LINE(RPAD(' ',8,'-') ||RPAD(' ',35,'-')|| 
   RPAD(' ',10,'-') ||RPAD(' ',15,'-'));

FOR x in (SELECT SUBSTR(dr.comp_id,1,8) comp_id,
 SUBSTR(dr.comp_name,1,35) comp_name, 
 dr.status Status,SUBSTR(dr.version,1,15) version
 FROM dba_registry dr,registry$ r
 WHERE dr.comp_id=r.cid and dr.comp_name=r.cname
 ORDER BY 1)

LOOP

DBMS_OUTPUT.PUT_LINE(RPAD(SUBSTR(x.comp_id,1,8),8) || 
   RPAD(SUBSTR(x.comp_name,1,35),35)||
   RPAD(x.status,10) || RPAD(x.version, 15));
END LOOP;

ELSIF SUBSTR(p_version,1,5) != '9.2.0' THEN

DBMS_OUTPUT.PUT_LINE(RPAD('Comp ID', 8) ||RPAD('Component',35)||  
   RPAD('Status',10) ||RPAD('Version', 15)||
   RPAD('Org_Version',15)||RPAD('Prv_Version',15));

DBMS_OUTPUT.PUT_LINE(RPAD(' ',8,'-') ||RPAD(' ',35,'-')|| 
   RPAD(' ',10,'-')||RPAD(' ',15,'-')||RPAD(' ',15,'-')||
   RPAD(' ',15,'-'));

FOR y in (SELECT SUBSTR(dr.comp_id,1,8) comp_id,
 SUBSTR(dr.comp_name,1,35) comp_name, dr.status Status, 
 SUBSTR(dr.version,1,11) version,org_version,prv_version
 FROM dba_registry dr,registry$ r
 WHERE dr.comp_id=r.cid and dr.comp_name=r.cname
 ORDER BY 1)

LOOP

DBMS_OUTPUT.PUT_LINE(RPAD(substr(y.comp_id,1,8), 8) || 
    RPAD(substr(y.comp_name,1,35),35)||RPAD(y.status,10) ||
    RPAD(y.version, 15)||RPAD(y.org_version,15)||RPAD(y.prv_version,15));

END LOOP;

END IF;
END;
/
SET SERVEROUTPUT OFF
Prompt
Prompt
Prompt
Prompt ======================================================
Prompt List of Invalid Database Objects Owned by SYS / SYSTEM
Prompt ======================================================
Prompt
set head on
SELECT case count(object_name)
WHEN 0 THEN 'There are no Invalid Objects'
ELSE 'There are '||count(object_name)||' Invalid objects'
END "Number of Invalid Objects"
FROM dba_objects 
WHERE status='INVALID'
AND owner in ('SYS','SYSTEM');
Prompt
DOC 
################################################################

 If there are no Invalid objects below will result in zero rows.

################################################################
#
Prompt
set feedback on
SELECT owner,object_name,object_type 
FROM dba_objects 
WHERE status='INVALID' 
AND owner in ('SYS','SYSTEM')
ORDER BY owner,object_type;
set feedback off
Prompt
Prompt ================================
Prompt List of Invalid Database Objects
Prompt ================================
Prompt
set head on
SELECT case count(object_name)
WHEN 0 THEN 'There are no Invalid Objects'
ELSE 'There are '||count(object_name)||' Invalid objects'
END "Number of Invalid Objects"
FROM dba_objects 
WHERE status='INVALID'
AND owner  in 
('SYSMAN','CTXSYS','ORDSYS','MDSYS','EXFSYS','WKSYS','WKPROXY','WK_TEST','OLAPSYS','OUTLIN','TSMSYS',
'FLOWS_FILES','SI_INFORMTN_SCHEMA','ORACLE_OCM','ORDPLUGINS','ORDDATA','DBSNMP');
Prompt
DOC
################################################################

 If there are no Invalid objects below will result in zero rows.

################################################################
#
Prompt
set feedback on
SELECT owner,object_name,object_type 
FROM dba_objects 
WHERE status='INVALID' 
AND owner in ('SYSMAN','CTXSYS','ORDSYS','MDSYS','EXFSYS','WKSYS','WKPROXY','WK_TEST','OLAPSYS','OUTLIN','TSMSYS',
'FLOWS_FILES','SI_INFORMTN_SCHEMA','ORACLE_OCM','ORDPLUGINS','ORDDATA','DBSNMP')
ORDER BY owner,object_type;
set feedback off
Prompt
Prompt ======================================================
Prompt Count of Invalids by Schema
Prompt ======================================================
Prompt
select owner,object_type,count(*) from dba_objects where status='INVALID'
group by owner,object_type order by owner,object_type ;
Prompt ==============================================================
Prompt Identifying whether a database was created as 32-bit or 64-bit
Prompt ==============================================================
Prompt
DOC 
###########################################################################

 Result referencing the string 'B023' ==> Database was created as 32-bit
 Result referencing the string 'B047' ==> Database was created as 64-bit
 When String results in 'B023' and when upgrading database to 10.2.0.3.0 
 (64-bit) , For known issue refer below articles
  
 Note 412271.1 ORA-600 [22635] and ORA-600 [KOKEIIX1] Reported While 
               Upgrading Or Patching Databases To 10.2.0.3
 Note 579523.1 ORA-600 [22635], ORA-600 [KOKEIIX1], ORA-7445 [KOPESIZ] and 
              OCI-21500 [KOXSIHREAD1] Reported While Upgrading To 11.1.0.6

###########################################################################
#
Prompt
SELECT SUBSTR(metadata,109,4) "Metadata",
CASE SUBSTR(metadata,109,4)
WHEN 'B023' THEN 'Database was created as 32-bit'
WHEN 'B047' THEN 'Database was created as 64-bit'
ELSE 'Metadata not Matching'
END "Initial DB Creation Info"
FROM sys.kopm$;
Prompt
Prompt ===================================================
Prompt Number of Duplicate Objects Owned by SYS and SYSTEM
Prompt ===================================================
Prompt
Prompt Counting duplicate objects ....
Prompt
SELECT count(1) 
FROM dba_objects 
WHERE object_name||object_type in 
   (SELECT object_name||object_type  
    from dba_objects 
    where owner = 'SYS')
AND owner = 'SYSTEM'
AND object_name NOT in ('AQ$_SCHEDULES','AQ$_SCHEDULES_PRIMARY','DBMS_REPCAT_AUTH','DBMS_REPCAT_AUTH') ;
Prompt
Prompt =========================================
Prompt Duplicate Objects Owned by SYS and SYSTEM
Prompt =========================================
Prompt
Prompt Querying duplicate objects ....
Prompt
SELECT object_name, object_type, subobject_name, object_id 
FROM dba_objects 
WHERE object_name||object_type in 
   (SELECT object_name||object_type  
    FROM dba_objects 
    WHERE owner = 'SYS')
AND owner = 'SYSTEM'
AND object_name NOT in ('AQ$_SCHEDULES','AQ$_SCHEDULES_PRIMARY','DBMS_REPCAT_AUTH','DBMS_REPCAT_AUTH') ; 
Prompt
DOC

################################################################################
Below are expected and required duplicates objects and OMITTED in the report .

Without replication installed:
INDEX           AQ$_SCHEDULES_PRIMARY
TABLE           AQ$_SCHEDULES

If replication is installed by running catrep.sql:
INDEX           AQ$_SCHEDULES_PRIMARY
PACKAGE         DBMS_REPCAT_AUTH
PACKAGE BODY    DBMS_REPCAT_AUTH
TABLE           AQ$_SCHEDULES

If any objects found please follow below article.
Note 1030426.6 How to Clean Up Duplicate Objects Owned by SYS and SYSTEM schema
Read the Exceptions carefully before taking actions.

################################################################################
#
Prompt
Prompt ========================
Prompt Password protected roles
Prompt ========================
Prompt
DOC

################################################################################

 In version 11.2 password protected roles are no longer enabled by default so if 
 an application relies on such roles being enabled by default and no action is
 performed to allow the user to enter the password with the set role command, it 
 is recommended to remove the password from those roles (to allow for existing 
 privileges to remain available). For more information see:

 Note 745407.1 : What Roles Can Be Set as Default for a User?

################################################################################
#
Prompt
Prompt Querying for password protected roles ....
Prompt
break on "Password protected Role"
select r.ROLE "Password protected Role",
p.grantee "Assigned by default to user"
from dba_roles r, dba_role_privs p
where r.PASSWORD_REQUIRED = 'YES' and p.GRANTED_ROLE = r.role
and p.default_role = 'YES'
and p.grantee <> 'SYS' and r.role not in
(select role from dba_application_roles);

Prompt
Prompt ================
Prompt JVM Verification
Prompt ================
Prompt
SET SERVEROUTPUT ON
DECLARE

V_CT NUMBER;
P_VERSION VARCHAR2(10);

BEGIN

-- If so, get the version of the JAVAM component
EXECUTE IMMEDIATE 'SELECT version FROM registry$ WHERE cid=''JAVAVM'' 
		   AND status <> 99' INTO p_version;

SELECT count(*) INTO v_ct FROM dba_objects
WHERE object_type LIKE '%JAVA%' AND owner='SYS';

IF SUBSTR(p_version,1,5) = '8.1.7' THEN
	IF v_ct>=6787 THEN
	DBMS_OUTPUT.PUT_LINE('JAVAVM - Installed properly');
	ELSE
	DBMS_OUTPUT.PUT_LINE('JAVAVM - Not Installed properly');
	END IF;
ELSIF SUBSTR(p_version,1,5) = '9.0.1' THEN
	IF v_ct>=8585 THEN
	DBMS_OUTPUT.PUT_LINE('JAVAVM - Installed properly');
	ELSE
	DBMS_OUTPUT.PUT_LINE('JAVAVM - Not Installed properly');
	END IF;
ELSIF SUBSTR(p_version,1,5) = '9.2.0' THEN
	IF v_ct>=8585 THEN
	DBMS_OUTPUT.PUT_LINE('JAVAVM - Installed properly');
	ELSE
	DBMS_OUTPUT.PUT_LINE('JAVAVM - Not Installed properly');
	END IF;
ELSIF SUBSTR(p_version,1,6) = '10.1.0' THEN
	IF v_ct>=13866 THEN
	DBMS_OUTPUT.PUT_LINE('JAVAVM - Installed properly');
	ELSE
	DBMS_OUTPUT.PUT_LINE('JAVAVM - Not Installed properly');
	END IF;
ELSIF SUBSTR(p_version,1,6) = '10.2.0' THEN
	IF v_ct>=14113 THEN
	DBMS_OUTPUT.PUT_LINE('JAVAVM - Installed properly');
	ELSE
	DBMS_OUTPUT.PUT_LINE('JAVAVM - Not Installed properly');
	END IF;
END IF;

EXCEPTION WHEN NO_DATA_FOUND THEN
	DBMS_OUTPUT.PUT_LINE('JAVAVM - NOT Installed. Below results can be ignored');

END;
/
SET SERVEROUTPUT OFF
Prompt
Prompt ================================================
Prompt Checking Existence of Java-Based Users and Roles
Prompt ================================================
Prompt
DOC

################################################################################

 There should not be any Java Based users for database version 9.0.1 and above.
 If any users found, it is faulty JVM.

################################################################################
#

Prompt
SELECT CASE count(username)
WHEN 0 THEN 'No Java Based Users'
ELSE 'There are '||count(*)||' JAVA based users'
END "User Existence"
FROM dba_users WHERE username LIKE '%AURORA%' AND username LIKE '%OSE%';
Prompt
DOC

###############################################################

 Healthy JVM Should contain Six Roles. For 12.2 Seven Roles 
 If there are more or less than six role, JVM is inconsistent.

###############################################################
#

Prompt
SELECT CASE count(role)
WHEN 0 THEN 'No JAVA related Roles'
ELSE 'There are '||count(role)||' JAVA related roles'
END "Role"
FROM dba_roles 
WHERE role LIKE '%JAVA%';
Prompt
Prompt Roles
Prompt
SELECT role FROM dba_roles WHERE role LIKE '%JAVA%';
set head off
Prompt
Prompt =========================================
Prompt List of Invalid Java Objects owned by SYS
Prompt =========================================
SELECT CASE count(*) 
       WHEN 0 THEN 'There are no SYS owned invalid JAVA objects'
       ELSE 'There are '||count(*)||' SYS owned invalid JAVA objects'
       END "Total Invalid JAVA objects"
FROM dba_objects 
WHERE object_type LIKE '%JAVA%' 
AND status='INVALID' 
AND owner='SYS';
Prompt
DOC

#################################################################

 Check the status of the main JVM interface packages DBMS_JAVA 
 and INITJVMAUX and make sure it is VALID.

 If there are no Invalid objects below will result in zero rows.

#################################################################
#
Prompt
set feedback on
SELECT owner,object_name,object_type
FROM dba_objects 
WHERE object_type LIKE '%JAVA%' 
AND status='INVALID' 
AND owner='SYS';
set feedback off
Prompt
DOC

#################################################################

 If the JAVAVM component is not installed in the database (for 
 example, after creating the database with custom scripts), the 
 next query will report the following error:

   select dbms_java.longname('foo') "JAVAVM TESTING" from dual
   *
   ERROR at line 1:
   ORA-00904: "DBMS_JAVA"."LONGNAME": invalid identifier

 If the JAVAVM component is installed, the query should succeed 
 with 'foo' as result.

#################################################################
#
Prompt
set heading on
select dbms_java.longname('foo') "JAVAVM TESTING" from dual;
set heading off
Prompt 
SET FEEDBACK ON HEAD ON serveroutput on
Prompt ===================================
Prompt Oracle Multimedia/InterMedia status
Prompt ===================================
Prompt

DECLARE
   v_count            NUMBER;
   v_version          varchar2(200);
   v_user_count       number;
   v_status           VARCHAR2(200);
   v_xdb_installed    NUMBER;
   v_xdk_installed    NUMBER;
   v_javavm_installed NUMBER;
   TYPE string_tt IS TABLE OF VARCHAR2 (100)
      INDEX BY BINARY_INTEGER;
   v_user             string_tt;

 BEGIN

 v_count            := 0;
 v_version          := '';
 v_user_count       := 0;
 v_status           := '';
 v_xdb_installed    := 0;
 v_xdk_installed    := 0;
 v_javavm_installed := 0;

 SELECT 1,version,status
 INTO   v_count, v_version, v_status
 FROM dba_registry
 WHERE comp_id='ORDIM';
 
                                                       
 IF v_count > 0 then
  DBMS_OUTPUT.PUT_LINE ('.');
  DBMS_OUTPUT.PUT_LINE ('Oracle Multimedia/interMedia is installed and listed with the following version: '||v_version||' and status: '||v_status);
  DBMS_OUTPUT.PUT_LINE ('.');

/* check if all users are installed.*/

 v_user(1) := 'ORDSYS';
 v_user(2) := 'ORDPLUGINS';
 v_user(3) := 'MDSYS';
 v_user(4) := 'SI_INFORMTN_SCHEMA';
 v_user(5) := 'ORDDATA';

 DBMS_OUTPUT.PUT_LINE('Checking for installed Database Schemas...');

   FOR i IN v_user.first .. v_user.last LOOP
   SELECT COUNT(username)
   INTO   v_user_count
   FROM   dba_users 
   WHERE  username = v_user(I);

/* ORDDATA user only exists starting 11.2 so no test if v_version is different */

   IF v_user(i) = 'ORDDATA' AND SUBSTR(V_VERSION,1,6) NOT IN ('11.2.0','12.1.0') THEN v_user_count :=2; 
   END IF;

/* SI_INFORMTN_SCHEMA user only exists starting 11.2 so no test if v_version is different */

   IF v_user(i) = 'SI_INFORMTN_SCHEMA' AND SUBSTR(V_VERSION,1,2) NOT IN ('10','11','12') THEN v_user_count :=2; 
   END IF; 

   CASE v_user_count
   WHEN 0 THEN  DBMS_OUTPUT.PUT_LINE (v_user(I)||' user does not exist.');
   WHEN 2 THEN NULL; -- user does not exist in that version
   ELSE DBMS_OUTPUT.PUT_LINE (v_user(I)||' user exists.');
   END CASE;
   END LOOP;

 DBMS_OUTPUT.PUT_LINE('.');

/* Prerequisites Check*/
       DBMS_OUTPUT.PUT_LINE ('Checking for Prerequisite Components...');
       
/* for versions >= 10.2 we will verify, if XDB and XDK are installed and valid */

 SELECT COUNT(1) 
 INTO   v_javavm_installed
 FROM   dba_registry
 WHERE  comp_id='JAVAVM';

 IF v_javavm_installed <> 1 THEN DBMS_OUTPUT.PUT_LINE ('JAVAVM is not installed or not valid'); 
 ELSE
      DBMS_OUTPUT.PUT_LINE('JAVAVM installed and listed as valid');
 END IF;
  
  IF  SUBSTR(V_VERSION,1,2) IN ('11','12') OR 
      SUBSTR(V_VERSION,1,6) = ('10.2.0')      THEN
             
      SELECT COUNT(1) 
      INTO   v_xdk_installed
      FROM   dba_registry
      WHERE  comp_id='XML';

      IF v_xdk_installed <> 1 THEN DBMS_OUTPUT.PUT_LINE ('XDK is not installed or not valid');
      ELSE
        DBMS_OUTPUT.PUT_LINE('XDK installed and listed as valid'); 
      END IF;
                   
      SELECT COUNT(1) 
      INTO   v_xdb_installed
      FROM   dba_registry
      WHERE  comp_id='XDB';
             
      IF v_xdb_installed <> 1 THEN DBMS_OUTPUT.PUT_LINE ('XDB is not installed or not valid');
      ELSE
        DBMS_OUTPUT.PUT_LINE ('XDB installed and listed as valid'); 
      END IF;

  END IF;               
                       
 /* for versions >= 11 we run validate_ordim */

    DBMS_OUTPUT.PUT_LINE ('Validating Oracle Multimedia/interMedia...(no output if component status is valid)'); 

    IF SUBSTR(V_VERSION,1,2) IN ('11','12') THEN
         EXECUTE IMMEDIATE 'begin validate_ordim; end;';
    ELSIF SUBSTR(V_VERSION,1,2) IN ('8.','9.','10') AND  v_status <> 'VALID' THEN
         DBMS_OUTPUT.PUT_LINE('Please run $ORACLE_HOME/ord/im/admin/imchk.sql to display details about invalid interMedia installation');
    END IF;
    
 END IF;

 EXCEPTION
   WHEN NO_DATA_FOUND THEN 
   DBMS_OUTPUT.PUT_LINE ('Oracle Multimedia/interMedia is NOT installed at database level');
 END;
/

set feedback off head off
select LPAD('*** End of LogFile ***',50) from dual;
set feedback on head on
Prompt
spool off
Prompt
set heading off
set heading off
set feedback off
select 'Upload db_upg_diag_&&dbname&×tamp&&suffix from "&log_path" directory' 
from dual;
set heading on
set feedback on
Prompt
-- - - - - - - - - - - - - - - - Script ends here - - - - - - - - - - - - - - 







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


SQL> @dbupgdiag.sql


                          *** Start of LogFile ***

  Oracle Database Upgrade Diagnostic Utility       01-08-2025 06:26:44

===============
Hostname
===============

rac01.int.XXXXXXXX

===============
Database Name
===============

UGARYD

===============
Database Uptime
===============

02:36 07-JAN-25

=================
Database Wordsize
=================

This is a 64-bit database

================
Software Version
================

Oracle Database 12c Standard Edition Release 12.1.0.2.0 - 64bit Production                0
PL/SQL Release 12.1.0.2.0 - Production                                                    0
CORE    12.1.0.2.0      Production                                                                0
TNS for Linux: Version 12.1.0.2.0 - Production                                            0
NLSRTL Version 12.1.0.2.0 - Production                                                    0

=============
Compatibility
=============

Compatibility is set as 12.1.0.2.0

================
Archive Log Mode
================

Database log mode              Archive Mode
Automatic archival             Enabled
Archive destination            USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence     219
Next log sequence to archive   221
Current log sequence           221

================
Auditing Check
================


NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
audit_file_dest                      string      /u01/app/oracle/admin/ugaryd/a
                                                 dump
audit_sys_operations                 boolean     TRUE
audit_syslog_level                   string
audit_trail                          string      DB
unified_audit_sga_queue_size         integer     1048576

================
Cluster Check
================

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
cluster_database                     boolean     TRUE
cluster_database_instances           integer     2

DOC>################################################################
DOC>
DOC> If CLUSTER_DATABASE is set to TRUE, change it to FALSE before
DOC> upgrading the database
DOC>
DOC>################################################################
DOC>#

===========================================
Tablespace and the owner of the aud$ table  ( IF Oracle Label Security and Oracle Database Vault are installed then aud$ will be in SYSTEM.AUD$)
===========================================

OWNER        TABLESPACE_NAME
------------ ------------------------------
SYS          SYSTEM

============================================================================
count of records in the sys.aud$ table where dbid is null- Standard Auditing
============================================================================


         0


============================================================================================
count of records in the system.aud$ when dbid is null, Std Auditing with OLS or DV installed
============================================================================================
select count(*) from system.aud$ where dbid is null
                            *
ERROR at line 1:
ORA-00942: table or view does not exist




=============================================================================
count of records in the sys.fga_log$ when dbid is null, Fine Grained Auditing
=============================================================================

         0



==========================================
Oracle Label Security is installed or not
==========================================

Oracle Label Security is NOT installed at database level

================
Number of AQ Records in Message Queue Tables
================

SYS - ALERT_QT - 0
SYS - AQ$_MEM_MC - 0
SYS - AQ_EVENT_TABLE - 0
SYS - AQ_PROP_TABLE - 0
SYS - KUPC$DATAPUMP_QUETAB - 0
SYS - SCHEDULER$_EVENT_QTAB - 0
SYS - SCHEDULER$_REMDB_JOBQTAB - 0
SYS - SCHEDULER_FILEWATCHER_QT - 0
SYS - SYS$SERVICE_METRICS_TAB - 0
SYSTEM - DEF$_AQCALL - 0
SYSTEM - DEF$_AQERROR - 0

================
Time Zone version
================


        18

================
Local Listener
================


(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)

================
Default and Temporary Tablespaces By User
================


USERNAME                     TEMPORARY_TABLESPACE   DEFAULT_TABLESPACE
---------------------------- ---------------------- ----------------------
ANONYMOUS                    TEMP                   SYSAUX
DBSNMP                       TEMP                   SYSAUX
XDB                          TEMP                   SYSAUX
APPQOSSYS                    TEMP                   SYSAUX
GSMADMIN_INTERNAL            TEMP                   SYSAUX
GSMCATUSER                   TEMP                   SYSTEM
SYSBACKUP                    TEMP                   SYSTEM
OUTLN                        TEMP                   SYSTEM
DIP                          TEMP                   SYSTEM
SYSDG                        TEMP                   SYSTEM
ORACLE_OCM                   TEMP                   SYSTEM
SYSKM                        TEMP                   SYSTEM
XS$NULL                      TEMP                   SYSTEM
GSMUSER                      TEMP                   SYSTEM
AUDSYS                       TEMP                   SYSTEM
SYSTEM                       TEMP                   SYSTEM
SYS                          TEMP                   SYSTEM


================
Component Status
================

Comp ID Component                          Status    Version        Org_Version    Prv_Version
------- ---------------------------------- --------- -------------- -------------- --------------
CATALOG Oracle Database Catalog Views      VALID     12.1.0.2.0
CATPROC Oracle Database Packages and Types VALID     12.1.0.2.0
RAC     Oracle Real Application Clusters   VALID     12.1.0.2.0
XDB     Oracle XML Database                VALID     12.1.0.2.0



======================================================
List of Invalid Database Objects Owned by SYS / SYSTEM
======================================================


Number of Invalid Objects
------------------------------------------------------------------
There are no Invalid Objects

DOC>################################################################
DOC>
DOC> If there are no Invalid objects below will result in zero rows.
DOC>
DOC>################################################################
DOC>#


no rows selected


================================
List of Invalid Database Objects
================================


Number of Invalid Objects
------------------------------------------------------------------
There are no Invalid Objects

DOC>################################################################
DOC>
DOC> If there are no Invalid objects below will result in zero rows.
DOC>
DOC>################################################################
DOC>#


no rows selected


======================================================
Count of Invalids by Schema
======================================================

==============================================================
Identifying whether a database was created as 32-bit or 64-bit
==============================================================

DOC>###########################################################################
DOC>
DOC> Result referencing the string 'B023' ==> Database was created as 32-bit
DOC> Result referencing the string 'B047' ==> Database was created as 64-bit
DOC> When String results in 'B023' and when upgrading database to 10.2.0.3.0
DOC> (64-bit) , For known issue refer below articles
DOC>
DOC> Note 412271.1 ORA-600 [22635] and ORA-600 [KOKEIIX1] Reported While
DOC>               Upgrading Or Patching Databases To 10.2.0.3
DOC> Note 579523.1 ORA-600 [22635], ORA-600 [KOKEIIX1], ORA-7445 [KOPESIZ] and
DOC>              OCI-21500 [KOXSIHREAD1] Reported While Upgrading To 11.1.0.6
DOC>
DOC>###########################################################################
DOC>#


Metadata Initial DB Creation Info
-------- -----------------------------------
B047     Database was created as 64-bit

===================================================
Number of Duplicate Objects Owned by SYS and SYSTEM
===================================================

Counting duplicate objects ....


  COUNT(1)
----------
         0

=========================================
Duplicate Objects Owned by SYS and SYSTEM
=========================================

Querying duplicate objects ....


DOC>
DOC>################################################################################
DOC>Below are expected and required duplicates objects and OMITTED in the report .
DOC>
DOC>Without replication installed:
DOC>INDEX           AQ$_SCHEDULES_PRIMARY
DOC>TABLE           AQ$_SCHEDULES
DOC>
DOC>If replication is installed by running catrep.sql:
DOC>INDEX           AQ$_SCHEDULES_PRIMARY
DOC>PACKAGE         DBMS_REPCAT_AUTH
DOC>PACKAGE BODY        DBMS_REPCAT_AUTH
DOC>TABLE           AQ$_SCHEDULES
DOC>
DOC>If any objects found please follow below article.
DOC>Note 1030426.6 How to Clean Up Duplicate Objects Owned by SYS and SYSTEM schema
DOC>Read the Exceptions carefully before taking actions.
DOC>
DOC>################################################################################
DOC>#

========================
Password protected roles
========================

DOC>
DOC>################################################################################
DOC>
DOC> In version 11.2 password protected roles are no longer enabled by default so if
DOC> an application relies on such roles being enabled by default and no action is
DOC> performed to allow the user to enter the password with the set role command, it
DOC> is recommended to remove the password from those roles (to allow for existing
DOC> privileges to remain available). For more information see:
DOC>
DOC> Note 745407.1 : What Roles Can Be Set as Default for a User?
DOC>
DOC>################################################################################
DOC>#

Querying for password protected roles ....


================
JVM Verification
================

JAVAVM - NOT Installed. Below results can be ignored

================================================
Checking Existence of Java-Based Users and Roles
================================================

DOC>
DOC>################################################################################
DOC>
DOC> There should not be any Java Based users for database version 9.0.1 and above.
DOC> If any users found, it is faulty JVM.
DOC>
DOC>################################################################################
DOC>#


User Existence
---------------------------
No Java Based Users

DOC>
DOC>###############################################################
DOC>
DOC> Healthy JVM Should contain Six Roles. For 12.2 Seven Roles
DOC> If there are more or less than six role, JVM is inconsistent.
DOC>
DOC>###############################################################
DOC>#


Role
------------------------------
No JAVA related Roles

Roles


=========================================
List of Invalid Java Objects owned by SYS
=========================================

There are no SYS owned invalid JAVA objects

DOC>
DOC>#################################################################
DOC>
DOC> Check the status of the main JVM interface packages DBMS_JAVA
DOC> and INITJVMAUX and make sure it is VALID.
DOC>
DOC> If there are no Invalid objects below will result in zero rows.
DOC>
DOC>#################################################################
DOC>#


no rows selected


DOC>
DOC>#################################################################
DOC>
DOC> If the JAVAVM component is not installed in the database (for
DOC> example, after creating the database with custom scripts), the
DOC> next query will report the following error:
DOC>
DOC>   select dbms_java.longname('foo') "JAVAVM TESTING" from dual
DOC>   *
DOC>   ERROR at line 1:
DOC>   ORA-00904: "DBMS_JAVA"."LONGNAME": invalid identifier
DOC>
DOC> If the JAVAVM component is installed, the query should succeed
DOC> with 'foo' as result.
DOC>
DOC>#################################################################
DOC>#

select dbms_java.longname('foo') "JAVAVM TESTING" from dual
       *
ERROR at line 1:
ORA-00904: "DBMS_JAVA"."LONGNAME": invalid identifier



===================================
Oracle Multimedia/InterMedia status
===================================

Oracle Multimedia/interMedia is NOT installed at database level

PL/SQL procedure successfully completed.


                            *** End of LogFile ***

not spooling currently

Enter value for log_path:

Upload db_upg_diag_UGARYD_08_Jan_2025_0626.log from "" directory

ANALYZE PARTITION TABLE VALIDATE STRUCTURE CASCADE

ANALYZE PARTITION TABLE VALIDATE STRUCTURE CASCADE Script




	ORA-14508: ANALYZE PARTITION TABLE VALIDATE STRUCTURE CASCADE (Doc ID 111990.1)
    
    

 set linesize 300 pagesize 300
 col xx for a100
 select 'Prompt '||TABLE_OWNER||'.'||TABLE_NAME||'.'||PARTITION_NAME dba_TAB_PARTITIONS  FROM dba_TAB_PARTITIONS WHERE TABLE_NAME ='XXXX';
 
 
 set pagesize 0 
 -- spool p.sql 
 select 'Prompt '||TABLE_OWNER||'.'||TABLE_NAME||'.'||PARTITION_NAME  || chr(10) ||'analyze table ' ||TABLE_OWNER||'.'||TABLE_NAME || ' partition (' ||PARTITION_NAME ||') validate structure cascade online into invalid_rows;'  || chr(10) || ' select count(*) from invalid_rows ;'
 FROM dba_TAB_PARTITIONS 
 WHERE TABLE_NAME ='XXX';
 
 -- spool off 
 
 

Friday, 3 January 2025

coe_xfr_sql_profile.sql example


  
 
 [oracle@localhost ~]$ sqlplus system/system@//localhost:1521/free
 
  
  
  *****************************************************************************************************************
  ---  coe_xfr_sql_profile.sql
  
  ---  coe_xfr_sql_profile.sql dg8duxp7zprxp PLAN_HASH_VALUE
  
    SQL> START coe_xfr_sql_profile.sql [SQL_ID] [PLAN_HASH_VALUE];
  
  
  -- Transfer (copy) a SQL Profile from PDBx on CDBa into PDBy on CDBb
SPO coe_xfr_sql_profile.log;
SET DEF ON TERM OFF ECHO ON FEED OFF VER OFF HEA ON LIN 2000 PAGES 100 LONG 8000000 LONGC 800000 TRIMS ON TI OFF TIMI OFF SERVEROUT ON SIZE 1000000 NUMF "" SQLP SQL>;
SET SERVEROUT ON SIZE UNL;
REM
REM $Header: coe_xfr_sql_profile.sql 2020/03/10 carlos.sierra $
REM
REM AUTHOR
REM   Carlos Sierra
REM
REM SCRIPT
REM   coe_xfr_sql_profile.sql
REM
REM DESCRIPTION
REM   This script generates another that contains the commands to
REM   create a manual custom SQL Profile out of a known plan from
REM   memory or AWR. The manual custom profile can be implemented
REM   into the same SOURCE system where the plan was retrieved,
REM   or into another similar TARGET system that has same schema
REM   objects referenced by the SQL that generated the known plan.
REM
REM PRE-REQUISITES
REM   1. Oracle Tuning Pack license.
REM
REM PARAMETERS
REM   1. SQL_ID (required)
REM   2. Plan Hash Value for which a manual custom SQL Profile is
REM      needed (required). A list of known plans is presented.
REM      You may choose from list provided or enter a valid phv
REM      from a version of the SQL modified with Hints.
REM
REM EXECUTION
REM   1. Connect into SQL*Plus as user with access to data dictionary.
REM      Do not use SYS.
REM   2. Execute script coe_xfr_sql_profile.sql passing SQL_ID and
REM      plan hash value (parameters can be passed inline or until
REM      requested).
REM
REM EXAMPLE
REM   # sqlplus system
REM   SQL> START coe_xfr_sql_profile.sql [SQL_ID] [PLAN_HASH_VALUE];
REM   SQL> START coe_xfr_sql_profile.sql gnjy0mn4y9pbm 2055843663;
REM   SQL> START coe_xfr_sql_profile.sql gnjy0mn4y9pbm;
REM   SQL> START coe_xfr_sql_profile.sql;
REM
REM NOTES
REM   1. For possible errors see coe_xfr_sql_profile.log
REM   2. If SQLT is installed in SOURCE, you can use instead:
REM      sqlt/utl/sqltprofile.sql
REM   3. Be aware that using DBMS_SQLTUNE requires a license for
REM      Oracle Tuning Pack.
REM   4. Use a DBA user but not SYS.
REM   5. If you get "ORA-06532: Subscript outside of limit, ORA-06512: at line 1"
REM      Then you may consider this change (only in a test and disposable system):
REM      create or replace TYPE sys.sqlprof_attr AS VARRAY(5000) of VARCHAR2(500);
REM
SET TERM ON ECHO OFF;
PRO
PRO Parameter 1:
PRO SQL_ID (required)
PRO
DEF sql_id = '&1.';
UNDEF 1;
PRO
WITH
p AS (
SELECT plan_hash_value
  FROM gv$sql_plan
 WHERE sql_id = TRIM('&&sql_id.')
   AND other_xml IS NOT NULL
 UNION
SELECT plan_hash_value
  FROM dba_hist_sql_plan
 WHERE sql_id = TRIM('&&sql_id.')
   AND dbid = (SELECT dbid FROM v$database) 
   AND other_xml IS NOT NULL ),
m AS (
SELECT plan_hash_value,
       SUM(elapsed_time)/SUM(executions) avg_et_secs,
       SUM(executions) executions
  FROM gv$sql
 WHERE sql_id = TRIM('&&sql_id.')
   AND executions > 0
 GROUP BY
       plan_hash_value ),
a AS (
SELECT plan_hash_value,
       SUM(elapsed_time_delta)/SUM(executions_delta) avg_et_secs,
       SUM(executions_delta) executions
  FROM dba_hist_sqlstat
 WHERE sql_id = TRIM('&&sql_id.')
   AND executions_delta > 0
 GROUP BY
       plan_hash_value )
SELECT 
       TO_CHAR(ROUND(m.avg_et_secs/1e6, 6), '999,990.000000') avg_et_secs_mem,
       TO_CHAR(ROUND(a.avg_et_secs/1e6, 6), '999,990.000000') avg_et_secs_awr,
       p.plan_hash_value,
       m.executions executions_mem,
       a.executions executions_awr
       --TO_CHAR(ROUND(NVL(m.avg_et_secs, a.avg_et_secs)/1e6, 6), '999,990.000000') avg_et_secs
  FROM p, m, a
 WHERE p.plan_hash_value = m.plan_hash_value(+)
   AND p.plan_hash_value = a.plan_hash_value(+)
 ORDER BY
       NVL(m.avg_et_secs, a.avg_et_secs) NULLS LAST, a.avg_et_secs;
PRO
PRO Parameter 2:
PRO PLAN_HASH_VALUE (required)
PRO
DEF plan_hash_value = '&2';
UNDEF 2;
PRO
PRO Values passed to coe_xfr_sql_profile:
PRO ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
PRO SQL_ID         : "&&sql_id."
PRO PLAN_HASH_VALUE: "&&plan_hash_value."
PRO
SET TERM OFF ECHO ON;
WHENEVER SQLERROR EXIT SQL.SQLCODE;

-- trim parameters
COL sql_id NEW_V sql_id FOR A30;
COL plan_hash_value NEW_V plan_hash_value FOR A30;
SELECT TRIM('&&sql_id.') sql_id, TRIM('&&plan_hash_value.') plan_hash_value FROM DUAL;

VAR sql_text CLOB;
VAR sql_text2 CLOB;
VAR other_xml CLOB;
EXEC :sql_text := NULL;
EXEC :sql_text2 := NULL;
EXEC :other_xml := NULL;

-- get sql_text from memory
DECLARE
  l_sql_text VARCHAR2(32767);
BEGIN -- 10g see bug 5017909
  FOR i IN (SELECT DISTINCT piece, sql_text
              FROM gv$sqltext_with_newlines
             WHERE sql_id = TRIM('&&sql_id.')
             ORDER BY 1, 2)
  LOOP
    IF :sql_text IS NULL THEN
      DBMS_LOB.CREATETEMPORARY(:sql_text, TRUE);
      DBMS_LOB.OPEN(:sql_text, DBMS_LOB.LOB_READWRITE);
    END IF;
    -- removes NUL characters
    l_sql_text := REPLACE(i.sql_text, CHR(00), ' ');
    -- adds a NUL character at the end of each line
    DBMS_LOB.WRITEAPPEND(:sql_text, LENGTH(l_sql_text) + 1, l_sql_text||CHR(00));
  END LOOP;
  -- if found in memory then sql_text is not null
  IF :sql_text IS NOT NULL THEN
    DBMS_LOB.CLOSE(:sql_text);
  END IF;
EXCEPTION
  WHEN OTHERS THEN
    DBMS_OUTPUT.PUT_LINE('getting sql_text from memory: '||SQLERRM);
    :sql_text := NULL;
END;
/

SELECT :sql_text FROM DUAL;

-- get sql_text from awr
DECLARE
  l_sql_text VARCHAR2(32767);
  l_clob_size NUMBER;
  l_offset NUMBER;
BEGIN
  IF :sql_text IS NULL OR NVL(DBMS_LOB.GETLENGTH(:sql_text), 0) = 0 THEN
    SELECT sql_text
      INTO :sql_text2
      FROM dba_hist_sqltext
     WHERE sql_id = TRIM('&&sql_id.')
       AND sql_text IS NOT NULL
       AND ROWNUM = 1;
  END IF;
  -- if found in awr then sql_text2 is not null
  IF :sql_text2 IS NOT NULL THEN
    l_clob_size := NVL(DBMS_LOB.GETLENGTH(:sql_text2), 0);
    l_offset := 1;
    DBMS_LOB.CREATETEMPORARY(:sql_text, TRUE);
    DBMS_LOB.OPEN(:sql_text, DBMS_LOB.LOB_READWRITE);
    -- store in clob as 64 character pieces plus a NUL character at the end of each piece
    WHILE l_offset < l_clob_size
    LOOP
      IF l_clob_size - l_offset > 64 THEN
        l_sql_text := REPLACE(DBMS_LOB.SUBSTR(:sql_text2, 64, l_offset), CHR(00), ' ');
      ELSE -- last piece
        l_sql_text := REPLACE(DBMS_LOB.SUBSTR(:sql_text2, l_clob_size - l_offset + 1, l_offset), CHR(00), ' ');
      END IF;
      DBMS_LOB.WRITEAPPEND(:sql_text, LENGTH(l_sql_text) + 1, l_sql_text||CHR(00));
      l_offset := l_offset + 64;
    END LOOP;
    DBMS_LOB.CLOSE(:sql_text);
  END IF;
EXCEPTION
  WHEN OTHERS THEN
    DBMS_OUTPUT.PUT_LINE('getting sql_text from awr: '||SQLERRM);
    :sql_text := NULL;
END;
/

SELECT :sql_text2 FROM DUAL;
SELECT :sql_text FROM DUAL;

-- validate sql_text
SET TERM ON;
BEGIN
  IF :sql_text IS NULL THEN
    RAISE_APPLICATION_ERROR(-20100, 'SQL_TEXT for SQL_ID &&sql_id. was not found in memory (gv$sqltext_with_newlines) or AWR (dba_hist_sqltext).');
  END IF;
END;
/
SET TERM OFF;

-- get other_xml from memory
BEGIN
  FOR i IN (SELECT other_xml
              FROM gv$sql_plan
             WHERE sql_id = TRIM('&&sql_id.')
               AND plan_hash_value = TO_NUMBER(TRIM('&&plan_hash_value.'))
               AND other_xml IS NOT NULL
             ORDER BY
                   child_number, id)
  LOOP
    :other_xml := i.other_xml;
    EXIT; -- 1st
  END LOOP;
EXCEPTION
  WHEN OTHERS THEN
    DBMS_OUTPUT.PUT_LINE('getting other_xml from memory: '||SQLERRM);
    :other_xml := NULL;
END;
/

-- get other_xml from awr
BEGIN
  IF :other_xml IS NULL OR NVL(DBMS_LOB.GETLENGTH(:other_xml), 0) = 0 THEN
    FOR i IN (SELECT other_xml
                FROM dba_hist_sql_plan
               WHERE sql_id = TRIM('&&sql_id.')
                 AND plan_hash_value = TO_NUMBER(TRIM('&&plan_hash_value.'))
                 AND dbid = (SELECT dbid FROM v$database) 
                 AND other_xml IS NOT NULL
               ORDER BY
                     id)
    LOOP
      :other_xml := i.other_xml;
      EXIT; -- 1st
    END LOOP;
  END IF;
EXCEPTION
  WHEN OTHERS THEN
    DBMS_OUTPUT.PUT_LINE('getting other_xml from awr: '||SQLERRM);
    :other_xml := NULL;
END;
/

-- get other_xml from memory from modified SQL
BEGIN
  IF :other_xml IS NULL OR NVL(DBMS_LOB.GETLENGTH(:other_xml), 0) = 0 THEN
    FOR i IN (SELECT other_xml
                FROM gv$sql_plan
               WHERE plan_hash_value = TO_NUMBER(TRIM('&&plan_hash_value.'))
               --WHERE full_plan_hash_value = TO_NUMBER(TRIM('&&plan_hash_value.'))
                 AND other_xml IS NOT NULL
               ORDER BY
                     child_number, id)
    LOOP
      :other_xml := i.other_xml;
      EXIT; -- 1st
    END LOOP;
  END IF;
EXCEPTION
  WHEN OTHERS THEN
    DBMS_OUTPUT.PUT_LINE('getting other_xml from memory: '||SQLERRM);
    :other_xml := NULL;
END;
/

-- get other_xml from awr from modified SQL
BEGIN
  IF :other_xml IS NULL OR NVL(DBMS_LOB.GETLENGTH(:other_xml), 0) = 0 THEN
    FOR i IN (SELECT other_xml
                FROM dba_hist_sql_plan
               WHERE plan_hash_value = TO_NUMBER(TRIM('&&plan_hash_value.'))
               --WHERE full_plan_hash_value = TO_NUMBER(TRIM('&&plan_hash_value.'))
                 AND dbid = (SELECT dbid FROM v$database) 
                 AND other_xml IS NOT NULL
               ORDER BY
                     id)
    LOOP
      :other_xml := i.other_xml;
      EXIT; -- 1st
    END LOOP;
  END IF;
EXCEPTION
  WHEN OTHERS THEN
    DBMS_OUTPUT.PUT_LINE('getting other_xml from awr: '||SQLERRM);
    :other_xml := NULL;
END;
/

SELECT :other_xml FROM DUAL;

-- validate other_xml
SET TERM ON;
BEGIN
  IF :other_xml IS NULL THEN
    RAISE_APPLICATION_ERROR(-20101, 'PLAN for SQL_ID &&sql_id. and PHV &&plan_hash_value. was not found in memory (gv$sql_plan) or AWR (dba_hist_sql_plan).');
  END IF;
END;
/
SET TERM OFF;

-- generates script that creates sql profile in target system:
SET ECHO OFF;
PRO coe_xfr_sql_profile_&&sql_id._&&plan_hash_value..sql.
SET FEED OFF LIN 666 TRIMS ON TI OFF TIMI OFF SERVEROUT ON SIZE 1000000 FOR WOR;
SET SERVEROUT ON SIZE UNL FOR WOR;
SPO OFF;
SPO coe_xfr_sql_profile_&&sql_id._&&plan_hash_value..sql;
DECLARE
  l_pos NUMBER;
  l_clob_size NUMBER;
  l_offset NUMBER;
  l_sql_text VARCHAR2(32767);
  l_len NUMBER;
  l_hint VARCHAR2(32767);
BEGIN
  DBMS_OUTPUT.PUT_LINE('SPO coe_xfr_sql_profile_&&sql_id._&&plan_hash_value..log;');
  DBMS_OUTPUT.PUT_LINE('SET ECHO ON TERM ON LIN 2000 TRIMS ON NUMF 99999999999999999999;');
  DBMS_OUTPUT.PUT_LINE('REM');
  DBMS_OUTPUT.PUT_LINE('REM $Header: 215187.1 coe_xfr_sql_profile_&&sql_id._&&plan_hash_value..sql 11.4.4.4 '||TO_CHAR(SYSDATE, 'YYYY/MM/DD')||' carlos.sierra $');
  DBMS_OUTPUT.PUT_LINE('REM');
  DBMS_OUTPUT.PUT_LINE('REM Copyright (c) 2000-2012, Oracle Corporation. All rights reserved.');
  DBMS_OUTPUT.PUT_LINE('REM');
  DBMS_OUTPUT.PUT_LINE('REM AUTHOR');
  DBMS_OUTPUT.PUT_LINE('REM   carlos.sierra@oracle.com');
  DBMS_OUTPUT.PUT_LINE('REM');
  DBMS_OUTPUT.PUT_LINE('REM SCRIPT');
  DBMS_OUTPUT.PUT_LINE('REM   coe_xfr_sql_profile_&&sql_id._&&plan_hash_value..sql');
  DBMS_OUTPUT.PUT_LINE('REM');
  DBMS_OUTPUT.PUT_LINE('REM DESCRIPTION');
  DBMS_OUTPUT.PUT_LINE('REM   This script is generated by coe_xfr_sql_profile.sql');
  DBMS_OUTPUT.PUT_LINE('REM   It contains the SQL*Plus commands to create a custom');
  DBMS_OUTPUT.PUT_LINE('REM   SQL Profile for SQL_ID &&sql_id. based on plan hash');
  DBMS_OUTPUT.PUT_LINE('REM   value &&plan_hash_value..');
  DBMS_OUTPUT.PUT_LINE('REM   The custom SQL Profile to be created by this script');
  DBMS_OUTPUT.PUT_LINE('REM   will affect plans for SQL commands with signature');
  DBMS_OUTPUT.PUT_LINE('REM   matching the one for SQL Text below.');
  DBMS_OUTPUT.PUT_LINE('REM   Review SQL Text and adjust accordingly.');
  DBMS_OUTPUT.PUT_LINE('REM');
  DBMS_OUTPUT.PUT_LINE('REM PARAMETERS');
  DBMS_OUTPUT.PUT_LINE('REM   None.');
  DBMS_OUTPUT.PUT_LINE('REM');
  DBMS_OUTPUT.PUT_LINE('REM EXAMPLE');
  DBMS_OUTPUT.PUT_LINE('REM   SQL> START coe_xfr_sql_profile_&&sql_id._&&plan_hash_value..sql;');
  DBMS_OUTPUT.PUT_LINE('REM');
  DBMS_OUTPUT.PUT_LINE('REM NOTES');
  DBMS_OUTPUT.PUT_LINE('REM   1. Should be run as SYSTEM or SYSDBA.');
  DBMS_OUTPUT.PUT_LINE('REM   2. User must have CREATE ANY SQL PROFILE privilege.');
  DBMS_OUTPUT.PUT_LINE('REM   3. SOURCE and TARGET systems can be the same or similar.');
  DBMS_OUTPUT.PUT_LINE('REM   4. To drop this custom SQL Profile after it has been created:');
  DBMS_OUTPUT.PUT_LINE('REM      EXEC DBMS_SQLTUNE.DROP_SQL_PROFILE(''coe_&&sql_id._&&plan_hash_value.'');');
  DBMS_OUTPUT.PUT_LINE('REM   5. Be aware that using DBMS_SQLTUNE requires a license');
  DBMS_OUTPUT.PUT_LINE('REM      for the Oracle Tuning Pack.');
  DBMS_OUTPUT.PUT_LINE('REM   6. If you modified a SQL putting Hints in order to produce a desired');
  DBMS_OUTPUT.PUT_LINE('REM      Plan, you can remove the artifical Hints from SQL Text pieces below.');
  DBMS_OUTPUT.PUT_LINE('REM      By doing so you can create a custom SQL Profile for the original');
  DBMS_OUTPUT.PUT_LINE('REM      SQL but with the Plan captured from the modified SQL (with Hints).');
  DBMS_OUTPUT.PUT_LINE('REM');
  DBMS_OUTPUT.PUT_LINE('WHENEVER SQLERROR EXIT SQL.SQLCODE;');
  DBMS_OUTPUT.PUT_LINE('REM');
  DBMS_OUTPUT.PUT_LINE('VAR signature NUMBER;');
  DBMS_OUTPUT.PUT_LINE('VAR signaturef NUMBER;');
  DBMS_OUTPUT.PUT_LINE('REM');
  DBMS_OUTPUT.PUT_LINE('DECLARE');
  DBMS_OUTPUT.PUT_LINE('sql_txt CLOB;');
  DBMS_OUTPUT.PUT_LINE('h       SYS.SQLPROF_ATTR;');
  DBMS_OUTPUT.PUT_LINE('PROCEDURE wa (p_line IN VARCHAR2) IS');
  DBMS_OUTPUT.PUT_LINE('BEGIN');
  DBMS_OUTPUT.PUT_LINE('DBMS_LOB.WRITEAPPEND(sql_txt, LENGTH(p_line), p_line);');
  DBMS_OUTPUT.PUT_LINE('END wa;');
  DBMS_OUTPUT.PUT_LINE('BEGIN');
  DBMS_OUTPUT.PUT_LINE('DBMS_LOB.CREATETEMPORARY(sql_txt, TRUE);');
  DBMS_OUTPUT.PUT_LINE('DBMS_LOB.OPEN(sql_txt, DBMS_LOB.LOB_READWRITE);');
  DBMS_OUTPUT.PUT_LINE('-- SQL Text pieces below do not have to be of same length.');
  DBMS_OUTPUT.PUT_LINE('-- So if you edit SQL Text (i.e. removing temporary Hints),');
  DBMS_OUTPUT.PUT_LINE('-- there is no need to edit or re-align unmodified pieces.');
  l_clob_size := NVL(DBMS_LOB.GETLENGTH(:sql_text), 0);
  l_offset := 1;
  WHILE l_offset < l_clob_size
  LOOP
    l_pos := DBMS_LOB.INSTR(:sql_text, CHR(00), l_offset);
    IF l_pos > 0 THEN
      l_len := l_pos - l_offset;
    ELSE -- last piece
      l_len := l_clob_size - l_pos + 1;
    END IF;
    l_sql_text := DBMS_LOB.SUBSTR(:sql_text, l_len, l_offset);
    /* cannot do such 3 replacement since a line could end with a comment using "--"
    l_sql_text := REPLACE(l_sql_text, CHR(10), ' '); -- replace LF with SP
    l_sql_text := REPLACE(l_sql_text, CHR(13), ' '); -- replace CR with SP
    l_sql_text := REPLACE(l_sql_text, CHR(09), ' '); -- replace TAB with SP
    */
    l_offset := l_offset + l_len + 1;
    IF l_len > 0 THEN
      IF INSTR(l_sql_text, '''[') + INSTR(l_sql_text, ']''') = 0 THEN
        l_sql_text := '['||l_sql_text||']';
      ELSIF INSTR(l_sql_text, '''{') + INSTR(l_sql_text, '}''') = 0 THEN
        l_sql_text := '{'||l_sql_text||'}';
      ELSIF INSTR(l_sql_text, '''<') + INSTR(l_sql_text, '>''') = 0 THEN
        l_sql_text := '<'||l_sql_text||'>';
      ELSIF INSTR(l_sql_text, '''(') + INSTR(l_sql_text, ')''') = 0 THEN
        l_sql_text := '('||l_sql_text||')';
      ELSIF INSTR(l_sql_text, '''"') + INSTR(l_sql_text, '"''') = 0 THEN
        l_sql_text := '"'||l_sql_text||'"';
      ELSIF INSTR(l_sql_text, '''|') + INSTR(l_sql_text, '|''') = 0 THEN
        l_sql_text := '|'||l_sql_text||'|';
      ELSIF INSTR(l_sql_text, '''~') + INSTR(l_sql_text, '~''') = 0 THEN
        l_sql_text := '~'||l_sql_text||'~';
      ELSIF INSTR(l_sql_text, '''^') + INSTR(l_sql_text, '^''') = 0 THEN
        l_sql_text := '^'||l_sql_text||'^';
      ELSIF INSTR(l_sql_text, '''@') + INSTR(l_sql_text, '@''') = 0 THEN
        l_sql_text := '@'||l_sql_text||'@';
      ELSIF INSTR(l_sql_text, '''#') + INSTR(l_sql_text, '#''') = 0 THEN
        l_sql_text := '#'||l_sql_text||'#';
      ELSIF INSTR(l_sql_text, '''%') + INSTR(l_sql_text, '%''') = 0 THEN
        l_sql_text := '%'||l_sql_text||'%';
      ELSIF INSTR(l_sql_text, '''$') + INSTR(l_sql_text, '$''') = 0 THEN
        l_sql_text := '$'||l_sql_text||'$';
      ELSE
        l_sql_text := CHR(96)||l_sql_text||CHR(96);
      END IF;
      DBMS_OUTPUT.PUT_LINE('wa(q'''||l_sql_text||''');');
    END IF;
  END LOOP;
  DBMS_OUTPUT.PUT_LINE('DBMS_LOB.CLOSE(sql_txt);');
  DBMS_OUTPUT.PUT_LINE('h := SYS.SQLPROF_ATTR(');
  DBMS_OUTPUT.PUT_LINE('q''[BEGIN_OUTLINE_DATA]'',');
  FOR i IN (SELECT /*+ opt_param('parallel_execution_enabled', 'false') */
                   SUBSTR(EXTRACTVALUE(VALUE(d), '/hint'), 1, 4000) hint
              FROM TABLE(XMLSEQUENCE(EXTRACT(XMLTYPE(:other_xml), '/*/outline_data/hint'))) d)
  LOOP
    l_hint := i.hint;
    WHILE NVL(LENGTH(l_hint), 0) > 0
    LOOP
      IF LENGTH(l_hint) <= 500 THEN
        DBMS_OUTPUT.PUT_LINE('q''['||l_hint||']'',');
        l_hint := NULL;
      ELSE
        l_pos := INSTR(SUBSTR(l_hint, 1, 500), ' ', -1);
        DBMS_OUTPUT.PUT_LINE('q''['||SUBSTR(l_hint, 1, l_pos)||']'',');
        l_hint := '   '||SUBSTR(l_hint, l_pos);
      END IF;
    END LOOP;
  END LOOP;
  DBMS_OUTPUT.PUT_LINE('q''[END_OUTLINE_DATA]'');');
  DBMS_OUTPUT.PUT_LINE(':signature := DBMS_SQLTUNE.SQLTEXT_TO_SIGNATURE(sql_txt);');
  DBMS_OUTPUT.PUT_LINE(':signaturef := DBMS_SQLTUNE.SQLTEXT_TO_SIGNATURE(sql_txt, TRUE);');
  DBMS_OUTPUT.PUT_LINE('DBMS_SQLTUNE.IMPORT_SQL_PROFILE (');
  DBMS_OUTPUT.PUT_LINE('sql_text    => sql_txt,');
  DBMS_OUTPUT.PUT_LINE('profile     => h,');
  DBMS_OUTPUT.PUT_LINE('name        => ''coe_&&sql_id._&&plan_hash_value.'',');
  DBMS_OUTPUT.PUT_LINE('description => ''coe &&sql_id. &&plan_hash_value. ''||:signature||'' ''||:signaturef||'''',');
  DBMS_OUTPUT.PUT_LINE('category    => ''DEFAULT'',');
  DBMS_OUTPUT.PUT_LINE('validate    => TRUE,');
  DBMS_OUTPUT.PUT_LINE('replace     => TRUE,');
  DBMS_OUTPUT.PUT_LINE('force_match => FALSE /* TRUE:FORCE (match even when different literals in SQL). FALSE:EXACT (similar to CURSOR_SHARING) */ );');
  DBMS_OUTPUT.PUT_LINE('DBMS_LOB.FREETEMPORARY(sql_txt);');
  DBMS_OUTPUT.PUT_LINE('END;');
  DBMS_OUTPUT.PUT_LINE('/');
  DBMS_OUTPUT.PUT_LINE('WHENEVER SQLERROR CONTINUE');
  DBMS_OUTPUT.PUT_LINE('SET ECHO OFF;');
  DBMS_OUTPUT.PUT_LINE('PRINT signature');
  DBMS_OUTPUT.PUT_LINE('PRINT signaturef');
  DBMS_OUTPUT.PUT_LINE('PRO');
  DBMS_OUTPUT.PUT_LINE('PRO ... manual custom SQL Profile has been created');
  DBMS_OUTPUT.PUT_LINE('PRO');
  DBMS_OUTPUT.PUT_LINE('SET TERM ON ECHO OFF LIN 80 TRIMS OFF NUMF "";');
  DBMS_OUTPUT.PUT_LINE('SPO OFF;');
  DBMS_OUTPUT.PUT_LINE('PRO');
  DBMS_OUTPUT.PUT_LINE('PRO COE_XFR_SQL_PROFILE_&&sql_id._&&plan_hash_value. completed');
END;
/
SPO OFF;
SET DEF ON TERM ON ECHO OFF FEED 6 VER ON HEA ON LIN 80 PAGES 14 LONG 80 LONGC 80 TRIMS OFF TI OFF TIMI OFF SERVEROUT OFF NUMF "" SQLP SQL>;
SET SERVEROUT OFF;
PRO
PRO Execute coe_xfr_sql_profile_&&sql_id._&&plan_hash_value..sql
PRO on TARGET system in order to create a custom SQL Profile
PRO with plan &&plan_hash_value linked to adjusted sql_text.
PRO
UNDEFINE 1 2 sql_id plan_hash_value
CL COL
PRO
PRO COE_XFR_SQL_PROFILE completed.
  
  
**********************************************************
  
  
  
  
  
set linesize window
SELECT * FROM table(DBMS_XPLAN.DISPLAY_CURSOR(NULL, NULL, 'ALLSTATS LAST'));






set lines 300
col sql_sql_text head SQL_TEXT format a50 word_wrap
col sql_child_number head CH# for 9999
column EXACT_MATCHING_SIGNATURE format 99999999999999999999
column force_matching_signature format 99999999999999999999
select 
  s.sql_id,
  s.hash_value, 
  s.plan_hash_value, 
  s.force_matching_signature, 
  s.EXACT_MATCHING_SIGNATURE,
  t.phv2,
  s.sql_text sql_sql_text  
from 
  v$sql s,
  v$sql_plan p
 ,xmltable('for $i in /other_xml/info
             where $i/@type eq "plan_hash_2"
             return $i'
             passing xmltype(p.other_xml)
             columns phv2 number path '/'
            ) t
where
s.sql_id=p.sql_id
AND
s.plan_hash_value=p.plan_hash_value
AND
s.child_number=p.CHILD_NUMBER
AND
p.other_xml is not null
-- AND s.sql_text like 'sql_text%'
and s.sql_id in ('dg8duxp7zprxp','29v6w386wqnzt')
order by   3 desc




coe_xfr_sql_profile.sql dg8duxp7zprxp 1288918533



coe_xfr_sql_profile.sql dg8duxp7zprxp PLAN_HASH_VALUE




SQL> ed coe_xfr_sql_profile

SQL> @coe_xfr_sql_profile

Parameter 1:
SQL_ID (required)

Enter value for 1: dg8duxp7zprxp


AVG_ET_SECS_MEM AVG_ET_SECS_AWR PLAN_HASH_VALUE EXECUTIONS_MEM EXECUTIONS_AWR
--------------- --------------- --------------- -------------- --------------
       0.017320                      1130139812              1

Parameter 2:
PLAN_HASH_VALUE (required)

Enter value for 2: 1130139812

Values passed to coe_xfr_sql_profile:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
SQL_ID         : "dg8duxp7zprxp"
PLAN_HASH_VALUE: "1130139812"

SQL>BEGIN
  2    IF :sql_text IS NULL THEN
  3      RAISE_APPLICATION_ERROR(-20100, 'SQL_TEXT for SQL_ID &&sql_id. was not found in memory (gv$sqltext_with_newlines) or AWR (dba_hist_sqltext).');
  4    END IF;
  5  END;
  6  /
SQL>SET TERM OFF;
SQL>BEGIN
  2    IF :other_xml IS NULL THEN
  3      RAISE_APPLICATION_ERROR(-20101, 'PLAN for SQL_ID &&sql_id. and PHV &&plan_hash_value. was not found in memory (gv$sql_plan) or AWR (dba_hist_sql_plan).');
  4    END IF;
  5  END;
  6  /
SQL>SET TERM OFF;

Execute coe_xfr_sql_profile_dg8duxp7zprxp_1130139812.sql
on TARGET system in order to create a custom SQL Profile
with plan 1130139812 linked to adjusted sql_text.


COE_XFR_SQL_PROFILE completed.




##########################



SQL>!grep -i force coe_xfr_sql_profile_dg8duxp7zprxp_1130139812.sql
force_match => FALSE /* TRUE:FORCE (match even when different literals in SQL). FALSE:EXACT (similar to CURSOR_SHARING) */ );

SQL>







SQL>@coe_xfr_sql_profile_dg8duxp7zprxp_1130139812.sql
SQL>REM
SQL>REM $Header: 215187.1 coe_xfr_sql_profile_dg8duxp7zprxp_1130139812.sql 11.4.4.4 2025/01/03 carlos.sierra $
SQL>REM
SQL>REM Copyright (c) 2000-2012, Oracle Corporation. All rights reserved.
SQL>REM
SQL>REM AUTHOR
SQL>REM   carlos.sierra@oracle.com
SQL>REM
SQL>REM SCRIPT
SQL>REM   coe_xfr_sql_profile_dg8duxp7zprxp_1130139812.sql
SQL>REM
SQL>REM DESCRIPTION
SQL>REM   This script is generated by coe_xfr_sql_profile.sql
SQL>REM   It contains the SQL*Plus commands to create a custom
SQL>REM   SQL Profile for SQL_ID dg8duxp7zprxp based on plan hash
SQL>REM   value 1130139812.
SQL>REM   The custom SQL Profile to be created by this script
SQL>REM   will affect plans for SQL commands with signature
SQL>REM   matching the one for SQL Text below.
SQL>REM   Review SQL Text and adjust accordingly.
SQL>REM
SQL>REM PARAMETERS
SQL>REM   None.
SQL>REM
SQL>REM EXAMPLE
SQL>REM   SQL> START coe_xfr_sql_profile_dg8duxp7zprxp_1130139812.sql;
SQL>REM
SQL>REM NOTES
SQL>REM   1. Should be run as SYSTEM or SYSDBA.
SQL>REM   2. User must have CREATE ANY SQL PROFILE privilege.
SQL>REM   3. SOURCE and TARGET systems can be the same or similar.
SQL>REM   4. To drop this custom SQL Profile after it has been created:
SQL>REM  EXEC DBMS_SQLTUNE.DROP_SQL_PROFILE('coe_dg8duxp7zprxp_1130139812');
SQL>REM   5. Be aware that using DBMS_SQLTUNE requires a license
SQL>REM  for the Oracle Tuning Pack.
SQL>REM   6. If you modified a SQL putting Hints in order to produce a desired
SQL>REM  Plan, you can remove the artifical Hints from SQL Text pieces below.
SQL>REM  By doing so you can create a custom SQL Profile for the original
SQL>REM  SQL but with the Plan captured from the modified SQL (with Hints).
SQL>REM
SQL>WHENEVER SQLERROR EXIT SQL.SQLCODE;
SQL>REM
SQL>VAR signature NUMBER;
SQL>VAR signaturef NUMBER;
SQL>REM
SQL>DECLARE
  2  sql_txt CLOB;
  3  h       SYS.SQLPROF_ATTR;
  4  PROCEDURE wa (p_line IN VARCHAR2) IS
  5  BEGIN
  6  DBMS_LOB.WRITEAPPEND(sql_txt, LENGTH(p_line), p_line);
  7  END wa;
  8  BEGIN
  9  DBMS_LOB.CREATETEMPORARY(sql_txt, TRUE);
 10  DBMS_LOB.OPEN(sql_txt, DBMS_LOB.LOB_READWRITE);
 11  -- SQL Text pieces below do not have to be of same length.
 12  -- So if you edit SQL Text (i.e. removing temporary Hints),
 13  -- there is no need to edit or re-align unmodified pieces.
 14  wa(q'[with s1 as (
 15    select
 16      a.n2 n2,
 17      a.vc vc
 18    from
 19      t1 a
 20  )]');
 21  wa(q'[,
 22  s2 as (
 23    select
 24      b.n4 n4,
 25      b.vd vd
 26    from
 27      t2 b
 28  )
 29  se]');
 30  wa(q'[lect
 31    s1.n2,
 32    s1.vc,
 33    s2.n4,
 34    s2.vd,
 35    s1.n2||s2.n4 as N
 36  fro]');
 37  wa(q'[m
 38    s1,
 39    s2
 40  where
 41    s1.n2 = s2.n4
 42    and s1.vc = 'xY'
 43      AND s2]');
 44  wa(q'[.n4 = 0]');
 45  DBMS_LOB.CLOSE(sql_txt);
 46  h := SYS.SQLPROF_ATTR(
 47  q'[BEGIN_OUTLINE_DATA]',
 48  q'[IGNORE_OPTIM_EMBEDDED_HINTS]',
 49  q'[OPTIMIZER_FEATURES_ENABLE('23.1.0')]',
 50  q'[DB_VERSION('23.1.0')]',
 51  q'[ALL_ROWS]',
 52  q'[OUTLINE_LEAF(@"SEL$18780C30")]',
 53  q'[MERGE(@"SEL$1" >"SEL$3")]',
 54  q'[MERGE(@"SEL$2" >"SEL$3")]',
 55  q'[OUTLINE(@"SEL$3")]',
 56  q'[OUTLINE(@"SEL$1")]',
 57  q'[OUTLINE(@"SEL$2")]',
 58  q'[FULL(@"SEL$18780C30" "B"@"SEL$2")]',
 59  q'[INDEX_RS_ASC(@"SEL$18780C30" "A"@"SEL$1" ("T1"."N2"))]',
 60  q'[BATCH_TABLE_ACCESS_BY_ROWID(@"SEL$18780C30" "A"@"SEL$1")]',
 61  q'[LEADING(@"SEL$18780C30" "B"@"SEL$2" "A"@"SEL$1")]',
 62  q'[USE_MERGE_CARTESIAN(@"SEL$18780C30" "A"@"SEL$1")]',
 63  q'[END_OUTLINE_DATA]');
 64  :signature := DBMS_SQLTUNE.SQLTEXT_TO_SIGNATURE(sql_txt);
 65  :signaturef := DBMS_SQLTUNE.SQLTEXT_TO_SIGNATURE(sql_txt, TRUE);
 66  DBMS_SQLTUNE.IMPORT_SQL_PROFILE (
 67  sql_text    => sql_txt,
 68  profile     => h,
 69  name        => 'coe_dg8duxp7zprxp_1130139812',
 70  description => 'coe dg8duxp7zprxp 1130139812 '||:signature||' '||:signaturef||'',
 71  category    => 'DEFAULT',
 72  validate    => TRUE,
 73  replace     => TRUE,
 74  force_match => FALSE /* TRUE:FORCE (match even when different literals in SQL). FALSE:EXACT (similar to CURSOR_SHARING) */ );
 75  DBMS_LOB.FREETEMPORARY(sql_txt);
 76  END;
 77  /

PL/SQL procedure successfully completed.

SQL>WHENEVER SQLERROR CONTINUE
SQL>SET ECHO OFF;

            SIGNATURE
---------------------
  5336375310114799588


           SIGNATUREF
---------------------
 14577638555275281096


... manual custom SQL Profile has been created


COE_XFR_SQL_PROFILE_dg8duxp7zprxp_1130139812 completed


col name for a35
col created for a30
col FORCE_MATCHING for a25
SELECT 
  --s.sql_id, 
 -- s.plan_hash_value, 
  p.name, 
  p.CREATED, 
 -- p.LAST_MODIFIED, 
  p.STATUS, 
  p.FORCE_MATCHING 
FROM 
  dba_sql_profiles p, 
  v$sqlstats s 
where 
  p.signature = s.FORCE_MATCHING_SIGNATURE
AND s.sql_id='dg8duxp7zprxp';




set linesize 300
col name for a35
col created for a30
col FORCE_MATCHING for a25
SELECT 
  --s.sql_id, 
 -- s.plan_hash_value, 
  p.name, 
  p.CREATED, 
 -- p.LAST_MODIFIED, 
  p.STATUS, 
  p.FORCE_MATCHING 
FROM 
  dba_sql_profiles p ;
  
  
  
  NAME                                CREATED                        STATUS   FORCE_MATCHING
----------------------------------- ------------------------------ -------- -------------------------
coe_dg8duxp7zprxp_1130139812        03-JAN-25 02.30.19.728687 PM   ENABLED  NO

Oracle DBA

anuj blog Archive