【我和openGauss的故事】openEuler20.03上编译安装opengauss-5.0.0
ziyoo0830 [openGauss](javascript:void(0);) 2023-08-03 16:49 发表于四川
为了更好地学习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工具进行调试。
标签:5.0,openEuler20.03,server,--,debug,home,openGauss,opengauss From: https://blog.51cto.com/u_16191492/7011818