Disclaimer

Thursday, 3 March 2022

Optimizer Adaptive feature parameter in Oracle

Oracle optimizer is used to find the most effective execution plan for each SQL statement. Oracle released adaptive feature in Oracle 12c.

Adaptive Query Optimization is a set of capabilities that enable the optimizer to make run-time adjustments to execution plans and discover additional information that can lead to better statistics. 
This new approach is extremely helpful when existing statistics are not sufficient to generate an optimal plan. 

Adaptive query optimization means during runtime of SQL statement find better execution plan with adjust statistics.

There are two distinct aspects in Adaptive Query Optimization:

Adaptive plans: focuses on improving the execution of a query

Adaptive statistics: uses additional information to improve query execution plans.





Following are the parameter as optimizer adaptive plan and optimizer adaptive statistics.

SQL> show parameter adaptive

NAME                                 TYPE         VALUE
------------------------------------ ------------ ------------------------------
optimizer_adaptive_plans             boolean      TRUE
optimizer_adaptive_reporting_only    boolean      FALSE
optimizer_adaptive_statistics        boolean      FALSE
parallel_adaptive_multi_user         boolean      FALSE

For Enable and Disable Adaptive features
In Oracle 12101 version only one parameter defines for adaptive but in 12102 version use two parameter as adaptive:

-- Enable
In 12101 version:
alter system set optimizer_adaptive_features=true scope=both;

In 12102 onward:
alter system set optimizer_adaptive_plans=true scope=both;
alter system set optimizer_adaptive_statistics=true scope=both;

-- Disable
In 12101 version:
alter system set optimizer_adaptive_features=false scope=both;

In 12102 onward:
alter system set optimizer_adaptive_plans=false scope=both;
alter system set optimizer_adaptive_statistics=false scope=both;

1) OPTIMIZER_ADAPTIVE_PLANS
It used by query optimizer for considers adaptive plans. If it’s set to TRUE (the default), the feature is enabled.
Following are the hidden parameter used by adaptive plans:
_OPTIMIZER_NLJ_HJ_ADAPTIVE_JOIN:
It is used the adaptive join methods. If it’s set to TRUE (the default), the feature is enabled.


_PX_ADAPTIVE_DIST_METHOD:
It controls the adaptive parallel distribution methods. If it’s set to CHOOSE (the default), the feature is enabled. If it’s set to OFF, the feature is disabled.

_OPTIMIZER_STRANS_ADAPTIVE_PRUNING:
It will controls the adaptive star transformations. If it’s set to TRUE (the default), the feature is enabled.

2) OPTIMIZER_ADAPTIVE_STATISTICS
It used by query optimizer for considers adaptive statistics, It is set to TRUE then enabled, FALSE (DEFAULT)

Following are the hidden parameter used by adaptive statistics:
_OPTIMIZER_DSDIR_USAGE_CONTROL
It controls whether the query optimizer uses SQL plan directives. If it’s set to 126 (the default), the feature is enabled.

If it’s set to 0, the feature is disabled. This parameter also supports other integer values, but I never spent time investigating their behavior.

_OPTIMIZER_GATHER_FEEDBACK
It controls whether the query optimizer asks the execution engine to check for mis-estimates then create feedback, If it’s set to TRUE (the default), the feature is enabled.


_OPTIMIZER_USE_FEEDBACK
It controls whether the query optimizer choose to use the feedback’s and produced more execution plan for compare. If it’s set to TRUE (the default), the feature is enabled.
_sql_plan_directive_mgmt_control
O means disable creation of directives, 3 value means enable creation of directives.

Check discription of these parameter

select ksppinm,ksppdesc from x$ksppi where ksppinm in ('_optimizer_nlj_hj_adaptive_join', '_optimizer_strans_adaptive_pruning',
'_px_adaptive_dist_method', '_sql_plan_directive_mgmt_control', '_optimizer_dsdir_usage_control', '_optimizer_use_feedback', '_optimizer_gather_feedback', '_optimizer_performance_feedback');

Change the adaptive parameter inner functionality with hidden parameters

-- Backup of the parameter
COLUMN ksppinm FORMAT A40
COLUMN ksppstvl FORMAT A20
SELECT ksppinm,ksppstvl FROM x$ksppi a,x$ksppsv b WHERE a.indx=b.indx
AND ksppinm in ('_optimizer_nlj_hj_adaptive_join', '_optimizer_strans_adaptive_pruning', '_px_adaptive_dist_method', '_sql_plan_directive_mgmt_control', '_optimizer_dsdir_usage_control',
'_optimizer_use_feedback', '_optimizer_gather_feedback', '_optimizer_performance_feedback') ORDER BY ksppinm;

KSPPINM                                KSPPDESC
-------------------------------------- -------------------------------------------------------------
_optimizer_use_feedback                optimizer use feedback
_optimizer_gather_feedback             optimizer gather feedback
_sql_plan_directive_mgmt_control       controls internal SQL Plan Directive management activities
_px_adaptive_dist_method               determines the behavior of adaptive distribution methods
_optimizer_dsdir_usage_control         controls optimizer usage of dynamic sampling directives
_optimizer_strans_adaptive_pruning     allow adaptive pruning of star transformation bitmap trees
_optimizer_performance_feedback        controls the performance feedback
_optimizer_nlj_hj_adaptive_join        allow adaptive NL Hash joins


KSPPINM                                  KSPPSTVL
---------------------------------------- --------------------
_optimizer_dsdir_usage_control           0
_optimizer_gather_feedback               TRUE
_optimizer_nlj_hj_adaptive_join          TRUE
_optimizer_performance_feedback          OFF
_optimizer_strans_adaptive_pruning       TRUE
_optimizer_use_feedback                  TRUE
_px_adaptive_dist_method                 CHOOSE
_sql_plan_directive_mgmt_control         67

--Disable the parameters
alter system set "_optimizer_nlj_hj_adaptive_join"= FALSE scope=both;
alter system set "_optimizer_strans_adaptive_pruning"= FALSE scope=both;
alter system set "_px_adaptive_dist_method" = OFF scope=both;
alter system set "_sql_plan_directive_mgmt_control" = 0 scope=both;
alter system set "_optimizer_dsdir_usage_control" = 0 scope=both;
alter system set "_optimizer_use_feedback" = FALSE scope=both;
alter system set "_optimizer_gather_feedback" = FALSE scope=both;
alter system set "_optimizer_performance_feedback" = OFF scope=both;

-- Reset the parameter
alter system reset "_optimizer_nlj_hj_adaptive_join" scope=both;
alter system reset "_optimizer_strans_adaptive_pruning" scope=both;
alter system reset "_px_adaptive_dist_method" scope=both;
alter system reset "_sql_plan_directive_mgmt_control" scope=both;
alter system reset "_optimizer_dsdir_usage_control" scope=both;
alter system reset "_optimizer_use_feedback" scope=both;
alter system reset "_optimizer_gather_feedback" scope=both;
alter system reset "_optimizer_performance_feedback" scope=both;

You can also use the parameter as hints:

select /*+ opt_param('_optimizer_use_feedback' 'false') */ * from table;













Oracle 19c Import with disable_archive_logging

Oracle 19c Import with disable_archive_logging Tips

Oracle19c feature is the ability to run in nologging mode in import execution, disabling archive logging during a large import. Only for table and index Not for tablespace.

    transform=disable_archive_logging:Y
    transform=disable_archive_logging:Y:tablename
    transform=disable_archive_logging:Y:indexname

Test

Create directory and user;

SYS@orcl> create directory imp_home as '/home/oracle';

Directory created.

SYS@orcl> 
SYS@orcl> show parameter user_pre

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
common_user_prefix                   string      C##

SYS@orcl> create user c##lin identified by oracle;

User created.

SYS@orcl> grant dba to c##lin;

Grant succeeded.

SYS@orcl>

Generate data

