1.下载源码包
wget https://ftp.postgresql.org/pub/source/v9.5.6/postgresql-9.5.6.tar.gz --no-check-certificate
2.解压源码包
tar -xzvf postgresql-9.5.6.tar.gz
3.安装编译需要的依赖
yum install perl-ExtUtils-Embed -y
yum install -y gcc
yum install -y libicu-devel.x86_64
yum install -y readline-devel.x86_64
yum -y install openssl-devel
yum -y install pam-devel.x86_64
yum install -y libxml2-devel.x86_64
yum install -y libxslt.x86_64
yum install -y libxslt-devel.x86_64
yum install -y openldap-devel.x86_64
yum install -y systemd-devel.x86_64
yum install -y tcl-devel.x86_64
yum install -y python-devel.x86_64(如果没有这个包,就下载yum install -y python36-devel.x86_64)
5.配置目录
./configure --prefix=/pgsql_data/pgsql --exec-prefix=/pgsql_data/pgsql --bindir=/pgsql_data/pgsql/bin --sysconfdir=/pgsql_data/pgsql/etc --libdir=/pgsql_data/pgsql/lib --includedir=/pgsql_data/pgsql/include --mandir=/pgsql_data/pgsql/man --docdir=/pgsql_data/pgsql/doc --htmldir=/pgsql_data/pgsql/html --enable-nls='zh_CN en_US' --with-pgport=5432 --with-perl --with-python --with-tcl --with-openssl --with-pam --with-ldap --with-readline --with-libxml --with-libxslt --with-segsize=1 --with-blocksize=8 --with-wal-segsize=16 --with-wal-blocksize=8 --without-zlib
#如果失败了,就把--with-python改为--with-python3
6.编译安装
make && make install
结果如下图所示表示编译安装成功
7.创建postgres用户
#ruishi123这是postgres用户的密码
useradd postgres
passwd postgres
mkdir -p /home/pg/data
chown -R postgres:postgres /home/pg/
8.初始化数据库
su postgres
/home/pg/bin/pg_ctl -D /home/pg/data initdb
9.配置环境变量
vim ~/.bashrc
#.bashrc
#Source global definitions
if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi
#User specific environment
if ! [[ "$PATH" =~ "$HOME/.local/bin:$HOME/bin:" ]]
then
PATH="$HOME/.local/bin:$HOME/bin:$PATH"
fi
export PATH
#Uncomment the following line if you don't like systemctl's auto-paging feature:
#export SYSTEMD_PAGER=
#User specific aliases and functions
PATH=$PATH:$HOME/.local/bin:$HOME/bin:/home/pg/bin
export PATH
export PGHOME=/home/pg
export PGDATA=/home/pg/data
export LD_LIBRARY_PATH=/home/pg/lib
export MANPATH=/home/pg/man
export PATH=/home/pg/bin:$PATH
10刷新环境变量
source ~/.bashrc
11.启动数据库并查看状态
/home/pg/bin/pg_ctl -D /home/pg/data -l logfile start
/home/pg/bin/pg_ctl -D /home/pg/data status
12.安装中遇到的两个错误
1.配置目录时报错error:conflicting types for copy_file_range
解决(找到编译的目录):
sed -i "s/copy_file_range/copy_file_chunk/g" /data/postgresql-9.5.6/src/bin/pg_rewind/copy_fetch.c
2.编译安装时报错checking for Python.h... no
解决:
yum install python python-devel
13.参考文献
https://blog.csdn.net/weixin_30895723/article/details/126204115