Category Archives: Performance

Finding SCN for Oracle Database by Date and time

Oracle provides the function TIMESTAMP_TO_SCN to determine the database SCN number for a given time. This is very useful in performing multiple Oracle Administrative tasks. This procedure explains the use of this function to extract SCN.

1. Logon to Oracle Database server as the Oracle software owner and start SQLPLUS.

[root@linux2 etc]# su – oracle
Last login: Thu Jun 1 09:25:23 EST 2017 on pts/1
[oracle@linux2 ~]$
[oracle@linux2 ~]$ sqlplus / as sysdba

SQL*Plus: Release 12.1.0.2.0 Production on Thu Jun 1 13:47:01 2017

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

Connected to:
Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 – 64bit Production
With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options

SQL>

2. Determine Oracle SCN one hour ago by specifying sysdate-1/24

SQL> select timestamp_to_scn(sysdate-1/24) from dual;

TIMESTAMP_TO_SCN(SYSDATE-1/24)
——————————
5062307

SQL>

3. Determine Oracle SCN 1 day ago by specifying sysdate-1

SQL> select timestamp_to_scn(sysdate-1) from dual;

TIMESTAMP_TO_SCN(SYSDATE-1)
—————————
4975332

SQL>

4. Determine Oracle SCN 1 week ago by specifying sysdate-7

SQL> select timestamp_to_scn(sysdate-7) from dual;

TIMESTAMP_TO_SCN(SYSDATE-7)
—————————
4696226

SQL>

5. Determine Oracle SCN by specific date time by using the to_date() function with appropriate date mask.

SQL> select timestamp_to_scn(to_date(’25-MAY-2017 06:30:00′,’DD-MON-YYYY HH24:MI_SS’)) from dual;

TIMESTAMP_TO_SCN(TO_DATE(’25-MAY-201706:30:00′,’DD-MON-YYYYHH24:MI_SS’))
————————————————————————
4696226

SQL>

6. This completes the use of the function TIMESTAMP_TO_SCN.

Larry Catt
OCP

Oracle 12c – Database Replay

Database replay captures all external database calls made to system during capture period. This capture can be replayed against test system for the purpose of testing new software, evaluating bug fixes, or optimization of current code.   The capture includes all relevant information about the client request, such as SQL text bind values, transaction information.  Background activities and scheduler jobs are not captured.   Additional client requests that are not captured are:

 

  1. Direct path load SQL*Loader.
  2. Shared Server requests (MTS)
  3. Oracle Streams.
  4. Advance Replication streams.
  5. NON-PL/SQL based advance queuing(AQ)
  6. Oracle Call Interface (OCI) based object navigation.
  7. NON SQL-based object access.
  8. Distributed transactions.

 

 

It is best practice to restart database before capturing production workloads, to allow started transactions to complete or be rolled back and avoid partial captures.   By default all transactions by users are captured.  You can either filter by exclude or include user sessions but not both.  Use the DBMS_WORKLOAD_CAPTURE package ADD_FILTER and DELETE_FILTER for this purpose.

 

Have a well-defined starting point of capture with no user sessions active.  It is recommended to starting the database in RESTICTED mode and switching the database to unrestricted mode once workload capture beings.  Use DBMS_WORKLOAD_CAPTURE package START_CAPTURE and FINISH_CAPTURE.  DBMS_WORKLOAD_CAPTURE package EXPORT_AWR – allows you to get statistics from production workload machine.  You can use EM to monitor workload capture or the views DBA_WORKLOAD_CAPTURES and DBA_WORLOAD_FILTERS.

 

After workload is captured, you must preprocess the capture files prior to using them in replay.  This changes them into replay files and creates necessary meta data.  They can be replayed multiple times.  It is suggested to move captured files to another machine for preprocessing, which can be a very intensive process.  Use the package DBMS_WORKLOAD_REPLAY.PROCESS_CAPTURE to do the preprocessing of capture.

 

On replay to test system the database uses the external program called replay client.  Multiple replay clients may be necessary and all DML and SQL will be replayed just as in production.

 

This article details the capture, processing and replay of a simple table creation and data insert on a single database system.

 

  1. Logon your server as the oracle software owner.

 

[larry@linux2 ~]$ su – oracle

Password:

