postgre 的安裝步驟
來源:互聯網
上載者:User
1 . 為 了安全考 慮 , Postgresql 不能以 root 用 戶 運行,所以必 須 建立 對應 的用 戶 和 組 。 # useradd postgre (自動建立 postgre 組,必須為root許可權) 2. 安裝的 過 程
解壓到 /usr/local/src:
# tar xvfz Postgresql 8.0.1.tar.gz
# cd Postgresql -8.0.1
# ./configure --prefix=/usr/local/pgsql
# make
# make install
# chown -R postgre.postgre /usr/local/pgsql 3. 用 vi ~postgre/.bash_profile 命令編輯檔案 添加 : PGLIB=/usr/local/pgsql/lib
PGDATA=$HOME/data
PATH=$PATH:/usr/local/pgsql/bin
MANPATH=$MANPATH:/usr/local/pgsql/man
export PGLIB PGDATA PATH MANPATH 4 . 以 postgres 用 戶 登 錄 ,
# su – postgre
建立資料 庫 目 錄 :
$ mkdir data 啟動資料庫引擎 $ initdb -E (EUC_JP,EUC_CN) 啟動資料庫 $ postmaster -i -D ~/data & 或者 pg_ctl start -l LOGFILE 5 . 使資料 庫 隨 開 機自運行
cp 解 壓 包中的 contrib/start-scripts/linux 到 /etc/init.d Postgresql
使用命令 chkconfig --add Postgresql 添加啟 動 6. 進入資料庫 $psql –U postgre –d postgres 7. 創 建 別 的用 戶 , 賦 於他 創 建資料 庫 的 權 限
CREATE USER testuser CREATEDB; (如果是 createuser , 則為 超 級 用 戶權 限 )
8. 為 普通用 戶創 建資料 庫 ,也可由普通用 戶 登入模板資料 庫 自行 創 建
CREATE DATABASE testdb OWNER testuser; 9. 到目前為止資料庫已經可以使用了,但是僅限本機串連要想網路中的機器也能訪問資料庫必須要配置/home/postgresql/data/下的兩個檔案pg_hba.conf和postgresql.conf ① vi pg_hba.conf 添加: host all all 192.168.100.0/24 trust ② vi postgresql.conf 添加: listen_addresses = ‘*’ port = 5432 max_connections = 100 儲存後需要重啟資料庫 pg_ctl re start 10. 監控資料庫服務進程 ps auxww | grep postgres