SYS@orcl> conn c##lin/oracle
Connected.
C##LIN@orcl>
C##LIN@orcl> select count(*) from dba_objects;

  COUNT(*)
----------
     72549

C##LIN@orcl> select count(*) from cdb_objects;

  COUNT(*)
----------
     72549

C##LIN@orcl> create table imp_test as select * from dba_objects;

Table created.

C##LIN@orcl> insert into imp_test (select * from imp_test);

72549 rows created.

C##LIN@orcl> /

145098 rows created.

C##LIN@orcl> /

290196 rows created.

C##LIN@orcl> /

580392 rows created.

C##LIN@orcl> /

1160784 rows created.

C##LIN@orcl> commit;

Commit complete.

C##LIN@orcl>

C##LIN@orcl> col segment_name for a20
C##LIN@orcl> select bytes/1024/1024  mb, segment_name, segment_type from user_segments;

        MB SEGMENT_NAME         SEGMENT_TYPE
---------- -------------------- ------------------
       360 IMP_TEST             TABLE



Export the test data;


C##LIN@orcl> !expdp \"/as sysdba\" directory=imp_home dumpfile=imp_test.dmp logfile=imp_test.log schemas="C##LIN"

Export: Release 19.0.0.0.0 - Production on Thu Aug 22 14:03:58 2019
Version 19.3.0.0.0

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

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.

Starting "SYS"."SYS_EXPORT_SCHEMA_01":  "/******** AS SYSDBA" directory=imp_home dumpfile=imp_test.dmp logfile=imp_test.log schemas=C##LIN
Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA
Processing object type SCHEMA_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS
Processing object type SCHEMA_EXPORT/STATISTICS/MARKER
Processing object type SCHEMA_EXPORT/SYSTEM_GRANT
Processing object type SCHEMA_EXPORT/ROLE_GRANT
Processing object type SCHEMA_EXPORT/DEFAULT_ROLE
Processing object type SCHEMA_EXPORT/PRE_SCHEMA/PROCACT_SCHEMA
Processing object type SCHEMA_EXPORT/TABLE/TABLE
. . exported "C##LIN"."IMP_TEST"                         305.8 MB 2321568 rows
Master table "SYS"."SYS_EXPORT_SCHEMA_01" successfully loaded/unloaded
******************************************************************************
Dump file set for SYS.SYS_EXPORT_SCHEMA_01 is:
  /home/oracle/imp_test.dmp
Job "SYS"."SYS_EXPORT_SCHEMA_01" successfully completed at Thu Aug 22 14:07:32 2019 elapsed 0 00:03:10


C##LIN@orcl> 
C##LIN@orcl> !ls -ltr /home/oracle/imp_test.dmp
-rw-r-----. 1 oracle oinstall 321089536 Aug 22 14:07 /home/oracle/imp_test.dmp

C##LIN@orcl> !du -sm /home/oracle/imp_test.dmp
307     /home/oracle/imp_test.dmp



Test import transform_enable mode: redo log from 724mb to 1081mb / elapsed 0 00:02:20


C##LIN@orcl> drop table c##lin.imp_test purge;

Table dropped.

C##LIN@orcl> select name, value/1024/1024 mb from v$sysstat where name ='redo size' ;

NAME                                                                     MB
---------------------------------------------------------------- ----------
redo size                                                        724.179874

C##LIN@orcl> !impdp \"/as sysdba\" directory=imp_home dumpfile=imp_test.dmp logfile=transform_disable.log schemas="C##LIN"

Import: Release 19.0.0.0.0 - Production on Thu Aug 22 14:22:11 2019
Version 19.3.0.0.0

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

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.