Last login: Thu Jan 12 09:03:22 EST 2017 on pts/1

Enter database to use:

1 – ORCL

2 – CDB1

Option >

1

[oracle@linux2 ~]$

 

  1. Logon to SQLPLUS as sysdba.

 

[oracle@linux2 ~]$ sqlplus / as sysdba

 

SQL*Plus: Release 12.1.0.2.0 Production on Fri Jan 13 07:05:13 2017

 

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

 

 

Connected to:

Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 – 64bit Production

With the Partitioning, OLAP, Advanced Analytics, Real Application Testing

and Unified Auditing options

 

SQL>

 

  1. Shutdown and restart the database with ‘startup force’ to terminate all transactions.

 

SQL> startup force

ORACLE instance started.

 

Total System Global Area  549453824 bytes

Fixed Size                  2926616 bytes

Variable Size             268437480 bytes

Database Buffers          272629760 bytes

Redo Buffers                5459968 bytes

Database mounted.

Database opened.

SQL>

 

 

  1. Exit out of SQLPLUS, create a directory for storage, and change permissions to 777. NOTE: A newly created empty directory should be used for REPLAY Capture.

 

SQL> exit

Disconnected from Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 – 64bit Production

With the Partitioning, OLAP, Advanced Analytics, Real Application Testing

and Unified Auditing options

[oracle@linux2 ~]$ mkdir /opt/app/sql_cap

[oracle@linux2 ~]$ chmod 777 /opt/app/sql_cap

[oracle@linux2 ~]$

 

  1. Log back into SQLPLUS as sysdba and create a directory object for capture operations. NOTE:  This directory should be empty.

 

[oracle@linux2 ~]$ sqlplus / as sysdba

 

SQL*Plus: Release 12.1.0.2.0 Production on Fri Jan 13 09:09:57 2017

 

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

 

 

Connected to:

Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 – 64bit Production

With the Partitioning, OLAP, Advanced Analytics, Real Application Testing

and Unified Auditing options

 

SQL>

SQL> create directory SQL_CAP as ‘/opt/app/sql_cap’;

 

Directory created.

 

SQL>

 

  1. Flush the shared_pool.

 

SQL> alter system flush shared_pool;

 

System altered.

 

SQL>

 

  1. Now begin the capture with DBMS_WORKLOAD_CAPTURE.START_CAPTURE procedure passing in the name and directory objects to be used.

 

SQL> execute DBMS_WORKLOAD_CAPTURE.START_CAPTURE(‘REPLAY_TEST’,’SQL_CAP’);

 

PL/SQL procedure successfully completed.

 

SQL>

 

 

  1. Now logon as the user scott/tiger, create a test table REPLAY_TEST, load the table with 100 records, and commit the transaction.

 

SQL> connect scott/tiger

Connected.

SQL> create table replay_test(col_a number,

col_b char(1));

  2

Table created.

 

SQL> declare

val_b char(1):=’a’;

val_a number:=0;

begin

while val_a<100

loop

insert into replay_test(col_a, col_b)

values(val_a, val_b);

val_a:=val_a+1;

if val_b=’z’

then

val_b:=’a’;

else

val_b:=chr(ascii(val_b) + 1);

end if;

end loop;

end;

/  2    3    4    5    6    7    8    9   10   11   12   13   14   15   16   17   18

 

PL/SQL procedure successfully completed.

 

SQL> commit;

 

Commit complete.

 

SQL>

 

  1. Exit SQLPLUS and reconnect as sysdba.

 

SQL> exit

Disconnected from Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 – 64bit Production

With the Partitioning, OLAP, Advanced Analytics, Real Application Testing

and Unified Auditing options

[oracle@linux2 ~]$ sqlplus / as sysdba

 

SQL*Plus: Release 12.1.0.2.0 Production on Fri Jan 13 09:14:43 2017

 

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

 

 

Connected to:

Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 – 64bit Production

With the Partitioning, OLAP, Advanced Analytics, Real Application Testing

and Unified Auditing options

 

SQL>

 

  1. Execute the DBMS_WORKLOAD_CAPTURE.FINISH_CAPTURE; procedure to stop the capture process.

 

SQL> execute DBMS_WORKLOAD_CAPTURE.FINISH_CAPTURE;

 

PL/SQL procedure successfully completed.

 

