From b9f1cbf21a1845937d60bbcbd8f6291b6179359c Mon Sep 17 00:00:00 2001 From: mry <1312348150@qq.com> Date: Wed, 15 Dec 2021 14:25:38 +0800 Subject: [PATCH 1/2] pg2og --- README.md | 84 +++++++++++------- migration.sh | 20 ++++- ...ezium.connector.postgresql.spi.Snapshotter | 1 + .../snapshot/PgDumpSnapshotter.class | Bin 0 -> 4217 bytes 4 files changed, 71 insertions(+), 34 deletions(-) create mode 100644 pgdumpSnapshotter/target/classes/META-INF.services/io.debezium.connector.postgresql.spi.Snapshotter create mode 100644 pgdumpSnapshotter/target/classes/io/debezium/connector/postgresql/snapshot/PgDumpSnapshotter.class diff --git a/README.md b/README.md index b4ed5c7..7e2ac82 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,32 @@ 若主机A上运行着postgresql13数据库,主机B上运行着openGauss数据库,需要将postgresql13中数据库DBNAME迁移至openGauss数据库。 +# 范围 + +- 在数据库迁移过程中,数据库向客户端提供的服务存在一定的局限性(仅支持DML) + + 在线迁移模块中的debezium工具仅可以捕获对postgres数据库插入、更新和删除的行级更改,无法捕获到对postgres数据库表结构、表索引等更改。这意味着,在数据库迁移过程中,数据库向客户端提供的服务存在一定的局限性,客户端仅可以对已创建物理表进行插入(insert)、更新(update)和删除(delete)的行级更改,无法创建新表、修改表结构、修改索引等操作。 + +- 仅支持自动迁移postgres数据库内数据,不支持自动迁移postgres数据库的表结构,索引等对象。 + + postgres数据库的表结构,索引等对象需要在opengauss数据库手动创建。 + +- 数据类型 + + 仅支持迁移常见数据类型:数值类型(整数、小数)、字符串类型、一维数组。 + + 不支持interval、json、xml、bit、point数据类型。 + + 日期时间类型需要考虑时区影响,不保证迁移的准确性。 + +- 特殊表 + + 支持迁移分区表,但是分区表必须存在主键。 + + 不支持迁移unlogged表 + +- 不支持断点续传 + # 迁移准备 - 检查端口是否被占用 @@ -12,7 +38,7 @@ | --------- | ----- | -------- | | 2181 | 9092 | 8083 | - 若以上端口被占用,建议杀死占用相应进程,释放端口。 + 若以上端口被占用,建议杀死占用端口的相应进程,释放端口。 - postgresql13端 @@ -58,10 +84,10 @@ 添加: ```shell - host all all 192.168.0.0/16 trust + host all all 192.168.0.1/32 trust ``` - 其中,192.168.0.0/16表示192.168.0.0~192.168.255.255的网段均可访问postgresql13数据库。 + 其中,192.168.0.1/32为openGauss端IP地址。 - postgresql13设置允许使用 Debezium 连接器主机进行复制 @@ -80,7 +106,7 @@ pg_ctl start -D XXX/data ``` - - 检查待迁移数据库内所有table是否存在主键 + - 检查待迁移数据库内table(非分区表)是否存在主键 wal2json无法解析没有主键表的插入删除。对于没有主键的表,需要对其进行如下修改: @@ -93,10 +119,10 @@ 考虑到安全性,最好不要创建最高权限的复制用户,建议创建拥有最低权限的复制用户 ```sql - CREATE ROLE copyuser with password 'testdb@1234' REPLICATION LOGIN; + CREATE ROLE with password 'password' REPLICATION LOGIN; CREATE ROLE ; GRANT REPLICATION_GROUP TO ; - GRANT REPLICATION_GROUP TO copyuser; + GRANT REPLICATION_GROUP TO ; ALTER TABLE OWNER TO ; ``` @@ -105,8 +131,8 @@ - 在openGauss创建复制用户,用于JDBC连接 ```sql - create user testuser with password 'testdb@1234'; - grant all privileges to testuser; + create user with password 'password'; + grant all privileges to ; ``` - openGauss配置客户端接入认证 @@ -131,22 +157,14 @@ 此工具仅迁移数据库内数据,数据库表结构、索引等需要在opengauss端手动创建。 + 注意:创建opengauss数据库时需要指定DBCOMPATIBILITY='PG',以兼容postgres数据库。例如,CREATE DATABASE DBCOMPATIBILITY 'PG'; + - 重启opengauss数据库 ```shell gs_ctl restart -D XXX/data ``` -# 迁移工具局限性 - -- 在数据库迁移过程中,数据库向客户端提供的服务存在一定的局限性(仅支持DML) - - 在线迁移模块中的debezium工具仅可以捕获对postgres数据库插入、更新和删除的行级更改,无法捕获到对postgres数据库表结构、表索引等更改。这意味着,在数据库迁移过程中,数据库向客户端提供的服务存在一定的局限性,客户端仅可以对已创建物理表进行插入(insert)、更新(update)和删除(delete)的行级更改,无法创建新表、修改表结构、修改索引等操作。 - -- 待迁移物理表中不存在中文字符 - - 在postgres数据库中每个中文字符占用2个字节,而在opengauss中每个中文字符占用3个字节。若待迁移物理表中存在中文字符,可能会出现 value too long for type char(XXX)的错误。 - # 迁移工具使用 将迁移工具拷贝至openGauss所在主机 @@ -170,8 +188,8 @@ "connector.class": "io.debezium.connector.postgresql.PostgresConnector", "database.hostname": "0.0.0.0", "database.port": "5432", - "database.user": "copyuser", - "database.password": "testdb@1234", + "database.user": "", + "database.password": "password", "database.dbname" : "pg_dbname", "database.server.name": "fulfillment", "plugin.name":"wal2json", @@ -208,8 +226,8 @@ group.id=consumer database.driver.classname=org.postgresql.Driver database.url=jdbc:postgresql://127.0.0.1:5432/og_dbname?stringtype=unspecified - database.user=testuser - database.password=testdb@1234 + database.user= + database.password=password ``` 需更改的配置: @@ -217,21 +235,23 @@ | 配置名称 | 更改后的内容 | | -------------------- | ------------------------------------------------------------ | | database.server.name | 需要同register-pg13-xtreams.json中database.server.name相同 | - | database.url | jdbc:postgresql://127.0.0.1:port/dbname 其中,port为opengauss的连接端口,dbname为待迁移数据库名 | + | database.url | jdbc:postgresql://127.0.0.1:port/dbname?stringtype=unspecified 其中,port为opengauss的连接端口,dbname为待迁移数据库名,TimeZone设置值需要与postgres数据库时区相同 | | database.user | openGauss数据库中创建复制用户 | | database.password | 复制用户的密码 | - 配置openGauss2postgresql13-tools-migration\migration.sh - | 变量名称 | 添加内容 | - | --------- | -------------------------------------- | - | SCHEMA | 待迁移schema,若无schema,则填入public | - | PG_HOST | postgres所在主机ip | - | PG_USER | postgres的安装用户 | - | PG_PORT | 待迁移postgres数据库连接端口 | - | PG_DBNAME | 待迁移postgres数据库名称 | - | OG_PORT | 本机openGauss数据库连接端口 | - | OG_DBNAME | 本机openGauss端接收数据库名称 | + | 变量名称 | 添加内容 | + | ----------- | -------------------------------------- | + | SCHEMA | 待迁移schema,若无schema,则填入public | + | PG_HOST | postgres所在主机ip | + | PG_USER | postgres的安装用户 | + | PG_PORT | 待迁移postgres数据库连接端口 | + | PG_DBNAME | 待迁移postgres数据库名称 | + | PG_DATA_DIR | postgres端存放中间数据的目录 | + | OG_PORT | 本机openGauss数据库连接端口 | + | OG_DBNAME | 本机openGauss端接收数据库名称 | + | OG_DATA_DIR | openGauss端存放中间数据的目录 | - 运行shell脚本 diff --git a/migration.sh b/migration.sh index 9041a46..c4c5e1f 100644 --- a/migration.sh +++ b/migration.sh @@ -1,21 +1,37 @@ +# Postgres database schema to be migrated # default:public SCHEMA="public" + # host of postgres # for example, PG_HOST="0.0.0.0" PG_HOST="" + # install user of postgres # for example, PG_USER="postgres" PG_USER="" + +# database port of postgres database +# for example, PG_PORT="5432" +PG_PORT="" + # Postgres database name to be migrated # for example, PG_DBNAME="pg_dbname" -PG_PORT="" PG_DBNAME="" + +# The directory where intermediate data is stored on the postgres side +# for example, PG_DATA_DIR="/data/pg2og" PG_DATA_DIR="" + # database port of openGauss in local host # for example, OG_PORT="5432" -# for example, OG_DBNAME="og_dbname" OG_PORT="" + +# opengauss database name for receiving data from postgres +# for example, OG_DBNAME="og_dbname" OG_DBNAME="" + +# The directory where intermediate data is stored on the opengauss side +# for example, OG_DATA_DIR="/data/pg2og" OG_DATA_DIR="" DIR=$(cd `dirname $0`;pwd) diff --git a/pgdumpSnapshotter/target/classes/META-INF.services/io.debezium.connector.postgresql.spi.Snapshotter b/pgdumpSnapshotter/target/classes/META-INF.services/io.debezium.connector.postgresql.spi.Snapshotter new file mode 100644 index 0000000..64f0bcd --- /dev/null +++ b/pgdumpSnapshotter/target/classes/META-INF.services/io.debezium.connector.postgresql.spi.Snapshotter @@ -0,0 +1 @@ +io.debezium.connector.postgresql.snapshot.PgDumpSnapshotter \ No newline at end of file diff --git a/pgdumpSnapshotter/target/classes/io/debezium/connector/postgresql/snapshot/PgDumpSnapshotter.class b/pgdumpSnapshotter/target/classes/io/debezium/connector/postgresql/snapshot/PgDumpSnapshotter.class new file mode 100644 index 0000000000000000000000000000000000000000..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i1_z@kqO76B zcq^A0oz-E>P-_+Gf3Y0JWjGqD0(UE6rEsQJmPMq)MU8iD!F2sMGDU(t)PKz;dX$5+&iuP9-KvZYjw z9P{pL%)3k~8_&)RPiBTkvg1>e@yz7#bY^TS8$Wu)IZ8X{@eP?EFKl$#pl?BU-z~B) za*DZK(|BeoJ*;%5Q?sdbd?q!W8qN-%NvF6R9!Whv zHCg(+j|6t9P)ryVb*m9q4r~H1@1So^`xEI%eMaSC!73zo#!7Hd+}R09ylU;qp4nCi z{6dF@2zv&Zr(S`f?Q!m8Gsiin4$oP6dmzWZG(3Z3GhMW694=L_Q`K^T-OhjM52aE3 z4u8<_`<)Ks0g80o#OrKx^_D$ePAx2Ov}fbUs3HBVC8y{1O}_{RW$xes(iP%=Gyj_; zYy7>Tam^u|pKW|f@LTY^xpxKnAGv74Zhp3?mwT~?YuyvTUAUW1%uDR0)IKG9g!x6=pLO*x@V$?~l3Zz(6{P9&1f8X; zld+kh@Egd=t^PG!AT=Lb#>ZD-P%KuUP|Wfqm+{mpDlKngel8Tdl9>y~mNIkA1DRz! zJ=EOUyo_hgZ?WGQ4hp=xqG#6?y@tr-z%srR`)c@Ygyurh-pne#KB+wTCQak6H2-FA z-wM8UlWy5TAK)eG?81xqAy;9dPvJ-SF_UJE zPd~v=x%&>Y@?|CW3WL&t(0^%ah)J$tQsacd@9SY%2S3Bly$E84@L>wK^!EQ5uWlrL zl<$Ed!Y7rHy`I#%kuCToenkvf9 Date: Wed, 15 Dec 2021 06:48:37 +0000 Subject: [PATCH 2/2] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=96=87=E4=BB=B6=20pgdu?= =?UTF-8?q?mpSnapshotter/target/classes/io/debezium/connector/postgresql/s?= =?UTF-8?q?napshot/PgDumpSnapshotter.class?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../postgresql/snapshot/PgDumpSnapshotter.class | Bin 4217 -> 0 bytes 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 pgdumpSnapshotter/target/classes/io/debezium/connector/postgresql/snapshot/PgDumpSnapshotter.class diff --git a/pgdumpSnapshotter/target/classes/io/debezium/connector/postgresql/snapshot/PgDumpSnapshotter.class b/pgdumpSnapshotter/target/classes/io/debezium/connector/postgresql/snapshot/PgDumpSnapshotter.class deleted file mode 100644 index 11fa30ab053b84fbf993c1e3d5f86917ad19cafb..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 4217 zcmbVPTX!2*75xtCiD1qvlVD8=@wSK$rT;;B!(@xW951@N6SBYPA(wTsuXbY{*z-`@M% zm$UVc|Gf1V03X1gG&Bh$Ejy7n=gp_BS}BpU%Vjg?+SNqGcHBbMbS@VYPT8n9i?*AX zE{xVnm5l%BnpF*9fx9jlSByl_C>Ih_^Oty9LyN#e+rw6@L;y=5>e#hv&Kxf<*aFAX zI|7(mSa3`?;~K7+6lghRl`Z$QK&ZQCRvat87lzO7mtlYs?o- zfmqtk8O2$nYRPB+W!PP`9Dzr6V8R`#p*6AjnpMo#T|8GatJefhbT^<@&7$F2cG)N< zl=AU>vL~$wt+`e)F;($4iPoC23T4BsRcZC({};$94_HMi<5sP5A$dBfp+lf!BZS_@ z8ELs$jiMd9A~-0pJCjPMMzZnV_}Q7MiMZUjSI2$0pQIa=idoJJ40LZ+;5!r0=|d-@ zh~uz^2L$d9MtU7NS z9*GihZSQ0heHhTt&oFJKTgM<00!{XUKzGn9FTw8=BF&XaG)^kw+XY!bTo&luL|C02 zf&1!Zr}Bbn`V<4E61`-WU4fInU9MF!6Qi}NN~2^TcQU4XCqwNWoISOj3#Ye4-!jQ0 z*&otz5<>#bW~t(`5Zdd3yFJm{iu5&0uk0G#+~;}J=%tLKM>WfI&uu;vy0NIQRqBO( ztWk6aE(-Ln$DwMJ9U~_Ta@?`KvQ3*;%wixY6ODzrbvu=PuV}j?Ra3=m#&l}M^-u*W zg|#^%~AHcvv##)xDlKc*n5qC0}~Si`FwnAY^YQka-1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