[20150828]插入commit scn到記錄.txt
[20150828]插入commit scn到記錄.txt
--昨天看
--連結:http://blog.dbi-services.com/oracle-cdc-for-datawarehouse-dbvisit-replicate-as-an-alternative/
--發現透過使用函式userenv('commitscn'),可以實現在DML記錄(插入與修改)時記錄提交scn的功能,自己按照例子也做了測試!
1.建立測試環境:
SCOTT@test01p> @ver1
PORT_STRING VERSION BANNER CON_ID
------------------------------ -------------- -------------------------------------------------------------------------------- ----------
IBMPC/WIN_NT64-9.1.0 12.1.0.1.0 Oracle Database 12c Enterprise Edition Release 12.1.0.1.0 - 64bit Production 0
SCOTT@test01p> create table DEMO (id number, update_scn number, commit_scn number);
Table created.
SCOTT@test01p> select dbms_flashback.get_system_change_number from dual;
GET_SYSTEM_CHANGE_NUMBER
------------------------
20498673
2.開始測試:
SCOTT@test01p> insert into DEMO values (1,dbms_flashback.get_system_change_number,userenv('commitscn'));
1 row created.
SCOTT@test01p> select * from demo;
ID UPDATE_SCN COMMIT_SCN
---------- ---------- ----------
1 20498680 20498680
-- 插入時UPDATE_SCN=COMMIT_SCN.
SCOTT@test01p> select dbms_flashback.get_system_change_number from dual;
GET_SYSTEM_CHANGE_NUMBER
------------------------
20498693
SCOTT@test01p> commit ;
Commit complete.
SCOTT@test01p> select * from demo;
ID UPDATE_SCN COMMIT_SCN
---------- ---------- ----------
1 20498680 20498695
--可以發現commit後,欄位commit_scn的資訊發生了變化,感覺就像給commit命令加了觸發器,修改了提交資訊.
SCOTT@test01p> select ora_rowscn,demo.* from demo ;
ORA_ROWSCN ID UPDATE_SCN COMMIT_SCN
---------- ---------- ---------- ----------
20498696 1 20498680 20498695
-- 偽列ora_rowscn 與 commit_scn 相差1 .
3.修改記錄看看:
SCOTT@test01p> update demo set commit_scn=userenv('commitscn');
1 row updated.
SCOTT@test01p> select ora_rowscn,demo.* from demo ;
ORA_ROWSCN ID UPDATE_SCN COMMIT_SCN
---------- ---------- ---------- ----------
20498696 1 20498680 20498827
--commit_scn再次發生了變化.
SCOTT@test01p> rollback ;
Rollback complete.
SCOTT@test01p> select ora_rowscn,demo.* from demo ;
ORA_ROWSCN ID UPDATE_SCN COMMIT_SCN
---------- ---------- ---------- ----------
20498696 1 20498680 20498695
--回滾後還原.下面修改並提交看看.
SCOTT@test01p> update demo set commit_scn=userenv('commitscn');
1 row updated.
SCOTT@test01p> commit ;
Commit complete.
SCOTT@test01p> select ora_rowscn,demo.* from demo ;
ORA_ROWSCN ID UPDATE_SCN COMMIT_SCN
---------- ---------- ---------- ----------
20498854 1 20498680 20498853
--感覺有點奇怪,oracle內部如何實現這個功能的?
4.使用logminer探究看看.
BEGIN
DBMS_LOGMNR.START_LOGMNR (
STARTSCN => 20498673,
ENDSCN => 20498854,
OPTIONS => DBMS_LOGMNR.DICT_FROM_ONLINE_CATALOG
+ DBMS_LOGMNR.CONTINUOUS_MINE
+ DBMS_LOGMNR.COMMITTED_DATA_ONLY);
END;
/
SYS@test> column SQL_REDO format a100
SYS@test> select scn,start_scn,commit_scn,seg_owner,operation,sql_redo from v$logmnr_contents where seg_owner='SCOTT';
SCN START_SCN COMMIT_SCN SEG_OWNER OPERATION SQL_REDO
---------- ---------- ---------- ---------- ------------ -----------------------------------------------------------------------------------------------
20498682 20498682 20498696 SCOTT INSERT insert into "SCOTT"."DEMO"("ID","UPDATE_SCN","COMMIT_SCN") values ('1','20498680','20498680');
20498695 20498682 20498696 SCOTT UNSUPPORTED Unsupported
--看不到修改語句.沒有開啟SUPPLEMENTAL LOG DATA;
SYS@test> ALTER DATABASE ADD SUPPLEMENTAL LOG DATA;
Database altered.
5.重複測試:
SCOTT@test01p> select dbms_flashback.get_system_change_number from dual;
GET_SYSTEM_CHANGE_NUMBER
------------------------
20535870
SCOTT@test01p> insert into DEMO values (2,dbms_flashback.get_system_change_number,userenv('commitscn'));
1 row created.
SCOTT@test01p> select ora_rowscn,demo.* from demo ;
ORA_ROWSCN ID UPDATE_SCN COMMIT_SCN
---------- ---------- ---------- ----------
20498854 1 20498680 20498853
20498682 2 20535883 20535883
SCOTT@test01p> commit ;
Commit complete.
SCOTT@test01p> select ora_rowscn,demo.* from demo ;
ORA_ROWSCN ID UPDATE_SCN COMMIT_SCN
---------- ---------- ---------- ----------
20498854 1 20498680 20498853
20535907 2 20535883 20535906
6.再次使用logminer探究看看.
BEGIN
DBMS_LOGMNR.START_LOGMNR (
STARTSCN => 20535870,
ENDSCN => 20535907,
OPTIONS => DBMS_LOGMNR.DICT_FROM_ONLINE_CATALOG
+ DBMS_LOGMNR.CONTINUOUS_MINE
+ DBMS_LOGMNR.COMMITTED_DATA_ONLY);
END;
/
SYS@test> select scn,start_scn,commit_scn,seg_owner,operation,sql_redo from v$logmnr_contents where seg_owner='SCOTT';
SCN START_SCN COMMIT_SCN SEG_OWNER OPERATION SQL_REDO
---------- ---------- ---------- ---------- ---------- ------------------------------------------------------------------------------------------------------------------------
20535883 20535883 20535907 SCOTT INSERT insert into "SCOTT"."DEMO"("ID","UPDATE_SCN","COMMIT_SCN") values ('2','20535883','20535883');
20535906 20535883 20535907 SCOTT UPDATE update "SCOTT"."DEMO" set "COMMIT_SCN" = '20535906' where "COMMIT_SCN" = '20535883' and ROWID = 'AAAYBeAAJAAAAC+AAA';
--確實可以看到在提交時有一個修改commit_scn的語句.
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/267265/viewspace-1787037/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- PLSQL Language Referenc-PL/SQL集合和記錄-記錄比較-將記錄插入到表中SQL
- Git插入新的commitGitMIT
- db2不記錄日誌插入記錄DB2
- git如何清空所有的commit記錄GitMIT
- mysql怎麼插入空記錄MySql
- commit操作是否一定會被記錄到redo等問題的研究MIT
- update誤操作後 通過undo記錄的scn找回原紀錄
- MySQL 當記錄不存在時插入,當記錄存在時更新MySql
- MySQL:使用INSERT 插入多條記錄MySql
- Oracle存在修改,不存在插入記錄Oracle
- oracle快速向表中插入記錄方法Oracle
- MySQL Cases-記錄大量waiting for handler commitMySqlAIMIT
- mysql 存在該記錄則更新,不存在則插入記錄的sqlMySql
- 如果需要同時插入30到50條記錄JDBC的事務該如何處理?JDBC
- PLSQL Language Referenc-PL/SQL集合和記錄-記錄更新和插入的限制SQL
- 透過DNS TXT記錄執行powershellDNS
- oracle單條sql與plsql rowid插入記錄小記OracleSQL
- MySql避免重複插入記錄的幾種方法MySql
- MySQL防止重複插入相同記錄 insert if not existsMySql
- MySQL:簡單記錄一下Waiting for commit lockMySqlAIMIT
- SQL INSERT INTO 語句詳解:插入新記錄、多行插入和自增欄位SQL
- 直接插入演算法的學習記錄演算法
- Oracle11gr2物化檢視日誌新增COMMIT SCN語句OracleMIT
- ORA_ROWSCN與按照commit時間對記錄進行排序MIT排序
- [20150806]scn headroom.txtOOM
- SQL 獲取插入後的最新一條記錄ID號SQL
- 資料庫中怎麼取回剛剛插入的記錄?資料庫
- 【BUG記錄】MySQL插入Emoji表情報錯"Incorrect string value"MySql
- oracle redo record scn與transaction相關block scn關係小記Oracle RedoBloC
- [20171115]redo and commit.txtMIT
- [20170515]檢查資料庫scn指令碼.txt資料庫指令碼
- [20170412]bbed隱藏資料記錄.txt
- 一步步學MongoDB之插入記錄總結MongoDB
- [20190531]建立job與commit.txtMIT
- 提交內容到版本庫:git commitGitMIT
- oracle commit隨筆記載OracleMIT筆記
- [20140624]bbed修改資料記錄.txt
- 記錄一個sql最佳化的全過程.txtSQL