一、下載解壓
1,下載postgresql-9.4.0-1-windows-x64-binaries.zip
2,解壓postgresql-9.4.0-1-windows-x64-binaries.zip 到E:\
二、添加用戶
1,添加windows用戶,用於啓動PostgreSQL的windows服務
net user postgres pgsqlpw /add /expires:never /passwordchg:no
2,爲保證安全,此用戶不允許本地登錄
net localgroup users postgres /del
3,賦於windows用戶postgres訪問PostgreSQL安裝目錄的權限
cacls . /T /E /P postgres:R
4、配置環境變量:
三、初始化數據庫
1、配置環境變量:
PG_HOME = E:\postgresql-9.4.0-1-windows-x64
PGDATA = %PG_HOME%\data
PGHOST = localhost
PGLIB = %PG_HOME%\lib
Path = %path%; %PG_HOME%\bin;
2,切換到windows用戶postgres的命令行環境
runas /noprofile /env /user:postgres cmd
注: 用管理員賬號,把postgres 賬號初始化,改下密碼就可以了。
3,初始化數據庫,若不使用-U admin,則數據庫裏自動添加當前windows用戶(即postgres)爲數據庫帳號
initdb.exe -D E:\postgresql-9.4.0-1-windows-x64\data -E UTF-8 --locale=chs
4,啓動數據庫
pg_ctl.exe -D E:\postgresql-9.4.0-1-windows-x64\data -l logfile start
5,停止數據庫
pg_ctl.exe -D E:\postgresql-9.4.0-1-windows-x64\data stop
四、註冊爲Windows服務
1,註冊爲windows服務,當前windows用戶(即postgres)將作爲PostgreSQL服務的登錄用戶
pg_ctl.exe register -D E:\postgresql-9.4.0-1-windows-x64\data -NPostgreSQL
2,啓動PostgreSQL服務
net start PostgreSQL
五、連接測試
psql -Upostgres -W