On 03/20/2012 03:14 AM, Bèrto ëd Sèra wrote:
>
> I currently have an emergency ... As an emergency procedure we have
> set a script that each minute has a look at the situation and runs
> pg_cancel_backend() against anything that has been waiting for more
> than X secs. Then it sleeps one more minute...
...
> Is there anyway I can mark the process running the filter, maybe using
> the update_process_title feature? I'd like to have something I can see
> from a ps command, grep for it and kill -15 it, without wasting our
> scarce resources on one more pg process to use info from pg_stat_activity.
>
Several things spring to mind.
1. The script that starts the filter can note its pid and set an at-job
to kill it after 30 minutes. I've used this technique with success.
2. Create a new role specifically to run the filter. The role is
generally visible in ps.
But this all begs the question. Why not:
3. Set the statement_timeout so long-running statements will be
automatically killed. This can be done on a per-role basis so simply set
it as desired for the role used by the problematic Java program. It is a
default and can be changed by the user so if there are individual
statements that need a longer timeout you can change just for those
statements.
Cheers,
Steve