postgresql 默认public用户对函数和存储过程有执行权限
创建函数
test=> create or replace function fun1(var integer)
test-> returns integer as $$
test$> begin
test$> var := var+1;
test$> return var;
test$> end; $$
test-> language plpgsql;
CREATE FUNCTION
test=>
test=> select funname,funacl from pg_function where funname = ‘fun1’;
funname | funacl
---------±-------
fun1 |
(1 row)
test=>
# 新建的函数,权限为空
新建用户
test=# create user temp ;
CREATE ROLE
test=#
赋予用户新建函数所属schema的usage权限
test=> grant usage on schema user1 to temp;
GRANT
test=# quit
新建用户连接数据库
[polardb@polardb1 ~]$ psql -h 127.0.0.1 -U temp -d test
psql (11.2.9)
Type “help” for help.
test=>
# 对函数有默认执行权限
test=> select user1.fun1(2);
fun1
#------
3
(1 row)
显式赋予函数的查询权限
test=> grant execute on function fun1 to temp;
GRANT
test=>
#再次查看函数的权限信息
test=> select funname,funacl from pg_function where funname = ‘fun2’;
funname | funacl
---------±--------------------------------------
fun2 | {=X/user1,user1=X/user1,temp=X/user1}