SQL>

 

  1. Now you have to process the capture by calling the procedure DBMS_WORKLOAD_REPLAY.PROCESS_CAPTURE(‘SQL_CAP’); and passing in the directory object where the capture is stored.

 

SQL> execute DBMS_WORKLOAD_REPLAY.PROCESS_CAPTURE(‘SQL_CAP’);

 

PL/SQL procedure successfully completed.

 

SQL>

 

  1. Because we are replaying this capture against the same database, we need to remove the objects and data inserted during the capture to remove any confusion.

 

SQL>  drop table scott.replay_test;

 

Table dropped.

 

SQL>

 

  1. Prepare the database for replay with the procedures DBMS_WORKLOAD_REPLAY.INITIALIZE_REPLAY and DBMS_WORKLOAD_REPLAY.PREPARE_REPLAY.

 

SQL> execute DBMS_WORKLOAD_REPLAY.INITIALIZE_REPLAY(‘REPLAY_TEST’,’SQL_CAP’);

 

PL/SQL procedure successfully completed.

 

SQL> execute DBMS_WORKLOAD_REPLAY.PREPARE_REPLAY;

 

PL/SQL procedure successfully completed.

 

SQL>

 

  1. Exit out of SQLPLUS and use the WRC utility to replay contents of your directory object.  NOTE:  You can also execute replay from inside of database with DBMS_WORKLOAD_REPLAY.START_REPLAY procedure.

 

wrc scott/tiger mode=replay replaydir=/opt/app/sql_cap

 

[oracle@linux2 ~]$ wrc scott/tiger mode=replay replaydir=/opt/app/sql_cap

 

Workload Replay Client: Release 12.1.0.2.0 – Production on Fri Jan 13 11:08:26 2017

 

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

 

 

Wait for the replay to start (11:08:26)

Replay client 1 started (11:08:39)

 

 

 

 

  1. In a second session of SQLPLUS as sysdba execute the procedure DBMS_WORKLOAD_REPLAY.START_REPLAY ();

 

SQL> execute DBMS_WORKLOAD_REPLAY.START_REPLAY ();

 

PL/SQL procedure successfully completed.

 

SQL>

 

  1. Select count(*) from scott.replay_test and see that the previous session has been re-executed.

 

SQL> select count(*) from scott.replay_test;

 

  COUNT(*)

———-

       100

 

SQL>

 

  1. Complete the transaction in the first command lines session with CTRL-C
  2. This completes simple example of database replay.

 

Larry Catt

OCP

Oracle 12c – DBMS_SPM – Creating SQL Plan

Oracle 12c provides the DBMS_SPM package for managing plan evolution.   This article demonstrates the creation of SQL Plan using the DBMS_SPM package.

 

 

  1. Logon to you database server as the oracle software owner and connect to SQLPLUS as sysdba.

 

[root@linux2 ~]# su – oracle

Last login: Tue Dec 27 07:53:43 EST 2016 on pts/2

Enter database to use:

1 – ORCL

2 – CDB1

Option >

1

[oracle@linux2 ~]$ sqlplus / as sysdba

 

SQL*Plus: Release 12.1.0.2.0 Production on Wed Dec 28 11:06:31 2016

 

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

 

 

Connected to:

Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 – 64bit Production

With the Partitioning, OLAP, Advanced Analytics, Real Application Testing

and Unified Auditing options

 

SQL>

  1. Create test table for SPM test and populate with values.

 

create table test_spm(val_1 number, val_2 char(1));

 

insert into  test_spm

select level, ‘a’ from dual connect by level <=100;

 

 

SQL> create table test_spm(val_1 number, val_2 char(1));

 

Table created.

 

SQL> insert into  test_spm

  2  select level, ‘a’ from dual connect by level <=100;

 

100 rows created.

 

SQL> commit;

 

Commit complete.

 

  1. Get the SQL PLAN name by setting the AUTOTRACE to TRACE and executing query against test table. SQL PLAN NAME in this example is SQL_PLAN_891rxd509mzp3eb1890ae.

SET AUTOTRACE TRACE

select * from test_spm;

 

SET AUTOTRACE TRACE

select * from test_spm;SQL> SQL>

 

100 rows selected.

 

 

Execution Plan

———————————————————-

