Sha*_*aun 12 postgresql postgresql-fdw
我正在尝试设置一个具有有限权限的用户,该用户能够创建外部表。我有两个数据库,hr_db
和accounting_db
. 我已经创建了一个hr_user
用户hr_db
和一个accounting_user
用户accounting_db
。我只希望accounting_user
用户对某些hr_db
表(例如表)具有选择权限users
。为此,作为超级用户,我转到hr_db
数据库并运行:
GRANT CONNECT ON DATABASE hr_db TO accounting_user;
GRANT SELECT ON people TO accounting_user;
Run Code Online (Sandbox Code Playgroud)
我设置了一个连接hr_db
从accounting_db
使用外国数据包装:
CREATE SERVER hr_db FOREIGN DATA WRAPPER postgres_fdw
OPTIONS (host 'localhost', dbname 'hr_db', port '5432');
Run Code Online (Sandbox Code Playgroud)
然后我为accounting_user
用户添加了一个映射:
CREATE USER MAPPING FOR accounting_user SERVER hr_db
OPTIONS (user 'accounting_user', password 'secretpassword');
Run Code Online (Sandbox Code Playgroud)
密码accounting_user
与我用于从命令行登录的密码相同。这工作正常:
psql -U accounting_user -W hr_db
[enter accounting_user password]
SELECT * FROM people LIMIT 10;
Run Code Online (Sandbox Code Playgroud)
我可以accounting_db
作为accounting_user
用户在数据库中创建一个常规表:
psql -U accounting_user -W accounting_db
[enter accounting_user password]
CREATE TABLE test (person_id integer NOT NULL);
DROP TABLE test;
Run Code Online (Sandbox Code Playgroud)
但是如果我尝试创建一个外部表:
CREATE FOREIGN TABLE hr_people (person_id integer NOT NULL)
SERVER hr_db OPTIONS (table_name 'people');
ERROR: permission denied for foreign server hr_db
Run Code Online (Sandbox Code Playgroud)
作为超级用户,我可以创建hr_people
外部表并且accounting_user
可以访问它。所以外部数据连接hr_db
似乎是正确的。accounting_user
为了能够创建和删除外部表,我还需要提供什么?
小智 12
为外部服务器授予权限:
GRANT USAGE ON FOREIGN SERVER hr_db TO accounting_user;
Run Code Online (Sandbox Code Playgroud)
官方页面https://www.postgresql.org/docs/9.6/static/contrib-dblink-connect.html上的示例中提供了更多详细信息
归档时间: |
|
查看次数: |
13328 次 |
最近记录: |