Flashback Data Archive in #Oracle 12c

This article highlights some 12c changes of Flashback Data Archive (FDA). See here for an introduction. Remarkably, the feature is now included in all editions. I will focus here on the 12c enhancement that an application can be registered to FDA. That has two major benefits:

1. FDA can be turned on and off for all tables of that application with one command

2. Protection (better than READ ONLY) can be turned on and off for all tables of that application with one command

The playing field:

SQL> select * from v$version;

BANNER                                                                               CON_ID
-------------------------------------------------------------------------------- ----------
Oracle Database 12c Enterprise Edition Release 12.1.0.1.0 - 64bit Production              0
PL/SQL Release 12.1.0.1.0 - Production                                                    0
CORE    12.1.0.1.0      Production                                                        0
TNS for Linux: Version 12.1.0.1.0 - Production                                            0
NLSRTL Version 12.1.0.1.0 - Production                                                    0
SQL> grant dba to quaid identified by quaid;

Grant succeeded.

SQL> connect quaid/quaid
Connected.
SQL> create tablespace flatbs datafile '/home/oracle/prima/flatbs01.dbf' size 50m;

Tablespace created.

SQL> create table t1 as select * from dual;

Table created.

SQL> create table t2 as select * from dual;

Table created.

SQL> create flashback archive fla_10y tablespace flatbs retention 10 year;

Flashback archive created.

So far no new feature as the same can be done with 11g. No I register the application – that is just declarative:

SQL> begin
     dbms_flashback_archive.register_application
     (application_name=>'MYAPP',
     flashback_archive_name=>'FLA_10Y');
     end;
     /  

PL/SQL procedure successfully completed.

Now I add all tables of that application:

SQL> begin
     dbms_flashback_archive.add_table_to_application
     (application_name=>'MYAPP',
     table_name=>'t1',
     schema_name=>'QUAID');
     end;
     /  

PL/SQL procedure successfully completed.

SQL> begin
     dbms_flashback_archive.add_table_to_application
     (application_name=>'MYAPP',
     table_name=>'t2',
     schema_name=>'QUAID');
     end;
     /  

PL/SQL procedure successfully completed.

I can now turn FDA on and off for all the tables with one command:

SQL> select table_name,status from user_flashback_archive_tables;

no rows selected

SQL> exec dbms_flashback_archive.enable_application(application_name=>'MYAPP')

PL/SQL procedure successfully completed.

SQL> select table_name,status from user_flashback_archive_tables;

TABLE_NAME STATUS
---------- ----------
T1         ENABLED
T2         ENABLED

SQL> exec dbms_flashback_archive.disable_application(application_name=>'MYAPP')

PL/SQL procedure successfully completed.

SQL> select table_name,status from user_flashback_archive_tables;

no rows selected

Furthermore, I can now protect these tables with one command against modification and drop:

SQL> exec dbms_flashback_archive.lock_down_application(application_name=>'MYAPP')

PL/SQL procedure successfully completed.

SQL> delete from t1;
delete from t1
            *
ERROR at line 1:
ORA-55622: DML, ALTER and CREATE UNIQUE INDEX operations are not allowed on table "QUAID"."T1"

SQL> drop table t1;
drop table t1
           *
ERROR at line 1:
ORA-55622: DML, ALTER and CREATE UNIQUE INDEX operations are not allowed on table "QUAID"."T1"

This is a much better protection than just making tables READ ONLY:

SQL> create table t3 as select * from dual;

Table created.

SQL> alter table t3 read only;

Table altered.

SQL> drop table t3;

Table dropped.

Please notice also that the tables need not to be in FDA mode to be protected by the lock_down_application call. The doc by the way doesn’t mention the unlock procedure:

SQL> exec dbms_flashback_archive.unlock_application(application_name=>'MYAPP')

PL/SQL procedure successfully completed.

Conclusion: The 12c enhancements of Flashback Data Archive enable the fast change of the FDA mode for multiple tables. Furthermore, it is now easily possible to prevent tables from being modified and dropped.

, , ,

7 Kommentare

#Oracle RAC One Node – Video

Based on the Grid Infrastructure, RAC One Node is a RAC Database with only one instance running. This architecture reduces unplanned as well as planned downtime. If the server crashes that holds the instance of a RAC One Node database, that instance can failover to another node in the cluster automatically. If we need to take down the server (or the clusterware stack there) because of a maintenance task, we can do an Online Database Relocation:

The demo was done with 11gR2 and it is very similar to what I show live during the Oracle University course Oracle Database 11g: RAC Administration about RAC One Node. Hope you like it 🙂

, ,

2 Kommentare

#Oracle SQL Tuning Advisor on the Command Line

