General
=========================================
How to see all updated tables in database?
=========================================
Theory
=========================================
USER_TAB_MODIFICATIONS lists DML operations on a table.
There is also ALL_TAB_MODIFICATIONS and SYS.DBA_TAB_MODIFICATIONS(But there is no DBA_TAB_MODIFICATIONS synonym)
This is an SQL showing DML operations during last 2 days:
SELECT TABLE_NAME, INSERTS ,UPDATES,DELETES, TRUNCATED, DROP_SEGMENTS,TIMESTAMP
FROM USER_TAB_MODIFICATIONS
WHERE timestamp > SYSDATE -2
ORDER BY timestamp DESC ;
TABLE_NAME INSERTS UPDATES DELETES TRUNCATED DROP_SEGMENTS TIMESTAMP
-------------------- ---------- ---------- ---------- --------- ------------- -----------
GSM_MSC_PREFIXES 259 6 33 NO 0 03/05/2016
SH_REFRESH_LOG 775 775 0 NO 0 03/05/2016
MLOG$_GSM_MSC_PREFIXE 10405 8163 4584 NO 0 03/05/2016
MLOG$_SHORT_CODES 3229 3219 39 NO 0 03/05/2016
MLOG$_SHORT_CODE_NET 3081 3057 2325 NO 0 03/05/2016
MLOG$_HSC_GATE_SC 778649 542725 517226 NO 0 03/05/2016
MLOG$_GSM_NDC_PREFIXES 195356 193049 145975 NO 0 03/05/2016
SHORT_CODE_NETWORK 39 2 7 NO 0 03/05/2016
SHORT_CODES 9 11 3 NO 0 03/05/2016
HSC_GATE_SC 16644 2194 11806 NO 0 03/05/2016
GSM_NDC_PREFIXES 4578 133 215 NO 0 03/05/2016
SGA_W_LOG 189 0 0 NO 0 03/05/2016
SUPPORT_CNT_LOG 581 0 0 NO 0 02/05/2016
13 rows selected
=========================================
Example
=========================================
Example
=========================================
Now lets perform Update on another table:
UPDATE DB_INSTALLED_VERSIONS
SET app_upgrade_id = 881
WHERE app_name = 'IG2-SA DB' AND app_upgrade_id = 81;
1 row updated
SQL> commit;
Commit complete
EXECUTE DBMS_STATS.FLUSH_DATABASE_MONITORING_INFO;
SELECT TABLE_OWNER,
TABLE_NAME,
INSERTS ,
UPDATES,
DELETES,
(inserts+updates+deletes) total_dml
FROM DBA_TAB_MODIFICATIONS
WHERE table_owner NOT IN ('SYS')
ORDER BY total_dml;
TABLE_OWNER TABLE_NAME INSERTS UPDATES DELETES TOTAL_DML
----------------- --------------------------- -------- -------- ---------- ----------
CHE_SWISS_IPNQQ DB_PROC_SFI_SUBSCRIBER_TEMP 10066349 0 10066112 20132461
CHE_SWISS_IPNQQ SGA_SUBSCRIBER_SFI 6657283 3409066 6671100 16737449
CHE_SWISS_IPNQQ GA_W_COUNTERS_HISTORY 4493598 0 6459166 10952764
CHE_SWISS_IPNQQ SGA_W_IPN_SUBSCRIBER 139831 10432759 230121 10802711
CHE_SWISS_IPNQQ SGA_W_PSMS_SUBSCRIBER 11461 3465714 8500 3485675
CHE_SWISS_IPNQQ SGA_W_SUBS_CAMP_HISTORY 103602 0 41595 145197
CHE_SWISS_IPNQQ IPN_W_ACTUAL_DISTRIBUTION_A 65373 0 65369 130742
CHE_SWISS_IPNQQ IPN_W_ACTUAL_DISTRIBUTION_B 61619 0 61611 123230
CHE_SWISS_IPNQQ REP_DAILY_DNORM 42570 22719 39100 104389
CHE_SWISS_IPNQQ REP_MONTHLY_DNORM 52101 396 51391 103888
CHE_SWISS_TSTQQ REP_DAILY_DNORM 20616 20616 20616 61848
COL TABLE_OWNER FOR A30
COL TABLE_NAME FOR A30
SELECT TABLE_OWNER,
TABLE_NAME,
INSERTS ,
UPDATES,
DELETES,
TRUNCATED,
DROP_SEGMENTS,
TIMESTAMP
FROM DBA_TAB_MODIFICATIONS
WHERE timestamp > SYSDATE -2
ORDER BY timestamp DESC ;
TABLE_NAME INSERTS UPDATES DELETES TRUNCATED DROP_SEGMENTS TIMESTAMPWHERE timestamp > SYSDATE -2
ORDER BY timestamp DESC ;
-------------------- ---------- ---------- ---------- --------- ------------- -----------
GSM_MSC_PREFIXES 259 6 33 NO 0 03/05/2016
SH_REFRESH_LOG 775 775 0 NO 0 03/05/2016
MLOG$_GSM_MSC_PREFIXE 10405 8163 4584 NO 0 03/05/2016
MLOG$_SHORT_CODES 3229 3219 39 NO 0 03/05/2016
MLOG$_SHORT_CODE_NET 3081 3057 2325 NO 0 03/05/2016
MLOG$_HSC_GATE_SC 778649 542725 517226 NO 0 03/05/2016
MLOG$_GSM_NDC_PREFIXES 195356 193049 145975 NO 0 03/05/2016
SHORT_CODE_NETWORK 39 2 7 NO 0 03/05/2016
SHORT_CODES 9 11 3 NO 0 03/05/2016
HSC_GATE_SC 16644 2194 11806 NO 0 03/05/2016
GSM_NDC_PREFIXES 4578 133 215 NO 0 03/05/2016
SGA_W_LOG 189 0 0 NO 0 03/05/2016
SUPPORT_CNT_LOG 581 0 0 NO 0 02/05/2016
13 rows selected
The updated table does not appear in USER_TAB_MODIFICATIONS.
Why...???
Checking on the status of table DB_INSTALLED_VERSIONS, it does not differ from another table, that does appear in the list.
SELECT table_name, status, last_analyzed, global_stats, user_stats, monitoring
FROM USER_TABLES
WHERE table_name = 'DB_INSTALLED_VERSIONS';
TABLE_NAME STATUS LAST_ANALYZED GLOBAL_STATS USER_STATS MONITORING
------------------------------ -------- ------------- ------------ ---------- ----------
DB_INSTALLED_VERSIONS VALID 04/03/2014 22 YES NO YES
GSM_MSC_PREFIXES VALID 22/07/2015 21 YES NO YES
What does USER_TAB_MODIFICATIONS report for table GSM_MSC_PREFIXES but does not report for DB_INSTALLED_VERSIONS?
=========================================
Permission
=========================================
To be able execute user must have
"ANALYZE ANY" permission, and not "EXECUTE ON DBMS_STATS", as one might expect.
For example:
sqlplus / as sysdba
GRANT ANALYZE ANY TO some_user;
=========================================
Solution
=========================================
To get to see DML operation, need to execute:
BEGIN
DBMS_STATS.flush_database_monitoring_info;
END;
/
PL/SQL procedure successfully completed
Now there is a lot more information...:
SELECT TABLE_NAME, INSERTS ,UPDATES,DELETES, TRUNCATED, DROP_SEGMENTS,TIMESTAMP
FROM USER_TAB_MODIFICATIONS
WHERE timestamp > SYSDATE -2
ORDER BY timestamp DESC ;
TABLE_NAME INSERTS UPDATES DELETES TRUNCATED DROP_SEGMENTS TIMESTAMP
--------------------- ---------- ---------- ---------- --------- ------------- ---------
REPORT_PLMN_NDC 1 0 0 NO 0 04/05/2016
DB_INSTALLED_VERSIONS 45 5 0 NO 0 04/05/2016
SH_REFRESH_LOG 806 806 0 NO 0 04/05/2016
REPORTS_PLMN_NDC 7467 0 0 NO 0 04/05/2016
=========================================
DBMS_STATS.FLUSH_DATABASE_MONITORING_INFO
=========================================
This procedure flushes in-memory monitoring information for all tables in the dictionary.
Corresponding entries in the:
*_TAB_MODIFICATIONS
*_TAB_STATISTICS
*_IND_STATISTICS
views are updated immediately, without waiting for the Oracle database to flush them periodically.
This procedure is useful when you need up-to-date information in those views.
Because the GATHER_*_STATS procedures internally flush monitoring information, it is not necessary to run this procedure before gathering the statistics.
No comments:
Post a Comment