【檢視】利用USER_TAB_MODIFICATIONS檢視輔助監控表的增刪改等操作
因為該檢視中記錄的資訊會因表的分析自動清除,同時Oracle從效能上考慮並沒有保證這個檢視與表的操作實時保持一致,有一定的滯後,因此其中記錄的資訊僅可用於參考之目的。
在早期Oracle版本中,若要啟用這個功能需要使用“alter table t monitoring;”語句使表具有monitoring屬性。到了Oracle 10g時代,該功能已是預設行為,這主要歸功於STATISTICS_LEVEL引數,該引數共有三種取值(STATISTICS_LEVEL = { ALL | TYPICAL | BASIC }),當其值是“TYPICAL”或“ALL”時該功能就會生效,因其預設值是“TYPICAL”所以該功能預設被啟用。
這裡,我透過實驗給大家展示一下這個功能,並提出一點注意事項,供大家參考。
1.建立實驗表T
sec@ora10g> create table t (x int);
Table created.
2.向表T中插入一條記錄,注意這裡我們先不提交。
sec@ora10g> insert into t values (6);
1 row created.
3.嘗試查詢USER_TAB_MODIFICATIONS檢視
sec@ora10g> select TABLE_NAME,INSERTS,UPDATES,DELETES,TIMESTAMP from user_tab_modifications;
no rows selected
此時是沒有結果的,因為我們剛剛完成插入操作,維護到這個檢視是需要一段時間的。
4.如何縮短這個等待的過程呢?
執行DBMS_STATS.FLUSH_DATABASE_MONITORING_INFO這個儲存過程可以瞬間得到結果。
1)執行儲存過程
注意,在普通使用者中想要執行這個儲存過程,需要被授予“analyze any”的系統許可權
sec@ora10g> exec DBMS_STATS.FLUSH_DATABASE_MONITORING_INFO;
BEGIN DBMS_STATS.FLUSH_DATABASE_MONITORING_INFO; END;
*
ERROR at line 1:
ORA-20000: Insufficient privileges
ORA-06512: at "SYS.DBMS_STATS", line 2148
ORA-06512: at "SYS.DBMS_STATS", line 14135
ORA-06512: at line 1
sec@ora10g> conn / as sysdba
Connected.
sys@ora10g> grant analyze any to sec;
Grant succeeded.
sys@ora10g> conn sec/sec
Connected.
sec@ora10g> exec DBMS_STATS.FLUSH_DATABASE_MONITORING_INFO;
PL/SQL procedure successfully completed.
2)此時已經可以得到查詢結果,結果顯示T表在“2009-12-01 20:01:06”時被插入了一條記錄。
sec@ora10g> select TABLE_NAME,INSERTS,UPDATES,DELETES,TIMESTAMP from user_tab_modifications;
TABLE_NAME INSERTS UPDATES DELETES TIMESTAMP
---------- ------- ------- ------- -------------------
T 1 0 0 2009-12-01 20:01:06
5.這裡要特別注意一點:在執行完FLUSH_DATABASE_MONITORING_INFO儲存過程之後,所有之前的操作都將被提交!
驗證如下
1)檢視錶T中的資料
sec@ora10g> select * from t;
X
----------
6
2)嘗試回滾(之前沒有進行過提交和回滾操作)
sec@ora10g> rollback;
Rollback complete.
3)此時發現,即使顯式回滾也無濟於事,插入操作已經被提交。
sec@ora10g> select * from t;
X
----------
6
4)USER_TAB_MODIFICATIONS檢視中的記錄也被保留了下來
sec@ora10g> select TABLE_NAME,INSERTS,UPDATES,DELETES,TIMESTAMP from user_tab_modifications;
TABLE_NAME INSERTS UPDATES DELETES TIMESTAMP
---------- ------- ------- ------- -------------------
T 1 0 0 2009-12-01 20:01:06
6.再來驗證一下表被分析之後的效果
1)分析前
sec@ora10g> select TABLE_NAME,INSERTS,UPDATES,DELETES,TIMESTAMP from user_tab_modifications;
TABLE_NAME INSERTS UPDATES DELETES TIMESTAMP
---------- ------- ------- ------- -------------------
T 1 0 0 2009-12-01 20:01:06
2)分析中
sec@ora10g> analyze table t compute statistics;
Table analyzed.
3)分析後
sec@ora10g> select TABLE_NAME,INSERTS,UPDATES,DELETES,TIMESTAMP from user_tab_modifications;
no rows selected
實驗結論得證。
7.摘錄一些10gR2官方文件資料供參考
STATISTICS_LEVEL
Property | Description |
---|---|
Parameter type | String |
Syntax | STATISTICS_LEVEL = { ALL | TYPICAL | BASIC } |
Default value | TYPICAL |
Modifiable | ALTER SESSION, ALTER SYSTEM |
STATISTICS_LEVEL specifies the level of collection for database and operating system statistics. The Oracle Database collects these statistics for a variety of purposes, including making self-management decisions.
The default setting of TYPICAL ensures collection of all major statistics required for database self-management functionality and provides best overall performance. The default value should be adequate for most environments.
When the STATISTICS_LEVEL parameter is set to ALL, additional statistics are added to the set of statistics collected with the TYPICAL setting. The additional statistics are timed OS statistics and plan execution statistics.
Setting the STATISTICS_LEVEL parameter to BASIC disables the collection of many of the important statistics required by Oracle Database features and functionality, including:
-
Automatic Workload Repository (AWR) Snapshots
-
Automatic Database Diagnostic Monitor (ADDM)
-
All server-generated alerts
-
Automatic SGA Memory Management
-
Automatic optimizer statistics collection
-
Object level statistics
-
End to End Application Tracing (V$CLIENT_STATS)
-
Database time distribution statistics (V$SESS_TIME_MODEL and V$SYS_TIME_MODEL)
-
Service level statistics
-
Buffer cache advisory
-
MTTR advisory
-
Shared pool sizing advisory
-
Segment level statistics
-
PGA Target advisory
-
Timed statistics
-
Monitoring of statistics
Note:
Oracle strongly recommends that you do not disable these important features and functionality.When the STATISTICS_LEVEL parameter is modified by ALTER SYSTEM, all advisories or statistics are dynamically turned on or off, depending on the new value of STATISTICS_LEVEL. When modified by ALTER SESSION, the following advisories or statistics are turned on or off in the local session only. Their system-wide state is not changed:
-
Timed statistics
-
Timed OS statistics
-
Plan execution statistics
The V$STATISTICS_LEVEL view displays information about the status of the statistics or advisories controlled by the STATISTICS_LEVEL parameter. See .
USER_TAB_MODIFICATIONS
USER_TAB_MODIFICATIONS describes modifications to all tables owned by the current user that have been modified since the last time statistics were gathered on the tables. Its columns are the same as those in .
Note:
This view is populated only for tables with the MONITORING attribute. It is intended for statistics collection over a long period of time. For performance reasons, the Oracle Database does not populate this view immediately when the actual modifications occur. Run the FLUSH_DATABASE_MONITORING_INFO procedure in the DIMS_STATS PL/SQL package to populate this view with the latest information. The ANALYZE_ANY system privilege is required to run this procedure.8.小結
USER_TAB_MODIFICATIONS檢視在Oracle的不同版本中也在不斷的做著細微的調整和最佳化,Oracle的細節之處無處不在。
從此我們又多了一條瞭解資料庫執行狀況的手段。
Good luck.
secooler
09.12.01
-- The End --
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/519536/viewspace-621109/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- Odoo禁止Tree、Form檢視增刪改編輯OdooORM
- Redis Manager 如何檢視監控Redis
- Oracle“並行執行”——監控檢視Oracle並行
- Android studio增刪改查尚未全部完成時如何檢視資料庫Android資料庫
- 檢視鎖表
- 車間操作檢視
- 檢視oracle臨時表空間佔用率的檢視Oracle
- Git檢視本地幫助文件Git
- 如何把SQL Server中一個表,一個儲存過程,一個檢視等改為系統表,系統儲存過程,系統檢視等...SQLServer儲存過程
- 11 UML中的邏輯檢視、程序檢視、實現檢視、部署檢視
- Linux基楚操作指引【檢視版本、檢視路徑、檢視內容、編輯檔案】Linux
- VUE檢視常規操作Vue
- linux伺服器檢視監控頻寬的幾個工具Linux伺服器
- abp(net core)+easyui+efcore實現倉儲管理系統——展現層實現增刪改查之增刪改檢視(八)UI
- 檢視歸檔暴增的原因
- windows10怎麼檢視監聽埠_windows10檢視監聽埠的方法Windows
- firewalld:檢視版本/幫助/狀態
- Python檢視模組幫助/文件Python
- win10系統如何檢視自己電腦有沒有被監控_win10怎麼檢視自己電腦是否被監控Win10
- ASP.NET Core 5.0 MVC中的檢視分類——佈局檢視、啟動檢視、具體檢視、分部檢視ASP.NETMVC
- Postgresql系統表/檢視SQL
- 將檢視轉為表
- postgresql如何檢視所有表SQL
- [Django REST framework - 檢視元件之檢視基類、檢視擴充套件類、檢視子類、檢視集]DjangoRESTFramework元件套件
- MySQL檢視簡介與操作MySql
- 0x05. 檢視操作
- mybatis中的增刪改操作MyBatis
- Oracle 檢視可以DML操作的條件Oracle
- Dock視窗輔助增強工具:HyperDock for Mac中文版Mac
- oracle db link的檢視建立與刪除Oracle
- MongoDB增刪改查操作MongoDB
- 電腦配置的三種檢視方法 不用藉助軟體怎麼檢視電腦配置
- win10系統怎麼利用事件檢視器檢視最近的事件活動Win10事件
- MySQL檢視建表語句MySql
- Oracle普通檢視和物化檢視的區別Oracle
- 14、flask-模型-models-表的操作-增刪改查Flask模型
- QT: 操作主從檢視及XMLQTXML
- laravel利用artisan建立view檢視檔案LaravelView
- 【轉】改變檢視頁面原始碼的程式原始碼