源数据位于数据库键的公共模式中的键表中 (参考 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
鉴于用户键是外部数据库中键表的所有者,我不明白。这里应该做什么?