PostgreSQL简单安装
1. 系统软件更新(根据具体需要更新)**
yum -y install lrzsz sysstat e4fsprogs ntp readline-devel zlib zlib-devel openssl openssl-devel pam-devel libxml2-devel libxslt-devel python-devel tcl-devel gcc make flex bison perl perl-devel perl-ExtUtils* OpenIPMI-tools systemtap-sdt-devel smartmontools
2. 下载源码包编译安装
cd /opt/soft
wget https://ftp.postgresql.org/pub/source/v9.5.1/postgresql-9.6.2.tar.gz
3. 编译安装
tar -zxvf postgresql-9.6.2.tar.gz
cd /opt/soft/postgresql-9.6.2
./configure --prefix=/usr/local/pgsql --with-pgport=5432 --with-perl --with-tcl --with-python --with-openssl --with-pam --without-ldap --with-libxml --with-libxslt --with-wal-blocksize=8 --with-blocksize=8 --enable-dtrace --enable-debug
make && make install
>如果需要调试则按照以下方式编译
CFLAGS="-g -ggdb -fno-omit-frame-pointer" ./configure --prefix=/usr/local/pgsql --with-pgport=5432 -enable-debug
CFLAGS="-g -ggdb -fno-omit-frame-pointer" make
CFLAGS="-g -ggdb -fno-omit-frame-pointer" make install
安装contrib目录下的一些工具,是第三方组织的一些工具代码,建议安装
cd /opt/soft/postgresql-9.6.2/contrib/
make && make install
4. 创建用户和组
groupadd postgres
useradd -g postgres postgres
5.创建数据库数据目录和审计日志目录
mkdir -p /home/postgres/pgdata
mkdir -p /home/postgres/pg_log
chown postgres:postgres /home/postgres/*
chown postgres:postgres /usr/local/pgsql/*
chmod -R 775 /home/postgres/*
*注意数据库data目录权限需是0700*
6.设置环境变量
vi /home/postgres/.bash_profile
export PGHOME=/usr/local/pgsql
export PGPORT=5432
export PGDATA=/home/postgres/pgdata
export DATE=`date +"%Y%m%d%H%M"`
export PGUSER=postgres
export PGHOST=localhost
export PGDATABASE=postgres
export PATH=$PGHOME/bin:$PATH:.
export MANPATH=$PGHOME/share/man:$MANPATH
export LD_LIBRARY_PATH=$PGHOME/lib:$LD_LIBRARY_PATH
export LANG=en_US.utf8
export PG_OOM_ADJUST_FILE=/proc/self/oom_score_adj
export PG_OOM_ADJUST_VALUE=0
7.初始化数据库
su - postgres
initdb -D /home/postgres/pgdata -E UTF8 --locale=C -U postgres
8.启动数据库
pg_ctl -mf start