繁体   English   中英

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

[英]How to run PostgreSQL as a service in windows?

我在 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"

我需要做的就是; 当我双击我的 java 应用程序启动到 Windows 后,我需要顺利运行我的应用程序,而不会出现任何数据库错误。 我不能这样做,因为 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

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

问题已解决 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

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

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

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

postgres 无法访问服务器配置文件 "C:/Windows/system32/pgsql/data/postgresql.conf": No such file or directory

这看起来像您的工作目录是C:\\Windows\\system32并且您在那里运行 postgres 并查找data/postgresql.conf

尝试更改工作目录或指定-DC:\\path\\to\\my\\data

它也适用于 W11,谢谢。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM