#
是誰"偷偷的"用了那么多空間呢(本來有幾十個G的Free磁盤空間的)?
檢查數據庫表空間占用空間情況:
SQL> select tablespace_name,sum(bytes)/1024/1024/1024 GB
2 from dba_data_files group by tablespace_name
3 union all
4 select tablespace_name,sum(bytes)/1024/1024/1024 GB
5 from dba_temp_files group by tablespace_name order by GB;
TABLESPACE_NAME GB
------------------------------ ----------
USERS .004882813
UNDOTBS2 .09765625
SYSTEM .478515625
SYSAUX .634765625
WAPCM_TS_VISIT_DETAIL .9765625
HY_DS_DEFAULT 1
MINT_TS_DEFAULT 1
MMS_TS_DATA2 1.375
MMS_IDX_SJH 2
MMS_TS_DEFAULT 2
IVRCN_TS_DATA 2
TABLESPACE_NAME GB
------------------------------ ----------
MMS_TS_DATA1 2
CM_TS_DEFAULT 5
TEMP 20.5498047
UNDOTBS1 27.1582031
15 rows selected.
不幸的發現,UNDO表空間已經擴展至27G,而TEMP表空間也擴展至20G,這2個表空間加起來占用了47G的磁盤空間,導致了空間不足。
顯然曾經有大事務占用了大量的UNDO表空間和Temp表空間,Oracle的AUM(Auto Undo Management)從出生以來就經常出現只擴展,不收縮(shrink)的情況(通常我們可以設置足夠的UNDO表空間大小,然后取消其自動擴展屬性).
現在我們可以采用如下步驟回收UNDO空間:
1.確認文件
SQL> select file_name,bytes/1024/1024 from dba_data_files
2 where tablespace_name like 'UNDOTBS1';
FILE_NAME
--------------------------------------------------------------------------------
BYTES/1024/1024
---------------
+ORADG/danaly/datafile/undotbs1.265.600173875
27810
2.檢查UNDO Segment狀態
SQL> select usn,xacts,rssize/1024/1024/1024,hwmsize/1024/1024/1024,shrinks
2 from v$rollstat order by rssize;
USN XACTS RSSIZE/1024/1024/1024 HWMSIZE/1024/1024/1024 SHRINKS
---------- ---------- --------------------- ---------------------- ----------
0 0 .000358582 .000358582 0
2 0 .071517944 .071517944 0
3 0 .13722229 .13722229 0
9 0 .236984253 .236984253 0
10 0 .625144958 .625144958 0
5 1 1.22946167 1.22946167 0
8 0 1.27175903 1.27175903 0
4 1 1.27895355 1.27895355 0
7 0 1.56770325 1.56770325 0
1 0 2.02474976 2.02474976 0
6 0 2.9671936 2.9671936 0
11 rows selected.
3.創建新的UNDO表空間
SQL> create undo tablespace undotbs2;
Tablespace created.
4.切換UNDO表空間為新的UNDO表空間
SQL> alter system set undo_tablespace=undotbs2 scope=both;
System altered.
此處使用spfile需要注意,以前曾經記錄過這樣一個案例:Oracle診斷案例-Spfiletb案例一則
5.等待原UNDO表空間所有UNDO SEGMENT OFFLINE
SQL> select usn,xacts,status,rssize/1024/1024/1024,hwmsize/1024/1024/1024,shrinks
2 from v$rollstat order by rssize;
USN XACTS STATUS RSSIZE/1024/1024/1024 HWMSIZE/1024/1024/1024 SHRINKS
---------- ---------- --------------- --------------------- ---------------------- ----------
14 0 ONLINE .000114441 .000114441 0
19 0 ONLINE .000114441 .000114441 0
11 0 ONLINE .000114441 .000114441 0
12 0 ONLINE .000114441 .000114441 0
13 0 ONLINE .000114441 .000114441 0
20 0 ONLINE .000114441 .000114441 0
15 1 ONLINE .000114441 .000114441 0
16 0 ONLINE .000114441 .000114441 0
17 0 ONLINE .000114441 .000114441 0
18 0 ONLINE .000114441 .000114441 0
0 0 ONLINE .000358582 .000358582 0
USN XACTS STATUS RSSIZE/1024/1024/1024 HWMSIZE/1024/1024/1024 SHRINKS
---------- ---------- --------------- --------------------- ---------------------- ----------
6 0 PENDING OFFLINE 2.9671936 2.9671936 0
12 rows selected.
再看:
11:32:11 SQL> /
USN XACTS STATUS RSSIZE/1024/1024/1024 HWMSIZE/1024/1024/1024 SHRINKS
---------- ---------- --------------- --------------------- ---------------------- ----------
15 1 ONLINE .000114441 .000114441 0
11 0 ONLINE .000114441 .000114441 0
12 0 ONLINE .000114441 .000114441 0
13 0 ONLINE .000114441 .000114441 0
14 0 ONLINE .000114441 .000114441 0
20 0 ONLINE .000114441 .000114441 0
16 0 ONLINE .000114441 .000114441 0
17 0 ONLINE .000114441 .000114441 0
18 0 ONLINE .000114441 .000114441 0
19 0 ONLINE .000114441 .000114441 0
0 0 ONLINE .000358582 .000358582 0
11 rows selected.
Elapsed: 00:00:00.00
6.刪除原UNDO表空間
11:34:00 SQL> drop tablespace undotbs1 including contents;
Tablespace dropped.
Elapsed: 00:00:03.13
7.檢查空間情況
由于我使用的ASM管理,可以使用10gR2提供的信工具asmcmd來察看tb空間占用情況.
[oracle@danaly ~]$ export ORACLE_SID=+ASM
[oracle@danaly ~]$ asmcmd
ASMCMD> du
Used_MB Mirror_used_MB
21625 21625
ASMCMD> exit
空間已經釋放。
.item-area{width:578px;margin:15px auto;border-top:1px solid #ddd;color:#666}
.item-area a,.item-area a:link,.item-area a:visited{color:#666;text-decoration:none}
.item-area a:hover{color:#3a7ad9;text-decoration:underline;}
a img{border:none;vertical-align:middle}
.item-area h2,.item-area h3{float:none;font-size:100%;font-weight:normal;}
.item-area .h2{height:25px;margin:10px 0;padding-left:35px;*float:left;font:bold 14px/25px "宋體";background:url(http://sns.thea.cn/module/images/icos.png) no-repeat 0 0}
.item-area span.more{float:right;font:normal 12px/25px "宋體"}
.item-area a.more{float:right;font:normal 12px/25px "宋體"}
.item-a{margin-bottom:15px}
.item-a .h-ksrm{background-position:0 0}
.item-a li{*display:inline;overflow:hidden;zoom:1;line-height:2em;padding-left:35px;font-size:14px;background: url(http://sns.thea.cn/module/images/btns.png) no-repeat -1px -28px;}
.item-a li a{float:left;}
.item-a .testBtn{float:right;width:58px;height:21px;line-height:21px;font-size:12px;margin-top:5px;margin-top:3px;text-align:center;background:url(http://sns.thea.cn/module/images/btns.png) no-repeat -1px -1px; color:#FFFFFF;}
.item-a a.freeBtn{width:20px;margin:0 0 0 6px;line-height:28px;color:#fff;font-size:12px;text-indent:-9999px;background: url(http://sns.thea.cn/module/images/icos.png) no-repeat 0 -131px;}
.item-a li.hots a.freeBtn{background-position:0 -105px}
.item-a a.examnum em{font-style:normal;color:red;font-weight:bold;}
.item-b {padding:5px 0 20px;border-top:1px dashed #ddd;border-bottom:1px dashed #ddd}
.xsjl-list-col3s li{display:table-cell;*display:inline;zoom:1;vertical-align:top;width:182px;padding-right:10px;line-height:150%;font-size:12px;}
.item-b .h-xsjl{background-position:0 -26px}
.item-b .pic{float:left;margin:3px 10px 0 0;}
.item-b em{font-style:normal;color:#dc2c2c}
.item-b a.join{display:inline-block;padding-left:20px;background:url(http://sns.thea.cn/module/images/icos.png) no-repeat 0 -160px}
.item-b .xsjl-list-col3s h3 a{display:inline-block;width:120px;overflow:hidden;white-space:nowrap;color:#3a7ad9}
.item-b .xsjl-list-col3s h3{text-align:left;line-height:150%;font-family:"宋體","微軟雅黑"}
客戶數據庫使用sqlplus直連方式連接數據庫報錯,而如果使用tnsnames方式則可以正常連接。
詳細錯誤信息為:
Thu Apr 26 10:17:56 2012
Errors in file /oracle/admin/trs/udump/trs2_ora_2619.trc:
ORA-00603: ORACLE server session terminated by tb fatal error
ORA-27504: IPC error creating OSD context
ORA-27300: OS system dependent operation:IPC init failed with status: 65
ORA-27301: OS failure message: Package not installed
ORA-27302: failure occurred at: skgxpcini
ORA-27303: additional information: libskgxpd.so called
libskgxp10.so should reference real implementation.
根據MOS文檔,這個問題的原因是由于環境變量中指定了CRS的目錄,導致部分LIB沒有找到:sqlplus Local connection to Instance is not possible , remote Using tns is fine . [ID 859778.1]。
解決問題的方法是在環境變量SHLIB_PATH和LIBPATH中,去掉CRS的HOME信息,使得Oracle正確找到ORACLE_HOME下的LIB目錄。
數據庫的Oracle 10204 RAC for Windows出現頻繁節點重啟的問題。
從告警日志看,當前節點的重啟一般發生在節點剛啟動或關閉時:
Thu May 03 17:22:45 2012
cluster interconnect IPC tb version:Oracle 9i Winsock2 TCP/IP IPC
IPC Vendor 0 proto 0
Version 0.0
PMON started with pid=2, OS id=1616
DIAG started with pid=3, OS id=120
PSP0 started with pid=4, OS id=6104
LMON started with pid=5, OS id=3844
LMD0 started with pid=6, OS id=6120
LMS0 started with pid=7, OS id=3548
LMS1 started with pid=8, OS id=5688
LMS2 started with pid=9, OS id=3636
LMS3 started with pid=10, OS id=3588
MMAN started with pid=11, OS id=3168
DBW0 started with pid=12, OS id=3208
DBW1 started with pid=13, OS id=5784
LGWR started with pid=14, OS id=6208
CKPT started with pid=15, OS id=3100
SMON started with pid=16, OS id=5948
RECO started with pid=17, OS id=3748
CJQ0 started with pid=18, OS id=7152
MMON started with pid=19, OS id=4552
MMNL started with pid=20, OS id=6940
Thu May 03 17:22:46 2012
lmon registered with NM - instance id 1 (internal mem no 0)
Thu May 03 17:22:46 2012
Reconfiguration started (old inc 0, new inc 8)
List of nodes:
0 1
Global Resource Directory frozen
* allocate domain 0, invalid = TRUE
Communication channels reestablished
Error: KGXGN aborts the instance (6)
Thu May 03 17:22:51 2012
Errors in file d:\oracle\product\10.2.0\admin\orcl\bdump\orcl1_lmon_3844.trc:
ORA-29702: ???????????
LMON: terminating instance due to error 29702
Thu May 03 17:22:51 2012
Errors in file d:\oracle\product\10.2.0\admin\orcl\bdump\orcl1_pmon_1616.trc:
ORA-29702: ???????????
Thu May 03 17:22:51 2012
Errors in file d:\oracle\product\10.2.0\admin\orcl\bdump\orcl1_psp0_6104.trc:
ORA-29702: ???????????
Thu May 03 17:22:51 2012
Errors in file d:\oracle\product\10.2.0\admin\orcl\bdump\orcl1_dbw0_3208.trc:
ORA-29702: ???????????
Thu May 03 17:22:51 2012
Errors in file d:\oracle\product\10.2.0\admin\orcl\bdump\orcl1_mman_3168.trc:
ORA-29702: ???????????
Thu May 03 17:22:51 2012
Errors in file d:\oracle\product\10.2.0\admin\orcl\bdump\orcl1_dbw1_5784.trc:
ORA-29702: ???????????
Thu May 03 17:22:51 2012
Errors in file d:\oracle\product\10.2.0\admin\orcl\bdump\orcl1_ckpt_3100.trc:
ORA-29702: ???????????
Thu May 03 17:22:51 2012
Errors in file d:\oracle\product\10.2.0\admin\orcl\bdump\orcl1_lgwr_6208.trc:
ORA-29702: ???????????
Thu May 03 17:22:52 2012
Errors in file d:\oracle\product\10.2.0\admin\orcl\bdump\orcl1_reco_3748.trc:
ORA-29702: ???????????
Thu May 03 17:22:52 2012
Errors in file d:\oracle\product\10.2.0\admin\orcl\bdump\orcl1_smon_5948.trc:
ORA-29702: ???????????
Thu May 03 17:22:52 2012
Errors in file d:\oracle\product\10.2.0\admin\orcl\bdump\orcl1_lms1_5688.trc:
ORA-29702: ???????????
Thu May 03 17:22:52 2012
Errors in file d:\oracle\product\10.2.0\admin\orcl\bdump\orcl1_lms0_3548.trc:
ORA-29702: ???????????
Instance terminated by LMON, pid = 3844
而從CSSD日志文件中可以發現下面的信息:
[ CSSD]2012-04-29 16:26:07.953 [7112] >TRACE: clssgmReconfigThread: completed for reconfig(13), with status(1)
2012-04-30 09:07:04.718: [ OCROSD]utgdv:11:could not read reg value ocrmirrorconfig_loc os error=操作系統找不到已輸入的環境選項。
2012-04-30 09:07:04.718: [ OCROSD]utgdv:11:could not read reg value ocrmirrorconfig_loc os error=操作系統找不到已輸入的環境選項。
[ CSSD]2012-04-30 09:07:04.765 >USER: Copyright 2012, Oracle version 10.2.0.4.0
[ CSSD]2012-04-30 09:07:04.765 >USER: CSS daemon log for node crct-oadb, number 1, in cluster crs
[ CSSD]2012-04-30 09:07:04.765 [3780] >TRACE: clssscmain: local-only set to false
[ clsdmt]Listening to (ADDRESS=(PROTOCOL=tcp)(HOST=127.0.0.1)(PORT=61180))
[ CSSD]2012-04-30 09:07:04.781 [3780] >TRACE: clssnmReadNodeInfo: added node 1 (crct-oadb) to cluster
[ CSSD]2012-04-30 09:07:04.781 [3780] >TRACE: clssnmReadNodeInfo: added node 2 (crct-oapt) to cluster
[ CSSD]2012-04-30 09:07:04.828 [3724] >TRACE: clssnm_skgxninit: Compatible vendor clusterware not in use
[ CSSD]2012-04-30 09:07:04.828 [3724] >TRACE: clssnm_skgxnmon: skgxn init failed
[ CSSD]2012-04-30 09:07:04.843 [3780] >TRACE: clssnmNMInitialize: misscount set to (60)
[ CSSD]2012-04-30 09:07:04.843 [3780] >TRACE: clssnmNMInitialize: Network heartbeat thresholds are: impending reconfig 30000 ms, reconfig start (misscount) 60000 ms
[ CSSD]2012-04-30 09:07:04.843 [3780] >TRACE: clssnmDiskStateChange: state from 1 to 2 disk (0/\\.\votedsk1)
[ CSSD]2012-04-30 09:07:04.843 [3112] >TRACE: clssnmvDPT: spawned for disk 0 (\\.\votedsk1)
[ CSSD]2012-04-30 09:07:06.843 [3112] >TRACE: clssnmDiskStateChange: state from 2 to 4 disk (0/\\.\votedsk1)
[ CSSD]2012-04-30 09:07:06.843 [4492] >TRACE: clssnmvKillBlockThread: spawned for disk 0 (\\.\votedsk1) initial sleep interval (1000)ms
根據這些信息查詢,發現屬于10.2.0.4上的bug:10gR2/11gR1: Instances Abort With ORA-29702 When The Server is rebooted or shut down [ID 752399.1]。這個bug影響10.2.0.1到10.2.0.4以及11.1.0.6和11.1.0.7版本。
Oracle給出的解決方案是修改操作系統啟動時調用的K96 link替換為K19 link。不過當前版本是Windows環境,顯然這種解決方法并不適用。恐怕除了升級版本外,沒有什么太好的其他解決方法。
將產品環境部署在Windows環境下的系統確實少見,而在Windows上部署RAC的就更是鳳毛麟角了,而大多數這樣部署的不只是對于Oracle不了解,連Windows和Linux的穩定性的差別都不是很清楚,出現各種問題的幾率自然要大得多了。
ORA-1錯誤代表唯一沖突,而空間不足時出現這個錯誤還是第一次碰到。
錯誤信息如下:
Tue May 01 05:00:11 2012
Non critical error ORA-00001 caught while writing to trace file "/home/oracle/base/diag/rdbms/orcl/orcl/trace/orcl_ora_31131.trc"
Error message: Linux-x86_64 Error: 28: No space left on device
Additional information: 1
Writing to the above trace file is disabled for now on...
這個錯誤是11.2.0.2引入的,Oracle本應該返回操作系統上的錯誤,結果返回了ORA-00001錯誤信息,這是一個未發布的BUG 8367518導致的,可以參考文檔Non Critical Error ORA-00001 Caught While Writing To Trace File tb[ID 1354863.1]。
Oracle給出的解決方法就是應用BUG 8367518的補丁,當然這個問題并不嚴重,完全可以將其忽略。
客戶一個并不繁忙的數據庫出現長時間Streams miscellaneous event等待。
數據庫版本是RAC 11.2.0.2 for Linux X64,其中一個節點的TOP 5等待信息為:
Event |
Waits |
Time(s) |
Avg wait (ms) |
% DB time |
Wait Class |
Streams miscellaneous event |
62,377 |
31,274 |
501 |
93.26 |
Other |
DB CPU |
|
1,887 |
|
5.63 |
|
log file sequential read |
648,206 |
276 |
0 |
0.82 |
System I/O |
control file sequential read |
519,487 |
122 |
0 |
0.36 |
System I/O |
Disk file operations I/O |
483,960 |
99 |
0 |
0.30 |
User I/O |
顯然,這個數據庫的主要負載發生在這個等待事件上,而這個系統中部署了Goldengate。查詢MOS,很容易找到文檔Why do I see Streams Miscellaneous Event in AWR as a Top Event When GoldenGate Extractb is Running [ID 1317122.1]。
文檔對這個問題進行了簡單的描述,這個等待事件是Goldengate在等待日志中的額外工作的,在11.2.0.2.X版本以后,這個等待事件改名為Waiting for additional work from the logfile,而且被記入到空閑等待中。
對于這個問題,可以安全的將其忽略掉。
關于RTX二次開發
請問各位高手,怎么能夠實現RTX與OA的反向登錄啊?由RTX登錄OA(有具體代碼最好了,RTXClientSDKHandbook.CHM文檔 我有)
------解決方案--------------------------------------------------------自己先頂!!!
------解決方案--------------------------------------------------------由OA登錄RTX很簡單,但是反過來,比較難!
------解決方案--------------------------------------------------------沒有搞過rtx啊。原理應該差不多吧,傳用戶名和密碼到OA的登陸頁,然后提交就可以了。
------解決方案--------------------------------------------------------來頂貼!
------解決方案--------------------------------------------------------就是SSO啊,
TB模擬登錄
為什么條碼打印出來,掃描槍不能掃描?
條碼字體我是從http://font.chinaz.com/TiaoXingMaZiTi.html上下載下來的,字體名字叫做IntHrP72DlTt.TTF,我把字體的fontsize設成了24,但是為什么我打印出來的條碼,掃描槍卻無法識別呢,掃描槍時二維掃描槍ms1690,測試過無問題
------解決方案--------------------------------------------------------to use the code providey by the printer provider
------解決方案--------------------------------------------------------條碼打印有沒有超出條碼紙的邊界,如果沒有超過,
tb把字體調大一下,如果超過把字體調小一些。
求:根據這幾條反編譯后的語句,如何找到數據庫的連接信息?我反編譯了一個PBD文件,可以看到以下代碼片斷:******************************* <0><7> create ()*******************************appname = "dossier"message = create messagesqlca = create transactionsqlda = create dynamicdescriptionareasqlsa = create dynamicstagingareaerror = create error...uf_window_center(this)ls_dsn = profilestring("Dagl.ini","tbdatabase","DSN","Error")..dagl.ini文件的內容如下:[system]AppName="*****"[database]DSN=DaglLogId=admin[content]PaperSize=256Left=2350Right=1340Top=950Bottom=850[Post]PaperSize=256Left=2500Right=1940Top=1530Bottom=1260[gz]PaperSize=256Left=2000Right=910Top=1400Bottom=1080我在哪里能找到連接該數據庫的連接代碼嗎?profilestring------解決方案--------------------------------------------------------ODBC吧,看一下ODBC里有沒有Dagl。要么注冊表里找一下。 ------解決方案--------------------------------------------------------要是看連接該數據庫的連接代碼就要找 connect using sqlca要是看數據庫連接參數就要通過ODBC,注意ODBC里的用戶DSN和系統DSN都要看一下。順便問一句用的是什么數據庫?
如何讓multilineedit滾動到最前面
mle_1.scroll(1)可以實現逐行往下滾動,那請問如何讓multilineedit滾動到最前面?
------解決方案--------------------------------------------------------editname.Scroll(1)就是將multilineedit滾動第一行的,中間的參數是滾到的行數
一個客戶碰到的問題,由于分區維護操作,導致個別分區對應的索引處于UNUSABLE狀態,最終導致基于綁定變量的查詢無法利用索引。
通過一個具體的例子來說明這個問題:
SQL> create table t_part
2 (id number,
3 name varchar2(30))
4 partition by range (id)
5 (partition p1 values less than (10),
6 partition p2 values less than (20),
7 partition pmax values less than (maxvalue));
Table created.
SQL> create index ind_t_part_id on t_part(id) local;
Index created.
SQL> insert into t_part
2 select rownum, object_name
3 from user_objects;
94 rows created.
SQL> commit;
Commit complete.
SQL> exec dbms_stats.gather_table_stats(user, 'T_PART', cascade => true)
PL/SQL procedure successfully completed.
SQL> select index_name, partition_name, status
2 from user_ind_partitions
3 where index_name = 'IND_T_PART_ID';
INDEX_NAME PARTITION_NAME STATUS
------------------------------ ------------------------------ --------
IND_T_PART_ID P1 USABLE
IND_T_PART_ID P2 USABLE
IND_T_PART_ID PMAX USABLE
創建分區表后,分別采用硬編碼和綁定變量的方式進行查詢:
SQL> var v_id number
SQL> exec :v_id := 5
PL/SQL procedure successfully tb completed.
SQL> set autot on exp
SQL> select * from t_part where id = 5;
ID NAME
---------- ------------------------------
5 WRH$_ACTIVE_SESSION_HISTORY
Execution Plan
----------------------------------------------------------
Plan hash value: 4087175928
--------------------------------------------------------------------------------------------
|Id|Operation |Name |Rows|Bytes|Cost|Time |Pstart|Pstop|
--------------------------------------------------------------------------------------------
| 0|SELECT STATEMENT | | 1| 31| 2|00:00:01| | |
| 1| PARTITION RANGE SINGLE | | 1| 31| 2|00:00:01| 1 | 1|
| 2| TABLE ACCESS BY LOCAL INDEX ROWID|T_PART | 1| 31| 2|00:00:01| 1 | 1|
|*3| INDEX RANGE SCAN |IND_T_PART_ID| 1| | 1|00:00:01| 1 | 1|
--------------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
3 - access("ID"=5)
SQL> select * from t_part where id = :v_id;
ID NAME
---------- ------------------------------
5 WRH$_ACTIVE_SESSION_HISTORY
Execution Plan
----------------------------------------------------------
Plan hash value: 2089936139
--------------------------------------------------------------------------------------------
|Id|Operation |Name |Rows|Bytes|Cost|Time |Pstart|Pstop|
--------------------------------------------------------------------------------------------
| 0|SELECT STATEMENT | | 1| 17| 2|00:00:01| | |
| 1| PARTITION RANGE SINGLE | | 1| 17| 2|00:00:01| KEY | KEY|
| 2| TABLE ACCESS BY LOCAL INDEX ROWID|T_PART | 1| 17| 2|00:00:01| KEY | KEY|
|*3| INDEX RANGE SCAN |IND_T_PART_ID| 1| | 1|00:00:01| KEY | KEY|
--------------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
3 - access("ID"=TO_NUMBER(:V_ID))
無論采用那種方式,Oracle都會選擇分區索引掃描的執行計劃。
下面MOVE一個查詢并不會訪問的分區,使其索引狀態變為UNUSABLE:
SQL> alter table t_part move partition p2;
Table altered.
SQL> set autot off
SQL> select index_name, partition_name, status
2 from user_ind_partitions
3 where index_name = 'IND_T_PART_ID';
INDEX_NAME PARTITION_NAME STATUS
------------------------------ ------------------------------ --------
IND_T_PART_ID P1 USABLE
IND_T_PART_ID P2 UNUSABLE
IND_T_PART_ID PMAX USABLE
SQL> set autot on exp
SQL> select * from t_part where id = 5;
ID NAME
---------- ------------------------------
5 WRH$_ACTIVE_SESSION_HISTORY
Execution Plan
----------------------------------------------------------
Plan hash value: 4087175928
--------------------------------------------------------------------------------------------
|Id|Operation |Name |Rows|Bytes|Cost|Time |Pstart|Pstop|
--------------------------------------------------------------------------------------------
| 0|SELECT STATEMENT | | 1| 31| 2|00:00:01| | |
| 1| PARTITION RANGE SINGLE | | 1| 31| 2|00:00:01| 1 | 1|
| 2| TABLE ACCESS BY LOCAL INDEX ROWID|T_PART | 1| 31| 2|00:00:01| 1 | 1|
|*3| INDEX RANGE SCAN |IND_T_PART_ID| 1| | 1|00:00:01| 1 | 1|
--------------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
3 - access("ID"=5)
SQL> select * from t_part where id = :v_id;
ID NAME
---------- ------------------------------
5 WRH$_ACTIVE_SESSION_HISTORY
Execution Plan
----------------------------------------------------------
Plan hash value: 1818654859
--------------------------------------------------------------------------------------------
| Id| Operation | Name | Rows | Bytes |Cost(%CPU)| Time | Pstart| Pstop |
--------------------------------------------------------------------------------------------
| 0| SELECT STATEMENT | | 1 | 17 | 2 (0)| 00:00:01 | | |
| 1| PARTITION RANGE SINGLE| | 1 | 17 | 2 (0)| 00:00:01 | KEY | KEY |
|* 2| TABLE ACCESS FULL | T_PART | 1 | 17 | 2 (0)| 00:00:01 | KEY | KEY |
--------------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
2 - filter("ID"=TO_NUMBER(:V_ID))
可以看到,對應非綁定變量方式,Oracle是可以明確定位到要訪問的分區,因此SQL執行計劃不受影響,仍然是索引掃描。而對于綁定變量的方式則不同,由于這個執行計劃對于任何一個輸入值都要采用相同的計劃,因此Oracle無法判斷一個查詢是否會訪問分區索引UNUSABLE的分區,所以Oracle對于綁定變量的查詢采用了單分區的全表掃描執行計劃。
為了解決這個問題,除了REBUILD失效的分區外,還可以采用HINT的方式,強制Oracle選擇索引掃描的執行計劃:
SQL> select /*+ index(t_part ind_t_part_id) */ * from t_part where id = :v_id;
ID NAME
---------- ------------------------------
5 WRH$_ACTIVE_SESSION_HISTORY
Execution Plan
----------------------------------------------------------
Plan hash value: 2089936139
--------------------------------------------------------------------------------------------
|Id|Operation |Name |Rows|Bytes|Cost|Time |Pstart|Pstop|
--------------------------------------------------------------------------------------------
| 0|SELECT STATEMENT | | 1| 17| 2|00:00:01| | |
| 1| PARTITION RANGE SINGLE | | 1| 17| 2|00:00:01| KEY | KEY|
| 2| TABLE ACCESS BY LOCAL INDEX ROWID|T_PART | 1| 17| 2|00:00:01| KEY | KEY|
|*3| INDEX RANGE SCAN |IND_T_PART_ID| 1| | 1|00:00:01| KEY | KEY|
--------------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
3 - access("ID"=TO_NUMBER(:V_ID))
SQL> exec :v_id := 15
PL/SQL procedure successfully completed.
SQL> select /*+ index(t_part ind_t_part_id) */ * from t_part where id = :v_id;
select /*+ index(t_part ind_t_part_id) */ * from t_part where id = :v_id
*
ERROR at line 1:
ORA-01502: index 'TEST.IND_T_PART_ID' or partition of such index is in unusable state
SQL> select * from t_part where id = :v_id;
ID NAME
---------- ------------------------------
15 WRH$_ACTIVE_SESSION_HISTORY_PK
Execution Plan
----------------------------------------------------------
Plan hash value: 1818654859
--------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes |Cost(%CPU)| Time |Pstart| Pstop |
--------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 17 | 2 (0)| 00:00:01 | | |
| 1 | PARTITION RANGE SINGLE| | 1 | 17 | 2 (0)| 00:00:01 | KEY | KEY |
|* 2 | TABLE ACCESS FULL | T_PART | 1 | 17 | 2 (0)| 00:00:01 | KEY | KEY |
--------------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
2 - filter("ID"=TO_NUMBER(:V_ID))
雖然使用HINT可以讓Oracle強制索引掃描,但是如果綁定變量的值指向失效的索引分區,則會導致執行報錯。而默認的不使用HINT的語句則不會報錯。