Evaluate Index Usage on Exadata

Exadata is well-known with great performance in scanning large amount of data. If need to pull huge amount of data from Exadata in the join operation, full table scan is more efficient than index scan. This is especially true in the data warehouse environment on Exadata.

The smartscan feature on Exadata allows database query to offload the full scan to cell nodes instead of the regular database nodes. But do you want to drop all indexes and in favor of full table scan for everything? Well, although this strategy is used by many database warehouse appliance vendors, you might not want to go for this path, especially when you have a mixed workload environment. For example, in OLTP environment, you might just need to get a few rows or a small amount of data from a large table. In this case, index access might be faster than the full table scan.

I have been to many Exadata clients and one of the top questions from my clients is always related to index. Many Exadata clients migrate their databases from other non-Exadata environment to Exadata. Ideally you want to take this opportunity to clean up the tables and indexes in the database and migrate only the portion of data needed. The tables are relatively easy to identified while indexes are not. You have no idea which index Exadata is going to pick it up in the execution plan before the migration. In addition, many large databases have way too many indexes for the purpose “in case” Oracle optimizer want to use it. Going through each of them before the Exadata migration is going to be painful and time-consuming task. So many companies do the migration first, then go back to evaluate index usage later. So the popular question I get is which index I can keep and which one I can drop.

It is not easy to evaluate whether you want to keep every index, but relatively easier just focus on the large indexes. Just like the “new version” of Mission Impossible below, identifying index usage is the way to help you to determine which one to keep and which one to drop.
mission-impossible
Here are a few ways to determine index usage as follows.

V$OBJECT_USAGE

The first way is using V$OBJECT_USAGE. By default, index monitoring is disabled and you need to run the command as follows to enable the monitoring.

alter index your_index_name monitoring usage;

WZHOU@dbm2> select * from v$object_usage;
no rows selected

WZHOU@dbm2> alter index BIGTAB_OLTP_PK monitoring usage;
Index altered.

WZHOU@dbm2> select * from v$object_usage;
INDEX_NAME        TABLE_NAME	MON USE START_MONITORING    END_MONITORING
----------------- ------------- --- --- ------------------- ------------------
BIGTAB_OLTP_PK    BIGTAB_OLTP   YES NO 02/17/2014 10:57:10

WZHOU@dbm2> select owner, object_name from bigtab_oltp where id = 30;
OWNER        OBJECT_NAME
------------ ------------------------------
SYS          I_PROXY_DATA$

WZHOU@dbm2> select * from v$object_usage;

INDEX_NAME      TABLE_NAME     MON USE START_MONITORING    END_MONITORING
--------------- -------------- --- --- ------------------- -------------------
BIGTAB_OLTP_PK  BIGTAB_OLTP    YES YES 02/17/2014 10:57:10

Please note. If you rerun the monitoring usage command, the previous usage information is wiped out and the USE flag is reset to NO.

WZHOU@dbm2>  alter index BIGTAB_OLTP_PK monitoring usage;
Index altered.

WZHOU@dbm2> select * from v$object_usage;
INDEX_NAME        TABLE_NAME     MON USE START_MONITORING    END_MONITORING
----------------- -------------- --- --- ------------------- ---------------
BIGTAB_OLTP_PK    BIGTAB_OLTP    YES NO  02/17/2014 11:01:01

WZHOU@dbm2> select owner, object_name from bigtab_oltp where id = 31;
OWNER        OBJECT_NAME
------------ ------------------------------
SYS          I_OBJ1

WZHOU@dbm2> select * from v$object_usage;

INDEX_NAME       TABLE_NAME     MON USE START_MONITORING  END_MONITORING
---------------- -------------- --- --- ----------------- -----------------
BIGTAB_OLTP_PK   BIGTAB_OLTP    YES YES 02/17/2014        11:01:01

If you rebuild the index, the index is reported to be used.

