/*on remote system*/ DROP USER; DROP TABLE remote_tbl; CREATE USER foreign_user; CREATE TABLE remote_tbl ( index INTEGER, height real CHECK (height > 50), weight real CHECK (weight > 50) ); INSERT INTO remote_tbl VALUES(1,78.67, 83.45); INSERT INTO remote_tbl VALUES(2,75.67, 85.45); INSERT INTO remote_tbl VALUES(3,76.67, 87.45); INSERT INTO remote_tbl VALUES(4,79.67, 89.45); GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA public TO foreign_user; /*on local system*/ DROP FOREIGN TABLE foreign_tbl; DROP USER MAPPING FOR public SERVER foreign_server; DROP SERVER foreign_server; DROP EXTENSION postgres_fdw; CREATE EXTENSION postgres_fdw; CREATE SERVER foreign_server FOREIGN DATA WRAPPER postgres_fdw OPTIONS ( host 'localhost', port '5440', dbname 'postgres' ); CREATE USER MAPPING FOR public SERVER foreign_server OPTIONS ( USER 'foreign_user', PASSWORD '' ); CREATE FOREIGN TABLE foreign_tbl ( index INTEGER, height real, weight real) SERVER foreign_server OPTIONS ( schema_name 'public', table_name 'remote_tbl' ); SET enable_connectioncache TO off; SELECT * FROM foreign_tbl;