Changing Postgres Foreign Data Wrappers

Derry Hamilton - 28/09/2017

Migrating from a commercial server to Postgres meant that we needed to change the underlying connection type for the Foreign Data Wrappers. At this time, there’s no ALTER SERVER command that will do the job, but it’s possible to update the system tables instead.

UPDATE pg_foreign_server SET srvfdw = (select oid from pg_foreign_data_wrapper where fdwname = 'postgres_fdw') where srvname IN ('test','test2');

Then, we can use ALTER SERVER to tidy up, removing the old parameters (“dbserver”) replacing them with PG equivalents:

ALTER SERVER test OPTIONS ( drop dbserver, dbname 'example_database', host '192.168.0.1', port '5432');