Master table "SYS"."SYS_IMPORT_SCHEMA_01" successfully loaded/unloaded
Starting "SYS"."SYS_IMPORT_SCHEMA_01":  "/******** AS SYSDBA" directory=imp_home dumpfile=imp_test.dmp logfile=transform_disable.log schemas=C##LIN
Processing object type SCHEMA_EXPORT/SYSTEM_GRANT
Processing object type SCHEMA_EXPORT/ROLE_GRANT
Processing object type SCHEMA_EXPORT/DEFAULT_ROLE
Processing object type SCHEMA_EXPORT/PRE_SCHEMA/PROCACT_SCHEMA
Processing object type SCHEMA_EXPORT/TABLE/TABLE
Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA
. . imported "C##LIN"."IMP_TEST"                         305.8 MB 2321568 rows
Processing object type SCHEMA_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS
Processing object type SCHEMA_EXPORT/STATISTICS/MARKER
Job "SYS"."SYS_IMPORT_SCHEMA_01" successfully completed at Thu Aug 22 14:24:39 2019 elapsed 0 00:02:20


C##LIN@orcl> select name, value/1024/1024 mb from v$sysstat where name ='redo size' ;

NAME                                                                     MB
---------------------------------------------------------------- ----------
redo size                                                        1081.06575

C##LIN@orcl>




Test import transform_disable mode: redo log from 1081mb to 1084mb / elapsed 0 00:01:28


C##LIN@orcl> drop table c##lin.imp_test purge;

Table dropped.

C##LIN@orcl> select name, value/1024/1024 mb from v$sysstat where name ='redo size' ;

NAME                                                                     MB
---------------------------------------------------------------- ----------
redo size                                                        1081.18863

C##LIN@orcl>
C##LIN@orcl> !impdp \"/as sysdba\" directory=imp_home dumpfile=imp_test.dmp logfile=transform_disable.log schemas="C##LIN" transform=disable_archive_logging:Y

Import: Release 19.0.0.0.0 - Production on Thu Aug 22 14:28:48 2019
Version 19.3.0.0.0

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

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.

Master table "SYS"."SYS_IMPORT_SCHEMA_01" successfully loaded/unloaded
Starting "SYS"."SYS_IMPORT_SCHEMA_01":  "/******** AS SYSDBA" directory=imp_home dumpfile=imp_test.dmp logfile=transform_disable.log schemas=C##LIN transform=disable_archive_logging:Y
Processing object type SCHEMA_EXPORT/SYSTEM_GRANT
Processing object type SCHEMA_EXPORT/ROLE_GRANT
Processing object type SCHEMA_EXPORT/DEFAULT_ROLE
Processing object type SCHEMA_EXPORT/PRE_SCHEMA/PROCACT_SCHEMA
Processing object type SCHEMA_EXPORT/TABLE/TABLE
Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA
. . imported "C##LIN"."IMP_TEST"                         305.8 MB 2321568 rows
Processing object type SCHEMA_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS
Processing object type SCHEMA_EXPORT/STATISTICS/MARKER

Job "SYS"."SYS_IMPORT_SCHEMA_01" successfully completed at Thu Aug 22 14:30:23 2019 elapsed 0 00:01:28


C##LIN@orcl> select name, value/1024/1024 mb from v$sysstat where name ='redo size' ;

NAME                                                                     MB
---------------------------------------------------------------- ----------
redo size                                                        1084.21175

C##LIN@orcl>



The Result of importing with transform/disable_archive_logging


Datatransform(archive_logging)Generated Redo log sizeImport elapsed
360MBenable(default)357 MB02:20
360MBdisable3.1 MB01:28





SQL Analyze in AWR report - 19c

Oracle 19c Analysis SQL in AWR report

There are some sql in SQL ordered by CPU Time AWR report.

These sql were using so many cpu time…








/* SQL Analyze(0) */ select /*+ full(t) parallel(t, 6) parallel_index(t, 6) dbms_stats cursor_sharing_exact use_weak_name_resl dynamic_sampling(0) no_monitoring xmlindex_sel_idx_tbl no_substrb_pad */to_char...
 


What are these sqls? what are they doing?

Simulate test

LIN@pdb1> drop table lin.test_tab purge;

Table dropped.

LIN@pdb1> create table lin.test_tab(col1 number, col2 varchar(20));

Table created.

