PostgreSQL:测试 Readline 和 Zlib 选项

PostgreSQL 编译安装时默认支持 readline 和 zlib,其中 readline 选项支持 psql 历史命令查看等功能,zlib 选项支持 pg_dump 的压缩功能,下面测试这两个功能,测试方法:重新编译 PostgreSQL 并不带readline 和 zlib 选项:

重新编译安装

创建用户

1
2
3
#groupadd pgtest
#useradd -g pgtest pgtest
#passwd pgtest

环境变量 .bash_profile

1
2
3
4
5
6
7
8
9
10
11
12
export PGPORT=1922
export PGUSER=postgres
export PGDATA=/database/pgtest/pgdata/pg_root
export LANG=en_US.utf8

export PGHOME=/opt/pgsql_test
export LD_LIBRARY_PATH=$PGHOME/lib:/lib64:/usr/lib64:/usr/local/lib64:/lib:/usr/lib:/usr/local/lib
export DATE=`date +"%Y%m%d%H%M"`
export PATH=$PGHOME/bin:$PATH:.
export MANPATH=$PGHOME/share/man:$MANPATH
alias rm='rm -i'
alias ll='ls -lh'

清理编译文件,重新编译

1
2
# gmake clean
# gmake distclean

编译

1
./configure --prefix=/opt/pgsql_test --with-pgport=1922 --with-wal-blocksize=16 without-readline --without-zlib

备注:注意选项 –without-readline –without-zlib

安装

1
2
# gmake world
# gmake install-world

初始化 initdb

1
$ initdb -D /database/pgtest/pgdata/pg_root -E UTF8 --locale=C -U postgres -W

备注:以数据库用户执行 initdb 操作即可,这里是以 pgtest 用户执行。

测试 Readline

readline 测试,发现上下翻键无效,Backspace 键也无效

1
2
3
4
5
6
7
8
9
10
11
[pgtest@host172-16-3-215 ~]$ psql
psql (9.1.9)
Type "help" for help.

postgres=# select now();
now
-------------------------------
2013-11-18 13:56:55.350743+08
(1 row)

postgres=# ^[[A ----上下翻键无效

备注:如果没安装Readline 库,既编译时加上 –without-readline 选项,那么 psql 端不能使用上下翻键和 Backspace 键,也不能查看历史 psql 命令,非常不方便。

测试 Zlib

建库

1
2
3
4
5
6
[pgtest@host172-16-3-215 ~]$ psql
psql (9.1.9)
Type "help" for help.

postgres=# create database francs;
CREATE DATABASE

建表

1
2
3
4
5
francs=# create table test_1 (id int4);
CREATE TABLE

francs=# insert into test_1 select generate_series(1,1000);
INSERT 0 1000

备份测试

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
[pgtest@host ~]$ pg_dump -h 127.0.0.1 -E UTF8 -Fc francs -v > francs.dmp
pg_dump: reading schemas
pg_dump: reading user-defined tables
pg_dump: reading extensions
pg_dump: reading user-defined functions
pg_dump: reading user-defined types
pg_dump: reading procedural languages
pg_dump: reading user-defined aggregate functions
pg_dump: reading user-defined operators
pg_dump: reading user-defined operator classes
pg_dump: reading user-defined operator families
pg_dump: reading user-defined text search parsers
pg_dump: reading user-defined text search templates
pg_dump: reading user-defined text search dictionaries
pg_dump: reading user-defined text search configurations
pg_dump: reading user-defined foreign-data wrappers
pg_dump: reading user-defined foreign servers
pg_dump: reading default privileges
pg_dump: reading user-defined collations
pg_dump: reading user-defined conversions
pg_dump: reading type casts
pg_dump: reading table inheritance information
pg_dump: reading rewrite rules
pg_dump: finding extension members
pg_dump: finding inheritance relationships
pg_dump: reading column info for interesting tables
pg_dump: finding the columns and types of table "test_1"
pg_dump: flagging inherited columns in subtables
pg_dump: reading indexes
pg_dump: reading constraints
pg_dump: reading triggers
pg_dump: reading large objects
pg_dump: reading dependency data
pg_dump: saving encoding = UTF8
pg_dump: saving standard_conforming_strings = on
pg_dump: saving database definition
pg_dump: [archiver] WARNING: requested compression not available in this installation -- archive will be uncompressed
pg_dump: dumping contents of table test_1

备注:查看日志输出倒数第二行,”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/238015.html

(0)
上一篇 2022年1月30日
下一篇 2022年1月30日

相关推荐

发表回复

登录后才能评论