CREATE EXTENSION postgres_fdw; CREATE SERVER dst_server FOREIGN DATA WRAPPER postgres_fdw OPTIONS (host '192.168.20.105', port '5432', dbname 'dst_db'); CREATE USER MAPPING FOR admin SERVER dst_server OPTIONS (user 'admin', password 'aDmin2021'); CREATE FOREIGN TABLE dst_book ( id integer NOT NULL, name text ) SERVER dst_server OPTIONS (schema_name 'public', table_name 'book1'); --创建函数 CREATE OR REPLACE FUNCTION insertbook1() RETURNS TRIGGER AS $$ BEGIN INSERT INTO dst_book(id, name) VALUES (new.id, new.name); RETURN NEW; END; $$ LANGUAGE plpgsql; --创建触发器 CREATE TRIGGER insertbook1_trigger AFTER INSERT ON book FOR EACH ROW EXECUTE PROCEDURE insertbook1(); --删除外表服务 DROP FOREIGN TABLE tree_sys_account; DROP USER MAPPING IF EXISTS FOR postgres SERVER tree_server; DROP server tree_server;
没有帐号? 立即注册