风故故,也依依

Stand still in the wind.

导航

Windows环境zip版PostgreSQL数据库安装

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  阅读(3363)  评论(0编辑  收藏  举报