TimesTen 数据库复制学习:9. 更改Active Standby Pair

Posted dingdingfish

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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 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

先不复制一个表,后续又将其加入到复制计划中

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的主要内容,如果未能解决你的问题,请参考以下文章

TimesTen 数据库复制学习:2. 配置Active Standby Pair

TimesTen 数据库复制学习:3. 配置Classic Replication单表复制

TimesTen 数据库复制学习:10. 定义classic复制

TimesTen 数据库复制学习:16. 一个缓存组,复制,客户端自动切换的串烧实验

TimesTen 数据库复制学习:8. 管理Active Standby Pair(带缓存组)

TimesTen 数据库复制学习:5. 设定复制网络传输的return service