# Schema Changes

Monitors can track structural changes to your database schemas, alerting you when tables, columns, or types are added, dropped, or altered.

![monitor-notification](/files/bvpPYxFM9JGp1F57TzO9)

## Schema Change Detection

Schema change detection captures the full column-level state of your database on each monitor run and compares it against the previous state. Any differences — new tables, dropped columns, type changes — are recorded as events.

### Configuration

Enable schema change detection with the `schemata` block:

```yaml
connection: MY_POSTGRES

schemata:
  enabled: true

objects:
  "public.*":
    metadata: true
```

| Key       | Type      | Default       | Description                                               |
| --------- | --------- | ------------- | --------------------------------------------------------- |
| `enabled` | bool      | `false`       | Enable schema change detection                            |
| `exclude` | string\[] | `["*.*_tmp"]` | Glob patterns for objects to exclude from schema tracking |

{% hint style="warning" %}
Schema change detection requires `metadata: true` on the monitored objects. Without metadata collection, Sling cannot compare schema states between runs.
{% endhint %}

### Exclude Patterns

Use `exclude` to skip objects that change frequently or are not relevant:

```yaml
schemata:
  enabled: true
  exclude:
    - "temp_schema.*"
    - "*.staging_*"
    - "*.*_backup"
```

{% hint style="info" %}
When `exclude` is not set, the default pattern `["*.*_tmp"]` excludes temporary tables automatically. Set `exclude: []` (empty array) to disable all exclusions.
{% endhint %}

### Detected Events

| Event                 | Description                                 |
| --------------------- | ------------------------------------------- |
| `schema_added`        | A new schema was detected                   |
| `schema_dropped`      | A schema was removed                        |
| `table_added`         | A new table or view was detected            |
| `table_dropped`       | A table or view was removed                 |
| `table_recreated`     | A table was dropped and re-created          |
| `column_added`        | A new column was added to an existing table |
| `column_dropped`      | A column was removed from an existing table |
| `column_type_altered` | A column's data type was changed            |

Each event includes the database name, schema name, object name, and object type. For `column_type_altered` events, both the old and new data types are recorded.

### Example

Monitor all tables in multiple schemas for structural changes:

```yaml
connection: MY_POSTGRES

schemata:
  enabled: true
  exclude:
    - "*.tmp_*"

objects:
  "public.*":
    metadata: true
  "analytics.*":
    metadata: true
  "staging.*":
    metadata: true
```

### Notifications

Enable **On Schema Change** in your monitor job's notification settings to receive alerts when schema drift is detected.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.slingdata.io/sling-platform/platform/monitors/schema-changes.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