WZHOU@dbm2> alter index BIGTAB_OLTP_PK monitoring usage;
Index altered.

WZHOU@dbm2> select * from v$object_usage;

INDEX_NAME       TABLE_NAME     MON USE START_MONITORING  END_MONITORING
---------------- -------------- --- --- ----------------- -----------------
BIGTAB_OLTP_PK   BIGTAB_OLTP    YES NO  02/17/2014 12:04:21

WZHOU@dbm2> alter index bigtab_oltp_pk rebuild;

WZHOU@dbm2> select * from v$object_usage;
INDEX_NAME       TABLE_NAME     MON USE START_MONITORING  END_MONITORING
---------------- -------------- --- --- ----------------- -----------------
BIGTAB_OLTP_PK   BIGTAB_OLTP    NO  YES 02/17/2014 12:04:21

To disable the monitoring, run the following command:
alter Index your_index_name nomonitoring usage;

WZHOU@dbm2>  alter index BIGTAB_OLTP_PK nomonitoring usage;
Index altered.

WZHOU@dbm2> select * from v$object_usage;
INDEX_NAME       TABLE_NAME     MON USE START_MONITORING  END_MONITORING
---------------- -------------- --- --- ----------------- -----------------
BIGTAB_OLTP_PK   BIGTAB_OLTP    NO  YES 02/17/2014 11:01:01 02/17/2014 11:03:37

Although this approach can tell you whether the index is used or not, it does not tell you how many times the index has been used. There is a big difference between 1 time usage and 1,000 times usage. I also do not like the way to run alter index command first to enable usage and have to remember to run the alter index to disable the monitor after the analysis. In addition, this alter index has to be performed on every indexes you want to monitor.

DBA_HIST_SQL_PLAN
Another way is to use dba_hist_sql_plan to find out the index usage. This is not cover 100% usage, but majority of the usage. For the purpose to get a big picture of an index, the information is good enough.

As there are tons of indexes in the database, I usually starts from the index with largest size. Here is the script and sample output.

set line 160 pages 100
col object_owner for a20
col object_name for a35
col index_operation for a30
col total_megs for 999,999,999,999
col total_exec for 999,999,999

break on total_megs skip 1

with top_index as
(
    select * from (
        select
            owner,
            segment_name,
            sum(bytes/1024/1024) as total_megs,
            tablespace_name
        from dba_segments
        where
            segment_name in (
                select index_name
                from dba_indexes
                where
                    owner not in ('SYS', 'SYSTEM', 'SYSMAN','TSMSYS','DBSNMP','OUTLN'))
        group by owner, segment_name, tablespace_name
        order by total_megs desc
    )
    where
        rownum <= 100
)
select
    sp.object_owner,
    sp.object_name,
    decode( options, null, '   -', options) index_operation,
    ti.total_megs,
    count(sp.operation) total_exec,
    min(sp.timestamp) min_exec_date,
    max(sp.timestamp) max_exec_date
from dba_hist_sql_plan sp, top_index ti
where
    sp.object_owner = ti.owner
    and sp.object_name = ti.segment_name
group by
    sp.object_owner,
    sp.object_name,
    decode( options, null, '   -', options),
    ti.total_megs
order by
    ti.total_megs desc,
    sp.object_owner,
    sp.object_name,
    total_exec desc;

Let’s run a test.
WZHOU@dbm2> select /*+ index(bigtab_oltp BIGTAB_OLTP_PK) */ * from bigtab_oltp where id = 31;

ID OWNER OBJECT_NAME SUBOBJECT_NAME OBJECT_ID DATA_OBJECT_ID OBJECT_TYPE CREATED
———- ——————– ———————————– —————————— ———- ————– ——————- ———
LAST_DDL_ TIMESTAMP STATUS T G S NAMESPACE EDITION_NAME
——— ——————- ——- – – – ———- ——————————
31 SYS I_OBJ1 36 36 INDEX 12-MAR-13
12-MAR-13 2013-03-12:14:00:57 VALID N N N 4

