PostgreSQL 编译安装时默认支持 readline 和 zlib,其中 readline 选项支持 psql 历史命令查看等功能,zlib 选项支持 pg_dump 的压缩功能,下面测试这两个功能,测试方法:重新编译 PostgreSQL 并不带readline 和 zlib 选项:
重新编译安装
创建用户
1 |
groupadd pgtest |
环境变量 .bash_profile
1 |
export PGPORT=1922 |
清理编译文件,重新编译
1 |
gmake clean |
编译
1 |
./configure --prefix=/opt/pgsql_test --with-pgport=1922 --with-wal-blocksize=16 without-readline --without-zlib |
备注:注意选项 –without-readline –without-zlib
安装
1 |
gmake world |
初始化 initdb
1 |
$ initdb -D /database/pgtest/pgdata/pg_root -E UTF8 --locale=C -U postgres -W |
备注:以数据库用户执行 initdb 操作即可,这里是以 pgtest 用户执行。
测试 Readline
readline 测试,发现上下翻键无效,Backspace 键也无效
1 |
[pgtest@host172-16-3-215 ~]$ psql |
备注:如果没安装Readline 库,既编译时加上 –without-readline 选项,那么 psql 端不能使用上下翻键和 Backspace 键,也不能查看历史 psql 命令,非常不方便。
测试 Zlib
建库
1 |
[pgtest@host172-16-3-215 ~]$ psql |
建表
1 |
francs=# create table test_1 (id int4); |
备份测试
1 |
[pgtest@host ~]$ pg_dump -h 127.0.0.1 -E UTF8 -Fc francs -v > francs.dmp |
备注:查看日志输出倒数第二行,”pg_dump: [archiver] WARNING: requested compression not available in this installation “ , 表示不支持压缩,而这个功能是备份数据库时压缩比高,非常有用。
总结
Readline 和 zlib 属性非常重要,在编译 PostgreSQL 时,强烈推荐启用。
附: Readline 和 Zlib
4.1 Readline 解释
The GNU Readline library is used by default. It allows psql (the PostgreSQL command line SQL interpreter) to remember each command you type, and allows you to use arrow keys to recall and edit previous commands. This is very helpful and is strongly recommended. If you do not want to use it then you must specify the –without-readline option to configure. As an alternative, you can often use the BSD-licensed libedit library, originally developed on NetBSD. The libedit library is GNU Readline-compatible and is used if libreadline is not found, or if –with-libedit-preferred is used as an option to configure. If you are using a package-based Linux distribution, be aware that you need both the readline and readline-devel packages, if those are separate in your distribution.
4.2 zlib 解释
The zlib compression library is used by default. If you do not want to use it then you must specify the –without-zlib option to configure. Using this option disables support for compressed archives in pg_dump and pg_restore.
参考
原创文章,作者:254126420,如若转载,请注明出处:https://blog.ytso.com/tech/database/238015.html