Plan hash value: 1145642998

 

——————————————————————————

| Id  | Operation         | Name     | Rows  | Bytes | Cost (%CPU)| Time     |

——————————————————————————

|   0 | SELECT STATEMENT  |          |   100 |   500 |     2   (0)| 00:00:01 |

|   1 |  TABLE ACCESS FULL| TEST_SPM |   100 |   500 |     2   (0)| 00:00:01 |

——————————————————————————

 

Note

—–

   – dynamic statistics used: dynamic sampling (level=AUTO)

   – SQL plan baseline “SQL_PLAN_891rxd509mzp3eb1890ae” used for this statement

 

 

Statistics

———————————————————-

          0  recursive calls

          0  db block gets

         10  consistent gets

          0  physical reads

          0  redo size

       2816  bytes sent via SQL*Net to client

        617  bytes received via SQL*Net from client

          8  SQL*Net roundtrips to/from client

          0  sorts (memory)

          0  sorts (disk)

        100  rows processed

 

SQL>

 

  1. Set autotrace off.

 

set autotrace off;

SQL> set autotrace off;

 

  1. Get the SQL_HANDLE from PLAN_NAME out of the dba_sql_plan_baselines table.

 

SELECT sql_handle, plan_name, enabled, accepted

FROM   dba_sql_plan_baselines

WHERE  plan_name = ‘SQL_PLAN_891rxd509mzp3eb1890ae’;

 

 

SELECT sql_handle, plan_name, enabled, accepted

FROM   dba_sql_plan_baselines

WHERE  plan_name = ‘SQL_PLAN_891rxd509mzp3eb1890ae’;SQL> SQL>   2    3

 

SQL_HANDLE           PLAN_NAME                      ENA ACC

——————– —————————— — —

SQL_8486fd694099fea3 SQL_PLAN_891rxd509mzp3eb1890ae YES YES

 

SQL>

 

  1. Create an evolve task using the function CREATE_EVOLVE_TASK function with SQL_HANDLE from above.

 

SET SERVEROUTPUT ON

DECLARE

  l_return VARCHAR2(32767);

BEGIN

  l_return := DBMS_SPM.create_evolve_task(sql_handle => ‘SQL_8486fd694099fea3’);

  DBMS_OUTPUT.put_line(‘Task Name: ‘ || l_return);

END;

/

SQL> SET SERVEROUTPUT ON

DECLARE

  l_return VARCHAR2(32767);

BEGIN

  l_return := DBMS_SPM.create_evolve_task(sql_handle => ‘SQL_8486fd694099fea3’);

  DBMS_OUTPUT.put_line(‘Task Name: ‘ || l_return);

END;

/SQL>   2    3    4    5    6    7

Task Name: TASK_1049

 

PL/SQL procedure successfully completed.

 

SQL>

 

  1. Execute the evolve task using the DBMS_SPM.execute_evolve_task function and the TASK_NAME from above.

 

SET SERVEROUTPUT ON

DECLARE

  l_return VARCHAR2(32767);

BEGIN

  l_return := DBMS_SPM.execute_evolve_task(task_name => ‘TASK_1049’);

  DBMS_OUTPUT.put_line(‘Execution Name: ‘ || l_return);

END;

/

 

SQL> SET SERVEROUTPUT ON

DECLARE

  l_return VARCHAR2(32767);

BEGIN

  l_return := DBMS_SPM.execute_evolve_task(task_name => ‘TASK_1049’);

  DBMS_OUTPUT.put_line(‘Execution Name: ‘ || l_return);

END;

/SQL>   2    3    4    5    6    7

Execution Name: EXEC_1082

 

PL/SQL procedure successfully completed.

 

SQL>

 

  1. Report on the task outcome using the DBMS_SPM.report_evolve_task function and the TASK_NAME and EXECUTION_NAME from above.

 

SET LONG 1000000 PAGESIZE 1000 LONGCHUNKSIZE 100 LINESIZE 100

 

SELECT DBMS_SPM.report_evolve_task(task_name => ‘TASK_1049’, execution_name => ‘EXEC_1082’) AS output

FROM   dual;

 

SQL>

SET LONG 1000000 PAGESIZE 1000 LONGCHUNKSIZE 100 LINESIZE 100

 

