run function on server restart

Started by John D. Westover 13 years ago8 messagesgeneral
Jump to latest
#1John D. West
john.d.west@asu.edu

Sometimes the server process crashes and restarts, usually when I run some
large calculations that eat up all available memory. Is there any way to
detect this and run a cleanup routine when it happens? Running 8.4 on
Ubuntu.

-- John

#2Kevin Grittner
Kevin.Grittner@wicourts.gov
In reply to: John D. West (#1)
Re: run function on server restart

"John D. West" <john.d.west@asu.edu> wrote:

Sometimes the server process crashes and restarts, usually when I
run some large calculations that eat up all available memory.

You might want to reconfigure to avoid that.

Is there any way to detect this and run a cleanup routine when it
happens?

What is it that are you trying to clean up?

-Kevin

#3John D. West
john.d.west@asu.edu
In reply to: Kevin Grittner (#2)
Re: run function on server restart

I have various background processes outside of postgres that need to be
killed and restarted after the server reboots.

-- John

On Fri, Aug 24, 2012 at 2:29 PM, Kevin Grittner <Kevin.Grittner@wicourts.gov

Show quoted text

wrote:

"John D. West" <john.d.west@asu.edu> wrote:

Sometimes the server process crashes and restarts, usually when I
run some large calculations that eat up all available memory.

You might want to reconfigure to avoid that.

Is there any way to detect this and run a cleanup routine when it
happens?

What is it that are you trying to clean up?

-Kevin

#4Rob Sargent
robjsargent@gmail.com
In reply to: John D. West (#3)
Re: run function on server restart

On 08/24/2012 03:46 PM, John D. West wrote:

I have various background processes outside of postgres that need to be
killed and restarted after the server reboots.

-- John

On Fri, Aug 24, 2012 at 2:29 PM, Kevin Grittner
<Kevin.Grittner@wicourts.gov <mailto:Kevin.Grittner@wicourts.gov>> wrote:

"John D. West" <john.d.west@asu.edu <mailto:john.d.west@asu.edu>> wrote:

Sometimes the server process crashes and restarts, usually when I
run some large calculations that eat up all available memory.

You might want to reconfigure to avoid that.

Is there any way to detect this and run a cleanup routine when it
happens?

What is it that are you trying to clean up?

-Kevin

Seems it would be the responsibility of the dependent processes to
recognize pg went away, and clean themselves up (as only they know how
to do).

#5Kevin Grittner
Kevin.Grittner@wicourts.gov
In reply to: John D. West (#3)
Re: run function on server restart

"John D. West" <john.d.west@asu.edu> wrote:

I have various background processes outside of postgres that need
to be killed and restarted after the server reboots.

All of our applications are coded such that when they have an error
on a database connection, they check for a serialization failure or
a broken connection; if they find either they retry the database
transaction. That would be my first recommendation. (Well, second,
after identifying the causes of server crashes and fixing them.)

Are you running any monitoring applications which could trigger what
you want?

-Kevin

#6John D. West
john.d.west@asu.edu
In reply to: Kevin Grittner (#5)
Re: run function on server restart

I *think* my independent processes are cleaning up in that they supposedly
abort themselves if they lose db connection, but on restart there is a
table of pid's I'd like to (1) make sure all of the processes are really
dead, killing any who aren't (2) reset flags in a table showing the status
of those process, and (3) clear out the pid list so I can restart the
processes.

Apparently the answer to my original question is "no, there is no way to
run a function at postgres startup." The question on monitoring apps
intrigues me, however. What can they do, and what is available?

Thanks!

-- John

On Fri, Aug 24, 2012 at 3:56 PM, Kevin Grittner <Kevin.Grittner@wicourts.gov

Show quoted text

wrote:

"John D. West" <john.d.west@asu.edu> wrote:

I have various background processes outside of postgres that need
to be killed and restarted after the server reboots.

All of our applications are coded such that when they have an error
on a database connection, they check for a serialization failure or
a broken connection; if they find either they retry the database
transaction. That would be my first recommendation. (Well, second,
after identifying the causes of server crashes and fixing them.)

Are you running any monitoring applications which could trigger what
you want?

-Kevin

#7Chris Angelico
rosuav@gmail.com
In reply to: John D. West (#6)
Re: run function on server restart

On Sat, Aug 25, 2012 at 8:25 AM, John D. West <john.d.west@asu.edu> wrote:

I *think* my independent processes are cleaning up in that they supposedly
abort themselves if they lose db connection, but on restart there is a table
of pid's I'd like to (1) make sure all of the processes are really dead,
killing any who aren't (2) reset flags in a table showing the status of
those process, and (3) clear out the pid list so I can restart the
processes.

Hmm. I wonder is there a way to not use a table for this. What's the
status flagging intended to do? Can it be accomplished with, perhaps,
locks?

ChrisA

#8John D. West
john.d.west@asu.edu
In reply to: Chris Angelico (#7)
Re: run function on server restart

It's become clear I need to go back and rethink my logic for this
functionality. Thanks for all of the suggestions.

-- John

On Sat, Aug 25, 2012 at 12:40 AM, Chris Angelico <rosuav@gmail.com> wrote:

Show quoted text

On Sat, Aug 25, 2012 at 8:25 AM, John D. West <john.d.west@asu.edu> wrote:

I *think* my independent processes are cleaning up in that they

supposedly

abort themselves if they lose db connection, but on restart there is a

table

of pid's I'd like to (1) make sure all of the processes are really dead,
killing any who aren't (2) reset flags in a table showing the status of
those process, and (3) clear out the pid list so I can restart the
processes.

Hmm. I wonder is there a way to not use a table for this. What's the
status flagging intended to do? Can it be accomplished with, perhaps,
locks?

ChrisA

--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general