ITPub博客

首页 > IT职业 > > PostgreSQL开发入门(1)--编译、测试

PostgreSQL开发入门(1)--编译、测试

作者:格伯纳 时间:2020-05-19 17:34:24 0 删除 编辑

作为PostgreSQL开发人员,首先我们需要知道如何在Linux下进行编译、测试。这里将会介绍环境准备,代码下载、配置、编译,回归测试,如何获得代码覆盖率。

环境准备

操作系统:

[postgres@localhost ~]$ cat /etc/redhat-release
CentOS Linux release 7.6.1810 (Core)
[postgres@localhost ~]$ uname -a
Linux localhost.localdomain 3.10.0-957.el7.x86_64 #1 SMP Thu Nov 8 23:39:32 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux

环境准备(很贴心的只保留了命令):

sudo yum install -y git gcc lcov flex bison zlib-devel readline-devel libxml2-devel libxslt-devel openssl-devel vim lcov
sudo yum install -y epel-release
sudo yum install -y centos-release-scl
sudo yum install -y llvm-toolset-7 llvm-toolset-7-llvm-devel llvm5.0-devel llvm-toolset-7-clang-analyzer llvm-toolset-7-clang-tools-extra gcc-c++
scl enable llvm-toolset-7 bash //enable clang
sudo ln -s /opt/rh/llvm-toolset-7/root/usr/bin/clang /usr/bin/clang

补充:这里安装LLVM是为了启用PostgreSQL的JIT功能,详细安装过程,请参看:developers.redhat.com/b。

sudo yum install -y perl-core perl-IPC-Run

为了启用PostgreSQL的TAP测试套件,需要安装Perl相关组件。perl-core内容,请参看:perl.com/article/what-i。更多TAP内容,请参看:testanything.org/。

源码下载

Git下载:

[postgres@localhost ~]$ git clone git://git.postgresql.org/git/postgresql.git pg13
Cloning into 'pg13'...
remote: Counting objects: 761424, done.
remote: Compressing objects: 100% (109491/109491), done.
remote: Total 761424 (delta 652269), reused 757277 (delta 649047)
Receiving objects: 100% (761424/761424), 229.17 MiB | 1.08 MiB/s, done.
Resolving deltas: 100% (652269/652269), done.
[postgres@localhost ~]$ cd pg13/
[postgres@localhost pg13]$ ls
aclocal.m4  configure     contrib    doc             HISTORY   README      src
config      configure.in  COPYRIGHT  GNUmakefile.in  Makefile  README.git

Git结构:

[postgres@localhost pg13]$ git tag | grep REL_12
REL_12_0
REL_12_1
REL_12_BETA1
REL_12_BETA2
REL_12_BETA3
REL_12_BETA4
REL_12_RC1
[postgres@localhost pg13]$ git branch -r | grep REL_12
  origin/REL_12_STABLE

tag是PostgreSQL各个版本,branch是代码分支。

编译、测试:

[postgres@localhost pg13]$ ./configure --prefix=/home/postgres/pgdb13 --enable-debug --enable-coverage --enable-tap-tests --with-openssl --with-llvm LLVM_CONFIG=/usr/lib64/llvm5.0/bin/llvm-config --with-libxml --with-libxslt --enable-thread-safety
[postgres@localhost pg13]$ make world; make install-world; make check-world
[postgres@localhost pg13]$ make coverage-html

make coverage-html会代码覆盖率报告,如下:

详细过程请参看:postgresql.org/docs/cur。

当准备开发PostgreSQL时,我们首先要对整个数据库进行回归测试,确认没有问题后,再进行开发。当完成功能开发后,同时要增加自己的测试用例,还需要再次进行回归测试。同时要进行代码覆盖率测试,确保开发代码覆盖率足够高。

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/31509949/viewspace-3123505/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论
管理员

注册时间:2018-03-30

  • 博文量
    2383
  • 访问量
    984449