check_sequences
Detect database sequences lagging behind their column’s max value after migrations or bulk copies; fix them with setval() before they hand out duplicate IDs.
Instructions
Find sequences lagging behind their column's max value (stale after migrations).
A behind: true sequence would hand out an id that already exists — fix with
setval(). Run this after any bulk copy or logical-replication migration. By
default only the problem sequences are listed, with total_sequences reporting
how many were checked and skipped listing the ones that could not be probed —
so behind_count: 0 means "all clear" only when skipped_count is 0. A skipped
entry's reason is no_privilege (grant USAGE on the schema and SELECT on the
sequence and its table) or probe_failed (the owning column is not numeric or the
sequence could not be read). Pass behind_only=false for the full census; on a
large schema that is one row per sequence (hundreds), so ask for it only when you
need every sequence's state.
Returns meta, database, sequences, behind_count, total_sequences,
skipped and skipped_count.
Tool call template
Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {
"database": "<database>"
},
"name": "check_sequences"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| database | Yes | Name of a configured database, exactly as list_databases returns it (case-sensitive). Not a DSN, host or server-side database name. An unknown name is an error that lists the configured names. | |
| behind_only | No | true (default): list only sequences that are behind. false: every sequence's state. |