哈喽!大家好,我是【IT邦德】,江湖人称jeames007,10余年DBA及大数据工作经验
一位上进心十足的【大数据领域博主】!
中国DBA联盟(ACDU)成员,目前服务于工业互联网
擅长主流Oracle、MySQL、PG、高斯及Greenplum运维开发,备份恢复,安装迁移,性能优化、故障应急处理等。
✨ 如果有对【数据库】感兴趣的【小可爱】,欢迎关注【IT邦德】
❤️❤️❤️感谢各位大可爱小可爱!❤️❤️❤️
主机名 | IP | 操作系统 | 内存/空间 | 角色 | 说明 |
---|---|---|---|---|---|
ora19c | 172.18.12.90 | centos7.8 | 2c/18G 400G | 源端 | Oracle 19.3 |
postgres14 | 172.18.12.50 | centos7.8 | 2c/18G 400G | 目标库 | postgreSQL 14 |
1.官方下载
https://www.oracle.com/middleware/technologies/goldengate-downloads.html
1.OGG for oracle安装包
213000_fbo_ggs_Linux_x64_Oracle_shiphome.zip
2.OGG for PostgreSQL安装包
213000_ggs_Linux_x64_PostgreSQL_64bit.zip
mkdir /ogg
mkdir /soft
chown oracle.oinstall /ogg
unzip /opt/213000_fbo_ggs_Linux_x64_Oracle_shiphome.zip -d /soft
cd /soft/fbo_ggs_Linux_x64_Oracle_shiphome/Disk1/
chown -R oracle.oinstall *
#使用oracle用户安装ogg
[root@jemora19c ~]# su - oracle
[oracle@jemora19c ~]$ cd /soft/fbo_ggs_Linux_x64_Oracle_shiphome/Disk1/
./runInstaller -silent
oracle.install.responseFileVersion=/oracle/install/rspfmt_ogginstall_response_schema_v21_1_0
INSTALL_OPTION=ORA19c
SOFTWARE_LOCATION=/ogg
START_MANAGER=true
MANAGER_PORT=7809
DATABASE_LOCATION=/opt/oracle/product/19c/dbhome_1
INVENTORY_LOCATION=/opt/oracle/oraInventory
UNIX_GROUP_NAME=oinstall
cat >> /home/oracle/.bash_profile <<"EOF"
export OGG_HOME=/ogg
export PATH=$OGG_HOME:$ORACLE_HOME/bin:$PATH
export LD_LIBRARY_PATH=$OGG_HOME:$ORACLE_HOME/lib:$LD_LIBRARYPATH
alias ggsci='cd $OGG_HOME;ggsci'
EOF
source /home/oracle/.bash_profile
[oracle@jemora19c ~]$ ggsci
Oracle GoldenGate Command Interpreter for Oracle
Version 21.3.0.0.0 OGGCORE_21.3.0.0.0_PLATFORMS_210728.1047_FBO
Oracle Linux 7, x64, 64bit (optimized), Oracle Database 21c and lower supported versions on Jul 29 2021 03:59:23
Operating system character set identified as UTF-8.
Copyright (C) 1995, 2021, Oracle and/or its affiliates. All rights reserved.
GGSCI (jemora19c) 1> info all
Program Status Group Lag at Chkpt Time Since Chkpt
MANAGER RUNNING
oracle@jemora19c ~]$ ggsci
GGSCI (jemora19c) 2> create subdirs
mkdir /ogg
unzip /opt/213000_ggs_Linux_x64_PostgreSQL_64bit.zip
tar vxf ggs_Linux_x64_PostgreSQL_64bit.tar -C /ogg
chown -R postgres.postgres /ogg
cat >> /var/lib/pgsql/.bash_profile <<"EOF"
export OGG_HOME=/ogg
export PATH=$OGG_HOME:$PATH
export LD_LIBRARY_PATH=$OGG_HOME/lib:$LD_LIBRARY_PATH
alias ggsci='cd $GG_HOME;ggsci'
EOF
source /var/lib/pgsql/.bash_profile
GGSCI (postgres14) 2> create subdirs
– mount阶段
alter database archivelog;
archive log list;
lter system set enable_goldengate_replication=true;
alter database add supplemental log data;
SELECT supplemental_log_data_min min,
supplemental_log_data_pk pk,
supplemental_log_data_ui ui,
supplemental_log_data_fk fk,
supplemental_log_data_all allc
FROM v$database;
cat > /ogg/dirprm/mgr.prm << “EOF”
PORT 7809
DYNAMICPORTLIST 7810-7830
AUTOSTART EXTRACT *
AUTORESTART EXTRACT , RETRIES 100, WAITMINUTES 2, RESETMINUTES 10
PURGEOLDEXTRACTS ./dirdat/, usecheckpoints, minkeepdays 30
LAGREPORTHOURS 1
LAGINFOMINUTES 30
LAGCRITICALMINUTES 45
EOF
cat > /ogg/dirprm/ext_ora.prm << “EOF”
extract ext_ora
setenv (ORACLE_SID=oradb)
setenv (ORACLE_HOME=/opt/oracle/product/19c/dbhome_1)
setenv (NLS_LANG=“AMERICAN_AMERICA.AL32UTF8”)
userid PGOGG@oradb,password oracle
exttrail /ogg/dirdat/ex
table PGOGG.test01;
table STEST.*;
EOF
– 添加进程
add extract ext_ora, tranlog, begin now
add exttrail /ogg/dirdat/ex, extract ext_ora
cat > /ogg/dirprm/pump_ora.prm << “EOF”
extract pump_ora
setenv (ORACLE_SID=oradb)
setenv (ORACLE_HOME=/opt/oracle/product/19c/dbhome_1)
setenv (NLS_LANG=“AMERICAN_AMERICA.AL32UTF8”)
rmthost 172.18.12.50,mgrport 7809,compress
rmttrail /ogg/dirdat/ex
table PGOGG.test01;
table STEST.*;
EOF
cat > /ogg/dirprm/rep_pg.prm <<“EOF”
replicat rep_pg
SOURCEDEFS ./dirdef/defgen_PG.prm
SETENV(PGCLIENTENCODING = “UTF8” )
SETENV(ODBCINI=“/ogg/odbc.ini” )
SETENV(NLS_LANG=“AMERICAN_AMERICA.AL32UTF8”)
TARGETDB PGDSN, userid stest, password post
DISCARDFILE ./discard/rep_pg.dsc, append
–ap lhrogg.test01, target lhrogg.test01;
map stest., target stest.;
EOF
-- oracle查询
col table_name format a30
SELECT a.table_name,a.num_rows FROM dba_tables a where a.OWNER='STEST' order by num_rows desc ;
SYS@oradb> delete from STEST.LOGON;
2383 rows deleted.
SYS@oradb> select count(*) from STEST.LOGON;
COUNT(*)
----------
0
jemdb=# select count(*) from stest.LOGON;
count
-------
0
(1 row)
-- 在pg中查询数据量
select nspname AS schemaname,
relname,
reltuples::numeric as rowcount,
pg_size_pretty (
pg_total_relation_size ( '"' || nspname || '"."' || relname || '"' )) AS SIZE
from pg_class C LEFT JOIN pg_namespace N ON ( N.oid = C.relnamespace )
where nspname NOT IN ( 'pg_catalog', 'information_schema' )
AND relkind = 'r'
ORDER by reltuples DESC
LIMIT 20;
schemaname | relname | rowcount | size
------------+----------------------+----------+------------
stest | inventories | 899441 | 433 MB
stest | order_items | 7341 | 1072 kB
stest | addresses | 1500 | 264 kB
stest | card_details | 1500 | 264 kB
stest | orders | 1430 | 376 kB
stest | product_information | 1000 | 400 kB
stest | warehouses | 1000 | 192 kB
stest | customers | 1000 | 440 kB
stest | product_descriptions | 1000 | 288 kB
stest | logon | 0 | 16 kB
stest | orderentry_metadata | -1 | 8192 bytes
pgogg | test01 | -1 | 8192 bytes
stest | checkpointtab | -1 | 32 kB
stest | checkpointtab_lox | -1 | 16 kB
(14 rows)
GGSCI (postgres14) 2> stats rep_pg,table stest.logon, total
Sending STATS request to Replicat group REP_PG ...
Start of statistics at 2023-12-02 00:27:37.
Replicating from STEST.LOGON to stest.logon:
*** Total statistics since 2023-12-02 00:24:44 ***
Total inserts 0.00
Total updates 0.00
Total deletes 2383.00
Total upserts 0.00
Total discards 0.00
Total operations 2383.00