1

I am trying to set worker.bgw_restart_time = 1. This ensures that the background worker will restart in case of system crash.

But I want to restart my background worker if we restart postgres itself. Is there a way to do it?

2
  • Why dont use a timer to try to reconnect? Commented Jun 17, 2016 at 14:04
  • A timer where the script to restart postgres is present? Commented Jun 17, 2016 at 14:08

1 Answer 1

4

worker.bgw_restart_time = 1 means that the background worker process will be restarted automatically by the postmaster if the background worker process itself crashes. That way you can maintain a continuously running background process, even if it dies occasionally.

All background worker processes are automatically stopped if the PostgreSQL server is stopped altogether.

What happens on a restart depends on how the background worker is initialized. If it is loaded via shared_preload_libraries, for example, it will be started automatically. In other cases it might be started much later when called upon.

There is no facility that "remembers" what background workers were running before a shutdown and starts them back up after a restart. You might have to implement something like that yourself specifically for what you are designing.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks. That is actually an awesome solution to load it into shared_preload_libraries.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.