windows下PostgreSQL 安装与配置

下载地址

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")+"in;"+sysenv("Path") sysenv("PGLIB")=sysenv("PGHOME")+"lib" sysenv("PGDATA")=sysenv("PGHOME")+"data" wscript.echo "PostgreSQL环境变量安装成功!不需要重新启动计算机啊!"

 

初始化数据库

在命令行执行,最好右键选择管理员权限(下边还会用到)。

 

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

-D :指定数据库簇的存储目录E:pgsqldata

-E :默认编码格式UTF8

--locale:关于区域设置(chinese-simplified-china)

-U :指定DB的超级用户的用户名postgres

-W :为超级用户指定密码的提示

 

安装windows服务

pg_ctl register -N PostgreSQL -D D:pgsqldata(一定要管理员权限才可以)

原文地址:https://www.cnblogs.com/bityinjd/p/8503325.html