Wednesday, August 7, 2013

Index/table fragmentation scripts

-- identify all tables with more than 20% of rows deleted

select
T.TABLE_NAME,
t.partition_name,
a.num_rows,
sum(t.inserts) ins,
sum(t.updates) upd,
sum(t.deletes) del,
sum(t.updates)+sum(t.inserts)+sum(t.deletes) tot_chgs,
to_char((sum(t.deletes)/(decode(a.num_rows,0,1,a.num_rows)))*100.0,'999999.99') per_del,
ROUND(((SUM(T.UPDATES)+SUM(T.INSERTS)+SUM(T.DELETES))/(DECODE(a.NUM_ROWS,0,1,a.NUM_ROWS))*100.0),2) PER_CHG
from ALL_TAB_MODIFICATIONS T,
all_TABLES a
where T.timestamp >= TO_DATE('01-JAN-2001','dd-mon-yyyy')
and T.TABLE_NAME=a.TABLE_NAME
having (sum(t.deletes)/(decode(a.num_rows,0,1,a.num_rows)))*100 >=20
group by
T.TABLE_NAME, t.partition_name, a.NUM_ROWS
order by NUM_ROWS desc, t.table_name;

-- get fragmentation factor

select OWNER,TABLE_NAME, LAST_ANALYZED, NUM_ROWS,AVG_ROW_LEN,ROUND(blocks*8/1024) MB, ROUND(blocks*7297/AVG_ROW_LEN/NUM_ROWS,1)"factor" from DBA_TABLES
  where blocks>1000 and num_rows>0 and owner not like 'SYS%' order by 1,7;

-- get BLEVEL for indexes (BLEVEL>=4 must be rebuild)

select t.owner,t.table_name,round(t.blocks*8/1024) "tMB", i.index_name, round(i.leaf_blocks*8/1024) "iMB", i.blevel from DBA_INDEXES i, DBA_TABLES t where t.table_name=i.table_name AND t.blocks<i.leaf_blocks*3 and t.blocks>6400 and t.owner not like 'SYS%' order by 1,3;

Wednesday, July 17, 2013

Move from ASMM to AMM

In a RAC architecture is easy to move from ASMM to AMM

SQL> conn / as sysdba
Connected.

SQL> alter system set memory_max_target=9G scope=spfile sid='*';

System altered.

SQL> alter system set memory_target=8G scope=spfile sid='*';

System altered.

SQL> alter system set sga_target=0 scope=spfile sid='*';

System altered.

SQL> alter system set pga_aggregate_target=0 scope=spfile sid='*';

System altered.

Then for each instance do a stop and a start:

srvctl stop instance -d dbora -i dbora2
srvctl start instance -d dbora -i dbora2

srvctl stop instance -d dbora -i dbora1
srvctl start instance -d dbora -i dbora1

Anyway, if you try to increase even more memory_max_target, at restart you might get the following error:

srvctl start instance -d dbora -i dbora2
PRCR-1013 : Failed to start resource ora.dbora.db
PRCR-1064 : Failed to start resource ora.dbora.db on node node-2
CRS-5017: The resource action "ora.dbora.db start" encountered the following error:
ORA-00845: MEMORY_TARGET not supported on this system

This error is generated by the size of memory chunks in memory allocation that is different depending on the size of memory allocated.
A workaround might be to decrease MEMORY_MAX_TARGET or increase also MEMORY_TARGET

Tuesday, July 2, 2013

MYSQL - Purge binary logs

1. SHOW SLAVE STATUS on slave server

mysql> show slave status\G
*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: 10.120.251.21
                  Master_User: repl
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: mysql-bin.000047
          Read_Master_Log_Pos: 925196802
               Relay_Log_File: relay-bin.000140
                Relay_Log_Pos: 925196965
        Relay_Master_Log_File: mysql-bin.000047
             Slave_IO_Running: Yes
            Slave_SQL_Running: Yes
              Replicate_Do_DB:
          Replicate_Ignore_DB:
           Replicate_Do_Table:
       Replicate_Ignore_Table:
      Replicate_Wild_Do_Table:
  Replicate_Wild_Ignore_Table:
                   Last_Errno: 0
                   Last_Error:
                 Skip_Counter: 0
          Exec_Master_Log_Pos: 925196802
              Relay_Log_Space: 925197179
              Until_Condition: None
               Until_Log_File:
                Until_Log_Pos: 0
           Master_SSL_Allowed: No
           Master_SSL_CA_File:
           Master_SSL_CA_Path:
              Master_SSL_Cert:
            Master_SSL_Cipher:
               Master_SSL_Key:
        Seconds_Behind_Master: 0
Master_SSL_Verify_Server_Cert: No
                Last_IO_Errno: 0
                Last_IO_Error:
               Last_SQL_Errno: 0
               Last_SQL_Error:
  Replicate_Ignore_Server_Ids:
             Master_Server_Id: 1
                  Master_UUID: 55f6585c-bd69-11e2-90a5-ac162d8b1c44
             Master_Info_File: /var/lib/mysql/master.info
                    SQL_Delay: 0
          SQL_Remaining_Delay: NULL
      Slave_SQL_Running_State: Slave has read all relay log; waiting for the slave I/O thread to update it
           Master_Retry_Count: 86400
                  Master_Bind:
      Last_IO_Error_Timestamp:
     Last_SQL_Error_Timestamp:
               Master_SSL_Crl:
           Master_SSL_Crlpath:
           Retrieved_Gtid_Set:
            Executed_Gtid_Set:
                Auto_Position: 0
