Safely remove the Snowflake foreign data wrapper (snowflake_fdw) and all related objects from a PostgreSQL database.
The Snowflake foreign data wrapper (snowflake_fdw) lets PostgreSQL query Snowflake, but you should remove it when migrating fully to Snowflake, upgrading the FDW, or tightening security. Uninstalling frees resources and removes unused connections.
You need superuser or ALTER SYSTEM privileges to drop servers and extensions.Always back up the database before you start.
Run SELECT relname FROM pg_class WHERE reloptions @> '{server=snowflake_svr}';
to list foreign tables. Plan to drop or migrate them before uninstalling.
Use SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE foreign_server LIKE 'snowflake%';
to close open Snowflake connections and avoid locks.
Example: DROP FOREIGN TABLE IF EXISTS customers_sf, orders_sf, orderitems_sf;
DROP USER MAPPING IF EXISTS FOR CURRENT_USER SERVER snowflake_svr;
DROP SERVER IF EXISTS snowflake_svr CASCADE;
— CASCADE cleans up any remaining objects tied to the server.
DROP EXTENSION IF EXISTS snowflake_fdw CASCADE;
— this final command removes the FDW library and catalog entries.
Yes.Run CREATE EXTENSION snowflake_fdw;
followed by CREATE SERVER
and CREATE USER MAPPING
to reconnect PostgreSQL to Snowflake anytime.
Always audit foreign tables first, remove only what you understand, and script the procedure so it can be repeated in staging before production.
Use SELECT objid::regclass FROM pg_depend WHERE refobjid = 'snowflake_fdw'::regclass;
to discover remaining dependencies, then drop them or retry with CASCADE.
No.Uninstalling the FDW only changes PostgreSQL metadata. Your Snowflake data remains intact.
No. It only removes PostgreSQL objects that reference Snowflake; the remote data is untouched.
Run \dx
in psql. If snowflake_fdw is absent, the uninstall succeeded.
Uninstall on the primary first; streaming replicas will reflect the change automatically.
.
No. Removing the FDW only alters PostgreSQL metadata. Your Snowflake warehouse is untouched.
Yes. Run CREATE EXTENSION snowflake_fdw;
, recreate the server, and user mappings to restore connectivity.
Use \dx
to list extensions and SELECT * FROM pg_foreign_server;
to verify that snowflake_svr is absent.