【檢視】利用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
- 在SQL Server中對檢視進行增刪改SQLServer
- Redis Manager 如何檢視監控Redis
- Oracle“並行執行”——監控檢視Oracle並行
- oracle 監控 DML DDL 鎖 的4個檢視Oracle
- 利用日誌挖掘 oracle 不完全恢復 恢復誤刪除的表/資料/檢視等Oracle
- 車間操作檢視
- oracle檢視基本操作Oracle
- 物化檢視妙用__表同步使用物化檢視方法
- 檢視oracle臨時表空間佔用率的檢視Oracle
- 備份相關的動態效能檢視及監控
- 如何把SQL Server中一個表,一個儲存過程,一個檢視等改為系統表,系統儲存過程,系統檢視等...SQLServer儲存過程
- 檢視歸檔暴增的原因
- abp(net core)+easyui+efcore實現倉儲管理系統——展現層實現增刪改查之增刪改檢視(八)UI
- MySQL資料庫檢視:檢視定義、建立檢視、修改檢視MySql資料庫
- VUE檢視常規操作Vue
- 表的建立修改及增刪改查-DML操作
- 使用user_tab_modifications檢視業務運算元據庫記錄
- 利用tkprof檢視trace檔案
- 檢視和表的區別
- windows10怎麼檢視監聽埠_windows10檢視監聽埠的方法Windows
- Linux基楚操作指引【檢視版本、檢視路徑、檢視內容、編輯檔案】Linux
- 利用AUDIT檢視資料庫表結構變化資料庫
- ●linux程式的檢視與操作●Linux
- win10系統如何檢視自己電腦有沒有被監控_win10怎麼檢視自己電腦是否被監控Win10
- postgresql如何檢視所有表SQL
- oracle檢視鎖表程式Oracle
- oracle表空間檢視Oracle
- 將檢視轉為表
- ASP.NET Core 5.0 MVC中的檢視分類——佈局檢視、啟動檢視、具體檢視、分部檢視ASP.NETMVC
- [Django REST framework - 檢視元件之檢視基類、檢視擴充套件類、檢視子類、檢視集]DjangoRESTFramework元件套件
- 利用DBCC PAGE檢視SQL Server中的表和索引資料SQLServer索引
- 檢視insert,delete,update對基表的影響(檢視初識)delete
- linux伺服器檢視監控頻寬的幾個工具Linux伺服器
- 利用檢視 V$FIXED_VIEW_DEFINITION 可以檢視Oracle很多底層的東西ViewOracle
- Oracle檢視版本號等其他資訊Oracle
- mybatis中的增刪改操作MyBatis