ogg 同步pg資料到oracle--步驟
環境準備
作業系統: ORACLE Linux7.9-64bit
pg 版本:14.8
ogg for pg 版本:21.3
oracle版本: 11.2.0.4
ogg for oracle 版本:19.1(版本太高和oralce版本不相容,導致無法複製)
2臺測試伺服器:(源) 192.168.137.103;(目標)192.168.137.102
pg14.8 安裝:
https://blog.itpub.net/10201716/viewspace-3002437/
實現原理
OGG準備專用schema和專用使用者並授權
在正式開始配置OGG流程前,根據官方推薦,最好給OGG準備一個專門的schema和專門的使用者,並對該使用者授予必要的許可權,操作如下:
(1)建立資料庫
建立演示庫-test_db
psql -h /data/pgsql/run
alter
user postgres
password
'Cloud_4u';
##初始化密碼
create
DATABASE test_db; 測試資料庫
\q
切換到OGG專庫,建立schema
psql -h /data/pgsql/run -d test_db -U postgres
create
SCHEMA ggsch; ogg專用資料庫shcema
切換到演示庫,建立測試用的表
psql -d test_db -U postgres
create
schema test_schema;
CREATE
TABLE test_schema.COMPANY(
ID
INT PRIMARY
KEY
NOT
NULL,
NAME
TEXT ,
AGE
INT ,
ADDRESS
CHAR(
50),
SALARY
REAL
);
CREATE
TABLE test_schema.DEPARTMENT(
ID
INT PRIMARY
KEY ,
DEPT
CHAR(
50) ,
EMP_ID
INT
);
test_db=
# insert into test_schema.COMPANY values (1,'du',30,'beijing','222');
test_db=
# insert into test_schema.DEPARTMENT values (1,'tech',3);
————————————————
建立OGG專用使用者,並授權
create
role gguser login
password
'Cloud_4u' ;
GRANT
CONNECT
ON
DATABASE postgres
TO gguser;
ALTER
USER gguser
WITH
REPLICATION;
ALTER
USER gguser
WITH SUPERUSER;
psql -d test_db -U postgres
GRANT
USAGE
ON
SCHEMA ggsch
TO gguser;
GRANT
SELECT
ON ALL
TABLES
IN
SCHEMA ggsch
TO gguser;
GRANT
INSERT,
UPDATE,
DELETE,
TRUNCATE
ON ALL
TABLES
IN
SCHEMA ggsch
TO gguser;
-- 心跳和檢查點許可權
GRANT
CREATE
ON
DATABASE gg_db
TO gguser;
GRANT
CREATE,
USAGE
ON
SCHEMA ggsch
TO gguser;
GRANT
EXECUTE
ON ALL FUNCTIONS
IN
SCHEMA ggsch
TO gguser;
GRANT
SELECT,
INSERT,
UPDATE,
DELETE
ON ALL
TABLES
IN
SCHEMA ggsch
TO gguser;
————————————————
安裝ODBC驅動,配置DNS
cd /data/ogg
[postgres@pgdb ogg]$ cat odbc.ini
[ODBC Data Sources]
PGDSN=DataDirect 14.8 PostgreSQL Wire Protocol
postgres=DataDirect 14.8 PostgreSQL Wire Protocol
scott=DataDirect 14.8 PostgreSQL Wire Protocol
[ODBC]
IANAAppCodePage=106
InstallDir=/data/ogg
[TESTPDB]
Driver=/data/ogg/lib/GGpsql25.so
Description=DataDirect 14.8 PostgreSQL Wire Protocol
Database=test_db
HostName=192.168.137.103
PortNumber=5432
#LogonID=ogguser
#Password=ogg123
TransactionErrorBehavior=2
OGG程式配置
- 管理服務程式
- 配置資料來源的提取程式
- 配置目標庫的複製程式
配置管理程式
GGSCI(pgdb,作為 gguser@testpdb)
91> edit param mgr
PORT
7810
DYNAMICPORTLIST
7810
-7820
purgeoldextracts .
/dirdat/*, usecheckpoints,minkeephours
24
AUTORESTART ER *, RETRIES
3, WAITMINUTES
2,RESETMINUTES
10
源端postgresql引數調整
log_directory = '/data/pgsql/data/log'
# directory where log files are written,
# can be absolute or relative to PGDATA
log_filename = 'pg-%Y-%m-%d_%H%M%S.log'
wal_level = logical
#minimal, replica, or logical
max_replication_slots = 10
#max number of replication slots
max_wal_sender = 10
#maximum number of wal sender processes
wal_receiver_status_interval=10s
#optional, keep the system default
wal_sender_timeout
#optional, keep the system default
track_commit_timestamp
#optional, keep the system default
wal_receiver_status_interval=10s
wal_sender_timeout = 60s
track_commit_timestamp=off
調整後重啟源端postgresql
開啟表級別附加日誌
[postgres@pgdb ogg]$
export ODBCINI=/data/ogg/odbc.ini
[postgres@pgdb ogg]$
[postgres@pgdb ogg]$ ./ggsci
Oracle GoldenGate Command Interpreter
for PostgreSQL
Version
21.3.
0.0.
0 OGGCORE_21.
3.0.
0.0_PLATFORMS_210728.
1047
Oracle Linux
7, x64,
64bit (optimized), PostgreSQL
on Aug
4
2021
20:
27:
55
作業系統字符集標識為 UTF-
8。
Copyright (C)
1995,
2021, Oracle
and/
or its affiliates. All rights reserved.
GGSCI (pgdb)
1> dblogin sourcedb testpdb, userid gguser, password Cloud_4u
2024-
01-
06
20:
25:
49 INFO OGG-
03036 資料庫字符集被標識為 UTF-
8。區域設定:zh_CN.UTF-
8.
2024-
01-
06
20:
25:
49 INFO OGG-
03037 會話字符集被標識為 UTF-
8。.
GGSCI(pgdb,作為 gguser@testpdb)
48> add trandata test_schema.COMPANY
add trandata test_schema.DEPARTMENT
Logging
of supplemental log data
is already enabled
for table test_schema.company
with REPLICA IDENTITY
set
to
DEFAULT
GGSCI(pgdb,作為 gguser@testpdb)
49>
Logging
of supplemental log data
is already enabled
for table test_schema.department
with REPLICA IDENTITY
set
to
DEFAULT
GGSCI(pgdb,作為 gguser@testpdb)
50> info trandata test_schema.COMPANY
Logging
of supplemental log data
is enabled
for table test_schema.company
with REPLICA IDENTITY
set
to
DEFAULT
在pg上註冊抽取程式
在pg庫上註冊抽取程式,實際上就是建立了一個複製槽,output plugin 預設使用test_decoding
GGSCI(pgdb,作為 gguser@testpdb)
53> register extract ext_pg
2024
-01
-06
17:
25:
08 INFO OGG
-25355 已成功在資料庫
'test_db' 中建立用於提取組
'EXT_PG' 的複製插槽
'ext_pg_de21e46e9800bf64'。
配置抽取程式和投遞程式
配置抽取程式
GGSCI(
pgdb,作為
gguser@
testpdb)
3> edit param EXT_PG
EXTRACT ext_pg
SETENV(PGCLIENTENCODING =
"UTF8" )
SETENV(ODBCINI=
"/data/ogg/odbc.ini" )
sourcedb testpdb, userid gguser, password Cloud_4u
LOGALLSUPCOLS
NOCOMPRESSUPDATES
UPDATERECORDFORMAT FULL
--TRANLOGOPTIONS MINEFROMACTIVEDG
DISCARDFILE ./dirrpt/pg.dsc, APPEND, MEGABYTES
4000
CACHEMGR CACHESIZE
1024MB, CACHEDIRECTORY ./dirtmp
REPORTCOUNT EVERY
10000 records, RATE
EXTTRAIL ./dirdat/pg
GETTRUNCATES
TABLE test_schema.COMPANY;
TABLE
test_schema
.DEPARTMENT;
GGSCI(pgdb,作為 gguser@testpdb)
53> register extract ext_pg
2024-
01-
06
17
:
25
:08 INFO OGG-
25355 已成功在資料庫
'test_db' 中建立用於提取組
'EXT_PG' 的複製插槽
'ext_pg_de21e46e9800bf64'。
GGSCI(pgdb,作為 gguser@testpdb)
57> ADD extract ext_pg, TRANLOG,
BEGIN now
已新增提取。
GGSCI(pgdb,作為 gguser@testpdb)
58> add exttrail ./dirdat/pg,extract ext_pg,megabytes
500
已新增 EXTTRAIL。
配置投遞程式
GGSCI(
pgdb,作為
gguser@
testpdb)
4> edit param pump_pg1
extract pump_pg1
SETENV(PGCLIENTENCODING =
"UTF8" )
RMTHOST
192.168.
137.102, MGRPORT
7809, COMPRESS
PASSTHRU
NUMFILES
1000
RMTTRAIL ./dirdat/gp
TABLE test_schema.COMPANY;
TABLE
test_schema
.DEPARTMENT;
GGSCI(
pgdb,作為
gguser@
testpdb)
68>add extract pump_pg1,exttrailsource ./dirdat/pg
GGSCI(pgdb,作為 gguser@testpdb)
69> add rmttrail ./dirdat/gp,extract pump_pg1,megabytes
500
配置defgen
說明
利用DEFGEN工具可以為源端和目標端表生成資料定義檔案,當源庫和目標庫型別不一致時,或源端的表和目標端的表結構不一致時,資料定義檔案時必須要有的
如果表結構一直可以配置引數ASSUMETARGETDEFS
GGSCI(
pgdb,作為
gguser@
testpdb)
121> edit param defg
DEFSFILE ./dirdef/tb.def, PURGE
sourcedb testpdb, userid gguser, password Cloud_4u
TABLE test_schema.COMPANY;
TABLE
test_schema
.DEPARTMENT;
生成表定義檔案
[postgres@pgdb ogg]$ ./defgen paramfile /data/ogg/dirprm/defg.prm
[postgres@pgdb dirdef]$ ls
demo.def tb.def
複製defgen檔案到目標端的dirdef目錄下
scp tb.def oracle@192.168.137.102
啟動複製及投遞程式
GGSCI(pgdb,作為 gguser@testpdb)
6> start EXT_PG
GGSCI(pgdb,作為 gguser@testpdb)
6> start pump_pg1
GGSCI(pgdb,作為 gguser@testpdb)
123> info all
Program Status Group Lag at Chkpt Time Since Chkpt
MANAGER RUNNING
EXTRACT ABENDED E1
00:
00:
00
06:
50:
26
EXTRACT RUNNING E2
00:
00:
00
00:
00:
11
EXTRACT RUNNING EXT_PG
00:
00:
00
00:
00:
02
EXTRACT STOPPED PU2
00:
00:
00
06:
52:
28
EXTRACT RUNNING PUMP_PG
00:
00:
00
00:
00:
05
EXTRACT RUNNING PUMP_PG1
00:
00:
00
00:
00:
06
目標端oracle配置
oracle庫的使用者和許可權
create
user goldengate
identified
by
"123456";
grant
create
session,
alter
session
to goldengate;
grant
alter
system
to goldengate;
grant
resource
to goldengate;
grant
connect
to goldengate;
grant
select
any dictionary
to goldengate;
grant
flashback
any
table
to goldengate;
grant
select
any
table
to goldengate;
grant
select
any
table
to goldengate;
grant
insert
any
table
to goldengate;
grant
update
any
table
to goldengate;
grant
delete
any
table
to goldengate;
grant
select
on dba_clusters
to goldengate;
grant
execute
on dbms_flashback
to goldengate;
grant
create
table
to goldengate;
grant
create
sequence
to goldengate;
grant
alter
any
table
to goldengate;
grant dba
to goldengate;
grant
lock
any
table
to goldengate;
ogg for oracle 安裝(略)
安裝的版本是19.1 影像化介面安裝
mgr配置
edit param mgr
PORT
7809
DYNAMICPORTLIST
7810
-7980
PURGEOLDEXTRACTS .
/dirdat/*, USECHECKPOINTS, MINKEEPDAYS
3
PURGEDDLHISTORY MINKEEPDAYS
7, MAXKEEPDAYS
10
LAGREPORTHOURS
1
LAGINFOMINUTES
30
LAGCRITICALMINUTES
45
start mgr
目標端配置複製程式
dblogin USERID goldengate
@misdb,password
123456
Successfully logged into database.
GGSCI (Node1 as goldengate
@misdb)
2> edit param rep_pg1
REPLICAT rep_pg1
SETENV (NLS_LANG=
"AMERICAN_AMERICA.AL32UTF8")
USERID goldengate
@misdb,password
123456
SOURCEDEFS ./dirdef/tb.def
MAP test_schema.COMPANY, TARGET togg.COMPANY;
MAP test_schema.DEPARTMENT,TARGET togg.DEPARTMENT;
add checkpointtable goldengate.chkt
add checkpointtable goldengate.checkpointtab
add replicat rep_pg1,exttrail ./dirdat/gp,checkpointtable goldengate.checkpointtab
start rep_pg1
GGSCI (Node1 as goldengate
@misdb)
3>
info all
Program Status Group Lag at Chkpt Time Since Chkpt
MANAGER RUNNING
REPLICAT RUNNING REP_PG
00:
00:
00
00:
00:
01
REPLICAT RUNNING REP_PG1
00:
00:
00
00:
00:
06
測試
test_db=# insert into test_schema.COMPANY values (
3,
'w2',
'33',
'au',
'556');
GGSCI(pgdb,作為 gguser@testpdb)
7> stats PUMP_PG1 , total
正在將 STATS 請求傳送到提取組 PUMP_PG1 ...
統計資訊開始於
2024-
01-
06
21:
01:
02。
到 ./dirdat/gp 的輸出:
從 test_schema.department 提取到 test_schema.department:
*** 自
2024-
01-
06
17:
53:
37 以來的統計資訊總計 ***
插入總數
1.00
更新總數
0.00
刪除總數
0.00
更新插入總數
0.00
放棄總數
0.00
操作總數
1.00
從 test_schema.company 提取到 test_schema.company:
*** 自
2024-
01-
06
17:
53:
37 以來的統計資訊總計 ***
插入總數
2.00
更新總數
0.00
刪除總數
0.00
更新插入總數
0.00
放棄總數
0.00
操作總數
2.00
目標端狀態
GGSCI (Node1
as goldengate@misdb)
26> stats rep_pg1, total
Sending STATS request
to REPLICAT REP_PG1 ...
Start
of Statistics at
2024-
01-
06
21:
01:
41.
Replicating from test_schema.company
to TOGG.COMPANY:
*** Total statistics since
2024-
01-
06
17:
53:
39 ***
Total inserts
2.00
Total updates
0.00
Total deletes
0.00
Total upserts
0.00
Total discards
0.00
Total operations
2.00
Replicating from test_schema.department
to TOGG.DEPARTMENT:
*** Total statistics since
2024-
01-
06
17:
53:
39 ***
Total inserts
1.00
Total updates
0.00
Total deletes
0.00
Total upserts
0.00
Total discards
0.00
Total operations
1.00
ID
NAME AGE ADDRESS SALARY
--- ------------ ---------- -------------------------------------------------- --------------------
2 yang
28 taiyuan
3333
3 w2
33 au
556
來自 “ ITPUB部落格 ” ,連結:https://blog.itpub.net/10201716/viewspace-3002939/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- pg 用ogg 同步大概步驟
- ORACLE(Linux版本)實時同步資料到MYSQL(Linux版本)解決方案:OGGOracleLinuxMySql
- Oracle+Ogg 歸檔丟失 重新導資料建立ogg同步步驟Oracle
- Debezium vs OGG vs Tapdata:如何實時同步 Oracle 資料到 Kafka 訊息佇列?OracleKafka佇列
- flinkcdc同步mysql資料到selectdbMySql
- PG 資料庫 從阿里雲pg rds 同步資料。資料庫阿里
- Logstash7.6.2同步Mysql資料到ElasticSearchMySqlElasticsearch
- 使用SeaTunnel從InfluxDB同步資料到DorisUX
- mysql 如何毫秒級同步資料到 elasticsearchMySqlElasticsearch
- 使用canal.adapter同步資料到MySQLAPTMySql
- ogg 同步kafka OGG-15051 Java or JNI exception:KafkaJavaException
- Flink同步Kafka資料到ClickHouse分散式表Kafka分散式
- OGG 簡單DML同步
- docker搭建Elasticsearch、Kibana、Logstash 同步mysql資料到ESDockerElasticsearchMySql
- 從物件儲存服務同步資料到Elasticsearch物件Elasticsearch
- Flinkx實時和離線同步Postgresql資料到KafkaSQLKafka
- GoldenGate 12c 在原有同步程式中新增同步表的操作步驟Go
- 基於OGG Datahub外掛將Oracle資料同步上雲Oracle
- 使用DataX同步MaxCompute資料到TableStore(原OTS)最佳化指南
- KunlunDB 快速入門 4.0(從Oracle實時同步資料到kunlunDB)Oracle
- Laravel 生成假資料步驟Laravel
- Win10便箋如何同步 Win10便籤同步的設定步驟Win10
- ogg在異構資料庫實時雙向同步中如何防止資料死迴圈同步資料庫
- 資料探勘的步驟有哪些?
- TRMM降水資料下載步驟
- Oracle資料庫啟動步驟Oracle資料庫
- 操作步驟
- OGG-Oracle 11.2.0.1 ->19.3 pdb 使用Ogg 同步版本相關問題學習整理Oracle
- Hive:資料倉儲構建步驟Hive
- MySQL資料庫安裝步驟-WindowsMySql資料庫Windows
- 資料庫設計的基本步驟資料庫
- PHP連線資料庫的步驟PHP資料庫
- java中UDP接收資料的步驟JavaUDP
- python連線mysql資料庫步驟PythonMySql資料庫
- kubernetes-部署Oracle資料庫步驟Oracle資料庫
- vnc安裝步驟,vnc安裝步驟詳解VNC
- 1.4 基於OGG單表到分庫分表資料同步場景
- SSM整合步驟SSM