PolarDB for PG15 之初体验

文摘   科技   2024-09-11 09:00   上海  

前言

Digoal(德哥)最近发布了消息,有称PolarDB for PG有重大版本更新,代码分支上开始支持PG15了。上一个版本是PG11, 这无疑是一个重大的版本更新。

于是,我按照提供的网站上的介绍,简单的试了一下。也说说自己的感受。

试用

1、直接从docker入手

参考文档:PolarDB for PostgreSQL:阿里云自主研发的云原生数据库[1]

拉取 PolarDB for PostgreSQL 的 单机实例镜像[2],运行容器并试用 PolarDB-PG:

声明一下,我这里用的是MacOS arm64系统(提前准备好Docker desktop),从效果来看,完美:

 polardb docker pull polardb/polardb_pg_local_instance:15                                           1 ↵
15: Pulling from polardb/polardb_pg_local_instance
e63ce922f022: Pull complete
d97884cea023: Pull complete
39cac19a0e18: Pull complete
8ea822c55bd1: Pull complete
e06267635bf9: Pull complete
aeaeffe7bc65: Pull complete
a816333e9c5b: Pull complete
34d064495bcf: Pull complete
b01f56a4840f: Pull complete
84730161a01c: Pull complete
a901a4d0073c: Pull complete
a0455e76b8bd: Pull complete
24683caf08e6: Pull complete
4f4fb700ef54: Pull complete
3fafc429db5e: Pull complete
fcc5cd3d66a3: Pull complete
a4080438be54: Pull complete
15b873ec7817: Pull complete
b02735bb7a6e: Pull complete
Digest: sha256:4bfa39b166211967292bf7fa24e7bdd26c9767724ef924ae6a4ccad7ed1304a8
Status: Downloaded newer image for polardb/polardb_pg_local_instance:15
docker.io/polardb/polardb_pg_local_instance:15


执行:

docker run -it --rm polardb/polardb_pg_local_instance:15 psql

执行的输出如下:

Begin initdb, flag: -D /var/polardb/primary_datadir --wal-segsize=16
PolarDB no use deploy mode
The files belonging to this database system will be owned by user "postgres".
This user must also own the server process.

The database cluster will be initialized with locale "en_US.UTF-8".
The default database encoding has accordingly been set to "UTF8".
The default text search configuration will be set to "english".

Data page checksums are disabled.

creating directory /var/polardb/primary_datadir ... ok
creating subdirectories ... ok
selecting dynamic shared memory implementation ... posix
selecting default max_connections ... 100
selecting default shared_buffers ... 128MB
selecting default time zone ... Asia/Shanghai
creating configuration files ... ok
.......

done
server started
psql (PostgreSQL 15.8 (PolarDB 15.8.2.0 build unknown) on aarch64-linux-gnu)
Type "help" for help.

postgres=#

最后我们能看到相关的版本输出信息:

psql (PostgreSQL 15.8 (PolarDB 15.8.2.0 build unknown) on aarch64-linux-gnu)
postgres=# select version();
version
-----------------------------------------------------------------------
PostgreSQL 15.8 (PolarDB 15.8.2.0 build unknown) on aarch64-linux-gnu
(1 row)

postgres=# \l
List of databases
Name | Owner | Encoding | Collate | Ctype | ICU Locale | Locale Provider | Access privileges
---------------+----------+----------+-------------+-------------+------------+-----------------+-----------------------
polardb_admin | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | | libc | =T/postgres +
| | | | | | | postgres=CTc/postgres
postgres | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | | libc |
template0 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | | libc | =c/postgres +
| | | | | | | postgres=CTc/postgres
template1 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | | libc | =c/postgres +
| | | | | | | postgres=CTc/postgres
(4 rows)

多了个pollard_admin的缺省数据库。

2、直接编译

2.1、MacOS上:

wget https://github.com/ApsaraDB/PolarDB-for-PostgreSQL/archive/refs/tags/v15.8.2.0.tar.gz
tar xf v15.8.2.0.tar.gz
cd PolarDB-for-PostgreSQL-15.8.2.0

export PATH="/opt/homebrew/opt/openssl@3/bin:/opt/homebrew/opt/icu4c/bin":$PATH
export LDFLAGS="-L/opt/homebrew/opt/openssl@3/lib -L/opt/homebrew/opt/icu4c/lib"
export CPPFLAGS="-I/opt/homebrew/opt/openssl@3/include -I/opt/homebrew/opt/icu4c/include"

./configure --prefix=/Users/sean/opt/polardb-15 --with-openssl --with-python --with-lz4 --with-libxml --with-libxslt 'ICU_CFLAGS=-I/opt/homebrew/opt/icu4c/include' 'ICU_LIBS=-L/opt/homebrew/opt/icu4c/lib -licui18n -licuuc -licudata' -with-extra-version=" [By SeanHe on polardb]"

