源碼安裝
tar zxvf postgresql-10.0.tar.gz
mv postgresql-10.0 /usr/local/pgsql
cd /usr/local/pgsql/
root使用者下安裝依賴包
yum -y install gcc gcc-c++ automake autoconf libtool make readline-devel zlib-devel readline
安裝資料庫
./configure --prefix=/usr/local/pgsql --without-readline
make
make install
添加使用者,設定目錄權限
adduser postgres
passwd postgres
chown -R postgres:root /usr/local/pgsql
添加啟動服務(确認檔案postgresql内的目錄正确)
cp /usr/local/pgsql/contrib/start-scripts/linux /etc/init.d/postgresql
chmod u+x /etc/init.d/postgresql
添加開啟自啟動
chkconfig --add postgresql
切換使用者,初始化資料并建立測試庫(确認data目錄下為空)
su - postgres
/usr/local/pgsql/bin/initdb -D /usr/local/pgsql/data
設定環境變量
> su - postgres
> vim ~/.bash_profile
export PATH=$PATH:/usr/local/pgsql/bin
export PGDATA=/usr/local/pgsql/data
> source ~/.bash_profile
> vim ~/.bashrc
export PGDATA=/usr/local/pgsql/data
> source ~/.bash_profile
啟動服務
service postgresql start
啟動資料庫
/usr/local/pgsql/bin/pg_ctl -D /usr/local/pgsql/data -l logfile start
建立和連接配接資料庫
createdb test
psql test
允許所有連接配接
> vim /usr/local/pgsql/data/pg_hba.conf
host all all 0.0.0.0/0 trust
偵聽所有連接配接
> vim /usr/local/pgsql/data/postgresql.conf
listen_addresses = '*'
logging_collector = on
關閉防火牆
啟動: systemctl start firewalld
關閉: systemctl stop firewalld
檢視狀态: systemctl status firewalld
開機禁用 : systemctl disable firewalld
開機啟用 : systemctl enable firewalld