LIN@pdb1>
begin
 for i in 1..10000 loop
 insert into lin.test_tab values (i, i||'aaaabbbb');
 end loop;
 commit;
end;
  7  /

PL/SQL procedure successfully completed.

LIN@pdb1> select count(*) from lin.test_tab;

  COUNT(*)
----------
     10000

LIN@pdb1>
LIN@pdb1> conn sys/oracle@pdb1 as sysdba
Connected.
SYS@pdb1> alter session set max_dump_file_size = UNLIMITED;

Session altered.

SYS@pdb1> alter session set events '10046 trace name context forever, level 12';

Session altered.

SYS@pdb1> exec DBMS_STATS.GATHER_TABLE_STATS('LIN','TEST_TAB');

PL/SQL procedure successfully completed.

SYS@pdb1> alter session set events '10046 trace name context off';

Session altered.

SYS@pdb1>
SYS@pdb1> select tracefile from v$process where addr in (select paddr from v$session where sid in (select sid from v$mystat));

TRACEFILE
--------------------------------------------------------------------------------
/u01/app/oracle/diag/rdbms/orcl/orcl/trace/orcl_ora_17733.trc

SYS@pdb1> !ls -ltr /u01/app/oracle/diag/rdbms/orcl/orcl/trace/orcl_ora_17733.trc
-rw-r-----. 1 oracle oinstall 520812 Feb 19 09:12 /u01/app/oracle/diag/rdbms/orcl/orcl/trace/orcl_ora_17733.trc

SYS@pdb1> 

the /* SQL Analyze(0) */ sql can be found in the trace file

PARSING IN CURSOR #139867558904224 len=513 dep=1 uid=126 oct=3 lid=0 tim=16068278669 hv=2609264150 ad='71e71608' sqlid='1391vrydscdhq'
/* SQL Analyze(0) */ select /*+  full(t)    no_parallel(t) no_parallel_index(t) dbms_stats cursor_sharing_exact use_weak_name_resl dynamic_sampling(0) no_monitoring xmlindex_sel_idx_tbl opt_param('optimizer_inmemory_aware' 'false') no_substrb_pad  */to_char(count("COL1")),substrb(dump(min("COL1"),16,0,64),1,240),substrb(dump(max("COL1"),16,0,64),1,240),to_char(count("COL2")),substrb(dump(min("COL2"),16,0,64),1,240),substrb(dump(max("COL2"),16,0,64),1,240) from "LIN"."TEST_TAB" t  /* NDV,NIL,NIL,NDV,NIL,NIL*/


Result

the sql - /* SQL Analyze(0) */ is similar with the internal sql which are from using DBMS_STATS package to gather statistics with objects

Maybe happened in mid-night, there are some batch job doing insert append sql and gather statistics with objects online.


Monday, 28 February 2022

Flashback Oracle RAC Database with Dataguard

 


Flashback Oracle RAC Database with Dataguard

 


##########   Creating  Restore Point  ############

1)  Stop Redo Transport and Redo Apply 

A)  When we Dont have Broker Configuration  

alter system set log_archive_dest_state_n='defer'  sid='*' ;   ( On primary
alter database recover managed standby database cancel  ;  
 ( On Standby ) 

B)  When we have Broker Configuration  
edit database Chicago  set state='TRANSPORT-OFF'; 
EDIT database Boston  set state='apply-off' ; 



2) Create Restore  Point (in Standby First   ) 

create  restore point GRP_DG GUARANTEE FLASHBACK DATABASE ;  
 ( On Standby ) 
create  restore point GRP_PR  GUARANTEE FLASHBACK DATABASE ;   ( On Primary ) 



3) Enable Log Transport and Apply 

A) When we Dont have Broker Configuration  
alter system set log_archive_dest_state_n='enable'  sid='*' ;   ( On primary ) 
alter database recover managed standby databsae  using current logfile  disconnect ;  ( on  Standby

B)  When we chave Broker Configuration 
edit database Chicago  set state='TRANSPORT-On'; 
EDIT database Boston  set state='apply-on' ; 