Here is the result.

OBJECT_OWNER  OBJECT_NAME        INDEX_OPERATION TOTAL_MEGS TOTAL_EXEC MIN_EXEC_ MAX_EXEC_
------------- ------------------ --------------- ---------- ---------- --------- ---------
WZHOU         TESTCP_OBJID_IDX   RANGE SCAN       176	    2          17-FEB-14 17-FEB-14
WZHOU         TESTCP_OBJID_IDX   FULL SCAN                  1          17-FEB-14 17-FEB-14

WZHOU         TESTCP_PK          UNIQUE SCAN      175       1          17-FEB-14 17-FEB-14

WZHOU         BIGTAB_OLTP_PK     UNIQUE SCAN      117	    2          17-FEB-14 17-FEB-14
WZHOU         BIGTAB_OLTP_PK     RANGE SCAN                 2          21-FEB-14 21-FEB-14

WZHOU         BIGTAB_PK          UNIQUE SCAN      121       1          17-FEB-14 17-FEB-14   

If you could not find any rows from the above rows. Replace dba_hist_sql_plan with V$SQL_PLAN_STATISTICS_ALL.

Once you identify the indexes with less usage, you could make the index invisible first. Then after some period of time, if no negative impact on your system, you can safely drop these indexes.

Here is the command to make index invisible.
WZHOU@dbm2> alter index TESTCP_OBJID_IDX invisible;

Query to verify which indexes are in invisible state.

column tname format a39
column index_name for a30
column index_type format a15
select table_owner||’.’||table_name tname , index_name, index_type, status, visibility
from dba_indexes
where owner like nvl(‘&owner’,owner)
and table_name like nvl(‘&table_name’,table_name)
and index_name like nvl(‘&index_name’,index_name)
and visibility = ‘INVISIBLE’
order by 1,2
/

Enter value for owner: WZHOU
Enter value for table_name:
Enter value for index_name:

TNAME INDEX_NAME INDEX_TYPE STATUS VISIBILITY
————– ——————- ————— ——– ———
WZHOU.TESTCP TESTCP_OBJID_IDX NORMAL VALID INVISIBLE

There is a scenario that you have mixed workload in the same database. Sometimes for data warehouse type of queries, you would like not use the index, but do the full table scan. But for OLTP type queries, you want to use the index. One solution to handle this scenario is to make the index invisible, so optimizer will go for full table scan for the data warehouse type of queries. For OTLP queries, set OPTIMIZER_USE_INVISIBLE_INDEXES to TRUE at session level and will pick up this invisible index for the OLTP queries.

Replace Cisco Ethernet Switch on Exadata

network_port

Usually there is no need to replace Cisco switch on Exadata. However, certain enterprises might have their own standards to use different switch as part of enterprise standard. In this case, the Cisco ethernet switch on Exadata will be replaced. Oracle Support has a nice document about the process to replace Cisco switch, How to replace a Cisco ethernet switch in an Engineered Systems rack (Doc ID 1531203.1). This document is a good one, but focuses only on steps of replacing Cisco Switch, not enough to specify whether additional steps that need to be performed.

At first, I thought Cisco switch only affected the traffic on Management Network on Exadata and don’t have to shut down database and cell nodes. After discussing with my colleague, Andy Colvin, he brought some good points. Although it is not required to shut down the system, there will be no way to get into any of the components via SSH. Furthermore the storage servers will lose connectivity to DNS, which will have adverse consequences on performance. With so many network cables moving around, it would definitely be easier to shut down the entire system and replace the switch. Yes, that makes sense. Here are the high level steps to replace Cisco Switch.
1. Shutdown database nodes
2. Shutdown cell nodes
3. Flip off the switches on PDUs to make sure everything is down.
4. Replace the Cisco switch
5. Turn on PDUs and verify new Ethernet switch
6. Start cell nodes
7. Start database nodes.

