通常,数据库复制时,无需指定固定的复制端口,而是两个数据库之间进行在线协商,使用动态的端口。
不过某些特殊情况下需要指定固定的端口,例如TimesTen的Daemon端口为非缺省时。
下面的例子给出了设置指定固定端口复制的完整过程,为了测试简便,我在一个虚拟机里安装了两个TimesTen实例,它们的版本不同,Daemon端口分别为53392和55555:
[oracle@timesten-hol info]$ ttversion
TimesTen Release 11.2.2.6.2 (64 bit Linux/x86_64) (tt1122:53392) 2014-01-03T07:01:05Z
Instance admin: oracle
Instance home directory: /home/oracle/TimesTen/tt1122
Group owner: oracle
Daemon home directory: /home/oracle/TimesTen/tt1122/info
PL/SQL enabled.
[oracle@timesten-hol info]$ ttversion
TimesTen Release 11.2.2.8.11 (64 bit Linux/x86_64) (ttnew:55555) 2016-02-09T19:36:50Z
Instance admin: oracle
Instance home directory: /u01/TimesTen/ttnew
Group owner: oracle
Daemon home directory: /u01/TimesTen/ttnew/info
PL/SQL enabled.
在instance_info中也可以看到类似的信息:
$ vi /etc/TimesTen/instance_info
#SUM 55602 1
[ tt1122 ]
Product=TimesTen11.2.2.6.2
InstallDir=/home/oracle/TimesTen/tt1122
InstanceAdministrator=oracle
DaemonHome=/home/oracle/TimesTen/tt1122/info
BitLevel=64
Component=Client/Server and DataManager
TT_PORT=53392
[ ttnew ]
Product=TimesTen11.2.2.8.11
InstallDir=/u01/TimesTen/ttnew
InstanceAdministrator=oracle
DaemonHome=/u01/TimesTen/ttnew/info
BitLevel=64
Component=Client/Server and DataManager
TT_PORT=55555
暂且就把这两个实例称为tt1122和ttnew吧。我们准备建立一个active standby pair, active为cachedb1,位于tt1122, standby为cachedb2, 位于ttnew。
首先在不同的终端上启动TimesTen Daemon,由于环境变量不同,启动ttnew时需要先初始化环境变量:
. /u01/TimesTen/ttnew/bin/ttenv.sh
export TT_HOME=/u01/TimesTen/ttnew
ttdaemonadmin -start
然后我们建立一个ASP,并试图克隆standby,失败了,原因是两个数据库实例使用的并非缺省的端口。
cachedb1> CREATE ACTIVE STANDBY PAIR cachedb1 on "timesten-hol", cachedb2 on "timesten-hol";
ttnew$ ttRepAdmin -duplicate -from cachedb1 -host timesten-hol -uid repadmin -pwd timesten cachedb2
TT12039: Could not get port number of TimesTen replication agent on remote host. Either the replication agent was not started, or it was just started and has not communicated its port number to the TimesTen daemon
翻了下手册,发现可用-remoteDaemonPort指定TimesTen Daemon端口,不过仍失败了。因为这个选项不能用于动态端口的情形:
ttnew$ ttRepAdmin -duplicate -from cachedb1 -host timesten-hol -remoteDaemonPort 53392 -uid repadmin -pwd timesten cachedb2
TT12048: Error performing backup at source. More information can be found in the source's message log
TT12048: Error text: [1084782912, 0, noAwt] CACHEDB1:receiver.c(6840): TT16266: The -remoteDaemonPort cannot be used for this -duplicate operation because the sending datastore has stores which use auto automatic port allocation..
在MOS上搜了下,发现只能在创建ASP时指定端口才行,因此,删掉ASP重建:
CREATE ACTIVE STANDBY PAIR cachedb1 on "timesten-hol", cachedb2 on "timesten-hol"
store cachedb1 port 12306 store cachedb2 port 12307;
cachedb1> repschemes;
Replication Scheme Active Standby:
Master Store: CACHEDB1 on TIMESTEN-HOL
Master Store: CACHEDB2 on TIMESTEN-HOL
Excluded Tables:
None
Excluded Cache Groups:
None
Excluded sequences:
None
Store: CACHEDB1 on TIMESTEN-HOL
Port: 12306
Log Fail Threshold: (none)
Retry Timeout: 120 seconds
Compress Traffic: Disabled
Store: CACHEDB2 on TIMESTEN-HOL
Port: 12307
Log Fail Threshold: (none)
Retry Timeout: 120 seconds
Compress Traffic: Disabled
cachedb1> call ttrepstart;
由于只启动了active master数据库的rep agent,因此只有端口12306占用:
[oracle@timesten-hol info]$ netstat -an|grep 12306
tcp 0 0 0.0.0.0:12306 0.0.0.0:* LISTEN
[oracle@timesten-hol info]$ netstat -an|grep 12307
信心满满,居然又失败了!
[oracle@timesten-hol info]$ ttRepAdmin -duplicate -from cachedb1 -host timesten-hol -remoteDaemonPort 53392 -uid repadmin -pwd timesten cachedb2
TT12048: Error performing backup at source. More information can be found in the source's message log
TT8144: [1111923008, 0, noAwt] CACHEDB1:receiver.c(6735): TT8144: Duplicate not permitted.
Reason: Attempted duplicate from a non-ACTIVE Master to Master. Duplicate is only permitted from the ACTIVE store to the STANDBY store, from the STANDBY store to a SUBSCRIBER, or from the ACTIVE store to a SUBSCRIBER if the STANDBY store has failed
TT16025: [1111923008, 0, noAwt] CACHEDB1:repagent.c(1227): TT16025: Thread 'RECEIVER' (context 0x4826d50) starting
不过错误很明显,因为active master的角色没有设置。
cachedb1> call ttrepstateset('active');
cachedb1> call ttrepstateget;
< ACTIVE, NO GRID >
一波三折,终于成功了!!!
[oracle@timesten-hol info]$ ttRepAdmin -duplicate -from cachedb1 -host timesten-hol -
remoteDaemonPort 53392 -uid repadmin -pwd timesten cachedb2
[oracle@timesten-hol info]$ echo $?
0
启动standby的rep agent,自动进入STANDBY状态
ttnew$ ttisql -v1 -e "set prompt 'cachedb2> '" "dsn=cachedb2;uid=tthr;pwd=timesten;oraclepwd=oracle"
cachedb2> call ttrepstateget;
< IDLE, NO GRID >
cachedb2> call ttrepstart;
cachedb2> call ttrepstateget;
< STANDBY, NO GRID >
cachedb2> repschemes;
Replication Scheme Active Standby:
Master Store: CACHEDB1 on TIMESTEN-HOL
Master Store: CACHEDB2 on TIMESTEN-HOL
Excluded Tables:
None
Excluded Cache Groups:
None
Excluded sequences:
None
Store: CACHEDB1 on TIMESTEN-HOL
Port: 12306
Log Fail Threshold: (none)
Retry Timeout: 120 seconds
Compress Traffic: Disabled
Store: CACHEDB2 on TIMESTEN-HOL
Port: 12307
Log Fail Threshold: (none)
Retry Timeout: 120 seconds
Compress Traffic: Disabled
cachedb2>
这时可以看到端口的状态:
[oracle@timesten-hol info]$ netstat -a|grep 12306
tcp 0 0 *:12306 *:* LISTEN
tcp 0 0 timesten-hol:29005 timesten-hol:12306 ESTABLISHED
tcp 0 0 timesten-hol:12306 timesten-hol:29005 ESTABLISHED
[oracle@timesten-hol info]$ netstat -an|grep 12307
tcp 0 0 0.0.0.0:12307 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:12307 127.0.0.1:57495 ESTABLISHED
tcp 0 0 127.0.0.1:57495 127.0.0.1:12307 ESTABLISHED
[root@timesten-hol ~]# lsof|grep 12307
timestenr 4860 oracle 17u IPv4 20352 TCP timesten-
hol:57495->timesten-hol:12307 (ESTABLISHED)
timestenr 4939 oracle 13u IPv4 20345 TCP *:12307 (LISTEN)
timestenr 4939 oracle 16u IPv4 20353 TCP timesten-
hol:12307->timesten-hol:57495 (ESTABLISHED)
[root@timesten-hol ~]# lsof|grep 12306
timestenr 4860 oracle 13u IPv4 19992 TCP *:12306 (LISTEN)
timestenr 4860 oracle 15u IPv4 20347 TCP timesten-
hol:12306->timesten-hol:29005 (ESTABLISHED)
timestenr 4939 oracle 15u IPv4 20346 TCP timesten-
hol:29005->timesten-hol:12306 (ESTABLISHED)
最终可以看到TRANSMITTER和RECEIVER subdaemon;
[oracle@timesten-hol info]$ ttstatus
TimesTen status report as of Wed Jun 29 00:41:20 2016
Daemon pid 4611 port 55555 instance ttnew
TimesTen server pid 4620 started on port 55556
------------------------------------------------------------------------
Data store /home/oracle/TimesTen/tt1122/info/DemoDataStore/cachedb2
There are 18 connections to the data store
Shared Memory KEY 0x0a020080 ID 2719764
PL/SQL Memory KEY 0x0b020080 ID 2752533 Address 0x7fa0000000
Type PID Context Connection Name ConnID
Replication 4939 0x000000000320bd70 LOGFORCE:0x411b8940 127
Replication 4939 0x000000000328eb50 REPHOLD:0x40444940 130
Replication 4939 0x00000000032fb870 TRANSMITTER(M):0x41b31940 126
Replication 4939 0x0000000003398f70 RECEIVER:0x41e32940 125
Replication 4939 0x00007f65f8002e20 REPLISTENER:0x40c38940 131
Replication 4939 0x00007f66000008c0 FAILOVER:0x40937940 128
Replication 4939 0x00007f6600015b40 XLA_PARENT:0x41830940 129
Subdaemon 4615 0x00000000016e2350 Manager 142
Subdaemon 4615 0x0000000001759a80 Rollback 141
Subdaemon 4615 0x000000000181b250 Deadlock Detector 140
Subdaemon 4615 0x0000000001860620 Log Marker 138
Subdaemon 4615 0x00000000018b58e0 Checkpoint 137
Subdaemon 4615 0x000000000190aba0 Monitor 136
Subdaemon 4615 0x000000000195fe60 Aging 135
Subdaemon 4615 0x0000000001a24070 Flusher 134
Subdaemon 4615 0x0000000001a44860 HistGC 139
Subdaemon 4615 0x0000000001b26c40 AsyncMV 132
Subdaemon 4615 0x00007f88fc0008c0 IndexGC 133
Replication policy : Manual
Replication agent is running.
Cache Agent policy : Manual
PL/SQL enabled.
------------------------------------------------------------------------
Accessible by group oracle
End of report
* HOWTO : Resolve TimesTen Error TT12039 - Could not get port number of TimesTen replication agent on remote host. (Doc ID 855521.1)
* HOWTO : Resolve TimesTen Error TT12038 When Configuring/Starting Replication (Doc ID 420004.1)
* TT12038: Could Not Connect To Timesten Daemon On Remote Host %S (Doc ID 563391.1)