centos環境源碼安裝postgresql9.4
源碼安裝簡要步驟
- 下載PostgreSQL 源碼包
下載根目錄地址:http://ftp.postgresql.org/
本人選擇的是當前最新版本v9.4.1:http://ftp.postgresql.org/pub/source/v9.4.1/
本人下載的源碼壓縮包地址如下:
$ /usr/local/postgresql
$ tar -zxvf postgresql-9.4.1.tar.gz
$ cd postgresql-9.4.1
$ ./configure
$ gmake
- 執行gmake install
$ gmake install
- 設定環境變數
$ vi .bash_profile#### 把 PATH=$PATH:$HOME/bin 改成下面內容 ####$ PATH=$PATH:$HOME/bin:/usr/local/pgsql/bin
$ source .bash_profile
$ adduser postgres
- 更改使用者目錄(可選操作)
$ vi /etc/passwd#### 把 postgres:x:528:528::/home/postgres:/bin/bash 改成下面內容 ####$ postgres:x:528:528::/usr/local/pgsql:/bin/bash#### 將.bash_profile 移動到新的使用者目錄並修改許可權 ####$ cp /home/postgres/.bash_profile /usr/local/pgsql/$ chown postgres.postgres .bash_profile#### 刪除使用者目錄 ####$ rm -rf postgres/
$ mkdir /usr/local/pgsql/data
$ chown postgres /usr/local/pgsql/data
$ su - postgres
- 初始化資料庫
$ /usr/local/pgsql/bin/initdb -D /usr/local/pgsql/data/
- 回到root 使用者
$ exit
- 複製安裝目錄下的linux檔案到/etc/init.d/
$ cd postgresql-9.4.1$ cp contrib/start-scripts/linux /etc/init.d/postgresql
- 添加執行許可權
$ chmod +x /etc/init.d/postgresql
$ service postgresql restart
- 讓資料庫開機啟動
$ chkconfig --add postgresql $ chkconfig postgresql on
$ su - postgres$ createdb test$ psql testtest=$ create table test(id int);
源碼安裝相關問題及解決方案
- ./configure時,提示error: readline library not found 該情況,一般是未安裝readline-devel,雖然提示中有建議使用 –without readline,但是裝下又何妨,萬一後面出點亂子,找個問題都難找,還是裝一下吧。
yum install readline-devel
- 直接執行gmake install,預設安裝在哪?
$ /usr/local/pgsql
- 執行postgresql命令、修改postgresql設定檔(postgresql.conf、pg_hba.conf),檔案和目錄在哪?
$ /usr/local/pgsql/data
- postgresql預設只允許本機訪問,需要遠端連線、外網訪問,如何配置? 先配置監聽地址
$ vi /usr/local/pgsql/data/postgresql.conf#### 取消掉下面一行的前面的#注釋,並將值改為* ####$ listen_addresses = '*'
再配置支援遠端連線
$ vi /usr/local/pgsql/data/pg_hba.conf#### 直接配置為不限制IP,即0.0.0.0,注意:/後面也必須為0!!! ####$ 將 127.0.0.1/8 改為 0.0.0.0/0