How to run PostgreSQL as a service in windows?

 ̄綄美尐妖づ 提交于 2019-12-12 09:06:08

问题


I installed postgreSQL binaries in windows 7 32bit operating system; I can start the server from cmd but I cant run it as a windows service.

This is the error that I'm getting when I try to start the service manually:

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

All I need to do is; after booting to windows when I double clicked my java application I need to run my app smoothly without any database errors. I cannot do this because postgreSQL is not running as a windows service.

I found this in windows event viewer:

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

I googled about it but I was not able to find an answer.


回答1:


Problem was solved path to the data directory was wrong in windows service file.

So I delete the service file from this method:

1)Run Regedit or Regedt32.

2)Go to the registry entry "HKEY_LOCAL_MACHINE/SYSTEM/CurrentControlSet/Services"

3)Look for the postgreSQL service that you want delete and delete it.

4)reboot the computer.

After that open the cmd (Run as administrator) Go to the postgreSQL bin directory and run this command to create a new windows service:

pg_ctl.exe register -N "PostgreSQL" -U "NT AUTHORITY\NetworkService" -D "C:/Program Files/postgresql/pgsql/bin/pgsql/data" -w

This worked for me. Hope this will help.




回答2:


postgres cannot access the server configuration file "C:/Windows/system32/pgsql/data/postgresql.conf": No such file or directory

This looks like your working directory is C:\Windows\system32 and you are running postgres there and it looks for data/postgresql.conf.

Try changing the working directory or specifying -D C:\path\to\my\data.



来源:https://stackoverflow.com/questions/27566859/how-to-run-postgresql-as-a-service-in-windows

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!