Prepared a concept map for me to understand OEM 12c monitoring concepts and framework:
Everything Changes
1 week ago
SQL>@test SQL>set echo on SQL>drop table t; Table dropped. SQL>create table t(x number, y number, z number); Table created. SQL> SQL>insert into t values(1,1,2); 1 row created. SQL>insert into t values(1,1,3); 1 row created. SQL>insert into t values(2,1,1); 1 row created. SQL> SQL> SQL>set autotrace on SQL>-- approach 1 SQL> SQL>select x, y, z 2 from t 3 where 4 exists ( select 1 from 5 ( select y, max(z) mz 6 from t 7 group by y 8 ) zz 9 where t.y=zz.y 10 and t.z=zz.mz 11 ) 12 ; X Y Z ---------- ---------- ---------- 1 1 3 1 row selected. Execution Plan ---------------------------------------------------------- Plan hash value: 3359768323 ----------------------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | ----------------------------------------------------------------------------- | 0 | SELECT STATEMENT | | 3 | 117 | 5 (20)| 00:00:01 | |* 1 | FILTER | | | | | | | 2 | TABLE ACCESS FULL | T | 3 | 117 | 2 (0)| 00:00:01 | |* 3 | FILTER | | | | | | | 4 | HASH GROUP BY | | 1 | 26 | 3 (34)| 00:00:01 | |* 5 | TABLE ACCESS FULL| T | 1 | 26 | 2 (0)| 00:00:01 | ----------------------------------------------------------------------------- Predicate Information (identified by operation id): --------------------------------------------------- 1 - filter( EXISTS (SELECT /*+ */ 0 FROM "T" "T" WHERE "Y"=:B1 GROUP BY "Y",:B2 HAVING MAX("Z")=:B3)) 3 - filter(MAX("Z")=:B1) 5 - filter("Y"=:B1) Note ----- - dynamic sampling used for this statement Statistics ---------------------------------------------------------- 78 recursive calls 0 db block gets 38 consistent gets 0 physical reads 0 redo size 270 bytes sent via SQL*Net to client 247 bytes received via SQL*Net from client 2 SQL*Net roundtrips to/from client 0 sorts (memory) 0 sorts (disk) 1 rows processed SQL> SQL>-- approach 2 SQL> SQL> SQL>select x,y,z from 2 ( 3 select x,y, z, max(z) over (partition by y) mz 4 from t 5 ) 6 where z=mz 7 ; X Y Z ---------- ---------- ---------- 1 1 3 1 row selected. Execution Plan ---------------------------------------------------------- Plan hash value: 2206009079 ---------------------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | ---------------------------------------------------------------------------- | 0 | SELECT STATEMENT | | 3 | 156 | 3 (34)| 00:00:01 | |* 1 | VIEW | | 3 | 156 | 3 (34)| 00:00:01 | | 2 | WINDOW SORT | | 3 | 117 | 3 (34)| 00:00:01 | | 3 | TABLE ACCESS FULL| T | 3 | 117 | 2 (0)| 00:00:01 | ---------------------------------------------------------------------------- Predicate Information (identified by operation id): --------------------------------------------------- 1 - filter("Z"="MZ") Note ----- - dynamic sampling used for this statement Statistics ---------------------------------------------------------- 4 recursive calls 0 db block gets 7 consistent gets 0 physical reads 0 redo size 272 bytes sent via SQL*Net to client 247 bytes received via SQL*Net from client 2 SQL*Net roundtrips to/from client 1 sorts (memory) 0 sorts (disk) 1 rows processedApproach 1 is essetially used in a query in one of our production databases that causes performance issue. I suggested we re-write the query using approach 2. My test results of the production-like query show that bad query needs 2M consistent gets to get 6382 rows out while the re-written query needs only about 6k.
SQL> select * from BOD_OTHR_SERIAL_ACTIVITY_I8400 I8400 2 where 3 (I8400.DVTQ_ACCT_NUM = 'A145779917' OR ( 4 I8400.UJTJPM_CUSTOMER_ID = '' AND I8400.UJTJPM_ACCOUNT_ID = '' 5 )) 6 ; Execution Plan ---------------------------------------------------------- Plan hash value: 972526864 ------------------------------------------------------------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | ------------------------------------------------------------------------------------------------------------------- | 0 | SELECT STATEMENT | | 578K| 170M| 161K (11)| 00:05:17 | | 1 | TABLE ACCESS BY INDEX ROWID | BOD_OTHR_SERIAL_ACTIVITY_I8400 | 578K| 170M| 161K (11)| 00:05:17 | | 2 | BITMAP CONVERSION TO ROWIDS | | | | | | | 3 | BITMAP OR | | | | | | | 4 | BITMAP CONVERSION FROM ROWIDS| | | | | | |* 5 | INDEX RANGE SCAN | IX_I8400_04 | | | 1 (0)| 00:00:01 | | 6 | BITMAP CONVERSION FROM ROWIDS| | | | | | |* 7 | INDEX RANGE SCAN | IX_I8400_07 | | | 3 (0)| 00:00:01 | ------------------------------------------------------------------------------------------------------------------- Predicate Information (identified by operation id): --------------------------------------------------- 5 - access("I8400"."UJTJPM_CUSTOMER_ID"='' AND "I8400"."UJTJPM_ACCOUNT_ID"='') 7 - access("I8400"."DVTQ_ACCT_NUM"='A145779917')
SQL> alter session set "_b_tree_bitmap_plans"=false; Session altered.
SQL> select * from BOD_OTHR_SERIAL_ACTIVITY_I8400 I8400 2 where 3 (I8400.DVTQ_ACCT_NUM = 'A145779917' OR ( 4 I8400.UJTJPM_CUSTOMER_ID = '' AND I8400.UJTJPM_ACCOUNT_ID = '' 5 )) 6 ; Execution Plan ---------------------------------------------------------- Plan hash value: 7978316 --------------------------------------------------------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | --------------------------------------------------------------------------------------------------------------- | 0 | SELECT STATEMENT | | 2 | 618 | 9 (0)| 00:00:01 | | 1 | CONCATENATION | | | | | | | 2 | TABLE ACCESS BY INDEX ROWID| BOD_OTHR_SERIAL_ACTIVITY_I8400 | 1 | 309 | 6 (0)| 00:00:01 | |* 3 | INDEX RANGE SCAN | IX_I8400_07 | 1 | | 4 (25)| 00:00:01 | |* 4 | TABLE ACCESS BY INDEX ROWID| BOD_OTHR_SERIAL_ACTIVITY_I8400 | 1 | 309 | 3 (0)| 00:00:01 | |* 5 | INDEX RANGE SCAN | IX_I8400_04 | 1 | | 2 (50)| 00:00:01 | --------------------------------------------------------------------------------------------------------------- Predicate Information (identified by operation id): --------------------------------------------------- 3 - access("I8400"."DVTQ_ACCT_NUM"='A145779917') 4 - filter(LNNVL("I8400"."DVTQ_ACCT_NUM"='A145779917')) 5 - access("I8400"."UJTJPM_CUSTOMER_ID"='' AND "I8400"."UJTJPM_ACCOUNT_ID"='')
SQL> select count(*) from BOD_OTHR_SERIAL_ACTIVITY_I8400 I8400 2 where 3 (I8400.CUST_ACCT_NUM = 'A145779917' OR ( 4 I8400.UJTJPM_CUSTOMER_ID = '' AND I8400.UJTJPM_ACCOUNT_ID = '' 5 )) 6 ; COUNT(*) ---------- 1 1 row selected.
(1) At primary:
alter tablespace dbaets_data add datafile '/db2/u01/oradata/ettdb/dbaets_data_02.dbf' size 500M;
(2) At standby, query v$datafile
NAME SIZE_M
------------------------------------------------- -------
/db2st2/u01/oradata/etsdb/system01.dbf 500
/db2st2/u01/oradata/etsdb/sysaux01.dbf 2048
/db2st2/u01/oradata/etsdb/undotbs01.dbf 271
/db2st2/u01/oradata/etsdb/users01.dbf 500
/db2st2/u01/oradata/etsdb/xdb01.dbf 1024
/db2st2/u01/oradata/etsdb/dbaets_data_01.dbf 500
/apps/opt/oracle/product/11.2.0/dbs/UNNAMED00007 0
(3) At standby, issue 'ALTER DATABAE CREATE DATAFILE AS'
ALTER DATABASE CREATE DATAFILE '/apps/opt/oracle/product/11.2.0/dbs/UNNAMED00007' AS '/db2st2/u01/oradata/etsdb/dbaets_data_02.dbf';
(4) At standby, query v$datafile again:
NAME SIZE_M
-------------------------------------------------- ----------
/db2st2/u01/oradata/etsdb/system01.dbf 500
/db2st2/u01/oradata/etsdb/sysaux01.dbf 2048
/db2st2/u01/oradata/etsdb/undotbs01.dbf 271
/db2st2/u01/oradata/etsdb/users01.dbf 500
/db2st2/u01/oradata/etsdb/xdb01.dbf 1024
/db2st2/u01/oradata/etsdb/dbaets_data_01.dbf 500
/db2st2/u01/oradata/etsdb/dbaets_data_02.dbf 500
Case 2 - STANDBY_FILE_MANAGEMENT set to AUTO, but file cannot be created due to other error
NAME TYPE VALUE ------------------------------------ ----------- ------------------------------ db_file_name_convert string /db2st2/u01/oradata/etsdb, /db 2/u01/oradata/ettdbThis is not in the correct order as at standby site the path is '/db2st2/u01/oradata/etsdb' whereas '/db2/u01' does not exist.
ops$oracle@ETSDB> alter tablespace dbaets_data add datafile '/db2/u01/oradata/ettdb/dbaets_data_03.dbf' size 100M; Tablespace altered.In the alert log file of the standby database, it can be seen the file is not created and managed recovery process (MRP0) is terminated:
Media Recovery Log /db2st2/arch/1_1115_790089239.dbf WARNING: File being created with same name as in Primary Existing file may be overwritten Errors in file /apps/opt/oracle/admin/etsdb/diag/rdbms/etsdb/etsdb/trace/etsdb_pr00_8554.trc: ORA-01119: error in creating database file '/db2/u01/oradata/ettdb/dbaets_data_03.dbf' ORA-27054: NFS file system where the file is created or resides is not mounted with correct options SVR4 Error: 13: Permission denied File #8 added to control file as 'UNNAMED00008'. Originally created as: '/db2/u01/oradata/ettdb/dbaets_data_03.dbf' Recovery was unable to create the file as: '/db2/u01/oradata/ettdb/dbaets_data_03.dbf' MRP0: Background Media Recovery terminated with error 1274 Errors in file /apps/opt/oracle/admin/etsdb/diag/rdbms/etsdb/etsdb/trace/etsdb_pr00_8554.trc: ORA-01274: cannot add datafile '/db2/u01/oradata/ettdb/dbaets_data_03.dbf' - file could not be created Managed Standby Recovery not using Real Time Apply Recovery interrupted! Recovery stopped due to failure in applying recovery marker (opcode 17.30). Datafiles are recovered to a consistent state at change 12910838021570 but controlfile could be ahead of datafiles.
MRP0: Background Managed Standby Recovery process started (etsdb) started logmerger process Tue Apr 08 16:43:35 2014 Managed Standby Recovery starting Real Time Apply MRP0: Background Media Recovery terminated with error 1111 Errors in file /apps/opt/oracle/admin/etsdb/diag/rdbms/etsdb/etsdb/trace/etsdb_pr00_10330.trc: ORA-01111: name for data file 8 is unknown - rename to correct file ORA-01110: data file 8: '/apps/opt/oracle/product/11.2.0/dbs/UNNAMED00008' ORA-01157: cannot identify/lock data file 8 - see DBWR trace file ORA-01111: name for data file 8 is unknown - rename to correct file ORA-01110: data file 8: '/apps/opt/oracle/product/11.2.0/dbs/UNNAMED00008' Managed Standby Recovery not using Real Time Apply Recovery Slave PR00 previously exited with exception 1111 MRP0: Background Media Recovery process shutdown (etsdb) Completed: ALTER DATABASE RECOVER MANAGED STANDBY DATABASE USING CURRENT LOGFILE DISCONNECT
SQL> alter system set standby_file_management=manual; System altered. SQL> alter database create datafile '/apps/opt/oracle/product/11.2.0/dbs/UNNAMED00008' as '/db2st2/u01/oradata/etsdb/dbaets_data_03.dbf'; Database altered. SQL> alter system set standby_file_management=auto; System altered.Case 3 STANDBY_FILE_MANAGEMENT set to AUTO and DB_FILE_NAME_CONVERT is correct
ops$oracle@ETSDB> alter tablespace dbaets_data add datafile '/db2/u01/oradata/ettdb/dbaets_data_04.dbf' size 100M; Tablespace altered.
Tue Apr 08 16:56:22 2014
ALTER DATABASE RECOVER MANAGED STANDBY DATABASE USING CURRENT LOGFILE DISCONNECT
Attempt to start background Managed Standby Recovery process (etsdb)
Tue Apr 08 16:56:22 2014
MRP0 started with pid=33, OS id=12229
MRP0: Background Managed Standby Recovery process started (etsdb)
started logmerger process
Tue Apr 08 16:56:27 2014
Managed Standby Recovery starting Real Time Apply
Parallel Media Recovery started with 4 slaves
Waiting for all non-current ORLs to be archived...
All non-current ORLs have been archived.
Media Recovery Log /db2st2/arch/1_1115_790089239.dbf
Media Recovery Log /db2st2/arch/1_1116_790089239.dbf
Media Recovery Log /db2st2/arch/1_1117_790089239.dbf
Completed: ALTER DATABASE RECOVER MANAGED STANDBY DATABASE USING CURRENT LOGFILE DISCONNECT
Recovery created file /db2st2/u01/oradata/etsdb/dbaets_data_04.dbf
Successfully added datafile 9 to media recovery
Datafile #9: '/db2st2/u01/oradata/etsdb/dbaets_data_04.dbf'
SQL> ALTER DATABASE FORCE LOGGING;
SQL> alter database add standby logfile '/db2st2/u01/oradata/etsdb/stby_redo01.rdo' size 100M;
alter system set LOG_ARCHIVE_CONFIG='DG_CONFIG=(etsdb,ettdb)';
alter system set LOG_ARCHIVE_DEST_1='LOCATION=/db2st2/arch VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=etsdalter system set LOG_ARCHIVE_DEST_2='SERVICE=ettdb LGWR ASYNC VALID_FOR=(online_LOGFILES, PRIMARY_ROLE) DB_UNIQUE_NAME=ettdb';
alter system set LOG_ARCHIVE_DEST_STATE_1=ENABLE;
alter system set FAL_SERVER=ettdb;
alter system set FAL_CLIENT=etsdb;
alter system set DB_FILE_NAME_CONVERT='/db2st2/u01/oradata/etsdb','/db2/u01/oradata/ettdb' scope=spfile;
alter system set LOG_FILE_NAME_CONVERT='/db2st2/u01/oradata/etsdb','/db2/u01/oradata/ettdb', '/db2st2/u02/oradata/etsdb','/db2/u02/oradata/ettdb' scope=spfile;
2. Ensure that the sql*net connectivity is working fine.
ettdb = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = standby_server)(PORT = 1523)) ) (CONNECT_DATA = (SERVICE_NAME = ettdb ) ) ) etsdb = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = primary_server)(PORT = 1521)) ) (CONNECT_DATA = (SERVICE_NAME = etsdb ) ) )Confirm that tnsping ettdb and tnsping etsdb work on both primary and standby sites
-- initettdb.ora DB_NAME=etsdb DB_UNIQUE_NAME=ettdb DB_BLOCK_SIZE=8192
% export ORACLE_SID=ettdb % sqlplus "/ as sysdba" SQL> startup nomount pfile=$ORACLE_HOME/dbs/initettdb.ora
duplicate target database for standby from active database spfile parameter_value_convert 'etsdb','ettdb' set db_unique_name='ettdb' set db_file_name_convert='/db2st2/u01/oradata/etsdb','/db2/u01/oradata/ettdb','/db2st2','/db2' set log_file_name_convert='/db2st2/u01/oradata/etsdb','/db2/u01/oradata/ettdb', '/db2st2/u02/oradata/etsdb','/db2/u02/oradata/ettdb' set control_files='/db2/u01/oradata/ettdb/control01.ctl' set log_archive_dest_1 = 'LOCATION=/db2/arch VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=ettdb' set log_archive_max_processes='5' set fal_client='ettdb' set fal_server='etsdb' set standby_file_management='AUTO' set log_archive_config='dg_config=(etsdb,ettdb)' set log_archive_dest_2='service=etsdb ASYNC valid_for=(ONLINE_LOGFILE,PRIMARY_ROLE) db_unique_name=etsdb' ;
SQL> alter database recover managed standby database cancel; SQL> alter database open read only; SQL> alter database recover managed standby database disconnect using current logfile; -- verify SQL> select name, db_unique_name, database_role, open_mode from v$database; NAME DB_UNIQUE_NAME DATABASE_ROLE OPEN_MODE --------- ------------------------------ ---------------- -------------------- ETSDB ettdb PHYSICAL STANDBY READ ONLY WITH APPLYtesting to confirm that standby db can be read and meanwhile redo logs are being applied:
in standby create table dbaets.t as select * from all_objects * ERROR at line 1: ORA-00604: error occurred at recursive SQL level 1 ORA-16000: database open for read-only access in primary 1* select thread#, max(sequence#) from v$log_history group by thread# SQL> / THREAD# MAX(SEQUENCE#) ---------- -------------- 1 1057 SQL> create table dbaets.t as select * from all_objects; Table created. SQL> alter system archive log current; System altered. SQL> select thread#, max(sequence#) from v$log_history group by thread# 2 ; THREAD# MAX(SEQUENCE#) ---------- -------------- 1 1058 in standby: SQL> select thread#, max(sequence#) from v$log_history group by thread#; THREAD# MAX(SEQUENCE#) ---------- -------------- 1 1058 SQL> select count(*) from dbaets.t; COUNT(*) ---------- 17855References: