PG17源码编译安装

很早以前玩过PG12源码编译安装,说实话速度确实比MYSQL快,一个在虚拟机要1个多小时,另外PG只要20分钟.

可以参考:PG 源码编译安装

只是玩玩而已,后来忙工作,就没有深究PG,最近拾起PG12,发现它居然没有带上DEBUG信息.虽然CONFIG加了DEBUG信息. 观察GCC编译 带了-G 只是后面跟着-O2! 2级优化和调试信息是否冲突呢?

图片

额,这个PG12和PG17差距太大了点吧!,还是下载最新的PG17安装看看
下载的版本是:postgresql-17.1.tar.gz

配置编译遇到了缺少RPM包的问题:

编译报错缺少icu:
checking for icu-uc icu-i18n… no
configure: error: ICU library not found
If you have ICU already installed, see config.log for details on the
failure. It is possible the compiler isn’t looking in the proper directory.
Use --without-icu to disable ICU support.

检查icu是否没有安装
icu-config --version

安装icu
yum install libicu-devel -y

ICU据说是国际化的库不知道下面初始化数据库命令是不是上面的库所导致的?

initdb -D $PGDATA -E UTF8 --locale=zh_CN.utf8 

[shark@sharkdb=>bin]$initdb -D $PGDATA -E UTF8 --locale=zh_CN.utf8 
The files belonging to this database system will be owned by user "shark".
This user must also own the server process.

initdb: error: locale name "zh_CN.utf8 " contains non-ASCII characters

这是啥意思? 我用这个初始数据库命令可以初始化PG12,反而到了PG17就有毛病.重新配置下编译选项试试看
编译配置选项排除了ICU

./configure --prefix=/Program/pg17/pg_soft \
--enable-debug CFLAGS="-g3 -O0" --enable-dtrace 
--with-openssl 
--without-icu
./configure参数解释:
–prefix 参数是指定编译安装的目录;

–with-pgport 是指定psql的端口,通常为5432

–with-lz4 支持 LZ4 压缩构建。使用 LZ4 压缩表数据。

–with-systemd 编译对systemd 服务通知的支持。如果服务器是在systemd 机制下被启动,这可以提高集成度,否则不会有影响。要使用这个选项,必须安装libsystemd 以及相关的头文件。

–with-libxml 使用 libxml2 构建,启用 SQL/XML 支持。此功能需要 Libxml2 版本 2.6.23 或更高版本。

–enable-debug 把所有程序和库以带有调试符号的方式编译。这意味着你可以通过一个调试器运行程序来分析问题。这样做显著增大了最后安装的可执行文件的大小,并且在非 GCC 的编译器上,这么做通常还要关闭编译器优化, 这些都导致速度的下降。但是,如果有这些符号的话,就可以非常有效地帮助定位可能发生问题的位置。目前,我们只是在你使用 GCC 的情况下才建议在生产安装中使用这个选项。

–with-tcl 制作PL/Tcl服务器编程语言。

–with-perl 制作PL/Perl服务器端编程语言。

–with-gssapi 构建支持 GSSAPI 身份验证。在许多系统上,GSSAPI 系统(通常是 Kerberos 安装的一部分) 并未安装在默认搜索的位置(例如,/usr/include、 /usr/lib),因此除此选项外,您还必须使用选项 --with-includes和–with-libraries。configure将检查所需的头文件和库,以确保您的 GSSAPI 安装足够,然后再继续。

–with-pam 使用PAM(可插拔身份验证模块)支持构建。

–with-openssl 相当于以前的 --with-ssl=openssl.

–with-ldap 为认证和连接参数查找编译LDAP支持

–with-libxml 使用 libxml2 构建,启用 SQL/XML 支持。此功能需要 Libxml2 版本 2.6.23 或更高版本。

–with-libxslt 使用 libxslt 构建,使xml2模块能够执行 XML 的 XSL 转换。--with-libxml也必须指定。

MAKE && MAKE INSTALL,居然报错了,还是需要ICU (医院的急救病房)

