Category Archives: 12c

Oracle 12c – Secure file LOBs

In Oracle 12c SecureFiles is now the default storage of LOB when the COMPATIBLE parameter is set to 12.1 or higher.  SecureFiles gives better performance than BasicFiles for unstructured objects.  The following enhancements have been made to SecureFiles:

 

  1. PDML Operations – parallel DML operations for non-partitioned tables containing SecureFile LOB columns, table cannot contain BasicFile LOB columns. Operations which can use parallelism include:
    1. insert
    2. insert as select
    3. create table as select
    4. delete
    5. update
    6. merger (conditional update and insert)
    7. multi-table insert
    8. SQL*Loader
    9. Import/Export
  2. LogMiner – LogMiner now fully supports SecureFiles LOBs (deduplication of SecureFile LOB SecureFile Database File System (DBFS). Only SQL_REDO columns are filled in SecureFile LOB, SQL_UNDO is not used.

 

 

Larry Catt

OCP

Oracle 12c – Flashback Transaction Query

Flashback Transaction Query is used to retrieve metadata and historical data for single and all transactions in a time interval from a static data dictionary view FLASHBACK_TRANSACTION_QUERY.

The FLASHBACK_TRANSACTION_QUERY has a column UNDO_SQL which is the opposite of DML which caused the change.  You can use the DBMS_FLASHBACK.TRANSACTION_BACKOUT procedure to roll back transaction and dependent transactions.   This procedure does not commit the rollback but temporarily holds the rollback until a manual commit is made.  To perform the flashback transaction query the database must be in archivelog mode and supplemental logging must be enabled with command:  ALTER DATABASE ADD SUPPLEMENTAL LOG DATA;

 

For a user to use the flashback query the admin must grant following.

  1. Grant flashback to user.
  2. Grant select privileges on objects.
  3. To allow queries on all tables grant FLASHBACK ANY TABLE privilege.
  4. Grant SELECT ANY TRANSACTION privilege.
  5. Must have SELECT, UPDATE, DELETE, INSERT privilege on that table.
  6. Execute privilege on DBMS_FLASHBACK package.

 

This article details setting up flashback transactions for your database, granting user scott the appropriate privileges, and performing flashback.

 

  1. Logon to your SQLPLUS as sysdba.

 

[oracle@linux2 flash_recovery_area]$ sqlplus / as sysdba

 

SQL*Plus: Release 12.1.0.2.0 Production on Fri Jan 6 08:25:35 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. Verify that the database is in archivelog mode, if not switch to archive log mode.

 

SQL> archive log list

Database log mode              Archive Mode

Automatic archival             Enabled

Archive destination            USE_DB_RECOVERY_FILE_DEST

Oldest online log sequence     2708

Next log sequence to archive   2710

Current log sequence           2710

SQL>

 

  1. Issue the command ‘ ALTER DATABASE ADD SUPPLEMENTAL LOG DATA;’

 

SQL> ALTER DATABASE ADD SUPPLEMENTAL LOG DATA;

Database altered.

SQL>

 

  1. To allow queries on all tables grant FLASHBACK ANY TABLE privilege.

 

SQL> grant flashback any table to scott;

Grant succeeded.

SQL>

 

  1. Grant SELECT ANY TRANSACTION privilege.

 

SQL> grant select any transaction to scott;

Grant succeeded.

SQL>

 

  1. Execute privilege on DBMS_FLASHBACK package.

 

SQL> grant execute on dbms_flashback to scott;

Grant succeeded.

SQL>

 

  1. Logon as the user scott.

 

SQL> connect scott/password

Connected.

SQL>

 

  1. Create the test table fb_test.

 

create table fb_test(fname varchar2(30), amt number);

SQL> create table fb_test(fname varchar2(30), amt number);

Table created.

SQL>

 

  1. Insert single record into fb_test.

 

insert into scott.fb_test(fname,amt) values(‘Larry’,111);

commit;

 

 

SQL> insert into scott.fb_test(fname,amt) values(‘Larry’,111);

commit;

1 row created.

SQL>

Commit complete.

SQL>

 

  1. Update single record and commit;

 

update scott.fb_test set amt=222 where fname=’Larry’;

commit;

 

 

SQL> update scott.fb_test set amt=222 where fname=’Larry’;

commit;

1 row updated.

SQL>

Commit complete.

SQL>

 

 

  1. Select value from scott.fb_test.

 

SQL> select * from scott.fb_test;

FNAME                                 AMT

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

Larry                                 222

SQL>

 

  1. Query flashback_transaction_query for transactions against scott.fb_test.

 

SQL> select operation, undo_sql  from flashback_transaction_query

where table_name=’FB_TEST’;  2

OPERATION

——————————–

UNDO_SQL

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

INSERT

delete from “SCOTT”.”FB_TEST” where ROWID = ‘AAAXaKAAGAAALUdAAA’;

UPDATE

update “SCOTT”.”FB_TEST” set “AMT” = ‘111’ where ROWID = ‘AAAXaKAAGAAALUdAAA’;

SQL>

 

  1. You can now execute the UNDO_SQL column to rewind the update statement.

 

SQL> update “SCOTT”.”FB_TEST” set “AMT” = ‘111’ where ROWID = ‘AAAXaKAAGAAALUdAAA’;

1 row updated.

SQL> commit;

Commit complete.

SQL>

 

  1. For a more complex set of updates impacting muptiple objects, you would use the dbms_flashback.transaction_backout procedure.

 

  1. This completes flashback transaction query.

 

 

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 – Valid Time Temporal Rules

In Oracle 12c Valid Time Temporal functionality to define a start and stop time where the data is valid.   This article covers the basic of Valid Time Temporal rules for implementation

Temporal Validity

  1. Valid time dimension is placed on a table for each row.
  2. Two hidden columns are added to table definition.
  3. When querying the table, rows will be displayed regardless of temporal validity, unless you filter based on these two columns.
  4. Temporal Validity has no effect on storage or performance.
  5. It provides a new filter capability only.
  6. Provides a range of time for each row when the data is valid.
  7. Date range of validity can be set by user or application.
  8. Concepts of Temporal Validity”
    1. VALID TIME – This is a user-defined representation of time. Examples of a valid time include project start and finish dates, and employee hire and termination dates.
    2. Tables with valid-time semantics — These tables have one or more dimensions of user-defined time, each of which has a start and an end.
    3. Valid-time flashback queries — This is the ability to do as-of and versions queries using a valid-time dimension.
  9. Valid-time periods require pairs of date-time: start and end.

 

 

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

EM Express 12c Opening Page

Oracle EM Express Opening Page provides the ability to view a snapshot of current database instance.  This article covers the general layout of EM Express Opening Page and its functional usage.

 

  1. Logon the EM Express as an administrative user.   In this case we will use the URL:  https://10.30.15.63:5500/em.   This indicates the EM Express is installed on server 10.30.15.63, listening on port 5500 (which is the default).  NOTE:  You may receive a certificate warning but select continue to site option.   Enter your sysdba credentials at the sign in page and mark the check box as sysdba, normally this is the user name and password you used to create the database.

  1. The initial page will give you a summary of the current setup and state of the oracle database EM Express is attached to.

  1. There are six drop down views which can be minimized: Status, Performance, Incidents, Resources, Running Jobs, and SQL Monitor

 

  1. Status drop down give the general information about the database being monitored.

  1. Performance drop down give the current activity on the database instance by Activity Class or Services.

  1. Incidents drop down give all errors and warning that have occurred for administrative review.

  1. Resources drop down give a snap shot of the resources currently being used by the database instance.

  1. Running Jobs drop down give lists all jobs currently executing in the database.

  1. SQL Monitor drop down give the currently executing SQL statements against the database instance.

 

This article summarized the feature and use of the Opening Page of Oracle 12c EM Express.

 

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 -RMAN Backup Overview

Oracle provides the Recovery Manager utility (RMAN) to perform two types of database backups: Image Backup and Backup Set.    RMAN command BACKUP AS COPY command creates an image copy or bit for bit copy of the data files, archived redo log and controlfiles.

 

RMAN> BACKUP AS COPY DEVICE TYPE DISK DATABASE;

 

You can set the default backup to image copy with CONFIGURE DEVICE TYPE command

 

RMAN> CONFIGURE DEVICE TYPE DISK BACKUP TYPE TO COPY;

 

Backup sets are the other type of RMAN backups, each backup set has one or more binary files called backup pieces, in proprietary format that can be restored by RMAN.  You can limit the size of size of backup pieces by the MAXPIECESIZE option.   Use the RMAN command BACKUP AS BACKUPSET to create backup copy of database.

 

RMAN> BACKUP AS BACKUPSET DATABASE.

 

You can set the default backup to backup set with the CONIFGURE DEVICE TYPE command.

 

RMAN> CONFIGURE DEVICE TYPE DISK BACKUP TYPE TO BACKUPSET;

 

You can backup the entire database with the command:

 

RMAN> BACKUP DATABASE;

 

Add PLUS ARCHIVELOGS clause will cause a log switch that allows for full media recovery to the point of starting the backup.

 

RMAN> BACKUP DATABASE PLUS ARCHIVELOG;

 

Incremental Backups are part of a backup set that only contains changes to the database since the last full backup.   The benefit of an incremental backup is size of the backup and time required to tack the backup.   Incremental Backups are only good if combined with the last full backup and any incremental backup between the last full backup.

 

You can create an incremental backup with the RMAN command BACKUP INCREMENTAL in three ways

 

Level 0 – Identical to full back

Level 1 Differential – backups all changed blocks since most recent incremental backup.

Level 1 Cumulative – backups all changed block since most recent Level 0 incremental backup

 

Restoring incremental backup use level 0 at start and apply level 1 cumulative or all differential.

 

Example of incremental Level 1:

 

RMAN> backup incremental level 1 cumulative database;

 

RMAN> backup incremental level 1 database;

 

 

Larry Catt

OCP

Oracle 12c – Flashback Technology Overview

Flashback table – by default when a table is dropped oracle does not immediately remove the space, but renames it and places the table and associated objects in recycle bin.   This allows it to be recovered at a later time.

 

The recycle bin is a data dictionary table that contains info needed to recover dropped tables.  Original table stays in place and occupies same space until purged or database needs space for storage.

 

tablespaces are not placed in recycle bin and once dropped are gone.   All tables in that tablespace are removed from recycle bin if they have previously been dropped.

 

Recycle bin can be disabled with recyclebin initialization parameter.

 

FLASHBACK TABLE ….  TO BEFORE DROP;    statement is used to recover tables from recyclebin.  You must use the system generated recyclebin name.  You can rename the table with RENAME clause during recovery.  The USER_RECYCLEBIN view can be used to find the system generated recyclebin name.

example:

 

FLASHBACK TABLE test2_bak TO BEFORE DROP RENAME test2;

 

Larry Catt

OCP