SELECT DBMS_SPM.report_evolve_task(task_name => ‘TASK_1049’, execution_name => ‘EXEC_1082’) AS output

FROM   dual;SQL> SQL> SQL>   2

 

OUTPUT

—————————————————————————————————-

GENERAL INFORMATION SECTION

———————————————————————————————

 

 Task Information:

 ———————————————

 Task Name            : TASK_1049

 Task Owner           : SYS

 Execution Name       : EXEC_1082

 Execution Type       : SPM EVOLVE

 Scope                : COMPREHENSIVE

 Status               : COMPLETED

 Started              : 12/28/2016 15:07:14

 Finished             : 12/28/2016 15:07:14

 Last Updated         : 12/28/2016 15:07:14

 Global Time Limit    : 2147483646

 Per-Plan Time Limit  : UNUSED

 Number of Errors     : 0

———————————————————————————————

 

SUMMARY SECTION

———————————————————————————————

  Number of plans processed  : 0

  Number of findings         : 0

  Number of recommendations  : 0

  Number of errors           : 0

———————————————————————————————

SQL>

 

  1. Implement the recommendations in the task with the DBMS_SPM.implement_evolve_task function and the TASK_NAME from above.

 

SET SERVEROUTPUT ON

DECLARE

  l_return NUMBER;

BEGIN

  l_return := DBMS_SPM.implement_evolve_task(task_name => ‘TASK_1049’);

  DBMS_OUTPUT.put_line(‘Plans Accepted: ‘ || l_return);

END;

/

SQL>

SET SERVEROUTPUT ON

DECLARE

  l_return NUMBER;

BEGIN

  l_return := DBMS_SPM.implement_evolve_task(task_name => ‘TASK_1049’);

  DBMS_OUTPUT.put_line(‘Plans Accepted: ‘ || l_return);

END;

/SQL> SQL>   2    3    4    5    6    7

Plans Accepted: 0

 

PL/SQL procedure successfully completed.

 

SQL>

 

  1. Verify the change by querying the DBA_SQL_PLAN_BASELINES table witht eh SQL_HANDLE from above.

 

SELECT sql_handle, plan_name, enabled, accepted

FROM   dba_sql_plan_baselines

WHERE  sql_handle = ‘SQL_8486fd694099fea3’;

 

 

 

SQL> SELECT sql_handle, plan_name, enabled, accepted

FROM   dba_sql_plan_baselines

WHERE  sql_handle = ‘SQL_8486fd694099fea3’;

  2    3

SQL_HANDLE           PLAN_NAME                      ENA ACC

——————– —————————— — —

SQL_8486fd694099fea3 SQL_PLAN_891rxd509mzp3eb1890ae YES YES

 

SQL>

 

  1. This complets use of DBMS_SPM for creating SQL plan.

 

 

Larry Catt

OCP

Oracle 12c – Use Adaptive SQL Plan Management

SQL Plan Management (SPM) Evolve Advisor in Oracle 12c analyzes SQL plans which were not used during executions to determine if they would run better than accepted plans.  If the plan is determined to run better than the accepted plan it will be accepted, more than one plan can be accepted for give SQL statement.   This evaluation is executed during maintenance window when automatic SQL tuning is set to COMPREHENSIVE mode.  The evaluation can be run manually with DBMS_SPM package, SPM Evolve Advisor or the Automatic SQL Tuning advisor.  This can be set in EM or through DBMS_AUTO_TASK_ADMIN package.   This procedure show the setup of SPM.

 

 

  1. Logon to you database server as the oracle software owner and connect to SQLPLUS as sysdba.

 

[root@linux2 ~]# su – oracle

Last login: Tue Dec 27 07:53:43 EST 2016 on pts/2

Enter database to use:

1 – ORCL

2 – CDB1

Option >

1

[oracle@linux2 ~]$ sqlplus / as sysdba

SQL*Plus: Release 12.1.0.2.0 Production on Wed Dec 28 11:06:31 2016

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

 

Connected to:

Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 – 64bit Production

With the Partitioning, OLAP, Advanced Analytics, Real Application Testing

and Unified Auditing options

 

SQL>

 

  1. Execute the following block:

BEGIN

DBMS_AUTO_TASK_ADMIN.ENABLE ( client_name => ‘sql tuning advisor’,

operation => NULL,

window_name => NULL );

