在以下的例子中,active master為cachedb2, standby master為cachedb1
DDLReplicationLevel 連接屬性可以控制復制對象的行動。
DDLReplicationLevel = 1:不復制表,索引和同義詞的create 和 drop,只復制復制表的添加和刪除列操作
DDLReplicationLevel = 2: 缺省,復制表,索引和同義詞的create 和 drop;DDLReplicationAction 必須設置為INCLUDE(缺省)
DDLReplicationLevel = 3:除2 的所有行動外,還復制視圖,序列,ttCacheUidPwdSet,和可以為1個表加1個非空的列
以下是DDLReplicationLevel = 2 的情形(缺省)
cachedb2> call ttconfiguration;
......
< DDLReplicationAction, INCLUDE >
< DDLReplicationLevel, 2 >
cachedb2> create table a1(a int, primary key(a));
cachedb1> select * from a1;
cachedb2> insert into a1 values(1);
cachedb1> select * from a1;
< 1 >
cachedb2> drop table a1;
cachedb1> select * from a1;
2206: Table TTHR.A1 not found
cachedb2> create table a2(a int);
17061: When DDLReplicationAction='INCLUDE' tables must be created with a primary key or a unique constraint on non-nullable column(s)
cachedb2> ALTER SESSION SET ddl_replication_action='EXCLUDE'; <- 只是不復制DML,DDL仍復制
Session altered.
cachedb2> call ttconfiguration('DDLReplicationAction');
< DDLReplicationAction, EXCLUDE >
cachedb2> create table a1(a int, primary key(a));
cachedb1> select * from a1;
cachedb2> insert into a1 values(1);
cachedb1> select * from a1;
cachedb2> create table a2(a int);
cachedb1> select * from a2;
cachedb1> repschemes;
Replication Scheme Active Standby:
Master Store: CACHEDB2 on TIMESTEN-HOL
Master Store: CACHEDB1 on TIMESTEN-HOL
Excluded Tables: <- 注意這里
TTHR.A1
TTHR.A2
Excluded Cache Groups:
None
Excluded sequences:
None
Store: CACHEDB1 on TIMESTEN-HOL
Port: (auto)
Log Fail Threshold: (none)
Retry Timeout: 120 seconds
Compress Traffic: Disabled
Store: CACHEDB2 on TIMESTEN-HOL
Port: (auto)
Log Fail Threshold: (none)
Retry Timeout: 120 seconds
Compress Traffic: Disabled
Store: _ORACLE from TIMESTEN-HOL
Port: (auto)
Log Fail Threshold: (none)
Retry Timeout: 120 seconds
Compress Traffic: Disabled
cachedb2> ALTER ACTIVE STANDBY PAIR INCLUDE TABLE a1;
cachedb2> insert into a1 values(3);
cachedb1> select * from a1;
< 3 >
cachedb2> repschemes;
Replication Scheme Active Standby:
Master Store: CACHEDB2 on TIMESTEN-HOL
Master Store: CACHEDB1 on TIMESTEN-HOL
Excluded Tables:
TTHR.A2
Included Tables: <- 注意這里
TTHR.A1
Excluded Cache Groups:
None
Excluded sequences:
None
Store: CACHEDB1 on TIMESTEN-HOL
Port: (auto)
Log Fail Threshold: (none)
Retry Timeout: 120 seconds
Compress Traffic: Disabled
Store: CACHEDB2 on TIMESTEN-HOL
Port: (auto)
Log Fail Threshold: (none)
Retry Timeout: 120 seconds
Compress Traffic: Disabled
Store: _ORACLE from TIMESTEN-HOL
Port: (auto)
Log Fail Threshold: (none)
Retry Timeout: 120 seconds
Compress Traffic: Disabled
cachedb2> create index idx on a1(a);
17063: CREATE INDEX can only refer to empty tables when DDLReplicationLevel > 1
先不復制1個表,后續又將其加入到復制計劃中
cachedb2> drop table a2;
cachedb2> ALTER SESSION SET ddl_replication_action='exclude';
Session altered.
cachedb2> create table a2(a int not null);
cachedb1> select * from a2;
cachedb2> ALTER ACTIVE STANDBY PAIR INCLUDE TABLE a2;
8000: No primary or unique index on non-nullable column found for replicated table TTHR.A2
cachedb2> CREATE UNIQUE INDEX ixnewtab ON a2(a);
cachedb2> ALTER ACTIVE STANDBY PAIR INCLUDE TABLE a2;
下面例子說明了,如果1個表最初不在復制計劃中,然后又加入復制計劃,此表必須為空
cachedb2> ALTER SESSION SET ddl_replication_action='exclude';
Session altered.
cachedb2> create table a2(a int, primary key(a));
cachedb2> insert into a2 values(1);
cachedb2> insert into a2 values(2);
cachedb2> ALTER ACTIVE STANDBY PAIR INCLUDE TABLE a2;
17059: Replicated INCLUDE TABLE failed for (TTHR.A2) because the table is not empty
cachedb2> delete from a2;
cachedb2> ALTER ACTIVE STANDBY PAIR INCLUDE TABLE a2;
以下的對象在DDLReplicationLevel = 2或3時可以自動復制
* Create, alter, or drop a user with the CREATE USER, ALTER USER, or DROP USER statements.
* Grant or revoke privileges from a user with the GRANT or REVOKE statements.
* Alter a table to add or drop a column with the ALTER TABLE … ADD COLUMN or ALTER TABLE … DROP COLUMN statements. These are the only ALTER TABLE clauses that are replicated. However, when DDLReplicationLevel=2, you cannot alter a table to add a NOT NULL column to a table that is part of a replication scheme with the ALTER TABLE … ADD COLUMN NOT NULL DEFAULT statement. You can execute this statement if DDLReplicationLevel=3.
* Create or drop a table, including global temporary tables with the CREATE TABLE or DROP TABLE statements. The new table is also included in the active standby pair.
* Create or drop a synonym with the CREATE SYNONYM or DROP SYNONYM statements.
* Create or drop an index with the CREATE INDEX or DROP INDEX statements.
以下的對象僅在 DDLReplicationLevel = 3時可以自動復制
* 視圖
* 序列(sequence)
* ttCacheUidPwdSet 操作
以上的復制操作均不需要停止復制代理。
對物化視圖的操作,更改autorefresh mode,PL/SQL都不會復制
如果需要創建PL/SQL函數,需要在所有的數據庫中履行create語句并賦權
只有在空表創建的索引才會被復制,如果需要復制索引,可以將DDLReplicationLevel設為1,然后在所有數據庫上手工建立
以下的操作必須先停止復制代理:
* Include or exclude a cache group.
* Add or drop a subscriber.
* Change values in the STORE clause.
* Change network operations (ADD ROUTE or DROP ROUTE clause).
以上操作的進程以下:
1. 在active上停rep agent
2. 如果ASP包括緩存組,在active上停cache agent
3. 使用ALTER ACTIVE STANDBY PAIR修改復制schema
4. 在active上啟動rep agent
5. 如果ASP包括緩存組,在active上啟動cache agent
6. destroy所有的standby和subscriber
7. 使用ttRepAdmin 克隆standby
8. 啟動standby上的rep agent
9. 等待standby的狀態自動變成STANDBY(ttRepStateGet )
10. 如果ASP包括緩存組,在standby上啟動cache agent
11. 通過standby克隆subsc
12. 啟動subscriber上的復制代理