configure过程没啥问题,问题最后出在make过程:

/Applications/Xcode.app/Contents/Developer/usr/bin/make -C libpq all
gcc -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Werror=vla -Werror=unguarded-availability-new -Wendif-labels -Wmissing-format-attribute -Wcast-function-type -Wformat-security -fno-strict-aliasing -fwrapv -Wno-unused-command-line-argument -Wno-compound-token-split-by-macro -Wno-deprecated-non-prototype -O2 -I../../../src/include -I/opt/homebrew/opt/icu4c/include -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.2.sdk -I/opt/homebrew/opt/openssl@3/include -I/opt/homebrew/opt/icu4c/include -I/opt/homebrew/Cellar/lz4/1.9.4/include -c -o polar_network_stats.o polar_network_stats.c
polar_network_stats.c:28:10: fatal error: 'linux/sockios.h' file not found
#include <linux/sockios.h>
^~~~~~~~~~~~~~~~~
1 error generated.
make[3]: *** [polar_network_stats.o] Error 1
make[2]: *** [libpq-recursive] Error 2
make[1]: *** [all-backend-recurse] Error 2
make: *** [all-src-recurse] Error 2

看来PolarDB目前并没有完全考虑在MacOS上的支持(对于广大开发人员来说,可能还是希望有这方面的支持)

2.2、试试Linux上的源码编译

平台:Red Hat Enterprise Linux Server release 7.9 (Maipo)

[23:52:56-postgres@sean-rh1:/iihero/source/polardb]$ lsb_release -a
LSB Version: :core-4.1-amd64:core-4.1-noarch
Distributor ID: RedHatEnterpriseServer
Description: Red Hat Enterprise Linux Server release 7.9 (Maipo)
Release: 7.9
Codename: Maipo

编译生成:

wget https://github.com/ApsaraDB/PolarDB-for-PostgreSQL/archive/refs/tags/v15.8.2.0.tar.gz
tar xf v15.8.2.0.tar.gz
cd PolarDB-for-PostgreSQL-15.8.2.0

[23:55:48-postgres@sean-rh1:/iihero/source/polardb/PolarDB-for-PostgreSQL-15.8.2.0]$ ./configure --prefix=/usr/polardb-15 --with-openssl --with-lz4 --with-libxml -with-extra-version=" [By SeanHe on polardb]"

make -j4 world-bin
su -c "make install-world-bin"