END;

/

 

 

SQL> BEGIN

DBMS_AUTO_TASK_ADMIN.ENABLE ( client_name => ‘sql tuning advisor’,

operation => NULL,

window_name => NULL );

END;

/

  2    3    4    5    6

PL/SQL procedure successfully completed.

 

SQL>

 

  1. Query dictionary to confirm:

 

SELECT client_name, status

FROM dba_autotask_client

WHERE client_name = ‘sql tuning advisor’;

CLIENT_NAME STATUS

——————– ——–

sql tuning advisor ENABLED

 

  1. Disable with DBMS_AUTO_TASK_ADMIN.DISABLE procedure.

 

 

  1. This completes overview of Adaptive SQL PLAN Management.

 

Larry Catt

OCP

Oracle 12c – SQL Tuning

Adaptive query optimization in 12c allows for changes to execution plan at run time and gathering of new information to generate better statistics.  The two aspects of Adaptive Query Optimization:

  1. Adaptive Plan – Improving the initial execution of query at run time.
  2. Adaptive Statistics – Gathering new statistics to improve future executions.

 

Adaptive Plans – allows optimizer to make decision on SQL at runtime and in mid execution.  It will actually make sub-plans and collect statistics to make final decision on execution.

  1. This may cause a difference in the EXPAIN PLAN command and the DBMS_XPLAN.DISPLAY_CURSOR where the EXPLAIN PLAN will show the initial plan execution and DISPLAY_CURSOR will show the final plan executed.
  2. In oracle 12c only Join and Parallel queries are supported of adaptive plans.
  3. You can actually see all plans tried with the DBMS_XPLAN function by using the ‘+adaptive’ parameter with the notation (-) against the id column of plan table.
  4. V$SQL view has new column IS_RESOLVED_ADAPTIVE_PLAN which show if SQL has an adaptive plan. If it ‘Y’ the statement has adaptive plan which has been used, if ‘N’ it has an adaptive plan that is not completed yet and if NULL it has no adaptive plan.
  5. INIT parameter OPTIMIZER_ADAPTIVE_REPORTING_ONLY is set to TRUE (default is FALSE) information on adaptive plan will be collected but not used. You can then use DBMS_XPLAN plan to view data with ‘+report”.

 

Adaptive Statistics:

Optimizer uses statistics in order to create good execution plans.  Re-optimization uses the execution of previous statements results to determine if the executed plan was optimal and adjusts plans for future execution in an iterative process.

Three types of re-optimization:

  1. Statistics Feedback – also known as cardinality feedback, it compares cardinality of estimated and actual executions. Storing the correct cardinality statistics and creates SQL plane directive for future use.
  2. Performance Feedback – Used to improve degree of parallelism for future SQL statements based on previous executions when Automatic Degree of Parallelism (AutoDOP) is enabled in adaptive mode.
  3. SQL plan directives – Is additional information used by optimizer to determine correct execution plans and are created on query expressions not SQL statements thus can be applied to multiple SQL statements. Multiple directives can be used for single SQL statement.  SQL directives are purged if not used in 53 days.  You can see directives in views:   DBA_SQL_PLAN_DIRECTIVES and DBA_SQL_PLAN_DIR_OBJECTS.

 

 

 

Partition table statistics – Two sets of statistics are gathered at the partition level and table level, in 12c the table level statistics are aggregated by partition level avoiding full table scan.

 

INCREMENTAL_STALENESS – preference setting in DBMS_STATS.SET_TABLE_PREFS allows you to determine when statistics on tables are stale by percentage of change with USE_STALE_PERCENT or locking statistics forcing their use regardless of how much change has occurred with USE_LOCKED_STATS.

 

Incremental statistics improved by EXCHANGE_PARTITION command allows you to statistics from non-partitioned table with those in a partition.  Prior to 12c you had to gather data on all partitions before using incremental global statistics.   Use the DBMS_STATS package preference of INCREMENTAL_LEVEL set to TABLE (the default is PARTITION) to use this EXCHANGE_PARTITION feature.

 

Concurrent Statistics – when global statistics gathering preference CONCURRENT is set, the Job Scheduler and Advance queuing gather states on table/partitions concurrently.  12c has optimized automatic statistics gathering by batching smaller jobs to run together.  When preference CONCURRENT is set to ALL or AUTOMATIC stats a gathered nightly.

 

 

