Keep PostgreSQL Windows Service running 24/7 with Service Protector

How to Keep the PostgreSQL Windows Service Running 24/7 with Service Protector

Automatically restart PostgreSQL when it stops for any reason. Achieve 100% availability for your databases today!

PostgreSQL is popular open-source object-relational database system.

To protect the PostgreSQL windows service with Service Protector:

  1. Download, install and configure PostgreSQL, if necessary.

  2. Download and install Service Protector, if necessary.

  3. Start Service Protector.

  4. Select Protector > Add to open the Add Protector window:

    Add Protector

  5. On the General tab:

    • In the Service to protect field, choose the PostgreSQL windows service, called something like postgresql-<VERSION-NUMBER>. Since we have installed version 9.2, our service is called postgresql-9.2.

      You will notice a green circle on the left if the PostgreSQL service is already running, as was the case on our server.

    • Some users have reported that PostgreSQL can fail to start properly after a power failure, system crash or other unexpected shutdown because the magical file has been left behind. To protect yourself against those situations, create a batch file that removes the lock file from the PostgreSQL data folder (by default, C:\Program Files\PostgreSQL\9.2\data):

      Remove the PostgreSQL File

      Specify that batch file in the Run this command prior to restarting the service section at the bottom of the window. This will ensure that PostgreSQL comes up "clean" if it ever dies and inadvertently leaves the lock file behind.

      PostgreSQL Windows Service: General Tab

  6. Click the Save >> button. In a couple of seconds, an entry for PostgreSQL will show up in the Service Protector window. PostgreSQL is probably already running but it is not yet being protected by Service Protector (as pictured below).

    PostgreSQL Windows Service: Created

  7. To start protection, choose Protector > Start "postgresql-9.2". In a couple of seconds the shield icon on the right will go to green to indicate that PostgreSQL is being monitored by Service Protector:

    PostgreSQL Windows Service: Protected

  8. That's it! Next time your computer boots, PostgreSQL will start and Service Protector will babysit the service to promptly restart it if it fails.

    We encourage you to edit PostgreSQL in Service Protector and check out the many other settings that may be appropriate for your environment. For example, send an email when the service fails, restart PostgreSQL if it runs away with the CPU, and much more.

Trouble protecting the PostgreSQL Windows Service?