diff --git a/docs/guides/removing-wrappers.md b/docs/guides/removing-wrappers.md new file mode 100644 index 00000000..859c5be5 --- /dev/null +++ b/docs/guides/removing-wrappers.md @@ -0,0 +1,64 @@ +# Removing Foreign Data Wrappers + +This guide explains how to fully remove all foreign data wrappers from your PostgreSQL database. + + +## Components to Remove + +When removing a foreign data wrapper, you need to remove several components in the correct order: + +1. Foreign Tables +2. Foreign Servers +3. Wrappers Extension + +## Step-by-Step Removal Process + +### 1. List and Remove Foreign Tables + +First, list all foreign tables associated with your wrapper: + +```sql +select c.relname as foreign_table_name, + n.nspname as schema_name +from pg_catalog.pg_foreign_table ft +join pg_catalog.pg_class c on c.oid = ft.ftrelid +join pg_catalog.pg_namespace n on n.oid = c.relnamespace; +``` + +Remove each foreign table: + +```sql +drop foreign table if exists schema_name.table_name; +``` + +### 2. Remove Foreign Servers + +List servers: + +```sql +select fs.srvname as server_name, + fdw.fdwname as wrapper_name +from pg_catalog.pg_foreign_server fs +join pg_catalog.pg_foreign_data_wrapper fdw on fdw.oid = fs.srvfdw; +``` + +Remove each server: + +```sql +drop server if exists server_name cascade; +``` + +!!! note + + With `cascade` option, this will also drop all foreign tables using that foreign server. + +### 3. Remove the Extension + +```sql +drop extension if exists wrappers cascade; +``` + +!!! note + + With `cascade` option, this will also drop all foreign servers and foreign tables using Wrappers extension. + diff --git a/mkdocs.yaml b/mkdocs.yaml index 2ff2c775..0e06de8c 100644 --- a/mkdocs.yaml +++ b/mkdocs.yaml @@ -41,6 +41,7 @@ nav: - Security: 'guides/security.md' - FDW Statistics: 'guides/usage-statistics.md' - Installing Wrappers in Postgres: 'guides/installation.md' + - Removing Foreign Data Wrappers: 'guides/removing-wrappers.md' - Limitations: 'guides/limitations.md' - Developing a Wasm Wrapper: - Quick Start: 'guides/create-wasm-wrapper.md'