1. 下载PostgreSQL数据库zip版本

2.  解压到D盘,例如:D:databasepostgresql

3.  cmd窗口进入D:databasepostgresqbin,依次执行如下命令:
set PGHOME=D:databasepostgresq
set PGDATA=%PGHOME%data
set PGLIB=%PGHOME%lib
set PGHOST=localhost
set PATH=%PGHOME%bin;%PATH%

4.  添加用户

> 添加windows用户,用于启动PostgreSQL的windows服务

D:databasepostgresql>net user postgres pgsqlpw /add /expires:never /passwordchg:no

> 为保证安全,此用户不允许本地登录
D:databasepostgresql>net localgroup users postgres /del

> 赋于windows用户postgres访问PostgreSQL安装目录的权限
D:databasepostgresql>cacls . /T /E /P postgres:R

5.  初始化数据库

> 切换到windows用户postgres的命令行环境
D:databasepostgresql>runas /noprofile /env /user:postgres "cmd"

> 初始化数据库,若不使用-U admin,则数据库里自动添加当前windows用户(即postgres)为数据库帐号
D:databasepostgresql>bininitdb -D "D:databasepostgresqldata" -E UTF-8  --locale=chs -A md5 -U admin -W







6. 启动PostgreSQL服务:
pg_ctl -D D:databasepostgresqldata -l  D:databasepostgresqlpglog.txt start



7. 创建并连接数据库:
createdb test
psql -h  localhost -w -d  test



8. 关闭PostgreSQL服务:
pg_ctl -D  D:databasepostgresqldata stop

9. 注册为Windows服务:

> 注册为windows服务,当前windows用户(即postgres)将作为PostgreSQL服务的登录用户
D:pgsql>binpg_ctl register -N PostgreSQL  -D “D:databasepostgresqldata

> 启动PostgreSQL服务
D:pgsql> sc start PostgreSQL


点赞(1421)

评论列表共有 0 条评论

立即
投稿
返回
顶部