Sto cercando di impostare un utente con autorizzazioni limitate che sarebbero in grado di creare tabelle esterne. Ho due database hr_dbe accounting_db. Ho creato un hr_userutente per hr_dbe un accounting_userutente per accounting_db. Voglio solo che l' accounting_userutente abbia diritti di selezione su alcune hr_dbtabelle, come ad esempio la userstabella. Per fare questo, come superutente sono andato al hr_dbdatabase ed ho eseguito:
GRANT CONNECT ON DATABASE hr_db TO accounting_user;
GRANT SELECT ON people TO accounting_user;
Ho creato una connessione a hr_dbda accounting_dbutilizzare un wrapper di dati straniera:
CREATE SERVER hr_db FOREIGN DATA WRAPPER postgres_fdw
OPTIONS (host 'localhost', dbname 'hr_db', port '5432');
Ho quindi aggiunto una mappatura per l' accounting_userutente:
CREATE USER MAPPING FOR accounting_user SERVER hr_db
OPTIONS (user 'accounting_user', password 'secretpassword');
La password per accounting_userè la stessa che uso per accedere dalla riga di comando. Funziona bene:
psql -U accounting_user -W hr_db
[enter accounting_user password]
SELECT * FROM people LIMIT 10;
Posso creare una tabella regolare nel accounting_dbdatabase come accounting_userutente:
psql -U accounting_user -W accounting_db
[enter accounting_user password]
CREATE TABLE test (person_id integer NOT NULL);
DROP TABLE test;
Ma se provo a creare una tabella esterna:
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
Come superutente, posso creare il hr_peopletavolo straniero e accounting_useravrò accesso ad esso. Quindi la connessione dati esterna a hr_dbsembra corretta. Cos'altro devo dare accounting_useraffinché sia in grado di creare e eliminare tavoli stranieri?
ERROR: only superuser can change options of a file_fdw foreign table... ☹️