创建用户

useradd postgres
passwd postgres

安装依赖包

yum groupinstall -y "Development Tools" "Legacy UNIX Compatibility"
yum install -y bios flex readline* zlib-devel gcc gcc-c++ gmake

创建目录并授权

mkdir -p /usr/local/pg14
mkdir -p /pgdata/14/data
chown -R postgres.postgres /pgdata
chown -R postgres.postgres /usr/local/pg14
chmod 700 /pgdata/14/data -R

系统参数优化

vim /etc/sysctl.conf

kernel.shmmax = 68719476736
kernel.shmall = 4294967296
kernel.shmmni = 4096
kernel.sem = 50100 64128000 50100 1280
fs.file-max = 7672460
fs.nr_open = 7672460
net.core.rmem_default = 1048576
net.core.wmem_default = 262144
net.core.wmem_max = 1048576

sysctl -p

vim /etc/security/limits.conf

* soft nofile 3301072
* hard nofile 3301072
* soft nppro 3301072
* hard nproc 3301072
* soft core unlimited
* hard core unlimited
* soft memlock 50000000
* hard memlock 50000000

源码安装

tar -zxvf postgresql-14.3.tar.gz
cd postgresql-14.3
./configure --prefix=/usr/local/pg14 --with-pgport=13365
gmake world
gmake install-world

设置环境变量

su - postgres
vim .bash_profile

export PGDATA=/pgdata/14/data
export LANG=en_US.utf8
export PGHOME=/usr/local/pg14
export LD_LIBRARY_PATH=$PGHOME/lib:/lib64:/usr/lib64:/usr/local/lib64:/lib:/usr/lib:/usr/local/lib:$LD_LIBRARY_PATH
export DATE=`date +"%Y%m%d%H%M"`
export PATH=$PGHOME/bin:$PATH:.
export MANPATH=$PGHOME/share/man:$MANPATH
export PGUSER=postgres

source .bash_profile

初始化数据

su - postgres
#简易初始化
initdb -D /pgdata/14/data -W
#生产初始化
initdb -A md5 -D /pgdata/14/data  --locale=C -W 

启动

pg_ctl -D /pgsql/14/data -l logfile start

停止

pg_ctl -D /pgsql/14/data stop