Automatic column group detection – Gathering of statistics on columns used in filter predicates by estimating cardinality.   Determining columns to gather increased stats is determined by workload history.  Three step process determines Auto Column Group detection:

  1. Seed column usage – workload history via the DBMS_STATS.SEED_COL_USAGE procedure.
  2. Create the column groups – Use the DBMS_STATS.CREATE_EXTENDED_STATS function to id columns groups based on usage information gathered. Once identified extended statistics will be automatically generated.
  3. Regather statistics – Regather statistics for all tables identified for column stats extended.

 

 

Larry Catt

OCP

Oracle 12c – Explain Partitioning enhancements

Interval-Reference Partitioning –

The top partitioning strategy in 12c is interval-reference.   Partitions in the referenced partitioned table link back to interval partition in the parent table.  Any operation that transform interval partitions in conventional partition of the parent table will construct the corresponding transformation in child table and create partition in child table as necessary.     This type of partitioning gives better performance.   COMPATIBLE parameter must be set to 12.0.0.0 or higher to use.

 

Cascade Functionality –

The commands TRUNCATE Partition and EXCHANGE Partition in reference or interval-reference partitions cascade to references in child table.  Thus child table inherit changes to parent table, by default cascade options are disabled for compatibility purposes.   CASCADE option is provided for the ALTER TABLE EXCHANGE PARTITION and ALTET TABLE EXCHANGE SUBPARTITION SQL commands.  All foreign keys must be defined with ON DELETE CASCADE option.

 

Maintenance Operations on Multiple Partitions –

Oracle 12c allows you to do multiple tasks with single command, where partition names are now separated by commas.

  1. Add – multiple partitions and sub-partitions can be added with single add command.
  2. Drop – multiple partitions and sub-partitions can be dropped with single drop command.
  3. Truncate – ditto.
  4. Merge – multiple partitions specified with single INTO PARTITION clause.
  5. SPLIT – Single partition specified and INTO PARTITION clause can specify multiple partitions for division.

 

Online Move Partition –

Oracle 12c allows for DDL operation to move or redefine while DML operations continue. MOVE PARTITION clause of ALTER TABLE changes existing data through the creating new segments and dropping old.   However, MODIFY PARTITION clause of ALTER TABLE only changes future data.

MOVE PARTITION clause of ALTER TABLE can do the following:

  1. Re-cluster data and reduce fragmentation.
  2. Move a partition to another tablespace.
  3. Modify create-time attribute
  4. Compress data using table compression.

 

Larry Catt

OCP

Oracle 12c – Monitor performance

There are several methods to monitor database performance, but EM is probably the most frequent used today.  Oracle Enterprise Manager Cloud Control is designed to manage the entire Oracle environment: database, server, middleware, and more.  OEM Cloud control requires additional licensing, however EM Express is provide free with Enterprise editions.

 

EM Express can be used to manage a single Oracle 12c database and it is actually built into the database.  EM Express is a light weight management console and provides basic administrative tasks with minimal impact to database operations.  EM Express has no background processes and it gathers information from already existing database stores.  The Performance Hub of Express provides the following abilities:

  1. ASH Analytics.
  2. SQL Monitor
  3. ADDM
  4. Workload metrics.
  5. Resource usage
  6. See real-time and historic data.
  7. In historic mode AWR (Automatic Workload Repository) data is used.
  8. Performance Hub tabs are
    1. Summary – real-time mode
    2. Activity – ASH analytics both real-time and historic.
    3. Workload – info about Top SQL
    4. RAC – RAC specific metrics.
    5. Monitor SQL – current and historic SQL executions.
    6. ADDM – ADDM reports both real-time and historic
    7. Current ADDM findings – performance analysis of last 5 minutes.

 

 

Larry Catt

OCP

Oracle 12c – Explain Multi-process Multi-threaded Oracle architecture

Using 12c multithread mode, one Operating System process can support multiple Oracle processes running in DB.

Multithreaded mode is not enabled with a new 12c database by default, to enable multi-threaded mode, the parameter THREADED_EXECUTION must be set to TRUE and the database restarted.   Some OS processes will still support only one oracle thread, while other OS processes may support multiple Oracle processes.   This can be viewed in V$PROCESS view by identifying OS process ID for each oracle process.