1 row in set (0.00 sec)


2. SHOW BINARY LOGS on master server

mysql> show binary logs;
+------------------+------------+
| Log_name         | File_size  |
+------------------+------------+
| mysql-bin.000001 |        540 |
| mysql-bin.000002 |        143 |
| mysql-bin.000003 |        143 |
| mysql-bin.000004 |        143 |
| mysql-bin.000005 |        143 |
| mysql-bin.000006 |        143 |
| mysql-bin.000007 |       4810 |
| mysql-bin.000008 |        224 |
| mysql-bin.000009 |    2090270 |
| mysql-bin.000010 | 1073795562 |
| mysql-bin.000011 | 1073787709 |
| mysql-bin.000012 | 1073755369 |
| mysql-bin.000013 | 1073760500 |
| mysql-bin.000014 |   13629930 |
| mysql-bin.000015 |      20507 |
| mysql-bin.000016 | 1073756709 |
| mysql-bin.000017 | 1073786502 |
| mysql-bin.000018 |  656410524 |
| mysql-bin.000019 |   11416561 |
| mysql-bin.000020 |   38092807 |
| mysql-bin.000021 | 1073764283 |
| mysql-bin.000022 | 1073763265 |
| mysql-bin.000023 | 1073758670 |
| mysql-bin.000024 | 1073761848 |
| mysql-bin.000025 | 1073767027 |
| mysql-bin.000026 | 1073807701 |
| mysql-bin.000027 | 1073815447 |
| mysql-bin.000028 | 1073746876 |
| mysql-bin.000029 | 1073752803 |
| mysql-bin.000030 | 1073810003 |
| mysql-bin.000031 | 1073742110 |
| mysql-bin.000032 | 1073807390 |
| mysql-bin.000033 | 1073759944 |
| mysql-bin.000034 | 1073742378 |
| mysql-bin.000035 | 1073764107 |
| mysql-bin.000036 | 1073775793 |
| mysql-bin.000037 |  996879580 |
| mysql-bin.000038 |    3833572 |
| mysql-bin.000039 |     240904 |
| mysql-bin.000040 |     610464 |
| mysql-bin.000041 | 1073800478 |
| mysql-bin.000042 | 1073791022 |
| mysql-bin.000043 | 1073796481 |
| mysql-bin.000044 | 1073756133 |
| mysql-bin.000045 | 1073764282 |
| mysql-bin.000046 | 1073796542 |
| mysql-bin.000047 |  925713238 |
+------------------+------------+
47 rows in set (0.01 sec)

3. Determine the earliest log file among all the slaves. This is the target file. If all the slaves are up to date, this is the last log file on the list. (mysql-bin.000046)

4. Copy all binary logs that will be deleted

[root@mysql]# cp mysql-bin.00000* /db/backup_logs/
[root@mysql]# cp mysql-bin.00001* /db/backup_logs/
[root@mysql]# cp mysql-bin.00002* /db/backup_logs/

[root@mysql]# cp mysql-bin.00003* /db/backup_logs/

5. Purge all log files except target log file

mysql> purge binary logs to 'mysql-bin.000039';

Query OK, 0 rows affected (1.00 sec)

6. List remaning binary logs on master

mysql> show binary logs;
+------------------+------------+
| Log_name         | File_size  |
+------------------+------------+
| mysql-bin.000039 |     240904 |
| mysql-bin.000040 |     610464 |
| mysql-bin.000041 | 1073800478 |
| mysql-bin.000042 | 1073791022 |
| mysql-bin.000043 | 1073796481 |
| mysql-bin.000044 | 1073756133 |
| mysql-bin.000045 | 1073764282 |
| mysql-bin.000046 | 1073796542 |
| mysql-bin.000047 |  935732985 |
+------------------+------------+
9 rows in set (0.02 sec)

Wednesday, June 26, 2013

Use Stored Outlines in Oracle 10.2

Get cursors from shared pool


SQL> select * from table(dbms_xplan.display_cursor('3sdab0awk8g3c',null));

PLAN_TABLE_OUTPUT
----------------------------------------------------------------------------------------------------------------------------------------------------------------
SQL_ID  3sdab0awk8g3c, child number 0
-------------------------------------
select fp_id from ftable where ftable.fp_name like :"SYS_B_0" and rownum=:"SYS_B_1"

Plan hash value: 3326224603

