DB version: PostgreSQL 12.3 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-39), 64-bit
OS: CentOS Linux release 7.7.1908 (Core)
roaringbitmap: roaringbitmap-0.5
roaringbitmap插件github地址: https://github.com/ChenHuajun/pg_roaringbitmap
作者github地址里的安装过程写的比较简单,一路碰到不少坑,记录下来供参考。
目录
一、安装前环境确认
二、源码下载
三、依赖安装
四、roaringbitmap make && make install
五、create extension 并测试
六、roaringbitmap函数测试
七、遇到的问题
一、安装前环境确认
1.查看当前安装的pg,确保只有一个版本存在
[root@localhost ~]# rpm -qa|grep postgr
postgresql12-12.3-5PGDG.rhel7.x86_64
postgresql12-server-12.3-5PGDG.rhel7.x86_64
postgresql12-libs-12.3-5PGDG.rhel7.x86_64
2.确认当前环境变量配置
-bash-4.2$ cat ~/.bash_profile
[ -f /etc/profile ] && source /etc/profile
export PGHOME=/usr/pgsql-12/
export PGDATA=/var/lib/pgsql/12/data
export PGPORT=5432
export PGUSER=postgres
export PGHOST=127.0.0.1
export PATH=$PATH:$PGHOME/bin
# If you want to customize your settings,
# Use the file below. This is not overridden
# by the RPMS.
[ -f /var/lib/pgsql/.pgsql_profile ] && source /var/lib/pgsql/.pgsql_profile
3.确认postgres主机账号已设置密码
[root@localhost soft]# passwd postgres
Changing password for user postgres.
New password:
Retype new password:
passwd: all authentication tokens updated successfully.
4.确认postgres主机账号已添加至sudoers文件中
[root@localhost soft]# vi /etc/sudoers
## 添加下面postgres这行,保存退出,因为是只读文件,保存退出用 :wq!
## Allow root to run any commands anywhere
root ALL=(ALL) ALL
postgres ALL=(ALL) ALL ## 新增此行
二、源码下载
[root@localhost soft]# git clone https://github.com/ChenHuajun/pg_roaringbitmap.git
Cloning into 'pg_roaringbitmap'...
remote: Enumerating objects: 134, done.
remote: Counting objects: 100% (134/134), done.
remote: Compressing objects: 100% (71/71), done.
remote: Total 292 (delta 73), reused 117 (delta 58), pack-reused 158
Receiving objects: 100% (292/292), 422.63 KiB | 148.00 KiB/s, done.
Resolving deltas: 100% (161/161), done.
# 更改用户组
[root@localhost soft]# chown -R postgres:postgres pg_roaringbitmap
三、依赖安装
1.安装 llvm-toolset-7-clang >= 4.0.1
yum install centos-release-scl-rh -y
yum install llvm-toolset-7-clang -y
2.安装 llvm5.0-devel >= 5.0
[root@localhost soft]# wget https://download-ib01.fedoraproject.org/pub/epel/7/x86_64/Packages/e/epel-release-7-14.noarch.rpm
[root@localhost soft]# rpm -Uvh epel-release*rpm
[root@localhost soft]# yum install llvm5.0-devel -y
3.安装postgresql12-devel
[root@localhost pg_roaringbitmap]# yum install postgresql12-devel -y
四、roaringbitmap make && make install
1.make (warning不用理会,没有error即可)
[root@localhost ~]# su - postgres
-bash-4.2$ cd /u01/soft/pg_roaringbitmap/
-bash-4.2$ make
make: pg_config: Command not found
make: *** No targets. Stop.
-bash-4.2$ ls
benchmark LICENSE META.json roaringbitmap--0.2.sql roaringbitmap--0.5.sql roaringbitmap.h roaring.c
CHANGELOG.md Makefile README.md roaringbitmap--0.3--0.4.sql roaringbitmap.c roaring_buffer_reader.c roaring.h
expected Makefile_native roaringbitmap--0.2--0.3.sql roaringbitmap--0.4--0.5.sql roaringbitmap.control roaring_buffer_reader.h sql
-bash-4.2$ vi Makefile
PG_CONFIG =/usr/pgsql-12/bin/pg_config ## 修改这行,后面把绝对路径加上
-bash-4.2$ make
gcc -std=gnu99 -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Werror=vla -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -fPIC -std=c99 -Wno-error=maybe-uninitialized -Wno-declaration-after-statement -I. -I./ -I/usr/pgsql-12/include/server -I/usr/pgsql-12/include/internal -D_GNU_SOURCE -I/usr/include/libxml2 -I/usr/include -c -o roaringbitmap.o roaringbitmap.c
In file included from roaringbitmap.h:26:0,
from roaringbitmap.c:1:
roaring.h:317:16: warning: no previous prototype for ‘binarySearch’ [-Wmissing-prototypes]
inline int32_t binarySearch(const uint16_t *array, int32_t lenarray,
^
roaring.h:1518:13: warning: no previous prototype for ‘array_container_contains’ [-Wmissing-prototypes]
inline bool array_container_contains(const array_container_t *arr,
^
roaring.h:1567:17: warning: no previous prototype for ‘array_container_minimum’ [-Wmissing-prototypes]
inline uint16_t array_container_minimum(const array_container_t *arr) {
... 省略部分信息
gcc -std=gnu99 -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Werror=vla -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -fPIC -shared -o roaringbitmap.so roaringbitmap.o -L/usr/pgsql-12/lib -Wl,--as-needed -L/usr/lib64/llvm5.0/lib -L/usr/lib64 -Wl,--as-needed -Wl,-rpath,'/usr/pgsql-12/lib',--enable-new-dtags
/opt/rh/llvm-toolset-7/root/usr/bin/clang -Wno-ignored-attributes -fno-strict-aliasing -fwrapv -O2 -I. -I./ -I/usr/pgsql-12/include/server -I/usr/pgsql-12/include/internal -D_GNU_SOURCE -I/usr/include/libxml2 -I/usr/include -flto=thin -emit-llvm -c -o roaringbitmap.bc roaringbitmap.c
2.make install(如果此步骤缺少后面的四行输出则会遇到后面的报错3)
-bash-4.2$ sudo make install
[sudo] password for postgres:
/usr/bin/mkdir -p '/usr/pgsql-12/lib'
/usr/bin/mkdir -p '/usr/pgsql-12/share/extension'
/usr/bin/mkdir -p '/usr/pgsql-12/share/extension'
/usr/bin/install -c -m 755 roaringbitmap.so '/usr/pgsql-12/lib/roaringbitmap.so'
/usr/bin/install -c -m 644 .//roaringbitmap.control '/usr/pgsql-12/share/extension/'
/usr/bin/install -c -m 644 .//roaringbitmap--0.5.sql .//roaringbitmap--0.2.sql .//roaringbitmap--0.2--0.3.sql .//roaringbitmap--0.4--0.5.sql .//roaringbitmap--0.3--0.4.sql '/usr/pgsql-12/share/extension/'
/usr/bin/mkdir -p '/usr/pgsql-12/lib/bitcode/roaringbitmap'
/usr/bin/mkdir -p '/usr/pgsql-12/lib/bitcode'/roaringbitmap/
/usr/bin/install -c -m 644 roaringbitmap.bc '/usr/pgsql-12/lib/bitcode'/roaringbitmap/./
cd '/usr/pgsql-12/lib/bitcode' && /usr/lib64/llvm5.0/bin/llvm-lto -thinlto -thinlto-action=thinlink -o roaringbitmap.index.bc roaringbitmap/roaringbitmap.bc
五、create extension 并测试
-bash-4.2$ psql -c "create extension roaringbitmap"
CREATE EXTENSION
-bash-4.2$ make installcheck
/usr/pgsql-12/lib/pgxs/src/makefiles/../../src/test/regress/pg_regress --inputdir=./ --bindir='/usr/pgsql-12/bin' --dbname=contrib_regression roaringbitmap
(using postmaster on 127.0.0.1, port 5432)
============== dropping database "contrib_regression" ==============
NOTICE: database "contrib_regression" does not exist, skipping
DROP DATABASE
============== creating database "contrib_regression" ==============
CREATE DATABASE
ALTER DATABASE
============== running regression test queries ==============
test roaringbitmap ... ok 283 ms
=====================
All 1 tests passed.
=====================
六、roaringbitmap函数测试
见github地址
七、遇到的问题
报错1:未配置环境变量以及未安装 postgresql12-devel 开发包
-bash-4.2$ make
bash: make: command not found...
-bash-4.2$ /usr/bin/make
Makefile:14: /usr/pgsql-12/lib/pgxs/src/makefiles/pgxs.mk: No such file or directory
make: *** No rule to make target `/usr/pgsql-12/lib/pgxs/src/makefiles/pgxs.mk'. Stop.
报错2:未安装依赖包 llvm5.0-devel >= 5.0 和 llvm-toolset-7-clang >= 4.0.1
[root@localhost pg_roaringbitmap]# yum install postgresql12-devel
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: mirrors.163.com
* extras: mirrors.163.com
* updates: mirrors.163.com
Resolving Dependencies
--> Running transaction check
---> Package postgresql12-devel.x86_64 0:12.3-5PGDG.rhel7 will be installed
--> Processing Dependency: llvm5.0-devel >= 5.0 for package: postgresql12-devel-12.3-5PGDG.rhel7.x86_64
--> Processing Dependency: llvm-toolset-7-clang >= 4.0.1 for package: postgresql12-devel-12.3-5PGDG.rhel7.x86_64
--> Processing Dependency: libicu-devel for package: postgresql12-devel-12.3-5PGDG.rhel7.x86_64
--> Running transaction check
---> Package libicu-devel.x86_64 0:50.2-4.el7_7 will be installed
--> Processing Dependency: libicu(x86-64) = 50.2-4.el7_7 for package: libicu-devel-50.2-4.el7_7.x86_64
---> Package postgresql12-devel.x86_64 0:12.3-5PGDG.rhel7 will be installed
--> Processing Dependency: llvm5.0-devel >= 5.0 for package: postgresql12-devel-12.3-5PGDG.rhel7.x86_64
--> Processing Dependency: llvm-toolset-7-clang >= 4.0.1 for package: postgresql12-devel-12.3-5PGDG.rhel7.x86_64
--> Running transaction check
---> Package libicu.x86_64 0:50.2-3.el7 will be updated
---> Package libicu.x86_64 0:50.2-4.el7_7 will be an update
---> Package postgresql12-devel.x86_64 0:12.3-5PGDG.rhel7 will be installed
--> Processing Dependency: llvm5.0-devel >= 5.0 for package: postgresql12-devel-12.3-5PGDG.rhel7.x86_64
--> Processing Dependency: llvm-toolset-7-clang >= 4.0.1 for package: postgresql12-devel-12.3-5PGDG.rhel7.x86_64
--> Finished Dependency Resolution
Error: Package: postgresql12-devel-12.3-5PGDG.rhel7.x86_64 (pgdg12)
Requires: llvm5.0-devel >= 5.0
Error: Package: postgresql12-devel-12.3-5PGDG.rhel7.x86_64 (pgdg12)
Requires: llvm-toolset-7-clang >= 4.0.1
You could try using --skip-broken to work around the problem
You could try running: rpm -Va --nofiles --nodigest
报错3.make install 步骤不完整导致报错 Float8GetDatum
-bash-4.2$ /usr/pgsql-12/bin/psql -c "create extension roaringbitmap"
ERROR: could not load library "/usr/pgsql-12/lib/roaringbitmap.so": /usr/pgsql-12/lib/roaringbitmap.so: undefined symbol: Float8GetDatum