源端(RAC) | 目标端(FS) | |
---|---|---|
IP | 192.168.40.30/31 | 192.168.40.50 |
数据库版本 | Oracle 19.3.0 | Oracle 19.3.0 |
主机名 | hfdb30/hfdb31 | hfogg |
操作系统 | REHL7.6 | REHL7.6 |
数据库实例 | hfdb1/hfdb2 | hfogg |
同步用户 | hfdb1 | hfdb1 |
同步表 | test | test |
OGG版本 | 19.1.0.0.4 | 19.1.0.0.4 |
上传并安装 OGG 软件
#在两台ogg设备上都创建目录
mkdir /ggs
mount /dev/mapper/backvg-backuplv /ggs
vi /etc/fstab
chown -R oracle:dba /ggs
chmod -R 777 /ggs
源端:vim .bash_profile
##原有配置不变,增加 ogg 相关路径
export OGG_HOME=/ggs
export PATH=$ORACLE_HOME/bin:$PATH:$ORACLE_HOME/OPatch:$OGG_HOME
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib
目标端:vim .bash_profile
##原有配置不变,增加 ogg 相关路径
export OGG_HOME=/ggs
export PATH=$ORACLE_HOME/bin:$PATH:$ORACLE_HOME/OPatch:$OGG_HOME
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib
使环境变量生效
source .bash_profile
上传安装包并解压
下载地址:https://edelivery.oracle.com/
源端和目标端都需上传
su - root
cd /backup
unzip V983658-01.zip
chown -R oracle:oinstall /backup/*
安装 OGG
图形化安装
- 两种方式:
- 安装vncserver
su - oracle
[oracle@hfdb30:/backup]$vncserver #源端和目标端都要执行
[oracle@hfdb30:/backup]$cd /backup/fbo_ggs_Linux_x64_shiphome/Disk1
[oracle@hfdb30:/backup]$./runInstaller
- 使用display
su - oracle
cd /backup/fbo_ggs_Linux_x64_shiphome/Disk1
export DISPLAY=192.168.40.50:0.0
./runInstaller
在 Oracle 11g 及之前的版本中,安装完 OGG,需要使用 ggsci 工具执行 create subdirs 命令手动创建 OGG 对应的目录,在 12c 及以后版本中,目录自动创建,无需再手动执行 create subdirs 命令。
静默安装
cp /backup/fbo_ggs_Linux_x64_shiphome/Disk1/response/oggcore.rsp ~/
编辑配置文件
#vim ~/oggcore.rsp
INSTALL_OPTION=ORA19c
SOFTWARE_LOCATION=/ggs
START_MANAGER=true
MANAGER_PORT=7809
DATABASE_LOCATION=/oracle/app/oracle/product/19.3.0/dbhome_1
INVENTORY_LOCATION=/oracle/app/oraInventory
UNIX_GROUP_NAME=oinstall
开始安装
cd /u01/soft/fbo_ggs_Linux_x64_shiphome/Disk1/
./runInstaller -silent -nowait -responseFile ~/oggcore.rsp
ogg 配置运行环境准备
01.源端一定要打开归档,目标端一般不需要。
02.源数据库打开补充日志
03.源端开启 force_logging
04.源端关闭回收站功能(下次重启生效,10g 要关,11g 手册说不用关了)
05.修改数据库参数(源端、目标端)
alter system set enable_goldengate_replication=true;
06.源和目标网络通讯正常。
07.创建专用的 goldengate 用户用来同步数据(源端、目标端)。
源端一定要打开归档,目标端一般不需要。
创建一个归档目录并授权
[oracle@hfdb30:/home/oracle]$mkdir /oracle/archive
[oracle@hfdb30:/home/oracle]$chown -R oracle:dba /oracle/archive
[oracle@hfdb30:/home/oracle]$chmod -R 777 /oracle/archive
SQL> show parameter recovery
SQL> alter system set db_recovery_file_dest_size=100g;
SQL> alter system set db_recovery_file_dest='/oracle/archive';
SQL> shutdown immediate
SQL> startup mount
SQL> alter database archivelog;
SQL> alter database open;
SQL> archive log list
SQL> alter system switch logfile; --【alter system archive log current; 】
源数据库打开补充日志
SQL> select supplemental_log_data_min from v$database; --【no 就是没有打开】
SQL> alter database add supplemental log data;
SQL> select supplemental_log_data_min from v$database; --【YES】
#检查下归档日志,归档日志正常切换说明就成功了
SQL> alter system switch logfile;
源端开启 force_logging 【强制日志】
SQL> select force_logging from v$database; --【no】
SQL> alter database force logging;
SQL> select force_logging from v$database; --【YES】
SQL> **alter system switch logfile;**
启用 OGG(源端、目标端)
ALTER SYSTEM SET ENABLE_GOLDENGATE_REPLICATION = TRUE SCOPE=BOTH; #源端和目标端都要做
源端关闭回收站功能(下次重启生效)
SQL> show parameter recyclebin
SQL> alter system set recyclebin=off scope=spfile;
SQL> shutdown immediate
SQL> startup
查看配置结果
select log_mode,supplemental_log_data_min,force_logging from v$database; #archivelog yes yes
源和目标网络通讯正常。
配置hosts (非必须)
[root@hfdb30 ~]# cat /etc/hosts --添加另外一台主机名和IP
[root@hfdb31 ~]# cat /etc/hosts --添加另外一台主机名和IP
[root@hfogg ~]# cat /etc/hosts --添加另外一台主机名和IP
[root@hfdb30 ~]# ping hfogg
[root@hfogg ~]# ping hfdb30
配置tnsname
[oracle@hfdb30:/oracle/app/oracle/product/19c/db_1/network/admin]$vi tnsnames. ora
# tnsnames.ora Network Configuration File: /oracle/app/oracle/product/19c/db_1/network/admin/tnsnames.ora
# Generated by Oracle configuration tools.
DGHFDB =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.40.40)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = dghfdb)
)
)
HFDB =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = hfdbscan)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = hfdb)
)
)
HFOGG =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.40.50)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = hfogg)
)
)
[oracle@hfogg:/oracle/app/oracle/product/19c/db_1/network/admin]$vi tnsnames.ora
# tnsnames.ora Network Configuration File: /oracle/app/oracle/product/19c/db_1/network/admin/tnsnames.ora
# Generated by Oracle configuration tools.
LISTENER_HFOGG =
(ADDRESS = (PROTOCOL = TCP)(HOST = hfogg)(PORT = 1521))
HFOGG =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = hfogg)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = hfogg)
)
)
HFDB =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.40.32)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = hfdb)
)
)
[oracle@hfogg:/oracle/app/oracle/product/19c/db_1/network/admin]$tnsping hfdb
TNS Ping Utility for Linux: Version 19.0.0.0.0 - Production on 19-NOV-2024 19:27:45
Copyright (c) 1997, 2019, Oracle. All rights reserved.
Used parameter files:
Used TNSNAMES adapter to resolve the alias
Attempting to contact (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.40.32)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = hfdb)))
OK (10 msec)
[oracle@hfogg:/oracle/app/oracle/product/19c/db_1/network/admin]$
[oracle@hfdb30:/oracle/app/oracle/product/19c/db_1/network/admin]$tnsping hfogg
TNS Ping Utility for Linux: Version 19.0.0.0.0 - Production on 19-NOV-2024 19:28:29
Copyright (c) 1997, 2019, Oracle. All rights reserved.
Used parameter files:
Used TNSNAMES adapter to resolve the alias
Attempting to contact (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.40.50)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = hfogg)))
OK (0 msec)
[oracle@hfdb30:/oracle/app/oracle/product/19c/db_1/network/admin]$
创建专用的 goldengate 用户用来同步数据
(源端和目标端都要执行)
#在rac节点hfdb30上面执行
create tablespace ogg_tbs datafile
'+dgsystem1' size 50m autoextend
on next 10m maxsize 1024m extent management local segment space management auto;
create user goldengate identified by goldengate default tablespace ogg_tbs temporary tablespace temp quota unlimited on users ;
grant connect to goldengate;
grant alter any table to goldengate;
grant alter session to goldengate;
grant create session to goldengate;
grant flashback any table to goldengate;
grant select any dictionary to goldengate;
grant select any table to goldengate;
grant resource to goldengate;
grant drop any table to goldengate;
grant dba to goldengate;
#在目标库hfogg上面执行
create tablespace ogg_tbs datafile '/oradata/hfogg/ogg.dbf' size 50m autoextend on next 10m maxsize 1024m extent management local segment space management auto;
create user goldengate identified by goldengate default tablespace ogg_tbs temporary tablespace temp quota unlimited on users ;
grant connect to goldengate;
grant alter any table to goldengate;
grant alter session to goldengate;
grant create session to goldengate;
grant flashback any table to goldengate;
grant select any dictionary to goldengate;
grant select any table to goldengate;
grant resource to goldengate;
grant drop any table to goldengate;
grant dba to goldengate;
ogg源端配置过程
ogg 的配置过程(源端)
配置管理进程 mgr
[oracle@hfogg:/ggs]$ggsci
ggsci> CREATE SUBDIRS --【安装中没有勾选,这里需要创建目录】
--01.配置管理进程 mgr
ggsci> edit params mgr
port 7809
autostart er *
autorestart er *,waitminutes 3,retries 15
purgeoldextracts ./dirdat/*,usecheckpoints,minkeepdays 7
ggsci>start mgr
*/
其他可加的参数含义
##########################
/*
DYNAMICPORTLIST 7810-7820
LAGREPORTHOURS 1
LAGINFOMINUTES 30
LAGCRITICALMINUTES 45
ACCESSRULE,PROG *,IPADDR 192.168.*.*,ALLOW
----参数含义
PORT:默认监听端口
DYNAMICPORTLIST:动态端口列表的范围,当指定端口被占用或者出现通 信故障,管理进程将会从列表中选择下一个端口尝试连接,避免通信端口的单点故障。
AUTORESTART:当提取进程中断后尝试自动重启,每隔 3 分钟尝试启动一次,尝试 15 次。
PURGEOLDEXTRACTS:定期清理 dirdat 路径下的本地队列(local trail)。保留期限 7 天,过期后自动删除。
LAGREPORTHOURS:每隔一小时检查一次传输延迟情况
LAGINFOMINUTES:传输延时超过 30 分钟将写入错误日志
LAGCRITICALMINUTES:传输延时超过 45 分钟将写入警告日志
#操作日志
[oracle@hfdb30:/home/oracle]$ggsci
Oracle GoldenGate Command Interpreter for Oracle
Version 19.1.0.0.4 OGGCORE_19.1.0.0.0_PLATFORMS_191017.1054_FBO
Linux, x64, 64bit (optimized), Oracle 19c on Oct 17 2019 21:16:29
Operating system character set identified as US-ASCII.
Copyright (C) 1995, 2019, Oracle and/or its affiliates. All rights reserved.
GGSCI (hfdb30) 1> CREATE SUBDIRS
Creating subdirectories under current directory /home/oracle
Parameter file /ggs/dirprm: already exists.
Report file /ggs/dirrpt: already exists.
Checkpoint file /ggs/dirchk: already exists.
Process status files /ggs/dirpcs: already exists.
SQL script files /ggs/dirsql: already exists.
Database definitions files /ggs/dirdef: already exists.
Extract data files /ggs/dirdat: already exists.
Temporary files /ggs/dirtmp: already exists.
Credential store files /ggs/dircrd: already exists.
Masterkey wallet files /ggs/dirwlt: already exists.
Dump files /ggs/dirdmp: already exists.
GGSCI (hfdb30) 2> edit params mgr
GGSCI (hfdb30) 3> start mgr
MGR is already running.
GGSCI (hfdb30) 4> info all
Program Status Group Lag at Chkpt Time Since Chkpt
MANAGER RUNNING
配置检查点
ggsci> edit params ./GLOBALS
checkpointtable goldengate.checkpoint
ggsci> dblogin userid goldengate,password goldengate
ggsci> add checkpointtable goldengate.checkpoint
GGSCI (hfdb30) 6> edit params ./GLOBALS
GGSCI (hfdb30) 7> dblogin userid goldengate,password goldengate
Successfully logged into database.
GGSCI (hfdb30 as goldengate@hfdb1) 8> add checkpointtable goldengate.checkpoint
Successfully created checkpoint table goldengate.checkpoint.
GGSCI (hfdb30 as goldengate@hfdb1) 9>
在源端配置抽取进程 extract
cd /ggs
mkdir -p ./dirdat/eitpux01
mkdir -p ./dirrpt/eitpux01
ggsci> edit params eitpux01
extract eitpux01
userid goldengate,password goldengate
exttrail ./dirdat/eitpux01/ex
tranlogoptions excludeuser goldengate
tranlogoptions dblogreader
warnlongtrans 12h,checkinterval 30m
discardfile ./dirrpt/eitpux01/eitpux01.dsc,append,megabytes 200
TABLE hfdb1.*;
/*
extract ext_che
SETENV (ORACLE_SID="orcl1")
SETENV (NLS_LANG="SIMPLIFIED CHINESE_CHINA.AL32UTF8")
userid c##ogg,password 123456
DBOPTIONS ALLOWUNUSEDCOLUMN
DISCARDFILE ./dirrpt/ext_che.dsc, APPEND,MEGABYTES 1024
DISCARDROLLOVER AT 22:00 ON SUNDAY
EXTTRAIL ./dirdat/ch
GETTRUNCATES
WARNLONGTRANS 2H,CHECKINTERVAL 5M
FETCHOPTIONS NOUSESNAPSHOT
REPORTCOUNT EVERY 30 MINUTES, RATE
DDL INCLUDE MAPPED
DDLOPTIONS ADDTRANDATA
DDLOPTIONS REPORT
TABLE PDB1.CHE.REGIONS;
SETENV:配置 Oracle 环境变量
userid:登录 Oracle 数据库用户名和密码
DISCARDFILE:将执行失败的记录保存在 discard file 中,大小为 1024 MB,记录方式为追加。
DISCARDROLLOVER:为了防止 discard file 被写满,周日 22:00 做一次文件过期设定
EXTTRAIL:队列文件路径
GETTRUNCATES:捕获源端 truncate table 的操作
2) 添加抽取进程
##sqlplus 中查询将上述的 scn 转换为时间点
select to_char(scn_to_timestamp(2375295), 'yyyy-mm-dd hh24:mi:ss') scndate from dual;
##根据指定时间点配置抽取进程
add extract ext_che, integrated tranlog,begin 2023-01-13 12:36:45
add exttrail ./dirdat/ch,extract ext_che
--添加一个抽取进程
ggsci > add extract eitpux01,tranlog,begin now,threads 2
--配置抽取队列文件
ggsci > add exttrail ./dirdat/eitpux01/ex,extract eitpux01,megabytes 200
启动停止测试
ggsci> start eitpux01
ggsci> stop eitpux01
ggsci> view report eitpux01
GGSCI (hfdb30) 5> start eitpux01
Sending START request to MANAGER ...
EXTRACT EITPUX01 starting
GGSCI (hfdb30) 6> stop eitpux01
EXTRACT EITPUX01 is already stopped.
GGSCI (hfdb30) 7> view report eitpux01
***********************************************************************
Oracle GoldenGate Capture for Oracle
Version 19.1.0.0.4 OGGCORE_19.1.0.0.0_PLATFORMS_191017.1054_FBO
Linux, x64, 64bit (optimized), Oracle 19c on Oct 17 2019 21:16:58
Copyright (C) 1995, 2019, Oracle and/or its affiliates. All rights reserved.
Starting at 2024-11-19 19:57:09
***********************************************************************
Operating System Version:
Linux
Version #1 SMP Thu Oct 4 20:48:51 UTC 2018, Release 3.10.0-957.el7.x86_64
Node: hfdb30
Machine: x86_64
soft limit hard limit
Address Space Size : unlimited unlimited
Heap Size : unlimited unlimited
File Size : unlimited unlimited
CPU Time : unlimited unlimited
Process id: 6003
Description:
***********************************************************************
** Running with the following parameters **
***********************************************************************
2024-11-19 19:57:09 INFO OGG-03059 Operating system character set identified as US-ASCII.
2024-11-19 19:57:09 INFO OGG-02695 ANSI SQL parameter syntax is used for parameter parsing.
extract eitpux01
userid goldengate,password ***
Source Context :
SourceModule : [er.init]
SourceID : [er/init.cpp]
SourceMethod : [get_infile_params]
SourceLine : [6841]
ThreadBacktrace : [11] elements
: [/ggs/libgglog.so(CMessageContext::AddThreadContext())]
: [/ggs/libgglog.so(CMessageFactory::CreateMessage(CSourceContext*, unsigned int, ...))]
: [/ggs/libgglog.so(_MSG_String(CSourceContext*, int, char const*, CMessageFactory::MessageDisposition))]
: [/ggs/extract()]
: [/ggs/extract()]
: [/ggs/extract(ggs::gglib::MultiThreading::MainThread::ExecMain())]
: [/ggs/extract(ggs::gglib::MultiThreading::Thread::RunThread(ggs::gglib::MultiThreading::Thread::ThreadArgs*))]
: [/ggs/extract(ggs::gglib::MultiThreading::MainThread::Run(int, char**))]
: [/ggs/extract(main)]
: [/lib64/libc.so.6(__libc_start_main)]
: [/ggs/extract()]
2024-11-19 19:57:12 ERROR OGG-00303 Unable to connect to database using user goldengate. Ensure that the necessary privileges are granted to the user.
Operation not supported because enable_goldengate_replication is not set to true.
2024-11-19 19:57:12 ERROR OGG-01668 PROCESS ABENDING.
GGSCI (hfdb30) 8>
在源端配置投递进程 pump
cd /ggs
mkdir -p ./dirdat/ritpux01
mkdir -p ./dirrpt/ritpux01
ggsci> edit params pitpux01
extract pitpux01
userid goldengate,password goldengate
PASSTHRU
RMTHOST 192.168.40.50,MGRPORT 7809
rmttrail ./dirdat/ritpux01/re
discardfile ./dirrpt/ritpux01/ritpux01.dsc,append,megabytes 200
TABLE hfdb1.*;
----参数含义
PASSTHRU:采用 pass-through 模式处理表,不登录到数据库
RMTHOST:目标端主机 IP,管理进程端口号,投递前压缩队列文件
RMTTRAIL:目标端保存队列文件的目录
–增加 pump 进程 (指定本地 trail 文件)
ggsci> add extract pitpux01,exttrailsource ./dirdat/eitpux01/ex
–增加 rmttail 文件
ggsci> add rmttrail ./dirdat/ritpux01/re,extract pitpux01,megabytes 200
–检查:
ggsci> info pitpux01
GGSCI (hfdb30) 4> info pitpux01
EXTRACT PITPUX01 Initialized 2024-11-19 20:06 Status STOPPED
Checkpoint Lag 00:00:00 (updated 00:01:08 ago)
Log Read Checkpoint File ./dirdat/eitpux01/ex000000000
First Record RBA 0
ogg 配置的过程(目标端)
配置目标端 mgr 管理
ggsci> edit params mgr
port 7809
autostart er *
autorestart er *,waitminutes 3,retries 15
purgeoldextracts ./dirdat/*,usecheckpoints,minkeepdays 7
ggsci> start mgr
ggsci> info mgr
GGSCI (hfogg) 3> start mgr
MGR is already running.
GGSCI (hfogg) 4> info mgr
Manager is running (IP port TCP:hfogg.7809, Process ID 7564).
配置检查点
ggsci> edit params ./GLOBALS
checkpointtable goldengate.checkpoint
ggsci> dblogin userid goldengate,password goldengate
ggsci> add checkpointtable goldengate.checkpoint
配置复制进程 replicat (目标端) --用oracle用户
cd /ggs
mkdir -p ./dirdat/ritpux01
mkdir -p ./dirrpt/ritpux01
ggsci> edit params ritpux01
replicat ritpux01
userid goldengate,password goldengate
handlecollisions
assumetargetdefs
discardfile ./dirrpt/ritpux01/ritpux01.dsc,append,megabytes 200
map hfdb1.*,target hfdb1.*;
--添加 replicat 进程
ggsci> add replicat ritpux01 exttrail ./dirdat/ritpux01/re,checkpointtable goldengate.checkpoint
GGSCI (hfogg) 3> info all
Program Status Group Lag at Chkpt Time Since Chkpt
MANAGER RUNNING
REPLICAT STOPPED RITPUX01 00:00:00 00:00:13
ogg rac-expdp-impdp初始化
源端启动 extract 进程 (关键 1)
源和目标的 mgr 进程一定要先启动。
ggsci> start mgr
ggsci> start eitpux01
ggsci> info all
备份源端数据库(expdp)
注意一定要在抽取进程 启动后再进行数据库备份(关键2)
sql>select current_scn from v$database;
12345678
create directory hfbak as '/home/oracle'; --上步已经创建了,这里没有再操作了。
grant read,write on directory hfbak to system;
grant create any directory to system;
expdp system/oracle directory=hfbak dumpfile=expdp_hffs_m.dmp logfile=expdp_hffs_m.log flashback_scn=12345678 schemas=hfdb1
把备份文件拷贝到目标库
scp 命令拷贝
在目标库恢复数据库(impdp)
create directory hfbak as '/home/oracle';
grant read,write on directory hfbak to system;
grant create any directory to system;
impdp system/oracle directory=hfbak dumpfile=expdp_hffs_m.dmp logfile=expdp_out_m.log full=y table_exists_action=truncate
disable 目标库所有的 trigger、cascading delete 、check、 job
收集统计信息
[oracle@racdb1 backup]$ cat tjxjogg.sh
#!/bin/sh
export ORACLE_SID=ora11g
export ORACLE_BASE=/u01/app/oracle/
export ORACLE_HOME=/u01/app/oracle/product/11.2.0.4/dbhome_1
$ORACLE_HOME/bin/sqlplus / as sysdba <<EOF > /backup/tjxjogg.log
SELECT TO_CHAR(SYSDATE, 'YYYY-MM-DD HH24:MI:SS') FROM DUAL;
begin
dbms_stats.gather_schema_stats(ownname=> '"WYY"' ,
cascade=> TRUE,
estimate_percent=> null,
degree=> 4,
no_invalidate=> DBMS_STATS.AUTO_INVALIDATE,
granularity=> 'AUTO',
method_opt=> 'FOR ALL COLUMNS SIZE AUTO',
options=> 'GATHER');
end;
/
SELECT TO_CHAR(SYSDATE, 'YYYY-MM-DD HH24:MI:SS') FROM DUAL;
exit;
EOF
目标库匹配导入导出数据行数
[oracle@ expdp]$ grep " rows" expogg0908.log |sort -n| awk '{print $4,$7,$8}'
|awk -F "." '{print $2}'> /tmp/exp.a
[oracle@expdp]$ grep " rows" impogg0908.log |sort -n| awk '{print
$4,$7,$8}'|awk -F "." '{print $2}'> /tmp/imp.b
[oracle@racdb1 expdp]$ diff /tmp/exp.a /tmp/imp.b #此时没有结果输出说明导入导出数据行数一致
禁用目标库约束
#参数 owner_list 里面的用户名请根据实际情况修改
#禁用约束脚本如下:
racdb1:/home/oracle/ogg$cat disable_cascade.sql
set serveroutput on size 1000000
spool /home/oracle/disable_cascade.log
define owner_list=" in ('WYY','OGGWMS') "
declare
cursor c is SELECT A.OWNER, A.TABLE_NAME,A.CONSTRAINT_NAME, C.COLUMN_NAME,
A.STATUS,A.DELETE_RULE,B.TABLE_NAME REFER_TABLE
FROM dba_CONSTRAINTS A,dba_CONSTRAINTS B,dba_CONS_COLUMNS C
WHERE A.R_CONSTRAINT_NAME=B.CONSTRAINT_NAME
AND A.CONSTRAINT_NAME=C.CONSTRAINT_NAME
AND A.status ='ENABLED'
AND A.delete_rule like '%CASCADE%'
and A.owner &owner_list;
temp varchar2(512);
begin
dbms_output.put_line('-- BEGIN ALTER TABLE DISABBLE CASCADE --');
dbms_output.put_line('-- WAIT FOR A MONENT --');
dbms_output.put_line('--...................--');
for x in c loop
temp := 'ALTER TABLE "' || x.OWNER || '"."' || x.TABLE_NAME || '" DISABLE
CONSTRAINT "'|| x.CONSTRAINT_NAME||'"';
execute immediate temp;
dbms_output.put_line('--DISABLE CONSTRAINT'||
x.OWNER||'.'||x.CONSTRAINT_NAME||' SUCCESSFUL--') ;
end loop;
dbms_output.put_line('-- END ALTER TABLE DISABBLE CASCADE --');
end;
/
spool off
禁用目标库触发器
#参数 owner_list 里面的用户名请根据实际情况修改
#禁用触发器脚本如下:
racdb1:/home/oracle/ogg$cat disable_trigger.sql
set serveroutput on size 1000000
spool /home/oracle/disable_trigger.log
define owner_list=" in ('WYY','OGGWMS')"
declare
cursor c is SELECT OWNER,TRIGGER_NAME FROM dba_triggers WHERE status ='ENABLED'
and owner &owner_list;
temp varchar2(512);
begin
dbms_output.put_line('-- BEGIN DISABBLE TRIGGERS --');
dbms_output.put_line('-- WAIT FOR A MONENT --');
dbms_output.put_line('--...................--');
for x in c loop
temp := 'ALTER TRIGGER "'||x.OWNER||'"."'||x.TRIGGER_NAME||'" DISABLE';
execute immediate temp;
dbms_output.put_line('--DISABLE
TRIGGER'||x.OWNER||'.'||x.TRIGGER_NAME||' SUCCESSFUL--') ;
end loop;
dbms_output.put_line('-- END ALTER TABLE DISABBLE TRIGGERS --');
end;
/
spool off
禁用 job
conn oggspa/spaora
spool disable_job.sql
set pagesize 999;
select 'execute DBMS_IJOB.BROKEN('||job||',TRUE); commit;'
from dba_jobs where BROKEN='N';
spool off
'EXECUTEDBMS_SCHEDULER.STOP_JOB('||JOB_NAME||');COMMIT;'
------------------------------------------------------------------------
execute DBMS_SCHEDULER.stop_job(QUEST_PPCM_JOB_PM_1); commit;
execute DBMS_SCHEDULER.stop_job(JOB_PLANDT_AUTOADD); commit;
--关闭 job
set echo off
set verify off
set feedback off
set pagesize 10000
set heading off
set lines 100
spool disable_job.sql
set pagesize 999;
set linesize 200;
set heading off;
select 'execute DBMS_IJOB.BROKEN('||job||',TRUE); commit;'
from dba_jobs where BROKEN='N';
spool off
--关闭触发器
spool disable_triggers.sql
select 'alter trigger '||owner||'.'||trigger_name||' disable;'
from dba_triggers where owner in ('WYY') and status='ENABLED'
order by status,owner;
spool off
--禁用约束
spool disable_constraints1.sql
select 'alter table '||owner||'.'||table_name||' disable constraint
'||constraint_name||';'
from dba_constraints
where constraint_type in ('R') and owner='WYY'
order by status,owner;
spool off
目标端启动 replicate 进程
–源端开启投递进程:
ggsci> start eitpux01 --这个从备份开始,就应该一直启动。
ggsci> start pitpux01
ggsci> info all
GGSCI (hfdb30) 7> start pitpux01
Sending START request to MANAGER ...
EXTRACT PITPUX01 starting
GGSCI (hfdb30) 8> info all
Program Status Group Lag at Chkpt Time Since Chkpt
MANAGER RUNNING
EXTRACT STOPPED EITPUX01 00:00:00 00:25:01
EXTRACT STOPPED PITPUX01 00:00:00 00:15:18
–目标端开启复制进程
ggsci> start ritpux01,aftercsn 1341822
ggsci> info all
ggsci> view report ritpux01
select checkpoint_change#,file# from v$datafile_header;