-------------------------------------------------------------------------------------------------------------------------------
| Id  | Operation                     | Name             | Rows  | Bytes | Cost (%CPU)| Time     |    TQ  |IN-OUT| PQ Distrib |
-------------------------------------------------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT              |                  |       |       |   622K(100)|          |        |      |            |
|*  1 |  COUNT STOPKEY                |                  |       |       |            |          |        |      |            |
|   2 |   PX COORDINATOR              |                  |       |       |            |          |        |      |            |
|   3 |    PX SEND QC (RANDOM)        | :TQ10002         |  1353K|    81M|   622K (12)| 00:04:05 |  Q1,02 | P->S | QC (RAND)  |
|*  4 |     COUNT STOPKEY             |                  |       |       |            |          |  Q1,02 | PCWC |            |
|   5 |      VIEW                     | index$_join$_001 |  1353K|    81M|   622K (12)| 00:04:05 |  Q1,02 | PCWP |            |
|*  6 |       HASH JOIN BUFFERED      |                  |       |       |            |          |  Q1,02 | PCWP |            |
|   7 |        BUFFER SORT            |                  |       |       |            |          |  Q1,02 | PCWC |            |
|   8 |         PX RECEIVE            |                  |  1353K|    81M|   196K (12)| 00:01:17 |  Q1,02 | PCWP |            |
|   9 |          PX SEND HASH         | :TQ10000         |  1353K|    81M|   196K (12)| 00:01:17 |        | S->P | HASH       |
|  10 |           INDEX FAST FULL SCAN| PK_FTABLE      |  1353K|    81M|   196K (12)| 00:01:17 |        |      |            |
|  11 |        PX RECEIVE             |                  |  1353K|    81M|   439K  (7)| 00:02:53 |  Q1,02 | PCWP |            |
|  12 |         PX SEND HASH          | :TQ10001         |  1353K|    81M|   439K  (7)| 00:02:53 |  Q1,01 | P->P | HASH       |
|  13 |          PX BLOCK ITERATOR    |                  |  1353K|    81M|   439K  (7)| 00:02:53 |  Q1,01 | PCWC |            |
|* 14 |           INDEX FAST FULL SCAN| UNIQUE_FP_NAME   |  1353K|    81M|   439K  (7)| 00:02:53 |  Q1,01 | PCWP |            |
-------------------------------------------------------------------------------------------------------------------------------

Predicate Information (identified by operation id):
---------------------------------------------------

   1 - filter(ROWNUM=:SYS_B_1)
   4 - filter(ROWNUM=:SYS_B_1)
   6 - access(ROWID=ROWID)
  14 - access(:Z>=:Z AND :Z<=:Z)
       filter("FTABLE"."FP_NAME" LIKE :SYS_B_0)

SQL_ID  3sdab0awk8g3c, child number 1


PLAN_TABLE_OUTPUT
----------------------------------------------------------------------------------------------------------------------------------------------------------------
select fp_id from ftable where ftable.fp_name like :"SYS_B_0" and rownum=:"SYS_B_1"

NOTE: cannot fetch plan for SQL_ID: 3sdab0awk8g3c, CHILD_NUMBER: 1
      Please verify value of SQL_ID and CHILD_NUMBER;
      It could also be that the plan is no longer in cursor cache (check v$sql_plan)

SQL_ID  3sdab0awk8g3c, child number 2
-------------------------------------
select fp_id from ftable where ftable.fp_name like :"SYS_B_0" and rownum=:"SYS_B_1"

Plan hash value: 3326224603

-------------------------------------------------------------------------------------------------------------------------------
| Id  | Operation                     | Name             | Rows  | Bytes | Cost (%CPU)| Time     |    TQ  |IN-OUT| PQ Distrib |
-------------------------------------------------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT              |                  |       |       |   622K(100)|          |        |      |            |
|*  1 |  COUNT STOPKEY                |                  |       |       |            |          |        |      |            |
|   2 |   PX COORDINATOR              |                  |       |       |            |          |        |      |            |
|   3 |    PX SEND QC (RANDOM)        | :TQ10002         |  1353K|    81M|   622K (12)| 00:04:05 |  Q1,02 | P->S | QC (RAND)  |
|*  4 |     COUNT STOPKEY             |                  |       |       |            |          |  Q1,02 | PCWC |            |
|   5 |      VIEW                     | index$_join$_001 |  1353K|    81M|   622K (12)| 00:04:05 |  Q1,02 | PCWP |            |
|*  6 |       HASH JOIN BUFFERED      |                  |       |       |            |          |  Q1,02 | PCWP |            |
|   7 |        BUFFER SORT            |                  |       |       |            |          |  Q1,02 | PCWC |            |
|   8 |         PX RECEIVE            |                  |  1353K|    81M|   196K (12)| 00:01:17 |  Q1,02 | PCWP |            |
|   9 |          PX SEND HASH         | :TQ10000         |  1353K|    81M|   196K (12)| 00:01:17 |        | S->P | HASH       |
|  10 |           INDEX FAST FULL SCAN| PK_FTABLE      |  1353K|    81M|   196K (12)| 00:01:17 |        |      |            |
|  11 |        PX RECEIVE             |                  |  1353K|    81M|   439K  (7)| 00:02:53 |  Q1,02 | PCWP |            |
|  12 |         PX SEND HASH          | :TQ10001         |  1353K|    81M|   439K  (7)| 00:02:53 |  Q1,01 | P->P | HASH       |
|  13 |          PX BLOCK ITERATOR    |                  |  1353K|    81M|   439K  (7)| 00:02:53 |  Q1,01 | PCWC |            |
|* 14 |           INDEX FAST FULL SCAN| UNIQUE_FP_NAME   |  1353K|    81M|   439K  (7)| 00:02:53 |  Q1,01 | PCWP |            |
-------------------------------------------------------------------------------------------------------------------------------

Predicate Information (identified by operation id):
---------------------------------------------------

   1 - filter(ROWNUM=:SYS_B_1)
   4 - filter(ROWNUM=:SYS_B_1)

