私は、外部テーブルを作成できるように制限された権限を持つユーザーを設定しようとしています。2つのデータベースが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;
私はへの接続を設定hr_dbからaccounting_db外国データラッパを使用しました:
CREATE SERVER hr_db FOREIGN DATA WRAPPER postgres_fdw
OPTIONS (host 'localhost', dbname 'hr_db', port '5432');
次に、accounting_userユーザーのマッピングを追加しました。
CREATE USER MAPPING FOR accounting_user SERVER hr_db
OPTIONS (user 'accounting_user', password 'secretpassword');
のパスワードaccounting_userは、コマンドラインからのログインに使用するものと同じです。これはうまくいきます:
psql -U accounting_user -W hr_db
[enter accounting_user password]
SELECT * FROM people LIMIT 10;
ユーザー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;
しかし、外部テーブルを作成しようとすると:
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
スーパーユーザーとして、hr_people外部テーブルを作成できます。外部テーブルにaccounting_userアクセスできます。したがって、外部データ接続hr_dbは正しいようです。accounting_user外部テーブルを作成および削除できるようにするには、他に何を指定する必要がありますか?
ERROR: only superuser can change options of a file_fdw foreign table今...☹️