/home/shark/source/postgresql-17.1/src/backend/commands/collationcmds.c:990:对‘uloc_countAvailable_50’未定义的引用
/home/shark/source/postgresql-17.1/src/backend/commands/collationcmds.c:1000:对‘uloc_getAvailable_50’未定义的引用
commands/collationcmds.o:在函数‘get_icu_locale_comment’中:
/home/shark/source/postgresql-17.1/src/backend/commands/collationcmds.c:659:对‘uloc_getDisplayName_50’未定义的引用

只能回到原路去:解决这个本地化的问题.

​​​​​​​[shark@sharkdb=>pg_data]$initdb -D $PGDATA -E UTF8 --locale=zh_CN.utf8 
The files belonging to this database system will be owned by user "shark".
This user must also own the server process. initdb: error: locale name "zh_CN.utf8 " contains non-ASCII characters

其中源码这样子的:

  /* Don't let Windows' non-ASCII locale names out. */
  if (canonname && !pg_is_ascii(*canonname))
    pg_fatal("locale name \"%s\" contains non-ASCII characters",
         *canonname);
}

不理解是啥意思,没精力搞 先换成英语的看看

[shark@sharkdb=>pg_data]$initdb -D $PGDATA -E UTF8  --locale=en_US.utf8
The files belonging to this database system will be owned by user "shark".
This user must also own the server process.

The database cluster will be initialized with locale "en_US.utf8".
The default text search configuration will be set to "english".

Data page checksums are disabled.

fixing permissions on existing directory /Program/pg17/pg_data ... ok
creating subdirectories ... ok
selecting dynamic shared memory implementation ... posix
selecting default "max_connections" ... 100
selecting default "shared_buffers" ... 128MB
selecting default time zone ... PRC
creating configuration files ... ok
running bootstrap script ... ok
performing post-bootstrap initialization ... ok
syncing data to disk ... ok

initdb: warning: enabling "trust" authentication for local connections
initdb: hint: You can change this by editing pg_hba.conf or using the option -A, or --auth-local and --auth-host, the next time you run initdb.

Success. You can now start the database server using:

    pg_ctl -D /Program/pg17/pg_data -l logfile start

居然成了! 看样子ICU对中文支持的不好!..

[shark@sharkdb=>pg_data]$start_pg
[shark@sharkdb=>pg_data]$ps -ef |grep postgre
shark     52104      1  0 17:02 ?        00:00:00 /Program/pg17/pg_soft/bin/postgres -D /Program/pg17/pg_data
shark     52105  52104  0 17:02 ?        00:00:00 postgres: checkpointer 
shark     52106  52104  0 17:02 ?        00:00:00 postgres: background writer 
shark     52108  52104  0 17:02 ?        00:00:00 postgres: walwriter 
shark     52109  52104  0 17:02 ?        00:00:00 postgres: autovacuum launcher 
shark     52110  52104  0 17:02 ?        00:00:00 postgres: logical replication launcher

然后依瓢画葫芦 进入临时数据库,创建用户,创建测试数据库表和数据,乃至权限

psql -d template1
create user shark with password '123456';

实际过程:

[shark@sharkdb=>pg_data]$psql -d template1
psql (17.1)
Type "help" for help.

SHARKSQL> create user shark with password '123456';
CREATE ROLE
Time: 17.533 ms

SHARKSQL> create database TESTDB owner shark;
CREATE DATABASE
Time: 36.838 ms

SHARKSQL> grant all on database TESTDB to shark;
GRANT
Time: 1.400 ms

SHARKSQL> \c testdb
You are now connected to database "testdb" as user "shark".

SHARKSQL> create table Mytest(id integer primary key,name varchar(30));
CREATE TABLE
Time: 10.975 ms

SHARKSQL> insert into mytest (id,name) values(1,'Jack');
INSERT 0 1
Time: 2.627 ms

