您好,登錄后才能下訂單哦!
邏輯備庫與物理備庫不同,它并不是Primary數據庫的一個精確的copy。同一rowid,在邏輯備庫上返回的值并不是相同的。有些數據類型或者對象,邏輯備庫并不支持同步。在創建邏輯備庫之前,你首先要確認,哪些schema及對象是不被SQL-APPLY支持的。
1. 查詢不被同步的schema 。
SQL> set pagesize 200 SQL> SELECT OWNER FROM DBA_LOGSTDBY_SKIP WHERE STATEMENT_OPT = 'INTERNAL SCHEMA'; OWNER ------------------------------- SYS SYSTEM OUTLN MGMT_VIEW MDSYS ORDSYS EXFSYS DBSNMP WMSYS APPQOSSYS APEX_030200 ORDDATA CTXSYS ANONYMOUS SYSMAN XDB ORDPLUGINS OWBSYS SI_INFORMTN_SCHEMA OLAPSYS ORACLE_OCM XS$NULL DIP 23 rows selected.
2. 查詢哪些表是不被執行的。
SQL> SELECT DISTINCT OWNER,TABLE_NAME FROM DBA_LOGSTDBY_UNSUPPORTED ORDER BY OWNER,TABLE_NAME; no rows selected
3. 如果上步返回數據,可以通過如下查詢得知是哪些類型不被支持
SQL> SELECT COLUMN_NAME,DATA_TYPE FROM DBA_LOGSTDBY_UNSUPPORTED WHERE OWNER='OE' AND TABLE_NAME = 'CUSTOMERS'; no rows selected
4. 邏輯備庫的SQL-APPLY是通過表的唯一標識進行的,也就是說表必須有主鍵或者唯一性索引。
SQL> col owner for a10 SQL> col table_name for a30 SQL> SELECT OWNER, TABLE_NAME FROM DBA_LOGSTDBY_NOT_UNIQUE; OWNER TABLE_NAME ---------- ------------------------------ SCOTT BONUS SCOTT SALGRADE SCOTT T1
如果表沒有主鍵或唯一約束怎么辦?Oracle會在日志文件中寫入supplemental logging 。也就是會寫入大量的附加信息,用所有的column的值以構建update時的唯一性。
當然也有一些表是無法構建唯一性的,可以通過如下語句查詢
SELECT OWNER, TABLE_NAME FROM DBA_LOGSTDBY_NOT_UNIQUE WHERE (OWNER, TABLE_NAME) NOT IN (SELECT DISTINCT OWNER, TABLE_NAME FROM DBA_LOGSTDBY_UNSUPPORTED) AND BAD_COLUMN = 'Y';
5. 關閉物理備庫的日志應用
SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE CANCEL; Database altered.
6. 構建創建邏輯備庫必要的數據字典。
轉到主庫上執行如下命令
SQL> EXECUTE DBMS_LOGSTDBY.BUILD; PL/SQL procedure successfully completed.
此命令做了如下事情
主庫上開啟supplemental logging功能。
在主庫上構建LogMiner的數據字典,使得邏輯備庫知道如何處理主庫發來的redo數據。
記錄一個scn號,從庫上的SQL-APPLY方式日志應用從此scn號開始。
7. 如果有主備切換的需求,那么必須先在standby數據庫上手工開啟supplemental logging。
SQL> ALTER DATABASE ADD SUPPLEMENTAL LOG DATA (PRIMARY KEY, UNIQUE INDEX) COLUMNS; Database altered.
8. 在從庫上應用切換成邏輯備庫之前的redo
SQL> ALTER DATABASE RECOVER TO LOGICAL STANDBY "standby"; ALTER DATABASE RECOVER TO LOGICAL STANDBY "standby" * ERROR at line 1: ORA-19953: database should not be open SQL> shutdown immediate Database closed. Database dismounted. ORACLE instance shut down. SQL> startup mount ORACLE instance started. Total System Global Area 839282688 bytes Fixed Size 2233000 bytes Variable Size 494931288 bytes Database Buffers 339738624 bytes Redo Buffers 2379776 bytes Database mounted. SQL> ALTER DATABASE RECOVER TO LOGICAL STANDBY "standby"; Database altered.
9. 打開數據庫
SQL> shutdown immediate ORA-01507: database not mounted ORACLE instance shut down. SQL> startup mount ORACLE instance started. Total System Global Area 839282688 bytes Fixed Size 2233000 bytes Variable Size 494931288 bytes Database Buffers 339738624 bytes Redo Buffers 2379776 bytes Database mounted. SQL> alter database open resetlogs; Database altered. SQL>
10. 啟動日志應該
SQL> ALTER DATABASE START LOGICAL STANDBY APPLY IMMEDIATE; Database altered.
11. 驗證數據同步
主庫
SQL> conn scott/tiger Connected. SQL> select count(*) from t1; COUNT(*) ---------- 14 SQL> insert into t1 select * from t1; 14 rows created. SQL> commit; Commit complete.
從庫上查詢數據
SQL> conn scott/tiger Connected. SQL> select count(*) from t1; COUNT(*) ---------- 28
從庫也能建立表,修改數據等。
SQL> conn / as sysdba Connected. SQL> ALTER DATABASE STOP LOGICAL STANDBY APPLY; Database altered. SQL> ALTER SESSION DISABLE GUARD; Session altered. SQL> create table scott.t2 as select * from scott.t1; Table created. SQL> ALTER SESSION ENABLE GUARD; Session altered. SQL> ALTER DATABASE START LOGICAL STANDBY APPLY IMMEDIATE; Database altered.
SQL> conn / as sysdba Connected. SQL> ALTER SESSION DISABLE GUARD; Session altered. SQL> insert into scott.t1 select * from scott.t1; 28 rows created. SQL> commit; Commit complete. SQL> alter session enable guard; Session altered.
被DataGuard傳輸的表,也能被修改數據,這個還蠻危險的,兩邊的數據就不一致啦。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。