如何在 Windows 中将 PostgreSQL 作为服务运行?

cha*_*age 9 java postgresql windows-services

我在 windows 7 32 位操作系统中安装了 postgreSQL 二进制文件;我可以从 cmd 启动服务器,但无法将其作为 Windows 服务运行。

这是我尝试手动启动服务时遇到的错误:

"The postgreSQL service on local computer started and then stopped. some services stop automatically if they are not in use by other servces or programs"
Run Code Online (Sandbox Code Playgroud)

我需要做的就是;启动到 Windows 后,当我双击我的 java 应用程序时,我需要顺利运行我的应用程序,没有任何数据库错误。我不能这样做,因为 postgreSQL 没有作为 Windows 服务运行。

我在Windows事件查看器中发现了这个:

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 cannot access the server configuration file 
"C:/Windows/system32/pgsql/data/postgresql.conf": No such file or directory
Run Code Online (Sandbox Code Playgroud)

我用谷歌搜索了一下,但找不到答案。

cha*_*age 10

问题已解决,Windows 服务文件中数据目录的路径错误。

所以我从此方法中删除服务文件:

1)运行Regedit或Regedt32。

2)进入注册表项“HKEY_LOCAL_MACHINE/SYSTEM/CurrentControlSet/Services”

3)查找要删除的postgreSQL服务并将其删除。

4)重新启动计算机。

之后打开cmd(以管理员身份运行)转到postgreSQL bin目录并运行以下命令来创建新的Windows服务:

pg_ctl.exe register -N "PostgreSQL" -U "NT AUTHORITY\NetworkService" -D "C:/Program Files/postgresql/pgsql/bin/pgsql/data" -w
Run Code Online (Sandbox Code Playgroud)

这对我有用。希望这会有所帮助。


fox*_*ris 5

这是给普通用户的注意事项。如果使用官方安装程序,它应该有一个内置服务,

  1. Win+R并输入services.msc
  2. 根据安装的版本搜索Postgres服务,例如“postgresql-x64-13 - PostgreSQL Server 13”
  3. 单击停止、启动或重新启动服务选项