<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-6717103620143238053</id><updated>2012-01-30T01:22:56.201-08:00</updated><category term='INDEX FULL SCAN'/><category term='resize'/><category term='v$result_cache_objects'/><category term='v$streams_capture'/><category term='x$ksppi'/><category term='TWO_TASK'/><category term='firstTreeExtensions'/><category term='gv$session'/><category term='command prompt'/><category term='v$result_cache_statistics'/><category term='temporary'/><category term='ORA-02063'/><category term='USE_DB_RECOVERY_FILE_DEST'/><category term='index compression'/><category term='disk'/><category term='sqlplus'/><category term='grant'/><category term='include'/><category term='sql result cache'/><category term='archivelog'/><category term='pagesize'/><category term='crsctl'/><category term='job'/><category term='log_archive_dest'/><category term='set autotrace traceonly explain'/><category term='create_capture'/><category term='gather_table_stats'/><category term='hostname'/><category term='environment variables'/><category term='oifcfg'/><category term='lsnrctl'/><category term='data pump import'/><category term='ocr'/><category term='x$ksppcv'/><category term='crontab'/><category term='dbms_stats'/><category term='backup'/><category term='compress'/><category term='racgons'/><category term='INDEX RANGE SCAN'/><category term='6751'/><category term='sqlprompt'/><category term='plsql'/><category term='result_cache'/><category term='rebuild'/><category term='rootdelete.sh'/><category term='statistics_level'/><category term='undo'/><category term='nologging'/><category term='INDEX UNIQUE SCAN'/><category term='streams'/><category term='impdp'/><category term='rman log'/><category term='memory'/><category term='dbms_streams_adm'/><category term='oracle'/><category term='case'/><category term='restore_table_stats'/><category term='ocrcheck'/><category term='DISTINCT_KEYS'/><category term='rollback'/><category term='ocrconfig'/><category term='filesystem'/><category term='index_stats'/><category term='segment'/><category term='archive log list'/><category term='session'/><category term='ibm aix v5.3'/><category term='statistics'/><category term='expdp'/><category term='capture'/><category term='pwd. profile'/><category term='BLEVEL'/><category term='glogin.sql'/><category term='user_tab_stats_history'/><category term='lun'/><category term='undo_tablespace'/><category term='db_recovery_file_dest'/><category term='vipca'/><category term='ORA-28500'/><category term='rac'/><category term='trace'/><category term='Oracle Heterogeneous Services'/><category term='/ as sysdba'/><category term='fuser'/><category term='PGA'/><category term='SET_UP_QUEUE'/><category term='ADD_TABLE_RULES'/><category term='delete all input'/><category term='directory'/><category term='9i'/><category term='v$parameter'/><category term='export'/><category term='hidden parameters'/><category term='kill'/><category term='downstream'/><category term='mknod'/><category term='TABLE ACCESS FULL'/><category term='queryprocessor'/><category term='processes'/><category term='node'/><category term='ibm'/><category term='ORA-04030'/><category term='monitor'/><category term='parallel'/><category term='background'/><category term='with grant option'/><category term='nfs'/><category term='dbms_job'/><category term='chmod'/><category term='AVG_LEAF_BLOCKS_PER_KEY'/><category term='oracle 11g'/><category term='HS_FDS_CONNECT_STRING'/><category term='userid'/><category term='hsodbc'/><category term='crs_stat'/><category term='multiple schemas'/><category term='addnode.sh'/><category term='function-based index'/><category term='get_stats_history_retention'/><category term='delete input'/><category term='shell script'/><category term='alter_stats_history_retention'/><category term='INDEX FAST FULL SCAN'/><category term='leaf block'/><category term='CBO'/><category term='v$rman_status'/><category term='reload'/><category term='dba'/><category term='log_archive_dest_n'/><category term='INDEX FULL SCAN DESCENDING'/><category term='hs'/><category term='v$rman_output'/><category term='unusable'/><category term='aix'/><category term='50-50 block split'/><category term='SQL*Plus'/><category term='dba_queue_tables'/><category term='asm'/><category term='ibm aix v6.1'/><category term='extent'/><category term='os upgrade'/><category term='ORA-27123'/><category term='cascading revoke'/><category term='unix'/><category term='rootdeletenode.sh'/><category term='ORA-01034'/><category term='index'/><category term='90-10 block split'/><category term='tablespace'/><category term='rman'/><category term='cost based optimizer'/><category term='LF_BLKS'/><category term='whoami'/><category term='supplemental logging'/><title type='text'>Ural URAL's Oracle Blog</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://uralural.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6717103620143238053/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://uralural.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Ural Ural</name><uri>http://www.blogger.com/profile/06556787053001681445</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='19' height='32' src='http://2.bp.blogspot.com/-FS7mo23hHG0/TjlVoo70i9I/AAAAAAAABwQ/mlpdh17_nwM/s220/IMAG0008.jpg'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>33</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-6717103620143238053.post-8303342835440190116</id><published>2011-09-27T03:33:00.000-07:00</published><updated>2011-09-27T03:35:30.920-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='log_archive_dest_n'/><category scheme='http://www.blogger.com/atom/ns#' term='create_capture'/><category scheme='http://www.blogger.com/atom/ns#' term='v$streams_capture'/><category scheme='http://www.blogger.com/atom/ns#' term='supplemental logging'/><category scheme='http://www.blogger.com/atom/ns#' term='dba_queue_tables'/><category scheme='http://www.blogger.com/atom/ns#' term='ADD_TABLE_RULES'/><category scheme='http://www.blogger.com/atom/ns#' term='capture'/><category scheme='http://www.blogger.com/atom/ns#' term='streams'/><category scheme='http://www.blogger.com/atom/ns#' term='SET_UP_QUEUE'/><category scheme='http://www.blogger.com/atom/ns#' term='downstream'/><category scheme='http://www.blogger.com/atom/ns#' term='dbms_streams_adm'/><title type='text'>How to configure Oracle Streams for table replication</title><content type='html'>Below post is a sample case which explains how to configure Oracle Streams for table replication in an Oracle 10gR2 database. It will use asynchronous downstream  capture method when replicating a table from one database to another database. This means archive log files generated in the source database will be implicitly copied to the target database asynchronously and they will be processed in the target database to capture the changes related to the replicated table and they will be applied there.  &lt;br /&gt;&lt;br /&gt;First you need to create a new user who is the Streams administrator in both source and target databases. You also create a separate tablespace for this new user's objects.&lt;br /&gt;&lt;br /&gt;Below command should be executed in both the source and the target databases.&lt;br /&gt;&lt;br /&gt;To create a new tablespace&lt;br /&gt;If you are using ASM with OMF(Oracle Managed Files) and ASSM (Automatic Segment Space Management), use the below statement.&lt;br /&gt;&lt;pre class='brush: sql'&gt;create tablespace streams_tbs;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;if not, use the below statement.&lt;br /&gt;&lt;pre class='brush: sql'&gt;CREATE TABLESPACE streams_tbs DATAFILE '/usr/oracle/dbs/streams_tbs.dbf'&lt;br /&gt;SIZE 25M REUSE AUTOEXTEND ON MAXSIZE UNLIMITED;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Ceate the Streams admin user&lt;br /&gt;&lt;pre class='brush: sql'&gt;CREATE USER strmadmin&lt;br /&gt;IDENTIFIED BY "strmadminpwd"&lt;br /&gt;DEFAULT TABLESPACE streams_tbs&lt;br /&gt;QUOTA UNLIMITED ON streams_tbs;&lt;br /&gt;GRANT DBA TO strmadmin;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;The source database should be in archivelog mode to generate files containing the change records happened in this database.&lt;br /&gt;&lt;br /&gt;You can check with the following sql whether the source database is in archivelog mode or not.&lt;br /&gt;&lt;br /&gt;&lt;pre class='brush: sql'&gt;--@db1&lt;br /&gt;select log_mode from v$database;&lt;br /&gt;--ARCHIVELOG&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Next you should create an ANYDATA queue in the target database to associate with the capture process.&lt;br /&gt;If the specified queue table does not exist, then it is created. If the specified queue table exists, then the existing queue table is used for the new queue. If you do not specify any queue table when you create the queue, then, by default, streams_queue_table is specified.&lt;br /&gt;You can use a single procedure, the SET_UP_QUEUE procedure in the DBMS_STREAMS_ADM package, to create an ANYDATA queue and the queue table used by the queue. For SET_UP_QUEUE to create a new queue table, the specified queue table must&lt;br /&gt;not exist.&lt;br /&gt;&lt;br /&gt;&lt;pre class='brush: sql'&gt;--strmadmin@db2&lt;br /&gt;BEGIN&lt;br /&gt;DBMS_STREAMS_ADM.SET_UP_QUEUE(&lt;br /&gt;queue_table =&gt; 'strmadmin.streams_queue_table',&lt;br /&gt;queue_name =&gt; 'strmadmin.streams_queue',&lt;br /&gt;queue_user =&gt; 'd_dba');&lt;br /&gt;END;&lt;br /&gt;/&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;"queue_user" parameter is the user who is privileged to use this queue, in our case it is "d_dba" database user which we will replicate a table of this user.&lt;br /&gt;&lt;br /&gt;You can use the following sqls to check the newly created queue.&lt;br /&gt;&lt;pre class='brush: sql'&gt;select * from dba_queue_tables where owner='STRMADMIN'; &lt;br /&gt;/*&lt;br /&gt;OWNER,QUEUE_TABLE,TYPE,OBJECT_TYPE,SORT_ORDER,RECIPIENTS,MESSAGE_GROUPING,COMPATIBLE,PRIMARY_INSTANCE,SECONDARY_INSTANCE,OWNER_INSTANCE,USER_COMMENT,SECURE&lt;br /&gt;STRMADMIN,STREAMS_QUEUE_TABLE,OBJECT,SYS.ANYDATA,COMMIT_TIME,MULTIPLE,TRANSACTIONAL,10.0.0,0,0,1,,YES&lt;br /&gt;*/&lt;br /&gt;select * from dba_queues where owner='STRMADMIN'; &lt;br /&gt;/*&lt;br /&gt;OWNER,NAME,QUEUE_TABLE,QID,QUEUE_TYPE,MAX_RETRIES,RETRY_DELAY,ENQUEUE_ENABLED,DEQUEUE_ENABLED,RETENTION,USER_COMMENT,NETWORK_NAME&lt;br /&gt;STRMADMIN,STREAMS_QUEUE,STREAMS_QUEUE_TABLE,133367,NORMAL_QUEUE,5,0, YES , YES ,0,,&lt;br /&gt;STRMADMIN,AQ$_STREAMS_QUEUE_TABLE_E,STREAMS_QUEUE_TABLE,133366,EXCEPTION_QUEUE,0,0, NO , NO ,0,exception queue,&lt;br /&gt;*/&lt;br /&gt;select * from dba_rulesets where owner='STRMADMIN'; &lt;br /&gt;/*&lt;br /&gt;OWNER,RULESET_NAME,RULESET_STORAGE_TABLE,BASE_TABLE,RULESET_COMMENT&lt;br /&gt;STRMADMIN,STREAMS_QUEUE_N,,STRMADMIN.AQ$_STREAMS_QUEUE_TABLE_V,&lt;br /&gt;STRMADMIN,STREAMS_QUEUE_R,,STRMADMIN.AQ$_STREAMS_QUEUE_TABLE_V,&lt;br /&gt;*/&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;We should add the tns alias of the target database to the "tnsnames.ora" file in source database. So that we will use this name for implicit archivelog file transfer to the target database.&lt;br /&gt;&lt;br /&gt;&lt;pre class='brush: sql'&gt;--@db1srv&lt;br /&gt;vi $TNS_ADMIN/tnsnames.ora&lt;br /&gt;&lt;br /&gt;--Add these lines&lt;br /&gt;### STREAMS CONFIG ###&lt;br /&gt;DB2 =&lt;br /&gt;(DESCRIPTION=&lt;br /&gt;(ADDRESS=&lt;br /&gt;(PROTOCOL=TCP)&lt;br /&gt;(HOST=DB2SRV)&lt;br /&gt;(PORT=1521)&lt;br /&gt;)&lt;br /&gt;(CONNECT_DATA=&lt;br /&gt;(SERVICE_NAME=DB2)&lt;br /&gt;)&lt;br /&gt;)&lt;br /&gt;### END STREAMS CONFIG ###&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;In the target database's ASM create the folder structure where the newly created archivelogs will be copied.&lt;br /&gt;&lt;pre class='brush: sql'&gt;--@db2srv&lt;br /&gt;asmcmp -p&lt;br /&gt;ASMCMD [+DG_DB_ASM_DB2/DB2] &gt; mkdir ARCHIVELOG&lt;br /&gt;ASMCMD [+DG_DB_ASM_DB2/DB2] &gt; cd ARCHIVELOG&lt;br /&gt;ASMCMD [+DG_DB_ASM_DB2/DB2/ARCHIVELOG] &gt; mkdir FROM_DB1&lt;br /&gt;ASMCMD [+DG_DB_ASM_DB2/DB2/ARCHIVELOG] &gt; cd FROM_DB1&lt;br /&gt;ASMCMD [+DG_DB_ASM_DB2/DB2/ARCHIVELOG/FROM_DB1] &gt; ls -l&lt;br /&gt;ASMCMD [+DG_DB_ASM_DB2/DB2/ARCHIVELOG/FROM_DB1] &gt; &lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;In the source database configure the log_archive_dest_2 parameter and enable it so that it will point to and send the generated archivelogs to the destination database.&lt;br /&gt;&lt;pre class='brush: sql'&gt;alter system set LOG_ARCHIVE_DEST_2='SERVICE=DB2 ASYNC NOREGISTER &lt;br /&gt;VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) &lt;br /&gt;TEMPLATE=+DG_DB_ASM_DB2/DB2/ARCHIVELOG/FROM_DB1/%t_%s_%r.dbf &lt;br /&gt;DB_UNIQUE_NAME=DB2'&lt;br /&gt;scope=both;&lt;br /&gt;alter system set LOG_ARCHIVE_DEST_STATE_2='ENABLE';&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Try to generate a new archive in source database and check if it is copied to the destination database ASM or not.&lt;br /&gt;&lt;br /&gt;&lt;pre class='brush: sql'&gt;--@db1&lt;br /&gt;alter system switch logfile;&lt;br /&gt;&lt;br /&gt;--@db2srv&lt;br /&gt;asmcmp -p&lt;br /&gt;ASMCMD [+DG_DB_ASM_DB2/DB2/ARCHIVELOG/FROM_DB1] &gt; ls -l&lt;br /&gt;Type Redund Striped Time Sys Name&lt;br /&gt;N 1_200291_699577217.dbf =&gt; +DG_DB_ASM_DB2/DB2/ARCHIVELOG/2011_09_22thread_1_seq_200291.296.762521353&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;We should add the tns alias of the source database to the "tnsnames.ora" file in target database. So that we will use this name for implicit archivelog file transfer to the target database.&lt;br /&gt;&lt;br /&gt;&lt;pre class='brush: sql'&gt;--@db2srv&lt;br /&gt;&lt;br /&gt;vi $TNS_ADMIN/tnsnames.ora&lt;br /&gt;&lt;br /&gt;--Add these lines&lt;br /&gt;### STREAMS CONFIG ###&lt;br /&gt;DB1 =&lt;br /&gt;(DESCRIPTION=&lt;br /&gt;(ADDRESS=&lt;br /&gt;(PROTOCOL=TCP)&lt;br /&gt;(HOST=DB1SRV)&lt;br /&gt;(PORT=1521)&lt;br /&gt;)&lt;br /&gt;(CONNECT_DATA=&lt;br /&gt;(SERVICE_NAME=DB1)&lt;br /&gt;)&lt;br /&gt;)&lt;br /&gt;### END STREAMS CONFIG ###&lt;br /&gt;&lt;br /&gt;--test this tns alias if it is reachable or not&lt;br /&gt;--@db2srv&lt;br /&gt;tnsping DB1&lt;br /&gt;TNS Ping Utility for IBM/AIX RISC System/6000: Version 10.2.0.4.0 - Production on 22-SEP-2011 15:48:03&lt;br /&gt;Copyright (c) 1997, 2007, Oracle. All rights reserved.&lt;br /&gt;Used parameter files:&lt;br /&gt;/oracle/asmhome1/network/admin/sqlnet.ora&lt;br /&gt;Used TNSNAMES adapter to resolve the alias&lt;br /&gt;Attempting to contact (DESCRIPTION= (ADDRESS= (PROTOCOL=TCP) (HOST=DB1SRV) (PORT=1521)) (CONNECT_DATA= (SERVICE_NAME=DB1)))&lt;br /&gt;OK (0 msec)&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Create a database link in strmadmin schema in target database, we will use this later.&lt;br /&gt;&lt;pre class='brush: sql'&gt;--strmadmin@db2&lt;br /&gt;CREATE DATABASE LINK db1&lt;br /&gt;CONNECT TO strmadmin&lt;br /&gt;IDENTIFIED BY "strmadminpwd"&lt;br /&gt;USING 'DB1';&lt;br /&gt;&lt;br /&gt;--Test it if it works or not&lt;br /&gt;select sysdate from dual@db1;&lt;br /&gt;--OK&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;While connected to the downstream database as the Streams administrator, run&lt;br /&gt;the CREATE_CAPTURE procedure to create the capture process:&lt;br /&gt;&lt;pre class='brush: sql'&gt;BEGIN&lt;br /&gt;DBMS_CAPTURE_ADM.CREATE_CAPTURE(&lt;br /&gt;queue_name =&gt; 'strmadmin.streams_queue',&lt;br /&gt;capture_name =&gt; 'strm04_capture',&lt;br /&gt;rule_set_name =&gt; NULL,&lt;br /&gt;start_scn =&gt; NULL,&lt;br /&gt;source_database =&gt; 'db1',&lt;br /&gt;use_database_link =&gt; true,&lt;br /&gt;first_scn =&gt; NULL,&lt;br /&gt;logfile_assignment =&gt; 'implicit');&lt;br /&gt;END;&lt;br /&gt;/&lt;br /&gt;SELECT CAPTURE_NAME, FIRST_SCN, MAX_CHECKPOINT_SCN FROM DBA_CAPTURE;&lt;br /&gt;/*&lt;br /&gt;CAPTURE_NAME,FIRST_SCN,MAX_CHECKPOINT_SCN&lt;br /&gt;STRM04_CAPTURE,74313112953,0&lt;br /&gt;*/&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;We created a capture process called "strm04_capture".&lt;br /&gt;&lt;br /&gt;This step does not associate the capture process strm04_capture with any rule&lt;br /&gt;set. A rule set will be created and associated with the capture process in the next&lt;br /&gt;step.&lt;br /&gt;First we need to create the table in source database which will be replicated to the destination database.&lt;br /&gt;&lt;pre class='brush: sql'&gt;--sys@db1&lt;br /&gt;create table d_dba.streams_test_uural(col1 number, col2 varchar2(100), a_date date);&lt;br /&gt;insert into d_dba.streams_test_uural(col1, col2, a_date) values (1,'1',sysdate);&lt;br /&gt;commit;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;While connected to the downstream database as the Streams administrator, create&lt;br /&gt;the positive rule set for the capture process and add a rule to it:&lt;br /&gt;&lt;pre class='brush: sql'&gt;--strmadmin@db2&lt;br /&gt;BEGIN&lt;br /&gt;DBMS_STREAMS_ADM.ADD_TABLE_RULES(&lt;br /&gt;table_name =&gt; 'd_dba.streams_test_uural',&lt;br /&gt;streams_type =&gt; 'capture',&lt;br /&gt;streams_name =&gt; 'strm04_capture',&lt;br /&gt;queue_name =&gt; 'strmadmin.streams_queue',&lt;br /&gt;include_dml =&gt; true,&lt;br /&gt;include_ddl =&gt; false,&lt;br /&gt;include_tagged_lcr =&gt; false,&lt;br /&gt;source_database =&gt; 'db1',&lt;br /&gt;inclusion_rule =&gt; true);&lt;br /&gt;END;&lt;br /&gt;/&lt;br /&gt;select * from dba_rules where rule_owner = 'STRMADMIN';&lt;br /&gt;/*&lt;br /&gt;RULE_OWNER,RULE_NAME,RULE_CONDITION,RULE_EVALUATION_CONTEXT_OWNER,RULE_EVALUATION_CONTEXT_NAME,RULE_ACTION_CONTEXT,RULE_COMMENT&lt;br /&gt;STRMADMIN,STREAMS_TEST_UURAL1,(((:dml.get_object_owner() = 'D_DBA' and :dml.get_object_name() = 'STREAMS_TEST_UURAL')) and :dml.is_null_tag() = 'Y' and :dml.get_source_database_name() = 'DB1' ),SYS,STREAMS$_EVALUATION_CONTEXT,,&lt;br /&gt;*/&lt;br /&gt;select * from dba_rulesets where owner = 'STRMADMIN' order by ruleset_name;&lt;br /&gt;/*&lt;br /&gt;OWNER,RULESET_NAME,RULESET_STORAGE_TABLE,BASE_TABLE,RULESET_COMMENT&lt;br /&gt;STRMADMIN,RULESET$_2,,SYS.STREAMS$_EVALUATION_CONTEXT,streams name is STRM04_CAPTURE&lt;br /&gt;STRMADMIN,STREAMS_QUEUE_N,,STRMADMIN.AQ$_STREAMS_QUEUE_TABLE_V,&lt;br /&gt;STRMADMIN,STREAMS_QUEUE_R,,STRMADMIN.AQ$_STREAMS_QUEUE_TABLE_V,&lt;br /&gt;*/&lt;br /&gt;select * from dba_rule_set_rules where rule_set_owner = 'STRMADMIN' order by rule_set_name;&lt;br /&gt;/*&lt;br /&gt;RULE_SET_OWNER,RULE_SET_NAME,RULE_OWNER,RULE_NAME,RULE_SET_RULE_ENABLED,RULE_SET_RULE_EVAL_CTX_OWNER,RULE_SET_RULE_EVAL_CTX_NAME,RULE_SET_RULE_COMMENT&lt;br /&gt;STRMADMIN,RULESET$_2,STRMADMIN,STREAMS_TEST_UURAL1,ENABLED,,,"STRMADMIN"."RULESET$_2"&lt;br /&gt;*/&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;You should set minimum supplemental log data in the source database (SUPPLEMENTAL_LOG_DATA_MIN), so that you can enable the table level supplemental logging in the source database.&lt;br /&gt;&lt;pre class='brush: sql'&gt;--sys@db1&lt;br /&gt;select SUPPLEMENTAL_LOG_DATA_MIN,&lt;br /&gt;SUPPLEMENTAL_LOG_DATA_PK,&lt;br /&gt;SUPPLEMENTAL_LOG_DATA_UI from v$database;&lt;br /&gt;/*&lt;br /&gt;SUPPLEMENTAL_LOG_DATA_MIN,SUPPLEMENTAL_LOG_DATA_PK,SUPPLEMENTAL_LOG_DATA_UI&lt;br /&gt;NO,NO,NO&lt;br /&gt;*/&lt;br /&gt;alter database add supplemental log data;&lt;br /&gt;select SUPPLEMENTAL_LOG_DATA_MIN,&lt;br /&gt;SUPPLEMENTAL_LOG_DATA_PK,&lt;br /&gt;SUPPLEMENTAL_LOG_DATA_UI from v$database;&lt;br /&gt;/*&lt;br /&gt;SUPPLEMENTAL_LOG_DATA_MIN,SUPPLEMENTAL_LOG_DATA_PK,SUPPLEMENTAL_LOG_DATA_UI&lt;br /&gt;YES,NO,NO&lt;br /&gt;*/&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Now you should instantiate the source table&lt;br /&gt;&lt;pre class='brush: sql'&gt;--strmadmin@db1&lt;br /&gt;BEGIN&lt;br /&gt;DBMS_CAPTURE_ADM.PREPARE_TABLE_INSTANTIATION(&lt;br /&gt;table_name =&gt; 'd_dba.streams_test_uural',&lt;br /&gt;supplemental_logging =&gt; 'keys');&lt;br /&gt;END;&lt;br /&gt;/&lt;br /&gt;/*&lt;br /&gt;DROP TABLE D_DBA.STREAMS_TEST_UURAL CASCADE CONSTRAINTS;&lt;br /&gt;CREATE TABLE D_DBA.STREAMS_TEST_UURAL&lt;br /&gt;(&lt;br /&gt;COL1 NUMBER,&lt;br /&gt;COL2 VARCHAR2(100 BYTE),&lt;br /&gt;A_DATE DATE,&lt;br /&gt;SUPPLEMENTAL LOG DATA (PRIMARY KEY) COLUMNS,&lt;br /&gt;SUPPLEMENTAL LOG DATA (UNIQUE) COLUMNS,&lt;br /&gt;SUPPLEMENTAL LOG DATA (FOREIGN KEY) COLUMNS&lt;br /&gt;)&lt;br /&gt;TABLESPACE TS_DBA&lt;br /&gt;LOGGING &lt;br /&gt;NOCOMPRESS &lt;br /&gt;NOCACHE&lt;br /&gt;NOPARALLEL&lt;br /&gt;MONITORING;&lt;br /&gt;*/&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;By doing this you enabled the primary key, unique key and foreign key supplemental logging on the source table, so that if any of these key exists on this table the supplemental log data can be captured by using one one these key columns in the destination database.&lt;br /&gt;If your table does not have any key columns like here then you should enable the "all" columns supplemental log data for this table to be place in to the newly generated archivelog files.&lt;br /&gt;&lt;br /&gt;Check the current supplemental log data activated for this table and then add the all columns supplemental log data to this table.&lt;br /&gt;&lt;br /&gt;Check activated supplemental logging&lt;br /&gt;&lt;pre class='brush: sql'&gt;select * from dba_log_groups order by owner, table_name, log_group_type;&lt;br /&gt;/*&lt;br /&gt;OWNER,LOG_GROUP_NAME,TABLE_NAME,LOG_GROUP_TYPE,ALWAYS,GENERATED&lt;br /&gt;D_DBA,SYS_C0043369,STREAMS_TEST_UURAL,FOREIGN KEY LOGGING,CONDITIONAL,GENERATED NAME&lt;br /&gt;D_DBA,SYS_C0043367,STREAMS_TEST_UURAL,PRIMARY KEY LOGGING,ALWAYS,GENERATED NAME&lt;br /&gt;D_DBA,SYS_C0043368,STREAMS_TEST_UURAL,UNIQUE KEY LOGGING,CONDITIONAL,GENERATED NAME&lt;br /&gt;*/&lt;br /&gt;&lt;br /&gt;alter table d_dba.streams_test_uural add supplemental log data (ALL) columns;&lt;br /&gt;&lt;br /&gt;select * from dba_log_groups order by owner, table_name, log_group_type;&lt;br /&gt;/*&lt;br /&gt;OWNER,LOG_GROUP_NAME,TABLE_NAME,LOG_GROUP_TYPE,ALWAYS,GENERATED&lt;br /&gt;D_DBA,SYS_C0043423,STREAMS_TEST_UURAL,ALL COLUMN LOGGING,ALWAYS,GENERATED NAME&lt;br /&gt;D_DBA,SYS_C0043369,STREAMS_TEST_UURAL,FOREIGN KEY LOGGING,CONDITIONAL,GENERATED NAME&lt;br /&gt;D_DBA,SYS_C0043367,STREAMS_TEST_UURAL,PRIMARY KEY LOGGING,ALWAYS,GENERATED NAME&lt;br /&gt;D_DBA,SYS_C0043368,STREAMS_TEST_UURAL,UNIQUE KEY LOGGING,CONDITIONAL,GENERATED NAME&lt;br /&gt;*/&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Now we should create the replicated table in the target database as an empty table.&lt;br /&gt;Instantiate the table in DB2&lt;br /&gt;&lt;pre class='brush: sql'&gt;create table d_dba.streams_test_uural nologging&lt;br /&gt;as select /*+ parallel(t1, 4) */ * from d_dba.streams_test_uural@db1 t1;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Create a database link in source database pointing to the target database&lt;br /&gt;&lt;pre class='brush: sql'&gt;--strmadmin@db1 &lt;br /&gt;CREATE DATABASE LINK db2&lt;br /&gt;CONNECT TO strmadmin&lt;br /&gt;IDENTIFIED BY "strmadminpwd"&lt;br /&gt;USING 'DB2';&lt;br /&gt;select sysdate from dual@db2;&lt;br /&gt;--OK&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Set the instantiation SCN for the "d_dba.streams_test_uural" table at db2 by running the following procedure at the source database db1:&lt;br /&gt;&lt;pre class='brush: sql'&gt;DECLARE&lt;br /&gt;iscn NUMBER; -- Variable to hold instantiation SCN value&lt;br /&gt;BEGIN&lt;br /&gt;iscn := DBMS_FLASHBACK.GET_SYSTEM_CHANGE_NUMBER();&lt;br /&gt;DBMS_APPLY_ADM.SET_TABLE_INSTANTIATION_SCN@db2(&lt;br /&gt;source_object_name =&gt; 'd_dba.streams_test_uural',&lt;br /&gt;source_database_name =&gt; 'db1',&lt;br /&gt;instantiation_scn =&gt; iscn);&lt;br /&gt;END;&lt;br /&gt;/&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;After the instantiation SCN has been set, you can configure an apply process to apply LCRs for the "d_dba.streams_test_uural" table from the streams_queue queue. Setting the instantiation SCN for an object at a database is required only if an apply process applies LCRs for the object. When all of the necessary propagations and apply processes are configured, start the capture process using the START_CAPTURE procedure in DBMS_CAPTURE_ADM.&lt;br /&gt;&lt;br /&gt;&lt;pre class='brush: sql'&gt;--strmadmin@db2&lt;br /&gt;select * from dba_apply_instantiated_objects;&lt;br /&gt;/*&lt;br /&gt;SOURCE_DATABASE,SOURCE_OBJECT_OWNER,SOURCE_OBJECT_NAME,SOURCE_OBJECT_TYPE,INSTANTIATION_SCN,IGNORE_SCN,APPLY_DATABASE_LINK&lt;br /&gt;DB1,D_DBA,STREAMS_TEST_UURAL,TABLE,74313116531,0,&lt;br /&gt;*/&lt;br /&gt;&lt;br /&gt;select * from dba_capture;&lt;br /&gt;/*&lt;br /&gt;CAPTURE_NAME,QUEUE_NAME,QUEUE_OWNER,RULE_SET_NAME,RULE_SET_OWNER,CAPTURE_USER,START_SCN,STATUS,CAPTURED_SCN,APPLIED_SCN,USE_DATABASE_LINK,FIRST_SCN,SOURCE_DATABASE,SOURCE_DBID,SOURCE_RESETLOGS_SCN,SOURCE_RESETLOGS_TIME,LOGMINER_ID,NEGATIVE_RULE_SET_NAME,NEGATIVE_RULE_SET_OWNER,MAX_CHECKPOINT_SCN,REQUIRED_CHECKPOINT_SCN,LOGFILE_ASSIGNMENT,STATUS_CHANGE_TIME,ERROR_NUMBER,ERROR_MESSAGE,VERSION,CAPTURE_TYPE,LAST_ENQUEUED_SCN,CHECKPOINT_RETENTION_TIME&lt;br /&gt;STRM04_CAPTURE,STREAMS_QUEUE,STRMADMIN,RULESET$_2,STRMADMIN,STRMADMIN,74313112953,DISABLED,,,YES,74313112953,DB1,0,0,0,1,,,0,0,IMPLICIT,22/09/2011 17:52:51,,,,DOWNSTREAM,,60&lt;br /&gt;*/&lt;br /&gt;--STATUS=DISABLED&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Creating an Apply Process for Captured Messages with DBMS_APPLY_ADM&lt;br /&gt;&lt;pre class='brush: sql'&gt;BEGIN&lt;br /&gt;DBMS_APPLY_ADM.CREATE_APPLY(&lt;br /&gt;queue_name =&gt; 'strmadmin.streams_queue',&lt;br /&gt;apply_name =&gt; 'strm04_apply',&lt;br /&gt;rule_set_name =&gt; 'strmadmin.ruleset$_2',&lt;br /&gt;message_handler =&gt; NULL,&lt;br /&gt;ddl_handler =&gt; NULL,&lt;br /&gt;apply_user =&gt; 'd_dba',&lt;br /&gt;apply_database_link =&gt; NULL,&lt;br /&gt;apply_tag =&gt; NULL,&lt;br /&gt;apply_captured =&gt; true,&lt;br /&gt;precommit_handler =&gt; NULL,&lt;br /&gt;negative_rule_set_name =&gt; NULL,&lt;br /&gt;source_database =&gt; 'db1');&lt;br /&gt;END;&lt;br /&gt;/&lt;br /&gt;select * from dba_apply_error;&lt;br /&gt;--Nrr&lt;br /&gt;select * from dba_apply_progress;&lt;br /&gt;/*&lt;br /&gt;APPLY_NAME,SOURCE_DATABASE,APPLIED_MESSAGE_NUMBER,OLDEST_MESSAGE_NUMBER,APPLY_TIME,APPLIED_MESSAGE_CREATE_TIME,OLDEST_TRANSACTION_ID&lt;br /&gt;STRM04_APPLY,DB1,0,0,01/01/1988,01/01/1988,&lt;br /&gt;*/&lt;br /&gt;select * from sys.streams$_apply_progress; --holds historical data of the apply process&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Starting an Apply Process&lt;br /&gt;&lt;pre class='brush: sql'&gt;BEGIN&lt;br /&gt;DBMS_APPLY_ADM.START_APPLY(&lt;br /&gt;apply_name =&gt; 'strm04_apply');&lt;br /&gt;END;&lt;br /&gt;/&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Starting a Capture Process&lt;br /&gt;&lt;pre class='brush: sql'&gt;BEGIN&lt;br /&gt;DBMS_CAPTURE_ADM.START_CAPTURE(&lt;br /&gt;capture_name =&gt; 'strm04_capture');&lt;br /&gt;END;&lt;br /&gt;/&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Check the views&lt;br /&gt;&lt;pre class='brush: sql'&gt;select * from dba_capture;&lt;br /&gt;/*&lt;br /&gt;CAPTURE_NAME,QUEUE_NAME,QUEUE_OWNER,RULE_SET_NAME,RULE_SET_OWNER,CAPTURE_USER,START_SCN,STATUS,CAPTURED_SCN,APPLIED_SCN,USE_DATABASE_LINK,FIRST_SCN,SOURCE_DATABASE,SOURCE_DBID,SOURCE_RESETLOGS_SCN,SOURCE_RESETLOGS_TIME,LOGMINER_ID,NEGATIVE_RULE_SET_NAME,NEGATIVE_RULE_SET_OWNER,MAX_CHECKPOINT_SCN,REQUIRED_CHECKPOINT_SCN,LOGFILE_ASSIGNMENT,STATUS_CHANGE_TIME,ERROR_NUMBER,ERROR_MESSAGE,VERSION,CAPTURE_TYPE,LAST_ENQUEUED_SCN,CHECKPOINT_RETENTION_TIME&lt;br /&gt;STRM04_CAPTURE,STREAMS_QUEUE,STRMADMIN,RULESET$_2,STRMADMIN,STRMADMIN,74313112953,ENABLED,74313112953,74313112953,YES,74313112953,DB1,2977989118,538113,699577217,1,,,74318832255,0,IMPLICIT,23/09/2011 11:23:51,,,10.2.0.4.0,DOWNSTREAM,0,60&lt;br /&gt;*/&lt;br /&gt;&lt;br /&gt;--STATUS=ENABLED&lt;br /&gt;&lt;br /&gt;select * from dba_apply;&lt;br /&gt;/*&lt;br /&gt;APPLY_NAME,QUEUE_NAME,QUEUE_OWNER,APPLY_CAPTURED,RULE_SET_NAME,RULE_SET_OWNER,APPLY_USER,APPLY_DATABASE_LINK,APPLY_TAG,DDL_HANDLER,PRECOMMIT_HANDLER,MESSAGE_HANDLER,STATUS,MAX_APPLIED_MESSAGE_NUMBER,NEGATIVE_RULE_SET_NAME,NEGATIVE_RULE_SET_OWNER,STATUS_CHANGE_TIME,ERROR_NUMBER,ERROR_MESSAGE&lt;br /&gt;STRM04_APPLY,STREAMS_QUEUE,STRMADMIN,YES,RULESET$_2,STRMADMIN,D_DBA,,,,,,ENABLED,,,,23/09/2011 11:22:19,,&lt;br /&gt;*/&lt;br /&gt;select * from d_dba.streams_test_uural;&lt;br /&gt;/*&lt;br /&gt;COL1,COL2,A_DATE&lt;br /&gt;1,1,22/09/2011 17:49:55&lt;br /&gt;*/&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Now try to add more rows to the source table in the source database and check whether they will be replicated to the target database or not.&lt;br /&gt;&lt;br /&gt;&lt;pre class='brush: sql'&gt;--sys@db1&lt;br /&gt;insert into d_dba.streams_test_uural(col1, col2, a_date) values (2,'2',sysdate);&lt;br /&gt;commit;&lt;br /&gt;alter system switch logfile;&lt;br /&gt;select DBMS_FLASHBACK.GET_SYSTEM_CHANGE_NUMBER() from dual;&lt;br /&gt;--74318845118&lt;br /&gt;select max(sequence#) from v$archived_log where next_change# &lt;= 74318845118; &lt;br /&gt;--200551&lt;br /&gt;&lt;br /&gt;--strmadmin@db2&lt;br /&gt;select * from v$streams_capture;&lt;br /&gt;/*&lt;br /&gt;SID,SERIAL#,CAPTURE#,CAPTURE_NAME,LOGMINER_ID,STARTUP_TIME,STATE,TOTAL_PREFILTER_DISCARDED,TOTAL_PREFILTER_KEPT,TOTAL_PREFILTER_EVALUATIONS,TOTAL_MESSAGES_CAPTURED,CAPTURE_TIME,CAPTURE_MESSAGE_NUMBER,CAPTURE_MESSAGE_CREATE_TIME,TOTAL_MESSAGES_CREATED,TOTAL_FULL_EVALUATIONS,TOTAL_MESSAGES_ENQUEUED,ENQUEUE_TIME,ENQUEUE_MESSAGE_NUMBER,ENQUEUE_MESSAGE_CREATE_TIME,AVAILABLE_MESSAGE_NUMBER,AVAILABLE_MESSAGE_CREATE_TIME,ELAPSED_CAPTURE_TIME,ELAPSED_RULE_TIME,ELAPSED_ENQUEUE_TIME,ELAPSED_LCR_TIME,ELAPSED_REDO_WAIT_TIME,ELAPSED_PAUSE_TIME,STATE_CHANGED_TIME&lt;br /&gt;506,230,1,STRM04_CAPTURE,1,23/09/2011 11:23:51,CAPTURING CHANGES,6360288,0,6360289,157710,23/09/2011 11:25:49,74314650119,23/09/2011 06:55:23,157797,43,44,23/09/2011 11:24:35,74313260014,23/09/2011 00:24:42,74318845076,23/09/2011 10:46:45,11105,0,22,95,0,0,23/09/2011 11:25:49&lt;br /&gt;*/&lt;br /&gt;select * from d_dba.streams_test_uural;&lt;br /&gt;/*&lt;br /&gt;COL1,COL2,A_DATE&lt;br /&gt;1,1,22/09/2011 17:49:55&lt;br /&gt;2,2,23/09/2011 10:46:36&lt;br /&gt;*/&lt;br /&gt;&lt;/pre&gt;As a result we see that newly inserted row in source table is replicated to the target database.We can check the apply errors, if there are any, by using the below sql in the target database.&lt;pre class='brush: sql'&gt;select * from dba_apply_error;&lt;br /&gt;--No rows returned&lt;br /&gt;&lt;/pre&gt;Above example only replicates the data changes in the source table to the destination table, we can also capture and apply the DDL changes happening on the source table to the destination table. You can use the following commands to achive this.Add DDL capture rule to existing table ruleset :&lt;pre class='brush: sql'&gt;--strmadmin@db2&lt;br /&gt;select * from dba_rules where rule_owner = 'STRMADMIN';&lt;br /&gt;/*&lt;br /&gt;RULE_OWNER,RULE_NAME,RULE_CONDITION,RULE_EVALUATION_CONTEXT_OWNER,RULE_EVALUATION_CONTEXT_NAME,RULE_ACTION_CONTEXT,RULE_COMMENT&lt;br /&gt;STRMADMIN,STREAMS_TEST_UURAL1,(((:dml.get_object_owner() = 'D_DBA' and :dml.get_object_name() = 'STREAMS_TEST_UURAL')) and :dml.is_null_tag() = 'Y' and :dml.get_source_database_name() = 'DB1' ),SYS,STREAMS$_EVALUATION_CONTEXT,,&lt;br /&gt;*/&lt;br /&gt;select * from dba_rulesets where owner = 'STRMADMIN' order by ruleset_name;&lt;br /&gt;/*&lt;br /&gt;OWNER,RULESET_NAME,RULESET_STORAGE_TABLE,BASE_TABLE,RULESET_COMMENT&lt;br /&gt;STRMADMIN,RULESET$_2,,SYS.STREAMS$_EVALUATION_CONTEXT,streams name is STRM04_CAPTURE&lt;br /&gt;STRMADMIN,STREAMS_QUEUE_N,,STRMADMIN.AQ$_STREAMS_QUEUE_TABLE_V,&lt;br /&gt;STRMADMIN,STREAMS_QUEUE_R,,STRMADMIN.AQ$_STREAMS_QUEUE_TABLE_V,&lt;br /&gt;*/&lt;br /&gt;select * from dba_rule_set_rules where rule_set_owner = 'STRMADMIN' order by rule_set_name;&lt;br /&gt;/*&lt;br /&gt;RULE_SET_OWNER,RULE_SET_NAME,RULE_OWNER,RULE_NAME,RULE_SET_RULE_ENABLED,RULE_SET_RULE_EVAL_CTX_OWNER,RULE_SET_RULE_EVAL_CTX_NAME,RULE_SET_RULE_COMMENT&lt;br /&gt;STRMADMIN,RULESET$_2,STRMADMIN,STREAMS_TEST_UURAL1,ENABLED,,,"STRMADMIN"."RULESET$_2"&lt;br /&gt;STRMADMIN,STREAMS_QUEUE_R,STRMADMIN,STREAMS_TEST_UURAL1,ENABLED,SYS,STREAMS$_EVALUATION_CONTEXT,adding to queue default ruleset&lt;br /&gt;*/&lt;br /&gt;&lt;/pre&gt;Now we add a new DDL rule to the existing table rule by using the parameter "include_ddl =&gt; true"&lt;pre class='brush: sql'&gt;BEGIN&lt;br /&gt;DBMS_STREAMS_ADM.ADD_TABLE_RULES(&lt;br /&gt;table_name =&gt; 'd_dba.streams_test_uural',&lt;br /&gt;streams_type =&gt; 'capture',&lt;br /&gt;streams_name =&gt; 'strm04_capture',&lt;br /&gt;queue_name =&gt; 'strmadmin.streams_queue',&lt;br /&gt;include_dml =&gt; false,&lt;br /&gt;include_ddl =&gt; true,&lt;br /&gt;source_database =&gt; 'db1',&lt;br /&gt;inclusion_rule =&gt; true);&lt;br /&gt;END;&lt;br /&gt;/&lt;br /&gt;&lt;/pre&gt;Running this procedure performs the following actions:¦ Creates two rules. One rule evaluates to TRUE for DML changes to thed_dba.streams_test_uural table, and the other rule evaluates to TRUE for DDL changes to the d_dba.streams_test_uural table. The rule names are system generated.¦ Adds the two rules to the positive rule set associated with the capture processbecause the inclusion_rule parameter is set to true.¦ Prepares the d_dba.streams_test_uural table for instantiation by running the PREPARE_TABLE_INSTANTIATION procedure in the DBMS_CAPTURE_ADM package.¦ Enables supplemental logging for any primary key, unique key, bitmap index,and foreign key columns in the d_dba.streams_test_uural table. When the PREPARE_TABLE_INSTANTIATION procedure is run, the default value (keys) is specifiedfor the supplemental_logging parameter.If the capture process is performing downstream capture, then the table is preparedfor instantiation and supplemental logging is enabled for key columns only if thedownstream capture process uses a database link to the source database. If adownstream capture process does not use a database link to the source database, thenthe table must be prepared for instantiation manually and supplemental logging mustbe enabled manually.&lt;pre class='brush: sql'&gt;select * from dba_rules where rule_owner = 'STRMADMIN';&lt;br /&gt;/*&lt;br /&gt;RULE_OWNER,RULE_NAME,RULE_CONDITION,RULE_EVALUATION_CONTEXT_OWNER,RULE_EVALUATION_CONTEXT_NAME,RULE_ACTION_CONTEXT,RULE_COMMENT&lt;br /&gt;STRMADMIN,STREAMS_TEST_UURAL1,(((:dml.get_object_owner() = 'D_DBA' and :dml.get_object_name() = 'STREAMS_TEST_UURAL')) and :dml.is_null_tag() = 'Y' and :dml.get_source_database_name() = 'DB1' ),SYS,STREAMS$_EVALUATION_CONTEXT,,&lt;br /&gt;STRMADMIN,STREAMS_TEST_UURAL3,(((:ddl.get_object_owner() = 'D_DBA' and :ddl.get_object_name() = 'STREAMS_TEST_UURAL')or (:ddl.get_base_table_owner() = 'D_DBA' and :ddl.get_base_table_name() = 'STREAMS_TEST_UURAL')) and :ddl.is_null_tag() = 'Y' and :ddl.get_source_database_name() = 'DB1' ),SYS,STREAMS$_EVALUATION_CONTEXT,,&lt;br /&gt;*/&lt;br /&gt;select * from dba_rulesets where owner = 'STRMADMIN' order by ruleset_name;&lt;br /&gt;/*&lt;br /&gt;OWNER,RULESET_NAME,RULESET_STORAGE_TABLE,BASE_TABLE,RULESET_COMMENT&lt;br /&gt;STRMADMIN,RULESET$_2,,SYS.STREAMS$_EVALUATION_CONTEXT,streams name is STRM04_CAPTURE&lt;br /&gt;STRMADMIN,STREAMS_QUEUE_N,,STRMADMIN.AQ$_STREAMS_QUEUE_TABLE_V,&lt;br /&gt;STRMADMIN,STREAMS_QUEUE_R,,STRMADMIN.AQ$_STREAMS_QUEUE_TABLE_V,&lt;br /&gt;*/&lt;br /&gt;select * from dba_rule_set_rules where rule_set_owner = 'STRMADMIN' order by rule_set_name;&lt;br /&gt;/*&lt;br /&gt;RULE_SET_OWNER,RULE_SET_NAME,RULE_OWNER,RULE_NAME,RULE_SET_RULE_ENABLED,RULE_SET_RULE_EVAL_CTX_OWNER,RULE_SET_RULE_EVAL_CTX_NAME,RULE_SET_RULE_COMMENT&lt;br /&gt;STRMADMIN,RULESET$_2,STRMADMIN,STREAMS_TEST_UURAL3,ENABLED,,,&lt;br /&gt;STRMADMIN,RULESET$_2,STRMADMIN,STREAMS_TEST_UURAL1,ENABLED,,,"STRMADMIN"."RULESET$_2"&lt;br /&gt;STRMADMIN,STREAMS_QUEUE_R,STRMADMIN,STREAMS_TEST_UURAL3,ENABLED,SYS,STREAMS$_EVALUATION_CONTEXT,adding to queue default ruleset&lt;br /&gt;STRMADMIN,STREAMS_QUEUE_R,STRMADMIN,STREAMS_TEST_UURAL1,ENABLED,SYS,STREAMS$_EVALUATION_CONTEXT,adding to queue default ruleset&lt;br /&gt;*/&lt;br /&gt;&lt;/pre&gt;Lets test the DDL capture :&lt;pre class='brush: sql'&gt;--sys@db1&lt;br /&gt;alter table d_dba.streams_test_uural drop column col2;&lt;br /&gt;select DBMS_FLASHBACK.GET_SYSTEM_CHANGE_NUMBER() from dual;&lt;br /&gt;--74318863000&lt;br /&gt;alter system switch logfile;&lt;br /&gt;select max(sequence#) from v$archived_log where next_change# &lt;= 74318863000; &lt;br /&gt;--200556&lt;br /&gt;&lt;br /&gt;--strmadmin@db2&lt;br /&gt;select * from v$streams_capture;&lt;br /&gt;/*&lt;br /&gt;SID,SERIAL#,CAPTURE#,CAPTURE_NAME,LOGMINER_ID,STARTUP_TIME,STATE,TOTAL_PREFILTER_DISCARDED,TOTAL_PREFILTER_KEPT,TOTAL_PREFILTER_EVALUATIONS,TOTAL_MESSAGES_CAPTURED,CAPTURE_TIME,CAPTURE_MESSAGE_NUMBER,CAPTURE_MESSAGE_CREATE_TIME,TOTAL_MESSAGES_CREATED,TOTAL_FULL_EVALUATIONS,TOTAL_MESSAGES_ENQUEUED,ENQUEUE_TIME,ENQUEUE_MESSAGE_NUMBER,ENQUEUE_MESSAGE_CREATE_TIME,AVAILABLE_MESSAGE_NUMBER,AVAILABLE_MESSAGE_CREATE_TIME,ELAPSED_CAPTURE_TIME,ELAPSED_RULE_TIME,ELAPSED_ENQUEUE_TIME,ELAPSED_LCR_TIME,ELAPSED_REDO_WAIT_TIME,ELAPSED_PAUSE_TIME,STATE_CHANGED_TIME&lt;br /&gt;506,230,1,STRM04_CAPTURE,1,23/09/2011 11:23:51,WAITING FOR REDO: LAST SCN MINED 74318863003,18339223,0,18339230,224424,23/09/2011 17:15:01,74318863003,23/09/2011 17:14:50,224545,45,82,23/09/2011 17:15:33,74318863003,,74318863003,23/09/2011 17:14:58,25043,0,23,107,2087402,0,23/09/2011 17:16:03&lt;br /&gt;*/&lt;br /&gt;select * from d_dba.streams_test_uural;&lt;br /&gt;/*&lt;br /&gt;COL1,A_DATE&lt;br /&gt;1,22/09/2011 17:49:55&lt;br /&gt;3,23/09/2011 11:30:20&lt;br /&gt;*/&lt;br /&gt;&lt;/pre&gt;OK , col2 column is dropped in destination db2 database alsoOther streams commands that you might need :&lt;pre class='brush: sql'&gt;--Removing a Rule from a Rule Set for a Capture Process&lt;br /&gt;BEGIN&lt;br /&gt;DBMS_STREAMS_ADM.REMOVE_RULE(&lt;br /&gt;rule_name =&gt; 'departments3',&lt;br /&gt;streams_type =&gt; 'capture',&lt;br /&gt;streams_name =&gt; 'strm01_capture',&lt;br /&gt;drop_unused_rule =&gt; true,&lt;br /&gt;inclusion_rule =&gt; true);&lt;br /&gt;END;&lt;br /&gt;/&lt;br /&gt;&lt;br /&gt;--Removing a Rule Set for a Capture Process&lt;br /&gt;BEGIN&lt;br /&gt;DBMS_CAPTURE_ADM.ALTER_CAPTURE(&lt;br /&gt;capture_name =&gt; 'strm01_capture',&lt;br /&gt;remove_rule_set =&gt; true,&lt;br /&gt;remove_negative_rule_set =&gt; true);&lt;br /&gt;END;&lt;br /&gt;/&lt;br /&gt;&lt;br /&gt;--Setting a Capture Process Parameter&lt;br /&gt;BEGIN&lt;br /&gt;DBMS_CAPTURE_ADM.SET_PARAMETER(&lt;br /&gt;capture_name =&gt; 'strm01_capture',&lt;br /&gt;parameter =&gt; 'parallelism',&lt;br /&gt;value =&gt; '3');&lt;br /&gt;END;&lt;br /&gt;/&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;--Removing a Streams Configuration&lt;br /&gt;You run the REMOVE_STREAMS_CONFIGURATION procedure in the DBMS_STREAMS_ADM package to remove a Streams configuration at the local database.&lt;br /&gt;To remove the Streams configuration at the local database, run the following&lt;br /&gt;procedure:&lt;br /&gt;EXEC DBMS_STREAMS_ADM.REMOVE_STREAMS_CONFIGURATION();&lt;br /&gt;After running this procedure, drop the Streams administrator at the database, if&lt;br /&gt;possible.&lt;br /&gt;Attention: Running this procedure is dangerous. You should run&lt;br /&gt;this procedure only if you are sure you want to remove the entire&lt;br /&gt;Streams configuration at a database.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6717103620143238053-8303342835440190116?l=uralural.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://uralural.blogspot.com/feeds/8303342835440190116/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6717103620143238053&amp;postID=8303342835440190116' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6717103620143238053/posts/default/8303342835440190116'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6717103620143238053/posts/default/8303342835440190116'/><link rel='alternate' type='text/html' href='http://uralural.blogspot.com/2011/09/how-to-configure-oracle-streams-for.html' title='How to configure Oracle Streams for table replication'/><author><name>Ural Ural</name><uri>http://www.blogger.com/profile/06556787053001681445</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='19' height='32' src='http://2.bp.blogspot.com/-FS7mo23hHG0/TjlVoo70i9I/AAAAAAAABwQ/mlpdh17_nwM/s220/IMAG0008.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6717103620143238053.post-7935344562379785371</id><published>2011-07-22T07:15:00.000-07:00</published><updated>2011-07-22T07:23:51.079-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='unusable'/><category scheme='http://www.blogger.com/atom/ns#' term='50-50 block split'/><category scheme='http://www.blogger.com/atom/ns#' term='rebuild'/><category scheme='http://www.blogger.com/atom/ns#' term='index_stats'/><category scheme='http://www.blogger.com/atom/ns#' term='90-10 block split'/><category scheme='http://www.blogger.com/atom/ns#' term='leaf block'/><title type='text'>Why we should put index creation statements at the end of the table transfer scripts</title><content type='html'>Try to put the index creation statements at the end of the table transfer scritps, after the table data transfer part. It does not only increase the performance of the script in data insert part but also results in a better utilized index structure. Creating the index first and inserting table data causes different index structure to be created than inserting the table data and then creating the index, if your index key is not a unique value and inserted into the table in sequential order. Second option will be most probably faster and will cause the index blocks better utilized. &lt;br /&gt;&lt;br /&gt;Below is a demonstration showing that case.&lt;br /&gt;&lt;br /&gt;Lets start with creating a sample schema. You can find the contents of the "cre_user-U0001.sql" in my previous blog posts.&lt;br /&gt;&lt;pre class='brush: sql'&gt;[oracle@localhost uural]$ sqlplus / as sysdba&lt;br /&gt; &lt;br /&gt;SQL*Plus: Release 11.1.0.7.0 - Production on Thu Jul 21 01:02:47 2011&lt;br /&gt; &lt;br /&gt;Copyright (c) 1982, 2008, Oracle.  All rights reserved.&lt;br /&gt; &lt;br /&gt;&lt;br /&gt;Connected to:&lt;br /&gt;Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - Production&lt;br /&gt;With the Partitioning, OLAP, Data Mining and Real Application Testing options&lt;br /&gt; &lt;br /&gt;SQL&gt; @cre_user-U0001&lt;br /&gt; &lt;br /&gt;User dropped.&lt;br /&gt; &lt;br /&gt;&lt;br /&gt;User created.&lt;br /&gt; &lt;br /&gt;&lt;br /&gt;Grant succeeded.&lt;br /&gt; &lt;br /&gt;&lt;br /&gt;User altered.&lt;br /&gt; &lt;br /&gt;&lt;br /&gt;Grant succeeded.&lt;br /&gt; &lt;br /&gt;&lt;br /&gt;Grant succeeded.&lt;br /&gt; &lt;br /&gt;Connected.&lt;br /&gt;USER is "U0001"&lt;br /&gt;SQL&gt; set lines 120&lt;br /&gt;SQL&gt; !vi check_index_stats.sql&lt;br /&gt; &lt;br /&gt;set lines 120&lt;br /&gt;select index_name, blevel, leaf_blocks, distinct_keys, avg_leaf_blocks_per_key, avg_data_blocks_per_key, num_rows, clustering_factor&lt;br /&gt;from user_indexes&lt;br /&gt;where index_name = '&amp;&amp;index_name';&lt;br /&gt;validate index &amp;&amp;index_name;&lt;br /&gt;select name, height, blocks, lf_rows, lf_blks, lf_rows_len, lf_blk_len, br_rows, br_blks, br_rows_len, br_blk_len, del_lf_rows, del_lf_rows_len, distinct_keys, most_repeated_key, b&lt;br /&gt;tree_space, used_space, pct_used, rows_per_key, blks_gets_per_access&lt;br /&gt;from index_stats&lt;br /&gt;where name = '&amp;&amp;index_name';&lt;br /&gt;undefine index_name&lt;br /&gt;--set lines 80&lt;br /&gt; &lt;br /&gt;~&lt;br /&gt;~&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Now create an empty table and an index on its id column.&lt;br /&gt;&lt;pre class='brush: sql'&gt;SQL&gt; create table t1 tablespace ts_no_assm&lt;br /&gt;  2  as&lt;br /&gt;  3  select rownum id&lt;br /&gt;  4  from dual&lt;br /&gt;  5  where null is not null;&lt;br /&gt; &lt;br /&gt;Table created.&lt;br /&gt; &lt;br /&gt;SQL&gt; create index t1_01 on t1(id) tablespace ts_no_assm;&lt;br /&gt; &lt;br /&gt;Index created.&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Then insert some 100,000 rows into that table, with id column values are not unique and sequential. You can think of that operation like you are transferring the data from another database table to "t1" table.&lt;br /&gt;&lt;pre class='brush: sql'&gt;SQL&gt; insert into t1&lt;br /&gt;  2  select mod(rownum,1000) id&lt;br /&gt;  3  from dual&lt;br /&gt;  4  connect by level &lt;= 100000;&lt;br /&gt; &lt;br /&gt;100000 rows created.&lt;br /&gt; &lt;br /&gt;SQL&gt; commit;&lt;br /&gt; &lt;br /&gt;Commit complete.&lt;br /&gt; &lt;br /&gt;SQL&gt; exec dbms_stats.gather_table_stats('','t1',estimate_percent=&gt;null, cascade=&gt;true, method_opt=&gt;'for all columns size 1');&lt;br /&gt; &lt;br /&gt;PL/SQL procedure successfully completed.&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Check the index stats&lt;br /&gt;&lt;pre class='brush: sql'&gt;SQL&gt; @check_index_stats&lt;br /&gt;Enter value for index_name: T1_01&lt;br /&gt;old   3: where index_name = '&amp;&amp;index_name'&lt;br /&gt;new   3: where index_name = 'T1_01'&lt;br /&gt; &lt;br /&gt;INDEX_NAME                         BLEVEL LEAF_BLOCKS DISTINCT_KEYS AVG_LEAF_BLOCKS_PER_KEY AVG_DATA_BLOCKS_PER_KEY&lt;br /&gt;------------------------------ ---------- ----------- ------------- ----------------------- -----------------------&lt;br /&gt;  NUM_ROWS CLUSTERING_FACTOR&lt;br /&gt;---------- -----------------&lt;br /&gt;T1_01                                   1         252          1000                       1                     100&lt;br /&gt;    100000            100000&lt;br /&gt; &lt;br /&gt;&lt;br /&gt;old   1: validate index &amp;&amp;index_name&lt;br /&gt;new   1: validate index T1_01&lt;br /&gt; &lt;br /&gt;Index analyzed.&lt;br /&gt; &lt;br /&gt;old   3: where name = '&amp;&amp;index_name'&lt;br /&gt;new   3: where name = 'T1_01'&lt;br /&gt; &lt;br /&gt;NAME                               HEIGHT     BLOCKS    LF_ROWS    LF_BLKS LF_ROWS_LEN LF_BLK_LEN    BR_ROWS    BR_BLKS&lt;br /&gt;------------------------------ ---------- ---------- ---------- ---------- ----------- ---------- ---------- ----------&lt;br /&gt;BR_ROWS_LEN BR_BLK_LEN DEL_LF_ROWS DEL_LF_ROWS_LEN DISTINCT_KEYS MOST_REPEATED_KEY BTREE_SPACE USED_SPACE   PCT_USED&lt;br /&gt;----------- ---------- ----------- --------------- ------------- ----------------- ----------- ---------- ----------&lt;br /&gt;ROWS_PER_KEY BLKS_GETS_PER_ACCESS&lt;br /&gt;------------ --------------------&lt;br /&gt;T1_01                                   2        256     100000        252     1489000       7996        251          1&lt;br /&gt;       3314       8028           0               0          1000               100     2023020    1492314         74&lt;br /&gt;         100                 52.5&lt;br /&gt;&lt;/pre&gt;As you can see in the index stats above, index has grown to 252 leaf blocks which are %74 full on average and index size is around 2 MB.&lt;br /&gt;&lt;br /&gt;Now try the second case by first inserting the rows than creating the index. &lt;br /&gt;&lt;pre class='brush: sql'&gt;SQL&gt; drop table t1;&lt;br /&gt; &lt;br /&gt;Table dropped.&lt;br /&gt;&lt;br /&gt;SQL&gt; create table t1 tablespace ts_no_assm&lt;br /&gt;  2  as&lt;br /&gt;  3  select rownum id&lt;br /&gt;  4  from dual&lt;br /&gt;  5  where null is not null;&lt;br /&gt; &lt;br /&gt;Table created.&lt;br /&gt; &lt;br /&gt;SQL&gt; insert into t1&lt;br /&gt;  2  select mod(rownum,1000) id&lt;br /&gt;  3  from dual&lt;br /&gt;  4  connect by level &lt;= 100000;&lt;br /&gt; &lt;br /&gt;100000 rows created.&lt;br /&gt; &lt;br /&gt;SQL&gt; commit;&lt;br /&gt; &lt;br /&gt;Commit complete.&lt;br /&gt; &lt;br /&gt;SQL&gt; create index t1_01 on t1(id) tablespace ts_no_assm;&lt;br /&gt; &lt;br /&gt;Index created.&lt;br /&gt; &lt;br /&gt;SQL&gt; exec dbms_stats.gather_table_stats('','t1',estimate_percent=&gt;null, cascade=&gt;true, method_opt=&gt;'for all columns size 1');&lt;br /&gt; &lt;br /&gt;PL/SQL procedure successfully completed.&lt;br /&gt; &lt;br /&gt;SQL&gt; @check_index_stats&lt;br /&gt;Enter value for index_name: T1_01&lt;br /&gt;old   3: where index_name = '&amp;&amp;index_name'&lt;br /&gt;new   3: where index_name = 'T1_01'&lt;br /&gt; &lt;br /&gt;INDEX_NAME                         BLEVEL LEAF_BLOCKS DISTINCT_KEYS AVG_LEAF_BLOCKS_PER_KEY AVG_DATA_BLOCKS_PER_KEY&lt;br /&gt;------------------------------ ---------- ----------- ------------- ----------------------- -----------------------&lt;br /&gt;  NUM_ROWS CLUSTERING_FACTOR&lt;br /&gt;---------- -----------------&lt;br /&gt;T1_01                                   1         208          1000                       1                     100&lt;br /&gt;    100000            100000&lt;br /&gt; &lt;br /&gt;&lt;br /&gt;old   1: validate index &amp;&amp;index_name&lt;br /&gt;new   1: validate index T1_01&lt;br /&gt; &lt;br /&gt;Index analyzed.&lt;br /&gt; &lt;br /&gt;old   3: where name = '&amp;&amp;index_name'&lt;br /&gt;new   3: where name = 'T1_01'&lt;br /&gt; &lt;br /&gt;NAME                               HEIGHT     BLOCKS    LF_ROWS    LF_BLKS LF_ROWS_LEN LF_BLK_LEN    BR_ROWS    BR_BLKS&lt;br /&gt;------------------------------ ---------- ---------- ---------- ---------- ----------- ---------- ---------- ----------&lt;br /&gt;BR_ROWS_LEN BR_BLK_LEN DEL_LF_ROWS DEL_LF_ROWS_LEN DISTINCT_KEYS MOST_REPEATED_KEY BTREE_SPACE USED_SPACE   PCT_USED&lt;br /&gt;----------- ---------- ----------- --------------- ------------- ----------------- ----------- ---------- ----------&lt;br /&gt;ROWS_PER_KEY BLKS_GETS_PER_ACCESS&lt;br /&gt;------------ --------------------&lt;br /&gt;T1_01                                   2        256     100000        208     1489000       7996        207          1&lt;br /&gt;       3066       8028           0               0          1000               100     1671196    1492066         90&lt;br /&gt;         100                 52.5&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;As you can see now, index has grown to 208 leaf blocks which are %90 full on average and index size is around 1.7 MB.&lt;br /&gt;&lt;br /&gt;As a result, putting the index creation statements at the end of a table transfer script, does not only makes the data insert operation faster, since the database will not have to deal with creating the index tree, but also makes the index well organized by utilizing the leaf blocks better with %90 average usage because of 90-10 index block splits.&lt;br /&gt;&lt;br /&gt;The reason for this result is, when you first create the index and then insert the rows, the indexed column values are inserted into the table not in sequential order because of the "mod(rownum, 1000)" function because the same value was inserted again for every 1,000 rows causing 50-50 index leaf block splits. This caused the index allocate more blocks for its leaf blocks making the index larger. Although in the second scenario, since all the rows were already inserted to the table, when we created the index on id column, Oracle selected the id column values from table and sort them before inserting into the index tree causing only 90-10 index leaf block splits. &lt;br /&gt;&lt;br /&gt;If the id column were unique and inserted into table in sequential order, it would not make much difference creating the index first from the index structure point of view, but anyway insert operation will be faster if you create the index as a last step. &lt;br /&gt;&lt;br /&gt;At least, if you can not drop the existing index on an existing table and then create it after the insert operation, you can use the method of making the existing index "UNUSABLE" then "REBUILD" it after the insert operation which will be faster and more effective related the index structure.&lt;br /&gt;&lt;br /&gt;In an OLTP system, which the insert, update, delete operations will start to happen after you transferred the table, index structure will soon do some 50-50 index leaf block splits and return to a structure with less utilized leaf blocks, but in a datawarehouse-like database where mostly insert and select statements happen, you can use this method more effectively.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6717103620143238053-7935344562379785371?l=uralural.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://uralural.blogspot.com/feeds/7935344562379785371/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6717103620143238053&amp;postID=7935344562379785371' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6717103620143238053/posts/default/7935344562379785371'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6717103620143238053/posts/default/7935344562379785371'/><link rel='alternate' type='text/html' href='http://uralural.blogspot.com/2011/07/why-we-should-put-index-creation.html' title='Why we should put index creation statements at the end of the table transfer scripts'/><author><name>Ural Ural</name><uri>http://www.blogger.com/profile/06556787053001681445</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='19' height='32' src='http://2.bp.blogspot.com/-FS7mo23hHG0/TjlVoo70i9I/AAAAAAAABwQ/mlpdh17_nwM/s220/IMAG0008.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6717103620143238053.post-2726989135111005698</id><published>2011-07-19T06:59:00.000-07:00</published><updated>2011-07-20T06:19:25.531-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='LF_BLKS'/><category scheme='http://www.blogger.com/atom/ns#' term='index compression'/><category scheme='http://www.blogger.com/atom/ns#' term='BLEVEL'/><category scheme='http://www.blogger.com/atom/ns#' term='AVG_LEAF_BLOCKS_PER_KEY'/><category scheme='http://www.blogger.com/atom/ns#' term='DISTINCT_KEYS'/><category scheme='http://www.blogger.com/atom/ns#' term='compress'/><category scheme='http://www.blogger.com/atom/ns#' term='index_stats'/><title type='text'>Will index compression help us or not ?</title><content type='html'>Below are two demonstrations related to the index compression in Oracle. In the first test, index compression will make situation worse because the indexed column values are unique, in the second test we will see how much we will get by using index compression in a specific case.&lt;br /&gt;&lt;br /&gt;Lets begin the first test by creating a sample schema and a sample table.&lt;br /&gt;&lt;pre class='brush: sql'&gt;[oracle@localhost uural]$ sqlplus / as sysdba&lt;br /&gt;&lt;br /&gt;SQL*Plus: Release 11.1.0.7.0 - Production on Tue Jul 19 01:45:22 2011&lt;br /&gt;&lt;br /&gt;Copyright (c) 1982, 2008, Oracle.  All rights reserved.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Connected to:&lt;br /&gt;Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - Production&lt;br /&gt;With the Partitioning, OLAP, Data Mining and Real Application Testing options&lt;br /&gt;&lt;br /&gt;SQL&gt; !vi cre_user-U0001.sql&lt;br /&gt;&lt;br /&gt;drop user u0001 cascade;&lt;br /&gt;create user u0001 identified by u0001;&lt;br /&gt;grant create session to u0001;&lt;br /&gt;alter user u0001 quota 5G on users;&lt;br /&gt;grant create table to u0001;&lt;br /&gt;grant dba to u0001;&lt;br /&gt;&lt;br /&gt;conn u0001/u0001&lt;br /&gt;sho user&lt;br /&gt;~&lt;br /&gt;~&lt;br /&gt;~&lt;br /&gt;"cre_user-U0001.sql" 9L, 207C written&lt;br /&gt;&lt;br /&gt;SQL&gt; @cre_user-U0001&lt;br /&gt;&lt;br /&gt;User dropped.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;User created.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Grant succeeded.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;User altered.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Grant succeeded.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Grant succeeded.&lt;br /&gt;&lt;br /&gt;Connected.&lt;br /&gt;USER is "U0001"&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;I created a script to query the index related information form "user_indexes", validate the index and then query the "index_stats" view.&lt;br /&gt;&lt;pre class='brush: sql'&gt;SQL&gt; !vi check_index_stats.sql&lt;br /&gt;&lt;br /&gt;set lines 120&lt;br /&gt;select index_name, blevel, leaf_blocks, distinct_keys, avg_leaf_blocks_per_key, avg_data_blocks_per_key, num_rows, clustering_factor&lt;br /&gt;from user_indexes&lt;br /&gt;where index_name = '&amp;&amp;index_name';&lt;br /&gt;validate index &amp;&amp;index_name;&lt;br /&gt;select name, height, blocks, lf_rows, lf_blks, lf_rows_len, lf_blk_len, br_rows, br_blks, br_rows_len, br_blk_len, del_lf_rows, del_lf_rows_len, distinct_keys, most_repeated_key, btree_space, used_space, pct_used, rows_per_key, blks_gets_per_access&lt;br /&gt;from index_stats&lt;br /&gt;where name = '&amp;&amp;index_name';&lt;br /&gt;undefine index_name&lt;br /&gt;set lines 80&lt;br /&gt;~&lt;br /&gt;~&lt;br /&gt;~&lt;br /&gt;"check_index_stats.sql" 11L, 558C written&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;SQL&gt; create table t1 as&lt;br /&gt;  2  select&lt;br /&gt;  3          rownum                          id,&lt;br /&gt;  4          dbms_random.string('U',6)       v1,&lt;br /&gt;  5          lpad(rownum,10)                 v2,&lt;br /&gt;  6          rpad('x',100)                   padding&lt;br /&gt;  7  from&lt;br /&gt;  8  dual&lt;br /&gt;  9  connect by level &lt;= 1000000&lt;br /&gt; 10  ;&lt;br /&gt;/&lt;br /&gt;&lt;br /&gt;SQL&gt; create index t1_01 on t1(id);&lt;br /&gt;&lt;br /&gt;Index created.&lt;br /&gt;&lt;br /&gt;Elapsed: 00:00:02.02&lt;br /&gt;SQL&gt; exec dbms_stats.gather_table_stats('', 't1', estimate_percent =&gt; null, cascade =&gt; true, method_opt =&gt; 'for all columns size 1');&lt;br /&gt;&lt;br /&gt;PL/SQL procedure successfully completed.&lt;br /&gt;&lt;br /&gt;Elapsed: 00:00:16.47&lt;br /&gt;SQL&gt; @check_index_stats&lt;br /&gt;Enter value for index_name: T1_01&lt;br /&gt;old   3: where index_name = '&amp;&amp;index_name'&lt;br /&gt;new   3: where index_name = 'T1_01'&lt;br /&gt;&lt;br /&gt;INDEX_NAME                         BLEVEL LEAF_BLOCKS DISTINCT_KEYS AVG_LEAF_BLOCKS_PER_KEY AVG_DATA_BLOCKS_PER_KEY&lt;br /&gt;------------------------------ ---------- ----------- ------------- ----------------------- -----------------------&lt;br /&gt;  NUM_ROWS CLUSTERING_FACTOR&lt;br /&gt;---------- -----------------&lt;br /&gt;T1_01                                   2        2226       1000000                       1                       1&lt;br /&gt;   1000000             17858&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Elapsed: 00:00:00.03&lt;br /&gt;old   1: validate index &amp;&amp;index_name&lt;br /&gt;new   1: validate index T1_01&lt;br /&gt;&lt;br /&gt;Index analyzed.&lt;br /&gt;&lt;br /&gt;Elapsed: 00:00:00.59&lt;br /&gt;old   3: where name = '&amp;&amp;index_name'&lt;br /&gt;new   3: where name = 'T1_01'&lt;br /&gt;&lt;br /&gt;NAME                               HEIGHT     BLOCKS    LF_ROWS    LF_BLKS LF_ROWS_LEN LF_BLK_LEN    BR_ROWS    BR_BLKS&lt;br /&gt;------------------------------ ---------- ---------- ---------- ---------- ----------- ---------- ---------- ----------&lt;br /&gt;BR_ROWS_LEN BR_BLK_LEN DEL_LF_ROWS DEL_LF_ROWS_LEN DISTINCT_KEYS MOST_REPEATED_KEY BTREE_SPACE USED_SPACE   PCT_USED&lt;br /&gt;----------- ---------- ----------- --------------- ------------- ----------------- ----------- ---------- ----------&lt;br /&gt;ROWS_PER_KEY BLKS_GETS_PER_ACCESS&lt;br /&gt;------------ --------------------&lt;br /&gt;T1_01                                   3       2304    1000000       2226    15979802       7996       2225          5&lt;br /&gt;      26657       8028           0               0       1000000                 1    17839236   16006459         90&lt;br /&gt;           1                    4&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Elapsed: 00:00:00.19&lt;br /&gt;&lt;/pre&gt;As we can see from the above output, the index we created has 2226 leaf blocks and since the values in "id" column are unique it has 1,000,000 distinct keys, it took nearly 18 MB storage to keep this index.&lt;br /&gt;&lt;br /&gt;Lets now try to query this table by using this index.&lt;br /&gt;&lt;pre class='brush: sql'&gt;SQL&gt; alter system flush buffer_cache;&lt;br /&gt;&lt;br /&gt;System altered.&lt;br /&gt;&lt;br /&gt;Elapsed: 00:00:00.15&lt;br /&gt;SQL&gt; set lines 120&lt;br /&gt;SQL&gt; set autot trace&lt;br /&gt;SQL&gt; select * from t1 where id between 100000 and 200000;&lt;br /&gt;&lt;br /&gt;100001 rows selected.&lt;br /&gt;&lt;br /&gt;Elapsed: 00:00:03.25&lt;br /&gt;&lt;br /&gt;Execution Plan&lt;br /&gt;----------------------------------------------------------&lt;br /&gt;Plan hash value: 2362378154&lt;br /&gt;&lt;br /&gt;-------------------------------------------------------------------------------------&lt;br /&gt;| Id  | Operation                   | Name  | Rows  | Bytes | Cost (%CPU)| Time     |&lt;br /&gt;-------------------------------------------------------------------------------------&lt;br /&gt;|   0 | SELECT STATEMENT            |       |   100K|    11M|  2013   (1)| 00:00:25 |&lt;br /&gt;|   1 |  TABLE ACCESS BY INDEX ROWID| T1    |   100K|    11M|  2013   (1)| 00:00:25 |&lt;br /&gt;|*  2 |   INDEX RANGE SCAN          | T1_01 |   100K|       |   226   (1)| 00:00:03 |&lt;br /&gt;-------------------------------------------------------------------------------------&lt;br /&gt;&lt;br /&gt;Predicate Information (identified by operation id):&lt;br /&gt;---------------------------------------------------&lt;br /&gt;&lt;br /&gt;   2 - access("ID"&gt;=100000 AND "ID"&lt;=200000)&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Statistics&lt;br /&gt;----------------------------------------------------------&lt;br /&gt;          1  recursive calls&lt;br /&gt;          0  db block gets&lt;br /&gt;      15213  consistent gets&lt;br /&gt;       2013  physical reads&lt;br /&gt;          0  redo size&lt;br /&gt;   13766300  bytes sent via SQL*Net to client&lt;br /&gt;      73745  bytes received via SQL*Net from client&lt;br /&gt;       6668  SQL*Net roundtrips to/from client&lt;br /&gt;          0  sorts (memory)&lt;br /&gt;          0  sorts (disk)&lt;br /&gt;     100001  rows processed&lt;br /&gt;&lt;br /&gt;SQL&gt; set autot off&lt;br /&gt;&lt;/pre&gt;As a result it took 03.25 seconds, 15213  consistent gets and 2013  physical reads to get 100001 rows from the table. &lt;br /&gt;&lt;br /&gt;Now drop and create this index as compressed&lt;br /&gt;&lt;pre class='brush: sql'&gt;SQL&gt; drop index t1_01;&lt;br /&gt;&lt;br /&gt;Index dropped.&lt;br /&gt;&lt;br /&gt;SQL&gt; create index t1_01 on t1(id) compress;&lt;br /&gt;&lt;br /&gt;Index created.&lt;br /&gt;&lt;br /&gt;SQL&gt; exec dbms_stats.gather_table_stats('', 't1', estimate_percent =&gt; null, cascade =&gt; true, method_opt =&gt; 'for all columns size 1');&lt;br /&gt;&lt;br /&gt;PL/SQL procedure successfully completed.&lt;br /&gt;&lt;br /&gt;SQL&gt; @check_index_stats&lt;br /&gt;Enter value for index_name: T1_01&lt;br /&gt;old   3: where index_name = '&amp;&amp;index_name'&lt;br /&gt;new   3: where index_name = 'T1_01'&lt;br /&gt;&lt;br /&gt;INDEX_NAME                         BLEVEL LEAF_BLOCKS DISTINCT_KEYS AVG_LEAF_BLOCKS_PER_KEY AVG_DATA_BLOCKS_PER_KEY&lt;br /&gt;------------------------------ ---------- ----------- ------------- ----------------------- -----------------------&lt;br /&gt;  NUM_ROWS CLUSTERING_FACTOR&lt;br /&gt;---------- -----------------&lt;br /&gt;T1_01                                   2        3067       1000000                       1                       1&lt;br /&gt;   1000000             17858&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;old   1: validate index &amp;&amp;index_name&lt;br /&gt;new   1: validate index T1_01&lt;br /&gt;&lt;br /&gt;Index analyzed.&lt;br /&gt;&lt;br /&gt;old   3: where name = '&amp;&amp;index_name'&lt;br /&gt;new   3: where name = 'T1_01'&lt;br /&gt;&lt;br /&gt;NAME                               HEIGHT     BLOCKS    LF_ROWS    LF_BLKS LF_ROWS_LEN LF_BLK_LEN    BR_ROWS    BR_BLKS&lt;br /&gt;------------------------------ ---------- ---------- ---------- ---------- ----------- ---------- ---------- ----------&lt;br /&gt;BR_ROWS_LEN BR_BLK_LEN DEL_LF_ROWS DEL_LF_ROWS_LEN DISTINCT_KEYS MOST_REPEATED_KEY BTREE_SPACE USED_SPACE   PCT_USED&lt;br /&gt;----------- ---------- ----------- --------------- ------------- ----------------- ----------- ---------- ----------&lt;br /&gt;ROWS_PER_KEY BLKS_GETS_PER_ACCESS&lt;br /&gt;------------ --------------------&lt;br /&gt;T1_01                                   3       3200    1000000       3067    11000000       7992       3066          6&lt;br /&gt;      36702       8028           0               0       1000000                 1    24559632   22016504         90&lt;br /&gt;           1                    4&lt;br /&gt;&lt;/pre&gt;As we can see from the above output, the compressed index we created has 3067 leaf blocks and it took nearly 25 MB storage to keep this index. These values are greater than the values that we got when we used non-compressed index.&lt;br /&gt;&lt;br /&gt;Lets now try to query this table by using this compressed index.&lt;br /&gt;&lt;pre class='brush: sql'&gt;SQL&gt; alter system flush buffer_cache;&lt;br /&gt;&lt;br /&gt;System altered.&lt;br /&gt;&lt;br /&gt;SQL&gt; set timing on&lt;br /&gt;SQL&gt; set autot trace&lt;br /&gt;SQL&gt; select * from t1 where id between 100000 and 200000;&lt;br /&gt;&lt;br /&gt;100001 rows selected.&lt;br /&gt;&lt;br /&gt;Elapsed: 00:00:03.31&lt;br /&gt;&lt;br /&gt;Execution Plan&lt;br /&gt;----------------------------------------------------------&lt;br /&gt;Plan hash value: 2362378154&lt;br /&gt;&lt;br /&gt;-------------------------------------------------------------------------------------&lt;br /&gt;| Id  | Operation                   | Name  | Rows  | Bytes | Cost (%CPU)| Time     |&lt;br /&gt;-------------------------------------------------------------------------------------&lt;br /&gt;|   0 | SELECT STATEMENT            |       |   100K|    11M|  2097   (1)| 00:00:26 |&lt;br /&gt;|   1 |  TABLE ACCESS BY INDEX ROWID| T1    |   100K|    11M|  2097   (1)| 00:00:26 |&lt;br /&gt;|*  2 |   INDEX RANGE SCAN          | T1_01 |   100K|       |   310   (1)| 00:00:04 |&lt;br /&gt;-------------------------------------------------------------------------------------&lt;br /&gt;&lt;br /&gt;Predicate Information (identified by operation id):&lt;br /&gt;---------------------------------------------------&lt;br /&gt;&lt;br /&gt;   2 - access("ID"&gt;=100000 AND "ID"&lt;=200000)&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Statistics&lt;br /&gt;----------------------------------------------------------&lt;br /&gt;          1  recursive calls&lt;br /&gt;          0  db block gets&lt;br /&gt;      15292  consistent gets&lt;br /&gt;       2097  physical reads&lt;br /&gt;          0  redo size&lt;br /&gt;   13766300  bytes sent via SQL*Net to client&lt;br /&gt;      73745  bytes received via SQL*Net from client&lt;br /&gt;       6668  SQL*Net roundtrips to/from client&lt;br /&gt;          0  sorts (memory)&lt;br /&gt;          0  sorts (disk)&lt;br /&gt;     100001  rows processed&lt;br /&gt;&lt;br /&gt;SQL&gt; set autot off&lt;br /&gt;SQL&gt; drop index t1_01;&lt;br /&gt;&lt;br /&gt;Index dropped.&lt;br /&gt;&lt;br /&gt;Elapsed: 00:00:00.11&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;As a result, it took 03.31 seconds, 15292  consistent gets and 2097  physical reads to run the query by using this compressed index. These values are greater than the previous test which we used a non-compressed index.&lt;br /&gt;&lt;br /&gt;In that case using a compressed index made situation worse. The reason for this is that, Oracle makes the compression by using an algorithm to tore the index key values only once in every index block in a special structure and put only the reference to this index key in index entries instead of using the index key itself. &lt;br /&gt;&lt;br /&gt;Compressing an index on a column with unique values, causes the index to consume more storage space and it will make the performance worse. Because index will have to write all the key values in the block and keep an extra structure to manage the compressed index.&lt;br /&gt;&lt;br /&gt;We should use the index compression on indexes with less selective columns, so that the number of repeating values for a index key in a block will increase making the index compression more efficient in terms of storage space and performance due to reading and fetching less number of index blocks to the database server memory.&lt;br /&gt;&lt;br /&gt;Indeed, Oracle protects this kind of case to happen, if we had given it some information about this index column. If we try to create the index having only one column as unique and compressed, it will not allow us to do that, since the index compression in that case will not be efficient. It tries to protect us from making mistakes shortly.&lt;br /&gt;&lt;br /&gt;Lets try this &lt;br /&gt;&lt;pre class='brush: sql'&gt;SQL&gt; create unique index t1_01 on t1(id) compress;&lt;br /&gt;create unique index t1_01 on t1(id) compress&lt;br /&gt;                                    *&lt;br /&gt;ERROR at line 1:&lt;br /&gt;ORA-25193: cannot use COMPRESS option for a single column key&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;-------------------&lt;br /&gt;&lt;br /&gt;Lets demonstrate another case where index compression will help to decrease index size and improve the performance.&lt;br /&gt;In this test, we will create a sample table which has a non-selective column with repeating values on which we will create our index.&lt;br /&gt;&lt;br /&gt;&lt;pre class='brush: sql'&gt;SQL&gt; set autot off&lt;br /&gt;SQL&gt; create table t1&lt;br /&gt;  2  as&lt;br /&gt;  3  with generator as (&lt;br /&gt;  4      select  --+ materialize&lt;br /&gt;  5          *&lt;br /&gt;  6      from all_objects&lt;br /&gt;  7  )&lt;br /&gt;  8  select&lt;br /&gt;  9      v1.*&lt;br /&gt; 10  from&lt;br /&gt; 11      generator   v1,&lt;br /&gt; 12      generator   v2&lt;br /&gt; 13  where&lt;br /&gt; 14      rownum &lt;= 1000000&lt;br /&gt; 15  ;&lt;br /&gt;&lt;br /&gt;Table created.&lt;br /&gt;&lt;br /&gt;Elapsed: 00:00:23.85&lt;br /&gt;SQL&gt; create index t1_01 on t1(object_type);&lt;br /&gt;&lt;br /&gt;Index created.&lt;br /&gt;&lt;br /&gt;Elapsed: 00:00:02.80&lt;br /&gt;SQL&gt; exec dbms_stats.gather_table_stats('', 't1', estimate_percent =&gt; null, cascade =&gt; true, method_opt =&gt; 'for all columns size 1');&lt;br /&gt;&lt;br /&gt;PL/SQL procedure successfully completed.&lt;br /&gt;&lt;br /&gt;Elapsed: 00:00:10.38&lt;br /&gt;SQL&gt; @check_index_stats&lt;br /&gt;Enter value for index_name: T1_01&lt;br /&gt;old   3: where index_name = '&amp;&amp;index_name'&lt;br /&gt;new   3: where index_name = 'T1_01'&lt;br /&gt;&lt;br /&gt;INDEX_NAME                         BLEVEL LEAF_BLOCKS DISTINCT_KEYS AVG_LEAF_BLOCKS_PER_KEY AVG_DATA_BLOCKS_PER_KEY&lt;br /&gt;------------------------------ ---------- ----------- ------------- ----------------------- -----------------------&lt;br /&gt;  NUM_ROWS CLUSTERING_FACTOR&lt;br /&gt;---------- -----------------&lt;br /&gt;T1_01                                   2        2391             3                     797                    3800&lt;br /&gt;   1000000             11402&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Elapsed: 00:00:00.02&lt;br /&gt;old   1: validate index &amp;&amp;index_name&lt;br /&gt;new   1: validate index T1_01&lt;br /&gt;&lt;br /&gt;Index analyzed.&lt;br /&gt;&lt;br /&gt;Elapsed: 00:00:00.54&lt;br /&gt;old   3: where name = '&amp;&amp;index_name'&lt;br /&gt;new   3: where name = 'T1_01'&lt;br /&gt;&lt;br /&gt;NAME                               HEIGHT     BLOCKS    LF_ROWS    LF_BLKS LF_ROWS_LEN LF_BLK_LEN    BR_ROWS    BR_BLKS&lt;br /&gt;------------------------------ ---------- ---------- ---------- ---------- ----------- ---------- ---------- ----------&lt;br /&gt;BR_ROWS_LEN BR_BLK_LEN DEL_LF_ROWS DEL_LF_ROWS_LEN DISTINCT_KEYS MOST_REPEATED_KEY BTREE_SPACE USED_SPACE   PCT_USED&lt;br /&gt;----------- ---------- ----------- --------------- ------------- ----------------- ----------- ---------- ----------&lt;br /&gt;ROWS_PER_KEY BLKS_GETS_PER_ACCESS&lt;br /&gt;------------ --------------------&lt;br /&gt;T1_01                                   3       2560    1000000       2391    17147394       7996       2390          7&lt;br /&gt;      45746       8028           0               0             3            484121    19174632   17193140         90&lt;br /&gt;  333333.333           166670.167&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Elapsed: 00:00:00.19&lt;br /&gt;&lt;/pre&gt;This index has 2391 leaf blocks, takes nearly 19 MB storage space.&lt;br /&gt;&lt;br /&gt;Lets try to query the table using this index.&lt;br /&gt;&lt;pre class='brush: sql'&gt;SQL&gt; alter system flush buffer_cache;&lt;br /&gt;&lt;br /&gt;System altered.&lt;br /&gt;&lt;br /&gt;Elapsed: 00:00:00.18&lt;br /&gt;SQL&gt; set autot trace&lt;br /&gt;SQL&gt; select object_type, count(*) from t1 group by object_type order by object_type;&lt;br /&gt;&lt;br /&gt;Elapsed: 00:00:00.35&lt;br /&gt;&lt;br /&gt;Execution Plan&lt;br /&gt;----------------------------------------------------------&lt;br /&gt;Plan hash value: 3946799371&lt;br /&gt;&lt;br /&gt;---------------------------------------------------------------------------&lt;br /&gt;| Id  | Operation          | Name | Rows  | Bytes | Cost (%CPU)| Time     |&lt;br /&gt;---------------------------------------------------------------------------&lt;br /&gt;|   0 | SELECT STATEMENT   |      |     3 |    21 |  3168   (2)| 00:00:39 |&lt;br /&gt;|   1 |  SORT GROUP BY     |      |     3 |    21 |  3168   (2)| 00:00:39 |&lt;br /&gt;|   2 |   TABLE ACCESS FULL| T1   |  1000K|  6835K|  3139   (1)| 00:00:38 |&lt;br /&gt;---------------------------------------------------------------------------&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Statistics&lt;br /&gt;----------------------------------------------------------&lt;br /&gt;          1  recursive calls&lt;br /&gt;          0  db block gets&lt;br /&gt;      11397  consistent gets&lt;br /&gt;      11395  physical reads&lt;br /&gt;          0  redo size&lt;br /&gt;        551  bytes sent via SQL*Net to client&lt;br /&gt;        419  bytes received via SQL*Net from client&lt;br /&gt;          2  SQL*Net roundtrips to/from client&lt;br /&gt;          1  sorts (memory)&lt;br /&gt;          0  sorts (disk)&lt;br /&gt;          3  rows processed&lt;br /&gt;&lt;/pre&gt;Oracle chose Full Table Scan (FTS) because the index column "object_type" is not defined as a "NOT NULL" column and Oracle thinks that there maybe null values which are not in the index but in the table and do not use index. To force Oracle use index, we will make "object_type" column "NOT NULL".&lt;br /&gt;&lt;br /&gt;&lt;pre class='brush: sql'&gt;SQL&gt; alter table t1 modify object_type not null;&lt;br /&gt;&lt;br /&gt;Table altered.&lt;br /&gt;&lt;br /&gt;Elapsed: 00:00:00.29&lt;br /&gt;SQL&gt; alter system flush buffer_cache;&lt;br /&gt;&lt;br /&gt;System altered.&lt;br /&gt;&lt;br /&gt;Elapsed: 00:00:00.06&lt;br /&gt;SQL&gt; select object_type, count(*) from t1 group by object_type order by object_type;&lt;br /&gt;&lt;br /&gt;Elapsed: 00:00:00.35&lt;br /&gt;&lt;br /&gt;Execution Plan&lt;br /&gt;----------------------------------------------------------&lt;br /&gt;Plan hash value: 2450666175&lt;br /&gt;&lt;br /&gt;-------------------------------------------------------------------------------&lt;br /&gt;| Id  | Operation             | Name  | Rows  | Bytes | Cost (%CPU)| Time     |&lt;br /&gt;-------------------------------------------------------------------------------&lt;br /&gt;|   0 | SELECT STATEMENT      |       |     3 |    21 |   682   (5)| 00:00:09 |&lt;br /&gt;|   1 |  SORT GROUP BY        |       |     3 |    21 |   682   (5)| 00:00:09 |&lt;br /&gt;|   2 |   INDEX FAST FULL SCAN| T1_01 |  1000K|  6835K|   653   (1)| 00:00:08 |&lt;br /&gt;-------------------------------------------------------------------------------&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Statistics&lt;br /&gt;----------------------------------------------------------&lt;br /&gt;         74  recursive calls&lt;br /&gt;          0  db block gets&lt;br /&gt;       2473  consistent gets&lt;br /&gt;       2415  physical reads&lt;br /&gt;          0  redo size&lt;br /&gt;        551  bytes sent via SQL*Net to client&lt;br /&gt;        419  bytes received via SQL*Net from client&lt;br /&gt;          2  SQL*Net roundtrips to/from client&lt;br /&gt;          7  sorts (memory)&lt;br /&gt;          0  sorts (disk)&lt;br /&gt;          3  rows processed&lt;br /&gt;&lt;/pre&gt;Now Oracle uses this index. It takes 00.35 seconds, 2473  consistent gets and 2415  physical reads to get the final 3 rows.&lt;br /&gt;&lt;br /&gt;Now try to recreate the index as compressed.&lt;br /&gt;&lt;pre class='brush: sql'&gt;SQL&gt; drop index t1_01;&lt;br /&gt;&lt;br /&gt;Index dropped.&lt;br /&gt;&lt;br /&gt;Elapsed: 00:00:00.13&lt;br /&gt;SQL&gt; create index t1_01 on t1(object_type) compress;&lt;br /&gt;&lt;br /&gt;Index created.&lt;br /&gt;&lt;br /&gt;Elapsed: 00:00:02.18&lt;br /&gt;SQL&gt; exec dbms_stats.gather_table_stats('', 't1', estimate_percent =&gt; null, cascade =&gt; true, method_opt =&gt; 'for all columns size 1');&lt;br /&gt;&lt;br /&gt;PL/SQL procedure successfully completed.&lt;br /&gt;&lt;br /&gt;Elapsed: 00:00:10.07&lt;br /&gt;SQL&gt; set autot off&lt;br /&gt;SQL&gt; @check_index_stats&lt;br /&gt;Enter value for index_name: T1_01&lt;br /&gt;old   3: where index_name = '&amp;&amp;index_name'&lt;br /&gt;new   3: where index_name = 'T1_01'&lt;br /&gt;&lt;br /&gt;INDEX_NAME                         BLEVEL LEAF_BLOCKS DISTINCT_KEYS AVG_LEAF_BLOCKS_PER_KEY AVG_DATA_BLOCKS_PER_KEY&lt;br /&gt;------------------------------ ---------- ----------- ------------- ----------------------- -----------------------&lt;br /&gt;  NUM_ROWS CLUSTERING_FACTOR&lt;br /&gt;---------- -----------------&lt;br /&gt;T1_01                                   2        1537             3                     512                    3800&lt;br /&gt;   1000000             11402&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Elapsed: 00:00:00.01&lt;br /&gt;old   1: validate index &amp;&amp;index_name&lt;br /&gt;new   1: validate index T1_01&lt;br /&gt;&lt;br /&gt;Index analyzed.&lt;br /&gt;&lt;br /&gt;Elapsed: 00:00:00.56&lt;br /&gt;old   3: where name = '&amp;&amp;index_name'&lt;br /&gt;new   3: where name = 'T1_01'&lt;br /&gt;&lt;br /&gt;NAME                               HEIGHT     BLOCKS    LF_ROWS    LF_BLKS LF_ROWS_LEN LF_BLK_LEN    BR_ROWS    BR_BLKS&lt;br /&gt;------------------------------ ---------- ---------- ---------- ---------- ----------- ---------- ---------- ----------&lt;br /&gt;BR_ROWS_LEN BR_BLK_LEN DEL_LF_ROWS DEL_LF_ROWS_LEN DISTINCT_KEYS MOST_REPEATED_KEY BTREE_SPACE USED_SPACE   PCT_USED&lt;br /&gt;----------- ---------- ----------- --------------- ------------- ----------------- ----------- ---------- ----------&lt;br /&gt;ROWS_PER_KEY BLKS_GETS_PER_ACCESS&lt;br /&gt;------------ --------------------&lt;br /&gt;T1_01                                   3       1664    1000000       1537    11000000       7992       1536          5&lt;br /&gt;      29374       8028           0               0             3            484121    12323844   11048070         90&lt;br /&gt;  333333.333           166670.167&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Elapsed: 00:00:00.05&lt;br /&gt;&lt;/pre&gt;The new compressed index has 1537 leaf blocks, taking nearly 12 MB storage space and this is nearly half of the uncompressed index size. Also pay attention, how AVG_LEAF_BLOCKS_PER_KEY values got down from 797 to 512, which shows average index leaf blocks needed to store each index key.&lt;br /&gt;&lt;br /&gt;Lets go on running the SQL by using this compressed index.&lt;br /&gt;&lt;pre class='brush: sql'&gt;SQL&gt; set autot trace&lt;br /&gt;SQL&gt; alter system flush buffer_cache;&lt;br /&gt;&lt;br /&gt;System altered.&lt;br /&gt;&lt;br /&gt;Elapsed: 00:00:00.07&lt;br /&gt;SQL&gt; select object_type, count(*) from t1 group by object_type order by object_type;&lt;br /&gt;&lt;br /&gt;Elapsed: 00:00:00.28&lt;br /&gt;&lt;br /&gt;Execution Plan&lt;br /&gt;----------------------------------------------------------&lt;br /&gt;Plan hash value: 2450666175&lt;br /&gt;&lt;br /&gt;-------------------------------------------------------------------------------&lt;br /&gt;| Id  | Operation             | Name  | Rows  | Bytes | Cost (%CPU)| Time     |&lt;br /&gt;-------------------------------------------------------------------------------&lt;br /&gt;|   0 | SELECT STATEMENT      |       |     3 |    21 |   451   (8)| 00:00:06 |&lt;br /&gt;|   1 |  SORT GROUP BY        |       |     3 |    21 |   451   (8)| 00:00:06 |&lt;br /&gt;|   2 |   INDEX FAST FULL SCAN| T1_01 |  1000K|  6835K|   422   (1)| 00:00:06 |&lt;br /&gt;-------------------------------------------------------------------------------&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Statistics&lt;br /&gt;----------------------------------------------------------&lt;br /&gt;          1  recursive calls&lt;br /&gt;          0  db block gets&lt;br /&gt;       1550  consistent gets&lt;br /&gt;       1543  physical reads&lt;br /&gt;          0  redo size&lt;br /&gt;        551  bytes sent via SQL*Net to client&lt;br /&gt;        419  bytes received via SQL*Net from client&lt;br /&gt;          2  SQL*Net roundtrips to/from client&lt;br /&gt;          1  sorts (memory)&lt;br /&gt;          0  sorts (disk)&lt;br /&gt;          3  rows processed&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;This time query took 00.28 seconds which is not too much faster than using a non-compressed index but still faster. Physical reads which are very expensive went down from 2415 to 1543. By using compressed index we saved some index storage and performance of some SQLs.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6717103620143238053-2726989135111005698?l=uralural.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://uralural.blogspot.com/feeds/2726989135111005698/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6717103620143238053&amp;postID=2726989135111005698' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6717103620143238053/posts/default/2726989135111005698'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6717103620143238053/posts/default/2726989135111005698'/><link rel='alternate' type='text/html' href='http://uralural.blogspot.com/2011/07/will-index-compression-help-us-or-not.html' title='Will index compression help us or not ?'/><author><name>Ural Ural</name><uri>http://www.blogger.com/profile/06556787053001681445</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='19' height='32' src='http://2.bp.blogspot.com/-FS7mo23hHG0/TjlVoo70i9I/AAAAAAAABwQ/mlpdh17_nwM/s220/IMAG0008.jpg'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6717103620143238053.post-3127440665643150173</id><published>2011-07-17T11:06:00.000-07:00</published><updated>2011-07-17T11:07:42.453-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='case'/><category scheme='http://www.blogger.com/atom/ns#' term='index_stats'/><category scheme='http://www.blogger.com/atom/ns#' term='function-based index'/><title type='text'>Indexing only the needed column values to save index space and also to improve the performance</title><content type='html'>You can reduce the index space and also improve the performance of specific SQL statements by indexing only a specific value of a column by using function-based indexes in Oracle.&lt;br /&gt;&lt;br /&gt;Below is a demonstration related to this.&lt;br /&gt;&lt;br /&gt;First create a sample schema.&lt;br /&gt;&lt;pre class='brush: sql'&gt;[oracle@localhost uural]$ sqlplus / as sysdba&lt;br /&gt;&lt;br /&gt;SQL*Plus: Release 11.1.0.7.0 - Production on Sun Jul 17 05:01:51 2011&lt;br /&gt;&lt;br /&gt;Copyright (c) 1982, 2008, Oracle.  All rights reserved.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Connected to:&lt;br /&gt;Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - Production&lt;br /&gt;With the Partitioning, OLAP, Data Mining and Real Application Testing options&lt;br /&gt;&lt;br /&gt;SQL&gt; @cre_user-U0001&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;User dropped.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;User created.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Grant succeeded.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;User altered.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Grant succeeded.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Grant succeeded.&lt;br /&gt;&lt;br /&gt;SQL&gt; !more cre_user-U0001.sql&lt;br /&gt;drop user u0001 cascade;&lt;br /&gt;create user u0001 identified by u0001;&lt;br /&gt;grant create session to u0001;&lt;br /&gt;alter user u0001 quota 5G on users;&lt;br /&gt;grant create table to u0001;&lt;br /&gt;grant dba to u0001;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Create a sample table with 1,000,000 rows with a status column which has the value of 'CLOSED'.&lt;br /&gt;&lt;pre class='brush: sql'&gt;SQL&gt; conn u0001/u0001&lt;br /&gt;Connected.&lt;br /&gt;SQL&gt; create table t1 as&lt;br /&gt;  2  select&lt;br /&gt;  3    rownum id,&lt;br /&gt;  dbms_random.string('U',6) v1,&lt;br /&gt;  4    5    lpad(rownum,10) v2,&lt;br /&gt;  6    rpad('x',100) padding,&lt;br /&gt;  7    'CLOSED' status&lt;br /&gt;  8  from&lt;br /&gt;  dual&lt;br /&gt;  9   10  connect by level &lt;= 1000000;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Table created.&lt;br /&gt;&lt;br /&gt;SQL&gt; desc t1&lt;br /&gt; Name                                      Null?    Type&lt;br /&gt; ----------------------------------------- -------- ----------------------------&lt;br /&gt; ID                                                 NUMBER&lt;br /&gt; V1                                                 VARCHAR2(4000)&lt;br /&gt; V2                                                 VARCHAR2(40)&lt;br /&gt; PADDING                                            VARCHAR2(100)&lt;br /&gt; STATUS                                             CHAR(6)&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Now insert some 100 rows which have the status column as 'OPEN'.&lt;br /&gt;&lt;pre class='brush: sql'&gt;SQL&gt; insert into t1&lt;br /&gt;  2  select&lt;br /&gt;  3    rownum id,&lt;br /&gt;  4    dbms_random.string('U',6) v1,&lt;br /&gt;  5    lpad(rownum,10) v2,&lt;br /&gt;  6    rpad('x',100) padding,&lt;br /&gt;  7    'OPEN' status&lt;br /&gt;  8  from&lt;br /&gt;  9    dual&lt;br /&gt; 10  connect by level &lt;= 100;&lt;br /&gt;&lt;br /&gt;100 rows created.&lt;br /&gt;&lt;br /&gt;SQL&gt; commit;&lt;br /&gt;&lt;br /&gt;Commit complete.&lt;br /&gt;&lt;br /&gt;SQL&gt; exec dbms_stats.gather_table_stats('','t1',estimate_percent =&gt; null,cascade =&gt; true,method_opt =&gt; 'for all columns size 1');&lt;br /&gt;&lt;br /&gt;PL/SQL procedure successfully completed.&lt;br /&gt;&lt;br /&gt;SQL&gt; set autot trace&lt;br /&gt;SQL&gt; sho autot&lt;br /&gt;autotrace TRACEONLY EXPLAIN STATISTICS&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Create an index on status column.&lt;br /&gt;&lt;pre class='brush: sql'&gt;SQL&gt; create index t1_01 on t1(status);&lt;br /&gt;&lt;br /&gt;Index created.&lt;br /&gt;&lt;br /&gt;SQL&gt; exec dbms_stats.gather_table_stats('','t1',estimate_percent =&gt; null,cascade =&gt; true,method_opt =&gt; 'for all columns size 1');&lt;br /&gt;&lt;br /&gt;PL/SQL procedure successfully completed.&lt;br /&gt;&lt;br /&gt;SQL&gt; alter system flush buffer_cache;&lt;br /&gt;&lt;br /&gt;System altered.&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Query the the rows which has the status column with the value 'OPEN'.&lt;br /&gt;&lt;pre class='brush: sql'&gt;SQL&gt; set timing on&lt;br /&gt;SQL&gt; select * from t1 where status = 'OPEN';&lt;br /&gt;&lt;br /&gt;100 rows selected.&lt;br /&gt;&lt;br /&gt;Elapsed: 00:00:01.94&lt;br /&gt;&lt;br /&gt;Execution Plan&lt;br /&gt;----------------------------------------------------------&lt;br /&gt;Plan hash value: 3617692013&lt;br /&gt;&lt;br /&gt;--------------------------------------------------------------------------&lt;br /&gt;| Id  | Operation         | Name | Rows  | Bytes | Cost (%CPU)| Time     |&lt;br /&gt;--------------------------------------------------------------------------&lt;br /&gt;|   0 | SELECT STATEMENT  |      |   500K|    62M|  5220   (1)| 00:01:03 |&lt;br /&gt;|*  1 |  TABLE ACCESS FULL| T1   |   500K|    62M|  5220   (1)| 00:01:03 |&lt;br /&gt;--------------------------------------------------------------------------&lt;br /&gt;&lt;br /&gt;Predicate Information (identified by operation id):&lt;br /&gt;---------------------------------------------------&lt;br /&gt;&lt;br /&gt;   1 - filter("STATUS"='OPEN')&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Statistics&lt;br /&gt;----------------------------------------------------------&lt;br /&gt;          1  recursive calls&lt;br /&gt;          0  db block gets&lt;br /&gt;      18897  consistent gets&lt;br /&gt;      18887  physical reads&lt;br /&gt;          0  redo size&lt;br /&gt;       4229  bytes sent via SQL*Net to client&lt;br /&gt;        485  bytes received via SQL*Net from client&lt;br /&gt;          8  SQL*Net roundtrips to/from client&lt;br /&gt;          0  sorts (memory)&lt;br /&gt;          0  sorts (disk)&lt;br /&gt;        100  rows processed&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;As you can see the CBO did not use the index on status column most probably because of the low distinct values and low selectivity of the "status" column. It did 18887 "physical reads" and 18897 "consistent gets" and it took "01.94" seconds to get the result.&lt;br /&gt;&lt;br /&gt;Now try to give a hint to make the CBO use the index on "status" column.&lt;br /&gt;&lt;pre class='brush: sql'&gt;SQL&gt; alter system flush buffer_cache;&lt;br /&gt;&lt;br /&gt;System altered.&lt;br /&gt;&lt;br /&gt;Elapsed: 00:00:00.25&lt;br /&gt;SQL&gt; alter system flush buffer_cache;&lt;br /&gt;&lt;br /&gt;System altered.&lt;br /&gt;&lt;br /&gt;Elapsed: 00:00:00.02&lt;br /&gt;&lt;br /&gt;SQL&gt; select /*+ index(t, t1_01)*/ * from t1 t where status = 'OPEN';&lt;br /&gt;&lt;br /&gt;100 rows selected.&lt;br /&gt;&lt;br /&gt;Elapsed: 00:00:00.04&lt;br /&gt;&lt;br /&gt;Execution Plan&lt;br /&gt;----------------------------------------------------------&lt;br /&gt;Plan hash value: 2362378154&lt;br /&gt;&lt;br /&gt;-------------------------------------------------------------------------------------&lt;br /&gt;| Id  | Operation                   | Name  | Rows  | Bytes | Cost (%CPU)| Time    |&lt;br /&gt;-------------------------------------------------------------------------------------&lt;br /&gt;|   0 | SELECT STATEMENT            |       |   500K|    62M| 10703   (1)| 00:02:09 |&lt;br /&gt;|   1 |  TABLE ACCESS BY INDEX ROWID| T1    |   500K|    62M| 10703   (1)| 00:02:09 |&lt;br /&gt;|*  2 |   INDEX RANGE SCAN          | T1_01 |   500K|       |  1262   (1)| 00:00:16 |&lt;br /&gt;-------------------------------------------------------------------------------------&lt;br /&gt;&lt;br /&gt;Predicate Information (identified by operation id):&lt;br /&gt;---------------------------------------------------&lt;br /&gt;&lt;br /&gt;   2 - access("STATUS"='OPEN')&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Statistics&lt;br /&gt;----------------------------------------------------------&lt;br /&gt;          1  recursive calls&lt;br /&gt;          0  db block gets&lt;br /&gt;         19  consistent gets&lt;br /&gt;          5  physical reads&lt;br /&gt;          0  redo size&lt;br /&gt;      14839  bytes sent via SQL*Net to client&lt;br /&gt;        485  bytes received via SQL*Net from client&lt;br /&gt;          8  SQL*Net roundtrips to/from client&lt;br /&gt;          0  sorts (memory)&lt;br /&gt;          0  sorts (disk)&lt;br /&gt;        100  rows processed&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;As you can see above, CBO used the index and did 5 "physical reads" and 19 "consistent gets" and query took "00.04" seconds although the CBO computed the cost higher then Full Table Scan (FTS).&lt;br /&gt;&lt;br /&gt;Lets look at the index structure&lt;br /&gt;&lt;pre class='brush: sql'&gt;SQL&gt; set autot off&lt;br /&gt;&lt;br /&gt;SQL&gt; select BLEVEL, LEAF_BLOCKS, DISTINCT_KEYS, AVG_LEAF_BLOCKS_PER_KEY, AVG_DATA_BLOCKS_PER_KEY, NUM_ROWS from user_indexes where index_name = 'T1_01';&lt;br /&gt;&lt;br /&gt;    BLEVEL LEAF_BLOCKS DISTINCT_KEYS AVG_LEAF_BLOCKS_PER_KEY&lt;br /&gt;---------- ----------- ------------- -----------------------&lt;br /&gt;AVG_DATA_BLOCKS_PER_KEY   NUM_ROWS&lt;br /&gt;----------------------- ----------&lt;br /&gt;         2        2513             2                    1256&lt;br /&gt;                   9435    1000100&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Elapsed: 00:00:00.06&lt;br /&gt;SQL&gt; validate index t1_01;&lt;br /&gt;&lt;br /&gt;Index analyzed.&lt;br /&gt;&lt;br /&gt;Elapsed: 00:00:01.45&lt;br /&gt;&lt;br /&gt;SQL&gt; select HEIGHT,BLOCKS,LF_ROWS,LF_BLKS,BR_ROWS,BR_BLKS,DEL_LF_ROWS,DISTINCT_KEYS,USED_SPACE,PCT_USED,ROWS_PER_KEY,BLKS_GETS_PER_ACCESS from index_stats;&lt;br /&gt;&lt;br /&gt;    HEIGHT     BLOCKS    LF_ROWS    LF_BLKS    BR_ROWS    BR_BLKS DEL_LF_ROWS&lt;br /&gt;---------- ---------- ---------- ---------- ---------- ---------- -----------&lt;br /&gt;DISTINCT_KEYS USED_SPACE   PCT_USED ROWS_PER_KEY BLKS_GETS_PER_ACCESS&lt;br /&gt;------------- ---------- ---------- ------------ --------------------&lt;br /&gt;         3       2688    1000100       2513       2512          8           0&lt;br /&gt;            2   18051946         90       500050             250028.5&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Elapsed: 00:00:00.73&lt;br /&gt;&lt;/pre&gt;You can see from the index stats that, this index ha 2513 leaf blocks which takes about 18 MB storage space. &lt;br /&gt;&lt;br /&gt;Lets now drop this index and create a function-based index on "status" column but for only the value that we are interested in.&lt;br /&gt;&lt;pre class='brush: sql'&gt;SQL&gt; drop index t1_01;&lt;br /&gt;&lt;br /&gt;Index dropped.&lt;br /&gt;&lt;br /&gt;Elapsed: 00:00:00.60&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;We use the CASE statement, to tell Oracle that we only want the rows whose status column is "OPEN" to be indexed. Since the CASE will return NULL value for other values these rows' rowids will not be kept in the index structure. &lt;br /&gt;&lt;pre class='brush: sql'&gt;SQL&gt; create index t1_01 on t1(case when status = 'OPEN' then status else null end);&lt;br /&gt;&lt;br /&gt;Index created.&lt;br /&gt;&lt;br /&gt;Elapsed: 00:00:01.87&lt;br /&gt;SQL&gt; exec dbms_stats.gather_table_stats('','t1',estimate_percent =&gt; null,cascade =&gt; true,method_opt =&gt; 'for all columns size 1');&lt;br /&gt;&lt;br /&gt;PL/SQL procedure successfully completed.&lt;br /&gt;&lt;br /&gt;Elapsed: 00:00:17.51&lt;br /&gt;SQL&gt; alter system flush buffer_cache;&lt;br /&gt;&lt;br /&gt;System altered.&lt;br /&gt;&lt;br /&gt;Elapsed: 00:00:00.11&lt;br /&gt;SQL&gt; set autot trace&lt;br /&gt;&lt;br /&gt;SQL&gt; SQL&gt; sho autot&lt;br /&gt;autotrace TRACEONLY EXPLAIN STATISTICS&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Now we need to use the same statement that we used while creating the function-based index, in the where condition of our query to make it use the new index. &lt;br /&gt;&lt;pre class='brush: sql'&gt;SQL&gt; select * from t1 where (case when status = 'OPEN' then status else null end) = 'OPEN';&lt;br /&gt;&lt;br /&gt;100 rows selected.&lt;br /&gt;&lt;br /&gt;Elapsed: 00:00:00.03&lt;br /&gt;&lt;br /&gt;Execution Plan&lt;br /&gt;----------------------------------------------------------&lt;br /&gt;Plan hash value: 2362378154&lt;br /&gt;&lt;br /&gt;-------------------------------------------------------------------------------------&lt;br /&gt;| Id  | Operation                   | Name  | Rows  | Bytes | Cost (%CPU)| Time    |&lt;br /&gt;-------------------------------------------------------------------------------------&lt;br /&gt;|   0 | SELECT STATEMENT            |       |   100 | 13200 |     3   (0)| 00:00:01 |&lt;br /&gt;|   1 |  TABLE ACCESS BY INDEX ROWID| T1    |   100 | 13200 |     3   (0)| 00:00:01 |&lt;br /&gt;|*  2 |   INDEX RANGE SCAN          | T1_01 |   100 |       |     1   (0)| 00:00:01 |&lt;br /&gt;-------------------------------------------------------------------------------------&lt;br /&gt;&lt;br /&gt;Predicate Information (identified by operation id):&lt;br /&gt;---------------------------------------------------&lt;br /&gt;&lt;br /&gt;   2 - access(CASE  WHEN "STATUS"='OPEN' THEN "STATUS" ELSE NULL END ='OPEN')&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Statistics&lt;br /&gt;----------------------------------------------------------&lt;br /&gt;          8  recursive calls&lt;br /&gt;          0  db block gets&lt;br /&gt;         19  consistent gets&lt;br /&gt;          4  physical reads&lt;br /&gt;          0  redo size&lt;br /&gt;       4229  bytes sent via SQL*Net to client&lt;br /&gt;        485  bytes received via SQL*Net from client&lt;br /&gt;          8  SQL*Net roundtrips to/from client&lt;br /&gt;          0  sorts (memory)&lt;br /&gt;          0  sorts (disk)&lt;br /&gt;        100  rows processed&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;From the trace we see that this statement did 4 "physical reads", 19 "consistent gets" and completed in "00.03" seconds. These values are very close to the values we got from the test using the non function-based index before.&lt;br /&gt;But what about the storage space that this new index uses, lets check.&lt;br /&gt;&lt;pre class='brush: sql'&gt;SQL&gt; set autot off&lt;br /&gt;SQL&gt; select BLEVEL, LEAF_BLOCKS, DISTINCT_KEYS, AVG_LEAF_BLOCKS_PER_KEY, AVG_DATA_BLOCKS_PER_KEY, NUM_ROWS from user_indexes where index_name = 'T1_01';&lt;br /&gt;&lt;br /&gt;    BLEVEL LEAF_BLOCKS DISTINCT_KEYS AVG_LEAF_BLOCKS_PER_KEY&lt;br /&gt;---------- ----------- ------------- -----------------------&lt;br /&gt;AVG_DATA_BLOCKS_PER_KEY   NUM_ROWS&lt;br /&gt;----------------------- ----------&lt;br /&gt;         0           1             1                       1&lt;br /&gt;                      2        100&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Elapsed: 00:00:00.01&lt;br /&gt;SQL&gt; validate index t1_01;&lt;br /&gt;&lt;br /&gt;Index analyzed.&lt;br /&gt;&lt;br /&gt;Elapsed: 00:00:00.04&lt;br /&gt;SQL&gt; select HEIGHT,BLOCKS,LF_ROWS,LF_BLKS,BR_ROWS,BR_BLKS,DEL_LF_ROWS,DISTINCT_KEYS,USED_SPACE,PCT_USED,ROWS_PER_KEY,BLKS_GETS_PER_ACCESS from index_stats;&lt;br /&gt;&lt;br /&gt;    HEIGHT     BLOCKS    LF_ROWS    LF_BLKS    BR_ROWS    BR_BLKS DEL_LF_ROWS&lt;br /&gt;---------- ---------- ---------- ---------- ---------- ---------- -----------&lt;br /&gt;DISTINCT_KEYS USED_SPACE   PCT_USED ROWS_PER_KEY BLKS_GETS_PER_ACCESS&lt;br /&gt;------------- ---------- ---------- ------------ --------------------&lt;br /&gt;         1          8        100          1          0          0           0&lt;br /&gt;            1       1800         23          100                 51.5&lt;br /&gt;&lt;br /&gt;Elapsed: 00:00:00.04&lt;br /&gt;&lt;/pre&gt;As we can see, this new function-based index has only 1 leaf blocks and takes only 1.8 KB storage space which is far less compared to the values of non function-based index which took around 18 MB.&lt;br /&gt;&lt;br /&gt;Now we can go one step further, suppose instead of having a status column, we have two date columns named "date_to_be_processed" and "date_processed". Every row is inserted by a batch process with their date_to_be_processed column set to a specific date normally one day later and when tomorrow comes another job selects only the rows with their "date_to_be_processed" column set to this date and "date_processed" column is set to "NULL". In that case we are not interested in the column which their "date_processed" values set already. Below is the demonstration of that case.  &lt;br /&gt;&lt;br /&gt;&lt;pre class='brush: sql'&gt;SQL&gt; alter table t1 drop column status;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Table altered.&lt;br /&gt;&lt;br /&gt;Elapsed: 00:02:00.87&lt;br /&gt;&lt;br /&gt;SQL&gt; alter table t1 add (date_processed date);&lt;br /&gt;&lt;br /&gt;Table altered.&lt;br /&gt;&lt;br /&gt;Elapsed: 00:00:00.38&lt;br /&gt;SQL&gt; alter table t1 add (date_to_be_processed date);&lt;br /&gt;&lt;br /&gt;Table altered.&lt;br /&gt;&lt;br /&gt;Elapsed: 00:00:00.05&lt;br /&gt;SQL&gt; truncate table t1;&lt;br /&gt;&lt;br /&gt;Table truncated.&lt;br /&gt;&lt;br /&gt;Elapsed: 00:00:02.35&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;We insert 1,000,000 rows which their "date_processed" columns are set. Every day has 100 rows processed.&lt;br /&gt;&lt;pre class='brush: sql'&gt;SQL&gt; insert into t1&lt;br /&gt;  2      select&lt;br /&gt;  3        rownum id,&lt;br /&gt;  4        dbms_random.string('U',6) v1,&lt;br /&gt;  5        lpad(rownum,10) v2,&lt;br /&gt;  6        rpad('x',100) padding,&lt;br /&gt;  7        trunc(sysdate) - (10000 - trunc((rownum-1)/100)) date_processed,&lt;br /&gt;      trunc(sysdate) - (10000 - trunc((rownum-1)/100)) date_to_be_processed&lt;br /&gt;  8    9      from&lt;br /&gt; 10       dual&lt;br /&gt; 11     connect by level &lt;= 1000000;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;1000000 rows created.&lt;br /&gt;&lt;br /&gt;Elapsed: 00:01:04.80&lt;br /&gt;SQL&gt; set pause on&lt;br /&gt;SQL&gt; select date_processed, count(*) from t1 group by date_processed order by date_processed;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;DATE_PROC   COUNT(*)&lt;br /&gt;--------- ----------&lt;br /&gt;29-FEB-84        100&lt;br /&gt;01-MAR-84        100&lt;br /&gt;02-MAR-84        100&lt;br /&gt;03-MAR-84        100&lt;br /&gt;04-MAR-84        100&lt;br /&gt;05-MAR-84        100&lt;br /&gt;06-MAR-84        100&lt;br /&gt;07-MAR-84        100&lt;br /&gt;08-MAR-84        100&lt;br /&gt;09-MAR-84        100&lt;br /&gt;10-MAR-84        100&lt;br /&gt;11-MAR-84        100&lt;br /&gt;...&lt;br /&gt;Ctrl+C&lt;br /&gt;13 rows selected.&lt;br /&gt;&lt;br /&gt;Elapsed: 00:00:05.70&lt;br /&gt;&lt;br /&gt;SQL&gt; select date_processed, count(*) from t1 group by date_processed order by date_processed desc;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;DATE_PROC   COUNT(*)&lt;br /&gt;--------- ----------&lt;br /&gt;16-JUL-11        100&lt;br /&gt;15-JUL-11        100&lt;br /&gt;14-JUL-11        100&lt;br /&gt;13-JUL-11        100&lt;br /&gt;12-JUL-11        100&lt;br /&gt;11-JUL-11        100&lt;br /&gt;10-JUL-11        100&lt;br /&gt;09-JUL-11        100&lt;br /&gt;08-JUL-11        100&lt;br /&gt;07-JUL-11        100&lt;br /&gt;06-JUL-11        100&lt;br /&gt;05-JUL-11        100&lt;br /&gt;...&lt;br /&gt;Ctrl+C&lt;br /&gt;13 rows selected.&lt;br /&gt;&lt;br /&gt;Elapsed: 00:00:04.60&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Now insert some 100 rows which should be processed today with their "date_processed" columnsset to "NULL".&lt;br /&gt;&lt;pre class='brush: sql'&gt;SQL&gt;  insert into t1&lt;br /&gt;  2      select&lt;br /&gt;  3        rownum id,&lt;br /&gt;  4        dbms_random.string('U',6) v1,&lt;br /&gt;  5        lpad(rownum,10) v2,&lt;br /&gt;  6        rpad('x',100) padding,&lt;br /&gt;  7        null date_processed,&lt;br /&gt;  8        trunc(sysdate) date_to_be_processed&lt;br /&gt;  9      from&lt;br /&gt; 10       dual&lt;br /&gt; 11     connect by level &lt;= 100;&lt;br /&gt;&lt;br /&gt;100 rows created.&lt;br /&gt;&lt;br /&gt;Elapsed: 00:00:00.04&lt;br /&gt;SQL&gt; commit;&lt;br /&gt;&lt;br /&gt;Commit complete.&lt;br /&gt;&lt;br /&gt;Elapsed: 00:00:00.00&lt;br /&gt;SQL&gt; select date_processed, count(*) from t1 group by date_processed order by date_processed desc;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;DATE_PROC   COUNT(*)&lt;br /&gt;--------- ----------&lt;br /&gt;                 100&lt;br /&gt;16-JUL-11        100&lt;br /&gt;15-JUL-11        100&lt;br /&gt;14-JUL-11        100&lt;br /&gt;13-JUL-11        100&lt;br /&gt;12-JUL-11        100&lt;br /&gt;11-JUL-11        100&lt;br /&gt;10-JUL-11        100&lt;br /&gt;09-JUL-11        100&lt;br /&gt;08-JUL-11        100&lt;br /&gt;07-JUL-11        100&lt;br /&gt;06-JUL-11        100&lt;br /&gt;...&lt;br /&gt;Ctrl+C&lt;br /&gt;13 rows selected.&lt;br /&gt;&lt;br /&gt;Elapsed: 00:00:07.02&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Create a regular composite index on these columns as we could normally do.&lt;br /&gt;&lt;pre class='brush: sql'&gt;SQL&gt; create index t1_01 on t1(date_processed, date_to_be_processed);&lt;br /&gt;&lt;br /&gt;Index created.&lt;br /&gt;&lt;br /&gt;Elapsed: 00:00:04.99&lt;br /&gt;SQL&gt; exec dbms_stats.gather_table_stats('','t1',estimate_percent =&gt; null,cascade =&gt; true,method_opt =&gt; 'for all columns size 1');&lt;br /&gt;&lt;br /&gt;PL/SQL procedure successfully completed.&lt;br /&gt;&lt;br /&gt;Elapsed: 00:00:24.62&lt;br /&gt;SQL&gt; set autot trace&lt;br /&gt;SQL&gt; alter system flush buffer_cache;&lt;br /&gt;&lt;br /&gt;System altered.&lt;br /&gt;&lt;br /&gt;Elapsed: 00:00:00.07&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Now try to query the rows that we are interested.&lt;br /&gt;&lt;pre class='brush: sql'&gt;SQL&gt; select * from t1 where date_processed is null and date_to_be_processed = trunc(sysdate);&lt;br /&gt;&lt;br /&gt;100 rows selected.&lt;br /&gt;&lt;br /&gt;Elapsed: 00:00:00.08&lt;br /&gt;&lt;br /&gt;Execution Plan&lt;br /&gt;----------------------------------------------------------&lt;br /&gt;Plan hash value: 2362378154&lt;br /&gt;&lt;br /&gt;-------------------------------------------------------------------------------------&lt;br /&gt;| Id  | Operation                   | Name  | Rows  | Bytes | Cost (%CPU)| Time    |&lt;br /&gt;-------------------------------------------------------------------------------------&lt;br /&gt;|   0 | SELECT STATEMENT            |       |     1 |   140 |     4   (0)| 00:00:01 |&lt;br /&gt;|   1 |  TABLE ACCESS BY INDEX ROWID| T1    |     1 |   140 |     4   (0)| 00:00:01 |&lt;br /&gt;|*  2 |   INDEX RANGE SCAN          | T1_01 |     1 |       |     3   (0)| 00:00:01 |&lt;br /&gt;-------------------------------------------------------------------------------------&lt;br /&gt;&lt;br /&gt;Predicate Information (identified by operation id):&lt;br /&gt;---------------------------------------------------&lt;br /&gt;&lt;br /&gt;   2 - access("DATE_PROCESSED" IS NULL AND&lt;br /&gt;              "DATE_TO_BE_PROCESSED"=TRUNC(SYSDATE@!))&lt;br /&gt;       filter("DATE_TO_BE_PROCESSED"=TRUNC(SYSDATE@!))&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Statistics&lt;br /&gt;----------------------------------------------------------&lt;br /&gt;          1  recursive calls&lt;br /&gt;          0  db block gets&lt;br /&gt;         21  consistent gets&lt;br /&gt;          5  physical reads&lt;br /&gt;        188  redo size&lt;br /&gt;      15117  bytes sent via SQL*Net to client&lt;br /&gt;        485  bytes received via SQL*Net from client&lt;br /&gt;          8  SQL*Net roundtrips to/from client&lt;br /&gt;          0  sorts (memory)&lt;br /&gt;          0  sorts (disk)&lt;br /&gt;        100  rows processed&lt;br /&gt;&lt;br /&gt;SQL&gt; select BLEVEL, LEAF_BLOCKS, DISTINCT_KEYS, AVG_LEAF_BLOCKS_PER_KEY, AVG_DATA_BLOCKS_PER_KEY, NUM_ROWS from user_indexes where index_name = 'T1_01'&lt;br /&gt;  2&lt;br /&gt;&lt;br /&gt;SQL&gt; set autot off&lt;br /&gt;SQL&gt; select BLEVEL, LEAF_BLOCKS, DISTINCT_KEYS, AVG_LEAF_BLOCKS_PER_KEY, AVG_DATA_BLOCKS_PER_KEY, NUM_ROWS from user_indexes where index_name = 'T1_01';&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;    BLEVEL LEAF_BLOCKS DISTINCT_KEYS AVG_LEAF_BLOCKS_PER_KEY&lt;br /&gt;---------- ----------- ------------- -----------------------&lt;br /&gt;AVG_DATA_BLOCKS_PER_KEY   NUM_ROWS&lt;br /&gt;----------------------- ----------&lt;br /&gt;         2        3774         10001                       1&lt;br /&gt;                      2    1000100&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Elapsed: 00:00:00.60&lt;br /&gt;SQL&gt; validate index t1_01;&lt;br /&gt;&lt;br /&gt;Index analyzed.&lt;br /&gt;&lt;br /&gt;Elapsed: 00:00:00.97&lt;br /&gt;SQL&gt; select HEIGHT,BLOCKS,LF_ROWS,LF_BLKS,BR_ROWS,BR_BLKS,DEL_LF_ROWS,DISTINCT_KEYS,USED_SPACE,PCT_USED,ROWS_PER_KEY,BLKS_GETS_PER_ACCESS from index_stats;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;    HEIGHT     BLOCKS    LF_ROWS    LF_BLKS    BR_ROWS    BR_BLKS DEL_LF_ROWS&lt;br /&gt;---------- ---------- ---------- ---------- ---------- ---------- -----------&lt;br /&gt;DISTINCT_KEYS USED_SPACE   PCT_USED ROWS_PER_KEY BLKS_GETS_PER_ACCESS&lt;br /&gt;------------- ---------- ---------- ------------ --------------------&lt;br /&gt;         3       3968    1000100       3774       3773         15           0&lt;br /&gt;        10001   27107816         90          100                 53.5&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Elapsed: 00:00:04.46&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;It did 21 "consistent gets", 5 "physical reads" and it took "00.08" seconds to complete. The index we created has 3773 leaf blocks and it took about 27 MB storage space.&lt;br /&gt;&lt;br /&gt;Now try a function-based index on only specific values we interested in. We tell Oracle that put into index "date_to_be_processed" values of only the rows which has "date_processed" columns are null.  &lt;br /&gt;&lt;pre class='brush: sql'&gt;SQL&gt; set lines 120&lt;br /&gt;SQL&gt; drop index t1_01;&lt;br /&gt;&lt;br /&gt;Index dropped.&lt;br /&gt;&lt;br /&gt;Elapsed: 00:00:00.34&lt;br /&gt;SQL&gt; create index t1_01 on t1(case when date_processed is null then date_to_be_processed else null end);&lt;br /&gt;&lt;br /&gt;Index created.&lt;br /&gt;&lt;br /&gt;Elapsed: 00:00:02.22&lt;br /&gt;SQL&gt; exec dbms_stats.gather_table_stats('','t1',estimate_percent =&gt; null,cascade =&gt; true,method_opt =&gt; 'for all columns size 1');&lt;br /&gt;&lt;br /&gt;PL/SQL procedure successfully completed.&lt;br /&gt;&lt;br /&gt;Elapsed: 00:00:17.58&lt;br /&gt;SQL&gt; alter system flush buffer_cache;&lt;br /&gt;&lt;br /&gt;System altered.&lt;br /&gt;&lt;br /&gt;Elapsed: 00:00:00.03&lt;br /&gt;SQL&gt; set autot trace&lt;br /&gt;&lt;br /&gt;SQL&gt; alter system flush buffer_cache;&lt;br /&gt;&lt;br /&gt;System altered.&lt;br /&gt;&lt;br /&gt;Elapsed: 00:00:00.04&lt;br /&gt;SQL&gt; select * from t1 where (case when date_processed is null then date_to_be_processed else null end) = trunc(sysdate);&lt;br /&gt;&lt;br /&gt;100 rows selected.&lt;br /&gt;&lt;br /&gt;Elapsed: 00:00:00.02&lt;br /&gt;&lt;br /&gt;Execution Plan&lt;br /&gt;----------------------------------------------------------&lt;br /&gt;Plan hash value: 2362378154&lt;br /&gt;&lt;br /&gt;-------------------------------------------------------------------------------------&lt;br /&gt;| Id  | Operation                   | Name  | Rows  | Bytes | Cost (%CPU)| Time     |&lt;br /&gt;-------------------------------------------------------------------------------------&lt;br /&gt;|   0 | SELECT STATEMENT            |       |   100 | 14100 |     3   (0)| 00:00:01 |&lt;br /&gt;|   1 |  TABLE ACCESS BY INDEX ROWID| T1    |   100 | 14100 |     3   (0)| 00:00:01 |&lt;br /&gt;|*  2 |   INDEX RANGE SCAN          | T1_01 |   100 |       |     1   (0)| 00:00:01 |&lt;br /&gt;-------------------------------------------------------------------------------------&lt;br /&gt;&lt;br /&gt;Predicate Information (identified by operation id):&lt;br /&gt;---------------------------------------------------&lt;br /&gt;&lt;br /&gt;   2 - access(CASE  WHEN "DATE_PROCESSED" IS NULL THEN&lt;br /&gt;              "DATE_TO_BE_PROCESSED" ELSE NULL END =TRUNC(SYSDATE@!))&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Statistics&lt;br /&gt;----------------------------------------------------------&lt;br /&gt;          0  recursive calls&lt;br /&gt;          0  db block gets&lt;br /&gt;         17  consistent gets&lt;br /&gt;          3  physical reads&lt;br /&gt;          0  redo size&lt;br /&gt;       4311  bytes sent via SQL*Net to client&lt;br /&gt;        485  bytes received via SQL*Net from client&lt;br /&gt;          8  SQL*Net roundtrips to/from client&lt;br /&gt;          0  sorts (memory)&lt;br /&gt;          0  sorts (disk)&lt;br /&gt;        100  rows processed&lt;br /&gt;&lt;br /&gt;SQL&gt; set autot off&lt;br /&gt;SQL&gt; select BLEVEL, LEAF_BLOCKS, DISTINCT_KEYS, AVG_LEAF_BLOCKS_PER_KEY, AVG_DATA_BLOCKS_PER_KEY, NUM_ROWS from user_indexes where index_name = 'T1_01';&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;    BLEVEL LEAF_BLOCKS DISTINCT_KEYS AVG_LEAF_BLOCKS_PER_KEY AVG_DATA_BLOCKS_PER_KEY   NUM_ROWS&lt;br /&gt;---------- ----------- ------------- ----------------------- ----------------------- ----------&lt;br /&gt;         0           1             1                       1                       2        100&lt;br /&gt;&lt;br /&gt;Elapsed: 00:00:00.98&lt;br /&gt;SQL&gt; validate index t1_01;&lt;br /&gt;&lt;br /&gt;Index analyzed.&lt;br /&gt;&lt;br /&gt;Elapsed: 00:00:00.18&lt;br /&gt;SQL&gt; select HEIGHT,BLOCKS,LF_ROWS,LF_BLKS,BR_ROWS,BR_BLKS,DEL_LF_ROWS,DISTINCT_KEYS,USED_SPACE,PCT_USED,ROWS_PER_KEY,BLKS_GETS_PER_ACCESS from index_stats;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;    HEIGHT     BLOCKS    LF_ROWS    LF_BLKS    BR_ROWS    BR_BLKS DEL_LF_ROWS DISTINCT_KEYS USED_SPACE   PCT_USED&lt;br /&gt;---------- ---------- ---------- ---------- ---------- ---------- ----------- ------------- ---------- ----------&lt;br /&gt;ROWS_PER_KEY BLKS_GETS_PER_ACCESS&lt;br /&gt;------------ --------------------&lt;br /&gt;         1          8        100          1          0          0           0             1       1900         24&lt;br /&gt;         100                 51.5&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Elapsed: 00:00:00.78&lt;br /&gt;SQL&gt;&lt;br /&gt;&lt;/pre&gt;Now we see that it did 17 "consistent gets, 3 "physical reads" and it took just "00.02" seconds to get the results which is also a better value compared to "00.08" of previous normal index test, but when you compare the index structure, new index has only 1 leaf block which took 1.9 KB storage space which is far less compared to the 27 MB which was used in a normal index test.&lt;br /&gt;&lt;br /&gt;These examples are suitable for very selective cases, I mean, in these tests you are not interested in the old historical values, you only need to select the new values or values which we are interested in. But especially, from the storage point of view, if the table will grow very huge to billion of rows and you will not query the old historical values very often then this method is very well suits your needs.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6717103620143238053-3127440665643150173?l=uralural.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://uralural.blogspot.com/feeds/3127440665643150173/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6717103620143238053&amp;postID=3127440665643150173' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6717103620143238053/posts/default/3127440665643150173'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6717103620143238053/posts/default/3127440665643150173'/><link rel='alternate' type='text/html' href='http://uralural.blogspot.com/2011/07/indexing-only-needed-column-values-to.html' title='Indexing only the needed column values to save index space and also to improve the performance'/><author><name>Ural Ural</name><uri>http://www.blogger.com/profile/06556787053001681445</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='19' height='32' src='http://2.bp.blogspot.com/-FS7mo23hHG0/TjlVoo70i9I/AAAAAAAABwQ/mlpdh17_nwM/s220/IMAG0008.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6717103620143238053.post-1653683336600345691</id><published>2011-07-14T17:22:00.000-07:00</published><updated>2011-07-14T17:27:14.345-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='TABLE ACCESS FULL'/><category scheme='http://www.blogger.com/atom/ns#' term='cost based optimizer'/><category scheme='http://www.blogger.com/atom/ns#' term='set autotrace traceonly explain'/><category scheme='http://www.blogger.com/atom/ns#' term='index'/><category scheme='http://www.blogger.com/atom/ns#' term='INDEX FULL SCAN DESCENDING'/><category scheme='http://www.blogger.com/atom/ns#' term='CBO'/><category scheme='http://www.blogger.com/atom/ns#' term='INDEX FULL SCAN'/><category scheme='http://www.blogger.com/atom/ns#' term='INDEX FAST FULL SCAN'/><category scheme='http://www.blogger.com/atom/ns#' term='INDEX UNIQUE SCAN'/><category scheme='http://www.blogger.com/atom/ns#' term='INDEX RANGE SCAN'/><title type='text'>Effects of indexes on Oracle Cost Based Optimizer (CBO) execution plan selection</title><content type='html'>Followings are some tests that I performed on an Oracle 11gR2 database and my comments about the effects of the indexes on Oracle Cost Based Optimizer (CBO) execution plan selection. The results can change on different database versions or on the databases configured with different database parameters. Below are my output that I got at the time of my tests.&lt;br /&gt;&lt;br /&gt;&lt;pre class='brush: sql'&gt;[oracle@localhost uural]$ sqlplus / as sysdba&lt;br /&gt;&lt;br /&gt;SQL*Plus: Release 11.1.0.7.0 - Production on Thu Jul 14 14:15:11 2011&lt;br /&gt;&lt;br /&gt;Copyright (c) 1982, 2008, Oracle.  All rights reserved.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Connected to:&lt;br /&gt;Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - Production&lt;br /&gt;With the Partitioning, OLAP, Data Mining and Real Application Testing options&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;First I create a test user&lt;br /&gt;&lt;pre class='brush: sql'&gt;SQL&gt; !more cre_user-U0001.sql&lt;br /&gt;drop user u0001 cascade;&lt;br /&gt;create user u0001 identified by u0001;&lt;br /&gt;grant create session to u0001;&lt;br /&gt;alter user u0001 quota 5G on users;&lt;br /&gt;grant create table to u0001;&lt;br /&gt;grant dba to u0001;&lt;br /&gt;SQL&gt; @cre_user-U0001&lt;br /&gt;&lt;br /&gt;User dropped.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;User created.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Grant succeeded.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;User altered.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Grant succeeded.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Grant succeeded.&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Then I connect with that test user&lt;br /&gt;&lt;pre class='brush: sql'&gt;SQL&gt; conn u0001/u0001&lt;br /&gt;Connected.&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Create a big sample table&lt;br /&gt;&lt;pre class='brush: sql'&gt;SQL&gt; create table t1 as&lt;br /&gt;  2  select&lt;br /&gt;  3    rownum id,&lt;br /&gt;  4    dbms_random.string('U',6) v1,&lt;br /&gt;  5    lpad(rownum,10) v2,&lt;br /&gt;  6    rpad('x',100) padding&lt;br /&gt;  7  from&lt;br /&gt;  8    dual&lt;br /&gt;connect by level &lt;= 1000000;  9&lt;br /&gt;&lt;br /&gt;Table created.&lt;br /&gt;&lt;/pre&gt;Create an index on id column&lt;pre class='brush: sql'&gt;SQL&gt; create index t1_01 on t1(id);&lt;br /&gt;&lt;br /&gt;Index created.&lt;br /&gt;&lt;/pre&gt;gather table statistics with cascade option, which will gather index statistics also&lt;pre class='brush: sql'&gt;SQL&gt; exec dbms_stats.gather_table_stats('','t1',estimate_percent =&gt; null,cascade =&gt; true,method_opt =&gt; 'for all columns size 1');&lt;br /&gt;&lt;br /&gt;PL/SQL procedure successfully completed.&lt;br /&gt;&lt;br /&gt;SQL&gt; set lines 160&lt;br /&gt;&lt;br /&gt;SQL&gt; desc t1&lt;br /&gt; Name                                                                                      Null?    Type&lt;br /&gt; ----------------------------------------------------------------------------------------- -------- ------------------------------------------------------------&lt;br /&gt; ID                                                                                                 NUMBER&lt;br /&gt; V1                                                                                                 VARCHAR2(4000)&lt;br /&gt; V2                                                                                                 VARCHAR2(40)&lt;br /&gt; PADDING                                                                                            VARCHAR2(100)&lt;br /&gt;&lt;/pre&gt;set auto trace to explain only, we are only interested in the execution plans right now&lt;pre class='brush: sql'&gt;SQL&gt; set autot trace exp&lt;br /&gt;SQL&gt; sho autot&lt;br /&gt;autotrace TRACEONLY EXPLAIN&lt;br /&gt;&lt;/pre&gt;When we try to select all columns with a condition using an indexed column, CBO decides to do an "INDEX RANGE SCAN" and after finding the related rowids of the rows matching the index key in where condition, then select the rows from table by using these rowids.&lt;pre class='brush: sql'&gt;SQL&gt; select * from t1 where id = 100000;&lt;br /&gt;&lt;br /&gt;Execution Plan&lt;br /&gt;----------------------------------------------------------&lt;br /&gt;Plan hash value: 2362378154&lt;br /&gt;&lt;br /&gt;-------------------------------------------------------------------------------------&lt;br /&gt;| Id  | Operation                   | Name  | Rows  | Bytes | Cost (%CPU)| Time     |&lt;br /&gt;-------------------------------------------------------------------------------------&lt;br /&gt;|   0 | SELECT STATEMENT            |       |     1 |   124 |     4   (0)| 00:00:01 |&lt;br /&gt;|   1 |  TABLE ACCESS BY INDEX ROWID| T1    |     1 |   124 |     4   (0)| 00:00:01 |&lt;br /&gt;|*  2 |   INDEX RANGE SCAN          | T1_01 |     1 |       |     3   (0)| 00:00:01 |&lt;br /&gt;-------------------------------------------------------------------------------------&lt;br /&gt;&lt;br /&gt;Predicate Information (identified by operation id):&lt;br /&gt;---------------------------------------------------&lt;br /&gt;&lt;br /&gt;   2 - access("ID"=100000)&lt;br /&gt;&lt;/pre&gt;When we select only the indexed column from the table CBO goes directly to the table and does a full table scan(TABLE ACCESS FULL). Although this column is indexed, it did not use the index for this sql, because there is no "NOT NULL" constraint on indexed column "ID" and there can be NULL values for this column in the table which they did not exist in the corresponding index, since the index keys consisting of null values are not kept in an index.&lt;pre class='brush: sql'&gt;SQL&gt; select id from t1;&lt;br /&gt;&lt;br /&gt;Execution Plan&lt;br /&gt;----------------------------------------------------------&lt;br /&gt;Plan hash value: 3617692013&lt;br /&gt;&lt;br /&gt;--------------------------------------------------------------------------&lt;br /&gt;| Id  | Operation         | Name | Rows  | Bytes | Cost (%CPU)| Time     |&lt;br /&gt;--------------------------------------------------------------------------&lt;br /&gt;|   0 | SELECT STATEMENT  |      |  1000K|  4882K|  4895   (1)| 00:00:59 |&lt;br /&gt;|   1 |  TABLE ACCESS FULL| T1   |  1000K|  4882K|  4895   (1)| 00:00:59 |&lt;br /&gt;--------------------------------------------------------------------------&lt;br /&gt;&lt;/pre&gt;This time we query again the indexed column by giving a not null condition, and CBO uses associated index. It does not go to table because indexed column value also exists in the index as index key so there is no need to go to the table.Although, actually we know that there is only one row matching the condition, CBO does not know it and it does a "INDEX RANGE SCAN" instead of "INDEX UNIQUE SCAN" which could only be an option if we created a unique index on "ID" column. &lt;pre class='brush: sql'&gt;SQL&gt; select id from t1 where id = 100000;&lt;br /&gt;&lt;br /&gt;Execution Plan&lt;br /&gt;----------------------------------------------------------&lt;br /&gt;Plan hash value: 2311469903&lt;br /&gt;&lt;br /&gt;--------------------------------------------------------------------------&lt;br /&gt;| Id  | Operation        | Name  | Rows  | Bytes | Cost (%CPU)| Time     |&lt;br /&gt;--------------------------------------------------------------------------&lt;br /&gt;|   0 | SELECT STATEMENT |       |     1 |     5 |     3   (0)| 00:00:01 |&lt;br /&gt;|*  1 |  INDEX RANGE SCAN| T1_01 |     1 |     5 |     3   (0)| 00:00:01 |&lt;br /&gt;--------------------------------------------------------------------------&lt;br /&gt;&lt;br /&gt;Predicate Information (identified by operation id):&lt;br /&gt;---------------------------------------------------&lt;br /&gt;&lt;br /&gt;   1 - access("ID"=100000)&lt;br /&gt;&lt;/pre&gt;Again for the count operation since there is a not null condition in the where clause CBO computes this count only using the index without going to the table.&lt;pre class='brush: sql'&gt;SQL&gt; select count(*) from t1 where id = 100000;&lt;br /&gt;&lt;br /&gt;Execution Plan&lt;br /&gt;----------------------------------------------------------&lt;br /&gt;Plan hash value: 1142046246&lt;br /&gt;&lt;br /&gt;---------------------------------------------------------------------------&lt;br /&gt;| Id  | Operation         | Name  | Rows  | Bytes | Cost (%CPU)| Time     |&lt;br /&gt;---------------------------------------------------------------------------&lt;br /&gt;|   0 | SELECT STATEMENT  |       |     1 |     5 |     3   (0)| 00:00:01 |&lt;br /&gt;|   1 |  SORT AGGREGATE   |       |     1 |     5 |            |          |&lt;br /&gt;|*  2 |   INDEX RANGE SCAN| T1_01 |     1 |     5 |     3   (0)| 00:00:01 |&lt;br /&gt;---------------------------------------------------------------------------&lt;br /&gt;&lt;br /&gt;Predicate Information (identified by operation id):&lt;br /&gt;---------------------------------------------------&lt;br /&gt;&lt;br /&gt;   2 - access("ID"=100000)&lt;br /&gt;&lt;/pre&gt;Lets now set the indexed column to "NOT NULL" and see what will change.&lt;pre class='brush: sql'&gt;SQL&gt; alter table t1 modify id not null;&lt;br /&gt;&lt;br /&gt;Table altered.&lt;br /&gt;&lt;/pre&gt;Now CBO knows that there is no NULL value for the indexed column in the table and since all the values of indexed column is also recorded in the corresponding index there is no need to go to table. CBO chooses a "INDEX FAST FULL SCAN" (index ffs) which is done by using multi block read (mbr) technique, and because of that, returning rows from this operation will not be ordered by indexed column value.&lt;pre class='brush: sql'&gt;SQL&gt; select id from t1;&lt;br /&gt;&lt;br /&gt;Execution Plan&lt;br /&gt;----------------------------------------------------------&lt;br /&gt;Plan hash value: 93400700&lt;br /&gt;&lt;br /&gt;------------------------------------------------------------------------------&lt;br /&gt;| Id  | Operation            | Name  | Rows  | Bytes | Cost (%CPU)| Time     |&lt;br /&gt;------------------------------------------------------------------------------&lt;br /&gt;|   0 | SELECT STATEMENT     |       |  1000K|  4882K|   609   (1)| 00:00:08 |&lt;br /&gt;|   1 |  INDEX FAST FULL SCAN| T1_01 |  1000K|  4882K|   609   (1)| 00:00:08 |&lt;br /&gt;------------------------------------------------------------------------------&lt;br /&gt;&lt;/pre&gt;This time we want the result in order and CBO chooses "INDEX FULL SCAN" which will read all the index keys from the beginning leaf block to the end leaf block in the order of indexed key and return them again without going to the table.&lt;pre class='brush: sql'&gt;SQL&gt; select id from t1 order by id;&lt;br /&gt;&lt;br /&gt;Execution Plan&lt;br /&gt;----------------------------------------------------------&lt;br /&gt;Plan hash value: 2357002434&lt;br /&gt;&lt;br /&gt;--------------------------------------------------------------------------&lt;br /&gt;| Id  | Operation        | Name  | Rows  | Bytes | Cost (%CPU)| Time     |&lt;br /&gt;--------------------------------------------------------------------------&lt;br /&gt;|   0 | SELECT STATEMENT |       |  1000K|  4882K|  2235   (1)| 00:00:27 |&lt;br /&gt;|   1 |  INDEX FULL SCAN | T1_01 |  1000K|  4882K|  2235   (1)| 00:00:27 |&lt;br /&gt;--------------------------------------------------------------------------&lt;br /&gt;&lt;/pre&gt;This is very common execution plan CBO uses the index to get the rowids matching the criteria and then goes to table to fetch the matching rows by using the rowids got from the index.&lt;pre class='brush: sql'&gt;SQL&gt; select * from t1 where id = 100000;&lt;br /&gt;&lt;br /&gt;Execution Plan&lt;br /&gt;----------------------------------------------------------&lt;br /&gt;Plan hash value: 2362378154&lt;br /&gt;&lt;br /&gt;-------------------------------------------------------------------------------------&lt;br /&gt;| Id  | Operation                   | Name  | Rows  | Bytes | Cost (%CPU)| Time     |&lt;br /&gt;-------------------------------------------------------------------------------------&lt;br /&gt;|   0 | SELECT STATEMENT            |       |     1 |   124 |     4   (0)| 00:00:01 |&lt;br /&gt;|   1 |  TABLE ACCESS BY INDEX ROWID| T1    |     1 |   124 |     4   (0)| 00:00:01 |&lt;br /&gt;|*  2 |   INDEX RANGE SCAN          | T1_01 |     1 |       |     3   (0)| 00:00:01 |&lt;br /&gt;-------------------------------------------------------------------------------------&lt;br /&gt;&lt;br /&gt;Predicate Information (identified by operation id):&lt;br /&gt;---------------------------------------------------&lt;br /&gt;&lt;br /&gt;   2 - access("ID"=100000)&lt;br /&gt;&lt;/pre&gt;This time CBO does the ordering by using the index although there is no where condition containing the indexed column. Since the order by column is an indexes column, and all the values of that column exist in the index tree because of the "NOT NULL" constraint on that column, CBO finds the rowids of all rows in order from the index and then gets the associated rows from the table by using these rowids.&lt;pre class='brush: sql'&gt;SQL&gt; select * from t1 order by id;&lt;br /&gt;&lt;br /&gt;Execution Plan&lt;br /&gt;----------------------------------------------------------&lt;br /&gt;Plan hash value: 331831787&lt;br /&gt;&lt;br /&gt;-------------------------------------------------------------------------------------&lt;br /&gt;| Id  | Operation                   | Name  | Rows  | Bytes | Cost (%CPU)| Time     |&lt;br /&gt;-------------------------------------------------------------------------------------&lt;br /&gt;|   0 | SELECT STATEMENT            |       |  1000K|   118M| 20103   (1)| 00:04:02 |&lt;br /&gt;|   1 |  TABLE ACCESS BY INDEX ROWID| T1    |  1000K|   118M| 20103   (1)| 00:04:02 |&lt;br /&gt;|   2 |   INDEX FULL SCAN           | T1_01 |  1000K|       |  2235   (1)| 00:00:27 |&lt;br /&gt;-------------------------------------------------------------------------------------&lt;br /&gt;&lt;/pre&gt;Because of the "NOT NULL" constraint CBO knows that all values of the indexed column are index tree and the count of them equals to the count of rows in the table. It does a "INDEX FAST FULL SCAN" by using multi block read operation.&lt;pre class='brush: sql'&gt;SQL&gt; select count(*) from t1;&lt;br /&gt;&lt;br /&gt;Execution Plan&lt;br /&gt;----------------------------------------------------------&lt;br /&gt;Plan hash value: 442041690&lt;br /&gt;&lt;br /&gt;-----------------------------------------------------------------------&lt;br /&gt;| Id  | Operation             | Name  | Rows  | Cost (%CPU)| Time     |&lt;br /&gt;-----------------------------------------------------------------------&lt;br /&gt;|   0 | SELECT STATEMENT      |       |     1 |   609   (1)| 00:00:08 |&lt;br /&gt;|   1 |  SORT AGGREGATE       |       |     1 |            |          |&lt;br /&gt;|   2 |   INDEX FAST FULL SCAN| T1_01 |  1000K|   609   (1)| 00:00:08 |&lt;br /&gt;-----------------------------------------------------------------------&lt;br /&gt;&lt;/pre&gt;Now make the indexed column unique&lt;pre class='brush: sql'&gt;SQL&gt; alter table t1 add constraint t1_c_01 unique (id);&lt;br /&gt;&lt;br /&gt;Table altered.&lt;br /&gt;&lt;/pre&gt;As we can see CBO still chooses "INDEX RANGE SCAN", because although we made the indexed column UNIQUE, the index is still non-unique&lt;pre class='brush: sql'&gt;SQL&gt; select * from t1 where id = 100000;&lt;br /&gt;&lt;br /&gt;Execution Plan&lt;br /&gt;----------------------------------------------------------&lt;br /&gt;Plan hash value: 2362378154&lt;br /&gt;&lt;br /&gt;-------------------------------------------------------------------------------------&lt;br /&gt;| Id  | Operation                   | Name  | Rows  | Bytes | Cost (%CPU)| Time     |&lt;br /&gt;-------------------------------------------------------------------------------------&lt;br /&gt;|   0 | SELECT STATEMENT            |       |     1 |   124 |     3   (0)| 00:00:01 |&lt;br /&gt;|   1 |  TABLE ACCESS BY INDEX ROWID| T1    |     1 |   124 |     3   (0)| 00:00:01 |&lt;br /&gt;|*  2 |   INDEX RANGE SCAN          | T1_01 |     1 |       |     2   (0)| 00:00:01 |&lt;br /&gt;-------------------------------------------------------------------------------------&lt;br /&gt;&lt;br /&gt;Predicate Information (identified by operation id):&lt;br /&gt;---------------------------------------------------&lt;br /&gt;&lt;br /&gt;   2 - access("ID"=100000)&lt;br /&gt;&lt;/pre&gt;Lets drop and recreate the index as a unique index&lt;pre class='brush: sql'&gt;SQL&gt; drop index t1_01;&lt;br /&gt;drop index t1_01&lt;br /&gt;           *&lt;br /&gt;ERROR at line 1:&lt;br /&gt;ORA-02429: cannot drop index used for enforcement of unique/primary key&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;SQL&gt; alter table t1 drop constraint t1_c_01;&lt;br /&gt;&lt;br /&gt;Table altered.&lt;br /&gt;&lt;br /&gt;SQL&gt; drop index t1_01;&lt;br /&gt;&lt;br /&gt;Index dropped.&lt;br /&gt;&lt;br /&gt;SQL&gt; create unique index t1_01 on t1(id);&lt;br /&gt;&lt;br /&gt;Index created.&lt;br /&gt;&lt;br /&gt;SQL&gt; exec dbms_stats.gather_table_stats('','t1',estimate_percent =&gt; null,cascade =&gt; true,method_opt =&gt; 'for all columns size 1');&lt;br /&gt;&lt;br /&gt;PL/SQL procedure successfully completed.&lt;br /&gt;&lt;/pre&gt;Now we see that CBO decides to do a "INDEX UNIQUE SCAN" which will be cheaper than a "INDEX RANGE SCAN" in means of cost.&lt;pre class='brush: sql'&gt;SQL&gt; select * from t1 where id = 100000;&lt;br /&gt;&lt;br /&gt;Execution Plan&lt;br /&gt;----------------------------------------------------------&lt;br /&gt;Plan hash value: 2407846814&lt;br /&gt;&lt;br /&gt;-------------------------------------------------------------------------------------&lt;br /&gt;| Id  | Operation                   | Name  | Rows  | Bytes | Cost (%CPU)| Time     |&lt;br /&gt;-------------------------------------------------------------------------------------&lt;br /&gt;|   0 | SELECT STATEMENT            |       |     1 |   124 |     3   (0)| 00:00:01 |&lt;br /&gt;|   1 |  TABLE ACCESS BY INDEX ROWID| T1    |     1 |   124 |     3   (0)| 00:00:01 |&lt;br /&gt;|*  2 |   INDEX UNIQUE SCAN         | T1_01 |     1 |       |     2   (0)| 00:00:01 |&lt;br /&gt;-------------------------------------------------------------------------------------&lt;br /&gt;&lt;br /&gt;Predicate Information (identified by operation id):&lt;br /&gt;---------------------------------------------------&lt;br /&gt;&lt;br /&gt;   2 - access("ID"=100000)&lt;br /&gt;&lt;/pre&gt;Again CBO chooses "INDEX UNIQUE SCAN" without going to the table since all the indexed column values exists in the index because of the "NOT NULL" constrained on indexed column.&lt;pre class='brush: sql'&gt;SQL&gt; select id from t1 where id = 100000;&lt;br /&gt;&lt;br /&gt;Execution Plan&lt;br /&gt;----------------------------------------------------------&lt;br /&gt;Plan hash value: 2394460924&lt;br /&gt;&lt;br /&gt;---------------------------------------------------------------------------&lt;br /&gt;| Id  | Operation         | Name  | Rows  | Bytes | Cost (%CPU)| Time     |&lt;br /&gt;---------------------------------------------------------------------------&lt;br /&gt;|   0 | SELECT STATEMENT  |       |     1 |     5 |     2   (0)| 00:00:01 |&lt;br /&gt;|*  1 |  INDEX UNIQUE SCAN| T1_01 |     1 |     5 |     2   (0)| 00:00:01 |&lt;br /&gt;---------------------------------------------------------------------------&lt;br /&gt;&lt;br /&gt;Predicate Information (identified by operation id):&lt;br /&gt;---------------------------------------------------&lt;br /&gt;&lt;br /&gt;   1 - access("ID"=100000)&lt;br /&gt;&lt;/pre&gt;Nothings changed in the execution plan after changing the index to a unique one.&lt;pre class='brush: sql'&gt;SQL&gt; select * from t1 order by id;&lt;br /&gt;&lt;br /&gt;Execution Plan&lt;br /&gt;----------------------------------------------------------&lt;br /&gt;Plan hash value: 331831787&lt;br /&gt;&lt;br /&gt;-------------------------------------------------------------------------------------&lt;br /&gt;| Id  | Operation                   | Name  | Rows  | Bytes | Cost (%CPU)| Time     |&lt;br /&gt;-------------------------------------------------------------------------------------&lt;br /&gt;|   0 | SELECT STATEMENT            |       |  1000K|   118M| 19965   (1)| 00:04:00 |&lt;br /&gt;|   1 |  TABLE ACCESS BY INDEX ROWID| T1    |  1000K|   118M| 19965   (1)| 00:04:00 |&lt;br /&gt;|   2 |   INDEX FULL SCAN           | T1_01 |  1000K|       |  2097   (1)| 00:00:26 |&lt;br /&gt;-------------------------------------------------------------------------------------&lt;br /&gt;&lt;/pre&gt;Lets give an example how CBO chooses to scan the index leaf blocks from the end to the beginning when we give an order by in descending order by using "INDEX FULL SCAN DESCENDING".&lt;pre class='brush: sql'&gt;SQL&gt; select * from t1 order by id desc;&lt;br /&gt;&lt;br /&gt;Execution Plan&lt;br /&gt;----------------------------------------------------------&lt;br /&gt;Plan hash value: 2369582229&lt;br /&gt;&lt;br /&gt;-------------------------------------------------------------------------------------&lt;br /&gt;| Id  | Operation                   | Name  | Rows  | Bytes | Cost (%CPU)| Time     |&lt;br /&gt;-------------------------------------------------------------------------------------&lt;br /&gt;|   0 | SELECT STATEMENT            |       |  1000K|   118M| 19965   (1)| 00:04:00 |&lt;br /&gt;|   1 |  TABLE ACCESS BY INDEX ROWID| T1    |  1000K|   118M| 19965   (1)| 00:04:00 |&lt;br /&gt;|   2 |   INDEX FULL SCAN DESCENDING| T1_01 |  1000K|       |  2097   (1)| 00:00:26 |&lt;br /&gt;-------------------------------------------------------------------------------------&lt;br /&gt;&lt;/pre&gt;Again if we only select only the indexed column, column values comes from only the index without going to the table in descending order.&lt;pre class='brush: sql'&gt;SQL&gt; select id from t1 order by id desc;&lt;br /&gt;&lt;br /&gt;Execution Plan&lt;br /&gt;----------------------------------------------------------&lt;br /&gt;Plan hash value: 1356827296&lt;br /&gt;&lt;br /&gt;------------------------------------------------------------------------------------&lt;br /&gt;| Id  | Operation                  | Name  | Rows  | Bytes | Cost (%CPU)| Time     |&lt;br /&gt;------------------------------------------------------------------------------------&lt;br /&gt;|   0 | SELECT STATEMENT           |       |  1000K|  4882K|  2097   (1)| 00:00:26 |&lt;br /&gt;|   1 |  INDEX FULL SCAN DESCENDING| T1_01 |  1000K|  4882K|  2097   (1)| 00:00:26 |&lt;br /&gt;------------------------------------------------------------------------------------&lt;br /&gt;&lt;br /&gt;SQL&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;That's all folks.&lt;br /&gt;I hope my demonstrations and comments can give you any little idea about how the Oracle CBO works and decides the execution plans in the presence of indexes.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6717103620143238053-1653683336600345691?l=uralural.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://uralural.blogspot.com/feeds/1653683336600345691/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6717103620143238053&amp;postID=1653683336600345691' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6717103620143238053/posts/default/1653683336600345691'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6717103620143238053/posts/default/1653683336600345691'/><link rel='alternate' type='text/html' href='http://uralural.blogspot.com/2011/07/effects-of-indexes-on-oracle-cost-based.html' title='Effects of indexes on Oracle Cost Based Optimizer (CBO) execution plan selection'/><author><name>Ural Ural</name><uri>http://www.blogger.com/profile/06556787053001681445</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='19' height='32' src='http://2.bp.blogspot.com/-FS7mo23hHG0/TjlVoo70i9I/AAAAAAAABwQ/mlpdh17_nwM/s220/IMAG0008.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6717103620143238053.post-8933117670773071167</id><published>2011-07-14T12:55:00.000-07:00</published><updated>2011-07-14T13:09:43.092-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='reload'/><category scheme='http://www.blogger.com/atom/ns#' term='queryprocessor'/><category scheme='http://www.blogger.com/atom/ns#' term='HS_FDS_CONNECT_STRING'/><category scheme='http://www.blogger.com/atom/ns#' term='lsnrctl'/><category scheme='http://www.blogger.com/atom/ns#' term='ORA-28500'/><category scheme='http://www.blogger.com/atom/ns#' term='firstTreeExtensions'/><category scheme='http://www.blogger.com/atom/ns#' term='hs'/><category scheme='http://www.blogger.com/atom/ns#' term='Oracle Heterogeneous Services'/><category scheme='http://www.blogger.com/atom/ns#' term='hsodbc'/><category scheme='http://www.blogger.com/atom/ns#' term='ORA-02063'/><title type='text'>Oracle Heterogeneous Services (HS) problem with tables having lots of columns</title><content type='html'>Today, our Oracle data warehouse team got an error while querying a table having around 650 columns in an AS/400 database by using Oracle Heterogeneous Services or HS for short(It is also called HSODBC).&lt;br /&gt;&lt;br /&gt;HSODBC is a bundled component in Oracle database installation package. It enables yo to query any non-Oracle database tables from within an Oracle database as if the remote non-Oracle database is an Oracle database. I am thinking to publish another blog post in the future about how to setup HSODBC which I will not cover today. &lt;br /&gt;&lt;br /&gt;In this post, I only want to talk about an error in HSODBC and its solution since I could not find so much information about the solution of this problem today. I want to help anybody who will have that same problem in their HSODBC configuration. The HSODBC version we use is Oracle 10gR2 HSODBC. HSODBC parameter in different Oracle versions are different so the following solution is especially for Oracle 10gR2 HSODBC configuration. In our case, Oracle HSODBC server is a separate Windows machine which runs only Oracle HSODBC on it.&lt;br /&gt;&lt;br /&gt;The sql statements giving error were like below.&lt;br /&gt;select col1,col2,...,col650 from owner.table_name@database_link_using_hsodbc_to_as400_db;&lt;br /&gt;or the following sql statement got also the same error&lt;br /&gt;select * from owner.table_name@database_link_using_hsodbc_to_as400_db;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Error :&lt;/b&gt;&lt;br /&gt;ORA-28500: connection from ORACLE to a non-Oracle system returned this message:&lt;br /&gt;[Generic Connectivity Using ODBC][A048] The execution tree of this sql text is too big. Try to increase the variable 'firstTreeExtensions' in your environment file.&lt;br /&gt;ORA-02063: preceding line from database_link_using_hsodbc_to_as400_db&lt;br /&gt;&lt;br /&gt;The above error indicates that Oracle HSODBC has an internal limitation about the length of the selected data(consisting of column values in select statement) of a table coming from the non-Oracle database. We tried to select around 520 column from that table without getting this error but after adding some more columns to this list select, we started to get this error because we already reached that internal limitation of selected row size. In another document, we found that this internal default max size limit of selected row size, you can select from the non-Oracle database, is 150 Kilobytes.&lt;br /&gt;&lt;br /&gt;So we started to find how to increase that parameter and after trying different configurations we were able to increase the value of this parameter in the configuration and got rid of the above error.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Solution :&lt;/b&gt;&lt;br /&gt;Just add the following line to the "init&amp;ltsid_name_of_as400_db_in_listener.ora_file&amp;gt.ora" file in the "$ORACLE_HOME\hs\admin" folder. With this setting we increase the limit to 1000 KB.&lt;br /&gt;&lt;br /&gt;HS_FDS_CONNECT_STRING="&amp;ltnavobj&amp;gt&amp;ltbinding&amp;gt&amp;ltenvironment&amp;gt&amp;ltqueryprocessor firstTreeExtensions='1000'&amp;gt&amp;lt/queryProcessor&amp;gt&amp;lt/environment&amp;gt&amp;lt/binding&amp;gt&amp;lt/navobj&amp;gt"&lt;br /&gt;&lt;br /&gt;Then we need to reload the listener in HSODBC machine, like below so that our change in ".ora" configuration will take effect.&lt;br /&gt;&lt;br /&gt;In a windows Command Prompt window in HSODBC machine do the following to reload the listener.&lt;br /&gt;&lt;b&gt;&lt;br /&gt;lsnrctl&lt;br /&gt;LSNRCTL&gt; reload&lt;br /&gt;&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;Now you need to create a new session to the Oracle database, since the connections connected before these changes made to the listener in HSODBC server, will not be effected by this change, because of that, it is very important to create a new session to Oracle database where we will execute our sql statement querying the big table in the non-Oracle database.&lt;br /&gt;Then try to query all 650 columns of this table in non-Oracle database which is As/400 in our case.&lt;br /&gt;&lt;br /&gt;select col1,col2,...,col650 from owner.table_name@database_link_using_hsodbc_to_as400_db;&lt;br /&gt;&lt;br /&gt;Finally, you should successfully query all the 650 columns of this table.&lt;br /&gt;I hope the same solution will help to your case also.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6717103620143238053-8933117670773071167?l=uralural.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://uralural.blogspot.com/feeds/8933117670773071167/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6717103620143238053&amp;postID=8933117670773071167' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6717103620143238053/posts/default/8933117670773071167'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6717103620143238053/posts/default/8933117670773071167'/><link rel='alternate' type='text/html' href='http://uralural.blogspot.com/2011/07/oracle-heterogeneous-services-hs.html' title='Oracle Heterogeneous Services (HS) problem with tables having lots of columns'/><author><name>Ural Ural</name><uri>http://www.blogger.com/profile/06556787053001681445</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='19' height='32' src='http://2.bp.blogspot.com/-FS7mo23hHG0/TjlVoo70i9I/AAAAAAAABwQ/mlpdh17_nwM/s220/IMAG0008.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6717103620143238053.post-951907908148029454</id><published>2011-07-04T05:10:00.000-07:00</published><updated>2011-07-04T08:50:28.753-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='dbms_stats'/><category scheme='http://www.blogger.com/atom/ns#' term='statistics_level'/><category scheme='http://www.blogger.com/atom/ns#' term='gather_table_stats'/><category scheme='http://www.blogger.com/atom/ns#' term='user_tab_stats_history'/><category scheme='http://www.blogger.com/atom/ns#' term='restore_table_stats'/><category scheme='http://www.blogger.com/atom/ns#' term='get_stats_history_retention'/><category scheme='http://www.blogger.com/atom/ns#' term='alter_stats_history_retention'/><title type='text'>Oracle automatically keeps the old, historical table statistics</title><content type='html'>After Oracle version 10g, Oracle started to keep the old, historical table statistics in the database automatically so that you can use them, in case you need them later.&lt;br /&gt;If a specific SQL starts to perform badly in the database and you realized that the reason is the statistics of the table changed a lot since the last statistics collected on that table, you can use the previous old statistics of this table by restoring them in a very short time, without any need to collect them from scratch which could take a long time.&lt;br /&gt;&lt;br /&gt;Below is how you can accomplish to query and restore those old table statistics.&lt;br /&gt;&lt;br /&gt;Firs connect to a sample schema in database.&lt;br /&gt;&lt;pre class='brush: sql'&gt;[oracle@localhost uural]$ sqlplus u0001/u0001&lt;br /&gt;&lt;br /&gt;SQL*Plus: Release 11.1.0.7.0 - Production on Mon Jul 4 04:03:56 2011&lt;br /&gt;&lt;br /&gt;Copyright (c) 1982, 2008, Oracle.  All rights reserved.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Connected to:&lt;br /&gt;Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - Production&lt;br /&gt;With the Partitioning, OLAP, Data Mining and Real Application Testing options&lt;br /&gt;&lt;br /&gt;SQL&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Then create a sample table and collect statistics on this table by using "dbms_stats.gather_table_stats" procedure.&lt;br /&gt;&lt;pre class='brush: sql'&gt;SQL&gt; create table t1 as&lt;br /&gt;  2  select&lt;br /&gt;  3          rownum                          id,&lt;br /&gt;  4          dbms_random.string('U',6)       v1,&lt;br /&gt;  5          lpad(rownum,10)                 v2,&lt;br /&gt;  6          rpad('x',100)                   padding&lt;br /&gt;  7  from&lt;br /&gt;  8          all_objects&lt;br /&gt;  9  where&lt;br /&gt; 10          rownum &lt;= 1000&lt;br /&gt; 11  ;&lt;br /&gt;&lt;br /&gt;Table created.&lt;br /&gt;&lt;/pre&gt;You can query the old statistics info in a view in the database called "user_tab_stats_history". Since there is no statistics collected on this table we will not see any rows returning from this view.&lt;pre class='brush: sql'&gt;SQL&gt; select * from user_tab_stats_history;&lt;br /&gt;&lt;br /&gt;no rows selected&lt;br /&gt;&lt;/pre&gt;Now collect the statistics on the new table.&lt;pre class='brush: sql'&gt;SQL&gt; begin&lt;br /&gt;  2          dbms_stats.gather_table_stats(&lt;br /&gt;  3                  ownname          =&gt; user,&lt;br /&gt;  4                  tabname          =&gt; 'T1',&lt;br /&gt;  5                  cascade          =&gt; true,&lt;br /&gt;  6                  estimate_percent =&gt; null,&lt;br /&gt;  7                  granularity      =&gt; 'default',&lt;br /&gt;  8                  method_opt       =&gt; 'for all columns size 1'&lt;br /&gt;  9          );&lt;br /&gt; 10  end;&lt;br /&gt; 11  /&lt;br /&gt;&lt;br /&gt;PL/SQL procedure successfully completed.&lt;br /&gt;&lt;/pre&gt;Now check the "num_rows" info of table in "user_tables" view.&lt;pre class='brush: sql'&gt;SQL&gt; select table_name, num_rows from user_tables where table_name = 'T1';&lt;br /&gt;&lt;br /&gt;TABLE_NAME                       NUM_ROWS&lt;br /&gt;------------------------------ ----------&lt;br /&gt;T1                                   1000&lt;br /&gt;&lt;/pre&gt;Check the "user_tab_stats_history" view again.&lt;pre class='brush: sql'&gt;SQL&gt; set lines 250&lt;br /&gt;SQL&gt; r&lt;br /&gt;  1* select * from user_tab_stats_history&lt;br /&gt;&lt;br /&gt;TABLE_NAME                     PARTITION_NAME                 SUBPARTITION_NAME              STATS_UPDATE_TIME&lt;br /&gt;------------------------------ ------------------------------ ------------------------------ ---------------------------------------------------------------------------&lt;br /&gt;T1                                                                                           04-JUL-11 04.10.24.567434 AM -07:00&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;Now truncate the table and collect the statistics again, and check the "user_tab_stats_history" view.&lt;pre class='brush: sql'&gt;SQL&gt; truncate table t1;&lt;br /&gt;&lt;br /&gt;Table truncated.&lt;br /&gt;&lt;br /&gt;SQL&gt; select table_name, num_rows from user_tables where table_name = 'T1';&lt;br /&gt;&lt;br /&gt;TABLE_NAME                       NUM_ROWS&lt;br /&gt;------------------------------ ----------&lt;br /&gt;T1                                   1000&lt;br /&gt;&lt;br /&gt;SQL&gt; begin&lt;br /&gt;        dbms_stats.gather_table_stats(&lt;br /&gt;  2    3                  ownname          =&gt; user,&lt;br /&gt;  4                  tabname          =&gt; 'T1',&lt;br /&gt;  5                  cascade          =&gt; true,&lt;br /&gt;  6                  estimate_percent =&gt; null,&lt;br /&gt;  7                  granularity      =&gt; 'default',&lt;br /&gt;  8                  method_opt       =&gt; 'for all columns size 1'&lt;br /&gt;  9          );&lt;br /&gt; 10  end;&lt;br /&gt; 11  /&lt;br /&gt;&lt;br /&gt;PL/SQL procedure successfully completed.&lt;br /&gt;&lt;br /&gt;SQL&gt; select table_name, num_rows from user_tables where table_name = 'T1';&lt;br /&gt;&lt;br /&gt;TABLE_NAME                       NUM_ROWS&lt;br /&gt;------------------------------ ----------&lt;br /&gt;T1                                      0&lt;br /&gt;&lt;br /&gt;SQL&gt; select * from user_tab_stats_history;&lt;br /&gt;&lt;br /&gt;TABLE_NAME                     PARTITION_NAME                 SUBPARTITION_NAME              STATS_UPDATE_TIME&lt;br /&gt;------------------------------ ------------------------------ ------------------------------ ---------------------------------------------------------------------------&lt;br /&gt;T1                                                                                           04-JUL-11 04.10.24.567434 AM -07:00&lt;br /&gt;T1                                                                                           04-JUL-11 04.16.39.947784 AM -07:00&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;This sample table has only 1000 rows being relatively small, but suppose you have a big table with 100 million rows in it, and it takes quiet a long time to collect the statistics. If this table is truncated and statistics refreshed, then 100 million rows are inserted back to this table and new table statistics are not refreshed yet and an SQL in database is performing bad because the statistics of this table is not up-to-date. In that case if you have the old statistics from the time that this table had 100 million rows you can try to restore that statistics and try to tune the SQL.Below is how you can restore the old statistics.First insert 1000 rows back to that table, check the "num_rows" column in "user_tables" view.&lt;pre class='brush: sql'&gt;SQL&gt; insert into t1&lt;br /&gt;  2  select&lt;br /&gt;  3          rownum                          id,&lt;br /&gt;  4          dbms_random.string('U',6)       v1,&lt;br /&gt;  5          lpad(rownum,10)                 v2,&lt;br /&gt;  6          rpad('x',100)                   padding&lt;br /&gt;  7  from&lt;br /&gt;  8          all_objects&lt;br /&gt;  9  where&lt;br /&gt; 10          rownum &lt;= 1000&lt;br /&gt; 11  ;&lt;br /&gt;&lt;br /&gt;1000 rows created.&lt;br /&gt;&lt;br /&gt;SQL&gt; commit;&lt;br /&gt;&lt;br /&gt;Commit complete.&lt;br /&gt;&lt;br /&gt;SQL&gt; select count(*) from t1;&lt;br /&gt;&lt;br /&gt;  COUNT(*)&lt;br /&gt;----------&lt;br /&gt;      1000&lt;br /&gt;&lt;br /&gt;SQL&gt; select table_name, num_rows from user_tables where table_name = 'T1';&lt;br /&gt;&lt;br /&gt;TABLE_NAME                       NUM_ROWS&lt;br /&gt;------------------------------ ----------&lt;br /&gt;T1                                      0&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;Restore the old statistics back.&lt;pre class='brush: sql'&gt;SQL&gt; begin&lt;br /&gt;  dbms_stats.restore_table_stats (ownname         =&gt; 'U0001',&lt;br /&gt;  2    3                                    tabname         =&gt; 'T1',&lt;br /&gt;  4                                    as_of_timestamp =&gt;'04-JUL-11 04.10.24.567434 AM -07:00');&lt;br /&gt;  5  end;&lt;br /&gt;  6  /&lt;br /&gt;&lt;br /&gt;PL/SQL procedure successfully completed.&lt;br /&gt;&lt;br /&gt;SQL&gt; select table_name, num_rows from user_tables where table_name = 'T1';&lt;br /&gt;&lt;br /&gt;TABLE_NAME                       NUM_ROWS&lt;br /&gt;------------------------------ ----------&lt;br /&gt;T1                                   1000&lt;br /&gt;&lt;br /&gt;SQL&gt; select * from user_tab_stats_history;&lt;br /&gt;&lt;br /&gt;TABLE_NAME                     PARTITION_NAME                 SUBPARTITION_NAME              STATS_UPDATE_TIME&lt;br /&gt;------------------------------ ------------------------------ ------------------------------ ---------------------------------------------------------------------------&lt;br /&gt;T1                                                                                           04-JUL-11 04.10.24.567434 AM -07:00&lt;br /&gt;T1                                                                                           04-JUL-11 04.16.39.947784 AM -07:00&lt;br /&gt;T1                                                                                           04-JUL-11 04.31.24.129217 AM -07:00&lt;br /&gt;&lt;/pre&gt;As you can see, we restored the statistics of first row in the above "user_tab_stats_history" output, and Oracle created a new row stating that the statistics of the table has changed after the restore operation.Oracle keeps those old statistics for 31 days and after that automatically removes them which are older than 31 days.You can query that parameter "the history retention value" with the following SQL.&lt;pre class='brush: sql'&gt;SQL&gt; select dbms_stats.get_stats_history_retention from dual;&lt;br /&gt;&lt;br /&gt;GET_STATS_HISTORY_RETENTION&lt;br /&gt;---------------------------&lt;br /&gt;                         31&lt;br /&gt;&lt;/pre&gt;Below function gets the oldest time stamp where statistics history is available. Users cannot restore statistics to a time stamp older than the oldest time stamp.&lt;pre class='brush: sql'&gt;SQL&gt; select dbms_stats.get_stats_history_availability from dual;&lt;br /&gt;&lt;br /&gt;GET_STATS_HISTORY_AVAILABILITY&lt;br /&gt;---------------------------------------------------------------------------&lt;br /&gt;03-JUN-11 12.46.58.682468000 AM -07:00&lt;br /&gt;&lt;/pre&gt;Automatic purging is enabled when STATISTICS_LEVEL parameter is set to TYPICAL or ALL. If automatic purging is disabled, the old versions of statistics need to be purged manually using the PURGE_STATS procedure.You can query that parameter like below.&lt;pre class='brush: sql'&gt;[oracle@localhost uural]$ sqlplus / as sysdba&lt;br /&gt;&lt;br /&gt;SQL*Plus: Release 11.1.0.7.0 - Production on Mon Jul 4 04:45:47 2011&lt;br /&gt;&lt;br /&gt;Copyright (c) 1982, 2008, Oracle.  All rights reserved.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Connected to:&lt;br /&gt;Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - Production&lt;br /&gt;With the Partitioning, OLAP, Data Mining and Real Application Testing options&lt;br /&gt;&lt;br /&gt;SQL&gt; sho parameter statistics_level&lt;br /&gt;&lt;br /&gt;NAME                                 TYPE        VALUE&lt;br /&gt;------------------------------------ ----------- ------------------------------&lt;br /&gt;statistics_level                     string      TYPICAL&lt;br /&gt;SQL&gt;&lt;br /&gt;&lt;/pre&gt;You can change the history retention value like below. To run this procedure, you must have the SYSDBA or both ANALYZE ANY DICTIONARY and ANALYZE ANY system privileges.retention parameter : The retention time in days. The stats history will be retained for at least these many number of days.The valid range is [1,365000].  Also the following values can be used for special purposes.                 0 - old stats are never saved. The automatic purge will delete all stats history                -1 - stats history is never purged by automatic purge.                null -  change stats history retention to default value&lt;pre class='brush: sql'&gt;SQL&gt; select dbms_stats.get_stats_history_retention from dual;&lt;br /&gt;&lt;br /&gt;GET_STATS_HISTORY_RETENTION&lt;br /&gt;---------------------------&lt;br /&gt;                         31&lt;br /&gt;&lt;br /&gt;SQL&gt; exec dbms_stats.alter_stats_history_retention(retention =&gt; 45);&lt;br /&gt;&lt;br /&gt;PL/SQL procedure successfully completed.&lt;br /&gt;&lt;br /&gt;SQL&gt; select dbms_stats.get_stats_history_retention from dual;&lt;br /&gt;&lt;br /&gt;GET_STATS_HISTORY_RETENTION&lt;br /&gt;---------------------------&lt;br /&gt;                         45&lt;br /&gt;&lt;/pre&gt;Set it back to default value.&lt;pre class='brush: sql'&gt;SQL&gt; exec dbms_stats.alter_stats_history_retention(retention =&gt; null);&lt;br /&gt;&lt;br /&gt;PL/SQL procedure successfully completed.&lt;br /&gt;&lt;br /&gt;SQL&gt; select dbms_stats.get_stats_history_retention from dual;&lt;br /&gt;&lt;br /&gt;GET_STATS_HISTORY_RETENTION&lt;br /&gt;---------------------------&lt;br /&gt;                         31&lt;br /&gt;&lt;br /&gt;SQL&gt;&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6717103620143238053-951907908148029454?l=uralural.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://uralural.blogspot.com/feeds/951907908148029454/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6717103620143238053&amp;postID=951907908148029454' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6717103620143238053/posts/default/951907908148029454'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6717103620143238053/posts/default/951907908148029454'/><link rel='alternate' type='text/html' href='http://uralural.blogspot.com/2011/07/oracle-automatically-keeps-old.html' title='Oracle automatically keeps the old, historical table statistics'/><author><name>Ural Ural</name><uri>http://www.blogger.com/profile/06556787053001681445</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='19' height='32' src='http://2.bp.blogspot.com/-FS7mo23hHG0/TjlVoo70i9I/AAAAAAAABwQ/mlpdh17_nwM/s220/IMAG0008.jpg'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6717103620143238053.post-3176001696416576786</id><published>2011-06-23T09:05:00.000-07:00</published><updated>2011-06-23T09:05:40.616-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='x$ksppcv'/><category scheme='http://www.blogger.com/atom/ns#' term='v$parameter'/><category scheme='http://www.blogger.com/atom/ns#' term='hidden parameters'/><category scheme='http://www.blogger.com/atom/ns#' term='x$ksppi'/><title type='text'>Oracle hidden parameters</title><content type='html'>Oracle database has some parameters related to the database configuration, some of them which are hidden and some of them are unhidden. &lt;br /&gt;&lt;br /&gt;To list the unhidden parameters you can connect to the database "as sysdba" and directly query the "v$parameter" view as below.&lt;br /&gt;&lt;br /&gt;&lt;pre class='brush: sql'&gt;[oracle@localhost ~]$ sqlplus / as sysdba&lt;br /&gt;&lt;br /&gt;SQL*Plus: Release 11.2.0.2.0 Production on Thu Jun 23 08:41:55 2011&lt;br /&gt;&lt;br /&gt;Copyright (c) 1982, 2010, Oracle.  All rights reserved.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Connected to:&lt;br /&gt;Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - Production&lt;br /&gt;With the Partitioning, OLAP, Data Mining and Real Application Testing options&lt;br /&gt;&lt;br /&gt;SQL&gt; column name format a30&lt;br /&gt;SQL&gt; column value format a50 &lt;br /&gt;SQL&gt; column description format a50&lt;br /&gt;SQL&gt; set lines 132&lt;br /&gt;SQL&gt; set pause on&lt;br /&gt;SQL&gt; select name, value, description from v$parameter order by name;&lt;br /&gt;&lt;br /&gt;NAME                           VALUE                                              DESCRIPTION&lt;br /&gt;------------------------------ -------------------------------------------------- --------------------------------------------------&lt;br /&gt;O7_DICTIONARY_ACCESSIBILITY    FALSE                                              Version 7 Dictionary Accessibility Support&lt;br /&gt;active_instance_count                                                             number of active instances in the cluster database&lt;br /&gt;aq_tm_processes                0                                                  number of AQ Time Managers to start&lt;br /&gt;archive_lag_target             0                                                  Maximum number of seconds of redos the standby cou&lt;br /&gt;                                                                                  ld lose&lt;br /&gt;&lt;br /&gt;asm_diskgroups                                                                    disk groups to mount automatically&lt;br /&gt;asm_diskstring                                                                    disk set locations for discovery&lt;br /&gt;asm_power_limit                1                                                  number of parallel relocations for disk rebalancin&lt;br /&gt;                                                                                  g&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;asm_preferred_read_failure_gro                                                    preferred read failure groups&lt;br /&gt;&lt;br /&gt;............&lt;br /&gt;SQL&gt; &lt;br /&gt;&lt;/pre&gt; &lt;br /&gt;To list the hidden parameters you need to use an SQL like below, by switching commented where conditions, you can query different set of parameters hidden or unhidden. The following SQL only brings the hidden parameter called "_disable_logging" as an example.&lt;br /&gt;&lt;br /&gt;&lt;pre class='brush: sql'&gt;SQL&gt; SELECT x.ksppinm name,&lt;br /&gt;       y.ksppstvl VALUE,&lt;br /&gt;       x.ksppdesc description&lt;br /&gt;  FROM x$ksppi x,&lt;br /&gt;       x$ksppcv y&lt;br /&gt; WHERE x.inst_id = userenv('Instance')&lt;br /&gt;   AND y.inst_id = userenv('Instance')&lt;br /&gt;   AND x.indx = y.indx&lt;br /&gt;--   AND x.ksppinm LIKE '%pga%'; --list hidden and unhidden all parameters like "pga"&lt;br /&gt;   AND x.ksppinm LIKE '\_disable\_logging%' escape '\' --list hidden parameters like "_disable_logging"&lt;br /&gt;--   AND x.ksppinm NOT LIKE '\_%' escape '\' --list all unhidden parameters&lt;br /&gt;--   AND x.ksppinm LIKE '\_%' escape '\' --list all hidden parameters&lt;br /&gt;    order by 1;  2    3    4    5    6    7    8    9   10   11   12   13  &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;NAME                           VALUE                                              DESCRIPTION&lt;br /&gt;------------------------------ -------------------------------------------------- --------------------------------------------------&lt;br /&gt;_disable_logging               FALSE                                              Disable logging&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;All the Oracle hidden parameters start with an underscore (_). They are not documented parameters by Oracle. Oracle does not advise customers to change them without the knowledge of Oracle Support. &lt;br /&gt;&lt;br /&gt;For example, if you bump into an Oracle database bug and there is no published One-off patch to solve this bug yet, Oracle support can advise you to change an hidden Oracle parameter as a workaround until the patch will be released for this bug. Otherwise do not try to play with them since that can result to unexpected results in your databases.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6717103620143238053-3176001696416576786?l=uralural.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://uralural.blogspot.com/feeds/3176001696416576786/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6717103620143238053&amp;postID=3176001696416576786' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6717103620143238053/posts/default/3176001696416576786'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6717103620143238053/posts/default/3176001696416576786'/><link rel='alternate' type='text/html' href='http://uralural.blogspot.com/2011/06/oracle-hidden-parameters.html' title='Oracle hidden parameters'/><author><name>Ural Ural</name><uri>http://www.blogger.com/profile/06556787053001681445</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='19' height='32' src='http://2.bp.blogspot.com/-FS7mo23hHG0/TjlVoo70i9I/AAAAAAAABwQ/mlpdh17_nwM/s220/IMAG0008.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6717103620143238053.post-8345107885943166280</id><published>2011-06-23T08:15:00.000-07:00</published><updated>2011-06-23T08:15:24.635-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='whoami'/><category scheme='http://www.blogger.com/atom/ns#' term='hostname'/><category scheme='http://www.blogger.com/atom/ns#' term='pwd. profile'/><category scheme='http://www.blogger.com/atom/ns#' term='unix'/><category scheme='http://www.blogger.com/atom/ns#' term='command prompt'/><category scheme='http://www.blogger.com/atom/ns#' term='aix'/><title type='text'>How to change the command prompt on Unix</title><content type='html'>Below is how I change the command prompt on IBM AIX Unix type.&lt;br /&gt;&lt;br /&gt;It will set the command prompt on AIX to &lt;br /&gt;"connected username"@"hostname of the server":"current folder full path"&lt;br /&gt; &lt;br /&gt;&lt;pre class='brush: bash'&gt;[oracle@srvdb01]:/oracle &gt; more .profile | grep PS&lt;br /&gt;export PS1="[`whoami`@`hostname`]:\$PWD \&gt; "&lt;br /&gt;[oracle@srvdb01]:/oracle &gt;&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6717103620143238053-8345107885943166280?l=uralural.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://uralural.blogspot.com/feeds/8345107885943166280/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6717103620143238053&amp;postID=8345107885943166280' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6717103620143238053/posts/default/8345107885943166280'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6717103620143238053/posts/default/8345107885943166280'/><link rel='alternate' type='text/html' href='http://uralural.blogspot.com/2011/06/how-to-change-command-prompt-on-unix.html' title='How to change the command prompt on Unix'/><author><name>Ural Ural</name><uri>http://www.blogger.com/profile/06556787053001681445</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='19' height='32' src='http://2.bp.blogspot.com/-FS7mo23hHG0/TjlVoo70i9I/AAAAAAAABwQ/mlpdh17_nwM/s220/IMAG0008.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6717103620143238053.post-318035161591707239</id><published>2011-06-23T07:27:00.000-07:00</published><updated>2011-06-23T07:35:33.718-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='expdp'/><category scheme='http://www.blogger.com/atom/ns#' term='data pump import'/><category scheme='http://www.blogger.com/atom/ns#' term='directory'/><category scheme='http://www.blogger.com/atom/ns#' term='tablespace'/><category scheme='http://www.blogger.com/atom/ns#' term='include'/><category scheme='http://www.blogger.com/atom/ns#' term='multiple schemas'/><title type='text'>How to export tables from multiple schemas with Oracle Data Pump in Oracle 10g and 11g databases</title><content type='html'>First try it in an Oracle 10g database on an AIX server.&lt;br /&gt;&lt;br /&gt;First create the sample export folder which export files will be written. &lt;br /&gt;This folder should be created by unix user which is the owner of Oracle database (here "oracle" Unix OS user) or if created by another OS user, the directory permissions should be arranged so that Oracle owner OS user "oracle" can write to this folder.&lt;br /&gt;&lt;pre class='brush: bash'&gt;[oracle@srvdb01]:/oracle &gt; mkdir -p /transfer/uural/datapumpdemo&lt;br /&gt;[oracle@srvdb01]:/oracle &gt; cd /transfer/uural&lt;br /&gt;[oracle@srvdb01]:/transfer/uural &gt; ls -ld datapumpdemo&lt;br /&gt;drwxr-xr-x    2 oracle   dba            4096 Jun 22 15:06 datapumpdemo&lt;br /&gt;[oracle@srvdb01]:/transfer/uural &gt; cd datapumpdemo&lt;br /&gt;[oracle@srvdb01]:/transfer/uural/datapumpdemo &gt; ls -l&lt;br /&gt;total 0&lt;br /&gt;[oracle@srvdb01]:/transfer/uural/datapumpdemo &gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Now create a new directory in the database pointing to the above export folder.&lt;br /&gt;&lt;pre class='brush: sql'&gt;[oracle@srvdb01]:/transfer/uural/datapumpdemo &gt; sqlplus / as sysdba&lt;br /&gt;&lt;br /&gt;SQL*Plus: Release 10.2.0.4.0 - Production on Wed Jun 22 15:28:09 2011&lt;br /&gt;&lt;br /&gt;Copyright (c) 1982, 2007, Oracle.  All Rights Reserved.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Connected to:&lt;br /&gt;Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bit Production&lt;br /&gt;With the Partitioning, OLAP, Data Mining and Real Application Testing options&lt;br /&gt;&lt;br /&gt;SYS@ORCL AS SYSDBA&gt; create or replace directory uural_datapumpdemo as '/transfer/uural/datapumpdemo';&lt;br /&gt;&lt;br /&gt;Directory created.&lt;br /&gt;&lt;br /&gt;SYS@ORCL AS SYSDBA&gt; desc dba_directories&lt;br /&gt; Name                                      Null?    Type&lt;br /&gt; ----------------------------------------- -------- ----------------------------&lt;br /&gt; OWNER                                     NOT NULL VARCHAR2(30)&lt;br /&gt; DIRECTORY_NAME                            NOT NULL VARCHAR2(30)&lt;br /&gt; DIRECTORY_PATH                                     VARCHAR2(4000)&lt;br /&gt;&lt;br /&gt;SYS@ORCL AS SYSDBA&gt; column directory_path format a50&lt;br /&gt;SYS@ORCL AS SYSDBA&gt; set lines 200&lt;br /&gt;SYS@ORCL AS SYSDBA&gt; r&lt;br /&gt;  1* select * from dba_directories where directory_name = 'UURAL_DATAPUMPDEMO'&lt;br /&gt;&lt;br /&gt;OWNER                          DIRECTORY_NAME                 DIRECTORY_PATH&lt;br /&gt;------------------------------ ------------------------------ --------------------------------------------------&lt;br /&gt;SYS                            UURAL_DATAPUMPDEMO             /transfer/uural/datapumpdemo&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Lets create a sample schemas with some of empty tables in them.&lt;br /&gt;&lt;pre class='brush: sql'&gt;SYS@ORCL AS SYSDBA&gt; create user u0001 identified by "u0001_pass";&lt;br /&gt;&lt;br /&gt;User created.&lt;br /&gt;&lt;br /&gt;SYS@ORCL AS SYSDBA&gt; grant create session to u0001;&lt;br /&gt;&lt;br /&gt;Grant succeeded.&lt;br /&gt;&lt;br /&gt;SYS@ORCL AS SYSDBA&gt; grant create table to u0001;&lt;br /&gt;&lt;br /&gt;Grant succeeded.&lt;br /&gt;&lt;br /&gt;SYS@ORCL AS SYSDBA&gt; alter user u0001 quota 5G on users;&lt;br /&gt;&lt;br /&gt;User altered.&lt;br /&gt;&lt;br /&gt;SYS@ORCL AS SYSDBA&gt; GRANT READ, WRITE ON DIRECTORY SYS.UURAL_DATAPUMPDEMO TO U0001;&lt;br /&gt;&lt;br /&gt;Grant succeeded.&lt;br /&gt;&lt;br /&gt;SYS@ORCL AS SYSDBA&gt; create user u0002 identified by "u0002_pass";&lt;br /&gt;&lt;br /&gt;User created.&lt;br /&gt;&lt;br /&gt;SYS@ORCL AS SYSDBA&gt; grant create session to u0002;&lt;br /&gt;&lt;br /&gt;Grant succeeded.&lt;br /&gt;&lt;br /&gt;SYS@ORCL AS SYSDBA&gt; grant create table to u0002;&lt;br /&gt;&lt;br /&gt;Grant succeeded.&lt;br /&gt;&lt;br /&gt;SYS@ORCL AS SYSDBA&gt; alter user u0002 quota 5G on users;&lt;br /&gt;&lt;br /&gt;User altered.&lt;br /&gt;&lt;br /&gt;SYS@ORCL AS SYSDBA&gt; conn u0001/u0001_pass&lt;br /&gt;Connected.&lt;br /&gt;U0001@ORCL &gt; create table t0001 (col1 number);&lt;br /&gt;&lt;br /&gt;Table created.&lt;br /&gt;&lt;br /&gt;U0001@ORCL &gt; conn u0002/u0002_pass&lt;br /&gt;Connected.&lt;br /&gt;U0002@ORCL &gt; create table t0001 (col1 number);&lt;br /&gt;&lt;br /&gt;Table created.&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Lets try to export some tables from only a single schema in the database.&lt;br /&gt;&lt;pre class='brush: bash'&gt;[oracle@srvdb01]:/transfer/uural/datapumpdemo &gt; expdp u0001/u0001_pass directory=UURAL_DATAPUMPDEMO &lt;br /&gt;dumpfile=u0001_tables logfile=u0001_tables tables=T0001&lt;br /&gt;&lt;br /&gt;Export: Release 10.2.0.4.0 - 64bit Production on Thursday, 23 June, 2011 15:29:05&lt;br /&gt;&lt;br /&gt;Copyright (c) 2003, 2007, Oracle.  All rights reserved.&lt;br /&gt;&lt;br /&gt;Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bit Production&lt;br /&gt;With the Partitioning, OLAP, Data Mining and Real Application Testing options&lt;br /&gt;Starting "U0001"."SYS_EXPORT_TABLE_01":  u0001/******** directory=UURAL_DATAPUMPDEMO dumpfile=u0001_tables logfile=u0001_tables tables=T0001&lt;br /&gt;Estimate in progress using BLOCKS method...&lt;br /&gt;Processing object type TABLE_EXPORT/TABLE/TABLE_DATA&lt;br /&gt;Total estimation using BLOCKS method: 0 KB&lt;br /&gt;Processing object type TABLE_EXPORT/TABLE/TABLE&lt;br /&gt;. . exported "U0001"."T0001"                                 0 KB       0 rows&lt;br /&gt;Master table "U0001"."SYS_EXPORT_TABLE_01" successfully loaded/unloaded&lt;br /&gt;******************************************************************************&lt;br /&gt;Dump file set for U0001.SYS_EXPORT_TABLE_01 is:&lt;br /&gt;  /transfer/uural/datapumpdemo/u0001_tables.dmp&lt;br /&gt;Job "U0001"."SYS_EXPORT_TABLE_01" successfully completed at 15:32:39&lt;br /&gt;&lt;br /&gt;[oracle@srvdb01]:/transfer/uural/datapumpdemo &gt; ls -l&lt;br /&gt;total 136&lt;br /&gt;-rw-r-----    1 oracle   dba           61440 Jun 23 15:32 u0001_tables.dmp&lt;br /&gt;-rw-r--r--    1 oracle   dba            1043 Jun 23 15:32 u0001_tables.log&lt;br /&gt;[oracle@srvdb01]:/transfer/uural/datapumpdemo &gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Now try to export tables from two different schemas, since we are going to export tables from two schemas we will use "SYS" as the userid parameter in expdp command.&lt;br /&gt;&lt;pre class='brush: bash'&gt;[oracle@srvdb01]:/transfer/uural/datapumpdemo &gt; expdp '"/ as sysdba"' directory=UURAL_DATAPUMPDEMO &lt;br /&gt;dumpfile=u0001-u0002_tables logfile=u0001-u0002_tables tables=U0001.T0001,U0002.T0001                                                     &lt;br /&gt;&lt;br /&gt;Export: Release 10.2.0.4.0 - 64bit Production on Thursday, 23 June, 2011 15:35:01&lt;br /&gt;&lt;br /&gt;Copyright (c) 2003, 2007, Oracle.  All rights reserved.&lt;br /&gt;&lt;br /&gt;Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bit Production&lt;br /&gt;With the Partitioning, OLAP, Data Mining and Real Application Testing options&lt;br /&gt;UDE-00012: table mode exports only allow objects from one schema&lt;br /&gt;&lt;br /&gt;[oracle@srvdb01]:/transfer/uural/datapumpdemo &gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;As you can see you can not export tables from different schemas by using "tables" parameter in expdp in Oracle 10g.&lt;br /&gt;What you should do is create a table and insert the names of the tables to be exported to this table and use the "schemas" and "include" parameter in expdp command.&lt;br /&gt;&lt;br /&gt;&lt;pre class='brush: sql'&gt;U0001@ORCL &gt; create table expdp_tables (table_name varchar2(30));&lt;br /&gt;&lt;br /&gt;Table created.&lt;br /&gt;&lt;br /&gt;U0001@ORCL &gt; insert into expdp_tables values ('T0001');&lt;br /&gt;&lt;br /&gt;1 row created.&lt;br /&gt;&lt;br /&gt;U0001@ORCL &gt; commit;&lt;br /&gt;&lt;br /&gt;Commit complete.&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;You only need to insert the distinct names of all the tables into "expdp_tables" schema. Put the names of the all the distinct schemas whose tables will be exported in the "schemas" parameter. &lt;br /&gt;In that method you export all the tables in "expdp_tables" table from both schemas, this means if a specific table name exist in both schemas and you only want to export one of them, you can not do that.&lt;br /&gt;&lt;br /&gt;&lt;pre class='brush: bash'&gt;[oracle@srvdb01]:/transfer/uural/datapumpdemo &gt; expdp '"/ as sysdba"' directory=UURAL_DATAPUMPDEMO &lt;br /&gt;dumpfile=u0001-u0002_tables logfile=u0001-u0002_tables schemas=U0001,U0002 &lt;br /&gt;INCLUDE=TABLE:\"IN \(SELECT table_name FROM u0001.expdp_tables\)\"                                                             &lt;br /&gt;&lt;br /&gt;Export: Release 10.2.0.4.0 - 64bit Production on Thursday, 23 June, 2011 15:50:35&lt;br /&gt;&lt;br /&gt;Copyright (c) 2003, 2007, Oracle.  All rights reserved.&lt;br /&gt;&lt;br /&gt;Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bit Production&lt;br /&gt;With the Partitioning, OLAP, Data Mining and Real Application Testing options&lt;br /&gt;Starting "SYS"."SYS_EXPORT_SCHEMA_01":  "/******** AS SYSDBA" directory=UURAL_DATAPUMPDEMO dumpfile=u0001-u0002_tables logfile=u0001-u0002_tables schemas=U0001,U0002 INCLUDE=TABLE:"IN (SELECT table_name FROM u0001.expdp_tables)"&lt;br /&gt;Estimate in progress using BLOCKS method...&lt;br /&gt;Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA&lt;br /&gt;Total estimation using BLOCKS method: 0 KB&lt;br /&gt;Processing object type SCHEMA_EXPORT/TABLE/TABLE&lt;br /&gt;Processing object type SCHEMA_EXPORT/TABLE/GRANT/OWNER_GRANT/OBJECT_GRANT&lt;br /&gt;. . exported "U0001"."T0001"                                 0 KB       0 rows&lt;br /&gt;. . exported "U0002"."T0001"                                 0 KB       0 rows&lt;br /&gt;Master table "SYS"."SYS_EXPORT_SCHEMA_01" successfully loaded/unloaded&lt;br /&gt;******************************************************************************&lt;br /&gt;Dump file set for SYS.SYS_EXPORT_SCHEMA_01 is:&lt;br /&gt;  /transfer/uural/datapumpdemo/u0001-u0002_tables.dmp&lt;br /&gt;Job "SYS"."SYS_EXPORT_SCHEMA_01" successfully completed at 15:58:01&lt;br /&gt;&lt;br /&gt;[oracle@srvdb01]:/transfer/uural/datapumpdemo &gt;&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Lets now try to export tables from different schemas in Oracle 11g database on a Linux server.&lt;br /&gt;&lt;pre class='brush: sql'&gt;[oracle@localhost ~]$ sqlplus / as sysdba&lt;br /&gt;&lt;br /&gt;SQL*Plus: Release 11.2.0.2.0 Production on Thu Jun 23 07:07:24 2011&lt;br /&gt;&lt;br /&gt;Copyright (c) 1982, 2010, Oracle.  All rights reserved.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Connected to:&lt;br /&gt;Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - Production&lt;br /&gt;With the Partitioning, OLAP, Data Mining and Real Application Testing options&lt;br /&gt;&lt;br /&gt;SQL&gt; column directory_path format a50&lt;br /&gt;SQL&gt; select * from dba_directories where directory_name = 'DATA_PUMP_DIR'&lt;br /&gt;&lt;br /&gt;OWNER                          DIRECTORY_NAME                 DIRECTORY_PATH&lt;br /&gt;------------------------------ ------------------------------ --------------------------------------------------&lt;br /&gt;SYS                            DATA_PUMP_DIR                  /home/oracle/app/oracle/admin/orcl/dpdump/&lt;br /&gt;&lt;br /&gt;SQL&gt; &lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Check the number of files in the destination folder before the export&lt;br /&gt;&lt;pre class='brush: bash'&gt;[oracle@localhost ~]$ ls -l /home/oracle/app/oracle/admin/orcl/dpdump/&lt;br /&gt;total 4&lt;br /&gt;-rw-r----- 1 oracle oracle 116 Oct  2  2010 dp.log&lt;br /&gt;[oracle@localhost ~]$ &lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Prepare the sample schema and objects&lt;br /&gt;&lt;pre class='brush: sql'&gt;SQL&gt; create user u0001 identified by "u0001_pass";&lt;br /&gt;&lt;br /&gt;User created.&lt;br /&gt;&lt;br /&gt;SQL&gt; grant create session to u0001;&lt;br /&gt;&lt;br /&gt;Grant succeeded.&lt;br /&gt;&lt;br /&gt;SQL&gt; grant create table to u0001;&lt;br /&gt;&lt;br /&gt;Grant succeeded.&lt;br /&gt;&lt;br /&gt;SQL&gt; create user u0002 identified by "u0002_pass";&lt;br /&gt;&lt;br /&gt;User created.&lt;br /&gt;&lt;br /&gt;SQL&gt; grant create session to u0002;&lt;br /&gt;&lt;br /&gt;Grant succeeded.&lt;br /&gt;&lt;br /&gt;SQL&gt; grant create table to u0002;&lt;br /&gt;&lt;br /&gt;Grant succeeded.&lt;br /&gt;&lt;br /&gt;SQL&gt; conn u0001/u0001_pass&lt;br /&gt;Connected.&lt;br /&gt;SQL&gt; create table t0001 (col1 number);&lt;br /&gt;&lt;br /&gt;Table created.&lt;br /&gt;&lt;br /&gt;SQL&gt; conn u0002/u0002_pass&lt;br /&gt;Connected.&lt;br /&gt;SQL&gt; create table t0001 (col1 number);&lt;br /&gt;&lt;br /&gt;Table created.&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Try the export in 11g&lt;br /&gt;&lt;pre class='brush: bash'&gt;[oracle@localhost ~]$ expdp '"/ as sysdba"' directory=DATA_PUMP_DIR dumpfile=u0001-u0002_tables &lt;br /&gt;logfile=u0001-u0002_tables tables=U0001.T0001,U0002.T0001&lt;br /&gt;&lt;br /&gt;Export: Release 11.2.0.2.0 - Production on Thu Jun 23 07:17:53 2011&lt;br /&gt;&lt;br /&gt;Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.&lt;br /&gt;&lt;br /&gt;Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - Production&lt;br /&gt;With the Partitioning, OLAP, Data Mining and Real Application Testing options&lt;br /&gt;Starting "SYS"."SYS_EXPORT_TABLE_01":  "/******** AS SYSDBA" directory=DATA_PUMP_DIR dumpfile=u0001-u0002_tables logfile=u0001-u0002_tables tables=U0001.T0001,U0002.T0001 &lt;br /&gt;Estimate in progress using BLOCKS method...&lt;br /&gt;Processing object type TABLE_EXPORT/TABLE/TABLE_DATA&lt;br /&gt;Total estimation using BLOCKS method: 0 KB&lt;br /&gt;Processing object type TABLE_EXPORT/TABLE/TABLE&lt;br /&gt;. . exported "U0001"."T0001"                                 0 KB       0 rows&lt;br /&gt;. . exported "U0002"."T0001"                                 0 KB       0 rows&lt;br /&gt;Master table "SYS"."SYS_EXPORT_TABLE_01" successfully loaded/unloaded&lt;br /&gt;******************************************************************************&lt;br /&gt;Dump file set for SYS.SYS_EXPORT_TABLE_01 is:&lt;br /&gt;  /home/oracle/app/oracle/admin/orcl/dpdump/u0001-u0002_tables.dmp&lt;br /&gt;Job "SYS"."SYS_EXPORT_TABLE_01" successfully completed at 07:18:48&lt;br /&gt;&lt;br /&gt;[oracle@localhost ~]$  ls -l /home/oracle/app/oracle/admin/orcl/dpdump/&lt;br /&gt;total 96&lt;br /&gt;-rw-r----- 1 oracle oracle   116 Oct  2  2010 dp.log&lt;br /&gt;-rw-rw---- 1 oracle oracle 86016 Jun 23 07:18 u0001-u0002_tables.dmp&lt;br /&gt;-rw-rw-r-- 1 oracle oracle  1167 Jun 23 07:18 u0001-u0002_tables.log&lt;br /&gt;[oracle@localhost ~]$ &lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;As you can see, in Oracle 11g, you can export tables from different schemas by using "tables" parameter in Export Data Pump Utility and this is not possible in Oracle 10g.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6717103620143238053-318035161591707239?l=uralural.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://uralural.blogspot.com/feeds/318035161591707239/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6717103620143238053&amp;postID=318035161591707239' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6717103620143238053/posts/default/318035161591707239'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6717103620143238053/posts/default/318035161591707239'/><link rel='alternate' type='text/html' href='http://uralural.blogspot.com/2011/06/how-to-export-tables-from-multiple.html' title='How to export tables from multiple schemas with Oracle Data Pump in Oracle 10g and 11g databases'/><author><name>Ural Ural</name><uri>http://www.blogger.com/profile/06556787053001681445</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='19' height='32' src='http://2.bp.blogspot.com/-FS7mo23hHG0/TjlVoo70i9I/AAAAAAAABwQ/mlpdh17_nwM/s220/IMAG0008.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6717103620143238053.post-1211947992944533433</id><published>2011-06-21T07:17:00.000-07:00</published><updated>2011-06-21T11:33:52.356-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='archivelog'/><category scheme='http://www.blogger.com/atom/ns#' term='archive log list'/><category scheme='http://www.blogger.com/atom/ns#' term='USE_DB_RECOVERY_FILE_DEST'/><category scheme='http://www.blogger.com/atom/ns#' term='log_archive_dest'/><category scheme='http://www.blogger.com/atom/ns#' term='db_recovery_file_dest'/><title type='text'>How to enable and disable archivelog mode in an Oracle database</title><content type='html'>Although this is a very basic info, I just wanted to express it again and give some tips about it.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;1-) Enable archivelog mode :&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre class='brush: sql'&gt;[oracle@localhost ~]$ sqlplus / as sysdba&lt;br /&gt;&lt;br /&gt;SQL*Plus: Release 11.2.0.2.0 Production on Tue Jun 21 06:15:49 2011&lt;br /&gt;&lt;br /&gt;Copyright (c) 1982, 2010, Oracle.  All rights reserved.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Connected to:&lt;br /&gt;Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - Production&lt;br /&gt;With the Partitioning, OLAP, Data Mining and Real Application Testing options&lt;br /&gt;&lt;br /&gt;--Check current archivelog mode in database&lt;br /&gt;SQL&gt; archive log list&lt;br /&gt;Database log mode              No Archive Mode&lt;br /&gt;Automatic archival             Disabled&lt;br /&gt;Archive destination            USE_DB_RECOVERY_FILE_DEST&lt;br /&gt;Oldest online log sequence     427&lt;br /&gt;Current log sequence           429&lt;br /&gt;&lt;br /&gt;--Force a checkpoint to help and speed the database shutdown&lt;br /&gt;SQL&gt; alter system checkpoint;&lt;br /&gt;&lt;br /&gt;System altered.&lt;br /&gt;&lt;br /&gt;--Shutdown the database&lt;br /&gt;SQL&gt; shu immediate&lt;br /&gt;Database closed.&lt;br /&gt;Database dismounted.&lt;br /&gt;ORACLE instance shut down.&lt;br /&gt;&lt;br /&gt;--Start the database in mount mode&lt;br /&gt;SQL&gt; startup mount&lt;br /&gt;ORACLE instance started.&lt;br /&gt;&lt;br /&gt;Total System Global Area  456146944 bytes&lt;br /&gt;Fixed Size                  1344840 bytes&lt;br /&gt;Variable Size             373295800 bytes&lt;br /&gt;Database Buffers           75497472 bytes&lt;br /&gt;Redo Buffers                6008832 bytes&lt;br /&gt;Database mounted.&lt;br /&gt;&lt;br /&gt;--Enable archivelog in the database&lt;br /&gt;SQL&gt; alter database archivelog;&lt;br /&gt;&lt;br /&gt;Database altered.&lt;br /&gt;&lt;br /&gt;--Open the database&lt;br /&gt;SQL&gt; alter database open;&lt;br /&gt;&lt;br /&gt;Database altered.&lt;br /&gt;&lt;br /&gt;--Check the current archivelog mode in the database&lt;br /&gt;SQL&gt; archive log list&lt;br /&gt;Database log mode              Archive Mode&lt;br /&gt;Automatic archival             Enabled&lt;br /&gt;Archive destination            USE_DB_RECOVERY_FILE_DEST&lt;br /&gt;Oldest online log sequence     427&lt;br /&gt;Next log sequence to archive   429&lt;br /&gt;Current log sequence           429&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Do you know where the newly generated archivelogs are going to from now on, if there is any "log_archive_dest_n" parameter set and its "log_archive_des_n_state" is "enable" then all the newly generated archivelogs goes to that destination. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre class='brush: sql'&gt;SQL&gt; show parameter log_archive_dest&lt;br /&gt;&lt;br /&gt;NAME                                 TYPE        VALUE&lt;br /&gt;------------------------------------ ----------- ------------------------------&lt;br /&gt;log_archive_dest                     string&lt;br /&gt;log_archive_dest_1                   string&lt;br /&gt;log_archive_dest_10                  string&lt;br /&gt;log_archive_dest_11                  string&lt;br /&gt;log_archive_dest_12                  string&lt;br /&gt;log_archive_dest_13                  string&lt;br /&gt;log_archive_dest_14                  string&lt;br /&gt;log_archive_dest_15                  string&lt;br /&gt;log_archive_dest_16                  string&lt;br /&gt;log_archive_dest_17                  string&lt;br /&gt;log_archive_dest_18                  string&lt;br /&gt;&lt;br /&gt;NAME                                 TYPE        VALUE&lt;br /&gt;------------------------------------ ----------- ------------------------------&lt;br /&gt;log_archive_dest_19                  string&lt;br /&gt;log_archive_dest_2                   string&lt;br /&gt;log_archive_dest_20                  string&lt;br /&gt;log_archive_dest_21                  string&lt;br /&gt;log_archive_dest_22                  string&lt;br /&gt;log_archive_dest_23                  string&lt;br /&gt;log_archive_dest_24                  string&lt;br /&gt;log_archive_dest_25                  string&lt;br /&gt;log_archive_dest_26                  string&lt;br /&gt;log_archive_dest_27                  string&lt;br /&gt;log_archive_dest_28                  string&lt;br /&gt;&lt;br /&gt;NAME                                 TYPE        VALUE&lt;br /&gt;------------------------------------ ----------- ------------------------------&lt;br /&gt;log_archive_dest_29                  string&lt;br /&gt;log_archive_dest_3                   string&lt;br /&gt;log_archive_dest_30                  string&lt;br /&gt;log_archive_dest_31                  string&lt;br /&gt;log_archive_dest_4                   string&lt;br /&gt;log_archive_dest_5                   string&lt;br /&gt;log_archive_dest_6                   string&lt;br /&gt;log_archive_dest_7                   string&lt;br /&gt;log_archive_dest_8                   string&lt;br /&gt;log_archive_dest_9                   string&lt;br /&gt;log_archive_dest_state_1             string      enable&lt;br /&gt;&lt;br /&gt;NAME                                 TYPE        VALUE&lt;br /&gt;------------------------------------ ----------- ------------------------------&lt;br /&gt;log_archive_dest_state_10            string      enable&lt;br /&gt;log_archive_dest_state_11            string      enable&lt;br /&gt;log_archive_dest_state_12            string      enable&lt;br /&gt;log_archive_dest_state_13            string      enable&lt;br /&gt;log_archive_dest_state_14            string      enable&lt;br /&gt;log_archive_dest_state_15            string      enable&lt;br /&gt;log_archive_dest_state_16            string      enable&lt;br /&gt;log_archive_dest_state_17            string      enable&lt;br /&gt;log_archive_dest_state_18            string      enable&lt;br /&gt;log_archive_dest_state_19            string      enable&lt;br /&gt;log_archive_dest_state_2             string      enable&lt;br /&gt;&lt;br /&gt;NAME                                 TYPE        VALUE&lt;br /&gt;------------------------------------ ----------- ------------------------------&lt;br /&gt;log_archive_dest_state_20            string      enable&lt;br /&gt;log_archive_dest_state_21            string      enable&lt;br /&gt;log_archive_dest_state_22            string      enable&lt;br /&gt;log_archive_dest_state_23            string      enable&lt;br /&gt;log_archive_dest_state_24            string      enable&lt;br /&gt;log_archive_dest_state_25            string      enable&lt;br /&gt;log_archive_dest_state_26            string      enable&lt;br /&gt;log_archive_dest_state_27            string      enable&lt;br /&gt;log_archive_dest_state_28            string      enable&lt;br /&gt;log_archive_dest_state_29            string      enable&lt;br /&gt;log_archive_dest_state_3             string      enable&lt;br /&gt;&lt;br /&gt;NAME                                 TYPE        VALUE&lt;br /&gt;------------------------------------ ----------- ------------------------------&lt;br /&gt;log_archive_dest_state_30            string      enable&lt;br /&gt;log_archive_dest_state_31            string      enable&lt;br /&gt;log_archive_dest_state_4             string      enable&lt;br /&gt;log_archive_dest_state_5             string      enable&lt;br /&gt;log_archive_dest_state_6             string      enable&lt;br /&gt;log_archive_dest_state_7             string      enable&lt;br /&gt;log_archive_dest_state_8             string      enable&lt;br /&gt;log_archive_dest_state_9             string      enable&lt;br /&gt;SQL&gt; &lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;As you can see above there is no explicitly set "log_archive_dest_n", then archivelogs will go to the destination set in Oracle database parameter "db_recovery_file_dest" because "log_archive_dest_10" parameter implicitly set to "db_recovery_file_dest" parameter value, if there is no explicitly set "log_archive_dest_n" parameter. This is also the reason why we see in the above output "Archive destination            USE_DB_RECOVERY_FILE_DEST", means the destination set in the "db_recovery_file_dest" parameter value.&lt;br /&gt;&lt;br /&gt;Lets check that "db_recovery_file_dest" parameter value and see that it points to flash recovery area.&lt;br /&gt;&lt;br /&gt;&lt;pre class='brush: sql'&gt;SQL&gt; sho parameter db_recovery_file_dest&lt;br /&gt;&lt;br /&gt;NAME                                 TYPE        VALUE&lt;br /&gt;------------------------------------ ----------- ------------------------------&lt;br /&gt;db_recovery_file_dest                string      /home/oracle/app/oracle/flash_&lt;br /&gt;                                                 recovery_area&lt;br /&gt;db_recovery_file_dest_size           big integer 3852M&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Check that destination&lt;br /&gt;&lt;pre class='brush: bash'&gt;[oracle@localhost ORCL]$ pwd&lt;br /&gt;/home/oracle/app/oracle/flash_recovery_area/ORCL&lt;br /&gt;[oracle@localhost ORCL]$ ls -l&lt;br /&gt;total 4&lt;br /&gt;drwxr-x--- 2 oracle oracle 4096 Oct 30  2009 onlinelog&lt;br /&gt;[oracle@localhost ORCL]$&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;There is a folder named "ORCL"(value of $ORACLE_SID) below that folder.There is no "archivelog" folder yet, since there is no archivelogs generated yet.&lt;br /&gt;&lt;br /&gt;Lets force generation of some archivelogs&lt;br /&gt;&lt;pre class='brush: sql'&gt;SQL&gt; alter system switch logfile;&lt;br /&gt;&lt;br /&gt;System altered.&lt;br /&gt;&lt;br /&gt;SQL&gt; r&lt;br /&gt;  1* alter system switch logfile&lt;br /&gt;&lt;br /&gt;System altered.&lt;br /&gt;&lt;br /&gt;SQL&gt; r&lt;br /&gt;  1* alter system switch logfile&lt;br /&gt;&lt;br /&gt;System altered.&lt;br /&gt;&lt;br /&gt;SQL&gt; &lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Check the archivelog destination again&lt;br /&gt;&lt;pre class='brush: bash'&gt;[oracle@localhost ORCL]$ ls -l&lt;br /&gt;total 8&lt;br /&gt;drwxrwx--- 3 oracle oracle 4096 Jun 21 06:37 archivelog&lt;br /&gt;drwxr-x--- 2 oracle oracle 4096 Oct 30  2009 onlinelog&lt;br /&gt;[oracle@localhost ORCL]$ cd archivelog/&lt;br /&gt;[oracle@localhost archivelog]$ ls -l&lt;br /&gt;total 4&lt;br /&gt;drwxrwx--- 2 oracle oracle 4096 Jun 21 06:37 2011_06_21&lt;br /&gt;[oracle@localhost archivelog]$ cd 2011_06_21/&lt;br /&gt;[oracle@localhost 2011_06_21]$ ls -l&lt;br /&gt;total 2756&lt;br /&gt;-rw-rw---- 1 oracle oracle 2808320 Jun 21 06:37 o1_mf_1_429_7017nnrw_.arc&lt;br /&gt;-rw-rw---- 1 oracle oracle    1024 Jun 21 06:37 o1_mf_1_430_7017nq5w_.arc&lt;br /&gt;-rw-rw---- 1 oracle oracle    2560 Jun 21 06:37 o1_mf_1_431_7017nrxo_.arc&lt;br /&gt;[oracle@localhost 2011_06_21]$&lt;br /&gt;&lt;/pre&gt;As you can see Oracle created a folder named "archivelog" and a subfolder with today's date "2011_06_21" and put the newly generated archivelogs there.&lt;br /&gt;&lt;br /&gt;If you want, you can explicitly set a new archivelog destination instead of implicitly set flash recovery area like below.&lt;br /&gt;&lt;br /&gt;First create the new destination on the server&lt;br /&gt;&lt;pre class='brush: bash'&gt;[oracle@localhost oracle]$ pwd&lt;br /&gt;/home/oracle/app/oracle&lt;br /&gt;[oracle@localhost oracle]$ mkdir arc2&lt;br /&gt;[oracle@localhost oracle]$ cd arc2&lt;br /&gt;[oracle@localhost arc2]$ mkdir ORCL&lt;br /&gt;[oracle@localhost arc2]$ cd ORCL&lt;br /&gt;[oracle@localhost ORCL]$ pwd&lt;br /&gt;/home/oracle/app/oracle/arc2/ORCL&lt;br /&gt;[oracle@localhost ORCL]$ &lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Now set "log_archive_dest_1" parameter to this new destination, you can do this while the database is in open mode.&lt;br /&gt;&lt;pre class='brush: sql'&gt;SQL&gt; alter system set log_archive_dest_1='LOCATION=/home/oracle/app/oracle/arc2/ORCL';&lt;br /&gt;&lt;br /&gt;System altered.&lt;br /&gt;&lt;br /&gt;--Check the "log_archive_dest_1" parameter&lt;br /&gt;SQL&gt; sho parameter log_archive_dest_1 &lt;br /&gt;&lt;br /&gt;NAME                                 TYPE        VALUE&lt;br /&gt;------------------------------------ ----------- ------------------------------&lt;br /&gt;log_archive_dest_1                   string      LOCATION=/home/oracle/app/orac&lt;br /&gt;                                                 le/arc2/ORCL&lt;br /&gt;log_archive_dest_10                  string&lt;br /&gt;log_archive_dest_11                  string&lt;br /&gt;log_archive_dest_12                  string&lt;br /&gt;log_archive_dest_13                  string&lt;br /&gt;log_archive_dest_14                  string&lt;br /&gt;log_archive_dest_15                  string&lt;br /&gt;log_archive_dest_16                  string&lt;br /&gt;log_archive_dest_17                  string&lt;br /&gt;log_archive_dest_18                  string&lt;br /&gt;&lt;br /&gt;NAME                                 TYPE        VALUE&lt;br /&gt;------------------------------------ ----------- ------------------------------&lt;br /&gt;log_archive_dest_19                  string&lt;br /&gt;&lt;br /&gt;--Now check the archivelog mode state, as you can see we see the new destination as "Archive destination            /home/oracle/app/oracle/arc2/ORCL"&lt;br /&gt;SQL&gt; archive log list&lt;br /&gt;Database log mode              Archive Mode&lt;br /&gt;Automatic archival             Enabled&lt;br /&gt;Archive destination            /home/oracle/app/oracle/arc2/ORCL&lt;br /&gt;Oldest online log sequence     430&lt;br /&gt;Next log sequence to archive   432&lt;br /&gt;Current log sequence           432&lt;br /&gt;SQL&gt; &lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;From now on, all the newly generated archivelogs will go to that new destination.&lt;br /&gt;&lt;br /&gt;There is no archivelog in the new destination for now&lt;br /&gt;&lt;pre class='brush: bash'&gt;[oracle@localhost ORCL]$ pwd&lt;br /&gt;/home/oracle/app/oracle/arc2/ORCL&lt;br /&gt;[oracle@localhost ORCL]$ ls -l&lt;br /&gt;total 0&lt;br /&gt;[oracle@localhost ORCL]$ &lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Generate some new archivelogs&lt;br /&gt;&lt;pre class='brush: sql'&gt;SQL&gt; alter system switch logfile;&lt;br /&gt;&lt;br /&gt;System altered.&lt;br /&gt;&lt;br /&gt;SQL&gt; r&lt;br /&gt;  1* alter system switch logfile&lt;br /&gt;&lt;br /&gt;System altered.&lt;br /&gt;&lt;br /&gt;SQL&gt; r&lt;br /&gt;  1* alter system switch logfile&lt;br /&gt;&lt;br /&gt;System altered.&lt;br /&gt;&lt;br /&gt;SQL&gt; &lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Check the new destination and see the newly generated archivelogs&lt;br /&gt;&lt;br /&gt;&lt;pre class='brush: bash'&gt;[oracle@localhost ORCL]$ pwd&lt;br /&gt;/home/oracle/app/oracle/arc2/ORCL&lt;br /&gt;[oracle@localhost ORCL]$ ls -l&lt;br /&gt;total 816&lt;br /&gt;-rw-rw---- 1 oracle oracle 822272 Jun 21 06:53 1_432_701609923.dbf&lt;br /&gt;-rw-rw---- 1 oracle oracle   2560 Jun 21 06:53 1_433_701609923.dbf&lt;br /&gt;-rw-rw---- 1 oracle oracle   3072 Jun 21 06:53 1_434_701609923.dbf&lt;br /&gt;[oracle@localhost ORCL]$&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;b&gt;2-) Disable archivelog mode :&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre class='brush: sql'&gt;[oracle@localhost ~]$ sqlplus / as sysdba&lt;br /&gt;&lt;br /&gt;SQL*Plus: Release 11.2.0.2.0 Production on Tue Jun 21 06:56:38 2011&lt;br /&gt;&lt;br /&gt;Copyright (c) 1982, 2010, Oracle.  All rights reserved.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Connected to:&lt;br /&gt;Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - Production&lt;br /&gt;With the Partitioning, OLAP, Data Mining and Real Application Testing options&lt;br /&gt;&lt;br /&gt;--Check current archivelog mode in database&lt;br /&gt;SQL&gt; archive log list&lt;br /&gt;Database log mode              Archive Mode&lt;br /&gt;Automatic archival             Enabled&lt;br /&gt;Archive destination            /home/oracle/app/oracle/arc2/ORCL&lt;br /&gt;Oldest online log sequence     433&lt;br /&gt;Next log sequence to archive   435&lt;br /&gt;Current log sequence           435&lt;br /&gt;&lt;br /&gt;--Force a checkpoint to help and speed the database shutdown&lt;br /&gt;SQL&gt; alter system checkpoint;&lt;br /&gt;&lt;br /&gt;System altered.&lt;br /&gt;&lt;br /&gt;--Shutdown the database&lt;br /&gt;SQL&gt; shu immediate&lt;br /&gt;Database closed.&lt;br /&gt;Database dismounted.&lt;br /&gt;ORACLE instance shut down.&lt;br /&gt;&lt;br /&gt;--Start the database in mount mode&lt;br /&gt;SQL&gt; startup mount&lt;br /&gt;ORACLE instance started.&lt;br /&gt;&lt;br /&gt;SQL&gt; startup mount&lt;br /&gt;ORACLE instance started.&lt;br /&gt;&lt;br /&gt;Total System Global Area  456146944 bytes&lt;br /&gt;Fixed Size                  1344840 bytes&lt;br /&gt;Variable Size             381684408 bytes&lt;br /&gt;Database Buffers           67108864 bytes&lt;br /&gt;Redo Buffers                6008832 bytes&lt;br /&gt;Database mounted.&lt;br /&gt;&lt;br /&gt;--Disable archivelog in the database&lt;br /&gt;SQL&gt; alter database noarchivelog;&lt;br /&gt;&lt;br /&gt;Database altered.&lt;br /&gt;&lt;br /&gt;--Open the database&lt;br /&gt;SQL&gt; alter database open;&lt;br /&gt;&lt;br /&gt;Database altered.&lt;br /&gt;&lt;br /&gt;--Check the current archivelog mode in the database&lt;br /&gt;SQL&gt; archive log list&lt;br /&gt;Database log mode              No Archive Mode&lt;br /&gt;Automatic archival             Disabled&lt;br /&gt;Archive destination            /home/oracle/app/oracle/arc2/ORCL&lt;br /&gt;Oldest online log sequence     433&lt;br /&gt;Current log sequence           435&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;As you can see we disabled the archivelog mode in the database, there will not be any newly generated archivelogs in the archivelog destination although it is still set in the database.&lt;br /&gt;&lt;br /&gt;Switch some logfiles&lt;br /&gt;&lt;pre class='brush: sql'&gt;SQL&gt; alter system switch logfile;&lt;br /&gt;&lt;br /&gt;System altered.&lt;br /&gt;&lt;br /&gt;SQL&gt; r&lt;br /&gt;  1* alter system switch logfile&lt;br /&gt;&lt;br /&gt;System altered.&lt;br /&gt;&lt;br /&gt;SQL&gt; r&lt;br /&gt;  1* alter system switch logfile&lt;br /&gt;&lt;br /&gt;System altered.&lt;br /&gt;&lt;br /&gt;SQL&gt; &lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;As you can see there is no newly generated archivelogs in the archivelog destination.&lt;br /&gt;&lt;pre class='brush: bash'&gt;[oracle@localhost ORCL]$ pwd&lt;br /&gt;/home/oracle/app/oracle/arc2/ORCL&lt;br /&gt;[oracle@localhost ORCL]$ ls -l&lt;br /&gt;total 816&lt;br /&gt;-rw-rw---- 1 oracle oracle 822272 Jun 21 06:53 1_432_701609923.dbf&lt;br /&gt;-rw-rw---- 1 oracle oracle   2560 Jun 21 06:53 1_433_701609923.dbf&lt;br /&gt;-rw-rw---- 1 oracle oracle   3072 Jun 21 06:53 1_434_701609923.dbf&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;b&gt;3-) Additional info :&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;Do not close the database in a way that it will require instance recovery(e.g. shutdown abort) before you will mount it for archivelog mode change otherwise you will get the below error "ORA-00265", always try to shutdown the database gracefully by using "shutdown immediate".&lt;br /&gt;&lt;br /&gt;&lt;pre class='brush: sql'&gt;[oracle@localhost ~]$ sqlplus / as sysdba&lt;br /&gt;&lt;br /&gt;SQL*Plus: Release 11.2.0.2.0 Production on Tue Jun 21 07:07:41 2011&lt;br /&gt;&lt;br /&gt;Copyright (c) 1982, 2010, Oracle.  All rights reserved.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Connected to:&lt;br /&gt;Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - Production&lt;br /&gt;With the Partitioning, OLAP, Data Mining and Real Application Testing options&lt;br /&gt;&lt;br /&gt;SQL&gt; alter system checkpoint;&lt;br /&gt;&lt;br /&gt;System altered.&lt;br /&gt;&lt;br /&gt;SQL&gt; shu abort&lt;br /&gt;ORACLE instance shut down.&lt;br /&gt;SQL&gt; startup mount&lt;br /&gt;ORACLE instance started.&lt;br /&gt;&lt;br /&gt;Total System Global Area  456146944 bytes&lt;br /&gt;Fixed Size                  1344840 bytes&lt;br /&gt;Variable Size             381684408 bytes&lt;br /&gt;Database Buffers           67108864 bytes&lt;br /&gt;Redo Buffers                6008832 bytes&lt;br /&gt;Database mounted.&lt;br /&gt;SQL&gt; alter database archivelog;&lt;br /&gt;alter database archivelog&lt;br /&gt;*&lt;br /&gt;ERROR at line 1:&lt;br /&gt;ORA-00265: instance recovery required, cannot set ARCHIVELOG mode&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;SQL&gt; &lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;If there is a little chance that you can close the database with "shutdown immediate" because of the heavy activity on the database, you can use the below method to bring the database to the mount mode without causing any instance recovery.&lt;br /&gt;&lt;br /&gt;&lt;pre class='brush: sql'&gt;[oracle@localhost ~]$ sqlplus / as sysdba&lt;br /&gt;&lt;br /&gt;SQL*Plus: Release 11.2.0.2.0 Production on Tue Jun 21 07:11:07 2011&lt;br /&gt;&lt;br /&gt;Copyright (c) 1982, 2010, Oracle.  All rights reserved.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Connected to:&lt;br /&gt;Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - Production&lt;br /&gt;With the Partitioning, OLAP, Data Mining and Real Application Testing options&lt;br /&gt;&lt;br /&gt;SQL&gt; alter system checkpoint;&lt;br /&gt;&lt;br /&gt;System altered.&lt;br /&gt;&lt;br /&gt;SQL&gt; shu abort&lt;br /&gt;ORACLE instance shut down.&lt;br /&gt;SQL&gt; startup restrict&lt;br /&gt;ORACLE instance started.&lt;br /&gt;&lt;br /&gt;Total System Global Area  456146944 bytes&lt;br /&gt;Fixed Size                  1344840 bytes&lt;br /&gt;Variable Size             381684408 bytes&lt;br /&gt;Database Buffers           67108864 bytes&lt;br /&gt;Redo Buffers                6008832 bytes&lt;br /&gt;Database mounted.&lt;br /&gt;Database opened.&lt;br /&gt;SQL&gt; shu immediate&lt;br /&gt;Database closed.&lt;br /&gt;Database dismounted.&lt;br /&gt;ORACLE instance shut down.&lt;br /&gt;SQL&gt; startup mount&lt;br /&gt;ORACLE instance started.&lt;br /&gt;&lt;br /&gt;Total System Global Area  456146944 bytes&lt;br /&gt;Fixed Size                  1344840 bytes&lt;br /&gt;Variable Size             381684408 bytes&lt;br /&gt;Database Buffers           67108864 bytes&lt;br /&gt;Redo Buffers                6008832 bytes&lt;br /&gt;Database mounted.&lt;br /&gt;SQL&gt; alter database archivelog;&lt;br /&gt;&lt;br /&gt;Database altered.&lt;br /&gt;&lt;br /&gt;SQL&gt; alter database open;&lt;br /&gt;&lt;br /&gt;Database altered.&lt;br /&gt;&lt;br /&gt;SQL&gt; archive log list&lt;br /&gt;Database log mode              Archive Mode&lt;br /&gt;Automatic archival             Enabled&lt;br /&gt;Archive destination            /home/oracle/app/oracle/arc2/ORCL&lt;br /&gt;Oldest online log sequence     438&lt;br /&gt;Next log sequence to archive   440&lt;br /&gt;Current log sequence           440&lt;br /&gt;SQL&gt; exit&lt;br /&gt;Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - Production&lt;br /&gt;With the Partitioning, OLAP, Data Mining and Real Application Testing options&lt;br /&gt;[oracle@localhost ~]$ &lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;When you open the database with "startup restrict", only the users with "Restricted Session" system privilege (SYS user is one of them) can connect to database, since all the other client sessions will not be able to connect to the database, you will be able to shutdown the database faster with "shutdown immediate".&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6717103620143238053-1211947992944533433?l=uralural.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://uralural.blogspot.com/feeds/1211947992944533433/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6717103620143238053&amp;postID=1211947992944533433' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6717103620143238053/posts/default/1211947992944533433'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6717103620143238053/posts/default/1211947992944533433'/><link rel='alternate' type='text/html' href='http://uralural.blogspot.com/2011/06/how-to-enable-and-disable-archivelog.html' title='How to enable and disable archivelog mode in an Oracle database'/><author><name>Ural Ural</name><uri>http://www.blogger.com/profile/06556787053001681445</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='19' height='32' src='http://2.bp.blogspot.com/-FS7mo23hHG0/TjlVoo70i9I/AAAAAAAABwQ/mlpdh17_nwM/s220/IMAG0008.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6717103620143238053.post-5885715152313588900</id><published>2011-06-20T03:27:00.000-07:00</published><updated>2011-06-23T03:07:43.130-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='sqlprompt'/><category scheme='http://www.blogger.com/atom/ns#' term='SQL*Plus'/><category scheme='http://www.blogger.com/atom/ns#' term='glogin.sql'/><title type='text'>How to set Oracle SQL*Plus sqlprompt on Unix</title><content type='html'>Sometimes it is very confusing to realize in which database sqlprompt we are, writing and executing the SQL commands. If we write an SQL command in a production database instead of development or test database, the results can be catastrophic. In the below example, I will try to demonstrate my way of setting the sqlprompt in Oracle SQl*Plus. My example Unix version is IBM AIX.&lt;br /&gt;&lt;br /&gt;Oracle SQL*Plus, always, first runs an sql script called "glogin.sql" when you try to connect to an Oracle database.&lt;br /&gt;First take the backup of this script, if you need it later you can use the original version.&lt;br /&gt;&lt;pre class='brush: bash'&gt;[oracle@srvdb01]:/oracle/orahome1/sqlplus/admin &gt; ls -l&lt;br /&gt;total 40&lt;br /&gt;-rw-r-----    1 oracle   dba            1525 Aug 30 2004  glogin.sql&lt;br /&gt;drwxr-x---    2 oracle   dba             256 May 23 2008  help&lt;br /&gt;drwxr-x---    3 oracle   dba             256 May 23 2008  iplus&lt;br /&gt;-rw-r-----    1 oracle   dba            5363 Mar 02 2008  libsqlplus.exp&lt;br /&gt;-rw-r-----    1 oracle   dba             813 Mar 26 2006  plustrce.sql&lt;br /&gt;-rw-r-----    1 oracle   dba            2118 Feb 16 2003  pupbld.sql&lt;br /&gt;[oracle@srvdb01]:/oracle/orahome1/sqlplus/admin &gt; cp glogin.sql glogin.sql-201106141153&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Add the following line to the end of "glogin.sql" script.&lt;br /&gt;&lt;pre class='brush: sql'&gt;set sqlprompt "&amp;_USER'@'&amp;_CONNECT_IDENTIFIER &amp;_PRIVILEGE&gt; "&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Now try to login to database by using SQL*Plus in a telnet session.&lt;br /&gt;&lt;pre class='brush: sql'&gt;[oracle@srvdb01]:/oracle/orahome1/sqlplus/admin &gt; sqlplus / as sysdba&lt;br /&gt;&lt;br /&gt;SQL*Plus: Release 10.2.0.4.0 - Production on Tue Jun 14 12:53:42 2011&lt;br /&gt;&lt;br /&gt;Copyright (c) 1982, 2007, Oracle.  All Rights Reserved.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Connected to:&lt;br /&gt;Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bit Production&lt;br /&gt;With the Partitioning, OLAP, Data Mining and Real Application Testing options&lt;br /&gt;&lt;br /&gt;SYS@ORCL AS SYSDBA&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;As you can see, we set the Oracle SQL*Plus sqlprompt to the username@instance_name  the privilege like " as sysdba".&lt;br /&gt;&lt;br /&gt;If you apply this in your Unix Oracle database servers, when you have multiple databases in the same server or when you have multiple telnet sessions connected to different database servers and you are always switching between them, you realize in which database you are connected to and it will help a lot not to write the wrong SQL in especially in production databases instead of development or test databases.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6717103620143238053-5885715152313588900?l=uralural.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://uralural.blogspot.com/feeds/5885715152313588900/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6717103620143238053&amp;postID=5885715152313588900' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6717103620143238053/posts/default/5885715152313588900'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6717103620143238053/posts/default/5885715152313588900'/><link rel='alternate' type='text/html' href='http://uralural.blogspot.com/2011/06/how-to-set-oracle-sqlplus-sqlprompt-on.html' title='How to set Oracle SQL*Plus sqlprompt on Unix'/><author><name>Ural Ural</name><uri>http://www.blogger.com/profile/06556787053001681445</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='19' height='32' src='http://2.bp.blogspot.com/-FS7mo23hHG0/TjlVoo70i9I/AAAAAAAABwQ/mlpdh17_nwM/s220/IMAG0008.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6717103620143238053.post-5442260001480740610</id><published>2011-06-20T03:05:00.000-07:00</published><updated>2011-06-20T11:14:09.666-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='userid'/><category scheme='http://www.blogger.com/atom/ns#' term='ibm aix v5.3'/><category scheme='http://www.blogger.com/atom/ns#' term='data pump import'/><category scheme='http://www.blogger.com/atom/ns#' term='/ as sysdba'/><category scheme='http://www.blogger.com/atom/ns#' term='impdp'/><title type='text'>How to set the userid parameter in Oracle 10g impdp command line on IBM AIX</title><content type='html'>You can set the userid parameter in Oracle 10g impdp command line on IBM AIX OS like in the below example. It can sometimes be confusing to remember the placement of ' and " characters around / as sysdba, in below example it is ' "/ as sysdba" ' with no spaces between ' and ".  &lt;br /&gt;&lt;br /&gt;&lt;pre class='brush: bash'&gt;[oracle@srvdb01]:/oracle &gt; impdp '"/ as sysdba"' &lt;br /&gt;directory=DPUMP_DIR  dumpfile=SRVDB01_PROD_PROD_201105101132_tables &lt;br /&gt;logfile=SRVDB01_PROD_PROD_201105101132_tables_log tables=T0001 remap_schema=U0001:U0002&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6717103620143238053-5442260001480740610?l=uralural.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://uralural.blogspot.com/feeds/5442260001480740610/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6717103620143238053&amp;postID=5442260001480740610' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6717103620143238053/posts/default/5442260001480740610'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6717103620143238053/posts/default/5442260001480740610'/><link rel='alternate' type='text/html' href='http://uralural.blogspot.com/2011/06/how-to-set-userid-parameter-in-oracle.html' title='How to set the userid parameter in Oracle 10g impdp command line on IBM AIX'/><author><name>Ural Ural</name><uri>http://www.blogger.com/profile/06556787053001681445</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='19' height='32' src='http://2.bp.blogspot.com/-FS7mo23hHG0/TjlVoo70i9I/AAAAAAAABwQ/mlpdh17_nwM/s220/IMAG0008.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6717103620143238053.post-3443240086104019374</id><published>2011-06-19T13:56:00.000-07:00</published><updated>2011-06-20T11:25:14.038-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='v$result_cache_objects'/><category scheme='http://www.blogger.com/atom/ns#' term='oracle 11g'/><category scheme='http://www.blogger.com/atom/ns#' term='v$result_cache_statistics'/><category scheme='http://www.blogger.com/atom/ns#' term='sql result cache'/><category scheme='http://www.blogger.com/atom/ns#' term='result_cache'/><title type='text'>Oracle 11g New Feature "SQL Result Cache"</title><content type='html'>I want to demonstrate one of the new features of Oracle 11g called "SQL Result Cache" which will directly effect the database performance .&lt;br /&gt;&lt;br /&gt;I am going to use the same sample schemas that I created in my previous blog post.&lt;br /&gt;&lt;br /&gt;&lt;pre class='brush: sql'&gt;[oracle@localhost ~]$ sqlplus / as sysdba&lt;br /&gt;&lt;br /&gt;SQL*Plus: Release 11.2.0.2.0 Production on Sun Jun 19 13:13:02 2011&lt;br /&gt;&lt;br /&gt;Copyright (c) 1982, 2010, Oracle.  All rights reserved.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Connected to:&lt;br /&gt;Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - Production&lt;br /&gt;With the Partitioning, OLAP, Data Mining and Real Application Testing options&lt;br /&gt;&lt;br /&gt;SQL&gt; alter user u0001 quota 2G on users;&lt;br /&gt;&lt;br /&gt;User altered.&lt;br /&gt;&lt;br /&gt;SQL&gt; conn u0001/u0001&lt;br /&gt;Connected.&lt;br /&gt;SQL&gt; create table t0002 as select * from all_objects;&lt;br /&gt;&lt;br /&gt;Table created.&lt;br /&gt;&lt;br /&gt;SQL&gt; select count(*) from t0002;&lt;br /&gt;&lt;br /&gt;COUNT(*)&lt;br /&gt;----------&lt;br /&gt;56100&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Populate the records in table t0002&lt;br /&gt;&lt;pre class='brush: sql'&gt;SQL&gt; begin&lt;br /&gt;for c in (select rownum from t0002 where rownum &lt;= 5) loop&lt;br /&gt;    insert into t0002 select * from t0002;&lt;br /&gt;    commit;&lt;br /&gt;  end loop;&lt;br /&gt;end;&lt;br /&gt;/  2    3    4    5    6    7  &lt;br /&gt;&lt;br /&gt;PL/SQL procedure successfully completed.&lt;br /&gt;&lt;br /&gt;SQL&gt; select count(*) from t0002;&lt;br /&gt;&lt;br /&gt;COUNT(*)&lt;br /&gt;----------&lt;br /&gt;1795200&lt;br /&gt;&lt;br /&gt;SQL&gt; &lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Run a GROUP BY query on this table&lt;br /&gt;&lt;pre class='brush: sql'&gt;SQL&gt; set timing on&lt;br /&gt;SQL&gt; select object_type, count(*) from t0002 group by object_type order by object_type;&lt;br /&gt;&lt;br /&gt;OBJECT_TYPE           COUNT(*)&lt;br /&gt;------------------- ----------&lt;br /&gt;CONSUMER GROUP              64&lt;br /&gt;DESTINATION                 64&lt;br /&gt;EDITION                     64&lt;br /&gt;EVALUATION CONTEXT          32&lt;br /&gt;FUNCTION                  6688&lt;br /&gt;INDEXTYPE                  288&lt;br /&gt;JAVA CLASS              730496&lt;br /&gt;JAVA RESOURCE            26816&lt;br /&gt;JOB CLASS                   64&lt;br /&gt;OPERATOR                  1760&lt;br /&gt;PACKAGE                  14080&lt;br /&gt;&lt;br /&gt;OBJECT_TYPE           COUNT(*)&lt;br /&gt;------------------- ----------&lt;br /&gt;PROCEDURE                 1216&lt;br /&gt;PROGRAM                    352&lt;br /&gt;SCHEDULE                    96&lt;br /&gt;SCHEDULER GROUP            128&lt;br /&gt;SEQUENCE                   416&lt;br /&gt;SYNONYM                 893216&lt;br /&gt;TABLE                     5152&lt;br /&gt;TRIGGER                     32&lt;br /&gt;TYPE                     49024&lt;br /&gt;VIEW                     63040&lt;br /&gt;WINDOW                     288&lt;br /&gt;&lt;br /&gt;OBJECT_TYPE           COUNT(*)&lt;br /&gt;------------------- ----------&lt;br /&gt;XML SCHEMA                1824&lt;br /&gt;&lt;br /&gt;23 rows selected.&lt;br /&gt;&lt;br /&gt;Elapsed: 00:00:03.11&lt;br /&gt;SQL&gt; &lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Query took 03.11 seconds&lt;br /&gt;Now run the query so that results of the query will be cached in "SQL Result Cache", we accomplish this by using the "/*+ RESULT_CACHE */" hint in the query.&lt;br /&gt;&lt;br /&gt;&lt;pre class='brush: sql'&gt;SQL&gt; select /*+ RESULT_CACHE */ object_type, count(*) from t0002 group by object_type &lt;br /&gt;order by object_type;&lt;br /&gt;&lt;br /&gt;OBJECT_TYPE           COUNT(*)&lt;br /&gt;------------------- ----------&lt;br /&gt;CONSUMER GROUP              64&lt;br /&gt;DESTINATION                 64&lt;br /&gt;EDITION                     64&lt;br /&gt;EVALUATION CONTEXT          32&lt;br /&gt;FUNCTION                  6688&lt;br /&gt;INDEXTYPE                  288&lt;br /&gt;JAVA CLASS              730496&lt;br /&gt;JAVA RESOURCE            26816&lt;br /&gt;JOB CLASS                   64&lt;br /&gt;OPERATOR                  1760&lt;br /&gt;PACKAGE                  14080&lt;br /&gt;&lt;br /&gt;OBJECT_TYPE           COUNT(*)&lt;br /&gt;------------------- ----------&lt;br /&gt;PROCEDURE                 1216&lt;br /&gt;PROGRAM                    352&lt;br /&gt;SCHEDULE                    96&lt;br /&gt;SCHEDULER GROUP            128&lt;br /&gt;SEQUENCE                   416&lt;br /&gt;SYNONYM                 893216&lt;br /&gt;TABLE                     5152&lt;br /&gt;TRIGGER                     32&lt;br /&gt;TYPE                     49024&lt;br /&gt;VIEW                     63040&lt;br /&gt;WINDOW                     288&lt;br /&gt;&lt;br /&gt;OBJECT_TYPE           COUNT(*)&lt;br /&gt;------------------- ----------&lt;br /&gt;XML SCHEMA                1824&lt;br /&gt;&lt;br /&gt;23 rows selected.&lt;br /&gt;&lt;br /&gt;Elapsed: 00:00:02.87&lt;br /&gt;SQL&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;First run of the query took 02.87 seconds&lt;br /&gt;&lt;br /&gt;&lt;pre class='brush: sql'&gt;SQL&gt; r&lt;br /&gt;1* select /*+ RESULT_CACHE */ object_type, count(*) from t0002 group by object_type &lt;br /&gt;order by object_type&lt;br /&gt;&lt;br /&gt;OBJECT_TYPE           COUNT(*)&lt;br /&gt;------------------- ----------&lt;br /&gt;CONSUMER GROUP              64&lt;br /&gt;DESTINATION                 64&lt;br /&gt;EDITION                     64&lt;br /&gt;EVALUATION CONTEXT          32&lt;br /&gt;FUNCTION                  6688&lt;br /&gt;INDEXTYPE                  288&lt;br /&gt;JAVA CLASS              730496&lt;br /&gt;JAVA RESOURCE            26816&lt;br /&gt;JOB CLASS                   64&lt;br /&gt;OPERATOR                  1760&lt;br /&gt;PACKAGE                  14080&lt;br /&gt;&lt;br /&gt;OBJECT_TYPE           COUNT(*)&lt;br /&gt;------------------- ----------&lt;br /&gt;PROCEDURE                 1216&lt;br /&gt;PROGRAM                    352&lt;br /&gt;SCHEDULE                    96&lt;br /&gt;SCHEDULER GROUP            128&lt;br /&gt;SEQUENCE                   416&lt;br /&gt;SYNONYM                 893216&lt;br /&gt;TABLE                     5152&lt;br /&gt;TRIGGER                     32&lt;br /&gt;TYPE                     49024&lt;br /&gt;VIEW                     63040&lt;br /&gt;WINDOW                     288&lt;br /&gt;&lt;br /&gt;OBJECT_TYPE           COUNT(*)&lt;br /&gt;------------------- ----------&lt;br /&gt;XML SCHEMA                1824&lt;br /&gt;&lt;br /&gt;23 rows selected.&lt;br /&gt;&lt;br /&gt;Elapsed: 00:00:00.05&lt;br /&gt;SQL&gt; &lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Second run of the query took only 00.05 seconds because the query results has been fetched from "SQL Result Cache" in database server memory without going to disk to execute the SQL.&lt;br /&gt;&lt;br /&gt;We can also see from the explain plan that the results of the query is read from SQL Result Cache.&lt;br /&gt;&lt;pre class='brush: sql'&gt;SQL&gt; set autotrace traceonly explain&lt;br /&gt;SQL&gt; r&lt;br /&gt;1* select /*+ RESULT_CACHE */ object_type, count(*) from t0002 group by object_type &lt;br /&gt;order by object_type&lt;br /&gt;Elapsed: 00:00:00.00&lt;br /&gt;&lt;br /&gt;Execution Plan&lt;br /&gt;----------------------------------------------------------&lt;br /&gt;Plan hash value: 4234960643&lt;br /&gt;&lt;br /&gt;--------------------------------------------------------------------------------&lt;br /&gt;------------------&lt;br /&gt;&lt;br /&gt;| Id  | Operation           | Name                       | Rows  | Bytes | Cost&lt;br /&gt;(%CPU)| Time     |&lt;br /&gt;&lt;br /&gt;--------------------------------------------------------------------------------&lt;br /&gt;------------------&lt;br /&gt;&lt;br /&gt;|   0 | SELECT STATEMENT    |                            |    57M|   603M|  9677&lt;br /&gt;(26)| 00:01:57 |&lt;br /&gt;&lt;br /&gt;|   1 |  RESULT CACHE       | 44uuyvrukrh7w7w2m48aqb12tk |       |       |&lt;br /&gt;|          |&lt;br /&gt;&lt;br /&gt;|   2 |   SORT GROUP BY     |                            |    57M|   603M|  9677&lt;br /&gt;(26)| 00:01:57 |&lt;br /&gt;&lt;br /&gt;|   3 |    TABLE ACCESS FULL| T0002                      |    57M|   603M|  7612&lt;br /&gt;(6)| 00:01:32 |&lt;br /&gt;&lt;br /&gt;--------------------------------------------------------------------------------&lt;br /&gt;------------------&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Result Cache Information (identified by operation id):&lt;br /&gt;------------------------------------------------------&lt;br /&gt;&lt;br /&gt;1 - column-count=2; dependencies=(U0001.T0002); parameters=(nls); name="selec&lt;br /&gt;t /*+ RESULT_CACHE */ object_type, count(*) from t0002 group by object_type orde&lt;br /&gt;r by object_type"&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Note&lt;br /&gt;-----&lt;br /&gt;- dynamic sampling used for this statement (level=2)&lt;br /&gt;&lt;br /&gt;SQL&gt; &lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;We can also compare the SQL statisticts and see that SQL with RESULT_CAHCHE hint has no "consistent gets" or "physical reads".&lt;br /&gt;&lt;pre class='brush: sql'&gt;SQL&gt; set autotrace traceonly statistics;&lt;br /&gt;SQL&gt; select object_type, count(*) from t0002 group by object_type order by object_type;&lt;br /&gt;&lt;br /&gt;23 rows selected.&lt;br /&gt;&lt;br /&gt;Elapsed: 00:00:01.83&lt;br /&gt;&lt;br /&gt;Statistics&lt;br /&gt;----------------------------------------------------------&lt;br /&gt;0  recursive calls&lt;br /&gt;0  db block gets&lt;br /&gt;37542  consistent gets&lt;br /&gt;25909  physical reads&lt;br /&gt;0  redo size&lt;br /&gt;1041  bytes sent via SQL*Net to client&lt;br /&gt;430  bytes received via SQL*Net from client&lt;br /&gt;3  SQL*Net roundtrips to/from client&lt;br /&gt;1  sorts (memory)&lt;br /&gt;0  sorts (disk)&lt;br /&gt;23  rows processed&lt;br /&gt;&lt;br /&gt;SQL&gt; select /*+ RESULT_CACHE */ object_type, count(*) from t0002 group by object_type &lt;br /&gt;order by object_type;&lt;br /&gt;&lt;br /&gt;23 rows selected.&lt;br /&gt;&lt;br /&gt;Elapsed: 00:00:00.04&lt;br /&gt;&lt;br /&gt;Statistics&lt;br /&gt;----------------------------------------------------------&lt;br /&gt;0  recursive calls&lt;br /&gt;0  db block gets&lt;br /&gt;0  consistent gets&lt;br /&gt;0  physical reads&lt;br /&gt;0  redo size&lt;br /&gt;1041  bytes sent via SQL*Net to client&lt;br /&gt;430  bytes received via SQL*Net from client&lt;br /&gt;3  SQL*Net roundtrips to/from client&lt;br /&gt;0  sorts (memory)&lt;br /&gt;0  sorts (disk)&lt;br /&gt;23  rows processed&lt;br /&gt;&lt;br /&gt;SQL&gt; &lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Lets now monitor the SQL Result Cache by using related dynamic views.&lt;br /&gt;&lt;br /&gt;&lt;pre class='brush: sql'&gt;[oracle@localhost ~]$ sqlplus / as sysdba&lt;br /&gt;&lt;br /&gt;SQL*Plus: Release 11.2.0.2.0 Production on Sun Jun 19 13:41:23 2011&lt;br /&gt;&lt;br /&gt;Copyright (c) 1982, 2010, Oracle.  All rights reserved.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Connected to:&lt;br /&gt;Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - Production&lt;br /&gt;With the Partitioning, OLAP, Data Mining and Real Application Testing options&lt;br /&gt;&lt;br /&gt;SQL&gt; SELECT name&lt;br /&gt;,      type&lt;br /&gt;,      cache_id&lt;br /&gt;,      row_count&lt;br /&gt;FROM   v$result_cache_objects&lt;br /&gt;ORDER  BY&lt;br /&gt;creation_timestamp;    &lt;br /&gt;&lt;br /&gt;NAME&lt;br /&gt;--------------------------------------------------------------------------------&lt;br /&gt;TYPE&lt;br /&gt;----------&lt;br /&gt;CACHE_ID&lt;br /&gt;--------------------------------------------------------------------------------&lt;br /&gt;ROW_COUNT&lt;br /&gt;----------&lt;br /&gt;U0001.T0002&lt;br /&gt;Dependency&lt;br /&gt;U0001.T0002&lt;br /&gt;0&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;NAME&lt;br /&gt;--------------------------------------------------------------------------------&lt;br /&gt;TYPE&lt;br /&gt;----------&lt;br /&gt;CACHE_ID&lt;br /&gt;--------------------------------------------------------------------------------&lt;br /&gt;ROW_COUNT&lt;br /&gt;----------&lt;br /&gt;select /*+ RESULT_CACHE */ object_type, count(*) from t0002 group by object_type&lt;br /&gt;order by object_type&lt;br /&gt;Result&lt;br /&gt;44uuyvrukrh7w7w2m48aqb12tk&lt;br /&gt;23&lt;br /&gt;&lt;br /&gt;NAME&lt;br /&gt;--------------------------------------------------------------------------------&lt;br /&gt;TYPE&lt;br /&gt;----------&lt;br /&gt;CACHE_ID&lt;br /&gt;--------------------------------------------------------------------------------&lt;br /&gt;ROW_COUNT&lt;br /&gt;----------&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;When there will be any DML operation on the dependent object u0001.t0002, the result cache is invalidated and generated again with the next run of SQL.&lt;br /&gt;&lt;br /&gt;Monitor the SQL Result Cache statistics&lt;br /&gt;&lt;pre class='brush: sql'&gt;SQL&gt; column name format a30&lt;br /&gt;SQL&gt; column value format a30&lt;br /&gt;SQL&gt; select name, value from v$result_cache_statistics order by id;&lt;br /&gt;&lt;br /&gt;NAME                           VALUE&lt;br /&gt;------------------------------ ------------------------------&lt;br /&gt;Block Size (Bytes)             1024&lt;br /&gt;Block Count Maximum            1120&lt;br /&gt;Block Count Current            32&lt;br /&gt;Result Size Maximum (Blocks)   56&lt;br /&gt;Create Count Success           1&lt;br /&gt;Create Count Failure           0&lt;br /&gt;Find Count                     2&lt;br /&gt;Invalidation Count             0&lt;br /&gt;Delete Count Invalid           0&lt;br /&gt;Delete Count Valid             0&lt;br /&gt;Hash Chain Length              1&lt;br /&gt;&lt;br /&gt;NAME                           VALUE&lt;br /&gt;------------------------------ ------------------------------&lt;br /&gt;Find Copy Count                2&lt;br /&gt;&lt;br /&gt;12 rows selected.&lt;br /&gt;&lt;br /&gt;SQL&gt; &lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6717103620143238053-3443240086104019374?l=uralural.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://uralural.blogspot.com/feeds/3443240086104019374/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6717103620143238053&amp;postID=3443240086104019374' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6717103620143238053/posts/default/3443240086104019374'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6717103620143238053/posts/default/3443240086104019374'/><link rel='alternate' type='text/html' href='http://uralural.blogspot.com/2011/06/oracle-11g-new-feature-sql-result-cache.html' title='Oracle 11g New Feature &quot;SQL Result Cache&quot;'/><author><name>Ural Ural</name><uri>http://www.blogger.com/profile/06556787053001681445</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='19' height='32' src='http://2.bp.blogspot.com/-FS7mo23hHG0/TjlVoo70i9I/AAAAAAAABwQ/mlpdh17_nwM/s220/IMAG0008.jpg'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6717103620143238053.post-8489830665570408712</id><published>2011-06-19T12:44:00.000-07:00</published><updated>2011-06-20T11:28:35.158-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='grant'/><category scheme='http://www.blogger.com/atom/ns#' term='with grant option'/><category scheme='http://www.blogger.com/atom/ns#' term='cascading revoke'/><title type='text'>"WITH GRANT OPTION" and Cascading Revoke</title><content type='html'>Most of you probably already know, but I want to demonstrate again one of the important features of Oracle database called "Cascading Revoke". I will use Oracle 11g as an example database for this demonstration but this feature is also available in the older versions of Oracle databases.&lt;br /&gt;&lt;br /&gt;First connect to the database as SYS user.&lt;br /&gt;&lt;pre class='brush: sql'&gt;[oracle@localhost ~]$ sqlplus / as sysdba&lt;br /&gt;&lt;br /&gt;SQL*Plus: Release 11.2.0.2.0 Production on Sun Jun 19 12:05:59 2011&lt;br /&gt;&lt;br /&gt;Copyright (c) 1982, 2010, Oracle.  All rights reserved.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Connected to:&lt;br /&gt;Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - Production&lt;br /&gt;With the Partitioning, OLAP, Data Mining and Real Application Testing options&lt;br /&gt;&lt;br /&gt;SQL&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Create sample schemas&lt;br /&gt;&lt;pre class='brush: sql'&gt;SQL&gt; create user u0001 identified by u0001;&lt;br /&gt;&lt;br /&gt;User created.&lt;br /&gt;&lt;br /&gt;SQL&gt; grant create session to u0001;&lt;br /&gt;&lt;br /&gt;Grant succeeded.&lt;br /&gt;&lt;br /&gt;SQL&gt; grant create table to u0001;&lt;br /&gt;&lt;br /&gt;Grant succeeded.&lt;br /&gt;&lt;br /&gt;SQL&gt; create user u0002 identified by u0002;&lt;br /&gt;&lt;br /&gt;User created.&lt;br /&gt;&lt;br /&gt;SQL&gt; grant create session to u0002;&lt;br /&gt;&lt;br /&gt;Grant succeeded.&lt;br /&gt;&lt;br /&gt;SQL&gt; create user u0003 identified by u0003;&lt;br /&gt;&lt;br /&gt;User created.&lt;br /&gt;&lt;br /&gt;SQL&gt; grant create session to u0003;&lt;br /&gt;&lt;br /&gt;Grant succeeded.&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Create a sample table in u0001 schema and give select privilege on this table to u0002 user with grant option.&lt;br /&gt;&lt;pre class='brush: sql'&gt;SQL&gt; conn u0001/u0001&lt;br /&gt;Connected.&lt;br /&gt;SQL&gt; create table t0001 (col1 number, col2 varchar2(100));&lt;br /&gt;&lt;br /&gt;Table created.&lt;br /&gt;&lt;br /&gt;SQL&gt; grant select on t0001 to u0002 with grant option;&lt;br /&gt;&lt;br /&gt;Grant succeeded.&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;pre class='brush: sql'&gt;SQL&gt; column grantee format a7&lt;br /&gt;SQL&gt; column owner format a5&lt;br /&gt;SQL&gt; column table_name format a10&lt;br /&gt;SQL&gt; column grantor format a7&lt;br /&gt;SQL&gt; column privilege format a9&lt;br /&gt;SQL&gt; column grantable format a9&lt;br /&gt;SQL&gt; select * from user_tab_privs&lt;br /&gt;&lt;br /&gt;GRANTEE OWNER TABLE_NAME GRANTOR PRIVILEGE GRANTABLE HIE&lt;br /&gt;------- ----- ---------- ------- --------- --------- ---&lt;br /&gt;U0002   U0001 T0001      U0001   SELECT    YES       NO&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Connect with u0002 and grant select privilege on u0001.t0001 table to user u0003&lt;br /&gt;&lt;pre class='brush: sql'&gt;SQL&gt; conn u0002/u0002&lt;br /&gt;Connected.&lt;br /&gt;SQL&gt; grant select on u0001.t0001 to u0003;&lt;br /&gt;&lt;br /&gt;Grant succeeded.&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Check grants on table u0001.t0001&lt;br /&gt;&lt;pre class='brush: sql'&gt;SQL&gt; conn u0001/u0001&lt;br /&gt;Connected.&lt;br /&gt;SQL&gt; select * from user_tab_privs;&lt;br /&gt;&lt;br /&gt;GRANTEE OWNER TABLE_NAME GRANTOR PRIVILEGE GRANTABLE HIE&lt;br /&gt;------- ----- ---------- ------- --------- --------- ---&lt;br /&gt;U0003   U0001 T0001      U0002   SELECT    NO        NO&lt;br /&gt;U0002   U0001 T0001      U0001   SELECT    YES       NO&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Now revoke select privilege from only user u0002&lt;br /&gt;&lt;pre class='brush: sql'&gt;SQL&gt; revoke select on t0001 from u0002;&lt;br /&gt;&lt;br /&gt;Revoke succeeded.&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;List privileges on table u0001.t0001&lt;br /&gt;&lt;pre class='brush: sql'&gt;SQL&gt; select * from user_tab_privs;&lt;br /&gt;&lt;br /&gt;no rows selected&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;As you can see, although we revoked the select privilege only from user u0002, select privilege given to user u0003 by u0002 user was also revoked, because a "Cascading Revoke" occured. &lt;br /&gt;&lt;br /&gt;In summary, any privilege given to any user(u0003) by another grantor user(u0002) having this privilege "WITH GRANT OPTION" will automatically be revoked when this privilege revoked by object owner(u0001) from this grantor user(u0002).&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6717103620143238053-8489830665570408712?l=uralural.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://uralural.blogspot.com/feeds/8489830665570408712/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6717103620143238053&amp;postID=8489830665570408712' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6717103620143238053/posts/default/8489830665570408712'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6717103620143238053/posts/default/8489830665570408712'/><link rel='alternate' type='text/html' href='http://uralural.blogspot.com/2011/06/with-grant-option-and-cascading-revoke.html' title='&quot;WITH GRANT OPTION&quot; and Cascading Revoke'/><author><name>Ural Ural</name><uri>http://www.blogger.com/profile/06556787053001681445</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='19' height='32' src='http://2.bp.blogspot.com/-FS7mo23hHG0/TjlVoo70i9I/AAAAAAAABwQ/mlpdh17_nwM/s220/IMAG0008.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6717103620143238053.post-958178220768013139</id><published>2011-06-19T08:56:00.000-07:00</published><updated>2011-06-20T11:44:12.299-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='rac'/><category scheme='http://www.blogger.com/atom/ns#' term='ibm aix v5.3'/><category scheme='http://www.blogger.com/atom/ns#' term='crsctl'/><category scheme='http://www.blogger.com/atom/ns#' term='crs_stat'/><category scheme='http://www.blogger.com/atom/ns#' term='ocr'/><category scheme='http://www.blogger.com/atom/ns#' term='os upgrade'/><category scheme='http://www.blogger.com/atom/ns#' term='ibm'/><category scheme='http://www.blogger.com/atom/ns#' term='ibm aix v6.1'/><category scheme='http://www.blogger.com/atom/ns#' term='ocrcheck'/><category scheme='http://www.blogger.com/atom/ns#' term='mknod'/><category scheme='http://www.blogger.com/atom/ns#' term='aix'/><title type='text'>Problem starting the second node of RAC after OS upgrade from IBM AIX v5.3 to v6.1</title><content type='html'>We decided to test the IBM AIX OS upgrade operation in a test Oracle RAC environment. We wanted to do this test in a rolling fashion not to cause any downtime in production environment which is two node Oracle 10gR2 RAC database.&lt;br /&gt;&lt;br /&gt;What happened was that, after Unix team upgraded the OS on second node of RAC from IBM AIX v5.3 to v6.1, we restarted the second node and we saw that Oracle crs processes did not start successfully on the second node.&lt;br /&gt;&lt;br /&gt;We checked the CRS services&lt;br /&gt;&lt;pre class='brush: bash'&gt;[root@srvdb01]:/home/root &gt; crsstat&lt;br /&gt;HA Resource                       Target  State&lt;br /&gt;-----------                       ------  -----&lt;br /&gt;ora.ORCL.ORCL1.inst               ONLINE  ONLINE on srvdb01&lt;br /&gt;ora.ORCL.db                       ONLINE  ONLINE on srvdb01&lt;br /&gt;ora.srvdb01.ASM1.asm              ONLINE  ONLINE on srvdb01&lt;br /&gt;ora.srvdb01.LISTENER_SRVDB01.lsnr ONLINE  ONLINE on srvdb01&lt;br /&gt;ora.srvdb01.gsd                   ONLINE  ONLINE on srvdb01&lt;br /&gt;ora.srvdb01.ons                   ONLINE  ONLINE on srvdb01&lt;br /&gt;ora.srvdb01.vip                   ONLINE  ONLINE on srvdb01&lt;br /&gt;ora.ORCL.ORCL2.inst               OFFLINE OFFLINE&lt;br /&gt;ora.srvdb02.ASM2.asm              OFFLINE OFFLINE&lt;br /&gt;ora.srvdb02.LISTENER_SRVDB02.lsnr OFFLINE OFFLINE&lt;br /&gt;ora.srvdb02.gsd                   OFFLINE OFFLINE&lt;br /&gt;ora.srvdb02.ons                   OFFLINE OFFLINE&lt;br /&gt;ora.srvdb02.vip                   ONLINE  ONLINE on srvdb02&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;As you can see from the above output, "ora.srvdb02.vip" did not automatically moved to node1, so first we relocated that vip service to node1. Because client sessions trying to connect to the database by using this vip address was getting connection errors.&lt;br /&gt;&lt;pre class='brush: bash'&gt;[root@srvdb01]:/home/root &gt; $CRS_HOME/bin/crs_relocate ora.srvdb02.vip&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Status after relocate,&lt;br /&gt;&lt;pre class='brush: bash'&gt;[root@srvdb01]:/home/root &gt; crsstat&lt;br /&gt;HA Resource                       Target State&lt;br /&gt;-----------                       ------  -----&lt;br /&gt;ora.ORCL.ORCL1.inst               ONLINE  ONLINE on srvdb01&lt;br /&gt;ora.ORCL.db                       ONLINE  ONLINE on srvdb01&lt;br /&gt;ora.srvdb01.ASM1.asm              ONLINE  ONLINE on srvdb01&lt;br /&gt;ora.srvdb01.LISTENER_SRVDB01.lsnr ONLINE  ONLINE on srvdb01&lt;br /&gt;ora.srvdb01.gsd                   ONLINE  ONLINE on srvdb01&lt;br /&gt;ora.srvdb01.ons                   ONLINE  ONLINE on srvdb01&lt;br /&gt;ora.srvdb01.vip                   ONLINE  ONLINE on srvdb01&lt;br /&gt;ora.ORCL.ORCL2.inst               OFFLINE OFFLINE&lt;br /&gt;ora.srvdb02.ASM2.asm              OFFLINE OFFLINE&lt;br /&gt;ora.srvdb02.LISTENER_SRVDB02.lsnr OFFLINE OFFLINE&lt;br /&gt;ora.srvdb02.gsd                   OFFLINE OFFLINE&lt;br /&gt;ora.srvdb02.ons                   OFFLINE OFFLINE&lt;br /&gt;ora.srvdb02.vip                   ONLINE  ONLINE on srvdb01&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;By the way if you do not have "crsstat" command on your server, you can use "crs_stat -t" command instead or you can put the following script in a folder and add its path to the "PATH" environment variable in "oracle" user profile on your server. "crs_stat -t" command does not display the full name of "HA Resource" but "crsstat" command below will display full names of "HA Resource" column.&lt;br /&gt;&lt;pre class='brush: bash'&gt;[oracle@srvdb01]:/oracle/uural &gt; more crsstat&lt;br /&gt;#!/usr/bin/ksh&lt;br /&gt;#&lt;br /&gt;# Sample 10g CRS resource status query script&lt;br /&gt;#&lt;br /&gt;# Description:&lt;br /&gt;#    - Returns formatted version of crs_stat -t, in tabular&lt;br /&gt;#      format, with the complete rsc names and filtering keywords&lt;br /&gt;#   - The argument, $RSC_KEY, is optional and if passed to the script, will&lt;br /&gt;#     limit the output to HA resources whose names match $RSC_KEY.&lt;br /&gt;# Requirements:&lt;br /&gt;#   - $ORA_CRS_HOME should be set in your environment&lt;br /&gt;&lt;br /&gt;RSC_KEY=$1&lt;br /&gt;QSTAT=-u&lt;br /&gt;#AWK=/usr/xpg4/bin/awk    # if not available use /usr/bin/awk&lt;br /&gt;AWK=/usr/bin/awk    # if not available use /usr/bin/awk&lt;br /&gt;&lt;br /&gt;# Table header:echo ""&lt;br /&gt;$AWK \&lt;br /&gt;'BEGIN {printf "%-45s %-10s %-18s\n", "HA Resource", "Target", "State";&lt;br /&gt;printf "%-45s %-10s %-18s\n", "-----------", "------", "-----";}'&lt;br /&gt;&lt;br /&gt;# Table body:&lt;br /&gt;$ORA_CRS_HOME/bin/crs_stat $QSTAT | $AWK \&lt;br /&gt;'BEGIN { FS="="; state = 0; }&lt;br /&gt;$1~/NAME/ &amp;&amp; $2~/'$RSC_KEY'/ {appname = $2; state=1};&lt;br /&gt;state == 0 {next;}&lt;br /&gt;$1~/TARGET/ &amp;&amp; state == 1 {apptarget = $2; state=2;}&lt;br /&gt;$1~/STATE/ &amp;&amp; state == 2 {appstate = $2; state=3;}&lt;br /&gt;state == 3 {printf "%-45s %-10s %-18s\n", appname, apptarget, appstate; state=0;}'&lt;br /&gt;&lt;br /&gt;[oracle@srvdb01]:/oracle/uural &gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Anyway we checked the reason why CRS services was down on the second node after OS upgrade. We checked the CRS related logfiles on node2.&lt;br /&gt;We saw the following error.&lt;br /&gt;&lt;pre class='brush: bash'&gt;[root@srvdb02]:/oracle/crshome1/log/srvdb02/client &gt; vi ocrcheck_327920.log&lt;br /&gt;Oracle Database 10g CRS Release 10.2.0.4.0 Production Copyright 1996, 2008 Oracle.  All rights reserved.&lt;br /&gt;2011-06-14 16:13:48.455: [OCRCHECK][1]ocrcheck starts...&lt;br /&gt;2011-06-14 16:13:48.457: [  OCROSD][1]utopen:7:failed to open OCR file/disk /dev/ocr_disk1 /dev/ocr_disk2, errno=19, os err string=No such device&lt;br /&gt;2011-06-14 16:13:48.457: [  OCRRAW][1]proprinit: Could not open raw device&lt;br /&gt;2011-06-14 16:13:48.457: [ default][1]a_init:7!: Backend init unsuccessful : [26]&lt;br /&gt;2011-06-14 16:13:48.457: [OCRCHECK][1]Failed to access OCR repository: [PROC-26: Error while accessing the physical storage Operating System error [No such device] [19]]&lt;br /&gt;2011-06-14 16:13:48.457: [OCRCHECK][1]Failed to initialize ocrchek2&lt;br /&gt;2011-06-14 16:13:48.457: [OCRCHECK][1]Exiting [status=failed]...&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;We thought that node2 could not access the OCR disk anyway. We checked the OCR disk configuration on node2.&lt;br /&gt;&lt;pre class='brush: bash'&gt;[root@srvdb02]:/home/root &gt; ls -l /dev/ocr*&lt;br /&gt;crw-r-----    1 root     dba          23, 27 Jun 08 15:14 /dev/ocr_disk1&lt;br /&gt;crw-r-----    1 root     dba          23,  5 Jun 08 15:16 /dev/ocr_disk2&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;When we first installed Oracle RAC, we created the OCR disks as below&lt;br /&gt;&lt;pre class='brush: bash'&gt;mknod /dev/ocr_disk1 c 23 27&lt;br /&gt;mknod /dev/ocr_disk2 c 23 5&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Querying the corresponding hdisks by using the disk access path "major, minor" numbers gave no results&lt;br /&gt;&lt;pre class='brush: bash'&gt;[root@srvdb02]:/home/root &gt; ls -l /dev/hdisk* | grep "23, 27"&lt;br /&gt;[root@srvdb02]:/home/root &gt; ls -l /dev/hdisk* | grep "23,  5"&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;We realized that major numbers of hdisks have changed after OS upgrade.&lt;br /&gt;&lt;pre class='brush: bash'&gt;[root@srvdb02]:/home/root &gt; ls -l /dev/hdisk* | grep "21, 27"&lt;br /&gt;brw-------    1 root     system       21, 27 Jun 14 15:34 /dev/hdisk25&lt;br /&gt;[root@srvdb02]:/home/root &gt; ls -l /dev/hdisk* | grep "23,  5"&lt;br /&gt;brw-------    1 root     system       21,  5 Jun 14 15:34 /dev/hdisk3&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;But how could we be sure that the minor numbers did not change after OS upgrade. To check this we need to get one level deeper and compare the LUN ids of those hdisks with the ones on the node1 which has stil IBM AIX v5.3 OS.&lt;br /&gt;&lt;br /&gt;We checked the ocr disk configuration on node1&lt;br /&gt;&lt;pre class='brush: bash'&gt;[root@srvdb01]:/home/root &gt; ls -l /dev/ocr*&lt;br /&gt;crw-r-----    1 root     dba          23,  4 Jun 19 15:52 /dev/ocr_disk1&lt;br /&gt;crw-r-----    1 root     dba          23,  5 Jun 19 15:52 /dev/ocr_disk2&lt;br /&gt;[root@srvdb01]:/home/root &gt; ls -l /dev/hdisk* | grep "23,  4"&lt;br /&gt;brw-------    1 root     system       23,  4 May 16 2008  /dev/hdisk2&lt;br /&gt;[root@srvdb01]:/home/root &gt; ls -l /dev/hdisk* | grep "23,  5"&lt;br /&gt;brw-------    1 root     system       23,  5 May 16 2008  /dev/hdisk3&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Find the LUN ids of those hdisks on node1&lt;br /&gt;&lt;pre class='brush: bash'&gt;[root@srvdb01]:/home/root &gt; for i in 2 3&lt;br /&gt;&gt; do&lt;br /&gt;&gt; lsattr -El hdisk$i | grep reserve_policy | awk '{print $1,$2 }'| read rp1 rp2&lt;br /&gt;&gt; lsattr -El hdisk$i | grep pvid | awk '{print $1,$2 }'| read pv1 pv2&lt;br /&gt;&gt; lsattr -El hdisk$i | grep lun_id | awk '{print $1,$2 }'| read li1 li2&lt;br /&gt;&gt; if [ "$li1" != "" ]&lt;br /&gt;&gt; then&lt;br /&gt;&gt; echo hdisk$i' -&gt; '$li1' = '$li2' / '$rp1' = '$rp2' / '$pv1' = '$pv2&lt;br /&gt;&gt; fi&lt;br /&gt;&gt; done&lt;br /&gt;hdisk2 -&gt; lun_id = 0x0001000000000000 / reserve_policy = no_reserve / pvid = none&lt;br /&gt;hdisk3 -&gt; lun_id = 0x0002000000000000 / reserve_policy = no_reserve / pvid = none&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Find the LUN ids of hdisks on node2 which were configured as ocr disks&lt;br /&gt;&lt;pre class='brush: bash'&gt;[root@srvdb02]:/home/root &gt; for i in 25 3&lt;br /&gt;&gt; do&lt;br /&gt;&gt; lsattr -El hdisk$i | grep reserve_policy | awk '{print $1,$2 }'| read rp1 rp2&lt;br /&gt;&gt; lsattr -El hdisk$i | grep pvid | awk '{print $1,$2 }'| read pv1 pv2&lt;br /&gt;&gt; lsattr -El hdisk$i | grep lun_id | awk '{print $1,$2 }'| read li1 li2&lt;br /&gt;&gt; if [ "$li1" != "" ]&lt;br /&gt;&gt; then&lt;br /&gt;&gt; echo hdisk$i' -&gt; '$li1' = '$li2' / '$rp1' = '$rp2' / '$pv1' = '$pv2&lt;br /&gt;&gt; fi&lt;br /&gt;&gt; done&lt;br /&gt;hdisk25 -&gt; lun_id = 0x0018000000000000 / reserve_policy = single_path / pvid = none&lt;br /&gt;hdisk3 -&gt; lun_id = 0x0002000000000000 / reserve_policy = single_path / pvid = none&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;As we compare the LUN ids of those disks on both nodes, we saw that they did not match, which means not only the major numbers but also the minor numbers of hdisks had been changed on node2 after the OS upgrade on this node.&lt;br /&gt;Since we could not find so much information about this problem on the Internet, we discussed with the Unix guys about the problem and we decided that the problem of changing disk access path major minor number change could be the result of IBM AIX v6.1 started to use MPIO to manage storage although IBM AIX v5.3 was using RDAC. Although the Unix guys said they tried to changed the MPIO to RDAC after the upgrade on node2, they said this corrected only the major number change and set the major numbers to the old original values but still the minor numbers were scrambled causing the Oracle RAC node2 to fail to start CRS services.&lt;br /&gt;&lt;br /&gt;In any case like that if the Unix administrators are not able to bring back the original major,minor numbers of the hdisks, what you can do is find the corresponding hdisks numbers by matching the LUN ids on node2, remove ocr disks and create them againg with the correct hdisk major, minor numbers and try to start the OCR on node2.&lt;br /&gt;&lt;br /&gt;I will demonstrate how to find the matching hdisks on node2 by using LUN ids on node1.&lt;br /&gt;List the LUN ids on node2&lt;br /&gt;&lt;pre class='brush: bash'&gt;[root@srvdb02]:/home/root &gt; for i in 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41&lt;br /&gt;&gt; do&lt;br /&gt;&gt; lsattr -El hdisk$i | grep reserve_policy | awk '{print $1,$2 }'| read rp1 rp2&lt;br /&gt;&gt; lsattr -El hdisk$i | grep pvid | awk '{print $1,$2 }'| read pv1 pv2&lt;br /&gt;&gt; lsattr -El hdisk$i | grep lun_id | awk '{print $1,$2 }'| read li1 li2&lt;br /&gt;&gt; if [ "$li1" != "" ]&lt;br /&gt;&gt; then&lt;br /&gt;&gt; echo hdisk$i' -&gt; '$li1' = '$li2' / '$rp1' = '$rp2' / '$pv1' = '$pv2&lt;br /&gt;&gt; fi&lt;br /&gt;&gt; done&lt;br /&gt;hdisk1 -&gt; lun_id = 0x0000000000000000 / reserve_policy = single_path / pvid = none&lt;br /&gt;hdisk2 -&gt; lun_id = 0x0001000000000000 / reserve_policy = single_path / pvid = none&lt;br /&gt;hdisk3 -&gt; lun_id = 0x0002000000000000 / reserve_policy = single_path / pvid = none&lt;br /&gt;hdisk4 -&gt; lun_id = 0x0003000000000000 / reserve_policy = single_path / pvid = none&lt;br /&gt;hdisk5 -&gt; lun_id = 0x0004000000000000 / reserve_policy = single_path / pvid = none&lt;br /&gt;hdisk6 -&gt; lun_id = 0x0005000000000000 / reserve_policy = single_path / pvid = none&lt;br /&gt;hdisk7 -&gt; lun_id = 0x0006000000000000 / reserve_policy = single_path / pvid = none&lt;br /&gt;hdisk8 -&gt; lun_id = 0x0007000000000000 / reserve_policy = single_path / pvid = none&lt;br /&gt;hdisk9 -&gt; lun_id = 0x0008000000000000 / reserve_policy = single_path / pvid = none&lt;br /&gt;hdisk10 -&gt; lun_id = 0x0009000000000000 / reserve_policy = single_path / pvid = none&lt;br /&gt;hdisk11 -&gt; lun_id = 0x000a000000000000 / reserve_policy = single_path / pvid = none&lt;br /&gt;hdisk12 -&gt; lun_id = 0x000b000000000000 / reserve_policy = single_path / pvid = none&lt;br /&gt;hdisk13 -&gt; lun_id = 0x000c000000000000 / reserve_policy = single_path / pvid = none&lt;br /&gt;hdisk14 -&gt; lun_id = 0x000d000000000000 / reserve_policy = single_path / pvid = none&lt;br /&gt;hdisk15 -&gt; lun_id = 0x000e000000000000 / reserve_policy = single_path / pvid = none&lt;br /&gt;hdisk16 -&gt; lun_id = 0x000f000000000000 / reserve_policy = single_path / pvid = none&lt;br /&gt;hdisk17 -&gt; lun_id = 0x0010000000000000 / reserve_policy = single_path / pvid = none&lt;br /&gt;hdisk18 -&gt; lun_id = 0x0011000000000000 / reserve_policy = single_path / pvid = none&lt;br /&gt;hdisk19 -&gt; lun_id = 0x0012000000000000 / reserve_policy = single_path / pvid = none&lt;br /&gt;hdisk20 -&gt; lun_id = 0x0013000000000000 / reserve_policy = single_path / pvid = none&lt;br /&gt;hdisk21 -&gt; lun_id = 0x0014000000000000 / reserve_policy = single_path / pvid = none&lt;br /&gt;hdisk22 -&gt; lun_id = 0x0015000000000000 / reserve_policy = single_path / pvid = none&lt;br /&gt;hdisk23 -&gt; lun_id = 0x0016000000000000 / reserve_policy = single_path / pvid = none&lt;br /&gt;hdisk24 -&gt; lun_id = 0x0017000000000000 / reserve_policy = single_path / pvid = none&lt;br /&gt;hdisk25 -&gt; lun_id = 0x0018000000000000 / reserve_policy = single_path / pvid = none&lt;br /&gt;hdisk26 -&gt; lun_id = 0x0019000000000000 / reserve_policy = single_path / pvid = none&lt;br /&gt;hdisk27 -&gt; lun_id = 0x001a000000000000 / reserve_policy = single_path / pvid = none&lt;br /&gt;hdisk28 -&gt; lun_id = 0x001b000000000000 / reserve_policy = single_path / pvid = none&lt;br /&gt;hdisk29 -&gt; lun_id = 0x001c000000000000 / reserve_policy = single_path / pvid = none&lt;br /&gt;hdisk30 -&gt; lun_id = 0x001d000000000000 / reserve_policy = single_path / pvid = none&lt;br /&gt;hdisk31 -&gt; lun_id = 0x001e000000000000 / reserve_policy = single_path / pvid = none&lt;br /&gt;hdisk32 -&gt; lun_id = 0x001f000000000000 / reserve_policy = single_path / pvid = none&lt;br /&gt;hdisk33 -&gt; lun_id = 0x0028000000000000 / reserve_policy = single_path / pvid = 000c84c103c1d4480000000000000000&lt;br /&gt;hdisk34 -&gt; lun_id = 0x0020000000000000 / reserve_policy = single_path / pvid = none&lt;br /&gt;hdisk35 -&gt; lun_id = 0x0021000000000000 / reserve_policy = single_path / pvid = none&lt;br /&gt;hdisk36 -&gt; lun_id = 0x0022000000000000 / reserve_policy = single_path / pvid = none&lt;br /&gt;hdisk37 -&gt; lun_id = 0x0023000000000000 / reserve_policy = single_path / pvid = none&lt;br /&gt;hdisk38 -&gt; lun_id = 0x0024000000000000 / reserve_policy = single_path / pvid = none&lt;br /&gt;hdisk39 -&gt; lun_id = 0x0025000000000000 / reserve_policy = single_path / pvid = none&lt;br /&gt;hdisk40 -&gt; lun_id = 0x0026000000000000 / reserve_policy = single_path / pvid = none&lt;br /&gt;hdisk41 -&gt; lun_id = 0x0027000000000000 / reserve_policy = single_path / pvid = none&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;As you can see from the following output, if we match hdisk2 and hdisk3 LUN ids on node1 to LUN ids on node2 we found that they correspond again to the hdisk2 and hdisk3 on node2. This time LUN ids and hdisk names matches on both nodes but this is not always like that, hdisk names does not necessarily have to match on both servers everytime, the important thing is LUN ids should match, hdisk2 on node1 could match to hdisk18 on node2 in any other occasion.&lt;br /&gt;&lt;br /&gt;In our case, hdisk2 and hdisk3 on node1 are the same disks as hdisk2 and hdisk3 on node2.&lt;br /&gt;We need to find major, minor numbers of those disks on node2.&lt;br /&gt;&lt;pre class='brush: bash'&gt;[root@srvdb02]:/home/root &gt; ls -l /dev/hdisk[2,3]&lt;br /&gt;brw-------    1 root     system       21,  4 Jun 14 15:34 /dev/hdisk2&lt;br /&gt;brw-------    1 root     system       21,  5 Jun 14 15:34 /dev/hdisk3&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Delete old ocr disk device definitions&lt;br /&gt;&lt;pre class='brush: bash'&gt;[root@srvdb02]:/home/root &gt; rm /dev/ocr_disk1&lt;br /&gt;[root@srvdb02]:/home/root &gt; rm /dev/ocr_disk2&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Recreate ocr disks with the correct disk major,minor numbers&lt;br /&gt;&lt;pre class='brush: bash'&gt;[root@srvdb02]:/home/root &gt; mknod /dev/ocr_disk1 c 21 4&lt;br /&gt;[root@srvdb02]:/home/root &gt; mknod /dev/ocr_disk2 c 21 5&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;After completing this configuration you can first check the status and then try to restart CRS services&lt;br /&gt;&lt;pre class='brush: bash'&gt;[root@srvdb02]:/home/root &gt; crsctl check crs&lt;br /&gt;Failure 1 contacting CSS daemon&lt;br /&gt;Cannot communicate with CRS&lt;br /&gt;Cannot communicate with EVM&lt;br /&gt;[root@srvdb02]:/home/root &gt; crsctl start crs&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6717103620143238053-958178220768013139?l=uralural.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://uralural.blogspot.com/feeds/958178220768013139/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6717103620143238053&amp;postID=958178220768013139' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6717103620143238053/posts/default/958178220768013139'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6717103620143238053/posts/default/958178220768013139'/><link rel='alternate' type='text/html' href='http://uralural.blogspot.com/2011/06/problem-starting-second-node-of-rac.html' title='Problem starting the second node of RAC after OS upgrade from IBM AIX v5.3 to v6.1'/><author><name>Ural Ural</name><uri>http://www.blogger.com/profile/06556787053001681445</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='19' height='32' src='http://2.bp.blogspot.com/-FS7mo23hHG0/TjlVoo70i9I/AAAAAAAABwQ/mlpdh17_nwM/s220/IMAG0008.jpg'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6717103620143238053.post-1706980228405693313</id><published>2011-06-18T18:47:00.000-07:00</published><updated>2011-06-20T11:49:22.845-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='rac'/><category scheme='http://www.blogger.com/atom/ns#' term='rootdeletenode.sh'/><category scheme='http://www.blogger.com/atom/ns#' term='addnode.sh'/><category scheme='http://www.blogger.com/atom/ns#' term='ocrconfig'/><category scheme='http://www.blogger.com/atom/ns#' term='racgons'/><category scheme='http://www.blogger.com/atom/ns#' term='rootdelete.sh'/><category scheme='http://www.blogger.com/atom/ns#' term='vipca'/><category scheme='http://www.blogger.com/atom/ns#' term='oifcfg'/><title type='text'>How to delete and then add the same Oracle RAC node to an Oracle 10gR2 cluster</title><content type='html'>If you will need this kind of operation any time, you can use the following steps  to remove and then add the same Oracle RAC node to an Oracle 10gR2 Cluster.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;1-) Remove node2 from cluster :&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;First we backed up the OCR configuration (in case we need it)&lt;br /&gt;&lt;pre class='brush: bash'&gt;[root@srvdb01]:/home/root &gt; ocrconfig -export beforeupgrade -s online&lt;/pre&gt;&lt;br /&gt;Then we got RAC network configuration on first node.&lt;br /&gt;&lt;pre class='brush: bash'&gt;[root@srvdb01]:/home/root &gt; oifcfg getif&lt;br /&gt;en8  10.1.11.0  global  public&lt;br /&gt;en9  192.168.1.0  global  cluster_interconnect&lt;/pre&gt;&lt;br /&gt;List nodeapps&lt;br /&gt;&lt;pre class='brush: bash'&gt;[root@srvdb01]:/home/root &gt; crsstat&lt;br /&gt;HA Resource                                   Target     State&lt;br /&gt;-----------                                   ------     -----&lt;br /&gt;ora.ORCL.ORCL1.inst                           ONLINE     ONLINE on srvdb01&lt;br /&gt;ora.ORCL.db                                   ONLINE     ONLINE on srvdb01&lt;br /&gt;ora.srvdb01.ASM1.asm                          ONLINE     ONLINE on srvdb01&lt;br /&gt;ora.srvdb01.LISTENER_SRVDB01.lsnr             ONLINE     ONLINE on srvdb01&lt;br /&gt;ora.srvdb01.gsd                               ONLINE     ONLINE on srvdb01&lt;br /&gt;ora.srvdb01.ons                               ONLINE     ONLINE on srvdb01&lt;br /&gt;ora.srvdb01.vip                               ONLINE     ONLINE on srvdb01&lt;br /&gt;ora.ORCL.ORCL2.inst                           ONLINE     ONLINE on srvdb02&lt;br /&gt;ora.srvdb02.ASM2.asm                          ONLINE     ONLINE on srvdb02&lt;br /&gt;ora.srvdb02.LISTENER_SRVDB02.lsnr             ONLINE     ONLINE on srvdb02&lt;br /&gt;ora.srvdb02.gsd                               ONLINE     ONLINE on srvdb02&lt;br /&gt;ora.srvdb02.ons                               ONLINE     ONLINE on srvdb02&lt;br /&gt;ora.srvdb02.vip                               ONLINE     ONLINE on srvdb02&lt;/pre&gt;&lt;br /&gt;On node1 we removed the instance ORCL2 running on node2 by using $ORACLE_HOME/bin/dbca.&lt;br /&gt;&lt;pre class='brush: bash'&gt;[oracle@srvdb01]:/oracle &gt; $ORACLE_HOME/bin/dbca&lt;br /&gt;Choose RAC database&lt;br /&gt;Choose Instance Management&lt;br /&gt;Choose Delete Instance&lt;/pre&gt;&lt;br /&gt;On node1 we stopped and removed the ASM2 instance running on node2.&lt;br /&gt;&lt;pre class='brush: bash'&gt;[root@srvdb01]:/home/root &gt; srvctl stop asm -n srvdb02&lt;br /&gt;[root@srvdb01]:/home/root &gt; srvctl remove asm -n srvdb02&lt;/pre&gt;&lt;br /&gt;On node2 we removed the instance LISTENER_SRVDB02 running on node2 by using $ORACLE_HOME/bin/netca.&lt;br /&gt;&lt;pre class='brush: bash'&gt;[oracle@srvdb02]:/oracle &gt; $ORACLE_HOME/bin/netca&lt;br /&gt;Choose Cluster management&lt;br /&gt;Choose Listener&lt;br /&gt;Choose Remove&lt;br /&gt;Confirm deletion of LISTENER_SRVDB02&lt;/pre&gt;&lt;br /&gt;On node2 update node list in $ORACLE_HOME&lt;br /&gt;&lt;pre class='brush: bash'&gt;[oracle@srvdb02]:/oracle &gt; $ORACLE_HOME/oui/bin/runInstaller -updateNodeList ORACLE_HOME=$ORACLE_HOME CLUSTER_NODES="srvdb02" -local&lt;/pre&gt;&lt;br /&gt;On node1 update node list in $ORACLE_HOME&lt;br /&gt;&lt;pre class='brush: bash'&gt;[oracle@srvdb01]:/oracle &gt; $ORACLE_HOME/oui/bin/runInstaller -updateNodeList ORACLE_HOME=$ORACLE_HOME CLUSTER_NODES="srvdb01"&lt;/pre&gt;&lt;br /&gt;Remove node2 from cluster&lt;br /&gt;&lt;pre class='brush: bash'&gt;[oracle@srvdb01]:/oracle &gt; $CRS_HOME/bin/racgons remove_config srvdb02:6201&lt;/pre&gt;( Replace port 6201 in the above command with the number that you see in the remote port section of the ons.config file in the CRS_HOME/opmn/conf diretory )&lt;br /&gt;&lt;br /&gt;On node2&lt;br /&gt;&lt;pre class='brush: bash'&gt;[root@srvdb02]:/home/root &gt; $CRS_HOME/install/rootdelete.sh&lt;/pre&gt;&lt;br /&gt;List cluster nodes.&lt;br /&gt;&lt;pre class='brush: bash'&gt;[root@srvdb01]:/home/root &gt; olsnodes -n&lt;br /&gt;srvdb01       1&lt;br /&gt;srvdb02       2&lt;/pre&gt;&lt;br /&gt;On node1&lt;br /&gt;&lt;pre class='brush: bash'&gt;[root@srvdb01]:/home/root &gt; $CRS_HOME/install/rootdeletenode.sh srvdb02,2&lt;/pre&gt;&lt;br /&gt;On node2 update node list in $CRS_HOME&lt;br /&gt;&lt;pre class='brush: bash'&gt;[oracle@srvdb02]:/oracle &gt; $CRS_HOME/oui/bin/runInstaller -updateNodeList ORACLE_HOME=$CRS_HOME CLUSTER_NODES="srvdb02" CRS=TRUE -local&lt;/pre&gt;&lt;br /&gt;On node1 update node list in $CRS_HOME&lt;br /&gt;&lt;pre class='brush: bash'&gt;[oracle@srvdb01]:/oracle &gt; $CRS_HOME/oui/bin/runInstaller -updateNodeList ORACLE_HOME=$CRS_HOME CLUSTER_NODES="srvdb01" CRS=TRUE&lt;/pre&gt;&lt;br /&gt;Check the nodeapps have been removed on node2&lt;br /&gt;&lt;pre class='brush: bash'&gt;[root@srvdb01]:/home/root &gt; srvctl status nodeapps -n srvdb02&lt;/pre&gt;&lt;br /&gt;List cluster nodes.&lt;br /&gt;&lt;pre class='brush: bash'&gt;[root@srvdb01]:/home/root &gt; olsnodes -n&lt;br /&gt;srvdb01       1&lt;/pre&gt;&lt;br /&gt;&lt;b&gt;2-) Add node2 back to cluster :&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;Add Cluster Home&lt;br /&gt;&lt;pre class='brush: bash'&gt;[oracle@srvdb01]:/oracle &gt; $CRS_HOME/oui/bin/addNode.sh -nocopy&lt;/pre&gt;&lt;br /&gt;Add node2 to cluster&lt;br /&gt;&lt;pre class='brush: bash'&gt;[oracle@srvdb01]:/oracle &gt; $CRS_HOME/bin/racgons add_config srvdb02:6201&lt;/pre&gt;( Replace port 6201 in the above command with the number that you see in the remote port section of the ons.config file in the CRS_HOME/opmn/conf diretory )&lt;br /&gt;&lt;br /&gt;Add Oracle Home&lt;br /&gt;&lt;pre class='brush: bash'&gt;[oracle@srvdb01]:/oracle &gt; $ORACLE_HOME/oui/bin/addNode.sh -nocopy&lt;/pre&gt;&lt;br /&gt;Configure VIP of node2&lt;br /&gt;&lt;pre class='brush: bash'&gt;[oracle@srvdb01]:/oracle &gt; $ORACLE_HOME/bin/vipca -nodelist srvdb02&lt;/pre&gt;&lt;br /&gt;On node2 we added the instance LISTENER_SRVDB02 running on node2 by using $ORACLE_HOME/bin/netca.&lt;br /&gt;&lt;pre class='brush: bash'&gt;[oracle@srvdb02]:/oracle &gt; $ORACLE_HOME/bin/netca&lt;br /&gt;Choose Cluster management&lt;br /&gt;Choose Listener&lt;br /&gt;Choose Add&lt;br /&gt;Choose the name as LISTENER&lt;br /&gt;This will add a listener on node2 with the name LISTENER_SRVDB02&lt;/pre&gt;&lt;br /&gt;On node1 we added the instance ORCL2 running on node2 by using $ORACLE_HOME/bin/dbca with this step we also created the ASM2 instance.&lt;br /&gt;&lt;pre class='brush: bash'&gt;[oracle@srvdb01]:/oracle &gt; $ORACLE_HOME/bin/dbca&lt;br /&gt;Choose RAC&lt;br /&gt;Choose Instance Management&lt;br /&gt;Choose Add Instance&lt;/pre&gt;&lt;br /&gt;List cluster nodes.&lt;br /&gt;&lt;pre class='brush: bash'&gt;[root@srvdb01]:/home/root &gt; olsnodes -n&lt;br /&gt;srvdb01       1&lt;br /&gt;srvdb02       2&lt;/pre&gt;&lt;br /&gt;List nodeapps&lt;br /&gt;&lt;pre class='brush: bash'&gt;[root@srvdb01]:/home/root &gt; crsstat&lt;br /&gt;HA Resource                                   Target     State&lt;br /&gt;-----------                                   ------     -----&lt;br /&gt;ora.ORCL.ORCL1.inst                           ONLINE     ONLINE on srvdb01&lt;br /&gt;ora.ORCL.db                                   ONLINE     ONLINE on srvdb01&lt;br /&gt;ora.srvdb01.ASM1.asm                          ONLINE     ONLINE on srvdb01&lt;br /&gt;ora.srvdb01.LISTENER_SRVDB01.lsnr             ONLINE     ONLINE on srvdb01&lt;br /&gt;ora.srvdb01.gsd                               ONLINE     ONLINE on srvdb01&lt;br /&gt;ora.srvdb01.ons                               ONLINE     ONLINE on srvdb01&lt;br /&gt;ora.srvdb01.vip                               ONLINE     ONLINE on srvdb01&lt;br /&gt;ora.ORCL.ORCL2.inst                           ONLINE     ONLINE on srvdb02&lt;br /&gt;ora.srvdb02.ASM2.asm                          ONLINE     ONLINE on srvdb02&lt;br /&gt;ora.srvdb02.LISTENER_SRVDB02.lsnr             ONLINE     ONLINE on srvdb02&lt;br /&gt;ora.srvdb02.gsd                               ONLINE     ONLINE on srvdb02&lt;br /&gt;ora.srvdb02.ons                               ONLINE     ONLINE on srvdb02&lt;br /&gt;ora.srvdb02.vip                               ONLINE     ONLINE on srvdb02&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6717103620143238053-1706980228405693313?l=uralural.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://uralural.blogspot.com/feeds/1706980228405693313/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6717103620143238053&amp;postID=1706980228405693313' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6717103620143238053/posts/default/1706980228405693313'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6717103620143238053/posts/default/1706980228405693313'/><link rel='alternate' type='text/html' href='http://uralural.blogspot.com/2011/06/how-to-remove-and-then-add-same-oracle.html' title='How to delete and then add the same Oracle RAC node to an Oracle 10gR2 cluster'/><author><name>Ural Ural</name><uri>http://www.blogger.com/profile/06556787053001681445</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='19' height='32' src='http://2.bp.blogspot.com/-FS7mo23hHG0/TjlVoo70i9I/AAAAAAAABwQ/mlpdh17_nwM/s220/IMAG0008.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6717103620143238053.post-5510763593938869483</id><published>2011-06-18T12:40:00.000-07:00</published><updated>2011-06-20T11:51:57.640-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='archivelog'/><category scheme='http://www.blogger.com/atom/ns#' term='delete input'/><category scheme='http://www.blogger.com/atom/ns#' term='delete all input'/><category scheme='http://www.blogger.com/atom/ns#' term='backup'/><category scheme='http://www.blogger.com/atom/ns#' term='rman'/><title type='text'>The difference between "DELETE INPUT" and "DELETE ALL INPUT" after RMAN archivelog backup</title><content type='html'>Most probably most of you know but I wanted to demonstrate the difference between "DELETE INPUT" and "DELETE ALL INPUT" after RMAN archivelog backup.&lt;br /&gt;&lt;br /&gt;Lets first check the current archivelog destinations in the target database.&lt;br /&gt;&lt;br /&gt;&lt;pre class='brush: sql'&gt;[oracle@localhost ~]$ sqlplus / as sysdba&lt;br /&gt;&lt;br /&gt;SQL*Plus: Release 11.2.0.2.0 Production on Sat Jun 18 12:16:24 2011&lt;br /&gt;&lt;br /&gt;Copyright (c) 1982, 2010, Oracle.  All rights reserved.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Connected to:&lt;br /&gt;Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - Production&lt;br /&gt;With the Partitioning, OLAP, Data Mining and Real Application Testing options&lt;br /&gt;&lt;br /&gt;SQL&gt; sho parameter log_archive_dest&lt;br /&gt;&lt;br /&gt;NAME                                 TYPE        VALUE&lt;br /&gt;------------------------------------ ----------- ------------------------------&lt;br /&gt;log_archive_dest                     string&lt;br /&gt;log_archive_dest_1                   string      LOCATION=/home/oracle/app/orac&lt;br /&gt;le/arc2/ORCL&lt;br /&gt;log_archive_dest_10                  string&lt;br /&gt;log_archive_dest_11                  string&lt;br /&gt;log_archive_dest_12                  string&lt;br /&gt;log_archive_dest_13                  string&lt;br /&gt;log_archive_dest_14                  string&lt;br /&gt;log_archive_dest_15                  string&lt;br /&gt;log_archive_dest_16                  string&lt;br /&gt;log_archive_dest_17                  string&lt;br /&gt;&lt;br /&gt;NAME                                 TYPE        VALUE&lt;br /&gt;------------------------------------ ----------- ------------------------------&lt;br /&gt;log_archive_dest_18                  string&lt;br /&gt;log_archive_dest_19                  string&lt;br /&gt;log_archive_dest_2                   string      LOCATION=USE_DB_RECOVERY_FILE_&lt;br /&gt;DEST&lt;br /&gt;log_archive_dest_20                  string&lt;br /&gt;log_archive_dest_21                  string&lt;br /&gt;log_archive_dest_22                  string&lt;br /&gt;log_archive_dest_23                  string&lt;br /&gt;log_archive_dest_24                  string&lt;br /&gt;log_archive_dest_25                  string&lt;br /&gt;log_archive_dest_26                  string&lt;br /&gt;&lt;br /&gt;NAME                                 TYPE        VALUE&lt;br /&gt;------------------------------------ ----------- ------------------------------&lt;br /&gt;log_archive_dest_27                  string&lt;br /&gt;log_archive_dest_28                  string&lt;br /&gt;log_archive_dest_29                  string&lt;br /&gt;log_archive_dest_3                   string&lt;br /&gt;log_archive_dest_30                  string&lt;br /&gt;log_archive_dest_31                  string&lt;br /&gt;log_archive_dest_4                   string&lt;br /&gt;log_archive_dest_5                   string&lt;br /&gt;log_archive_dest_6                   string&lt;br /&gt;log_archive_dest_7                   string&lt;br /&gt;log_archive_dest_8                   string&lt;br /&gt;&lt;br /&gt;NAME                                 TYPE        VALUE&lt;br /&gt;------------------------------------ ----------- ------------------------------&lt;br /&gt;log_archive_dest_9                   string&lt;br /&gt;log_archive_dest_state_1             string      enable&lt;br /&gt;log_archive_dest_state_10            string      enable&lt;br /&gt;log_archive_dest_state_11            string      enable&lt;br /&gt;log_archive_dest_state_12            string      enable&lt;br /&gt;log_archive_dest_state_13            string      enable&lt;br /&gt;log_archive_dest_state_14            string      enable&lt;br /&gt;log_archive_dest_state_15            string      enable&lt;br /&gt;log_archive_dest_state_16            string      enable&lt;br /&gt;log_archive_dest_state_17            string      enable&lt;br /&gt;log_archive_dest_state_18            string      enable&lt;br /&gt;&lt;br /&gt;NAME                                 TYPE        VALUE&lt;br /&gt;------------------------------------ ----------- ------------------------------&lt;br /&gt;log_archive_dest_state_19            string      enable&lt;br /&gt;log_archive_dest_state_2             string      enable&lt;br /&gt;log_archive_dest_state_20            string      enable&lt;br /&gt;log_archive_dest_state_21            string      enable&lt;br /&gt;log_archive_dest_state_22            string      enable&lt;br /&gt;log_archive_dest_state_23            string      enable&lt;br /&gt;log_archive_dest_state_24            string      enable&lt;br /&gt;log_archive_dest_state_25            string      enable&lt;br /&gt;log_archive_dest_state_26            string      enable&lt;br /&gt;log_archive_dest_state_27            string      enable&lt;br /&gt;log_archive_dest_state_28            string      enable&lt;br /&gt;&lt;br /&gt;NAME                                 TYPE        VALUE&lt;br /&gt;------------------------------------ ----------- ------------------------------&lt;br /&gt;log_archive_dest_state_29            string      enable&lt;br /&gt;log_archive_dest_state_3             string      enable&lt;br /&gt;log_archive_dest_state_30            string      enable&lt;br /&gt;log_archive_dest_state_31            string      enable&lt;br /&gt;log_archive_dest_state_4             string      enable&lt;br /&gt;log_archive_dest_state_5             string      enable&lt;br /&gt;log_archive_dest_state_6             string      enable&lt;br /&gt;log_archive_dest_state_7             string      enable&lt;br /&gt;log_archive_dest_state_8             string      enable&lt;br /&gt;log_archive_dest_state_9             string      enable&lt;br /&gt;SQL&gt; &lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;As you can see there are two archivelog destinations defined "log_archive_dest_1" and "log_archive_dest_2".&lt;br /&gt;&lt;br /&gt;Lets list the archivelogs in the target database by using RMAN tool.&lt;br /&gt;&lt;br /&gt;&lt;pre class='brush: sql'&gt;[oracle@localhost ORCL]$ rman target /&lt;br /&gt;&lt;br /&gt;Recovery Manager: Release 11.2.0.2.0 - Production on Sat Jun 18 12:24:32 2011&lt;br /&gt;&lt;br /&gt;Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.&lt;br /&gt;&lt;br /&gt;connected to target database: ORCL (DBID=1229390655)&lt;br /&gt;&lt;br /&gt;RMAN&gt; list archivelog all;&lt;br /&gt;&lt;br /&gt;using target database control file instead of recovery catalog&lt;br /&gt;List of Archived Log Copies for database with db_unique_name ORCL&lt;br /&gt;=====================================================================&lt;br /&gt;&lt;br /&gt;Key     Thrd Seq     S Low Time &lt;br /&gt;------- ---- ------- - ---------&lt;br /&gt;23      1    404     A 18-JUN-11&lt;br /&gt;Name: /home/oracle/app/oracle/arc2/ORCL/1_404_701609923.dbf&lt;br /&gt;&lt;br /&gt;24      1    404     A 18-JUN-11&lt;br /&gt;Name: /home/oracle/app/oracle/flash_recovery_area/ORCL/archivelog/2011_06_18/o1_mf_1_404_6zsysvtq_.arc&lt;br /&gt;&lt;br /&gt;25      1    405     A 18-JUN-11&lt;br /&gt;Name: /home/oracle/app/oracle/arc2/ORCL/1_405_701609923.dbf&lt;br /&gt;&lt;br /&gt;26      1    405     A 18-JUN-11&lt;br /&gt;Name: /home/oracle/app/oracle/flash_recovery_area/ORCL/archivelog/2011_06_18/o1_mf_1_405_6zsyv5hp_.arc&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;RMAN&gt; &lt;/pre&gt;&lt;br /&gt;Lets now try to backup and delete backed up archivelogs by using "DELETE INPUT".&lt;br /&gt;&lt;br /&gt;&lt;pre class='brush: sql'&gt;RMAN&gt; backup archivelog all delete input;&lt;br /&gt;&lt;br /&gt;Starting backup at 18-JUN-11&lt;br /&gt;current log archived&lt;br /&gt;allocated channel: ORA_DISK_1&lt;br /&gt;channel ORA_DISK_1: SID=43 device type=DISK&lt;br /&gt;channel ORA_DISK_1: starting archived log backup set&lt;br /&gt;channel ORA_DISK_1: specifying archived log(s) in backup set&lt;br /&gt;input archived log thread=1 sequence=404 RECID=24 STAMP=754143819&lt;br /&gt;input archived log thread=1 sequence=405 RECID=26 STAMP=754143861&lt;br /&gt;input archived log thread=1 sequence=406 RECID=28 STAMP=754143995&lt;br /&gt;channel ORA_DISK_1: starting piece 1 at 18-JUN-11&lt;br /&gt;channel ORA_DISK_1: finished piece 1 at 18-JUN-11&lt;br /&gt;piece handle=/home/oracle/app/oracle/flash_recovery_area/ORCL/backupset/2011_06_18/o1_mf_annnn_TAG20110618T122636_6zsyzf26_.bkp tag=TAG20110618T122636 comment=NONE&lt;br /&gt;channel ORA_DISK_1: backup set complete, elapsed time: 00:00:02&lt;br /&gt;channel ORA_DISK_1: deleting archived log(s)&lt;br /&gt;archived log file name=/home/oracle/app/oracle/flash_recovery_area/ORCL/archivelog/2011_06_18/o1_mf_1_404_6zsysvtq_.arc RECID=24 STAMP=754143819&lt;br /&gt;archived log file name=/home/oracle/app/oracle/flash_recovery_area/ORCL/archivelog/2011_06_18/o1_mf_1_405_6zsyv5hp_.arc RECID=26 STAMP=754143861&lt;br /&gt;archived log file name=/home/oracle/app/oracle/flash_recovery_area/ORCL/archivelog/2011_06_18/o1_mf_1_406_6zsyzcjd_.arc RECID=28 STAMP=754143995&lt;br /&gt;Finished backup at 18-JUN-11&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Now list the remaining archivelog files, since only one copy of archivelog files are deleted, we still see the first copies of archivelogs remaining in the first archivelog destination.&lt;br /&gt;&lt;br /&gt;&lt;pre class='brush: sql'&gt;RMAN&gt; list archivelog all;&lt;br /&gt;&lt;br /&gt;List of Archived Log Copies for database with db_unique_name ORCL&lt;br /&gt;=====================================================================&lt;br /&gt;&lt;br /&gt;Key     Thrd Seq     S Low Time &lt;br /&gt;------- ---- ------- - ---------&lt;br /&gt;23      1    404     A 18-JUN-11&lt;br /&gt;Name: /home/oracle/app/oracle/arc2/ORCL/1_404_701609923.dbf&lt;br /&gt;&lt;br /&gt;25      1    405     A 18-JUN-11&lt;br /&gt;Name: /home/oracle/app/oracle/arc2/ORCL/1_405_701609923.dbf&lt;br /&gt;&lt;br /&gt;27      1    406     A 18-JUN-11&lt;br /&gt;Name: /home/oracle/app/oracle/arc2/ORCL/1_406_701609923.dbf&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;RMAN&gt; &lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Now lets try to backup and delete the all the archivelogs backed up by using "DELETE ALL INPUT". We will start the demonstration with newly generated archivelogs.&lt;br /&gt;&lt;pre class='brush: sql'&gt;RMAN&gt; list archivelog all;&lt;br /&gt;&lt;br /&gt;List of Archived Log Copies for database with db_unique_name ORCL&lt;br /&gt;=====================================================================&lt;br /&gt;&lt;br /&gt;Key     Thrd Seq     S Low Time &lt;br /&gt;------- ---- ------- - ---------&lt;br /&gt;29      1    407     A 18-JUN-11&lt;br /&gt;Name: /home/oracle/app/oracle/arc2/ORCL/1_407_701609923.dbf&lt;br /&gt;&lt;br /&gt;30      1    407     A 18-JUN-11&lt;br /&gt;Name: /home/oracle/app/oracle/flash_recovery_area/ORCL/archivelog/2011_06_18/o1_mf_1_407_6zsz7586_.arc&lt;br /&gt;&lt;br /&gt;31      1    408     A 18-JUN-11&lt;br /&gt;Name: /home/oracle/app/oracle/arc2/ORCL/1_408_701609923.dbf&lt;br /&gt;&lt;br /&gt;32      1    408     A 18-JUN-11&lt;br /&gt;Name: /home/oracle/app/oracle/flash_recovery_area/ORCL/archivelog/2011_06_18/o1_mf_1_408_6zsz78g4_.arc&lt;/pre&gt;&lt;br /&gt;Backup and delete all of them.&lt;br /&gt;&lt;br /&gt;&lt;pre class='brush: sql'&gt;RMAN&gt; backup archivelog all delete all input;&lt;br /&gt;&lt;br /&gt;Starting backup at 18-JUN-11&lt;br /&gt;current log archived&lt;br /&gt;using channel ORA_DISK_1&lt;br /&gt;channel ORA_DISK_1: starting archived log backup set&lt;br /&gt;channel ORA_DISK_1: specifying archived log(s) in backup set&lt;br /&gt;input archived log thread=1 sequence=407 RECID=30 STAMP=754144245&lt;br /&gt;input archived log thread=1 sequence=408 RECID=32 STAMP=754144248&lt;br /&gt;input archived log thread=1 sequence=409 RECID=34 STAMP=754144369&lt;br /&gt;channel ORA_DISK_1: starting piece 1 at 18-JUN-11&lt;br /&gt;channel ORA_DISK_1: finished piece 1 at 18-JUN-11&lt;br /&gt;piece handle=/home/oracle/app/oracle/flash_recovery_area/ORCL/backupset/2011_06_18/o1_mf_annnn_TAG20110618T123249_6zszc1s6_.bkp tag=TAG20110618T123249 comment=NONE&lt;br /&gt;channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01&lt;br /&gt;channel ORA_DISK_1: deleting archived log(s)&lt;br /&gt;archived log file name=/home/oracle/app/oracle/flash_recovery_area/ORCL/archivelog/2011_06_18/o1_mf_1_407_6zsz7586_.arc RECID=30 STAMP=754144245&lt;br /&gt;archived log file name=/home/oracle/app/oracle/arc2/ORCL/1_407_701609923.dbf RECID=29 STAMP=754144245&lt;br /&gt;archived log file name=/home/oracle/app/oracle/flash_recovery_area/ORCL/archivelog/2011_06_18/o1_mf_1_408_6zsz78g4_.arc RECID=32 STAMP=754144248&lt;br /&gt;archived log file name=/home/oracle/app/oracle/arc2/ORCL/1_408_701609923.dbf RECID=31 STAMP=754144248&lt;br /&gt;archived log file name=/home/oracle/app/oracle/flash_recovery_area/ORCL/archivelog/2011_06_18/o1_mf_1_409_6zszc108_.arc RECID=34 STAMP=754144369&lt;br /&gt;archived log file name=/home/oracle/app/oracle/arc2/ORCL/1_409_701609923.dbf RECID=33 STAMP=754144369&lt;br /&gt;Finished backup at 18-JUN-11&lt;br /&gt;&lt;br /&gt;RMAN&gt; list archivelog all;&lt;br /&gt;&lt;br /&gt;specification does not match any archived log in the repository&lt;br /&gt;&lt;br /&gt;RMAN&gt; &lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;As a result, by using "DELETE INPUT" we made RMAN, backup only one copy of all the archivelogs in one archivelog destination and then delete only the backed up copies of all the archivelogs in only one archivelog destination, but by using "DELETE ALL INPUT", we made RMAN backup only one copy of all the archivelogs in one archivelog destination and then delete all the copies of all the archivelogs in all the archivelog destinations.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6717103620143238053-5510763593938869483?l=uralural.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://uralural.blogspot.com/feeds/5510763593938869483/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6717103620143238053&amp;postID=5510763593938869483' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6717103620143238053/posts/default/5510763593938869483'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6717103620143238053/posts/default/5510763593938869483'/><link rel='alternate' type='text/html' href='http://uralural.blogspot.com/2011/06/difference-between-delete-input-and.html' title='The difference between &quot;DELETE INPUT&quot; and &quot;DELETE ALL INPUT&quot; after RMAN archivelog backup'/><author><name>Ural Ural</name><uri>http://www.blogger.com/profile/06556787053001681445</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='19' height='32' src='http://2.bp.blogspot.com/-FS7mo23hHG0/TjlVoo70i9I/AAAAAAAABwQ/mlpdh17_nwM/s220/IMAG0008.jpg'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6717103620143238053.post-4613989364317734967</id><published>2011-06-18T06:11:00.000-07:00</published><updated>2011-06-20T11:56:04.071-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='v$rman_status'/><category scheme='http://www.blogger.com/atom/ns#' term='monitor'/><category scheme='http://www.blogger.com/atom/ns#' term='rman log'/><category scheme='http://www.blogger.com/atom/ns#' term='rman'/><category scheme='http://www.blogger.com/atom/ns#' term='v$rman_output'/><title type='text'>Monitoring last RMAN backup log in target Oracle database in Oracle 10g</title><content type='html'>You can use two simple SQL commands to monitor the last RMAN backup log in target Oracle database without using RMAN catalog database in Oracle 10g.&lt;br /&gt;&lt;br /&gt;The information in "v$rman_status" comes from the target database controlfile, showing one record for every RMAN command executed in RMAN backup script.&lt;br /&gt;&lt;br /&gt;&lt;pre class='brush: sql'&gt;select * &lt;br /&gt;from v$rman_status &lt;br /&gt;where session_recid = (select max(session_recid) from v$rman_status) &lt;br /&gt;order by recid;&lt;/pre&gt;&lt;br /&gt;The information in "v$rman_output" comes from the target database memory and is not stored in target database controlfile, showing all  the output as seperate records for every RMAN command executed in RMAN backup script.&lt;br /&gt;&lt;br /&gt;In a single server database you should use "v$rman_output", if you have a RAC database you should use "gv$rman_output" dynamic view instead.&lt;br /&gt;&lt;br /&gt;&lt;pre class='brush: sql'&gt;select * &lt;br /&gt;from v$rman_output &lt;br /&gt;where session_recid = (select max(session_recid) from v$rman_status) &lt;br /&gt;order by recid ;&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6717103620143238053-4613989364317734967?l=uralural.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://uralural.blogspot.com/feeds/4613989364317734967/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6717103620143238053&amp;postID=4613989364317734967' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6717103620143238053/posts/default/4613989364317734967'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6717103620143238053/posts/default/4613989364317734967'/><link rel='alternate' type='text/html' href='http://uralural.blogspot.com/2011/06/monitoring-last-rman-backup-log-in.html' title='Monitoring last RMAN backup log in target Oracle database in Oracle 10g'/><author><name>Ural Ural</name><uri>http://www.blogger.com/profile/06556787053001681445</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='19' height='32' src='http://2.bp.blogspot.com/-FS7mo23hHG0/TjlVoo70i9I/AAAAAAAABwQ/mlpdh17_nwM/s220/IMAG0008.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6717103620143238053.post-8041476919172629670</id><published>2011-06-17T06:45:00.000-07:00</published><updated>2011-06-20T11:58:56.591-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='expdp'/><category scheme='http://www.blogger.com/atom/ns#' term='filesystem'/><category scheme='http://www.blogger.com/atom/ns#' term='export'/><category scheme='http://www.blogger.com/atom/ns#' term='nfs'/><category scheme='http://www.blogger.com/atom/ns#' term='aix'/><title type='text'>ORA-27054: NFS file system where the file is created or resides is not mounted with correct options</title><content type='html'>Today, we faced an error in some of our daily Oracle database export jobs as below.&lt;br /&gt;&lt;br /&gt;&lt;pre class='brush: sql'&gt;;;;&lt;br /&gt;Export: Release 10.2.0.3.0 - 64bit Production on Friday, 17 June, 2011 0:30:00&lt;br /&gt;&lt;br /&gt;Copyright (c) 2003, 2005, Oracle.  All rights reserved.&lt;br /&gt;;;;&lt;br /&gt;Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bit Production&lt;br /&gt;With the Partitioning, OLAP, Data Mining and Real Application Testing options&lt;br /&gt;ORA-39000: bad dump file specification&lt;br /&gt;ORA-31641: unable to create dump file "/export/SRVDB01_DEV_DEV_201106170030_01.dmp"&lt;br /&gt;ORA-27054: NFS file system where the file is created or resides is not mounted with correct options&lt;br /&gt;IBM AIX RISC System/6000 Error: 13: Permission denied&lt;br /&gt;Additional information: 4&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Working together with our Unix team, we tried to solve the problem.&lt;br /&gt;First we checked the "/export" NFS file system mount options on AIX server.&lt;br /&gt;&lt;br /&gt;&lt;pre class='brush: bash'&gt;[oracle@srvdb01]:/oracle &gt; mount -p&lt;br /&gt;node       mounted        mounted over    vfs       date        options&lt;br /&gt;-------- ---------------  ---------------  ------ ------------ ---------------&lt;br /&gt;srvnfs01 /export          /export          nfs3   Jun 17 14:02 bg,hard,intr,rsize=32768,wsize=32768,proto=udp,sec=sys,rw&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;We saw that the mount options are correct on the database server where the "/export" filesystem is mounted.&lt;br /&gt;&lt;br /&gt;Then, one of our Unix team members realized that file access permissions on "/etc/filesystems" file does not have a read permission for the Unix user "oracle" and he gave this permission so that "oracle" Unix user can read this file.&lt;br /&gt;&lt;br /&gt;&lt;pre class='brush: bash'&gt;--Before&lt;br /&gt;[oracle@srvdb01]:/oracle &gt; ls -ld /etc/filesystems&lt;br /&gt;-rw-rw----    1 root     system         3107 Jun 17 14:38 /etc/filesystems&lt;br /&gt;&lt;br /&gt;--After&lt;br /&gt;[oracle@srvdb01]:/oracle &gt; ls -ld /etc/filesystems&lt;br /&gt;-rw-r--r--    1 root     system         3107 Jun 17 14:38 /etc/filesystems&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;And the Oracle export can not write to "/export" NFS filesystem problem is solved.&lt;br /&gt;&lt;br /&gt;What I think Oracle Export Datapump Utility does is, it reads "/etc/filesystems" file when exporting to an NFS file system. This file contains an entry about the mounted "/export" NFS filesystem in it.&lt;br /&gt;&lt;br /&gt;&lt;pre class='brush: bash'&gt;[oracle@srvdb01]:/oracle &gt; more /etc/filesystems&lt;br /&gt;...&lt;br /&gt;/export:&lt;br /&gt;dev             = "/export"&lt;br /&gt;vfs             = nfs&lt;br /&gt;nodename        = srvnfs01&lt;br /&gt;mount           = true&lt;br /&gt;options         = bg,hard,intr,rsize=32768,wsize=32768,proto=udp,sec=sys,rw&lt;br /&gt;account         = false&lt;br /&gt;...&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6717103620143238053-8041476919172629670?l=uralural.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://uralural.blogspot.com/feeds/8041476919172629670/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6717103620143238053&amp;postID=8041476919172629670' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6717103620143238053/posts/default/8041476919172629670'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6717103620143238053/posts/default/8041476919172629670'/><link rel='alternate' type='text/html' href='http://uralural.blogspot.com/2011/06/ora-27054-nfs-file-system-where-file-is.html' title='ORA-27054: NFS file system where the file is created or resides is not mounted with correct options'/><author><name>Ural Ural</name><uri>http://www.blogger.com/profile/06556787053001681445</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='19' height='32' src='http://2.bp.blogspot.com/-FS7mo23hHG0/TjlVoo70i9I/AAAAAAAABwQ/mlpdh17_nwM/s220/IMAG0008.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6717103620143238053.post-6619151509260409315</id><published>2010-02-19T09:44:00.001-08:00</published><updated>2011-06-20T12:10:25.521-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='trace'/><category scheme='http://www.blogger.com/atom/ns#' term='index'/><category scheme='http://www.blogger.com/atom/ns#' term='nologging'/><category scheme='http://www.blogger.com/atom/ns#' term='rebuild'/><category scheme='http://www.blogger.com/atom/ns#' term='parallel'/><category scheme='http://www.blogger.com/atom/ns#' term='oracle'/><title type='text'>Parallel index rebuild</title><content type='html'>You can use parallel index rebuild option whenever you have to rebuild an index since, most of the time, parallel rebuild option will be much faster than a noparallel operation.&lt;br /&gt;&lt;br /&gt;I will try to demonstrate this situation below.&lt;br /&gt;&lt;br /&gt;First create a tablespace and a database user&lt;br /&gt;&lt;pre class='brush: sql'&gt;C:\uural\work_cmd\20081014&gt;sqlplus sys@db01 as sysdba&lt;br /&gt;&lt;br /&gt;SQL*Plus: Release 10.2.0.1.0 - Production on Fri Feb 19 15:16:33 2010&lt;br /&gt;&lt;br /&gt;Copyright (c) 1982, 2005, Oracle.  All rights reserved.&lt;br /&gt;&lt;br /&gt;Enter password: &lt;br /&gt;&lt;br /&gt;Connected to:&lt;br /&gt;Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bit Production&lt;br /&gt;With the Partitioning, OLAP, Data Mining and Real Application Testing options&lt;br /&gt;&lt;br /&gt;SYS@db01&gt; create tablespace tbs01;&lt;br /&gt;&lt;br /&gt;Tablespace created.&lt;br /&gt;&lt;br /&gt;SYS@db01&gt; create user dbuser01 identified by dbuser01 default tablespace tbs01;&lt;br /&gt;&lt;br /&gt;User created.&lt;br /&gt;&lt;br /&gt;SYS@db01&gt; grant connect, resource to dbuser01;&lt;br /&gt;&lt;br /&gt;Grant succeeded.&lt;br /&gt;&lt;br /&gt;SYS@db01&gt; grant alter system to dbuser01;&lt;br /&gt;&lt;br /&gt;Grant succeeded.&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Connect to the database with the new user&lt;br /&gt;&lt;pre class='brush: sql'&gt;C:\uural\work_cmd\20100219&gt;sqlplus dbuser01/dbuser01@db01&lt;br /&gt;&lt;br /&gt;SQL*Plus: Release 10.2.0.1.0 - Production on Fri Feb 19 15:32:56 2010&lt;br /&gt;&lt;br /&gt;Copyright (c) 1982, 2005, Oracle.  All rights reserved.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Connected to:&lt;br /&gt;Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bit Production&lt;br /&gt;With the Partitioning, OLAP, Data Mining and Real Application Testing options&lt;br /&gt;&lt;br /&gt;DBUSER01@db01&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Create a test table&lt;br /&gt;&lt;pre class='brush: sql'&gt;DBUSER01@db01&gt; @cre_table01&lt;br /&gt;DBUSER01@db01&gt; create table table01 nologging pctfree 90&lt;br /&gt;2  as&lt;br /&gt;3  select dbms_random.value(1,1000000) id&lt;br /&gt;4  , rpad('*',4000,'*') data&lt;br /&gt;5    from dual&lt;br /&gt;6  connect by level &lt;= 1000000;&lt;br /&gt;&lt;br /&gt;Table created.&lt;br /&gt;&lt;/pre&gt;Create an index on this test table&lt;pre class='brush: sql'&gt;DBUSER01@db01&gt; select blocks,bytes from user_segments where segment_name = 'TABLE01';&lt;br /&gt;&lt;br /&gt;BLOCKS BYTES&lt;br /&gt;---------- ----------&lt;br /&gt;1007616 8254390272&lt;br /&gt;&lt;br /&gt;1 row selected.&lt;br /&gt;&lt;br /&gt;DBUSER01@db01&gt; create index table01_01 on table01(id) nologging;&lt;br /&gt;Index created.&lt;br /&gt;&lt;/pre&gt;Make this index unusable&lt;pre class='brush: sql'&gt;DBUSER01@db01&gt; alter index table01_01 unusable;&lt;br /&gt;&lt;/pre&gt;Clear the buffer cache of the database&lt;pre class='brush: sql'&gt;SYS@db01&gt; alter system flush buffer_cache;&lt;br /&gt;&lt;br /&gt;System altered.&lt;br /&gt;&lt;/pre&gt;Set timing on&lt;pre class='brush: sql'&gt;DBUSER01@db01&gt; show timing&lt;br /&gt;timing OFF&lt;br /&gt;DBUSER01@db01&gt; set timing on&lt;br /&gt;&lt;/pre&gt;Enable session trace&lt;pre class='brush: sql'&gt;DBUSER01@db01&gt; alter system set sql_trace=TRUE;&lt;br /&gt;&lt;br /&gt;System altered.&lt;br /&gt;&lt;br /&gt;Elapsed: 00:00:00.00&lt;br /&gt;&lt;/pre&gt;Run NOPARALLEL index rebuild&lt;pre class='brush: sql'&gt;DBUSER01@db01&gt; alter index table01_01 rebuild nologging;&lt;br /&gt;&lt;br /&gt;Index altered.&lt;br /&gt;&lt;br /&gt;Elapsed: 00:01:01.20&lt;br /&gt;&lt;/pre&gt;It took 1 minutes 1 secondsCheck the trace file&lt;pre class='brush: plain'&gt;********************************************************************************&lt;br /&gt;&lt;br /&gt;alter index table01_01 rebuild nologging&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;call     count       cpu    elapsed       disk      query    current        rows&lt;br /&gt;------- ------  -------- ---------- ---------- ---------- ----------  ----------&lt;br /&gt;Parse        1      0.00       0.03          1          1          0           0&lt;br /&gt;Execute      1     20.11      59.45    1000005    1000174       6897           0&lt;br /&gt;Fetch        0      0.00       0.00          0          0          0           0&lt;br /&gt;------- ------  -------- ---------- ---------- ---------- ----------  ----------&lt;br /&gt;total        2     20.11      59.49    1000006    1000175       6897           0&lt;br /&gt;&lt;br /&gt;Misses in library cache during parse: 1&lt;br /&gt;Optimizer mode: ALL_ROWS&lt;br /&gt;Parsing user id: 378&lt;br /&gt;********************************************************************************  &lt;br /&gt;&lt;/pre&gt;Before trying the PARALLEL option clear the buffer cache again&lt;pre class='brush: sql'&gt;SYS@db01&gt; alter system flush buffer_cache;&lt;br /&gt;&lt;br /&gt;System altered.&lt;br /&gt;&lt;/pre&gt;Rebuild the index with PARALLEL option this time&lt;pre class='brush: sql'&gt;DBUSER01@db01&gt; alter index table01_01 unusable;&lt;br /&gt;&lt;br /&gt;Index altered.&lt;br /&gt;&lt;br /&gt;Elapsed: 00:00:00.07&lt;br /&gt;DBUSER01@db01&gt; alter index table01_01 rebuild parallel nologging;&lt;br /&gt;&lt;br /&gt;Index altered.&lt;br /&gt;&lt;br /&gt;Elapsed: 00:00:30.62&lt;br /&gt;DBUSER01@db01&gt; &lt;br /&gt;&lt;/pre&gt;It took 30 secondsCheck the trace file again&lt;pre class='brush: plain'&gt;********************************************************************************&lt;br /&gt;&lt;br /&gt;alter index table01_01 rebuild parallel nologging&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;call     count       cpu    elapsed       disk      query    current        rows&lt;br /&gt;------- ------  -------- ---------- ---------- ---------- ----------  ----------&lt;br /&gt;Parse        1      0.00       0.00          1          1          0           0&lt;br /&gt;Execute      1      0.06      29.72    1005359    1003636       9010           0&lt;br /&gt;Fetch        0      0.00       0.00          0          0          0           0&lt;br /&gt;------- ------  -------- ---------- ---------- ---------- ----------  ----------&lt;br /&gt;total        2      0.06      29.73    1005360    1003637       9010           0&lt;br /&gt;&lt;br /&gt;Misses in library cache during parse: 1&lt;br /&gt;Optimizer mode: ALL_ROWS&lt;br /&gt;Parsing user id: 378&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;******************************************************************************** &lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;As you can see parallel index rebuild is much faster than noparallel index rebuild.&lt;br /&gt;Since, most of the time,  parallel operations use the server CPU more efficiently, especially in data warehouse databases&lt;br /&gt;we better use the parallel option in database operations whenever possible.&lt;br /&gt;&lt;br /&gt;Regards,&lt;br /&gt;Ural&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6717103620143238053-6619151509260409315?l=uralural.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://uralural.blogspot.com/feeds/6619151509260409315/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6717103620143238053&amp;postID=6619151509260409315' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6717103620143238053/posts/default/6619151509260409315'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6717103620143238053/posts/default/6619151509260409315'/><link rel='alternate' type='text/html' href='http://uralural.blogspot.com/2010/02/parallel-index-rebuild.html' title='Parallel index rebuild'/><author><name>Ural Ural</name><uri>http://www.blogger.com/profile/06556787053001681445</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='19' height='32' src='http://2.bp.blogspot.com/-FS7mo23hHG0/TjlVoo70i9I/AAAAAAAABwQ/mlpdh17_nwM/s220/IMAG0008.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6717103620143238053.post-7670319688062975703</id><published>2010-02-19T03:18:00.001-08:00</published><updated>2011-06-20T12:19:41.180-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='rac'/><category scheme='http://www.blogger.com/atom/ns#' term='node'/><category scheme='http://www.blogger.com/atom/ns#' term='kill'/><category scheme='http://www.blogger.com/atom/ns#' term='job'/><category scheme='http://www.blogger.com/atom/ns#' term='session'/><category scheme='http://www.blogger.com/atom/ns#' term='gv$session'/><category scheme='http://www.blogger.com/atom/ns#' term='oracle'/><title type='text'>How to kill a session which is connected to another RAC node in an Oracle 10g RAC database</title><content type='html'>If you want to kill a session which is connected to another node of an Oracle 10g RAC database, there is no one direct single command provided by Oracle which you can use, this became possible with the version 11g of Oracle RAC database.&lt;br /&gt;&lt;br /&gt;For example, assume that you have a 2-node Oracle 10g RAC database and you are currently connected to the first node with SYS user. You want to kill a session that is connected to the second node of RAC database. This is not possible with one single command in 10g. You can use the database package that I developed below which uses database job method to kill a session that is connected on another node of Oracle 10g RAC database. I also tried to explain the situation below.&lt;br /&gt;&lt;br /&gt;First connect to the first node of 2-node Oracle 10g RAC database.&lt;br /&gt;&lt;br /&gt;&lt;pre class='brush: sql'&gt;C:\Documents and Settings\user01&gt;sqlplus sys@server01_inst1 as sysdba&lt;br /&gt;&lt;br /&gt;SQL*Plus: Release 10.2.0.1.0 - Production on Fri Feb 19 09:59:03 2010&lt;br /&gt;&lt;br /&gt;Copyright (c) 1982, 2005, Oracle.  All rights reserved.&lt;br /&gt;&lt;br /&gt;Enter password:&lt;br /&gt;&lt;br /&gt;Connected to:&lt;br /&gt;Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bit Production&lt;br /&gt;With the Partitioning, Real Application Clusters, OLAP, Data Mining&lt;br /&gt;and Real Application Testing options&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Bring some information about this RAC database&lt;br /&gt;&lt;pre class='brush: sql'&gt;SQL&gt; set lines 200&lt;br /&gt;SQL&gt; col host_name format a30&lt;br /&gt;SQL&gt; r&lt;br /&gt;1  select inst_id, instance_number, instance_name, host_name, version, status&lt;br /&gt;2* from gv$instance&lt;br /&gt;&lt;br /&gt;INST_ID INSTANCE_NUMBER INSTANCE_NAME    HOST_NAME                      VERSION           STATUS&lt;br /&gt;---------- --------------- ---------------- ------------------------------ ----------------- ------------&lt;br /&gt;1               1 INST1            server01                       10.2.0.4.0        OPEN&lt;br /&gt;2               2 INST2            server02                       10.2.0.4.0        OPEN&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;I am connected to the fist node&lt;br /&gt;&lt;br /&gt;&lt;pre class='brush: sql'&gt;SQL&gt; select instance_number, instance_name, host_name, version, status&lt;br /&gt;2  from v$instance;&lt;br /&gt;&lt;br /&gt;INSTANCE_NUMBER INSTANCE_NAME    HOST_NAME                      VERSION           STATUS&lt;br /&gt;--------------- ---------------- ------------------------------ ----------------- ------------&lt;br /&gt;1 INST1            server01                       10.2.0.4.0        OPEN&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Create a schema in which I will create my package&lt;br /&gt;&lt;pre class='brush: sql'&gt;SQL&gt; create user dbuser01 identified by dbuser01;&lt;br /&gt;&lt;br /&gt;User created.&lt;br /&gt;&lt;br /&gt;SQL&gt; grant create session to dbuser01;&lt;br /&gt;&lt;br /&gt;Grant succeeded.&lt;br /&gt;&lt;br /&gt;SQL&gt; grant select on gv_$session to dbuser01;&lt;br /&gt;&lt;br /&gt;Grant succeeded.&lt;br /&gt;&lt;br /&gt;SQL&gt; grant alter system to dbuser01;&lt;br /&gt;&lt;br /&gt;Grant succeeded.&lt;br /&gt;&lt;br /&gt;SQL&gt; grant create job to dbuser01;&lt;br /&gt;&lt;br /&gt;Grant succeeded.&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Create the package&lt;br /&gt;&lt;pre class='brush: sql'&gt;SQL&gt; CREATE OR REPLACE PACKAGE dbuser01.DBA_OPERATION IS&lt;br /&gt;2&lt;br /&gt;3  PROCEDURE Kill_Session_User(p_username VARCHAR2);&lt;br /&gt;4  PROCEDURE Kill_Session_Job(p_sid     NUMBER,&lt;br /&gt;5                             p_serial  NUMBER,&lt;br /&gt;6                             p_inst_id NUMBER);&lt;br /&gt;7  PROCEDURE Kill_Session(p_sid     NUMBER,&lt;br /&gt;8                         p_serial  NUMBER);&lt;br /&gt;9  END DBA_OPERATION;&lt;br /&gt;10  /&lt;br /&gt;&lt;br /&gt;Package created.&lt;br /&gt;&lt;br /&gt;SQL&gt;&lt;br /&gt;SQL&gt; CREATE OR REPLACE PACKAGE BODY dbuser01.DBA_OPERATION IS&lt;br /&gt;2&lt;br /&gt;3  PROCEDURE Kill_Session_User(p_username VARCHAR2) IS&lt;br /&gt;4    d_stmt VARCHAR2(4000);&lt;br /&gt;5  BEGIN&lt;br /&gt;6    FOR c_stmt IN (&lt;br /&gt;7      SELECT t1.sid, t1.serial#, t1.inst_id&lt;br /&gt;8        FROM gv$session t1&lt;br /&gt;9       WHERE t1.username = p_username&lt;br /&gt;10     ) LOOP&lt;br /&gt;11      Kill_Session_Job(p_sid     =&gt; c_stmt.sid,&lt;br /&gt;12                       p_serial  =&gt; c_stmt.serial#,&lt;br /&gt;13                       p_inst_id =&gt; c_stmt.inst_id);&lt;br /&gt;14    END LOOP;&lt;br /&gt;15    DBMS_OUTPUT.Put_Line('===== All the database sessions of user "'||p_username||'" killed successfully ! =====');&lt;br /&gt;16&lt;br /&gt;17  END Kill_Session_User;&lt;br /&gt;18&lt;br /&gt;19  PROCEDURE Kill_Session_Job(p_sid     NUMBER,&lt;br /&gt;20                             p_serial  NUMBER,&lt;br /&gt;21                             p_inst_id NUMBER) IS&lt;br /&gt;22    JOB BINARY_INTEGER;&lt;br /&gt;23    d_stmt VARCHAR2(4000);&lt;br /&gt;24  BEGIN&lt;br /&gt;25    d_stmt := 'begin dbuser01.DBA_OPERATION.Kill_Session(p_sid =&gt; '||p_sid||', p_serial =&gt; '||p_serial||'); end;';&lt;br /&gt;26    SYS.DBMS_JOB.Submit(job =&gt; job, what =&gt; d_stmt, instance =&gt; p_inst_id);&lt;br /&gt;27    COMMIT;&lt;br /&gt;28    DBMS_OUTPUT.Put_Line(d_stmt);&lt;br /&gt;29  END Kill_Session_Job;&lt;br /&gt;30&lt;br /&gt;31  PROCEDURE Kill_Session(p_sid     NUMBER,&lt;br /&gt;32                         p_serial  NUMBER) IS&lt;br /&gt;33    d_stmt VARCHAR2(4000);&lt;br /&gt;34  BEGIN&lt;br /&gt;35    d_stmt := 'ALTER SYSTEM KILL SESSION '''||p_sid||', '||p_serial||''' IMMEDIATE';&lt;br /&gt;36    DBMS_OUTPUT.Put_Line(d_stmt);&lt;br /&gt;37    EXECUTE IMMEDIATE d_stmt;&lt;br /&gt;38  END Kill_Session;&lt;br /&gt;39&lt;br /&gt;40  END DBA_OPERATION;&lt;br /&gt;41  /&lt;br /&gt;&lt;br /&gt;Package body created.&lt;br /&gt;&lt;br /&gt;SQL&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Create a second user which we will use in kill session test&lt;br /&gt;&lt;pre class='brush: sql'&gt;SQL&gt; create user dbuser02 identified by dbuser02;&lt;br /&gt;&lt;br /&gt;User created.&lt;br /&gt;&lt;br /&gt;SQL&gt; grant create session to dbuser02;&lt;br /&gt;&lt;br /&gt;Grant succeeded.&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Connect to the second node of RAC with this user&lt;br /&gt;&lt;pre class='brush: sql'&gt;C:\Documents and Settings\user01&gt;sqlplus dbuser02/dbuser02@server02_inst2&lt;br /&gt;&lt;br /&gt;SQL*Plus: Release 10.2.0.1.0 - Production on Fri Feb 19 10:22:58 2010&lt;br /&gt;&lt;br /&gt;Copyright (c) 1982, 2005, Oracle.  All rights reserved.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Connected to:&lt;br /&gt;Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bit Production&lt;br /&gt;With the Partitioning, Real Application Clusters, OLAP, Data Mining&lt;br /&gt;and Real Application Testing options&lt;br /&gt;&lt;br /&gt;SQL&gt; &lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Return to the first session on node1 and try to kill the session of dbuser02 which is on node2.&lt;br /&gt;Query the session info of dbuser02&lt;br /&gt;&lt;pre class='brush: sql'&gt;SQL&gt; SELECT t1.sid, t1.serial#, t1.inst_id&lt;br /&gt;2    FROM gv$session t1&lt;br /&gt;3   WHERE t1.username = 'DBUSER02';&lt;br /&gt;&lt;br /&gt;SID    SERIAL#    INST_ID&lt;br /&gt;---------- ---------- ----------&lt;br /&gt;260      28071          2&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;If we are on the same node as the session that we want to kill, we would use command below, but since the session to be killed is on another node you can not use the below command&lt;br /&gt;&lt;pre class='brush: sql'&gt;SQL&gt; alter system kill session '260, 28071';&lt;br /&gt;alter system kill session '260, 28071'&lt;br /&gt;*&lt;br /&gt;ERROR at line 1:&lt;br /&gt;ORA-00030: User session ID does not exist.&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;If the database version would have been 11g then you can could use the below command, but in 10g not&lt;br /&gt;&lt;pre class='brush: sql'&gt;SQL&gt; alter system kill session '260, 28071, @2';&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;So in that case we can use the package procedure which uses database job method and kills a specific session or all of the sessions of a specific user, no mather which node they are connected&lt;br /&gt;&lt;br /&gt;To kill only one specific session&lt;br /&gt;&lt;pre class='brush: sql'&gt;SQL&gt; set serveroutput on size 1000000&lt;br /&gt;SQL&gt; exec dbuser01.DBA_OPERATION.Kill_Session_Job(p_sid =&gt; 260, p_serial =&gt; 28071, p_inst_id =&gt; 2);&lt;br /&gt;begin dbuser01.DBA_OPERATION.Kill_Session(p_sid =&gt; 260, p_serial =&gt; 28071); end;&lt;br /&gt;&lt;br /&gt;PL/SQL procedure successfully completed.&lt;br /&gt;&lt;br /&gt;SQL&gt; SELECT t1.sid, t1.serial#, t1.inst_id&lt;br /&gt;2    FROM gv$session t1&lt;br /&gt;3   WHERE t1.sid = 260&lt;br /&gt;4     AND t1.serial# = 28071&lt;br /&gt;5     AND t1.inst_id = 2;&lt;br /&gt;&lt;br /&gt;no rows selected&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;To kill all of the sessions of a specific user no mather which node they are connected&lt;br /&gt;&lt;pre class='brush: sql'&gt;SQL&gt; set serveroutput on size 1000000&lt;br /&gt;SQL&gt; exec dbuser01.DBA_OPERATION.Kill_Session_User(p_username =&gt; 'DBUSER02');&lt;br /&gt;begin dbuser01.DBA_OPERATION.Kill_Session(p_sid =&gt; 260, p_serial =&gt; 28071); end;&lt;br /&gt;===== All the database sessions of user "DBUSER02" killed successfully ! =====&lt;br /&gt;&lt;br /&gt;PL/SQL procedure successfully completed.&lt;br /&gt;&lt;br /&gt;SQL&gt; SELECT t1.sid, t1.serial#, t1.inst_id&lt;br /&gt;2    FROM gv$session t1&lt;br /&gt;3   WHERE t1.username = 'DBUSER02';&lt;br /&gt;&lt;br /&gt;no rows selected&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Regards,&lt;br /&gt;Ural&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6717103620143238053-7670319688062975703?l=uralural.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://uralural.blogspot.com/feeds/7670319688062975703/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6717103620143238053&amp;postID=7670319688062975703' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6717103620143238053/posts/default/7670319688062975703'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6717103620143238053/posts/default/7670319688062975703'/><link rel='alternate' type='text/html' href='http://uralural.blogspot.com/2010/02/how-to-kill-session-which-is-connected_2341.html' title='How to kill a session which is connected to another RAC node in an Oracle 10g RAC database'/><author><name>Ural Ural</name><uri>http://www.blogger.com/profile/06556787053001681445</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='19' height='32' src='http://2.bp.blogspot.com/-FS7mo23hHG0/TjlVoo70i9I/AAAAAAAABwQ/mlpdh17_nwM/s220/IMAG0008.jpg'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6717103620143238053.post-4417585224009611620</id><published>2010-02-11T12:26:00.001-08:00</published><updated>2011-06-20T12:22:42.493-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='processes'/><category scheme='http://www.blogger.com/atom/ns#' term='lun'/><category scheme='http://www.blogger.com/atom/ns#' term='disk'/><category scheme='http://www.blogger.com/atom/ns#' term='asm'/><category scheme='http://www.blogger.com/atom/ns#' term='unix'/><category scheme='http://www.blogger.com/atom/ns#' term='background'/><category scheme='http://www.blogger.com/atom/ns#' term='fuser'/><category scheme='http://www.blogger.com/atom/ns#' term='oracle'/><title type='text'>Oracle background processes still use and lock the dropped ASM disks and these disks can not be removed and assigned to another server without restart</title><content type='html'>Oracle background processes still use and lock the dropped ASM disks and these disks can not be removed and assigned to another server without restarting the databases which are locking this ASM disks.&lt;br /&gt;&lt;br /&gt;Hi All,&lt;br /&gt;&lt;br /&gt;Today, our Unix Admins group wanted to take back a storage LUN (/dev/hdisk19) which had been given temporarly to be used for a project and assigned to the the ASM of one of our Oracle databases.&lt;br /&gt;&lt;br /&gt;We use Oracle Database Enterprise Edition and ASM version 10.2.0.4.&lt;br /&gt;&lt;br /&gt;As a normal procedure I dropped the ASM disk which is corresponding to this LUN.&lt;br /&gt;First I connected to the ASM instance and checked the ASM disk name of the related ASM device.&lt;br /&gt;&lt;br /&gt;&lt;pre class='brush: sql'&gt;SQL&gt; select name, substr(path, 1, 20) from v$asm_disk order by name;&lt;br /&gt;&lt;br /&gt;NAME                           SUBSTR(PATH,1,20)&lt;br /&gt;------------------------------ --------------------&lt;br /&gt;DG_DB_ASM_DB01_0000            /dev/ASM_Disk1&lt;br /&gt;DG_DB_ASM_DB01_0001            /dev/ASM_Disk2&lt;br /&gt;DG_DB_ASM_DB01_0002            /dev/ASM_Disk3&lt;br /&gt;DG_DB_ASM_DB01_0003            /dev/ASM_Disk4&lt;br /&gt;DG_DB_ASM_DB01_0004            /dev/ASM_Disk5&lt;br /&gt;&lt;br /&gt;NAME                           SUBSTR(PATH,1,20)&lt;br /&gt;------------------------------ --------------------&lt;br /&gt;DG_DB_ASM_DB01_0005            /dev/ASM_Disk6&lt;br /&gt;DG_DB_ASM_DB01_0006            /dev/ASM_Disk13&lt;br /&gt;DG_DB_ASM_DB01_0007            /dev/ASM_Disk14&lt;br /&gt;DG_DB_ASM_DB01_0008            /dev/ASM_Disk15&lt;br /&gt;DG_DB_ASM_DB01_0009            /dev/ASM_Disk17&lt;br /&gt;&lt;br /&gt;10 rows selected.    &lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;I used the following command to drop the ASM disk.&lt;br /&gt;&lt;pre class='brush: sql'&gt;ALTER DISKGROUP DG_DB_ASM_DB01 DROP DISK DG_DB_ASM_DB01_0009;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;After this command completes, Unix Admin group tried to remove the hdisk (/dev/hdisk19) corresponding to this device and they said that there were some processes in the Unix server (IBM AIX) which were using this hdisk and because of that they can not remove it.&lt;br /&gt;&lt;br /&gt;I checked again to find out which processes use this ASM disk corresponding this ASM device.&lt;br /&gt;&lt;pre class='brush: bash'&gt;[osuser01@os01]:/oracle &gt; fuser /dev/ASM_Disk17&lt;br /&gt;/dev/ASM_Disk17:   200796  430276  675882  712952  745630  749608  757766  782390  892942 1220622 1515754 1613864 1765430 1921252 1945674&lt;br /&gt;[osuser01@os01]:/oracle &gt; ps -ef|grep  200796&lt;br /&gt;oracle  200796       1   0 16:52:57      -  0:00 oracle+ASM (LOCAL=NO)&lt;br /&gt;oracle 1146924 1589428   0 17:56:00  pts/2  0:00 grep 200796&lt;br /&gt;[osuser01@os01]:/oracle &gt; ps -ef|grep  430276&lt;br /&gt;oracle  430276       1   0   Oct 06      - 20:01 asm_gmon_+ASM&lt;br /&gt;oracle 1589430 1146926   0 17:56:05  pts/2  0:00 grep 430276&lt;br /&gt;[osuser01@os01]:/oracle &gt; ps -ef|grep  675882&lt;br /&gt;oracle  675882       1   0   Oct 06      - 26:20 ora_cjq0_DB01&lt;br /&gt;oracle 1400942 1065140   0 17:56:09  pts/2  0:00 grep 675882&lt;br /&gt;[osuser01@os01]:/oracle &gt; ps -ef|grep  712952&lt;br /&gt;oracle  712952       1   0   Oct 06      - 10:15 ora_smon_DB01&lt;br /&gt;oracle 1065142 1400944   0 17:56:14  pts/2  0:00 grep 712952&lt;br /&gt;[osuser01@os01]:/oracle &gt; ps -ef|grep  745630&lt;br /&gt;oracle  745630       1   0   Oct 06      - 207:01 ora_ckpt_DB01&lt;br /&gt;oracle 1380554 1400950   0 17:56:19  pts/2  0:00 grep 745630&lt;br /&gt;[osuser01@os01]:/oracle &gt; ps -ef|grep  749608&lt;br /&gt;oracle  749608       1   0   Oct 06      - 58:08 ora_lgwr_DB01&lt;br /&gt;oracle 1065156 1380564   0 17:56:25  pts/2  0:00 grep 749608&lt;br /&gt;[osuser01@os01]:/oracle &gt; ps -ef|grep  757766&lt;br /&gt;oracle  757766       1   0 09:27:29      -  0:11 ora_j000_DB01&lt;br /&gt;oracle 1876066 1589452   0 17:56:31  pts/2  0:00 grep 757766&lt;br /&gt;[osuser01@os01]:/oracle &gt; ps -ef|grep  782390&lt;br /&gt;oracle  782390       1   0   Oct 06      - 3793:04 ora_dbw0_DB01&lt;br /&gt;oracle 1589454 1876068   0 17:56:42  pts/2  0:00 grep 782390&lt;br /&gt;[osuser01@os01]:/oracle &gt; ps -ef|grep  892942&lt;br /&gt;oracle  892942       1   0   Oct 06      -  1:59 ora_rbal_DB01&lt;br /&gt;oracle 1589456 1065172   0 17:56:48  pts/2  0:00 grep 892942&lt;br /&gt;[osuser01@os01]:/oracle &gt; ps -ef|grep  1220622&lt;br /&gt;oracle 1065174 1589460   0 17:56:54  pts/2  0:00 grep 1220622&lt;br /&gt;oracle 1220622       1   0   Oct 06      - 15:45 ora_mmon_DB01&lt;br /&gt;[osuser01@os01]:/oracle &gt; ps -ef|grep  1515754&lt;br /&gt;oracle 1400968 1876080   0 17:57:02  pts/2  0:00 grep 1515754&lt;br /&gt;oracle 1515754       1   0   Oct 06      -  2:55 asm_rbal_+ASM&lt;br /&gt;[osuser01@os01]:/oracle &gt; ps -ef|grep  1613864&lt;br /&gt;oracle 1065184 1876088   0 17:57:13  pts/2  0:00 grep 1613864&lt;br /&gt;oracle 1613864       1   0   Oct 06      -  4:20 asm_lgwr_+ASM&lt;br /&gt;[osuser01@os01]:/oracle &gt; ps -ef|grep  1765430&lt;br /&gt;oracle 1765430       1   0   Oct 06      -  3:19 asm_dbw0_+ASM&lt;br /&gt;oracle 1876090 1065186   0 17:57:18  pts/2  0:00 grep 1765430&lt;br /&gt;[osuser01@os01]:/oracle &gt; ps -ef|grep  1921252&lt;br /&gt;oracle 1065188 1876092   0 17:57:25  pts/2  0:00 grep 1921252&lt;br /&gt;oracle 1921252       1   0 15:34:14      -  0:00 oracle+ASM (LOCAL=NO)&lt;br /&gt;[osuser01@os01]:/oracle &gt; ps -ef|grep  1945674&lt;br /&gt;oracle 1065192 1876098   0 17:57:30  pts/2  0:00 grep 1945674&lt;br /&gt;oracle 1945674       1   0   Oct 06      - 49:47 ora_mmnl_DB01&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;As we can see, the locking processes belong to the Oracle database and ASM instance background processes.&lt;br /&gt;&lt;br /&gt;I also checked the database side whether dropped disk is still there or not.&lt;br /&gt;&lt;br /&gt;I connected to the ASM instance and run the following query.&lt;br /&gt;&lt;br /&gt;&lt;pre class='brush: sql'&gt;SQL&gt; select name, substr(path, 1, 20) from v$asm_disk order by name;&lt;br /&gt;&lt;br /&gt;NAME                           SUBSTR(PATH,1,20)&lt;br /&gt;------------------------------ --------------------&lt;br /&gt;DG_DB_ASM_DB01_0000            /dev/ASM_Disk1&lt;br /&gt;DG_DB_ASM_DB01_0001            /dev/ASM_Disk2&lt;br /&gt;DG_DB_ASM_DB01_0002            /dev/ASM_Disk3&lt;br /&gt;DG_DB_ASM_DB01_0003            /dev/ASM_Disk4&lt;br /&gt;DG_DB_ASM_DB01_0004            /dev/ASM_Disk5&lt;br /&gt;&lt;br /&gt;NAME                           SUBSTR(PATH,1,20)&lt;br /&gt;------------------------------ --------------------&lt;br /&gt;DG_DB_ASM_DB01_0005            /dev/ASM_Disk6&lt;br /&gt;DG_DB_ASM_DB01_0006            /dev/ASM_Disk13&lt;br /&gt;DG_DB_ASM_DB01_0007            /dev/ASM_Disk14&lt;br /&gt;DG_DB_ASM_DB01_0008            /dev/ASM_Disk15&lt;br /&gt;/dev/ASM_Disk17&lt;br /&gt;&lt;br /&gt;10 rows selected.    &lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;ASM device name still appears there but without any ASM disk name, this looks a bit strange because we successfully dropped this ASM disk and there are still Oracle background processes which does not release this ASM device.&lt;br /&gt;&lt;br /&gt;After searching a bit about this problem, I found a Metalink note in Oracle Metalink website explaining that this problem occurs because of an Oracle bug which will be solved in Oracle version 10.2.0.5 (we use Oracle version 10.2.0.4). (Oracle Metalink note : Asm Devices Are Still Held Open After Dismount or Drop [ID 402526.1])&lt;br /&gt;&lt;br /&gt;As a quick solution, since this database is not a production database, I restarted ASM and Oracle database instance to get rid of these background processes locking the ASM device and problem was solved.&lt;br /&gt;&lt;br /&gt;Regards,&lt;br /&gt;Ural&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6717103620143238053-4417585224009611620?l=uralural.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://uralural.blogspot.com/feeds/4417585224009611620/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6717103620143238053&amp;postID=4417585224009611620' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6717103620143238053/posts/default/4417585224009611620'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6717103620143238053/posts/default/4417585224009611620'/><link rel='alternate' type='text/html' href='http://uralural.blogspot.com/2010/02/oracle-background-processes-still-use.html' title='Oracle background processes still use and lock the dropped ASM disks and these disks can not be removed and assigned to another server without restart'/><author><name>Ural Ural</name><uri>http://www.blogger.com/profile/06556787053001681445</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='19' height='32' src='http://2.bp.blogspot.com/-FS7mo23hHG0/TjlVoo70i9I/AAAAAAAABwQ/mlpdh17_nwM/s220/IMAG0008.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6717103620143238053.post-1155133332941953773</id><published>2010-02-06T03:10:00.000-08:00</published><updated>2011-06-20T12:24:21.682-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='environment variables'/><category scheme='http://www.blogger.com/atom/ns#' term='unix'/><category scheme='http://www.blogger.com/atom/ns#' term='shell script'/><category scheme='http://www.blogger.com/atom/ns#' term='oracle'/><category scheme='http://www.blogger.com/atom/ns#' term='crontab'/><title type='text'>How to add an Oracle related script to Unix crontab</title><content type='html'>Dear All,&lt;br /&gt;&lt;br /&gt;After a long period of time not publishing any blog posts, I'm back again to share my Oracle knowledge with you and get your reviews and feedbacks about the published subjects.&lt;br /&gt;&lt;br /&gt;I want to share a point with you, which most of you would already have been aware of it.&lt;br /&gt;&lt;br /&gt;When you want to prepare an Oracle related script which will connect to an Oracle database and do some work and schedule it in Unix crontab (in my case IBM AIX), you should pay attention to set the environment variables related to database which will be connected to and running on the same server.&lt;br /&gt;&lt;br /&gt;These environment settings are normally set in the profile of the Unix user, running the script in Unix, most of the time this Unix user is also the owner of the database running on this server.&lt;br /&gt;&lt;br /&gt;In case of scheduling a shell script in crontab, the scheduled script does not have any profile setting automatically and you should prepare a separate script including these Oracle related environment settings or you can directly embed these setting to your database related Unix shell script.&lt;br /&gt;&lt;br /&gt;Below are the examples of these kinds of Unix shell scripts.&lt;br /&gt;&lt;br /&gt;Regards,&lt;br /&gt;Ural&lt;br /&gt;&lt;br /&gt;&lt;pre class='brush: bash'&gt;[user01@server01]:/oracle &gt; crontab -l&lt;br /&gt;00 00 * * * /oracle/scripts/script.sh &gt; /oracle/scripts/script.log 2&gt;&amp;amp;1&lt;br /&gt;&lt;br /&gt;[user01@server01]:/oracle &gt; more /oracle/scripts/script.sh&lt;br /&gt;. /oracle/scripts/set_env.sh&lt;br /&gt;/oracle/scripts/script_02.sh&lt;br /&gt;&lt;br /&gt;[user01@server01]:/oracle &gt; more /oracle/scripts/set_env.sh&lt;br /&gt;export ORACLE_BASE=/oracle&lt;br /&gt;export ORACLE_HOME=$ORACLE_BASE/orahome1&lt;br /&gt;export LD_LIBRARY_PATH=$ORACLE_HOME/lib:$ORACLE_HOME/lib32&lt;br /&gt;export LIBPATH=$LD_LIBRARY_PATH&lt;br /&gt;export PATH=$ORACLE_HOME/bin:$PATH&lt;br /&gt;export NLS_LANG=AMERICAN_AMERICA.WE8ISO8859P9&lt;br /&gt;cd /oracle/scripts&lt;br /&gt;&lt;br /&gt;[user01@server01]:/oracle &gt; more /oracle/scripts/script_02.sh&lt;br /&gt;d_date=`date +"%Y%m%d%H%M"`&lt;br /&gt;expdp parfile=script_02.par dumpfile=script_02_${d_date}.dmp logfile=script_02_${d_date}.log&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6717103620143238053-1155133332941953773?l=uralural.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://uralural.blogspot.com/feeds/1155133332941953773/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6717103620143238053&amp;postID=1155133332941953773' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6717103620143238053/posts/default/1155133332941953773'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6717103620143238053/posts/default/1155133332941953773'/><link rel='alternate' type='text/html' href='http://uralural.blogspot.com/2010/02/how-to-add-oracle-related-script-to.html' title='How to add an Oracle related script to Unix crontab'/><author><name>Ural Ural</name><uri>http://www.blogger.com/profile/06556787053001681445</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='19' height='32' src='http://2.bp.blogspot.com/-FS7mo23hHG0/TjlVoo70i9I/AAAAAAAABwQ/mlpdh17_nwM/s220/IMAG0008.jpg'/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6717103620143238053.post-8628492251182666452</id><published>2007-10-03T10:30:00.000-07:00</published><updated>2011-06-20T12:28:04.780-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='expdp'/><category scheme='http://www.blogger.com/atom/ns#' term='impdp'/><category scheme='http://www.blogger.com/atom/ns#' term='tablespace'/><title type='text'>Oracle database keeps the old dropped tablespace info in database registry for a partitoned table</title><content type='html'>Hi,&lt;br /&gt;&lt;br /&gt;We have just upgraded our Oracle production database from 9i(9.2.0.4) to 10g(10.2.0.3). &lt;br /&gt;I will prepare and publish a blog post about this subject in the following days. &lt;br /&gt;While I struggle with the CBO subjects that are changed in 10g. I realised &lt;br /&gt;something that I was aware of before but I am very shocked that it is not corrected in 10g. &lt;br /&gt;&lt;br /&gt;The case is related to a partitioned table which is originally created together with its partitions in &lt;br /&gt;"tablespace_1" but for some time later, as a reorganization need, its partitions are moved online to &lt;br /&gt;"tablespace_2" and old "tablespace_1" is dropped from the database.&lt;br /&gt;&lt;br /&gt;I know from my earlier experiences that in 9i, in a case like above, Oracle 9i keeps the old dropped &lt;br /&gt;tablespace "tablespace_1" info in database registry as a part of the partitioned table's description.&lt;br /&gt;&lt;br /&gt;Lets give an example...&lt;br /&gt;&lt;br /&gt;&lt;pre class='brush: sql'&gt;conn dbuser01@prod10g&lt;br /&gt;&lt;br /&gt;select username, default_tablespace from dba_users where username = 'DBUSER01';&lt;br /&gt;/*&lt;br /&gt;username|default_tablespace&lt;br /&gt;DBUSER01|USER_DATA&lt;br /&gt;*/&lt;br /&gt;&lt;br /&gt;CREATE TABLESPACE USER_DATA_TEST DATAFILE &lt;br /&gt;'/data2/oracle3/oradata/oradb3/user_data_test.dbf' SIZE 10M AUTOEXTEND ON NEXT 10M MAXSIZE 100M&lt;br /&gt;LOGGING&lt;br /&gt;ONLINE&lt;br /&gt;PERMANENT&lt;br /&gt;EXTENT MANAGEMENT LOCAL AUTOALLOCATE&lt;br /&gt;BLOCKSIZE 8K&lt;br /&gt;SEGMENT SPACE MANAGEMENT AUTO&lt;br /&gt;FLASHBACK ON;&lt;br /&gt;&lt;br /&gt;ALTER USER DBUSER01 DEFAULT TABLESPACE "USER_DATA_TEST";&lt;br /&gt;&lt;br /&gt;select username, default_tablespace from dba_users where username = 'DBUSER01';&lt;br /&gt;/*&lt;br /&gt;username|default_tablespace&lt;br /&gt;DBUSER01|USER_DATA_TEST&lt;br /&gt;*/&lt;br /&gt;&lt;br /&gt;--DROP TABLE DBUSER01.EGTEST1;&lt;br /&gt;&lt;br /&gt;CREATE TABLE DBUSER01.EGTEST1&lt;br /&gt;(&lt;br /&gt;COL1           CHAR(21 BYTE),&lt;br /&gt;COL2           CHAR(1 BYTE),&lt;br /&gt;COL3           DATE&lt;br /&gt;)&lt;br /&gt;PARTITION BY RANGE (COL3) &lt;br /&gt;(  &lt;br /&gt;PARTITION P1 VALUES LESS THAN (TO_DATE(' 2003-12-31 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN'))&lt;br /&gt;TABLESPACE TB_DATA&lt;br /&gt;,  &lt;br /&gt;PARTITION P2 VALUES LESS THAN (MAXVALUE)&lt;br /&gt;TABLESPACE TB_DATA&lt;br /&gt;);&lt;br /&gt;&lt;br /&gt;ALTER USER DBUSER01 DEFAULT TABLESPACE "USER_DATA";&lt;br /&gt;&lt;br /&gt;select username, default_tablespace from dba_users where username = 'DBUSER01';&lt;br /&gt;/*&lt;br /&gt;username|default_tablespace&lt;br /&gt;DBUSER01|USER_DATA&lt;br /&gt;*/&lt;br /&gt;&lt;br /&gt;drop tablespace USER_DATA_TEST INCLUDING CONTENTS AND DATAFILES; &lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;try to export this table &lt;br /&gt;&lt;pre class='brush: bash'&gt;user01@test3:/data1/oracle3&gt;exp dbuser01 file=egtest1 log=egtest1 tables=egtest1 rows=n&lt;br /&gt;&lt;br /&gt;Export: Release 10.2.0.3.0 - Production on Thu Sep 27 11:21:45 2007&lt;br /&gt;&lt;br /&gt;Copyright (c) 1982, 2005, Oracle.  All rights reserved.&lt;br /&gt;&lt;br /&gt;Password:&lt;br /&gt;&lt;br /&gt;Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - 64bit Production&lt;br /&gt;With the Partitioning, OLAP and Data Mining options&lt;br /&gt;Export done in WE8ISO8859P9 character set and AL16UTF16 NCHAR character set&lt;br /&gt;Note: table data (rows) will not be exported&lt;br /&gt;&lt;br /&gt;About to export specified tables via Conventional Path ...&lt;br /&gt;. . exporting table                 EGTEST1&lt;br /&gt;Export terminated successfully without warnings.&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;pre class='brush: sql'&gt;DROP TABLE DBUSER01.EGTEST1;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;try to import this table&lt;br /&gt;&lt;pre class='brush: bash'&gt;user01@test3:/data1/oracle3&gt;imp dbuser01 file=egtest1 log=egtest1_imp fromuser=dbuser01 touser=dbuser01&lt;br /&gt;&lt;br /&gt;Import: Release 10.2.0.3.0 - Production on Thu Sep 27 11:24:17 2007&lt;br /&gt;&lt;br /&gt;Copyright (c) 1982, 2005, Oracle.  All rights reserved.&lt;br /&gt;&lt;br /&gt;Password:&lt;br /&gt;&lt;br /&gt;Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - 64bit Production&lt;br /&gt;With the Partitioning, OLAP and Data Mining options&lt;br /&gt;&lt;br /&gt;Export file created by EXPORT:V10.02.01 via conventional path&lt;br /&gt;import done in WE8ISO8859P9 character set and AL16UTF16 NCHAR character set&lt;br /&gt;. importing DBUSER01's objects into DBUSER01&lt;br /&gt;IMP-00017: following statement failed with ORACLE error 959:&lt;br /&gt;"CREATE TABLE "EGTEST1" ("COL1" CHAR(21), "COL2" CHAR(1), "COL3" DATE)"  &lt;br /&gt;PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 TABLESPACE "USER_DATA_TEST" LOGGING P"&lt;br /&gt;"ARTITION BY RANGE ("COL3" )  (PARTITION "P1" VALUES LESS THAN (TO_DATE('"&lt;br /&gt;" 2003-12-31 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN'))"&lt;br /&gt;"  PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 STORAGE(INITIAL 65536 FREEL"&lt;br /&gt;"ISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT) TABLESPACE "TB_DATA" LOGGING "&lt;br /&gt;"NOCOMPRESS, PARTITION "P2" VALUES LESS THAN (MAXVALUE)  PCTFREE 10 PCTUSED "&lt;br /&gt;"40 INITRANS 1 MAXTRANS 255 STORAGE(INITIAL 65536 FREELISTS 1 FREELIST GROUP"&lt;br /&gt;"S 1 BUFFER_POOL DEFAULT) TABLESPACE "TB_DATA" LOGGING NOCOMPRESS )"&lt;br /&gt;IMP-00003: ORACLE error 959 encountered&lt;br /&gt;ORA-00959: tablespace 'USER_DATA_TEST' does not exist&lt;br /&gt;Import terminated successfully with warnings.&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;import can not find the already dropped tablespace and can not import the table&lt;br /&gt;&lt;br /&gt;---------------------------&lt;br /&gt;testing the normal behaviour with a non-partitioned table.&lt;br /&gt;&lt;br /&gt;&lt;pre class='brush: sql'&gt;CREATE TABLESPACE USER_DATA_TEST DATAFILE &lt;br /&gt;'/data2/oracle3/oradata/oradb3/user_data_test.dbf' SIZE 10M AUTOEXTEND ON NEXT 10M MAXSIZE 100M&lt;br /&gt;LOGGING&lt;br /&gt;ONLINE&lt;br /&gt;PERMANENT&lt;br /&gt;EXTENT MANAGEMENT LOCAL AUTOALLOCATE&lt;br /&gt;BLOCKSIZE 8K&lt;br /&gt;SEGMENT SPACE MANAGEMENT AUTO&lt;br /&gt;FLASHBACK ON;&lt;br /&gt;&lt;br /&gt;create table test_tbl (col1 number) tablespace USER_DATA_TEST;&lt;br /&gt;insert into test_tbl values (1);&lt;br /&gt;commit;&lt;br /&gt;&lt;br /&gt;select table_name,tablespace_name from user_tables where table_name = 'TEST_TBL';&lt;br /&gt;/*&lt;br /&gt;table_name|tablespace_name&lt;br /&gt;TEST_TBL|USER_DATA_TEST&lt;br /&gt;*/&lt;br /&gt;drop tablespace USER_DATA_TEST INCLUDING CONTENTS AND DATAFILES; &lt;br /&gt;select table_name,tablespace_name from user_tables where table_name = 'TEST_TBL';&lt;br /&gt;--No rows returned.&lt;br /&gt;&lt;/pre&gt;---------------------------&lt;br /&gt;&lt;br /&gt;In normal database behaviour when we drop the tablespace, the tables, that resides in the dropped tablespace, &lt;br /&gt;dropped also. Why the database behaves differently in case of parititioned tables ?&lt;br /&gt;&lt;br /&gt;You can see this oddity when you try to extract the DDL script of such a parititoned table with any database tool,&lt;br /&gt;because the Oracle database continues to keep this already dropped tablespace info in the database registry.&lt;br /&gt;&lt;br /&gt;Oracle Advanced Resolution Team of Oracle Worldwide Support considered the issue not as a bug and &lt;br /&gt;they accept it only as an enhancement request which is done in expdp/impdp (Oracle Data Pump Export/Import)&lt;br /&gt;on 10G. When you try to import (impdp) a partitioned table like in the above case, which is exported with expdp,&lt;br /&gt;you can use "remap_tablespace=user_data_test:an_existing_tblspace" parameter to change the old dropped &lt;br /&gt;tablespace name to a tablespace that exists in the database.&lt;br /&gt;&lt;br /&gt;So, in our case, since the related partitioned tables are very big and the database operates in archivelog mode&lt;br /&gt;we do not want to export them with expdp and import them again into database with impdp by using the &lt;br /&gt;"remap_tablespace" parameter. Nevermind our case, but the strange thing is that , Oracle still have this&lt;br /&gt;oddity even in 10g database. I mean if you do not export and then import them, then you have to live with it.&lt;br /&gt;Any tool (including expdp) extracts the DDL of such a partitioned table with wrong old tablespace,&lt;br /&gt;then you will have to manually edit this generated script (except impdp) to change this non-existing &lt;br /&gt;tablespace from the DDL script.&lt;br /&gt;&lt;br /&gt;One more point, since the impdb can import only the export dump files that are taken with expdp, if you &lt;br /&gt;just upgraded your database from 9i to 10g, I thing you should convert your export scripts to use the expdp, &lt;br /&gt;if any. Otherwise, if, from time-to-time, you are importing some tables into any of your test databases, &lt;br /&gt;there will be some manual extra works waiting for you, like for these partitioned tables containing old dropped&lt;br /&gt;tablespace info you will have to extract the script from export file, change the tablespace part to point to an&lt;br /&gt;existing tablespace,pre-create the tables and then import them.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Regards&lt;br /&gt;Ural Ural&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6717103620143238053-8628492251182666452?l=uralural.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://uralural.blogspot.com/feeds/8628492251182666452/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6717103620143238053&amp;postID=8628492251182666452' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6717103620143238053/posts/default/8628492251182666452'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6717103620143238053/posts/default/8628492251182666452'/><link rel='alternate' type='text/html' href='http://uralural.blogspot.com/2007/10/oracle-database-keeps-old-dropped.html' title='Oracle database keeps the old dropped tablespace info in database registry for a partitoned table'/><author><name>Ural Ural</name><uri>http://www.blogger.com/profile/06556787053001681445</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='19' height='32' src='http://2.bp.blogspot.com/-FS7mo23hHG0/TjlVoo70i9I/AAAAAAAABwQ/mlpdh17_nwM/s220/IMAG0008.jpg'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6717103620143238053.post-7076765831471309359</id><published>2007-07-12T10:19:00.000-07:00</published><updated>2011-06-20T12:37:10.471-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='statistics'/><category scheme='http://www.blogger.com/atom/ns#' term='dbms_stats'/><category scheme='http://www.blogger.com/atom/ns#' term='cost based optimizer'/><category scheme='http://www.blogger.com/atom/ns#' term='index'/><category scheme='http://www.blogger.com/atom/ns#' term='CBO'/><title type='text'>Oracle CBO chooses the wrong index although the statistics are collected on the related table</title><content type='html'>Hi,&lt;br /&gt;&lt;br /&gt;Our system analysis and support team called us, the Oracle DBA team, for a problem. The problem was a report program was running &lt;br /&gt;OK before but it runs very slowly now, but they said that nothing has changed about the program except the data that it selects. &lt;br /&gt;So we examined the situation and these are the things we did.&lt;br /&gt;&lt;br /&gt;We traced the situation and found the guilty SQL. It is a simple one as it looks. The table TABLE01 has about 65 million rows.&lt;br /&gt;&lt;br /&gt;&lt;pre class='brush: sql'&gt;SELECT SUM (DECODE (b1, 'A', tut1, 0)), SUM (DECODE (b1, 'B', tut1, 0))&lt;br /&gt;FROM table01 t1&lt;br /&gt;WHERE tar1 = to_date('29.06.2007','dd.mm.yyyy')&lt;br /&gt;AND skod1 = NVL(NULL, skod1)&lt;br /&gt;AND htno1 = '22001901'&lt;br /&gt;AND 9000 + dkod1 = 9001&lt;br /&gt;AND NVL (dtkod1, '*') = NVL (NULL, '*')&lt;br /&gt;AND eno1 &lt; 9000;&lt;br /&gt;&lt;/pre&gt;We looked at the explain plan of that SQL statement,&lt;pre class='brush: sql'&gt;Plan&lt;br /&gt;SELECT STATEMENT  CHOOSECost: 350  Bytes: 36  Cardinality: 1     &lt;br /&gt;3 SORT AGGREGATE  Bytes: 36  Cardinality: 1    &lt;br /&gt;2 TABLE ACCESS BY INDEX ROWID DBUSER01.TABLE01 Cost: 350  Bytes: 36  Cardinality: 1   &lt;br /&gt;1 INDEX RANGE SCAN NON-UNIQUE DBUSER01.TABLE01_2X Cost: 347  Cardinality: 9  &lt;br /&gt;&lt;/pre&gt;When we run this query like that, although this SQL statement should not return any rows, we waited for 1 hour but it did not finish, so we killed the session because this is too much time for a report and apperantly there was a problem.Then we looked at the indexes of this table and there was another candidate index for this index and we tried the SQLby giving a hint for this second index.&lt;pre class='brush: sql'&gt;SELECT /*+ index(t1 TABLE01_4X)*/&lt;br /&gt;SUM (DECODE (b1, 'A', tut1, 0)), SUM (DECODE (b1, 'B', tut1, 0))&lt;br /&gt;FROM table01 t1&lt;br /&gt;WHERE tar1 = to_date('29.06.2007','dd.mm.yyyy')&lt;br /&gt;AND skod1 = NVL(NULL, skod1)&lt;br /&gt;AND htno1 = '22001901'&lt;br /&gt;AND 9000 + dkod1 = 9001&lt;br /&gt;AND NVL (dtkod1, '*') = NVL (NULL, '*')&lt;br /&gt;AND eno1 &lt; 9000;&lt;br /&gt;&lt;/pre&gt;OOOPPPS !!!, it just finished in 15 miliseconds. So we looked at the explain plan of this SQL statement.&lt;pre class='brush: sql'&gt;Plan&lt;br /&gt;SELECT STATEMENT  CHOOSECost: 542  Bytes: 36  Cardinality: 1     &lt;br /&gt;3 SORT AGGREGATE  Bytes: 36  Cardinality: 1    &lt;br /&gt;2 TABLE ACCESS BY INDEX ROWID DBUSER01.TABLE01 Cost: 542  Bytes: 36  Cardinality: 1   &lt;br /&gt;1 INDEX RANGE SCAN NON-UNIQUE DBUSER01.TABLE01_4X Cost: 501  Cardinality: 1,452  &lt;br /&gt;&lt;/pre&gt;Although the cost of the second query (hinted) is higher than than the first one, the second SQL runs much faster.So how can this be, is the Oracle CBO missing something in calculating the cost ? We will see...Lets look at the structures of related indexes.&lt;pre class='brush: sql'&gt;CREATE INDEX TABLE01_2X ON TABLE01&lt;br /&gt;(htno1, dkod1, skod1);&lt;br /&gt;&lt;br /&gt;CREATE INDEX TABLE01_4X ON TABLE01&lt;br /&gt;(TAR1, skod1);&lt;br /&gt;&lt;/pre&gt;We collect statistics for the tables in our Oracle database, the Oracle CBO (Cost Base Optimizer) calculates the cost of a SQL statement false and chooses the wrong index, I mean the one that is less efficient. As a result of this behaviour these SQL statements does not finish in a resonable time, causing loss of business.How we collect the statistics is like that, we collect statistics for tables by using the following command :&lt;pre class='brush: sql'&gt;exec dbms_stats.gather_table_stats(ownname =&gt; 'DBUSER01', tabname =&gt; 'TABLE01', estimate_percent =&gt; 33, cascade =&gt; TRUE);&lt;br /&gt;&lt;/pre&gt;After collecting the statistics we will examine how the CBO calculates the cost.According to Jonathan Lewis, Oracle CBO calculates the cost like below :cost =blevel +ceiling(leaf_blocks * effective index selectivity) +ceiling(clustering_factor * effective table selectivity)Lets calculate the cost of the following SQL&lt;pre class='brush: sql'&gt;SELECT SUM (DECODE (b1, 'A', tut1, 0)), SUM (DECODE (b1, 'B', tut1, 0))&lt;br /&gt;FROM table01 t1&lt;br /&gt;WHERE tar1 = to_date('29.06.2007','dd.mm.yyyy')&lt;br /&gt;AND skod1 = NVL(NULL, skod1)&lt;br /&gt;AND htno1 = '22001901'&lt;br /&gt;AND 9000 + dkod1 = 9001&lt;br /&gt;AND NVL (dtkod1, '*') = NVL (NULL, '*')&lt;br /&gt;AND eno1 &lt; 9000;&lt;br /&gt;---------------------------------------------------------&lt;br /&gt;Plan&lt;br /&gt;SELECT STATEMENT  CHOOSECost: 350  Bytes: 36  Cardinality: 1     &lt;br /&gt;3 SORT AGGREGATE  Bytes: 36  Cardinality: 1    &lt;br /&gt;2 TABLE ACCESS BY INDEX ROWID DBUSER01.TABLE01 Cost: 350  Bytes: 36  Cardinality: 1   &lt;br /&gt;1 INDEX RANGE SCAN NON-UNIQUE DBUSER01.TABLE01_2X Cost: 347  Cardinality: 9   &lt;br /&gt;---------------------------------------------------------&lt;br /&gt;&lt;br /&gt;select owner, index_name, blevel, leaf_blocks, clustering_factor from dba_indexes where index_name = 'TABLE01_2X';&lt;br /&gt;---------------------------------------------------------&lt;br /&gt;OWNER|INDEX_NAME|BLEVEL|LEAF_BLOCKS|CLUSTERING_FACTOR&lt;br /&gt;DBUSER01|TABLE01_2X|3|331491|16303842&lt;br /&gt;&lt;/pre&gt;effective index selectivity = density of "HTNO1" columneffective table selectivity = (density of "DKOD1" column) * (density of "HTNO1" column) * (density of "SKOD1" column) &lt;pre class='brush: sql'&gt;select column_name, num_distinct, density, num_buckets from dba_tab_columns t1 where t1.table_name = 'TABLE01' &lt;br /&gt;and t1.column_name in ('DKOD1', 'HTNO1', 'SKOD1')&lt;br /&gt;order by t1.column_name;&lt;br /&gt;---------------------------------------------------------&lt;br /&gt;COLUMN_NAME|NUM_DISTINCT|DENSITY|NUM_BUCKETS&lt;br /&gt;DKOD1|12|0.0833333333333333|1&lt;br /&gt;HTNO1|965|0.00103626943005181|1&lt;br /&gt;SKOD1|73|0.0136986301369863|1&lt;br /&gt;&lt;/pre&gt;Since the "   AND 9000 + dkod1 = 9001" condition equals "function(col) = constant" is has the static selectivity of %1 (0.001)instead of 0.0833333333333333.cost =blevel +ceiling(leaf_blocks * effective index selectivity) +ceiling(clustering_factor * effective table selectivity)cost =3 +ceiling(331491 * 0.00103626943005181) +ceiling(16303842 * (0.01 * 0.00103626943005181 * 0.0136986301369863))= 350-----------------------Lets calculate the cost of the following SQL&lt;pre class='brush: sql'&gt;SELECT /*+ index(t1 TABLE01_4X)*/&lt;br /&gt;SUM (DECODE (b1, 'A', tut1, 0)), SUM (DECODE (b1, 'B', tut1, 0))&lt;br /&gt;FROM table01 t1&lt;br /&gt;WHERE tar1 = to_date('29.06.2007','dd.mm.yyyy')&lt;br /&gt;AND skod1 = NVL(NULL, skod1)&lt;br /&gt;AND htno1 = '22001901'&lt;br /&gt;AND 9000 + dkod1 = 9001&lt;br /&gt;AND NVL (dtkod1, '*') = NVL (NULL, '*')&lt;br /&gt;AND eno1 &lt; 9000;&lt;br /&gt;---------------------------------------------------------&lt;br /&gt;Plan&lt;br /&gt;SELECT STATEMENT  CHOOSECost: 542  Bytes: 36  Cardinality: 1     &lt;br /&gt;3 SORT AGGREGATE  Bytes: 36  Cardinality: 1    &lt;br /&gt;2 TABLE ACCESS BY INDEX ROWID DBUSER01.TABLE01 Cost: 542  Bytes: 36  Cardinality: 1   &lt;br /&gt;1 INDEX RANGE SCAN NON-UNIQUE DBUSER01.TABLE01_4X Cost: 501  Cardinality: 1,452  &lt;br /&gt;---------------------------------------------------------&lt;br /&gt;&lt;br /&gt;select owner, index_name, blevel, leaf_blocks, clustering_factor from dba_indexes where index_name = 'TABLE01_4X';&lt;br /&gt;---------------------------------------------------------&lt;br /&gt;OWNER|INDEX_NAME|BLEVEL|LEAF_BLOCKS|CLUSTERING_FACTOR&lt;br /&gt;DBUSER01|TABLE01_4X|3|302597|1791039&lt;br /&gt;&lt;/pre&gt;effective index selectivity = density of "TAR1" columneffective table selectivity = (density of "TAR1" column) * (density of "SKOD1" column) &lt;pre class='brush: sql'&gt;select column_name, num_distinct, density, num_buckets from dba_tab_columns t1 where t1.table_name = 'TABLE01' &lt;br /&gt;and t1.column_name in ('TAR1', 'SKOD1')&lt;br /&gt;order by t1.column_name;&lt;br /&gt;---------------------------------------------------------&lt;br /&gt;COLUMN_NAME|NUM_DISTINCT|DENSITY|NUM_BUCKETS&lt;br /&gt;TAR1|608|0.00164473684210526|1&lt;br /&gt;SKOD1|73|0.0136986301369863|1&lt;br /&gt;&lt;/pre&gt;cost =blevel +ceiling(leaf_blocks * effective index selectivity) +ceiling(clustering_factor * effective table selectivity)cost =3 +ceiling(302597 * 0.00164473684210526) +ceiling(1791039 * (0.00164473684210526 * 0.0136986301369863))= 542------------------------------It is obvious that CBO can not choose the optimal index for this SQL, that is "TABLE01_4X". Why ?The answer is that we did not give the CBO the enough info about the structure of the data in table and the indexes.So the solution is, we should collect more data for this table about the distribution of data in that table. What should we do ? We should collect histogram data for this table, lets see the result of collecting histograms for this table.Lets collect histograms for this table.&lt;pre class='brush: sql'&gt;exec dbms_stats.gather_table_stats('DBUSER01','TABLE01', estimate_percent=&gt;33, cascade =&gt; TRUE, method_opt =&gt; 'FOR ALL INDEXED COLUMNS SIZE 10');&lt;br /&gt;&lt;/pre&gt;Lets look at the explain plans :First select is just finished in 15 miliseconds, and the second one does not finishso the problem is solved, our SQL now finishes in 15 msecs.&lt;pre class='brush: sql'&gt;SELECT SUM (DECODE (b1, 'A', tut1, 0)), SUM (DECODE (b1, 'B', tut1, 0))&lt;br /&gt;FROM table01 t1&lt;br /&gt;WHERE tar1 = to_date('29.06.2007','dd.mm.yyyy')&lt;br /&gt;AND skod1 = NVL(NULL, skod1)&lt;br /&gt;AND htno1 = '22001901'&lt;br /&gt;AND 9000 + dkod1 = 9001&lt;br /&gt;AND NVL (dtkod1, '*') = NVL (NULL, '*')&lt;br /&gt;AND eno1 &lt; 9000;&lt;br /&gt;&lt;br /&gt;Plan&lt;br /&gt;SELECT STATEMENT  CHOOSECost: 621  Bytes: 36  Cardinality: 1     &lt;br /&gt;3 SORT AGGREGATE  Bytes: 36  Cardinality: 1    &lt;br /&gt;2 TABLE ACCESS BY INDEX ROWID DBUSER01.TABLE01 Cost: 621  Bytes: 36  Cardinality: 1   &lt;br /&gt;1 INDEX RANGE SCAN NON-UNIQUE DBUSER01.TABLE01_4X Cost: 519  Cardinality: 3,648  &lt;br /&gt;&lt;br /&gt;SELECT /*+ index(t1 TABLE01_2X)*/&lt;br /&gt;SUM (DECODE (b1, 'A', tut1, 0)), SUM (DECODE (b1, 'B', tut1, 0))&lt;br /&gt;FROM table01 t1&lt;br /&gt;WHERE tar1 = to_date('29.06.2007','dd.mm.yyyy')&lt;br /&gt;AND skod1 = NVL(NULL, skod1)&lt;br /&gt;AND htno1 = '22001901'&lt;br /&gt;AND 9000 + dkod1 = 9001&lt;br /&gt;AND NVL (dtkod1, '*') = NVL (NULL, '*')&lt;br /&gt;AND eno1 &lt; 9000;&lt;br /&gt;&lt;br /&gt;Plan&lt;br /&gt;SELECT STATEMENT  CHOOSECost: 11,248  Bytes: 36  Cardinality: 1     &lt;br /&gt;3 SORT AGGREGATE  Bytes: 36  Cardinality: 1    &lt;br /&gt;2 TABLE ACCESS BY INDEX ROWID DBUSER01.TABLE01 Cost: 11,248  Bytes: 36  Cardinality: 1   &lt;br /&gt;1 INDEX RANGE SCAN NON-UNIQUE DBUSER01.TABLE01_2X Cost: 11,066  Cardinality: 716  &lt;br /&gt;&lt;/pre&gt;------------------------------Lets examine the costs of the following SQLs&lt;pre class='brush: sql'&gt;SELECT SUM (DECODE (b1, 'A', tut1, 0)), SUM (DECODE (b1, 'B', tut1, 0))&lt;br /&gt;FROM table01 t1&lt;br /&gt;WHERE tar1 = to_date('29.06.2007','dd.mm.yyyy')&lt;br /&gt;AND skod1 = NVL(NULL, skod1)&lt;br /&gt;AND htno1 = '22001901'&lt;br /&gt;AND 9000 + dkod1 = 9001&lt;br /&gt;AND NVL (dtkod1, '*') = NVL (NULL, '*')&lt;br /&gt;AND eno1 &lt; 9000;&lt;br /&gt;---------------------------------------------------------&lt;br /&gt;Plan&lt;br /&gt;SELECT STATEMENT  CHOOSECost: 621  Bytes: 36  Cardinality: 1     &lt;br /&gt;3 SORT AGGREGATE  Bytes: 36  Cardinality: 1    &lt;br /&gt;2 TABLE ACCESS BY INDEX ROWID DBUSER01.TABLE01 Cost: 621  Bytes: 36  Cardinality: 1   &lt;br /&gt;1 INDEX RANGE SCAN NON-UNIQUE DBUSER01.TABLE01_4X Cost: 519  Cardinality: 3,648  &lt;br /&gt;---------------------------------------------------------&lt;br /&gt;&lt;br /&gt;select owner, index_name, blevel, leaf_blocks, clustering_factor from dba_indexes where index_name = 'TABLE01_4X';&lt;br /&gt;---------------------------------------------------------&lt;br /&gt;OWNER|INDEX_NAME|BLEVEL|LEAF_BLOCKS|CLUSTERING_FACTOR&lt;br /&gt;DBUSER01|TABLE01_4X|3|303888|1796569&lt;br /&gt;&lt;/pre&gt;effective index selectivity = density of "TAR1" columneffective table selectivity = (density of "TAR1" column) * (density of "SKOD1" column) &lt;pre class='brush: sql'&gt;select column_name, num_distinct, density, num_buckets from dba_tab_columns t1 where t1.table_name = 'TABLE01' &lt;br /&gt;and t1.column_name in ('TAR1', 'SKOD1')&lt;br /&gt;order by t1.column_name;&lt;br /&gt;---------------------------------------------------------&lt;br /&gt;COLUMN_NAME|NUM_DISTINCT|DENSITY|NUM_BUCKETS&lt;br /&gt;TAR1|608|0.00169779286926995|10&lt;br /&gt;SKOD1|73|0.0333333333333333|8&lt;br /&gt;&lt;/pre&gt;cost =blevel +ceiling(leaf_blocks * effective index selectivity) +ceiling(clustering_factor * effective table selectivity)cost =3 +ceiling(303888 * 0.00169779286926995) +ceiling(1796569 * (0.00169779286926995 * 0.0333333333333333))= 621----------------------&lt;pre class='brush: sql'&gt;SELECT /*+ index(t1 TABLE01_2X)*/&lt;br /&gt;SUM (DECODE (b1, 'A', tut1, 0)), SUM (DECODE (b1, 'B', tut1, 0))&lt;br /&gt;FROM table01 t1&lt;br /&gt;WHERE tar1 = to_date('29.06.2007','dd.mm.yyyy')&lt;br /&gt;AND skod1 = NVL(NULL, skod1)&lt;br /&gt;AND htno1 = '22001901'&lt;br /&gt;AND 9000 + dkod1 = 9001&lt;br /&gt;AND NVL (dtkod1, '*') = NVL (NULL, '*')&lt;br /&gt;AND eno1 &lt; 9000;&lt;br /&gt;---------------------------------------------------------&lt;br /&gt;Plan&lt;br /&gt;SELECT STATEMENT  CHOOSECost: 11,248  Bytes: 36  Cardinality: 1     &lt;br /&gt;3 SORT AGGREGATE  Bytes: 36  Cardinality: 1    &lt;br /&gt;2 TABLE ACCESS BY INDEX ROWID DBUSER01.TABLE01 Cost: 11,248  Bytes: 36  Cardinality: 1   &lt;br /&gt;1 INDEX RANGE SCAN NON-UNIQUE DBUSER01.TABLE01_2X Cost: 11,066  Cardinality: 716  &lt;br /&gt;---------------------------------------------------------&lt;br /&gt;&lt;br /&gt;select owner, index_name, blevel, leaf_blocks, clustering_factor from dba_indexes where index_name = 'TABLE01_2X';&lt;br /&gt;---------------------------------------------------------&lt;br /&gt;OWNER|INDEX_NAME|BLEVEL|LEAF_BLOCKS|CLUSTERING_FACTOR&lt;br /&gt;DBUSER01|TABLE01_2X|3|331864|16304224&lt;br /&gt;&lt;/pre&gt;effective index selectivity = density of "HTNO1" columneffective table selectivity = (density of "DKOD1" column) * (density of "HTNO1" column) * (density of "SKOD1" column) &lt;pre class='brush: sql'&gt;select column_name, num_distinct, density, num_buckets from dba_tab_columns t1 where t1.table_name = 'TABLE01' &lt;br /&gt;and t1.column_name in ('DKOD1', 'HTNO1', 'SKOD1')&lt;br /&gt;order by t1.column_name;&lt;br /&gt;---------------------------------------------------------&lt;br /&gt;COLUMN_NAME|NUM_DISTINCT|DENSITY|NUM_BUCKETS&lt;br /&gt;DKOD1|12|0.0384615384615385|2&lt;br /&gt;HTNO1|968|0.0333333333333333|9&lt;br /&gt;SKOD1|73|0.0333333333333333|8&lt;br /&gt;&lt;/pre&gt;Since the "   AND 9000 + dkod1 = 9001" condition equals "function(col) = constant" is has the static selectivity of %1 (0.001)instead of 0.0833333333333333.cost =blevel +ceiling(leaf_blocks * effective index selectivity) +ceiling(clustering_factor * effective table selectivity)cost =3 +ceiling(331864 * 0.0333333333333333) +ceiling(16304224 * (0.01 * 0.0333333333333333 * 0.0333333333333333))= 11248--------------------------How the histograms caused the CBO to choose the righr index ?Lets look at the histogram data.&lt;pre class='brush: sql'&gt;select * from dba_tab_histograms t1 where t1.table_name = 'TABLE01' &lt;br /&gt;and t1.column_name in ('TAR1','HTNO1', 'DKOD1', 'SKOD1')&lt;br /&gt;order by t1.column_name, t1.endpoint_number ;&lt;br /&gt;---------------------------------------------&lt;br /&gt;OWNER|TABLE_NAME|COLUMN_NAME|ENDPOINT_NUMBER|ENDPOINT_VALUE|ENDPOINT_ACTUAL_VALUE&lt;br /&gt;DBUSER01|TABLE01|DKOD1|8|1|&lt;br /&gt;DBUSER01|TABLE01|DKOD1|9|2|&lt;br /&gt;DBUSER01|TABLE01|DKOD1|10|21|&lt;br /&gt;DBUSER01|TABLE01|HTNO1|0|2.50227984373754E35|&lt;br /&gt;DBUSER01|TABLE01|HTNO1|1|2.60632781273513E35|&lt;br /&gt;DBUSER01|TABLE01|HTNO1|2|2.60632860505268E35|&lt;br /&gt;DBUSER01|TABLE01|HTNO1|3|2.60775139366763E35|&lt;br /&gt;DBUSER01|TABLE01|HTNO1|5|2.65906207772846E35|&lt;br /&gt;DBUSER01|TABLE01|HTNO1|6|2.76351807179888E35|&lt;br /&gt;DBUSER01|TABLE01|HTNO1|7|2.76351807179912E35|&lt;br /&gt;DBUSER01|TABLE01|HTNO1|8|2.81462815943683E35|&lt;br /&gt;DBUSER01|TABLE01|HTNO1|9|2.81462815943707E35|&lt;br /&gt;DBUSER01|TABLE01|HTNO1|10|2.97121551998981E35|&lt;br /&gt;DBUSER01|TABLE01|TAR1|0|2453374|&lt;br /&gt;DBUSER01|TABLE01|TAR1|1|2453502|&lt;br /&gt;DBUSER01|TABLE01|TAR1|2|2453599|&lt;br /&gt;DBUSER01|TABLE01|TAR1|3|2453689|&lt;br /&gt;DBUSER01|TABLE01|TAR1|4|2453790|&lt;br /&gt;DBUSER01|TABLE01|TAR1|5|2453889|&lt;br /&gt;DBUSER01|TABLE01|TAR1|6|2453973|&lt;br /&gt;DBUSER01|TABLE01|TAR1|7|2454060|&lt;br /&gt;DBUSER01|TABLE01|TAR1|8|2454141|&lt;br /&gt;DBUSER01|TABLE01|TAR1|9|2454218|&lt;br /&gt;DBUSER01|TABLE01|TAR1|10|2454292|&lt;br /&gt;DBUSER01|TABLE01|SKOD1|0|8345|&lt;br /&gt;DBUSER01|TABLE01|SKOD1|3|9000|&lt;br /&gt;DBUSER01|TABLE01|SKOD1|4|9050|&lt;br /&gt;DBUSER01|TABLE01|SKOD1|5|9159|&lt;br /&gt;DBUSER01|TABLE01|SKOD1|6|9170|&lt;br /&gt;DBUSER01|TABLE01|SKOD1|7|9300|&lt;br /&gt;DBUSER01|TABLE01|SKOD1|8|9412|&lt;br /&gt;DBUSER01|TABLE01|SKOD1|9|9631|&lt;br /&gt;DBUSER01|TABLE01|SKOD1|10|9892|&lt;br /&gt;&lt;/pre&gt;Lets look at the densities before and after the histograms.Before&lt;pre class='brush: sql'&gt;select owner, index_name, blevel, leaf_blocks, clustering_factor from dba_indexes where index_name = 'TABLE01_2X';&lt;br /&gt;---------------------------------------------------------&lt;br /&gt;OWNER|INDEX_NAME|BLEVEL|LEAF_BLOCKS|CLUSTERING_FACTOR&lt;br /&gt;DBUSER01|TABLE01_2X|3|331491|16303842&lt;br /&gt;DBUSER01|TABLE01_4X|3|302597|1791039&lt;br /&gt;&lt;br /&gt;select column_name, num_distinct, density, num_buckets from dba_tab_columns t1 where t1.table_name = 'TABLE01' &lt;br /&gt;and t1.column_name in ('DKOD1', 'HTNO1', 'SKOD1', 'TAR1')&lt;br /&gt;order by t1.column_name;&lt;br /&gt;---------------------------------------------------------&lt;br /&gt;COLUMN_NAME|NUM_DISTINCT|DENSITY|NUM_BUCKETS&lt;br /&gt;DKOD1|12|0.0833333333333333|1&lt;br /&gt;HTNO1|965|0.00103626943005181|1&lt;br /&gt;TAR1|608|0.00164473684210526|1&lt;br /&gt;SKOD1|73|0.0136986301369863|1&lt;br /&gt;&lt;/pre&gt;After&lt;pre class='brush: sql'&gt;select owner, index_name, blevel, leaf_blocks, clustering_factor from dba_indexes where index_name = 'TABLE01_2X';&lt;br /&gt;---------------------------------------------------------&lt;br /&gt;OWNER|INDEX_NAME|BLEVEL|LEAF_BLOCKS|CLUSTERING_FACTOR&lt;br /&gt;DBUSER01|TABLE01_2X|3|331864|16304224&lt;br /&gt;DBUSER01|TABLE01_4X|3|303888|1796569&lt;br /&gt;&lt;br /&gt;select column_name, num_distinct, density, num_buckets from dba_tab_columns t1 where t1.table_name = 'TABLE01' &lt;br /&gt;and t1.column_name in ('DKOD1', 'HTNO1', 'SKOD1', 'TAR1')&lt;br /&gt;order by t1.column_name;&lt;br /&gt;---------------------------------------------------------&lt;br /&gt;COLUMN_NAME|NUM_DISTINCT|DENSITY|NUM_BUCKETS&lt;br /&gt;DKOD1|12|0.0384615384615385|2&lt;br /&gt;HTNO1|968|0.0333333333333333|9&lt;br /&gt;TAR1|608|0.00169779286926995|10&lt;br /&gt;SKOD1|73|0.0333333333333333|8&lt;br /&gt;&lt;/pre&gt;As we can see the leaf_blocks and clustering_factor values of the indexes are changed a bit,but these are not so important in cost calculation, but the densities of the indexed columns are much more effective in cost calculation.Lets examine them closer.Before the histograms the densities of all the colums are equal to 1/num_distinct of the respective columns.&lt;pre class='brush: sql'&gt;select column_name, num_distinct, density, 1/numdistinct density_calculated from dba_tab_columns t1 where t1.table_name = 'TABLE01' &lt;br /&gt;and t1.column_name in ('DKOD1', 'HTNO1', 'SKOD1', 'TAR1')&lt;br /&gt;order by t1.column_name;&lt;br /&gt;---------------------------------------------------------&lt;br /&gt;COLUMN_NAME|NUM_DISTINCT|DENSITY|DENSITY_CALCULATED&lt;br /&gt;DKOD1|12|0.0833333333333333|0.0833333333333333&lt;br /&gt;HTNO1|965|0.00103626943005181|0.00103626943005181&lt;br /&gt;TAR1|608|0.00164473684210526|0.00164473684210526&lt;br /&gt;SKOD1|73|0.0136986301369863|0.0136986301369863&lt;br /&gt;&lt;/pre&gt;After collecting the histograms the densities of all the colums are NOT equal to 1/num_distinct of the respective columns.&lt;pre class='brush: sql'&gt;select column_name, num_distinct, density, 1/numdistinct density_calculated from dba_tab_columns t1 where t1.table_name = 'TABLE01' &lt;br /&gt;and t1.column_name in ('DKOD1', 'HTNO1', 'SKOD1', 'TAR1')&lt;br /&gt;order by t1.column_name;&lt;br /&gt;---------------------------------------------------------&lt;br /&gt;COLUMN_NAME|NUM_DISTINCT|DENSITY|DENSITY_CALCULATED&lt;br /&gt;DKOD1|12|0.0384615384615385|0.0833333333333333&lt;br /&gt;HTNO1|968|0.0333333333333333|0.00103305785123967&lt;br /&gt;TAR1|608|0.00169779286926995|0.00164473684210526&lt;br /&gt;SKOD1|73|0.0333333333333333|0.0136986301369863&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Since the "DKOD1" column has the static selectivity of 0.01, the selectivities of the other columns &lt;br /&gt;are effective role in the calculation of cost. As we see after the histograms, the density of "HTNO1" &lt;br /&gt;and "SKOD1" columns are increased,  the density of "TAR1" is decreased a little bit. Since the "SKOD1" &lt;br /&gt;column exists in both indexes we should examine the densities of the "HTNO1" and "TAR1" columns. &lt;br /&gt;&lt;br /&gt;In normal case, I mean statistics without histograms, the CBO assumes a smooth distribution of data values of&lt;br /&gt;a column between minimum and maximum values. But in reality there are fluctuation in the distribution of data&lt;br /&gt;for some columns. I mean some values appears rarely but some data appears frequently in distribution. So the CBO &lt;br /&gt;can not determine this distribution without having histogram data on these columns. The calculation of density of &lt;br /&gt;these columns in case of histograms is a very complex algorithm so we should not bother about it. &lt;br /&gt;&lt;br /&gt;This case show the importance of histograms where there is skewed data in indexed columns.&lt;br /&gt;&lt;br /&gt;Regards&lt;br /&gt;Ural Ural&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6717103620143238053-7076765831471309359?l=uralural.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://uralural.blogspot.com/feeds/7076765831471309359/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6717103620143238053&amp;postID=7076765831471309359' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6717103620143238053/posts/default/7076765831471309359'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6717103620143238053/posts/default/7076765831471309359'/><link rel='alternate' type='text/html' href='http://uralural.blogspot.com/2007/07/oracle-cbo-chooses-wrong-index-although.html' title='Oracle CBO chooses the wrong index although the statistics are collected on the related table'/><author><name>Ural Ural</name><uri>http://www.blogger.com/profile/06556787053001681445</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='19' height='32' src='http://2.bp.blogspot.com/-FS7mo23hHG0/TjlVoo70i9I/AAAAAAAABwQ/mlpdh17_nwM/s220/IMAG0008.jpg'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6717103620143238053.post-7497243467594575453</id><published>2007-04-20T09:55:00.000-07:00</published><updated>2011-06-20T12:40:27.475-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='dbms_job'/><category scheme='http://www.blogger.com/atom/ns#' term='plsql'/><category scheme='http://www.blogger.com/atom/ns#' term='9i'/><category scheme='http://www.blogger.com/atom/ns#' term='ORA-04030'/><category scheme='http://www.blogger.com/atom/ns#' term='PGA'/><category scheme='http://www.blogger.com/atom/ns#' term='memory'/><category scheme='http://www.blogger.com/atom/ns#' term='dba'/><category scheme='http://www.blogger.com/atom/ns#' term='oracle'/><title type='text'>PGA memory hungry plsql codes and inevitable "ORA-04030" error</title><content type='html'>Hi,&lt;br /&gt;Today, we found out memory eating, carnivore unix processes in our &lt;br /&gt;production Oracle database server's operating system.&lt;br /&gt;When we trace them, we realized&lt;br /&gt;that they are Oracle client processes coming from Internet banking &lt;br /&gt;connections. We analyzed the case and these sessions were growing in PGA &lt;br /&gt;Memory usage. When they hit the Operating System memory limit they got &lt;br /&gt;"ORA-04030" error but they did not stop , they continued to eat up the &lt;br /&gt;memory (PGA). So we killed some of them but there were new sessions coming &lt;br /&gt;from the same system behaving similarly.We examined the situation with the &lt;br /&gt;people from development team and they found out that one day ago they &lt;br /&gt;added a new dynamic parameter to one of the database packages generating &lt;br /&gt;html output, they generating the html code by combining data from &lt;br /&gt;different tables but one of these cursors that selects form these tables&lt;br /&gt;gone into an infinite loop and caused that problem, so they corrected the &lt;br /&gt;data that caused this infinite loop and they put extra controls to the &lt;br /&gt;plsql code and user interface programs to prevent the error happening &lt;br /&gt;again.&lt;br /&gt;&lt;br /&gt;But after that we, as Oracle DBA team, decided to develop a database &lt;br /&gt;procedure and database job that repeatedly checks for any sessions that &lt;br /&gt;consumes PGA memory and have it email these sessions info to the DBA &lt;br /&gt;Group for being able take early corrective action.&lt;br /&gt;&lt;br /&gt;The following is the code that we developed and use for this purpose.&lt;br /&gt;&lt;br /&gt;-----------------&lt;br /&gt;&lt;pre class='brush: sql'&gt;select * from v$statname where statistic# = 20&lt;br /&gt;/*&lt;br /&gt;STATISTIC#|NAME|CLASS&lt;br /&gt;20|session pga memory|1&lt;br /&gt;*/&lt;br /&gt;&lt;br /&gt;CREATE OR REPLACE PROCEDURE DBUSER01.Dba_Sess_Pga_Mem_Control IS&lt;br /&gt;CURSOR c1 IS&lt;br /&gt;SELECT t1.username, t1.SID, t1.serial#,&lt;br /&gt;TRUNC (a_sess_pga_mem / 1024 / 1024) sess_pga_mem_mb&lt;br /&gt;FROM v$session t1,&lt;br /&gt;(SELECT *&lt;br /&gt;FROM (SELECT   SID, VALUE a_sess_pga_mem&lt;br /&gt;FROM v$sesstat&lt;br /&gt;WHERE statistic# = 20 --session pga memory&lt;br /&gt;AND TRUNC(VALUE / 1024 / 1024) &gt;= 50&lt;br /&gt;ORDER BY VALUE DESC)&lt;br /&gt;WHERE ROWNUM &lt;= 1) t2&lt;br /&gt;WHERE t1.SID = t2.SID;&lt;br /&gt;&lt;br /&gt;v_message   VARCHAR2(2000);&lt;br /&gt;v_delimiter VARCHAR2(2);&lt;br /&gt;r1          c1%ROWTYPE;&lt;br /&gt;BEGIN&lt;br /&gt;IF m_tatil_bul2(TRUNC(SYSDATE), 'B') = 0 THEN&lt;br /&gt;-- If it is not on weekend&lt;br /&gt;&lt;br /&gt;v_delimiter := '';&lt;br /&gt;OPEN c1;&lt;br /&gt;LOOP&lt;br /&gt;FETCH c1&lt;br /&gt;INTO r1;&lt;br /&gt;EXIT WHEN c1%NOTFOUND;&lt;br /&gt;&lt;br /&gt;v_message := v_message || v_delimiter;&lt;br /&gt;v_message := v_message || 'Username '        || CHR(9) || CHR(9) || ' : ' || r1.username                 || CHR(10)&lt;br /&gt;|| 'Sid,Serial# '     || CHR(9) || CHR(9) || ' : ' || r1.sid || ',' || r1.serial# || CHR(10)&lt;br /&gt;|| 'PGA Memory (MB) '           || CHR(9) || ' : ' || r1.sess_pga_mem_mb          || CHR(10)&lt;br /&gt;|| '------------------------------------------------------';&lt;br /&gt;v_delimiter := CHR(10);&lt;br /&gt;&lt;br /&gt;END LOOP;&lt;br /&gt;CLOSE c1;&lt;br /&gt;&lt;br /&gt;IF v_delimiter = CHR(10) THEN&lt;br /&gt;DBUSER01.smtp.mail('dba@company01.com.tr',&lt;br /&gt;'dba@company01.com.tr',&lt;br /&gt;'There are sessions consuming too much PGA MEMORY (PGA Memory &gt;= 50 MB) Please check !...',&lt;br /&gt;v_message);&lt;br /&gt;END IF;&lt;br /&gt;END IF;&lt;br /&gt;END;&lt;br /&gt;/&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Create the job that will call the above procedure in the specified intervals (3 mins in our case)&lt;br /&gt;&lt;br /&gt;&lt;pre class='brush: sql'&gt;DECLARE&lt;br /&gt;X NUMBER;&lt;br /&gt;BEGIN&lt;br /&gt;SYS.DBMS_JOB.SUBMIT&lt;br /&gt;( job       =&gt; X &lt;br /&gt;,what      =&gt; 'DBUSER01.Dba_Sess_Pga_Mem_Control;'&lt;br /&gt;,next_date =&gt; SYSDATE&lt;br /&gt;,interval  =&gt; 'SYSDATE + 3/(24*60)'&lt;br /&gt;,no_parse  =&gt; TRUE&lt;br /&gt;);&lt;br /&gt;SYS.DBMS_OUTPUT.PUT_LINE('Job Number is: ' || to_char(x));&lt;br /&gt;END;&lt;br /&gt;/&lt;br /&gt;&lt;br /&gt;commit;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;I hope you do not have any PGA memory hungry sessions.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6717103620143238053-7497243467594575453?l=uralural.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://uralural.blogspot.com/feeds/7497243467594575453/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6717103620143238053&amp;postID=7497243467594575453' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6717103620143238053/posts/default/7497243467594575453'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6717103620143238053/posts/default/7497243467594575453'/><link rel='alternate' type='text/html' href='http://uralural.blogspot.com/2007/04/pga-memory-hungry-plsql-codes-and_20.html' title='PGA memory hungry plsql codes and inevitable &quot;ORA-04030&quot; error'/><author><name>Ural Ural</name><uri>http://www.blogger.com/profile/06556787053001681445</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='19' height='32' src='http://2.bp.blogspot.com/-FS7mo23hHG0/TjlVoo70i9I/AAAAAAAABwQ/mlpdh17_nwM/s220/IMAG0008.jpg'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6717103620143238053.post-6994381564776777</id><published>2007-04-19T11:11:00.000-07:00</published><updated>2011-06-20T12:45:28.917-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='sqlplus'/><category scheme='http://www.blogger.com/atom/ns#' term='6751'/><category scheme='http://www.blogger.com/atom/ns#' term='TWO_TASK'/><category scheme='http://www.blogger.com/atom/ns#' term='ORA-27123'/><category scheme='http://www.blogger.com/atom/ns#' term='ORA-01034'/><category scheme='http://www.blogger.com/atom/ns#' term='chmod'/><category scheme='http://www.blogger.com/atom/ns#' term='9i'/><category scheme='http://www.blogger.com/atom/ns#' term='dba'/><category scheme='http://www.blogger.com/atom/ns#' term='oracle'/><title type='text'>Getting "ORA-01034" and "ORA-27123" errors when connecting to Oracle 9i database with another unix user other than "oracle" user (database owner)</title><content type='html'>The problem is when you try to connect to the oracle locally by using another user other than oracle (database owner) we get "ORA-01034" and "ORA-27123" errors. When you use "TWO_TASK" environment variable, it is OK, since it is going through network I mean over the listener. &lt;br /&gt;But locally we are not able to connect to the database whithout using "TWO_TASK". &lt;br /&gt;&lt;br /&gt;There may be others who have seen the same error, so I am writing the solution in my case here.&lt;br /&gt;&lt;br /&gt;&lt;pre class='brush: bash'&gt;user1@host1:/data3/oracle/user1 &gt; echo $TWO_TASK&lt;br /&gt;&lt;/pre&gt;&lt;pre class='brush: sql'&gt;user1@host1:/data3/oracle/user1 &gt; sqlplus db_user1&lt;br /&gt;&lt;br /&gt;SQL*Plus: Release 9.2.0.4.0 - Production on Wed Apr 18 23:37:00 2007&lt;br /&gt;&lt;br /&gt;Copyright (c) 1982, 2002, Oracle Corporation.  All rights reserved.&lt;br /&gt;&lt;br /&gt;Enter password:&lt;br /&gt;ERROR:&lt;br /&gt;ORA-01034: ORACLE not available&lt;br /&gt;ORA-27123: unable to attach to shared memory segment&lt;br /&gt;IBM AIX RISC System/6000 Error: 13: Permission denied&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Enter user-name: ^C&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;ORACLE_SID and ORACLE_HOME are checked and they are what they should be for this database so what is the problem then ?&lt;br /&gt;&lt;br /&gt;Solution :&lt;br /&gt;&lt;br /&gt;After searching for the solution for some time in Internet,&lt;br /&gt;I finally found the following a solution that solved my problem.&lt;br /&gt;&lt;br /&gt;&lt;pre class='brush: bash'&gt;oracle@host1:/data3/oracle &gt; cd $ORACLE_HOME/bin&lt;br /&gt;oracle@host1:/data3/oracle/bin &gt; ls -l oracle&lt;br /&gt;-rwxr-xrwx   1 oracle   dba        74053740 Sep 04 2003  oracle&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;When we look at the file permissions of "oracle" executable it looks strange &lt;br /&gt;because it normally should be like "-rwsr-s--x", so we are going to make it so&lt;br /&gt;&lt;br /&gt;First of all we close the database&lt;br /&gt;This is very important that you should close the database before doing that&lt;br /&gt;&lt;br /&gt;&lt;pre class='brush: sql'&gt;oracle@host1:/data3/oracle &gt; sqlplus "/as sysdba"&lt;br /&gt;&lt;br /&gt;SQL*Plus: Release 9.2.0.4.0 - Production on Thu Apr 19 00:17:08 2007&lt;br /&gt;&lt;br /&gt;Copyright (c) 1982, 2002, Oracle Corporation.  All rights reserved.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Connected to:&lt;br /&gt;Oracle9i Enterprise Edition Release 9.2.0.4.0 - 64bit Production&lt;br /&gt;With the Partitioning, OLAP and Oracle Data Mining options&lt;br /&gt;JServer Release 9.2.0.4.0 - Production&lt;br /&gt;&lt;br /&gt;SQL&gt; alter system checkpoint;&lt;br /&gt;&lt;br /&gt;System altered.&lt;br /&gt;&lt;br /&gt;SQL&gt; shutdown abort&lt;br /&gt;ORACLE instance shut down.&lt;br /&gt;SQL&gt; exit&lt;br /&gt;Disconnected from Oracle9i Enterprise Edition Release 9.2.0.4.0 -&lt;br /&gt;64bit Production&lt;br /&gt;With the Partitioning, OLAP and Oracle Data Mining options&lt;br /&gt;JServer Release 9.2.0.4.0 - Production&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Then we change the file permissions of "oracle" executable&lt;br /&gt;&lt;br /&gt;&lt;pre class='brush: bash'&gt;oracle@host1:/data3/oracle/bin &gt; chmod 6751 oracle&lt;br /&gt;oracle@host1:/data3/oracle/bin &gt; ls -l oracle&lt;br /&gt;-rwsr-s--x   1 oracle   dba        74053740 Sep 04 2003  oracle&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Then we open the database &lt;br /&gt;&lt;br /&gt;&lt;pre class='brush: sql'&gt;oracle@host1:/data3/oracle/bin &gt; sqlplus "/as sysdba"&lt;br /&gt;&lt;br /&gt;SQL*Plus: Release 9.2.0.4.0 - Production on Thu Apr 19 00:18:10 2007&lt;br /&gt;&lt;br /&gt;Copyright (c) 1982, 2002, Oracle Corporation.  All rights reserved.&lt;br /&gt;&lt;br /&gt;Connected to an idle instance.&lt;br /&gt;&lt;br /&gt;SQL&gt; startup&lt;br /&gt;ORACLE instance started.&lt;br /&gt;&lt;br /&gt;Total System Global Area  622298928 bytes&lt;br /&gt;Fixed Size                   743216 bytes&lt;br /&gt;Variable Size             486539264 bytes&lt;br /&gt;Database Buffers          134217728 bytes&lt;br /&gt;Redo Buffers                 798720 bytes&lt;br /&gt;Database mounted.&lt;br /&gt;Database opened.&lt;br /&gt;SQL&gt; exit&lt;br /&gt;Disconnected from Oracle9i Enterprise Edition Release 9.2.0.4.0 -&lt;br /&gt;64bit Production&lt;br /&gt;With the Partitioning, OLAP and Oracle Data Mining options&lt;br /&gt;JServer Release 9.2.0.4.0 - Production&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;We switch to the user where the connection problem occurs&lt;br /&gt;&lt;br /&gt;&lt;pre class='brush: bash'&gt;oracle@host1:/data3/oracle/bin &gt; su - user1&lt;br /&gt;user1's Password:&lt;br /&gt;&lt;/pre&gt;&lt;pre class='brush: sql'&gt;user1@host1:/data3/oracle/user1 &gt; sqlplus db_user1&lt;br /&gt;&lt;br /&gt;SQL*Plus: Release 9.2.0.4.0 - Production on Thu Apr 19 00:18:46 2007&lt;br /&gt;&lt;br /&gt;Copyright (c) 1982, 2002, Oracle Corporation.  All rights reserved.&lt;br /&gt;&lt;br /&gt;Enter password:&lt;br /&gt;&lt;br /&gt;Connected to:&lt;br /&gt;Oracle9i Enterprise Edition Release 9.2.0.4.0 - 64bit Production&lt;br /&gt;With the Partitioning, OLAP and Oracle Data Mining options&lt;br /&gt;JServer Release 9.2.0.4.0 - Production&lt;br /&gt;&lt;br /&gt;SQL&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Finally the problem is solved.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6717103620143238053-6994381564776777?l=uralural.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://uralural.blogspot.com/feeds/6994381564776777/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6717103620143238053&amp;postID=6994381564776777' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6717103620143238053/posts/default/6994381564776777'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6717103620143238053/posts/default/6994381564776777'/><link rel='alternate' type='text/html' href='http://uralural.blogspot.com/2007/04/getting-ora-01034-and-ora-27123-errors_19.html' title='Getting &quot;ORA-01034&quot; and &quot;ORA-27123&quot; errors when connecting to Oracle 9i database with another unix user other than &quot;oracle&quot; user (database owner)'/><author><name>Ural Ural</name><uri>http://www.blogger.com/profile/06556787053001681445</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='19' height='32' src='http://2.bp.blogspot.com/-FS7mo23hHG0/TjlVoo70i9I/AAAAAAAABwQ/mlpdh17_nwM/s220/IMAG0008.jpg'/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6717103620143238053.post-3753278976290518084</id><published>2007-04-16T12:52:00.000-07:00</published><updated>2011-06-20T12:51:56.704-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='undo_tablespace'/><category scheme='http://www.blogger.com/atom/ns#' term='segment'/><category scheme='http://www.blogger.com/atom/ns#' term='undo'/><category scheme='http://www.blogger.com/atom/ns#' term='9i'/><category scheme='http://www.blogger.com/atom/ns#' term='rollback'/><category scheme='http://www.blogger.com/atom/ns#' term='extent'/><category scheme='http://www.blogger.com/atom/ns#' term='resize'/><category scheme='http://www.blogger.com/atom/ns#' term='dba'/><category scheme='http://www.blogger.com/atom/ns#' term='oracle'/><title type='text'>Resizing Undo Tablespaces</title><content type='html'>How do you resize undo tablepaces ? This is how I do it in an Oracle 9i database.&lt;br /&gt;&lt;br /&gt;Problem is the undo tablespace has grown up to the limit of its maxsize &lt;br /&gt;and we need to compact it or just we want to make it smaller due to a space problem&lt;br /&gt;&lt;br /&gt;Find undo info&lt;br /&gt;&lt;pre class='brush: sql'&gt;SELECT NAME, VALUE&lt;br /&gt;FROM v$parameter&lt;br /&gt;WHERE LOWER (NAME) LIKE '%undo%';&lt;br /&gt;/*&lt;br /&gt;NAME|VALUE&lt;br /&gt;undo_management|AUTO&lt;br /&gt;undo_tablespace|UNDOTBS1&lt;br /&gt;*/&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Find undo tablespace datafile info&lt;br /&gt;&lt;pre class='brush: sql'&gt;SELECT   file_name, BYTES / 1024 / 1024 mb&lt;br /&gt;FROM dba_data_files&lt;br /&gt;WHERE tablespace_name = 'UNDOTBS1'&lt;br /&gt;ORDER BY file_name;&lt;br /&gt;/*&lt;br /&gt;FILE_NAME|MB&lt;br /&gt;/datac3/oradata/andlp2/undotbs1_01.dbf|1793&lt;br /&gt;/datac6/oradata/andlp2/undotbs1_02.dbf|235&lt;br /&gt;/datac7/oradata/andlp2/undotbs1_03.dbf|1679&lt;br /&gt;*/&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Execute the following query to determine who is using a particular UNDO or Rollback Segment:&lt;br /&gt;&lt;pre class='brush: sql'&gt;SELECT TO_CHAR (s.SID) || ',' || TO_CHAR (s.serial#) sid_serial,&lt;br /&gt;NVL (s.username, 'None') orauser, s.program, r.NAME undoseg,&lt;br /&gt;t.used_ublk * TO_NUMBER (x.VALUE) / 1024 || 'K' "Undo"&lt;br /&gt;FROM SYS.v_$rollname r,&lt;br /&gt;SYS.v_$session s,&lt;br /&gt;SYS.v_$transaction t,&lt;br /&gt;SYS.v_$parameter x&lt;br /&gt;WHERE s.taddr = t.addr &lt;br /&gt;AND r.usn = t.xidusn(+) &lt;br /&gt;AND x.NAME = 'db_block_size'&lt;br /&gt;--No rows returned&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Create a second temporary undo tablespace&lt;br /&gt;&lt;pre class='brush: sql'&gt;CREATE UNDO TABLESPACE UNDOTBS2 DATAFILE &lt;br /&gt;'/datac7/oradata/andlp2/undotbs2_01.dbf' SIZE 500M AUTOEXTEND ON NEXT 16M MAXSIZE 5000M&lt;br /&gt;ONLINE&lt;br /&gt;BLOCKSIZE 8K;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Set this new undo tablespace as undo tablespace of the database&lt;br /&gt;&lt;pre class='brush: sql'&gt;ALTER SYSTEM SET undo_tablespace = UNDOTBS2;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;You can monitor the undo extents of all the undo tablespaces by using the following query&lt;br /&gt;&lt;pre class='brush: sql'&gt;SELECT tablespace_name, segment_name, SUM (blocks), SUM (BYTES) / 1024&lt;br /&gt;FROM dba_undo_extents&lt;br /&gt;GROUP BY tablespace_name, segment_name;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Since we are going to drop the old undo tablespace we need to know if any session is&lt;br /&gt;using any undo extent of this undo tablespace &lt;br /&gt;&lt;pre class='brush: sql'&gt;SELECT TO_CHAR (s.SID) || ',' || TO_CHAR (s.serial#) sid_serial,&lt;br /&gt;NVL (s.username, 'None') orauser, s.program, r.NAME undoseg,&lt;br /&gt;t.used_ublk * TO_NUMBER (x.VALUE) / 1024 || 'K' "Undo",&lt;br /&gt;t1.tablespace_name&lt;br /&gt;FROM SYS.v_$rollname r,&lt;br /&gt;SYS.v_$session s,&lt;br /&gt;SYS.v_$transaction t,&lt;br /&gt;SYS.v_$parameter x,&lt;br /&gt;dba_rollback_segs t1&lt;br /&gt;WHERE s.taddr = t.addr&lt;br /&gt;AND r.usn = t.xidusn(+)&lt;br /&gt;AND x.NAME = 'db_block_size'&lt;br /&gt;AND t1.segment_id = r.usn&lt;br /&gt;AND t1.tablespace_name = 'UNDOTBS1'  &lt;br /&gt;/*&lt;br /&gt;SID_SERIAL|ORAUSER|PROGRAM|UNDOSEG|Undo|TABLESPACE_NAME&lt;br /&gt;615,998|USER1|runform30x@host1 (TNS interface)|_SYSSMU102$|8K|UNDOTBS1&lt;br /&gt;*/&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;You can get more info about the undo extent that is online (used)   &lt;br /&gt;&lt;pre class='brush: sql'&gt;SELECT *&lt;br /&gt;FROM dba_rollback_segs&lt;br /&gt;WHERE status = 'ONLINE' &lt;br /&gt;AND tablespace_name = 'UNDOTBS1'&lt;br /&gt;ORDER BY tablespace_name, segment_name&lt;br /&gt;/*&lt;br /&gt;SEGMENT_NAME|OWNER|TABLESPACE_NAME|SEGMENT_ID|FILE_ID|BLOCK_ID|INITIAL_EXTENT|NEXT_EXTENT|MIN_EXTENTS|MAX_EXTENTS|PCT_INCREASE|STATUS|INSTANCE_NUM|RELATIVE_FNO&lt;br /&gt;_SYSSMU102$|PUBLIC|UNDOTBS1|102|33|4473|131072||2|32765||ONLINE||33&lt;br /&gt;*/&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Monitor the status of online undo extents&lt;br /&gt;&lt;pre class='brush: sql'&gt;SELECT segment_name, xacts, v.status&lt;br /&gt;FROM v$rollstat v, dba_rollback_segs&lt;br /&gt;WHERE tablespace_name = 'UNDOTBS1' &lt;br /&gt;AND segment_id = usn;&lt;br /&gt;/*&lt;br /&gt;SEGMENT_NAME|XACTS|STATUS&lt;br /&gt;_SYSSMU102$|1|PENDING OFFLINE&lt;br /&gt;*/&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;See it is in "PENDING OFFLINE" status until the transaction that is using it ends.&lt;br /&gt;&lt;br /&gt;See all the rollback info&lt;br /&gt;&lt;pre class='brush: sql'&gt;SELECT n.NAME, s.status, s.extents, s.rssize, s.hwmsize, s.xacts&lt;br /&gt;FROM v$rollname n, v$rollstat s&lt;br /&gt;WHERE n.usn = s.usn;&lt;br /&gt;/*&lt;br /&gt;NAME|STATUS|EXTENTS|RSSIZE|HWMSIZE|XACTS&lt;br /&gt;SYSTEM|ONLINE|6|385024|385024|0&lt;br /&gt;_SYSSMU102$|PENDING OFFLINE|42|42065920|42065920|1&lt;br /&gt;_SYSSMU262$|ONLINE|4|253952|253952|0&lt;br /&gt;_SYSSMU263$|ONLINE|2|122880|122880|0&lt;br /&gt;_SYSSMU264$|ONLINE|3|188416|188416|0&lt;br /&gt;_SYSSMU265$|ONLINE|3|188416|188416|0&lt;br /&gt;_SYSSMU266$|ONLINE|4|253952|253952|0&lt;br /&gt;_SYSSMU267$|ONLINE|2|122880|122880|0&lt;br /&gt;_SYSSMU268$|ONLINE|2|122880|122880|0&lt;br /&gt;_SYSSMU269$|ONLINE|2|122880|122880|0&lt;br /&gt;_SYSSMU270$|ONLINE|2|122880|122880|0&lt;br /&gt;_SYSSMU271$|ONLINE|2|122880|122880|0&lt;br /&gt;*/&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Find the active transactions using undo extents&lt;br /&gt;&lt;pre class='brush: sql'&gt;SELECT s.username, t.xidusn, t.ubafil, t.ubablk, t.used_ublk&lt;br /&gt;FROM v$session s, v$transaction t&lt;br /&gt;WHERE s.saddr = t.ses_addr;&lt;br /&gt;/*&lt;br /&gt;USERNAME|XIDUSN|UBAFIL|UBABLK|USED_UBLK&lt;br /&gt;MARDATA|102|30|153176|1&lt;br /&gt;*/&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;After all active transactions are committed, the status of Undo segment &lt;br /&gt;_SYSSMU102$ is automatically switched from PENDING OFFLINE mode to OFFLINE mode. &lt;br /&gt;PENDING OFFLINE mode does not allow any deletion process of tablespace. &lt;br /&gt;You can delete the tablespace in OFFLINE mode.&lt;br /&gt;&lt;br /&gt;If no segment is selected after you execute the SQL statement below, &lt;br /&gt;it means the segment is already switched to OFFLINE mode.&lt;br /&gt;&lt;br /&gt;&lt;pre class='brush: sql'&gt;SQL&gt; SELECT SEGMENT_NAME, XACTS, V.STATUS&lt;br /&gt;FROM V$ROLLSTAT V, DBA_ROLLBACK_SEGS&lt;br /&gt;WHERE TABLESPACE_NAME = 'UNDOTBS_02'&lt;br /&gt;AND SEGMENT_ID = USN;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;If the segment is selected and XACTS points to zero (0), rollback segment &lt;br /&gt;does not contain any pending transactions, and therefore, &lt;br /&gt;the segment is switched to OFFLINE mode immediately&lt;br /&gt;&lt;br /&gt;Wait for the active transaction to finish then monitor again   &lt;br /&gt;&lt;pre class='brush: sql'&gt;SELECT n.NAME, s.status, s.extents, s.rssize, s.hwmsize, s.xacts&lt;br /&gt;FROM v$rollname n, v$rollstat s&lt;br /&gt;WHERE n.usn = s.usn;&lt;br /&gt;/*&lt;br /&gt;NAME|STATUS|EXTENTS|RSSIZE|HWMSIZE|XACTS&lt;br /&gt;SYSTEM|ONLINE|6|385024|385024|0&lt;br /&gt;_SYSSMU262$|ONLINE|5|319488|319488|0&lt;br /&gt;_SYSSMU263$|ONLINE|2|122880|122880|0&lt;br /&gt;_SYSSMU264$|ONLINE|3|188416|188416|0&lt;br /&gt;_SYSSMU265$|ONLINE|3|188416|188416|0&lt;br /&gt;_SYSSMU266$|ONLINE|4|253952|253952|0&lt;br /&gt;_SYSSMU267$|ONLINE|2|122880|122880|0&lt;br /&gt;_SYSSMU268$|ONLINE|2|122880|122880|0&lt;br /&gt;_SYSSMU269$|ONLINE|2|122880|122880|0&lt;br /&gt;_SYSSMU270$|ONLINE|3|188416|188416|0&lt;br /&gt;_SYSSMU271$|ONLINE|2|122880|122880|0&lt;br /&gt;*/&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;As you can see all undo extents of the old undo tablespace UNDOTBS1 are dropped already now we can drop the tablespace&lt;br /&gt;&lt;pre class='brush: sql'&gt;DROP TABLESPACE undotbs1 INCLUDING CONTENTS AND DATAFILES ;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Recreate the original configuration :&lt;br /&gt;After that we can create again the original configuration, so recreate the old undo again&lt;br /&gt;and switch to it&lt;br /&gt;&lt;br /&gt;&lt;pre class='brush: sql'&gt;CREATE UNDO TABLESPACE UNDOTBS1 DATAFILE &lt;br /&gt;'/datac3/oradata/andlp2/undotbs1_01.dbf' SIZE 500M AUTOEXTEND ON NEXT 16M MAXSIZE 5000M,&lt;br /&gt;'/datac6/oradata/andlp2/undotbs1_02.dbf' SIZE 500M AUTOEXTEND ON NEXT 16M MAXSIZE 5000M,&lt;br /&gt;'/datac7/oradata/andlp2/undotbs1_03.dbf' SIZE 100M AUTOEXTEND OFF&lt;br /&gt;ONLINE&lt;br /&gt;BLOCKSIZE 8K;&lt;br /&gt;&lt;br /&gt;ALTER SYSTEM SET undo_tablespace = UNDOTBS1;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;See if there are any active undo extents of UNDOTBS2&lt;br /&gt;&lt;pre class='brush: sql'&gt;SELECT n.NAME, s.status, s.extents, s.rssize, s.hwmsize, s.xacts&lt;br /&gt;FROM v$rollname n, v$rollstat s&lt;br /&gt;WHERE n.usn = s.usn;&lt;br /&gt;/*&lt;br /&gt;NAME|STATUS|EXTENTS|RSSIZE|HWMSIZE|XACTS&lt;br /&gt;SYSTEM|ONLINE|6|385024|385024|0&lt;br /&gt;_SYSSMU1$|ONLINE|2|122880|122880|0&lt;br /&gt;_SYSSMU2$|ONLINE|2|122880|122880|0&lt;br /&gt;_SYSSMU3$|ONLINE|2|122880|122880|0&lt;br /&gt;_SYSSMU4$|ONLINE|2|122880|122880|0&lt;br /&gt;_SYSSMU5$|ONLINE|2|122880|122880|0&lt;br /&gt;_SYSSMU6$|ONLINE|2|122880|122880|0&lt;br /&gt;_SYSSMU7$|ONLINE|2|122880|122880|0&lt;br /&gt;_SYSSMU8$|ONLINE|2|122880|122880|0&lt;br /&gt;_SYSSMU9$|ONLINE|2|122880|122880|0&lt;br /&gt;_SYSSMU10$|ONLINE|2|122880|122880|0&lt;br /&gt;*/&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;See if there is any rollback segments of UNDOTBS2&lt;br /&gt;&lt;pre class='brush: sql'&gt;SELECT segment_name, xacts, v.status&lt;br /&gt;FROM v$rollstat v, dba_rollback_segs&lt;br /&gt;WHERE tablespace_name = 'UNDOTBS2' &lt;br /&gt;AND segment_id = usn;&lt;br /&gt;--No rows returned&lt;br /&gt;&lt;br /&gt;DROP TABLESPACE undotbs2 INCLUDING CONTENTS AND DATAFILES ;     &lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6717103620143238053-3753278976290518084?l=uralural.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://uralural.blogspot.com/feeds/3753278976290518084/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6717103620143238053&amp;postID=3753278976290518084' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6717103620143238053/posts/default/3753278976290518084'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6717103620143238053/posts/default/3753278976290518084'/><link rel='alternate' type='text/html' href='http://uralural.blogspot.com/2007/04/resizing-undo-tablespaces_16.html' title='Resizing Undo Tablespaces'/><author><name>Ural Ural</name><uri>http://www.blogger.com/profile/06556787053001681445</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='19' height='32' src='http://2.bp.blogspot.com/-FS7mo23hHG0/TjlVoo70i9I/AAAAAAAABwQ/mlpdh17_nwM/s220/IMAG0008.jpg'/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6717103620143238053.post-1682289775214406190</id><published>2007-04-16T11:33:00.000-07:00</published><updated>2011-06-20T12:52:56.481-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='statistics'/><category scheme='http://www.blogger.com/atom/ns#' term='dbms_job'/><category scheme='http://www.blogger.com/atom/ns#' term='dbms_stats'/><category scheme='http://www.blogger.com/atom/ns#' term='9i'/><category scheme='http://www.blogger.com/atom/ns#' term='job'/><category scheme='http://www.blogger.com/atom/ns#' term='dba'/><category scheme='http://www.blogger.com/atom/ns#' term='oracle'/><title type='text'>Gathering Table Statistics By Using Database Jobs</title><content type='html'>In Oracle9i Database, sometimes you need to gather statistics for a big table, since it will take long time&lt;br /&gt;you may not want to wait for it to finish or maybe you do not want to be disconnected by your company's firewall&lt;br /&gt;in the middle of the stat gathering work, in a situation like that you can create a database job for that purpose&lt;br /&gt;and let the job do the work at the background. You can use the some idea for your other long running processes too,&lt;br /&gt;convert them to database jobs, ideally using packaged logged procedures or functions, by doing that you can monitor the&lt;br /&gt;work from log records. I use the same idea in most of my work.&lt;br /&gt;Connect as SYS to the database and run the example code below, put the relevant parameters for the literal parts.&lt;br /&gt;&lt;br /&gt;&lt;pre class='brush: sql'&gt;DECLARE&lt;br /&gt;x NUMBER;&lt;br /&gt;BEGIN&lt;br /&gt;DBMS_JOB.submit&lt;br /&gt;(job =&gt; x,&lt;br /&gt;what =&gt; 'DBMS_STATS.gather_table_stats(ownname =&gt; ''OWNER1'', tabname =&gt; ''BIGTABLE1'', estimate_percent =&gt; 10, cascade =&gt; TRUE);',&lt;br /&gt;next_date =&gt; SYSDATE,&lt;br /&gt;interval =&gt; NULL,&lt;br /&gt;no_parse =&gt; TRUE&lt;br /&gt;);&lt;br /&gt;DBMS_OUTPUT.put_line ('Job Number is: '  TO_CHAR (x));&lt;br /&gt;COMMIT;&lt;br /&gt;END;&lt;br /&gt;/&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6717103620143238053-1682289775214406190?l=uralural.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://uralural.blogspot.com/feeds/1682289775214406190/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6717103620143238053&amp;postID=1682289775214406190' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6717103620143238053/posts/default/1682289775214406190'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6717103620143238053/posts/default/1682289775214406190'/><link rel='alternate' type='text/html' href='http://uralural.blogspot.com/2007/04/gathering-table-statistics-by-using_5949.html' title='Gathering Table Statistics By Using Database Jobs'/><author><name>Ural Ural</name><uri>http://www.blogger.com/profile/06556787053001681445</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='19' height='32' src='http://2.bp.blogspot.com/-FS7mo23hHG0/TjlVoo70i9I/AAAAAAAABwQ/mlpdh17_nwM/s220/IMAG0008.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6717103620143238053.post-2765864285214497897</id><published>2007-04-15T04:10:00.000-07:00</published><updated>2011-06-20T12:57:20.026-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='9i'/><category scheme='http://www.blogger.com/atom/ns#' term='temporary'/><category scheme='http://www.blogger.com/atom/ns#' term='tablespace'/><category scheme='http://www.blogger.com/atom/ns#' term='resize'/><category scheme='http://www.blogger.com/atom/ns#' term='dba'/><category scheme='http://www.blogger.com/atom/ns#' term='oracle'/><title type='text'>Resizing Temporary Tablespaces</title><content type='html'>How do you resize temporary tablepaces ? This is how I do it in a 9.2.0.4 Oracle database.&lt;br /&gt;&lt;br /&gt;Problem is the default temporary tablespace consists of only one tempfile&lt;br /&gt;and that tempfile has grown up to the limit of its maxsize&lt;br /&gt;and we need to compact it.&lt;br /&gt;&lt;br /&gt;The following is our default temporary tablespace&lt;br /&gt;&lt;pre class='brush: sql'&gt;SELECT property_value&lt;br /&gt;FROM database_properties&lt;br /&gt;WHERE property_name = 'DEFAULT_TEMP_TABLESPACE';&lt;br /&gt;/*&lt;br /&gt;PROPERTY_VALUE&lt;br /&gt;TEMP&lt;br /&gt;*/&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;The creation script of the temporary tablespace TEMP&lt;br /&gt;&lt;pre class='brush: sql'&gt;CREATE TEMPORARY TABLESPACE TEMP TEMPFILE&lt;br /&gt;'/datac6/oradata/andlp2/temp_1.dbf' SIZE 500M AUTOEXTEND ON NEXT 128M MAXSIZE 8000M&lt;br /&gt;EXTENT MANAGEMENT LOCAL UNIFORM SIZE 1M;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;This script is just for your information, to know the structure of the temporary tablespace&lt;br /&gt;&lt;br /&gt;Find the tempfile of this temporary tablespace&lt;br /&gt;&lt;pre class='brush: sql'&gt;SELECT tablespace_name, file_name, maxbytes, BYTES&lt;br /&gt;FROM dba_temp_files&lt;br /&gt;WHERE tablespace_name = 'TEMP';&lt;br /&gt;/*&lt;br /&gt;TABLESPACE_NAMEFILE_NAMEMAXBYTESBYTES&lt;br /&gt;TEMP/datac6/oradata/andlp2/temp_1.dbf83886080008388608000&lt;br /&gt;*/&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;As you can see from the maxbytes and bytes columns this datafile has grown up to its maxsize of 8000M&lt;br /&gt;&lt;br /&gt;First of all, we create another temporary tablespace&lt;br /&gt;&lt;pre class='brush: sql'&gt;CREATE TEMPORARY TABLESPACE TEMP1 TEMPFILE&lt;br /&gt;'/datac7/oradata/andlp2/temp1_1.dbf' SIZE 500M AUTOEXTEND ON NEXT 128M MAXSIZE 8000M&lt;br /&gt;EXTENT MANAGEMENT LOCAL UNIFORM SIZE 1M;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Make the new temprary tablespace TEMP1 the default temporary tablespace of the database&lt;br /&gt;&lt;pre class='brush: sql'&gt;ALTER DATABASE DEFAULT TEMPORARY TABLESPACE temp1;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Change the default temporary teblespaces of users to use he new TEMP1 temporary tablespace which are using the TEMP temporary tablespace before&lt;br /&gt;&lt;pre class='brush: sql'&gt;SELECT 'ALTER USER '  username  ' TEMPORARY TABLESPACE temp1;'&lt;br /&gt;FROM dba_users&lt;br /&gt;WHERE temporary_tablespace = 'TEMP'&lt;br /&gt;ORDER BY username;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Run the output of the above query as a script like below&lt;br /&gt;&lt;pre class='brush: sql'&gt;ALTER USER USER1 TEMPORARY TABLESPACE temp1;&lt;br /&gt;ALTER USER USER2 TEMPORARY TABLESPACE temp1;&lt;br /&gt;ALTER USER USER3 TEMPORARY TABLESPACE temp1;&lt;br /&gt;...&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Check if any of the active sessions use the TEMP temporary tablespace&lt;br /&gt;since there should not be any session using it, in order to change the size of it&lt;br /&gt;You can examine the sessions using it and decide to kill them or wait for them to finish their jobs and disconnect&lt;br /&gt;&lt;pre class='brush: sql'&gt;select *&lt;br /&gt;from v$session&lt;br /&gt;where saddr in (select session_addr&lt;br /&gt;from v$tempseg_usage v&lt;br /&gt;where v.tablespace = 'TEMP')&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;You can kill these sessions in your operating system with "kill -9" command (since the OS I am working on is IBM AIX)&lt;br /&gt;&lt;pre class='brush: sql'&gt;select 'kill -9 'spid&lt;br /&gt;from v$process&lt;br /&gt;where addr in (select paddr&lt;br /&gt;from v$session&lt;br /&gt;where saddr in (select session_addr&lt;br /&gt;from v$tempseg_usage v&lt;br /&gt;where v.tablespace = 'TEMP'))&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;After killing the sessions you can drop the old TEMP temporary tablespace&lt;br /&gt;&lt;pre class='brush: sql'&gt;DROP TABLESPACE temp INCLUDING CONTENTS AND DATAFILES;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Then to make the structure the same as before, we need to recreate the TEMP temporary tablespace and drop the TEMP1 temporary tablespace&lt;br /&gt;&lt;pre class='brush: sql'&gt;CREATE TEMPORARY TABLESPACE TEMP TEMPFILE&lt;br /&gt;'/datac6/oradata/andlp2/temp_1.dbf' SIZE 500M AUTOEXTEND ON NEXT 128M MAXSIZE 8000M&lt;br /&gt;EXTENT MANAGEMENT LOCAL UNIFORM SIZE 1M;&lt;br /&gt;&lt;br /&gt;ALTER DATABASE DEFAULT TEMPORARY TABLESPACE temp;&lt;br /&gt;&lt;br /&gt;select 'ALTER USER 'username' TEMPORARY TABLESPACE TEMP;'&lt;br /&gt;from dba_users&lt;br /&gt;where temporary_tablespace = 'TEMP1'&lt;br /&gt;order by username;&lt;br /&gt;--run the output as script&lt;br /&gt;&lt;br /&gt;DROP TABLESPACE temp1 INCLUDING CONTENTS AND DATAFILES;&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6717103620143238053-2765864285214497897?l=uralural.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://uralural.blogspot.com/feeds/2765864285214497897/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6717103620143238053&amp;postID=2765864285214497897' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6717103620143238053/posts/default/2765864285214497897'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6717103620143238053/posts/default/2765864285214497897'/><link rel='alternate' type='text/html' href='http://uralural.blogspot.com/2007/04/resizing-temporary-tablespaces.html' title='Resizing Temporary Tablespaces'/><author><name>Ural Ural</name><uri>http://www.blogger.com/profile/06556787053001681445</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='19' height='32' src='http://2.bp.blogspot.com/-FS7mo23hHG0/TjlVoo70i9I/AAAAAAAABwQ/mlpdh17_nwM/s220/IMAG0008.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6717103620143238053.post-3271509361917358058</id><published>2007-04-12T09:48:00.000-07:00</published><updated>2011-06-20T12:58:57.345-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='sqlplus'/><category scheme='http://www.blogger.com/atom/ns#' term='pagesize'/><category scheme='http://www.blogger.com/atom/ns#' term='9i'/><category scheme='http://www.blogger.com/atom/ns#' term='oracle'/><title type='text'>Sqlplus - pagesize</title><content type='html'>Everyday we learn something new about Oracle databases that we missedbefore or may be we did not needed. Below is one of them for me, but Iused it recently in a Unix script to generate an Sqlplus report. Ipublish it here so that there may be others that missed the samepoint.&lt;br /&gt;&lt;br /&gt;Maximum value of the Sqlplus pagesize parameter that you can set is 50000.&lt;br /&gt;&lt;br /&gt;&lt;pre class='brush: sql'&gt;set pagesize 50000&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6717103620143238053-3271509361917358058?l=uralural.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://uralural.blogspot.com/feeds/3271509361917358058/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6717103620143238053&amp;postID=3271509361917358058' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6717103620143238053/posts/default/3271509361917358058'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6717103620143238053/posts/default/3271509361917358058'/><link rel='alternate' type='text/html' href='http://uralural.blogspot.com/2007/04/sqlplus-pagesize_2023.html' title='Sqlplus - pagesize'/><author><name>Ural Ural</name><uri>http://www.blogger.com/profile/06556787053001681445</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='19' height='32' src='http://2.bp.blogspot.com/-FS7mo23hHG0/TjlVoo70i9I/AAAAAAAABwQ/mlpdh17_nwM/s220/IMAG0008.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6717103620143238053.post-8711776378327907047</id><published>2007-04-11T11:53:00.000-07:00</published><updated>2011-06-20T12:59:31.095-07:00</updated><title type='text'></title><content type='html'>Hi to the blogging community !&lt;br /&gt;&lt;br /&gt;My name is Ural Ural and I've been working with Oracle databases for about 12 years. I am a senior Oracle DBA. I am going to share all the information I learned about the Oracle databases and database administration here. I think, the more we share the more we learn new things about the Information Technology. So lets share our knowledge with the blogging community...&lt;br /&gt;&lt;br /&gt;Regards&lt;br /&gt;Ural&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6717103620143238053-8711776378327907047?l=uralural.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://uralural.blogspot.com/feeds/8711776378327907047/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6717103620143238053&amp;postID=8711776378327907047' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6717103620143238053/posts/default/8711776378327907047'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6717103620143238053/posts/default/8711776378327907047'/><link rel='alternate' type='text/html' href='http://uralural.blogspot.com/2007/04/hi-to-blogging-community-my-name-is.html' title=''/><author><name>Ural Ural</name><uri>http://www.blogger.com/profile/06556787053001681445</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='19' height='32' src='http://2.bp.blogspot.com/-FS7mo23hHG0/TjlVoo70i9I/AAAAAAAABwQ/mlpdh17_nwM/s220/IMAG0008.jpg'/></author><thr:total>0</thr:total></entry></feed>
