1. 程式人生 > >原始碼安裝postgresql資料庫

原始碼安裝postgresql資料庫

一般情況下,postgresql由非root使用者啟動。

1、建立postgres使用者

groupadd postgres

useradd -g postgres postgres

下面的操作都在postgres使用者下完成

su postgres

2、解壓原始碼包

tar -xvzf postgres-9.4.tar.gz

cd postgres-9.4

3、配置

./configure --prefix=/usr/local/postgres --enable-debug

(開啟debug選項,用於除錯)

4、編譯安裝

make & make install

(pg安裝需要flex和bison,apt-get或yum自行安裝即可)

5、新增環境變數

export PATH=$PATH:/usr/local/postgresql/bin

6、建立postgresql資料庫目錄

mkdir -p /var/postgresql/data

chown postgres:postgres /var/postgres/*

chown postgres:postgres /usr/local/postgresql/*

chmod -R 775 /var/postgresql/*

7、初始化資料庫

initdb -D /var/postgresql/data

8、啟動資料庫服務

pg_ctl -D /var/postgresql/data -l /var/postgresql/logfile start

 

連入資料庫

 

檢視資料庫狀態

 

 

備註:部分配置項需要修改pg_hba.conf配置檔案

 ls -l /var/postgrresql/data/