【发布时间】:2020-09-23 19:11:44
【问题描述】:
源数据位于数据库 keys 的 public 架构中的 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。
- 设置服务器连接
CREATE SERVER keys
FOREIGN DATA WRAPPER postgres_fdw
OPTIONS (host '1.2.3.4', port '5432', dbname 'keys');
- 创建用户映射
CREATE USER MAPPING FOR vids
SERVER keys
OPTIONS (user 'keys', password 'keys');
- 创建表映射
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');
- 在 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
allon theforeign tableto localuser mapping修复了权限问题。连接仍然无法正常工作,但这取决于我。随意[/鼓励]回答。