Search code examples
databasepostgresqlforeign-data-wrapper

Keep PostgreSQL (FDW) Foreign Schema In-Sync


Using Postgres 9.6 with postgres_fdw extension, there any means to keep the tables present within the local schema in-sync with the tables on the remote database? I often need to add new tables to the wrapped schema on the remote database and would like to access them locally via FDW without having to drop and re-import my foreign schema or individual tables as they come / go.

I'm looking for a command such as REFRESH FOREIGN SCHEMA schema_name.


Solution

  • I don't think there is a refresh, but the drop and import should take less than a second:

    DROP SCHEMA IF EXISTS local_schema_name CASCADE; 
    CREATE SCHEMA local_schema_name ;
    IMPORT FOREIGN SCHEMA foreign_schema_name 
        FROM SERVER foreign_server_name INTO local_schema_name ;