TimesTen 数据库复制学习:17. 更改classic复制
来源:互联网 发布:国家邮政局投诉知乎 编辑:程序博客网 时间:2024/04/27 01:34
本文描述的是如何更改classic replication的scheme,table等
更改复制策略
以下的更改无需停止复制代理:
* Create, alter 或 drop 用户
* Grant or revoke 权限
* 添加subscriber
* 添加 PL/SQL 对象
其它的更改的过程如下:
1. 停止复制代理
2. alter replication语句,在master和subscriber上都需要执行
3. 启动复制代理
准备工作
在cachedb1和cachedb2上使用instance admin建立用户tthr和复制管理用户repadmin
create user tthr identified by timesten;grant create session, create table to tthr;create user repadmin identified by timesten;grant admin to repadmin;
在cachedb1和cachedb2上使用repadmin建立复制scheme
为了试验目的了,我们建立两种基准的复制scheme,这两者并不能并存,而是创建一种时,必须先将另一种删除掉。
- 基于TABLE的基准复制scheme
create table tthr.a1(a int, primary key(a));CREATE REPLICATION repscheme ELEMENT e TABLE tthr.a1 MASTER cachedb1 ON "timesten-hol" SUBSCRIBER cachedb2 ON "timesten-hol" RETURN RECEIPT;call ttrepstart;insert into tthr.a1 values(1)
- 基于DATSTORE的基准复制scheme
call ttrepstop;CREATE REPLICATION repscheme1 ELEMENT e DATASTORE MASTER cachedb1 ON "timesten-hol" SUBSCRIBER cachedb2 ON "timesten-hol" RETURN RECEIPT;call ttrepstart;Command> repschemes;Replication Scheme REPADMIN.REPSCHEME: Element: E Type: Table TTHR.A1 Master Store: CACHEDB1 on TIMESTEN-HOL Transmit Durable Subscriber Store: CACHEDB2 on TIMESTEN-HOL Return Receipt 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 Return Service Wait Time: 10 seconds Return Service on Replication Stop: Disabled Return Service Failure Policy: (none)1 replication scheme found.
增加表到已有的scheme
分两种情形.
- 基于TABLE的基准复制scheme
在cachedb1和cachedb2上使用repadmin更改复制scheme,添加表a2
create table tthr.a2(a int, primary key(a));call ttrepstop;ALTER REPLICATION repscheme ADD ELEMENT e1 TABLE tthr.a2 MASTER cachedb1 ON "timesten-hol" SUBSCRIBER cachedb2 ON "timesten-hol" RETURN RECEIPT;call ttrepstart;Command> repschemes;Replication Scheme REPADMIN.REPSCHEME: Element: E Type: Table TTHR.A1 Master Store: CACHEDB1 on TIMESTEN-HOL Transmit Durable Subscriber Store: CACHEDB2 on TIMESTEN-HOL Return Receipt Element: E1 Type: Table TTHR.A2 Master Store: CACHEDB1 on TIMESTEN-HOL Transmit Durable Subscriber Store: CACHEDB2 on TIMESTEN-HOL Return Receipt 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 Return Service Wait Time: 10 seconds Return Service on Replication Stop: Disabled Return Service Failure Policy: (none)1 replication scheme found.
- 基于DATASTORE的基准复制scheme
如果建立的是DATASTORE的复制,那么建立时,数据库中所有满足条件的表都会复制。
但如果后续添加了表,则需要alter replication添加才可复制
Command> repschemes;Replication Scheme REPADMIN.REPSCHEME1: Element: E Type: Datastore Master Store: CACHEDB1 on TIMESTEN-HOL Transmit Durable Subscriber Store: CACHEDB2 on TIMESTEN-HOL Return Receipt Excluded Tables: None 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 Return Service Wait Time: 10 seconds Return Service on Replication Stop: Disabled Return Service Failure Policy: (none)1 replication scheme found.create table tthr.a3(a int, primary key(a));Command> repschemes;Replication Scheme REPADMIN.REPSCHEME1: Element: E Type: Datastore Master Store: CACHEDB1 on TIMESTEN-HOL Transmit Durable Subscriber Store: CACHEDB2 on TIMESTEN-HOL Return Receipt Excluded Tables: TTHR.A3 Included 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 Return Service Wait Time: 10 seconds Return Service on Replication Stop: Disabled Return Service Failure Policy: (none)1 replication scheme found.call ttrepstop;ALTER REPLICATION repscheme1 ALTER ELEMENT E INCLUDE TABLE tthr.a3;call ttrepstart;Command> repschemes;Replication Scheme REPADMIN.REPSCHEME1: Element: E Type: Datastore Master Store: CACHEDB1 on TIMESTEN-HOL Transmit Durable Subscriber Store: CACHEDB2 on TIMESTEN-HOL Return Receipt Excluded Tables: None 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 Return Service Wait Time: 10 seconds Return Service on Replication Stop: Disabled Return Service Failure Policy: (none)1 replication scheme found.
添加DATASTORE到已有的scheme
感觉主要用于双向复制。或级联复制,例如db1->db2,同时db2->db3,这时db2既是master,也是subscriber
ALTER REPLICATION repscheme ADD ELEMENT ds1 DATASTORE MASTER cachedb1 SUBSCRIBER cachedb3; 8180: Full versus partial replication conflict with an existing replication scheme on data store CACHEDB1The command failed.
ALTER REPLICATION repscheme1
ADD ELEMENT ds1 DATASTORE
MASTER cachedb3
SUBSCRIBER cachedb4;
ALTER REPLICATION repscheme1
ADD ELEMENT ds1 DATASTORE
MASTER cachedb2
SUBSCRIBER cachedb4;
Command> repschemes;
Replication Scheme REPADMIN.REPSCHEME1:
Element: DS1
Type: Datastore
Master Store: CACHEDB2 on TIMESTEN-HOL Transmit Durable
Subscriber Store: CACHEDB4 on TIMESTEN-HOL
Excluded Tables:
None
Excluded Cache Groups:
None
Excluded sequences:
None
Element: E
Type: Datastore
Master Store: CACHEDB1 on TIMESTEN-HOL Transmit Durable
Subscriber Store: CACHEDB2 on TIMESTEN-HOL Return Receipt
Subscriber Store: CACHEDB3 on TIMESTEN-HOL
Excluded Tables:
None
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
Return Service Wait Time: 10 seconds
Return Service on Replication Stop: Disabled
Return Service Failure Policy: (none)
Store: CACHEDB3 on TIMESTEN-HOL
Port: (auto)
Log Fail Threshold: (none)
Retry Timeout: 120 seconds
Compress Traffic: Disabled
Store: CACHEDB4 on TIMESTEN-HOL
Port: (auto)
Log Fail Threshold: (none)
Retry Timeout: 120 seconds
Compress Traffic: Disabled
1 replication scheme found.
05:15:02 Contacting remote main daemon at 127.0.0.1 port 53392
05:15:02 Contacting the replication agent for CACHEDB2 ON TIMESTEN-HOL (127.0.0.1) port 19521
05:15:02 Beginning transfer from CACHEDB2 ON TIMESTEN-HOL to CACHEDB4 ON TIMESTEN-HOL
05:15:16 Checkpoint transfer 10 percent complete
05:15:16 Checkpoint transfer 20 percent complete
05:15:16 Checkpoint transfer 30 percent complete
05:15:16 Checkpoint transfer 100 percent complete
05:15:16 Checkpoint transfer phase complete
05:15:17 Log transfer 100 percent complete
05:15:17 Log transfer phase complete
05:15:18 Transfer complete
05:15:21 Duplicate Operation Ends
[oracle@timesten-hol info]$ ttisql “dsn=cachedb4;uid=repadmin;pwd=timesten”
Copyright (c) 1996, 2014, Oracle and/or its affiliates. All rights reserved.
Type ? or “help” for help, type “exit” to quit ttIsql.
connect “dsn=cachedb4;uid=repadmin;pwd=timesten”;
Connection successful: DSN=cachedb4;UID=repadmin;DataStore=/home/oracle/TimesTen/tt1122/info/DemoDataStore/cachedb4;DatabaseCharacterSet=AL32UTF8;ConnectionCharacterSet=US7ASCII;LogFileSize=32;DRIVER=/home/oracle/TimesTen/tt1122/lib/libtten.so;PermSize=32;TempSize=64;TypeMode=0;OracleNetServiceName=ttorcl;LogBufMB=32;
(Default setting AutoCommit=1)
Command> call ttrepstart;
Command> repschemes;
Replication Scheme REPADMIN.REPSCHEME1:
Element: DS1
Type: Datastore
Master Store: CACHEDB2 on TIMESTEN-HOL Transmit Durable
Subscriber Store: CACHEDB4 on TIMESTEN-HOL
Excluded Tables:
None
Excluded Cache Groups:
None
Excluded sequences:
None
Element: E
Type: Datastore
Master Store: CACHEDB1 on TIMESTEN-HOL Transmit Durable
Subscriber Store: CACHEDB2 on TIMESTEN-HOL Return Receipt
Subscriber Store: CACHEDB3 on TIMESTEN-HOL
Excluded Tables:
None
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
Return Service Wait Time: 10 seconds
Return Service on Replication Stop: Disabled
Return Service Failure Policy: (none)
Store: CACHEDB3 on TIMESTEN-HOL
Port: (auto)
Log Fail Threshold: (none)
Retry Timeout: 120 seconds
Compress Traffic: Disabled
Store: CACHEDB4 on TIMESTEN-HOL
Port: (auto)
Log Fail Threshold: (none)
Retry Timeout: 120 seconds
Compress Traffic: Disabled
1 replication scheme found.
利用了classic replication,master库是可以读写的,只有在当前master库上产生的日志,才会复制到对方
例如cachedb1->cachedb2,但不会传递到cachedb4;例如cachedb2->cachedb4
增加PL/SQL对象到已有的scheme
- 在master库中创建PL/SQL对象,此create语句不会复制
- 在subscriber库中创建相同PL/SQL对象
- 在master库中为PL/SQL对象赋权,赋权语句被复制
从复制scheme中去除一个表或sequence
- 基于DATASTORE的基准复制scheme
Command> drop table tthr.a3; 8002: Cannot drop replicated table, index, or sequenceThe command failed.ALTER REPLICATION repscheme1 ALTER ELEMENT E EXCLUDE TABLE tthr.a3;DROP TABLE tthr.a3;
- 基于TABLE的基准复制scheme
ALTER REPLICATION repscheme DROP ELEMENT e1;
创建和添加subscriber
需要添加的subscriber为cachedb3, 确保cachedb3不存在
在cachedb1和cachedb2上皆执行,无需停复制代理
ALTER REPLICATION repscheme1 ALTER ELEMENT e ADD SUBSCRIBER cachedb3;Command> repschemes;Replication Scheme REPADMIN.REPSCHEME1: Element: E Type: Datastore Master Store: CACHEDB1 on TIMESTEN-HOL Transmit Durable Subscriber Store: CACHEDB2 on TIMESTEN-HOL Return Receipt Subscriber Store: CACHEDB3 on TIMESTEN-HOL Excluded Tables: None 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 Return Service Wait Time: 10 seconds Return Service on Replication Stop: Disabled Return Service Failure Policy: (none) Store: CACHEDB3 on TIMESTEN-HOL Port: (auto) Log Fail Threshold: (none) Retry Timeout: 120 seconds Compress Traffic: Disabled1 replication scheme found.$ ttRepAdmin -verbosity 2 -duplicate -from cachedb1 -host timesten-hol -dsn cachedb3 -uid repadmin -pwd timesten05:06:57 Contacting remote main daemon at 127.0.0.1 port 5339205:06:57 Contacting the replication agent for CACHEDB1 ON TIMESTEN-HOL (127.0.0.1) port 1119305:06:57 Beginning transfer from CACHEDB1 ON TIMESTEN-HOL to CACHEDB3 ON TIMESTEN-HOL05:07:16 Checkpoint transfer 10 percent complete05:07:16 Checkpoint transfer 20 percent complete05:07:16 Checkpoint transfer 30 percent complete05:07:16 Checkpoint transfer 100 percent complete05:07:16 Checkpoint transfer phase complete05:07:17 Log transfer 100 percent complete05:07:17 Log transfer phase complete05:07:17 Transfer complete05:07:21 Duplicate Operation Ends[oracle@timesten-hol info]$ ttisql cachedb3Copyright (c) 1996, 2014, Oracle and/or its affiliates. All rights reserved.Type ? or "help" for help, type "exit" to quit ttIsql.connect "DSN=cachedb3";Connection successful: DSN=cachedb3;UID=oracle;DataStore=/home/oracle/TimesTen/tt1122/info/DemoDataStore/cachedb3;DatabaseCharacterSet=AL32UTF8;ConnectionCharacterSet=US7ASCII;LogFileSize=32;DRIVER=/home/oracle/TimesTen/tt1122/lib/libtten.so;PermSize=32;TempSize=64;TypeMode=0;OracleNetServiceName=ttorcl;LogBufMB=32;(Default setting AutoCommit=1)Command> call ttrepstart;Command> repschemes;Replication Scheme REPADMIN.REPSCHEME1: Element: E Type: Datastore Master Store: CACHEDB1 on TIMESTEN-HOL Transmit Durable Subscriber Store: CACHEDB2 on TIMESTEN-HOL Return Receipt Subscriber Store: CACHEDB3 on TIMESTEN-HOL Excluded Tables: None 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 Return Service Wait Time: 10 seconds Return Service on Replication Stop: Disabled Return Service Failure Policy: (none) Store: CACHEDB3 on TIMESTEN-HOL Port: (auto) Log Fail Threshold: (none) Retry Timeout: 120 seconds Compress Traffic: Disabled1 replication scheme found.Command>
删除subscriber库
ALTER REPLICATION repscheme1
ALTER ELEMENT E
DROP SUBSCRIBER cachedb3;
更改 Table element名字
ALTER REPLICATION r1 ALTER ELEMENT Eelem_westleads SET NAME newelname;
更换master数据库???
ALTER REPLICATION repscheme1
ALTER ELEMENT * IN cachedb1
SET MASTER cachedb3;
ALTER ELEMENT * IN FullStoreName
SET { MASTER | PROPAGATOR } FullStoreName
去除return service
Command> repschemes;Replication Scheme REPADMIN.REPSCHEME1: Element: DS1 Type: Datastore Master Store: CACHEDB2 on TIMESTEN-HOL Transmit Durable Subscriber Store: CACHEDB4 on TIMESTEN-HOL Excluded Tables: None Excluded Cache Groups: None Excluded sequences: None Element: E Type: Datastore Master Store: CACHEDB1 on TIMESTEN-HOL Transmit Durable Subscriber Store: CACHEDB2 on TIMESTEN-HOL Return Receipt Excluded Tables: None 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 Return Service Wait Time: 10 seconds Return Service on Replication Stop: Disabled Return Service Failure Policy: (none) Store: CACHEDB4 on TIMESTEN-HOL Port: (auto) Log Fail Threshold: (none) Retry Timeout: 120 seconds Compress Traffic: Disabled1 replication scheme found.ALTER REPLICATION repscheme1 ALTER ELEMENT E ALTER SUBSCRIBER cachedb2 SET NO RETURN;Command> repschemes;Replication Scheme REPADMIN.REPSCHEME1: Element: DS1 Type: Datastore Master Store: CACHEDB2 on TIMESTEN-HOL Transmit Durable Subscriber Store: CACHEDB4 on TIMESTEN-HOL Excluded Tables: None Excluded Cache Groups: None Excluded sequences: None Element: E Type: Datastore Master Store: CACHEDB1 on TIMESTEN-HOL Transmit Durable Subscriber Store: CACHEDB2 on TIMESTEN-HOL Excluded Tables: None 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: CACHEDB4 on TIMESTEN-HOL Port: (auto) Log Fail Threshold: (none) Retry Timeout: 120 seconds Compress Traffic: Disabled1 replication scheme found.
添加return service
ALTER REPLICATION repscheme1 ALTER ELEMENT E ALTER SUBSCRIBER cachedb2 SET RETURN RECEIPT;
更改复制表
唯一支持复制的命令: ALTER TABLE … ADD COLUMN or ALTER TABLE … DROP COLUMN
如果是双向复制,就必须保证在更改期间没有数据写入
如果有多个alter table语句,就必须保证一个完成后再做下一个
truncate复制表
truncate table是可以复制的
删除复制策略
call ttrepstop;
drop replication repscheme1;
- TimesTen 数据库复制学习:17. 更改classic复制
- TimesTen 数据库复制学习:10. 定义classic复制
- TimesTen 数据库复制学习:18. classic复制的典型设计模式-双向复制
- TimesTen 数据库复制学习:3. 配置Classic Replication单表复制
- TimesTen 数据库复制学习:12. Classic带缓存组复制的几种固定架构模式
- TimesTen 数据库复制学习:9. 更改Active Standby Pair
- TimesTen 数据库复制学习:1. TimesTen复制概述
- TimesTen 数据库复制学习:13. 设置复制系统
- TimesTen 数据库复制学习:15. 监控复制系统
- TimesTen 数据库复制学习:19. 解决复制冲突
- TimesTen 数据库复制学习:2. 配置Active Standby Pair
- TimesTen 数据库复制学习:14. 使用指定端口通讯的数据库复制
- TimesTen 数据库复制学习:4. 定义Active Standby Pair复制策略
- TimesTen 数据库复制学习:5. 设定复制网络传输的return service
- TimesTen 数据库复制学习:6. 利用STORE关键字设定复制网络传输的属性
- TimesTen 数据库复制学习:16. 一个缓存组,复制,客户端自动切换的串烧实验
- TimesTen 数据库复制学习:11. ASP带缓存组复制的几种固定架构模式
- Timesten复制配置
- Poj1386 Play on Words
- find -name a.txt的误用(没考虑软链), 导致浪费0.5小时
- 5.3 输入/输出(I/O)管理
- LCA-倍增思想 POJ1330 Nearest Common Ancestors
- src
- TimesTen 数据库复制学习:17. 更改classic复制
- Properties的解耦实验
- 21. Merge Two Sorted Lists
- 读书笔记-现代操作系统-2进程与线程-2.3进程间通信
- TimesTen 数据库复制学习:19. 解决复制冲突
- bzoj3224 Tyvj1728 普通平衡树
- python3关于urllib中urlopen报错问题的解决
- day2总结--JS切换卡效果(转自个人印象笔记)
- Quick Look Framework