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

9

我在Windows 7 32位操作系统中安装了PostgreSQL二进制文件;我可以从命令提示符启动服务器,但我无法将其作为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"

我需要做的就是,在启动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

我搜索了一下,但是没有找到答案。


我在另一台电脑上尝试了一下,但是还是出现了相同的错误。 请问您能告诉我如何卸载PostgreSQL二进制文件吗? - chalitha geekiyanage
我认为有一些文件丢失了;我从Windows事件查看器中获取了一些信息;我已经更新了相关问题。 - chalitha geekiyanage
你是在电脑上安装了Postgres还是只是复制了文件? - jhamon
我将pgsql文件夹复制并粘贴到system32目录中;然后我成功启动了服务。但我想运行安装位置存储的数据库。 - chalitha geekiyanage
我解决了我的问题。@jhamon非常感谢您尝试帮助我。 - chalitha geekiyanage
显示剩余4条评论
3个回答

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

这对我很有用。希望能帮到你。


5

这是一份给普通用户的说明。如果使用官方安装程序,则应该有一个内置服务。

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

0
postgres 无法访问服务器配置文件 "C:/Windows/system32/pgsql/data/postgresql.conf":没有这样的文件或目录。
看起来您的工作目录是 C:\Windows\system32,并且您正在那里运行 postgres,它正在寻找 data/postgresql.conf
尝试更改工作目录或指定 -D C:\path\to\my\data

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接