wal2json是逻辑解码插件,使用该插件可以访问由INSERT和UPDATE生成的元组,解析WAL中的内容。
本篇文章介绍了如何手动编译openGauss对应版本的wal2json.so。
首先,需要一套对应版本数据库的软件和openGauss-server的源码,以及wal2json代码进行编译安装。本篇文章以openGauss 3.0.0为例
对应的网址如下:
1.openGauss-server源码路径:openGauss-server: openGauss kernel ~ openGauss is an open source relational database management system.
2.openGauss软件下载路径:软件包 | openGauss
3.wal2json代码路径:wal2json: This project is a fork from wal2json, a compatibility version for openGuass.
我编译好的openGauss 3.0的 wal2json.so(x86)放到了gitee上,需要的朋友可以自取:wal2json-openGauss3.0-x86: wal2json-openGauss3.0-x86
- [mog@localhost ~]$ pwd
- /home/mog
- [mog@localhost ~]$ mkdir opengauss-server-package
- [mog@localhost ~]$ cd opengauss-server-package/
- [mog@localhost opengauss-server-package]$ git clone https://gitee.com/opengauss/openGauss-server.git
- Cloning into 'openGauss-server'...
- remote: Enumerating objects: 59079, done.
- remote: Counting objects: 100% (13276/13276), done.
- remote: Compressing objects: 100% (4659/4659), done.
复制opengauss源码src/include/*的内容到数据库安装目录的include/postgresql/server 下,cd到这个目录下,执行 rm -f pg_config_os.h; cp port/linux.h pg_config_os.h
因此我本地源码对应的要拷贝的目录为:
/home/mog/opengauss-server-package/openGauss-server/src/include/*
这里 /mogdb/software是我本地数据库的软件目录。
因此我软件的对应目录为
/mogdb/software/include/postgresql/server
进行拷贝
cp -r /home/mog/opengauss-server-package/openGauss-server/src/include/* /mogdb/software/include/postgresql/server
替换pg_config_os.h
- cd /mogdb/software/include/postgresql/server
- rm -f pg_config_os.h
- cp port/linux.h pg_config_os.h
#编译前需要确保g+ +安装,g+ +需要c+ +14版本
本地发现g++版本不够,重新编译安装较高版本,这里gcc要至少6.1版本,否则会有相关报错
yum -y install gcc+ gcc-c++
当前版本较低
wget http://ftp.gnu.org/gnu/gcc/gcc-6.2.0/gcc-6.2.0.tar.bz2
tar jxf gcc-6.2.0.tar.bz2
- cd gcc-6.2.0
- ./contrib/download_prerequisites
- mkdir gcc-build-6.2.0
- cd gcc-build-6.2.0/
- ../configure -enable-checking=release -enable-languages=c,c++ -disable-multilib
make
漫长的等待
make install
git clone https://gitee.com/enmotech/wal2json
-
- export PATH=/mogdb/software/bin:$PATH
- make
- make install
发现编译过程存在报错,我们把对应的几个.h里进行修改,去掉std::
最后编译成功
wal2json放到对应路径下
已经可以正常使用了
- postgres=# select * from pg_create_logical_replication_slot('mdb_20220823025242_slot','wal2json');
- slotname | xlog_position
- -------------------------+---------------
- mdb_20220823025242_slot | D70/EE73A0A8
- (1 row)