Skip to content

Commit

Permalink
docs: add guide for removing foreign data wrappers
Browse files Browse the repository at this point in the history
- Add comprehensive guide for removing FDWs
- Cover both native and WASM wrapper cleanup
- Include verification steps
- Fixes #177

Co-Authored-By: [email protected] <[email protected]>
  • Loading branch information
1 parent 054a42d commit e3a6eb9
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 0 deletions.
86 changes: 86 additions & 0 deletions docs/guides/removing-wrappers.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
# Removing Foreign Data Wrappers

This guide explains how to fully remove a foreign data wrapper 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. Extension
4. (For WASM wrappers only) Cache files

## Step-by-Step Removal Process

### 1. List and Remove Foreign Tables

First, list all foreign tables associated with your wrapper:

```sql
SELECT foreign_table_schema, foreign_table_name
FROM information_schema.foreign_tables;
```

Remove each foreign table:

```sql
DROP FOREIGN TABLE IF EXISTS [schema_name.]table_name;
```

### 2. Remove Foreign Servers

List servers:

```sql
SELECT srvname, fdwname
FROM pg_foreign_server fs
JOIN pg_foreign_data_wrapper fdw ON fs.srvfdw = fdw.oid;
```

Remove each server:

```sql
DROP SERVER IF EXISTS server_name CASCADE;
```

### 3. Remove the Extension

```sql
DROP EXTENSION IF EXISTS wrappers CASCADE;
```

### 4. Additional Steps for WASM Wrappers

WASM wrappers cache their compiled code locally. To fully clean up:

1. Stop the PostgreSQL server
2. Remove cached WASM files:
```bash
rm -rf /var/lib/postgresql/[version]/wasm_cache/*
```
3. Restart the PostgreSQL server

## Verification

After removal, verify that all components are gone:

```sql
-- Check for remaining foreign tables
SELECT foreign_table_schema, foreign_table_name
FROM information_schema.foreign_tables;

-- Check for remaining servers
SELECT srvname, fdwname
FROM pg_foreign_server fs
JOIN pg_foreign_data_wrapper fdw ON fs.srvfdw = fdw.oid;

-- Check for the extension
SELECT * FROM pg_extension WHERE extname = 'wrappers';
```

## Common Issues

- Always use CASCADE when dropping servers if you're unsure about dependencies
- For production environments, take a backup before removing components
- Some wrappers might have additional cleanup steps; check wrapper-specific documentation
13 changes: 13 additions & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,16 @@ Although a foreign table behaves like any other table, the data is not stored in
The following Postgres providers support Wrappers:

- [supabase.com](https://supabase.com)

## Guides

Learn how to use and manage Foreign Data Wrappers:

- [Installing Wrappers](guides/installation.md)
- [Removing Wrappers](guides/removing-wrappers.md)
- [Native vs WASM Wrappers](guides/native-wasm.md)
- [Query Pushdown](guides/query-pushdown.md)
- [Remote Subqueries](guides/remote-subqueries.md)
- [Usage Statistics](guides/usage-statistics.md)
- [Security](guides/security.md)
- [Limitations](guides/limitations.md)

0 comments on commit e3a6eb9

Please sign in to comment.