- 安装gcc、readline-devel、zlib-devel
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