本文主要是介绍TimesTen 数据库复制学习:9. 更改Active Standby Pair,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
在Active Standby Pair中复制DDL语句
在以下的例子中,active master为cachedb2, standby master为cachedb1
在Active Standby Pair复制数据库对象
DDLReplicationLevel 连接属性可以控制复制对象的行为。
DDLReplicationLevel = 1:不复制表,索引和同义词的create 和 drop,只复制复制表的添加和删除列操作
DDLReplicationLevel = 2: 缺省,复制表,索引和同义词的create 和 drop;DDLReplicationAction 必须设置为INCLUDE(缺省)
DDLReplicationLevel = 3:除了2 的所有行为外,还复制视图,序列,ttCacheUidPwdSet,以及可以为一个表加一个非空的列
控制复制的行为
以下是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 foundcachedb2> 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-HOLMaster Store: CACHEDB1 on TIMESTEN-HOLExcluded Tables: <- 注意这里TTHR.A1TTHR.A2Excluded Cache Groups:NoneExcluded sequences:NoneStore: CACHEDB1 on TIMESTEN-HOLPort: (auto)Log Fail Threshold: (none)Retry Timeout: 120 secondsCompress Traffic: DisabledStore: CACHEDB2 on TIMESTEN-HOLPort: (auto)Log Fail Threshold: (none)Retry Timeout: 120 secondsCompress Traffic: DisabledStore: _ORACLE from TIMESTEN-HOLPort: (auto)Log Fail Threshold: (none)Retry Timeout: 120 secondsCompress Traffic: Disabledcachedb2> 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-HOLMaster Store: CACHEDB1 on TIMESTEN-HOLExcluded Tables:TTHR.A2Included Tables: <- 注意这里TTHR.A1Excluded Cache Groups:NoneExcluded sequences:NoneStore: CACHEDB1 on TIMESTEN-HOLPort: (auto)Log Fail Threshold: (none)Retry Timeout: 120 secondsCompress Traffic: DisabledStore: CACHEDB2 on TIMESTEN-HOLPort: (auto)Log Fail Threshold: (none)Retry Timeout: 120 secondsCompress Traffic: DisabledStore: _ORACLE from TIMESTEN-HOLPort: (auto)Log Fail Threshold: (none)Retry Timeout: 120 secondsCompress Traffic: Disabledcachedb2> create index idx on a1(a);
17063: CREATE INDEX can only refer to empty tables when DDLReplicationLevel > 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;
下面例子说明了,如果一个表最初不在复制计划中,然后又加入复制计划,此表必须为空
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,然后在所有数据库上手工建立
对于active standby pair的其它更改操作
以下的操作必须先停止复制代理:
* 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上的复制代理
这篇关于TimesTen 数据库复制学习:9. 更改Active Standby Pair的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!