9

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.

chalitha geekiyanage
  • 6,464
  • 5
  • 25
  • 32
  • Using default postgres installer, it should be installed as a service in automatic start mode. Have you tried to reinstall postgres? – jhamon Dec 19 '14 at 13:15
  • I tried it on another computer but I'm getting the same error. Can you please tell me how to uninstall postgreqsl binaries. – chalitha geekiyanage Dec 19 '14 at 13:19
  • go to your postgres install directory and run "uninstall-postgresql.exe" – jhamon Dec 19 '14 at 13:23
  • I think some files are missing; I got some information from windows event viewer; I have update the question about it. – chalitha geekiyanage Dec 19 '14 at 13:32
  • Did you install postgres on your computer or simply copy the files? – jhamon Dec 19 '14 at 13:38
  • No I installed it according to the instructions given in [here](http://www.petrikainulainen.net/programming/tips-and-tricks/installing-postgresql-9-1-to-windows-7-from-the-binary-zip-distribution/) – chalitha geekiyanage Dec 19 '14 at 13:41
  • Try to install it using [pgAdmin](http://www.postgresql.org/ftp/pgadmin3/release/v1.20.0/win32/) – jhamon Dec 19 '14 at 13:45
  • I copy and paste the pgsql folder to the system32 directory; Then I was able tho start the service successfully. But I want to run the database which is stored in the installed location. – chalitha geekiyanage Dec 19 '14 at 13:48

3 Answers3

9

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.

John
  • 1
  • 13
  • 98
  • 177
chalitha geekiyanage
  • 6,464
  • 5
  • 25
  • 32
5

This is a note for a normal user. If using an official installer it should has a build-in service,

  1. Win+R and type services.msc
  2. Search Postgres service based on the version installed, e.g., "postgresql-x64-13 - PostgreSQL Server 13"
  3. Click stop, start, or restart the service option
foxiris
  • 3,125
  • 32
  • 32
0

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.

Marc
  • 13,011
  • 11
  • 78
  • 98