01. 環(huán)境描述
centos6.5:https://www.centos.org/download/
postgresql9.5.4:https://www.postgresql.org/ftp/source/v9.5.4/
02. 安裝基礎(chǔ)軟件
基礎(chǔ)軟件在reference手冊(cè)分為必選和可選兩部分,主要是gcc編譯器和相關(guān)的庫(kù)。
yum install -y gcc
yum install -y glibc
yum install -y glibc-devel
yum install -y readline-devel
yum install -y zlib-devel
03. 創(chuàng)建用戶(hù)和目錄
創(chuàng)建用戶(hù)和組
groupadd postgres
useradd -g postgres -s /bin/bash -d /home/postgres -m postgres
創(chuàng)建軟件介質(zhì)目錄
mkdir -p /opt/postgresql/9.5.4
創(chuàng)建數(shù)據(jù)目錄
mkdir -p /pg/data/
mkdir -p /pg/archive/
mkdir -p /pg/backup/
配置權(quán)限
chown postgres.postgres -R /opt/postgresql/9.5.4
chown postgres.postgres -R /pg/
04. 編譯安裝軟件
解壓源碼
tar -zxvf postgresql-9.5.4.tar.gz
cd postgresql-9.5.4
編譯軟件
./configure --prefix=/opt/postgresql/9.5.4
make
make install
make check
make check命令在initdb時(shí)由于是在root用戶(hù)不能啟動(dòng)實(shí)例導(dǎo)致異常。
05. 配置用戶(hù)環(huán)境變量
vi ~/.bash_profile
PATH=$PATH:$HOME/bin:/opt/postgresql/9.5.4/bin
source ~/.bash_profile
06. 初始化并數(shù)據(jù)庫(kù)
initdb -d /pg/datapg_ctl -D /pg/data -l /pg/alert.log start
07. 配置數(shù)據(jù)庫(kù)
登陸數(shù)據(jù)庫(kù)并修改密碼
psql -U postgres
postgres-# \password
Enter new password:
Enter it again:
配置監(jiān)聽(tīng)遠(yuǎn)程訪問(wèn)數(shù)據(jù)庫(kù)時(shí)需要配置監(jiān)聽(tīng)
cd /pg/datavi postgresql.conf
#找到listen_addresses參數(shù),增加一行
listen_addresses = '*'
08. reference
postgresql 官方在線參考手冊(cè)
https://www.postgresql.org/docs/9.5/static/index.html