【问题标题】:How to set up permissions on foreign table using postgres_fdw?如何使用 postgres_fdw 设置外部表的权限?
【发布时间】:2020-09-23 19:11:44
【问题描述】:

源数据位于数据库 keyspublic 架构中的 keys 表中(参考 pg 文档:https://www.postgresql.org/docs/current/postgres-fdw.html):

create table keys (
    id varchar not null,
    keyname varchar not null,
    created timestamp default current_timestamp not null,
    modified timestamp default current_timestamp not null
);

引用用户/模式/数据库是vids/public/vids

  1. 设置服务器连接
CREATE SERVER keys
        FOREIGN DATA WRAPPER postgres_fdw
        OPTIONS (host '1.2.3.4', port '5432', dbname 'keys');
  1. 创建用户映射
CREATE USER MAPPING FOR vids
        SERVER keys
        OPTIONS (user 'keys', password 'keys');
  1. 创建表映射
create foreign table keys (
    id varchar not null,
    keyname varchar not null,
    created timestamp default current_timestamp not null,
    modified timestamp default current_timestamp not null
) server keys options (schema_name 'public', table_name 'keys');
  1. vids db 中作为 vids 连接时尝试访问外部表:
vids=> select * from keys;
ERROR:  permission denied for foreign table keys

鉴于用户 keys 是外部数据库中 keys 表的所有者,我不明白。这里应该做什么?

【问题讨论】:

  • 什么是“引用用户”?
  • @jjanes 我在问题中这样澄清:user/schema/database is vids_/_public_/_vids
  • 在此过程的每个步骤中,仍不清楚哪个用户登录到哪个服务器上的哪个数据库。此外,您为 clip 创建了一个用户映射,而不是您在其他任何地方使用的用户。
  • 错误信息表明问题出在本地。外部表的本地表示不归vids 所有,vids 没有权限。因此,永远无法确定keys 是否可以在国外访问keys
  • @jjanes Yes grantint all on the foreign table to local user mapping 修复了权限问题。连接仍然无法正常工作,但这取决于我。随意[/鼓励]回答。

标签: postgresql postgres-fdw


【解决方案1】:

来自@jjanes 的评论:

错误消息表明问题出在本地”。外部表的本地表示由vidsvids 拥有权限。因此它永远无法确定是否keys在国外可以访问keys

所以对我的步骤的更正是:

 grant all on table keys to clips;

【讨论】:

    猜你喜欢
    • 2022-06-14
    • 1970-01-01
    • 2011-11-04
    • 1970-01-01
    • 2013-11-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-08-12
    相关资源
    最近更新 更多