Scott M. Mcdermott

UNIX Systems & Network Administrator
available for contract or salaried positions

pgdb_kill_bydb

#

require pgdb_getpids_bydb

pgdb_kill_bydb ()
{
        local dbname=$1

        # This is highly counter-intuitive:
        #
        # for postmaster:
        #       TERM:INT:QUIT = graceful:presently:instantly
        #
        # for backends:
        #       TERM = terminate backend (pg_terminate_backend() 8.4+)
        #       INT  = cancel query      (pg_cancel_backend() 8.3)
        #       QUIT = abort process     (unhandled)
        #       (only in 8.4 is TERM safe)
        #
        # According to developers on IRC, there is "no safe
        # way prior to 8.4" without entire DBMS shutdown
        # (only postmaster knows enough to do it).  However,
        # TERM is safer than QUIT and does some cleanup.
        #
        # 8.4+ has pg_terminate_backend
        #
        local signal=${2:-TERM}

        local -a pids

        pids=($(pgdb_getpids_bydb $dbname))

        ((${#pids[@]})) && kill -$signal ${pids[@]}
}
# vim:syn=sh:ft=sh