PLAN_TABLE_OUTPUT
----------------------------------------------------------------------------------------------------------------------------------------------------------------
   6 - access(ROWID=ROWID)
  14 - access(:Z>=:Z AND :Z<=:Z)
       filter("FTABLE"."FP_NAME" LIKE :SYS_B_0)

SQL_ID  3sdab0awk8g3c, child number 3
-------------------------------------
select fp_id from ftable where ftable.fp_name like :"SYS_B_0" and rownum=:"SYS_B_1"

Plan hash value: 3326224603

-------------------------------------------------------------------------------------------------------------------------------
| Id  | Operation                     | Name             | Rows  | Bytes | Cost (%CPU)| Time     |    TQ  |IN-OUT| PQ Distrib |
-------------------------------------------------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT              |                  |       |       |   622K(100)|          |        |      |            |
|*  1 |  COUNT STOPKEY                |                  |       |       |            |          |        |      |            |
|   2 |   PX COORDINATOR              |                  |       |       |            |          |        |      |            |
|   3 |    PX SEND QC (RANDOM)        | :TQ10002         |  1353K|    81M|   622K (12)| 00:04:05 |  Q1,02 | P->S | QC (RAND)  |
|*  4 |     COUNT STOPKEY             |                  |       |       |            |          |  Q1,02 | PCWC |            |
|   5 |      VIEW                     | index$_join$_001 |  1353K|    81M|   622K (12)| 00:04:05 |  Q1,02 | PCWP |            |
|*  6 |       HASH JOIN BUFFERED      |                  |       |       |            |          |  Q1,02 | PCWP |            |
|   7 |        BUFFER SORT            |                  |       |       |            |          |  Q1,02 | PCWC |            |
|   8 |         PX RECEIVE            |                  |  1353K|    81M|   196K (12)| 00:01:17 |  Q1,02 | PCWP |            |
|   9 |          PX SEND HASH         | :TQ10000         |  1353K|    81M|   196K (12)| 00:01:17 |        | S->P | HASH       |
|  10 |           INDEX FAST FULL SCAN| PK_FTABLE      |  1353K|    81M|   196K (12)| 00:01:17 |        |      |            |
|  11 |        PX RECEIVE             |                  |  1353K|    81M|   439K  (7)| 00:02:53 |  Q1,02 | PCWP |            |
|  12 |         PX SEND HASH          | :TQ10001         |  1353K|    81M|   439K  (7)| 00:02:53 |  Q1,01 | P->P | HASH       |
|  13 |          PX BLOCK ITERATOR    |                  |  1353K|    81M|   439K  (7)| 00:02:53 |  Q1,01 | PCWC |            |
|* 14 |           INDEX FAST FULL SCAN| UNIQUE_FP_NAME   |  1353K|    81M|   439K  (7)| 00:02:53 |  Q1,01 | PCWP |            |
-------------------------------------------------------------------------------------------------------------------------------

Predicate Information (identified by operation id):
---------------------------------------------------

   1 - filter(ROWNUM=:SYS_B_1)
   4 - filter(ROWNUM=:SYS_B_1)
   6 - access(ROWID=ROWID)
  14 - access(:Z>=:Z AND :Z<=:Z)

PLAN_TABLE_OUTPUT
----------------------------------------------------------------------------------------------------------------------------------------------------------------
       filter("FTABLE"."FP_NAME" LIKE :SYS_B_0)

SQL_ID  3sdab0awk8g3c, child number 4
-------------------------------------
select fp_id from ftable where ftable.fp_name like :"SYS_B_0" and rownum=:"SYS_B_1"

Plan hash value: 1013486222

-----------------------------------------------------------------------------------------------------------------------
| Id  | Operation                            | Name           | Rows  | Bytes | Cost (%CPU)| Time     | Pstart| Pstop |
-----------------------------------------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT                     |                |       |       | 66952 (100)|          |       |       |
|   1 |  COUNT                               |                |       |       |            |          |       |       |
|*  2 |   FILTER                             |                |       |       |            |          |       |       |
|   3 |    TABLE ACCESS BY GLOBAL INDEX ROWID| FTABLE       |  1353K|    81M| 66952   (6)| 00:00:27 | ROW L | ROW L |
|*  4 |     INDEX RANGE SCAN                 | UNIQUE_FP_NAME |   243K|       |  3165   (7)| 00:00:02 |       |       |
-----------------------------------------------------------------------------------------------------------------------

Predicate Information (identified by operation id):
---------------------------------------------------

   2 - filter(ROWNUM=TO_NUMBER(:SYS_B_1))
   4 - access("FTABLE"."FP_NAME" LIKE :SYS_B_0)
       filter("FTABLE"."FP_NAME" LIKE :SYS_B_0)

SQL_ID  3sdab0awk8g3c, child number 8
-------------------------------------
select fp_id from ftable where ftable.fp_name like :"SYS_B_0" and rownum=:"SYS_B_1"

Plan hash value: 3326224603

-------------------------------------------------------------------------------------------------------------------------------
| Id  | Operation                     | Name             | Rows  | Bytes | Cost (%CPU)| Time     |    TQ  |IN-OUT| PQ Distrib |
-------------------------------------------------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT              |                  |       |       |   622K(100)|          |        |      |            |
|*  1 |  COUNT STOPKEY                |                  |       |       |            |          |        |      |            |
|   2 |   PX COORDINATOR              |                  |       |       |            |          |        |      |            |