make[2]: Entering directory `/iihero/source/polardb/PolarDB-for-PostgreSQL-15.8.2.0/external/pase'
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 -fPIC -fopenmp -Wno-uninitialized -msse4 -mpopcnt -fcf-protection=none -I/usr/lib64/openmpi/share/vampirtrace -I. -I. -I../../src/include -D_GNU_SOURCE -I/usr/include/libxml2 -c -o type/pase_type.o type/pase_type.c
gcc: error: unrecognized command line option ‘-fcf-protection=none’
make[2]: *** [type/pase_type.o] Error 1
make[2]: Leaving directory `/iihero/source/polardb/PolarDB-for-PostgreSQL-15.8.2.0/external/pase'
make[1]: *** [install-pase-recurse] Error 2
make[1]: Leaving directory `/iihero/source/polardb/PolarDB-for-PostgreSQL-15.8.2.0/external'
make: *** [install-world-bin-external-recurse] Error 2

上边这一块儿,似乎是编译plugin/extension的时候,gcc不支持:

-fcf-protection=none

也许可以作为一个bug 来处理。去掉这个选项就好了。

于是,跳过extension:

su -c  "make install"
全部成功

运行一下源码安装的结果:

1. 建目录及初始化环境变量
mkdir -p /var/lib/pgsql/ploardb15

export PGROOT=/usr/polardb-15
export PGHOME=/var/lib/pgsql/ploardb15
export PGPORT=5432
export PGDATA=$PGHOME/data
export PATH=$PGROOT/bin:$PATH
export LD_LIBRARY_PATH=$PGROOT/lib:$LD_LIBRARY_PATH

initdb -D polardb15/ --locale=C -E UTF8
......
pg_ctl -D polardb15/ -l logfile start

log输出:
2024-09-11 00:33:33.056 UTC [6758] LOG: polar_vfs loaded in postmaster 6758
2024-09-11 00:33:33.056 UTC [6758] LOG: polar_vfs init done
2024-09-11 00:33:33.056 UTC [6758] LOG: "polar_settings.conf" is in non-sharedstorage mode, additional load it.
......
2024-09-11 00:33:33.079 UTC [6761] LOG: startup process DATA IO follows:open 0.000000 s, count 0, write 0.000000 s, count 0, read 0.000000 s, count 0, lseek 0.000000 s, count 0,fsync 0.000000 s, count 0
2024-09-11 00:33:33.080 UTC [6758] LOG: database system is ready to accept connections
2024-09-11 00:33:33.081 UTC [6764] LOG: [polar_resource_manager] resource manager started

2. 简单连接
00:34:25-postgres@sean-rh1:/var/lib/pgsql]$ psql
psql (PostgreSQL 15.8 [By SeanHe on polardb] (PolarDB 15.8.2.0 build unknown) on x86_64-linux-gnu)
Type "help" for help.

postgres=# create table t (id) as values (1), (2), (3);
SELECT 3
postgres=# select * from t;
id
----
1
2
3
(3 rows)

postgres=#

上边有完整的版本输出:psql (PostgreSQL 15.8 [By SeanHe on polardb]。

小遗憾就是那些extenstion, 得手动编译修改相关选项来处理。

它自带有一个build.sh, 没来得及去尝试。直接使用:

./build.sh --prefix=/iihero/polardb15 -m

仍然有一些错误,比如:

egin compile and install PolarDB, flag: -j4 -s
syslogger.c: In function ‘SysLogger_Start’:
syslogger.c:903:4: error: unknown option after ‘#pragma GCC diagnostic’ kind [-Werror=pragmas]
GCC_IGNORE_BEGIN("-Wstringop-overflow");
^
cc1: all warnings being treated as errors
make[3]: *** [syslogger.o] Error 1
make[2]: *** [postmaster-recursive] Error 2
make[2]: *** Waiting for unfinished jobs....
polar_logindex_redo.c: In function ‘polar_logindex_replay_db’:
polar_logindex_redo.c:2778:2: error: missing braces around initializer [-Werror=missing-braces]
BufferTag target_tag = {0};
^
polar_logindex_redo.c:2778:2: error: (near initialization for ‘target_tag.rnode’) [-Werror=missing-braces]
cc1: all warnings being treated as errors
make[4]: *** [polar_logindex_redo.o] Error 1
make[4]: *** Waiting for unfinished jobs....
make[3]: *** [logindex-recursive] Error 2
make[3]: *** Waiting for unfinished jobs....
make[2]: *** [access-recursive] Error 2
make[1]: *** [install-backend-recurse] Error 2
make: *** [install-world-bin-src-recurse] Error 2

总结

PolarDB for PG总的来说,是非常不错的。至少在安装和环境搭建方面,没有让人感到一连串的磕磕绊绊,尤其是对于刚切入这个数据库的技术人员而言。

小的瑕疵的地方:

在我所测试的平台:RHELS 7.9, gcc:

sing built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-redhat-linux/4.8.5/lto-wrapper
Target: x86_64-redhat-linux
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-bootstrap --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-linker-hash-style=gnu --enable-languages=c,c++,objc,obj-c++,java,fortran,ada,go,lto --enable-plugin --enable-initfini-array --disable-libgcj --with-isl=/builddir/build/BUILD/gcc-4.8.5-20150702/obj-x86_64-redhat-linux/isl-install --with-cloog=/builddir/build/BUILD/gcc-4.8.5-20150702/obj-x86_64-redhat-linux/cloog-install --enable-gnu-indirect-function --with-tune=generic --with-arch_32=x86-64 --build=x86_64-redhat-linux
Thread model: posix
gcc version 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC)

这只是一个初体验。后续有机会将尝试PolarDB和更多的国产数据库。

参考资料

[1]

PolarDB for PostgreSQL:阿里云自主研发的云原生数据库: https://apsaradb.github.io/PolarDB-for-PostgreSQL/zh/

[2]

单机实例镜像: https://hub.docker.com/r/polardb/polardb_pg_local_instance/tags




我是【Sean】,  欢迎大家长按关注并加星公众号:数据库杂记。有好资源相送,同时为你提供及时更新。已关注的朋友,发送0、1到7,都有好资源相送。


往期导读: 
1. PostgreSQL中配置单双向SSL连接详解
2. 提升PSQL使用技巧:PostgreSQL中PSQL使用技巧汇集(1)
3. 提升PSQL使用技巧:PostgreSQL中PSQL使用技巧汇集(2)
4. PostgreSQL SQL的基础使用及技巧
5. PostgreSQL开发技术基础:过程与函数
6. PostgreSQL中vacuum 物理文件truncate发生的条件
7. PostgreSQL中表的年龄与Vacuum的实验探索:Vacuum有大用
8. PostgreSQL利用分区表来弥补AutoVacuum的不足
9. 也聊聊PostgreSQL中的空间膨胀与AutoVacuum
10. 正确理解SAP BTP中hyperscaler PG中的IOPS (AWS篇)

数据库杂记
数据库技术专家,PostgreSQL ACE,SAP HANA,Sybase ASE/ASA,Oracle,MySQL,SQLite各类数据库, SAP BTP云计算技术, 以及陈式太极拳教学倾情分享。出版过三本技术图书,武术6段。
 最新文章