【實驗】【analyze】分析特定使用者的表和索引
1.使用analyze方法對特定使用者的表和索引進行分析指令碼如下
ora10g@testdb183 /home/oracle$ cat analyze_schema.sql
set pagesize 6000
set heading off
spool analytab.sql
select 'analyze table '||table_name||' estimate statistics sample 20 percent;' from user_tables;
spool off
spool analyind.sql
select 'analyze table '||table_name||' estimate statistics sample 20 percent for all indexes;' from user_tables;
spool off
spool analyze.log
@analytab.sql
@analyind.sql
spool off
2.使用方法,進入到sqlplus介面
ora10g@testdb183 /home/oracle$ sqlplus / as sysdba
SQL*Plus: Release 10.2.0.3.0 - Production on Sat Aug 29 20:16:29 2009
Copyright (c) 1982, 2006, Oracle. All Rights Reserved.
Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - 64bit Production
With the Partitioning, Oracle Label Security, OLAP and Data Mining Scoring Engine options
3.連線到待分析的使用者,這裡是sec使用者
sys@ora10g> conn sec/sec
Connected.
4.使用“@”符號呼叫上面的analyze_schema.sql指令碼,執行過程如下(這個使用者下只有兩張表)
sec@ora10g> @analyze_schema.sql
analyze table T_PARENT estimate statistics sample 20 percent;
analyze table T_CHILD estimate statistics sample 20 percent;
analyze table T_PARENT estimate statistics sample 20 percent for all indexes;
analyze table T_CHILD estimate statistics sample 20 percent for all indexes;
Table analyzed.
Table analyzed.
Table analyzed.
Table analyzed.
sec@ora10g>
5.上面的指令碼使用的是analyze方法進行分析的,analyze方法不支援“並行”操作,下面演示一下使用dbms_stats.gather_schema_stats方法使用4並行對sec使用者的10%資料進行分析的過程。
sec@ora10g> exec dbms_stats.gather_schema_stats(OWNNAME=>'SEC',ESTIMATE_PERCENT=>10,DEGREE=>4,cascade=>true);
PL/SQL procedure successfully completed.
如果想對SEC使用者中所有表使用DBMS_STATS.GATHER_TABLE_STATS方法進行分析,可以參考如下我寫的一個語句(所有能節省DBA寶貴時間的嘗試都應該被鼓勵):
SET lin 300
SET head off
SELECT 'execute DBMS_STATS.GATHER_TABLE_STATS(ownname=>'
|| ''''
|| owner
|| ''''
|| ',tabname=>'
|| ''''
|| table_name
|| ''''
|| ',method_opt=>'
|| ''''
|| 'FOR ALL COLUMNS SIZE 254'
|| ''''
|| ',DEGREE=>4,cascade=>true);'
FROM dba_tables
WHERE dba_tables.owner = 'SEC';
6.小結
對錶和索引的定期分析有利於Oracle的CBO得到正確的執行計劃,提高系統的效能。是DBA日常維護中必做的內容。
analyze和dbms_stats兩種方法都可以完成分析的任務,如果在資源可用,並且待分析資料較大的情況下可以考慮使用dbms_stats加並行的方法進行處理。
上面只是演示了一種非常簡單的用法,更多的analyze方法請參考Oracle官方文件《ANALYZE》
更多的DBMS_STATS方法,請參考Oracle官方文件《103 DBMS_STATS》http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14258/d_stats.htm#CIHBIEII
-- The End --
ora10g@testdb183 /home/oracle$ cat analyze_schema.sql
set pagesize 6000
set heading off
spool analytab.sql
select 'analyze table '||table_name||' estimate statistics sample 20 percent;' from user_tables;
spool off
spool analyind.sql
select 'analyze table '||table_name||' estimate statistics sample 20 percent for all indexes;' from user_tables;
spool off
spool analyze.log
@analytab.sql
@analyind.sql
spool off
2.使用方法,進入到sqlplus介面
ora10g@testdb183 /home/oracle$ sqlplus / as sysdba
SQL*Plus: Release 10.2.0.3.0 - Production on Sat Aug 29 20:16:29 2009
Copyright (c) 1982, 2006, Oracle. All Rights Reserved.
Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - 64bit Production
With the Partitioning, Oracle Label Security, OLAP and Data Mining Scoring Engine options
3.連線到待分析的使用者,這裡是sec使用者
sys@ora10g> conn sec/sec
Connected.
4.使用“@”符號呼叫上面的analyze_schema.sql指令碼,執行過程如下(這個使用者下只有兩張表)
sec@ora10g> @analyze_schema.sql
analyze table T_PARENT estimate statistics sample 20 percent;
analyze table T_CHILD estimate statistics sample 20 percent;
analyze table T_PARENT estimate statistics sample 20 percent for all indexes;
analyze table T_CHILD estimate statistics sample 20 percent for all indexes;
Table analyzed.
Table analyzed.
Table analyzed.
Table analyzed.
sec@ora10g>
5.上面的指令碼使用的是analyze方法進行分析的,analyze方法不支援“並行”操作,下面演示一下使用dbms_stats.gather_schema_stats方法使用4並行對sec使用者的10%資料進行分析的過程。
sec@ora10g> exec dbms_stats.gather_schema_stats(OWNNAME=>'SEC',ESTIMATE_PERCENT=>10,DEGREE=>4,cascade=>true);
PL/SQL procedure successfully completed.
如果想對SEC使用者中所有表使用DBMS_STATS.GATHER_TABLE_STATS方法進行分析,可以參考如下我寫的一個語句(所有能節省DBA寶貴時間的嘗試都應該被鼓勵):
SET lin 300
SET head off
SELECT 'execute DBMS_STATS.GATHER_TABLE_STATS(ownname=>'
|| ''''
|| owner
|| ''''
|| ',tabname=>'
|| ''''
|| table_name
|| ''''
|| ',method_opt=>'
|| ''''
|| 'FOR ALL COLUMNS SIZE 254'
|| ''''
|| ',DEGREE=>4,cascade=>true);'
FROM dba_tables
WHERE dba_tables.owner = 'SEC';
6.小結
對錶和索引的定期分析有利於Oracle的CBO得到正確的執行計劃,提高系統的效能。是DBA日常維護中必做的內容。
analyze和dbms_stats兩種方法都可以完成分析的任務,如果在資源可用,並且待分析資料較大的情況下可以考慮使用dbms_stats加並行的方法進行處理。
上面只是演示了一種非常簡單的用法,更多的analyze方法請參考Oracle官方文件《ANALYZE》
更多的DBMS_STATS方法,請參考Oracle官方文件《103 DBMS_STATS》http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14258/d_stats.htm#CIHBIEII
-- The End --
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/519536/viewspace-613551/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- ANALYZE導致的阻塞問題分析
- OPA-Gatekeeper實驗:對特定使用者的更新時間視窗做限制
- 【DSL】Elasticsearch之Analyze(分析過程)Elasticsearch
- MySQL管理表和索引MySql索引
- 自動生成特定領域模型和圖表模型
- Sqlserver表和索引壓縮SQLServer索引
- IP和TCP抓包分析實驗TCP
- 索引表和 ES 的一點點思考索引
- exp匯出表中特定條件的表
- UserService 新增使用者關聯索引 addUserPermission 分析索引
- 使用 nuxi analyze 命令分析 Nuxt 應用的生產包UX
- 移動分割槽表和分割槽索引的表空間索引
- MySQL的索引分析MySql索引
- easyExcel多行表頭設定不同樣式和特定單元格設定樣式的實現Excel
- ORA-01658建立表或索引報錯分析索引
- 堆和索引堆的python實現索引Python
- 從InnoDB 索引執行簡述 聚集索引和非聚集索引、覆蓋索引、回表、索引下推索引
- MySQL全面瓦解22:索引的介紹和原理分析MySql索引
- 最常見網路和使用者體驗問題的根本原因分析
- MySQL的索引型別和實現原理MySql索引型別
- 全表掃描和全索引掃描索引
- MySQL中的全表掃描和索引樹掃描MySql索引
- MySQL實戰45講——普通索引和唯一索引MySql索引
- UserService 查詢使用者有許可權的關聯索引 queryIndexPatternByUserName分析索引Index
- 實驗二-需求分析
- 實驗二:需求分析
- 實驗2:需求分析
- [20210112]ashtop查詢特定表的SQL語句.txtSQL
- Analyze table對Oracle效能的提升Oracle
- 關於 PHP - ML 使用者習慣分析 Laravel 實驗程式碼整理PHPLaravel
- 關於InnoDB表資料和索引資料的儲存索引
- SQL歷理 ICbA的使用者表和公式表的構思SQL公式
- 主鍵索引 (聚集索引) 和普通索引 (輔助索引) 的區別索引
- 66_索引管理_複雜上機實驗:基於scoll+bulk+索引別名實現零停機重建索引索引
- mongodb建立索引和刪除索引和背景索引backgroundMongoDB索引
- 唯一索引和普通索引的選擇索引
- 淺析InnoDB引擎的索引和索引原理索引
- MySQL的索引優化分析(一)MySql索引優化
- MySQL的索引優化分析(二)MySql索引優化