1. 下載PostgreSQL數據庫zip版本
2.? 解壓到D盤,例如:D:\database\postgresql
3.? cmd窗口進入D:\database\postgresq\bin,依次執行如下命令:
set PGHOME=D:\database\postgresq
set PGDATA=%PGHOME%\data
set PGLIB=%PGHOME%\lib
set PGHOST=localhost
set PATH=%PGHOME%\bin;%PATH%

4.? 添加用戶
> 添加windows用戶,用于啟動PostgreSQL的windows服務
D:\database\postgresql>net user postgres pgsqlpw /add /expires:never /passwordchg:no
> 為保證安全,此用戶不允許本地登錄
D:\database\postgresql>net localgroup users postgres /del
> 賦于windows用戶postgres訪問PostgreSQL安裝目錄的權限
D:\database\postgresql>cacls . /T /E /P postgres:R
5.? 初始化數據庫
> 切換到windows用戶postgres的命令行環境
D:\database\postgresql>runas /noprofile /env /user:postgres "cmd"
> 初始化數據庫,若不使用-U admin,則數據庫里自動添加當前windows用戶(即postgres)為數據庫帳號
D:\database\postgresql>bin\initdb -D "D:\database\postgresql\data" -E UTF-8? --locale=chs -A md5 -U admin -W

6. 啟動PostgreSQL服務:
pg_ctl -D?D:\database\postgresql\data -l? D:\database\postgresql\pglog.txt start



7. 創建并連接數據庫:
createdb test
psql -h localhost -w -d test

8. 關閉PostgreSQL服務:
pg_ctl -D? D:\database\postgresql\data stop
9. 注冊為Windows服務:
> 注冊為windows服務,當前windows用戶(即postgres)將作為PostgreSQL服務的登錄用戶
D:\pgsql>bin\pg_ctl register -N PostgreSQL? -D “D:\database\postgresql\data”
> 啟動PostgreSQL服務
D:\pgsql> sc start PostgreSQL
?
?
posted on 2011-08-11 20:46
jadmin 閱讀(232)
評論(0) 編輯 收藏