1. 程式人生 > >CentOS 7安裝指定版本的資料庫postgresql

CentOS 7安裝指定版本的資料庫postgresql

安裝指定版本的資料庫postgresql(centos7.4)

網上搜索Linux安裝postgresql有很多教程,主要是下載rpm包線上安裝:

yum install https://download.postgresql.org/pub/repos/yum/10/redhat/rhel-7-x86_64/pgdg-centos10-10-2.noarch.rpm

但是使用此方法安裝資料庫現在最新版已是postgresql10.4的版本,而環境需要指定安裝10.3的版本,因此可選擇解壓版安裝。

首先下載壓縮包:https://www.postgresql.org/ftp/source/v10.3/,選擇 

postgresql-10.3.tar.gz下載

上傳到/usr/data/postgresql10.3/ ,解壓

tar -zxvf postgresql-10.3.tar.gz

進入postgresql10.3目錄輸入命令檢查環境

 ./configure

如果出現以下錯誤

configure: error: in `/root/postgresql-10.3':
configure: error: no acceptable C compiler found in $PATH

See `config.log' for more details

缺少編譯環境,執行命令,安裝對應的包

yum –y install gcc

成功之後再次輸入

 ./configure

又報錯

configure: error: readline library not found
If you have readline already installed, see config.log for details on the
failure.  It is possible the compiler isn't looking in the proper directory.

Use --without-readline to disable readline support.

安裝readline support

yum -y install -y readline-devel

成功之後再次輸入

 ./configure

再次報錯

configure: error: zlib library not found
If you have zlib already installed, see config.log for details on the
failure.  It is possible the compiler isn't looking in the proper directory.

Use --without-zlib to disable zlib support.

安裝zlib-devel

yum -y install zlib-devel

終於不再報錯,總之缺少什麼就安裝什麼

執行編譯

make && make install

需要大概10分鐘,出現如下資訊則編譯成功

以上內容參考:https://blog.csdn.net/qq_35267557/article/details/79788703

接下來新增使用者

建立一個data資料夾用於儲存資料

mkdir /usr/local/pgsql/data
chown postgres /usr/local/pgsql/data  
chmod 700 /usr/local/pgsql/data

切換使用者為postgresql並初始化資料庫

su postgres
/usr/local/pgsql/bin/initdb -D /usr/local/pgsql/data

到bin目錄下

cd /usr/local/pgsql/bin/

啟動資料庫

su postgres
./pg_ctl start  -D /usr/local/pgsql/data/

檢視下狀態

./pg_ctl status  -D /usr/local/pgsql/data/

接下來修改下配置檔案,便於遠端連線

cd /usr/local/pgsql/data/
vim pg_hba.conf

vim postgresql.conf

重啟資料庫

su postgres
./pg_ctl restart  -D /usr/local/pgsql/data/

即可遠端連線啦!