PLAN_TABLE_OUTPUT
----------------------------------------------------------------------------------------------------------------------------------------------------------------
|   3 |    PX SEND QC (RANDOM)        | :TQ10002         |  1353K|    81M|   622K (12)| 00:04:05 |  Q1,02 | P->S | QC (RAND)  |
|*  4 |     COUNT STOPKEY             |                  |       |       |            |          |  Q1,02 | PCWC |            |
|   5 |      VIEW                     | index$_join$_001 |  1353K|    81M|   622K (12)| 00:04:05 |  Q1,02 | PCWP |            |
|*  6 |       HASH JOIN BUFFERED      |                  |       |       |            |          |  Q1,02 | PCWP |            |
|   7 |        BUFFER SORT            |                  |       |       |            |          |  Q1,02 | PCWC |            |
|   8 |         PX RECEIVE            |                  |  1353K|    81M|   196K (12)| 00:01:17 |  Q1,02 | PCWP |            |
|   9 |          PX SEND HASH         | :TQ10000         |  1353K|    81M|   196K (12)| 00:01:17 |        | S->P | HASH       |
|  10 |           INDEX FAST FULL SCAN| PK_FTABLE      |  1353K|    81M|   196K (12)| 00:01:17 |        |      |            |
|  11 |        PX RECEIVE             |                  |  1353K|    81M|   439K  (7)| 00:02:53 |  Q1,02 | PCWP |            |
|  12 |         PX SEND HASH          | :TQ10001         |  1353K|    81M|   439K  (7)| 00:02:53 |  Q1,01 | P->P | HASH       |
|  13 |          PX BLOCK ITERATOR    |                  |  1353K|    81M|   439K  (7)| 00:02:53 |  Q1,01 | PCWC |            |
|* 14 |           INDEX FAST FULL SCAN| UNIQUE_FP_NAME   |  1353K|    81M|   439K  (7)| 00:02:53 |  Q1,01 | PCWP |            |
-------------------------------------------------------------------------------------------------------------------------------

Predicate Information (identified by operation id):
---------------------------------------------------

   1 - filter(ROWNUM=:SYS_B_1)
   4 - filter(ROWNUM=:SYS_B_1)
   6 - access(ROWID=ROWID)
  14 - access(:Z>=:Z AND :Z<=:Z)
       filter("FTABLE"."FP_NAME" LIKE :SYS_B_0)

SQL_ID  3sdab0awk8g3c, child number 9
-------------------------------------
select fp_id from ftable where ftable.fp_name like :"SYS_B_0" and rownum=:"SYS_B_1"

Plan hash value: 3326224603

-------------------------------------------------------------------------------------------------------------------------------
| Id  | Operation                     | Name             | Rows  | Bytes | Cost (%CPU)| Time     |    TQ  |IN-OUT| PQ Distrib |
-------------------------------------------------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT              |                  |       |       |   622K(100)|          |        |      |            |
|*  1 |  COUNT STOPKEY                |                  |       |       |            |          |        |      |            |
|   2 |   PX COORDINATOR              |                  |       |       |            |          |        |      |            |
|   3 |    PX SEND QC (RANDOM)        | :TQ10002         |  1353K|    81M|   622K (12)| 00:04:05 |  Q1,02 | P->S | QC (RAND)  |
|*  4 |     COUNT STOPKEY             |                  |       |       |            |          |  Q1,02 | PCWC |            |

PLAN_TABLE_OUTPUT
----------------------------------------------------------------------------------------------------------------------------------------------------------------
|   5 |      VIEW                     | index$_join$_001 |  1353K|    81M|   622K (12)| 00:04:05 |  Q1,02 | PCWP |            |
|*  6 |       HASH JOIN BUFFERED      |                  |       |       |            |          |  Q1,02 | PCWP |            |
|   7 |        BUFFER SORT            |                  |       |       |            |          |  Q1,02 | PCWC |            |
|   8 |         PX RECEIVE            |                  |  1353K|    81M|   196K (12)| 00:01:17 |  Q1,02 | PCWP |            |
|   9 |          PX SEND HASH         | :TQ10000         |  1353K|    81M|   196K (12)| 00:01:17 |        | S->P | HASH       |
|  10 |           INDEX FAST FULL SCAN| PK_FTABLE      |  1353K|    81M|   196K (12)| 00:01:17 |        |      |            |
|  11 |        PX RECEIVE             |                  |  1353K|    81M|   439K  (7)| 00:02:53 |  Q1,02 | PCWP |            |
|  12 |         PX SEND HASH          | :TQ10001         |  1353K|    81M|   439K  (7)| 00:02:53 |  Q1,01 | P->P | HASH       |
|  13 |          PX BLOCK ITERATOR    |                  |  1353K|    81M|   439K  (7)| 00:02:53 |  Q1,01 | PCWC |            |
|* 14 |           INDEX FAST FULL SCAN| UNIQUE_FP_NAME   |  1353K|    81M|   439K  (7)| 00:02:53 |  Q1,01 | PCWP |            |
-------------------------------------------------------------------------------------------------------------------------------

Predicate Information (identified by operation id):
---------------------------------------------------

   1 - filter(ROWNUM=:SYS_B_1)
   4 - filter(ROWNUM=:SYS_B_1)
   6 - access(ROWID=ROWID)
  14 - access(:Z>=:Z AND :Z<=:Z)
       filter("FTABLE"."FP_NAME" LIKE :SYS_B_0)

