Search Postgresql Archives

Functions To Let Users Cancel/Terminate own Back Ends

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



PostgreSQLers,

I have a need at my $dayjob to let users cancel their own back ends. See any issues with this function to allow them to do that? Any security gotchas or anything?

CREATE OR REPLACE FUNCTION iov_cancel_user_backend(
    pid INTEGER
) RETURNS BOOLEAN LANGUAGE plpgsql SECURITY DEFINER AS $$
DECLARE
   username NAME;
BEGIN
    SELECT usename INTO username FROM iov_catalog.iov_stat_activity WHERE procpid = pid;
    IF username IS NULL THEN RETURN FALSE; END IF;

    IF username <> session_user THEN
        RAISE EXCEPTION 'You do not own back end %', pid;
    END IF;

    RETURN iov_catalog.pg_cancel_backend(pid);
END;
$$;

I plan to have one that calls pg_terminate_backend(), as well.

Thanks,

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



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]

  Powered by Linux