PostgreSQL: Foreign Table

  • Create extension

    CREATE EXTENSION postgres_fdw;
    
  • Create server

    CREATE SERVER server_name FOREIGN DATA WRAPPER postgres_fdw options(host 'host_addr', port '5432', dbname 'db_name');
    
  • Create user mapping

    CREATE USER MAPPING FOR postgres SERVER server_name options(user 'username',password 'password');
    
  • Import remote schema

    IMPORT FOREIGN SCHEMA schema_name LIMIT TO (table1,table2,...) FROM SERVER server_name INTO destination_schema;
    
    \dx list the installed extensions
    \des List the foreign servers
    \deu+ List the user mappings
    
  • Drop

    DROP FOREIGN TABLE table_name;
    DROP USER MAPPING FOR user_name SERVER server_name;
    DROP SERVER server_name;
    
    原文作者:青鱼之鱼
    原文地址: https://www.jianshu.com/p/da9c164c91b2
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