SQL_ID  3sdab0awk8g3c, child number 10
--------------------------------------
select fp_id from ftable where ftable.fp_name like :"SYS_B_0" and rownum=:"SYS_B_1"

Plan hash value: 2456616034

----------------------------------------------------------------------------------------------------------------------
| Id  | Operation                           | Name           | Rows  | Bytes | Cost (%CPU)| Time     | Pstart| Pstop |
----------------------------------------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT                    |                |       |       |     6 (100)|          |       |       |
|*  1 |  COUNT STOPKEY                      |                |       |       |            |          |       |       |
|   2 |   TABLE ACCESS BY GLOBAL INDEX ROWID| FTABLE       |     2 |   126 |     6   (0)| 00:00:01 | ROW L | ROW L |
|*  3 |    INDEX RANGE SCAN                 | UNIQUE_FP_NAME |       |       |     4   (0)| 00:00:01 |       |       |
----------------------------------------------------------------------------------------------------------------------

Predicate Information (identified by operation id):

PLAN_TABLE_OUTPUT
----------------------------------------------------------------------------------------------------------------------------------------------------------------
---------------------------------------------------

   1 - filter(ROWNUM=:SYS_B_1)
   3 - access("FTABLE"."FP_NAME" LIKE :SYS_B_0)
       filter("FTABLE"."FP_NAME" LIKE :SYS_B_0)

SQL_ID  3sdab0awk8g3c, child number 13

select fp_id from ftable where ftable.fp_name like :"SYS_B_0" and rownum=:"SYS_B_1"

NOTE: cannot fetch plan for SQL_ID: 3sdab0awk8g3c, CHILD_NUMBER: 13
      Please verify value of SQL_ID and CHILD_NUMBER;
      It could also be that the plan is no longer in cursor cache (check v$sql_plan)


236 rows selected.

Get sql details from shared pool


SQL> select sql_text, sql_id, plan_hash_value, HASH_VALUE, CHILD_NUMBER
     from V$SQL
     where sql_text like 'select fp_id from ftable%';  2    3

SQL_TEXT
----------------------------------------------------------------------------------------------------------------------------------------------------------------
SQL_ID        PLAN_HASH_VALUE HASH_VALUE CHILD_NUMBER
------------- --------------- ---------- ------------
select fp_id from ftable where ftable.fp_name like :"SYS_B_0" and rownum=:"SYS_B_1"
3sdab0awk8g3c      3326224603 3106159724            0

select fp_id from ftable where ftable.fp_name like :"SYS_B_0" and rownum=:"SYS_B_1"
3sdab0awk8g3c      3326224603 3106159724            1

select fp_id from ftable where ftable.fp_name like :"SYS_B_0" and rownum=:"SYS_B_1"
3sdab0awk8g3c      3326224603 3106159724            2

select fp_id from ftable where ftable.fp_name like :"SYS_B_0" and rownum=:"SYS_B_1"
3sdab0awk8g3c      3326224603 3106159724            3

select fp_id from ftable where ftable.fp_name like :"SYS_B_0" and rownum=:"SYS_B_1"
3sdab0awk8g3c      1013486222 3106159724            4

select fp_id from ftable where ftable.fp_name like :"SYS_B_0" and rownum=:"SYS_B_1"
3sdab0awk8g3c      3326224603 3106159724            8

select fp_id from ftable where ftable.fp_name like :"SYS_B_0" and rownum=:"SYS_B_1"
3sdab0awk8g3c      3326224603 3106159724            9

select fp_id from ftable where ftable.fp_name like :"SYS_B_0" and rownum=:"SYS_B_1"
3sdab0awk8g3c      2456616034 3106159724           10

select fp_id from ftable where ftable.fp_name like :"SYS_B_0" and rownum=:"SYS_B_1"
3sdab0awk8g3c      3326224603 3106159724           13


9 rows selected.

Get cursor with BEST PLAN details


SQL> select * from table(dbms_xplan.display_cursor('3sdab0awk8g3c',10,'ADVANCED'));

PLAN_TABLE_OUTPUT
----------------------------------------------------------------------------------------------------------------------------------------------------------------
SQL_ID  3sdab0awk8g3c, child number 10
--------------------------------------
select fp_id from ftable where ftable.fp_name like :"SYS_B_0" and rownum=:"SYS_B_1"

Plan hash value: 2456616034

----------------------------------------------------------------------------------------------------------------------
| Id  | Operation                           | Name           | Rows  | Bytes | Cost (%CPU)| Time     | Pstart| Pstop |
----------------------------------------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT                    |                |       |       |     6 (100)|          |       |       |
|*  1 |  COUNT STOPKEY                      |                |       |       |            |          |       |       |
|   2 |   TABLE ACCESS BY GLOBAL INDEX ROWID| FTABLE       |     2 |   126 |     6   (0)| 00:00:01 | ROW L | ROW L |
|*  3 |    INDEX RANGE SCAN                 | UNIQUE_FP_NAME |       |       |     4   (0)| 00:00:01 |       |       |
----------------------------------------------------------------------------------------------------------------------

