Postgresql

解釋的 Postgres 權限

  • February 5, 2021

我想授予使用者執行EXPLAIN但不執行SELECT自身的權限。這在 PostgreSQL 中可行嗎?

創建一個如下所示的函式;

   CREATE OR REPLACE FUNCTION public.explain_this (
     l_query text,
     out explain text
   )
   RETURNS SETOF text AS
   $body$
   BEGIN
     RETURN QUERY EXECUTE 'explain (ANALYZE FALSE) ' || l_query;
   END;
   $body$
   LANGUAGE 'plpgsql'
   VOLATILE
   RETURNS NULL ON NULL INPUT
   SECURITY DEFINER
   COST 100 ROWS 1000;

然後安排特權;

 ALTER FUNCTION public.explain_this(l_query text, out explain text)
   OWNER TO some_user_with_select_only_privileges;

 GRANT EXECUTE
   ON FUNCTION public.explain_this(l_query text, out explain text) TO user_to_execute;

引用自:https://dba.stackexchange.com/questions/143470