This post will show a brief example how to use the SQL Tuning Advisor on the Command Line. The documentation is very verbose about it, but maybe you’ll find it a bit hard to dig through and prefer to start easy.

SQL> grant dba to adam identified by adam;

Grant succeeded.

SQL> connect adam/adam
Connected.
SQL> create table adam.test(n number, w varchar2(3));

Table created.

SQL> insert into adam.test values (1,'uwe');

1 row created.

SQL> commit;

Commit complete.

SQL> create index adam.idx on adam.test(w);

Index created.

The playing field contains nothing special, just an ordinary table and an ordinary index. Now let’s pretend that the following statement has a very long runtime and we don’t know why it does not use the index on the table:

SQL> select * from test where lower(w)='uwe';

         N W
---------- ---
         1 uwe

I will now ask the SQL Tuning Advisor about that ’slow‘ statement

command_line

SQL> declare
    tempstring  varchar2(300);
    task_id   varchar2(200);
    begin
       tempstring := 'select * from adam.test where lower(w)=''uwe''';
       task_id := dbms_sqltune.create_tuning_task(sql_text => tempstring, task_name=>'SQLTUNE1');
       dbms_sqltune.execute_tuning_task('SQLTUNE1');
    end;
    /

PL/SQL procedure successfully completed.

SQL> set long 5000
SQL> select dbms_sqltune.report_tuning_task('SQLTUNE1') from dual; 

DBMS_SQLTUNE.REPORT_TUNING_TASK('SQLTUNE1')
-------------------------------------------------------------------------------
GENERAL INFORMATION SECTION
-------------------------------------------------------------------------------
Tuning Task Name   : SQLTUNE1
Tuning Task Owner  : ADAM
Workload Type      : Single SQL Statement
Scope              : COMPREHENSIVE
Time Limit(seconds): 1800
Completion Status  : COMPLETED
Started at         : 10/11/2013 08:46:19
Completed at       : 10/11/2013 08:46:21

DBMS_SQLTUNE.REPORT_TUNING_TASK('SQLTUNE1')
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
Schema Name: ADAM
SQL ID     : 71vcnzazw9kvw
SQL Text   : select * from adam.test where lower(w)='uwe'

-------------------------------------------------------------------------------
FINDINGS SECTION (3 findings)
-------------------------------------------------------------------------------

1- Statistics Finding
---------------------

DBMS_SQLTUNE.REPORT_TUNING_TASK('SQLTUNE1')
-------------------------------------------------------------------------------
  Table "ADAM"."TEST" was not analyzed.

  Recommendation
  --------------
  - Consider collecting optimizer statistics for this table.
    execute dbms_stats.gather_table_stats(ownname => 'ADAM', tabname =>
            'TEST', estimate_percent => DBMS_STATS.AUTO_SAMPLE_SIZE,
            method_opt => 'FOR ALL COLUMNS SIZE AUTO');

  Rationale
  ---------

DBMS_SQLTUNE.REPORT_TUNING_TASK('SQLTUNE1')
-------------------------------------------------------------------------------
    The optimizer requires up-to-date statistics for the table in order to
    select a good execution plan.

2- Index Finding (see explain plans section below)
--------------------------------------------------
  The execution plan of this statement can be improved by creating one or more
  indices.

  Recommendation (estimated benefit: 66.52%)
  ------------------------------------------
  - Consider running the Access Advisor to improve the physical schema design

DBMS_SQLTUNE.REPORT_TUNING_TASK('SQLTUNE1')
--------------------------------------------------------------------------------
    or creating the recommended index.
    create index ADAM.IDX$$_000C0001 on ADAM.TEST(LOWER("W"),"N","W");

  Rationale
  ---------
    Creating the recommended indices significantly improves the execution plan
    of this statement. However, it might be preferable to run "Access Advisor"
    using a representative SQL workload as opposed to a single statement. This
    will allow to get comprehensive index recommendations which takes into
    account index maintenance overhead and additional space consumption.

DBMS_SQLTUNE.REPORT_TUNING_TASK('SQLTUNE1')
--------------------------------------------------------------------------------
3- Restructure SQL finding (see plan 1 in explain plans section)
----------------------------------------------------------------
  The predicate LOWER("TEST"."W")='uwe' used at line ID 1 of the execution
  plan contains an expression on indexed column "W". This expression prevents
  the optimizer from selecting indices on table "ADAM"."TEST".

  Recommendation
  --------------
  - Rewrite the predicate into an equivalent form to take advantage of
    indices. Alternatively, create a function-based index on the expression.

Pretty much to the point, don’t you agree? I removed the explain plan sections from the output; they show that without the recommended function based index, the statement needs to do a Full Table Scan .

That was a demonstration I did during my recent class Oracle Database 11g: Performance Tuning. Hope you find it useful 🙂

12 Kommentare