When running in multi-threaded mode, you must have an administration account controlled by a password file.  If a password file is not in use starting the system in multi-threaded mode will result in the error ORA-01017 invalid username/password; logon denied.

Larry Catt

OCP

Oracle 12c – Explain Index enhancements for partitioned tables

Asynchronous Global Index Maintenance

In Oracle 12c the commands DROP PARTITION and TRUNCATE PARTITION only affects metadata.   The index maintenance is asynchronous now, thus it does not invalidate indexes on the partitions.   You then use UPDATE INDEXES commands to synch indexes during maintenance hours.    Limitations of asynchronous global index maintenance are:

  1. Only for heap tables.
  2. Object types in table not supported.
  3. Domain indexes not supported.
  4. Cannot be user SYS

 

SYS.PMO_DEFERRED_GIDX_MAINT_JOB –

Oracle 12c provides this Automatic scheduled job to execute at 0200 and it updates any indexes impacted by DROP PARTITION and TRUNCATE PARTITION commands.   This job can be executed anytime by DBMS_SCHEDULER.RUN_JOB.

 

Partial Indexes –

In Oracle 12c you can now create local and global indexes on subsets of partitions.  Partial indexes do not supported unique indexes and cannot enforce unique constraints.  By default, indexes are created as FULL indexes.   You create partial indexing using the INDEXING clause at the partition and sub-partition level.

 

ONLINE Move Partition –

In Oracle 12c, the ALTER TABLE …   MOVE PARTITION allows for DML operations to take place while executing.  During MOVE operation, global indexes are maintained and rebuilt later by scheduler job.

 

 

Larry Catt

OCP

Oracle 12c – Use Resource Manager to manage resources

Oracle Database Resource Manager is designed to optimize resource allocation among concurrent database sessions.   It prevents from the OS making resource decisions during high overhead periods without awareness of database needs.  Resource Manager gives the database more control over resource allocation and gives the ability to place sessions into groups and allocated resources to those groups, through resource plans.    Oracle 12c comes with the following Resource Plans by default:

  • DEFAULT_MAINTENANCE_PLAN – default plan for maintenance windows.
  • DEFAULT_PLAN – Default gives priority to SYS_GROUP and gives minimal resources to maintenance and diagnostics operations.
  • DSS_PLAN – for data warehouse gives priority to DDS queries and less to non-DDS and ETL operations.
  • ETL_CRITICAL_PLAN – for data warehouse gives priority to ETL over DDS.
  • INTERNAL_QUIESCE – quiescing the database, must be done manually with QUIESCE command.
  • MIXED_WORKLOAD_PLAN – prioritized interactive processes over batch.

Three elements of Resource Management are:

  • Resource Consumer Group – group of sessions based on resource needs.
  • Resource Plan – directives that detail how resources are allocated to group.
  • Resource Plan Directive – Associates resource consumer group with a particular plan and how resources are allocated to consumer group.

Resource plan directives can limit CPU and I/O for sessions in the group.   This is done by a processes call switching, which specifies an action to take when a call exceeds the limit.  Resource plan directive attribute SWITCH_GROUP determines which action to take.  If the attribute is a consumer group name action 1 will be taken, if the attribute is KILL_SESSION action 2, and if attribute is CANCEL_SQL action 3.

The possible actions are:

  • Session is switched to a consumer group with lower resource allocation.
  • Session is killed.
  • Sessions current SQL is aborted.

Attributes which control I/O and CPU are as follow:   NOTE: unlimited means no limit.

  • SWITCH_TIME – CPU time in seconds before switch
  • SWITCH_IO_MEGABYTES – amount of I/O read and writes before switch.
  • SWITCH_IO_REQS – number of I/O requests before switch.

Two attributes that can modify behavior of resource plan switching:

  • SWITCH_ESTIMATE – If TRUE – database estimate execution time of each call. if it exceeds SWITCH_TIME attribute, the session is moved to    Default is FALSE.
  • SWITCH_FOR_CALL – If TRUE – session switched because of exceeding resource is returned to original group once completed. Default is NULL.

 

Larry Catt

OCP