【我和openGauss的故事】openEuler20.03上编译安装opengauss-5.0.0

为了更好 地 学习openGauss数据库知识,有时候需要去调试源代码来深入了解一些东西。 以下记录了在openEuler20.03上编译最新的openGauss-server源代码的过程,记录了手工编译过程遇到的一些问题,同时尝试使用vscode去调试了下源代码,文中也提供了几个vscode的调试样例。

vscode调试参考:https://www.modb.pro/db/1683159982970331136,https://www.modb.pro/db/658344。

以下采用的是手工编译的方法来安装。

下载第三方 libs

  
  
  
mkdir -p /home/debug/opengauss/binarylibs/
wget https://opengauss.obs.cn-south-1.myhuaweicloud.com/5.0.0/binarylibs/openGauss-third_party_binarylibs_openEuler_x86_64.tar.gz
# 以上提供的是已经编译好的包,无需再次编译, 用--with-3rdpartydir不要用--with-3rdparty_sourcedir
tar -xf openGauss-third_party_binarylibs_openEuler_x86_64.tar.gz -C /home/debug/opengauss/binarylibs/

下载 opengauss-server 代码

下载 5.0.0 的源代码

  
  
  
cd /home/debug/opengauss/
git clone https://gitee.com/opengauss/openGauss-server.git openGauss-server -b 5.0.0

configure

  
  
  
cd openGauss-server
# 编译debug版本
./configure --gcc-version=7.3.0 CC=g++ CFLAGS='-O0' --prefix=$GAUSSHOME --with-3rdpartydir=$BINARYLIBS --enable-debug --enable-cassert --enable-thread-safety --with-readline --without-zlib

#
以上是sh build.sh脚本中使用的configure命令参数记录。
./configure --gcc-version=7.3.0 --prefix=/home/debug/opengauss/opengauss-server/openGauss-server/mppdb_temp_install --3rd=/home/debug/opengauss/binarylibs/ --enable-thread-safety --with-readline --without-zlib CFLAGS=-O0 --enable-mot --enable-debug --enable-cassert CC=g++

make

  
  
  
make

make[2]: Leaving directory '/home/debug/opengauss/opengauss-server/openGauss-server/src/test/regress'
make[1]: Leaving directory '/home/debug/opengauss/opengauss-server/openGauss-server/src'
make -C config all
make[1]: Entering directory '/home/debug/opengauss/opengauss-server/openGauss-server/config'
make[1]: Nothing to be done for 'all'.
make[1]: Leaving directory '/home/debug/opengauss/opengauss-server/openGauss-server/config'

make install

  
  
  
make install

make[1]: Leaving directory '/home/debug/opengauss/opengauss-server/openGauss-server/contrib/dblink'
openGauss installation complete.

配置环境变量

  
  
  
# more .bashrc

export CODE_BASE=/home/debug/opengauss-server
export BINARYLIBS=/home/debug/binarylibs
export GAUSSHOME=/home/debug/ogsql
export GCC_PATH=$BINARYLIBS/buildtools/gcc7.3
export CC=$GCC_PATH/gcc/bin/gcc
export CXX=$GCC_PATH/gcc/bin/g++
export LD_LIBRARY_PATH=$GAUSSHOME/lib:$GCC_PATH/gcc/lib64:$GCC_PATH/isl/lib:$GCC_PATH/mpc/lib:$GCC_PATH/mpfr/lib:
$GCC_PATH/gmp/lib:$LD_LIBRARY_PATH
export PATH=$GAUSSHOME/bin:$GCC_PATH/gcc/bin:$PATH
export PGDATA=/home/debug/ogdata
export PATH=$GAUSSHOME/bin:$PATH
export S3_CLIENT_CRT_FILE=$GAUSSHOME/lib/client.crt
export PGHOST=$PGDATA/

初始化数据库

  
  
  
mkdir -p /home/debug/ogdata
gs_initdb -D /home/debug/ogdata --nodename=pghost1

Success. You can now start the database server of single node using:

gaussdb -D /home/debug/ogdata --single_node
or
gs_ctl start -D /home/debug/ogdata -Z single_node -l logfile

启动数据库

  
  
  
gs_ctl start -D /home/debug/ogdata -Z single_node -l /home/debug/ogdata/log/opengauss.log

登录数据库

  
  
  
gsql -d postgres -p 5432 -r

问题记录

expected primary-expression

…/…/…/src/include/storage/cfs/cfs_converter.h:15:55: error: expected primary-expression before ‘/’ token
constexpr int CFS_EXTENT_COUNT_PER_FILE = RELSEG_SIZE / CFS_EXTENT_SIZE;
^
In file included from cfs_tools.cpp:9:0:
…/…/…/src/include/storage/cfs/cfs_converter.h:15:55: error: expected primary-expression before ‘/’ token
constexpr int CFS_EXTENT_COUNT_PER_FILE = RELSEG_SIZE / CFS_EXTENT_SIZE;
^
make[3]: *** [Makefile:49: libpagecompression.so] Error 1
make[3]: Leaving directory ‘/home/debug/opengauss/opengauss-server/openGauss-server/src/lib/page_compression’
make[2]: *** [Makefile:31: all-page_compression-recurse] Error 2
make[2]: Leaving directory ‘/home/debug/opengauss/opengauss-server/openGauss-server/src/lib’
make[1]: *** [Makefile:68: all-lib-recurse] Error 2
make[1]: Leaving directory ‘/home/debug/opengauss/opengauss-server/openGauss-server/src’
make: *** [GNUmakefile:12: all-src-recurse] Error 2

   
   
   
# configure 脚本中该值无法计算 ,可以直接写按默认值计算出的值。
# RELSEG_SIZE=`expr '(' 1024 / ${blocksize} ')' '*' ${segsize} '*' 1024`
# RELSEG_SIZE=`expr '(' 1024 / 8 ')' '*' 1 '*' 1024`
RELSEG_SIZE=131072

vscode 调试代码

gaussdb 的服务进程入口为 src/gausskernel/process/main/main.cpp 下的main函数,在此函数的第一行代码打上断点。

详细配置调试方法可参考网上方法。

  
  
  
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [

{
"name": "gaussdb --help",
"type": "cppdbg",
"request": "launch",
"program": "/home/debug/opengauss/opengauss-server/dest/bin/gaussdb",
"args": [
"--help"
],
"stopAtEntry": false,
"cwd": "${fileDirname}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
},
{
"name": "gaussdb -D /home/debug/ogdata",
"type": "cppdbg",
"request": "launch",
"program": "/home/debug/opengauss/opengauss-server/dest/bin/gaussdb",
"args": [
"--D",
"/home/debug/ogdata"
],
"stopAtEntry": false,
"cwd": "${fileDirname}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}

总结

从以上编译过程可以看到,openGauss的编译还是比较简单的。
也可以编译出tar包,部署到线上测试环境,使用gdb工具进行调试。

本文分享自微信公众号 - openGauss(openGauss)。
如有侵权,请联系 support@oschina.cn 删除。
本文参与“ OSC源创计划 ”,欢迎正在阅读的你也加入,一起分享。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

openGauss社区

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值