Here are the detail steps.
Step 1. Shudown database nodes

1) Logon as oracle user to db node 1 and source one db env, get the status of the database.

crsctl status res -­t | more

check status of oracle instances.
ps -ef |grep pmon

The above steps are optional. Just to make sure all databases are running normal. If seeing issues in database, you might want to resolve it first before replacing Cisco switch. You don’t add the complexity of issues in the middle of switch changes.

2) Stop all the database currently running on Exadata by using srvctl command.
srvctl stop database -d yourdbname

3) Logon as root user to db node 1 and stop crs on the current node.
/u01/app/11.2/grid/bin/crsctl stop crs

During the shutdown process of CRS, run the following command regularly to check the number of oracle processes. It should reduce to 0 when CRS is stopped.
ps -ef|grep d.bin|grep -v grep|wc -l

4) Verify all oracle databases are shut down.
ps -­ef | grep pmon

5) Power off the node
Logon to ILOM to Power Off Server
or
shutdown -h -y now

6) Repeat the above steps for the rest of database nodes

Step 2. Shutdown cell nodes
1) Logon as root user to cell node 1

2) Check cell service, verify the disk status
service celld status
or
cellcli -e list cell detail

3) Verify disk status and they should be ONLINE, not SYNCING state
cellcli -e list griddisk attributes name,asmmodestatus

4) Stop the cell service
service celld stop
or
cellcli -e alter cell shutdown services all

5) Verify the cell services are down
service celld status

6) Logon to ILOM
Logon to ILOM to Power Off Server
or
shutdown -h -y now

7) Repeat the same process for the rest of cell nodes

Step 3. Turn off the PDUs
There is no power button on IB switches. As long as PDUs is on, the IB switches are always on. Before turn off the PDUS, verify ILOM for IB switch is working.

Login to IB switches using ILOM to verify it you can login from there.
http://ib-switch-name/

If ILOM for IB switches is working, flip off the switch on PDUs

Step 4. Replace the Cisco Switch
Use Oracle Support document to replace the switch
How to replace a Cisco ethernet switch in an Engineered Systems rack (Doc ID 1531203.1)

Step 5. Turn on PDU and verify accessibility to/from IB switches

1) Turn on PDUs
After turning on PDU, the IB switches are automatically starts. Make sure to give a few minutes to allow IB switches fully boot up before doing anything.

2) Verify the IB switch
To verify IB switch is ok, run the following command as root user on IB switch
env_test

3) Verify the network connectivity to/from the IB switch. You don’t want start cell nodes if you know you have connectivity issues from/to IB switches. There is no nslookup command on IB switch. So you have to use ping command to figure out whether DNS is working or not on IB switches.
a. First ping IB switch and ssh to it as root user

b. After login, ping a server outside Exadata by hostname. It should work.

c. Then ping a db node and a cell node by hostname

d. Finally, login to IB switch using ILOM to verify it you can login from there
http://ib-switch-name/

Step 6. Start the cell nodes
1) Verify you can access ALL cell nodes from ILOM
http://cell-node-ilom/

2) From ILOM, boot up the cell node, monitor the progress from remote console

3) ssh to cell node as root user, this is to verify NET0 connection is working

4) Verify all cell services are up
service celld status
or
cellcli -e list cell detail

5) Verify all disks are from SYNCING state to ONLINE state
cellcli -e list griddisk attributes name, asmmodestatus

6) Wait until all cell nodes’ disks showing ONLINE state. Highly recommend to wait them complete the SYNCING before starting the db node.

Step 7. Start the DB Nodes
1) Verify you can access ALL db nodes from ILOM.
http://db-node-ilom/

2) From ILOM, boot up the db node 1, monitor the progress from remote console.

3) ssh to db node as oracle user, source ASM environment.

4) Check whether database are online by the following command.
crsctl stat res -t

5) Repeat the above process for the rest of database nodes.

6) Verify database alert files to see anything unusual.