安装PG10.5

一. 下载PostgreSQL10.5 for windows 64位:

https://www.postgresql.org/download/windows/

https://www.enterprisedb.com/downloads/postgres-postgresql-downloads

二. 安装pg:

  1. 右击安装包,管理员身份安装:
  2. 开始会安装MS C++2013,默认安装
  3. Stack Builder去掉:
  4. User: postgres
  5. Port number默认5432
  6. Locale选择chinese(simplified Chinese),china

综上,只有3和7需要选择下,其他都是默认选项。

然后,快要安装结束的时候遇到报错:

点击OK,不管,继续安装完成。

三. 启动数据库

注册服务:

  1. 点左下角圆圈,搜索cmd,以管理员身份进入
  2. Cmd,   进入db安装路径cd C:\Program Files\PostgreSQL\10\bin
  3. pg_ctl register -N PostgreSQL -D “C:\Program Files\PostgreSQL\10\data”
  4. cmd中输入services.msc打开服务管理器,找到PostgreSQL。可以右击启动,不过好像没有被用到的时候会自动关闭。
  5. 排查4中的问题:进入事件查看器(计算机管理——事件查看器——Windows日志)查看,发现application中error:

The description for Event ID 0 from source PostgreSQL cannot be found. Either the component that raises this event is not installed on your local computer or the installation is corrupted. You can install or repair the component on the local computer.

If the event originated on another computer, the display information had to be saved with the event.

The following information was included with the event:

postgres无法访问服务器配置文件 "C:/Program Files/PostgreSQL/10/data/postgresql.conf": No such file or directory

发现确实C:\Program Files\PostgreSQL\10\data是空文件夹

需要初始化数据库。

网上查资料,解决办法:

https://my.oschina.net/ericliu77/blog/1947244

https://www.cnblogs.com/wzjfl21/p/5225350.html

https://my.oschina.net/Suregogo/blog/315393          ---- 很有用,基本就是按照这个来的。

具体步骤如下:

 

  1. cmd,  net user发现没有用户postgres
  2. 创建用户postgres,密码为postgres               --此处应该没用
net user postgres postgres /add

 

3. 将data目录的权限赋给postgres用户:

C:\Program Files\PostgreSQL\10>cacls data /e /t /g postgres:C

processed dir: C:\Program Files\PostgreSQL\10\data

 

4. 用postgres用户打开cmd

C:\Program Files\PostgreSQL\10>runas /user:postgres cmd.exe

Enter the password for postgres:

Attempting to start cmd.exe as user "DESKTOP-UB4QA3B\postgres" ...

C:\Program Files\PostgreSQL\10>

此处密码和user相同postgres,回车后会打开另一个窗口,在新打开的窗口中,进入路径cd C:\Program Files\PostgreSQL\10\bin并执行: initdb.exe -D ../data -E utf8 --locale C -U postgres

C:\WINDOWS\system32>cd C:\Program Files\PostgreSQL\10\bin

 

C:\Program Files\PostgreSQL\10\bin>initdb.exe -D ../data -E utf8 --locale C -U postgres

属于此数据库系统的文件宿主为用户 "postgres".

此用户也必须为服务器进程的宿主.

数据库簇将使用本地化语言 "C"进行初始化.

缺省的文本搜索配置将会被设置到"english"

 

禁止为数据页生成校验和.

 

修复已存在目录 ../data 的权限 ... 成功

正在创建子目录 ... 成功

选择默认最大联接数 (max_connections) ... 100

选择默认共享缓冲区大小 (shared_buffers) ... 128MB

选择动态共享内存实现 ......windows

创建配置文件 ... 成功

正在运行自举脚本 ...成功

正在执行自举后初始化 ...成功

同步数据到磁盘...成功

 

警告:为本地连接启动了 "trust" 认证.

你可以通过编辑 pg_hba.conf 更改或你下次

行 initdb 时使用 -A或者--auth-local和--auth-host选项.

 

Success. You can now start the database server using:

 

    pg_ctl -D ../data -l logfile start

这时候就会发现data下有文件了。

启动数据库:

"pg_ctl" -D "../data" start C:\Program Files\PostgreSQL\10\bin>"pg_ctl" -D "../data" start
等待服务器进程启动 ....2018-09-17 12:06:50.880 HKT [20440] LOG:  listening on IPv6 address "::1", port 5432
2018-09-17 12:06:50.881 HKT [20440] LOG:  listening on IPv4 address "127.0.0.1", port 5432
2018-09-17 12:06:51.126 HKT [22728] LOG:  database system was shut down at 2018-09-17 12:03:37 HKT
2018-09-17 12:06:51.257 HKT [20440] LOG:  database system is ready to accept connections
 完成
服务器进程已经启动

 

这时候打开pgadmin,输入密码就可以进入了。

猜你喜欢

转载自blog.csdn.net/liujinwei2005/article/details/82780371