下載PostgreSQL 源碼包
#wget http://ftp.postgresql.org/pub/source/v9.5.0/postgresql-9.5.0.tar.bz2解壓源碼包
# tar xjf postgresql-9.5.0.tar.bz2進入解壓後的目錄
# cd postgresql-9.5.0查看INSTALL 文件
INSTALL 文件中Short Version 部分解釋瞭如何安裝PostgreSQL 的命令,Requirements 部分描述了安裝PostgreSQL 所依賴的lib,比較長,先configure 試一下,如果出現error,那麼需要檢查是否滿足了Requirements 的要求。
開始編譯安裝PostgreSQL 數據庫。
# ./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 isnt looking in the proper directory.
Use –without-readline to disable readline support.
解決:
#yum install *readline**再次configure:
# ./configure
configure 成功,無錯誤。
執行gmake
# gmake
gmake 成功,Ready to install.
執行gmake install
# gmake install
gmake install 成功
到這一步,PostgreSQL 源碼編譯安裝完成,下面開始配置PostgreSQL.設置環境變量
# vi .bash_profile
把 PATH=$PATH:$HOME/bin
改成 PATH=$PATH:$HOME/bin:/usr/local/pgsql/bin
保存退出。讓環境變量生效:
# source .bash_profile添加用戶postgres
# 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 /usr/local/pgsql/.bash_profile刪除用戶目錄:
# rm -rf postgres/初始化數據庫
14.1 新建數據目錄
# mkdir /usr/local/pgsql/data
14.2 更改權限
# chown postgres /usr/local/pgsql/data
14.3 切換到postgres 用戶
# su - postgres
14.4 init db
$ /usr/local/pgsql/bin/initdb -D /usr/local/pgsql/data/
到這裏數據的初始化就完成了。系統服務
15.1 回到root 用戶
$ exit
15.2 複製安裝目錄下的linux文件到/etc/init.d/
進入postgresql 的安裝目錄(即剛剛使用tar命令解壓的目錄)
# cd postgresql-9.2.4
# cp contrib/start-scripts/linux /etc/init.d/postgresql
15.3 添加執行權限
# chmod +x /etc/init.d/postgresql
15.4 啓動數據庫
#/etc/init.d/postgresql start
#ps -ef | grep postgres
15.5 讓數據庫開機啓動
# chkconfig –add postgresql
# chkconfig postgresql on
# chkconfig –list | grep postgres
15.6 創建數據庫操作的歷史記錄文件
# touch /usr/local/pgsql/.pgsql_history
#chown postgres:postgres /usr/local/pgsql/.pgsql_history測試使用
# su - postgres
$ createdb test
$ psql test
test=# create table test(id int);
test=# \dt
源碼編譯安裝成功。
參考文獻:
1、http://www.cnblogs.com/mchina/archive/2012/06/06/2539003.html
2、http://www.oschina.net/question/565065_66639