How to uninstall Snowflake in PostgreSQL

Galaxy Glossary

How do I uninstall the Snowflake foreign data wrapper in PostgreSQL?

Safely remove the Snowflake foreign data wrapper (snowflake_fdw) and all related objects from a PostgreSQL database.

Sign up for the latest in SQL knowledge from the Galaxy Team!
Welcome to the Galaxy, Guardian!
You'll be receiving a confirmation email

Follow us on twitter :)
Oops! Something went wrong while submitting the form.

Description

Table of Contents

Why uninstall the Snowflake FDW?

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.

What permissions are required?

You need superuser or ALTER SYSTEM privileges to drop servers and extensions.Always back up the database before you start.

How do you locate dependent objects?

Run SELECT relname FROM pg_class WHERE reloptions @> '{server=snowflake_svr}'; to list foreign tables. Plan to drop or migrate them before uninstalling.

Step-by-step uninstall procedure

1. Terminate active sessions

Use SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE foreign_server LIKE 'snowflake%'; to close open Snowflake connections and avoid locks.

2. Drop dependent foreign tables

Example: DROP FOREIGN TABLE IF EXISTS customers_sf, orders_sf, orderitems_sf;

3.Remove user mappings

DROP USER MAPPING IF EXISTS FOR CURRENT_USER SERVER snowflake_svr;

4. Drop the foreign server

DROP SERVER IF EXISTS snowflake_svr CASCADE; — CASCADE cleans up any remaining objects tied to the server.

5. Drop the extension

DROP EXTENSION IF EXISTS snowflake_fdw CASCADE; — this final command removes the FDW library and catalog entries.

Can you reinstall Snowflake later?

Yes.Run CREATE EXTENSION snowflake_fdw; followed by CREATE SERVER and CREATE USER MAPPING to reconnect PostgreSQL to Snowflake anytime.

Best practices for a clean uninstall

Always audit foreign tables first, remove only what you understand, and script the procedure so it can be repeated in staging before production.

What if DROP EXTENSION fails?

Use SELECT objid::regclass FROM pg_depend WHERE refobjid = 'snowflake_fdw'::regclass; to discover remaining dependencies, then drop them or retry with CASCADE.

Is data in Snowflake affected?

No.Uninstalling the FDW only changes PostgreSQL metadata. Your Snowflake data remains intact.

FAQ

Does DROP EXTENSION snowflake_fdw delete data in Snowflake?

No. It only removes PostgreSQL objects that reference Snowflake; the remote data is untouched.

How do I verify the extension is gone?

Run \dx in psql. If snowflake_fdw is absent, the uninstall succeeded.

Can I uninstall on a replica?

Uninstall on the primary first; streaming replicas will reflect the change automatically.

.

Why How to uninstall Snowflake in PostgreSQL is important

How to uninstall Snowflake in PostgreSQL Example Usage


-- Complete script to uninstall Snowflake FDW
BEGIN;

-- Terminate sessions
SELECT pg_terminate_backend(pid)
FROM   pg_stat_activity
WHERE  pid <> pg_backend_pid()
  AND  foreign_server LIKE 'snowflake%';

-- Drop dependent foreign tables
DROP FOREIGN TABLE IF EXISTS customers_sf,
                         orders_sf,
                         orderitems_sf;

-- Remove user mappings
DROP USER MAPPING IF EXISTS FOR CURRENT_USER SERVER snowflake_svr;

-- Drop server and extension
DROP SERVER IF EXISTS snowflake_svr CASCADE;
DROP EXTENSION IF EXISTS snowflake_fdw CASCADE;

COMMIT;

How to uninstall Snowflake in PostgreSQL Syntax


-- 1. Terminate active Snowflake sessions
SELECT pg_terminate_backend(pid)
FROM   pg_stat_activity
WHERE  pid <> pg_backend_pid()
  AND  foreign_server LIKE 'snowflake%';

-- 2. Drop dependent foreign tables (e-commerce example)
DROP FOREIGN TABLE IF EXISTS customers_sf,
                         orders_sf,
                         orderitems_sf;

-- 3. Remove user mappings
DROP USER MAPPING IF EXISTS
    FOR CURRENT_USER
    SERVER snowflake_svr;

-- 4. Drop the foreign server
DROP SERVER IF EXISTS snowflake_svr CASCADE;

-- 5. Drop the extension
DROP EXTENSION IF EXISTS snowflake_fdw CASCADE;

Common Mistakes

Frequently Asked Questions (FAQs)

Does uninstalling affect data stored in Snowflake?

No. Removing the FDW only alters PostgreSQL metadata. Your Snowflake warehouse is untouched.

Can I reinstall the FDW later?

Yes. Run CREATE EXTENSION snowflake_fdw;, recreate the server, and user mappings to restore connectivity.

How do I confirm all Snowflake objects are gone?

Use \dx to list extensions and SELECT * FROM pg_foreign_server; to verify that snowflake_svr is absent.

Want to learn about other SQL terms?

Trusted by top engineers on high-velocity teams
Aryeo Logo
Assort Health
Curri
Rubie Logo
Bauhealth Logo
Truvideo Logo
Welcome to the Galaxy, Guardian!
You'll be receiving a confirmation email

Follow us on twitter :)
Oops! Something went wrong while submitting the form.