1. 程式人生 > >windows下PostgreSQL 安裝與配置

windows下PostgreSQL 安裝與配置

this 開始 ror scripting ping 存儲 install driver 選擇

下載地址

https://www.postgresql.org/download/

Download the installer certified by EnterpriseDB for all supported PostgreSQL versions.

This installer includes the PostgreSQL server, pgAdmin; a graphical tool for managing and developing your databases, and StackBuilder; a package manager that can be used to download and install additional PostgreSQL tools and drivers. Stackbuilder includes management, integration, migration, replication, geospatial, connectors and other tools.

可以下載整合的安裝包:包含PostgreSQL server,pgAdmin一個圖形界面客戶端,StackBuilder 負責管理集成遷移復制等工作。

PostgreSQL的文檔並不友好,我只找到了linux類系統的文檔。後來就開始自己踩坑。

文件是exe的,如果沒有directx或者Microsoft Visual C++ 2013 Redistributable (x64) …之類的東東它會自動幫助安裝,所以不用擔心。(選擇PostgreSQL的原因之一是mysql的免安裝包不提供此類支持,手動沒解決,其它的好處還沒接觸到)

設置環境變量

新建一個文件,擴展名為vbs,內容如下,雙擊執行。

on error resume next set sysenv=CreateObject("WScript.Shell").Environment("system") ‘系統環境變量的數組對象 Path = CreateObject("Scripting.FileSystemObject").GetFolder(".").Path ‘添加變量 sysenv("PGHOME")="D:\pgsql" sysenv("PGHOST")="localhost" sysenv("Path")=sysenv("PGHOME")+"\bin;"+sysenv("Path") sysenv("PGLIB")=sysenv("PGHOME")+"\lib" sysenv("PGDATA")=sysenv("PGHOME")+"\data" wscript.echo "PostgreSQL環境變量安裝成功!不需要重新啟動計算機啊!"

初始化數據庫

在命令行執行,最好右鍵選擇管理員權限(下邊還會用到)。

initdb.exe -D d:\pgsql\data -E UTF-8 --locale=chs -U postgres -W

-D :指定數據庫簇的存儲目錄E:\pgsql\data

-E :默認編碼格式UTF8

--locale:關於區域設置(chinese-simplified-china)

-U :指定DB的超級用戶的用戶名postgres

-W :為超級用戶指定密碼的提示

安裝windows服務

pg_ctl register -N PostgreSQL -D D:\pgsql\data(一定要管理員權限才可以)

windows下PostgreSQL 安裝與配置