源端:
SQL> GRANT EXECUTE ON utl_file TO scofy;
SQL> GRANT CREATE TABLE,CREATE SEQUENCE TO scofy;
SQL> alter system set recyclebin=off scope=spfile;
SQL> @marker_setup.sql
Marker setup script
You will be prompted for the name of a schema for the Oracle GoldenGate database objects.
NOTE: The schema must be created prior to running this script.
NOTE: Stop all DDL replication before starting this installation.
Enter Oracle GoldenGate schema name:scofy
Marker setup table script complete, running verification script...
Please enter the name of a schema for the GoldenGate database objects:
Setting schema name to SCOFY
MARKER TABLE
-------------------------------
OK
MARKER SEQUENCE
-------------------------------
OK
Script complete.
SQL> @ddl_setup.sql
Oracle GoldenGate DDL Replication setup script
Verifying that current user has privileges to install DDL Replication...
You will be prompted for the name of a schema for the Oracle GoldenGate database objects.
NOTE: For an Oracle 10g source, the system recycle bin must be disabled. For Oracle 11g and later, it can be
enabled.
NOTE: The schema must be created prior to running this script.
NOTE: Stop all DDL replication before starting this installation.
Enter Oracle GoldenGate schema name:scofy
Working, please wait ...
Spooling to file ddl_setup_spool.txt
Checking for sessions that are holding locks on Oracle Golden Gate metadata tables ...
Check complete.
Using SCOFY as a Oracle GoldenGate schema name.
Working, please wait ...
DDL replication setup script complete, running verification script...
Please enter the name of a schema for the GoldenGate database objects:
Setting schema name to SCOFY
CLEAR_TRACE STATUS:
Line/pos Error
-------------------- -----------------------------------------------------------------
No errors No errors
CREATE_TRACE STATUS:
Line/pos Error
-------------------- -----------------------------------------------------------------
No errors No errors
TRACE_PUT_LINE STATUS:
Line/pos Error
-------------------- -----------------------------------------------------------------
No errors No errors
INITIAL_SETUP STATUS:
Line/pos Error
-------------------- -----------------------------------------------------------------
No errors No errors
DDLVERSIONSPECIFIC PACKAGE STATUS:
Line/pos Error
-------------------- -----------------------------------------------------------------
No errors No errors
DDLREPLICATION PACKAGE STATUS:
Line/pos Error
-------------------- -----------------------------------------------------------------
No errors No errors
DDLREPLICATION PACKAGE BODY STATUS:
Line/pos Error
-------------------- -----------------------------------------------------------------
No errors No errors
DDL IGNORE TABLE
-----------------------------------
OK
DDL IGNORE LOG TABLE
-----------------------------------
OK
DDLAUX PACKAGE STATUS:
Line/pos Error
-------------------- -----------------------------------------------------------------
No errors No errors
DDLAUX PACKAGE BODY STATUS:
Line/pos Error
-------------------- -----------------------------------------------------------------
No errors No errors
SYS.DDLCTXINFO PACKAGE STATUS:
Line/pos Error
-------------------- -----------------------------------------------------------------
No errors No errors
SYS.DDLCTXINFO PACKAGE BODY STATUS:
Line/pos Error
-------------------- -----------------------------------------------------------------
No errors No errors
DDL HISTORY TABLE
-----------------------------------
OK
DDL HISTORY TABLE(1)
-----------------------------------
OK
DDL DUMP TABLES
-----------------------------------
OK
DDL DUMP COLUMNS
-----------------------------------
OK
DDL DUMP LOG GROUPS
-----------------------------------
OK
DDL DUMP PARTITIONS
-----------------------------------
OK
DDL DUMP PRIMARY KEYS
-----------------------------------
OK
DDL SEQUENCE
-----------------------------------
OK
GGS_TEMP_COLS
-----------------------------------
OK
GGS_TEMP_UK
-----------------------------------
OK
DDL TRIGGER CODE STATUS:
Line/pos Error
-------------------- -----------------------------------------------------------------
No errors No errors
DDL TRIGGER INSTALL STATUS
-----------------------------------
OK
DDL TRIGGER RUNNING STATUS
----------------------------------------------------------------------
ENABLED
STAYMETADATA IN TRIGGER
----------------------------------------------------------------------
OFF
DDL TRIGGER SQL TRACING
----------------------------------------------------------------------
0
DDL TRIGGER TRACE LEVEL
----------------------------------------------------------------------
0
LOCATION OF DDL TRACE FILE
-----------------------------------------------------------------------------------------------------------------
-------
/oradata/app/oracle/diag/rdbms/source2/source2/trace/ggs_ddl_trace.log
Analyzing installation status...
STATUS OF DDL REPLICATION
-----------------------------------------------------------------------------------------------------------------
-------
SUCCESSFUL installation of DDL Replication software components
Script complete.
SQL> @role_setup.sql
GGS Role setup script
This script will drop and recreate the role GGS_GGSUSER_ROLE
To use a different role name, quit this script and then edit the params.sql script to change the gg_role
parameter to the preferred name. (Do not run the script.)
You will be prompted for the name of a schema for the GoldenGate database objects.
NOTE: The schema must be created prior to running this script.
NOTE: Stop all DDL replication before starting this installation.
Enter GoldenGate schema name:scofy
Wrote file role_setup_set.txt
PL/SQL procedure successfully completed.
Role setup script complete
Grant this role to each user assigned to the Extract, GGSCI, and Manager processes, by using the following SQL
command:
GRANT GGS_GGSUSER_ROLE TO
where
SQL> grant ggs_ggsuser_role to scofy;
Grant succeeded.
SQL> @ddl_enable.sql
Trigger altered.
SQL> @?/rdbms/admin/dbmspool.sql
Package created.
Grant succeeded.
SQL> @ddl_pin.sql scofy;
PL/SQL procedure successfully completed.
PL/SQL procedure successfully completed.
PL/SQL procedure successfully completed.
配置源端提取进程参数:
GGSCI (test3) 58> edit param extdr
EXTRACT extdr
USERID scofy,PASSWORD scofy
REPORTCOUNT EVERY 30 MINUTES,RATE
DISCARDFILE ./dirrpt/extdr.dsc, APPEND, MEGABYTES 10m
DISCARDROLLOVER AT 3:00
WARNLONGTRANS 2h, CHECKINTERVAL 3m
TRANLOGOPTIONS DBLOGREADER
EXTTRAIL ./dirdat/sa
DYNAMICRESOLUTION
DBOPTIONS ALLOWUNUSEDCOLUMN
FETCHOPTIONS NOUSESNAPSHOT
--TRANLOGOPTIONS CONVERTUCS2CLOBS
TRANLOGOPTIONS EXCLUDEUSER ggate
--TRANLOGOPTIONS altarchivelogdest instance ora10 /.../
--THREADOPTIONS MAXCOMMITPROPAGATIONDELAY 60000 IOLATENCY 60000
--DDL area
DDL &
INCLUDE MAPPED OBJTYPE 'TABLE' &
INCLUDE MAPPED OBJTYPE 'INDEX' &
INCLUDE MAPPED OBJTYPE 'SEQUENCE' &
INCLUDE MAPPED OBJTYPE 'VIEW' &
INCLUDE MAPPED OBJTYPE 'PROCEDURE' &
INCLUDE MAPPED OBJTYPE 'FUNCTION' &
INCLUDE MAPPED OBJTYPE 'PACKAGE' &
EXCLUDE OPTYPE COMMENT
DDLOPTIONS addtrandata REPORT
--add objects
TABLE hc.*;
SEQUENCE hc.*;
配置传输进程参数:
GGSCI (test3) 58> edit param extpump
EXTRACT extpump
RMTHOST 10.80.18.250, MGRPORT 7839, COMPRESS
PASSTHRU
RMTTRAIL ./dirdat/sa
DYNAMICRESOLUTION
--objects
TABLE hc.*;
SEQUENCE hc.*;
GGSCI (test1) 48> ADD EXTRACT extdr, TRANLOG,begin now, threads 2
EXTRACT added.
GGSCI (test1) 50> ADD EXTTRAIL ./dirdat/sa, EXTRACT extdr, MEGABYTES 200
EXTTRAIL added.
GGSCI (test1) 51> ADD EXTRACT extpump, EXTTRAILSOURCE ./dirdat/sa
EXTRACT added.
GGSCI (test1) 53> ADD RMTTRAIL ./dirdat/sa, EXTRACT extpump, MEGABYTES 200
RMTTRAIL added.
目标端:
配置复制进程参数:
GGSCI (test3) 58> edit param repdr
REPLICAT repdr
USERID ogg, PASSWORD ogg
REPORT AT 06:00
REPORTCOUNT EVERY 25 MINUTES, RATE
REPORTROLLOVER AT 02:00
REPERROR DEFAULT, ABEND
ALLOWNOOPUPDATES
ASSUMETARGETDEFS
DISCARDFILE ./dirrpt/repdr.dsc, APPEND, MEGABYTES 1024
DISCARDROLLOVER AT 02:30
--DDL
DDL include mapped
ddloptions report
--DDL
--DDLERROR
--DDLERROR
--
MAP hc.*, TARGET pdg.*;
GGSCI (test3) 64> dblogin userid ogg,password ogg
Successfully logged into database.
GGSCI (test3) 65> ADD CHECKPOINTTABLE checktable
Successfully created checkpoint table checktable.
GGSCI (test3) 68> add replicat repdr, exttrail ./dirdat/sa checkpointtable checktable
REPLICAT added.
------------------------------------------
上面基本上配置结束了,下面进行测试:
SQL> conn hc/hc
Connected.
SQL> create table test4(a int constraint key4 primary key,b varchar2(100),c varchar2(100),d date default
sysdate,e date);
Table created.
create or replace procedure insert_ogg_sql as
begin
for i in 1..20000 loop
insert into test4(a,b,c,d) values(i,i,i,sysdate);
if mod(i,2000)=0 then
commit;
end if;
end loop;
end;
/
SQL> create table test (name varchar(10),code NUMBER(5));
Table created.
SQL> insert INTO test values('scofy',06);
1 row created.
SQL> commit;
Commit complete.
目标端:
SQL> conn pdg/pdg
Connected.
SQL> select table_name from user_tables;
TABLE_NAME
------------------------------
TEST4
TEST
SQL> select OBJECT_NAME from user_procedures;
OBJECT_NAME
--------------------------------------------------------------------------------
INSERT_OGG_SQL
SQL> select * from test;
NAME CODE
---------- ----------
scofy 6
可以看到ddl操作成功。
------------------------------------
下面介绍下,如何删除ddl环境:
1、Log in to SQL*Plus as a user that has SYSDBA privileges。
2、Disconnect all sessions that ever issued DDL, including those of Oracle GoldenGate processes, SQL*Plus,
business applications, and any
other software that uses Oracle. Otherwise the database might generate an ORA-04021 error.
3、@ddl_disable.sql
4、@ddl_remove.sql
5、@marker_remove.sql
-----------------------------
最后介绍下ddl功能限制的几点:
1.需关闭回收站功能:
Oracle recycle bin
Because of a known issue in Oracle 10g, the Oracle recycle bin must be turned off to
support Oracle GoldenGate DDL replication. If the recycle bin is enabled, the Oracle
GoldenGate DDL trigger session receives implicit recycle bin DDL operations that cause
the trigger to fail.
When you install the Oracle GoldenGate DDL support objects, the script prompts you to
permit it to purge the recycle bin, and then it will do so automatically if permission is
granted. However, you still must disable the recycle bin manually.
To turn off the recycle bin:
● Oracle 10g Release 2 and later: Set the RECYCLEBIN initialization parameter to OFF.
● Oracle 10g Release 1: Set the _RECYCLEBIN initialization parameter to FALSE.
Consult the database documentation for the correct syntax.
2.DDL语句长度小于2MB
DDL statement length
Oracle GoldenGate measures the length of a DDL statement in bytes, not in characters.
The supported length is approximately 2 MB, allowing for some internal overhead that can
vary in size depending on the name of the affected object and its DDL type, among other
characteristics. If the DDL is longer than the supported size, Extract will issue a warning
and ignore the DDL operation.
3.系统配置:
1).源表结构和目标表结构必须一致
2).复制段必须使用ASSUMETARGETDEFS参数。如果使用 SOURCEDEFS参数(表结构不一致使用此参数),则将导致复制端进程ABENDED。