深度linux安装postgresql_PostgreSQL开发入门(1)--编译、测试

本文介绍了在Linux环境下编译和测试PostgreSQL的详细步骤,包括安装必要的依赖,如git、gcc、perl等,下载PostgreSQL源码,配置编译选项,进行回归测试和代码覆盖率检查。通过启用LLVM和TAP测试套件,确保PostgreSQL的稳定性和性能。
摘要由CSDN通过智能技术生成

3becb18a6afceeb5279a8bec6cc3851b.png

作为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功能,详细安装过程,请参看:https://developers.redhat.com/blog/2018/07/07/yum-install-gcc7-clang/。

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

为了启用PostgreSQL的TAP测试套件,需要安装Perl相关组件。perl-core内容,请参看:https://www.perl.com/article/what-is-the-perl-core-/。更多TAP内容,请参看:http://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会代码覆盖率报告,如下:

75cd99418feaf2e466d10eb88b6b9da6.png

详细过程请参看:https://www.postgresql.org/docs/current/regress-coverage.html。

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值