yum install -y gcc readline-devel zlib-devel
./configure --prefix=/usr/local/pgsql
make -j 4 && make install
useradd pgsql
vim /home/pgsql/.bash_profile
# add
export PGPORT=1999
export PGDATA=/home/pgsql/pg_data
export LANG=en_US.utf8
export PGHOME=/usr/local/pgsql/
export LD_LIBRARY_PATH=$PGHOME/lib:/lib:/lib64:usr/lib:/usr/lib64:/usr/local/lib:/usr/local/lib64:$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
export PGHOST=$PGDATA
export PGDATABASE=postgres
su - pgsql
initdb -D $PGDATA -E UTF8 --locale=C -U postgres -W
[root@localhost ~]# vim /etc/sysctl.conf
# add
kernel.shmmni = 4096
kernel.sem = 50100 64128000 50100 1280
fs.file-max = 7672460
net.ipv4.ip_local_port_range = 9000 65000
net.core.rmem_default = 1048576
net.core.rmem_max = 4194304
net.core.wmem_default = 262144
net.core.wmem_max = 1048576
[root@localhost ~]# sysctl -p
vim /etc/security/limits.conf
* soft nofile 131072
* hard nofile 131072
* soft nproc 131072
* hard nproc 131072
* soft core unlimited
* hard core unlimited
* soft memlock 50000000
* hard memlock 50000000
pg_hba.conf
vim $PGDATA/pg_hba.conf
# add
host all all 0.0.0.0/0 md5
//第一个all表示允许访问的数据库实例
//第二个all表示允许连接的用户
//地址段为允许的访问的地址
//md5为验证方法
# TYPE DATABASE USER ADDRESS METHOD
host test pgtest 10.10.56.17/32 md5
即表示允许地址为 10.10.56.17 的用户 pgtest通过 MD5方式 加密的密码方式连接主机上的 test 数据库
postgresql.conf
vim $PGDATA/postgresql.conf
listen_addresses = ‘*‘
# 启动
pg_ctl start -D $PGDATA
# 停止
pg_ctl stop -m fast|smart|immediate -D $PGDATA
psql -h 127.0.0.1 -p 1999 -U postgres postgres
原文:https://www.cnblogs.com/ly447742/p/14584963.html