windows上安装postgres

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值