pgcrypto:普通用户无法使用

问题描述

我需要在 postgresql 12 实例上启用 pgcrypto

我启用了扩展并检查它是否正常:

postgres=# CREATE EXTENSION pgcrypto;
CREATE EXTENSION
postgres=# SELECT digest('blah','sha256');
                               digest
--------------------------------------------------------------------
 \x8b7df143d91c716ecfa5fc1730022f6b421b05cedee8fd52b1fc65a96030ad52
(1 row)

我遵循了我在 SO 上阅读的建议:

postgres=# GRANT EXECUTE ON FUNCTION digest(bytea,text) TO normaluser;
GRANT
postgres=# GRANT EXECUTE ON FUNCTION digest(text,text) TO normaluser;
GRANT

遗憾的是,仍然无法通过“普通用户”使用该功能

normaluser@planck:5432/cryptodb> SELECT digest('blah','sha256');
ERROR:  42883: function digest(unkNown,unkNown) does not exist
LINE 1: SELECT digest('blah','sha256');
               ^
HINT:  No function matches the given name and argument types. You might need to add explicit type casts.
LOCATION:  ParseFuncOrColumn,parse_func.c:631
Time: 52,065 ms

欢迎任何提示,谢谢:)

解决方法

在问题中,您可以看到我在创建扩展时以超级用户 postgres 的身份连接,并且不是进入数据库 cryptodb 使用的是用户 {{1} }. 因此,我使用 normaluser 连接到数据库 cryptodb,现在 postgres 可以在 normaluser 上下文中使用 pgcrypto 函数 digest

TL;博士; : cryptodb

之前连接到正确的数据库