##########  Flashback Database   ############


1)  Stop Redo Transport and Redo Apply 

A)  When we Dont have Broker Configuration  

alter system set log_archive_dest_state_n='defer'  sid='*'  ;   ( On primary ) 

alter database recover managed standby database cancel  ;   
( On Standby ) 

B)  When we chave Broker Configuration  
edit database Chicago  set state='TRANSPORT-OFF'; 
EDIT database Boston  set state='apply-off' ; 





2 a) Flashbackup  Primary Database to restore Point 

srvctl stop database -d DB_NAME 
srvctl start instance -d DB_NAME -i instance_name -o mount 
flashback database to restore point GRP_PR ; 
alter database open resetlogs ; 
srvctl stop instance -d DB_NAME -i instance_name  
srvctl start database -d DB_NAME 


2 b) Flashbackup  Satndby Database to restore Point 

srvctl stop database -db  DB_NAME -stopoption immediate 
srvctl start instance -d DB_NAME -i instance_name -o mount 
flashback database to restore point GRP_DG ; 
srvctl stop instance -db DB_NAME -i instance_name  
srvctl start database -db DB_NAME -startoption  mount 


3) Enable Log Transport and Apply 

A) When we Dont have Broker Configuration  
alter system set log_archive_dest_state_n='enable'  SID='*';   ( On primary ) 
alter database recover managed standby databsae  using current logfile  disconnect ;  ( on  Standby ) 

B)  When we chave Broker Configuration 
edit database Chicago  set state='TRANSPORT-On'; 
EDIT database Boston  set state='apply-on' ; 



4)  Restart standby database on  Database pass through  resetlogs  and there is no lag 




########## Drop Restore Point   ############



1)  Stop Redo Transport and Redo Apply 

A)  When we Dont have Broker Configuration  
alter system set log_archive_dest_state_n='defer'  SID='*';  
 ( On primary ) 

alter database recover managed standby database cancel  ;   
( On Standby ) 

B)  When we chave Broker Configuration  
edit database Chicago  set state='TRANSPORT-OFF'; 
EDIT database Boston  set state='apply-off' ; 



2) Drop Restore  Point  

drop  restore point GRP_PR  ;   ( On Primary ) 
dROP  restore point GRP_dg   ;   ( On Standby ) 




3) Enable Log Transport and Apply 

A) When we Dont have Broker Configuration  
alter system set log_archive_dest_state_n='enable'  SID='*';   ( On primary ) 
alter database recover managed standby databsae  using current logfile  disconnect ;  ( on  Standby ) 

B)  When we chave Broker Configuration 
edit database Chicago  set state='TRANSPORT-On'; 
EDIT database Boston  set state='apply-on' ; 



########## Reference   ############

Metalink Doc   2338328.1 



Oracle Database smon recovery -- Disable , enable and Tuning Rollback

 

Oracle Database smon recovery -- Disable , enable and Tuning Rollback

 

Most of time we face performance issues , we miss to  check if there  is rollback ongoing . However we come across many situations where rollback is ongoing which impacts database performance .

We can speed up and slowdown rollback seeing business hours .

 If Undo tablespace is used up and rollback is slow , we can add new undo tablespace and change default undo tablespace 

If smon recovery is causing performance issues we may opt to disable smon recovery temporarily and re-enable back after business hours .  Similarly we can speed up and reduce speed of smon recovery 


How to check Smon recovery : 

set linesize 100
alter session set NLS_DATE_FORMAT='DD-MON-YYYY HH24:MI:SS';

  select ktuxeusn, to_char(sysdate,'DD-MON-YYYY HH24:MI:SS') "Time", ktuxesiz, ktuxesta
   from x$ktuxe
   where ktuxecfl = 'DEAD';
 
 
 
select sql_text
from v$sqlarea
where address = (select sql_address from v$session where sid in (select SID 
from v$transaction,dba_rollback_segs,v$session        
where SADDR=SES_ADDR and
      XIDUSN=SEGMENT_ID and
      flag=7811));
 
 


