0

I newly installed PostgreSQL 9.4 onto my Windows 7 os laptop.

Straight afterwards, I think I saw on services.msc a service: postgresql-9.4 PostgreSQL Server 9.4. However, this had a message something along the lines of "marked for deletion".

Didn't understand that and being ignorant I restarted the laptop after the install, expecting magic on the reboot.

Now I can no longer see on any such service available to Start or Stop. I only have a PostgreSQL Scheduling Agent service.

I also have a problem starting and stopping the PostgreSQL Server. For instance, the typical advice seems to be:

NET START postgresql (this doesn't work on mine, because there's no service)

"pg_ctl" -D "C:/Program Files/Postgresql/9.4/data" -l logfile start (uff..I'd much prefer just to click 'start' in services.msc, ala SQL Server. Plus sometimes this gives me an error Another service might be running. Access denied and I can't find the other service, and resmon shows no port usage.)

I've also tried clicking on just about every .exe file in the binaries folder (eg. postgres.exe). But no joy.

I've read that PostgreSQL and Windows are not typically combined, but I'm stuck with Windows due to high use of Office products. Hence, mind if I ask for any construction suggestions on how to fix this issue?

Ideally I'd love to hear a way to get that postgreSQL-x64-9.4 service permanently running in my services.msc.

Many thanks in advance!

Craig Ringer
  • 307,061
  • 76
  • 688
  • 778
christo
  • 127
  • 1
  • 2
  • 12
  • 1
    _I've read that PostgreSQL and Windows are not typically combined_ - this doesn't mean that there's usually any problems with install. Try uninstall and reinstall... – Simo Kivistö Apr 09 '15 at 18:44
  • There's no real reason not to use PostgreSQL on Windows these days. The information you read is probably very outdated, from PostgreSQL 8.4 or older. – Craig Ringer Apr 10 '15 at 01:36

2 Answers2

1

You can re-create the service manually using pg_ctl

Remove the old service:

pg_ctl unregister -N postgreSQL-x64-9.4 

(replace postgresql with the actual service name)

Create a new service

pg_ctl register -N postgreSQL-x64-9.4 -D "C:/Program Files/Postgresql/9.4/data"

Note that it's not a good idea to put the data directory into Program Files. This is an extremely stupid choice of the installer and I don't understand why it's still doing that (I stopped using the installer years ago - I only unzip the archive and then run initdb manually)

c:\Program Files is a restricted directory where only the administrator account is allowed to write to. The Postgres service runs as a regular account and cannot write into that directory. In general you will have a lot less problems if you move the data directory somewhere else.

Craig Ringer
  • 307,061
  • 76
  • 688
  • 778
  • It should now be putting the datadir into `%PROGRAMDATA%` by default (usually `C:\ProgramData\`) on Windows Vista and above. I've been bugging the EDB guys about this since 9.2 but they don't want to change the default. Argh. – Craig Ringer Apr 10 '15 at 01:33
  • ... however, permissions are not the issue here. It uses `icacls.exe` to assign rights to the data directory. – Craig Ringer Apr 10 '15 at 01:34
  • Cheers for the detailed explanation Craig of how to do this. And I will go investigate relocating the data directory into Program Data via your's and other's instructions [here](http://stackoverflow.com/questions/22596301/how-to-change-postgresql-data-directory) and [here](https://wiki.postgresql.org/wiki/Change_the_default_PGDATA_directory_on_Windows). It seems like a good idea, as long as I execute it correctly. Many thanks again! – christo Apr 10 '15 at 15:12
  • I had the same problem with PosgreSQL 9.5. Unregistering/registering didn't solve the issue. Had to re-run the installer to start the service again. – whbogado Mar 02 '17 at 00:25
0

Ah...thanks Simo!

Because I hadn't yet created any databases, I ran the installer again and that started the server and it now appears again in services.msc. So it solved my immediate issue.

Although still curious about what to do if server disappears again. Hence, if anyone has a better solution than this scorched earth approach, that would be of interest.

Many thanks again.

christo
  • 127
  • 1
  • 2
  • 12
  • In short: this shouldn't happen, running the installer is usually sufficient. To say why it didn't do the job for you I would need to see the *original* installer log file (see https://wiki.postgresql.org/wiki/Troubleshooting_Installation) which the re-run of the installer probably overwrote. – Craig Ringer Apr 10 '15 at 01:35