Query Block Name / Object Alias (identified by operation id):
-------------------------------------------------------------

   1 - SEL$1
   2 - SEL$1 / FTABLE@SEL$1
   3 - SEL$1 / FTABLE@SEL$1

Outline Data
-------------

  /*+
      BEGIN_OUTLINE_DATA
      IGNORE_OPTIM_EMBEDDED_HINTS
      OPTIMIZER_FEATURES_ENABLE('10.2.0.5')
      ALL_ROWS
      OUTLINE_LEAF(@"SEL$1")
      INDEX_RS_ASC(@"SEL$1" "FTABLE"@"SEL$1" ("FTABLE"."FP_NAME" "FTABLE"."FP_SOURCE_APP"
              "FTABLE"."FP_DEST_APP" "FTABLE"."FP_SOURCE_FP_ID"))
      END_OUTLINE_DATA
  */

Peeked Binds (identified by position):

PLAN_TABLE_OUTPUT
----------------------------------------------------------------------------------------------------------------------------------------------------------------
--------------------------------------

   1 - :SYS_B_0 (VARCHAR2(30), CSID=871): '%BSR_GTR14425673.FILE%'
   2 - :SYS_B_1 (NUMBER): 1

Predicate Information (identified by operation id):
---------------------------------------------------

   1 - filter(ROWNUM=:SYS_B_1)
   3 - access("FTABLE"."FP_NAME" LIKE :SYS_B_0)
       filter("FTABLE"."FP_NAME" LIKE :SYS_B_0)

Column Projection Information (identified by operation id):
-----------------------------------------------------------

   1 - "FP_ID"[NUMBER,22]
   2 - "FP_ID"[NUMBER,22]
   3 - "FTABLE".ROWID[ROWID,10]


56 rows selected.

Grant outline privileges


SQL> conn / as sysdba
Connected.
SQL> grant create any outline to fuser;

Grant succeeded.

SQL> grant alter any outline to fuser;

Grant succeeded.

SQL> grant drop any outline to fuser;

Grant succeeded.

Create outline for cursor with best execution plan


SQL> conn fuser/fuser
Connected.
SQL> EXEC DBMS_OUTLN.CREATE_OUTLINE(3106159724,10,'FUSER_OUTLINES');

PL/SQL procedure successfully completed.

SQL> select * from user_outlines;

SYS_OUTLINE_13062618005000302       FUSER_OUTLINES                   UNUSED 26.06.2013 18:00:50 10.2.0.5.0
select fp_id from ftable where ftable.fp_name like :"SYS_B_0" and rownum=:"S E3F801A3532476555971DEFCE0EA1F6E COMPATIBLE   ENABLED NORMAL


SQL>

Change outline name


SQL> alter outline SYS_OUTLINE_13062618005000302 rename to FTABLE_OUTLINE;

Outline altered.

Use and test outline


As sys

SQL> alter system set use_stored_outlines = FUSER_OUTLINES;

As user

SQL> variable SYS_B_0 varchar2(200);
SQL> exec :SYS_B_0 := '%cat.IN00102.20130110010000.20130110010502.0607%';

PL/SQL procedure successfully completed.

SQL> variable SYS_B_1 number;
SQL> exec :SYS_B_1 := 1;

PL/SQL procedure successfully completed.

SQL> select fp_id from ftable where ftable.fp_name like :"SYS_B_0" and rownum=:"SYS_B_1";

no rows selected

SQL> SELECT * FROM table(DBMS_XPLAN.DISPLAY_CURSOR);

PLAN_TABLE_OUTPUT
----------------------------------------------------------------------------------------------------------------------------------------------------------------
SQL_ID  3sdab0awk8g3c, child number 5
-------------------------------------
select fp_id from ftable where ftable.fp_name like :"SYS_B_0" and rownum=:"SYS_B_1"

Plan hash value: 2456616034

----------------------------------------------------------------------------------------------------------------------
| Id  | Operation                           | Name           | Rows  | Bytes | Cost (%CPU)| Time     | Pstart| Pstop |
----------------------------------------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT                    |                |       |       |   993K(100)|          |       |       |
|*  1 |  COUNT STOPKEY                      |                |       |       |            |          |       |       |
|   2 |   TABLE ACCESS BY GLOBAL INDEX ROWID| FTABLE       |  1353K|    81M|   993K  (3)| 00:06:30 | ROW L | ROW L |
|*  3 |    INDEX RANGE SCAN                 | UNIQUE_FP_NAME |  1353K|       | 17563   (7)| 00:00:07 |       |       |
----------------------------------------------------------------------------------------------------------------------

Predicate Information (identified by operation id):
---------------------------------------------------

   1 - filter(ROWNUM=:SYS_B_1)
   3 - access("FTABLE"."FP_NAME" LIKE :SYS_B_0)
       filter("FTABLE"."FP_NAME" LIKE :SYS_B_0)

Note
-----
   - outline "FTABLE_OUTLINE" used for this statement


26 rows selected.


SQL> select * from user_outlines;

NAME                                CATEGORY                       USED   TIMESTAMP           VERSION
----------------------------------- ------------------------------ ------ ------------------- ----------------------------------------------------------------
SQL_TEXT                                                                         SIGNATURE                        COMPATIBLE   ENABLED FORMAT
-------------------------------------------------------------------------------- -------------------------------- ------------ -------- ------
FTABLE_OUTLINE                    FUSER_OUTLINES                   USED   26.06.2013 18:13:27 10.2.0.5.0
select fp_id from ftable where ftable.fp_name like :"SYS_B_0" and rownum=:"S E3F801A3532476555971DEFCE0EA1F6E COMPATIBLE   ENABLED NORMAL

