Postgresql-\>openGauss遷移工具debezium-connector-postgres
可獲得性
本特性自openGauss 7.0.0-RC1版本開始引入。
特性簡介
debezium-connector-postgres工具是一個基于Java語言的Postgresql到openGauss的復制工具。該工具提供了初始全量數據及對象(視圖、觸發器、函數、存儲過程)和增量數據(DML)的復制能力,可實現數據及對象從Postgresql遷移至openGauss。對于數據的全量遷移,支持Postgresql中各種數據類型的遷移,同時對于Postgresql中的浮點數據類型,包括decimal、numeric、double precision、real數據類型,可保證遷移后數據精度不丟失。對于數據的增量遷移,可以將Postgresql數據遷移期間(包括全量和增量遷移)產生的數據遷移至openGauss端。
客戶價值
通過使用debezium-connector-postgres工具,可完成數據從Postgresql搬遷至openGauss數據庫。基于sysbench測試模型,2路鯤鵬920 CPU、openEuler操作系統下,Postgresql數據庫20張表(無索引)單表數據量在500萬以上時,gs_mysync使用20并發遷移數據至openGauss,整體全量遷移性能可達300M/s以上。增量遷移按表回放,針對混合IUD場景,50張表50個線程(insert-30線程,update-10線程,delete-10線程),性能可達3w tps。
特性描述
debezium-connector-postgres工具提供數據全量和增量復制功能,使得數據可以從Postgresql遷移至openGauss數據庫。debezium-connector-postgres工具中存儲了Postgresql數據類型與openGauss數據類型之間的映射關系,可支持Postgresql中各種數據類型的遷移。
debezium-connector-postgres工具支持在指定版本和架構的系統(包括CentOS7、openEuler20.03、openEuler22.03系統版本,x86_64和aarch64架構)上進行離線安裝,無需連接外部網絡。
debezium-connector-postgres工具采用debezium connector結構,全量遷移時,source端使用pgjdbc驅動查詢postgresql數據庫并導出數據至csv文件中,sink端使用ogjdbc驅動將csv文件導入至openGauss數據庫。增量遷移時,source端將數據推送至指定topic下,同時sink端配置topics為合并后的topic,用于從kafka抽取數據,從而可保證事務的順序。數據復制過程中,debezium-connector-postgres工具會針對不同的類型進行相應的轉換。
特性約束
- 支持postgresql 9.4以上版本。
- PostgreSQL版本低于10.x,僅支持使用wal2json插件創建邏輯復制槽;
- PostgreSQL版本大于10.x,支持使用wal2json和pgoutput插件創建邏輯復制槽(推薦使用pgoutput插件)。
依賴關系
debezium-connector-postgres工具依賴kafka、zookeeper和schema-registry三方組件。
使用說明
下載依賴
- [kafka](https://mirrors.tuna.tsinghua.edu.cn/apache/kafka/)
? (以kafka_2.13-3.6.1為例)
?wget?-c https://mirrors.tuna.tsinghua.edu.cn/apache/kafka/3.6.1/kafka_2.13-3.6.1.tgz ?tar?-zxf kafka_2.13-3.6.1.tgz?
?????- [confluent community](https://packages.confluent.io/archive/5.5/confluent-community-5.5.1-2.12.zip)
?wget?-c ?https://packages.confluent.io/archive/5.5/confluent-community-5.5.1-2.12.zipunzip?confluent-community-5.5.1-2.12.zip
- [debezium-connector-postgres](https://opengauss.obs.cn-south-1.myhuaweicloud.com/latest/tools/replicate-postgresql2openGauss-7.0.0rc1.tar.gz)
?wget?-c https://opengauss.obs.cn-south-1.myhuaweicloud.com/latest/tools/replicate-postgresql2openGauss-7.0.0rc1.tar.gztar?-zxvf replicate-postgresql2openGauss-7.0.0rc1.tar.gz
修改配置文件
默認配置文件的地址均為localhost,若需修改為具體ip,請同步修改下列所有文件中參數涉及localhost的均改為實際ip。
- zookeeper
? 配置文件位置:/kafka_2.13-3.6.1/config/zookeeper.properties
? zookeeper的默認端口號為2181,對應參數clientPort=2181。
? 若端口沖突,需要修改端口號,則同步修改以下文件對應參數:
??kafka_2.13-3.6.1/config/zookeeper.properties------clientPort=2181kafka_2.13-3.6.1/config/server.properties------zookeeper.connect=localhost:2181confluent-5.5.1/etc/schema-registry/schema-registry.properties------kafkastore.connection.url=localhost:2181
- kafka
? 配置文件位置:/kafka_2.13-3.6.1/config/server.properties
? 注意topic的分區數必須為1,因此需設置參數num.partitions=1,該參數默認值即為1,因此無需單獨修改該參數。
? kafka的默認端口是9092,對應參數listeners=PLAINTEXT://:9092。
? 若端口沖突,需要修改端口號,則同步修改以下文件對應參數:
??kafka_2.13-3.6.1/config/server.properties------listeners=PLAINTEXT://:9092confluent-5.5.1/etc/schema-registry/schema-registry.properties------kafkastore.bootstrap.servers=PLAINTEXT://localhost:9092confluent-5.5.1/etc/schema-registry/connect-avro-standalone.properties------bootstrap.servers=localhost:9092confluent-5.5.1/etc/kafka/postgres-source.properties------database.history.kafka.bootstrap.servers=127.0.0.1:9092
- schema-registry???????
? 配置文件位置:/confluent-5.5.1/etc/schema-registry/schema-registry.properties
? schema-registry的默認端口是8081,對應參數listeners=http://0.0.0.0:8081。
? 若端口沖突,需要修改端口號,則同步修改以下文件對應參數:???????
? confluent-5.5.1/etc/schema-registry/schema-registry.properties------listeners=http://0.0.0.0:8081confluent-5.5.1/etc/schema-registry/connect-avro-standalone.properties------key.converter.schema.registry.url=http://localhost:8081confluent-5.5.1/etc/schema-registry/connect-avro-standalone.properties------value.converter.schema.registry.url=http://localhost:8081若需查看kafka topic內容,需修改confluent-5.5.1/bin/kafka-avro-console-consumer------DEFAULT_SCHEMA_REGISTRY_URL="--property schema.registry.url=http://192.168.0.219:8081"
- connect-standalone
配置文件位置:/confluent-5.5.1/etc/schema-registry/connect-avro-standalone.properties
注意在plugin.path配置項中增加debezium-connector-postgres所在的路徑
若debezium-connector-postgres所在路徑為:/data/debezium_kafka/plugin/debezium-connector-postgres
則配置其上一層目錄,即plugin.path=share/java,/data/debezium_kafka/plugin
connect-standalone的默認端口是8083,對應參數rest.port=8083。
若端口沖突,需要修改端口號,則同步修改以下文件對應參數:
confluent-5.5.1/etc/schema-registry/connect-avro-standalone.properties------rest.port=8083
- postgres-source.properties
配置文件位置:/confluent-5.5.1/etc/kafka/postgres-source.properties
示例詳見[postgres-source.properties](https://gitee.com/opengauss/debezium/blob/master/debezium-connector-postgres/patch/postgres-source.properties)
- postgres-sink.properties
配置文件位置:/confluent-5.5.1/etc/kafka/postgres-sink.properties
示例詳見[postgres-sink.properties](https://gitee.com/opengauss/debezium/blob/master/debezium-connector-postgres/patch/postgres-sink.properties)
啟動命令
(1)啟動zookeeper???????
cd?kafka_2.13-3.6.1
./bin/zookeeper-server-start.sh ./config/zookeeper.properties
(2)啟動kafka???????
cd?kafka_2.13-3.6.1
./bin/kafka-server-start.sh ./config/server.properties
(3)注冊schema???????
cd?confluent-5.5.1
./bin/schema-registry-start etc/schema-registry/schema-registry.properties
(4)啟動kafka-connect source端???????
cd?confluent-5.5.1
./bin/connect-standalone etc/schema-registry/connect-avro-standalone.properties etc/kafka/postgres-source.properties
(5)啟動kafka-connect sink端???????
cd?confluent-5.5.1
./bin/connect-standalone etc/schema-registry/connect-avro-standalone-1.properties etc/kafka/postgres-sink.properties
說明:source端和sink端的兩個配置文件connect-avro-standalone.properties和connect-avro-standalone-1.properties的差異點在于rest.port參數的不同,默認為8083,即兩個文件中設置不同的端口號,即可啟動多個kafka-connect,實現sink端和source端獨立工作。
步驟(4)和(5)示例source端和sink端分開啟動,推薦分開啟動方式。兩者也可以同時啟動,同時啟動的命令為:???????
cd?confluent-5.5.1
./bin/connect-standalone etc/schema-registry/connect-avro-standalone.properties etc/kafka/postgres-source.properties etc/kafka/postgres-sink.properties
其他命令:
(1)查看topic???????
cd?kafka_2.13-3.6.1
./bin/kafka-topics.sh --bootstrap-server 127.0.0.1:9092 --list
(2)查看topic的信息???????
cd?kafka_2.13-3.6.1
./bin/kafka-topics.sh --bootstrap-server 127.0.0.1:9092 --describe --topic topic_name
(3)查看topic的內容???????
cd confluent-5.5.1
./bin/kafka-avro-console-consumer --bootstrap-server?127.0.0.1:9092?--topic topic_name --from-beginning
參考文檔
debezium-connector-postgres詳細說明和使用文檔參考:<a href="https://gitee.com/opengauss/debezium/blob/master/README.md#debezium-postgres-connector">debezium-connector-postgres.md</a>
官網資料:https://docs.opengauss.org/zh/docs/5.0.0/docs/DataMigrationGuide/DataMigrationGuide.html