Disable parallel rollback / smon recovery
 
-- to check if parallel smon recovery is in progress

select * from v$fast_start_servers;  
select pid, spid from v$process where pid in ( select pid from v$fast_start_servers);
 

-- set PID of smon
-- not be killed . main smon  
select pid, program from v$process where program like '%SMON%'; -

 -- disable SMON transaction rollback/recovery
oradebug setorapid 10  

oradebug event 10513 trace name context forever, level 2

-- kill parallel  smon processes if its exists
select 'alter system kill session '''||s.sid||','||s.serial#||''' immediate;', 'kill -9 '||spid from v$session s, (select * from v$process
 where pid in (select pid from v$fast_start_servers)) p
 where s.paddr=p.addr;
 
-- disable parallel smon
alter system set fast_start_parallel_rollback=false;  
select * from v$fast_start_servers;
select pid from v$fast_start_servers ;
show parameter fast
 
-- enable  SMON transaction rollback/recovery
oradebug event 10513 trace name context off ; 
 


 
Speed up smon recovery
 
1)
select * from v$fast_start_servers;
If all the processes are in state RECOVERING, then you can benefit from adding more processes:
  
SQL> alter system set fast_start_parallel_rollback = high;
 
This will create parallel servers as much as 4 times the number of CPUs.
 
 
2)
Increase the parameter ‘_cleanup_rollback_entries’ to 400. The default is 100.
This parameter cannot be changed dynamically, so in order to change this the database will need to be restarted. As outlined above this is not advisable  and basically needs to be done when no alternative. This needs to be done only on suggestion of  Oracle support 




CONVERT NON-CONTAINER ORACLE DB TO CONTAINER DB

