本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。
使用 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');