postgresql 对外部表 pg_redis_fdw 的权限被拒绝

问题描述 投票:0回答:2

我正在与来自 postgres 的

pg_rdeis_fdw
合作。

当我尝试从

postgres
帐户将记录插入到现有架构时,一切正常。

但是,当我尝试从另一个用户那里执行相同操作时,尽管我授予了该用户以下权限,但我收到“关系权限被拒绝”:

grant all on FOREIGN DATA WRAPPER redis_fdw to ami;
grant all on FOREIGN SERVER redis_server to ami;
grant all on ALL TABLES IN SCHEMA public to ami;
GRANT ALL PRIVILEGES ON TABLE user_redis_hash to ami;

定义如下(正如我所说,对于用户

postgres
来说效果很好):

CREATE EXTENSION redis_fdw;

CREATE SERVER redis_server
   FOREIGN DATA WRAPPER redis_fdw
   OPTIONS (address '127.0.0.1', port '6379');   

CREATE USER MAPPING FOR PUBLIC
            SERVER redis_server
            OPTIONS (password 'secret');

create foreign table user_redis_hash(key text, val text[])
   server redis_server
   options (database '0', tabletype 'hash', tablekeyset 'user:');   

谢谢, 阿米

postgresql redis
2个回答
3
投票

就我而言,我必须将外部表的所有者更改为正确的角色。所以你可以尝试这样的事情(来自

postgres
帐户):

ALTER FOREIGN TABLE public.user_redis_hash OWNER TO ami;

如果您有其他外部表(就像我一样)并且需要全部更改,以下 SQL 将生成一系列 SQL 行,您可以将其复制到

psql
提示中以更新每个外部表。

 SELECT 'ALTER FOREIGN TABLE '|| foreign_table_schema || '.' || foreign_table_name ||' OWNER TO ami;' FROM information_schema.foreign_tables WHERE NOT foreign_table_schema IN ('pg_catalog', 'information_schema') ORDER BY foreign_table_schema, foreign_table_name;

如果您有其他服务器或数据包装器的外部表,而您不想想要更改其所有权,则可以通过在 WHERE 子句中添加

AND foreign_server_name = 'redis_server'
来限制上述内容。


0
投票

将外部表的访问权限分配给普通用户:

-- before, we created a foreign server, create user mapping, and made an import foreign schema for the superuser
grant usage on schema foreign_table_schema to common_user;
grant all on all tables in schema foreign_table_schema to common_user;
© www.soinside.com 2019 - 2024. All rights reserved.