使用 postgres_fdw 擴充功能存取外部資料
您可以使用 postgres_fdw
若要使用 postgres_fdw 來存取遠端資料庫伺服器
安裝 postgres_fdw 擴充功能。
CREATE EXTENSION postgres_fdw;使用 CREATE SERVER 建立外部資料伺服器。
CREATE SERVER foreign_server FOREIGN DATA WRAPPER postgres_fdw OPTIONS (host 'xxx.xx.xxx.xx', port '5432', dbname 'foreign_db');建立使用者對應,找出要使用於遠端伺服器的角色。
重要
若要修訂密碼使其不會在日誌中顯示,請在工作階段層級設定
log_statement=none。在參數層級進行設定不會修訂密碼。CREATE USER MAPPING FOR local_user SERVER foreign_server OPTIONS (user 'foreign_user', password 'password');建立一個資料表,其對應至遠端伺服器上的資料表。
CREATE FOREIGN TABLE foreign_table ( id integer NOT NULL, data text) SERVER foreign_server OPTIONS (schema_name 'some_schema', table_name 'some_table');