Here are the two situations:

  • Convert a Non-Container 12C database to Container 12C database
  • Migrate Non-Container 11g/12C database to Container 12C database


  • There is no direct way to convert a Non-Container 12C database to Container 12C database. All you can do is to consider Non-Container database as a pluggable database(PDB) and attach it to the existing 12C container database.

    With that said - How to create a PDB Using a Non-CDB?

    Both the CDB and the non-CDB must be running Oracle Database 12c Release 1 (12.1.0.2) or later.
    If your current non-CDB uses an Oracle Database release before Oracle Database 12c Release 1 (12.1.0.2), then you must upgrade the non-CDB to Oracle Database 12C.

    Once you have both your Non-Container database and Container database running on 12C,
  • you can can create a PDB by cloning a non-CDB
  • This method is the simplest way to create a PDB using a non-CDB, but it requires copying the files of the non-CDB to a new location.

  • Use the DBMS_PDB package to generate an XML metadata file
  • This method is little complicated. The XML metadata file describes the database files of the non-CDB so that you can plug it into a CDB.

  • Use Oracle Data Pump export/import
  • You export the data from the non-CDB and import it into a PDB. If the Oracle Database release of the non-CDB is Oracle Database 11g Release 2 (11.2.0.3) or later, then you can use full transportable export/import to move the data.

    When transporting a non-CDB from an Oracle Database 11g Release 2 (11.2.0.3) or later Oracle Database 11g database to Oracle Database 12c, the VERSION Data Pump export parameter must be set to 12.0.0.0.0 or higher.

  • Use GoldenGate replication
  • You replicate the data from the non-CDB to a PDB. When the PDB catches up with the non-CDB, you fail over to the PDB.


    How to Change DBID of a Single-Instance Database

     

    For a duplicate database, you may want to change its Database Identifier (DBID) only in order to distinguish this one from another. 

    Here we use nid, a DBNEWID utility provided by Oracle to change DBID only.

    Let's check DBID before changing.

    [oracle@test ~]$ sqlplus / as sysdba
    ...
    SQL> select name, dbid from v$database;

    NAME            DBID
    --------- ----------
    TESTCDB   
    3411734329

    We restart the database to MOUNT state.

    SQL> shutdown immediate;
    Database closed.
    Database dismounted.
    ORACLE instance shut down.
    SQL> startup mount
    ORACLE instance started.
    ...
    Database mounted.


    Next, we use nid to connect to the database. Without specifying DBNAMEnid will change only DBID. There're more options of nid syntax in Oracle documentation.

    [oracle@test ~]$ nid target=sys


    Or connect to the database via a TNS name.

    [oracle@test ~]$ nid target=sys@testcdb

    DBNEWID: Release 19.0.0.0.0 - Production on Mon Dec 21 21:00:40 2020

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

    Password:

    Connected to database TESTCDB (DBID=3411734329)

    Connected to server version 19.9.0

    Control Files in database:
        /u01/app/oracle/oradata/TESTCDB/control01.ctl
        /u01/app/oracle/fast_recovery_area/TESTCDB/control02.ctl

    Change database ID of database TESTCDB? (Y/[N]) => Y

    Proceeding with operation
    Changing database ID from 3411734329 to 3425699846
        Control File /u01/app/oracle/oradata/TESTCDB/control01.ctl - modified
        Control File /u01/app/oracle/fast_recovery_area/TESTCDB/control02.ctl - modified
        Datafile /u01/app/oracle/oradata/TESTCDB/system01.db - dbid changed
        Datafile /u01/app/oracle/oradata/TESTCDB/sysaux01.db - dbid changed
        Datafile /u01/app/oracle/oradata/TESTCDB/undotbs01.db - dbid changed
        Datafile /u01/app/oracle/oradata/TESTCDB/pdbseed/system01.db - dbid changed
        Datafile /u01/app/oracle/oradata/TESTCDB/pdbseed/sysaux01.db - dbid changed
        Datafile /u01/app/oracle/oradata/TESTCDB/users01.db - dbid changed
        Datafile /u01/app/oracle/oradata/TESTCDB/pdbseed/undotbs01.db - dbid changed
        Datafile /u01/app/oracle/oradata/TESTCDB/ORCLPDB1/system01.db - dbid changed
        Datafile /u01/app/oracle/oradata/TESTCDB/ORCLPDB1/sysaux01.db - dbid changed
        Datafile /u01/app/oracle/oradata/TESTCDB/ORCLPDB1/undotbs01.db - dbid changed
        Datafile /u01/app/oracle/oradata/TESTCDB/ORCLPDB1/users01.db - dbid changed
        Datafile /u01/app/oracle/oradata/TESTCDB/ORCLPDB1/example01.db - dbid changed
        Datafile /u01/app/oracle/oradata/TESTCDB/temp01.db - dbid changed
        Datafile /u01/app/oracle/oradata/TESTCDB/pdbseed/temp012020-07-14_23-10-41-107-PM.db - dbid changed
        Datafile /u01/app/oracle/oradata/TESTCDB/ORCLPDB1/temp01.db - dbid changed
        Control File /u01/app/oracle/oradata/TESTCDB/control01.ctl - dbid changed
        Control File /u01/app/oracle/fast_recovery_area/TESTCDB/control02.ctl - dbid changed
        Instance shut down

    Database ID for database TESTCDB changed to 3425699846.
    All previous backups and archived redo logs for this database are unusable.
    Database is not aware of previous backups and archived logs in Recovery Area.
    Database has been shutdown, open database with RESETLOGS option.
    Succesfully changed database ID.
    DBNEWID - Completed succesfully.


    Since the database identifier has been changed, we have to open the database with resetlogs.

    [oracle@test ~]$ sqlplus / as sysdba
    ...
    Connected to an idle instance.

    SQL> startup mount
    ORACLE instance started.
    ...
    Database mounted.
    SQL> alter database open resetlogs;

    Database altered.


    A new DBID now service the database.

    SQL> select name, dbid from v$database;

    NAME            DBID
    --------- ----------
    TESTCDB   
    3425699846


    Done!


    SQL Queries for Goldengate Replications

      set linesize 200 set pagesize 100 set trimspool on column table_owner format a25 heading 'TABLE_OWNER' column tabl...