1.建立data目录
2.执行bat
set PGHOME=C:/PostgreSQL/pgsql
set PATH=%PGHOME%/bin;%path%
set PGHOST=localhost
set PGLIB=%PGHOME%/lib
set PGDATA=%PGHOME%/data
3.删除用户 postgres 并重建 net user postgres pass /add /expires:never /passwordchg:no
(从用户组删除用户:C:/>net localgroup users postgres /delete)
5.给用户赋权限
创建 PostgreSQL 服务,命令如下:(假设我们的数据库创建在 C:/PostgreSQL/pgsql/data下,创建数据库用 createdb 命令) C:/PostgreSQL/pgsql/bin>pg_ctl register -N PostgreSQL -U postgres -P pass -D C:/PostgreSQL/pgsql/data
指定 postgres 用户的访问权限,如下:
(设置 postgres 用户对 C:/PostgreSQL/pgsql 目录可读)
C:/PostgreSQL/pgsql>cacls . /T /E /P postgres:R
C:/PostgreSQL/pgsql>cacls . /T /E /P postgres:R
设置 postgres 用户对 C:/PostgreSQL/pgsql/data 目录可更改(可写)
C:/PostgreSQL/pgsql>cacls data /T /E /P postgres:C
4.切换用户runas /user:postgres cmd
进入C:/PostgreSQL/pgsql/bin
5.initdb -D C:/PostgreSQL/pgsql/data --locale=C
加入--locale=C是因为默认的会提示initdb: locale Chinese_People's Republic of China.936 requires unsupported encoding GBK
initdb –E utf8初始化数据库,这里设置数据库的编码为utf8
6.进入服务,启动服务,启动之前确认路径,方法:
进入注册表regedit
键值
HKEY_LOCAL_MACHINE/SYSTEM/CurrentControlSet/Services/PostgreSQL
注册项目,编辑ImagePath项目,其数值为
"C:/PostgreSQL/pgsql/bin/pg_ctl.exe runservice -N "PostgreSQL" -D "C:/PostgreSQL/pgsql/data/"
删除 -D "C:/PostgreSQL/pgsql/data",新的ImagePath值为
"C:/PostgreSQL/pgsql/bin/pg_ctl.exe runservice -N "PostgreSQL"
杂记:
支持远程
修改Postgresql的配置文件Postgresql.conf,该文件在数据目录/opt/pg/data下,将其中的一句:
listen_address=’localhost’
前面的注释去掉,并把’localhost’改为’*’。
修改Postgresql的配置文件pg_hba.conf,该文件在数据目录/opt/pg/data下,在文件后面加一句:
host all all 192.168.0.0/24 password