Drop outlines


SQL> exec dbms_outln.drop_by_cat('FUSER_OUTLINES');

PL/SQL procedure successfully completed.

SQL> select * from user_outlines;

no rows selected

Revoke user privileges


SQL> conn / as sysdba
Connected.
SQL> revoke drop any outline from fuser;

Revoke succeeded.

SQL> revoke alter any outline from fuser;

Revoke succeeded.

SQL> revoke create any outline from fuser;

Revoke succeeded.






Wednesday, June 19, 2013

ORA-8102 - Traces generated with no error in alert.log, OER 8102 reported in the trace

In alert log appears the message that a trace file was created, but no oracle error was reported:

bash-3.2$ less alert_db11.log

Wed Jun 19 10:00:38 2013
Errors in file /u02/app/oracle/diag/rdbms/db11/db11/trace/db11_j000_24568.trc:
Wed Jun 19 10:00:42 2013
Dumping diagnostic data in directory=[cdmp_20130619100042], requested by (instance=1, osid=24568 (J000)), summary=[abnormal process termination].

In trace file following error appears:

bash-3.2$ less /u02/app/oracle/diag/rdbms/db11/db11/trace/db11_j000_24568.trc

oer 8102.2 - obj# 70688, rdba: 0x0081a2ea(afn 2, blk# 107242)
kdk key 8102.2:
  ncol: 4, len: 64
....

Details for ORA-8102:

Error: ORA-08102 (ORA-8102)
Text: index key not found, obj# %s, file %s, block %s (%s)
---------------------------------------------------------------------------
Cause: Internal error: possible inconsistency in index
Action: Send trace file to your customer support representative, along
with information on reproducing the error

Bellow there is also the current sql running:

dbkedDefDump(): Starting a non-incident diagnostic dump (flags=0x0, level=3, mask=0x0)
----- Error Stack Dump -----
----- Current SQL Statement for this session (sql_id=11p815z8hkfms) -----
DELETE MGMT_SYSTEM_PERFORMANCE_LOG WHERE TIME < :B2 AND ROWNUM <= :B1
----- PL/SQL Stack -----
----- PL/SQL Call Stack -----
  object      line  object
  handle    number  name

The recommendation from Oracle support is to rebuild indexes for affected tables.

Select affected index:

SELECT *
FROM   dba_objects
WHERE  object_id = 70688;

MGMT_SYSTEM_PERF_LOG_IDX_01

If there is an inconsistency between table and index, the next analyze command produces an error ORA-01499:

ANALYZE TABLE MGMT_SYSTEM_PERFORMANCE_LOG VALIDATE STRUCTURE CASCADE;


ORA-01499: table/index cross reference failure - see trace file


bash-3.2$ less db11_ora_25102.trc
....
row not found in index tsn: 1 rdba: 0x00809d52
env [0xfffffd7fffde70a0]: (scn: 0x0857.ee95b7d8  xid: 0x00a6.011.00000198  uba: 0x00000000.0000.00  statement num=0  parent xid
: 0x0000.000.00000000  st-scn: 0x0000.00000000  hi-scn: 0x0000.00000000  ma-scn: 0x0857.ee95b7c3  flg: 0x00000060)
col 0; len 36; (36):
 4d 47 4d 54 5f 43 4f 4c 4c 45 43 54 49 4f 4e 2e 43 6f 6c 6c 65 63 74 69 6f
 6e 20 53 75 62 73 79 73 74 65 6d
col 1; len 7; (7):  78 71 06 0e 10 0d 02
col 2; len 11; (11):  43 6f 6c 6c 65 63 74 69 6f 6e 73
col 3; len 6; (6):  00 81 01 ed 00 32
Block header dump:  0x008101ed
 Object id on Block? Y
 seg/obj: 0x11190  csc: 0x857.ee8b62d4  itc: 2  flg: E  typ: 1 - DATA
     brn: 0  bdba: 0x8101e8 ver: 0x01 opc: 0
     inc: 0  exflg: 0
....
kdgDumpRedo: dump redo on table/index mismatch:
             table block tsn=1 rdba=0x008101ed index objn=70688
             head rowid 0x008101ed.0032

Detect if the corruption is at table or at index level:

ANALYZE TABLE MGMT_SYSTEM_PERFORMANCE_LOG VALIDATE STRUCTURE;
ANALYZE INDEX MGMT_SYSTEM_PERF_LOG_IDX_01 VALIDATE STRUCTURE;

Recreate index:

DROP INDEX SYSMAN.MGMT_SYSTEM_PERF_LOG_IDX_01;

CREATE INDEX SYSMAN.MGMT_SYSTEM_PERF_LOG_IDX_01 ON SYSMAN.MGMT_SYSTEM_PERFORMANCE_LOG
(JOB_NAME, TIME, NAME)
LOGGING
TABLESPACE SYSAUX;

Now, analyzing table with cascade options give no errors:

ANALYZE TABLE MGMT_SYSTEM_PERFORMANCE_LOG VALIDATE STRUCTURE CASCADE;

No errors are reported in alert log, no trace file are created.