一、postgresql-14.2-源码包下载链接
https://ftp.postgresql.org/pub/source/v14.2/postgresql-14.2.tar.gz
二、环境简介
名称 | 值 |
---|---|
cpu | Intel® Core™ i7-7700HQ CPU @ 2.80GHz |
操作系统 | Red Hat Enterprise Linux Server release 7.9 (Maipo) |
pg数据目录 | /opt/pg14-2 |
pg安装目录 | /opt/pg14-2/data |
三、安装
1、关闭 SELinux
编辑/etc/selinux/config,修改参数SELINUX=disabled。
2、创建用户和组
groupadd postgres -g 2000
useradd postgres -g 2000 -u 2000
echo "postgres"|passwd --stdin postgres
3、修改操作系统limits
编辑/etc/security/limits.conf添加如下参数:
postgres soft nofile 1048576
postgres hard nofile 1048576
postgres soft nproc 131072
postgres hard nproc 131072
postgres soft stack 10240
postgres hard stack 32768
postgres soft core 6291456
postgres hard core 6291456
4、编译安装
yum -y install readline readline-devel zlib zlib-devel gettext gettext-devel openssl openssl-devel pam pam-devel libxml2 libxml2-devel libxslt libxslt-devel perl perl-devel tcl-devel uuid-devel gcc gcc-c++ make flex bison perl-ExtUtils*
cd /opt/postgresql-14.2
./configure --prefix=/opt/pg14-2 --enable-debug --enable-dtrace
gmake world -j 4
gmake install-world
注: --enable-debug --enable-dtrace,不调试可以不加。
如果大家想调试PG代码,最好在configure之后,把src/Makefile.global中的编译优化去掉,再进行gmake或make,因为优化后可能和源码的位置对不上,不利于大家学习PG代码,不调试的小伙伴可以不加下面这步。
vim src/Makefile.global
我只是把原来的CXXFLAGS、CFLAGS内容注释了,具体如下:
#CFLAGS = -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Werror=vla -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard -g -O2
CFLAGS = -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Werror=vla -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard -g
#CXXFLAGS = -Wall -Wpointer-arith -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -g -O2
CXXFLAGS = -Wall -Wpointer-arith -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -g
5、修改用户组
chown -R postgres:postgres /opt/pg14-2
6、初始化库
su - postgres
cd /opt/pg14-2/bin
./initdb -D/opt/pg14-2/data -X/opt/pg14-2/pgwal
7、修改配置文件
(1)编辑pg_hba.conf,添加如下内容:
host all all 0.0.0.0/0 md5
(2)编辑postgresql.conf,修改如下参数:
listen_addresses = '*'
8、启动数据库
su - postgres
cd /opt/pg14-2/bin
./pg_ctl -D /opt/pg14-2/data -l /opt/pg14-2/data/logfile restart
9、psql连接数据库
su - postgres
cd /opt/pg14-2/bin
./psql
select version();
10、数据库环境变量
编辑/home/postgres/.bashrc,添加如下内容:
export PGPORT=5432
export PGUSER=postgres
export PGDATABASE=postgres
export PGHOME=/opt/pg14-2
export PGDATA=/opt/pg14-2/data
export PATH=$PGHOME/bin:$PATH
11、配置数据库自启
cp /opt/postgresql-14.2/contrib/start-scripts/linux /etc/init.d/pg14-2
vim /etc/init.d/pg14-2
修改如下内容:
chmod 755 /etc/init.d/pg14-2
chkconfig --add pg14-2
chkconfig --list