#wget下载postgresql-11.4.tar.gz
wget https://ftp.postgresql.org/pub/source/v11.4/postgresql-11.4.tar.gz
#解压postgresql-11.4.tar.gz
tar -zxf postgresql-11.4.tar.gz
#安装依赖包
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
#编译安装 PostgreSQL
cd postgresql-11.4
./configure
make && sudo make install
#创建postgres 用户
adduser postgres
#cd到/usr/local/pgsql目录下
cd /usr/local/pgsql
mkdir data
#给postgres用户赋予权限
chown postgres /usr/local/pgsql/data
su postgres
/usr/local/pgsql/bin/initdb -D /usr/local/pgsql/data
su
/usr/local/pgsql/bin/postgres -D /usr/local/pgsql/data >logfile 2>&1 &
su postgres
./pg_ctl start -D /usr/local/pgsql/data
cd /usr/local/pgsql/bin
su
#给pg_ctl 创建软链接
ln -s /usr/local/pgsql/bin/pg_ctl /usr/bin/pg_ctl
#访问数据库
su postgres
./psql
\l
#修改配置使能远程访问
vi /usr/local/pgsql/data/pg_hba.conf
#添加如下内容
host all all 0.0.0.0/0 md5
#修改配置使能远程访问
vi /usr/local/pgsql/data/postgresql.conf
#将注释去掉,修改如下图
#重启数据库,得在postgres用户下,如 su postgres
pg_ctl restart -D /usr/local/pgsql/data
(完)