SHARKSQL> insert into mytest (id,name) values(2,'Tonny');
INSERT 0 1
Time: 1.226 ms
SHARKSQL> insert into mytest (id,name) values(3,'Acebaby');
INSERT 0 1
Time: 1.544 ms

SHARKSQL> select * from mytest;
 id |  name   
----+---------
  1 | Jack
  2 | Tonny
  3 | Acebaby
(3 rows)

Time: 1.035 ms

说实话PG客户端PSQL格式真不好看! 对了上面我稍微该了下,比如说SHARKSQL> 和默认开启TIME,下个命令和前面的结果人工空行,
我喜欢MYSQL用框框把数据框起来.

如果要改写并调试的话,做成个SHELL脚本

make clean
./configure --prefix=/Program/pg17/pg_soft --enable-dtrace --with-openssl \ 
--enable-debug CFLAGS="-g3 -O0"
make -j4
make install

另外 其实每个目录下都有MAKEFILE编译文件,然后执行一些MAKE命令就行

make clean
make -j4
make install
make dist

GDB 看下调试信息:

[shark@sharkdb=>psql]$start_pg
[shark@sharkdb=>psql]$ps -ef |grep post
root       2438      1  0 11月18 ?      00:00:00 /usr/libexec/postfix/master -w
postfix    2447   2438  0 11月18 ?      00:00:00 qmgr -l -t unix -u
postfix   64443   2438  0 01:28 ?        00:00:00 pickup -l -t unix -u
shark    113553      1  0 02:17 ?        00:00:00 /Program/pg17/pg_soft/bin/postgres -D /Program/pg17/pg_data
shark    113554 113553  0 02:17 ?        00:00:00 postgres: checkpointer 
shark    113555 113553  0 02:17 ?        00:00:00 postgres: background writer 
shark    113557 113553  0 02:17 ?        00:00:00 postgres: walwriter 
shark    113558 113553  0 02:17 ?        00:00:00 postgres: autovacuum launcher 
shark    113559 113553  0 02:17 ?        00:00:00 postgres: logical replication launcher 
shark    113561 105562  0 02:17 pts/2    00:00:00 grep --color post
[shark@sharkdb=>psql]$ps -ef |grep pgsql
shark    113563  95541  0 02:17 pts/1    00:00:00 pgsql -d testdb
shark    113567 105562  0 02:18 pts/2    00:00:00 grep --color pgsql
[shark@sharkdb=>psql]$gdb -p 113563

好久没有用GDB了,GDB -P 到了父进程.老半天没有看到调试信息出来

(gdb) bt
#0  0x00007f74d487f740 in __read_nocancel () from /lib64/libpthread.so.0
#1  0x00007f74d4ab7137 in rl_getc () from /lib64/libreadline.so.6
#2  0x00007f74d4ab7987 in rl_read_key () from /lib64/libreadline.so.6
#3  0x00007f74d4aa29bf in readline_internal_char () from /lib64/libreadline.so.6
#4  0x00007f74d4aa30d5 in readline () from /lib64/libreadline.so.6
#5  0x0000000000422dae in gets_interactive (prompt=0x6b0ca0 <destination.7411> "SHARKSQL> ", query_buf=0xf1d460) at input.c:91
#6  0x000000000042406c in MainLoop (source=0x7f74d4361640 <_IO_2_1_stdin_>) at mainloop.c:166
#7  0x000000000042da5b in main (argc=3, argv=0x7fff9da46358) at startup.c:462

查看PGSQL客户端进程的堆栈信息,然后下面给MAIN打上断点看看

(gdb) list
121   *
122   * main
123   *
124   */
125  int
126  main(int argc, char *argv[])
127  {
128    struct adhoc_opts options;
129    int      successResult;
130    char     *password = NULL;
(gdb) b 126
Breakpoint 1 at 0x42cf67: file startup.c, line 126.

整洁架构:软件架构中那些永恒不变的规则

MYSQL死锁真实案例

MYSQL高并发下真实死锁之2

是否有必要考PG认证?

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值