diff --git a/content/zh/post/douxin/database-sync_for_openGauss.md b/content/zh/post/douxin/database-sync_for_openGauss.md new file mode 100644 index 0000000000000000000000000000000000000000..09b7725c1d252e590befde22bdb5474cbf449962 --- /dev/null +++ b/content/zh/post/douxin/database-sync_for_openGauss.md @@ -0,0 +1,183 @@ ++++ +title = "database-sync适配openGauss使用指导书" +date = "2021-03-29" +tags = ["openGauss社区开发入门"] +archives = "2021-03" +author = "douxin" +summary = "openGauss社区开发入门" +img="/zh/post/douxin/title/img1.png" +times = "17:30" + ++++ + +## 一、database-sync简介 + +database-sync作为一种开源辅助工具,用于数据库之间的表同步,更确切的说法是复制,可以从一个数据库复制表到另一个数据库 + +- 该工具支持的功能如下: + (1)自动同步表字段,如:源表扩字段,目标表自动扩字段 + + (2)支持增量或全量同步数据 + + (3)支持指定字段同步,只同步关心的字段 + +- 支持的关系型数据库: + + mysql、db2、postgresql、oracle、sqlserver + +- 源代码下载: + + database-sync代码托管在github上 + + 源代码下载:[下载](https://gitee.com/somenzz/database-sync) + +## 二、database-sync适配openGauss + +目标:database-sync适配openGauss数据库,可支持openGauss与其他数据库之间实现数据同步 + +源代码下载:适配openGauss的源代码已上传到个人仓库下的“douxin_master”分支 + +下载链接:[下载](https://gitee.com/ywzq1161327784/database-sync) + +## 三、程序使用说明 + +前提:已安装Java JDK 1.8或更高版本,安装maven + +### Step 1:下载代码并打包 + +git clone下载 douxin_master分支的代码,并进行打包 + +``` +git clone https://gitee.com/ywzq1161327784/database-sync.git +cd database-sync/ +git checkout origin/douxin_master +mvn clean package -Dmaven.test.skip=true +``` + +打包后,target目录内容如下: + +![1616832540491](../image/database-sync/image1.png) + +### Step 2:构建可执行工程目录 + +将mylib目录、target下的lib目录和database-sync-1.3.jar包复制到同一目录下,并创建一个config目录,在其下创建config.json文件写入配置信息,目录结构如下所示: + +![1616845721141](../image/database-sync/image2.png) + +### Step 3:编写配置文件 + +数据库连接信息以json格式配置在config/config.json文件中,每个节点包含type、driver、url、user、password、tbspace_ddl、encoding信息, + +其中type指定数据库类型,取值为db2、postgres、mysql、oracle、sqlserver、openGauss,特别地,对于openGauss数据库需指定“type”:“openGauss”; + +tbspace_ddl指定表空间语句,encoding指定编码方式。 + +配置文件示例: + +``` +{ + "database1":{ + "type":"openGauss", + "driver":"org.postgresql.Driver", + "url":"jdbc:postgresql://ip:port/postgres", + "user": "****", + "password":"******", + "tbspace_ddl": "", + "encoding":"utf-8" + }, + + "database2":{ + "type":"postgres", + "driver":"org.postgresql.Driver", + "url":"jdbc:postgresql://ip:5432/postgres", + "user": "****", + "password":"******", + "tbspace_ddl":"WITH (compression=no, orientation=orc, version=0.12)\ntablespace hdfs\n", + "encoding":"utf-8" + }, + + "database3":{ + "type":"oracle", + "driver":"oracle.jdbc.driver.OracleDriver", + "url":"jdbc:oracle:thin:@localhost:1521:orcl", + "user": "****", + "password":"****", + "tbspace_ddl": "", + "encoding":"utf-8" + }, + + "database4":{ + "type":"db2", + "driver":"com.ibm.db2.jcc.DB2Driver", + "url":"jdbc:db2://ip:port/wbsj", + "user": "****", + "password":"****", + "tbspace_ddl": "", + "encoding":"utf-8" + }, + + "database5":{ + "type":"mysql", + "driver":"com.mysql.cj.jdbc.Driver", + "url":"jdbc:mysql://localhost:3306/aarondb", + "user": "****", + "password":"****", + "encoding":"utf-8" + }, + + "buffer-rows": 100000 +} +``` + +### Step 4:查看程序帮助信息 + +在步骤2中的目录下,执行`java -jar database-sync-1.3.jar -h`命令可查看程序运行的帮助信息 + +![1616847412381](../image/database-sync/image3.png) + +其中[]表示可选参数,包括如下几种: + +--version或者-v表示打印版本信息并退出; + +--help或者-h表示打印帮助信息并退出; + +--sync-ddl或者-sd 表示自动同步表结果,默认情况下不会自动同步表结构,因此不指定该参数时,同步表时下述的目标表{toDB}需存在; + +--from_fields=col1,col2或者-ff=col3,col4表示指定原表的字段序列; + +--to_fields=col1,col2或者-tf=col3,col4表示指定目标表的字段序列; + +--no-feture或者-nf表示不使用特定数据库的特性; + +[whereClause]表示where条件,用于增量更新。 + +**{}表示必选参数**,共有6个,分别说明如下: + +{fromDB}表示原表所在的数据库信息,在Step3所示的配置文件中,可以取值为database1,database2等; + +{fromSchema}表示原表的模式名; + +{fromTable}表示原表的表名; + +{toDB}表示目标表所在的数据库信息; + +{toSchema}表示目标表的模式名; + +{toTable}表示目标表的表名。 + +### Step 5:跨数据库间实现表数据同步 + +eg 1:从postgres到openGauss实现表同步 + +`java -jar database-sync-1.3.jar -sd postgres public test_0322 opengauss1 public test_0322_1` + +![1616848683463](../image/database-sync/image4.png) + +eg 2:从openGauss到postgres实现表同步 + +`java -jar database-sync-1.3.jar -sd opengauss1 public test_0322_1 postgres public test_0322` + +![1616848847482](../image/database-sync/image5.png) + +至此,可实现openGauss数据库与其他数据库间的表数据同步 + diff --git a/content/zh/post/douxin/image/database-sync/image1.png b/content/zh/post/douxin/image/database-sync/image1.png new file mode 100644 index 0000000000000000000000000000000000000000..d1f4a28c6091d05829457f0fa8a15dd2bb71a589 Binary files /dev/null and b/content/zh/post/douxin/image/database-sync/image1.png differ diff --git a/content/zh/post/douxin/image/database-sync/image2.png b/content/zh/post/douxin/image/database-sync/image2.png new file mode 100644 index 0000000000000000000000000000000000000000..e85528341885b975d47b2efec40fd5d2ba4bbb44 Binary files /dev/null and b/content/zh/post/douxin/image/database-sync/image2.png differ diff --git a/content/zh/post/douxin/image/database-sync/image3.png b/content/zh/post/douxin/image/database-sync/image3.png new file mode 100644 index 0000000000000000000000000000000000000000..56b1c5b18f9f2718cdd7e5bfc892995755517371 Binary files /dev/null and b/content/zh/post/douxin/image/database-sync/image3.png differ diff --git a/content/zh/post/douxin/image/database-sync/image4.png b/content/zh/post/douxin/image/database-sync/image4.png new file mode 100644 index 0000000000000000000000000000000000000000..e7e8bce68cc9089b0f9c23797d8a41b7289bccdb Binary files /dev/null and b/content/zh/post/douxin/image/database-sync/image4.png differ diff --git a/content/zh/post/douxin/image/database-sync/image5.png b/content/zh/post/douxin/image/database-sync/image5.png new file mode 100644 index 0000000000000000000000000000000000000000..7335e5691fe236ab2eef1126f0b72a87726b0717 Binary files /dev/null and b/content/zh/post/douxin/image/database-sync/image5.png differ diff --git a/content/zh/post/douxin/title/img1.png b/content/zh/post/douxin/title/img1.png new file mode 100644 index 0000000000000000000000000000000000000000..65e2d4c4751f069c64357704715e2ba99beb511a Binary files /dev/null and b/content/zh/post/douxin/title/img1.png differ