1、下载安装包
https://www.postgresql.org/ftp/source/
2、解压安装包
cd /home/soft/
tar -zxvf postgresql-11.2.tar.gz
3、安装依赖包
yum install -y perl-ExtUtils-Embed readline-devel zlib-devel pam-devel libxml2-devel libxslt-devel openldap-devel python-devel gcc-c++ openssl-devel cmake
4、编译安装
cd /home/soft/postgresql-11.2
./configure --prefix=/usr/local/postgres --with-wal-segsize=512 --with-wal-blocksize=16 --with-pgport=5432 --with-segsize=1 --with-blocksize=8 --with-libedit-preferred --with-perl --with-openssl --with-libxml --with-libxslt --enable-thread-safety --enable-nls=en_US.UTF-8
make && make install
5、设置环境变量
编辑环境变量/etc/profile
export PG_HOME=/usr/local/postgres
export PATH=$PG_HOME/bin:$PATH
LD_LIBRARY_PATH=/usr/local/postgres/lib
export LD_LIBRARY_PATH
source /etc/profile
6、创建运行用户
设置运行用户
groupadd postgres
useradd -g postgres postgres
passwd postgres
7、初始化数据库
初始化数据库
mkdir -p /home/pgsql/data
chown -R postgres:postgres /home/pgsql/
su - postgres
pg_ctl -D /home/pgsql/data initdb
8、启动数据库
pg_ctl start -D /home/pgsql/data -l serverlog