> ## Documentation Index
> Fetch the complete documentation index at: https://villagesql.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Uninstalling Extensions

> Remove VillageSQL extensions safely

## Command Syntax

```sql theme={null}
UNINSTALL EXTENSION extension_name [VERSION 'version'];
```

When `VERSION` is supplied, the server compares it against the installed
extension's version and aborts if they differ. Omit the clause to uninstall
whatever version is currently installed.

<Warning>
  You must remove all columns, stored procedure parameters, and DECLARE variables that use types from the extension before uninstalling. The uninstall process will then remove all functions and types provided by the extension.
</Warning>

## Prerequisites

* Administrative access to VillageSQL
* No tables using custom types from the extension
* No stored procedures with parameters or DECLARE variables using custom types from the extension
* Backup of data if extension stores custom data

## Uninstall Steps

### 1. Attempt Uninstall

Run the uninstall command. If the extension has no dependencies, it will succeed immediately.
If columns depend on it, the error message identifies exactly which ones:

```sql theme={null}
UNINSTALL EXTENSION vsql_complex;
```

**If the extension has column dependencies**, you will see an error like:

```
ERROR HY000: Cannot drop extension `vsql_complex` as 1 column(s) depend on it,
e.g. mydb.signals.impedance has type COMPLEX
```

Drop or alter the identified column(s), then retry:

```sql theme={null}
-- Option 1: Drop the table
DROP TABLE mydb.signals;

-- Option 2: Alter to remove only the custom type column
ALTER TABLE mydb.signals DROP COLUMN impedance;
```

**If a stored procedure uses a custom type from the extension**, you will see an error like:

```
ERROR 3219 (HY000): Cannot uninstall extension 'vsql_complex': stored procedure mydb.transform_signal uses custom type COMPLEX
```

Drop or alter the stored procedure to remove the typed parameter or variable, then retry:

```sql theme={null}
-- Option 1: Drop the stored procedure
DROP PROCEDURE mydb.transform_signal;

-- Option 2: Recreate the procedure without the custom type parameter
-- (replace the custom type with a compatible built-in type or remove the parameter)
```

### 2. Uninstall the Extension

```sql theme={null}
UNINSTALL EXTENSION vsql_complex;
```

To guard against uninstalling an unexpected version — useful in CI or after a
rolling upgrade — include the `VERSION` clause:

```sql theme={null}
UNINSTALL EXTENSION vsql_complex VERSION '1.2.0';
```

If `1.2.0` is not the installed version, the server returns an error and leaves
the extension in place:

```
ERROR 3219 (HY000): Cannot uninstall extension 'vsql_complex': installed
version is '0.0.1' but VERSION '1.2.0' was specified
```

**What this removes:**

* ✅ All VDFs (functions) provided by the extension
* ✅ Custom type definitions registered by the extension
* ✅ Extension registration record
* ✅ Custom column metadata for the extension
* ✅ Persisted system variables (`SET PERSIST`) for the extension from `mysqld-auto.cnf`

**What this does NOT remove:**

* ❌ The `.veb` file remains in `veb_dir`
* ❌ Expanded directories in `{datadir}/.veb_expansion_cache/` remain temporarily
* ❌ Table data (you must drop tables with custom types first)

<Note>
  Expansion directories in `{datadir}/.veb_expansion_cache/{extension}/{sha256}/` are cleaned up automatically on server restart.
</Note>

<Note>
  `UNINSTALL EXTENSION` also removes any persisted system variables belonging to the
  extension from `mysqld-auto.cnf`. If you previously ran
  `SET PERSIST extensionname.varname = value`, that entry is deleted automatically
  during uninstall. Persisted values are **not** removed during server shutdown —
  they survive a restart cycle so the extension can read them on next load.
</Note>

<Note>
  Uninstalling an extension that has a pending version change (a queued
  `ALTER EXTENSION name VERSION 'x' AT RESTART`) discards that pending action
  along with the extension row — there is no orphaned pending state to clean
  up, and no error. A later `INSTALL EXTENSION` starts fresh with no pending
  action. See [Managing Extensions](/mysql-8.4/0.0.5/managing) for how
  pending version changes are tracked and cleared.
</Note>

### 3. Verify Uninstall

```sql theme={null}
-- Check extension is gone
SELECT * FROM INFORMATION_SCHEMA.EXTENSIONS WHERE EXTENSION_NAME = 'vsql_complex';
-- Should return no rows

-- Verify functions removed
SELECT complex_abs('(1.0,2.0)');
-- Error: FUNCTION test_db.complex_abs does not exist
```

## Common Errors

| Error                                                                                          | Cause                                                                                    | Solution                                                                                                            |
| ---------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------- |
| `Cannot drop extension \`name\` as N column(s) depend on it, e.g. db.table.col has type TYPE\` | Tables have columns using the extension's custom types                                   | Drop or alter the identified columns, then retry                                                                    |
| `Cannot uninstall extension 'name': stored procedure db.sp uses custom type TYPE`              | A stored procedure has a parameter or DECLARE variable using the extension's custom type | Drop or alter the stored procedure to remove the custom type usage, then retry                                      |
| `Cannot uninstall extension 'name': installed version is 'X' but VERSION 'Y' was specified`    | The `VERSION` clause was specified but doesn't match the installed version               | Re-run without `VERSION`, or use the version shown in `SELECT EXTENSION_VERSION FROM INFORMATION_SCHEMA.EXTENSIONS` |
| `Extension not found`                                                                          | Extension not installed                                                                  | Verify with `SELECT * FROM INFORMATION_SCHEMA.EXTENSIONS`                                                           |

## Optional: Remove .veb File

The `.veb` file remains after uninstall. To remove completely:

```bash theme={null}
# Find veb_dir
mysql -u root -p -e "SHOW VARIABLES LIKE 'veb_dir';"

# Delete .veb file
sudo rm /path/to/veb_dir/vsql_complex.veb
```

<Note>
  The .veb file can be kept safely for future reinstallation. Deleting it does not affect server performance.
</Note>

## Reinstalling

To reinstall an extension, use `INSTALL EXTENSION` again (if .veb file still exists):

```sql theme={null}
INSTALL EXTENSION vsql_complex;
```

See [Installing Extensions](/mysql-8.4/0.0.5/install) for details.

## Next Steps

<CardGroup cols={2}>
  <Card title="Install Extensions" icon="download" href="/mysql-8.4/0.0.5/install">
    Add extensions back if needed
  </Card>

  <Card title="Managing Extensions" icon="sliders" href="/mysql-8.4/0.0.5/managing">
    Monitor and troubleshoot extensions
  </Card>

  <Card title="System Reference" icon="book" href="/mysql-8.4/0.0.5/reference">
    Query system tables
  </Card>
</CardGroup>
